diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000000000000000000000000000000000000..0e8b84b3af9f001f3119e6b746b69d8d50e329ae
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,88 @@
+Language: Cpp
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignConsecutiveMacros: true
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never # "false" for clang-format version < 9, "Never" for newer versions
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+BinPackArguments: true
+BinPackParameters: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Allman
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 0
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false # "true" would drop newline before closing curly bracket in array definitions, see lib_com/rom_com.c
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"options.h'
+ Priority: -2
+ - Regex: '^"debug.h'
+ Priority: -1
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: true
+IndentPPDirectives: None # not supported in clang-format version < 9
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 2
+NamespaceIndentation: None
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: true
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements # should be "Never" for current code, but "ControlStatements" seems cleaner
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: true
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 8
+UseTab: Never
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000000000000000000000000000000000000..aa9c35e4f9786f3321942cacb1f56d7d91840e20
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,31 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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.
+
+*******************************************************************************************************/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..74c97cf3bac1cab34a80c82c16a316eb08ecd137
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,192 @@
+
+# GNU Makefile
+
+# Paths
+SRC_LIBCOM = lib_com
+SRC_LIBDEBUG = lib_debug
+SRC_LIBDEC = lib_dec
+SRC_LIBENC = lib_enc
+SRC_LIBREND = lib_rend
+SRC_LIBUTIL = lib_util
+SRC_APP = apps
+BUILD = build
+OBJDIR = obj
+
+SRC_DIRS = $(sort -u $(SRC_LIBCOM) $(SRC_LIBDEBUG) $(SRC_LIBDEC) $(SRC_LIBENC) $(SRC_LIBREND) $(SRC_LIBUTIL) $(SRC_APP))
+
+# Name of CLI binaries
+CLI_APIDEC ?= IVAS_dec
+CLI_APIENC ?= IVAS_cod
+CLI_APIREND ?= IVAS_rend
+LIB_LIBCOM ?= libivascom.a
+LIB_LIBDEBUG ?= libivasdebug.a
+LIB_LIBDEC ?= libivasdec.a
+LIB_LIBENC ?= libivasenc.a
+LIB_LIBREND ?= libivasrend.a
+LIB_LIBUTIL ?= libivasutil.a
+
+# Default tool settings
+CC ?= gcc
+RM ?= rm -f
+AR ?= ar
+
+# Detect system
+UNAME_S := $(shell uname -s)
+
+# Switches for cross-platform builds (i.e. build 32 bit code on 64 bit platforms)
+ifneq "$(TARGET_PLATFORM)" ""
+ifeq ("$(TARGET_PLATFORM)", "$(findstring $(TARGET_PLATFORM), i386 i586 i686)")
+ CFLAGS += -m32
+ LDFLAGS += -m32
+endif
+
+ifeq ("$(TARGET_PLATFORM)", "$(findstring $(TARGET_PLATFORM), x86_64)")
+ CFLAGS += -m64
+ LDFLAGS += -m64
+endif
+endif
+
+ifndef VERBOSE
+QUIET_CC = @echo ' ' Compiling $<;
+QUIET_LINK= @echo ' ' Linking $@;
+QUIET_AR = @echo ' ' Archiving $@;
+QUIET = @
+endif
+
+# C compiler flags
+CFLAGS += -std=c99 -pedantic -Wcast-qual -Wall -W -Wextra -Wno-long-long \
+ -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
+ -Werror-implicit-function-declaration \
+ -Wno-unused-function -Wno-implicit-fallthrough
+
+# libs to link
+LDLIBS += -lm
+
+# Clang sanitizer compiler options
+CCCLANG = clang
+ifeq "$(CLANG)" "1"
+CC = $(CCCLANG)
+CFLAGS += -fsanitize=memory
+LDFLAGS += -fsanitize=memory
+endif
+ifeq "$(CLANG)" "2"
+CC = $(CCCLANG)
+CFLAGS += -fsanitize=address
+LDFLAGS += -fsanitize=address
+endif
+ifeq "$(CLANG)" "3"
+CC = $(CCCLANG)
+# NOTE: keep in sync with list in CMakeLists.txt
+usan_checks = undefined,float-divide-by-zero,implicit-conversion,local-bounds
+CFLAGS += -fsanitize=$(usan_checks)
+CFLAGS += -fsanitize-recover=$(usan_checks)
+LDFLAGS += -fsanitize=$(usan_checks)
+LDFLAGS += -fsanitize-recover=$(usan_checks)
+endif
+
+ifeq "$(RELEASE)" "1"
+CFLAGS += -DRELEASE
+OPTIM ?= 2
+endif
+
+ifneq "$(DEBUG)" "0"
+CFLAGS += -g3
+LDFLAGS += -g3
+endif
+
+ifeq "$(GCOV)" "1"
+CFLAGS += -fprofile-arcs -ftest-coverage
+LDFLAGS += -fprofile-arcs -ftest-coverage
+endif
+
+ifeq "$(STRIP)" "1"
+CFLAGS += -fdata-sections -ffunction-sections
+ifneq ($(UNAME_S),Darwin)
+LDFLAGS += -Wl,-gc-sections -static
+else
+LDFLAGS += -Wl,-dead_strip
+endif
+endif
+
+OPTIM ?= 0
+CFLAGS += -O$(OPTIM)
+
+CFLAGS += $(foreach DIR,$(SRC_DIRS),-I$(DIR))
+
+# Source file search paths
+VPATH = $(SRC_DIRS)
+
+###############################################################################
+
+SRCS_LIBCOM = $(foreach DIR,$(SRC_LIBCOM),$(patsubst $(DIR)/%,%,$(wildcard $(DIR)/*.c)))
+SRCS_LIBDEBUG = $(foreach DIR,$(SRC_LIBDEBUG),$(patsubst $(DIR)/%,%,$(wildcard $(DIR)/*.c)))
+SRCS_LIBDEC = $(foreach DIR,$(SRC_LIBDEC),$(patsubst $(DIR)/%,%,$(wildcard $(DIR)/*.c)))
+SRCS_LIBENC = $(foreach DIR,$(SRC_LIBENC),$(patsubst $(DIR)/%,%,$(wildcard $(DIR)/*.c)))
+SRCS_LIBREND = $(foreach DIR,$(SRC_LIBREND),$(patsubst $(DIR)/%,%,$(wildcard $(DIR)/*.c)))
+SRCS_LIBUTIL = $(foreach DIR,$(SRC_LIBUTIL),$(patsubst $(DIR)/%,%,$(wildcard $(DIR)/*.c)))
+
+OBJS_LIBCOM = $(addprefix $(OBJDIR)/,$(SRCS_LIBCOM:.c=.o))
+OBJS_LIBDEBUG = $(addprefix $(OBJDIR)/,$(SRCS_LIBDEBUG:.c=.o))
+OBJS_LIBDEC = $(addprefix $(OBJDIR)/,$(SRCS_LIBDEC:.c=.o))
+OBJS_LIBENC = $(addprefix $(OBJDIR)/,$(SRCS_LIBENC:.c=.o))
+OBJS_LIBREND = $(addprefix $(OBJDIR)/,$(SRCS_LIBREND:.c=.o))
+OBJS_LIBUTIL = $(addprefix $(OBJDIR)/,$(SRCS_LIBUTIL:.c=.o))
+OBJS_CLI_APIDEC = $(OBJDIR)/decoder.o
+OBJS_CLI_APIENC = $(OBJDIR)/encoder.o
+OBJS_CLI_APPREND = $(OBJDIR)/renderer.o
+
+DEPS = $(addprefix $(OBJDIR)/,$(SRCS_LIBCOM:.c=.P) $(SRCS_LIBDEBUG:.c=.P) $(SRCS_LIBDEC:.c=.P) \
+ $(SRCS_LIBENC:.c=.P) $(SRCS_LIBUTIL:.c=.P) $(SRCS_LIBREND:.c=.P))
+
+###############################################################################
+
+.PHONY: all clean
+
+all: $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND)
+
+$(OBJDIR):
+ $(QUIET)mkdir -p $(OBJDIR)
+
+$(LIB_LIBCOM): $(OBJS_LIBCOM)
+ $(QUIET_AR)$(AR) rcs $@ $^
+
+$(LIB_LIBDEC): $(OBJS_LIBDEC) $(OBJS_LIBREND)
+ $(QUIET_AR)$(AR) rcs $@ $^
+
+$(LIB_LIBDEBUG): $(OBJS_LIBDEBUG)
+ $(QUIET_AR)$(AR) rcs $@ $^
+
+$(LIB_LIBENC): $(OBJS_LIBENC)
+ $(QUIET_AR)$(AR) rcs $@ $^
+
+$(LIB_LIBREND): $(OBJS_LIBREND)
+ $(QUIET_AR)$(AR) rcs $@ $^
+
+$(LIB_LIBUTIL): $(OBJS_LIBUTIL)
+ $(QUIET_AR)$(AR) rcs $@ $^
+
+$(CLI_APIENC): $(OBJS_CLI_APIENC) $(LIB_LIBENC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG)
+ $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIENC) -L. -livasenc -livascom -livasutil -livasdebug $(LDLIBS) -o $(CLI_APIENC)
+
+$(CLI_APIDEC): $(OBJS_CLI_APIDEC) $(LIB_LIBDEC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG)
+ $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIDEC) -L. -livasdec -livascom -livasutil -livasdebug $(LDLIBS) -o $(CLI_APIDEC)
+
+$(CLI_APIREND): $(OBJS_CLI_APPREND) $(LIB_LIBREND) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG) $(LIB_LIBDEC)
+ $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APPREND) -L. -livasrend -livasdec -livasutil -livasdebug -livascom $(LDLIBS) -o $(CLI_APIREND)
+
+libs: $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBREND) $(LIB_LIBUTIL)
+
+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) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND)
+
+$(OBJDIR)/%.o : %.c | $(OBJDIR)
+ $(QUIET_CC)$(CC) $(CFLAGS) -c -MD -o $@ $<
+ @cp $(OBJDIR)/$*.d $(OBJDIR)/$*.P; \
+ sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
+ -e '/^$$/ d' -e 's/$$/ :/' < $(OBJDIR)/$*.d >> $(OBJDIR)/$*.P; \
+ $(RM) $(OBJDIR)/$*.d
+
+-include $(DEPS)
diff --git a/Workspace_msvc/Workspace_msvc.sln b/Workspace_msvc/Workspace_msvc.sln
new file mode 100644
index 0000000000000000000000000000000000000000..a0783ddbf435ddeb6f09907e51620302fac68237
--- /dev/null
+++ b/Workspace_msvc/Workspace_msvc.sln
@@ -0,0 +1,103 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.902
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_dec", "lib_dec.vcxproj", "{E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_enc", "lib_enc.vcxproj", "{824DA4CF-06F0-45C9-929A-8792F0E19C3E}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_com", "lib_com.vcxproj", "{39EC200D-7795-4FF8-B214-B24EDA5526AE}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_rend", "lib_rend.vcxproj", "{718DE063-A18B-BB72-9150-62B892E6FFA6}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_util", "lib_util.vcxproj", "{2FA8F384-0775-F3B7-F8C3-85209222FC70}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_debug", "lib_debug.vcxproj", "{54509728-928B-44D9-A118-A6F92F08B34F}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "decoder", "decoder.vcxproj", "{E3DCBC31-7FC9-D127-E000-529F8460D5FD}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "encoder", "encoder.vcxproj", "{B3FC9DFC-7268-8660-7C0D-B60BAF02C554}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "renderer", "renderer.vcxproj", "{12B4C8A5-1E06-4E30-B443-D1F916F52B47}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{51160D4C-55C9-4C16-A792-D94507225746}"
+ ProjectSection(SolutionItems) = preProject
+ ..\.clang-format = ..\.clang-format
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Debug|x64 = Debug|x64
+ Release|Win32 = Release|Win32
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}.Debug|Win32.ActiveCfg = Debug|Win32
+ {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}.Debug|Win32.Build.0 = Debug|Win32
+ {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}.Debug|x64.ActiveCfg = Debug|Win32
+ {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}.Release|Win32.ActiveCfg = Release|Win32
+ {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}.Release|Win32.Build.0 = Release|Win32
+ {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}.Release|x64.ActiveCfg = Release|Win32
+ {824DA4CF-06F0-45C9-929A-8792F0E19C3E}.Debug|Win32.ActiveCfg = Debug|Win32
+ {824DA4CF-06F0-45C9-929A-8792F0E19C3E}.Debug|Win32.Build.0 = Debug|Win32
+ {824DA4CF-06F0-45C9-929A-8792F0E19C3E}.Debug|x64.ActiveCfg = Debug|Win32
+ {824DA4CF-06F0-45C9-929A-8792F0E19C3E}.Release|Win32.ActiveCfg = Release|Win32
+ {824DA4CF-06F0-45C9-929A-8792F0E19C3E}.Release|Win32.Build.0 = Release|Win32
+ {824DA4CF-06F0-45C9-929A-8792F0E19C3E}.Release|x64.ActiveCfg = Release|Win32
+ {39EC200D-7795-4FF8-B214-B24EDA5526AE}.Debug|Win32.ActiveCfg = Debug|Win32
+ {39EC200D-7795-4FF8-B214-B24EDA5526AE}.Debug|Win32.Build.0 = Debug|Win32
+ {39EC200D-7795-4FF8-B214-B24EDA5526AE}.Debug|x64.ActiveCfg = Debug|Win32
+ {39EC200D-7795-4FF8-B214-B24EDA5526AE}.Release|Win32.ActiveCfg = Release|Win32
+ {39EC200D-7795-4FF8-B214-B24EDA5526AE}.Release|Win32.Build.0 = Release|Win32
+ {39EC200D-7795-4FF8-B214-B24EDA5526AE}.Release|x64.ActiveCfg = Release|Win32
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}.Debug|Win32.ActiveCfg = Debug|Win32
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}.Debug|Win32.Build.0 = Debug|Win32
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}.Debug|x64.ActiveCfg = Debug|Win32
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}.Release|Win32.ActiveCfg = Release|Win32
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}.Release|Win32.Build.0 = Release|Win32
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}.Release|x64.ActiveCfg = Release|Win32
+ {2FA8F384-0775-F3B7-F8C3-85209222FC70}.Debug|Win32.ActiveCfg = Debug|Win32
+ {2FA8F384-0775-F3B7-F8C3-85209222FC70}.Debug|Win32.Build.0 = Debug|Win32
+ {2FA8F384-0775-F3B7-F8C3-85209222FC70}.Debug|x64.ActiveCfg = Debug|Win32
+ {2FA8F384-0775-F3B7-F8C3-85209222FC70}.Release|Win32.ActiveCfg = Release|Win32
+ {2FA8F384-0775-F3B7-F8C3-85209222FC70}.Release|Win32.Build.0 = Release|Win32
+ {2FA8F384-0775-F3B7-F8C3-85209222FC70}.Release|x64.ActiveCfg = Release|Win32
+ {54509728-928B-44D9-A118-A6F92F08B34F}.Debug|Win32.ActiveCfg = Debug|Win32
+ {54509728-928B-44D9-A118-A6F92F08B34F}.Debug|Win32.Build.0 = Debug|Win32
+ {54509728-928B-44D9-A118-A6F92F08B34F}.Debug|x64.ActiveCfg = Debug|Win32
+ {54509728-928B-44D9-A118-A6F92F08B34F}.Release|Win32.ActiveCfg = Release|Win32
+ {54509728-928B-44D9-A118-A6F92F08B34F}.Release|Win32.Build.0 = Release|Win32
+ {54509728-928B-44D9-A118-A6F92F08B34F}.Release|x64.ActiveCfg = Release|Win32
+ {E3DCBC31-7FC9-D127-E000-529F8460D5FD}.Debug|Win32.ActiveCfg = Debug|Win32
+ {E3DCBC31-7FC9-D127-E000-529F8460D5FD}.Debug|Win32.Build.0 = Debug|Win32
+ {E3DCBC31-7FC9-D127-E000-529F8460D5FD}.Debug|x64.ActiveCfg = Debug|Win32
+ {E3DCBC31-7FC9-D127-E000-529F8460D5FD}.Release|Win32.ActiveCfg = Release|Win32
+ {E3DCBC31-7FC9-D127-E000-529F8460D5FD}.Release|Win32.Build.0 = Release|Win32
+ {E3DCBC31-7FC9-D127-E000-529F8460D5FD}.Release|x64.ActiveCfg = Release|Win32
+ {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Debug|Win32.ActiveCfg = Debug|Win32
+ {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Debug|Win32.Build.0 = Debug|Win32
+ {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Debug|x64.ActiveCfg = Debug|Win32
+ {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
+ {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
+ {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Release|Win32.ActiveCfg = Release|Win32
+ {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Release|Win32.Build.0 = Release|Win32
+ {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Release|x64.ActiveCfg = Release|Win32
+ {95030B82-70CD-4C6B-84D4-61096035BEA2}.Debug|Win32.ActiveCfg = Debug|Win32
+ {95030B82-70CD-4C6B-84D4-61096035BEA2}.Debug|Win32.Build.0 = Debug|Win32
+ {95030B82-70CD-4C6B-84D4-61096035BEA2}.Debug|x64.ActiveCfg = Debug|Win32
+ {95030B82-70CD-4C6B-84D4-61096035BEA2}.Release|Win32.ActiveCfg = Release|Win32
+ {95030B82-70CD-4C6B-84D4-61096035BEA2}.Release|Win32.Build.0 = Release|Win32
+ {95030B82-70CD-4C6B-84D4-61096035BEA2}.Release|x64.ActiveCfg = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {74E3E3B8-3E51-4003-816B-8ED3057AAC21}
+ EndGlobalSection
+EndGlobal
diff --git a/Workspace_msvc/decoder.vcxproj b/Workspace_msvc/decoder.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..e59992847c71b085235a5232aad1afa7d710d17f
--- /dev/null
+++ b/Workspace_msvc/decoder.vcxproj
@@ -0,0 +1,171 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ decoder
+ {E3DCBC31-7FC9-D127-E000-529F8460D5FD}
+ decoder
+ 10.0.17763.0
+
+
+
+ Application
+ v141
+ false
+ MultiByte
+
+
+ Application
+ v141
+ false
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ ..\
+ .\Debug_$(ProjectName)\
+ false
+ false
+ IVAS_dec
+
+
+ ..\
+ .\Release_$(ProjectName)\
+ false
+ false
+ IVAS_dec
+
+
+
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ Disabled
+ ..\lib_dec;..\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)
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+
+ $(OutDir)$(TargetName).exe
+ true
+
+ true
+ $(IntDir)$(ProjectName).pdb
+ Console
+ false
+
+ MachineX86
+
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ MaxSpeed
+ AnySuitable
+ false
+ Neither
+ false
+ false
+ ..\lib_dec;..\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)
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ $(OutDir)$(TargetName).exe
+ true
+
+ false
+ $(IntDir)$(ProjectName).pdb
+ Console
+ false
+
+ MachineX86
+ libcmtd.lib
+
+
+
+
+
+
+
+ {e822ddaf-0f5f-4cd0-a694-38ae69de74d3}
+ false
+
+
+ {2fa8f384-0775-f3b7-f8c3-85209222fc70}
+ false
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/encoder.vcxproj b/Workspace_msvc/encoder.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..9578e488dcee1c036524b8520471e228f6cb409f
--- /dev/null
+++ b/Workspace_msvc/encoder.vcxproj
@@ -0,0 +1,178 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ encoder
+ {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}
+ encoder
+ 10.0.17763.0
+
+
+
+ Application
+ v141
+ false
+ MultiByte
+
+
+ Application
+ v141
+ false
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ ..\
+ .\Debug_$(ProjectName)\
+ false
+ false
+ IVAS_cod
+
+
+ ..\
+ .\Release_$(ProjectName)\
+ false
+ false
+ IVAS_cod
+
+
+
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ Disabled
+ ..\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)
+
+
+ _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_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)
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ $(OutDir)$(TargetName).exe
+ true
+
+ false
+ $(IntDir)$(ProjectName).pdb
+ Console
+ false
+
+ MachineX86
+
+
+
+
+
+
+
+ {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
new file mode 100644
index 0000000000000000000000000000000000000000..22407fb0268c6e5d81348fb91415f62362793e10
--- /dev/null
+++ b/Workspace_msvc/lib_com.vcxproj
@@ -0,0 +1,311 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ {39EC200D-7795-4FF8-B214-B24EDA5526AE}
+ common
+ 10.0.17763.0
+
+
+
+ StaticLibrary
+ v141
+ false
+ MultiByte
+
+
+ StaticLibrary
+ v141
+ false
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ .\Debug_$(ProjectName)\
+ .\Debug_$(ProjectName)\
+ libivascom
+
+
+ .\Release_$(ProjectName)\
+ .\Release_$(ProjectName)\
+ libivascom
+
+
+
+
+
+
+ Disabled
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions)
+
+ EnableFastChecks
+ MultiThreadedDebug
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+ OldStyle
+ Default
+ %(DisableSpecificWarnings)
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ WS2_32.lib; %(AdditionalDependencies)
+ $(OutDir)$(TargetName).lib
+ true
+
+
+
+
+
+
+
+ MaxSpeed
+ AnySuitable
+ false
+ Neither
+ false
+ false
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions)
+ true
+
+ Default
+ MultiThreaded
+ true
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ WS2_32.lib; %(AdditionalDependencies)
+ $(OutDir)$(TargetName).lib
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters
new file mode 100644
index 0000000000000000000000000000000000000000..7a8f8e013bc27c7ca256c1f5945d88fd49176f28
--- /dev/null
+++ b/Workspace_msvc/lib_com.vcxproj.filters
@@ -0,0 +1,557 @@
+
+
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+ common_h
+
+
+
+ common_h
+
+
+
+
+
+ {890c2f45-9385-4fce-859b-6a65469e8dc0}
+
+
+ {201ea764-9626-4dca-9cc4-5b4106f8b8b2}
+
+
+ {fbb860e2-79d0-45b1-ada1-c3a0a369ce2c}
+
+
+ {b95b7bed-a666-4a00-9332-2b528638503e}
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/lib_debug.vcxproj b/Workspace_msvc/lib_debug.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..f54f282f05863a94d58638b16b12501e42ec4440
--- /dev/null
+++ b/Workspace_msvc/lib_debug.vcxproj
@@ -0,0 +1,116 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ {54509728-928B-44D9-A118-A6F92F08B34F}
+ debug
+ 10.0.17763.0
+
+
+
+ StaticLibrary
+ v141
+ MultiByte
+
+
+ StaticLibrary
+ v141
+ MultiByte
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ .\Debug_$(ProjectName)\
+ .\Debug_$(ProjectName)\
+ libivasdebug
+
+
+ .\Release_$(ProjectName)\
+ .\Release_$(ProjectName)\
+ libivasdebug
+
+
+
+
+
+
+ Disabled
+ ..\lib_com;..\lib_debug;%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions)
+ false
+
+ EnableFastChecks
+ MultiThreadedDebug
+ false
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ OldStyle
+ Default
+ %(DisableSpecificWarnings)
+
+
+ $(OutDir)$(TargetName).lib
+
+
+
+
+
+
+
+ MaxSpeed
+ AnySuitable
+ false
+ false
+ ..\lib_com;..\lib_debug;%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions)
+ true
+
+ Default
+ MultiThreaded
+ true
+ $(IntDir)$(ProjectName).pdb
+ Level4
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ $(OutDir)$(TargetName).lib
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..10a3ac1b4b7ca56c73d22a2e7a8b79e49e17513e
--- /dev/null
+++ b/Workspace_msvc/lib_dec.vcxproj
@@ -0,0 +1,350 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ lib_dec
+ {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}
+ evs_dec
+ 10.0.17763.0
+
+
+ StaticLibrary
+ v141
+ false
+ MultiByte
+
+
+
+ StaticLibrary
+ v141
+ false
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ .\Debug_$(ProjectName)\
+ .\Debug_$(ProjectName)\
+ false
+ false
+ libivasdec
+
+
+ .\Release_$(ProjectName)\
+ .\Release_$(ProjectName)\
+ false
+ false
+ libivasdec
+
+
+
+
+
+
+ .\Debug\$(ProjectName).tlb
+
+
+
+ Disabled
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions)
+
+ EnableFastChecks
+ MultiThreadedDebug
+ false
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+ OldStyle
+ Default
+ %(DisableSpecificWarnings)
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ WS2_32.lib; %(AdditionalDependencies)
+ $(OutDir)$(TargetName).lib
+ true
+
+
+
+
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ MaxSpeed
+ AnySuitable
+ false
+ Neither
+ false
+ false
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions)
+ true
+
+ Default
+ MultiThreaded
+ true
+ false
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ WS2_32.lib; %(AdditionalDependencies)
+ $(OutDir)$(TargetName).lib
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {39ec200d-7795-4ff8-b214-b24eda5526ae}
+ false
+
+
+ {54509728-928b-44d9-a118-a6f92f08b34f}
+ false
+
+
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}
+ false
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters
new file mode 100644
index 0000000000000000000000000000000000000000..ef14ddf0e47f22646d686d7263637b5628af85e2
--- /dev/null
+++ b/Workspace_msvc/lib_dec.vcxproj.filters
@@ -0,0 +1,575 @@
+
+
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_evs_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+ decoder_all_c
+
+
+
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+ decoder_h
+
+
+
+
+
+ {f63b6db2-97ec-4d8d-be9c-e798ac8bb645}
+
+
+ {0853864e-7de7-411d-975b-5045652f22c3}
+
+
+ {e29aae34-aeeb-45dd-a986-61b39890c5bb}
+
+
+ {c33b80b3-67ce-466b-91c0-4adfc9efcb5c}
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..e2db02d61cba7d8946f927a8e97cbe8797bef5b8
--- /dev/null
+++ b/Workspace_msvc/lib_enc.vcxproj
@@ -0,0 +1,365 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ lib_enc
+ {824DA4CF-06F0-45C9-929A-8792F0E19C3E}
+ evs_enc
+ 10.0.17763.0
+
+
+
+ StaticLibrary
+ v141
+ false
+ MultiByte
+
+
+ StaticLibrary
+ v141
+ false
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ .\Debug_$(ProjectName)\
+ .\Debug_$(ProjectName)\
+ false
+ false
+ libivasenc
+
+
+ .\Release_$(ProjectName)\
+ .\Release_$(ProjectName)\
+ false
+ false
+ libivasenc
+
+
+
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ Disabled
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions)
+
+ EnableFastChecks
+ MultiThreadedDebug
+ false
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+ OldStyle
+ Default
+ %(DisableSpecificWarnings)
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ WS2_32.lib; %(AdditionalDependencies)
+ $(OutDir)$(TargetName).lib
+ true
+
+
+
+
+
+
+
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ MaxSpeed
+ AnySuitable
+ false
+ Neither
+ false
+ false
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions)
+ true
+
+ Default
+ MultiThreaded
+ true
+ Precise
+ false
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ WS2_32.lib; %(AdditionalDependencies)
+ $(OutDir)$(TargetName).lib
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {39ec200d-7795-4ff8-b214-b24eda5526ae}
+ false
+
+
+ {54509728-928b-44d9-a118-a6f92f08b34f}
+ false
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters
new file mode 100644
index 0000000000000000000000000000000000000000..e74f441c4c7902d05da6850e2642eebf15c1208e
--- /dev/null
+++ b/Workspace_msvc/lib_enc.vcxproj.filters
@@ -0,0 +1,629 @@
+
+
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_all_c
+
+
+ enc_evs_c
+
+
+ enc_evs_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_all_c
+
+
+ enc_evs_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+ enc_ivas_c
+
+
+
+
+ enc_h
+
+
+ enc_h
+
+
+ enc_h
+
+
+ enc_h
+
+
+
+
+
+ {b7ee0526-8b79-4554-a3ec-04e51d38475f}
+
+
+ {dabed049-70a2-48f2-9da6-3b81a3664033}
+
+
+ {5717f1cb-c593-400b-b23a-45c422fd95c8}
+
+
+ {6cccabbe-510f-43d3-90e1-8ed5ea3837d7}
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..11edc931023867a961d8e3c355f6c5e4f1568c96
--- /dev/null
+++ b/Workspace_msvc/lib_rend.vcxproj
@@ -0,0 +1,206 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ lib_rend
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}
+ evs_dec
+ 10.0.17763.0
+
+
+ StaticLibrary
+ v141
+ false
+ MultiByte
+
+
+
+ StaticLibrary
+ v141
+ false
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ .\Debug_$(ProjectName)\
+ .\Debug_$(ProjectName)\
+ false
+ false
+ libivasrend
+
+
+ .\Release_$(ProjectName)\
+ .\Release_$(ProjectName)\
+ false
+ false
+ libivasrend
+
+
+
+
+
+
+ .\Debug\$(ProjectName).tlb
+
+
+
+ Disabled
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions)
+
+ EnableFastChecks
+ MultiThreadedDebug
+ false
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+ OldStyle
+ Default
+ %(DisableSpecificWarnings)
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ WS2_32.lib; %(AdditionalDependencies)
+ $(OutDir)$(TargetName).lib
+ true
+
+
+
+
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ MaxSpeed
+ AnySuitable
+ false
+ Neither
+ false
+ false
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions)
+ true
+
+ Default
+ MultiThreaded
+ true
+ false
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ WS2_32.lib; %(AdditionalDependencies)
+ $(OutDir)$(TargetName).lib
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {39ec200d-7795-4ff8-b214-b24eda5526ae}
+ false
+
+
+ {54509728-928b-44d9-a118-a6f92f08b34f}
+ false
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/lib_rend.vcxproj.filters b/Workspace_msvc/lib_rend.vcxproj.filters
new file mode 100644
index 0000000000000000000000000000000000000000..406ba2c85ee9fc8f3adfb0910136e2f379fe553b
--- /dev/null
+++ b/Workspace_msvc/lib_rend.vcxproj.filters
@@ -0,0 +1,215 @@
+
+
+
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+ rend_c
+
+
+
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+ rend_h
+
+
+
+
+ {54449ece-ef29-44b5-9512-ed8f555851a8}
+
+
+ {672b0eb6-cce8-425c-8bf2-aba4b45639bb}
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..6696ee00a8f723137553a0491a1e7842a7bfa965
--- /dev/null
+++ b/Workspace_msvc/lib_util.vcxproj
@@ -0,0 +1,156 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ {2FA8F384-0775-F3B7-F8C3-85209222FC70}
+ utility
+ 10.0.17763.0
+
+
+
+ StaticLibrary
+ v141
+ MultiByte
+
+
+ StaticLibrary
+ v141
+ MultiByte
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ true
+ .\Debug_$(ProjectName)\
+ .\Debug_$(ProjectName)\
+ libivasutil
+
+
+ false
+ .\Release_$(ProjectName)\
+ .\Release_$(ProjectName)\
+ libivasutil
+
+
+
+ Disabled
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_util;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);ZLIB_WINAPI;%(PreprocessorDefinitions)
+ false
+
+ EnableFastChecks
+ MultiThreadedDebug
+ false
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ OldStyle
+ Default
+ %(DisableSpecificWarnings)
+
+
+ $(OutDir)$(TargetName).lib
+
+
+
+
+ MaxSpeed
+ AnySuitable
+ false
+ false
+ ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_util;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);ZLIB_WINAPI;%(PreprocessorDefinitions)
+ true
+
+ Default
+ MultiThreaded
+ true
+ $(IntDir)$(ProjectName).pdb
+ Level4
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ $(OutDir)$(TargetName).lib
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Workspace_msvc/renderer.vcxproj b/Workspace_msvc/renderer.vcxproj
new file mode 100644
index 0000000000000000000000000000000000000000..c62874ec0afbfb789e4d8814ab3938b3e33f3410
--- /dev/null
+++ b/Workspace_msvc/renderer.vcxproj
@@ -0,0 +1,180 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ renderer
+ {12B4C8A5-1E06-4E30-B443-D1F916F52B47}
+ renderer
+ 10.0.17763.0
+
+
+
+ Application
+ v141
+ false
+ MultiByte
+
+
+ Application
+ v141
+ false
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>15.0.27428.2015
+
+
+ ..\
+ .\Debug_$(ProjectName)\
+ false
+ false
+ IVAS_rend
+
+
+ ..\
+ .\Release_$(ProjectName)\
+ false
+ false
+ IVAS_rend
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ Disabled
+ ..\lib_com;..\lib_debug;..\lib_util;..\lib_rend;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;WIN32;$(Macros);%(PreprocessorDefinitions)
+
+ EnableFastChecks
+ MultiThreadedDebug
+ false
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+ OldStyle
+ Default
+ %(DisableSpecificWarnings)
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+
+ $(OutDir)$(TargetName).exe
+ true
+
+ true
+ $(IntDir)$(ProjectName).pdb
+ Console
+ false
+
+ MachineX86
+
+
+
+
+ $(IntDir)$(ProjectName).tlb
+
+
+
+ MaxSpeed
+ AnySuitable
+ false
+ Neither
+ false
+ false
+ ..\lib_com;..\lib_debug;..\lib_util;..\lib_rend;.%(AdditionalIncludeDirectories)
+ _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions)
+ true
+
+ Default
+ MultiThreaded
+ true
+ Precise
+ false
+
+
+ $(IntDir)$(ProjectName).pdb
+ Level4
+ true
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c0c
+
+
+ $(OutDir)$(TargetName).exe
+ true
+
+ false
+ $(IntDir)$(ProjectName).pdb
+ Console
+ false
+
+ MachineX86
+ libcmtd.lib
+
+
+
+
+
+
+
+ {54509728-928B-44D9-A118-A6F92F08B34F}
+ false
+
+
+ {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}
+ false
+
+
+ {2FA8F384-0775-F3B7-F8C3-85209222FC70}
+ false
+
+
+ {39ec200d-7795-4ff8-b214-b24eda5526ae}
+ false
+
+
+ {718DE063-A18B-BB72-9150-62B892E6FFA6}
+ false
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/apps/decoder.c b/apps/decoder.c
new file mode 100644
index 0000000000000000000000000000000000000000..afb288dc098f943b56ef65c33f5bd6713ba320db
--- /dev/null
+++ b/apps/decoder.c
@@ -0,0 +1,2366 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "lib_dec.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 "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"
+#include "vector3_pair_file_reader.h"
+#include "wmc_auto.h"
+
+
+#define WMC_TOOL_SKIP
+
+/*------------------------------------------------------------------------------------------*
+ * Local constants
+ *------------------------------------------------------------------------------------------*/
+
+#if !defined( WMOPS )
+static
+#endif
+ int32_t frame = 0; /* Counter of frames */
+
+#define MIN_NUM_BITS_ACTIVE_FRAME 56
+#define NUM_BITS_SID_IVAS_5K2 104
+#define MAX_OUTPUT_PCM_BUFFER_SIZE ( ( IVAS_MAX_OUTPUT_CHANNELS + IVAS_MAX_NUM_OBJECTS ) * IVAS_MAX_FRAME_SIZE )
+
+#define ORIENT_TRK_NONE ( 0 )
+#define ORIENT_TRK_REF ( 1 )
+#define ORIENT_TRK_AVG ( 2 )
+#define ORIENT_TRK_REF_VEC ( 3 )
+#define ORIENT_TRK_REF_VEC_LEV ( 4 )
+
+#define JBM_FRONTEND_FETCH_FRAMESIZE_MS 20
+#define HEADROTATION_FETCH_FRAMESIZE_MS 5
+#define DEFAULT_FETCH_FRAMESIZE_MS 20
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local structure for storing cmdln arguments
+ *------------------------------------------------------------------------------------------*/
+
+typedef struct
+{
+ char *inputBitstreamFilename;
+ char *outputWavFilename;
+ IVAS_DEC_MODE decMode;
+ int32_t output_Fs;
+ IVAS_AUDIO_CONFIG outputConfig;
+ bool quietModeEnabled;
+ bool delayCompensationEnabled;
+ bool voipMode;
+ bool enableHeadRotation;
+ char *headrotTrajFileName;
+ bool enableReferenceRotation;
+ char *refrotTrajFileName;
+ bool enableReferenceVectorTracking;
+ char *referenceVectorTrajFileName;
+ bool enableExternalOrientation;
+ char *externalOrientationTrajFileName;
+#ifdef SUPPORT_JBM_TRACEFILE
+ char *jbmTraceFilename;
+#endif
+ char *jbmOffsetFilename;
+ char *FEPatternFileName;
+ float FER;
+ bool hrtfReaderEnabled;
+ char *hrtfFileName;
+ IVAS_DEC_INPUT_FORMAT inputFormat;
+ bool customLsOutputEnabled;
+ char *customLsSetupFilename;
+ int16_t orientation_tracking;
+ int16_t Opt_non_diegetic_pan;
+ float non_diegetic_pan_gain;
+ bool renderConfigEnabled;
+ char *renderConfigFilename;
+ IVAS_DEC_COMPLEXITY_LEVEL complexityLevel;
+ bool tsmEnabled;
+ bool enable5ms;
+ uint16_t acousticEnvironmentId;
+ int16_t Opt_dpid_on;
+ uint16_t directivityPatternId[IVAS_MAX_NUM_OBJECTS];
+
+} DecArguments;
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local functions prototypes
+ *------------------------------------------------------------------------------------------*/
+
+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, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
+static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec );
+
+/*------------------------------------------------------------------------------------------*
+ * main()
+ *
+ * Main IVAS decoder function for command-line interface
+ *------------------------------------------------------------------------------------------*/
+
+int main(
+ int argc,
+ char *argv[] )
+{
+ bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */
+ DecArguments arg;
+ ivas_error error = IVAS_ERR_UNKNOWN;
+
+ /* Any handles that require cleanup must be declared here and initialized to NULL */
+ IVAS_DEC_HANDLE hIvasDec = NULL;
+ BS_READER_HANDLE hBsReader = NULL;
+ LsCustomFileReader *hLsCustomReader = NULL;
+ hrtfFileReader *hrtfReader = NULL;
+ RotFileReader *headRotReader = NULL;
+ RotFileReader *externalOrientationFileReader = NULL;
+ RotFileReader *refRotReader = NULL;
+ Vector3PairFileReader *referenceVectorReader = NULL;
+ RenderConfigReader *renderConfigReader = NULL;
+ int16_t *pcmBuf = NULL;
+
+#ifdef WMOPS
+ reset_wmops();
+ reset_mem( USE_32BITS );
+#endif
+
+ /*------------------------------------------------------------------------------------------*
+ * Parse command-line arguments
+ *------------------------------------------------------------------------------------------*/
+
+ IVAS_DEC_PrintDisclaimer();
+
+ if ( !parseCmdlIVAS_dec( (int16_t) argc, argv, &arg ) )
+ {
+ /* Error printout done in parseCmdlIVAS_dec() */
+ goto cleanup;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open decoder handle
+ *------------------------------------------------------------------------------------------*/
+
+ if ( ( error = IVAS_DEC_Open( &hIvasDec, arg.decMode ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open input bitstream file
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.inputFormat == IVAS_DEC_INPUT_FORMAT_G192 || arg.inputFormat == IVAS_DEC_INPUT_FORMAT_MIME )
+ {
+ BS_READER_FORMAT bsReaderFormat = BS_READER_FORMAT_G192;
+
+ if ( arg.inputFormat == IVAS_DEC_INPUT_FORMAT_MIME )
+ {
+ bsReaderFormat = BS_READER_FORMAT_MIME;
+ }
+
+ if ( BS_Reader_Open_filename( &hBsReader, arg.inputBitstreamFilename, bsReaderFormat ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nUnable to open %s\n\n", arg.inputBitstreamFilename );
+ goto cleanup;
+ }
+ else
+ {
+ fprintf( stdout, "Input bitstream file: %s\n", arg.inputBitstreamFilename );
+ }
+ }
+
+ {
+ fprintf( stdout, "Output synthesis file: %s\n", arg.outputWavFilename );
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open HRTF file
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.hrtfReaderEnabled )
+ {
+ /* 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.hrtfReaderEnabled = false;
+ fprintf( stderr, "\nError: HRTF binary file cannot be used in this output configuration.\n\n" );
+ goto cleanup;
+ }
+
+ if ( ( error = hrtfFileReader_open( arg.hrtfFileName, &hrtfReader ) ) != IVAS_ERR_OK )
+ {
+ arg.hrtfReaderEnabled = false;
+ fprintf( stderr, "\nError: Can't open HRTF binary file %s \n\n", arg.hrtfFileName );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open head-rotation file
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.enableHeadRotation )
+ {
+ /* 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
+ )
+ {
+ fprintf( stderr, "\nError: Head-rotation file file cannot be used in this output configuration.\n\n" );
+ goto cleanup;
+ }
+
+ if ( ( error = RotationFileReader_open( arg.headrotTrajFileName, &headRotReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: Can't open head-rotation file %s \n\n", arg.headrotTrajFileName );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open reference rotation file
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.enableReferenceRotation )
+ {
+ /* 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 )
+ {
+ fprintf( stderr, "\nError: Reference rotation file cannot be used in this output configuration.\n\n" );
+ goto cleanup;
+ }
+
+ /* sanity check */
+ if ( arg.orientation_tracking != ORIENT_TRK_REF )
+ {
+ fprintf( stderr, "\nError: Reference rotation file can be used in '-otr ref' mode only.\n\n" );
+ goto cleanup;
+ }
+
+ if ( ( error = RotationFileReader_open( arg.refrotTrajFileName, &refRotReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: Can't open reference rotation file %s \n\n", arg.refrotTrajFileName );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open reference vector trajectory file
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.enableReferenceVectorTracking )
+ {
+ /* 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 )
+ {
+ fprintf( stderr, "\nError: Reference vector trajectory file cannot be used in this output configuration.\n\n" );
+ goto cleanup;
+ }
+
+ /* sanity check */
+ if ( arg.orientation_tracking != ORIENT_TRK_REF_VEC && arg.orientation_tracking != ORIENT_TRK_REF_VEC_LEV )
+ {
+ fprintf( stderr, "\nError: Reference trajectory file can be used in '-otr ref_vec' or '-otr ref_vec_lev' mode only.\n\n" );
+ goto cleanup;
+ }
+
+ if ( ( error = Vector3PairFileReader_open( arg.referenceVectorTrajFileName, &referenceVectorReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: Can't open reference vector trajectory file %s \n\n", arg.referenceVectorTrajFileName );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open external orientation file
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.enableExternalOrientation )
+ {
+ if ( ( error = RotationFileReader_open( arg.externalOrientationTrajFileName, &externalOrientationFileReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: Can't open external orientation file %s \n\n", arg.externalOrientationTrajFileName );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open custom loudspeaker layout file
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.customLsOutputEnabled )
+ {
+ if ( ( error = CustomLsReader_open( arg.customLsSetupFilename, &hLsCustomReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: Can't open Custom loudspeaker setup file %s \n\n", arg.customLsSetupFilename );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Open renderer configuration reader file
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.renderConfigEnabled )
+ {
+ /* 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
+ )
+ {
+ fprintf( stderr, "\nError: Renderer configuration file cannot be used in this output configuration.\n\n" );
+ goto cleanup;
+ }
+
+ if ( ( error = RenderConfigReader_open( arg.renderConfigFilename, &renderConfigReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: Can't open Renderer configuration file %s \n\n", arg.renderConfigFilename );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Configure the decoder
+ *------------------------------------------------------------------------------------------*/
+
+ if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.enable5ms, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation,
+ arg.orientation_tracking, arg.renderConfigEnabled, arg.Opt_non_diegetic_pan, arg.non_diegetic_pan_gain, arg.Opt_dpid_on, arg.acousticEnvironmentId, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Configure Split rendering
+ *------------------------------------------------------------------------------------------*/
+
+
+ /*------------------------------------------------------------------------------------------*
+ * Configure VoIP mode
+ *------------------------------------------------------------------------------------------*/
+
+ 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;
+ }
+ }
+
+ IVAS_DEC_PrintConfig( hIvasDec, 1, arg.voipMode );
+
+ /*-------------------------------------------------------------------*
+ * Load renderer configuration from file
+ *--------------------------------------------------------------------*/
+
+ 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 )
+ {
+ fprintf( stderr, "\nExternal Renderer Config is supported only for binaural output configurations. Exiting. \n\n" );
+ goto cleanup;
+ }
+
+ if ( ( error = IVAS_DEC_GetRenderConfig( hIvasDec, &renderConfig ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+
+ if ( RenderConfigReader_read( renderConfigReader, arg.renderConfigFilename, &renderConfig ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename );
+ goto cleanup;
+ }
+
+ if ( ( error = RenderConfigReader_getDirectivity( renderConfigReader, arg.directivityPatternId, renderConfig.directivity ) ) != 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] );
+ goto cleanup;
+ }
+
+ if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
+ {
+ if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, arg.acousticEnvironmentId, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
+ {
+ if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Invalid reverberation configuration parameters\n\n" );
+ goto cleanup;
+ }
+ }
+ else
+ {
+ fprintf( stderr, "Failed to get acoustic environment with ID: %d\n\n", arg.acousticEnvironmentId );
+ goto cleanup;
+ }
+ renderConfig.roomAcoustics.override = true;
+ }
+
+ 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;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Load custom loudspeaker layout data
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.customLsOutputEnabled )
+ {
+ IVAS_CUSTOM_LS_DATA hLsCustomData;
+ LS_CUSTOM_FILEREADER_ERROR lsCustomError;
+
+ if ( ( lsCustomError = CustomLsFileReading( hLsCustomReader, &hLsCustomData ) ) != LS_CUSTOM_FILEREADER_NO_ERROR )
+ {
+ fprintf( stderr, "\nError in reading Custom loudspeaker file %s: %s\n\n", arg.customLsSetupFilename, CustomLoudspeakerLayout_getError( lsCustomError ) );
+ goto cleanup;
+ }
+
+ if ( ( error = IVAS_DEC_FeedCustomLsData( hIvasDec, hLsCustomData ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedCustomLsData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Load HRTF binary file data
+ *------------------------------------------------------------------------------------------*/
+
+ if ( arg.hrtfReaderEnabled )
+ {
+ IVAS_DEC_HRTF_HANDLE hHrtfTD = NULL;
+
+ if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( error = load_HRTF_binary( hHrtfTD, hrtfReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", arg.hrtfFileName );
+ goto cleanup;
+ }
+
+ IVAS_DEC_HRTF_CREND_HANDLE hSetOfHRTF = NULL;
+ if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hSetOfHRTF ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_GetHrtfCRendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( error = create_SetOfHRTF_from_binary( hSetOfHRTF, hrtfReader, arg.output_Fs ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in loading HRTF binary file %s for CRend \n\n", arg.hrtfFileName );
+ goto cleanup;
+ }
+
+ IVAS_DEC_HRTF_FASTCONV_HANDLE hHrtfFastConv = NULL;
+ if ( ( error = IVAS_DEC_GetHrtfFastConvHandle( hIvasDec, &hHrtfFastConv ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_GetHrtfFastConvHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( error = load_fastconv_HRTF_from_binary( hHrtfFastConv, hrtfReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in loading HRTF binary file %s for FastConv \n\n", arg.hrtfFileName );
+ goto cleanup;
+ }
+
+ IVAS_DEC_HRTF_PARAMBIN_HANDLE hHrtfParambin = NULL;
+ if ( ( error = IVAS_DEC_GetHrtfParamBinHandle( hIvasDec, &hHrtfParambin ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_GetHrtfParamBinHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( error = load_parambin_HRTF_from_binary( hHrtfParambin, hrtfReader ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in loading HRTF binary file %s for parametric binauralizer \n\n", arg.hrtfFileName );
+ goto cleanup;
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Allocate output data buffer
+ *------------------------------------------------------------------------------------------*/
+
+ int16_t pcmBufSize;
+ if ( ( error = IVAS_DEC_GetOutputBufferSize( hIvasDec, &pcmBufSize ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nGetOutputBufferSize failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ pcmBuf = malloc( pcmBufSize * sizeof( int16_t ) );
+
+ /*-----------------------------------------------------------------*
+ * Decoding
+ *-----------------------------------------------------------------*/
+
+ if ( arg.voipMode )
+ {
+ error = decodeVoIP( arg, hBsReader, hIvasDec );
+ }
+ else
+ {
+ error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec, pcmBuf );
+ }
+
+ if ( error == IVAS_ERR_OK || error == IVAS_ERR_END_OF_FILE )
+ {
+ if ( arg.quietModeEnabled )
+ {
+ fprintf( stdout, "Decoding finished\n\n" );
+ }
+ else
+ {
+ fprintf( stdout, "\nDecoding of %d frames finished\n\n", frame );
+ }
+ }
+ else
+ {
+ fprintf( stdout, "Decoding finished prematurely\n\n" );
+ goto cleanup;
+ }
+
+
+ /*------------------------------------------------------------------------------------------*
+ * 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 ( arg.hrtfReaderEnabled )
+ {
+ IVAS_DEC_HRTF_HANDLE hHrtfTD = NULL;
+ IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD );
+ dealloc_HRTF_binary( hHrtfTD );
+ IVAS_DEC_HRTF_CREND_HANDLE hSetOfHRTF = NULL;
+ IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hSetOfHRTF );
+ destroy_SetOfHRTF( hSetOfHRTF );
+ }
+
+ IVAS_DEC_Close( &hIvasDec );
+ CustomLsReader_close( &hLsCustomReader );
+ hrtfFileReader_close( &hrtfReader );
+ RotationFileReader_close( &headRotReader );
+ RotationFileReader_close( &externalOrientationFileReader );
+ RotationFileReader_close( &refRotReader );
+ Vector3PairFileReader_close( &referenceVectorReader );
+ RenderConfigReader_close( &renderConfigReader );
+
+ if ( BS_Reader_Close( &hBsReader ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError while closing file: %s\nContinuing...\n\n", arg.inputBitstreamFilename );
+ }
+
+#ifdef WMOPS
+ print_wmops();
+ print_mem( NULL );
+#endif
+ if ( !arg.quietModeEnabled )
+ {
+ printf( "\n" );
+ }
+
+ return mainFailed ? -1 : 0;
+}
+
+
+/*---------------------------------------------------------------------*
+ * cmdline2config()
+ *
+ * Translate command-line argument to output configuration
+ *---------------------------------------------------------------------*/
+
+static IVAS_AUDIO_CONFIG cmdline2config(
+ char *argv )
+{
+ IVAS_AUDIO_CONFIG output_config;
+
+ char argv_to_upper[FILENAME_MAX];
+
+ strncpy( argv_to_upper, argv, sizeof( argv_to_upper ) - 1 );
+ argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0';
+ to_upper( argv_to_upper );
+
+ if ( strcmp( argv_to_upper, "EXT" ) == 0 ) /* external renderer */
+ {
+ output_config = IVAS_AUDIO_CONFIG_EXTERNAL;
+ }
+ else if ( strcmp( argv_to_upper, "MONO" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_MONO;
+ }
+ else if ( strcmp( argv_to_upper, "STEREO" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_STEREO;
+ }
+ else if ( strcmp( argv_to_upper, "5_1" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_5_1;
+ }
+ else if ( strcmp( argv_to_upper, "7_1" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_7_1;
+ }
+ else if ( strcmp( argv_to_upper, "5_1_2" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_5_1_2;
+ }
+ else if ( strcmp( argv_to_upper, "5_1_4" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_5_1_4;
+ }
+ else if ( strcmp( argv_to_upper, "7_1_4" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_7_1_4;
+ }
+ else if ( strcmp( argv_to_upper, "FOA" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_FOA;
+ }
+ else if ( strcmp( argv_to_upper, "HOA2" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_HOA2;
+ }
+ else if ( strcmp( argv_to_upper, "HOA3" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_HOA3;
+ }
+ else if ( strcmp( argv_to_upper, "BINAURAL" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_BINAURAL;
+ }
+ else if ( strcmp( argv_to_upper, "BINAURAL_ROOM_IR" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR;
+ }
+ else if ( strcmp( argv_to_upper, "BINAURAL_ROOM_REVERB" ) == 0 )
+ {
+ output_config = IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB;
+ }
+ else
+ {
+ output_config = IVAS_AUDIO_CONFIG_LS_CUSTOM;
+ }
+
+ return output_config;
+}
+
+
+/*---------------------------------------------------------------------*
+ * parseCmdlIVAS_dec()
+ *
+ * Decoder command-line parsing
+ *---------------------------------------------------------------------*/
+
+static bool parseCmdlIVAS_dec(
+ int16_t argc,
+ char **argv,
+ DecArguments *arg )
+{
+ int16_t i;
+ char argv_to_upper[FILENAME_MAX];
+
+ arg->output_Fs = 48000;
+ arg->outputConfig = IVAS_AUDIO_CONFIG_MONO;
+ arg->decMode = IVAS_DEC_MODE_IVAS;
+ arg->quietModeEnabled = false;
+ arg->delayCompensationEnabled = true;
+ arg->voipMode = false;
+ arg->complexityLevel = IVAS_DEC_COMPLEXITY_LEVEL_THREE;
+
+ arg->enableHeadRotation = false;
+ arg->headrotTrajFileName = NULL;
+ arg->orientation_tracking = ORIENT_TRK_NONE;
+ arg->enableReferenceRotation = false;
+ arg->headrotTrajFileName = NULL;
+ arg->enableReferenceVectorTracking = false;
+ arg->referenceVectorTrajFileName = NULL;
+ arg->enableExternalOrientation = false;
+ arg->externalOrientationTrajFileName = NULL;
+
+#ifdef SUPPORT_JBM_TRACEFILE
+ arg->jbmTraceFilename = NULL;
+#endif
+ arg->jbmOffsetFilename = NULL;
+
+ arg->FER = 0.f;
+ arg->FEPatternFileName = NULL;
+
+ arg->hrtfReaderEnabled = false;
+ arg->hrtfFileName = NULL;
+
+ arg->customLsOutputEnabled = false;
+ arg->customLsSetupFilename = NULL;
+
+ arg->renderConfigEnabled = false;
+ arg->renderConfigFilename = NULL;
+ arg->Opt_dpid_on = 0;
+
+
+ arg->inputFormat = IVAS_DEC_INPUT_FORMAT_G192;
+ arg->Opt_non_diegetic_pan = 0;
+ arg->non_diegetic_pan_gain = 0.f;
+ arg->tsmEnabled = false;
+ arg->enable5ms = false;
+ arg->acousticEnvironmentId = 65535;
+ for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
+ {
+ arg->directivityPatternId[i] = 65535;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Initialization
+ *-----------------------------------------------------------------*/
+
+ if ( argc < 4 )
+ {
+ fprintf( stderr, "Error: Not enough input parameters. Exiting!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Optional input arguments
+ *-----------------------------------------------------------------*/
+
+ i = 1;
+
+ while ( argv[i][0] == '-' )
+ {
+ 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 );
+
+ if ( strcmp( argv_to_upper, "-VOIP" ) == 0 )
+ {
+ arg->voipMode = 1;
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=0" ) == 0 )
+ {
+ arg->voipMode = 1;
+ arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP;
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=1" ) == 0 )
+ {
+ arg->voipMode = 1;
+ arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF;
+ i++;
+ }
+#ifdef SUPPORT_JBM_TRACEFILE
+ else if ( strcmp( argv_to_upper, "-TRACEFILE" ) == 0 )
+ {
+ i++;
+ if ( argc - i <= 3 || argv[i][0] == '-' )
+ {
+ fprintf( stderr, "Error: JBM Trace file name not specified!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ arg->jbmTraceFilename = argv[i];
+ i++;
+ }
+#endif
+ else if ( strcmp( argv_to_upper, "-FEC_CFG_FILE" ) == 0 )
+ {
+ i++;
+ if ( argc - i <= 3 || argv[i][0] == '-' )
+ {
+ fprintf( stderr, "Error: JBM config. file name not specified!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ arg->jbmOffsetFilename = argv[i];
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-Q" ) == 0 )
+ {
+ arg->quietModeEnabled = true;
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-NO_DELAY_CMP" ) == 0 )
+ {
+ arg->delayCompensationEnabled = false;
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-HRTF" ) == 0 )
+ {
+ i++;
+ arg->hrtfReaderEnabled = true;
+ if ( i < argc - 3 )
+ {
+ arg->hrtfFileName = argv[i];
+ i++;
+ }
+ }
+
+ else if ( strcmp( argv_to_upper, "-MIME" ) == 0 )
+ {
+ arg->inputFormat = IVAS_DEC_INPUT_FORMAT_MIME;
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-T" ) == 0 )
+ {
+ arg->enableHeadRotation = true;
+ i++;
+
+ if ( argc - i <= 4 || argv[i][0] == '-' )
+ {
+ fprintf( stderr, "Error: Head rotation file name not specified!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ arg->headrotTrajFileName = argv[i];
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-FR5" ) == 0 )
+ {
+ arg->enable5ms = true;
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-OTR" ) == 0 )
+ {
+
+ strncpy( argv_to_upper, argv[i + 1], sizeof( argv_to_upper ) - 1 );
+ argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0';
+ to_upper( argv_to_upper );
+
+ if ( strcmp( argv_to_upper, "NONE" ) == 0 )
+ {
+ arg->orientation_tracking = ORIENT_TRK_NONE;
+ }
+ else if ( strcmp( argv_to_upper, "REF" ) == 0 )
+ {
+ arg->orientation_tracking = ORIENT_TRK_REF;
+ }
+ else if ( strcmp( argv_to_upper, "AVG" ) == 0 )
+ {
+ arg->orientation_tracking = ORIENT_TRK_AVG;
+ }
+ else if ( strcmp( argv_to_upper, "REF_VEC" ) == 0 )
+ {
+ arg->orientation_tracking = ORIENT_TRK_REF_VEC;
+ }
+ else if ( strcmp( argv_to_upper, "REF_VEC_LEV" ) == 0 )
+ {
+ arg->orientation_tracking = ORIENT_TRK_REF_VEC_LEV;
+ }
+ else
+ {
+ fprintf( stderr, "Error: Invalid orientation tracking type %s \n\n", argv[i + 1] );
+ usage_dec();
+ return false;
+ }
+ i += 2;
+ }
+ else if ( strcmp( argv_to_upper, "-RF" ) == 0 )
+ {
+ arg->enableReferenceRotation = true;
+ i++;
+
+ if ( argc - i <= 4 || argv[i][0] == '-' )
+ {
+ fprintf( stderr, "Error: Reference rotation file name not specified!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ arg->refrotTrajFileName = argv[i];
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-RVF" ) == 0 )
+ {
+ arg->enableReferenceVectorTracking = true;
+ i++;
+
+ if ( argc - i <= 4 || argv[i][0] == '-' )
+ {
+ fprintf( stderr, "Error: reference vector trajectory file name not specified!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ arg->referenceVectorTrajFileName = argv[i];
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-EXOF" ) == 0 )
+ {
+ arg->enableExternalOrientation = true;
+ i++;
+
+ if ( argc - i <= 4 || argv[i][0] == '-' )
+ {
+ fprintf( stderr, "Error: External orientation file name not specified!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ arg->externalOrientationTrajFileName = argv[i];
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-RENDER_CONFIG" ) == 0 )
+ {
+ arg->renderConfigEnabled = true;
+ arg->renderConfigFilename = argv[i + 1];
+
+ if ( arg->renderConfigFilename[0] == '\0' )
+ {
+ fprintf( stderr, "Error: Renderer configuration file path not specified\n\n" );
+ usage_dec();
+ return false;
+ }
+ i += 2;
+ }
+ else if ( strcmp( argv_to_upper, "-NON_DIEGETIC_PAN" ) == 0 )
+ {
+ i++;
+ arg->Opt_non_diegetic_pan = 1;
+ 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 );
+ if ( ( strcmp( argv_to_upper, "CENTER" ) == 0 ) || ( strchr( argv_to_upper, 'C' ) != NULL ) )
+ {
+ arg->non_diegetic_pan_gain = 0.f;
+ }
+ else if ( ( strcmp( argv_to_upper, "LEFT" ) == 0 ) || ( strchr( argv_to_upper, 'L' ) != NULL ) )
+ {
+ arg->non_diegetic_pan_gain = 1.f;
+ }
+ else if ( ( strcmp( argv_to_upper, "RIGHT" ) == 0 ) || ( strchr( argv_to_upper, 'R' ) != NULL ) )
+ {
+ arg->non_diegetic_pan_gain = -1.f;
+ }
+ else
+ {
+ arg->non_diegetic_pan_gain = (float) atof( argv_to_upper ) / 90.f;
+
+ if ( arg->non_diegetic_pan_gain > 1.0f || arg->non_diegetic_pan_gain < -1.0f )
+ {
+ fprintf( stderr, "Error: Incorrect value for panning gain value specified: %s\n\n", argv[i] );
+ usage_dec();
+ return false;
+ }
+ }
+ i++;
+ }
+ else if ( strcmp( argv_to_upper, "-LEVEL" ) == 0 )
+ {
+ int16_t level;
+
+ ++i;
+ level = (int16_t) atoi( argv[i++] );
+ if ( level < IVAS_DEC_COMPLEXITY_LEVEL_ONE || level > IVAS_DEC_COMPLEXITY_LEVEL_THREE )
+ {
+ fprintf( stdout, "Invalid complexity level specified.\n" );
+ usage_dec();
+ return false;
+ }
+ else if ( level == IVAS_DEC_COMPLEXITY_LEVEL_ONE || level == IVAS_DEC_COMPLEXITY_LEVEL_TWO )
+ {
+ fprintf( stdout, "Complexity levels 1 and 2 will be defined after characterisation - default to level 3 (full functionality).\n" );
+ }
+ }
+ else if ( strcmp( argv_to_upper, "-AEID" ) == 0 )
+ {
+ ++i;
+ if ( argc - i <= 4 )
+ {
+ fprintf( stderr, "Error: Acoustic environment ID not specified!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ if ( !is_digits_only( argv[i] ) )
+ {
+ fprintf( stdout, "Error: Invalid acoustic environment ID specified: %s\n\n", argv[i] );
+ usage_dec();
+ return false;
+ }
+ arg->acousticEnvironmentId = (int16_t) atoi( argv[i++] );
+ }
+ else if ( strcmp( argv_to_upper, "-DPID" ) == 0 )
+ {
+ int16_t id, tmp;
+
+ arg->Opt_dpid_on = 1;
+ ++i;
+ tmp = 0;
+ while ( is_number( argv[i + tmp] ) && tmp < IVAS_MAX_NUM_OBJECTS )
+ {
+ id = (int16_t) atoi( argv[i + tmp] );
+
+ if ( !is_digits_only( argv[i + tmp] ) || id < 0 )
+ {
+ fprintf( stdout, "Error: Invalid directivity pattern ID specified: %s\n\n", argv[i + tmp] );
+ usage_dec();
+ return false;
+ }
+
+ arg->directivityPatternId[tmp] = id;
+ ++tmp;
+ }
+
+ if ( tmp == 0 )
+ {
+ if ( argc - i <= 4 || argv[i][0] == '-' )
+ {
+ fprintf( stderr, "Error: Directivity pattern ID not specified!\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ if ( !is_digits_only( argv[i + tmp] ) )
+ {
+ fprintf( stdout, "Error: Invalid directivity pattern ID specified: %s\n\n", argv[i + tmp] );
+ usage_dec();
+ return false;
+ }
+ }
+
+ i += tmp;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Option not recognized
+ *-----------------------------------------------------------------*/
+ else
+ {
+ fprintf( stderr, "Error: Unknown option %s or wrong number of parameters!\n\n", argv[i] );
+ usage_dec();
+ return false;
+ }
+
+ } /* end of while */
+
+
+ /*-----------------------------------------------------------------*
+ * Mandatory input arguments
+ *-----------------------------------------------------------------*/
+
+ if ( i < argc - 3 )
+ {
+ arg->outputConfig = cmdline2config( argv[i] );
+ if ( arg->outputConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM )
+ {
+ arg->customLsOutputEnabled = true;
+ arg->customLsSetupFilename = argv[i];
+ }
+ i++;
+ if ( ( arg->Opt_non_diegetic_pan ) && ( arg->outputConfig != IVAS_AUDIO_CONFIG_STEREO ) )
+ {
+ fprintf( stderr, "Error: non-diegetic panning is supported in stereo only\n\n" );
+ usage_dec();
+ return false;
+ }
+ }
+ else
+ {
+ arg->outputConfig = IVAS_AUDIO_CONFIG_MONO;
+ arg->decMode = IVAS_DEC_MODE_EVS;
+ if ( ( arg->Opt_non_diegetic_pan ) )
+ {
+ arg->outputConfig = IVAS_AUDIO_CONFIG_STEREO;
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Output sampling frequency
+ *-----------------------------------------------------------------*/
+
+ if ( i < argc - 2 )
+ {
+ arg->output_Fs = (int32_t) atoi( argv[i] ) * 1000;
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "Error: Sampling rate is not specified\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Input bitstream file
+ *-----------------------------------------------------------------*/
+
+ if ( i < argc - 1 )
+ {
+ arg->inputBitstreamFilename = argv[i];
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "Error: no input bitstream file specified\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Output synthesis file name
+ *-----------------------------------------------------------------*/
+
+ if ( i < argc )
+ {
+ arg->outputWavFilename = argv[i];
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "Error: no output synthesis file specified\n\n" );
+ usage_dec();
+ return false;
+ }
+
+ if ( ( !arg->enableHeadRotation ) && ( !arg->enableExternalOrientation ) && ( !arg->tsmEnabled ) )
+ {
+ arg->enable5ms = false;
+ }
+
+ return true;
+}
+
+
+/*---------------------------------------------------------------------*
+ * usage_dec()
+ *
+ * Print the usage of the "ivas_dec" program
+ *---------------------------------------------------------------------*/
+
+static void usage_dec( void )
+{
+ fprintf( stdout, "Usage for EVS: IVAS_dec.exe [Options] Fs bitstream_file output_file\n" );
+ fprintf( stdout, "Usage for IVAS: IVAS_dec.exe [Options] OutputConf Fs bitstream_file output_file\n\n" );
+
+ fprintf( stdout, "Mandatory parameters:\n" );
+ fprintf( stdout, "---------------------\n" );
+ fprintf( stdout, "OutputConf : Output configuration: MONO, STEREO, 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4, FOA,\n" );
+ fprintf( stdout, " HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, EXT\n" );
+ fprintf( stdout, " By default, channel order and loudspeaker positions are equal to the\n" );
+ fprintf( stdout, " encoder. For loudspeaker outputs, OutputConf can be a custom loudspeaker\n" );
+ fprintf( stdout, " layout file. See readme.txt for details.\n" );
+ fprintf( stdout, " Parameter is only used when decoding IVAS bitstream.\n" );
+ fprintf( stdout, "Fs : Output sampling rate in kHz (8, 16, 32 or 48)\n" );
+ fprintf( stdout, "bitstream_file : Input bitstream filename or RTP packet filename (in VOIP mode)\n" );
+ fprintf( stdout, "output_file : Output audio filename \n\n" );
+
+ fprintf( stdout, "Options:\n" );
+ fprintf( stdout, "--------\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, " 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, " Reading RFC4867 AMR/AMR-WB RTP payload format is not supported.\n" );
+#ifdef SUPPORT_JBM_TRACEFILE
+ fprintf( stdout, "-Tracefile TF : VoIP mode: Generate trace file named TF\n" );
+#endif
+ fprintf( stdout, "-fr5 : option to perform rendering + head-tracking with 5ms frame size\n" );
+ fprintf( stdout, "-fec_cfg_file : Optimal channel aware configuration computed by the JBM \n" );
+ fprintf( stdout, " as described in Section 6.3.1 of TS26.448. The output is \n" );
+ fprintf( stdout, " written into a .txt file. Each line contains the FER indicator \n" );
+ fprintf( stdout, " (HI|LO) and optimal FEC offset. \n" );
+ fprintf( stdout, "-no_delay_cmp : Turn off delay compensation\n" );
+ fprintf( stdout, "-mime : Mime bitstream file format\n" );
+ fprintf( stdout, " The decoder may read both TS26.445 Annex.2.6 and RFC4867 Mime Storage\n" );
+ fprintf( stdout, " Format files, the magic word in the mime file is used to determine\n" );
+ fprintf( stdout, " which of the two supported formats is in use.\n" );
+ fprintf( stdout, " default bitstream file format is G.192\n" );
+ fprintf( stdout, "-hrtf File : HRTF filter File used in BINAURAL output configuration\n" );
+ fprintf( stdout, "-T File : Head rotation specified by external trajectory File\n" );
+ fprintf( stdout, "-otr tracking_type : Head orientation tracking type: 'none', 'ref', 'avg', 'ref_vec' \n" );
+ fprintf( stdout, " or 'ref_vec_lev' (only for binaural rendering)\n" );
+ fprintf( stdout, "-rf File : Reference rotation specified by external trajectory File\n" );
+ fprintf( stdout, " works only in combination with '-otr ref' mode \n" );
+ 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, "-non_diegetic_pan P : panning mono non-diegetic sound to stereo with paning 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" );
+ fprintf( stdout, "-exof File : External orientation File for external orientation trajectory\n" );
+ fprintf( stdout, "-dpid ID : Directivity pattern ID(s) = [ID1, ID2, ID3, ID4]. Space-separated list of up\n" );
+ fprintf( stdout, " to 4 numbers (unsigned integers) can be specified for BINAURAL and BINAURAL_ROOM_REVERB\n" );
+ 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) for BINAURAL_ROOM_REVERB output configuration\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" );
+ fprintf( stdout, " default is deactivated\n" );
+ fprintf( stdout, "\n" );
+
+ return;
+}
+
+
+
+/*---------------------------------------------------------------------*
+ * initOnFirstGoodFrame()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+static ivas_error initOnFirstGoodFrame(
+ IVAS_DEC_HANDLE hIvasDec, /* i/o: */
+ const DecArguments arg, /* i : */
+ const int16_t numInitialBadFrames, /* i : */
+ const uint16_t numOutSamples, /* i : */
+ int16_t *pFullDelayNumSamples, /* o : */
+ int16_t *pRemainingDelayNumSamples, /* o : */
+ int32_t *delayTimeScale, /* o : */
+ IVAS_DEC_BS_FORMAT *pBsFormat, /* i/o: */
+ AudioFileWriter **ppAfWriter, /* o : */
+ MasaFileWriter **ppMasaWriter, /* o : */
+ IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], /* o : */
+ int16_t *pNumOutChannels, /* o : */
+ uint16_t *pNumObj /* o : */
+)
+{
+ ivas_error error = IVAS_ERR_UNKNOWN;
+
+ /* Now delay, number of output channels and frame size are known */
+ if ( ( error = IVAS_DEC_GetDelay( hIvasDec, pFullDelayNumSamples, delayTimeScale ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nUnable to get delay of decoder: %s\n", ivas_error_to_string( error ) );
+ return error;
+ }
+
+
+ if ( !arg.delayCompensationEnabled )
+ {
+ pFullDelayNumSamples[0] = 0;
+ }
+ *pRemainingDelayNumSamples = pFullDelayNumSamples[0];
+
+ if ( ( error = IVAS_DEC_GetNumOutputChannels( hIvasDec, pNumOutChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetNumOutputChannels, code: %d\n", error );
+ return error;
+ }
+
+ int32_t pcmFrameSize;
+
+ if ( ( error = IVAS_DEC_GetPcmFrameSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetPcmFrameSize, error code: %d\n", error );
+ return error;
+ }
+
+ /* Open audio writer and write all previously skipped bad frames now that frame size is known */
+ if ( ( error = AudioFileWriter_open( ppAfWriter, arg.outputWavFilename, arg.output_Fs, *pNumOutChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nUnable to open output file %s\n", arg.outputWavFilename );
+ return error;
+ }
+
+ int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) );
+ memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) );
+
+ for ( int16_t i = 0; i < numInitialBadFrames; ++i )
+ {
+
+ 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 );
+
+ /* Open other output files if EXT output config - now details about ISM or MASA are known */
+ if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
+ {
+ if ( ( error = IVAS_DEC_GetFormat( hIvasDec, pBsFormat ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error );
+ return error;
+ }
+
+ /* If outputting ISM, get number of objects, open output files and write zero metadata for initial bad frames */
+ if ( *pBsFormat == IVAS_DEC_BS_OBJ || *pBsFormat == IVAS_DEC_BS_MASA_ISM || *pBsFormat == IVAS_DEC_BS_SBA_ISM )
+ {
+ if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, pNumObj ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ return error;
+ }
+
+ for ( int16_t i = 0; i < *pNumObj; ++i )
+ {
+ if ( ( error = IsmFileWriter_open( arg.outputWavFilename, i, &ismWriters[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: Error opening ISM decoded metadata file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) );
+ return error;
+ }
+ }
+
+ for ( int16_t j = 0; j < numInitialBadFrames; ++j )
+ {
+ /* write zero metadata */
+ for ( int16_t i = 0; i < *pNumObj; ++i )
+ {
+ IVAS_ISM_METADATA IsmMetadata;
+
+ if ( ( error = IVAS_DEC_GetObjectMetadata( hIvasDec, &IsmMetadata, 1, i ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetObjectMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ return error;
+ }
+
+ if ( ( error = IsmFileWriter_writeFrame( IsmMetadata, ismWriters[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing ISM metadata to file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) );
+ return error;
+ }
+ }
+ }
+ }
+
+ /* If outputting MASA, open output file and write metadata for initial bad frames */
+ if ( *pBsFormat == IVAS_DEC_BS_MASA || *pBsFormat == IVAS_DEC_BS_MASA_ISM )
+ {
+ if ( ( error = MasaFileWriter_open( arg.outputWavFilename, arg.delayCompensationEnabled, ppMasaWriter ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: Error opening MASA decoded metadata file %s\n", MasaFileWriter_getFilePath( *ppMasaWriter ) );
+ return error;
+ }
+
+ if ( numInitialBadFrames > 0 )
+ {
+ /* Duplicate good first frame metadata to fill the beginning of stream. */
+ IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta = NULL;
+ if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ return error;
+ }
+
+ for ( int16_t j = 0; j < numInitialBadFrames; ++j )
+ {
+ if ( ( error = MasaFileWriter_writeFrame( *ppMasaWriter, hMasaExtOutMeta ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( *ppMasaWriter ) );
+ return error;
+ }
+ }
+ }
+ }
+ }
+
+
+ return IVAS_ERR_OK;
+}
+
+
+/*---------------------------------------------------------------------*
+ * decodeG192()
+ *
+ * Read G.192 bitstream and decode in regular decoder
+ *---------------------------------------------------------------------*/
+
+static ivas_error decodeG192(
+ DecArguments arg,
+ BS_READER_HANDLE hBsReader,
+ RotFileReader *headRotReader,
+ RotFileReader *externalOrientationFileReader,
+ RotFileReader *refRotReader,
+ Vector3PairFileReader *referenceVectorReader,
+ IVAS_DEC_HANDLE hIvasDec,
+ int16_t *pcmBuf )
+
+{
+ bool decodingFailed = true; /* Assume failure until cleanup is reached without errors */
+ uint16_t bit_stream[IVAS_MAX_BITS_PER_FRAME + 4 * 8];
+ int16_t i, num_bits;
+ int16_t bfi = 0;
+ AudioFileWriter *afWriter = NULL;
+ MasaFileWriter *masaWriter = NULL;
+ bool decodedGoodFrame = false;
+ int16_t numInitialBadFrames = 0; /* Number of bad frames received until first good frame is decoded */
+ int16_t nOutChannels = 0;
+ int16_t delayNumSamples = -1;
+ int16_t delayNumSamples_orig[3];
+ int16_t nOutSamples = 0;
+ int32_t delayTimeScale = 0;
+ ivas_error error = IVAS_ERR_UNKNOWN;
+ uint16_t numObj = 0;
+ IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN;
+ uint16_t nSamplesAvailableNext;
+ bool needNewFrame;
+ int16_t nSamplesRendered, nSamplesRendered_loop, nSamplesToRender;
+ IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS];
+ IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
+ int16_t vec_pos_update, vec_pos_len;
+
+ for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
+ {
+ ismWriters[i] = NULL;
+ }
+
+ /* we always start with needing a new frame */
+ needNewFrame = true;
+
+
+ if ( !arg.quietModeEnabled )
+ {
+ fprintf( stdout, "\n------ Running the decoder ------\n\n" );
+ fprintf( stdout, "Frames processed: " );
+ }
+ else
+ {
+ fprintf( stdout, "\n-- Start the decoder (quiet mode) --\n\n" );
+ }
+
+ delayNumSamples_orig[0] = -1;
+
+#ifdef WMOPS
+ reset_stack();
+ reset_wmops();
+#endif
+ nSamplesAvailableNext = 0;
+
+ vec_pos_update = 0;
+ if ( arg.enableHeadRotation && arg.enable5ms )
+ {
+ nOutSamples = (int16_t) ( arg.output_Fs / 1000 * HEADROTATION_FETCH_FRAMESIZE_MS );
+ vec_pos_len = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES;
+ }
+ else
+ {
+ nOutSamples = (int16_t) ( arg.output_Fs / 1000 * DEFAULT_FETCH_FRAMESIZE_MS );
+ vec_pos_len = 1;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Loop for every packet (frame) of bitstream data
+ * - Read the bitstream packet
+ * - Run the decoder
+ * - Write the synthesized signal into output file
+ *------------------------------------------------------------------------------------------*/
+
+ while ( 1 )
+ {
+ /* Read next frame if not enough samples availble */
+
+ /* reference vector */
+ if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 )
+ {
+ IVAS_VECTOR3 listenerPosition, referencePosition;
+ if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) );
+ goto cleanup;
+ }
+
+ if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+
+ /* Reference rotation */
+ if ( arg.enableReferenceRotation && vec_pos_update == 0 )
+ {
+ IVAS_QUATERNION quaternion;
+ if ( ( error = HeadRotationFileReading( refRotReader, &quaternion, NULL ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( refRotReader ) );
+ goto cleanup;
+ }
+
+ if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+
+ int16_t enable5ms, num_subframes;
+ if ( ( error = IVAS_DEC_Get5msFlag( hIvasDec, &enable5ms ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ arg.enable5ms = enable5ms;
+ num_subframes = ( arg.enable5ms ) ? 1 : IVAS_MAX_PARAM_SPATIAL_SUBFRAMES;
+
+ /* Head-tracking input simulation */
+ /* Head-tracking input simulation */
+ if ( arg.enableHeadRotation )
+ {
+ IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
+
+ for ( i = 0; i < num_subframes; i++ )
+ {
+ if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) );
+ goto cleanup;
+ }
+ }
+
+ for ( i = 0; i < num_subframes; i++ )
+ {
+ if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+ }
+
+ 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++ )
+ {
+ if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( externalOrientationFileReader ) );
+ goto cleanup;
+ }
+ }
+ for ( i = 0; i < num_subframes; i++ )
+ {
+ if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions[i], enableHeadRotation[i], enableExternalOrientation[i], enableRotationInterpolation[i], numFramesToTargetOrientation[i], i ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedExternalOrientationData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+ }
+
+ /* decode and get samples */
+ nSamplesRendered = 0;
+ nSamplesToRender = nOutSamples;
+ do
+ {
+ if ( needNewFrame )
+ {
+ if ( ( error = BS_Reader_ReadFrame_short( hBsReader, bit_stream, &num_bits, &bfi ) ) != IVAS_ERR_OK )
+ {
+ if ( error == IVAS_ERR_END_OF_FILE )
+ {
+ break;
+ }
+ fprintf( stderr, "\nError: input bitstream file couldn't be read: %s \n\n", arg.inputBitstreamFilename );
+ goto cleanup;
+ }
+
+ /* Feed into decoder */
+ if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, bit_stream, num_bits, bfi ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError: could not feed frame to decoder: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+
+ if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
+
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ nSamplesRendered += nSamplesRendered_loop;
+ nSamplesToRender -= nSamplesRendered_loop;
+
+ } while ( nSamplesRendered < nOutSamples && error == IVAS_ERR_OK );
+
+ if ( error == IVAS_ERR_END_OF_FILE )
+ {
+ break;
+ }
+
+ /* Continue checking for first good frame until it is found */
+ if ( !decodedGoodFrame )
+ {
+ if ( ( error = IVAS_DEC_HasDecodedFirstGoodFrame( hIvasDec, &decodedGoodFrame ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_HasDecodedFirstGoodFrame, code: %d\n", error );
+ goto cleanup;
+ }
+
+ /* Once good frame decoded, catch up */
+ if ( decodedGoodFrame )
+ {
+ if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, nOutSamples, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj ) ) != IVAS_ERR_OK )
+ {
+ goto cleanup;
+ }
+ }
+ else
+ {
+ ++numInitialBadFrames;
+ }
+ }
+
+ /* Write current frame */
+ if ( decodedGoodFrame )
+ {
+ if ( delayNumSamples < nOutSamples )
+ {
+ if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nOutput audio file writer error\n" );
+ goto cleanup;
+ }
+ delayNumSamples = 0;
+ }
+ else
+ {
+ delayNumSamples -= nOutSamples;
+ }
+ }
+
+ /* Write ISm metadata to external file(s) */
+ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
+ {
+ if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM )
+ {
+ if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ for ( i = 0; i < numObj; ++i )
+ {
+ IVAS_ISM_METADATA IsmMetadata;
+
+ if ( ( error = IVAS_DEC_GetObjectMetadata( hIvasDec, &IsmMetadata, 0, i ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetObjectMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( IsmFileWriter_writeFrame( IsmMetadata, ismWriters[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing ISM metadata to file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) );
+ goto cleanup;
+ }
+ }
+ }
+
+ if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM )
+ {
+ IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta;
+ if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMasaExtOutMeta ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) );
+ goto cleanup;
+ }
+ }
+ }
+ vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len;
+ if ( needNewFrame )
+ {
+ frame++;
+ if ( !arg.quietModeEnabled )
+ {
+ fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame );
+ }
+ }
+#ifdef WMOPS
+ if ( vec_pos_update == 0 )
+ {
+ update_wmops();
+ update_mem();
+#ifdef MEM_COUNT_DETAILS
+ export_mem( "mem_analysis.csv" );
+#endif
+ }
+#endif
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Flush what is still left in the VoIP Buffers....
+ *------------------------------------------------------------------------------------------*/
+
+ while ( nSamplesAvailableNext > 0 )
+ {
+ int16_t nSamplesFlushed;
+
+ /* Feed into decoder */
+
+ /* reference vector */
+ if ( arg.enableReferenceVectorTracking )
+ {
+ IVAS_VECTOR3 listenerPosition, referencePosition;
+ if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) );
+ goto cleanup;
+ }
+
+ if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+
+ /* Reference rotation */
+ if ( arg.enableReferenceRotation )
+ {
+ IVAS_QUATERNION quaternion;
+ if ( ( error = HeadRotationFileReading( refRotReader, &quaternion, NULL ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( refRotReader ) );
+ goto cleanup;
+ }
+
+ if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+
+ /* Head-tracking input simulation */
+ if ( arg.enableHeadRotation )
+ {
+ IVAS_QUATERNION Quaternion;
+ if ( ( error = HeadRotationFileReading( headRotReader, &Quaternion, &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 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ }
+
+ /* decode and get samples */
+ if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ /* Write current frame */
+ if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, nSamplesFlushed * nOutChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nOutput audio file writer error\n" );
+ goto cleanup;
+ }
+
+ /* Write ISm metadata to external file(s) */
+ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
+ {
+ if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM )
+ {
+ if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ for ( i = 0; i < numObj; ++i )
+ {
+ IVAS_ISM_METADATA IsmMetadata;
+
+ if ( ( error = IVAS_DEC_GetObjectMetadata( hIvasDec, &IsmMetadata, 0, i ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetObjectMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( IsmFileWriter_writeFrame( IsmMetadata, ismWriters[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing ISM metadata to file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) );
+ goto cleanup;
+ }
+ }
+ }
+
+ if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM )
+ {
+ IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta;
+ if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMasaExtOutMeta ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) );
+ goto cleanup;
+ }
+ }
+ }
+
+ frame++;
+ if ( !arg.quietModeEnabled )
+ {
+ fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame );
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Printouts after decoding has finished
+ *------------------------------------------------------------------------------------------*/
+
+ if ( !arg.quietModeEnabled )
+ {
+ printf( "\n\nDecoder+renderer delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[1] / (float) delayTimeScale, delayNumSamples_orig[1], delayTimeScale );
+
+ if ( delayNumSamples_orig[2] > 0 )
+ {
+ printf( "HRIR/BRIR delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[2] / (float) delayTimeScale, delayNumSamples_orig[2], delayTimeScale );
+ printf( "Total delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * ( delayNumSamples_orig[1] + delayNumSamples_orig[2] ) / (float) delayTimeScale, delayNumSamples_orig[1] + delayNumSamples_orig[2], delayTimeScale );
+ }
+ }
+
+ /* Print output metadata file name(s) */
+ if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
+ {
+ if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM )
+ {
+ for ( i = 0; i < numObj; i++ )
+ {
+ fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) );
+ }
+ fprintf( stdout, "\n" );
+ }
+
+ if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM )
+ {
+ fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) );
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Add zeros at the end to have equal length of synthesized signals
+ *------------------------------------------------------------------------------------------*/
+
+ memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) );
+ 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;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Close files and deallocate resources
+ *------------------------------------------------------------------------------------------*/
+
+ decodingFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */
+
+cleanup:
+
+ AudioFileWriter_close( &afWriter );
+ MasaFileWriter_close( &masaWriter );
+ for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ )
+ {
+ IsmFileWriter_close( &ismWriters[i] );
+ }
+
+ if ( decodingFailed && error == IVAS_ERR_OK )
+ {
+ return IVAS_ERR_UNKNOWN;
+ }
+
+ return error;
+}
+
+
+#ifdef SUPPORT_JBM_TRACEFILE
+static ivas_error writeJbmTraceFileFrameWrapper( const void *data, void *writer )
+{
+ return JbmTraceFileWriter_writeFrame( data, writer );
+}
+#endif
+
+
+/*---------------------------------------------------------------------*
+ * decodeVoIP()
+ *
+ * Read G.192 or RTPDUMP bitstream and decode in VOIP
+ *---------------------------------------------------------------------*/
+
+static ivas_error decodeVoIP(
+ DecArguments arg,
+ BS_READER_HANDLE hBsReader,
+ IVAS_DEC_HANDLE hIvasDec )
+{
+ bool decodingFailed = true; /* Assume failure until cleanup is reached without errors */
+ ivas_error error = IVAS_ERR_OK;
+
+ uint32_t nextPacketRcvTime_ms = 0;
+ uint32_t systemTime_ms = 0;
+ uint32_t systemTimeInc_ms = (uint32_t) JBM_FRONTEND_FETCH_FRAMESIZE_MS;
+ int32_t nFramesFed = 0;
+
+ uint8_t au[( IVAS_MAX_BITS_PER_FRAME + 7 ) >> 3];
+ int16_t auSize;
+ uint16_t rtpSequenceNumber;
+ uint32_t rtpTimeStamp;
+
+ bool decodedGoodFrame = false;
+ int16_t numInitialBadFrames = 0; /* Number of bad frames received until first good frame is decoded */
+ int16_t nOutChannels = 0;
+ MasaFileWriter *masaWriter = NULL;
+ uint16_t numObj = 0;
+
+ int16_t pcmBuf[MAX_OUTPUT_PCM_BUFFER_SIZE];
+ AudioFileWriter *afWriter = NULL;
+#ifdef SUPPORT_JBM_TRACEFILE
+ JbmTraceFileWriter *jbmTraceWriter = NULL;
+#endif
+ JbmOffsetFileWriter *jbmOffsetWriter = NULL;
+
+ int16_t delayNumSamples_orig[3]; /* stores: overall delay, dec+rend delay, and binauralization delay */
+ 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;
+ 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];
+
+ for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
+ {
+ ismWriters[i] = NULL;
+ }
+
+ 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 )
+ {
+ fprintf( stderr, "error in EVS_RTPDUMP_DEPACKER_open(): %d\n", rtpdumpDepackerError );
+ goto cleanup;
+ }
+ break;
+ case IVAS_DEC_INPUT_FORMAT_G192:
+ auPtr = au;
+ break;
+ default:
+ fprintf( stderr, "Unsupported format of input bitstream" );
+ goto cleanup;
+ }
+
+
+#ifdef SUPPORT_JBM_TRACEFILE
+ if ( arg.jbmTraceFilename != NULL )
+ {
+ if ( ( error = JbmTraceFileWriter_open( arg.jbmTraceFilename, &jbmTraceWriter ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Could not open: %s\n", arg.jbmTraceFilename );
+ goto cleanup;
+ }
+ fprintf( stdout, "JBM trace file: %s\n", arg.jbmTraceFilename );
+ }
+#endif
+
+ if ( arg.jbmOffsetFilename != NULL )
+ {
+ if ( ( error = JbmOffsetFileWriter_open( arg.jbmOffsetFilename, &jbmOffsetWriter ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Could not open CA offset file: %s\n", arg.jbmOffsetFilename );
+ goto cleanup;
+ }
+ fprintf( stdout, "JBM CA offset file: %s\n", arg.jbmOffsetFilename );
+ }
+
+ /* read first packet */
+ if ( arg.inputFormat == IVAS_DEC_INPUT_FORMAT_G192 )
+ {
+ error = BS_Reader_ReadVoipFrame_compact( hBsReader, au, &auSize, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms );
+ qBit = 1; /* good q_bit for INPUT_FORMAT_G192 */
+ }
+ 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 */
+ rtpTimeStamp = rtpTimeStamp / 16;
+ }
+ if ( error != IVAS_ERR_OK || rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR )
+ {
+ fprintf( stderr, "failed to read first RTP packet\n" );
+ goto cleanup;
+ }
+
+ if ( !arg.quietModeEnabled )
+ {
+ fprintf( stdout, "\n------ Running the decoder ------\n\n" );
+ fprintf( stdout, "Frames processed: " );
+ }
+ else
+ {
+ fprintf( stdout, "\n-- Start the decoder (quiet mode) --\n\n" );
+ }
+
+#ifdef WMOPS
+ reset_stack();
+ reset_wmops();
+#endif
+
+ /*------------------------------------------------------------------------------------------*
+ * Main receiving/decoding loop
+ *------------------------------------------------------------------------------------------*/
+
+
+ while ( 1 )
+ {
+ int16_t nOutSamples = 0;
+ nOutSamples = (int16_t) ( arg.output_Fs / 1000 * JBM_FRONTEND_FETCH_FRAMESIZE_MS );
+
+ /* read all packets with a receive time smaller than the system time */
+ while ( nextPacketRcvTime_ms <= systemTime_ms )
+ {
+ /* feed the previous read packet into the receiver now */
+ error = IVAS_DEC_VoIP_FeedFrame( hIvasDec, auPtr, auSize, rtpSequenceNumber, rtpTimeStamp, nextPacketRcvTime_ms, qBit );
+ if ( error != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_VoIP_FeedFrame: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+ ++nFramesFed;
+
+ /* read the next packet */
+ if ( arg.inputFormat == IVAS_DEC_INPUT_FORMAT_G192 )
+ {
+ error = BS_Reader_ReadVoipFrame_compact( hBsReader, au, &auSize, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms );
+
+ qBit = 1; /* good q_bit for VOIP_G192_RTP */
+ }
+ 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 */
+ rtpTimeStamp = rtpTimeStamp / 16;
+ }
+ if ( error == IVAS_ERR_END_OF_FILE || rtpdumpDepackerError == EVS_RTPDUMP_DEPACKER_EOF )
+ {
+ /* finished reading */
+ nextPacketRcvTime_ms = (uint32_t) -1;
+ }
+ else if ( error != IVAS_ERR_OK || rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR )
+ {
+ fprintf( stderr, "\nError in BS_Reader_ReadVoipFrame_compact, error code: %d\n", error );
+ goto cleanup;
+ }
+ }
+
+ /* 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 ) )
+ {
+ break;
+ }
+
+
+ /* decode and get samples */
+
+#ifdef SUPPORT_JBM_TRACEFILE
+ if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK )
+#else
+ if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK )
+#endif
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ /* write JBM Offset file entry */
+ if ( jbmOffsetWriter != NULL )
+ {
+ int16_t optimum_offset, FEC_hi;
+
+ if ( ( error = IVAS_DEC_VoIP_Get_CA_offset( hIvasDec, &optimum_offset, &FEC_hi ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_VoIP_Get_CA_offset: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( JbmOffsetFileWriter_writeFrame( FEC_hi, optimum_offset, jbmOffsetWriter ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing JBM Offset data to file %s\n", arg.jbmOffsetFilename );
+ goto cleanup;
+ }
+ }
+
+ /* Continue checking for first good frame until it is found */
+ if ( !decodedGoodFrame )
+ {
+ if ( ( error = IVAS_DEC_HasDecodedFirstGoodFrame( hIvasDec, &decodedGoodFrame ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame, code: %d\n", error );
+ goto cleanup;
+ }
+
+ /* Once good frame decoded, catch up */
+ if ( decodedGoodFrame )
+ {
+ if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, nOutSamples, delayNumSamples_orig, &delayNumSamples, &delayTimeScale,
+ &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj ) ) != IVAS_ERR_OK )
+ {
+ goto cleanup;
+ }
+ }
+ else
+ {
+ ++numInitialBadFrames;
+ }
+ }
+
+ /* Write current frame */
+ if ( decodedGoodFrame )
+ {
+ if ( delayNumSamples < nOutSamples )
+ {
+ if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nOutput audio file writer error\n" );
+ goto cleanup;
+ }
+ delayNumSamples = 0;
+ }
+ else
+ {
+ delayNumSamples -= nOutSamples;
+ }
+
+ /* Write ISM metadata to external file(s) */
+ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
+ {
+ if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM )
+ {
+ if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ for ( i = 0; i < numObj; ++i )
+ {
+ IVAS_ISM_METADATA IsmMetadata;
+
+ if ( ( error = IVAS_DEC_GetObjectMetadata( hIvasDec, &IsmMetadata, 0, i ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetObjectMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( IsmFileWriter_writeFrame( IsmMetadata, ismWriters[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing ISM metadata to file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) );
+ goto cleanup;
+ }
+ }
+ }
+
+ if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM )
+ {
+ IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta;
+ if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 1 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
+ goto cleanup;
+ }
+
+ if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMasaExtOutMeta ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) );
+ goto cleanup;
+ }
+ }
+ }
+ }
+
+ if ( !arg.quietModeEnabled )
+ {
+ fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame );
+ }
+
+ frame++;
+ systemTime_ms += systemTimeInc_ms;
+
+#ifdef WMOPS
+ update_mem();
+ update_wmops();
+#endif
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Add zeros at the end to have equal length of synthesized signals
+ *------------------------------------------------------------------------------------------*/
+
+ memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) );
+ 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;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Printouts after decoding has finished
+ *------------------------------------------------------------------------------------------*/
+
+ if ( !arg.quietModeEnabled )
+ {
+ printf( "\n\nDecoder+renderer delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[1] / (float) delayTimeScale, delayNumSamples_orig[1], delayTimeScale );
+
+ if ( delayNumSamples_orig[2] > 0 )
+ {
+ printf( "HRIR/BRIR delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[2] / (float) delayTimeScale, delayNumSamples_orig[2], delayTimeScale );
+ printf( "Total delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * ( delayNumSamples_orig[1] + delayNumSamples_orig[2] ) / (float) delayTimeScale, delayNumSamples_orig[1] + delayNumSamples_orig[2], delayTimeScale );
+ }
+ }
+
+ /* Print output metadata file name(s) */
+ if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
+ {
+ if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM )
+ {
+ for ( i = 0; i < numObj; i++ )
+ {
+ fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) );
+ }
+ fprintf( stdout, "\n" );
+ }
+
+ if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM )
+ {
+ fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) );
+ }
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Close files and deallocate resources
+ *------------------------------------------------------------------------------------------*/
+
+ decodingFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */
+
+cleanup:
+
+ EVS_RTPDUMP_DEPACKER_close( &rtpdumpDepacker );
+ AudioFileWriter_close( &afWriter );
+ JbmOffsetFileWriter_close( &jbmOffsetWriter );
+#ifdef SUPPORT_JBM_TRACEFILE
+ JbmTraceFileWriter_close( &jbmTraceWriter );
+#endif
+ MasaFileWriter_close( &masaWriter );
+ for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ )
+ {
+ IsmFileWriter_close( &ismWriters[i] );
+ }
+
+ if ( decodingFailed && error == IVAS_ERR_OK )
+ {
+ return IVAS_ERR_UNKNOWN;
+ }
+
+ return error;
+}
+
+
diff --git a/apps/encoder.c b/apps/encoder.c
new file mode 100644
index 0000000000000000000000000000000000000000..31c6c334b310a7a5676492ce455fe3c19b333d23
--- /dev/null
+++ b/apps/encoder.c
@@ -0,0 +1,1746 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "lib_enc.h"
+#include
+#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 "wmc_auto.h"
+
+
+#define WMC_TOOL_SKIP
+
+/*------------------------------------------------------------------------------------------*
+ * Local constants, enums
+ *------------------------------------------------------------------------------------------*/
+
+#if !defined( WMOPS )
+static
+#endif
+ int32_t frame = 0; /* Counter of frames */
+
+#define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */
+
+/* Additional config info for each input format */
+typedef union _EncInputFormatConfig
+{
+ /* MONO details */
+ bool stereoToMonoDownmix;
+
+
+ /* 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;
+ bool pca;
+ bool ism_extended_metadata;
+
+} EncArguments;
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local functions prototypes
+ *------------------------------------------------------------------------------------------*/
+
+static void initArgStruct( EncArguments *arg );
+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 );
+
+
+/*------------------------------------------------------------------------------------------*
+ * main()
+ *
+ * Main IVAS encoder function for command-line interface
+ *------------------------------------------------------------------------------------------*/
+
+int main(
+ int argc,
+ char *argv[] )
+{
+ 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;
+
+#ifdef WMOPS
+ reset_wmops();
+ reset_mem( USE_32BITS );
+#endif
+
+ initArgStruct( &arg );
+
+ /*------------------------------------------------------------------------------------------*
+ * Parse command-line arguments
+ *------------------------------------------------------------------------------------------*/
+
+ IVAS_ENC_PrintDisclaimer();
+
+ 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( &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 ( 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;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * 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:
+ if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural ) ) != IVAS_ERR_OK )
+ {
+ 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 ) );
+ exit( -1 );
+ }
+ 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 );
+ }
+ 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;
+ }
+ }
+ }
+
+
+ /*------------------------------------------------------------------------------------------*
+ * 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;
+ }
+ }
+
+ 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, "JbmFileReader_readCAconfig() failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
+ 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;
+ }
+ }
+
+ /* 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 ( ( 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 );
+ }
+
+ IVAS_ENC_Close( &hIvasEnc );
+
+#ifdef WMOPS
+ print_wmops();
+ print_mem( NULL );
+#endif
+
+ return mainFailed ? -1 : 0;
+}
+
+
+/*-------------------------------------------------------------------*
+ * Local functions
+ *-------------------------------------------------------------------*/
+
+#define IVAS_DEFAULT_AGC ( 0 )
+
+static void initArgStruct( EncArguments *arg )
+{
+ /* Set default values here */
+ 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->pca = false;
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * 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;
+
+ 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;
+ }
+ }
+
+
+ /*-----------------------------------------------------------------*
+ * 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;
+
+ }
+ 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();
+ }
+ 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();
+ }
+ }
+ }
+ else
+ {
+ fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" );
+ usage_enc();
+ }
+ 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();
+ break;
+ }
+ }
+
+ /* 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();
+ }
+ }
+
+ if ( i < argc - 4 )
+ {
+ arg->masaMetadataFile = argv[i];
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "Error: not enough MASA arguments\n\n" );
+ usage_enc();
+ }
+ }
+ 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();
+ }
+ 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();
+ }
+ }
+ }
+ else
+ {
+ fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" );
+ usage_enc();
+ }
+
+ 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();
+ }
+ }
+ }
+ 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, "-BYPASS" ) == 0 ) // TODO: should be renamed to "-pca"
+ {
+ i++;
+ if ( i < argc - 4 )
+ {
+ switch ( atoi( argv[i] ) )
+ {
+ case 1:
+ {
+ arg->pca = 0;
+ break;
+ }
+ case 2:
+ {
+ arg->pca = 1;
+ break;
+ }
+ default:
+ {
+ fprintf( stderr, "Error: SBA PCA bypass argument is out of range (%d), expected 1 or 2\n", (int32_t) atoi( argv[i] ) );
+ usage_enc();
+ return false;
+ }
+ }
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "Error: SBA unspecified PCA BYPASS value \n\n" );
+ usage_enc();
+ return false;
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * 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 in EVS, stereo, ISM, SBA up to 80kbps and MASA up to 128kbps \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, "-bypass mode : SBA PCA by-pass, mode = (1, 2), 1 = PCA off, 2 = signal adaptive, default is 1\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 counters\n" );
+ fprintf( stdout, " default is deactivated\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;
+}
+
+
diff --git a/apps/renderer.c b/apps/renderer.c
new file mode 100644
index 0000000000000000000000000000000000000000..7a04cfb0bdbf67b3ac254abb2f1221482f1af16e
--- /dev/null
+++ b/apps/renderer.c
@@ -0,0 +1,3283 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "lib_rend.h"
+#include
+#include
+#include
+#include "audio_file_reader.h"
+#include "audio_file_writer.h"
+#include "cmdl_tools.h"
+#include "cmdln_parser.h"
+#include "hrtf_file_reader.h"
+#include "ism_file_reader.h"
+#include "ls_custom_file_reader.h"
+#include "masa_file_reader.h"
+#include "masa_file_writer.h"
+#include "render_config_reader.h"
+#include "rotation_file_reader.h"
+#include "vector3_pair_file_reader.h"
+#include "wmc_auto.h"
+
+
+#define WMC_TOOL_SKIP
+
+/*------------------------------------------------------------------------------------------*
+ * Local constants
+ *------------------------------------------------------------------------------------------*/
+
+#define RENDERER_MAX_CLI_ARG_LENGTH ( FILENAME_MAX )
+#define RENDERER_MAX_METADATA_LENGTH 8192
+#define RENDERER_MAX_METADATA_LINE_LENGTH 1024
+
+
+#define IVAS_MAX16B_FLT 32767.0f
+#define IVAS_MIN16B_FLT ( -32768.0f )
+
+#if !defined( WMOPS )
+static
+#endif
+ int32_t frame = 0;
+
+#ifdef _WIN32
+#define SEP_FOLDER '\\'
+#else
+#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 struct
+{
+ uint32_t frameCounter;
+ uint16_t numObjects;
+ IsmFileReader *ismReaders[RENDERER_MAX_ISM_INPUTS];
+ uint32_t numPositions[RENDERER_MAX_ISM_INPUTS];
+ IVAS_ISM_METADATA *positions[RENDERER_MAX_ISM_INPUTS]; /* size: [RENDERER_MAX_ISM_INPUTS][numPositions[object_index]] */
+ uint16_t *positionDurations[RENDERER_MAX_ISM_INPUTS]; /* size: [RENDERER_MAX_ISM_INPUTS][numPositions[object_index]] */
+ uint32_t currentPositionIdxs[RENDERER_MAX_ISM_INPUTS]; /* Index of current position as listed in the metadata file */
+ uint16_t durationCounters[RENDERER_MAX_ISM_INPUTS]; /* Number of frames spent at current position */
+} IsmPositionProvider;
+
+typedef struct
+{
+ float lfe_azi;
+ float lfe_ele;
+ float lfe_gain_dB;
+ char lfe_routing_mtx[FILENAME_MAX];
+} LfeRoutingConfig;
+
+typedef struct
+{
+ IVAS_AUDIO_CONFIG audioConfig;
+ int32_t inputChannelIndex;
+ float gain_dB;
+} RendererInput;
+
+typedef struct
+{
+ IVAS_ISM_METADATA positions[RENDERER_MAX_ISM_INPUTS];
+ int16_t numObjects;
+} ObjectPositionBuffer;
+
+typedef struct
+{
+ RendererInput audioObjects[RENDERER_MAX_ISM_INPUTS];
+ uint16_t numAudioObjects;
+ RendererInput multiChannelBuses[RENDERER_MAX_MC_INPUTS];
+ uint16_t numMultiChannelBuses;
+ RendererInput ambisonicsBuses[RENDERER_MAX_SBA_INPUTS];
+ uint16_t numAmbisonicsBuses;
+ IVAS_CUSTOM_LS_DATA inSetupCustom;
+ RendererInput masaBuses[RENDERER_MAX_MASA_INPUTS];
+ uint16_t numMasaBuses;
+} InputConfig;
+
+typedef struct
+{
+ IVAS_AUDIO_CONFIG audioConfig;
+ IVAS_CUSTOM_LS_DATA outSetupCustom;
+} OutputConfig;
+
+typedef struct
+{
+ char executableName[RENDERER_MAX_CLI_ARG_LENGTH];
+ char inputFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
+ char outputFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
+ int32_t sampleRate;
+ InputConfig inConfig;
+ OutputConfig outConfig;
+ char inMetadataFilePaths[RENDERER_MAX_ISM_INPUTS][RENDERER_MAX_CLI_ARG_LENGTH];
+ int16_t numInMetadataFiles;
+ char headRotationFilePath[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];
+ char customHrtfFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
+ char renderConfigFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
+ int8_t orientation_tracking;
+ int16_t nonDiegeticPan;
+ float nonDiegeticPanGain;
+ IVAS_REND_COMPLEXITY_LEVEL complexityLevel;
+ bool delayCompensationEnabled;
+ bool quietModeEnabled;
+ bool sceneDescriptionInput;
+ float inputGainGlobal; /* Linear gain (not in dB) */
+ bool lfePanningEnabled;
+ float lfeConfigGain; /* Linear gain (not in dB) */
+ float lfeConfigAzimuth;
+ float lfeConfigElevation;
+ bool lfeCustomRoutingEnabled;
+ char inLfePanningMatrixFile[RENDERER_MAX_CLI_ARG_LENGTH];
+ float syncMdDelay;
+ bool framing_5ms;
+ uint16_t directivityPatternId[RENDERER_MAX_ISM_INPUTS];
+ uint16_t acousticEnvironmentId;
+} CmdlnArgs;
+
+typedef enum
+{
+ CmdLnOptionId_inputFile = 1,
+ CmdLnOptionId_inputFormat,
+ CmdLnOptionId_outputFile,
+ CmdLnOptionId_outputFormat,
+ CmdLnOptionId_sampleRate,
+ CmdLnOptionId_trajFile,
+ CmdLnOptionId_refRotFile,
+ CmdLnOptionId_customHrtfFile,
+ CmdLnOptionId_renderConfigFile,
+ CmdLnOptionId_nonDiegeticPan,
+ CmdLnOptionId_orientationTracking,
+ CmdlnOptionId_lfePosition,
+ CmdlnOptionId_lfeMatrix,
+ CmdLnOptionId_complexityLevel,
+ CmdLnOptionId_noDelayCmp,
+ CmdLnOptionId_quietModeEnabled,
+ CmdLnOptionId_inputMetadata,
+ CmdLnOptionId_listFormats,
+ CmdLnOptionId_inputGain,
+ CmdLnOptionId_referenceVectorFile,
+ CmdLnOptionId_exteriorOrientationFile,
+ CmdLnOptionId_framing5ms,
+ CmdLnOptionId_syncMdDelay,
+ CmdLnOptionId_directivityPatternId,
+ CmdLnOptionId_acousticEnvironmentId
+} CmdLnOptionId;
+
+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)",
+ },
+ {
+ .id = CmdLnOptionId_inputFormat,
+ .match = "input_format",
+ .matchShort = "if",
+ .description = "Audio format of input file (e.g. 5_1 or HOA3 or META, use -l for a list)",
+ },
+ {
+ .id = CmdLnOptionId_inputMetadata,
+ .match = "input_metadata",
+ .matchShort = "im",
+ .description = "Space-separated list of path to metadata files for ISM or MASA inputs",
+ },
+ {
+ .id = CmdLnOptionId_outputFile,
+ .match = "output_file",
+ .matchShort = "o",
+ .description = "Path to the output file",
+ },
+ {
+ .id = CmdLnOptionId_outputFormat,
+ .match = "output_format",
+ .matchShort = "of",
+ .description = "Output format to render.\nAlternatively, can be a custom loudspeaker layout file",
+ },
+ {
+ .id = CmdLnOptionId_sampleRate,
+ .match = "sample_rate",
+ .matchShort = "fs",
+ .description = "Input sampling rate in kHz (16, 32, 48) - required only with raw PCM inputs",
+ },
+ {
+ .id = CmdLnOptionId_trajFile,
+ .match = "trajectory_file",
+ .matchShort = "tf",
+ .description = "Head rotation trajectory file for simulation of head tracking (only for binaural outputs)",
+ },
+ {
+ .id = CmdLnOptionId_refRotFile,
+ .match = "reference_rotation_file",
+ .matchShort = "rf",
+ .description = "Reference rotation trajectory file for simulation of head tracking (only for binaural outputs)",
+ },
+ {
+ .id = CmdLnOptionId_customHrtfFile,
+ .match = "custom_hrtf",
+ .matchShort = "hrtf",
+ .description = "Custom HRTF file for binaural rendering (only for binaural outputs)",
+ },
+ {
+ .id = CmdLnOptionId_renderConfigFile,
+ .match = "render_config",
+ .matchShort = "rc",
+ .description = "Binaural renderer configuration file (only for binaural outputs)",
+ },
+ {
+ .id = CmdLnOptionId_nonDiegeticPan,
+ .match = "non_diegetic_pan",
+ .matchShort = "ndp",
+ .description = "Panning mono non diegetic sound to stereo -90<= pan <= 90\nleft or l or 90->left, right or r or -90->right, center or c or 0 ->middle\n",
+ },
+ {
+ .id = CmdLnOptionId_orientationTracking,
+ .match = "tracking_type",
+ .matchShort = "otr",
+ .description = "Head orientation tracking type: 'none', 'ref', 'avg' or `ref_vec` or `ref_vec_lev` (only for binaural outputs)",
+ },
+ {
+ .id = CmdlnOptionId_lfePosition,
+ .match = "lfe_position",
+ .matchShort = "lp",
+ .description = "Output LFE position. Comma-delimited triplet of [gain, azimuth, elevation] where gain is linear (like --gain, -g) and azimuth, elevation are in degrees.\nIf specified, overrides the default behavior which attempts to map input to output LFE channel(s)",
+ },
+ { .id = CmdlnOptionId_lfeMatrix,
+ .match = "lfe_matrix",
+ .matchShort = "lm",
+ .description = "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). \nIf specified, overrides the output LFE position option and the default behavior which attempts to map input to output LFE channel(s)" },
+ {
+ .id = CmdLnOptionId_noDelayCmp,
+ .match = "no_delay_cmp",
+ .matchShort = "ndc",
+ .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.",
+ },
+ {
+ .id = CmdLnOptionId_quietModeEnabled,
+ .match = "quiet",
+ .matchShort = "q",
+ .description = "[flag] Limit printouts to terminal",
+ },
+ {
+ .id = CmdLnOptionId_inputGain,
+ .match = "gain",
+ .matchShort = "g",
+ .description = "Input gain (linear, not in dB) to be applied to input audio file",
+ },
+ {
+ .id = CmdLnOptionId_listFormats,
+ .match = "list",
+ .matchShort = "l",
+ .description = "List supported audio formats",
+ },
+ {
+ .id = CmdLnOptionId_referenceVectorFile,
+ .match = "reference_vector_file",
+ .matchShort = "rvf",
+ .description = "Reference vector trajectory file for simulation of head tracking (only for binaural outputs)",
+ },
+ {
+ .id = CmdLnOptionId_exteriorOrientationFile,
+ .match = "exterior_orientation_file",
+ .matchShort = "exof",
+ .description = "External orientation trajectory file for simulation of external orientations",
+ },
+ {
+ .id = CmdLnOptionId_framing5ms,
+ .match = "framing_5ms",
+ .matchShort = "fr5",
+ .description = "Render audio with 5 ms framing.",
+ },
+ {
+ .id = CmdLnOptionId_syncMdDelay,
+ .match = "sync_md_delay",
+ .matchShort = "smd",
+ .description = "Metadata Synchronization Delay in ms, Default is 0. Quantized by 5ms subframes for TDRenderer (13ms -> 10ms -> 2subframes)",
+ },
+ {
+ .id = CmdLnOptionId_directivityPatternId,
+ .match = "ism_directivity_pattern_id",
+ .matchShort = "dpid",
+ .description = "Directivity pattern ID(s) = [ID1, ID2, ID3, ID4]. Space-separated list of up to 4 numbers (unsigned integers) can be specified for BINAURAL and BINAURAL_ROOM_REVERB output configuration.\nID1, ID2, ID3, ID4 specify the directivity pattern IDs used for ISMs 1,2,3 and 4 respectively.\nThis options needs to be accompanied by a render_config file, otherwise a default directivity pattern is used.",
+ },
+ {
+ .id = CmdLnOptionId_acousticEnvironmentId,
+ .match = "acoustic_environment_id",
+ .matchShort = "aeid",
+ .description = "Acoustic environment ID (number >= 0) for BINAURAL_ROOM_REVERB output configuration",
+ },
+};
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local function prototypes
+ *------------------------------------------------------------------------------------------*/
+
+static const int32_t numCliOptions = sizeof( cliOptions ) / sizeof( CmdLnParser_Option );
+
+static IVAS_AUDIO_CONFIG ambisonicsOrderToEnum( const int16_t order );
+
+static void parseSceneDescriptionFile( char *path, char *audioFilePath, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders, LfeRoutingConfig **lfeRoutingConfigs );
+
+static ivas_error parseCustomLayoutFile( const char *filePath, IVAS_CUSTOM_LS_DATA *pLsSetupCustom );
+
+static CmdlnArgs parseCmdlnArgs( const int argc, char **argv );
+
+static IsmPositionProvider *IsmPositionProvider_open( void );
+
+static void IsmPositionProvider_getNextFrame( IsmPositionProvider *positionProvider, ObjectPositionBuffer *objectMetadataBuffer );
+
+static void IsmPositionProvider_close( IsmPositionProvider *positionProvider );
+
+static LfeRoutingConfig *LfeRoutingConfig_open( void );
+
+static void LfeRoutingConfig_close( LfeRoutingConfig *lfeRoutingCfg );
+
+static void readFromShorthandMetadata( IsmPositionProvider *positionProvider, ObjectPositionBuffer *objectMetadataBuffer, const uint32_t objIdx );
+
+void getMetadataFromFileReader( IsmFileReader *ismReader, ObjectPositionBuffer *objectMetadataBuffer, const uint32_t objIdx );
+
+static void splitConfigFile( const char *mdfFilePath, char *metadataString, uint32_t *metadataStringLength, char *wavFileName, uint32_t *wavFileNameLength );
+
+static char *readNextMetadataChunk( char *line, const char *delimiter );
+
+static void parseUint8( const char *line, uint8_t *ret );
+
+static int8_t parseUint32( const char *line, uint32_t *ret );
+
+static int8_t parseInt32( const char *line, int32_t *ret );
+
+static void parseObjectPosition( char *line, IVAS_ISM_METADATA *position, uint16_t *positionDuration );
+
+static void parseMetadata( char *metadataString, char *inDir, InputConfig *inConfig, IsmPositionProvider *positionProvider, MasaFileReader **masaReaders, LfeRoutingConfig **lfeRoutingConfigs );
+
+static ivas_error parseLfePanMtxFile( const char *lfeRoutingMatrixFilePath, IVAS_REND_LfePanMtx *lfePanMtx );
+
+static void printSupportedAudioConfigs( void );
+
+static IVAS_AUDIO_CONFIG parseAudioConfig( const char *configString );
+
+static void convertInputBuffer( const int16_t *intBuffer, const int16_t numIntSamplesPerChannel, const int16_t numFloatSamplesPerChannel, const int16_t numChannels, float *floatBuffer );
+
+static void convertOutputBuffer( const float *floatBuffer, const int16_t numSamplesPerChannel, const int16_t numChannels, int16_t *intBuffer );
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local functions
+ *------------------------------------------------------------------------------------------*/
+
+static IVAS_REND_ReadOnlyAudioBuffer getReadOnlySubBuffer(
+ IVAS_REND_AudioBuffer buffer,
+ const int16_t chBeginIdx,
+ const int16_t numChannels )
+{
+ IVAS_REND_ReadOnlyAudioBuffer subBuffer;
+
+ subBuffer.config = buffer.config;
+ subBuffer.config.numChannels = numChannels;
+ subBuffer.data = buffer.data + subBuffer.config.numSamplesPerChannel * chBeginIdx;
+
+ return subBuffer;
+}
+
+
+static int16_t getTotalNumInChannels(
+ IVAS_REND_HANDLE hIvasRend,
+ IVAS_REND_InputId mcIds[RENDERER_MAX_MC_INPUTS],
+ IVAS_REND_InputId ismIds[RENDERER_MAX_ISM_INPUTS],
+ IVAS_REND_InputId sbaIds[RENDERER_MAX_SBA_INPUTS],
+ IVAS_REND_InputId masaIds[RENDERER_MAX_MASA_INPUTS]
+)
+{
+ int16_t totalNumInChannels = 0;
+ int16_t i, numInputChannels;
+ ivas_error error;
+
+ for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
+ {
+ if ( mcIds[i] == 0 )
+ {
+ /* Skip inactive inputs */
+ continue;
+ }
+
+ if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, mcIds[i], &numInputChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ totalNumInChannels += numInputChannels;
+ }
+
+ for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i )
+ {
+ if ( ismIds[i] == 0 )
+ {
+ /* Skip inactive inputs */
+ continue;
+ }
+
+ if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, ismIds[i], &numInputChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ /* In case of MASA output, modify the numInputChannels to contain all objects. Otherwise, keep the original value. */
+ if ( ( error = IVAS_REND_GetNumAllObjects( hIvasRend, &numInputChannels ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ totalNumInChannels += numInputChannels;
+ }
+
+ for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i )
+ {
+ if ( sbaIds[i] == 0 )
+ {
+ /* Skip inactive inputs */
+ continue;
+ }
+
+
+ if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, sbaIds[i], &numInputChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ totalNumInChannels += numInputChannels;
+ }
+
+ for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i )
+ {
+ if ( masaIds[i] == 0 )
+ {
+ /* Skip inactive inputs */
+ continue;
+ }
+
+ if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, masaIds[i], &numInputChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ totalNumInChannels += numInputChannels;
+ }
+
+
+ return totalNumInChannels;
+}
+
+
+static void setupWithSingleFormatInput(
+ CmdlnArgs args,
+ char *audioFilePath,
+ IsmPositionProvider *positionProvider,
+ MasaFileReader **masaReaders
+)
+{
+ /* With single-format input, inputFilePath is the path to input audio file. */
+ strncpy( audioFilePath, args.inputFilePath, FILENAME_MAX - 1 );
+
+ /* Depending on input format, prepare metadata reading for ISM or MASA */
+ if ( args.inConfig.numMasaBuses != 0 )
+ {
+ if ( args.inConfig.numMasaBuses != args.numInMetadataFiles )
+ {
+ fprintf( stderr, "Error: all MASA inputs must have a corresponding metadata file" );
+ exit( -1 );
+ }
+
+ for ( int16_t i = 0; i < args.numInMetadataFiles; ++i )
+ {
+ masaReaders[i] = MasaFileReader_open( args.inMetadataFilePaths[i] );
+ if ( masaReaders[i] == NULL )
+ {
+ fprintf( stderr, "Could not open MASA metadata file %s\n", args.inMetadataFilePaths[i] );
+ exit( -1 );
+ }
+ }
+ }
+ else if ( args.inConfig.numAudioObjects != 0 )
+ {
+ positionProvider->numObjects = args.inConfig.numAudioObjects;
+ for ( int16_t i = 0; i < positionProvider->numObjects; ++i )
+ {
+ /* It is allowed on CLI to have no metadata for an ISM input - skip opening if string is empty or contains "NULL" */
+ char charBuf[FILENAME_MAX];
+ strncpy( charBuf, args.inMetadataFilePaths[i], min( FILENAME_MAX, RENDERER_MAX_CLI_ARG_LENGTH ) - 1 );
+ charBuf[min( FILENAME_MAX, RENDERER_MAX_CLI_ARG_LENGTH ) - 1] = '\0';
+ to_upper( charBuf );
+ if ( isEmptyString( args.inMetadataFilePaths[i] ) || strncmp( charBuf, "NULL", 4 ) == 0 )
+ {
+ continue;
+ }
+
+ positionProvider->ismReaders[i] = IsmFileReader_open( args.inMetadataFilePaths[i] );
+ if ( positionProvider->ismReaders[i] == NULL )
+ {
+ fprintf( stderr, "Could not open object metadata file %s\n", args.inMetadataFilePaths[i] );
+ exit( -1 );
+ }
+ }
+ }
+
+ return;
+}
+
+
+static float dBToLin(
+ const float gain_dB )
+{
+ return powf( 10.0f, gain_dB / 20.0f );
+}
+
+
+
+
+/*------------------------------------------------------------------------------------------*
+ * main()
+ *
+ * Main External renderer function for command-line interface
+ *------------------------------------------------------------------------------------------*/
+
+int main(
+ int argc,
+ char **argv )
+{
+ IVAS_REND_HANDLE hIvasRend;
+ RotFileReader *headRotReader = NULL;
+ RotFileReader *externalOrientationFileReader = NULL;
+ RotFileReader *referenceRotReader = NULL;
+ Vector3PairFileReader *referenceVectorReader = NULL;
+ hrtfFileReader *hrtfFileReader = NULL;
+ IsmPositionProvider *positionProvider;
+ LfeRoutingConfig *lfeRoutingConfigs[RENDERER_MAX_MC_INPUTS];
+ RenderConfigReader *renderConfigReader = NULL;
+ MasaFileReader *masaReaders[RENDERER_MAX_MASA_INPUTS];
+ MasaFileWriter *masaWriter = NULL;
+ IVAS_MASA_METADATA_HANDLE hMasaMetadata[RENDERER_MAX_MASA_INPUTS];
+ char audioFilePath[FILENAME_MAX];
+ AudioFileReader *audioReader = NULL;
+ AudioFileWriter *audioWriter;
+ int32_t inBufferSize;
+ int32_t outBufferSize;
+ int16_t *inpInt16Buffer;
+ float *inFloatBuffer;
+ int16_t *outInt16Buffer;
+ float *outFloatBuffer;
+ IVAS_REND_AudioBuffer inBuffer;
+ IVAS_REND_AudioBuffer outBuffer;
+ int16_t numSamplesRead;
+ int16_t delayNumSamples = -1;
+ int16_t delayNumSamples_orig = 0;
+ int16_t zeroPad = 0;
+ int16_t zeroPadToWrite = 0;
+ int32_t delayTimeScale = 0;
+ int16_t i, numChannels;
+ ivas_error error = IVAS_ERR_OK;
+ bool splitBinNeedsNewFrame = true;
+
+#ifdef WMOPS
+ reset_wmops();
+ reset_mem( USE_32BITS );
+#endif
+
+ for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i )
+ {
+ masaReaders[i] = NULL;
+ hMasaMetadata[i] = NULL;
+ }
+
+ for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
+ {
+ lfeRoutingConfigs[i] = NULL;
+ }
+
+ CmdlnArgs args = parseCmdlnArgs( argc, argv );
+
+ if ( args.nonDiegeticPan && !( ( args.inConfig.numAudioObjects == 0 && args.inConfig.multiChannelBuses[0].audioConfig == IVAS_AUDIO_CONFIG_MONO ) ||
+ ( args.inConfig.numAudioObjects > 0 && args.inConfig.audioObjects[0].audioConfig == IVAS_AUDIO_CONFIG_OBA && args.inConfig.numAudioObjects == 1 ) ) )
+ {
+ fprintf( stderr, "\ninvalid configuration - non-diegetic panning requires mono or ISM1 input\n" );
+ exit( -1 );
+ }
+
+ if ( args.nonDiegeticPan && args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_STEREO )
+ {
+ fprintf( stderr, "\ninvalid configuration - non-diegetic panning requires stereo output\n" );
+ exit( -1 );
+ }
+
+ positionProvider = IsmPositionProvider_open();
+
+ convert_backslash( args.inputFilePath );
+ convert_backslash( args.outputFilePath );
+ convert_backslash( args.headRotationFilePath );
+ convert_backslash( args.referenceVectorFilePath );
+ convert_backslash( args.referenceRotationFilePath );
+ convert_backslash( args.inLfePanningMatrixFile );
+ convert_backslash( args.externalOrientationFilePath );
+
+ if ( !isEmptyString( args.headRotationFilePath ) )
+ {
+ if ( RotationFileReader_open( args.headRotationFilePath, &headRotReader ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error opening file: %s\n", args.headRotationFilePath );
+ exit( -1 );
+ }
+ }
+
+ if ( !isEmptyString( args.referenceRotationFilePath ) )
+ {
+ if ( RotationFileReader_open( args.referenceRotationFilePath, &referenceRotReader ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error opening file: %s\n", args.referenceRotationFilePath );
+ exit( -1 );
+ }
+ }
+ if ( !isEmptyString( args.referenceVectorFilePath ) )
+ {
+ if ( Vector3PairFileReader_open( args.referenceVectorFilePath, &referenceVectorReader ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error opening file: %s\n", args.referenceVectorFilePath );
+ exit( -1 );
+ }
+ }
+
+ if ( !isEmptyString( args.externalOrientationFilePath ) )
+ {
+ if ( RotationFileReader_open( args.externalOrientationFilePath, &externalOrientationFileReader ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error opening file: %s\n", args.externalOrientationFilePath );
+ exit( -1 );
+ }
+ }
+
+ if ( !isEmptyString( args.customHrtfFilePath ) )
+ {
+ if ( hrtfFileReader_open( args.customHrtfFilePath, &hrtfFileReader ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error opening file: %s\n", args.customHrtfFilePath );
+ exit( -1 );
+ }
+ }
+
+ if ( !isEmptyString( args.renderConfigFilePath ) )
+ {
+ if ( RenderConfigReader_open( args.renderConfigFilePath, &renderConfigReader ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error opening file: %s\n", args.renderConfigFilePath );
+ exit( -1 );
+ }
+ }
+
+ /* Initialize main input files, i.e. audio and metadata */
+ if ( args.sceneDescriptionInput )
+ {
+ /* With scene description input, inputFilePath is the path to the scene description file. Parse it. */
+ parseSceneDescriptionFile( args.inputFilePath, audioFilePath, &args.inConfig, positionProvider, masaReaders, lfeRoutingConfigs );
+ }
+ else
+ {
+ /* With single-format input, all information is given on command line. */
+ setupWithSingleFormatInput( args, audioFilePath, positionProvider, masaReaders );
+ }
+
+ /* Check that there is allowed configuration for MASA format output */
+ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA2 )
+ {
+ if ( args.inConfig.numMasaBuses == 0 )
+ {
+ fprintf( stderr, "\nInvalid configuration - Merging to MASA output requires MASA input and at least one another input to be present\n" );
+ fprintf( stderr, "\nMASA input is missing\n" );
+ exit( -1 );
+ }
+
+ if ( args.inConfig.numAudioObjects == 0 && args.inConfig.numMultiChannelBuses == 0 && args.inConfig.numAmbisonicsBuses == 0 )
+ {
+ fprintf( stderr, "\nInvalid configuration - Merging to MASA output requires MASA input and at least one another input to be present\n" );
+ fprintf( stderr, "\nNo object, multi-channel, or Ambisonic input present.\n" );
+ exit( -1 );
+ }
+ }
+
+ if ( AudioFileReader_open( &audioReader, audioFilePath ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error opening file: %s\n", audioFilePath );
+ exit( -1 );
+ }
+
+ int32_t inFileSampleRate = 0;
+ error = AudioFileReader_getSamplingRate( audioReader, &inFileSampleRate );
+
+ switch ( error )
+ {
+ case IVAS_ERR_OK:
+ /* If sampling rate not given on command line, use the one from wav file */
+ if ( args.sampleRate == 0 )
+ {
+ args.sampleRate = inFileSampleRate;
+ }
+ /* else if sampling rate given on command line, compare with wav file */
+ else if ( inFileSampleRate != args.sampleRate )
+ {
+ fprintf( stderr, "Sampling rate mismatch: %d Hz requested, but %d Hz found in file %s\n", args.sampleRate, inFileSampleRate, args.inputFilePath );
+ exit( -1 );
+ }
+ break;
+ case IVAS_ERR_SAMPLING_RATE_UNKNOWN: /* Returned when input is raw PCM */
+ if ( args.sampleRate == 0 )
+ {
+ fprintf( stderr, "Sampling rate must be specified on command line when using raw PCM input\n" );
+ exit( -1 );
+ }
+ break;
+ default:
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ int16_t inFileNumChannels = 0;
+ error = AudioFileReader_getNumChannels( audioReader, &inFileNumChannels );
+ if ( error != IVAS_ERR_OK && error != IVAS_ERR_NUM_CHANNELS_UNKNOWN )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ const int16_t frameSize_smpls = (int16_t) ( ( args.framing_5ms ? 5 : 20 ) * args.sampleRate / 1000 );
+
+ if ( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, args.nonDiegeticPan, args.nonDiegeticPanGain, ( args.framing_5ms ) ? 1 : 4 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error opening renderer handle: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ /* === Configure === */
+ if ( ( error = IVAS_REND_InitConfig( hIvasRend, args.outConfig.audioConfig ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in Renderer Config Init\n" );
+ exit( -1 );
+ }
+
+
+ if ( args.renderConfigFilePath[0] != '\0' )
+ {
+ IVAS_RENDER_CONFIG_DATA renderConfig;
+
+ /* sanity check */
+ if ( ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL ) && ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) && ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
+ {
+ fprintf( stderr, "\nExternal Renderer Config is only supported for binaural output configurations. Exiting. \n" );
+ exit( -1 );
+ }
+
+
+ if ( ( error = IVAS_REND_GetRenderConfig( hIvasRend, &renderConfig ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_GetRenderConfig failed\n" );
+ exit( -1 );
+ }
+
+ if ( RenderConfigReader_read( renderConfigReader, args.renderConfigFilePath, &renderConfig ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Failed to read renderer configuration from file %s\n", args.renderConfigFilePath );
+ exit( -1 );
+ }
+
+ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
+ {
+ if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, args.acousticEnvironmentId, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
+ {
+ if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Invalid room acoustics configuration parameters\n\n" );
+ exit( -1 );
+ }
+ }
+ else
+ {
+ fprintf( stderr, "Failed to get acoustic environment with ID: %d\n\n", args.acousticEnvironmentId );
+ exit( -1 );
+ }
+ renderConfig.roomAcoustics.override = 1;
+ }
+
+ if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed\n" );
+ exit( -1 );
+ }
+
+ }
+
+ if ( ( error = IVAS_REND_SetOrientationTrackingMode( hIvasRend, args.orientation_tracking ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_SetOrientationTrackingMode(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ /* Set up output custom layout configuration */
+ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM )
+ {
+ if ( ( error = IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( hIvasRend, args.outConfig.outSetupCustom ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_ConfigureCustomOutputLoudspeakerLayout(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ /* Set up MASA writer for MASA output */
+ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA2 )
+ {
+ MasaFileWriter_open( args.outputFilePath, true, &masaWriter ); /* No delay for audio in renderer, so calling metadata writer in delayCompensated mode, i.e., no delay applied to meta */
+ if ( masaWriter == NULL )
+ {
+ fprintf( stderr, "Could not open MASA metadata file %s\n", args.outputFilePath );
+ exit( -1 );
+ }
+ }
+
+ /* Set the total number of objects */
+ if ( args.inConfig.numAudioObjects > 0 )
+ {
+ if ( ( error = IVAS_REND_SetTotalNumberOfObjects( hIvasRend, args.inConfig.numAudioObjects ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_SetTotalNumberOfObjects(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_SetIsmMetadataDelay( hIvasRend, args.syncMdDelay ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_SetIsmMetadataDelay(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ IVAS_REND_LfePanMtx lfePanMatrix;
+
+ /* parse input LFE panning matrix */
+ if ( args.lfeCustomRoutingEnabled && !isEmptyString( args.inLfePanningMatrixFile ) )
+ {
+ if ( ( error = parseLfePanMtxFile( args.inLfePanningMatrixFile, &lfePanMatrix ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ IVAS_REND_InputId mcIds[RENDERER_MAX_MC_INPUTS];
+ IVAS_REND_InputId ismIds[RENDERER_MAX_ISM_INPUTS];
+ IVAS_REND_InputId sbaIds[RENDERER_MAX_SBA_INPUTS];
+ IVAS_REND_InputId masaIds[RENDERER_MAX_MASA_INPUTS];
+
+ for ( i = 0; i < RENDERER_MAX_MC_INPUTS; i++ )
+ {
+ mcIds[i] = 0u;
+ }
+ for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; i++ )
+ {
+ ismIds[i] = 0u;
+ }
+ for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; i++ )
+ {
+ sbaIds[i] = 0u;
+ }
+ for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; i++ )
+ {
+ masaIds[i] = 0u;
+ }
+
+ for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i )
+ {
+ if ( ( error = IVAS_REND_AddInput( hIvasRend, args.inConfig.multiChannelBuses[i].audioConfig, &mcIds[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_SetInputGain( hIvasRend, mcIds[i], args.inputGainGlobal * dBToLin( args.inConfig.multiChannelBuses[i].gain_dB ) ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( args.inConfig.multiChannelBuses[i].audioConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM )
+ {
+ if ( ( error = IVAS_REND_ConfigureCustomInputLoudspeakerLayout( hIvasRend, mcIds[i], args.inConfig.inSetupCustom ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_ConfigureCustomInputLoudspeakerLayout(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ /* set panning matrix for input LFE */
+ if ( args.lfeCustomRoutingEnabled )
+ {
+ if ( args.lfePanningEnabled )
+ {
+ fprintf( stderr, "Warning: LFE position specified as well as panning matrix! Ignoring position and using gains from panning matrix\n" );
+ args.lfePanningEnabled = false;
+ }
+
+ if ( ( error = IVAS_REND_SetInputLfeMtx( hIvasRend, mcIds[i], (const IVAS_REND_LfePanMtx *) &lfePanMatrix ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ /* set panning gains for input LFE */
+ else if ( args.lfePanningEnabled )
+ {
+ if ( ( error = IVAS_REND_SetInputLfePos( hIvasRend, mcIds[i], args.lfeConfigGain, args.lfeConfigAzimuth, args.lfeConfigElevation ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ else
+ {
+ /* check for configuration from scene description file */
+ if ( lfeRoutingConfigs[i] != NULL )
+ {
+ /* prioritise panning matrix if configured */
+ if ( !isEmptyString( lfeRoutingConfigs[i]->lfe_routing_mtx ) )
+ {
+ if ( ( error = parseLfePanMtxFile( lfeRoutingConfigs[i]->lfe_routing_mtx, &lfePanMatrix ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_SetInputLfeMtx( hIvasRend, mcIds[i], (const IVAS_REND_LfePanMtx *) &lfePanMatrix ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ /* set position based gains */
+ else
+ {
+ if ( ( error = IVAS_REND_SetInputLfePos( hIvasRend, mcIds[i], lfeRoutingConfigs[i]->lfe_gain_dB, lfeRoutingConfigs[i]->lfe_azi, lfeRoutingConfigs[i]->lfe_ele ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ }
+ }
+ }
+
+ for ( i = 0; i < args.inConfig.numAudioObjects; ++i )
+ {
+ if ( ( error = IVAS_REND_AddInput( hIvasRend, IVAS_AUDIO_CONFIG_OBA, &ismIds[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_SetInputGain( hIvasRend, ismIds[i], args.inputGainGlobal * dBToLin( args.inConfig.audioObjects[i].gain_dB ) ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ /* With MASA output, all objects are handled at once, so add only one input having all objects in it */
+ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA2 )
+ {
+ break;
+ }
+ }
+
+ for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i )
+ {
+ if ( ( error = IVAS_REND_AddInput( hIvasRend, args.inConfig.ambisonicsBuses[i].audioConfig, &sbaIds[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_SetInputGain( hIvasRend, sbaIds[i], args.inputGainGlobal * dBToLin( args.inConfig.ambisonicsBuses[i].gain_dB ) ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+
+ for ( i = 0; i < args.inConfig.numMasaBuses; ++i )
+ {
+ if ( ( error = IVAS_REND_AddInput( hIvasRend, args.inConfig.masaBuses[i].audioConfig, &masaIds[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_SetInputGain( hIvasRend, masaIds[i], args.inputGainGlobal * dBToLin( args.inConfig.masaBuses[i].gain_dB ) ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ const int16_t totalNumInChannels = getTotalNumInChannels( hIvasRend, mcIds, ismIds, sbaIds, masaIds );
+
+ if ( inFileNumChannels != 0 /* inFileNumChannels is 0 with raw PCM input */ && totalNumInChannels != inFileNumChannels )
+ {
+ fprintf( stderr, "Number of channels in input file does not match selected configuration\n" );
+ exit( -1 );
+ }
+
+ for ( i = 0; i < args.inConfig.numMasaBuses; ++i )
+ {
+ if ( masaReaders[i] != NULL )
+ {
+ hMasaMetadata[i] = MasaFileReader_getMetadataHandle( masaReaders[i] );
+ }
+ }
+
+ int16_t numOutChannels;
+ if ( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_NumOutChannels(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+
+ if ( AudioFileWriter_open( &audioWriter, args.outputFilePath, args.sampleRate, numOutChannels ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Failed to open file: %s\n", args.outputFilePath );
+ exit( -1 );
+ }
+
+ inBufferSize = frameSize_smpls * totalNumInChannels;
+ outBufferSize = frameSize_smpls * numOutChannels;
+ inpInt16Buffer = malloc( inBufferSize * sizeof( int16_t ) );
+
+ inFloatBuffer = malloc( inBufferSize * sizeof( float ) );
+ outInt16Buffer = malloc( outBufferSize * sizeof( int16_t ) );
+ outFloatBuffer = malloc( outBufferSize * sizeof( float ) );
+
+ inBuffer.config.numSamplesPerChannel = (int16_t) frameSize_smpls;
+ inBuffer.config.numChannels = (int16_t) totalNumInChannels;
+ inBuffer.data = inFloatBuffer;
+
+ outBuffer.config.numSamplesPerChannel = (int16_t) frameSize_smpls;
+ outBuffer.config.numChannels = (int16_t) numOutChannels;
+ outBuffer.data = outFloatBuffer;
+
+#ifdef WMOPS
+ reset_stack();
+ reset_wmops();
+#endif
+
+ if ( !args.quietModeEnabled )
+ {
+ fprintf( stdout, "\n------ Running the renderer ------\n\n" );
+ fprintf( stdout, "Frames processed: " );
+ }
+ else
+ {
+ fprintf( stdout, "\n\n-- Start the renderer (quiet mode) --\n\n" );
+ }
+
+ ObjectPositionBuffer mtdBuffer;
+
+ while ( 1 )
+ {
+ int16_t num_in_channels;
+ num_in_channels = inBuffer.config.numChannels;
+ const bool isCurrentFrameMultipleOf20ms = !args.framing_5ms || frame % 4 == 0;
+
+ /* Read the input data */
+ if ( ( error = AudioFileReader_read( audioReader, inpInt16Buffer, (int16_t) inBufferSize, &numSamplesRead ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError reading from file %s\n", audioFilePath );
+ exit( -1 );
+ }
+
+ if ( numSamplesRead == 0 && splitBinNeedsNewFrame )
+ {
+ /* end of input data */
+ break;
+ }
+
+ /* Convert from int to float and from interleaved to packed */
+ convertInputBuffer( inpInt16Buffer, numSamplesRead, inBuffer.config.numSamplesPerChannel, num_in_channels, inFloatBuffer );
+
+ int16_t num_subframes, sf_idx;
+ num_subframes = ( args.framing_5ms ) ? 1 : IVAS_MAX_PARAM_SPATIAL_SUBFRAMES;
+
+ if ( isCurrentFrameMultipleOf20ms )
+ {
+ IsmPositionProvider_getNextFrame( positionProvider, &mtdBuffer );
+
+ if ( referenceVectorReader != NULL )
+ {
+ IVAS_VECTOR3 listenerPos, refPos;
+ if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPos, &refPos ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ if ( ( error = IVAS_REND_SetReferenceVector( hIvasRend, listenerPos, refPos ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ /* Read from reference rotation trajectory file if specified */
+ if ( referenceRotReader != NULL )
+ {
+ for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
+ {
+ IVAS_QUATERNION quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
+ if ( ( error = HeadRotationFileReading( referenceRotReader, &quaternions[sf_idx], NULL ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in Head Rotation File Reading: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_SetReferenceRotation( hIvasRend, quaternions[sf_idx] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error setting Reference Rotation: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ }
+ }
+
+ /* Read from head rotation trajectory file if specified */
+ if ( headRotReader != NULL )
+ {
+ for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
+ {
+ IVAS_QUATERNION headRot;
+ IVAS_VECTOR3 Pos;
+
+ if ( ( error = HeadRotationFileReading( headRotReader, &headRot, &Pos ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in Head Rotation File Reading: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_SetHeadRotation( hIvasRend, headRot, Pos, sf_idx ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error setting Head Rotation: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ }
+ else
+ {
+ if ( ( error = IVAS_REND_DisableHeadRotation( hIvasRend ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error disabling head rotation: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+
+ /* Read from external orientation file if specified */
+ if ( externalOrientationFileReader != NULL )
+ {
+ IVAS_QUATERNION quatBuffer[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 ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
+ {
+ if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &quatBuffer[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in External Orientation File Reading: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
+ {
+ if ( ( error = IVAS_REND_SetExternalOrientation( hIvasRend, &quatBuffer[sf_idx], enableHeadRotation[sf_idx], enableExternalOrientation[sf_idx], enableRotationInterpolation[sf_idx], numFramesToTargetOrientation[sf_idx], sf_idx ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error setting External Orientation: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ }
+
+ /* Combine external orientations and head rotation */
+
+ if ( ( error = IVAS_REND_CombineHeadAndExternalOrientation( hIvasRend ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error combining external and head orientations: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i )
+ {
+ if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, mcIds[i], &numChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.multiChannelBuses[i].inputChannelIndex, numChannels );
+
+ if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, mcIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ for ( i = 0; i < args.inConfig.numAudioObjects; ++i )
+ {
+ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA2 )
+ {
+ if ( i == 0 )
+ {
+ IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, args.inConfig.numAudioObjects );
+
+ if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ if ( ( error = IVAS_REND_FeedInputObjectMetadataToOMasa( hIvasRend, i, mtdBuffer.positions[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ else
+ {
+ IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, 1 );
+
+ if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( ( error = IVAS_REND_FeedInputObjectMetadata( hIvasRend, ismIds[i], mtdBuffer.positions[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ }
+
+ for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i )
+ {
+ if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, sbaIds[i], &numChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.ambisonicsBuses[i].inputChannelIndex, numChannels );
+
+ if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, sbaIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ for ( i = 0; i < args.inConfig.numMasaBuses; ++i )
+ {
+ if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, masaIds[i], &numChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.masaBuses[i].inputChannelIndex, numChannels );
+
+ if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, masaIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+
+ if ( masaReaders[i] != NULL )
+ {
+ /* This will update data in hMasaMetadata[i] */
+ MasaFileReader_readNextFrame( masaReaders[i] );
+
+ if ( ( error = IVAS_REND_FeedInputMasaMetadata( hIvasRend, masaIds[i], hMasaMetadata[i] ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ }
+
+
+
+ if ( ( error = IVAS_REND_GetSamples( hIvasRend, outBuffer ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in getting samples\n" );
+ exit( -1 );
+ }
+
+ int16_t num_out_channels;
+ num_out_channels = outBuffer.config.numChannels;
+
+ /* Convert from float to int and from packed to interleaved.
+ * Values in outFloatBuffer are guaranteed to be within range INT16_MIN:INT16_MAX */
+ convertOutputBuffer( outFloatBuffer, outBuffer.config.numSamplesPerChannel, num_out_channels, outInt16Buffer );
+
+ if ( delayNumSamples == -1 )
+ {
+ if ( args.delayCompensationEnabled )
+ {
+ if ( IVAS_REND_GetDelay( hIvasRend, &delayNumSamples, &delayTimeScale ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nUnable to get delay of renderer!\n" );
+ exit( -1 );
+ }
+
+
+ delayNumSamples_orig = delayNumSamples;
+ }
+ else
+ {
+ delayNumSamples = 0;
+ }
+ zeroPad = delayNumSamples;
+ }
+
+ if ( delayNumSamples * num_out_channels < outBufferSize )
+ {
+ if ( AudioFileWriter_write( audioWriter, &outInt16Buffer[delayNumSamples * num_out_channels], outBufferSize - ( delayNumSamples * num_out_channels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error writing audio file %s\n", args.outputFilePath );
+ exit( -1 );
+ }
+ delayNumSamples = 0;
+ }
+ else
+ {
+ delayNumSamples -= (int16_t) ( outBufferSize / num_out_channels );
+ }
+
+ /* Write MASA metadata for MASA outputs */
+ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA2 )
+ {
+ IVAS_REND_AudioConfigType inputType1;
+ IVAS_REND_AudioConfigType inputType2;
+ IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMetaOutput;
+ int16_t numInputFormats;
+
+ inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN;
+ inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN;
+ hMetaOutput = NULL;
+
+ numInputFormats = 0;
+ if ( args.inConfig.numAmbisonicsBuses > 0 )
+ {
+ numInputFormats++;
+ inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS;
+ }
+ if ( args.inConfig.numMultiChannelBuses > 0 )
+ {
+ numInputFormats++;
+ if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
+ {
+ inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED;
+ }
+ }
+ if ( args.inConfig.numMasaBuses > 0 )
+ {
+ numInputFormats++;
+ if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
+ {
+ inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_MASA;
+ }
+ }
+ if ( args.inConfig.numAudioObjects > 0 )
+ {
+ numInputFormats++;
+ if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
+ {
+ inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED;
+ }
+ }
+
+ if ( numInputFormats == 1 )
+ {
+ if ( ( error = IVAS_REND_GetMasaMetadata( hIvasRend, &hMetaOutput, inputType1 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_GetMasaMetadata(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ else
+ {
+ if ( args.inConfig.numAmbisonicsBuses > 0 && args.inConfig.numMultiChannelBuses > 0 )
+ {
+ inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED;
+ if ( ( error = IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_MergeMasaMetadata(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ if ( ( args.inConfig.numAmbisonicsBuses > 0 || args.inConfig.numMultiChannelBuses > 0 ) && args.inConfig.numMasaBuses > 0 )
+ {
+ inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_MASA;
+ if ( ( error = IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_MergeMasaMetadata(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+
+ if ( ( args.inConfig.numAmbisonicsBuses > 0 || args.inConfig.numMultiChannelBuses > 0 || args.inConfig.numMasaBuses > 0 ) && args.inConfig.numAudioObjects > 0 )
+ {
+ inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED;
+ if ( ( error = IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error in IVAS_REND_MergeMasaMetadata(): %s\n", ivas_error_to_string( error ) );
+ exit( -1 );
+ }
+ }
+ }
+
+ if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMetaOutput ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) );
+ }
+ }
+
+ frame++;
+ if ( !args.quietModeEnabled )
+ {
+ fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame );
+ }
+
+#ifdef WMOPS
+ update_mem();
+ update_wmops();
+#endif
+ }
+
+ /* add zeros at the end to have equal length of synthesized signals */
+ for ( zeroPadToWrite = zeroPad; zeroPadToWrite > frameSize_smpls; zeroPadToWrite -= frameSize_smpls )
+ {
+ memset( outInt16Buffer, 0, outBufferSize * sizeof( int16_t ) );
+ if ( ( error = AudioFileWriter_write( audioWriter, outInt16Buffer, outBufferSize ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nOutput audio file writer error\n" );
+ exit( -1 );
+ }
+ }
+
+ memset( outInt16Buffer, 0, zeroPadToWrite * outBuffer.config.numChannels * sizeof( int16_t ) );
+ if ( ( error = AudioFileWriter_write( audioWriter, outInt16Buffer, zeroPadToWrite * outBuffer.config.numChannels ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nOutput audio file writer error\n" );
+ exit( -1 );
+ }
+ zeroPadToWrite = 0;
+
+
+ if ( args.inConfig.numAudioObjects != 0 && ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
+ {
+ fprintf( stdout, "\n\nMetadata delayed %d subframes\n\n", (int16_t) round( args.syncMdDelay / ( 1000 / IVAS_NUM_FRAMES_PER_SEC / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) );
+ }
+
+ if ( !args.quietModeEnabled && args.delayCompensationEnabled )
+ {
+ fprintf( stdout, "\nRenderer delay: %-5u [samples] - Timescale: %5u\n", delayNumSamples_orig, delayTimeScale );
+ }
+
+ fprintf( stdout, "\n\nRendering of %d frames finished\n\n", frame );
+
+
+ /* === Close === */
+ free( inpInt16Buffer );
+ free( inFloatBuffer );
+ free( outInt16Buffer );
+ free( outFloatBuffer );
+ for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i )
+ {
+ MasaFileReader_close( &masaReaders[i] );
+ }
+
+
+ for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
+ {
+ LfeRoutingConfig_close( lfeRoutingConfigs[i] );
+ }
+ MasaFileWriter_close( &masaWriter );
+ AudioFileReader_close( &audioReader );
+ AudioFileWriter_close( &audioWriter );
+ RotationFileReader_close( &headRotReader );
+ RotationFileReader_close( &externalOrientationFileReader );
+ RotationFileReader_close( &referenceRotReader );
+ Vector3PairFileReader_close( &referenceVectorReader );
+ hrtfFileReader_close( &hrtfFileReader );
+ IVAS_REND_Close( &hIvasRend );
+ IsmPositionProvider_close( positionProvider );
+ RenderConfigReader_close( &renderConfigReader );
+
+#ifdef WMOPS
+ print_wmops();
+ print_mem( NULL );
+#endif
+
+ return 0;
+}
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local functions
+ *------------------------------------------------------------------------------------------*/
+
+static IVAS_AUDIO_CONFIG ambisonicsOrderToEnum(
+ const int16_t order )
+{
+ switch ( order )
+ {
+ case 1:
+ return IVAS_AUDIO_CONFIG_FOA;
+ case 2:
+ return IVAS_AUDIO_CONFIG_HOA2;
+ case 3:
+ return IVAS_AUDIO_CONFIG_HOA3;
+ }
+
+ return IVAS_AUDIO_CONFIG_INVALID;
+}
+
+static const CmdLnParser_Option *findOptionById(
+ const int32_t id )
+{
+ for ( int32_t i = 0; i < numCliOptions; ++i )
+ {
+ if ( cliOptions[i].id == id )
+ {
+ return &cliOptions[i];
+ }
+ }
+
+ return NULL;
+}
+
+static bool parseInConfig(
+ const char *inFormatStr,
+ InputConfig *inConfig,
+ bool *sceneDescriptionInput )
+{
+ char charBuf[FILENAME_MAX];
+
+ /* Initialize input config struct */
+ inConfig->numAudioObjects = 0;
+ inConfig->numAmbisonicsBuses = 0;
+ inConfig->numMultiChannelBuses = 0;
+ inConfig->numMasaBuses = 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 );
+ switch ( audioConfig )
+ {
+ case IVAS_AUDIO_CONFIG_MONO:
+ case IVAS_AUDIO_CONFIG_STEREO:
+ case IVAS_AUDIO_CONFIG_5_1:
+ case IVAS_AUDIO_CONFIG_7_1:
+ case IVAS_AUDIO_CONFIG_5_1_2:
+ case IVAS_AUDIO_CONFIG_5_1_4:
+ case IVAS_AUDIO_CONFIG_7_1_4:
+ inConfig->numMultiChannelBuses = 1;
+ inConfig->multiChannelBuses[0].audioConfig = audioConfig;
+ inConfig->multiChannelBuses[0].inputChannelIndex = 0;
+ inConfig->multiChannelBuses[0].gain_dB = 0.0f;
+ break;
+ case IVAS_AUDIO_CONFIG_FOA:
+ case IVAS_AUDIO_CONFIG_HOA2:
+ case IVAS_AUDIO_CONFIG_HOA3:
+ inConfig->numAmbisonicsBuses = 1;
+ inConfig->ambisonicsBuses[0].audioConfig = audioConfig;
+ inConfig->ambisonicsBuses[0].inputChannelIndex = 0;
+ inConfig->ambisonicsBuses[0].gain_dB = 0.0f;
+ break;
+ case IVAS_AUDIO_CONFIG_MASA1:
+ case IVAS_AUDIO_CONFIG_MASA2:
+ inConfig->numMasaBuses = 1;
+ inConfig->masaBuses[0].audioConfig = audioConfig;
+ inConfig->masaBuses[0].inputChannelIndex = 0;
+ inConfig->masaBuses[0].gain_dB = 0.0f;
+ break;
+ case IVAS_AUDIO_CONFIG_OBA:
+ /* If input format is objects, parse the characters after "ISM" to get number of objects */
+ {
+ char *ptr = NULL;
+ inConfig->numAudioObjects = (uint16_t) strtol( inFormatStr + 3, &ptr, 10 );
+ if ( ptr == NULL || *ptr != '\0' )
+ {
+ /* Failed to parse string as a number */
+ fprintf( stderr, "Cannot parse string \"%s\" as a valid input format", inFormatStr );
+ return false;
+ }
+ if ( inConfig->numAudioObjects > RENDERER_MAX_ISM_INPUTS )
+ {
+ fprintf( stderr, "Too many objects at input. Max %d supported.", RENDERER_MAX_ISM_INPUTS );
+ return false;
+ }
+ for ( int16_t i = 0; i < inConfig->numAudioObjects; ++i )
+ {
+ inConfig->audioObjects[i].audioConfig = audioConfig;
+ inConfig->audioObjects[i].inputChannelIndex = i;
+ inConfig->audioObjects[i].gain_dB = 0.0f;
+ }
+ }
+ break;
+ case IVAS_AUDIO_CONFIG_INVALID:
+ /* This case will be reached if parsing string to AUDIO_CONFIG enum fails.
+ * Try to use the given string as a path to a custom loudspeaker layout file. */
+ {
+ ivas_error error = parseCustomLayoutFile( inFormatStr, &inConfig->inSetupCustom );
+
+ if ( error == IVAS_ERR_FAILED_FILE_OPEN )
+ {
+ /* Failed to open with given string - most likely wasn't a file path */
+ const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_listFormats );
+ fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match );
+ return false;
+ }
+ if ( error != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error while reading custom loudspeaker layout file %s\n", inFormatStr );
+ return false;
+ }
+ inConfig->numMultiChannelBuses = 1;
+ inConfig->multiChannelBuses[0].audioConfig = IVAS_AUDIO_CONFIG_LS_CUSTOM;
+ inConfig->multiChannelBuses[0].inputChannelIndex = 0;
+ inConfig->multiChannelBuses[0].gain_dB = 0.0f;
+ }
+ break;
+ default:
+ {
+ /* 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 );
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static bool parseOutConfig(
+ const char *outputFormatStr,
+ OutputConfig *outConfig )
+{
+ ivas_error error;
+
+ outConfig->audioConfig = parseAudioConfig( outputFormatStr );
+ /* If the string provided is not recognized as a valid output config,
+ * it's expected to be a path to a custom loudspeaker layout description file. */
+ if ( outConfig->audioConfig == IVAS_AUDIO_CONFIG_INVALID )
+ {
+ outConfig->audioConfig = IVAS_AUDIO_CONFIG_LS_CUSTOM;
+ if ( ( error = parseCustomLayoutFile( outputFormatStr, &outConfig->outSetupCustom ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error while parsing output format option\n" );
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static bool parseDiegeticPan(
+ char *value,
+ float *nonDiegeticPan )
+{
+ to_upper( value );
+
+ if ( ( strcmp( value, "CENTER" ) == 0 ) || ( strchr( value, 'C' ) != NULL ) )
+ {
+ *nonDiegeticPan = 0.f;
+ }
+ else if ( ( strcmp( value, "LEFT" ) == 0 ) || ( strchr( value, 'L' ) != NULL ) )
+ {
+ *nonDiegeticPan = 1.f;
+ }
+ else if ( ( strcmp( value, "RIGHT" ) == 0 ) || ( strchr( value, 'R' ) != NULL ) )
+ {
+ *nonDiegeticPan = -1.f;
+ }
+ else
+ {
+ *nonDiegeticPan = (float) atof( value ) / 90.f;
+
+ if ( *nonDiegeticPan > 1.0f || *nonDiegeticPan < -1.0f )
+ {
+ fprintf( stderr, "Error: Incorrect value for panning option argument specified!\n\n" );
+ return false;
+ }
+ }
+ return true;
+}
+
+static bool parseOrientationTracking(
+ char *value,
+ int8_t *orientation_tracking )
+{
+ to_upper( value );
+
+ if ( strcmp( value, "NONE" ) == 0 )
+ {
+ *orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE;
+ }
+ else if ( strcmp( value, "REF" ) == 0 )
+ {
+ *orientation_tracking = IVAS_HEAD_ORIENT_TRK_REF;
+ }
+ else if ( strcmp( value, "AVG" ) == 0 )
+ {
+ *orientation_tracking = IVAS_HEAD_ORIENT_TRK_AVG;
+ }
+ else if ( strcmp( value, "REF_VEC" ) == 0 )
+ {
+ *orientation_tracking = IVAS_HEAD_ORIENT_TRK_REF_VEC;
+ }
+ else if ( strcmp( value, "REF_VEC_LEV" ) == 0 )
+ {
+ *orientation_tracking = IVAS_HEAD_ORIENT_TRK_REF_VEC_LEV;
+ }
+ else
+ {
+ fprintf( stderr, "Error: Invalid orientation tracking type %s \n\n", value );
+ return false;
+ }
+
+ return true;
+}
+
+static IVAS_AUDIO_CONFIG parseAudioConfig(
+ const char *configString )
+{
+ char charBuf[21];
+ charBuf[20] = '\0';
+
+ strncpy( charBuf, configString, sizeof( charBuf ) - 1 );
+ charBuf[sizeof( charBuf ) - 1] = '\0';
+ to_upper( charBuf );
+
+ if ( ( strcmp( charBuf, "MONO" ) == 0 ) || ( strcmp( charBuf, "HOA0" ) == 0 ) || ( strcmp( charBuf, "SBA0" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_MONO;
+ }
+ if ( ( strcmp( charBuf, "STEREO" ) == 0 ) || ( strcmp( charBuf, "CICP2" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_STEREO;
+ }
+ if ( ( strcmp( charBuf, "FOA" ) == 0 ) || ( strcmp( charBuf, "SBA1" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_FOA;
+ }
+ if ( ( strcmp( charBuf, "HOA2" ) == 0 ) || ( strcmp( charBuf, "SBA2" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_HOA2;
+ }
+ if ( ( strcmp( charBuf, "HOA3" ) == 0 ) || ( strcmp( charBuf, "SBA3" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_HOA3;
+ }
+ if ( ( strcmp( charBuf, "5_1" ) == 0 ) || ( strcmp( charBuf, "CICP6" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_5_1;
+ }
+ if ( ( strcmp( charBuf, "7_1" ) == 0 ) || ( strcmp( charBuf, "CICP12" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_7_1;
+ }
+ if ( ( strcmp( charBuf, "5_1_2" ) == 0 ) || ( strcmp( charBuf, "CICP14" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_5_1_2;
+ }
+ if ( ( strcmp( charBuf, "5_1_4" ) == 0 ) || ( strcmp( charBuf, "CICP16" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_5_1_4;
+ }
+ if ( ( strcmp( charBuf, "7_1_4" ) == 0 ) || ( strcmp( charBuf, "CICP19" ) == 0 ) )
+ {
+ return IVAS_AUDIO_CONFIG_7_1_4;
+ }
+ if ( strncmp( charBuf, "ISM", 3 ) == 0 )
+ {
+ /* Accept input config as ISM only if the 4th character is a number from 1 to 4.
+ * Otherwise, do nothing. Unknown audio config will be returned. */
+ switch ( charBuf[3] )
+ {
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ return IVAS_AUDIO_CONFIG_OBA;
+ }
+ }
+ if ( strncmp( charBuf, "MASA", 4 ) == 0 )
+ {
+ switch ( charBuf[4] )
+ {
+ case '1':
+ fprintf( stderr, "1TC MASA support is not functional and is pending on DirAC renderer refactoring.\n" );
+ exit( EXIT_FAILURE );
+ /*return IVAS_AUDIO_CONFIG_MASA1;*/ // ToDo: temporarily disabled to avoid compilation warnings
+ case '2':
+ return IVAS_AUDIO_CONFIG_MASA2;
+ default:
+ return IVAS_AUDIO_CONFIG_INVALID;
+ }
+ }
+ if ( strcmp( charBuf, "BINAURAL" ) == 0 )
+ {
+ return IVAS_AUDIO_CONFIG_BINAURAL;
+ }
+ if ( strcmp( charBuf, "BINAURAL_ROOM_IR" ) == 0 )
+ {
+ return IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR;
+ }
+ if ( strcmp( charBuf, "BINAURAL_ROOM_REVERB" ) == 0 )
+ {
+ return IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB;
+ }
+ return IVAS_AUDIO_CONFIG_INVALID;
+}
+
+static bool parseLfePositionConfig(
+ const char *value,
+ float *lfeGain,
+ float *lfeAzimuth,
+ float *lfeElevation )
+{
+ uint8_t nvalues;
+ const char *tok;
+ float values[3];
+ char config_string[RENDERER_MAX_METADATA_LINE_LENGTH];
+
+ strncpy( config_string, value, RENDERER_MAX_METADATA_LINE_LENGTH );
+ nvalues = 0;
+
+ for ( tok = strtok( config_string, "," ); tok && *tok; tok = strtok( NULL, ",\n" ) )
+ {
+ while ( *tok == ' ' )
+ {
+ tok++;
+ }
+
+ if ( *tok == '\0' )
+ {
+ continue;
+ }
+ values[nvalues] = (float) atof( tok );
+ nvalues++;
+
+ /* ignore any additionally specified values */
+ if ( nvalues == 3 )
+ {
+ break;
+ }
+ }
+
+ if ( nvalues != 3 )
+ {
+ return false;
+ }
+
+ *lfeGain = values[0];
+ *lfeAzimuth = values[1];
+ *lfeElevation = values[2];
+ return true;
+}
+
+
+static bool checkRequiredArgs(
+ CmdlnArgs args )
+{
+ const CmdLnParser_Option *tmpOption;
+
+ /* Check required arguments */
+ bool missingRequiredArg = false;
+ if ( isEmptyString( args.inputFilePath ) )
+ {
+ tmpOption = findOptionById( CmdLnOptionId_inputFile );
+ fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort );
+ missingRequiredArg = true;
+ }
+
+ const bool singleInputSpecified = args.inConfig.numAudioObjects != 0 ||
+ args.inConfig.numAmbisonicsBuses != 0 ||
+ args.inConfig.numMultiChannelBuses != 0 ||
+ args.inConfig.numMasaBuses != 0;
+
+ if ( !args.sceneDescriptionInput && !singleInputSpecified )
+ {
+ /* Neither scene description input nor single-type input was specified on command line */
+ tmpOption = findOptionById( CmdLnOptionId_inputFormat );
+ fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort );
+ missingRequiredArg = true;
+ }
+ if ( isEmptyString( args.outputFilePath ) )
+ {
+ tmpOption = findOptionById( CmdLnOptionId_outputFile );
+ fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort );
+ missingRequiredArg = true;
+ }
+ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_INVALID )
+ {
+ tmpOption = findOptionById( CmdLnOptionId_outputFormat );
+ fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort );
+ missingRequiredArg = true;
+ }
+ if ( missingRequiredArg )
+ {
+ CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions );
+ }
+
+ return !missingRequiredArg;
+}
+
+static CmdlnArgs defaultArgs(
+ const char *executableName )
+{
+ CmdlnArgs args;
+
+ strncpy( args.executableName, executableName, RENDERER_MAX_CLI_ARG_LENGTH );
+ clearString( args.inputFilePath );
+ clearString( args.outputFilePath );
+ args.sampleRate = 0;
+
+ args.inConfig.inSetupCustom.num_spk = 0;
+ args.inConfig.inSetupCustom.num_lfe = 0;
+ args.inConfig.numAudioObjects = 0;
+ args.inConfig.numAmbisonicsBuses = 0;
+ args.inConfig.numMultiChannelBuses = 0;
+ args.inConfig.numMasaBuses = 0;
+
+ args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_INVALID;
+ args.outConfig.outSetupCustom.num_spk = 0;
+ args.outConfig.outSetupCustom.num_lfe = 0;
+
+ for ( int32_t i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i )
+ {
+ clearString( args.inMetadataFilePaths[i] );
+ }
+ args.numInMetadataFiles = 0;
+
+ clearString( args.headRotationFilePath );
+ clearString( args.referenceVectorFilePath );
+ clearString( args.referenceRotationFilePath );
+ clearString( args.customHrtfFilePath );
+ clearString( args.renderConfigFilePath );
+ clearString( args.externalOrientationFilePath );
+
+ args.orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE;
+ args.nonDiegeticPan = 0;
+ args.nonDiegeticPanGain = 0.f;
+
+ args.delayCompensationEnabled = true;
+ args.quietModeEnabled = false;
+ args.sceneDescriptionInput = false;
+ args.inputGainGlobal = 1.0f;
+
+ args.lfePanningEnabled = false;
+ args.lfeConfigGain = 1.0f;
+ args.lfeConfigAzimuth = 0.f;
+ args.lfeConfigElevation = 0.f;
+
+ args.lfeCustomRoutingEnabled = false;
+ clearString( args.inLfePanningMatrixFile );
+ args.framing_5ms = false;
+ args.syncMdDelay = 0;
+
+ for ( int32_t i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i )
+ {
+ args.directivityPatternId[i] = 65535;
+ }
+
+ args.acousticEnvironmentId = 65535;
+
+ return args;
+}
+
+static void parseOption(
+ const int32_t optionId,
+ char **optionValues,
+ const int16_t numOptionValues,
+ void *pOutputStruct )
+{
+ CmdlnArgs *args = pOutputStruct;
+
+ switch ( optionId )
+ {
+ case CmdLnOptionId_listFormats:
+ assert( numOptionValues == 0 );
+ printSupportedAudioConfigs();
+ exit( 0 );
+ case CmdLnOptionId_inputFile:
+ assert( numOptionValues == 1 );
+ strncpy( args->inputFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+ break;
+ case CmdLnOptionId_inputFormat:
+ assert( numOptionValues == 1 );
+ if ( !parseInConfig( optionValues[0], &args->inConfig, &args->sceneDescriptionInput ) )
+ {
+ exit( -1 ); /* Error printout handled by failing function */
+ }
+ break;
+ case CmdLnOptionId_inputMetadata:
+ assert( numOptionValues <= RENDERER_MAX_ISM_INPUTS );
+ for ( int16_t i = 0; i < numOptionValues; ++i )
+ {
+ strncpy( args->inMetadataFilePaths[i], optionValues[i], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+ }
+ args->numInMetadataFiles = numOptionValues;
+ break;
+ case CmdLnOptionId_outputFile:
+ assert( numOptionValues == 1 );
+ strncpy( args->outputFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+ break;
+ case CmdLnOptionId_outputFormat:
+ assert( numOptionValues == 1 );
+ if ( !parseOutConfig( optionValues[0], &args->outConfig ) )
+ {
+ exit( -1 ); /* Error printout handled by failing function */
+ }
+ 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 );
+ }
+ break;
+ case CmdLnOptionId_trajFile:
+ assert( numOptionValues == 1 );
+ strncpy( args->headRotationFilePath, 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 );
+ break;
+ case CmdLnOptionId_refRotFile:
+ assert( numOptionValues == 1 );
+ strncpy( args->referenceRotationFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+ break;
+ case CmdLnOptionId_exteriorOrientationFile:
+ assert( numOptionValues == 1 );
+ strncpy( args->externalOrientationFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+ break;
+ case CmdLnOptionId_customHrtfFile:
+ assert( numOptionValues == 1 );
+ strncpy( args->customHrtfFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+ break;
+ case CmdLnOptionId_renderConfigFile:
+ assert( numOptionValues == 1 );
+ strncpy( args->renderConfigFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+ break;
+ case CmdLnOptionId_nonDiegeticPan:
+ assert( numOptionValues == 1 );
+ if ( !parseDiegeticPan( optionValues[0], &args->nonDiegeticPanGain ) )
+ {
+ fprintf( stderr, "Unknown option for diegetic panning: %s\n", optionValues[0] );
+ exit( -1 );
+ }
+ args->nonDiegeticPan = 1;
+ break;
+ case CmdLnOptionId_orientationTracking:
+ assert( numOptionValues == 1 );
+ if ( !parseOrientationTracking( optionValues[0], &args->orientation_tracking ) )
+ {
+ fprintf( stderr, "Unknown option for orientation tracking: %s\n", optionValues[0] );
+ exit( -1 );
+ }
+ break;
+ case CmdlnOptionId_lfePosition:
+ assert( numOptionValues == 1 );
+ if ( !parseLfePositionConfig( optionValues[0], &args->lfeConfigGain, &args->lfeConfigAzimuth, &args->lfeConfigElevation ) )
+ {
+ fprintf( stderr, "Unknown or invalid option for LFE position: %s\n", optionValues[0] );
+ exit( -1 );
+ }
+ args->lfePanningEnabled = true;
+ break;
+ break;
+ case CmdlnOptionId_lfeMatrix:
+ assert( numOptionValues == 1 );
+ strncpy( args->inLfePanningMatrixFile, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+ args->lfeCustomRoutingEnabled = true;
+ break;
+ case CmdLnOptionId_complexityLevel:
+ assert( numOptionValues == 1 );
+ args->complexityLevel = (int32_t) ( strtol( optionValues[0], NULL, 10 ) );
+ if ( args->complexityLevel < IVAS_REND_COMPLEXITY_LEVEL_ONE || args->complexityLevel > IVAS_REND_COMPLEXITY_LEVEL_THREE )
+ {
+ fprintf( stdout, "Invalid complexity level specified.\n" );
+ exit( -1 );
+ }
+ else if ( args->complexityLevel == IVAS_REND_COMPLEXITY_LEVEL_ONE || args->complexityLevel == IVAS_REND_COMPLEXITY_LEVEL_TWO )
+ {
+ fprintf( stdout, "Complexity levels 1 and 2 will be defined after characterisation - default to level 3 (full functionality).\n" );
+ }
+ break;
+ case CmdLnOptionId_noDelayCmp:
+ assert( numOptionValues == 0 );
+ args->delayCompensationEnabled = false;
+ break;
+ case CmdLnOptionId_quietModeEnabled:
+ assert( numOptionValues == 0 );
+ args->quietModeEnabled = true;
+ break;
+ case CmdLnOptionId_inputGain:
+ assert( numOptionValues == 1 );
+ args->inputGainGlobal = strtof( optionValues[0], NULL );
+ if ( args->inputGainGlobal == 0.0f )
+ {
+ fprintf( stderr, "Invalid input gain specified\n" );
+ exit( -1 );
+ }
+ break;
+ case CmdLnOptionId_framing5ms:
+ assert( numOptionValues == 0 );
+ args->framing_5ms = true;
+ fprintf( stderr, "Warning: this is a placeholder for 5ms framing.\n" );
+ break;
+ case CmdLnOptionId_directivityPatternId:
+ assert( numOptionValues <= RENDERER_MAX_ISM_INPUTS );
+ for ( int16_t i = 0; i < numOptionValues; ++i )
+ {
+ args->directivityPatternId[i] = (int16_t) strtol( optionValues[i], NULL, 10 );
+ }
+ break;
+ case CmdLnOptionId_acousticEnvironmentId:
+ assert( numOptionValues == 1 );
+ if ( !is_digits_only( optionValues[0] ) )
+ {
+ fprintf( stderr, "Invalid acousting environment ID specified: %s\n", optionValues[0] );
+ exit( -1 );
+ }
+ args->acousticEnvironmentId = (int16_t) strtol( optionValues[0], NULL, 10 );
+ break;
+ case CmdLnOptionId_syncMdDelay:
+ assert( numOptionValues == 1 );
+ /* Metadata Delay to sync with audio delay in ms */
+ args->syncMdDelay = strtof( optionValues[0], NULL );
+ break;
+ default:
+ assert( 0 && "This should be unreachable - all command line options should be explicitly handled." );
+ break;
+ }
+
+ return;
+}
+
+static CmdlnArgs parseCmdlnArgs(
+ const int argc,
+ char **argv )
+{
+ CmdlnArgs args = defaultArgs( argv[0] );
+
+ if ( CmdLnParser_parseArgs( argc, argv, cliOptions, numCliOptions, &args, parseOption ) != 0 )
+ {
+ exit( -1 ); /* Error printout handled by failing function */
+ }
+
+ if ( !checkRequiredArgs( args ) )
+ {
+ exit( -1 ); /* Error printout handled by failing function */
+ }
+
+ return args;
+}
+
+
+IsmPositionProvider *IsmPositionProvider_open(
+ void )
+{
+ IsmPositionProvider *ipp;
+ uint16_t i;
+
+ ipp = (IsmPositionProvider *) malloc( sizeof( IsmPositionProvider ) );
+ ipp->frameCounter = 0;
+ ipp->numObjects = 0;
+
+ for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i )
+ {
+ ipp->ismReaders[i] = NULL;
+ ipp->positions[i] = NULL;
+ ipp->positionDurations[i] = NULL;
+ ipp->currentPositionIdxs[i] = 0;
+ ipp->durationCounters[i] = 0;
+ }
+
+ return ipp;
+}
+
+LfeRoutingConfig *LfeRoutingConfig_open(
+ void )
+{
+ LfeRoutingConfig *lrc;
+
+ lrc = (LfeRoutingConfig *) malloc( sizeof( LfeRoutingConfig ) );
+ lrc->lfe_azi = 0.f;
+ lrc->lfe_ele = 0.f;
+ lrc->lfe_gain_dB = 0.f;
+ lrc->lfe_routing_mtx[0] = '\0';
+
+ return lrc;
+}
+
+void LfeRoutingConfig_close(
+ LfeRoutingConfig *lfeRoutingCfg )
+{
+ if ( lfeRoutingCfg != NULL )
+ {
+
+ free( lfeRoutingCfg );
+ }
+
+ return;
+}
+
+void getMetadataFromFileReader(
+ IsmFileReader *ismReader,
+ ObjectPositionBuffer *objectMetadataBuffer,
+ const uint32_t objIdx )
+{
+ IVAS_ISM_METADATA ismMetadata;
+ ivas_error error;
+
+ if ( ( error = IsmFileReader_readNextFrame( ismReader, &ismMetadata ) ) != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "\nError (%s) while reading ISM metadata from: %s\n\n", ivas_error_to_string( error ), IsmFileReader_getFilePath( ismReader ) );
+ exit( -1 );
+ }
+
+ 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;
+ objectMetadataBuffer->positions[objIdx].non_diegetic_flag = ismMetadata.non_diegetic_flag;
+
+ return;
+}
+
+void readFromShorthandMetadata(
+ IsmPositionProvider *positionProvider,
+ ObjectPositionBuffer *objectMetadataBuffer,
+ const uint32_t objIdx )
+{
+ uint32_t preUpdatePositionIdx;
+ uint32_t postUpdatePositionIdx;
+
+ preUpdatePositionIdx = positionProvider->currentPositionIdxs[objIdx];
+
+ if ( positionProvider->durationCounters[objIdx] == positionProvider->positionDurations[objIdx][preUpdatePositionIdx] )
+ {
+ positionProvider->durationCounters[objIdx] = 0;
+ positionProvider->currentPositionIdxs[objIdx] = ( positionProvider->currentPositionIdxs[objIdx] + 1 ) % positionProvider->numPositions[objIdx];
+ }
+
+ ++positionProvider->durationCounters[objIdx];
+
+ postUpdatePositionIdx = positionProvider->currentPositionIdxs[objIdx];
+
+ objectMetadataBuffer->positions[objIdx] = positionProvider->positions[objIdx][postUpdatePositionIdx];
+
+ return;
+}
+
+static void IsmPositionProvider_getNextFrame(
+ IsmPositionProvider *positionProvider,
+ ObjectPositionBuffer *objectMetadataBuffer )
+{
+ uint32_t objIdx;
+
+ objectMetadataBuffer->numObjects = positionProvider->numObjects;
+
+ for ( objIdx = 0; objIdx < positionProvider->numObjects; ++objIdx )
+ {
+ /* If ISM metadata reader is open, read from metadata file */
+ if ( positionProvider->ismReaders[objIdx] != NULL )
+ {
+ getMetadataFromFileReader( positionProvider->ismReaders[objIdx], objectMetadataBuffer, objIdx );
+ }
+ /* Otherwise, if positions were provided in a scene description file, use them */
+ else if ( positionProvider->positions[objIdx] != NULL )
+ {
+ readFromShorthandMetadata( positionProvider, objectMetadataBuffer, objIdx );
+ }
+ /* Otherwise fall back to default position */
+ 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;
+ }
+
+ /* Wrap azimuth to lie within (-180, 180] range */
+ 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 );
+ /* 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 );
+ }
+
+ ++positionProvider->frameCounter;
+
+ return;
+}
+
+static void IsmPositionProvider_close(
+ IsmPositionProvider *positionProvider )
+{
+ uint32_t i;
+
+ if ( positionProvider == NULL )
+ {
+ assert( !"Can't close IsmPositionProvider - pointer is NULL" );
+ }
+
+ for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i )
+ {
+ if ( positionProvider->ismReaders[i] != NULL )
+ {
+ IsmFileReader_close( &positionProvider->ismReaders[i] );
+ }
+
+ if ( positionProvider->positions[i] != NULL )
+ {
+ free( positionProvider->positions[i] );
+ }
+
+ if ( positionProvider->positionDurations[i] != NULL )
+ {
+ free( positionProvider->positionDurations[i] );
+ }
+ }
+
+ free( positionProvider );
+
+ return;
+}
+
+static void splitConfigFile(
+ const char *mdfFilePath,
+ char *metadataString,
+ uint32_t *metadataStringLength,
+ char *wavFileName,
+ uint32_t *wavFileNameLength )
+{
+ FILE *file;
+ uint32_t bufferlength;
+ char wavLine[FILENAME_MAX];
+ uint32_t currentPositionIdxs;
+ uint32_t mdlength;
+
+ memset( metadataString, 0, *metadataStringLength );
+ memset( wavFileName, 0, (int16_t) *wavFileNameLength );
+
+ file = fopen( mdfFilePath, "rb" );
+ if ( !file )
+ {
+ fprintf( stderr, "Couldn't open metadata file %s\n", mdfFilePath );
+ exit( -1 );
+ }
+
+ fseek( file, 0, SEEK_END );
+ bufferlength = ftell( file );
+ fseek( file, 0, SEEK_SET );
+
+ if ( fgets( wavLine, (int) *wavFileNameLength, file ) == NULL )
+ {
+ fprintf( stderr, "Error reading metadata\n" );
+ exit( -1 );
+ }
+ currentPositionIdxs = ftell( file );
+ if ( *wavFileNameLength < currentPositionIdxs )
+ {
+ assert( !"Couldn't read wavFileName, string buffer too small" );
+ }
+ if ( !sscanf( wavLine, "%s", wavFileName ) )
+ {
+ fprintf( stderr, "Error reading metadata\n" );
+ exit( -1 );
+ }
+ *wavFileNameLength = (uint32_t) strlen( wavFileName );
+
+ mdlength = bufferlength - currentPositionIdxs;
+ /* "+1" for null termination */
+ if ( *metadataStringLength + 1 < mdlength )
+ {
+ assert( !"Couldn't read metadata string, string buffer too small" );
+ }
+
+ fread( metadataString, 1, mdlength, file );
+ metadataString[mdlength] = '\0';
+ *metadataStringLength = mdlength + 1;
+
+ fclose( file );
+
+ return;
+}
+
+/* r: pointer to character following last found delimiter */
+static char *readNextMetadataChunkFrom(
+ char *start_char,
+ char *line,
+ const char *delimiter )
+{
+ char *token;
+
+ /* start_char can be NULL - it's used to continue parsing with strtok */
+ assert( line != NULL && delimiter != NULL && "unexpected NULL ptr given to readNextMetadataChunkFrom()" );
+
+ token = strtok( start_char, delimiter );
+
+ /* End of string reached */
+ if ( token == NULL )
+ {
+ /* Clear `line` from previous contents and return NULL */
+ clearString( line );
+ return NULL;
+ }
+
+ strcpy( line, token );
+
+ return token + strlen( token ) + 1;
+}
+
+/* r: pointer to character following last found delimiter */
+static char *readNextMetadataChunk(
+ char *line,
+ const char *delimiter )
+{
+ return readNextMetadataChunkFrom( NULL, line, delimiter );
+}
+
+static void parseUint8(
+ const char *line,
+ uint8_t *ret )
+{
+ char *ptr;
+ ptr = NULL;
+
+ *ret = (uint8_t) strtol( line, &ptr, 10 );
+ if ( ptr == NULL || *ptr != '\0' )
+ {
+ fprintf( stderr, "Cannot parse string \"%s\" as an integer value\n", line );
+ exit( -1 );
+ }
+
+ return;
+}
+
+static int8_t parseUint32(
+ const char *line,
+ uint32_t *ret )
+{
+ char *ptr;
+ ptr = NULL;
+
+ *ret = strtol( line, &ptr, 10 );
+ if ( ptr == NULL || *ptr != '\0' )
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+static int8_t parseInt32(
+ const char *line,
+ int32_t *ret )
+{
+ char *ptr;
+ ptr = NULL;
+
+ *ret = strtol( line, &ptr, 10 );
+ if ( ptr == NULL || *ptr != '\0' )
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+static void parseOptionalInputValues(
+ char *line,
+ float *lfe_gain_dB,
+ float *lfe_pos_azi,
+ float *lfe_pos_ele,
+ char *lfe_pan_mtx_filename,
+ float *gain_dB )
+{
+ char *parse_pos;
+ char *key;
+ char *value;
+ char *endptr;
+
+ endptr = NULL;
+
+ /* Set default values, in case some values are not specified */
+ *gain_dB = 0.f;
+ if ( lfe_gain_dB != NULL )
+ {
+ *lfe_gain_dB = 0.f;
+ }
+ if ( lfe_pos_azi != NULL )
+ {
+ *lfe_pos_azi = 0.f;
+ }
+ if ( lfe_pos_ele != NULL )
+ {
+ *lfe_pos_ele = 0.f;
+ }
+ if ( lfe_pan_mtx_filename != NULL )
+ {
+ *lfe_pan_mtx_filename = '\0';
+ }
+
+ /* Save parsing position - will have to be passed to strtok to resume parsing after using strtok with non-NULL value below */
+ parse_pos = readNextMetadataChunk( line, "\n" );
+
+ /* Look for optional metadata until end of string or next input identifier is found */
+ while ( parse_pos != NULL && strcmp( line, "MC" ) != 0 && strcmp( line, "SBA" ) != 0 && strcmp( line, "ISM" ) != 0 && strcmp( line, "MASA" ) != 0 )
+ {
+ key = strtok( line, ":" );
+ value = strtok( NULL, "\n" );
+
+ if ( strcmp( key, "gain_dB" ) == 0 )
+ {
+ *gain_dB = (float) strtod( value, &endptr );
+
+ if ( *endptr != '\0' )
+ {
+ fprintf( stderr, "Cannot parse string \"%s\" as a float value\n", value );
+ exit( -1 );
+ }
+ }
+ else if ( ( strcmp( key, "lfe_gain_dB" ) == 0 ) && lfe_gain_dB != NULL )
+ {
+ *lfe_gain_dB = (float) strtod( value, &endptr );
+
+ if ( *endptr != '\0' )
+ {
+ fprintf( stderr, "Cannot parse string \"%s\" as a float value\n", value );
+ exit( -1 );
+ }
+ }
+ else if ( ( strcmp( key, "lfe_azi" ) == 0 ) && lfe_pos_azi != NULL )
+ {
+ *lfe_pos_azi = (float) strtod( value, &endptr );
+
+ if ( *endptr != '\0' )
+ {
+ fprintf( stderr, "Cannot parse string \"%s\" as a float value\n", value );
+ exit( -1 );
+ }
+ }
+ else if ( ( strcmp( key, "lfe_ele" ) == 0 ) && lfe_pos_ele != NULL )
+ {
+ *lfe_pos_ele = (float) strtod( value, &endptr );
+
+ if ( *endptr != '\0' )
+ {
+ fprintf( stderr, "Cannot parse string \"%s\" as a float value\n", value );
+ exit( -1 );
+ }
+ }
+ else if ( strcmp( key, "lfe_matrix" ) == 0 )
+ {
+ strncpy( lfe_pan_mtx_filename, value, FILENAME_MAX - 1 );
+ }
+ else
+ {
+ fprintf( stderr, "Unsupported optional key: %s\n", key );
+ exit( -1 );
+ }
+
+ parse_pos = readNextMetadataChunkFrom( parse_pos, line, "\n" );
+ }
+
+ return;
+}
+
+static void parseObjectPosition(
+ char *line,
+ IVAS_ISM_METADATA *position,
+ uint16_t *positionDuration )
+{
+ char *endptr;
+ int16_t read_values;
+ float meta_prm[8] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f };
+
+
+ readNextMetadataChunk( line, "," );
+ *positionDuration = (uint16_t) strtol( line, &endptr, 10 );
+ readNextMetadataChunk( line, "\n" );
+
+ read_values = (int16_t) sscanf( line, "%f,%f,%f,%f,%f,%f,%f,%f", &meta_prm[0], &meta_prm[1], &meta_prm[2], &meta_prm[3], &meta_prm[4], &meta_prm[5], &meta_prm[6], &meta_prm[7] );
+
+ if ( read_values < 2 )
+ {
+ fprintf( stderr, "Error reading metadata\n" );
+ exit( -1 );
+ }
+
+ position->azimuth = meta_prm[0];
+ position->elevation = meta_prm[1];
+ position->radius = meta_prm[2];
+ position->yaw = meta_prm[5];
+ position->pitch = meta_prm[6];
+ position->non_diegetic_flag = (int16_t) meta_prm[7];
+
+ return;
+}
+
+static void parseIsm(
+ char *line,
+ char *inDir,
+ InputConfig *inConfig,
+ IsmPositionProvider *positionProvider,
+ const int32_t idx )
+{
+ uint32_t numberOfObjectPositionsToRead;
+ uint32_t i;
+
+ readNextMetadataChunk( line, "\n" );
+ parseInt32( line, &inConfig->audioObjects[idx].inputChannelIndex );
+ --inConfig->audioObjects[idx].inputChannelIndex; /* Convert from 1-indexing */
+
+ readNextMetadataChunk( line, "\n" );
+
+ /* Try to interpret line as number of positions to read */
+ if ( parseUint32( line, &numberOfObjectPositionsToRead ) == 0 )
+ {
+ positionProvider->numPositions[idx] = numberOfObjectPositionsToRead;
+ positionProvider->positions[idx] = malloc( numberOfObjectPositionsToRead * sizeof( IVAS_ISM_METADATA ) );
+ positionProvider->positionDurations[idx] = malloc( numberOfObjectPositionsToRead * sizeof( uint16_t ) );
+
+ for ( i = 0; i < numberOfObjectPositionsToRead; ++i )
+ {
+ parseObjectPosition( line, &positionProvider->positions[idx][i], &positionProvider->positionDurations[idx][i] );
+ }
+ }
+ else /* If not a number, it is a relative path from main metadata file to a metadata file */
+ {
+ char fullpath[FILENAME_MAX];
+ fullpath[0] = '\0';
+ strncat( fullpath, inDir, strlen( inDir ) );
+ strncat( fullpath, line, sizeof( fullpath ) - strlen( fullpath ) - 1 );
+ if ( ( positionProvider->ismReaders[idx] = IsmFileReader_open( fullpath ) ) == NULL )
+ {
+ fprintf( stderr, "Error: ISM input metadata file %s could not be opened\n", fullpath );
+ exit( -1 );
+ }
+ }
+
+ /* Read optional values */
+ parseOptionalInputValues( line, NULL, NULL, NULL, NULL, &inConfig->audioObjects[idx].gain_dB );
+
+ return;
+}
+
+static void parseSba(
+ char *line,
+ InputConfig *inConfig,
+ const int32_t idx )
+{
+ uint8_t ambiOrder;
+
+ readNextMetadataChunk( line, "\n" );
+ parseInt32( line, &inConfig->ambisonicsBuses[idx].inputChannelIndex );
+ --inConfig->ambisonicsBuses[idx].inputChannelIndex; /* Convert from 1-indexing */
+
+ readNextMetadataChunk( line, "\n" );
+ parseUint8( line, &ambiOrder );
+ inConfig->ambisonicsBuses[idx].audioConfig = ambisonicsOrderToEnum( ambiOrder );
+
+ /* Read optional values */
+ parseOptionalInputValues( line, NULL, NULL, NULL, NULL, &inConfig->ambisonicsBuses[idx].gain_dB );
+
+ return;
+}
+
+static void parseMc(
+ char *line,
+ InputConfig *inConfig,
+ LfeRoutingConfig **lfeRoutingConfigs,
+ const int32_t idx )
+{
+ readNextMetadataChunk( line, "\n" );
+ parseInt32( line, &inConfig->multiChannelBuses[idx].inputChannelIndex );
+ --inConfig->multiChannelBuses[idx].inputChannelIndex; /* Convert from 1-indexing */
+
+ readNextMetadataChunk( line, "\n" );
+ IVAS_AUDIO_CONFIG cfg = parseAudioConfig( line );
+ /* Try to use the given string as a path to a custom loudspeaker layout file. */
+ if ( cfg == IVAS_AUDIO_CONFIG_INVALID )
+ {
+ ivas_error error = parseCustomLayoutFile( line, &inConfig->inSetupCustom );
+
+ if ( error != IVAS_ERR_OK )
+ {
+ fprintf( stderr, "Error while parsing input format %s\n", line );
+ exit( -1 );
+ }
+ inConfig->numMultiChannelBuses = 1;
+ inConfig->multiChannelBuses[idx].audioConfig = IVAS_AUDIO_CONFIG_LS_CUSTOM;
+ inConfig->multiChannelBuses[idx].inputChannelIndex = 0;
+ inConfig->multiChannelBuses[idx].gain_dB = 0.0f;
+ }
+ else
+ {
+ inConfig->multiChannelBuses[idx].audioConfig = cfg;
+ }
+
+ /* Read optional values */
+ bool lfe_panningEnabled;
+ float lfe_gain_dB, lfe_azi, lfe_ele;
+ char lfe_routing_mtx[FILENAME_MAX];
+
+ parseOptionalInputValues( line, &lfe_gain_dB, &lfe_azi, &lfe_ele, lfe_routing_mtx, &inConfig->multiChannelBuses[idx].gain_dB );
+
+ lfe_panningEnabled = ( lfe_gain_dB != 0.f || lfe_azi != 0.f || lfe_ele != 0.f ) ? true : false;
+
+ if ( lfe_panningEnabled && !isEmptyString( lfe_routing_mtx ) )
+ {
+ fprintf( stderr, "Warning: LFE position specified as well as panning matrix! Ignoring position and using gains from panning matrix\n" );
+ lfe_panningEnabled = false;
+ }
+
+ if ( lfe_panningEnabled || !isEmptyString( lfe_routing_mtx ) )
+ {
+ /* a configuration was specified, set the values */
+ lfeRoutingConfigs[idx] = LfeRoutingConfig_open();
+
+ if ( lfe_panningEnabled )
+ {
+ lfeRoutingConfigs[idx]->lfe_gain_dB = lfe_gain_dB;
+ lfeRoutingConfigs[idx]->lfe_azi = lfe_azi;
+ lfeRoutingConfigs[idx]->lfe_ele = lfe_ele;
+ }
+
+ if ( !isEmptyString( lfe_routing_mtx ) )
+ {
+ strncpy( lfeRoutingConfigs[idx]->lfe_routing_mtx, lfe_routing_mtx, FILENAME_MAX );
+ convert_backslash( lfeRoutingConfigs[idx]->lfe_routing_mtx );
+ }
+ }
+
+ return;
+}
+
+static void parseMasa(
+ char *line,
+ char *inDir,
+ InputConfig *inConfig,
+ MasaFileReader **masaReaders,
+ const int32_t idx )
+{
+ readNextMetadataChunk( line, "\n" );
+ parseInt32( line, &inConfig->masaBuses[idx].inputChannelIndex );
+ --inConfig->masaBuses[idx].inputChannelIndex; /* Convert from 1-indexing */
+
+ readNextMetadataChunk( line, "\n" );
+
+ /* Allow both just the number of TCs or MASAx. parseStrToAudioCfg() only accepts MASAx, so prepend if necessary. */
+ if ( strncmp( line, "MASA", 4 ) != 0 )
+ {
+ char numTcs = *line;
+ snprintf( line, 6 /* write at most 6 characters: MASAx + null termination */, "MASA%c", numTcs );
+ }
+
+ inConfig->masaBuses[idx].audioConfig = parseAudioConfig( line );
+
+ readNextMetadataChunk( line, "\n" );
+
+ char fullpath[FILENAME_MAX];
+ fullpath[0] = '\0';
+ strncat( fullpath, inDir, strlen( inDir ) );
+ strncat( fullpath, line, sizeof( fullpath ) - strlen( fullpath ) - 1 );
+
+ if ( ( masaReaders[idx] = MasaFileReader_open( fullpath ) ) == NULL )
+ {
+ fprintf( stderr, "Error: MASA metadata file %s could not be opened\n", fullpath );
+ exit( -1 );
+ }
+
+ /* Read optional values */
+ parseOptionalInputValues( line, NULL, NULL, NULL, NULL, &inConfig->masaBuses[idx].gain_dB );
+
+ return;
+}
+
+static ivas_error parseCustomLayoutFile(
+ const char *filePath,
+ IVAS_CUSTOM_LS_DATA *pLsSetupCustom )
+{
+ LsCustomFileReader *hLsCustomReader = NULL;
+ IVAS_CUSTOM_LS_DATA hLsCustomData;
+ ivas_error error;
+
+ if ( ( error = CustomLsReader_open( filePath, &hLsCustomReader ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( CustomLsFileReading( hLsCustomReader, &hLsCustomData ) != LS_CUSTOM_FILEREADER_NO_ERROR )
+ {
+ return error;
+ }
+
+ pLsSetupCustom->num_spk = hLsCustomData.num_spk;
+
+ for ( int16_t i = 0; i < hLsCustomData.num_spk; i++ )
+ {
+ pLsSetupCustom->azimuth[i] = hLsCustomData.azimuth[i];
+ pLsSetupCustom->elevation[i] = hLsCustomData.elevation[i];
+ }
+
+ /* Loudspeaker LFE */
+ pLsSetupCustom->num_lfe = hLsCustomData.num_lfe;
+
+ for ( int16_t i = 0; i < hLsCustomData.num_lfe; i++ )
+ {
+ pLsSetupCustom->lfe_idx[i] = hLsCustomData.lfe_idx[i];
+ }
+
+ CustomLsReader_close( &hLsCustomReader );
+
+ return IVAS_ERR_OK;
+}
+
+static void parseMetadata(
+ char *metadataString,
+ char *inDir,
+ InputConfig *inConfig,
+ IsmPositionProvider *positionProvider,
+ MasaFileReader **masaReaders,
+ LfeRoutingConfig **lfeRoutingConfigs )
+{
+ char line[RENDERER_MAX_METADATA_LINE_LENGTH];
+ char *delimiter;
+ char *token;
+ uint8_t totalNumberOfAudioObjects;
+ uint8_t counterChannelAudioObjects;
+ uint8_t counterAmbisonicsAudioObjects;
+ uint8_t counterMonoAudioObjects;
+ uint8_t counterMasaInputs;
+ uint8_t num_parsed_inputs;
+
+ delimiter = "\n";
+
+ token = strtok( metadataString, delimiter );
+ if ( token == NULL )
+ {
+ fprintf( stderr, "Unexpected metadata format\n" );
+ exit( -1 );
+ }
+ if ( !sscanf( token, "%s", line ) )
+ {
+ fprintf( stderr, "Unexpected metadata format\n" );
+ exit( -1 );
+ }
+
+ parseUint8( line, &totalNumberOfAudioObjects );
+ if ( totalNumberOfAudioObjects <= 0 )
+ {
+ fprintf( stderr, "Invalid metadata: number of inputs should be > 0\n" );
+ exit( -1 );
+ }
+
+ num_parsed_inputs = 0;
+ counterChannelAudioObjects = 0;
+ counterAmbisonicsAudioObjects = 0;
+ counterMonoAudioObjects = 0;
+ counterMasaInputs = 0;
+
+ readNextMetadataChunk( line, delimiter );
+
+ while ( num_parsed_inputs < totalNumberOfAudioObjects )
+ {
+ /* `line` will already contain the identifier ("MC", "SBA" or "ISM") after previous iteration */
+ if ( strcmp( line, "MC" ) == 0 )
+ {
+ ++counterChannelAudioObjects;
+ if ( counterChannelAudioObjects > RENDERER_MAX_MC_INPUTS )
+ {
+ fprintf( stderr, "Metadata exceeds the supported number of MC inputs\n" );
+ exit( -1 );
+ }
+ parseMc( line, inConfig, lfeRoutingConfigs, counterChannelAudioObjects - 1 );
+ }
+ else if ( strcmp( line, "SBA" ) == 0 )
+ {
+ ++counterAmbisonicsAudioObjects;
+ if ( counterAmbisonicsAudioObjects > RENDERER_MAX_SBA_INPUTS )
+ {
+ fprintf( stderr, "Metadata exceeds the supported number of SBA inputs\n" );
+ exit( -1 );
+ }
+ parseSba( line, inConfig, counterAmbisonicsAudioObjects - 1 );
+ }
+ else if ( strcmp( line, "ISM" ) == 0 )
+ {
+ ++counterMonoAudioObjects;
+ if ( counterMonoAudioObjects > RENDERER_MAX_ISM_INPUTS )
+ {
+ fprintf( stderr, "Metadata exceeds the supported number of ISM inputs\n" );
+ exit( -1 );
+ }
+ parseIsm( line, inDir, inConfig, positionProvider, counterMonoAudioObjects - 1 );
+ }
+ else if ( strcmp( line, "MASA" ) == 0 )
+ {
+ ++counterMasaInputs;
+ if ( counterMasaInputs > RENDERER_MAX_MASA_INPUTS )
+ {
+ fprintf( stderr, "Metadata exceeds the supported number of MASA inputs\n" );
+ exit( -1 );
+ }
+ parseMasa( line, inDir, inConfig, masaReaders, counterMasaInputs - 1 );
+ }
+ else if ( isEmptyString( line ) )
+ {
+ fprintf( stderr, "Metadata string too short - expected %d inputs, found %d.\n", totalNumberOfAudioObjects, num_parsed_inputs );
+ exit( -1 );
+ }
+ else
+ {
+ fprintf( stderr, "Unexpected metadata identifier\n" );
+ exit( -1 );
+ }
+
+ ++num_parsed_inputs;
+ }
+
+ inConfig->numAudioObjects = counterMonoAudioObjects;
+ inConfig->numAmbisonicsBuses = counterAmbisonicsAudioObjects;
+ inConfig->numMultiChannelBuses = counterChannelAudioObjects;
+ inConfig->numMasaBuses = counterMasaInputs;
+ positionProvider->numObjects = counterMonoAudioObjects;
+
+ /* check for trailing text */
+ token = strtok( NULL, delimiter );
+ if ( token != NULL && sscanf( token, "%s", line ) )
+ {
+ fprintf( stderr, "Trailing text in metadata file\n" );
+ exit( -1 );
+ }
+
+ return;
+}
+
+static void parseSceneDescriptionFile(
+ char *path,
+ char *audioFilePath,
+ InputConfig *inConfig,
+ IsmPositionProvider *positionProvider,
+ MasaFileReader **masaReaders,
+ LfeRoutingConfig **lfeRoutingConfigs )
+{
+ uint32_t inAudioFilePathLen;
+ char inAudioFilePath[FILENAME_MAX];
+ uint32_t mtdStrLen;
+ char mtdStr[RENDERER_MAX_METADATA_LENGTH];
+ char inDir[FILENAME_MAX];
+ char *lastSlash = NULL;
+
+ inAudioFilePathLen = FILENAME_MAX;
+ mtdStrLen = RENDERER_MAX_METADATA_LENGTH;
+ splitConfigFile( path, mtdStr, &mtdStrLen, inAudioFilePath, &inAudioFilePathLen );
+
+ remove_cr( mtdStr );
+ convert_backslash( inAudioFilePath );
+
+ /* Trim config file path to get path to the dir containing it */
+ lastSlash = strrchr( path, SEP_FOLDER );
+ inDir[0] = '\0';
+ if ( lastSlash != NULL )
+ {
+ strncat( inDir, path, ( lastSlash - path + 1 ) );
+ }
+
+ /* Append audio file path (relative to config file location)
+ * to config file location path to get full absolute path */
+ strcpy( audioFilePath, inDir );
+ strncat( audioFilePath, inAudioFilePath, inAudioFilePathLen );
+
+ parseMetadata( mtdStr, inDir, inConfig, positionProvider, masaReaders, lfeRoutingConfigs );
+
+ return;
+}
+
+static void printSupportedAudioConfigs( void )
+{
+ uint16_t i;
+ const char *supportedFormats[] = {
+ "MONO",
+ "STEREO",
+ "5_1",
+ "5_1_2",
+ "5_1_4",
+ "7_1",
+ "7_1_4",
+ "Path to Custom Loudspeaker .txt file",
+ "FOA",
+ "HOA2",
+ "HOA3",
+ "ISMx (input only)",
+ "MASAx (input only)",
+ "BINAURAL (output only)",
+ "BINAURAL_ROOM_IR (output only)",
+ "BINAURAL_ROOM_REVERB (output only)",
+ };
+
+ fprintf( stdout, "Supported audio formats:\n" );
+ for ( i = 0; i < sizeof( supportedFormats ) / sizeof( *supportedFormats ); i++ )
+ {
+ fprintf( stdout, "%s\n", supportedFormats[i] );
+ }
+
+ return;
+}
+
+static ivas_error parseLfePanMtxFile(
+ const char *lfeRoutingMatrixFilePath,
+ IVAS_REND_LfePanMtx *lfePanMtx )
+{
+ int16_t i, lfe_in, ch_out;
+ const char *tok;
+ char line[200]; /* > (10 chars * IVAS_MAX_OUTPUT_CHANNELS) i.e. "-999, " */
+ FILE *mtxFile;
+
+ if ( strlen( lfeRoutingMatrixFilePath ) < 1 )
+ {
+ return IVAS_ERR_FAILED_FILE_OPEN;
+ }
+
+ mtxFile = fopen( lfeRoutingMatrixFilePath, "r" );
+
+ if ( !mtxFile )
+ {
+ return IVAS_ERR_FAILED_FILE_OPEN;
+ }
+
+ /* set default panning matrix to all zeros
+ any subsequent issue in file reading will gracefully exit the function */
+ for ( lfe_in = 0; lfe_in < IVAS_MAX_INPUT_LFE_CHANNELS; lfe_in++ )
+ {
+ for ( i = 0; i < IVAS_MAX_OUTPUT_CHANNELS; i++ )
+ {
+ ( *lfePanMtx )[lfe_in][i] = 0.0f;
+ }
+ }
+
+ for ( lfe_in = 0; lfe_in < IVAS_MAX_INPUT_LFE_CHANNELS; lfe_in++ )
+ {
+ ch_out = 0;
+
+ /* if EOF or a blank line is encountered, simply return */
+ if ( ( fgets( line, 200, mtxFile ) == NULL ) && ( strcmp( line, "\n" ) == 0 ) && ( strcmp( line, "\r\n" ) == 0 ) )
+ {
+ fclose( mtxFile );
+ return IVAS_ERR_OK;
+ }
+
+ for ( tok = strtok( line, "," ); tok && *tok; tok = strtok( NULL, ",\n" ) )
+ {
+ while ( *tok == ' ' )
+ {
+ tok++;
+ }
+
+ if ( *tok == '\0' )
+ {
+ continue;
+ }
+ if ( ch_out > IVAS_MAX_OUTPUT_CHANNELS )
+ {
+ break;
+ }
+ else
+ {
+ ( *lfePanMtx )[lfe_in][ch_out] = (float) atof( tok );
+ ch_out++;
+ }
+ }
+ }
+
+ fclose( mtxFile );
+
+ return IVAS_ERR_OK;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * convertInputBuffer()
+ *
+ * Convert input buffer from WAV/PCM file (int16_t, interleaved) to a format
+ * accepted by the renderer (float, packed)
+ *--------------------------------------------------------------------------*/
+
+static void convertInputBuffer(
+ const int16_t *intBuffer,
+ const int16_t numIntSamplesPerChannel,
+ const int16_t numFloatSamplesPerChannel,
+ const int16_t numChannels,
+ float *floatBuffer
+)
+{
+ int16_t chnl, smpl, i;
+
+ i = 0;
+
+ for ( smpl = 0; smpl < numFloatSamplesPerChannel; ++smpl )
+ {
+ for ( chnl = 0; chnl < numChannels; ++chnl )
+ {
+ if ( i < numIntSamplesPerChannel )
+ {
+ floatBuffer[chnl * numFloatSamplesPerChannel + smpl] = (float) intBuffer[i];
+ }
+ else
+ {
+ floatBuffer[chnl * numFloatSamplesPerChannel + smpl] = 0.f;
+ }
+
+ ++i;
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * convertOutputBuffer()
+ *
+ * Convert output buffer from the renderer (float, packed) to a format ready
+ * for writing to a WAV/PCM file (int16_t, interleaved)
+ *--------------------------------------------------------------------------*/
+
+static void convertOutputBuffer(
+ const float *floatBuffer,
+ const int16_t numSamplesPerChannel,
+ const int16_t numChannels,
+ int16_t *intBuffer
+)
+{
+ int16_t chnl, smpl, i;
+ float temp;
+
+ i = 0;
+
+ for ( smpl = 0; smpl < numSamplesPerChannel; ++smpl )
+ {
+ for ( chnl = 0; chnl < numChannels; ++chnl )
+ {
+ temp = floatBuffer[chnl * numSamplesPerChannel + smpl];
+ temp = (float) floor( temp + 0.5f );
+ if ( temp > IVAS_MAX16B_FLT )
+ {
+ temp = IVAS_MAX16B_FLT;
+ }
+ else if ( temp < IVAS_MIN16B_FLT )
+ {
+ temp = IVAS_MIN16B_FLT;
+ }
+ intBuffer[i] = (int16_t) temp;
+
+ ++i;
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/ACcontextMapping.c b/lib_com/ACcontextMapping.c
new file mode 100644
index 0000000000000000000000000000000000000000..13cbe8482ba51ad3f2768d9e29d66198cd01810a
--- /dev/null
+++ b/lib_com/ACcontextMapping.c
@@ -0,0 +1,107 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * get_next_coeff_mapped()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+/*! r: index of next coefficient */
+int16_t get_next_coeff_mapped(
+ int16_t ii[2], /* i/o: coefficient indexes */
+ int32_t *pp, /* o : peak(1)/hole(0) indicator */
+ int16_t *idx, /* o : index in unmapped domain */
+ CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */
+)
+{
+ uint32_t p;
+
+ p = ( ii[1] - hm_cfg->numPeakIndices ) & ( hm_cfg->indexBuffer[ii[1]] - hm_cfg->indexBuffer[ii[0]] );
+ p >>= sizeof( p ) * 8 - 1;
+ *pp = p;
+ *idx = ii[p];
+ ii[p]++;
+
+ return hm_cfg->indexBuffer[*idx];
+}
+
+
+/*-------------------------------------------------------------------*
+ * get_next_coeff_unmapped()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+/*! r: index of next coefficient */
+int16_t get_next_coeff_unmapped(
+ int16_t *ii, /* i/o: coefficient indexes */
+ int16_t *idx /* o : index in unmapped domain */
+)
+{
+ *idx = *ii;
+ ( *ii )++;
+
+ return *idx;
+}
+
+/*-------------------------------------------------------------------*
+ * update_mixed_context()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int32_t update_mixed_context(
+ int32_t ctx,
+ int16_t a )
+{
+ int32_t t;
+
+ t = 1 - 13 + ( a & ~1 ) * ( ( a >> 2 ) + 1 );
+
+ if ( t > 0 )
+ {
+ t = min( ( a >> 3 ), 2 );
+ }
+
+ return ( ctx & 0xf ) * 16 + t + 13;
+}
diff --git a/lib_com/ari.c b/lib_com/ari.c
new file mode 100644
index 0000000000000000000000000000000000000000..2ee0be62310edc98d315593d6f269ca2529a6423
--- /dev/null
+++ b/lib_com/ari.c
@@ -0,0 +1,67 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "basop_util.h"
+#include "cnst.h"
+#include "wmc_auto.h"
+
+
+/*---------------------------------------------------------------
+ Ari 14 bits common routines
+ -------------------------------------------------------------*/
+
+/**
+ * \brief Integer Multiply
+ *
+ * \param[i] r
+ * \param[i] c
+ *
+ * \return r*c
+ */
+int32_t mul_sbc_14bits(
+ int32_t r,
+ int32_t c )
+{
+ int32_t temp;
+ /*function in line*/
+ temp = ( ( (int32_t) r ) * ( (int32_t) c ) ) >> stat_bitsnew;
+ return temp;
+
+ /*function in line*/
+}
diff --git a/lib_com/ari_hm.c b/lib_com/ari_hm.c
new file mode 100644
index 0000000000000000000000000000000000000000..3995913c43f7bfefb31276a0787aa0200b20ff6b
--- /dev/null
+++ b/lib_com/ari_hm.c
@@ -0,0 +1,305 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "cnst.h"
+#include "stl.h"
+#include "basop_util.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * UnmapIndex()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void UnmapIndex(
+ const int16_t PeriodicityIndex,
+ const int16_t Bandwidth,
+ const int16_t LtpPitchLag,
+ const int16_t SmallerLags,
+ int16_t *FractionalResolution,
+ int32_t *Lag )
+{
+ if ( ( LtpPitchLag > 0 ) && ( PeriodicityIndex & kLtpHmFlag ) )
+ {
+ int16_t LtpPitchIndex, Multiplier;
+ LtpPitchIndex = PeriodicityIndex >> 9;
+ Multiplier = PeriodicityIndex & 0xff;
+ assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 );
+ assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) );
+ *FractionalResolution = kLtpHmFractionalResolution;
+ *Lag = ( LtpPitchLag * (int32_t) ( 4 * Ratios[Bandwidth][LtpPitchIndex][Multiplier - 1] ) ) >> 2;
+ }
+ else
+ {
+ if ( PeriodicityIndex < 16 )
+ {
+ *FractionalResolution = 3;
+ *Lag = PeriodicityIndex + GET_ADJ( 0, 6 );
+ }
+ else if ( PeriodicityIndex < 80 )
+ {
+ *FractionalResolution = 4;
+ *Lag = PeriodicityIndex + GET_ADJ( 16, 8 );
+ }
+ else if ( PeriodicityIndex < 208 )
+ {
+ *FractionalResolution = 3;
+ *Lag = PeriodicityIndex + GET_ADJ( 80, 12 );
+ }
+ else if ( PeriodicityIndex < 224 || SmallerLags )
+ {
+ *FractionalResolution = 1;
+ *Lag = PeriodicityIndex + GET_ADJ( 208, 28 );
+ }
+ else
+ {
+ *FractionalResolution = 0;
+ *Lag = PeriodicityIndex + GET_ADJ( 224, 188 );
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ConfigureContextHm()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void ConfigureContextHm(
+ const int16_t NumCoeffs, /* (I) Number of coefficients */
+ const int16_t TargetBits, /* (I) Target bit budget (excl. Done flag) */
+ const int16_t PeriodicityIndex, /* (I) Pitch related index */
+ const int16_t LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */
+ CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */
+)
+{
+ int16_t Bandwidth, SmallerLags;
+ int32_t i, Lag;
+ int16_t j, FractionalResolution;
+ int32_t Limit;
+ int16_t Index;
+ int16_t *tmp;
+
+ Bandwidth = 0;
+ if ( NumCoeffs >= 256 )
+ {
+ Bandwidth = 1;
+ }
+
+ SmallerLags = 0;
+
+ if ( TargetBits <= kSmallerLagsTargetBitsThreshold || Bandwidth == 0 )
+ {
+ SmallerLags = 1;
+ }
+
+ UnmapIndex( PeriodicityIndex, Bandwidth, LtpPitchLag, SmallerLags, &FractionalResolution, &Lag );
+
+ /* Set up and fill peakIndices */
+ hm_cfg->peakIndices = hm_cfg->indexBuffer;
+ tmp = hm_cfg->peakIndices;
+ Limit = ( NumCoeffs - 1 ) << FractionalResolution;
+
+ for ( i = Lag; i < Limit; i += Lag )
+ {
+ Index = (int16_t) ( i >> FractionalResolution );
+ *tmp++ = Index - 1;
+ *tmp++ = Index;
+ *tmp++ = Index + 1;
+ }
+ hm_cfg->numPeakIndices = (int16_t) ( tmp - hm_cfg->indexBuffer );
+
+ /* Set up and fill holeIndices */
+ hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices;
+ tmp = hm_cfg->holeIndices;
+ Index = 0;
+
+ for ( j = 0; j < hm_cfg->numPeakIndices; j += 3 )
+ {
+ for ( ; Index < hm_cfg->peakIndices[j]; ++Index )
+ {
+ *tmp++ = Index;
+ }
+ Index += 3; /* Skip the peak */
+ }
+
+ for ( ; Index < NumCoeffs; ++Index )
+ {
+ *tmp++ = Index;
+ }
+ hm_cfg->numHoleIndices = (int16_t) ( tmp - hm_cfg->holeIndices );
+ /* Add extremal element signaling the end of the buffer */
+ *tmp++ = NumCoeffs;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * CountIndexBits()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t CountIndexBits(
+ const int16_t Bandwidth,
+ const int16_t PeriodicityIndex )
+{
+ if ( PeriodicityIndex & kLtpHmFlag )
+ {
+ int16_t LtpPitchIndex = PeriodicityIndex >> 9;
+ return NumRatioBits[Bandwidth][LtpPitchIndex];
+ }
+
+ return 8;
+}
+
+#define WMC_TOOL_SKIP
+
+/*-------------------------------------------------------------------*
+ * tcx_hm_render()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t tcx_hm_render(
+ const int16_t lag, /* i : pitch lag */
+ const int16_t fract_res, /* i : fractional resolution of the lag */
+ Word16 p[] /* o : harmonic model (Q13) */
+)
+{
+ int16_t k;
+ Word32 f0, tmp32;
+ Word16 height, PeakDeviation, tmp;
+
+ /* Set up overall shape */
+
+ f0 = L_shl( lag, sub( 15, fract_res ) ); /* Q15 */
+
+ tmp32 = Mpy_32_16( f0, -26474 );
+ tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 );
+ tmp32 = L_sub( 603979776L, tmp32 );
+ tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16( tmp32, 26214 ) );
+ height = round_fx( tmp32 ); /* Q13 */
+
+ tmp32 = Mpy_32_16( f0, -18910 );
+ tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 );
+ tmp32 = L_sub( 1395864371L, tmp32 );
+ PeakDeviation = round_fx( tmp32 ); /* Q14 */
+
+ IF( sub( 13915, PeakDeviation ) > 0 )
+ {
+ /* A bit error was encountered */
+ return 1;
+ }
+ ELSE
+ {
+ tmp = div_s( 13915, PeakDeviation );
+ tmp = mult_r( tmp, tmp ); /* Q15 */
+ }
+
+ /* Render the prototype peak */
+ p[kTcxHmParabolaHalfWidth] = height;
+
+ for ( k = 1; k <= kTcxHmParabolaHalfWidth; ++k )
+ {
+ p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16( BASOP_Util_InvLog2( L_shl( L_mult0( mult0( negate( k ), k ), tmp ), 10 ) ), height ) );
+ }
+ /* Mirror */
+ for ( k = -kTcxHmParabolaHalfWidth; k < 0; ++k )
+ {
+ p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k];
+ }
+
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tcx_hm_modify_envelope()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tcx_hm_modify_envelope(
+ const Word16 gain, /* i : HM gain (Q11) */
+ const int16_t lag,
+ const int16_t fract_res,
+ const Word16 p[], /* i : harmonic model (Q13) */
+ Word32 env[], /* i/o: envelope (Q16) */
+ const int16_t L_frame /* i : number of spectral lines */
+)
+{
+ int16_t k, h, x;
+ Word16 inv_shape[2 * kTcxHmParabolaHalfWidth + 1]; /* Q15 */
+
+ if ( gain == 0 )
+ {
+ return;
+ }
+
+ for ( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k )
+ {
+ inv_shape[k] = div_s( 512, add( 512, round_fx( L_mult( gain, p[k] ) ) ) );
+ }
+
+ h = 1;
+ k = lag >> fract_res;
+
+ while ( k <= L_frame + kTcxHmParabolaHalfWidth - 1 )
+ {
+
+ for ( x = max( 0, k - kTcxHmParabolaHalfWidth ); x <= min( k + kTcxHmParabolaHalfWidth, L_frame - 1 ); ++x )
+ {
+ env[x] = Mpy_32_16( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] );
+ }
+ ++h;
+ k = ( h * lag ) >> fract_res;
+ }
+
+ return;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/arith_coder.c b/lib_com/arith_coder.c
new file mode 100644
index 0000000000000000000000000000000000000000..f27617b27828a0f54d713a99eb326e85ae4863c3
--- /dev/null
+++ b/lib_com/arith_coder.c
@@ -0,0 +1,575 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "basop_util.h"
+#include "basop_proto_func.h"
+#include "wmc_auto.h"
+
+
+#define WMC_TOOL_SKIP
+
+/*-------------------------------------------------------*
+ * expfp()
+ *
+ * Fixed point implementation of exp()
+ *-------------------------------------------------------*/
+
+/*! r: Q15 */
+Word16 expfp(
+ const Word16 x, /* i : mantissa Q15-e */
+ const Word16 x_e /* i : exponent Q0 */
+)
+{
+ Word16 xi, xf, tmp;
+ Word16 b0, b1, b2, b3;
+ Word32 y, L_tmp;
+
+ assert( x <= 0 );
+
+ L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) );
+
+ /* split into integer and fractional parts */
+ xi = round_fx( L_tmp );
+ xf = extract_l( L_tmp );
+
+ BASOP_SATURATE_WARNING_OFF;
+ xf = negate( xf );
+ BASOP_SATURATE_WARNING_ON;
+
+ /* Fractional part */
+ /* y = 65536
+ + xf
+ + ((xf*xf) / (2*65536))
+ + ((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)
+ + ((((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)*xf) / (4*65536)); */
+ y = L_mac0( 65536, xf, 1 );
+ tmp = shr( mult( xf, xf ), 2 );
+ y = L_mac0( y, tmp, 1 );
+ tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 );
+ y = L_mac0( y, tmp, 1 );
+ tmp = shr( mult( tmp, xf ), 3 );
+ y = L_mac0( y, tmp, 1 );
+
+ /* Integer part */
+ b0 = s_and( xi, 1 );
+ b1 = s_and( xi, 2 );
+ b2 = s_and( xi, 4 );
+ b3 = s_and( xi, 8 );
+
+ if ( b0 != 0 )
+ y = Mpy_32_16( y, 24109 ); /* exp(-1) in -1Q16 */
+ if ( b1 != 0 )
+ y = Mpy_32_16( y, 17739 ); /* exp(-2) in -2Q17 */
+ if ( b2 != 0 )
+ y = Mpy_32_16( y, 19205 ); /* exp(-4) in -5Q20 */
+ if ( b3 != 0 )
+ y = Mpy_32_16( y, 22513 ); /* exp(-8) in -11Q26 */
+
+ /* scaling: -1*b0 - 2*b1 -5*b2 -11*b3 */
+ y = L_shr( y, add( add( xi, shr( xi, 2 ) ), shr( b3, 3 ) ) );
+
+ /* zero for xi >= 16 */
+ if ( shr( xi, 4 ) > 0 )
+ {
+ y = L_deposit_l( 0 );
+ move16();
+ }
+
+ return round_fx( L_shl( y, 15 ) );
+}
+
+
+/*-------------------------------------------------------*
+ * powfp_odd2()
+ *
+ * Fixed point implementation of pow(), where base is fixed point (16/16) and exponent a small *odd* integer
+ *-------------------------------------------------------*/
+/*
+ *
+ * Returns: *pout1 = ( (base/65536)^(2*exp - 1) ) * 65536
+ * *pout2 = ( (base/65536)^(2*exp + 1) ) * 65536
+ *
+ * NOTE: This function must be in sync with ari_decode_14bits_pow() */
+
+void powfp_odd2(
+ const Word16 base, /* Q15 */
+ const Word16 exp, /* Q0 */
+ Word16 *pout1, /* Q15 */
+ Word16 *pout2 /* Q15 */
+)
+{
+ /* this version is in sync with ari_enc_14bits_pow()
+ * that is, we have to start multiplication from the largest power-of-two, in order to
+ * get the rounding errors to appear at the same places */
+ Word16 pows[12]; /* powers of two exponents*/
+ Word16 exp2;
+ Word16 out, out2;
+ Word16 k, h, maxk;
+
+ assert( exp >= 0 );
+
+ out = base;
+ move16();
+ out2 = 0x7FFF;
+ move16();
+ IF( exp != 0 )
+ {
+ exp2 = sub( exp, 1 );
+ maxk = sub( 15, norm_s( exp ) );
+ assert( maxk < 12 );
+
+ pows[0] = base;
+ move16();
+ FOR( k = 0; k < maxk; k++ )
+ {
+ pows[k + 1] = mult_r( pows[k], pows[k] );
+ move16();
+ }
+ k = sub( k, 1 );
+ h = shl( 1, k ); /* highest bit of exp2 */
+ out2 = base;
+ move16();
+ out = mult_r( out, pows[k + 1] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */
+ /* .. the effective length of "exp" earlier on, thus we omit the branch for out2 */
+ if ( s_and( exp2, h ) != 0 )
+ {
+ out2 = mult_r( out2, pows[k + 1] );
+ }
+
+ h = shr( h, 1 );
+ FOR( k = sub( k, 1 ); k >= 0; k-- )
+ {
+ if ( s_and( exp, h ) != 0 )
+ {
+ out = mult_r( out, pows[k + 1] );
+ }
+
+ if ( s_and( exp2, h ) != 0 )
+ {
+ out2 = mult_r( out2, pows[k + 1] );
+ }
+
+ h = shr( h, 1 );
+ }
+ }
+
+ *pout1 = out2;
+ move16();
+ *pout2 = out;
+ move16();
+
+ return;
+}
+
+
+/*------------------------------------------------------------------------
+ * Function: tcx_arith_scale_envelope
+ *
+ * For optimal performance of the arithmetic coder, the envelope shape must
+ * be scaled such that the expected bit-consumption of a signal that
+ * follows the scaled shape coincides with the target bitrate.
+ * This function calculates a first-guess scaling and then uses the bi-section
+ * search to find the optimal scaling.
+ *
+ * We assume that lines follow the Laplacian distribution, whereby the expected
+ * bit-consumption would be log2(2*e*s[k]), where s[k] is the envelope value
+ * for the line in question. However, this theoretical formula assumes that
+ * all lines are encoded with magnitude+sign. Since the sign is unnecessary
+ * for 0-values, that estimate of bit-consumption is biased when s[k] is small.
+ * Analytical solution of the expectation for small s[k] is difficult, whereby
+ * we use the approximation log2(2*e*s[k] + 0.15 + 0.035 / s[k]) which is accurate
+ * on the range 0.08 to 1.0.
+ *
+ * NOTE: This function must be bit-exact on all platforms such that encoder
+ * and decoder remain synchronized.
+ *-------------------------------------------------------------------------*/
+
+void tcx_arith_scale_envelope(
+ const Word16 L_spec_core, /* i : number of lines to scale Q0 */
+ Word16 L_frame, /* i : number of lines Q0 */
+ const Word32 env[], /* i : unscaled envelope Q16 */
+ Word16 target_bits, /* i : number of available bits Q0 */
+ const Word16 low_complexity, /* i : low-complexity Q0 */
+ Word16 s_env[], /* o : scaled envelope Q15-e */
+ Word16 *s_env_e /* o : scaled envelope exponent Q0 */
+)
+{
+ Word32 ienv[N_MAX_ARI];
+ Word16 scale, iscale, iscale_e, a_e, b, b_e;
+ Word16 lob, hib, adjust;
+ Word16 k, iter, max_iter, lob_bits, hib_bits;
+ Word16 statesi, bits;
+ Word32 mean, a, s, L_tmp;
+ Word16 mean_e, tmp, tmp2;
+#ifdef BASOP_NOGLOB
+ Flag Overflow;
+#endif /* BASOP_NOGLOB */
+
+
+ lob_bits = 0;
+ move16();
+ hib_bits = 0;
+ move16();
+
+ /* Boosting to account for expected spectrum truncation (kMax) */
+ /* target_bits = (int16_t)(target_bits * (1.2f - 0.00045f * target_bits + 0.00000025f * target_bits * target_bits)); */
+ L_tmp = L_shr( Mpy_32_16( L_mult0( target_bits, target_bits ), 17180 ), 6 ); /* Q15; 17180 -> 0.00000025f (Q36) */
+ L_tmp = L_sub( L_tmp, L_shr( L_mult0( target_bits, 30199 ), 11 ) ); /* Q15; 30199 -> 0.00045f (Q26) */
+ L_tmp = L_add( L_tmp, 39322 ); /* Q15; 39322 -> 1.2f (Q15) */
+ L_tmp = Mpy_32_16( L_tmp, target_bits ); /* Q0 */
+ assert( L_tmp < 32768 );
+ target_bits = extract_l( L_tmp );
+
+ /* Calculate inverse envelope and find initial scale guess based on mean */
+ mean = L_deposit_l( 0 );
+ FOR( k = 0; k < L_frame; k++ )
+ {
+ /* ienv[k] = 1.0f / env[k];
+ mean += ienv[k]; */
+
+ tmp = norm_l( env[k] );
+ tmp2 = sub( 15, tmp );
+#ifndef BASOP_NOGLOB
+ tmp = Inv16( round_fx( L_shl( env[k], tmp ) ), &tmp2 );
+#else /* BASOP_NOGLOB */
+ tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 );
+#endif /* BASOP_NOGLOB */
+ ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */
+ move32();
+ mean = L_add( mean, ienv[k] );
+ }
+ tmp = norm_s( L_frame );
+ tmp2 = div_s( 8192, shl( L_frame, tmp ) );
+ tmp = shl( tmp2, sub( tmp, 7 ) );
+ mean = L_shr( Mpy_32_16( mean, tmp ), 6 ); /* Q16 */
+
+ /* Rate dependent compensation to get closer to the target on average */
+ /* mean = powf(mean, (float)L_frame / target_bits * 0.357f); */
+ tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 );
+ tmp = mult_r( tmp, FL2WORD16( 0.357f ) );
+ mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e );
+
+ /* Find first-guess scaling coefficient "scale" such that if "mean" is the
+ * mean of the envelope, then the mean bit-consumption is approximately
+ *
+ * log2(2*e*mean*scale + 0.15 + 0.035/(mean*scale)) * L_frame = target_bits
+ */
+ /* a = 2*2.71828183f*mean*mean; */
+ tmp = round_fx( mean );
+ a = L_mult( mult_r( tmp, FL2WORD16_SCALE( 2.71828183f, 2 ) ), tmp );
+ a_e = add( shl( mean_e, 1 ), 3 );
+
+ /* b = (0.15f - powf(2.0f, target_bits/(float)L_frame)) * mean; */
+ tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 );
+ tmp = round_fx( BASOP_util_Pow2( L_deposit_h( tmp ), tmp2, &tmp2 ) );
+ b_e = BASOP_Util_Add_MantExp( FL2WORD16( 0.15f ), 0, negate( tmp ), tmp2, &b );
+ b = mult_r( b, round_fx( mean ) );
+ b_e = add( b_e, mean_e );
+
+ /* scale = (-b + sqrtf(b*b - 4.0f*a*0.035f)) / (2.0f * a); */
+#ifndef BASOP_NOGLOB
+ tmp = round_fx( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ) );
+#else
+ tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ), &Overflow );
+#endif
+
+ IF( tmp <= 0 )
+ {
+ tmp = 0;
+
+ FOR( k = 0; k < L_frame; k++ )
+ {
+ s_env[k] = 0;
+ move16();
+ }
+ }
+ ELSE
+ {
+ tmp = Sqrt16( tmp, &tmp2 );
+ }
+
+ tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale );
+ scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp );
+#ifndef BASOP_NOGLOB
+ scale = shl( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ) ); /* Q15 */
+#else
+ scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */
+#endif
+
+ /* iscale = 1.0f / scale; */
+ iscale_e = 0;
+ move16();
+ iscale = Inv16( s_max( 1, scale ), &iscale_e );
+
+ lob = 0;
+ move16();
+ hib = 0;
+ move16();
+
+ max_iter = 2;
+ move16();
+ if ( low_complexity )
+ {
+ max_iter = 1;
+ move16();
+ }
+
+ FOR( iter = 0; iter < max_iter; iter++ )
+ {
+ statesi = 0x7FFF;
+ move16();
+ bits = 0;
+ move16();
+
+ FOR( k = 0; k < L_frame; k++ )
+ {
+ s = Mpy_32_16( ienv[k], scale ); /* Q16 */
+
+ IF( L_sub( s, FL2WORD32_SCALE( 0.08f, 15 ) ) <= 0 )
+ {
+ /* If s = 0.08, the expected bit-consumption is log2(1.0224). Below 0.08, the bit-consumption
+ estimate function becomes inaccurate, so use log2(1.0224) for all values below 0.08. */
+ /* round(state * 1.0224 * 32768) */
+ statesi = mult_r( statesi, FL2WORD16_SCALE( 1.0224, 1 ) );
+ tmp = norm_s( statesi );
+ statesi = shl( statesi, tmp );
+ bits = add( bits, sub( 1, tmp ) );
+ }
+ ELSE IF( L_sub( s, FL2WORD32_SCALE( 255.0, 15 ) ) <= 0 )
+ {
+ /* a = 5.436564f * s + 0.15f + 0.035f * env[k] * iscale; */
+ L_tmp = L_shl( Mpy_32_16( s, FL2WORD16_SCALE( 5.436564f, 3 ) ), 3 );
+ L_tmp = L_add( L_tmp, FL2WORD32_SCALE( 0.15f, 15 ) );
+ L_tmp = L_add( L_tmp, L_shl( Mpy_32_16( env[k], mult_r( FL2WORD16( 0.035f ), iscale ) ), iscale_e ) );
+
+ tmp = norm_l( L_tmp );
+#ifndef BASOP_NOGLOB
+ statesi = mult_r( statesi, round_fx( L_shl( L_tmp, tmp ) ) );
+#else /* BASOP_NOGLOB */
+ statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) );
+#endif /* BASOP_NOGLOB */
+ bits = add( bits, sub( 15, tmp ) );
+
+ tmp = norm_s( statesi );
+ statesi = shl( statesi, tmp );
+ bits = sub( bits, tmp );
+ }
+ ELSE
+ {
+ /* for large envelope values, s > 255, bit consumption is approx log2(2*e*s)
+ * further, we use round(log2(x)) = floor(log2(x)+0.5) = floor(log2(x*sqrt(2))) */
+ /* a = 5.436564f * s; */
+ L_tmp = Mpy_32_16( s, FL2WORD16_SCALE( 5.436564f * 1.4142f, 3 ) ); /* Q13 */
+ bits = add( bits, sub( 17, norm_l( L_tmp ) ) );
+ }
+ }
+
+ IF( sub( bits, target_bits ) <= 0 )
+ {
+ /* Bits leftover => scale is too small */
+ lob = scale;
+ move16();
+ lob_bits = bits;
+ move16();
+
+ IF( hib > 0 ) /* Bisection search */
+ {
+ adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) );
+ scale = add( mult_r( sub( lob, hib ), adjust ), hib );
+ }
+ ELSE
+ {
+ /* Initial scale adaptation */
+ /* adjust = 1.05f * target_bits / (float)bits;
+ scale *= adjust; */
+ adjust = mult_r( FL2WORD16_SCALE( 1.05f, 1 ), target_bits );
+ adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp );
+ scale = shl( mult_r( scale, adjust ), add( 1, tmp ) );
+ }
+ }
+ ELSE
+ {
+ /* Ran out of bits => scale is too large */
+ hib = scale;
+ move16();
+ hib_bits = bits;
+ move16();
+
+ IF( lob > 0 ) /* Bisection search */
+ {
+ adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) );
+ scale = add( mult_r( sub( lob, hib ), adjust ), hib );
+ }
+ ELSE
+ { /* Initial scale adaptation */
+ test();
+ IF( target_bits <= 0 || bits <= 0 ) /* safety check in case of bit errors */
+ {
+ adjust = 0;
+ move16();
+
+ FOR( k = 0; k < L_frame; k++ )
+ {
+ s_env[k] = 0;
+ move16();
+ }
+ }
+ ELSE
+ {
+ adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits );
+ }
+ scale = mult_r( scale, adjust );
+ }
+ }
+ iscale_e = 0;
+ move16();
+
+ IF( scale == 0 ) /* safety check in case of bit errors */
+ {
+ iscale = 0;
+ move16();
+
+ FOR( k = 0; k < L_frame; k++ )
+ {
+ s_env[k] = 0;
+ move16();
+ }
+ }
+ ELSE
+ {
+ iscale = Inv16( scale, &iscale_e );
+ }
+ }
+ L_frame = L_spec_core;
+ move16();
+
+ tmp = getScaleFactor32( env, L_frame );
+ *s_env_e = sub( add( 15, iscale_e ), tmp );
+ move16();
+ BASOP_SATURATE_WARNING_OFF;
+#ifndef BASOP_NOGLOB
+ a = L_shl( 1265000, sub( 15, *s_env_e ) );
+#else /* BASOP_NOGLOB */
+ a = L_shl_o( 1265000, sub( 15, *s_env_e ), &Overflow );
+#endif /* BASOP_NOGLOB */
+ BASOP_SATURATE_WARNING_ON;
+
+ FOR( k = 0; k < L_frame; k++ )
+ {
+ L_tmp = Mpy_32_16( L_shl( env[k], tmp ), iscale );
+ L_tmp = L_min( L_tmp, a );
+ s_env[k] = round_fx( L_tmp );
+ move16();
+ }
+
+ return;
+}
+
+
+/*------------------------------------------------------------------------
+ * Function: tcx_arith_render_envelope
+ *
+ * Calculate the envelope of the spectrum based on the LPC shape. The
+ * envelope is used in a perceptual domain, whereby the LPC shape has to
+ * be multiplied by the perceptual model.
+ * Operations that are performed on the spectrum, which change the magnitude
+ * expectation of lines, such as low-frequency emphasis, are included in the
+ * envelope shape.
+ * NOTE: This function must be bit-exact on all platforms such that encoder
+ * and decoder remain synchronized.
+ *-------------------------------------------------------------------------*/
+
+void tcx_arith_render_envelope(
+ const Word16 A_ind[], /* i : LPC coefficients of signal envelope */
+ const Word16 L_frame, /* i : number of spectral lines */
+ const Word16 L_spec, /* i : length of the coded spectrum */
+ const Word16 preemph_fac, /* i : pre-emphasis factor */
+ const Word16 gamma_w, /* i : A_ind -> weighted envelope factor */
+ const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor */
+ Word32 env[] /* o : shaped signal envelope */
+)
+{
+ Word16 k;
+ Word16 tmpA[M + 2];
+ Word16 signal_env[FDNS_NPTS], signal_env_e[FDNS_NPTS];
+ Word16 gainlpc[FDNS_NPTS], gainlpc_e[FDNS_NPTS];
+
+ /* Compute perceptual LPC envelope, transform it into freq.-domain gains */
+ basop_weight_a( A_ind, tmpA, gamma_w );
+ basop_lpc2mdct( tmpA, M, NULL, NULL, gainlpc, gainlpc_e );
+
+ /* Add pre-emphasis tilt to LPC envelope, transform LPC into MDCT gains */
+ basop_weight_a_inv( A_ind, signal_env, gamma_uw );
+ basop_E_LPC_a_add_tilt( signal_env, tmpA, preemph_fac );
+ basop_lpc2mdct( tmpA, M + 1, signal_env, signal_env_e, NULL, NULL );
+
+ /* Compute weighted signal envelope in perceptual domain */
+ FOR( k = 0; k < FDNS_NPTS; k++ )
+ {
+ signal_env[k] = mult_r( signal_env[k], gainlpc[k] );
+ move16();
+ signal_env_e[k] = add( signal_env_e[k], gainlpc_e[k] );
+ move16();
+ }
+
+ /* Adaptive low frequency emphasis */
+ FOR( k = 0; k < L_frame; k++ )
+ {
+ env[k] = 0x10000;
+ move32();
+ }
+
+ basop_PsychAdaptLowFreqDeemph( env, gainlpc, gainlpc_e, NULL );
+
+ /* Scale from FDNS_NPTS to L_frame and multiply LFE gains */
+ basop_mdct_noiseShaping_interp( env, L_frame, signal_env, signal_env_e );
+
+ FOR( k = L_frame; k < L_spec; ++k )
+ {
+ env[k] = env[k - 1];
+ move32();
+ }
+
+ return;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/basop32.c b/lib_com/basop32.c
new file mode 100644
index 0000000000000000000000000000000000000000..3e608e4a6506c626dca99b99daf1d223d7d057c7
--- /dev/null
+++ b/lib_com/basop32.c
@@ -0,0 +1,3153 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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.
+
+*******************************************************************************************************/
+
+/* v.2.3 - 30.Nov.2009
+ =============================================================================
+
+ U U GGG SSSS TTTTT
+ U U G S T
+ U U G GG SSSS T
+ U U G G S T
+ UUU GG SSS T
+
+ ========================================
+ ITU-T - USER'S GROUP ON SOFTWARE TOOLS
+ ========================================
+
+ =============================================================
+ COPYRIGHT NOTE: This source code, and all of its derivations,
+ is subject to the "ITU-T General Public License". Please have
+ it read in the distribution disk, or in the ITU-T
+ Recommendation G.191 on "SOFTWARE TOOLS FOR SPEECH AND AUDIO
+ CODING STANDARDS".
+ =============================================================
+
+MODULE: BASOP32, BASIC OPERATORS
+
+ORIGINAL BY:
+ Incorporated from anonymous contributions for
+ ETSI Standards as well as G.723.1, G.729, and G.722.1
+
+DESCRIPTION:
+ This file contains the definition of 16- and 32-bit basic
+ operators to be used in the implementation of signal
+ processing algorithms. The basic operators try to resemble
+ assembly language instructions that are commonly found in
+ digital signal processor (DSP) CPUs, thus allowing algorithm
+ C-code implementations more directly mapeable to DSP assembly
+ code.
+
+ *********************************************************
+ NOTE: so far, this module does not have a demo program!
+ *********************************************************
+
+FUNCTIONS:
+ Defined in basop32.h. Self-documentation within each function.
+
+HISTORY:
+ 26.Jan.00 v1.0 Incorporated to the STL from updated G.723.1/G.729
+ basic operator library (based on basicop2.c) and
+ G.723.1's basop.c [L_mls(), div_l(), i_mult()]
+
+ 05.Jul.00 v1.1 Added 32-bit shiftless accumulation basic
+ operators (L_msu0, L_mac0, L_mult0). Improved
+ documentation for i_mult().
+
+ 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control
+ operators for the ITU-T Standard Tool Library as
+ described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
+ TD 11 document and subsequent discussions on the
+ wp3audio@yahoogroups.com email reflector.
+ norm_s() weight reduced from 15 to 1.
+ norm_l() weight reduced from 30 to 1.
+ L_abs() weight reduced from 2 to 1.
+ L_add() weight reduced from 2 to 1.
+ L_negate() weight reduced from 2 to 1.
+ L_shl() weight reduced from 2 to 1.
+ L_shr() weight reduced from 2 to 1.
+ L_sub() weight reduced from 2 to 1.
+ mac_r() weight reduced from 2 to 1.
+ msu_r() weight reduced from 2 to 1.
+ mult_r() weight reduced from 2 to 1.
+ L_deposit_h() weight reduced from 2 to 1.
+ L_deposit_l() weight reduced from 2 to 1.
+ L_mls() weight of 5.
+ div_l() weight of 32.
+ i_mult() weight of 3.
+
+ 30 Nov 09 v2.3 round() function is now round_fx().
+ saturate() is not referencable from outside application
+ =============================================================================
+*/
+
+
+/*___________________________________________________________________________
+ | |
+ | Basic arithmetic operators. |
+ | |
+ | |
+ | |
+ | saturate() |
+ | add() |
+ | sub() |
+ | abs_s() |
+ | divide_s() |
+ | extract_h() |
+ | extract_l() |
+ | L_abs() |
+ | L_add() |
+ | L_deposit_h() |
+ | L_deposit_l() |
+ | L_mac() |
+ | L_msu() |
+ | L_mult() |
+ | L_negate() |
+ | L_shl() |
+ | L_shr() |
+ | L_sub() |
+ | mac_r() |
+ | msu_r() |
+ | mult() |
+ | mult_r() |
+ | negate() |
+ | norm_l() |
+ | norm_s() |
+ | round_fx() |
+ | shl() |
+ | shr() |
+ |___________________________________________________________________________|
+*/
+
+
+/*___________________________________________________________________________
+ | |
+ | Include-Files |
+ |___________________________________________________________________________|
+*/
+#ifndef _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+
+#include
+#include
+#include "stl.h"
+#ifdef BASOP_NOGLOB
+#include
+#endif /* BASOP_NOGLOB */
+
+#define WMC_TOOL_SKIP
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4310 )
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Local Functions |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+static Word16 saturate_o( Word32 L_var1, Flag *Overflow );
+#endif /* BASOP_NOGLOB */
+static Word16 saturate( Word32 L_var1 );
+
+
+/*___________________________________________________________________________
+ | |
+ | Constants and Globals |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Flag Overflow = 0;
+Flag Carry = 0;
+
+#else /* BASOP_NOGLOB */
+/*
+Flag BASOP_Overflow = 0;
+Flag BASOP_Carry = 0;
+*/
+#endif /* BASOP_NOGLOB */
+
+/*___________________________________________________________________________
+ | |
+ | Functions |
+ |___________________________________________________________________________|
+*/
+
+#define PRINT_STACK_ID_ALL "*"
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : saturate |
+ | |
+ | Purpose : |
+ | |
+ | Limit the 32 bit input to the range of a 16 bit word. Must NOT be |
+ | referenced from outside applications. |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+static Word16 saturate( Word32 L_var1 )
+#else /* BASOP_NOGLOB */
+static Word16 saturate_o( Word32 L_var1, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+ Word16 var_out;
+
+ if ( L_var1 > 0X00007fffL )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ var_out = MAX_16;
+ }
+ else if ( L_var1 < (Word32) 0xffff8000L )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ var_out = MIN_16;
+ }
+ else
+ {
+ var_out = extract_l( L_var1 );
+ }
+
+ BASOP_CHECK();
+
+ return ( var_out );
+}
+
+#ifdef BASOP_NOGLOB
+static Word16 saturate( Word32 L_var1 )
+{
+ Word16 var_out;
+
+ if ( L_var1 > 0X00007fffL )
+ {
+ assert( 0 );
+ var_out = MAX_16;
+ }
+ else if ( L_var1 < (Word32) 0xffff8000L )
+ {
+ assert( 0 );
+ var_out = MIN_16;
+ }
+ else
+ {
+ var_out = extract_l( L_var1 );
+ }
+
+ BASOP_CHECK();
+
+ return ( var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : add |
+ | |
+ | Purpose : |
+ | |
+ | Performs the addition (var1+var2) with overflow control and saturation;|
+ | the 16 bit result is set at +32767 when overflow occurs or at -32768 |
+ | when underflow occurs. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word16 add_o( Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word16 var_out;
+ Word32 L_sum;
+
+ L_sum = (Word32) var1 + var2;
+ var_out = saturate_o( L_sum, Overflow );
+
+
+ return ( var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word16 add( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+ Word32 L_sum;
+
+ L_sum = (Word32) var1 + var2;
+ var_out = saturate( L_sum );
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : sub |
+ | |
+ | Purpose : |
+ | |
+ | Performs the subtraction (var1+var2) with overflow control and satu- |
+ | ration; the 16 bit result is set at +32767 when overflow occurs or at |
+ | -32768 when underflow occurs. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word16 sub_o( Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word16 var_out;
+ Word32 L_diff;
+
+ L_diff = (Word32) var1 - var2;
+ var_out = saturate_o( L_diff, Overflow );
+
+ return ( var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word16 sub( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+ Word32 L_diff;
+
+ L_diff = (Word32) var1 - var2;
+ var_out = saturate( L_diff );
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : abs_s |
+ | |
+ | Purpose : |
+ | |
+ | Absolute value of var1; abs_s(-32768) = 32767. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+Word16 abs_s( Word16 var1 )
+{
+ Word16 var_out;
+
+ if ( var1 == (Word16) MIN_16 )
+ {
+ var_out = MAX_16;
+ }
+ else
+ {
+ if ( var1 < 0 )
+ {
+ var_out = -var1;
+ }
+ else
+ {
+ var_out = var1;
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : shl |
+ | |
+ | Purpose : |
+ | |
+ | Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
+ | the var2 LSB of the result. If var2 is negative, arithmetically shift |
+ | var1 right by -var2 with sign extension. Saturate the result in case of |
+ | underflows or overflows. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word16 shl( Word16 var1, Word16 var2 )
+#else /* BASOP_NOGLOB */
+Word16 shl_o( Word16 var1, Word16 var2, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+ Word16 var_out;
+ Word32 result;
+
+ if ( var2 < 0 )
+ {
+ if ( var2 < -16 )
+ var2 = -16;
+ var2 = -var2;
+ var_out = shr( var1, var2 );
+ }
+ else
+ {
+ result = (Word32) var1 * ( (Word32) 1 << var2 );
+
+ if ( ( var2 > 15 && var1 != 0 ) || ( result != (Word32) ( (Word16) result ) ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ var_out = ( var1 > 0 ) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ var_out = extract_l( result );
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+#ifdef BASOP_NOGLOB
+Word16 shl( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+ Word32 result;
+
+ if ( var2 < 0 )
+ {
+ if ( var2 < -16 )
+ var2 = -16;
+ var2 = -var2;
+ var_out = shr( var1, var2 );
+ }
+ else
+ {
+ result = (Word32) var1 * ( (Word32) 1 << var2 );
+
+ if ( ( var2 > 15 && var1 != 0 ) || ( result != (Word32) ( (Word16) result ) ) )
+ {
+ assert( 0 );
+ var_out = ( var1 > 0 ) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ var_out = extract_l( result );
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : shr |
+ | |
+ | Purpose : |
+ | |
+ | Arithmetically shift the 16 bit input var1 right var2 positions with |
+ | sign extension. If var2 is negative, arithmetically shift var1 left by |
+ | -var2 with sign extension. Saturate the result in case of underflows or |
+ | overflows. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+Word16 shr( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ if ( var2 < 0 )
+ {
+#ifdef BASOP_NOGLOB
+ assert( 0 );
+#endif /* BASOP_NOGLOB */
+ if ( var2 < -16 )
+ var2 = -16;
+ var2 = -var2;
+ var_out = shl( var1, var2 );
+ }
+ else
+ {
+ if ( var2 >= 15 )
+ {
+ var_out = ( var1 < 0 ) ? -1 : 0;
+ }
+ else
+ {
+ if ( var1 < 0 )
+ {
+ var_out = ~( ( ~var1 ) >> var2 );
+ }
+ else
+ {
+ var_out = var1 >> var2;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : mult |
+ | |
+ | Purpose : |
+ | |
+ | Performs the multiplication of var1 by var2 and gives a 16 bit result |
+ | which is scaled i.e.: |
+ | mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and |
+ | mult(-32768,-32768) = 32767. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word16 mult_o( Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word16 var_out;
+ Word32 L_product;
+
+ L_product = (Word32) var1 * (Word32) var2;
+
+ L_product = ( L_product & (Word32) 0xffff8000L ) >> 15;
+
+ if ( L_product & (Word32) 0x00010000L )
+ L_product = L_product | (Word32) 0xffff0000L;
+
+ var_out = saturate_o( L_product, Overflow );
+
+
+ return ( var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word16 mult( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+ Word32 L_product;
+
+ L_product = (Word32) var1 * (Word32) var2;
+
+ L_product = ( L_product & (Word32) 0xffff8000L ) >> 15;
+
+ if ( L_product & (Word32) 0x00010000L )
+ L_product = L_product | (Word32) 0xffff0000L;
+
+ var_out = saturate( L_product );
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_mult |
+ | |
+ | Purpose : |
+ | |
+ | L_mult is the 32 bit result of the multiplication of var1 times var2 |
+ | with one shift left i.e.: |
+ | L_mult(var1,var2) = L_shl((var1 times var2),1) and |
+ | L_mult(-32768,-32768) = 2147483647. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_mult( Word16 var1, Word16 var2 )
+#else /* BASOP_NOGLOB */
+Word32 L_mult_o( Word16 var1, Word16 var2, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1 * (Word32) var2;
+
+ if ( L_var_out != (Word32) 0x40000000L )
+ {
+ L_var_out *= 2;
+ }
+ else
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ L_var_out = MAX_32;
+ }
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+
+#ifdef BASOP_NOGLOB
+Word32 L_mult( Word16 var1, Word16 var2 )
+{
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1 * (Word32) var2;
+
+ if ( L_var_out != (Word32) 0x40000000L )
+ {
+ L_var_out *= 2;
+ }
+ else
+ {
+ assert( 0 );
+ L_var_out = MAX_32;
+ }
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : negate |
+ | |
+ | Purpose : |
+ | |
+ | Negate var1 with saturation, saturate in the case where input is -32768:|
+ | negate(var1) = sub(0,var1). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+Word16 negate( Word16 var1 )
+{
+ Word16 var_out;
+
+ var_out = ( var1 == MIN_16 ) ? MAX_16 : -var1;
+
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : extract_h |
+ | |
+ | Purpose : |
+ | |
+ | Return the 16 MSB of L_var1. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32 ) whose value falls in the |
+ | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+Word16 extract_h( Word32 L_var1 )
+{
+ Word16 var_out;
+
+ var_out = (Word16) ( L_var1 >> 16 );
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : extract_l |
+ | |
+ | Purpose : |
+ | |
+ | Return the 16 LSB of L_var1. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32 ) whose value falls in the |
+ | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+Word16 extract_l( Word32 L_var1 )
+{
+ Word16 var_out;
+
+ var_out = (Word16) L_var1;
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : round_fx |
+ | |
+ | Purpose : |
+ | |
+ | Round the lower 16 bits of the 32 bit input number into the MS 16 bits |
+ | with saturation. Shift the resulting bits right by 16 and return the 16 |
+ | bit number: |
+ | round_fx(L_var1) = extract_h(L_add(L_var1,32768)) |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32 ) whose value falls in the |
+ | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word16 round_fx_o( Word32 L_var1, Flag *Overflow )
+{
+ Word16 var_out;
+ Word32 L_rounded;
+
+ BASOP_SATURATE_WARNING_OFF
+ L_rounded = L_add_o( L_var1, (Word32) 0x00008000L, Overflow );
+ BASOP_SATURATE_WARNING_ON
+ var_out = extract_h( L_rounded );
+
+ BASOP_CHECK();
+
+ return ( var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word16 round_fx( Word32 L_var1 )
+{
+ Word16 var_out;
+ Word32 L_rounded;
+
+ BASOP_SATURATE_WARNING_OFF
+ L_rounded = L_add( L_var1, (Word32) 0x00008000L );
+ BASOP_SATURATE_WARNING_ON
+ var_out = extract_h( L_rounded );
+
+ BASOP_CHECK();
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_mac |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
+ | result to L_var3 with saturation, return a 32 bit result: |
+ | L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word32 L_mac_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult_o( var1, var2, Overflow );
+ L_var_out = L_add_o( L_var3, L_product, Overflow );
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word32 L_mac( Word32 L_var3, Word16 var1, Word16 var2 )
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult( var1, var2 );
+ L_var_out = L_add( L_var3, L_product );
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_msu |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
+ | bit result from L_var3 with saturation, return a 32 bit result: |
+ | L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word32 L_msu_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult_o( var1, var2, Overflow );
+ L_var_out = L_sub_o( L_var3, L_product, Overflow );
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word32 L_msu( Word32 L_var3, Word16 var1, Word16 var2 )
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult( var1, var2 );
+ L_var_out = L_sub( L_var3, L_product );
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_macNs |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
+ | result to L_var3 without saturation, return a 32 bit result. Generate |
+ | carry and overflow values : |
+ | L_macNs(L_var3,var1,var2) = L_add_c(L_var3,L_mult(var1,var2)). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ | |
+ | Caution : |
+ | |
+#ifndef BASOP_NOGLOB
+ | In some cases the Carry flag has to be cleared or set before using |
+#else
+ | In some cases the BASOP_Carry flag has to be cleared or set before using |
+#endif
+ | operators which take into account its value. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_macNs( Word32 L_var3, Word16 var1, Word16 var2 )
+#else /* BASOP_NOGLOB */
+Word32 DEPR_L_macNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+
+ L_var_out = L_mult( var1, var2 );
+#ifndef BASOP_NOGLOB
+ L_var_out = L_add_c( L_var3, L_var_out );
+#else /* BASOP_NOGLOB */
+ L_var_out = DEPR_L_add_c( L_var3, L_var_out, Carry );
+#endif /* BASOP_NOGLOB */
+
+ /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_msuNs |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
+ | bit result from L_var3 without saturation, return a 32 bit result. Ge- |
+ | nerate carry and overflow values : |
+ | L_msuNs(L_var3,var1,var2) = L_sub_c(L_var3,L_mult(var1,var2)). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ | |
+ | Caution : |
+ | |
+#ifndef BASOP_NOGLOB
+ | In some cases the Carry flag has to be cleared or set before using |
+#else
+ | In some cases the BASOP_Carry flag has to be cleared or set before using |
+#endif
+ | operators which take into account its value. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_msuNs( Word32 L_var3, Word16 var1, Word16 var2 )
+#else /* BASOP_NOGLOB */
+Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+
+ L_var_out = L_mult( var1, var2 );
+#ifndef BASOP_NOGLOB
+ L_var_out = L_sub_c( L_var3, L_var_out );
+#else /* BASOP_NOGLOB */
+ L_var_out = DEPR_L_sub_c( L_var3, L_var_out, Carry );
+#endif /* BASOP_NOGLOB */
+
+ /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_add |
+ | |
+ | Purpose : |
+ | |
+ | 32 bits addition of the two 32 bits variables (L_var1+L_var2) with |
+ | overflow control and saturation; the result is set at +2147483647 when |
+ | overflow occurs or at -2147483648 when underflow occurs. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | L_var2 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_add( Word32 L_var1, Word32 L_var2 )
+#else /* BASOP_NOGLOB */
+Word32 L_add_o( Word32 L_var1, Word32 L_var2, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1 + L_var2;
+
+ if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) == 0 )
+ {
+ if ( ( L_var_out ^ L_var1 ) & MIN_32 )
+ {
+ L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32;
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+#ifdef BASOP_NOGLOB
+Word32 L_add( Word32 L_var1, Word32 L_var2 )
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1 + L_var2;
+
+ if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) == 0 )
+ {
+ if ( ( L_var_out ^ L_var1 ) & MIN_32 )
+ {
+ L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32;
+ assert( 0 );
+ }
+ }
+
+ return ( L_var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_sub |
+ | |
+ | Purpose : |
+ | |
+ | 32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with |
+ | overflow control and saturation; the result is set at +2147483647 when |
+ | overflow occurs or at -2147483648 when underflow occurs. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | L_var2 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_sub( Word32 L_var1, Word32 L_var2 )
+#else /* BASOP_NOGLOB */
+Word32 L_sub_o( Word32 L_var1, Word32 L_var2, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1 - L_var2;
+
+ if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) != 0 )
+ {
+ if ( ( L_var_out ^ L_var1 ) & MIN_32 )
+ {
+ L_var_out = ( L_var1 < 0L ) ? MIN_32 : MAX_32;
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ }
+ }
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+
+#ifdef BASOP_NOGLOB
+Word32 L_sub( Word32 L_var1, Word32 L_var2 )
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1 - L_var2;
+
+ if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) != 0 )
+ {
+ if ( ( L_var_out ^ L_var1 ) & MIN_32 )
+ {
+ L_var_out = ( L_var1 < 0L ) ? MIN_32 : MAX_32;
+ assert( 0 );
+ }
+ }
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_add_c |
+ | |
+ | Purpose : |
+ | |
+ | Performs 32 bits addition of the two 32 bits variables (L_var1+L_var2+C)|
+#ifndef BASOP_NOGLOB
+ | with carry. No saturation. Generate carry and Overflow values. The car- |
+#else
+ | with carry. No saturation. Generate carry and BASOP_Overflow values. The car- |
+#endif
+ | ry and overflow values are binary variables which can be tested and as- |
+ | signed values. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | L_var2 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ | |
+ | Caution : |
+ | |
+#ifndef BASOP_NOGLOB
+ | In some cases the Carry flag has to be cleared or set before using |
+#else
+ | In some cases the BASOP_Carry flag has to be cleared or set before using |
+#endif
+ | operators which take into account its value. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_add_c( Word32 L_var1, Word32 L_var2 )
+#else /* BASOP_NOGLOB */
+Word32 DEPR_L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+ Word32 L_test;
+ Flag carry_int = 0;
+
+#ifndef BASOP_NOGLOB
+ L_var_out = L_var1 + L_var2 + Carry;
+#else /* BASOP_NOGLOB */
+ L_var_out = L_var1 + L_var2 + *Carry;
+#endif /* BASOP_NOGLOB */
+
+ L_test = L_var1 + L_var2;
+
+ if ( ( L_var1 > 0 ) && ( L_var2 > 0 ) && ( L_test < 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#endif /* ! BASOP_NOGLOB */
+ carry_int = 0;
+ }
+ else
+ {
+ if ( ( L_var1 < 0 ) && ( L_var2 < 0 ) )
+ {
+ if ( L_test >= 0 )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#endif /* ! BASOP_NOGLOB */
+ carry_int = 1;
+ }
+ else
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 0;
+#endif /* ! BASOP_NOGLOB */
+ carry_int = 1;
+ }
+ }
+ else
+ {
+ if ( ( ( L_var1 ^ L_var2 ) < 0 ) && ( L_test >= 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 0;
+#endif /* ! BASOP_NOGLOB */
+ carry_int = 1;
+ }
+ else
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 0;
+#endif /* ! BASOP_NOGLOB */
+ carry_int = 0;
+ }
+ }
+ }
+
+#ifndef BASOP_NOGLOB
+ if ( Carry )
+#else /* BASOP_NOGLOB */
+ if ( *Carry )
+#endif /* BASOP_NOGLOB */
+ {
+ if ( L_test == MAX_32 )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ Carry = carry_int;
+#else /* BASOP_NOGLOB */
+ *Carry = carry_int;
+#endif /* BASOP_NOGLOB */
+ }
+ else
+ {
+ if ( L_test == (Word32) 0xFFFFFFFFL )
+ {
+#ifndef BASOP_NOGLOB
+ Carry = 1;
+#else /* BASOP_NOGLOB */
+ *Carry = 1;
+#endif /* BASOP_NOGLOB */
+ }
+ else
+ {
+#ifndef BASOP_NOGLOB
+ Carry = carry_int;
+#else /* BASOP_NOGLOB */
+ *Carry = carry_int;
+#endif /* BASOP_NOGLOB */
+ }
+ }
+ }
+ else
+ {
+#ifndef BASOP_NOGLOB
+ Carry = carry_int;
+#else /* BASOP_NOGLOB */
+ *Carry = carry_int;
+#endif /* BASOP_NOGLOB */
+ }
+
+ /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_sub_c |
+ | |
+ | Purpose : |
+ | |
+ | Performs 32 bits subtraction of the two 32 bits variables with carry |
+#ifndef BASOP_NOGLOB
+ | (borrow) : L_var1-L_var2-C. No saturation. Generate carry and Overflow |
+#else
+ | (borrow) : L_var1-L_var2-C. No saturation. Generate carry and BASOP_Overflow |
+#endif
+ | values. The carry and overflow values are binary variables which can |
+ | be tested and assigned values. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | L_var2 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ | |
+ | Caution : |
+ | |
+#ifndef BASOP_NOGLOB
+ | In some cases the Carry flag has to be cleared or set before using |
+#else
+ | In some cases the BASOP_Carry flag has to be cleared or set before using |
+#endif
+ | operators which take into account its value. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_sub_c( Word32 L_var1, Word32 L_var2 )
+#else /* BASOP_NOGLOB */
+Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+ Word32 L_test;
+ Flag carry_int = 0;
+
+#ifndef BASOP_NOGLOB
+ if ( Carry )
+#else /* BASOP_NOGLOB */
+ if ( *Carry )
+#endif /* BASOP_NOGLOB */
+ {
+#ifndef BASOP_NOGLOB
+ Carry = 0;
+#else /* BASOP_NOGLOB */
+ *Carry = 0;
+#endif /* BASOP_NOGLOB */
+ if ( L_var2 != MIN_32 )
+ {
+#ifndef BASOP_NOGLOB
+ L_var_out = L_add_c( L_var1, -L_var2 );
+#else /* BASOP_NOGLOB */
+ L_var_out = DEPR_L_add_c( L_var1, -L_var2, Carry );
+#endif /* BASOP_NOGLOB */
+ }
+ else
+ {
+ L_var_out = L_var1 - L_var2;
+ if ( L_var1 > 0L )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ Carry = 0;
+#else /* BASOP_NOGLOB */
+ *Carry = 0;
+#endif /* BASOP_NOGLOB */
+ }
+ }
+ }
+ else
+ {
+ L_var_out = L_var1 - L_var2 - (Word32) 0X00000001L;
+ L_test = L_var1 - L_var2;
+
+ if ( ( L_test < 0 ) && ( L_var1 > 0 ) && ( L_var2 < 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#endif /* ! BASOP_NOGLOB */
+ carry_int = 0;
+ }
+ else if ( ( L_test > 0 ) && ( L_var1 < 0 ) && ( L_var2 > 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#endif /* ! BASOP_NOGLOB */
+ carry_int = 1;
+ }
+ else if ( ( L_test > 0 ) && ( ( L_var1 ^ L_var2 ) > 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 0;
+#endif /* ! BASOP_NOGLOB */
+ carry_int = 1;
+ }
+ if ( L_test == MIN_32 )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ Carry = carry_int;
+#else /* BASOP_NOGLOB */
+ *Carry = carry_int;
+#endif /* BASOP_NOGLOB */
+ }
+ else
+ {
+#ifndef BASOP_NOGLOB
+ Carry = carry_int;
+#else /* BASOP_NOGLOB */
+ *Carry = carry_int;
+#endif /* BASOP_NOGLOB */
+ }
+ }
+
+ /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_negate |
+ | |
+ | Purpose : |
+ | |
+ | Negate the 32 bit variable L_var1 with saturation; saturate in the case |
+ | where input is -2147483648 (0x8000 0000). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+Word32 L_negate( Word32 L_var1 )
+{
+ Word32 L_var_out;
+
+ L_var_out = ( L_var1 == MIN_32 ) ? MAX_32 : -L_var1;
+
+ BASOP_CHECK();
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : mult_r |
+ | |
+ | Purpose : |
+ | |
+ | Same as mult with rounding, i.e.: |
+ | mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and |
+ | mult_r(-32768,-32768) = 32767. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x8000 <= var_out <= 0x7fff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word16 mult_ro( Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word16 var_out;
+ Word32 L_product_arr;
+
+ L_product_arr = (Word32) var1 * (Word32) var2; /* product */
+ L_product_arr += (Word32) 0x00004000L; /* round */
+ L_product_arr &= (Word32) 0xffff8000L;
+ L_product_arr >>= 15; /* shift */
+
+ if ( L_product_arr & (Word32) 0x00010000L ) /* sign extend when necessary */
+ {
+ L_product_arr |= (Word32) 0xffff0000L;
+ }
+ var_out = saturate_o( L_product_arr, Overflow );
+
+
+ return ( var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word16 mult_r( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+ Word32 L_product_arr;
+
+ L_product_arr = (Word32) var1 * (Word32) var2; /* product */
+ L_product_arr += (Word32) 0x00004000L; /* round */
+ L_product_arr &= (Word32) 0xffff8000L;
+ L_product_arr >>= 15; /* shift */
+
+ if ( L_product_arr & (Word32) 0x00010000L ) /* sign extend when necessary */
+ {
+ L_product_arr |= (Word32) 0xffff0000L;
+ }
+ var_out = saturate( L_product_arr );
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_shl |
+ | |
+ | Purpose : |
+ | |
+ | Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero |
+ | fill the var2 LSB of the result. If var2 is negative, arithmetically |
+ | shift L_var1 right by -var2 with sign extension. Saturate the result in |
+ | case of underflows or overflows. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_shl( Word32 L_var1, Word16 var2 )
+#else /* BASOP_NOGLOB */
+Word32 L_shl_o( Word32 L_var1, Word16 var2, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+
+ Word32 L_var_out = 0L;
+
+ if ( var2 <= 0 )
+ {
+ if ( var2 < -32 )
+ var2 = -32;
+ var2 = -var2;
+ L_var_out = L_shr( L_var1, var2 );
+ }
+ else
+ {
+ for ( ; var2 > 0; var2-- )
+ {
+ if ( L_var1 > (Word32) 0X3fffffffL )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ L_var_out = MAX_32;
+ break;
+ }
+ else
+ {
+ if ( L_var1 < (Word32) 0xc0000000L )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ L_var_out = MIN_32;
+ break;
+ }
+ }
+ L_var1 *= 2;
+ L_var_out = L_var1;
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+#ifdef BASOP_NOGLOB
+Word32 L_shl( Word32 L_var1, Word16 var2 )
+{
+
+ Word32 L_var_out = 0L;
+
+ if ( var2 <= 0 )
+ {
+ if ( var2 < -32 )
+ var2 = -32;
+ var2 = -var2;
+ L_var_out = L_shr( L_var1, var2 );
+ }
+ else
+ {
+ for ( ; var2 > 0; var2-- )
+ {
+ if ( L_var1 > (Word32) 0X3fffffffL )
+ {
+ assert( 0 );
+ L_var_out = MAX_32;
+ break;
+ }
+ else
+ {
+ if ( L_var1 < (Word32) 0xc0000000L )
+ {
+ assert( 0 );
+ L_var_out = MIN_32;
+ break;
+ }
+ }
+ L_var1 *= 2;
+ L_var_out = L_var1;
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_shr |
+ | |
+ | Purpose : |
+ | |
+ | Arithmetically shift the 32 bit input L_var1 right var2 positions with |
+ | sign extension. If var2 is negative, arithmetically shift L_var1 left |
+ | by -var2 and zero fill the -var2 LSB of the result. Saturate the result |
+ | in case of underflows or overflows. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word32 L_shr_o( Word32 L_var1, Word16 var2, Flag *Overflow )
+{
+ Word32 L_var_out;
+
+ if ( var2 < 0 )
+ {
+ if ( var2 < -32 )
+ var2 = -32;
+ var2 = -var2;
+ L_var_out = L_shl_o( L_var1, var2, Overflow );
+ }
+ else
+ {
+ if ( var2 >= 31 )
+ {
+ L_var_out = ( L_var1 < 0L ) ? -1 : 0;
+ }
+ else
+ {
+ if ( L_var1 < 0 )
+ {
+ L_var_out = ~( ( ~L_var1 ) >> var2 );
+ }
+ else
+ {
+ L_var_out = L_var1 >> var2;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word32 L_shr( Word32 L_var1, Word16 var2 )
+{
+ Word32 L_var_out;
+
+ if ( var2 < 0 )
+ {
+ if ( var2 < -32 )
+ var2 = -32;
+ var2 = -var2;
+ L_var_out = L_shl( L_var1, var2 );
+ }
+ else
+ {
+ if ( var2 >= 31 )
+ {
+ L_var_out = ( L_var1 < 0L ) ? -1 : 0;
+ }
+ else
+ {
+ if ( L_var1 < 0 )
+ {
+ L_var_out = ~( ( ~L_var1 ) >> var2 );
+ }
+ else
+ {
+ L_var_out = L_var1 >> var2;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : shr_r |
+ | |
+ | Purpose : |
+ | |
+ | Same as shr(var1,var2) but with rounding. Saturate the result in case of|
+ | underflows or overflows : |
+ | - If var2 is greater than zero : |
+ | if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1)))) |
+ | is equal to zero |
+ | then |
+ | shr_r(var1,var2) = shr(var1,var2) |
+ | else |
+ | shr_r(var1,var2) = add(shr(var1,var2),1) |
+ | - If var2 is less than or equal to zero : |
+ | shr_r(var1,var2) = shr(var1,var2). |
+ | |
+ | Complexity weight : 3 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+Word16 shr_r( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ if ( var2 > 15 )
+ {
+ var_out = 0;
+ }
+ else
+ {
+ var_out = shr( var1, var2 );
+
+ if ( var2 > 0 )
+ {
+ if ( ( var1 & ( (Word16) 1 << ( var2 - 1 ) ) ) != 0 )
+ {
+ var_out++;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : mac_r |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
+ | result to L_var3 with saturation. Round the LS 16 bits of the result |
+ | into the MS 16 bits with saturation and shift the result right by 16. |
+ | Return a 16 bit result. |
+ | mac_r(L_var3,var1,var2) = round_fx(L_mac(L_var3,var1,var2)) |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 8000 <= L_var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word16 mac_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word16 var_out;
+
+ L_var3 = L_mac_o( L_var3, var1, var2, Overflow );
+ L_var3 = L_add_o( L_var3, (Word32) 0x00008000L, Overflow );
+ var_out = extract_h( L_var3 );
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word16 mac_r( Word32 L_var3, Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ L_var3 = L_mac( L_var3, var1, var2 );
+ L_var3 = L_add( L_var3, (Word32) 0x00008000L );
+ var_out = extract_h( L_var3 );
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : msu_r |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
+ | bit result from L_var3 with saturation. Round the LS 16 bits of the res-|
+ | ult into the MS 16 bits with saturation and shift the result right by |
+ | 16. Return a 16 bit result. |
+ | msu_r(L_var3,var1,var2) = round_fx(L_msu(L_var3,var1,var2)) |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 8000 <= L_var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word16 msu_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word16 var_out;
+
+ L_var3 = L_msu_o( L_var3, var1, var2, Overflow );
+ L_var3 = L_add_o( L_var3, (Word32) 0x00008000L, Overflow );
+ var_out = extract_h( L_var3 );
+
+ BASOP_CHECK();
+
+ return ( var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word16 msu_r( Word32 L_var3, Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ L_var3 = L_msu( L_var3, var1, var2 );
+ L_var3 = L_add( L_var3, (Word32) 0x00008000L );
+ var_out = extract_h( L_var3 );
+
+ BASOP_CHECK();
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_deposit_h |
+ | |
+ | Purpose : |
+ | |
+ | Deposit the 16 bit var1 into the 16 MS bits of the 32 bit output. The |
+ | 16 LS bits of the output are zeroed. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var_out <= 0x7fff 0000. |
+ |___________________________________________________________________________|
+*/
+Word32 L_deposit_h( Word16 var1 )
+{
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1 << 16;
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_deposit_l |
+ | |
+ | Purpose : |
+ | |
+ | Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The |
+ | 16 MS bits of the output are sign extended. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0xFFFF 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+Word32 L_deposit_l( Word16 var1 )
+{
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1;
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_shr_r |
+ | |
+ | Purpose : |
+ | |
+ | Same as L_shr(L_var1,var2) but with rounding. Saturate the result in |
+ | case of underflows or overflows : |
+ | - If var2 is greater than zero : |
+ | if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))|
+ | is equal to zero |
+ | then |
+ | L_shr_r(L_var1,var2) = L_shr(L_var1,var2) |
+ | else |
+ | L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1) |
+ | - If var2 is less than or equal to zero : |
+ | L_shr_r(L_var1,var2) = L_shr(L_var1,var2). |
+ | |
+ | Complexity weight : 3 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+Word32 L_shr_r( Word32 L_var1, Word16 var2 )
+{
+ Word32 L_var_out;
+
+ if ( var2 > 31 )
+ {
+ L_var_out = 0;
+ }
+ else
+ {
+ L_var_out = L_shr( L_var1, var2 );
+
+ if ( var2 > 0 )
+ {
+ if ( ( L_var1 & ( (Word32) 1 << ( var2 - 1 ) ) ) != 0 )
+ {
+ L_var_out++;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_abs |
+ | |
+ | Purpose : |
+ | |
+ | Absolute value of L_var1; Saturate in case where the input is |
+ | -214783648 |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+Word32 L_abs( Word32 L_var1 )
+{
+ Word32 L_var_out;
+
+ if ( L_var1 == MIN_32 )
+ {
+ L_var_out = MAX_32;
+ }
+ else
+ {
+ if ( L_var1 < 0 )
+ {
+ L_var_out = -L_var1;
+ }
+ else
+ {
+ L_var_out = L_var1;
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_sat |
+ | |
+ | Purpose : |
+ | |
+ | 32 bit L_var1 is set to 2147483647 if an overflow occured or to |
+ | -2147483648 if an underflow occured on the most recent L_add_c, |
+ | L_sub_c, L_macNs or L_msuNs operations. The carry and overflow values |
+ | are binary values which can be tested and assigned values. |
+ | |
+ | Complexity weight : 4 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word32 L_sat( Word32 L_var1 )
+#else /* BASOP_NOGLOB */
+Word32 DEPR_L_sat_co( Word32 L_var1, Flag Overflow, Flag Carry )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1;
+
+ if ( Overflow )
+ {
+
+ if ( Carry )
+ {
+ L_var_out = MIN_32;
+ }
+ else
+ {
+ L_var_out = MAX_32;
+ }
+#ifndef BASOP_NOGLOB
+
+ Carry = 0;
+ Overflow = 0;
+#endif /* ! BASOP_NOGLOB */
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : norm_s |
+ | |
+ | Purpose : |
+ | |
+ | Produces the number of left shift needed to normalize the 16 bit varia- |
+ | ble var1 for positive values on the interval with minimum of 16384 and |
+ | maximum of 32767, and for negative values on the interval with minimum |
+ | of -32768 and maximum of -16384; in order to normalize the result, the |
+ | following operation must be done : |
+ | norm_var1 = shl(var1,norm_s(var1)). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x0000 000f. |
+ |___________________________________________________________________________|
+*/
+Word16 norm_s( Word16 var1 )
+{
+ Word16 var_out;
+
+ if ( var1 == 0 )
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if ( var1 == (Word16) 0xffff )
+ {
+ var_out = 15;
+ }
+ else
+ {
+ if ( var1 < 0 )
+ {
+ var1 = ~var1;
+ }
+ for ( var_out = 0; var1 < 0x4000; var_out++ )
+ {
+ var1 <<= 1;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : div_s |
+ | |
+ | Purpose : |
+ | |
+ | Produces a result which is the fractional integer division of var1 by |
+ | var2; var1 and var2 must be positive and var2 must be greater or equal |
+ | to var1; the result is positive (leading bit equal to 0) and truncated |
+ | to 16 bits. |
+ | If var1 = var2 then div(var1,var2) = 32767. |
+ | |
+ | Complexity weight : 18 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var1 <= var2 and var2 != 0. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : var1 <= var2 <= 0x0000 7fff and var2 != 0. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
+ | It's a Q15 value (point between b15 and b14). |
+ |___________________________________________________________________________|
+*/
+Word16 div_s( Word16 var1, Word16 var2 )
+{
+ Word16 var_out = 0;
+ Word16 iteration;
+ Word32 L_num;
+ Word32 L_denom;
+
+ if ( ( var1 > var2 ) || ( var1 < 0 ) || ( var2 < 0 ) )
+ {
+ /* printf ("Division Error var1=%d var2=%d in ", var1, var2); printStack(); */
+ char text[60];
+ sprintf( text, "Division Error var1=%d var2=%d in ", var1, var2 );
+ abort(); /* exit (0); */
+ }
+ if ( var2 == 0 )
+ {
+ /* printf ("Division by 0, Fatal error in "); printStack(); */
+ abort(); /* exit (0); */
+ }
+ if ( var1 == 0 )
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if ( var1 == var2 )
+ {
+ var_out = MAX_16;
+ }
+ else
+ {
+ L_num = L_deposit_l( var1 );
+ L_denom = L_deposit_l( var2 );
+
+ for ( iteration = 0; iteration < 15; iteration++ )
+ {
+ var_out <<= 1;
+ L_num <<= 1;
+
+ if ( L_num >= L_denom )
+ {
+ L_num = L_sub( L_num, L_denom );
+ var_out = add( var_out, 1 );
+ }
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : norm_l |
+ | |
+ | Purpose : |
+ | |
+ | Produces the number of left shifts needed to normalize the 32 bit varia-|
+ | ble L_var1 for positive values on the interval with minimum of |
+ | 1073741824 and maximum of 2147483647, and for negative values on the in-|
+ | terval with minimum of -2147483648 and maximum of -1073741824; in order |
+ | to normalize the result, the following operation must be done : |
+ | norm_L_var1 = L_shl(L_var1,norm_l(L_var1)). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x0000 001f. |
+ |___________________________________________________________________________|
+*/
+Word16 norm_l( Word32 L_var1 )
+{
+ Word16 var_out;
+
+ if ( L_var1 == 0 )
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if ( L_var1 == (Word32) 0xffffffffL )
+ {
+ var_out = 31;
+ }
+ else
+ {
+ if ( L_var1 < 0 )
+ {
+ L_var1 = ~L_var1;
+ }
+ for ( var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++ )
+ {
+ L_var1 <<= 1;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+/*
+ ******************************************************************************
+ * Additional operators extracted from the G.723.1 Library
+ * Adapted for WMOPS calculations
+ ******************************************************************************
+ */
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_mls |
+ | |
+ | Purpose : |
+ | |
+ | Multiplies a 16 bit word v by a 32 bit word Lv and returns a 32 bit |
+ | word (multiplying 16 by 32 bit words gives 48 bit word; the function |
+ | extracts the 32 MSB and shift the result to the left by 1). |
+ | |
+ | A 32 bit word can be written as |
+ | Lv = a + b * 2^16 |
+ | where a= unsigned 16 LSBs and b= signed 16 MSBs. |
+ | The function returns v * Lv / 2^15 which is equivalent to |
+ | a*v / 2^15 + b*v*2 |
+ | |
+ | Complexity weight : 5 |
+ | |
+ | Inputs : |
+ | |
+ | Lv |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+ | v |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x8000 <= var1 <= 0x7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var_out <= 0x7fff ffff. |
+ | |
+ |___________________________________________________________________________|
+*/
+#ifdef BASOP_NOGLOB
+Word32 L_mls_o( Word32 Lv, Word16 v, Flag *Overflow )
+{
+ Word32 Temp;
+
+ Temp = Lv & (Word32) 0x0000ffff;
+ Temp = Temp * (Word32) v;
+ Temp = L_shr( Temp, (Word16) 15 );
+ Temp = L_mac_o( Temp, v, extract_h( Lv ), Overflow );
+
+ BASOP_CHECK();
+
+ return Temp;
+}
+
+#endif /* BASOP_NOGLOB */
+Word32 L_mls( Word32 Lv, Word16 v )
+{
+ Word32 Temp;
+
+ Temp = Lv & (Word32) 0x0000ffff;
+ Temp = Temp * (Word32) v;
+ Temp = L_shr( Temp, (Word16) 15 );
+ Temp = L_mac( Temp, v, extract_h( Lv ) );
+
+ BASOP_CHECK();
+
+ return Temp;
+}
+
+
+/*__________________________________________________________________________
+| |
+| Function Name : div_l |
+| |
+| Purpose : |
+| |
+| Produces a result which is the fractional integer division of L_var1 by |
+| var2; L_var1 and var2 must be positive and var2 << 16 must be greater or|
+| equal to L_var1; the result is positive (leading bit equal to 0) and |
+| truncated to 16 bits. |
+| If L_var1 == var2 << 16 then div_l(L_var1,var2) = 32767. |
+| |
+| Complexity weight : 32 |
+| |
+| Inputs : |
+| |
+| L_var1 |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x0000 0000 <= var1 <= (var2 << 16) and var2 != 0. |
+| L_var1 must be considered as a Q.31 value |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : var1 <= (var2<< 16) <= 0x7fff0000 and var2 != 0. |
+| var2 must be considered as a Q.15 value |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
+| It's a Q15 value (point between b15 and b14). |
+|___________________________________________________________________________|
+*/
+Word16 div_l( Word32 L_num, Word16 den )
+{
+ Word16 var_out = (Word16) 0;
+ Word32 L_den;
+ Word16 iteration;
+
+
+ if ( den == (Word16) 0 )
+ {
+ /* printf("Division by 0 in div_l, Fatal error in "); printStack(); */
+ exit( -1 );
+ }
+
+ if ( ( L_num < (Word32) 0 ) || ( den < (Word16) 0 ) )
+ {
+ /* printf("Division Error in div_l, Fatal error in "); printStack(); */
+ exit( -1 );
+ }
+
+ L_den = L_deposit_h( den );
+
+ if ( L_num >= L_den )
+ {
+
+
+ BASOP_CHECK();
+ return MAX_16;
+ }
+ else
+ {
+ L_num = L_shr( L_num, (Word16) 1 );
+ L_den = L_shr( L_den, (Word16) 1 );
+ for ( iteration = (Word16) 0; iteration < (Word16) 15; iteration++ )
+ {
+ var_out = shl( var_out, (Word16) 1 );
+ L_num = L_shl( L_num, (Word16) 1 );
+ if ( L_num >= L_den )
+ {
+ L_num = L_sub( L_num, L_den );
+ var_out = add( var_out, (Word16) 1 );
+ }
+ }
+
+
+ BASOP_CHECK();
+
+ return var_out;
+ }
+}
+
+
+/*__________________________________________________________________________
+| |
+| Function Name : i_mult |
+| |
+| Purpose : |
+| |
+| Integer 16-bit multiplication with overflow control. |
+| No overflow protection is performed if ORIGINAL_G7231 is defined. |
+| |
+| Complexity weight : 3 (it is performing something equivalent to |
+| extract_h( L_shl( L_mult0( v1, v2), 16)) |
+| |
+| Inputs : |
+| |
+| a |
+| 16 bit short signed integer (Word16). |
+| |
+| b |
+| 16 bit short signed integer (Word16). |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| 16 bit short signed integer (Word16). No overflow checks |
+| are performed if ORIGINAL_G7231 is defined. |
+|___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+Word16 i_mult( Word16 a, Word16 b )
+#else /* BASOP_NOGLOB */
+Word16 DEPR_i_mult( Word16 a, Word16 b )
+#endif /* BASOP_NOGLOB */
+{
+#ifdef ORIGINAL_G7231
+ return a * b;
+#else
+ Word32 /*register*/ c = a * b;
+ return saturate( c );
+#endif
+}
+
+
+/*
+ ******************************************************************************
+ * The following three operators are not part of the original
+ * G.729/G.723.1 set of basic operators and implement shiftless
+ * accumulation operation.
+ ******************************************************************************
+ */
+
+/*___________________________________________________________________________
+ |
+ | Function Name : L_mult0
+ |
+ | Purpose :
+ |
+ | L_mult0 is the 32 bit result of the multiplication of var1 times var2
+ | without one left shift.
+ |
+ | Complexity weight : 1
+ |
+ | Inputs :
+ |
+ | var1 16 bit short signed integer (Word16) whose value falls in the
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ |
+ | var2 16 bit short signed integer (Word16) whose value falls in the
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ |
+ | Return Value :
+ |
+ | L_var_out
+ | 32 bit long signed integer (Word32) whose value falls in the
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ |___________________________________________________________________________
+*/
+Word32 L_mult0( Word16 var1, Word16 var2 )
+{
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1 * (Word32) var2;
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ |
+ | Function Name : L_mac0
+ |
+ | Purpose :
+ |
+ | Multiply var1 by var2 (without left shift) and add the 32 bit result to
+ | L_var3 with saturation, return a 32 bit result:
+ | L_mac0(L_var3,var1,var2) = L_add(L_var3,(L_mult0(var1,var2)).
+ |
+ | Complexity weight : 1
+ |
+ | Inputs :
+ |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+ |
+ | var1 16 bit short signed integer (Word16) whose value falls in the
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ |
+ | var2 16 bit short signed integer (Word16) whose value falls in the
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ |
+ | Return Value :
+ |
+ | L_var_out
+ | 32 bit long signed integer (Word32) whose value falls in the
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ |___________________________________________________________________________
+*/
+#ifdef BASOP_NOGLOB
+Word32 L_mac0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult0( var1, var2 );
+ L_var_out = L_add_o( L_var3, L_product, Overflow );
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word32 L_mac0( Word32 L_var3, Word16 var1, Word16 var2 )
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult0( var1, var2 );
+ L_var_out = L_add( L_var3, L_product );
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*___________________________________________________________________________
+ |
+ | Function Name : L_msu0
+ |
+ | Purpose :
+ |
+ | Multiply var1 by var2 (without left shift) and subtract the 32 bit
+ | result to L_var3 with saturation, return a 32 bit result:
+ | L_msu0(L_var3,var1,var2) = L_sub(L_var3,(L_mult0(var1,var2)).
+ |
+ | Complexity weight : 1
+ |
+ | Inputs :
+ |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+ |
+ | var1 16 bit short signed integer (Word16) whose value falls in the
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ |
+ | var2 16 bit short signed integer (Word16) whose value falls in the
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ |
+ | Return Value :
+ |
+ | L_var_out
+ | 32 bit long signed integer (Word32) whose value falls in the
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ |___________________________________________________________________________
+*/
+#ifdef BASOP_NOGLOB
+Word32 L_msu0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult0( var1, var2 );
+ L_var_out = L_sub_o( L_var3, L_product, Overflow );
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word32 L_msu0( Word32 L_var3, Word16 var1, Word16 var2 )
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult0( var1, var2 );
+ L_var_out = L_sub( L_var3, L_product );
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/basop32.h b/lib_com/basop32.h
new file mode 100644
index 0000000000000000000000000000000000000000..f1a7e1b8646ffb8d13fa33090acc23f218575732
--- /dev/null
+++ b/lib_com/basop32.h
@@ -0,0 +1,276 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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.
+
+*******************************************************************************************************/
+
+/*
+ ===========================================================================
+ File: BASOP32.H v.2.3 - 30.Nov.2009
+ ===========================================================================
+
+ ITU-T STL BASIC OPERATORS
+
+ GLOBAL FUNCTION PROTOTYPES
+
+ History:
+ 26.Jan.00 v1.0 Incorporated to the STL from updated G.723.1/G.729
+ basic operator library (based on basic_op.h) and
+ G.723.1's basop.h.
+ 05.Jul.00 v1.1 Added 32-bit shiftless mult/mac/msub operators
+
+ 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control
+ operators for the ITU-T Standard Tool Library as
+ described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
+ TD 11 document and subsequent discussions on the
+ wp3audio@yahoogroups.com email reflector.
+ norm_s() weight reduced from 15 to 1.
+ norm_l() weight reduced from 30 to 1.
+ L_abs() weight reduced from 2 to 1.
+ L_add() weight reduced from 2 to 1.
+ L_negate() weight reduced from 2 to 1.
+ L_shl() weight reduced from 2 to 1.
+ L_shr() weight reduced from 2 to 1.
+ L_sub() weight reduced from 2 to 1.
+ mac_r() weight reduced from 2 to 1.
+ msu_r() weight reduced from 2 to 1.
+ mult_r() weight reduced from 2 to 1.
+ L_deposit_h() weight reduced from 2 to 1.
+ L_deposit_l() weight reduced from 2 to 1.
+ L_mls() weight of 5.
+ div_l() weight of 32.
+ i_mult() weight of 3.
+
+ 30 Nov 09 v2.3 round() function is now round_fx().
+ saturate() is not referencable from outside application
+
+ 13 Mar 12 Add Overflow2 flag for additional overflow checking.
+ ============================================================================
+*/
+
+
+#ifndef _BASIC_OP_H
+#define _BASIC_OP_H
+
+#include "typedef.h"
+#define BASOP_OVERFLOW2
+
+/*___________________________________________________________________________
+ | |
+ | Constants and Globals |
+ |___________________________________________________________________________|
+*/
+#ifndef BASOP_NOGLOB
+extern Flag Overflow, Overflow2;
+extern Flag Carry;
+
+#else /* BASOP_NOGLOB */
+/* DISABLED TO AVOID GLOBAL VARIABLES */
+/*
+extern Flag BASOP_Overflow, BASOP_Overflow2;
+extern Flag BASOP_Carry;
+*/
+#endif /* BASOP_NOGLOB */
+#define BASOP_SATURATE_WARNING_ON
+#define BASOP_SATURATE_WARNING_OFF
+#define BASOP_SATURATE_ERROR_ON
+#define BASOP_SATURATE_ERROR_OFF
+#define BASOP_CHECK()
+
+
+#define MAX_32 (Word32) 0x7fffffffL
+#define MIN_32 (Word32) 0x80000000L
+
+#define MAX_16 (Word16) 0x7fff
+#define MIN_16 (Word16) 0x8000
+
+/*___________________________________________________________________________
+ | |
+ | Prototypes for basic arithmetic operators |
+ |___________________________________________________________________________|
+*/
+
+#ifndef BASOP_NOGLOB
+Word16 add( Word16 var1, Word16 var2 ); /* Short add, 1 */
+Word16 sub( Word16 var1, Word16 var2 ); /* Short sub, 1 */
+Word16 abs_s( Word16 var1 ); /* Short abs, 1 */
+Word16 shl( Word16 var1, Word16 var2 ); /* Short shift left, 1 */
+Word16 shr( Word16 var1, Word16 var2 ); /* Short shift right, 1 */
+Word16 mult( Word16 var1, Word16 var2 ); /* Short mult, 1 */
+Word32 L_mult( Word16 var1, Word16 var2 ); /* Long mult, 1 */
+Word16 negate( Word16 var1 ); /* Short negate, 1 */
+Word16 extract_h( Word32 L_var1 ); /* Extract high, 1 */
+Word16 extract_l( Word32 L_var1 ); /* Extract low, 1 */
+Word16 round_fx( Word32 L_var1 ); /* Round, 1 */
+Word32 L_mac( Word32 L_var3, Word16 var1, Word16 var2 ); /* Mac, 1 */
+Word32 L_msu( Word32 L_var3, Word16 var1, Word16 var2 ); /* Msu, 1 */
+Word32 L_macNs( Word32 L_var3, Word16 var1, Word16 var2 ); /* Mac without
+ sat, 1 */
+#else /* BASOP_NOGLOB */
+Word16 add( Word16 var1, Word16 var2 ); /* Short add, 1 */
+Word16 sub( Word16 var1, Word16 var2 ); /* Short sub, 1 */
+Word16 abs_s( Word16 var1 ); /* Short abs, 1 */
+Word16 shl( Word16 var1, Word16 var2 ); /* Short shift left, 1 */
+Word16 shr( Word16 var1, Word16 var2 ); /* Short shift right, 1 */
+Word16 mult( Word16 var1, Word16 var2 ); /* Short mult, 1 */
+Word32 L_mult( Word16 var1, Word16 var2 ); /* Long mult, 1 */
+Word16 negate( Word16 var1 ); /* Short negate, 1 */
+Word16 extract_h( Word32 L_var1 ); /* Extract high, 1 */
+Word16 extract_l( Word32 L_var1 ); /* Extract low, 1 */
+Word16 round_fx( Word32 L_var1 ); /* Round, 1 */
+Word32 L_mac( Word32 L_var3, Word16 var1, Word16 var2 ); /* Mac, 1 */
+Word32 L_msu( Word32 L_var3, Word16 var1, Word16 var2 ); /* Msu, 1 */
+Word32 DEPR_L_macNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ); /* Mac without
+ sat, 1 */
+#endif /* BASOP_NOGLOB */
+
+#ifndef BASOP_NOGLOB
+Word32 L_msuNs( Word32 L_var3, Word16 var1, Word16 var2 ); /* Msu without
+ sat, 1 */
+#else /* BASOP_NOGLOB */
+Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ); /* Msu without
+ sat, 1 */
+#endif /* BASOP_NOGLOB */
+#ifndef BASOP_NOGLOB
+Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */
+Word32 L_sub( Word32 L_var1, Word32 L_var2 ); /* Long sub, 1 */
+Word32 L_add_c( Word32 L_var1, Word32 L_var2 ); /* Long add with c, 2 */
+Word32 L_sub_c( Word32 L_var1, Word32 L_var2 ); /* Long sub with c, 2 */
+Word32 L_negate( Word32 L_var1 ); /* Long negate, 1 */
+Word16 mult_r( Word16 var1, Word16 var2 ); /* Mult with round, 1 */
+Word32 L_shl( Word32 L_var1, Word16 var2 ); /* Long shift left, 1 */
+Word32 L_shr( Word32 L_var1, Word16 var2 ); /* Long shift right, 1 */
+Word16 shr_r( Word16 var1, Word16 var2 ); /* Shift right with
+ round, 2 */
+#else /* BASOP_NOGLOB */
+Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */
+Word32 L_sub( Word32 L_var1, Word32 L_var2 ); /* Long sub, 1 */
+Word32 DEPR_L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long add with c, 2 */
+Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long sub with c, 2 */
+Word32 L_negate( Word32 L_var1 ); /* Long negate, 1 */
+Word16 mult_r( Word16 var1, Word16 var2 ); /* Mult with round, 1 */
+Word32 L_shl( Word32 L_var1, Word16 var2 ); /* Long shift left, 1 */
+Word32 L_shr( Word32 L_var1, Word16 var2 ); /* Long shift right, 1 */
+Word16 shr_r( Word16 var1, Word16 var2 ); /* Shift right with
+ round, 2 */
+#endif /* BASOP_NOGLOB */
+
+#ifndef BASOP_NOGLOB
+Word16 mac_r( Word32 L_var3, Word16 var1, Word16 var2 ); /* Mac with
+ rounding, 1 */
+#else /* BASOP_NOGLOB */
+Word16 mac_r( Word32 L_var3, Word16 var1, Word16 var2 ); /* Mac with
+ rounding, 1 */
+#endif /* BASOP_NOGLOB */
+#ifndef BASOP_NOGLOB
+Word16 msu_r( Word32 L_var3, Word16 var1, Word16 var2 ); /* Msu with
+ rounding, 1 */
+#else /* BASOP_NOGLOB */
+Word16 msu_r( Word32 L_var3, Word16 var1, Word16 var2 ); /* Msu with
+ rounding, 1 */
+#endif /* BASOP_NOGLOB */
+#ifndef BASOP_NOGLOB
+Word32 L_deposit_h( Word16 var1 ); /* 16 bit var1 -> MSB, 1 */
+Word32 L_deposit_l( Word16 var1 ); /* 16 bit var1 -> LSB, 1 */
+#else /* BASOP_NOGLOB */
+Word32 L_deposit_h( Word16 var1 ); /* 16 bit var1 -> MSB, 1 */
+Word32 L_deposit_l( Word16 var1 ); /* 16 bit var1 -> LSB, 1 */
+#endif /* BASOP_NOGLOB */
+
+#ifndef BASOP_NOGLOB
+Word32 L_shr_r( Word32 L_var1, Word16 var2 ); /* Long shift right with
+ round, 3 */
+#else /* BASOP_NOGLOB */
+Word32 L_shr_r( Word32 L_var1, Word16 var2 ); /* Long shift right with
+ round, 3 */
+#endif /* BASOP_NOGLOB */
+#ifndef BASOP_NOGLOB
+Word32 L_abs( Word32 L_var1 ); /* Long abs, 1 */
+Word32 L_sat( Word32 L_var1 ); /* Long saturation, 4 */
+Word16 norm_s( Word16 var1 ); /* Short norm, 1 */
+Word16 div_s( Word16 var1, Word16 var2 ); /* Short division, 18 */
+Word16 norm_l( Word32 L_var1 ); /* Long norm, 1 */
+#else /* BASOP_NOGLOB */
+Word32 L_abs( Word32 L_var1 ); /* Long abs, 1 */
+Word32 DEPR_L_sat_co( Word32 L_var1, Flag Overflow, Flag Carry ); /* Long saturation, 4 */
+Word16 norm_s( Word16 var1 ); /* Short norm, 1 */
+Word16 div_s( Word16 var1, Word16 var2 ); /* Short division, 18 */
+Word16 norm_l( Word32 L_var1 ); /* Long norm, 1 */
+#endif /* BASOP_NOGLOB */
+
+
+/*
+ * Additional G.723.1 operators
+ */
+#ifndef BASOP_NOGLOB
+Word32 L_mls( Word32, Word16 ); /* Weight FFS; currently assigned 5 */
+Word16 div_l( Word32, Word16 ); /* Weight FFS; currently assigned 32 */
+Word16 i_mult( Word16 a, Word16 b ); /* Weight FFS; currently assigned 3 */
+#else /* BASOP_NOGLOB */
+Word32 L_mls( Word32, Word16 ); /* Weight FFS; currently assigned 5 */
+Word16 div_l( Word32, Word16 ); /* Weight FFS; currently assigned 32 */
+Word16 DEPR_i_mult( Word16 a, Word16 b ); /* Weight FFS; currently assigned 3 */
+#endif /* BASOP_NOGLOB */
+
+/*
+ * New shiftless operators, not used in G.729/G.723.1
+ */
+Word32 L_mult0( Word16 v1, Word16 v2 ); /* 32-bit Multiply w/o shift 1 */
+Word32 L_mac0( Word32 L_v3, Word16 v1, Word16 v2 ); /* 32-bit Mac w/o shift 1 */
+Word32 L_msu0( Word32 L_v3, Word16 v1, Word16 v2 ); /* 32-bit Msu w/o shift 1 */
+#ifdef BASOP_NOGLOB
+
+/*
+ * Overflowing operators
+ */
+Word16 add_o( Word16 var1, Word16 var2, Flag *Overflow );
+Word16 sub_o( Word16 var1, Word16 var2, Flag *Overflow );
+Word16 shl_o( Word16 var1, Word16 var2, Flag *Overflow );
+Word16 mult_o( Word16 var1, Word16 var2, Flag *Overflow );
+Word32 L_mult_o( Word16 var1, Word16 var2, Flag *Overflow );
+Word16 round_fx_o( Word32 L_var1, Flag *Overflow );
+Word32 L_mac_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow );
+Word32 L_msu_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow );
+Word32 L_add_o( Word32 L_var1, Word32 L_var2, Flag *Overflow );
+Word32 L_sub_o( Word32 L_var1, Word32 L_var2, Flag *Overflow );
+Word32 L_shr_o( Word32 L_var1, Word16 var2, Flag *Overflow );
+Word32 L_shl_o( Word32 L_var1, Word16 var2, Flag *Overflow );
+Word32 L_mls_o( Word32 Lv, Word16 v, Flag *Overflow );
+Word32 L_mac0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow );
+Word32 L_msu0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow );
+Word16 mult_ro( Word16 var1, Word16 var2, Flag *Overflow );
+Word16 mac_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow );
+Word16 msu_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow );
+#endif /* BASOP_NOGLOB */
+
+
+#endif /* ifndef _BASIC_OP_H */
+
+
+/* end of file */
diff --git a/lib_com/basop_com_lpc.c b/lib_com/basop_com_lpc.c
new file mode 100644
index 0000000000000000000000000000000000000000..442afe554c1e02eeaa23c7b5e5370018c806ce8f
--- /dev/null
+++ b/lib_com/basop_com_lpc.c
@@ -0,0 +1,263 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "typedef.h"
+#include "basop_proto_func.h"
+#include "cnst.h"
+#include "basop_util.h"
+#include "stl.h"
+
+#define WMC_TOOL_SKIP
+
+#define UNROLL_CHEBYSHEV_INNER_LOOP
+#define NC_MAX 8
+#define GUESS_TBL_SZ 256
+
+#define Madd_32_16( accu, x, y ) L_add( accu, Mpy_32_16( x, y ) )
+#define Msub_32_16( accu, x, y ) L_sub( accu, Mpy_32_16( x, y ) )
+
+
+/*
+ * weight_a
+ *
+ * Parameters:
+ * a I: LP filter coefficients Q12
+ * ap O: weighted LP filter coefficients Q12
+ * gamma I: weighting factor Q15
+ *
+ * Function:
+ * Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i).
+ *
+ * Returns:
+ * void
+ */
+void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma )
+{
+ Word16 i, fac;
+ Word32 Amax;
+ Word16 shift;
+
+
+ fac = gamma;
+ Amax = L_mult( 16384, a[0] );
+ FOR( i = 1; i < M; i++ )
+ {
+ Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) );
+ fac = mult_r( fac, gamma );
+ }
+ Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) );
+ shift = norm_l( Amax );
+ fac = gamma;
+ ap[0] = shl( a[0], sub( shift, 1 ) );
+ move16();
+ FOR( i = 1; i < M; i++ )
+ {
+ ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) );
+ move16();
+ fac = mult_r( fac, gamma );
+ }
+ ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) );
+ move16();
+
+
+ return;
+}
+
+/*
+ * weight_a_inv
+ *
+ * Parameters:
+ * a I: LP filter coefficients Q12
+ * ap O: weighted LP filter coefficients Q12
+ * inv_gamma I: inverse weighting factor Q14
+ *
+ * Function:
+ * Weighting of LP filter coefficients, ap[i] = a[i] * (inv_gamma^i).
+ *
+ * Returns:
+ * void
+ */
+void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma )
+{
+ Word16 i;
+ static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924, /* Q14 */
+ 17350, 18859, 20499, 22281, 24219, 26325, 28614, 31102 }; /* Q13 */
+ static const Word16 inv_gamma_tab_16k[16] = { 17430, 18542, 19726, 20985, 22324, 23749, 25265, 26878, /* Q14 */
+ 14297, 15209, 16180, 17213, 18312, 19480, 20724, 22047 }; /* Q13 */
+ const Word16 *inv_gamma_tab;
+ Word32 L_tmp;
+ Word32 Amax;
+ Word16 shift;
+
+
+ IF( inv_gamma == 16384 )
+ {
+ FOR( i = 0; i <= M; i++ )
+ {
+ ap[i] = a[i];
+ move16();
+ }
+ return;
+ }
+
+ assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV );
+
+ inv_gamma_tab = inv_gamma_tab_12k8;
+ move16();
+ if ( sub( inv_gamma, GAMMA16k_INV ) == 0 )
+ {
+ inv_gamma_tab = inv_gamma_tab_16k;
+ move16();
+ }
+
+ Amax = L_mult( 16384, a[0] );
+ FOR( i = 1; i < 9; i++ )
+ {
+ Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) );
+ }
+ FOR( i = 9; i < 17; i++ )
+ {
+ Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) );
+ }
+ shift = norm_l( Amax );
+ ap[0] = shl( a[0], sub( shift, 1 ) );
+ move16();
+ FOR( i = 1; i < 9; i++ )
+ {
+ L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] );
+ ap[i] = round_fx( L_shl( L_tmp, shift ) );
+ move16();
+ }
+ shift = add( shift, 1 );
+ FOR( i = 9; i < 17; i++ )
+ {
+ L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] );
+ ap[i] = round_fx( L_shl( L_tmp, shift ) );
+ move16();
+ }
+
+
+ return;
+}
+
+/*
+ * basop_E_LPC_a_add_tilt
+ *
+ * Parameters:
+ * a I: LP filter coefficients (m+1 coeffs)
+ * ap O: modified LP filter coefficients (m+2 coeffs)
+ * gamma I: tilt factor
+ *
+ * Function:
+ * Modified LP filter by adding 1st order pre-premphasis, Ap(z)=A(z).(1-gamma.z^(-1))
+ *
+ * Returns:
+ * void
+ */
+void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma )
+{
+ Word16 i;
+ Word32 Amax, Atmp[M + 2];
+ Word16 shift;
+
+
+ Amax = L_mult( 16384, a[0] );
+ FOR( i = 1; i <= M; i++ )
+ {
+ Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) );
+ move32();
+ Amax = L_max( Amax, L_abs( Atmp[i] ) );
+ }
+ Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) );
+ move32();
+ Amax = L_max( Amax, L_abs( Atmp[M + 1] ) );
+ shift = norm_l( Amax );
+ ap[0] = shl( a[0], sub( shift, 1 ) );
+ move16();
+ FOR( i = 1; i <= M; i++ )
+ {
+ ap[i] = round_fx( L_shl( Atmp[i], shift ) );
+ move16();
+ }
+ ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) );
+ move16();
+
+ return;
+}
+
+
+static Word16 xsf_to_xsp( Word16 xsf )
+{
+ /* xsp = cos(xsf * 3.1415/6400); */
+ return getCosWord16R2( xsf );
+}
+
+/*
+ * lsf2lsp
+ *
+ * Parameters:
+ * lsf I: lsf[m] normalized (range: 0 <= val <= 0.5) x2.56
+ * lsp O: lsp[m] (range: -1 <= val < 1) Q15
+ *
+ * Function:
+ * Transformation lsf to lsp
+ *
+ * LSF are line spectral pair in frequency domain (0 to 6400).
+ * LSP are line spectral pair in cosine domain (-1 to 1).
+ *
+ * Returns:
+ * void
+ */
+void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] )
+{
+ Word16 i;
+
+
+ /* convert ISFs to the cosine domain */
+ FOR( i = 0; i < M; i++ )
+ {
+ *lsp++ = xsf_to_xsp( *lsf++ );
+ move16();
+ }
+
+
+ return;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/basop_lsf_tools.c b/lib_com/basop_lsf_tools.c
new file mode 100644
index 0000000000000000000000000000000000000000..eddce99e83929a2ae105b6117512512f20fd1880
--- /dev/null
+++ b/lib_com/basop_lsf_tools.c
@@ -0,0 +1,314 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "basop_proto_func.h"
+#include "control.h"
+#include "basop_util.h"
+
+#define WMC_TOOL_SKIP
+
+#define NC_MAX 8
+
+static Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1 );
+
+
+/*
+ * E_LPC_f_lsp_a_conversion
+ *
+ * Parameters:
+ * lsp I: Line spectral pairs Q15
+ * a O: Predictor coefficients (order = m) Qx (The Q factor of the output to be deduced from a(0))
+ * m I: order of LP filter
+ *
+ * Function:
+ * Convert ISPs to predictor coefficients a[]
+ *
+ * Returns:
+ * void
+ */
+void basop_E_LPC_f_lsp_a_conversion(
+ const Word16 *lsp,
+ Word16 *a,
+ const Word16 m )
+{
+ Word16 i, j, k;
+ Word32 f1[NC_MAX + 1], f2[NC_MAX + 1];
+ Word16 nc;
+ Word32 t0;
+ Word16 Ovf, Ovf2;
+
+
+ /*-----------------------------------------------------*
+ * Find the polynomials F1(z) and F2(z) *
+ *-----------------------------------------------------*/
+
+ nc = shr( m, 1 );
+
+ assert( m == 16 || m == 10 );
+
+ Ovf = 0;
+ move16();
+ Ovf = E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, Ovf, 1 );
+ Ovf2 = E_LPC_f_lsp_pol_get( &lsp[1], f2, nc, Ovf, 1 );
+ IF( sub( Ovf2, Ovf ) != 0 )
+ {
+ /* to ensure similar scaling for f1 and f2 in case
+ an overflow would be detected only in f2,
+ but this case never happen on my dtb */
+ E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, s_max( Ovf2, Ovf ), 1 );
+ }
+ /*-----------------------------------------------------*
+ * Multiply F1(z) by (1+z^-1) and F2(z) by (1-z^-1) *
+ *-----------------------------------------------------*/
+ /*modification*/
+ k = sub( nc, 1 );
+ FOR( i = 0; i <= k; i++ )
+ {
+ f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] );
+ move32();
+ f2[nc - i] = L_sub( f2[nc - i], f2[nc - i - 1] );
+ move32();
+ }
+
+ /*-----------------------------------------------------*
+ * A(z) = (F1(z)+F2(z))/2 *
+ * F1(z) is symmetric and F2(z) is antisymmetric *
+ *-----------------------------------------------------*/
+
+ t0 = L_deposit_l( 0 );
+ FOR( i = 1; i <= nc; i++ )
+ {
+ t0 = L_max( t0, L_abs( L_add( f1[i], f2[i] ) ) );
+ t0 = L_max( t0, L_abs( L_sub( f1[i], f2[i] ) ) );
+ }
+ k = s_min( norm_l( t0 ), 6 );
+ a[0] = shl( 256, k );
+ move16();
+ test();
+ IF( Ovf || Ovf2 )
+ {
+ a[0] = shl( 256, sub( k, Ovf ) );
+ move16();
+ }
+ j = m;
+ FOR( i = 1; i <= nc; i++ )
+ {
+ /* a[i] = 0.5*(f1[i] + f2[i]) */
+ t0 = L_add( f1[i], f2[i] );
+ t0 = L_shl( t0, k );
+ a[i] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */
+
+ /* a[j] = 0.5*(f1[i] - f2[i]) */
+ t0 = L_sub( f1[i], f2[i] );
+ t0 = L_shl( t0, k );
+ a[j] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */
+ j--;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------------
+ * procedure reorder_lsf()
+ *
+ * To make sure that the lsfs are properly ordered and to keep a certain
+ * minimum distance between consecutive lsfs.
+ *--------------------------------------------------------------------------*/
+void basop_reorder_lsf(
+ Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/
+ const Word16 min_dist, /* i : minimum required distance x2.56*/
+ const Word16 n, /* i : LPC order */
+ const Word32 Fs /* i : sampling frequency */
+)
+{
+ Word16 i, lsf_min, n_m_1;
+ Word16 lsf_max;
+
+ lsf_min = min_dist;
+ move16();
+
+ /*-----------------------------------------------------------------------*
+ * Verify the LSF ordering and minimum GAP
+ *-----------------------------------------------------------------------*/
+
+ FOR( i = 0; i < n; i++ )
+ {
+ if ( sub( lsf[i], lsf_min ) < 0 )
+ {
+ lsf[i] = lsf_min;
+ move16();
+ }
+ lsf_min = add( lsf[i], min_dist );
+ }
+
+ /*-----------------------------------------------------------------------*
+ * Reverify the LSF ordering and minimum GAP in the reverse order (security)
+ *-----------------------------------------------------------------------*/
+
+ lsf_max = round_fx( L_sub( L_shr( L_mult0( extract_l( L_shr( Fs, 1 ) ), 1311 ), 9 - 16 ), L_deposit_h( min_dist ) ) ); /* Q0 + Q9 , 1311 is 2.56 in Q9 */
+
+ n_m_1 = sub( n, 1 );
+ IF( sub( lsf[n_m_1], lsf_max ) > 0 ) /* If danger of unstable filter in case of resonance in HF */
+ {
+ FOR( i = n_m_1; i >= 0; i-- ) /* Reverify the minimum LSF gap in the reverse direction */
+ {
+ if ( sub( lsf[i], lsf_max ) > 0 )
+ {
+ lsf[i] = lsf_max;
+ move16();
+ }
+ lsf_max = sub( lsf[i], min_dist );
+ }
+ }
+
+ return;
+}
+
+
+/*
+ * E_LPC_f_lsp_pol_get
+ *
+ * Parameters:
+ * lsp/isp I: Line spectral pairs (cosine domaine) Q15
+ * f O: the coefficients of F1 or F2 Q23
+ * n I: no of coefficients (m/2)
+ * == NC for F1(z); == NC-1 for F2(z)
+ * fact I: scaling factor
+ *
+ *-----------------------------------------------------------*
+ * procedure E_LPC_f_lsp_pol_get: *
+ * ~~~~~~~~~~~ *
+ * Find the polynomial F1(z) or F2(z) from the LSPs. *
+ * This is performed by expanding the product polynomials: *
+ * *
+ * F1(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 ) *
+ * i=0,2,4,6,8 *
+ * F2(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 ) *
+ * i=1,3,5,7,9 *
+ * *
+ * where LSP_i are the LSPs in the cosine domain. *
+ * *
+ *-----------------------------------------------------------*
+ * R.A.Salami October 1990 *
+ *-----------------------------------------------------------*
+ */
+static Word16 E_LPC_f_lsp_pol_get(
+ const Word16 lsp[],
+ Word32 f[],
+ const Word16 n,
+ const Word16 past_Ovf,
+ const Word16 isMODE1 )
+{
+ /* All computation in Q23 */
+ const Word16 *plsp;
+ Word16 i, j;
+ Word16 b;
+ Word32 b32;
+ Word16 Ovf = 0;
+ Word16 Q_out;
+ Word16 m2;
+#ifdef BASOP_NOGLOB
+ Flag Overflow;
+#endif /* BASOP_NOGLOB */
+
+
+ Q_out = 31 - 23;
+ move16();
+ Ovf = past_Ovf;
+ move16();
+
+ test();
+ if ( past_Ovf && isMODE1 ) /* Currently this feature is implemented only in MODE1 */
+ {
+ /* In some NB cases, overflow where detectected
+ in f1 or f2 polynomial computation when it
+ happen we reduce the precision of the computing
+ to limit the risk of saturation*/
+ Q_out = add( Q_out, past_Ovf );
+ }
+ Overflow = 0;
+ move16();
+ plsp = lsp;
+ f[0] = L_shl( 1, sub( 31, Q_out ) );
+ move32();
+ /*b = -2.0f * *plsp;*/
+ b = *plsp;
+ move16();
+ m2 = shl( -2, sub( 15, Q_out ) );
+ f[1] = L_mult( b, m2 );
+ move32();
+
+ FOR( i = 2; i <= n; i++ )
+ {
+ plsp += 2;
+ /*b = 2.0f * *plsp;*/
+ move16();
+ b = *plsp;
+ b32 = L_mult( b, m2 );
+
+ /*f[i] = -b*f[i-1] + 2.0f*f[i-2];*/
+ move32();
+ f[i] = L_shl( L_sub( f[i - 2], Mpy_32_16( f[i - 1], b ) ), 1 );
+
+ FOR( j = i - 1; j > 1; j-- )
+ {
+ /*f[j] += b*f[j-1] + f[j-2];*/
+ move32();
+ f[j] = L_add( f[j], L_sub( f[j - 2], L_shl( Mpy_32_16( f[j - 1], b ), 1 ) ) );
+ }
+ move32();
+ f[1] = L_add( f[1], b32 );
+ }
+
+
+ test();
+ IF( Overflow > 0 && isMODE1 )
+ {
+#ifdef BASOP_NOGLOB
+ assert( 0 );
+#endif /* BASOP_NOGLOB */
+ /* If an overflow is detected, redo the computation with 1 bit less */
+ Ovf = add( Ovf, 1 );
+ Ovf = E_LPC_f_lsp_pol_get( lsp, f, n, Ovf, isMODE1 );
+ }
+ return Ovf;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/basop_mpy.c b/lib_com/basop_mpy.c
new file mode 100644
index 0000000000000000000000000000000000000000..cb6268d6279abe7ff8e6c01bf0b9de7ee948fde2
--- /dev/null
+++ b/lib_com/basop_mpy.c
@@ -0,0 +1,89 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include "basop_mpy.h"
+#include
+#include "options.h"
+
+#define WMC_TOOL_SKIP
+
+Word32 Mpy_32_16_1( Word32 x, Word16 y )
+{
+ Word32 mh;
+ UWord16 ml;
+
+ Mpy_32_16_ss( x, y, &mh, &ml );
+
+ return ( mh );
+}
+
+Word32 Mpy_32_16( Word32 x, Word16 y )
+{
+ Word32 mh;
+ UWord16 ml;
+
+ Mpy_32_16_ss( x, y, &mh, &ml );
+
+ return ( mh );
+}
+
+Word32 Mpy_32_16_r( Word32 x, Word16 y )
+{
+ Word32 mh;
+ UWord16 ml;
+
+ Mpy_32_16_ss( x, y, &mh, &ml );
+
+ if ( s_and( ml, -32768 /* 0x8000 */ ) )
+ {
+ mh = L_add( mh, 1 );
+ }
+
+ return ( mh );
+}
+
+
+Word32 Mpy_32_32( Word32 x, Word32 y )
+{
+ Word32 mh;
+ UWord32 ml;
+
+ Mpy_32_32_ss( x, y, &mh, &ml );
+
+ return ( mh );
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/basop_mpy.h b/lib_com/basop_mpy.h
new file mode 100644
index 0000000000000000000000000000000000000000..c35531fa6fcb5d4b1c6435b36d98ca76581f0c0b
--- /dev/null
+++ b/lib_com/basop_mpy.h
@@ -0,0 +1,97 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 __BASOP_MPY_H
+#define __BASOP_MPY_H
+
+#include "stl.h"
+#include
+#include "options.h"
+
+/**
+ * \brief 32*16 Bit fractional Multiplication using 40 bit OPS
+ * Performs a multiplication of a 32-bit variable x by
+ * a 16-bit variable y, returning a 32-bit value.
+ *
+ * \param[i] x
+ * \param[i] y
+ *
+ * \return x*y
+ */
+Word32 Mpy_32_16_1( Word32 x, Word16 y );
+
+
+/**
+ * \brief 32*16 Bit fractional Multiplication using 40 bit OPS
+ * Performs a multiplication of a 32-bit variable x by
+ * a 16-bit variable y, returning a 32-bit value.
+ *
+ * \param[i] x
+ * \param[i] y
+ *
+ * \return x*y
+ */
+Word32 Mpy_32_16( Word32 x, Word16 y );
+
+
+/**
+ * \brief 32*16 Bit fractional Multiplication using 40 bit OPS
+ * Performs a multiplication of a 32-bit variable x by
+ * a 16-bit variable y including rounding, returning a 32-bit value.
+ *
+ * \param[i] x
+ * \param[i] y
+ *
+ * \return x*y
+ */
+Word32 Mpy_32_16_r( Word32 x, Word16 y );
+
+
+/**
+ * \brief 32*32 Bit fractional Multiplication using 40 bit OPS
+ *
+ * Performs a multiplication of a 32-bit variable x by
+ * a 32-bit variable y, returning a 32-bit value.
+ *
+ * \param[i] x
+ * \param[i] y
+ *
+ * \return x*y
+ */
+
+Word32 Mpy_32_32( Word32 x, Word32 y );
+
+#endif /* __BASOP_SETTINGS_H */
diff --git a/lib_com/basop_proto_func.h b/lib_com/basop_proto_func.h
new file mode 100644
index 0000000000000000000000000000000000000000..0c514475f324d6a587142fb07f75d6648a816986
--- /dev/null
+++ b/lib_com/basop_proto_func.h
@@ -0,0 +1,70 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 BASOP_PROTO_FUNC_H
+#define BASOP_PROTO_FUNC_H
+
+#include
+#include "options.h"
+#include "stl.h"
+#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) */
+#define INT_FS_FX 12800 /* internal sampling frequency */
+
+void basop_lsp2a_stab( const Word16 *lsp, Word16 *a );
+void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] );
+void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma );
+void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma );
+void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma );
+void basop_reorder_lsf( Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 Fs );
+void basop_E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m );
+
+/* tcx_utils.c */
+void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp );
+
+void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] );
+void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] );
+
+
+#endif
diff --git a/lib_com/basop_settings.h b/lib_com/basop_settings.h
new file mode 100644
index 0000000000000000000000000000000000000000..758a99650cea4a0a7c0fc7ca59c4bab70953dbf0
--- /dev/null
+++ b/lib_com/basop_settings.h
@@ -0,0 +1,110 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 __BASOP_SETTINGS_H
+#define __BASOP_SETTINGS_H
+
+#include
+#include "options.h"
+#include "stl.h"
+#include "basop_mpy.h"
+
+#define WORD32_BITS 32
+#define MAXVAL_WORD32 ( (int32_t) 0x7FFFFFFF )
+#define MINVAL_WORD32 ( (int32_t) 0x80000000 )
+#define WORD32_FIX_SCALE ( (int64_t) ( 1 ) << ( WORD32_BITS - 1 ) )
+
+#define WORD16_BITS 16
+#define MAXVAL_WORD16 ( ( (int32_t) 0x7FFFFFFF ) >> 16 )
+#define MINVAL_WORD16 ( ( (int32_t) 0x80000000 ) >> 16 )
+#define WORD16_FIX_SCALE ( (int64_t) ( 1 ) << ( WORD16_BITS - 1 ) )
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4310 )
+#endif
+
+/*!
+ \def Macro converts a float < 1 to Word32 fixed point with saturation and rounding
+*/
+#define FL2WORD32( val ) \
+ ( Word32 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD32 ) ) ? (int32_t) ( MAXVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * (WORD32_FIX_SCALE) -0.5 ) <= (double) ( MINVAL_WORD32 ) ) ? (int32_t) ( MINVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) (WORD32_FIX_SCALE) -0.5 ) ) )
+
+/*!
+ \def Macro converts a float < 1 to Word16 fixed point with saturation and rounding
+*/
+#define FL2WORD16( val ) \
+ ( Word16 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD16 ) ) ? (int32_t) ( MAXVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * (WORD16_FIX_SCALE) -0.5 ) <= (double) ( MINVAL_WORD16 ) ) ? (int32_t) ( MINVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) (WORD16_FIX_SCALE) -0.5 ) ) )
+
+/*!
+ \def Macro converts a Word32 fixed point to Word16 fixed point <1 with saturation
+*/
+#define WORD322WORD16( val ) \
+ ( ( ( ( ( ( val ) >> ( WORD32_BITS - WORD16_BITS - 1 ) ) + 1 ) > ( ( (int32_t) 1 << WORD16_BITS ) - 1 ) ) && ( (int32_t) ( val ) > 0 ) ) ? (Word16) (int16_t) ( ( (int32_t) 1 << ( WORD16_BITS - 1 ) ) - 1 ) : (Word16) (int16_t) ( ( ( ( val ) >> ( WORD32_BITS - WORD16_BITS - 1 ) ) + 1 ) >> 1 ) )
+
+/*!
+ \def Macro converts a Word32 fixed point < 1 to float shifts result left by scale
+*/
+#define WORD322FL_SCALE( x, scale ) ( ( (float) ( (int32_t) ( x ) ) ) / ( (int64_t) 1 << ( WORD32_BITS - 1 - ( scale ) ) ) )
+
+/*!
+ \def Macro converts a float < 1 to Word32 fixed point with saturation and rounding, shifts result right by scale
+*/
+/* Note: Both x and scale must be constants at compile time, scale must be in range -31..31 */
+#define FL2WORD32_SCALE( x, scale ) FL2WORD32( (double) ( x ) * ( (int64_t) 1 << ( WORD32_BITS - 1 - ( scale ) ) ) / ( (int64_t) 1 << ( WORD32_BITS - 1 ) ) )
+
+/*!
+ \def Macro converts a Word16 fixed point < 1 to float shifts result left by scale
+*/
+#define WORD162FL_SCALE( x, scale ) ( ( (float) ( (int32_t) ( x ) ) ) / ( (int64_t) 1 << ( WORD16_BITS - 1 - ( scale ) ) ) )
+
+/*!
+ \def Macro converts a float < 1 to Word16 fixed point with saturation and rounding, shifts result right by scale
+*/
+/* Note: At compile time, x must be a float constant and scale must be an integer constant in range -15..15 */
+#define FL2WORD16_SCALE( x, scale ) FL2WORD16( (float) ( x ) * ( (int64_t) 1 << ( WORD16_BITS - 1 - ( scale ) ) ) / ( (int64_t) 1 << ( WORD16_BITS - 1 ) ) )
+
+
+/* Word16 Packed Type */
+typedef struct
+{
+ struct
+ {
+ Word16 re;
+ Word16 im;
+ } v;
+} PWord16;
+
+#endif /* __BASOP_SETTINGS_H */
diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c
new file mode 100644
index 0000000000000000000000000000000000000000..f57bf10a8b60c0f490f70d60e607772dc84cf84a
--- /dev/null
+++ b/lib_com/basop_tcx_utils.c
@@ -0,0 +1,438 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "cnst.h"
+#include "basop_proto_func.h"
+#include "stl.h"
+#include "prot.h"
+#include "rom_com.h"
+
+#define WMC_TOOL_SKIP
+
+/* compare two positive normalized 16 bit mantissa/exponent values */
+/* return value: positive if first value greater, negative if second value greater, zero if equal */
+static Word16 compMantExp16Unorm( Word16 m1, Word16 e1, Word16 m2, Word16 e2 )
+{
+ Word16 tmp;
+
+ assert( ( m1 >= 0x4000 ) && ( m2 >= 0x4000 ) ); /* comparisons below work only for normalized mantissas */
+
+ tmp = sub( e1, e2 );
+ if ( tmp == 0 )
+ tmp = sub( m1, m2 );
+
+ return tmp;
+}
+
+void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp )
+{
+ Word32 RealData[FDNS_NPTS];
+ Word32 ImagData[FDNS_NPTS];
+ Word16 i, j, k, step, scale, s, tmp16;
+ Word16 g, g_e, ig, ig_e;
+ Word32 tmp32;
+ const PWord16 *ptwiddle;
+
+
+ /* short-cut, to avoid calling of BASOP_getTables() */
+ ptwiddle = SineTable512_fx;
+ step = 8;
+
+ /*ODFT*/
+ assert( lpcOrder < FDNS_NPTS );
+
+ /* pre-twiddle */
+ FOR( i = 0; i <= lpcOrder; i++ )
+ {
+ RealData[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re );
+ move32();
+ ImagData[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) );
+ move32();
+ ptwiddle += step;
+ }
+
+ /* zero padding */
+ FOR( ; i < FDNS_NPTS; i++ )
+ {
+ RealData[i] = 0;
+ move32();
+ ImagData[i] = 0;
+ move32();
+ }
+
+ /* half length FFT */
+ scale = add( norm_s( lpcCoeffs[0] ), 1 );
+ move16();
+ BASOP_cfft( RealData, ImagData, 1, &scale ); /* sizeOfFft == FDNS_NPTS == 8 */
+
+
+ /*Get amplitude*/
+ j = FDNS_NPTS - 1;
+ k = 0;
+ move16();
+
+ FOR( i = 0; i < FDNS_NPTS / 2; i++ )
+ {
+ s = sub( norm_l( L_max( L_abs( RealData[i] ), L_abs( ImagData[i] ) ) ), 1 );
+
+ tmp16 = extract_h( L_shl( RealData[i], s ) );
+ tmp32 = L_mult( tmp16, tmp16 );
+
+ tmp16 = extract_h( L_shl( ImagData[i], s ) );
+ tmp16 = mac_r( tmp32, tmp16, tmp16 );
+
+ s = shl( sub( scale, s ), 1 );
+
+ if ( tmp16 == 0 )
+ {
+ s = -16;
+ move16();
+ }
+ if ( tmp16 == 0 )
+ {
+ tmp16 = 1;
+ move16();
+ }
+
+ BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e );
+
+ if ( mdct_gains != NULL )
+ {
+ mdct_gains[k] = g;
+ move16();
+ }
+
+ if ( mdct_gains_exp != NULL )
+ {
+ mdct_gains_exp[k] = g_e;
+ move16();
+ }
+
+ if ( mdct_inv_gains != NULL )
+ {
+ mdct_inv_gains[k] = ig;
+ move16();
+ }
+
+ if ( mdct_inv_gains_exp != NULL )
+ {
+ mdct_inv_gains_exp[k] = ig_e;
+ move16();
+ }
+
+ k = add( k, 1 );
+
+
+ s = sub( norm_l( L_max( L_abs( RealData[j] ), L_abs( ImagData[j] ) ) ), 1 );
+
+ tmp16 = extract_h( L_shl( RealData[j], s ) );
+ tmp32 = L_mult( tmp16, tmp16 );
+
+ tmp16 = extract_h( L_shl( ImagData[j], s ) );
+ tmp16 = mac_r( tmp32, tmp16, tmp16 );
+
+ s = shl( sub( scale, s ), 1 );
+
+ if ( tmp16 == 0 )
+ {
+ s = -16;
+ move16();
+ }
+ if ( tmp16 == 0 )
+ {
+ tmp16 = 1;
+ move16();
+ }
+
+ BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e );
+
+ if ( mdct_gains != NULL )
+ {
+ mdct_gains[k] = g;
+ move16();
+ }
+
+ if ( mdct_gains_exp != NULL )
+ {
+ mdct_gains_exp[k] = g_e;
+ move16();
+ }
+
+ if ( mdct_inv_gains != NULL )
+ {
+ mdct_inv_gains[k] = ig;
+ move16();
+ }
+
+ if ( mdct_inv_gains_exp != NULL )
+ {
+ mdct_inv_gains_exp[k] = ig_e;
+ move16();
+ }
+
+ j = sub( j, 1 );
+ k = add( k, 1 );
+ }
+}
+
+
+void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] )
+{
+ Word16 i, j, jp, jn, k, l;
+ Word16 g, pg, ng, e, tmp;
+
+
+ assert( lg % FDNS_NPTS == 0 );
+ k = shr( lg, 6 ); /* FDNS_NPTS = 64 */
+
+ IF( gains != NULL )
+ {
+ /* Linear interpolation */
+ IF( sub( k, 4 ) == 0 )
+ {
+ jp = 0;
+ move16();
+ j = 0;
+ move16();
+ jn = 1;
+ move16();
+
+ FOR( i = 0; i < lg; i += 4 )
+ {
+ pg = gains[jp];
+ move16();
+ g = gains[j];
+ move16();
+ ng = gains[jn];
+ move16();
+
+ /* common exponent for pg and g */
+ tmp = sub( gains_exp[j], gains_exp[jp] );
+ if ( tmp > 0 )
+ pg = shr( pg, tmp );
+ if ( tmp < 0 )
+ g = shl( g, tmp );
+ e = s_max( gains_exp[j], gains_exp[jp] );
+
+ tmp = mac_r( L_mult( pg, FL2WORD16( 0.375f ) ), g, FL2WORD16( 0.625f ) );
+ x[i] = L_shl( Mpy_32_16( x[i], tmp ), e );
+ move32();
+
+ tmp = mac_r( L_mult( pg, FL2WORD16( 0.125f ) ), g, FL2WORD16( 0.875f ) );
+ x[i + 1] = L_shl( Mpy_32_16( x[i + 1], tmp ), e );
+ move32();
+
+ /* common exponent for g and ng */
+ g = gains[j];
+ move16();
+ tmp = sub( gains_exp[j], gains_exp[jn] );
+ if ( tmp > 0 )
+ ng = shr( ng, tmp );
+ if ( tmp < 0 )
+ g = shl( g, tmp );
+ e = s_max( gains_exp[j], gains_exp[jn] );
+
+ tmp = mac_r( L_mult( g, FL2WORD16( 0.875f ) ), ng, FL2WORD16( 0.125f ) );
+ x[i + 2] = L_shl( Mpy_32_16( x[i + 2], tmp ), e );
+ move32();
+
+ tmp = mac_r( L_mult( g, FL2WORD16( 0.625f ) ), ng, FL2WORD16( 0.375f ) );
+ x[i + 3] = L_shl( Mpy_32_16( x[i + 3], tmp ), e );
+ move32();
+
+ jp = j;
+ move16();
+ j = jn;
+ move16();
+ jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 );
+ }
+ }
+ ELSE IF( sub( k, 5 ) == 0 )
+ {
+ jp = 0;
+ move16();
+ j = 0;
+ move16();
+ jn = 1;
+ move16();
+
+ FOR( i = 0; i < lg; i += 5 )
+ {
+ pg = gains[jp];
+ move16();
+ g = gains[j];
+ move16();
+ ng = gains[jn];
+ move16();
+
+ /* common exponent for pg and g */
+ tmp = sub( gains_exp[j], gains_exp[jp] );
+ if ( tmp > 0 )
+ pg = shr( pg, tmp );
+ if ( tmp < 0 )
+ g = shl( g, tmp );
+ e = s_max( gains_exp[j], gains_exp[jp] );
+
+ tmp = mac_r( L_mult( pg, FL2WORD16( 0.40f ) ), g, FL2WORD16( 0.60f ) );
+ x[i] = L_shl( Mpy_32_16( x[i], tmp ), e );
+ move32();
+
+ tmp = mac_r( L_mult( pg, FL2WORD16( 0.20f ) ), g, FL2WORD16( 0.80f ) );
+ x[i + 1] = L_shl( Mpy_32_16( x[i + 1], tmp ), e );
+ move32();
+
+
+ x[i + 2] = L_shl( Mpy_32_16( x[i + 2], gains[j] ), gains_exp[j] );
+ move32();
+
+ /* common exponent for g and ng */
+ g = gains[j];
+ move16();
+ tmp = sub( gains_exp[j], gains_exp[jn] );
+ if ( tmp > 0 )
+ ng = shr( ng, tmp );
+ if ( tmp < 0 )
+ g = shl( g, tmp );
+ e = s_max( gains_exp[j], gains_exp[jn] );
+
+ tmp = mac_r( L_mult( g, FL2WORD16( 0.80f ) ), ng, FL2WORD16( 0.20f ) );
+ x[i + 3] = L_shl( Mpy_32_16( x[i + 3], tmp ), e );
+ move32();
+
+ tmp = mac_r( L_mult( g, FL2WORD16( 0.60f ) ), ng, FL2WORD16( 0.40f ) );
+ x[i + 4] = L_shl( Mpy_32_16( x[i + 4], tmp ), e );
+ move32();
+
+ jp = j;
+ move16();
+ j = jn;
+ move16();
+ jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 );
+ }
+ }
+ ELSE /* no interpolation */
+ {
+ FOR( i = 0; i < FDNS_NPTS; i++ )
+ {
+ FOR( l = 0; l < k; l++ )
+ {
+ *x = L_shl( Mpy_32_16( *x, *gains ), *gains_exp );
+ move32();
+ x++;
+ }
+
+ gains++;
+ gains_exp++;
+ }
+ }
+ }
+}
+
+
+void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] )
+{
+ Word16 i;
+ Word16 max_val, max_e, fac, min_val, min_e, tmp, tmp_e;
+ Word32 L_tmp;
+
+
+ assert( lpcGains[0] >= 0x4000 );
+
+ max_val = lpcGains[0];
+ move16();
+ max_e = lpcGains_e[0];
+ move16();
+ min_val = lpcGains[0];
+ move16();
+ min_e = lpcGains_e[0];
+ move16();
+
+ /* find minimum (min) and maximum (max) of LPC gains in low frequencies */
+ FOR( i = 1; i < 9; i++ )
+ {
+ IF( compMantExp16Unorm( lpcGains[i], lpcGains_e[i], min_val, min_e ) < 0 )
+ {
+ min_val = lpcGains[i];
+ move16();
+ min_e = lpcGains_e[i];
+ move16();
+ }
+
+ IF( compMantExp16Unorm( lpcGains[i], lpcGains_e[i], max_val, max_e ) > 0 )
+ {
+ max_val = lpcGains[i];
+ move16();
+ max_e = lpcGains_e[i];
+ move16();
+ }
+ }
+
+ min_e = add( min_e, 5 ); /* min *= 32.0f; */
+
+ test();
+ IF( ( compMantExp16Unorm( max_val, max_e, min_val, min_e ) < 0 ) && ( min_val > 0 ) )
+ {
+ /* fac = tmp = (float)pow(max / min, 0.0078125f); */
+ tmp_e = min_e;
+ move16();
+ tmp = Inv16( min_val, &tmp_e );
+ L_tmp = L_shl( L_mult( tmp, max_val ), add( tmp_e, max_e ) ); /* Q31 */
+ L_tmp = BASOP_Util_Log2( L_tmp ); /* Q25 */
+ L_tmp = L_shr( L_tmp, 7 ); /* 0.0078125f = 1.f/(1<<7) */
+ L_tmp = BASOP_Util_InvLog2( L_tmp ); /* Q31 */
+ tmp = round_fx( L_tmp ); /* Q15 */
+ fac = tmp; /* Q15 */
+ move16();
+
+ /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */
+ FOR( i = 31; i >= 0; i-- )
+ {
+ x[i] = Mpy_32_16( x[i], fac );
+ move32();
+ if ( lf_deemph_factors != NULL )
+ {
+ lf_deemph_factors[i] = mult_r( lf_deemph_factors[i], fac );
+ move16();
+ }
+ fac = mult_r( fac, tmp );
+ }
+ }
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c
new file mode 100644
index 0000000000000000000000000000000000000000..ff42b0eb4345633aea6c15f49f41d06f4c86423e
--- /dev/null
+++ b/lib_com/basop_util.c
@@ -0,0 +1,1109 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "basop_util.h"
+#include "rom_com.h"
+#include "basop_settings.h"
+#include "basop_mpy.h"
+#include "control.h"
+#include "cnst.h"
+
+#define WMC_TOOL_SKIP
+
+extern const Word32 SqrtTable[32];
+extern const Word16 SqrtDiffTable[32];
+
+extern const Word32 ISqrtTable[32];
+extern const Word16 ISqrtDiffTable[32];
+
+extern const Word32 InvTable[32];
+extern const Word16 InvDiffTable[32];
+
+
+Word32 BASOP_Util_Log2(
+ Word32 x )
+{
+ Word32 exp;
+ Word16 exp_e;
+ Word16 nIn;
+ Word16 accuSqr;
+ Word32 accuRes;
+
+ assert( x >= 0 );
+
+ if ( x == 0 )
+ {
+ return ( (Word32) MIN_32 );
+ }
+
+ /* normalize input, calculate integer part */
+ exp_e = norm_l( x );
+ x = L_shl( x, exp_e );
+ exp = L_deposit_l( exp_e );
+
+ /* calculate (1-normalized_input) */
+ nIn = extract_h( L_sub( MAX_32, x ) );
+
+ /* approximate ln() for fractional part (nIn *c0 + nIn^2*c1 + nIn^3*c2 + ... + nIn^8 *c7) */
+
+ /* iteration 1, no need for accumulation */
+ accuRes = L_mult( nIn, ldCoeff[0] ); /* nIn^i * coeff[0] */
+ accuSqr = mult( nIn, nIn ); /* nIn^2, nIn^3 .... */
+
+ /* iteration 2 */
+ accuRes = L_mac( accuRes, accuSqr, ldCoeff[1] ); /* nIn^i * coeff[1] */
+ accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */
+
+ /* iteration 3 */
+ accuRes = L_mac( accuRes, accuSqr, ldCoeff[2] ); /* nIn^i * coeff[2] */
+ accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */
+
+ /* iteration 4 */
+ accuRes = L_mac( accuRes, accuSqr, ldCoeff[3] ); /* nIn^i * coeff[3] */
+ accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */
+
+ /* iteration 5 */
+ accuRes = L_mac( accuRes, accuSqr, ldCoeff[4] ); /* nIn^i * coeff[4] */
+ accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */
+
+ /* iteration 6 */
+ accuRes = L_mac( accuRes, accuSqr, ldCoeff[5] ); /* nIn^i * coeff[5] */
+ accuSqr = mult( accuSqr, nIn ); /* nIn^2, nIn^3 .... */
+
+ /* iteration 7, no need to calculate accuSqr any more */
+ accuRes = L_mac( accuRes, accuSqr, ldCoeff[6] ); /* nIn^i * coeff[6] */
+
+ /* ld(fractional part) = ln(fractional part)/ln(2), 1/ln(2) = (1 + 0.44269504) */
+ accuRes = L_mac0( L_shr( accuRes, 1 ), extract_h( accuRes ), 14506 );
+
+ accuRes = L_shr( accuRes, LD_DATA_SCALE - 1 ); /* fractional part/LD_DATA_SCALE */
+ exp = L_shl( exp, ( 31 - LD_DATA_SCALE ) ); /* integer part/LD_DATA_SCALE */
+ accuRes = L_sub( accuRes, exp ); /* result = integer part + fractional part */
+
+ return ( accuRes );
+}
+
+
+Word32 BASOP_Util_InvLog2(
+ Word32 x )
+{
+ Word16 frac;
+ Word16 exp;
+ Word32 retVal;
+ UWord32 index3;
+ UWord32 index2;
+ UWord32 index1;
+ UWord32 lookup3f;
+ UWord32 lookup12;
+ UWord32 lookup;
+
+ if ( x < FL2WORD32( -31.0 / 64.0 ) )
+ {
+ return 0;
+ }
+ test();
+ if ( ( L_sub( x, FL2WORD32( 31.0 / 64.0 ) ) >= 0 ) || ( x == 0 ) )
+ {
+ return 0x7FFFFFFF;
+ }
+
+ frac = extract_l( L_and( x, 0x3FF ) );
+
+ index3 = L_and( L_shr( x, 10 ), 0x1F );
+ index2 = L_and( L_shr( x, 15 ), 0x1F );
+ index1 = L_and( L_shr( x, 20 ), 0x1F );
+
+ exp = extract_l( L_shr( x, 25 ) );
+ if ( x > 0 )
+ {
+ exp = sub( 31, exp );
+ }
+ if ( x < 0 )
+ {
+ exp = negate( exp );
+ }
+
+ lookup3f = L_add( exp2x_tab_long[index3], L_shr( Mpy_32_16( 0x0016302F, frac ), 1 ) );
+ lookup12 = Mpy_32_32( exp2_tab_long[index1], exp2w_tab_long[index2] );
+ lookup = Mpy_32_32( lookup12, lookup3f );
+
+ retVal = L_shr( lookup, sub( exp, 3 ) );
+
+ return retVal;
+}
+
+
+Word16 BASOP_Util_Add_MantExp /*!< Exponent of result */
+ ( Word16 a_m, /*!< Mantissa of 1st operand a */
+ Word16 a_e, /*!< Exponent of 1st operand a */
+ Word16 b_m, /*!< Mantissa of 2nd operand b */
+ Word16 b_e, /*!< Exponent of 2nd operand b */
+ Word16 *ptrSum_m ) /*!< Mantissa of result */
+{
+ Word32 L_lm, L_hm;
+ Word16 shift;
+
+ /* Compare exponents: the difference is limited to +/- 15
+ The Word16 mantissa of the operand with higher exponent is moved into the low
+ part of a Word32 and shifted left by the exponent difference. Then, the
+ unshifted mantissa of the operand with the lower exponent is added to the lower
+ 16 bits. The addition result is normalized and the upper Word16 of the result represents
+ the mantissa to return. The returned exponent takes into account all shift operations
+ including the final 16-bit extraction.
+ Note: The resulting mantissa may be inaccurate in the case, where the mantissa of the operand
+ with higher exponent is not really left-aligned, while the mantissa of the operand with
+ lower exponent is so. If in such a case, the difference in exponents is more than 15,
+ an inaccuracy is introduced.
+ Example:
+ A: a_e = 20, a_m = 0x0001
+ B: b_e = 0, b_m = 0x4000
+ correct: A+B=1*2^20+1*2^14=0x0010.0000+0x0000.4000=0x0010.4000=0x4100*2^6
+ previously: A+B=1*2^20+1*2^14=0x0001+0x0000=0x0001*2^20
+ this version: A+B=1*2^20+1*2^14=0x0000.8000+0x0000.4000=0x6000*2^6
+ */
+
+ shift = sub( a_e, b_e );
+ if ( shift >= 0 )
+ shift = s_min( 15, shift );
+
+ if ( shift < 0 )
+ shift = s_max( -15, shift );
+ a_e = s_max( a_e, b_e );
+ L_hm = L_deposit_l( a_m ); /* mantissa belonging to higher exponent */
+ L_lm = L_deposit_l( a_m ); /* mantissa belonging to lower exponent */
+ if ( shift >= 0 )
+ L_lm = L_deposit_l( b_m );
+ if ( shift < 0 )
+ L_hm = L_deposit_l( b_m );
+
+ if ( shift > 0 )
+ shift = negate( shift );
+
+ L_hm = L_shr( L_hm, shift ); /* shift left due to negative shift parameter */
+ a_e = add( a_e, shift );
+ L_hm = L_add( L_hm, L_lm );
+ shift = norm_l( L_hm );
+ L_hm = L_shl( L_hm, shift );
+ *ptrSum_m = extract_h( L_hm );
+ move16();
+
+ a_e = sub( a_e, shift );
+ if ( L_hm )
+ a_e = add( a_e, 16 );
+
+ return ( a_e );
+}
+
+
+/* local function for Sqrt16 */
+static Word16 Sqrt16_common(
+ Word16 m,
+ Word16 e )
+{
+ Word16 index, frac;
+#ifdef BASOP_NOGLOB
+ Flag Overflow;
+#endif /* BASOP_NOGLOB */
+
+ assert( ( m >= 0x4000 ) || ( m == 0 ) );
+
+ /* get table index (upper 6 bits minus 32) */
+ /* index = (m >> 9) - 32; */
+ index = mac_r( -32768 - ( 32 << 16 ), m, 1 << 6 );
+
+ /* get fractional part for interpolation (lower 9 bits) */
+ frac = s_and( m, 0x1FF ); /* Q9 */
+
+ /* interpolate */
+ if ( m != 0 )
+ {
+ BASOP_SATURATE_WARNING_OFF;
+#ifndef BASOP_NOGLOB
+ m = mac_r( SqrtTable[index], SqrtDiffTable[index], frac );
+#else /* BASOP_NOGLOB */
+ m = mac_ro( SqrtTable[index], SqrtDiffTable[index], frac, &Overflow );
+#endif /* BASOP_NOGLOB */
+ BASOP_SATURATE_WARNING_ON;
+ }
+
+ /* handle odd exponents */
+ if ( s_and( e, 1 ) != 0 )
+ m = mult_r( m, 0x5a82 );
+
+ return m;
+}
+
+
+Word16 Sqrt16( /*!< output mantissa */
+ Word16 mantissa, /*!< input mantissa */
+ Word16 *exponent /*!< pointer to exponent */
+)
+{
+ Word16 preShift, e;
+
+ assert( mantissa >= 0 );
+
+ /* normalize */
+ preShift = norm_s( mantissa );
+
+ e = sub( *exponent, preShift );
+ mantissa = shl( mantissa, preShift );
+
+ /* calc mantissa */
+ mantissa = Sqrt16_common( mantissa, e );
+
+ /* e = (e + 1) >> 1 */
+ *exponent = mult_r( e, 1 << 14 );
+ move16();
+
+ return mantissa;
+}
+
+Word16 Inv16( /*!< output mantissa */
+ Word16 mantissa, /*!< input mantissa */
+ Word16 *exponent /*!< pointer to exponent */
+)
+{
+ Word16 index, frac;
+ Word16 preShift;
+ Word16 m, e;
+
+ assert( mantissa != 0 );
+
+ /* absolute */
+ BASOP_SATURATE_WARNING_OFF;
+ m = abs_s( mantissa );
+ BASOP_SATURATE_WARNING_ON;
+
+ /* normalize */
+ preShift = norm_s( m );
+
+ e = sub( *exponent, preShift );
+ m = shl( m, preShift );
+
+ /* get table index (upper 6 bits minus 32) */
+ /* index = (m >> 9) - 32; */
+ index = mac_r( -32768 - ( 32 << 16 ), m, 1 << 6 );
+
+ /* get fractional part for interpolation (lower 9 bits) */
+ frac = shl( s_and( m, 0x1FF ), 1 ); /* Q10 */
+
+ /* interpolate */
+ m = msu_r( InvTable[index], InvDiffTable[index], frac );
+
+ /* restore sign */
+ if ( mantissa < 0 )
+ m = negate( m );
+
+ /* e = 1 - e */
+ *exponent = sub( 1, e );
+ move16();
+
+ return m;
+}
+
+
+void BASOP_Util_Sqrt_InvSqrt_MantExp(
+ Word16 mantissa, /*!< mantissa */
+ Word16 exponent, /*!< expoinent */
+ Word16 *sqrt_mant, /*!< Pointer to sqrt mantissa */
+ Word16 *sqrt_exp, /*!< Pointer to sqrt exponent */
+ Word16 *isqrt_mant, /*!< Pointer to 1/sqrt mantissa */
+ Word16 *isqrt_exp /*!< Pointer to 1/sqrt exponent */
+)
+{
+ Word16 index, frac;
+ Word16 preShift;
+ Word16 m, mi, e_odd;
+
+ assert( mantissa > 0 );
+
+ /* normalize */
+ preShift = norm_s( mantissa );
+
+ exponent = sub( exponent, preShift );
+ mantissa = shl( mantissa, preShift );
+
+ /* get table index (upper 6 bits minus 32) */
+ /* index = (m >> 9) - 32; */
+ index = mac_r( -32768 - ( 32 << 16 ), mantissa, 1 << 6 );
+
+ /* get fractional part for interpolation (lower 9 bits) */
+ frac = s_and( mantissa, 0x1FF ); /* Q9 */
+
+ /* interpolate */
+ BASOP_SATURATE_WARNING_OFF;
+ m = mac_r( SqrtTable[index], SqrtDiffTable[index], frac );
+ mi = msu_r( ISqrtTable[index], ISqrtDiffTable[index], frac );
+ BASOP_SATURATE_WARNING_ON;
+
+ /* handle even/odd exponents */
+ e_odd = s_and( exponent, 1 );
+ if ( e_odd != 0 )
+ m = mult_r( m, 0x5a82 );
+ if ( e_odd == 0 )
+ mi = mult_r( mi, 0x5a82 );
+
+ /* e = (e + 1) >> 1 */
+ *sqrt_exp = mult_r( exponent, 1 << 14 );
+ move16();
+
+ /* e = (2 - e) >> 1 */
+ *isqrt_exp = msu_r( 1L << 15, exponent, 1 << 14 );
+ move16();
+
+ /* Write result */
+ *sqrt_mant = m;
+ move16();
+ *isqrt_mant = mi;
+ move16();
+}
+
+/********************************************************************/
+/*!
+ \brief Calculates the scalefactor needed to normalize input array
+
+ The scalefactor needed to normalize the Word32 input array is returned
+ If the input array contains only '0', a scalefactor 0 is returned
+ Scaling factor is determined wrt a normalized target x: 1073741824 <= x <= 2147483647 for positive x
+ and -2147483648 <= x <= -1073741824 for negative x
+*/
+
+/*! r: measured headroom in range [0..31], 0 if all x[i] == 0 */
+Word16 getScaleFactor32(
+ const Word32 *x, /* i : array containing 32-bit data */
+ const Word16 len_x ) /* i : length of the array to scan */
+{
+ Word16 i, i_min, i_max;
+ Word32 x_min, x_max;
+
+ x_max = L_add( 0, 0 );
+ x_min = L_add( 0, 0 );
+ FOR( i = 0; i < len_x; i++ )
+ {
+ if ( x[i] >= 0 )
+ x_max = L_max( x_max, x[i] );
+ if ( x[i] < 0 )
+ x_min = L_min( x_min, x[i] );
+ }
+
+ i_max = 0x20;
+ move16();
+ i_min = 0x20;
+ move16();
+
+ if ( x_max != 0 )
+ i_max = norm_l( x_max );
+
+ if ( x_min != 0 )
+ i_min = norm_l( x_min );
+
+ i = s_and( s_min( i_max, i_min ), 0x1F );
+
+ return i;
+}
+
+
+Word16 BASOP_Util_Divide1616_Scale(
+ Word16 x,
+ Word16 y,
+ Word16 *s )
+{
+ Word16 z;
+ Word16 sx;
+ Word16 sy;
+ Word16 sign;
+
+ /* assert (x >= (Word16)0); */
+ assert( y != (Word16) 0 );
+
+ sign = 0;
+ move16();
+
+ IF( x < 0 )
+ {
+ x = negate( x );
+ sign = s_xor( sign, 1 );
+ }
+
+ IF( y < 0 )
+ {
+ y = negate( y );
+ sign = s_xor( sign, 1 );
+ }
+
+ IF( x == (Word16) 0 )
+ {
+ move16();
+ *s = 0;
+
+ return ( (Word16) 0 );
+ }
+
+ sx = norm_s( x );
+ x = shl( x, sx );
+ x = shr( x, 1 );
+ move16();
+ *s = sub( 1, sx );
+
+ sy = norm_s( y );
+ y = shl( y, sy );
+ move16();
+ *s = add( *s, sy );
+
+ z = div_s( x, y );
+
+ if ( sign != 0 )
+ {
+ z = negate( z );
+ }
+
+ return z;
+}
+
+
+void set_val_Word16(
+ Word16 X[],
+ const Word16 val,
+ Word16 n )
+{
+ Word16 i;
+
+
+ FOR( i = 0; i < n; i++ )
+ {
+ X[i] = val;
+ move16();
+ }
+
+
+ return;
+}
+
+void set_val_Word32(
+ Word32 X[],
+ const Word32 val,
+ Word16 n )
+{
+ Word16 i;
+
+
+ FOR( i = 0; i < n; i++ )
+ {
+ X[i] = val;
+ move32();
+ }
+
+
+ return;
+}
+
+Word16 mult0(
+ Word16 x,
+ Word16 y )
+{
+ return extract_l( L_mult0( x, y ) );
+}
+
+
+#define SINETAB SineTable512_fx
+#define LD 9
+
+/*
+ * Calculates coarse lookup values for sine/cosine and residual angle.
+ * \param x angle in radians with exponent = 2 or as radix 2 with exponent = 0.
+ * \param scale shall always be 2
+ * \param sine pointer to where the sine lookup value is stored into
+ * \param cosine pointer to where the cosine lookup value is stored into
+ * \param flag_radix2 flag indicating radix 2 angle if non-zero.
+ */
+static Word16 fixp_sin_cos_residual_16(
+ Word16 x,
+ const Word16 scale,
+ Word16 *sine,
+ Word16 *cosine,
+ Word8 flag_radix2 )
+{
+ Word16 residual;
+ Word16 s;
+ Word16 ssign;
+ Word16 csign;
+ Word16 tmp, cl = 0, sl = 0;
+ const Word16 shift = 15 - LD - 1 - scale;
+
+ if ( flag_radix2 == 0 )
+ {
+ x = mult_r( x, FL2WORD16( 1.0 / EVS_PI ) );
+ }
+ s = shr( x, shift );
+
+ residual = s_and( x, ( 1 << shift ) - 1 );
+ /* We assume "2+scale" is a constant */
+ residual = shl( residual, 2 + scale );
+ residual = mult_r( residual, FL2WORD16( EVS_PI / 4.0 ) );
+
+ /* Sine sign symmetry */
+ ssign = s_and( s, ( 1 << LD ) << 1 );
+
+ /* Cosine sign symmetry */
+ csign = s_and( add( s, ( 1 << LD ) ), ( 1 << LD ) << 1 );
+
+ /* Modulo EVS_PI */
+ s = s_and( s, ( 2 << LD ) - 1 );
+
+ /* EVS_PI/2 symmetry */
+ s = s_min( s, sub( 2 << LD, s ) );
+
+ {
+ tmp = s_min( sub( 1 << LD, s ), s );
+ s = sub( tmp, s );
+
+ if ( !s )
+ {
+ move16();
+ sl = SINETAB[tmp].v.im;
+ }
+ if ( !s )
+ {
+ move16();
+ cl = SINETAB[tmp].v.re;
+ }
+ if ( s )
+ {
+ move16();
+ sl = SINETAB[tmp].v.re;
+ }
+ if ( s )
+ {
+ move16();
+ cl = SINETAB[tmp].v.im;
+ }
+
+ if ( ssign )
+ {
+ sl = negate( sl );
+ }
+ if ( csign )
+ {
+ cl = negate( cl );
+ }
+
+ move16();
+ move16();
+ *sine = sl;
+ *cosine = cl;
+ }
+
+ return residual;
+}
+
+
+Word16 getCosWord16R2(
+ Word16 theta )
+{
+ Word16 result, residual, sine, cosine;
+
+ residual = fixp_sin_cos_residual_16( theta, 1, &sine, &cosine, 1 );
+ /* This negation prevents the subsequent addition from overflow */
+ /* The negation cannot overflow, sine is in range [0x0..0x7FFF] */
+ BASOP_SATURATE_WARNING_OFF
+ sine = negate( sine );
+ result = msu_r( L_mult( sine, residual ), cosine, -32768 );
+ BASOP_SATURATE_WARNING_ON
+
+ return result;
+}
+
+
+Word16 idiv1616U(
+ Word16 x,
+ Word16 y )
+{
+ Word16 s;
+ Word16 tmp;
+
+ /* make y > x */
+ s = add( sub( norm_s( y ), norm_s( x ) ), 1 );
+ s = s_max( s, 0 );
+
+ BASOP_SATURATE_WARNING_OFF
+ y = shl( y, s );
+ BASOP_SATURATE_WARNING_ON
+
+ /* divide and shift */
+ tmp = div_s( x, y );
+ y = shr( tmp, sub( 15, s ) );
+
+ return y;
+}
+
+Word32 BASOP_util_Pow2(
+ const Word32 exp_m,
+ const Word16 exp_e,
+ Word16 *result_e )
+{
+ static const Word16 pow2Coeff[8] = {
+ FL2WORD16( 0.693147180559945309417232121458177 ), /* ln(2)^1 /1! */
+ FL2WORD16( 0.240226506959100712333551263163332 ), /* ln(2)^2 /2! */
+ FL2WORD16( 0.0555041086648215799531422637686218 ), /* ln(2)^3 /3! */
+ FL2WORD16( 0.00961812910762847716197907157365887 ), /* ln(2)^4 /4! */
+ FL2WORD16( 0.00133335581464284434234122219879962 ), /* ln(2)^5 /5! */
+ FL2WORD16( 1.54035303933816099544370973327423e-4 ), /* ln(2)^6 /6! */
+ FL2WORD16( 1.52527338040598402800254390120096e-5 ), /* ln(2)^7 /7! */
+ FL2WORD16( 1.32154867901443094884037582282884e-6 ) /* ln(2)^8 /8! */
+ };
+
+ Word32 frac_part = 0, tmp_frac, result_m;
+ Word16 int_part = 0;
+
+ IF( exp_e > 0 )
+ {
+ /* "+ 1" compensates L_shr(,1) of the polynomial evaluation at the loop end. */
+
+ int_part = add( 1, extract_l( L_shr( exp_m, sub( 31, exp_e ) ) ) );
+ frac_part = L_lshl( exp_m, exp_e );
+ frac_part = L_and( 0x7FFFFFFF, frac_part );
+ }
+ if ( exp_e <= 0 )
+ frac_part = L_shl( exp_m, exp_e );
+ if ( exp_e <= 0 )
+ {
+ int_part = 1;
+ move16();
+ }
+
+ /* Best accuracy is around 0, so try to get there with the fractional part. */
+ IF( ( tmp_frac = L_sub( frac_part, FL2WORD32( 0.5 ) ) ) >= 0 )
+ {
+ int_part = add( int_part, 1 );
+ frac_part = L_sub( tmp_frac, FL2WORD32( 0.5 ) );
+ }
+ ELSE IF( ( tmp_frac = L_add( frac_part, FL2WORD32( 0.5 ) ) ) < 0 )
+ {
+ int_part = sub( int_part, 1 );
+ frac_part = L_add( tmp_frac, FL2WORD32( 0.5 ) );
+ }
+
+ /* Evaluate taylor polynomial which approximates 2^x */
+ {
+ Word32 p;
+ Word16 i;
+
+
+ /* First taylor series coefficient a_0 = 1.0, scaled by 0.5 due to L_shr(,1). */
+ result_m = L_add( FL2WORD32( 1.0 / 2.0 ), L_shr( Mpy_32_16( frac_part, pow2Coeff[0] ), 1 ) );
+ p = Mpy_32_32( frac_part, frac_part );
+ FOR( i = 1; i < 7; i++ )
+ {
+ /* next taylor series term: a_i * x^i, x=0 */
+ result_m = L_add( result_m, L_shr( Mpy_32_16( p, pow2Coeff[i] ), 1 ) );
+ p = Mpy_32_32( p, frac_part );
+ }
+ result_m = L_add( result_m, L_shr( Mpy_32_16( p, pow2Coeff[i] ), 1 ) );
+ }
+ *result_e = int_part;
+ move16();
+
+ return result_m;
+}
+
+/*! r: result of division x/y, not normalized */
+Word16 BASOP_Util_Divide3216_Scale(
+ Word32 x, /* i : numerator, signed */
+ Word16 y, /* i : denominator, signed */
+ Word16 *s ) /* o : scaling, 0, if x==0 */
+{
+ Word16 z;
+ Word16 sx;
+ Word16 sy;
+ Word16 sign;
+
+ /*assert (x > (Word32)0);
+ assert (y >= (Word16)0);*/
+
+ /* check, if numerator equals zero, return zero then */
+ IF( x == (Word32) 0 )
+ {
+ *s = 0;
+ move16();
+
+ return ( (Word16) 0 );
+ }
+
+ sign = s_xor( extract_h( x ), y ); /* just to exor the sign bits */
+ BASOP_SATURATE_WARNING_OFF
+ x = L_abs( x );
+ y = abs_s( y );
+ BASOP_SATURATE_WARNING_ON
+ sx = sub( norm_l( x ), 1 );
+ x = L_shl( x, sx );
+ sy = norm_s( y );
+ y = shl( y, sy );
+ *s = sub( sy, sx );
+ move16();
+
+ z = div_s( round_fx( x ), y );
+
+ if ( sign < 0 ) /* if sign bits differ, negate the result */
+ {
+ z = negate( z );
+ }
+
+ return z;
+}
+
+
+static const Word16 table_pow2[32] = {
+ 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911,
+ 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726,
+ 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706,
+ 31379, 32066
+};
+/* table of table_pow2[i+1] - table_pow2[i] */
+static const Word16 table_pow2_diff_x32[32] = {
+ 11488, 11712, 12000, 12256, 12512, 12800, 13056, 13376, 13664, 13952,
+ 14240, 14560, 14912, 15200, 15552, 15872, 16256, 16576, 16960, 17344,
+ 17696, 18080, 18496, 18880, 19328, 19712, 20192, 20576, 21056, 21536,
+ 21984, 22432
+};
+
+Word32 Pow2( /* o Q0 : result (range: 0<=val<=0x7fffffff) */
+ Word16 exponant, /* i Q0 : Integer part. (range: 0<=val<=30) */
+ Word16 fraction /* i Q15 : Fractional part. (range: 0.0<=val<1.0) */
+)
+{
+ Word16 exp, i, a;
+ Word32 L_x;
+
+ i = mac_r( -32768, fraction, 32 ); /* Extract b10-b16 of fraction */
+ a = s_and( fraction, 0x3ff ); /* Extract b0-b9 of fraction */
+
+ L_x = L_deposit_h( table_pow2[i] ); /* table[i] << 16 */
+ L_x = L_mac( L_x, table_pow2_diff_x32[i], a ); /* L_x -= diff*a*2 */
+
+ exp = sub( 30, exponant );
+
+ L_x = L_shr_r( L_x, exp );
+
+ return L_x;
+}
+
+/*************************************************************************
+ *
+ * FUNCTION: Log2_norm()
+ *
+ * PURPOSE: Computes log2(L_x, exp), where L_x is positive and
+ * normalized, and exp is the normalisation exponent
+ * If L_x is negative or zero, the result is 0.
+ *
+ * DESCRIPTION:
+ * The function Log2(L_x) is approximated by a table and linear
+ * interpolation. The following steps are used to compute Log2(L_x)
+ *
+ * 1- exponent = 30-norm_exponent
+ * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization).
+ * 3- a = bit10-b24
+ * 4- i -=32
+ * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ *
+ *************************************************************************/
+
+static const Word32 L_table[32] = {
+ -32768L, 95322112L, 187793408L, 277577728L,
+ 364871680L, 449740800L, 532381696L, 612859904L,
+ 691306496L, 767787008L, 842432512L, 915308544L,
+ 986546176L, 1056210944L, 1124302848L, 1190887424L,
+ 1256095744L, 1319993344L, 1382580224L, 1443921920L,
+ 1504083968L, 1563131904L, 1621000192L, 1677885440L,
+ 1733722112L, 1788510208L, 1842380800L, 1895399424L,
+ 1947435008L, 1998618624L, 2049015808L, 2098626560L
+};
+
+static const Word16 table_diff[32] = {
+ 1455, 1411, 1370, 1332, 1295, 1261, 1228, 1197,
+ 1167, 1139, 1112, 1087, 1063, 1039, 1016, 995,
+ 975, 955, 936, 918, 901, 883, 868, 852,
+ 836, 822, 809, 794, 781, 769, 757, 744
+};
+
+Word16 Log2_norm_lc( /* o : Fractional part of Log2. (range: 0<=val<1) */
+ Word32 L_x /* i : input value (normalized) */
+)
+{
+ Word16 i, a;
+ Word16 y;
+
+
+ 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 */
+
+ y = mac_r( L_table[i], table_diff[i], a ); /* table[i] << 16 - diff*a*2 */
+
+
+ return y;
+}
+
+
+Word32 BASOP_Util_fPow(
+ Word32 base_m,
+ Word16 base_e,
+ Word32 exp_m,
+ Word16 exp_e,
+ Word16 *result_e )
+{
+
+ Word16 ans_lg2_e, base_lg2_e;
+ Word32 base_lg2_m, ans_lg2_m, result_m;
+ Word16 shift;
+
+ test();
+ IF( ( base_m == 0 ) && ( exp_m != 0 ) )
+ {
+ *result_e = 0;
+ move16();
+ return 0;
+ }
+ /* Calc log2 of base */
+ shift = norm_l( base_m );
+ base_m = L_shl( base_m, shift );
+ base_e = sub( base_e, shift );
+ base_lg2_m = BASOP_Util_Log2( base_m );
+
+ /* shift: max left shift such that neither base_e or base_lg2_m saturate. */
+ shift = sub( s_min( norm_s( base_e ), WORD16_BITS - 1 - LD_DATA_SCALE ), 1 );
+ /* Compensate shift into exponent of result. */
+ base_lg2_e = sub( WORD16_BITS - 1, shift );
+ base_lg2_m = L_add( L_shr( base_lg2_m, sub( WORD16_BITS - 1 - LD_DATA_SCALE, shift ) ), L_deposit_h( shl( base_e, shift ) ) );
+
+ /* Prepare exp */
+ shift = norm_l( exp_m );
+ exp_m = L_shl( exp_m, shift );
+ exp_e = sub( exp_e, shift );
+
+ /* Calc base pow exp */
+ ans_lg2_m = Mpy_32_32( base_lg2_m, exp_m );
+ ans_lg2_e = add( exp_e, base_lg2_e );
+
+ /* Calc antilog */
+ result_m = BASOP_util_Pow2( ans_lg2_m, ans_lg2_e, result_e );
+
+ return result_m;
+}
+
+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 = add( b_e, 0 );
+
+ if ( !b_m )
+ b_e = add( a_e, 0 );
+
+ 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 = add( 0, 0 );
+ if ( L_tmp != 0 )
+ a_e = sub( a_e, shift );
+ *ptr_e = a_e;
+
+ return ( L_tmp );
+}
+
+static const Word32 L_table_isqrt[48] = {
+ 2147418112L, 2083389440L, 2024669184L, 1970667520L,
+ 1920794624L, 1874460672L, 1831403520L, 1791098880L,
+ 1753415680L, 1717960704L, 1684602880L, 1653145600L,
+ 1623326720L, 1595080704L, 1568276480L, 1542782976L,
+ 1518469120L, 1495334912L, 1473183744L, 1451950080L,
+ 1431633920L, 1412169728L, 1393491968L, 1375469568L,
+ 1358168064L, 1341521920L, 1325465600L, 1309933568L,
+ 1294991360L, 1280507904L, 1266548736L, 1252982784L,
+ 1239875584L, 1227161600L, 1214775296L, 1202847744L,
+ 1191182336L, 1179910144L, 1168965632L, 1158283264L,
+ 1147863040L, 1137770496L, 1127940096L, 1118306304L,
+ 1108934656L, 1099825152L, 1090912256L, 1082261504L
+};
+/* table of table_isqrt[i] - table_isqrt[i+1] */
+static const Word16 table_isqrt_diff[48] = {
+ 977, 896, 824, 761, 707, 657, 615, 575,
+ 541, 509, 480, 455, 431, 409, 389, 371,
+ 353, 338, 324, 310, 297, 285, 275, 264,
+ 254, 245, 237, 228, 221, 213, 207, 200,
+ 194, 189, 182, 178, 172, 167, 163, 159,
+ 154, 150, 147, 143, 139, 136, 132, 130
+};
+
+static const Word16 shift[] = { 9, 10 };
+
+Word32 Isqrt_lc1(
+ Word32 frac, /* i : Q31: normalized value (1.0 < frac <= 0.5) */
+ Word16 *exp /* i/o: exponent (value = frac x 2^exponent) */
+)
+{
+ Word16 i, a;
+ Word32 L_tmp;
+
+ IF( frac <= (Word32) 0 )
+ {
+ *exp = 0;
+ move16();
+ return 0x7fffffff; /*0x7fffffff*/
+ }
+
+ /* If exponant odd -> shift right by 10 (otherwise 9) */
+ L_tmp = L_shr( frac, shift[s_and( *exp, 1 )] );
+
+ /* 1) -16384 to shift left and change sign */
+ /* 2) 32768 to Add 1 to Exponent like it was divided by 2 */
+ /* 3) We let the mac_r add another 0.5 because it imitates */
+ /* the behavior of shr on negative number that should */
+ /* not be rounded towards negative infinity. */
+ /* It replaces: */
+ /* *exp = negate(shr(sub(*exp, 1), 1)); move16(); */
+ *exp = mac_r( 32768, *exp, -16384 );
+ move16();
+
+ a = extract_l( L_tmp ); /* Extract b10-b24 */
+ a = lshr( a, 1 );
+
+ i = mac_r( L_tmp, -16 * 2 - 1, 16384 ); /* Extract b25-b31 minus 16 */
+
+ L_tmp = L_msu( L_table_isqrt[i], table_isqrt_diff[i], a ); /* table[i] << 16 - diff*a*2 */
+
+ return L_tmp;
+}
+
+static const Word16 sqrt_table[49] = {
+ 16384, 16888, 17378, 17854, 18318, 18770, 19212,
+ 19644, 20066, 20480, 20886, 21283, 21674, 22058,
+ 22435, 22806, 23170, 23530, 23884, 24232, 24576,
+ 24915, 25249, 25580, 25905, 26227, 26545, 26859,
+ 27170, 27477, 27780, 28081, 28378, 28672, 28963,
+ 29251, 29537, 29819, 30099, 30377, 30652, 30924,
+ 31194, 31462, 31727, 31991, 32252, 32511, 32767
+};
+
+/*! r: output value, Q31 */
+Word32 Sqrt_l(
+ Word32 L_x, /* i : input value, Q31 */
+ Word16 *exp /* o : right shift to be applied to result, Q1 */
+)
+{
+ /*
+ y = sqrt(x)
+
+ x = f * 2^-e, 0.5 <= f < 1 (normalization)
+
+ y = sqrt(f) * 2^(-e/2)
+
+ a) e = 2k --> y = sqrt(f) * 2^-k (k = e div 2,
+ 0.707 <= sqrt(f) < 1)
+ b) e = 2k+1 --> y = sqrt(f/2) * 2^-k (k = e div 2,
+ 0.5 <= sqrt(f/2) < 0.707)
+ */
+
+ Word16 e, i, a, tmp;
+ Word32 L_y;
+
+ if ( L_x <= 0 )
+ {
+ *exp = 0;
+ move16();
+ return L_deposit_l( 0 );
+ }
+
+#if 0 /* original version creates an overflow warning */
+ e = s_and(norm_l(L_x), 0xFFFE); /* get next lower EVEN norm. exp */
+#else
+ e = s_and( norm_l( L_x ), 0x7FFE ); /* get next lower EVEN norm. exp */
+#endif
+ L_x = L_shl( L_x, e ); /* L_x is normalized to [0.25..1) */
+ *exp = e;
+ move16(); /* return 2*exponent (or Q1) */
+
+ L_x = L_shr( L_x, 9 );
+ a = extract_l( L_x ); /* Extract b10-b24 */
+ a = lshr( a, 1 );
+
+ i = mac_r( L_x, -16 * 2 - 1, 16384 ); /* Extract b25-b31 minus 16 */
+
+ L_y = L_deposit_h( sqrt_table[i] ); /* table[i] << 16 */
+ tmp = sub( sqrt_table[i], sqrt_table[i + 1] ); /* table[i] - table[i+1]) */
+ L_y = L_msu( L_y, tmp, a ); /* L_y -= tmp*a*2 */
+
+ /* L_y = L_shr (L_y, *exp); */ /* denormalization done by caller */
+
+ return ( L_y );
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..c09b8ea62ca4e8321ef2227978afb9df7aac680d
--- /dev/null
+++ b/lib_com/basop_util.h
@@ -0,0 +1,418 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 __BASOP_UTIL_H__
+#define __BASOP_UTIL_H__
+
+#include
+#include "options.h"
+#include "basop_settings.h"
+#include "typedef.h"
+#include "basop32.h"
+#include "basop_mpy.h"
+
+
+#define LD_DATA_SCALE ( 6 )
+
+#define LD_DATA_SHIFT_I5 ( 7 )
+
+#define modDiv2( x ) sub( x, shl( shr( x, 1 ), 1 ) )
+#define modDiv8( x ) L_sub( x, L_shl( L_shr( x, 3 ), 3 ) )
+
+#ifndef CHEAP_NORM_SIZE
+#define CHEAP_NORM_SIZE 161
+#endif
+
+static __inline Word16 limitScale16( Word16 s )
+{
+ /* It is assumed, that s is calculated just before, therefore we can switch upon sign */
+ if ( s >= 0 )
+ s = s_min( s, WORD16_BITS - 1 );
+ if ( s < 0 )
+ s = s_max( s, 1 - WORD16_BITS );
+ return ( s );
+}
+
+static __inline Word16 limitScale32( Word16 s )
+{
+ /* It is assumed, that s is calculated just before, therefore we can switch upon sign */
+ if ( s >= 0 )
+ s = s_min( s, WORD32_BITS - 1 );
+ if ( s < 0 )
+ s = s_max( s, 1 - WORD32_BITS );
+ return ( s );
+}
+
+
+/*!**********************************************************************
+ \brief Add two values given by mantissa and exponent.
+
+ Mantissas are in 16-bit-fractional format with values between 0 and 1.
+ The base for exponents is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$
+
+************************************************************************/
+Word16 BASOP_Util_Add_MantExp /*!< Exponent of result */
+ ( Word16 a_m, /*!< Mantissa of 1st operand a */
+ Word16 a_e, /*!< Exponent of 1st operand a */
+ Word16 b_m, /*!< Mantissa of 2nd operand b */
+ Word16 b_e, /*!< Exponent of 2nd operand b */
+ Word16 *ptrSum_m ); /*!< Mantissa of result */
+
+
+/************************************************************************/
+/*!
+ \brief Calculate the squareroot of a number given by mantissa and exponent
+
+ Mantissa is in 16/32-bit-fractional format with values between 0 and 1.
+ For *norm versions mantissa has to be between 0.5 and 1.
+ The base for the exponent is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$
+ The exponent is addressed via pointers and will be overwritten with the result.
+*/
+Word16 Sqrt16( /*!< output mantissa */
+ Word16 mantissa, /*!< input mantissa */
+ Word16 *exponent /*!< pointer to exponent */
+);
+
+/*****************************************************************************/
+/*!
+ \brief Calculate the inverse of a number given by mantissa and exponent
+
+ Mantissa is in 16-bit-fractional format with values between 0 and 1.
+ The base for the exponent is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$
+ The operand is addressed via pointers and will be overwritten with the result.
+
+ The function uses a table lookup and a newton iteration.
+*/
+Word16 Inv16( /*!< output mantissa */
+ Word16 mantissa, /*!< input mantissa */
+ Word16 *exponent /*!< pointer to exponent */
+);
+
+/******************************************************************************/
+/*!
+ \brief Calculate the squareroot and inverse of squareroot of a number given by mantissa and exponent
+
+ Mantissa is in 16-bit-fractional format with values between 0 and 1.
+ The base for the exponent is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$
+*/
+void BASOP_Util_Sqrt_InvSqrt_MantExp( Word16 mantissa, /*!< mantissa */
+ Word16 exponent, /*!< expoinent */
+ Word16 *sqrt_mant, /*!< Pointer to sqrt mantissa */
+ Word16 *sqrt_exp, /*!< Pointer to sqrt exponent */
+ Word16 *isqrt_mant, /*!< Pointer to 1/sqrt mantissa */
+ Word16 *isqrt_exp /*!< Pointer to 1/sqrt exponent */
+);
+
+
+/********************************************************************/
+/*!
+ \brief Calculates the scalefactor needed to normalize input array
+
+ The scalefactor needed to normalize the Word32 input array is returned
+ If the input array contains only '0', a scalefactor 0 is returned
+ Scaling factor is determined wrt a normalized target x: 1073741824 <= x <= 2147483647 for positive x
+ and -2147483648 <= x <= -1073741824 for negative x
+*/
+
+/*! r: measured headroom in range [0..31], 0 if all x[i] == 0 */
+Word16 getScaleFactor32(
+ const Word32 *x, /* i : array containing 32-bit data */
+ const Word16 len_x ); /* i : length of the array to scan */
+
+/************************************************************************/
+/*!
+ \brief Binary logarithm with 7 iterations
+
+ \param x
+
+ \return log2(x)/64
+ */
+/************************************************************************/
+Word32 BASOP_Util_Log2( Word32 x );
+
+
+/****************************************************************************/
+/*!
+ \brief Does fractional division of Word16 arg1 by Word16 arg2
+
+
+ \return fractional Q15 Word16 z = arg1(Q15)/arg2(Q15) with scaling s
+*/
+Word16 BASOP_Util_Divide1616_Scale( Word16 x, /* i : Numerator*/
+ Word16 y, /* i : Denominator*/
+ Word16 *s ); /* o : Additional scalefactor difference*/
+
+/****************************************************************************/
+/*!
+ \brief Does fractional integer division of Word32 arg1 by Word16 arg2
+
+
+ \return fractional Word16 integer z = arg1(32bits)/arg2(16bits), z not normalized
+*/
+Word16 BASOP_Util_Divide3216_Scale( Word32 x, /*!< i : Numerator */
+ Word16 y, /*!< i : Denominator*/
+ Word16 *s ); /*!< o : Additional scalefactor difference*/
+
+
+/************************************************************************/
+/*!
+ * \brief Binary logarithm with 5 iterations
+ *
+ * \param[i] val
+ *
+ * \return basop_log2(val)/128
+ */
+/************************************************************************/
+Word32 BASOP_Util_log2_i5( Word32 val );
+
+/************************************************************************/
+/*!
+ \brief Binary power
+
+ Date: 06-JULY-2012 Arthur Tritthart, IIS Fraunhofer Erlangen
+
+ Version with 3 table lookup and 1 linear interpolations
+
+ Algorithm: compute power of 2, argument x is in Q7.25 format
+ result = 2^(x/64)
+ We split exponent (x/64) into 5 components:
+ integer part: represented by b31..b25 (exp)
+ fractional part 1: represented by b24..b20 (lookup1)
+ fractional part 2: represented by b19..b15 (lookup2)
+ fractional part 3: represented by b14..b10 (lookup3)
+ fractional part 4: represented by b09..b00 (frac)
+ => result = (lookup1*lookup2*(lookup3+C1*frac)<<3)>>exp
+
+ Due to the fact, that all lookup values contain a factor 0.5
+ the result has to be shifted by 3 to the right also.
+ Table exp2_tab_long contains the log2 for 0 to 1.0 in steps
+ of 1/32, table exp2w_tab_long the log2 for 0 to 1/32 in steps
+ of 1/1024, table exp2x_tab_long the log2 for 0 to 1/1024 in
+ steps of 1/32768. Since the 2-logarithm of very very small
+ negative value is rather linear, we can use interpolation.
+
+ Limitations:
+
+ For x <= 0, the result is fractional positive
+ For x > 0, the result is integer in range 1...7FFF.FFFF
+ For x < -31/64, we have to clear the result
+ For x = 0, the result is ~1.0 (0x7FFF.FFFF)
+ For x >= 31/64, the result is 0x7FFF.FFFF
+
+ \param x
+
+ \return pow(2,(x/64))
+ */
+/************************************************************************/
+Word32 BASOP_Util_InvLog2( Word32 x );
+
+
+/****************************************************************************/
+/*!
+ \brief Sets Array Word16 arg1 to value Word16 arg2 for Word16 arg3 elements
+*/
+void set_val_Word16( Word16 X[], /*!< Address of array */
+ const Word16 val, /*!< Value to copy into array */
+ Word16 n ); /*!< Number of elements to process */
+
+
+/****************************************************************************/
+/*!
+ \brief Sets Array Word32 arg1 to value Word32 arg2 for Word16 arg3 elements
+*/
+void set_val_Word32( Word32 X[], /*!< Address of array */
+ const Word32 val, /*!< Value to copy into array */
+ Word16 n ); /*!< Number of elements to process */
+
+/****************************************************************************/
+/*!
+ \brief Does a multiplication of Word16 input values
+
+ \return z16 = x16 * y16
+*/
+Word16 mult0( Word16 x, /* i : Multiplier */
+ Word16 y ); /* i : Multiplicand */
+
+/**
+ * \brief calculate cosine of angle. Tuned for ISF domain.
+ * \param theta Angle normalized to radix 2, theta = (angle in radians)*2.0/pi
+ * \return result with exponent 0.
+ */
+Word16 getCosWord16R2( Word16 theta );
+
+/****************************************************************************/
+/*!
+ \brief 16/16->16 unsigned integer division
+
+ x and y have to be positive, x has to be < 16384
+
+ \return 16/16->16 integer
+ */
+
+Word16 idiv1616U( Word16 x, Word16 y );
+
+
+/**
+ * \brief return 2 ^ (exp * 2^exp_e)
+ * \param exp_m mantissa of the exponent to 2.0f
+ * \param exp_e exponent of the exponent to 2.0f
+ * \param result_e pointer to a INT where the exponent of the result will be stored into
+ * \return mantissa of the result
+ */
+Word32 BASOP_util_Pow2(
+ const Word32 exp_m,
+ const Word16 exp_e,
+ Word16 *result_e );
+
+
+Word32 Isqrt_lc1(
+ Word32 frac, /* i : Q31: normalized value (1.0 < frac <= 0.5) */
+ Word16 *exp /* i/o: exponent (value = frac x 2^exponent) */
+);
+
+/*****************************************************************************/
+/*!
+
+ \brief Calculates pow(2,x)
+ ___________________________________________________________________________
+ | |
+ | Function Name : Pow2() |
+ | |
+ | L_x = pow(2.0, exponant.fraction) (exponent = interger part) |
+ | = pow(2.0, 0.fraction) << exponent |
+ |---------------------------------------------------------------------------|
+ | Algorithm: |
+ | |
+ | The function Pow2(L_x) is approximated by a table and linear |
+ | interpolation. |
+ | |
+ | 1- i = bit10-b15 of fraction, 0 <= i <= 31 |
+ | 2- a = bit0-b9 of fraction |
+ | 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2 |
+ | 4- L_x = L_x >> (30-exponant) (with rounding) |
+ |___________________________________________________________________________|
+*/
+Word32 Pow2( /* o : Q0 : result (range: 0<=val<=0x7fffffff) */
+ Word16 exponant, /* i : Q0 : Integer part. (range: 0<=val<=30) */
+ Word16 fraction /* i : Q15 : Fractionnal part. (range: 0.0<=val<1.0) */
+);
+
+/*************************************************************************
+ *
+ * FUNCTION: Log2_norm()
+ *
+ * PURPOSE: Computes log2(L_x, exp), where L_x is positive and
+ * normalized, and exp is the normalisation exponent
+ * If L_x is negative or zero, the result is 0.
+ *
+ * DESCRIPTION:
+ * The function Log2(L_x) is approximated by a table and linear
+ * interpolation. The following steps are used to compute Log2(L_x)
+ *
+ * 1- exponent = 30-norm_exponent
+ * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization).
+ * 3- a = bit10-b24
+ * 4- i -=32
+ * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ *
+ *************************************************************************/
+
+Word16 Log2_norm_lc( /* o : Fractional part of Log2. (range: 0<=val<1) */
+ Word32 L_x /* i : input value (normalized) */
+);
+
+/*************************************************************************
+ *
+ * FUNCTION: BASOP_Util_fPow()
+ */
+/**
+ * \brief BASOP_Util_fPow
+ *
+ * PURPOSE: Computes pow(base_m, base_e, exp_m, exp_e), where base_m and base_e
+ * specify the base, and exp_m and exp_e specify the exponent.
+ * The result is returned in a mantissa and exponent representation.
+ *
+ * DESCRIPTION:
+ * The function BASOP_Util_fPow(L_x) calculates the power function by
+ * calculating 2 ^ (log2(base)*exp)
+ *
+ * \param base_m mantissa of base
+ * \param base_e exponent of base
+ * \param exp_m mantissa of exponent
+ * \param exp_e exponent of exponent
+ * \param result_e pointer to exponent of result
+ * \return Word32 mantissa of result
+ *
+ *************************************************************************/
+
+Word32 BASOP_Util_fPow( /* o : mantissa of result */
+ Word32 base_m,
+ Word16 base_e, /* i : input value for base (mantissa and exponent) */
+ Word32 exp_m,
+ Word16 exp_e, /* i : input value for exponent (mantissa and exponent) */
+ Word16 *result_e /* o : output pointer to exponent of result */
+);
+
+/*!**********************************************************************
+ \brief Add two values given by mantissa and exponent.
+
+ Mantissas are in 32-bit-fractional format with values between 0 and 1.
+ The base for exponents is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$
+
+************************************************************************/
+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 */
+
+/****************************************************************************/
+/*!
+ \brief Accumulates multiplications
+
+ Accumulates the elementwise multiplications of Word32 Array X with Word16 Array Y
+ pointed to by arg1 and arg2 with specified headroom. Length of to be multiplied arrays is arg3,
+ headroom with has to be taken into account is specified in arg4
+
+ \return Word32 result of accumulated multiplications over Word32 array arg1 and Word16 array arg2 and Word16 pointer
+ to exponent correction factor which needs to be added to the exponent of the result vector
+*/
+Word32 dotWord32_16_guards( const Word32 *X, const Word16 *Y, Word16 n, Word16 hr, Word16 *shift );
+
+Word32 Sqrt_l( Word32 L_x, Word16 *exp );
+
+#endif /* __BASOP_UTIL_H__ */
diff --git a/lib_com/bitalloc.c b/lib_com/bitalloc.c
new file mode 100644
index 0000000000000000000000000000000000000000..351ab9e3a80b0334617b43c5960413fa35b42f4a
--- /dev/null
+++ b/lib_com/bitalloc.c
@@ -0,0 +1,1022 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "basop_util.h"
+#include "basop_proto_func.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------
+ * bitalloc()
+ *
+ * Adaptive bit allocation for 20kHz audio codec
+ *--------------------------------------------------------------------------*/
+
+void bitalloc(
+ int16_t *y, /* i : reordered norm of sub-vectors */
+ int16_t *idx, /* i : reordered sub-vector indices */
+ int16_t sum, /* i : number of available bits */
+ int16_t N, /* i : number of norms */
+ int16_t K, /* i : maximum number of bits per dimension */
+ int16_t *r, /* o : bit-allacation vector */
+ const int16_t *sfmsize, /* i : band length */
+ const int16_t hqswb_clas /* i : signal classification flag */
+)
+{
+ int16_t i, j, k, n, m, v, im;
+ int16_t diff, temp;
+ int16_t fac;
+ int16_t ii;
+ int16_t SFM_thr = SFM_G1G2;
+
+ N -= 1;
+
+ if ( hqswb_clas == HQ_HARMONIC )
+ {
+ SFM_thr = 22;
+ }
+
+ fac = 3;
+ K -= 2;
+ im = 1;
+ diff = sum;
+ n = sum >> 3;
+ for ( i = 0; i < n; i++ )
+ {
+ k = 0;
+ temp = y[0];
+ for ( m = 1; m < im; m++ )
+ {
+ if ( temp < y[m] )
+ {
+ temp = y[m];
+ k = m;
+ }
+ }
+
+ if ( temp < y[m] )
+ {
+ k = m;
+ if ( im < N )
+ {
+ im++;
+ }
+ }
+
+ j = idx[k];
+ if ( sum >= sfmsize[j] && r[j] < K )
+ {
+ y[k] -= fac;
+ r[j]++;
+ if ( r[j] >= K )
+ {
+ y[k] = MIN16B;
+ }
+ sum -= sfmsize[j];
+ }
+ else
+ {
+ y[k] = MIN16B;
+ k++;
+ if ( k == im && im < N )
+ {
+ im++;
+ }
+ }
+
+ if ( sum < sfmsize[SFM_G1 - 1] || diff == sum ) /* sfmsize[SFM_G1-1] matches WID_G1, but also allows for extended BWs used in ACELP->HQ switching. */
+ {
+ break;
+ }
+
+ diff = sum;
+ v = N - 1;
+
+ if ( k > v )
+ {
+ for ( ii = 0; ii <= N; ii++ )
+ {
+ if ( y[ii] > MIN16B )
+ {
+ if ( ii < N )
+ {
+ im = ii + 1;
+ }
+
+ break;
+ }
+ }
+ }
+ }
+
+ if ( sum >= sfmsize[SFM_G1] ) /* sfmsize[SFM_G1] matches WID_G2, but also allows for extended BWs used in ACELP->HQ switching. */
+ {
+ for ( i = 0; i <= N; i++ )
+ {
+ j = idx[i];
+ if ( j >= SFM_G1 && j < SFM_thr && r[j] == 0 )
+ {
+ r[j] = 1;
+ sum -= sfmsize[j];
+ if ( sum < sfmsize[SFM_G1] )
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ if ( sum >= sfmsize[SFM_G1] )
+ {
+ for ( i = 0; i <= N; i++ )
+ {
+ j = idx[i];
+ if ( j >= SFM_G1 && j < SFM_thr && r[j] == 1 )
+ {
+ r[j] = 2;
+ sum -= sfmsize[j];
+ if ( sum < sfmsize[SFM_G1] )
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ if ( sum >= sfmsize[SFM_G1 - 1] )
+ {
+ for ( i = 0; i <= N; i++ )
+ {
+ j = idx[i];
+ if ( j < SFM_G1 && r[j] == 0 )
+ {
+ r[j] = 1;
+ sum -= sfmsize[j];
+ if ( sum < sfmsize[SFM_G1 - 1] )
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ if ( sum >= sfmsize[SFM_G1 - 1] )
+ {
+ for ( i = 0; i <= N; i++ )
+ {
+ j = idx[i];
+ if ( j < SFM_G1 && r[j] == 1 )
+ {
+ r[j] = 2;
+ sum -= sfmsize[j];
+ if ( sum < sfmsize[SFM_G1 - 1] )
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+#define WMC_TOOL_SKIP
+
+/*-------------------------------------------------------------------*
+ * BitAllocF()
+ *
+ * Fractional bit allocation
+ *-------------------------------------------------------------------*/
+
+/*! r: Integer (truncated) number of allocated bits */
+int16_t BitAllocF(
+ int16_t *y, /* i : norm of sub-vectors */
+ int32_t bit_rate, /* i : bitrate */
+ int16_t B, /* i : number of available bits */
+ int16_t N, /* i : number of sub-vectors */
+ int16_t *R, /* o : bit-allocation indicator */
+ int16_t *Rsubband, /* o : sub-band bit-allocation vector (Q3) */
+ const int16_t hqswb_clas, /* i : hq swb class */
+ const int16_t num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */
+)
+{
+ Word16 fac;
+ Word16 i, n, Nmin, Bits, bs, low_rate = 0;
+
+ Word16 m_fx;
+ Word32 t_fx, B_fx;
+ Word32 L_tmp1, L_tmp2;
+ Word16 tmp, exp1, exp2;
+ Word32 Rsubband_w32_fx[NB_SFM]; /* Q15 */
+ Word16 B_w16_fx;
+#ifdef BASOP_NOGLOB
+ Flag Overflow;
+#endif /* BASOP_NOGLOB */
+
+ set_l( Rsubband_w32_fx, 0, NB_SFM );
+
+ fac = 3;
+ if ( L_sub( bit_rate, 32000 ) < 0 )
+ {
+ bs = 2;
+ }
+ else
+ {
+ bs = 3;
+ }
+ low_rate = 1;
+
+ Nmin = N;
+ if ( sub( Nmin, SFM_N ) > 0 )
+ {
+ Nmin = SFM_N;
+ }
+
+ /* Initial bits distribution */
+ if ( sub( hqswb_clas, HQ_GEN_SWB ) == 0 || sub( hqswb_clas, HQ_GEN_FB ) == 0 )
+ {
+ /* Initial bits distribution */
+ L_tmp1 = 0;
+ m_fx = 0;
+ for ( i = 0; i < num_env_bands; i++ )
+ {
+ L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] );
+ }
+ L_tmp1 = L_msu0( L_tmp1, fac, B );
+
+ t_fx = 0;
+ n = 0;
+ tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) );
+ exp1 = norm_s( tmp );
+ tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/
+ exp2 = norm_s( tmp );
+ tmp = shl( tmp, exp2 );
+ exp1 = add( 29, sub( exp2, exp1 ) );
+
+ for ( i = 0; i < N; i++ )
+ {
+ L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[num_env_bands - 1] ), L_tmp1 );
+ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] );
+ move32(); /*Q0*/
+ if ( Rsubband_w32_fx[i] > 0 )
+ {
+ n = add( n, Nb[i] );
+ Rsubband_w32_fx[i] = Mpy_32_16( Rsubband_w32_fx[i], tmp );
+ move32(); /*exp1 - 15*/
+ Rsubband_w32_fx[i] = L_shl( Rsubband_w32_fx[i], sub( 30, exp1 ) ); /*Q15*/
+
+ t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/
+ }
+ else
+ {
+ Rsubband_w32_fx[i] = 0;
+ move32();
+ }
+ }
+ }
+ else
+ {
+ /* Initial bits distribution */
+ L_tmp1 = 0;
+ m_fx = 0;
+ for ( i = 0; i < N; i++ )
+ {
+ L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] );
+ }
+ L_tmp1 = L_msu0( L_tmp1, fac, B );
+
+
+ t_fx = 0;
+ n = 0;
+ tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) );
+ exp1 = norm_s( tmp );
+ tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/
+ exp2 = norm_s( tmp );
+ tmp = shl( tmp, exp2 );
+ exp1 = add( 29, sub( exp2, exp1 ) );
+ for ( i = 0; i < N; i++ )
+ {
+ L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 );
+ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] );
+ move32(); /*Q0*/
+ if ( Rsubband_w32_fx[i] > 0 )
+ {
+ n = add( n, Nb[i] );
+ Rsubband_w32_fx[i] = Mpy_32_16( Rsubband_w32_fx[i], tmp );
+ move32(); /*exp1 - 15*/
+ Rsubband_w32_fx[i] = L_shl( Rsubband_w32_fx[i], sub( 30, exp1 ) ); /*Q15*/
+
+ t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/
+ }
+ else
+ {
+ Rsubband_w32_fx[i] = 0;
+ move32();
+ }
+ }
+ }
+
+ /* Distribute the remaining bits to subbands with non-zero bits */
+ B_fx = L_shl( B, 15 );
+ WHILE( L_sub( L_shr( L_add( t_fx, 16384 ), 15 ), B ) != 0 )
+ {
+ L_tmp1 = L_sub( t_fx, B_fx );
+ exp1 = sub( norm_l( L_tmp1 ), 1 );
+ exp2 = norm_s( n );
+ tmp = div_s( extract_h( L_shl( L_tmp1, exp1 ) ), shl( n, exp2 ) ); /*15 + 15 + exp1 - 16 - exp2*/
+#ifndef BASOP_NOGLOB
+ m_fx = shl( tmp, sub( exp2, exp1 ) ); /*Q14*/
+#else
+ m_fx = shl_o( tmp, sub( exp2, exp1 ), &Overflow ); /*Q14*/
+#endif
+
+ t_fx = 0;
+ n = 0;
+ for ( i = 0; i < N; i++ )
+ {
+ if ( Rsubband_w32_fx[i] > 0 )
+ {
+ Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] );
+ move32();
+
+ if ( Rsubband_w32_fx[i] > 0 )
+ {
+ n = add( n, Nb[i] );
+
+ t_fx = L_add( t_fx, Rsubband_w32_fx[i] );
+ }
+ else
+ {
+ Rsubband_w32_fx[i] = 0;
+ move32();
+ }
+ }
+ }
+ }
+ Bits = B;
+
+ /* Impose bit-constraints to subbands with less than minimum bits*/
+ t_fx = 0;
+ n = 0;
+ for ( i = 0; i < N; i++ )
+ {
+ if ( Rsubband_w32_fx[i] > 0 )
+ {
+ test();
+ test();
+ if ( ( L_sub( Rsubband_w32_fx[i], L_shl( add( bs, LNb[i] ), 15 ) ) < 0 ) && ( sub( low_rate, 1 ) == 0 ) )
+ {
+ Rsubband_w32_fx[i] = 0;
+ move32();
+ }
+ else if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) <= 0 )
+ {
+ B = sub( B, Nb[i] );
+ Rsubband_w32_fx[i] = L_shl( Nb[i], 15 );
+ move32();
+ }
+ else
+ {
+ n = add( n, Nb[i] );
+ t_fx = L_add( t_fx, Rsubband_w32_fx[i] );
+ }
+ }
+ }
+
+ /* Distribute the remaining bits to subbands with more than 1-bit per sample */
+ WHILE( L_sub( L_shr( L_add( t_fx, 16384 ), 15 ), B ) != 0 )
+ {
+ L_tmp1 = L_sub( t_fx, L_shl( B, 15 ) );
+ L_tmp2 = L_abs( L_tmp1 );
+
+ if ( n > 0 )
+ {
+ exp1 = sub( norm_l( L_tmp2 ), 1 );
+ exp2 = norm_s( n );
+ tmp = div_s( extract_h( L_shl( L_tmp2, exp1 ) ), shl( n, exp2 ) ); /*15 + 15 + exp1 - 16 - exp2*/
+#ifndef BASOP_NOGLOB
+ m_fx = shl( tmp, sub( exp2, exp1 ) ); /*Q14*/
+#else /* BASOP_NOGLOB */
+ m_fx = shl_o( tmp, sub( exp2, exp1 ), &Overflow ); /*Q14*/
+#endif /* BASOP_NOGLOB */
+ if ( L_tmp1 < 0 )
+ {
+ m_fx = negate( m_fx );
+ }
+
+ t_fx = 0;
+ n = 0;
+ for ( i = 0; i < N; i++ )
+ {
+ if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) > 0 )
+ {
+ Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] );
+ if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) > 0 )
+ {
+ n = add( n, Nb[i] );
+
+ t_fx = L_add( t_fx, Rsubband_w32_fx[i] );
+ }
+ else
+ {
+ B = sub( B, Nb[i] );
+
+ Rsubband_w32_fx[i] = L_shl( Nb[i], 15 );
+ move32();
+ }
+ }
+ }
+ }
+ /*In case no subband has enough bits more than 1-bit per sample, take bits off the higher subbands */
+ if ( t_fx == 0 )
+ {
+ for ( i = N - 1; i >= 0; i-- )
+ {
+ if ( Rsubband_w32_fx[i] > 0 )
+ {
+ B = add( B, Nb[i] );
+ Rsubband_w32_fx[i] = 0;
+ move32();
+ if ( B >= 0 )
+ {
+ BREAK;
+ }
+ }
+ }
+ BREAK;
+ }
+ }
+
+ /* fine redistribution of over-allocated or under-allocated bits */
+ tmp = 0;
+ for ( i = 0; i < N; i++ )
+ {
+ Rsubband[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) );
+ tmp = add( tmp, Rsubband[i] );
+ }
+
+ B = Bits;
+ B_w16_fx = shl( B, 3 );
+ if ( sub( tmp, B_w16_fx ) > 0 )
+ {
+ tmp = sub( tmp, B_w16_fx );
+ for ( i = 0; i < N; i++ )
+ {
+ if ( sub( Rsubband[i], add( shl( Nb[i], 3 ), tmp ) ) >= 0 )
+ {
+ Rsubband[i] = sub( Rsubband[i], tmp );
+ BREAK;
+ }
+ }
+ }
+ else
+ {
+ tmp = sub( tmp, B_w16_fx );
+ for ( i = 0; i < N; i++ )
+ {
+ if ( Rsubband[i] > 0 )
+ {
+ Rsubband[i] = sub( Rsubband[i], tmp );
+ BREAK;
+ }
+ }
+ }
+
+ /* Calculate total used bits and initialize R to be used for Noise Filling */
+ tmp = 0;
+ for ( i = 0; i < N; i++ )
+ {
+ tmp = add( tmp, Rsubband[i] );
+ R[i] = shr( Rsubband[i], 3 );
+ }
+
+ return shr( tmp, 3 );
+}
+
+/*-------------------------------------------------------------------*
+ * Bit_group()
+ *
+ * bit allocation in group
+ *-------------------------------------------------------------------*/
+static void Bit_group_fx(
+ Word16 *y, /* i : norm of sub-band Q0*/
+ Word16 start_band, /* i : start band indices Q0*/
+ Word16 end_band, /* i : end band indices Q0*/
+ Word16 Bits, /* i : number of allocation bits in group Q0*/
+ Word16 thr, /* i : smallest bit number for allocation in group Q0*/
+ Word32 *Rsubband_fx, /* o : bit allocation of sub-band Q21*/
+ Word16 *fac_fx /* i : weight factor for norm of sub-band Q13*/
+)
+{
+ Word16 i, j, k, m, y_index[16], index[16], bit_band, band_num, norm_sum;
+ Word16 tmp, exp;
+ Word16 factor_fx;
+ Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0;
+ Word32 L_tmp;
+ UWord32 lo;
+
+ /* initialization for bit allocation in one group*/
+ tmp = 6554;
+ move16(); /*Q15 1/5 */
+ IF( sub( thr, 5 ) == 0 )
+ {
+ tmp = 6554;
+ move16(); /*Q15 1/5 */
+ }
+ IF( sub( thr, 6 ) == 0 )
+ {
+ tmp = 5462;
+ move16(); /*Q15 1/6 */
+ }
+ IF( sub( thr, 7 ) == 0 )
+ {
+ tmp = 4682;
+ move16(); /*Q15 1/7 */
+ }
+ bit_band = mult( tmp, Bits ); /*0+15-15=0, Q0 */
+ band_num = sub( end_band, start_band );
+
+ FOR( i = 0; i < band_num; i++ )
+ {
+ y_index[i] = y[add( i, start_band )];
+ move16();
+ index[i] = i;
+ move16();
+ }
+
+ /* Rearrange norm vector in decreasing order */
+ reordvct( y_index, band_num, index );
+ /* norm vector modification */
+
+ factor_fx = div_s( 1, band_num ); /*Q15 */
+ IF( sub( thr, 5 ) > 0 )
+ {
+ FOR( i = 0; i < band_num; i++ )
+ {
+ L_tmp = L_mult( i, factor_fx ); /*Q16 */
+ tmp = extract_h( L_shl( L_tmp, 13 ) ); /*Q13 */
+ tmp = sub( fac_fx[1], tmp ); /*Q13 */
+ L_tmp = L_mult( y_index[i], tmp ); /*Q14 */
+ y_index[i] = extract_h( L_shl( L_tmp, 2 ) ); /*Q0 */
+ }
+ }
+ ELSE
+ {
+ FOR( i = 0; i < band_num; i++ )
+ {
+ L_tmp = L_mult( i, factor_fx ); /*Q16 */
+ tmp = extract_h( L_shl( L_tmp, 13 ) ); /*Q13 */
+ tmp = sub( fac_fx[0], tmp ); /*Q13 */
+ L_tmp = L_mult( y_index[i], tmp ); /*Q14 */
+ y_index[i] = extract_h( L_shl( L_tmp, 2 ) ); /*Q0 */
+ }
+ }
+
+ /* bit allocation based on modified norm */
+ L_tmp = L_mult( band_num, 24576 ); /*Q16 */
+ tmp = extract_h( L_shl( L_tmp, 7 ) ); /*Q7 */
+ IF( sub( shl( bit_band, 7 ), tmp ) >= 0 )
+ {
+ FOR( j = 0; j < band_num; j++ )
+ {
+ IF( y_index[j] < 0 )
+ {
+ y_index[j] = 0;
+ move16();
+ }
+ R_temp_fx[j] = 2097152;
+ move16(); /*Q21 = 1 move16(); */
+ }
+
+ i = sub( band_num, 1 );
+ norm_sum = 0; /*Q0 */
+ FOR( k = 0; k <= i; k++ )
+ {
+ norm_sum = add( norm_sum, y_index[k] );
+ }
+
+ FOR( j = 0; j < band_num; j++ )
+ {
+ IF( norm_sum == 0 )
+ {
+ FOR( k = 0; k <= i; k++ )
+ {
+ R_temp_fx[k] = 0;
+ move32(); /*Q21 */
+ }
+ }
+ ELSE
+ {
+ exp = norm_s( norm_sum );
+ tmp = shl( norm_sum, exp ); /*Q(exp) */
+ tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */
+ Bits_avg_fx = L_mult( tmp, Bits ); /*Q(30-exp) */
+
+ FOR( k = 0; k <= i; k++ )
+ {
+ L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 );
+ Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo );
+
+ R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) );
+ move32(); /*Q21 */
+ }
+ }
+
+ L_tmp = L_shl( L_deposit_l( thr ), 21 ); /*Q21 */
+ IF( L_sub( R_temp_fx[i], L_tmp ) < 0 )
+ {
+ R_temp_fx[i] = 0;
+ move32();
+ norm_sum = sub( norm_sum, y_index[i] );
+ i--;
+ }
+ ELSE
+ {
+ BREAK;
+ }
+ }
+ }
+ ELSE
+ {
+ FOR( j = 0; j < bit_band; j++ )
+ {
+ IF( y_index[j] < 0 )
+ {
+ y_index[j] = 0;
+ move16();
+ }
+ R_temp_fx[j] = 2097152;
+ move32(); /*Q21 = 1 */
+ }
+
+ FOR( j = bit_band; j < band_num; j++ )
+ {
+ R_temp_fx[j] = 0;
+ move32();
+ }
+
+ norm_sum = 0;
+ FOR( k = 0; k < bit_band; k++ )
+ {
+ norm_sum = add( norm_sum, y_index[k] );
+ }
+
+ i = bit_band;
+ FOR( j = 0; j < bit_band; j++ )
+ {
+ IF( norm_sum == 0 )
+ {
+ FOR( k = 0; k < i; k++ )
+ {
+ R_temp_fx[k] = 0;
+ move32(); /*Q21 */
+ }
+ }
+ ELSE
+ {
+ exp = norm_s( norm_sum );
+ tmp = shl( norm_sum, exp ); /*Q(exp) */
+ tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */
+ Bits_avg_fx = L_mult( tmp, Bits ); /*Q(30-exp) */
+ FOR( k = 0; k < i; k++ )
+ {
+ L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 );
+ Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo );
+ R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) );
+ move32(); /*Q21 */
+ }
+ }
+ R_sum_fx = 0;
+ L_tmp = L_shl( L_deposit_l( thr ), 21 ); /*Q21 */
+ FOR( k = 0; k < i; k++ )
+ {
+ IF( L_sub( R_temp_fx[k], L_tmp ) < 0 )
+ {
+ FOR( m = k; m < i; m++ )
+ {
+ norm_sum = sub( norm_sum, y_index[m] );
+ R_temp_fx[m] = 0;
+ move32(); /*Q21 */
+ }
+ i = k;
+ BREAK;
+ }
+ ELSE
+ {
+ R_sum_fx = L_add( R_sum_fx, R_temp_fx[k] );
+ }
+ }
+ IF( L_sub( R_sum_fx, R_sum_org_fx ) == 0 )
+ {
+ BREAK;
+ }
+
+ R_sum_org_fx = R_sum_fx;
+ }
+ }
+
+ /* index comeback */
+ FOR( k = 0; k < band_num; k++ )
+ {
+ j = index[k];
+ move16();
+ Rsubband_fx[add( j, start_band )] = R_temp_fx[k];
+ move32();
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * BitAllocWB()
+ *
+ * WB bit allocation
+ *-------------------------------------------------------------------*/
+
+/*! r: Integer (truncated) number of allocated bits */
+int16_t BitAllocWB(
+ int16_t *y, /* i : norm of sub-vectors */
+ int16_t B, /* i : number of available bits */
+ int16_t N, /* i : number of sub-vectors */
+ int16_t *R, /* o : bit-allocation indicator */
+ int16_t *Rsubband /* o : sub-band bit-allocation vector (Q3) */
+)
+{
+ Word16 t_fx;
+ Word16 i, j, k, B1, B2, B3, B_saved;
+ Word16 Rsum_fx, Rsum_sub_fx[3];
+ Word32 Ravg_sub_32_fx[3], R_diff_32_fx[2];
+ Word16 factor_fx[2]; /*Q13 */
+ Word16 BANDS;
+ Word16 tmp, exp;
+ Word32 L_tmp, L_tmp1;
+ Word32 Rsubband_buf[NB_SFM];
+ UWord16 lo;
+
+ BANDS = N;
+ move16();
+ IF( sub( BANDS, SFM_N ) > 0 )
+ {
+ BANDS = SFM_N;
+ move16();
+ }
+ /* Init Rsubband to non-zero values for bands to be allocated bits */
+ FOR( k = 0; k < BANDS; k++ )
+ {
+ Rsubband_buf[k] = 2097152;
+ move32(); /*Q21 */
+ }
+ /* Calculate the norm sum and average of sub-band */
+ Rsum_sub_fx[0] = 0;
+ FOR( j = 0; j < SFM_G1; j++ )
+ {
+ IF( y[j] > 0 )
+ {
+ Rsum_sub_fx[0] = add( Rsum_sub_fx[0], y[j] );
+ move16(); /*Q0 */
+ }
+ }
+ Ravg_sub_32_fx[0] = L_mult( Rsum_sub_fx[0], 2048 );
+ move32(); /*Q16 0+15+1, q15 1/16 =2048 */
+
+ Rsum_sub_fx[1] = 0;
+ move32();
+ FOR( j = SFM_G1; j < SFM_G1G2; j++ )
+ {
+ IF( y[j] > 0 )
+ {
+ Rsum_sub_fx[1] = add( Rsum_sub_fx[1], y[j] );
+ move16(); /*Q0 */
+ }
+ }
+ Ravg_sub_32_fx[1] = L_mult( Rsum_sub_fx[1], 4096 ); /*16 0+15+1, q15 1/8 =4096 */
+
+ Rsum_sub_fx[2] = 0;
+ move16();
+ FOR( j = SFM_G1G2; j < BANDS; j++ )
+ {
+ IF( y[j] > 0 )
+ {
+ Rsum_sub_fx[2] = add( Rsum_sub_fx[2], y[j] );
+ move16(); /*Q0 */
+ }
+ }
+ tmp = div_s( 1, BANDS - SFM_G1G2 ); /*Q15 */
+ Ravg_sub_32_fx[2] = L_mult( Rsum_sub_fx[2], tmp );
+ move32(); /*Q16 */
+
+ /* Bit allocation for every group */
+ tmp = add( Rsum_sub_fx[0], Rsum_sub_fx[1] );
+ Rsum_fx = add( tmp, Rsum_sub_fx[2] ); /*Q0 */
+
+ factor_fx[0] = 16384; /*Q13 move16(); */
+ factor_fx[1] = 24576; /*Q13 move16(); */
+ {
+ R_diff_32_fx[0] = L_sub( Ravg_sub_32_fx[0], Ravg_sub_32_fx[1] );
+ move32(); /*Q16 */
+ R_diff_32_fx[1] = L_sub( Ravg_sub_32_fx[1], Ravg_sub_32_fx[2] );
+ move32(); /*Q16 */
+
+ IF( L_sub( R_diff_32_fx[0], 393216 ) < 0 && L_sub( R_diff_32_fx[1], 245760 ) < 0 )
+ {
+ IF( Rsum_fx == 0 )
+ {
+ B1 = 0;
+ move16();
+ B2 = 0;
+ move16();
+ B3 = 0;
+ move16();
+ }
+ ELSE
+ {
+ exp = norm_s( Rsum_fx );
+ tmp = shl( Rsum_fx, exp ); /*Q(exp) */
+ tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */
+ L_tmp1 = L_mult( B, Rsum_sub_fx[0] ); /*Q1 */
+ Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo );
+ B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */
+ IF( L_sub( L_tmp1, L_mult( B1, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) >= 0 )
+ {
+ B1 = add( B1, 1 );
+ }
+ L_tmp1 = L_mult( B, Rsum_sub_fx[1] ); /*Q1 */
+ Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo );
+ B2 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */
+ IF( L_sub( L_tmp1, L_mult( B2, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B2, 1 ), Rsum_fx ) ) >= 0 )
+ {
+ B2 = add( B2, 1 );
+ }
+ L_tmp1 = L_mult( B, Rsum_sub_fx[2] ); /*Q1 */
+ Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo );
+ B3 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */
+ IF( L_sub( L_tmp1, L_mult( B3, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B3, 1 ), Rsum_fx ) ) >= 0 )
+ {
+ B3 = add( B3, 1 );
+ }
+ }
+ IF( L_sub( Ravg_sub_32_fx[2], 786432 ) > 0 )
+ {
+ B_saved = 0;
+ move16();
+ IF( sub( B1, 288 ) > 0 )
+ {
+ B_saved = sub( B1, 288 );
+ B1 = 288;
+ move16();
+ }
+
+ IF( sub( B2, 256 ) > 0 )
+ {
+ tmp = sub( B2, 256 );
+ B_saved = add( B_saved, tmp );
+ B2 = 256;
+ move16();
+ }
+
+ IF( sub( B3, 96 ) > 0 )
+ {
+ tmp = sub( B3, 96 );
+ B_saved = add( B_saved, tmp );
+ B3 = 96;
+ move16();
+ }
+
+ IF( B_saved > 0 )
+ {
+ IF( sub( B1, 288 ) == 0 )
+ {
+ tmp = shr( B_saved, 1 );
+ B2 = add( B2, tmp );
+ tmp = sub( B, B1 );
+ B3 = sub( tmp, B2 );
+ }
+ ELSE
+ {
+ tmp = shr( B_saved, 1 );
+ B1 = add( B1, tmp );
+ IF( sub( B2, 256 ) == 0 )
+ {
+ tmp = sub( B, B1 );
+ B3 = sub( tmp, B2 );
+ }
+ ELSE
+ {
+ tmp = sub( B, B1 );
+ B2 = sub( tmp, B3 );
+ }
+ }
+ }
+ }
+
+ factor_fx[0] = 16384;
+ move16(); /*Q13 */
+ factor_fx[1] = 12288;
+ move16(); /*Q13 */
+ }
+ ELSE
+ {
+ IF( Rsum_fx == 0 )
+ {
+ B1 = 0;
+ move16();
+ B2 = 0;
+ move16();
+ B3 = B;
+ move16();
+ }
+ ELSE
+ {
+ exp = norm_s( Rsum_fx );
+ tmp = shl( Rsum_fx, exp ); /*Q(exp) */
+ tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */
+ L_tmp1 = L_mult( B, Rsum_sub_fx[0] ); /*Q1 */
+ Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo );
+ B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */
+ IF( L_sub( L_tmp1, L_mult( B1, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) >= 0 )
+ {
+ B1 = add( B1, 1 );
+ }
+ Mpy_32_16_ss( 1975684956, shl( B, 5 ), &L_tmp1, &lo );
+ Mpy_32_16_ss( L_tmp1, shl( Rsum_sub_fx[1], 7 ), &L_tmp1, &lo );
+ Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo );
+ B2 = extract_h( L_shl( L_tmp, sub( exp, 11 ) ) ); /*Q0 */
+ IF( L_sub( L_tmp1, L_shl( L_mult( B2, Rsum_fx ), 12 ) ) > 0 && L_sub( L_add( L_tmp1, 2 ), L_shl( L_mult( add( B2, 1 ), Rsum_fx ), 12 ) ) >= 0 )
+ {
+ B2 = add( B2, 1 );
+ }
+ tmp = sub( B, B1 );
+ B3 = sub( tmp, B2 );
+ }
+ }
+ }
+
+ IF( sub( Rsum_sub_fx[2], 3 ) < 0 )
+ {
+ B2 = add( B2, B3 );
+ B3 = 0;
+ move16();
+ }
+
+ /* Bit allocation in group */
+ Bit_group_fx( y, 0, SFM_G1, B1, 5, Rsubband_buf, factor_fx );
+ Bit_group_fx( y, SFM_G1, SFM_G1G2, B2, 6, Rsubband_buf, factor_fx );
+ Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx );
+ FOR( i = 0; i < BANDS; i++ )
+ {
+ Rsubband[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) );
+ move16();
+ }
+
+ /* Calcuate total used bits and initialize R to be used for Noise Filling */
+ L_tmp = 0;
+ move32();
+ FOR( i = 0; i < N; i++ )
+ {
+ L_tmp = L_add( L_tmp, Rsubband_buf[i] ); /*Q21 */
+ R[i] = extract_h( L_shr( Rsubband_buf[i], 5 ) ); /*Q0 */
+ }
+ t_fx = extract_h( L_shr( L_tmp, 5 ) ); /*Q0 */
+
+ return (Word16) t_fx;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/bitallocsum.c b/lib_com/bitallocsum.c
new file mode 100644
index 0000000000000000000000000000000000000000..2daf67b731199ed05e9befb17c8c15e8d7b90e55
--- /dev/null
+++ b/lib_com/bitallocsum.c
@@ -0,0 +1,93 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------
+ * bitallocsum()
+ *
+ * Calculate the total number of bits allocated over frame
+ *--------------------------------------------------------------------------*/
+
+void bitallocsum(
+ int16_t *R, /* i : bit-allocation vector */
+ const int16_t nb_sfm, /* i : number of sub-vectors */
+ int16_t *sum, /* o : total number of bits allocated */
+ int16_t *Rsubband, /* o : rate per subband (Q3) */
+ const int16_t num_bits, /* i : number of bits */
+ const int16_t length, /* i : length of spectrum */
+ const int16_t *sfmsize /* i : band length */
+)
+{
+ int16_t i;
+ int16_t total, tmp;
+ int16_t diff;
+
+ total = 0;
+ for ( i = 0; i < nb_sfm; i++ )
+ {
+ tmp = R[i] * sfmsize[i];
+ Rsubband[i] = tmp * 8;
+ total += tmp;
+ }
+ *sum = total;
+
+ if ( length <= L_FRAME32k )
+ {
+ diff = num_bits - *sum;
+ i = 0;
+ while ( diff > 0 )
+ {
+ if ( R[i] > 0 )
+ {
+ Rsubband[i] += 8;
+ diff -= 1;
+ *sum += 1;
+ }
+ i++;
+ if ( i >= nb_sfm )
+ {
+ i = 0;
+ }
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c
new file mode 100644
index 0000000000000000000000000000000000000000..0d1611de6a28e895269dd9e15f16300274965527
--- /dev/null
+++ b/lib_com/bits_alloc.c
@@ -0,0 +1,1487 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local function prototypes
+ *--------------------------------------------------------------------*/
+
+static int16_t BITS_ALLOC_adjust_acelp_fixed_cdk( const int16_t bits_frame, int16_t *fixed_cdk_index, const int16_t nb_subfr );
+
+static int16_t allocate_unused( const int32_t core_brate, const int16_t coder_type, const int16_t unused_bits, const int16_t nb_prm, const int16_t subfr, const int16_t prm_type, int16_t *prm_bit_mode );
+
+typedef enum
+{
+ GAINSPRM = 0x0,
+ PITCHPRM = 0x1,
+ MID_LSFSPRM = 0x3,
+ LSFPRM = 0x4
+} PRM_TYPES;
+
+/*-------------------------------------------------------------------*
+ * BITS_ALLOC_init_config_acelp()
+ *
+ * initial configuration for Mode 2 ACELP
+ *--------------------------------------------------------------------*/
+
+void BITS_ALLOC_init_config_acelp(
+ const int32_t bit_rate,
+ const int16_t narrowBand,
+ const int16_t nb_subfr,
+ ACELP_config *acelp_cfg /* o : configuration structure of ACELP */
+)
+{
+ int16_t rate_mode_index;
+
+ if ( bit_rate <= ACELP_9k60 )
+ {
+ rate_mode_index = 0;
+ }
+ else
+ {
+ rate_mode_index = 1;
+ }
+
+ acelp_cfg->mode_index = rate_mode_index;
+
+ /*LPC: midLpc should be swithced off?*/
+ acelp_cfg->midLpc_enable = 1;
+
+ /*ACELP ICB config*/
+ if ( ( rate_mode_index == 0 ) || ( narrowBand == 1 ) )
+ {
+ acelp_cfg->pre_emphasis = 1;
+ acelp_cfg->formant_enh = 1;
+ acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1;
+ acelp_cfg->formant_enh_den = FORMANT_SHARPENING_G2;
+ acelp_cfg->formant_tilt = 0;
+ acelp_cfg->voice_tilt = 0;
+ }
+ else
+ {
+ acelp_cfg->pre_emphasis = 0;
+ acelp_cfg->formant_enh = 1;
+ acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1;
+ acelp_cfg->formant_enh_den = FORMANT_SHARPENING_G2;
+ acelp_cfg->formant_tilt = 1;
+ acelp_cfg->voice_tilt = 1;
+ }
+
+ /*Wide band @ 16kHz*/
+ if ( nb_subfr == NB_SUBFR16k )
+ {
+ acelp_cfg->pre_emphasis = 1;
+ acelp_cfg->formant_enh = 1;
+ acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1_16k;
+ acelp_cfg->formant_enh_den = FORMANT_SHARPENING_G2_16k;
+ acelp_cfg->formant_tilt = 0;
+ acelp_cfg->voice_tilt = 2;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * BITS_ALLOC_config_acelp()
+ *
+ * configure all Mode 2 ACELP coder types and allocate the bits
+ *--------------------------------------------------------------------*/
+
+int16_t BITS_ALLOC_config_acelp(
+ const int16_t bits_frame, /* i : remaining bit budget for the frame */
+ const int16_t coder_type, /* i : acelp coder type */
+ ACELP_config *acelp_cfg, /* i/o: configuration structure of ACELP */
+ const int16_t narrowBand, /* i : narrowband flag */
+ const int16_t nb_subfr /* i : number of subframes */
+)
+{
+ int16_t mode_index;
+ int16_t band_index;
+ int16_t i;
+ int16_t remaining_bits, bits;
+
+ /*Sanity check*/
+
+ mode_index = acelp_cfg->mode_index;
+ band_index = ( narrowBand == 0 );
+ bits = 0;
+
+ if ( band_index == 0 )
+ {
+ if ( coder_type == INACTIVE )
+ {
+ acelp_cfg->formant_enh = 0;
+ }
+ else
+ {
+ acelp_cfg->formant_enh = 1;
+ }
+ }
+
+ if ( band_index == 1 && nb_subfr == NB_SUBFR )
+ {
+
+ if ( coder_type == INACTIVE )
+ {
+ acelp_cfg->pre_emphasis = 0;
+ acelp_cfg->formant_enh = 0;
+ acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1_16k;
+ acelp_cfg->formant_tilt = 1;
+ acelp_cfg->voice_tilt = 1;
+ }
+ else
+ {
+ acelp_cfg->pre_emphasis = 1;
+ acelp_cfg->formant_enh = 1;
+ acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1;
+ acelp_cfg->formant_tilt = 0;
+ acelp_cfg->voice_tilt = 0;
+ }
+ }
+
+ if ( coder_type == UNVOICED )
+ {
+ if ( ACELP_GAINS_MODE[mode_index][band_index][coder_type] == 6 )
+ {
+ acelp_cfg->pitch_sharpening = 0;
+ acelp_cfg->phase_scrambling = 1;
+ }
+ else
+ {
+ acelp_cfg->pitch_sharpening = 0;
+ acelp_cfg->phase_scrambling = 0;
+ }
+ }
+ else
+ {
+ acelp_cfg->pitch_sharpening = 1;
+ acelp_cfg->phase_scrambling = 0;
+ }
+
+ if ( coder_type > ACELP_MODE_MAX )
+ {
+ /* keep pitch sharpening for RF_ALLPRED mode */
+ acelp_cfg->pitch_sharpening = 0;
+ acelp_cfg->phase_scrambling = 0;
+ }
+
+ /*Allocate bits and different modes*/
+ acelp_cfg->bpf_mode = ACELP_BPF_MODE[mode_index][band_index][coder_type];
+ bits += ACELP_BPF_BITS[acelp_cfg->bpf_mode];
+
+ acelp_cfg->nrg_mode = ACELP_NRG_MODE[mode_index][band_index][coder_type];
+ acelp_cfg->nrg_bits = ACELP_NRG_BITS[acelp_cfg->nrg_mode];
+ bits += acelp_cfg->nrg_bits;
+
+ acelp_cfg->ltp_mode = ACELP_LTP_MODE[mode_index][band_index][coder_type];
+ acelp_cfg->ltp_bits = 0;
+ acelp_cfg->ltf_mode = ACELP_LTF_MODE[mode_index][band_index][coder_type];
+ acelp_cfg->ltf_bits = ACELP_LTF_BITS[acelp_cfg->ltf_mode];
+
+ if ( nb_subfr == NB_SUBFR16k && acelp_cfg->ltf_bits == 4 )
+ {
+ acelp_cfg->ltf_bits++;
+ }
+ bits += acelp_cfg->ltf_bits;
+
+
+ for ( i = 0; i < nb_subfr; i++ )
+ {
+ acelp_cfg->gains_mode[i] = ACELP_GAINS_MODE[mode_index][band_index][coder_type];
+
+ /* skip subframe 1, 3 gain encoding, and use from subframe 0, and 3, respectively */
+ if ( coder_type >= ACELP_MODE_MAX && ( i == 1 || i == 3 ) )
+ {
+ acelp_cfg->gains_mode[i] = 0;
+ }
+
+ bits += ACELP_GAINS_BITS[acelp_cfg->gains_mode[i]];
+ bits += ACELP_LTP_BITS_SFR[acelp_cfg->ltp_mode][i];
+ acelp_cfg->ltp_bits += ACELP_LTP_BITS_SFR[acelp_cfg->ltp_mode][i];
+ }
+
+ /*Innovation*/
+ if ( bits_frame < bits )
+ {
+ printf( "\nWarning: bits per frame too low\n" );
+ return -1;
+ }
+
+ if ( coder_type == RF_ALLPRED )
+ {
+ set_s( acelp_cfg->fixed_cdk_index, -1, nb_subfr );
+ }
+ else if ( coder_type == RF_GENPRED )
+ {
+ acelp_cfg->fixed_cdk_index[0] = 0; /* 7 bits */
+ acelp_cfg->fixed_cdk_index[1] = -1;
+ acelp_cfg->fixed_cdk_index[2] = 0; /* 7 bits */
+ acelp_cfg->fixed_cdk_index[3] = -1;
+ acelp_cfg->fixed_cdk_index[4] = -1;
+ bits += 14;
+ }
+ else if ( coder_type == RF_NOPRED )
+ {
+ set_s( acelp_cfg->fixed_cdk_index, 0, nb_subfr );
+ bits += 28;
+ }
+ else
+ {
+ bits += BITS_ALLOC_adjust_acelp_fixed_cdk( bits_frame - bits, acelp_cfg->fixed_cdk_index, nb_subfr );
+ }
+
+ remaining_bits = bits_frame - bits;
+
+ /*Sanity check*/
+ if ( remaining_bits < 0 )
+ {
+ bits = -1;
+ }
+
+
+ return ( bits );
+}
+
+/*-------------------------------------------------------------------*
+ * BITS_ALLOC_adjust_acelp_fixed_cdk()
+ *
+ *
+ *--------------------------------------------------------------------*/
+
+static int16_t BITS_ALLOC_adjust_acelp_fixed_cdk(
+ const int16_t bits_frame, /* i : bit budget */
+ int16_t *fixed_cdk_index,
+ const int16_t nb_subfr )
+{
+ int16_t bits_subframe2;
+ int16_t sfr, k, bitsused, bits_currsubframe;
+
+ bits_subframe2 = bits_frame;
+
+ if ( bits_subframe2 < ACELP_FIXED_CDK_BITS( 0 ) * nb_subfr )
+ {
+ return ( bits_frame + 1 ); /* Not enough bits for lowest mode. -> trigger alarm*/
+ }
+
+ /* search cdk-index for first subframe */
+ for ( k = 0; k < ACELP_FIXED_CDK_NB - 1; k++ )
+ {
+ if ( ACELP_FIXED_CDK_BITS( k ) * nb_subfr > bits_subframe2 )
+ {
+ k--; /* previous mode did not exceed bit-budget */
+ break;
+ }
+ }
+
+ if ( ACELP_FIXED_CDK_BITS( k ) * nb_subfr > bits_subframe2 )
+ {
+ k--; /* previous mode did not exceed bit-budget */
+ }
+ fixed_cdk_index[0] = k;
+
+ bitsused = ACELP_FIXED_CDK_BITS( k );
+
+ for ( sfr = 1; sfr < nb_subfr; sfr++ )
+ {
+ bits_currsubframe = ( sfr * bits_subframe2 + bits_subframe2 ) - bitsused * nb_subfr;
+
+ /* try increasing mode while below threshold */
+ while ( ( k < ACELP_FIXED_CDK_NB - 1 ) && ( ACELP_FIXED_CDK_BITS( k + 1 ) * nb_subfr <= bits_currsubframe ) )
+ {
+ k++;
+ }
+
+ /* try decreasing mode until below threshold */
+ while ( ACELP_FIXED_CDK_BITS( k ) * nb_subfr > bits_currsubframe )
+ {
+ k--;
+ if ( k == 0 )
+ {
+ break;
+ }
+ }
+
+ /* store mode */
+ fixed_cdk_index[sfr] = k;
+ bitsused += ACELP_FIXED_CDK_BITS( k );
+ }
+
+ return bitsused;
+}
+
+
+/*-------------------------------------------------------------------*
+ * fcb_table()
+ *
+ * Selection of fixed innovation codebook bitbudget table
+ *--------------------------------------------------------------------*/
+
+static int16_t fcb_table(
+ const int16_t n,
+ const int16_t L_subfr )
+{
+ int16_t out;
+
+ out = PulseConfTable[n].bits;
+ if ( L_subfr > L_SUBFR )
+ {
+ out = fast_FCB_bits_2sfr[n];
+ }
+
+ return ( out );
+}
+
+/*-------------------------------------------------------------------*
+ * acelp_FCB_allocator()
+ *
+ * Routine to allocate fixed innovation codebook bit-budget
+ *--------------------------------------------------------------------*/
+
+static ivas_error acelp_FCB_allocator(
+ int16_t *nBits, /* i/o: available bit-budget */
+ int16_t fixed_cdk_index[], /* o : codebook index */
+ int16_t nb_subfr, /* i : number of subframes */
+ const int16_t L_subfr, /* i : subframe length */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t tc_subfr, /* i : TC subframe index */
+ const int16_t fix_first /* i : flag to indicate whether the first subframe bit-budget was fixed */
+)
+{
+ int16_t cdbk, sfr, step;
+ int16_t nBits_tmp;
+ int16_t *p_fixed_cdk_index;
+ ivas_error error;
+ int16_t max_n;
+
+ error = IVAS_ERR_OK;
+
+ cdbk = coder_type; /* just to avoid warning when DEBUGGING is deactivated */
+
+ p_fixed_cdk_index = fixed_cdk_index;
+
+ /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */
+ if ( tc_subfr >= L_SUBFR && fix_first )
+ {
+ int16_t i;
+
+ for ( i = 0; i < nb_subfr; i++ )
+ {
+ *nBits -= ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] );
+ }
+ return error;
+ }
+
+ /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */
+ sfr = 0;
+ if ( fix_first )
+ {
+ *nBits -= ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] );
+ sfr = 1;
+ p_fixed_cdk_index++;
+ nb_subfr = 3;
+ }
+
+ /* distribute the bit-budget equally between subframes */
+ if ( L_subfr > L_SUBFR ) /* access fast_FCB_bits_2sfr */
+ {
+ max_n = 6;
+ }
+ else
+ {
+ max_n = ACELP_FIXED_CDK_NB;
+ }
+ for ( cdbk = 0; cdbk < max_n; cdbk++ )
+ {
+ if ( fcb_table( cdbk, L_subfr ) * nb_subfr > *nBits )
+ {
+ break;
+ }
+ }
+ cdbk--;
+
+ set_s( p_fixed_cdk_index, cdbk, nb_subfr );
+ nBits_tmp = 0;
+ if ( cdbk >= 0 )
+ {
+ nBits_tmp = fcb_table( cdbk, L_subfr );
+ }
+ else
+ {
+ nBits_tmp = 0;
+ }
+ *nBits -= nBits_tmp * nb_subfr;
+
+ /* try to increase the FCB bit-budget of the first subframe(s) */
+ if ( cdbk < ACELP_FIXED_CDK_NB - 1 )
+ {
+ step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp;
+ while ( *nBits >= step )
+ {
+ ( *p_fixed_cdk_index )++;
+ *nBits -= step;
+ p_fixed_cdk_index++;
+ }
+
+ /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */
+ if ( fixed_cdk_index[sfr] < ACELP_FIXED_CDK_NB - 1 )
+ {
+ step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr );
+ if ( *nBits >= step && cdbk >= 0 )
+ {
+ fixed_cdk_index[sfr]++;
+ *nBits -= step;
+
+ if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 )
+ {
+ sfr++;
+ fixed_cdk_index[sfr]++;
+ *nBits -= step;
+ }
+ }
+ }
+ }
+ /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */
+ if ( tc_subfr >= L_SUBFR )
+ {
+ int16_t tempr;
+
+ SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] );
+
+ /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */
+ if ( tc_subfr / L_SUBFR < nb_subfr - 1 )
+ {
+ SWAP( fixed_cdk_index[( tc_subfr - L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] );
+ }
+ }
+
+ /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */
+ if ( L_subfr > L_SUBFR )
+ {
+ int16_t i, j;
+ for ( i = 0; i < nb_subfr; i++ )
+ {
+ j = fixed_cdk_index[i];
+ fixed_cdk_index[i] = fast_FCB_bits_2sfr[j];
+ }
+ }
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------*
+ * config_acelp1()
+ *
+ * Configure ACELP bit allocation
+ * - should be in range of <6700; 24350> for ACELP@12.8kHz
+ * - per channel bitrate minimum is 13250 kbps for ACELP@16kHz
+ *--------------------------------------------------------------------*/
+
+ivas_error config_acelp1(
+ const int16_t enc_dec, /* i : encoder/decoder flag */
+ const int32_t total_brate, /* i : total bitrate */
+ const int32_t core_brate_inp, /* i : core bitrate */
+ const int16_t core, /* i : core */
+ const int16_t extl, /* i : extension layer */
+ const int32_t extl_brate, /* i : extension layer bitrate */
+ const int16_t L_frame, /* i : frame length at internal Fs */
+ const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */
+ ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */
+ const int16_t signaling_bits, /* i : number of signaling bits */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t tc_subfr, /* i : TC subfr ID */
+ const int16_t tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */
+ int16_t *nBits_es_Pred, /* o : number of bits for Es_pred Q */
+ int16_t *unbits, /* o : number of unused bits */
+ const int16_t element_mode, /* i : element mode */
+ int16_t *uc_two_stage_flag, /* o : flag undicating two-stage UC */
+ const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */
+ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
+ const int16_t idchan, /* i : stereo channel ID */
+ const int16_t active_cnt, /* i : Active frame counter */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/
+ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */
+ const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */
+)
+{
+ int16_t i, bits, nb_subfr;
+ int16_t flag_hardcoded, coder_type_sw, fix_first;
+ int32_t core_brate;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ /*-----------------------------------------------------------------*
+ * Set the flag indicating two-stage Unvoiced (UC) frame
+ *-----------------------------------------------------------------*/
+
+ *uc_two_stage_flag = 0;
+ if ( coder_type == UNVOICED )
+ {
+ if ( total_brate >= MIN_UNVOICED_TWO_STAGE_BRATE && element_mode > EVS_MONO && ( idchan == 0 || ( ( total_brate >= 8500 || extl_brate == 0 ) && tdm_LRTD_flag == 1 ) ) )
+ {
+ *uc_two_stage_flag = 1;
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Set the number of subframes
+ *-----------------------------------------------------------------*/
+
+ if ( L_frame == L_FRAME )
+ {
+ nb_subfr = NB_SUBFR;
+
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ nb_subfr = NB_SUBFR16k;
+
+ }
+
+ coder_type_sw = coder_type;
+ if ( core != ACELP_CORE )
+ {
+ /* used in acelp_core_switch_enc() */
+ nb_subfr = 1;
+ if ( L_frame == L_FRAME )
+ {
+ coder_type_sw = TRANSITION;
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Check if the core_brate is hard coded (to keep BE for mono core) or not
+ *-----------------------------------------------------------------*/
+
+ flag_hardcoded = 0;
+ i = 0;
+
+ while ( i < SIZE_BRATE_INTERMED_TBL )
+ {
+ if ( core_brate_inp == brate_intermed_tbl[i] )
+ {
+ flag_hardcoded = 1;
+ break;
+ }
+
+ if ( core_brate_inp < brate_intermed_tbl[i] )
+ {
+ flag_hardcoded = 0;
+ break;
+ }
+
+ i++;
+ }
+
+ if ( element_mode == IVAS_CPE_TD && coder_type == AUDIO &&
+ core_brate_inp <= STEREO_GSC_BIT_RATE_ALLOC && 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--;
+ }
+
+ core_brate = brate_intermed_tbl[i];
+
+ if ( element_mode > EVS_MONO )
+ {
+ flag_hardcoded = 0; /* use automatic and flexible ACELP bit-budget allocation */
+ }
+
+ if ( core != ACELP_CORE && element_mode == EVS_MONO ) /* needed for mode1 core switching in EVS mono */
+ {
+ flag_hardcoded = 1;
+ }
+
+ /*-----------------------------------------------------------------*
+ * ACELP bit allocation
+ *-----------------------------------------------------------------*/
+
+ if ( !( coder_type == TRANSITION && tc_subfr != -1 ) || enc_dec == DEC )
+ {
+ /* Set the bit-budget */
+ bits = (int16_t) ( core_brate_inp / FRAMES_PER_SEC );
+
+ if ( coder_type == TRANSITION && enc_dec == DEC && tc_call == 1 )
+ {
+ bits += *nBits_es_Pred; /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */
+ }
+
+ /* Subtract signaling bits */
+ if ( enc_dec == DEC && idchan == 1 && element_mode > EVS_MONO )
+ {
+ bits -= TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS;
+
+ if ( tdm_LRTD_flag == 1 )
+ {
+ bits += STEREO_BITS_TCA;
+ }
+
+ /* subtract TBE/BWE flag */
+ if ( extl_brate > 0 && ( extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE ) )
+ {
+ bits--;
+ }
+ }
+ else
+ {
+ /* Subtract signaling bits */
+ bits -= signaling_bits;
+ }
+
+ if ( extl_brate > 0 && ( extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE ) )
+ {
+ /* extension layer signaling bit is counted in the extension layer bitbudget */
+ bits++;
+ }
+
+ /*-----------------------------------------------------------------*
+ * LSF Q bit-budget
+ *-----------------------------------------------------------------*/
+
+ if ( !tdm_lp_reuse_flag || idchan == 0 )
+ {
+ /* LSF Q bit-budget */
+ acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX( core_brate, coder_type )];
+
+ if ( !flag_hardcoded )
+ {
+ if ( L_frame == L_FRAME )
+ {
+ if ( element_mode == IVAS_SCE && tdm_low_rate_mode )
+ {
+ acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX( core_brate, coder_type )];
+ }
+ else if ( ( total_brate < 7200 || coder_type == INACTIVE || coder_type == AUDIO ) && idchan == 1 )
+ {
+ /* TD stereo, secondary channel: do nothing */
+ acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX( core_brate, coder_type )];
+ }
+ else if ( element_mode > EVS_MONO && coder_type == AUDIO && brate_intermed_tbl[i] < ACELP_9k60 )
+ {
+ /* primary channel: do nothing */
+ }
+ else if ( element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] >= ACELP_9k60*/ )
+ {
+ acelp_cfg->lsf_bits = 42;
+ }
+ else if ( total_brate <= 9600 || coder_type == UNVOICED )
+ {
+ acelp_cfg->lsf_bits = 31;
+ }
+ else if ( total_brate <= 20000 )
+ {
+ acelp_cfg->lsf_bits = 36;
+ }
+ else
+ {
+ acelp_cfg->lsf_bits = 41;
+ }
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ acelp_cfg->lsf_bits = 41;
+ }
+ }
+
+ bits -= acelp_cfg->lsf_bits;
+
+ /* mid-LSF Q bit-budget */
+ acelp_cfg->mid_lsf_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX( core_brate, coder_type )];
+
+ if ( element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] < ACELP_9k60*/ )
+ {
+ acelp_cfg->mid_lsf_bits = 5;
+ /* primary channel: do nothing */
+ }
+
+ bits -= acelp_cfg->mid_lsf_bits;
+ }
+ else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 )
+ {
+ bits -= TDM_IC_LSF_PRED_BITS;
+ }
+
+ /* gain Q bit-budget - part 1 */
+ if ( ( coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !( core_brate <= ACELP_8k00 && coder_type != TRANSITION ) ) || ( coder_type == INACTIVE && total_brate > MAX_GSC_INACTIVE_BRATE ) )
+ {
+ *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, -1, -1 )];
+ bits -= *nBits_es_Pred;
+ }
+ else if ( *uc_two_stage_flag )
+ {
+ *nBits_es_Pred = 4;
+ bits -= *nBits_es_Pred;
+ }
+ }
+ else
+ {
+ bits = *unbits;
+ }
+
+ if ( coder_type == TRANSITION && tc_call == 0 )
+ {
+ *unbits = bits;
+ return error;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Low-rate mode - bits are allocated in tdm_low_rate_enc()
+ *-----------------------------------------------------------------*/
+
+ if ( element_mode == IVAS_SCE && tdm_low_rate_mode )
+ {
+ acelp_cfg->FEC_mode = 0;
+ acelp_cfg->ltf_mode = FULL_BAND;
+ *nBits_es_Pred = 0;
+ *unbits = 0;
+ acelp_cfg->ubits = 0;
+
+ return error;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Supplementary information for FEC
+ *-----------------------------------------------------------------*/
+
+ acelp_cfg->FEC_mode = 0;
+ if ( core_brate >= ACELP_11k60 && ( idchan == 0 || element_mode == EVS_MONO ) )
+ {
+ acelp_cfg->FEC_mode = 1;
+
+ if ( coder_type > UNVOICED && coder_type < AUDIO && coder_type != VOICED )
+ {
+ bits -= FEC_BITS_CLS;
+ }
+
+ if ( coder_type != TRANSITION )
+ {
+ if ( total_brate >= ACELP_16k40 )
+ {
+ acelp_cfg->FEC_mode = 2;
+
+ if ( coder_type > UNVOICED && coder_type < AUDIO )
+ {
+ bits -= FEC_BITS_ENR;
+ }
+ }
+
+ if ( total_brate >= ACELP_32k )
+ {
+ acelp_cfg->FEC_mode = 3;
+
+ if ( coder_type > UNVOICED && coder_type < AUDIO )
+ {
+ bits -= FEC_BITS_POS;
+ }
+ }
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * LP filtering of the adaptive excitation
+ *-----------------------------------------------------------------*/
+
+ if ( idchan > 0 && element_mode > EVS_MONO )
+ {
+ acelp_cfg->ltf_mode = FULL_BAND;
+ }
+ else if ( coder_type == UNVOICED )
+ {
+ acelp_cfg->ltf_mode = FULL_BAND;
+ }
+ else if ( ( coder_type == GENERIC || coder_type == TRANSITION ) && core_brate < ACELP_11k60 )
+ {
+ acelp_cfg->ltf_mode = LOW_PASS;
+ }
+ else if ( core_brate >= ACELP_11k60 && ( coder_type != AUDIO && !( coder_type == INACTIVE && L_frame == L_FRAME ) ) )
+ {
+ if ( coder_type == INACTIVE && L_frame == L_FRAME16k && total_brate <= MAX_GSC_INACTIVE_BRATE ) /* GSC Inactive @16kHz */
+ {
+ acelp_cfg->ltf_mode = FULL_BAND;
+ }
+ else
+ {
+ acelp_cfg->ltf_mode = NORMAL_OPERATION;
+ if ( coder_type != TRANSITION )
+ {
+ bits -= nb_subfr;
+ }
+ }
+ }
+ else
+ {
+ acelp_cfg->ltf_mode = FULL_BAND;
+ }
+
+ /*-----------------------------------------------------------------*
+ * UC bit-budget
+ *-----------------------------------------------------------------*/
+
+ if ( ( ( coder_type == UNVOICED && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && core_brate <= ACELP_9k60 ) ) && ( idchan == 0 || element_mode == EVS_MONO ) )
+ {
+ bits -= NBITS_NOISENESS; /* noiseness */
+ }
+ if ( coder_type == UNVOICED && !( *uc_two_stage_flag ) )
+ {
+ bits -= ( 3 * NB_SUBFR ); /* tilt factor */
+ }
+
+ /*-----------------------------------------------------------------*
+ * TC bit-budget
+ *-----------------------------------------------------------------*/
+
+ fix_first = 0;
+ if ( coder_type == TRANSITION )
+ {
+ if ( tc_call == 2 )
+ {
+ fix_first = 1;
+ }
+
+ /* TC signaling */
+ if ( L_frame == L_FRAME )
+ {
+ if ( tc_subfr == TC_0_0 )
+ {
+ if ( enc_dec == ENC )
+ {
+ bits -= 1; /* TC signaling */
+ }
+
+ if ( acelp_cfg->ltf_mode == NORMAL_OPERATION )
+ {
+ bits -= 3; /* LP filtering flag */
+ }
+ }
+ else if ( tc_subfr == TC_0_64 )
+ {
+ if ( enc_dec == ENC )
+ {
+ bits -= 4; /* TC signaling */
+ }
+
+ if ( acelp_cfg->ltf_mode == NORMAL_OPERATION )
+ {
+ bits -= 3; /* LP filtering flag */
+ }
+ }
+ else if ( tc_subfr == TC_0_128 )
+ {
+ if ( enc_dec == ENC )
+ {
+ bits -= 4; /* TC signaling */
+ }
+
+ if ( acelp_cfg->ltf_mode == NORMAL_OPERATION )
+ {
+ bits -= 2; /* LP filtering flag */
+ }
+ }
+ else if ( tc_subfr == TC_0_192 )
+ {
+ if ( enc_dec == ENC )
+ {
+ bits -= 3; /* TC signaling */
+ }
+
+ if ( acelp_cfg->ltf_mode == NORMAL_OPERATION )
+ {
+ bits -= 1; /* LP filtering flag */
+ }
+ }
+ else if ( tc_subfr == L_SUBFR )
+ {
+ if ( enc_dec == ENC )
+ {
+ bits -= 3; /* TC signaling */
+ }
+
+ if ( acelp_cfg->ltf_mode == NORMAL_OPERATION )
+ {
+ bits -= ( L_FRAME - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */
+ }
+ }
+ else
+ {
+ if ( enc_dec == ENC )
+ {
+ bits -= 4; /* TC signaling */
+ }
+
+ if ( acelp_cfg->ltf_mode == NORMAL_OPERATION )
+ {
+ bits -= ( L_FRAME - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */
+ }
+ }
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ if ( enc_dec == ENC )
+ {
+ if ( tc_subfr <= 2 * L_SUBFR )
+ {
+ bits -= 2; /* TC signaling */
+ }
+ else
+ {
+ bits -= 3; /* TC signaling */
+ }
+ }
+
+ bits -= ( L_FRAME16k - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */
+ }
+
+ /* glottal-shape codebook bits */
+ bits -= ( 3 + 6 + 1 + 3 );
+ }
+
+ /*-----------------------------------------------------------------*
+ * pitch, innovation, gains bit-budget
+ *-----------------------------------------------------------------*/
+
+ acelp_cfg->fcb_mode = 0;
+
+ if ( element_mode == IVAS_CPE_TD && tdm_low_rate_mode == 1 && coder_type != INACTIVE && coder_type != UNVOICED ) /* GENERIC low rate mode for secondary channel */
+ {
+ set_s( acelp_cfg->pitch_bits, 0, NB_SUBFR16k );
+ set_s( acelp_cfg->gains_mode, 0, NB_SUBFR16k );
+
+ for ( i = 0; i < 2; i++ )
+ {
+ acelp_cfg->pitch_bits[i] = 0;
+ if ( tdm_Pitch_reuse_flag == 0 )
+ {
+ acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX( ACELP_7k20, GENERIC, 2 * i * L_SUBFR, TC_SUBFR2IDX( tc_subfr ) )];
+ bits -= acelp_cfg->pitch_bits[i];
+ }
+ acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX( ACELP_7k20, GENERIC, i * L_SUBFR, TC_SUBFR2IDX( tc_subfr ) )];
+ bits -= acelp_cfg->gains_mode[i];
+ }
+ acelp_cfg->fcb_mode = 1;
+
+ if ( bits >= 16 )
+ {
+ acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 );
+ }
+ else
+ {
+ acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 );
+ acelp_cfg->fixed_cdk_index[1] = -1;
+ }
+ acelp_cfg->fixed_cdk_index[2] = -1;
+ acelp_cfg->fixed_cdk_index[3] = -1;
+ }
+ else if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || ( nb_subfr == NB_SUBFR16k && ( total_brate > MAX_GSC_INACTIVE_BRATE || coder_type != INACTIVE ) ) || core == HQ_CORE )
+ {
+ /* pitch Q & gain Q bit-budget - part 2*/
+ for ( i = 0; i < nb_subfr; i++ )
+ {
+ if ( L_frame == L_FRAME )
+ {
+ if ( tdm_Pitch_reuse_flag == 1 && idchan == 1 )
+ {
+ acelp_cfg->pitch_bits[i] = 0;
+ }
+ else
+ {
+ acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX( tc_subfr ) )];
+ }
+ acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX( tc_subfr ) )];
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ if ( tdm_Pitch_reuse_flag == 1 && idchan == 1 )
+ {
+ acelp_cfg->pitch_bits[i] = 0;
+ }
+ else
+ {
+ acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )];
+ }
+ acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )];
+ }
+
+ bits -= acelp_cfg->pitch_bits[i];
+
+ if ( coder_type == INACTIVE && acelp_cfg->gains_mode[i] == 6 /* VQ vs. SQ threshold @32 kbps */ )
+ {
+ bits -= 5;
+ }
+ else
+ {
+ if ( *uc_two_stage_flag == 1 )
+ {
+ acelp_cfg->gains_mode[i] = 7;
+ }
+
+ bits -= acelp_cfg->gains_mode[i];
+ }
+ }
+
+ /* algebraic codebook bit-budget */
+ if ( flag_hardcoded || ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) || ( total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE ) )
+ {
+ for ( i = 0; i < nb_subfr; i++ )
+ {
+ if ( L_frame == L_FRAME )
+ {
+ acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX( tc_subfr ) )];
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )];
+ }
+ bits -= acelp_cfg->fixed_cdk_index[i];
+ }
+ }
+ else if ( !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) )
+ {
+ if ( coder_type == UNVOICED && !( *uc_two_stage_flag ) )
+ {
+ i = bits / NB_SUBFR;
+ if ( i % 2 == 0 )
+ {
+ i--; /* must be odd */
+ }
+ i = min( i, 13 );
+ i = max( i, 0 ); /* If i == 0-> random noise generator will be used as FCB */
+ set_s( acelp_cfg->fixed_cdk_index, i, NB_SUBFR );
+ bits -= ( i * NB_SUBFR );
+ }
+ else
+ {
+
+ acelp_cfg->fcb_mode = 1;
+ if ( element_mode == IVAS_CPE_TD )
+ {
+ if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr ) ) /* enough bits for all fcb */
+ {
+ acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
+ }
+ else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr - 1 ) )
+ {
+ acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr - 1, L_SUBFR, coder_type, tc_subfr, fix_first );
+ acelp_cfg->fixed_cdk_index[3] = -1;
+ }
+ else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr - 2 ) )
+ {
+ acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr - 2, L_SUBFR, coder_type, tc_subfr, fix_first );
+ acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1];
+ acelp_cfg->fixed_cdk_index[1] = -1;
+ acelp_cfg->fixed_cdk_index[3] = -1;
+ }
+ else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) )
+ {
+ acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first );
+ acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0];
+ acelp_cfg->fixed_cdk_index[0] = -1;
+ acelp_cfg->fixed_cdk_index[2] = -1;
+ acelp_cfg->fixed_cdk_index[3] = -1;
+ }
+ else /* No FCB */
+ {
+ acelp_cfg->fixed_cdk_index[0] = -1;
+ acelp_cfg->fixed_cdk_index[1] = -1;
+ acelp_cfg->fixed_cdk_index[2] = -1;
+ acelp_cfg->fixed_cdk_index[3] = -1;
+ }
+ }
+ else if ( element_mode != IVAS_CPE_TD && GSC_IVAS_mode > 0 && L_frame == L_FRAME16k )
+ {
+ bits = 100; /* 9 kbps for fcb */
+ acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
+ }
+ else
+ {
+ acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
+ }
+ }
+ }
+
+ /* AVQ codebook */
+ if ( ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) || ( total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE ) )
+ {
+ for ( i = 0; i < nb_subfr; i++ )
+ {
+ if ( flag_hardcoded )
+ {
+ acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )];
+ {
+ bits -= acelp_cfg->AVQ_cdk_bits[i];
+ }
+ }
+
+ bits -= G_AVQ_BITS;
+ }
+
+ if ( core_brate_inp >= MIN_BRATE_AVQ_EXC && core_brate_inp <= MAX_BRATE_AVQ_EXC_TD && coder_type == GENERIC )
+ {
+ /* harm. flag ACELP AVQ */
+ bits--;
+ }
+
+ if ( !flag_hardcoded )
+ {
+ int16_t bit_tmp;
+
+ bit_tmp = bits / nb_subfr;
+ set_s( acelp_cfg->AVQ_cdk_bits, bit_tmp, nb_subfr );
+ bits -= bit_tmp * nb_subfr;
+
+ bit_tmp = bits % nb_subfr;
+ acelp_cfg->AVQ_cdk_bits[0] += bit_tmp;
+ bits -= bit_tmp;
+ }
+ }
+ }
+ else if ( ( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) || ( ( coder_type == INACTIVE || coder_type == AUDIO ) && nb_subfr == NB_SUBFR ) || ( coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) )
+ {
+ int32_t Local_BR, Pitch_BR;
+ int16_t Pitch_CT;
+
+ /* as defined at the beginning of [enc,dec]_pit_exc() */
+ if ( GSC_IVAS_mode > 0 && ( GSC_noisy_speech || core_brate > GSC_H_RATE_STG ) )
+ {
+ Local_BR = ACELP_8k00;
+ Pitch_CT = GENERIC;
+ Pitch_BR = ACELP_8k00;
+ if ( L_frame == L_FRAME16k )
+ {
+ Local_BR = ACELP_14k80;
+ if ( GSC_IVAS_mode > 0 && core_brate < IVAS_24k4 )
+ {
+ Local_BR = ACELP_9k60;
+ }
+ Pitch_BR = core_brate;
+ }
+ }
+ else if ( GSC_noisy_speech )
+ {
+ Local_BR = ACELP_7k20;
+ Pitch_CT = GENERIC;
+ Pitch_BR = ACELP_7k20;
+ if ( L_frame == L_FRAME16k )
+ {
+ Pitch_BR = core_brate;
+ }
+ }
+ else
+ {
+ Local_BR = ACELP_7k20;
+ Pitch_CT = AUDIO;
+ Pitch_BR = core_brate;
+
+ if ( L_frame == L_FRAME16k )
+ {
+ Local_BR = ACELP_13k20;
+ Pitch_CT = GENERIC;
+ }
+ }
+
+ for ( i = 0; i < nb_subfr; i++ )
+ {
+ if ( L_frame == L_FRAME16k )
+ {
+ acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )];
+ acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )];
+ }
+ else
+ {
+ acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )];
+ acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )];
+ acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX( ACELP_7k20, LOCAL_CT, i * L_SUBFR, 0 )];
+ }
+ }
+ }
+
+ if ( coder_type == TRANSITION && ( tc_call == 1 && tc_subfr == 0 && L_frame == L_FRAME ) )
+ {
+ return error;
+ }
+
+ /*-----------------------------------------------------------------*
+ * unused bits handling
+ *-----------------------------------------------------------------*/
+
+ acelp_cfg->ubits = 0; /* these bits could be reused for something else */
+
+ if ( flag_hardcoded && core_brate != PPP_NELP_2k80 )
+ {
+ /* unused bits */
+ if ( coder_type == AUDIO || ( coder_type == INACTIVE && core_brate <= ACELP_24k40 ) )
+ {
+ acelp_cfg->ubits = 0;
+ }
+ else if ( L_frame == L_FRAME )
+ {
+ acelp_cfg->ubits = reserved_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, -1, TC_SUBFR2IDX( tc_subfr ) )];
+ }
+ else
+ {
+ acelp_cfg->ubits = 0;
+ }
+
+ bits -= acelp_cfg->ubits;
+ }
+
+ /* sanity check */
+ if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || nb_subfr == NB_SUBFR16k )
+ {
+ if ( ( L_frame == L_FRAME16k && coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) || ( GSC_IVAS_mode > 0 && L_frame == L_FRAME16k ) ) /* GSC Inactive @16kHz */
+ {
+ acelp_cfg->ubits = 0;
+ }
+ else if ( flag_hardcoded && core == ACELP_CORE && bits != 0 )
+ {
+ }
+ else if ( bits > 0 && !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) )
+ {
+ if ( idchan > 0 && element_mode == IVAS_CPE_TD )
+ {
+ if ( !tdm_lp_reuse_flag )
+ {
+ acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */
+ bits = 0;
+ }
+ else
+ {
+ int16_t nb_prm = 4;
+
+ if ( tdm_low_rate_mode == 1 )
+ {
+ nb_prm = 2;
+ }
+ /* First add remaining bits on gains */
+ bits -= allocate_unused( core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode );
+
+ /* Then, Increase pitch bit budget */
+ if ( tdm_Pitch_reuse_flag == 0 && bits > 0 )
+ {
+ bits -= allocate_unused( core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits );
+ }
+
+ /* Increase mid-lsf bit budget */
+ if ( tdm_lp_reuse_flag == 0 && bits > 0 )
+ {
+ bits -= allocate_unused( core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits );
+ bits -= allocate_unused( core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits );
+ }
+ }
+ }
+
+ else if ( core == ACELP_CORE && coder_type >= UNVOICED && coder_type <= GENERIC && L_frame == L_FRAME )
+ {
+ acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */
+
+ if ( acelp_cfg->lsf_bits > 46 )
+ {
+ acelp_cfg->ubits = acelp_cfg->lsf_bits - 46;
+ acelp_cfg->lsf_bits = 46;
+ }
+ else if ( acelp_cfg->lsf_bits > 42 && L_frame == L_FRAME )
+ {
+ acelp_cfg->ubits = acelp_cfg->lsf_bits - 42;
+ acelp_cfg->lsf_bits = 42;
+ }
+ }
+ else
+ {
+ acelp_cfg->ubits = bits;
+ }
+ }
+ else if ( bits < 0 && !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) )
+ {
+ }
+ }
+
+ return error;
+}
+
+/*-------------------------------------------------------------------*
+ * allocate_unused()
+ *
+ * Allocate unused bits
+ *--------------------------------------------------------------------*/
+
+static int16_t allocate_unused(
+ const int32_t core_brate,
+ const int16_t coder_type,
+ const int16_t unused_bits,
+ const int16_t nb_prm,
+ const int16_t subfr,
+ const int16_t prm_type,
+ int16_t *prm_bit_mode )
+{
+ int16_t max_bit_per_pos = 0, bit_added = 0;
+
+ if ( prm_type == GAINSPRM )
+ {
+ max_bit_per_pos = 6;
+ if ( core_brate > ACELP_8k00 )
+ {
+ max_bit_per_pos = 7;
+ }
+ else if ( coder_type != UNVOICED )
+ {
+ if ( subfr >= 1 )
+ {
+ max_bit_per_pos = 7;
+ }
+ else if ( subfr == 0 )
+ {
+ max_bit_per_pos = 8;
+ }
+ }
+ else if ( coder_type == UNVOICED )
+ {
+ max_bit_per_pos = 9; /* No real limit on UC gain bit budget of the secondary channel */
+ }
+ }
+ else if ( prm_type == PITCHPRM )
+ {
+ max_bit_per_pos = 6;
+ if ( subfr == 0 || subfr == 2 || nb_prm == 2 )
+ {
+ max_bit_per_pos = 10;
+ }
+
+ if ( coder_type == UNVOICED )
+ {
+ max_bit_per_pos = 0; /* Should not allocate bits in case of unvoiced coder type */
+ }
+ }
+ else if ( prm_type == MID_LSFSPRM )
+ {
+ max_bit_per_pos = 5;
+ }
+ else if ( prm_type == LSFPRM )
+ {
+ max_bit_per_pos = 42;
+ }
+ else
+ {
+ }
+
+ max_bit_per_pos = min( unused_bits, max_bit_per_pos - prm_bit_mode[subfr] );
+ if ( max_bit_per_pos < 0 )
+ {
+ return 0;
+ }
+ else if ( max_bit_per_pos >= 0 && subfr == ( nb_prm - 1 ) )
+ {
+ prm_bit_mode[subfr] += max_bit_per_pos;
+ }
+ else
+ {
+ prm_bit_mode[subfr] += max_bit_per_pos;
+ bit_added += allocate_unused( core_brate, coder_type, unused_bits - max_bit_per_pos, nb_prm, subfr + 1, prm_type, &prm_bit_mode[0] );
+ }
+
+ return bit_added + max_bit_per_pos;
+}
+
+
+/*-------------------------------------------------------------------*
+ * set_ACELP_flag()
+ *
+ * set ACELP@16kHz flag
+ *--------------------------------------------------------------------*/
+
+/*! r: ACELP16k flag */
+int16_t set_ACELP_flag(
+ const int16_t element_mode, /* i : element mode */
+ const int32_t element_brate, /* i : element bitrate */
+ const int32_t total_brate, /* i : total bitrate per channel */
+ const int16_t idchan, /* i : Channel id */
+ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int16_t cng_type /* i : CNG type */
+)
+{
+ if ( element_mode == IVAS_CPE_DFT && idchan == 0 && total_brate <= SID_2k40 && bwidth == WB && cng_type == LP_CNG )
+ {
+
+ return 1;
+ }
+ else if ( element_mode == IVAS_CPE_TD )
+ {
+ if ( element_brate >= IVAS_24k4 && idchan == 0 && ( tdm_LRTD_flag == 0 || element_brate > IVAS_24k4 ) )
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else if ( element_mode == IVAS_CPE_DFT )
+ {
+ if ( element_brate >= IVAS_24k4 )
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else if ( element_mode == IVAS_SCE )
+ {
+ if ( element_brate >= SCE_CORE_16k_LOW_LIMIT )
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else if ( total_brate >= ACELP_16k_LOW_LIMIT ) /* EVS_MONO */
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c
new file mode 100644
index 0000000000000000000000000000000000000000..0aeed3040c4af49e164afc853feb42f903430095
--- /dev/null
+++ b/lib_com/bitstream.c
@@ -0,0 +1,2731 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "stat_enc.h"
+#include "stat_dec.h"
+#include "rom_com.h"
+#include "mime.h"
+#include "ivas_prot.h"
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "wmc_auto.h"
+
+
+#define STEP_MAX_NUM_INDICES 100 /* increase the maximum number of allowed indices in the list by this amount */
+
+
+/*-------------------------------------------------------------------*
+ * rate2AMRWB_IOmode()
+ *
+ * lookup AMRWB IO mode
+ *-------------------------------------------------------------------*/
+
+static Word16 rate2AMRWB_IOmode(
+ Word32 brate /* i : bitrate */
+)
+{
+ switch ( brate )
+ {
+ /* EVS AMR-WB IO modes */
+ case SID_1k75:
+ return AMRWB_IO_SID;
+ case ACELP_6k60:
+ return AMRWB_IO_6600;
+ case ACELP_8k85:
+ return AMRWB_IO_8850;
+ case ACELP_12k65:
+ return AMRWB_IO_1265;
+ case ACELP_14k25:
+ return AMRWB_IO_1425;
+ case ACELP_15k85:
+ return AMRWB_IO_1585;
+ case ACELP_18k25:
+ return AMRWB_IO_1825;
+ case ACELP_19k85:
+ return AMRWB_IO_1985;
+ case ACELP_23k05:
+ return AMRWB_IO_2305;
+ case ACELP_23k85:
+ return AMRWB_IO_2385;
+ default:
+ break;
+ }
+
+ return -1;
+}
+
+/*-------------------------------------------------------------------*
+ * rate2EVSmode()
+ *
+ * lookup EVS mode
+ *-------------------------------------------------------------------*/
+Word16 rate2EVSmode(
+ const Word32 brate, /* i : bitrate */
+ int16_t *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */
+)
+{
+ if ( is_amr_wb != NULL )
+ {
+ *is_amr_wb = 0;
+ }
+
+ switch ( brate )
+ {
+ /* EVS Primary modes */
+ case FRAME_NO_DATA:
+ return NO_DATA_RECEIVED;
+ case SID_2k40:
+ return PRIMARY_SID;
+ case PPP_NELP_2k80:
+ return PRIMARY_2800;
+ case ACELP_7k20:
+ return PRIMARY_7200;
+ case ACELP_8k00:
+ return PRIMARY_8000;
+ case ACELP_9k60:
+ return PRIMARY_9600;
+ case ACELP_13k20:
+ return PRIMARY_13200;
+ case ACELP_16k40:
+ return PRIMARY_16400;
+ case ACELP_24k40:
+ return PRIMARY_24400;
+ case ACELP_32k:
+ return PRIMARY_32000;
+ case ACELP_48k:
+ return PRIMARY_48000;
+ case ACELP_64k:
+ return PRIMARY_64000;
+ case HQ_96k:
+ return PRIMARY_96000;
+ case HQ_128k:
+ return PRIMARY_128000;
+ default:
+ break;
+ }
+
+ if ( is_amr_wb != NULL )
+ {
+ *is_amr_wb = 1;
+ }
+
+ return rate2AMRWB_IOmode( brate );
+}
+
+/*-------------------------------------------------------------------*
+ * ind_list_realloc()
+ *
+ * Re-allocate the list of indices
+ *-------------------------------------------------------------------*/
+
+ivas_error ind_list_realloc(
+ INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */
+ const int16_t max_num_indices, /* i : new maximum number of allowed indices in the list */
+ Encoder_Struct *st_ivas /* i : IVAS encoder structure */
+)
+{
+ int16_t i, n, ch, n_channels, ind_list_pos, is_metadata, ivas_max_num_indices;
+ INDICE_HANDLE new_ind_list;
+ BSTR_ENC_HANDLE hBstr;
+
+ if ( st_ivas == NULL )
+ {
+ return IVAS_ERR_OK;
+ }
+
+ /* get the pointer to the beginning of the old buffer of indices (either metadata or core coders) */
+ if ( old_ind_list == st_ivas->ind_list_metadata )
+ {
+ is_metadata = 1;
+ ivas_max_num_indices = st_ivas->ivas_max_num_indices_metadata;
+ }
+ else
+ {
+ is_metadata = 0;
+ ivas_max_num_indices = st_ivas->ivas_max_num_indices;
+ }
+
+ /* allocate new buffer of indices */
+ if ( ( new_ind_list = (INDICE_HANDLE) malloc( max_num_indices * sizeof( Indice ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) );
+ }
+
+ /* move indices from the old list to the new list */
+ for ( i = 0; i < min( max_num_indices, ivas_max_num_indices ); i++ )
+ {
+ if ( old_ind_list[i].nb_bits > -1 )
+ {
+ new_ind_list[i].id = old_ind_list[i].id;
+ new_ind_list[i].value = old_ind_list[i].value;
+ }
+ new_ind_list[i].nb_bits = old_ind_list[i].nb_bits;
+ }
+
+ /* reset nb_bits of all other indices to -1 */
+ for ( ; i < max_num_indices; i++ )
+ {
+ new_ind_list[i].nb_bits = -1;
+ }
+
+ /* update parameters in all SCE elements */
+ for ( n = 0; n < st_ivas->nSCE; n++ )
+ {
+ /* get the pointer to hBstr */
+ if ( is_metadata )
+ {
+ hBstr = st_ivas->hSCE[n]->hMetaData;
+ }
+ else
+ {
+ hBstr = st_ivas->hSCE[n]->hCoreCoder[0]->hBstr;
+ }
+
+ if ( hBstr != NULL )
+ {
+ /* get the current position inside the old list */
+ ind_list_pos = (int16_t) ( hBstr->ind_list - old_ind_list );
+
+ /* set pointers in the new list */
+ *( hBstr->ivas_ind_list_zero ) = new_ind_list;
+ hBstr->ind_list = &new_ind_list[ind_list_pos];
+
+ /* set the new maximum number of indices */
+ *( hBstr->ivas_max_num_indices ) = max_num_indices;
+ }
+ }
+
+ /* update parameters in all CPE elements */
+ for ( n = 0; n < st_ivas->nCPE; n++ )
+ {
+ /* get the pointer to hBstr */
+ if ( is_metadata )
+ {
+ n_channels = 1;
+ }
+ else
+ {
+ n_channels = CPE_CHANNELS;
+ }
+
+ for ( ch = 0; ch < n_channels; ch++ )
+ {
+ if ( is_metadata )
+ {
+ hBstr = st_ivas->hCPE[n]->hMetaData;
+ }
+ else
+ {
+ hBstr = st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr;
+ }
+
+ if ( hBstr != NULL )
+ {
+ /* get the current position inside the old list */
+ ind_list_pos = (int16_t) ( hBstr->ind_list - old_ind_list );
+
+ /* set pointers in the new list */
+ *( hBstr->ivas_ind_list_zero ) = new_ind_list;
+ hBstr->ind_list = &new_ind_list[ind_list_pos];
+
+ /* set the new maximum number of indices */
+ *( hBstr->ivas_max_num_indices ) = max_num_indices;
+ }
+ }
+ }
+
+ /* free the old list */
+ free( old_ind_list );
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * get_ivas_max_num_indices()
+ *
+ * Get the maximum allowed number of indices in the encoder
+ *-----------------------------------------------------------------------*/
+
+/*! r: maximum number of indices */
+int16_t get_ivas_max_num_indices(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ if ( ivas_format == STEREO_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 300;
+ }
+ else if ( ivas_total_brate <= IVAS_24k4 )
+ {
+ return 400;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 450;
+ }
+ else if ( ivas_total_brate <= IVAS_48k )
+ {
+ return 650;
+ }
+ else if ( ivas_total_brate <= IVAS_80k )
+ {
+ return 750;
+ }
+ else if ( ivas_total_brate <= IVAS_128k )
+ {
+ return 850;
+ }
+ else if ( ivas_total_brate <= IVAS_192k )
+ {
+ return 950;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 1350;
+ }
+ else
+ {
+ return 1650;
+ }
+ }
+ else if ( ivas_format == ISM_FORMAT || ivas_format == MONO_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 250;
+ }
+ else if ( ivas_total_brate <= IVAS_24k4 )
+ {
+ return 350;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 450;
+ }
+ else if ( ivas_total_brate <= IVAS_48k )
+ {
+ return 550;
+ }
+ else if ( ivas_total_brate <= IVAS_64k )
+ {
+ return 620;
+ }
+ else if ( ivas_total_brate <= IVAS_80k )
+ {
+ return 670;
+ }
+ else if ( ivas_total_brate <= IVAS_96k )
+ {
+ return 780;
+ }
+ else if ( ivas_total_brate <= IVAS_128k )
+ {
+ return 880;
+ }
+ else if ( ivas_total_brate <= IVAS_192k )
+ {
+ return 950;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 1100;
+ }
+ else if ( ivas_total_brate <= IVAS_384k )
+ {
+ return 1300;
+ }
+ else
+ {
+ return 1650;
+ }
+ }
+ else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 250;
+ }
+ else if ( ivas_total_brate <= IVAS_24k4 )
+ {
+ return 350;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 400;
+ }
+ else if ( ivas_total_brate <= IVAS_48k )
+ {
+ return 650;
+ }
+ else if ( ivas_total_brate <= IVAS_80k )
+ {
+ return 750;
+ }
+ else if ( ivas_total_brate <= IVAS_128k )
+ {
+ return 1020;
+ }
+ else if ( ivas_total_brate <= IVAS_160k )
+ {
+ return 1160;
+ }
+ else if ( ivas_total_brate <= IVAS_192k )
+ {
+ return 1220;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 1300;
+ }
+ else if ( ivas_total_brate <= IVAS_384k )
+ {
+ return 1720;
+ }
+ else
+ {
+ return 2000;
+ }
+ }
+ else if ( ivas_format == MASA_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 300;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 400;
+ }
+ else if ( ivas_total_brate <= IVAS_48k )
+ {
+ return 650;
+ }
+ else if ( ivas_total_brate <= IVAS_80k )
+ {
+ return 750;
+ }
+ else if ( ivas_total_brate <= IVAS_160k )
+ {
+ return 850;
+ }
+ else if ( ivas_total_brate <= IVAS_192k )
+ {
+ return 950;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 1150;
+ }
+ else if ( ivas_total_brate <= IVAS_384k )
+ {
+ return 1450;
+ }
+ else
+ {
+ return 1650;
+ }
+ }
+ else if ( ivas_format == MASA_ISM_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 300;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 400;
+ }
+ else if ( ivas_total_brate <= IVAS_48k )
+ {
+ return 650;
+ }
+ else if ( ivas_total_brate <= IVAS_80k )
+ {
+ return 750;
+ }
+ else if ( ivas_total_brate <= IVAS_160k )
+ {
+ return 1150;
+ }
+ else if ( ivas_total_brate <= IVAS_192k )
+ {
+ return 1250;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 1400;
+ }
+ else if ( ivas_total_brate <= IVAS_384k )
+ {
+ return 1650;
+ }
+ else
+ {
+ return 1850;
+ }
+ }
+ else if ( ivas_format == MC_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 250;
+ }
+ else if ( ivas_total_brate <= IVAS_24k4 )
+ {
+ return 350;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 400;
+ }
+ else if ( ivas_total_brate <= IVAS_48k )
+ {
+ return 650;
+ }
+ else if ( ivas_total_brate <= IVAS_64k )
+ {
+ return 750;
+ }
+ else if ( ivas_total_brate <= IVAS_80k )
+ {
+ return 850;
+ }
+ else if ( ivas_total_brate <= IVAS_128k )
+ {
+ return 1150;
+ }
+ else if ( ivas_total_brate <= IVAS_160k )
+ {
+ return 1420;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 2120;
+ }
+ else if ( ivas_total_brate <= IVAS_384k )
+ {
+ return 2250;
+ }
+ else
+ {
+ return 2450;
+ }
+ }
+
+ return 2450;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * get_BWE_max_num_indices()
+ *
+ * Get the maximum number of indices in the BWE
+ *-----------------------------------------------------------------------*/
+
+/*! r: maximum number of indices */
+int16_t get_BWE_max_num_indices(
+ const int32_t extl_brate /* i : extensiona layer bitrate */
+)
+{
+ /* set the maximum number of indices in the BWE */
+ if ( extl_brate < SWB_BWE_16k )
+ {
+ return 30;
+ }
+ else
+ {
+ return 150;
+ }
+}
+
+
+/*-----------------------------------------------------------------------*
+ * get_ivas_max_num_indices_metadata()
+ *
+ * Set the maximum allowed number of metadata indices in the list
+ *-----------------------------------------------------------------------*/
+
+/*! r: maximum number of indices */
+int16_t get_ivas_max_num_indices_metadata(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ /* set the maximum required number of metadata indices */
+ if ( ivas_format == MONO_FORMAT )
+ {
+ return 0;
+ }
+ else if ( ivas_format == STEREO_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 60;
+ }
+ else
+ {
+ return 80;
+ }
+ }
+ else if ( ivas_format == ISM_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 20;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 65;
+ }
+ else
+ {
+ return 80;
+ }
+ }
+ else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 100;
+ }
+ else if ( ivas_total_brate <= IVAS_24k4 )
+ {
+ return 200;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 300;
+ }
+ else if ( ivas_total_brate <= IVAS_192k )
+ {
+ return 500;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 1050;
+ }
+ else if ( ivas_total_brate <= IVAS_384k )
+ {
+ return 2000;
+ }
+ else
+ {
+ return 2500;
+ }
+ }
+ else if ( ivas_format == MASA_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 80;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 125;
+ }
+ else if ( ivas_total_brate <= IVAS_48k )
+ {
+ return 205;
+ }
+ else if ( ivas_total_brate <= IVAS_96k )
+ {
+ return 240;
+ }
+ else if ( ivas_total_brate <= IVAS_128k )
+ {
+ return 305;
+ }
+ else if ( ivas_total_brate <= IVAS_160k )
+ {
+ return 425;
+ }
+ else if ( ivas_total_brate <= IVAS_192k )
+ {
+ return 630;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 850;
+ }
+ else if ( ivas_total_brate <= IVAS_384k )
+ {
+ return 1000;
+ }
+ else
+ {
+ return 1750;
+ }
+ }
+ else if ( ivas_format == MASA_ISM_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ return 80;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ return 125 + 100;
+ }
+ else if ( ivas_total_brate <= IVAS_48k )
+ {
+ return 205 + 100;
+ }
+ else if ( ivas_total_brate <= IVAS_96k )
+ {
+ return 240 + 150;
+ }
+ else if ( ivas_total_brate <= IVAS_128k )
+ {
+ return 305 + 30;
+ }
+ else if ( ivas_total_brate <= IVAS_160k )
+ {
+ return 425 + 30;
+ }
+ else if ( ivas_total_brate <= IVAS_192k )
+ {
+ return 630 + 30;
+ }
+ else if ( ivas_total_brate <= IVAS_256k )
+ {
+ return 850 + 30;
+ }
+ else if ( ivas_total_brate <= IVAS_384k )
+ {
+ return 1000 + 30;
+ }
+ else
+ {
+ return 1750 + 30;
+ }
+ }
+ else if ( ivas_format == MC_FORMAT )
+ {
+ if ( ivas_total_brate <= IVAS_13k2 )
+ {
+ return 80;
+ }
+ else if ( ivas_total_brate <= IVAS_24k4 )
+ {
+ return 100;
+ }
+ else if ( ivas_total_brate <= IVAS_64k )
+ {
+ return 210;
+ }
+ else if ( ivas_total_brate <= IVAS_96k )
+ {
+ return 220;
+ }
+ else
+ {
+ return 300;
+ }
+ }
+
+ return 50;
+}
+
+/*-------------------------------------------------------------------*
+ * move_indices()
+ *
+ * Move indices inside the buffer or among two buffers
+ *-------------------------------------------------------------------*/
+
+void move_indices(
+ INDICE_HANDLE old_ind_list, /* i/o: old location of indices */
+ INDICE_HANDLE new_ind_list, /* i/o: new location of indices */
+ const int16_t nb_indices /* i : number of moved indices */
+)
+{
+ int16_t i;
+
+ if ( new_ind_list < old_ind_list )
+ {
+ for ( i = 0; i < nb_indices; i++ )
+ {
+ new_ind_list[i].id = old_ind_list[i].id;
+ new_ind_list[i].value = old_ind_list[i].value;
+ new_ind_list[i].nb_bits = old_ind_list[i].nb_bits;
+
+ old_ind_list[i].nb_bits = -1;
+ }
+ }
+ else if ( new_ind_list > old_ind_list )
+ {
+ for ( i = nb_indices - 1; i >= 0; i-- )
+ {
+ new_ind_list[i].id = old_ind_list[i].id;
+ new_ind_list[i].value = old_ind_list[i].value;
+ new_ind_list[i].nb_bits = old_ind_list[i].nb_bits;
+
+ old_ind_list[i].nb_bits = -1;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * check_ind_list_limits()
+ *
+ * Check, if the maximum number of indices has been reached -> reallocate
+ * Check, if we will not overwrite an existing indice -> adjust the location
+ *-------------------------------------------------------------------*/
+
+ivas_error check_ind_list_limits(
+ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */
+)
+{
+ Indice *ivas_ind_list_zero, *ivas_ind_list_last;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+ ivas_ind_list_zero = *( hBstr->ivas_ind_list_zero );
+
+ /* check, if the maximum number of indices has been reached and re-allocate the buffer */
+ /* the re-allocation can be avoided by increasing the limits in get_ivas_max_num_indices() or get_ivas_max_num_indices_metadata() */
+ if ( ( &hBstr->ind_list[hBstr->nb_ind_tot] - ivas_ind_list_zero ) >= *( hBstr->ivas_max_num_indices ) )
+ {
+
+ /* reallocate the buffer of indices with increased limit */
+ if ( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ /* check, if we will not overwrite an existing indice */
+ if ( hBstr->ind_list[hBstr->nb_ind_tot].nb_bits > 0 )
+ {
+ if ( hBstr->nb_ind_tot == 0 )
+ {
+ /* move the pointer to the next available empty slot */
+ ivas_ind_list_last = &ivas_ind_list_zero[*( hBstr->ivas_max_num_indices )];
+ while ( hBstr->ind_list[0].nb_bits > 0 && hBstr->ind_list < ivas_ind_list_last )
+ {
+ hBstr->ind_list++;
+ }
+
+ if ( hBstr->ind_list >= ivas_ind_list_last )
+ {
+
+ /* no available empty slot -> need to re-allocate the buffer */
+ if ( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ }
+ else
+ {
+ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Buffer of indices corrupted in frame %d! Attempt to overwrite indice ID = %d (value: %d, bits: %d)!\n", frame, hBstr->ind_list[hBstr->nb_ind_tot].id, hBstr->ind_list[hBstr->nb_ind_tot].value, hBstr->ind_list[hBstr->nb_ind_tot].nb_bits );
+ }
+ }
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------*
+ * push_indice()
+ *
+ * Push a new indice into the buffer
+ *-------------------------------------------------------------------*/
+
+ivas_error push_indice(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ int16_t id, /* i : ID of the indice */
+ uint16_t value, /* i : value of the quantized indice */
+ int16_t nb_bits /* i : number of bits used to quantize the indice */
+)
+{
+ int16_t i;
+ int16_t j;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+
+ /* check the limits of the list of indices */
+ if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK )
+ {
+ return IVAS_ERROR( error, "Error occured in push_indice() while re-allocating the list of indices (frame %d) !\n", frame );
+ }
+
+ /* find the location in the list of indices based on ID */
+ i = hBstr->nb_ind_tot;
+ while ( i > 0 && id < hBstr->ind_list[i - 1].id )
+ {
+ i--;
+ }
+
+ /* shift indices, if the new ID is to be written somewhere inside the list */
+ if ( i < hBstr->nb_ind_tot )
+ {
+ for ( j = hBstr->nb_ind_tot; j > i; j-- )
+ {
+ hBstr->ind_list[j].id = hBstr->ind_list[j - 1].id;
+ hBstr->ind_list[j].nb_bits = hBstr->ind_list[j - 1].nb_bits;
+ hBstr->ind_list[j].value = hBstr->ind_list[j - 1].value;
+ }
+ }
+
+
+ /* store the new indice in the list */
+ hBstr->ind_list[i].id = id;
+ hBstr->ind_list[i].value = value;
+ hBstr->ind_list[i].nb_bits = nb_bits;
+
+ /* updates */
+ hBstr->nb_ind_tot++;
+ hBstr->nb_bits_tot += nb_bits;
+
+ return error;
+}
+
+/*-------------------------------------------------------------------*
+ * push_next_indice()
+ *
+ * Push a new indice into the buffer at the next position
+ *-------------------------------------------------------------------*/
+
+ivas_error push_next_indice(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ uint16_t value, /* i : value of the quantized indice */
+ int16_t nb_bits /* i : number of bits used to quantize the indice */
+)
+{
+ int16_t prev_id;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+
+ /* check the limits of the list of indices */
+ if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ /* get the id of the previous indice -> it will be re-used */
+ if ( hBstr->nb_ind_tot > 0 )
+ {
+ prev_id = hBstr->ind_list[hBstr->nb_ind_tot - 1].id;
+ }
+ else
+ {
+ prev_id = 0;
+ }
+
+ /* store the values in the list */
+ hBstr->ind_list[hBstr->nb_ind_tot].id = prev_id;
+ hBstr->ind_list[hBstr->nb_ind_tot].value = value;
+ hBstr->ind_list[hBstr->nb_ind_tot].nb_bits = nb_bits;
+
+ /* updates */
+ hBstr->nb_ind_tot++;
+ hBstr->nb_bits_tot += nb_bits;
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------*
+ * push_next_bits()
+ * Push a bit buffer into the buffer at the next position
+ *-------------------------------------------------------------------*/
+
+ivas_error push_next_bits(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const uint16_t bits[], /* i : bit buffer to pack, sequence of single bits */
+ const int16_t nb_bits /* i : number of bits to pack */
+)
+{
+ uint16_t code;
+ int16_t i, nb_bits_m15;
+ Indice *ptr;
+ int16_t prev_id;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ ptr = &hBstr->ind_list[hBstr->nb_ind_tot];
+
+ /* get the id of the previous indice -> will be re-used */
+ if ( hBstr->nb_ind_tot > 0 )
+ {
+ prev_id = hBstr->ind_list[hBstr->nb_ind_tot - 1].id;
+ }
+ else
+ {
+ prev_id = 0;
+ }
+ nb_bits_m15 = nb_bits - 15;
+
+ for ( i = 0; i < nb_bits_m15; i += 16 )
+ {
+ code = (uint16_t) ( ( bits[i] << 15 ) | ( ( bits[i + 1] << 14 ) | ( ( bits[i + 2] << 13 ) | ( ( bits[i + 3] << 12 ) | ( ( bits[i + 4] << 11 ) | ( ( bits[i + 5] << 10 ) | ( ( bits[i + 6] << 9 ) | ( ( bits[i + 7] << 8 ) | ( ( bits[i + 8] << 7 ) | ( ( bits[i + 9] << 6 ) | ( ( bits[i + 10] << 5 ) | ( ( bits[i + 11] << 4 ) | ( ( bits[i + 12] << 3 ) | ( ( bits[i + 13] << 2 ) | ( ( bits[i + 14] << 1 ) | bits[i + 15] ) ) ) ) ) ) ) ) ) ) ) ) ) ) );
+
+ /* check the limits of the list of indices */
+ if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK )
+ {
+ return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n", frame );
+ }
+ ptr = &hBstr->ind_list[hBstr->nb_ind_tot];
+
+ ptr->value = code;
+ ptr->nb_bits = 16;
+ ptr->id = prev_id;
+ hBstr->nb_ind_tot++;
+ ++ptr;
+ }
+
+ for ( ; i < nb_bits; ++i )
+ {
+ /* check the limits of the list of indices */
+ if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK )
+ {
+ return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n", frame );
+ }
+ ptr = &hBstr->ind_list[hBstr->nb_ind_tot];
+
+ ptr->value = bits[i];
+ ptr->nb_bits = 1;
+ ptr->id = prev_id;
+ hBstr->nb_ind_tot++;
+ ++ptr;
+ }
+
+ hBstr->nb_bits_tot = hBstr->nb_bits_tot + nb_bits;
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------*
+ * find_indice()
+ *
+ * Find indice based on its id
+ *-------------------------------------------------------------------*/
+
+/*! r: result: index of the indice in the list, -1 if not found */
+int16_t find_indice(
+ BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */
+ const int16_t id, /* i : ID of the indice */
+ uint16_t *value, /* o : value of the quantized indice */
+ int16_t *nb_bits /* o : number of bits used to quantize the indice */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < hBstr->nb_ind_tot; i++ )
+ {
+ if ( hBstr->ind_list[i].id == id && hBstr->ind_list[i].nb_bits > 0 )
+ {
+ *value = hBstr->ind_list[i].value;
+ *nb_bits = hBstr->ind_list[i].nb_bits;
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------*
+ * delete_indice()
+ *
+ * Delete indice based on its id (note, that nb_ind_tot and nb_bits_tot are updated)
+ *-------------------------------------------------------------------*/
+
+/*! r: number of deleted indices */
+uint16_t delete_indice(
+ BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */
+ const int16_t id /* i : ID of the indice */
+)
+{
+ int16_t i, j;
+
+ j = 0;
+ for ( i = 0; i < hBstr->nb_ind_tot; i++ )
+ {
+ if ( hBstr->ind_list[i].id == id )
+ {
+ hBstr->nb_bits_tot -= hBstr->ind_list[i].nb_bits;
+ continue;
+ }
+
+ if ( j < i )
+ {
+ /* shift the indice left */
+ hBstr->ind_list[j].id = hBstr->ind_list[i].id;
+ hBstr->ind_list[j].value = hBstr->ind_list[i].value;
+ hBstr->ind_list[j].nb_bits = hBstr->ind_list[i].nb_bits;
+ }
+
+ j++;
+ }
+
+ hBstr->nb_ind_tot = j;
+
+ for ( ; j < i; j++ )
+ {
+ /* reset the shifted indices at the end of the list */
+ hBstr->ind_list[j].nb_bits = -1;
+ }
+
+ return i - j;
+}
+
+
+/*-------------------------------------------------------------------*
+ * get_next_indice()
+ *
+ * Get the next indice from the buffer
+ *-------------------------------------------------------------------*/
+
+/*! r: value of the indice */
+uint16_t get_next_indice(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+)
+{
+ uint16_t value;
+ int16_t i;
+ int32_t nbits_total;
+
+ assert( nb_bits <= 16 );
+
+ nbits_total = st->total_brate / FRAMES_PER_SEC;
+ /* detect corrupted bitstream */
+ if ( st->next_bit_pos + nb_bits > nbits_total )
+ {
+ st->BER_detect = 1;
+ return ( 0 );
+ }
+
+ value = 0;
+ for ( i = 0; i < nb_bits; i++ )
+ {
+ value <<= 1;
+ value += st->bit_stream[st->next_bit_pos + i];
+ }
+
+ /* update the position in the bitstream */
+ st->next_bit_pos += nb_bits;
+
+ return value;
+}
+
+/*-------------------------------------------------------------------*
+ * get_next_indice_1()
+ *
+ * Get the next 1-bit indice from the buffer
+ *-------------------------------------------------------------------*/
+
+/*! r: value of the indice */
+uint16_t get_next_indice_1(
+ Decoder_State *st /* i/o: decoder state structure */
+)
+{
+ int32_t nbits_total;
+ nbits_total = st->total_brate / FRAMES_PER_SEC;
+ /* detect corrupted bitstream */
+ if ( ( st->next_bit_pos + 1 > nbits_total && st->codec_mode == MODE1 ) ||
+ ( ( st->next_bit_pos + 1 > nbits_total + ( 2 * 8 ) ) && st->codec_mode == MODE2 ) /* add two zero bytes for arithmetic coder flush */
+ )
+ {
+ st->BER_detect = 1;
+ return ( 0 );
+ }
+
+ return st->bit_stream[st->next_bit_pos++];
+}
+
+/*-------------------------------------------------------------------*
+ * get_next_indice_tmp()
+ *
+ * update the total number of bits and the position in the bitstream
+ *-------------------------------------------------------------------*/
+
+void get_next_indice_tmp(
+ Decoder_State *st, /* o : decoder state structure */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+)
+{
+ /* update the position in the bitstream */
+ st->next_bit_pos += nb_bits;
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * get_indice()
+ *
+ * Get indice at specific position in the buffer
+ *-------------------------------------------------------------------*/
+
+/*! r: value of the indice */
+uint16_t get_indice(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t pos, /* i : absolute position in the bitstream (update after the read) */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+)
+{
+ uint16_t value;
+ int16_t i;
+ int32_t nbits_total;
+
+ assert( nb_bits <= 16 );
+
+ nbits_total = st->total_brate / FRAMES_PER_SEC;
+
+ /* detect corrupted bitstream */
+ if ( pos + nb_bits > nbits_total )
+ {
+ st->BER_detect = 1;
+ return ( 0 );
+ }
+
+ value = 0;
+ for ( i = 0; i < nb_bits; i++ )
+ {
+ value <<= 1;
+ value += st->bit_stream[pos + i];
+ }
+ return value;
+}
+
+/*-------------------------------------------------------------------*
+ * get_indice_st()
+ *
+ * Get indice at specific position in the buffer
+ *-------------------------------------------------------------------*/
+
+/*! r: value of the indice */
+uint16_t get_indice_st(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t pos, /* i : absolute position in the bitstream */
+ const int16_t nb_bits /* i : number of bits to quantize the indice */
+)
+{
+ uint16_t value;
+ int16_t i;
+
+ assert( nb_bits <= 16 );
+
+ /* detect corrupted bitstream */
+ if ( pos + nb_bits > element_brate / FRAMES_PER_SEC )
+ {
+ st->BER_detect = 1;
+ return ( 0 );
+ }
+
+ value = 0;
+ for ( i = 0; i < nb_bits; i++ )
+ {
+ value <<= 1;
+ value += st->bit_stream[pos + i];
+ }
+
+ return value;
+}
+
+/*-------------------------------------------------------------------*
+ * get_indice_1()
+ *
+ * Get a 1-bit indice at specific position in the buffer
+ *-------------------------------------------------------------------*/
+
+/*! r: value of the indice */
+uint16_t get_indice_1(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t pos /* i : absolute position in the bitstream (update after the read) */
+)
+{
+ int32_t nbits_total;
+ nbits_total = st->total_brate / FRAMES_PER_SEC;
+ /* detect corrupted bitstream */
+ if ( pos + 1 > nbits_total )
+ {
+ st->BER_detect = 1;
+ return ( 0 );
+ }
+
+ return st->bit_stream[pos];
+}
+
+#define WMC_TOOL_SKIP
+
+/*-------------------------------------------------------------------*
+ * reset_indices_enc()
+ *
+ * Reset the buffer of encoder indices
+ *-------------------------------------------------------------------*/
+
+void reset_indices_enc(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t max_num_indices /* i : max number of indices */
+)
+{
+ int16_t i;
+
+ hBstr->nb_bits_tot = 0;
+ hBstr->nb_ind_tot = 0;
+
+ for ( i = 0; i < max_num_indices; i++ )
+ {
+ hBstr->ind_list[i].nb_bits = -1;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * reset_indices_dec()
+ *
+ * Reset the buffer of decoder indices
+ *-------------------------------------------------------------------*/
+
+void reset_indices_dec(
+ Decoder_State *st )
+{
+ st->next_bit_pos = 0;
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * write_indices_to_stream()
+ *
+ * writing forward or backward to a serial stream
+ *-------------------------------------------------------------------*/
+
+static int16_t write_indices_to_stream(
+ Indice *ind_list,
+ uint16_t **pt_stream,
+ const int16_t inc,
+ const int16_t num_indices )
+{
+ int16_t i, k;
+ int16_t value, nb_bits;
+ uint16_t mask;
+
+ for ( i = 0; i < num_indices; i++ )
+ {
+ value = ind_list[i].value;
+ nb_bits = ind_list[i].nb_bits;
+
+ if ( nb_bits > 0 )
+ {
+ /* mask from MSB to LSB */
+ mask = 1 << ( nb_bits - 1 );
+
+ /* write bit by bit */
+ for ( k = 0; k < nb_bits; k++ )
+ {
+ if ( value & mask )
+ {
+ **pt_stream = 1;
+ *pt_stream += inc;
+ }
+ else
+ {
+ **pt_stream = 0;
+ *pt_stream += inc;
+ }
+
+ mask >>= 1;
+ }
+ }
+ }
+ return 0;
+}
+
+/*-------------------------------------------------------------------*
+ * write_indices_element()
+ *
+ * Bitstream writing function of one element (one SCE or one CPE)
+ *-------------------------------------------------------------------*/
+
+static ivas_error write_indices_element(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ uint16_t **pt_stream, /* i : pointer to bitstream buffer */
+ const int16_t is_SCE, /* i : flag to distingusih SCE and CPE */
+ const int16_t element_id /* i : id of the SCE or CPE */
+)
+{
+ int16_t ch;
+ Encoder_State **sts = NULL;
+ uint16_t *pt_stream_loc;
+ uint16_t *pt_stream_backup;
+ uint16_t *pt_stream_end;
+ int16_t nb_bits_tot_metadata;
+ int16_t nb_ind_tot_metadata;
+
+ Indice *ind_list_metadata;
+ int16_t n, n_channels;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ ind_list_metadata = NULL;
+ nb_ind_tot_metadata = 0;
+
+ if ( st_ivas->hEncoderConfig->ivas_format == MONO_FORMAT )
+ {
+ sts = st_ivas->hSCE[0]->hCoreCoder;
+ nb_bits_tot_metadata = 0;
+ }
+ else
+ {
+ nb_bits_tot_metadata = 0;
+ if ( is_SCE && st_ivas->hSCE[element_id] != NULL )
+ {
+ sts = st_ivas->hSCE[element_id]->hCoreCoder;
+
+ if ( st_ivas->hSCE[element_id]->hMetaData != NULL )
+ {
+ nb_bits_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_bits_tot;
+ ind_list_metadata = st_ivas->hSCE[element_id]->hMetaData->ind_list;
+ nb_ind_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot;
+ }
+ }
+ else if ( !is_SCE && st_ivas->hCPE[element_id] != NULL )
+ {
+ sts = st_ivas->hCPE[element_id]->hCoreCoder;
+
+ if ( st_ivas->hCPE[element_id]->hMetaData != NULL )
+ {
+ nb_bits_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_bits_tot;
+ ind_list_metadata = st_ivas->hCPE[element_id]->hMetaData->ind_list;
+ nb_ind_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot;
+ }
+ }
+ }
+
+ n_channels = 1;
+ if ( sts[0]->element_mode > IVAS_CPE_DFT )
+ {
+ n_channels = CPE_CHANNELS;
+ }
+
+ /*----------------------------------------------------------------*
+ * Bitstream packing (conversion of individual indices into a serial stream)
+ *----------------------------------------------------------------*/
+
+ pt_stream_loc = *pt_stream;
+ pt_stream_end = pt_stream_loc;
+
+ for ( n = 0; n < n_channels; n++ )
+ {
+ /* write the metadata buffer */
+ if ( n == 0 && nb_bits_tot_metadata != 0 )
+ {
+ pt_stream_backup = pt_stream_loc;
+
+ for ( ch = 0; ch < n_channels; ch++ )
+ {
+ pt_stream_loc += sts[ch]->hBstr->nb_bits_tot;
+ }
+ pt_stream_loc += nb_bits_tot_metadata - 1;
+ pt_stream_end = pt_stream_loc + 1;
+
+ write_indices_to_stream( ind_list_metadata, &pt_stream_loc, -1,
+ nb_ind_tot_metadata );
+
+ /* restore previous pointer position */
+ pt_stream_loc = pt_stream_backup;
+ }
+ write_indices_to_stream( sts[n]->hBstr->ind_list, &pt_stream_loc, 1,
+ sts[n]->hBstr->nb_ind_tot );
+
+ if ( pt_stream_loc > pt_stream_end )
+ {
+ pt_stream_end = pt_stream_loc;
+ }
+ }
+
+ /*----------------------------------------------------------------*
+ * Clearing of indices
+ * Reset index pointers
+ *----------------------------------------------------------------*/
+
+ if ( is_SCE ) /* EVS and SCE */
+ {
+ if ( st_ivas->hSCE[element_id]->hMetaData != NULL )
+ {
+ reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot );
+ }
+
+ reset_indices_enc( sts[0]->hBstr, sts[0]->hBstr->nb_ind_tot );
+ }
+ else
+ {
+ if ( st_ivas->hCPE[element_id]->hMetaData != NULL )
+ {
+ reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot );
+ }
+
+ for ( n = 0; n < n_channels; n++ )
+ {
+ reset_indices_enc( sts[n]->hBstr, sts[n]->hBstr->nb_ind_tot );
+ }
+ }
+
+ /* update pointer */
+ *pt_stream = pt_stream_end;
+
+ return error;
+}
+
+/*-------------------------------------------------------------------*
+ * write_indices_ivas()
+ *
+ * Write the buffer of indices to a serial bitstream buffer,
+ * each bit represented as a uint16_t of value 0 or 1
+ *-------------------------------------------------------------------*/
+
+ivas_error write_indices_ivas(
+ Encoder_Struct *st_ivas, /* i/o: encoder state structure */
+ uint16_t *bit_stream, /* i/o: output bitstream */
+ uint16_t *num_bits /* i : number of indices written to output */
+)
+{
+ int16_t i, n;
+ uint16_t *pt_stream;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ pt_stream = bit_stream;
+ for ( i = 0; i < MAX_BITS_PER_FRAME; ++i )
+ {
+ bit_stream[i] = 0;
+ }
+
+
+ /*-----------------------------------------------------------------*
+ * Encode Payload
+ *-----------------------------------------------------------------*/
+
+ for ( n = 0; n < st_ivas->nSCE; n++ )
+ {
+ write_indices_element( st_ivas, &pt_stream, 1, n );
+ }
+
+ for ( n = 0; n < st_ivas->nCPE; n++ )
+ {
+ write_indices_element( st_ivas, &pt_stream, 0, n );
+ }
+
+ *num_bits = (uint16_t) ( pt_stream - bit_stream );
+
+ return error;
+}
+
+
+/*---------------------------------------------------------------------*
+ * convertSerialToBytestream( )
+ *
+ * convert 16-bit short serial streams with 0x0000 and 0x0001 to a bytstream
+ *---------------------------------------------------------------------*/
+
+void convertSerialToBytestream(
+ const uint16_t *const serial, /* i : input serial bitstream with values 0 and 1 */
+ const uint16_t num_bits, /* i : number of bits in the input bitstream */
+ uint8_t *const bytestream /* o : output compact bitstream (bytestream) */
+)
+{
+ uint32_t i;
+ uint8_t bit, bitinbyte;
+
+ for ( i = 0; i < num_bits; ++i )
+ {
+ bit = ( serial[i] == 0x0001 ) ? 1 : 0;
+ bitinbyte = bit << ( 7 - ( i & 0x7 ) );
+ if ( !( i & 0x7 ) )
+ {
+ bytestream[i >> 3] = 0;
+ }
+ bytestream[i >> 3] |= bitinbyte;
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * convertBytestreamToSerial( )
+ *
+ * convert bytestream to 16-bit short serial streams with 0x0000 and 0x0001
+ *---------------------------------------------------------------------*/
+
+void convertBytestreamToSerial(
+ const uint8_t *const bytestream, /* i : input compact bitstream (bytestream) */
+ const uint16_t num_bits, /* i : number of bits in the input bitstream */
+ uint16_t *const serial /* o : output serial bitstream with values 0 and 1 */
+)
+{
+ uint32_t i;
+
+ for ( i = 0; i < num_bits; ++i )
+ {
+ serial[i] = ( bytestream[( i >> 3 )] >> ( 7 - ( i & 7 ) ) ) & 0x1;
+ }
+}
+
+/*-------------------------------------------------------------------*
+ * decoder_selectCodec()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void decoder_selectCodec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t bit0 /* i : first bit */
+)
+{
+ /* set the AMR-WB IO flag */
+ if ( rate2AMRWB_IOmode( total_brate ) != -1 )
+ {
+ st->Opt_AMR_WB = 1;
+ }
+ else if ( total_brate != FRAME_NO_DATA )
+ {
+ st->Opt_AMR_WB = 0;
+ }
+
+ if ( st->Opt_AMR_WB )
+ {
+ st->codec_mode = MODE1;
+ }
+ else
+ {
+ st->codec_mode = get_codec_mode( total_brate );
+
+ if ( st->codec_mode == -1 )
+ {
+ switch ( total_brate )
+ {
+ case 0:
+ st->codec_mode = st->last_codec_mode;
+ break;
+ case 2400:
+ st->codec_mode = st->last_codec_mode;
+ break;
+ case 2800:
+ st->codec_mode = MODE1;
+ break;
+ default: /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bitrates */
+ st->codec_mode = st->last_codec_mode;
+ st->bfi = 1;
+ break;
+ }
+ }
+ }
+
+ if ( st->ini_frame == 0 )
+ {
+ if ( st->codec_mode == -1 )
+ {
+ st->codec_mode = MODE1;
+ }
+ st->last_codec_mode = st->codec_mode;
+ }
+
+ /* set SID/CNG type */
+ if ( total_brate == SID_2k40 )
+ {
+ if ( bit0 == 0 )
+ {
+ st->cng_type = LP_CNG;
+
+ /* force MODE1 when selecting LP_CNG */
+ st->codec_mode = MODE1;
+ }
+ else if ( bit0 == 1 )
+ {
+ st->cng_type = FD_CNG;
+ if ( st->last_codec_mode == MODE2 && st->last_total_brate == ACELP_13k20 )
+ {
+ st->codec_mode = MODE1;
+ }
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * dec_prm_core()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void dec_prm_core(
+ Decoder_State *st )
+{
+ int16_t n, frame_size_index = -1;
+
+ st->core = -1;
+
+ if ( st->total_brate == FRAME_NO_DATA )
+ {
+ st->m_frame_type = ZERO_FRAME;
+ }
+ else if ( st->total_brate == SID_2k40 )
+ {
+ st->m_frame_type = SID_FRAME;
+ }
+ else
+ {
+ st->m_frame_type = ACTIVE_FRAME;
+ for ( n = 0; n < FRAME_SIZE_NB; ++n )
+ {
+ if ( FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC )
+ {
+ frame_size_index = n;
+ break;
+ }
+ }
+
+ /* Get audio bandwidth info */
+ st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits );
+ st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min;
+ if ( st->bwidth > FB )
+ {
+ st->bwidth = FB;
+ st->BER_detect = 1;
+ }
+
+ if ( st->bwidth > SWB && st->total_brate < ACELP_16k40 )
+ {
+ st->bwidth = SWB;
+ st->BER_detect = 1;
+ }
+ /* Skip reserved bit */
+ get_next_indice_tmp( st, FrameSizeConfig[frame_size_index].reserved_bits );
+
+ if ( get_next_indice_1( st ) ) /* TCX */
+ {
+ if ( get_next_indice_1( st ) )
+ {
+ st->core = HQ_CORE;
+ }
+ else
+ {
+ st->core = TCX_20_CORE;
+ }
+ }
+ else /* ACELP */
+ {
+ st->core = ACELP_CORE;
+ }
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * decision_matrix_core_dec()
+ *
+ * Read core signaling bits from the bitstream
+ * Set st->core, and st->bwidth if signalled together with the core.
+ *-----------------------------------------------------------------*/
+
+static void decision_matrix_core_dec(
+ Decoder_State *st /* i/o: decoder state structure */
+)
+{
+ int16_t start_idx;
+ int32_t ind;
+ int16_t nBits;
+
+ assert( st->bfi != 1 );
+
+ st->core = -1;
+ st->bwidth = -1;
+
+ if ( st->total_brate == FRAME_NO_DATA || st->total_brate == SID_2k40 )
+ {
+ st->core = ACELP_CORE;
+ }
+ /* SC-VBR */
+ else if ( st->total_brate == PPP_NELP_2k80 )
+ {
+ st->core = ACELP_CORE;
+ return;
+ }
+
+ /*---------------------------------------------------------------------*
+ * ACELP/HQ core selection
+ *---------------------------------------------------------------------*/
+
+ if ( st->total_brate < ACELP_24k40 )
+ {
+ st->core = ACELP_CORE;
+ }
+ else if ( st->total_brate >= ACELP_24k40 && st->total_brate <= ACELP_64k )
+ {
+ /* read the ACELP/HQ core selection bit */
+ st->core = get_next_indice( st, 1 ) * HQ_CORE;
+ }
+ else
+ {
+ st->core = HQ_CORE;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Read ACELP signaling bits from the bitstream
+ *-----------------------------------------------------------------*/
+
+ if ( st->core == ACELP_CORE )
+ {
+ /* find the section in the ACELP signaling table corresponding to bitrate */
+ start_idx = 0;
+ while ( acelp_sig_tbl[start_idx] != st->total_brate )
+ {
+ start_idx++;
+ }
+
+ /* skip the bitrate */
+ start_idx += 1;
+
+ /* retrieve the number of bits */
+ nBits = (int16_t) acelp_sig_tbl[start_idx++];
+
+ /* retrieve the signaling indice */
+ ind = acelp_sig_tbl[start_idx + get_next_indice( st, nBits )];
+ st->bwidth = ( ind >> 3 ) & 0x7;
+
+ /* convert signaling indice into signaling information */
+ if ( ( ind & 0x7 ) == LR_MDCT )
+ {
+ st->core = HQ_CORE;
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Read HQ signaling bits from the bitstream
+ * Set HQ core type
+ *-----------------------------------------------------------------*/
+
+ if ( st->core == HQ_CORE )
+ {
+ /* read the HQ/TCX core switching flag */
+ if ( get_next_indice( st, 1 ) )
+ {
+ st->core = TCX_20_CORE;
+ }
+
+ /* For TCX: read/set band-width (needed for different I/O sampling rate support) */
+ if ( st->core == TCX_20_CORE && st->total_brate > ACELP_16k40 )
+ {
+ ind = get_next_indice( st, 2 );
+
+ if ( ind == 0 )
+ {
+ st->bwidth = NB;
+ }
+ else if ( ind == 1 )
+ {
+ st->bwidth = WB;
+ }
+ else if ( ind == 2 )
+ {
+ st->bwidth = SWB;
+ }
+ else
+ {
+ st->bwidth = FB;
+ }
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * mdct_switching_dec()
+ *
+ * Set up MDCT core switching if indicated in the bitstream
+ *-------------------------------------------------------------------*/
+
+void mdct_switching_dec(
+ Decoder_State *st /* i/o: decoder state structure */
+)
+{
+ if ( !st->bfi )
+ {
+
+ if ( st->Opt_AMR_WB )
+ {
+ return;
+ }
+
+
+ if ( st->total_brate == ACELP_13k20 || st->total_brate == ACELP_32k )
+ {
+ st->mdct_sw_enable = MODE1;
+ }
+ else if ( ACELP_16k40 <= st->total_brate && st->total_brate <= ACELP_24k40 )
+ {
+ st->mdct_sw_enable = MODE2;
+ }
+
+ if ( st->codec_mode == MODE1 && st->mdct_sw_enable == MODE1 )
+ {
+ /* Read ahead core signaling */
+ int16_t next_bit_pos_save = st->next_bit_pos;
+ int16_t core_save = st->core;
+ int16_t bwidth_save = st->bwidth;
+
+ decision_matrix_core_dec( st ); /* sets st->core */
+
+ if ( st->core == TCX_20_CORE )
+ {
+ /* Trigger TCX */
+ st->codec_mode = MODE2;
+ st->mdct_sw = MODE1;
+ }
+ else
+ {
+ /* Rewind bitstream */
+ st->next_bit_pos = next_bit_pos_save;
+ if ( st->bfi )
+ {
+ st->core = core_save;
+ st->bwidth = bwidth_save;
+ }
+ }
+ }
+ else if ( st->codec_mode == MODE2 && st->mdct_sw_enable == MODE2 )
+ {
+ /* Read ahead core signaling */
+ int16_t next_bit_pos_save = st->next_bit_pos;
+ int16_t core_save = st->core;
+ int16_t bwidth_save = st->bwidth;
+
+ dec_prm_core( st ); /* sets st->core */
+
+ if ( st->core == HQ_CORE )
+ {
+ /* Trigger HQ_CORE */
+ st->codec_mode = MODE1;
+ st->mdct_sw = MODE2;
+ }
+ else
+ {
+ /* Rewind bitstream */
+ st->next_bit_pos = next_bit_pos_save;
+ if ( st->bfi )
+ {
+ st->core = core_save;
+ }
+ /* always reset bwidth, to not interfere with BER logic */
+ st->bwidth = bwidth_save;
+ }
+ }
+ }
+
+ return;
+}
+
+
+
+
+
+/*-------------------------------------------------------------------*
+ * reset_elements()
+ *
+ * Simulate packet losses by reading FEC pattern from external file
+ *-------------------------------------------------------------------*/
+
+Decoder_State **reset_elements(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+)
+{
+ int16_t k, n;
+ Decoder_State **sts = NULL; /* to avoid compilation warning */
+
+ for ( k = 0; k < st_ivas->nSCE; k++ )
+ {
+ sts = st_ivas->hSCE[k]->hCoreCoder;
+
+ sts[0]->bfi = 0;
+ sts[0]->BER_detect = 0;
+ sts[0]->mdct_sw_enable = 0;
+ sts[0]->mdct_sw = 0;
+
+ reset_indices_dec( sts[0] );
+ }
+
+ for ( k = 0; k < st_ivas->nCPE; k++ )
+ {
+ sts = st_ivas->hCPE[k]->hCoreCoder;
+
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ sts[n]->bfi = 0;
+ sts[n]->BER_detect = 0;
+ sts[n]->mdct_sw_enable = 0;
+ sts[n]->mdct_sw = 0;
+
+ reset_indices_dec( sts[n] );
+ }
+ }
+
+ return sts; /* return last decoder state */
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_set_bitstream_pointers()
+ *
+ * Set bitstream pointers for every SCE/CPE Core-Decoder
+ *-------------------------------------------------------------------*/
+
+void ivas_set_bitstream_pointers(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+)
+{
+ int16_t k, num_bits;
+ Decoder_State **sts;
+
+ num_bits = 0;
+
+ /* set bitstream pointers for SCEs */
+ for ( k = 0; k < st_ivas->nSCE; k++ )
+ {
+ sts = st_ivas->hSCE[k]->hCoreCoder;
+ sts[0]->bit_stream = st_ivas->bit_stream + num_bits;
+ num_bits += (int16_t) ( st_ivas->hSCE[k]->element_brate / FRAMES_PER_SEC );
+ }
+
+ /* set bitstream pointers for CPEs */
+ for ( k = 0; k < st_ivas->nCPE; k++ )
+ {
+ sts = st_ivas->hCPE[k]->hCoreCoder;
+ sts[0]->bit_stream = st_ivas->bit_stream + num_bits;
+ num_bits += (int16_t) ( st_ivas->hCPE[k]->element_brate / FRAMES_PER_SEC );
+ }
+
+ return;
+}
+
+
+
+
+/*-------------------------------------------------------------------*
+ * read_indices()
+ *
+ * Read indices from an ITU-T G.192 bitstream to the buffer
+ * Simulate packet losses by inserting frame erasures
+ *-------------------------------------------------------------------*/
+
+/*! r: 1 = reading OK, 0 = problem */
+ivas_error read_indices(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ uint16_t bit_stream[], /* i : bitstream buffer */
+ UWord16 num_bits, /* i : number of bits in bitstream */
+ int16_t *prev_ft_speech,
+ int16_t *CNG,
+ int16_t bfi /* i : bad frame indicator */
+)
+{
+ int16_t k;
+ Decoder_State **sts;
+ int32_t total_brate = 0;
+ int16_t curr_ft_good_sp, curr_ft_bad_sp;
+ int16_t g192_sid_first, sid_upd_bad, sid_update;
+ int16_t speech_bad, speech_lost;
+ int16_t n;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ st_ivas->BER_detect = 0;
+ sts = reset_elements( st_ivas );
+
+ st_ivas->bfi = bfi;
+
+ /* convert the frame length to total bitrate */
+ total_brate = (int32_t) ( num_bits * FRAMES_PER_SEC );
+
+ /* verify that a valid num bits value is present in the G.192 file */
+ /* only AMRWB, EVS or IVAS bitrates or 0(NO DATA) are allowed in G.192 file frame reading */
+ if ( st_ivas->ivas_format != MONO_FORMAT )
+ {
+ k = 0;
+ while ( k < SIZE_IVAS_BRATE_TBL && total_brate != ivas_brate_tbl[k] )
+ {
+ k++;
+ }
+
+ if ( st_ivas->ivas_format == ISM_FORMAT && ( k < SIZE_IVAS_BRATE_TBL || total_brate <= SID_2k40 ) )
+ {
+ st_ivas->element_mode_init = IVAS_SCE;
+ }
+ else if ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) && ( total_brate <= SID_2k40 ) )
+ {
+ st_ivas->element_mode_init = IVAS_SCE;
+ }
+ else if ( k == SIZE_IVAS_BRATE_TBL )
+ {
+ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) in the G.192 frame ! Exiting ! \n", total_brate );
+ }
+ else
+ {
+ st_ivas->element_mode_init = -1;
+ }
+ }
+ else /* AMRWB or EVS */
+ {
+ st_ivas->element_mode_init = EVS_MONO;
+
+ if ( rate2EVSmode( total_brate, NULL ) < 0 ) /* negative value means that a valid rate was not found */
+ {
+ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) in the G.192 frame ! Exiting ! \n", total_brate );
+ }
+ }
+
+ /* G.192 RX DTX handler*/
+ /* handle SID_FIRST, SID_BAD, SPEECH_LOST, NO_DATA as properly as possible for the ITU-T G.192 format */
+ /* (total_brate, bfi , st_CNG) = rx_handler(received frame type, [previous frame type], past CNG state, past core) */
+ curr_ft_good_sp = 0;
+ curr_ft_bad_sp = 0;
+
+ if ( is_DTXrate( total_brate ) == 0 )
+ {
+ if ( st_ivas->bfi == 0 )
+ {
+ curr_ft_good_sp = 1;
+ }
+ else
+ {
+ curr_ft_bad_sp = 1;
+ }
+ }
+
+ sid_update = 0;
+ sid_upd_bad = 0;
+ if ( is_SIDrate( total_brate ) == 1 )
+ {
+ if ( st_ivas->bfi == 0 )
+ {
+ sid_update = 1;
+ }
+ else
+ {
+ sid_upd_bad = 1; /* this frame type may happen in ETSI/3GPP CS cases, a corrupt SID frames */
+ }
+ }
+
+ /* all zero indices/bits iSP AMRWB SID_update results in a valid LP filter with extremely high LP-filter-gain */
+ /* all zero indices/bits may be a result of CS bit errors and/or erroneously injected by gateways or by a bad dejitter handlers */
+ if ( total_brate == SID_1k75 && sid_update == 1 )
+ {
+ /* valid sid_update received, check for very risky but formally valid content */
+ int16_t sum = 0;
+ for ( k = 0; k < num_bits; ++k )
+ {
+ sum += ( bit_stream[k] == 1 ); /* check of 35 zeroes */
+ }
+ if ( sum == 0 )
+ { /* all zeros */
+ sid_upd_bad = 1; /* initial signal as corrupt (BER likely) */
+ }
+ }
+
+ /* AMRWB 26.173 G.192 file reader (read_serial) does not declare/use SID_BAD ft,
+ it declares every bad synch marked frame initially as a lost_speech frame,
+ and then the RXDTX handler CNG state decides the decoding mode CNG/SPEECH.
+ While In the AMRWB ETSI/3GPP format eid a CRC error in a detected SID_UPDATE frames triggers SID_BAD.
+
+ Here we inhibit use of the SID-length info, even though it is available in the G.192 file format after STL/EID-XOR .
+ */
+ if ( sid_upd_bad )
+ {
+ sid_upd_bad = 0;
+ total_brate = FRAME_NO_DATA; /* treat SID_BAD as a stolen signaling frame --> SPEECH LOST */
+ }
+
+ g192_sid_first = 0;
+ if ( st_ivas->ivas_format == MONO_FORMAT && sts[0]->core == AMR_WB_CORE && *prev_ft_speech && total_brate == FRAME_NO_DATA && st_ivas->bfi == 0 )
+ {
+ g192_sid_first = 1; /* SID_FIRST detected for previous AMRWB/AMRWBIO active frames only */
+ /* It is not possible to perfectly simulate rate switching conditions EVS->AMRWBIO where:
+ the very first SID_FIRST detection is based on a past EVS active frame
+ and a good length 0 "SID_FIRST"(NO_DATA) frame is sent in AMRWBIO,
+ due to the one frame state memory in the AMRWB legacy G.192 SID_FIRST encoding
+ */
+ }
+
+ speech_bad = 0;
+ if ( st_ivas->bfi != 0 && ( is_DTXrate( total_brate ) == 0 ) )
+ {
+ speech_bad = 1; /* initial ft assumption, CNG_state decides what to do */
+ }
+
+ speech_lost = 0;
+ if ( total_brate == FRAME_NO_DATA && st_ivas->bfi != 0 ) /* unsent NO_DATA or stolen NO_DATA/signaling frame */
+ {
+ speech_lost = 1; /* initial ft assumption, CNG_state decides what to do */
+ }
+
+ /* Do not allow decoder to enter CNG-synthesis for any instantly received GOOD+LENGTH==0 frame
+ as this frame was never transmitted, one can not know it is good and has a a length of zero ) */
+ if ( *CNG != 0 )
+ {
+ /* We were in CNG synthesis */
+ if ( curr_ft_good_sp != 0 )
+ {
+ /* only a good speech frame makes you leave CNG synthesis */
+ *CNG = 0;
+ }
+ }
+ else
+ {
+ /* We were in SPEECH synthesis */
+ /* only a received/detected SID frame can make the decoder enter into CNG synthsis */
+ if ( g192_sid_first || sid_update || sid_upd_bad )
+ {
+ *CNG = 1;
+ }
+ }
+
+ /* set bfi, total_brate pair for proper decoding */
+ /* handle the G.192 _simulated_ untransmitted NO_DATA frame, setting for decoder SPEECH synthesis */
+ if ( *CNG == 0 && total_brate == FRAME_NO_DATA && st_ivas->bfi == 0 )
+ {
+ st_ivas->bfi = 1; /* SPEECH PLC code will now become active as in a real system */
+ /* total_brate= 0 */
+ }
+
+ /* handle bad/lost speech frame(and CS bad SID frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */
+ if ( (
+ bfi != FRAMEMODE_FUTURE &&
+ ( *CNG != 0 ) && ( ( speech_bad != 0 ) || ( speech_lost != 0 ) ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */
+ ( sid_upd_bad != 0 ) ) /* SID_UPD_BAD --> start CNG */
+ {
+ st_ivas->bfi = 0; /* bfi=0 needed to activate CNG code */
+ total_brate = FRAME_NO_DATA;
+ }
+
+ /* update for next frame's G.192 file format's odd SID_FIRST detection (primarily for AMRWBIO) */
+ *prev_ft_speech = ( ( curr_ft_good_sp != 0 ) || ( curr_ft_bad_sp != 0 ) );
+
+ /* st->total brate= total_brate; updated in a good frame below */
+
+ for ( k = 0; k < st_ivas->nCPE; k++ )
+ {
+ sts = st_ivas->hCPE[k]->hCoreCoder;
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ sts[n]->bfi = st_ivas->bfi;
+ }
+ }
+
+ for ( k = 0; k < st_ivas->nSCE; k++ )
+ {
+ sts = st_ivas->hSCE[k]->hCoreCoder;
+ sts[0]->bfi = st_ivas->bfi;
+ }
+
+ if ( st_ivas->bfi == 0 )
+ {
+ /* select Mode 1 or Mode 2 */
+ if ( st_ivas->ivas_format == MONO_FORMAT ) /* EVS mono */
+ {
+ decoder_selectCodec( sts[0], total_brate, bit_stream[0] );
+ st_ivas->hDecoderConfig->Opt_AMR_WB = sts[0]->Opt_AMR_WB;
+ }
+ else /* IVAS */
+ {
+ st_ivas->codec_mode = MODE1;
+ st_ivas->hDecoderConfig->Opt_AMR_WB = 0;
+ }
+ }
+
+ /* GOOD frame */
+ if ( st_ivas->bfi == 0 || st_ivas->bfi == FRAMEMODE_FUTURE )
+ {
+ /* GOOD frame - convert ITU-T G.192 words to short values */
+ st_ivas->hDecoderConfig->ivas_total_brate = total_brate;
+ }
+
+ st_ivas->bit_stream = bit_stream;
+
+ if ( st_ivas->ivas_format == MONO_FORMAT )
+ {
+ ivas_set_bitstream_pointers( st_ivas );
+ }
+
+ return error;
+}
+
+/*-------------------------------------------------------------------*
+ * get_rfFrameType()
+ *
+ * Extract the RF frame type
+ *-------------------------------------------------------------------*/
+
+static void get_rfFrameType(
+ Decoder_State *st, /* i : decoder state structure */
+ int16_t *rf_frame_type /* o : RF frame type */
+)
+{
+ int16_t num_bits;
+ num_bits = (int16_t) ( st->total_brate / FRAMES_PER_SEC );
+ if ( st->rf_flag == 1 )
+ {
+ /* the last three bits in a packet is the RF frame type */
+ *rf_frame_type = get_indice( st, num_bits - 3, 3 );
+ }
+ else
+ {
+ *rf_frame_type = 0;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * get_rfFlag()
+ *
+ * Check if RF flag is present in the bitstream
+ *-------------------------------------------------------------------*/
+
+static void get_rfFlag(
+ Decoder_State *st, /* i : decoder state structure */
+ int16_t *rf_flag, /* o : check for the RF flag */
+ int16_t *nBits,
+ int32_t *ind )
+{
+ int16_t start_idx, nBits_tmp;
+ int32_t ind_tmp;
+
+ /* Init */
+ *rf_flag = 0;
+
+ /* check for rf_flag in the packet and extract the rf_frame_type and rf_fec_offset */
+ if ( st->total_brate == ACELP_13k20 && ( st->bfi == FRAMEMODE_NORMAL || st->bfi == FRAMEMODE_FUTURE ) )
+ {
+ /* find the section in the ACELP signaling table corresponding to bitrate */
+ start_idx = 0;
+ while ( acelp_sig_tbl[start_idx] != st->total_brate )
+ {
+ start_idx++;
+ assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" );
+ }
+
+ /* skip the bitrate */
+ start_idx += 1;
+
+ /* retrieve the number of bits */
+ nBits_tmp = (int16_t) acelp_sig_tbl[start_idx++];
+
+ /* retrieve the signaling indice */
+ ind_tmp = acelp_sig_tbl[start_idx + get_indice( st, 0, nBits_tmp )];
+
+ /* convert signaling indice into RF flag. */
+ *rf_flag = ( ind_tmp >> 7 ) & 0x1;
+
+ if ( ind )
+ {
+ *ind = ind_tmp;
+ }
+
+ if ( nBits )
+ {
+ *nBits = nBits_tmp;
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * get_rf_fec_offset()
+ *
+ * Extract the FEC offset
+ *-------------------------------------------------------------------*/
+
+static void get_rf_fec_offset(
+ Decoder_State *st, /* i : decoder state structure */
+ int16_t *rf_fec_offset /* o : RF FEC offset */
+)
+{
+ int16_t num_bits, tmp;
+ num_bits = (int16_t) ( st->total_brate / FRAMES_PER_SEC );
+ if ( st->rf_flag == 1 )
+ {
+ /* the two bits before the RF frame type contains the FEC offset */
+ tmp = get_indice( st, num_bits - 5, 2 );
+
+ if ( tmp == 0 )
+ {
+ *rf_fec_offset = 2;
+ }
+ else
+ {
+ *rf_fec_offset = 2 * tmp + 1;
+ }
+ }
+ else
+ {
+ *rf_fec_offset = 0;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * get_rfTargetBits()
+ *
+ * Return the number of RF target bits
+ *-------------------------------------------------------------------*/
+
+static void get_rfTargetBits(
+ int16_t rf_frame_type, /* i : RF frame type */
+ int16_t *rf_target_bits /* o : Number of RF target bits */
+)
+{
+ /* Number of RF bits for different RF coder types */
+
+ switch ( rf_frame_type )
+ {
+ case RF_NO_DATA:
+ *rf_target_bits = 5;
+ break;
+ case RF_TCXFD:
+ *rf_target_bits = 27;
+ break;
+ case RF_TCXTD1:
+ *rf_target_bits = 16;
+ break;
+ case RF_TCXTD2:
+ *rf_target_bits = 16;
+ break;
+ case RF_ALLPRED:
+ /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/
+ *rf_target_bits = 63;
+ break;
+ case RF_NOPRED:
+ /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/
+ *rf_target_bits = 66;
+ break;
+ case RF_GENPRED:
+ /* Es_pred bits 3 bits, LTF: 1, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/
+ *rf_target_bits = 70;
+ break;
+ case RF_NELP:
+ /* gain: 19, Diff GFr: 5 */
+ *rf_target_bits = 45;
+ break;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * berCheck()
+ *
+ * Check for bit errors in channel aware signaling.
+ *-------------------------------------------------------------------*/
+
+static void berCheck(
+ Decoder_State *st /* i/o: decoder state structure */
+)
+{
+ /* In case of RF flag = 1, and valid RF packet with primary and partial copy */
+ if ( st->bwidth == NB || st->bwidth == FB || st->coder_type >= TRANSITION )
+ {
+ if ( st->use_partial_copy == 1 )
+ {
+ st->use_partial_copy = 0;
+ }
+
+ st->bfi = 1;
+ st->bwidth = st->last_bwidth;
+ st->BER_detect = 1;
+ st->coder_type = GENERIC;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * getPartialCopyInfo()
+ *
+ * Check if the frame includes a partial copy for channel aware processing.
+ *-------------------------------------------------------------------*/
+
+void getPartialCopyInfo(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t *sharpFlag )
+{
+ int16_t nBits = 0;
+ int32_t ind = 0;
+
+ /* check the RF flag in the packet */
+ get_rfFlag( st, &( st->rf_flag ), &nBits, &ind );
+
+ /* get RF frame type info */
+ get_rfFrameType( st, &( st->rf_frame_type ) );
+
+ /* Get the FEC offset info */
+ get_rf_fec_offset( st, &( st->rf_fec_offset ) );
+
+ /* reset number of target bits in case of rate switching */
+ st->rf_target_bits = 0;
+
+ /* Get the number of bits used for RF*/
+ if ( st->rf_flag == 1 )
+ {
+ st->coder_type = ind & 0x7;
+ st->bwidth = ( ind >> 3 ) & 0x7;
+ *sharpFlag = ( ind >> 6 ) & 0x1;
+ st->codec_mode = MODE2;
+ get_rfTargetBits( st->rf_frame_type, &( st->rf_target_bits ) );
+
+ if ( st->bfi == FRAMEMODE_FUTURE )
+ {
+ st->use_partial_copy = 1;
+ /* now set the frame mode to normal mode */
+ if ( st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 )
+ {
+ st->bfi = 1;
+ st->core = TCX_20_CORE;
+ }
+ else
+ {
+ st->bfi = FRAMEMODE_NORMAL;
+ st->core = ACELP_CORE;
+ }
+ }
+
+ /* check for bit errors */
+ berCheck( st );
+
+ get_next_indice_tmp( st, nBits );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * get_NextCoderType()
+ *
+ * Extract the coder type of next frame
+ *-------------------------------------------------------------------*/
+
+void get_NextCoderType(
+ uint8_t *bitstream, /* i : bitstream */
+ int16_t *next_coder_type /* o : next coder type */
+)
+{
+ int16_t k;
+ int16_t start_idx;
+ int8_t bit_stream[ACELP_13k20 / FRAMES_PER_SEC];
+ int32_t tmp;
+ int16_t nBits_tmp;
+
+
+ for ( k = 0; k < ACELP_13k20 / FRAMES_PER_SEC; k++ )
+ {
+ bit_stream[k] = ( bitstream[k / 8] >> ( 7 - ( k % 8 ) ) ) & 0x1;
+ }
+ start_idx = 0;
+ while ( acelp_sig_tbl[start_idx] != ACELP_13k20 )
+ {
+ start_idx++;
+ assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" );
+ }
+
+ /* skip the bitrate */
+ start_idx += 1;
+
+ tmp = 0;
+ nBits_tmp = (int16_t) acelp_sig_tbl[start_idx++];
+ for ( k = 0; k < nBits_tmp; k++ )
+ {
+ tmp <<= 1;
+ tmp += bit_stream[k];
+ }
+
+ /* retrieve the signaling indice */
+ *next_coder_type = acelp_sig_tbl[start_idx + tmp] & 0x7;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * get_indice_preview()
+ *
+ * Indices preview to parse for the presence of partial copy
+ *-------------------------------------------------------------------*/
+
+static uint16_t get_indice_preview(
+ uint8_t *bitstream,
+ const int16_t bitstreamSize,
+ const int16_t pos,
+ const int16_t nb_bits )
+{
+ uint16_t value;
+ int16_t i;
+ uint16_t bitstreamShort[MAX_BITS_PER_FRAME + 16];
+ uint16_t *bitstreamShortPtr;
+
+ /* convert bitstream from compact bytes to short values */
+ bitstreamShortPtr = bitstreamShort;
+ for ( i = 0; i < bitstreamSize; i++ )
+ {
+ *bitstreamShortPtr++ = ( bitstream[i / 8] >> ( 7 - ( i % 8 ) ) ) & 0x1;
+ }
+
+ assert( nb_bits <= 16 );
+ value = 0;
+ for ( i = 0; i < nb_bits; i++ )
+ {
+ value <<= 1;
+ value += bitstreamShort[pos + i];
+ }
+ return value;
+}
+
+
+/*-------------------------------------------------------------------*
+ * evs_dec_previewFrame()
+ *
+ * Signalling index preview for JBM
+ *-------------------------------------------------------------------*/
+
+void evs_dec_previewFrame(
+ uint8_t *bitstream,
+ int16_t bitstreamSize,
+ int16_t *partialCopyFrameType,
+ int16_t *partialCopyOffset )
+{
+ int32_t total_brate;
+ int16_t start_idx, nBits;
+ int32_t ind;
+ int16_t rf_flag;
+
+ rf_flag = 0;
+ *partialCopyFrameType = 0;
+ *partialCopyOffset = 0;
+ total_brate = bitstreamSize * FRAMES_PER_SEC;
+
+ if ( total_brate == ACELP_13k20 )
+ {
+ /* find the section in the ACELP signaling table corresponding to bitrate */
+ start_idx = 0;
+ while ( acelp_sig_tbl[start_idx] != total_brate )
+ {
+ start_idx++;
+ assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" );
+ }
+
+ /* skip the bitrate */
+ start_idx += 1;
+ /* retrieve the number of bits */
+ nBits = (int16_t) acelp_sig_tbl[start_idx++];
+
+ /* retrieve the signaling indice */
+ ind = acelp_sig_tbl[start_idx + get_indice_preview( bitstream, bitstreamSize, 0, nBits )];
+
+ /* convert signaling indice into RF flag. */
+ rf_flag = ( ind >> 7 ) & 0x1;
+ if ( rf_flag != 0 )
+ {
+ /* read the FEC offset at which the partial copy is received */
+ ind = get_indice_preview( bitstream, bitstreamSize, ( bitstreamSize - 5 ), 2 );
+ if ( ind == 0 )
+ {
+ *partialCopyOffset = 2;
+ }
+ else if ( ind == 1 )
+ {
+ *partialCopyOffset = 3;
+ }
+ else if ( ind == 2 )
+ {
+ *partialCopyOffset = 5;
+ }
+ else if ( ind == 3 )
+ {
+ *partialCopyOffset = 7;
+ }
+ /* the last three bits in a packet is the RF frame type */
+ *partialCopyFrameType = get_indice_preview( bitstream, bitstreamSize, bitstreamSize - 3, 3 );
+ }
+ }
+
+ return;
+}
+
+
+void dtx_read_padding_bits(
+ DEC_CORE_HANDLE st,
+ const int16_t num_bits )
+{
+ /* TODO: temporary hack, need to decide what to do with core-coder bitrate */
+ int32_t tmp;
+
+ tmp = st->total_brate;
+ st->total_brate = st->total_brate + num_bits * FRAMES_PER_SEC;
+ get_next_indice( st, num_bits );
+ st->total_brate = tmp;
+
+ return;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/calc_st_com.c b/lib_com/calc_st_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..59ceb09daf7a34f815912237997fbf61187b0d74
--- /dev/null
+++ b/lib_com/calc_st_com.c
@@ -0,0 +1,307 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+
+/*----------------------------------------------------------------------------
+ * calc_rc0_h()
+ *
+ * computes 1st parcor from composed filter impulse response
+ *---------------------------------------------------------------------------*/
+
+static void calc_rc0_h(
+ const float *h, /* i : impulse response of composed filter */
+ float *rc0 /* o : 1st parcor */
+)
+{
+ float acf0, acf1;
+ float temp, temp2;
+ const float *ptrs;
+ int16_t i;
+
+ /* computation of the autocorrelation function acf */
+ temp = 0.0f;
+ for ( i = 0; i < LONG_H_ST; i++ )
+ {
+ temp += h[i] * h[i];
+ }
+ acf0 = temp;
+
+ temp = 0.0f;
+ ptrs = h;
+ for ( i = 0; i < LONG_H_ST - 1; i++ )
+ {
+ temp2 = *ptrs++;
+ temp += temp2 * ( *ptrs );
+ }
+ acf1 = temp;
+
+ /* Initialisation of the calculation */
+ if ( acf0 == 0.0f )
+ {
+ *rc0 = 0.0f;
+ return;
+ }
+
+ /* Compute 1st parcor */
+ if ( acf0 < (float) fabs( acf1 ) )
+ {
+ *rc0 = 0.0f;
+ return;
+ }
+ *rc0 = -acf1 / acf0;
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+ * calc_st_filt()
+ *
+ * computes impulse response of A(gamma2) / A(gamma1)
+ * controls gain : computation of energy impulse response as
+ * SUMn (abs (h[n])) and computes parcor0
+ *---------------------------------------------------------------------------- */
+
+void calc_st_filt(
+ const float *apond2, /* i : coefficients of numerator */
+ const float *apond1, /* i : coefficients of denominator */
+ float *parcor0, /* o : 1st parcor calcul. on composed filter */
+ float *sig_ltp_ptr, /* i/o: input of 1/A(gamma1) : scaled by 1/g0 */
+ float *mem_zero, /* i/o: All zero memory */
+ const int16_t L_subfr, /* i : the length of subframe */
+ const int16_t extl /* i : extension layer info */
+
+)
+{
+ float h[LONG_H_ST];
+ float g0, temp;
+ int16_t i;
+
+ /* compute i.r. of composed filter apond2 / apond1 */
+ if ( extl == SWB_TBE )
+ {
+ syn_filt( apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 );
+ }
+ else
+ {
+ syn_filt( apond1, M, apond2, h, LONG_H_ST, mem_zero, 0 );
+ }
+
+ /* compute 1st parcor */
+ calc_rc0_h( h, parcor0 );
+
+ /* compute g0 */
+ g0 = 0.0f;
+ for ( i = 0; i < LONG_H_ST; i++ )
+ {
+ g0 += (float) fabs( h[i] );
+ }
+
+ /* Scale signal input of 1/A(gamma1) */
+ if ( g0 > 1.0f )
+ {
+ temp = 1.0f / g0;
+
+ for ( i = 0; i < L_subfr; i++ )
+ {
+ sig_ltp_ptr[i] = sig_ltp_ptr[i] * temp;
+ }
+ }
+
+ 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(
+ const float *sig_in, /* i : signal (beginning at sample -1) */
+ float *sig_out, /* o : output signal */
+ const float parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */
+ const int16_t L_subfr, /* i : the length of subframe */
+ const int16_t extl /* i : extension layer info */
+)
+{
+ int16_t n;
+ float mu, ga, temp;
+ const float *ptrs;
+
+ if ( extl == SWB_TBE )
+ {
+ if ( parcor0 > 0.0f )
+ {
+ mu = parcor0 * GAMMA3_PLUS_WB;
+ }
+ else
+ {
+ mu = parcor0 * GAMMA3_MINUS_WB;
+ }
+ }
+ else
+ {
+ if ( parcor0 > 0.0f )
+ {
+ mu = parcor0 * GAMMA3_PLUS;
+ }
+ else
+ {
+ mu = parcor0 * GAMMA3_MINUS;
+ }
+ }
+
+ ga = (float) 1. / ( (float) 1. - (float) fabs( mu ) );
+
+ ptrs = sig_in; /* points on sig_in(-1) */
+
+ for ( n = 0; n < L_subfr; n++ )
+ {
+ temp = mu * ( *ptrs++ );
+ temp += ( *ptrs );
+ sig_out[n] = ga * temp;
+ }
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+ * scale_st()
+ *
+ * control of the subframe gain
+ * gain[n] = AGC_FAC_FX * gain[n-1] + (1 - AGC_FAC_FX) g_in/g_out
+ *---------------------------------------------------------------------------*/
+
+void scale_st(
+ const float *sig_in, /* i : postfilter input signal */
+ float *sig_out, /* i/o: postfilter output signal */
+ float *gain_prec, /* i/o: last value of gain for subframe */
+ const int16_t L_subfr, /* i : the length of subframe */
+ const int16_t extl /* i : extension layer info */
+)
+{
+ int16_t i;
+ float gain_in, gain_out;
+ float g0, gain;
+ float agc_fac1_para = 0.0f;
+ float agc_fac_para = 0.0f;
+
+ if ( extl == SWB_TBE )
+ {
+ agc_fac1_para = AGC_FAC1_WB;
+ agc_fac_para = AGC_FAC_WB;
+ }
+ else
+ {
+ agc_fac1_para = AGC_FAC1;
+ agc_fac_para = AGC_FAC;
+ }
+
+ /* compute input gain */
+ gain_in = 0.0f;
+ for ( i = 0; i < L_subfr; i++ )
+ {
+ gain_in += (float) fabs( sig_in[i] );
+ }
+
+ if ( gain_in == 0.0f )
+ {
+ g0 = 0.0f;
+ }
+ else
+ {
+ /* Compute output gain */
+ gain_out = 0.0f;
+ for ( i = 0; i < L_subfr; i++ )
+ {
+ gain_out += (float) fabs( sig_out[i] );
+ }
+
+ if ( gain_out == 0.0f )
+ {
+ *gain_prec = 0.0f;
+ return;
+ }
+
+ g0 = gain_in / gain_out;
+ g0 *= agc_fac1_para;
+ }
+
+ /* compute gain(n) = AGC_FAC gain(n-1) + (1-AGC_FAC)gain_in/gain_out */
+ /* sig_out(n) = gain(n) sig_out(n) */
+ gain = *gain_prec;
+ for ( i = 0; i < L_subfr; i++ )
+ {
+ gain *= agc_fac_para;
+ gain += g0;
+ sig_out[i] *= gain;
+ }
+
+ *gain_prec = gain;
+
+ return;
+}
+
+void blend_subfr2(
+ float *sigIn1,
+ float *sigIn2,
+ float *sigOut )
+{
+ float fac1 = 1.f - ( 1.f / L_SUBFR );
+ float fac2 = 0.f + ( 1.f / L_SUBFR );
+ float step = 1.f / ( L_SUBFR / 2 );
+ int16_t i;
+
+ for ( i = 0; i < L_SUBFR / 2; i++ )
+ {
+ sigOut[i] = fac1 * sigIn1[i] + fac2 * sigIn2[i];
+ fac1 -= step;
+ fac2 += step;
+ }
+
+ return;
+}
diff --git a/lib_com/cb_shape.c b/lib_com/cb_shape.c
new file mode 100644
index 0000000000000000000000000000000000000000..77f17eb236e4585282cc15725c138c325b163f3f
--- /dev/null
+++ b/lib_com/cb_shape.c
@@ -0,0 +1,122 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * cb_shape()
+ *
+ * pre-emphasis, pitch sharpening and formant sharpening of the algebraic codebook
+ *-------------------------------------------------------------------*/
+
+void cb_shape(
+ const int16_t preemphFlag, /* i : flag for pre-emphasis */
+ const int16_t pitchFlag, /* i : flag for pitch sharpening */
+ const int16_t scramblingFlag, /* i : flag for phase scrambling */
+ const int16_t formantFlag, /* i : flag for formant sharpening */
+ const int16_t formantTiltFlag, /* i : flag for formant tilt */
+ const float g1, /* i : formant sharpening numerator weighting */
+ const float g2, /* i : formant sharpening denominator weighting */
+ const float *p_Aq, /* i : LP filter coefficients */
+ float *code, /* i/o: signal to shape */
+ const float tilt_code, /* i : tilt of code */
+ const float pt_pitch, /* i : pointer to current subframe fractional pitch */
+ const int16_t L_subfr /* i : subfframe length */
+)
+{
+ float buff[M + 2 * L_SUBFR], A_num[M + 1], A_den[M + 1];
+ float tmp, tilt;
+ int16_t i, round_T0;
+
+ /* pre-emphasize the algebraic codebook */
+ if ( preemphFlag )
+ {
+ tmp = 0.0f;
+ preemph( code, tilt_code, L_subfr, &tmp );
+ }
+
+ /* pitch sharpening */
+ if ( pitchFlag )
+ {
+ round_T0 = (int16_t) ( pt_pitch + 0.4f );
+ for ( i = round_T0; i < L_subfr; i++ )
+ {
+ code[i] += code[i - round_T0] * PIT_SHARP;
+ }
+ }
+
+ /* phase scrambling filter */
+ if ( scramblingFlag )
+ {
+ buff[0] = code[0];
+ for ( i = 1; i < L_subfr; i++ )
+ {
+ buff[i] = code[i];
+ code[i] = 0.7f * buff[i] + buff[i - 1] - 0.7f * code[i - 1];
+ }
+ }
+
+ /* formant sharpening (only on active speech) */
+ if ( formantFlag || formantTiltFlag )
+ {
+ weight_a( p_Aq, A_num, g1, M );
+ weight_a( p_Aq, A_den, g2, M );
+
+ set_f( buff, 0, M + L_subfr );
+
+ /* formant tilt */
+ if ( formantTiltFlag )
+ {
+ mvr2r( A_num, buff + M, M + 1 );
+ syn_filt( A_den, M, buff + M, buff + M, L_subfr, buff, 0 );
+ tilt = get_gain( buff + M + 1, buff + M, L_subfr - 1, NULL );
+ tmp = 0.0;
+ preemph( code, 0.5f * tilt_code - 0.25f * tilt, L_subfr, &tmp );
+ }
+ else
+ {
+ mvr2r( code, buff + M, L_subfr );
+ residu( A_num, M, buff + M, code, L_subfr );
+ syn_filt( A_den, M, code, code, L_subfr, buff, 0 );
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c
new file mode 100644
index 0000000000000000000000000000000000000000..716dff7a3aba197abf85610ed5c734a3ec8b9d99
--- /dev/null
+++ b/lib_com/cldfb.c
@@ -0,0 +1,1232 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include
+#include "stat_dec.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+#if __STDC_VERSION__ >= 199901L
+#if defined __ICL
+#define restrict __restrict
+#endif
+#else
+#define restrict
+#endif
+
+
+/*-------------------------------------------------------------------*
+ * Local prototypes
+ *--------------------------------------------------------------------*/
+
+static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs );
+
+static float GetEnergyCldfb( float *energyValuesSum, float *energyLookahead, float **realValues, float **imagValues, const int16_t numberBands, int16_t numberCols, TEC_ENC_HANDLE hTecEnc );
+
+/*-------------------------------------------------------------------*
+ * cplxMult()
+ *
+ * Conduct complex multiplication
+ *--------------------------------------------------------------------*/
+
+static void cplxMult(
+ float *yr, /* o : real output */
+ float *yi, /* o : imag output */
+ const float xr, /* i : real input 1*/
+ const float xi, /* i : imag input 1*/
+ const float cr, /* i : real input 1*/
+ const float ci /* i : imag input 1*/
+)
+{
+ *yr = xr * cr - xi * ci;
+ *yi = xr * ci + xi * cr;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * cldfbAnalysis()
+ *
+ * Conduct multiple overlap complex low delay MDCT
+ *--------------------------------------------------------------------*/
+
+void cldfbAnalysis(
+ const float *timeIn, /* i : time buffer */
+ float **realBuffer, /* o : real value buffer */
+ float **imagBuffer, /* o : imag value buffer */
+ const int16_t samplesToProcess, /* i : samples to process */
+ HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filterbank state */
+)
+{
+ int16_t i, k;
+ int16_t L2, M1, M2, M4;
+ int16_t no_col = h_cldfb->no_col;
+
+ float r1, r2, rr12, ir12;
+ float i1, i2, ri12, ii12;
+ float rBuffer[2 * CLDFB_NO_CHANNELS_MAX];
+ float iBuffer[2 * CLDFB_NO_CHANNELS_MAX];
+ const float *rot_vctr_re;
+ const float *rot_vctr_im;
+ const float *ptr_pf;
+ float *timeBuffer, buffer[( CLDFB_NO_CHANNELS_MAX * CLDFB_NO_COL_MAX ) + ( 9 * CLDFB_NO_CHANNELS_MAX )];
+ int16_t offset, frameSize;
+
+ offset = h_cldfb->p_filter_length - h_cldfb->no_channels;
+ frameSize = h_cldfb->no_channels * h_cldfb->no_col;
+
+ assert( h_cldfb->prototype == CLDFB_PROTOTYPE_1_25MS );
+ /* prepare input buffer */
+ timeBuffer = buffer;
+ mvr2r( h_cldfb->cldfb_state, timeBuffer, offset );
+
+ if ( samplesToProcess > -1 )
+ {
+ mvr2r( timeIn, timeBuffer + offset, samplesToProcess );
+ set_f( timeBuffer + offset + samplesToProcess, 0.0f, ( frameSize - samplesToProcess ) );
+ }
+ else
+ {
+ mvr2r( timeIn, timeBuffer + offset, frameSize );
+ }
+
+ /* only process needed cols */
+ if ( samplesToProcess > -1 )
+ {
+ no_col = min( no_col, ( samplesToProcess + h_cldfb->no_channels - 1 ) / h_cldfb->no_channels );
+ }
+
+ M1 = h_cldfb->no_channels;
+ M2 = M1 >> 1;
+ M4 = M1 >> 2;
+ L2 = M1 << 1;
+
+ if ( M2 & 1 )
+ {
+ M4 += 1;
+ }
+
+ rot_vctr_re = h_cldfb->rot_vec_ana_re;
+ rot_vctr_im = h_cldfb->rot_vec_ana_im;
+
+ ptr_pf = h_cldfb->p_filter;
+
+ for ( i = 0; i < no_col; i++ )
+ {
+ for ( k = 0; k < M4; k++ )
+ {
+ /* prototype filter */
+ r1 = 0 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 0 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 1 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 2 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 3 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 4 * L2];
+
+ r2 = 0 - ptr_pf[( L2 - M2 + ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 0 * L2];
+ r2 = r2 - ptr_pf[( L2 - M2 + ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 1 * L2];
+ r2 = r2 - ptr_pf[( L2 - M2 + ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 2 * L2];
+ r2 = r2 - ptr_pf[( L2 - M2 + ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 3 * L2];
+ r2 = r2 - ptr_pf[( L2 - M2 + ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 4 * L2];
+
+ i1 = 0 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 0 * L2];
+ i1 = i1 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 1 * L2];
+ i1 = i1 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 2 * L2];
+ i1 = i1 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 3 * L2];
+ i1 = i1 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 4 * L2];
+
+ i2 = 0 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2];
+
+ /* folding + pre modulation of DST IV */
+ rr12 = r1 - r2;
+ ri12 = -i1 - i2;
+ cplxMult( &rBuffer[2 * k], &rBuffer[2 * k + 1], rr12, ri12, rot_vctr_re[k], rot_vctr_im[k] );
+
+ /* folding + pre modulation of DCT IV */
+ ir12 = r1 + r2;
+ ii12 = i1 - i2;
+ cplxMult( &iBuffer[2 * k], &iBuffer[2 * k + 1], ir12, ii12, rot_vctr_re[k], rot_vctr_im[k] );
+ }
+
+ for ( k = M4; k < M2; k++ )
+ {
+ /* prototype filter */
+ r1 = 0 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 0 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 1 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 2 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 3 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 4 * L2];
+
+ r2 = 0 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 0 * L2];
+ r2 = r2 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 1 * L2];
+ r2 = r2 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 2 * L2];
+ r2 = r2 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 3 * L2];
+ r2 = r2 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 4 * L2];
+
+ i1 = 0 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 0 * L2];
+ i1 = i1 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 1 * L2];
+ i1 = i1 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 2 * L2];
+ i1 = i1 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 3 * L2];
+ i1 = i1 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 4 * L2];
+
+ i2 = 0 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 0 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 1 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 2 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 3 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 4 * L2];
+
+ /* folding + pre modulation of DST IV */
+ rr12 = r1 + r2;
+ ri12 = i1 - i2;
+ cplxMult( &rBuffer[2 * k], &rBuffer[2 * k + 1], rr12, ri12, rot_vctr_re[k], rot_vctr_im[k] );
+
+ /* folding + pre modulation of DCT IV */
+ ir12 = r1 - r2;
+ ii12 = i1 + i2;
+ cplxMult( &iBuffer[2 * k], &iBuffer[2 * k + 1], ir12, ii12, rot_vctr_re[k], rot_vctr_im[k] );
+ }
+
+ /* FFT of DST IV */
+ fft_cldfb( rBuffer, M2 );
+
+ /* post modulation of DST IV */
+ for ( k = 0; k < M2; k++ )
+ {
+ cplxMult( &realBuffer[i][M1 - 1 - ( 2 * k )], &realBuffer[i][2 * k], rBuffer[2 * k], rBuffer[2 * k + 1], rot_vctr_re[k], rot_vctr_im[k] );
+ }
+
+ /* FFT of DCT IV */
+ fft_cldfb( iBuffer, M2 );
+
+ /* post modulation of DCT IV */
+ for ( k = 0; k < M2; k++ )
+ {
+ /* do it inplace */
+ cplxMult( &imagBuffer[i][2 * k], &imagBuffer[i][M1 - 1 - ( 2 * k )], iBuffer[2 * k], iBuffer[2 * k + 1], rot_vctr_re[k], rot_vctr_im[k] );
+ }
+
+ timeBuffer += L2 * 5;
+ timeBuffer += h_cldfb->no_channels - h_cldfb->p_filter_length;
+ }
+
+ /* update memory */
+ mvr2r( buffer + frameSize, h_cldfb->cldfb_state, offset );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * cldfbAnalysis_ts()
+ *
+ *
+ *--------------------------------------------------------------------*/
+
+void cldfbAnalysis_ts(
+ const float *timeIn, /* i : time buffer */
+ float realBuffer[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */
+ float imagBuffer[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */
+ const int16_t samplesToProcess, /* i : samples to process */
+ HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filterbank state */
+)
+{
+ int16_t i, k;
+ int16_t L2, M1, M2, M4;
+ int16_t no_col = h_cldfb->no_col;
+
+ float r1, r2, rr12, ir12;
+ float i1, i2, ri12, ii12;
+ float rBuffer[2 * CLDFB_NO_CHANNELS_MAX];
+ float iBuffer[2 * CLDFB_NO_CHANNELS_MAX];
+ const float *rot_vctr_re;
+ const float *rot_vctr_im;
+ const float *rot_vctr_delay_re;
+ const float *rot_vctr_delay_im;
+ const float *ptr_pf;
+ float *timeBuffer, buffer[( CLDFB_NO_CHANNELS_MAX * CLDFB_NO_COL_MAX ) + ( 9 * CLDFB_NO_CHANNELS_MAX )];
+ int16_t offset, frameSize;
+
+ offset = h_cldfb->p_filter_length - h_cldfb->no_channels;
+ frameSize = h_cldfb->no_channels * h_cldfb->no_col;
+
+ /* prepare input buffer */
+ timeBuffer = buffer;
+ mvr2r( h_cldfb->cldfb_state, timeBuffer, offset );
+
+ if ( samplesToProcess > -1 )
+ {
+ mvr2r( timeIn, timeBuffer + offset, samplesToProcess );
+ set_f( timeBuffer + offset + samplesToProcess, 0.0f, ( frameSize - samplesToProcess ) );
+ }
+ else
+ {
+ mvr2r( timeIn, timeBuffer + offset, frameSize );
+ }
+
+ /* only process needed cols */
+ if ( samplesToProcess > -1 )
+ {
+ no_col = min( no_col, ( samplesToProcess + h_cldfb->no_channels - 1 ) / h_cldfb->no_channels );
+ assert( no_col == 1 );
+ }
+
+ M1 = h_cldfb->no_channels;
+ M2 = M1 >> 1;
+ M4 = M1 >> 2;
+ L2 = M1 << 1;
+
+ if ( M2 & 1 )
+ {
+ M4 += 1;
+ }
+
+ rot_vctr_re = h_cldfb->rot_vec_ana_re;
+ rot_vctr_im = h_cldfb->rot_vec_ana_im;
+ rot_vctr_delay_re = h_cldfb->rot_vec_ana_delay_re;
+ rot_vctr_delay_im = h_cldfb->rot_vec_ana_delay_im;
+
+ ptr_pf = h_cldfb->p_filter;
+
+ for ( i = 0; i < no_col; i++ )
+ {
+ for ( k = 0; k < M4; k++ )
+ {
+ /* prototype filter */
+ r1 = 0 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 0 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 1 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 2 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 3 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 4 * L2];
+
+ r2 = 0 - ptr_pf[( L2 - M2 + ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 0 * L2];
+ r2 = r2 - ptr_pf[( L2 - M2 + ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 1 * L2];
+ r2 = r2 - ptr_pf[( L2 - M2 + ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 2 * L2];
+ r2 = r2 - ptr_pf[( L2 - M2 + ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 3 * L2];
+ r2 = r2 - ptr_pf[( L2 - M2 + ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - M2 + ( 2 * k ) + 4 * L2];
+
+ i1 = 0 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 0 * L2];
+ i1 = i1 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 1 * L2];
+ i1 = i1 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 2 * L2];
+ i1 = i1 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 3 * L2];
+ i1 = i1 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 4 * L2];
+
+ i2 = 0 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2];
+
+ /* folding + pre modulation of DST IV */
+ rr12 = r1 - r2;
+ ri12 = -i1 - i2;
+ /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/
+ rBuffer[2 * k] = rr12 * rot_vctr_re[k] - ri12 * rot_vctr_im[k];
+ rBuffer[2 * k + 1] = rr12 * rot_vctr_im[k] + ri12 * rot_vctr_re[k];
+
+ /* folding + pre modulation of DCT IV */
+ ir12 = r1 + r2;
+ ii12 = i1 - i2;
+ /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/
+ iBuffer[2 * k] = ir12 * rot_vctr_re[k] - ii12 * rot_vctr_im[k];
+ iBuffer[2 * k + 1] = ir12 * rot_vctr_im[k] + ii12 * rot_vctr_re[k];
+ }
+
+ for ( k = M4; k < M2; k++ )
+ {
+ /* prototype filter */
+ r1 = 0 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 0 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 1 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 2 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 3 * L2];
+ r1 = r1 - ptr_pf[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - M2 - 1 - ( 2 * k ) + 4 * L2];
+
+ r2 = 0 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 0 * L2];
+ r2 = r2 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 1 * L2];
+ r2 = r2 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 2 * L2];
+ r2 = r2 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 3 * L2];
+ r2 = r2 - ptr_pf[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - 5 * M2 + ( 2 * k ) + 4 * L2];
+
+ i1 = 0 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 0 * L2];
+ i1 = i1 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 1 * L2];
+ i1 = i1 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 2 * L2];
+ i1 = i1 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 3 * L2];
+ i1 = i1 - ptr_pf[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 + M2 - 1 - ( 2 * k ) + 4 * L2];
+
+ i2 = 0 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 0 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 1 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 2 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 3 * L2];
+ i2 = i2 - ptr_pf[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] * timeBuffer[L2 - 3 * M2 + ( 2 * k ) + 4 * L2];
+
+ /* folding + pre modulation of DST IV */
+ rr12 = r1 + r2;
+ ri12 = i1 - i2;
+ /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/
+ rBuffer[2 * k] = rr12 * rot_vctr_re[k] - ri12 * rot_vctr_im[k];
+ rBuffer[2 * k + 1] = rr12 * rot_vctr_im[k] + ri12 * rot_vctr_re[k];
+
+ /* folding + pre modulation of DCT IV */
+ ir12 = r1 - r2;
+ ii12 = i1 + i2;
+ /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/
+ iBuffer[2 * k] = ir12 * rot_vctr_re[k] - ii12 * rot_vctr_im[k];
+ iBuffer[2 * k + 1] = ir12 * rot_vctr_im[k] + ii12 * rot_vctr_re[k];
+ }
+
+ /* FFT of DST IV */
+ fft_cldfb( rBuffer, M2 );
+
+ /* post modulation of DST IV */
+ for ( k = 0; k < M2; k++ )
+ {
+ /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/
+ realBuffer[M1 - 1 - ( 2 * k )] = rBuffer[2 * k] * rot_vctr_re[k] - rBuffer[2 * k + 1] * rot_vctr_im[k];
+ realBuffer[2 * k] = rBuffer[2 * k] * rot_vctr_im[k] + rBuffer[2 * k + 1] * rot_vctr_re[k];
+ }
+
+ /* FFT of DCT IV */
+ fft_cldfb( iBuffer, M2 );
+
+ /* post modulation of DCT IV */
+ for ( k = 0; k < M2; k++ )
+ {
+ /* do it inplace */
+ /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/
+ imagBuffer[2 * k] = iBuffer[2 * k] * rot_vctr_re[k] - iBuffer[2 * k + 1] * rot_vctr_im[k];
+ imagBuffer[M1 - 1 - ( 2 * k )] = iBuffer[2 * k] * rot_vctr_im[k] + iBuffer[2 * k + 1] * rot_vctr_re[k];
+ }
+
+ if ( h_cldfb->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ /* rotation due to delay*/
+ /*if(h_cldfb->da != M1)*/
+ if ( rot_vctr_delay_re != NULL )
+ {
+ for ( k = 0; k < M1; k++ )
+ {
+ float cplx_aux;
+ /* delay */
+ /*cplxMult(&rBuffer[k], &iBuffer[k], realBuffer[i][k], imagBuffer[i][k], cos((EVS_PI/M1)*(k+0.5)*((h_cldfb->da-M1)*0.5)),
+ sin((EVS_PI/M1)*(k+0.5)*((h_cldfb->da-M1)*0.5)));*/
+ /*cplxMult(&rBuffer[k], &iBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/
+ /*cplxMult(&realBuffer[k], &imagBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/
+ /*realBuffer[k] = rBuffer[k];
+ imagBuffer[k] = iBuffer[k];*/
+ cplx_aux = realBuffer[k] * rot_vctr_delay_re[k] - imagBuffer[k] * rot_vctr_delay_im[k];
+ imagBuffer[k] = realBuffer[k] * rot_vctr_delay_im[k] + imagBuffer[k] * rot_vctr_delay_re[k];
+ realBuffer[k] = cplx_aux;
+ }
+ }
+ }
+
+ timeBuffer += L2 * 5;
+ timeBuffer += h_cldfb->no_channels - h_cldfb->p_filter_length;
+ }
+
+ /* update memory */
+ if ( samplesToProcess > -1 )
+ {
+ mvr2r( buffer + samplesToProcess, h_cldfb->cldfb_state, offset );
+ }
+ else
+ {
+ mvr2r( buffer + frameSize, h_cldfb->cldfb_state, offset );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * cldfbSynthesis()
+ *
+ * Conduct inverse multple overlap cmplex low delay MDCT
+ *--------------------------------------------------------------------*/
+
+void cldfbSynthesis(
+ float **realBuffer, /* i : real values */
+ float **imagBuffer, /* i : imag values */
+ float *timeOut, /* o : output time domain samples */
+ const int16_t samplesToProcess, /* i : number of processed samples */
+ HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filter bank state */
+)
+{
+ int16_t i;
+ int16_t k;
+ int16_t L2;
+ int16_t M1;
+ int16_t M2;
+ int16_t M41;
+ int16_t M42;
+ int16_t Mz;
+
+ float rBuffer[2 * CLDFB_NO_CHANNELS_MAX];
+ float iBuffer[2 * CLDFB_NO_CHANNELS_MAX];
+ const float *rot_vctr_re;
+ const float *rot_vctr_im;
+ const float *rot_vctr_delay_re;
+ const float *rot_vctr_delay_im;
+ float rr12, ir12;
+ float ri12, ii12;
+
+ float *synthesisBuffer, buffer[( CLDFB_NO_CHANNELS_MAX * CLDFB_NO_COL_MAX ) + ( 10 * CLDFB_NO_CHANNELS_MAX )];
+ float new_samples[2 * CLDFB_NO_CHANNELS_MAX];
+
+ float *ptr_time_out;
+ const float *p_filter;
+
+ float accu0, accu1, accu2, accu3, accu4;
+ int16_t no_col = h_cldfb->no_col;
+
+ M1 = h_cldfb->no_channels;
+ L2 = M1 << 1;
+ M2 = M1 >> 1;
+ M41 = M2 >> 1;
+ M42 = M2 - M41;
+ Mz = M1 - h_cldfb->bandsToZero;
+
+ /* only process needed cols */
+ if ( samplesToProcess > -1 )
+ {
+ no_col = min( no_col, ( samplesToProcess + h_cldfb->no_channels - 1 ) / h_cldfb->no_channels );
+ }
+
+ rot_vctr_re = h_cldfb->rot_vec_syn_re;
+ rot_vctr_im = h_cldfb->rot_vec_syn_im;
+
+ rot_vctr_delay_re = h_cldfb->rot_vec_syn_delay_re;
+ rot_vctr_delay_im = h_cldfb->rot_vec_syn_delay_im;
+
+ synthesisBuffer = buffer;
+ mvr2r( h_cldfb->cldfb_state, synthesisBuffer + ( M1 * no_col ), h_cldfb->p_filter_length );
+
+ p_filter = h_cldfb->p_filter;
+ ptr_time_out = timeOut;
+
+ /*synthesisBuffer += M1 * h_cldfb->no_col;*/
+ synthesisBuffer += M1 * no_col;
+
+ for ( k = 0; k < no_col; k++ )
+ {
+ if ( h_cldfb->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ /* rotation due to delay*/
+ /*if(h_cldfb->ds != M1)*/
+ if ( rot_vctr_delay_re != NULL )
+ {
+ for ( i = 0; i < M1; i++ )
+ {
+ float cplx_aux;
+ /* delay */
+ /*cplxMult(&rBuffer[i], &iBuffer[i], realBuffer[k][i], imagBuffer[k][i], cos((EVS_PI/M1)*(i+0.5)*(-(h_cldfb->ds-M1)*0.5)),
+ sin((EVS_PI/M1)*(i+0.5)*(-(h_cldfb->ds-M1)*0.5)));*/
+ /*cplxMult(&rBuffer[i], &iBuffer[i], realBuffer[k][i], imagBuffer[k][i], rot_vctr_delay_re[i], rot_vctr_delay_im[i]);*/
+ /*cplxMult(&realBuffer[k][i], &imagBuffer[k][i], realBuffer[k][i], imagBuffer[k][i], rot_vctr_delay_re[i], rot_vctr_delay_im[i]);*/
+ cplx_aux = realBuffer[k][i] * rot_vctr_delay_re[i] - imagBuffer[k][i] * rot_vctr_delay_im[i];
+ imagBuffer[k][i] = realBuffer[k][i] * rot_vctr_delay_im[i] + imagBuffer[k][i] * rot_vctr_delay_re[i];
+ realBuffer[k][i] = cplx_aux;
+ /*realBuffer[k][i] = rBuffer[i];
+ imagBuffer[k][i] = iBuffer[i];*/
+ }
+ }
+ }
+ for ( i = Mz; i < M1; i++ )
+ {
+ realBuffer[k][i] = 0.0f;
+ imagBuffer[k][i] = 0.0f;
+ }
+
+ for ( i = 0; i < M2; i++ )
+ {
+ /* pre modulation of DST IV */
+ /*cplxMult(&rBuffer[2*i], &rBuffer[2*i+1], realBuffer[k][2*i], realBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]);*/
+ rBuffer[2 * i] = realBuffer[k][2 * i] * rot_vctr_re[i] - realBuffer[k][M1 - 1 - 2 * i] * rot_vctr_im[i];
+ rBuffer[2 * i + 1] = realBuffer[k][2 * i] * rot_vctr_im[i] + realBuffer[k][M1 - 1 - 2 * i] * rot_vctr_re[i];
+
+ /* pre modulation of DCT IV */
+ /*cplxMult(&iBuffer[2*i], &iBuffer[2*i+1],-imagBuffer[k][2*i], imagBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]);*/
+ iBuffer[2 * i] = ( -( imagBuffer[k][2 * i] ) ) * rot_vctr_re[i] - imagBuffer[k][M1 - 1 - 2 * i] * rot_vctr_im[i];
+ iBuffer[2 * i + 1] = ( -( imagBuffer[k][2 * i] ) ) * rot_vctr_im[i] + imagBuffer[k][M1 - 1 - 2 * i] * rot_vctr_re[i];
+ }
+
+ /* FFT of DST IV */
+ fft_cldfb( rBuffer, M2 );
+
+ /* FFT of DCT IV */
+ fft_cldfb( iBuffer, M2 );
+
+ /* folding */
+ for ( i = 0; i < M41; i++ )
+ {
+ /* post modulation of DST IV */
+ rr12 = rBuffer[M1 - 2 - 2 * i] * rot_vctr_re[M2 - 1 - i] - rBuffer[M1 - 1 - 2 * i] * rot_vctr_im[M2 - 1 - i];
+ ri12 = rBuffer[M1 - 2 - 2 * i] * rot_vctr_im[M2 - 1 - i] + rBuffer[M1 - 1 - 2 * i] * rot_vctr_re[M2 - 1 - i];
+
+ /* post modulation of DCT IV */
+ ir12 = iBuffer[M1 - 2 - 2 * i] * rot_vctr_re[M2 - 1 - i] - iBuffer[M1 - 1 - 2 * i] * rot_vctr_im[M2 - 1 - i];
+ ii12 = iBuffer[M1 - 2 - 2 * i] * rot_vctr_im[M2 - 1 - i] + iBuffer[M1 - 1 - 2 * i] * rot_vctr_re[M2 - 1 - i];
+
+ new_samples[M1 + M2 + 1 + 2 * i] = -rr12 - ii12;
+ new_samples[M2 - 2 - 2 * i] = -ri12 - ir12;
+
+ new_samples[M1 + M2 - 2 - 2 * i] = rr12 - ii12;
+ new_samples[M2 + 1 + 2 * i] = ir12 - ri12;
+ }
+
+ for ( i = 0; i < M42; i++ )
+ {
+ /* post modulation of DST IV */
+ rr12 = rBuffer[2 * i] * rot_vctr_re[i] - rBuffer[2 * i + 1] * rot_vctr_im[i];
+ ri12 = rBuffer[2 * i] * rot_vctr_im[i] + rBuffer[2 * i + 1] * rot_vctr_re[i];
+
+ /* post modulation of DCT IV */
+ ir12 = iBuffer[2 * i] * rot_vctr_re[i] - iBuffer[2 * i + 1] * rot_vctr_im[i];
+ ii12 = iBuffer[2 * i] * rot_vctr_im[i] + iBuffer[2 * i + 1] * rot_vctr_re[i];
+
+ new_samples[M1 + M2 + 2 * i] = ri12 + ir12;
+ new_samples[M2 - 1 - 2 * i] = rr12 + ii12;
+
+ new_samples[M1 + M2 - 1 - 2 * i] = ir12 - ri12;
+ new_samples[M2 + 2 * i] = rr12 - ii12;
+ }
+
+ /* synthesis prototype filter */
+ for ( i = 0; i < L2; i++ )
+ {
+ accu0 = synthesisBuffer[0 * L2 + i] + p_filter[( 0 * L2 + i )] * new_samples[L2 - 1 - i];
+ accu1 = synthesisBuffer[1 * L2 + i] + p_filter[( 1 * L2 + i )] * new_samples[L2 - 1 - i];
+ accu2 = synthesisBuffer[2 * L2 + i] + p_filter[( 2 * L2 + i )] * new_samples[L2 - 1 - i];
+ accu3 = synthesisBuffer[3 * L2 + i] + p_filter[( 3 * L2 + i )] * new_samples[L2 - 1 - i];
+ accu4 = synthesisBuffer[4 * L2 + i] + p_filter[( 4 * L2 + i )] * new_samples[L2 - 1 - i];
+
+ synthesisBuffer[0 * L2 + i] = accu0;
+ synthesisBuffer[1 * L2 + i] = accu1;
+ synthesisBuffer[2 * L2 + i] = accu2;
+ synthesisBuffer[3 * L2 + i] = accu3;
+ synthesisBuffer[4 * L2 + i] = accu4;
+ }
+
+ for ( i = 0; i < M1; i++ )
+ {
+ ptr_time_out[M1 - 1 - i] = synthesisBuffer[4 * L2 + M1 + i];
+ }
+
+ ptr_time_out += M1;
+
+ synthesisBuffer -= M1;
+
+ set_f( synthesisBuffer, 0, M1 );
+ }
+
+ /* update memory */
+ mvr2r( buffer, h_cldfb->cldfb_state, h_cldfb->p_filter_length );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * configureClfdb()
+ *
+ * configures a CLDFB handle
+ *--------------------------------------------------------------------*/
+
+void configureCldfb(
+ HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */
+ const int32_t 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 = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f );
+ h_cldfb->p_filter_length = 10 * h_cldfb->no_channels;
+
+ cldfb_init_proto_and_twiddles( h_cldfb );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * openClfdb()
+ *
+ * open and configures a CLDFB handle
+ *--------------------------------------------------------------------*/
+
+ivas_error openCldfb(
+ HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */
+ CLDFB_TYPE type, /* i : analysis or synthesis */
+ const int32_t sampling_rate, /* i : sampling rate */
+ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */
+)
+{
+ HANDLE_CLDFB_FILTER_BANK hs;
+ int16_t buf_len;
+
+ if ( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" );
+ }
+
+ hs->type = type;
+ hs->prototype = prototype;
+
+ configureCldfb( hs, sampling_rate );
+ hs->memory = NULL;
+ hs->memory_length = 0;
+
+ if ( type == CLDFB_ANALYSIS )
+ {
+ buf_len = hs->p_filter_length - hs->no_channels;
+ }
+ else
+ {
+ buf_len = hs->p_filter_length;
+ }
+
+ if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" );
+ }
+
+ set_f( hs->cldfb_state, 0.0f, buf_len );
+
+ *h_cldfb = hs;
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-------------------------------------------------------------------*
+ * resampleCldfb()
+ *
+ * Change sample rate of filter bank
+ *--------------------------------------------------------------------*/
+
+void resampleCldfb(
+ HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */
+ const int32_t newSamplerate )
+{
+ int16_t timeOffset;
+
+ /* keep old parameters before switching*/
+ int16_t timeOffsetold = hs->p_filter_length - hs->no_channels;
+
+ /* new settings */
+ configureCldfb( hs, newSamplerate );
+ timeOffset = hs->p_filter_length - hs->no_channels;
+
+ /*low complexity-resampling only stored previous samples that are needed for next frame modulation */
+ lerp( hs->cldfb_state, hs->cldfb_state, timeOffset, timeOffsetold );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * analysisCLDFBEncoder()
+ *
+ * Encoder CLDFB analysis + energy stage
+ *--------------------------------------------------------------------*/
+
+void analysisCldfbEncoder(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float *timeIn,
+ const int16_t samplesToProcess,
+ float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
+ float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
+ float *ppBuf_Ener )
+{
+ int16_t i;
+ float *ppBuf_Real[CLDFB_NO_COL_MAX];
+ float *ppBuf_Imag[CLDFB_NO_COL_MAX];
+
+ for ( i = 0; i < CLDFB_NO_COL_MAX; i++ )
+ {
+ ppBuf_Real[i] = &realBuffer[i][0];
+ ppBuf_Imag[i] = &imagBuffer[i][0];
+ }
+
+ cldfbAnalysis( timeIn, ppBuf_Real, ppBuf_Imag, samplesToProcess, st->cldfbAnaEnc );
+
+ st->currEnergyHF = GetEnergyCldfb( ppBuf_Ener, &st->currEnergyLookAhead, ppBuf_Real, ppBuf_Imag, st->cldfbAnaEnc->no_channels, st->cldfbAnaEnc->no_col, st->hTECEnc );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * GetEnergyCldfb()
+ *
+ * Conduct energy from complex data
+ *--------------------------------------------------------------------*/
+
+static float GetEnergyCldfb(
+ float *energyValuesSum, /* o : the result of the operation */
+ float *energyLookahead, /* o : the result in the core look-ahead slot */
+ float **realValues, /* i : the real part of the subsamples */
+ float **imagValues, /* i : the imaginary part of the subsamples */
+ const int16_t numberBands, /* i : number of bands */
+ int16_t numberCols, /* i : number of subsamples */
+ TEC_ENC_HANDLE hTecEnc /* i/o: TEC handle */
+)
+{
+ int16_t j, k;
+ float energyValues[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+ int16_t numLookahead = 1;
+
+ for ( k = 0; k < numberCols; k++ )
+ {
+ for ( j = 0; j < numberBands; j++ )
+ {
+ energyValues[k][j] = realValues[k][j] * realValues[k][j] +
+ imagValues[k][j] * imagValues[k][j];
+ }
+ }
+
+ if ( numberBands >= freqTable[1] && hTecEnc != NULL )
+ {
+ float *tempEnergyValuesArry[CLDFB_NO_COL_MAX];
+
+ assert( numberCols == CLDFB_NO_COL_MAX );
+ for ( j = 0; j < numberCols; j++ )
+ {
+ tempEnergyValuesArry[j] = &energyValues[j][0];
+ }
+
+ calcHiEnvLoBuff( numberCols, freqTable, 1, tempEnergyValuesArry, hTecEnc->loBuffer, hTecEnc->hiTempEnv );
+ }
+
+ for ( j = 0; j < numberBands; j++ )
+ {
+ energyValuesSum[j] = 0;
+ for ( k = 0; k < CLDFB_NO_COL_MAX; k++ )
+ {
+ energyValuesSum[j] += energyValues[k][j];
+ }
+ }
+
+ if ( numberBands > 20 )
+ {
+ float energyHF = *energyLookahead; /* energy above 8 kHz */
+ numberCols -= numLookahead;
+ *energyLookahead = 6.1e-5f; /* process look-ahead region */
+
+ for ( j = 20; j < min( 40, numberBands ); j++ )
+ {
+ energyHF += energyValuesSum[j];
+
+ for ( k = numberCols; k < CLDFB_NO_COL_MAX; k++ )
+ {
+ energyHF -= energyValues[k][j];
+ *energyLookahead += energyValues[k][j];
+ }
+ }
+
+ return energyHF * OUTMAX_SQ_INV;
+ }
+
+ return 65535.0f;
+}
+
+
+/*-------------------------------------------------------------------*
+ * GetEnergyCldfb()
+ *
+ * Remove handle
+ *--------------------------------------------------------------------*/
+
+void deleteCldfb(
+ HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */
+)
+{
+ HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb;
+
+ if ( h_cldfb == NULL || *h_cldfb == NULL )
+ {
+ return;
+ }
+
+ if ( hs->cldfb_state )
+ {
+ free( hs->cldfb_state );
+ }
+
+ free( hs );
+ *h_cldfb = NULL;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * cldfb_init_proto_and_twiddles()
+ *
+ * Initializes rom pointer
+ *--------------------------------------------------------------------*/
+
+static void cldfb_init_proto_and_twiddles(
+ 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 = rot_vec_ana_re_L10;
+ hs->rot_vec_ana_im = rot_vec_ana_im_L10;
+ hs->rot_vec_syn_re = rot_vec_syn_re_L10;
+ hs->rot_vec_syn_im = rot_vec_syn_im_L10;
+
+ if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS )
+ {
+ hs->p_filter = CLDFB80_10;
+ hs->scale = CLDFB80_10_SCALE;
+ hs->ds = 10;
+ hs->da = 10;
+ hs->rot_vec_ana_delay_re = NULL;
+ hs->rot_vec_ana_delay_im = NULL;
+ hs->rot_vec_syn_delay_re = NULL;
+ hs->rot_vec_syn_delay_im = NULL;
+ }
+ else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ hs->p_filter = LDQMF_10;
+ hs->scale = LDQMF_10_SCALE;
+ hs->ds = 40;
+ hs->da = -20;
+ hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF;
+ hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF;
+ }
+ break;
+
+ case 16:
+ hs->rot_vec_ana_re = rot_vec_ana_re_L16;
+ hs->rot_vec_ana_im = rot_vec_ana_im_L16;
+ hs->rot_vec_syn_re = rot_vec_syn_re_L16;
+ hs->rot_vec_syn_im = rot_vec_syn_im_L16;
+ if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS )
+ {
+ hs->p_filter = CLDFB80_16;
+ hs->scale = CLDFB80_16_SCALE;
+ hs->ds = 20;
+ hs->da = 20;
+ hs->rot_vec_ana_delay_re = NULL;
+ hs->rot_vec_ana_delay_im = NULL;
+ hs->rot_vec_syn_delay_re = NULL;
+ hs->rot_vec_syn_delay_im = NULL;
+ }
+ else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ hs->p_filter = LDQMF_16;
+ hs->scale = LDQMF_16_SCALE;
+ hs->ds = 80;
+ hs->da = -40;
+ hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF;
+ hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF;
+ }
+ break;
+
+ case 20:
+ hs->rot_vec_ana_re = rot_vec_ana_re_L20;
+ hs->rot_vec_ana_im = rot_vec_ana_im_L20;
+ hs->rot_vec_syn_re = rot_vec_syn_re_L20;
+ hs->rot_vec_syn_im = rot_vec_syn_im_L20;
+ if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS )
+ {
+ hs->p_filter = CLDFB80_20;
+ hs->scale = CLDFB80_20_SCALE;
+ hs->ds = 20;
+ hs->da = 20;
+ hs->rot_vec_ana_delay_re = NULL;
+ hs->rot_vec_ana_delay_im = NULL;
+ hs->rot_vec_syn_delay_re = NULL;
+ hs->rot_vec_syn_delay_im = NULL;
+ }
+ else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ hs->p_filter = LDQMF_20;
+ hs->scale = LDQMF_20_SCALE;
+ hs->ds = 80;
+ hs->da = -40;
+ hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF;
+ hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF;
+ }
+ break;
+
+ case 30:
+ hs->rot_vec_ana_re = rot_vec_ana_re_L30;
+ hs->rot_vec_ana_im = rot_vec_ana_im_L30;
+ hs->rot_vec_syn_re = rot_vec_syn_re_L30;
+ hs->rot_vec_syn_im = rot_vec_syn_im_L30;
+ if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS )
+ {
+ hs->p_filter = CLDFB80_30;
+ hs->scale = CLDFB80_30_SCALE;
+ hs->ds = 30;
+ hs->da = 30;
+ hs->rot_vec_ana_delay_re = NULL;
+ hs->rot_vec_ana_delay_im = NULL;
+ hs->rot_vec_syn_delay_re = NULL;
+ hs->rot_vec_syn_delay_im = NULL;
+ }
+ else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ hs->p_filter = LDQMF_30;
+ hs->scale = LDQMF_30_SCALE;
+ hs->ds = 120;
+ hs->da = -60;
+ hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF;
+ hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF;
+ }
+ break;
+
+ case 32:
+ hs->rot_vec_ana_re = rot_vec_ana_re_L32;
+ hs->rot_vec_ana_im = rot_vec_ana_im_L32;
+ hs->rot_vec_syn_re = rot_vec_syn_re_L32;
+ hs->rot_vec_syn_im = rot_vec_syn_im_L32;
+ if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS )
+ {
+ hs->p_filter = CLDFB80_32;
+ hs->scale = CLDFB80_32_SCALE;
+ hs->ds = 32;
+ hs->da = 32;
+ hs->rot_vec_ana_delay_re = NULL;
+ hs->rot_vec_ana_delay_im = NULL;
+ hs->rot_vec_syn_delay_re = NULL;
+ hs->rot_vec_syn_delay_im = NULL;
+ }
+ else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ hs->p_filter = LDQMF_32;
+ hs->scale = LDQMF_32_SCALE;
+ hs->ds = 160;
+ hs->da = -80;
+ hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF;
+ hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF;
+ }
+ break;
+
+ case 40:
+ hs->rot_vec_ana_re = rot_vec_ana_re_L40;
+ hs->rot_vec_ana_im = rot_vec_ana_im_L40;
+ hs->rot_vec_syn_re = rot_vec_syn_re_L40;
+ hs->rot_vec_syn_im = rot_vec_syn_im_L40;
+ if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS )
+ {
+ hs->p_filter = CLDFB80_40;
+ hs->scale = CLDFB80_40_SCALE;
+ hs->ds = 40;
+ hs->da = 40;
+ hs->rot_vec_ana_delay_re = NULL;
+ hs->rot_vec_ana_delay_im = NULL;
+ hs->rot_vec_syn_delay_re = NULL;
+ hs->rot_vec_syn_delay_im = NULL;
+ }
+ else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ hs->p_filter = LDQMF_40;
+ hs->scale = LDQMF_40_SCALE;
+ hs->ds = 160;
+ hs->da = -80;
+ hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF;
+ hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF;
+ }
+ break;
+
+ case 60:
+ hs->rot_vec_ana_re = rot_vec_ana_re_L60;
+ hs->rot_vec_ana_im = rot_vec_ana_im_L60;
+ hs->rot_vec_syn_re = rot_vec_syn_re_L60;
+ hs->rot_vec_syn_im = rot_vec_syn_im_L60;
+ if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS )
+ {
+ hs->p_filter = CLDFB80_60;
+ hs->scale = CLDFB80_60_SCALE;
+ hs->ds = 60;
+ hs->da = 60;
+ hs->rot_vec_ana_delay_re = NULL;
+ hs->rot_vec_ana_delay_im = NULL;
+ hs->rot_vec_syn_delay_re = NULL;
+ hs->rot_vec_syn_delay_im = NULL;
+ }
+ else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS )
+ {
+ hs->p_filter = LDQMF_60;
+ hs->scale = LDQMF_60_SCALE;
+ hs->ds = 240;
+ hs->da = -120;
+ hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF;
+ hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF;
+ hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF;
+ }
+ break;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * cldfb_save_memory()
+ *
+ * Save the memory of filter; to be restored with cldfb_restore_memory()
+ *--------------------------------------------------------------------*/
+
+ivas_error cldfb_save_memory(
+ HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */
+)
+{
+ uint16_t offset = hs->p_filter_length - hs->no_channels;
+
+ if ( hs->memory != NULL || hs->memory_length != 0 )
+ {
+ /* memory already stored; Free memory first */
+ return IVAS_ERR_OK;
+ }
+
+ if ( hs->type == CLDFB_ANALYSIS )
+ {
+ hs->memory_length = offset;
+ }
+ else
+ {
+ hs->memory_length = hs->p_filter_length;
+ }
+
+ if ( ( hs->memory = (float *) malloc( hs->memory_length * sizeof( float ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" );
+ }
+
+ /* save the memory */
+ mvr2r( hs->cldfb_state, hs->memory, hs->memory_length );
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-------------------------------------------------------------------*
+ * cldfb_restore_memory()
+ *
+ * Restores the memory of filter; memory to be save by cldfb_save_memory()
+ *--------------------------------------------------------------------*/
+
+void cldfb_restore_memory(
+ HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */
+)
+{
+ uint16_t offset = hs->p_filter_length - hs->no_channels;
+ uint16_t size;
+
+ if ( hs->memory == NULL || hs->memory_length == 0 )
+ {
+ /* memory not allocated */
+ return;
+ }
+
+ if ( hs->type == CLDFB_ANALYSIS )
+ {
+ size = offset;
+ }
+ else
+ {
+ size = hs->p_filter_length;
+ }
+
+ /* read the memory */
+ mvr2r( hs->memory, hs->cldfb_state, hs->memory_length );
+
+ /* adjust sample rate if it was changed in the meanwhile */
+ if ( hs->memory_length != size )
+ {
+ lerp( hs->cldfb_state, hs->cldfb_state, size, hs->memory_length );
+ }
+
+ hs->memory_length = 0;
+ free( hs->memory );
+ hs->memory = NULL;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * cldfb_reset_memory()
+ *
+ * Resets the memory of filter.
+ *--------------------------------------------------------------------*/
+
+void cldfb_reset_memory(
+ HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */
+)
+{
+ uint16_t offset = hs->p_filter_length - hs->no_channels;
+ int16_t memory_length;
+
+ if ( hs->type == CLDFB_ANALYSIS )
+ {
+ memory_length = offset;
+ }
+ else
+ {
+ memory_length = hs->p_filter_length;
+ }
+
+ /* save the memory */
+ set_f( hs->cldfb_state, 0, memory_length );
+
+ return;
+}
diff --git a/lib_com/cng_exc.c b/lib_com/cng_exc.c
new file mode 100644
index 0000000000000000000000000000000000000000..8fdc68921b1a5080204f0a7b48790f986184e945
--- /dev/null
+++ b/lib_com/cng_exc.c
@@ -0,0 +1,618 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * Local constants
+ *---------------------------------------------------------------------*/
+
+#define A2 0.2f
+#define GAIN_VAR 0.000011f
+
+/*-------------------------------------------------------*
+ * CNG_exc()
+ *
+ * Comfort noise generation routine
+ *-------------------------------------------------------*/
+
+void CNG_exc(
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t L_frame, /* i : length of the frame */
+ float *Enew, /* i/o: decoded SID energy */
+ int16_t *seed, /* i/o: random generator seed */
+ float exc[], /* o : current non-enhanced excitation */
+ float exc2[], /* o : current enhanced excitation */
+ float *lp_ener, /* i/o: LP filtered E */
+ const int32_t last_core_brate, /* i : previous frame core bitrate */
+ int16_t *first_CNG, /* i/o: first CNG frame flag for energy init. */
+ int16_t *cng_ener_seed, /* i/o: random generator seed for CNG energy */
+ float bwe_exc[], /* o : excitation for SWB TBE */
+ const int16_t allow_cn_step, /* i : allow CN step */
+ int16_t *last_allow_cn_step, /* i/o: last allow step */
+ const int16_t num_ho, /* i : number of selected hangover frames */
+ float q_env[],
+ float *lp_env,
+ float *old_env,
+ float *exc_mem,
+ float *exc_mem1,
+ int16_t *sid_bw,
+ int16_t *cng_ener_seed1,
+ float exc3[],
+ const int16_t Opt_AMR_WB, /* i : AMR-WB interop flag */
+ const int16_t element_mode /* i : IVAS Element mode */
+)
+{
+ float enr;
+ int16_t i;
+ float ener_lp;
+ int16_t i_subfr;
+ int16_t pit_max;
+ float ftmp;
+ float *ptR, *ptI;
+ float fft_io[L_FRAME16k];
+ float itmp[129];
+ float env[NUM_ENV_CNG];
+ float enr1;
+ float denv[NUM_ENV_CNG];
+
+ /*------------------------------------------------------------------*
+ * Initializations
+ *------------------------------------------------------------------*/
+
+ if ( L_frame == L_FRAME )
+ {
+ pit_max = PIT_MAX;
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ pit_max = PIT16k_MAX;
+ }
+
+ /*---------------------------------------------------------------------*
+ * Initialization of CNG energy for the first CNG frame
+ *---------------------------------------------------------------------*/
+
+ if ( *first_CNG == 0 )
+ {
+ if ( core_brate == FRAME_NO_DATA )
+ {
+ /* needed only in decoder when the very first SID frame was erased and this frame is FRAME_NO_DATA frame */
+ *Enew = dotp( exc - pit_max, exc - pit_max, pit_max ) / pit_max;
+ }
+
+ if ( element_mode == EVS_MONO )
+ {
+ *lp_ener = *Enew;
+ }
+ }
+
+ /*---------------------------------------------------------------------*
+ * Update CNG energy
+ *---------------------------------------------------------------------*/
+
+ if ( last_core_brate != SID_1k75 && last_core_brate != FRAME_NO_DATA && last_core_brate != SID_2k40 )
+ {
+ /* Partially reset CNG energy after active speech period */
+ if ( allow_cn_step == 0 && *last_allow_cn_step == 0 )
+ {
+ if ( num_ho < 3 || *Enew < 1.5f * *lp_ener )
+ {
+ *lp_ener = 0.8f * *lp_ener + 0.2f * *Enew;
+ }
+ else
+ {
+ *lp_ener = 0.95f * *lp_ener + 0.05f * *Enew;
+ }
+ }
+ else
+ {
+ *lp_ener = *Enew;
+ *last_allow_cn_step = 0;
+ }
+ }
+ else
+ {
+ /* normal CNG update */
+ if ( *last_allow_cn_step == 0 )
+ {
+ *lp_ener = (float) ( A2 * *Enew + ( 1 - A2 ) * *lp_ener );
+ }
+ else
+ {
+ if ( core_brate == SID_1k75 || core_brate == SID_2k40 )
+ {
+ *last_allow_cn_step = 0;
+ }
+
+ *lp_ener = *Enew;
+ }
+ }
+
+ if ( allow_cn_step == 1 )
+ {
+ *last_allow_cn_step = 1;
+ }
+
+ /* If not mono, skip CNG here */
+ if ( element_mode > IVAS_SCE )
+ {
+ return;
+ }
+
+ /*---------------------------------------------------------------------*
+ * Generate white noise vector
+ *---------------------------------------------------------------------*/
+
+ for ( i = 0; i < L_frame; i++ )
+ {
+ exc2[i] = (float) own_random( seed );
+ }
+
+ /*------------------------------------------------------------*
+ * Insert random variation for excitation energy
+ * (random variation is scaled according to *lp_ener value)
+ *------------------------------------------------------------*/
+
+ for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
+ {
+ ener_lp = ( ( own_random( cng_ener_seed ) * ( *lp_ener ) ) * GAIN_VAR ) + ( *lp_ener );
+
+ if ( ener_lp < 0.0f )
+ {
+ ener_lp = 0.01f;
+ }
+ enr = dotp( &exc2[i_subfr], &exc2[i_subfr], L_SUBFR ) + 0.01f;
+
+ enr = (float) sqrt( ener_lp * L_SUBFR / enr );
+
+ for ( i = 0; i < L_SUBFR; i++ )
+ {
+ exc2[i_subfr + i] *= enr;
+ }
+ }
+
+ if ( Opt_AMR_WB != 1 )
+ {
+ mvr2r( exc2, exc3, L_FRAME16k );
+
+ enr1 = (float) log10( *Enew * L_frame + 0.1f ) / (float) log10( 2.0f );
+
+ if ( core_brate == SID_2k40 )
+ {
+ if ( *sid_bw == 0 )
+ {
+ for ( i = 0; i < NUM_ENV_CNG; i++ )
+ {
+ /* get quantized envelope */
+ env[i] = powf( 2.0f, ( enr1 - q_env[i] ) );
+ }
+ }
+
+ /* initialize CNG envelope */
+ if ( *first_CNG == 0 && *sid_bw == 0 )
+ {
+ mvr2r( env, lp_env, NUM_ENV_CNG );
+ }
+
+ if ( *sid_bw == 0 )
+ {
+ mvr2r( env, old_env, NUM_ENV_CNG );
+ }
+ }
+
+ for ( i = 0; i < NUM_ENV_CNG; i++ )
+ {
+ /* get AR low-passed envelope */
+ lp_env[i] = 0.9f * lp_env[i] + ( 1 - 0.9f ) * old_env[i];
+ }
+
+ /* calculate the spectrum of random excitation signal */
+ mvr2r( exc2, fft_io, L_frame );
+
+ if ( L_frame == L_FRAME16k )
+ {
+ modify_Fs( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem1, 0 );
+ }
+
+ fft_rel( 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;
+ ptR++;
+ ptI--;
+ }
+
+ for ( i = 0; i < NUM_ENV_CNG; i++ )
+ {
+ denv[i] = lp_env[i] + 2 * ( *lp_ener ) - env[i];
+
+ if ( denv[i] < 0 )
+ {
+ denv[i] = 0;
+ }
+ }
+ set_f( itmp, 0.0f, NUM_ENV_CNG );
+
+ set_f( fft_io, 0.0f, L_FFT );
+ ptR = &fft_io[1];
+ ptI = &fft_io[L_FFT - 1];
+ for ( i = 0; i < NUM_ENV_CNG; i++ )
+ {
+ *ptR = own_random( cng_ener_seed1 );
+ *ptI = own_random( cng_ener_seed1 );
+
+ env[i] = 2.0f * ( *ptR * *ptR + *ptI * *ptI ) / L_FFT;
+ ptR++;
+ ptI--;
+ }
+
+ for ( i = 0; i < NUM_ENV_CNG; i++ )
+ {
+ itmp[i] += own_random( cng_ener_seed1 ) * denv[i] * 0.000011f + denv[i];
+
+ if ( itmp[i] < 0.0f )
+ {
+ itmp[i] = 0;
+ }
+ }
+
+ ptR = &fft_io[1];
+ ptI = &fft_io[L_FFT - 1];
+ for ( i = 0; i < NUM_ENV_CNG; i++ )
+ {
+ *ptR = (float) ( *ptR * sqrt( itmp[i] / env[i] ) );
+ *ptI = (float) ( *ptI * sqrt( itmp[i] / env[i] ) );
+
+ ptR++;
+ ptI--;
+ }
+
+ ifft_rel( fft_io, L_FFT, LOG2_L_FFT );
+
+ if ( L_frame == L_FRAME16k )
+ {
+ modify_Fs( fft_io, L_FFT, 12800, fft_io, 16000, exc_mem, 0 );
+ }
+
+ enr1 = dotp( fft_io, fft_io, L_frame ) / L_frame;
+
+ /* add time domain randomization */
+ for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
+ {
+ enr = dotp( &fft_io[i_subfr], &fft_io[i_subfr], L_SUBFR ) + 0.01f;
+ ener_lp = ( ( own_random( cng_ener_seed1 ) * ( enr1 ) ) * 0.000011f ) + ( enr1 );
+ ener_lp *= L_SUBFR;
+ enr = (float) sqrt( ener_lp / enr );
+
+ if ( last_core_brate != SID_2k40 && last_core_brate != SID_1k75 && last_core_brate != FRAME_NO_DATA && core_brate == SID_2k40 )
+ {
+ if ( enr > 1 )
+ {
+ enr = 1;
+ }
+ }
+
+ for ( i = 0; i < L_SUBFR; i++ )
+ {
+ fft_io[i_subfr + i] *= enr;
+ }
+ }
+
+ for ( i = 0; i < L_frame; i++ )
+ {
+ fft_io[i] = 0.75f * fft_io[i] + exc2[i];
+ }
+
+ enr = ( dotp( fft_io, fft_io, L_frame ) / L_frame ) + 0.01f;
+ enr = ( *lp_ener ) / enr;
+
+ if ( enr > 1 )
+ {
+ enr = 1;
+ }
+
+ ftmp = sqrtf( enr );
+ for ( i = 0; i < L_frame; i++ )
+ {
+ fft_io[i] *= ftmp;
+ }
+
+ mvr2r( fft_io, exc2, L_frame );
+ }
+ if ( Opt_AMR_WB != 1 )
+ {
+ mvr2r( exc3, exc, L_frame );
+ }
+ else
+ {
+ mvr2r( exc2, exc, L_frame );
+ }
+
+ if ( L_frame == L_FRAME )
+ {
+ interp_code_5over2( exc2, bwe_exc, L_frame );
+ }
+ else
+ {
+ interp_code_4over2( exc2, bwe_exc, L_frame );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------*
+ * cng_params_postupd
+ *
+ * Post-update of CNG parameters
+ *-------------------------------------------------------*/
+
+void cng_params_postupd(
+ const int16_t ho_circ_ptr, /* i : pointer for CNG averaging buffers */
+ int16_t *cng_buf_cnt, /* i/o: counter for CNG store buffers */
+ const float *cng_exc2_buf, /* i : Excitation buffer */
+ const int32_t *cng_brate_buf, /* i : bitrate buffer */
+ float ho_env_circ[], /* i/o: Envelope buffer */
+ const int16_t element_mode, /* i : Element mode */
+ const int16_t bwidth /* i : Audio bandwidth */
+)
+{
+ int16_t i, j;
+ const float *exc2;
+ float fft_io[L_FFT];
+ float sp[129];
+ float *ptR, *ptI;
+ float env[NUM_ENV_CNG];
+ int16_t CNG_mode;
+ int16_t ptr;
+ float att;
+ int32_t last_active_brate;
+
+ ptr = ho_circ_ptr - *cng_buf_cnt + 1;
+ if ( ptr < 0 )
+ {
+ ptr += HO_HIST_SIZE;
+ }
+
+ for ( j = 0; j < *cng_buf_cnt; j++ )
+ {
+ exc2 = &cng_exc2_buf[ptr * L_FFT];
+ last_active_brate = cng_brate_buf[ptr];
+
+ /* calculate the spectrum of residual signal */
+ /* calculate the spectrum of residual signal */
+ mvr2r( exc2, fft_io, L_FFT );
+
+ fft_rel( 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++ )
+ {
+ sp[i] = 2.0f * ( *ptR * *ptR + *ptI * *ptI ) / L_FFT;
+ ptR++;
+ ptI--;
+ }
+
+ mvr2r( sp, env, NUM_ENV_CNG );
+
+ if ( element_mode == IVAS_SCE || element_mode == IVAS_CPE_DFT )
+ {
+ att = 0.0f;
+ apply_scale( &att, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO );
+ att = powf( 10, att / 10.0f );
+ }
+ else
+ {
+ CNG_mode = get_cng_mode( last_active_brate );
+ att = (float) ( 1 / pow( 2, ENR_ATT[CNG_mode] ) );
+ }
+
+ for ( i = 0; i < NUM_ENV_CNG; i++ )
+ {
+ env[i] *= att;
+ }
+
+ /* update the circular buffer of old residual envelope */
+ mvr2r( env, &( ho_env_circ[(ho_circ_ptr) *NUM_ENV_CNG] ), NUM_ENV_CNG );
+
+ ptr++;
+ if ( ptr == HO_HIST_SIZE )
+ {
+ ptr = 0;
+ }
+ }
+
+ *cng_buf_cnt = 0;
+
+ return;
+}
+
+
+/*-------------------------------------------------------*
+ * cng_params_upd()
+ *
+ * update CNG parameters
+ *-------------------------------------------------------*/
+
+void cng_params_upd(
+ const float lsp_new[], /* i : LSP parameters */
+ const float exc2[], /* i : current enhanced excitation */
+ const int16_t L_frame, /* i : frame length */
+ int16_t *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers */
+ float ho_ener_circ[], /* o : energy buffer for CNG averaging */
+ int16_t *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging */
+ float ho_lsp_circ[], /* o : old LSP buffer for CNG averaging */
+ const int16_t enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */
+ float ho_env_circ[], /* i/o: Envelope buffer */
+ int16_t *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */
+ float cng_exc2_buf[], /* i/o: Excitation buffer */
+ int32_t cng_brate_buf[], /* i/o: last_active_brate buffer */
+ const int32_t last_active_brate, /* i : Last active bitrate */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t bwidth /* i : audio bandwidth */
+)
+{
+ float enr;
+ float fft_io[L_FRAME16k];
+ float sp[129];
+ float *ptR, *ptI;
+ float env[NUM_ENV_CNG];
+ int16_t i;
+ int16_t CNG_mode;
+ float att;
+
+ /* update the pointer to circular buffer of old LSP vectors */
+ ( *ho_circ_ptr )++;
+ if ( *ho_circ_ptr == HO_HIST_SIZE )
+ {
+ *ho_circ_ptr = 0;
+ }
+
+ /* update the circular buffer of old LSP vectors with the new LSP vector */
+ mvr2r( lsp_new, &( ho_lsp_circ[( *ho_circ_ptr ) * M] ), M );
+
+ /* calculate the residual signal energy */
+ enr = dotp( exc2, exc2, L_frame ) / L_frame;
+
+ /* update the circular buffer of old energies */
+ ho_ener_circ[*ho_circ_ptr] = enr;
+
+ if ( enc_dec_flag == ENC )
+ {
+ /* Store residual signal for postponed FFT-processing*/
+ ( *cng_buf_cnt )++;
+ if ( *cng_buf_cnt > HO_HIST_SIZE )
+ {
+ *cng_buf_cnt = HO_HIST_SIZE;
+ }
+ mvr2r( exc2, &( cng_exc2_buf[( *ho_circ_ptr ) * L_FFT] ), L_FFT );
+ cng_brate_buf[*ho_circ_ptr] = last_active_brate;
+ }
+ else
+ {
+
+ /* calculate the spectrum of residual signal */
+ mvr2r( exc2, fft_io, L_frame );
+
+ fft_rel( 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++ )
+ {
+ sp[i] = 2.0f * ( *ptR * *ptR + *ptI * *ptI ) / L_FFT;
+ ptR++;
+ ptI--;
+ }
+
+ mvr2r( sp, env, NUM_ENV_CNG );
+
+ if ( element_mode == IVAS_SCE || element_mode == IVAS_CPE_DFT )
+ {
+ att = 0.0f;
+ apply_scale( &att, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO );
+ att = powf( 10, att / 10.0f );
+ }
+ else
+ {
+ CNG_mode = get_cng_mode( last_active_brate );
+ att = (float) ( 1 / pow( 2, ENR_ATT[CNG_mode] ) );
+ }
+
+ for ( i = 0; i < NUM_ENV_CNG; i++ )
+ {
+ env[i] *= att;
+ }
+
+ /* update the circular buffer of old residual envelope */
+ mvr2r( env, &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG );
+ }
+
+ ( *ho_circ_size )++;
+ if ( *ho_circ_size > HO_HIST_SIZE )
+ {
+ *ho_circ_size = HO_HIST_SIZE;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * get_cng_mode()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+int16_t get_cng_mode(
+ const int32_t last_active_brate /* i : last active bitrate */
+)
+{
+ int16_t CNG_mode;
+
+ if ( last_active_brate > ACELP_13k20 )
+ {
+ CNG_mode = 4;
+ }
+ else if ( last_active_brate > ACELP_9k60 )
+ {
+ CNG_mode = 3;
+ }
+ else if ( last_active_brate > ACELP_8k00 )
+ {
+ CNG_mode = 2;
+ }
+ else if ( last_active_brate > ACELP_7k20 )
+ {
+ CNG_mode = 1;
+ }
+ else
+ {
+ CNG_mode = 0;
+ }
+
+ return ( CNG_mode );
+}
diff --git a/lib_com/cnst.h b/lib_com/cnst.h
new file mode 100644
index 0000000000000000000000000000000000000000..5bfffa4dd4219e13cd8c5c042b141773e2f9c645
--- /dev/null
+++ b/lib_com/cnst.h
@@ -0,0 +1,2233 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 CNST_H
+#define CNST_H
+
+#include
+#include "options.h"
+
+/* clang-format off */
+
+/*----------------------------------------------------------------------------------*
+ * General constants
+ *----------------------------------------------------------------------------------*/
+
+#define MODE1 1
+#define MODE2 2
+
+#define EVS_PI 3.14159265358979323846264338327950288f
+
+#define PI2 ( 2 * EVS_PI )
+#define RANDOM_INITSEED 21845 /* Seed for random generators */
+#ifndef FLT_MIN
+#define FLT_MIN ( 1.175494351e-38F )
+#endif
+#ifndef FLT_MAX
+#define FLT_MAX ( 3.402823466e+38F )
+#endif
+#define TRUE 1
+#define FALSE 0
+
+#define MAX16B 32767
+#define MIN16B ( -32768 )
+#define MAX16B_FLT 32767.0f
+#define MIN16B_FLT ( -32768.0f )
+#define PCM16_TO_FLT_FAC 32768.0f
+#define MDFT_NORM_SCALING ( 1.0f / PCM16_TO_FLT_FAC )
+#define MAX_FRAME_COUNTER 200
+#define MAX_BITS_PER_FRAME 10240 /* Bits per frame for max. bitrate 512kbps, == IVAS_MAX_BITS_PER_FRAME */
+
+#define ENC 0 /* Index for "encoder" */
+#define DEC 1 /* Index for "decoder" */
+
+#define DEC_IVAS 2 /* Index for IVAS decoder */
+
+
+enum{
+ NB = 0, /* Indicator of 4 kHz bandwidth */
+ WB = 1, /* Indicator of 8 kHz bandwidth */
+ SWB = 2, /* Indicator of 14 kHz bandwidth */
+ FB = 3 /* Indicator of 20 kHz bandwidth */
+};
+
+/* Conversion of bandwidth string into numerical constant */
+#define CONV_BWIDTH( bw ) ( !strcmp( bw, "NB" ) ? NB : !strcmp( bw, "WB" ) ? WB : !strcmp( bw, "SWB" ) ? SWB : !strcmp( bw, "FB" ) ? FB : -1 )
+
+#define L_FRAME48k 960 /* Frame size in samples at 48kHz */
+#define L_FRAME32k 640 /* Frame size in samples at 32kHz */
+#define L_FRAME25_6k 512 /* Frame size in samples at 25.6kHz */
+#define L_FRAME16k 320 /* Frame size in samples at 16kHz */
+#define L_FRAME8k 160 /* Frame size in samples at 8kHz */
+#define L_FRAME4k 80 /* Frame size in samples at 4kHz */
+
+#define L_SPEC48k 800 /* HQ spectrum length at 48kHz */
+#define L_SPEC32k 640 /* HQ spectrum length at 32kHz */
+#define L_SPEC16k 320 /* HQ spectrum length at 16kHz */
+#define L_SPEC8k 160 /* HQ spectrum length at 8kHz */
+#define L_SPEC48k_EXT 1000 /* Extended HQ spectrum length at 48kHz, for ACELP->HQ switching */
+#define L_SPEC32k_EXT 800 /* Extended HQ spectrum length at 32kHz, for ACELP->HQ switching */
+#define L_SPEC16k_EXT 400 /* Extended HQ spectrum length at 16kHz, for ACELP->HQ switching */
+#define L_FRAME48k_EXT 1200 /* Extended MDCT frame size in samples at 48kHz */
+
+/* Conversion of ns to samples for a given sampling frequency */
+#define NS2SA( fs, x ) ( int16_t )( ( ( ( int32_t )( fs ) / 100L ) * ( ( x ) / 100L ) ) / 100000L )
+
+#define ACTIVE_FRAME 0xFF
+#define SID_FRAME 0xFA
+#define ZERO_FRAME 0xF0
+#define FRAME_SIZE_NB 13
+
+#define RATE_MODE_MAX 2 /* Number of rate mode */
+#define BANDWIDTH_MODE_MAX 2 /* Number of different bandwidth (NB/WB-FB) */
+
+#define MIN_LOG_60dB 0.000001f
+#define MIN_LOG_VAL_60dB -60.0f
+
+#define INV_LOG_2 1.442695040888963f /* 1/log(2) */
+#define INV_SQRT_2 0.70710676908493f /* 1/sqrt(2) */
+
+#define MAX_V_MULT_MAT 100 /* maximum array length for the function v_mult_mat() */
+
+#define SBA_AGC_FORCE_ENABLE 1
+#define SBA_AGC_FORCE_DISABLE 0
+#define SBA_AGC_DEFAULT -1
+
+/*----------------------------------------------------------------------------------*
+ * Layers
+ *----------------------------------------------------------------------------------*/
+
+#define ACELP_CORE 0 /* ACELP core layer */
+#define TCX_20_CORE 1 /* TCX 20ms core layer */
+#define TCX_10_CORE 2 /* TCX 10ms core layer */
+#define HQ_CORE 3 /* HQ core layer */
+#define AMR_WB_CORE 4 /* AMR-WB IO core */
+
+
+#define WB_TBE 5 /* WB TBE layer (16/32/48kHz signals) */
+#define WB_BWE 6 /* WB BWE layer optimized for music (16/32/48kHz signals) */
+
+#define SWB_CNG 7 /* SWB CNG layer (32/48kHz signals) */
+#define SWB_TBE 8 /* SWB TBE layer optimized for speech (32/48kHz signals) */
+#define SWB_BWE 9 /* SWB BWE layer optimized for music (32/48kHz signals) */
+#define SWB_BWE_HIGHRATE 10 /* SWB BWE layer optimized for highrate speech (32/48kHz) */
+
+#define FB_TBE 11 /* FB TBE layer (48kHz signals) */
+#define FB_BWE 12 /* FB BWE layer optimized for music (48kHz) */
+#define FB_BWE_HIGHRATE 13 /* FB BWE layer optimized for highrate speech (48kHz) */
+
+#define IGF_BWE 14 /* IGF layer for music (16.4 and 24.4kbps), 32kHz signals */
+
+#define LP_CNG 0 /* LP-based CNG in DTX operation */
+#define FD_CNG 1 /* FD-based CNG in DTX operation */
+
+/*----------------------------------------------------------------------------------*
+ * Bitrates
+ *----------------------------------------------------------------------------------*/
+
+#define FRAME_NO_DATA 0 /* Frame with no data */
+#define SID_1k75 1750 /* SID at 1.75 kbps (used only in AMR-WB IO mode */
+#define SID_2k40 2400 /* SID at 2.40 kbps */
+#define PPP_NELP_2k80 2800 /* PPP and NELP at 2.80 kbps (used only for SC-VBR) */
+#define ACELP_5k90 5900 /* ACELP core layer at average bitrate of 5.90 kbps (used only in SC-VBR mode) */
+#define ACELP_5k00 5000 /* ACELP core layer at 5.00 kbps (used only in TD stereo secondary channel) */
+#define ACELP_6k15 6150 /* ACELP core layer at 6.15 kbps (used only in TD stereo secondary channel) */
+#define ACELP_6k60 6600 /* ACELP core layer at 6.60 kbps (used only in AMR-WB IO mode) */
+#define ACELP_7k20 7200 /* ACELP core layer at 7.20 kbps */
+#define ACELP_8k00 8000 /* ACELP core layer at 8 kbps */
+#define ACELP_8k85 8850 /* ACELP core layer at 8.85 kbps (used only in AMR-WB IO mode) */
+#define ACELP_9k60 9600 /* ACELP core layer at 9.60 kbps */
+#define ACELP_11k60 11600 /* ACELP core layer at 11.60 kbps (used for SWB TBE) */
+#define ACELP_12k15 12150 /* ACELP core layer at 12.15 kbps (used for WB TBE) */
+#define ACELP_12k65 12650 /* ACELP core layer at 12.65 kbps (used only in AMR-WB IO mode) */
+#define ACELP_12k85 12850 /* ACELP core layer at 12.85 kbps (used for WB BWE) */
+#define ACELP_13k20 13200 /* ACELP core layer at 13.20 kbps */
+#define ACELP_14k25 14250 /* ACELP core layer at 14.25 kbps (used only in AMR-WB IO mode) */
+#define ACELP_14k80 14800 /* ACELP core layer at 14.80 kbps (used only in core switching) */
+#define ACELP_15k85 15850 /* ACELP core layer at 15.85 kbps (used only in AMR-WB IO mode) */
+#define ACELP_16k40 16400 /* ACELP core layer at 16.40 kbps */
+#define ACELP_18k25 18250 /* ACELP core layer at 18.25 kbps (used only in AMR-WB IO mode) */
+#define ACELP_19k85 19850 /* ACELP core layer at 19.85 kbps (used only in AMR-WB IO mode) */
+#define ACELP_22k60 22600 /* ACELP core layer at 22.60 kbps (used only in core switching) */
+#define ACELP_23k05 23050 /* ACELP core layer at 23.05 kbps (used only in AMR-WB IO mode) */
+#define ACELP_23k85 23850 /* ACELP core layer at 23.85 kbps (used only in AMR-WB IO mode) */
+#define ACELP_24k40 24400 /* ACELP core layer at 24.40 kbps */
+#define ACELP_29k00 29000 /* ACELP core layer at 29.00 kbps (used for FB + SWB TBE) */
+#define ACELP_29k20 29200 /* ACELP core layer at 29.20 kbps (used for SWB TBE) */
+#define ACELP_30k20 30200 /* ACELP core layer at 30.20 kbps (used for FB + SWB BWE) */
+#define ACELP_30k40 30400 /* ACELP core layer at 30.40 kbps (used for SWB BWE) */
+#define ACELP_32k 32000 /* ACELP core layer at 32 kbps */
+#define ACELP_48k 48000 /* ACELP core layer at 48 kbps */
+#define ACELP_64k 64000 /* ACELP core layer at 64 kbps */
+
+#define HQ_16k40 16400 /* HQ core at 16.4 kbps */
+#define HQ_13k20 13200 /* HQ core at 13.2 kbps */
+#define HQ_24k40 24400 /* HQ core at 24.4 kbps */
+#define HQ_32k 32000 /* HQ core at 32 kbps */
+#define HQ_48k 48000 /* HQ core at 48 kbps */
+#define HQ_64k 64000 /* HQ core at 64 kbps */
+#define HQ_96k 96000 /* HQ core at 96 kbps */
+#define HQ_128k 128000 /* HQ core at 128 kbps */
+
+#define WB_TBE_0k35 350 /* WB TBE layer (used only at 9.6 kbps on top of ACELP@12k8 core for 16kHz signals) */
+#define WB_BWE_0k35 350 /* WB BWE layer (used only on top of ACELP@12k8 core for 16kHz signals) */
+#define WB_TBE_1k05 1050 /* WB TBE layer (used only on top of ACELP@12k8 core for 16kHz signals) */
+#define SWB_TBE_0k95 950 /* SWB TBE layer (used in low SWB bitrates) */
+#define SWB_TBE_1k10 1100 /* SWB TBE layer in LRTD stereo */
+#define SWB_TBE_1k75 1750 /* SWB TBE layer in LRTD stereo */
+#define SWB_TBE_1k6 1600 /* SWB TBE layer */
+#define SWB_BWE_1k6 1600 /* SWB BWE layer */
+#define FB_TBE_1k8 1800 /* SWB+FB TBE layer (used only for 48kHz signals) */
+#define FB_BWE_1k8 1800 /* SWB+FB BWE layer (used only for 48kHz signals) */
+#define SWB_TBE_2k8 2800 /* SWB TBE layer @32kbps */
+#define FB_TBE_3k0 3000 /* SWB+FB TBE layer @32kbps (used only for 48kHz signals) */
+#define SWB_BWE_16k 16000 /* SWB BWE layer for highrate SWB speech */
+
+#define GSC_LRES_GAINQ_LIMIT 3000 /* Bitrate where the low resolution quantization starts for the GSC */
+#define GSC_LRES_NB_NITS 10 /* Number of bits gained by using the low resolution quantization */
+
+#define SIZE_BRATE_TBL 11
+#define SIZE_BRATE_INTERMED_TBL 22
+
+#define BRATE2IDX( brate ) ( brate == ACELP_5k00 ? 0 : brate == ACELP_6k15 ? 1 : brate == ACELP_7k20 ? 2 : brate == ACELP_8k00 ? 3 : brate == ACELP_9k60 ? 4 : brate == ACELP_11k60 ? 5 : brate == ACELP_12k15 ? 6 : brate == ACELP_12k85 ? 7 : brate == ACELP_13k20 ? 8 : brate == ACELP_14k80 ? 9 : brate == ACELP_16k40 ? 10 : brate == ACELP_22k60 ? 11 : brate == ACELP_24k40 ? 12 : brate == ACELP_29k00 ? 13 : brate == ACELP_29k20 ? 14 : brate == ACELP_30k20 ? 15 : brate == ACELP_30k40 ? 16 : brate == ACELP_32k ? 17 : brate == ACELP_48k ? 18 : brate == ACELP_64k ? 19 : brate == HQ_96k ? 20 : brate == HQ_128k ? 21 : -1 )
+
+#define BRATE2IDX16k( brate ) ( brate == ACELP_8k00 ? 0 : brate == ACELP_14k80 || brate == ACELP_16k40 ? 1 : brate == ACELP_22k60 ? 2 : brate == ACELP_24k40 ? 3 : brate == ACELP_29k00 ? 4 : brate == ACELP_29k20 ? 5 : brate == ACELP_30k20 ? 6 : brate == ACELP_30k40 ? 7 : brate == ACELP_32k ? 8 : brate == ACELP_48k ? 9 : brate == ACELP_64k ? 10 : -1 )
+
+/* Combine parameters into a single index (used to retrieve number of bits from bit allocation tables) */
+#define LSF_BIT_ALLOC_IDX( brate, ctype ) ( 6 * BRATE2IDX( brate ) + ( ctype ) )
+
+#define BIT_ALLOC_IDX( brate, ctype, sfrm, tc ) \
+ ( ( sfrm != -1 ? NB_SUBFR : 1 ) * \
+ ( ( tc == -1 ? 4 : 10 ) * BRATE2IDX( brate ) + ( ctype == INACTIVE ? GENERIC : ctype ) - 1 + ( tc == -1 ? 0 : tc ) ) + \
+ ( sfrm != -1 ? sfrm / L_SUBFR : 0 ) )
+
+#define BIT_ALLOC_IDX_16KHZ( brate, ctype, sfrm, tc ) \
+ ( ( sfrm > -1 ? NB_SUBFR16k : 1 ) * \
+ ( ( tc == -1 ? 3 : 7 ) * BRATE2IDX16k( brate ) + ( ctype == TRANSITION ? 2 : ( ctype == GENERIC ? 1 : 0 ) ) + ( tc == -1 ? 0 : tc ) ) + \
+ ( sfrm != -1 ? sfrm / L_SUBFR : 0 ) )
+
+/* Combine coder_type, bandwidth, formant sharpening flag, and channel-aware flag into one indice */
+#define SIG2IND( ctype, bw, sf, ca_rf ) ( ctype | ( bw << 3 ) | ( sf << 6 ) | ( ca_rf << 7 ) )
+
+#define MAX_ACELP_SIG 100
+
+/*----------------------------------------------------------------------------------*
+ * Bitstream indices
+ *----------------------------------------------------------------------------------*/
+
+#define MAX_PVQ_PUSH_IND 320 /* Maximum number of (fwd+reverse) calls to push_indices for the PVQ_range encoder */
+
+enum
+{
+ IND_IVAS_FORMAT,
+ IND_SMODE_OMASA,
+ IND_SMODE,
+ IND_SID_TYPE,
+ IND_BWIDTH,
+ IND_CORE,
+ IND_PPP_NELP_MODE,
+ IND_ACELP_16KHZ,
+ IND_ACELP_SIGNALLING,
+ IND_SHARP_FLAG,
+ IND_MDCT_CORE,
+ IND_TCX_CORE,
+ IND_BWE_FLAG,
+ IND_HQ_SWITCHING_FLG,
+ IND_LAST_L_FRAME,
+ IND_VAD_FLAG,
+ IND_HQ_BWIDTH,
+ IND_TC_SUBFR,
+ IND_GSC_IVAS_SP = IND_TC_SUBFR + 4,
+ IND_LSF_PREDICTOR_SELECT_BIT,
+ IND_LSF,
+ IND_MID_FRAME_LSF_INDEX = IND_LSF + 17,
+
+ IND_ISF_0_0,
+ IND_ISF_0_1,
+ IND_ISF_0_2,
+ IND_ISF_0_3,
+ IND_ISF_0_4,
+ IND_ISF_1_0,
+ IND_ISF_1_1,
+ IND_ISF_1_2,
+ IND_ISF_1_3,
+ IND_ISF_1_4,
+ IND_IC_LSF_PRED,
+ IND_GSC_ATTACK,
+ IND_GSC_SWB_SPEECH,
+ IND_NOISE_LEVEL,
+ IND_HF_NOISE,
+ IND_PIT_CONTR_IDX,
+ IND_FEC_CLAS,
+ IND_FEC_ENR,
+ IND_FEC_POS,
+ IND_ES_PRED,
+ IND_HARM_FLAG_ACELP,
+
+ /* ------------- Loop for alg. codebook indices at 24.4 kbps (special case) -------------- */
+ TAG_ALG_CDBK_4T64_24KBIT_START,
+ IND_ALG_CDBK_4T64_1_24KBIT = TAG_ALG_CDBK_4T64_24KBIT_START,
+ IND_ALG_CDBK_4T64_2_24KBIT = TAG_ALG_CDBK_4T64_24KBIT_START,
+ TAG_ALG_CDBK_4T64_24KBIT_END = TAG_ALG_CDBK_4T64_24KBIT_START + 40,
+ /* ------------------------------------------------ */
+
+ /* ------------- ACELP subframe loop -------------- */
+ TAG_ACELP_SUBFR_LOOP_START,
+ IND_PITCH = TAG_ACELP_SUBFR_LOOP_START,
+ IND_LP_FILT_SELECT = TAG_ACELP_SUBFR_LOOP_START,
+ IND_ALG_CDBK_1T64 = TAG_ACELP_SUBFR_LOOP_START,
+ IND_ALG_CDBK_2T32 = TAG_ACELP_SUBFR_LOOP_START,
+ IND_ALG_CDBK_4T64 = TAG_ACELP_SUBFR_LOOP_START,
+ IND_ALG_CDBK_4T64_1 = TAG_ACELP_SUBFR_LOOP_START,
+ IND_ALG_CDBK_4T64_2 = TAG_ACELP_SUBFR_LOOP_START,
+ IND_ALG_CDBK_4T64_1BIT = TAG_ACELP_SUBFR_LOOP_START,
+ IND_GAUS_CDBK_INDEX = TAG_ACELP_SUBFR_LOOP_START,
+ IND_TILT_FACTOR = TAG_ACELP_SUBFR_LOOP_START,
+ IND_GAIN = TAG_ACELP_SUBFR_LOOP_START,
+ IND_GAIN_CODE = TAG_ACELP_SUBFR_LOOP_START,
+ IND_TC_IMP_SHAPE = TAG_ACELP_SUBFR_LOOP_START,
+ IND_TC_IMP_POS = TAG_ACELP_SUBFR_LOOP_START,
+ IND_TC_IMP_SIGN = TAG_ACELP_SUBFR_LOOP_START,
+ IND_TC_IMP_GAIN = TAG_ACELP_SUBFR_LOOP_START,
+ IND_GAIN_PIT = TAG_ACELP_SUBFR_LOOP_START,
+ IND_PIT_IDX = TAG_ACELP_SUBFR_LOOP_START,
+ IND_AVQ_GAIN = TAG_ACELP_SUBFR_LOOP_START,
+ IND_I = TAG_ACELP_SUBFR_LOOP_START,
+ IND_KV = TAG_ACELP_SUBFR_LOOP_START,
+ IND_NQ = TAG_ACELP_SUBFR_LOOP_START,
+ IND_HF_GAIN_MODIFICATION = TAG_ACELP_SUBFR_LOOP_START,
+ TAG_ACELP_SUBFR_LOOP_END = TAG_ACELP_SUBFR_LOOP_START + 300,
+ /* ------------------------------------------------ */
+
+ IND_MEAN_GAIN2,
+ IND_Y_GAIN_TMP = IND_MEAN_GAIN2 + 32,
+ IND_Y_GAIN_HF = IND_Y_GAIN_TMP + 32,
+ IND_HQ_VOICING_FLAG,
+ IND_HQ_SWB_CLAS,
+ IND_NF_IDX,
+ IND_LC_MODE,
+ IND_YNRM,
+ IND_HQ_SWB_EXC_SP_CLAS = IND_YNRM + 44,
+ IND_HQ_SWB_EXC_CLAS = IND_HQ_SWB_EXC_SP_CLAS,
+ IND_SWB_FENV_HQ = IND_HQ_SWB_EXC_CLAS,
+ IND_FB_FENV_HQ = IND_SWB_FENV_HQ + 5,
+ IND_DELTA_ENV_HQ = IND_FB_FENV_HQ + 5,
+ IND_HVQ_BWE_NL,
+ IND_NUM_PEAKS = IND_HVQ_BWE_NL + 2,
+ IND_POS_IDX,
+ IND_FLAGN = IND_POS_IDX + 280,
+ IND_PG_IDX,
+ IND_HVQ_PEAKS = IND_PG_IDX + 35,
+ IND_HVQ_NF_GAIN = IND_HVQ_PEAKS + 70,
+ IND_HQ2_SWB_CLAS = IND_HVQ_NF_GAIN + 2,
+ IND_HQ2_DENG_MODE,
+ IND_HQ2_DENG_8SMODE,
+ IND_HQ2_DENG_8SMODE_N0,
+ IND_HQ2_DENG_8SMODE_N1,
+ IND_HQ2_DENG_8SPOS,
+ IND_HQ2_DENG_8SDEPTH,
+ IND_HQ2_DENG_HMODE,
+ IND_HQ2_DIFF_ENERGY,
+ IND_HQ2_P2A_FLAGS = IND_HQ2_DIFF_ENERGY + 100,
+ IND_HQ2_LAST_BA_MAX_BAND = IND_HQ2_P2A_FLAGS + 60,
+ IND_RC_START = IND_HQ2_LAST_BA_MAX_BAND + 2,
+ IND_RC_END = IND_RC_START + MAX_PVQ_PUSH_IND,
+ IND_HVQ_PVQ_GAIN = IND_RC_END + 1,
+ IND_NOISINESS = IND_HVQ_PVQ_GAIN + 8,
+ IND_ENERGY,
+ IND_CNG_HO,
+ IND_SID_BW,
+ IND_CNG_ENV1,
+ IND_WB_FENV,
+ IND_WB_CLASS,
+ IND_IG1,
+ IND_IG2A,
+ IND_IG2B,
+ IND_NELP_FID,
+ IND_DELTALAG,
+ IND_POWER,
+ IND_AMP0,
+ IND_AMP1,
+ IND_GLOBAL_ALIGNMENT,
+ IND_PVQ_FINE_GAIN,
+ IND_UV_FLAG,
+ IND_SHB_SUBGAIN = IND_PVQ_FINE_GAIN + 44,
+ IND_SHB_FRAMEGAIN,
+ IND_STEREO_ICBWE_MSFLAG,
+ IND_SHB_ENER_SF,
+ IND_SHB_RES_GS,
+ IND_SHB_VF = IND_SHB_RES_GS + 5,
+ IND_SHB_LSF,
+ IND_SHB_MIRROR = IND_SHB_LSF + 5,
+ IND_SHB_GRID,
+ IND_SWB_CLASS,
+ IND_SWB_TENV,
+ IND_SWB_FENV = IND_SWB_TENV + 4,
+ IND_SHB_CNG_GAIN = IND_SWB_FENV + 4,
+ IND_DITHERING,
+ IND_FB_SLOPE,
+
+ IND_HQ2_SPT_SHORTEN,
+ IND_HQ2_SUBBAND_TCQ,
+ IND_HQ2_SUBBAND_GAIN = IND_HQ2_SUBBAND_TCQ + 100,
+ IND_HQ2_DUMMY = IND_HQ2_SUBBAND_GAIN + 20,
+
+ IND_LAGINDICES,
+ IND_NOISEG,
+ IND_AUDIO_GAIN,
+ IND_AUDIO_DELAY,
+
+ /* ------------- HR SWB BWE loop -------------- */
+ TAG_HR_BWE_LOOP_START = IND_AUDIO_DELAY + 4,
+ IND_HR_IS_TRANSIENT = TAG_HR_BWE_LOOP_START,
+ IND_HR_GAIN = TAG_HR_BWE_LOOP_START,
+ IND_HR_ENVELOPE = TAG_HR_BWE_LOOP_START,
+ IND_HR_HF_GAIN = TAG_HR_BWE_LOOP_START,
+ IND_I2 = TAG_HR_BWE_LOOP_START,
+ IND_KV2 = TAG_HR_BWE_LOOP_START,
+ IND_NQ2 = TAG_HR_BWE_LOOP_START,
+ TAG_HR_BWE_LOOP_END = TAG_HR_BWE_LOOP_START + 200,
+ /* ------------------------------------------------ */
+
+ IND_CORE_SWITCHING_CELP_SUBFRAME,
+ IND_CORE_SWITCHING_AUDIO_DELAY = IND_CORE_SWITCHING_CELP_SUBFRAME + 20,
+ IND_CORE_SWITCHING_AUDIO_GAIN,
+
+ IND_STEREO_ICBWE_REF,
+ IND_STEREO_ICBWE_SP,
+ IND_STEREO_ICBWE_GS,
+ IND_STEREO_REFCHAN,
+ IND_STEREO_CORRSTATS,
+ IND_STEREO_GD,
+ IND_STEREO_LRTD_FLAG,
+ IND_STEREO_LPC_REUSE,
+ IND_STEREO_TD_ALPHA,
+ IND_STEREO_2ND_CODER_T,
+
+ IND_UNUSED,
+};
+
+/*----------------------------------------------------------------------------------*
+ * Delays
+ *----------------------------------------------------------------------------------*/
+
+#define FRAMES_PER_SEC 50
+
+#define FRAME_SIZE_NS 20000000L
+
+#define ACELP_LOOK_NS 8750000L
+#define DELAY_FIR_RESAMPL_NS 937500L
+#define DELAY_CLDFB_NS 1250000L
+
+#define DELAY_SWB_TBE_12k8_NS 1250000L
+#define DELAY_SWB_TBE_16k_NS 1125000L
+#define MAX_DELAY_TBE_NS 1312500L
+#define DELAY_BWE_TOTAL_NS 2312500L
+#define DELAY_FD_BWE_ENC_12k8_NS ( DELAY_BWE_TOTAL_NS - ( MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ) )
+#define DELAY_FD_BWE_ENC_16k_NS ( DELAY_BWE_TOTAL_NS - ( MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ) )
+#define DELAY_FD_BWE_ENC_NS 2250000L
+
+#define L_LOOK_12k8 NS2SA( INT_FS_12k8, ACELP_LOOK_NS ) /* look-ahead length at 12.8kHz */
+#define L_LOOK_16k NS2SA( INT_FS_16k, ACELP_LOOK_NS ) /* look-ahead length at 16kHz */
+
+/* core switching constants @16kHz */
+#define SWITCH_GAP_LENGTH_NS 6250000L /* length of ACELP->HQ switching gap in ms */
+#define HQ_DELAY_COMP NS2SA( 8000, DELAY_CLDFB_NS )
+#define HQ_DELTA_MAX 6 /* maximum multiplication factor (==48kHz/8kHz) for core switching modules */
+
+#define N_ZERO_MDCT_NS 5625000L /* number of zeros in ms for MDCT */
+#define NL_BUFF_OFFSET 12
+
+#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 */
+
+/*----------------------------------------------------------------------------------*
+ * Coder types (only for ACELP core when not running in AMR-WB IO mode)
+ *----------------------------------------------------------------------------------*/
+
+#define INACTIVE 0 /* inactive */
+#define UNVOICED 1 /* unvoiced */
+#define VOICED 2 /* purely voiced */
+#define GENERIC 3 /* generic */
+#define TRANSITION 4 /* transition */
+#define AUDIO 5 /* audio (GSC) */
+#define LR_MDCT 6 /* low-rate MDCT core */
+
+
+/*--------------------------------------------------*
+ * Partial copy frame types (only for ACELP core )
+ *--------------------------------------------------*/
+
+#define ACELP_MODE_MAX 4
+#define RF_MODE_MAX 4
+
+/* TCX partial copy frame types */
+#define RF_NO_DATA 0
+#define RF_TCXFD 1
+#define RF_TCXTD1 2
+#define RF_TCXTD2 3
+
+/* ACELP partial copy frame types */
+#define RF_ALLPRED ACELP_MODE_MAX
+#define RF_NOPRED ACELP_MODE_MAX + 1
+#define RF_GENPRED ACELP_MODE_MAX + 2
+#define RF_NELP ACELP_MODE_MAX + 3
+
+
+/*--------------------------------------------------------------*
+ * Frame length constants in mode 2
+ *---------------------------------------------------------------*/
+
+#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) */
+#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 */
+#define BITS_TFA 1 /* number of bits for TTF */
+#define N_TEC_TFA_SUBFR 16 /* number of subframes of TEC/TFA */
+#define L_TEC_TFA_SUBFR16k ( L_FRAME16k / N_TEC_TFA_SUBFR ) /* TEC/TFA subframe size @ 16kHz*/
+#define MAX_TEC_SMOOTHING_DEG 6 /* max degree of smoothing for TEC */
+#define N_MAX 1200 /* Max size of MDCT spectrum = 25ms @ 48kHz */
+#define N_MAX_TCX 1000 /* Max size of TCX/IGF coded lines */
+#define IGF_START_MN 144 /* MDCT lines not used by IGF*/
+#define IGF_START_MX 800 /* max. MDCT lines used by IGF*/
+#define MAX_IGF_SFB_LEN 160 /* max width of an IGF SFB */
+#define NUM_DCT_LENGTH 24
+
+#define NB_DIV 2 /* number of division (subframes) per 20ms frame */
+#define L_MDCT_HALF_OVLP_MAX L_MDCT_OVLP_MAX - 48000 / 200 /* Size of HALF overlap window slope @ 48 kHz */
+#define L_MDCT_MIN_OVLP_MAX 60 /* Size of the MDCT minimal overlap @ 48 kHz - 1.25ms */
+#define L_MDCT_TRANS_OVLP_MAX NS2SA( 48000, ACELP_TCX_TRANS_NS ) /* Size of the ACELP->MDCT transition overlap - 1.25ms */
+
+#define L_NEXT_MAX_16k NS2SA( 16000, ACELP_LOOK_NS ) /* 140 */ /* maximum encoder lookahead at 16kHz */
+#define L_NEXT_MAX_32k NS2SA( 32000, ACELP_LOOK_NS ) /* 280 */ /* maximum encoder lookahead at 32kHz */
+#define L_PAST_MAX_32k 360 /* maximum encoder past samples at 32kHz */
+
+#define L_MDCT_OVLP_MAX_CORE_FS L_NEXT_MAX_32k /* 280, 2/3 * L_MDCT_OVLP_MAX */
+#define L_MDCT_HALF_OVLP_MAX_CORE_FS 2 * ( L_MDCT_HALF_OVLP_MAX ) / 3 /* 2/3 * L_MDCT_HALF_OVLP_MAX */
+#define L_MDCT_MIN_OVLP_MAX_CORE_FS 2 * ( L_MDCT_MIN_OVLP_MAX ) / 3 /* 2/3 * L_MDCT_MIN_OVLP_MAX */
+#define L_ALDO_WIN1_MAX_CORE_FS 460 /* ALDO1 maximum window length for max core Fs */
+#define L_ALDO_WIN1_FB_MAX 690 /* ALDO1 maximum window length */
+
+/*----------------------------------------------------------------------------------*
+ * ACELP core constants
+ *----------------------------------------------------------------------------------*/
+
+#define SAFETY_NET 0
+#define MOVING_AVERAGE 1
+#define AUTO_REGRESSIVE 2
+
+#define INT_FS_12k8 12800 /* 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_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 */
+#define L_INP ( L_INP_MEM + L_FRAME32k ) /* length of input signal buffer @32kHz */
+
+#define L_EXC_MEM L_FRAME16k /* length of memory of excitation signal @16kHz */
+#define L_EXC_MEM_12k8 ( PIT_MAX + L_INTERPOL ) /* length of memory of excitation signal @12.8kHz */
+#define L_EXC_MEM_DEC ( 3 * L_FRAME16k / 2 ) /*Half-frame needed for PLC in case of TCX->ACELP*/
+#define L_EXC ( L_EXC_MEM + L_FRAME16k + 1 ) /* length of encoder excitation signal buffer @16kHz*/
+#define L_EXC_DEC ( L_EXC_MEM_DEC + L_FRAME16k + 1 + L_SUBFR ) /* length of decoder excitation signal buffer @16kHz*/
+#define L_SYN_MEM NS2SA( 48000, DELAY_CLDFB_NS ) /* synthesis memory length, 1.25ms @ 48kHz */
+#define L_SYN ( L_SYN_MEM + L_FRAME16k ) /* length of synthesis signal buffer @16kHz */
+#define L_WSP_MEM ( PIT_MAX + L_INTERPOL ) /* length of memory for weighted input signal @12.8kHz*/
+#define L_WSP ( L_WSP_MEM + L_FRAME + L_LOOK_12k8 ) /* length of weighted input signal buffer @12.8kHz*/
+
+#define OLD_SYNTH_SIZE_DEC ( 2 * L_FRAME_MAX ) /* decoder past synthesis; needed for LTP, PLC and rate switching*/
+#define OLD_SYNTH_INTERNAL_DEC ( 2 * L_FRAME32k ) /* decoder past synthesis @ internal sampling rate; needed for LTP, PLC and rate switching*/
+#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 0.3f /* ACELP code preemphasis factor */
+
+#define L_SUBFR16k ( L_FRAME16k / NB_SUBFR ) /* subframe size at 16kHz */
+#define L_HALFR16k ( 2 * L_SUBFR16k ) /* half-frame size at 16kHz */
+
+#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 M16k 20 /* order of the LP filter @ 16kHz */
+#define PIT_SHARP 0.85f /* pitch sharpening factor */
+#define PIT_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 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 LP_NOISE_THRESH 20.f
+
+#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
+#define L_FILT 12 /* Resampling - delay of the resampling low-pass filter @12.8kHz */
+#define L_FILT16k 15 /* Resampling - delay of filter for 16 kHz input signals (at 16kHz sampling rate) */
+#define L_FILT32k 30 /* Resampling - delay of filter for 32 kHz input signals (at 32kHz sampling rate) */
+#define L_FILT48k 45 /* Resampling - delay of filter for 48 kHz input signals (at 48kHz sampling rate) */
+#define L_FILT_UP16k 12 /* Resampling - delay of filter for 16 kHz output signals (at 12.8 kHz sampling rate) */
+#define L_FILT_UP32k 12 /* Resampling - delay of filter for 32 kHz output signals (at 12.8 kHz sampling rate) */
+#define L_FILT_UP48k 12 /* Resampling - delay of filter for 48 kHz output signals (at 12.8 kHz sampling rate) */
+#define L_FILT_MAX L_FILT48k /* Resampling - maximum length of all filters - for memories */
+#define RS_INV_FAC 0x8000 /* Resampling - flag needed in rom_com and modif_fs to allow pre-scaled and non pre-scaled filters */
+
+#define L_HP20_MEM 4 /* HP20 filter memory length */
+
+#define CLDFB_NO_CHANNELS_MAX 60 /* CLDFB resampling - max number of CLDFB channels, == IVAS_CLDFB_NO_CHANNELS_MAX */
+#define CLDFB_NO_COL_MAX 16 /* CLDFB resampling - max number of CLDFB col., == IVAS_CLDFB_NO_COL_MAX */
+#define CLDFB_NO_COL_MAX_SWITCH 6 /* CLDFB resampling - max number of CLDFB col. for switching */
+#define CLDFB_NO_COL_MAX_SWITCH_BFI 10 /* CLDFB resampling - max number of CLDFB col. for switching, BFI */
+#define CLDFB_OVRLP_MIN_SLOTS 3 /* CLDFB resampling - minimize processing to minimum required for transition frame ACELP->TCX/HQ */
+#define INV_CLDFB_BANDWIDTH ( 1.f / 800.f )
+
+#define L_FILT_2OVER3 12
+#define L_FILT_2OVER3_LP 3
+
+typedef enum
+{
+ CLDFB_ANALYSIS,
+ CLDFB_SYNTHESIS
+} CLDFB_TYPE;
+
+typedef enum
+{
+ CLDFB_PROTOTYPE_1_25MS,
+ CLDFB_PROTOTYPE_5_00MS
+} 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 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 L_FFT 256 /* Spectral analysis - length of the FFT */
+#define LOG2_L_FFT 8 /* Spectral analysis - log2 of L_FFT */
+
+#define BIN ( INT_FS_12k8 / L_FFT ) /* Spectral analysis - Width of one frequency bin in Hz */
+#define NB_BANDS 20 /* Spectral analysis - number of frequency bands */
+#define VOIC_BINS 74 /* Spectral analysis - max number of frequency bins considered as voiced (related to VOIC_BAND and L_FFT) */
+#define VOIC_BAND 17 /* Spectral analysis - number of critical bands considered as voiced (related to VOIC_BINS) */
+#define VOIC_BINS_8k 115 /* Spectral analysis - max number of frequency bins considered as voiced in NB (related to VOIC_BAND_8k and L_FFT) */
+#define VOIC_BAND_8k 17 /* Spectral analysis - number of critical bands considered as voiced in NB (related to VOIC_BINS_8k) */
+
+#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 L_LP 320 /* LP analysis - LP window size */
+#define L_LP_16k 400 /* LP analysis @16kHz - LP window size for 16kHz */
+#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 GRID100_POINTS 100 /* LP analysis - number of points to evaluate Chebyshev polynomials */
+
+#define PIT_MIN 34 /* OL pitch analysis - Minimum pitch lag */
+#define PIT_MAX 231 /* OL pitch analysis - Maximum pitch lag */
+#define PIT_MIN_EXTEND 20 /* OL pitch analysis - Minimum pitch lag of extended range */
+#define PIT_MIN_DOUBLEEXTEND 17 /* OL pitch analysis - Minimum pitch lag of double-extended range */
+#define OPL_DECIM 2 /* OL pitch analysis - decimation factor */
+#define L_INTERPOL1 4 /* OL pitch analysis - interval to compute normalized correlation */
+#define FIR_SIZE1 ( PIT_UP_SAMP * L_INTERPOL1 + 1 ) /* OL pitch analysis - total length of the 1/4 interpolation filter */
+
+#define PIT_MIN_SHORTER 29 /* OL pitch analysis - minimum for wider pitch */
+
+#define PIT_MIN_12k8 29 /* Minimum pitch lag with resolution 1/4 */
+#define PIT_FR2_12k8 121 /* Minimum pitch lag with resolution 1/2 */
+#define PIT_FR1_12k8 154 /* Minimum pitch lag with resolution 1 */
+#define PIT_MAX_12k8 231 /* Maximum pitch lag */
+#define PIT_FR1_8b_12k8 82 /* Minimum pitch lag with resolution 1 for low bitrate pitch delay codings*/
+#define PIT_MIN_16k 36
+#define PIT_FR2_16k 36
+#define PIT_FR1_16k 165
+#define PIT_FR1_8b_16k 165
+#define PIT_MIN_25k6 58
+#define PIT_FR2_25k6 58
+#define PIT_FR1_25k6 164
+#define PIT_MAX_25k6 463
+#define PIT_FR1_8b_25k6 164
+#define PIT_MIN_32k 72
+#define PIT_FR2_32k 72
+#define PIT_FR1_32k 75
+#define PIT_MAX_32k 577
+#define PIT_FR1_8b_32k 75
+#define PIT_MAX_MAX PIT_MAX_32k
+
+#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 */
+#define PIT_FR1_9b 160 /* Pitch encoding - Minimum pitch lag with resolution 1 */
+#define PIT_FR1_EXTEND_8b 64 /* Pitch encoding - Minimum pitch lag with resolution 1 of extended range */
+#define PIT_FR2_EXTEND_9b 116 /* Pitch encoding - Minimum pitch lag with resolution 1/2 of extended range */
+#define PIT_FR1_EXTEND_9b 128 /* Pitch encoding - Minimum pitch lag with resolution 1 of extended range */
+#define PIT_FR1_DOUBLEEXTEND_8b 58 /* Pitch encoding - Minimum pitch lag with resolution 1 of double-extended range */
+#define PIT_FR2_DOUBLEEXTEND_9b 112 /* Pitch encoding - Minimum pitch lag with resolution 1/2 of double-extended range */
+#define PIT_FR1_DOUBLEEXTEND_9b 124 /* Pitch encoding - Minimum pitch lag with resolution 1 of double-extended range */
+
+#define LOW_PASS 0 /* LP filtering - flag for low-pass filtering of the excitation */
+#define FULL_BAND 1 /* LP filtering - flag for no low-pass filtering of the excitation */
+#define NORMAL_OPERATION 2 /* LP filtering - flag for selecting the best of the two above */
+
+#define NB_TRACK_FCB_2T 2 /* Algebraic codebook - number of tracks in algebraic fixed codebook search with 2 tracks */
+#define NB_POS_FCB_2T 32 /* Algebraic codebook - number of positions in algebraic fixed codebook search with 2 tracks */
+#define NB_TRACK_FCB_4T 4 /* Algebraic codebook - number of tracks in algebraic fixed codebook search with 4 tracks */
+#define NB_POS_FCB_4T 16 /* Algebraic codebook - number of positions in algebraic fixed codebook search with 4 tracks */
+#define NB_POS_FCB_2T_128 64 /* Algebraic codebook - number of positions in algebraic fixed codebook search with 2 tracks and L_subfr = 128 */
+#define NB_POS_FCB_4T_128 32 /* Algebraic codebook - number of positions in algebraic fixed codebook search with 4 tracks and L_subfr = 128 */
+#define NB_PULSE_MAX 36
+#define MAX_IDX_LEN 9
+#define NPMAXPT ( ( NB_PULSE_MAX + NB_TRACK_FCB_4T - 1 ) / NB_TRACK_FCB_4T ) /* used in search as well */
+
+#define GAIN_PRED_ORDER 4 /* Gain quantization - prediction order for gain quantizer (only for AMR-WB IO mode) */
+#define MEAN_ENER 30 /* Gain quantization - average innovation energy */
+
+#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 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_DEC_RATE 25 /* CNG & DTX - buffer size decrease rate for active frames */
+#define STEP_SID 5.25f /* CNG & DTX - CNG energy quantization step */
+
+#define MIN_ACT_CNG_UPD 20 /* DTX - Minimum number of consecutive active frames for CNG mode update */
+#define FIXED_SID_RATE 8 /* DTX SID rate */
+
+#define TOTALNOISE_HIST_SIZE 4
+
+#define UNKNOWN_NOISE 0 /* unknown noisy type */
+#define SILENCE 1 /* speech with high SNR */
+#define CLDFBVAD_NB_ID 1
+#define CLDFBVAD_WB_ID 2
+#define CLDFBVAD_SWB_ID 3
+#define CLDFBVAD_FB_ID 4
+#define SP_CENTER_NUM 4 /* number of spectral centroid */
+#define TONA_NUM 3 /* number of tonal */
+#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 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*/
+#define MIN_AMP_ID 5
+#define MAX_AMP_ID 64
+#define SPEC_AMP_NUM ( MAX_AMP_ID - MIN_AMP_ID + 1 )
+#define STABLE_NUM 4 /* number of time-domain stable rate*/
+#define SFM_NUM 3 /* number of spectral flatness */
+
+#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 FEC_BITS_CLS 2 /* FEC - number of bits for clas information */
+#define FEC_BITS_ENR 5 /* FEC - number of bits for energy information */
+#define FEC_ENR_STEP ( 96.0f / ( 1 << FEC_BITS_ENR ) )
+#define FEC_ENR_QLIMIT ( ( 1 << FEC_BITS_ENR ) - 1 )
+#define FEC_BITS_POS 8 /* FEC - number of bits for glottal pulse position */
+#define L_SYN_MEM_CLAS_ESTIM ( 2 * PIT16k_MAX - L_FRAME16k ) /* FEC - memory of the synthesis signal for frame class estimation */
+#define L_SYN_CLAS_ESTIM ( L_SYN_MEM_CLAS_ESTIM + L_FRAME16k ) /* FEC - length of the synthesis signal buffer for frame class estimation */
+
+#define FRAME_COUNT_HF_SYNTH 100 /* Threshold of frame counter in HF synthesis */
+
+#define AUDIO_COUNTER_INI 200 /* Counter initialization */
+#define AUDIO_COUNTER_STEP 10 /* Counter increase on each audio frame */
+#define AUDIO_COUNTER_MAX 1000 /* Counter saturation */
+
+#define BWD_TOTAL_WIDTH 320 /* BWD width */
+#define BWD_COUNT_MAX 100 /* maximum value of BWD counter */
+#define BWD_N_BINS_MAX 13 /* maximum number of BWD bins */
+#define BWS_TRAN_PERIOD 5 /* BWS - number of frames for transition period */
+
+#define PREEMPH_FAC 0.68f /* preemphasis factor at 12.8kHz */
+#define PREEMPH_FAC_16k 0.72f
+#define PREEMPH_FAC_SWB 0.9f /* preemphasis factor for super wide band */
+#define GAMMA1 0.92f /* weighting factor (numerator) default:0.92 */
+#define GAMMA16k 0.94f
+
+#define FORMANT_SHARPENING_G1 0.75f /* Formant sharpening numerator weighting at 12.8kHz */
+#define FORMANT_SHARPENING_G2 0.9f /* Formant sharpening denominator weighting at 12.8kHz */
+#define FORMANT_SHARPENING_G1_16k 0.8f /* Formant sharpening numerator weighting at 16kHz */
+#define FORMANT_SHARPENING_G2_16k 0.92f /* Formant sharpening denominator weighting at 16kHz */
+
+#define FSCALE_DENOM 512
+#define ACELP_FIXED_CDK_NB 41
+#define ACELP_FIXED_CDK_BITS( n ) PulseConfTable[n].bits
+
+#define L_FIR 31
+
+enum TRACKPOS
+{
+ TRACKPOS_FIXED_FIRST = 0, /* Fill tracks from left */
+ TRACKPOS_FIXED_EVEN = 1, /* Even tracks */
+ TRACKPOS_FIXED_FIRST_TWO = 2, /* One track of 32 */
+ TRACKPOS_FIXED_TWO = 3, /* Two tracks of 32 instead of four of 16 */
+ TRACKPOS_FREE_ONE = 4, /* One freely moving track with extra pulse */
+ TRACKPOS_FREE_THREE = 6, /* Three freely moving tracks with single extra pulses */
+ TRACKPOS_GRADIENT = 7
+};
+
+enum
+{
+ LAGW_WEAK, /* weak lag window */
+ LAGW_MEDIUM, /* medium strength lag window */
+ LAGW_STRONG, /* strong lag window */
+
+ NUM_LAGW_STRENGTHS
+};
+
+#define NBITS_NOISENESS 5 /* number of bits for coding noiseness in UV frames */
+
+/*----------------------------------------------------------------------------------*
+ * ACELP@16kHz core constants
+ *----------------------------------------------------------------------------------*/
+
+#define NB_SUBFR16k 5 /* number of subframes per frame @16kHz */
+#define INT_FS_16k 16000 /* CELP core internal sampling frequency @16kHz */
+
+#define PIT16k_MIN 42 /* Minimum pitch lag @16kHz */
+#define PIT16k_MAX 289 /* Maximum pitch lag @16kHz */
+#define PIT16k_FR2_TC0_2SUBFR 83 /* Minimum pitch lag with resolution 1/2 @16kHz for TC02, 2nd subframe */
+#define PIT16k_MIN_EXTEND 21 /* Minimum pitch lag of extended range @16kHz */
+#define PIT16k_FR2_EXTEND_9b 88 /* Minimum 9 bit pitch lag with resolution 1/2 of extended range @16kHz */
+#define PIT16k_FR1_EXTEND_9b 130 /* Minimum 9 bit pitch lag with resolution 1 of extended range @16kHz */
+#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_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_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_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_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 BIT_SAVING_LOW_THR 10
+#define BIT_SAVING_HIGH_THR 80
+
+/*--------------------------------------------------------------*
+ * TCX constants
+ *---------------------------------------------------------------*/
+
+#define NBITS_TCX_GAIN 7
+
+#define NOISE_FILL_RANGES 1
+#define NBITS_NOISE_FILL_LEVEL 3 /* Number of bits used for coding noise filling level for each range */
+#define NF_GAIN_BITS ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL )
+#define MIN_NOISE_FILLING_HOLE 8
+#define HOLE_SIZE_FROM_LTP( gain ) ( 4 + ( int16_t )( 2.0f * gain * ( 4.0f / 0.625f ) ) )
+#define FDNS_NPTS 64
+#define AVG_TCX20_LSF_BITS 40
+#define AVG_TCX10_LSF_BITS 59
+#define LTPSIZE 3
+#define TCXLTP_DELAY_NS 250000
+#define TCXLTP_MAX_DELAY NS2SA( 48000, TCXLTP_DELAY_NS )
+#define TCXLTP_LTP_ORDER 24
+#define TCX_RES_Q_BITS_GAIN 3
+
+/* Use arithmetic coder with LPC shaping also at high (i.e. TCX-only) bitrates */
+#define LPC_SHAPED_ARI_MAX_RATE_CPE ACELP_13k20
+#define LPC_SHAPED_ARI_MAX_RATE ACELP_9k60
+#define N_MAX_ARI 800
+
+#define N_LTP_GAIN_MEMS 4
+
+#define N_TCX_STARTLINE_NOISE_WB 11
+#define N_TCX_STARTLINE_NOISE_SWB 9
+
+/*----------------------------------------------------------------------------------*
+ * TNS constants
+ *----------------------------------------------------------------------------------*/
+
+#define R1_48 690
+#define R2_48 420
+#define R1_16 230
+#define R2_16 140
+#define R1_25 368
+#define R2_25 224
+#define TNS_MAX_NUM_OF_FILTERS 2 /* TNS maximum number of filters */
+#define TNS_MAX_FILTER_ORDER 8 /* TNS maximum filter order */
+#define ITF_MAX_FILTER_ORDER 16 /* ITF maximum filter order */
+#define TNS_FILTER_OFF 0
+#define TNS_FILTER_ON_ZERO 1
+#define TNS_FILTER_ON 2
+#define NPRM_TNS ( 3 + TNS_MAX_NUM_OF_FILTERS * ( 3 + TNS_MAX_FILTER_ORDER ) ) /* TNS total number of quantized parameters */
+#define NPRM_RESQ 100 /* Maximum number of parameter for residual Q in TCX */
+#define NPRM_CTX_HM 3 /* Number of Parameters for Context HM : flag+index*/
+#define NPRM_DIV ( 2 + NPRM_TNS + N_MAX / 2 + NPRM_RESQ + NPRM_CTX_HM ) /* Total number of quantized parameter in 1 division */
+#define DEC_NPRM_DIV NPRM_DIV /* Total number of quantized parameter in 1 division (decoder side) */
+#define NPRM_LPC_NEW 2 * ( 4 + 2 * NB_SPHERE ) /* LPC total number of quantized parameters */
+
+#define BITBUFSIZE ( IVAS_BRATE_MAX / FRAMES_PER_SEC )
+#define IGF_BITBUFSIZE ( HQ_128k / FRAMES_PER_SEC )
+
+#define TNS_COEF_RES 4 /* Bit resolution of the coefficients. */
+#define INDEX_SHIFT ( 1 << ( TNS_COEF_RES - 1 ) ) /* For shifting the index so that index 0 points to 0. */
+
+/*----------------------------------------------------------------------------------*
+ * LSF quantization constants
+ *----------------------------------------------------------------------------------*/
+
+#define GENERIC_MA_LIMIT ACELP_9k60 /* crossover limit, for Generic WB mode, < use SN/AR, >= use MA-predictor */
+
+#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 NC M / 2
+#define LSF_GAP 50.0f
+#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 SFNETLOWLIMIT_WB 35000 /* new sampling rate dependent thresholds used in LSF codebook decision logic, WB case */
+#define SFNETLOWLIMIT_NB 38000 /* 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 LSFMBEST_MAX 16
+
+#define TCXLPC_NUMSTAGES 3
+#define TCXLPC_NUMBITS 13
+#define TCXLPC_IND_NUMSTAGES 1
+#define TCXLPC_IND_NUMBITS 2
+#define TCXLPC_LSF_GAP 80.0f
+
+#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 MIDLSF_NBITS 5
+#define ENDLSF_NBITS 31
+
+#define LEN_INDICE 15
+#define LATTICE_DIM 8
+#define NO_LEADERS 49
+#define MAX_NO_BR_LVQ 28
+#define MAX_NO_SCALES 3
+#define MAX_NO_VALS 4
+#define WB_LIMIT_LSF 6350
+#define CNG_LVQ_MODES 16
+#define MAX_NO_MODES 169
+#define START_CNG MAX_NO_MODES - CNG_LVQ_MODES
+#define MAX_NO_MODES_p 237
+#define NO_CODING_MODES 6
+#define LVQ_COD_MODES 18
+
+#define LIMIT_LEADER 19
+#define DELTA_LEADER 256
+
+/* BC-TCVQ */
+#define N_STAGE_VQ 8
+#define N_DIM 2
+#define NUM_SUBSET 8
+#define OP_LOOP_THR_HVO 3784536.3f /* 80% : Open-loop Threshold */
+#define NUM_STATE 16 /* BC-TCQ - Number of state of the Trellis */
+#define N_STAGE 16 /* BC-TCQ - Smaple number in a frame */
+
+#define SIZE_BK1 256
+#define SIZE_BK2 256
+#define SIZE_BK21 64
+#define SIZE_BK22 128
+#define SIZE_BK23 128
+#define SIZE_BK24 32
+#define SIZE_BK25 32
+#define SIZE_BK21_36b 128
+#define SIZE_BK22_36b 128
+#define SIZE_BK23_36b 64
+
+/* Gain quantizer constants */
+#define NB_QUA_GAIN5B 32 /* Number of quantization level */
+#define NB_QUA_GAIN6B 64 /* Number of quantization level */
+#define NB_QUA_GAIN7B 128 /* Number of quantization level */
+
+/*----------------------------------------------------------------------------------*
+ * TCX transient detection
+ *----------------------------------------------------------------------------------*/
+
+#define NSUBBLOCKS 8 /* Number of subblocks per frame, one transient per a sub-block can be found */
+#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 TRANSITION_OVERLAP ( -2 )
+#define RECTANGULAR_OVERLAP ( -1 )
+#define FULL_OVERLAP 0
+#define NOT_SUPPORTED 1
+#define MIN_OVERLAP 2
+#define HALF_OVERLAP 3
+#define ALDO_WINDOW 4
+
+#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
+
+/*----------------------------------------------------------------------------------*
+ * TCX transform kernel switching
+ *----------------------------------------------------------------------------------*/
+
+#define MDCT_IV 0
+#define MDST_II 1
+#define MDCT_II 2
+#define MDST_IV 3
+
+/*----------------------------------------------------------------------------------*
+ * FEC constants
+ *----------------------------------------------------------------------------------*/
+
+#define UNVOICED_CLAS 0 /* Unvoiced, silence, noise, voiced offset */
+#define UNVOICED_TRANSITION 1 /* Transition from unvoiced to voiced components - possible onset, but too small */
+#define VOICED_TRANSITION 2 /* Transition from voiced - still voiced, but with very weak voiced characteristics */
+#define VOICED_CLAS 3 /* Voiced frame, previous frame was also voiced or ONSET */
+#define ONSET 4 /* Voiced onset sufficiently well built to follow with a voiced concealments */
+#define SIN_ONSET 5 /* Artificial harmonic+noise onset (used only in decoder) */
+#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 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 */
+
+#define AGC 0.98f
+
+#define PLC_MIN_CNG_LEV 0.01f /* minimum background level */
+#define PLC_MIN_STAT_BUFF_SIZE 50 /* buffer size for minimum statistics */
+#define PLC_MIN_CNG_LEV 0.01f
+#define G_LPC_RECOVERY_BITS 1
+
+/*----------------------------------------------------------------------------------*
+ * Transition mode (TC) constants
+ *----------------------------------------------------------------------------------*/
+
+/* Conversion of tc_subfr to index */
+#define TC_SUBFR2IDX( x ) ( x == 0 ? 0 : x == 1 ? 0 : x == 2 ? 1 : x == 3 ? 2 : x == 4 ? 3 : x == 64 ? 4 : x == 128 ? 5 : x == 192 ? 6 : x == 256 ? 7 : 0 )
+
+#define TC_SUBFR2IDX_16KHZ( x ) ( x == 0 ? 0 : x == 64 ? 1 : x == 128 ? 2 : x == 192 ? 3 : x == 256 ? 4 : 0 )
+
+#define L_IMPULSE 17 /* TC - length of one prototype impulse */
+#define L_IMPULSE2 8 /* TC - half-length of one prototype impulse == floor(L_IMPULSE/2) */
+#define NUM_IMPULSE 8 /* TC - number of prototype impulses */
+#define N_GAIN_CODE_TC 8 /* TC - number of levels for gain_code quantization for subrames without glot. impulse(s) - */
+#define N_GAIN_TC 8 /* TC - number of levels for gain_trans quantization */
+
+/* TC - attention: DO NOT CHANGE the following constants - needed for correct bit-allocations */
+#define TC_0_0 1 /* TC - subframe ID for TC: first glottal impulse in the 1st subframe, second in the 1st subframe */
+#define TC_0_64 2 /* TC - subframe ID for TC: first glottal impulse in the 1st subframe, second in the 2nd subframe */
+#define TC_0_128 3 /* TC - subframe ID for TC: first glottal impulse in the 1st subframe, second in the 3rd subframe */
+#define TC_0_192 4 /* TC - subframe ID for TC: first glottal impulse in the 1st subframe, second in the 4th subframe */
+
+/*----------------------------------------------------------------------------------*
+ * AVQ constants
+ *----------------------------------------------------------------------------------*/
+
+/* RE8 constants */
+#define NB_LDQ3 9
+#define NB_SPHERE 32
+#define NB_LEADER 36
+#define NB_LDQ4 27
+#define FAC_LOG2 3.321928095f
+
+#define NSV_MAX 34 /* maximal number of sub-vectors used by the AVQ */
+
+/*----------------------------------------------------------------------------------*
+ * Arithmetic coder
+ *----------------------------------------------------------------------------------*/
+
+#define A_THRES_SHIFT 2
+#define A_THRES ( 1 << A_THRES_SHIFT )
+#define VAL_ESC 16
+#define NBITS_CONTEXT 8
+#define NBITS_RATEQ 2
+
+#define cbitsnew 16
+#define stat_bitsnew 14
+
+#define ari_q4new ( ( (int32_t) 1 << cbitsnew ) - 1 )
+#define ari_q1new ( ari_q4new / 4 + 1 )
+#define ari_q2new ( 2 * ari_q1new )
+#define ari_q3new ( 3 * ari_q1new )
+
+#define kLtpHmFractionalResolution 7
+#define kLtpHmFlag ( 1 << 8 )
+
+#define MAX_LENGTH L_FRAME_MAX
+
+/*----------------------------------------------------------------------------------*
+ * TCQ constants
+ *----------------------------------------------------------------------------------*/
+
+#define MAX_PULSES 560
+
+#define NORMAL_HQ_CORE 0 /* Signal use of Normal HQ core */
+#define LOW_RATE_HQ_CORE 1 /* Signal use of Low Rate MDCT core */
+#define LOW_RATE_HQ_CORE_TRAN 2 /* Signal use of Low Rate MDCT core Tran SWB */
+#define NORM_MDCT_FACTOR L_FRAME8k /* Normalize Low Rate MDCT coefficients to this frame size */
+#define BANDS_MAX ( 4 * 8 )
+#define MAX_GQLEVS 32 /* Max fine gain levels */
+#define BITS_DE_CMODE 1
+#define BITS_DE_HMODE 1
+#define BITS_DE_8SMODE 1
+#define MAXIMUM_ENERGY_LOWBRATE 255
+#define MINIMUM_ENERGY_LOWBRATE -256
+#define BITS_ABS_ENG 7
+#define ABS_ENG_OFFSET 64
+#define BITS_MAX_DEPTH 3
+#define BITS_DE_8SMODE_N0 1
+#define BITS_DE_8SMODE_N1 1
+#define BITS_DE_8SPOS 5
+#define BITS_DE_FCOMP 5
+#define BITS_DE_LSB 1
+#define DE_OFFSET0 46
+#define DE_OFFSET1 32
+#define DE_LIMIT 64
+#define LRMDCT_BE_OFFSET 15
+#define LRMDCT_BE_LIMIT 31
+
+#define HQCORE_NB_MIN_RATE 7200 /* NB LR MDCT coding down to this bitrate */
+#define HQCORE_WB_MIN_RATE 13200 /* WB LR MDCT coding down to this bitrate */
+#define HQCORE_SWB_MIN_RATE 13200 /* SWB LR MDCT coding down to this bitrate */
+
+#define LRMDCT_CROSSOVER_POINT 16400 /* Use LR MDCT core at this rate and below */
+
+#define HTH_NORM 17
+#define LTH_NORM 13
+#define OFFSET_NORM 3
+
+
+/*----------------------------------------------------------------------------------*
+ * SWB TBE constants
+ *----------------------------------------------------------------------------------*/
+
+#define STEPSNUM 4 /* Number of steps in a2lsp routine for SHB LPC */
+#define ALLPASSSECTIONS_STEEP 3 /* Size of all pass filters for interpolation and decimation by a factor of 2 */
+#define INTERP_3_1_MEM_LEN 13 /* Size of all pass filters for interpolation and decimation by a factor of 3:1 */
+#define INTERP_3_2_MEM_LEN 15
+#define L_SHB_LAHEAD 20 /* Size of lookahead for SHB */
+#define NUM_SHB_SUBFR 16
+#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 NUM_HILBERTS 2
+#define HILBERT_ORDER1 5
+#define HILBERT_ORDER2 4
+#define HILBERT_MEM_SIZE ( HILBERT_ORDER1 + ( 2 * HILBERT_ORDER2 ) + ( 2 * HILBERT_ORDER2 ) )
+
+#define L_SHB_TRANSITION_LENGTH ( 2 * NS2SA( 48000, DELAY_BWE_TOTAL_NS ) )
+
+#define NUM_BITS_SHB_SubGain 6
+#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 LPC_SHB_ORDER_WB 6
+#define LPC_WHTN_ORDER_WB 2 /* Order of whitening filter for WB excitation */
+#define NUM_BITS_WB_LSF 8
+#define LPC_SHB_ORDER_LBR_WB 4
+#define NUM_BITS_LBR_WB_LSF 2
+
+#define COMP_FIL_ORDER 19
+#define MAX_BIQ_N L_FRAME32k
+
+#define NUM_SHB_SUBGAINS 4 /* Number of subframe gains */
+#define NUM_BITS_SHB_SUBGAINS 5 /* Number of bits for subframe gains for SWB */
+#define NUM_BITS_SHB_FRAMEGAIN 5 /* Number of bits for framegain for SWB */
+#define NUM_BITS_SHB_FRAMEGAIN_1k75 6 /* Number of bits for framegain for SWB */
+#define NUM_BITS_SHB_ENER_SF 6
+#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 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 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 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 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 BWE constants
+ *----------------------------------------------------------------------------------*/
+
+#define INV_L_SUBFR16k 0.0125f
+#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_MAX_GAIN_VAR 0.5f
+
+
+#define NUM_BITS_FB_FRAMEGAIN 4 /* Number of bits for framegain for FB BWE */
+#define FB_BAND_BEGIN 620 /* == 15.5 kHz */
+#define FB_BAND_BEGIN_12k8 560 /* == 14 kHz */
+#define FB_BAND_END 800 /* == 20 kHz */
+#define FB_BAND_WIDTH 180 /* == 4.5 kHz */
+#define N_CAND 2
+#define N_CB11 32 /* 5bits */
+#define N_CB1ST 128 /* 7bits */
+#define N_CB2ND 64 /* 6bits */
+#define N_CB3RD 32 /* 5bits */
+#define N_CB4TH 64 /* 6bits */
+#define DIM1ST 3
+#define DIM2ND 4
+#define DIM3RD 3
+#define DIM4TH 4
+#define DIM11 ( DIM1ST + DIM2ND )
+#define DIM12 ( DIM3RD + DIM4TH )
+#define N_CAND_TR 3
+#define N_CB_TR1 128
+#define N_CB_TR2 64
+#define DIM_TR1 2
+#define DIM_TR2 2
+#define SWB_FENV_TRANS 4
+#define SWB_TENV 4
+#define NUM_SHARP 9
+#define SHARP_WIDTH 32
+
+#define HARMONIC 3
+#define NORMAL 2
+#define TRANSIENT 1
+#define NOISE 0
+
+/*----------------------------------------------------------------------------------*
+ * HR SWB BWE constants
+ *----------------------------------------------------------------------------------*/
+
+#define NSV_OVERLAP 2 /* number of sub-bands overlaping with lower-band (0-8kHz) */ /* note that NSV_MAX >= END_FREQ_BWE_FULL/(8*50) + NSV_OVERLAP ! */
+#define N_BANDS_BWE_HR 4 /* number of frequency bands in non-transient frame */
+#define N_BANDS_TRANS_BWE_HR 2 /* number of frequency bands in transient frame */
+#define END_FREQ_BWE 14400 /* maximum frequency coded by AVQ */
+#define END_FREQ_BWE_FULL 16000 /* maximum frequency coded by HR SWB BWE */
+#define END_FREQ_BWE_FULL_FB 20000 /* maximum frequency coded by HR FB BWE */
+
+#define NBITS_GLOB_GAIN_BWE_HR 5 /* number of bits of the global gain quantizer */
+#define MIN_GLOB_GAIN_BWE_HR 3 /* minimum value of the global gain quantizer */
+#define MAX_GLOB_GAIN_BWE_HR 500 /* maximum value of the global gain quantizer */
+
+#define NBITS_ENVELOPE_BWE_HR1 6 /* number of bits for envelope VQ - first two subbands in non-transient frame */
+#define NBITS_ENVELOPE_BWE_HR2 5 /* number of bits for envelope VQ - second two subbands in non-transient frame */
+#define NBITS_ENVELOPE_BWE_HR_TR 4 /* number of bits for envelope VQ - two subbands in transient frame */
+#define NUM_ENVLOPE_CODE_HR1 64 /* dimension of envelope VQ - first two subbands in non-transient frame */
+#define NUM_ENVLOPE_CODE_HR2 32 /* dimension of envelope VQ - second two subbands in non-transient frame */
+#define NUM_ENVLOPE_CODE_HR_TR 16 /* dimension of envelope VQ - two subbands in transient frame */
+#define NUM_ENVLOPE_CODE_HR_TR2 8 /* dimension of envelope VQ - two subbands in transient frame */
+
+#define NUM_NONTRANS_START_FREQ_COEF ( L_FRAME32k / 2 - NSV_OVERLAP * WIDTH_BAND ) /* start frequency coefficient (==7.6kHz) in non-transient frame */
+#define NUM_NONTRANS_END_FREQ_COEF ( L_FRAME32k * END_FREQ_BWE / END_FREQ_BWE_FULL ) /* end frequency coefficient (==14.4kHz) in non-transient frame */
+#define NUM_TRANS_START_FREQ_COEF ( NUM_NONTRANS_START_FREQ_COEF / NUM_TIME_SWITCHING_BLOCKS ) /* start frequency coefficient (==7.6kHz) in transient frame */
+#define NUM_TRANS_END_FREQ_COEF ( NUM_NONTRANS_END_FREQ_COEF / NUM_TIME_SWITCHING_BLOCKS ) /* end frequency coefficient (==14.4kHz) in transient frame */
+#define NUM_TRANS_END_FREQ_COEF_EFF 140
+#define WIDTH_NONTRANS_FREQ_COEF ( ( NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF ) / N_BANDS_BWE_HR ) /* number of coefficients per band in non-transient frame */
+#define WIDTH_TRANS_FREQ_COEF ( ( NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF ) / N_BANDS_TRANS_BWE_HR ) /* number of coefficients per band in transient frame */
+
+#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 */
+
+/*----------------------------------------------------------------------------------*
+ * FD CNG
+ *----------------------------------------------------------------------------------*/
+
+#define SIZE_SCALE_TABLE_MONO 20
+#define SIZE_SCALE_TABLE_STEREO 27
+#define SIZE_SCALE_TABLE_CN 18
+#define SIZE_SCALE_TABLE_CN_AMRWB 3
+#define SIZE_SCALE_TABLE_TCX 13
+
+#define SIZE_SIDPARTS_ENC_NOISE_EST 24
+
+#define FD_CNG_maxN_37bits 24
+#define FD_CNG_maxC_37bits 8
+#define FD_CNG_stages_37bits 6
+#define FD_CNG_JOINT_stages_25bits 4
+
+#define OUTMAX_INV 0.000030517578125f /* 1/2^15 */
+#define OUTMAX_SQ 1073741824.f /* 2^30 */
+#define OUTMAX_SQ_INV 0.00000000093132257461547852f /* 1/2^30 */
+#define DELTA ( 1e-20f )
+
+#define CLDFB_SCALING ( 1.5f )
+
+#define FFTLEN 640
+#define FFTLEN2 ( FFTLEN / 2 )
+#define CORECLDFBLEN 20
+#define TOTCLDFBLEN 40
+#define FFTCLDFBLEN ( FFTLEN2 + TOTCLDFBLEN - CORECLDFBLEN )
+#define PERIODOGLEN ( FFTLEN2 - 2 )
+#define NPART 24
+#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_DCT_NPOST 8
+
+typedef enum _DCTTYPE
+{
+ DCT_T2_24_XX = 0, /* truncated DCT_T2_24 */
+ IDCT_T2_XX_24 = 1,
+ DCT_T2_21_XX = 2, /* truncated DCT_T2_21 */
+ IDCT_T2_XX_21 = 3
+} DCTTYPE;
+
+
+#define MSSUBFRLEN 12
+#define MSNUMSUBFR 6
+#define MSBUFLEN 5
+#define MSALPHACORALPHA 0.7f
+#define MSALPHACORMAX 0.3f
+#define MSALPHAMAX 0.96f
+#define MSALPHAHATMIN 0.05f /* It is used for all bands except the first one to get a stable bass */
+#define MSQEQINVMAX ( 1.f / 5.f )
+#define MSAV 2.12f
+#define MSBETAMAX 0.8f
+#define MSSNREXP ( -0.02f / 0.064f )
+
+#define NB_LAST_BAND_SCALE 0.8f
+#define SWB_13k2_LAST_BAND_SCALE 0.8f
+
+#define CNG_LOG_SCALING 512.f /*2^9*/
+
+#define M_MAX 32
+#define N_GAIN_MIN 4
+#define N_GAIN_MAX 17
+
+#define CHEAP_NORM_SIZE 161
+
+#define CNA_MAX_BRATE ACELP_13k20
+
+#define CNA_INIT_NBANDS 6
+
+#define GAIN_Q_OFFSET_EVS 60.f
+#define GAIN_Q_OFFSET_IVAS 45.f
+
+/*----------------------------------------------------------------------------------*
+ * Bass post-filter constants
+ *----------------------------------------------------------------------------------*/
+
+#define NBPSF_PIT_MAX ( PIT16k_MAX + 1 ) /* maximum pitch value for bass post-filter */
+#define L_TRACK_HIST 10
+
+/*----------------------------------------------------------------------------------*
+ * 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_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 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 )
+#define DECMEM_RES2 ( PIT16k_MAX + 2 + LH_UP_L )
+#define SIZ_RES2 ( DECMEM_RES2 + L_SUBFR )
+#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
+
+/*----------------------------------------------------------------------------------*
+ * Stability estimation
+ *----------------------------------------------------------------------------------*/
+
+#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
+
+/*----------------------------------------------------------------------------------*
+ * Speech/music classifier constants
+ *----------------------------------------------------------------------------------*/
+
+#define SPEECH 0 /* S/M classifier's final decision is pure speech */
+#define SPEECH_OR_MUSIC 1 /* S/M classifier's final decision is unclear, i.e. speech or music */
+#define MUSIC 2 /* S/M classifier's final decision is pure music */
+
+#define N_FEATURES 12 /* number of features */
+#define N_MIXTURES 6 /* number of mixtures */
+
+#define NB_MEL_BANDS 40 /* number of mel filter bands */
+#define NB_MEL_COEF 13 /* number of mel filter coefficients */
+#define N_SMC_FEATURES 15 /* number of features */
+#define N_SMC_MIXTURES 6 /* number of mixtures */
+#define N_PCA_COEF 12 /* number of PCA components */
+#define SMC_ST_MEAN_FACT 0.5 /* forgetting factor of short-term IIR mean filter */
+
+#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 LOWEST_FBIN 3 /* lowest frequency bin for feature vector preparation */
+#define HIGHEST_FBIN 70 /* highest frequency bin for feature vector preparation */
+#define HANG_LEN_INIT 8 /* number of frames for hang-over (causes delay of decision) */
+#define HANG_LEN 8
+#define BUF_LEN 60
+#define L_OVR 8
+
+#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_THR_MASS 0.86f /* 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 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 */
+
+/*----------------------------------------------------------------------------------*
+ * LD music post-filter constants
+ *----------------------------------------------------------------------------------*/
+
+#define TH_0_MIN2 1.875f
+#define TH_1_MIN2 1.25f
+#define TH_2_MIN2 0.9375f
+#define TH_3_MIN2 0.625f
+
+#define DCT_L_POST 640
+#define OFFSET2 192
+
+#define VOIC_BINS_HR 640
+#define BIN_16kdct ( 6400.0f / DCT_L_POST )
+#define NB_LIMIT_BAND 16
+#define MBANDS_GN_LD 20 /* number of bands for gain coding in the postfilter */
+
+/*----------------------------------------------------------------------------------*
+ * AC mode (GSC) constants
+ *----------------------------------------------------------------------------------*/
+
+#define NOISE_LEVEL_SP0 8
+#define NOISE_LEVEL_SP1a 9
+#define NOISE_LEVEL_SP1 10
+#define NOISE_LEVEL_SP2 12
+#define NOISE_LEVEL_SP3 14
+
+#define MAX_DYNAMIC 82
+#define MIN_DYNAMIC 50
+#define DYNAMIC_RANGE ( MAX_DYNAMIC - MIN_DYNAMIC )
+#define MAX_GSC_NF_BITS 3
+#define GSC_NF_STEPS ( 1 << MAX_GSC_NF_BITS )
+
+#define CRIT_NOIS_BAND 23
+
+#define SSF 32 /* Sub-subframe length for energy estimation in UC decision */
+#define NB_SSF ( L_FRAME / SSF ) /* number of sub-subframes per frame */
+
+#define MBANDS_GN16k 18 /* Number of band for gain coding in GSC */
+#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 MAX_EQ_LF 1.0f
+#define MBANDS_LOC ( MBANDS_GN - 1 )
+#define BIN_SIZE 25.0f
+#define SWNB_SUBFR 1
+
+#define MIN_RATE_4SBFR ACELP_16k40
+#define MIN_RATE_FCB ACELP_22k60
+
+#define VAR_COR_LEN 10
+
+#define CFREQ_BITRATE ACELP_11k60
+
+#define LT_UV_THR 100
+#define LT_UV_THRMID 70
+
+#define PIT_EXC_L_SUBFR L_FRAME16k
+
+#define LOCAL_CT VOICED
+
+/*----------------------------------------------------------------------------------*
+ * Core switching constants
+ *----------------------------------------------------------------------------------*/
+
+#define SWITCH_MAX_GAP 360 /* 6.25 + 1.25 of filter mem max == NS2SA(48000, SWITCH_GAP_LENGTH_NS+DELAY_CLDFB_NS) */
+
+/*----------------------------------------------------------------------------------*
+ * HQ core constants
+ *----------------------------------------------------------------------------------*/
+
+#define HQ_NORMAL 0
+#define HQ_TRANSIENT 1
+#define HQ_HARMONIC 2
+#define HQ_HVQ 3
+#define HQ_GEN_SWB 4
+#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 MAX_SEGMENT_LENGTH 480
+#define NUM_TIME_SWITCHING_BLOCKS 4
+#define NUM_MAP_BANDS 20
+#define NUM_MAP_BANDS_HQ_24k4 17
+#define NUM_MAP_BANDS_HQ_32k 18
+#define FREQ_LENGTH 800
+
+#define STOP_BAND 800
+
+#define SFM_G1 16
+#define SFM_G1G2 24
+#define SFM_N_NB 18
+#define SFM_N_WB 26
+#define SFM_N_STA_8k 27
+#define SFM_N_STA_10k 30
+#define SFM_N_ENV_STAB SFM_N_STA_8k /* Number of bands for env_stab stability measure */
+#define SFM_N_ENV_STAB_WB SFM_N_WB /* Number of bands for env_stab stability measure used in HQPLC decision for WB signals */
+#define SFM_N_HARMONIC 39
+#define SFM_N 36
+
+#define L_HQ_WB_BWE 20 /* == band_end_wb[SFM_N_WB-1] - (band_start_wb[SFM_N_WB-1]+12) */
+#define N_INTL_GRP_16 2 /* Number of interleaving band groups at 16kHz sampling rate */
+#define N_INTL_GRP_32 2 /* Number of interleaving band groups at 32kHz sampling rate */
+#define N_INTL_GRP_48 3 /* Number of interleaving band groups at 48kHz sampling rate */
+#define SFM_N_SWB 39
+#define SFM_N_HARM 31
+#define SFM_N_HARM_FB 33
+#define NB_SFM 44
+#define NB_SFM_MAX 58
+#define WID_G1 8
+#define WID_G2 16
+#define WID_G3 24
+#define WID_GX 32
+#define NUMC_N 544
+#define HQ_MAX_BAND_LEN 96 /* Largest bandwidth in HQ mode (band_len_harm[32]) */
+#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 FLAGN_BITS 1
+#define GAIN0_BITS 5
+#define GAINI_BITS 5
+
+#define FLAGS_BITS 2
+#define FLAGS_BITS_FB 3
+#define NORM0_BITS 5
+#define NORMI_BITS 5
+#define NUMNRMIBITS_SWB_STA_8k 5 * ( SFM_N_STA_8k - 1 )
+#define NUMNRMIBITS_SWB_STA_10k 5 * ( SFM_N_STA_10k - 1 )
+#define NUMNRMIBITS_SWB_HARMONIC 185
+#define NUMNRMIBITS_SWB 190
+#define NUMNRMIBITS 215
+#define NUMNRMIBITS_WB 125
+
+#define NOHUFCODE 0
+#define HUFCODE 1
+#define HUFF_THR 10
+#define NOSUPERPOSITION 40
+
+#define MAXVALUEOFFIRSTGAIN 2.5f
+#define MINVALUEOFFIRSTGAIN -2.5f
+#define NOOFGAINBITS1 6
+
+#define AUDIODELAYBITS 6
+#define DELTAOFFIRSTGAIN (float) ( MAXVALUEOFFIRSTGAIN - MINVALUEOFFIRSTGAIN ) / (float) ( ( 1 << NOOFGAINBITS1 ) - 1 )
+
+#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 )
+
+#define MAX_P_ATT 40 /* Maximum number of pulses for gain attenuation factor */
+#define NB_G 4 /* Number of band groups */
+#define MAX_GAIN_BITS 5 /* Maximum number of gain bits */
+
+#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 L_STAB_TBL 10 /* Number of elements in stability transition table */
+#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 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 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 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 */
+#define ENERGY_TH 100.0f /* Energy threshold for transient detection */
+#define ENERGY_LT_BETA 0.93f /* Smoothing factor for long-term energy measure */
+
+#define START_EXC 60
+#define L_HARMONIC_EXC 202
+
+#define HQ_GENERIC_OFFSET 2
+#define HQ_GENERIC_END_FREQ 560
+#define HQ_GENERIC_END_FREQ_14P2KHZ 568
+#define HQ_GENERIC_END_FREQ_16P0KHZ 640
+
+#define HQ_GENERIC_FOFFSET_24K4 80
+#define HQ_GENERIC_FOFFSET_32K 144
+#define HQ_GENERIC_SWB_NBITS 31
+#define HQ_GENERIC_SWB_NBITS2 30
+#define HQ_GENERIC_FB_NBITS 5
+
+#define HQ_GENERIC_ST_FREQ 224
+#define HQ_GENERIC_LOW0 80
+#define HQ_GENERIC_HIGH0 240
+#define HQ_GENERIC_HIGH1 368
+#define HQ_GENERIC_HIGH2 496
+#define HQ_GENERIC_LEN0 128
+#define HQ_GENERIC_NVQIDX 6
+
+#define HQ_GENERIC_EXC0 0
+#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
+
+#define HVQ_THRES_BIN_24k 224
+#define HVQ_THRES_SFM_24k 22
+#define HVQ_THRES_BIN_32k 320
+#define HVQ_THRES_SFM_32k 25
+#define HVQ_MIN_PEAKS 2
+#define HVQ_MAX_PEAKS_32k 23
+#define HVQ_MAX_PEAKS_24k 17
+#define HVQ_MAX_PEAKS_24k_CLAS 20 /* Limit for HVQ mode */
+#define HVQ_MAX_PEAKS ( HVQ_MAX_PEAKS_32k + 1 + 11 ) /* Allowing HVQ at max 48 kbps */
+#define HVQ_PEAKS_BPS_DELTA ( HQ_32k - HQ_24k40 )
+#define HVQ_PEAKS_PER_DELTA ( HVQ_MAX_PEAKS_32k - HVQ_MAX_PEAKS_24k )
+#define HVQ_PEAKS_PER_DELTA_THR ( HVQ_MAX_PEAKS_32k - HVQ_MAX_PEAKS_24k_CLAS )
+#define HVQ_PEAKS_PER_DELTA_OFFS ( HVQ_MAX_PEAKS_24k * HVQ_PEAKS_BPS_DELTA - HQ_24k40 * HVQ_PEAKS_PER_DELTA )
+#define HVQ_PEAKS_PER_DELTA_THR_OFFS ( HVQ_MAX_PEAKS_24k_CLAS * HVQ_PEAKS_BPS_DELTA - HQ_24k40 * HVQ_PEAKS_PER_DELTA_THR )
+#define HVQ_NUM_SFM_24k ( SFM_N_HARMONIC - 1 - HVQ_THRES_SFM_24k )
+#define HVQ_NUM_SFM_32k ( SFM_N_HARMONIC - 1 - HVQ_THRES_SFM_32k )
+#define HVQ_E_PEAK_SMOOTH_FAC ( 0.3f )
+
+#define HVQ_MAX_RATE 32000
+
+#define NUMNRMIBITS_SWB_HVQ_24k 35
+#define NUMNRMIBITS_SWB_HVQ_32k 25
+
+#define MAX_PVQ_BANDS 8
+#define HVQ_MAX_PVQ_WORDS ( ( HVQ_MAX_RATE / FRAMES_PER_SEC ) / 16 + MAX_PVQ_BANDS )
+#define HVQ_MAX_POS_WORDS 40
+#define HVQ_PVQ_COEFS 24
+#define HVQ_BAND_MIN_PULSES 2
+#define HVQ_BAND_MAX_BITS_24k 80
+#define HVQ_BAND_MAX_BITS_32k 95
+#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_PA_FAC 0.7071f /* 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_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_MOD_THRESHOLD 2.128f /* HQ harmonic high band classifier, modified crest threshold */
+#define HQ_CREST_FAC_SM 0.97f /* HQ harmonic high band classifier, smoothing factor */
+
+#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_VQ_DIM 5 /* HVQ peak VQ dimension */
+#define HVQ_PVQ_GAIN_BITS 5 /* Number of bits to encode PVQ gains in HVQ */
+#define HVQ_NUM_CLASS 4 /* Number of codebook classes */
+#define HVQ_CB_SIZE 256
+
+#define NUM_PG_HUFFLEN 9 /* Number of Huffman codewords for peak gains */
+#define MAX_PG_HUFFLEN 12 /* Length of the longest codeword for peak gain Huffman coding */
+
+#define HVQ_CP_HUFF_OFFSET 3 /* HVQ Code Pos - Delta offset */
+#define HVQ_CP_HUFF_MAX 51 /* HVQ Code Pos - Maximum delta for huffman coding */
+#define HVQ_CP_HUFF_MAX_CODE 13 /* HVQ Code Pos - Size of largest code word */
+#define HVQ_CP_HUFF_NUM_LEN 11 /* HVQ Code Pos - Number of different huffman lengths */
+#define HVQ_CP_L2_MAX 64 /* HVQ Code Pos - Layer 2 maximum size */
+#define HVQ_CP_L1_LEN 5 /* HVQ Code Pos - Layer 1 block size */
+#define HVQ_CP_MAP_LEN 8 /* HVQ Code Pos - Mapping table size */
+#define HVQ_CP_MAP_IDX_LEN 3 /* HVQ Code Pos - Mapping index size */
+#define HVQ_CP_DELTA 0 /* HVQ Code Pos - Use Delta coding */
+#define HVQ_CP_SPARSE 1 /* HVQ Code Pos - Use Sparse coding */
+
+#define MAX_SPLITS 10 /* Maximum number of PVQ band splits */
+#define QUANTAQ3OFFSET 1
+
+enum QuantaMode
+{
+ PVQ_NEAREST = 0,
+ PVQ_CONS
+};
+
+#define DS_INDEX_LINEAR_END 21
+#define PYR_OFFSET 1
+#define RCF_INIT_SHIFT 14
+#define THR_ADD_SPLIT 7 /* Threshold for using additional split */
+#define PVQ_MAX_BAND_SIZE 64 /* Maxiumum supported band size for PVQ search */
+#define MIN_BAND_SIZE 1 /* Minimum supported band size for PVQ search */
+#define RC_BITS_RESERVED 1
+#define MAX_PVQ_BITS_PER_COEFFICIENT 80 /* Maximum bits per coefficient allocated per PVQ band. Q3. */
+#define MAX_SRT_LEN NB_SFM_MAX /* Maximum length of input for srt_vec_ind() */
+
+/* index_pvq constants */
+#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 */
+
+/* TCQ */
+#define TCQ_MAX_BAND_SIZE 120 /* Maxiumum supported band size for TCQ+USQ search */
+#define STATES 8
+#define MAX_AR_FREQ 16383
+#define AR_BITS 16
+#define STATES_LSB 4
+#define TCQ_LSB_SIZE 24
+#define TCQ_AMP 10
+#define QTCQ ( 0.2f )
+
+#define AR_FIRST ( AR_TOP / 4 + 1 )
+#define AR_TOP ( ( 1 << AR_BITS ) - 1 )
+#define AR_HALF ( 2 * AR_FIRST )
+#define AR_THIRD ( 3 * AR_FIRST )
+
+#define MAX_SIZEBUF_PBITSTREAM 1024
+
+/*----------------------------------------------------------------------------------*
+ * SWB BWE for LR MDCT core
+ *----------------------------------------------------------------------------------*/
+
+#define G1_RANGE 4
+#define G1G2_RANGE 15
+#define GRP_SB 4 /*Maximum subband groups*/
+#define THR1 4 /* Bit allocation threshold value */
+#define THR2 5 /* Bit allocation threshold value */
+#define THR3 6 /* Bit allocation threshold value */
+
+#define NB_SWB_SUBBANDS 4 /* maximum number of subbands in normal2 subband coding */
+#define SWB_SB_LEN0_12KBPS 55 /* length of subband number X in lowest bitrate operation */
+#define SWB_SB_LEN1_12KBPS 68
+#define SWB_SB_LEN2_12KBPS 84
+#define SWB_SB_LEN3_12KBPS 105
+#define SWB_HIGHBAND_12KBPS ( SWB_SB_LEN0_12KBPS + SWB_SB_LEN1_12KBPS + SWB_SB_LEN2_12KBPS + SWB_SB_LEN3_12KBPS )
+#define SWB_LOWBAND_12KBPS ( HQ_GENERIC_END_FREQ_14P2KHZ - SWB_HIGHBAND_12KBPS )
+#define SWB_HIGHBAND_MAX SWB_HIGHBAND_12KBPS
+#define SWB_LOWBAND_MAX SWB_LOWBAND_12KBPS
+
+#define SWB_SB_OFF0_12KBPS 0 /* subband offsets are based on the subband lengths */
+#define SWB_SB_OFF1_12KBPS ( SWB_SB_OFF0_12KBPS + SWB_SB_LEN0_12KBPS )
+#define SWB_SB_OFF2_12KBPS ( SWB_SB_OFF1_12KBPS + SWB_SB_LEN1_12KBPS )
+#define SWB_SB_OFF3_12KBPS ( SWB_SB_OFF2_12KBPS + SWB_SB_LEN2_12KBPS )
+#define SWB_SB_OFF4_12KBPS ( SWB_SB_OFF3_12KBPS + SWB_SB_LEN3_12KBPS )
+
+/* 16.4 kbps */
+#define SWB_SB_LEN0_16KBPS 59 /* length of subband number X in lowest bitrate operation */
+#define SWB_SB_LEN1_16KBPS 74
+#define SWB_SB_LEN2_16KBPS 92
+#define SWB_SB_LEN3_16KBPS 115
+#define SWB_HIGHBAND_16KBPS ( SWB_SB_LEN0_16KBPS + SWB_SB_LEN1_16KBPS + SWB_SB_LEN2_16KBPS + SWB_SB_LEN3_16KBPS )
+#define SWB_LOWBAND_16KBPS ( HQ_GENERIC_END_FREQ_16P0KHZ - SWB_HIGHBAND_16KBPS )
+
+#define SWB_SB_OFF0_16KBPS 0 /* subband offsets are based on the subband lengths */
+#define SWB_SB_OFF1_16KBPS ( SWB_SB_OFF0_16KBPS + SWB_SB_LEN0_16KBPS )
+#define SWB_SB_OFF2_16KBPS ( SWB_SB_OFF1_16KBPS + SWB_SB_LEN1_16KBPS )
+#define SWB_SB_OFF3_16KBPS ( SWB_SB_OFF2_16KBPS + SWB_SB_LEN2_16KBPS )
+#define SWB_SB_OFF4_16KBPS ( SWB_SB_OFF3_16KBPS + SWB_SB_LEN3_16KBPS )
+
+/* SpectrumSmoothing */
+#define L_SB 12 /* subband length for SpectrumSmoothing */
+
+/* SpectrumSmoothing for NSS */
+#define L_SB_NSS 8
+#define L_SB_NSS_HALF ( L_SB_NSS / 2 )
+#define NUM_SUBBAND_SMOOTH_MAX ( SWB_HIGHBAND_12KBPS / L_SB_NSS + 1 )
+#define MA_LEN 7
+
+/* Harmonic mode */
+#define NB_SWB_SUBBANDS_HAR_SEARCH_SB 2 /* search number of subbands in harmonic subband coding */
+#define NB_SWB_SUBBANDS_HAR 4 /* maximum number of subbands in harmonic subband coding */
+#define N_NBIGGEST_PULSEARCH 18
+#define N_NBIGGEST_SEARCH_LRG_B 32
+
+
+/* 13.2 kbps */
+#define SWB_SB_BW_LEN0_12KBPS_HAR 56 /* Group 1 length for BWE */
+#define SWB_SB_BW_LEN1_12KBPS_HAR 100 /* Group 2 Length for BWE */
+#define SWB_SB_BW_LEN2_12KBPS_HAR SWB_SB_BW_LEN1_12KBPS_HAR
+#define SWB_SB_BW_LEN3_12KBPS_HAR SWB_SB_BW_LEN0_12KBPS_HAR
+
+/* 16.4 kbps */
+#define SWB_SB_BW_LEN0_16KBPS_HAR 60 /* Group 1 length for BWE */
+#define SWB_SB_BW_LEN1_16KBPS_HAR 110 /* Group 2 Length for BWE */
+#define SWB_SB_BW_LEN2_16KBPS_HAR SWB_SB_BW_LEN1_16KBPS_HAR
+#define SWB_SB_BW_LEN3_16KBPS_HAR SWB_SB_BW_LEN0_16KBPS_HAR
+
+#define SWB_SB_OFF0_SUB5_12KBPS_HAR 0 /* subband offsets are based on the subband lengths */
+#define SWB_SB_OFF1_SUB5_12KBPS_HAR ( SWB_SB_OFF0_SUB5_12KBPS_HAR + SWB_SB_BW_LEN0_12KBPS_HAR )
+#define SWB_SB_OFF2_SUB5_12KBPS_HAR ( SWB_SB_OFF1_SUB5_12KBPS_HAR + SWB_SB_BW_LEN1_12KBPS_HAR )
+#define SWB_SB_OFF3_SUB5_12KBPS_HAR ( SWB_SB_OFF2_SUB5_12KBPS_HAR + SWB_SB_BW_LEN2_12KBPS_HAR )
+
+#define SWB_SB_OFF0_SUB5_16KBPS_HAR 0 /* subband offsets are based on the subband lengths */
+#define SWB_SB_OFF1_SUB5_16KBPS_HAR ( SWB_SB_OFF0_SUB5_16KBPS_HAR + SWB_SB_BW_LEN0_16KBPS_HAR )
+#define SWB_SB_OFF2_SUB5_16KBPS_HAR ( SWB_SB_OFF1_SUB5_16KBPS_HAR + SWB_SB_BW_LEN1_16KBPS_HAR )
+#define SWB_SB_OFF3_SUB5_16KBPS_HAR ( SWB_SB_OFF2_SUB5_16KBPS_HAR + SWB_SB_BW_LEN2_16KBPS_HAR )
+
+#define LR_BLK_LEN 16
+#define LR_HLF_PK_BLK_LEN 8
+#define LR_LOWBAND_DIF_PK_LEN 10
+#define SWB_HAR_RAN1 80
+#define SWB_HAR_RAN2 140
+#define SWB_HAR_RAN3 200
+#define SPT_SHORTEN_SBNUM 4
+
+/* LRMDCT fix precision */
+#define SWB_BWE_LR_Qs 12
+#define SWB_BWE_LR_Qbe 14
+#define SWB_BWE_LR_QRk 16
+
+
+/*----------------------------------------------------------------------------------*
+ * FEC for HQ core
+ *----------------------------------------------------------------------------------*/
+
+#define MAX_PGF 7
+#define MAX_ROW 2
+
+#define MAX_SB_NB 3
+
+#define NELP_LP_ORDER 8
+#define NUM_NELP_GAINS 10
+
+#define MINIMUM_RATE_TO_ENCODE_VOICING_FLAG 45000
+#define FRAC_BWE_SMOOTH 2.0f /* >= 1 */
+#define FRAMECTTOSTART_MDCT 3
+
+/*----------------------------------------------------------------------------------*
+ * Channel aware mode (FEC)
+ *----------------------------------------------------------------------------------*/
+
+#define FEC_OFFSET 3
+#define MAX_RF_FEC_OFFSET 9
+
+
+/*----------------------------------------------------------------------------------*
+ * HQ FEC
+ *----------------------------------------------------------------------------------*/
+
+#define POST_HQ_DELAY_NS DELAY_BWE_TOTAL_NS /* delay of post processing after core HQ coding */
+#define PH_ECU_ALDO_OLP2_NS ( ACELP_LOOK_NS / 2 ) /* half length of ALDO WINDOW overlap */
+#define PH_ECU_LOOKAHEAD_NS ( 11 * ACELP_LOOK_NS / ( 7 * 2 ) ) /* Number of nanoseconds look-ahead ahead from the end of the past synthesized frame */
+#define PH_ECU_MEM_NS ( ( L_PROT48k / 48 - 20 ) * 1000000 - PH_ECU_LOOKAHEAD_NS ) /* Number of nanoseconds memory for Phase ECU before the old_synthFB_fx pointer */
+
+#define N_LEAD_NB 70 /* (N_LEAD_MDCT*(L_FRAME8k/20)) */
+#define N_ZERO_NB 45 /* (N_ZERO_MDCT*(L_FRAME8k/20)) */
+#define N_LEAD_O_NB 90 /* (20.f-N_LEAD_MDCT)*(L_FRAME8k/20) */
+#define N_ZERO_O_NB 35 /* (10.f-N_ZERO_MDCT)*(L_FRAME8k/20) */
+#define N_Z_L_NB 115 /* (N_Z_L_MDCT*(float)(L/20)) = N_ZERO_NB + N_LEAD_NB*/
+#define N_Z_L_O_NB 205 /* (N_Z_L_O_MDCT*(float)(L/20)) = N_ZERO_NB + N_LEAD_NB + N_LEAD_O_NB */
+
+#define L_PROT32k 1024 /* HQ phase ECU prototype frame length */
+#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 0.5f /* 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 )
+#define L_PROT_HAMM_LEN2_48k NS2SA( 48000, 6000000L )
+#define L_PROT_HAMM_LEN2_32k NS2SA( 32000, 6000000L )
+#define L_PROT_HAMM_LEN2_16k NS2SA( 16000, 6000000L )
+#define L_PROT48k L_PROT32k * 3 / 2 /* HQ phase ECU prototype frame length */
+#define L_PROT48k_2 L_PROT48k / 2
+#define L_TRANA48k ( L_PROT48k / QUOT_LPR_LTR ) /* transient analysis frame length */
+#define PH_ECU_SPEC_SIZE L_PROT48k
+#define T_SIN_PI_2 ( PH_ECU_SPEC_SIZE / 4 )
+#define HQ_FEC_SIGN_SFM 16
+#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 ED_THRES_12P 0.032209f
+#define ED_THRES_50P 0.159063f
+#define ED_THRES_90P 0.532669
+#define MAXDELAY_FEC 224
+
+#define RANDOM_START 1
+#define HQ_FEC_SIGN_THRES 6
+#define HQ_FEC_SIGN_THRES_TRANS 3
+#define HQ_FEC_BAND_SIZE 4
+
+
+/*--------------------------------------------------------------*
+ * Tonal MDCT PLC
+ *---------------------------------------------------------------*/
+
+#define MAX_NUMBER_OF_IDX 30
+#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 3.0f /* 4.8 dB */
+#define LEVEL_ABOVE_ENVELOPE 7.59f /* 8.8 dB */
+#define UNREACHABLE_THRESHOLD 16.0f /* 12 dB Increase of LEVEL_ABOVE_ENVELOPE so that the threshold is not reached */
+#define SMALL_THRESHOLD 1.10f /* 0.41 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a definitive peak in the estimated spectrum */
+#define BIG_THRESHOLD 1.5f /* 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 2.6f
+
+
+#define kTcxHmNumGainBits 2 /* Number of bits for the gain index */
+#define kTcxHmParabolaHalfWidth 4 /* Parabola half width */
+#define kLtpHmGainThr 0.46f /* Use the LTP pitch lag in the harmonic model? */
+
+#define LOWRATE_TCXLPC_MAX_BR_CPE ACELP_13k20
+#define LOWRATE_TCXLPC_MAX_BR ACELP_9k60
+
+/*--------------------------------------------------------------*
+ * Waveform-adjustment MDCT PLC
+ *---------------------------------------------------------------*/
+
+#define DEC_STATE_LEN 10
+#define MAX_POST_LEN 3
+#define TCX_TONALITY_INIT_CNT 7
+
+#define TCX_NONTONAL 0
+#define TCX_TONAL 1
+
+/*---------------------------------------------------------------*
+ * IGF *
+ *---------------------------------------------------------------*/
+
+#define IGF_MAX_TILES 10
+#define IGF_MAX_GRANULE_LEN 1200
+#define IGF_TRANS_FAK 2
+#define IGF_MAX_SFB 23
+#define IGF_NOF_GRIDS 3
+#define IGF_MAX_SUBFRAMES 2
+#define IGF_PAST_SFM_LEN 5
+#define IGF_MID_WHITENING_LEVEL 7
+#define IGF_MID_WHITENING_LEVEL2 9
+
+#define IGF_MODE_WB 1
+#define IGF_MODE_SWB 2
+#define IGF_MODE_FB 3
+
+enum
+{
+ IGF_BITRATE_WB_9600,
+ IGF_BITRATE_RF_WB_13200,
+ IGF_BITRATE_SWB_9600,
+ IGF_BITRATE_SWB_13200,
+ IGF_BITRATE_RF_SWB_13200,
+ IGF_BITRATE_SWB_16400,
+ IGF_BITRATE_SWB_24400,
+ IGF_BITRATE_SWB_32000,
+ IGF_BITRATE_SWB_48000,
+ IGF_BITRATE_SWB_64000,
+ IGF_BITRATE_FB_16400,
+ IGF_BITRATE_FB_24400,
+ IGF_BITRATE_FB_32000,
+ IGF_BITRATE_FB_48000,
+ IGF_BITRATE_FB_64000,
+ IGF_BITRATE_FB_96000,
+ IGF_BITRATE_FB_128000,
+ IGF_BITRATE_WB_13200_CPE,
+ IGF_BITRATE_WB_16400_CPE,
+ IGF_BITRATE_SWB_13200_CPE,
+ IGF_BITRATE_SWB_16400_CPE,
+ IGF_BITRATE_SWB_24400_CPE,
+ IGF_BITRATE_SWB_32000_CPE,
+ IGF_BITRATE_SWB_48000_CPE,
+ IGF_BITRATE_SWB_48000_CPE_TCX10,
+ IGF_BITRATE_SWB_64000_CPE,
+ IGF_BITRATE_SWB_80000_CPE,
+ IGF_BITRATE_SWB_96000_CPE,
+ IGF_BITRATE_FB_24400_CPE,
+ IGF_BITRATE_FB_32000_CPE,
+ IGF_BITRATE_FB_48000_CPE,
+ IGF_BITRATE_FB_48000_CPE_TCX10,
+ IGF_BITRATE_FB_64000_CPE,
+ IGF_BITRATE_FB_80000_CPE,
+ IGF_BITRATE_FB_96000_CPE,
+ IGF_BITRATE_FB_128000_CPE,
+ IGF_BITRATE_UNKNOWN
+};
+
+#define IGF_WHITENING_OFF 0
+#define IGF_WHITENING_MID 1
+#define IGF_WHITENING_STRONG 2
+
+#define IGF_GRID_LB_NORM 0
+#define IGF_GRID_LB_TRAN 1
+#define IGF_GRID_LB_SHORT 2
+
+/* constants for IGFSCFDecoder and IGFSCFEncoder */
+#define IGF_CTX_OFFSET 3 /* offset added to make the context values non negative, for array indexing */
+#define IGF_CTX_COUNT ( 2 * IGF_CTX_OFFSET + 1 ) /* number of contexts for the AC statistical model */
+#define IGF_MIN_ENC_SEPARATE -12 /* minimum residual value coded separately, without escape coding */
+#define IGF_MAX_ENC_SEPARATE +12 /* maximum residual value coded separately, without escape coding */
+#define IGF_SYMBOLS_IN_TABLE ( 1 + ( IGF_MAX_ENC_SEPARATE - IGF_MIN_ENC_SEPARATE + 1 ) + 1 ) /* alphabet size */
+
+/*----------------------------------------------------------------------------------*
+ * SC-VBR
+ *----------------------------------------------------------------------------------*/
+
+#define UVG1_CBSIZE 32 /* NELP unvoiced gain-1 codebook size */
+#define UVG2_CBSIZE 64 /* NELP unvoiced gain-2 codebook size */
+
+/* PPP constants */
+#define NUM_ERB_WB 24 /* Number of ERB bands in wideband */
+#define NUM_ERB_NB 22 /* Number of ERB bands in narrowband */
+
+#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 180 /* max lag allowed for PPP coding */
+
+#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 */
+
+/*----------------------------------------------------------------------------------*
+ * 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 */
+
+/*----------------------------------------------------------------------------------*
+ * TEC/TFA
+ *----------------------------------------------------------------------------------*/
+
+#define DELAY_TEMP_ENV_BUFF_TEC 9
+#define EXT_DELAY_HI_TEMP_ENV 2
+
+
+/*----------------------------------------------------------------------------------*
+ * BASOP ROM Tables
+ *----------------------------------------------------------------------------------*/
+
+#define LD_INT_TAB_LEN 120
+#define INV_TABLE_SIZE 256
+#define SQRT_TABLE_SIZE 256
+
+
+/*----------------------------------------------------------------------------------*
+ * Decoder modes
+ *----------------------------------------------------------------------------------*/
+
+enum
+{
+ PRIMARY_2800,
+ PRIMARY_7200,
+ PRIMARY_8000,
+ PRIMARY_9600,
+ PRIMARY_13200,
+ PRIMARY_16400,
+ PRIMARY_24400,
+ PRIMARY_32000,
+ PRIMARY_48000,
+ PRIMARY_64000,
+ PRIMARY_96000,
+ PRIMARY_128000,
+ PRIMARY_SID,
+ PRIMARY_FUT1,
+ SPEECH_LOST,
+ NO_DATA_RECEIVED
+};
+
+enum
+{
+ AMRWB_IO_6600,
+ AMRWB_IO_8850,
+ AMRWB_IO_1265,
+ AMRWB_IO_1425,
+ AMRWB_IO_1585,
+ AMRWB_IO_1825,
+ AMRWB_IO_1985,
+ AMRWB_IO_2305,
+ AMRWB_IO_2385,
+ AMRWB_IO_SID /*,
+ AMRWB_IO_FUT1,
+ AMRWB_IO_FUT2,
+ AMRWB_IO_FUT3,
+ AMRWB_IO_FUT4,
+ SPEECH_LOST,
+ NO_DATA_RECEIVED */
+};
+
+enum
+{
+ G192,
+ MIME,
+ VOIP_G192_RTP,
+ VOIP_RTPDUMP
+};
+
+
+/* clang-format on */
+#endif /* CNST_H */
diff --git a/lib_com/codec_tcx_common.c b/lib_com/codec_tcx_common.c
new file mode 100644
index 0000000000000000000000000000000000000000..2375ef387e807bc38396b7be5eba3dbd0cba6ebe
--- /dev/null
+++ b/lib_com/codec_tcx_common.c
@@ -0,0 +1,332 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * tcxGetNoiseFillingTilt()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t tcxGetNoiseFillingTilt(
+ const float A[],
+ const int16_t L_frame,
+ const int16_t mode,
+ float *noiseTiltFactor )
+{
+ int16_t firstLine;
+
+ if ( mode )
+ {
+ firstLine = L_frame / 6;
+ *noiseTiltFactor = 0.5625f;
+ }
+ else
+ {
+ firstLine = L_frame / 8;
+ *noiseTiltFactor = get_gain( A + 1, A, M, NULL );
+ *noiseTiltFactor = min( 1.0f, ( *noiseTiltFactor ) + 0.09375f );
+ }
+
+ return firstLine;
+}
+
+/*-------------------------------------------------------------------*
+ * tcxFormantEnhancement()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tcxFormantEnhancement(
+ float xn_buf[],
+ const float *gainlpc,
+ float spectrum[],
+ const int16_t L_frame )
+{
+ int16_t k, i, j, l = 0;
+ float fac, step;
+
+ k = L_frame / FDNS_NPTS;
+
+ /* Formant enhancement via square root of the LPC gains */
+ xn_buf[0] = (float) sqrt( gainlpc[0] );
+ xn_buf[1] = (float) sqrt( gainlpc[1] );
+ fac = 1.0f / min( xn_buf[0], xn_buf[1] );
+
+ for ( i = 1; i < FDNS_NPTS - 1; i++ )
+ {
+ xn_buf[i + 1] = (float) sqrt( gainlpc[i + 1] );
+
+ if ( ( xn_buf[i - 1] <= xn_buf[i] ) && ( xn_buf[i + 1] <= xn_buf[i] ) )
+ {
+ step = max( xn_buf[i - 1], xn_buf[i + 1] );
+ step = ( 1.0f / step - fac ) / (float) ( i - l );
+ xn_buf[l] = 1.0f;
+ fac += step;
+ for ( j = l + 1; j < i; j++ )
+ {
+ xn_buf[j] = min( 1.0f, xn_buf[j] * fac );
+ fac += step;
+ }
+ l = i;
+ }
+ }
+
+ /* i = hTcxCfg->fdns_npts - 1; Completing changes to gains */
+ step = min( xn_buf[i - 1], xn_buf[i] );
+ step = ( 1.0f / step - fac ) / (float) ( i - l );
+ xn_buf[l] = 1.0f;
+ fac += step;
+ for ( j = l + 1; j < i; j++ )
+ {
+ xn_buf[j] = min( 1.0f, xn_buf[j] * fac );
+ fac += step;
+ }
+ xn_buf[i] = 1.0f;
+
+ /* Application of changed gains onto decoded MDCT lines */
+ for ( i = j = 0; i < L_frame; j++ )
+ {
+ for ( l = 0; l < k; i++, l++ )
+ {
+ spectrum[i] *= xn_buf[j];
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * tcxInvertWindowGrouping()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tcxInvertWindowGrouping(
+ TCX_CONFIG_HANDLE hTcxCfg,
+ float xn_buf[],
+ float spectrum[],
+ const int16_t L_frame,
+ const int16_t fUseTns,
+ const int16_t last_core,
+ const int16_t index,
+ const int16_t frame_cnt,
+ const int16_t bfi )
+{
+ int16_t i, w, t_integer;
+ int16_t L_win, L_spec;
+
+ if ( frame_cnt && !bfi && last_core != ACELP_CORE )
+ {
+ /* fix sub-window overlap */
+ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
+ }
+
+ if ( ( ( !bfi ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) ||
+ ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( index == 0 ) ) ) ) ||
+ ( ( bfi ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) &&
+ !( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) ) ) )
+ {
+
+ /* ungroup sub-windows: deinterleave MDCT bins into separate windows */
+ for ( t_integer = w = 0; w < 2; w++ )
+ {
+ for ( i = w; i < L_frame; i += 2 )
+ {
+ xn_buf[t_integer++] = spectrum[i];
+ }
+ }
+
+ mvr2r( xn_buf, spectrum, L_frame );
+
+ if ( hTcxCfg->fIsTNSAllowed && !bfi && fUseTns )
+ {
+ L_win = L_frame >> 1;
+ L_spec = hTcxCfg->tnsConfig[0][0].iFilterBorders[0];
+
+ /* rearrange LF sub-window lines prior to TNS synthesis filtering */
+ if ( L_spec < L_frame )
+ {
+ mvr2r( spectrum + 8, spectrum + 16, L_spec / 2 - 8 );
+ mvr2r( spectrum + L_frame / 2, spectrum + 8, 8 );
+ mvr2r( spectrum + L_frame / 2 + 8, spectrum + L_spec / 2 + 8, L_spec / 2 - 8 );
+ }
+ else
+ {
+ mvr2r( spectrum + 8, xn_buf, L_win );
+ mvr2r( xn_buf, spectrum + 16, L_win - 8 );
+ mvr2r( xn_buf + L_win - 8, spectrum + 8, 8 );
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tcx5SpectrumInterleaving()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tcx5SpectrumInterleaving(
+ const int16_t tcx5Size,
+ float *spectrum )
+{
+ int16_t i;
+ float interleaveBuf[N_TCX10_MAX];
+
+ set_f( interleaveBuf, 0.0f, N_TCX10_MAX );
+
+ /* group sub-windows: interleave bins according to their frequencies */
+ for ( i = 0; i < tcx5Size; i++ )
+ {
+ interleaveBuf[2 * i] = spectrum[i];
+ interleaveBuf[2 * i + 1] = spectrum[tcx5Size + i];
+ }
+
+ mvr2r( interleaveBuf, spectrum, 2 * tcx5Size );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tcx5SpectrumDeinterleaving()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tcx5SpectrumDeinterleaving(
+ const int16_t tcx5Size,
+ float *spectrum )
+{
+ int16_t i;
+ float interleaveBuf[N_TCX10_MAX];
+
+ set_f( interleaveBuf, 0.0f, N_TCX10_MAX );
+
+ /* ungroup sub-windows: interleave bins according to their frequencies */
+ for ( i = 0; i < tcx5Size; i++ )
+ {
+ interleaveBuf[i] = spectrum[2 * i];
+ interleaveBuf[tcx5Size + i] = spectrum[2 * i + 1];
+ }
+
+ mvr2r( interleaveBuf, spectrum, 2 * tcx5Size );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tcx5TnsGrouping()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tcx5TnsGrouping(
+ const int16_t L_frame, /* i : frame length (TCX5) */
+ const int16_t L_spec, /* i : coded spec length (TCX5, derived from filter borders*/
+ float *spectrum )
+{
+ /* rearrange LF sub-window lines prior to TNS synthesis filtering */
+ if ( L_spec < L_frame )
+ {
+ mvr2r( spectrum + 8, spectrum + 16, L_spec - 8 );
+ mvr2r( spectrum + L_frame, spectrum + 8, 8 );
+ mvr2r( spectrum + L_frame + 8, spectrum + L_spec + 8, L_spec - 8 );
+ }
+ else
+ {
+ float buff[8]; /* Buffer for the rearrangement of LF TCX5 */
+ mvr2r( spectrum + L_spec, buff, 8 );
+ mvr2r( spectrum + 8, spectrum + 16, L_spec - 8 );
+ mvr2r( buff, spectrum + 8, 8 );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tcx5TnsUngrouping()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tcx5TnsUngrouping(
+ const int16_t L_frame, /* i : frame length (TCX5) */
+ const int16_t L_spec, /* i : coded spec length (TCX5, derived from filter borders*/
+ float *spectrum,
+ const int16_t enc_dec /* i : 0: encoder, else decoder */
+)
+{
+ /* undo rearrangement of LF sub-window lines prior to TNS analysis */
+ if ( L_spec < L_frame )
+ {
+ mvr2r( spectrum + L_spec + 8, spectrum + L_frame + 8, L_spec - 8 );
+ mvr2r( spectrum + 8, spectrum + L_frame, 8 );
+ mvr2r( spectrum + 16, spectrum + 8, L_spec - 8 );
+ set_zero( spectrum + L_spec, L_frame - L_spec );
+ set_zero( spectrum + L_frame + L_spec, L_frame - L_spec );
+ }
+ else
+ {
+ float buff[8]; /* Buffer for the rearrangement of LF TCX5 */
+
+ mvr2r( spectrum + 8, buff, 8 );
+
+ if ( enc_dec == ENC )
+ {
+ mvr2r( spectrum + 16, spectrum + 8, L_frame - 8 );
+ mvr2r( buff, spectrum + L_frame, 8 );
+ }
+ else
+ {
+ mvr2r( spectrum + 16, spectrum + 8, L_spec - 8 );
+ mvr2r( buff, spectrum + L_spec, 8 );
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h
new file mode 100644
index 0000000000000000000000000000000000000000..92331dc9a57e09741c5391de6415e4f4e73f72f6
--- /dev/null
+++ b/lib_com/common_api_types.h
@@ -0,0 +1,224 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 COMMON_API_TYPES_H
+#define COMMON_API_TYPES_H
+
+/* options.h needed for debugging/development features
+ * It should be stripped for delivery along with debugging switches */
+#include "options.h"
+#include
+#include
+#include "ivas_error.h"
+
+/*----------------------------------------------------------------------------------*
+ * Common API constants
+ *----------------------------------------------------------------------------------*/
+
+#define IVAS_NUM_FRAMES_PER_SEC 50
+#define IVAS_MAX_FRAME_SIZE ( 48000 / IVAS_NUM_FRAMES_PER_SEC )
+
+#define IVAS_MAX_BITS_PER_FRAME ( 512000 / IVAS_NUM_FRAMES_PER_SEC )
+
+#define IVAS_MAX_NUM_OBJECTS 4
+#define IVAS_MAX_INPUT_CHANNELS 16
+#define IVAS_MAX_OUTPUT_CHANNELS 16
+#define IVAS_CLDFB_NO_COL_MAX 16
+#define IVAS_CLDFB_NO_CHANNELS_MAX 60
+#define IVAS_MAX_INPUT_LFE_CHANNELS 4
+
+#define IVAS_MAX_PARAM_SPATIAL_SUBFRAMES 4
+
+#define IVAS_ROOM_ABS_COEFF 6
+
+/*----------------------------------------------------------------------------------*
+ * Common API enum for output audio configurations
+ *----------------------------------------------------------------------------------*/
+
+typedef enum _IVAS_AUDIO_CONFIG
+{
+ IVAS_AUDIO_CONFIG_INVALID,
+ IVAS_AUDIO_CONFIG_MONO, /* mono output */
+ IVAS_AUDIO_CONFIG_STEREO, /* stereo output */
+ IVAS_AUDIO_CONFIG_5_1, /* 5.1 speakers layout CICP6 */
+ IVAS_AUDIO_CONFIG_7_1, /* 7.1 speakers layout CICP12 */
+ IVAS_AUDIO_CONFIG_5_1_2, /* 5.1+2 speakers layout CICP14 */
+ IVAS_AUDIO_CONFIG_5_1_4, /* 5.1+4 speakers layout CICP16 */
+ IVAS_AUDIO_CONFIG_7_1_4, /* 7.1+4 speakers layout CICP19 */
+ IVAS_AUDIO_CONFIG_LS_CUSTOM, /* custom loudspeaker layout */
+ IVAS_AUDIO_CONFIG_FOA, /* ambisonics, order 1 */
+ IVAS_AUDIO_CONFIG_HOA2, /* ambisonics, order 2 */
+ IVAS_AUDIO_CONFIG_HOA3, /* ambisonics, order 3 */
+ IVAS_AUDIO_CONFIG_OBA, /* object based audio */
+ IVAS_AUDIO_CONFIG_BINAURAL, /* binaural with HRIR */
+ IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED, /* split binaural with CLDFB coded output */
+ IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM, /* split binaural with PCM coded output */
+ IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, /* binaural with BRIR */
+ IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB, /* binaural with HRIR + reverb */
+ IVAS_AUDIO_CONFIG_ISM1, /* ISM1 */
+ IVAS_AUDIO_CONFIG_ISM2, /* ISM2 */
+ IVAS_AUDIO_CONFIG_ISM3, /* ISM3 */
+ IVAS_AUDIO_CONFIG_ISM4, /* ISM4 */
+ IVAS_AUDIO_CONFIG_MASA1, /* MASA1 */
+ IVAS_AUDIO_CONFIG_MASA2, /* MASA2 */
+ IVAS_AUDIO_CONFIG_EXTERNAL /* external renderer */
+
+} IVAS_AUDIO_CONFIG;
+
+
+/*----------------------------------------------------------------------------------*
+ * Common API structures and enums
+ *----------------------------------------------------------------------------------*/
+
+typedef enum _IVAS_ENC_FEC_INDICATOR
+{
+ IVAS_ENC_FEC_LO,
+ IVAS_ENC_FEC_HI,
+ IVAS_ENC_FEC_UNDEFINED = 0xffff
+
+} IVAS_ENC_FEC_INDICATOR;
+
+typedef struct _IVAS_ENC_CHANNEL_AWARE_CONFIG
+{
+ int16_t channelAwareModeEnabled;
+ IVAS_ENC_FEC_INDICATOR fec_indicator;
+ int16_t fec_offset;
+
+} IVAS_ENC_CHANNEL_AWARE_CONFIG;
+
+typedef struct _IVAS_ISM_METADATA
+{
+ float azimuth;
+ float elevation;
+ float radius;
+ float spread;
+ float gainFactor;
+ float yaw;
+ float pitch;
+ int16_t non_diegetic_flag;
+
+} IVAS_ISM_METADATA;
+
+typedef struct
+{
+ float w, x, y, z;
+
+} IVAS_QUATERNION;
+
+typedef struct
+{
+ float x, y, z;
+
+} IVAS_VECTOR3;
+
+typedef enum
+{
+ IVAS_HEAD_ORIENT_TRK_NONE,
+ IVAS_HEAD_ORIENT_TRK_REF,
+ IVAS_HEAD_ORIENT_TRK_AVG,
+ IVAS_HEAD_ORIENT_TRK_REF_VEC,
+ IVAS_HEAD_ORIENT_TRK_REF_VEC_LEV
+
+} IVAS_HEAD_ORIENT_TRK_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;
+
+typedef struct TDREND_HRFILT_FiltSet_struct *IVAS_DEC_HRTF_HANDLE;
+typedef struct ivas_hrtfs_crend_structure *IVAS_DEC_HRTF_CREND_HANDLE;
+typedef struct ivas_hrtfs_fastconv_struct *IVAS_DEC_HRTF_FASTCONV_HANDLE;
+typedef struct ivas_hrtfs_parambin_struct *IVAS_DEC_HRTF_PARAMBIN_HANDLE;
+typedef struct cldfb_filter_bank_struct *IVAS_CLDFB_FILTER_BANK_HANDLE;
+
+typedef struct ivas_LS_setup_custom *IVAS_LSSETUP_CUSTOM_HANDLE;
+typedef struct ivas_LS_setup_custom IVAS_LSSETUP_CUSTOM_STRUCT;
+
+typedef struct _IVAS_LS_CUSTOM_LAYOUT
+{
+ int16_t num_spk;
+ float azimuth[IVAS_MAX_OUTPUT_CHANNELS];
+ float elevation[IVAS_MAX_OUTPUT_CHANNELS];
+ int16_t num_lfe;
+ int16_t lfe_idx[IVAS_MAX_OUTPUT_CHANNELS];
+
+} IVAS_CUSTOM_LS_DATA;
+
+typedef struct _IVAS_JBM_TRACE_DATA
+{
+ uint32_t systemTimestamp_ms;
+ uint16_t extBufferedSamples;
+ uint16_t lastDecodedWasActive;
+ int32_t output_Fs;
+ int16_t dataUnit_flag;
+ uint16_t sequenceNumber;
+ uint32_t timeStamp;
+ uint32_t rcvTime;
+
+ int16_t partial_frame;
+ int16_t partialCopyOffset;
+
+} IVAS_JBM_TRACE_DATA;
+
+
+
+/*----------------------------------------------------------------------------------*
+ * Renderer API structures and enums
+ *----------------------------------------------------------------------------------*/
+
+
+typedef struct _IVAS_ROOM_ACOUSTICS_CONFIG
+{
+ int16_t override;
+ int16_t nBands; /* Number of frequency bands for which reverb properties are provided, integer, range [2..256] */
+ float pFc_input[IVAS_CLDFB_NO_CHANNELS_MAX]; /* Center frequencies for which following values are provided: */
+ float pAcoustic_rt60[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's T60 per center frequency */
+ float pAcoustic_dsr[IVAS_CLDFB_NO_CHANNELS_MAX]; /* - The room's Diffuse to Source Ratio per center frequency */
+ float acousticPreDelay; /* Time elapsed between input signal and late reverberation start, float, range [0.001..10] */
+ float inputPreDelay; /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10] */
+
+ /* early reflections */
+ int16_t use_er; /* ER activation flag */
+ int32_t lowComplexity; /* Low complexity ER flag */
+ IVAS_VECTOR3 dimensions; /* Room dimensions [m] */
+ float AbsCoeff[IVAS_ROOM_ABS_COEFF]; /* Absorption coeffs */
+ IVAS_VECTOR3 ListenerOrigin; /* Listener origin */
+
+} IVAS_ROOM_ACOUSTICS_CONFIG_DATA;
+
+typedef struct _IVAS_RENDER_CONFIG
+{
+ IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcoustics;
+ float directivity[IVAS_MAX_NUM_OBJECTS * 3];
+
+} IVAS_RENDER_CONFIG_DATA, *IVAS_RENDER_CONFIG_HANDLE;
+
+#endif /* COMMON_API_TYPES_H */
diff --git a/lib_com/control.h b/lib_com/control.h
new file mode 100644
index 0000000000000000000000000000000000000000..725163728dc88ec26e8cee3d1f0b2c7c28e5721e
--- /dev/null
+++ b/lib_com/control.h
@@ -0,0 +1,82 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 _CONTROL_H
+#define _CONTROL_H
+
+/* BASOP -> FLC brigde: flow control instructions */
+
+#include "stl.h"
+
+#define FOR( a ) \
+ if ( incrFor(), 0 ) \
+ ; \
+ else \
+ for ( a )
+static __inline void incrFor( void )
+{
+}
+
+#define WHILE( a ) \
+ if ( incrFlcWhile(), 0 ) \
+ ; \
+ else \
+ while ( a )
+static __inline void incrFlcWhile( void )
+{
+}
+
+#define DO do
+
+#define IF( a ) if ( incrIf(), a )
+static __inline void incrIf( void )
+{
+}
+
+#define ELSE else
+
+#define SWITCH( a ) switch ( incrSwitch(), a )
+static __inline void incrSwitch( void )
+{
+}
+
+#define CONTINUE continue
+
+#define BREAK break
+
+#define GOTO goto
+
+#endif /* _CONTROL_H */
diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c
new file mode 100644
index 0000000000000000000000000000000000000000..13fe05bbb161c1b6776506dfe5858e8143a3256a
--- /dev/null
+++ b/lib_com/core_com_config.c
@@ -0,0 +1,923 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+#include "ivas_prot.h"
+
+
+/*-------------------------------------------------------------------*
+ * is_EVS_bitrate()
+ *
+ * check if the bitrate is EVS supported active bitrate
+ *-------------------------------------------------------------------*/
+
+/*! r: flag indicating a valid bitrate */
+int16_t is_EVS_bitrate(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ int16_t *Opt_AMR_WB /* i : AMR-WB IO flag */
+)
+{
+ int16_t j;
+
+ j = 0;
+ while ( j < SIZE_BRATE_TBL && ivas_total_brate != brate_tbl[j] )
+ {
+ j++;
+ }
+
+ /* AMR-WB IO mode/EVS primary mode determination */
+ if ( j >= SIZE_BRATE_TBL )
+ {
+ switch ( ivas_total_brate )
+ {
+ case ACELP_6k60:
+ case ACELP_8k85:
+ case ACELP_12k65:
+ case ACELP_14k25:
+ case ACELP_15k85:
+ case ACELP_18k25:
+ case ACELP_19k85:
+ case ACELP_23k05:
+ case ACELP_23k85:
+ break;
+ default:
+ {
+ return 0;
+ }
+ break;
+ }
+
+ *Opt_AMR_WB = 1;
+ }
+ else
+ {
+ *Opt_AMR_WB = 0;
+ }
+
+ return 1;
+}
+
+
+/*-------------------------------------------------------------------*
+ * get_codec_mode()
+ *
+ * Get codec_mode (MODE1 or MODE2)
+ *-------------------------------------------------------------------*/
+
+/*! r: codec mode */
+int16_t get_codec_mode(
+ const int32_t total_brate /* i : total bitrate */
+)
+{
+ int16_t codec_mode = -1;
+
+ switch ( total_brate )
+ {
+ case 5900:
+ codec_mode = MODE1;
+ break;
+ case 7200:
+ codec_mode = MODE1;
+ break;
+ case 8000:
+ codec_mode = MODE1;
+ break;
+ case 9600:
+ codec_mode = MODE2;
+ break;
+ case 13200:
+ codec_mode = MODE1;
+ break;
+ case 16400:
+ codec_mode = MODE2;
+ break;
+ case 24400:
+ codec_mode = MODE2;
+ break;
+ case 32000:
+ codec_mode = MODE1;
+ break;
+ case 48000:
+ codec_mode = MODE2;
+ break;
+ case 64000:
+ codec_mode = MODE1;
+ break;
+ case 96000:
+ codec_mode = MODE2;
+ break;
+ case 128000:
+ codec_mode = MODE2;
+ break;
+ }
+
+ return codec_mode;
+}
+
+
+/*-------------------------------------------------------------------*
+ * getTcxonly()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getTcxonly(
+ const int16_t element_mode, /* i : IVAS element mode */
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/
+ const int16_t is_ism_format /* i : flag indicating ISM format */
+)
+{
+ int16_t tcxonly = 0;
+
+ switch ( element_mode )
+ {
+ case EVS_MONO:
+ if ( total_brate > ACELP_32k )
+ {
+ tcxonly = 1;
+ }
+ break;
+ case IVAS_SCE:
+ if ( is_ism_format )
+ {
+ if ( total_brate > MAX_ACELP_BRATE_ISM )
+ {
+ tcxonly = 1;
+ }
+ }
+ else
+ {
+ if ( total_brate > MAX_ACELP_BRATE )
+ {
+ tcxonly = 1;
+ }
+ }
+ break;
+
+ case IVAS_CPE_DFT:
+ case IVAS_CPE_TD:
+ if ( total_brate > MAX_ACELP_BRATE )
+ {
+ tcxonly = 1;
+ }
+ break;
+ case IVAS_CPE_MDCT:
+ if ( total_brate >= ( MCT_flag ? IVAS_32k : IVAS_48k ) )
+ {
+ tcxonly = 1;
+ }
+ break;
+ }
+
+ return tcxonly;
+}
+
+
+/*-------------------------------------------------------------------*
+ * getCtxHm()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getCtxHm(
+ const int16_t element_mode, /* i : IVAS element mode */
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t rf_flag /* i : flag to signal the RF mode */
+)
+{
+ int16_t ctx_hm = 0;
+
+ if ( ( ( element_mode <= IVAS_SCE && total_brate > LPC_SHAPED_ARI_MAX_RATE ) || ( element_mode > IVAS_SCE && total_brate > LPC_SHAPED_ARI_MAX_RATE_CPE ) ) && !rf_flag && ( ( total_brate <= IVAS_64k && element_mode != IVAS_CPE_DFT ) || ( total_brate < 24400 && element_mode == IVAS_CPE_DFT ) ) && element_mode != IVAS_CPE_MDCT )
+ {
+ ctx_hm = 1;
+ }
+
+ return ctx_hm;
+}
+
+/*-------------------------------------------------------------------*
+ * getResq()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getResq(
+ const int32_t total_brate /* i : total bitrate */
+)
+{
+ int16_t resq = 0;
+
+ if ( total_brate <= IVAS_64k )
+ {
+ resq = 1;
+ }
+
+ return resq;
+}
+
+/*-------------------------------------------------------------------*
+ * getTnsAllowed()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getTnsAllowed(
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t igf, /* i : flag indicating IGF activity*/
+ const int16_t element_mode /* i : IVAS element mode */
+)
+{
+ int16_t tnsAllowed = 0;
+
+ if ( igf )
+ {
+ if ( total_brate > HQ_16k40 || ( ( total_brate > HQ_13k20 ) && element_mode == IVAS_CPE_DFT ) )
+ {
+ tnsAllowed = 1;
+ }
+ }
+ else if ( total_brate > HQ_32k )
+ {
+ tnsAllowed = 1;
+ }
+
+ return tnsAllowed;
+}
+
+/*-------------------------------------------------------------------*
+ * getRestrictedMode()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getRestrictedMode(
+ const int16_t element_mode, /* i : IVAS element mode */
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */
+)
+{
+ int16_t restrictedMode = 3;
+
+ if ( !Opt_AMR_WB && ( total_brate > HQ_32k && element_mode != IVAS_SCE ) )
+ {
+ restrictedMode = 6;
+ }
+ else if ( !Opt_AMR_WB && ( total_brate > HQ_48k && element_mode == IVAS_SCE ) )
+ {
+ restrictedMode = 6;
+ }
+ else if ( Opt_AMR_WB )
+ {
+ restrictedMode = 1;
+ }
+
+ return restrictedMode;
+}
+
+/*-------------------------------------------------------------------*
+ * getMdctWindowLength()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getMdctWindowLength(
+ const int16_t fscale )
+{
+ int16_t mdctWindowLength;
+
+ mdctWindowLength = ( L_LOOK_12k8 * fscale ) / FSCALE_DENOM;
+
+ return mdctWindowLength;
+}
+
+/*-------------------------------------------------------------------*
+ * sr2fscale()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t sr2fscale(
+ const int32_t sr_core /* i : internal sampling rate */
+)
+{
+
+ return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 );
+}
+
+/*-------------------------------------------------------------------*
+ * getCoreSamplerateMode2()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int32_t getCoreSamplerateMode2(
+ const int16_t element_mode, /* i : IVAS element mode */
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */
+ const int16_t rf_mode, /* i : flag to signal the RF mode */
+ const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */
+)
+{
+ int32_t sr_core = 0;
+
+ if ( bwidth == NB )
+ {
+ sr_core = INT_FS_12k8;
+ }
+ else if ( element_mode == EVS_MONO && ( ( bwidth == WB && total_brate < ACELP_13k20 ) || ( bwidth == SWB && total_brate <= ACELP_13k20 ) || ( rf_mode == 1 ) ) )
+ {
+ sr_core = INT_FS_12k8;
+ }
+ else if ( element_mode > EVS_MONO && flag_ACELP16k == 0 )
+ {
+ sr_core = INT_FS_12k8;
+ }
+ else if ( bwidth == WB || ( bwidth == SWB && total_brate <= ACELP_32k ) || ( bwidth == FB && total_brate <= ACELP_32k ) )
+ {
+ sr_core = INT_FS_16k;
+ }
+ else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && !is_ism_format )
+ {
+ sr_core = INT_FS_16k;
+ }
+ else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE_ISM && element_mode == IVAS_SCE && is_ism_format )
+ {
+ sr_core = INT_FS_16k;
+ }
+ else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && is_ism_format )
+ {
+ sr_core = 25600;
+ }
+ else if ( ( ( bwidth == SWB || bwidth == FB ) && element_mode == EVS_MONO && total_brate <= HQ_64k ) || ( element_mode > IVAS_SCE && ( ( bwidth == SWB && total_brate <= IVAS_96k ) || ( bwidth == FB && total_brate <= IVAS_96k ) ) ) )
+ {
+ sr_core = 25600;
+ }
+ else if ( bwidth == SWB || bwidth == FB )
+ {
+ sr_core = 32000;
+ }
+
+ return sr_core;
+}
+
+/*-------------------------------------------------------------------*
+ * getTcxBandwidth()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+float getTcxBandwidth(
+ const int16_t bwidth /* i : audio bandwidth */
+)
+{
+ float tcxBandwidth = 0.5f;
+
+ if ( bwidth == NB )
+ {
+ tcxBandwidth = 0.3125f;
+ }
+
+ return tcxBandwidth;
+}
+
+/*-------------------------------------------------------------------*
+ * getIgfPresent()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getIgfPresent(
+ const int16_t element_mode, /* i : IVAS element mode */
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int16_t rf_mode /* i : flag to signal the RF mode */
+)
+{
+ int16_t igfPresent = 0;
+
+
+ if ( bwidth == SWB )
+ {
+ switch ( element_mode )
+ {
+ case EVS_MONO:
+ case IVAS_SCE:
+ if ( total_brate <= HQ_64k )
+ {
+ igfPresent = 1;
+ }
+ break;
+ case IVAS_CPE_DFT:
+ case IVAS_CPE_TD:
+ if ( total_brate <= HQ_48k )
+ {
+ igfPresent = 1;
+ }
+ break;
+ case IVAS_CPE_MDCT:
+ if ( total_brate <= IVAS_96k )
+ {
+ igfPresent = 1;
+ }
+ break;
+ }
+ }
+ else if ( bwidth == FB )
+ {
+ switch ( element_mode )
+ {
+ case EVS_MONO:
+ case IVAS_SCE:
+ if ( total_brate <= IVAS_128k )
+ {
+ igfPresent = 1;
+ }
+ break;
+ case IVAS_CPE_DFT:
+ case IVAS_CPE_TD:
+ if ( total_brate <= IVAS_48k )
+ {
+ igfPresent = 1;
+ }
+ break;
+ case IVAS_CPE_MDCT:
+ if ( total_brate <= IVAS_128k )
+ {
+ igfPresent = 1;
+ }
+ break;
+ }
+ }
+ else if ( bwidth == WB )
+ {
+ switch ( element_mode )
+ {
+ case EVS_MONO:
+ case IVAS_SCE:
+ if ( total_brate <= ACELP_9k60 )
+ {
+ igfPresent = 1;
+ }
+ break;
+ case IVAS_CPE_DFT:
+ case IVAS_CPE_TD:
+ case IVAS_CPE_MDCT:
+ if ( total_brate <= ACELP_13k20 )
+ {
+ igfPresent = 1;
+ }
+ break;
+ }
+ }
+
+ if ( ( ( bwidth == WB ) || ( bwidth == SWB ) ) && ( rf_mode == 1 ) && ( total_brate == ACELP_13k20 ) )
+ {
+ igfPresent = 1;
+ }
+
+ return igfPresent;
+}
+
+/*-------------------------------------------------------------------*
+ * getCnaPresent()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getCnaPresent(
+ const int16_t element_mode, /* i : element mode */
+ const int32_t element_brate, /* i : element bitrate */
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t bwidth /* i : audio bandwidth */
+)
+{
+ int16_t flag_cna = 0;
+
+ if ( element_mode == IVAS_CPE_DFT && element_brate <= CNA_MAX_BRATE_DFT_STEREO )
+ {
+ flag_cna = 1;
+ }
+ else
+ {
+ if ( bwidth == NB && total_brate <= ACELP_13k20 )
+ {
+ flag_cna = 1;
+ }
+
+ if ( bwidth == WB && total_brate <= ACELP_13k20 )
+ {
+ flag_cna = 1;
+ }
+
+ if ( bwidth == SWB && total_brate <= ACELP_13k20 )
+ {
+ flag_cna = 1;
+ }
+ }
+
+ return flag_cna;
+}
+
+/*-------------------------------------------------------------------*
+ * getTcxLtp()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getTcxLtp(
+ const int32_t sr_core /* i : internal sampling rate */
+)
+{
+ int16_t tcxltp = 0;
+
+ if ( sr_core <= 25600 )
+ {
+ tcxltp = 1;
+ }
+
+ return tcxltp;
+}
+
+/*-------------------------------------------------------------------*
+ * initPitchLagParameters()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t initPitchLagParameters(
+ const int32_t sr_core,
+ int16_t *pit_min,
+ int16_t *pit_fr1,
+ int16_t *pit_fr1b,
+ int16_t *pit_fr2,
+ int16_t *pit_max )
+{
+ int16_t pit_res_max;
+
+ if ( sr_core == INT_FS_12k8 )
+ {
+ *pit_min = PIT_MIN_12k8;
+ *pit_max = PIT_MAX_12k8;
+ *pit_fr2 = PIT_FR2_12k8;
+ *pit_fr1 = PIT_FR1_12k8;
+ *pit_fr1b = PIT_FR1_8b_12k8;
+ pit_res_max = 4;
+ }
+ else if ( sr_core == INT_FS_16k )
+ {
+ *pit_min = PIT_MIN_16k;
+ *pit_max = PIT16k_MAX;
+ *pit_fr2 = PIT_FR2_16k;
+ *pit_fr1 = PIT_FR1_16k;
+ *pit_fr1b = PIT_FR1_8b_16k;
+ pit_res_max = 6;
+ }
+ else if ( sr_core == 25600 )
+ {
+ *pit_min = PIT_MIN_25k6;
+ *pit_max = PIT_MAX_25k6;
+ *pit_fr2 = PIT_FR2_25k6;
+ *pit_fr1 = PIT_FR1_25k6;
+ *pit_fr1b = PIT_FR1_8b_25k6;
+ pit_res_max = 4;
+ }
+ else /* sr_core==32000 */
+ {
+ *pit_min = PIT_MIN_32k;
+ *pit_max = PIT_MAX_32k;
+ *pit_fr2 = PIT_FR2_32k;
+ *pit_fr1 = PIT_FR1_32k;
+ *pit_fr1b = PIT_FR1_8b_32k;
+ pit_res_max = 6;
+ }
+
+ return pit_res_max;
+}
+
+/*-------------------------------------------------------------------*
+ * getNumTcxCodedLines()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getNumTcxCodedLines(
+ const int16_t bwidth /* i : audio bandwidth */
+)
+{
+ int16_t tcx_coded_lines;
+
+ switch ( bwidth )
+ {
+ case NB:
+ tcx_coded_lines = 160;
+ break;
+ case WB:
+ tcx_coded_lines = 320;
+ break;
+ case SWB:
+ tcx_coded_lines = 640;
+ break;
+ case FB:
+ tcx_coded_lines = 960;
+ break;
+ default:
+ tcx_coded_lines = 0;
+ break;
+ }
+
+ return tcx_coded_lines;
+}
+
+/*-------------------------------------------------------------------*
+ * getTcxLpcShapedAri()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+int16_t getTcxLpcShapedAri(
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t rf_mode, /* i : flag to signal the RF mode */
+ const int16_t element_mode /* i : IVAS element mode */
+)
+{
+ int16_t tcx_lpc_shaped_ari = 0;
+
+ if ( ( ( element_mode <= IVAS_SCE && total_brate <= LPC_SHAPED_ARI_MAX_RATE ) || ( element_mode > IVAS_SCE && total_brate <= LPC_SHAPED_ARI_MAX_RATE_CPE ) ) || rf_mode )
+ {
+ tcx_lpc_shaped_ari = 1;
+ }
+
+ return tcx_lpc_shaped_ari;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * init_tcx_window_cfg()
+ *
+ * Initialization of TCX windows
+ *-----------------------------------------------------------------------*/
+
+void init_tcx_window_cfg(
+ TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */
+ const int32_t sr_core, /* i : SR core */
+ const int32_t input_Fs, /* i : input/output SR */
+ const int16_t L_frame, /* i : L_frame at sr_core */
+ const int16_t L_frameTCX, /* i : L_frame at i/o SR */
+ const int16_t encoderLookahead_enc, /* i : encoder LA at sr_core */
+ const int16_t encoderLookahead_FB, /* i : encoder LA at i/o SR */
+ const int16_t mdctWindowLength, /* i : window length at sr_core */
+ const int16_t mdctWindowLengthFB, /* i : window length at i/o SR */
+ const int16_t element_mode /* i : mode of CPE/SCE */
+)
+{
+ /* Symmetric window = sine LD window*/
+ hTcxCfg->tcx_mdct_window_delay = mdctWindowLength;
+ hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB;
+ hTcxCfg->tcx_mdct_window_length = mdctWindowLength;
+ hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB;
+
+ mdct_window_sine( hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode );
+ if ( hTcxCfg->tcx_mdct_window_length == hTcxCfg->tcx_mdct_window_lengthFB )
+ {
+ mvr2r( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, hTcxCfg->tcx_mdct_window_length );
+ }
+ else
+ {
+ mdct_window_sine( hTcxCfg->tcx_mdct_windowFB, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode );
+ }
+
+ /*ALDO windows for MODE2*/
+ mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_2, L_frame );
+ mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_2_FB, NS2SA( input_Fs, FRAME_SIZE_NS ) );
+ hTcxCfg->tcx_aldo_window_1_trunc = hTcxCfg->tcx_aldo_window_1 + NS2SA( sr_core, N_ZERO_MDCT_NS );
+ hTcxCfg->tcx_aldo_window_1_FB_trunc = hTcxCfg->tcx_aldo_window_1_FB + NS2SA( input_Fs, N_ZERO_MDCT_NS );
+
+ /*1.25ms transition window for ACELP->TCX*/
+ hTcxCfg->tcx_mdct_window_trans_length = NS2SA( sr_core, ACELP_TCX_TRANS_NS );
+ mdct_window_sine( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode );
+ hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA( input_Fs, ACELP_TCX_TRANS_NS );
+ if ( hTcxCfg->tcx_mdct_window_trans_length == hTcxCfg->tcx_mdct_window_trans_lengthFB )
+ {
+ mvr2r( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_trans_length );
+ }
+ else
+ {
+ mdct_window_sine( hTcxCfg->tcx_mdct_window_transFB, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode );
+ }
+
+ /*Mid-OLA*/
+ /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/
+ hTcxCfg->tcx_mdct_window_half_length = 2 * ( ( encoderLookahead_enc - (int16_t) ( 0.005f * sr_core + 0.5f ) ) >> 1 );
+ hTcxCfg->tcx_mdct_window_half_lengthFB = 2 * ( ( encoderLookahead_FB - (int16_t) ( 0.005f * input_Fs + 0.5f ) ) >> 1 );
+ assert( ( hTcxCfg->tcx_mdct_window_half_length > 16 ) && "Half window can not be large enough!" );
+
+ mdct_window_sine( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode );
+ if ( hTcxCfg->tcx_mdct_window_half_length == hTcxCfg->tcx_mdct_window_half_lengthFB )
+ {
+ mvr2r( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_half_length );
+ }
+ else
+ {
+ mdct_window_sine( hTcxCfg->tcx_mdct_window_halfFB, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode );
+ }
+
+ /* minimum overlap 1.25 ms */
+ hTcxCfg->tcx_mdct_window_min_length = (int16_t) ( sr_core * INV_CLDFB_BANDWIDTH );
+ hTcxCfg->tcx_mdct_window_min_lengthFB = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH );
+ /* save complexity by copying the small windows if they have the same length */
+ if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_trans_length )
+ {
+ mvr2r( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_min_length );
+ }
+ else
+ {
+ mdct_window_sine( hTcxCfg->tcx_mdct_window_minimum, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode );
+ }
+
+ if ( hTcxCfg->tcx_mdct_window_min_lengthFB == hTcxCfg->tcx_mdct_window_trans_lengthFB )
+ {
+ mvr2r( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB );
+ }
+ else if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_min_lengthFB )
+ {
+ mvr2r( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB );
+ }
+ else
+ {
+ mdct_window_sine( hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode );
+ }
+
+ /* TCX Offset */
+ hTcxCfg->tcx_offset = ( hTcxCfg->tcx_mdct_window_delay >> 1 );
+ hTcxCfg->tcx_offsetFB = ( hTcxCfg->tcx_mdct_window_delayFB >> 1 );
+ /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/
+ hTcxCfg->lfacNext = hTcxCfg->tcx_offset - L_frame / 4;
+ hTcxCfg->lfacNextFB = hTcxCfg->tcx_offsetFB - L_frameTCX / 4;
+
+ return;
+}
+
+/*-----------------------------------------------------------------------*
+ * init_tcx()
+ *
+ * Initialization of TCX
+ *-----------------------------------------------------------------------*/
+
+void init_tcx_cfg(
+ TCX_CONFIG_HANDLE hTcxCfg,
+ const int32_t total_brate,
+ const int32_t sr_core,
+ const int32_t input_Fs,
+ const int16_t L_frame,
+ const int16_t bwidth,
+ const int16_t L_frameTCX,
+ const int16_t fscale,
+ const int16_t encoderLookahead_enc,
+ const int16_t encoderLookahead_FB,
+ const float preemph_fac,
+ const int16_t tcxonly,
+ const int16_t rf_mode,
+ const int16_t igf,
+ const int16_t infoIGFStopFreq,
+ const int16_t element_mode,
+ const int16_t ini_frame,
+ const int16_t MCT_flag )
+{
+ int16_t i;
+ int16_t mdctWindowLength;
+ int16_t mdctWindowLengthFB;
+ int16_t na_scale_bwidth;
+
+ hTcxCfg->preemph_fac = preemph_fac;
+ hTcxCfg->tcx5Size = NS2SA( sr_core, FRAME_SIZE_NS / 4 ); /* Always 5 ms */
+ hTcxCfg->tcx5SizeFB = NS2SA( input_Fs, FRAME_SIZE_NS / 4 ); /* Always 5 ms */
+
+ hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length;
+ mdctWindowLength = getMdctWindowLength( fscale );
+ mdctWindowLengthFB = (int16_t) ( mdctWindowLength * input_Fs / sr_core );
+
+ init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode );
+
+ /* SQ deadzone & memory quantization*/
+ hTcxCfg->sq_rounding = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
+
+ /* TCX rate loop */
+ hTcxCfg->tcxRateLoopOpt = ( tcxonly ) ? 2 : 0;
+ hTcxCfg->tcxRateLoopOpt = ( element_mode == IVAS_CPE_MDCT ) ? 3 : hTcxCfg->tcxRateLoopOpt;
+
+ /* TCX bandwidth */
+ hTcxCfg->bandwidth = getTcxBandwidth( bwidth );
+
+ /* set number of coded lines */
+ hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth );
+
+ /* TNS in TCX */
+ hTcxCfg->pCurrentTnsConfig = NULL;
+ hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode );
+
+ if ( hTcxCfg->fIsTNSAllowed )
+ {
+ InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag );
+
+ SetAllowTnsOnWhite( hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT );
+ }
+
+ if ( ini_frame == 0 )
+ {
+ hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
+ hTcxCfg->last_aldo = 1;
+ }
+
+ /* Context HM*/
+ hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode );
+
+ /* Residual Coding*/
+ hTcxCfg->resq = getResq( total_brate );
+ hTcxCfg->tcxRateLoopOpt = ( hTcxCfg->resq && !tcxonly ) ? 1 : hTcxCfg->tcxRateLoopOpt;
+
+ /*Set bandwidth scale*/
+ if ( bwidth == NB )
+ {
+ na_scale_bwidth = NB;
+ }
+ else if ( sr_core <= INT_FS_16k )
+ {
+ na_scale_bwidth = WB;
+ }
+ else
+ {
+ na_scale_bwidth = SWB;
+ }
+
+ /* Scale TCX for non-active frames to adjust loudness with ACELP*/
+ hTcxCfg->na_scale = 1.f;
+
+ if ( na_scale_bwidth < SWB && !tcxonly )
+ {
+ for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
+ {
+ if ( ( na_scale_bwidth == scaleTcxTable[i].bwmode ) &&
+ ( total_brate >= scaleTcxTable[i].bitrateFrom ) &&
+ ( total_brate < scaleTcxTable[i].bitrateTo ) )
+ {
+ if ( rf_mode )
+ {
+ i--;
+ }
+ hTcxCfg->na_scale = scaleTcxTable[i].scale;
+ break;
+ }
+ }
+ }
+
+ if ( tcxonly )
+ {
+ InitPsychLPC( sr_core, L_frame, hTcxCfg );
+ }
+ else
+ {
+ hTcxCfg->psychParamsCurrent = NULL;
+ }
+
+ return;
+}
diff --git a/lib_com/deemph.c b/lib_com/deemph.c
new file mode 100644
index 0000000000000000000000000000000000000000..26baccd04a492255c048cabe6d0dcaea5cc7e252
--- /dev/null
+++ b/lib_com/deemph.c
@@ -0,0 +1,71 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * deemph()
+ *
+ * Deemphasis: filtering through 1/(1-mu z^-1)
+ *-------------------------------------------------------------------*/
+
+void deemph(
+ float *signal, /* i/o: signal */
+ const float mu, /* i : deemphasis factor */
+ const int16_t L, /* i : vector size */
+ float *mem /* i/o: memory (y[-1]) */
+)
+{
+ int16_t i;
+
+ signal[0] = signal[0] + mu * ( *mem );
+ for ( i = 1; i < L; i++ )
+ {
+ signal[i] = signal[i] + mu * signal[i - 1];
+ }
+
+ *mem = signal[L - 1];
+
+ if ( ( *mem < 1e-10 ) & ( *mem > -1e-10 ) )
+ {
+ *mem = 0;
+ }
+
+ return;
+}
diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c
new file mode 100644
index 0000000000000000000000000000000000000000..66c81d440c3c880a2c7cf4706a7ce51bbe5d9a74
--- /dev/null
+++ b/lib_com/delay_comp.c
@@ -0,0 +1,111 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "ivas_cnst.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------
+ * get_delay()
+ *
+ * Function returns various types of delays in the codec in ns.
+ *--------------------------------------------------------------------------*/
+
+/*! r: delay value in ns */
+int32_t get_delay(
+ const int16_t enc_dec, /* i : encoder/decoder flag */
+ const int32_t io_fs, /* i : input/output sampling frequency */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */
+)
+{
+ int32_t delay = 0;
+
+ if ( enc_dec == ENC )
+ {
+ if ( ivas_format == MONO_FORMAT ) /* EVS mono */
+ {
+ delay = ( DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS );
+ }
+ else /* IVAS */
+ {
+ delay = IVAS_ENC_DELAY_NS;
+
+ if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT )
+ {
+ delay = 0; /* All delay is compensated in the decoder with MASA */
+ }
+ }
+ if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
+ {
+ /* compensate for DirAC/SPAR filterbank delay */
+ delay += IVAS_FB_ENC_DELAY_NS;
+ }
+ }
+ else /* DEC */
+ {
+ if ( ivas_format == MONO_FORMAT ) /* EVS mono */
+ {
+ if ( io_fs == 8000 )
+ {
+ delay = DELAY_CLDFB_NS;
+ }
+ else
+ {
+ delay = DELAY_BWE_TOTAL_NS;
+ }
+ }
+ else /* IVAS */
+ {
+ delay = IVAS_DEC_DELAY_NS;
+
+ if ( hCldfb != NULL )
+ {
+ /* compensate for filterbank delay */
+ delay += IVAS_FB_DEC_DELAY_NS;
+ }
+
+ if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT )
+ {
+ delay += IVAS_ENC_DELAY_NS; /* Compensate also the encoder delay in the decoder with MASA */
+ }
+ }
+ }
+
+ return delay;
+}
diff --git a/lib_com/disclaimer.c b/lib_com/disclaimer.c
new file mode 100644
index 0000000000000000000000000000000000000000..f8af72f54117a1a9f442daee4094c3b86e06d580
--- /dev/null
+++ b/lib_com/disclaimer.c
@@ -0,0 +1,56 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+
+#define WMC_TOOL_SKIP
+
+int16_t print_disclaimer( FILE *fPtr )
+{
+
+ fprintf( fPtr, "\n==================================================================================================\n" );
+ fprintf( fPtr, " IVAS Codec Baseline\n" );
+ fprintf( fPtr, " \n" );
+ fprintf( fPtr, " Based on EVS Codec (Floating Point) 3GPP TS26.443 Nov 04, 2021,\n" );
+ fprintf( fPtr, " Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0\n" );
+ fprintf( fPtr, "==================================================================================================\n\n" );
+
+ return 0;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/dlpc_bfi.c b/lib_com/dlpc_bfi.c
new file mode 100644
index 0000000000000000000000000000000000000000..ea701a3fed4315e755b6055a9769d3b1e5458a08
--- /dev/null
+++ b/lib_com/dlpc_bfi.c
@@ -0,0 +1,77 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * routine: dlpc_bfi()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+void dlpc_bfi(
+ const int16_t L_frame,
+ float *lsf_q, /* o : quantized lsfs */
+ const float *lsfold, /* i : past quantized lsf */
+ const int16_t last_good, /* i : last good received frame */
+ const int16_t nbLostCmpt, /* i : counter of consecutive bad frames */
+ float mem_MA[], /* i/o: quantizer memory for MA model */
+ float *mem_AR, /* i/o: quantizer memory for AR model */
+ float *stab_fac, /* i : lsf stability factor */
+ float *lsf_adaptive_mean, /* i : lsf adaptive mean, updated when BFI==0 */
+ const int16_t numlpc, /* i : Number of division per superframe */
+ float lsf_cng[],
+ const int16_t plcBackgroundNoiseUpdated,
+ float *lsf_q_cng, /* o : quantized lsfs of background noise */
+ float *old_lsf_q_cng, /* o : old quantized lsfs for background noise */
+ const float lsfBase[] /* i : base for differential lsf coding */
+)
+{
+ lsf_dec_bfi( MODE2, &lsf_q[0], lsfold, lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, 0, L_frame, last_good, nbLostCmpt, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, 0 );
+
+ if ( numlpc == 2 )
+ {
+ /* Decode the second LPC */
+ lsf_dec_bfi( MODE2, &lsf_q[M], &lsf_q[0], lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, 0, L_frame, last_good, nbLostCmpt + 1, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, 0 );
+ }
+
+ return;
+}
diff --git a/lib_com/edct.c b/lib_com/edct.c
new file mode 100644
index 0000000000000000000000000000000000000000..a265794f3690159fb9b78e9860613d0a6bab8ee7
--- /dev/null
+++ b/lib_com/edct.c
@@ -0,0 +1,417 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+#include /* for cosf, sinf */
+
+static ivas_error get_edct_table(
+ const float **edct_table,
+ const int16_t length )
+{
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+ *edct_table = NULL;
+
+ switch ( length )
+ {
+ case 1200:
+ *edct_table = edct_table_600;
+ break;
+ case 960:
+ *edct_table = edct_table_480;
+ break;
+ case 640:
+ *edct_table = edct_table_320;
+ break;
+ case 320:
+ *edct_table = edct_table_160;
+ break;
+ case 256:
+ *edct_table = edct_table_128;
+ break;
+ case 240:
+ *edct_table = edct_table_120;
+ break;
+ case 200:
+ *edct_table = edct_table_100;
+ break;
+ case 160:
+ *edct_table = edct_table_80;
+ break;
+ case 40:
+ *edct_table = edct_table_20;
+ break;
+ case 800:
+ *edct_table = edct_table_400;
+ break;
+ case 512:
+ *edct_table = edct_table_256;
+ break;
+ case 480:
+ *edct_table = edct_table_240;
+ break;
+ case 400:
+ *edct_table = edct_table_200;
+ break;
+ case 128:
+ *edct_table = edct_table_64;
+ break;
+ case 80:
+ *edct_table = edct_table_40;
+ break;
+ }
+
+ return error;
+}
+
+
+/*-----------------------------------------------------------------*
+ * edct()
+ *
+ * DCT-IV transform
+ *-----------------------------------------------------------------*/
+
+void edct(
+ const float *x, /* i : input signal */
+ float *y, /* o : output transform */
+ const int16_t length, /* i : length */
+ const int16_t element_mode /* i : IVAS element mode */
+)
+{
+ int16_t i;
+ float re[L_FRAME_PLUS / 2];
+ float im[L_FRAME_PLUS / 2];
+ const float *edct_table = 0;
+ float local;
+
+ get_edct_table( &edct_table, length );
+
+ /* Twiddling and Pre-rotate */
+ for ( i = 0; i < length / 2; i++ )
+ {
+ re[i] = x[2 * i] * edct_table[i] + x[length - 1 - 2 * i] * edct_table[length / 2 - 1 - i];
+ im[i] = x[length - 1 - 2 * i] * edct_table[i] - x[2 * i] * edct_table[length / 2 - 1 - i];
+ }
+
+ if ( element_mode == EVS_MONO )
+ {
+ DoFFT( re, im, length / 2 );
+ }
+ else
+ {
+ fft( re, im, length / 2, 1 );
+ }
+
+ local = ( 0.75f * EVS_PI ) / length;
+
+ for ( i = 0; i < length / 2; i++ )
+ {
+ float tmp;
+ tmp = re[i] - im[i] * local; /* 3*pi/(4*length) is a constant */
+ im[i] = im[i] + re[i] * local;
+ re[i] = tmp;
+ }
+
+ /* Post-rotate and obtain the output data */
+ for ( i = 0; i < length / 2; i++ )
+ {
+ y[2 * i] = re[i] * edct_table[i] + im[i] * edct_table[length / 2 - 1 - i];
+ y[length - 1 - 2 * i] = re[i] * edct_table[length / 2 - 1 - i] - im[i] * edct_table[i];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------*
+ * edst()
+ *
+ * DST-IV transform
+ *-------------------------------------------------------------------------*/
+
+void edst(
+ const float *x, /* i : input signal */
+ float *y, /* o : output transform */
+ const int16_t length, /* i : length */
+ const int16_t element_mode /* i : IVAS element mode */
+)
+{
+ int16_t i;
+ float re[L_FRAME_PLUS / 2];
+ float im[L_FRAME_PLUS / 2];
+ const float *edct_table = 0;
+ float local;
+
+ get_edct_table( &edct_table, length );
+
+ /* Twiddling and Pre-rotate */
+ for ( i = 0; i < length / 2; i++ )
+ {
+ re[i] = x[length - 1 - 2 * i] * edct_table[i] + x[2 * i] * edct_table[length / 2 - 1 - i];
+ im[i] = x[2 * i] * edct_table[i] - x[length - 1 - 2 * i] * edct_table[length / 2 - 1 - i];
+ }
+
+ if ( element_mode == EVS_MONO )
+ {
+ DoFFT( re, im, length / 2 );
+ }
+ else
+ {
+ fft( re, im, length / 2, 1 );
+ }
+
+ local = ( 0.75f * EVS_PI ) / length;
+
+ for ( i = 0; i < length / 2; i++ )
+ {
+ float tmp;
+ tmp = re[i] - im[i] * local; /* 3*pi/(4*length) is a constant */
+ im[i] = im[i] + re[i] * local;
+ re[i] = tmp;
+ }
+
+ /* Post-rotate and obtain the output data */
+ for ( i = 0; i < length / 2; i++ )
+ {
+ y[2 * i] = re[i] * edct_table[i] + im[i] * edct_table[length / 2 - 1 - i];
+ y[length - 1 - 2 * i] = im[i] * edct_table[i] - re[i] * edct_table[length / 2 - 1 - i];
+ }
+
+ return;
+}
+
+#define FAST_EDXT /* optimized FFT-based DCT/DST algorithm */
+
+/*-------------------------------------------------------------------------*
+ * edxt()
+ *
+ * DCT/DST-II or III transform (currently also calculates DCT-IV and DST-IV)
+ *-------------------------------------------------------------------------*/
+
+void edxt(
+ const float *x, /* i : input signal */
+ float *y, /* o : output transform */
+ const int16_t length, /* i : length */
+ const uint16_t kernelType, /* i : kernel type (0 - 3) */
+ const uint16_t synthesis /* i : nonzero for inverse */
+)
+{
+ const float pi_len = EVS_PI / length;
+ int16_t k, m;
+
+#ifdef FAST_EDXT
+ if ( kernelType == MDST_II || kernelType == MDCT_II )
+ {
+ const int16_t Nm1 = length - 1;
+ const float xSign = 2.f * ( kernelType >> 1 ) - 1.f;
+ const float scale = 0.5f * pi_len;
+ float re[L_FRAME_PLUS];
+ float im[L_FRAME_PLUS];
+
+ if ( !synthesis )
+ {
+ for ( k = Nm1 >> 1; k >= 0; k-- ) /* pre-modulation of audio input */
+ {
+ re[k] = x[2 * k];
+ re[Nm1 - k] = x[2 * k + 1] * xSign;
+ im[k] = im[Nm1 - k] = 0.f;
+ }
+
+ if ( length == 512 )
+ {
+ DoRTFTn( re, im, 512 );
+ }
+ else /* fft() doesn't support 512 */
+ {
+ fft( re, im, length, 1 );
+ }
+
+ if ( kernelType >> 1 )
+ {
+ for ( k = Nm1 >> 1; k > 0; k-- )
+ {
+ const float wRe = cosf( scale * k );
+ const float wIm = sinf( scale * k );
+
+ y[k] /*pt 1*/ = wRe * re[k] + wIm * im[k];
+ y[length - k] = wIm * re[k] - wRe * im[k];
+ }
+ y[length >> 1] = re[length >> 1] * sqrtf( 0.5f );
+ }
+ else /* forw. DST-II */
+ {
+ for ( k = Nm1 >> 1; k > 0; k-- )
+ {
+ const float wRe = cosf( scale * k );
+ const float wIm = sinf( scale * k );
+
+ y[Nm1 - k] = wRe * re[k] + wIm * im[k];
+ y[k - 1] = wIm * re[k] - wRe * im[k];
+ }
+ y[Nm1 >> 1] = re[length >> 1] * sqrtf( 0.5f );
+ }
+
+ y[Nm1 - Nm1 * ( kernelType >> 1 )] = re[0] * 0.5f;
+ }
+ else /* inverse II = III */
+ {
+ if ( kernelType >> 1 )
+ {
+ for ( k = Nm1 >> 1; k > 0; k-- )
+ {
+ const float wRe = cosf( scale * k ) * 0.5f;
+ const float wIm = sinf( scale * k ) * 0.5f;
+
+ re[k] = wRe * x[k] + wIm * x[length - k];
+ im[k] = wRe * x[length - k] - wIm * x[k];
+ }
+ re[length >> 1] = x[length >> 1] * sqrtf( 0.5f );
+ }
+ else /* DST type III */
+ {
+ for ( k = Nm1 >> 1; k > 0; k-- )
+ {
+ const float wRe = cosf( scale * k ) * 0.5f;
+ const float wIm = sinf( scale * k ) * 0.5f;
+
+ re[k] = wRe * x[Nm1 - k] + wIm * x[k - 1];
+ im[k] = wRe * x[k - 1] - wIm * x[Nm1 - k];
+ }
+ re[length >> 1] = x[Nm1 >> 1] * sqrtf( 0.5f );
+ }
+
+ re[0] = x[Nm1 - Nm1 * ( kernelType >> 1 )];
+ im[0] = im[length >> 1] = 0.f;
+ for ( k = Nm1 >> 1; k > 0; k-- )
+ {
+ re[length - k] = re[k];
+ im[length - k] = -im[k];
+ }
+
+ if ( length == 512 )
+ {
+ DoRTFTn( re, im, 512 );
+ }
+ else /* fft() doesn't support 512 */
+ {
+ fft( re, im, length, 1 );
+ }
+
+ for ( k = Nm1 >> 1; k >= 0; k-- ) /* post-modulation of FFT output */
+ {
+ y[2 * k] = re[k];
+ y[2 * k + 1] = re[Nm1 - k] * xSign;
+ }
+ }
+ }
+ else
+#endif
+ if ( kernelType & 1 ) /* DST */
+ {
+ const float offK = ( kernelType == MDST_II && synthesis ? 0.5f : 1.0f - 0.5f * ( kernelType >> 1 ) );
+ const float offM = ( kernelType == MDST_II && synthesis ? 1.0f : 0.5f );
+
+ for ( k = 0; k < length; k++ )
+ {
+ y[k] = 0.f;
+ for ( m = 0; m < length; m++ )
+ {
+ y[k] += x[m] * sinf( pi_len * ( m + offM ) * ( k + offK ) );
+ }
+ }
+ if ( offK == 1.f )
+ {
+ y[length - 1] *= 0.5f; /* scale Nyquist sample */
+ }
+ }
+ else /* kernelType 0, 2: DCT */
+ {
+ const float offK = ( kernelType == MDCT_II && synthesis ? 0.5f : 0.5f - 0.5f * ( kernelType >> 1 ) );
+ const float offM = ( kernelType == MDCT_II && synthesis ? 0.0f : 0.5f );
+
+ for ( k = 0; k < length; k++ )
+ {
+ y[k] = 0.f;
+ for ( m = 0; m < length; m++ )
+ {
+ y[k] += x[m] * cosf( pi_len * ( m + offM ) * ( k + offK ) );
+ }
+ }
+ if ( offK == 0.f )
+ {
+ y[0] *= 0.5f; /* scale lowest (i.e. DC) sample */
+ }
+ }
+
+ v_multc( y, ( kernelType == MDCT_II ? -1.f : 1.f ) * sqrtf( 2.f / length ), y, length );
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * iedct_short()
+ *
+ * Inverse EDCT for short frames
+ *-----------------------------------------------------------------*/
+
+void iedct_short(
+ const float *in, /* i : input vector */
+ float *out, /* o : output vector */
+ const int16_t segment_length, /* i : length */
+ const int16_t element_mode /* i : IVAS element mode */
+)
+{
+ float alias[MAX_SEGMENT_LENGTH];
+ int16_t i;
+
+ edct( in, alias, segment_length / 2, element_mode );
+
+ for ( i = 0; i < segment_length / 4; i++ )
+ {
+ out[i] = alias[segment_length / 4 + i];
+ out[segment_length / 4 + i] = -alias[segment_length / 2 - 1 - i];
+ out[segment_length / 2 + i] = -alias[segment_length / 4 - 1 - i];
+ out[3 * segment_length / 4 + i] = -alias[i];
+ }
+
+ return;
+}
diff --git a/lib_com/enh1632.c b/lib_com/enh1632.c
new file mode 100644
index 0000000000000000000000000000000000000000..1dd192faaa7d9c2d0190c781c3a18af3cdda27db
--- /dev/null
+++ b/lib_com/enh1632.c
@@ -0,0 +1,633 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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.
+
+*******************************************************************************************************/
+
+/*
+ ===========================================================================
+ File: ENH1632.C v.2.3 - 30.Nov.2009
+ ===========================================================================
+
+ ITU-T STL BASIC OPERATORS
+
+ ENHANCED 16-BIT & 32-BIT ARITHMETIC OPERATORS
+
+ History:
+ 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control
+ operators for the ITU-T Standard Tool Library as
+ described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
+ TD 11 document and subsequent discussions on the
+ wp3audio@yahoogroups.com email reflector.
+
+ ============================================================================
+*/
+
+
+/*****************************************************************************
+ *
+ * Enhanced 16/32 bit operators :
+ * s_max()
+ * s_min()
+ * L_max()
+ * L_min()
+ * shl_r()
+ * L_shl_r()
+ * L_mac0()
+ * L_mult0()
+ * L_msu0()
+ * s_and()
+ * s_or()
+ * s_xor()
+ * L_and()
+ * L_or()
+ * lshl()
+ * lshr()
+ * L_lshl()
+ * L_lshr()
+ * rotr()
+ * rotl()
+ * L_rotr()
+ * L_rotl()
+ *
+ *****************************************************************************/
+
+
+/*****************************************************************************
+ *
+ * Include-Files
+ *
+ *****************************************************************************/
+
+#include
+#include
+#include "stl.h"
+
+#define WMC_TOOL_SKIP
+
+/*****************************************************************************
+ *
+ * Constants and Globals
+ *
+ *****************************************************************************/
+
+
+/*****************************************************************************
+ *
+ * Functions
+ *
+ *****************************************************************************/
+
+
+/*****************************************************************************
+ *
+ * Function Name : lshl
+ *
+ * Purpose :
+ *
+ * Logically shifts left var1 by var2 positions.
+ * - If var2 is negative, var1 is shifted to the LSBits by (-var2)
+ * positions with insertion of 0 at the MSBit.
+ * - If var2 is positive, var1 is shifted to the MSBits by (var2)
+ * positions.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value falls in
+ * the range 0xffff 8000 <= var1 <= 0x0000 7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value:
+ *
+ * var_out 16 bit short signed integer (Word16) whose value falls in
+ * the range 0xffff 8000 <= var_out <= 0x0000 7fff.
+ *
+ *****************************************************************************/
+Word16 lshl( Word16 var1, Word16 var2 )
+{
+ Word16 var_out = 0;
+
+ if ( var2 < 0 )
+ {
+ var2 = -var2;
+ var_out = lshr( var1, var2 );
+ }
+ else
+ {
+ if ( var2 == 0 || var1 == 0 )
+ {
+ var_out = var1;
+ }
+ else if ( var2 >= 16 )
+ {
+ var_out = 0;
+ }
+ else
+ {
+ var_out = var1 << var2;
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+/*****************************************************************************
+ *
+ * Function Name : lshr
+ *
+ * Purpose :
+ *
+ * Logically shifts right var1 by var2 positions.
+ * - If var2 is positive, var1 is shifted to the LSBits by (var2)
+ * positions with insertion of 0 at the MSBit.
+ * - If var2 is negative, var1 is shifted to the MSBits by (-var2)
+ * positions.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value falls in
+ * the range 0xffff 8000 <= var1 <= 0x0000 7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value:
+ *
+ * var_out 16 bit short signed integer (Word16) whose value falls in
+ * the range 0xffff 8000 <= var_out <= 0x0000 7fff.
+ *
+ *****************************************************************************/
+Word16 lshr( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ if ( var2 < 0 )
+ {
+ var2 = -var2;
+ var_out = lshl( var1, var2 );
+ }
+ else
+ {
+ if ( var2 == 0 || var1 == 0 )
+ {
+ var_out = var1;
+ }
+ else if ( var2 >= 16 )
+ {
+ var_out = 0;
+ }
+ else
+ {
+ var_out = var1 >> 1;
+ var_out = var_out & 0x7fff;
+ var_out = var_out >> ( var2 - 1 );
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_lshl
+ *
+ * Purpose :
+ *
+ * Logically shifts left L_var1 by var2 positions.
+ * - If var2 is negative, L_var1 is shifted to the LSBits by (-var2)
+ * positions with insertion of 0 at the MSBit.
+ * - If var2 is positive, L_var1 is shifted to the MSBits by (var2)
+ * positions.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in
+ * the range 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value:
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value falls in
+ * the range 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+Word32 L_lshl( Word32 L_var1, Word16 var2 )
+{
+ Word32 L_var_out = 0;
+
+ if ( var2 < 0 )
+ {
+ var2 = -var2;
+ L_var_out = L_lshr( L_var1, var2 );
+ }
+ else
+ {
+ if ( var2 == 0 || L_var1 == 0 )
+ {
+ L_var_out = L_var1;
+ }
+ else if ( var2 >= 32 )
+ {
+ L_var_out = 0;
+ }
+ else
+ {
+ L_var_out = L_var1 << var2;
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_lshr
+ *
+ * Purpose :
+ *
+ * Logically shifts right L_var1 by var2 positions.
+ * - If var2 is positive, L_var1 is shifted to the LSBits by (var2)
+ * positions with insertion of 0 at the MSBit.
+ * - If var2 is negative, L_var1 is shifted to the MSBits by (-var2)
+ * positions.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in
+ * the range 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value:
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value falls in
+ * the range 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+Word32 L_lshr( Word32 L_var1, Word16 var2 )
+{
+ Word32 L_var_out;
+
+ if ( var2 < 0 )
+ {
+ var2 = -var2;
+ L_var_out = L_lshl( L_var1, var2 );
+ }
+ else
+ {
+ if ( var2 == 0 || L_var1 == 0 )
+ {
+ L_var_out = L_var1;
+ }
+ else if ( var2 >= 32 )
+ {
+ L_var_out = 0;
+ }
+ else
+ {
+ L_var_out = L_var1 >> 1;
+ L_var_out = L_var_out & 0x7fffffff;
+ L_var_out = L_var_out >> ( var2 - 1 );
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : shl_r
+ *
+ * Purpose :
+ *
+ * Identical to shl( var1, var2) but with rounding. Saturates the result
+ * in case of underflows or overflows.
+ *
+ * Complexity weight : 3
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+ *
+ *****************************************************************************/
+Word16 shl_r( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ if ( var2 >= 0 )
+ {
+ var_out = shl( var1, var2 );
+ }
+ else
+ {
+ var2 = -var2;
+ var_out = shr_r( var1, var2 );
+ }
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_shl_r
+ *
+ * Purpose :
+ *
+ * Same as L_shl( var1, var2) but with rounding. Saturates the result in
+ * case of underflows or overflows.
+ *
+ * Complexity weight : 3
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+Word32 L_shl_r( Word32 L_var1, Word16 var2 )
+{
+ Word32 var_out;
+
+ if ( var2 >= 0 )
+ {
+ var_out = L_shl( L_var1, var2 );
+ }
+ else
+ {
+ var2 = -var2;
+ var_out = L_shr_r( L_var1, var2 );
+ }
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : rotr
+ *
+ * Purpose :
+ *
+ * Performs a 16-bit logical rotation of var1 by 1 bit to the LSBits. The
+ * MSBit is set to var2 bit 0. The LSBit of var1 is kept in *var3 bit 0.
+ *
+ * Complexity weight : 3
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value must be 0
+ * or 1.
+ *
+ * Outputs :
+ *
+ * *var3 Points on a 16 bit short signed integer (Word16) whose
+ * value will be 0 or 1.
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+ *
+ *****************************************************************************/
+Word16 rotr( Word16 var1, Word16 var2, Word16 *var3 )
+{
+ Word16 var_out;
+
+ *var3 = s_and( var1, 0x1 );
+ var_out = s_or( lshr( var1, 1 ), lshl( var2, 15 ) );
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : rotl
+ *
+ * Purpose :
+ *
+ * Performs a 16-bit logical rotation of var1 by 1 bit to the MSBits. The
+ * LSBit is set to var2 bit 0. The MSBit of var1 is kept in *var3 bit 0.
+ *
+ * Complexity weight : 3
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value must be 0
+ * or 1.
+ *
+ * Outputs :
+ *
+ * *var3 Points on a 16 bit short signed integer (Word16) whose
+ * value will be 0 or 1.
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+ *
+ *****************************************************************************/
+Word16 rotl( Word16 var1, Word16 var2, Word16 *var3 )
+{
+ Word16 var_out;
+
+ *var3 = lshr( var1, 15 );
+
+ var_out = s_or( lshl( var1, 1 ), s_and( var2, 0x1 ) );
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_rotr
+ *
+ * Purpose :
+ *
+ * Performs a 32-bit logical rotation of L_var1 by 1 bit to the LSBits. The
+ * MSBit is set to var2 bit 0. The LSBit of L_var1 is kept in *var3 bit 0.
+ *
+ * Complexity weight : 3
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value must be 0
+ * or 1.
+ *
+ * Outputs :
+ *
+ * *var3 Points on a 16 bit short signed integer (Word16) whose
+ * value will be 0 or 1.
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+Word32 L_rotr( Word32 L_var1, Word16 var2, Word16 *var3 )
+{
+ Word32 L_var_out;
+
+ *var3 = s_and( extract_l( L_var1 ), 0x1 );
+
+ L_var_out = L_or( L_lshr( L_var1, 1 ), L_lshl( L_deposit_l( var2 ), 31 ) );
+
+
+ return ( L_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_rotl
+ *
+ * Purpose :
+ *
+ * Performs a 32-bit logical rotation of L_var1 by 1 bit to the MSBits. The
+ * LSBit is set to var2 bit 0. The MSBit of L_var1 is kept in *var3 bit 0.
+ *
+ * Complexity weight : 3
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value must be 0
+ * or 1.
+ *
+ * Outputs :
+ *
+ * *var3 Points on a 16 bit short signed integer (Word16) whose
+ * value will be 0 or 1.
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+Word32 L_rotl( Word32 L_var1, Word16 var2, Word16 *var3 )
+{
+ Word32 L_var_out;
+
+ *var3 = extract_l( L_lshr( L_var1, 31 ) );
+
+ L_var_out = L_or( L_lshl( L_var1, 1 ), L_deposit_l( s_and( var2, 0x1 ) ) );
+
+
+ return ( L_var_out );
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/enh1632.h b/lib_com/enh1632.h
new file mode 100644
index 0000000000000000000000000000000000000000..9216ea6c201a3b63690723318b65ea19367445c2
--- /dev/null
+++ b/lib_com/enh1632.h
@@ -0,0 +1,508 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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.
+
+*******************************************************************************************************/
+
+/*
+ ===========================================================================
+ File: ENH1632.H v.2.3 - 30.Nov.2009
+ ===========================================================================
+
+ ITU-T STL BASIC OPERATORS
+
+ ENHANCED 16-BIT & 32-BIT ARITHMETIC OPERATORS
+
+ History:
+ 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control
+ operators for the ITU-T Standard Tool Library as
+ described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
+ TD 11 document and subsequent discussions on the
+ wp3audio@yahoogroups.com email reflector.
+ March 06 v2.1 Changed to improve portability.
+ Some counters incrementations were missing (s_and,
+ s_or, s_xor).
+ 30 Nov 09 v2.3 saturate() removed
+
+ ============================================================================
+*/
+
+
+#ifndef _ENH1632_H
+#define _ENH1632_H
+
+
+/*****************************************************************************
+ *
+ * Constants and Globals
+ *
+ *****************************************************************************/
+
+
+#include "stl.h"
+
+
+/*****************************************************************************
+ *
+ * Prototypes for enhanced 16/32 bit arithmetic operators
+ *
+ *****************************************************************************/
+Word16 shl_r( Word16 var1, Word16 var2 );
+Word32 L_shl_r( Word32 L_var1, Word16 var2 );
+
+
+Word16 lshl( Word16 var1, Word16 var2 );
+Word16 lshr( Word16 var1, Word16 var2 );
+Word32 L_lshl( Word32 L_var1, Word16 var2 );
+Word32 L_lshr( Word32 L_var1, Word16 var2 );
+
+Word16 rotr( Word16 var1, Word16 var2, Word16 *var3 );
+Word16 rotl( Word16 var1, Word16 var2, Word16 *var3 );
+Word32 L_rotr( Word32 var1, Word16 var2, Word16 *var3 );
+Word32 L_rotl( Word32 var1, Word16 var2, Word16 *var3 );
+
+
+/*****************************************************************************
+ *
+ * Functions
+ *
+ *****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Function Name : s_max
+ *
+ * Purpose :
+ *
+ * Compares var1 and var2 and returns the maximum value.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0x8000 <= var1 <= 0x7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0x8000 <= var2 <= 0x7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0x8000 <= L_var_out <= 0x7fff.
+ *
+ *****************************************************************************/
+static __inline Word16 s_max( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ if ( var1 >= var2 )
+ var_out = var1;
+ else
+ var_out = var2;
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : s_min
+ *
+ * Purpose :
+ *
+ * Compares var1 and var2 and returns the minimum value.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0x8000 <= var1 <= 0x7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0x8000 <= var2 <= 0x7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0x8000 <= var_out <= 0x7fff.
+ *
+ *****************************************************************************/
+static __inline Word16 s_min( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ if ( var1 <= var2 )
+ var_out = var1;
+ else
+ var_out = var2;
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_max
+ *
+ * Purpose :
+ *
+ * Compares L_var1 and L_var2 and returns the maximum value.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in the
+ * range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * L_var2 32 bit long signed integer (Word32) whose value falls in the
+ * range : 0x8000 0000 <= L_var2 <= 0x7fff ffff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value falls in the
+ * range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+static __inline Word32 L_max( Word32 L_var1, Word32 L_var2 )
+{
+ Word32 L_var_out;
+
+ if ( L_var1 >= L_var2 )
+ L_var_out = L_var1;
+ else
+ L_var_out = L_var2;
+
+
+ return ( L_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_min
+ *
+ * Purpose :
+ *
+ * Compares L_var1 and L_var2 and returns the minimum value.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in the
+ * range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * L_var2 32 bit long signed integer (Word32) whose value falls in the
+ * range : 0x8000 0000 <= L_var2 <= 0x7fff ffff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value falls in the
+ * range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+static __inline Word32 L_min( Word32 L_var1, Word32 L_var2 )
+{
+ Word32 L_var_out;
+
+ if ( L_var1 <= L_var2 )
+ L_var_out = L_var1;
+ else
+ L_var_out = L_var2;
+
+
+ return ( L_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : s_and
+ *
+ * Purpose :
+ *
+ * Performs logical AND of the two 16 bit input variables.
+ * var_out = var1 & var2
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff.
+ *
+ *****************************************************************************/
+static __inline Word16 s_and( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ var_out = var1 & var2;
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_and
+ *
+ * Purpose :
+ *
+ * Performs logical AND of the two 32 bit input variables.
+ * L_var_out = L_var1 & L_var2
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * L_var2 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var2 <= 0x7fff ffff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+static __inline Word32 L_and( Word32 L_var1, Word32 L_var2 )
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1 & L_var2;
+
+
+ return ( L_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : s_or
+ *
+ * Purpose :
+ *
+ * Performs logical OR of the two 16 bit input variables.
+ * var_out = var1 | var2
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff.
+ *
+ *****************************************************************************/
+static __inline Word16 s_or( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ var_out = var1 | var2;
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_or
+ *
+ * Purpose :
+ *
+ * Performs logical OR of the two 32 bit input variables.
+ * L_var_out = L_var1 | L_var2
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * L_var2 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var2 <= 0x7fff ffff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+static __inline Word32 L_or( Word32 L_var1, Word32 L_var2 )
+{
+
+ Word32 L_var_out;
+
+ L_var_out = L_var1 | L_var2;
+
+
+ return ( L_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : s_xor
+ *
+ * Purpose :
+ *
+ * Performs logical XOR of the two 16 bit input variables.
+ * var_out = var1 ^ var2
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * var1 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value
+ * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff.
+ *
+ *****************************************************************************/
+static __inline Word16 s_xor( Word16 var1, Word16 var2 )
+{
+ Word16 var_out;
+
+ var_out = var1 ^ var2;
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_xor
+ *
+ * Purpose :
+ *
+ * Performs logical OR of the two 32 bit input variables.
+ * L_var_out = L_var1 ^ L_var2
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * L_var2 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var2 <= 0x7fff ffff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value
+ * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+static __inline Word32 L_xor( Word32 L_var1, Word32 L_var2 )
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1 ^ L_var2;
+
+
+ return ( L_var_out );
+}
+
+
+#endif /*_ENH1632_H*/
+
+/* end of file */
diff --git a/lib_com/enh40.c b/lib_com/enh40.c
new file mode 100644
index 0000000000000000000000000000000000000000..8a48cece39bed8b7e709fedb9bd8c9b40c5354a0
--- /dev/null
+++ b/lib_com/enh40.c
@@ -0,0 +1,1309 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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.
+
+*******************************************************************************************************/
+
+/*
+ ===========================================================================
+ File: ENH40.C v.2.3 - 30.Nov.2009
+ ===========================================================================
+
+ ITU-T STL BASIC OPERATORS
+
+ 40-BIT ARITHMETIC OPERATORS
+
+ History:
+ 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control
+ operators for the ITU-T Standard Tool Library as
+ described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
+ TD 11 document and subsequent discussions on the
+ wp3audio@yahoogroups.com email reflector.
+
+ ============================================================================
+*/
+
+
+/*****************************************************************************
+ *
+ * Enhanced 40 bit operators :
+ *
+ * L40_add()
+ * L40_sub()
+ * L40_abs()
+ * L40_negate()
+ * L40_max()
+ * L40_min()
+ * L40_shr()
+ * L40_shr_r()
+ * L40_shl()
+ * L40_shl_r()
+ * norm_L40()
+ * L40_mult()
+ * L40_mac()
+ * L40_msu()
+ * mac_r40()
+ * msu_r40()
+ * Mpy_32_16_ss()
+ * Mpy_32_32_ss()
+ * L40_lshl()
+ * L40_lshr()
+ * L40_round()
+ * L_saturate40()
+ * L40_set()
+ * Extract40_H()
+ * Extract40_L()
+ * L_Extract40()
+ * L40_deposit_h()
+ * L40_deposit_l()
+ * L40_deposit32()
+ *
+ *****************************************************************************/
+
+
+/*****************************************************************************
+ *
+ * Include-Files
+ *
+ *****************************************************************************/
+
+#include
+#include
+#include "stl.h"
+#ifdef BASOP_NOGLOB
+#include
+#endif /* BASOP_NOGLOB */
+
+#define WMC_TOOL_SKIP
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4310 )
+#endif
+
+/*****************************************************************************
+ *
+ * Local Functions
+ *
+ *****************************************************************************/
+
+
+/*****************************************************************************
+ *
+ * Constants and Globals
+ *
+ *****************************************************************************/
+
+
+/*****************************************************************************
+ *
+ * Functions
+ *
+ *****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Function Name : L40_shl
+ *
+ * Purpose :
+ *
+ * Arithmetically shifts left L40_var1 by var2 positions.
+ * - If var2 is negative, L40_var1 is shifted to the LSBits by (-var2)
+ * positions with extension of the sign bit.
+ * - If var2 is positive, L40_var1 is shifted to the MSBits by (var2)
+ * positions.
+ * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit.
+ * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : MIN_16 <= var2 <= MAX_16.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+#ifndef BASOP_NOGLOB
+Word40 L40_shl( Word40 L40_var1, Word16 var2 )
+#else /* BASOP_NOGLOB */
+Word40 L40_shl_o( Word40 L40_var1, Word16 var2, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+
+ Word40 L40_var_out;
+ Word40 L40_constant;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ L40_constant = L40_set( 0xc000000000 );
+#else
+ L40_constant = L40_set( 0xc000000000LL );
+#endif
+
+ if ( var2 < 0 )
+ {
+ var2 = -var2;
+ L40_var_out = L40_shr( L40_var1, var2 );
+ }
+
+ else
+ {
+ L40_var_out = L40_var1;
+
+ for ( ; var2 > 0; var2-- )
+ {
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( L40_var_out > 0x003fffffffff )
+#else
+ if ( L40_var_out > 0x003fffffffffLL )
+#endif
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 1 );
+ /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+ L40_var_out = MAX_40;
+#endif /* BASOP_NOGLOB */
+ break;
+ }
+
+ else if ( L40_var_out < L40_constant )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 2 );
+ /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+ L40_var_out = MIN_40;
+#endif /* BASOP_NOGLOB */
+ break;
+ }
+
+ else
+ {
+ L40_var_out = L40_var_out << 1;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+
+#ifdef BASOP_NOGLOB
+Word40 L40_shl( Word40 L40_var1, Word16 var2 )
+{
+
+ Word40 L40_var_out;
+ Word40 L40_constant;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ L40_constant = L40_set( 0xc000000000 );
+#else
+ L40_constant = L40_set( 0xc000000000LL );
+#endif
+
+ if ( var2 < 0 )
+ {
+ var2 = -var2;
+ L40_var_out = L40_shr( L40_var1, var2 );
+ }
+
+ else
+ {
+ L40_var_out = L40_var1;
+
+ for ( ; var2 > 0; var2-- )
+ {
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( L40_var_out > 0x003fffffffff )
+#else
+ if ( L40_var_out > 0x003fffffffffLL )
+#endif
+ {
+ assert( 0 );
+ L40_var_out = MAX_40;
+ break;
+ }
+
+ else if ( L40_var_out < L40_constant )
+ {
+ assert( 0 );
+ L40_var_out = MIN_40;
+ break;
+ }
+
+ else
+ {
+ L40_var_out = L40_var_out << 1;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*****************************************************************************
+ *
+ * Function Name : L40_shr
+ *
+ * Purpose :
+ *
+ * Arithmetically shifts right L40_var1 by var2 positions.
+ * - If var2 is positive, L40_var1 is shifted to the LSBits by (var2)
+ * positions with extension of the sign bit.
+ * - If var2 is negative, L40_var1 is shifted to the MSBits by (-var2)
+ * positions.
+ * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit.
+ * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : MIN_16 <= var2 <= MAX_16.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_shr( Word40 L40_var1, Word16 var2 )
+{
+ Word40 L40_var_out;
+
+ if ( var2 < 0 )
+ {
+ var2 = -var2;
+ L40_var_out = L40_shl( L40_var1, var2 );
+ }
+ else
+ {
+ L40_var_out = L40_var1 >> var2;
+ }
+
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_negate
+ *
+ * Purpose :
+ *
+ * Negates L40_var1.
+ * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit.
+ * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_negate( Word40 L40_var1 )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = L40_add( ~L40_var1, 0x01 );
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_add
+ *
+ * Purpose :
+ *
+ * Adds L40_var1 and L40_var2 and returns the 40-bit result.
+ * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit.
+ * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * L40_var2 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var2 <= MAX_40.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+#ifdef BASOP_NOGLOB
+
+Word40 L40_add_o( Word40 L40_var1, Word40 L40_var2, Flag *Overflow )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = L40_var1 + L40_var2;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( ( ( ( L40_var1 & 0x8000000000 ) >> 39 ) != 0 ) && ( ( ( L40_var2 & 0x8000000000 ) >> 39 ) != 0 ) && ( ( ( L40_var_out & 0x8000000000 ) >> 39 ) == 0 ) )
+ {
+ *Overflow = 1;
+ L40_var_out = MIN_40;
+ }
+ else if ( ( ( ( L40_var1 & 0x8000000000 ) >> 39 ) == 0 ) && ( ( ( L40_var2 & 0x8000000000 ) >> 39 ) == 0 ) && ( ( ( L40_var_out & 0x8000000000 ) >> 39 ) != 0 ) )
+ {
+ *Overflow = 1;
+ L40_var_out = MAX_40;
+ }
+#else
+ if ( ( ( ( L40_var1 & 0x8000000000LL ) >> 39 ) != 0 ) && ( ( ( L40_var2 & 0x8000000000LL ) >> 39 ) != 0 ) && ( ( ( L40_var_out & 0x8000000000LL ) >> 39 ) == 0 ) )
+ {
+ *Overflow = 1;
+ L40_var_out = MIN_40;
+ }
+ else if ( ( ( ( L40_var1 & 0x8000000000LL ) >> 39 ) == 0 ) && ( ( ( L40_var2 & 0x8000000000LL ) >> 39 ) == 0 ) && ( ( ( L40_var_out & 0x8000000000LL ) >> 39 ) != 0 ) )
+ {
+ *Overflow = 1;
+ L40_var_out = MAX_40;
+ }
+#endif
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+
+#endif /* BASOP_NOGLOB */
+Word40 L40_add( Word40 L40_var1, Word40 L40_var2 )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = L40_var1 + L40_var2;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( ( ( ( L40_var1 & 0x8000000000 ) >> 39 ) != 0 ) && ( ( ( L40_var2 & 0x8000000000 ) >> 39 ) != 0 ) && ( ( ( L40_var_out & 0x8000000000 ) >> 39 ) == 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 2 );
+ /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ assert( 0 );
+ L40_var_out = MIN_40;
+#endif /* BASOP_NOGLOB */
+ }
+ else if ( ( ( ( L40_var1 & 0x8000000000 ) >> 39 ) == 0 ) && ( ( ( L40_var2 & 0x8000000000 ) >> 39 ) == 0 ) && ( ( ( L40_var_out & 0x8000000000 ) >> 39 ) != 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 1 );
+ /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ assert( 0 );
+ L40_var_out = MAX_40;
+#endif /* BASOP_NOGLOB */
+ }
+#else
+ if ( ( ( ( L40_var1 & 0x8000000000LL ) >> 39 ) != 0 ) && ( ( ( L40_var2 & 0x8000000000LL ) >> 39 ) != 0 ) && ( ( ( L40_var_out & 0x8000000000LL ) >> 39 ) == 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 2 );
+ /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ assert( 0 );
+ L40_var_out = MIN_40;
+#endif /* BASOP_NOGLOB */
+ }
+ else if ( ( ( ( L40_var1 & 0x8000000000LL ) >> 39 ) == 0 ) && ( ( ( L40_var2 & 0x8000000000LL ) >> 39 ) == 0 ) && ( ( ( L40_var_out & 0x8000000000LL ) >> 39 ) != 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 1 );
+ /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ assert( 0 );
+ L40_var_out = MAX_40;
+#endif /* BASOP_NOGLOB */
+ }
+#endif
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_sub
+ *
+ * Purpose :
+ *
+ * Subtracts L40_var2 from L40_var1.
+ * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit.
+ * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * L40_var2 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var2 <= MAX_40.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+#ifndef BASOP_NOGLOB
+Word40 L40_sub( Word40 L40_var1, Word40 L40_var2 )
+#else /* BASOP_NOGLOB */
+Word40 L40_sub_o( Word40 L40_var1, Word40 L40_var2, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+ Word40 L40_var_out;
+
+ L40_var_out = L40_var1 - L40_var2;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( ( ( ( L40_var1 & 0x8000000000 ) >> 39 ) != 0 ) && ( ( ( L40_var2 & 0x8000000000 ) >> 39 ) == 0 ) && ( ( ( L40_var_out & 0x8000000000 ) >> 39 ) == 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 2 );
+ /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+ L40_var_out = MIN_40;
+#endif /* BASOP_NOGLOB */
+ }
+ else if ( ( ( ( L40_var1 & 0x8000000000 ) >> 39 ) == 0 ) && ( ( ( L40_var2 & 0x8000000000 ) >> 39 ) != 0 ) && ( ( ( L40_var_out & 0x8000000000 ) >> 39 ) != 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 1 );
+ /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+ L40_var_out = MAX_40;
+#endif /* BASOP_NOGLOB */
+ }
+#else
+ if ( ( ( ( L40_var1 & 0x8000000000LL ) >> 39 ) != 0 ) && ( ( ( L40_var2 & 0x8000000000LL ) >> 39 ) == 0 ) && ( ( ( L40_var_out & 0x8000000000LL ) >> 39 ) == 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 2 );
+ /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+ L40_var_out = MIN_40;
+#endif /* BASOP_NOGLOB */
+ }
+ else if ( ( ( ( L40_var1 & 0x8000000000LL ) >> 39 ) == 0 ) && ( ( ( L40_var2 & 0x8000000000LL ) >> 39 ) != 0 ) && ( ( ( L40_var_out & 0x8000000000LL ) >> 39 ) != 0 ) )
+ {
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+ exit( 1 );
+ /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+ L40_var_out = MAX_40;
+#endif /* BASOP_NOGLOB */
+ }
+#endif
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+
+#ifdef BASOP_NOGLOB
+Word40 L40_sub( Word40 L40_var1, Word40 L40_var2 )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = L40_var1 - L40_var2;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( ( ( ( L40_var1 & 0x8000000000 ) >> 39 ) != 0 ) && ( ( ( L40_var2 & 0x8000000000 ) >> 39 ) == 0 ) && ( ( ( L40_var_out & 0x8000000000 ) >> 39 ) == 0 ) )
+ {
+ assert( 0 );
+ L40_var_out = MIN_40;
+ }
+ else if ( ( ( ( L40_var1 & 0x8000000000 ) >> 39 ) == 0 ) && ( ( ( L40_var2 & 0x8000000000 ) >> 39 ) != 0 ) && ( ( ( L40_var_out & 0x8000000000 ) >> 39 ) != 0 ) )
+ {
+ assert( 0 );
+ L40_var_out = MAX_40;
+ }
+#else
+ if ( ( ( ( L40_var1 & 0x8000000000LL ) >> 39 ) != 0 ) && ( ( ( L40_var2 & 0x8000000000LL ) >> 39 ) == 0 ) && ( ( ( L40_var_out & 0x8000000000LL ) >> 39 ) == 0 ) )
+ {
+ assert( 0 );
+ L40_var_out = MIN_40;
+ }
+ else if ( ( ( ( L40_var1 & 0x8000000000LL ) >> 39 ) == 0 ) && ( ( ( L40_var2 & 0x8000000000LL ) >> 39 ) != 0 ) && ( ( ( L40_var_out & 0x8000000000LL ) >> 39 ) != 0 ) )
+ {
+ assert( 0 );
+ L40_var_out = MAX_40;
+ }
+#endif
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*****************************************************************************
+ *
+ * Function Name : L40_abs
+ *
+ * Purpose :
+ *
+ * Returns the absolute value of L40_var1.
+ * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit.
+ * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : 0x00 0000 0000 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_abs( Word40 L40_var1 )
+{
+ Word40 L40_var_out;
+
+ if ( L40_var1 < 0 )
+ {
+ L40_var_out = L40_negate( L40_var1 );
+ }
+ else
+ {
+ L40_var_out = L40_var1;
+ }
+
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_max
+ *
+ * Purpose :
+ *
+ * Compares L40_var1 and L40_var2 and returns the maximum value.
+ *
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * L40_var2 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var2 <= MAX_40.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_max( Word40 L40_var1, Word40 L40_var2 )
+{
+ Word40 L40_var_out;
+
+ if ( L40_var1 < L40_var2 )
+ L40_var_out = L40_var2;
+ else
+ L40_var_out = L40_var1;
+
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_min
+ *
+ * Purpose :
+ *
+ * Compares L40_var1 and L40_var2 and returns the minimum value.
+ *
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * L40_var2 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var2 <= MAX_40.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_min( Word40 L40_var1, Word40 L40_var2 )
+{
+ Word40 L40_var_out;
+
+ if ( L40_var1 < L40_var2 )
+ L40_var_out = L40_var1;
+ else
+ L40_var_out = L40_var2;
+
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L_saturate40
+ *
+ * Purpose :
+ *
+ * If L40_var1 is greater than MAX_32, returns MAX_32.
+ * If L40_var1 is lower than MIN_32, returns MIN_32.
+ * If not, returns L_Extract40( L40_var1).
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L_var_out 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+ *
+ *****************************************************************************/
+#ifndef BASOP_NOGLOB
+Word32 L_saturate40( Word40 L40_var1 )
+#else /* BASOP_NOGLOB */
+
+Word32 L_saturate40_o( Word40 L40_var1, Flag *Overflow )
+#endif /* BASOP_NOGLOB */
+{
+ Word32 L_var_out;
+
+ Word40 UNDER_L40_var2 = ( Word40 ) ~( ( ( (Word40) 1 ) << 31 ) - (Word40) 1 );
+ Word40 OVER_L40_var2 = (Word40) ( ( ( (Word40) 1 ) << 31 ) - (Word40) 1 );
+
+ if ( L40_var1 < UNDER_L40_var2 )
+ {
+ L40_var1 = UNDER_L40_var2;
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ }
+
+ if ( L40_var1 > OVER_L40_var2 )
+ {
+ L40_var1 = OVER_L40_var2;
+#ifndef BASOP_NOGLOB
+ Overflow = 1;
+#else /* BASOP_NOGLOB */
+ *Overflow = 1;
+#endif /* BASOP_NOGLOB */
+ }
+
+ L_var_out = L_Extract40( L40_var1 );
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+
+#ifdef BASOP_NOGLOB
+Word32 L_saturate40( Word40 L40_var1 )
+{
+ Word32 L_var_out;
+
+ Word40 UNDER_L40_var2 = ( Word40 ) ~( ( ( (Word40) 1 ) << 31 ) - (Word40) 1 );
+ Word40 OVER_L40_var2 = (Word40) ( ( ( (Word40) 1 ) << 31 ) - (Word40) 1 );
+
+ if ( L40_var1 < UNDER_L40_var2 )
+ {
+ L40_var1 = UNDER_L40_var2;
+ assert( 0 );
+ }
+
+ if ( L40_var1 > OVER_L40_var2 )
+ {
+ L40_var1 = OVER_L40_var2;
+ assert( 0 );
+ }
+
+ L_var_out = L_Extract40( L40_var1 );
+
+ BASOP_CHECK();
+
+
+ return ( L_var_out );
+}
+#endif /* BASOP_NOGLOB */
+
+/*****************************************************************************
+ *
+ * Function Name : Mpy_32_16_ss
+ *
+ * Purpose :
+ *
+ * Multiplies the 2 signed values L_var1 and var2 with saturation control
+ * on 48-bit. The operation is performed in fractional mode :
+ * - L_var1 is supposed to be in 1Q31 format.
+ * - var2 is supposed to be in 1Q15 format.
+ * - The result is produced in 1Q47 format : L_varout_h points to the
+ * 32 MSBits while varout_l points to the 16 LSBits.
+ *
+ * Complexity weight : 2
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * *L_varout_h 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_varout_h <= 0x7fff ffff.
+ *
+ * *varout_l 16 bit short unsigned integer (UWord16) whose value falls in
+ * the range : 0x0000 0000 <= varout_l <= 0x0000 ffff.
+ *
+ * Return Value :
+ *
+ * none
+ *
+ *****************************************************************************/
+void Mpy_32_16_ss( Word32 L_var1, Word16 var2, Word32 *L_varout_h, UWord16 *varout_l )
+{
+ Word16 var1_h;
+ UWord16 uvar1_l;
+ Word40 L40_var1;
+
+ if ( ( L_var1 == (Word32) 0x80000000 ) && ( var2 == (Word16) 0x8000 ) )
+ {
+ *L_varout_h = 0x7fffffff;
+ *varout_l = (UWord16) 0xffff;
+ }
+ else
+ {
+ uvar1_l = extract_l( L_var1 );
+ var1_h = extract_h( L_var1 );
+
+ /* Below line can not overflow, so we can use << instead of L40_shl. */
+ L40_var1 = ( (Word40) ( (Word32) var2 * (Word32) uvar1_l ) ) << 1;
+
+ *varout_l = Extract40_L( L40_var1 );
+
+ L40_var1 = L40_shr( L40_var1, 16 );
+ L40_var1 = L40_mac( L40_var1, var2, var1_h );
+
+ *L_varout_h = L_Extract40( L40_var1 );
+ }
+
+
+ return;
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : Mpy_32_32_ss
+ *
+ * Purpose :
+ *
+ * Multiplies the 2 signed values L_var1 and L_var2 with saturation control
+ * on 64-bit. The operation is performed in fractional mode :
+ * - L_var1 and L_var2 are supposed to be in 1Q31 format.
+ * - The result is produced in 1Q63 format : L_varout_h points to the
+ * 32 MSBits while L_varout_l points to the 32 LSBits.
+ *
+ * Complexity weight : 4
+ *
+ * Inputs :
+ *
+ * L_var1 32 bit long signed integer (Word32) whose value falls in the
+ * range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ *
+ * L_var2 32 bit long signed integer (Word32) whose value falls in the
+ * range : 0x8000 0000 <= L_var2 <= 0x7fff ffff.
+ *
+ * Outputs :
+ *
+ * *L_varout_h 32 bit long signed integer (Word32) whose value falls in
+ * the range : 0x8000 0000 <= L_varout_h <= 0x7fff ffff.
+ *
+ * *L_varout_l 32 bit short unsigned integer (UWord32) whose value falls in
+ * the range : 0x0000 0000 <= L_varout_l <= 0xffff ffff.
+ *
+ *
+ * Return Value :
+ *
+ * none
+ *
+ *****************************************************************************/
+void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l )
+{
+ UWord16 uvar1_l, uvar2_l;
+ Word16 var1_h, var2_h;
+ Word40 L40_var1;
+
+ if ( ( L_var1 == (Word32) 0x80000000 ) && ( L_var2 == (Word32) 0x80000000 ) )
+ {
+ *L_varout_h = 0x7fffffff;
+ *L_varout_l = (UWord32) 0xffffffff;
+ }
+ else
+ {
+
+ uvar1_l = extract_l( L_var1 );
+ var1_h = extract_h( L_var1 );
+ uvar2_l = extract_l( L_var2 );
+ var2_h = extract_h( L_var2 );
+
+ /* Below line can not overflow, so we can use << instead of L40_shl. */
+ L40_var1 = ( (Word40) ( (UWord32) uvar2_l * (UWord32) uvar1_l ) ) << 1;
+
+ *L_varout_l = 0x0000ffff & L_Extract40( L40_var1 );
+
+ L40_var1 = L40_shr( L40_var1, 16 );
+ L40_var1 = L40_add( L40_var1, ( (Word40) ( (Word32) var2_h * (Word32) uvar1_l ) ) << 1 );
+ L40_var1 = L40_add( L40_var1, ( (Word40) ( (Word32) var1_h * (Word32) uvar2_l ) ) << 1 );
+ *L_varout_l |= ( L_Extract40( L40_var1 ) ) << 16;
+
+ L40_var1 = L40_shr( L40_var1, 16 );
+ L40_var1 = L40_mac( L40_var1, var1_h, var2_h );
+
+ *L_varout_h = L_Extract40( L40_var1 );
+ }
+
+
+ return;
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_lshl
+ *
+ * Purpose :
+ *
+ * Logically shifts left L40_var1 by var2 positions.
+ * - If var2 is negative, L40_var1 is shifted to the LSBits by (-var2)
+ * positions with insertion of 0 at the MSBit.
+ * - If var2 is positive, L40_var1 is shifted to the MSBits by (var2)
+ * positions.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : MIN_16 <= var2 <= MAX_16.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_lshl( Word40 L40_var1, Word16 var2 )
+{
+ Word40 L40_var_out;
+
+ if ( var2 <= 0 )
+ {
+ var2 = -var2;
+ L40_var_out = L40_lshr( L40_var1, var2 );
+ }
+ else
+ {
+ if ( var2 >= 40 )
+ L40_var_out = 0x0000000000;
+ else
+ {
+ L40_var_out = L40_var1 << var2;
+ }
+ L40_var_out = L40_set( L40_var_out );
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_lshr
+ *
+ * Purpose :
+ *
+ * Logically shifts right L40_var1 by var2 positions.
+ * - If var2 is positive, L40_var1 is shifted to the LSBits by (var2)
+ * positions with insertion of 0 at the MSBit.
+ * - If var2 is negative, L40_var1 is shifted to the MSBits by (-var2)
+ * positions.
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : MIN_16 <= var2 <= MAX_16.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_lshr( Word40 L40_var1, Word16 var2 )
+{
+ Word40 L40_var_out;
+
+ if ( var2 < 0 )
+ {
+ var2 = -var2;
+ L40_var_out = L40_lshl( L40_var1, var2 );
+ }
+ else
+ {
+ if ( var2 >= 40 )
+ L40_var_out = 0x0000000000;
+ else
+ {
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ L40_var_out = ( L40_var1 & 0xffffffffff ) >> var2;
+#else
+ L40_var_out = ( L40_var1 & 0xffffffffffLL ) >> var2;
+#endif
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : norm_L40
+ *
+ * Purpose :
+ *
+ * Produces the number of left shifts needed to normalize in 32 bit format
+ * the 40 bit variable L40_var1. This returned value can be used to scale
+ * L_40_var1 into the following intervals :
+ * - [(MAX_32+1)/2 .. MAX_32 ] for positive values.
+ * - [ MIN_32 .. (MIN_32/2)+1 ] for negative values.
+ * - [ 0 .. 0 ] for null values.
+ * In order to normalize the result, the following operation must be done :
+ * normelized_L40_var1 = L40_shl( L40_var1, norm_L40( L40_var1))
+ *
+ * Complexity weight : 1
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * var_out 16 bit short signed integer (Word16) whose value falls in
+ * the range : -8 <= var_out <= 31.
+ *
+ *****************************************************************************/
+Word16 norm_L40( Word40 L40_var1 )
+{
+ Word16 var_out;
+
+ var_out = 0;
+
+ if ( L40_var1 != 0 )
+ {
+ while ( ( L40_var1 > (Word32) 0x80000000L ) && ( L40_var1 < (Word32) 0x7fffffffL ) )
+ {
+
+ L40_var1 = L40_shl( L40_var1, 1 );
+ var_out++;
+ }
+
+ while ( ( L40_var1 < (Word32) 0x80000000L ) || ( L40_var1 > (Word32) 0x7fffffffL ) )
+ {
+
+ L40_var1 = L40_shl( L40_var1, -1 );
+ var_out--;
+ }
+ }
+
+
+ return ( var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_shr_r
+ *
+ * Purpose :
+ *
+ * Arithmetically shifts right L40_var1 by var2 positions and rounds the
+ * result. It is equivalent to L40_shr( L40_var1, var2) except that if the
+ * last bit shifted out to the LSBit is 1, then the shifted result is
+ * incremented by 1.
+ * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit.
+ * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit.
+ *
+ * Complexity weight : 3
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_shr_r( Word40 L40_var1, Word16 var2 )
+{
+ Word40 L40_var_out;
+
+ if ( var2 > 39 )
+ {
+ L40_var_out = 0;
+ }
+ else
+ {
+ L40_var_out = L40_shr( L40_var1, var2 );
+
+ if ( var2 > 0 )
+ {
+ if ( ( L40_var1 & ( (Word40) 1 << ( var2 - 1 ) ) ) != 0 )
+ {
+ /* below line can not generate overflows on 40-bit */
+ L40_var_out++;
+ }
+ }
+ }
+
+ BASOP_CHECK();
+
+
+ return ( L40_var_out );
+}
+
+
+/*****************************************************************************
+ *
+ * Function Name : L40_shl_r
+ *
+ * Purpose :
+ *
+ * Arithmetically shifts left L40_var1 by var2 positions and rounds the
+ * result. It is equivalent to L40_shl( L40_var1, var2) except if var2 is
+ * negative. In that case, it does the same as
+ * L40_shr_r( L40_var1, (-var2)).
+ * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit.
+ * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit.
+ *
+ * Complexity weight : 3
+ *
+ * Inputs :
+ *
+ * L40_var1 40 bit long signed integer (Word40) whose value falls in the
+ * range : MIN_40 <= L40_var1 <= MAX_40.
+ *
+ * var2 16 bit short signed integer (Word16) whose value falls in
+ * the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+ *
+ * Outputs :
+ *
+ * none
+ *
+ * Return Value :
+ *
+ * L40_var_out 40 bit long signed integer (Word40) whose value falls in
+ * the range : MIN_40 <= L40_var_out <= MAX_40.
+ *
+ *****************************************************************************/
+Word40 L40_shl_r( Word40 L40_var1, Word16 var2 )
+{
+ Word40 L40_var_out;
+
+ if ( var2 >= 0 )
+ {
+ L40_var_out = L40_shl( L40_var1, var2 );
+ }
+ else
+ {
+ var2 = -var2;
+ L40_var_out = L40_shr_r( L40_var1, var2 );
+ }
+
+
+ return ( L40_var_out );
+}
+
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/enh40.h b/lib_com/enh40.h
new file mode 100644
index 0000000000000000000000000000000000000000..a55bd925e9da5ca2408aa43f18f787a3ae32be64
--- /dev/null
+++ b/lib_com/enh40.h
@@ -0,0 +1,349 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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.
+
+*******************************************************************************************************/
+
+/*
+ ===========================================================================
+ File: ENH40.H v.2.3 - 30.Nov.2009
+ ===========================================================================
+
+ ITU-T STL BASIC OPERATORS
+
+ 40-BIT ARITHMETIC OPERATORS
+
+ History:
+ 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control
+ operators for the ITU-T Standard Tool Library as
+ described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
+ TD 11 document and subsequent discussions on the
+ wp3audio@yahoogroups.com email reflector.
+ March 06 v2.1 Changed to improve portability.
+
+ ============================================================================
+*/
+
+
+#ifndef _ENH40_H
+#define _ENH40_H
+
+
+#include "stl.h"
+
+#if defined( BASOP_NOGLOB ) || defined( _MSC_VER )
+#define MAX_40 ( 0x0000007fffffffff )
+#define MIN_40 ( 0xffffff8000000000 )
+#endif
+
+
+#define L40_OVERFLOW_OCCURED( L40_var1 ) ( Overflow = 1, exit( 1 ), L40_var1 )
+#define L40_UNDERFLOW_OCCURED( L40_var1 ) ( Overflow = 1, exit( 2 ), L40_var1 )
+
+
+/*****************************************************************************
+ *
+ * Prototypes for enhanced 40 bit arithmetic operators
+ *
+ *****************************************************************************/
+Word40 L40_shr( Word40 L40_var1, Word16 var2 );
+Word40 L40_shr_r( Word40 L40_var1, Word16 var2 );
+Word40 L40_shl( Word40 L40_var1, Word16 var2 );
+Word40 L40_shl_r( Word40 L40_var1, Word16 var2 );
+
+static __inline Word40 L40_mult( Word16 var1, Word16 var2 );
+
+static __inline Word40 L40_mac( Word40 L40_var1, Word16 var1, Word16 var2 );
+static __inline Word16 mac_r40( Word40 L40_var1, Word16 var1, Word16 var2 );
+
+static __inline Word40 L40_msu( Word40 L40_var1, Word16 var1, Word16 var2 );
+static __inline Word16 msu_r40( Word40 L40_var1, Word16 var1, Word16 var2 );
+
+
+void Mpy_32_16_ss( Word32 L_var1, Word16 var2, Word32 *L_varout_h, UWord16 *varout_l );
+void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l );
+
+
+Word40 L40_lshl( Word40 L40_var1, Word16 var2 );
+Word40 L40_lshr( Word40 L40_var1, Word16 var2 );
+
+static __inline Word40 L40_set( Word40 L40_var1 );
+static __inline UWord16 Extract40_H( Word40 L40_var1 );
+static __inline UWord16 Extract40_L( Word40 L40_var1 );
+static __inline UWord32 L_Extract40( Word40 L40_var1 );
+
+static __inline Word40 L40_deposit_h( Word16 var1 );
+static __inline Word40 L40_deposit_l( Word16 var1 );
+static __inline Word40 L40_deposit32( Word32 L_var1 );
+
+static __inline Word40 L40_round( Word40 L40_var1 );
+static __inline Word16 round40( Word40 L40_var1 );
+
+
+Word40 L40_add( Word40 L40_var1, Word40 L40_var2 );
+Word40 L40_sub( Word40 L40_var1, Word40 L40_var2 );
+Word40 L40_abs( Word40 L40_var1 );
+Word40 L40_negate( Word40 L40_var1 );
+Word40 L40_max( Word40 L40_var1, Word40 L40_var2 );
+Word40 L40_min( Word40 L40_var1, Word40 L40_var2 );
+Word32 L_saturate40( Word40 L40_var1 );
+Word16 norm_L40( Word40 L40_var1 );
+
+#ifdef BASOP_NOGLOB
+/*
+ * Overflowing operators
+ */
+Word40 L40_shl_o( Word40 L40_var1, Word16 var2, Flag *Overflow );
+Word40 L40_add_o( Word40 L40_var1, Word40 L40_var2, Flag *Overflow );
+Word40 L40_sub_o( Word40 L40_var1, Word40 L40_var2, Flag *Overflow );
+Word32 L_saturate40_o( Word40 L40_var1, Flag *Overflow );
+#endif /* BASOP_NOGLOB */
+
+/*#ifdef _MSC_VER*/
+static __inline Word40 L40_set( Word40 L40_var1 )
+{
+ Word40 L40_var_out;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ L40_var_out = L40_var1 & 0x000000ffffffffff;
+
+ if ( L40_var1 & 0x8000000000 )
+ L40_var_out = L40_var_out | 0xffffff0000000000;
+#else
+ L40_var_out = L40_var1 & 0x000000ffffffffffLL;
+
+ if ( L40_var1 & 0x8000000000LL )
+ L40_var_out = L40_var_out | 0xffffff0000000000LL;
+#endif
+
+
+ return ( L40_var_out );
+}
+/*#endif*/ /* ifdef _MSC_VER */
+
+
+static __inline UWord16 Extract40_H( Word40 L40_var1 )
+{
+ UWord16 var_out;
+
+ var_out = (UWord16) ( L40_var1 >> 16 );
+
+
+ return ( var_out );
+}
+
+
+static __inline UWord16 Extract40_L( Word40 L40_var1 )
+{
+ UWord16 var_out;
+
+ var_out = (UWord16) ( L40_var1 );
+
+
+ return ( var_out );
+}
+
+
+static __inline UWord32 L_Extract40( Word40 L40_var1 )
+{
+ UWord32 L_var_out;
+
+ L_var_out = (UWord32) L40_var1;
+
+
+ return ( L_var_out );
+}
+
+
+static __inline Word40 L40_deposit_h( Word16 var1 )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = ( (Word40) var1 ) << 16;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( var1 & 0x8000 )
+ {
+ L40_var_out = L40_set( L40_var_out | 0xff00000000 );
+#else
+ if ( var1 & 0x8000 )
+ {
+ L40_var_out = L40_set( L40_var_out | 0xff00000000LL );
+#endif
+ }
+
+
+ return ( L40_var_out );
+}
+
+
+static __inline Word40 L40_deposit_l( Word16 var1 )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = var1;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( var1 & 0x8000 )
+ {
+ L40_var_out = L40_set( L40_var_out | 0xffffff0000 );
+#else
+ if ( var1 & 0x8000 )
+ {
+ L40_var_out = L40_set( L40_var_out | 0xffffff0000LL );
+#endif
+ }
+
+
+ return ( L40_var_out );
+}
+
+
+static __inline Word40 L40_deposit32( Word32 L_var1 )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = (Word40) L_var1;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ if ( L_var1 & 0x80000000 )
+ {
+ L40_var_out = L40_set( L40_var_out | 0xff00000000 );
+#else
+ if ( L_var1 & 0x80000000 )
+ {
+ L40_var_out = L40_set( L40_var_out | 0xff00000000LL );
+#endif
+ }
+
+
+ return ( L40_var_out );
+}
+
+
+static __inline Word40 L40_round( Word40 L40_var1 )
+{
+ Word40 L40_var_out;
+ Word40 L40_constant;
+
+#if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
+ L40_constant = L40_set( 0xffffff0000 );
+#else
+ L40_constant = L40_set( 0xffffff0000LL );
+#endif
+
+ L40_var_out = L40_add( 0x8000, L40_var1 );
+ L40_var_out = L40_var_out & L40_constant;
+
+
+ return ( L40_var_out );
+}
+
+
+static __inline Word16 round40( Word40 L40_var1 )
+{
+ Word16 var_out;
+
+ var_out = extract_h( L_saturate40( L40_round( L40_var1 ) ) );
+
+
+ return ( var_out );
+}
+
+
+static __inline Word40 L40_mult( Word16 var1, Word16 var2 )
+{
+ Word32 L_var_out;
+ Word40 L40_var_out;
+
+ L_var_out = (Word32) var1 * (Word32) var2;
+ L40_var_out = (Word40) L_var_out;
+
+ /* Below line can not overflow, so we can use << instead of L40_shl. */
+ L40_var_out = L40_var_out << 1;
+
+
+ return ( L40_var_out );
+}
+
+
+static __inline Word40 L40_mac( Word40 L40_var1, Word16 var2, Word16 var3 )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = L40_mult( var2, var3 );
+ L40_var_out = L40_add( L40_var1, L40_var_out );
+
+
+ return ( L40_var_out );
+}
+
+
+static __inline Word16 mac_r40( Word40 L40_var1, Word16 var2, Word16 var3 )
+{
+ Word40 L40_var_out;
+ Word16 var_out;
+
+ L40_var_out = L40_mac( L40_var1, var2, var3 );
+ var_out = round40( L40_var_out );
+
+
+ return ( var_out );
+}
+
+
+static __inline Word40 L40_msu( Word40 L40_var1, Word16 var2, Word16 var3 )
+{
+ Word40 L40_var_out;
+
+ L40_var_out = L40_mult( var2, var3 );
+ L40_var_out = L40_sub( L40_var1, L40_var_out );
+
+
+ return ( L40_var_out );
+}
+
+
+static __inline Word16 msu_r40( Word40 L40_var1, Word16 var2, Word16 var3 )
+{
+ Word40 L40_var_out;
+ Word16 var_out;
+
+ L40_var_out = L40_msu( L40_var1, var2, var3 );
+ var_out = round40( L40_var_out );
+
+
+ return ( var_out );
+}
+
+
+#endif /*_ENH40_H*/
+
+
+/* end of file */
diff --git a/lib_com/enhancer.c b/lib_com/enhancer.c
new file mode 100644
index 0000000000000000000000000000000000000000..407588bc3f090b07430bec7148d9921d9afb621c
--- /dev/null
+++ b/lib_com/enhancer.c
@@ -0,0 +1,281 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * Local function prototypes
+ *---------------------------------------------------------------------*/
+
+static void agc2( const float *sig_in, float *sig_out, const int16_t l_trm );
+
+/*---------------------------------------------------------------------*
+ * enhancer()
+ *
+ * Enhancement of the excitation signal before synthesis
+ *---------------------------------------------------------------------*/
+
+void enhancer(
+ const int16_t codec_mode, /* i : flag indicating Codec Mode */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t cbk_index, /* i : */
+ const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t L_frame, /* i : frame size */
+ const float voice_fac, /* i : subframe voicing estimation */
+ const float stab_fac, /* i : LP filter stablility measure */
+ const float norm_gain_code, /* i : normalized innovative cb. gain */
+ const float gain_inov, /* i : gain of the unscaled innovation */
+ float *gc_threshold, /* i/o: code threshold */
+ float *code, /* i/o: innovation */
+ float *pt_exc2, /* i/o: adapt. excitation/total exc. */
+ const float gain_pit, /* i : Quantized pitch gain */
+ float *dispMem /* i/o: Phase dispersion algorithm memory */
+)
+{
+ float tmp, gain_code, new_norm_gain_code, fac;
+ int16_t i;
+ float pit_sharp;
+ float excp[L_SUBFR];
+
+ pit_sharp = gain_pit;
+
+ /*-----------------------------------------------------------------*
+ * Phase dispersion
+ *
+ * Enhance noise at low bitrates
+ *-----------------------------------------------------------------*/
+
+ i = 2; /* no dispersion */
+ if ( Opt_AMR_WB )
+ {
+ if ( core_brate <= ACELP_6k60 )
+ {
+ i = 0; /* high dispersion */
+ }
+ else if ( core_brate <= ACELP_8k85 )
+ {
+ i = 1; /* low dispersion */
+ }
+ }
+ else if ( codec_mode == MODE1 && coder_type != UNVOICED )
+ {
+ if ( core_brate <= ACELP_7k20 )
+ {
+ i = 0; /* high dispersion */
+ }
+ else if ( ( coder_type == GENERIC || coder_type == TRANSITION || coder_type == AUDIO || coder_type == INACTIVE ) && core_brate <= ACELP_9k60 )
+ {
+ i = 1; /* low dispersion */
+ }
+ }
+ else if ( codec_mode == MODE2 )
+ {
+ if ( ( ( coder_type != VOICED ) && cbk_index <= 2 ) || ( ( coder_type == UNVOICED ) && L_frame == L_FRAME && cbk_index <= 10 ) || ( ( coder_type == UNVOICED ) && L_frame == L_FRAME16k && cbk_index <= 14 ) )
+ {
+ i = 0; /* high dispersion */
+ }
+ else if ( ( coder_type != VOICED ) && ( cbk_index <= 7 ) )
+ {
+ i = 1; /* low dispersion */
+ }
+ }
+ else if ( codec_mode == MODE1 && coder_type == UNVOICED && cbk_index /*uc_two_stage_flag*/ )
+ {
+ i = 0; /* high dispersion */
+ }
+
+ phase_dispersion( norm_gain_code, gain_pit, code, i, dispMem );
+
+ /*------------------------------------------------------------
+ * Noise enhancer
+ *
+ * Enhance excitation on noise (modify code gain). If signal is noisy and LPC filter is stable,
+ * move code gain 1.5 dB towards its threshold. This decreases by 3 dB noise energy variation.
+ *-----------------------------------------------------------*/
+
+ if ( norm_gain_code < *gc_threshold )
+ {
+ new_norm_gain_code = (float) ( norm_gain_code * 1.19f );
+ if ( new_norm_gain_code > *gc_threshold )
+ {
+ new_norm_gain_code = *gc_threshold;
+ }
+ }
+ else
+ {
+ new_norm_gain_code = (float) ( norm_gain_code / 1.19f );
+ if ( new_norm_gain_code < *gc_threshold )
+ {
+ new_norm_gain_code = *gc_threshold;
+ }
+ }
+ *gc_threshold = new_norm_gain_code;
+
+ /* calculate new code gain */
+ fac = stab_fac * ( 0.5f * ( 1.0f - voice_fac ) ); /* 1 = unvoiced, 0 = voiced */
+ gain_code = fac * new_norm_gain_code + ( 1.0f - fac ) * norm_gain_code;
+ gain_code *= gain_inov;
+
+ for ( i = 0; i < L_SUBFR; i++ )
+ {
+ code[i] *= gain_code;
+ }
+
+ /*------------------------------------------------------------*
+ * Pitch enhancer
+ *
+ * Enhance excitation on voiced (HP filtering of code). On voiced signal, filter code by a smooth HP
+ * filter to decrease the energy of code at low frequency
+ *------------------------------------------------------------*/
+
+ if ( !Opt_AMR_WB && codec_mode == MODE1 && coder_type == UNVOICED )
+ {
+ mvr2r( code, pt_exc2, L_SUBFR );
+ }
+ else
+ {
+ if ( Opt_AMR_WB && ( core_brate == ACELP_8k85 || core_brate == ACELP_6k60 ) )
+ {
+ pit_sharp = gain_pit;
+ if ( pit_sharp > 1.0 )
+ {
+ pit_sharp = 1.0;
+ }
+
+ if ( pit_sharp > 0.5 )
+ {
+ for ( i = 0; i < L_SUBFR; i++ )
+ {
+ excp[i] = pt_exc2[i] * pit_sharp * 0.25f;
+ }
+ }
+ }
+
+ /*-----------------------------------------------------------------
+ * Do a simple noncasual "sharpening": effectively an FIR
+ * filter with coefs [-tmp 1.0 -tmp] where tmp = 0 ... 0.25
+ * This is applied to code and added to exc2
+ *-----------------------------------------------------------------*/
+ if ( L_frame == L_FRAME16k )
+ {
+ tmp = (float) ( 0.150f * ( 1.0f + voice_fac ) ); /* 0.30=voiced, 0=unvoiced */
+ }
+ else
+ {
+ tmp = (float) ( 0.125f * ( 1.0f + voice_fac ) ); /* 0.25=voiced, 0=unvoiced */
+ }
+ pt_exc2[0] += code[0] - ( tmp * code[1] );
+ for ( i = 1; i < L_SUBFR - 1; i++ )
+ {
+ pt_exc2[i] += code[i] - ( tmp * code[i - 1] ) - ( tmp * code[i + 1] );
+ }
+ pt_exc2[L_SUBFR - 1] += code[L_SUBFR - 1] - ( tmp * code[L_SUBFR - 2] );
+
+ if ( Opt_AMR_WB && ( core_brate == ACELP_8k85 || core_brate == ACELP_6k60 ) )
+ {
+ if ( pit_sharp > 0.5f )
+ {
+ for ( i = 0; i < L_SUBFR; i++ )
+ {
+ excp[i] += pt_exc2[i];
+ }
+
+ agc2( pt_exc2, excp, L_SUBFR );
+ mvr2r( excp, pt_exc2, L_SUBFR );
+ }
+ }
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------------*
+ * agc2()
+ *
+ * Adaptive gain control
+ *-----------------------------------------------------------------------*/
+
+static void agc2(
+ const float *sig_in, /* i : postfilter input signal */
+ float *sig_out, /* i/o: postfilter output signal */
+ const int16_t l_trm /* i : subframe size */
+)
+{
+ int16_t i;
+ float gain_in, gain_out;
+ float g0, gain;
+
+
+ gain_out = 0.0f;
+ for ( i = 0; i < l_trm; i++ )
+ {
+ gain_out += sig_out[i] * sig_out[i];
+ }
+
+ if ( gain_out == 0.0f )
+ {
+ return;
+ }
+
+ gain_in = 0.0f;
+ for ( i = 0; i < l_trm; i++ )
+ {
+ gain_in += sig_in[i] * sig_in[i];
+ }
+ if ( gain_in == 0.0f )
+ {
+ g0 = 0.0f;
+ }
+ else
+ {
+ g0 = (float) sqrt( gain_in / gain_out );
+ }
+
+ gain = g0;
+ for ( i = 0; i < l_trm; i++ )
+ {
+ sig_out[i] *= gain;
+ }
+
+ return;
+}
diff --git a/lib_com/enr_1_az.c b/lib_com/enr_1_az.c
new file mode 100644
index 0000000000000000000000000000000000000000..800fa185c69af3cf748388ea8ecadcbce8119942
--- /dev/null
+++ b/lib_com/enr_1_az.c
@@ -0,0 +1,65 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * enr_1_Az()
+ *
+ * Find Energy of the 1/A(z) impulse response
+ *-------------------------------------------------------------------*/
+
+/*! r: impulse response energy */
+float enr_1_Az(
+ const float Aq[], /* i : LP filter coefs */
+ const int16_t len /* i : impulse response length */
+)
+{
+ float enr_LP, h1[2 * L_SUBFR], mem[M];
+
+
+ set_f( h1, 0, len ); /* Find the impulse response */
+ set_f( mem, 0, M );
+ h1[0] = 1.0f;
+ syn_filt( Aq, M, h1, h1, len, mem, 0 );
+ enr_LP = dotp( h1, h1, len ) + 0.01f; /* Find the impulse response energy */
+
+ return enr_LP;
+}
diff --git a/lib_com/env_adj.c b/lib_com/env_adj.c
new file mode 100644
index 0000000000000000000000000000000000000000..459c40338d4b24df07208f2c5e1e2c986ba72029
--- /dev/null
+++ b/lib_com/env_adj.c
@@ -0,0 +1,165 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * env_adj()
+ *
+ * Adjust the band energies of noise-fill and low resolution bands
+ *--------------------------------------------------------------------------*/
+
+void env_adj(
+ const int16_t *pulses, /* i : number of pulses per band */
+ const int16_t length, /* i : length of spectrum */
+ const int16_t last_sfm, /* i : index of the last band */
+ float *adj, /* o : adjustment factors for the envelope */
+ const float env_stab, /* i : Envelope stability parameter */
+ const int16_t *sfmsize /* i : Band widths */
+)
+{
+ int16_t i, j, group;
+ int16_t npul;
+ int16_t att_state;
+ int16_t start, len;
+ float tmp;
+ float gain_adj;
+ int16_t idx;
+
+ att_state = 0;
+ len = 0;
+ start = 0;
+
+ /* Find attenuation levels */
+ for ( i = 0; i <= last_sfm; i++ )
+ {
+ group = ( sfmsize[i] >> 3 ) - 1;
+ npul = pulses[i];
+
+ if ( length == L_FRAME32k )
+ {
+ if ( npul == 0 )
+ {
+ /* Noise filled band */
+ if ( group <= 1 )
+ {
+ if ( i > 0 && pulses[i - 1] != 0 && pulses[i + 1] != 0 )
+ {
+ adj[i] = 0.36f;
+ }
+ else if ( i > 0 && ( pulses[i - 1] == 0 || pulses[i + 1] == 0 ) )
+ {
+ adj[i] = 0.54f;
+ }
+ else
+ {
+ adj[i] = 0.72f;
+ }
+ }
+ else if ( i < last_sfm )
+ {
+ if ( pulses[i - 1] != 0 && pulses[i + 1] != 0 )
+ {
+ adj[i] = 0.54f;
+ }
+ else
+ {
+ adj[i] = 0.72f;
+ }
+ }
+ else
+ {
+ adj[i] = 0.72f;
+ }
+
+ if ( att_state == 0 )
+ {
+ start = i;
+ }
+
+ len++;
+ att_state = 1;
+ }
+ else
+ {
+ adj[i] = 1.0f;
+ if ( att_state == 1 ) /* End of attenuation region found */
+ {
+ tmp = min( 1, max( 0, len - ENV_ADJ_START ) * ( 1.0f / ENV_ADJ_INCL ) );
+ for ( j = start; j < i; j++ )
+ {
+ adj[j] = max( tmp + ( 1 - tmp ) * adj[j], env_stab );
+ }
+ len = 0;
+ att_state = 0;
+ }
+ }
+ }
+ /* length == L_FRAME16k */
+ else
+ {
+ /* Calculate low accuracy band attenuation */
+ gain_adj = 1.0f;
+ if ( npul > 0 && npul < MAX_P_ATT )
+ {
+ idx = (int16_t) ( npul * att_step[group] + 0.5f ) - 1;
+ if ( idx < MAX_P_ATT )
+ {
+ gain_adj = gain_att[idx];
+ }
+ }
+ adj[i] = gain_adj;
+ }
+ }
+
+ /* Check if the sequence ended with an attenuation region */
+ if ( att_state == 1 )
+ {
+ tmp = min( 1, max( 0, len - ENV_ADJ_START ) * ( 1.0f / ENV_ADJ_INCL ) );
+
+ for ( j = start; j < i; j++ )
+ {
+ adj[j] = max( tmp + ( 1 - tmp ) * adj[j], env_stab );
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/env_stab.c b/lib_com/env_stab.c
new file mode 100644
index 0000000000000000000000000000000000000000..ee07218f9b14f61c9302ebe037e54fcb20c54f82
--- /dev/null
+++ b/lib_com/env_stab.c
@@ -0,0 +1,233 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+#include "stl.h"
+
+/*--------------------------------------------------------------------------*
+ * Local constants
+ *--------------------------------------------------------------------------*/
+
+#define ENV_STAB_SMO_HO 10 /* number of hangover frames when switching from music to speech state */
+
+
+/*--------------------------------------------------------------------------*/
+/* Function env_stability() */
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~ */
+/* */
+/* Envelope stability measure */
+/*--------------------------------------------------------------------------*/
+
+float env_stability(
+ const int16_t *ynrm, /* i : Norm vector for current frame */
+ const int16_t nb_sfm, /* i : Number of sub-bands */
+ int16_t *mem_norm, /* i/o: Norm vector memory from past frame */
+ int16_t *mem_env_delta, /* i/o: Envelope stability memory for smoothing*/
+ const int16_t core_switching_flag /* i : Core switching flag */
+)
+{
+ Word16 env_delta;
+ Word16 env_stab;
+ Word16 tmp, tmp_stab;
+ Word16 i;
+
+ Word16 exp, exp2;
+ Word32 L_tmp, L_env_delta;
+ Word16 inv_nb_sfm;
+ float env_stab_f;
+#ifdef BASOP_NOGLOB
+ Flag Overflow;
+#endif /* BASOP_NOGLOB */
+
+ if ( core_switching_flag )
+ {
+ for ( i = 0; i < nb_sfm; i++ )
+ {
+ mem_norm[i] = ynrm[i];
+ }
+#ifdef BASOP_NOGLOB
+ Overflow = 0;
+ env_delta = shl_o( *mem_env_delta, 1, &Overflow );
+#else
+ env_delta = shl( *mem_env_delta, 1 );
+#endif
+ }
+ else
+ {
+ /* Calculate envelope stability parameter */
+ L_env_delta = L_deposit_l( 0 );
+ for ( i = 0; i < nb_sfm; i++ )
+ {
+ tmp = sub( mem_norm[i], ynrm[i] );
+ L_env_delta = L_mac0( L_env_delta, tmp, tmp );
+ mem_norm[i] = ynrm[i];
+ }
+
+ inv_nb_sfm = 19418; /* Q19 */
+ if ( nb_sfm == 26 )
+ {
+ inv_nb_sfm = 20165; /* Q19 */
+ }
+ exp = norm_l( L_env_delta );
+ L_env_delta = Mult_32_16( L_shl( L_env_delta, exp ), inv_nb_sfm ); /* 0+exp+19-15 */
+
+ L_tmp = Sqrt_l( L_env_delta, &exp2 ); /* exp+4+31+exp2 */
+
+ exp = add( 35, add( exp, exp2 ) );
+ if ( sub( s_and( exp, 1 ), 1 ) == 0 )
+ {
+ L_tmp = Mult_32_16( L_tmp, 23170 ); /* 1/sqrt(2) in Q15 */
+ }
+ exp = shr( exp, 1 );
+
+#ifndef BASOP_NOGLOB
+ env_delta = round_fx( L_shl( L_tmp, sub( 26, exp ) ) ); /* Q10 */
+ L_tmp = L_mult0( 26214, env_delta ); /* 26214 is 0.1 in Q18. Q28 */
+ L_tmp = L_mac( L_tmp, 29491, *mem_env_delta ); /* 29491 is 0.9 in Q15. Q28 */
+ *mem_env_delta = round_fx( L_tmp ); /* Q12 */
+#else /* BASOP_NOGLOB */
+ env_delta = round_fx_o( L_shl_o( L_tmp, sub( 26, exp ), &Overflow ), &Overflow ); /* Q10 */
+ L_tmp = L_mult0( 26214, env_delta ); /* 26214 is 0.1 in Q18. Q28 */
+ L_tmp = L_mac_o( L_tmp, 29491, *mem_env_delta, &Overflow ); /* 29491 is 0.9 in Q15. Q28 */
+ *mem_env_delta = round_fx_o( L_tmp, &Overflow ); /* Q12 */
+#endif /* BASOP_NOGLOB */
+ Overflow = 0;
+#ifndef BASOP_NOGLOB
+ env_delta = round_fx( L_shl( L_tmp, 1 ) ); /* Q13 */
+#else /* BASOP_NOGLOB */
+ env_delta = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /* Q13 */
+#endif /* BASOP_NOGLOB */
+ }
+ if ( Overflow != 0 ) /* Saturated due to the above up-shifting operation. */
+ {
+ env_stab = stab_trans_fx[L_STAB_TBL - 1]; /* The highest quantized index. */
+ env_stab_f = ( (float) env_stab ) / PCM16_TO_FLT_FAC; /* Convert env_stab(Q15) to float */
+ return env_stab_f;
+ }
+
+ /* If tmp_stab > (D_STAB_TBL*L_STAB_TBL + M_STAB_TBL), i.e., 0.103138*10+2.51757=3.603137,
+ * the quantized index is equal to 9. Hence, we only need to worry about any tmpStab < 4.
+ * In this case, Q13 is good enough.
+ */
+ tmp_stab = sub( env_delta, M_STAB_TBL_FX ); /* in Q13 */
+ tmp_stab = abs_s( tmp_stab );
+
+ /* Table lookup for smooth transitions
+ * First, find the quantization level, i, of tmpStab. */
+#if L_STAB_TBL > 10
+#error env_stability_fx: Use more efficient usquant()
+#endif
+ tmp_stab = sub( tmp_stab, HALF_D_STAB_TBL_FX ); /* in Q13 */
+ for ( i = 0; i < L_STAB_TBL - 1; i++ )
+ {
+ if ( tmp_stab < 0 )
+ {
+ break;
+ }
+ else
+ {
+ tmp_stab = sub( tmp_stab, D_STAB_TBL_FX ); /* in Q13 */
+ }
+ }
+
+ env_stab = stab_trans_fx[i];
+ if ( sub( env_delta, M_STAB_TBL_FX ) < 0 )
+ {
+ env_stab = sub( 0x7FFF, stab_trans_fx[i] );
+ }
+
+ env_stab_f = ( (float) env_stab ) / PCM16_TO_FLT_FAC; /* Convert env_stab(Q15) to float */
+
+ return env_stab_f;
+}
+
+/*--------------------------------------------------------------------------*
+ * env_stab_smo_fx()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+/*! r: New speech/music state */
+float env_stab_smo(
+ float env_stab, /* i : env_stab value */
+ float *env_stab_state_p, /* i/o: env_stab state probabilities */
+ int16_t *ho_cnt /* i/o: hangover counter for speech state */
+)
+{
+ int16_t state, prev_state;
+ float maxval, pp[NUM_ENV_STAB_PLC_STATES], pa[NUM_ENV_STAB_PLC_STATES];
+ /* get previous state */
+ prev_state = maximum( env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval );
+
+ /* assume two states: speech(0), music(1) */
+ /* set a posteriori likelihoods for the two states according to env_stab */
+ env_stab = ( env_stab - stab_trans[L_STAB_TBL - 1] ) / ( 1 - 2 * stab_trans[L_STAB_TBL - 1] );
+ pp[0] = 1.0f - env_stab;
+ pp[1] = env_stab;
+
+ /* calculate a priori likelihoods */
+ pa[0] = dotp( env_stab_tp[0], env_stab_state_p, NUM_ENV_STAB_PLC_STATES );
+ pa[1] = dotp( env_stab_tp[1], env_stab_state_p, NUM_ENV_STAB_PLC_STATES );
+
+ /* multiply elementwise with a posteriori likelihoods */
+ v_mult( pa, pp, env_stab_state_p, NUM_ENV_STAB_PLC_STATES );
+
+ /* renormalize state probabilities */
+ v_multc( env_stab_state_p, 1.0f / sum_f( env_stab_state_p, NUM_ENV_STAB_PLC_STATES ), env_stab_state_p, NUM_ENV_STAB_PLC_STATES );
+
+ /* find maximum index as return value */
+ state = maximum( env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval );
+
+ /* apply some hangover for speech */
+ if ( state == 0 && prev_state == 1 )
+ {
+ *ho_cnt = ENV_STAB_SMO_HO;
+ }
+ if ( *ho_cnt > 0 )
+ {
+ pp[0] = 1;
+ pp[1] = 0;
+ ( *ho_cnt )--;
+ }
+
+ return state;
+}
diff --git a/lib_com/env_stab_trans.c b/lib_com/env_stab_trans.c
new file mode 100644
index 0000000000000000000000000000000000000000..1850ed48ba9f5b50302762b321bb0d85ec0d8ae1
--- /dev/null
+++ b/lib_com/env_stab_trans.c
@@ -0,0 +1,155 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * env_stab_transient_detect()
+ *
+ * Transient detector for envelope stability measure
+ *--------------------------------------------------------------------------*/
+
+void env_stab_transient_detect(
+ const int16_t is_transient, /* i : Transient flag */
+ const int16_t length, /* i : Length of spectrum (32 or 48 kHz) */
+ const int16_t norm[], /* i : quantization indices for norms */
+ int16_t *no_att_hangover, /* i/o: Frame counter for attenuation hangover */
+ float *energy_lt, /* i/o: Long-term energy measure for transient detection */
+ const int16_t HQ_mode, /* i : HQ coding mode */
+ const int16_t bin_th, /* i : HVQ cross-over frequency bin */
+ const float *coeff /* i : Coded spectral coefficients */
+)
+{
+ float d_max;
+ float e_frame;
+ int16_t blk;
+ int16_t i;
+ float E_sub[4];
+ float delta_e_sub;
+ int16_t norm_ind;
+
+ int16_t num_subframes = 4;
+ int16_t bands_per_subframe = 9;
+
+ if ( HQ_mode == HQ_HVQ )
+ {
+ e_frame = 0.0f;
+
+ for ( i = 0; i < bin_th; i++ )
+ {
+ e_frame += coeff[i] * coeff[i];
+ }
+
+ e_frame = (float) sqrt( e_frame / bin_th );
+
+ if ( e_frame > ENERGY_TH )
+ {
+ *energy_lt = ENERGY_LT_BETA * ( *energy_lt ) + ( 1 - ENERGY_LT_BETA ) * e_frame;
+ }
+
+ if ( *no_att_hangover > 0 )
+ {
+ ( *no_att_hangover )--;
+ }
+ }
+ else
+ {
+ d_max = 0.0f;
+ e_frame = 0.0f;
+ if ( is_transient && length == L_FRAME32k )
+ {
+ /* Measure subframe energies */
+ for ( blk = 0; blk < num_subframes; blk++ )
+ {
+ E_sub[blk] = 0.0f;
+ for ( i = 0; i < bands_per_subframe; i++ )
+ {
+ norm_ind = subf_norm_groups[blk][i];
+ E_sub[blk] += dicn[norm[norm_ind]];
+ }
+ E_sub[blk] = E_sub[blk] / bands_per_subframe;
+ e_frame += E_sub[blk];
+ }
+ /* Test for transient */
+ if ( e_frame > ENERGY_TH * num_subframes )
+ {
+ for ( blk = 0; blk < num_subframes - 1; blk++ )
+ {
+ delta_e_sub = ( E_sub[blk + 1] - E_sub[blk] ) / *energy_lt;
+ if ( delta_e_sub > d_max )
+ {
+ d_max = delta_e_sub;
+ }
+ }
+ }
+ }
+ else
+ {
+ /* Update long-term energy measure */
+ e_frame = 0.0f;
+
+ for ( i = 0; i < SFM_N_ENV_STAB; i++ )
+ {
+ e_frame += dicn[norm[i]];
+ }
+
+ e_frame = e_frame / SFM_N_ENV_STAB;
+
+ if ( e_frame > ENERGY_TH )
+ {
+ *energy_lt = ENERGY_LT_BETA * ( *energy_lt ) + ( 1 - ENERGY_LT_BETA ) * e_frame;
+ }
+ }
+
+ /* Add hang-over for conservative application of stability-dependent attenuation */
+ if ( d_max > DELTA_TH )
+ {
+ *no_att_hangover = ATT_LIM_HANGOVER;
+ }
+ else if ( *no_att_hangover > 0 )
+ {
+ ( *no_att_hangover )--;
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/est_tilt.c b/lib_com/est_tilt.c
new file mode 100644
index 0000000000000000000000000000000000000000..2f5b5bbac8db7fe540a45bb85f410c5b1fa7af44
--- /dev/null
+++ b/lib_com/est_tilt.c
@@ -0,0 +1,90 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * est_tilt()
+ *
+ * Estimate spectral tilt based on the relative E of adaptive
+ * and innovative excitations
+ *-------------------------------------------------------------------*/
+
+/*! r: tilt of the code */
+float est_tilt(
+ const float *adpt_exc, /* i : adaptive excitation vector */
+ const float gain_pit, /* i : adaptive gain */
+ const float *fixe_exc, /* i : algebraic exctitation vector */
+ const float gain_code, /* i : algebraic code gain */
+ float *voice_fac, /* o : voicing factor */
+ const int16_t L_subfr, /* i : subframe size */
+ const int16_t flag_tilt /* i : flag for special tilt */
+)
+{
+ float ener, tmp, tilt_code;
+
+ ener = dotp( adpt_exc, adpt_exc, L_subfr );
+ ener *= gain_pit * gain_pit; /* energy of pitch excitation */
+
+ tmp = dotp( fixe_exc, fixe_exc, L_subfr );
+ tmp *= gain_code * gain_code; /* energy of innovative code excitation */
+
+ /* find voice factor (1=voiced, -1=unvoiced) */
+ *voice_fac = (float) ( ( ener - tmp ) / ( ener + tmp + 0.01f ) );
+
+ /* find tilt of code for next subframe */
+ if ( flag_tilt == 0 )
+ {
+ /*Between 0 (=unvoiced) and 0.5 (=voiced)*/
+ tilt_code = (float) ( 0.25f * ( 1.0f + *voice_fac ) );
+ }
+ else if ( flag_tilt == 1 )
+ {
+ /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/
+ tilt_code = (float) ( 0.25f + ( *voice_fac + 1.0f ) * 0.125f );
+ }
+ else
+ {
+ /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/
+ tilt_code = (float) ( 0.28f + ( *voice_fac + 1.0f ) * 0.14f );
+ }
+
+ return tilt_code;
+}
diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..a6029e1059691a66da43ba419d7d0ff503b5a899
--- /dev/null
+++ b/lib_com/fd_cng_com.c
@@ -0,0 +1,1223 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------------
+ * Local function prototypes
+ *-------------------------------------------------------------------*/
+
+static void mhvals( const int16_t d, float *m );
+
+static void getmidbands( int16_t *part, const int16_t npart, int16_t *midband, float *psize, float *psize_inv );
+
+
+/*-------------------------------------------------------------------
+ * createFdCngCom()
+ *
+ * Create an instance of type FD_CNG_COM
+ *-------------------------------------------------------------------*/
+
+ivas_error createFdCngCom(
+ HANDLE_FD_CNG_COM *hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
+)
+{
+ HANDLE_FD_CNG_COM hs;
+
+ /* Allocate memory */
+ if ( ( hs = (HANDLE_FD_CNG_COM) malloc( sizeof( FD_CNG_COM ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD CNG COM" );
+ }
+
+ *hFdCngCom = hs;
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-------------------------------------------------------------------
+ * initFdCngCom()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void initFdCngCom(
+ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
+ const float scale )
+{
+ /* Calculate FFT scaling factor */
+ hFdCngCom->scalingFactor = 1 / ( scale * scale * 8.f );
+
+ /* Initialize the overlap-add */
+ set_f( hFdCngCom->timeDomainBuffer, 0.0f, L_FRAME16k );
+ set_f( hFdCngCom->olapBufferAna, 0.0f, FFTLEN );
+ set_f( hFdCngCom->olapBufferSynth, 0.0f, FFTLEN );
+ set_f( hFdCngCom->olapBufferSynth2, 0.0f, FFTLEN );
+
+ /* Initialize the comfort noise generation */
+ set_f( hFdCngCom->fftBuffer, 0.0f, FFTLEN );
+ set_f( hFdCngCom->cngNoiseLevel, 0.0f, FFTCLDFBLEN );
+
+ /* Initialize quantizer */
+ set_f( hFdCngCom->sidNoiseEst, 0.0f, NPART );
+ set_f( hFdCngCom->A_cng, 0.0f, M + 1 );
+ hFdCngCom->A_cng[0] = 1.f;
+
+ /* Set some counters and flags */
+ hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */
+ hFdCngCom->active_frame_counter = 0;
+ hFdCngCom->frame_type_previous = ACTIVE_FRAME;
+ hFdCngCom->flag_noisy_speech = 0;
+ hFdCngCom->likelihood_noisy_speech = 0.f;
+ hFdCngCom->numCoreBands = 0;
+ hFdCngCom->stopBand = 0;
+ hFdCngCom->startBand = 0;
+ hFdCngCom->stopFFTbin = 0;
+ hFdCngCom->frameSize = 0;
+ hFdCngCom->fftlen = 0;
+ hFdCngCom->seed = 0;
+ hFdCngCom->seed2 = 1;
+ hFdCngCom->seed3 = 2;
+ hFdCngCom->CngBitrate = -1;
+
+ /* Initialize noise estimation algorithm */
+ set_f( hFdCngCom->periodog, 0.0f, PERIODOGLEN );
+ mhvals( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win ) );
+ mhvals( MSSUBFRLEN, &( hFdCngCom->msM_subwin ) );
+ set_f( hFdCngCom->msPeriodogSum, 0.0f, 2 );
+ set_f( hFdCngCom->msPsdSum, 0.0f, 2 );
+ set_f( hFdCngCom->msSlope, 0.0f, 2 );
+ set_f( hFdCngCom->msQeqInvAv, 0.0f, 2 );
+ hFdCngCom->msFrCnt_init_counter = 0;
+ hFdCngCom->msFrCnt_init_thresh = 1;
+ hFdCngCom->init_old = 0;
+ hFdCngCom->offsetflag = 0;
+ hFdCngCom->msFrCnt = MSSUBFRLEN;
+ hFdCngCom->msMinBufferPtr = 0;
+ set_f( hFdCngCom->msAlphaCor, 0.3f, 2 );
+
+ hFdCngCom->coherence = 0.5f;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * deleteFdCngCom()
+ *
+ * Delete an instance of type FD_CNG_COM
+ *-------------------------------------------------------------------*/
+
+void deleteFdCngCom(
+ HANDLE_FD_CNG_COM *hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
+)
+{
+ HANDLE_FD_CNG_COM hsCom = *hFdCngCom;
+
+ if ( hsCom != NULL )
+ {
+ free( hsCom );
+ *hFdCngCom = NULL;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * initPartitions()
+ *
+ * Initialize the spectral partitioning
+ *-------------------------------------------------------------------*/
+
+void initPartitions(
+ const int16_t *part_in,
+ const int16_t npart_in,
+ const int16_t startBand,
+ const int16_t stopBand,
+ int16_t *part_out,
+ int16_t *npart_out,
+ int16_t *midband,
+ float *psize,
+ float *psize_inv,
+ const int16_t stopBandFR )
+{
+ int16_t i, j, len_out;
+
+ if ( part_in != NULL )
+ {
+ if ( stopBandFR > startBand )
+ {
+ len_out = stopBandFR - startBand; /*part_out*/
+ for ( i = 0; i < len_out; i++ )
+ {
+ part_out[i] = i;
+ }
+ }
+ else
+ {
+ len_out = 0;
+ } /*npart_in,part_out*/
+ for ( j = 0; j < npart_in && part_in[j] < stopBand; j++ )
+ {
+ if ( part_in[j] >= stopBandFR && part_in[j] >= startBand )
+ {
+ part_out[len_out++] = part_in[j] - startBand;
+ }
+ }
+ }
+ else
+ {
+ len_out = stopBand - startBand; /*part_out*/
+ for ( i = 0; i < len_out; i++ )
+ {
+ part_out[i] = i;
+ }
+ }
+
+ *npart_out = len_out;
+ getmidbands( part_out, len_out, midband, psize, psize_inv );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * compress_range()
+ *
+ * Apply some dynamic range compression based on the log
+ *-------------------------------------------------------------------*/
+
+void compress_range(
+ float *in,
+ float *out,
+ const int16_t len )
+{
+ float *ptrIn = in;
+ float *ptrOut = out;
+ int16_t i;
+
+ /* out = log2( 1 + in ) */
+ for ( i = 0; i < len; i++ )
+ {
+ *ptrOut = (float) log10( *ptrIn + 1.f );
+ ptrIn++;
+ ptrOut++;
+ }
+ v_multc( out, 1.f / (float) log10( 2.f ), out, len );
+
+ /* Quantize to simulate a fixed-point representation 6Q9 */
+ v_multc( out, CNG_LOG_SCALING, out, len );
+ for ( ptrOut = out; ptrOut < out + len; ptrOut++ )
+ {
+ *ptrOut = (float) ( (int16_t) ( *ptrOut + 0.5f ) );
+ if ( *ptrOut == 0.f )
+ {
+ *ptrOut = 1.f;
+ }
+ }
+ v_multc( out, 1. / CNG_LOG_SCALING, out, len );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * expand_range()
+ *
+ * Apply some dynamic range expansion to undo the compression
+ *-------------------------------------------------------------------*/
+
+void expand_range(
+ float *in,
+ float *out,
+ const int16_t len )
+{
+ float *ptrIn = in;
+ float *ptrOut = out;
+ int16_t i;
+
+ /* out = (2^(in) - 1) */
+ for ( i = 0; i < len; i++ )
+ {
+ *ptrOut = (float) pow( 2.f, *ptrIn ) - 1.f;
+ if ( *ptrOut < 0.0003385080526823181f )
+ {
+ *ptrOut = 0.0003385080526823181f;
+ }
+ ptrIn++;
+ ptrOut++;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * minimum_statistics()
+ *
+ * Noise estimation using Minimum Statistics (MS)
+ *-------------------------------------------------------------------*/
+
+void minimum_statistics(
+ const int16_t len, /* i : Vector length */
+ const int16_t lenFFT, /* i : Length of the FFT part of the vectors */
+ float *psize,
+ float *msPeriodog, /* i : Periodograms */
+ float *msNoiseFloor,
+ float *msNoiseEst, /* o : Noise estimates */
+ float *msAlpha,
+ float *msPsd,
+ float *msPsdFirstMoment,
+ float *msPsdSecondMoment,
+ float *msMinBuf,
+ float *msBminWin,
+ float *msBminSubWin,
+ float *msCurrentMin,
+ float *msCurrentMinOut,
+ float *msCurrentMinSubWindow,
+ int16_t *msLocalMinFlag,
+ int16_t *msNewMinFlag,
+ float *msPeriodogBuf,
+ int16_t *msPeriodogBufPtr,
+ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
+ const int16_t enc_dec, /* i : encoder/decoder indicator */
+ const int16_t element_mode /* i : IVAS element mode type */
+)
+{
+ float msM_win = hFdCngCom->msM_win;
+ float msM_subwin = hFdCngCom->msM_subwin;
+ float *msPsdSum = hFdCngCom->msPsdSum;
+ float *msPeriodogSum = hFdCngCom->msPeriodogSum;
+ float slope;
+ float *ptr;
+ float msAlphaCorAlpha = MSALPHACORALPHA;
+ float msAlphaCorAlpha2 = 1.f - MSALPHACORALPHA;
+
+ int16_t i, j, k;
+ float scalar, scalar2, scalar3;
+ float snr, BminCorr, QeqInv, QeqInvAv;
+ float beta;
+ float msAlphaHatMin2;
+ int16_t len2 = MSNUMSUBFR * len;
+ int16_t current_len;
+ int16_t start, stop, cnt;
+ int16_t totsize;
+ const float inv_buflen = 1.f / MSBUFLEN;
+
+ /* No minimum statistics at initialization */
+ if ( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh )
+ {
+ mvr2r( msPeriodog, msPsd, len );
+ mvr2r( msPeriodog, msNoiseFloor, len );
+ mvr2r( msPeriodog, msNoiseEst, len );
+ mvr2r( msPeriodog, msPsdFirstMoment, len );
+ set_f( msPsdSecondMoment, 0.0f, len );
+ msPeriodogSum[0] = dotp( msPeriodog, psize, lenFFT );
+ msPsdSum[0] = msPeriodogSum[0];
+ if ( lenFFT < len )
+ {
+ msPeriodogSum[1] = dotp( msPeriodog + lenFFT, psize + lenFFT, len - lenFFT );
+ msPsdSum[1] = msPeriodogSum[1];
+ }
+
+ /* Increment frame counter at initialization */
+ /* Some frames are sometimes zero at initialization => ignore them */
+ if ( msPeriodog[0] < hFdCngCom->init_old )
+ {
+ set_f( msCurrentMinOut, FLT_MAX, len );
+ set_f( msCurrentMin, FLT_MAX, len );
+ set_f( msMinBuf, FLT_MAX, len2 );
+ set_f( msCurrentMinSubWindow, FLT_MAX, len );
+ hFdCngCom->msFrCnt_init_counter++;
+ }
+ hFdCngCom->init_old = msPeriodog[0];
+ }
+ else
+ {
+
+ /* Consider the FFT and CLDFB bands separately
+ - first iteration for FFT bins,
+ - second one for CLDFB bands in SWB mode */
+ start = 0;
+ stop = lenFFT;
+ totsize = hFdCngCom->stopFFTbin - hFdCngCom->startBand;
+ cnt = 0; /*msAlphaCor*/
+ while ( stop > start )
+ {
+ current_len = stop - start;
+
+ /* Compute smoothed correction factor for PSD smoothing */
+ msPeriodogSum[cnt] = dotp( msPeriodog + start, psize + start, current_len );
+ scalar = msPeriodogSum[cnt] * msPeriodogSum[cnt] + DELTA;
+ scalar2 = msPsdSum[cnt] - msPeriodogSum[cnt];
+ scalar = max( scalar / ( scalar + scalar2 * scalar2 ), MSALPHACORMAX );
+ hFdCngCom->msAlphaCor[cnt] = msAlphaCorAlpha * hFdCngCom->msAlphaCor[cnt] + msAlphaCorAlpha2 * scalar;
+
+ /* Compute SNR */
+ snr = dotp( msNoiseFloor + start, psize + start, current_len );
+ snr = ( msPsdSum[cnt] + DELTA ) / ( snr + DELTA );
+ snr = (float) pow( snr, MSSNREXP );
+ msAlphaHatMin2 = min( MSALPHAHATMIN, snr );
+ scalar = MSALPHAMAX * hFdCngCom->msAlphaCor[cnt]; /*msAlpha,msPsd,msPeriodog,msNoiseFloor*/
+ for ( j = start; j < stop; j++ )
+ {
+ /* Compute optimal smoothing parameter for PSD estimation */
+ scalar2 = msNoiseFloor[j] + DELTA;
+ scalar2 *= scalar2;
+ scalar3 = msPsd[j] - msNoiseFloor[j];
+ msAlpha[j] = max( ( scalar * scalar2 ) / ( scalar2 + scalar3 * scalar3 ), msAlphaHatMin2 );
+
+ /* Compute the PSD (smoothed periodogram) in each band */
+ msPsd[j] = msAlpha[j] * msPsd[j] + ( 1.f - msAlpha[j] ) * msPeriodog[j];
+ }
+ msPsdSum[cnt] = dotp( msPsd + start, psize + start, current_len );
+ QeqInvAv = 0;
+ scalar = ( (float) ( MSNUMSUBFR * MSSUBFRLEN ) - 1.f ) * ( 1.f - msM_win );
+ scalar2 = ( (float) MSSUBFRLEN - 1.f ) * ( 1.f - msM_subwin ); /*msAlpha,msPsd,msPsdFirstMoment,msPsdSecondMoment,msNoiseFloor,msBminSubWin,msBminWin,psize*/
+ for ( j = start; j < stop; j++ )
+ {
+ /* Compute variance of PSD */
+ beta = min( msAlpha[j] * msAlpha[j], MSBETAMAX );
+ scalar3 = msPsd[j] - msPsdFirstMoment[j];
+ msPsdFirstMoment[j] = beta * msPsdFirstMoment[j] + ( 1.f - beta ) * msPsd[j];
+ msPsdSecondMoment[j] = beta * msPsdSecondMoment[j] + ( 1.f - beta ) * scalar3 * scalar3;
+ /* Compute inverse of amount of degrees of freedom */
+ QeqInv = min( ( msPsdSecondMoment[j] + DELTA ) / ( 2.f * msNoiseFloor[j] * msNoiseFloor[j] + DELTA ), MSQEQINVMAX );
+ QeqInvAv += QeqInv * psize[j];
+
+ /* Compute bias correction Bmin */
+ msBminWin[j] = 1.f + scalar * QeqInv / ( 0.5f - msM_win * QeqInv );
+ msBminSubWin[j] = 1.f + scalar2 * QeqInv / ( 0.5f - msM_subwin * QeqInv );
+ }
+ QeqInvAv /= totsize;
+ hFdCngCom->msQeqInvAv[cnt] = QeqInvAv;
+
+ /* New minimum? */
+ BminCorr = 1.f + MSAV * (float) sqrt( QeqInvAv ); /*msPsd,msBminWin,msNewMinFlag,msCurrentMin,msCurrentMinSubWindow*/
+ for ( j = start; j < stop; j++ )
+ {
+ scalar = BminCorr * msPsd[j];
+ scalar2 = scalar * msBminWin[j];
+ if ( scalar2 < msCurrentMin[j] )
+ {
+ msNewMinFlag[j] = 1;
+ msCurrentMin[j] = scalar2;
+ msCurrentMinSubWindow[j] = scalar * msBminSubWin[j];
+ }
+ else
+ {
+ msNewMinFlag[j] = 0;
+ }
+ }
+
+ /* This is used later to identify local minima */
+ if ( hFdCngCom->msFrCnt >= MSSUBFRLEN )
+ {
+ i = 0;
+ while ( i < 3 )
+ {
+ if ( hFdCngCom->msQeqInvAv[cnt] < msQeqInvAv_thresh[i] )
+ {
+ break;
+ }
+ else
+ {
+ i++;
+ }
+ }
+ hFdCngCom->msSlope[cnt] = msNoiseSlopeMax[i];
+ }
+
+ /* Consider the FFT and CLDFB bands separately */
+ start = stop;
+ stop = len;
+ totsize = hFdCngCom->stopBand - hFdCngCom->stopFFTbin;
+ cnt++;
+ } /*while (stop > start)*/
+
+ /* Update minimum between sub windows */
+ if ( hFdCngCom->msFrCnt > 1 && hFdCngCom->msFrCnt < MSSUBFRLEN )
+ {
+ /*msNewMinFlag,msCurrentMinSubWindow,msCurrentMinOut*/
+ for ( j = 0; j < len; j++ )
+ {
+ if ( msNewMinFlag[j] > 0 )
+ {
+ msLocalMinFlag[j] = 1;
+ }
+ if ( msCurrentMinSubWindow[j] < msCurrentMinOut[j] )
+ {
+ msCurrentMinOut[j] = msCurrentMinSubWindow[j];
+ }
+ }
+ /* Get the current noise floor */
+ mvr2r( msCurrentMinOut, msNoiseFloor, len );
+ }
+
+ /* sub window complete */
+ else
+ {
+ if ( hFdCngCom->msFrCnt >= MSSUBFRLEN )
+ {
+ /* Collect buffers */
+ mvr2r( msCurrentMinSubWindow, msMinBuf + len * hFdCngCom->msMinBufferPtr, len );
+
+ /* Compute minimum among all buffers */
+ mvr2r( msMinBuf, msCurrentMinOut, len );
+ ptr = msMinBuf + len;
+ for ( i = 1; i < MSNUMSUBFR; i++ )
+ {
+ /*msCurrentMinOut*/
+ for ( j = 0; j < len; j++ )
+ {
+ if ( *ptr < msCurrentMinOut[j] )
+ {
+ msCurrentMinOut[j] = *ptr;
+ }
+ ptr++;
+ }
+ }
+
+ /* Take over local minima */
+ slope = hFdCngCom->msSlope[0]; /*msLocalMinFlag,msNewMinFlag,msCurrentMinSubWindow,msCurrentMinOut*/
+ for ( j = 0; j < len; j++ )
+ {
+ if ( j == lenFFT )
+ {
+ slope = hFdCngCom->msSlope[1];
+ }
+ if ( msLocalMinFlag[j] && !msNewMinFlag[j] &&
+ msCurrentMinSubWindow[j] < slope * msCurrentMinOut[j] &&
+ msCurrentMinSubWindow[j] > msCurrentMinOut[j] )
+ {
+ msCurrentMinOut[j] = msCurrentMinSubWindow[j];
+ i = j;
+ for ( k = 0; k < MSNUMSUBFR; k++ )
+ {
+ msMinBuf[i] = msCurrentMinOut[j];
+ i += len;
+ }
+ }
+ }
+
+ /* Reset */
+ set_s( msLocalMinFlag, 0, len );
+ set_f( msCurrentMin, FLT_MAX, len );
+
+ /* Get the current noise floor */
+ mvr2r( msCurrentMinOut, msNoiseFloor, len );
+ }
+ }
+
+ /* Detect sudden offsets based on the FFT bins (core bandwidth) */
+ if ( msPsdSum[0] > 50.f * msPeriodogSum[0] )
+ {
+ if ( hFdCngCom->offsetflag > 0 )
+ {
+ mvr2r( msPeriodog, msPsd, len );
+ mvr2r( msPeriodog, msCurrentMinOut, len );
+ set_f( hFdCngCom->msAlphaCor, 1.0f, cnt );
+ set_f( msAlpha, 0.0f, len );
+ mvr2r( msPeriodog, msPsdFirstMoment, len );
+ set_f( msPsdSecondMoment, 0.0f, len );
+ msPsdSum[0] = dotp( msPeriodog, psize, lenFFT );
+ if ( lenFFT < len )
+ {
+ msPsdSum[1] = dotp( msPeriodog + lenFFT, psize + lenFFT, len - lenFFT );
+ }
+ }
+ hFdCngCom->offsetflag = 1;
+ }
+ else
+ {
+ hFdCngCom->offsetflag = 0;
+ }
+
+ /* Increment frame counter */
+ if ( hFdCngCom->msFrCnt == MSSUBFRLEN )
+ {
+ hFdCngCom->msFrCnt = 1;
+ hFdCngCom->msMinBufferPtr++;
+ if ( hFdCngCom->msMinBufferPtr == MSNUMSUBFR )
+ {
+ hFdCngCom->msMinBufferPtr = 0;
+ }
+ }
+ else
+ {
+ ( hFdCngCom->msFrCnt )++;
+ }
+
+ /* Smooth noise estimate during CNG phases */ /*msNoiseEst,msNoiseFloor*/
+ for ( j = 0; j < len; j++ )
+ {
+ msNoiseEst[j] = 0.95f * msNoiseEst[j] + 0.05f * msNoiseFloor[j];
+ }
+ }
+
+ if ( enc_dec == DEC && element_mode == IVAS_CPE_TD )
+ {
+ v_multc( msNoiseEst, 1.4125f, msNoiseEst, NPART_SHAPING );
+ }
+
+ /* Collect buffers */
+ mvr2r( msPeriodog, msPeriodogBuf + len * ( *msPeriodogBufPtr ), len );
+
+ ( *msPeriodogBufPtr )++;
+ if ( ( *msPeriodogBufPtr ) == MSBUFLEN )
+ {
+ ( *msPeriodogBufPtr ) = 0;
+ }
+
+ /* Upper limit the noise floors with the averaged input energy */ /*msNoiseEst*/
+ for ( j = 0; j < len; j++ )
+ {
+ scalar = msPeriodogBuf[j];
+ for ( i = j + len; i < MSBUFLEN * len; i += len )
+ {
+ scalar += msPeriodogBuf[i];
+ } /*division by a constant = multiplication by its (constant) inverse */
+ scalar *= inv_buflen;
+ if ( msNoiseEst[j] > scalar )
+ {
+ msNoiseEst[j] = scalar;
+ }
+ assert( msNoiseEst[j] >= 0 );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * apply_scale()
+ *
+ * Apply bitrate-dependent scale
+ *-------------------------------------------------------------------*/
+
+void apply_scale(
+ float *scale, /* o : scalefactor */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int32_t brate, /* i : Bit rate */
+ const SCALE_SETUP *scaleTable, /* i : Scale table */
+ const int16_t scaleTableSize /* i : Size of scale table */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < scaleTableSize; i++ )
+ {
+ if ( ( bwidth == scaleTable[i].bwmode ) &&
+ ( brate >= scaleTable[i].bitrateFrom ) &&
+ ( brate < scaleTable[i].bitrateTo ) )
+ {
+ break;
+ }
+ }
+
+ assert( i < scaleTableSize );
+
+ *scale += scaleTable[i].scale;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * bandcombinepow()
+ *
+ * Compute the power for each partition
+ *-------------------------------------------------------------------*/
+
+void bandcombinepow(
+ const float *bandpow, /* i : Power for each band */
+ const int16_t nband, /* i : Number of bands */
+ int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */
+ const int16_t npart, /* i : Number of partitions */
+ const float *psize_inv, /* i : Inverse partition sizes */
+ float *partpow /* o : Power for each partition */
+)
+{
+ int16_t i, p;
+ float temp;
+
+ if ( nband == npart )
+ {
+ mvr2r( bandpow, partpow, nband );
+ }
+ else
+ {
+ /* Compute the power in each partition */
+ i = 0; /*part,partpow,psize_inv*/
+ for ( p = 0; p < npart; p++ )
+ {
+ /* Arithmetic averaging of power for all bins in partition */
+ temp = 0;
+ for ( ; i <= part[p]; i++ )
+ {
+ temp += bandpow[i];
+ }
+ partpow[p] = temp * psize_inv[p];
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * scalebands()
+ *
+ * Scale partitions (with smoothing)
+ *-------------------------------------------------------------------*/
+
+void scalebands(
+ const float *partpow, /* i : Power for each partition */
+ int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */
+ const int16_t npart, /* i : Number of partitions */
+ int16_t *midband, /* i : Central band of each partition */
+ const int16_t nFFTpart, /* i : Number of FFT partitions */
+ const int16_t nband, /* i : Number of bands */
+ float *bandpow, /* o : Power for each band */
+ const int16_t flag_fft_en )
+{
+ int16_t i, j = 0, nint, startBand, startPart, stopPart;
+ float val, delta = 0.f;
+
+ /* Interpolate the bin/band-wise levels from the partition levels */
+ if ( nband == npart )
+ {
+ mvr2r( partpow, bandpow, npart );
+ }
+ else
+ {
+ startBand = 0;
+ startPart = 0;
+ stopPart = nFFTpart;
+ while ( startBand < nband )
+ {
+ if ( flag_fft_en || startPart >= nFFTpart )
+ {
+
+ /* first half partition */
+ j = startPart;
+ val = partpow[j];
+ for ( i = startBand; i <= midband[j]; i++ )
+ {
+ bandpow[i] = val;
+ }
+ j++;
+
+ delta = 1;
+ /* inner partitions */
+ for ( ; j < stopPart; j++ )
+ {
+ nint = midband[j] - midband[j - 1];
+ /* log-linear interpolation */ /* Only one new LOG needs to be computed per loop iteration */
+ delta = (float) exp( ( log( partpow[j] + DELTA ) - log( partpow[j - 1] + DELTA ) ) * normReciprocal[nint] );
+ val = partpow[j - 1];
+ for ( ; i < midband[j]; i++ )
+ {
+ val *= delta;
+ bandpow[i] = val;
+ }
+ bandpow[i++] = partpow[j];
+ }
+ if ( delta > 1.f )
+ {
+ delta = 1.f;
+ }
+
+ /* last half partition */
+ val = partpow[stopPart - 1];
+ for ( ; i <= part[stopPart - 1]; i++ )
+ {
+ val *= delta;
+ bandpow[i] = val;
+ }
+ }
+ startBand = part[stopPart - 1] + 1;
+ startPart = stopPart;
+ stopPart = npart;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * getmidbands()
+ *
+ * Get central band for each partition
+ *-------------------------------------------------------------------*/
+
+static void getmidbands(
+ int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */
+ const int16_t npart, /* i : Number of partitions */
+ int16_t *midband, /* o : Central band of each partition */
+ float *psize, /* o : Partition sizes */
+ float *psize_inv /* o : Inverse of partition sizes */
+)
+{
+ int16_t j;
+
+ /* first half partition */
+ midband[0] = part[0];
+ psize[0] = (float) part[0] + 1.f;
+ psize_inv[0] = normReciprocal[part[0] + 1];
+
+ /* inner partitions */ /*part,midband,psize_inv*/
+ for ( j = 1; j < npart; j++ )
+ {
+ midband[j] = ( part[j - 1] + 1 + part[j] ) >> 1;
+ psize[j] = (float) ( part[j] - part[j - 1] );
+ psize_inv[j] = normReciprocal[part[j] - part[j - 1]];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * AnalysisSTFT()
+ *
+ * STFT analysis filterbank
+ *-------------------------------------------------------------------*/
+
+void AnalysisSTFT(
+ const float *timeDomainInput,
+ float *fftBuffer, /* o : FFT bins */
+ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
+)
+{
+ float *olapBuffer = hFdCngCom->olapBufferAna;
+ const float *olapWin = hFdCngCom->olapWinAna;
+
+ /* Shift and cascade for overlap-add */
+ mvr2r( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->fftlen - hFdCngCom->frameSize );
+ mvr2r( timeDomainInput, olapBuffer + hFdCngCom->fftlen - hFdCngCom->frameSize, hFdCngCom->frameSize );
+
+ /* Window the signal */
+ v_mult( olapBuffer, olapWin, fftBuffer, hFdCngCom->fftlen );
+
+ /* Perform FFT */
+ RFFTN( fftBuffer, hFdCngCom->fftSineTab, hFdCngCom->fftlen, -1 );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * SynthesisSTFT()
+ *
+ * STFT synthesis filterbank
+ *-------------------------------------------------------------------*/
+
+void SynthesisSTFT(
+ float *fftBuffer, /* i : FFT bins */
+ float *timeDomainOutput,
+ float *olapBuffer,
+ const float *olapWin,
+ const int16_t tcx_transition,
+ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t nchan_out /* i : number of output channels */
+)
+{
+ int16_t i;
+ float buf[M + 1 + 320], tmp;
+
+ /* Perform IFFT */
+ RFFTN( fftBuffer, hFdCngCom->fftSineTab, hFdCngCom->fftlen, 1 );
+
+ /* Handle overlap in P/S domain for stereo */
+ if ( ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) && nchan_out == 2 )
+ {
+ mvr2r( olapBuffer + 3 * hFdCngCom->frameSize / 4 - ( M + 1 ), buf, hFdCngCom->frameSize + M + 1 );
+ set_f( olapBuffer, 0.0f, hFdCngCom->fftlen );
+ }
+ else
+ {
+ mvr2r( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize );
+ set_f( olapBuffer + hFdCngCom->frameSize, 0.0f, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/
+ }
+
+ if ( tcx_transition )
+ {
+ for ( i = 0; i < 5 * hFdCngCom->frameSize / 4; i++ )
+ {
+ olapBuffer[i] = fftBuffer[i];
+ }
+ }
+ else
+ {
+ for ( i = hFdCngCom->frameSize / 4; i < 3 * hFdCngCom->frameSize / 4; i++ )
+ {
+ olapBuffer[i] += fftBuffer[i] * olapWin[i - hFdCngCom->frameSize / 4];
+ }
+ for ( ; i < 5 * hFdCngCom->frameSize / 4; i++ )
+ {
+ olapBuffer[i] = fftBuffer[i];
+ }
+ }
+ for ( ; i < 7 * hFdCngCom->frameSize / 4; i++ )
+ {
+ olapBuffer[i] = fftBuffer[i] * olapWin[i - 3 * hFdCngCom->frameSize / 4];
+ }
+
+ for ( ; i < hFdCngCom->fftlen; i++ )
+ {
+ olapBuffer[i] = 0;
+ }
+
+ /* Get time-domain signal */
+ v_multc( olapBuffer + hFdCngCom->frameSize / 4, (float) ( hFdCngCom->fftlen / 2 ), timeDomainOutput, hFdCngCom->frameSize );
+
+ /* Get excitation */
+ if ( ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) && nchan_out == 2 )
+ {
+ for ( i = 0; i < hFdCngCom->frameSize / 2; i++ )
+ {
+ buf[i + ( M + 1 )] += olapBuffer[i + hFdCngCom->frameSize / 4];
+ }
+ v_multc( buf, (float) ( hFdCngCom->fftlen / 2 ), buf, M + 1 + hFdCngCom->frameSize );
+ }
+ else
+ {
+ v_multc( olapBuffer + hFdCngCom->frameSize / 4 - ( M + 1 ), (float) ( hFdCngCom->fftlen / 2 ), buf, M + 1 + hFdCngCom->frameSize );
+ }
+
+ tmp = buf[0];
+ preemph( buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp );
+ residu( hFdCngCom->A_cng, M, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * SynthesisSTFT_dirac()
+ *
+ * STFT synthesis filterbank
+ *-------------------------------------------------------------------*/
+
+void SynthesisSTFT_dirac(
+ float *fftBuffer, /* i : FFT bins */
+ float *timeDomainOutput,
+ float *olapBuffer,
+ const float *olapWin,
+ const int16_t samples_out,
+ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
+)
+{
+ int16_t i;
+ float buf[M + 1 + 320], tmp;
+
+ /* Perform IFFT */
+ RFFTN( fftBuffer, hFdCngCom->fftSineTab, hFdCngCom->fftlen, 1 );
+
+ /* Handle overlap in P/S domain for stereo */
+ mvr2r( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize );
+ set_f( olapBuffer + hFdCngCom->frameSize, 0.0f, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/
+
+ for ( i = hFdCngCom->frameSize / 4; i < 3 * hFdCngCom->frameSize / 4; i++ )
+ {
+ olapBuffer[i] += fftBuffer[i] * olapWin[i - hFdCngCom->frameSize / 4];
+ }
+ for ( ; i < 5 * hFdCngCom->frameSize / 4; i++ )
+ {
+ olapBuffer[i] = fftBuffer[i];
+ }
+
+ for ( ; i < 7 * hFdCngCom->frameSize / 4; i++ )
+ {
+ olapBuffer[i] = fftBuffer[i];
+ }
+
+ for ( ; i < hFdCngCom->fftlen; i++ )
+ {
+ olapBuffer[i] = 0;
+ }
+
+ /* Get time-domain signal */
+ v_multc( olapBuffer + hFdCngCom->frameSize / 4, (float) ( hFdCngCom->fftlen / 2 ), timeDomainOutput, samples_out );
+
+ /* Get excitation */
+ v_multc( olapBuffer + hFdCngCom->frameSize / 4 - ( M + 1 ), (float) ( hFdCngCom->fftlen / 2 ), buf, M + 1 + hFdCngCom->frameSize );
+ tmp = buf[0];
+ preemph( buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp );
+ residu( hFdCngCom->A_cng, M, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize );
+
+ /* update and window olapBuf if we have a output frame that is shorter than the default frame size...*/
+ if ( samples_out < hFdCngCom->frameSize )
+ {
+ mvr2r( olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, 3 * hFdCngCom->frameSize / 4 );
+ }
+ for ( i = 5 * hFdCngCom->frameSize / 4; i < 7 * hFdCngCom->frameSize / 4; i++ )
+ {
+ olapBuffer[i] *= olapWin[i - 3 * hFdCngCom->frameSize / 4];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * mhvals()
+ *
+ * Compute some values used in the bias correction of the minimum statistics algorithm
+ *-------------------------------------------------------------------*/
+
+static void mhvals(
+ const int16_t d,
+ float *m )
+{
+ int16_t i, j;
+ float qi, qj, q;
+ int16_t len = SIZE_SCALE_TABLE_CN;
+
+ i = 0;
+ for ( i = 0; i < len; i++ )
+ {
+ if ( d <= d_array[i] )
+ {
+ break;
+ }
+ }
+ if ( i == len )
+ {
+ i = len - 1;
+ j = i;
+ }
+ else
+ {
+ j = i - 1;
+ }
+ if ( d == d_array[i] )
+ {
+ *m = m_array[i];
+ }
+ else
+ {
+ qj = (float) sqrt( (float) d_array[i - 1] ); /*interpolate using sqrt(d)*/
+ qi = (float) sqrt( (float) d_array[i] );
+ q = (float) sqrt( (float) d );
+ *m = m_array[i] + ( qi * qj / q - qj ) * ( m_array[j] - m_array[i] ) / ( qi - qj );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------
+ * rand_gauss()
+ *
+ * Random generator with Gaussian distribution with mean 0 and std 1
+ *-------------------------------------------------------------------*/
+
+float rand_gauss(
+ float *x,
+ int16_t *seed )
+{
+ float temp;
+
+ temp = (float) own_random( seed );
+ temp += (float) own_random( seed );
+ temp += (float) own_random( seed );
+ temp *= OUTMAX_INV;
+
+ *x = temp;
+
+ return temp;
+}
+
+
+/*-------------------------------------------------------------------
+ * lpc_from_spectrum()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void lpc_from_spectrum(
+ HANDLE_FD_CNG_COM hFdCngCom,
+ const int16_t start,
+ const int16_t stop,
+ const float preemph_fac )
+{
+ int16_t i;
+ float r[32], nf;
+ float fftBuffer[FFTLEN], *ptr, *pti;
+
+ float *powspec = hFdCngCom->cngNoiseLevel;
+ int16_t fftlen = hFdCngCom->fftlen;
+ const float *fftSineTab = hFdCngCom->fftSineTab;
+ float *A = hFdCngCom->A_cng;
+
+ /* Power Spectrum */
+ ptr = fftBuffer;
+ pti = fftBuffer + 1;
+ nf = 1e-3f;
+ for ( i = 0; i < start; i++ )
+ {
+ *ptr = nf;
+ *pti = 0.f;
+ ptr += 2;
+ pti += 2;
+ }
+ for ( ; i < stop; i++ )
+ {
+ *ptr = max( nf, powspec[i - start] );
+ *pti = 0.f;
+ ptr += 2;
+ pti += 2;
+ }
+ for ( ; i < fftlen / 2; i++ )
+ {
+ *ptr = nf;
+ *pti = 0.f;
+ ptr += 2;
+ pti += 2;
+ }
+ fftBuffer[1] = nf;
+
+ /* Pre-emphasis */
+ ptr = fftBuffer;
+ for ( i = 0; i < fftlen / 2; i++ )
+ {
+ *ptr *= ( 1.f + preemph_fac * preemph_fac - 2.0f * preemph_fac * (float) cos( -2.0f * EVS_PI * (float) i / (float) fftlen ) );
+
+ ptr += 2;
+ }
+ fftBuffer[1] *= ( 1.f + preemph_fac * preemph_fac + 2.0f * preemph_fac );
+
+ /* Autocorrelation */
+ RFFTN( fftBuffer, fftSineTab, fftlen, 1 );
+ for ( i = 0; i <= M; i++ )
+ {
+ r[i] = fftBuffer[i] * ( fftlen / 2 ) * ( fftlen / 2 );
+ }
+ if ( r[0] < 100.f )
+ {
+ r[0] = 100.f;
+ }
+
+ r[0] *= 1.0005f;
+
+ /* LPC */
+ lev_dur( A, r, M, NULL );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * FdCng_exc()
+ *
+ * Generate FD-CNG as LP excitation
+ *-------------------------------------------------------------------*/
+
+void FdCng_exc(
+ HANDLE_FD_CNG_COM hFdCngCom,
+ int16_t *CNG_mode,
+ const int16_t L_frame,
+ const float *lsp_old,
+ const int16_t first_CNG,
+ float *lspCNG,
+ float *Aq, /* o : LPC coeffs */
+ float *lsp_new, /* o : lsp */
+ float *lsf_new, /* o : lsf */
+ float *exc, /* o : LP excitation */
+ float *exc2, /* o : LP excitation */
+ float *bwe_exc /* o : LP excitation for BWE */
+)
+{
+ int16_t i;
+ *CNG_mode = -1;
+
+ /*Get excitation */
+ for ( i = 0; i < L_frame / L_SUBFR; i++ )
+ {
+ mvr2r( hFdCngCom->A_cng, Aq + i * ( M + 1 ), M + 1 );
+ }
+
+ a2lsp_stab( Aq, lsp_new, lsp_old );
+
+ if ( first_CNG == 0 )
+ {
+ mvr2r( lsp_old, lspCNG, M );
+ }
+
+ for ( i = 0; i < M; i++ )
+ {
+ /* AR low-pass filter */
+ lspCNG[i] = CNG_ISF_FACT * lspCNG[i] + ( 1 - CNG_ISF_FACT ) * lsp_new[i];
+ }
+
+ if ( L_frame == L_FRAME16k )
+ {
+ lsp2lsf( lsp_new, lsf_new, M, INT_FS_16k );
+ }
+ else
+ {
+ lsp2lsf( lsp_new, lsf_new, M, INT_FS_12k8 );
+ }
+
+ mvr2r( hFdCngCom->exc_cng, exc, L_frame );
+ mvr2r( hFdCngCom->exc_cng, exc2, L_frame );
+
+ if ( bwe_exc )
+ {
+ if ( L_frame == L_FRAME )
+ {
+ interp_code_5over2( exc2, bwe_exc, L_frame );
+ }
+ else
+ {
+ interp_code_4over2( exc2, bwe_exc, L_frame );
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/fft.c b/lib_com/fft.c
new file mode 100644
index 0000000000000000000000000000000000000000..e5607dcc3aeb35a9dae5706e4b7bd0f1b693646a
--- /dev/null
+++ b/lib_com/fft.c
@@ -0,0 +1,6767 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4310 )
+#endif
+
+/*-----------------------------------------------------------------*
+ * Local constants
+ *-----------------------------------------------------------------*/
+
+#define FFT_15PONIT_WNK1 0.55901699f /* EDCT & EMDCT constants */
+#define FFT_15PONIT_WNK2 0.95105652f /* EDCT & EMDCT constants */
+#define FFT_15PONIT_WNK3 0.58778525f /* EDCT & EMDCT constants */
+#define FFT_15PONIT_WNK4 0.86602540f /* EDCT & EMDCT constants */
+#define FFT_15PONIT_WNK5 0.25000000f /* EDCT & EMDCT constants */
+
+/* FFT constants */
+#define FFT_C31 -0.8660254037f
+#define FFT_C51 0.9510565195f
+#define FFT_C52 -1.5388417989f
+#define FFT_C53 -0.3632712597f
+#define FFT_C54 0.5590169895f
+#define FFT_C55 -1.2500000000f
+#define FFT_C61 0.8660254036f
+#define FFT_C81 0.7071067811f
+#define FFT_C82 -0.7071067811f
+#define FFT_C161 0.7071067811f
+#define FFT_C162 -0.7071067811f
+#define FFT_C163 0.9238795325f
+#define FFT_C164 -0.9238795325f
+#define FFT_C165 0.3826834323f
+#define FFT_C166 -0.3826834323f
+
+
+/*-----------------------------------------------------------------*
+ * Local function prototypes
+ *-----------------------------------------------------------------*/
+
+static void cdftForw( int16_t n, float *a, const int16_t *ip, const float *w );
+static void bitrv2_SR( int16_t n, const int16_t *ip, float *a );
+static void cftfsub( int16_t n, float *a, const float *w );
+static void cft1st( int16_t n, float *a, const float *w );
+static void cftmdl( int16_t n, int16_t l, float *a, const float *w );
+static void fft16( float *x, float *y, const int16_t *Idx );
+static void fft5_shift1( int16_t n1, float *zRe, float *zIm, const int16_t *Idx );
+static void fft8( float *x, float *y, const int16_t *Idx );
+static void fft15_shift2( int16_t n1, float *zRe, float *zIm, const int16_t *Idx );
+static void fft15_shift8( int16_t n1, float *zRe, float *zIm, const int16_t *Idx );
+static void fft5_shift4( int16_t n1, float *zRe, float *zIm, const int16_t *Idx );
+static void fft5_32( float *zRe, float *zIm, const int16_t *Idx );
+static void fft64( float *x, float *y, const int16_t *Idx );
+static void fft32_15( float *x, float *y, const int16_t *Idx );
+static void fft32_5( float *x, float *y, const int16_t *Idx );
+static void fft8_5( float *x, float *y, const int16_t *Idx );
+static void fft5_8( int16_t n1, float *zRe, float *zIm, const int16_t *Idx );
+static void fft4_5( float *x, float *y, const int16_t *Idx );
+static void fft5_4( int16_t n1, float *zRe, float *zIm, const int16_t *Idx );
+
+static float fmac( float a, float b, float c )
+{
+ return ( ( ( a ) * ( b ) ) + ( c ) );
+}
+
+static float fnms( float a, float b, float c )
+{
+ return ( ( c ) - ( ( a ) * ( b ) ) );
+}
+
+/*-----------------------------------------------------------------*
+ * fft15_shift2()
+ * 15-point FFT with 2-point circular shift
+ *-----------------------------------------------------------------*/
+
+static void fft15_shift2(
+ int16_t n1, /* i : length of data */
+ float *zRe, /* i/o: real part of input and output data */
+ float *zIm, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t in0, in8, in16, in24, in32, in1, in9, in17, in25, in33, in2, in10, in18, in26, in34;
+ float fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8, fi9, fi10, fi11, fi12, fi13, fi14, fi15;
+ float fi16, fi17, fi18, fi19, fi20, fi21, fi22, fi23, fi24, fi25, fi26, fi27, fi28, fi29, fi30;
+ float f2i1, f2i2, f2i3, f2i4, f2i5, f2i6, f2i7, f2i8, f2i9, f2i10, f2i11, f2i12;
+ float f2i13, f2i14, f2i15, f2i16, f2i17, f2i18, f2i19, f2i20, f2i21, f2i22, f2i23, f2i24;
+ float f3i1, f3i2, f3i3, f3i4, f3i5, f3i6, f3i7, f3i8, f3i9, f3i10, f3i11, f3i12, f3i13, f3i14, f3i15;
+ float f4i1, f4i2, f4i3, f4i4, f4i5, f4i6, f4i7, f4i8, f4i9;
+ float f4i10, f4i11, f4i12, f4i13, f4i14, f4i15, f4i16, f4i17, f4i18, f4i19, f4i20, fo1, fo2, fo3, fo4;
+ float fo5, fo6, fo7, fo8, fo9, fo10, fo11, fo12, fo13, fo14, fo15, fo16, fo17, fo18;
+ float f2o1, f2o2, f2o3, f2o4, f2o5, f2o6, f2o7, f2o8, f2o9, f2o10, f2o11, f2o12, f2o13;
+ float f2o14, f2o15, f3o1, f3o2, f3o3, f3o4, f3o5, f3o6, f3o7, f3o8, f3o9, f3o10, f3o11;
+ float f3o12, f3o13, f3o14, f3o15, f4o1, f4o2, f4o3, f4o4, f4o5, f4o6;
+ float f4o7, f4o8, f4o9, f4o10, f4o11, f4o12, f4o13, f4o14, f4o15, f4o16, f4o17, f4o18, f4o19;
+
+ in0 = Idx[0];
+ in8 = Idx[n1];
+ in16 = Idx[n1 * 2];
+ in24 = Idx[n1 * 3];
+ in32 = Idx[n1 * 4];
+ in1 = Idx[n1 * 5];
+ in9 = Idx[n1 * 6];
+ in17 = Idx[n1 * 7];
+ in25 = Idx[n1 * 8];
+ in33 = Idx[n1 * 9];
+ in2 = Idx[n1 * 10];
+ in10 = Idx[n1 * 11];
+ in18 = Idx[n1 * 12];
+ in26 = Idx[n1 * 13];
+ in34 = Idx[n1 * 14];
+
+ f2i13 = zRe[in0];
+ f2i14 = zIm[in0];
+ f2i21 = zRe[in1];
+ f2i22 = zRe[in2];
+ f2i23 = zIm[in1];
+ f2i24 = zIm[in2];
+
+ f2i15 = f2i21 + f2i22;
+ f2i16 = FFT_15PONIT_WNK4 * ( f2i22 - f2i21 );
+ f2i17 = FFT_15PONIT_WNK4 * ( f2i23 - f2i24 );
+ f2i18 = f2i23 + f2i24;
+ fi1 = f2i13 + f2i15;
+ fi2 = f2i14 + f2i18;
+
+ f2i19 = fnms( 0.5f, f2i15, f2i13 );
+ f2i20 = fnms( 0.5f, f2i18, f2i14 );
+ fi3 = f2i19 - f2i17;
+ fi4 = f2i19 + f2i17;
+ fi5 = f2i16 + f2i20;
+ fi6 = f2i20 - f2i16;
+
+ f3i1 = zRe[in9];
+ f4i2 = zRe[in10];
+ f4i3 = zRe[in8];
+ f3i2 = f4i2 + f4i3;
+ f3i3 = fnms( 0.5f, f3i2, f3i1 );
+ f3i4 = FFT_15PONIT_WNK4 * ( f4i3 - f4i2 );
+
+ f3i5 = zIm[in9];
+ f4i4 = zIm[in10];
+ f4i5 = zIm[in8];
+ f3i6 = f4i4 + f4i5;
+ f3i7 = FFT_15PONIT_WNK4 * ( f4i4 - f4i5 );
+ f3i8 = fnms( 0.5f, f3i6, f3i5 );
+
+ f3i9 = zRe[in33];
+ f4i6 = zRe[in34];
+ f4i7 = zRe[in32];
+ f3i10 = f4i6 + f4i7;
+ f3i11 = fnms( 0.5f, f3i10, f3i9 );
+ f3i12 = FFT_15PONIT_WNK4 * ( f4i7 - f4i6 );
+
+ f3i13 = zIm[in33];
+ f4i8 = zIm[in34];
+ f4i9 = zIm[in32];
+ f3i14 = f4i8 + f4i9;
+ f3i15 = FFT_15PONIT_WNK4 * ( f4i8 - f4i9 );
+ f4i1 = fnms( 0.5f, f3i14, f3i13 );
+
+ fi7 = f3i1 + f3i2;
+ fi8 = f3i9 + f3i10;
+ fi9 = fi7 + fi8;
+ fi10 = f3i3 - f3i7;
+ fi11 = f3i11 - f3i15;
+ fi12 = fi10 + fi11;
+ fi13 = f3i5 + f3i6;
+ fi14 = f3i13 + f3i14;
+ fi15 = fi13 + fi14;
+ fi16 = f3i8 - f3i4;
+ fi17 = f4i1 - f3i12;
+ fi18 = fi16 + fi17;
+ fi19 = f3i4 + f3i8;
+ fi20 = f3i12 + f4i1;
+ fi21 = fi19 + fi20;
+ fi22 = f3i3 + f3i7;
+ fi23 = f3i11 + f3i15;
+ fi24 = fi22 + fi23;
+
+ f4i10 = zRe[in24];
+ fo6 = zRe[in25];
+ fo7 = zRe[in26];
+ f4i11 = fo6 + fo7;
+ f4i12 = fnms( 0.5f, f4i11, f4i10 );
+ f4i13 = FFT_15PONIT_WNK4 * ( fo7 - fo6 );
+
+ f4i14 = zIm[in24];
+ fo8 = zIm[in25];
+ fo9 = zIm[in26];
+ f4i15 = fo8 + fo9;
+ f4i16 = FFT_15PONIT_WNK4 * ( fo8 - fo9 );
+ f4i17 = fnms( 0.5f, f4i15, f4i14 );
+
+ f4i18 = zRe[in18];
+ f2o10 = zRe[in16];
+ f2o11 = zRe[in17];
+ f4i19 = f2o10 + f2o11;
+ f4i20 = fnms( 0.5f, f4i19, f4i18 );
+ fo1 = FFT_15PONIT_WNK4 * ( f2o11 - f2o10 );
+
+ fo2 = zIm[in18];
+ f2o12 = zIm[in16];
+ f2o13 = zIm[in17];
+ fo3 = f2o12 + f2o13;
+ fo4 = FFT_15PONIT_WNK4 * ( f2o12 - f2o13 );
+ fo5 = fnms( 0.5f, fo3, fo2 );
+
+ fi25 = f4i10 + f4i11;
+ fi26 = f4i18 + f4i19;
+ fi27 = fi25 + fi26;
+ fi28 = f4i12 - f4i16;
+ fi29 = f4i20 - fo4;
+ fi30 = fi28 + fi29;
+ f2i1 = f4i14 + f4i15;
+ f2i2 = fo2 + fo3;
+ f2i3 = f2i1 + f2i2;
+ f2i4 = f4i17 - f4i13;
+ f2i5 = fo5 - fo1;
+ f2i6 = f2i4 + f2i5;
+ f2i7 = f4i13 + f4i17;
+ f2i8 = fo1 + fo5;
+ f2i9 = f2i7 + f2i8;
+ f2i10 = f4i12 + f4i16;
+ f2i11 = f4i20 + fo4;
+ f2i12 = f2i10 + f2i11;
+
+ fo10 = FFT_15PONIT_WNK1 * ( fi27 - fi9 );
+ fo11 = fi27 + fi9;
+ fo12 = fnms( FFT_15PONIT_WNK5, fo11, fi1 );
+ fo15 = fi13 - fi14;
+ fo16 = f2i1 - f2i2;
+ fo13 = fnms( FFT_15PONIT_WNK3, fo16, FFT_15PONIT_WNK2 * fo15 );
+ fo14 = fmac( FFT_15PONIT_WNK2, fo16, FFT_15PONIT_WNK3 * fo15 );
+
+ zRe[in0] = fi1 + fo11;
+ fo17 = fo10 + fo12;
+ zRe[in18] = fo17 - fo14;
+ zRe[in24] = fo17 + fo14;
+ fo18 = fo12 - fo10;
+ zRe[in9] = fo18 - fo13;
+ zRe[in33] = fo18 + fo13;
+
+ f2o1 = FFT_15PONIT_WNK1 * ( f2i3 - fi15 );
+ f2o2 = f2i3 + fi15;
+ f2o3 = fnms( FFT_15PONIT_WNK5, f2o2, fi2 );
+ f2o6 = fi7 - fi8;
+ f2o7 = fi25 - fi26;
+ f2o4 = fnms( FFT_15PONIT_WNK3, f2o7, FFT_15PONIT_WNK2 * f2o6 );
+ f2o5 = fmac( FFT_15PONIT_WNK2, f2o7, FFT_15PONIT_WNK3 * f2o6 );
+ zIm[in0] = fi2 + f2o2;
+ f2o8 = f2o1 + f2o3;
+ zIm[in24] = f2o8 - f2o5;
+ zIm[in18] = f2o5 + f2o8;
+ f2o9 = f2o3 - f2o1;
+ zIm[in33] = f2o9 - f2o4;
+ zIm[in9] = f2o4 + f2o9;
+
+ f2o14 = FFT_15PONIT_WNK1 * ( fi30 - fi12 );
+ f2o15 = fi30 + fi12;
+ f3o1 = fnms( FFT_15PONIT_WNK5, f2o15, fi3 );
+ f3o4 = fi16 - fi17;
+ f3o5 = f2i4 - f2i5;
+ f3o2 = fnms( FFT_15PONIT_WNK3, f3o5, FFT_15PONIT_WNK2 * f3o4 );
+ f3o3 = fmac( FFT_15PONIT_WNK2, f3o5, FFT_15PONIT_WNK3 * f3o4 );
+ zRe[in2] = fi3 + f2o15;
+ f3o6 = f2o14 + f3o1;
+ zRe[in17] = f3o6 - f3o3;
+ zRe[in26] = f3o6 + f3o3;
+ f3o7 = f3o1 - f2o14;
+ zRe[in8] = f3o7 - f3o2;
+ zRe[in32] = f3o7 + f3o2;
+
+ f3o8 = FFT_15PONIT_WNK1 * ( f2i6 - fi18 );
+ f3o9 = f2i6 + fi18;
+ f3o10 = fnms( FFT_15PONIT_WNK5, f3o9, fi6 );
+ f3o13 = fi10 - fi11;
+ f3o14 = fi28 - fi29;
+ f3o11 = fnms( FFT_15PONIT_WNK3, f3o14, FFT_15PONIT_WNK2 * f3o13 );
+ f3o12 = fmac( FFT_15PONIT_WNK2, f3o14, FFT_15PONIT_WNK3 * f3o13 );
+ zIm[in2] = fi6 + f3o9;
+ f3o15 = f3o8 + f3o10;
+ zIm[in26] = f3o15 - f3o12;
+ zIm[in17] = f3o12 + f3o15;
+ f4o1 = f3o10 - f3o8;
+ zIm[in8] = f3o11 + f4o1;
+ zIm[in32] = f4o1 - f3o11;
+
+ f4o2 = FFT_15PONIT_WNK1 * ( f2i9 - fi21 );
+ f4o3 = f2i9 + fi21;
+ f4o4 = fnms( FFT_15PONIT_WNK5, f4o3, fi5 );
+ f4o7 = f2i10 - f2i11;
+ f4o8 = fi22 - fi23;
+ f4o5 = fmac( FFT_15PONIT_WNK2, f4o7, FFT_15PONIT_WNK3 * f4o8 );
+ f4o6 = fnms( FFT_15PONIT_WNK3, f4o7, FFT_15PONIT_WNK2 * f4o8 );
+ zIm[in1] = fi5 + f4o3;
+ f4o9 = f4o4 - f4o2;
+ f4o10 = f4o2 + f4o4;
+
+ zIm[in10] = f4o6 + f4o9;
+ zIm[in34] = f4o9 - f4o6;
+ zIm[in25] = f4o10 - f4o5;
+ zIm[in16] = f4o5 + f4o10;
+
+ f4o11 = FFT_15PONIT_WNK1 * ( f2i12 - fi24 );
+ f4o12 = f2i12 + fi24;
+ f4o13 = fnms( FFT_15PONIT_WNK5, f4o12, fi4 );
+ f4o16 = f2i7 - f2i8;
+ f4o17 = fi19 - fi20;
+ f4o14 = fmac( FFT_15PONIT_WNK2, f4o16, FFT_15PONIT_WNK3 * f4o17 );
+ f4o15 = fnms( FFT_15PONIT_WNK3, f4o16, FFT_15PONIT_WNK2 * f4o17 );
+ zRe[in1] = fi4 + f4o12;
+ f4o18 = f4o13 - f4o11;
+ f4o19 = f4o11 + f4o13;
+
+ zRe[in10] = f4o18 - f4o15;
+ zRe[in34] = f4o18 + f4o15;
+ zRe[in16] = f4o19 - f4o14;
+ zRe[in25] = f4o19 + f4o14;
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft15_shift8()
+ * 15-point FFT with 8-point circular shift
+ *-----------------------------------------------------------------*/
+
+static void fft15_shift8(
+ int16_t n1, /* i : length of data */
+ float *zRe, /* i/o: real part of input and output data */
+ float *zIm, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t in0, in8, in16, in24, in32, in1, in9, in17, in25, in33, in2, in10, in18, in26, in34;
+ float fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8, fi9, fi10, fi11, fi12, fi13, fi14, fi15;
+ float fi16, fi17, fi18, fi19, fi20, fi21, fi22, fi23, fi24, fi25, fi26, fi27, fi28, fi29, fi30;
+ float f2i1, f2i2, f2i3, f2i4, f2i5, f2i6, f2i7, f2i8, f2i9, f2i10, f2i11, f2i12;
+ float f2i13, f2i14, f2i15, f3i1, f3i2, f3i3, f3i4, f3i5, f3i6, f3i7, f3i8, f3i9;
+ float f3i10, f3i11, f3i12, f3i13, f3i14, f3i15, f4i1, f4i2, f4i3, f4i4, f4i5, f4i6, f4i7, f4i8, f4i9;
+ float f4i10, f4i11, f4i12, f4i13, f4i14, f4i15, fo1, fo2, fo3, fo4, fo5, fo6;
+ float fo7, fo8, fo9, fo10, fo11, fo12, fo13, fo14, fo15, f2o1, f2o2, f2o3, f2o4;
+ float f2o5, f2o6, f2o7, f2o8, f2o9, f2o10, f2o11, f2o12, f2o13, f2o14, f2o15;
+ float f3o1, f3o2, f3o3, f3o4, f3o5, f3o6, f3o7, f3o8, f3o9, f3o10, f3o11, f3o12;
+ float f3o13, f3o14, f3o15, f4o1, f4o2, f4o3, f4o4, f4o5, f4o6, f4o7, f4o8, f4o9;
+ float f4o10, f4o11, f4o12, f4o13, f4o14, f4o15, f5o1, f5o2, f5o3, f5o4, f5o5, f5o6, f5o7;
+ float f5o8, f5o9, f5o10, f5o11, f5o12, f5o13, f5o14, f5o15, f5o16, f5o17, f5o18, f5o19, f5o21, f5o22;
+
+ in0 = Idx[0];
+ in8 = Idx[n1];
+ in16 = Idx[n1 * 2];
+ in24 = Idx[n1 * 3];
+ in32 = Idx[n1 * 4];
+ in1 = Idx[n1 * 5];
+ in9 = Idx[n1 * 6];
+ in17 = Idx[n1 * 7];
+ in25 = Idx[n1 * 8];
+ in33 = Idx[n1 * 9];
+ in2 = Idx[n1 * 10];
+ in10 = Idx[n1 * 11];
+ in18 = Idx[n1 * 12];
+ in26 = Idx[n1 * 13];
+ in34 = Idx[n1 * 14];
+
+ f2i13 = zRe[in0];
+ f2i14 = zIm[in0];
+ f3i6 = zRe[in1];
+ f3i7 = zRe[in2];
+ f3i8 = zIm[in1];
+ f3i9 = zIm[in2];
+
+ f2i15 = f3i6 + f3i7;
+ f3i1 = FFT_15PONIT_WNK4 * ( f3i7 - f3i6 );
+ f3i2 = FFT_15PONIT_WNK4 * ( f3i8 - f3i9 );
+ f3i3 = f3i8 + f3i9;
+
+ fi1 = f2i13 + f2i15;
+ fi2 = f2i14 + f3i3;
+ f3i4 = fnms( 0.5f, f2i15, f2i13 );
+ fi3 = f3i4 - f3i2;
+ fi4 = f3i4 + f3i2;
+ f3i5 = fnms( 0.5f, f3i3, f2i14 );
+ fi5 = f3i1 + f3i5;
+ fi6 = f3i5 - f3i1;
+
+ f3i10 = zRe[in9];
+ f4i11 = zRe[in10];
+ f4i12 = zRe[in8];
+ f3i14 = zIm[in9];
+ f4i13 = zIm[in10];
+ f4i14 = zIm[in8];
+ f4i3 = zRe[in33];
+ f4i15 = zRe[in34];
+ fo1 = zRe[in32];
+ f4i7 = zIm[in33];
+ fo2 = zIm[in34];
+ fo3 = zIm[in32];
+
+
+ f3i11 = f4i11 + f4i12;
+ f3i12 = fnms( 0.5f, f3i11, f3i10 );
+ f3i13 = FFT_15PONIT_WNK4 * ( f4i12 - f4i11 );
+ f3i15 = f4i13 + f4i14;
+ f4i1 = FFT_15PONIT_WNK4 * ( f4i13 - f4i14 );
+ f4i2 = fnms( 0.5f, f3i15, f3i14 );
+ f4i4 = f4i15 + fo1;
+ f4i5 = fnms( 0.5f, f4i4, f4i3 );
+ f4i6 = FFT_15PONIT_WNK4 * ( fo1 - f4i15 );
+ f4i8 = fo2 + fo3;
+ f4i9 = FFT_15PONIT_WNK4 * ( fo2 - fo3 );
+ f4i10 = fnms( 0.5f, f4i8, f4i7 );
+
+ fi7 = f3i10 + f3i11;
+ fi8 = f4i3 + f4i4;
+ fi9 = fi7 + fi8;
+ fi10 = f3i12 - f4i1;
+ fi11 = f4i5 - f4i9;
+ fi12 = fi10 + fi11;
+ fi13 = f3i14 + f3i15;
+ fi14 = f4i7 + f4i8;
+ fi15 = fi13 + fi14;
+ fi16 = f4i2 - f3i13;
+ fi17 = f4i10 - f4i6;
+ fi18 = fi16 + fi17;
+ fi19 = f3i13 + f4i2;
+ fi20 = f4i6 + f4i10;
+ fi21 = fi19 + fi20;
+ fi22 = f3i12 + f4i1;
+ fi23 = f4i5 + f4i9;
+ fi24 = fi22 + fi23;
+
+ fo4 = zRe[in24];
+ f2o5 = zRe[in25];
+ f2o6 = zRe[in26];
+ fo8 = zIm[in24];
+ f2o7 = zIm[in25];
+ f2o8 = zIm[in26];
+ fo12 = zRe[in18];
+ f2o9 = zRe[in16];
+ f2o10 = zRe[in17];
+ f2o1 = zIm[in18];
+ f2o11 = zIm[in16];
+ f2o12 = zIm[in17];
+
+
+ fo5 = f2o5 + f2o6;
+ fo6 = fnms( 0.5f, fo5, fo4 );
+ fo7 = FFT_15PONIT_WNK4 * ( f2o6 - f2o5 );
+ fo9 = f2o7 + f2o8;
+ fo10 = FFT_15PONIT_WNK4 * ( f2o7 - f2o8 );
+ fo11 = fnms( 0.5f, fo9, fo8 );
+ fo13 = f2o9 + f2o10;
+ fo14 = fnms( 0.5f, fo13, fo12 );
+ fo15 = FFT_15PONIT_WNK4 * ( f2o10 - f2o9 );
+ f2o2 = f2o11 + f2o12;
+ f2o3 = FFT_15PONIT_WNK4 * ( f2o11 - f2o12 );
+ f2o4 = fnms( 0.5f, f2o2, f2o1 );
+
+ fi25 = fo4 + fo5;
+ fi26 = fo12 + fo13;
+ fi27 = fi25 + fi26;
+ fi28 = fo6 - fo10;
+ fi29 = fo14 - f2o3;
+ fi30 = fi28 + fi29;
+ f2i1 = fo8 + fo9;
+ f2i2 = f2o1 + f2o2;
+ f2i3 = f2i1 + f2i2;
+ f2i4 = fo11 - fo7;
+ f2i5 = f2o4 - fo15;
+ f2i6 = f2i4 + f2i5;
+ f2i7 = fo7 + fo11;
+ f2i8 = fo15 + f2o4;
+ f2i9 = f2i7 + f2i8;
+ f2i10 = fo6 + fo10;
+ f2i11 = fo14 + f2o3;
+ f2i12 = f2i10 + f2i11;
+
+ f2o13 = FFT_15PONIT_WNK1 * ( fi27 - fi9 );
+ f2o14 = fi27 + fi9;
+ f2o15 = fnms( FFT_15PONIT_WNK5, f2o14, fi1 );
+ f3o3 = fi13 - fi14;
+ f3o4 = f2i1 - f2i2;
+ f3o1 = fnms( FFT_15PONIT_WNK3, f3o4, FFT_15PONIT_WNK2 * f3o3 );
+ f3o2 = fmac( FFT_15PONIT_WNK2, f3o4, FFT_15PONIT_WNK3 * f3o3 );
+ zRe[in0] = fi1 + f2o14;
+ f3o5 = f2o13 + f2o15;
+ zRe[in24] = f3o5 - f3o2;
+ zRe[in18] = f3o5 + f3o2;
+ f3o6 = f2o15 - f2o13;
+ zRe[in33] = f3o6 - f3o1;
+ zRe[in9] = f3o6 + f3o1;
+
+ f3o7 = FFT_15PONIT_WNK1 * ( f2i3 - fi15 );
+ f3o8 = f2i3 + fi15;
+ f3o9 = fnms( FFT_15PONIT_WNK5, f3o8, fi2 );
+ f3o12 = fi7 - fi8;
+ f3o13 = fi25 - fi26;
+ f3o10 = fnms( FFT_15PONIT_WNK3, f3o13, FFT_15PONIT_WNK2 * f3o12 );
+ f3o11 = fmac( FFT_15PONIT_WNK2, f3o13, FFT_15PONIT_WNK3 * f3o12 );
+ zIm[in0] = fi2 + f3o8;
+ f3o14 = f3o7 + f3o9;
+ zIm[in18] = f3o14 - f3o11;
+ zIm[in24] = f3o11 + f3o14;
+ f3o15 = f3o9 - f3o7;
+ zIm[in9] = f3o15 - f3o10;
+ zIm[in33] = f3o10 + f3o15;
+
+ f4o1 = FFT_15PONIT_WNK1 * ( fi30 - fi12 );
+ f4o2 = fi30 + fi12;
+ f4o3 = fnms( FFT_15PONIT_WNK5, f4o2, fi3 );
+ f4o6 = fi16 - fi17;
+ f4o7 = f2i4 - f2i5;
+ f4o4 = fnms( FFT_15PONIT_WNK3, f4o7, FFT_15PONIT_WNK2 * f4o6 );
+ f4o5 = fmac( FFT_15PONIT_WNK2, f4o7, FFT_15PONIT_WNK3 * f4o6 );
+ zRe[in2] = fi3 + f4o2;
+ f4o8 = f4o1 + f4o3;
+ zRe[in26] = f4o8 - f4o5;
+ zRe[in17] = f4o8 + f4o5;
+ f4o9 = f4o3 - f4o1;
+ zRe[in32] = f4o9 - f4o4;
+ zRe[in8] = f4o9 + f4o4;
+
+ f4o10 = FFT_15PONIT_WNK1 * ( f2i6 - fi18 );
+ f4o11 = f2i6 + fi18;
+ f4o12 = fnms( FFT_15PONIT_WNK5, f4o11, fi6 );
+ f4o15 = fi10 - fi11;
+ f5o1 = fi28 - fi29;
+ f4o13 = fnms( FFT_15PONIT_WNK3, f5o1, FFT_15PONIT_WNK2 * f4o15 );
+ f4o14 = fmac( FFT_15PONIT_WNK2, f5o1, FFT_15PONIT_WNK3 * f4o15 );
+ zIm[in2] = fi6 + f4o11;
+ f5o2 = f4o10 + f4o12;
+ zIm[in17] = f5o2 - f4o14;
+ zIm[in26] = f4o14 + f5o2;
+ f5o3 = f4o12 - f4o10;
+ zIm[in32] = f4o13 + f5o3;
+ zIm[in8] = f5o3 - f4o13;
+
+ f5o4 = FFT_15PONIT_WNK1 * ( f2i9 - fi21 );
+ f5o5 = f2i9 + fi21;
+ f5o6 = fnms( FFT_15PONIT_WNK5, f5o5, fi5 );
+ f5o9 = f2i10 - f2i11;
+ f5o10 = fi22 - fi23;
+ f5o7 = fmac( FFT_15PONIT_WNK2, f5o9, FFT_15PONIT_WNK3 * f5o10 );
+ f5o8 = fnms( FFT_15PONIT_WNK3, f5o9, FFT_15PONIT_WNK2 * f5o10 );
+ zIm[in1] = fi5 + f5o5;
+ f5o11 = f5o6 - f5o4;
+ f5o12 = f5o4 + f5o6;
+ zIm[in34] = f5o8 + f5o11;
+ zIm[in10] = f5o11 - f5o8;
+
+ zIm[in16] = f5o12 - f5o7;
+ zIm[in25] = f5o7 + f5o12;
+
+ f5o13 = FFT_15PONIT_WNK1 * ( f2i12 - fi24 );
+ f5o14 = f2i12 + fi24;
+ f5o15 = fnms( FFT_15PONIT_WNK5, f5o14, fi4 );
+ f5o18 = f2i7 - f2i8;
+ f5o19 = fi19 - fi20;
+ f5o16 = fmac( FFT_15PONIT_WNK2, f5o18, FFT_15PONIT_WNK3 * f5o19 );
+ f5o17 = fnms( FFT_15PONIT_WNK3, f5o18, FFT_15PONIT_WNK2 * f5o19 );
+ zRe[in1] = fi4 + f5o14;
+ f5o21 = f5o15 - f5o13;
+ f5o22 = f5o13 + f5o15;
+
+ zRe[in34] = f5o21 - f5o17;
+ zRe[in10] = f5o21 + f5o17;
+ zRe[in25] = f5o22 - f5o16;
+ zRe[in16] = f5o22 + f5o16;
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft5_shift1()
+ * 5-point FFT with 1-point circular shift
+ *-----------------------------------------------------------------*/
+
+static void fft5_shift1(
+ int16_t n1, /* i : length of data */
+ float *zRe, /* i/o: real part of input and output data */
+ float *zIm, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ float fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8;
+ float fo1, fo2, fo3, fo4, fo5, fo6, fo7, fo8;
+ int16_t in1, in2, in3, in4, in5;
+
+ in1 = Idx[0];
+ in2 = Idx[n1];
+ in3 = Idx[n1 * 2];
+ in4 = Idx[n1 * 3];
+ in5 = Idx[n1 * 4];
+
+ fi1 = zRe[in1];
+ fi2 = zIm[in1];
+ fo3 = zRe[in2];
+ fo4 = zRe[in5];
+ fo6 = zRe[in3];
+ fo7 = zRe[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi3 = fo5 + fo8;
+ fi4 = fo6 - fo7;
+ fi5 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+ fi6 = fo3 - fo4;
+
+ fo3 = zIm[in2];
+ fo4 = zIm[in5];
+ fo6 = zIm[in3];
+ fo7 = zIm[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi7 = fo3 - fo4;
+ fi8 = fo5 + fo8;
+ fo1 = fo6 - fo7;
+ fo2 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+
+ zRe[in1] = fi1 + fi3;
+ zIm[in1] = fi2 + fi8;
+
+ fo3 = FFT_15PONIT_WNK2 * fi7 + FFT_15PONIT_WNK3 * fo1;
+ fo4 = FFT_15PONIT_WNK2 * fo1 - FFT_15PONIT_WNK3 * fi7;
+ fo7 = fi1 - fi3 / 4;
+ fo5 = fi5 + fo7;
+ fo6 = fo7 - fi5;
+
+ zRe[in2] = fo5 + fo3;
+ zRe[in3] = fo6 - fo4;
+ zRe[in4] = fo6 + fo4;
+ zRe[in5] = fo5 - fo3;
+
+ fo3 = FFT_15PONIT_WNK2 * fi6 + FFT_15PONIT_WNK3 * fi4;
+ fo4 = FFT_15PONIT_WNK2 * fi4 - FFT_15PONIT_WNK3 * fi6;
+ fo7 = fi2 - fi8 / 4;
+ fo5 = fo2 + fo7;
+ fo6 = fo7 - fo2;
+
+ zIm[in2] = fo5 - fo3;
+ zIm[in3] = fo4 + fo6;
+ zIm[in4] = fo6 - fo4;
+ zIm[in5] = fo3 + fo5;
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft5_shift4()
+ * 5-point FFT with 4-point circular shift
+ *-----------------------------------------------------------------*/
+
+static void fft5_shift4(
+ int16_t n1, /* i : length of data */
+ float *zRe, /* i/o: real part of input and output data */
+ float *zIm, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ float fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8;
+ float fo1, fo2, fo3, fo4, fo5, fo6, fo7, fo8;
+ int16_t in1, in2, in3, in4, in5;
+
+ in1 = Idx[0];
+ in2 = Idx[n1];
+ in3 = Idx[n1 * 2];
+ in4 = Idx[n1 * 3];
+ in5 = Idx[n1 * 4];
+
+ fi1 = zRe[in1];
+ fi2 = zIm[in1];
+ fo3 = zRe[in2];
+ fo4 = zRe[in5];
+ fo6 = zRe[in3];
+ fo7 = zRe[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi3 = fo5 + fo8;
+ fi4 = fo6 - fo7;
+ fi5 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+ fi6 = fo3 - fo4;
+
+ fo3 = zIm[in2];
+ fo4 = zIm[in5];
+ fo6 = zIm[in3];
+ fo7 = zIm[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi7 = fo3 - fo4;
+ fi8 = fo5 + fo8;
+ fo1 = fo6 - fo7;
+ fo2 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+
+ zRe[in1] = fi1 + fi3;
+ zIm[in1] = fi2 + fi8;
+
+ fo3 = FFT_15PONIT_WNK2 * fi7 + FFT_15PONIT_WNK3 * fo1;
+ fo4 = FFT_15PONIT_WNK2 * fo1 - FFT_15PONIT_WNK3 * fi7;
+ fo7 = fi1 - fi3 / 4;
+ fo5 = fi5 + fo7;
+ fo6 = fo7 - fi5;
+ zRe[in2] = fo5 - fo3;
+ zRe[in4] = fo6 - fo4;
+ zRe[in3] = fo6 + fo4;
+ zRe[in5] = fo5 + fo3;
+
+ fo3 = FFT_15PONIT_WNK2 * fi6 + FFT_15PONIT_WNK3 * fi4;
+ fo4 = FFT_15PONIT_WNK2 * fi4 - FFT_15PONIT_WNK3 * fi6;
+ fo7 = fi2 - fi8 / 4;
+ fo5 = fo2 + fo7;
+ fo6 = fo7 - fo2;
+
+ zIm[in3] = fo6 - fo4;
+ zIm[in2] = fo3 + fo5;
+ zIm[in4] = fo4 + fo6;
+ zIm[in5] = fo5 - fo3;
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft5_32()
+ * 5-point FFT called for 32 times
+ *-----------------------------------------------------------------*/
+
+static void fft5_32(
+ float *zRe, /* i/o: real part of input and output data */
+ float *zIm, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ float fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8;
+ float fo1, fo2, fo3, fo4, fo5, fo6, fo7, fo8;
+ int16_t in1, in2, in3, in4, in5;
+
+ in1 = Idx[0];
+ in2 = Idx[32];
+ in3 = Idx[64];
+ in4 = Idx[96];
+ in5 = Idx[128];
+
+ fi1 = zRe[in1];
+ fi2 = zIm[in1];
+ fo3 = zRe[in2];
+ fo4 = zRe[in5];
+ fo6 = zRe[in3];
+ fo7 = zRe[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi3 = fo5 + fo8;
+ fi4 = fo6 - fo7;
+ fi5 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+ fi6 = fo3 - fo4;
+
+ fo3 = zIm[in2];
+ fo4 = zIm[in5];
+ fo6 = zIm[in3];
+ fo7 = zIm[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi7 = fo3 - fo4;
+ fi8 = fo5 + fo8;
+ fo1 = fo6 - fo7;
+ fo2 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+
+ zRe[in1] = fi1 + fi3;
+ zIm[in1] = fi2 + fi8;
+
+ fo3 = FFT_15PONIT_WNK2 * fi7 + FFT_15PONIT_WNK3 * fo1;
+ fo4 = FFT_15PONIT_WNK2 * fo1 - FFT_15PONIT_WNK3 * fi7;
+ fo7 = fi1 - fi3 / 4;
+ fo5 = fi5 + fo7;
+ fo6 = fo7 - fi5;
+
+ zRe[in2] = fo6 + fo4;
+ zRe[in3] = fo5 + fo3;
+ zRe[in4] = fo5 - fo3;
+ zRe[in5] = fo6 - fo4;
+
+ fo3 = FFT_15PONIT_WNK2 * fi6 + FFT_15PONIT_WNK3 * fi4;
+ fo4 = FFT_15PONIT_WNK2 * fi4 - FFT_15PONIT_WNK3 * fi6;
+ fo7 = fi2 - fi8 / 4;
+ fo5 = fo2 + fo7;
+ fo6 = fo7 - fo2;
+
+ zIm[in2] = fo6 - fo4;
+ zIm[in3] = fo5 - fo3;
+ zIm[in4] = fo3 + fo5;
+ zIm[in5] = fo4 + fo6;
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft64()
+ * 64-point FFT
+ *-----------------------------------------------------------------*/
+
+static void fft64(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t i, id, jd;
+ float z[128];
+ for ( i = 0; i < 64; i++ )
+ {
+ id = Idx[i];
+ z[2 * i] = x[id];
+ z[2 * i + 1] = y[id];
+ }
+
+ cdftForw( 128, z, Ip_fft64, w_fft64 );
+
+ for ( i = 0; i < 64; i++ )
+ {
+ jd = Odx_fft64[i];
+ id = Idx[jd];
+ x[id] = z[2 * i];
+ y[id] = z[2 * i + 1];
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------*
+ * fft32_15()
+ * 32-point FFT called for 15 times
+ *-----------------------------------------------------------------*/
+
+static void fft32_15(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t i, id, jd;
+ float z[64];
+
+ for ( i = 0; i < 32; i++ )
+ {
+ id = Idx[i];
+ z[2 * i] = x[id];
+ z[2 * i + 1] = y[id];
+ }
+
+ cdftForw( 64, z, Ip_fft32, w_fft32 );
+
+ for ( i = 0; i < 32; i++ )
+ {
+ jd = Odx_fft32_15[i];
+ id = Idx[jd];
+ x[id] = z[2 * i];
+ y[id] = z[2 * i + 1];
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft32_5()
+ * 32-point FFT called for 5 times
+ *-----------------------------------------------------------------*/
+
+static void fft32_5(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t i, id, jd;
+ float z[64];
+
+ for ( i = 0; i < 32; i++ )
+ {
+ id = Idx[i];
+ z[2 * i] = x[id];
+ z[2 * i + 1] = y[id];
+ }
+
+ cdftForw( 64, z, Ip_fft32, w_fft32 );
+
+ for ( i = 0; i < 32; i++ )
+ {
+ jd = Odx_fft32_5[i];
+ id = Idx[jd];
+ x[id] = z[2 * i];
+ y[id] = z[2 * i + 1];
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft16()
+ * 16-point FFT
+ *-----------------------------------------------------------------*/
+
+static void fft16(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t i, id, jd;
+ float z[32];
+
+ for ( i = 0; i < 16; i++ )
+ {
+ id = Idx[i];
+ z[2 * i] = x[id];
+ z[2 * i + 1] = y[id];
+ }
+
+ cdftForw( 32, z, Ip_fft16, w_fft16 );
+
+ for ( i = 0; i < 16; i++ )
+ {
+ jd = Odx_fft16[i];
+ id = Idx[jd];
+ x[id] = z[2 * i];
+ y[id] = z[2 * i + 1];
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft8()
+ * 8-point FFT
+ *-----------------------------------------------------------------*/
+
+static void fft8(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t i, id;
+ float z[16];
+
+ for ( i = 0; i < 8; i++ )
+ {
+ id = Idx[i];
+ z[2 * i] = x[id];
+ z[2 * i + 1] = y[id];
+ }
+
+ cdftForw( 16, z, Ip_fft8, w_fft8 );
+
+ for ( i = 0; i < 8; i++ )
+ {
+ id = Idx[i];
+ x[id] = z[2 * i];
+ y[id] = z[2 * i + 1];
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft8_5()
+ * 8-point FFT with shift 5
+ *-----------------------------------------------------------------*/
+
+static void fft8_5(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t i, id, jd;
+ float z[16];
+
+ for ( i = 0; i < 8; i++ )
+ {
+ id = Idx[i];
+ z[2 * i] = x[id];
+ z[2 * i + 1] = y[id];
+ }
+
+ cdftForw( 16, z, Ip_fft8, w_fft8 );
+
+ for ( i = 0; i < 8; i++ )
+ {
+ jd = Odx_fft8_5[i];
+ id = Idx[jd];
+ x[id] = z[2 * i];
+ y[id] = z[2 * i + 1];
+ }
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft5_8()
+ * 5-point FFT with shift 2
+ *-----------------------------------------------------------------*/
+
+static void fft5_8(
+ int16_t n1, /* i : length of data */
+ float *zRe, /* i/o: real part of input and output data */
+ float *zIm, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ float fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8;
+ float fo1, fo2, fo3, fo4, fo5, fo6, fo7, fo8;
+ int16_t in1, in2, in3, in4, in5;
+
+ in1 = Idx[0];
+ in2 = Idx[n1];
+ in3 = Idx[n1 * 2];
+ in4 = Idx[n1 * 3];
+ in5 = Idx[n1 * 4];
+
+ fi1 = zRe[in1];
+ fi2 = zIm[in1];
+ fo3 = zRe[in2];
+ fo4 = zRe[in5];
+ fo6 = zRe[in3];
+ fo7 = zRe[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi3 = fo5 + fo8;
+ fi4 = fo6 - fo7;
+ fi5 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+ fi6 = fo3 - fo4;
+
+ fo3 = zIm[in2];
+ fo4 = zIm[in5];
+ fo6 = zIm[in3];
+ fo7 = zIm[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi7 = fo3 - fo4;
+ fi8 = fo5 + fo8;
+ fo1 = fo6 - fo7;
+ fo2 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+
+ zRe[in1] = fi1 + fi3;
+ zIm[in1] = fi2 + fi8;
+
+ fo3 = FFT_15PONIT_WNK2 * fi7 + FFT_15PONIT_WNK3 * fo1;
+ fo4 = FFT_15PONIT_WNK2 * fo1 - FFT_15PONIT_WNK3 * fi7;
+ fo7 = fi1 - fi3 / 4;
+ fo5 = fi5 + fo7;
+ fo6 = fo7 - fi5;
+
+ zRe[in2] = fo6 - fo4;
+ zRe[in3] = fo5 - fo3;
+ zRe[in5] = fo6 + fo4;
+ zRe[in4] = fo5 + fo3;
+
+ fo3 = FFT_15PONIT_WNK2 * fi6 + FFT_15PONIT_WNK3 * fi4;
+ fo4 = FFT_15PONIT_WNK2 * fi4 - FFT_15PONIT_WNK3 * fi6;
+ fo7 = fi2 - fi8 / 4;
+ fo5 = fo2 + fo7;
+ fo6 = fo7 - fo2;
+
+ zIm[in2] = fo4 + fo6;
+ zIm[in3] = fo3 + fo5;
+ zIm[in4] = fo5 - fo3;
+ zIm[in5] = fo6 - fo4;
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft4_5()
+ * 8-point FFT with shift 1
+ *-----------------------------------------------------------------*/
+
+static void fft4_5(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t *Idx /* i : pointer of the address table */
+)
+{
+ int16_t i, id, jd;
+ float z[8];
+
+ for ( i = 0; i < 4; i++ )
+ {
+ id = Idx[i];
+ z[2 * i] = x[id];
+ z[2 * i + 1] = y[id];
+ }
+
+ cdftForw( 8, z, Ip_fft4, w_fft4 );
+
+ for ( i = 0; i < 4; i++ )
+ {
+ jd = Odx_fft4_5[i];
+ id = Idx[jd];
+ x[id] = z[2 * i];
+ y[id] = z[2 * i + 1];
+ }
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * fft5_4()
+ * 5-point FFT with shift 4
+ *-----------------------------------------------------------------*/
+
+static void fft5_4(
+ int16_t n1,
+ float *zRe,
+ float *zIm,
+ const int16_t *Idx )
+{
+ float fi1, fi2, fi3, fi4, fi5, fi6, fi7, fi8;
+ float fo1, fo2, fo3, fo4, fo5, fo6, fo7, fo8;
+ int16_t in1, in2, in3, in4, in5;
+
+ in1 = Idx[0];
+ in2 = Idx[n1];
+ in3 = Idx[n1 * 2];
+ in4 = Idx[n1 * 3];
+ in5 = Idx[n1 * 4];
+
+ fi1 = zRe[in1];
+ fi2 = zIm[in1];
+ fo3 = zRe[in2];
+ fo4 = zRe[in5];
+ fo6 = zRe[in3];
+ fo7 = zRe[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi3 = fo5 + fo8;
+ fi4 = fo6 - fo7;
+ fi5 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+ fi6 = fo3 - fo4;
+
+ fo3 = zIm[in2];
+ fo4 = zIm[in5];
+ fo6 = zIm[in3];
+ fo7 = zIm[in4];
+
+ fo5 = fo3 + fo4;
+ fo8 = fo6 + fo7;
+ fi7 = fo3 - fo4;
+ fi8 = fo5 + fo8;
+ fo1 = fo6 - fo7;
+ fo2 = FFT_15PONIT_WNK1 * ( fo5 - fo8 );
+
+ zRe[in1] = fi1 + fi3;
+ zIm[in1] = fi2 + fi8;
+
+ fo3 = FFT_15PONIT_WNK2 * fi7 + FFT_15PONIT_WNK3 * fo1;
+ fo4 = FFT_15PONIT_WNK2 * fo1 - FFT_15PONIT_WNK3 * fi7;
+ fo7 = fi1 - fi3 / 4;
+ fo5 = fi5 + fo7;
+ fo6 = fo7 - fi5;
+
+ zRe[in2] = fo5 - fo3;
+ zRe[in4] = fo6 - fo4;
+ zRe[in3] = fo6 + fo4;
+ zRe[in5] = fo5 + fo3;
+
+ fo3 = FFT_15PONIT_WNK2 * fi6 + FFT_15PONIT_WNK3 * fi4;
+ fo4 = FFT_15PONIT_WNK2 * fi4 - FFT_15PONIT_WNK3 * fi6;
+ fo7 = fi2 - fi8 / 4;
+ fo5 = fo2 + fo7;
+ fo6 = fo7 - fo2;
+
+ zIm[in2] = fo3 + fo5;
+ zIm[in3] = fo6 - fo4;
+ zIm[in4] = fo4 + fo6;
+ zIm[in5] = fo5 - fo3;
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------*
+ * DoRTFT80()
+ * a low complexity 2-dimensional DFT of 80 points
+ *-----------------------------------------------------------------*/
+
+void DoRTFT80(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ int16_t j;
+
+ /* Applying 16-point FFT for 5 times based on the address table Idx_dortft80 */
+ for ( j = 0; j < 5; j++ )
+ {
+ fft16( x, y, Idx_dortft80 + 16 * j );
+ }
+
+ /* Applying 5-point FFT for 16 times based on the address table Idx_dortft80 */
+ for ( j = 0; j < 16; j++ )
+ {
+ fft5_shift1( 16, x, y, Idx_dortft80 + j );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * DoRTFT120()
+ * a low complexity 2-dimensional DFT of 120 points
+ *-----------------------------------------------------------------*/
+
+void DoRTFT120(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ int16_t j;
+
+ /* Applying 8-point FFT for 15 times based on the address table Idx_dortft120 */
+ for ( j = 0; j < 15; j++ )
+ {
+ fft8( x, y, Idx_dortft120 + 8 * j );
+ }
+
+ /* Applying 15-point FFT for 8 times based on the address table Idx_dortft120 */
+ for ( j = 0; j < 8; j++ )
+ {
+ fft15_shift2( 8, x, y, Idx_dortft120 + j );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * DoRTFT160()
+ * a low complexity 2-dimensional DFT of 160 points
+ *-----------------------------------------------------------------*/
+
+void DoRTFT160(
+ float x[], /* i/o: real part of input and output data */
+ float y[] /* i/o: imaginary part of input and output data */
+)
+{
+ int16_t j;
+
+ /* Applying 32-point FFT for 5 times based on the address table Idx_dortft160 */
+ for ( j = 0; j < 5; j++ )
+ {
+ fft32_5( x, y, Idx_dortft160 + 32 * j );
+ }
+
+ /* Applying 5-point FFT for 32 times based on the address table Idx_dortft160 */
+ for ( j = 0; j < 32; j++ )
+ {
+ fft5_32( x, y, Idx_dortft160 + j );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * DoRTFT320()
+ * a low complexity 2-dimensional DFT of 320 points
+ *-----------------------------------------------------------------*/
+
+void DoRTFT320(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ int16_t j;
+
+ /* Applying 64-point FFT for 5 times based on the address table Idx_dortft160 */
+ for ( j = 0; j < 5; j++ )
+ {
+ fft64( x, y, Idx_dortft320 + 64 * j );
+ }
+
+ /* Applying 5-point FFT for 64 times based on the address table Idx_dortft160 */
+ for ( j = 0; j < 64; j++ )
+ {
+ fft5_shift4( 64, x, y, Idx_dortft320 + j );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * DoRTFT480()
+ * a low complexity 2-dimensional DFT of 480 points
+ *-----------------------------------------------------------------*/
+
+void DoRTFT480(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ int16_t j;
+
+ /* Applying 32-point FFT for 15 times based on the address table Idx_dortft160 */
+ for ( j = 0; j < 15; j++ )
+ {
+ fft32_15( x, y, Idx_dortft480 + 32 * j );
+ }
+
+ /* Applying 5-point FFT for 32 times based on the address table Idx_dortft160 */
+ for ( j = 0; j < 32; j++ )
+ {
+ fft15_shift8( 32, x, y, Idx_dortft480 + j );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * DoRTFT40()
+ * a low complexity 2-dimensional DFT of 40 points
+ *-----------------------------------------------------------------*/
+
+void DoRTFT40(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ int16_t j;
+ /* Applying 8-point FFT for 5 times based on the address table Idx_dortft40 */
+ for ( j = 0; j < 5; j++ )
+ {
+ fft8_5( x, y, Idx_dortft40 + 8 * j );
+ }
+
+ /* Applying 5-point FFT for 8 times based on the address table Idx_dortft40 */
+ for ( j = 0; j < 8; j++ )
+ {
+ fft5_8( 8, x, y, Idx_dortft40 + j );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * DoRTFT20()
+ * a low complexity 2-dimensional DFT of 20 points
+ *-----------------------------------------------------------------*/
+
+void DoRTFT20(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ int16_t j;
+
+ /* Applying 4-point FFT for 5 times based on the address table Idx_dortft20 */
+ for ( j = 0; j < 5; j++ )
+ {
+ fft4_5( x, y, Idx_dortft20 + 4 * j );
+ }
+
+ /* Applying 5-point FFT for 4 times based on the address table Idx_dortft20 */
+ for ( j = 0; j < 4; j++ )
+ {
+ fft5_4( 4, x, y, Idx_dortft20 + j );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * DoRTFT128()
+ * FFT with 128 points
+ *-----------------------------------------------------------------*/
+
+void DoRTFT128(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+
+ int16_t i;
+ float z[256];
+
+ for ( i = 0; i < 128; i++ )
+ {
+ z[2 * i] = x[i];
+ z[2 * i + 1] = y[i];
+ }
+
+ cdftForw( 256, z, Ip_fft128, w_fft128 );
+
+ x[0] = z[0];
+ y[0] = z[1];
+ for ( i = 1; i < 128; i++ )
+ {
+ x[128 - i] = z[2 * i];
+ y[128 - i] = z[2 * i + 1];
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * cdftForw()
+ * Main fuction of Complex Discrete Fourier Transform
+ *-----------------------------------------------------------------*/
+
+static void cdftForw(
+ int16_t n, /* i : data length of real and imag */
+ float *a, /* i/o: input/output data */
+ const int16_t *ip, /* i : work area for bit reversal */
+ const float *w /* i : cos/sin table */
+)
+{
+ /* bit reversal */
+ bitrv2_SR( n, ip + 2, a );
+
+ /* Do FFT */
+ cftfsub( n, a, w );
+}
+
+/*-----------------------------------------------------------------*
+ * bitrv2_SR()
+ * Bit reversal
+ *-----------------------------------------------------------------*/
+
+static void bitrv2_SR(
+ int16_t n, /* i : data length of real and imag */
+ const int16_t *ip, /* i/o: work area for bit reversal */
+ float *a /* i/o: input/output data */
+)
+{
+ int16_t j, j1, k, k1, m, m2;
+ int16_t l;
+ float xr, xi, yr, yi;
+
+ if ( n == 64 )
+ {
+ m = 4;
+ l = -1;
+ }
+ else if ( n == 256 )
+ {
+ m = 8;
+ l = -1;
+ }
+ else if ( n == 16 )
+ {
+ m = 2;
+ l = -1;
+ }
+ else
+ {
+ l = n;
+ m = 1;
+
+ while ( ( m << 3 ) < l )
+ {
+ l >>= 1;
+ m <<= 1;
+ }
+ l -= m * 8;
+ }
+
+ m2 = 2 * m;
+
+ if ( l == 0 )
+ {
+ for ( k = 0; k < m; k++ )
+ {
+ for ( j = 0; j < k; j++ )
+ {
+ j1 = 2 * j + ip[k];
+ k1 = 2 * k + ip[j];
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += m2;
+ k1 += 2 * m2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += m2;
+ k1 -= m2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += m2;
+ k1 += 2 * m2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+
+ j1 = 2 * k + m2 + ip[k];
+ k1 = j1 + m2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+ }
+ else
+ {
+ for ( k = 1; k < m; k++ )
+ {
+ for ( j = 0; j < k; j++ )
+ {
+ j1 = 2 * j + ip[k];
+ k1 = 2 * k + ip[j];
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += m2;
+ k1 += m2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+ }
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * cftfsub()
+ * Complex Discrete Fourier Transform
+ *-----------------------------------------------------------------*/
+
+static void cftfsub(
+ int16_t n, /* i : data length of real and imag */
+ float *a, /* i/o: input/output data */
+ const float *w /* i : cos/sin table */
+)
+{
+ int16_t j, j1, j2, j3, l;
+ float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+
+ l = 2;
+ if ( n > 8 )
+ {
+ cft1st( n, a, w );
+
+ l = 8;
+ while ( ( l << 2 ) < n )
+ {
+ cftmdl( n, l, a, w );
+ l <<= 2;
+ }
+ }
+
+ if ( ( l << 2 ) == n )
+ {
+ for ( j = 0; j < l; j += 2 )
+ {
+ j1 = j + l;
+ j2 = j1 + l;
+ j3 = j2 + l;
+ x0r = a[j] + a[j1];
+ x0i = a[j + 1] + a[j1 + 1];
+ x1r = a[j] - a[j1];
+ x1i = a[j + 1] - a[j1 + 1];
+ x2r = a[j2] + a[j3];
+ x2i = a[j2 + 1] + a[j3 + 1];
+ x3r = a[j2] - a[j3];
+ x3i = a[j2 + 1] - a[j3 + 1];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i + x2i;
+ a[j2] = x0r - x2r;
+ a[j2 + 1] = x0i - x2i;
+ a[j1] = x1r - x3i;
+ a[j1 + 1] = x1i + x3r;
+ a[j3] = x1r + x3i;
+ a[j3 + 1] = x1i - x3r;
+ }
+ }
+ else
+ {
+ for ( j = 0; j < l; j += 2 )
+ {
+ j1 = j + l;
+ x0r = a[j] - a[j1];
+ x0i = a[j + 1] - a[j1 + 1];
+ a[j] += a[j1];
+ a[j + 1] += a[j1 + 1];
+ a[j1] = x0r;
+ a[j1 + 1] = x0i;
+ }
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * cft1st()
+ * Subfunction of Complex Discrete Fourier Transform
+ *-----------------------------------------------------------------*/
+
+static void cft1st(
+ int16_t n, /* i : data length of real and imag */
+ float *a, /* i/o: input/output data */
+ const float *w /* i : cos/sin table */
+)
+{
+ int16_t j, k1, k2;
+ float wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
+ float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+
+ x0r = a[0] + a[2];
+ x0i = a[1] + a[3];
+ x1r = a[0] - a[2];
+ x1i = a[1] - a[3];
+ x2r = a[4] + a[6];
+ x2i = a[5] + a[7];
+ x3r = a[4] - a[6];
+ x3i = a[5] - a[7];
+ a[0] = x0r + x2r;
+ a[1] = x0i + x2i;
+ a[4] = x0r - x2r;
+ a[5] = x0i - x2i;
+ a[2] = x1r - x3i;
+ a[3] = x1i + x3r;
+ a[6] = x1r + x3i;
+ a[7] = x1i - x3r;
+ wk1r = w[2];
+ x0r = a[8] + a[10];
+ x0i = a[9] + a[11];
+ x1r = a[8] - a[10];
+ x1i = a[9] - a[11];
+ x2r = a[12] + a[14];
+ x2i = a[13] + a[15];
+ x3r = a[12] - a[14];
+ x3i = a[13] - a[15];
+ a[8] = x0r + x2r;
+ a[9] = x0i + x2i;
+ a[12] = x2i - x0i;
+ a[13] = x0r - x2r;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[10] = wk1r * ( x0r - x0i );
+ a[11] = wk1r * ( x0r + x0i );
+ x0r = x3i + x1r;
+ x0i = x3r - x1i;
+ a[14] = wk1r * ( x0i - x0r );
+ a[15] = wk1r * ( x0i + x0r );
+ k1 = 0;
+
+ for ( j = 16; j < n; j += 16 )
+ {
+ k1 += 2;
+ k2 = 2 * k1;
+ wk2r = w[k1];
+ wk2i = w[k1 + 1];
+ wk1r = w[k2];
+ wk1i = w[k2 + 1];
+ wk3r = wk1r - 2 * wk2i * wk1i;
+ wk3i = 2 * wk2i * wk1r - wk1i;
+ x0r = a[j] + a[j + 2];
+ x0i = a[j + 1] + a[j + 3];
+ x1r = a[j] - a[j + 2];
+ x1i = a[j + 1] - a[j + 3];
+ x2r = a[j + 4] + a[j + 6];
+ x2i = a[j + 5] + a[j + 7];
+ x3r = a[j + 4] - a[j + 6];
+ x3i = a[j + 5] - a[j + 7];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i + x2i;
+ x0r -= x2r;
+ x0i -= x2i;
+ a[j + 4] = wk2r * x0r - wk2i * x0i;
+ a[j + 5] = wk2r * x0i + wk2i * x0r;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j + 2] = wk1r * x0r - wk1i * x0i;
+ a[j + 3] = wk1r * x0i + wk1i * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j + 6] = wk3r * x0r - wk3i * x0i;
+ a[j + 7] = wk3r * x0i + wk3i * x0r;
+ wk1r = w[k2 + 2];
+ wk1i = w[k2 + 3];
+ wk3r = wk1r - 2 * wk2r * wk1i;
+ wk3i = 2 * wk2r * wk1r - wk1i;
+ x0r = a[j + 8] + a[j + 10];
+ x0i = a[j + 9] + a[j + 11];
+ x1r = a[j + 8] - a[j + 10];
+ x1i = a[j + 9] - a[j + 11];
+ x2r = a[j + 12] + a[j + 14];
+ x2i = a[j + 13] + a[j + 15];
+ x3r = a[j + 12] - a[j + 14];
+ x3i = a[j + 13] - a[j + 15];
+ a[j + 8] = x0r + x2r;
+ a[j + 9] = x0i + x2i;
+ x0r -= x2r;
+ x0i -= x2i;
+ a[j + 12] = -wk2i * x0r - wk2r * x0i;
+ a[j + 13] = -wk2i * x0i + wk2r * x0r;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j + 10] = wk1r * x0r - wk1i * x0i;
+ a[j + 11] = wk1r * x0i + wk1i * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j + 14] = wk3r * x0r - wk3i * x0i;
+ a[j + 15] = wk3r * x0i + wk3i * x0r;
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * cftmdl()
+ * Subfunction of Complex Discrete Fourier Transform
+ *-----------------------------------------------------------------*/
+
+static void cftmdl(
+ int16_t n, /* i : data length of real and imag */
+ int16_t l, /* i : initial shift for processing */
+ float *a, /* i/o: input/output data */
+ const float *w /* i : cos/sin table */
+)
+{
+ int16_t j, j1, j2, j3, k, k1, k2, m, m2;
+ float wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
+ float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+
+ m = l << 2;
+ for ( j = 0; j < l; j += 2 )
+ {
+ j1 = j + l;
+ j2 = j1 + l;
+ j3 = j2 + l;
+ x0r = a[j] + a[j1];
+ x0i = a[j + 1] + a[j1 + 1];
+ x1r = a[j] - a[j1];
+ x1i = a[j + 1] - a[j1 + 1];
+ x2r = a[j2] + a[j3];
+ x2i = a[j2 + 1] + a[j3 + 1];
+ x3r = a[j2] - a[j3];
+ x3i = a[j2 + 1] - a[j3 + 1];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i + x2i;
+ a[j2] = x0r - x2r;
+ a[j2 + 1] = x0i - x2i;
+ a[j1] = x1r - x3i;
+ a[j1 + 1] = x1i + x3r;
+ a[j3] = x1r + x3i;
+ a[j3 + 1] = x1i - x3r;
+ }
+
+ wk1r = w[2];
+ for ( j = m; j < l + m; j += 2 )
+ {
+ j1 = j + l;
+ j2 = j1 + l;
+ j3 = j2 + l;
+ x0r = a[j] + a[j1];
+ x0i = a[j + 1] + a[j1 + 1];
+ x1r = a[j] - a[j1];
+ x1i = a[j + 1] - a[j1 + 1];
+ x2r = a[j2] + a[j3];
+ x2i = a[j2 + 1] + a[j3 + 1];
+ x3r = a[j2] - a[j3];
+ x3i = a[j2 + 1] - a[j3 + 1];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i + x2i;
+ a[j2] = x2i - x0i;
+ a[j2 + 1] = x0r - x2r;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j1] = wk1r * ( x0r - x0i );
+ a[j1 + 1] = wk1r * ( x0r + x0i );
+ x0r = x3i + x1r;
+ x0i = x3r - x1i;
+ a[j3] = wk1r * ( x0i - x0r );
+ a[j3 + 1] = wk1r * ( x0i + x0r );
+ }
+
+ k1 = 0;
+ m2 = 2 * m;
+ for ( k = m2; k < n; k += m2 )
+ {
+ k1 += 2;
+ k2 = 2 * k1;
+ wk2r = w[k1];
+ wk2i = w[k1 + 1];
+ wk1r = w[k2];
+ wk1i = w[k2 + 1];
+ wk3r = wk1r - 2 * wk2i * wk1i;
+ wk3i = 2 * wk2i * wk1r - wk1i;
+ for ( j = k; j < l + k; j += 2 )
+ {
+ j1 = j + l;
+ j2 = j1 + l;
+ j3 = j2 + l;
+ x0r = a[j] + a[j1];
+ x0i = a[j + 1] + a[j1 + 1];
+ x1r = a[j] - a[j1];
+ x1i = a[j + 1] - a[j1 + 1];
+ x2r = a[j2] + a[j3];
+ x2i = a[j2 + 1] + a[j3 + 1];
+ x3r = a[j2] - a[j3];
+ x3i = a[j2 + 1] - a[j3 + 1];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i + x2i;
+ x0r -= x2r;
+ x0i -= x2i;
+ a[j2] = wk2r * x0r - wk2i * x0i;
+ a[j2 + 1] = wk2r * x0i + wk2i * x0r;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j1] = wk1r * x0r - wk1i * x0i;
+ a[j1 + 1] = wk1r * x0i + wk1i * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3] = wk3r * x0r - wk3i * x0i;
+ a[j3 + 1] = wk3r * x0i + wk3i * x0r;
+ }
+
+ wk1r = w[k2 + 2];
+ wk1i = w[k2 + 3];
+ wk3r = wk1r - 2 * wk2r * wk1i;
+ wk3i = 2 * wk2r * wk1r - wk1i;
+ for ( j = k + m; j < l + ( k + m ); j += 2 )
+ {
+ j1 = j + l;
+ j2 = j1 + l;
+ j3 = j2 + l;
+ x0r = a[j] + a[j1];
+ x0i = a[j + 1] + a[j1 + 1];
+ x1r = a[j] - a[j1];
+ x1i = a[j + 1] - a[j1 + 1];
+ x2r = a[j2] + a[j3];
+ x2i = a[j2 + 1] + a[j3 + 1];
+ x3r = a[j2] - a[j3];
+ x3i = a[j2 + 1] - a[j3 + 1];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i + x2i;
+ x0r -= x2r;
+ x0i -= x2i;
+ a[j2] = -wk2i * x0r - wk2r * x0i;
+ a[j2 + 1] = -wk2i * x0i + wk2r * x0r;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j1] = wk1r * x0r - wk1i * x0i;
+ a[j1 + 1] = wk1r * x0i + wk1i * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3] = wk3r * x0r - wk3i * x0i;
+ a[j3 + 1] = wk3r * x0i + wk3i * x0r;
+ }
+ }
+
+ return;
+}
+
+static void cftbsub(
+ int16_t n,
+ float *a,
+ const float *w /* i : cos/sin table */
+)
+{
+ int16_t j, j1, j2, j3, l;
+ float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+
+ l = 2;
+ if ( n > 8 )
+ {
+ cft1st( n, a, w );
+ l = 8;
+
+ while ( ( l << 2 ) < n )
+ {
+ cftmdl( n, l, a, w );
+ l <<= 2;
+ }
+ }
+
+ if ( ( l << 2 ) == n )
+ {
+ for ( j = 0; j < l; j += 2 )
+ {
+ j1 = j + l;
+ j2 = j1 + l;
+ j3 = j2 + l;
+ x0r = a[j] + a[j1];
+ x0i = -a[j + 1] - a[j1 + 1];
+ x1r = a[j] - a[j1];
+ x1i = -a[j + 1] + a[j1 + 1];
+ x2r = a[j2] + a[j3];
+ x2i = a[j2 + 1] + a[j3 + 1];
+ x3r = a[j2] - a[j3];
+ x3i = a[j2 + 1] - a[j3 + 1];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i - x2i;
+ a[j2] = x0r - x2r;
+ a[j2 + 1] = x0i + x2i;
+ a[j1] = x1r - x3i;
+ a[j1 + 1] = x1i - x3r;
+ a[j3] = x1r + x3i;
+ a[j3 + 1] = x1i + x3r;
+ }
+ }
+ else
+ {
+ for ( j = 0; j < l; j += 2 )
+ {
+ j1 = j + l;
+ x0r = a[j] - a[j1];
+ x0i = -a[j + 1] + a[j1 + 1];
+ a[j] += a[j1];
+ a[j + 1] = -a[j + 1] - a[j1 + 1];
+ a[j1] = x0r;
+ a[j1 + 1] = x0i;
+ }
+ }
+
+ return;
+}
+
+static void rftfsub(
+ int16_t n,
+ float *a,
+ int16_t nc,
+ const float *c )
+{
+ int16_t j, k, kk, ks, m;
+ float wkr, wki, xr, xi, yr, yi;
+
+ m = n >> 1;
+ ks = 2 * nc / m;
+ kk = 0;
+ for ( j = 2; j < m; j += 2 )
+ {
+ k = n - j;
+ kk += ks;
+ wkr = 0.5f - c[nc - kk];
+ wki = c[kk];
+ xr = a[j] - a[k];
+ xi = a[j + 1] + a[k + 1];
+ yr = wkr * xr - wki * xi;
+ yi = wkr * xi + wki * xr;
+ a[j] -= yr;
+ a[j + 1] -= yi;
+ a[k] += yr;
+ a[k + 1] -= yi;
+ }
+
+ return;
+}
+
+
+static void rftbsub(
+ int16_t n,
+ float *a,
+ int16_t nc,
+ const float *c )
+{
+ int16_t j, k, kk, ks, m;
+ float wkr, wki, xr, xi, yr, yi;
+
+ a[1] = -a[1];
+ m = n >> 1;
+ ks = 2 * nc / m;
+ kk = 0;
+ for ( j = 2; j < m; j += 2 )
+ {
+ k = n - j;
+ kk += ks;
+ wkr = 0.5f - c[nc - kk];
+ wki = c[kk];
+ xr = a[j] - a[k];
+ xi = a[j + 1] + a[k + 1];
+ yr = wkr * xr + wki * xi;
+ yi = wkr * xi - wki * xr;
+ a[j] -= yr;
+ a[j + 1] = yi - a[j + 1];
+ a[k] += yr;
+ a[k + 1] = yi - a[k + 1];
+ }
+ a[m + 1] = -a[m + 1];
+
+ return;
+}
+
+
+static void dctsub(
+ int16_t n,
+ float *a,
+ int16_t nc,
+ const float *c )
+{
+ int16_t j, k, kk, ks, m;
+ float wkr, wki, xr;
+
+ m = n >> 1;
+ ks = nc / n;
+ kk = 0;
+ for ( j = 1; j < m; j++ )
+ {
+ k = n - j;
+ kk += ks;
+ wkr = c[kk] - c[nc - kk];
+ wki = c[kk] + c[nc - kk];
+ xr = wki * a[j] - wkr * a[k];
+ a[j] = wkr * a[j] + wki * a[k];
+ a[k] = xr;
+ }
+ a[m] *= c[0];
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------*
+ * edct2()
+ *
+ * Transformation of the signal to DCT domain
+ * OR Inverse EDCT-II for short frames
+ *-----------------------------------------------------------------*/
+
+void edct2(
+ const int16_t n,
+ const int16_t isgn,
+ float *in,
+ float *a,
+ const int16_t *ip,
+ const float *w )
+{
+ int16_t j, nw, nc;
+ float xr;
+
+ mvr2r( in, a, n );
+
+ nw = ip[0];
+ if ( n > ( nw << 2 ) )
+ {
+ nw = n >> 2;
+ }
+
+ nc = ip[1];
+ if ( n > nc )
+ {
+ nc = n;
+ }
+
+ if ( isgn < 0 )
+ {
+ xr = a[n - 1];
+ for ( j = n - 2; j >= 2; j -= 2 )
+ {
+ a[j + 1] = a[j] - a[j - 1];
+ a[j] += a[j - 1];
+ }
+ a[1] = a[0] - xr;
+ a[0] += xr;
+
+ if ( n > 4 )
+ {
+ rftbsub( n, a, nc, w + nw );
+ bitrv2_SR( n, ip + 2, a );
+ cftbsub( n, a, w );
+ }
+ else if ( n == 4 )
+ {
+ cftfsub( n, a, w );
+ }
+ }
+
+ if ( isgn >= 0 )
+ {
+ a[0] *= 0.5f;
+ }
+
+ dctsub( n, a, nc, w + nw );
+
+ if ( isgn >= 0 )
+ {
+ if ( n > 4 )
+ {
+ bitrv2_SR( n, ip + 2, a );
+ cftfsub( n, a, w );
+ rftfsub( n, a, nc, w + nw );
+ }
+ else if ( n == 4 )
+ {
+ cftfsub( n, a, w );
+ }
+ xr = a[0] - a[1];
+ a[0] += a[1];
+ for ( j = 2; j < n; j += 2 )
+ {
+ a[j - 1] = a[j] - a[j + 1];
+ a[j] += a[j + 1];
+ }
+ a[n - 1] = xr;
+
+ for ( j = 0; j < n; j++ )
+ {
+ a[j] /= 32.0f;
+ }
+ }
+}
+
+
+void DoRTFTn(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t n /* i : size of the FFT up to 1024 */
+)
+{
+
+ int16_t i;
+ float z[2048];
+
+ for ( i = 0; i < n; i++ )
+ {
+ z[2 * i] = x[i];
+ z[2 * i + 1] = y[i];
+ }
+
+ switch ( n )
+ {
+ case ( 16 ):
+ cdftForw( 2 * n, z, Ip_fft16, w_fft16 );
+ break;
+ case ( 32 ):
+ cdftForw( 2 * n, z, Ip_fft32, w_fft32 );
+ break;
+ case ( 64 ):
+ cdftForw( 2 * n, z, Ip_fft64, w_fft64 );
+ break;
+ case ( 128 ):
+ cdftForw( 2 * n, z, Ip_fft128, w_fft128 );
+ break;
+ case ( 256 ):
+ cdftForw( 2 * n, z, Ip_fft256, w_fft256 );
+ break;
+ case ( 512 ):
+ cdftForw( 2 * n, z, Ip_fft512, w_fft512 );
+ break;
+ default:
+ assert( 0 );
+ }
+
+ x[0] = z[0];
+ y[0] = z[1];
+ for ( i = 1; i < n; i++ )
+ {
+ x[n - i] = z[2 * i];
+ y[n - i] = z[2 * i + 1];
+ }
+
+ return;
+}
+
+
+void fft3(
+ const float X[],
+ float Y[],
+ const int16_t n )
+{
+ float Z[PH_ECU_SPEC_SIZE];
+ float *Z0, *Z1, *Z2;
+ float *z0, *z1, *z2;
+ const float *x;
+ const float *t_sin = sincos_t_rad3;
+ int16_t m, step, order;
+ int16_t i, j;
+ int16_t c1_ind, s1_ind, c2_ind, s2_ind;
+ int16_t c1_step, s1_step, c2_step, s2_step;
+ float *RY, *IY, *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2;
+
+ /* Determine the order of the transform, the length of decimated */
+ /* transforms m, and the step for the sine and cosine tables. */
+ switch ( n )
+ {
+ case 1536:
+ order = 9;
+ m = 512;
+ step = 1;
+ break;
+ case 384:
+ order = 7;
+ m = 128;
+ step = 4;
+ break;
+ default:
+ order = 9;
+ m = 512;
+ step = 1;
+ }
+
+ /* Compose decimated sequences X[3i], X[3i+1],X[3i+2] */
+ /* compute their FFT of length m. */
+ Z0 = &Z[0];
+ z0 = &Z0[0];
+ Z1 = &Z0[m];
+ z1 = &Z1[0]; /* Z1 = &Z[ m]; */
+ Z2 = &Z1[m];
+ z2 = &Z2[0]; /* Z2 = &Z[2m]; */
+ x = &X[0];
+ for ( i = 0; i < n / 3; i++ )
+ {
+ *z0++ = *x++; /* Z0[i] = X[3i]; */
+ *z1++ = *x++; /* Z1[i] = X[3i+1]; */
+ *z2++ = *x++; /* Z2[i] = X[3i+2]; */
+ }
+
+ fft_rel( &Z0[0], m, order );
+ fft_rel( &Z1[0], m, order );
+ fft_rel( &Z2[0], m, order );
+
+ /* Butterflies of order 3. */
+ /* pointer initialization */
+ RY = &Y[0];
+ IY = &Y[n];
+ RZ0 = &Z0[0];
+ IZ0 = &Z0[m];
+ RZ1 = &Z1[0];
+ IZ1 = &Z1[m];
+ RZ2 = &Z2[0];
+ IZ2 = &Z2[m];
+
+ c1_step = -step;
+ s1_step = step;
+ c2_step = -2 * step;
+ s2_step = 2 * step;
+ c1_ind = T_SIN_PI_2 + c1_step;
+ s1_ind = s1_step;
+ c2_ind = T_SIN_PI_2 + c2_step;
+ s2_ind = s2_step;
+
+ /* special case: i = 0 */
+ RY[0] = RZ0[0] + RZ1[0] + RZ2[0];
+
+ /* first 3/12 */
+ for ( i = 1; i < 3 * m / 8; i++, c1_ind += c1_step, s1_ind += s1_step, c2_ind += c2_step, s2_ind += s2_step )
+ {
+ RY[i] = RZ0[i] + RZ1[i] * t_sin[c1_ind] + IZ1[-i] * t_sin[s1_ind] + RZ2[i] * t_sin[c2_ind] + IZ2[-i] * t_sin[s2_ind];
+ IY[-i] = IZ0[-i] - RZ1[i] * t_sin[s1_ind] + IZ1[-i] * t_sin[c1_ind] - RZ2[i] * t_sin[s2_ind] + IZ2[-i] * t_sin[c2_ind];
+ }
+
+ /* next 1/12 */
+ for ( ; i < 4 * m / 8; i++, c1_ind += c1_step, s1_ind += s1_step, c2_ind -= c2_step, s2_ind -= s2_step )
+ {
+ RY[i] = RZ0[i] + RZ1[i] * t_sin[c1_ind] + IZ1[-i] * t_sin[s1_ind] - RZ2[i] * t_sin[c2_ind] + IZ2[-i] * t_sin[s2_ind];
+ IY[-i] = IZ0[-i] - RZ1[i] * t_sin[s1_ind] + IZ1[-i] * t_sin[c1_ind] - RZ2[i] * t_sin[s2_ind] - IZ2[-i] * t_sin[c2_ind];
+ }
+
+ /* special case: i = m/2 i.e. 1/3 */
+ RY[i] = RZ0[i] + RZ1[i] * t_sin[c1_ind] - RZ2[i] * t_sin[c2_ind];
+ IY[-i] = -RZ1[i] * t_sin[s1_ind] - RZ2[i] * t_sin[s2_ind];
+ i++;
+
+ c1_ind += c1_step, s1_ind += s1_step, c2_ind -= c2_step, s2_ind -= s2_step;
+
+ /* next 2/12 */
+ for ( j = i - 2; i < 6 * m / 8; i++, j--, c1_ind += c1_step, s1_ind += s1_step, c2_ind -= c2_step, s2_ind -= s2_step )
+ {
+ RY[i] = RZ0[j] + RZ1[j] * t_sin[c1_ind] - IZ1[-j] * t_sin[s1_ind] - RZ2[j] * t_sin[c2_ind] - IZ2[-j] * t_sin[s2_ind];
+ IY[-i] = -IZ0[-j] - RZ1[j] * t_sin[s1_ind] - IZ1[-j] * t_sin[c1_ind] - RZ2[j] * t_sin[s2_ind] + IZ2[-j] * t_sin[c2_ind];
+ }
+
+ /*--------------------------half--------------------------*/
+ /* next 2/12 */
+ for ( ; i < 8 * m / 8; i++, j--, c1_ind -= c1_step, s1_ind -= s1_step, c2_ind += c2_step, s2_ind += s2_step )
+ {
+ RY[i] = RZ0[j] - RZ1[j] * t_sin[c1_ind] - IZ1[-j] * t_sin[s1_ind] - RZ2[j] * t_sin[c2_ind] + IZ2[-j] * t_sin[s2_ind];
+ IY[-i] = -IZ0[-j] - RZ1[j] * t_sin[s1_ind] + IZ1[-j] * t_sin[c1_ind] + RZ2[j] * t_sin[s2_ind] + IZ2[-j] * t_sin[c2_ind];
+ }
+
+ /* special case: i = m, i.e 2/3 */
+ RY[i] = RZ0[j] - RZ1[j] * t_sin[c1_ind] - RZ2[j] * t_sin[c2_ind];
+ IY[-i++] = -RZ1[j] * t_sin[s1_ind] + RZ2[j] * t_sin[s2_ind];
+ c1_ind -= c1_step, s1_ind -= s1_step, c2_ind += c2_step, s2_ind += s2_step;
+
+ /* next 1/12 */
+ for ( j = 1; i < 9 * m / 8; i++, j++, c1_ind -= c1_step, s1_ind -= s1_step, c2_ind += c2_step, s2_ind += s2_step )
+ {
+ RY[i] = RZ0[j] - RZ1[j] * t_sin[c1_ind] + IZ1[-j] * t_sin[s1_ind] - RZ2[j] * t_sin[c2_ind] - IZ2[-j] * t_sin[s2_ind];
+ IY[-i] = IZ0[-j] - RZ1[j] * t_sin[s1_ind] - IZ1[-j] * t_sin[c1_ind] + RZ2[j] * t_sin[s2_ind] - IZ2[-j] * t_sin[c2_ind];
+ }
+
+ /* last 3/12 */
+ for ( ; i < 12 * m / 8; i++, j++, c1_ind -= c1_step, s1_ind -= s1_step, c2_ind -= c2_step, s2_ind -= s2_step )
+ {
+ RY[i] = RZ0[j] - RZ1[j] * t_sin[c1_ind] + IZ1[-j] * t_sin[s1_ind] + RZ2[j] * t_sin[c2_ind] - IZ2[-j] * t_sin[s2_ind];
+ IY[-i] = IZ0[-j] - RZ1[j] * t_sin[s1_ind] - IZ1[-j] * t_sin[c1_ind] + RZ2[j] * t_sin[s2_ind] + IZ2[-j] * t_sin[c2_ind];
+ }
+
+ /* special case: i = 3*m/2 */
+ RY[i] = RZ0[j] - RZ1[j] * t_sin[c1_ind] + RZ2[j] * t_sin[c2_ind];
+
+ return;
+}
+
+void ifft3(
+ const float Z[],
+ float X[],
+ const int16_t n )
+{
+ float Y[PH_ECU_SPEC_SIZE];
+ const float *t_sin = sincos_t_rad3;
+ int16_t m, step, step2, order;
+ int16_t i;
+ int16_t c0_ind, s0_ind, c1_ind, s1_ind, c2_ind, s2_ind;
+ float scale;
+ const float *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2;
+ float *RY0, *IY0, *RY1, *IY1, *RY2, *IY2, *y0, *y1, *y2;
+
+ /* Determine the order of the transform, the length of decimated */
+ /* transforms m, and the step for the sine and cosine tables. */
+ switch ( n )
+ {
+ case 1536:
+ order = 9;
+ m = 512;
+ step = 1;
+ break;
+ case 384:
+ order = 7;
+ m = 128;
+ step = 4;
+ break;
+ default:
+ order = 9;
+ m = 512;
+ step = 1;
+ }
+
+ /* pointer initialization */
+ RY0 = &Y[0];
+ IY0 = &RY0[m];
+ RY1 = &RY0[m];
+ IY1 = &RY1[m];
+ RY2 = &RY1[m];
+ IY2 = &RY2[m];
+
+ RZ0 = &Z[0];
+ RZ1 = RZ0 + m;
+ RZ2 = RZ0 + n / 2 - m / 2;
+ IZ0 = &Z[n];
+ IZ1 = IZ0 - m;
+ IZ2 = IZ0 - n / 2 + m / 2;
+
+ /* Inverse butterflies of order 3. */
+
+ /* Construction of Y0 */
+ RY0[0] = RZ0[0] + RZ1[0] + RZ2[0];
+ for ( i = 1; i < m / 2; i++ )
+ {
+ RY0[i] = RZ0[i] + RZ1[i] + RZ2[-i];
+ IY0[-i] = IZ0[-i] + IZ1[-i] - IZ2[i];
+ }
+
+ /* m/2 */
+ RY0[i] = RZ0[i] + RZ1[i] + RZ2[-i];
+
+ /* Construction of Y1 */
+ c0_ind = T_SIN_PI_2;
+ s0_ind = 0;
+ c1_ind = T_SIN_PI_2 * 1 / 3;
+ s1_ind = T_SIN_PI_2 * 2 / 3;
+ c2_ind = T_SIN_PI_2 * 1 / 3;
+ s2_ind = T_SIN_PI_2 * 2 / 3;
+
+ RY1[0] = RZ0[0] * t_sin[c0_ind] - RZ1[0] * t_sin[c1_ind] - RZ2[0] * t_sin[c2_ind] - IZ1[0] * t_sin[s1_ind] - IZ2[0] * t_sin[s2_ind];
+
+ c0_ind -= step, s0_ind += step, c1_ind += step, s1_ind -= step, c2_ind -= step, s2_ind += step;
+ for ( i = 1; i < m / 4; i++, c0_ind -= step, s0_ind += step, c1_ind += step, s1_ind -= step, c2_ind -= step, s2_ind += step )
+ {
+ RY1[i] = RZ0[i] * t_sin[c0_ind] - RZ1[i] * t_sin[c1_ind] - RZ2[-i] * t_sin[c2_ind] - IZ0[-i] * t_sin[s0_ind] - IZ1[-i] * t_sin[s1_ind] - IZ2[i] * t_sin[s2_ind];
+ IY1[-i] = IZ0[-i] * t_sin[c0_ind] - IZ1[-i] * t_sin[c1_ind] + IZ2[i] * t_sin[c2_ind] + RZ0[i] * t_sin[s0_ind] + RZ1[i] * t_sin[s1_ind] - RZ2[-i] * t_sin[s2_ind];
+ }
+
+ for ( ; i < m / 2; i++, c0_ind -= step, s0_ind += step, c1_ind += step, s1_ind -= step, c2_ind += step, s2_ind -= step )
+ {
+ RY1[i] = RZ0[i] * t_sin[c0_ind] - RZ1[i] * t_sin[c1_ind] + RZ2[-i] * t_sin[c2_ind] - IZ0[-i] * t_sin[s0_ind] - IZ1[-i] * t_sin[s1_ind] - IZ2[i] * t_sin[s2_ind];
+ IY1[-i] = IZ0[-i] * t_sin[c0_ind] - IZ1[-i] * t_sin[c1_ind] - IZ2[i] * t_sin[c2_ind] + RZ0[i] * t_sin[s0_ind] + RZ1[i] * t_sin[s1_ind] - RZ2[-i] * t_sin[s2_ind];
+ }
+
+ /* m/2 */
+ RY1[i] = RZ0[i] * t_sin[c0_ind] - RZ1[i] * t_sin[c1_ind] + RZ2[-i] * t_sin[c2_ind] - IZ0[-i] * t_sin[s0_ind] - IZ1[-i] * t_sin[s1_ind] - IZ2[i] * t_sin[s2_ind];
+
+ /* Construction of Y2 */
+ c0_ind = T_SIN_PI_2;
+ s0_ind = 0;
+ c1_ind = T_SIN_PI_2 * 1 / 3;
+ s1_ind = T_SIN_PI_2 * 2 / 3;
+ c2_ind = T_SIN_PI_2 * 1 / 3;
+ s2_ind = T_SIN_PI_2 * 2 / 3;
+ step2 = 2 * step;
+ RY2[0] = RZ0[0] * t_sin[c0_ind] - RZ1[0] * t_sin[c1_ind] - RZ2[0] * t_sin[c2_ind] + IZ1[0] * t_sin[s1_ind] + IZ2[0] * t_sin[s2_ind];
+
+ c0_ind -= step2, s0_ind += step2, c1_ind -= step2, s1_ind += step2, c2_ind += step2, s2_ind -= step2;
+ for ( i = 1; i < m / 8; i++, c0_ind -= step2, s0_ind += step2, c1_ind -= step2, s1_ind += step2, c2_ind += step2, s2_ind -= step2 )
+ {
+ RY2[i] = RZ0[i] * t_sin[c0_ind] - RZ1[i] * t_sin[c1_ind] - RZ2[-i] * t_sin[c2_ind] - IZ0[-i] * t_sin[s0_ind] + IZ1[-i] * t_sin[s1_ind] + IZ2[i] * t_sin[s2_ind];
+ IY2[-i] = IZ0[-i] * t_sin[c0_ind] - IZ1[-i] * t_sin[c1_ind] + IZ2[i] * t_sin[c2_ind] + RZ0[i] * t_sin[s0_ind] - RZ1[i] * t_sin[s1_ind] + RZ2[-i] * t_sin[s2_ind];
+ }
+
+ for ( ; i < m / 4; i++, c0_ind -= step2, s0_ind += step2, c1_ind += step2, s1_ind -= step2, c2_ind += step2, s2_ind -= step2 )
+ {
+ RY2[i] = RZ0[i] * t_sin[c0_ind] + RZ1[i] * t_sin[c1_ind] - RZ2[-i] * t_sin[c2_ind] - IZ0[-i] * t_sin[s0_ind] + IZ1[-i] * t_sin[s1_ind] + IZ2[i] * t_sin[s2_ind];
+ IY2[-i] = IZ0[-i] * t_sin[c0_ind] + IZ1[-i] * t_sin[c1_ind] + IZ2[i] * t_sin[c2_ind] + RZ0[i] * t_sin[s0_ind] - RZ1[i] * t_sin[s1_ind] + RZ2[-i] * t_sin[s2_ind];
+ }
+
+ for ( ; i < 3 * m / 8; i++, c0_ind -= step2, s0_ind += step2, c1_ind += step2, s1_ind -= step2, c2_ind -= step2, s2_ind += step2 )
+ {
+ RY2[i] = RZ0[i] * t_sin[c0_ind] + RZ1[i] * t_sin[c1_ind] - RZ2[-i] * t_sin[c2_ind] - IZ0[-i] * t_sin[s0_ind] + IZ1[-i] * t_sin[s1_ind] - IZ2[i] * t_sin[s2_ind];
+ IY2[-i] = IZ0[-i] * t_sin[c0_ind] + IZ1[-i] * t_sin[c1_ind] + IZ2[i] * t_sin[c2_ind] + RZ0[i] * t_sin[s0_ind] - RZ1[i] * t_sin[s1_ind] - RZ2[-i] * t_sin[s2_ind];
+ }
+
+ for ( ; i < m / 2; i++, c0_ind += step2, s0_ind -= step2, c1_ind += step2, s1_ind -= step2, c2_ind -= step2, s2_ind += step2 )
+ {
+ RY2[i] = -RZ0[i] * t_sin[c0_ind] + RZ1[i] * t_sin[c1_ind] - RZ2[-i] * t_sin[c2_ind] - IZ0[-i] * t_sin[s0_ind] + IZ1[-i] * t_sin[s1_ind] - IZ2[i] * t_sin[s2_ind];
+ IY2[-i] = -IZ0[-i] * t_sin[c0_ind] + IZ1[-i] * t_sin[c1_ind] + IZ2[i] * t_sin[c2_ind] + RZ0[i] * t_sin[s0_ind] - RZ1[i] * t_sin[s1_ind] - RZ2[-i] * t_sin[s2_ind];
+ }
+
+ /* m/2 */
+ RY2[i] = -RZ0[i] * t_sin[c0_ind] + RZ1[i] * t_sin[c1_ind] - RZ2[-i] * t_sin[c2_ind] - IZ0[-i] * t_sin[s0_ind] + IZ1[-i] * t_sin[s1_ind] - IZ2[i] * t_sin[s2_ind];
+
+ /* Compute the inverse FFT for all 3 blocks. */
+ ifft_rel( RY0, m, order );
+ ifft_rel( RY1, m, order );
+ ifft_rel( RY2, m, order );
+
+ y0 = RY0;
+ y1 = RY1;
+ y2 = RY2;
+
+ /* Interlacing and scaling, scale = 1/3 */
+ scale = 1.0f / 3;
+ for ( i = 0; i < n; )
+ {
+ X[i++] = ( *y0++ ) * scale;
+ X[i++] = ( *y1++ ) * scale;
+ X[i++] = ( *y2++ ) * scale;
+ }
+
+ return;
+}
+
+
+static void rfft_post(
+ const float *sine_table,
+ float *buf,
+ const int16_t len )
+{
+ float tmp1, tmp2, tmp3, tmp4, s, c;
+ int16_t i = 0;
+
+ tmp1 = buf[0] + buf[1];
+ buf[1] = buf[0] - buf[1];
+ buf[0] = tmp1;
+
+ for ( i = 1; i <= ( len + 2 ) / 4; i++ )
+ {
+ s = sine_table[i]; /* sin(pi*i/(len/2)) */
+ c = sine_table[i + len / 4]; /* cos(pi*i/(len/2)) */
+
+ tmp1 = buf[2 * i] - buf[len - 2 * i];
+ tmp2 = buf[2 * i + 1] + buf[len - 2 * i + 1];
+ tmp3 = s * tmp1 - c * tmp2; /* real part of j*W(k,N)*[T(k) - T'(N-k)] */
+ tmp4 = c * tmp1 + s * tmp2; /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */
+ tmp1 = buf[2 * i] + buf[len - 2 * i];
+ tmp2 = buf[2 * i + 1] - buf[len - 2 * i + 1];
+
+ buf[2 * i] = 0.5f * ( tmp1 - tmp3 );
+ buf[2 * i + 1] = 0.5f * ( tmp2 - tmp4 );
+ buf[len - 2 * i] = 0.5f * ( tmp1 + tmp3 );
+ buf[len - 2 * i + 1] = -0.5f * ( tmp2 + tmp4 );
+ }
+}
+
+static void rfft_pre(
+ const float *sine_table,
+ float *buf,
+ const int16_t len )
+{
+ const float scale = 1.0f / len;
+ float tmp1, tmp2, tmp3, tmp4, s, c;
+ int16_t i = 0;
+
+ tmp1 = buf[0] + buf[1];
+ buf[1] = scale * ( buf[0] - buf[1] );
+ buf[0] = scale * tmp1;
+
+ for ( i = 1; i <= ( len + 2 ) / 4; i++ )
+ {
+ s = sine_table[i]; /* sin(pi*i/(len/2)) */
+ c = sine_table[i + len / 4]; /* cos(pi*i/(len/2)) */
+
+ tmp1 = buf[2 * i] - buf[len - 2 * i];
+ tmp2 = buf[2 * i + 1] + buf[len - 2 * i + 1];
+ tmp3 = s * tmp1 + c * tmp2; /* real part of j*W(k,N)*[T(k) - T'(N-k)] */
+ tmp4 = -c * tmp1 + s * tmp2; /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */
+ tmp1 = buf[2 * i] + buf[len - 2 * i];
+ tmp2 = buf[2 * i + 1] - buf[len - 2 * i + 1];
+
+ buf[2 * i] = scale * ( tmp1 + tmp3 );
+ buf[2 * i + 1] = -scale * ( tmp2 + tmp4 );
+ buf[len - 2 * i] = scale * ( tmp1 - tmp3 );
+ buf[len - 2 * i + 1] = scale * ( tmp2 - tmp4 );
+ }
+
+ return;
+}
+
+int16_t RFFTN(
+ float *data,
+ const float *sine_table,
+ const int16_t len,
+ const int16_t sign )
+{
+ assert( len <= 640 && len > 0 );
+
+ if ( len == 640 )
+ {
+ float x[320], y[320];
+ int16_t i;
+
+ if ( sign != -1 )
+ {
+ rfft_pre( sine_table, data, len );
+ }
+
+ for ( i = 0; i < 320; i++ )
+ {
+ x[i] = data[2 * i];
+ y[i] = data[2 * i + 1];
+ }
+ DoRTFT320( x, y );
+ for ( i = 0; i < 320; i++ )
+ {
+ data[2 * i] = x[i];
+ data[2 * i + 1] = y[i];
+ }
+
+ if ( sign == -1 )
+ {
+ rfft_post( sine_table, data, len );
+ }
+ }
+ else
+ {
+ if ( len == 512 )
+ {
+ int16_t i;
+ const int16_t log2 = 9;
+ float reordered_data[512];
+
+ if ( sign == -1 )
+ {
+ fft_rel( data, len, log2 );
+ reordered_data[0] = data[0];
+ reordered_data[1] = data[len / 2];
+ for ( i = 1; i < len / 2; i++ )
+ {
+ reordered_data[2 * i] = data[i];
+ reordered_data[2 * i + 1] = data[len - i];
+ }
+ }
+ else
+ {
+ reordered_data[0] = data[0];
+ reordered_data[len / 2] = data[1];
+ for ( i = 1; i < len / 2; i++ )
+ {
+ reordered_data[i] = data[2 * i];
+ reordered_data[len - i] = data[2 * i + 1];
+ }
+ ifft_rel( reordered_data, len, log2 );
+ }
+ mvr2r( reordered_data, data, len );
+ }
+ else
+ {
+ assert( !"Not supported FFT length!" );
+ }
+ }
+
+ return 0;
+}
+
+static void butterfly(
+ const float a,
+ const float b,
+ float *aPlusb,
+ float *aMinusb )
+{
+ *aPlusb = a + b;
+ *aMinusb = a - b;
+
+ return;
+}
+
+static void fft2(
+ float *pInOut )
+{
+ /* FFT MATRIX:
+ 1.0000 1.0000
+ 1.0000 -1.0000
+ */
+ float re1, im1;
+ float re2, im2;
+
+ re1 = pInOut[0];
+ im1 = pInOut[1];
+ re2 = pInOut[2];
+ im2 = pInOut[3];
+ pInOut[0] = re1 + re2;
+ pInOut[1] = im1 + im2;
+
+ pInOut[2] = re1 - re2;
+ pInOut[3] = im1 - im2;
+
+ return;
+}
+
+static const float C31 = 0.5f; /* cos(PI/3); sin(2*PI/3) */
+static const float C32 = 0.866025403784439f; /* cos(PI/3); sin(2*PI/3) */
+
+static void fft3_2(
+ float *pInOut )
+{
+ float re1, im1;
+ float re2, im2;
+ float re3, im3;
+
+ float tmp1, tmp2;
+ float tmp3, tmp4;
+
+ re1 = pInOut[0];
+ im1 = pInOut[1];
+ re2 = pInOut[2];
+ im2 = pInOut[3];
+ re3 = pInOut[4];
+ im3 = pInOut[5];
+
+ /* FFT MATRIX:
+ 1.0000 1.0000 1.0000
+ C31 C32
+ 1.0000 -0.5000 - 0.8660i -0.5000 + 0.8660i
+ 1.0000 -0.5000 + 0.8660i -0.5000 - 0.8660i
+ */
+ tmp1 = re2 + re3;
+ tmp3 = im2 + im3;
+ tmp2 = re2 - re3;
+ tmp4 = im2 - im3;
+ pInOut[0] = re1 + tmp1;
+ pInOut[1] = im1 + tmp3;
+ pInOut[2] = re1 - C31 * tmp1 + C32 * tmp4;
+ pInOut[4] = re1 - C31 * tmp1 - C32 * tmp4;
+
+ pInOut[3] = im1 - C32 * tmp2 - C31 * tmp3;
+ pInOut[5] = im1 + C32 * tmp2 - C31 * tmp3;
+}
+
+
+static void fft4(
+ float *pInOut )
+{
+ float re1, im1;
+ float re2, im2;
+ float re3, im3;
+ float re4, im4;
+
+ float tmp1, tmp2;
+ float tmp3, tmp4;
+ float tmp5, tmp6;
+ float tmp7, tmp8;
+
+ re1 = pInOut[0];
+ im1 = pInOut[1];
+ re2 = pInOut[2];
+ im2 = pInOut[3];
+ re3 = pInOut[4];
+ im3 = pInOut[5];
+ re4 = pInOut[6];
+ im4 = pInOut[7];
+
+ /*
+ 1.0000 1.0000 1.0000 1.0000
+ 1.0000 -1.0000i -1.0000 1.0000i
+ 1.0000 -1.0000 1.0000 -1.0000
+ 1.0000 1.0000i -1.0000 -1.0000i
+ */
+ tmp1 = re1 + re3;
+ tmp3 = re2 + re4;
+ tmp5 = im1 + im3;
+ tmp7 = im2 + im4;
+ pInOut[0] = tmp1 + tmp3;
+ pInOut[4] = tmp1 - tmp3;
+
+ pInOut[1] = tmp5 + tmp7;
+ pInOut[5] = tmp5 - tmp7;
+ tmp2 = re1 - re3;
+ tmp4 = re2 - re4;
+ tmp6 = im1 - im3;
+ tmp8 = im2 - im4;
+ pInOut[2] = tmp2 + tmp8;
+ pInOut[6] = tmp2 - tmp8;
+
+ pInOut[3] = -tmp4 + tmp6;
+ pInOut[7] = tmp4 + tmp6;
+
+ return;
+}
+
+static const float C51 = 0.309016994374947f; /* cos(2*PI/5); */
+static const float C52 = 0.951056516295154f; /* sin(2*PI/5); */
+static const float C53 = 0.809016994374947f; /* cos( PI/5); */
+static const float C54 = 0.587785252292473f; /* sin( PI/5); */
+
+static void fft5(
+ float *pInOut )
+{
+ float re1, im1;
+ float re2, im2;
+ float re3, im3;
+ float re4, im4;
+ float re5, im5;
+
+ float tmp1, tmp2;
+ float tmp3, tmp4;
+ float tmp5, tmp6;
+ float tmp7, tmp8;
+
+
+ re1 = pInOut[0];
+ im1 = pInOut[1];
+ re2 = pInOut[2];
+ im2 = pInOut[3];
+ re3 = pInOut[4];
+ im3 = pInOut[5];
+ re4 = pInOut[6];
+ im4 = pInOut[7];
+ re5 = pInOut[8];
+ im5 = pInOut[9];
+
+ /*
+ 1.0000 1.0000 1.0000 1.0000 1.0000
+ C51 C52 C53 C54
+ 1.0000 0.3090 - 0.9511i -0.8090 - 0.5878i -0.8090 + 0.5878i 0.3090 + 0.9511i
+ 1.0000 -0.8090 - 0.5878i 0.3090 + 0.9511i 0.3090 - 0.9511i -0.8090 + 0.5878i
+ 1.0000 -0.8090 + 0.5878i 0.3090 - 0.9511i 0.3090 + 0.9511i -0.8090 - 0.5878i
+ 1.0000 0.3090 + 0.9511i -0.8090 + 0.5878i -0.8090 - 0.5878i 0.3090 - 0.9511i
+ */
+ tmp1 = re2 + re5;
+ tmp2 = re2 - re5;
+ tmp3 = im2 + im5;
+ tmp4 = im2 - im5;
+ tmp5 = re3 + re4;
+ tmp6 = re3 - re4;
+ tmp7 = im3 + im4;
+ tmp8 = im3 - im4;
+
+
+ pInOut[0] = re1 + tmp1 + tmp5;
+ pInOut[1] = im1 + tmp3 + tmp7;
+
+ pInOut[2] = re1 + C51 * tmp1 - C53 * tmp5 + C52 * tmp4 + C54 * tmp8;
+ pInOut[8] = re1 + C51 * tmp1 - C53 * tmp5 - C52 * tmp4 - C54 * tmp8;
+ pInOut[3] = im1 - C52 * tmp2 - C54 * tmp6 + C51 * tmp3 - C53 * tmp7;
+ pInOut[9] = im1 + C52 * tmp2 + C54 * tmp6 + C51 * tmp3 - C53 * tmp7;
+ pInOut[4] = re1 - C53 * tmp1 + C51 * tmp5 + C54 * tmp4 - C52 * tmp8;
+ pInOut[6] = re1 - C53 * tmp1 + C51 * tmp5 - C54 * tmp4 + C52 * tmp8;
+ pInOut[5] = im1 - C54 * tmp2 + C52 * tmp6 - C53 * tmp3 + C51 * tmp7;
+ pInOut[7] = im1 + C54 * tmp2 - C52 * tmp6 - C53 * tmp3 + C51 * tmp7;
+
+ return;
+}
+
+static const float C81 = 0.707106781186548f; /* cos(PI/4); */
+
+static void fft8_2(
+ float *pInOut )
+{
+ float re0, im0, re4, im4;
+
+ float re1_7p, re1_7m;
+ float im1_7p, im1_7m;
+ float re2_6p, re2_6m;
+ float im2_6p, im2_6m;
+ float re3_5p, re3_5m;
+ float im3_5p, im3_5m;
+
+ re0 = pInOut[0];
+ im0 = pInOut[1];
+ re4 = pInOut[8];
+ im4 = pInOut[9];
+ butterfly( pInOut[1 * 2], pInOut[7 * 2], &re1_7p, &re1_7m );
+ butterfly( pInOut[1 * 2 + 1], pInOut[7 * 2 + 1], &im1_7p, &im1_7m );
+ butterfly( pInOut[2 * 2], pInOut[6 * 2], &re2_6p, &re2_6m );
+ butterfly( pInOut[2 * 2 + 1], pInOut[6 * 2 + 1], &im2_6p, &im2_6m );
+ butterfly( pInOut[3 * 2], pInOut[5 * 2], &re3_5p, &re3_5m );
+ butterfly( pInOut[3 * 2 + 1], pInOut[5 * 2 + 1], &im3_5p, &im3_5m );
+
+ /*
+ 0: 1 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i
+ 1: 1 + 0i C81 - C81i 0 - 1i -C81 - C81i -1 - 0i -C81 + C81i - 0 + 1i C81 + C81i
+ 2: 1 + 0i 0 - 1i -1 - 0i - 0 + 1i 1 + 0i 0 - 1i - 1 - 0i - 0 + 1i
+ 3: 1 + 0i -C81 - C81i -0 + 1i C81 - C81i -1 - 0i C81 + C81i 0 - 1i -C81 + C81i
+ 4: 1 + 0i - 1 - 0i 1 + 0i - 1 - 0i 1 + 0i - 1 - 0i 1 + 0i - 1 - 0i
+ 5: 1 + 0i -C81 + C81i 0 - 1i C81 + C81i -1 - 0i C81 - C81i - 0 + 1i -C81 - C81i
+ 6: 1 + 0i - 0 + 1i -1 - 0i 0 - 1i 1 + 0i - 0 + 1i - 1 - 0i - 0 - 1i
+ 7: 1 + 0i C81 + C81i -0 + 1i -C81 + C81i -1 - 0i -C81 - C81i - 0 - 1i C81 - C81i
+ */
+ pInOut[0] = re0 + re4 + re1_7p + re2_6p + re3_5p;
+ pInOut[1] = im0 + im4 + im1_7p + im2_6p + im3_5p;
+
+ pInOut[2] = re0 + C81 * ( re1_7p - re3_5p ) - re4 + C81 * ( im1_7m + im3_5m ) + im2_6m;
+ pInOut[3] = im0 + C81 * ( im1_7p - im3_5p ) - im4 - C81 * ( re1_7m + re3_5m ) - re2_6m;
+
+ pInOut[4] = re0 - re2_6p + re4 + im1_7m - im3_5m;
+ pInOut[5] = im0 - im2_6p + im4 - re1_7m + re3_5m;
+
+ pInOut[6] = re0 + C81 * ( -re1_7p + re3_5p ) - re4 + C81 * ( im1_7m + im3_5m ) - im2_6m;
+ pInOut[7] = im0 + C81 * ( -im1_7p + im3_5p ) - im4 - C81 * ( re1_7m + re3_5m ) + re2_6m;
+
+ pInOut[8] = re0 - re1_7p + re2_6p - re3_5p + re4;
+ pInOut[9] = im0 - im1_7p + im2_6p - im3_5p + im4;
+
+ pInOut[10] = re0 + C81 * ( -re1_7p + re3_5p ) - re4 - C81 * ( im1_7m + im3_5m ) + im2_6m;
+ pInOut[11] = im0 + C81 * ( -im1_7p + im3_5p ) - im4 + C81 * ( re1_7m + re3_5m ) - re2_6m;
+
+ pInOut[12] = re0 - re2_6p + re4 - im1_7m + im3_5m;
+ pInOut[13] = im0 - im2_6p + im4 + re1_7m - re3_5m;
+
+ pInOut[14] = re0 + C81 * ( re1_7p - re3_5p ) - re4 - C81 * ( im1_7m + im3_5m ) - im2_6m;
+ pInOut[15] = im0 + C81 * ( im1_7p - im3_5p ) - im4 + C81 * ( re1_7m + re3_5m ) + re2_6m;
+
+ return;
+}
+
+static void nextFFT(
+ float *x,
+ const int16_t length )
+{
+ switch ( length )
+ {
+ case 2:
+ fft2( x );
+ break;
+ case 3:
+ fft3_2( x );
+ break;
+ case 4:
+ fft4( x );
+ break;
+ case 5:
+ fft5( x );
+ break;
+ case 8:
+ fft8_2( x );
+ break;
+ default:
+ assert( !"length not supported" );
+ break;
+ }
+
+ return;
+}
+
+static const int16_t CTFFTfactors[] = { 9, 8, 7, 5, 4, 3, 2, 0 };
+
+static __inline int16_t findFactor(
+ const int16_t length )
+{
+ int16_t i = 0;
+ int16_t factor = 0;
+
+ while ( CTFFTfactors[i] != 0 )
+ {
+ if ( 0 == ( length % CTFFTfactors[i] ) )
+ {
+ factor = CTFFTfactors[i];
+ break;
+ }
+ i++;
+ }
+ return factor;
+}
+
+static __inline void twiddle(
+ float *x,
+ const int16_t length,
+ const int16_t n1,
+ const int16_t n2 )
+{
+ int16_t i, ii;
+ double pi = 4. * atan( 1. );
+ float sinValOrg, cosValOrg;
+ float sinVal = 0.f, cosVal = 1.f;
+ float twReal = 0.f, twImag = 1.f;
+
+ cosValOrg = (float) cos( -2 * pi * 1. / (double) length );
+ sinValOrg = (float) sin( -2 * pi * 1. / (double) length );
+ for ( i = 1; i < n1; i++ )
+ {
+ float tmp;
+ twReal = 1.f;
+ twImag = 0.f;
+ tmp = cosVal * cosValOrg - sinVal * sinValOrg;
+ sinVal = sinVal * cosValOrg + cosVal * sinValOrg;
+ cosVal = tmp;
+ for ( ii = 1; ii < n2; ii++ )
+ {
+ float xRe, xIm, tmpReal;
+ /* cos(x+y) = cos(x)*cos(y) - sin(x)*sin(y); */
+ /* sin(x+y) = sin(x)*cos(y) + sin(y)*cos(x); */
+ tmpReal = twReal * cosVal - twImag * sinVal;
+ twImag = twImag * cosVal + sinVal * twReal;
+ twReal = tmpReal;
+ xRe = x[2 * ( i * n2 + ii )];
+ xIm = x[2 * ( i * n2 + ii ) + 1];
+ x[2 * ( i * n2 + ii )] = twReal * xRe - twImag * xIm;
+ x[2 * ( i * n2 + ii ) + 1] = twImag * xRe + twReal * xIm;
+ }
+ tmp = cosVal;
+ }
+
+ return;
+}
+
+static void cooleyTukeyFFT(
+ float *x,
+ const int16_t length,
+ float *scratch )
+{
+ int16_t factor;
+ int16_t i, ii;
+ int16_t n1, n2;
+ int16_t cnt = 0;
+ float *src, *dest;
+
+ switch ( length )
+ {
+ case 1:
+ break;
+ case 2:
+ fft2( x );
+ break;
+ case 3:
+ fft3_2( x );
+ break;
+ case 4:
+ fft4( x );
+ break;
+ case 5:
+ fft5( x );
+ break;
+ case 8:
+ fft8_2( x );
+ break;
+ default:
+ {
+ factor = findFactor( length );
+ if ( factor > 0 && ( length / factor > 1 ) )
+ {
+ n1 = factor;
+ n2 = length / factor;
+
+ /* DATA Resorting for stage1 */
+ dest = scratch;
+ for ( i = 0; i < 2 * n1; i += 2 )
+ {
+ src = x + i;
+ for ( ii = 0; ii < n2; ii++ )
+ {
+ /* *dest++ = x[2*(i+ii*n1)]; */
+ /* *dest++ = x[2*(i+ii*n1)+1]; */
+ *dest++ = *src;
+ *dest++ = *( src + 1 );
+ src += 2 * n1;
+ }
+ }
+ src = scratch;
+ dest = x;
+ for ( i = 0; i < length; i++ )
+ {
+ *dest++ = *src++;
+ *dest++ = *src++;
+ }
+ /* perform n1 ffts of length n2 */
+ for ( i = 0; i < n1; i++ )
+ {
+ cooleyTukeyFFT( x + 2 * i * n2, n2, scratch + 2 * i * n2 );
+ }
+ /*data twiddeling */
+ twiddle( x, length, n1, n2 );
+ /* DATA Resorting for stage2 */
+ cnt = 0;
+ for ( i = 0; i < n2; i++ )
+ {
+ for ( ii = 0; ii < n1; ii++ )
+ {
+ scratch[2 * cnt] = x[2 * ( i + ii * n2 )];
+ scratch[2 * cnt + 1] = x[2 * ( i + ii * n2 ) + 1];
+ cnt++;
+ }
+ }
+ /* perform n2 ffts of length n1 */
+ for ( i = 0; i < n2; i++ )
+ {
+ nextFFT( scratch + 2 * i * n1, n1 );
+ }
+ cnt = 0;
+ for ( i = 0; i < n1; i++ )
+ {
+ for ( ii = 0; ii < n2; ii++ )
+ {
+ x[2 * cnt] = scratch[2 * ( i + ii * n1 )];
+ x[2 * cnt + 1] = scratch[2 * ( i + ii * n1 ) + 1];
+ cnt++;
+ }
+ }
+ }
+ else
+ {
+ assert( !"length not supported" );
+ }
+ }
+ }
+
+ return;
+}
+
+static void pfaDFT(
+ float *x,
+ const int16_t length,
+ float *scratch1,
+ const int16_t numFactors,
+ const int16_t *factor )
+{
+ int16_t i, ii;
+ int16_t cnt;
+
+ if ( numFactors > 1 )
+ {
+ float *tmp = scratch1;
+ int16_t n1_inv = 1, n2_inv = 1;
+ int16_t n2 = factor[0 /*idx*/];
+ int16_t n1 = length / n2;
+ int16_t idx, incr;
+
+ while ( ( ( n1_inv * n1 ) % n2 ) != 1 )
+ {
+ n1_inv++;
+ }
+ while ( ( ( n2_inv * n2 ) % n1 ) != 1 )
+ {
+ n2_inv++;
+ }
+ idx = 0;
+ incr = n1 * n1_inv;
+ cnt = 0;
+ for ( i = 0; i < n1; i++ )
+ {
+ for ( ii = 0; ii < n2 - 1; ii++ )
+ {
+ tmp[cnt++] = x[2 * idx];
+ tmp[cnt++] = x[2 * idx + 1];
+
+ idx += incr;
+ if ( idx > length )
+ {
+ idx -= length;
+ }
+ }
+ tmp[cnt++] = x[2 * idx];
+ tmp[cnt++] = x[2 * idx + 1];
+ idx++;
+ }
+ for ( cnt = 0; cnt < length; cnt += n2 )
+ {
+ cooleyTukeyFFT( tmp + 2 * cnt, n2, x + 2 * cnt );
+ }
+ for ( cnt = 0; cnt < n1; cnt++ )
+ {
+ for ( i = 0; i < n2; i++ )
+ {
+ x[2 * ( cnt + i * n1 )] = tmp[2 * ( cnt * n2 + i )];
+ x[2 * ( cnt + i * n1 ) + 1] = tmp[2 * ( cnt * n2 + i ) + 1];
+ }
+ }
+ for ( cnt = 0; cnt < length; cnt += n1 )
+ {
+ pfaDFT( x + 2 * cnt, n1, tmp, numFactors - 1, &factor[1] );
+ }
+ idx = 0;
+ cnt = 0;
+ for ( i = 0; i < n2; i++ )
+ {
+ idx = i * n1;
+ for ( ii = 0; ii < n1; ii++ )
+ {
+ tmp[2 * idx] = x[cnt++];
+ tmp[2 * idx + 1] = x[cnt++];
+ idx += n2;
+ if ( idx > length )
+ {
+ idx -= length;
+ }
+ }
+ }
+ for ( cnt = 0; cnt < length; cnt++ )
+ {
+ x[2 * cnt] = tmp[2 * cnt];
+ x[2 * cnt + 1] = tmp[2 * cnt + 1];
+ }
+ }
+ else
+ {
+ cooleyTukeyFFT( x, length, scratch1 );
+ }
+
+ return;
+}
+
+static void fftf_interleave(
+ float *re,
+ float *im,
+ float *out,
+ const int16_t len )
+{
+ int16_t i = 0;
+
+ for ( i = 0; i < len; i++ )
+ {
+ *out++ = *re++;
+ *out++ = *im++;
+ }
+
+ return;
+}
+
+static void fftf_deinterleave(
+ float *in,
+ float *re,
+ float *im,
+ const int16_t len )
+{
+ int16_t i = 0;
+
+ for ( i = 0; i < len; i++ )
+ {
+ *re++ = *in++;
+ *im++ = *in++;
+ }
+
+ return;
+}
+
+static void DoRTFT600(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ float scratch[1200], cmplx[1200];
+ const int16_t factors[3] = { 25, 8, 3 };
+
+ fftf_interleave( x, y, cmplx, 600 );
+ pfaDFT( cmplx, 600, scratch, 3, factors );
+ fftf_deinterleave( cmplx, x, y, 600 );
+
+ return;
+}
+
+static void DoRTFT400(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ float scratch[800], cmplx[800];
+ const int16_t factors[2] = { 25, 16 };
+
+ fftf_interleave( x, y, cmplx, 400 );
+ pfaDFT( cmplx, 400, scratch, 2, factors );
+ fftf_deinterleave( cmplx, x, y, 400 );
+
+
+ return;
+}
+
+static void DoRTFT240(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ float scratch[480], cmplx[480];
+ const int16_t factors[3] = { 16, 5, 3 };
+
+ fftf_interleave( x, y, cmplx, 240 );
+ pfaDFT( cmplx, 240, scratch, 3, factors );
+ fftf_deinterleave( cmplx, x, y, 240 );
+
+ return;
+}
+
+static void DoRTFT200(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ float scratch[400], cmplx[400];
+ const int16_t factors[2] = { 25, 8 };
+
+ fftf_interleave( x, y, cmplx, 200 );
+ pfaDFT( cmplx, 200, scratch, 2, factors );
+ fftf_deinterleave( cmplx, x, y, 200 );
+
+ return;
+}
+
+static void DoRTFT100(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+)
+{
+ float scratch[200], cmplx[200];
+ const int16_t factors[2] = { 25, 4 };
+
+ fftf_interleave( x, y, cmplx, 100 );
+ pfaDFT( cmplx, 100, scratch, 2, factors );
+ fftf_deinterleave( cmplx, x, y, 100 );
+
+ return;
+}
+
+
+void DoFFT(
+ float *re2,
+ float *im2,
+ const int16_t length )
+{
+ switch ( length )
+ {
+ case 600:
+ DoRTFT600( re2, im2 );
+ break;
+ case 480:
+ DoRTFT480( re2, im2 );
+ break;
+ case 400:
+ DoRTFT400( re2, im2 );
+ break;
+ case 320:
+ DoRTFT320( re2, im2 );
+ break;
+ case 256:
+ DoRTFTn( re2, im2, 256 );
+ break;
+ case 240:
+ DoRTFT240( re2, im2 );
+ break;
+ case 200:
+ DoRTFT200( re2, im2 );
+ break;
+ case 160:
+ DoRTFT160( re2, im2 );
+ break;
+ case 128:
+ DoRTFT128( re2, im2 );
+ break;
+ case 120:
+ DoRTFT120( re2, im2 );
+ break;
+ case 100:
+ DoRTFT100( re2, im2 );
+ break;
+ case 80:
+ DoRTFT80( re2, im2 );
+ break;
+ case 64:
+ DoRTFTn( re2, im2, 64 );
+ break;
+ case 40:
+ DoRTFT40( re2, im2 );
+ break;
+ case 20:
+ DoRTFT20( re2, im2 );
+ break;
+ default:
+ assert( !"fft is not supported!" );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * Low-complexity implementation of FFT
+ *-----------------------------------------------------------------*/
+
+static void fft_len5(
+ float *re,
+ float *im,
+ const int16_t s )
+{
+ float x0, x1, x2, x3, x4;
+ float r1, r2, r3, r4;
+ float s1, s2, s3, s4;
+ float t;
+
+ x0 = re[s * 0];
+ x1 = re[s * 1];
+ x2 = re[s * 2];
+ x3 = re[s * 3];
+ x4 = re[s * 4];
+
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x2 + x3 );
+ r2 = ( x2 - x3 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ re[0] = ( x0 + r1 );
+
+ r1 = ( re[0] + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( r4 + r2 ) * FFT_C51 );
+
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ x0 = im[s * 0];
+ x1 = im[s * 1];
+ x2 = im[s * 2];
+ x3 = im[s * 3];
+ x4 = im[s * 4];
+
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x2 + x3 );
+ s2 = ( x2 - x3 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ im[0] = ( x0 + s1 );
+
+ s1 = ( im[0] + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ re[s * 1] = ( r1 + s2 );
+ re[s * 4] = ( r1 - s2 );
+ re[s * 2] = ( r3 - s4 );
+ re[s * 3] = ( r3 + s4 );
+
+ im[s * 1] = ( s1 - r2 );
+ im[s * 4] = ( s1 + r2 );
+ im[s * 2] = ( s3 + r4 );
+ im[s * 3] = ( s3 - r4 );
+
+ return;
+}
+
+static void fft_len8(
+ float *re,
+ float *im,
+ const int16_t s )
+{
+ float x00, x01, x02, x03, x04, x05, x06, x07;
+ float x08, x09, x10, x11, x12, x13, x14, x15;
+ float t00, t01, t02, t03, t04, t05, t06, t07;
+ float t08, t09, t10, t11, t12, t13, t14, t15;
+ float s00, s01, s02, s03, s04, s05, s06, s07;
+ float s08, s09, s10, s11, s12, s13, s14, s15;
+
+ x00 = re[s * 0];
+ x01 = im[s * 0];
+ x02 = re[s * 1];
+ x03 = im[s * 1];
+ x04 = re[s * 2];
+ x05 = im[s * 2];
+ x06 = re[s * 3];
+ x07 = im[s * 3];
+ x08 = re[s * 4];
+ x09 = im[s * 4];
+ x10 = re[s * 5];
+ x11 = im[s * 5];
+ x12 = re[s * 6];
+ x13 = im[s * 6];
+ x14 = re[s * 7];
+ x15 = im[s * 7];
+
+ t00 = ( x00 + x08 );
+ t02 = ( x00 - x08 );
+ t01 = ( x01 + x09 );
+ t03 = ( x01 - x09 );
+ t04 = ( x02 + x10 );
+ t06 = ( x02 - x10 );
+ t05 = ( x03 + x11 );
+ t07 = ( x03 - x11 );
+ t08 = ( x04 + x12 );
+ t10 = ( x04 - x12 );
+ t09 = ( x05 + x13 );
+ t11 = ( x05 - x13 );
+ t12 = ( x06 + x14 );
+ t14 = ( x06 - x14 );
+ t13 = ( x07 + x15 );
+ t15 = ( x07 - x15 );
+
+ s00 = ( t00 + t08 );
+ s04 = ( t00 - t08 );
+ s01 = ( t01 + t09 );
+ s05 = ( t01 - t09 );
+ s08 = ( t02 - t11 );
+ s10 = ( t02 + t11 );
+ s09 = ( t03 + t10 );
+ s11 = ( t03 - t10 );
+ s02 = ( t04 + t12 );
+ s07 = ( t04 - t12 );
+ s03 = ( t05 + t13 );
+ s06 = ( t13 - t05 );
+
+ t01 = ( t06 + t14 );
+ t02 = ( t06 - t14 );
+ t00 = ( t07 + t15 );
+ t03 = ( t07 - t15 );
+
+ s12 = ( ( t00 + t02 ) * FFT_C81 );
+ s14 = ( ( t00 - t02 ) * FFT_C81 );
+ s13 = ( ( t03 - t01 ) * FFT_C81 );
+ s15 = ( ( t01 + t03 ) * FFT_C82 );
+
+ re[s * 0] = ( s00 + s02 );
+ re[s * 4] = ( s00 - s02 );
+ im[s * 0] = ( s01 + s03 );
+ im[s * 4] = ( s01 - s03 );
+ re[s * 2] = ( s04 - s06 );
+ re[s * 6] = ( s04 + s06 );
+ im[s * 2] = ( s05 - s07 );
+ im[s * 6] = ( s05 + s07 );
+ re[s * 3] = ( s08 + s14 );
+ re[s * 7] = ( s08 - s14 );
+ im[s * 3] = ( s09 + s15 );
+ im[s * 7] = ( s09 - s15 );
+ re[s * 1] = ( s10 + s12 );
+ re[s * 5] = ( s10 - s12 );
+ im[s * 1] = ( s11 + s13 );
+ im[s * 5] = ( s11 - s13 );
+
+ return;
+}
+
+static void fft_len10(
+ float *re,
+ float *im,
+ const int16_t s )
+{
+ float t;
+ float x0, x1, x2, x3, x4;
+ float r1, r2, r3, r4;
+ float s1, s2, s3, s4;
+ float y00, y01, y02, y03, y04, y05, y06, y07, y08, y09;
+ float y10, y11, y12, y13, y14, y15, y16, y17, y18, y19;
+
+ x0 = re[s * 0];
+ x1 = re[s * 2];
+ x2 = re[s * 4];
+ x3 = re[s * 6];
+ x4 = re[s * 8];
+
+ r1 = ( x3 + x2 );
+ r4 = ( x3 - x2 );
+ r3 = ( x1 + x4 );
+ r2 = ( x1 - x4 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y00 = ( x0 + r1 );
+ r1 = ( y00 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ x0 = im[s * 0];
+ x1 = im[s * 2];
+ x2 = im[s * 4];
+ x3 = im[s * 6];
+ x4 = im[s * 8];
+
+ s1 = ( x3 + x2 );
+ s4 = ( x3 - x2 );
+ s3 = ( x1 + x4 );
+ s2 = ( x1 - x4 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y01 = ( x0 + s1 );
+ s1 = ( y01 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y04 = ( r1 + s2 );
+ y16 = ( r1 - s2 );
+ y08 = ( r3 - s4 );
+ y12 = ( r3 + s4 );
+
+ y05 = ( s1 - r2 );
+ y17 = ( s1 + r2 );
+ y09 = ( s3 + r4 );
+ y13 = ( s3 - r4 );
+
+ x0 = re[s * 5];
+ x1 = re[s * 1];
+ x2 = re[s * 3];
+ x3 = re[s * 7];
+ x4 = re[s * 9];
+
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x3 + x2 );
+ r2 = ( x3 - x2 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y02 = ( x0 + r1 );
+ r1 = ( y02 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ x0 = im[s * 5];
+ x1 = im[s * 1];
+ x2 = im[s * 3];
+ x3 = im[s * 7];
+ x4 = im[s * 9];
+
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x3 + x2 );
+ s2 = ( x3 - x2 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y03 = ( x0 + s1 );
+ s1 = ( y03 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y06 = ( r1 + s2 );
+ y18 = ( r1 - s2 );
+ y10 = ( r3 - s4 );
+ y14 = ( r3 + s4 );
+
+ y07 = ( s1 - r2 );
+ y19 = ( s1 + r2 );
+ y11 = ( s3 + r4 );
+ y15 = ( s3 - r4 );
+
+ re[s * 0] = ( y00 + y02 );
+ im[s * 0] = ( y01 + y03 );
+ re[s * 5] = ( y00 - y02 );
+ im[s * 5] = ( y01 - y03 );
+
+ re[s * 2] = ( y04 + y06 );
+ im[s * 2] = ( y05 + y07 );
+ re[s * 7] = ( y04 - y06 );
+ im[s * 7] = ( y05 - y07 );
+
+ re[s * 4] = ( y08 + y10 );
+ im[s * 4] = ( y09 + y11 );
+ re[s * 9] = ( y08 - y10 );
+ im[s * 9] = ( y09 - y11 );
+
+ re[s * 6] = ( y12 + y14 );
+ im[s * 6] = ( y13 + y15 );
+ re[s * 1] = ( y12 - y14 );
+ im[s * 1] = ( y13 - y15 );
+
+ re[s * 8] = ( y16 + y18 );
+ im[s * 8] = ( y17 + y19 );
+ re[s * 3] = ( y16 - y18 );
+ im[s * 3] = ( y17 - y19 );
+
+ return;
+}
+
+static void fft_len15(
+ float *re,
+ float *im,
+ const int16_t s )
+{
+ float t;
+ float r1, r2, r3, r4;
+ float s1, s2, s3, s4;
+ float x00, x01, x02, x03, x04, x05, x06, x07, x08, x09;
+ float x10, x11, x12, x13, x14, x15, x16, x17, x18, x19;
+ float x20, x21, x22, x23, x24, x25, x26, x27, x28, x29;
+ float y00, y01, y02, y03, y04, y05, y06, y07, y08, y09;
+ float y10, y11, y12, y13, y14, y15, y16, y17, y18, y19;
+ float y20, y21, y22, y23, y24, y25, y26, y27, y28, y29;
+
+ x00 = re[s * 0];
+ x01 = im[s * 0];
+ x02 = re[s * 3];
+ x03 = im[s * 3];
+ x04 = re[s * 6];
+ x05 = im[s * 6];
+ x06 = re[s * 9];
+ x07 = im[s * 9];
+ x08 = re[s * 12];
+ x09 = im[s * 12];
+
+ x10 = re[s * 5];
+ x11 = im[s * 5];
+ x12 = re[s * 8];
+ x13 = im[s * 8];
+ x14 = re[s * 11];
+ x15 = im[s * 11];
+ x16 = re[s * 14];
+ x17 = im[s * 14];
+ x18 = re[s * 2];
+ x19 = im[s * 2];
+
+ x20 = re[s * 10];
+ x21 = im[s * 10];
+ x22 = re[s * 13];
+ x23 = im[s * 13];
+ x24 = re[s * 1];
+ x25 = im[s * 1];
+ x26 = re[s * 4];
+ x27 = im[s * 4];
+ x28 = re[s * 7];
+ x29 = im[s * 7];
+
+ r1 = ( x02 + x08 );
+ r4 = ( x02 - x08 );
+ r3 = ( x04 + x06 );
+ r2 = ( x04 - x06 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y00 = ( x00 + r1 );
+ r1 = ( y00 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x03 + x09 );
+ s4 = ( x03 - x09 );
+ s3 = ( x05 + x07 );
+ s2 = ( x05 - x07 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y01 = ( x01 + s1 );
+ s1 = ( y01 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y02 = ( r1 + s2 );
+ y08 = ( r1 - s2 );
+ y04 = ( r3 - s4 );
+ y06 = ( r3 + s4 );
+
+ y03 = ( s1 - r2 );
+ y09 = ( s1 + r2 );
+ y05 = ( s3 + r4 );
+ y07 = ( s3 - r4 );
+
+ r1 = ( x12 + x18 );
+ r4 = ( x12 - x18 );
+ r3 = ( x14 + x16 );
+ r2 = ( x14 - x16 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y10 = ( x10 + r1 );
+ r1 = ( y10 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x13 + x19 );
+ s4 = ( x13 - x19 );
+ s3 = ( x15 + x17 );
+ s2 = ( x15 - x17 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y11 = ( x11 + s1 );
+ s1 = ( y11 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y12 = ( r1 + s2 );
+ y18 = ( r1 - s2 );
+ y14 = ( r3 - s4 );
+ y16 = ( r3 + s4 );
+
+ y13 = ( s1 - r2 );
+ y19 = ( s1 + r2 );
+ y15 = ( s3 + r4 );
+ y17 = ( s3 - r4 );
+
+ r1 = ( x22 + x28 );
+ r4 = ( x22 - x28 );
+ r3 = ( x24 + x26 );
+ r2 = ( x24 - x26 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y20 = ( x20 + r1 );
+ r1 = ( y20 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x23 + x29 );
+ s4 = ( x23 - x29 );
+ s3 = ( x25 + x27 );
+ s2 = ( x25 - x27 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y21 = ( x21 + s1 );
+ s1 = ( y21 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y22 = ( r1 + s2 );
+ y28 = ( r1 - s2 );
+ y24 = ( r3 - s4 );
+ y26 = ( r3 + s4 );
+
+ y23 = ( s1 - r2 );
+ y29 = ( s1 + r2 );
+ y25 = ( s3 + r4 );
+ y27 = ( s3 - r4 );
+
+ r1 = ( y10 + y20 );
+ r2 = ( ( y10 - y20 ) * FFT_C31 );
+ re[s * 0] = ( y00 + r1 );
+ r1 = ( y00 - r1 * 0.5f );
+
+ s1 = ( y11 + y21 );
+ s2 = ( ( y11 - y21 ) * FFT_C31 );
+ im[s * 0] = ( y01 + s1 );
+ s1 = ( y01 - s1 * 0.5f );
+
+ re[s * 10] = ( r1 - s2 );
+ re[s * 5] = ( r1 + s2 );
+ im[s * 10] = ( s1 + r2 );
+ im[s * 5] = ( s1 - r2 );
+
+ r1 = ( y12 + y22 );
+ r2 = ( ( y12 - y22 ) * FFT_C31 );
+ re[s * 6] = ( y02 + r1 );
+ r1 = ( y02 - r1 * 0.5f );
+
+ s1 = ( y13 + y23 );
+ s2 = ( ( y13 - y23 ) * FFT_C31 );
+ im[s * 6] = ( y03 + s1 );
+ s1 = ( y03 - s1 * 0.5f );
+
+ re[s * 1] = ( r1 - s2 );
+ re[s * 11] = ( r1 + s2 );
+ im[s * 1] = ( s1 + r2 );
+ im[s * 11] = ( s1 - r2 );
+
+ r1 = ( y14 + y24 );
+ r2 = ( ( y14 - y24 ) * FFT_C31 );
+ re[s * 12] = ( y04 + r1 );
+ r1 = ( y04 - r1 * 0.5f );
+
+ s1 = ( y15 + y25 );
+ s2 = ( ( y15 - y25 ) * FFT_C31 );
+ im[s * 12] = ( y05 + s1 );
+ s1 = ( y05 - s1 * 0.5f );
+
+ re[s * 7] = ( r1 - s2 );
+ re[s * 2] = ( r1 + s2 );
+ im[s * 7] = ( s1 + r2 );
+ im[s * 2] = ( s1 - r2 );
+
+ r1 = ( y16 + y26 );
+ r2 = ( ( y16 - y26 ) * FFT_C31 );
+ re[s * 3] = ( y06 + r1 );
+ r1 = ( y06 - r1 * 0.5f );
+
+ s1 = ( y17 + y27 );
+ s2 = ( ( y17 - y27 ) * FFT_C31 );
+ im[s * 3] = ( y07 + s1 );
+ s1 = ( y07 - s1 * 0.5f );
+
+ re[s * 13] = ( r1 - s2 );
+ re[s * 8] = ( r1 + s2 );
+ im[s * 13] = ( s1 + r2 );
+ im[s * 8] = ( s1 - r2 );
+
+ r1 = ( y18 + y28 );
+ r2 = ( ( y18 - y28 ) * FFT_C31 );
+ re[s * 9] = ( y08 + r1 );
+ r1 = ( y08 - r1 * 0.5f );
+
+ s1 = ( y19 + y29 );
+ s2 = ( ( y19 - y29 ) * FFT_C31 );
+ im[s * 9] = ( y09 + s1 );
+ s1 = ( y09 - s1 * 0.5f );
+
+ re[s * 4] = ( r1 - s2 );
+ re[s * 14] = ( r1 + s2 );
+ im[s * 4] = ( s1 + r2 );
+ im[s * 14] = ( s1 - r2 );
+
+ return;
+}
+
+static void fft_len16(
+ float *re,
+ float *im,
+ const int16_t s )
+{
+ float x0, x1, x2, x3, x4, x5, x6, x7;
+ float t0, t1, t2, t3, t4, t5, t6, t7;
+ float y00, y01, y02, y03, y04, y05, y06, y07;
+ float y08, y09, y10, y11, y12, y13, y14, y15;
+ float y16, y17, y18, y19, y20, y21, y22, y23;
+ float y24, y25, y26, y27, y28, y29, y30, y31;
+
+ x0 = re[s * 0];
+ x1 = im[s * 0];
+ x2 = re[s * 4];
+ x3 = im[s * 4];
+ x4 = re[s * 8];
+ x5 = im[s * 8];
+ x6 = re[s * 12];
+ x7 = im[s * 12];
+
+ t0 = ( x0 + x4 );
+ t2 = ( x0 - x4 );
+ t1 = ( x1 + x5 );
+ t3 = ( x1 - x5 );
+ t4 = ( x2 + x6 );
+ t7 = ( x2 - x6 );
+ t5 = ( x7 + x3 );
+ t6 = ( x7 - x3 );
+
+ y00 = ( t0 + t4 );
+ y01 = ( t1 + t5 );
+ y02 = ( t2 - t6 );
+ y03 = ( t3 - t7 );
+ y04 = ( t0 - t4 );
+ y05 = ( t1 - t5 );
+ y06 = ( t2 + t6 );
+ y07 = ( t3 + t7 );
+
+ x0 = re[s * 1];
+ x1 = im[s * 1];
+ x2 = re[s * 5];
+ x3 = im[s * 5];
+ x4 = re[s * 9];
+ x5 = im[s * 9];
+ x6 = re[s * 13];
+ x7 = im[s * 13];
+
+ t0 = ( x0 + x4 );
+ t2 = ( x0 - x4 );
+ t1 = ( x1 + x5 );
+ t3 = ( x1 - x5 );
+ t4 = ( x2 + x6 );
+ t7 = ( x2 - x6 );
+ t5 = ( x7 + x3 );
+ t6 = ( x7 - x3 );
+
+ y08 = ( t0 + t4 );
+ y09 = ( t1 + t5 );
+ y10 = ( t2 - t6 );
+ y11 = ( t3 - t7 );
+ y12 = ( t0 - t4 );
+ y13 = ( t1 - t5 );
+ y14 = ( t2 + t6 );
+ y15 = ( t3 + t7 );
+
+ x0 = re[s * 2];
+ x1 = im[s * 2];
+ x2 = re[s * 6];
+ x3 = im[s * 6];
+ x4 = re[s * 10];
+ x5 = im[s * 10];
+ x6 = re[s * 14];
+ x7 = im[s * 14];
+
+ t0 = ( x0 + x4 );
+ t2 = ( x0 - x4 );
+ t1 = ( x1 + x5 );
+ t3 = ( x1 - x5 );
+ t4 = ( x2 + x6 );
+ t7 = ( x2 - x6 );
+ t5 = ( x7 + x3 );
+ t6 = ( x7 - x3 );
+
+ y16 = ( t0 + t4 );
+ y17 = ( t1 + t5 );
+ y18 = ( t2 - t6 );
+ y19 = ( t3 - t7 );
+ y20 = ( t1 - t5 );
+ y21 = ( t4 - t0 );
+ y22 = ( t2 + t6 );
+ y23 = ( t3 + t7 );
+
+ x0 = re[s * 3];
+ x1 = im[s * 3];
+ x2 = re[s * 7];
+ x3 = im[s * 7];
+ x4 = re[s * 11];
+ x5 = im[s * 11];
+ x6 = re[s * 15];
+ x7 = im[s * 15];
+
+ t0 = ( x0 + x4 );
+ t2 = ( x0 - x4 );
+ t1 = ( x1 + x5 );
+ t3 = ( x1 - x5 );
+ t4 = ( x2 + x6 );
+ t7 = ( x2 - x6 );
+ t5 = ( x7 + x3 );
+ t6 = ( x7 - x3 );
+
+ y24 = ( t0 + t4 );
+ y25 = ( t1 + t5 );
+ y26 = ( t2 - t6 );
+ y27 = ( t3 - t7 );
+ y28 = ( t0 - t4 );
+ y29 = ( t1 - t5 );
+ y30 = ( t2 + t6 );
+ y31 = ( t3 + t7 );
+
+ x0 = ( y22 * FFT_C162 );
+ x1 = ( y23 * FFT_C162 );
+ y22 = ( x0 - x1 );
+ y23 = ( x0 + x1 );
+
+ x0 = ( y28 * FFT_C162 );
+ x1 = ( y29 * FFT_C162 );
+ y28 = ( x0 - x1 );
+ y29 = ( x0 + x1 );
+
+ x0 = ( y12 * FFT_C161 );
+ x1 = ( y13 * FFT_C161 );
+ y12 = ( x0 + x1 );
+ y13 = ( x1 - x0 );
+
+ x0 = ( y18 * FFT_C161 );
+ x1 = ( y19 * FFT_C161 );
+ y18 = ( x0 + x1 );
+ y19 = ( x1 - x0 );
+
+ x0 = ( y10 * FFT_C163 );
+ x1 = ( y11 * FFT_C166 );
+ x2 = ( y10 * FFT_C166 );
+ x3 = ( y11 * FFT_C163 );
+ y10 = ( x0 - x1 );
+ y11 = ( x2 + x3 );
+
+ x0 = ( y14 * FFT_C165 );
+ x1 = ( y15 * FFT_C164 );
+ x2 = ( y14 * FFT_C164 );
+ x3 = ( y15 * FFT_C165 );
+ y14 = ( x0 - x1 );
+ y15 = ( x2 + x3 );
+
+ x0 = ( y26 * FFT_C165 );
+ x1 = ( y27 * FFT_C164 );
+ x2 = ( y26 * FFT_C164 );
+ x3 = ( y27 * FFT_C165 );
+ y26 = ( x0 - x1 );
+ y27 = ( x2 + x3 );
+
+ x0 = ( y30 * FFT_C164 );
+ x1 = ( y31 * FFT_C165 );
+ x2 = ( y30 * FFT_C165 );
+ x3 = ( y31 * FFT_C164 );
+ y30 = ( x0 - x1 );
+ y31 = ( x2 + x3 );
+
+ t0 = ( y00 + y16 );
+ t2 = ( y00 - y16 );
+ t1 = ( y01 + y17 );
+ t3 = ( y01 - y17 );
+ t4 = ( y08 + y24 );
+ t7 = ( y08 - y24 );
+ t5 = ( y25 + y09 );
+ t6 = ( y25 - y09 );
+
+ re[s * 0] = ( t0 + t4 );
+ im[s * 0] = ( t1 + t5 );
+ re[s * 4] = ( t2 - t6 );
+ im[s * 4] = ( t3 - t7 );
+ re[s * 8] = ( t0 - t4 );
+ im[s * 8] = ( t1 - t5 );
+ re[s * 12] = ( t2 + t6 );
+ im[s * 12] = ( t3 + t7 );
+
+ t0 = ( y02 + y18 );
+ t2 = ( y02 - y18 );
+ t1 = ( y03 + y19 );
+ t3 = ( y03 - y19 );
+ t4 = ( y10 + y26 );
+ t7 = ( y10 - y26 );
+ t5 = ( y27 + y11 );
+ t6 = ( y27 - y11 );
+
+ re[s * 1] = ( t0 + t4 );
+ im[s * 1] = ( t1 + t5 );
+ re[s * 5] = ( t2 - t6 );
+ im[s * 5] = ( t3 - t7 );
+ re[s * 9] = ( t0 - t4 );
+ im[s * 9] = ( t1 - t5 );
+ re[s * 13] = ( t2 + t6 );
+ im[s * 13] = ( t3 + t7 );
+
+ t0 = ( y04 + y20 );
+ t2 = ( y04 - y20 );
+ t1 = ( y05 + y21 );
+ t3 = ( y05 - y21 );
+ t4 = ( y12 + y28 );
+ t7 = ( y12 - y28 );
+ t5 = ( y29 + y13 );
+ t6 = ( y29 - y13 );
+
+ re[s * 2] = ( t0 + t4 );
+ im[s * 2] = ( t1 + t5 );
+ re[s * 6] = ( t2 - t6 );
+ im[s * 6] = ( t3 - t7 );
+ re[s * 10] = ( t0 - t4 );
+ im[s * 10] = ( t1 - t5 );
+ re[s * 14] = ( t2 + t6 );
+ im[s * 14] = ( t3 + t7 );
+
+ t0 = ( y06 + y22 );
+ t2 = ( y06 - y22 );
+ t1 = ( y07 + y23 );
+ t3 = ( y07 - y23 );
+ t4 = ( y14 + y30 );
+ t7 = ( y14 - y30 );
+ t5 = ( y31 + y15 );
+ t6 = ( y31 - y15 );
+
+ re[s * 3] = ( t0 + t4 );
+ im[s * 3] = ( t1 + t5 );
+ re[s * 7] = ( t2 - t6 );
+ im[s * 7] = ( t3 - t7 );
+ re[s * 11] = ( t0 - t4 );
+ im[s * 11] = ( t1 - t5 );
+ re[s * 15] = ( t2 + t6 );
+ im[s * 15] = ( t3 + t7 );
+
+ return;
+}
+
+static void fft_len20(
+ float *re,
+ float *im,
+ const int16_t s )
+{
+ float r1, r2, r3, r4;
+ float s1, s2, s3, s4;
+ float x0, x1, x2, x3, x4;
+ float t, t0, t1, t2, t3, t4, t5, t6, t7;
+ float y00, y01, y02, y03, y04, y05, y06, y07, y08, y09;
+ float y10, y11, y12, y13, y14, y15, y16, y17, y18, y19;
+ float y20, y21, y22, y23, y24, y25, y26, y27, y28, y29;
+ float y30, y31, y32, y33, y34, y35, y36, y37, y38, y39;
+
+ x0 = re[s * 0];
+ x1 = re[s * 16];
+ x2 = re[s * 12];
+ x3 = re[s * 8];
+ x4 = re[s * 4];
+
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x2 + x3 );
+ r2 = ( x2 - x3 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y00 = ( x0 + r1 );
+ r1 = ( y00 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ x0 = im[s * 0];
+ x1 = im[s * 16];
+ x2 = im[s * 12];
+ x3 = im[s * 8];
+ x4 = im[s * 4];
+
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x2 + x3 );
+ s2 = ( x2 - x3 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y01 = ( x0 + s1 );
+ s1 = ( y01 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y08 = ( r1 + s2 );
+ y32 = ( r1 - s2 );
+ y16 = ( r3 - s4 );
+ y24 = ( r3 + s4 );
+
+ y09 = ( s1 - r2 );
+ y33 = ( s1 + r2 );
+ y17 = ( s3 + r4 );
+ y25 = ( s3 - r4 );
+
+ x0 = re[s * 5];
+ x1 = re[s * 1];
+ x2 = re[s * 17];
+ x3 = re[s * 13];
+ x4 = re[s * 9];
+
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x2 + x3 );
+ r2 = ( x2 - x3 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y02 = ( x0 + r1 );
+ r1 = ( y02 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ x0 = im[s * 5];
+ x1 = im[s * 1];
+ x2 = im[s * 17];
+ x3 = im[s * 13];
+ x4 = im[s * 9];
+
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x2 + x3 );
+ s2 = ( x2 - x3 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y03 = ( x0 + s1 );
+ s1 = ( y03 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y10 = ( r1 + s2 );
+ y34 = ( r1 - s2 );
+ y18 = ( r3 - s4 );
+ y26 = ( r3 + s4 );
+
+ y11 = ( s1 - r2 );
+ y35 = ( s1 + r2 );
+ y19 = ( s3 + r4 );
+ y27 = ( s3 - r4 );
+
+ x0 = re[s * 10];
+ x1 = re[s * 6];
+ x2 = re[s * 2];
+ x3 = re[s * 18];
+ x4 = re[s * 14];
+
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x2 + x3 );
+ r2 = ( x2 - x3 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y04 = ( x0 + r1 );
+ r1 = ( y04 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ x0 = im[s * 10];
+ x1 = im[s * 6];
+ x2 = im[s * 2];
+ x3 = im[s * 18];
+ x4 = im[s * 14];
+
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x2 + x3 );
+ s2 = ( x2 - x3 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y05 = ( x0 + s1 );
+ s1 = ( y05 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y12 = ( r1 + s2 );
+ y36 = ( r1 - s2 );
+ y20 = ( r3 - s4 );
+ y28 = ( r3 + s4 );
+
+ y13 = ( s1 - r2 );
+ y37 = ( s1 + r2 );
+ y21 = ( s3 + r4 );
+ y29 = ( s3 - r4 );
+
+ x0 = re[s * 15];
+ x1 = re[s * 11];
+ x2 = re[s * 7];
+ x3 = re[s * 3];
+ x4 = re[s * 19];
+
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x2 + x3 );
+ r2 = ( x2 - x3 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y06 = ( x0 + r1 );
+ r1 = ( y06 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ x0 = im[s * 15];
+ x1 = im[s * 11];
+ x2 = im[s * 7];
+ x3 = im[s * 3];
+ x4 = im[s * 19];
+
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x2 + x3 );
+ s2 = ( x2 - x3 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y07 = ( x0 + s1 );
+ s1 = ( y07 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y14 = ( r1 + s2 );
+ y38 = ( r1 - s2 );
+ y22 = ( r3 - s4 );
+ y30 = ( r3 + s4 );
+
+ y15 = ( s1 - r2 );
+ y39 = ( s1 + r2 );
+ y23 = ( s3 + r4 );
+ y31 = ( s3 - r4 );
+
+ t0 = ( y00 + y04 );
+ t2 = ( y00 - y04 );
+ t1 = ( y01 + y05 );
+ t3 = ( y01 - y05 );
+ t4 = ( y02 + y06 );
+ t7 = ( y02 - y06 );
+ t5 = ( y07 + y03 );
+ t6 = ( y07 - y03 );
+
+ re[s * 0] = ( t0 + t4 );
+ im[s * 0] = ( t1 + t5 );
+ re[s * 5] = ( t2 - t6 );
+ im[s * 5] = ( t3 - t7 );
+ re[s * 10] = ( t0 - t4 );
+ im[s * 10] = ( t1 - t5 );
+ re[s * 15] = ( t2 + t6 );
+ im[s * 15] = ( t3 + t7 );
+
+ t0 = ( y08 + y12 );
+ t2 = ( y08 - y12 );
+ t1 = ( y09 + y13 );
+ t3 = ( y09 - y13 );
+ t4 = ( y10 + y14 );
+ t7 = ( y10 - y14 );
+ t5 = ( y15 + y11 );
+ t6 = ( y15 - y11 );
+
+ re[s * 4] = ( t0 + t4 );
+ im[s * 4] = ( t1 + t5 );
+ re[s * 9] = ( t2 - t6 );
+ im[s * 9] = ( t3 - t7 );
+ re[s * 14] = ( t0 - t4 );
+ im[s * 14] = ( t1 - t5 );
+ re[s * 19] = ( t2 + t6 );
+ im[s * 19] = ( t3 + t7 );
+
+ t0 = ( y16 + y20 );
+ t2 = ( y16 - y20 );
+ t1 = ( y17 + y21 );
+ t3 = ( y17 - y21 );
+ t4 = ( y18 + y22 );
+ t7 = ( y18 - y22 );
+ t5 = ( y23 + y19 );
+ t6 = ( y23 - y19 );
+
+ re[s * 8] = ( t0 + t4 );
+ im[s * 8] = ( t1 + t5 );
+ re[s * 13] = ( t2 - t6 );
+ im[s * 13] = ( t3 - t7 );
+ re[s * 18] = ( t0 - t4 );
+ im[s * 18] = ( t1 - t5 );
+ re[s * 3] = ( t2 + t6 );
+ im[s * 3] = ( t3 + t7 );
+
+ t0 = ( y24 + y28 );
+ t2 = ( y24 - y28 );
+ t1 = ( y25 + y29 );
+ t3 = ( y25 - y29 );
+ t4 = ( y26 + y30 );
+ t7 = ( y26 - y30 );
+ t5 = ( y31 + y27 );
+ t6 = ( y31 - y27 );
+
+ re[s * 12] = ( t0 + t4 );
+ im[s * 12] = ( t1 + t5 );
+ re[s * 17] = ( t2 - t6 );
+ im[s * 17] = ( t3 - t7 );
+ re[s * 2] = ( t0 - t4 );
+ im[s * 2] = ( t1 - t5 );
+ re[s * 7] = ( t2 + t6 );
+ im[s * 7] = ( t3 + t7 );
+
+ t0 = ( y32 + y36 );
+ t2 = ( y32 - y36 );
+ t1 = ( y33 + y37 );
+ t3 = ( y33 - y37 );
+ t4 = ( y34 + y38 );
+ t7 = ( y34 - y38 );
+ t5 = ( y39 + y35 );
+ t6 = ( y39 - y35 );
+
+ re[s * 16] = ( t0 + t4 );
+ im[s * 16] = ( t1 + t5 );
+ re[s * 1] = ( t2 - t6 );
+ im[s * 1] = ( t3 - t7 );
+ re[s * 6] = ( t0 - t4 );
+ im[s * 6] = ( t1 - t5 );
+ re[s * 11] = ( t2 + t6 );
+ im[s * 11] = ( t3 + t7 );
+
+ return;
+}
+
+static void fft_len30(
+ float *re,
+ float *im,
+ const int16_t s )
+{
+ float t;
+ float r1, r2, r3, r4;
+ float s1, s2, s3, s4;
+ float x00, x01, x02, x03, x04, x05, x06, x07, x08, x09;
+ float x10, x11, x12, x13, x14, x15, x16, x17, x18, x19;
+ float x20, x21, x22, x23, x24, x25, x26, x27, x28, x29;
+
+ float y00, y01, y02, y03, y04, y05, y06, y07, y08, y09;
+ float y10, y11, y12, y13, y14, y15, y16, y17, y18, y19;
+ float y20, y21, y22, y23, y24, y25, y26, y27, y28, y29;
+
+ float z00, z01, z02, z03, z04, z05, z06, z07, z08, z09;
+ float z10, z11, z12, z13, z14, z15, z16, z17, z18, z19;
+ float z20, z21, z22, z23, z24, z25, z26, z27, z28, z29;
+ float z30, z31, z32, z33, z34, z35, z36, z37, z38, z39;
+ float z40, z41, z42, z43, z44, z45, z46, z47, z48, z49;
+ float z50, z51, z52, z53, z54, z55, z56, z57, z58, z59;
+
+ float *rel, *reh, *iml, *imh;
+
+ rel = &re[s * 0];
+ reh = &re[s * 15];
+ iml = &im[s * 0];
+ imh = &im[s * 15];
+
+ x00 = re[s * 0];
+ x01 = im[s * 0];
+ x02 = re[s * 18];
+ x03 = im[s * 18];
+ x04 = re[s * 6];
+ x05 = im[s * 6];
+ x06 = re[s * 24];
+ x07 = im[s * 24];
+ x08 = re[s * 12];
+ x09 = im[s * 12];
+
+ x10 = re[s * 20];
+ x11 = im[s * 20];
+ x12 = re[s * 8];
+ x13 = im[s * 8];
+ x14 = re[s * 26];
+ x15 = im[s * 26];
+ x16 = re[s * 14];
+ x17 = im[s * 14];
+ x18 = re[s * 2];
+ x19 = im[s * 2];
+
+ x20 = re[s * 10];
+ x21 = im[s * 10];
+ x22 = re[s * 28];
+ x23 = im[s * 28];
+ x24 = re[s * 16];
+ x25 = im[s * 16];
+ x26 = re[s * 4];
+ x27 = im[s * 4];
+ x28 = re[s * 22];
+ x29 = im[s * 22];
+
+ r1 = ( x02 + x08 );
+ r4 = ( x02 - x08 );
+ r3 = ( x04 + x06 );
+ r2 = ( x04 - x06 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y00 = ( x00 + r1 );
+ r1 = ( y00 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x03 + x09 );
+ s4 = ( x03 - x09 );
+ s3 = ( x05 + x07 );
+ s2 = ( x05 - x07 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y01 = ( x01 + s1 );
+ s1 = ( y01 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y02 = ( r1 + s2 );
+ y08 = ( r1 - s2 );
+ y04 = ( r3 - s4 );
+ y06 = ( r3 + s4 );
+
+ y03 = ( s1 - r2 );
+ y09 = ( s1 + r2 );
+ y05 = ( s3 + r4 );
+ y07 = ( s3 - r4 );
+
+ r1 = ( x12 + x18 );
+ r4 = ( x12 - x18 );
+ r3 = ( x14 + x16 );
+ r2 = ( x14 - x16 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y10 = ( x10 + r1 );
+ r1 = ( y10 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x13 + x19 );
+ s4 = ( x13 - x19 );
+ s3 = ( x15 + x17 );
+ s2 = ( x15 - x17 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y11 = ( x11 + s1 );
+ s1 = ( y11 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y12 = ( r1 + s2 );
+ y18 = ( r1 - s2 );
+ y14 = ( r3 - s4 );
+ y16 = ( r3 + s4 );
+
+ y13 = ( s1 - r2 );
+ y19 = ( s1 + r2 );
+ y15 = ( s3 + r4 );
+ y17 = ( s3 - r4 );
+
+ r1 = ( x22 + x28 );
+ r4 = ( x22 - x28 );
+ r3 = ( x24 + x26 );
+ r2 = ( x24 - x26 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y20 = ( x20 + r1 );
+ r1 = ( y20 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x23 + x29 );
+ s4 = ( x23 - x29 );
+ s3 = ( x25 + x27 );
+ s2 = ( x25 - x27 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y21 = ( x21 + s1 );
+ s1 = ( y21 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y22 = ( r1 + s2 );
+ y28 = ( r1 - s2 );
+ y24 = ( r3 - s4 );
+ y26 = ( r3 + s4 );
+
+ y23 = ( s1 - r2 );
+ y29 = ( s1 + r2 );
+ y25 = ( s3 + r4 );
+ y27 = ( s3 - r4 );
+
+ r1 = ( y10 + y20 );
+ r2 = ( ( y10 - y20 ) * FFT_C31 );
+ z00 = ( y00 + r1 );
+ r1 = ( y00 - r1 * 0.5f );
+
+ s1 = ( y11 + y21 );
+ s2 = ( ( y11 - y21 ) * FFT_C31 );
+ z01 = ( y01 + s1 );
+ s1 = ( y01 - s1 * 0.5f );
+
+ z20 = ( r1 - s2 );
+ z10 = ( r1 + s2 );
+ z21 = ( s1 + r2 );
+ z11 = ( s1 - r2 );
+
+ r1 = ( y12 + y22 );
+ r2 = ( ( y12 - y22 ) * FFT_C31 );
+ z12 = ( y02 + r1 );
+ r1 = ( y02 - r1 * 0.5f );
+
+ s1 = ( y13 + y23 );
+ s2 = ( ( y13 - y23 ) * FFT_C31 );
+ z13 = ( y03 + s1 );
+ s1 = ( y03 - s1 * 0.5f );
+
+ z02 = ( r1 - s2 );
+ z22 = ( r1 + s2 );
+ z03 = ( s1 + r2 );
+ z23 = ( s1 - r2 );
+
+ r1 = ( y14 + y24 );
+ r2 = ( ( y14 - y24 ) * FFT_C31 );
+ z24 = ( y04 + r1 );
+ r1 = ( y04 - r1 * 0.5f );
+
+ s1 = ( y15 + y25 );
+ s2 = ( ( y15 - y25 ) * FFT_C31 );
+ z25 = ( y05 + s1 );
+ s1 = ( y05 - s1 * 0.5f );
+
+ z14 = ( r1 - s2 );
+ z04 = ( r1 + s2 );
+ z15 = ( s1 + r2 );
+ z05 = ( s1 - r2 );
+
+ r1 = ( y16 + y26 );
+ r2 = ( ( y16 - y26 ) * FFT_C31 );
+ z06 = ( y06 + r1 );
+ r1 = ( y06 - r1 * 0.5f );
+
+ s1 = ( y17 + y27 );
+ s2 = ( ( y17 - y27 ) * FFT_C31 );
+ z07 = ( y07 + s1 );
+ s1 = ( y07 - s1 * 0.5f );
+
+ z26 = ( r1 - s2 );
+ z16 = ( r1 + s2 );
+ z27 = ( s1 + r2 );
+ z17 = ( s1 - r2 );
+
+ r1 = ( y18 + y28 );
+ r2 = ( ( y18 - y28 ) * FFT_C31 );
+ z18 = ( y08 + r1 );
+ r1 = ( y08 - r1 * 0.5f );
+
+ s1 = ( y19 + y29 );
+ s2 = ( ( y19 - y29 ) * FFT_C31 );
+ z19 = ( y09 + s1 );
+ s1 = ( y09 - s1 * 0.5f );
+
+ z08 = ( r1 - s2 );
+ z28 = ( r1 + s2 );
+ z09 = ( s1 + r2 );
+ z29 = ( s1 - r2 );
+
+ x00 = re[s * 15];
+ x01 = im[s * 15];
+ x02 = re[s * 3];
+ x03 = im[s * 3];
+ x04 = re[s * 21];
+ x05 = im[s * 21];
+ x06 = re[s * 9];
+ x07 = im[s * 9];
+ x08 = re[s * 27];
+ x09 = im[s * 27];
+
+ x10 = re[s * 5];
+ x11 = im[s * 5];
+ x12 = re[s * 23];
+ x13 = im[s * 23];
+ x14 = re[s * 11];
+ x15 = im[s * 11];
+ x16 = re[s * 29];
+ x17 = im[s * 29];
+ x18 = re[s * 17];
+ x19 = im[s * 17];
+
+ x20 = re[s * 25];
+ x21 = im[s * 25];
+ x22 = re[s * 13];
+ x23 = im[s * 13];
+ x24 = re[s * 1];
+ x25 = im[s * 1];
+ x26 = re[s * 19];
+ x27 = im[s * 19];
+ x28 = re[s * 7];
+ x29 = im[s * 7];
+
+ r1 = ( x02 + x08 );
+ r4 = ( x02 - x08 );
+ r3 = ( x04 + x06 );
+ r2 = ( x04 - x06 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y00 = ( x00 + r1 );
+ r1 = ( y00 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x03 + x09 );
+ s4 = ( x03 - x09 );
+ s3 = ( x05 + x07 );
+ s2 = ( x05 - x07 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y01 = ( x01 + s1 );
+ s1 = ( y01 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y02 = ( r1 + s2 );
+ y08 = ( r1 - s2 );
+ y04 = ( r3 - s4 );
+ y06 = ( r3 + s4 );
+
+ y03 = ( s1 - r2 );
+ y09 = ( s1 + r2 );
+ y05 = ( s3 + r4 );
+ y07 = ( s3 - r4 );
+
+ r1 = ( x12 + x18 );
+ r4 = ( x12 - x18 );
+ r3 = ( x14 + x16 );
+ r2 = ( x14 - x16 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y10 = ( x10 + r1 );
+ r1 = ( y10 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x13 + x19 );
+ s4 = ( x13 - x19 );
+ s3 = ( x15 + x17 );
+ s2 = ( x15 - x17 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y11 = ( x11 + s1 );
+ s1 = ( y11 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y12 = ( r1 + s2 );
+ y18 = ( r1 - s2 );
+ y14 = ( r3 - s4 );
+ y16 = ( r3 + s4 );
+
+ y13 = ( s1 - r2 );
+ y19 = ( s1 + r2 );
+ y15 = ( s3 + r4 );
+ y17 = ( s3 - r4 );
+
+ r1 = ( x22 + x28 );
+ r4 = ( x22 - x28 );
+ r3 = ( x24 + x26 );
+ r2 = ( x24 - x26 );
+ t = ( ( r1 - r3 ) * FFT_C54 );
+ r1 = ( r1 + r3 );
+ y20 = ( x20 + r1 );
+ r1 = ( y20 + ( ( r1 * FFT_C55 ) ) );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( ( ( r4 + r2 ) ) * FFT_C51 );
+ r4 = ( t + ( r4 * FFT_C52 ) );
+ r2 = ( t + ( r2 * FFT_C53 ) );
+
+ s1 = ( x23 + x29 );
+ s4 = ( x23 - x29 );
+ s3 = ( x25 + x27 );
+ s2 = ( x25 - x27 );
+ t = ( ( s1 - s3 ) * FFT_C54 );
+ s1 = ( s1 + s3 );
+ y21 = ( x21 + s1 );
+ s1 = ( y21 + ( s1 * FFT_C55 ) );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( ( s4 + s2 ) * FFT_C51 );
+ s4 = ( t + ( s4 * FFT_C52 ) );
+ s2 = ( t + ( s2 * FFT_C53 ) );
+
+ y22 = ( r1 + s2 );
+ y28 = ( r1 - s2 );
+ y24 = ( r3 - s4 );
+ y26 = ( r3 + s4 );
+
+ y23 = ( s1 - r2 );
+ y29 = ( s1 + r2 );
+ y25 = ( s3 + r4 );
+ y27 = ( s3 - r4 );
+
+ r1 = ( y10 + y20 );
+ r2 = ( ( y10 - y20 ) * FFT_C31 );
+ z30 = ( y00 + r1 );
+ r1 = ( y00 - r1 * 0.5f );
+
+ s1 = ( y11 + y21 );
+ s2 = ( ( y11 - y21 ) * FFT_C31 );
+ z31 = ( y01 + s1 );
+ s1 = ( y01 - s1 * 0.5f );
+
+ z50 = ( r1 - s2 );
+ z40 = ( r1 + s2 );
+ z51 = ( s1 + r2 );
+ z41 = ( s1 - r2 );
+
+ r1 = ( y12 + y22 );
+ r2 = ( ( y12 - y22 ) * FFT_C31 );
+ z42 = ( y02 + r1 );
+ r1 = ( y02 - r1 * 0.5f );
+
+ s1 = ( y13 + y23 );
+ s2 = ( ( y13 - y23 ) * FFT_C31 );
+ z43 = ( y03 + s1 );
+ s1 = ( y03 - s1 * 0.5f );
+
+ z32 = ( r1 - s2 );
+ z52 = ( r1 + s2 );
+ z33 = ( s1 + r2 );
+ z53 = ( s1 - r2 );
+
+ r1 = ( y14 + y24 );
+ r2 = ( ( y14 - y24 ) * FFT_C31 );
+ z54 = ( y04 + r1 );
+ r1 = ( y04 - r1 * 0.5f );
+
+ s1 = ( y15 + y25 );
+ s2 = ( ( y15 - y25 ) * FFT_C31 );
+ z55 = ( y05 + s1 );
+ s1 = ( y05 - s1 * 0.5f );
+
+ z44 = ( r1 - s2 );
+ z34 = ( r1 + s2 );
+ z45 = ( s1 + r2 );
+ z35 = ( s1 - r2 );
+
+ r1 = ( y16 + y26 );
+ r2 = ( ( y16 - y26 ) * FFT_C31 );
+ z36 = ( y06 + r1 );
+ r1 = ( y06 - r1 * 0.5f );
+
+ s1 = ( y17 + y27 );
+ s2 = ( ( y17 - y27 ) * FFT_C31 );
+ z37 = ( y07 + s1 );
+ s1 = ( y07 - s1 * 0.5f );
+
+ z56 = ( r1 - s2 );
+ z46 = ( r1 + s2 );
+ z57 = ( s1 + r2 );
+ z47 = ( s1 - r2 );
+
+ r1 = ( y18 + y28 );
+ r2 = ( ( y18 - y28 ) * FFT_C31 );
+ z48 = ( y08 + r1 );
+ r1 = ( y08 - r1 * 0.5f );
+
+ s1 = ( y19 + y29 );
+ s2 = ( ( y19 - y29 ) * FFT_C31 );
+ z49 = ( y09 + s1 );
+ s1 = ( y09 - s1 * 0.5f );
+
+ z38 = ( r1 - s2 );
+ z58 = ( r1 + s2 );
+ z39 = ( s1 + r2 );
+ z59 = ( s1 - r2 );
+
+ r1 = z00;
+ r2 = z30;
+ r3 = z01;
+ r4 = z31;
+ *rel = ( r1 + r2 );
+ *reh = ( r1 - r2 );
+ *iml = ( r3 + r4 );
+ *imh = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z16;
+ r2 = z46;
+ r3 = z17;
+ r4 = z47;
+ *reh = ( r1 + r2 );
+ *rel = ( r1 - r2 );
+ *imh = ( r3 + r4 );
+ *iml = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z02;
+ r2 = z32;
+ r3 = z03;
+ r4 = z33;
+ *rel = ( r1 + r2 );
+ *reh = ( r1 - r2 );
+ *iml = ( r3 + r4 );
+ *imh = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z18;
+ r2 = z48;
+ r3 = z19;
+ r4 = z49;
+ *reh = ( r1 + r2 );
+ *rel = ( r1 - r2 );
+ *imh = ( r3 + r4 );
+ *iml = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z04;
+ r2 = z34;
+ r3 = z05;
+ r4 = z35;
+ *rel = ( r1 + r2 );
+ *reh = ( r1 - r2 );
+ *iml = ( r3 + r4 );
+ *imh = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z20;
+ r2 = z50;
+ r3 = z21;
+ r4 = z51;
+ *reh = ( r1 + r2 );
+ *rel = ( r1 - r2 );
+ *imh = ( r3 + r4 );
+ *iml = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z06;
+ r2 = z36;
+ r3 = z07;
+ r4 = z37;
+ *rel = ( r1 + r2 );
+ *reh = ( r1 - r2 );
+ *iml = ( r3 + r4 );
+ *imh = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z22;
+ r2 = z52;
+ r3 = z23;
+ r4 = z53;
+ *reh = ( r1 + r2 );
+ *rel = ( r1 - r2 );
+ *imh = ( r3 + r4 );
+ *iml = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z08;
+ r2 = z38;
+ r3 = z09;
+ r4 = z39;
+ *rel = ( r1 + r2 );
+ *reh = ( r1 - r2 );
+ *iml = ( r3 + r4 );
+ *imh = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z24;
+ r2 = z54;
+ r3 = z25;
+ r4 = z55;
+ *reh = ( r1 + r2 );
+ *rel = ( r1 - r2 );
+ *imh = ( r3 + r4 );
+ *iml = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z10;
+ r2 = z40;
+ r3 = z11;
+ r4 = z41;
+ *rel = ( r1 + r2 );
+ *reh = ( r1 - r2 );
+ *iml = ( r3 + r4 );
+ *imh = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z26;
+ r2 = z56;
+ r3 = z27;
+ r4 = z57;
+ *reh = ( r1 + r2 );
+ *rel = ( r1 - r2 );
+ *imh = ( r3 + r4 );
+ *iml = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z12;
+ r2 = z42;
+ r3 = z13;
+ r4 = z43;
+ *rel = ( r1 + r2 );
+ *reh = ( r1 - r2 );
+ *iml = ( r3 + r4 );
+ *imh = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z28;
+ r2 = z58;
+ r3 = z29;
+ r4 = z59;
+ *reh = ( r1 + r2 );
+ *rel = ( r1 - r2 );
+ *imh = ( r3 + r4 );
+ *iml = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ r1 = z14;
+ r2 = z44;
+ r3 = z15;
+ r4 = z45;
+ *rel = ( r1 + r2 );
+ *reh = ( r1 - r2 );
+ *iml = ( r3 + r4 );
+ *imh = ( r3 - r4 );
+ rel += s, reh += s, iml += s;
+ imh += s;
+
+ return;
+}
+
+static void fft_len32(
+ float *re,
+ float *im,
+ const int16_t s )
+{
+ float as, bs;
+ float x00, x01, x02, x03, x04, x05, x06, x07;
+ float x08, x09, x10, x11, x12, x13, x14, x15;
+ float t00, t01, t02, t03, t04, t05, t06, t07;
+ float t08, t09, t10, t11, t12, t13, t14, t15;
+ float s00, s01, s02, s03, s04, s05, s06, s07;
+ float s08, s09, s10, s11, s12, s13, s14, s15;
+
+ float y00, y01, y02, y03, y04, y05, y06, y07;
+ float y08, y09, y10, y11, y12, y13, y14, y15;
+ float y16, y17, y18, y19, y20, y21, y22, y23;
+ float y24, y25, y26, y27, y28, y29, y30, y31;
+ float y32, y33, y34, y35, y36, y37, y38, y39;
+ float y40, y41, y42, y43, y44, y45, y46, y47;
+ float y48, y49, y50, y51, y52, y53, y54, y55;
+ float y56, y57, y58, y59, y60, y61, y62, y63;
+
+ x00 = re[s * 0];
+ x01 = im[s * 0];
+ x02 = re[s * 4];
+ x03 = im[s * 4];
+ x04 = re[s * 8];
+ x05 = im[s * 8];
+ x06 = re[s * 12];
+ x07 = im[s * 12];
+ x08 = re[s * 16];
+ x09 = im[s * 16];
+ x10 = re[s * 20];
+ x11 = im[s * 20];
+ x12 = re[s * 24];
+ x13 = im[s * 24];
+ x14 = re[s * 28];
+ x15 = im[s * 28];
+
+ t00 = ( x00 + x08 );
+ t02 = ( x00 - x08 );
+ t01 = ( x01 + x09 );
+ t03 = ( x01 - x09 );
+ t04 = ( x02 + x10 );
+ t06 = ( x02 - x10 );
+ t05 = ( x03 + x11 );
+ t07 = ( x03 - x11 );
+ t08 = ( x04 + x12 );
+ t10 = ( x04 - x12 );
+ t09 = ( x05 + x13 );
+ t11 = ( x05 - x13 );
+ t12 = ( x06 + x14 );
+ t14 = ( x06 - x14 );
+ t13 = ( x07 + x15 );
+ t15 = ( x07 - x15 );
+
+ s00 = ( t00 + t08 );
+ s04 = ( t00 - t08 );
+ s01 = ( t01 + t09 );
+ s05 = ( t01 - t09 );
+ s08 = ( t02 - t11 );
+ s10 = ( t02 + t11 );
+ s09 = ( t03 + t10 );
+ s11 = ( t03 - t10 );
+ s02 = ( t04 + t12 );
+ s07 = ( t04 - t12 );
+ s03 = ( t05 + t13 );
+ s06 = ( t13 - t05 );
+ t01 = ( t06 + t14 );
+ t02 = ( t06 - t14 );
+ t00 = ( t07 + t15 );
+ t03 = ( t07 - t15 );
+
+ {
+ s12 = ( ( t00 + t02 ) * FFT_C81 );
+ s14 = ( ( t00 - t02 ) * FFT_C81 );
+ s13 = ( ( t03 - t01 ) * FFT_C81 );
+ s15 = ( ( t01 + t03 ) * FFT_C82 );
+ };
+
+ y00 = ( s00 + s02 );
+ y08 = ( s00 - s02 );
+ y01 = ( s01 + s03 );
+ y09 = ( s01 - s03 );
+ y04 = ( s04 - s06 );
+ y12 = ( s04 + s06 );
+ y05 = ( s05 - s07 );
+ y13 = ( s05 + s07 );
+ y06 = ( s08 + s14 );
+ y14 = ( s08 - s14 );
+ y07 = ( s09 + s15 );
+ y15 = ( s09 - s15 );
+ y02 = ( s10 + s12 );
+ y10 = ( s10 - s12 );
+ y03 = ( s11 + s13 );
+ y11 = ( s11 - s13 );
+
+ x00 = re[s * 1];
+ x01 = im[s * 1];
+ x02 = re[s * 5];
+ x03 = im[s * 5];
+ x04 = re[s * 9];
+ x05 = im[s * 9];
+ x06 = re[s * 13];
+ x07 = im[s * 13];
+ x08 = re[s * 17];
+ x09 = im[s * 17];
+ x10 = re[s * 21];
+ x11 = im[s * 21];
+ x12 = re[s * 25];
+ x13 = im[s * 25];
+ x14 = re[s * 29];
+ x15 = im[s * 29];
+
+ t00 = ( x00 + x08 );
+ t02 = ( x00 - x08 );
+ t01 = ( x01 + x09 );
+ t03 = ( x01 - x09 );
+ t04 = ( x02 + x10 );
+ t06 = ( x02 - x10 );
+ t05 = ( x03 + x11 );
+ t07 = ( x03 - x11 );
+ t08 = ( x04 + x12 );
+ t10 = ( x04 - x12 );
+ t09 = ( x05 + x13 );
+ t11 = ( x05 - x13 );
+ t12 = ( x06 + x14 );
+ t14 = ( x06 - x14 );
+ t13 = ( x07 + x15 );
+ t15 = ( x07 - x15 );
+
+ s00 = ( t00 + t08 );
+ s04 = ( t00 - t08 );
+ s01 = ( t01 + t09 );
+ s05 = ( t01 - t09 );
+ s08 = ( t02 - t11 );
+ s10 = ( t02 + t11 );
+ s09 = ( t03 + t10 );
+ s11 = ( t03 - t10 );
+ s02 = ( t04 + t12 );
+ s07 = ( t04 - t12 );
+ s03 = ( t05 + t13 );
+ s06 = ( t13 - t05 );
+ t01 = ( t06 + t14 );
+ t02 = ( t06 - t14 );
+ t00 = ( t07 + t15 );
+ t03 = ( t07 - t15 );
+
+ {
+ s12 = ( ( t00 + t02 ) * FFT_C81 );
+ s14 = ( ( t00 - t02 ) * FFT_C81 );
+ s13 = ( ( t03 - t01 ) * FFT_C81 );
+ s15 = ( ( t01 + t03 ) * FFT_C82 );
+ };
+
+ y16 = ( s00 + s02 );
+ y24 = ( s00 - s02 );
+ y17 = ( s01 + s03 );
+ y25 = ( s01 - s03 );
+ y20 = ( s04 - s06 );
+ y28 = ( s04 + s06 );
+ y21 = ( s05 - s07 );
+ y29 = ( s05 + s07 );
+ y22 = ( s08 + s14 );
+ y30 = ( s08 - s14 );
+ y23 = ( s09 + s15 );
+ y31 = ( s09 - s15 );
+ y18 = ( s10 + s12 );
+ y26 = ( s10 - s12 );
+ y19 = ( s11 + s13 );
+ y27 = ( s11 - s13 );
+
+ x00 = re[s * 2];
+ x01 = im[s * 2];
+ x02 = re[s * 6];
+ x03 = im[s * 6];
+ x04 = re[s * 10];
+ x05 = im[s * 10];
+ x06 = re[s * 14];
+ x07 = im[s * 14];
+ x08 = re[s * 18];
+ x09 = im[s * 18];
+ x10 = re[s * 22];
+ x11 = im[s * 22];
+ x12 = re[s * 26];
+ x13 = im[s * 26];
+ x14 = re[s * 30];
+ x15 = im[s * 30];
+
+ t00 = ( x00 + x08 );
+ t02 = ( x00 - x08 );
+ t01 = ( x01 + x09 );
+ t03 = ( x01 - x09 );
+ t04 = ( x02 + x10 );
+ t06 = ( x02 - x10 );
+ t05 = ( x03 + x11 );
+ t07 = ( x03 - x11 );
+ t08 = ( x04 + x12 );
+ t10 = ( x04 - x12 );
+ t09 = ( x05 + x13 );
+ t11 = ( x05 - x13 );
+ t12 = ( x06 + x14 );
+ t14 = ( x06 - x14 );
+ t13 = ( x07 + x15 );
+ t15 = ( x07 - x15 );
+
+ s00 = ( t00 + t08 );
+ s04 = ( t00 - t08 );
+ s01 = ( t01 + t09 );
+ s05 = ( t01 - t09 );
+ s08 = ( t02 - t11 );
+ s10 = ( t02 + t11 );
+ s09 = ( t03 + t10 );
+ s11 = ( t03 - t10 );
+ s02 = ( t04 + t12 );
+ s07 = ( t04 - t12 );
+ s03 = ( t05 + t13 );
+ s06 = ( t13 - t05 );
+ t01 = ( t06 + t14 );
+ t02 = ( t06 - t14 );
+ t00 = ( t07 + t15 );
+ t03 = ( t07 - t15 );
+
+ {
+ s12 = ( ( t00 + t02 ) * FFT_C81 );
+ s14 = ( ( t00 - t02 ) * FFT_C81 );
+ s13 = ( ( t03 - t01 ) * FFT_C81 );
+ s15 = ( ( t01 + t03 ) * FFT_C82 );
+ };
+
+ y32 = ( s00 + s02 );
+ y40 = ( s00 - s02 );
+ y33 = ( s01 + s03 );
+ y41 = ( s01 - s03 );
+ y36 = ( s04 - s06 );
+ y44 = ( s04 + s06 );
+ y37 = ( s05 - s07 );
+ y45 = ( s05 + s07 );
+ y38 = ( s08 + s14 );
+ y46 = ( s08 - s14 );
+ y39 = ( s09 + s15 );
+ y47 = ( s09 - s15 );
+ y34 = ( s10 + s12 );
+ y42 = ( s10 - s12 );
+ y35 = ( s11 + s13 );
+ y43 = ( s11 - s13 );
+
+ x00 = re[s * 3];
+ x01 = im[s * 3];
+ x02 = re[s * 7];
+ x03 = im[s * 7];
+ x04 = re[s * 11];
+ x05 = im[s * 11];
+ x06 = re[s * 15];
+ x07 = im[s * 15];
+ x08 = re[s * 19];
+ x09 = im[s * 19];
+ x10 = re[s * 23];
+ x11 = im[s * 23];
+ x12 = re[s * 27];
+ x13 = im[s * 27];
+ x14 = re[s * 31];
+ x15 = im[s * 31];
+
+ t00 = ( x00 + x08 );
+ t02 = ( x00 - x08 );
+ t01 = ( x01 + x09 );
+ t03 = ( x01 - x09 );
+ t04 = ( x02 + x10 );
+ t06 = ( x02 - x10 );
+ t05 = ( x03 + x11 );
+ t07 = ( x03 - x11 );
+ t08 = ( x04 + x12 );
+ t10 = ( x04 - x12 );
+ t09 = ( x05 + x13 );
+ t11 = ( x05 - x13 );
+ t12 = ( x06 + x14 );
+ t14 = ( x06 - x14 );
+ t13 = ( x07 + x15 );
+ t15 = ( x07 - x15 );
+
+ s00 = ( t00 + t08 );
+ s04 = ( t00 - t08 );
+ s01 = ( t01 + t09 );
+ s05 = ( t01 - t09 );
+ s08 = ( t02 - t11 );
+ s10 = ( t02 + t11 );
+ s09 = ( t03 + t10 );
+ s11 = ( t03 - t10 );
+ s02 = ( t04 + t12 );
+ s07 = ( t04 - t12 );
+ s03 = ( t05 + t13 );
+ s06 = ( t13 - t05 );
+ t01 = ( t06 + t14 );
+ t02 = ( t06 - t14 );
+ t00 = ( t07 + t15 );
+ t03 = ( t07 - t15 );
+
+ {
+ s12 = ( ( t00 + t02 ) * FFT_C81 );
+ s14 = ( ( t00 - t02 ) * FFT_C81 );
+ s13 = ( ( t03 - t01 ) * FFT_C81 );
+ s15 = ( ( t01 + t03 ) * FFT_C82 );
+ };
+
+ y48 = ( s00 + s02 );
+ y56 = ( s00 - s02 );
+ y49 = ( s01 + s03 );
+ y57 = ( s01 - s03 );
+ y52 = ( s04 - s06 );
+ y60 = ( s04 + s06 );
+ y53 = ( s05 - s07 );
+ y61 = ( s05 + s07 );
+ y54 = ( s08 + s14 );
+ y62 = ( s08 - s14 );
+ y55 = ( s09 + s15 );
+ y63 = ( s09 - s15 );
+ y50 = ( s10 + s12 );
+ y58 = ( s10 - s12 );
+ y51 = ( s11 + s13 );
+ y59 = ( s11 - s13 );
+
+
+ {
+ as = y18;
+ bs = y19;
+ y18 = ( ( as * FFT_RotVector_32[2 * 0 + 0] ) - ( bs * FFT_RotVector_32[2 * 0 + 1] ) );
+ y19 = ( ( as * FFT_RotVector_32[2 * 0 + 1] ) + ( bs * FFT_RotVector_32[2 * 0 + 0] ) );
+ };
+ {
+ as = y20;
+ bs = y21;
+ y20 = ( ( as * FFT_RotVector_32[2 * 1 + 0] ) - ( bs * FFT_RotVector_32[2 * 1 + 1] ) );
+ y21 = ( ( as * FFT_RotVector_32[2 * 1 + 1] ) + ( bs * FFT_RotVector_32[2 * 1 + 0] ) );
+ };
+ {
+ as = y22;
+ bs = y23;
+ y22 = ( ( as * FFT_RotVector_32[2 * 2 + 0] ) - ( bs * FFT_RotVector_32[2 * 2 + 1] ) );
+ y23 = ( ( as * FFT_RotVector_32[2 * 2 + 1] ) + ( bs * FFT_RotVector_32[2 * 2 + 0] ) );
+ };
+ {
+ as = y24;
+ bs = y25;
+ y24 = ( ( as * FFT_RotVector_32[2 * 3 + 0] ) - ( bs * FFT_RotVector_32[2 * 3 + 1] ) );
+ y25 = ( ( as * FFT_RotVector_32[2 * 3 + 1] ) + ( bs * FFT_RotVector_32[2 * 3 + 0] ) );
+ };
+ {
+ as = y26;
+ bs = y27;
+ y26 = ( ( as * FFT_RotVector_32[2 * 4 + 0] ) - ( bs * FFT_RotVector_32[2 * 4 + 1] ) );
+ y27 = ( ( as * FFT_RotVector_32[2 * 4 + 1] ) + ( bs * FFT_RotVector_32[2 * 4 + 0] ) );
+ };
+ {
+ as = y28;
+ bs = y29;
+ y28 = ( ( as * FFT_RotVector_32[2 * 5 + 0] ) - ( bs * FFT_RotVector_32[2 * 5 + 1] ) );
+ y29 = ( ( as * FFT_RotVector_32[2 * 5 + 1] ) + ( bs * FFT_RotVector_32[2 * 5 + 0] ) );
+ };
+ {
+ as = y30;
+ bs = y31;
+ y30 = ( ( as * FFT_RotVector_32[2 * 6 + 0] ) - ( bs * FFT_RotVector_32[2 * 6 + 1] ) );
+ y31 = ( ( as * FFT_RotVector_32[2 * 6 + 1] ) + ( bs * FFT_RotVector_32[2 * 6 + 0] ) );
+ };
+ {
+ as = y34;
+ bs = y35;
+ y34 = ( ( as * FFT_RotVector_32[2 * 7 + 0] ) - ( bs * FFT_RotVector_32[2 * 7 + 1] ) );
+ y35 = ( ( as * FFT_RotVector_32[2 * 7 + 1] ) + ( bs * FFT_RotVector_32[2 * 7 + 0] ) );
+ };
+ {
+ as = y36;
+ bs = y37;
+ y36 = ( ( as * FFT_RotVector_32[2 * 8 + 0] ) - ( bs * FFT_RotVector_32[2 * 8 + 1] ) );
+ y37 = ( ( as * FFT_RotVector_32[2 * 8 + 1] ) + ( bs * FFT_RotVector_32[2 * 8 + 0] ) );
+ };
+ {
+ as = y38;
+ bs = y39;
+ y38 = ( ( as * FFT_RotVector_32[2 * 9 + 0] ) - ( bs * FFT_RotVector_32[2 * 9 + 1] ) );
+ y39 = ( ( as * FFT_RotVector_32[2 * 9 + 1] ) + ( bs * FFT_RotVector_32[2 * 9 + 0] ) );
+ };
+ {
+ as = y42;
+ bs = y43;
+ y42 = ( ( as * FFT_RotVector_32[2 * 10 + 0] ) - ( bs * FFT_RotVector_32[2 * 10 + 1] ) );
+ y43 = ( ( as * FFT_RotVector_32[2 * 10 + 1] ) + ( bs * FFT_RotVector_32[2 * 10 + 0] ) );
+ };
+ {
+ as = y44;
+ bs = y45;
+ y44 = ( ( as * FFT_RotVector_32[2 * 11 + 0] ) - ( bs * FFT_RotVector_32[2 * 11 + 1] ) );
+ y45 = ( ( as * FFT_RotVector_32[2 * 11 + 1] ) + ( bs * FFT_RotVector_32[2 * 11 + 0] ) );
+ };
+ {
+ as = y46;
+ bs = y47;
+ y46 = ( ( as * FFT_RotVector_32[2 * 12 + 0] ) - ( bs * FFT_RotVector_32[2 * 12 + 1] ) );
+ y47 = ( ( as * FFT_RotVector_32[2 * 12 + 1] ) + ( bs * FFT_RotVector_32[2 * 12 + 0] ) );
+ };
+ {
+ as = y50;
+ bs = y51;
+ y50 = ( ( as * FFT_RotVector_32[2 * 13 + 0] ) - ( bs * FFT_RotVector_32[2 * 13 + 1] ) );
+ y51 = ( ( as * FFT_RotVector_32[2 * 13 + 1] ) + ( bs * FFT_RotVector_32[2 * 13 + 0] ) );
+ };
+ {
+ as = y52;
+ bs = y53;
+ y52 = ( ( as * FFT_RotVector_32[2 * 14 + 0] ) - ( bs * FFT_RotVector_32[2 * 14 + 1] ) );
+ y53 = ( ( as * FFT_RotVector_32[2 * 14 + 1] ) + ( bs * FFT_RotVector_32[2 * 14 + 0] ) );
+ };
+ {
+ as = y54;
+ bs = y55;
+ y54 = ( ( as * FFT_RotVector_32[2 * 15 + 0] ) - ( bs * FFT_RotVector_32[2 * 15 + 1] ) );
+ y55 = ( ( as * FFT_RotVector_32[2 * 15 + 1] ) + ( bs * FFT_RotVector_32[2 * 15 + 0] ) );
+ };
+ {
+ as = y56;
+ bs = y57;
+ y56 = ( ( as * FFT_RotVector_32[2 * 16 + 0] ) - ( bs * FFT_RotVector_32[2 * 16 + 1] ) );
+ y57 = ( ( as * FFT_RotVector_32[2 * 16 + 1] ) + ( bs * FFT_RotVector_32[2 * 16 + 0] ) );
+ };
+ {
+ as = y58;
+ bs = y59;
+ y58 = ( ( as * FFT_RotVector_32[2 * 17 + 0] ) - ( bs * FFT_RotVector_32[2 * 17 + 1] ) );
+ y59 = ( ( as * FFT_RotVector_32[2 * 17 + 1] ) + ( bs * FFT_RotVector_32[2 * 17 + 0] ) );
+ };
+ {
+ as = y60;
+ bs = y61;
+ y60 = ( ( as * FFT_RotVector_32[2 * 18 + 0] ) - ( bs * FFT_RotVector_32[2 * 18 + 1] ) );
+ y61 = ( ( as * FFT_RotVector_32[2 * 18 + 1] ) + ( bs * FFT_RotVector_32[2 * 18 + 0] ) );
+ };
+ {
+ as = y62;
+ bs = y63;
+ y62 = ( ( as * FFT_RotVector_32[2 * 19 + 0] ) - ( bs * FFT_RotVector_32[2 * 19 + 1] ) );
+ y63 = ( ( as * FFT_RotVector_32[2 * 19 + 1] ) + ( bs * FFT_RotVector_32[2 * 19 + 0] ) );
+ };
+
+ t00 = ( y00 + y32 );
+ t02 = ( y00 - y32 );
+ t01 = ( y01 + y33 );
+ t03 = ( y01 - y33 );
+ t04 = ( y16 + y48 );
+ t07 = ( y16 - y48 );
+ t05 = ( y49 + y17 );
+ t06 = ( y49 - y17 );
+
+ re[s * 0] = ( t00 + t04 );
+ im[s * 0] = ( t01 + t05 );
+ re[s * 8] = ( t02 - t06 );
+ im[s * 8] = ( t03 - t07 );
+ re[s * 16] = ( t00 - t04 );
+ im[s * 16] = ( t01 - t05 );
+ re[s * 24] = ( t02 + t06 );
+ im[s * 24] = ( t03 + t07 );
+
+ t00 = ( y02 + y34 );
+ t02 = ( y02 - y34 );
+ t01 = ( y03 + y35 );
+ t03 = ( y03 - y35 );
+ t04 = ( y18 + y50 );
+ t07 = ( y18 - y50 );
+ t05 = ( y51 + y19 );
+ t06 = ( y51 - y19 );
+
+ re[s * 1] = ( t00 + t04 );
+ im[s * 1] = ( t01 + t05 );
+ re[s * 9] = ( t02 - t06 );
+ im[s * 9] = ( t03 - t07 );
+ re[s * 17] = ( t00 - t04 );
+ im[s * 17] = ( t01 - t05 );
+ re[s * 25] = ( t02 + t06 );
+ im[s * 25] = ( t03 + t07 );
+
+ t00 = ( y04 + y36 );
+ t02 = ( y04 - y36 );
+ t01 = ( y05 + y37 );
+ t03 = ( y05 - y37 );
+ t04 = ( y20 + y52 );
+ t07 = ( y20 - y52 );
+ t05 = ( y53 + y21 );
+ t06 = ( y53 - y21 );
+
+ re[s * 2] = ( t00 + t04 );
+ im[s * 2] = ( t01 + t05 );
+ re[s * 10] = ( t02 - t06 );
+ im[s * 10] = ( t03 - t07 );
+ re[s * 18] = ( t00 - t04 );
+ im[s * 18] = ( t01 - t05 );
+ re[s * 26] = ( t02 + t06 );
+ im[s * 26] = ( t03 + t07 );
+
+ t00 = ( y06 + y38 );
+ t02 = ( y06 - y38 );
+ t01 = ( y07 + y39 );
+ t03 = ( y07 - y39 );
+ t04 = ( y22 + y54 );
+ t07 = ( y22 - y54 );
+ t05 = ( y55 + y23 );
+ t06 = ( y55 - y23 );
+
+ re[s * 3] = ( t00 + t04 );
+ im[s * 3] = ( t01 + t05 );
+ re[s * 11] = ( t02 - t06 );
+ im[s * 11] = ( t03 - t07 );
+ re[s * 19] = ( t00 - t04 );
+ im[s * 19] = ( t01 - t05 );
+ re[s * 27] = ( t02 + t06 );
+ im[s * 27] = ( t03 + t07 );
+
+ t00 = ( y08 + y41 );
+ t02 = ( y08 - y41 );
+ t01 = ( y09 - y40 );
+ t03 = ( y09 + y40 );
+ t04 = ( y24 + y56 );
+ t07 = ( y24 - y56 );
+ t05 = ( y57 + y25 );
+ t06 = ( y57 - y25 );
+
+ re[s * 4] = ( t00 + t04 );
+ im[s * 4] = ( t01 + t05 );
+ re[s * 12] = ( t02 - t06 );
+ im[s * 12] = ( t03 - t07 );
+ re[s * 20] = ( t00 - t04 );
+ im[s * 20] = ( t01 - t05 );
+ re[s * 28] = ( t02 + t06 );
+ im[s * 28] = ( t03 + t07 );
+
+ t00 = ( y10 + y42 );
+ t02 = ( y10 - y42 );
+ t01 = ( y11 + y43 );
+ t03 = ( y11 - y43 );
+ t04 = ( y26 + y58 );
+ t07 = ( y26 - y58 );
+ t05 = ( y59 + y27 );
+ t06 = ( y59 - y27 );
+
+ re[s * 5] = ( t00 + t04 );
+ im[s * 5] = ( t01 + t05 );
+ re[s * 13] = ( t02 - t06 );
+ im[s * 13] = ( t03 - t07 );
+ re[s * 21] = ( t00 - t04 );
+ im[s * 21] = ( t01 - t05 );
+ re[s * 29] = ( t02 + t06 );
+ im[s * 29] = ( t03 + t07 );
+
+ t00 = ( y12 + y44 );
+ t02 = ( y12 - y44 );
+ t01 = ( y13 + y45 );
+ t03 = ( y13 - y45 );
+ t04 = ( y28 + y60 );
+ t07 = ( y28 - y60 );
+ t05 = ( y61 + y29 );
+ t06 = ( y61 - y29 );
+
+ re[s * 6] = ( t00 + t04 );
+ im[s * 6] = ( t01 + t05 );
+ re[s * 14] = ( t02 - t06 );
+ im[s * 14] = ( t03 - t07 );
+ re[s * 22] = ( t00 - t04 );
+ im[s * 22] = ( t01 - t05 );
+ re[s * 30] = ( t02 + t06 );
+ im[s * 30] = ( t03 + t07 );
+
+ t00 = ( y14 + y46 );
+ t02 = ( y14 - y46 );
+ t01 = ( y15 + y47 );
+ t03 = ( y15 - y47 );
+ t04 = ( y30 + y62 );
+ t07 = ( y30 - y62 );
+ t05 = ( y63 + y31 );
+ t06 = ( y63 - y31 );
+
+ re[s * 7] = ( t00 + t04 );
+ im[s * 7] = ( t01 + t05 );
+ re[s * 15] = ( t02 - t06 );
+ im[s * 15] = ( t03 - t07 );
+ re[s * 23] = ( t00 - t04 );
+ im[s * 23] = ( t01 - t05 );
+ re[s * 31] = ( t02 + t06 );
+ im[s * 31] = ( t03 + t07 );
+
+ return;
+}
+
+static void fft_lenN(
+ float *re,
+ float *im,
+ const float *W,
+ const int16_t len,
+ const int16_t dim1,
+ const int16_t dim2,
+ const int16_t sx,
+ const int16_t sc,
+ const int16_t Woff )
+{
+ int16_t i, j;
+ float x[L_FRAME_MAX * 2];
+
+ for ( i = 0; i < dim2; i++ )
+ {
+ for ( j = 0; j < dim1; j++ )
+ {
+ x[2 * i * dim1 + 2 * j] = re[sx * i + sx * j * dim2];
+ x[2 * i * dim1 + 2 * j + 1] = im[sx * i + sx * j * dim2];
+ }
+ }
+
+ switch ( dim1 )
+ {
+ case 5:
+ for ( i = 0; i < dim2; i++ )
+ {
+ fft_len5( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+ break;
+
+ case 8:
+ for ( i = 0; i < dim2; i++ )
+ {
+ fft_len8( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+ break;
+
+ case 10:
+ for ( i = 0; i < dim2; i++ )
+ {
+ fft_len10( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+ break;
+
+ case 15:
+ for ( i = 0; i < dim2; i++ )
+ {
+ fft_len15( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+ break;
+
+ case 16:
+ for ( i = 0; i < dim2; i++ )
+ {
+ fft_len16( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+ break;
+
+ case 20:
+ for ( i = 0; i < dim2; i++ )
+ {
+ fft_len20( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+ break;
+
+ case 30:
+ for ( i = 0; i < dim2; i++ )
+ {
+ fft_len30( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+ break;
+
+ case 32:
+ for ( i = 0; i < dim2; i++ )
+ {
+ fft_len32( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+ break;
+ }
+
+ switch ( dim2 )
+ {
+
+ case 8:
+ {
+ float x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, x11, x12, x13, x14, x15;
+ float t00, t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15;
+ float s00, s01, s02, s03, s04, s05, s06, s07, s08, s09, s10, s11, s12, s13, s14, s15;
+
+ if ( dim1 == 30 || dim1 == 20 || dim1 == 15 || dim1 == 10 || dim1 == 5 )
+ {
+ for ( i = 0; i < dim1; i++ )
+ {
+ {
+ x00 = x[2 * i + 2 * 0 * dim1];
+ x01 = x[2 * i + 2 * 0 * dim1 + 1];
+ };
+ if ( i == 0 )
+ {
+ {
+ x02 = x[2 * i + 2 * 1 * dim1];
+ x03 = x[2 * i + 2 * 1 * dim1 + 1];
+ };
+ {
+ x04 = x[2 * i + 2 * 2 * dim1];
+ x05 = x[2 * i + 2 * 2 * dim1 + 1];
+ };
+ {
+ x06 = x[2 * i + 2 * 3 * dim1];
+ x07 = x[2 * i + 2 * 3 * dim1 + 1];
+ };
+ {
+ x08 = x[2 * i + 2 * 4 * dim1];
+ x09 = x[2 * i + 2 * 4 * dim1 + 1];
+ };
+ {
+ x10 = x[2 * i + 2 * 5 * dim1];
+ x11 = x[2 * i + 2 * 5 * dim1 + 1];
+ };
+ {
+ x12 = x[2 * i + 2 * 6 * dim1];
+ x13 = x[2 * i + 2 * 6 * dim1 + 1];
+ };
+ {
+ x14 = x[2 * i + 2 * 7 * dim1];
+ x15 = x[2 * i + 2 * 7 * dim1 + 1];
+ };
+ }
+ else
+ {
+ {
+ x02 = ( x[2 * i + 2 * 1 * dim1] * W[sc * i + sc * 1 * dim1 * 2 - Woff] ) - ( x[2 * i + 2 * 1 * dim1 + 1] * W[sc * i + sc * 1 * dim1 * 2 + 1 - Woff] );
+ x03 = ( x[2 * i + 2 * 1 * dim1] * W[sc * i + sc * 1 * dim1 * 2 + 1 - Woff] ) + ( x[2 * i + 2 * 1 * dim1 + 1] * W[sc * i + sc * 1 * dim1 * 2 - Woff] );
+ };
+ {
+ x04 = ( x[2 * i + 2 * 2 * dim1] * W[sc * i + sc * 2 * dim1 * 2 - Woff] ) - ( x[2 * i + 2 * 2 * dim1 + 1] * W[sc * i + sc * 2 * dim1 * 2 + 1 - Woff] );
+ x05 = ( x[2 * i + 2 * 2 * dim1] * W[sc * i + sc * 2 * dim1 * 2 + 1 - Woff] ) + ( x[2 * i + 2 * 2 * dim1 + 1] * W[sc * i + sc * 2 * dim1 * 2 - Woff] );
+ };
+ {
+ x06 = ( x[2 * i + 2 * 3 * dim1] * W[sc * i + sc * 3 * dim1 * 2 - Woff] ) - ( x[2 * i + 2 * 3 * dim1 + 1] * W[sc * i + sc * 3 * dim1 * 2 + 1 - Woff] );
+ x07 = ( x[2 * i + 2 * 3 * dim1] * W[sc * i + sc * 3 * dim1 * 2 + 1 - Woff] ) + ( x[2 * i + 2 * 3 * dim1 + 1] * W[sc * i + sc * 3 * dim1 * 2 - Woff] );
+ };
+ {
+ x08 = ( x[2 * i + 2 * 4 * dim1] * W[sc * i + sc * 4 * dim1 * 2 - Woff] ) - ( x[2 * i + 2 * 4 * dim1 + 1] * W[sc * i + sc * 4 * dim1 * 2 + 1 - Woff] );
+ x09 = ( x[2 * i + 2 * 4 * dim1] * W[sc * i + sc * 4 * dim1 * 2 + 1 - Woff] ) + ( x[2 * i + 2 * 4 * dim1 + 1] * W[sc * i + sc * 4 * dim1 * 2 - Woff] );
+ };
+ {
+ x10 = ( x[2 * i + 2 * 5 * dim1] * W[sc * i + sc * 5 * dim1 * 2 - Woff] ) - ( x[2 * i + 2 * 5 * dim1 + 1] * W[sc * i + sc * 5 * dim1 * 2 + 1 - Woff] );
+ x11 = ( x[2 * i + 2 * 5 * dim1] * W[sc * i + sc * 5 * dim1 * 2 + 1 - Woff] ) + ( x[2 * i + 2 * 5 * dim1 + 1] * W[sc * i + sc * 5 * dim1 * 2 - Woff] );
+ };
+ {
+ x12 = ( x[2 * i + 2 * 6 * dim1] * W[sc * i + sc * 6 * dim1 * 2 - Woff] ) - ( x[2 * i + 2 * 6 * dim1 + 1] * W[sc * i + sc * 6 * dim1 * 2 + 1 - Woff] );
+ x13 = ( x[2 * i + 2 * 6 * dim1] * W[sc * i + sc * 6 * dim1 * 2 + 1 - Woff] ) + ( x[2 * i + 2 * 6 * dim1 + 1] * W[sc * i + sc * 6 * dim1 * 2 - Woff] );
+ };
+ {
+ x14 = ( x[2 * i + 2 * 7 * dim1] * W[sc * i + sc * 7 * dim1 * 2 - Woff] ) - ( x[2 * i + 2 * 7 * dim1 + 1] * W[sc * i + sc * 7 * dim1 * 2 + 1 - Woff] );
+ x15 = ( x[2 * i + 2 * 7 * dim1] * W[sc * i + sc * 7 * dim1 * 2 + 1 - Woff] ) + ( x[2 * i + 2 * 7 * dim1 + 1] * W[sc * i + sc * 7 * dim1 * 2 - Woff] );
+ };
+ }
+
+ t00 = ( x00 + x08 );
+ t02 = ( x00 - x08 );
+ t01 = ( x01 + x09 );
+ t03 = ( x01 - x09 );
+ t04 = ( x02 + x10 );
+ t06 = ( x02 - x10 );
+ t05 = ( x03 + x11 );
+ t07 = ( x03 - x11 );
+ t08 = ( x04 + x12 );
+ t10 = ( x04 - x12 );
+ t09 = ( x05 + x13 );
+ t11 = ( x05 - x13 );
+ t12 = ( x06 + x14 );
+ t14 = ( x06 - x14 );
+ t13 = ( x07 + x15 );
+ t15 = ( x07 - x15 );
+
+ s00 = ( t00 + t08 );
+ s04 = ( t00 - t08 );
+ s01 = ( t01 + t09 );
+ s05 = ( t01 - t09 );
+ s08 = ( t02 - t11 );
+ s10 = ( t02 + t11 );
+ s09 = ( t03 + t10 );
+ s11 = ( t03 - t10 );
+ s02 = ( t04 + t12 );
+ s07 = ( t04 - t12 );
+ s03 = ( t05 + t13 );
+ s06 = ( t13 - t05 );
+
+ t01 = ( t06 + t14 );
+ t02 = ( t06 - t14 );
+ t00 = ( t07 + t15 );
+ t03 = ( t07 - t15 );
+
+ s12 = ( ( t00 + t02 ) * FFT_C81 );
+ s14 = ( ( t00 - t02 ) * FFT_C81 );
+ s13 = ( ( t03 - t01 ) * FFT_C81 );
+ s15 = ( ( t01 + t03 ) * FFT_C82 );
+
+ re[sx * i + sx * 0 * dim1] = ( s00 + s02 );
+ im[sx * i + sx * 0 * dim1] = ( s01 + s03 );
+ re[sx * i + sx * 1 * dim1] = ( s10 + s12 );
+ im[sx * i + sx * 1 * dim1] = ( s11 + s13 );
+ re[sx * i + sx * 2 * dim1] = ( s04 - s06 );
+ im[sx * i + sx * 2 * dim1] = ( s05 - s07 );
+ re[sx * i + sx * 3 * dim1] = ( s08 + s14 );
+ im[sx * i + sx * 3 * dim1] = ( s09 + s15 );
+ re[sx * i + sx * 4 * dim1] = ( s00 - s02 );
+ im[sx * i + sx * 4 * dim1] = ( s01 - s03 );
+ re[sx * i + sx * 5 * dim1] = ( s10 - s12 );
+ im[sx * i + sx * 5 * dim1] = ( s11 - s13 );
+ re[sx * i + sx * 6 * dim1] = ( s04 + s06 );
+ im[sx * i + sx * 6 * dim1] = ( s05 + s07 );
+ re[sx * i + sx * 7 * dim1] = ( s08 - s14 );
+ im[sx * i + sx * 7 * dim1] = ( s09 - s15 );
+ }
+ }
+ else
+ {
+ for ( i = 0; i < dim1; i++ )
+ {
+ {
+ x00 = x[2 * i + 2 * 0 * dim1];
+ x01 = x[2 * i + 2 * 0 * dim1 + 1];
+ };
+ if ( i == 0 )
+ {
+ {
+ x02 = x[2 * i + 2 * 1 * dim1];
+ x03 = x[2 * i + 2 * 1 * dim1 + 1];
+ };
+ {
+ x04 = x[2 * i + 2 * 2 * dim1];
+ x05 = x[2 * i + 2 * 2 * dim1 + 1];
+ };
+ {
+ x06 = x[2 * i + 2 * 3 * dim1];
+ x07 = x[2 * i + 2 * 3 * dim1 + 1];
+ };
+ {
+ x08 = x[2 * i + 2 * 4 * dim1];
+ x09 = x[2 * i + 2 * 4 * dim1 + 1];
+ };
+ {
+ x10 = x[2 * i + 2 * 5 * dim1];
+ x11 = x[2 * i + 2 * 5 * dim1 + 1];
+ };
+ {
+ x12 = x[2 * i + 2 * 6 * dim1];
+ x13 = x[2 * i + 2 * 6 * dim1 + 1];
+ };
+ {
+ x14 = x[2 * i + 2 * 7 * dim1];
+ x15 = x[2 * i + 2 * 7 * dim1 + 1];
+ };
+ }
+ else
+ {
+ {
+ x02 = ( x[2 * i + 2 * 1 * dim1] * W[sc * i + sc * 1 * dim1 - Woff] ) - ( x[2 * i + 2 * 1 * dim1 + 1] * W[sc * i + sc * 1 * dim1 + 1 - Woff] );
+ x03 = ( x[2 * i + 2 * 1 * dim1] * W[sc * i + sc * 1 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * 1 * dim1 + 1] * W[sc * i + sc * 1 * dim1 - Woff] );
+ };
+ {
+ x04 = ( x[2 * i + 2 * 2 * dim1] * W[sc * i + sc * 2 * dim1 - Woff] ) - ( x[2 * i + 2 * 2 * dim1 + 1] * W[sc * i + sc * 2 * dim1 + 1 - Woff] );
+ x05 = ( x[2 * i + 2 * 2 * dim1] * W[sc * i + sc * 2 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * 2 * dim1 + 1] * W[sc * i + sc * 2 * dim1 - Woff] );
+ };
+ {
+ x06 = ( x[2 * i + 2 * 3 * dim1] * W[sc * i + sc * 3 * dim1 - Woff] ) - ( x[2 * i + 2 * 3 * dim1 + 1] * W[sc * i + sc * 3 * dim1 + 1 - Woff] );
+ x07 = ( x[2 * i + 2 * 3 * dim1] * W[sc * i + sc * 3 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * 3 * dim1 + 1] * W[sc * i + sc * 3 * dim1 - Woff] );
+ };
+ {
+ x08 = ( x[2 * i + 2 * 4 * dim1] * W[sc * i + sc * 4 * dim1 - Woff] ) - ( x[2 * i + 2 * 4 * dim1 + 1] * W[sc * i + sc * 4 * dim1 + 1 - Woff] );
+ x09 = ( x[2 * i + 2 * 4 * dim1] * W[sc * i + sc * 4 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * 4 * dim1 + 1] * W[sc * i + sc * 4 * dim1 - Woff] );
+ };
+ {
+ x10 = ( x[2 * i + 2 * 5 * dim1] * W[sc * i + sc * 5 * dim1 - Woff] ) - ( x[2 * i + 2 * 5 * dim1 + 1] * W[sc * i + sc * 5 * dim1 + 1 - Woff] );
+ x11 = ( x[2 * i + 2 * 5 * dim1] * W[sc * i + sc * 5 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * 5 * dim1 + 1] * W[sc * i + sc * 5 * dim1 - Woff] );
+ };
+ {
+ x12 = ( x[2 * i + 2 * 6 * dim1] * W[sc * i + sc * 6 * dim1 - Woff] ) - ( x[2 * i + 2 * 6 * dim1 + 1] * W[sc * i + sc * 6 * dim1 + 1 - Woff] );
+ x13 = ( x[2 * i + 2 * 6 * dim1] * W[sc * i + sc * 6 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * 6 * dim1 + 1] * W[sc * i + sc * 6 * dim1 - Woff] );
+ };
+ {
+ x14 = ( x[2 * i + 2 * 7 * dim1] * W[sc * i + sc * 7 * dim1 - Woff] ) - ( x[2 * i + 2 * 7 * dim1 + 1] * W[sc * i + sc * 7 * dim1 + 1 - Woff] );
+ x15 = ( x[2 * i + 2 * 7 * dim1] * W[sc * i + sc * 7 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * 7 * dim1 + 1] * W[sc * i + sc * 7 * dim1 - Woff] );
+ };
+ }
+
+ t00 = ( x00 + x08 );
+ t02 = ( x00 - x08 );
+ t01 = ( x01 + x09 );
+ t03 = ( x01 - x09 );
+ t04 = ( x02 + x10 );
+ t06 = ( x02 - x10 );
+ t05 = ( x03 + x11 );
+ t07 = ( x03 - x11 );
+ t08 = ( x04 + x12 );
+ t10 = ( x04 - x12 );
+ t09 = ( x05 + x13 );
+ t11 = ( x05 - x13 );
+ t12 = ( x06 + x14 );
+ t14 = ( x06 - x14 );
+ t13 = ( x07 + x15 );
+ t15 = ( x07 - x15 );
+
+ s00 = ( t00 + t08 );
+ s04 = ( t00 - t08 );
+ s01 = ( t01 + t09 );
+ s05 = ( t01 - t09 );
+ s08 = ( t02 - t11 );
+ s10 = ( t02 + t11 );
+ s09 = ( t03 + t10 );
+ s11 = ( t03 - t10 );
+ s02 = ( t04 + t12 );
+ s07 = ( t04 - t12 );
+ s03 = ( t05 + t13 );
+ s06 = ( t13 - t05 );
+
+ t01 = ( t06 + t14 );
+ t02 = ( t06 - t14 );
+ t00 = ( t07 + t15 );
+ t03 = ( t07 - t15 );
+
+ s12 = ( ( t00 + t02 ) * FFT_C81 );
+ s14 = ( ( t00 - t02 ) * FFT_C81 );
+ s13 = ( ( t03 - t01 ) * FFT_C81 );
+ s15 = ( ( t01 + t03 ) * FFT_C82 );
+
+ re[sx * i + sx * 0 * dim1] = ( s00 + s02 );
+ im[sx * i + sx * 0 * dim1] = ( s01 + s03 );
+ re[sx * i + sx * 1 * dim1] = ( s10 + s12 );
+ im[sx * i + sx * 1 * dim1] = ( s11 + s13 );
+ re[sx * i + sx * 2 * dim1] = ( s04 - s06 );
+ im[sx * i + sx * 2 * dim1] = ( s05 - s07 );
+ re[sx * i + sx * 3 * dim1] = ( s08 + s14 );
+ im[sx * i + sx * 3 * dim1] = ( s09 + s15 );
+ re[sx * i + sx * 4 * dim1] = ( s00 - s02 );
+ im[sx * i + sx * 4 * dim1] = ( s01 - s03 );
+ re[sx * i + sx * 5 * dim1] = ( s10 - s12 );
+ im[sx * i + sx * 5 * dim1] = ( s11 - s13 );
+ re[sx * i + sx * 6 * dim1] = ( s04 + s06 );
+ im[sx * i + sx * 6 * dim1] = ( s05 + s07 );
+ re[sx * i + sx * 7 * dim1] = ( s08 - s14 );
+ im[sx * i + sx * 7 * dim1] = ( s09 - s15 );
+ }
+ }
+ break;
+ }
+
+ case 10:
+ {
+ float y[2 * 10];
+ for ( j = 0; j < dim2; j++ )
+ {
+ {
+ y[2 * j] = x[2 * 0 + 2 * j * dim1];
+ y[2 * j + 1] = x[2 * 0 + 2 * j * dim1 + 1];
+ };
+ }
+ fft_len10( &y[0], &y[1], 2 );
+ for ( j = 0; j < dim2; j++ )
+ {
+ re[sx * 0 + sx * j * dim1] = y[2 * j];
+ im[sx * 0 + sx * j * dim1] = y[2 * j + 1];
+ }
+
+ for ( i = 1; i < dim1; i++ )
+ {
+ {
+ y[2 * ( 0 + 0 )] = x[2 * i + 2 * ( 0 + 0 ) * dim1];
+ y[2 * ( 0 + 0 ) + 1] = x[2 * i + 2 * ( 0 + 0 ) * dim1 + 1];
+ }
+
+ for ( j = 1; j < dim2; j++ )
+ {
+ {
+ y[2 * ( j + 0 )] = ( x[2 * i + 2 * ( j + 0 ) * dim1] * W[sc * i + sc * j * dim1 - Woff] ) - ( x[2 * i + 2 * ( j + 0 ) * dim1 + 1] * W[sc * i + sc * j * dim1 + 1 - Woff] );
+ y[2 * ( j + 0 ) + 1] = ( x[2 * i + 2 * ( j + 0 ) * dim1] * W[sc * i + sc * j * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * ( j + 0 ) * dim1 + 1] * W[sc * i + sc * j * dim1 - Woff] );
+ }
+ }
+ fft_len10( &y[0], &y[1], 2 );
+ for ( j = 0; j < dim2; j++ )
+ {
+ re[sx * i + sx * j * dim1] = y[2 * j];
+ im[sx * i + sx * j * dim1] = y[2 * j + 1];
+ }
+ }
+ break;
+ }
+
+ case 16:
+ {
+ float y[2 * 16];
+ for ( j = 0; j < dim2; j++ )
+ {
+ {
+ y[2 * j] = x[2 * 0 + 2 * j * dim1];
+ y[2 * j + 1] = x[2 * 0 + 2 * j * dim1 + 1];
+ };
+ }
+ fft_len16( &y[0], &y[1], 2 );
+ for ( j = 0; j < dim2; j++ )
+ {
+ re[sx * 0 + sx * j * dim1] = y[2 * j];
+ im[sx * 0 + sx * j * dim1] = y[2 * j + 1];
+ }
+
+ for ( i = 1; i < dim1; i++ )
+ {
+ {
+ y[2 * ( 0 + 0 )] = x[2 * i + 2 * ( 0 + 0 ) * dim1];
+ y[2 * ( 0 + 0 ) + 1] = x[2 * i + 2 * ( 0 + 0 ) * dim1 + 1];
+ }
+
+ for ( j = 1; j < dim2; j++ )
+ {
+ {
+ y[2 * ( j + 0 )] = ( x[2 * i + 2 * ( j + 0 ) * dim1] * W[sc * i + sc * j * dim1 - Woff] ) - ( x[2 * i + 2 * ( j + 0 ) * dim1 + 1] * W[sc * i + sc * j * dim1 + 1 - Woff] );
+ y[2 * ( j + 0 ) + 1] = ( x[2 * i + 2 * ( j + 0 ) * dim1] * W[sc * i + sc * j * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * ( j + 0 ) * dim1 + 1] * W[sc * i + sc * j * dim1 - Woff] );
+ }
+ }
+ fft_len16( &y[0], &y[1], 2 );
+ for ( j = 0; j < dim2; j++ )
+ {
+ re[sx * i + sx * j * dim1] = y[2 * j];
+ im[sx * i + sx * j * dim1] = y[2 * j + 1];
+ }
+ }
+ break;
+ }
+
+ case 20:
+ {
+ float y[2 * 20];
+ for ( j = 0; j < dim2; j++ )
+ {
+ {
+ y[2 * j] = x[2 * 0 + 2 * j * dim1];
+ y[2 * j + 1] = x[2 * 0 + 2 * j * dim1 + 1];
+ };
+ }
+ fft_len20( &y[0], &y[1], 2 );
+ for ( j = 0; j < dim2; j++ )
+ {
+ re[sx * 0 + sx * j * dim1] = y[2 * j];
+ im[sx * 0 + sx * j * dim1] = y[2 * j + 1];
+ }
+
+ for ( i = 1; i < dim1; i++ )
+ {
+ {
+ y[2 * ( 0 + 0 )] = x[2 * i + 2 * ( 0 + 0 ) * dim1];
+ y[2 * ( 0 + 0 ) + 1] = x[2 * i + 2 * ( 0 + 0 ) * dim1 + 1];
+ }
+ {
+ y[2 * ( 0 + 1 )] = ( x[2 * i + 2 * ( 0 + 1 ) * dim1] * W[len + sc * i + 0 * dim1 - Woff] ) - ( x[2 * i + 2 * ( 0 + 1 ) * dim1 + 1] * W[len + sc * i + 0 * dim1 + 1 - Woff] );
+ y[2 * ( 0 + 1 ) + 1] = ( x[2 * i + 2 * ( 0 + 1 ) * dim1] * W[len + sc * i + 0 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * ( 0 + 1 ) * dim1 + 1] * W[len + sc * i + 0 * dim1 - Woff] );
+ }
+
+ for ( j = 2; j < dim2; j = j + 2 )
+ {
+ {
+ y[2 * ( j + 0 )] = ( x[2 * i + 2 * ( j + 0 ) * dim1] * W[sc * i + j * dim1 - Woff] ) - ( x[2 * i + 2 * ( j + 0 ) * dim1 + 1] * W[sc * i + j * dim1 + 1 - Woff] );
+ y[2 * ( j + 0 ) + 1] = ( x[2 * i + 2 * ( j + 0 ) * dim1] * W[sc * i + j * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * ( j + 0 ) * dim1 + 1] * W[sc * i + j * dim1 - Woff] );
+ }
+ {
+ y[2 * ( j + 1 )] = ( x[2 * i + 2 * ( j + 1 ) * dim1] * W[len + sc * i + j * dim1 - Woff] ) - ( x[2 * i + 2 * ( j + 1 ) * dim1 + 1] * W[len + sc * i + j * dim1 + 1 - Woff] );
+ y[2 * ( j + 1 ) + 1] = ( x[2 * i + 2 * ( j + 1 ) * dim1] * W[len + sc * i + j * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * ( j + 1 ) * dim1 + 1] * W[len + sc * i + j * dim1 - Woff] );
+ }
+ }
+ fft_len20( &y[0], &y[1], 2 );
+ for ( j = 0; j < dim2; j++ )
+ {
+ re[sx * i + sx * j * dim1] = y[2 * j];
+ im[sx * i + sx * j * dim1] = y[2 * j + 1];
+ }
+ }
+ break;
+ }
+
+ case 32:
+ {
+ float y[2 * 32];
+ for ( j = 0; j < dim2; j++ )
+ {
+ {
+ y[2 * j] = x[2 * 0 + 2 * j * dim1];
+ y[2 * j + 1] = x[2 * 0 + 2 * j * dim1 + 1];
+ };
+ }
+ fft_len32( &y[0], &y[1], 2 );
+ for ( j = 0; j < dim2; j++ )
+ {
+ re[sx * 0 + sx * j * dim1] = y[2 * j];
+ im[sx * 0 + sx * j * dim1] = y[2 * j + 1];
+ }
+
+ for ( i = 1; i < dim1; i++ )
+ {
+ {
+ y[2 * ( 0 + 0 )] = x[2 * i + 2 * ( 0 + 0 ) * dim1];
+ y[2 * ( 0 + 0 ) + 1] = x[2 * i + 2 * ( 0 + 0 ) * dim1 + 1];
+ }
+ {
+ y[2 * ( 0 + 1 )] = ( x[2 * i + 2 * ( 0 + 1 ) * dim1] * W[len + sc * i + 0 * dim1 - Woff] ) - ( x[2 * i + 2 * ( 0 + 1 ) * dim1 + 1] * W[len + sc * i + 0 * dim1 + 1 - Woff] );
+ y[2 * ( 0 + 1 ) + 1] = ( x[2 * i + 2 * ( 0 + 1 ) * dim1] * W[len + sc * i + 0 * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * ( 0 + 1 ) * dim1 + 1] * W[len + sc * i + 0 * dim1 - Woff] );
+ }
+
+ for ( j = 2; j < dim2; j = j + 2 )
+ {
+ {
+ y[2 * ( j + 0 )] = ( x[2 * i + 2 * ( j + 0 ) * dim1] * W[sc * i + j * dim1 - Woff] ) - ( x[2 * i + 2 * ( j + 0 ) * dim1 + 1] * W[sc * i + j * dim1 + 1 - Woff] );
+ y[2 * ( j + 0 ) + 1] = ( x[2 * i + 2 * ( j + 0 ) * dim1] * W[sc * i + j * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * ( j + 0 ) * dim1 + 1] * W[sc * i + j * dim1 - Woff] );
+ }
+ {
+ y[2 * ( j + 1 )] = ( x[2 * i + 2 * ( j + 1 ) * dim1] * W[len + sc * i + j * dim1 - Woff] ) - ( x[2 * i + 2 * ( j + 1 ) * dim1 + 1] * W[len + sc * i + j * dim1 + 1 - Woff] );
+ y[2 * ( j + 1 ) + 1] = ( x[2 * i + 2 * ( j + 1 ) * dim1] * W[len + sc * i + j * dim1 + 1 - Woff] ) + ( x[2 * i + 2 * ( j + 1 ) * dim1 + 1] * W[len + sc * i + j * dim1 - Woff] );
+ }
+ }
+ fft_len32( &y[0], &y[1], 2 );
+ for ( j = 0; j < dim2; j++ )
+ {
+ re[sx * i + sx * j * dim1] = y[2 * j];
+ im[sx * i + sx * j * dim1] = y[2 * j + 1];
+ }
+ }
+ break;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------*
+ * fft()
+ *
+ * Complex-value FFT
+ *-----------------------------------------------------------------*/
+
+void fft(
+ float *re, /* i/o: real part */
+ float *im, /* i/o: imag part */
+ const int16_t length, /* i : length of fft */
+ const int16_t s /* i : sign */
+)
+{
+ switch ( length )
+ {
+ case 20:
+ fft_len20( re, im, s );
+ break;
+ case 40:
+ fft_lenN( re, im, FFT_RotVector_640, 640, 5, 8, s, 8, 40 );
+ break;
+ case 64:
+ fft_lenN( re, im, FFT_RotVector_256, 256, 8, 8, s, 8, 64 );
+ break;
+ case 80:
+ fft_lenN( re, im, FFT_RotVector_640, 640, 10, 8, s, 4, 40 );
+ break;
+ case 100:
+ fft_lenN( re, im, FFT_RotVector_400, 400, 10, 10, s, 4, 40 );
+ break;
+ case 120:
+ fft_lenN( re, im, FFT_RotVector_960, 960, 15, 8, s, 4, 60 );
+ break;
+ case 128:
+ fft_lenN( re, im, FFT_RotVector_256, 256, 16, 8, s, 4, 64 );
+ break;
+ case 160:
+ fft_lenN( re, im, FFT_RotVector_640, 640, 20, 8, s, 2, 40 );
+ break;
+ case 200:
+ fft_lenN( re, im, FFT_RotVector_400, 400, 20, 10, s, 2, 40 );
+ break;
+ case 240:
+ fft_lenN( re, im, FFT_RotVector_960, 960, 30, 8, s, 2, 60 );
+ break;
+ case 256:
+ fft_lenN( re, im, FFT_RotVector_256, 256, 32, 8, s, 2, 64 );
+ break;
+ case 320:
+ fft_lenN( re, im, FFT_RotVector_640, 640, 20, 16, s, 2, 40 );
+ break;
+ case 400:
+ fft_lenN( re, im, FFT_RotVector_400, 400, 20, 20, s, 2, 40 );
+ break;
+ case 480:
+ fft_lenN( re, im, FFT_RotVector_960, 960, 30, 16, s, 2, 60 );
+ break;
+ case 600:
+ fft_lenN( re, im, FFT_RotVector_600, 600, 30, 20, s, 2, 60 );
+ break;
+ case 640:
+ fft_lenN( re, im, FFT_RotVector_640, 640, 20, 32, s, 2, 40 );
+ break;
+ case 960:
+ fft_lenN( re, im, FFT_RotVector_960, 960, 30, 32, s, 2, 60 );
+ break;
+ default:
+ assert( !"fft length is not supported!" );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------*
+ * rfft()
+ *
+ * Real-value FFT
+ *-----------------------------------------------------------------*/
+
+void rfft(
+ float *x, /* i/o: values */
+ const float *w, /* i : window */
+ const int16_t length, /* i : length of fft */
+ const int16_t isign /* i : sign */
+)
+{
+ int16_t i, sizeOfFft2, sizeOfFft4;
+ float tmp, t1, t2, t3, t4, s1, s2;
+
+ sizeOfFft2 = length >> 1;
+ sizeOfFft4 = length >> 2;
+ s1 = 1.f / (float) sizeOfFft2;
+ s2 = -1.f / (float) sizeOfFft2;
+
+ switch ( isign )
+ {
+
+ case -1:
+
+ fft( x, x + 1, sizeOfFft2, 2 );
+
+ tmp = x[0] + x[1];
+ x[1] = x[0] - x[1];
+ x[0] = tmp;
+
+ for ( i = 1; i <= sizeOfFft4; i++ )
+ {
+ t1 = x[2 * i] - x[length - 2 * i];
+ t2 = x[2 * i + 1] + x[length - 2 * i + 1];
+ t3 = w[i] * t1 - w[i + sizeOfFft4] * t2;
+ t4 = w[i + sizeOfFft4] * t1 + w[i] * t2;
+ t1 = x[2 * i] + x[length - 2 * i];
+ t2 = x[2 * i + 1] - x[length - 2 * i + 1];
+
+ x[2 * i] = ( t1 - t3 ) * 0.5f;
+ x[2 * i + 1] = ( t2 - t4 ) * 0.5f;
+ x[length - 2 * i] = ( t1 + t3 ) * 0.5f;
+ x[length - 2 * i + 1] = -( t2 + t4 ) * 0.5f;
+ }
+
+ break;
+
+ case +1:
+
+ tmp = ( x[0] + x[1] ) * 0.5f;
+ x[1] = ( x[1] - x[0] ) * 0.5f;
+ x[0] = tmp;
+
+ for ( i = 1; i <= sizeOfFft4; i++ )
+ {
+ t1 = x[2 * i] - x[length - 2 * i];
+ t2 = x[2 * i + 1] + x[length - 2 * i + 1];
+ t3 = w[i] * t1 + w[i + sizeOfFft4] * t2;
+ t4 = -w[i + sizeOfFft4] * t1 + w[i] * t2;
+ t1 = x[2 * i] + x[length - 2 * i];
+ t2 = x[2 * i + 1] - x[length - 2 * i + 1];
+
+ x[2 * i] = ( t1 - t3 ) * 0.5f;
+ x[2 * i + 1] = ( t4 - t2 ) * 0.5f;
+ x[length - 2 * i] = ( t1 + t3 ) * 0.5f;
+ x[length - 2 * i + 1] = ( t2 + t4 ) * 0.5f;
+ }
+
+ fft( x, x + 1, sizeOfFft2, 2 );
+
+ for ( i = 0; i < length; i += 2 )
+ {
+ x[i] *= s1;
+ x[i + 1] *= s2;
+ }
+
+ break;
+ }
+
+ return;
+}
+
+
+#define WMC_TOOL_SKIP
+
+#define SCALEFACTOR8 ( 4 )
+#define SCALEFACTOR64 ( 7 )
+#define SCALEFACTORN2 ( 3 )
+
+#define SHC( x ) ( (Word16) x )
+#define FFTC( x ) WORD322WORD16( (Word32) x )
+
+#define C81_FX ( FFTC( 0x5a82799a ) ) /* FL2WORD32( 7.071067811865475e-1) */
+#define C82_FX ( FFTC( 0xa57d8666 ) ) /* FL2WORD32(-7.071067811865475e-1) */
+
+#define cplxMpy4_8_0( re, im, a, b, c, d ) \
+ re = L_shr( L_sub( Mpy_32_16( a, c ), Mpy_32_16( b, d ) ), 1 ); \
+ im = L_shr( L_add( Mpy_32_16( a, d ), Mpy_32_16( b, c ) ), 1 );
+
+#define cplxMpy4_8_1( re, im, a, b ) \
+ re = L_shr( a, 1 ); \
+ im = L_shr( b, 1 );
+
+
+/**
+ * \brief Twiddle factors are unscaled
+ */
+static const Word16 RotVector_256[2 * ( 256 - 32 )] = {
+ SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7ff6 ), SHC( 0xfcdc ), SHC( 0x7fd9 ), SHC( 0xf9b8 ), SHC( 0x7fa7 ), SHC( 0xf695 ),
+ SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7f0a ), SHC( 0xf055 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7e1e ), SHC( 0xea1e ),
+ SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7ce4 ), SHC( 0xe3f4 ), SHC( 0x7c2a ), SHC( 0xe0e6 ), SHC( 0x7b5d ), SHC( 0xdddc ),
+ SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x798a ), SHC( 0xd7d9 ), SHC( 0x7885 ), SHC( 0xd4e1 ), SHC( 0x776c ), SHC( 0xd1ef ),
+ SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x7505 ), SHC( 0xcc21 ), SHC( 0x73b6 ), SHC( 0xc946 ), SHC( 0x7255 ), SHC( 0xc673 ),
+ SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x6f5f ), SHC( 0xc0e9 ), SHC( 0x6dca ), SHC( 0xbe32 ), SHC( 0x6c24 ), SHC( 0xbb85 ),
+ SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x68a7 ), SHC( 0xb64c ), SHC( 0x66d0 ), SHC( 0xb3c0 ), SHC( 0x64e9 ), SHC( 0xb140 ),
+ SHC( 0x62f2 ), SHC( 0xaecc ), SHC( 0x60ec ), SHC( 0xac65 ), SHC( 0x5ed7 ), SHC( 0xaa0a ), SHC( 0x5cb4 ), SHC( 0xa7bd ),
+ SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fd9 ), SHC( 0xf9b8 ), SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7e9d ), SHC( 0xed38 ),
+ SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7c2a ), SHC( 0xe0e6 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x7885 ), SHC( 0xd4e1 ),
+ SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x73b6 ), SHC( 0xc946 ), SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x6dca ), SHC( 0xbe32 ),
+ SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x66d0 ), SHC( 0xb3c0 ), SHC( 0x62f2 ), SHC( 0xaecc ), SHC( 0x5ed7 ), SHC( 0xaa0a ),
+ SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x55f6 ), SHC( 0xa129 ), SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x4c40 ), SHC( 0x9930 ),
+ SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x3c57 ), SHC( 0x8f1d ), SHC( 0x36ba ), SHC( 0x8c4a ),
+ SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x2b1f ), SHC( 0x877b ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x1f1a ), SHC( 0x83d6 ),
+ SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x12c8 ), SHC( 0x8163 ), SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0x0648 ), SHC( 0x8027 ),
+ SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7fa7 ), SHC( 0xf695 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7ce4 ), SHC( 0xe3f4 ),
+ SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x776c ), SHC( 0xd1ef ), SHC( 0x73b6 ), SHC( 0xc946 ), SHC( 0x6f5f ), SHC( 0xc0e9 ),
+ SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x64e9 ), SHC( 0xb140 ), SHC( 0x5ed7 ), SHC( 0xaa0a ), SHC( 0x5843 ), SHC( 0xa34c ),
+ SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x49b4 ), SHC( 0x9759 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x398d ), SHC( 0x8dab ),
+ SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x2827 ), SHC( 0x8676 ), SHC( 0x1f1a ), SHC( 0x83d6 ), SHC( 0x15e2 ), SHC( 0x81e2 ),
+ SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0x0324 ), SHC( 0x800a ), SHC( 0xf9b8 ), SHC( 0x8027 ), SHC( 0xf055 ), SHC( 0x80f6 ),
+ SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xdddc ), SHC( 0x84a3 ), SHC( 0xd4e1 ), SHC( 0x877b ), SHC( 0xcc21 ), SHC( 0x8afb ),
+ SHC( 0xc3a9 ), SHC( 0x8f1d ), SHC( 0xbb85 ), SHC( 0x93dc ), SHC( 0xb3c0 ), SHC( 0x9930 ), SHC( 0xac65 ), SHC( 0x9f14 ),
+ SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f62 ), SHC( 0xf374 ), SHC( 0x7d8a ), SHC( 0xe707 ), SHC( 0x7a7d ), SHC( 0xdad8 ),
+ SHC( 0x7642 ), SHC( 0xcf04 ), SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x62f2 ), SHC( 0xaecc ),
+ SHC( 0x5a82 ), SHC( 0xa57e ), SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x3c57 ), SHC( 0x8f1d ),
+ SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x2528 ), SHC( 0x8583 ), SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x0c8c ), SHC( 0x809e ),
+ SHC( 0x0000 ), SHC( 0x8000 ), SHC( 0xf374 ), SHC( 0x809e ), SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xdad8 ), SHC( 0x8583 ),
+ SHC( 0xcf04 ), SHC( 0x89be ), SHC( 0xc3a9 ), SHC( 0x8f1d ), SHC( 0xb8e3 ), SHC( 0x9592 ), SHC( 0xaecc ), SHC( 0x9d0e ),
+ SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9d0e ), SHC( 0xaecc ), SHC( 0x9592 ), SHC( 0xb8e3 ), SHC( 0x8f1d ), SHC( 0xc3a9 ),
+ SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x8583 ), SHC( 0xdad8 ), SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x809e ), SHC( 0xf374 ),
+ SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7f0a ), SHC( 0xf055 ), SHC( 0x7c2a ), SHC( 0xe0e6 ), SHC( 0x776c ), SHC( 0xd1ef ),
+ SHC( 0x70e3 ), SHC( 0xc3a9 ), SHC( 0x68a7 ), SHC( 0xb64c ), SHC( 0x5ed7 ), SHC( 0xaa0a ), SHC( 0x539b ), SHC( 0x9f14 ),
+ SHC( 0x471d ), SHC( 0x9592 ), SHC( 0x398d ), SHC( 0x8dab ), SHC( 0x2b1f ), SHC( 0x877b ), SHC( 0x1c0c ), SHC( 0x831c ),
+ SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0xfcdc ), SHC( 0x800a ), SHC( 0xed38 ), SHC( 0x8163 ), SHC( 0xdddc ), SHC( 0x84a3 ),
+ SHC( 0xcf04 ), SHC( 0x89be ), SHC( 0xc0e9 ), SHC( 0x90a1 ), SHC( 0xb3c0 ), SHC( 0x9930 ), SHC( 0xa7bd ), SHC( 0xa34c ),
+ SHC( 0x9d0e ), SHC( 0xaecc ), SHC( 0x93dc ), SHC( 0xbb85 ), SHC( 0x8c4a ), SHC( 0xc946 ), SHC( 0x8676 ), SHC( 0xd7d9 ),
+ SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x8059 ), SHC( 0xf695 ), SHC( 0x8027 ), SHC( 0x0648 ), SHC( 0x81e2 ), SHC( 0x15e2 ),
+ SHC( 0x8583 ), SHC( 0x2528 ), SHC( 0x8afb ), SHC( 0x33df ), SHC( 0x9236 ), SHC( 0x41ce ), SHC( 0x9b17 ), SHC( 0x4ec0 ),
+ SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e9d ), SHC( 0xed38 ), SHC( 0x7a7d ), SHC( 0xdad8 ), SHC( 0x73b6 ), SHC( 0xc946 ),
+ SHC( 0x6a6e ), SHC( 0xb8e3 ), SHC( 0x5ed7 ), SHC( 0xaa0a ), SHC( 0x5134 ), SHC( 0x9d0e ), SHC( 0x41ce ), SHC( 0x9236 ),
+ SHC( 0x30fc ), SHC( 0x89be ), SHC( 0x1f1a ), SHC( 0x83d6 ), SHC( 0x0c8c ), SHC( 0x809e ), SHC( 0xf9b8 ), SHC( 0x8027 ),
+ SHC( 0xe707 ), SHC( 0x8276 ), SHC( 0xd4e1 ), SHC( 0x877b ), SHC( 0xc3a9 ), SHC( 0x8f1d ), SHC( 0xb3c0 ), SHC( 0x9930 ),
+ SHC( 0xa57e ), SHC( 0xa57e ), SHC( 0x9930 ), SHC( 0xb3c0 ), SHC( 0x8f1d ), SHC( 0xc3a9 ), SHC( 0x877b ), SHC( 0xd4e1 ),
+ SHC( 0x8276 ), SHC( 0xe707 ), SHC( 0x8027 ), SHC( 0xf9b8 ), SHC( 0x809e ), SHC( 0x0c8c ), SHC( 0x83d6 ), SHC( 0x1f1a ),
+ SHC( 0x89be ), SHC( 0x30fc ), SHC( 0x9236 ), SHC( 0x41ce ), SHC( 0x9d0e ), SHC( 0x5134 ), SHC( 0xaa0a ), SHC( 0x5ed7 ),
+ SHC( 0xb8e3 ), SHC( 0x6a6e ), SHC( 0xc946 ), SHC( 0x73b6 ), SHC( 0xdad8 ), SHC( 0x7a7d ), SHC( 0xed38 ), SHC( 0x7e9d ),
+ SHC( 0x7fff ), SHC( 0x0000 ), SHC( 0x7e1e ), SHC( 0xea1e ), SHC( 0x7885 ), SHC( 0xd4e1 ), SHC( 0x6f5f ), SHC( 0xc0e9 ),
+ SHC( 0x62f2 ), SHC( 0xaecc ), SHC( 0x539b ), SHC( 0x9f14 ), SHC( 0x41ce ), SHC( 0x9236 ), SHC( 0x2e11 ), SHC( 0x8894 ),
+ SHC( 0x18f9 ), SHC( 0x8276 ), SHC( 0x0324 ), SHC( 0x800a ), SHC( 0xed38 ), SHC( 0x8163 ), SHC( 0xd7d9 ), SHC( 0x8676 ),
+ SHC( 0xc3a9 ), SHC( 0x8f1d ), SHC( 0xb140 ), SHC( 0x9b17 ), SHC( 0xa129 ), SHC( 0xaa0a ), SHC( 0x93dc ), SHC( 0xbb85 ),
+ SHC( 0x89be ), SHC( 0xcf04 ), SHC( 0x831c ), SHC( 0xe3f4 ), SHC( 0x8027 ), SHC( 0xf9b8 ), SHC( 0x80f6 ), SHC( 0x0fab ),
+ SHC( 0x8583 ), SHC( 0x2528 ), SHC( 0x8dab ), SHC( 0x398d ), SHC( 0x9930 ), SHC( 0x4c40 ), SHC( 0xa7bd ), SHC( 0x5cb4 ),
+ SHC( 0xb8e3 ), SHC( 0x6a6e ), SHC( 0xcc21 ), SHC( 0x7505 ), SHC( 0xe0e6 ), SHC( 0x7c2a ), SHC( 0xf695 ), SHC( 0x7fa7 ),
+ SHC( 0x0c8c ), SHC( 0x7f62 ), SHC( 0x2224 ), SHC( 0x7b5d ), SHC( 0x36ba ), SHC( 0x73b6 ), SHC( 0x49b4 ), SHC( 0x68a7 )
+};
+
+/*-----------------------------------------------------------------*
+ * BASOP_fft8()
+ *
+ * Function performs a complex 8-point FFT
+ * The FFT is performed inplace. The result of the FFT
+ * is scaled by SCALEFACTOR8 bits.
+ *
+ * WOPS with 32x16 bit multiplications: 108 cycles
+ *-----------------------------------------------------------------*/
+
+static void BASOP_fft8(
+ Word32 *re,
+ Word32 *im,
+ Word16 s )
+{
+ Word32 x00, x01, x02, x03, x04, x05, x06, x07;
+ Word32 x08, x09, x10, x11, x12, x13, x14, x15;
+ Word32 t00, t01, t02, t03, t04, t05, t06, t07;
+ Word32 t08, t09, t10, t11, t12, t13, t14, t15;
+ Word32 s00, s01, s02, s03, s04, s05, s06, s07;
+ Word32 s08, s09, s10, s11, s12, s13, s14, s15;
+
+
+ /* Pre-additions */
+
+ x00 = L_shr( re[s * 0], SCALEFACTOR8 );
+ x01 = L_shr( im[s * 0], SCALEFACTOR8 );
+ x02 = L_shr( re[s * 1], SCALEFACTOR8 );
+ x03 = L_shr( im[s * 1], SCALEFACTOR8 );
+ x04 = L_shr( re[s * 2], SCALEFACTOR8 );
+ x05 = L_shr( im[s * 2], SCALEFACTOR8 );
+ x06 = L_shr( re[s * 3], SCALEFACTOR8 );
+ x07 = L_shr( im[s * 3], SCALEFACTOR8 );
+ x08 = L_shr( re[s * 4], SCALEFACTOR8 );
+ x09 = L_shr( im[s * 4], SCALEFACTOR8 );
+ x10 = L_shr( re[s * 5], SCALEFACTOR8 );
+ x11 = L_shr( im[s * 5], SCALEFACTOR8 );
+ x12 = L_shr( re[s * 6], SCALEFACTOR8 );
+ x13 = L_shr( im[s * 6], SCALEFACTOR8 );
+ x14 = L_shr( re[s * 7], SCALEFACTOR8 );
+ x15 = L_shr( im[s * 7], SCALEFACTOR8 );
+
+ t00 = L_add( x00, x08 );
+ t02 = L_sub( x00, x08 );
+ t01 = L_add( x01, x09 );
+ t03 = L_sub( x01, x09 );
+ t04 = L_add( x02, x10 );
+ t06 = L_sub( x02, x10 );
+ t05 = L_add( x03, x11 );
+ t07 = L_sub( x03, x11 );
+ t08 = L_add( x04, x12 );
+ t10 = L_sub( x04, x12 );
+ t09 = L_add( x05, x13 );
+ t11 = L_sub( x05, x13 );
+ t12 = L_add( x06, x14 );
+ t14 = L_sub( x06, x14 );
+ t13 = L_add( x07, x15 );
+ t15 = L_sub( x07, x15 );
+
+ /* Pre-additions and core multiplications */
+
+ s00 = L_add( t00, t08 );
+ s04 = L_sub( t00, t08 );
+ s01 = L_add( t01, t09 );
+ s05 = L_sub( t01, t09 );
+ s08 = L_sub( t02, t11 );
+ s10 = L_add( t02, t11 );
+ s09 = L_add( t03, t10 );
+ s11 = L_sub( t03, t10 );
+ s02 = L_add( t04, t12 );
+ s07 = L_sub( t04, t12 );
+ s03 = L_add( t05, t13 );
+ s06 = L_sub( t13, t05 );
+
+ t01 = L_add( t06, t14 );
+ t02 = L_sub( t06, t14 );
+ t00 = L_add( t07, t15 );
+ t03 = L_sub( t07, t15 );
+
+ s12 = Mpy_32_16( L_add( t00, t02 ), C81_FX );
+ s14 = Mpy_32_16( L_sub( t00, t02 ), C81_FX );
+ s13 = Mpy_32_16( L_sub( t03, t01 ), C81_FX );
+ s15 = Mpy_32_16( L_add( t01, t03 ), C82_FX );
+
+ /* Post-additions */
+
+ re[s * 0] = L_add( s00, s02 );
+ move32();
+ re[s * 4] = L_sub( s00, s02 );
+ move32();
+ im[s * 0] = L_add( s01, s03 );
+ move32();
+ im[s * 4] = L_sub( s01, s03 );
+ move32();
+ re[s * 2] = L_sub( s04, s06 );
+ move32();
+ re[s * 6] = L_add( s04, s06 );
+ move32();
+ im[s * 2] = L_sub( s05, s07 );
+ move32();
+ im[s * 6] = L_add( s05, s07 );
+ move32();
+ re[s * 3] = L_add( s08, s14 );
+ move32();
+ re[s * 7] = L_sub( s08, s14 );
+ move32();
+ im[s * 3] = L_add( s09, s15 );
+ move32();
+ im[s * 7] = L_sub( s09, s15 );
+ move32();
+ re[s * 1] = L_add( s10, s12 );
+ move32();
+ re[s * 5] = L_sub( s10, s12 );
+ move32();
+ im[s * 1] = L_add( s11, s13 );
+ move32();
+ im[s * 5] = L_sub( s11, s13 );
+ move32();
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------*
+ * fftN2()
+ *
+ * Combined FFT
+ *-----------------------------------------------------------------*/
+
+static void BASOP_fftN2(
+ Word32 *re, /* i/o: real part */
+ Word32 *im, /* i/o: imag part */
+ const Word16 *W, /* i : rotation factor */
+ Word16 dim1, /* i : length of fft1 */
+ Word16 dim2, /* i : length of fft2 */
+ Word16 sx, /* i : stride real and imag part */
+ Word16 sc, /* i : stride phase rotation coefficients */
+ Word32 *x, /* tmp: 32-bit workbuffer */
+ Word16 Woff /* i : offset for addressing the rotation vector table */
+)
+{
+ Word16 i, j;
+ Word32 x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, x11, x12, x13, x14, x15;
+ Word32 t00, t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15;
+ Word32 s00, s01, s02, s03, s04, s05, s06, s07, s08, s09, s10, s11, s12, s13, s14, s15;
+
+ FOR( i = 0; i < dim2; i++ )
+ {
+ FOR( j = 0; j < dim1; j++ )
+ {
+ x[2 * i * dim1 + 2 * j] = re[sx * i + sx * j * dim2];
+ move32();
+ x[2 * i * dim1 + 2 * j + 1] = im[sx * i + sx * j * dim2];
+ move32();
+ }
+ }
+
+ /* dim1 == 8 */
+ FOR( i = 0; i < dim2; i++ )
+ {
+ BASOP_fft8( &x[i * 2 * dim1], &x[i * 2 * dim1 + 1], 2 );
+ }
+
+ /* dim2 == 8 */
+ FOR( i = 0; i < dim1; i++ )
+ {
+ cplxMpy4_8_1( x00, x01, x[2 * i + 2 * 0 * dim1], x[2 * i + 2 * 0 * dim1 + 1] );
+
+ IF( i == 0 )
+ {
+ cplxMpy4_8_1( x02, x03, x[2 * i + 2 * 1 * dim1], x[2 * i + 2 * 1 * dim1 + 1] );
+ cplxMpy4_8_1( x04, x05, x[2 * i + 2 * 2 * dim1], x[2 * i + 2 * 2 * dim1 + 1] );
+ cplxMpy4_8_1( x06, x07, x[2 * i + 2 * 3 * dim1], x[2 * i + 2 * 3 * dim1 + 1] );
+ cplxMpy4_8_1( x08, x09, x[2 * i + 2 * 4 * dim1], x[2 * i + 2 * 4 * dim1 + 1] );
+ cplxMpy4_8_1( x10, x11, x[2 * i + 2 * 5 * dim1], x[2 * i + 2 * 5 * dim1 + 1] );
+ cplxMpy4_8_1( x12, x13, x[2 * i + 2 * 6 * dim1], x[2 * i + 2 * 6 * dim1 + 1] );
+ cplxMpy4_8_1( x14, x15, x[2 * i + 2 * 7 * dim1], x[2 * i + 2 * 7 * dim1 + 1] );
+ }
+ ELSE
+ {
+ cplxMpy4_8_0( x02, x03, x[2 * i + 2 * 1 * dim1], x[2 * i + 2 * 1 * dim1 + 1], W[sc * i + sc * 1 * dim1 - Woff], W[sc * i + sc * 1 * dim1 + 1 - Woff] );
+ cplxMpy4_8_0( x04, x05, x[2 * i + 2 * 2 * dim1], x[2 * i + 2 * 2 * dim1 + 1], W[sc * i + sc * 2 * dim1 - Woff], W[sc * i + sc * 2 * dim1 + 1 - Woff] );
+ cplxMpy4_8_0( x06, x07, x[2 * i + 2 * 3 * dim1], x[2 * i + 2 * 3 * dim1 + 1], W[sc * i + sc * 3 * dim1 - Woff], W[sc * i + sc * 3 * dim1 + 1 - Woff] );
+ cplxMpy4_8_0( x08, x09, x[2 * i + 2 * 4 * dim1], x[2 * i + 2 * 4 * dim1 + 1], W[sc * i + sc * 4 * dim1 - Woff], W[sc * i + sc * 4 * dim1 + 1 - Woff] );
+ cplxMpy4_8_0( x10, x11, x[2 * i + 2 * 5 * dim1], x[2 * i + 2 * 5 * dim1 + 1], W[sc * i + sc * 5 * dim1 - Woff], W[sc * i + sc * 5 * dim1 + 1 - Woff] );
+ cplxMpy4_8_0( x12, x13, x[2 * i + 2 * 6 * dim1], x[2 * i + 2 * 6 * dim1 + 1], W[sc * i + sc * 6 * dim1 - Woff], W[sc * i + sc * 6 * dim1 + 1 - Woff] );
+ cplxMpy4_8_0( x14, x15, x[2 * i + 2 * 7 * dim1], x[2 * i + 2 * 7 * dim1 + 1], W[sc * i + sc * 7 * dim1 - Woff], W[sc * i + sc * 7 * dim1 + 1 - Woff] );
+ }
+ t00 = L_shr( L_add( x00, x08 ), SCALEFACTORN2 - 1 );
+ t02 = L_shr( L_sub( x00, x08 ), SCALEFACTORN2 - 1 );
+ t01 = L_shr( L_add( x01, x09 ), SCALEFACTORN2 - 1 );
+ t03 = L_shr( L_sub( x01, x09 ), SCALEFACTORN2 - 1 );
+ t04 = L_shr( L_add( x02, x10 ), SCALEFACTORN2 - 1 );
+ t06 = L_sub( x02, x10 );
+ t05 = L_shr( L_add( x03, x11 ), SCALEFACTORN2 - 1 );
+ t07 = L_sub( x03, x11 );
+ t08 = L_shr( L_add( x04, x12 ), SCALEFACTORN2 - 1 );
+ t10 = L_shr( L_sub( x04, x12 ), SCALEFACTORN2 - 1 );
+ t09 = L_shr( L_add( x05, x13 ), SCALEFACTORN2 - 1 );
+ t11 = L_shr( L_sub( x05, x13 ), SCALEFACTORN2 - 1 );
+ t12 = L_shr( L_add( x06, x14 ), SCALEFACTORN2 - 1 );
+ t14 = L_sub( x06, x14 );
+ t13 = L_shr( L_add( x07, x15 ), SCALEFACTORN2 - 1 );
+ t15 = L_sub( x07, x15 );
+
+ s00 = L_add( t00, t08 );
+ s04 = L_sub( t00, t08 );
+ s01 = L_add( t01, t09 );
+ s05 = L_sub( t01, t09 );
+ s08 = L_sub( t02, t11 );
+ s10 = L_add( t02, t11 );
+ s09 = L_add( t03, t10 );
+ s11 = L_sub( t03, t10 );
+ s02 = L_add( t04, t12 );
+ s07 = L_sub( t04, t12 );
+ s03 = L_add( t05, t13 );
+ s06 = L_sub( t13, t05 );
+
+ t01 = L_shr( L_add( t06, t14 ), SCALEFACTORN2 - 1 );
+ t02 = L_shr( L_sub( t06, t14 ), SCALEFACTORN2 - 1 );
+ t00 = L_shr( L_add( t07, t15 ), SCALEFACTORN2 - 1 );
+ t03 = L_shr( L_sub( t07, t15 ), SCALEFACTORN2 - 1 );
+
+ s12 = Mpy_32_16( L_add( t00, t02 ), C81_FX );
+ s14 = Mpy_32_16( L_sub( t00, t02 ), C81_FX );
+ s13 = Mpy_32_16( L_sub( t03, t01 ), C81_FX );
+ s15 = Mpy_32_16( L_add( t01, t03 ), C82_FX );
+
+ re[sx * i + sx * 0 * dim1] = L_add( s00, s02 );
+ move32();
+ im[sx * i + sx * 0 * dim1] = L_add( s01, s03 );
+ move32();
+ re[sx * i + sx * 1 * dim1] = L_add( s10, s12 );
+ move32();
+ im[sx * i + sx * 1 * dim1] = L_add( s11, s13 );
+ move32();
+ re[sx * i + sx * 2 * dim1] = L_sub( s04, s06 );
+ move32();
+ im[sx * i + sx * 2 * dim1] = L_sub( s05, s07 );
+ move32();
+ re[sx * i + sx * 3 * dim1] = L_add( s08, s14 );
+ move32();
+ im[sx * i + sx * 3 * dim1] = L_add( s09, s15 );
+ move32();
+ re[sx * i + sx * 4 * dim1] = L_sub( s00, s02 );
+ move32();
+ im[sx * i + sx * 4 * dim1] = L_sub( s01, s03 );
+ move32();
+ re[sx * i + sx * 5 * dim1] = L_sub( s10, s12 );
+ move32();
+ im[sx * i + sx * 5 * dim1] = L_sub( s11, s13 );
+ move32();
+ re[sx * i + sx * 6 * dim1] = L_add( s04, s06 );
+ move32();
+ im[sx * i + sx * 6 * dim1] = L_add( s05, s07 );
+ move32();
+ re[sx * i + sx * 7 * dim1] = L_sub( s08, s14 );
+ move32();
+ im[sx * i + sx * 7 * dim1] = L_sub( s09, s15 );
+ move32();
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------*
+ * BASOP_cfft()
+ *
+ * Complex valued FFT
+ *-----------------------------------------------------------------*/
+
+void BASOP_cfft(
+ Word32 *re, /* i/o: real part */
+ Word32 *im, /* i/o: imag part */
+ Word16 s, /* i : stride real and imag part */
+ Word16 *scale /* i : scalefactor */
+)
+{
+ Word32 x[2 * 64];
+
+ /* FFT for len = FDNS_NPTS */
+ BASOP_fftN2( re, im, RotVector_256, 8, 8, s, 8, x, 64 );
+ s = add( *scale, SCALEFACTOR64 );
+
+ *scale = s;
+ move16();
+
+ return;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/fft_cldfb.c b/lib_com/fft_cldfb.c
new file mode 100644
index 0000000000000000000000000000000000000000..0ea848abdbba069cd73569df5054e417386a65fa
--- /dev/null
+++ b/lib_com/fft_cldfb.c
@@ -0,0 +1,1223 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "prot.h"
+#include "ivas_cnst.h"
+#include "wmc_auto.h"
+
+#if __STDC_VERSION__ >= 199901L
+#if defined __ICL
+#define restrict __restrict
+#endif
+#else
+#define restrict
+#endif
+
+
+static void fft8( float *vec );
+static void fft10( float *vec );
+static void fft16( float *vec );
+static void fft20( float *vec );
+static void fft30( float *vec );
+static void fft5s( float *x, const int16_t stride );
+
+
+#define COS_PI_DIV8 9.238795325112867e-1f
+#define COS_3PI_DIV8 3.826834323650898e-1f
+#define SQRT2PLUS1 2.414213562373095f
+#define SQRT2MINUS1 4.142135623730952e-1f
+
+
+/*******************************************************************************
+ Functionname: fft8
+ *******************************************************************************
+
+ Description: 8-point FFT. Complex-valued input takes 52 real additions
+ and 4 real multiplications.
+
+ Arguments: vec - pointer to data (interleaved real / imaginary parts)
+
+ Return: none
+
+*******************************************************************************/
+static void fft8( float *restrict vec )
+{
+ float temp1[16];
+ float temp2[16];
+
+
+ /* Pre-additions */
+ temp1[0] = vec[0] + vec[8];
+ temp1[2] = vec[0] - vec[8];
+ temp1[1] = vec[1] + vec[9];
+ temp1[3] = vec[1] - vec[9];
+ temp1[4] = vec[2] + vec[10];
+ temp1[6] = vec[2] - vec[10];
+ temp1[5] = vec[3] + vec[11];
+ temp1[7] = vec[3] - vec[11];
+ temp1[8] = vec[4] + vec[12];
+ temp1[10] = vec[4] - vec[12];
+ temp1[9] = vec[5] + vec[13];
+ temp1[11] = vec[5] - vec[13];
+ temp1[12] = vec[6] + vec[14];
+ temp1[14] = vec[6] - vec[14];
+ temp1[13] = vec[7] + vec[15];
+ temp1[15] = vec[7] - vec[15];
+
+ /* Pre-additions and core multiplications */
+ temp2[0] = temp1[0] + temp1[8];
+ temp2[4] = temp1[0] - temp1[8];
+ temp2[1] = temp1[1] + temp1[9];
+ temp2[5] = temp1[1] - temp1[9];
+ temp2[8] = temp1[2] - temp1[11];
+ temp2[10] = temp1[2] + temp1[11];
+ temp2[9] = temp1[3] + temp1[10];
+ temp2[11] = temp1[3] - temp1[10];
+ temp2[2] = temp1[4] + temp1[12];
+ temp2[7] = temp1[4] - temp1[12];
+ temp2[3] = temp1[5] + temp1[13];
+ temp2[6] = temp1[13] - temp1[5];
+
+ temp1[1] = temp1[6] + temp1[14];
+ temp1[2] = temp1[6] - temp1[14];
+ temp1[0] = temp1[7] + temp1[15];
+ temp1[3] = temp1[7] - temp1[15];
+
+ temp2[12] = ( temp1[0] + temp1[2] ) * INV_SQRT2;
+ temp2[14] = ( temp1[0] - temp1[2] ) * INV_SQRT2;
+ temp2[13] = ( temp1[3] - temp1[1] ) * INV_SQRT2;
+ temp2[15] = ( temp1[1] + temp1[3] ) * -INV_SQRT2;
+
+ /* Post-additions */
+ vec[0] = temp2[0] + temp2[2];
+ vec[8] = temp2[0] - temp2[2];
+ vec[1] = temp2[1] + temp2[3];
+ vec[9] = temp2[1] - temp2[3];
+ vec[4] = temp2[4] - temp2[6];
+ vec[12] = temp2[4] + temp2[6];
+ vec[5] = temp2[5] - temp2[7];
+ vec[13] = temp2[5] + temp2[7];
+ vec[6] = temp2[8] + temp2[14];
+ vec[14] = temp2[8] - temp2[14];
+ vec[7] = temp2[9] + temp2[15];
+ vec[15] = temp2[9] - temp2[15];
+ vec[2] = temp2[10] + temp2[12];
+ vec[10] = temp2[10] - temp2[12];
+ vec[3] = temp2[11] + temp2[13];
+ vec[11] = temp2[11] - temp2[13];
+
+ return;
+}
+
+
+/*******************************************************************************
+ Functionname: fft16
+ *******************************************************************************
+
+ Description: 16-point FFT. Complex-valued input takes 144 real additions and
+ 24 real multiplications.
+
+ Arguments: vec - pointer to data (interleaved real / imaginary parts)
+
+ Return: none
+
+*******************************************************************************/
+/* fast implementation, completely unrolled and inlined */
+static void fft16( float *restrict vec )
+{
+ float temp10, temp11, temp12, temp13, temp14, temp15, temp16, temp17,
+ temp18, temp19, temp110, temp111, temp112, temp113, temp114, temp115;
+ float temp20, temp21, temp22, temp23, temp24, temp25, temp26, temp27,
+ temp28, temp29, temp210, temp211, temp212, temp213, temp214, temp215;
+ float vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7,
+ vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15;
+
+
+ /* even */
+ vec0 = vec[0] + vec[16];
+ vec1 = vec[1] + vec[17];
+ vec2 = vec[2] + vec[18];
+ vec3 = vec[3] + vec[19];
+ vec4 = vec[4] + vec[20];
+ vec5 = vec[5] + vec[21];
+ vec6 = vec[6] + vec[22];
+ vec7 = vec[7] + vec[23];
+ vec8 = vec[8] + vec[24];
+ vec9 = vec[9] + vec[25];
+ vec10 = vec[10] + vec[26];
+ vec11 = vec[11] + vec[27];
+ vec12 = vec[12] + vec[28];
+ vec13 = vec[13] + vec[29];
+ vec14 = vec[14] + vec[30];
+ vec15 = vec[15] + vec[31];
+
+ /* Pre-additions */
+ temp10 = vec0 + vec8;
+ temp12 = vec0 - vec8;
+ temp11 = vec1 + vec9;
+ temp13 = vec1 - vec9;
+ temp14 = vec2 + vec10;
+ temp16 = vec2 - vec10;
+ temp15 = vec3 + vec11;
+ temp17 = vec3 - vec11;
+ temp18 = vec4 + vec12;
+ temp110 = vec4 - vec12;
+ temp19 = vec5 + vec13;
+ temp111 = vec5 - vec13;
+ temp112 = vec6 + vec14;
+ temp114 = vec6 - vec14;
+ temp113 = vec7 + vec15;
+ temp115 = vec7 - vec15;
+
+ /* Pre-additions and core multiplications */
+ temp20 = temp10 + temp18;
+ temp24 = temp10 - temp18;
+ temp21 = temp11 + temp19;
+ temp25 = temp11 - temp19;
+ temp28 = temp12 - temp111;
+ temp210 = temp12 + temp111;
+ temp29 = temp13 + temp110;
+ temp211 = temp13 - temp110;
+ temp22 = temp14 + temp112;
+ temp27 = temp14 - temp112;
+ temp23 = temp15 + temp113;
+ temp26 = temp113 - temp15;
+
+ temp11 = temp16 + temp114;
+ temp12 = temp16 - temp114;
+ temp10 = temp17 + temp115;
+ temp13 = temp17 - temp115;
+
+ temp212 = ( temp10 + temp12 ) * INV_SQRT2;
+ temp214 = ( temp10 - temp12 ) * INV_SQRT2;
+ temp213 = ( temp13 - temp11 ) * INV_SQRT2;
+ temp215 = ( temp11 + temp13 ) * -INV_SQRT2;
+
+
+ /* odd */
+ vec0 = vec[0] - vec[16];
+ vec1 = vec[1] - vec[17];
+ vec2 = vec[2] - vec[18];
+ vec3 = vec[3] - vec[19];
+ vec4 = vec[4] - vec[20];
+ vec5 = vec[5] - vec[21];
+ vec6 = vec[6] - vec[22];
+ vec7 = vec[7] - vec[23];
+ vec8 = vec[8] - vec[24];
+ vec9 = vec[9] - vec[25];
+ vec10 = vec[10] - vec[26];
+ vec11 = vec[11] - vec[27];
+ vec12 = vec[12] - vec[28];
+ vec13 = vec[13] - vec[29];
+ vec14 = vec[14] - vec[30];
+ vec15 = vec[15] - vec[31];
+
+ /* Pre-additions and core multiplications */
+ temp19 = ( vec2 + vec14 ) * -COS_3PI_DIV8;
+ temp110 = ( vec2 - vec14 ) * COS_PI_DIV8;
+ temp18 = ( vec3 + vec15 ) * COS_3PI_DIV8;
+ temp111 = ( vec3 - vec15 ) * COS_PI_DIV8;
+ temp15 = ( vec4 + vec12 ) * -INV_SQRT2;
+ temp16 = ( vec4 - vec12 ) * INV_SQRT2;
+ temp14 = ( vec5 + vec13 ) * INV_SQRT2;
+ temp17 = ( vec5 - vec13 ) * INV_SQRT2;
+ temp113 = ( vec6 + vec10 ) * -COS_PI_DIV8;
+ temp114 = ( vec6 - vec10 ) * COS_3PI_DIV8;
+ temp112 = ( vec7 + vec11 ) * COS_PI_DIV8;
+ temp115 = ( vec7 - vec11 ) * COS_3PI_DIV8;
+
+ /* Core multiplications */
+ vec2 = temp18 * SQRT2PLUS1 - temp112 * SQRT2MINUS1;
+ vec3 = temp19 * SQRT2PLUS1 - temp113 * SQRT2MINUS1;
+ vec4 = temp110 * SQRT2MINUS1 - temp114 * SQRT2PLUS1;
+ vec5 = temp111 * SQRT2MINUS1 - temp115 * SQRT2PLUS1;
+
+ /* Post-additions */
+ temp18 += temp112;
+ temp19 += temp113;
+ temp110 += temp114;
+ temp111 += temp115;
+
+ vec6 = vec0 + temp14;
+ vec10 = vec0 - temp14;
+ vec7 = vec1 + temp15;
+ vec11 = vec1 - temp15;
+
+ vec12 = temp16 - vec9;
+ vec14 = temp16 + vec9;
+ vec13 = vec8 + temp17;
+ vec15 = vec8 - temp17;
+
+ temp10 = vec6 - vec14;
+ temp12 = vec6 + vec14;
+ temp11 = vec7 + vec15;
+ temp13 = vec7 - vec15;
+ temp14 = vec10 + vec12;
+ temp16 = vec10 - vec12;
+ temp15 = vec11 + vec13;
+ temp17 = vec11 - vec13;
+
+ vec10 = temp18 + temp110;
+ temp110 = temp18 - temp110;
+ vec11 = temp19 + temp111;
+ temp111 = temp19 - temp111;
+
+ temp112 = vec2 + vec4;
+ temp114 = vec2 - vec4;
+ temp113 = vec3 + vec5;
+ temp115 = vec3 - vec5;
+
+
+ /* Post-additions */
+ *vec++ = temp20 + temp22;
+ *vec++ = temp21 + temp23;
+ *vec++ = temp12 + vec10;
+ *vec++ = temp13 + vec11;
+ *vec++ = temp210 + temp212;
+ *vec++ = temp211 + temp213;
+ *vec++ = temp10 + temp112;
+ *vec++ = temp11 + temp113;
+ *vec++ = temp24 - temp26;
+ *vec++ = temp25 - temp27;
+ *vec++ = temp16 + temp114;
+ *vec++ = temp17 + temp115;
+ *vec++ = temp28 + temp214;
+ *vec++ = temp29 + temp215;
+ *vec++ = temp14 + temp110;
+ *vec++ = temp15 + temp111;
+ *vec++ = temp20 - temp22;
+ *vec++ = temp21 - temp23;
+ *vec++ = temp12 - vec10;
+ *vec++ = temp13 - vec11;
+ *vec++ = temp210 - temp212;
+ *vec++ = temp211 - temp213;
+ *vec++ = temp10 - temp112;
+ *vec++ = temp11 - temp113;
+ *vec++ = temp24 + temp26;
+ *vec++ = temp25 + temp27;
+ *vec++ = temp16 - temp114;
+ *vec++ = temp17 - temp115;
+ *vec++ = temp28 - temp214;
+ *vec++ = temp29 - temp215;
+ *vec++ = temp14 - temp110;
+ *vec++ = temp15 - temp111;
+
+ return;
+}
+
+
+/*******************************************************************************
+ Functionname: fft15
+ *******************************************************************************
+
+ Description: 15-point FFT. Complex-valued input takes 176 real additions
+ and 34 real multiplications.
+
+ Arguments: vec - pointer to data (interleaved real / imaginary parts)
+
+ Return: none
+
+*******************************************************************************/
+static void fft15( float *restrict vec )
+{
+
+ float r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17;
+ float i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17;
+ float tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9,
+ tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17, tmp18, tmp19,
+ tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27, tmp28, tmp29;
+
+
+ /* Pre-additions real part */
+ r1 = vec[2] + vec[8];
+ r2 = vec[2] - vec[8];
+ r3 = vec[4] + vec[16];
+ r4 = vec[4] - vec[16];
+ r5 = vec[6] + vec[24];
+ r6 = vec[6] - vec[24];
+ r7 = vec[10] + vec[20];
+ r8 = vec[10] - vec[20];
+ r9 = vec[12] + vec[18];
+ r10 = vec[12] - vec[18];
+ r11 = vec[14] + vec[26];
+ r12 = vec[14] - vec[26];
+ r13 = vec[22] + vec[28];
+ r14 = vec[22] - vec[28];
+
+ tmp2 = r1 + r3;
+ tmp4 = r1 - r3;
+ tmp6 = r2 + r14;
+ tmp8 = r2 - r14;
+ tmp10 = r4 + r12;
+ tmp12 = r4 - r12;
+ tmp14 = r5 + r9;
+ tmp16 = r5 - r9;
+ tmp18 = r11 + r13;
+ tmp20 = r11 - r13;
+
+ /* Pre-additions imaginary part */
+ i1 = vec[3] + vec[9];
+ i2 = vec[3] - vec[9];
+ i3 = vec[5] + vec[17];
+ i4 = vec[5] - vec[17];
+ i5 = vec[7] + vec[25];
+ i6 = vec[7] - vec[25];
+ i7 = vec[11] + vec[21];
+ i8 = vec[11] - vec[21];
+ i9 = vec[13] + vec[19];
+ i10 = vec[13] - vec[19];
+ i11 = vec[15] + vec[27];
+ i12 = vec[15] - vec[27];
+ i13 = vec[23] + vec[29];
+ i14 = vec[23] - vec[29];
+
+ tmp3 = i1 + i3;
+ tmp5 = i1 - i3;
+ tmp7 = i2 + i14;
+ tmp9 = i2 - i14;
+ tmp11 = i4 + i12;
+ tmp13 = i4 - i12;
+ tmp15 = i5 + i9;
+ tmp17 = i5 - i9;
+ tmp19 = i11 + i13;
+ tmp21 = i11 - i13;
+
+
+ /* Pre-additions and core multiplications */
+ tmp28 = tmp4 + tmp20;
+ tmp29 = tmp5 + tmp21;
+ r4 = tmp2 + tmp18;
+ i4 = tmp3 + tmp19;
+ r3 = ( r4 + tmp14 ) * -1.25f;
+ i3 = ( i4 + tmp15 ) * -1.25f;
+ r2 = ( tmp29 - i8 ) * -8.660254037844387e-1f;
+ i2 = ( tmp28 - r8 ) * 8.660254037844387e-1f;
+ r1 = r4 + r7;
+ i1 = i4 + i7;
+ r0 = r1 + vec[0] + tmp14;
+ i0 = i1 + vec[1] + tmp15;
+ r7 = tmp4 - tmp20;
+ i7 = tmp5 - tmp21;
+ r8 = ( tmp3 - tmp19 ) * -4.841229182759272e-1f;
+ i8 = ( tmp2 - tmp18 ) * 4.841229182759272e-1f;
+ tmp0 = tmp6 + r10;
+ tmp1 = tmp7 + i10;
+ tmp2 = r6 - tmp10;
+ tmp3 = i6 - tmp11;
+ r10 = tmp7 * -2.308262652881440f;
+ i10 = tmp6 * 2.308262652881440f;
+ r11 = tmp8 * 1.332676064001459f;
+ i11 = tmp9 * 1.332676064001459f;
+ r6 = ( r7 - tmp16 ) * 5.590169943749475e-1f;
+ i6 = ( i7 - tmp17 ) * 5.590169943749475e-1f;
+ r12 = ( tmp1 + tmp3 ) * 5.877852522924733e-1f;
+ i12 = ( tmp0 + tmp2 ) * -5.877852522924733e-1f;
+ r13 = ( tmp7 - tmp11 ) * -8.816778784387098e-1f;
+ i13 = ( tmp6 - tmp10 ) * 8.816778784387098e-1f;
+ r14 = ( tmp8 + tmp12 ) * 5.090369604551274e-1f;
+ i14 = ( tmp9 + tmp13 ) * 5.090369604551274e-1f;
+ r16 = tmp11 * 5.449068960040204e-1f;
+ i16 = tmp10 * -5.449068960040204e-1f;
+ r17 = tmp12 * 3.146021430912046e-1f;
+ i17 = tmp13 * 3.146021430912046e-1f;
+
+ r4 *= 1.875f;
+ i4 *= 1.875f;
+ r1 *= -1.5f;
+ i1 *= -1.5f;
+ r7 *= -8.385254915624212e-1f;
+ i7 *= -8.385254915624212e-1f;
+ r5 = tmp29 * 1.082531754730548f;
+ i5 = tmp28 * -1.082531754730548f;
+ r9 = tmp1 * 1.538841768587627f;
+ i9 = tmp0 * -1.538841768587627f;
+ r15 = tmp3 * 3.632712640026803e-1f;
+ i15 = tmp2 * -3.632712640026803e-1f;
+
+
+ /* Post-additions real part */
+ tmp2 = r0 + r1;
+ tmp4 = r3 + r6;
+ tmp6 = r3 - r6;
+ tmp8 = r4 + r5;
+ tmp10 = r4 - r5;
+ tmp12 = r7 + r8;
+ tmp14 = r7 - r8;
+ tmp16 = r13 + r16;
+ tmp18 = r14 + r17;
+ tmp20 = r10 - r13;
+ tmp22 = r11 - r14;
+ tmp24 = r12 + r15;
+ tmp26 = r12 - r9;
+
+ r1 = tmp2 + r2;
+ r2 = tmp2 - r2;
+ r3 = tmp4 + tmp26;
+ r4 = tmp4 - tmp26;
+ r5 = tmp6 + tmp24;
+ r6 = tmp6 - tmp24;
+ r7 = tmp16 + tmp18;
+ r8 = tmp16 - tmp18;
+ r9 = tmp20 - tmp22;
+ r10 = tmp20 + tmp22;
+ r11 = r1 + tmp8;
+ r12 = r2 + tmp10;
+ r13 = r11 - tmp12;
+ r14 = r12 - tmp14;
+ r15 = r12 + tmp14;
+ r16 = r11 + tmp12;
+
+ /* Post-additions imaginary part */
+ tmp3 = i0 + i1;
+ tmp5 = i3 + i6;
+ tmp7 = i3 - i6;
+ tmp9 = i4 + i5;
+ tmp11 = i4 - i5;
+ tmp13 = i7 + i8;
+ tmp15 = i7 - i8;
+ tmp17 = i13 + i16;
+ tmp19 = i14 + i17;
+ tmp21 = i10 - i13;
+ tmp23 = i11 - i14;
+ tmp25 = i12 + i15;
+ tmp27 = i12 - i9;
+
+ i1 = tmp3 + i2;
+ i2 = tmp3 - i2;
+ i3 = tmp5 + tmp27;
+ i4 = tmp5 - tmp27;
+ i5 = tmp7 + tmp25;
+ i6 = tmp7 - tmp25;
+ i7 = tmp17 + tmp19;
+ i8 = tmp17 - tmp19;
+ i9 = tmp21 - tmp23;
+ i10 = tmp21 + tmp23;
+ i11 = i1 + tmp9;
+ i12 = i2 + tmp11;
+ i13 = i11 - tmp13;
+ i14 = i12 - tmp15;
+ i15 = i12 + tmp15;
+ i16 = i11 + tmp13;
+
+ *vec++ = r0;
+ *vec++ = i0;
+ *vec++ = r13 + r5 + r7;
+ *vec++ = i13 + i5 + i7;
+ *vec++ = r15 + r3 - r9;
+ *vec++ = i15 + i3 - i9;
+ *vec++ = r0 + r4;
+ *vec++ = i0 + i4;
+ *vec++ = r13 + r6 - r7;
+ *vec++ = i13 + i6 - i7;
+ *vec++ = r2;
+ *vec++ = i2;
+ *vec++ = r0 + r5;
+ *vec++ = i0 + i5;
+ *vec++ = r16 + r3 - r10;
+ *vec++ = i16 + i3 - i10;
+ *vec++ = r15 + r4 + r9;
+ *vec++ = i15 + i4 + i9;
+ *vec++ = r0 + r6;
+ *vec++ = i0 + i6;
+ *vec++ = r1;
+ *vec++ = i1;
+ *vec++ = r14 + r5 + r8;
+ *vec++ = i14 + i5 + i8;
+ *vec++ = r0 + r3;
+ *vec++ = i0 + i3;
+ *vec++ = r16 + r4 + r10;
+ *vec++ = i16 + i4 + i10;
+ *vec++ = r14 + r6 - r8;
+ *vec++ = i14 + i6 - i8;
+
+ return;
+}
+
+/*******************************************************************************
+ Functionname: fft5s
+ *******************************************************************************
+
+ Description: 5-point FFT.
+
+ Arguments: x - pointer to input data (interleaved real / imaginary parts)
+ stride - stride for input data
+
+ Return: none
+
+*******************************************************************************/
+static const float C51 = 0.9510565162951535f;
+static const float C52 = -1.5388417685876270f;
+static const float C53 = -0.3632712640026803f;
+static const float C54 = 0.5590169943749475f;
+static const float C55 = -1.25f;
+
+static void fft5s( float *x, const int16_t stride )
+{
+ float r1, r2, r3, r4;
+ float s1, s2, s3, s4;
+ float t;
+ /* real part */
+ r1 = x[1 * stride] + x[4 * stride];
+ r4 = x[1 * stride] - x[4 * stride];
+ r3 = x[2 * stride] + x[3 * stride];
+ r2 = x[2 * stride] - x[3 * stride];
+ t = ( r1 - r3 ) * C54;
+ r1 = r1 + r3;
+ x[0] = x[0] + r1;
+ r1 = x[0] + ( r1 * C55 );
+ r3 = r1 - t;
+ r1 = r1 + t;
+ t = ( r4 + r2 ) * C51;
+ r4 = t + ( r4 * C52 );
+ r2 = t + ( r2 * C53 );
+
+ /* imaginary part */
+ s1 = x[1 * stride + 1] + x[4 * stride + 1];
+ s4 = x[1 * stride + 1] - x[4 * stride + 1];
+ s3 = x[2 * stride + 1] + x[3 * stride + 1];
+ s2 = x[2 * stride + 1] - x[3 * stride + 1];
+ t = ( s1 - s3 ) * C54;
+ s1 = s1 + s3;
+ x[1] = x[1] + s1;
+ s1 = x[1] + ( s1 * C55 );
+ s3 = s1 - t;
+ s1 = s1 + t;
+ t = ( s4 + s2 ) * C51;
+ s4 = t + ( s4 * C52 );
+ s2 = t + ( s2 * C53 );
+
+ /* combination */
+ x[1 * stride] = r1 + s2;
+ x[4 * stride] = r1 - s2;
+ x[2 * stride] = r3 - s4;
+ x[3 * stride] = r3 + s4;
+
+ x[1 * stride + 1] = s1 - r2;
+ x[4 * stride + 1] = s1 + r2;
+ x[2 * stride + 1] = s3 + r4;
+ x[3 * stride + 1] = s3 - r4;
+}
+
+
+/**
+ * \brief Function performs a complex 10-point FFT
+ * The FFT is performed inplace. The result of the FFT
+ * is scaled by SCALEFACTOR10 bits.
+ *
+ * WOPS FLC version: 1093 cycles
+ * WOPS with 32x16 bit multiplications: 196 cycles
+ *
+ * \param [i/o] re real input / output
+ * \param [i/o] im imag input / output
+ * \param [i ] s stride real and imag input / output
+ *
+ * \return void
+ */
+static void fft10( float *restrict vec )
+{
+ float t;
+ float r1, r2, r3, r4;
+ float s1, s2, s3, s4;
+ float y00, y01, y02, y03, y04, y05, y06, y07, y08, y09;
+ float y10, y11, y12, y13, y14, y15, y16, y17, y18, y19;
+
+ /* 2 fft5 stages */
+
+ /* real part */
+ r1 = vec[12] + vec[8];
+ r4 = vec[12] - vec[8];
+ r3 = vec[4] + vec[16];
+ r2 = vec[4] - vec[16];
+ t = ( r1 - r3 ) * C54;
+ r1 = r1 + r3;
+ y00 = vec[0] + r1;
+ r1 = y00 + ( r1 * C55 );
+ r3 = r1 - t;
+ r1 = r1 + t;
+ t = ( r4 + r2 ) * C51;
+ r4 = t + ( r4 * C52 );
+ r2 = t + ( r2 * C53 );
+
+ /* imaginary part */
+ s1 = vec[13] + vec[9];
+ s4 = vec[13] - vec[9];
+ s3 = vec[5] + vec[17];
+ s2 = vec[5] - vec[17];
+ t = ( s1 - s3 ) * C54;
+ s1 = s1 + s3;
+ y01 = vec[1] + s1;
+ s1 = y01 + ( s1 * C55 );
+ s3 = s1 - t;
+ s1 = s1 + t;
+ t = ( s4 + s2 ) * C51;
+ s4 = t + ( s4 * C52 );
+ s2 = t + ( s2 * C53 );
+
+ /* combination */
+ y04 = r1 + s2;
+ y16 = r1 - s2;
+ y08 = r3 - s4;
+ y12 = r3 + s4;
+ y05 = s1 - r2;
+ y17 = s1 + r2;
+ y09 = s3 + r4;
+ y13 = s3 - r4;
+
+ /* real part */
+ r1 = vec[2] + vec[18];
+ r4 = vec[2] - vec[18];
+ r3 = vec[14] + vec[6];
+ r2 = vec[14] - vec[6];
+ t = ( r1 - r3 ) * C54;
+ r1 = r1 + r3;
+ y02 = vec[10] + r1;
+ r1 = y02 + ( r1 * C55 );
+ r3 = r1 - t;
+ r1 = r1 + t;
+ t = ( r4 + r2 ) * C51;
+ r4 = t + ( r4 * C52 );
+ r2 = t + ( r2 * C53 );
+
+ /* imaginary part */
+ s1 = vec[3] + vec[19];
+ s4 = vec[3] - vec[19];
+ s3 = vec[15] + vec[7];
+ s2 = vec[15] - vec[7];
+ t = ( s1 - s3 ) * C54;
+ s1 = s1 + s3;
+ y03 = vec[11] + s1;
+ s1 = y03 + ( s1 * C55 );
+ s3 = s1 - t;
+ s1 = s1 + t;
+ t = ( s4 + s2 ) * C51;
+ s4 = t + ( s4 * C52 );
+ s2 = t + ( s2 * C53 );
+
+ /* combination */
+ y06 = r1 + s2;
+ y18 = r1 - s2;
+ y10 = r3 - s4;
+ y14 = r3 + s4;
+ y07 = s1 - r2;
+ y19 = s1 + r2;
+ y11 = s3 + r4;
+ y15 = s3 - r4;
+
+ /* 5 fft2 stages */
+ vec[0] = y00 + y02;
+ vec[1] = y01 + y03;
+ vec[2] = y12 - y14;
+ vec[3] = y13 - y15;
+ vec[4] = y04 + y06;
+ vec[5] = y05 + y07;
+ vec[6] = y16 - y18;
+ vec[7] = y17 - y19;
+ vec[8] = y08 + y10;
+ vec[9] = y09 + y11;
+ vec[10] = y00 - y02;
+ vec[11] = y01 - y03;
+ vec[12] = y12 + y14;
+ vec[13] = y13 + y15;
+ vec[14] = y04 - y06;
+ vec[15] = y05 - y07;
+ vec[16] = y16 + y18;
+ vec[17] = y17 + y19;
+ vec[18] = y08 - y10;
+ vec[19] = y09 - y11;
+
+ return;
+}
+
+/**
+ * \brief Function performs a complex 20-point FFT
+ * The FFT is performed inplace. The result of the FFT
+ * is scaled by SCALEFACTOR20 bits.
+ *
+ * WOPS FLC version: 1509 cycles
+ * WOPS with 32x16 bit multiplications: 432 cycles
+ *
+ * \param [i/o] re real input / output
+ * \param [i/o] im imag input / output
+ * \param [i ] s stride real and imag input / output
+ *
+ * \return void
+ */
+static void fft20( float *signal )
+{
+ const int16_t s = 2;
+ float *re = signal, *im = signal + 1;
+ float r1, r2, r3, r4;
+ float s1, s2, s3, s4;
+ float x0, x1, x2, x3, x4;
+ float t, t0, t1, t2, t3, t4, t5, t6, t7;
+ float y00, y01, y02, y03, y04, y05, y06, y07, y08, y09;
+ float y10, y11, y12, y13, y14, y15, y16, y17, y18, y19;
+ float y20, y21, y22, y23, y24, y25, y26, y27, y28, y29;
+ float y30, y31, y32, y33, y34, y35, y36, y37, y38, y39;
+
+ /* 1. FFT5 stage */
+
+ /* real part */
+ x0 = re[s * 0];
+ x1 = re[s * 16];
+ x2 = re[s * 12];
+ x3 = re[s * 8];
+ x4 = re[s * 4];
+ r1 = x1 + x4;
+ r4 = x1 - x4;
+ r3 = x2 + x3;
+ r2 = x2 - x3;
+ t = ( r1 - r3 ) * C54;
+ r1 = r1 + r3;
+ y00 = x0 + r1;
+ r1 = y00 + ( r1 * C55 );
+ r3 = r1 - t;
+ r1 = r1 + t;
+ t = ( r4 + r2 ) * C51;
+ r4 = t + ( r4 * C52 );
+ r2 = t + ( r2 * C53 );
+
+ /* imaginary part */
+ x0 = im[s * 0];
+ x1 = im[s * 16];
+ x2 = im[s * 12];
+ x3 = im[s * 8];
+ x4 = im[s * 4];
+ s1 = x1 + x4;
+ s4 = x1 - x4;
+ s3 = x2 + x3;
+ s2 = x2 - x3;
+ t = ( s1 - s3 ) * C54;
+ s1 = ( s1 + s3 );
+ y01 = ( x0 + s1 );
+ s1 = y01 + ( s1 * C55 );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( s4 + s2 ) * C51;
+ s4 = t + ( s4 * C52 );
+ s2 = t + ( s2 * C53 );
+
+ /* combination */
+ y08 = ( r1 + s2 );
+ y32 = ( r1 - s2 );
+ y16 = ( r3 - s4 );
+ y24 = ( r3 + s4 );
+
+ y09 = ( s1 - r2 );
+ y33 = ( s1 + r2 );
+ y17 = ( s3 + r4 );
+ y25 = ( s3 - r4 );
+
+ /* 2. FFT5 stage */
+
+ /* real part */
+ x0 = re[s * 5];
+ x1 = re[s * 1];
+ x2 = re[s * 17];
+ x3 = re[s * 13];
+ x4 = re[s * 9];
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x2 + x3 );
+ r2 = ( x2 - x3 );
+ t = ( r1 - r3 ) * C54;
+ r1 = ( r1 + r3 );
+ y02 = ( x0 + r1 );
+ r1 = y02 + ( r1 * C55 );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( r4 + r2 ) * C51;
+ r4 = t + ( r4 * C52 );
+ r2 = t + ( r2 * C53 );
+
+ /* imaginary part */
+ x0 = im[s * 5];
+ x1 = im[s * 1];
+ x2 = im[s * 17];
+ x3 = im[s * 13];
+ x4 = im[s * 9];
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x2 + x3 );
+ s2 = ( x2 - x3 );
+ t = ( s1 - s3 ) * C54;
+ s1 = ( s1 + s3 );
+ y03 = ( x0 + s1 );
+ s1 = y03 + ( s1 * C55 );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( s4 + s2 ) * C51;
+ s4 = t + ( s4 * C52 );
+ s2 = t + ( s2 * C53 );
+
+ /* combination */
+ y10 = ( r1 + s2 );
+ y34 = ( r1 - s2 );
+ y18 = ( r3 - s4 );
+ y26 = ( r3 + s4 );
+
+ y11 = ( s1 - r2 );
+ y35 = ( s1 + r2 );
+ y19 = ( s3 + r4 );
+ y27 = ( s3 - r4 );
+
+ /* 3. FFT5 stage */
+
+ /* real part */
+ x0 = re[s * 10];
+ x1 = re[s * 6];
+ x2 = re[s * 2];
+ x3 = re[s * 18];
+ x4 = re[s * 14];
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x2 + x3 );
+ r2 = ( x2 - x3 );
+ t = ( r1 - r3 ) * C54;
+ r1 = ( r1 + r3 );
+ y04 = ( x0 + r1 );
+ r1 = y04 + ( r1 * C55 );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( r4 + r2 ) * C51;
+ r4 = t + ( r4 * C52 );
+ r2 = t + ( r2 * C53 );
+
+ /* imaginary part */
+ x0 = im[s * 10];
+ x1 = im[s * 6];
+ x2 = im[s * 2];
+ x3 = im[s * 18];
+ x4 = im[s * 14];
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x2 + x3 );
+ s2 = ( x2 - x3 );
+ t = ( s1 - s3 ) * C54;
+ s1 = ( s1 + s3 );
+ y05 = ( x0 + s1 );
+ s1 = y05 + ( s1 * C55 );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( s4 + s2 ) * C51;
+ s4 = t + ( s4 * C52 );
+ s2 = t + ( s2 * C53 );
+
+ /* combination */
+ y12 = ( r1 + s2 );
+ y36 = ( r1 - s2 );
+ y20 = ( r3 - s4 );
+ y28 = ( r3 + s4 );
+
+ y13 = ( s1 - r2 );
+ y37 = ( s1 + r2 );
+ y21 = ( s3 + r4 );
+ y29 = ( s3 - r4 );
+
+ /* 4. FFT5 stage */
+
+ /* real part */
+ x0 = re[s * 15];
+ x1 = re[s * 11];
+ x2 = re[s * 7];
+ x3 = re[s * 3];
+ x4 = re[s * 19];
+ r1 = ( x1 + x4 );
+ r4 = ( x1 - x4 );
+ r3 = ( x2 + x3 );
+ r2 = ( x2 - x3 );
+ t = ( r1 - r3 ) * C54;
+ r1 = ( r1 + r3 );
+ y06 = ( x0 + r1 );
+ r1 = y06 + ( r1 * C55 );
+ r3 = ( r1 - t );
+ r1 = ( r1 + t );
+ t = ( r4 + r2 ) * C51;
+ r4 = t + ( r4 * C52 );
+ r2 = t + ( r2 * C53 );
+
+ /* imaginary part */
+ x0 = im[s * 15];
+ x1 = im[s * 11];
+ x2 = im[s * 7];
+ x3 = im[s * 3];
+ x4 = im[s * 19];
+ s1 = ( x1 + x4 );
+ s4 = ( x1 - x4 );
+ s3 = ( x2 + x3 );
+ s2 = ( x2 - x3 );
+ t = ( s1 - s3 ) * C54;
+ s1 = ( s1 + s3 );
+ y07 = ( x0 + s1 );
+ s1 = y07 + ( s1 * C55 );
+ s3 = ( s1 - t );
+ s1 = ( s1 + t );
+ t = ( s4 + s2 ) * C51;
+ s4 = t + ( s4 * C52 );
+ s2 = t + ( s2 * C53 );
+
+ /* combination */
+ y14 = ( r1 + s2 );
+ y38 = ( r1 - s2 );
+ y22 = ( r3 - s4 );
+ y30 = ( r3 + s4 );
+
+ y15 = ( s1 - r2 );
+ y39 = ( s1 + r2 );
+ y23 = ( s3 + r4 );
+ y31 = ( s3 - r4 );
+
+
+ /* 1. FFT4 stage */
+
+ /* Pre-additions */
+ t0 = ( y00 + y04 );
+ t2 = ( y00 - y04 );
+ t1 = ( y01 + y05 );
+ t3 = ( y01 - y05 );
+ t4 = ( y02 + y06 );
+ t7 = ( y02 - y06 );
+ t5 = ( y07 + y03 );
+ t6 = ( y07 - y03 );
+
+ /* Post-additions */
+ re[s * 0] = ( t0 + t4 );
+ im[s * 0] = ( t1 + t5 );
+ re[s * 5] = ( t2 - t6 );
+ im[s * 5] = ( t3 - t7 );
+ re[s * 10] = ( t0 - t4 );
+ im[s * 10] = ( t1 - t5 );
+ re[s * 15] = ( t2 + t6 );
+ im[s * 15] = ( t3 + t7 );
+
+ /* 2. FFT4 stage */
+
+ /* Pre-additions */
+ t0 = ( y08 + y12 );
+ t2 = ( y08 - y12 );
+ t1 = ( y09 + y13 );
+ t3 = ( y09 - y13 );
+ t4 = ( y10 + y14 );
+ t7 = ( y10 - y14 );
+ t5 = ( y15 + y11 );
+ t6 = ( y15 - y11 );
+
+ /* Post-additions */
+ re[s * 4] = ( t0 + t4 );
+ im[s * 4] = ( t1 + t5 );
+ re[s * 9] = ( t2 - t6 );
+ im[s * 9] = ( t3 - t7 );
+ re[s * 14] = ( t0 - t4 );
+ im[s * 14] = ( t1 - t5 );
+ re[s * 19] = ( t2 + t6 );
+ im[s * 19] = ( t3 + t7 );
+
+
+ /* 3. FFT4 stage */
+
+ /* Pre-additions */
+ t0 = ( y16 + y20 );
+ t2 = ( y16 - y20 );
+ t1 = ( y17 + y21 );
+ t3 = ( y17 - y21 );
+ t4 = ( y18 + y22 );
+ t7 = ( y18 - y22 );
+ t5 = ( y23 + y19 );
+ t6 = ( y23 - y19 );
+
+ /* Post-additions */
+ re[s * 8] = ( t0 + t4 );
+ im[s * 8] = ( t1 + t5 );
+ re[s * 13] = ( t2 - t6 );
+ im[s * 13] = ( t3 - t7 );
+ re[s * 18] = ( t0 - t4 );
+ im[s * 18] = ( t1 - t5 );
+ re[s * 3] = ( t2 + t6 );
+ im[s * 3] = ( t3 + t7 );
+
+ /* 4. FFT4 stage */
+
+ /* Pre-additions */
+ t0 = ( y24 + y28 );
+ t2 = ( y24 - y28 );
+ t1 = ( y25 + y29 );
+ t3 = ( y25 - y29 );
+ t4 = ( y26 + y30 );
+ t7 = ( y26 - y30 );
+ t5 = ( y31 + y27 );
+ t6 = ( y31 - y27 );
+
+ /* Post-additions */
+ re[s * 12] = ( t0 + t4 );
+ im[s * 12] = ( t1 + t5 );
+ re[s * 17] = ( t2 - t6 );
+ im[s * 17] = ( t3 - t7 );
+ re[s * 2] = ( t0 - t4 );
+ im[s * 2] = ( t1 - t5 );
+ re[s * 7] = ( t2 + t6 );
+ im[s * 7] = ( t3 + t7 );
+
+ /* 5. FFT4 stage */
+
+ /* Pre-additions */
+ t0 = ( y32 + y36 );
+ t2 = ( y32 - y36 );
+ t1 = ( y33 + y37 );
+ t3 = ( y33 - y37 );
+ t4 = ( y34 + y38 );
+ t7 = ( y34 - y38 );
+ t5 = ( y39 + y35 );
+ t6 = ( y39 - y35 );
+
+ /* Post-additions */
+ re[s * 16] = ( t0 + t4 );
+ im[s * 16] = ( t1 + t5 );
+ re[s * 1] = ( t2 - t6 );
+ im[s * 1] = ( t3 - t7 );
+ re[s * 6] = ( t0 - t4 );
+ im[s * 6] = ( t1 - t5 );
+ re[s * 11] = ( t2 + t6 );
+ im[s * 11] = ( t3 + t7 );
+
+ return;
+}
+
+/*******************************************************************************
+ Functionname: fft30
+ *******************************************************************************
+
+ Description: 30-point FFT.
+
+ Arguments: in - pointer to data (interleaved real / imaginary parts)
+
+ Return: none
+
+*******************************************************************************/
+
+static void fft30( float *restrict in )
+{
+ int16_t i;
+ float temp[60];
+ float *temp_l = temp;
+ float *temp_lu = temp + 2 * 8;
+ float *temp_h = temp + 2 * 15;
+ float *temp_hu = temp + 2 * 15 + 2 * 8;
+ float *in_l = in + 2 * 0;
+ float *in_h = in + 2 * 15;
+ for ( i = 0; i < 7; i++ )
+ {
+ *temp_l++ = *in_l++;
+ *temp_l++ = *in_l++;
+ *temp_h++ = *in_h++;
+ *temp_h++ = *in_h++;
+ *temp_l++ = *in_h++;
+ *temp_l++ = *in_h++;
+ *temp_h++ = *in_l++;
+ *temp_h++ = *in_l++;
+ }
+ *temp_l++ = *in_l++;
+ *temp_l++ = *in_l++;
+ *temp_h++ = *in_h++;
+ *temp_h++ = *in_h++;
+ temp_l = temp;
+ temp_h = temp + 30;
+ fft15( temp_l );
+ fft15( temp_h );
+
+ in_l = in + 2 * 0;
+ in_h = in + 2 * 15;
+ for ( i = 0; i < 7; i++ )
+ {
+ *in_l++ = *temp_l + *temp_h;
+ *in_h++ = *temp_l++ - *temp_h++;
+ *in_l++ = *temp_l + *temp_h;
+ *in_h++ = *temp_l++ - *temp_h++;
+
+ *in_h++ = *temp_lu + *temp_hu;
+ *in_l++ = *temp_lu++ - *temp_hu++;
+ *in_h++ = *temp_lu + *temp_hu;
+ *in_l++ = *temp_lu++ - *temp_hu++;
+ }
+ *in_l++ = *temp_l + *temp_h;
+ *in_h++ = *temp_l++ - *temp_h++;
+ *in_l++ = *temp_l + *temp_h;
+ *in_h++ = *temp_l++ - *temp_h++;
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * fft_cldfb()
+ *
+ * Interface functions FFT subroutines
+ *--------------------------------------------------------------------*/
+void fft_cldfb(
+ float *data, /* i/o: input/output vector */
+ const int16_t size /* size of fft operation */
+)
+{
+
+ switch ( size )
+ {
+ case 5:
+ fft5s( data, 2 );
+ break;
+ case 8:
+ fft8( data );
+ break;
+ case 10:
+ fft10( data );
+ break;
+ case 16:
+ fft16( data );
+ break;
+ case 20:
+ fft20( data );
+ break;
+ case 30:
+ fft30( data );
+ break;
+
+ default:
+ assert( 0 );
+ break;
+ }
+
+ return;
+}
diff --git a/lib_com/fft_rel.c b/lib_com/fft_rel.c
new file mode 100644
index 0000000000000000000000000000000000000000..e45736be8c0144dd9f84f22a3bd83ea9b8ac169d
--- /dev/null
+++ b/lib_com/fft_rel.c
@@ -0,0 +1,300 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * Local constants
+ *---------------------------------------------------------------------*/
+
+#define N_MAX_FFT 1024
+#define N_MAX_DIV2 ( N_MAX_FFT >> 1 )
+#define N_MAX_DIV4 ( N_MAX_DIV2 >> 1 )
+
+/*---------------------------------------------------------------------*
+ * fft_rel()
+ *
+ * Computes the split-radix FFT in place for the real-valued
+ * signal x of length n. The algorithm has been ported from
+ * the Fortran code of [1].
+ *
+ * The function needs sine and cosine tables t_sin and t_cos,
+ * and the constant N_MAX_FFT. The table entries are defined as
+ * sin(2*pi*i) and cos(2*pi*i) for i = 0, 1, ..., N_MAX_FFT-1. The
+ * implementation assumes that any entry will not be needed
+ * outside the tables. Therefore, N_MAX_FFT and n must be properly
+ * set. The function has been tested with the values n = 16,
+ * 32, 64, 128, 256, and N_MAX_FFT = 1280.
+ *
+ * References
+ * [1] H.V. Sorensen, D.L. Jones, M.T. Heideman, C.S. Burrus,
+ * "Real-valued fast Fourier transform algorithm," IEEE
+ * Trans. on Signal Processing, Vol.35, No.6, pp 849-863,
+ * 1987.
+ *
+ * OUTPUT
+ * x[0:n-1] Transform coeffients in the order re[0], re[1],
+ * ..., re[n/2], im[n/2-1], ..., im[1].
+ *---------------------------------------------------------------------*/
+
+void fft_rel(
+ float x[], /* i/o: input/output vector */
+ const int16_t n, /* i : vector length */
+ const int16_t m /* i : log2 of vector length */
+)
+{
+ int16_t i, j, k, n1, n2, n4;
+ int16_t step;
+ float xt, t1, t2;
+ float *x0, *x1, *x2;
+ float *xi2, *xi3, *xi4, *xi1;
+ const float *s, *c;
+ const int16_t *idx;
+
+ /* !!!! NMAX = 256 is hardcoded here (similar optimizations should be done for NMAX > 256) !!! */
+
+ float *x2even, *x2odd;
+ float temp[512];
+
+ if ( n == 128 || n == 256 || n == 512 )
+ {
+ idx = fft256_read_indexes;
+
+ /* Combined Digit reverse counter & Length two butterflies */
+ if ( n == 128 )
+ {
+ x2 = temp;
+ for ( i = 0; i < 64; i++ )
+ {
+ j = *idx++;
+ k = *idx++;
+
+ *x2++ = x[j >> 1] + x[k >> 1];
+ *x2++ = x[j >> 1] - x[k >> 1];
+ }
+ }
+ else if ( n == 256 )
+ {
+ x2 = temp;
+ for ( i = 0; i < 128; i++ )
+ {
+ j = *idx++;
+ k = *idx++;
+
+ *x2++ = x[j] + x[k];
+ *x2++ = x[j] - x[k];
+ }
+ }
+ else if ( n == 512 )
+ {
+ x2even = temp;
+ x2odd = temp + 256;
+
+ for ( i = 0; i < 128; i++ )
+ {
+ j = 2 * *idx++;
+ k = 2 * *idx++;
+
+ *x2even++ = x[j] + x[k];
+ *x2even++ = x[j] - x[k];
+ *x2odd++ = x[++j] + x[++k];
+ *x2odd++ = x[j] - x[k];
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * 1st Stage Loop has been Unrolled because n4 is '1' and that
+ * allows the elimination of the 'for_ (j = 1; j < n4; j++)' loop
+ * and the associated pointers initialization.
+ * Also, it allows to Put the Data from 'temp' back into 'x' due
+ * to the previous Combined Digit Reverse and Length two butterflies
+ *-----------------------------------------------------------------*/
+
+ /*for_ (k = 2; k < 3; k++)*/
+ {
+ x0 = temp;
+ x1 = x0 + 2;
+ x2 = x;
+
+ for ( i = 0; i < n; i += 4 )
+ {
+ *x2++ = *x0++ + *x1; /* x[i] = xt + x[i+n2]; */
+ *x2++ = *x0;
+ *x2++ = *--x0 - *x1++; /* x[i+n2] = xt - x[i+n2]; */
+ *x2++ = -*x1; /* x[i+n2+n4] = -x[i+n2+n4]; */
+
+ x0 += 4;
+ x1 += 3; /* x1 has already advanced */
+ }
+ }
+ }
+ else
+ {
+ /*-----------------------------------------------------------------*
+ * Digit reverse counter
+ *-----------------------------------------------------------------*/
+
+ j = 0;
+ x0 = &x[0];
+ for ( i = 0; i < n - 1; i++ )
+ {
+ if ( i < j )
+ {
+ xt = x[j];
+ x[j] = *x0;
+ *x0 = xt;
+ }
+ x0++;
+ k = n / 2;
+ while ( k <= j )
+ {
+ j -= k;
+ k = k >> 1;
+ }
+ j += k;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Length two butterflies
+ *-----------------------------------------------------------------*/
+
+ x0 = &x[0];
+ x1 = &x[1];
+ for ( i = 0; i < n / 2; i++ )
+ {
+ *x1 = *x0 - *x1;
+ *x0 = *x0 * 2 - *x1;
+
+ x0++;
+ x0++;
+ x1++;
+ x1++;
+ }
+
+ /*-----------------------------------------------------------------*
+ * 1st Stage Loop has been Unrolled because n4 is '1' and that
+ * allows the elimination of the 'for_ (j = 1; j < n4; j++)' loop
+ * and the associated pointers initialization.
+ *-----------------------------------------------------------------*/
+
+ /* for_ (k = 2; k < 3; k++) */
+ {
+ x0 = x;
+ x1 = x0 + 2;
+
+ for ( i = 0; i < n; i += 4 )
+ {
+ *x1 = *x0 - *x1; /* x[i+n2] = xt - x[i+n2]; */
+ *x0 = *x0 * 2 - *x1++; /* x[i] = xt + x[i+n2]; */
+ *x1 = -*x1; /* x[i+n2+n4] = -x[i+n2+n4]; */
+
+ x0 += 4;
+ x1 += 3; /* x1 has already advanced */
+ }
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Other butterflies
+ *
+ * The implementation described in [1] has been changed by using
+ * table lookup for evaluating sine and cosine functions. The
+ * variable ind and its increment step are needed to access table
+ * entries. Note that this implementation assumes n4 to be so
+ * small that ind will never exceed the table. Thus the input
+ * argument n and the constant N_MAX_FFT must be set properly.
+ *-----------------------------------------------------------------*/
+
+ n4 = 1;
+ n2 = 2;
+ n1 = 4;
+
+ step = N_MAX_DIV4;
+
+ for ( k = 3; k <= m; k++ )
+ {
+ step >>= 1;
+ n4 <<= 1;
+ n2 <<= 1;
+ n1 <<= 1;
+
+ x0 = x;
+ x1 = x0 + n2;
+ x2 = x1 + n4;
+
+ for ( i = 0; i < n; i += n1 )
+ {
+ *x1 = *x0 - *x1; /* x[i+n2] = xt - x[i+n2]; */
+ *x0 = *x0 * 2 - *x1; /* x[i] = xt + x[i+n2]; */
+ *x2 = -*x2; /* x[i+n2+n4] = -x[i+n2+n4]; */
+
+ s = sincos_t_ext;
+ c = s + N_MAX_FFT / 4; /* 1024/4 = 256, 256/4=64 */
+ xi1 = x0;
+ xi3 = xi1 + n2;
+ xi2 = xi3;
+ x0 += n1;
+ xi4 = x0;
+
+ for ( j = 1; j < n4; j++ )
+ {
+ xi3++;
+ xi1++;
+ xi4--;
+ xi2--;
+ c += step;
+ s += step; /* autoincrement by ar0 */
+
+ t1 = *xi3 * *c + *xi4 * *s; /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */
+ t2 = *xi3 * *s - *xi4 * *c; /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */
+
+ *xi4 = *xi2 - t2;
+ *xi2 = *xi1 - t1;
+ *xi1 = *xi1 * 2 - *xi2;
+ *xi3 = -2 * t2 - *xi4;
+ }
+
+ x1 += n1;
+ x2 += n1;
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/fill_spectrum.c b/lib_com/fill_spectrum.c
new file mode 100644
index 0000000000000000000000000000000000000000..93d4cd572dccee762a71807a0d10d5d2442524e2
--- /dev/null
+++ b/lib_com/fill_spectrum.c
@@ -0,0 +1,266 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * fill_spectrum()
+ *
+ * Apply spectral filling by
+ * - filling zero-bit bands below BWE region
+ * - applying BWE above transition frequency
+ *--------------------------------------------------------------------------*/
+
+void fill_spectrum(
+ float *coeff, /* i/o: normalized MLT spectrum / nf spectrum */
+ int16_t *R, /* i : number of pulses per band */
+ const int16_t is_transient, /* i : transient flag */
+ int16_t norm[], /* i : quantization indices for norms */
+ const float *hq_generic_fenv, /* i : HQ GENERIC envelope */
+ const int16_t hq_generic_offset, /* i : HQ GENERIC offset */
+ const int16_t nf_idx, /* i : noise fill index */
+ const int16_t length, /* i : Length of spectrum (32 or 48 kHz) */
+ const float env_stab, /* i : Envelope stability measure [0..1] */
+ int16_t *no_att_hangover, /* i/o: Frame counter for attenuation hangover */
+ float *energy_lt, /* i/o: Long-term energy measure for transient detection */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ const int16_t hq_generic_exc_clas, /* i : HQ generic hf excitation class */
+ const int16_t core_sfm, /* i : index of the end band for core */
+ int16_t HQ_mode, /* i : HQ mode */
+ float noise_level[], /* i : noise levels for harmonic modes */
+ int32_t core_brate, /* i : target bitrate */
+ float prev_noise_level[], /* i/o: noise factor in previous frame */
+ int16_t *prev_R, /* i/o: bit allocation info. in previous frame */
+ float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */
+ const int16_t *peak_idx, /* i : HVQ peak indices */
+ const int16_t Npeaks, /* i : Number of HVQ peaks */
+ const int16_t *npulses, /* i : Number of assigned pulses per band */
+ int16_t prev_is_transient, /* i : previous transient flag */
+ float *prev_normq, /* i : previous norms */
+ float *prev_env, /* i : previous noise envelopes */
+ int16_t prev_bfi, /* i : previous bad frame indicator */
+ const int16_t *sfmsize, /* i : Length of bands */
+ const int16_t *sfm_start, /* i : Start of bands */
+ const int16_t *sfm_end, /* i : End of bands */
+ int16_t *prev_L_swb_norm, /* i/o: last normalize length for harmonic mode */
+ int16_t prev_hq_mode, /* i : previous HQ mode */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int16_t num_env_bands, /* i : Number of envelope bands */
+ const int16_t element_mode /* i : element mode */
+)
+{
+ float CodeBook[L_SPEC48k_EXT];
+ int16_t cb_size = 0;
+ int16_t last_sfm;
+ float CodeBook_mod[L_SPEC48k_EXT];
+ float norm_adj[NB_SFM];
+ int16_t high_sfm = 23;
+ int16_t flag_32K_env_hangover;
+ int16_t bin_th = 0;
+ int16_t peak_pos[L_HARMONIC_EXC];
+ int16_t bwe_peaks[L_FRAME48k];
+ float normq_v[NB_SFM];
+ float coeff_fine[L_SPEC48k_EXT];
+ float coeff_out[L_SPEC48k_EXT];
+
+ set_s( peak_pos, 0, L_HARMONIC_EXC );
+ set_s( bwe_peaks, 0, L_FRAME48k );
+ set_f( norm_adj, 1.0f, num_sfm );
+ set_f( coeff_out, 0.0f, L_FRAME48k );
+
+ if ( HQ_mode == HQ_TRANSIENT )
+ {
+ last_sfm = num_sfm - 1;
+ }
+ else if ( HQ_mode == HQ_GEN_SWB || HQ_mode == HQ_GEN_FB )
+ {
+ last_sfm = max( core_sfm, num_env_bands - 1 );
+ }
+ else
+ {
+ last_sfm = core_sfm;
+ }
+
+ if ( HQ_mode == HQ_HARMONIC )
+ {
+ high_sfm = ( core_brate < HQ_BWE_CROSSOVER_BRATE ) ? HVQ_THRES_SFM_24k - 1 : HVQ_THRES_SFM_32k - 1;
+
+ if ( last_sfm < high_sfm )
+ {
+ last_sfm = high_sfm;
+ }
+ }
+ else if ( HQ_mode == HQ_HVQ )
+ {
+ bin_th = sfm_end[last_sfm];
+ }
+
+ /* Transient analysis for envelope stability measure */
+ if ( length == L_FRAME32k )
+ {
+ env_stab_transient_detect( is_transient, length, norm, no_att_hangover, energy_lt, HQ_mode, bin_th, coeff );
+ }
+
+ if ( length == L_FRAME16k || ( ( length == L_FRAME32k && HQ_mode != HQ_HARMONIC && HQ_mode != HQ_HVQ ) && *no_att_hangover == 0 ) )
+ {
+ /* Norm adjustment function */
+ env_adj( npulses, length, last_sfm, norm_adj, env_stab, sfmsize );
+ }
+
+ flag_32K_env_hangover = ( length == L_FRAME32k && ( ( env_stab < 0.5f && *no_att_hangover == 0 ) || HQ_mode == HQ_HVQ ) );
+
+ /*----------------------------------------------------------------*
+ * Build noise-fill codebook
+ *----------------------------------------------------------------*/
+
+ if ( HQ_mode != HQ_HVQ )
+ {
+ cb_size = build_nf_codebook( flag_32K_env_hangover, coeff, sfm_start, sfmsize, sfm_end, last_sfm, R, CodeBook, CodeBook_mod );
+ }
+
+ /*----------------------------------------------------------------*
+ * Prepare fine structure for Harmonic and HVQ
+ *----------------------------------------------------------------*/
+
+ if ( HQ_mode == HQ_HARMONIC )
+ {
+ harm_bwe_fine( R, last_sfm, high_sfm, num_sfm, norm, sfm_start, sfm_end, prev_L_swb_norm, coeff, coeff_out, coeff_fine );
+ }
+ else if ( HQ_mode == HQ_HVQ )
+ {
+ hvq_bwe_fine( last_sfm, num_sfm, sfm_end, peak_idx, Npeaks, peak_pos, prev_L_swb_norm, coeff, bwe_peaks, coeff_fine );
+ }
+
+ /*----------------------------------------------------------------*
+ * Apply noise-fill
+ *----------------------------------------------------------------*/
+
+ if ( HQ_mode != HQ_HVQ && cb_size > 0 )
+ {
+ apply_noisefill_HQ( R, length, flag_32K_env_hangover, core_brate, last_sfm, CodeBook, CodeBook_mod, cb_size, sfm_start, sfm_end, sfmsize, coeff );
+ }
+
+ /*----------------------------------------------------------------*
+ * Normal mode BWE
+ *----------------------------------------------------------------*/
+
+ if ( HQ_mode == HQ_NORMAL )
+ {
+ hq_fold_bwe( last_sfm, sfm_end, num_sfm, coeff );
+ }
+
+ /*----------------------------------------------------------------*
+ * Apply noise-fill adjustment
+ *----------------------------------------------------------------*/
+
+ if ( ( length >= L_FRAME32k || core_brate > HQ_32k || core_brate < HQ_24k40 ) && HQ_mode != HQ_HVQ )
+ {
+ apply_nf_gain( nf_idx, last_sfm, R, sfm_start, sfm_end, coeff );
+ }
+
+ /*----------------------------------------------------------------*
+ * Prepare fine strucutre for HQ GENERIC
+ *----------------------------------------------------------------*/
+ if ( HQ_mode == HQ_GEN_SWB || HQ_mode == HQ_GEN_FB )
+ {
+ hq_generic_fine( coeff, last_sfm, sfm_start, sfm_end, bwe_seed, coeff_fine );
+ }
+
+ /*----------------------------------------------------------------*
+ * Apply envelope
+ *----------------------------------------------------------------*/
+
+ if ( HQ_mode != HQ_HARMONIC && HQ_mode != HQ_HVQ )
+ {
+ apply_envelope( coeff, norm, norm_adj, num_sfm, last_sfm, HQ_mode, length, sfm_start, sfm_end, normq_v, coeff_out, coeff_fine );
+ }
+
+ /*----------------------------------------------------------------*
+ * Harmonic BWE, HVQ BWE and HQ SWB BWE
+ *----------------------------------------------------------------*/
+
+ if ( HQ_mode == HQ_HARMONIC )
+ {
+ harm_bwe( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, high_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, coeff_out, element_mode );
+ }
+ else if ( HQ_mode == HQ_HVQ )
+ {
+ hvq_bwe( coeff, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, prev_hq_mode, bwe_peaks, bin_th, num_sfm, core_brate, R, norm, noise_level, prev_noise_level, bwe_seed, coeff_out );
+ }
+ else if ( HQ_mode == HQ_GEN_SWB || HQ_mode == HQ_GEN_FB )
+ {
+ hq_generic_bwe( HQ_mode, coeff_fine, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R );
+ }
+
+ /*----------------------------------------------------------------*
+ * HQ WB BWE refinements
+ *----------------------------------------------------------------*/
+
+ if ( length == L_FRAME16k && core_brate <= HQ_32k )
+ {
+ hq_wb_nf_bwe( coeff, is_transient, prev_bfi, normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R, prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, coeff_out );
+ }
+
+ /*----------------------------------------------------------------*
+ * Update memories
+ *----------------------------------------------------------------*/
+
+ if ( HQ_mode != HQ_HARMONIC && HQ_mode != HQ_HVQ )
+ {
+ prev_noise_level[0] = 0.1f;
+ prev_noise_level[1] = 0.1f;
+ }
+ if ( !( length == L_FRAME16k && core_brate <= HQ_32k ) )
+ {
+ set_f( prev_env, 0, SFM_N_WB );
+ set_f( prev_normq, 0, SFM_N_WB );
+ }
+
+ if ( length == L_FRAME32k && core_brate <= HQ_32k )
+ {
+ *prev_R = R[SFM_N_WB - 1];
+ mvr2r( coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE );
+ }
+
+ mvr2r( coeff_out, coeff, length );
+
+ return;
+}
diff --git a/lib_com/findpulse.c b/lib_com/findpulse.c
new file mode 100644
index 0000000000000000000000000000000000000000..3f8321160888350bc6dc7e977d4612aa1941a8dc
--- /dev/null
+++ b/lib_com/findpulse.c
@@ -0,0 +1,140 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "prot.h"
+#include "cnst.h"
+#include "wmc_auto.h"
+
+/*----------------------------------------------------------------------------------*
+ * findpulse()
+ *
+ * Find first pitch pulse in a frame
+ *----------------------------------------------------------------------------------*/
+
+/*! r: pulse position */
+int16_t findpulse(
+ const int16_t L_frame, /* i : length of the frame */
+ const float res[], /* i : residual signal */
+ const int16_t T0, /* i : integer pitch */
+ const int16_t enc_dec, /* i : flag enc/dec, 0 - enc, 1 - dec */
+ int16_t *sign /* i/o: sign of the maximum */
+)
+{
+ const float *ptr;
+ float val, maxval;
+ int16_t i, maxi;
+ float resf[L_FRAME16k]; /* Low pass filtered residual */
+
+ if ( enc_dec == ENC )
+ {
+ /*-----------------------------------------------------------------*
+ * Very simple LP filter
+ *-----------------------------------------------------------------*/
+
+ resf[0] = 0.50f * res[0] + 0.25f * res[1];
+ for ( i = 1; i < L_frame - 1; i++ )
+ {
+ resf[i] = 0.25f * res[i - 1] + 0.5f * res[i] + 0.25f * res[i + 1];
+ }
+ resf[L_frame - 1] = 0.25f * res[L_frame - 2] + 0.50f * res[L_frame - 1];
+
+ /*-----------------------------------------------------------------*
+ * Find "biggest" pulse in the last pitch section
+ *-----------------------------------------------------------------*/
+
+ ptr = resf + L_frame - 1;
+ maxval = 0;
+ maxi = 0;
+ for ( i = 0; i < T0; i++ )
+ {
+ val = (float) fabs( *ptr );
+ if ( val > maxval )
+ {
+ maxval = val;
+ maxi = i;
+ if ( *ptr >= 0 )
+ {
+ *sign = 0;
+ }
+ else
+ {
+ *sign = 1;
+ }
+ }
+ ptr--;
+ }
+ }
+ else
+ {
+ /*-----------------------------------------------------------------*
+ * Find "biggest" pulse in the last pitch section according to the sign
+ *-----------------------------------------------------------------*/
+
+ ptr = res;
+ maxval = 0;
+ maxi = 0;
+
+ if ( *sign == 0 )
+ {
+ for ( i = 1; i <= T0; i++ )
+ {
+ val = *ptr++;
+ if ( val >= maxval )
+ {
+ maxval = val;
+ maxi = i;
+ }
+ }
+ }
+ else
+ {
+ for ( i = 1; i <= T0; i++ )
+ {
+ val = *ptr++;
+ if ( val <= maxval )
+ {
+ maxval = val;
+ maxi = i;
+ }
+ }
+ }
+ }
+
+ return ( maxi );
+}
diff --git a/lib_com/fine_gain_bits.c b/lib_com/fine_gain_bits.c
new file mode 100644
index 0000000000000000000000000000000000000000..5e65b12e4f74787d30e303fdca684e9130c53b73
--- /dev/null
+++ b/lib_com/fine_gain_bits.c
@@ -0,0 +1,128 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "rom_com.h"
+#include "prot.h"
+#include
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------
+ * subband_gain_bits()
+ *
+ * HQ core encoder
+ *--------------------------------------------------------------------------*/
+
+static void subband_gain_bits(
+ const int16_t *Rk, /* i : bit allocation per band (Q3)*/
+ const int16_t N, /* i : number of bands */
+ int16_t *bits, /* o : gain bits per band */
+ const int16_t *sfmsize /* i : Size of bands */
+)
+{
+ int16_t i, b, tot;
+ int16_t bps;
+
+ tot = 0;
+
+ for ( i = 0; i < N; i++ )
+ {
+ bps = ( Rk[i] * fg_inv_tbl_fx[sfmsize[i] >> 3] ) >> 18;
+ if ( ( ( sfmsize[i] * ( bps + 1 ) ) << 3 ) - Rk[i] == 0 )
+ { /* correct approx. division result, to obtain exact integer division output */
+ bps++;
+ }
+ bps = min( 7, bps );
+
+ b = fine_gain_bits[bps];
+ bits[i] = b;
+ tot += b;
+ }
+
+ if ( tot == 0 )
+ {
+ /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */
+ bits[0] = 1;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * assign_gain_bits()
+ *
+ * Assign gain adjustment bits and update bit budget
+ *--------------------------------------------------------------------------*/
+
+/*! r: Number of assigned gain bits */
+int16_t assign_gain_bits(
+ const int16_t core, /* i : HQ core */
+ const int16_t BANDS, /* i : Number of bands */
+ const int16_t *band_width, /* i : Sub band bandwidth */
+ int16_t *Rk, /* i/o: Bit allocation/Adjusted bit alloc. (Q3) */
+ int16_t *gain_bits_array, /* o : Assigned gain bits */
+ int16_t *Rcalc /* o : Bit budget for shape quantizer (Q3) */
+)
+{
+ int16_t gain_bits_tot;
+ int16_t i;
+
+ /* Allocate gain bits for every subband used, based on bitrate and bandwidth */
+ if ( core == HQ_CORE )
+ {
+ subband_gain_bits( Rk, BANDS, gain_bits_array, band_width );
+ }
+ else
+ {
+ set_s( gain_bits_array, 0, BANDS );
+ }
+
+ /* Re-adjust bit budget for gain quantization */
+ gain_bits_tot = 0;
+ *Rcalc = 0;
+ for ( i = 0; i < BANDS; i++ )
+ {
+ if ( Rk[i] > 0 )
+ {
+ Rk[i] -= gain_bits_array[i] * 8;
+ gain_bits_tot += gain_bits_array[i];
+ *Rcalc += Rk[i];
+ }
+ }
+
+ return gain_bits_tot;
+}
diff --git a/lib_com/frame_ener.c b/lib_com/frame_ener.c
new file mode 100644
index 0000000000000000000000000000000000000000..1592c6e9f19f9e89fb5c63365e021d6fbf660da6
--- /dev/null
+++ b/lib_com/frame_ener.c
@@ -0,0 +1,128 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*----------------------------------------------------------------------------------*
+ * fer_energy()
+ *
+ * Estimation of pitch-synchronous (voiced sounds) or half-frame energy
+ *----------------------------------------------------------------------------------*/
+
+void fer_energy(
+ const int16_t L_frame, /* i : frame length */
+ const int16_t clas, /* i : frame classification */
+ const float *synth, /* i : synthesized speech at Fs = 12k8 Hz */
+ const float pitch, /* i : pitch period */
+ float *enr, /* o : pitch-synchronous or half_frame energy */
+ const int16_t offset /* i : speech pointer offset (0 or L_frame) */
+)
+{
+ int16_t len;
+ const float *pt_synth;
+
+ if ( clas == VOICED_CLAS || clas == ONSET || clas == SIN_ONSET ) /* Voiced or Onset current frame */
+ {
+ len = (int16_t) ( pitch + 0.5f ); /* pitch value */
+
+ pt_synth = synth;
+ if ( offset != 0 )
+ {
+ pt_synth = synth + L_frame - len;
+ }
+
+ emaximum( pt_synth, len, enr ); /* pitch synchronous E */
+ }
+ else
+ {
+ pt_synth = synth;
+ if ( offset != 0 )
+ {
+ pt_synth = synth + L_frame / 2;
+ }
+
+ *enr = dotp( pt_synth, pt_synth, L_frame / 2 );
+ *enr /= (float) ( L_frame / 2 );
+ }
+ return;
+}
+
+
+/*------------------------------------------------------------------------*
+ * frame_energy()
+ *
+ * Compute pitch-synchronous energy at the frame end
+ *------------------------------------------------------------------------*/
+
+float frame_energy(
+ const int16_t L_frame, /* i : length of the frame */
+ const float *pitch, /* i : pitch values for each subframe */
+ const float *speech, /* i : pointer to speech signal for E computation */
+ const float lp_speech, /* i : long-term active speech energy average */
+ float *frame_ener /* o : pitch-synchronous energy at frame end */
+)
+{
+ float enern;
+ const float *pt1;
+ int16_t len;
+ float dotProd;
+
+ len = (int16_t) ( 0.5f * ( pitch[2] + pitch[3] ) + 0.5f );
+ if ( len < L_SUBFR )
+ {
+ len *= 2;
+ }
+
+ pt1 = speech + L_frame - len;
+
+ dotProd = dotp( pt1, pt1, len );
+ if ( 0 == dotProd )
+ {
+ *frame_ener = MIN_LOG_VAL_60dB;
+ }
+ else
+ {
+ *frame_ener = 10.0f * (float) log10( dotProd / (float) len );
+ }
+ enern = *frame_ener - lp_speech;
+
+ return enern;
+}
diff --git a/lib_com/get_gain.c b/lib_com/get_gain.c
new file mode 100644
index 0000000000000000000000000000000000000000..94e23a1c6d69e0a6b17b1ba64484e47b1de6315f
--- /dev/null
+++ b/lib_com/get_gain.c
@@ -0,0 +1,71 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*----------------------------------------------------------------------------------*
+ * get_gain()
+ *
+ *
+ *----------------------------------------------------------------------------------*/
+
+/*! r: codebook gain (adaptive or fixed) */
+float get_gain(
+ const float x[], /* i : target signal */
+ const float y[], /* i : filtered codebook excitation */
+ const int16_t n, /* i : segment length */
+ float *en_y /* o : energy of y (sum of y[]^2, optional) */
+)
+{
+ float corr = 0.0f, ener = 1e-6f;
+ int16_t i;
+
+ for ( i = 0; i < n; i++ )
+ {
+ corr += x[i] * y[i];
+ ener += y[i] * y[i];
+ }
+
+ if ( en_y )
+ {
+ *en_y = ener;
+ }
+
+ return ( corr / ener );
+}
diff --git a/lib_com/gs_bitallocation.c b/lib_com/gs_bitallocation.c
new file mode 100644
index 0000000000000000000000000000000000000000..8bbf1d21c6baedec3c40f648b0fda3cef717ebdb
--- /dev/null
+++ b/lib_com/gs_bitallocation.c
@@ -0,0 +1,929 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local function prototypes
+ *-------------------------------------------------------------------*/
+
+static float Find_bit_frac( const int16_t nb_band, const int16_t remaining_bits );
+
+static void reajust_bits( float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, const int16_t bit_bdgt_in );
+
+
+/*-------------------------------------------------------------------*
+ * bands_and_bit_alloc()
+ *
+ * AC mode (GSC) bands and bits allocation
+ *-------------------------------------------------------------------*/
+
+void bands_and_bit_alloc(
+ const int16_t cor_strong_limit, /* i : HF correlation */
+ const int16_t noise_lev, /* i : dwn scaling factor */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/
+ const int16_t bits_used, /* i : Number of bit used before frequency Q */
+ int16_t *bit, /* i/o: Number of bit allowed for frequency quantization */
+ float *Ener_per_bd_iQ, /* i/o: Quantized energy vector */
+ int16_t *max_ener_band, /* o : Sorted order */
+ int16_t *bits_per_bands_s, /* i/o: Number of bit allowed per allowed subband (Q3) */
+ int16_t *nb_subbands, /* o : Number of subband allowed */
+ const float *exc_diff, /* i : Difference signal to quantize (encoder side only) */
+ float *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */
+ int16_t *pvq_len, /* o : Number of bin covered with the PVQ */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t bwidth, /* i : input signal bandwidth */
+ const int16_t GSC_noisy_speech, /* i : GSC noisy speech flag */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */
+)
+{
+ int16_t bandoffset, i, j, nb_bands_max, bit_new_bands, bit_tmp, st_band, nb_bands;
+ float bit_fracf, etmp;
+ float sum_bit;
+ float ener_vec[MBANDS_GN_BITALLOC16k];
+ int16_t nb_tot_bands;
+ int16_t bit_index, bit_index_mem, imax;
+ int16_t pos, band;
+ float SWB_bit_budget;
+ float bits_per_bands[MBANDS_GN_BITALLOC16k];
+ float fzero_val, mp, mb, nb_bands_adj, bit_adj;
+ int16_t nb_pulse_per_band[MBANDS_GN_BITALLOC16k];
+
+ /* initializations */
+ nb_tot_bands = 16;
+ set_f( bits_per_bands, 0.0f, MBANDS_GN_BITALLOC16k );
+
+ if ( L_frame == L_FRAME16k )
+ {
+ nb_tot_bands = MBANDS_GN_BITALLOC16k;
+ }
+
+ /* To adapt current energy band to PVQ freq band for sorting*/
+ ener_vec[0] = Ener_per_bd_iQ[0] + Ener_per_bd_iQ[1];
+ mvr2r( Ener_per_bd_iQ + 1, ener_vec, 15 );
+ ener_vec[15] = ener_vec[14];
+
+ if ( L_frame == L_FRAME16k )
+ {
+ ener_vec[16] = Ener_per_bd_iQ[16];
+ ener_vec[17] = ( Ener_per_bd_iQ[16] + Ener_per_bd_iQ[17] ) * 0.5f;
+ ener_vec[18] = Ener_per_bd_iQ[17];
+ ener_vec[19] = Ener_per_bd_iQ[17] * 0.8f;
+ }
+
+ for ( i = 0; i < nb_tot_bands; i++ )
+ {
+ ener_vec[i] = (float) ( (int16_t) ( ener_vec[i] * 4096.f + 0.5f ) );
+ }
+
+ /*------------------------------------------------------------------------
+ * Determination of the number of bits available to the frequency domain
+ * Allocation of a maximum number of band to be encoded
+ *-----------------------------------------------------------------------*/
+
+ nb_bands_max = nb_tot_bands;
+ bit_new_bands = 5;
+
+ if ( core_brate > ACELP_16k40 && L_frame == L_FRAME16k )
+ {
+ bit_new_bands = 7;
+ }
+
+ i = 0;
+ while ( i < SIZE_BRATE_INTERMED_TBL )
+ {
+ if ( core_brate <= brate_intermed_tbl[i] )
+ {
+ break;
+ }
+
+ if ( brate_intermed_tbl[i] == ACELP_24k40 )
+ {
+ break;
+ }
+
+ i++;
+ }
+
+ if ( element_mode > EVS_MONO && coder_type == AUDIO &&
+ core_brate <= STEREO_GSC_BIT_RATE_ALLOC && 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--;
+ }
+
+ bit_index = BRATE2IDX( brate_intermed_tbl[i] ) * 17;
+
+ bit_index_mem = bit_index;
+
+ if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
+ {
+ if ( core_brate >= ACELP_9k60 )
+ {
+ *bit = (int16_t) ( core_brate * ( 1.0f / FRAMES_PER_SEC ) + 0.5f ) - bits_used - 25;
+ }
+ else
+ {
+ *bit = (int16_t) ( core_brate * ( 1.0f / FRAMES_PER_SEC ) + 0.5f ) - bits_used - 21;
+ }
+
+ nb_tot_bands = 10;
+ }
+ else
+ {
+ *bit = (int16_t) ( core_brate * ( 1.0f / FRAMES_PER_SEC ) + 0.5f ) - bits_used - GSC_freq_bits[bit_index];
+ }
+
+ if ( L_frame == L_FRAME16k )
+ {
+ *bit -= 8;
+ }
+
+ if ( coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT ) /* can happen only for 2nd channel inactive */
+ {
+ *bit += GSC_LRES_NB_NITS;
+ }
+
+ if ( *bit > 0 )
+ {
+ if ( GSC_IVAS_mode > 0 )
+ {
+ SWB_bit_budget = *bit;
+ st_band = 5;
+
+ set_f( bits_per_bands, 0, MBANDS_GN_BITALLOC16k );
+
+ /* 2- Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */
+ bit_fracf = ( -0.125f * Diff_len + 76.0f ) / 100;
+ bit_fracf = check_bounds( bit_fracf, 0.50f, 0.75f );
+
+ /* Adjusment of the bitrate between LF and HF base on the content type */
+ /* 1 = new GSC bit alloc
+ 2 = GSC bit alloc for tc frame
+ 3 = more music like (should not happen often given music is coded with dft) */
+
+ if ( GSC_IVAS_mode <= 3 )
+ {
+ nb_bands_max -= 6;
+ }
+
+ if ( GSC_IVAS_mode == 2 )
+ {
+ bit_fracf += 0.1f;
+ nb_bands_max--;
+ }
+
+ if ( GSC_IVAS_mode == 3 )
+ {
+ bit_fracf -= 0.1f;
+ nb_bands_max += 3;
+ }
+
+ /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/
+ /* Adjust the number of band based on the content type and bitrate */
+ nb_bands_adj = 1.0f;
+ if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG )
+ {
+ nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;
+ }
+ else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG )
+ {
+ nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;
+ }
+ nb_bands_max = (int16_t) ( nb_bands_max * nb_bands_adj + 0.5f );
+ nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands );
+
+ bit_fracf *= SWB_bit_budget;
+
+ /* Estimation of the number of bit used in HF */
+ /* with only the first weigthing The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */
+ mb = .17f * bit_fracf;
+ mp = ( 2.0f * DSR_NB_PULSE );
+ if ( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 )
+ {
+ mp = 1.5f * DSR_NB_PULSE;
+ }
+ else if ( core_brate < GSC_L_RATE_STG )
+ {
+ mp = DSR_NB_PULSE;
+ }
+
+ /* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/
+ /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */
+ /* compute the total possible number of band to be coded */
+ nb_tot_bands = (int16_t) ( ( SWB_bit_budget - bit_fracf ) / ( mp + ( mb - mp ) / 2.0f ) );
+ mp = min( mp, mb );
+ if ( nb_tot_bands + st_band > nb_bands_max )
+ {
+ bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands + st_band - nb_bands_max );
+ bit_adj = max( 0, bit_adj );
+ nb_tot_bands = nb_bands_max - st_band;
+ bit_fracf += bit_adj;
+ }
+ nb_tot_bands += st_band;
+
+ /* Allocate bits to LF */
+ etmp = 0.23f;
+ for ( j = 0; j < st_band; j++ )
+ {
+ i = j;
+ max_ener_band[j] = i;
+ ener_vec[i] = MIN16B;
+ bits_per_bands[j] = etmp * bit_fracf;
+ etmp -= 0.015f;
+ }
+
+ SWB_bit_budget -= bit_fracf;
+
+ /* Find low energy band in HF */
+ set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k );
+ for ( i = st_band + 2; i < nb_tot_bands - 1; i++ )
+ {
+ if ( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] )
+ {
+ nb_pulse_per_band[i] = 1;
+ }
+ }
+ for ( j = st_band; j < nb_tot_bands; j++ )
+ {
+ if ( j > 6 )
+ {
+ i = maximum( ener_vec, nb_tot_bands, &etmp );
+ }
+ else
+ {
+ i = j;
+ }
+
+ max_ener_band[j] = i;
+ ener_vec[i] = MIN16B;
+ }
+
+ /* Recompute the final bit distribution for HF */
+ if ( nb_tot_bands > st_band )
+ {
+ bit_fracf = DSR_NB_PULSE;
+ mb = ( SWB_bit_budget * 2 / ( nb_tot_bands - st_band ) ) - mp;
+ bit_fracf = ( mb - mp ) / ( nb_tot_bands - st_band );
+ mb -= bit_fracf;
+ /* Do the distribution */
+ for ( j = st_band; j < nb_tot_bands; j++ )
+ {
+ if ( nb_pulse_per_band[max_ener_band[j]] > 1 )
+ {
+ bits_per_bands[max_ener_band[j]] = mb;
+ }
+ else
+ {
+ bits_per_bands[max_ener_band[j]] = 4.5f;
+ }
+ mb -= bit_fracf;
+ SWB_bit_budget -= bits_per_bands[max_ener_band[j]];
+ }
+ }
+
+ /* Series of verification in case bit allocated != the budget */
+ if ( SWB_bit_budget > 0 )
+ {
+ i = st_band - 1;
+ while ( SWB_bit_budget > 0 )
+ {
+ bits_per_bands[i]++;
+ SWB_bit_budget--;
+ i--;
+ if ( i == -1 )
+ {
+ i = st_band - 1;
+ }
+ }
+ }
+
+ nb_bands = nb_tot_bands;
+
+ sum_bit = 0;
+ j = 0;
+ for ( i = 0; i < nb_bands; i++ )
+ {
+ if ( bits_per_bands[i] > 112 )
+ {
+ sum_bit += bits_per_bands[i] - 112;
+ bits_per_bands[i] = 112;
+ j = i + 1;
+ }
+
+ /* safety check for overage bit reallocation */
+ else if ( bits_per_bands[i] + sum_bit / 3 > 112 )
+ {
+ j = i + 1;
+ }
+ }
+
+ if ( sum_bit != 0 )
+ {
+ sum_bit /= ( nb_bands - j );
+ for ( i = j; i < nb_bands; i++ )
+ {
+ bits_per_bands[i] += sum_bit;
+ }
+ }
+ }
+ else if ( GSC_noisy_speech )
+ {
+ SWB_bit_budget = *bit;
+ nb_bands = 5;
+
+ fzero_val = 0.0f;
+ if ( element_mode > EVS_MONO )
+ {
+ fzero_val = MIN16B_FLT;
+ }
+
+ if ( coder_type == UNVOICED && element_mode > EVS_MONO )
+ {
+ nb_bands = 3;
+ if ( SWB_bit_budget > 20 )
+ {
+ nb_bands = 5;
+ }
+ }
+ else if ( bwidth < SWB )
+ {
+ nb_bands = 7;
+ }
+
+ st_band = nb_bands;
+
+ set_f( bits_per_bands, 0, MBANDS_GN );
+
+ bit_fracf = Find_bit_frac( nb_bands, (int16_t) SWB_bit_budget ); /* Supplementary bits distributed only on first bands */
+
+ nb_tot_bands = nb_bands_max - 6;
+
+ if ( nb_tot_bands > 16 )
+ {
+ nb_tot_bands = 16;
+ }
+
+ for ( j = 0; j < 2; j++ )
+ {
+ i = j;
+ max_ener_band[j] = i;
+ ener_vec[i] = fzero_val;
+ }
+
+ if ( bwidth < SWB )
+ {
+ if ( coder_type == UNVOICED && element_mode > EVS_MONO )
+ {
+ nb_tot_bands = 5;
+ }
+
+ for ( ; j < nb_bands; j++ )
+ {
+ i = maximum( ener_vec, nb_tot_bands, &etmp );
+ max_ener_band[j] = i;
+ ener_vec[i] = fzero_val;
+ }
+ }
+ else
+ {
+ for ( ; j < nb_bands; j++ )
+ {
+ i = maximum( ener_vec, nb_tot_bands, &etmp );
+ max_ener_band[j] = i;
+ ener_vec[i] = fzero_val;
+ }
+ }
+
+ set_f( bits_per_bands, bit_fracf, nb_bands );
+ }
+ else
+ {
+ bit_index++;
+ bit_tmp = *bit - GSC_freq_bits[bit_index];
+ bit_index++;
+ nb_bands_max += GSC_freq_bits[bit_index];
+ bit_index++;
+
+ *pvq_len = 112;
+ st_band = 7;
+
+ if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 )
+ {
+ *pvq_len = 160;
+ st_band = 10;
+ nb_bands = *pvq_len / 16;
+ bit_tmp -= 35;
+ bit_new_bands = 5;
+ }
+
+ if ( core_brate <= ACELP_9k60 )
+ {
+ *pvq_len = 80;
+ st_band = 5;
+ if ( Diff_len == 0 )
+ {
+ nb_bands_max += 2;
+ bit_tmp -= 13;
+ }
+ }
+ else if ( Diff_len == 0 )
+ {
+ nb_bands_max += 2;
+ bit_tmp -= 17;
+ }
+
+ nb_bands = *pvq_len / 16;
+ nb_bands_max = min( nb_bands_max, MBANDS_GN_BITALLOC16k );
+
+ /*------------------------------------------------------------------------
+ * Adjustement of the maximum number of bands in function of the
+ * dynamics of the spectrum (more or less speech like)
+ *-----------------------------------------------------------------------*/
+
+ if ( coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3 )
+ {
+ /* Probably classification error -> concentrate bits on LF */
+ if ( L_frame == L_FRAME16k && core_brate >= ACELP_24k40 )
+ {
+ nb_bands_max = nb_tot_bands - 2;
+ }
+ else if ( core_brate >= ACELP_16k40 )
+ {
+ nb_bands_max = nb_bands + 2;
+ }
+ else if ( core_brate >= ACELP_8k00 )
+ {
+ nb_bands_max = nb_bands + 1;
+ }
+ else
+ {
+ nb_bands_max = nb_bands;
+ }
+ }
+ else if ( noise_lev >= NOISE_LEVEL_SP2 || ( core_brate <= ACELP_13k20 && core_brate >= ACELP_9k60 && cor_strong_limit == 0 ) ) /* Very low dynamic, tend to speech, do not try to code HF at all */
+ {
+ nb_bands_max -= 2;
+ }
+ else if ( noise_lev >= NOISE_LEVEL_SP1 ) /* Very low dynamic, tend to speech, code less HF */
+ {
+ nb_bands_max -= 1;
+ }
+
+ if ( L_frame == L_FRAME16k )
+ {
+ if ( core_brate < ACELP_24k40 )
+ {
+ nb_bands_max -= 4;
+ }
+ else if ( core_brate < ACELP_32k )
+ {
+ if ( Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2 )
+ {
+ nb_bands_max -= 2;
+ bit_new_bands *= 2;
+ }
+ }
+ else if ( core_brate >= ACELP_32k )
+ {
+ bit_new_bands *= 2;
+ }
+ }
+
+ if ( bwidth == NB && nb_bands_max > 10 )
+ {
+ nb_bands_max = 10;
+ }
+
+ /*------------------------------------------------------------------------
+ * Find extra number of band to code according to bitrate availables
+ *-----------------------------------------------------------------------*/
+
+ while ( bit_tmp >= bit_new_bands && nb_bands <= nb_bands_max - 1 )
+ {
+ bit_tmp -= bit_new_bands;
+ nb_bands++;
+ }
+
+ /*------------------------------------------------------------------------
+ * Fractional bits to distribute on the first x bands
+ *-----------------------------------------------------------------------*/
+
+ if ( L_frame == L_FRAME16k && core_brate > ACELP_32k )
+ {
+ bit_fracf = 0;
+ }
+ else
+ {
+ bit_fracf = Find_bit_frac( st_band, bit_tmp ); /* Supplementary bits distributed only on first bands */
+ }
+
+ /*------------------------------------------------------------------------
+ * Complete the bit allocation per frequency band
+ *-----------------------------------------------------------------------*/
+
+ imax = 5;
+ if ( core_brate > ACELP_9k60 )
+ {
+ imax = 7;
+ }
+
+ for ( i = 0; i < imax; i++ )
+ {
+ bits_per_bands[i] = GSC_freq_bits[bit_index] + bit_fracf;
+ bit_index++;
+ }
+
+ if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 )
+ {
+ bit_index = 0;
+ i = imax - 1;
+ bits_per_bands[i] += Compl_GSC_freq_bits[bit_index];
+ i++;
+ bit_index++;
+
+ for ( ; i < 10; i++ )
+ {
+ bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf;
+ bit_index++;
+ }
+ }
+
+ if ( Diff_len == 0 )
+ {
+ bit_index = bit_index_mem + 10;
+ for ( i = 0; i < 7; i++ )
+ {
+ bits_per_bands[i] += GSC_freq_bits[bit_index];
+ bit_index++;
+ }
+ }
+
+ if ( bit_fracf < 0 )
+ {
+ for ( j = 0; j < nb_tot_bands; j++ )
+ {
+ bits_per_bands[j] = max( bits_per_bands[j], 0 );
+ }
+ }
+
+ /*--------------------------------------------------------------------------
+ * Complete the bit allocation per frequency band for 16kHz high brate mode
+ *--------------------------------------------------------------------------*/
+
+ if ( L_frame == L_FRAME16k && core_brate > ACELP_32k )
+ {
+ for ( j = st_band; j < nb_bands; j++ )
+ {
+ bits_per_bands[j] = bit_new_bands;
+ }
+
+ bit_fracf = ( 1.0f / nb_bands ) * ( bit_tmp );
+
+ etmp = 2.0f * bit_fracf / ( nb_bands + 1 );
+ bit_fracf = etmp;
+ for ( j = nb_bands - 1; j >= 0; j-- )
+ {
+ bits_per_bands[j] += etmp;
+ etmp += bit_fracf;
+ }
+ }
+ else
+ {
+ for ( j = st_band; j < nb_bands; j++ )
+ {
+ bits_per_bands[j] = bit_new_bands;
+ }
+ }
+
+ /*--------------------------------------------------------------------------
+ * Compute a maximum band (band offset) for the search on maximal energy
+ * This is function of the spectral dynamic and the bitrate
+ *--------------------------------------------------------------------------*/
+
+ bandoffset = nb_tot_bands - ( nb_bands + 2 );
+
+ if ( noise_lev <= NOISE_LEVEL_SP1a )
+ {
+ bandoffset--;
+ }
+ else if ( ( core_brate <= ACELP_13k20 && ( coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3 ) ) || ( core_brate <= ACELP_13k20 && core_brate >= ACELP_9k60 && cor_strong_limit == 0 ) )
+ {
+ bandoffset++;
+ }
+
+ if ( bandoffset < 0 )
+ {
+ bandoffset = 0;
+ }
+
+ /*--------------------------------------------------------------------------
+ * Initiazed sorted vector
+ * For the first x bands to be included in th final sorted vector
+ * Sort the remaining bands in decrease energy order
+ *--------------------------------------------------------------------------*/
+
+ for ( j = 0; j < nb_tot_bands; j++ )
+ {
+ max_ener_band[j] = -10;
+ }
+
+ for ( j = 0; j < st_band; j++ )
+ {
+ max_ener_band[j] = j;
+ ener_vec[j] = -10;
+ }
+
+ pos = st_band;
+ for ( ; j < nb_bands; j++ )
+ {
+ i = maximum( ener_vec, nb_tot_bands - bandoffset, &etmp );
+ if ( i > pos )
+ {
+ pos = i;
+ }
+ max_ener_band[j] = i;
+ ener_vec[i] = -10;
+ }
+
+ /* re-allocate bits to the frames such that the highest band with allocated bits is higher than the threshold */
+ if ( nb_tot_bands - bandoffset > nb_bands && ( pos > 7 && core_brate == ACELP_8k00 ) && bwidth == WB )
+ {
+ band = nb_tot_bands - bandoffset - nb_bands;
+ for ( j = 0; j < band; j++ )
+ {
+ i = maximum( ener_vec, nb_tot_bands - bandoffset, &etmp );
+ max_ener_band[nb_bands + j] = i;
+ ener_vec[i] = -10;
+ bits_per_bands[nb_bands + j] = 5;
+ }
+ nb_bands += band;
+
+ bit_tmp = 5 * band;
+ if ( band <= 2 )
+ {
+ for ( j = st_band - 1; j < nb_bands; j++ )
+ {
+ bits_per_bands[j] += 1;
+ }
+ bit_tmp += nb_bands - st_band + 1;
+ }
+
+ i = 0;
+ j = 0;
+ while ( bit_tmp > 0 )
+ {
+ bits_per_bands[j] -= 1;
+
+ if ( j == st_band - 1 - i )
+ {
+ j = 0;
+ }
+ else
+ {
+ ++j;
+ }
+
+ if ( j == 0 && i < st_band - 1 )
+ {
+ i++;
+ }
+
+ bit_tmp -= 1;
+ }
+ }
+
+ /*--------------------------------------------------------------------------
+ * Bit sum verification for GSC inactive at very high rate
+ * The maximum number of bits per band of length 16 is 112
+ * Redistribute the overage bits if needed
+ *--------------------------------------------------------------------------*/
+
+ sum_bit = 0;
+ j = 0;
+ for ( i = 0; i < nb_bands; i++ )
+ {
+ if ( bits_per_bands[i] > 112 )
+ {
+ sum_bit += bits_per_bands[i] - 112;
+ bits_per_bands[i] = 112;
+ j = i + 1;
+ }
+
+ /* safety check for overage bit reallocation */
+ else if ( bits_per_bands[i] + sum_bit / 3 > 112 )
+ {
+ j = i + 1;
+ }
+ }
+
+ if ( sum_bit != 0 )
+ {
+ sum_bit /= ( nb_bands - j );
+ for ( i = j; i < nb_bands; i++ )
+ {
+ bits_per_bands[i] += sum_bit;
+ }
+ }
+ }
+
+ /*--------------------------------------------------------------------------
+ * second step of bit sum verification, normally sum_bit == *bit
+ *--------------------------------------------------------------------------*/
+
+ sum_bit = 0.00f;
+ for ( i = 0; i < nb_bands; i++ )
+ {
+ bits_per_bands[i] = (float) floor( bits_per_bands[i] );
+ sum_bit += bits_per_bands[i];
+ }
+
+ if ( GSC_IVAS_mode != 0 && sum_bit < *bit ) /* If we need to add bits, we are doing it on the LF */
+ {
+ reajust_bits( bits_per_bands, 0, nb_bands, (int16_t) sum_bit, *bit );
+ }
+ else
+ {
+ reajust_bits( bits_per_bands, nb_bands - 1, 0, (int16_t) sum_bit, *bit );
+ }
+
+ /*--------------------------------------------------------------------------
+ * Recompute the real number/length of frequency bands to encode
+ *--------------------------------------------------------------------------*/
+
+ *nb_subbands = nb_bands;
+ *pvq_len = *nb_subbands * 16;
+
+ /*--------------------------------------------------------------------------
+ * Concatenate bands (encoder only)
+ *--------------------------------------------------------------------------*/
+
+ if ( exc_diff != NULL )
+ {
+ for ( j = 0; j < nb_bands; j++ )
+ {
+ mvr2r( exc_diff + max_ener_band[j] * 16, concat_in + j * 16, 16 );
+ }
+ }
+
+ set_s( bits_per_bands_s, 0, nb_tot_bands );
+
+ for ( j = 0; j < nb_bands; j++ )
+ {
+ bits_per_bands_s[j] = ( (int16_t) bits_per_bands[j] ) << 3;
+ }
+ }
+ else /* *bit == 0 */
+ {
+ set_s( bits_per_bands_s, 0, nb_tot_bands );
+ *nb_subbands = 0;
+ *pvq_len = 0;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * reajust_bits()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void reajust_bits(
+ float *bits_per_bands,
+ const int16_t st_band,
+ const int16_t end_band,
+ const int16_t sum_bit_in,
+ const int16_t bit_bdgt_in )
+{
+ int16_t i, amount_to_add, incr;
+ int16_t bit_bdgt, sum_bit;
+
+ incr = 1;
+ if ( end_band < st_band )
+ {
+ incr = -1;
+ }
+
+ if ( bit_bdgt_in < sum_bit_in )
+ {
+ amount_to_add = -1;
+ bit_bdgt = sum_bit_in;
+ sum_bit = bit_bdgt_in;
+ }
+ else
+ {
+ bit_bdgt = bit_bdgt_in;
+ sum_bit = sum_bit_in;
+ amount_to_add = 1;
+ }
+
+ i = st_band;
+ while ( bit_bdgt > sum_bit )
+ {
+ if ( amount_to_add > 0 || ( amount_to_add < 0 && bits_per_bands[i] > 1 ) )
+ {
+ bits_per_bands[i] += amount_to_add;
+ sum_bit += (int16_t) abs( amount_to_add );
+ }
+
+ i += incr;
+ if ( i == end_band )
+ {
+ i = st_band;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * Find_bit_frac()
+ *
+ * Computes the fraction of the remaining bit budget to allocate to the bands
+ *-------------------------------------------------------------------*/
+
+static float Find_bit_frac(
+ const int16_t nb_band,
+ const int16_t remaining_bits )
+{
+ float var_out;
+ int16_t inv_bandQ15;
+ int32_t L_num;
+
+ inv_bandQ15 = 6553;
+ if ( nb_band == 7 )
+ {
+ inv_bandQ15 = 4681;
+ }
+ else if ( nb_band == 3 )
+ {
+ inv_bandQ15 = 10922;
+ }
+ else if ( nb_band == 4 )
+ {
+ inv_bandQ15 = 8192;
+ }
+ else if ( nb_band == 5 )
+ {
+ inv_bandQ15 = 6536;
+ }
+ else if ( nb_band == 10 )
+ {
+ inv_bandQ15 = 3277;
+ }
+ else
+ {
+ inv_bandQ15 = (int16_t) ( ( 1.0f / nb_band ) * 32678 + 0.5f );
+ }
+
+ L_num = inv_bandQ15 * remaining_bits;
+ L_num *= 8;
+ var_out = L_num / 262144.0f;
+
+ return ( var_out );
+}
diff --git a/lib_com/gs_gains.c b/lib_com/gs_gains.c
new file mode 100644
index 0000000000000000000000000000000000000000..72b1ccf357320cf7fbec5a40a0324fb0359302bc
--- /dev/null
+++ b/lib_com/gs_gains.c
@@ -0,0 +1,692 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local function prototypes
+ *-------------------------------------------------------------------*/
+
+static int16_t VDQ_vec( float *Qvec_out, const float *mean_dic, const float *dic, const int16_t index, const int16_t vec_en );
+
+/*-------------------------------------------------------------------*
+ * Comp_and_apply_gain()
+ *
+ * Compute and apply the quantized per band gain
+ *-------------------------------------------------------------------*/
+
+void Comp_and_apply_gain(
+ float exc_diffQ[], /* i/o: Quantized excitation */
+ float Ener_per_bd_iQ[], /* o : Target ener per band */
+ float Ener_per_bd_yQ[], /* o : Ener per band for norm vector */
+ int16_t Mbands_gn, /* i : number of bands */
+ const int16_t ReUseGain /* i : Reuse the gain in Ener_per_bd_yQ */
+)
+{
+ int16_t i, i_band;
+ int16_t StartBin, NB_Qbins;
+ float y_gain;
+
+ /* Recreate excitation for local synthesis and decoder */
+ StartBin = 0;
+ NB_Qbins = 0;
+ for ( i_band = 0; i_band < Mbands_gn; i_band++ )
+ {
+ StartBin += NB_Qbins;
+ NB_Qbins = mfreq_bindiv_loc[i_band];
+ if ( ReUseGain == 1 )
+ {
+ y_gain = Ener_per_bd_yQ[i_band];
+ }
+ else
+ {
+ y_gain = (float) pow( 10, ( Ener_per_bd_iQ[i_band] - Ener_per_bd_yQ[i_band] ) );
+ Ener_per_bd_yQ[i_band] = y_gain;
+ }
+
+ for ( i = StartBin; i < NB_Qbins + StartBin; i++ )
+ {
+ exc_diffQ[i] *= y_gain;
+ }
+ }
+
+ return;
+}
+
+
+/*------------------------------------------------------------------*
+ * Ener_per_band_comp()
+ *
+ * Compute the energy per band in log domain for quantization purposes
+ * Loops are decomposed to accomodate the PVQ quantization
+ *------------------------------------------------------------------*/
+
+void Ener_per_band_comp(
+ const float exc_diff[], /* i : target signal */
+ float y_gain4[], /* o : Energy per band to quantize */
+ const int16_t Mband, /* i : Max band */
+ const int16_t Eflag, /* i : flag of highest band */
+ const int16_t L_frame /* i : frame length */
+)
+{
+ float etmp;
+ const float *pt;
+ int16_t i, j;
+
+ pt = exc_diff;
+ for ( j = 0; j < 2; j++ )
+ {
+ y_gain4[j] = 0;
+ etmp = 0.02f;
+
+ pt = exc_diff + j * 8;
+ for ( i = 0; i < 8; i++ )
+ {
+ etmp += ( *pt * *pt );
+ pt++;
+ }
+
+ /* normalized to 16 bins to easy the quantization */
+ y_gain4[j] = (float) log10( sqrt( 2 * etmp ) );
+ }
+
+ for ( j = 1; j < Mband - 2; j++ )
+ {
+ etmp = 0.01f;
+
+ pt = exc_diff + j * 16;
+ for ( i = 0; i < 16; i++ )
+ {
+ etmp += ( *pt * *pt );
+ pt++;
+ }
+
+ y_gain4[j + 1] = (float) log10( sqrt( etmp ) );
+ }
+
+ if ( Eflag == 1 )
+ {
+ etmp = 0.01f;
+
+ pt = exc_diff + j * 16;
+ for ( i = 0; i < 32; i++ )
+ {
+ etmp += ( *pt * *pt );
+ pt++;
+ }
+
+ y_gain4[j + 1] = (float) log10( sqrt( etmp / 2 ) );
+ }
+
+ if ( L_frame == L_FRAME16k )
+ {
+ etmp = 0.01f;
+
+ for ( i = 0; i < 32; i++ )
+ {
+ etmp += ( *pt * *pt );
+ pt++;
+ }
+
+ y_gain4[j + 2] = (float) log10( sqrt( etmp / 2 ) );
+
+ for ( i = 0; i < 32; i++ )
+ {
+ etmp += ( *pt * *pt );
+ pt++;
+ }
+
+ y_gain4[j + 3] = (float) log10( sqrt( etmp / 2 ) );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * GSC_gain_DQ()
+ *
+ * Form the final vector after gain quantization/Dequantization
+ * Common to both encoder and decoder
+ *-------------------------------------------------------------------*/
+
+static void GSC_gain_DQ(
+ const int16_t element_mode, /* i : element mode */
+ const int16_t enc_dec, /* i : encoder/decoder flag */
+ const int16_t coder_type, /* i : Coder type */
+ const int16_t Mbands_gn, /* i : Number of band */
+ const int32_t core_brate, /* i : Core bitrate */
+ const float mean_g, /* i : Average gain */
+ const float *Gain_in, /* i : Unquantized gain vector */
+ float *Gain_out /* o : Level adjusted unquantized gain vector */
+)
+{
+ float Gain_off;
+ int16_t i;
+
+ /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
+ Gain_off = 0.0f;
+ if ( coder_type == INACTIVE || coder_type == UNVOICED )
+ {
+ if ( core_brate <= ACELP_5k00 && coder_type == UNVOICED )
+ {
+ Gain_off = 9.f;
+ }
+ else if ( core_brate <= ACELP_7k20 )
+ {
+ Gain_off = 8.f; /* 0 dB */
+ }
+ else if ( core_brate <= ACELP_8k00 )
+ {
+ Gain_off = 6.6f; /* ~-3.3 dB */
+ }
+ else if ( core_brate <= ACELP_9k60 )
+ {
+ Gain_off = 4.8f; /* ~-2.4 dB */
+ }
+ else if ( core_brate <= ACELP_11k60 )
+ {
+ Gain_off = 3.5f; /* ~-2.4 dB */
+ }
+ else if ( core_brate <= ACELP_13k20 )
+ {
+ Gain_off = 3.0f; /* ~-2.4 dB */
+ }
+ }
+
+ if ( coder_type != INACTIVE && coder_type != UNVOICED )
+ {
+ for ( i = 0; i < Mbands_gn; i++ )
+ {
+ Gain_out[i] = Gain_in[i] + mean_g;
+ }
+ }
+ else
+ {
+ /*mimic ACELP decay of energy for low rates*/
+ if ( element_mode == EVS_MONO && 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] += mean_g - i * ( Gain_off / 20.f ) / ( (float) Mbands_gn );
+ }
+ }
+ else
+ {
+ for ( i = 0; i < Mbands_gn; i++ )
+ {
+ 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
+ *-------------------------------------------------------------------*/
+
+float gsc_gainQ(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t idchan, /* i : channel ID */
+ const float y_gain4[], /* i : Energy per band */
+ float y_gainQ[], /* o : quantized energy per band */
+ const int32_t core_brate, /* i : Core rate */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t bwidth, /* i : input signal bandwidth */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */
+ const int32_t core_brate_inp /* i : true core bitrate */
+)
+{
+ float y_gain_tmp[MBANDS_GN16k], y_gain_tmp2[MBANDS_GN16k];
+ int16_t i, idx_g = 0;
+ float mean_4g[1], ftmp1;
+ int16_t Mbands_gn = MBANDS_GN;
+ float y_gain_tmp3[MBANDS_GN];
+
+ if ( L_frame == L_FRAME16k )
+ {
+ Mbands_gn = MBANDS_GN16k;
+ }
+
+ mean_4g[0] = 0;
+
+ if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
+ {
+ ftmp1 = mean( y_gain4, 10 ) - 0.6f;
+ for ( i = 0; i < Mbands_gn; i++ )
+ {
+ if ( y_gain4[i] < ftmp1 )
+ {
+ y_gain_tmp2[i] = ftmp1;
+ }
+ else
+ {
+ y_gain_tmp2[i] = y_gain4[i];
+ }
+ }
+
+ /* Quantized mean gain without clipping */
+ mean_4g[0] = mean( y_gain_tmp2, 10 );
+ idx_g = (int16_t) vquant( mean_4g, Gain_meanNB, mean_4g, Gain_mean_dicNB, 1, 64 );
+ push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );
+
+ for ( i = 0; i < Mbands_gn; i++ )
+ {
+ y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0];
+ }
+
+ if ( y_gain_tmp[9] < -0.3f )
+ {
+ y_gain_tmp[9] = -0.3f;
+ }
+
+ set_f( y_gain_tmp + 10, 0.0f, MBANDS_GN - 10 );
+ idx_g = (int16_t) vquant( y_gain_tmp, Mean_dic_NB, y_gain_tmp, Gain_dic1_NB, 3, 64 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
+
+ if ( core_brate < ACELP_9k60 )
+ {
+ idx_g = vquant( y_gain_tmp + 3, Mean_dic_NB + 3, y_gain_tmp + 3, Gain_dic2_NB, 3, 32 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
+
+ idx_g = vquant( y_gain_tmp + 6, Mean_dic_NB + 6, y_gain_tmp + 6, Gain_dic3_NB, 4, 16 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
+ }
+ else
+ {
+ idx_g = vquant( y_gain_tmp + 3, Mean_dic_NB + 3, y_gain_tmp + 3, Gain_dic2_NBHR, 3, 64 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
+
+ idx_g = vquant( y_gain_tmp + 6, Mean_dic_NB + 6, y_gain_tmp + 6, Gain_dic3_NBHR, 4, 128 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
+ }
+
+ if ( 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( y_gain_tmp + 6, 3 );
+ y_gain_tmp[11] = mean( y_gain_tmp + 7, 3 );
+ y_gain_tmp[12] = mean( y_gain_tmp + 8, 3 );
+ y_gain_tmp[13] = mean( y_gain_tmp + 9, 3 );
+ y_gain_tmp[14] = mean( y_gain_tmp + 10, 3 );
+ y_gain_tmp[15] = mean( y_gain_tmp + 11, 3 );
+ }
+ else
+ {
+ set_f( y_gain_tmp + 10, 0, MBANDS_GN - 10 );
+ }
+ }
+ else
+ {
+ ftmp1 = mean( y_gain4, 16 );
+ for ( i = 0; i < Mbands_gn; i++ )
+ {
+ if ( y_gain4[i] < ftmp1 - 0.6f )
+ {
+ y_gain_tmp2[i] = ftmp1 - .6f;
+ }
+ else if ( y_gain4[i] > ftmp1 + 0.6f )
+ {
+ y_gain_tmp2[i] = ftmp1 + 0.6f;
+ }
+ else
+ {
+ y_gain_tmp2[i] = y_gain4[i];
+ }
+ }
+
+ mean_4g[0] = mean( y_gain_tmp2, 16 );
+ idx_g = vquant( mean_4g, mean_m, mean_4g, mean_gain_dic, 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] = y_gain_tmp2[i] - mean_4g[0];
+ }
+
+ if ( 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
+ *--------------------------------------------------------------------------------------*/
+
+ mvr2r( y_gain_tmp, y_gain_tmp2, 8 );
+
+ y_gain_tmp2[8] = y_gain_tmp[8];
+ y_gain_tmp2[9] = y_gain_tmp[10];
+ y_gain_tmp2[10] = y_gain_tmp[12];
+ y_gain_tmp2[11] = y_gain_tmp[14];
+
+ idx_g = 0;
+ idx_g = vquant( y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
+
+ if ( !( coder_type == INACTIVE && tdm_LRTD_flag == 0 && idchan == 1 ) || core_brate_inp > GSC_LRES_GAINQ_LIMIT )
+ {
+ idx_g = vquant( y_gain_tmp2 + 3, YGain_mean_LR + 3, y_gain_tmp2 + 3, YGain_dic2_LR, 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( y_gain_tmp2 + 7, YGain_mean_LR + 7, y_gain_tmp2 + 7, YGain_dic3_LR, 5, 32 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
+
+ set_f( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 );
+
+ /* Update to quantized vector */
+ mvr2r( y_gain_tmp2, y_gain_tmp, 8 );
+
+ mvr2r( y_gain_tmp2 + 8, y_gain_tmp3, 4 );
+ set_f( y_gain_tmp + 8, 0, 8 );
+ fft_rel( y_gain_tmp2 + 8, 4, 2 );
+
+ mvr2r( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 );
+ y_gain_tmp[15] = y_gain_tmp2[11];
+ ifft_rel( y_gain_tmp + 8, 8, 3 );
+
+ for ( i = 8; i < 16; i++ )
+ {
+ y_gain_tmp[i] *= 1.41f;
+ }
+
+ y_gain_tmp[8] = y_gain_tmp3[0];
+ y_gain_tmp[10] = y_gain_tmp3[1];
+ y_gain_tmp[12] = y_gain_tmp3[2];
+ y_gain_tmp[14] = y_gain_tmp3[3];
+ }
+ else
+ {
+ mvr2r( y_gain_tmp2, y_gain_tmp, 3 );
+ set_f( y_gain_tmp + 3, 0.0f, MBANDS_GN16k - 3 );
+ }
+ }
+ else
+ {
+ if ( L_frame == L_FRAME )
+ {
+ idx_g = vquant( y_gain_tmp, YG_mean16, y_gain_tmp, YG_dicMR_1, 4, 64 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
+
+ idx_g = vquant( y_gain_tmp + 4, YG_mean16 + 4, y_gain_tmp + 4, YG_dicMR_2, 4, 32 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
+
+ idx_g = vquant( y_gain_tmp + 8, YG_mean16 + 8, y_gain_tmp + 8, YG_dicMR_3, 4, 32 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
+
+ idx_g = vquant( y_gain_tmp + 12, YG_mean16 + 12, y_gain_tmp + 12, YG_dicMR_4, 4, 16 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
+ }
+ else
+ {
+ idx_g = vquant( y_gain_tmp, YG_mean16HR, y_gain_tmp, YG_dicHR_1, 4, 128 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
+
+ idx_g = vquant( y_gain_tmp + 4, YG_mean16HR + 4, y_gain_tmp + 4, YG_dicHR_2, 4, 64 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
+
+ idx_g = vquant( y_gain_tmp + 8, YG_mean16HR + 8, y_gain_tmp + 8, YG_dicHR_3, 4, 64 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
+
+ idx_g = vquant( y_gain_tmp + 12, YG_mean16HR_16kHz, y_gain_tmp + 12, YG_dicHR_4_16kHz, 4, 64 );
+ push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
+
+ idx_g = vquant( y_gain_tmp + 16, YG_meanL2G_16kHz, y_gain_tmp + 16, YG_dicL2G_16kHz, 2, 8 );
+ push_indice( hBstr, IND_Y_GAIN_HF, idx_g, 3 );
+ }
+ }
+ }
+
+ GSC_gain_DQ( element_mode, ENC, coder_type, Mbands_gn, core_brate, mean_4g[0], y_gain_tmp, y_gainQ );
+
+ return mean_4g[0];
+}
+
+/*-------------------------------------------------------------------*
+ * gsc_gaindec()
+ *
+ * Generic signal frequency band decoding and application
+ *-------------------------------------------------------------------*/
+
+/*! r: average frequency gain */
+float gsc_gaindec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ float y_gainQ[], /* o : quantized gain per band */
+ const int32_t core_brate, /* i : core used */
+ float old_y_gain[], /* i/o: AR gain quantizer for low rate */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t bwidth /* i : input signal bandwidth */
+)
+{
+ int16_t idx_g, i;
+ float mean_4g;
+ int16_t Mbands_gn = MBANDS_GN;
+ float y_gain_tmp3[MBANDS_GN];
+
+ if ( st->L_frame == L_FRAME16k )
+ {
+ Mbands_gn = MBANDS_GN16k;
+ }
+
+ if ( ( coder_type == AUDIO || coder_type == INACTIVE ) && bwidth == NB )
+ {
+ idx_g = get_next_indice( st, 6 );
+ VDQ_vec( &mean_4g, Gain_meanNB, Gain_mean_dicNB, idx_g, 1 );
+
+ idx_g = get_next_indice( st, 6 );
+ VDQ_vec( y_gainQ, Mean_dic_NB, Gain_dic1_NB, idx_g, 3 );
+
+ if ( core_brate < ACELP_9k60 )
+ {
+ idx_g = get_next_indice( st, 5 );
+ VDQ_vec( y_gainQ + 3, Mean_dic_NB + 3, Gain_dic2_NB, idx_g, 3 );
+
+ idx_g = get_next_indice( st, 4 );
+ VDQ_vec( y_gainQ + 6, Mean_dic_NB + 6, Gain_dic3_NB, idx_g, 4 );
+ }
+ else
+ {
+ idx_g = get_next_indice( st, 6 );
+ VDQ_vec( y_gainQ + 3, Mean_dic_NB + 3, Gain_dic2_NBHR, idx_g, 3 );
+
+ idx_g = get_next_indice( st, 7 );
+ VDQ_vec( y_gainQ + 6, Mean_dic_NB + 6, Gain_dic3_NBHR, idx_g, 4 );
+ }
+
+ if ( 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_gainQ[10] = mean( y_gainQ + 6, 3 );
+ y_gainQ[11] = mean( y_gainQ + 7, 3 );
+ y_gainQ[12] = mean( y_gainQ + 8, 3 );
+ y_gainQ[13] = mean( y_gainQ + 9, 3 );
+ y_gainQ[14] = mean( y_gainQ + 10, 3 );
+ y_gainQ[15] = mean( y_gainQ + 11, 3 );
+ }
+ else
+ {
+ set_f( y_gainQ + 10, 0, MBANDS_GN - 10 );
+ }
+ }
+ else
+ {
+ idx_g = get_next_indice( st, 6 );
+ VDQ_vec( &mean_4g, mean_m, mean_gain_dic, idx_g, 1 );
+
+ if ( core_brate < ACELP_9k60 )
+ {
+ /*--------------------------------------------------------------------------------------*
+ * UQ of the first 8 bands and half of the last 8 bands
+ *--------------------------------------------------------------------------------------*/
+
+ idx_g = get_next_indice( st, 5 );
+ VDQ_vec( y_gainQ, YGain_mean_LR, YGain_dic1_LR, idx_g, 3 );
+
+ if ( !( coder_type == INACTIVE && st->tdm_LRTD_flag == 0 && st->idchan == 1 ) || st->core_brate > GSC_LRES_GAINQ_LIMIT )
+ {
+ idx_g = get_next_indice( st, 5 );
+ VDQ_vec( y_gainQ + 3, YGain_mean_LR + 3, YGain_dic2_LR, idx_g, 4 );
+
+ /*----------------------------------------------------------------------*
+ * Interpolation of the last 4 Q bands to create bands 8-16
+ * And scaling
+ *----------------------------------------------------------------------*/
+
+ idx_g = get_next_indice( st, 5 );
+ VDQ_vec( y_gainQ + 7, YGain_mean_LR + 7, YGain_dic3_LR, idx_g, 5 );
+
+ mvr2r( y_gainQ + 8, y_gain_tmp3, 4 );
+ set_f( y_gainQ + 12, 0.0f, 4 );
+
+ fft_rel( y_gainQ + 8, 4, 2 );
+
+ y_gainQ[15] = y_gainQ[11];
+ y_gainQ[11] = 0.0f;
+
+ ifft_rel( y_gainQ + 8, 8, 3 );
+
+ for ( i = 8; i < 16; i++ )
+ {
+ y_gainQ[i] *= 1.41f;
+ }
+
+ /*----------------------------------------------------------------------*
+ * Copy the true Q values in the specific bands
+ *----------------------------------------------------------------------*/
+
+ y_gainQ[8] = y_gain_tmp3[0];
+ y_gainQ[10] = y_gain_tmp3[1];
+ y_gainQ[12] = y_gain_tmp3[2];
+ y_gainQ[14] = y_gain_tmp3[3];
+ }
+ else
+ {
+ set_f( y_gainQ + 3, 0.0f, MBANDS_GN16k - 3 );
+ }
+ }
+ else
+ {
+ if ( st->L_frame == L_FRAME )
+ {
+ idx_g = get_next_indice( st, 6 );
+ VDQ_vec( y_gainQ, YG_mean16, YG_dicMR_1, idx_g, 4 );
+
+ idx_g = get_next_indice( st, 5 );
+ VDQ_vec( y_gainQ + 4, YG_mean16 + 4, YG_dicMR_2, idx_g, 4 );
+
+ idx_g = get_next_indice( st, 5 );
+ VDQ_vec( y_gainQ + 8, YG_mean16 + 8, YG_dicMR_3, idx_g, 4 );
+
+ idx_g = get_next_indice( st, 4 );
+ VDQ_vec( y_gainQ + 12, YG_mean16 + 12, YG_dicMR_4, idx_g, 4 );
+ }
+ else
+ {
+ idx_g = get_next_indice( st, 7 );
+ VDQ_vec( y_gainQ, YG_mean16HR, YG_dicHR_1, idx_g, 4 );
+
+ idx_g = get_next_indice( st, 6 );
+ VDQ_vec( y_gainQ + 4, YG_mean16HR + 4, YG_dicHR_2, idx_g, 4 );
+
+ idx_g = get_next_indice( st, 6 );
+ VDQ_vec( y_gainQ + 8, YG_mean16HR + 8, YG_dicHR_3, idx_g, 4 );
+
+ idx_g = get_next_indice( st, 6 );
+ VDQ_vec( y_gainQ + 12, YG_mean16HR_16kHz, YG_dicHR_4_16kHz, idx_g, 4 );
+
+ idx_g = get_next_indice( st, 3 );
+ VDQ_vec( y_gainQ + 16, YG_meanL2G_16kHz, YG_dicL2G_16kHz, idx_g, 2 );
+ }
+ }
+ }
+
+ mvr2r( y_gainQ, old_y_gain, Mbands_gn );
+
+ GSC_gain_DQ( st->element_mode, DEC, coder_type, Mbands_gn, core_brate, mean_4g, y_gainQ, y_gainQ );
+
+ return mean_4g;
+}
+
+
+/*-------------------------------------------------------------------*
+ * VDQ_vec()
+ *
+ * Return the dequantized vector of index
+ *-------------------------------------------------------------------*/
+
+static int16_t VDQ_vec(
+ float *Qvec_out, /* o : Quanitzed vector */
+ const float *mean_dic, /* i : average codebook */
+ const float *dic, /* i : codebook */
+ const int16_t index, /* i : index of codebook*/
+ const int16_t vec_en /* i : vector length */
+)
+{
+ int16_t i, j;
+
+ j = index * vec_en;
+ for ( i = 0; i < vec_en; i++ )
+ {
+ Qvec_out[i] = dic[j++];
+ }
+
+ for ( i = 0; i < vec_en; i++ )
+ {
+ Qvec_out[i] += mean_dic[i];
+ }
+
+ return index;
+}
diff --git a/lib_com/gs_inact_switching.c b/lib_com/gs_inact_switching.c
new file mode 100644
index 0000000000000000000000000000000000000000..04ad8a3ebbfb855848491864963473326b7bf971
--- /dev/null
+++ b/lib_com/gs_inact_switching.c
@@ -0,0 +1,145 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------------------------*/
+
+#define ALPHA0 0.5f
+#define BETA0 ( 1.0f - ALPHA0 )
+
+/*-------------------------------------------------------------------*
+ * inact_switch_ematch()
+ *
+ * Apply energy matching when swithcing to INACTIVE frame coded by the GSC technology
+ *-------------------------------------------------------------------*/
+
+void inact_switch_ematch(
+ float exc2[], /* i/o: CELP/GSC excitation buffer */
+ float dct_exc_tmp[], /* i : GSC excitation in DCT domain */
+ float lt_ener_per_band[], /* i/o: Long term energy per band */
+ const int16_t coder_type, /* i : Coder type */
+ const int16_t L_frame, /* i : Frame length */
+ const int32_t total_brate, /* i : Total bitrate */
+ const int16_t bfi, /* i : frame lost indicator */
+ const int16_t last_core, /* i : Last core used */
+ const int16_t last_codec_mode, /* i : Last codec mode */
+ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/
+ const int16_t element_mode /* i : element mode */
+)
+{
+ float Ener_per_bd[MBANDS_GN16k];
+ float ftmp;
+ float *pt_exc;
+ int16_t j, i;
+
+
+ /*--------------------------------------------------------------------------
+ * average energy per band
+ *--------------------------------------------------------------------------*/
+
+ if ( ( coder_type == AUDIO || ( coder_type == UNVOICED && tdm_low_rate_mode == 1 ) ) && bfi == 0 )
+ {
+ Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1, L_frame );
+
+ /* reset long-term energy per band */
+ for ( i = 0; i < MBANDS_GN; i++ )
+ {
+ lt_ener_per_band[i] = Ener_per_bd[i];
+ }
+ }
+ else if ( coder_type == VOICED || coder_type == GENERIC || coder_type == TRANSITION || last_core != ACELP_CORE || last_codec_mode != MODE1 || ( element_mode > EVS_MONO && coder_type == UNVOICED ) )
+ {
+ /* Find spectrum and energy per band for GC and VC frames */
+ edct( exc2, dct_exc_tmp, L_frame, element_mode );
+
+ Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1, L_frame );
+
+ /* reset long-term energy per band */
+ for ( i = 0; i < MBANDS_GN; i++ )
+ {
+ lt_ener_per_band[i] = Ener_per_bd[i];
+ }
+ }
+ else if ( coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE )
+ {
+ /* Find spectrum and energy per band for inactive frames */
+ edct( exc2, dct_exc_tmp, L_frame, element_mode );
+
+ Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1, L_frame );
+
+ /* More agressive smoothing in the first 50 frames */
+ pt_exc = dct_exc_tmp;
+ for ( i = 0; i < MBANDS_GN; i++ )
+ {
+ /* Compute smoothing gain to apply with gain limitation */
+ lt_ener_per_band[i] = ALPHA0 * lt_ener_per_band[i] + BETA0 * Ener_per_bd[i];
+
+ ftmp = lt_ener_per_band[i] - Ener_per_bd[i];
+ ftmp = (float) pow( 10, ftmp );
+
+ if ( i < 2 )
+ {
+ for ( j = 0; j < 8; j++ )
+ {
+ *pt_exc *= ftmp;
+ pt_exc++;
+ }
+ }
+ else
+ {
+ for ( j = 0; j < 16; j++ )
+ {
+ *pt_exc *= ftmp;
+ pt_exc++;
+ }
+ }
+ }
+
+ /* Going back to time */
+ edct( dct_exc_tmp, exc2, L_frame, element_mode );
+ }
+
+ return;
+}
diff --git a/lib_com/gs_noisefill.c b/lib_com/gs_noisefill.c
new file mode 100644
index 0000000000000000000000000000000000000000..f452dab7a5cfb719a5d3470f75650799f219b4ba
--- /dev/null
+++ b/lib_com/gs_noisefill.c
@@ -0,0 +1,843 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * gs_noisf()
+ *
+ * Noise fill-in function
+ *-------------------------------------------------------------------*/
+
+static void gs_noisf(
+ const int16_t Start_BIN, /* i : First bin for noise fill */
+ const int16_t NB_Qbins, /* i : Number of bin per band */
+ const float Noise_fac, /* i : Noise level */
+ const float *y_norm, /* i : Quantized pulses */
+ float *exc_diffQ, /* o : Quantized pulses with noise added */
+ int16_t *seed_tcx, /* i : Random generator seed */
+ const int16_t coder_type /* i : coder type */
+)
+{
+ float ftmp;
+ int16_t i, k;
+ int16_t NB_zer = NB_Qbins / 2;
+
+ if ( coder_type == INACTIVE )
+ {
+ NB_zer = 2;
+ }
+
+ /*----------------------------------------------*
+ * noise fill-in on unquantized subvector *
+ * injected only from 1066Hz to 6400Hz. *
+ *----------------------------------------------*/
+
+ for ( k = Start_BIN; k < NB_Qbins + Start_BIN; k += NB_zer )
+ {
+ ftmp = 0.0;
+ for ( i = k; i < k + NB_zer; i++ )
+ {
+ exc_diffQ[i] = (float) y_norm[i];
+ ftmp += exc_diffQ[i] * exc_diffQ[i];
+ }
+
+ if ( ftmp < .5 )
+ {
+ for ( i = k; i < k + NB_zer; i++ )
+ {
+ exc_diffQ[i] += Noise_fac * ( (float) own_random( seed_tcx ) / PCM16_TO_FLT_FAC );
+ }
+ }
+ else
+ {
+ /* This is added only to keep the seed in sync between different compilers */
+ for ( i = k; i < k + NB_zer; i++ )
+ {
+ own_random( seed_tcx );
+ }
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * EstimateNoiseLevel_inner()
+ *
+ * Estimate noise level from the power spectrum
+ *-------------------------------------------------------------------*/
+
+static void EstimateNoiseLevel_inner(
+ float *noisepb, /* o : Noise per band */
+ const int32_t bitrate, /* i : Bitrate of the codec */
+ const int16_t i_band, /* i : First band to compute the noise */
+ const int16_t Mbands_gn /* i : number of bands */
+)
+{
+ int16_t i;
+ float noise_offset;
+
+ noise_offset = 0.25f;
+ if ( bitrate > ACELP_24k40 )
+ {
+ noise_offset = .2f;
+ }
+ else if ( bitrate >= ACELP_22k60 )
+ {
+ noise_offset = .3f;
+ }
+ else if ( bitrate >= ACELP_9k60 )
+ {
+ noise_offset = 0.35f;
+ }
+ else
+ {
+ noise_offset = .4f;
+ }
+
+ set_f( noisepb + i_band, noise_offset, Mbands_gn - i_band );
+
+ for ( i = i_band; i < 5; i++ )
+ {
+ if ( noisepb[i] > 0.2f )
+ {
+ noisepb[i] = 0.2f;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * EstimateNoiseLevel()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void EstimateNoiseLevel(
+ float *noisepb, /* o : Noise per band */
+ const int32_t bitrate, /* i : Bitrate of the codec */
+ const int16_t Diff_len, /* i : number of bin before cut-off frequency */
+ const int16_t Mbands_gn, /* i : number of bands */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t noise_lev, /* i : pulses dynamic */
+ const int16_t pit_band_idx, /* i : bin position of the cut-off frequency */
+ const int16_t last_bin, /* i : the last bin of bit allocation */
+ const int16_t bwidth,
+ const int16_t L_frame /* i : frame length */
+)
+{
+ int16_t i_band;
+
+ i_band = 0;
+
+ if ( Diff_len < L_frame )
+ {
+ EstimateNoiseLevel_inner( noisepb, bitrate, i_band, Mbands_gn );
+
+ if ( coder_type != INACTIVE )
+ {
+ if ( ( bitrate == ACELP_8k00 && last_bin > 8 ) && bwidth != NB )
+ {
+ while ( Mbands_gn > i_band )
+ {
+ noisepb[i_band] *= 2.0f;
+ i_band++;
+ }
+ }
+ else
+ {
+ while ( pit_band_idx > i_band )
+ {
+ noisepb[i_band] /= 2.0f;
+ i_band++;
+ }
+ }
+ }
+ }
+
+ if ( ( coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3 ) && L_frame == L_FRAME )
+ {
+ for ( i_band = 9; i_band < Mbands_gn; i_band++ )
+ {
+ noisepb[i_band] *= 1.15f;
+ }
+ }
+ else if ( L_frame == L_FRAME16k )
+ {
+ if ( bitrate == ACELP_13k20 )
+ {
+ set_f( noisepb, .45f, Mbands_gn );
+ }
+
+ if ( coder_type == INACTIVE )
+ {
+ for ( ; i_band < Mbands_gn; i_band++ )
+ {
+ noisepb[i_band] = .4f;
+ }
+ }
+ else if ( ( noise_lev <= NOISE_LEVEL_SP1 ) && bitrate > ACELP_16k40 )
+ {
+ for ( ; i_band < Mbands_gn - 4; i_band++ )
+ {
+ noisepb[i_band] *= .6f;
+ }
+ }
+ else if ( ( noise_lev <= NOISE_LEVEL_SP2 ) && bitrate > ACELP_16k40 )
+ {
+ for ( ; i_band < Mbands_gn - 4; i_band++ )
+ {
+ noisepb[i_band] *= .8f;
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * Apply_NoiseFill()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void Apply_NoiseFill(
+ float *exc_diffQ, /* i/o: Noise per band */
+ int16_t *seed_tcx, /* i : Seed for noise */
+ const float *noisepb, /* i : Noise per band */
+ const int16_t Diff_len, /* i : number of bin before cut-off frequency */
+ const int16_t Mbands_gn, /* i : number of bands */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t *freq_nsbin_per_band /* i : bin per bands tables */
+)
+{
+ int16_t StartBin, NB_Qbins, i_band;
+ StartBin = 0;
+ NB_Qbins = 0;
+
+ for ( i_band = 0; i_band < Mbands_gn; i_band++ )
+ {
+ StartBin += NB_Qbins;
+ NB_Qbins = freq_nsbin_per_band[i_band];
+
+ if ( Diff_len < L_FRAME )
+ {
+ gs_noisf( StartBin, NB_Qbins, noisepb[i_band], exc_diffQ, exc_diffQ, seed_tcx, coder_type );
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * freq_dnw_scaling()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void freq_dnw_scaling(
+ const int16_t cor_strong_limit, /* i : HF correlation */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t noise_lev, /* i : Noise level */
+ const int32_t core_brate, /* i : Core bitrate */
+ float fy_norm[], /* i/o: Frequency quantized parameter */
+ const int16_t L_frame /* i : frame length */
+)
+{
+ float sc_dyn;
+ int16_t start_sc, i;
+
+ sc_dyn = 1.0f;
+ start_sc = L_frame;
+
+ if ( core_brate <= ACELP_8k00 && coder_type == INACTIVE )
+ {
+ sc_dyn *= .15f;
+ start_sc = 64;
+ }
+ else if ( coder_type == INACTIVE )
+ {
+ sc_dyn *= .25f;
+ start_sc = 80;
+ }
+ else
+ {
+ sc_dyn = (float) ( NOISE_LEVEL_SP3 - noise_lev ) / 10.0f + 0.4f;
+ start_sc = 112 + ( NOISE_LEVEL_SP3 - noise_lev ) * 16;
+
+ if ( noise_lev == NOISE_LEVEL_SP0 )
+ {
+ start_sc = L_FRAME;
+ }
+ }
+
+ if ( L_frame == L_FRAME16k && core_brate <= ACELP_24k40 )
+ {
+ sc_dyn += 0.125f;
+ if ( sc_dyn > 1.0f )
+ {
+ sc_dyn = 1.0f;
+ }
+ }
+
+ for ( i = start_sc; i < L_frame; i++ )
+ {
+ fy_norm[i] *= sc_dyn;
+ }
+
+ if ( ( core_brate < ACELP_13k20 && cor_strong_limit == 0 ) || core_brate < ACELP_9k60 )
+ {
+ for ( i = 160; i < L_frame; i++ )
+ {
+ if ( fy_norm[i] > 1.0f )
+ {
+ fy_norm[i] = 1.0f;
+ }
+
+ if ( fy_norm[i] < -1.0f )
+ {
+ fy_norm[i] = -1.0f;
+ }
+ }
+ }
+ else if ( core_brate < ACELP_22k60 )
+ {
+ for ( i = 160; i < L_frame; i++ )
+ {
+ if ( fy_norm[i] > 1.5f )
+ {
+ fy_norm[i] = 1.5f;
+ }
+
+ if ( fy_norm[i] < -1.5f )
+ {
+ fy_norm[i] = -1.5f;
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * Decreas_freqPeak()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void Decreas_freqPeak(
+ const float *lsf_new, /* i : ISFs at the end of the frame */
+ float *exc_diffQ, /* i/o: frequency coefficients of per band */
+ float thr_rat /* i : threshold of ratio between consecutive lsf_new_diff */
+)
+{
+ int16_t i, j, k;
+ int16_t last_bin = 0;
+ int16_t pos = 0;
+ float *src;
+ float avrg, max_val;
+ float lsf_new_diff[M];
+ lsf_new_diff[0] = 0; /* prevent unitialized value */
+ for ( j = 1; j < ( M - 1 ); j++ )
+ {
+ lsf_new_diff[j] = lsf_new[j] - lsf_new[j - 1];
+ }
+
+ avrg = 0.0f;
+ /* This is to prevent a possible div by 0 in the '*(src) = (*src > 0) ?...'
+ loop. The value of 'max' is not important because it will be mutiplied
+ by 'avrg' and the result will be close to 0. The 'fabs(*src)/max'
+ div by 0 error will be avoided. */
+ max_val = 0.001f;
+ for ( i = 160; i < L_FRAME; i++ )
+ {
+ if ( fabs( exc_diffQ[i] ) > max_val )
+ {
+ max_val = (float) fabs( exc_diffQ[i] );
+ pos = i;
+ }
+ avrg += (float) fabs( exc_diffQ[i] );
+ }
+ avrg /= 96;
+ last_bin = M - 1; /* When the search is false, should equate the end of the vector, not the beginning */
+ for ( i = 0; i < ( M - 1 ); i++ )
+ {
+ if ( lsf_new[i] > 4000 )
+ {
+ last_bin = i;
+ break;
+ }
+ }
+
+ for ( i = last_bin; i < 14; i++ )
+ {
+ if ( lsf_new_diff[i] < thr_rat * lsf_new_diff[i - 1] )
+ {
+ src = &exc_diffQ[( i - 1 ) * 16];
+ for ( j = 0; j < 2; j++ )
+ {
+ for ( k = 0; k < 16; k++ )
+ {
+ if ( fabs( *src ) > 2.0f * avrg )
+ {
+ *( src ) = ( *src > 0 ) ? (float) ( avrg * ( 2.0f - fabs( *src ) / max_val ) ) : (float) ( -avrg * ( 2.0f - fabs( *src ) / max_val ) );
+ }
+ src++;
+ }
+ }
+ }
+ }
+
+ if ( fabs( exc_diffQ[pos] ) == max_val && max_val > 4.0f * avrg )
+ {
+ for ( i = pos - 1; i < pos + 2; i++ )
+ {
+ exc_diffQ[pos] *= 0.5f;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * envelop_modify()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void envelop_modify(
+ float *exc_diffQ, /* i/o: frequency coefficients of per band */
+ int16_t *seed_tcx, /* i : Seed for noise */
+ int16_t last_bin, /* i : last bin of bit allocation */
+ float *Ener_per_bd_iQ /* i : Quantized energy of targeted vector */
+)
+{
+ int16_t i, j, end_band;
+ float Ener, Ener1, *src;
+ float weight = 1.0f;
+
+ end_band = L_FRAME;
+ Ener = 0.1f;
+ for ( i = last_bin * 16; i < end_band; i++ )
+ {
+ Ener += exc_diffQ[i] * exc_diffQ[i];
+ }
+ Ener = (float) sqrt( ( end_band - last_bin * 16 ) / Ener );
+
+ weight = 0.5f;
+
+ src = &exc_diffQ[16 * last_bin];
+ for ( i = last_bin; i < last_bin + 4; i++ )
+ {
+ Ener1 = (float) ( 0.4f * pow( 10, Ener_per_bd_iQ[i + 1] ) );
+ for ( j = 0; j < 16; j++ )
+ {
+ *src = Ener1 * ( weight * ( *src ) * Ener + ( 1.0f - weight ) * own_random( seed_tcx ) / PCM16_TO_FLT_FAC );
+ src++;
+ }
+ }
+
+ Ener1 = (float) ( 0.4f * pow( 10, Ener_per_bd_iQ[15] ) );
+
+ src = &exc_diffQ[224];
+ for ( j = 0; j < 32; j++ )
+ {
+ *src = Ener1 * ( weight * ( *src ) * Ener + ( 1.0f - weight ) * own_random( seed_tcx ) / PCM16_TO_FLT_FAC );
+ src++;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * highband_exc_dct_in()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void highband_exc_dct_in(
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t *mfreq_bindiv, /* i : bin per bands tables */
+ int16_t last_bin, /* i : last bin of bit allocation */
+ int16_t Diff_len, /* i : number of bin before cut-off frequency */
+ int16_t noise_lev, /* i : pulses dynamic */
+ int16_t pit_band_idx, /* i : bin position of the cut-off frequency */
+ float *exc_diffQ, /* i : frequency coefficients of per band */
+ int16_t *seed_tcx, /* i : Seed for noise */
+ float *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */
+ int16_t nb_subfr, /* i : Number of subframe considered */
+ float *exc_dct_in, /* o : dct of residual signal */
+ int16_t last_coder_type, /* i : coding type of last frame */
+ int16_t *bitallocation_band, /* i : bit allocation flag of each band */
+ const float *lsf_new, /* i : LSFs at the end of the frame */
+ float *last_exc_dct_in, /* i : dct of residual signal of last frame */
+ float *last_ener, /* i : frequency energy of last frame */
+ int16_t *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */
+ int16_t *bitallocation_exc, /* i : flag of decoded coefficients */
+ const int16_t bfi, /* i : bad frame indicator */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t bwidth, /* i : audio bandwidth */
+ float *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */
+ const int16_t GSC_noisy_speech, /* i : GSC noisy speech flag */
+ float *lt_ener_per_band, /* i/o: Average per band energy */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t element_mode, /* i : IVAS element mode */
+ const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */
+)
+{
+ int16_t i, j;
+ int16_t MAX_Bin = 0;
+ int16_t last_bin_tmp;
+ float noisepb[MBANDS_GN16k];
+ float Ener_per_bd_yQ[MBANDS_GN16k];
+ float *src, *dst, *end;
+ float ener = 0.0f;
+ int16_t length_bin, bwe_flag = 0;
+
+ for ( j = 10; j < MBANDS_GN; j++ )
+ {
+ ener += (float) pow( 10, Ener_per_bd_iQ[j] );
+ }
+
+ if ( core_brate == ACELP_8k00 && bwidth != NB )
+ {
+ if ( last_coder_type != AUDIO )
+ {
+ *last_ener = ener;
+ }
+
+ if ( ( last_bin > 8 || Diff_len != 0 ) && last_coder_type == AUDIO )
+ {
+ MAX_Bin = 10;
+ bwe_flag = 1;
+ }
+ else
+ {
+ MAX_Bin = 15;
+ }
+
+ last_bin_tmp = last_bin;
+ if ( last_bin < MAX_Bin )
+ {
+ last_bin = MAX_Bin;
+ }
+ last_bin += 1;
+ }
+ else
+ {
+ if ( L_frame == L_FRAME16k )
+ {
+ last_bin = MBANDS_GN16k;
+ }
+ else
+ {
+ last_bin = MBANDS_GN;
+ }
+ last_bin_tmp = last_bin;
+ }
+
+
+ if ( bfi || core_brate < 6000 || ( core_brate < 8600 && coder_type == UNVOICED ) )
+ {
+ set_f( noisepb, 0.4f, MBANDS_GN );
+ }
+ else if ( GSC_IVAS_mode == 3 || ( GSC_IVAS_mode > 0 && GSC_noisy_speech == 1 ) )
+ {
+ set_f( noisepb, 0.4f, MBANDS_GN16k );
+ }
+ else
+ {
+ EstimateNoiseLevel( 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 )
+ {
+ mvr2r( exc_diffQ, exc_wo_nf, L_frame );
+ }
+
+ if ( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && element_mode <= IVAS_SCE )
+ {
+ set_f( noisepb, 0.1f, MBANDS_GN );
+ }
+
+ if ( core_brate < 6000 && coder_type <= UNVOICED )
+ {
+ for ( i = 0; i < L_frame; i++ )
+ {
+ if ( exc_diffQ[i] == 0.0f )
+ {
+ exc_diffQ[i] += 2.0f * noisepb[0] * ( (float) own_random( seed_tcx ) / PCM16_TO_FLT_FAC );
+ }
+ }
+ }
+ else
+ {
+ Apply_NoiseFill( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv );
+ }
+
+ /*--------------------------------------------------------------------------------------*
+ * Quantize average gain
+ * Subtract Q averaged gain
+ * VQ of remaining gain per band
+ *--------------------------------------------------------------------------------------*/
+
+ if ( core_brate == ACELP_8k00 && bwidth != NB )
+ {
+ Ener_per_band_comp( exc_diffQ, Ener_per_bd_yQ, last_bin + 1, 0, L_frame );
+ }
+ else
+ {
+ Ener_per_band_comp( exc_diffQ, Ener_per_bd_yQ, MBANDS_GN, 1, L_frame );
+
+ if ( nb_subfr < 4 && L_frame < L_FRAME16k )
+ {
+ for ( i = L_FRAME - 16; i < L_FRAME; i++ )
+ {
+ exc_diffQ[i] *= ( 0.067f * i - 15.0f );
+ }
+ }
+ }
+
+ /*--------------------------------------------------------------------------------------*
+ * Check potential energy excitation overshoot
+ *--------------------------------------------------------------------------------------*/
+
+ if ( bfi )
+ {
+ if ( GSC_noisy_speech == 0 && 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] = min( Ener_per_bd_iQ[i], ( lt_ener_per_band[i] - 0.0376f ) - Ener_per_bd_yQ[i] );
+ lt_ener_per_band[i] -= 0.0188f;
+ }
+ for ( ; i < MBANDS_GN; i++ )
+ {
+ Ener_per_bd_iQ[i] = min( Ener_per_bd_iQ[i], ( lt_ener_per_band[i] - 0.0376f ) );
+ lt_ener_per_band[i] -= 0.0188f;
+ }
+ }
+ else
+ {
+ for ( i = 0; i < last_bin; i++ )
+ {
+ Ener_per_bd_iQ[i] = min( Ener_per_bd_iQ[i], ( lt_ener_per_band[i] + 0.3f ) - Ener_per_bd_yQ[i] );
+ lt_ener_per_band[i] -= 0.0188f;
+ }
+ for ( ; i < MBANDS_GN; i++ )
+ {
+ Ener_per_bd_iQ[i] = min( Ener_per_bd_iQ[i], ( lt_ener_per_band[i] + 0.3f ) );
+ lt_ener_per_band[i] -= 0.0188f;
+ }
+ }
+ }
+
+ /*--------------------------------------------------------------------------------------*
+ * Apply decoded gain onto the difference signal
+ *--------------------------------------------------------------------------------------*/
+
+ if ( GSC_IVAS_mode >= 1 )
+ {
+ float scale_factLF = 0.9f;
+ float scale_factHF = 0.9f;
+
+ if ( GSC_IVAS_mode == 1 && GSC_noisy_speech == 0 )
+ {
+ scale_factHF = 0.8f;
+ }
+ else if ( GSC_IVAS_mode == 2 || GSC_noisy_speech == 1 )
+ {
+ scale_factHF = 0.71f;
+ }
+ else if ( GSC_IVAS_mode == 3 )
+ {
+ scale_factHF = 0.9f;
+ }
+ for ( i = 0; i < pit_band_idx * 16; i++ )
+ {
+ exc_diffQ[i] *= scale_factLF;
+ }
+ for ( ; i < L_frame; i++ )
+ {
+ exc_diffQ[i] *= scale_factHF;
+ }
+ }
+ else if ( GSC_noisy_speech )
+ {
+ float scale_fact = 0.9f;
+
+ if ( element_mode == IVAS_CPE_TD )
+ {
+ if ( coder_type == INACTIVE )
+ {
+ scale_fact = 1.0f;
+ }
+ else
+ {
+ scale_fact = 0.95f;
+ }
+ }
+ else if ( element_mode > IVAS_SCE )
+ {
+ scale_fact = 0.71f;
+ }
+
+ for ( i = 0; i < L_frame; i++ )
+ {
+ exc_diffQ[i] *= scale_fact;
+ }
+ }
+
+ if ( GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20 )
+ {
+ for ( i = 80; i < L_frame; i++ )
+ {
+ exc_diffQ[i] *= ( +0.0024f * (float) i + 1.192f );
+ }
+ }
+
+ Comp_and_apply_gain( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0 );
+
+ if ( exc_wo_nf != NULL )
+ {
+ Comp_and_apply_gain( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1 );
+
+ v_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
+ *--------------------------------------------------------------------------------------*/
+
+ v_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame );
+
+ if ( core_brate == ACELP_8k00 && bwidth != NB )
+ {
+ if ( bwe_flag == 1 )
+ {
+ last_bin -= 1;
+ src = &exc_diffQ[L_FRAME - 1];
+ dst = &exc_dct_in[MAX_Bin * 16 - 1];
+ end = &exc_diffQ[last_bin * 16 - 1];
+
+ while ( src > end )
+ {
+ *src-- = *dst--;
+ }
+
+ if ( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && core_brate == ACELP_8k00 )
+ {
+ exc_diffQ[160] = 0.0f;
+ }
+
+ envelop_modify( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ );
+
+ mvr2r( &exc_diffQ[last_bin * 16], &exc_dct_in[last_bin * 16], L_FRAME - last_bin * 16 );
+ }
+
+ if ( nb_subfr < 4 )
+ {
+ for ( i = L_FRAME - 16; i < L_FRAME; i++ )
+ {
+ exc_dct_in[i] *= ( 0.067f * i - 15.f );
+ }
+ }
+
+ if ( ener < 2 * ( *last_ener ) && ener > 0.5f * ( *last_ener ) )
+ {
+ length_bin = 6;
+ if ( last_coder_type != AUDIO )
+ {
+ set_s( last_bitallocation_band, 0, 6 );
+ mvr2r( &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++ )
+ {
+ if ( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) )
+ {
+ src = &exc_dct_in[( i + length_bin ) * 16];
+ dst = &last_exc_dct_in[( i + length_bin ) * 16];
+ for ( j = 0; j < 16; j++ )
+ {
+ if ( fabs( *src ) > 3.0f * fabs( *dst ) )
+ {
+ *src = ( *src > 0 ) ? (float) ( 0.5f * ( *src + fabs( *dst ) ) ) : (float) ( 0.5f * ( *src - fabs( *dst ) ) );
+ }
+ else if ( fabs( *dst ) > 3.0f * fabs( *src ) )
+ {
+ *src = ( *src > 0 ) ? (float) ( 0.7f * ( *src ) + 0.3f * fabs( *dst ) ) : (float) ( 0.7f * ( *src ) - 0.3f * fabs( *dst ) );
+ }
+ src++;
+ dst++;
+ }
+ }
+ }
+ }
+
+ if ( bwe_flag == 1 )
+ {
+ Decreas_freqPeak( lsf_new, exc_dct_in, 0.3f );
+ }
+ else
+ {
+ Decreas_freqPeak( lsf_new, exc_dct_in, 0.5f );
+ }
+ }
+
+ mvr2r( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 );
+ mvs2s( &bitallocation_band[4], last_bitallocation_band, 6 );
+ *last_ener = ener;
+
+ return;
+}
diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c
new file mode 100644
index 0000000000000000000000000000000000000000..ae2bbf6f53a4fa78ec79ef8149eb010a0ebf97e5
--- /dev/null
+++ b/lib_com/gs_preech.c
@@ -0,0 +1,139 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------------------------*/
+
+#define ATT_LENGHT16k 80
+#define INV_L_FRAME16k ( 1.0f / L_FRAME16k )
+#define ATT_LENGHT 64
+#define ATT_SEG_LEN ( L_FRAME / ATT_LENGHT )
+#define INV_ATT_SEG_LEN ( 1.0f / ATT_SEG_LEN )
+#define INV_L_FRAME ( 1.0f / L_FRAME )
+
+
+/*-------------------------------------------------------------------*
+ * pre_echo_att()
+ *
+ * Attenuation of the pre-echo when encoder specifies an attack
+ *-------------------------------------------------------------------*/
+
+void pre_echo_att(
+ float *Last_frame_ener, /* i/o: Energy of the last frame */
+ float *exc, /* i/o: Excitation of the current frame */
+ const int16_t attack_flag, /* i : attack flag (GSC or TC) */
+ const int16_t last_coder_type, /* i : Last coder type */
+ const int16_t L_frame /* i : frame length */
+)
+{
+ float etmp;
+ float etmp1;
+ float finc[ATT_LENGHT16k], ratio, inv_l_frame;
+ int16_t att_len;
+ int16_t attack_pos, i;
+
+ if ( attack_flag > 0 && last_coder_type == AUDIO )
+ {
+ /*-------------------------------------------------------------------------*
+ * 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;
+ if ( L_frame == L_FRAME16k )
+ {
+ att_len = ATT_LENGHT16k;
+ }
+ for ( i = 0; i < att_len; i++ )
+ {
+ finc[i] = sum2_f( exc + i * ATT_SEG_LEN, ATT_SEG_LEN ) * ( (float) ( att_len - i ) / ( att_len ) );
+ }
+ etmp = -1;
+ attack_pos = maximum( finc, att_len, &etmp );
+
+ /* Scaled the maximum energy and allowed 6 dB increase*/
+ etmp *= INV_ATT_SEG_LEN;
+ etmp1 = etmp;
+ *Last_frame_ener *= 4.0f;
+
+ /* If the maximum normalized energy > last frame energy + 6dB */
+ if ( etmp > *Last_frame_ener && attack_pos > 0 )
+ {
+ /* Find the average energy before the attack */
+ etmp = sum_f( finc, attack_pos ) + 0.01f;
+ etmp /= ( attack_pos * ATT_SEG_LEN );
+
+ /* Find the correction factor and apply it before the attack */
+ ratio = (float) sqrt( *Last_frame_ener / etmp );
+
+
+ /* Pre-echo atttenuation should never increase the energy */
+ ratio = min( ratio, 1.0f );
+ for ( i = 0; i < attack_pos * ATT_SEG_LEN; i++ )
+ {
+ exc[i] *= ratio;
+ }
+ }
+ *Last_frame_ener = etmp1;
+ }
+ else
+ {
+ /*-------------------------------------------------------*
+ * In normal cases, just compute the energy of the frame
+ *-------------------------------------------------------*/
+
+ etmp = sum2_f( exc, L_frame ) + 0.01f;
+ inv_l_frame = INV_L_FRAME;
+ if ( L_frame == L_FRAME16k )
+ {
+ inv_l_frame = INV_L_FRAME16k;
+ }
+ etmp *= inv_l_frame;
+ *Last_frame_ener = etmp;
+ }
+
+ return;
+}
diff --git a/lib_com/guided_plc_util.c b/lib_com/guided_plc_util.c
new file mode 100644
index 0000000000000000000000000000000000000000..884c2beeb860104d820e9dedadd5d0ef742ae43b
--- /dev/null
+++ b/lib_com/guided_plc_util.c
@@ -0,0 +1,323 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local function prototypes
+ *-------------------------------------------------------------------*/
+
+static void reorder_lsfs( float *lsf, float min_dist, const int16_t n, const int32_t sr_core );
+
+
+/*-------------------------------------------------------------------*
+ * getLookAheadResSig()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void getLookAheadResSig(
+ float *speechLookAhead,
+ const float *A,
+ float *res,
+ const int16_t L_frame,
+ const int16_t L_subfr,
+ const int16_t m,
+ const int16_t numSubFrame )
+{
+ const float *p_A;
+ int16_t i_subfr;
+ int16_t subfr_len[2];
+
+ subfr_len[0] = L_subfr;
+ subfr_len[1] = L_frame < L_FRAME16k ? (int16_t) ( 0.75 * L_subfr ) : L_subfr;
+
+ p_A = A;
+ for ( i_subfr = 0; i_subfr < numSubFrame * L_subfr; i_subfr += L_subfr )
+ {
+ residu( p_A, m, &speechLookAhead[i_subfr], &res[i_subfr], subfr_len[i_subfr / L_subfr] );
+ p_A += ( m + 1 );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * updatelsfForConcealment()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void updatelsfForConcealment(
+ PLC_ENC_EVS_HANDLE decState,
+ float *lsf )
+{
+ int16_t i;
+
+ for ( i = 0; i < M; i++ )
+ {
+ decState->lsf_adaptive_mean[i] = ( decState->lsfoldbfi1[i] + decState->lsfoldbfi0[i] + lsf[i] ) / 3;
+ decState->lsfoldbfi1[i] = decState->lsfoldbfi0[i];
+ decState->lsfoldbfi0[i] = lsf[i];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * getConcealedLP()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void getConcealedLP(
+ PLC_ENC_EVS_HANDLE memDecState,
+ float *AqCon,
+ const float lsfBase[],
+ const int32_t sr_core,
+ const int16_t last_good,
+ const int16_t L_frame )
+{
+ float *lsf = memDecState->lsf_con;
+ float lsp[( NB_DIV + 1 ) * M];
+ int16_t k;
+
+ dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold, last_good, 1 /* assumes packet loss */, memDecState->mem_MA, memDecState->mem_AR, &( memDecState->stab_fac ), memDecState->lsf_adaptive_mean, 1, NULL, 0, NULL, NULL, lsfBase );
+
+ mvr2r( memDecState->lspold, lsp, M );
+
+ for ( k = 0; k < 1; k++ )
+ {
+ lsf2lsp( &lsf[k * M], &lsp[( k + 1 ) * M], M, sr_core );
+ }
+
+ int_lsp( L_FRAME, &lsp[0], &lsp[M], AqCon, M, interpol_frac_12k8, 0 );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * RecLpcSpecPowDiffuseLc()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void RecLpcSpecPowDiffuseLc(
+ float *lspq,
+ float *lsp_old,
+ float *lsfq,
+ Decoder_State *st,
+ const int16_t reset_q )
+{
+ const float *means;
+ float lsf_old[M];
+ int16_t i;
+
+ means = PlcGetlsfBase( st->lpcQuantization, st->narrowBand, st->sr_core );
+
+ mvr2r( st->lsf_old, lsf_old, M );
+
+ modify_lsf( lsf_old, M, st->sr_core, reset_q );
+
+ lsf2lsp( lsf_old, lsp_old, M, st->sr_core );
+
+ if ( reset_q )
+ {
+ for ( i = 0; i < M; i++ )
+ {
+ lsfq[i] = st->mem_MA[i] + means[i];
+ }
+
+ v_sort( lsfq, 0, M - 1 );
+
+ reorder_lsfs( lsfq, LSF_GAP, M, st->sr_core );
+
+ lsf2lsp( lsfq, lspq, M, st->sr_core );
+ }
+ else
+ {
+ modify_lsf( lsfq, M, st->sr_core, reset_q );
+
+ lsf2lsp( lsfq, lspq, M, st->sr_core );
+ }
+
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * modify_lsf()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void modify_lsf(
+ float *lsf,
+ const int16_t n,
+ const int32_t sr_core,
+ const int16_t reset_q )
+{
+ int16_t i, k;
+ float gap;
+ float th;
+
+ th = 1900;
+
+ if ( reset_q == 0 )
+ {
+ th = 800;
+ }
+
+ if ( sr_core == INT_FS_16k )
+ {
+ th *= 1.25;
+ }
+
+
+ i = 1;
+
+ while ( lsf[i] < th && i < n )
+ {
+ i++;
+ }
+ gap = lsf[i - 1] / i;
+
+ for ( k = 0; k < i - 1; k++ )
+ {
+ lsf[k] = gap * ( k + 1 );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * reorder_lsfs()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void reorder_lsfs(
+ float *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5)*/
+ float min_dist, /* i : minimum required distance */
+ const int16_t n, /* i : LPC order */
+ const int32_t sr_core )
+{
+ int16_t i;
+ float lsf_min;
+ float lsf_max;
+ float fac;
+ float th1, th2;
+
+ th1 = 1000.0f;
+ th2 = 1900.0f;
+
+ if ( sr_core == INT_FS_16k )
+ {
+ min_dist *= 1.25;
+ th1 *= 1.25;
+ th2 *= 1.25;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Verify the LSF ordering and minimum GAP
+ *-----------------------------------------------------------------*/
+ fac = 3.0;
+
+ lsf_min = min_dist * fac;
+ for ( i = 0; i < n; i++ )
+ {
+
+ if ( lsf[i] > th1 )
+ {
+ fac = 2.0;
+ }
+ else
+ {
+ if ( lsf[i] > 1900.0 )
+ {
+ fac = 1.0;
+ }
+ }
+
+ if ( lsf[i] < lsf_min )
+ {
+ lsf[i] = lsf_min;
+ }
+
+ lsf_min = lsf[i] + min_dist * fac;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Reverify the LSF ordering and minimum GAP in the reverse order (security)
+ *------------------------------------------------------------------------------------------*/
+
+ lsf_max = (float) ( sr_core ) / 2.0f - min_dist * fac;
+
+ if ( lsf[n - 1] > lsf_max ) /* If danger of unstable filter in case of resonance in HF */
+ {
+ for ( i = n - 1; i >= 0; i-- ) /* Reverify the minimum LSF gap in the reverse sens */
+ {
+
+ if ( lsf[i] <= th2 )
+ {
+ fac = 2.0;
+ }
+ else
+ {
+ if ( lsf[i] <= th1 )
+ {
+ fac = 3.0;
+ }
+ }
+
+ if ( lsf[i] > lsf_max )
+ {
+ lsf[i] = lsf_max;
+ }
+
+ lsf_max = lsf[i] - min_dist * fac;
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/hp50.c b/lib_com/hp50.c
new file mode 100644
index 0000000000000000000000000000000000000000..b9268c8f99451b230edb1a74a78fa70af12fc581
--- /dev/null
+++ b/lib_com/hp50.c
@@ -0,0 +1,130 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+
+/*
+ * hp20
+ *
+ * Function:
+ * 2nd order high pass filter with nominal cut off frequency at 20 Hz.
+ *
+ * Returns:
+ * void
+ */
+
+void hp20(
+ Float32 signal[],
+ const Word16 lg,
+ Float32 mem[],
+ const Word32 Fs )
+{
+ Word16 i;
+ Float32 x0, x1, x2, y0, y1, y2;
+ Float32 a1, a2, b1, b2;
+
+ y1 = mem[0];
+ y2 = mem[1];
+ x0 = mem[2];
+ x1 = mem[3];
+
+ if ( Fs == 8000 )
+ {
+ /* hp filter 20Hz at 3dB for 8000KHz input sampling rate
+ [b,a] = butter(2, 20.0/4000.0, 'high');
+ b = [0.988954248067140 -1.977908496134280 0.988954248067140]
+ a =[1.000000000000000 -1.977786483776764 0.978030508491796]*/
+ a1 = 1.977786483776764f;
+ a2 = -0.978030508491796f;
+ b1 = -1.977908496134280f;
+ b2 = 0.988954248067140f;
+ }
+ else if ( Fs == 16000 )
+ {
+ /* hp filter 20Hz at 3dB for 16000KHz sampling rate
+ [b,a] = butter(2, 20.0/8000.0, 'high');
+ b =[ 0.994461788958195 -1.988923577916390 0.994461788958195]
+ a =[1.000000000000000 -1.988892905899653 0.988954249933127] */
+ a1 = 1.988892905899653f;
+ a2 = -0.988954249933127f;
+ b1 = -1.988923577916390f;
+ b2 = 0.994461788958195f;
+ }
+ else if ( Fs == 32000 )
+ {
+ /* hp filter 20Hz at 3dB for 32000KHz sampling rate
+ [b,a] = butter(2, 20.0/16000.0, 'high');
+ b =[0.997227049904470 -1.994454099808940 0.997227049904470]
+ a =[1.000000000000000 -1.994446410541927 0.994461789075954]*/
+ a1 = 1.994446410541927f;
+ a2 = -0.994461789075954f;
+ b1 = -1.994454099808940f;
+ b2 = 0.997227049904470f;
+ }
+ else
+ {
+ /* hp filter 20Hz at 3dB for 48000KHz sampling rate
+ [b,a] = butter(2, 20.0/24000.0, 'high');
+ b =[ 0.998150511190452 -1.996301022380904 0.998150511190452]
+ a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/
+ a1 = 1.996297601769122f;
+ a2 = -0.996304442992686f;
+ b1 = -1.996301022380904f;
+ b2 = 0.998150511190452f;
+ }
+
+ for ( i = 0; i < lg; i++ )
+ {
+ x2 = x1;
+ x1 = x0;
+ x0 = signal[i];
+ y0 = ( y1 * a1 ) + ( y2 * a2 ) + ( x0 * b2 ) + ( x1 * b1 ) + ( x2 * b2 );
+ signal[i] = y0;
+ y2 = y1;
+ y1 = y0;
+ }
+
+ mem[0] = ( ( y1 > 1e-10 ) | ( y1 < -1e-10 ) ) ? y1 : 0;
+ mem[1] = ( ( y2 > 1e-10 ) | ( y2 < -1e-10 ) ) ? y2 : 0;
+ mem[2] = ( ( x0 > 1e-10 ) | ( x0 < -1e-10 ) ) ? x0 : 0;
+ mem[3] = ( ( x1 > 1e-10 ) | ( x1 < -1e-10 ) ) ? x1 : 0;
+
+ return;
+}
diff --git a/lib_com/hq2_bit_alloc.c b/lib_com/hq2_bit_alloc.c
new file mode 100644
index 0000000000000000000000000000000000000000..d471b170e60439d6d3f2e7c1632a31479ffed207
--- /dev/null
+++ b/lib_com/hq2_bit_alloc.c
@@ -0,0 +1,1041 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "prot.h"
+#include "rom_com.h"
+#include "basop_util.h"
+#include "basop_mpy.h"
+#include "stl.h"
+#include "wmc_auto.h"
+
+#define WMC_TOOL_SKIP
+
+/*-------------------------------------------------------------------
+ * Local constants
+ *-------------------------------------------------------------------*/
+
+#define MIN_BITS_FIX 0
+#define HQ_16k40_BIT ( HQ_16k40 / FRAMES_PER_SEC ) /* 16400/50=328, FOR FIX TMP */
+#define C1_QRk ( 1 << SWB_BWE_LR_QRk ) /* 1 */
+#define Qbf 14
+#define C1_Qbf ( 1 << Qbf ) /* 1 */
+#define BITS_FACT_1p10 ( Word16 )( 1.10f * (float) pow( 2, Qbf ) + 0.5f )
+#define BITS_FACT_1p05 ( Word16 )( 1.05f * (float) pow( 2, Qbf ) + 0.5f )
+#define BITS_FACT_1p00 ( Word16 )( 1.00f * (float) pow( 2, Qbf ) + 0.5f )
+#define BITS_FACT_0p97 ( Word16 )( 0.97f * (float) pow( 2, Qbf ) + 0.5f )
+#define BITS_FACT_0p92 ( Word16 )( 0.92f * (float) pow( 2, Qbf ) + 0.5f )
+
+#define L_Comp( hi, lo ) L_mac( L_deposit_h( hi ), lo, 1 )
+
+/*-------------------------------------------------------------------
+ * div_s_ss()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+/*! r: result of division (Word16 Q0) */
+static Word16 div_s_ss(
+ const Word16 n, /* i : numerator (Word16 Q0 */
+ const Word16 d /* i : denominator (Word16 Q0) */
+)
+{
+ Word16 norm_n, norm_d;
+ Word16 ns, ds;
+ Word16 res;
+ Word16 tmp;
+
+ test();
+ IF( n == 0 || d == 0 )
+ {
+ return 0;
+ }
+
+ norm_n = norm_s( n );
+ norm_n = sub( norm_n, 1 );
+ ns = shl( n, norm_n );
+
+ norm_d = norm_s( d );
+ ds = shl( d, norm_d );
+
+ tmp = div_s( ns, ds );
+ res = shr( tmp, add( sub( norm_n, norm_d ), 15 ) );
+
+ return res;
+}
+
+
+/*-------------------------------------------------------------------*
+ * Bits2indvsb()
+ *
+ * Bit allocation to individual SB's in a group
+ *-------------------------------------------------------------------*/
+static void Bits2indvsb_fx(
+ const Word32 *L_be, /* i : Qbe Band Energy of sub-band */
+ const Word16 start_band, /* i : Q0 start band indices */
+ const Word16 end_band, /* i : Q0 end band indices */
+ const Word16 Bits, /* i : Q0 Total number of bits allocated to a group */
+ const Word32 L_Bits_needed, /* i : QRk smallest bit number for allocation in group */
+ Word32 *L_Rsubband, /* o : QRk bit allocation of sub-band */
+ Word16 *p2aflags_fx /* i/o: Q0 peaky/noise subband flag */
+)
+{
+ Word16 i, j, k;
+ Word32 L_R_temp[14]; /* QRk = QL_Rsubband; */
+ Word16 Ravg_fx;
+ Word16 QRavg;
+
+ const Word32 *L_y_ptr;
+ Word32 *L_R_ptr;
+
+ Word16 Bits_avg_fx;
+ Word16 QBavg;
+ Word16 scale_fact_fx;
+
+ Word16 band_num_fx;
+ Word16 index_fx[14];
+
+ Word16 y_index_fx[14];
+
+ Word16 be_sum_fx; /* Q0 */
+
+ Word16 exp_normn, exp_normd;
+ Word16 enr_diffcnt_fx;
+ Word16 th_5_fx;
+ Word16 Rcnt_fx;
+
+ Word16 be_cnt_fx;
+ Word16 *p2aflags_fx_ptr;
+
+ Word32 L_temp1;
+ Word32 L_temp2;
+
+ band_num_fx = sub( end_band, start_band );
+ L_y_ptr = L_be + start_band;
+ L_R_ptr = L_Rsubband + start_band;
+ p2aflags_fx_ptr = p2aflags_fx + start_band;
+
+ FOR( i = 0; i < band_num_fx; i++ )
+ {
+ y_index_fx[i] = extract_h( L_shr( L_y_ptr[i], sub( SWB_BWE_LR_Qbe, 16 ) ) );
+ move16();
+ index_fx[i] = i;
+ move16();
+ }
+
+
+ /* Rearrange norm vector in decreasing order */
+ reordvct( y_index_fx, band_num_fx, index_fx );
+
+ be_sum_fx = 0;
+ move16();
+ be_cnt_fx = 0;
+ move16();
+ FOR( j = 0; j < band_num_fx; j++ )
+ {
+ test();
+ IF( y_index_fx[j] <= 0 || p2aflags_fx_ptr[index_fx[j]] == 0 )
+ {
+ y_index_fx[j] = 0;
+ move16();
+ L_R_temp[j] = 0x0L;
+ move32();
+ }
+ ELSE
+ {
+ L_R_temp[j] = C1_QRk;
+ move32(); /* filled not zero value */
+ be_cnt_fx = add( be_cnt_fx, 1 );
+ }
+ }
+
+ i = sub( be_cnt_fx, 1 );
+ FOR( k = 0; k <= i; k++ )
+ {
+ test();
+ if ( L_R_temp[k] > 0 )
+ {
+ be_sum_fx = add( be_sum_fx, y_index_fx[k] );
+ }
+ }
+ QBavg = 0;
+ move16();
+
+ /*Ravg = (float) be_sum/be_cnt;*/
+ Ravg_fx = 0;
+ move16();
+ QRavg = 0;
+ move16();
+ IF( be_cnt_fx != 0x0 )
+ {
+ exp_normn = norm_s( be_sum_fx );
+ exp_normn = sub( exp_normn, 1 );
+ exp_normd = norm_s( be_cnt_fx );
+ Ravg_fx = div_s( shl( be_sum_fx, exp_normn ), shl( be_cnt_fx, exp_normd ) );
+
+ Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift */
+ QRavg = add( sub( exp_normn, exp_normd ), 15 - 2 );
+ }
+
+ enr_diffcnt_fx = 0;
+ move16();
+ th_5_fx = shl( 5, QRavg );
+ FOR( j = 0; j < be_cnt_fx; j++ )
+ {
+ IF( sub( abs_s( sub( Ravg_fx, shl( y_index_fx[j], QRavg ) ) ), th_5_fx ) > 0 )
+ {
+ enr_diffcnt_fx = add( enr_diffcnt_fx, 1 );
+ }
+ }
+
+ IF( enr_diffcnt_fx > 0 )
+ {
+ scale_fact_fx = 11468;
+ move16(); /* 0.35f 11468.8(Q15) */
+ }
+ ELSE
+ {
+ scale_fact_fx = 19661;
+ move16(); /* 0.60f 19660.8(Q15) */
+ }
+
+ /* Bits allocation to individual SB's in a group based on Band Energies */
+ FOR( j = 0; j < be_cnt_fx; j++ )
+ {
+ Rcnt_fx = add( i, 1 );
+
+ /* Ravg = (float) be_sum/Rcnt; */
+ exp_normn = norm_s( be_sum_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 */
+ QRavg = add( sub( exp_normn, exp_normd ), 15 - 2 );
+
+ test();
+ if ( be_sum_fx <= 0 )
+ {
+ be_sum_fx = 1;
+ move16();
+ }
+
+ /* Bits_avg = (float) Bits/(be_sum+EPSILON); */
+ Bits_avg_fx = 0;
+ move16();
+ QBavg = 0;
+ move16();
+ IF( Bits != 0 )
+ {
+ exp_normn = norm_s( Bits );
+ 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 */
+ QBavg = add( sub( exp_normn, exp_normd ), 15 - 2 );
+ }
+ FOR( k = 0; k <= i; k++ )
+ {
+ IF( L_R_temp[k] > 0 ) /* Rtemp -> SWB_BWE_LR_QRk */
+ {
+ /* Allocate more bits to SB, if SB bandenergy is higher than average energy */
+ /* R_temp[k] = (float)( Bits_avg * y_index[k]+( scale_fact * (y_index[k] - Ravg))); */
+ L_temp1 = L_mult( Bits_avg_fx, y_index_fx[k] ); /* QBavg+1 */
+ L_temp2 = L_mult( scale_fact_fx, sub( shl( y_index_fx[k], QRavg ), Ravg_fx ) ); /* 15+QRavg+1 */
+ L_R_temp[k] = L_add( L_shr( L_temp1, sub( add( QBavg, 1 ), SWB_BWE_LR_QRk ) ), L_shr( L_temp2, sub( add( QRavg, 16 ), SWB_BWE_LR_QRk ) ) ); /* SWB_BWE_LR_QRk */
+ }
+ }
+ IF( L_sub( L_R_temp[i], L_Bits_needed ) < 0 )
+ {
+ L_R_temp[i] = 0x0L;
+ move32();
+
+ p2aflags_fx_ptr[index_fx[i]] = 0;
+ move16();
+
+ /* be_sum -= y_index[i]; */
+ be_sum_fx = sub( be_sum_fx, y_index_fx[i] );
+
+ i = sub( i, 1 );
+ }
+ ELSE
+ {
+ BREAK;
+ }
+ }
+
+ /* Rearrange the bit allocation to align with original */
+ FOR( k = 0; k < band_num_fx; k++ )
+ {
+ j = index_fx[k];
+ move16();
+ L_R_ptr[j] = L_R_temp[k];
+ move32();
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * hq2_bit_alloc_har()
+ *
+ * Bit allocation mechanism for HQ_HARMONIC mode
+ *-------------------------------------------------------------------*/
+
+void hq2_bit_alloc_har(
+ float *y, /* i : band energy of sub-vectors */
+ int16_t B_fx, /* i : number of available bits */
+ int16_t N_fx, /* i : number of sub-vectors */
+ Word32 *L_Rsubband,
+ int16_t p2a_bands_fx,
+ int32_t L_core_brate, /* i : core bitrate */
+ int16_t p2a_flags_fx[],
+ int16_t band_width_fx[] )
+{
+ Word16 i, j, k;
+
+ Word32 L_norm_sum; /* Qbe */
+ Word32 L_Ravg_sub[GRP_SB]; /* Qbe */
+ Word32 L_temp_band_energy[BANDS_MAX]; /* Qbe */
+
+ Word16 j_fx, k_fx, Bits_grp_fx[GRP_SB];
+
+ Word32 L_temp_band_energydiff[BANDS_MAX];
+ Word16 G1_BE_DIFF_POS_fx; /* Q0 */
+ Word32 L_G1_BE_DIFF_VAL; /* Qbe Word32 */
+ Word16 final_gr_fact_pos_fx, gmax_range_fx[2], temp_fx;
+ Word16 bits_fact_fx, bits_fact1_fx; /* Q? */
+ Word16 grp_rngmax_fx[2];
+ Word16 index_fx[NB_SWB_SUBBANDS_HAR], y_index_fx[NB_SWB_SUBBANDS_HAR], esthf_bits_fx, grp_bit_avg_fx, harmonic_band_fx;
+ Word32 L_norm_sum_avg;
+ Word32 L_norm_diff; /* Qbe */
+ Word16 bits_allocweigh_fx; /* Q15 */
+ Word16 grp_bound_fx[5];
+ Word32 L_grp_thr[GRP_SB]; /* not require Word32 precission */
+ Word16 lf_hf_ge_r_fx; /* Q15 */
+ Word32 L_avg_enhf_en_diff; /* Qbe */
+
+ Word16 B_norm_fx;
+
+ Word32 L_temp, L_temp2;
+ Word16 exp, frac;
+
+ Word32 L_THR1, L_THR2, L_THR3;
+
+ Word16 exp_norm;
+ Word16 norm_sum_fx;
+ Word16 Qns; /* Q value for norm_sum_fx */
+ Word16 Inv_norm_sum_fx; /* 1/norm_sum */
+ Word16 QIns; /* Q value for Inv_norm_sum_fx */
+
+ Word16 exp_normn, exp_normd;
+ Word16 div_fx;
+
+ Word16 Inv_p2a_bands_fx;
+ Word16 QIpb;
+
+ Word16 exp_shift;
+
+ Word32 L_y[BANDS_MAX];
+
+#ifdef BASOP_NOGLOB
+ Flag Overflow;
+ Overflow = 0;
+#endif
+
+ grp_rngmax_fx[0] = 0;
+ grp_rngmax_fx[1] = 0;
+
+ for ( i = 0; i < N_fx; i++ )
+ {
+ L_y[i] = (Word32) ( y[i] * (float) pow( 2.0f, SWB_BWE_LR_Qbe ) );
+ }
+
+ L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk );
+ L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk );
+ L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk );
+
+ set_val_Word16( Bits_grp_fx, 0, GRP_SB );
+
+ /* Initialize subbands bits allocation vector based on harmonic bands */
+ harmonic_band_fx = add( sub( N_fx, p2a_bands_fx ), 1 );
+ /*printf("harmonic_band= %d %d\n", harmonic_band, harmonic_band_fx);*/
+ FOR( k = 0; k < N_fx; k++ )
+ {
+ L_Rsubband[k] = (Word32) ( C1_QRk );
+ move32(); /* Constant Value */
+ L_temp_band_energy[k] = L_y[k];
+ move32(); /* SWB_BWE_LR_Qbe */
+ }
+ final_gr_fact_pos_fx = 2;
+ move16();
+ bits_fact_fx = C1_Qbf;
+ move16();
+ bits_fact1_fx = C1_Qbf;
+ move16();
+
+ gmax_range_fx[0] = G1_RANGE;
+ move16();
+ gmax_range_fx[1] = G1G2_RANGE;
+ move16();
+
+ IF( L_sub( L_core_brate, HQ_16k40 ) == 0 )
+ {
+ gmax_range_fx[1] = add( gmax_range_fx[1], 2 );
+ move16();
+ }
+
+ /* decide each group range, for grouping spectral coefficients */
+ grp_rngmax_fx[1] = 16;
+ move16();
+ grp_rngmax_fx[0] = 7;
+ move16();
+ temp_fx = 0;
+ move16();
+ FOR( i = 0; i < 2; i++ )
+ {
+ j_fx = gmax_range_fx[i];
+ move16();
+ k_fx = 0;
+ move16();
+ test();
+ WHILE( L_sub( L_temp_band_energy[gmax_range_fx[i] - 1], L_temp_band_energy[j_fx] ) >= 0x0L && sub( j_fx, grp_rngmax_fx[i] ) < 0x0 )
+ {
+ test();
+ k_fx = add( k_fx, 1 );
+ j_fx = add( j_fx, 1 );
+ }
+
+ temp_fx = k_fx;
+ move16();
+ IF( sub( temp_fx, 1 ) > 0 )
+ {
+ FOR( temp_fx = 2; temp_fx <= k_fx; )
+ {
+ IF( L_sub( L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx] ) < 0 )
+ {
+ BREAK;
+ }
+ ELSE IF( L_sub( L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx] ) >= 0 )
+ {
+ temp_fx = add( temp_fx, 1 );
+ IF( sub( temp_fx, k_fx ) > 0 )
+ {
+ temp_fx = sub( temp_fx, 1 );
+ BREAK;
+ }
+ }
+ }
+
+ gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx );
+ }
+ ELSE
+ {
+ gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx );
+ }
+ }
+
+ grp_bound_fx[0] = 0;
+ move16();
+ FOR( i = 1; i < GRP_SB - 1; i++ )
+ {
+ grp_bound_fx[i] = gmax_range_fx[i - 1];
+ move16();
+ }
+ grp_bound_fx[i] = harmonic_band_fx;
+ move16();
+ grp_bound_fx[i + 1] = N_fx;
+ move16();
+
+
+ FOR( i = 0; i < GRP_SB; i++ )
+ {
+ L_Ravg_sub[i] = 0x0L;
+ move32();
+ FOR( j = grp_bound_fx[i]; j < grp_bound_fx[i + 1]; j++ )
+ {
+ IF( L_temp_band_energy[j] > 0x0L )
+ {
+ L_Ravg_sub[i] = L_add( L_Ravg_sub[i], L_temp_band_energy[j] );
+ move32();
+ }
+ }
+ }
+
+ L_temp_band_energydiff[0] = L_temp_band_energy[0];
+ move32();
+ FOR( j = 1; j < harmonic_band_fx; j++ )
+ {
+ L_temp_band_energydiff[j] = L_abs( L_sub( L_temp_band_energy[j], L_temp_band_energy[j - 1] ) );
+ move32();
+ }
+
+ G1_BE_DIFF_POS_fx = 0;
+ move16();
+ L_G1_BE_DIFF_VAL = 0x0L;
+ move32();
+
+ FOR( j = 1; j < harmonic_band_fx; j++ )
+ {
+ IF( L_sub( L_temp_band_energydiff[j], L_G1_BE_DIFF_VAL ) > 0 )
+ {
+ G1_BE_DIFF_POS_fx = j;
+ move16();
+ L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j];
+ move32();
+ }
+ }
+
+ test();
+ test();
+ IF( sub( G1_BE_DIFF_POS_fx, gmax_range_fx[0] ) < 0 && G1_BE_DIFF_POS_fx > 0 )
+ {
+ final_gr_fact_pos_fx = 0;
+ move16();
+ }
+ ELSE IF( sub( G1_BE_DIFF_POS_fx, gmax_range_fx[0] ) >= 0 && sub( G1_BE_DIFF_POS_fx, gmax_range_fx[1] ) < 0 )
+ {
+ final_gr_fact_pos_fx = 1;
+ move16();
+ }
+ ELSE
+ {
+ final_gr_fact_pos_fx = 2;
+ move16();
+ }
+
+ test();
+ IF( final_gr_fact_pos_fx == 0 || sub( final_gr_fact_pos_fx, 1 ) == 0 )
+ {
+ IF( L_sub( L_core_brate, HQ_16k40 ) == 0 )
+ {
+ bits_fact_fx = BITS_FACT_1p10;
+ move16(); /* 1.10f; */ /* G1 */
+ bits_fact1_fx = BITS_FACT_0p92;
+ move16(); /* 0.92f; */ /* G3 */
+ }
+ ELSE
+ {
+ bits_fact_fx = BITS_FACT_1p05;
+ move16(); /* 1.05f; */ /* G1 */
+ bits_fact1_fx = BITS_FACT_0p97;
+ move16(); /* 0.97f; */ /* G3 */
+ }
+ }
+ ELSE
+ {
+ IF( L_sub( L_core_brate, HQ_16k40 ) == 0 )
+ {
+ bits_fact_fx = BITS_FACT_0p97;
+ move16(); /* 0.97f; */ /* G1 */
+ bits_fact1_fx = BITS_FACT_1p00;
+ move16(); /* 1.00f; */ /* G3 */
+ }
+ ELSE
+ {
+ bits_fact_fx = BITS_FACT_0p92;
+ move16(); /* 0.92f; */ /* G1 */
+ bits_fact1_fx = BITS_FACT_1p00;
+ move16(); /* 1.00f; */ /* G3 */
+ }
+ }
+
+ FOR( i = 0; i < sub( N_fx, harmonic_band_fx ); i++ )
+ {
+ y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) );
+ move16();
+ index_fx[i] = add( harmonic_band_fx, i );
+ move16();
+ }
+
+ reordvct( y_index_fx, sub( N_fx, harmonic_band_fx ), index_fx );
+
+ /* Log2 */
+ L_temp = L_deposit_l( band_width_fx[index_fx[0]] );
+ exp = norm_l( L_temp );
+ frac = Log2_norm_lc( L_shl( L_temp, exp ) );
+ exp = sub( 30, exp );
+ L_temp = L_Comp( exp, frac );
+ /* ceil */
+ if ( L_and( 0x0000ffff, L_temp ) > 0 )
+ {
+ L_temp = L_add( L_temp, 0x00010000 );
+ }
+ esthf_bits_fx = extract_h( L_temp );
+
+ L_grp_thr[0] = L_THR1;
+ move32();
+ L_grp_thr[1] = L_THR2;
+ move32();
+ L_grp_thr[2] = L_THR3;
+ move32();
+ L_grp_thr[3] = L_shl( L_deposit_l( esthf_bits_fx ), SWB_BWE_LR_QRk );
+ move16();
+
+ L_norm_sum = 1;
+ move32();
+ FOR( i = 0; i < 3; i++ )
+ {
+ L_norm_sum = L_add( L_norm_sum, L_Ravg_sub[i] );
+ move32();
+ }
+
+ /*reserve bits for HF coding */
+ L_temp = L_add( L_norm_sum, L_Ravg_sub[GRP_SB - 1] );
+ exp_normn = norm_l( L_temp );
+ exp_normn = sub( exp_normn, 1 );
+ exp_normd = norm_s( N_fx );
+
+ div_fx = div_l( L_shl( L_temp, exp_normn ), shl( N_fx, exp_normd ) ); /* (Qbe+exp_normn)-(0+exp_normd)-1) */
+ L_norm_sum_avg = L_shr( L_deposit_h( div_fx ), add( sub( exp_normn, exp_normd ), 15 ) ); /* -> Qbe */
+
+ exp_norm = norm_l( L_norm_sum );
+ norm_sum_fx = extract_h( L_shl( L_norm_sum, exp_norm ) ); /* SWB_BWE_LR_Qbe+exp_norm-16 */
+ Qns = sub( add( SWB_BWE_LR_Qbe, exp_norm ), 16 );
+
+ Inv_norm_sum_fx = div_s( 0x4000 /* Q15 */, norm_sum_fx );
+ QIns = sub( 31, exp_norm ); /* 14 - (14+exp_norm-16) + 15 */
+
+ grp_bit_avg_fx = div_s_ss( B_fx, GRP_SB ); /* Q0 */
+
+ exp_normd = norm_s( p2a_bands_fx );
+ Inv_p2a_bands_fx = div_s( 0x3fff, shl( p2a_bands_fx, exp_normd ) ); /* 14-exp_normd+15 */
+ QIpb = sub( 29, exp_normd );
+
+ L_temp = L_shl( Mpy_32_16( L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx ), sub( SWB_BWE_LR_Qbe, sub( QIpb, 1 ) ) );
+ L_norm_diff = L_sub( L_temp, L_norm_sum_avg ); /* Qbe */
+
+ L_temp = Mpy_32_16( L_Ravg_sub[GRP_SB - 1], sub( GRP_SB, 1 ) ); /* Qbe+0+1 */
+ L_temp = Mpy_32_16( L_temp, Inv_norm_sum_fx ); /* Qbe+1+QIpb+1 */
+#ifdef BASOP_NOGLOB
+ lf_hf_ge_r_fx = round_fx_o( L_shl_o( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ), &Overflow ), &Overflow );
+ Overflow = 0; /* reset BASOP Overflow */
+#else
+ lf_hf_ge_r_fx = round_fx( L_shl( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ) ) );
+#endif
+
+ exp_normn = norm_s( norm_sum_fx );
+ exp_normn = sub( exp_normn, 1 );
+ exp_normd = norm_s( harmonic_band_fx );
+
+ div_fx = div_s( shl( norm_sum_fx, exp_normn ), shl( harmonic_band_fx, exp_normd ) );
+ L_avg_enhf_en_diff = L_sub( L_temp_band_energy[index_fx[0]], L_shl( L_deposit_h( div_fx ), sub( sub( SWB_BWE_LR_Qbe, ( add( Qns, sub( exp_normn, exp_normd ) ) ) ), 31 ) ) ); /* Qbe - (Qns+exp_normn-(exp_normd)+15) -16 */
+
+ IF( sub( lf_hf_ge_r_fx, 26214 ) > 0x0 && L_sub( L_avg_enhf_en_diff, (Word32) ( 8 << SWB_BWE_LR_Qbe ) ) > 0x0L ) /* 0.8=26214.4(Q15) 8.0f=131072(Qbe) */
+ {
+ bits_allocweigh_fx = 6554;
+ move16(); /* 0.2 6553.6(Q15) */
+ IF( L_norm_diff < 0x0L )
+ {
+ bits_allocweigh_fx = 13107;
+ move16(); /* 0.4 13107.2(Q15) */
+ }
+
+ /*allocate bits*/
+ /*Bits_grp[GRP_SB-1] = (int16_t)min((grp_bit_avg/p2a_bands + bits_allocweigh*norm_diff),10);*/
+ L_temp = L_mult( grp_bit_avg_fx, Inv_p2a_bands_fx ); /* Q0+QIpb+1 */
+ L_temp2 = Mpy_32_16( L_norm_diff, bits_allocweigh_fx ); /* Qbe+Q15-15 */
+
+ L_temp = L_shr( L_temp, add( QIpb, 1 ) );
+ L_temp = L_add( L_shl( L_temp, SWB_BWE_LR_Qbe ), L_temp2 );
+
+ Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) );
+ Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 );
+
+ test();
+ if ( sub( Bits_grp_fx[GRP_SB - 1], esthf_bits_fx ) < 0 )
+ {
+ Bits_grp_fx[GRP_SB - 1] = 0;
+ move16();
+ }
+ B_fx = sub( B_fx, Bits_grp_fx[GRP_SB - 1] );
+ }
+
+ exp_shift = sub( add( SWB_BWE_LR_Qbe, QIns ), 47 ); /* (SWB_BWE_LR_Qbe+14+1+QIns-15-16) */
+ exp_norm = norm_s( B_fx );
+ B_norm_fx = shl( B_fx, exp_norm );
+ exp_shift = add( exp_shift, exp_norm );
+
+ IF( sub( final_gr_fact_pos_fx, 1 ) == 0 )
+ {
+ L_temp = Mpy_32_16( L_Ravg_sub[1], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) );
+ L_temp = Mpy_32_16( L_temp, Inv_norm_sum_fx );
+ Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) );
+
+ L_temp = Mpy_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) );
+ L_temp = Mpy_32_16( L_temp, Inv_norm_sum_fx );
+ Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) );
+
+ Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] );
+ }
+ ELSE
+ {
+ L_temp = Mpy_32_16( L_Ravg_sub[0], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) );
+ L_temp = Mpy_32_16( L_temp, Inv_norm_sum_fx );
+ Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) );
+
+ L_temp = Mpy_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) );
+ L_temp = Mpy_32_16( L_temp, Inv_norm_sum_fx );
+ Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) );
+
+ Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] );
+ }
+
+ IF( sub( Bits_grp_fx[2], THR2 ) < 0 )
+ {
+ Bits_grp_fx[1] = add( Bits_grp_fx[1], Bits_grp_fx[2] );
+ move16();
+ Bits_grp_fx[2] = 0;
+ move16();
+ }
+
+ FOR( i = 0; i < GRP_SB; i++ )
+ {
+ IF( Bits_grp_fx[i] > 0 )
+ {
+ Bits2indvsb_fx( L_temp_band_energy, grp_bound_fx[i], grp_bound_fx[i + 1], Bits_grp_fx[i], L_grp_thr[i], L_Rsubband, p2a_flags_fx );
+ }
+ ELSE
+ {
+ set_val_Word32( L_Rsubband + grp_bound_fx[i], 0x0L, sub( grp_bound_fx[i + 1], grp_bound_fx[i] ) );
+ IF( sub( i, GRP_SB - 1 ) == 0 )
+ {
+ set_val_Word16( p2a_flags_fx + grp_bound_fx[i], 0, sub( grp_bound_fx[i + 1], grp_bound_fx[i] ) );
+ }
+ }
+ }
+ return;
+}
+
+void hq2_bit_alloc(
+ const float band_energy[], /* i : band energy of each subband */
+ const int16_t bands, /* i : total number of subbands in a frame */
+ Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */
+ int16_t *bit_budget_fx, /* i/o: bit bugdet */
+ int16_t *p2a_flags, /* i : HF tonal indicator */
+ const Word16 weight_fx, /* i : weight (Q13) */
+ const int16_t band_width[], /* i : Sub band bandwidth */
+ const int16_t num_bits, /* i : available bits */
+ const int16_t hqswb_clas, /* i : HQ2 class information */
+ const int16_t bwidth, /* i : input bandwidth */
+ const int16_t is_transient /* i : indicator HQ_TRANSIENT or not */
+)
+{
+ Word16 j, k;
+ Word16 tmp;
+ Word16 bit_budget_norm_fx;
+
+ Word32 L_Rcalc, L_Ravg, L_Rcalc1;
+
+ Word16 exp_normn, exp_normd;
+
+ Word16 Rcnt_fx;
+
+ Word16 div_fx;
+ Word16 Qdiv;
+
+ Word32 L_tmp;
+ Word16 tmp_fx;
+
+ Word32 L_maxxy;
+ Word16 maxdex_fx;
+ Word32 L_dummy;
+
+ Word16 bit_budget_temp_fx;
+
+ Word16 negflag;
+
+ Word32 L_THR1, L_THR2, L_THR3;
+
+ Word32 L_band_energy[BANDS_MAX];
+
+ for ( k = 0; k < bands; k++ )
+ {
+ L_band_energy[k] = (Word32) ( band_energy[k] * (float) pow( 2.0f, SWB_BWE_LR_Qbe ) );
+ }
+
+ L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk );
+ L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk );
+ L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk );
+
+ /* Init Rk to non-zero values for bands to be allocated bits */
+ IF( sub( num_bits, HQ_16k40_BIT ) <= 0 )
+ {
+ set_val_Word32( L_Rk, (Word32) ( C1_QRk ), bands ); /* 1< 0 )
+ {
+ L_Ravg = L_add( L_Ravg, L_shl( L_band_energy[k], sub( SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe ) ) ); /* SWB_BWE_LR_QRk-SWB_BWE_LR_Qbe */
+ Rcnt_fx = add( Rcnt_fx, 1 );
+ }
+ }
+ /* Ravg Qband_energy */
+
+ /*L_Ravg /= Rcnt; */
+ exp_normd = norm_l( L_Ravg );
+ exp_normd = sub( exp_normd, 1 );
+ exp_normn = norm_s( Rcnt_fx );
+
+ tmp = shl( Rcnt_fx, exp_normn );
+ tmp = s_max( tmp, 1 );
+ IF( L_Ravg > 0 )
+ {
+ div_fx = div_l( L_shl( L_Ravg, exp_normd ), tmp ); /* Qdiv = 14+exp_normd-(exp_normn)-1 */
+ }
+ ELSE
+ {
+ div_fx = div_l( L_shl( L_abs( L_Ravg ), exp_normd ), tmp ); /* Qdiv = 14+exp_normd-(exp_normn)-1 */
+ div_fx = negate( div_fx );
+ }
+
+ /*Qdiv = QRk+exp_normd-(exp_normn)-1; */
+ Qdiv = sub( sub( add( SWB_BWE_LR_QRk, exp_normd ), exp_normn ), 1 );
+
+ L_Ravg = L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) );
+
+ exp_normd = norm_s( *bit_budget_fx );
+ exp_normd = sub( exp_normd, 1 );
+ bit_budget_norm_fx = shl( *bit_budget_fx, exp_normd );
+ div_fx = 0;
+ move16();
+
+ test();
+ IF( bit_budget_norm_fx > 0 && sub( bit_budget_norm_fx, tmp ) < 0 )
+ {
+ div_fx = div_s( bit_budget_norm_fx, tmp );
+ }
+ Qdiv = add( sub( exp_normd, exp_normn ), 15 );
+
+ FOR( k = 0; k < bands; k++ )
+ {
+ IF( L_Rk[k] > 0 )
+ {
+ /*Rk[k] = ((float) *bit_budget / Rcnt + weight * (band_energy[k] - Ravg)); */
+
+ L_tmp = Mpy_32_16( L_sub( L_shl( L_band_energy[k], sub( SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe ) ), L_Ravg ), weight_fx ); /* SWB_BWE_LR_QRk + Q13 - 15 */
+ L_tmp = L_shl( L_tmp, 2 ); /* -> SWB_BWE_LR_QRk */
+
+ L_Rk[k] = L_add( L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ), L_tmp );
+ }
+ }
+
+ negflag = 0;
+ move16();
+ L_Rcalc = 0;
+ move32();
+ FOR( k = 0; k < bands; k++ )
+ {
+ IF( L_sub( L_Rk[k], MIN_BITS_FIX ) < 0 )
+ {
+ L_Rk[k] = 0x0L;
+ move32();
+ negflag = 1;
+ move16();
+ }
+ L_Rcalc = L_add( L_Rcalc, L_Rk[k] ); /*SWB_BWE_LR_QRk */
+ }
+
+ /* prune noiselike bands with low allocation */
+ IF( sub( num_bits, HQ_16k40_BIT ) <= 0 && negflag == 0 )
+ {
+ L_maxxy = 0;
+ move32();
+ maxdex_fx = -1;
+ move16();
+ L_Rcalc = 0;
+ move32();
+
+ /* find worst under-allocation */
+ FOR( k = sub( bands, 1 ); k >= 0; k-- )
+ {
+ /* dummy = ((float) min (band_width[k], max (12, band_width[k] / 4))) - Rk[k]; */
+ tmp_fx = s_min( band_width[k], s_max( 12, shr( band_width[k], 2 ) ) );
+ L_dummy = L_sub( L_shl( L_deposit_l( tmp_fx ), SWB_BWE_LR_QRk ), L_Rk[k] ); /*SWB_BWE_LR_QRk */
+ test();
+ test();
+ test();
+ IF( p2a_flags[k] == 0 && L_sub( L_dummy, L_maxxy ) > 0 && L_Rk[k] > 0 )
+ {
+ maxdex_fx = k;
+ move16();
+ L_maxxy = L_dummy;
+ move32(); /*SWB_BWE_LR_QRk */
+ }
+ }
+
+ /* prune worst allocation and recalculate total allocation */
+ IF( sub( maxdex_fx, -1 ) > 0 )
+ {
+ L_Rk[maxdex_fx] = 0;
+ move32();
+ }
+ FOR( k = 0; k < bands; k++ )
+ {
+ L_Rcalc = L_add( L_Rcalc, L_Rk[k] ); /*SWB_BWE_LR_QRk */
+ }
+ }
+ test();
+ IF( L_sub( L_Rcalc, L_Rcalc1 ) == 0 && sub( bwidth, SWB ) == 0 )
+ {
+ /* Reallocate bits to individual subbands for HQ_NORMAL mode */
+ /* if bits allocated to subbands areless than predefined threshold */
+ IF( sub( hqswb_clas, HQ_NORMAL ) == 0 && sub( num_bits, HQ_16k40_BIT ) < 0 )
+ {
+ L_dummy = 0x0L;
+ move32();
+ FOR( k = 0; k < bands; k++ )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( sub( k, 11 ) < 0 && L_sub( L_Rk[k], L_THR1 ) < 0 )
+ {
+ L_Rk[k] = 0x0L;
+ move32();
+ }
+ ELSE IF( sub( k, 11 ) >= 0 && sub( k, 16 ) < 0 && L_sub( L_Rk[k], L_THR2 ) < 0 )
+ {
+ L_Rk[k] = 0x0L;
+ move32();
+ }
+ ELSE IF( sub( k, 16 ) >= 0 && sub( k, bands ) < 0 && L_sub( L_Rk[k], L_THR3 ) < 0 )
+ {
+ L_Rk[k] = 0x0L;
+ move32();
+ }
+
+ L_dummy = L_add( L_dummy, L_Rk[k] );
+ }
+
+ IF( L_sub( L_dummy, L_Rcalc ) == 0 )
+ {
+ test();
+ IF( sub( hqswb_clas, HQ_NORMAL ) == 0 && sub( num_bits, HQ_16k40_BIT ) < 0 )
+ {
+ bit_budget_temp_fx = *bit_budget_fx;
+ move16();
+ FOR( k = 0; k < NB_SWB_SUBBANDS; k++ )
+ {
+ IF( p2a_flags[bands - NB_SWB_SUBBANDS + k] == 1 && L_Rk[bands - NB_SWB_SUBBANDS + k] == 0.0f )
+ {
+ p2a_flags[bands - NB_SWB_SUBBANDS + k] = 0;
+ move16();
+ bit_budget_temp_fx = sub( bit_budget_temp_fx, bits_lagIndices_modeNormal[k] );
+ }
+ }
+
+ IF( sub( bit_budget_temp_fx, *bit_budget_fx ) < 0 )
+ {
+ *bit_budget_fx = bit_budget_temp_fx;
+ move16();
+ /* a negative *bit_budget_fx may occur here due to Bit Errors */
+ /* handled outside this function to properly set flag: st_fx->BER_detect */
+ }
+ ELSE IF( sub( bit_budget_temp_fx, *bit_budget_fx ) == 0 )
+ {
+ BREAK;
+ }
+ }
+ ELSE
+ {
+ BREAK;
+ }
+ }
+ }
+ ELSE
+ {
+ BREAK;
+ }
+ }
+ ELSE IF( L_sub( L_Rcalc, L_Rcalc1 ) == 0 && sub( bwidth, SWB ) != 0 )
+ {
+ BREAK;
+ }
+
+ L_Rcalc1 = L_Rcalc;
+ move32();
+ }
+ return;
+}
+
+#undef WMC_TOOL_SKIP
diff --git a/lib_com/hq2_core_com.c b/lib_com/hq2_core_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..280d492ae6b121107e41e2ea1d2a1ee341f98543
--- /dev/null
+++ b/lib_com/hq2_core_com.c
@@ -0,0 +1,581 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "basop_util.h"
+#include "basop_proto_func.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * mdct_spectrum_denorm()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void mdct_spectrum_denorm(
+ const int32_t inp_vector[],
+ float y2[],
+ const int16_t band_start[],
+ const int16_t band_end[],
+ const int16_t band_width[],
+ const float band_energy[],
+ const int16_t npulses[],
+ const int16_t bands,
+ const float ld_slope,
+ const float pd_thresh )
+{
+ int16_t i, k;
+ float Eyy, gamma, pd, gain_tweak;
+
+ for ( k = 0; k < bands; k++ )
+ {
+ Eyy = 0;
+ for ( i = band_start[k]; i <= band_end[k]; i++ )
+ {
+ Eyy += (float) inp_vector[i] * inp_vector[i];
+ }
+
+ if ( Eyy > 0.0f )
+ {
+ /* Set gamma to be pulse gain which results in perfect quantized subband energy */
+ gamma = (float) sqrt( pow( 2.0f, band_energy[k] ) / Eyy );
+
+ /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */
+ pd = (float) npulses[k] / band_width[k];
+ if ( pd < pd_thresh )
+ {
+ gain_tweak = (float) pow( 2.0f, ( ld_slope * log2_f( pd / pd_thresh ) ) );
+ gamma *= gain_tweak;
+ }
+
+ for ( i = band_start[k]; i <= band_end[k]; i++ )
+ {
+ y2[i] = gamma * inp_vector[i];
+ }
+ }
+ }
+
+ return;
+}
+/*--------------------------------------------------------------------------*
+ * hq2_core_configure()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void hq2_core_configure(
+ const int16_t frame_length, /* i : frame length */
+ const int16_t num_bits, /* i : number of bits */
+ const int16_t is_transient, /* i : transient flag */
+ int16_t *bands,
+ int16_t *length,
+ int16_t band_width[],
+ int16_t band_start[],
+ int16_t band_end[],
+ Word32 *L_qint,
+ Word16 *eref_fx,
+ Word16 *bit_alloc_weight_fx,
+ int16_t *gqlevs,
+ int16_t *Ngq,
+ int16_t *p2a_bands,
+ float *p2a_th,
+ float *pd_thresh,
+ float *ld_slope,
+ float *ni_coef,
+ float *ni_pd_th,
+ int32_t bwe_br )
+{
+ const Xcore_Config *xcore_config;
+
+ int16_t i, k;
+ int16_t bands_sh;
+
+ if ( frame_length == L_FRAME8k )
+ {
+ if ( is_transient )
+ {
+ if ( num_bits <= ACELP_7k20 / FRAMES_PER_SEC )
+ {
+ xcore_config = &xcore_config_8kHz_007200bps_short;
+ }
+ else if ( num_bits <= ACELP_8k00 / FRAMES_PER_SEC )
+ {
+ xcore_config = &xcore_config_8kHz_008000bps_short;
+ }
+ else if ( num_bits <= ACELP_13k20 / FRAMES_PER_SEC )
+ {
+ xcore_config = &xcore_config_8kHz_013200bps_short;
+ }
+ else
+ {
+ xcore_config = &xcore_config_8kHz_016400bps_short;
+ }
+ }
+ else
+ {
+ if ( num_bits <= ACELP_7k20 / FRAMES_PER_SEC )
+ {
+ xcore_config = &xcore_config_8kHz_007200bps_long;
+ }
+ else if ( num_bits <= ACELP_8k00 / FRAMES_PER_SEC )
+ {
+ xcore_config = &xcore_config_8kHz_008000bps_long;
+ }
+ else if ( num_bits <= ACELP_13k20 / FRAMES_PER_SEC )
+ {
+ xcore_config = &xcore_config_8kHz_013200bps_long;
+ }
+ else
+ {
+ xcore_config = &xcore_config_8kHz_016400bps_long;
+ }
+ }
+ }
+ else if ( frame_length == L_FRAME16k )
+ {
+ if ( is_transient )
+ {
+ if ( num_bits <= ACELP_13k20 / FRAMES_PER_SEC )
+ {
+ xcore_config = &xcore_config_16kHz_013200bps_short;
+ }
+ else
+ {
+ xcore_config = &xcore_config_16kHz_016400bps_short;
+ }
+ }
+ else
+ {
+ if ( num_bits <= ACELP_13k20 / FRAMES_PER_SEC )
+ {
+ xcore_config = &xcore_config_16kHz_013200bps_long;
+ }
+ else
+ {
+ xcore_config = &xcore_config_16kHz_016400bps_long;
+ }
+ }
+ }
+ else /* (bwidth == SWB) */
+ {
+ if ( is_transient )
+ {
+ if ( bwe_br == ACELP_13k20 )
+ {
+ xcore_config = &xcore_config_32kHz_013200bps_short;
+ }
+ else
+ {
+ xcore_config = &xcore_config_32kHz_016400bps_short;
+ }
+ }
+ else
+ {
+ if ( bwe_br == ACELP_13k20 )
+ {
+ xcore_config = &xcore_config_32kHz_013200bps_long;
+ }
+ else
+ {
+ xcore_config = &xcore_config_32kHz_016400bps_long;
+ }
+ }
+ }
+
+ *bands = xcore_config->bands;
+ *length = xcore_config->bw;
+ *L_qint = xcore_config->L_qint;
+ *eref_fx = xcore_config->eref_fx;
+ *bit_alloc_weight_fx = xcore_config->bit_alloc_weight_fx;
+ *gqlevs = xcore_config->gqlevs;
+ *Ngq = xcore_config->Ngq;
+
+ *p2a_bands = xcore_config->p2a_bands;
+ *p2a_th = xcore_config->p2a_th;
+
+ *pd_thresh = xcore_config->pd_thresh;
+ *ld_slope = xcore_config->ld_slope;
+ *ni_coef = xcore_config->ni_coef;
+ *ni_pd_th = xcore_config->ni_pd_th;
+
+ mvs2s( xcore_config->band_width, band_width, *bands );
+
+ /* Expand band_width[] table for short windows */
+ if ( is_transient )
+ {
+ bands_sh = *bands;
+ *bands = NUM_TIME_SWITCHING_BLOCKS * bands_sh;
+ *length *= NUM_TIME_SWITCHING_BLOCKS;
+
+ for ( i = 1; i <= 3; i++ )
+ {
+ for ( k = 0; k < bands_sh; k++ )
+ {
+ band_width[i * bands_sh + k] = band_width[k];
+ }
+ }
+ }
+
+ /* Formulate band_start and band_end tables from band_width table */
+ band_start[0] = 0;
+ band_end[0] = band_width[0] - 1;
+ for ( k = 1; k < *bands; k++ )
+ {
+ band_start[k] = band_start[k - 1] + band_width[k - 1];
+ band_end[k] = band_start[k] + band_width[k] - 1;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * reverse_transient_frame_energies()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void reverse_transient_frame_energies(
+ float band_energy[], /* o : band energies */
+ const int16_t bands /* i : number of bands */
+)
+{
+ int16_t k, k1, k2;
+ float be;
+
+ k1 = bands / 4;
+ k2 = bands / 2 - 1;
+ for ( k = 0; k < bands / 8; k++ )
+ {
+ be = band_energy[k1];
+ band_energy[k1] = band_energy[k2];
+ band_energy[k2] = be;
+ k1++, k2--;
+ }
+
+ k1 = 3 * bands / 4;
+ k2 = bands - 1;
+ for ( k = 0; k < bands / 8; k++ )
+ {
+ be = band_energy[k1];
+ band_energy[k1] = band_energy[k2];
+ band_energy[k2] = be;
+ k1++, k2--;
+ }
+
+ return;
+}
+
+#define WMC_TOOL_SKIP
+void bit_allocation_second_fx(
+ Word32 *Rk,
+ Word32 *Rk_sort,
+ Word16 BANDS,
+ const Word16 *band_width,
+ Word16 *k_sort,
+ Word16 *k_num,
+ const Word16 *p2a_flags,
+ const Word16 p2a_bands,
+ const Word16 *last_bitalloc,
+ const Word16 input_frame )
+{
+ Word16 k, k2 = 0;
+ Word16 ever_bits[BANDS_MAX], ever_sort[BANDS_MAX]; /*Q12 */
+ Word16 class_flag = 0;
+ Word16 rk_temp = 32767, ever_temp = 32767; /*Q12 */
+ Word16 exp;
+ Word16 tmp;
+ Word32 L_tmp;
+
+ for ( k = 0; k < BANDS; k++ )
+ {
+ if ( ( ( sub( k_sort[k], sub( BANDS, p2a_bands ) ) >= 0 ) && ( sub( p2a_flags[k_sort[k]], 1 ) == 0 ) ) ||
+ ( ( sub( k_sort[k], sub( BANDS, 2 ) ) >= 0 ) && ( sub( last_bitalloc[sub( k_sort[k], sub( BANDS, 2 ) )], 1 ) == 0 ) ) )
+ {
+ exp = norm_s( band_width[k_sort[k]] );
+ tmp = shl( band_width[k_sort[k]], exp ); /*Q(exp) */
+ tmp = div_s( 16384, tmp ); /*Q(15+14-exp = 29-exp) */
+ L_tmp = Mult_32_16( Rk_sort[k], tmp ); /* Q(16+29-exp-15 = 30-exp) */
+ tmp = sub( 18, exp );
+ ever_bits[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */
+ if ( sub( ever_bits[k], rk_temp ) < 0 )
+ {
+ rk_temp = ever_bits[k];
+ k2 = k;
+ }
+ class_flag = 1;
+ }
+ }
+ if ( class_flag == 0 || sub( input_frame, L_FRAME8k ) == 0 )
+ {
+ for ( k = 0; k < BANDS; k++ )
+ {
+ if ( sub( k_sort[k], sub( BANDS, p2a_bands ) ) < 0 && Rk_sort[k] > 0 )
+ {
+ exp = norm_s( band_width[k_sort[k]] );
+ tmp = shl( band_width[k_sort[k]], exp ); /*Q(exp) */
+ tmp = div_s( 16384, tmp ); /*Q(15+14-exp = 29-exp) */
+ L_tmp = Mult_32_16( Rk_sort[k], tmp ); /* Q(16+29-exp-15 = 30-exp) */
+ tmp = sub( 18, exp );
+ ever_sort[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */
+ IF( sub( ever_sort[k], ever_temp ) < 0 )
+ {
+ ever_temp = ever_sort[k];
+ k2 = k;
+ }
+ }
+ }
+ }
+
+ k_num[0] = k2;
+ if ( sub( k_sort[k2], sub( BANDS, 1 ) ) == 0 )
+ {
+ for ( k = 0; k < BANDS; k++ )
+ {
+ if ( sub( k_sort[k], sub( k_sort[k2], 1 ) ) == 0 )
+ {
+ k_num[1] = k;
+ }
+ }
+ }
+ else if ( k_sort[k2] == 0 )
+ {
+ for ( k = 0; k < BANDS; k++ )
+ {
+ if ( sub( k_sort[k], add( k_sort[k2], 1 ) ) == 0 )
+ {
+ k_num[1] = k;
+ }
+ }
+ }
+ else
+ {
+ if ( L_sub( Rk[sub( k_sort[k2], 1 )], Rk[add( k_sort[k2], 1 )] ) < 0 )
+ {
+ for ( k = 0; k < BANDS; k++ )
+ {
+ if ( sub( k_sort[k], sub( k_sort[k2], 1 ) ) == 0 )
+ {
+ k_num[1] = k;
+ }
+ }
+ }
+ else
+ {
+ for ( k = 0; k < BANDS; k++ )
+ {
+ if ( sub( k_sort[k], add( k_sort[k2], 1 ) ) == 0 )
+ {
+ k_num[1] = k;
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+#undef WMC_TOOL_SKIP
+
+/*--------------------------------------------------------------------------*
+ * spt_shorten_domain_pre()
+ *
+ * Compute shorten subband if previous frame has spectral peak.
+ *--------------------------------------------------------------------------*/
+
+void spt_shorten_domain_pre(
+ const int16_t band_start[], /* i : Starting position of sub band */
+ const int16_t band_end[], /* i : End position of sub band */
+ const int16_t prev_SWB_peak_pos[], /* i : Spectral peak */
+ const int16_t BANDS, /* i : total number of bands */
+ const int32_t bwe_br, /* i : bitrate information */
+ int16_t new_band_start[], /* o : Starting position of new shorten sub band */
+ int16_t new_band_end[], /* o : End position of new shorten sub band */
+ int16_t new_band_width[] /* o : new sub band bandwidth */
+)
+{
+ int16_t j, k, kpos;
+
+ int16_t new_band_width_half;
+ const int16_t *p_bw_SPT_tbl; /* pointer of bw_SPT_tbl */
+
+ p_bw_SPT_tbl = bw_SPT_tbl[0];
+ if ( bwe_br == HQ_16k40 )
+ {
+ p_bw_SPT_tbl = bw_SPT_tbl[1];
+ }
+
+ kpos = 0;
+ j = 0;
+ for ( k = BANDS - SPT_SHORTEN_SBNUM; k < BANDS; k++ )
+ {
+ if ( prev_SWB_peak_pos[kpos] != 0 )
+ {
+ new_band_width[j] = p_bw_SPT_tbl[j];
+
+ /*shorten the bandwidth for pulse resolution*/
+ new_band_width_half = new_band_width[j] / 2;
+ new_band_start[j] = prev_SWB_peak_pos[kpos] - new_band_width_half;
+ new_band_end[j] = prev_SWB_peak_pos[kpos] + new_band_width_half;
+
+ if ( new_band_start[j] < band_start[k] )
+ {
+ new_band_start[j] = band_start[k];
+ new_band_end[j] = new_band_start[j] + ( new_band_width[j] - 1 );
+ }
+ else if ( new_band_end[j] > band_end[k] )
+ {
+ new_band_end[j] = band_end[k];
+ new_band_start[j] = new_band_end[j] - ( new_band_width[j] - 1 );
+ }
+ }
+ else
+ {
+ new_band_width[j] = p_bw_SPT_tbl[j];
+
+ /*shorten the bandwidth for pulse resolution*/
+ new_band_width_half = new_band_width[j] / 2;
+ new_band_start[j] = ( band_start[k] + band_end[k] ) / 2 - new_band_width_half;
+ new_band_end[j] = ( band_start[k] + band_end[k] ) / 2 + new_band_width_half;
+ }
+
+ kpos++;
+ j++;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * spt_shorten_domain_band_save()
+ *
+ * Store the original subband information
+ *--------------------------------------------------------------------------*/
+
+void spt_shorten_domain_band_save(
+ const int16_t bands, /* i : total subband */
+ const int16_t band_start[], /* i : starting position of subband */
+ const int16_t band_end[], /* i : end position of subband */
+ const int16_t band_width[], /* i : band width of subband */
+ int16_t org_band_start[], /* o : starting position of subband */
+ int16_t org_band_end[], /* o : end position of subband */
+ int16_t org_band_width[] /* o : band width of subband */
+)
+{
+ int16_t k, kpos;
+
+ kpos = 0;
+ for ( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ )
+ {
+ org_band_start[kpos] = band_start[k];
+ org_band_end[kpos] = band_end[k];
+ org_band_width[kpos] = band_width[k];
+ kpos++;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * spt_shorten_domain_band_restore()
+ *
+ * Restrore the subband information
+ *--------------------------------------------------------------------------*/
+
+void spt_shorten_domain_band_restore(
+ const int16_t bands, /* i : total subband */
+ int16_t band_start[], /* i/o: starting position of subband */
+ int16_t band_end[], /* i/o: end position of subband */
+ int16_t band_width[], /* i/o: band width of subband */
+ const int16_t org_band_start[], /* o : starting position of subband */
+ const int16_t org_band_end[], /* o : end position of subband */
+ const int16_t org_band_width[] /* o : band width of subband */
+)
+{
+ int16_t k, kpos;
+
+ kpos = 0;
+ for ( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ )
+ {
+ band_start[k] = org_band_start[kpos];
+ band_end[k] = org_band_end[kpos];
+ band_width[k] = org_band_width[kpos];
+ kpos++;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * spt_swb_peakpos_tmp_save
+ *
+ * Save Peak position for every higher subband
+ *--------------------------------------------------------------------------*/
+
+void spt_swb_peakpos_tmp_save(
+ const float y2[], /* i : coded spectral information */
+ const int16_t bands, /* i : total number of bands */
+ const int16_t band_start[], /* i : starting position of subband */
+ const int16_t band_end[], /* i : end position of subband */
+ int16_t prev_SWB_peak_pos_tmp[] /* o : spectral peaks */
+)
+{
+
+ int16_t i, j, k;
+ float peak_max;
+
+ j = 0;
+ for ( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ )
+ {
+ peak_max = 0;
+ prev_SWB_peak_pos_tmp[j] = 0;
+ for ( i = band_start[k]; i <= band_end[k]; i++ )
+ {
+ if ( peak_max < fabs( y2[i] ) )
+ {
+ peak_max = (float) fabs( y2[i] );
+ prev_SWB_peak_pos_tmp[j] = i;
+ }
+ }
+ j++;
+ }
+
+ return;
+}
diff --git a/lib_com/hq2_noise_inject.c b/lib_com/hq2_noise_inject.c
new file mode 100644
index 0000000000000000000000000000000000000000..ed48dab7b908ac6e257549f5396e3a23f565996c
--- /dev/null
+++ b/lib_com/hq2_noise_inject.c
@@ -0,0 +1,275 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * hq2_noise_inject()
+ *
+ * HQ2 noise injection for WB signals
+ *--------------------------------------------------------------------------*/
+
+void hq2_noise_inject(
+ float y2hat[],
+ const int16_t band_start[],
+ const int16_t band_end[],
+ const int16_t band_width[],
+ float Ep[],
+ float Rk[],
+ const int16_t npulses[],
+ int16_t ni_seed,
+ const int16_t bands,
+ const int16_t ni_start_band,
+ const int16_t bw_low,
+ const int16_t bw_high,
+ const float enerL,
+ const float enerH,
+ float last_ni_gain[],
+ float last_env[],
+ int16_t *last_max_pos_pulse,
+ int16_t *p2a_flags,
+ int16_t p2a_bands,
+ const int16_t hqswb_clas,
+ const int16_t bwidth,
+ const int32_t bwe_br )
+{
+ int16_t i, j, k, ni_end_band, satur = 0, count[BANDS_MAX], max_pos_pulse, pos;
+ float ni_gain[BANDS_MAX], pd[BANDS_MAX], rand, peak[BANDS_MAX], fac, env[BANDS_MAX];
+ int16_t sb = bands;
+
+ if ( ( hqswb_clas == HQ_HARMONIC || hqswb_clas == HQ_NORMAL ) && ( bwe_br == HQ_16k40 || bwe_br == HQ_13k20 ) && bwidth == SWB )
+ {
+ sb = ( bwe_br == HQ_16k40 ) ? 19 : 17;
+ }
+
+ /* calculate the envelopes/ the decoded peak coeff./number of the decoded coeff./ the last subbands of the bit-allocated/saturation of bit-allocation */
+ ni_end_band = bands;
+ max_pos_pulse = bands;
+ for ( k = ni_start_band; k < ni_end_band; k++ )
+ {
+ pd[k] = (float) Rk[k] / band_width[k];
+ env[k] = (float) sqrt( Ep[k] / band_width[k] );
+
+ peak[k] = 0.0f;
+ count[k] = 0;
+ if ( npulses[k] != 0 )
+ {
+ for ( i = band_start[k]; i <= band_end[k]; i++ )
+ {
+ Ep[k] -= y2hat[i] * y2hat[i];
+ if ( fabs( y2hat[i] ) > peak[k] )
+ {
+ peak[k] = (float) fabs( y2hat[i] );
+ }
+
+ if ( y2hat[i] != 0 )
+ {
+ count[k]++;
+ }
+ }
+
+ max_pos_pulse = k;
+ Ep[k] = Ep[k] > 0 ? (float) sqrt( Ep[k] / band_width[k] ) : 0.0f;
+ }
+ else
+ {
+ Ep[k] = env[k];
+ }
+ }
+
+ for ( k = ni_start_band; k < ni_end_band; k++ )
+ {
+ /* calculate the noise gain */
+ satur = ( pd[k] >= 0.8f ) ? 1 : 0;
+ if ( satur == 0 && Ep[k] > 0 )
+ {
+ if ( npulses[k] != 0 )
+ {
+ if ( bwidth == SWB )
+ {
+ if ( hqswb_clas != HQ_TRANSIENT )
+ {
+ if ( hqswb_clas == HQ_HARMONIC )
+ {
+ fac = ( k <= sb ) ? 6.0f * ( 1.5f - pd[k] ) * env[k] * Ep[k] / ( peak[k] * peak[k] ) : 1.5f * Ep[k] / peak[k];
+ }
+ else
+ {
+ fac = ( k <= sb ) ? 5.0f * ( 1.5f - pd[k] ) * Ep[k] / ( peak[k] ) : 4.0f * Ep[k] / peak[k];
+ }
+ }
+ else
+ {
+ fac = 1.1f;
+ }
+ }
+ else
+ {
+ fac = 20.0f * min( 1.0f, ( 1.5f - pd[k] ) ) * env[k] * Ep[k] / ( peak[k] * peak[k] );
+ if ( k > 1 && k < ni_end_band - 1 )
+ {
+ if ( count[k + 1] == 0 && env[k] > 0.5f * env[k + 1] && env[k] < 2.0f * env[k - 1] )
+ {
+ fac = 1.5f * env[k + 1] / env[k];
+ }
+ else if ( count[k - 1] == 0 && peak[k] > 2.0f * env[k] )
+ {
+ fac = env[k - 1] / env[k];
+ }
+ }
+
+ if ( k >= ni_end_band - p2a_bands && bwidth == WB )
+ {
+ if ( bw_low * enerH > bw_high * enerL && peak[k] < 2.0f * env[k] )
+ {
+ fac *= ( 2.0f - Ep[k] / peak[k] );
+ }
+
+ if ( p2a_flags[k] == 0 && fac > 0 )
+ {
+ fac *= min( 1.25f * env[k] / ( Ep[k] * fac ), 1.5f );
+ }
+ }
+ }
+ }
+ else
+ {
+ fac = ( hqswb_clas == HQ_HARMONIC && bwidth == SWB ) ? 0.8f : 1.1f;
+ }
+
+ ni_gain[k] = fac * Ep[k];
+ }
+ else
+ {
+ ni_gain[k] = 0.0;
+ }
+
+ /* smooth the noise gain between the current frame and the previous frame */
+ pos = bwidth == SWB ? ni_end_band - 1 : max( max_pos_pulse, *last_max_pos_pulse );
+
+ if ( k <= pos )
+ {
+ if ( k > 0 && k < ni_end_band - 1 )
+ {
+ if ( ( env[k] > 0.5f * last_env[k] && env[k] < 2.0f * last_env[k] ) ||
+ ( ( ( env[k] + env[k - 1] + env[k + 1] ) > 0.5f * ( last_env[k] + last_env[k - 1] + last_env[k + 1] ) ) &&
+ ( ( env[k] + env[k - 1] + env[k + 1] ) < 2.0f * ( last_env[k] + last_env[k - 1] + last_env[k + 1] ) ) ) )
+ {
+ if ( ni_gain[k] > last_ni_gain[k] )
+ {
+ ni_gain[k] = 0.2f * ni_gain[k] + 0.8f * last_ni_gain[k];
+ }
+ else
+ {
+ ni_gain[k] = 0.6f * ni_gain[k] + 0.4f * last_ni_gain[k];
+ }
+ }
+ }
+ else if ( k == ni_end_band - 1 )
+ {
+ if ( ( env[k] > 0.5f * last_env[k] && env[k] < 2.0f * last_env[k] ) ||
+ ( ( env[k] + env[k - 1] ) > 0.5f * ( last_env[k] + last_env[k - 1] ) &&
+ ( env[k] + env[k - 1] ) < 2.0f * ( last_env[k] + last_env[k - 1] ) ) )
+ {
+ if ( ni_gain[k] > last_ni_gain[k] )
+ {
+ ni_gain[k] = 0.2f * ni_gain[k] + 0.8f * last_ni_gain[k];
+ }
+ else
+ {
+ ni_gain[k] = 0.6f * ni_gain[k] + 0.4f * last_ni_gain[k];
+ }
+ }
+ }
+ }
+
+ /* inject noise into the non-decoded coeffs */
+ if ( k >= ni_end_band - p2a_bands && p2a_flags[k] == 0 && bwidth != SWB )
+ {
+ for ( i = band_start[k]; i <= band_end[k]; i++ )
+ {
+ if ( y2hat[i] != 0 )
+ {
+ y2hat[i] *= 0.8f;
+ }
+ }
+ }
+
+ if ( k == max_pos_pulse && k < bands - p2a_bands && satur != 1 && bwidth != SWB )
+ {
+ j = 0;
+ if ( ni_gain[k] < 0.01f )
+ {
+ fac = 0.0f;
+ }
+ else
+ {
+ fac = max( Ep[k] / ni_gain[k], 1.0f );
+ }
+ for ( i = band_start[k]; i <= band_end[k]; i++ )
+ {
+ if ( y2hat[i] == 0 )
+ {
+ rand = own_random( &ni_seed ) / PCM16_TO_FLT_FAC;
+ y2hat[i] += ( fac - ( ( fac - 1.0f ) * j ) / band_width[k] ) * ni_gain[k] * rand;
+ }
+
+ j++;
+ }
+ }
+ else
+ {
+ for ( i = band_start[k]; i <= band_end[k]; i++ )
+ {
+ if ( y2hat[i] == 0 )
+ {
+ rand = own_random( &ni_seed ) / PCM16_TO_FLT_FAC;
+ y2hat[i] += ni_gain[k] * rand;
+ }
+ }
+ }
+ }
+
+ mvr2r( env, last_env, ni_end_band );
+ mvr2r( ni_gain, last_ni_gain, ni_end_band );
+ *last_max_pos_pulse = max_pos_pulse;
+
+ return;
+}
diff --git a/lib_com/hq_bit_allocation.c b/lib_com/hq_bit_allocation.c
new file mode 100644
index 0000000000000000000000000000000000000000..7556ed505a072a6abf0d2a06c10b43ba50684ca2
--- /dev/null
+++ b/lib_com/hq_bit_allocation.c
@@ -0,0 +1,220 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * hq_bit_allocation()
+ *
+ * Assign bits for HQ fine structure coding with PVQ
+ *--------------------------------------------------------------------------*/
+
+void hq_bit_allocation(
+ const int32_t core_brate, /* i : Core bitrate */
+ const int16_t length, /* i : Frame length */
+ const int16_t hqswb_clas, /* i : HQ class */
+ int16_t *num_bits, /* i/o: Remaining bit budget */
+ const int16_t *normqlg2, /* i : Quantized norms */
+ const int16_t nb_sfm, /* i : Number sub bands to be encoded */
+ const int16_t *sfmsize, /* i : Sub band bandwidths */
+ float *noise_level, /* o : HVQ noise level */
+ int16_t *R, /* o : Bit allocation per sub band */
+ int16_t *Rsubband, /* o : Fractional bit allocation (Q3) */
+ int16_t *sum, /* o : Sum of allocated shape bits */
+ int16_t *core_sfm, /* o : Last coded band in core */
+ const int16_t num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */
+)
+{
+ int16_t sfm_limit = nb_sfm;
+ int16_t i;
+ int16_t idx[NB_SFM];
+ int16_t wnorm[NB_SFM];
+ int16_t avrg_wnorm;
+ int16_t E_low;
+ int16_t E_hb_mean;
+ int16_t E_max;
+ int16_t i_max;
+
+
+ set_s( R, 0, NB_SFM );
+ for ( i = 0; i < nb_sfm; i++ )
+ {
+ idx[i] = i;
+ }
+ if ( hqswb_clas != HQ_TRANSIENT && hqswb_clas != HQ_HVQ && !( length == L_FRAME16k && core_brate <= HQ_32k ) )
+ {
+ /* 'nf_idx' 2-bits index written later */
+ *num_bits -= 2;
+ }
+
+ if ( hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB )
+ {
+ if ( core_brate >= HQ_32k )
+ {
+ *num_bits -= HQ_GENERIC_SWB_NBITS2;
+ }
+ else
+ {
+ *num_bits -= HQ_GENERIC_SWB_NBITS;
+ }
+
+ if ( length == L_SPEC48k )
+ {
+ *num_bits -= HQ_GENERIC_FB_NBITS;
+ }
+ }
+
+ if ( ( length == L_SPEC48k ) && ( hqswb_clas != HQ_HARMONIC ) && ( hqswb_clas != HQ_HVQ ) )
+ {
+ map_quant_weight( normqlg2, wnorm, hqswb_clas == HQ_TRANSIENT );
+ }
+ else
+ {
+ mvs2s( normqlg2, wnorm, nb_sfm );
+ }
+
+
+ if ( hqswb_clas == HQ_HARMONIC )
+ {
+ /* classification and limit bandwidth for bit allocation */
+ sfm_limit -= 2;
+ limit_band_noise_level_calc( wnorm, &sfm_limit, core_brate, noise_level );
+
+ /* Detect important band in high frequency region */
+ E_low = sum_s( wnorm, SFM_G1 );
+ i_max = 0;
+ E_max = MIN16B;
+ E_hb_mean = 0;
+ for ( i = SFM_G1; i < nb_sfm; i++ )
+ {
+ E_hb_mean += wnorm[i];
+ if ( wnorm[i] > E_max )
+ {
+ E_max = wnorm[i];
+ i_max = i;
+ }
+ }
+ E_hb_mean = E_hb_mean >> 4; /* Truncated division by SFM_G1 */
+ if ( E_max * 15 < E_low || E_max * 0.67 < E_hb_mean || i_max < sfm_limit )
+ {
+ i_max = 0;
+ }
+
+ set_s( wnorm + sfm_limit, -20, nb_sfm - sfm_limit );
+ if ( i_max > 0 )
+ {
+ wnorm[i_max] = E_max;
+ }
+ }
+
+ if ( hqswb_clas == HQ_HVQ )
+ {
+ *sum = 0;
+ }
+ else if ( hqswb_clas == HQ_GEN_SWB || ( hqswb_clas == HQ_TRANSIENT && length == L_FRAME32k && core_brate <= HQ_32k ) )
+ {
+ *sum = BitAllocF( wnorm, core_brate, *num_bits, nb_sfm, R, Rsubband, hqswb_clas, num_env_bands );
+ }
+ else if ( length == L_FRAME16k && core_brate <= HQ_32k )
+ {
+ if ( hqswb_clas != HQ_TRANSIENT )
+ {
+ avrg_wnorm = wnorm[10];
+ for ( i = 11; i < 18; i++ )
+ {
+ avrg_wnorm += wnorm[i];
+ }
+
+ avrg_wnorm /= 8;
+ for ( i = 0; i < 4; i++ )
+ {
+ if ( wnorm[i] < avrg_wnorm )
+ {
+ wnorm[i] = avrg_wnorm;
+ }
+ }
+
+ /* Estimate number of bits per band */
+ *sum = BitAllocWB( wnorm, *num_bits, nb_sfm, R, Rsubband );
+ }
+ else
+ {
+ reordvct( wnorm, nb_sfm, idx );
+ bitalloc( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas );
+ bitallocsum( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize );
+ }
+ }
+ else
+ {
+ reordvct( wnorm, nb_sfm, idx );
+
+ /* enlarge the wnorm value so that more bits can be allocated to (sfm_limit/2 ~ sfm_limit) range */
+ if ( hqswb_clas == HQ_HARMONIC )
+ {
+ for ( i = sfm_limit / 2; i < sfm_limit; i++ )
+ {
+ wnorm[i] = wnorm[sfm_limit / 2 - 1];
+ }
+ }
+
+ bitalloc( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas );
+ bitallocsum( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize );
+ }
+
+ /* Find last coded core band */
+ *core_sfm = nb_sfm - 1;
+ if ( hqswb_clas == HQ_NORMAL || hqswb_clas == HQ_HARMONIC )
+ {
+ *core_sfm = find_last_band( R, nb_sfm );
+ }
+ else if ( hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB )
+ {
+ *core_sfm = find_last_band( R, nb_sfm );
+ if ( *core_sfm < num_env_bands )
+ {
+ *core_sfm = num_env_bands - 1;
+ }
+ }
+
+ *num_bits -= *sum;
+
+ return;
+}
diff --git a/lib_com/hq_conf.c b/lib_com/hq_conf.c
new file mode 100644
index 0000000000000000000000000000000000000000..d0f7939210c00e523e6231d7e9675e855d8a4373
--- /dev/null
+++ b/lib_com/hq_conf.c
@@ -0,0 +1,255 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * hq_configure()
+ *
+ * Configuration routine for HQ mode
+ *--------------------------------------------------------------------------*/
+
+void hq_configure(
+ const int16_t length, /* i : Frame length */
+ const int16_t hqswb_clas, /* i : HQ SWB class */
+ const int32_t core_brate, /* i : Codec bitrate */
+ int16_t *num_sfm, /* o : Total number of subbands */
+ int16_t *nb_sfm, /* o : Total number of coded bands */
+ int16_t *start_norm, /* o : First norm to be SDE encoded */
+ int16_t *num_env_bands, /* o : Number coded envelope bands */
+ int16_t *numnrmibits, /* o : Number of bits in fall-back norm encoding */
+ int16_t *hq_generic_offset, /* o : Freq offset for HQ GENERIC */
+ int16_t *sfmsize, /* o : Subband bandwidths */
+ int16_t *sfm_start, /* o : Subband start coefficients */
+ int16_t *sfm_end /* o : Subband end coefficients */
+)
+{
+ const int16_t *p_sfmsize;
+ const int16_t *p_sfm_start;
+ const int16_t *p_sfm_end;
+ int16_t i, bw_ext;
+
+ bw_ext = 0;
+ *start_norm = 0;
+
+ if ( length == L_SPEC48k )
+ {
+ if ( hqswb_clas == HQ_GEN_FB )
+ {
+ *num_sfm = NB_SFM;
+ p_sfmsize = band_len_HQ;
+ p_sfm_start = band_start_HQ;
+ p_sfm_end = band_end_HQ;
+
+ if ( core_brate >= HQ_32k )
+ {
+ *hq_generic_offset = HQ_GENERIC_FOFFSET_32K;
+ /* setting start frequency of FD BWE */
+ *num_env_bands = SFM_N_STA_10k;
+ }
+ else
+ {
+ *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4;
+ *num_env_bands = SFM_N_STA_8k;
+ }
+
+ *nb_sfm = *num_sfm;
+ }
+ else
+ {
+ if ( hqswb_clas == HQ_HARMONIC )
+ {
+ *num_sfm = SFM_N_HARM_FB;
+ *nb_sfm = SFM_N_HARM_FB;
+ *num_env_bands = SFM_N_HARM_FB;
+
+ p_sfmsize = band_len_harm;
+ p_sfm_start = band_start_harm;
+ p_sfm_end = band_end_harm;
+ }
+ else if ( hqswb_clas == HQ_HVQ )
+ {
+ if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
+ {
+ *num_sfm = SFM_N_HARM_FB;
+ *nb_sfm = HVQ_THRES_SFM_24k;
+ *num_env_bands = *num_sfm - *nb_sfm;
+ *start_norm = HVQ_THRES_SFM_24k;
+ }
+ else
+ {
+ *num_sfm = SFM_N_HARM_FB;
+ *nb_sfm = HVQ_THRES_SFM_32k;
+ *num_env_bands = *num_sfm - *nb_sfm;
+ *start_norm = HVQ_THRES_SFM_32k;
+ }
+
+ p_sfmsize = band_len_harm;
+ p_sfm_start = band_start_harm;
+ p_sfm_end = band_end_harm;
+ }
+ else
+ {
+ *num_sfm = NB_SFM;
+ *nb_sfm = *num_sfm;
+ *num_env_bands = NB_SFM;
+
+ p_sfmsize = band_len_HQ;
+ p_sfm_start = band_start_HQ;
+ p_sfm_end = band_end_HQ;
+ }
+ }
+ }
+ else if ( length == L_SPEC32k )
+ {
+ if ( hqswb_clas == HQ_HARMONIC )
+ {
+ *num_sfm = SFM_N_HARM;
+ *nb_sfm = SFM_N_HARM;
+ *num_env_bands = SFM_N_HARM;
+
+ p_sfmsize = band_len_harm;
+ p_sfm_start = band_start_harm;
+ p_sfm_end = band_end_harm;
+ }
+ else if ( hqswb_clas == HQ_HVQ )
+ {
+ if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
+ {
+ *num_sfm = SFM_N_HARM;
+ *nb_sfm = HVQ_THRES_SFM_24k;
+ *num_env_bands = *num_sfm - *nb_sfm;
+ *start_norm = HVQ_THRES_SFM_24k;
+ }
+ else
+ {
+ *num_sfm = SFM_N_HARM;
+ *nb_sfm = HVQ_THRES_SFM_32k;
+ *num_env_bands = *num_sfm - *nb_sfm;
+ *start_norm = HVQ_THRES_SFM_32k;
+ }
+
+ p_sfmsize = band_len_harm;
+ p_sfm_start = band_start_harm;
+ p_sfm_end = band_end_harm;
+ }
+ else if ( hqswb_clas == HQ_GEN_SWB )
+ {
+ *num_sfm = SFM_N_SWB;
+ p_sfmsize = band_len_HQ;
+ p_sfm_start = band_start_HQ;
+ p_sfm_end = band_end_HQ;
+
+ if ( core_brate >= HQ_32k )
+ {
+ *hq_generic_offset = HQ_GENERIC_FOFFSET_32K;
+ /* setting start frequency of FD BWE */
+ *num_env_bands = SFM_N_STA_10k;
+ }
+ else
+ {
+ *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4;
+ /* setting start frequency of FD BWE */
+ *num_env_bands = SFM_N_STA_8k;
+ }
+ *nb_sfm = *num_sfm;
+ }
+ else
+ {
+ /* HQ_NORMAL and HQ_TRANSIENT */
+ *num_sfm = SFM_N_SWB;
+ *nb_sfm = *num_sfm;
+ *num_env_bands = SFM_N_SWB;
+
+ p_sfmsize = band_len_HQ;
+ p_sfm_start = band_start_HQ;
+ p_sfm_end = band_end_HQ;
+ }
+ }
+ else if ( length == L_SPEC48k_EXT )
+ {
+ bw_ext = 1;
+ p_sfmsize = band_len_HQ;
+ p_sfm_start = band_start_HQ;
+ p_sfm_end = band_end_HQ;
+ *num_sfm = NB_SFM;
+ }
+ else if ( length == L_SPEC16k_EXT )
+ {
+ bw_ext = 1;
+ p_sfmsize = band_len_wb;
+ p_sfm_start = band_start_wb;
+ p_sfm_end = band_end_wb;
+ *num_sfm = SFM_N_WB;
+ }
+ else
+ {
+ *num_sfm = SFM_N_WB;
+ *nb_sfm = *num_sfm;
+ *num_env_bands = SFM_N_WB;
+
+ p_sfmsize = band_len_wb;
+ p_sfm_start = band_start_wb;
+ p_sfm_end = band_end_wb;
+ }
+
+ if ( bw_ext )
+ {
+ for ( i = 0; i < *num_sfm; i++ )
+ {
+ sfmsize[i] = (int16_t) ( 1.25f * p_sfmsize[i] );
+ sfm_start[i] = (int16_t) ( 1.25f * p_sfm_start[i] );
+ sfm_end[i] = (int16_t) ( 1.25f * p_sfm_end[i] );
+ }
+ *nb_sfm = *num_sfm;
+ *num_env_bands = *num_sfm;
+ }
+ else
+ {
+ mvs2s( p_sfmsize, sfmsize, *num_sfm );
+ mvs2s( p_sfm_start, sfm_start, *num_sfm );
+ mvs2s( p_sfm_end, sfm_end, *num_sfm );
+ }
+
+ *numnrmibits = ( *num_env_bands - 1 ) * NORMI_BITS;
+
+ return;
+}
diff --git a/lib_com/hq_tools.c b/lib_com/hq_tools.c
new file mode 100644
index 0000000000000000000000000000000000000000..df59ac1721cb59ba94585ca522ff05c842e02724
--- /dev/null
+++ b/lib_com/hq_tools.c
@@ -0,0 +1,1824 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * Local function prototypes
+ *--------------------------------------------------------------------------*/
+
+static void overlap_hq_bwe( const float *hq_swb_overlap_buf, float *coeff_out1, const int16_t n_swb_overlap_offset, const int16_t n_swb_overlap, const int16_t *R, const int16_t num_env_bands, const int16_t num_sfm, const int16_t *sfm_end );
+
+/*--------------------------------------------------------------------------*
+ * hq_swb_harmonic_calc_norm_envelop()
+ *
+ * Calculate normalization envelop
+ *--------------------------------------------------------------------------*/
+
+static void hq_swb_harmonic_calc_norm_envelop(
+ float *SWB_signal, /* i : input signal */
+ float *envelope, /* o : output envelope */
+ const int16_t L_swb_norm, /* i : length of normaliztion */
+ const int16_t SWB_flength /* i : length of input signal */
+)
+{
+ int16_t i, lookback, env_index;
+ int16_t n_freq, n_lag_now, n_lag;
+
+ lookback = L_swb_norm / 2;
+ env_index = 0;
+ for ( n_freq = 0; n_freq < lookback; n_freq++ )
+ {
+ n_lag_now = lookback + n_freq;
+
+ /* Apply MA filter */
+ envelope[env_index] = EPSILON;
+ for ( n_lag = 0; n_lag < n_lag_now; n_lag++ )
+ {
+ envelope[env_index] += (float) fabs( SWB_signal[n_lag] );
+ }
+ env_index++;
+ }
+
+ n_lag_now = L_swb_norm;
+
+ for ( n_freq = 0; n_freq < SWB_flength - L_swb_norm; n_freq++ )
+ {
+ /* Apply MA filter */
+ envelope[env_index] = EPSILON;
+ for ( n_lag = 0; n_lag < n_lag_now; n_lag++ )
+ {
+ envelope[env_index] += (float) fabs( SWB_signal[n_freq + n_lag] );
+ }
+ env_index++;
+ }
+
+ for ( n_freq = SWB_flength - L_swb_norm, i = 0; n_freq < SWB_flength - lookback; n_freq++, i++ )
+ {
+ n_lag_now = L_swb_norm - i;
+
+ /* Apply MA filter */
+ envelope[env_index] = EPSILON;
+ for ( n_lag = 0; n_lag < n_lag_now; n_lag++ )
+ {
+ envelope[env_index] += (float) fabs( SWB_signal[n_freq + n_lag] );
+ }
+ env_index++;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * noise_level_calc()
+ *
+ * Calculate noise level and limited band
+ *--------------------------------------------------------------------------*/
+
+void limit_band_noise_level_calc(
+ const int16_t *wnorm, /* i : reordered norm of sub-vectors */
+ int16_t *limit, /* o : highest band of bit allocation */
+ const int32_t core_brate, /* i : core bitrate */
+ float *noise_level /* o : noise level */
+)
+{
+ float ener_limit, ener_sum, fact;
+ int16_t i;
+ int16_t nb_sfm;
+
+ nb_sfm = *limit;
+ ener_limit = 1e-5f;
+ *noise_level = 0.0f;
+ for ( i = 0; i < 10; i++ )
+ {
+ ener_limit += wnorm[i];
+ *noise_level += (float) abs( wnorm[i + 1] - wnorm[i] );
+ }
+ ener_sum = ener_limit;
+
+ for ( i = 10; i < ( nb_sfm - 1 ); i++ )
+ {
+ ener_sum += wnorm[i];
+ *noise_level += (float) abs( wnorm[i + 1] - wnorm[i] );
+ }
+ ener_sum += wnorm[nb_sfm - 1];
+
+ if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
+ {
+ fact = 0.885f;
+ }
+ else
+ {
+ fact = 0.942f;
+ }
+
+ i = 9;
+ while ( ener_limit < ener_sum * fact && i + 1 < nb_sfm )
+ {
+ ener_limit += wnorm[++i];
+ }
+ *limit = i;
+
+ /* calculate noise level for spectrum filling */
+ *noise_level /= ener_sum;
+ if ( *noise_level < 0 )
+ {
+ *noise_level = 0.25f;
+ }
+
+ *noise_level = 0.25f - *noise_level;
+
+ if ( *noise_level < 0.0f )
+ {
+ *noise_level = 0.0f;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * build_nf_codebook()
+ *
+ * Build noise-fill codebook for HQ mode
+ *--------------------------------------------------------------------------*/
+
+/*! r: Number of coefficients in nf codebook */
+int16_t build_nf_codebook(
+ const int16_t flag_32K_env_ho, /* i : Envelope attenuation hangover flag */
+ const float *coeff, /* i : Coded spectral coefficients */
+ const int16_t *sfm_start, /* i : Subband start indices */
+ const int16_t *sfmsize, /* i : Subband widths */
+ const int16_t *sfm_end, /* i : Subband end indices */
+ const int16_t last_sfm, /* i : Last coded band */
+ const int16_t *R, /* i : Per-band bit allocation */
+ float *CodeBook, /* o : Noise-fill codebook */
+ float *CodeBook_mod /* o : Densified noise-fill codebook */
+)
+{
+ int16_t sfm_base;
+ int16_t sfm;
+ int16_t E_cb_vec;
+ int16_t i, j;
+ int16_t cb_size;
+
+ /* Build codebook */
+ cb_size = 0;
+ for ( sfm = 0; sfm <= last_sfm; sfm++ )
+ {
+ if ( R[sfm] != 0 )
+ {
+ if ( flag_32K_env_ho )
+ {
+ /* Build compressed (+/- 1) noise-fill codebook */
+ sfm_base = sfm_start[sfm];
+ for ( i = 0; i < sfmsize[sfm] / 8; i++ )
+ {
+ E_cb_vec = 0;
+ for ( j = sfm_base + i * 8; j < sfm_base + ( i + 1 ) * 8; j++ )
+ {
+ if ( coeff[j] > 0.0f )
+ {
+ CodeBook_mod[cb_size] = 1.0f;
+ E_cb_vec++;
+ }
+ else if ( coeff[j] < 0.0f )
+ {
+ CodeBook_mod[cb_size] = -1.0f;
+ E_cb_vec++;
+ }
+ else
+ {
+ CodeBook_mod[cb_size] = 0.0f;
+ }
+ cb_size++;
+ }
+
+ if ( E_cb_vec < 2 )
+ {
+ cb_size -= 8;
+ }
+ }
+ }
+ else
+ {
+ for ( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ )
+ {
+ CodeBook[cb_size] = coeff[j];
+ cb_size++;
+ }
+ }
+ }
+ }
+
+ if ( flag_32K_env_ho )
+ {
+ for ( j = 0; j < cb_size; j++ )
+ {
+ if ( CodeBook_mod[j] != 0.0f )
+ {
+ /* Densify codebook */
+ CodeBook[j] = sign( CodeBook_mod[j] ) * ( CodeBook_mod[j] * CodeBook_mod[j] + CodeBook_mod[cb_size - j - 1] * CodeBook_mod[cb_size - j - 1] );
+ }
+ else
+ {
+ CodeBook[j] = CodeBook_mod[cb_size - j - 1];
+ }
+ }
+ }
+
+ return cb_size;
+}
+
+/*--------------------------------------------------------------------------*
+ * find_last_band()
+ *
+ * Find the last band which has bits allocated
+ *--------------------------------------------------------------------------*/
+
+/*! r: index of last band */
+int16_t find_last_band(
+ const int16_t *bitalloc, /* i : bit allocation */
+ const int16_t nb_sfm /* i : number of possibly coded bands */
+)
+{
+ int16_t sfm, core_sfm;
+
+ core_sfm = nb_sfm - 1;
+
+ for ( sfm = nb_sfm - 1; sfm >= 0; sfm-- )
+ {
+ if ( bitalloc[sfm] != 0 )
+ {
+ core_sfm = sfm;
+ break;
+ }
+ }
+
+ return core_sfm;
+}
+
+/*--------------------------------------------------------------------------*
+ * apply_noisefill_HQ()
+ *
+ * Inject noise in non-coded bands
+ *--------------------------------------------------------------------------*/
+
+void apply_noisefill_HQ(
+ const int16_t *R, /* i : bit allocation */
+ const int16_t length, /* i : input frame length */
+ const int16_t flag_32K_env_ho, /* i : envelope stability hangover flag */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t last_sfm, /* i : last coded subband */
+ const float *CodeBook, /* i : Noise-fill codebook */
+ const float *CodeBook_mod, /* i : Densified noise-fill codebook */
+ const int16_t cb_size, /* i : Codebook length */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t *sfmsize, /* i : Subband band width */
+ float *coeff /* i/o: coded/noisefilled spectrum */
+)
+{
+ int16_t sfm;
+ int16_t cb_pos;
+ float E_cb_vec;
+ float E_corr;
+ float cb_buff[64];
+ int16_t i, j;
+
+ if ( length >= L_FRAME32k || core_brate != HQ_32k )
+ {
+ /* Read from codebook */
+ cb_pos = 0;
+
+ for ( sfm = 0; sfm <= last_sfm; sfm++ )
+ {
+ if ( R[sfm] == 0 )
+ {
+ if ( flag_32K_env_ho )
+ {
+ E_cb_vec = 0.0f;
+ if ( sfm < 20 )
+ {
+ for ( i = 0; i < sfmsize[sfm]; i++ )
+ {
+ cb_buff[i] = CodeBook_mod[cb_pos];
+ E_cb_vec += cb_buff[i] * cb_buff[i];
+ cb_pos++;
+ if ( cb_pos >= cb_size )
+ {
+ cb_pos = 0;
+ }
+ }
+ }
+ else
+ {
+ for ( i = 0; i < sfmsize[sfm]; i++ )
+ {
+ cb_buff[i] = CodeBook[cb_pos];
+ E_cb_vec += cb_buff[i] * cb_buff[i];
+ cb_pos++;
+ if ( cb_pos >= cb_size )
+ {
+ cb_pos = 0;
+ }
+ }
+ }
+
+ E_corr = E_cb_vec / ( (float) sfmsize[sfm] );
+ E_corr = 1.0f / (float) sqrt( E_corr );
+
+ for ( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ )
+ {
+ coeff[j] = cb_buff[j - sfm_start[sfm]] * E_corr;
+ }
+ }
+ else
+ {
+ for ( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ )
+ {
+ coeff[j] = CodeBook[cb_pos];
+ cb_pos++;
+ cb_pos = ( cb_pos >= cb_size ) ? 0 : cb_pos;
+ }
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * harm_bwe_fine()
+ *
+ * Prepare harmonic BWE fine structure
+ *--------------------------------------------------------------------------*/
+
+void harm_bwe_fine(
+ const int16_t *R, /* i : bit allocation */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t high_sfm, /* i : higher transition band to BWE */
+ const int16_t num_sfm, /* i : total number of bands */
+ const int16_t *norm, /* i : quantization indices for norms */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ int16_t *prev_L_swb_norm, /* i/o: last normalize length */
+ float *coeff, /* i/o: coded/noisefilled normalized spectrum */
+ float *coeff_out, /* o : coded/noisefilled spectrum */
+ float *coeff_fine /* o : BWE fine structure */
+)
+{
+ int16_t sfm;
+ int16_t i;
+ float normq;
+ float SWB_signal[L_HARMONIC_EXC];
+ float envelope[L_HARMONIC_EXC];
+ float *src, *dst, *end;
+
+ int16_t norm_width = 64;
+
+ /* shape the spectrum */
+ for ( sfm = 0; sfm <= last_sfm; sfm++ )
+ {
+ if ( R[sfm] != 0 )
+ {
+ normq = dicn[norm[sfm]];
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ coeff_out[i] = coeff[i] * normq;
+ }
+ }
+ else
+ {
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ coeff_out[i] = 0.0f;
+ }
+ }
+ }
+
+ /* excitation replication */
+ mvr2r( coeff_out, SWB_signal, L_HARMONIC_EXC );
+ calc_normal_length( HQ_CORE, coeff_out, HQ_HARMONIC, -1, &norm_width, prev_L_swb_norm );
+ hq_swb_harmonic_calc_norm_envelop( SWB_signal, envelope, norm_width, L_HARMONIC_EXC );
+
+ /* Normalize with envelope */
+ for ( i = 0; i < L_HARMONIC_EXC; i++ )
+ {
+ SWB_signal[i] = SWB_signal[i] / envelope[i];
+ }
+
+ dst = coeff_fine + sfm_end[last_sfm];
+ end = coeff_fine + sfm_end[num_sfm - 1];
+
+ if ( ( sfm_end[last_sfm] - sfm_end[high_sfm] ) <= L_HARMONIC_EXC - START_EXC )
+ {
+ src = SWB_signal + START_EXC + ( sfm_end[last_sfm] - sfm_end[high_sfm] );
+ }
+ else
+ {
+ src = SWB_signal + L_HARMONIC_EXC - 1;
+ }
+
+ while ( dst < end )
+ {
+ while ( dst < end && src < &SWB_signal[L_HARMONIC_EXC] )
+ {
+ *dst++ = *src++;
+ }
+ src--;
+
+ while ( dst < end && src >= &SWB_signal[START_EXC] )
+ {
+ *dst++ = *src--;
+ }
+ src++;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * hvq_bwe_fine()
+ *
+ * Prepare HVQ BWE fine structure
+ *--------------------------------------------------------------------------*/
+
+void hvq_bwe_fine(
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t num_sfm, /* i : total number of bands */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t *peak_idx, /* i : Peak index */
+ const int16_t Npeaks, /* i : Number of peaks */
+ int16_t *peak_pos, /* i/o: Peak positions */
+ int16_t *prev_L_swb_norm, /* i/o: last normalize length */
+ float *coeff, /* i/o: coded/noisefilled normalized spectrum */
+ int16_t *bwe_peaks, /* o : Positions of peaks in BWE */
+ float *coeff_fine /* o : HVQ BWE fine structure */
+)
+{
+ int16_t i, j;
+ float SWB_signal[L_HARMONIC_EXC];
+ float envelope[L_HARMONIC_EXC];
+ float *src, *dst, *end;
+ int16_t *peak_dst, *peak_src;
+ int16_t norm_width = 64;
+
+ /* excitation replication */
+ mvr2r( coeff, SWB_signal, L_HARMONIC_EXC );
+ calc_normal_length( HQ_CORE, coeff, HQ_HVQ, -1, &norm_width, prev_L_swb_norm );
+
+ hq_swb_harmonic_calc_norm_envelop( SWB_signal, envelope, norm_width, L_HARMONIC_EXC );
+
+ /* Normalize with envelope */
+ for ( i = 0; i < L_HARMONIC_EXC; i++ )
+ {
+ SWB_signal[i] = SWB_signal[i] / envelope[i];
+ }
+
+ dst = coeff_fine;
+ end = coeff_fine + sfm_end[num_sfm - 1] - sfm_end[last_sfm];
+
+ src = SWB_signal + START_EXC;
+ peak_src = peak_pos + START_EXC;
+
+ for ( i = 0; i < Npeaks; i++ )
+ {
+ if ( peak_idx[i] < L_HARMONIC_EXC )
+ {
+ peak_pos[peak_idx[i]] = 1;
+ }
+ }
+
+ i = L_HARMONIC_EXC - 1;
+ while ( i-- > 0 )
+ {
+ if ( peak_pos[i] == 1 )
+ {
+ break;
+ }
+ }
+
+ if ( i < 180 )
+ {
+ i = 180;
+ }
+
+ for ( j = L_HARMONIC_EXC - 1; j > i + 1; j-- )
+ {
+ SWB_signal[j] = 0.0f;
+ }
+
+ peak_dst = bwe_peaks + sfm_end[last_sfm];
+ while ( dst < end )
+ {
+ while ( dst < end && src < &SWB_signal[L_HARMONIC_EXC] )
+ {
+ *dst++ = *src++;
+ *peak_dst++ = *peak_src++;
+ }
+ peak_src--;
+ src--;
+
+ while ( dst < end && src >= &SWB_signal[START_EXC] )
+ {
+ *dst++ = *src--;
+ *peak_dst++ = *peak_src--;
+ }
+ peak_src++;
+ src++;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * hq_fold_bwe()
+ *
+ * HQ mode folding BWE
+ *--------------------------------------------------------------------------*/
+
+void hq_fold_bwe(
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t num_sfm, /* i : Number of subbands */
+ float *coeff /* i/o: coded/noisefilled normalized spectrum */
+)
+{
+ int16_t low_coeff;
+ int16_t first_coeff;
+ float *src, *dst, *end;
+
+ /* Find replication range for BWE */
+ low_coeff = sfm_end[last_sfm] >> 1;
+ src = coeff + sfm_end[last_sfm] - 1;
+
+ first_coeff = sfm_end[last_sfm];
+ dst = coeff + sfm_end[last_sfm];
+ end = coeff + sfm_end[num_sfm - 1];
+
+ /* Generate BWE with spectral folding */
+ while ( dst < end )
+ {
+ while ( dst < end && src >= &coeff[low_coeff] )
+ {
+ *dst++ = *src--;
+ }
+
+ src++;
+
+ while ( dst < end && src < &coeff[first_coeff] )
+ {
+ *dst++ = *src++;
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * apply_nf_gain()
+ *
+ * Apply noise fill gain
+ *--------------------------------------------------------------------------*/
+
+void apply_nf_gain(
+ const int16_t nf_idx, /* i : noise fill gain index */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t *R, /* i : bit allocation */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ float *coeff /* i/o: coded/noisefilled normalized spectrum */
+)
+{
+ int16_t sfm;
+ int16_t j;
+ float nf_scale;
+
+ nf_scale = 1.0f / ( 1 << nf_idx );
+ for ( sfm = 0; sfm <= last_sfm; sfm++ )
+ {
+ if ( R[sfm] == 0 )
+ {
+ for ( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ )
+ {
+ /* Scale NoiseFill */
+ coeff[j] = coeff[j] * nf_scale;
+ }
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * hq_generic_fine()
+ *
+ * Prepare HQ SWB BWE fine structure
+ *--------------------------------------------------------------------------*/
+
+void hq_generic_fine(
+ float *coeff, /* i : coded/noisefilled normalized spectrum */
+ const int16_t last_sfm, /* i : Last coded band */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ float *coeff_out1 /* o : HQ SWB BWE input */
+)
+{
+ int16_t sfm;
+ int16_t i;
+ float multi;
+
+ multi = 1.0f;
+ for ( sfm = 0; sfm <= last_sfm; sfm++ )
+ {
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ if ( coeff[i] == 0.f )
+ {
+ coeff_out1[i] = (float) multi * ( own_random( bwe_seed ) > 0 ? 1.0f : -1.0f ) * 0.5f;
+ }
+ else
+ {
+ coeff_out1[i] = coeff[i];
+ }
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * harm_bwe()
+ *
+ * HQ Harmonic BWE
+ *--------------------------------------------------------------------------*/
+
+void harm_bwe(
+ const float *coeff_fine, /* i : fine structure for BWE */
+ const float *coeff, /* i : coded/noisefilled normalized spectrum */
+ const int16_t num_sfm, /* i : Number of subbands */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t high_sfm, /* i : higher transition band to BWE */
+ const int16_t *R, /* i : bit allocation */
+ const int16_t prev_hq_mode, /* i : previous hq mode */
+ int16_t *norm, /* i/o: quantization indices for norms */
+ float *noise_level, /* i/o: noise levels for harmonic modes */
+ float *prev_noise_level, /* i/o: noise factor in previous frame */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ float *coeff_out, /* o : coded/noisefilled spectrum */
+ const int16_t element_mode /* i : element mode */
+)
+{
+ int16_t i, j;
+ int16_t sfm;
+ float normq;
+ float norm_adj;
+ float E_L;
+
+ float alfa = 0.5f;
+ float alpha, beta;
+ int16_t idx;
+ float fac;
+ float *src, *dst;
+
+ for ( sfm = 0; sfm <= last_sfm; sfm++ )
+ {
+ if ( R[sfm] == 0 )
+ {
+ normq = dicn[norm[sfm]];
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ coeff_out[i] = coeff[i] * normq;
+ }
+ }
+ }
+ noise_level[1] = noise_level[0];
+
+ /* shaping the BWE spectrum further by envelopes and noise factors */
+ noise_level[0] = 0.9f * prev_noise_level[0] + 0.1f * noise_level[0];
+ noise_level[1] = 0.9f * prev_noise_level[1] + 0.1f * noise_level[1];
+
+ if ( prev_hq_mode == HQ_NORMAL || prev_hq_mode == HQ_GEN_SWB )
+ {
+ if ( noise_level[0] < 0.25f )
+ {
+ noise_level[0] *= 4.0f;
+ }
+
+ if ( noise_level[1] < 0.25f )
+ {
+ noise_level[1] *= 4.0f;
+ }
+ }
+
+ E_L = EPSILON;
+ for ( i = last_sfm + 1; i < num_sfm; i++ )
+ {
+ E_L = EPSILON;
+ for ( j = sfm_start[i]; j < sfm_end[i]; j++ )
+ {
+ E_L += coeff_fine[j] * coeff_fine[j];
+ }
+ E_L = (float) sqrt( ( sfm_end[i] - sfm_start[i] ) / E_L );
+
+ normq = dicn[norm[i]];
+ norm_adj = normq * E_L;
+ alfa = ( i > 27 ) ? noise_level[1] : noise_level[0];
+ beta = (float) sqrt( 1.0f - alfa );
+ if ( element_mode > EVS_MONO )
+ {
+ alpha = (float) sqrt( alfa );
+ }
+ else
+ {
+ alpha = (float) sqrt( alfa ) * 0.5f;
+ }
+
+ for ( sfm = sfm_start[i]; sfm < sfm_end[i]; sfm++ )
+ {
+ coeff_out[sfm] = ( beta * coeff_fine[sfm] * norm_adj + alpha * own_random( bwe_seed ) / PCM16_TO_FLT_FAC * normq );
+ }
+ }
+
+ prev_noise_level[0] = noise_level[0];
+ prev_noise_level[1] = noise_level[1];
+ idx = 16;
+ src = &coeff_out[sfm_end[high_sfm] + L_HARMONIC_EXC - START_EXC];
+ dst = src - 1;
+
+ for ( i = 0; i < idx; i++ )
+ {
+ fac = i / ( 2.0f * idx );
+ *src++ *= 0.5f + fac;
+ *dst-- *= 0.5f + fac;
+ }
+ if ( num_sfm == 33 )
+ {
+ set_f( &coeff_out[800], 0, 160 );
+ }
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * HVQ_bwe()
+ *
+ * HQ HVQ BWE
+ *--------------------------------------------------------------------------*/
+
+void hvq_bwe(
+ const float *coeff, /* i : coded/noisefilled spectrum */
+ const float *coeff_fine, /* i : BWE fine structure */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t *sfm_len, /* i : Subband length */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t prev_hq_mode, /* i : previous hq mode */
+ const int16_t *bwe_peaks, /* i : HVQ bwe peaks */
+ const int16_t bin_th, /* i : HVQ transition bin */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int32_t core_brate, /* i : Core bitrate */
+ const int16_t *R, /* i : Bit allocation */
+ int16_t *norm, /* i/o: quantization indices for norms */
+ float *noise_level, /* i/o: noise levels for harmonic modes */
+ float *prev_noise_level, /* i/o: noise factor in previous frame */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ float *coeff_out /* o : coded/noisefilled spectrum */
+)
+{
+ int16_t i, j;
+ int16_t N;
+ float normq;
+ float E_L;
+
+ int16_t bwe_noise_th = 0;
+ int16_t peak_band, low, high, sel_norm;
+ int16_t norm_ind;
+ float tmp_norm = 0;
+ int16_t idx;
+ float fac;
+ float *src, *dst;
+ int16_t istart, iend;
+ int16_t offset = sfm_end[last_sfm];
+
+ mvr2r( coeff, coeff_out, L_FRAME48k );
+
+ bwe_noise_th = bin_th + ( sfm_end[num_sfm - 1] - bin_th ) / HVQ_BWE_NOISE_BANDS;
+ logqnorm( &coeff_out[sfm_start[last_sfm]], &norm[last_sfm], 40, sfm_len[last_sfm], thren_HQ );
+
+ /* shaping the BWE spectrum further by envelopes and noise factors */
+ noise_level[0] = 0.9f * prev_noise_level[0] + 0.1f * noise_level[0];
+ noise_level[1] = 0.9f * prev_noise_level[1] + 0.1f * noise_level[1];
+
+ if ( prev_hq_mode == HQ_NORMAL || prev_hq_mode == HQ_GEN_SWB )
+ {
+ if ( noise_level[0] < 0.25f )
+ {
+ noise_level[0] *= 4.0f;
+ }
+
+ if ( noise_level[1] < 0.25f )
+ {
+ noise_level[1] *= 4.0f;
+ }
+ }
+
+ norm_ind = last_sfm + 1;
+
+ if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
+ {
+ peak_band = 0;
+ E_L = EPSILON;
+ for ( i = sfm_start[norm_ind]; i < sfm_end[norm_ind + 1]; i++ )
+ {
+ if ( bwe_peaks[i] )
+ {
+ peak_band = 1;
+ }
+ E_L += coeff_fine[i - offset] * coeff_fine[i - offset];
+ }
+ E_L = (float) sqrt( ( sfm_end[norm_ind + 1] - sfm_start[norm_ind] ) / E_L );
+
+ normq = 0.1f * dicn[norm[norm_ind - 1]] + 0.8f * dicn[norm[norm_ind]] + 0.1f * dicn[norm[norm_ind + 1]];
+ tmp_norm = 0.1f * dicn[norm[norm_ind]] + 0.8f * dicn[norm[norm_ind + 1]] + 0.1f * dicn[norm[norm_ind + 2]];
+
+ istart = sfm_start[norm_ind];
+ iend = istart + sfm_len[norm_ind] / 2;
+ for ( i = istart; i < iend; i++ )
+ {
+ coeff_out[i] = ( ( 1.0f - noise_level[i / bwe_noise_th] ) * coeff_fine[i - offset] * E_L + noise_level[i / bwe_noise_th] * own_random( bwe_seed ) / PCM16_TO_FLT_FAC ) * normq;
+ }
+
+ j = 0;
+ N = sfm_len[norm_ind] / 2 + sfm_len[norm_ind + 1] / 2 - 1;
+ istart = iend;
+ iend = sfm_start[norm_ind + 1] + sfm_len[norm_ind + 1] / 2;
+ for ( i = istart; i < iend; i++ )
+ {
+ coeff_out[i] = ( (float) ( N - j ) / N * normq + (float) j / N * tmp_norm ) * ( ( 1.0f - noise_level[i / bwe_noise_th] ) * coeff_fine[i - offset] * E_L + noise_level[i / bwe_noise_th] * own_random( bwe_seed ) / PCM16_TO_FLT_FAC );
+ j++;
+ }
+
+ istart = iend;
+ iend = sfm_end[norm_ind + 1];
+ for ( i = istart; i < iend; i++ )
+ {
+ coeff_out[i] = ( ( 1.0f - noise_level[i / bwe_noise_th] ) * coeff_fine[i - offset] * E_L + noise_level[i / bwe_noise_th] * own_random( bwe_seed ) / PCM16_TO_FLT_FAC ) * tmp_norm;
+ }
+
+ norm_ind += 2;
+ }
+
+ for ( ; norm_ind < num_sfm; norm_ind++ )
+ {
+ if ( R[norm_ind] == 0 )
+ {
+ peak_band = 0;
+ E_L = EPSILON;
+
+ for ( i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++ )
+ {
+ if ( bwe_peaks[i] )
+ {
+ peak_band = 1;
+ break;
+ }
+ }
+
+ istart = sfm_start[norm_ind];
+ iend = sfm_end[norm_ind];
+
+ if ( peak_band == 1 && norm_ind > last_sfm + 1 && norm_ind < num_sfm - 1 )
+ {
+ istart -= sfm_len[norm_ind - 1] / 2;
+ iend += sfm_len[norm_ind + 1] / 2;
+ }
+
+ for ( i = istart; i < iend; i++ )
+ {
+ E_L += coeff_fine[i - offset] * coeff_fine[i - offset];
+ }
+ E_L = (float) sqrt( ( iend - istart ) / E_L );
+
+ if ( peak_band )
+ {
+ if ( norm_ind + 1 > num_sfm - 1 )
+ {
+ normq = 0.15f * dicn[norm[norm_ind - 1]] + 0.85f * dicn[norm[norm_ind]];
+ }
+ else
+ {
+ normq = 0.1f * dicn[norm[norm_ind - 1]] + 0.8f * dicn[norm[norm_ind]] + 0.1f * dicn[norm[norm_ind + 1]];
+ }
+ }
+ else
+ {
+ low = norm_ind;
+ high = min( norm_ind + 1, num_sfm - 1 );
+ sel_norm = norm[norm_ind - 1];
+ for ( j = low; j <= high; j++ )
+ {
+ if ( norm[j] > sel_norm )
+ {
+ sel_norm = norm[j];
+ }
+ }
+ normq = dicn[sel_norm];
+ }
+
+ for ( i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++ )
+ {
+ coeff_out[i] = ( ( 1.0f - noise_level[i / bwe_noise_th] ) * coeff_fine[i - offset] * E_L + noise_level[i / bwe_noise_th] * own_random( bwe_seed ) / PCM16_TO_FLT_FAC ) * normq;
+ }
+ }
+ else /* R[norm_ind] > 0 */
+ {
+ for ( i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++ )
+ {
+ coeff_out[i] = coeff[i]; /* Scaling already applied */
+ }
+ }
+ }
+
+ prev_noise_level[0] = noise_level[0];
+ prev_noise_level[1] = noise_level[1];
+ idx = 16;
+ src = &coeff_out[sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC];
+ dst = src - 1;
+
+ for ( i = 0; i < idx; i++ )
+ {
+ fac = i / ( 2.0f * idx );
+ *src++ *= 0.5f + fac;
+ *dst-- *= 0.5f + fac;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * hvq_concat_bands()
+ *
+ * Compute the band limits for concatenated bands for PVQ target signal in HVQ
+ *--------------------------------------------------------------------------*/
+
+void hvq_concat_bands(
+ const int16_t pvq_bands, /* i : Number of bands in concatenated PVQ target */
+ const int16_t *sel_bnds, /* i : Array of selected high bands */
+ const int16_t n_sel_bnds, /* i : Number of selected high bands */
+ int16_t *hvq_band_start, /* o : Band start indices */
+ int16_t *hvq_band_width, /* o : Band widths */
+ int16_t *hvq_band_end /* o : Band end indices */
+)
+{
+ int16_t k;
+ int16_t s;
+
+ s = 0;
+
+ for ( k = 0; k < pvq_bands; k++ )
+ {
+
+ if ( k >= pvq_bands - n_sel_bnds )
+ {
+ hvq_band_start[k] = hvq_band_end[k - 1];
+ hvq_band_width[k] = band_len_harm[sel_bnds[s]];
+ hvq_band_end[k] = hvq_band_end[k - 1] + band_len_harm[sel_bnds[s]];
+ s++;
+ }
+ else
+ {
+ hvq_band_start[k] = k * HVQ_PVQ_COEFS;
+ hvq_band_width[k] = HVQ_PVQ_COEFS;
+ hvq_band_end[k] = ( k + 1 ) * HVQ_PVQ_COEFS;
+ }
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * map_hq_generic_fenv_norm()
+ *
+ * mapping high frequency envelope to high band norm
+ *--------------------------------------------------------------------------*/
+
+void map_hq_generic_fenv_norm(
+ const int16_t hqswb_clas, /* i : signal classification flag */
+ const float *hq_generic_fenv, /* i : HQ GENERIC envelope */
+ int16_t *ynrm, /* o : high band norm indices */
+ int16_t *normqlg2, /* o : high band norm values */
+ const int16_t num_env_bands, /* i : Number coded envelope bands */
+ const int16_t nb_sfm, /* i : Number of envelope bands */
+ const int16_t hq_generic_offset /* i : Freq offset for HQ GENERIC */
+)
+{
+ float env_fl[17];
+ int16_t i, idx;
+
+ set_f( env_fl, 0, 17 );
+ if ( hq_generic_offset == 144 )
+ {
+ env_fl[0] = hq_generic_fenv[1];
+ env_fl[1] = hq_generic_fenv[2] * 0.6640625f + hq_generic_fenv[3] * 0.3359375f;
+ env_fl[2] = hq_generic_fenv[3] * 0.6640625f + hq_generic_fenv[4] * 0.3359375f;
+ env_fl[3] = hq_generic_fenv[4] * 0.3359375f + hq_generic_fenv[5] * 0.6640625f;
+ env_fl[4] = hq_generic_fenv[5] * 0.3359375f + hq_generic_fenv[6] * 0.6640625f;
+ env_fl[5] = hq_generic_fenv[7];
+ env_fl[6] = hq_generic_fenv[8] * 0.75f + hq_generic_fenv[9] * 0.25f;
+ env_fl[7] = hq_generic_fenv[9] * 0.75f + hq_generic_fenv[10] * 0.25f;
+ env_fl[8] = hq_generic_fenv[10] * 0.25f + hq_generic_fenv[11] * 0.75f;
+ }
+ else
+ {
+ env_fl[0] = hq_generic_fenv[0] * 0.3359375f + hq_generic_fenv[1] * 0.6640625f;
+ env_fl[1] = hq_generic_fenv[1] * 0.3359375f + hq_generic_fenv[2] * 0.6640625f;
+ env_fl[2] = hq_generic_fenv[3];
+ env_fl[3] = hq_generic_fenv[4] * 0.6640625f + hq_generic_fenv[5] * 0.3359375f;
+ env_fl[4] = hq_generic_fenv[5] * 0.6640625f + hq_generic_fenv[6] * 0.3359375f;
+ env_fl[5] = hq_generic_fenv[6] * 0.3359375f + hq_generic_fenv[7] * 0.6640625f;
+ env_fl[6] = hq_generic_fenv[7] * 0.3359375f + hq_generic_fenv[8] * 0.6640625f;
+ env_fl[7] = hq_generic_fenv[8] * 0.3359375f + hq_generic_fenv[9] * 0.6640625f;
+ env_fl[8] = hq_generic_fenv[9] * 0.3359375f + hq_generic_fenv[10] * 0.6640625f;
+ env_fl[9] = hq_generic_fenv[10] * 0.25f + hq_generic_fenv[11] * 0.75f;
+ env_fl[10] = hq_generic_fenv[12];
+ env_fl[11] = hq_generic_fenv[13];
+ }
+
+ if ( hqswb_clas == HQ_GEN_FB )
+ {
+ if ( hq_generic_offset == 144 )
+ {
+ env_fl[9] = hq_generic_fenv[12];
+ env_fl[10] = hq_generic_fenv[12] * 0.25f + hq_generic_fenv[13] * 0.75f;
+ env_fl[11] = hq_generic_fenv[13] * 0.5f + hq_generic_fenv[14] * 0.5f;
+ env_fl[12] = hq_generic_fenv[14];
+ env_fl[13] = hq_generic_fenv[14];
+ }
+ else
+ {
+ env_fl[12] = hq_generic_fenv[14];
+ env_fl[13] = hq_generic_fenv[14] * 0.25f + hq_generic_fenv[15] * 0.75f;
+ env_fl[14] = hq_generic_fenv[15] * 0.5f + hq_generic_fenv[16] * 0.5f;
+ env_fl[15] = hq_generic_fenv[16];
+ env_fl[16] = hq_generic_fenv[16];
+ }
+ }
+
+ logqnorm_2( env_fl, 40, num_env_bands, nb_sfm, ynrm + num_env_bands, normqlg2 + num_env_bands, thren_HQ );
+
+ for ( i = num_env_bands; i < nb_sfm; ++i )
+ {
+ idx = min( ynrm[i] + 10, 39 );
+ normqlg2[i] = dicnlg2[idx];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * update_rsubband()
+ *
+ * Update subband bit allocation
+ *--------------------------------------------------------------------------*/
+
+static void update_rsubband(
+ const int16_t nb_sfm, /* i : Number of sub-bands */
+ int16_t *Rsubband, /* o : Sub-bands bit allocation */
+ int16_t b_add_bits_denv /* i/o: Bits to redistribute */
+)
+{
+ int16_t i;
+
+ /* updating bit allocation */
+ while ( b_add_bits_denv > 0 )
+ {
+ i = nb_sfm - 1;
+ while ( b_add_bits_denv > 0 && i >= 0 )
+ {
+ if ( Rsubband[i] > 24 )
+ {
+ Rsubband[i] -= 8;
+ b_add_bits_denv--;
+ }
+ i--;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * get_nor_delta_hf()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+/*! r: Number of bits consumed for the delta coding */
+int16_t get_nor_delta_hf(
+ Decoder_State *st, /* i/o: Decoder state */
+ int16_t *ynrm, /* i/o: norm indices */
+ int16_t *Rsubband, /* i/o: sub-band bit allocation */
+ const int16_t num_env_bands, /* i : Number coded envelope bands */
+ const int16_t nb_sfm, /* i : Number of envelope bands */
+ const int16_t core_sfm ) /* i : index of the end band for core */
+{
+ int16_t i;
+ int16_t delta, bitsforDelta, add_bits_denv;
+
+ add_bits_denv = 0;
+ if ( core_sfm >= num_env_bands )
+ {
+ bitsforDelta = get_next_indice( st, 2 );
+ bitsforDelta += 2;
+ add_bits_denv += 2;
+
+ for ( i = num_env_bands; i < nb_sfm; ++i )
+ {
+ if ( Rsubband[i] != 0 )
+ {
+ delta = get_next_indice( st, bitsforDelta );
+ ynrm[i] += delta - ( 1 << ( bitsforDelta - 1 ) );
+
+ /* safety check in case of bit errors */
+ if ( ynrm[i] < 0 || ynrm[i] > 39 )
+ {
+ ynrm[i] = 39;
+ st->BER_detect = 1;
+ }
+ add_bits_denv += bitsforDelta;
+ }
+ }
+
+ update_rsubband( nb_sfm, Rsubband, add_bits_denv );
+ }
+
+ return add_bits_denv;
+}
+
+
+/*-------------------------------------------------------------------*
+ * calc_nor_delta_hf()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+/*! r: Number of bits consumed for the delta coding */
+int16_t calc_nor_delta_hf(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const float *t_audio, /* i : transform-domain coefficients */
+ int16_t *ynrm, /* i/o: norm indices */
+ int16_t *Rsubband, /* i/o: sub-band bit allocation */
+ const int16_t num_env_bands, /* i : Number coded envelope bands */
+ const int16_t nb_sfm, /* i : Number of envelope bands */
+ const int16_t *sfmsize, /* i : band length */
+ const int16_t *sfm_start, /* i : Start index of bands */
+ const int16_t core_sfm /* i : index of the end band for core */
+)
+{
+ int16_t i;
+ int16_t ynrm_t[44], normqlg2_t[44];
+ int16_t delta, max_delta, min_delta, bitsforDelta, add_bits_denv;
+
+ max_delta = -100;
+ calc_norm( t_audio, ynrm_t, normqlg2_t, 0, nb_sfm, sfmsize, sfm_start );
+ add_bits_denv = 0;
+ for ( i = num_env_bands; i < nb_sfm; ++i )
+ {
+ if ( Rsubband[i] != 0 )
+ {
+ delta = ynrm_t[i] - ynrm[i];
+ if ( delta > 0 )
+ {
+ delta += 1;
+ }
+ else
+ {
+ delta = -delta;
+ }
+ if ( delta > max_delta )
+ {
+ max_delta = delta;
+ }
+ }
+ }
+ if ( core_sfm >= num_env_bands )
+ {
+ if ( max_delta < 16 )
+ {
+ bitsforDelta = 2;
+ while ( max_delta >= 2 )
+ {
+ bitsforDelta++;
+ max_delta >>= 1;
+ }
+ }
+ else
+ {
+ bitsforDelta = 5;
+ }
+ max_delta = ( 1 << ( bitsforDelta - 1 ) ) - 1;
+ min_delta = ( max_delta + 1 ) * ( -1 );
+
+ /* updating norm & storing delta norm */
+ add_bits_denv = 2;
+ push_indice( hBstr, IND_DELTA_ENV_HQ, bitsforDelta - 2, 2 );
+ for ( i = num_env_bands; i < nb_sfm; ++i )
+ {
+ if ( Rsubband[i] != 0 )
+ {
+ delta = ynrm_t[i] - ynrm[i];
+ if ( delta > max_delta )
+ {
+ delta = max_delta;
+ }
+ else if ( delta < min_delta )
+ {
+ delta = min_delta;
+ }
+ push_indice( hBstr, IND_DELTA_ENV_HQ, delta - min_delta, bitsforDelta );
+ ynrm[i] += delta;
+ add_bits_denv += bitsforDelta;
+ }
+ }
+
+ /* updating bit allocation */
+ update_rsubband( nb_sfm, Rsubband, add_bits_denv );
+ }
+
+ return add_bits_denv;
+}
+
+/*-------------------------------------------------------------------*
+ * hq_generic_bwe()
+ *
+ * HQ GENERIC BWE
+ *--------------------------------------------------------------------------*/
+
+void hq_generic_bwe(
+ const int16_t HQ_mode, /* i : HQ mode */
+ float *coeff_out1, /* i/o: BWE input & temporary buffer */
+ const float *hq_generic_fenv, /* i : SWB frequency envelopes */
+ float *coeff_out, /* o : SWB signal in MDCT domain */
+ const int16_t hq_generic_offset, /* i : frequency offset for representing hq generic*/
+ int16_t *prev_L_swb_norm, /* i/o: last normalize length */
+ const int16_t hq_generic_exc_clas, /* i : hq generic hf excitation class */
+ const int16_t *sfm_end, /* i : End of bands */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int16_t num_env_bands, /* i : Number of coded envelope bands */
+ const int16_t *R /* i : Bit allocation */
+)
+{
+ int16_t n_swb_overlap_offset, n_swb_overlap;
+ float hq_swb_overlap_buf[640];
+
+ n_swb_overlap_offset = swb_bwe_subband[0] + hq_generic_offset;
+
+ n_swb_overlap = sfm_end[num_env_bands - 1] - n_swb_overlap_offset;
+ mvr2r( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf, n_swb_overlap + sfm_end[num_sfm - 1] - sfm_end[num_env_bands - 1] );
+
+ hq_generic_hf_decoding( HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R );
+
+ overlap_hq_bwe( hq_swb_overlap_buf, coeff_out, n_swb_overlap_offset, n_swb_overlap, R, num_env_bands, num_sfm, sfm_end );
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * hq_wb_nf_bwe()
+ *
+ * HQ WB noisefill and BWE
+ *--------------------------------------------------------------------------*/
+
+void hq_wb_nf_bwe(
+ const float *coeff, /* i : coded/noisefilled normalized spectrum */
+ const int16_t is_transient, /* i : is transient flag */
+ const int16_t prev_bfi, /* i : previous bad frame indicator */
+ const float *normq_v, /* i : norms */
+ const int16_t num_sfm, /* i : Number of subbands */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t *sfmsize, /* i : Subband band width */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t *R, /* i : bit allocation */
+ const int16_t prev_is_transient, /* i : previous transient flag */
+ float *prev_normq, /* i/o: previous norms */
+ float *prev_env, /* i/o: previous noise envelopes */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */
+ int16_t *prev_R, /* i/o: bit allocation info. in previous frame */
+ float *coeff_out /* o : coded/noisefilled spectrum */
+)
+{
+ int16_t i;
+ int16_t sfm;
+ int16_t total_bit;
+ int16_t num;
+
+ float bitalloc_var;
+ float sharp;
+ float mean;
+ float peak;
+ float fabs_coeff_out;
+ float harm_para;
+ float alfa = 0.5;
+ float env;
+ float step;
+ float min_coef;
+ float avrg_norm;
+ float prev_avrg_norm;
+
+ if ( is_transient == 0 )
+ {
+ if ( prev_bfi == 1 )
+ {
+ mvr2r( normq_v, prev_normq, SFM_N_WB );
+ }
+
+ /* the variance of bit allocation */
+ total_bit = 0;
+ bitalloc_var = 0.0f;
+ for ( sfm = 8; sfm <= last_sfm; sfm++ )
+ {
+ bitalloc_var += (float) abs( R[sfm] - R[sfm - 1] );
+ total_bit += R[sfm];
+ }
+ bitalloc_var = ( last_sfm > 8 && total_bit > 0 ) ? ( bitalloc_var / total_bit ) : 0;
+
+ /* calculate the peak-average ratio of saturable subbands */
+ num = 0;
+ sharp = EPSILON;
+ for ( sfm = last_sfm; sfm >= 8; sfm-- )
+ {
+ if ( R[sfm] >= rat[sfm] * sfmsize[sfm] )
+ {
+ peak = 0.0f;
+ mean = EPSILON;
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ fabs_coeff_out = (float) fabs( coeff_out[i] );
+ mean += fabs_coeff_out;
+ if ( fabs_coeff_out > peak )
+ {
+ peak = fabs_coeff_out;
+ }
+ }
+ sharp += sfmsize[sfm] * peak / mean;
+ num++;
+ }
+ }
+
+ sharp = ( num != 0 ) ? 2.0f * num / sharp : 1.0f;
+ harm_para = sharp;
+ if ( last_sfm == 0 )
+ {
+ step = 0;
+ }
+ else
+ {
+ step = 5.0f * sharp / last_sfm;
+ }
+ alfa = 2.5f;
+
+ /* fill noise for the insaturable subbands */
+ for ( sfm = 0; sfm < num_sfm; sfm++ )
+ {
+ env = 0.0f;
+ if ( R[sfm] != 0 && R[sfm] < 1.5f * sfmsize[sfm] )
+ {
+ /* calculate the energy of the undecoded coefficients */
+ peak = 0.0f;
+ min_coef = FLT_MAX;
+ env = normq_v[sfm] * normq_v[sfm] * sfmsize[sfm];
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ fabs_coeff_out = (float) fabs( coeff_out[i] );
+ if ( fabs_coeff_out < min_coef && coeff_out[i] != 0 )
+ {
+ min_coef = fabs_coeff_out;
+ }
+ if ( fabs_coeff_out > peak )
+ {
+ peak = fabs_coeff_out;
+ }
+ env -= coeff_out[i] * coeff_out[i];
+ }
+
+ if ( env > 0 )
+ {
+ if ( sfm == 0 )
+ {
+ avrg_norm = normq_v[0] + normq_v[1] + normq_v[2];
+ prev_avrg_norm = prev_normq[0] + prev_normq[1] + prev_normq[2];
+ }
+ else if ( sfm == 25 )
+ {
+ avrg_norm = normq_v[23] + normq_v[24] + normq_v[25];
+ prev_avrg_norm = prev_normq[23] + prev_normq[24] + prev_normq[25];
+ }
+ else
+ {
+ avrg_norm = normq_v[sfm - 1] + normq_v[sfm] + normq_v[sfm + 1];
+ prev_avrg_norm = prev_normq[sfm - 1] + prev_normq[sfm] + prev_normq[sfm + 1];
+ }
+
+ if ( bitalloc_var > 0.3f || 4.0f * normq_v[sfm] < peak )
+ {
+ /* calculate the noise magnitude of harmonic signal */
+ env = (float) ( avrg_norm * harm_para * sqrt( env / sfmsize[sfm] ) / peak );
+ }
+ else
+ {
+ /* calculate the noise magnitude of normal signal */
+ env = sharp * (float) sqrt( env / sfmsize[sfm] );
+ if ( alfa * normq_v[sfm] < peak )
+ {
+ env *= env / peak;
+ }
+ sharp += step;
+ }
+ if ( env > 0.5f * min_coef )
+ {
+ env = 0.5f * min_coef;
+ }
+
+ if ( prev_bfi == 1 )
+ {
+ prev_env[sfm] = env;
+ }
+ /* smooth the noise magnitudes between inter-frame */
+ if ( prev_avrg_norm > 0.5f * avrg_norm && prev_avrg_norm < 2.0f * avrg_norm && prev_is_transient == 0 )
+ {
+ env = 0.5f * env + 0.5f * prev_env[sfm];
+ }
+
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ if ( coeff[i] == 0 )
+ {
+ coeff_out[i] = (float) ( own_random( bwe_seed ) ) / PCM16_TO_FLT_FAC;
+ coeff_out[i] *= env;
+ }
+ }
+ }
+ else
+ {
+ env = 0.0f;
+ }
+ }
+ else if ( R[sfm] == 0 )
+ {
+ /* fill random noise for 0 bit subbands */
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ if ( coeff[i] == 0 )
+ {
+ coeff_out[i] = (float) ( own_random( bwe_seed ) ) / PCM16_TO_FLT_FAC;
+ coeff_out[i] *= normq_v[sfm];
+ }
+ }
+
+ env = normq_v[sfm];
+ }
+ if ( sfm == SFM_N_WB - 1 && prev_is_transient == 0 && prev_normq[sfm] > 0.5f * normq_v[sfm] && prev_normq[sfm] < 2.0f * normq_v[sfm] && bitalloc_var <= 0.3f )
+ {
+ float *p_prev_coeff_out = prev_coeff_out;
+ for ( i = sfm_start[sfm] + 12; i < sfm_end[sfm]; i++ )
+ {
+ if ( fabs( coeff_out[i] ) > 4.0f * fabs( *p_prev_coeff_out ) ||
+ fabs( coeff_out[i] ) < 0.25f * fabs( *p_prev_coeff_out ) ||
+ ( R[sfm] * ( *prev_R ) == 0 && R[sfm] + ( *prev_R ) != 0 ) )
+ {
+ coeff_out[i] = ( coeff_out[i] > 0 ) ? (float) ( 0.5f * ( fabs( coeff_out[i] ) + fabs( *p_prev_coeff_out ) ) ) : (float) ( -0.5f * ( fabs( coeff_out[i] ) + fabs( *p_prev_coeff_out ) ) );
+ }
+ p_prev_coeff_out++;
+ }
+ }
+
+ prev_env[sfm] = env;
+ }
+ }
+ else
+ {
+ /* fill random noise for 0 bit subbands of transient frame */
+ for ( sfm = 0; sfm < num_sfm; sfm++ )
+ {
+ if ( R[sfm] == 0 )
+ {
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ coeff_out[i] = (float) ( own_random( bwe_seed ) ) / PCM16_TO_FLT_FAC;
+ coeff_out[i] *= normq_v[sfm];
+ }
+ }
+ }
+
+ set_f( prev_env, 0, SFM_N_WB );
+ }
+
+ mvr2r( normq_v, prev_normq, SFM_N_WB );
+ mvr2r( coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE );
+ *prev_R = R[SFM_N_WB - 1];
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * enforce_zero_for_min_envelope()
+ *
+ * Detect minimum level of envelope and set corresponding bands to zero
+ *--------------------------------------------------------------------------*/
+
+void enforce_zero_for_min_envelope(
+ const int16_t hqswb_clas, /* i : HQ coding mode */
+ const int16_t *ynrm, /* i : Envelope indices */
+ float *coefsq, /* i/o: Quantized spectrum/zeroed spectrum */
+ int16_t nb_sfm, /* i : Number of coded sub bands */
+ const int16_t *sfm_start, /* i : Sub band start indices */
+ const int16_t *sfm_end /* i : Sub band end indices */
+)
+{
+ int16_t i, j;
+
+ /* prevent non-zero output for all-zero input */
+ if ( hqswb_clas != HQ_HVQ )
+ {
+ if ( ynrm[0] == 31 )
+ {
+ for ( j = sfm_start[0]; j < sfm_end[0]; j++ )
+ {
+ coefsq[j] = 0.0f;
+ }
+ }
+
+ for ( i = 1; i < nb_sfm; i++ )
+ {
+ if ( ynrm[i] == 39 )
+ {
+ for ( j = sfm_start[i]; j < sfm_end[i]; j++ )
+ {
+ coefsq[j] = 0.0f;
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * overlap_hq_bwe()
+ *
+ * Overlapping at the boundary between HQ core and BWE
+ *--------------------------------------------------------------------------*/
+
+static void overlap_hq_bwe(
+ const float *hq_swb_overlap_buf, /* i : spectrum from HQ core */
+ float *coeff_out, /* i/o: spectrum from BWE, overlapped output */
+ const int16_t n_swb_overlap_offset, /* i : starting offset of overlapping */
+ const int16_t n_swb_overlap, /* i : length of overlapping */
+ const int16_t *R, /* i : Bit allocation */
+ const int16_t num_env_bands, /* i : Number of coded envelope bands */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int16_t *sfm_end /* i : Band end indices */
+)
+{
+ int16_t i;
+ float step;
+ float weighting;
+ int16_t n_band;
+
+ if ( R[num_env_bands - 1] != 0 )
+ {
+ mvr2r( hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap );
+ }
+ else
+ {
+ /*weighting = 0.8f;*/
+ step = 1.0f / (float) n_swb_overlap;
+ weighting = 1.0f;
+ for ( i = 0; i < n_swb_overlap; i++ )
+ {
+ coeff_out[n_swb_overlap_offset + i] = hq_swb_overlap_buf[i] * weighting + coeff_out[n_swb_overlap_offset + i] * ( 1.0f - weighting );
+ weighting -= step;
+ }
+ }
+
+
+ for ( n_band = num_env_bands; n_band < num_sfm; n_band++ )
+ {
+ if ( R[n_band] != 0 )
+ {
+ for ( i = sfm_end[n_band - 1]; i < sfm_end[n_band]; ++i )
+ {
+ coeff_out[i] = hq_swb_overlap_buf[i - n_swb_overlap_offset];
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * apply_envelope()
+ *
+ * Apply spectral envelope with envelope adjustments
+ *--------------------------------------------------------------------------*/
+
+void apply_envelope(
+ const float *coeff, /* i/o: Coded/noisefilled normalized spectrum */
+ const int16_t *norm, /* i : Envelope */
+ const float *norm_adj, /* i : Envelope adjustment */
+ const int16_t num_sfm, /* i : Total number of bands */
+ const int16_t last_sfm, /* i : Last coded band */
+ const int16_t HQ_mode, /* i : HQ mode */
+ const int16_t length, /* i : Frame length */
+ const int16_t *sfm_start, /* i : Sub band start indices */
+ const int16_t *sfm_end, /* i : Sub band end indices */
+ float *normq_v, /* o : Envelope with adjustment */
+ float *coeff_out, /* o : coded/noisefilled spectrum */
+ float *coeff_out1 /* o : noisefilled spectrum for HQ SWE BWE */
+)
+{
+ int16_t i;
+ int16_t sfm;
+ float normq;
+ int16_t len;
+
+ len = num_sfm;
+ if ( HQ_mode == HQ_GEN_SWB || HQ_mode == HQ_GEN_FB )
+ {
+ len = last_sfm + 1;
+ }
+
+ if ( length == L_FRAME16k )
+ {
+ for ( sfm = 0; sfm < num_sfm; sfm++ )
+ {
+ normq_v[sfm] = dicn[norm[sfm]];
+ normq = normq_v[sfm] * norm_adj[sfm];
+
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ coeff_out[i] = coeff[i] * normq;
+ }
+ }
+ }
+ else
+ {
+ for ( sfm = 0; sfm < len; sfm++ )
+ {
+ normq_v[sfm] = dicn[norm[sfm]];
+ normq_v[sfm] *= norm_adj[sfm];
+
+ normq = normq_v[sfm];
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ coeff_out[i] = coeff[i] * normq;
+ }
+ }
+
+ if ( HQ_mode == HQ_GEN_SWB || HQ_mode == HQ_GEN_FB )
+ {
+ for ( sfm = 0; sfm <= last_sfm; sfm++ )
+ {
+ normq = normq_v[sfm];
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ coeff_out1[i] = coeff_out1[i] * normq;
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * apply_envelope_enc()
+ *
+ * Apply spectral envelope without envelope adjustments and noisefill
+ *--------------------------------------------------------------------------*/
+
+void apply_envelope_enc(
+ float *coeff, /* i/o: Normalized/scaled normalized spectrum */
+ const int16_t *norm, /* i : Envelope */
+ const int16_t num_sfm, /* i : Total number of bands */
+ const int16_t *sfm_start, /* i : Sub band start indices */
+ const int16_t *sfm_end /* i : Sub band end indices */
+)
+{
+ int16_t sfm;
+ int16_t i;
+ float normq;
+
+ for ( sfm = 0; sfm < num_sfm; sfm++ )
+ {
+ normq = dicn[norm[sfm]];
+
+ for ( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ )
+ {
+ coeff[i] *= normq;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------
+ * floating_point_add()
+ *
+ * Add two floating point numbers in integer representation: x <- x + y
+ * Ported from BASOP code to ensure interoperability
+ *----------------------------------------------------------------------------*/
+
+void floating_point_add(
+ int32_t *mx, /* i/o: mantissa of the addend Q31 */
+ int16_t *ex, /* i/o: exponent of the addend Q0 */
+ const int32_t my, /* i : mantissa of the adder Q31 */
+ const int16_t ey /* i : exponent of the adder Q0 */
+)
+{
+ Word32 accX, accY;
+ Word16 align, expo;
+
+ accX = *mx >> 1;
+ accY = my >> 1;
+ align = *ex - ey;
+ if ( align < 0 )
+ {
+ if ( align > -32 ) /* If align < -32, (accY >> (-align) = 0 */
+ {
+ accX = accX + ( accY >> ( -align ) );
+ }
+ }
+ else
+ {
+ if ( align < 32 ) /* If align > 32, (accX >> align) = 0 */
+ {
+ accX = accY + ( accX >> align );
+ }
+ else
+ {
+ accX = accY;
+ }
+ *ex = ey;
+ }
+ expo = norm_l( accX ); /* aligned to BASOP */
+ *mx = accX << expo;
+ *ex = *ex + expo - 1;
+
+ return;
+}
diff --git a/lib_com/hvq_pvq_bitalloc.c b/lib_com/hvq_pvq_bitalloc.c
new file mode 100644
index 0000000000000000000000000000000000000000..5ff0d3344c0f805295cb3983955190c528492bb8
--- /dev/null
+++ b/lib_com/hvq_pvq_bitalloc.c
@@ -0,0 +1,187 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*/
+/* Function hvq_pvq_bitalloc */
+/* ~~~~~~~~~~~~~~~~~~~~~~~~ */
+/* */
+/* Calculate the number of PVQ bands to code and allocate bits based on */
+/* the number of available bits. */
+/*--------------------------------------------------------------------------*/
+
+/*! r: Number of low frequency bands */
+int16_t hvq_pvq_bitalloc(
+ int16_t num_bits, /* i/o: Number of available bits (including gain bits)*/
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t bwidth, /* i : Encoded bandwidth */
+ const int16_t *ynrm, /* i : Envelope coefficients */
+ const int32_t manE_peak, /* i : Peak energy mantissa */
+ const int16_t expE_peak, /* i : Peak energy exponent */
+ int16_t *Rk, /* o : bit allocation for concatenated vector */
+ int16_t *R, /* i/o: Global bit allocation */
+ int16_t *sel_bands, /* o : Selected bands for encoding */
+ int16_t *n_sel_bands /* o : No. of selected bands for encoding */
+)
+{
+ int16_t num_bands, k, band_max_bits;
+ int16_t k_max;
+ int16_t k_start;
+ float E_max;
+ int32_t E_max5;
+ int16_t expo;
+ int16_t align;
+ int32_t acc;
+ float tmp;
+ int32_t env_mean;
+ int16_t reciprocal;
+ int16_t num_sfm;
+ int16_t bit_cost;
+
+ if ( bwidth == FB )
+ {
+ num_sfm = SFM_N_HARM_FB;
+ }
+ else
+ {
+ num_sfm = SFM_N_HARM;
+ }
+
+ if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
+ {
+ band_max_bits = HVQ_BAND_MAX_BITS_24k;
+ k_start = HVQ_THRES_SFM_24k;
+ if ( bwidth == FB )
+ {
+ reciprocal = 2731;
+ }
+ else
+ {
+ reciprocal = 3277;
+ }
+ }
+ else
+ {
+ band_max_bits = HVQ_BAND_MAX_BITS_32k;
+ k_start = HVQ_THRES_SFM_32k;
+ if ( bwidth == FB )
+ {
+ reciprocal = 3641;
+ }
+ else
+ {
+ reciprocal = 4681;
+ }
+ }
+
+ num_bands = num_bits / band_max_bits;
+ num_bits = num_bits - num_bands * band_max_bits;
+
+ if ( num_bits >= HVQ_NEW_BAND_BIT_THR )
+ {
+ num_bands++;
+ }
+ else
+ {
+ num_bits += band_max_bits;
+ }
+
+ /* safety check in case of bit errors */
+ if ( num_bands < 1 )
+ {
+ return 0;
+ }
+
+ *n_sel_bands = 0;
+ env_mean = 0;
+ E_max = 0;
+ k_max = k_start;
+ for ( k = k_start; k < num_sfm; k++ )
+ {
+ tmp = dicn[ynrm[k]];
+ env_mean += ynrm[k];
+ if ( tmp > E_max )
+ {
+ E_max = tmp;
+ k_max = k;
+ }
+ }
+ env_mean = 2 * ( env_mean * reciprocal );
+
+ if ( band_len_harm[k_max] == 96 )
+ {
+ bit_cost = 61;
+ }
+ else
+ {
+ QuantaPerDsDirac( band_len_harm[k_max], 1, hBitsN, &bit_cost );
+ }
+
+
+ expo = max( 0, ynrm[k_max] - 1 ) >> 1;
+ E_max5 = E_max5_tbl[ynrm[k_max]];
+ align = expo - expE_peak;
+ align = align + ( 19 - 14 ) - ( 31 - 2 * 12 );
+ if ( align < 0 )
+ {
+ acc = E_max5 - ( manE_peak >> -align );
+ }
+ else
+ {
+ acc = ( E_max5 >> align ) - manE_peak;
+ }
+ if ( acc > 0 && ( ( env_mean - ( ynrm[k_max] << 16 ) ) > 0x30000L ) && num_bands > 1 && ( num_bits - HVQ_PVQ_GAIN_BITS ) << 3 >= bit_cost )
+ {
+ sel_bands[*n_sel_bands] = k_max;
+ ( *n_sel_bands )++;
+ R[k_max] = 1; /* Mark that the band has been encoded for fill_spectrum */
+ }
+
+ /* Allocate bits */
+ for ( k = 0; k < num_bands - 1; k++ )
+ {
+ Rk[k] = band_max_bits - HVQ_PVQ_GAIN_BITS;
+ }
+ Rk[num_bands - 1] = num_bits - HVQ_PVQ_GAIN_BITS;
+
+ return num_bands;
+}
diff --git a/lib_com/ifft_rel.c b/lib_com/ifft_rel.c
new file mode 100644
index 0000000000000000000000000000000000000000..597a5d1734f916e6aacaeac7f6098f1ff1486e71
--- /dev/null
+++ b/lib_com/ifft_rel.c
@@ -0,0 +1,287 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*-----------------------------------------------------------------*
+ * Local constants
+ *-----------------------------------------------------------------*/
+
+#define N_MAX_FFT 1024
+
+/*---------------------------------------------------------------------*
+ * ifft_rel()
+ *
+ * Calculate the inverse FFT of a real signal
+ *
+ * Based on the FORTRAN code from the article "Real-valued Fast Fourier Transform Algorithms"
+ * by Sorensen, ... in IEEE Trans. on ASSP, Vol. ASSP-35, No. June 6th 1987.
+ *
+ * Input: the io[] signal containing the spectrum in the following order :
+ *
+ * Re[0], Re[1], .. Re[n/2], Im[n/2-1], .. Im[1]
+ *---------------------------------------------------------------------*/
+
+void ifft_rel(
+ float io[], /* i/o: input/output vector */
+ const int16_t n, /* i : vector length */
+ const int16_t m /* i : log2 of vector length */
+)
+{
+ int16_t i, j, k;
+ int16_t step;
+ int16_t n2, n4, n8, i0;
+ int16_t is, id;
+ float *x, *xi0, *xi1, *xi2, *xi3, *xi4, *xup1, *xdn6, *xup3, *xdn8;
+ float xt;
+ float r1;
+ float t1, t2, t3, t4, t5;
+ float cc1, cc3, ss1, ss3;
+ const float *s, *s3, *c, *c3;
+ const int16_t *idx;
+ float temp[512];
+ float n_inv;
+
+ n_inv = 1.0f / n;
+
+ /*-----------------------------------------------------------------*
+ * IFFT
+ *-----------------------------------------------------------------*/
+
+ x = &io[-1];
+ n2 = 2 * n;
+ for ( k = 1; k < m; k++ )
+ {
+ is = 0;
+ id = n2;
+ n2 = n2 >> 1;
+ n4 = n2 >> 2;
+ n8 = n4 >> 1;
+ while ( is < n - 1 )
+ {
+ xi1 = x + is + 1;
+ xi2 = xi1 + n4;
+ xi3 = xi2 + n4;
+ xi4 = xi3 + n4;
+
+ for ( i = is; i < n; i += id )
+ {
+ t1 = *xi1 - *xi3;
+ *xi1 += *xi3;
+ *xi2 = 2.0f * *xi2;
+ *xi3 = t1 - 2.0f * *xi4;
+ *xi4 = t1 + 2.0f * *xi4;
+ if ( n4 != 1 )
+ {
+ t1 = ( *( xi2 + n8 ) - *( xi1 + n8 ) ) * INV_SQRT_2;
+ t2 = ( *( xi4 + n8 ) + *( xi3 + n8 ) ) * INV_SQRT_2;
+
+ *( xi1 + n8 ) += *( xi2 + n8 );
+ *( xi2 + n8 ) = *( xi4 + n8 ) - *( xi3 + n8 );
+ *( xi3 + n8 ) = (float) ( 2.0f * ( -t2 - t1 ) );
+ *( xi4 + n8 ) = (float) ( 2.0f * ( -t2 + t1 ) );
+ }
+ xi1 += id;
+ xi2 += id;
+ xi3 += id;
+ xi4 += id;
+ }
+ is = 2 * id - n2;
+ id = 4 * id;
+ }
+ step = N_MAX_FFT / n2;
+
+ s = sincos_t_ext + step;
+ c = s + N_MAX_FFT / 4;
+ s3 = sincos_t_ext + 3 * step;
+ c3 = s3 + N_MAX_FFT / 4;
+ for ( j = 2; j <= n8; j++ )
+ {
+ cc1 = *c;
+ ss1 = *s;
+ cc3 = *c3;
+ ss3 = *s3;
+
+ is = 0;
+ id = 2 * n2;
+
+ c += step;
+ s += step;
+
+ c3 += 3 * step;
+ s3 += 3 * step;
+ while ( is < n - 1 )
+ {
+ xup1 = x + j + is;
+ xup3 = xup1 + 2 * n4;
+ xdn6 = xup3 - 2 * j + 2;
+ xdn8 = xdn6 + 2 * n4;
+
+ for ( i = is; i < n; i += id )
+ {
+ t1 = *xup1 - *xdn6;
+ *xup1 = *xup1 + *xdn6;
+ xup1 += n4;
+ xdn6 -= n4;
+
+ t2 = *xdn6 - *xup1;
+ *xdn6 = *xup1 + *xdn6;
+
+ xdn6 += n4;
+ t3 = *xdn8 + *xup3;
+ *xdn6 = *xdn8 - *xup3;
+
+ xup3 += n4;
+ xdn8 -= n4;
+
+ t4 = *xup3 + *xdn8;
+ *xup1 = *xup3 - *xdn8;
+
+ t5 = t1 - t4;
+ t1 = t1 + t4;
+ t4 = t2 - t3;
+ t2 = t2 + t3;
+ *xup3 = t1 * cc3 - t2 * ss3;
+ xup3 -= n4;
+ *xup3 = t5 * cc1 + t4 * ss1;
+ *xdn8 = -t4 * cc1 + t5 * ss1;
+
+ xdn8 += n4;
+ *xdn8 = t2 * cc3 + t1 * ss3;
+
+ xup1 -= n4;
+ xup1 += id;
+ xup3 += id;
+ xdn6 += id;
+ xdn8 += id;
+ }
+ is = 2 * id - n2;
+ id = 4 * id;
+ }
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Length two butterflies
+ *-----------------------------------------------------------------*/
+
+ is = 1;
+ id = 4;
+ while ( is < n )
+ {
+ xi0 = x + is;
+ xi1 = xi0 + 1;
+
+ for ( i0 = is; i0 <= n; i0 += id )
+ {
+ r1 = *xi0;
+ *xi0 = r1 + *xi1;
+ *xi1 = r1 - *xi1;
+ xi0 += id;
+ xi1 += id;
+ }
+ is = 2 * id - 1;
+ id = 4 * id;
+ }
+
+ /*-----------------------------------------------------------------*
+ * Digit reverse counter
+ *-----------------------------------------------------------------*/
+
+ idx = fft256_read_indexes;
+ xi0 = &temp[0] - 1;
+ if ( n == 128 )
+ {
+ for ( i = 0; i < n; i++ )
+ {
+ j = *idx++;
+ temp[i] = x[1 + ( j >> 1 )];
+ }
+ }
+ else if ( n == 256 )
+ {
+ for ( i = 0; i < n; i++ )
+ {
+ j = *idx++;
+ temp[i] = x[1 + j];
+ }
+ }
+ else if ( n == 512 )
+ {
+ for ( i = 0; i < 256; i++ )
+ {
+ j = *idx++;
+ temp[i] = x[1 + 2 * j];
+ temp[i + 256] = x[2 + 2 * j];
+ }
+ }
+ else
+ {
+ xi0 = x;
+ j = 1;
+ for ( i = 1; i < n; i++ )
+ {
+ if ( i < j )
+ {
+ xt = x[j];
+ x[j] = x[i];
+ x[i] = xt;
+ }
+ k = n >> 1;
+ while ( k < j )
+ {
+ j = j - k;
+ k = k >> 1;
+ }
+ j = j + k;
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Normalization
+ *-----------------------------------------------------------------*/
+
+ for ( i = 1; i <= n; i++ )
+ {
+ x[i] = xi0[i] * n_inv;
+ }
+
+ return;
+}
diff --git a/lib_com/igf_base.c b/lib_com/igf_base.c
new file mode 100644
index 0000000000000000000000000000000000000000..73f7228d0d278b9bbd9eb8472649c1f4863f33e4
--- /dev/null
+++ b/lib_com/igf_base.c
@@ -0,0 +1,738 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * IGF_ApplyTransFac()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+/*! r: | multiplication factor */
+int16_t IGF_ApplyTransFac(
+ const int16_t val, /* i : Q15 | input value for multiplication, Q15 */
+ const float transFac /* i : Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */
+)
+{
+ int16_t ret = val;
+
+ if ( transFac != 1.f )
+ {
+ ret = (int16_t) round_f( val * transFac );
+ ret += ( ret & 1 );
+ }
+
+ return ret;
+}
+
+
+/*---------------------------------------------------------------------*
+ * IGF_MapBitRateToIndex()
+ *
+ * maps a given bitrate to the IGF_BITRATE index
+ *---------------------------------------------------------------------*/
+
+/*! r: bitrate index */
+int16_t IGF_MapBitRateToIndex(
+ const int32_t brate, /* i : bitrate */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t rf_mode /* i : flag to signal the RF mode */
+)
+{
+ int16_t bitRateIndex = IGF_BITRATE_UNKNOWN;
+
+ /* Stereo/CPE modes */
+ if ( element_mode > IVAS_SCE )
+ {
+ switch ( bwidth )
+ {
+ case IGF_MODE_WB:
+ if ( brate <= IVAS_13k2 && rf_mode == 1 )
+ {
+ bitRateIndex = IGF_BITRATE_RF_WB_13200;
+ }
+ else if ( brate <= ACELP_9k60 )
+ {
+ bitRateIndex = IGF_BITRATE_WB_13200_CPE;
+ }
+ else if ( brate <= IVAS_13k2 )
+ {
+ bitRateIndex = IGF_BITRATE_WB_16400_CPE;
+ }
+ break;
+ case IGF_MODE_SWB:
+ /* DFT and TD Stereo bitrates */
+ if ( brate <= ACELP_9k60 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_13200_CPE;
+ }
+ else if ( brate <= IVAS_13k2 )
+ {
+ if ( rf_mode == 1 )
+ {
+ bitRateIndex = IGF_BITRATE_RF_SWB_13200;
+ }
+ else
+ {
+ bitRateIndex = IGF_BITRATE_SWB_16400_CPE;
+ }
+ }
+ else if ( brate <= IVAS_16k4 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_24400_CPE;
+ }
+ else if ( brate <= IVAS_24k4 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_32000_CPE;
+ }
+ else if ( brate <= IVAS_32k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_32000;
+ }
+ /* MDCT Stereo bitrates */
+ else if ( brate <= IVAS_48k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_48000_CPE;
+ }
+ else if ( brate <= IVAS_64k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_64000_CPE;
+ }
+ else if ( brate <= IVAS_80k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_80000_CPE;
+ }
+ else if ( brate <= IVAS_96k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_96000_CPE;
+ }
+ break;
+ case IGF_MODE_FB:
+ /* DFT and TD Stereo bitrates */
+ if ( brate <= IVAS_16k4 )
+ {
+ bitRateIndex = IGF_BITRATE_FB_24400_CPE;
+ }
+ else if ( brate <= IVAS_24k4 )
+ {
+ bitRateIndex = IGF_BITRATE_FB_32000_CPE;
+ }
+ else if ( brate <= IVAS_32k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_32000;
+ }
+ /* MDCT Stereo bitrates */
+ else if ( brate <= IVAS_48k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_48000_CPE;
+ }
+ else if ( brate <= IVAS_64k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_64000_CPE;
+ }
+ else if ( brate <= IVAS_80k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_80000_CPE;
+ }
+ else if ( brate <= IVAS_96k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_96000_CPE;
+ }
+ else if ( brate <= IVAS_128k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_128000_CPE;
+ }
+ break;
+ }
+ }
+ /* SCE modes: use tunings done for DFT stereo bitrates also for according SCE bitrates, otherwise same config as mono modes */
+ else if ( element_mode == IVAS_SCE )
+ {
+ switch ( bwidth )
+ {
+ case IGF_MODE_WB:
+ if ( brate <= IVAS_13k2 && rf_mode == 1 )
+ {
+ bitRateIndex = IGF_BITRATE_RF_WB_13200;
+ }
+ else if ( brate <= ACELP_9k60 ) /* bitrates 8000 and 9600 */
+ {
+ bitRateIndex = IGF_BITRATE_WB_9600;
+ }
+ break;
+ case IGF_MODE_SWB:
+ if ( brate <= ACELP_9k60 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_13200_CPE;
+ }
+ else if ( brate <= IVAS_13k2 )
+ {
+ if ( rf_mode == 1 )
+ {
+ bitRateIndex = IGF_BITRATE_RF_SWB_13200;
+ }
+ else
+ {
+ bitRateIndex = IGF_BITRATE_SWB_16400_CPE;
+ }
+ }
+ else if ( brate <= IVAS_16k4 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_24400_CPE;
+ }
+ else if ( brate <= IVAS_24k4 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_32000_CPE;
+ }
+ else if ( brate <= IVAS_32k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_32000;
+ }
+ else if ( brate <= IVAS_48k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_48000;
+ }
+ else if ( brate <= IVAS_64k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_64000;
+ }
+ break;
+ case IGF_MODE_FB:
+ if ( brate <= IVAS_16k4 )
+ {
+ bitRateIndex = IGF_BITRATE_FB_24400_CPE;
+ }
+ else if ( brate <= IVAS_24k4 )
+ {
+ bitRateIndex = IGF_BITRATE_FB_32000_CPE;
+ }
+ else if ( brate <= IVAS_32k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_32000;
+ }
+ else if ( brate <= IVAS_48k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_48000;
+ }
+ else if ( brate <= IVAS_64k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_64000;
+ }
+ else if ( brate <= IVAS_96k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_96000;
+ }
+ else if ( brate <= IVAS_128k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_128000;
+ }
+ break;
+ }
+ }
+ /* EVS mono */
+ else
+ {
+ switch ( bwidth )
+ {
+ case IGF_MODE_WB:
+ if ( brate <= ACELP_13k20 && rf_mode == 1 )
+ {
+ bitRateIndex = IGF_BITRATE_RF_WB_13200;
+ }
+ else if ( brate <= ACELP_9k60 ) /* bitrates 8000 and 9600 */
+ {
+ bitRateIndex = IGF_BITRATE_WB_9600;
+ }
+ break;
+ case IGF_MODE_SWB:
+ if ( brate <= ACELP_9k60 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_9600;
+ }
+ else if ( brate <= ACELP_13k20 )
+ {
+ if ( rf_mode == 1 )
+ {
+ bitRateIndex = IGF_BITRATE_RF_SWB_13200;
+ }
+ else
+ {
+ bitRateIndex = IGF_BITRATE_SWB_13200;
+ }
+ }
+ else if ( brate <= ACELP_16k40 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_16400;
+ }
+ else if ( brate <= ACELP_24k40 )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_24400;
+ }
+ else if ( brate <= ACELP_32k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_32000;
+ }
+ else if ( brate <= ACELP_48k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_48000;
+ }
+ else if ( brate <= ACELP_64k )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_64000;
+ }
+ break;
+ case IGF_MODE_FB:
+ if ( brate <= ACELP_16k40 )
+ {
+ bitRateIndex = IGF_BITRATE_FB_16400;
+ }
+ else if ( brate <= ACELP_24k40 )
+ {
+ bitRateIndex = IGF_BITRATE_FB_24400;
+ }
+ else if ( brate <= ACELP_32k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_32000;
+ }
+ else if ( brate <= ACELP_48k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_48000;
+ }
+ else if ( brate <= ACELP_64k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_64000;
+ }
+ else if ( brate <= HQ_96k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_96000;
+ }
+ else if ( brate <= HQ_128k )
+ {
+ bitRateIndex = IGF_BITRATE_FB_128000;
+ }
+ break;
+ }
+ }
+
+ return bitRateIndex;
+}
+
+
+/*---------------------------------------------------------------------*
+ * IGF_gridSetUp()
+ *
+ * IGF grid setup
+ *---------------------------------------------------------------------*/
+
+static void IGF_gridSetUp(
+ H_IGF_GRID hGrid, /* o : IGF grid handle */
+ int16_t bitRateIndex, /* i : IGF bitrate index */
+ const int32_t sampleRate, /* i : sample rate */
+ int16_t frameLength, /* i : frame length */
+ const float transFac, /* i : transFac */
+ const int16_t igfMinFq /* i : IGF minimum frequency indicating lower start frequency for copy up */
+)
+{
+ int16_t t, k;
+ int16_t sfb;
+ int16_t swb_offset_len;
+ const int16_t *swb_offset;
+ float bandwidth;
+ const int16_t *igf_tile_offset;
+
+ /* inits */
+ swb_offset = NULL;
+ swb_offset_len = 0;
+ if ( transFac == 0.5f && bitRateIndex == IGF_BITRATE_SWB_48000_CPE )
+ {
+ bitRateIndex = IGF_BITRATE_SWB_48000_CPE_TCX10;
+ }
+ else if ( transFac == 0.5f && bitRateIndex == IGF_BITRATE_FB_48000_CPE )
+ {
+ bitRateIndex = IGF_BITRATE_FB_48000_CPE_TCX10;
+ }
+
+ if ( bitRateIndex != IGF_BITRATE_UNKNOWN )
+ {
+ swb_offset = &swb_offset_LB_new[bitRateIndex][1];
+ swb_offset_len = swb_offset_LB_new[bitRateIndex][0];
+ mvr2r( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 );
+ }
+ else
+ {
+ assert( 0 );
+ }
+
+ for ( sfb = 0; sfb < swb_offset_len; sfb++ )
+ {
+ hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac );
+ }
+ for ( sfb = swb_offset_len; sfb < IGF_MAX_SFB; sfb++ )
+ {
+ hGrid->swb_offset[sfb] = 0;
+ }
+
+ hGrid->infoIsRefined = 0;
+ frameLength = IGF_ApplyTransFac( frameLength, transFac );
+ bandwidth = (float) sampleRate / 2.0f / (float) frameLength;
+ hGrid->swb_offset_len = swb_offset_len;
+ hGrid->startSfb = 0;
+ hGrid->stopSfb = hGrid->swb_offset_len - 1;
+ hGrid->startLine = hGrid->swb_offset[hGrid->startSfb];
+ hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb];
+ hGrid->startFrequency = (int16_t) round_f( bandwidth * hGrid->startLine );
+ hGrid->stopFrequency = (int16_t) round_f( bandwidth * hGrid->stopLine );
+ hGrid->minSrcSubband = (int16_t) round_f( ( igfMinFq * ( frameLength ) ) / ( sampleRate >> 1 ) );
+ hGrid->minSrcSubband += hGrid->minSrcSubband % 2;
+ hGrid->minSrcFrequency = (int16_t) round_f( bandwidth * hGrid->minSrcSubband );
+ hGrid->infoGranuleLen = frameLength;
+ hGrid->sfbWrap[0] = 0;
+ hGrid->tile[0] = hGrid->startLine;
+
+ igf_tile_offset = &igf_tile_offset_table[bitRateIndex][1];
+ hGrid->nTiles = igf_tile_offset_table[bitRateIndex][0];
+ hGrid->tile[0] = hGrid->startLine;
+ hGrid->sfbWrap[0] = 0;
+ for ( k = 0; k < hGrid->nTiles; k++ )
+ {
+ hGrid->sfbWrap[k + 1] = igf_tile_offset[2 * k];
+ hGrid->sbWrap[k] = hGrid->minSrcSubband + IGF_ApplyTransFac( igf_tile_offset[2 * k + 1], transFac );
+ hGrid->tile[k + 1] = hGrid->swb_offset[igf_tile_offset[2 * k]];
+ }
+ for ( t = hGrid->nTiles + 1; t < IGF_MAX_TILES; t++ )
+ {
+ hGrid->tile[t] = 0;
+ hGrid->sbWrap[t - 1] = 0;
+ hGrid->sfbWrap[t] = 0;
+ }
+
+ /* adapt level envelope: */
+ switch ( bitRateIndex )
+ {
+ case IGF_BITRATE_RF_WB_13200:
+ case IGF_BITRATE_WB_9600:
+ case IGF_BITRATE_WB_13200_CPE:
+ case IGF_BITRATE_WB_16400_CPE:
+ hGrid->gFactor = 0.800f;
+ hGrid->fFactor = 0.70f;
+ hGrid->lFactor = 0.60f;
+ break;
+ case IGF_BITRATE_SWB_13200:
+ case IGF_BITRATE_SWB_16400_CPE:
+ case IGF_BITRATE_FB_16400:
+ case IGF_BITRATE_SWB_16400:
+ case IGF_BITRATE_FB_24400_CPE:
+ case IGF_BITRATE_SWB_24400_CPE:
+ hGrid->gFactor = 0.930f;
+ hGrid->fFactor = 0.20f;
+ hGrid->lFactor = 0.85f;
+ break;
+ case IGF_BITRATE_FB_24400:
+ case IGF_BITRATE_SWB_24400:
+ case IGF_BITRATE_FB_32000_CPE:
+ case IGF_BITRATE_SWB_32000_CPE:
+ case IGF_BITRATE_FB_32000:
+ case IGF_BITRATE_SWB_32000:
+ case IGF_BITRATE_SWB_48000_CPE:
+ case IGF_BITRATE_SWB_64000_CPE:
+ hGrid->gFactor = 0.965f;
+ hGrid->fFactor = 0.20f;
+ hGrid->lFactor = 0.85f;
+ break;
+ case IGF_BITRATE_FB_48000:
+ case IGF_BITRATE_SWB_48000:
+ case IGF_BITRATE_FB_64000:
+ case IGF_BITRATE_SWB_64000:
+ case IGF_BITRATE_SWB_80000_CPE:
+ case IGF_BITRATE_SWB_96000_CPE:
+ hGrid->gFactor = 1.000f;
+ hGrid->fFactor = 0.20f;
+ hGrid->lFactor = 1.000f;
+ break;
+ case IGF_BITRATE_SWB_9600:
+ case IGF_BITRATE_SWB_13200_CPE:
+ case IGF_BITRATE_RF_SWB_13200:
+ default:
+ hGrid->gFactor = 1.000f;
+ hGrid->fFactor = 0.00f;
+ hGrid->lFactor = 1.000f;
+ }
+
+ for ( t = hGrid->nTiles + 1; t < IGF_MAX_TILES; t++ )
+ {
+ hGrid->tile[t] = 0;
+ hGrid->sbWrap[t - 1] = 0;
+ hGrid->sfbWrap[t] = 0;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * IGFCommonFuncsIGFConfiguration()
+ *
+ * changes the IGF configuration
+ *---------------------------------------------------------------------*/
+
+/*! r: error value: 0 -> error, 1 -> ok */
+int16_t IGFCommonFuncsIGFConfiguration(
+ const int32_t total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int16_t element_mode, /* i : element mode */
+ H_IGF_INFO hIGFInfo, /* o : IGF info handle */
+ const int16_t rf_mode /* i : flag to signal the RF mode */
+)
+{
+ H_IGF_GRID hGrid;
+ int16_t retValue;
+ int32_t sampleRate;
+ int16_t frameLength;
+ int16_t igfMinFq;
+ int16_t maxHopsize;
+
+ retValue = 0; /* bitrate index is unknown -> error! */
+
+ /* interface call for reading in settings */
+ hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode );
+
+ if ( hIGFInfo->bitRateIndex != IGF_BITRATE_UNKNOWN )
+ {
+ retValue = 1; /* no error */
+
+ /* mapping to local values */
+ sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate;
+ frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength;
+ igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq;
+ maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize;
+
+ /* basic information */
+ hIGFInfo->sampleRate = sampleRate;
+ hIGFInfo->frameLength = frameLength;
+ hIGFInfo->maxHopsize = maxHopsize;
+ hIGFInfo->nfSeedBuf[0] = 0;
+ hIGFInfo->nfSeedBuf[1] = 0;
+ hIGFInfo->nfSeed = &hIGFInfo->nfSeedBuf[0];
+
+ /* set up regular IGF grid for TCX 20 (transfac = 1.f) */
+ hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM];
+ IGF_gridSetUp( hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 1.00f, igfMinFq );
+
+ /* set up IGF grid for CELP->TCX 20 transitions (transfac = 1.25) */
+ hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN];
+ IGF_gridSetUp( hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 1.25f, igfMinFq );
+
+ /* set up IGF grid for TCX 10 (transfac = 0.5) */
+ hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT];
+ IGF_gridSetUp( hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 0.50f, igfMinFq );
+ }
+
+ return retValue;
+}
+
+
+/*---------------------------------------------------------------------*
+ * IGFCommonFuncsIGFGetCFTables()
+ *
+ * selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder
+ *---------------------------------------------------------------------*/
+
+/*! r: error value: 0 -> error, 1 -> ok */
+int16_t IGFCommonFuncsIGFGetCFTables(
+ const int32_t total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t rf_mode, /* i : flag to signal the RF mode */
+ const uint16_t **cf_se00, /* o : CF table for t == 0 and f == 0 */
+ const uint16_t **cf_se01, /* o : CF table for t == 0 and f == 1 */
+ int16_t *cf_off_se01, /* o : offset for CF table above */
+ const uint16_t **cf_se02, /* o : CF tables for t == 0 and f >= 2 */
+ const int16_t **cf_off_se02, /* o : offsets for CF tables above */
+ const uint16_t **cf_se10, /* o : CF table for t == 1 and f == 0 */
+ int16_t *cf_off_se10, /* o : offset for CF table above */
+ const uint16_t **cf_se11, /* o : CF tables for t == 1 and f >= 1 */
+ const int16_t **cf_off_se11 /* o : offsets for CF tables above */
+)
+{
+ int16_t retValue;
+ int16_t bitRateIndex;
+
+ retValue = 0; /* bitrate index is unknown -> error! */
+
+ bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode );
+
+ if ( bitRateIndex != IGF_BITRATE_UNKNOWN )
+ {
+ retValue = 1; /* no error */
+
+ switch ( bitRateIndex )
+ {
+ case IGF_BITRATE_WB_13200_CPE:
+ bitRateIndex = IGF_BITRATE_WB_9600;
+ break;
+ case IGF_BITRATE_WB_16400_CPE:
+ bitRateIndex = IGF_BITRATE_WB_9600;
+ break;
+ case IGF_BITRATE_SWB_13200_CPE:
+ bitRateIndex = IGF_BITRATE_SWB_9600;
+ break;
+ case IGF_BITRATE_SWB_16400_CPE:
+ bitRateIndex = IGF_BITRATE_SWB_13200;
+ break;
+ case IGF_BITRATE_SWB_24400_CPE:
+ bitRateIndex = IGF_BITRATE_SWB_16400;
+ break;
+ case IGF_BITRATE_FB_24400_CPE:
+ bitRateIndex = IGF_BITRATE_FB_16400;
+ break;
+ case IGF_BITRATE_SWB_32000_CPE:
+ bitRateIndex = IGF_BITRATE_SWB_24400;
+ break;
+ case IGF_BITRATE_FB_32000_CPE:
+ bitRateIndex = IGF_BITRATE_FB_24400;
+ break;
+ case IGF_BITRATE_FB_48000_CPE:
+ case IGF_BITRATE_FB_64000_CPE:
+ bitRateIndex = IGF_BITRATE_FB_32000;
+ break;
+ }
+
+ switch ( bitRateIndex )
+ {
+ case IGF_BITRATE_WB_9600:
+ case IGF_BITRATE_RF_WB_13200:
+ case IGF_BITRATE_SWB_9600:
+ case IGF_BITRATE_SWB_13200:
+ case IGF_BITRATE_RF_SWB_13200:
+ case IGF_BITRATE_SWB_16400:
+ case IGF_BITRATE_SWB_24400:
+ case IGF_BITRATE_SWB_32000:
+ case IGF_BITRATE_SWB_48000:
+ case IGF_BITRATE_SWB_64000:
+ *cf_se00 = cf_se00_tab;
+ *cf_se01 = cf_se01_tab[bitRateIndex];
+ *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
+ *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
+ *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
+ *cf_se10 = &cf_se10_tab[0];
+ *cf_off_se10 = cf_off_se10_tab;
+ *cf_se11 = &cf_se11_tab[0][0][0];
+ *cf_off_se11 = &cf_off_se11_tab[0][0];
+ break;
+ case IGF_BITRATE_FB_16400:
+ case IGF_BITRATE_FB_24400:
+ case IGF_BITRATE_FB_32000:
+ bitRateIndex = bitRateIndex - IGF_BITRATE_FB_16400 + IGF_BITRATE_SWB_16400;
+ *cf_se00 = cf_se00_tab;
+ *cf_se01 = cf_se01_tab[bitRateIndex];
+ *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
+ *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
+ *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
+ *cf_se10 = &cf_se10_tab[0];
+ *cf_off_se10 = cf_off_se10_tab;
+ *cf_se11 = &cf_se11_tab[0][0][0];
+ *cf_off_se11 = &cf_off_se11_tab[0][0];
+ break;
+ case IGF_BITRATE_FB_48000:
+ case IGF_BITRATE_FB_64000:
+ bitRateIndex = bitRateIndex - IGF_BITRATE_FB_48000 + IGF_BITRATE_SWB_48000;
+ *cf_se00 = cf_se00_tab;
+ *cf_se01 = cf_se01_tab[bitRateIndex];
+ *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
+ *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
+ *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
+ *cf_se10 = &cf_se10_tab[0];
+ *cf_off_se10 = cf_off_se10_tab;
+ *cf_se11 = &cf_se11_tab[0][0][0];
+ *cf_off_se11 = &cf_off_se11_tab[0][0];
+ break;
+ case IGF_BITRATE_FB_96000:
+ case IGF_BITRATE_FB_128000:
+ case IGF_BITRATE_FB_80000_CPE:
+ case IGF_BITRATE_FB_96000_CPE:
+ case IGF_BITRATE_FB_128000_CPE:
+ bitRateIndex = IGF_BITRATE_SWB_48000;
+ *cf_se00 = cf_se00_tab;
+ *cf_se01 = cf_se01_tab[bitRateIndex];
+ *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
+ *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
+ *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
+ *cf_se10 = &cf_se10_tab[0];
+ *cf_off_se10 = cf_off_se10_tab;
+ *cf_se11 = &cf_se11_tab[0][0][0];
+ *cf_off_se11 = &cf_off_se11_tab[0][0];
+ break;
+ case IGF_BITRATE_SWB_48000_CPE:
+ bitRateIndex = IGF_BITRATE_SWB_16400;
+ *cf_se00 = cf_se00_tab;
+ *cf_se01 = cf_se01_tab[bitRateIndex];
+ *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
+ *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
+ *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
+ *cf_se10 = &cf_se10_tab[0];
+ *cf_off_se10 = cf_off_se10_tab;
+ *cf_se11 = &cf_se11_tab[0][0][0];
+ *cf_off_se11 = &cf_off_se11_tab[0][0];
+ break;
+ case IGF_BITRATE_SWB_64000_CPE:
+ case IGF_BITRATE_SWB_80000_CPE:
+ case IGF_BITRATE_SWB_96000_CPE:
+ bitRateIndex = IGF_BITRATE_SWB_48000; /*bitRateIndex-IGF_BITRATE_SWB_56000+IGF_BITRATE_SWB_48000;*/
+ *cf_se00 = cf_se00_tab;
+ *cf_se01 = cf_se01_tab[bitRateIndex];
+ *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
+ *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
+ *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
+ *cf_se10 = &cf_se10_tab[0];
+ *cf_off_se10 = cf_off_se10_tab;
+ *cf_se11 = &cf_se11_tab[0][0][0];
+ *cf_off_se11 = &cf_off_se11_tab[0][0];
+ break;
+ case IGF_BITRATE_UNKNOWN:
+ default:
+ assert( 0 );
+ }
+ }
+
+ return retValue;
+}
diff --git a/lib_com/index_pvq_opt.c b/lib_com/index_pvq_opt.c
new file mode 100644
index 0000000000000000000000000000000000000000..b14fd8fa37980476b6f18e4bc68d687fdc6ded25
--- /dev/null
+++ b/lib_com/index_pvq_opt.c
@@ -0,0 +1,1239 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * LOCAL DEFINITIONS
+ *-------------------------------------------------------------------*/
+
+#define N_OPT 5 /* complexity setting, direct functional calculation limit */
+#define TABLE_LIM_OPT 96 /* odd divisor table recursion limit setting, due to dim 6 */
+
+/* local typedefs for optimized pvq indexing, used only in this c-file to vectorize common function calls for c-code clarity */
+typedef void ( *VEC2INDFUNCM )( const int16_t *, int16_t *, uint32_t *, uint32_t * );
+typedef uint32_t ( *NFUNCM )( int16_t );
+typedef uint32_t ( *H_FUNCM )( uint32_t );
+typedef void ( *IND2VECFUNCM )( int16_t, int16_t, uint32_t, int16_t * );
+typedef void ( *NDIM_FUNCM )( int16_t, int16_t, uint32_t, int16_t * );
+
+/* local constants for indexing functions c-code clarity */
+#ifndef ONE_U
+
+#define ZERO 0
+#define ONE 1
+#define ONE_U 1u
+#define TWO 2
+#define SIGNBIT 0x80000000u
+
+#define MAXBIT 0x40000000L /* if Word32 */
+#define MINNEG 0xffffffffL
+
+#define UDIVBY3 2863311531U
+
+
+/*-------------------------------------------------------------------*
+ * local_norm_l_opt
+ *
+ * rewritten version of STL norm_l for integer fixed point normalization
+ * in floating point c-code.
+ *-------------------------------------------------------------------*/
+
+/*! r: shifts needed for normalization */
+static int16_t local_norm_l_opt(
+ int32_t l32var /* i/o: signed 32-bit input value */
+)
+{
+ int16_t l32res;
+
+#define WMC_TOOL_SKIP
+
+ if ( l32var == (int32_t) MINNEG )
+ {
+ return ( 32 - ONE );
+ }
+ else
+ {
+ if ( l32var == ZERO )
+ {
+ return ZERO;
+ }
+ else
+ {
+ if ( l32var < ZERO )
+ {
+ l32var = ~l32var;
+ }
+
+ for ( l32res = ZERO; l32var < (int32_t) MAXBIT; l32res++ )
+ {
+ l32var <<= ONE;
+ }
+ }
+ }
+#undef WMC_TOOL_SKIP
+
+ return ( l32res );
+}
+
+
+/*-------------------------------------------------------------------*
+ * floor_sqrt_exact()
+ * returns x = floor(sqrt(input)); where (x*x) <= input
+ *-------------------------------------------------------------------*/
+
+/*! r: floor(sqrt(input)) */
+uint32_t floor_sqrt_exact(
+ const uint32_t input /* i : unsigned input [0.. UINT_MAX/4] */
+)
+{
+ double _tmp;
+ uint32_t x;
+ if ( input == ZERO )
+ {
+ return ZERO;
+ }
+
+ _tmp = (double) input;
+ x = (uint32_t) ( sqrt( _tmp ) ); /* floor is a part of the cast */
+
+ return x;
+}
+
+/*-------------------------------------------------------------------*
+ * f_odd_exact_div_opt()
+ *
+ * find 1/(den1*2+1) * ( num1p*num2p - num3) ,
+ * if the result is known a priori to be exactly a 32bit unsigned integer
+ *-------------------------------------------------------------------*/
+
+/*! r: see Eq. */
+static uint32_t f_odd_exact_div_opt(
+ const int16_t num1p, /* i : see Eq. */
+ const uint32_t num2p, /* i : see Eq. */
+ const uint32_t num3, /* i : see Eq. */
+ const int16_t den1 /* i : see Eq. */
+)
+{
+ uint32_t tmp;
+ tmp = exactdivodd[den1] * ( num1p * num2p - num3 );
+
+ return ( tmp );
+}
+
+/*---------------------------------------------------------------------------*
+ * f_even_exact_div_opt()
+ *
+ * returns (num1p*num2p - num3 )/ den1
+ * if the result is known a priori to be exactly a 32bit unsigned integer
+ *--------------------------------------------------------------------------*/
+
+/*! r: see Eq. */
+static uint32_t f_even_exact_div_opt(
+ const int16_t num1p, /* i : see Eq. */
+ const uint32_t num2p, /* i : see Eq. range should be larger than num1p */
+ const uint32_t num3, /* i : see Eq. */
+ const int16_t den1 /* i : see Eq. */
+)
+{
+ uint32_t tmp1, oddfactor, UL_tmp;
+ int16_t den1_m1;
+ int16_t even_sh;
+ uint32_t UL_tmp_h;
+ uint64_t ULL_tmp;
+
+ den1_m1 = den1 - ONE; /* remove top bit */
+ even_sh = ( 31 ) - local_norm_l_opt( ( den1_m1 ) ^ den1 ); /* NB STL operation defined for signed positive 32 bit variable */
+ oddfactor = exactdivodd[den1_m1 >> even_sh];
+ even_sh -= ONE;
+
+ ULL_tmp = (uint64_t) num1p * (uint64_t) num2p; /* use STL Mpy_32_32_uu functionality */
+ UL_tmp_h = (uint32_t) ( ULL_tmp >> 32 ); /* high output from basicop */
+ UL_tmp = (uint32_t) ( ULL_tmp ); /* low output from basicop */
+
+ if ( num3 > UL_tmp )
+ {
+ UL_tmp_h = UL_tmp_h - ONE_U;
+ }
+ UL_tmp = ( UL_tmp - num3 ); /* can and should underflow */
+ UL_tmp = ( UL_tmp_h << ( 32 - even_sh ) ) | ( UL_tmp >> even_sh ); /* bitwise OR */
+
+ /* use tabled modular multiplicative inverse for the odd part division */
+ tmp1 = UL_tmp * oddfactor;
+
+ return tmp1;
+}
+
+/*-------------------------------------------------------------------*
+ * a_three()
+ *-------------------------------------------------------------------*/
+
+/*! r: offset for dim 3 */
+static uint32_t a_three(
+ const uint32_t k_val /* i : nb unit pulses; k_val may be higher than 16 bit signed */
+)
+{
+ if ( k_val )
+ {
+ return ( ONE_U + k_val * ( ( k_val - ONE_U ) << ONE ) );
+ }
+ else
+ {
+ return ZERO;
+ }
+}
+
+/*-------------------------------------------------------------------*
+ * a_four()
+ *-------------------------------------------------------------------*/
+
+/*! r: offset for dim 4 */
+static uint32_t a_four(
+ const uint32_t k_val /* i : nb unit pulses */
+)
+{
+ if ( k_val )
+ {
+ return UDIVBY3 * ( ( k_val << ONE ) * ( 4 + ( ( k_val << ONE ) - 3 ) * k_val ) - 3 );
+ }
+
+ return ZERO;
+}
+
+/*-------------------------------------------------------------------*
+ * a_five()
+ *-------------------------------------------------------------------*/
+
+/*! r: offset for dim 5 */
+static uint32_t a_five(
+ const uint32_t k_val /* i : nb unit pulses */
+)
+{
+ uint32_t offset;
+
+ if ( k_val == 0 )
+ {
+ offset = 0;
+ }
+ else if ( k_val == 1 )
+ {
+ offset = 1;
+ }
+ else
+ {
+ offset = ( ONE_U + ( ( ( ( ( ( k_val - TWO ) * k_val + 5 ) * k_val - 4 ) * k_val ) * ( UDIVBY3 ) ) << ONE ) );
+ }
+ return offset;
+}
+
+/*-------------------------------------------------------------------*
+ * direct_msize()
+ *-------------------------------------------------------------------*/
+/*! r: Enumeration size */
+static uint32_t direct_msize(
+ const int16_t dim_in, /* i : Number of dimensions */
+ const int16_t k_in ) /* i : Number of pulses */
+{
+ uint32_t msize, k, ksq;
+
+ msize = ONE_U; /* k==0 or dim==1, and base */
+ if ( k_in )
+ {
+ k = (uint32_t) k_in;
+ ksq = k * k;
+ switch ( dim_in )
+ {
+ case ( 5 ):
+ /* k*k = 238*238 < 2^16 */
+ msize += ( ( ( ksq * ( 5 + ksq ) ) * UDIVBY3 ) << ONE );
+ break;
+ case ( 4 ):
+ msize = ( ( k * ( ksq + 2 ) ) * UDIVBY3 ) << TWO;
+ break;
+ case ( 3 ):
+ msize += ( ( ksq ) << ONE );
+ break;
+ case ( 2 ):
+ msize = k << ONE;
+ break;
+ }
+ }
+
+ return msize;
+}
+
+
+/*-------------------------------------------------------------------*
+ * initOffsets()
+ *
+ * update h_mem[0.. k_val_in+1] , with starting offsets for A+U recursion
+ *-------------------------------------------------------------------*/
+
+static void initOffsets(
+ const int16_t dim_in, /* i : Number of dimensions */
+ uint32_t *h_mem, /* o : offsets */
+ const int16_t k_val_in /* i : Number of pulses */
+)
+{
+ int16_t k_val_curr, k_val_prev;
+ int16_t k_val;
+ h_mem[0] = ZERO; /* % A(=>0,k=0) */
+ h_mem[1] = ONE_U; /* % A(*,k=1) */
+
+ if ( dim_in == 2 )
+ {
+ for ( k_val = TWO; k_val <= k_val_in; k_val++ )
+ {
+ h_mem[k_val] = (uint32_t) ( ( k_val << ONE ) - ONE ); /* A(2, 2 .. k ) */
+ }
+ h_mem[k_val] = (uint32_t) ( k_val_in ); /* U(2,k+1) */
+ }
+ else if ( dim_in == 3 )
+ {
+ k_val_prev = ONE;
+ for ( k_val_curr = TWO; k_val_curr <= k_val_in; k_val_curr++ )
+ {
+ h_mem[k_val_curr] = ( ONE_U + k_val_curr * ( k_val_prev << ONE ) );
+ k_val_prev = k_val_curr;
+ }
+ h_mem[k_val_curr] = k_val_curr * k_val_prev;
+ }
+ else if ( dim_in == 4 )
+ {
+ for ( k_val_curr = TWO; k_val_curr <= k_val_in; k_val_curr++ )
+ {
+ h_mem[k_val_curr] = UDIVBY3 * ( ( k_val_curr << ONE ) * ( 4 + ( ( k_val_curr << ONE ) - 3 ) * k_val_curr ) - 3 );
+ }
+ h_mem[k_val_curr] = ( UDIVBY3 * ( ( k_val_curr << ONE ) * ( 4 + ( ( k_val_curr << ONE ) - 3 ) * k_val_curr ) - 3 ) ) >> 1;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * a_fwd()
+ *
+ * create offsets for A(n,k) from lower A(n-1,k)
+ *-------------------------------------------------------------------*/
+
+static void a_fwd(
+ uint32_t *a_in, /* i/o: offsets */
+ const int16_t n_items /* i : items, k's */
+)
+{
+ uint32_t a_1;
+ int16_t i, i_prev;
+ uint32_t a_in0; /* i : start column value */
+
+ a_in0 = ONE_U;
+ i_prev = ZERO;
+ for ( i = ONE; i <= n_items; i++ ) /*basic A fwd row recursion */
+ {
+ a_1 = a_in0 + a_in[i_prev] + a_in[i]; /* a_in addressed in at least two locations */
+ a_in[i_prev] = a_in0;
+ a_in0 = a_1;
+ i_prev = i; /* no real need to count as it is a ptr update */
+ }
+ a_in[i_prev] = a_in0;
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * a_bwd()
+ *
+ * create offsets for A(n,k) from higher A(n+1,k)
+ *-------------------------------------------------------------------*/
+
+static void a_bwd(
+ uint32_t *a_in, /* i/o: offsets */
+ const int16_t n_items /* i : n_items */
+)
+{
+ uint32_t a_1;
+ uint32_t a_in0;
+ int16_t i;
+ int16_t i_prev;
+
+ a_in0 = ZERO;
+ i_prev = ZERO;
+ for ( i = ONE; i <= n_items; i++ ) /*basic A reverse row recursion */
+ {
+ a_1 = a_in[i] - a_in0 - a_in[i_prev];
+ a_in[i_prev] = a_in0;
+ a_in0 = a_1;
+ i_prev = i;
+ }
+ a_in[i_prev] = a_in0;
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * direct_row_A2U_rec_calc()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static uint32_t direct_row_A2U_rec_calc(
+ const int16_t dim_in, /* i : Number of dimensions */
+ const int16_t k_val_in, /* i : Number of pulses */
+ const uint32_t a_km2, /* i : Recursion for k-2 (see Eq below) */
+ const uint32_t a_km1 /* i : Recursion for k-1 (see Eq below) */
+)
+{
+
+ /* U(n,k) = (A(n,k-2)-1)/2 + ((2*n-1)*A(n,k-1) - A(n,k-2) )/2*(k-1) */
+ /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - floor(A(n,k-1)/2) - floor(A(n,k-2)/2) +1 )/(k-1) */
+ /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - (floor(A(n,k-1)/2) + floor(A(n,k-2)/2) +1) ) /(k-1) */
+
+ uint32_t km2_size, result;
+ int16_t divisor;
+
+ divisor = k_val_in - ONE;
+ km2_size = ( a_km1 >> ONE ) + ( a_km2 >> ONE ) + ONE_U;
+
+ if ( divisor & ONE )
+ {
+ /* odd */
+ result = ( ( a_km2 >> ONE ) + f_odd_exact_div_opt( dim_in, a_km1, km2_size, divisor >> ONE ) );
+ }
+ else
+ {
+ /* even divisor */
+ result = ( ( a_km2 >> ONE ) + f_even_exact_div_opt( dim_in, a_km1, km2_size, divisor ) );
+ }
+
+ return result;
+}
+
+/*-------------------------------------------------------------------*
+ * a_u_fwd()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void a_u_fwd(
+ uint32_t *a_u_in, /* o : auxiliary array a_u */
+ const int16_t k_val_in, /* i : number of pulses */
+ const int16_t mem_size_m1 /* i : length of a_u_in */
+)
+{
+ uint32_t u_kp1_prev;
+ uint32_t a_k_prev;
+
+ /* mem_size_m1 = 1 + k_val_in */
+ u_kp1_prev = a_u_in[mem_size_m1]; /* previous n U (n,k+1) value*/
+ a_k_prev = a_u_in[k_val_in]; /* previous n A(n,k) value*/
+
+ a_fwd( &a_u_in[ONE], k_val_in ); /* a_u_in[k==ZERO] = zero if n>0 */
+
+ /* low dynamic last offset entry mixed recursion */
+ /* used for size calculation */
+ /* U(n,k+1) = 1 + U(n-1,k+1) + U(n-1,k) + U(n,k) */
+ /* U(n,k+1) = 1 + U(n-1,k+1) + (A(n-1,k)-1)/2 + (A(n,k)-1)/2 */
+ /* Note, A(n,k) always odd for k>0, subtracted one always shifted out */
+ /* assert(a_k_prev>0, a_k-curr>0) */
+
+ a_u_in[mem_size_m1] = ONE_U + u_kp1_prev + ( a_k_prev >> ONE ) + ( a_u_in[k_val_in] >> ONE );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * nm_h_prep_opt()
+ *
+ * find and return N_MPVQ(n,k) and also offsets A(n, 0 to k ) and U(n,k+1).
+ *-------------------------------------------------------------------*/
+
+/*! r: msize for dim */
+static uint32_t nm_h_prep_opt(
+ const int16_t dim_in, /* i : dimension */
+ int16_t k_val_in, /* i : nb unit pulses */
+ uint32_t *h /* o : A/U offsets array */
+)
+{
+ int16_t mem_size_m1, k_val;
+ int16_t dim_tmp, d_start;
+ uint32_t h_saveA, h_saveB; /* registers for alternating A(n,k-1), A(n,k-2)*/
+ int16_t numDsub1; /* k_val_curr, k_val_prev*/
+
+ mem_size_m1 = k_val_in + ONE;
+
+ if ( k_val_in > TABLE_LIM_OPT )
+ {
+ if ( dim_in >= 3 )
+ {
+ d_start = 3;
+ }
+ else
+ {
+ d_start = 2;
+ }
+ initOffsets( d_start, h, k_val_in );
+
+ for ( dim_tmp = d_start; dim_tmp < dim_in; dim_tmp++ )
+ {
+ a_u_fwd( h, k_val_in, mem_size_m1 );
+ }
+ }
+ else
+ {
+ h[ZERO] = ZERO;
+ h[ONE] = ONE_U;
+ numDsub1 = ( ( dim_in << ONE ) - ONE );
+ h[TWO] = numDsub1;
+
+ /* interleaved odd even calls */
+ h_saveA = numDsub1;
+ h_saveB = ONE_U;
+ for ( k_val = 3; k_val < ( mem_size_m1 ); k_val++ )
+ {
+ /* A(n,k) = A(n,k-2) + ((2*n-1)*A(n,k-1)-A(n,k-2)) /(k-1) */
+ /* first odd k, even divisor */
+ h_saveB += f_even_exact_div_opt( numDsub1, h_saveA, h_saveB, k_val - ONE );
+ h[k_val] = h_saveB;
+
+ k_val++; /* next even k, odd divisor */
+ if ( k_val >= ( mem_size_m1 ) )
+ {
+ break;
+ }
+ h_saveA += f_odd_exact_div_opt( numDsub1, h_saveB, h_saveA, ( k_val - ONE ) >> ONE );
+ h[k_val] = h_saveA;
+ }
+ /* always do the last (k+1) recursion based on U(n,k+1) = func( A(n-2,k+1), A(n-1,k+1) ) */
+ h[mem_size_m1] = direct_row_A2U_rec_calc( dim_in, mem_size_m1, h[mem_size_m1 - 2], h[k_val_in] );
+ }
+
+ /* N_MPVQ(n,k) = 1 + U(n,k+1) + U(n,k) = 1 + U(n,k+1) + (A(n,k)-1)/2; */ /* A(n,k) always odd */
+ return ( ONE + h[mem_size_m1] + ( h[k_val_in] >> ONE ) );
+}
+
+
+/*-------------------------------------------------------------------*
+ * find_amp_split_offset_func_mem()
+ *
+ * find first offset in range 0..k_val_in that is less than ind_in
+ * using a tree search with direct function calls or memory iteration
+ *-------------------------------------------------------------------*/
+
+static int16_t find_amp_split_offset_func_mem(
+ const uint32_t ind_in, /* i : input index */
+ const int16_t k_val_in, /* i : number of pulses */
+ H_FUNCM h_func_ptr, /* i : offset function pointer */
+ const uint32_t *const h_mem, /* i : offsets */
+ uint32_t *tmp_offset /* o : offset found */
+)
+{
+ int16_t not_ready, low, high;
+ int16_t k_test;
+
+ k_test = -1; /* init to eliminate compiler warning */
+ low = 0;
+ high = k_val_in;
+ /* split over A(n,k)= h_mem(k), or use direct function */
+ not_ready = ONE;
+ while ( not_ready )
+ {
+ k_test = ( low + high ) >> ONE; /*% split range in half */
+
+ if ( h_mem )
+ {
+ *tmp_offset = h_mem[k_test]; /* memory search */
+ }
+ else
+ {
+ *tmp_offset = ( *h_func_ptr )( (uint32_t) k_test ); /* function search. NB only line difference to the memory search*/
+ }
+
+ if ( ind_in > *tmp_offset )
+ {
+ if ( k_test < high )
+ {
+ low = 1 + k_test;
+ }
+ else
+ {
+ not_ready = 0;
+ }
+ }
+ else
+ {
+ if ( *tmp_offset == ind_in )
+ {
+ not_ready = 0;
+ }
+ else
+ {
+ high = k_test - 1;
+ }
+ }
+ }
+
+ return k_test;
+}
+
+/*-------------------------------------------------------------------*
+ * get_lead_sign()
+ *
+ * update index and return leading sign
+ *-------------------------------------------------------------------*/
+
+/*! r: leading sign [-1,1] */
+static int16_t get_lead_sign(
+ uint32_t *ind /* i/o: Current index */
+)
+{
+ int16_t leading_sign;
+
+ if ( ( *ind ) & ONE_U ) /* leading sign stored in LSB */
+ {
+ leading_sign = -1;
+ }
+ else
+ {
+ leading_sign = 1;
+ }
+ ( *ind ) = ( *ind ) >> ONE;
+
+ return leading_sign;
+}
+
+
+/*-------------------------------------------------------------------*
+ * mind2vec_one()
+ *-------------------------------------------------------------------*/
+
+static void mind2vec_one(
+ const int16_t k_val_in, /* i : nb unit pulses */
+ const int16_t leading_sign, /* i : leading sign */
+ const uint32_t ind, /* i : index */
+ int16_t *vec_out /* o : pulse train */
+)
+{
+
+ vec_out[ind] = ( leading_sign * k_val_in ); /* NB input k_val_in can be zero */
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * mind2vec_two()
+ *-------------------------------------------------------------------*/
+
+static void mind2vec_two(
+ const int16_t k_val_in, /* i : nb unit pulses */
+ const int16_t leading_sign, /* i : leading sign */
+ const uint32_t ind_in, /* i : index */
+ int16_t *vec_out /* o : pulse train */
+)
+{
+ uint32_t ind_tmp;
+ int16_t val1;
+
+ if ( k_val_in > 0 ) /* k_val_in check */
+ {
+ if ( ind_in == 0 )
+ {
+ vec_out[0] = ( leading_sign * k_val_in );
+ vec_out[1] = 0;
+ }
+ else if ( ind_in == ( (uint32_t) ( k_val_in << ONE ) - ONE_U ) )
+ {
+ vec_out[0] = 0;
+ vec_out[1] = ( leading_sign * k_val_in );
+ }
+ else
+ {
+ ind_tmp = ind_in - ONE_U;
+ val1 = (int16_t) ( ONE_U + ( ind_tmp >> ONE ) );
+ vec_out[0] = leading_sign * ( k_val_in - val1 );
+
+ if ( ind_tmp & ONE_U )
+ {
+ vec_out[1] = -val1;
+ }
+ else
+ {
+ vec_out[1] = val1;
+ }
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * setval_update_sign()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+/*! r: max k */
+static int16_t setval_update_sign(
+ const int16_t k_delta, /* i : Delta-K */
+ int16_t k_max_local, /* i/o: Maximum K */
+ int16_t *leading_sign, /* o : Leading sign */
+ uint32_t *ind_in, /* i/o: Index/index with leading sign excluded */
+ int16_t *vec_out /* o : Output vector */
+)
+{
+ if ( k_delta != 0 )
+ {
+ *vec_out = ( *leading_sign ) * k_delta;
+ *leading_sign = get_lead_sign( ind_in );
+ k_max_local = k_max_local - k_delta;
+ }
+
+ return k_max_local;
+}
+
+/*-------------------------------------------------------------------*
+ * mind2vec_three()
+ *-------------------------------------------------------------------*/
+
+static void mind2vec_three(
+ int16_t k_max_local, /* i : nb unit pulses */
+ int16_t leading_sign, /* i : leading sign */
+ uint32_t ind_in, /* i : index */
+ int16_t *vec_out /* o : pulse train */
+)
+{
+ int16_t k_delta;
+ uint32_t acc_val;
+
+ /*
+ use direct calculation of first amplitude
+ (to find amplitudes faster than using split or linear iteration)
+ */
+ if ( ind_in == 0 )
+ {
+ vec_out[0] = leading_sign * k_max_local;
+ }
+ else
+ {
+ acc_val = ( ( ONE_U + floor_sqrt_exact( ( ind_in << ONE ) - ONE_U ) ) >> ONE ); /* in BASOP use approximation + search for exact sqrt )*/
+
+ k_delta = k_max_local - (int16_t) acc_val;
+ ind_in -= a_three( acc_val ); /* remove amplitude offset A(n,k_acc) */
+
+ k_max_local = setval_update_sign( k_delta, k_max_local, &leading_sign, &ind_in, vec_out );
+
+ mind2vec_two( k_max_local, leading_sign, ind_in, &vec_out[1] );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * mind2vec_direct()
+ *
+ * general function for direct decoding using direct functions
+ * (no memory recursion)
+ *-------------------------------------------------------------------*/
+
+static void mind2vec_direct(
+ int16_t k_max_local, /* i : nb unit pulses */
+ int16_t leading_sign, /* i : leading sign */
+ uint32_t ind, /* i : index */
+ H_FUNCM h_func_ptr, /* i : offset function */
+ NDIM_FUNCM nd_func_ptr, /* i : next dimension function */
+ int16_t *vec_out /* o : pulse train */
+)
+{
+ int16_t k_delta, k_test = 0;
+ uint32_t tmp_offset;
+
+ if ( ind == 0 )
+ {
+ vec_out[0] = leading_sign * k_max_local;
+ }
+ else
+ {
+ k_test = find_amp_split_offset_func_mem( ind, k_max_local, h_func_ptr, NULL, &tmp_offset );
+
+ k_delta = k_max_local - k_test;
+ ind = ind - tmp_offset; /* % remove amplitude offset A(n,k_acc) */
+ k_max_local = setval_update_sign( k_delta, k_max_local, &leading_sign, &ind, vec_out );
+ ( *nd_func_ptr )( k_max_local, leading_sign, ind, &vec_out[1] );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * mind2vec_four()
+ *-------------------------------------------------------------------*/
+
+static void mind2vec_four(
+ int16_t k_val_in, /* i : nb unit pulses */
+ int16_t leading_sign, /* i : leading sign */
+ uint32_t ind_in, /* i : index */
+ int16_t *vec_out /* o : pulse train */
+)
+{
+ mind2vec_direct( k_val_in, leading_sign, ind_in, a_four, mind2vec_three, vec_out );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * mind2vec_five()
+ *-------------------------------------------------------------------*/
+
+static void mind2vec_five(
+ int16_t k_val_in, /* i : nb unit pulses */
+ int16_t leading_sign, /* i : leading sign */
+ uint32_t ind_in, /* i : index */
+ int16_t *vec_out /* o : pulse train */
+)
+{
+ mind2vec_direct( k_val_in, leading_sign, ind_in, a_five, mind2vec_four, vec_out );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * mind2vec()
+ *-------------------------------------------------------------------*/
+
+static void mind2vec(
+ int16_t dim_in, /* i : dimension */
+ int16_t k_max_local, /* i : nb unit pulses */
+ int16_t leading_sign, /* i : leading sign */
+ uint32_t ind, /* i : index */
+ int16_t *vec_out, /* o : pulse train */
+ uint32_t *h_in /* i : offset vector A=1+2U */
+)
+{
+ int16_t pos;
+ int16_t k_acc, k_delta;
+ uint32_t tmp_offset;
+
+ k_acc = k_max_local;
+
+ pos = ZERO;
+ while ( pos < dim_in ) /* first to last position decoding */
+ {
+ if ( ind == 0 )
+ {
+ vec_out[pos] = leading_sign * k_max_local;
+ break; /* "fast" recursion exit */
+ }
+ else
+ {
+ {
+ /* linear magnitude search */
+ k_acc = k_max_local;
+ tmp_offset = h_in[k_acc];
+ while ( tmp_offset > ind )
+ {
+ k_acc = k_acc - 1;
+ tmp_offset = h_in[k_acc];
+ }
+ }
+ k_delta = k_max_local - k_acc; /* amplitude decoding */
+ }
+ ind = ind - tmp_offset; /* remove amplitude index offset A(n,k_acc) */
+
+ k_max_local = setval_update_sign( k_delta, k_max_local, &leading_sign, &ind, &vec_out[pos] );
+
+ /* move from A(n,kmax) to A(n-1, k_max_local), */
+ a_bwd( h_in, k_max_local + 1 ); /* [0..k_max_local], no need to calculate U(n,k_max_local+1) in index decoding */
+ pos = pos + 1;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * vec2mind_one()
+ *-------------------------------------------------------------------*/
+
+static void vec2mind_one(
+ const int16_t *vec_in, /* i : PVQ abs pulse train */
+ int16_t *k_val_out_ptr, /* o : number of unit pulses */
+ uint32_t *next_sign_ind, /* i/o: next sign ind */
+ uint32_t *ind /* o : MPVQ index */
+)
+{
+ *k_val_out_ptr = -1; /* just to avoid compiler warnings */
+
+ *ind = ZERO;
+ /* *k_val_out_ptr = (int16_t)abs(*vec_in); */ /* dim==1, function not called recursively */
+ *next_sign_ind = (uint32_t) ( *vec_in < ZERO ); /* single sign always pushed out of MPVQ */
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * vec2mind_two()
+ *-------------------------------------------------------------------*/
+
+static void vec2mind_two(
+ const int16_t *vec_in, /* i : PVQ pulse train */
+ int16_t *k_val_out_ptr, /* o : number of unit pulses */
+ uint32_t *next_sign_ind, /* i/o: next sign ind */
+ uint32_t *ind /* o : MPVQ index */
+)
+{
+ uint32_t lead_sign_ind;
+ int16_t abs0, abs1, abs01;
+
+ abs0 = (int16_t) abs( vec_in[0] );
+ abs1 = (int16_t) abs( vec_in[1] );
+
+ abs01 = abs0 + abs1;
+ *k_val_out_ptr = abs01;
+
+ if ( abs01 == 0 ) /* zeroes can happen in a recursive encoding call */
+ {
+ *next_sign_ind = SIGNBIT;
+ *ind = ZERO;
+ }
+ else
+ {
+ *next_sign_ind = 0;
+ if ( abs1 == 0 )
+ {
+ *ind = ZERO;
+ }
+ else if ( abs0 == 0 )
+ {
+ *ind = (uint32_t) ( abs1 << ONE ) - ONE_U;
+ *next_sign_ind = 1;
+ }
+ else
+ {
+ lead_sign_ind = (uint32_t) ( vec_in[1] < 0 ); /*% sign always shifted to first pos */
+ *ind = ONE_U + ( (uint32_t) ( abs1 - 1 ) << ONE ) + lead_sign_ind;
+ }
+ *next_sign_ind = (uint32_t) ( vec_in[*next_sign_ind] < 0 );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * vec2mind_gen345( vec_in kval, next_dim_func, offset_func,....)
+ * generic call saves PROM ,
+ *-------------------------------------------------------------------*/
+
+static void vec2mind_gen345(
+ const int16_t *vec_in, /* i : PVQ abs pulse train */
+ int16_t *k_val_out_ptr, /* o : number of unit pulses */
+ uint32_t *next_sign_ind, /* i/o: next sign ind */
+ uint32_t *index, /* o : MPVQ index */
+ VEC2INDFUNCM vec2indfunc_ptr, /* i : */
+ H_FUNCM a_func_ptr /* i : offset function */
+)
+{
+ int16_t tmp_val;
+
+ tmp_val = vec_in[ZERO];
+ ( *vec2indfunc_ptr )( &vec_in[ONE], k_val_out_ptr, next_sign_ind, index );
+
+ if ( ( ( *next_sign_ind & SIGNBIT ) == 0 && tmp_val != 0 ) != ZERO )
+ {
+ *index = ( *index << ONE ) + *next_sign_ind;
+ }
+
+ if ( tmp_val != 0 ) /* push sign */
+ {
+ *next_sign_ind = (uint32_t) ( tmp_val < 0 );
+ }
+
+ *index += ( *a_func_ptr )( (uint32_t) *k_val_out_ptr );
+ if ( tmp_val > 0 )
+ {
+ *k_val_out_ptr += tmp_val;
+ }
+ else
+ {
+ *k_val_out_ptr -= tmp_val;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * vec2mind_three()
+ *-------------------------------------------------------------------*/
+
+static void vec2mind_three(
+ const int16_t *vec_in, /* i : PVQ pulse train */
+ int16_t *k_val_out_ptr, /* o : number of unit pulses */
+ uint32_t *next_sign_ind, /* i/o: next sign ind */
+ uint32_t *index /* o : MPVQ index */
+)
+{
+ vec2mind_gen345( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_two, a_three );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * vec2mind_four()
+ *-------------------------------------------------------------------*/
+
+static void vec2mind_four(
+ const int16_t *vec_in, /* i : PVQ pulse train */
+ int16_t *k_val_out_ptr, /* o : number of unit pulses */
+ uint32_t *next_sign_ind, /* i/o: next sign ind */
+ uint32_t *index /* o : MPVQ index */
+)
+{
+ vec2mind_gen345( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_three, a_four );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * vec2mind_five()
+ *-------------------------------------------------------------------*/
+
+static void vec2mind_five(
+ const int16_t *vec_in, /* i : PVQ abs pulse train */
+ int16_t *k_val_out_ptr, /* o : number of unit pulses */
+ uint32_t *next_sign_ind, /* i/o: next sign ind */
+ uint32_t *index /* o : MPVQ index */
+)
+{
+ vec2mind_gen345( vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_four, a_five );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * vec2mind()
+ *-------------------------------------------------------------------*/
+
+static void vec2mind(
+ int16_t dim_in, /* i : dim */
+ int16_t k_val_in, /* i : number of unit pulses */
+ const int16_t *vec_in, /* i : PVQ pulse train */
+ uint32_t *next_sign_ind, /* o : pushed leading sign */
+ uint32_t *index, /* o : MPVQ index */
+ uint32_t *N_MPVQ_ptr, /* o : size(N_MPVQ(dim,K_val_in))*/
+ uint32_t *h_mem /* o : offsets */
+)
+{
+ int16_t pos, mem_size_m1;
+ int16_t k_val_acc;
+ int16_t tmp_val;
+
+ mem_size_m1 = k_val_in + ONE;
+
+ *next_sign_ind = SIGNBIT; /* % should always be 0 or 1 out, highest bit set signals no sign found yet*/
+
+ pos = dim_in - 2; /* % address 2nd last sample */
+ vec2mind_two( &vec_in[pos], &k_val_acc, next_sign_ind, index );
+ initOffsets( 3, h_mem, k_val_in );
+
+ for ( pos--; pos >= 0; pos-- )
+ {
+ /*
+ % Check if the leading sign 'bit' is to be added
+ */
+ tmp_val = vec_in[pos];
+ if ( ( ( *next_sign_ind & SIGNBIT ) == 0 && ( tmp_val != 0 ) ) )
+ {
+ *index = ( *index << ONE ) + ( *next_sign_ind );
+ }
+
+ /* % push sign fwd, for encoding in the next non_zero position */
+ if ( tmp_val != 0 )
+ {
+ *next_sign_ind = (uint32_t) ( tmp_val < 0 );
+ }
+
+ /*% add indexing offset up to this reverse (r_l) accumulated amplitude point */
+ *index += h_mem[k_val_acc]; /* % k_val_acc==0 ==>0 */
+
+ k_val_acc += (int16_t) abs( tmp_val ); /*% now increase acc k value for next N */
+
+ if ( pos )
+ {
+ a_u_fwd( h_mem, k_val_in, mem_size_m1 );
+ /*% update A(n,k=1:k_val_in) and U(n,k_val_in+1), NB here (k_val_in + 2 elements always has to be updated */
+ }
+ }
+
+ /* size is needed for the subseqent arithmetic encoding/transmission of the index. */
+ /* use relation N_MPVQ(n,K) = 1 + (A(n, K)-1)/2 + U(n, 1 + K) */
+ /* = N_MPVQ(n,K) = 1 + (A(n, K)>>1) + U(n, 1 + K), as A(n,K) is odd) */
+
+ *N_MPVQ_ptr = ONE_U + ( h_mem[k_val_acc] >> ONE ) + h_mem[mem_size_m1]; /* total size size */
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * mpvq_encode_vec()
+ *
+ * returns struct with leading sign index, MPVQ-index, dim and N_MPVQ
+ *-------------------------------------------------------------------------*/
+
+/*! r: leading_sign_index, index, size, k_val */
+PvqEntry mpvq_encode_vec(
+ const int16_t *vec_in, /* i : signed pulse train */
+ const int16_t dim_in, /* i : dimension */
+ int16_t k_val_local /* i/o: nb unit pulses */
+)
+{
+ PvqEntry result;
+ uint32_t h_mem[1 + KMAX_NON_DIRECT + 1]; /* allocate max offset memory for dim 6 */ /* OPT: actually only 1+k_val_in+1 needed ) */
+ uint32_t lead_sign_ind;
+ const VEC2INDFUNCM vec2mind_f[1 + N_OPT] = { NULL, vec2mind_one, vec2mind_two, vec2mind_three, vec2mind_four, vec2mind_five }; /* VEC2INDFUNCM can be a static global */
+
+ result.k_val = k_val_local;
+ result.dim = dim_in;
+
+ /* NB, k_val_local may be changed in some sub encoding routines */
+ if ( dim_in > N_OPT ) /* use the generic dimension function */
+ {
+ vec2mind( dim_in, k_val_local, vec_in, &lead_sign_ind, &result.index, &result.size, h_mem );
+ }
+ else /* if (dim_in<=N_OPT) */
+ {
+ ( vec2mind_f[dim_in] )( vec_in, &k_val_local, &lead_sign_ind, &result.index );
+ result.size = direct_msize( dim_in, k_val_local ); /* k_val_local not used for dim==1 */
+ }
+ result.lead_sign_ind = (int16_t) lead_sign_ind;
+
+ return result;
+}
+
+/*-------------------------------------------------------------------*
+ * get_size_mpvq_calc_offset()
+ *
+ * uint32_t h_mem[1 + KMAX +1 ];
+ * example using fixed size of offset vector input help variable
+ *-------------------------------------------------------------------*/
+
+/*! r: size, dim, k_val */
+PvqEntry get_size_mpvq_calc_offset(
+ const int16_t dim_in, /* i : dimension */
+ const int16_t k_val_in, /* i : nb unit pulses */
+ uint32_t *h_mem /* o : offsets */
+)
+{
+ PvqEntry entry;
+
+ entry.dim = dim_in;
+ entry.k_val = k_val_in;
+ entry.index = 0U; /* avoid gcc warning in struct passing */
+ entry.lead_sign_ind = 0; /* avoid gcc warning in struct passing */
+ if ( dim_in > N_OPT ) /* non-direct solutions, use A+U relation */
+ {
+ entry.size = nm_h_prep_opt( entry.dim, entry.k_val, h_mem );
+ }
+ else
+ {
+ entry.size = direct_msize( dim_in, entry.k_val ); /* ues equations, h_mem is not used */
+ }
+
+
+ return entry;
+}
+
+/*-------------------------------------------------------------------*
+ * mpvq_decode_vec()
+ *-------------------------------------------------------------------*/
+
+/*! r: void */
+void mpvq_decode_vec(
+ const PvqEntry *entry, /* i : sign_ind, index, dim, k_val */
+ uint32_t *h_mem, /* i : A/U offsets */
+ int16_t *vec_out /* o : pulse train */
+)
+{
+ int16_t i, leading_sign;
+ const IND2VECFUNCM mind2vec_f[N_OPT + 1] = { NULL, mind2vec_one, mind2vec_two, mind2vec_three, mind2vec_four, mind2vec_five }; /*IND2VECFUNCM vector can be static global */
+
+ for ( i = 0; i < entry->dim; i++ )
+ {
+ vec_out[i] = ZERO; /* set all of short output vector to zero */
+ }
+
+ leading_sign = 1;
+ if ( entry->lead_sign_ind )
+ {
+ leading_sign = -1;
+ }
+
+ if ( entry->k_val != 0 )
+ {
+ if ( entry->dim > N_OPT ) /* N_OPT */
+ {
+ /* generic */
+ mind2vec( entry->dim, entry->k_val, leading_sign, entry->index, vec_out, h_mem );
+ }
+ else
+ {
+ /* specialized functions */
+ ( mind2vec_f[entry->dim] )( entry->k_val, leading_sign, entry->index, vec_out );
+ }
+ }
+
+ return;
+}
+
+#ifdef ONE_U
+#undef ZERO
+#undef ONE
+#undef ONE_U
+#undef TWO
+#undef MAXBIT
+#undef MINNEG
+#undef SIGNBIT
+#undef UDIVBY3
+#endif
+
+#endif
diff --git a/lib_com/int_lsp.c b/lib_com/int_lsp.c
new file mode 100644
index 0000000000000000000000000000000000000000..448a97e33284950b24351e05e924532d8a143e83
--- /dev/null
+++ b/lib_com/int_lsp.c
@@ -0,0 +1,177 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * int_lsp()
+ *
+ * Find the interpolated LSP parameters for all subframes
+ *---------------------------------------------------------------------*/
+
+void int_lsp(
+ const int16_t L_frame, /* i : length of the frame */
+ const float lsp_old[], /* i : LSPs from past frame */
+ const float lsp_new[], /* i : LSPs from present frame */
+ float *Aq, /* o : LP coefficients in both subframes */
+ const int16_t m, /* i : order of LP filter */
+ const float *int_coeffs, /* i : interpolation coefficients */
+ const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */
+)
+{
+ float lsp[M], fnew, fold;
+ int16_t i, k;
+ const float *pt_int_coeffs;
+
+ if ( L_frame == L_FRAME )
+ {
+ pt_int_coeffs = int_coeffs;
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ pt_int_coeffs = interpol_frac_16k;
+ }
+
+ for ( k = 0; k < L_frame / L_SUBFR; k++ )
+ {
+ fnew = pt_int_coeffs[k];
+ fold = (float) ( 1.0f - fnew );
+
+ for ( i = 0; i < m; i++ )
+ {
+ lsp[i] = lsp_old[i] * fold + lsp_new[i] * fnew;
+ }
+
+ if ( Opt_AMR_WB )
+ {
+ isp2a( lsp, Aq, m );
+ }
+ else
+ {
+ lsp2a_stab( lsp, Aq, m );
+ }
+
+ Aq += ( m + 1 );
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * int_lsp4()
+ *
+ * Interpolate LSPs find the A[z] parameters for all subframes by interpolating between
+ * old end-frame LSPs, current mid-frame LSPs and current end-frame LSPs
+ *---------------------------------------------------------------------*/
+
+void int_lsp4(
+ const int16_t L_frame, /* i : length of the frame */
+ const float lsp_old[], /* i : LSPs from past frame */
+ const float lsp_mid[], /* i : LSPs from mid-frame */
+ const float lsp_new[], /* i : LSPs from present frame */
+ float *Aq, /* o : LP coefficients in both subframes */
+ const int16_t m, /* i : order of LP filter */
+ int16_t relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */
+)
+{
+ float lsp[M];
+ int16_t i;
+ int16_t j;
+ const float *pt_int_coeffs;
+
+ if ( L_frame == L_FRAME )
+ {
+ if ( relax_prev_lsf_interp == 1 )
+ {
+ pt_int_coeffs = interpol_frac_mid_relaxprev_12k8;
+ }
+ else if ( relax_prev_lsf_interp == 2 )
+ {
+ pt_int_coeffs = interpol_frac_mid_FEC;
+ }
+ else if ( relax_prev_lsf_interp == -1 )
+ {
+ pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8;
+ }
+ else if ( relax_prev_lsf_interp == -2 )
+ {
+ pt_int_coeffs = interpol_frac2_mid;
+ }
+ else
+ {
+ pt_int_coeffs = interpol_frac_mid;
+ }
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ if ( relax_prev_lsf_interp == 1 )
+ {
+ pt_int_coeffs = interpol_frac_mid_relaxprev_16k;
+ }
+ else if ( relax_prev_lsf_interp == 2 )
+ {
+ pt_int_coeffs = interpol_frac_mid_16k_FEC;
+ }
+ else if ( relax_prev_lsf_interp == -1 )
+ {
+ pt_int_coeffs = interpol_frac_mid_relaxprev_pred_16k;
+ }
+ else
+ {
+ pt_int_coeffs = interpol_frac_mid_16k;
+ }
+ }
+
+ for ( j = 0; j < L_frame / L_SUBFR; j++ )
+ {
+ for ( i = 0; i < m; i++ )
+ {
+ lsp[i] = lsp_old[i] * ( *pt_int_coeffs ) + lsp_mid[i] * ( *( pt_int_coeffs + 1 ) ) + lsp_new[i] * ( *( pt_int_coeffs + 2 ) );
+ }
+ pt_int_coeffs += 3;
+
+ lsp2a_stab( lsp, Aq, m );
+
+ Aq += ( m + 1 );
+ }
+
+ return;
+}
diff --git a/lib_com/interleave_spectrum.c b/lib_com/interleave_spectrum.c
new file mode 100644
index 0000000000000000000000000000000000000000..300295355adaa5cfad5980fb1da5301738ded0d1
--- /dev/null
+++ b/lib_com/interleave_spectrum.c
@@ -0,0 +1,205 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * interleave_spectrum()
+ *
+ * Interleave the spectrum
+ *--------------------------------------------------------------------------*/
+
+void interleave_spectrum(
+ float *coefs, /* i/o: input and output coefficients */
+ const int16_t length /* i : length of spectrum */
+)
+{
+ int16_t i, j, k;
+ float *p1, *p2, *p3, *p4;
+ float *p_out;
+ float coefs_out[STOP_BAND];
+ int16_t sublen;
+ int16_t grps;
+ const int16_t *bw;
+ const int16_t *cnt;
+ int16_t l_frame;
+
+ l_frame = length;
+
+ if ( length == L_SPEC48k )
+ {
+ bw = intl_bw_48;
+ cnt = intl_cnt_48;
+ grps = N_INTL_GRP_48;
+ l_frame = L_FRAME48k;
+ }
+ else if ( length == L_SPEC32k )
+ {
+ bw = intl_bw_32;
+ cnt = intl_cnt_32;
+ grps = N_INTL_GRP_32;
+ }
+ else /* length == L_SPEC16k */
+ {
+ bw = intl_bw_16;
+ cnt = intl_cnt_16;
+ grps = N_INTL_GRP_16;
+ }
+
+ sublen = l_frame / 4;
+ p1 = coefs;
+ p2 = coefs + sublen;
+ p3 = coefs + sublen * 2;
+ p4 = coefs + sublen * 3;
+ p_out = coefs_out;
+
+ for ( i = 0; i < grps; i++ )
+ {
+ for ( j = 0; j < cnt[i]; j++ )
+ {
+ for ( k = 0; k < bw[i]; k++ )
+ {
+ *p_out++ = *p1++;
+ }
+
+ for ( k = 0; k < bw[i]; k++ )
+ {
+ *p_out++ = *p2++;
+ }
+
+ for ( k = 0; k < bw[i]; k++ )
+ {
+ *p_out++ = *p3++;
+ }
+
+ for ( k = 0; k < bw[i]; k++ )
+ {
+ *p_out++ = *p4++;
+ }
+ }
+ }
+
+ /* For FB the interleaved spectrum is 800 samples */
+ mvr2r( coefs_out, coefs, (int16_t) ( p_out - coefs_out ) );
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * de_interleave_spectrum()
+ *
+ * Deinterleave the spectrum
+ *--------------------------------------------------------------------------*/
+
+void de_interleave_spectrum(
+ float *coefs, /* i/o: input and output coefficients */
+ int16_t length /* i : length of spectrum */
+)
+{
+ int16_t i, j, k;
+ float *p1, *p2, *p3, *p4;
+ float *p_in;
+ float coefs_out[L_FRAME48k];
+ int16_t sublen;
+ int16_t grps;
+ const int16_t *bw;
+ const int16_t *cnt;
+ int16_t l_frame;
+
+ l_frame = length;
+
+ if ( length == L_SPEC48k )
+ {
+ bw = intl_bw_48;
+ cnt = intl_cnt_48;
+ grps = N_INTL_GRP_48;
+ l_frame = L_FRAME48k;
+ }
+ else if ( length == L_FRAME32k )
+ {
+ bw = intl_bw_32;
+ cnt = intl_cnt_32;
+ grps = N_INTL_GRP_32;
+ }
+ else /* length == L_FRAME16k */
+ {
+ bw = intl_bw_16;
+ cnt = intl_cnt_16;
+ grps = N_INTL_GRP_16;
+ }
+
+ set_f( coefs_out, 0, L_FRAME48k );
+
+ sublen = l_frame / 4;
+ p1 = coefs_out;
+ p2 = coefs_out + sublen;
+ p3 = coefs_out + sublen * 2;
+ p4 = coefs_out + sublen * 3;
+ p_in = coefs;
+
+ for ( i = 0; i < grps; i++ )
+ {
+ for ( j = 0; j < cnt[i]; j++ )
+ {
+ for ( k = 0; k < bw[i]; k++ )
+ {
+ *p1++ = *p_in++;
+ }
+ for ( k = 0; k < bw[i]; k++ )
+ {
+ *p2++ = *p_in++;
+ }
+ for ( k = 0; k < bw[i]; k++ )
+ {
+ *p3++ = *p_in++;
+ }
+ for ( k = 0; k < bw[i]; k++ )
+ {
+ *p4++ = *p_in++;
+ }
+ }
+ }
+
+ mvr2r( coefs_out, coefs, l_frame );
+
+ return;
+}
diff --git a/lib_com/interpol.c b/lib_com/interpol.c
new file mode 100644
index 0000000000000000000000000000000000000000..332f34d5444ee0069cbd4bae59f791a12d10051a
--- /dev/null
+++ b/lib_com/interpol.c
@@ -0,0 +1,77 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * interpolation()
+ *
+ * Fractional interpolation of signal at position (frac/resol)
+ *-------------------------------------------------------------------*/
+
+/*! r: interpolated value */
+float interpolation(
+ const float *x, /* i : input vector */
+ const float *win, /* i : interpolation window */
+ const int16_t frac, /* i : fraction */
+ const int16_t up_samp, /* i : upsampling factor */
+ const int16_t nb_coef /* i : nb of filter coef */
+)
+{
+ int16_t i;
+ float s;
+ const float *x1, *x2, *c1, *c2;
+
+ x1 = &x[0];
+ x2 = &x[1];
+ c1 = &win[frac];
+ c2 = &win[up_samp - frac];
+ s = 0.0f;
+
+ for ( i = 0; i < nb_coef; i++ )
+ {
+ s += ( *x1-- ) * ( *c1 ) + ( *x2++ ) * ( *c2 );
+#define WMC_TOOL_SKIP
+ c1 += up_samp;
+ c2 += up_samp;
+#undef WMC_TOOL_SKIP
+ }
+
+ return s;
+}
diff --git a/lib_com/isf_dec_amr_wb.c b/lib_com/isf_dec_amr_wb.c
new file mode 100644
index 0000000000000000000000000000000000000000..49afd071fb5ac301dc5b7e02bf8dc6f54fc98aa7
--- /dev/null
+++ b/lib_com/isf_dec_amr_wb.c
@@ -0,0 +1,286 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * isf_dec_amr_wb()
+ *
+ * Decoding of ISF parameters in AMR-WB IO mode
+ *---------------------------------------------------------------------*/
+
+void isf_dec_amr_wb(
+ Decoder_State *st, /* i/o: State structure */
+ float *Aq, /* o : quantized A(z) for 4 subframes */
+ float *isf_new, /* o : de-quantized ISF vector */
+ float *isp_new /* o : de-quantized ISP vector */
+)
+{
+ int16_t i;
+ int16_t indice[7];
+
+ set_s( indice, -1, 7 );
+
+ /*---------------------------------*
+ * ISF de-quantization of SID frames
+ *---------------------------------*/
+
+ if ( st->core_brate == SID_1k75 )
+ {
+ indice[0] = get_next_indice( st, 6 );
+ indice[1] = get_next_indice( st, 6 );
+ indice[2] = get_next_indice( st, 6 );
+ indice[3] = get_next_indice( st, 5 );
+ indice[4] = get_next_indice( st, 5 );
+
+ disf_ns_28b( indice, isf_new );
+
+ reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 );
+
+ isf2isp( isf_new, isp_new, M, INT_FS_12k8 );
+
+ /* return if SID frame (conversion to A(z) done in the calling function) */
+ return;
+ }
+
+ /*-----------------------------------------------------------------*
+ * ISF de-quantization of all other frames
+ *-----------------------------------------------------------------*/
+
+ if ( st->core_brate == ACELP_6k60 )
+ {
+ indice[0] = get_next_indice( st, 8 );
+ indice[1] = get_next_indice( st, 8 );
+ indice[2] = get_next_indice( st, 7 );
+ indice[3] = get_next_indice( st, 7 );
+ indice[4] = get_next_indice( st, 6 );
+
+ disf_2s_36b( indice, isf_new, st->mem_AR, st->mem_MA );
+ }
+ else
+ {
+ indice[0] = get_next_indice( st, 8 );
+ indice[1] = get_next_indice( st, 8 );
+ indice[2] = get_next_indice( st, 6 );
+ indice[3] = get_next_indice( st, 7 );
+ indice[4] = get_next_indice( st, 7 );
+ indice[5] = get_next_indice( st, 5 );
+ indice[6] = get_next_indice( st, 5 );
+
+ disf_2s_46b( indice, isf_new, st->mem_AR, st->mem_MA );
+ }
+
+ reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 );
+
+ /* convert quantized ISFs to ISPs */
+ isf2isp( isf_new, isp_new, M, INT_FS_12k8 );
+
+ /*-------------------------------------------------------------------------------------*
+ * FEC - update adaptive mean ISF vector
+ *-------------------------------------------------------------------------------------*/
+
+ for ( i = 0; i < M; i++ )
+ {
+ st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i] ) / 3;
+ }
+
+ /*-------------------------------------------------------------------------------------*
+ * ISP interpolation
+ * A(z) calculation
+ *-------------------------------------------------------------------------------------*/
+
+ if ( st->rate_switching_reset )
+ {
+ /*extrapolation instead of interpolation*/
+ mvr2r( isp_new, st->lsp_old, M );
+ mvr2r( isf_new, st->lsf_old, M );
+ }
+
+ /* ISP interpolation and A(z) calculation */
+ int_lsp( L_FRAME, st->lsp_old, isp_new, Aq, M, interpol_isp_amr_wb, 1 );
+
+ /*------------------------------------------------------------------*
+ * Check ISF stability : distance between old ISF and current ISF
+ *------------------------------------------------------------------*/
+
+ st->stab_fac = lsf_stab( isf_new, st->lsf_old, 1, st->L_frame );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * disf_ns_28b()
+ *
+ * ISF de-quantizer for SID_1k75 frames (only for AMR-WB IO mode)
+ *-------------------------------------------------------------------*/
+
+void disf_ns_28b( int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ float *isf_q /* o : ISF in the frequency domain (0..6400) */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < 2; i++ )
+ {
+ isf_q[i] = dico1_ns_28b[indice[0] * 2 + i];
+ }
+
+ for ( i = 0; i < 3; i++ )
+ {
+ isf_q[i + 2] = dico2_ns_28b[indice[1] * 3 + i];
+ isf_q[i + 5] = dico3_ns_28b[indice[2] * 3 + i];
+ }
+
+ for ( i = 0; i < 4; i++ )
+ {
+ isf_q[i + 8] = dico4_ns_28b[indice[3] * 4 + i];
+ isf_q[i + 12] = dico5_ns_28b[indice[4] * 4 + i];
+ }
+
+ for ( i = 0; i < M; i++ )
+ {
+ isf_q[i] += mean_isf_noise_amr_wb[i];
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * disf_2s_46b()
+ *
+ * ISF de-quantizer for 46b. codebooks (only for AMR-WB IO mode)
+ *-------------------------------------------------------------------*/
+
+void disf_2s_46b(
+ int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ float *isf_q, /* o : quantized ISFs in the cosine domain */
+ float *mem_AR, /* o : quantizer memory for AR model */
+ float *mem_MA /* i/o: quantizer memory for MA model */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < 9; i++ )
+ {
+ isf_q[i] = dico1_isf[indice[0] * 9 + i];
+ }
+
+ for ( i = 0; i < 7; i++ )
+ {
+ isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];
+ }
+
+ for ( i = 0; i < 3; i++ )
+ {
+ isf_q[i] += dico21_isf_46b[indice[2] * 3 + i];
+ isf_q[i + 3] += dico22_isf_46b[indice[3] * 3 + i];
+ isf_q[i + 6] += dico23_isf_46b[indice[4] * 3 + i];
+ isf_q[i + 9] += dico24_isf_46b[indice[5] * 3 + i];
+ }
+
+ for ( i = 0; i < 4; i++ )
+ {
+ isf_q[i + 12] += dico25_isf_46b[indice[6] * 4 + i];
+ }
+
+ for ( i = 0; i < M; i++ )
+ {
+ mem_AR[i] = (float) ( isf_q[i] + MU_MA * mem_MA[i] ); /* Update with quantized ISF vector for AR model */
+ mem_MA[i] = isf_q[i]; /* Update with quantized prediction error for MA model */
+ isf_q[i] = mem_AR[i] + mean_isf_amr_wb[i]; /* Quantized ISFs */
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * disf_2s_36b()
+ *
+ * ISF de-quantizer for 36b. codebooks (only for AMR-WB IO mode)
+ *-------------------------------------------------------------------*/
+
+void disf_2s_36b(
+ int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ float *isf_q, /* o : quantized ISFs in the cosine domain */
+ float *mem_AR, /* i/o: quantizer memory for AR model */
+ float *mem_MA /* i/o: quantizer memory for MA model */
+)
+{
+ int16_t i;
+ const float *pt_dico1;
+
+ pt_dico1 = dico1_isf; /* Pointer of the 1st stage, 1st plit */
+
+ for ( i = 0; i < 9; i++ )
+ {
+ isf_q[i] = pt_dico1[indice[0] * 9 + i];
+ }
+
+ for ( i = 0; i < 7; i++ )
+ {
+ isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];
+ }
+
+ for ( i = 0; i < 5; i++ )
+ {
+ isf_q[i] += dico21_isf_36b[indice[2] * 5 + i];
+ }
+
+ for ( i = 0; i < 4; i++ )
+ {
+ isf_q[i + 5] += dico22_isf_36b[indice[3] * 4 + i];
+ }
+
+ for ( i = 0; i < 7; i++ )
+ {
+ isf_q[i + 9] += dico23_isf_36b[indice[4] * 7 + i];
+ }
+
+ for ( i = 0; i < M; i++ )
+ {
+ mem_AR[i] = (float) ( isf_q[i] + MU_MA * mem_MA[i] ); /* Update with quantized ISF vector for AR model */
+ mem_MA[i] = isf_q[i]; /* Update with quantized prediction error for MA model */
+ isf_q[i] = mem_AR[i] + mean_isf_amr_wb[i]; /* Quantized ISFs */
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_agc_com.c b/lib_com/ivas_agc_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..3bb4bdea2e9547843b30b6b42c14cf0b719b165c
--- /dev/null
+++ b/lib_com/ivas_agc_com.c
@@ -0,0 +1,112 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "ivas_prot.h"
+#include
+#include "wmc_auto.h"
+#include "prot.h"
+
+/*------------------------------------------------------------------------------------------*
+ * Local constants
+ *------------------------------------------------------------------------------------------*/
+
+#define SQRKMAX ( 1.5f )
+#define NBITS_DIFFG ( 2 )
+#define DBSTEP ( -6.f ) /* desired dB step value in dB*/
+#define ABS_EMIN_MAX ( 3 )
+#define MAXATTEXP ( 1 ) /* the desired maximum attenuation exponent range per frame*/
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_agc_initWindowFunc()
+ *
+ * Get a window function
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_agc_initWindowFunc(
+ float *pWinFunc,
+ const int16_t length )
+{
+ int16_t i;
+ float N;
+ float a;
+
+ N = (float) ( length - 1 );
+ a = 0.5f * ( 1.f - powf( 10.f, DBSTEP / 20.f ) );
+
+ for ( i = 0; i < length; i++ )
+ {
+ pWinFunc[i] = 1.f + a * ( cosf( EVS_PI * i / N ) - 1.f );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_agc_calcGainParams()
+ *
+ * Calculate gain parameters
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_agc_calcGainParams(
+ uint16_t *absEmin,
+ uint16_t *betaE,
+ uint16_t *maxAttExp,
+ const int16_t numCoeffs )
+{
+ int16_t totExp;
+ int16_t Bm;
+ int16_t nbits;
+
+ nbits = NBITS_DIFFG;
+
+ *absEmin = max( ABS_EMIN_MAX, (uint16_t) ceilf( logf( ceilf( SQRKMAX * numCoeffs ) ) * INV_LOG_2 ) );
+
+ totExp = *absEmin + AGC_EMAX + 1;
+ *betaE = (uint16_t) ceilf( logf( totExp ) * INV_LOG_2 );
+
+ Bm = (uint16_t) ceilf( logf( ( AGC_EMAX + 1 + 1 ) ) * INV_LOG_2 );
+
+ if ( nbits > 0 )
+ {
+ Bm = min( AGC_BITS_PER_CH - 1, NBITS_DIFFG );
+ }
+
+ *maxAttExp = ( (uint16_t) powf( 2, Bm ) ) - 2;
+ *maxAttExp = min( MAXATTEXP, *maxAttExp );
+
+ return;
+}
+
diff --git a/lib_com/ivas_arith.c b/lib_com/ivas_arith.c
new file mode 100644
index 0000000000000000000000000000000000000000..98243b0f4addacfbc7d4efb5277ac8568c96cb37
--- /dev/null
+++ b/lib_com/ivas_arith.c
@@ -0,0 +1,302 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "wmc_auto.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "stat_dec.h"
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_ari_start_decoding_14bits_ext_1_lfe()
+ *
+ * Start arithemetic coding
+ *
+ * Similar to ari_start_decoding_14bits(), but do not read past frame boundary.
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_ari_start_decoding_14bits_ext_1_lfe(
+ Decoder_State *st,
+ Tastat *s,
+ int16_t *extra_bits_read )
+{
+ int32_t val;
+
+ if ( st->bits_frame >= ( st->next_bit_pos + cbitsnew ) )
+ {
+ val = get_next_indice( st, cbitsnew );
+ }
+ else
+ {
+ int16_t rem_bits;
+ rem_bits = st->bits_frame - st->next_bit_pos;
+ val = get_next_indice( st, rem_bits );
+ val = ( val << ( cbitsnew - rem_bits ) );
+ *extra_bits_read = *extra_bits_read + ( cbitsnew - rem_bits );
+ }
+
+ s->low = 0;
+ s->high = ari_q4new;
+ s->value = val;
+
+ return;
+}
+
+
+/* Helper function to determine the symbol. */
+static uint16_t ivas_ari_get_symbol(
+ const uint16_t *p,
+ uint32_t range,
+ uint32_t cum )
+{
+ uint16_t symbol;
+
+ symbol = 0;
+
+ while ( ( p[symbol + 1] * range ) > cum )
+ {
+ symbol = symbol + 1;
+ }
+
+ return symbol;
+}
+
+
+/*---------------------------------------------------------------
+ * Function ivas_ari_decode_14bits_bit_ext_1_lfe()
+ *
+ *
+ *-------------------------------------------------------------*/
+
+uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe(
+ Decoder_State *st,
+ Tastat *s,
+ const uint16_t *cum_freq,
+ int16_t *extra_bits_read )
+{
+ uint16_t symbol;
+ uint32_t low, high, range, value;
+ uint32_t cum;
+
+ /* read s->low,high,value sequentially */
+ low = s->low;
+ high = s->high;
+ value = s->value;
+
+ range = high - low + 1;
+ cum = ( ( ( (uint32_t) ( value - low + 1 ) ) << stat_bitsnew ) - ( (uint32_t) 1 ) );
+
+ symbol = ivas_ari_get_symbol( cum_freq, range, cum );
+
+ high = low + mul_sbc_14bits( range, cum_freq[symbol] ) - 1;
+ low += mul_sbc_14bits( range, cum_freq[symbol + 1] );
+
+ for ( ;; )
+ {
+ if ( high >= ari_q2new )
+ {
+ if ( low >= ari_q2new )
+ {
+ value -= ari_q2new;
+ low -= ari_q2new;
+ high -= ari_q2new;
+ }
+ else
+ {
+ if ( low >= ari_q1new && high < ari_q3new )
+ {
+ value -= ari_q1new;
+ low -= ari_q1new;
+ high -= ari_q1new;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ low += low;
+ high += high + 1;
+
+ if ( st->next_bit_pos >= st->bits_frame )
+ {
+ value = ( value << 1 );
+ *extra_bits_read = *extra_bits_read + 1;
+ }
+ else
+ {
+ value = ( value << 1 ) | get_next_indice_1( st );
+ }
+ }
+
+ s->low = low;
+ s->high = high;
+ s->value = value;
+
+ return symbol;
+}
+
+
+/*---------------------------------------------------------------
+ * Function ivas_ari_done_decoding_14bits_ext_1_lfe()
+ *
+ *
+ *-------------------------------------------------------------*/
+
+void ivas_ari_done_decoding_14bits_ext_1_lfe(
+ Decoder_State *st,
+ const int16_t extra_bits_read )
+{
+ get_next_indice_tmp( st, -( cbitsnew - 2 - extra_bits_read ) );
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * Function ivas_ari_done_encoding_14bits()
+ *
+ * Arith encoding of last table entry
+ *-------------------------------------------------------------*/
+
+void ivas_ari_done_encoding_14bits(
+ BSTR_ENC_HANDLE hBstr,
+ Tastat *s )
+{
+ int32_t low;
+ int32_t bits_to_follow;
+
+ /* not needed, s points to s->low */
+ low = s->low;
+ bits_to_follow = s->bits_to_follow + 1;
+
+ if ( low < ari_q1new )
+ {
+ push_next_indice( hBstr, 0, 1 ); /*send a zero*/
+
+ for ( ; bits_to_follow > 0; bits_to_follow-- )
+ {
+ push_next_indice( hBstr, 1, 1 ); /*send a one*/
+ }
+ }
+ else
+ {
+ push_next_indice( hBstr, 1, 1 ); /*send a one*/
+ for ( ; bits_to_follow > 0; bits_to_follow-- )
+ {
+ push_next_indice( hBstr, 0, 1 ); /*send a zero*/
+ }
+ }
+
+ /*It is done so no need to save values-> no counting*/
+ /*s->low = low;
+ s->bits_to_follow = bits_to_follow;*/
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * Function ivas_ari_encode_14bits_ext()
+ *
+ * Arith encode function for extended proba tables
+ *-------------------------------------------------------------*/
+
+void ivas_ari_encode_14bits_ext(
+ BSTR_ENC_HANDLE hBstr,
+ Tastat *s,
+ int32_t symbol,
+ const uint16_t *cum_freq )
+{
+ int32_t low, high, range;
+ int32_t bits_to_follow;
+
+ /*for all operation using bit_ptr=&ptr[bp] */
+ /* for reading s->high,low,bits_to_follow sequentially */
+ high = s->high;
+ low = s->low;
+ range = high - low + 1;
+
+ high = low + mul_sbc_14bits( range, cum_freq[symbol] ) - 1;
+ low += mul_sbc_14bits( range, cum_freq[symbol + 1] );
+
+ bits_to_follow = s->bits_to_follow;
+
+ for ( ;; )
+ {
+ if ( high < ari_q2new )
+ {
+ push_next_indice( hBstr, 0, 1 ); /*send a zero*/
+ for ( ; bits_to_follow > 0; bits_to_follow-- )
+ {
+ push_next_indice( hBstr, 1, 1 ); /*send a one*/
+ }
+ }
+ else
+ {
+ if ( low >= ari_q2new )
+ {
+ push_next_indice( hBstr, 1, 1 ); /*send a one*/
+ for ( ; bits_to_follow > 0; bits_to_follow-- )
+ {
+ push_next_indice( hBstr, 0, 1 ); /*send a zero*/
+ }
+ low -= ari_q2new;
+ high -= ari_q2new; /* Subtract offset to top. */
+ }
+ else
+ {
+ /* Output an opposite bit */
+ if ( low >= ari_q1new && high < ari_q3new ) /* Output an opposite bit */
+ {
+ /* later if in middle half. */
+ bits_to_follow += 1;
+ low -= ari_q1new; /* Subtract offset to middle*/
+ high -= ari_q1new;
+ }
+ else
+ {
+ break; /* Otherwise exit loop. */
+ }
+ }
+ }
+ low += low;
+ high += high + 1; /* Scale up code range. */
+ }
+
+ s->low = low;
+ s->high = high;
+ s->bits_to_follow = bits_to_follow;
+
+ return;
+}
diff --git a/lib_com/ivas_avq_pos_reorder_com.c b/lib_com/ivas_avq_pos_reorder_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..015a3988f7ba326abebc023c471b032c9c0bd402
--- /dev/null
+++ b/lib_com/ivas_avq_pos_reorder_com.c
@@ -0,0 +1,63 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "prot.h"
+#include "wmc_auto.h"
+
+/*-----------------------------------------------------------------*
+ * ordr_esti()
+ *
+ *
+ *-----------------------------------------------------------------*/
+
+void ordr_esti(
+ const int16_t svLength, /* i : sub-vector index */
+ int16_t *Mpos, /* i/o: dominant sub-vector position from ACV */
+ int16_t svOrder[], /* i/o: AVQ sub-vector order */
+ const int16_t Nsv /* i : total sub-vectors in a sub-frames */
+)
+{
+ int16_t i, tmp;
+
+ tmp = svOrder[0];
+ svOrder[0] = *Mpos;
+ *Mpos = Nsv - 1;
+
+ for ( i = 1; i < svLength; tmp++, i++ )
+ {
+ svOrder[i] = tmp;
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h
new file mode 100644
index 0000000000000000000000000000000000000000..09241a5430f9bde72efe33ad07d301f278f3f3ce
--- /dev/null
+++ b/lib_com/ivas_cnst.h
@@ -0,0 +1,1788 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_CNST_H
+#define IVAS_CNST_H
+
+#include
+#include "options.h"
+#include "cnst.h"
+
+/* clang-format off */
+
+/*----------------------------------------------------------------------------------*
+ * mathematical constants
+ *----------------------------------------------------------------------------------*/
+
+#define PI_OVER_2 ( EVS_PI / 2.0f )
+#define PI_OVER_180 ( EVS_PI / 180.0f )
+#define _180_OVER_PI ( 180.0f / EVS_PI )
+
+#define SQRT2 1.414213562373095f
+#define SQRT2_OVER_2 (SQRT2 / 2.0f)
+
+#define INV_SQRT2 7.071067811865475e-1f /* 1/sqrt(2) */
+#define INV_SQRT3 0.577350269189626f /* 1/sqrt(3) */
+
+#define LOG_10 2.30258509299f
+
+
+/*----------------------------------------------------------------------------------*
+ * IVAS formats
+ *----------------------------------------------------------------------------------*/
+
+typedef enum
+{
+ UNDEFINED_FORMAT,
+ MONO_FORMAT, /* EVS mono processing */
+ STEREO_FORMAT, /* IVAS stereo format */
+ ISM_FORMAT, /* IVAS ISM (objects-coding) format */
+ SBA_FORMAT, /* IVAS SBA (ambisonics) format */
+ MASA_FORMAT, /* IVAS MASA format */
+ MC_FORMAT, /* IVAS multi-channel format */
+ MASA_ISM_FORMAT, /* IVAS combined MASA + objects format*/
+ SBA_ISM_FORMAT /* IVAS combined SBA + objects format */
+} IVAS_FORMAT;
+
+
+/*----------------------------------------------------------------------------------*
+ * IVAS format signaling
+ *----------------------------------------------------------------------------------*/
+
+#define IVAS_FORMAT_SIGNALING_NBITS 2 /* number of bits for signaling the IVAS format */
+#define IVAS_FORMAT_SIGNALING_NBITS_EXTENDED ( IVAS_FORMAT_SIGNALING_NBITS + 1 )
+#define IVAS_COMBINED_FORMAT_SIGNALLING_BITS 1
+
+
+/*----------------------------------------------------------------------------------*
+ * IVAS rendering configurations
+ *----------------------------------------------------------------------------------*/
+
+/* Rendering convention rules:
+ * 1) "st_ivas->renderer_type" reflects always the last rendering stage in the processing
+ * 2) in some configurations, more rendering stages are used
+ * - renderers at the last stage, like RENDERER_BINAURAL_xxx, consider uniquely "st_ivas->hOutputSetup"
+ * - renderers that can be followed by an additional rendering stage, e.g. RENDERER_DIRAC, consider uniquely "st_ivas->hIntSetup"
+ * 3) in case of a single rendering stage: "hIntSetup=hOutputSetup"
+ * 4) In case of no rendering stage: "hTransSetup=hIntSetup=hOutputSetup" */
+
+typedef enum
+{
+ RENDERER_DISABLE,
+ RENDERER_TD_PANNING,
+ RENDERER_BINAURAL_FASTCONV,
+ RENDERER_BINAURAL_FASTCONV_ROOM,
+ RENDERER_BINAURAL_PARAMETRIC,
+ RENDERER_BINAURAL_PARAMETRIC_ROOM,
+ RENDERER_BINAURAL_OBJECTS_TD,
+ RENDERER_DIRAC,
+ RENDERER_MC,
+ RENDERER_MC_PARAMMC,
+ RENDERER_SBA_LINEAR_DEC,
+ RENDERER_SBA_LINEAR_ENC,
+ RENDERER_STEREO_PARAMETRIC,
+ RENDERER_MONO_DOWNMIX,
+ RENDERER_MCMASA_MONO_STEREO,
+ RENDERER_PARAM_ISM,
+ RENDERER_BINAURAL_MIXER_CONV,
+ RENDERER_BINAURAL_MIXER_CONV_ROOM,
+ RENDERER_NON_DIEGETIC_DOWNMIX,
+ RENDERER_OSBA_STEREO,
+ RENDERER_OSBA_AMBI,
+ RENDERER_OSBA_LS
+} RENDERER_TYPE;
+
+
+/*----------------------------------------------------------------------------------*
+ * IVAS general constants
+ *----------------------------------------------------------------------------------*/
+
+#define MAX_INPUT_CHANNELS 16 /* Maximum number of input channels (HOA 3rd order), == IVAS_MAX_INPUT_CHANNELS */
+#define MAX_TRANSPORT_CHANNELS 12 /* Maximum number of transport channels */
+#define MAX_INTERN_CHANNELS 16 /* Maximum number of intern channels (HOA 3rd order) */
+#define HEAD_ROTATION_HOA_ORDER 3 /* HOA 3rd order */
+#define MAX_CICP_CHANNELS 16 /* max channels for loudspeaker layouts (16 for custom layouts)*/
+#define MAX_OUTPUT_CHANNELS 16 /* Maximum number of output channels (HOA 3rd order), == IVAS_MAX_OUTPUT_CHANNELS */
+#define MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN 2 /* Maximum number of output channels with non diegetic panning */
+
+#define BINAURAL_CHANNELS 2 /* number of channels for binaural output configuration */
+#define CPE_CHANNELS 2 /* number of CPE (stereo) channels */
+#define FOA_CHANNELS 4 /* number of FOA channels */
+#define HOA2_CHANNELS 9
+#define HOA3_CHANNELS 16
+
+#define MAX_NUM_OBJECTS 4 /* max. number of audio objects, == IVAS_MAX_NUM_OBJECTS */
+
+#define MAX_SCE MAX_NUM_OBJECTS /* max. number of SCEs */
+#define MAX_CPE ( MAX_TRANSPORT_CHANNELS / CPE_CHANNELS ) /* max. number of CPEs */
+
+#define MAX_BITS_METADATA 2500 /* max. bit-budget of metadata */
+#define MIN_NUM_IND 10 /* minimum number of indices in the core coder */
+#define MAX_NUM_IND_LFE 100 /* maximum number of indices in the LFE encoder */
+#define MAX_NUM_IND_TEMP_LIST 10 /* maximum number of indices in the temporary list */
+#define MAX_IND_TDM_TMP 10 /* maximum number of indices in the temporary list of TD stereo spatial parameters */
+
+#define IVAS_ENC_DELAY_NS ACELP_LOOK_NS
+#define IVAS_DEC_DELAY_NS 3250000L /* 3.25 ms: IVAS decoder delay (without renderer delay) */
+
+#define DELAY_FB_1_NS 1000000L /* 1.00 ms: filter-bank delay */
+#define DELAY_FB_4_NS 4000000L /* 4.00 ms: filter-bank delay */
+
+#define IVAS_FB_ENC_DELAY_NS DELAY_FB_1_NS /* 1.00 ms: IVAS encoder filter-bank delay */
+#define IVAS_FB_DEC_DELAY_NS 5000000L /* 5.00 ms: IVAS decoder/renderer filter-bank delay */
+
+#define IVAS_MAX_SBA_ORDER 3 /* Maximum supported Ambisonics order */
+
+#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 MAX_JBM_CLDFB_TIMESLOTS 32
+#define DEFAULT_JBM_CLDFB_TIMESLOTS 16
+#define MAX_JBM_L_FRAME48k 1920
+#define MAX_JBM_L_FRAME_NS 40000000L
+#define MAX_SPAR_INTERNAL_CHANNELS IVAS_SPAR_MAX_CH
+#define MAX_CLDFB_DIGEST_CHANNELS (FOA_CHANNELS + MAX_NUM_OBJECTS)
+
+typedef enum
+{
+ TC_BUFFER_MODE_NONE = 0,
+ TC_BUFFER_MODE_RENDERER,
+ TC_BUFFER_MODE_BUFFER
+} TC_BUFFER_MODE;
+
+/*----------------------------------------------------------------------------------*
+ * IVAS Bitrates
+ *----------------------------------------------------------------------------------*/
+
+#define IVAS_SID_5k2 5200 /* SID frame bitrate */
+#define IVAS_13k2 13200
+#define IVAS_16k4 16400
+#define IVAS_24k4 24400
+#define IVAS_32k 32000
+#define IVAS_48k 48000
+#define IVAS_64k 64000
+#define IVAS_80k 80000
+#define IVAS_96k 96000
+#define IVAS_128k 128000
+#define IVAS_160k 160000
+#define IVAS_192k 192000
+#define IVAS_256k 256000
+#define IVAS_384k 384000
+#define IVAS_512k 512000
+
+#define IVAS_BRATE_MAX IVAS_512k
+
+#define SIZE_IVAS_BRATE_TBL 16
+#define IVAS_NUM_ACTIVE_BRATES (SIZE_IVAS_BRATE_TBL - 2)
+
+/*----------------------------------------------------------------------------------*
+ * IVAS modes : IVAS SCE, IVAS CPE modes (DFT, TD, MDCT stereo)
+ *----------------------------------------------------------------------------------*/
+
+#define EVS_MONO 0 /* EVS Mono BE operating mode */
+#define IVAS_SCE 1 /* IVAS SCE */
+#define IVAS_CPE_DFT 2 /* IVAS CPE: DFT-based parametric stereo */
+#define IVAS_CPE_TD 3 /* IVAS CPE: TD stereo */
+#define IVAS_CPE_MDCT 4 /* IVAS CPE: MDCT-based stereo */
+
+#define MIN_BRATE_MDCT_STEREO IVAS_48k /* min. CPE bitrate where MDCT stereo is supported in stereo format coding */
+
+#define PCA_BRATE IVAS_256k /* PCA supported bitrate */
+
+#define NBITS_ELEMENT_MODE 1 /* number of bits to encode the stereo element mode */
+#define NBITS_BWIDTH 2 /* number of bits to encode all audio bandwidths */
+
+/* format signaling in SID frames */
+#define SID_FORMAT_NBITS 3 /* Bit 0 | Bit 1 | Bit 2 */
+ /*-------|-------|------ */
+#define SID_DFT_STEREO 0x0 /* 0| 0| 0 */
+#define SID_MDCT_STEREO 0x1 /* 1| 0| 0 */
+#define SID_ISM 0x2 /* 0| 1| 0 */
+#define SID_MASA_1TC 0x3 /* 1| 1| 0 */
+#define SID_MULTICHANNEL 0x4 /* 0| 0| 1 */
+#define SID_SBA_1TC 0x5 /* 1| 0| 1 */
+#define SID_SBA_2TC 0x6 /* 0| 1| 1 */
+#define SID_MASA_2TC 0x7 /* 1| 1| 1 */
+
+/*----------------------------------------------------------------------------------*
+ * IVAS ACELP core constants
+ *----------------------------------------------------------------------------------*/
+
+#define MIN_UNVOICED_TWO_STAGE_BRATE 7050 /* min. per channel bitrate where two stages UNVOICED is supported */
+#define MAX_UNVOICED_BRATE ACELP_13k20 /* max. per channel bitrate where UNVOICED is supported */
+#define MAX_VOICED_BRATE ACELP_13k20 /* max. per channel bitrate where VOICED is supported */
+#define MIN_TC_BRATE 6450 /* min. per channel bitrate where TRANSITION is supported */
+#define MAX_ACELP_BRATE 48000 /* max. per channel bitrate where ACELP core is supported */
+#define MAX_ACELP_BRATE_ISM 40000 /* max. per channel bitrate where ACELP core is supported in ISM format */
+
+#define ACELP_12k8_HIGH_LIMIT 24350 /* max. per channel bitrate where the ACELP@12.8kHz is supported */
+#define ACELP_16k_LOW_LIMIT 13250 /* min. per channel bitrate where the ACELP@16kHz is supported */
+#define SCE_CORE_16k_LOW_LIMIT 17000 /* min. SCE bitrate where the ACELP@16kHz is supported; must be >= (ACELP_16k_LOW_LIMIT + SWB_TBE_1k6) */
+#define MIN_BRATE_AVQ_EXC ACELP_29k00 /* min. per channel bitrate where the AVQ excitation stage is supported */
+#define MAX_BRATE_AVQ_EXC_TD 40000 /* max. per channel bitrate where the AVQ excitation stage in time domain is supported */
+
+#define MAX_GSC_INACTIVE_BRATE 28000 /* max. per channel bitrate where GSC Inactive (@16kHz) is supported (max. 31950 to ensure BE with EVS mono) */
+
+#define FRMT_SHP_MIN_BRATE_IVAS 18000 /* min. bitrate where formant-sharpening flag is transmitted; applies both to SCE and CPE */
+
+#define CNA_MAX_BRATE_STEREO IVAS_16k4 /* max. stereo bitrate where CNA is supported */
+#define CNA_MAX_BRATE_DFT_STEREO IVAS_32k /* max. stereo bitrate where CNA is supported in DFT stereo */
+
+#define MIN_BRATE_WB_BWE 7150 /* min. per channel bitrate where WB BWE info is encoded */
+#define MIN_BRATE_SWB_BWE 7800 /* min. per channel bitrate where SWB BWE info is encoded */
+
+#define MIN_BRATE_GSC_NOISY_FLAG 12000 /* min. per channel bitrate where gsc_noisy_flag in SWB is supported */
+#define GSC_L_RATE_STG 15000 /* bitrate below will use low rate GSC settings */
+#define GSC_H_RATE_STG 20000 /* bitrates above will use high rate GSC settings */
+
+#define MIN_BRATE_SWB_SCE ACELP_9k60 /* min. SCE bitrate where SWB is supported */
+#define MIN_BRATE_SWB_STEREO IVAS_13k2 /* min. stereo bitrate where SWB is supported */
+#define MIN_BRATE_FB_STEREO IVAS_32k /* min. SCE and stereo bitrate where FB is supported */
+#define MIN_BRATE_FB_ISM 16000 /* min. SCE bitrate where FB is supported in ISM format */
+
+#define MIN_TDM_BRATE_WB_TBE_1k05 12000 /* min. per channel bitrate where WB TBE @1.05 kbps is supported (0.35kbs at lower bitrates) */
+#define MIN_BRATE_WB_TBE_1k05 9650 /* min. per channel bitrate where WB TBE @1.05 kbps is supported (0.35kbs at lower bitrates) */
+#define MIN_BRATE_SWB_TBE_1k60 13200 /* min. per channel bitrate where SWB TBE @1.60 kbps is supported (0.95 kbps at lower bitrates) */
+#define MIN_BRATE_SWB_TBE_2k80 24400 /* min. per channel bitrate where SWB TBE @2.80 kbps is supported */
+#define MIN_MIN_BRATE_LRTD_SWB_BWE 5000
+
+#define STEREO_TCX_MIN_RATE 9000 /* TCX coding down to this per channel bitrate */
+#define STEREO_GSC_BIT_RATE_ALLOC 9200
+#define HQ_MDCTCLASS_CROSSOVER_BRATE 32000 /* MDCT classifier crossover bitrate between 24.4 and 32 kbps tunings*/
+#define HQ_BWE_CROSSOVER_BRATE 26000 /* HQ crossover bitrate between 24.4 and 32 kbps BWE tunings */
+
+
+/*----------------------------------------------------------------------------------*
+ * ISM Constants
+ *----------------------------------------------------------------------------------*/
+
+#define ISM_NB_BITS_METADATA_NOMINAL ( ( SCE_CORE_16k_LOW_LIMIT - ACELP_16k_LOW_LIMIT ) / FRAMES_PER_SEC ) /* nominal number of metadata bits - used for configuration of Core-Coder modules */
+
+#define ISM_METADATA_MD_FLAG_BITS 1 /* flag to distinguish between NULL metadata and low-rate ISM_NO_META class */
+#define ISM_METADATA_INACTIVE_FLAG_BITS 1 /* flag to signal whether MD are sent in low-rate inactive frame */
+#define ISM_METADATA_FLAG_BITS 2
+
+#define ISM_INACTIVE_IMP 0 /* == ISM_NO_META */
+#define ISM_NO_META 0
+#define ISM_LOW_IMP 1
+#define ISM_MEDIUM_IMP 2
+#define ISM_HIGH_IMP 3
+
+#define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISM no meta / inactive frames */
+#define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC )
+#define ADJUST_ISM_BRATE_NEG 6000
+#define ADJUST_ISM_BRATE_POS 8000
+
+#define ISM_AZIMUTH_NBITS 7
+#define ISM_AZIMUTH_MIN -180.0f
+#define ISM_AZIMUTH_MAX 180.0f
+#define ISM_AZIMUTH_LOW_BORDER -140.0f
+#define ISM_AZIMUTH_HIGH_BORDER 135.0f
+
+#define ISM_ELEVATION_NBITS 6
+#define ISM_ELEVATION_MIN -90.0f
+#define ISM_ELEVATION_MAX 90.0f
+#define ISM_ELEVATION_LOW_BORDER -70.0f
+#define ISM_ELEVATION_HIGH_BORDER 65.0f
+#define ISM_Q_STEP 2.5f
+#define ISM_Q_STEP_BORDER 5.0f
+
+#define ISM_RADIUS_NBITS 6
+#define ISM_RADIUS_MIN 0.0f
+#define ISM_RADIUS_DELTA 0.25f /* Max radius = (2^ISM_RADIUS_NBITS-1)*0.25 = 15.75 */
+#define ISM_EXTENDED_METADATA_BRATE IVAS_64k
+#define ISM_METADATA_IS_NDP_BITS 1
+#define ISM_EXTENDED_METADATA_BITS 1
+#define ISM_METADATA_RS_MAX_FRAMES 5 /* Number of frames with opposite extended metadata flags before switching */
+
+/* Parametric ISM */
+#define MAX_PARAM_ISM_NBANDS 11
+#define MAX_PARAM_ISM_NBANDS_WB 9
+#define MAX_PARAM_ISM_NBANDS_NB 7
+#define PARAM_ISM_MDFT_NO_SLOTS 4
+#define MAX_PARAM_ISM_NBLOCKS 1
+#define MAX_PARAM_ISM_WAVE 2
+#define PARAM_ISM_OBJ_IND_NBITS 2
+#define PARAM_ISM_POW_RATIO_NBITS 3
+#define PARAM_ISM_MAX_DMX 2
+#define PARAM_ISM_MAX_CHAN 16
+#define PARAM_ISM_HYS_BUF_SIZE 10
+
+/* ISM DTX */
+#define ISM_DTX_COH_SCA_BITS 4
+#define ISM_DTX_AZI_BITS_HIGH 8
+#define ISM_DTX_ELE_BITS_HIGH 7
+#define ISM_Q_STEP_HIGH (ISM_Q_STEP / 2)
+#define ISM_Q_STEP_BORDER_HIGH (ISM_Q_STEP_BORDER / 2)
+#define ISM_DTX_AZI_BITS_LOW 6
+#define ISM_DTX_ELE_BITS_LOW 5
+#define ISM_Q_STEP_LOW (ISM_Q_STEP * 2)
+#define ISM_Q_STEP_BORDER_LOW (ISM_Q_STEP_BORDER * 2)
+
+/* ISM modes */
+typedef enum
+{
+ ISM_MODE_NONE,
+ ISM_MODE_DISC, /* discrete ISM */
+ ISM_MODE_PARAM, /* parametric ISM */
+ ISM_MASA_MODE_MASA_ONE_OBJ, /* MASA ISM mode when one object is encoded separately and remainder using MASA parameters */
+ ISM_MASA_MODE_PARAM_ONE_OBJ, /* MASA ISM mode when one object is encoded separately and remainder using parametric object model */
+ ISM_MASA_MODE_DISC, /* MASA ISM mode when all objects are encoded separarately */
+ ISM_SBA_MODE_DISC /* SBA ISM mode when all objects are encoded separarately */
+} ISM_MODE;
+
+
+/* ISM metadata bitstream */
+enum
+{
+ IND_ISM_NUM_OBJECTS,
+ IND_ISM_EXTENDED_FLAG = IND_ISM_NUM_OBJECTS + MAX_NUM_OBJECTS,
+ IND_ISM_EXTENDED_NDP_FLAG,
+ IND_ISM_METADATA_FLAG,
+ IND_ISM_MD_NULL_FLAG = IND_ISM_METADATA_FLAG + MAX_NUM_OBJECTS,
+ IND_ISM_MD_INACTIVE_FLAG = IND_ISM_MD_NULL_FLAG + MAX_NUM_OBJECTS,
+ IND_ISM_NOISY_SPEECH_FLAG = IND_ISM_MD_INACTIVE_FLAG + MAX_NUM_OBJECTS,
+ IND_ISM_SCE_ID_DTX,
+ IND_ISM_DTX_COH_SCA,
+
+ /* ------------- loop for objects -------------- */
+ TAG_ISM_LOOP_START = IND_ISM_DTX_COH_SCA + MAX_NUM_OBJECTS,
+ IND_ISM_NDP_FLAG = TAG_ISM_LOOP_START,
+ IND_ISM_AZIMUTH_DIFF_FLAG = TAG_ISM_LOOP_START,
+ IND_ISM_AZIMUTH = TAG_ISM_LOOP_START,
+ IND_ISM_ELEVATION_DIFF_FLAG = TAG_ISM_LOOP_START,
+ IND_ISM_ELEVATION = TAG_ISM_LOOP_START,
+ IND_ISM_RADIUS_DIFF_FLAG = TAG_ISM_LOOP_START,
+ IND_ISM_RADIUS = TAG_ISM_LOOP_START,
+ TAG_ISM_LOOP_END = TAG_ISM_LOOP_START
+ /* --------- end of loop for objects ----------- */
+
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * DFT Stereo Constants
+ *----------------------------------------------------------------------------------*/
+
+/* Coding configurations*/
+#define STEREO_DFT_DMX_ACTIVE 1 /* Enable true spatialization */
+
+/* residual coding modes */
+#define STEREO_DFT_RES_COD_OFF 0
+#define STEREO_DFT_RES_COD_1kHz 1 /* use residual coding up to 1 kHz */
+#define STEREO_DFT_RES_COD_1_6kHz 2 /* use residual coding up to 1.6 kHz */
+
+/* residual prediction modes */
+#define STEREO_DFT_RESPRED_OFF 0
+#define STEREO_DFT_RESPRED_STEFI 1 /* full-band stereo filling (above residual) */
+#define STEREO_DFT_RESPRED_ESF 2 /* enhanced stereo filling in LB, regular stereo filling in HB */
+
+/* band resolution */
+#define STEREO_DFT_BAND_RES_HIGH 1 /* use higher band resolution following ERB4 scale */
+#define STEREO_DFT_BAND_RES_LOW 2 /* use lower band resolution following ERB8 scale */
+
+/* Processing constants*/
+#define STEREO_DFT_OVL_NS ACELP_LOOK_NS /* 8.75ms */
+#define STEREO_DFT_ZP_NS 3125000L /* 3.125ms */
+#define STEREO_DFT_HOP_NS 10000000L /* 10ms */
+#define STEREO_DFT_N_NS ( STEREO_DFT_HOP_NS + ACELP_LOOK_NS + 2 * STEREO_DFT_ZP_NS )
+
+#define STEREO_DFT_ZP_NS_ENC 5625000L /* 5.625ms */
+#define STEREO_DFT_HOP_NS_ENC FRAME_SIZE_NS /* 20ms */
+#define STEREO_DFT_N_NS_ENC ( STEREO_DFT_HOP_NS_ENC + ACELP_LOOK_NS + 2 * STEREO_DFT_ZP_NS_ENC )
+
+#define STEREO_DFT_OVL_MAX NS2SA( 48000, ACELP_LOOK_NS )
+#define STEREO_DFT_HOP_MAX NS2SA( 48000, STEREO_DFT_HOP_NS )
+
+#define STEREO_DFT_ZP_MAX_ENC NS2SA( 48000, STEREO_DFT_ZP_NS_ENC )
+#define STEREO_DFT_HOP_MAX_ENC NS2SA( 48000, STEREO_DFT_HOP_NS_ENC )
+#define STEREO_DFT_N_MAX_ENC NS2SA( 48000, STEREO_DFT_N_NS_ENC )
+
+#define STEREO_DFT_OVL_32k NS2SA( 32000, ACELP_LOOK_NS )
+
+#define STEREO_DFT_ZP_32k_ENC NS2SA( 32000, STEREO_DFT_ZP_NS_ENC )
+#define STEREO_DFT_HOP_32k_ENC NS2SA( 32000, STEREO_DFT_HOP_NS_ENC )
+#define STEREO_DFT_N_32k_ENC NS2SA( 32000, STEREO_DFT_N_NS_ENC )
+
+#define STEREO_DFT_OVL_16k NS2SA( 16000, ACELP_LOOK_NS )
+
+#define STEREO_DFT_ZP_16k_ENC NS2SA( 16000, STEREO_DFT_ZP_NS_ENC )
+#define STEREO_DFT_HOP_16k_ENC NS2SA( 16000, STEREO_DFT_HOP_NS_ENC )
+#define STEREO_DFT_N_16k_ENC NS2SA( 16000, STEREO_DFT_N_NS_ENC )
+
+#define STEREO_DFT_OVL_12k8 NS2SA( 12800, ACELP_LOOK_NS )
+
+#define STEREO_DFT_ZP_12k8_ENC NS2SA( 12800, STEREO_DFT_ZP_NS_ENC )
+#define STEREO_DFT_HOP_12k8_ENC NS2SA( 12800, STEREO_DFT_HOP_NS_ENC )
+#define STEREO_DFT_N_12k8_ENC NS2SA( 12800, STEREO_DFT_N_NS_ENC )
+
+#define STEREO_DFT_OVL_8k NS2SA( 8000, ACELP_LOOK_NS )
+#define STEREO_DFT_N_8k NS2SA( 8000, STEREO_DFT_N_NS )
+
+#define STEREO_DFT_ZP_8k_ENC NS2SA( 8000, STEREO_DFT_ZP_NS_ENC )
+#define STEREO_DFT_HOP_8k_ENC NS2SA( 8000, STEREO_DFT_HOP_NS_ENC )
+#define STEREO_DFT_N_8k_ENC NS2SA( 8000, STEREO_DFT_N_NS_ENC )
+
+#define STEREO_DFT32MS_N_NS FRAME_SIZE_NS /* 20 ms */
+#define STEREO_DFT32MS_OVL_NS 3125000L /* 3.125ms - Overlap for the outer edges of windows on decoder */
+#define STEREO_DFT32MS_OVL2_NS 9375000L /* 9.375ms - Overlap for the inner edges of windows on decoder */
+#define STEREO_DFT32MS_WIN_CENTER_NS ( int32_t )( ( FRAME_SIZE_NS + STEREO_DFT32MS_OVL_NS ) * 0.5f ) /* 11.5625ms - mid point of the two windows wrt the left edge of overlap */
+#define STEREO_DFT32MS_ZP_NS ( int32_t )( 0.5f * ( STEREO_DFT32MS_N_NS - STEREO_DFT32MS_WIN_CENTER_NS - ( STEREO_DFT32MS_OVL2_NS * 0.5f ) ) ) /* 2 sided zp calculated such that window size is satisfied */
+
+#define STEREO_DFT32MS_OVL_MAX NS2SA( 48000, STEREO_DFT32MS_OVL_NS )
+#define STEREO_DFT32MS_OVL2_MAX NS2SA( 48000, STEREO_DFT32MS_OVL2_NS )
+#define STEREO_DFT32MS_N_MAX NS2SA( 48000, STEREO_DFT32MS_N_NS )
+
+#define STEREO_DFT32MS_N_32k NS2SA( 32000, STEREO_DFT32MS_N_NS )
+
+#define STEREO_DFT32MS_OVL_16k NS2SA( 16000, STEREO_DFT32MS_OVL_NS )
+#define STEREO_DFT32MS_OVL2_16k NS2SA( 16000, STEREO_DFT32MS_OVL2_NS )
+#define STEREO_DFT32MS_N_16k NS2SA( 16000, STEREO_DFT32MS_N_NS )
+
+#define STEREO_DFT32MS_OVL_12k8 NS2SA( 12800, STEREO_DFT32MS_OVL_NS )
+#define STEREO_DFT32MS_OVL2_12k8 NS2SA( 12800, STEREO_DFT32MS_OVL2_NS )
+#define STEREO_DFT32MS_N_12k8 NS2SA( 12800, STEREO_DFT32MS_N_NS )
+
+#define STEREO_DFT32MS_OVL_8k NS2SA( 8000, STEREO_DFT32MS_OVL_NS )
+#define STEREO_DFT32MS_OVL2_8k NS2SA( 8000, STEREO_DFT32MS_OVL2_NS )
+#define STEREO_DFT32MS_N_8k NS2SA( 8000, STEREO_DFT32MS_N_NS )
+
+#define STEREO_DFT32MS_STEP 3 /* STEREO_DFT32MS_OVL2_NS / STEREO_DFT32MS_OVL_NS */
+#define STEREO_DFT_TRIGO_DEC_STEP 2
+#define STEREO_DFT_TRIGO_SRATE_8k_STEP 4
+#define STEREO_DFT_TRIGO_SRATE_12k8_STEP 1
+#define STEREO_DFT_TRIGO_SRATE_16k_STEP 2
+#define STEREO_DFT_TRIGO_SRATE_32k_STEP 1
+#define STEREO_DFT_TRIGO_SRATE_48k_STEP 1
+
+#define STEREO_DFT_OFFSET 1
+#define STEREO_DFT_NBDIV 2
+
+#define STEREO_DFT_ITD_CNG_XFADE 100
+#define STEREO_DFT_ITD_CNG_XFADE_RESET 2
+
+#define STEREO_DFT_DELAY_DEC_BWE_NS ( STEREO_DFT_OFFSET * STEREO_DFT_HOP_NS - ACELP_LOOK_NS ) /* 1.25ms/2.5ms: max delay for core decoder*/
+
+#define STEREO_DFT_ENC_DFT_NB ( STEREO_DFT_OFFSET + 1 ) /*frame + lookahead*/
+#define STEREO_DFT_DEC_DFT_NB ( STEREO_DFT_NBDIV + STEREO_DFT_OFFSET ) /*frame + lookahead*/
+
+#define STEREO_CNA_LR_CORR_LT_FILT 0.95f /* long-term averaging factor for L/R correlation estimation */
+#define STEREO_CNA_ILD_LT_FILT 0.9f /* long-term averaging factor for ILD estimation */
+
+typedef enum
+{
+ DFT_STEREO_DEC_ANA_NOCORE = -1, /*-1: signal read from file (DEBUG mode)*/
+ DFT_STEREO_DEC_ANA_FB, /* 0: full-band signal (e.g. HQ-CORE/TCX (M), residual (S))*/
+ DFT_STEREO_DEC_ANA_FB_ADD, /* 1: full-band signal to add (e.g High-band signal of TD-BWE)*/
+ DFT_STEREO_DEC_ANA_BPF, /* 2: Bass-post-filter error signal, to add and weight*/
+ DFT_STEREO_DEC_ANA_LB, /* 3: low-band signal (e.g. ACELP (M), resiudal signal (S))*/
+ DFT_STEREO_DEC_ANA_LB_ADD, /* 4: low-band signal to add (e.g. LB-TCX)*/
+ DFT_STEREO_DEC_ANA_HB_ADD /* 5: high-band signal to add (e.g. transition to ACELP in MDCT->DFT switching) */
+} DFT_STEREO_DEC_ANA_TYPE;
+
+/*Stereo parameters*/
+
+#define STEREO_DFT_ERB4_BANDS 14
+#define STEREO_DFT_ERB8_BANDS 8
+#define STEREO_DFT_BAND_MAX ( STEREO_DFT_ERB4_BANDS - 1 ) /*Maximum number of parameter bands*/
+#define STEREO_DFT_BUF_MAX STEREO_DFT32MS_N_MAX * STEREO_DFT_NBDIV
+
+#define STEREO_DFT_NRG_PAST_LEN 3
+
+/*ITD*/
+#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_NBITS 9 /* 1 bit for sign, the rest for the absolute value*/
+#define STEREO_DFT_ITD_MODE_NBITS 1
+
+#define STEREO_DFT_SID_ITD_NBITS 4 /* Number of ITD bits SID frames */
+#define STEREO_DFT_SID_ITD_FAC 1 /* Quantization step reduction factor */
+
+#define STEREO_DFT_FLAG_BITS 1
+#define STEREO_DFT_SIDEGAIN_NBITS 5
+#define STEREO_DFT_FEC_THRESHOLD 10
+#define STEREO_DFT_BITDIFF_LP_FAC (0.06f) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */
+#define STEREO_DFT_BITDIFF_ABS_SELECT (0.8f) /* Constant to set tendency for selecting absolute coding mode */
+#define STEREO_DFT_BITDIFF_INIT (12.0f) /* Init value for low-pass bit difference */
+
+#define STEREO_DFT_SIDE_GAIN_NBITS 5
+#define STEREO_DFT_IPD_NBITS 3
+#define STEREO_DFT_GIPD_NBITS 4
+
+#define STEREO_DFT_ITD_VAD_BAND_NUM 20
+
+#define STEREO_DFT_XCORR_LB_MAX 24
+
+#define STEREO_DFT_IPD_BUF_LEN 5
+
+#define STEREO_DFT_N_COH_PRED 4 /* Number of intra-frame predictors for coherence vector */
+#define STEREO_DFT_COH_PRED_COEFFS 15 /* Number of coefficients per predictor */
+#define STEREO_DFT_PRED_NBITS 2 /* Bits to signal predictor (log_2(4) = 2) */
+#define STEREO_DFT_N_COH_ALPHA_STEPS 5
+#define STEREO_DFT_N_COH_ALPHA_LEVELS 2
+#define STEREO_DFT_N_COH_ALPHA_BITS 1
+#define STEREO_DFT_SG_ACT_CNT_MAX 1500
+#define STEREO_DFT_COH_MAXBAND 6
+#define STEREO_DFT_SID_GIPD_NBITS 2
+#define STEREO_DFT_FD_FILT 0.9f
+
+#define STEREO_DFT_CNG_ITD_CNT 8
+
+/*Residual prediction*/
+#define STEREO_DFT_PAST_MAX 4
+#define STEREO_DFT_RES_PRED_BAND_MAX 12
+
+#define STEREO_DFT_REVERB_MODE_NBITS 1
+#define STEREO_DFT_RES_PRED_BAND_MIN 0
+#define STEREO_DFT_RES_PRED_BAND_MIN_RED 3
+#define STEREO_DFT_RES_PRED_BAND_MIN_CONST 3
+
+#define STEREO_DFT_ALLPASS_BUFFERLEN 256
+#define STEREO_DFT_ALLPASS_FADELEN_12k8 32
+#define STEREO_DFT_ALLPASS_FADELEN_16k 40
+#define STEREO_DFT_CORE_HIST_MAX ( STEREO_DFT_PAST_MAX + 3 ) / 2
+#define STEREO_DFT_TD_STEFI_DELAY_NS FRAME_SIZE_NS + IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS
+#define STEREO_DFT_TD_STEFI_SUBFR_DELAY 2
+
+/*Residual coding*/
+#define STEREO_DFT_N_MAX_RES 800 /* Maximum of lines coded in residual coding */
+#define STEREO_DFT_RES_GLOBAL_GAIN_BITS 7
+#define STEREO_DFT_RES_GAINS_BITS 3
+
+#define STEREO_DFT_RES_COD_SNR_MIN 10
+#define STEREO_DFT_RES_COD_SNR_MAX 40
+#define STEREO_DFT_L_SUBFR_8k 32
+#define STEREO_DFT_NBPSF_PIT_MAX_8k NBPSF_PIT_MAX / 2
+
+/* Residual coding BPF */
+#define STEREO_DFT_BPF_ADAPT_ALPHA (0.61f)
+#define STEREO_DFT_BPF_ADAPT_BETA (0.68f)
+
+/* Golomb-Rice encoding */
+#define NO_SYMB_GR_SIDE_G 31
+#define NO_SYMB_GR_PRED_G 8
+
+#define STEREO_DFT_RES_BW_MAX 66 /*Maximum number of bin for residual signal in each frame (res_cod_band_max == 6 in 48kHz)*/
+
+#define SBA_DIRAC_STEREO_NUM_BANDS 12
+
+#define SBA_DIRAC_NRG_SMOOTH_LONG 10
+#define SBA_DIRAC_NRG_SMOOTH_SHORT 3
+
+/* 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)*/
+
+/* MDCT to DFT Stereo switching */
+#define STEREO_MDCT2DFT_FADE_LEN_48k L_FRAME48k / 8
+
+/* DFT stereo side-info bitstream*/
+enum
+{
+ IND_STEREO_DFT_ATTACK_PRESENT,
+ IND_STEREO_DFT_RES_COD,
+ IND_STEREO_DFT_SIDEGAIN_FLAG,
+
+ IND_STEREO_DFT_SIDEGAINS,
+ IND_STEREO_DFT_ITD_MODE = IND_STEREO_DFT_SIDEGAINS + 4 * STEREO_DFT_BAND_MAX + 120,
+
+ IND_STEREO_DFT_ITD_HUFF,
+ IND_STEREO_DFT_ITD_NEG,
+ IND_STEREO_DFT_ITD_COD,
+
+ IND_STEREO_DFT_NO_IPD_FLAG,
+ IND_STEREO_DFT_GIPD,
+
+ IND_STEREO_DFT_IPD_FLAG,
+ IND_STEREO_DFT_IPD_COD,
+
+ IND_STEREO_DFT_REVERB_MODE = IND_STEREO_DFT_IPD_COD + 4 * STEREO_DFT_BAND_MAX + 2, /* max number for GR order 2 */
+
+ IND_STEREO_DFT_RES_PRED_FLAG,
+ IND_STEREO_DFT_PRED_GAIN_COD,
+
+ IND_STEREO_DFT_NON_USED = IND_STEREO_DFT_PRED_GAIN_COD + 4 * STEREO_DFT_RES_PRED_BAND_MAX + 2, /* max number for GR order 2 */
+
+ /* residual coding */
+ IND_STEREO_DFT_RESIDUAL_GLOBAL_GAIN,
+ IND_STEREO_DFT_RESIDUAL_COD,
+ IND_STEREO_DFT_SID_COH = IND_STEREO_DFT_RESIDUAL_COD + 56, /* max possible number of indices for residual coding */
+
+ STEREO_DFT_MAX_NUM_INDICES = IND_STEREO_DFT_SID_COH + 6 /* max possible number of indices for coherence encoding */
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * Range coder constants
+ *----------------------------------------------------------------------------------*/
+
+#define RANGE_UNI_BUFFER_BYTES_MAX 1024
+#define RANGE_N_CONTEXT 64
+#define RANGE_N_SYMBOLS 17
+
+
+/*----------------------------------------------------------------------------------*
+ * ECLVQ Stereo constants
+ *----------------------------------------------------------------------------------*/
+
+#define ECSQ_VECTOR_SIZE_MAX 256
+#define ECSQ_GLOBAL_GAIN_INDEX_ALL_ZERO 127 /* indicates that all values in the vector are zero */
+
+#define ECLVQ_GLOBAL_GAIN_FACTOR ( 20.0f * 127.0f / 90.0f )
+#define ECLVQ_INV_GLOBAL_GAIN_FACTOR ( 1.0f / ( 20.0f * 127.0f / 90.0f ) )
+
+/* the currently defined configuration indexes are:
+ 0: un-optimized using uniform 4 bit parameters (reserved)
+ 1: optimized for 32 kbps target SNR
+ 2: optimized for 32 kbps target bits
+ 3: optimized for 48 kbps target SNR
+ 4: optimized for 48 kbps target bits
+ 5: optimized for 64 kbps target SNR
+ 6: optimized for 64 kbps target bits
+*/
+
+#define ECSQ_CONFIG_COUNT 7 /* number of different configurations, such as bitrates or profiles */
+#define ECSQ_PARAM_COUNT 16 /* number of different coding distributions, the first indicates only zero values */
+#define ECSQ_ALL_ZERO_PARAM -1 /* the integer exponent of the first parameter indicating only zero values */
+#define ECSQ_PROB_BITS 14 /* number of bits used for representing the probabilities in the actual AC */
+#define ECSQ_PROB_TOTAL ( 1 << ECSQ_PROB_BITS ) /* total count used for representing the probabilities in the actual AC */
+
+#define ECSQ_TAB_VALS_SIZE 16 /* 0, 1, 2, 3, ... */
+#define ECSQ_SEGMENT_SIZE 8
+#define ECSQ_log2TB_SIZE 13
+#define ECSQ_PARAM_SEARCH_RANGE 1
+#define ECSQ_NONZERO_MAX 3
+
+
+/*----------------------------------------------------------------------------------*
+ * UNCLR & cross-talk stereo classifiers
+ *----------------------------------------------------------------------------------*/
+
+#define XTALK_SCORE_BUF_LEN 5
+
+#define SSC_MAX_NFEA 58 /* Maximum number of features for stereo scene classification */
+#define SIZE_UNCLR_ISEL_TD 10
+#define SIZE_UNCLR_ISEL_DFT 8
+
+#define SIZE_XTALK_ISEL_TD 17
+#define SIZE_XTALK_ISEL_DFT 11
+
+#define UNCLR_L_ETOT 3
+#define UNCLR_L_RELE 10
+#define UNCLR_RC_ORDER 20
+#define MAX_UV_CNT 100
+
+#define XTALK_PHAT_LEN 200
+
+enum fea_names
+{
+ E_d_clas, E_d_pitch, E_d_voicing, E_sum_d_LSF, E_d_lepsP_13, E_d_cor_map_sum, E_d_dE1, E_d_nchar,
+ E_d_non_sta, E_d_ps_sta, E_d_ps_diff, E_d_sp_div, E_clas, E_pitch, E_voicing, E_lsf_1,
+ E_lsf_4, E_lsf_9, E_lsf_14, E_lepsP_13, E_cor_map_sum, E_dE1, E_nchar, E_non_sta,
+ E_ps_sta, E_ps_diff, E_sp_div, E_corrLagStats0, E_ica_corr_value0, E_ica_instTargetGain,
+ E_diff_corrLM_corrRM, E_tdm_LT_es_em, E_sum_prod, E_tdm_es_em, E_m_corrL_corrR, E_d_corrL_corrR, E_corrEst0, E_corrLagMax,
+ E_d_corrLagMax, E_corrEstMax, E_corrEst_ncorr,E_sum_xcorr, E_es_em, E_cohSNR, E_d_prodL_prodR, E_xcorr_itd_value,
+ E_angle_rot, E_g_pred, E_g_side, E_gainILD, E_gainIPD, E_IPD, E_d_IPD, E_ITD,
+ E_gphat_d_itd2, E_gphat_itd1_flip, E_gphat_ratio_m1_m2, E_gphat_m2_m2
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * ICA Stereo constants
+ *----------------------------------------------------------------------------------*/
+
+#define L_CH_INDX 0
+#define R_CH_INDX 1
+#define CORR_INTER_FS 8000
+#define L_NCSHIFT_NS 5000000L
+#define L_MEM_RECALC_NS ( L_NCSHIFT_NS * 3 ) / 2
+#define L_MEM_RECALC_TBE_NS ( L_NCSHIFT_NS + L_SAMPLES_LA_NS )
+#define L_NCSHIFTMAX NS2SA( 48000, L_NCSHIFT_NS )
+#define L_DEC_MEM_LEN_ICA L_NCSHIFTMAX + ( N_MAX_SHIFT_CHANGE + 1 ) + SINC_ORDER1 / INTERP_FACTOR1
+#define L_FRAME_DS NS2SA( CORR_INTER_FS, FRAME_SIZE_NS )
+#define L_XCORRMEM_DS NS2SA( CORR_INTER_FS, 2 * ( ACELP_LOOK_NS ) )
+#define L_NCSHIFT_DS ( int16_t )( ( ( int32_t )(CORR_INTER_FS) *L_NCSHIFTMAX ) / 48000L )
+#define L_SAMPLES_LA_NS 625000L
+
+#define L_MEM_RECALC_TBE_16K NS2SA( 16000, L_MEM_RECALC_TBE_NS )
+#define L_MEM_RECALC_48K NS2SA( 48000, L_MEM_RECALC_NS )
+#define L_MEM_RECALC_12K8 NS2SA( 12800, L_MEM_RECALC_NS )
+#define L_MEM_RECALC_16K NS2SA( 16000, L_MEM_RECALC_NS )
+#define N_MAX_SHIFT_CHANGE 20
+
+#define L_MEM_RECALC_SCH_NS ( ACELP_LOOK_NS + DELAY_FIR_RESAMPL_NS - L_MEM_RECALC_NS )
+#define L_MEM_RECALC_48k_SCH NS2SA( 48000, L_MEM_RECALC_SCH_NS )
+
+#define INTERP_FACTOR1 2
+#define SINC_ORDER1 24
+#define L_SHIFT_ADAPT_MAX 596 /* must be a multiple of 2 */
+#define L_SHIFT_ADAPT_16k 290 /* must be a multiple of 2 */
+
+#define STEREO_BITS_TCA_CHAN 1 /* ref/target channel index */
+#define STEREO_BITS_TCA_CORRSTATS 5 /* target corrStats */
+#define STEREO_BITS_TCA_GD 5 /* target gain */
+#define STEREO_TCA_GDMIN -1.0f
+#define STEREO_TCA_GDSTEP 0.05f
+#define STEREO_BITS_TCA ( STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS + STEREO_BITS_TCA_GD )
+
+#define STEREO_ICBWE_MSFLAG_BITS 1 /* BWE Multi Source flag */
+
+#define STEREO_ICBWE_REFBITS 1
+#define STEREO_ICBWE_SPBITS 2
+#define STEREO_ICBWE_GSBITS 4
+#define STEREO_BITS_ICBWE ( STEREO_ICBWE_SPBITS + STEREO_ICBWE_GSBITS + STEREO_ICBWE_REFBITS )
+
+#define STEREO_ICBWE_SPBITS_DFT 2
+#define STEREO_ICBWE_GSBITS_DFT 7
+#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 MAX_INTERPOLATE 11
+#define ADDED_MEM_DS 40
+
+#define STEREO_L_TCA_OVLP_NS 5000000L /* overlap length of the ICA gain scaling */
+
+
+/*----------------------------------------------------------------------------------*
+ * TD Stereo Constants
+ *----------------------------------------------------------------------------------*/
+
+#define TDM_NQ ( 32 - 1 ) /* number of quantization steps of mixing factor */
+#define LRTD_STEREO_LEFT_IS_PRIM ( TDM_NQ - 1 ) /* Ratio index value indicating that left channel is coded as primary channel */
+#define LRTD_STEREO_RIGHT_IS_PRIM 0 /* Ratio index value indicating that right channel is coded as primary channel */
+#define LRTD_STEREO_QUARTER_RANGE ( ( TDM_NQ + 1 ) / 4 ) /* Ratio index value */
+#define LRTD_STEREO_MID_IS_PRIM ( ( TDM_NQ - 1 ) / 2 ) /* Ratio index value */
+
+#define TDM_L_NOVA_NS 5000000L /* mixing overlap length */
+
+#define TDM_SECONDARY_SIGNALLING 3 /* number of bits to code the signaling for secondary channel */
+#define TDM_RATIO_BITS 5 /* number of bits to code the correlation ratio */
+#define TDM_LP_REUSE_BITS 1 /* number of bits to code LP reuse flag for secondary channel */
+#define TDM_LR_CONTENT_BITS 1 /* number of bits to code flag when the content is LR or not */
+#define TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS + STEREO_BITS_TCA )
+#define TDM_IC_LSF_PRED_BITS 1 /* number of bits to code the inter channel LSF prediction mode */
+
+
+/*----------------------------------------------------------------------------------*
+ * MDCT Stereo Constants
+ *----------------------------------------------------------------------------------*/
+
+/* MDCT stereo modes */
+#define SMDCT_MS_DECISION 0
+
+#define MAX_SFB 70 /* Maximum number of stereo frequency bands = 64 + 6 for TCX after ACELP */
+
+#define SMDCT_DUAL_MONO 0 /* Dual-mono MDCT Stereo */
+#define SMDCT_MS_FULL 1 /* MS MDCT Stereo */
+#define SMDCT_BW_MS 2 /* Band-wise MS MDCT Stereo */
+
+#define SMDCT_MINIMUM_ARITH_BITS 17 /* Minimum bits to reserve for the arithmetic coder */
+#define SMDCT_GLOBAL_ILD_BITS 4
+#define SMDCT_ILD_RANGE ( 1 << SMDCT_GLOBAL_ILD_BITS ) /* Range of the coded ILD */
+#define SMDCT_NBBITS_SPLIT_RATIO 3
+#define SMDCT_BITRATE_RATIO_RANGE ( 1 << SMDCT_NBBITS_SPLIT_RATIO ) /* Range of the coded bitrate distribution ratio */
+#define SMDCT_EQUAL_RATIO_RANGE ( SMDCT_BITRATE_RATIO_RANGE >> 1 )
+
+#define SMDCT_MAX_STEREO_BANDS_TCX20 44
+#define SMDCT_MAX_STEREO_BANDS_TCX10 33
+
+#define MAX_MDCT_ITD_BRATE IVAS_64k
+
+#define SNS_LOW_BR_MODE -1
+#define SNS_NPTS 16 /* Number of downsampled SNS parameters */
+#define SNS_STEREO_MODE_LR 0
+#define SNS_STEREO_MODE_MS 1
+#define SNS_STEREO_MODE_OFFSET_INDICES 4
+#define SNS_MSVQ_NSTAGES_TCX20 4
+#define SNS_MSVQ_NSTAGES_TCX10 3
+#define SNS_MSVQ_NSTAGES_SIDE 2
+#define SNS_CDBKS_BITS_4_FRAC 12
+#define SNS_MEANS_BITS_4_FRAC 14
+
+#define MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG 0.001f
+#define MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME 2 * FRAMES_PER_SEC
+#define MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN 20
+#define MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE 3
+
+typedef enum {
+ NOISE_GEN_MODE_UNDEF = -1,
+ EQUAL_CORES = 0,
+ TCX10_IN_0_TCX20_IN_1,
+ TCX20_IN_0_TCX10_IN_1,
+} TONALMDCTCONC_NOISE_GEN_MODE;
+
+typedef enum {
+ ON_FIRST_LOST_FRAME,
+ ON_FIRST_GOOD_FRAME,
+} TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE;
+
+
+/*----------------------------------------------------------------------------------*
+ * MDFT FB Constants
+ *----------------------------------------------------------------------------------*/
+
+#define MDFT_FB_BANDS_240 240
+#define CLDFB_TO_MDFT_FAC 4
+#define MDFT_NO_COL_MAX 4
+
+/*----------------------------------------------------------------------------------*
+ * General Parametric Coding Constants
+ *----------------------------------------------------------------------------------*/
+
+#define MAX_PARAM_SPATIAL_SUBFRAMES 4 /* Maximum number of subframes for parameteric spatial coding */
+#define L_SPATIAL_SUBFR_48k (L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES)
+#define CLDFB_SLOTS_PER_SUBFRAME ( CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) /* Number of CLDFB slots per subframe */
+
+
+/*----------------------------------------------------------------------------------*
+ * SBA Constants
+ *----------------------------------------------------------------------------------*/
+
+#define SBA_FOA_ORDER 1
+#define SBA_HOA2_ORDER 2
+#define SBA_HOA3_ORDER 3
+
+#define SBA_PLANAR_BITS 1
+#define SBA_ORDER_BITS 2
+
+#define SBA_MIN_BRATE_HOA IVAS_256k
+#define SBA_NHARM_HOA3 16
+#define SBA_T_DESIGN_11_SIZE 70
+#define SBA_DTX_BITRATE_THRESHOLD IVAS_80k
+
+/*----------------------------------------------------------------------------------*
+ * DirAC Constants
+ *----------------------------------------------------------------------------------*/
+
+#define DIRAC_MAX_ANA_CHANS 11 /* Maximum number of channels for DirAC analysis */
+
+#define DIRAC_NUM_DIMS 3 /* number of directions to estimate (X,Y,Z) */
+#define DIRAC_MAX_NBANDS 12 /* Maximum number of frequency bands for the DirAC Side Parameter decoding */
+#define DIRAC_LOW_BANDRES_STEP 2 /* always combine two bands for low band resolution in the DirAC parameter coding */
+#define DIRAC_NO_COL_AVG_DIFF 32 /* Number of slots for averaging intensity vector for diffuseness computation */
+#define DIRAC_DIFFUSE_LEVELS 8 /* Size of the diffuseness alphabet (constant value) */
+#define DIRAC_DITH_SEED 29680
+#define DIRAC_MAX_BITS 512 /* Maximum number of bits for DirAC side information per frame */
+#define MAX_NUM_ENC_CLDFB_INSTANCES 8 /* Maximum Cldfb instances in DirAC encoder */
+#define DIRAC_NO_COL_AVG_DIFF_NS 40000000L
+#define DIRAC_NO_FB_BANDS_MAX MDFT_FB_BANDS_240
+#define DELAY_DIRAC_ENC_CMP_NS_PARAM_ISM ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) /* == 12 ms */
+
+#define DIRAC_HO_NUMSECTORS 2
+#define NUM_ANA_SECTORS 2
+
+
+/* DirAC renderer setup */
+typedef enum
+{
+ DIRAC_SYNTHESIS_INVALID,
+ DIRAC_SYNTHESIS_PSD_LS, /* PSD renderer in loudspeakers domain */
+ DIRAC_SYNTHESIS_GAIN_SHD, /* Gain renderer in Spherical Harmonic Domain*/
+ DIRAC_SYNTHESIS_PSD_SHD, /* PSD renderer in Spherical Harmonic Domain*/
+ DIRAC_SYNTHESIS_MONO,
+ DIRAC_SYNTHESIS_COV_MC_LS
+} DIRAC_SYNTHESIS_CONFIG;
+
+/* DirAC renderer panning setup */
+typedef enum
+{
+ DIRAC_PANNING_INVALID,
+ DIRAC_PANNING_HOA3, /* HOA3 */
+ DIRAC_PANNING_VBAP /* VBAP */
+} DIRAC_PANNING_CONFIG;
+
+#define DIRAC_DIFF_NUM_AMBI_COMP 4
+#define DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS 8
+#define DIRAC_GAIN_LIMIT 31.622776601683793f /* 30db gain limitiation */
+#define DIRAC_MAX_NUM_DECORR_FILTERS 22
+#define DIRAC_MAX_DECORR_FILTER_LEN 20
+#define DIRAC_DECORR_NUM_SPLIT_BANDS 3
+#define DIRAC_DECORR_FILTER_LEN_1 15
+#define DIRAC_DECORR_FILTER_LEN_2 6
+#define DIRAC_DECORR_FILTER_LEN_3 3
+#define DIRAC_ONSET_ALPHA 0.95f
+#define DIRAC_ONSET_BETA 0.995f
+#define DIRAC_ONSET_GAIN 4.0f
+
+#define DELAY_DIRAC_ENC_CMP_NS 9500000L /* Delay to be compensated on DirAC encoder */
+#define DELAY_DIRAC_SPAR_ENC_CMP_NS 500000L /* here we may set the 24 samples (at 48 kHz) additional delay to something else, leave as is for now*/
+#define DELAY_DIRAC_PARAM_DEC_SFR 2 /* Delay to be compensation for DirAC parameters in the decoder (subframes) */
+
+#define DELAY_MASA_PARAM_DEC_SFR 2 /* Delay to be compensation for MASA parameters in the decoder (subframes) */
+#define SPH_IDX_FRONT ( MASA_NO_POINTS_EQUATOR / 2 ) /* Spherical index corresponding to front direction for setting as default value */
+
+#define DIRAC_SLOT_NS 1250000L /* time duration of a time slot, 1.25ms (==DELAY_RENERER_NS/MAX_PARAM_SPATIAL_SUBFRAMES) */
+#define DIRAC_SLOT_ENC_NS 5000000L
+
+#define DIRAC_MONO_THRESH_SILENCE 3e4f
+#define DIRAC_MONO_NORM_FACTOR 1e13f
+#define DIRAC_MONO_ONE_ON_NORM_FACTOR (1.f / 1e13f)
+#define DIRAC_MONO_MAX_THRESH 1e6f
+#define DIRAC_MONO_MIN_THRESH 1e2f
+#define DIRAC_MONO_FRAME_THRESH 15 /* 30ms */
+
+typedef enum
+{
+ DIRAC_OPEN, /* initialize to default value */
+ DIRAC_RECONFIGURE, /* HOA3 */
+ DIRAC_RECONFIGURE_MODE
+} DIRAC_CONFIG_FLAG;
+
+
+/*----------------------------------------------------------------------------------*
+ * SPAR constants
+ *----------------------------------------------------------------------------------*/
+
+#define SPAR_CONFIG_BW FB
+
+#define IVAS_SPAR_MAX_CH ((( IVAS_MAX_SBA_ORDER ) * ( IVAS_MAX_SBA_ORDER )) + 2) /* HOA2 + pHOA3*/
+#define IVAS_HBR_MAX_DECOR_CHS (2)
+
+#define IVAS_SPAR_MAX_FB_IN_CHAN 11
+
+#define IVAS_SPAR_P_LOWERTRI ((IVAS_SPAR_MAX_CH - 1) * (IVAS_SPAR_MAX_CH - 2)) >> 1
+#define IVAS_SPAR_MAX_C_COEFF (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * ( IVAS_SPAR_MAX_DMX_CHS - 1)
+
+#define IVAS_SPAR_HOA3_NP_CHS 8 /* number of higher order non-planar channels */
+
+#define SPAR_NUM_CODING_STRAT_BITS 3
+
+/* AGC constants */
+#define AGC_BITS_PER_CH 3
+#define AGC_EMAX 0
+#define AGC_SIGNALLING_BITS 1
+#define IVAS_SPAR_ARITH_OVERSHOOT_BITS 16
+
+/* Common SPAR metadata constants */
+#define IVAS_ACTIVEW_DM_F_SCALE 0.5f
+#define IVAS_ACTIVEW_DM_F_SCALE_DTX 0.25f
+#define IVAS_ACTIVEW_DM_F_SCALE_VLBR 0.25f
+#define IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN 24000
+
+#define IVAS_SPAR_DYN_ACTIVEW_THRESH (0.0039f)
+#define IVAS_SPAR_SIDE_CH_DYN_ACTIVEW_THRESH (32.0f)
+
+#define MAX_QUANT_STRATS 3
+#define MAX_CODING_STRATS 3
+#define IVAS_NUM_PROB_MODELS 4
+#define IVAS_MAX_INPUT_LEN ( IVAS_MAX_NUM_BANDS * ( IVAS_SPAR_P_LOWERTRI ) )
+#define IVAS_MAX_QUANT_LEVELS 32
+#define BRATE_SPAR_Q_STRAT IVAS_256k
+
+#define SPAR_SID_BITS_TAR_PER_BAND 18
+
+typedef enum
+{
+ WYXZ = 0,
+ WY = 0,
+ WX,
+ WZ,
+ WYiX,
+} ivas_spar_pmx_strings_t;
+
+#define NUM_MD_Q_COEFS_SET 4
+
+#define IVAS_RED_BAND_FACT 2
+
+typedef enum
+{
+ PRED_COEFF = 0,
+ DRCT_COEFF,
+ DECD_COEFF,
+ DECX_COEFF
+} ivas_coeffs_type_t;
+
+#define IVAS_SPAR_BR_TABLE_LEN 20
+
+/* TD decorr */
+enum
+{
+ IVAS_TD_DECORR_OUT_1CH = 1,
+ IVAS_TD_DECORR_OUT_2CH,
+ IVAS_TD_DECORR_OUT_3CH,
+ IVAS_TD_DECORR_OUT_4CH,
+ IVAS_TD_DECORR_OUT_5CH,
+ IVAS_TD_DECORR_OUT_6CH,
+ IVAS_TD_DECORR_OUT_7CH,
+ IVAS_TD_DECORR_OUT_8CH
+};
+
+#define IVAS_SPAR_MAX_DMX_CHS 4
+#define IVAS_MAX_DECORR_CHS IVAS_TD_DECORR_OUT_8CH
+#define IVAS_MAX_DECORR_APD_SECTIONS 16
+#define IVAS_APD_2_SECT 2
+#define IVAS_APD_4_SECT 4
+#define IVAS_APD_8_SECT 8
+#define IVAS_APD_16_SECT 16
+
+#define IVAS_DECORR_PARM_LOOKAHEAD_TAU 2e-3f
+#define IVAS_DECORR_PARM_APD_TAU 20e-3f
+
+/* IVAS SBA PCA */
+#define IVAS_PCA_NB_SUBR 20 /* 80 -> 0.25 ms, 40 -> 0.5 ms... */
+#define IVAS_PCA_COV_THRES 3e-5f
+#define IVAS_PCA_QUAT_EPS 1e-7f
+#define IVAS_PCA_QBITS 19
+#define IVAS_PCA_N1 91
+#define IVAS_PCA_N1_EQ ( (IVAS_PCA_N1-1)/2 )
+#define IVAS_PCA_BIT_LEN ( 1 + ( IVAS_PCA_QBITS - 1 + IVAS_PCA_QBITS ) )
+#define IVAS_PCA_INTERP 4
+#define IVAS_PCA_N_SLOTS 40
+#define IVAS_PCA_LEN_INTERP_Q ( IVAS_PCA_INTERP * IVAS_PCA_N_SLOTS )
+#define IVAS_PCA_DELAY_CMP 24
+#define IVAS_PCA_LEN_INTERP_EIG_DEC ( (IVAS_PCA_N_SLOTS+IVAS_PCA_DELAY_CMP)*16)
+#define IVAS_PCA_THRES_MIN_DOT 0.8f
+#define IVAS_PCA_THRES_MIN_DOT2 0.0f
+#define IVAS_PCA_THRES_DIST_ALT 6.0f
+
+typedef enum
+{
+ PCA_MODE_ACTIVE = 0,
+ PCA_MODE_INACTIVE = 1
+} ivas_pca_bypass_mode;
+
+enum
+{
+ PRED_Q_1 = 0,
+ PRED_Q_7,
+ PRED_Q_15,
+ PRED_Q_21,
+ PRED_Q_31,
+ PRED_Q_7_ACTIVE_W,
+ TOTAL_PRED_QUANT_STRATS_HUFF = 5,
+ PRED_Q_15_ACTIVE_W,
+ PRED_Q_21_ACTIVE_W,
+ TOTAL_PRED_QUANT_STRATS_ARITH
+ };
+
+enum
+{
+ DRCT_Q_1 = 0,
+ DRCT_Q_7,
+ DRCT_Q_9,
+ DRCT_Q_11,
+ TOTAL_DRCT_QUANT_STRATS
+ };
+
+enum
+{
+ DECD_Q_1 = 0,
+ DECD_Q_3,
+ DECD_Q_5,
+ DECD_Q_7,
+ DECD_Q_9,
+ DECD_Q_11,
+ TOTAL_DECD_QUANT_STRATS
+ };
+
+/*----------------------------------------------------------------------------------*
+ * MASA constants
+ *----------------------------------------------------------------------------------*/
+
+#define MAX_NO_THETA 19
+#define NO_THETA16_MAX 122 /* number of theta values for 16 bits */
+#define NO_SPHERICAL_GRIDS 11 /* number of spherical grid structures */
+
+#define MASA_FREQUENCY_BANDS 24
+#define MASA_MAXIMUM_CODING_SUBBANDS 24
+#define MASA_MAXIMUM_DIRECTIONS 2
+#define MASA_MAX_TRANSPORT_CHANNELS 2
+
+
+#define MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS 5
+
+#define MASA_DELTA_AZI_DCT0 30
+#define MASA_DELTA_AZI_DCT 10
+
+#define MASA_TRANSP_BITS 1
+#define NO_BITS_MASA_ISM_NO_OBJ 2
+#define MASA2TOTAL_THR 0.98f
+#define BITS_MASA2TOTTAL_DCT0 6
+#define STEP_M2T 0.1f
+#define MASA_HEADER_BITS 2
+#define MASA_SUBFRAME_BITS 1
+#define MASA_LOWBITRATE_MODE_BITS 1
+#define MASA_FACTOR_CV_COH 6
+
+#define MASA_GR_ORD_EL 1
+#define MASA_GR_ORD_AZ 2
+
+#define MASA_DIRECTION_MAX_BITS 11
+#define MASA_NO_INDEX 32767
+#define MASA_BITS_ER 3
+#define MASA_BITS_ER_HR 4
+#define MASA_MIN_BITS_TF 4
+#define MASA_LIMIT_2D 2
+#define MASA_NO_CV_COH 8
+#define MASA_NO_CV_COH1 5
+#define MASA_MAX_NO_CV_SUR_COH 8
+#define MASA_NO_CB_SUR_COH 7
+#define MASA_MIN_BITS_SURR_COH 12
+
+#define MASA_SUM_FREQ_RANGE_BINS 25 /* Constant for MASA transport signal type detection */
+#define MASA_HI_FREQ_START_BIN 14 /* Constant for MASA transport signal type detection */
+#define MASA_STEREO_INTERPOLATION_SLOTS 16 /* The number of slots to interpolate when changing MASA transport signal type */
+#define MASA_SUM_PROTO_START_BIN 7 /* Constant for Ambisonics rendering from MASA */
+
+#define QMETADATA_MAXBIT_REQ_MASA 900 /* max bit-bit/direction for avoiding requantization in MASA path */
+#define QMETADATA_MAXBIT_REQ_SBA 400 /* max bit-bit/direction for avoiding requantization in SBA path */
+#define MASA_COH_LIMIT_2IDX 96 /* limit for sum of values across components for having two joint indexes */
+#define QMETADATA_MAX_NO_DIRECTIONS 2
+#define MASA_MAX_BITS 1300 /* max. bit-budget for MASA metadata */
+
+#define MASA_MAX_BITS_HR 2000 /* max. bit-budget for MASA metadata in HR mode*/
+#define HR_MASA_ER_LEVELS 16
+#define MAX_REDUCED_NBANDS 18 /* max number of subbands that is less than the default value 24 */
+
+#define LIMIT_ER_ELEVATION_ENC 4
+#define LIMIT_ER_SIMPLE_ENC 6
+#define LIMIT_USE_COMMON 3
+
+#define MASA_COHERENCE_TOLERANCE 0.1f
+#define MASA_COHERENCE_THRESHOLD 0.1f
+#define MASA_RATIO_TOLERANCE 0.1f
+#define MASA_RATIO_THRESHOLD 0.1f
+#define MASA_ANGLE_TOLERANCE 0.5f
+#define MASA_LIMIT_NO_BANDS_SUR_COH 8
+#define MINIMUM_BIT_BUDGET_NORMAL_META 100
+#define DIFF_DFRATIO_2BIT_LIMIT_IDX_HODIRAC 4
+#define DIFF_DFRATIO_2BIT_LIMIT_IDX 3
+
+#define DIFF_DFRATIO_1BIT_LIMIT_IDX 6
+#define DIFF_EC_HUFF_BAND_LIMIT 8
+#define DIFF_EC_HUFF_GR0_LIMIT 8
+#define VAR_AZI_THRESH 25
+#define MASA_LIMIT_IDX_AVG_AZI 4
+
+#define MASA_NO_POINTS_EQUATOR 430
+#define MASA_NO_CIRCLES 121
+#define MASA_ASIN_OFFSET 0.0064471690266724975f
+#define MASA_NTOT2_FAC 32768.00566947353f
+#define MASA_ANGLE_AT_EQUATOR 0.012894427382667f
+#define MASA_ANGLE_AT_EQUATOR_DEG 0.738796268264740f
+#define MASA_INV_ANGLE_AT_EQUATOR_DEG 1.353553128183453f
+#define MASA_STEREO_MIN_BITRATE IVAS_24k4
+#define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */
+#define OMASA_STEREO_SW_CNT_MAX 100
+
+#define MASA_BIT_REDUCT_PARAM 10
+#define MASA_MAXIMUM_TWO_DIR_BANDS 24
+#define NBITS_HR_COH 4
+
+#define MASA_JBM_RINGBUFFER_FRAMES 3
+
+typedef enum
+{
+ MASA_STEREO_NOT_DEFINED,
+ MASA_STEREO_SPACED_MICS,
+ MASA_STEREO_DOWNMIX
+} MASA_TRANSPORT_SIGNAL_TYPE;
+
+typedef enum
+{
+ MASA_FRAME_1SF,
+ MASA_FRAME_4SF
+} MASA_FRAME_MODE;
+
+
+/*----------------------------------------------------------------------------------*
+ * Multichannel format
+ *----------------------------------------------------------------------------------*/
+
+#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 */
+
+typedef enum
+{
+ MC_MODE_NONE,
+ MC_MODE_MCT,
+ MC_MODE_PARAMMC,
+ MC_MODE_MCMASA,
+ MC_MODE_PARAMUPMIX
+} MC_MODE;
+
+typedef enum
+{
+ MC_LS_SETUP_5_1,
+ MC_LS_SETUP_7_1,
+ MC_LS_SETUP_5_1_2,
+ MC_LS_SETUP_5_1_4,
+ MC_LS_SETUP_7_1_4,
+ MC_LS_SETUP_INVALID
+} MC_LS_SETUP;
+
+
+/*----------------------------------------------------------------------------------*
+ * McMASA constants
+ *----------------------------------------------------------------------------------*/
+
+#define MCMASA_SEPARATE_BRATE IVAS_64k /* minimum bitrate from which separated channel coding is supported */
+
+#define MCMASA_MAX_ANA_CHANS 11 /* Maximum number of channels currently used in analysis of multichannel formats */
+#define MCMASA_MONOBITRATIO 0.3f
+#define MCMASA_MONOBITRATIO_64k 0.25f
+#define MC_MASA_THR_ELEVATION 40
+
+#define MCMASA_LFE_QLOW -6.5f
+#define MCMASA_LFE_DELTA 1.0f
+#define MCMASA_LFE_1BIT_THRES 0.03f
+#define MCMASA_LFE_ALPHA 0.67f
+#define MCMASA_LFE_BETA 0.09f
+#define MCMASA_LFE_THETA 1.3f
+#define MCMASA_LFE_SYNTH_ALPHA 0.95f /* Smoothing coefficient for LFE synthesis */
+
+#define NUM_ELEVATED_SPEAKERS 4
+
+#define MCMASA_MIN_SPEAKERS_SEPARATE_CENTER 4
+
+/*----------------------------------------------------------------------------------*
+ * MCT constants
+ *----------------------------------------------------------------------------------*/
+
+#define LFE_CHANNEL 3
+
+#define MIN_LFE_NRG 0.5f
+#define MCT_MAX_CHANNELS MAX_TRANSPORT_CHANNELS
+#define MCT_MAX_BLOCKS ( MCT_MAX_CHANNELS / CPE_CHANNELS ) /* max. number of channel pairs (MCT_MAX_CHANNELS/2) within MCT*/
+
+#define MAX_NUM_DATA max( MCT_MAX_CHANNELS, 4 )
+
+#define NBBITS_MCT_RATIO 4
+#define BITRATE_MCT_RATIO_RANGE ( 1 << NBBITS_MCT_RATIO ) /* Range of the coded bitrate distribution ratio */
+
+#define MCT_NUM_BLOCK_DATA_BITS 4
+
+typedef enum
+{
+ MCT_CHAN_MODE_REGULAR,
+ MCT_CHAN_MODE_IGNORE
+} MCT_CHAN_MODE;
+
+
+/*----------------------------------------------------------------------------------*
+ * MC Param-Upmix Mode Constants
+ *----------------------------------------------------------------------------------*/
+
+#define MC_PARAMUPMIX_MAX_TRANSPORT_CHANS 8
+#define MC_PARAMUPMIX_MAX_INPUT_CHANS 12
+#define MC_PARAMUPMIX_MAX_BITS 1024 /* Maximum number of bits for the MC Param-Upmix metadata */
+#define MC_PARAMUPMIX_COMBINATIONS 4 /* number of sets of 2 channels combined */
+#define MC_PARAMUPMIX_NCH 2 /* number of channels to combine into 1 */
+#define MC_PARAMUPMIX_MIN_CLDFB 8
+
+typedef enum _COV_SMOOTHING_TYPE
+{
+ COV_SMOOTH_SPAR,
+ COV_SMOOTH_MC
+} COV_SMOOTHING_TYPE;
+
+typedef struct {
+ const int32_t *value;
+ const uint16_t *length;
+} HUFF_TAB;
+
+typedef struct {
+ int32_t value[81];
+ unsigned short length[81];
+} HUFF_ELEMENTS;
+
+typedef struct {
+ HUFF_ELEMENTS df0;
+ HUFF_ELEMENTS df;
+ HUFF_ELEMENTS dt;
+} HUFF_TABLE;
+
+typedef enum {
+ ALPHA,
+ BETA
+} PAR_TYPE;
+
+typedef enum {
+ FINE,
+ COARSE
+} QUANT_TYPE;
+
+typedef struct {
+ int16_t nquant;
+ int16_t offset;
+ float data[35];
+} ACPL_QUANT_TABLE;
+
+typedef struct
+{
+ const int16_t (*alpha[2])[2];
+ const int16_t (*beta[2])[2];
+} HUFF_NODE_TABLE;
+
+
+/*----------------------------------------------------------------------------------*
+ * Parametric MC Constants
+ *----------------------------------------------------------------------------------*/
+
+typedef enum
+{
+ PARAM_MC_SYNTH_DIRECT, /* synthesis to the transport format */
+ PARAM_MC_SYNTH_LS_CONV_COV, /* loudspeaker format conversion in the covariance domain */
+ PARAM_MC_SYNTH_LS_CONV_CLDFB, /* loudspeaker format conversion in the CLDFB domain */
+ PARAM_MC_SYNTH_MONO_STEREO /* synthesis to mono or stereo */
+} PARAM_MC_SYNTHESIS_CONF;
+
+#define PARAM_MC_REG_SX (0.2f) /* Regularization factor for mixing matrix calculation */
+#define PARAM_MC_REG_GHAT (0.001f) /* Regularization factor for mixing matrix calculation */
+#define PARAM_MC_MAX_PARAMETER_BANDS 20 /* Maximum number of parameter bands */
+#define PARAM_MC_MAX_PARAMETER_BANDS_RES 14 /* Maximum number of parameter bands with decorrelation */
+#define PARAM_MC_MAX_NSLOTS MAX_JBM_CLDFB_TIMESLOTS /* Maximum number of CLDFB slots in a frame */
+#define PARAM_MC_MAX_NSLOTS_IN_SUBFRAME 4 /* Maximum number of CLDFB slots in a subframe */
+#define PARAM_MC_NSUBFRAMES_DEC 4 /* Number of subframes for the synthesis in the decoder */
+#define PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND 30 /* Maximum number of CLDFB frequency bands within a parameter band */
+#define PARAM_MC_PARAMETER_FRAMES 2 /* Number of frames a parameter set for a parameter band is used*/
+#define PARAM_MC_ICC_ERROR_BIAS_FAC (1.15f) /* factor for favouring past ICC maps in the adaptive ICC map decision */
+#define PARAM_MC_TRANSIENT_BAND_STEP 2 /* Number of parameter bands combined in case of a transient frame*/
+#define PARAM_MC_MAX_DECORR_CLDFB_BANDS 20 /* Maximum number of CLDFB bands with decorrelation */
+#define PARAM_MC_MAX_TRANSPORT_CHANS 4 /* Number of down mix channels */
+#define PARAM_MC_MAX_ILD_REF_CHANNELS 2 /* Maximum number of reference channels for a coded ILD */
+#define PARAM_MC_NUM_CONFIGS 15 /* Number of available Parametric MC configurations */
+#define PARAM_MC_MAX_BAND_LFE 1 /* Number of parameter bands for LFE coding */
+#define PARAM_MC_SZ_ICC_MAP 11 /* Maximum number of transmitted ICCs per parameter band */
+#define PARAM_MC_SZ_ILD_MAP 12 /* Maximum number of transmitted channel energies per band*/
+#define PARAM_MC_MAX_VAL_MAP_SIZE 12 /* Maximum number of transmitted parameters per band */
+#define PARAM_MC_RANGE_CODER_TOT_SHIFT 16 /* resolution of the range coder frequency tables */
+#define PARAM_MC_SZ_ICC_QUANTIZER 8 /* Length of the ICC quantizer for Parametric MC */
+#define PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT 3 /* Number of bits for ICC uniform coding */
+#define PARAM_MC_SZ_ILD_QUANTIZER_4BITS 16 /* Length of the ILD quantizer for Parametric MC */
+#define PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT 4 /* Number of bits for ILD uniform coding */
+#define PARAM_MC_DEFAULT_MIN_ILD (-92.0f) /* Default relative channel level for untransmitted channel energies */
+#define PARAM_MC_MAX_BITS 1024 /* Maximum number of bits for the Parametric MC metadata */
+#define PARAM_MC_MAX_BAND_ABS_COV_ENC 10
+#define PARAM_MC_MAX_PARAM_BAND_ABS_COV_ENC 10
+#define PARAM_MC_MAX_BAND_ABS_COV_DEC 10
+#define PARAM_MC_ENER_LIMIT_INTRAFRAME (1.5f)
+#define PARAM_MC_ENER_LIMIT_INTERFRAME (2.0f)
+#define PARAM_MC_ENER_LIMIT_MAX_DELTA_FAC (15.0f)
+#define PARAM_MC_NUM_ATTACK_ILD_THRESH (3)
+#define PARAM_MC_LFE_ON_THRESH (8000.0f)
+#define PARAM_MC_BAND_TO_MDCT_BAND_RATIO 16 /* Ratio of resolution of CLDFB Bands to MDCT Bands */
+#define PARAM_MC_SLOT_ENC_NS 2500000L
+#define PARAM_MC_MDFT_NO_SLOTS 8
+#define PARAM_MC_CLDFB_TO_MDFT_FAC 2
+
+/*----------------------------------------------------------------------------------*
+ * LFE Coding Constants
+ *----------------------------------------------------------------------------------*/
+
+#define IVAS_LFE_ID_BITS 1
+
+typedef enum
+{
+ IVAS_FILTER_STAGE_0,
+ IVAS_FILTER_STAGE_1,
+ IVAS_FILTER_MAX_STAGES /* this becomes array len while declaring the array */
+} LFE_FILTERS_STAGES;
+
+/* IIR filter orders */
+typedef enum
+{
+ IVAS_FILTER_ORDER_1 = 1,
+ IVAS_FILTER_ORDER_2 = 2,
+ IVAS_FILTER_ORDER_4 = 4,
+} ivas_filter_order;
+
+#define IVAS_BIQUAD_FILT_LEN 3
+#define IVAS_LFE_FADE_LEN_48K 384
+#define IVAS_LFE_FADE_LEN_32K 256
+#define IVAS_LFE_FADE_LEN_16K 128
+#define IVAS_LFE_FADE_LEN_8K 64
+#define IVAS_LFE_SHIFTS_PER_DOUBLE 4
+#define IVAS_LFE_NUM_COEFFS_IN_SUBGRP 2
+#define IVAS_LFE_MAX_NUM_DCT_PASS_BINS 8
+#define IVAS_LFE_MAX_NUM_DCT_COEFFS (IVAS_LFE_MAX_NUM_DCT_PASS_BINS * IVAS_LFE_NUM_COEFFS_IN_SUBGRP)
+#define IVAS_LFE_FADE_NS 8000000L /* 8.0 ms */
+#define IVAS_MAX_NUM_QUANT_STRATS 2
+#define IVAS_MAX_NUM_DCT_COEF_GROUPS 4
+#define IVAS_LFE_SHIFT_BITS 5
+#define IVAS_LFE_BITRATE_5000 5000
+#define IVAS_LFE_ABS_SUM_FLT_THR (0.000001f)
+#define IVAS_ZERO_PAD_LEN_MULT_FAC (0.5f)
+
+/* LFE PLC */
+#define LFE_PLC_BUFLEN 240
+#define LFE_PLC_FS 1600
+#define L_FRAME_1k6 ( 20 * LFE_PLC_FS / 1000 )
+#define LFE_PLC_LENANA LFE_PLC_BUFLEN
+#define LFE_PLC_FDEL 300
+
+
+/*----------------------------------------------------------------------------------*
+ * Amplitude Panning (EFAP, VBAP) constants
+ *----------------------------------------------------------------------------------*/
+
+#define PANNING_AZI_RESOLUTION 2
+#define PANNING_ELE_RESOLUTION 5
+
+#define EFAP_MAX_CHAN_NUM 5 /* Maximum number of channels that constitute a polygon, 4 or 5 */
+#define EFAP_MAX_POLY_SET 50 /* Upper bound on number of polygons; with a Speaker setup of 16.0, we obtain 44 polygons/triangles in the matlab implementation. */
+
+#define EFAP_MODE_EFAP 0 /* EFAP Panning */
+#define EFAP_MODE_EFIP 1 /* EFIP Panning */
+
+typedef enum
+{
+ EFAP_DMX_NONE,
+ EFAP_DMX_AMPLITUDE,
+ EFAP_DMX_INTENSITY
+} EFAP_VTX_DMX_TYPE;
+
+
+#define VBAP_NUM_SEARCH_SECTORS 4
+
+
+/*----------------------------------------------------------------------------------*
+ * Binaural Rendering Constants
+ *----------------------------------------------------------------------------------*/
+
+#define BINAURAL_MAXBANDS 60 /* Max number of bands */
+#define BINAURAL_CONVBANDS 50 /* Bands upto which convolution is performed */
+#define BINAURAL_NTAPS 3
+#define BINAURAL_NTAPS_SBA BINAURAL_NTAPS
+
+#define BINAURAL_NTAPS_MAX 96
+
+#define HRTF_SH_ORDER 3
+#define HRTF_SH_CHANNELS HOA3_CHANNELS
+#define HRTF_LS_CHANNELS 15
+#define HRTF_NUM_BINS 60
+#define REVERB_PREDELAY_MAX 20 /* Max input delay for reverb module */
+#define GAIN_LFE 1.88364911f /* Gain applied to LFE during renderering */
+#define LOW_BIT_RATE_BINAURAL_EQ_BINS 17 /* Number of bins in an EQ applied at low bit rates in binauralization */
+#define LOW_BIT_RATE_BINAURAL_EQ_OFFSET 14 /* Offset of bins where the low-bit-rate EQ starts*/
+
+#define BINAURAL_COHERENCE_DIFFERENCE_BINS 9 /* Number of bins for direction-dependent diffuse-field binaural coherence */
+
+typedef enum
+{
+ BINAURAL_INPUT_AUDIO_CONFIG_INVALID,
+ BINAURAL_INPUT_AUDIO_CONFIG_COMBINED, /* 5_1, 5_1_2, 5_1_4, 7_1, 7_1_4 */
+ BINAURAL_INPUT_AUDIO_CONFIG_HOA3, /* HOA3 */
+ BINAURAL_INPUT_AUDIO_CONFIG_HOA2, /* HOA2 */
+ BINAURAL_INPUT_AUDIO_CONFIG_FOA, /* FOA */
+ BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED /* Not used */
+
+} BINAURAL_INPUT_AUDIO_CONFIG;
+
+#define HEADROT_ORDER 3
+#define HEADROT_SHMAT_DIM ( ( HEADROT_ORDER + 1 ) * ( HEADROT_ORDER + 1 ) )
+#define HEADROT_SHMAT_DIM2 ( HEADROT_SHMAT_DIM * HEADROT_SHMAT_DIM )
+
+
+
+
+/*----------------------------------------------------------------------------------*
+ * TD Binaural Object renderer
+ *----------------------------------------------------------------------------------*/
+
+#define MAX_NUM_TDREND_CHANNELS MAX_CICP_CHANNELS /* max. number of channels in TD renderer (objects or loudspeaker channels) */
+
+#define SFX_SPAT_BIN_MAX_NO_OF_OUTPUT_SAMPLES 288 /* 288 = 6 msec @ 48 kHz. */
+#define HRTF_MODEL_N_SECTIONS 3 /* No. sections used in approximate evaluation of model */
+#define HRTF_MODEL_BSPLINE_NUM_COEFFS 4 /* No. BSpline coefficients, including zeroth order e.g. cubic -> 4 */
+#define HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ 16 /* Square of HRTF_MODEL_BSPLINE_NUM_COEFFS */
+#define SFX_SPAT_BIN_MAX_FILTER_LENGTH 256
+
+#define SPAT_BIN_MAX_INPUT_CHANNELS 1 /* Max number of input channels per source/object. Mono for now, but stereo objects may be considered. */
+#define MAX_ITD 50
+#define SFX_SPAT_BIN_SINC_M 5
+#define SFX_SPAT_BIN_NUM_SUBSAMPLES 64
+#define ITD_MEM_LEN (MAX_ITD + SFX_SPAT_BIN_SINC_M)
+#define L_SUBFRAME5MS_48k (L_FRAME48k/4)
+#define MAX_ANGULAR_STEP (0.01f)
+#define MAX_ANGULAR_STEP_INV ( 1.0f / MAX_ANGULAR_STEP )
+#define MAX_INTERPOLATION_STEPS 12
+
+#define LR_IAC_LENGTH_NR_FC ( RV_LENGTH_NR_FC )
+
+/* ----- Enums - TD Renderer ----- */
+
+typedef enum
+{
+ TDREND_DIST_ATTEN_MODEL_INV_DIST,
+ TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED
+} TDREND_DistAttenModel_t;
+
+typedef enum
+{
+ TDREND_POSTYPE_ABSOLUTE, /* The source position is in absolute coordinates */
+ TDREND_POSTYPE_NON_DIEGETIC /* The source position is non-diegetic */
+} TDREND_PosType_t;
+
+typedef enum
+{
+ TDREND_PLAYSTATUS_INITIAL,
+ TDREND_PLAYSTATUS_PLAYING
+} TDREND_PlayStatus_t;
+
+typedef enum
+{
+ TDREND_DeallocIndex_None,
+ TDREND_DeallocIndex_Signal,
+ TDREND_DeallocIndex_Source
+} TDREND_DeallocFnIndex;
+
+typedef enum
+{
+ TDREND_HRFILT_Method_BSplineModel
+} TDREND_HRFILT_Method_t;
+
+typedef enum
+{
+ SFX_ON,
+ SFX_TRANSIENT,
+ SFX_OFF
+} SFX_OpMode_t;
+
+
+
+/*----------------------------------------------------------------------------------*
+ * Reverberator constants
+ *----------------------------------------------------------------------------------*/
+
+#define IVAS_REV_MAX_NR_BRANCHES 8 /* setup is for maximum */
+#define IVAS_REV_MAX_IIR_FILTER_LENGTH 4 /* maximum nr of taps - MUST BE EVEN! */
+
+#define RV_FILTER_MAX_FFT_SIZE ( 512 )
+#define RV_FILTER_MAX_HISTORY ( 512 - 160 ) /* for longest history */
+#define RV_LENGTH_NR_FC ( RV_FILTER_MAX_FFT_SIZE / 2 ) + 1
+
+#define IVAS_REVERB_DEFAULT_N_BANDS 31
+
+
+/*----------------------------------------------------------------------------------*
+ * FB mixer constants
+ *----------------------------------------------------------------------------------*/
+
+#define IVAS_960_PT_LEN 960
+#define IVAS_640_PT_LEN 640
+#define IVAS_480_PT_LEN 480
+#define IVAS_320_PT_LEN 320
+#define IVAS_240_PT_LEN 240
+#define IVAS_160_PT_LEN 160
+#define IVAS_120_PT_LEN 120
+#define IVAS_80_PT_LEN 80
+#define IVAS_40_PT_LEN 40
+
+/* FB windows ovlp */
+#define IVAS_FB_4MS_48K_SAMP 192
+#define IVAS_FB_1MS_48K_SAMP 48
+#define IVAS_FB_4MS_32K_SAMP 128
+#define IVAS_FB_1MS_32K_SAMP 32
+#define IVAS_FB_4MS_16K_SAMP 64
+#define IVAS_FB_1MS_16K_SAMP 16
+
+#define IVAS_MAX_FB_MIXER_OUT_CH IVAS_SPAR_MAX_CH
+#define IVAS_MAX_SPAR_FB_MIXER_IN_CH IVAS_SPAR_MAX_CH
+#define IVAS_MAX_FB_MIXER_IN_CH MAX_CICP_CHANNELS
+
+#define MAX_NUM_BANDS_DIFF_NON48K 3
+
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0 ( 0 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1 ( 0 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_2 ( 0 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_3 ( 0 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_4 ( 0 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_5 ( 9 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_6 ( 7 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_7 ( 0 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_8 ( 0 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_9 ( 49 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_10 ( 172 )
+#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_11 ( 377 )
+
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_0 ( 179 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_1 ( 160 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_2 ( 215 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_3 ( 200 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_4 ( 186 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_5 ( 196 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_6 ( 230 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_7 ( 351 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_8 ( 456 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_9 ( 617 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_10 ( 892 )
+#define IVAS_FB_12_1MS_48K_END_BINS_BAND_11 ( 960 )
+
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_0 ( 0 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_1 ( 0 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_2 ( 0 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_3 ( 0 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_4 ( 0 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_5 ( 9 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_6 ( 7 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_7 ( 0 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_8 ( 0 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_9 ( 49 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_10 ( 172 )
+#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_11 ( 377 )
+
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_0 ( 179 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_1 ( 160 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_2 ( 215 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_3 ( 200 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_4 ( 186 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_5 ( 196 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_6 ( 230 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_7 ( 351 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_8 ( 456 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_9 ( 617 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_10 ( 640 )
+#define IVAS_FB_12_1MS_32K_END_BINS_BAND_11 ( 640 )
+
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_0 ( 0 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_1 ( 0 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_2 ( 0 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_3 ( 0 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_4 ( 0 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_5 ( 9 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_6 ( 7 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_7 ( 0 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_8 ( 0 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_9 ( 49 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_10 ( 172 )
+#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_11 ( 320 )
+
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_0 ( 179 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_1 ( 160 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_2 ( 215 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_3 ( 200 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_4 ( 186 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_5 ( 196 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_6 ( 230 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_7 ( 320 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_8 ( 320 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_9 ( 320 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_10 ( 320 )
+#define IVAS_FB_12_1MS_16K_END_BINS_BAND_11 ( 320 )
+
+#define IVAS_FB_BANDS_12 12
+#define IVAS_FB_BANDS_20 20
+#define IVAS_MAX_NUM_BANDS IVAS_FB_BANDS_12
+#define IVAS_MAX_NUM_FB_BANDS IVAS_FB_BANDS_20
+#define IVAS_FB_12_1MS_LEN ( IVAS_FB_12_1MS_48K_END_BINS_BAND_0 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_1 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_2 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_2 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_3 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_3 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_4 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_4 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_5 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_5 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_6 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_6 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_7 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_7 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_8 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_8 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_9 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_9 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_10 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_10 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_11 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_11 )
+#define IVAS_16K_12BANDS_ACTIVE_BANDS 10
+
+#define SPAR_DIRAC_SPLIT_START_BAND 8
+#define DIRAC_TO_SPAR_HBR_PRED_CHS (FOA_CHANNELS - 1)
+#define SPAR_DTX_BANDS 2
+#define DIRAC_DTX_BANDS 2
+#define SPAR_DIRAC_DTX_BANDS ( SPAR_DTX_BANDS + DIRAC_DTX_BANDS )
+#define CLDFB_PAR_WEIGHT_START_BAND 7
+
+#define QUANT_STRAT_0 0
+#define QUANT_STRAT_2 2
+
+
+/*----------------------------------------------------------------------------------*
+ * Limiter constants
+ *----------------------------------------------------------------------------------*/
+
+#define IVAS_LIMITER_THRESHOLD 32729 /* -0.01 dBFS */
+#define IVAS_LIMITER_ATTACK_SECONDS 0.005f
+
+
+/*----------------------------------------------------------------------------------*
+ * Early Reflection constants
+ *----------------------------------------------------------------------------------*/
+
+#define ER_ABS_COEFF 6
+#define ER_MAX_SOURCES 25
+#define ER_REF_ORDER 1
+#define ER_NUM_REF 6
+
+#define ER_AIR_COEFF (0.00137f)
+#define ER_SOUND_SPEED (343.0f)
+#define ER_MIN_WALL_DIST (0.1f)
+#define ER_EUCLIDEAN_SCALE (1.29246971E-26f)
+
+#define ER_DEFAULT_ROOM_L (3.0f)
+#define ER_DEFAULT_ROOM_W (4.0f)
+#define ER_DEFAULT_ROOM_H (5.0f)
+#define ER_RADIUS (1.0f)
+#define ER_LIST_ORIGIN_X (0.0f)
+#define ER_LIST_ORIGIN_Y (0.0f)
+#define ER_LIST_HEIGHT (1.6f)
+
+#define ER_MIN_ROOM_DIMENSION (1.0f)
+#define ER_MAX_ROOM_DIMENSION (999.0f)
+#define ER_MIN_ABS_COEFF (0.0f)
+#define ER_MAX_ABS_COEFF (1.0f)
+
+
+/*----------------------------------------------------------------------------------*
+ * Stereo downmix EVS constants
+ *----------------------------------------------------------------------------------*/
+
+#define STEREO_DMX_EVS_PHA_LEN_16 48
+#define STEREO_DMX_EVS_FAD_LEN_16 160
+#define STEREO_DMX_EVS_PHA_LEN_32 96
+#define STEREO_DMX_EVS_FAD_LEN_32 320
+#define STEREO_DMX_EVS_PHA_LEN_48 96
+#define STEREO_DMX_EVS_FAD_LEN_48 480
+
+#define STEREO_DMX_EVS_SUBBAND_SIZE 2
+#define STEREO_DMX_EVS_NB_SUBBAND_MAX (L_FRAME48k / (2 * STEREO_DMX_EVS_SUBBAND_SIZE))
+
+#define STEREO_DMX_EVS_PHA_LEN_MAX 96 /* Max of PHA_LEN */
+#define STEREO_DMX_EVS_FAD_LEN_MAX 480 /* Max of FAD_LEN */
+
+#define STEREO_DMX_EVS_DATA_LEN_MAX (STEREO_DMX_EVS_PHA_LEN_MAX + L_FRAME48k)
+
+typedef enum
+{
+ STEREO_DMX_EVS_PHA_IPD,
+ STEREO_DMX_EVS_PHA_IPD2,
+ STEREO_DMX_EVS_NO_PHA
+
+} STEREO_DMX_EVS_PHA;
+
+typedef enum
+{
+ STEREO_DMX_EVS_PRC_POC,
+ STEREO_DMX_EVS_PRC_PHA,
+
+} STEREO_DMX_EVS_PRC;
+
+#endif
+/* clang-format on */
+/* IVAS_CNST_H */
diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c
new file mode 100644
index 0000000000000000000000000000000000000000..f15b21d7900d30d0a28348d1dba62d95bc6a22b1
--- /dev/null
+++ b/lib_com/ivas_cov_smooth.c
@@ -0,0 +1,359 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_prot.h"
+#include "wmc_auto.h"
+#include "prot.h"
+
+/*-----------------------------------------------------------------------------------------*
+ * Local constants
+ *-----------------------------------------------------------------------------------------*/
+
+#define BAND_SMOOTH_REST_START_IDX ( 2 )
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calculate_update_factor()
+ *
+ * To calculate the update factor
+ *-----------------------------------------------------------------------------------------*/
+
+static float ivas_calculate_update_factor(
+ float *p_bin_to_band,
+ int16_t active_bins )
+{
+ float update_factor_temp = 0.0f;
+ int16_t k;
+
+ for ( k = 0; k < active_bins; k++ )
+ {
+ update_factor_temp += p_bin_to_band[k];
+ }
+
+ return update_factor_temp;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calculate_smoothning_factor()
+ *
+ * To calculate the Smoothning factor
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_calculate_smoothning_factor(
+ float *Smoothing_factor,
+ float update_factor,
+ const int16_t min_pool_size,
+ const float max_update_rate,
+ const COV_SMOOTHING_TYPE smooth_mode,
+ const int32_t ivas_total_brate,
+ int16_t j )
+{
+ float smooth_fact;
+ *Smoothing_factor = update_factor / min_pool_size;
+ if ( smooth_mode != COV_SMOOTH_MC )
+ {
+ if ( ivas_total_brate < IVAS_24k4 )
+ {
+ smooth_fact = 0.5f;
+ }
+ else
+ {
+ smooth_fact = 0.75f;
+ }
+ *Smoothing_factor *= ( j + 1 ) * smooth_fact;
+ }
+
+ if ( *Smoothing_factor > max_update_rate )
+ {
+ *Smoothing_factor = max_update_rate;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_set_up_cov_smoothing()
+ *
+ * Setup for covariance smoothing
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_set_up_cov_smoothing(
+ ivas_cov_smooth_state_t *hCovState,
+ ivas_filterbank_t *pFb,
+ const float max_update_rate,
+ const int16_t min_pool_size,
+ const COV_SMOOTHING_TYPE smooth_mode, /* i : flag multichannel vs SPAR */
+ const int32_t ivas_total_brate )
+{
+ int16_t j;
+ float update_factor;
+ if ( smooth_mode == COV_SMOOTH_MC )
+ {
+ for ( j = 0; j < pFb->filterbank_num_bands; j++ )
+ {
+ int16_t active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j];
+ update_factor = ivas_calculate_update_factor( pFb->fb_bin_to_band.pFb_bin_to_band[j], active_bins );
+ ivas_calculate_smoothning_factor( &hCovState->pSmoothing_factor[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j );
+ }
+ }
+ else
+ {
+ for ( j = 0; j < pFb->filterbank_num_bands; j++ )
+ {
+ float *p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band[j];
+ int16_t active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j];
+ update_factor = ivas_calculate_update_factor( p_bin_to_band, active_bins );
+ ivas_calculate_smoothning_factor( &hCovState->pSmoothing_factor[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j );
+ }
+ }
+
+ hCovState->prior_bank_idx = -1;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_spar_covar_smooth_enc_open()
+ *
+ * Allocate and initialize SPAR Covar. smoothing handle
+ *------------------------------------------------------------------------*/
+
+ivas_error ivas_spar_covar_smooth_enc_open(
+ ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */
+ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */
+ ivas_filterbank_t *pFb, /* i/o: FB handle */
+ const int16_t nchan_inp, /* i : number of input channels */
+ const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ ivas_cov_smooth_state_t *hCovState;
+ int16_t i, j;
+
+ if ( ( hCovState = (ivas_cov_smooth_state_t *) malloc( sizeof( ivas_cov_smooth_state_t ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
+ }
+
+ if ( ( hCovState->pSmoothing_factor = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
+ }
+
+ for ( i = 0; i < nchan_inp; i++ )
+ {
+ for ( j = 0; j < nchan_inp; j++ )
+ {
+ if ( ( hCovState->pPrior_cov_real[i][j] = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
+ }
+ set_zero( hCovState->pPrior_cov_real[i][j], cov_smooth_cfg->max_bands );
+ }
+ }
+
+ ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, smooth_mode, ivas_total_brate );
+
+ *hCovState_out = hCovState;
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_spar_covar_smooth_enc_close()
+ *
+ * Deallocate SPAR Covar. smoothing handle
+ *------------------------------------------------------------------------*/
+
+void ivas_spar_covar_smooth_enc_close(
+ ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */
+ const int16_t nchan_inp /* i : number of input channels */
+)
+{
+ ivas_cov_smooth_state_t *hCovState;
+ int16_t i, j;
+
+ hCovState = *hCovState_out;
+
+ if ( hCovState != NULL )
+ {
+ free( hCovState->pSmoothing_factor );
+ hCovState->pSmoothing_factor = NULL;
+
+ for ( i = 0; i < nchan_inp; i++ )
+ {
+ for ( j = 0; j < nchan_inp; j++ )
+ {
+ free( hCovState->pPrior_cov_real[i][j] );
+ hCovState->pPrior_cov_real[i][j] = NULL;
+ }
+ }
+
+ free( hCovState );
+ hCovState_out = NULL;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_compute_smooth_cov()
+ *
+ * Compute smooth covariance real/imag.
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_compute_smooth_cov(
+ ivas_cov_smooth_state_t *hCovState,
+ ivas_filterbank_t *pFb,
+ float *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ float *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ const float fac,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t num_ch,
+ const int16_t transient_det[2] )
+{
+ int16_t i, j, k;
+ int16_t prev_idx = hCovState->prior_bank_idx;
+ float factor = 0;
+ int16_t sm_b;
+ int16_t non_sm_b_idx;
+ sm_b = BAND_SMOOTH_REST_START_IDX;
+
+ assert( end_band <= pFb->filterbank_num_bands );
+
+ if ( prev_idx == -1 || transient_det[1] == 1 )
+ {
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( k = start_band; k < end_band; k++ )
+ {
+ pCov_buf[i][i][k] += ( hCovState->pSmoothing_factor[k] * fac );
+ }
+ }
+ }
+ else if ( transient_det[0] == 1 )
+ {
+ non_sm_b_idx = min( sm_b, end_band );
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ if ( i == j )
+ {
+ factor = fac;
+ }
+ else
+ {
+ factor = 0.0f;
+ }
+
+ for ( k = start_band; k < non_sm_b_idx; k++ )
+ {
+ pCov_buf[i][j][k] = pPrior_cov_buf[i][j][k] + ( hCovState->pSmoothing_factor[k] * ( pCov_buf[i][j][k] - pPrior_cov_buf[i][j][k] + factor ) );
+ }
+ }
+ }
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( k = non_sm_b_idx; k < end_band; k++ )
+ {
+ pCov_buf[i][i][k] += ( hCovState->pSmoothing_factor[k] * fac );
+ }
+ }
+ }
+ else if ( prev_idx == 0 )
+ {
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ if ( i == j )
+ {
+ factor = fac;
+ }
+ else
+ {
+ factor = 0.0f;
+ }
+
+ for ( k = start_band; k < end_band; k++ )
+ {
+ pCov_buf[i][j][k] = pPrior_cov_buf[i][j][k] + ( hCovState->pSmoothing_factor[k] * ( pCov_buf[i][j][k] - pPrior_cov_buf[i][j][k] + factor ) );
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_cov_smooth_process()
+ *
+ * Covariance smoothing process
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_cov_smooth_process(
+ ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ ivas_filterbank_t *pFb, /* i/o: FB handle */
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t num_ch,
+ const int16_t transient_det[2] )
+{
+ int16_t i, j;
+ int16_t num_bands = end_band - start_band;
+
+ ivas_compute_smooth_cov( hCovState, pFb, cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, num_ch, transient_det );
+
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ mvr2r( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real[i][j][start_band], num_bands );
+ }
+ }
+
+ hCovState->prior_bank_idx = 0;
+
+ return;
+}
diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..22b726f314c24f72afc86f61bf74fb73d28ede2c
--- /dev/null
+++ b/lib_com/ivas_dirac_com.c
@@ -0,0 +1,1008 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "ivas_prot.h"
+#include "prot.h"
+#include "cnst.h"
+#include "wmc_auto.h"
+
+
+/*-----------------------------------------------------------------------*
+ * Local function prototypes
+ *-----------------------------------------------------------------------*/
+
+static uint16_t deindex_sph_idx_general( const int16_t idx_sph, const int16_t no_bits, float *theta_dec, float *phi_dec, uint16_t *p_id_phi, const MC_LS_SETUP mc_format );
+
+
+/*-------------------------------------------------------------------------
+ * ivas_get_hodirac_flag()
+ *
+ * Return flag for HO-DirAC method at high bitrates
+ *------------------------------------------------------------------------*/
+
+/*! r: HO-DirAC flag */
+int16_t ivas_get_hodirac_flag(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+)
+{
+ if ( sba_order > 1 && ivas_total_brate > IVAS_256k )
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_sba_config()
+ *
+ * DirAC Configuration function; used also in MASA decoder
+ *------------------------------------------------------------------------*/
+
+ivas_error ivas_dirac_config(
+ void *st_ivas, /* i/o: IVAS encoder/decoder state structure */
+ const int16_t enc_dec /* i : encoder or decoder flag */
+)
+{
+ IVAS_FORMAT ivas_format;
+ int16_t sba_order;
+ int16_t *element_mode;
+ int32_t ivas_total_brate;
+ DIRAC_CONFIG_DATA_HANDLE hConfig;
+ IVAS_QMETADATA_HANDLE hQMetaData;
+ int32_t Fs;
+ int16_t *band_grouping;
+ ivas_error error;
+ int16_t spar_dirac_split_band;
+ IVAS_FB_MIXER_HANDLE hFbMdft;
+ int16_t *dirac_to_spar_md_bands;
+
+ error = IVAS_ERR_OK;
+
+ if ( enc_dec == ENC )
+ {
+ ivas_format = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->ivas_format;
+ element_mode = &( (Encoder_Struct *) st_ivas )->hEncoderConfig->element_mode_init;
+ sba_order = ( (Encoder_Struct *) st_ivas )->sba_analysis_order;
+ ivas_total_brate = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->ivas_total_brate;
+ Fs = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->input_Fs;
+ band_grouping = ( (Encoder_Struct *) st_ivas )->hDirAC->band_grouping;
+ hConfig = ( (Encoder_Struct *) st_ivas )->hDirAC->hConfig;
+ hQMetaData = ( (Encoder_Struct *) st_ivas )->hQMetaData;
+ if ( ( (Encoder_Struct *) st_ivas )->hSpar != NULL )
+ {
+ hFbMdft = ( (Encoder_Struct *) st_ivas )->hSpar->hFbMixer;
+ dirac_to_spar_md_bands = ( (Encoder_Struct *) st_ivas )->hSpar->dirac_to_spar_md_bands;
+ }
+ else
+ {
+ hFbMdft = NULL;
+ dirac_to_spar_md_bands = NULL;
+ }
+ }
+ else
+ {
+ ivas_format = ( (Decoder_Struct *) st_ivas )->ivas_format;
+ element_mode = &( (Decoder_Struct *) st_ivas )->element_mode_init;
+ sba_order = ( (Decoder_Struct *) st_ivas )->sba_analysis_order;
+ ivas_total_brate = ( (Decoder_Struct *) st_ivas )->hDecoderConfig->ivas_total_brate;
+ Fs = ( (Decoder_Struct *) st_ivas )->hDecoderConfig->output_Fs;
+ band_grouping = ( (Decoder_Struct *) st_ivas )->hDirAC->band_grouping;
+ hConfig = ( (Decoder_Struct *) st_ivas )->hDirAC->hConfig;
+ hQMetaData = ( (Decoder_Struct *) st_ivas )->hQMetaData;
+ if ( ( (Decoder_Struct *) st_ivas )->hSpar != NULL )
+ {
+ hFbMdft = ( (Decoder_Struct *) st_ivas )->hSpar->hFbMixer;
+ dirac_to_spar_md_bands = ( (Decoder_Struct *) st_ivas )->hSpar->dirac_to_spar_md_bands;
+ }
+ else
+ {
+ hFbMdft = NULL;
+ dirac_to_spar_md_bands = NULL;
+ }
+ ( (Decoder_Struct *) st_ivas )->hDirAC->hFbMdft = hFbMdft;
+ }
+
+ if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
+ {
+ hConfig->nbands = IVAS_MAX_NUM_BANDS;
+
+ spar_dirac_split_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
+
+ if ( ivas_get_hodirac_flag( ivas_total_brate, sba_order ) )
+ {
+ spar_dirac_split_band = 0;
+ }
+ }
+ else
+ {
+ hConfig->nbands = 5;
+ spar_dirac_split_band = 0;
+ }
+ hConfig->enc_param_start_band = 0;
+ hConfig->dec_param_estim = FALSE;
+ if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) /* skip for MASA decoder */
+ {
+ if ( ( error = ivas_dirac_sba_config( hQMetaData, element_mode, ivas_total_brate, sba_order, hConfig->nbands - spar_dirac_split_band ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( hQMetaData != NULL )
+ {
+ if ( enc_dec == ENC )
+ {
+ hConfig->nbands = hQMetaData->q_direction[0].cfg.nbands;
+ }
+ hConfig->enc_param_start_band = hQMetaData->q_direction[0].cfg.start_band + spar_dirac_split_band;
+ }
+
+ hConfig->dec_param_estim = TRUE;
+ if ( hConfig->dec_param_estim == TRUE )
+ {
+ hConfig->enc_param_start_band = spar_dirac_split_band;
+ }
+
+ if ( ivas_get_hodirac_flag( ivas_total_brate, sba_order ) )
+ {
+ hConfig->dec_param_estim = FALSE;
+ hConfig->enc_param_start_band = 0;
+
+ set_c( (int8_t *) hQMetaData->twoDirBands, (int8_t) 1, hQMetaData->q_direction[0].cfg.nbands );
+ hQMetaData->numTwoDirBands = (uint8_t) hQMetaData->q_direction[0].cfg.nbands;
+ }
+ }
+
+ if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
+ {
+ ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft );
+ }
+ else
+ {
+ ivas_dirac_config_bands( band_grouping, hConfig->nbands, (int16_t) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), NULL, 0, 0, hFbMdft );
+ }
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_sba_config_bands()
+ *
+ * DirAC Configuration freq. band function; used also in MASA decoder
+ *------------------------------------------------------------------------*/
+
+void ivas_dirac_config_bands(
+ int16_t *band_grouping, /* o : band grouping */
+ const int16_t nbands, /* i : number of bands */
+ const int16_t max_band, /* i : maximal band index +1 */
+ int16_t *dirac_to_spar_md_bands,
+ const int8_t useLowerBandRes,
+ const int16_t enc_param_start_band,
+ IVAS_FB_MIXER_HANDLE hFbMdft )
+{
+ int16_t i;
+ {
+ if ( nbands == 5 )
+ {
+ mvs2s( DirAC_band_grouping_5, band_grouping, 5 + 1 );
+ }
+ else if ( nbands == 6 )
+ {
+ mvs2s( DirAC_band_grouping_6, band_grouping, 6 + 1 );
+ }
+ else if ( nbands == 12 )
+ {
+ int16_t band;
+ for ( band = 0; band < DIRAC_MAX_NBANDS; band++ )
+ {
+ dirac_to_spar_md_bands[band] = band;
+ }
+ if ( hFbMdft != NULL )
+ {
+ int16_t sb, idx1, idx2, b;
+
+ idx1 = -1;
+ sb = 0;
+ for ( b = 0; b < max_band; b++ )
+ {
+ idx2 = hFbMdft->pFb->fb_bin_to_band.p_cldfb_map_to_spar_band[b];
+ if ( idx2 > idx1 )
+ {
+ band_grouping[sb++] = b;
+ idx1 = idx2;
+ }
+ }
+ band_grouping[sb] = max_band;
+
+ /* set the remaining bands to max_band to avoid problems for the DirAC parameter estimation with bw < FB */
+ for ( b = sb; b <= nbands; b++ )
+ {
+ band_grouping[b] = max_band;
+ }
+ }
+ else
+ {
+ mvs2s( DirAC_band_grouping_12, band_grouping, 12 + 1 );
+ }
+
+ if ( useLowerBandRes )
+ {
+ int16_t step = DIRAC_LOW_BANDRES_STEP;
+ int16_t reduced_band;
+ for ( band = enc_param_start_band + 2, reduced_band = enc_param_start_band + 1; band <= DIRAC_MAX_NBANDS; band += step, reduced_band++ )
+ {
+ band_grouping[reduced_band] = band_grouping[band];
+ }
+ for ( ; reduced_band <= DIRAC_MAX_NBANDS; reduced_band++ )
+ {
+ band_grouping[reduced_band] = max_band;
+ }
+ for ( band = enc_param_start_band + ( DIRAC_MAX_NBANDS - enc_param_start_band ) / 2 - 1, reduced_band = DIRAC_MAX_NBANDS - 1; band >= enc_param_start_band; band--, reduced_band -= step )
+ {
+ dirac_to_spar_md_bands[reduced_band] = dirac_to_spar_md_bands[band];
+ dirac_to_spar_md_bands[reduced_band - 1] = dirac_to_spar_md_bands[band];
+ }
+ }
+ else
+ {
+ /* always code the last two fb bands together */
+ band_grouping[DIRAC_MAX_NBANDS - 1] = max_band;
+ dirac_to_spar_md_bands[DIRAC_MAX_NBANDS - 1] = DIRAC_MAX_NBANDS - 2;
+ }
+ }
+ else
+ {
+ assert( 0 && "nbands must be 5 or 6!" );
+ }
+ }
+
+ /* Limit the band range to band max */
+ for ( i = 0; i < nbands + 1; i++ )
+ {
+ if ( band_grouping[i] > max_band )
+ {
+ band_grouping[i] = max_band;
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * ivas_get_dirac_sba_max_md_bits()
+ *
+ * Return maximum SBA DirAC metadata bit-budget and nominal bit-budget
+ *-------------------------------------------------------------------*/
+
+void ivas_get_dirac_sba_max_md_bits(
+ const int32_t sba_total_brate,
+ int16_t *bits_frame_nominal,
+ int16_t *metadata_max_bits,
+ int16_t *qmetadata_max_bit_req,
+ const int16_t nbands )
+{
+ if ( sba_total_brate <= IVAS_13k2 )
+ {
+ *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC;
+ *metadata_max_bits = 70;
+ }
+ else if ( sba_total_brate <= IVAS_16k4 )
+ {
+ *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC;
+ *metadata_max_bits = 80;
+ }
+ else if ( sba_total_brate <= IVAS_24k4 )
+ {
+ *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC;
+ *metadata_max_bits = 103;
+ }
+ else if ( sba_total_brate <= IVAS_32k )
+ {
+ *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC;
+ *metadata_max_bits = 214;
+ }
+ else if ( sba_total_brate <= IVAS_48k )
+ {
+ *bits_frame_nominal = IVAS_48k / FRAMES_PER_SEC;
+ *metadata_max_bits = 240;
+ }
+ else if ( sba_total_brate <= IVAS_64k )
+ {
+ *bits_frame_nominal = IVAS_64k / FRAMES_PER_SEC;
+ *metadata_max_bits = 200;
+ }
+ else if ( sba_total_brate <= IVAS_80k )
+ {
+ *bits_frame_nominal = IVAS_80k / FRAMES_PER_SEC;
+ *metadata_max_bits = 200;
+ }
+ else if ( sba_total_brate <= IVAS_96k )
+ {
+ *bits_frame_nominal = IVAS_96k / FRAMES_PER_SEC;
+ *metadata_max_bits = 200;
+ }
+ else if ( sba_total_brate <= IVAS_128k )
+ {
+ *bits_frame_nominal = IVAS_128k / FRAMES_PER_SEC;
+ *metadata_max_bits = 250;
+ }
+ else
+ {
+ *bits_frame_nominal = (int16_t) ( sba_total_brate / FRAMES_PER_SEC );
+ *metadata_max_bits = MAX16B; /* no limit */
+ }
+ *metadata_max_bits = (int16_t) min( (float) MAX16B, ceilf( (float) *metadata_max_bits * nbands / 5 ) );
+ *qmetadata_max_bit_req = QMETADATA_MAXBIT_REQ_SBA >> 1;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_sba_config()
+ *
+ * DirAC Configuration function for SBA
+ *------------------------------------------------------------------------*/
+
+ivas_error ivas_dirac_sba_config(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ int16_t *element_mode, /* i/o: element mode of the core coder */
+ int32_t sba_total_brate, /* i : SBA total bitrate */
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int16_t nbands /* i : number of frequency bands */
+)
+{
+ int16_t nbands_coded;
+ int16_t hodirac_flag;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+ hQMetaData->is_masa_ivas_format = 0;
+ hodirac_flag = ivas_get_hodirac_flag( sba_total_brate, sba_order );
+
+ /* map the bitrate for SID frame */
+ if ( sba_total_brate == IVAS_SID_5k2 )
+ {
+ if ( *element_mode == IVAS_SCE )
+ {
+ sba_total_brate = ACELP_24k40;
+ }
+ else
+ {
+ sba_total_brate = ACELP_48k;
+ }
+ }
+
+ ivas_set_qmetadata_maxbit_req( hQMetaData, SBA_FORMAT );
+
+ if ( sba_total_brate <= IVAS_16k4 )
+ {
+ hQMetaData->useLowerRes = 1;
+ }
+ else
+ {
+ hQMetaData->useLowerRes = 0;
+ }
+
+ nbands_coded = nbands;
+ if ( sba_total_brate <= (int32_t) ( (float) IVAS_192k / (float) SPAR_DIRAC_SPLIT_START_BAND ) )
+ {
+ hQMetaData->useLowerBandRes = 1;
+ nbands_coded = nbands / 2 + nbands % 2;
+ }
+ else
+ {
+ hQMetaData->useLowerBandRes = 0;
+ if ( hodirac_flag == 0 )
+ {
+ nbands_coded = nbands - 1; /* always combine the last two bands */
+ }
+ }
+
+ {
+ int16_t no_dirs = 1;
+ if ( hodirac_flag )
+ {
+ no_dirs = 2;
+ }
+
+ if ( ( error = ivas_qmetadata_allocate_memory( hQMetaData, nbands_coded, no_dirs, 0 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ ivas_get_dirac_sba_max_md_bits( sba_total_brate, &hQMetaData->bits_frame_nominal, &hQMetaData->metadata_max_bits, &hQMetaData->qmetadata_max_bit_req, hQMetaData->q_direction[0].cfg.nbands );
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------------
+ * computeDirectionVectors()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+void computeDirectionVectors(
+ float *intensity_real_x,
+ float *intensity_real_y,
+ float *intensity_real_z,
+ const int16_t enc_param_start_band,
+ const int16_t num_frequency_bands,
+ float *direction_vector_x,
+ float *direction_vector_y,
+ float *direction_vector_z )
+{
+ int16_t i;
+ float intensityNorm;
+
+ for ( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; ++i )
+ {
+ intensityNorm = *( intensity_real_x ) * *( intensity_real_x ) +
+ *( intensity_real_y ) * *( intensity_real_y ) +
+ *( intensity_real_z ) * *( intensity_real_z );
+
+ if ( intensityNorm <= EPSILON )
+ {
+ intensityNorm = 1.0f;
+ *( direction_vector_x++ ) = 1.0f;
+ *( direction_vector_y++ ) = 0.0f;
+ *( direction_vector_z++ ) = 0.0f;
+ intensity_real_x++;
+ intensity_real_y++;
+ intensity_real_z++;
+ }
+ else
+ {
+ intensityNorm = sqrtf( 1.f / intensityNorm );
+ *( direction_vector_x++ ) = *( intensity_real_x++ ) * intensityNorm;
+ *( direction_vector_y++ ) = *( intensity_real_y++ ) * intensityNorm;
+ *( direction_vector_z++ ) = *( intensity_real_z++ ) * intensityNorm;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * computeDiffuseness()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+void computeDiffuseness(
+ float *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF],
+ const float *buffer_energy,
+ const int16_t num_freq_bands,
+ float *diffuseness )
+{
+ float intensity_slow[DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX];
+ float intensity_slow_abs[CLDFB_NO_CHANNELS_MAX];
+ float energy_slow[CLDFB_NO_CHANNELS_MAX];
+ int16_t i, j, k;
+ float tmp = 0;
+ float *p_tmp;
+ const float *p_tmp_c;
+
+ /* Compute Intensity slow and energy slow */
+
+ set_f( intensity_slow, 0.0f, DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX );
+ set_f( intensity_slow_abs, 0.0f, CLDFB_NO_CHANNELS_MAX );
+ set_f( energy_slow, 0.0f, CLDFB_NO_CHANNELS_MAX );
+
+ for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i )
+ {
+ /* Energy slow */
+ p_tmp_c = buffer_energy + i * num_freq_bands;
+ for ( k = 0; k < num_freq_bands; k++ )
+ {
+ energy_slow[k] += *( p_tmp_c++ );
+ }
+
+ /* Intensity slow */
+ for ( j = 0; j < DIRAC_NUM_DIMS; ++j )
+ {
+ p_tmp = buffer_intensity[j][i];
+
+ for ( k = 0; k < num_freq_bands; k++ )
+ {
+ intensity_slow[j * num_freq_bands + k] += *( p_tmp++ );
+ }
+ }
+ }
+
+ /* intensity_slow.^2 + intensity_slow_abs*/
+ for ( j = 0; j < DIRAC_NUM_DIMS; ++j )
+ {
+ p_tmp = intensity_slow + j * num_freq_bands;
+
+ for ( k = 0; k < num_freq_bands; k++ )
+ {
+ *( p_tmp ) *= ( *p_tmp );
+ intensity_slow_abs[k] += *( p_tmp++ );
+ }
+ }
+
+ /* Compute Diffuseness */
+ p_tmp = intensity_slow_abs;
+ for ( i = 0; i < num_freq_bands; ++i )
+ {
+ tmp = sqrtf( *( p_tmp++ ) ) / ( energy_slow[i] + EPSILON );
+ tmp = 1.0f - tmp;
+ diffuseness[i] = ( ( tmp < 1.0f ) ? ( ( tmp < 0.0f ) ? 0.f : tmp ) : 1.0f );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * deindex_azimuth()
+ *
+ * Deindex one azimuth index
+ *-------------------------------------------------------------------*/
+
+/*! r: azimuth value */
+float deindex_azimuth(
+ int16_t id_phi, /* i : index */
+ const int16_t no_bits, /* i : number of bits for the spherical grid */
+ const int16_t id_th, /* i : elevation index */
+ const int16_t remap, /* i : remapping flag */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+)
+{
+ int16_t flag_delta;
+ float dd, delta_phi;
+ float phi_hat;
+
+ if ( ( mc_format != MC_LS_SETUP_INVALID ) && ( no_bits == 2 ) )
+ {
+ if ( id_phi % 2 == 0 )
+ {
+ phi_hat = cb_azi_chan[id_phi / 2];
+ }
+ else
+ {
+ phi_hat = -cb_azi_chan[( id_phi + 1 ) / 2];
+ }
+ return phi_hat;
+ }
+ flag_delta = ( id_th % 2 == 1 );
+
+ if ( remap )
+ {
+ id_phi = ivas_qmetadata_dereorder_generic( id_phi ) + ( no_phi_masa[no_bits - 1][id_th] >> 1 );
+ }
+
+ delta_phi = 360 / (float) ( no_phi_masa[no_bits - 1][id_th] );
+ if ( ( flag_delta == 1 ) && ( no_phi_masa[no_bits - 1][id_th] > 2 ) && mc_format == MC_LS_SETUP_INVALID )
+ {
+ dd = delta_phi / 2.0f;
+ }
+ else
+ {
+ dd = 0;
+ }
+
+ id_phi -= ( ( no_phi_masa[no_bits - 1][id_th] ) >> 1 );
+ phi_hat = id_phi * delta_phi + dd + 180 - 180;
+ if ( mc_format != MC_LS_SETUP_INVALID )
+ {
+ phi_hat = companding_azimuth( phi_hat, mc_format, ( id_th * delta_theta_masa[no_bits - 3] > MC_MASA_THR_ELEVATION ), -1 );
+ }
+
+ return phi_hat;
+}
+
+
+/*----------------------------------------------------------------
+ * deindex_spherical_component()
+ *
+ * decoding the spherical index for one tile
+ *-----------------------------------------------------------------*/
+
+void deindex_spherical_component(
+ const uint16_t sph_idx, /* i : spherical index */
+ float *az, /* o : decoded azimuth value */
+ float *el, /* o : decoded elevation value */
+ uint16_t *az_idx, /* o : azimuth index */
+ uint16_t *el_idx, /* o : elevation index */
+ const uint16_t no_bits, /* i : number of bits for the spherical grid */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+)
+{
+ assert( sph_idx < ( 1 << no_bits ) );
+ switch ( no_bits )
+ {
+ case 0:
+ *az = 0;
+ *el = 0;
+ *az_idx = 0;
+ *el_idx = 0;
+ break;
+ case 1:
+ *az_idx = sph_idx;
+ *az = ( *az_idx ) * ( -180.f );
+ *el = 0;
+ *el_idx = 0;
+ break;
+ case 2:
+ *el = 0;
+ *el_idx = 0;
+ *az_idx = sph_idx;
+ *az = deindex_azimuth( *az_idx, no_bits, 0, 0, mc_format );
+ break;
+ default:
+ *el_idx = deindex_sph_idx_general( sph_idx, no_bits, el, az, az_idx, mc_format );
+ break;
+ }
+
+ return;
+}
+
+
+/*----------------------------------------------------------------
+ * calculate_hodirac_sector_parameters()
+ *
+ *
+ *-----------------------------------------------------------------*/
+
+void calculate_hodirac_sector_parameters(
+ DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */
+ float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */
+ float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */
+ const float beta, /* i : forgetting factor for average filtering */
+ const int16_t *band_grouping, /* i : indices of band groups */
+ const int16_t N_bands, /* i : number of bands (groups) */
+ const int16_t enc_param_start_band, /* i : first band to process */
+ float *azi, /* o : array of sector azimuth angles, flat */
+ float *ele, /* o : array of sector elevation angles, flat */
+ float *diff, /* o : array of sector diffuseness values, flat */
+ float *ene /* o : array of sector energy values, flat */
+)
+{
+ int16_t i_sec, i_bin, i_band;
+ float p_real, p_imag, normI, energy, tmp_diff;
+ float sec_I_vec_x[NUM_ANA_SECTORS];
+ float sec_I_vec_y[NUM_ANA_SECTORS];
+ float sec_I_vec_z[NUM_ANA_SECTORS];
+
+
+ for ( i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ )
+ {
+
+ float *p_sec_I_vec_x = &sec_I_vec_x[i_sec];
+ float *p_sec_I_vec_y = &sec_I_vec_y[i_sec];
+ float *p_sec_I_vec_z = &sec_I_vec_z[i_sec];
+
+ const float *p_c_weights = c_weights;
+
+ float *p_ImagBuffer_0 = ImagBuffer[0];
+ float *p_ImagBuffer_1 = ImagBuffer[1];
+ float *p_ImagBuffer_2 = ImagBuffer[2];
+ float *p_ImagBuffer_3 = ImagBuffer[3];
+ float *p_ImagBuffer_4 = ImagBuffer[4];
+ float *p_ImagBuffer_5 = ImagBuffer[5];
+ float *p_ImagBuffer_6 = ImagBuffer[6];
+ float *p_ImagBuffer_8 = ImagBuffer[8];
+
+ float *p_RealBuffer_0 = RealBuffer[0];
+ float *p_RealBuffer_1 = RealBuffer[1];
+ float *p_RealBuffer_2 = RealBuffer[2];
+ float *p_RealBuffer_3 = RealBuffer[3];
+ float *p_RealBuffer_4 = RealBuffer[4];
+ float *p_RealBuffer_5 = RealBuffer[5];
+ float *p_RealBuffer_6 = RealBuffer[6];
+ float *p_RealBuffer_8 = RealBuffer[8];
+
+ for ( i_band = enc_param_start_band; i_band < N_bands; i_band++ )
+ {
+ float *p_azi = &azi[i_sec * N_bands + i_band];
+ float *p_ele = &ele[i_sec * N_bands + i_band];
+ float *p_ene = &ene[i_sec * N_bands + i_band];
+
+ float *p_diff = &diff[i_sec * N_bands + i_band];
+ float *p_azi_prev = &hDirAC->azi_prev[i_sec * N_bands + i_band];
+ float *p_ele_prev = &hDirAC->ele_prev[i_sec * N_bands + i_band];
+
+ float *p_energy_smth = &hDirAC->energy_smth[i_sec][i_band];
+ float *p_sec_I_vec_smth_x = &hDirAC->sec_I_vec_smth_x[i_sec][i_band];
+ float *p_sec_I_vec_smth_y = &hDirAC->sec_I_vec_smth_y[i_sec][i_band];
+ float *p_sec_I_vec_smth_z = &hDirAC->sec_I_vec_smth_z[i_sec][i_band];
+ *p_sec_I_vec_x = 0.f;
+ *p_sec_I_vec_y = 0.f;
+ *p_sec_I_vec_z = 0.f;
+ energy = 0.f;
+
+ if ( i_sec == 0 )
+ {
+ for ( i_bin = band_grouping[i_band]; i_bin < band_grouping[i_band + 1]; i_bin++ )
+ {
+ float w = *( p_c_weights++ );
+ float sec_w_imag, sec_x_imag, sec_y_imag, sec_z_imag;
+ float sec_w_real, sec_x_real, sec_y_real, sec_z_real;
+
+ sec_w_imag = 1.772454f * *( p_ImagBuffer_0 ) + 1.772454f * *( p_ImagBuffer_1 );
+ sec_x_imag = 1.772454f * *( p_ImagBuffer_3++ ) + 1.023326f * *( p_ImagBuffer_4++ );
+ sec_y_imag = 0.590818f * *( p_ImagBuffer_0++ ) + 1.772454f * *( p_ImagBuffer_1++ ) - 0.590817f * *( p_ImagBuffer_6++ ) - 1.023326f * *( p_ImagBuffer_8++ );
+ sec_z_imag = 1.772454f * *( p_ImagBuffer_2++ ) + 1.023326f * *( p_ImagBuffer_5++ );
+
+ sec_w_real = 1.772454f * *( p_RealBuffer_0 ) + 1.772454f * *( p_RealBuffer_1 );
+ sec_x_real = 1.772454f * *( p_RealBuffer_3++ ) + 1.023326f * *( p_RealBuffer_4++ );
+ sec_y_real = 0.590818f * *( p_RealBuffer_0++ ) + 1.772454f * *( p_RealBuffer_1++ ) - 0.590817f * *( p_RealBuffer_6++ ) - 1.023326f * *( p_RealBuffer_8++ );
+ sec_z_real = 1.772454f * *( p_RealBuffer_2++ ) + 1.023326f * *( p_RealBuffer_5++ );
+
+ p_real = sec_w_real * w;
+ p_imag = sec_w_imag * w;
+
+ *p_sec_I_vec_x += p_real * sec_x_real + p_imag * sec_x_imag;
+ *p_sec_I_vec_y += p_real * sec_y_real + p_imag * sec_y_imag;
+ *p_sec_I_vec_z += p_real * sec_z_real + p_imag * sec_z_imag;
+
+ energy += 0.5f * ( p_real * p_real + p_imag * p_imag + sec_x_real * sec_x_real + sec_x_imag * sec_x_imag +
+ sec_y_real * sec_y_real + sec_y_imag * sec_y_imag +
+ sec_z_real * sec_z_real + sec_z_imag * sec_z_imag );
+ }
+ }
+ else
+ {
+ for ( i_bin = band_grouping[i_band]; i_bin < band_grouping[i_band + 1]; i_bin++ )
+ {
+ float w = *( p_c_weights++ );
+ float sec_w_imag, sec_x_imag, sec_y_imag, sec_z_imag;
+ float sec_w_real, sec_x_real, sec_y_real, sec_z_real;
+
+ sec_w_imag = 1.772454f * *(p_ImagBuffer_0) -1.772454f * *( p_ImagBuffer_1 );
+ sec_x_imag = 1.772454f * *( p_ImagBuffer_3++ ) - 1.023326f * *( p_ImagBuffer_4++ );
+ sec_y_imag = -0.590818f * *( p_ImagBuffer_0++ ) + 1.772454f * *( p_ImagBuffer_1++ ) + 0.590817f * *( p_ImagBuffer_6++ ) + 1.023326f * *( p_ImagBuffer_8++ );
+ sec_z_imag = 1.772454f * *( p_ImagBuffer_2++ ) - 1.023326f * *( p_ImagBuffer_5++ );
+
+ sec_w_real = 1.772454f * *(p_RealBuffer_0) -1.772454f * *( p_RealBuffer_1 );
+ sec_x_real = 1.772454f * *( p_RealBuffer_3++ ) - 1.023326f * *( p_RealBuffer_4++ );
+ sec_y_real = -0.590818f * *( p_RealBuffer_0++ ) + 1.772454f * *( p_RealBuffer_1++ ) + 0.590817f * *( p_RealBuffer_6++ ) + 1.023326f * *( p_RealBuffer_8++ );
+ sec_z_real = 1.772454f * *( p_RealBuffer_2++ ) - 1.023326f * *( p_RealBuffer_5++ );
+
+ p_real = sec_w_real * w;
+ p_imag = sec_w_imag * w;
+
+ *p_sec_I_vec_x += p_real * sec_x_real + p_imag * sec_x_imag;
+ *p_sec_I_vec_y += p_real * sec_y_real + p_imag * sec_y_imag;
+ *p_sec_I_vec_z += p_real * sec_z_real + p_imag * sec_z_imag;
+
+ energy += 0.5f * ( p_real * p_real + p_imag * p_imag + sec_x_real * sec_x_real + sec_x_imag * sec_x_imag +
+ sec_y_real * sec_y_real + sec_y_imag * sec_y_imag +
+ sec_z_real * sec_z_real + sec_z_imag * sec_z_imag );
+ }
+ }
+ if ( hDirAC->firstrun_sector_params )
+ {
+ *p_sec_I_vec_smth_x = *p_sec_I_vec_x;
+ *p_sec_I_vec_smth_y = *p_sec_I_vec_y;
+ *p_sec_I_vec_smth_z = *p_sec_I_vec_z;
+ *p_energy_smth = energy;
+ }
+ else
+ {
+ float w = ( 1.0f - beta );
+ *p_sec_I_vec_smth_x = w * *p_sec_I_vec_x + beta * *p_sec_I_vec_smth_x;
+ *p_sec_I_vec_smth_y = w * *p_sec_I_vec_y + beta * *p_sec_I_vec_smth_y;
+ *p_sec_I_vec_smth_z = w * *p_sec_I_vec_z + beta * *p_sec_I_vec_smth_z;
+ *p_energy_smth = w * energy + beta * *p_energy_smth;
+ }
+
+ if ( energy < EPSILON )
+ {
+ *p_azi = 0.f;
+ *p_ele = 0.f;
+ *p_ene = 0.f;
+ *p_diff = 1.f;
+ }
+ else
+ {
+ normI = sqrtf( *p_sec_I_vec_smth_x * *p_sec_I_vec_smth_x +
+ *p_sec_I_vec_smth_y * *p_sec_I_vec_smth_y +
+ *p_sec_I_vec_smth_z * *p_sec_I_vec_smth_z );
+ *p_azi = atan2f( *p_sec_I_vec_smth_y, *p_sec_I_vec_smth_x ) * _180_OVER_PI;
+ *p_ele = asinf( *p_sec_I_vec_smth_z / ( normI + EPSILON ) ) * _180_OVER_PI;
+ *p_ene = *p_energy_smth;
+ *p_diff = 1.f - normI / ( *p_energy_smth + EPSILON );
+ }
+
+ tmp_diff = *p_diff;
+
+ if ( tmp_diff < 0.0f )
+ {
+ *p_diff = 0.f;
+ }
+ if ( tmp_diff > 0.5f )
+ {
+ if ( hDirAC->firstrun_sector_params )
+ {
+ *p_azi = 0.f;
+ *p_ele = 0.f;
+ }
+ else
+ {
+ *p_azi = 2.f * ( 1.f - tmp_diff ) * *p_azi + ( 2.f * tmp_diff - 1.f ) * *p_azi_prev;
+ *p_ele = 2.f * ( 1.f - tmp_diff ) * *p_ele + ( 2.f * tmp_diff - 1.f ) * *p_ele_prev;
+ }
+ }
+ else
+ {
+ *p_azi_prev = *p_azi;
+ *p_ele_prev = *p_ele;
+ }
+ }
+ }
+
+ hDirAC->firstrun_sector_params = 0;
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * Local functions
+ *-----------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------*
+ * deindex_sph_idx_general()
+ *
+ * deindex the spherical index for more than 2 bits for the spherical grid
+ *----------------------------------------------------------------------*/
+
+/*! r: decoded elevation index */
+static uint16_t deindex_sph_idx_general(
+ const int16_t idx_sph, /* i : spherical index */
+ const int16_t no_bits, /* i : number of bits in the spherical grid*/
+ float *theta_dec, /* o : decoded elevation value */
+ float *phi_dec, /* o : decoded azimuth value */
+ uint16_t *p_id_phi, /* o : decoded azimuth index */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+)
+{
+ int16_t i;
+ uint16_t id_th;
+ int16_t sign_theta;
+ int16_t id_phi;
+ int16_t cum_n[250];
+ int16_t no_th;
+ const int16_t *n;
+
+ id_th = 0;
+ id_phi = 0;
+ sign_theta = 1;
+
+ no_th = no_theta_masa[no_bits - 3];
+ n = no_phi_masa[no_bits - 1];
+ if ( mc_format != MC_LS_SETUP_INVALID )
+ {
+ /* indexing */
+
+ cum_n[0] = n[0];
+ if ( idx_sph >= cum_n[0] )
+ {
+ for ( i = 1; i < no_th; i++ )
+ {
+ cum_n[i] = cum_n[i - 1] + n[i];
+ if ( idx_sph < cum_n[i] )
+ {
+ id_th = i;
+ id_phi = idx_sph - cum_n[i - 1];
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ /* Starting from Equator, alternating positive and negative */
+ cum_n[0] = n[0];
+ if ( idx_sph >= cum_n[0] )
+ {
+ for ( i = 1; i < no_th; i++ )
+ {
+ cum_n[2 * i - 1] = cum_n[2 * i - 2] + n[i];
+
+ if ( idx_sph < cum_n[2 * i - 1] )
+ {
+ id_th = i;
+ sign_theta = 1;
+ id_phi = idx_sph - cum_n[2 * i - 2];
+ break;
+ }
+
+ cum_n[2 * i] = cum_n[2 * i - 1] + n[i];
+
+ if ( idx_sph < cum_n[2 * i] )
+ {
+ id_th = i;
+ sign_theta = -1;
+ id_phi = idx_sph - cum_n[2 * i - 1];
+ break;
+ }
+
+ if ( i == ( no_th - 1 ) )
+ {
+ id_th = i;
+ sign_theta = -1;
+ id_phi = 0; /* idx_sph - cum_n[2*i-1]; */
+ break;
+ }
+ }
+ }
+ }
+
+ if ( id_th == 0 )
+ {
+ id_phi = idx_sph;
+ }
+ else
+ {
+ if ( ( id_th == no_th - 1 ) && ( no_bits > 4 ) )
+ {
+ id_phi = 0;
+ }
+ }
+
+ *theta_dec = id_th * delta_theta_masa[no_bits - 3];
+
+ if ( *theta_dec >= 90 )
+ {
+ *theta_dec = 90.f * sign_theta;
+ *phi_dec = 0;
+ *p_id_phi = 0;
+ }
+ else
+ {
+ *theta_dec *= sign_theta;
+
+ *phi_dec = deindex_azimuth( id_phi, no_bits, id_th, 0, mc_format );
+ *p_id_phi = id_phi;
+ }
+
+ return id_th;
+}
diff --git a/lib_com/ivas_entropy_coder_common.c b/lib_com/ivas_entropy_coder_common.c
new file mode 100644
index 0000000000000000000000000000000000000000..7696932cb033e3cc78967ac444a04d6c61efcdc9
--- /dev/null
+++ b/lib_com/ivas_entropy_coder_common.c
@@ -0,0 +1,455 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_prot.h"
+#include "ivas_rom_com.h"
+#include "math.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_wrap_arround)
+ *
+ * wrap around
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_wrap_arround(
+ int16_t *pArr,
+ const int16_t min_val,
+ const int16_t max_val,
+ const int16_t length )
+{
+ int16_t i;
+
+ for ( i = 0; i < length; i++ )
+ {
+ if ( pArr[i] < min_val )
+ {
+ pArr[i] = max_val - min_val + pArr[i] + 1;
+ }
+ if ( pArr[i] > max_val )
+ {
+ pArr[i] = min_val + pArr[i] - max_val - 1;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_cum_freq_model()
+ *
+ * get cumulative frequency model
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_get_cum_freq_model(
+ const int16_t *pFreq_model,
+ const int16_t length,
+ int16_t *pCum_freq_model )
+{
+ int16_t i;
+
+ pCum_freq_model[length] = 0;
+
+ for ( i = length; i > 0; i-- )
+ {
+ pCum_freq_model[i - 1] = pCum_freq_model[i] + pFreq_model[i];
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_map_num_pred_r_to_idx()
+ *
+ * Map the ivas_arith_pred_r_consts and ivas_huff_pred_r_consts tables
+ *-----------------------------------------------------------------------------------------*/
+
+int16_t ivas_map_num_pred_r_to_idx(
+ const int16_t num_quant_points_pred_r,
+ const int16_t active_w_flag )
+{
+ int16_t pred_r_to_idx = -1;
+ if ( active_w_flag == 0 )
+ {
+ switch ( num_quant_points_pred_r )
+ {
+ case 1:
+ pred_r_to_idx = PRED_Q_1;
+ break;
+ case 7:
+ pred_r_to_idx = PRED_Q_7;
+ break;
+ case 15:
+ pred_r_to_idx = PRED_Q_15;
+ break;
+ case 21:
+ pred_r_to_idx = PRED_Q_21;
+ break;
+ case 31:
+ pred_r_to_idx = PRED_Q_31;
+ break;
+ default:
+ assert( !"Forbidden value for prediction quantization strategy index" );
+ break;
+ }
+ }
+ else
+ {
+ switch ( num_quant_points_pred_r )
+ {
+ case 7:
+ pred_r_to_idx = PRED_Q_7_ACTIVE_W;
+ break;
+ case 15:
+ pred_r_to_idx = PRED_Q_15_ACTIVE_W;
+ break;
+ case 21:
+ pred_r_to_idx = PRED_Q_21_ACTIVE_W;
+ break;
+ default:
+ assert( !"Forbidden value for prediction quantization strategy index" );
+ break;
+ }
+ }
+
+ return pred_r_to_idx;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_map_num_drct_r_to_idx()
+ *
+ * Map the ivas_arith_drct_r_consts and ivas_huff_drct_r_consts tables
+ *-----------------------------------------------------------------------------------------*/
+
+int16_t ivas_map_num_drct_r_to_idx(
+ const int16_t num_quant_points_drct_r )
+{
+ int16_t drct_r_to_idx = -1;
+ switch ( num_quant_points_drct_r )
+ {
+ case 1:
+ drct_r_to_idx = DRCT_Q_1;
+ break;
+ case 7:
+ drct_r_to_idx = DRCT_Q_7;
+ break;
+ case 9:
+ drct_r_to_idx = DRCT_Q_9;
+ break;
+ case 11:
+ drct_r_to_idx = DRCT_Q_11;
+ break;
+ default:
+ assert( !"Forbidden value for DRCT quantization strategy index" );
+ break;
+ }
+ return drct_r_to_idx;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_map_num_decd_r_to_idx()
+ *
+ * Map the ivas_arith_decd_r_consts and ivas_huff_decd_r_consts tables
+ *-----------------------------------------------------------------------------------------*/
+
+int16_t ivas_map_num_decd_r_to_idx(
+ const int16_t num_quant_points_decd_r )
+{
+ int16_t decd_r_to_idx = -1;
+ switch ( num_quant_points_decd_r )
+ {
+ case 1:
+ decd_r_to_idx = DECD_Q_1;
+ break;
+ case 3:
+ decd_r_to_idx = DECD_Q_3;
+ break;
+ case 5:
+ decd_r_to_idx = DECD_Q_5;
+ break;
+ case 7:
+ decd_r_to_idx = DECD_Q_7;
+ break;
+ case 9:
+ decd_r_to_idx = DECD_Q_9;
+ break;
+ case 11:
+ decd_r_to_idx = DECD_Q_11;
+ break;
+ default:
+ assert( !"Forbidden value for DECD quantization strategy index" );
+ break;
+ }
+
+ return decd_r_to_idx;
+}
+
+
+/*---------------------------------------------------------------------------------------- - *
+ * Function ivas_spar_arith_com_init()
+ *
+ * arith coder init
+ *---------------------------------------------------------------------------------------- - */
+
+static void ivas_spar_arith_com_init(
+ ivas_arith_t *pArith,
+ const ivas_freq_models_t *pFreq_models,
+ ivas_arith_t *pArith_diff,
+ const int16_t q_levels,
+ const int16_t enc_dec )
+{
+ int16_t i, j;
+ float sum;
+
+ pArith->vals = pFreq_models->vals;
+ pArith->range = q_levels;
+ pArith->num_models = pFreq_models->num_models;
+ pArith->dyn_model_bits = ivas_get_bits_to_encode( pArith->num_models - 1 );
+ pArith->pFreq_model = pFreq_models->freq_model[0];
+
+ ivas_get_cum_freq_model( pArith->pFreq_model, pArith->range, pArith->cum_freq[0] );
+
+ for ( i = 0; i < pArith->num_models - 1; i++ )
+ {
+ pArith->pAlt_freq_models[i] = pFreq_models->freq_model[i + 1];
+ ivas_get_cum_freq_model( pArith->pAlt_freq_models[i], pArith->range, pArith->cum_freq[i + 1] );
+ }
+
+ if ( enc_dec == ENC )
+ {
+ sum = 0;
+ for ( i = 1; i < pArith->range + 1; i++ )
+ {
+ sum += pArith->pFreq_model[i];
+ }
+
+ for ( i = 1; i < pArith->range + 1; i++ )
+ {
+ pArith->saved_dist_arr[0][i - 1] = log2f( max( 1e-10f, pArith->pFreq_model[i] ) );
+ pArith->saved_dist_arr[0][i - 1] -= log2f( max( 1e-10f, sum ) );
+ }
+
+ for ( j = 0; j < pArith->num_models - 1; j++ )
+ {
+ sum = 0;
+ for ( i = 1; i < pArith->range + 1; i++ )
+ {
+ sum += pArith->pAlt_freq_models[j][i];
+ }
+
+ for ( i = 1; i < pArith->range + 1; i++ )
+ {
+ pArith->saved_dist_arr[j + 1][i - 1] = log2f( max( 1e-10f, pArith->pAlt_freq_models[j][i] ) );
+ pArith->saved_dist_arr[j + 1][i - 1] -= log2f( max( 1e-10f, sum ) );
+ }
+ }
+ }
+
+ pArith_diff->vals = pFreq_models->diff_vals;
+ pArith_diff->range = q_levels;
+ pArith_diff->num_models = pFreq_models->diff_num_models;
+ pArith_diff->dyn_model_bits = ivas_get_bits_to_encode( pArith_diff->num_models - 1 );
+ pArith_diff->pFreq_model = pFreq_models->diff_freq_model[0];
+
+ ivas_get_cum_freq_model( pArith_diff->pFreq_model, pArith_diff->range, pArith_diff->cum_freq[0] );
+
+ for ( i = 0; i < pArith_diff->num_models - 1; i++ )
+ {
+ pArith_diff->pAlt_freq_models[i] = pFreq_models->diff_freq_model[i + 1];
+ ivas_get_cum_freq_model( pArith_diff->pAlt_freq_models[i], pArith_diff->range, pArith_diff->cum_freq[i + 1] );
+ }
+
+ if ( enc_dec == ENC )
+ {
+ sum = 0;
+ for ( i = 1; i < pArith_diff->range + 1; i++ )
+ {
+ sum += pArith_diff->pFreq_model[i];
+ }
+
+ for ( i = 1; i < pArith_diff->range + 1; i++ )
+ {
+ pArith_diff->saved_dist_arr[0][i - 1] = log2f( max( 1e-10f, pArith_diff->pFreq_model[i] ) );
+ pArith_diff->saved_dist_arr[0][i - 1] -= log2f( max( 1e-10f, sum ) );
+ }
+
+ for ( j = 0; j < pArith_diff->num_models - 1; j++ )
+ {
+ sum = 0;
+ for ( i = 1; i < pArith_diff->range + 1; i++ )
+ {
+ sum += pArith_diff->pAlt_freq_models[j][i];
+ }
+
+ for ( i = 1; i < pArith_diff->range + 1; i++ )
+ {
+ pArith_diff->saved_dist_arr[j + 1][i - 1] = log2f( max( 1e-10f, pArith_diff->pAlt_freq_models[j][i] ) );
+ pArith_diff->saved_dist_arr[j + 1][i - 1] -= log2f( max( 1e-10f, sum ) );
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_spar_arith_coeffs_com_init()
+ *
+ * Init for Arithm. coding
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_spar_arith_coeffs_com_init(
+ ivas_arith_coeffs_t *pArith_coeffs,
+ ivas_spar_md_com_cfg *pSpar_cfg,
+ const int16_t table_idx,
+ const int16_t enc_dec )
+{
+ int16_t i, pred_r_index, drct_r_index, decd_r_index;
+ int16_t num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r;
+
+ for ( i = 0; i < MAX_QUANT_STRATS; i++ )
+ {
+ num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */
+ pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, ivas_spar_br_table_consts[table_idx].active_w );
+ ivas_spar_arith_com_init( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index],
+ &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec );
+
+ num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */
+ drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r );
+ ivas_spar_arith_com_init( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index],
+ &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec );
+
+ num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */
+ decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r );
+ ivas_spar_arith_com_init( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index],
+ &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_huffman_dec_init_min_max_len()
+ *
+ * Find min and max length in codebook and finalize initialization of ivas_huffman_cfg_t.
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_huffman_dec_init_min_max_len(
+ ivas_huffman_cfg_t *p_huff_cfg )
+{
+ int16_t i, code_len;
+ const int16_t *codebook;
+
+ codebook = p_huff_cfg->codebook;
+
+ p_huff_cfg->min_len = p_huff_cfg->sym_len;
+ p_huff_cfg->max_len = 0;
+
+ for ( i = 0; i < p_huff_cfg->sym_len; i++ )
+ {
+ code_len = codebook[1];
+ if ( p_huff_cfg->min_len > code_len )
+ {
+ p_huff_cfg->min_len = code_len;
+ }
+ if ( p_huff_cfg->max_len < code_len )
+ {
+ p_huff_cfg->max_len = code_len;
+ }
+ codebook = codebook + 3;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_spar_huff_coeffs_com_init()
+ *
+ * Init for Huffman decoding
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_spar_huff_coeffs_com_init(
+ ivas_huff_coeffs_t *pHuff_coeffs,
+ ivas_spar_md_com_cfg *pSpar_cfg,
+ const int16_t table_idx,
+ const int16_t enc_dec )
+{
+ int16_t i, pred_r_index, drct_r_index, decd_r_index;
+ int16_t num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r;
+ ivas_huffman_cfg_t *p_huff_cfg;
+
+ for ( i = 0; i < MAX_QUANT_STRATS; i++ )
+ {
+ p_huff_cfg = &pHuff_coeffs->pred_huff_re[i];
+ num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */
+ pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, 0 );
+ p_huff_cfg->codebook = &ivas_huff_pred_r_consts[pred_r_index].code_book[0][0];
+ if ( enc_dec == DEC )
+ {
+ p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].PR.q_levels[0];
+ ivas_huffman_dec_init_min_max_len( p_huff_cfg );
+ }
+
+ p_huff_cfg = &pHuff_coeffs->drct_huff_re[i];
+ num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */
+ drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r );
+ p_huff_cfg->codebook = &ivas_huff_drct_r_consts[drct_r_index].code_book[0][0];
+ if ( enc_dec == DEC )
+ {
+ p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].C.q_levels[0];
+ ivas_huffman_dec_init_min_max_len( p_huff_cfg );
+ }
+
+ p_huff_cfg = &pHuff_coeffs->decd_huff_re[i];
+ num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */
+ decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r );
+ p_huff_cfg->codebook = &ivas_huff_decd_r_consts[decd_r_index].code_book[0][0];
+ if ( enc_dec == DEC )
+ {
+ p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].P_r.q_levels[0];
+ ivas_huffman_dec_init_min_max_len( p_huff_cfg );
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_error.h b/lib_com/ivas_error.h
new file mode 100644
index 0000000000000000000000000000000000000000..fbb18cf9ff5d7fc6d67c511b0457d9972a2744d1
--- /dev/null
+++ b/lib_com/ivas_error.h
@@ -0,0 +1,259 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+/* options.h needed for debugging/development features
+ * It should be stripped for delivery along with debugging switches */
+#include "options.h"
+
+#ifndef IVAS_ERROR_H
+#define IVAS_ERROR_H
+
+typedef enum
+{
+ /*----------------------------------------*
+ * no error *
+ *----------------------------------------*/
+ IVAS_ERR_OK = 0x0000,
+
+ /*----------------------------------------*
+ * API errors *
+ *----------------------------------------*/
+ IVAS_ERR_INVALID_BANDWIDTH = 0x1000,
+ IVAS_ERR_INVALID_DTX_UPDATE_RATE,
+ IVAS_ERR_INVALID_SAMPLING_RATE,
+ IVAS_ERR_NOT_CONFIGURED,
+ IVAS_ERR_INVALID_STEREO_MODE,
+ IVAS_ERR_INVALID_MC_LAYOUT,
+ IVAS_ERR_INVALID_BITRATE,
+ IVAS_ERR_INVALID_MASA_CONFIG,
+ IVAS_ERR_TOO_MANY_INPUTS,
+ IVAS_ERR_MISSING_METADATA,
+ IVAS_ERR_RECONFIGURE_NOT_SUPPORTED,
+ IVAS_ERR_INVALID_FEC_CONFIG,
+ IVAS_ERR_INVALID_FEC_OFFSET,
+ IVAS_ERR_INVALID_INPUT_BUFFER_SIZE,
+ IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE,
+ IVAS_ERR_DTX_NOT_SUPPORTED,
+ IVAS_ERR_UNEXPECTED_NULL_POINTER,
+ IVAS_ERR_METADATA_NOT_EXPECTED,
+ IVAS_ERR_WRONG_PARAMS,
+ IVAS_ERR_INIT_ERROR,
+ IVAS_ERR_WRONG_MODE,
+ IVAS_ERR_INVALID_OUTPUT_FORMAT,
+ IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED,
+ IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED,
+ IVAS_ERR_DIRECTIVITY_NOT_SUPPORTED,
+ IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED,
+ IVAS_ERR_INVALID_HRTF,
+ IVAS_ERR_INVALID_INPUT_FORMAT,
+ IVAS_ERR_INVALID_INDEX,
+ IVAS_ERR_NOT_SUPPORTED_OPTION,
+ IVAS_ERR_NOT_IMPLEMENTED,
+ IVAS_ERR_WAITING_FOR_BITSTREAM,
+ IVAS_ERR_ISM_FILE_READER_INVALID_METADATA_FORMAT,
+ IVAS_ERR_ISM_INVALID_METADATA_VALUE,
+ IVAS_ERR_INVALID_MASA_FORMAT_METADATA_FILE,
+ IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED,
+ IVAS_ERR_TSM_NOT_ENABLED,
+ IVAS_ERR_FETCH_SIZE_NO_MULTIPLE_OF_5MS,
+
+ /*----------------------------------------*
+ * input data errors *
+ *----------------------------------------*/
+ IVAS_ERR_INVALID_BITSTREAM = 0x2000,
+
+ /*----------------------------------------*
+ * hardware errors *
+ *----------------------------------------*/
+ IVAS_ERR_FAILED_ALLOC = 0x3000,
+
+ /*----------------------------------------*
+ * internal errors *
+ *----------------------------------------*/
+ IVAS_ERR_INTERNAL = 0x4000,
+ IVAS_ERR_INTERNAL_FATAL,
+
+ /*----------------------------------------*
+ * file I/O errors (lib_util only) *
+ *----------------------------------------*/
+ IVAS_ERR_FAILED_FILE_OPEN = 0x5000,
+ IVAS_ERR_FAILED_FILE_WRITE,
+ IVAS_ERR_FAILED_FILE_READ,
+ IVAS_ERR_FAILED_FILE_PARSE,
+ IVAS_ERR_END_OF_FILE,
+ IVAS_ERR_BITSTREAM_WRITER_INVALID_FORMAT,
+ IVAS_ERR_BITSTREAM_READER_INVALID_DATA,
+ IVAS_ERR_BITSTREAM_READER_INVALID_FORMAT,
+ IVAS_ERR_NO_FILE_OPEN,
+ IVAS_ERR_SAMPLING_RATE_UNKNOWN,
+
+ /*----------------------------------------*
+ * renderer (lib_rend only) *
+ *----------------------------------------*/
+ IVAS_ERR_NUM_CHANNELS_UNKNOWN = 0x6000,
+ IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT,
+ IVAS_ERR_INVALID_INPUT_ID,
+ IVAS_ERR_WRONG_NUM_CHANNELS,
+ IVAS_ERR_INVALID_BUFFER_SIZE,
+ IVAS_ERR_INVALID_RENDER_CONFIG,
+ IVAS_ERR_ACOUSTIC_ENVIRONMENT_MISSING,
+ IVAS_ERR_INVALID_ER_PARAM,
+ IVAS_ERR_DIRECTIVITY_PATTERN_ID_MISSING,
+
+ /*----------------------------------------*
+ * unknown error *
+ *----------------------------------------*/
+ IVAS_ERR_UNKNOWN = 0xF000, /* fallback error code */
+
+} ivas_error;
+
+
+static inline const char *ivas_error_to_string( ivas_error error_code )
+{
+ /* Try to match to a specific string */
+ switch ( error_code )
+ {
+ case IVAS_ERR_OK:
+ return "No error";
+ case IVAS_ERR_FAILED_ALLOC:
+ return "Failed allocation error";
+ case IVAS_ERR_INTERNAL:
+ return "Internal error";
+ case IVAS_ERR_INTERNAL_FATAL:
+ return "Internal fatal error";
+ case IVAS_ERR_INVALID_SAMPLING_RATE:
+ return "Invalid sampling rate";
+ case IVAS_ERR_INVALID_OUTPUT_FORMAT:
+ return "Invalid output format";
+ case IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT:
+ return "Invalid custom loudspeaker layout";
+ case IVAS_ERR_INVALID_INPUT_ID:
+ return "Invalid input ID";
+ case IVAS_ERR_WRONG_NUM_CHANNELS:
+ return "Wrong number of channels";
+ case IVAS_ERR_INVALID_BUFFER_SIZE:
+ return "Invalid buffer size";
+ case IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED:
+ return "Unsupported input/output config pair";
+ case IVAS_ERR_FAILED_FILE_OPEN:
+ return "File open error";
+ case IVAS_ERR_FAILED_FILE_WRITE:
+ return "File write error";
+ case IVAS_ERR_FAILED_FILE_READ:
+ return "File read error";
+ case IVAS_ERR_FAILED_FILE_PARSE:
+ return "Parse error";
+ case IVAS_ERR_END_OF_FILE:
+ return "End of file";
+ case IVAS_ERR_WRONG_PARAMS:
+ return "Wrong function parameters";
+ case IVAS_ERR_INVALID_BANDWIDTH:
+ return "Invalid bandwidth";
+ case IVAS_ERR_INVALID_DTX_UPDATE_RATE:
+ return "Invalid DTX update rate";
+ case IVAS_ERR_NOT_CONFIGURED:
+ return "Handle has not been configured";
+ case IVAS_ERR_INVALID_STEREO_MODE:
+ return "Invalid stereo mode";
+ case IVAS_ERR_INVALID_MC_LAYOUT:
+ return "Invalid speaker layout";
+ case IVAS_ERR_INVALID_BITRATE:
+ return "Invalid bitrate";
+ case IVAS_ERR_INVALID_MASA_CONFIG:
+ return "Invalid MASA config";
+ case IVAS_ERR_TOO_MANY_INPUTS:
+ return "Too many object inputs provided";
+ case IVAS_ERR_RECONFIGURE_NOT_SUPPORTED:
+ return "Reconfigure not supported";
+ case IVAS_ERR_INVALID_FEC_OFFSET:
+ return "Invalid FEC offset";
+ case IVAS_ERR_INVALID_INPUT_BUFFER_SIZE:
+ return "Invalid input buffer size";
+ case IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE:
+ return "Invalid output buffer size";
+ case IVAS_ERR_DTX_NOT_SUPPORTED:
+ return "DTX is not supported in this IVAS format and element mode";
+ case IVAS_ERR_UNEXPECTED_NULL_POINTER:
+ return "Unexpected NULL pointer";
+ case IVAS_ERR_METADATA_NOT_EXPECTED:
+ return "Metadata input not expected for current configuration";
+ case IVAS_ERR_NOT_IMPLEMENTED:
+ return "Not implemented";
+ case IVAS_ERR_ISM_FILE_READER_INVALID_METADATA_FORMAT:
+ return "Invalid metadata file format";
+ case IVAS_ERR_ISM_INVALID_METADATA_VALUE:
+ return "Invalid metadata value provided";
+ case IVAS_ERR_NOT_SUPPORTED_OPTION:
+ return "Option not supported in this set-up";
+ case IVAS_ERR_INIT_ERROR:
+ return "Initialization error";
+ case IVAS_ERR_INVALID_BITSTREAM:
+ return "Invalid bitstream";
+ case IVAS_ERR_WRONG_MODE:
+ return "Wrong mode";
+ case IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED:
+ return "Head rotation not supported";
+ case IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED:
+ return "External orientation not supported";
+ case IVAS_ERR_DIRECTIVITY_NOT_SUPPORTED:
+ return "Directivity not supported";
+ case IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED:
+ return "Acoustic environment not supported";
+ case IVAS_ERR_INVALID_HRTF:
+ return "Unsupported HRTF filter set";
+ case IVAS_ERR_INVALID_INPUT_FORMAT:
+ return "Invalid input format";
+ case IVAS_ERR_INVALID_INDEX:
+ return "Invalid index";
+ default:
+ break;
+ }
+
+ /* For error categories that are likely to still have many changes to
+ * specific error codes, return one string per category */
+ if ( ( error_code & 0xF000 ) == 0x1000 )
+ {
+ return "API error";
+ }
+ if ( ( error_code & 0xF000 ) == 0x2000 )
+ {
+ return "data error";
+ }
+
+ return "Unknown error";
+}
+
+#endif /* IVAS_ERROR_H */
diff --git a/lib_com/ivas_error_utils.h b/lib_com/ivas_error_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..204acc40e876ac6feee771e3778a615437ec4f76
--- /dev/null
+++ b/lib_com/ivas_error_utils.h
@@ -0,0 +1,73 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+
+#include
+#include
+#include
+
+#include "ivas_error.h"
+
+
+#ifndef IVAS_ERROR_UTILS_H
+#define IVAS_ERROR_UTILS_H
+
+/*
+ * Usage:
+ *
+ * IVAS_ERROR( error_code, decription_fmt, ... );
+ *
+ * where:
+ * - error_code is of type enum ivas_error
+ * - decription_fmt is a description string with printf-like formatting
+ * - ... are (optional) printf-like arguments to place in the description format string
+ *
+ * Examples:
+ *
+ * IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for XXX" );
+ *
+ * IVAS_ERROR( IVAS_ERR_INTERNAL, "Unexpected value %f in frame %d", var, frame );
+ *
+ * Note: Contrary to printf, this macro is not able to verify at build time that the
+ * placeholders (e.g. "%f") in the format string match the types of provided arguments.
+ * If unexpected values are printed or the macro causes a crash, double check that the
+ * format specifiers are correct.
+ */
+#define IVAS_ERROR( error_code, ... ) ivas_error_wrapper( error_code )
+
+static inline ivas_error ivas_error_wrapper( const ivas_error error_code )
+{
+ return error_code;
+}
+
+#endif /* IVAS_ERROR_UTILS_H */
diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c
new file mode 100644
index 0000000000000000000000000000000000000000..f914d4e75160f1b5af8f9c44976f10b6cb471c9e
--- /dev/null
+++ b/lib_com/ivas_fb_mixer.c
@@ -0,0 +1,1341 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository. All Rights Reserved.
+
+ This software is protected by copyright law and by international treaties.
+ The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository retain full ownership rights in their respective contributions in
+ the software. This notice grants no license of any kind, including but not limited to patent
+ license, nor is any license granted by implication, estoppel or otherwise.
+
+ Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
+ contributions.
+
+ This software is provided "AS IS", without any express or implied warranties. The software is in the
+ development stage. It is intended exclusively for experts who have experience with such software and
+ solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
+ and fitness for a particular purpose are hereby disclaimed and excluded.
+
+ Any dispute, controversy or claim arising under or in relation to providing this software shall be
+ submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
+ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
+ the United Nations Convention on Contracts on the International Sales of Goods.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h"
+#include
+#include "prot.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
+#include
+#include "wmc_auto.h"
+
+
+/*------------------------------------------------------------------------------------------*
+ * Static functions declarations
+ *------------------------------------------------------------------------------------------*/
+
+static void ivas_get_active_bins( const int16_t **pActive_bins, const int16_t **pActive_bins_abs, const int16_t **pStart_offset, const int16_t **pStart_offset_ab, const int32_t sampling_rate );
+static void ivas_get_ld_fb_resp( float **ppIdeal_FRs_re, float **ppIdeal_FRs_im, float **ppNew_FRs_re, float **ppNew_FRs_im, const int16_t *pActive_bins, const int16_t *pStart_offset, const int16_t num_bands, const int16_t delay, const int32_t sampling_rate );
+static ivas_error ivas_filterbank_setup( IVAS_FB_MIXER_HANDLE hFbMixer, const int32_t sampling_rate );
+static ivas_error ivas_fb_mixer_get_window( const int16_t fade_len, const int32_t sampling_rate, const float **pWindow );
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_num_bands_from_bw_idx()
+ *
+ * Get number of bands from BW index
+ *-----------------------------------------------------------------------------------------*/
+
+/*! r: number of spectral bands */
+int16_t ivas_get_num_bands_from_bw_idx(
+ const int16_t bwidth /* i : audio bandwidth */
+)
+{
+ int16_t num_active_bands;
+
+ assert( bwidth > 0 ); /*NB BW is not supported*/
+ num_active_bands = ivas_num_active_bands[bwidth - 1];
+
+ return num_active_bands;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_num_bands()
+ *
+ * Get number of bands depending on the sampling rates
+ *-----------------------------------------------------------------------------------------*/
+
+static int16_t ivas_get_num_bands(
+ const int32_t sampling_rate )
+{
+ int16_t bwidth = ivas_get_bw_idx_from_sample_rate( sampling_rate );
+ int16_t num_active_bands = ivas_get_num_bands_from_bw_idx( bwidth );
+
+ return num_active_bands;
+}
+
+
+/*---------------------------------------------------------------------*
+ * Function ivas_fb_set_cfg()
+ *
+ * Set default configs for FB mixer
+ *---------------------------------------------------------------------*/
+
+ivas_error ivas_fb_set_cfg(
+ IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */
+ const int16_t ivas_format, /* i : IVAS format */
+ const int16_t num_in_chans, /* i : number of FB input channels */
+ const int16_t num_out_chans, /* i : number of FB output channels */
+ const int16_t active_w_mixing, /* i : active_w_mixing flag */
+ const int32_t sampling_rate, /* i : sampling rate */
+ const int16_t nchan_fb_in /* i : number of dirAC analysis channels*/
+)
+{
+ IVAS_FB_CFG *pFb_cfg;
+
+ if ( ( pFb_cfg = (IVAS_FB_CFG *) malloc( sizeof( IVAS_FB_CFG ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer config" );
+ }
+
+ pFb_cfg->num_in_chans = num_in_chans;
+ pFb_cfg->num_out_chans = num_out_chans;
+ pFb_cfg->nchan_fb_in = nchan_fb_in;
+
+ pFb_cfg->pcm_offset = 0; /* note: in SPAR decoder, this parameter is overwritten later */
+ pFb_cfg->active_w_mixing = active_w_mixing;
+ pFb_cfg->windowed_fr_offset = 0;
+
+ if ( ivas_format == ISM_FORMAT )
+ {
+ pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_4_NS );
+ pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_4_NS );
+ pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS_PARAM_ISM ) + NS2SA( sampling_rate, DIRAC_SLOT_ENC_NS );
+ }
+ else if ( ivas_format == SBA_FORMAT )
+ {
+ pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS );
+
+ pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_4_NS );
+ pFb_cfg->prior_input_length = NS2SA( sampling_rate, FRAME_SIZE_NS );
+ pFb_cfg->windowed_fr_offset = (int16_t) ( (float) ( sampling_rate / FRAMES_PER_SEC ) * 3.0f / 4.0f ) - NS2SA( sampling_rate, DELAY_DIRAC_SPAR_ENC_CMP_NS );
+ }
+ else if ( ivas_format == MASA_FORMAT )
+ {
+ pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS );
+ pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_1_NS );
+ pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS ) + NS2SA( sampling_rate, DIRAC_SLOT_ENC_NS );
+ }
+ else if ( ivas_format == MC_FORMAT )
+ {
+ pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS );
+ pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_1_NS );
+ pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS ) + NS2SA( sampling_rate, PARAM_MC_SLOT_ENC_NS );
+ }
+
+ *pFb_cfg_out = pFb_cfg;
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_FB_mixer_open()
+ *
+ * Allocate and initialize FB mixer handle
+ *------------------------------------------------------------------------*/
+
+ivas_error ivas_FB_mixer_open(
+ IVAS_FB_MIXER_HANDLE *hFbMixer_out, /* i/o: FB mixer handle */
+ const int32_t sampling_rate, /* i : sampling rate */
+ IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */
+ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */
+)
+{
+ IVAS_FB_MIXER_HANDLE hFbMixer;
+ int16_t i, j, frame_len, num_bands;
+ int16_t num_chs_alloc;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC );
+
+ hFbMixer = *hFbMixer_out;
+
+ if ( !spar_reconfig_flag )
+ {
+ if ( ( hFbMixer = (IVAS_FB_MIXER_HANDLE) malloc( sizeof( IVAS_FB_MIXER_DATA ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
+ }
+
+ if ( fb_cfg->num_out_chans > 0 )
+ {
+ if ( ( hFbMixer->pFb = (ivas_filterbank_t *) malloc( sizeof( ivas_filterbank_t ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
+ }
+ }
+ else
+ {
+ hFbMixer->pFb = NULL;
+ }
+ }
+
+ if ( fb_cfg->active_w_mixing == -1 )
+ {
+ num_chs_alloc = 0;
+ }
+ else if ( fb_cfg->active_w_mixing )
+ {
+ num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in );
+ }
+ else
+ {
+ num_chs_alloc = 1; /* only W channel processed for predicting YZX */
+ }
+
+ for ( i = 0; i < num_chs_alloc; i++ )
+ {
+ if ( fb_cfg->num_out_chans == 0 )
+ {
+ hFbMixer->ppFilterbank_inFR_re[i] = NULL;
+ hFbMixer->ppFilterbank_inFR_im[i] = NULL;
+ }
+ else
+ {
+ j = fb_cfg->remix_order[i];
+
+ if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
+ }
+
+ if ( ( hFbMixer->ppFilterbank_inFR_im[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
+ }
+ }
+ }
+
+ if ( fb_cfg->active_w_mixing == -1 )
+ {
+ num_chs_alloc = 0;
+ }
+ else
+ {
+ num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in );
+ }
+
+ for ( i = 0; i < num_chs_alloc; i++ )
+ {
+ if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
+ }
+ set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length );
+ }
+
+ if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) )
+ {
+ float *pTemp_mem;
+ if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" );
+ }
+ for ( i = 0; i < fb_cfg->num_out_chans; i++ )
+ {
+ for ( j = 0; j < fb_cfg->num_in_chans; j++ )
+ {
+ hFbMixer->prior_mixer[i][j] = pTemp_mem;
+ pTemp_mem += IVAS_MAX_NUM_BANDS;
+ set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS );
+ }
+ }
+ }
+
+ if ( !spar_reconfig_flag )
+ {
+ if ( fb_cfg->num_out_chans > 0 )
+ {
+ const int16_t *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs;
+
+ num_bands = ivas_get_num_bands( sampling_rate );
+
+ ivas_get_active_bins( &pActive_bins_per_band, &pActive_bins_per_band_abs, &pStart_offset, &pStart_offset_abs, sampling_rate );
+
+ if ( fb_cfg->active_w_mixing != -1 )
+ {
+ for ( i = 0; i < num_bands; i++ )
+ {
+ if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
+ }
+ }
+ }
+
+ if ( sampling_rate != 48000 )
+ {
+ int16_t num_diff_bands, start_diff_band_non48k;
+
+ num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K;
+ start_diff_band_non48k = num_bands - num_diff_bands;
+
+ hFbMixer->num_diff_bands = num_diff_bands;
+
+ for ( j = start_diff_band_non48k; j < num_bands; j++ )
+ {
+ if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
+ }
+
+ if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
+ }
+ }
+ }
+ }
+ else
+ {
+ /* ignore all the deeper filter bank stuff for now */
+ hFbMixer->num_diff_bands = 0;
+ }
+ }
+
+ hFbMixer->fb_cfg = fb_cfg;
+ set_s( hFbMixer->first_frame, 1, hFbMixer->fb_cfg->num_out_chans );
+ set_s( hFbMixer->first_frame + hFbMixer->fb_cfg->num_out_chans, 0, IVAS_SPAR_MAX_CH - hFbMixer->fb_cfg->num_out_chans );
+
+ if ( !spar_reconfig_flag )
+ {
+ if ( ( error = ivas_filterbank_setup( hFbMixer, sampling_rate ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ *hFbMixer_out = hFbMixer;
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_FB_mixer_close()
+ *
+ * Deallocate FB mixer handle
+ *------------------------------------------------------------------------*/
+
+void ivas_FB_mixer_close(
+ IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */
+ const int32_t sampling_rate, /* i : sampling rate in Hz */
+ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */
+)
+{
+ IVAS_FB_MIXER_HANDLE hFbMixer;
+ IVAS_FB_CFG *fb_cfg;
+ int16_t i, j, num_bands;
+ int16_t num_chs_alloc;
+
+ hFbMixer = *hFbMixer_in;
+ fb_cfg = hFbMixer->fb_cfg;
+
+ if ( fb_cfg->active_w_mixing == -1 )
+ {
+ num_chs_alloc = 0;
+ }
+ else if ( fb_cfg->active_w_mixing )
+ {
+ num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in );
+ }
+ else
+ {
+ num_chs_alloc = 1; /* only W channel processed for predicting YZX */
+ }
+
+ if ( hFbMixer != NULL )
+ {
+ for ( i = 0; i < num_chs_alloc; i++ )
+ {
+ if ( fb_cfg->num_out_chans > 0 )
+ {
+ j = fb_cfg->remix_order[i];
+
+ free( hFbMixer->ppFilterbank_inFR_re[j] );
+ hFbMixer->ppFilterbank_inFR_re[j] = NULL;
+
+ free( hFbMixer->ppFilterbank_inFR_im[j] );
+ hFbMixer->ppFilterbank_inFR_im[j] = NULL;
+ }
+ }
+
+ if ( fb_cfg->active_w_mixing == -1 )
+ {
+ num_chs_alloc = 0;
+ }
+ else
+ {
+ num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in );
+ }
+
+ for ( i = 0; i < num_chs_alloc; i++ )
+ {
+ free( hFbMixer->ppFilterbank_prior_input[i] );
+ hFbMixer->ppFilterbank_prior_input[i] = NULL;
+ }
+
+ if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) )
+ {
+ free( hFbMixer->prior_mixer[0][0] );
+ hFbMixer->prior_mixer[0][0] = NULL;
+ }
+
+ if ( !spar_reconfig_flag )
+ {
+ if ( fb_cfg->num_out_chans > 0 )
+ {
+ num_bands = hFbMixer->pFb->filterbank_num_bands;
+
+ if ( fb_cfg->active_w_mixing != -1 )
+ {
+ for ( i = 0; i < num_bands; i++ )
+ {
+ free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] );
+ hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL;
+ }
+ }
+
+ if ( sampling_rate != 48000 )
+ {
+ int16_t start_diff_band_non48k;
+ start_diff_band_non48k = num_bands - hFbMixer->num_diff_bands;
+
+ for ( j = start_diff_band_non48k; j < num_bands; j++ )
+ {
+ free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] );
+ hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = NULL;
+
+ free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] );
+ hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = NULL;
+ }
+ }
+ }
+ if ( hFbMixer->pFb != NULL )
+ {
+ free( hFbMixer->pFb );
+ hFbMixer->pFb = NULL;
+ }
+ }
+
+ if ( hFbMixer->fb_cfg != NULL )
+ {
+ free( hFbMixer->fb_cfg );
+ hFbMixer->fb_cfg = NULL;
+ }
+
+ if ( !spar_reconfig_flag )
+ {
+ free( hFbMixer );
+ hFbMixer = NULL;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_fb_mixer_pcm_ingest()
+ *
+ * PCM ingest block
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_fb_mixer_pcm_ingest(
+ IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */
+ float *pcm_in[], /* i : input audio channels */
+ float **ppOut_pcm, /* o : output audio channels */
+ const int16_t frame_len, /* i : frame length */
+ const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] )
+{
+ int16_t i;
+ int16_t num_chs_ingest;
+ IVAS_FB_CFG *fb_cfg = hFbMixer->fb_cfg;
+
+ if ( fb_cfg->active_w_mixing )
+ {
+ num_chs_ingest = fb_cfg->num_in_chans;
+ }
+ else
+ {
+ num_chs_ingest = 1; /* forward Filterbank MDFT only on W */
+ }
+
+ for ( i = 0; i < fb_cfg->num_in_chans; i++ )
+ {
+ mvr2r( &hFbMixer->ppFilterbank_prior_input[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len );
+ mvr2r( pcm_in[HOA_md_ind[i]], &ppOut_pcm[i][frame_len], frame_len );
+ }
+
+ for ( i = 0; i < num_chs_ingest; i++ )
+ {
+ ivas_mdft( ppOut_pcm[fb_cfg->remix_order[i]], hFbMixer->ppFilterbank_inFR_re[fb_cfg->remix_order[i]], hFbMixer->ppFilterbank_inFR_im[fb_cfg->remix_order[i]], frame_len << 1, frame_len );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_fb_mixer_update_prior_input()
+ *
+ *
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_fb_mixer_update_prior_input(
+ IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */
+ float *pcm_in[], /* i : input audio channels */
+ const int16_t length, /* i : length of time slot */
+ const int16_t nchan_fb_in /* i : number of analysis channels */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < nchan_fb_in; i++ )
+ {
+ mvr2r( &hFbMixer->ppFilterbank_prior_input[i][length], hFbMixer->ppFilterbank_prior_input[i], hFbMixer->fb_cfg->prior_input_length - length );
+ mvr2r( pcm_in[i], &hFbMixer->ppFilterbank_prior_input[i][hFbMixer->fb_cfg->prior_input_length - length], length );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_fb_mixer_get_windowed_fr()
+ *
+ *
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_fb_mixer_get_windowed_fr(
+ IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */
+ float *pcm_in[], /* i : input audio channels */
+ float *frame_f_real[], /* o : real freq domain values */
+ float *frame_f_imag[], /* o : imag freq domain values */
+ const int16_t length, /* i : number of new samples in time slot */
+ const int16_t mdft_len, /* i : MDFT frame length */
+ const int16_t nchan_fb_in /* i : number of analysis channels */
+)
+{
+ int16_t ch_idx, j, offset, rev_offset;
+ int16_t n_old_samples;
+ int16_t n_new_samples;
+ float fr_in_block[L_FRAME48k * 2];
+ const float *win_ptr;
+
+ n_old_samples = min( ( hFbMixer->fb_cfg->prior_input_length - hFbMixer->fb_cfg->windowed_fr_offset ), ( 2 * mdft_len ) );
+ n_new_samples = max( 0, 2 * length - n_old_samples );
+ offset = (int16_t) ( 2 * mdft_len - length - hFbMixer->ana_window_offset );
+ rev_offset = (int16_t) ( 2 * mdft_len - hFbMixer->ana_window_offset );
+ set_zero( fr_in_block, offset );
+
+ for ( ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ )
+ {
+ mvr2r( &hFbMixer->ppFilterbank_prior_input[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block[offset], n_old_samples - offset );
+ mvr2r( pcm_in[ch_idx], &fr_in_block[n_old_samples], n_new_samples );
+ win_ptr = hFbMixer->pAna_window;
+
+ for ( j = offset; j < 2 * mdft_len - length; j++ )
+ {
+ fr_in_block[j] *= ( *( win_ptr++ ) );
+ }
+
+ for ( j = rev_offset; j < 2 * mdft_len; j++ )
+ {
+ fr_in_block[j] *= ( *( --win_ptr ) );
+ }
+
+ ivas_mdft( fr_in_block, frame_f_real[ch_idx], frame_f_imag[ch_idx], mdft_len << 1, mdft_len );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_fb_mixer_cross_fading()
+ *
+ * FB Mixer cross fading
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_fb_mixer_cross_fading(
+ IVAS_FB_MIXER_HANDLE hFbMixer,
+ float **ppOut_pcm,
+ float *pMdft_out_old,
+ float *pMdft_out_new,
+ const int16_t ch,
+ const int16_t frame_len,
+ const int16_t cf_offset )
+{
+ int16_t k, fade_start_offset, fade_end_offset;
+
+ if ( hFbMixer->first_frame[ch] == 0 )
+ {
+ fade_start_offset = hFbMixer->cross_fade_start_offset;
+ fade_end_offset = hFbMixer->cross_fade_end_offset;
+
+ for ( k = 0; k < fade_start_offset; k++ )
+ {
+ ppOut_pcm[ch][k] = pMdft_out_old[k + cf_offset];
+ }
+
+ for ( k = fade_start_offset; k < fade_end_offset; k++ )
+ {
+ ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset] * hFbMixer->pFilterbank_cross_fade[k - fade_start_offset] + pMdft_out_old[k + cf_offset] * ( 1.0f - hFbMixer->pFilterbank_cross_fade[k - fade_start_offset] );
+ }
+
+ for ( k = fade_end_offset; k < frame_len; k++ )
+ {
+ ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset];
+ }
+ }
+ else
+ {
+ hFbMixer->first_frame[ch] = 0;
+
+ for ( k = 0; k < frame_len; k++ )
+ {
+ ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset];
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_fb_mixer_process()
+ *
+ * Filter bank process
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_fb_mixer_process(
+ IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */
+ float ***mixer_mat, /* i : mixer matrix */
+ float **ppOut_pcm, /* o : output audio channels */
+ const int16_t frame_len, /* i : frame length in samples */
+ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */
+)
+{
+ ivas_filterbank_t *pFb = hFbMixer->pFb;
+ int16_t num_bands = pFb->filterbank_num_bands;
+ int16_t i, j, k, ch, hist;
+ const float *pFilterbank_bin_to_band_re;
+ const float *pFilterbank_bin_to_band_im;
+ float *pMdft_out[2], *pOut_fr_re, *pOut_fr_im;
+ float Out_fr_re[L_FRAME48k], Out_fr_im[L_FRAME48k];
+ float Mdft_out_0[L_FRAME48k * 2], Mdft_out_1[L_FRAME48k * 2];
+
+ pOut_fr_re = Out_fr_re;
+ pOut_fr_im = Out_fr_im;
+ pMdft_out[0] = Mdft_out_0;
+ pMdft_out[1] = Mdft_out_1;
+
+ for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ )
+ {
+ /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */
+ for ( hist = 0; hist < 2; hist++ )
+ {
+ set_zero( pOut_fr_re, frame_len );
+ set_zero( pOut_fr_im, frame_len );
+
+ for ( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ )
+ {
+ if ( in_out_mixer_map[ch][j] != 0 )
+ {
+ float filterbank_mixer_bins_re[L_FRAME48k];
+ float filterbank_mixer_bins_im[L_FRAME48k];
+ float *pFb_inFR_re = hFbMixer->ppFilterbank_inFR_re[j];
+ float *pFb_inFR_im = hFbMixer->ppFilterbank_inFR_im[j];
+
+ set_zero( filterbank_mixer_bins_re, frame_len );
+ set_zero( filterbank_mixer_bins_im, frame_len );
+
+ for ( i = 0; i < num_bands; i++ )
+ {
+ int16_t start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i];
+ int16_t num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i];
+
+ float mixer_const = hFbMixer->prior_mixer[ch][j][i];
+
+ pFilterbank_bin_to_band_re = pFb->fb_consts.ppFilterbank_FRs[0][i];
+ pFilterbank_bin_to_band_im = pFb->fb_consts.ppFilterbank_FRs[1][i];
+
+ for ( k = start_offset; k < num_bins + start_offset; k++ )
+ {
+ filterbank_mixer_bins_re[k] += *pFilterbank_bin_to_band_re++ * mixer_const;
+ filterbank_mixer_bins_im[k] += *pFilterbank_bin_to_band_im++ * mixer_const;
+ }
+ hFbMixer->prior_mixer[ch][j][i] = mixer_mat[ch][j][i];
+ }
+
+ for ( k = 0; k < frame_len; k++ )
+ {
+ float temp_out_re, temp_out_im;
+
+ IVAS_CMULT_FLOAT( filterbank_mixer_bins_re[k], filterbank_mixer_bins_im[k], pFb_inFR_re[k],
+ pFb_inFR_im[k], temp_out_re, temp_out_im );
+
+ pOut_fr_re[k] += temp_out_re;
+ pOut_fr_im[k] += temp_out_im;
+ }
+ }
+ }
+
+ ivas_imdft( pOut_fr_re, pOut_fr_im, pMdft_out[hist], frame_len );
+ }
+
+ ivas_fb_mixer_cross_fading( hFbMixer, ppOut_pcm, pMdft_out[0], pMdft_out[1], ch, frame_len, frame_len );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_fb_mixer_get_in_out_mapping()
+ *
+ *
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_fb_mixer_get_in_out_mapping(
+ const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */
+ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */
+)
+{
+ int16_t i, j;
+
+ set_s( (int16_t *) in_out_mixer_map, 0, IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH );
+
+ if ( fb_cfg->active_w_mixing )
+ {
+ for ( i = 0; i < fb_cfg->num_out_chans; i++ )
+ {
+ for ( j = 0; j < fb_cfg->num_in_chans; j++ )
+ {
+ in_out_mixer_map[i][j] = 1;
+ }
+ }
+ }
+ else
+ {
+ in_out_mixer_map[0][0] = 1; /* W depends on only W input*/
+ for ( i = 1; i < fb_cfg->num_out_chans; i++ )
+ {
+ in_out_mixer_map[i][0] = 1;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calculate_abs_fr()
+ *
+ * Function to calculate number of active bands
+ *-----------------------------------------------------------------------------------------*/
+
+static int16_t ivas_calculate_abs_fr(
+ ivas_filterbank_t *pFb,
+ const int32_t sampling_rate,
+ const int16_t alloc_fb_resp )
+{
+ int16_t frame_len;
+ float ppFilterbank_FRs_s[L_FRAME48k];
+ int16_t bands = pFb->filterbank_num_bands;
+ int16_t i, j, num_active_bands = 0;
+ int16_t idx_short_stride_bin_to_band = 0;
+
+ for ( i = 0; i < bands; i++ )
+ {
+ const float *long_mdft_ptr_re = pFb->fb_consts.ppFilterbank_FRs[0][i];
+ const float *long_mdft_ptr_im = pFb->fb_consts.ppFilterbank_FRs[1][i];
+ int16_t start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i];
+ int16_t num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i];
+ int16_t short_mdft_start_bin = -1;
+ float short_stride_pow_spec[MDFT_FB_BANDS_240];
+ float short_stride_nrg = 0.0f;
+ float cldfb_nrg = 0.0f;
+ int16_t short_stride = pFb->fb_bin_to_band.short_stride;
+ const int16_t num_bins_per_short_stride_bin = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride );
+ const int16_t num_bins_per_cldfb_band = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands );
+ float short_stride_max_per_spar_band = 1e-9f;
+
+ /*loop over all stored Filter Bank Response MDFT coefficients*/
+ set_f( short_stride_pow_spec, 0, MDFT_FB_BANDS_240 );
+ for ( j = start_offset; j < num_bins + start_offset; j++ )
+ {
+ float sq_abs;
+
+ /*calculate bin energy */
+ IVAS_CALCULATE_SQ_ABS( *long_mdft_ptr_re, *long_mdft_ptr_im, sq_abs );
+ long_mdft_ptr_re++;
+ long_mdft_ptr_im++;
+
+ /* accumulate bin energies within a short stride bin */
+ short_stride_nrg += sq_abs;
+ if ( !( ( j + 1 ) % num_bins_per_short_stride_bin ) )
+ { /* new short stride bin */
+ short_stride_pow_spec[j / num_bins_per_short_stride_bin] = short_stride_nrg; /* energy rather than magnitude works better for covariance weighting*/
+ short_stride_max_per_spar_band = max( short_stride_nrg, short_stride_max_per_spar_band ); /*compute highest magnitude per band*/
+ short_stride_nrg = 0.0f;
+ }
+
+ /* accumulate bin energies within a CLDFB band */
+ cldfb_nrg += sq_abs;
+ if ( !( ( j + 1 ) % num_bins_per_cldfb_band ) )
+ {
+ pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j / num_bins_per_cldfb_band][i] = sqrtf( cldfb_nrg );
+ cldfb_nrg = 0.0f;
+ }
+ }
+
+ /*loop over the short MDFT bins*/
+ for ( j = 0; j < short_stride; j++ )
+ {
+ /* normalize and sparsify the energies */
+ short_stride_pow_spec[j] /= short_stride_max_per_spar_band;
+ short_stride_pow_spec[j] = max( short_stride_pow_spec[j] - 0.3f, 0.0f ) / 0.7f;
+ if ( short_stride_pow_spec[j] > 0.0f )
+ {
+ assert( idx_short_stride_bin_to_band < 2 * MDFT_FB_BANDS_240 ); /* array size of p_short_stride_bin_to_band */
+ if ( short_mdft_start_bin == -1 )
+ {
+ short_mdft_start_bin = j;
+ pFb->fb_bin_to_band.p_short_stride_start_bin_per_band[i] = j;
+ pFb->fb_bin_to_band.pp_short_stride_bin_to_band[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band[idx_short_stride_bin_to_band];
+ }
+ pFb->fb_bin_to_band.p_short_stride_bin_to_band[idx_short_stride_bin_to_band++] = short_stride_pow_spec[j];
+ pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[i]++;
+ }
+ }
+ }
+
+ /*loop over CLDFB bands*/
+ for ( j = 0; j < pFb->fb_bin_to_band.num_cldfb_bands; j++ )
+ {
+ float sum_over_spar_bands = 0.0f;
+ float max_spar_band_contribution = 0.0f;
+ int16_t spar_start = 0;
+ int16_t any_non_zero = 0;
+
+ for ( i = 0; i < bands; i++ )
+ {
+ sum_over_spar_bands += pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i];
+ if ( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] > max_spar_band_contribution )
+ {
+ max_spar_band_contribution = pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i];
+ pFb->fb_bin_to_band.p_cldfb_map_to_spar_band[j] = i;
+ }
+ }
+ sum_over_spar_bands = max( sum_over_spar_bands, EPSILON );
+ for ( i = 0; i < bands; i++ )
+ {
+ if ( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] == 0.0f && !any_non_zero )
+ {
+ spar_start++;
+ }
+ else
+ {
+ any_non_zero = 1;
+ }
+ pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] /= sum_over_spar_bands;
+ }
+ pFb->fb_bin_to_band.p_spar_start_bands[j] = spar_start;
+ }
+
+ frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC );
+
+ set_f( ppFilterbank_FRs_s, 0, frame_len );
+
+ /*Commented logic is for calculating number of active bands, can be removed if not needed */
+ for ( i = 0; i < bands; i++ )
+ {
+ const float *pFilterbank_bin_to_band_re = pFb->fb_consts.ppFilterbank_FRs[0][i];
+ const float *pFilterbank_bin_to_band_im = pFb->fb_consts.ppFilterbank_FRs[1][i];
+
+ int16_t start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i];
+ int16_t num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i];
+ int16_t idx = 0;
+ int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[i];
+ int16_t abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[i];
+
+ for ( j = start_offset; j < num_bins + start_offset; j++ )
+ {
+ float temp = 0;
+
+ IVAS_CALCULATE_ABS( *pFilterbank_bin_to_band_re, *pFilterbank_bin_to_band_im, temp );
+
+ pFilterbank_bin_to_band_re++;
+ pFilterbank_bin_to_band_im++;
+
+ temp -= 0.3f;
+
+ if ( temp < 0.0f )
+ {
+ temp = 0;
+ }
+
+ if ( j < ( abs_active_bins + abs_start_offset ) && j >= abs_start_offset && alloc_fb_resp != -1 )
+ {
+ pFb->fb_bin_to_band.pFb_bin_to_band[i][idx++] = temp;
+ }
+
+ ppFilterbank_FRs_s[j] += temp;
+ }
+ }
+
+ for ( i = 0; i < frame_len; i++ )
+ {
+ if ( ppFilterbank_FRs_s[i] < 0.1f )
+ {
+ ppFilterbank_FRs_s[i] = 0.1f;
+ }
+ }
+
+ if ( alloc_fb_resp != -1 )
+ {
+ for ( j = 0; j < bands; j++ )
+ {
+ int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j];
+ int16_t abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[j];
+
+ for ( i = 0; i < abs_active_bins; i++ )
+ {
+ pFb->fb_bin_to_band.pFb_bin_to_band[j][i] /= ppFilterbank_FRs_s[i + abs_start_offset];
+ /*if(pFb->fb_bin_to_band.pFb_bin_to_band[j][i] > 0.5f)
+ {
+ num_active_bands = j + 1;
+ break;
+ }*/
+ }
+ }
+ }
+
+ return num_active_bands;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_active_bins()
+ *
+ *
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_get_active_bins(
+ const int16_t **pActive_bins,
+ const int16_t **pActive_bins_abs,
+ const int16_t **pStart_offset,
+ const int16_t **pStart_offset_abs,
+ const int32_t sampling_rate )
+{
+ int16_t sr_idx;
+
+ if ( sampling_rate == 32000 )
+ {
+ sr_idx = 1;
+ }
+ else if ( sampling_rate == 16000 )
+ {
+ sr_idx = 2;
+ }
+ else
+ {
+ sr_idx = 0;
+ }
+
+ *pActive_bins_abs = ivas_fb_abs_bins_per_band_12band_1ms[sr_idx];
+ *pActive_bins = ivas_fb_bins_per_band_12band_1ms[sr_idx];
+ *pStart_offset_abs = ivas_fb_abs_bins_start_offset_12band_1ms[sr_idx];
+ *pStart_offset = ivas_fb_bins_start_offset_12band_1ms[sr_idx];
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_filterbank_setup()
+ *
+ * Filterbank setup, initialization
+ *-----------------------------------------------------------------------------------------*/
+
+static ivas_error ivas_filterbank_setup(
+ IVAS_FB_MIXER_HANDLE hFbMixer,
+ const int32_t sampling_rate )
+{
+ int16_t i, j;
+ const float *pAll_fb_fr[2];
+ const int16_t *pAll_bins_start_offset = NULL;
+ const int16_t *pAll_bins_per_band = NULL;
+ const int16_t *pAll_bins_start_offset_abs = NULL;
+ const int16_t *pAll_bins_per_band_abs = NULL;
+ const int16_t *pAll_bins_per_band_48k = NULL;
+ ivas_error error;
+ IVAS_FB_CFG *pCfg = hFbMixer->fb_cfg;
+
+ error = IVAS_ERR_OK;
+
+ if ( pCfg->num_out_chans > 0 )
+ {
+ hFbMixer->pFb->filterbank_num_bands = ivas_get_num_bands( sampling_rate );
+
+ ivas_get_active_bins( &pAll_bins_per_band, &pAll_bins_per_band_abs, &pAll_bins_start_offset, &pAll_bins_start_offset_abs, sampling_rate );
+
+ if ( pCfg->fb_latency == NS2SA( sampling_rate, DELAY_FB_1_NS ) )
+ {
+ pAll_fb_fr[0] = ivas_fb_fr_12band_1ms_re;
+ pAll_fb_fr[1] = ivas_fb_fr_12band_1ms_im;
+ pAll_bins_per_band_48k = ivas_fb_bins_per_band_12band_1ms[0];
+ }
+ else
+ {
+ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong FB in ivas_filterbank_setup()!" );
+ }
+ }
+
+ hFbMixer->cross_fade_end_offset = pCfg->fade_len + pCfg->pcm_offset;
+ hFbMixer->cross_fade_start_offset = hFbMixer->cross_fade_end_offset - pCfg->fade_len;
+ hFbMixer->ana_window_offset = pCfg->fb_latency + pCfg->pcm_offset;
+
+ if ( ( error = ivas_fb_mixer_get_window( pCfg->fb_latency, sampling_rate, &( hFbMixer->pAna_window ) ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( ( error = ivas_fb_mixer_get_window( pCfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade ) ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( pCfg->num_out_chans > 0 )
+ {
+ ivas_filterbank_t *pFb = hFbMixer->pFb;
+ int16_t offset = 0;
+
+ pFb->fb_consts.pFilterbank_bins_per_band = pAll_bins_per_band;
+ pFb->fb_consts.pFilterbank_bins_start_offset = pAll_bins_start_offset;
+ pFb->fb_bin_to_band.pFb_active_bins_per_band = pAll_bins_per_band_abs;
+ pFb->fb_bin_to_band.pFb_start_bin_per_band = pAll_bins_start_offset_abs;
+
+ /* Initialization for short stride Parameter calculation and SPAR CLDFB reconstruction */
+ pFb->fb_bin_to_band.num_cldfb_bands = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f );
+ /*pFb->fb_bin_to_band.cldfb_stride = ( int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );*/ /* equals num_cldfb_bands*/
+ pFb->fb_bin_to_band.short_stride = (int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / 4 );
+ set_f( pFb->fb_bin_to_band.p_short_stride_bin_to_band, 0.0f, 2 * MDFT_FB_BANDS_240 );
+ set_s( pFb->fb_bin_to_band.p_cldfb_map_to_spar_band, 0, CLDFB_NO_CHANNELS_MAX );
+ set_s( pFb->fb_bin_to_band.p_spar_start_bands, 0, CLDFB_NO_CHANNELS_MAX );
+
+ for ( j = 0; j < IVAS_MAX_NUM_FB_BANDS; j++ )
+ {
+ pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j] = 0; /* aka num_active_bins per SPAR band */
+ pFb->fb_bin_to_band.p_short_stride_start_bin_per_band[j] = 0; /* first considered bin index per SPAR band */
+ pFb->fb_bin_to_band.pp_short_stride_bin_to_band[j] = NULL;
+ for ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ )
+ {
+ pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[i][j] = 0.0f;
+ }
+ }
+ if ( sampling_rate == 48000 )
+ {
+ for ( j = 0; j < pFb->filterbank_num_bands; j++ )
+ {
+ pFb->fb_consts.ppFilterbank_FRs[0][j] = &pAll_fb_fr[0][offset];
+ pFb->fb_consts.ppFilterbank_FRs[1][j] = &pAll_fb_fr[1][offset];
+ offset += pFb->fb_consts.pFilterbank_bins_per_band[j];
+ }
+
+ ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing );
+ }
+ else
+ {
+ float *ppFilterbank_FRs_re_temp[MAX_NUM_BANDS_DIFF_NON48K];
+ float *ppFilterbank_FRs_im_temp[MAX_NUM_BANDS_DIFF_NON48K];
+ int16_t active_bins_temp[MAX_NUM_BANDS_DIFF_NON48K];
+ int16_t start_offset_temp[MAX_NUM_BANDS_DIFF_NON48K];
+ int16_t num_diff_bands, start_diff_band_non48k;
+
+ num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K;
+ start_diff_band_non48k = pFb->filterbank_num_bands - num_diff_bands;
+
+ pFb->fb_consts.pFilterbank_bins_per_band = pAll_bins_per_band;
+ pFb->fb_consts.pFilterbank_bins_start_offset = pAll_bins_start_offset;
+
+ for ( j = 0; j < pFb->filterbank_num_bands; j++ )
+ {
+ int16_t num_active_bins = pFb->fb_consts.pFilterbank_bins_per_band[j];
+
+ if ( j < start_diff_band_non48k )
+ {
+ pFb->fb_consts.ppFilterbank_FRs[0][j] = &pAll_fb_fr[0][offset];
+ pFb->fb_consts.ppFilterbank_FRs[1][j] = &pAll_fb_fr[1][offset];
+ }
+ else
+ {
+ mvr2r( &pAll_fb_fr[0][offset], pFb->fb_consts.ppFilterbank_FRs_non48k[0][j], num_active_bins );
+ mvr2r( &pAll_fb_fr[1][offset], pFb->fb_consts.ppFilterbank_FRs_non48k[1][j], num_active_bins );
+ }
+
+ offset += pAll_bins_per_band_48k[j];
+ }
+
+ for ( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ )
+ {
+ ppFilterbank_FRs_re_temp[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k[0][j];
+ ppFilterbank_FRs_im_temp[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k[1][j];
+ active_bins_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_per_band[j];
+ start_offset_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_start_offset[j];
+ }
+
+ ivas_get_ld_fb_resp( ppFilterbank_FRs_re_temp, ppFilterbank_FRs_im_temp, ppFilterbank_FRs_re_temp, ppFilterbank_FRs_im_temp,
+ active_bins_temp, start_offset_temp, num_diff_bands, pCfg->fb_latency, sampling_rate );
+
+ for ( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ )
+ {
+ pFb->fb_consts.ppFilterbank_FRs[0][j] = (const float *) pFb->fb_consts.ppFilterbank_FRs_non48k[0][j];
+ pFb->fb_consts.ppFilterbank_FRs[1][j] = (const float *) pFb->fb_consts.ppFilterbank_FRs_non48k[1][j];
+ }
+
+ ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing );
+ }
+ }
+
+ return error;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_fb_mixer_get_window()
+ *
+ *
+ *-----------------------------------------------------------------------------------------*/
+
+static ivas_error ivas_fb_mixer_get_window(
+ const int16_t fade_len, /* i : window fading length in samples */
+ const int32_t sampling_rate, /* i : sampling rate */
+ const float **pWindow /* o : pointer to the window coefficents */
+)
+{
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ if ( fade_len == NS2SA( sampling_rate, DELAY_FB_4_NS ) )
+ {
+ switch ( sampling_rate )
+ {
+ case 48000:
+ *pWindow = ivas_fb_cf_4ms_48k;
+ break;
+ case 32000:
+ *pWindow = ivas_fb_cf_4ms_32k;
+ break;
+ case 16000:
+ *pWindow = ivas_fb_cf_4ms_16k;
+ break;
+ default:
+ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" );
+ }
+ }
+ else if ( fade_len == NS2SA( sampling_rate, DELAY_FB_1_NS ) )
+ {
+ switch ( sampling_rate )
+ {
+ case 48000:
+ *pWindow = ivas_fb_cf_1ms_48k;
+ break;
+ case 32000:
+ *pWindow = ivas_fb_cf_1ms_32k;
+ break;
+ case 16000:
+ *pWindow = ivas_fb_cf_1ms_16k;
+ break;
+ default:
+ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" );
+ }
+ }
+ else
+ {
+ IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Incorrect FB window fade len (%f ms)\n", ( fade_len / 1000000.f ) );
+ }
+
+ return error;
+}
+
+
+static const float *ivas_get_cheby_ramp(
+ const int16_t delay )
+{
+ const float *pCheby = NULL;
+
+ switch ( delay )
+ {
+ case IVAS_FB_1MS_32K_SAMP:
+ pCheby = ivas_fb_resp_cheby_ramp_32del;
+ break;
+ case IVAS_FB_1MS_16K_SAMP:
+ pCheby = ivas_fb_resp_cheby_ramp_16del;
+ break;
+ default:
+ assert( !"Unsupported cheby ramp length!" );
+ }
+
+ return pCheby;
+}
+
+
+/*get first half of the hanning window*/
+static void ivas_get_hanning_win(
+ const int16_t len,
+ float *pH_win )
+{
+ int16_t i;
+
+ for ( i = 0; i < len; i++ )
+ {
+ pH_win[i] = 0.5f * ( 1.0f - cosf( ( PI2 * ( i + 1 ) ) / ( ( 2 * len ) + 1 ) ) );
+ }
+
+ return;
+}
+
+
+static void ivas_get_ld_fb_resp(
+ float **ppIdeal_FRs_re,
+ float **ppIdeal_FRs_im,
+ float **ppNew_FRs_re,
+ float **ppNew_FRs_im,
+ const int16_t *pActive_bins,
+ const int16_t *pStart_offset,
+ const int16_t num_bands,
+ const int16_t delay,
+ const int32_t sampling_rate )
+{
+ int16_t b, s, frame_len;
+ const float *pCheby;
+
+ /*common scratch buffers for computing impulse/frequency responses,
+ pre-ring, post-ring and circular shifted outputs to optimize stack*/
+ float scratch1[L_FRAME32k * 2];
+ float scratch2[L_FRAME32k * 2];
+ float han_win[L_FRAME32k];
+
+ frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC );
+ pCheby = ivas_get_cheby_ramp( delay );
+ b = 0;
+ s = 0;
+
+ assert( sampling_rate == 32000 || sampling_rate == 16000 );
+
+ ivas_get_hanning_win( frame_len, han_win );
+ for ( b = 0; b < num_bands; b++ )
+ {
+ set_f( scratch2, 0, frame_len << 1 );
+ mvr2r( ppIdeal_FRs_re[b], &scratch2[pStart_offset[b]], pActive_bins[b] );
+ mvr2r( ppIdeal_FRs_im[b], &scratch2[frame_len + pStart_offset[b]], pActive_bins[b] );
+ ivas_imdft( scratch2, &scratch2[frame_len], scratch1, frame_len );
+
+ /*apply circular shift and hanning window*/
+
+ for ( s = delay; s < frame_len + delay; s++ )
+ {
+ scratch2[s - delay] = scratch1[s] * ( 1 - han_win[s - delay] );
+ }
+
+ for ( ; s < 2 * frame_len; s++ )
+ {
+ scratch2[s - delay] = scratch1[s] * han_win[s - ( frame_len + delay )];
+ }
+
+ for ( s = 0; s < delay; s++ )
+ {
+ scratch2[2 * frame_len - delay + s] = -1 * scratch1[s] * han_win[frame_len - delay + s];
+ }
+
+ /*apply heavy/cheby ramp window and compute pre ring*/
+
+ for ( s = 0; s < delay + 1; s++ )
+ {
+ scratch1[s] = scratch2[s] * pCheby[delay - s];
+ }
+
+ for ( ; s < frame_len; s++ )
+ {
+ scratch1[s] = 0;
+ }
+
+ for ( ; s < 2 * frame_len - delay; s++ )
+ {
+ scratch1[s] = scratch2[s];
+ }
+
+ for ( ; s < 2 * frame_len; s++ )
+ {
+ scratch1[s] = scratch2[s] * ( 1 - pCheby[s - ( 2 * frame_len - delay )] );
+ }
+
+ /*IR - pre ring + post ring*/
+ for ( s = 1; s < 2 * frame_len; s++ )
+ {
+ scratch2[s] = scratch2[s] /*pre ring*/ - scratch1[s] /*post ring*/ - scratch1[( 2 * frame_len ) - s];
+ }
+
+ for ( s = 0; s < 2 * frame_len - delay; s++ )
+ {
+ scratch1[s + delay] = scratch2[s];
+ }
+
+ for ( ; s < 2 * frame_len; s++ )
+ {
+ scratch1[s - ( 2 * frame_len - delay )] = -1 * ( scratch2[s] );
+ }
+
+ /* apply final window*/
+ for ( s = 0; s < delay; s++ )
+ {
+ scratch1[s] = scratch1[s] * sinf( ( EVS_PI * ( s + 1 ) ) / ( 2 * delay ) );
+ }
+
+ for ( s = 2 * delay; s < frame_len + 1; s++ )
+ {
+ scratch1[s] = scratch1[s] * sinf( ( EVS_PI * ( frame_len - s ) ) / ( 2 * ( frame_len + 1 - ( 2 * delay ) ) ) );
+ }
+
+ for ( ; s < 2 * frame_len; s++ )
+ {
+ scratch1[s] = 0;
+ }
+
+ /*compute frequency response*/
+ ivas_mdft( scratch1, scratch2, &scratch2[frame_len], frame_len << 1, frame_len );
+
+ mvr2r( &scratch2[pStart_offset[b]], ppNew_FRs_re[b], pActive_bins[b] );
+ mvr2r( &scratch2[frame_len + pStart_offset[b]], ppNew_FRs_im[b], pActive_bins[b] );
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters.c
new file mode 100644
index 0000000000000000000000000000000000000000..8344fe33f71ee1eff5a0ae036f7bfc77423a2abf
--- /dev/null
+++ b/lib_com/ivas_filters.c
@@ -0,0 +1,163 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_prot.h"
+#include "ivas_cnst.h"
+#include "ivas_stat_com.h"
+#include "wmc_auto.h"
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local functions declaration
+ *------------------------------------------------------------------------------------------*/
+
+static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage );
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_filters_init()
+ *
+ * Initialisation call for filtering a signal
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_filters_init(
+ ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */
+ const float *filt_coeff, /* i : filter coefficients */
+ const int16_t order ) /* i : filter order */
+{
+ int16_t i;
+ filter_state->order = order;
+
+ if ( order == IVAS_FILTER_ORDER_2 || order == IVAS_FILTER_ORDER_1 )
+ {
+ filter_state->filt_len = order + 1;
+
+ for ( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ )
+ {
+ filter_state->num[IVAS_FILTER_STAGE_0][i] = filt_coeff[i];
+ filter_state->den[IVAS_FILTER_STAGE_0][i] = filt_coeff[i + IVAS_BIQUAD_FILT_LEN];
+ }
+
+ filter_state->state[0][0] = 0.0f;
+ filter_state->state[0][1] = 0.0f;
+ filter_state->state[0][2] = 0.0f;
+ }
+ else
+ {
+ filter_state->filt_len = IVAS_BIQUAD_FILT_LEN;
+
+ for ( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ )
+ {
+ filter_state->num[IVAS_FILTER_STAGE_0][i] = filt_coeff[i];
+ filter_state->den[IVAS_FILTER_STAGE_0][i] = filt_coeff[i + IVAS_BIQUAD_FILT_LEN];
+ filter_state->num[IVAS_FILTER_STAGE_1][i] = filt_coeff[i + IVAS_BIQUAD_FILT_LEN * 2];
+ filter_state->den[IVAS_FILTER_STAGE_1][i] = filt_coeff[i + IVAS_BIQUAD_FILT_LEN * 3];
+ }
+
+ filter_state->state[0][0] = 0.0f;
+ filter_state->state[0][1] = 0.0f;
+ filter_state->state[0][2] = 0.0f;
+ filter_state->state[1][0] = 0.0f;
+ filter_state->state[1][1] = 0.0f;
+ filter_state->state[1][2] = 0.0f;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_filter_process()
+ *
+ * Process call for selecting the type filter
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_filter_process(
+ ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */
+ float *pIn_Out, /* i/o: signal subject to filtering */
+ const int16_t length /* i : filter order */
+)
+{
+
+ switch ( filter_state->order )
+ {
+ case IVAS_FILTER_ORDER_1:
+ case IVAS_FILTER_ORDER_2:
+ ivas_iir_2_filter( filter_state, pIn_Out, length, IVAS_FILTER_STAGE_0 );
+ break;
+ case IVAS_FILTER_ORDER_4:
+ /* biquad-1 */
+ ivas_iir_2_filter( filter_state, pIn_Out, length, IVAS_FILTER_STAGE_0 );
+ /* biquad-2 */
+ ivas_iir_2_filter( filter_state, pIn_Out, length, IVAS_FILTER_STAGE_1 );
+ break;
+ default:
+ break;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_iir_2_filter()
+ *
+ * Process call for filtering a signal
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_iir_2_filter(
+ ivas_filters_process_state_t *filter_state,
+ float *pIn_Out,
+ const int16_t length,
+ const int16_t stage )
+{
+ int16_t i, j;
+ float *pIn = pIn_Out;
+ float *pOut = pIn_Out;
+ float tmp_pIn_buf_i;
+
+ for ( i = 0; i < length; i++ )
+ {
+ tmp_pIn_buf_i = pIn[i];
+ pOut[i] = filter_state->state[stage][0] + pIn[i] * filter_state->num[stage][0];
+
+ for ( j = 1; j < filter_state->filt_len; j++ )
+ {
+ filter_state->state[stage][j - 1] = filter_state->state[stage][j] + filter_state->num[stage][j] * tmp_pIn_buf_i -
+ filter_state->den[stage][j] * pOut[i];
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..b8e919ad52b124285f299e0270fe980f431a3f8e
--- /dev/null
+++ b/lib_com/ivas_ism_com.c
@@ -0,0 +1,667 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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.h"
+#include "ivas_prot.h"
+#include "ivas_stat_com.h"
+#include "ivas_rom_com.h"
+#include "wmc_auto.h"
+
+
+/*-----------------------------------------------------------------------*
+ * Local constants
+ *-----------------------------------------------------------------------*/
+
+#define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC )
+
+#define BETA_ISM_LOW_IMP 0.6f
+#define BETA_ISM_MEDIUM_IMP 0.8f
+
+#define MAX_BRATE_TCX_32k 48000
+
+
+/*-------------------------------------------------------------------*
+ * bitbudget_to_brate()
+ *
+ * Convert bit-budget to bitrate
+ *-------------------------------------------------------------------*/
+
+void bitbudget_to_brate(
+ const int16_t x[], /* i : bitbudgets */
+ int32_t y[], /* o : bitrates */
+ const int16_t N /* i : number of entries to be converted */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < N; i++ )
+ {
+ y[i] = FRAMES_PER_SEC * x[i];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_ism_config()
+ *
+ * Configure audio objects coding
+ *-------------------------------------------------------------------*/
+
+ivas_error ivas_ism_config(
+ const int32_t ism_total_brate, /* i : ISM total bitrate */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t nchan_ism, /* i : number of objects */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ const int16_t ism_extended_metadata_flag, /* i : extended metadata flag */
+ const int16_t null_metadata_flag[MAX_NUM_OBJECTS], /* i : NULL MD flag */
+ const int16_t ism_imp[], /* i : ISM importance flags */
+ int32_t element_brate[], /* o : element bitrate per object */
+ int32_t total_brate[], /* o : total bitrate per object */
+ int16_t nb_bits_metadata[], /* i/o: number of metadata bits */
+ const int16_t combined_format_flag /* i : flag indicating combined format */
+)
+{
+ int16_t ch;
+ int16_t bits_element[MAX_NUM_OBJECTS], bits_CoreCoder[MAX_NUM_OBJECTS];
+ int16_t bits_ism, bits_side;
+ int16_t limit_high = 0; /* just to avoid compilation warning */
+ int16_t tmp;
+ int16_t ism_metadata_flag_global;
+ int16_t n_ISms;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+ if ( combined_format_flag )
+ {
+ n_ISms = nchan_ism;
+ }
+ else
+ {
+ n_ISms = nchan_transport;
+ }
+
+ /* initialization */
+ ism_metadata_flag_global = 0;
+ bits_side = 0;
+ if ( hIsmMeta != NULL )
+ {
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ ism_metadata_flag_global |= ism_imp[ch];
+ }
+ }
+
+ /* decision about bitrates per channel */
+ if ( combined_format_flag )
+ {
+ /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */
+ bits_ism = (int16_t) ( ism_total_brate / FRAMES_PER_SEC );
+ set_s( bits_element, bits_ism / n_ISms, n_ISms );
+ bits_element[n_ISms - 1] += bits_ism % n_ISms;
+
+ /* ISM common signaling bits are counted in MASA MD bit-budget */
+ }
+ else
+ {
+ /* ISM format: decision about bitrates per channel - constant during the session (at one ivas_total_brate) */
+ bits_ism = (int16_t) ( ism_total_brate / FRAMES_PER_SEC );
+ set_s( bits_element, bits_ism / n_ISms, n_ISms );
+ bits_element[n_ISms - 1] += bits_ism % n_ISms;
+ bitbudget_to_brate( bits_element, element_brate, n_ISms );
+
+ /* count ISm common signaling bits */
+ if ( hIsmMeta != NULL )
+ {
+ nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS + nchan_ism;
+
+ if ( ism_total_brate >= ISM_EXTENDED_METADATA_BRATE )
+ {
+ nb_bits_metadata[0] += ISM_EXTENDED_METADATA_BITS;
+
+ if ( ism_extended_metadata_flag )
+ {
+ nb_bits_metadata[0] += ISM_METADATA_IS_NDP_BITS;
+ }
+ }
+
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ if ( null_metadata_flag[ch] )
+ {
+ nb_bits_metadata[0] += ISM_METADATA_MD_FLAG_BITS;
+ nb_bits_metadata[0] += ISM_METADATA_FLAG_BITS;
+ }
+ else
+ {
+ if ( ism_imp[ch] == ISM_NO_META )
+ {
+ nb_bits_metadata[0] += ISM_METADATA_MD_FLAG_BITS;
+ nb_bits_metadata[0] += ISM_METADATA_INACTIVE_FLAG_BITS;
+ }
+ }
+ }
+ }
+ }
+
+ /* split metadata bitbudget equally between channels */
+ if ( nb_bits_metadata != NULL )
+ {
+ bits_side = sum_s( nb_bits_metadata, n_ISms );
+ set_s( nb_bits_metadata, bits_side / n_ISms, n_ISms );
+ nb_bits_metadata[n_ISms - 1] += bits_side % n_ISms;
+ v_sub_s( bits_element, nb_bits_metadata, bits_CoreCoder, n_ISms );
+ bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
+
+ mvs2s( nb_bits_metadata, nb_bits_metadata, n_ISms );
+ }
+
+ /* assign less CoreCoder bit-budget to inactive streams (at least one stream must be active) */
+ if ( ism_metadata_flag_global )
+ {
+ int16_t diff, n_higher, flag_higher[MAX_NUM_OBJECTS];
+
+ set_s( flag_higher, 1, MAX_NUM_OBJECTS );
+
+ diff = 0;
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ if ( ism_imp[ch] == ISM_NO_META )
+ {
+ diff += bits_CoreCoder[ch] - BITS_ISM_INACTIVE;
+ bits_CoreCoder[ch] = BITS_ISM_INACTIVE;
+ flag_higher[ch] = 0;
+ }
+ }
+
+ n_higher = sum_s( flag_higher, n_ISms );
+
+ if ( diff > 0 && n_higher > 0 )
+ {
+ tmp = diff / n_higher;
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ if ( flag_higher[ch] )
+ {
+ bits_CoreCoder[ch] += tmp;
+ }
+ }
+
+ tmp = diff % n_higher;
+ ch = 0;
+ while ( flag_higher[ch] == 0 )
+ {
+ ch++;
+ }
+ bits_CoreCoder[ch] += tmp;
+ }
+
+ bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
+
+ diff = 0;
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ int16_t limit;
+
+ limit = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC;
+ if ( element_brate[ch] < MIN_BRATE_SWB_STEREO ) /* replicate function set_bw() -> check the coded audio band-width */
+ {
+ limit = MIN_BRATE_WB_BWE / FRAMES_PER_SEC;
+ }
+ else if ( element_brate[ch] >= SCE_CORE_16k_LOW_LIMIT ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */
+ {
+ /*limit = SCE_CORE_16k_LOW_LIMIT;*/
+ limit = ( ACELP_16k_LOW_LIMIT + SWB_TBE_1k6 ) / FRAMES_PER_SEC;
+ }
+
+ if ( ism_imp[ch] == ISM_NO_META )
+ {
+ tmp = BITS_ISM_INACTIVE;
+ }
+ else if ( ism_imp[ch] == ISM_LOW_IMP )
+ {
+ tmp = (int16_t) ( BETA_ISM_LOW_IMP * bits_CoreCoder[ch] );
+ tmp = max( limit, tmp );
+ }
+ else if ( ism_imp[ch] == ISM_MEDIUM_IMP )
+ {
+ tmp = (int16_t) ( BETA_ISM_MEDIUM_IMP * bits_CoreCoder[ch] );
+ tmp = max( limit, tmp );
+ }
+ else /* ism_imp[ch] == ISM_HIGH_IMP */
+ {
+ tmp = bits_CoreCoder[ch];
+ }
+
+ diff += bits_CoreCoder[ch] - tmp;
+ bits_CoreCoder[ch] = tmp;
+ }
+
+ if ( diff > 0 && n_higher > 0 )
+ {
+ tmp = diff / n_higher;
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ if ( flag_higher[ch] )
+ {
+ bits_CoreCoder[ch] += tmp;
+ }
+ }
+
+ tmp = diff % n_higher;
+ ch = 0;
+ while ( flag_higher[ch] == 0 )
+ {
+ ch++;
+ }
+ bits_CoreCoder[ch] += tmp;
+ }
+
+ /* verify for the maximum bitrate @12.8kHz core */
+ diff = 0;
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ limit_high = IVAS_512k / FRAMES_PER_SEC;
+ if ( element_brate[ch] < SCE_CORE_16k_LOW_LIMIT ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */
+ {
+ limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
+ }
+
+ tmp = (int16_t) min( bits_CoreCoder[ch], limit_high );
+
+ diff += bits_CoreCoder[ch] - tmp;
+ bits_CoreCoder[ch] = tmp;
+ }
+
+ /* limitation to avoid too high bitrate in one active TCX channel */
+ if ( element_brate[0] >= SCE_CORE_16k_LOW_LIMIT && element_brate[0] <= IVAS_32k )
+ {
+ diff = 0;
+ limit_high = MAX_BRATE_TCX_32k / FRAMES_PER_SEC;
+
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ tmp = (int16_t) min( bits_CoreCoder[ch], limit_high );
+
+ diff += bits_CoreCoder[ch] - tmp;
+ bits_CoreCoder[ch] = tmp;
+ }
+ }
+
+ if ( diff > 0 )
+ {
+ ch = 0;
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ if ( flag_higher[ch] == 0 )
+ {
+ if ( diff > limit_high )
+ {
+ diff += bits_CoreCoder[ch] - limit_high;
+ bits_CoreCoder[ch] = limit_high;
+ }
+ else
+ {
+ bits_CoreCoder[ch] += diff;
+
+ if ( combined_format_flag )
+ {
+ diff = 0;
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ if ( combined_format_flag )
+ {
+ if ( diff > 0 )
+ {
+ for ( ch = 0; ch < n_ISms; ch++ )
+ {
+ if ( ism_imp[ch] <= ISM_MEDIUM_IMP )
+ {
+ if ( diff > limit_high )
+ {
+ diff += bits_CoreCoder[ch] - limit_high;
+ bits_CoreCoder[ch] = limit_high;
+ }
+ else
+ {
+ bits_CoreCoder[ch] += diff;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
+ }
+
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_ism_reset_metadata()
+ *
+ * Reset ISM metadata parameters
+ *-------------------------------------------------------------------*/
+
+void ivas_ism_reset_metadata(
+ ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */
+)
+{
+ hIsmMeta->azimuth = 0.0f;
+ hIsmMeta->elevation = 0.0f;
+ hIsmMeta->yaw = 0.0f;
+ hIsmMeta->pitch = 0.0f;
+ hIsmMeta->radius = 1.0f;
+ hIsmMeta->ism_metadata_flag = 0;
+ hIsmMeta->non_diegetic_flag = 0;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_ism_reset_metadata_API()
+ *
+ * Reset ISM metadata parameters
+ *-------------------------------------------------------------------*/
+
+void ivas_ism_reset_metadata_API(
+ ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */
+)
+{
+ ivas_ism_reset_metadata( hIsmMeta );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ism_quant_meta()
+ *
+ * three-level uniform scalar quantizer for ISM metadata
+ *-------------------------------------------------------------------*/
+
+/*! r: index of the winning codeword */
+int16_t ism_quant_meta(
+ const float val, /* i : scalar value to quantize */
+ float *valQ, /* o : quantized value */
+ const float borders[], /* i : level borders */
+ const float q_step, /* i : quantization step */
+ const float q_step_border, /* i : quantization step at the border */
+ const int16_t cbsize /* i : codebook size */
+)
+{
+ int16_t idx, idx_start;
+ float qlow, step;
+
+ if ( val <= borders[1] )
+ {
+ qlow = borders[0];
+ idx_start = 0;
+ step = q_step_border;
+ }
+ else if ( val <= borders[2] )
+ {
+ qlow = borders[1];
+ idx_start = (int16_t) ( ( borders[1] - borders[0] ) / q_step_border );
+ step = q_step;
+ }
+ else
+ {
+ qlow = borders[2];
+ idx_start = (int16_t) ( cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border );
+ step = q_step_border;
+ }
+
+ idx = idx_start + (int16_t) max( 0.f, min( cbsize - 1, ( ( val - qlow ) / step + 0.5f ) ) );
+ *valQ = ( idx - idx_start ) * step + qlow;
+
+ return idx;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ism_dequant_meta()
+ *
+ * three-level uniform scalar dequantizer for ISM metadata
+ *-------------------------------------------------------------------*/
+
+/*! r: dequantized value */
+float ism_dequant_meta(
+ const int16_t idx, /* i : quantizer index */
+ const float borders[], /* i : level borders */
+ const float q_step, /* i : quantization step */
+ const float q_step_border, /* i : quantization step at the border */
+ const int16_t cbsize /* i : codebook size */
+)
+{
+ int16_t idx_start;
+ float qlow, step, valQ;
+
+ if ( idx <= ( borders[1] - borders[0] ) / q_step_border )
+ {
+ qlow = borders[0];
+ idx_start = 0;
+ step = q_step_border;
+ }
+ else if ( idx <= cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border )
+ {
+ qlow = borders[1];
+ idx_start = (int16_t) ( ( borders[1] - borders[0] ) / q_step_border );
+ step = q_step;
+ }
+ else
+ {
+ qlow = borders[2];
+ idx_start = (int16_t) ( cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border );
+ step = q_step_border;
+ }
+
+ valQ = ( idx - idx_start ) * step + qlow;
+
+ return valQ;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_param_ism_config()
+ *
+ *
+ * ---------------------------------------------------------------*/
+
+void ivas_param_ism_config(
+ PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */
+ const int16_t nchan_obj /* i : number of ISM channels */
+)
+{
+ int16_t i;
+
+ hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
+
+ for ( i = 0; i < hParamIsm->nbands; i++ )
+ {
+ hParamIsm->nblocks[i] = MAX_PARAM_ISM_NBLOCKS;
+ }
+
+ /* for elevation zero compute the max azi quantization indices */
+ for ( i = 0; i < nchan_obj; i++ )
+ {
+ hParamIsm->last_az_diff[i] = 0;
+ hParamIsm->last_az_sgn[i] = 1;
+ hParamIsm->last_el_diff[i] = 0;
+ hParamIsm->last_el_sgn[i] = 1;
+ }
+
+ hParamIsm->last_dmx_gain = 1.0f;
+ set_f( hParamIsm->last_cardioid_left, 1.0f, MAX_NUM_OBJECTS );
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_ism_mode_select()
+ *
+ * selects the ISM mode base on bitrate and number of objects
+ * ---------------------------------------------------------------*/
+
+/*! r : ISM format mode */
+ISM_MODE ivas_ism_mode_select(
+ const int16_t nchan_inp, /* i : number of input objects */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ ISM_MODE ism_mode = ISM_MODE_NONE;
+
+ if ( nchan_inp > 2 && ivas_total_brate <= ACELP_32k )
+ {
+ ism_mode = ISM_MODE_PARAM;
+ }
+ else
+ {
+ ism_mode = ISM_MODE_DISC;
+ }
+
+ return ism_mode;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_ism_metadata_close()
+ *
+ * Deallocate ISM metadata handles
+ * ---------------------------------------------------------------*/
+
+void ivas_ism_metadata_close(
+ ISM_METADATA_HANDLE hIsmMetaData[], /* i/o: object metadata handles */
+ const int16_t first_idx /* i : index of first handle to deallocate */
+)
+{
+ int16_t n;
+
+#ifdef FIX_852_FIX_HANDLE_DEREF
+ if ( hIsmMetaData == NULL || *hIsmMetaData == NULL )
+#else
+ if ( hIsmMetaData == NULL || hIsmMetaData == NULL )
+#endif
+ {
+ return;
+ }
+
+ for ( n = first_idx; n < MAX_NUM_OBJECTS; n++ )
+ {
+ if ( hIsmMetaData[n] != NULL )
+ {
+ free( hIsmMetaData[n] );
+ hIsmMetaData[n] = NULL;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * update_last_metadata()
+ *
+ * Store last metadata values
+ *-------------------------------------------------------------------*/
+
+void update_last_metadata(
+ const int16_t nchan_ism, /* i : number of objects */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ const int16_t updt_flag[] /* i : last metadata update flag */
+)
+{
+ int16_t ch;
+
+ for ( ch = 0; ch < nchan_ism; ch++ )
+ {
+ if ( updt_flag[ch] == 1 )
+ {
+ hIsmMeta[ch]->last_azimuth = hIsmMeta[ch]->azimuth;
+ hIsmMeta[ch]->last_elevation = hIsmMeta[ch]->elevation;
+ }
+ }
+
+ return;
+}
+
+
+/*----------------------------------------------------------------*
+ * ivas_get_ism_sid_quan_bitbudget()
+ *
+ * Set quantization bits based on the number of coded objects
+ *----------------------------------------------------------------*/
+
+void ivas_get_ism_sid_quan_bitbudget(
+ const int16_t nchan_ism, /* i : number of objects */
+ int16_t *nBits_azimuth, /* o : number of Q bits for azimuth */
+ int16_t *nBits_elevation, /* o : number of Q bits for elevation */
+ float *q_step, /* o : quantization step */
+ float *q_step_border, /* o : quantization step at the border */
+ int16_t *nBits_coh, /* o : number of Q bits for coherence */
+ int16_t *nBits_sce_id /* o : number of Q bits for sce_id_dtx */
+)
+{
+ *nBits_azimuth = ISM_DTX_AZI_BITS_HIGH;
+ *nBits_elevation = ISM_DTX_ELE_BITS_HIGH;
+ *q_step = ISM_Q_STEP_HIGH;
+ *q_step_border = ISM_Q_STEP_BORDER_HIGH;
+ *nBits_coh = ISM_DTX_COH_SCA_BITS;
+ *nBits_sce_id = 1;
+
+ if ( nchan_ism >= 3 )
+ {
+ *nBits_azimuth = ISM_DTX_AZI_BITS_LOW;
+ *nBits_elevation = ISM_DTX_ELE_BITS_LOW;
+ *q_step = ISM_Q_STEP_LOW;
+ *q_step_border = ISM_Q_STEP_BORDER_LOW;
+ *nBits_sce_id = 2;
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_lfe_com.c b/lib_com/ivas_lfe_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..6b323a13c45df500df31f23e9a6d02091c94e96a
--- /dev/null
+++ b/lib_com/ivas_lfe_com.c
@@ -0,0 +1,139 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "math.h"
+#include "options.h"
+#include "ivas_stat_com.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "rom_com.h"
+#include "ivas_rom_com.h"
+#include "cnst.h"
+#include
+#include "wmc_auto.h"
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_lfe_lpf_select_filt_coeff()
+ *
+ * Selects LFE filter coeff based on config.
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_lfe_lpf_select_filt_coeff(
+ const int32_t sampling_rate, /* i : sampling rate */
+ const int16_t order, /* i : filter order */
+ const float **ppFilt_coeff /* o : filter coefficients */
+)
+{
+ switch ( order )
+ {
+ case IVAS_FILTER_ORDER_2:
+ switch ( sampling_rate )
+ {
+ case 16000:
+ *ppFilt_coeff = ivas_lpf_2_butter_16k;
+ break;
+ case 32000:
+ *ppFilt_coeff = ivas_lpf_2_butter_32k;
+ break;
+ case 48000:
+ *ppFilt_coeff = ivas_lpf_2_butter_48k;
+ break;
+ default:
+ break;
+ }
+ break;
+ case IVAS_FILTER_ORDER_4:
+ switch ( sampling_rate )
+ {
+ case 16000:
+ *ppFilt_coeff = ivas_lpf_4_butter_16k_sos;
+ break;
+ case 32000:
+ *ppFilt_coeff = ivas_lpf_4_butter_32k_sos;
+ break;
+ case 48000:
+ *ppFilt_coeff = ivas_lpf_4_butter_48k_sos;
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ assert( !"Unsupported LFE Filter order" );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_lfe_window_init()
+ *
+ * Initialize LFE window
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_lfe_window_init(
+ LFE_WINDOW_HANDLE hLFEWindow, /* i/o: LFE window handle */
+ const int32_t sampling_rate, /* i : sampling rate */
+ const int16_t frame_len /* i : frame length in samples */
+)
+{
+ /* Set window coefficients */
+ if ( sampling_rate == 48000 )
+ {
+ hLFEWindow->pWindow_coeffs = ivas_lfe_window_coeff_48k;
+ }
+ else if ( sampling_rate == 32000 )
+ {
+ hLFEWindow->pWindow_coeffs = ivas_lfe_window_coeff_32k;
+ }
+ else if ( sampling_rate == 16000 )
+ {
+ hLFEWindow->pWindow_coeffs = ivas_lfe_window_coeff_16k;
+ }
+ else
+ {
+ assert( !"8kHz LFE Window not supported" );
+ }
+
+ /* 10ms stride, MDCT will be done in two iterations */
+ hLFEWindow->dct_len = frame_len >> 1;
+
+ /* 8ms of latency */
+ hLFEWindow->fade_len = NS2SA( sampling_rate, IVAS_LFE_FADE_NS );
+ hLFEWindow->zero_pad_len = (int16_t) ( IVAS_ZERO_PAD_LEN_MULT_FAC * ( hLFEWindow->dct_len - hLFEWindow->fade_len ) );
+ hLFEWindow->full_len = hLFEWindow->zero_pad_len + hLFEWindow->fade_len + hLFEWindow->dct_len;
+
+ return;
+}
diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..abb4dbd552c9c4ed956ce146329474da464e679b
--- /dev/null
+++ b/lib_com/ivas_masa_com.c
@@ -0,0 +1,994 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include
+#include "prot.h"
+#include "ivas_cnst.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
+#include "ivas_stat_dec.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------
+ * Local constants
+ *---------------------------------------------------------------*/
+
+#define MASA_EXTRA_BAND_META_BITS 40
+
+#define MASA_SMALL_INC_META_BITS 10
+
+
+/*---------------------------------------------------------------
+ * Local prototypes
+ *---------------------------------------------------------------*/
+
+static int16_t quantize_theta_masa( float x, const int16_t no_cb, float *xhat );
+
+static int16_t quantize_phi_masa( float phi, const int16_t flag_delta, float *phi_hat, const int16_t n );
+
+
+/*---------------------------------------------------------------
+ * ivas_masa_setup()
+ *
+ * Set-up MASA coding elements and bitrates
+ *---------------------------------------------------------------*/
+
+void ivas_masa_set_elements(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t mc_mode, /* i : MC format mode */
+ const int16_t nchan_transport, /* i : number of MASA input/transport channels */
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ int16_t *element_mode, /* o : element mode */
+ int16_t *nSCE, /* o : number of SCEs */
+ int16_t *nCPE, /* o : number of CPEs */
+ const int16_t ivas_format, /* i : IVAS format */
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ const int32_t ism_total_brate /* i : initial ISM total bitrate */
+)
+{
+ if ( nchan_transport == 2 )
+ {
+ if ( ivas_total_brate >= MCMASA_SEPARATE_BRATE && mc_mode == MC_MODE_MCMASA )
+ {
+ *nCPE = 1;
+ *nSCE = 1;
+
+ *element_mode = IVAS_SCE; /* This is needed for the initialization phase to initialize codec mode to SCE, since it is written first to the file*/
+ }
+ else if ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE )
+ {
+ *nCPE = 1;
+
+ if ( *element_mode == -1 )
+ {
+ *element_mode = IVAS_CPE_DFT; /* To have it initialized in case it was not already. */
+ }
+ if ( ivas_total_brate > MIN_BRATE_MDCT_STEREO )
+ {
+ *element_mode = IVAS_CPE_MDCT;
+ if ( ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) && ( ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) )
+ {
+ *element_mode = IVAS_CPE_DFT;
+ }
+ }
+ }
+ else
+ {
+ *nCPE = 1;
+ *nSCE = 0;
+
+ if ( ivas_total_brate > MIN_BRATE_MDCT_STEREO )
+ {
+ *element_mode = IVAS_CPE_MDCT;
+ }
+ }
+ hQMetaData->bits_frame_nominal = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC );
+ if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) )
+ {
+ hQMetaData->bits_frame_nominal -= (int16_t) ( ism_total_brate / FRAMES_PER_SEC );
+ }
+ }
+ else if ( nchan_transport == 1 )
+ {
+ *nCPE = 0;
+ *nSCE = 1;
+
+ if ( ivas_total_brate == IVAS_13k2 )
+ {
+ hQMetaData->bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC;
+ }
+ else if ( ivas_total_brate <= IVAS_16k4 )
+ {
+ hQMetaData->bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC;
+ }
+ else if ( ivas_total_brate <= IVAS_24k4 )
+ {
+ hQMetaData->bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC;
+ }
+ else if ( ivas_total_brate <= IVAS_32k )
+ {
+ hQMetaData->bits_frame_nominal = ACELP_24k40 / FRAMES_PER_SEC;
+ }
+ else
+ {
+ hQMetaData->bits_frame_nominal = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC );
+ }
+ *element_mode = IVAS_SCE;
+ }
+ else
+ {
+ assert( !"MASA number of transport channels must be 1, or 2" );
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * generate_gridEq()
+ *
+ * generate Spherical grid
+ *---------------------------------------------------------------*/
+
+void generate_gridEq(
+ SPHERICAL_GRID_DATA *data /* o : data structure for grid */
+)
+{
+ int32_t cum_n, cum_n_prev;
+ float theta;
+ int16_t i;
+ int16_t *n;
+
+ n = data->no_phi;
+ n[0] = MASA_NO_POINTS_EQUATOR;
+
+ cum_n_prev = 0;
+
+ for ( i = 1; i < MASA_NO_CIRCLES; i++ )
+ {
+ theta = MASA_ANGLE_AT_EQUATOR * (float) ( i + 0.5f );
+ if ( i == 1 )
+ {
+ cum_n = 2 * (int32_t) ceilf( MASA_NTOT2_FAC * ( sinf( theta ) - MASA_ASIN_OFFSET ) );
+ }
+ else
+ {
+ cum_n = 2 * (int32_t) roundf( MASA_NTOT2_FAC * ( sinf( theta ) - MASA_ASIN_OFFSET ) );
+ }
+ n[i] = (int16_t) ( ( cum_n - cum_n_prev ) >> 1 );
+ cum_n_prev = cum_n;
+ }
+ n[i] = 1;
+ data->no_theta = i + 1;
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_masa_set_coding_config()
+ *
+ * Sets MASA codec parameters based on bitrate, number of directions,
+ * and other metadata properties.
+ *---------------------------------------------------------------*/
+
+void ivas_masa_set_coding_config(
+ MASA_CODEC_CONFIG *config, /* i/o: MASA coding config structure */
+ int16_t *band_mapping, /* o : Band mapping used */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t nchan_transport, /* i : number of transport channels (mono/stereo) */
+ const uint8_t isMcMasa /* i : toggle for selecting mcMASA specific config */
+)
+{
+ int16_t i;
+ uint8_t nbands;
+ uint8_t nTwoDirBands;
+ const int16_t *masa_bits_table;
+
+ /* When coming into this function, these values should be already set:
+ * joinedSubframes;
+ * useCoherence;
+ * numberOfDirections;
+ */
+
+ /* Setup coding parameters based on the bitrate, transport channel count, subframe metadata information,
+ * and number of directions in metadata. */
+ nbands = 0;
+ nTwoDirBands = 0;
+ i = 0;
+
+ /* First select correct bit budget table */
+ masa_bits_table = masa_bits;
+ if ( isMcMasa )
+ {
+ masa_bits_table = mcmasa_bits;
+ }
+ else if ( ivas_total_brate < IVAS_48k && nchan_transport == 2 )
+ {
+ masa_bits_table = masa_bits_LR_stereo;
+ }
+
+ while ( nbands == 0 && i < IVAS_NUM_ACTIVE_BRATES )
+ {
+ if ( ivas_total_brate <= ivas_brate_tbl[i + SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES] )
+ {
+ int16_t idx_bands;
+ if ( ivas_total_brate < IVAS_48k && nchan_transport == 2 && i > 3 )
+ {
+ /* because it uses the bitallocation for the lower bit rates from 'masa_bits_LR_stereo' and it has 4 elements */
+ i = 3;
+ }
+ idx_bands = i;
+
+ if ( config->numberOfDirections > 1 )
+ {
+ nTwoDirBands = config->joinedSubframes ? masa_twodir_bands_joined[i] : masa_twodir_bands[i];
+
+ if ( ( ivas_total_brate > IVAS_96k && !config->joinedSubframes ) || ( ivas_total_brate > IVAS_80k && config->joinedSubframes ) )
+ {
+ idx_bands--;
+ }
+ }
+
+ if ( config->joinedSubframes )
+ {
+ nbands = masa_joined_nbands[idx_bands];
+ }
+ else
+ {
+ nbands = masa_nbands[idx_bands];
+ }
+
+ config->max_metadata_bits = masa_bits_table[i];
+
+ if ( ivas_total_brate == IVAS_64k && config->numberOfDirections > 1 )
+ {
+ /* At 64k, we increase metadata bit budget when there is two directions present. */
+ config->max_metadata_bits += MASA_EXTRA_BAND_META_BITS;
+ }
+
+ if ( ( ( ivas_total_brate == IVAS_32k && nchan_transport == 2 ) || ivas_total_brate == IVAS_48k ) && config->joinedSubframes )
+ {
+ /* At 32k and 48k, we increase metadata bit budget when joinedSubframes. */
+ config->max_metadata_bits += ( MASA_SMALL_INC_META_BITS );
+ }
+ }
+ i++;
+ }
+ config->numCodingBands = nbands;
+ config->numTwoDirBands = nTwoDirBands;
+
+ if ( config->joinedSubframes == TRUE )
+ {
+ config->mergeRatiosOverSubframes = FALSE;
+ }
+ else
+ {
+ config->mergeRatiosOverSubframes = TRUE;
+ }
+
+ /* Setup frequency band mapping based on the number of used coding bands */
+ switch ( config->numCodingBands )
+ {
+ case 5:
+ mvs2s( MASA_band_mapping_24_to_5, band_mapping, 5 + 1 );
+ break;
+ case 8:
+ mvs2s( MASA_band_mapping_24_to_8, band_mapping, 8 + 1 );
+ break;
+ case 12:
+ mvs2s( MASA_band_mapping_24_to_12, band_mapping, 12 + 1 );
+ break;
+ case 18:
+ mvs2s( MASA_band_mapping_24_to_18, band_mapping, 18 + 1 );
+ break;
+ case MASA_FREQUENCY_BANDS:
+ /* With input count of bands, no mapping is needed but for unified processing later, we store normal mapping */
+ for ( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ )
+ {
+ band_mapping[i] = i;
+ }
+ break;
+ default:
+ assert( 0 && "Error: The number of MASA coding bands is not supported" );
+ }
+
+ config->useCoherence = TRUE;
+ if ( ( !isMcMasa && ivas_total_brate < IVAS_48k ) || ( isMcMasa && ivas_total_brate < IVAS_16k4 ) )
+ {
+ config->useCoherence = FALSE;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * masa_sample_rate_band_correction()
+ *
+ *
+ *---------------------------------------------------------------*/
+
+void masa_sample_rate_band_correction(
+ MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */
+ int16_t *band_mapping, /* i/o: Band mapping used and modified */
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: QMetadata structure for modification */
+ const uint8_t maxBand, /* i : max band */
+ uint8_t is_encoder, /* i : signals if called at encoder */
+ MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */
+)
+{
+ uint8_t band, sf;
+ int16_t highBand;
+ uint8_t numBands48k;
+
+ numBands48k = config->numCodingBands;
+
+ for ( band = 1; band < config->numCodingBands + 1; band++ )
+ {
+ highBand = band_mapping[band];
+
+ if ( highBand >= maxBand )
+ {
+ config->numCodingBands = band;
+ hQMetaData->numCodingBands = band;
+
+ if ( is_encoder )
+ {
+ if ( hQMetaData->q_direction->cfg.nbands > band )
+ {
+ hQMetaData->q_direction->cfg.nbands = band;
+ }
+ if ( hQMetaData->no_directions == 2 && hQMetaData->q_direction[1].cfg.nbands > band )
+ {
+ hQMetaData->q_direction[1].cfg.nbands = band;
+ }
+ }
+
+ band_mapping[band] = maxBand;
+
+ break;
+ }
+ }
+
+ /* Set rest of the bands to zero in qmetadata. */
+ for ( ; band < numBands48k; band++ )
+ {
+ for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
+ {
+ hQMetaData->q_direction[0].band_data[band].azimuth[sf] = 0.0f;
+ hQMetaData->q_direction[0].band_data[band].elevation[sf] = 0.0f;
+ hQMetaData->q_direction[0].band_data[band].energy_ratio[sf] = 0.0f;
+
+ if ( hQMetaData->coherence_flag && hQMetaData->q_direction[0].coherence_band_data != NULL )
+ {
+ hQMetaData->q_direction[0].coherence_band_data[band].spread_coherence[sf] = 0u;
+ }
+
+ if ( hQMetaData->no_directions == 2 )
+ {
+ hQMetaData->q_direction[1].band_data[band].azimuth[sf] = 0.0f;
+ hQMetaData->q_direction[1].band_data[band].elevation[sf] = 0.0f;
+ hQMetaData->q_direction[1].band_data[band].energy_ratio[sf] = 0.0f;
+
+ if ( hQMetaData->coherence_flag && hQMetaData->q_direction[1].coherence_band_data != NULL )
+ {
+ hQMetaData->q_direction[1].coherence_band_data[band].spread_coherence[sf] = 0u;
+ }
+ }
+
+ if ( hQMetaData->coherence_flag && hQMetaData->surcoh_band_data != NULL )
+ {
+ hQMetaData->surcoh_band_data[band].surround_coherence[sf] = 0u;
+ }
+ }
+
+ if ( hQMetaData->no_directions == 2 )
+ {
+ hQMetaData->twoDirBands[band] = 0;
+ }
+ }
+
+ if ( hExtOutMeta != NULL )
+ {
+ /* in decoder, zero the EXT out MASA meta buffer */
+ for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
+ {
+ for ( band = hQMetaData->numCodingBands; band < MASA_FREQUENCY_BANDS; band++ )
+ {
+ hExtOutMeta->directionIndex[0][sf][band] = SPH_IDX_FRONT;
+ hExtOutMeta->directToTotalRatio[0][sf][band] = 0u;
+ hExtOutMeta->spreadCoherence[0][sf][band] = 0u;
+
+ hExtOutMeta->directionIndex[1][sf][band] = SPH_IDX_FRONT;
+ hExtOutMeta->directToTotalRatio[1][sf][band] = 0u;
+ hExtOutMeta->spreadCoherence[1][sf][band] = 0u;
+
+ hExtOutMeta->surroundCoherence[sf][band] = 0u;
+ hExtOutMeta->diffuseToTotalRatio[sf][band] = UINT8_MAX;
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * index_theta_phi_16()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+/*! r: output index for direction */
+uint16_t index_theta_phi_16(
+ float *p_theta, /* i/o: input elevation to be indexed */
+ float *p_phi, /* i/o: input azimuth to be indexed */
+ const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */
+)
+{
+ float abs_theta;
+ int16_t sign_th, id_phi, id_th;
+ uint16_t idx_sph;
+ uint16_t cum_n;
+ float theta_hat, phi_hat;
+ float theta, phi;
+
+ theta = *p_theta;
+ phi = *p_phi;
+ phi_hat = 0;
+ theta_hat = 0;
+ phi = phi + 180;
+
+ if ( theta < 0 )
+ {
+ abs_theta = -theta;
+ sign_th = -1;
+ }
+ else
+ {
+ abs_theta = theta;
+ sign_th = 1;
+ }
+
+ id_th = quantize_theta_masa( abs_theta, gridData->no_theta, &theta_hat );
+ if ( gridData->no_theta > 1 )
+ {
+ if ( gridData->no_phi[id_th] > 1 )
+ {
+ id_phi = quantize_phi_masa( phi, ( id_th % 2 == 1 ), &phi_hat, gridData->no_phi[id_th] );
+ }
+ else
+ {
+ id_phi = 0;
+ phi_hat = 180;
+ }
+ }
+ else
+ {
+ id_phi = quantize_phi_masa( phi, ( id_th % 2 == 1 ), &phi_hat, gridData->no_phi[id_th] );
+ }
+ *p_theta = sign_th * theta_hat;
+ *p_phi = phi_hat - 180;
+
+ /* Starting from Equator, alternating positive and negative */
+ if ( id_th == 0 )
+ {
+ idx_sph = id_phi;
+ }
+ else
+ {
+ if ( id_th == gridData->no_theta - 1 )
+ {
+ idx_sph = 65534 + ( sign_th < 0 );
+ }
+ else
+ {
+ theta = MASA_ANGLE_AT_EQUATOR * (float) ( id_th + 0.5f );
+ if ( id_th == 1 )
+ {
+ cum_n = 2 * (uint16_t) ceilf( MASA_NTOT2_FAC * ( sinf( theta ) - MASA_ASIN_OFFSET ) );
+ }
+ else
+ {
+ cum_n = 2 * (uint16_t) roundf( MASA_NTOT2_FAC * ( sinf( theta ) - MASA_ASIN_OFFSET ) );
+ }
+
+ cum_n += gridData->no_phi[0];
+
+ if ( sign_th > 0 )
+ {
+ cum_n -= 2 * gridData->no_phi[id_th];
+ }
+ else
+ {
+ cum_n -= gridData->no_phi[id_th];
+ }
+ idx_sph = cum_n + id_phi;
+ }
+ }
+
+ return idx_sph;
+}
+
+
+/*-------------------------------------------------------------------------
+ * quantize_phi_masa()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+/*! r: output index */
+static int16_t quantize_theta_masa(
+ float x, /* i : theta value to be quantized */
+ const int16_t no_cb, /* i : number of codewords */
+ float *xhat /* o : quantized value */
+)
+{
+ int16_t imin;
+ float diff1, diff2;
+
+ imin = (int16_t) ( x * MASA_INV_ANGLE_AT_EQUATOR_DEG + 0.5f );
+
+ if ( imin >= no_cb - 1 )
+ {
+ imin = no_cb - 1;
+ diff1 = x - 90;
+ diff2 = x - MASA_ANGLE_AT_EQUATOR_DEG * ( imin - 1 );
+ if ( fabsf( diff1 ) > fabsf( diff2 ) )
+ {
+ imin--;
+ *xhat = imin * MASA_ANGLE_AT_EQUATOR_DEG;
+ }
+ else
+ {
+ *xhat = 90;
+ }
+ }
+ else
+ {
+ *xhat = imin * MASA_ANGLE_AT_EQUATOR_DEG;
+ }
+
+ return imin;
+}
+
+
+/*-------------------------------------------------------------------------
+ * quantize_phi_masa()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+/*! r: index azimuth */
+static int16_t quantize_phi_masa(
+ float phi, /* i : azimuth value */
+ const int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */
+ float *phi_hat, /* o : quantized azimuth */
+ const int16_t n /* i : azimuth codebook size */
+)
+{
+ int16_t id_phi;
+ float dd;
+ float delta_phi;
+
+ delta_phi = 360.0f / (float) n;
+
+ if ( n == 1 )
+ {
+ *phi_hat = 0;
+
+ return 0;
+ }
+
+ if ( flag_delta == 1 )
+ {
+ dd = delta_phi / 2.0f;
+ }
+ else
+ {
+ dd = 0;
+ }
+
+ id_phi = (int16_t) ( ( phi - dd + delta_phi / 2.0f ) / (float) delta_phi );
+
+ if ( id_phi == n )
+ {
+ id_phi = 0;
+ }
+
+ if ( id_phi == -1 )
+ {
+ id_phi = n - 1;
+ }
+
+ *phi_hat = id_phi * delta_phi + dd;
+
+ return id_phi;
+}
+
+
+/*-------------------------------------------------------------------------
+ * deindex_sph_idx()
+ *
+ * deindex the MASA metadata from the input metadata file
+ *------------------------------------------------------------------------*/
+
+void deindex_sph_idx(
+ const uint16_t sphIndex, /* i : Spherical index */
+ const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */
+ float *theta, /* o : Elevation */
+ float *phi /* o : Azimuth */
+)
+{
+ float ba_crt, del_crt, div_crt, a4_crt;
+ float estim;
+ int32_t base_low, base_up;
+ int16_t n_crt;
+ int16_t id_th;
+ int16_t sign_theta;
+ int16_t id_phi;
+ int16_t no_th = gridData->no_theta;
+ const int16_t *n = gridData->no_phi;
+ const float ba[3] = { 2.137991118026424e+02f, 1.244854404591542e+02f, 1.228408647140870e+02f };
+ const float del[3] = { 7.998262115303199e+05f, 1.300883976959332e+06f, 1.424072242426373e+06f };
+ const float div[3] = { -0.237662341081474f, -0.100938185496887f, -0.092050209205032f };
+ const float a4[3] = { -8.415300425381099f, -19.814106922515204f, -21.727272727270197f };
+ const uint16_t limit_index1 = 64964, limit_index2 = 47870;
+
+ if ( sphIndex >= limit_index1 )
+ {
+ ba_crt = ba[2];
+ div_crt = div[2];
+ a4_crt = a4[2];
+ del_crt = del[2];
+ }
+ else if ( sphIndex >= limit_index2 )
+ {
+ ba_crt = ba[1];
+ div_crt = div[1];
+ a4_crt = a4[1];
+ del_crt = del[1];
+ }
+ else
+ {
+ ba_crt = ba[0];
+ div_crt = div[0];
+ a4_crt = a4[0];
+ del_crt = del[0];
+ }
+ estim = ba_crt + div_crt * sqrtf( del_crt + a4_crt * sphIndex );
+
+ if ( estim > MASA_NO_CIRCLES )
+ {
+ estim = MASA_NO_CIRCLES;
+ }
+
+ assert( estim > 0 );
+ id_th = (int16_t) roundf( estim ) - 1;
+ if ( id_th < 0 )
+ {
+ id_th = 0;
+ }
+
+ if ( id_th == 0 )
+ {
+ base_low = 0;
+ base_up = n[0];
+ }
+ else
+ {
+ estim = MASA_ANGLE_AT_EQUATOR * (float) ( id_th - 0.5f );
+ base_low = n[0];
+ if ( id_th >= 2 )
+ {
+ if ( id_th == 2 )
+ {
+ base_low += 2 * (int16_t) ceilf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) );
+ }
+ else
+ {
+ base_low += 2 * (int16_t) roundf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) );
+ }
+ }
+ base_up = base_low + 2 * n[id_th];
+ }
+
+ sign_theta = 1;
+
+ n_crt = n[id_th];
+ if ( sphIndex < base_low )
+ {
+ id_th--;
+ n_crt = n[id_th];
+ if ( id_th == 0 )
+ {
+ base_low = 0;
+ base_up = n_crt;
+ }
+ else
+ {
+ base_up = base_low;
+ base_low -= 2 * n[id_th];
+ }
+ assert( sphIndex >= base_low );
+ }
+ else if ( sphIndex >= base_up )
+ {
+ id_th++;
+ n_crt = n[id_th];
+ base_low = base_up;
+ base_up += 2 * n_crt;
+ assert( sphIndex < base_up );
+ }
+
+ id_phi = (int16_t) ( sphIndex - base_low );
+ if ( sphIndex - base_low >= n_crt )
+ {
+ id_phi -= n_crt;
+ sign_theta = -1;
+ }
+
+ if ( id_th == 0 )
+ {
+ *theta = 0.f;
+ *phi = (float) sphIndex * 360 / (float) n_crt - 180;
+ }
+ else
+ {
+ if ( id_th == no_th - 1 )
+ {
+ id_phi = 0;
+ *phi = -180;
+ *theta = 90 * (float) sign_theta;
+ }
+ else
+ {
+ *theta = id_th * MASA_ANGLE_AT_EQUATOR_DEG * (float) sign_theta;
+ if ( id_th % 2 == 0 )
+ {
+ *phi = (float) id_phi * 360 / (float) n_crt - 180;
+ }
+ else
+ {
+ *phi = ( (float) id_phi + 0.5f ) * 360 / (float) n_crt - 180;
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * valid_ratio_index()
+ *
+ * Checking validity of the index of an ISM ratio index vector,
+ * within the indexing function.
+ *---------------------------------------------------------------*/
+
+/*! r: valid or not 1/0 */
+int16_t valid_ratio_index(
+ int16_t index, /* i : index to be checked */
+ const int16_t K, /* i : L1 norm to check against */
+ const int16_t len /* i : vector length */
+)
+{
+ int16_t out;
+ int16_t i, sum, elem;
+ int16_t base[4];
+
+ sum = 0;
+ set_s( base, 1, len );
+
+
+ for ( i = 1; i < len; i++ )
+ {
+ base[i] = base[i - 1] * 10;
+ }
+ sum = 0;
+ for ( i = len - 1; i >= 0; i-- )
+ {
+ elem = index / base[i];
+ sum += elem;
+ index -= elem * base[i];
+ }
+ if ( sum <= K )
+ {
+ out = 1;
+ }
+ else
+ {
+ out = 0;
+ }
+
+ return out;
+}
+
+
+/*---------------------------------------------------------------
+ * reconstruct_ism_ratios()
+ *
+ * Obtains ISM ratio values from the quantized indexes
+ *---------------------------------------------------------------*/
+
+void reconstruct_ism_ratios(
+ int16_t *ratio_ism_idx, /* i : index vector */
+ const int16_t nchan_ism, /* i : number of components/objects */
+ const float step, /* i : quantization step */
+ float *q_energy_ratio_ism /* o : reconstructed ISM values */
+)
+{
+ int16_t i;
+ float sum;
+
+ sum = 0;
+ for ( i = 0; i < nchan_ism - 1; i++ )
+ {
+ q_energy_ratio_ism[i] = ratio_ism_idx[i] * step;
+ sum += q_energy_ratio_ism[i];
+ }
+
+ q_energy_ratio_ism[nchan_ism - 1] = 1.0f - sum;
+
+ if ( q_energy_ratio_ism[nchan_ism - 1] < 0 )
+ {
+ q_energy_ratio_ism[nchan_ism - 1] = 0.0f;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_omasa_modify_masa_energy_ratios()
+ *
+ * Updates energy ratios by taking into account the MASA content contribution
+ * to the total audio scene
+ *---------------------------------------------------------------*/
+
+void ivas_omasa_modify_masa_energy_ratios(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] )
+{
+ int16_t i, m, d, b;
+
+ for ( m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES; m++ )
+ {
+ if ( hQMetaData->q_direction[0].cfg.nblocks == 1 )
+ {
+ i = 0;
+ }
+ else
+ {
+ i = m;
+ }
+
+ for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ )
+ {
+ for ( d = 0; d < hQMetaData->no_directions; d++ )
+ {
+ hQMetaData->q_direction[d].band_data[b].energy_ratio[m] = hQMetaData->q_direction[d].band_data[b].energy_ratio[m] * masa_to_total_energy_ratio[i][b];
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * distribute_evenly_ism()
+ *
+ * Obtain ISM ratio indexes for even content distribution bbetween objects
+ *---------------------------------------------------------------*/
+
+void distribute_evenly_ism(
+ int16_t *idx, /* o : index values */
+ const int16_t K, /* i : sum of indexes */
+ const int16_t nchan_ism /* i : number of objects */
+)
+{
+ int16_t i;
+ int16_t sum;
+
+ sum = 0;
+ for ( i = 0; i < nchan_ism; i++ )
+ {
+ idx[i] = (int16_t) ( K / nchan_ism );
+ sum += idx[i];
+ }
+
+ assert( sum <= K );
+
+ i = 0;
+ while ( sum < K )
+ {
+ if ( i == nchan_ism )
+ {
+ i = 0;
+ }
+ idx[i]++;
+ sum++;
+ i++;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * calculate_cpe_brate_MASA_ISM()
+ *
+ * Calculates bitrate for MASA_ISM mode that is not used for separated objects,
+ * * but for the CPE part (metadata included)
+ *---------------------------------------------------------------*/
+
+/*! r: CPE bitrate value */
+int32_t calculate_cpe_brate_MASA_ISM(
+ const ISM_MODE ism_mode, /* i : ism mode */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t nchan_ism /* i : number of objects */
+)
+{
+ int32_t cpe_brate;
+ int16_t k, sce_id;
+
+ k = 0;
+ while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] )
+ {
+ k++;
+ }
+
+ if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
+ {
+ cpe_brate = ivas_total_brate - sep_object_brate[k - 2][0]; /* take data from the first column */
+ }
+ else if ( ism_mode == ISM_MASA_MODE_DISC )
+ {
+ cpe_brate = ivas_total_brate;
+
+ for ( sce_id = 0; sce_id < nchan_ism; sce_id++ )
+ {
+ cpe_brate -= sep_object_brate[k - 2][nchan_ism - 1];
+ }
+ }
+ else
+ {
+ cpe_brate = ivas_total_brate;
+ }
+
+ return cpe_brate;
+}
diff --git a/lib_com/ivas_mc_com.c b/lib_com/ivas_mc_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..664dd3a703d981489eabb484850f40f49821086b
--- /dev/null
+++ b/lib_com/ivas_mc_com.c
@@ -0,0 +1,236 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include
+#include "prot.h"
+#include "ivas_prot.h"
+#include "wmc_auto.h"
+
+
+/*---------------------------------------------------------------
+ * ivas_mc_mode_select()
+ *
+ * selects the multichannel mode base on bitrate and LS setup
+ * ---------------------------------------------------------------*/
+
+/*! r : MC format mode */
+MC_MODE ivas_mc_mode_select(
+ const MC_LS_SETUP mc_ls_setup, /* i : MC loudspeaker setup */
+ const int32_t total_brate /* i : IVAS total bitrate */
+)
+{
+ MC_MODE mc_mode = MC_MODE_MCT;
+
+ switch ( mc_ls_setup )
+ {
+ case MC_LS_SETUP_5_1:
+ if ( total_brate < IVAS_48k )
+ {
+ mc_mode = MC_MODE_MCMASA;
+ }
+ else if ( total_brate < IVAS_96k )
+ {
+ mc_mode = MC_MODE_PARAMMC;
+ }
+ break;
+ case MC_LS_SETUP_7_1:
+ if ( total_brate < IVAS_48k )
+ {
+ mc_mode = MC_MODE_MCMASA;
+ }
+ else if ( total_brate < IVAS_128k )
+ {
+ mc_mode = MC_MODE_PARAMMC;
+ }
+ break;
+ case MC_LS_SETUP_5_1_2:
+ if ( total_brate < IVAS_48k )
+ {
+ mc_mode = MC_MODE_MCMASA;
+ }
+ else if ( total_brate < IVAS_128k )
+ {
+ mc_mode = MC_MODE_PARAMMC;
+ }
+ break;
+ case MC_LS_SETUP_5_1_4:
+ if ( total_brate < IVAS_96k )
+ {
+ mc_mode = MC_MODE_MCMASA;
+ }
+ else if ( total_brate < IVAS_160k )
+ {
+ mc_mode = MC_MODE_PARAMMC;
+ }
+ break;
+ case MC_LS_SETUP_7_1_4:
+ if ( total_brate < IVAS_128k )
+ {
+ mc_mode = MC_MODE_MCMASA;
+ }
+ else if ( total_brate < IVAS_160k )
+ {
+ mc_mode = MC_MODE_PARAMMC;
+ }
+ else if ( total_brate < IVAS_192k )
+ {
+ mc_mode = MC_MODE_PARAMUPMIX;
+ }
+ break;
+ default:
+ assert( 0 && "LS Setup not supported or defined for MC mode!\n" );
+ }
+
+ return mc_mode;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_mc_setup_get_num_channels()
+ *
+ * returns the number of channels (including the LFE) for a MC LS setup
+ * ---------------------------------------------------------------*/
+
+/*! r : number of loudspeaker channels */
+int16_t ivas_mc_ls_setup_get_num_channels(
+ const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup */
+)
+{
+ int16_t nchan;
+
+ nchan = 0;
+
+ switch ( mc_ls_setup )
+ {
+ case MC_LS_SETUP_5_1:
+ nchan = 6;
+ break;
+ case MC_LS_SETUP_7_1:
+ nchan = 8;
+ break;
+ case MC_LS_SETUP_5_1_2:
+ nchan = 8;
+ break;
+ case MC_LS_SETUP_5_1_4:
+ nchan = 10;
+ break;
+ case MC_LS_SETUP_7_1_4:
+ nchan = 12;
+ break;
+ default:
+ assert( 0 && "LS Setup not supported or defined for MC mode!\n" );
+ }
+
+ return nchan;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_mc_map_output_config_to_mc_ls_setup()
+ *
+ * maps output configuration multi channel loudspeaker setup
+ * ---------------------------------------------------------------*/
+
+/*! r : multi channel loudspeaker setup */
+MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup(
+ const AUDIO_CONFIG output_config /* i : output audio configuration */
+)
+{
+ MC_LS_SETUP mc_ls_setup;
+
+ mc_ls_setup = MC_LS_SETUP_INVALID;
+
+ switch ( output_config )
+ {
+ case IVAS_AUDIO_CONFIG_5_1:
+ mc_ls_setup = MC_LS_SETUP_5_1;
+ break;
+ case IVAS_AUDIO_CONFIG_7_1:
+ mc_ls_setup = MC_LS_SETUP_7_1;
+ break;
+ case IVAS_AUDIO_CONFIG_5_1_2:
+ mc_ls_setup = MC_LS_SETUP_5_1_2;
+ break;
+ case IVAS_AUDIO_CONFIG_5_1_4:
+ mc_ls_setup = MC_LS_SETUP_5_1_4;
+ break;
+ case IVAS_AUDIO_CONFIG_7_1_4:
+ mc_ls_setup = MC_LS_SETUP_7_1_4;
+ break;
+ default:
+ assert( 0 && "Output config is not a valid MC loudspeaker setup!\n" );
+ }
+
+ return mc_ls_setup;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_mc_map_ls_setup_to_output_config
+ *
+ * maps multi channel loudspeaker setup to audio configuration
+ * ---------------------------------------------------------------*/
+
+/*! r: audio configuration*/
+AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config(
+ const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup*/
+)
+{
+ AUDIO_CONFIG audio_config;
+ audio_config = IVAS_AUDIO_CONFIG_INVALID;
+
+ switch ( mc_ls_setup )
+ {
+ case MC_LS_SETUP_5_1:
+ audio_config = IVAS_AUDIO_CONFIG_5_1;
+ break;
+ case MC_LS_SETUP_7_1:
+ audio_config = IVAS_AUDIO_CONFIG_7_1;
+ break;
+ case MC_LS_SETUP_5_1_2:
+ audio_config = IVAS_AUDIO_CONFIG_5_1_2;
+ break;
+ case MC_LS_SETUP_5_1_4:
+ audio_config = IVAS_AUDIO_CONFIG_5_1_4;
+ break;
+ case MC_LS_SETUP_7_1_4:
+ audio_config = IVAS_AUDIO_CONFIG_7_1_4;
+ break;
+ default:
+ assert( 0 && "MC loudspeaker setup is not valid!\n" );
+ }
+
+ return audio_config;
+}
diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..e8160527021164c336145a677fdb13f3db36cb9e
--- /dev/null
+++ b/lib_com/ivas_mc_param_com.c
@@ -0,0 +1,517 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include "ivas_cnst.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "ivas_stat_com.h"
+#include "ivas_rom_com.h"
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------------------
+ * Local function prototypes
+ *------------------------------------------------------------------------*/
+
+static void ivas_param_mc_set_coding_scheme( const MC_LS_SETUP mc_ls_setup, const int32_t ivas_total_brate, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC );
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_get_configuration_index()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+uint16_t ivas_param_mc_get_configuration_index(
+ const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ uint16_t cur_idx;
+
+ for ( cur_idx = 0; cur_idx < PARAM_MC_NUM_CONFIGS; cur_idx++ )
+ {
+ if ( ivas_param_mc_conf[cur_idx].mc_ls_setup == mc_ls_setup && ivas_param_mc_conf[cur_idx].ivas_total_brate == ivas_total_brate )
+ {
+ return cur_idx;
+ }
+ }
+ return PARAM_MC_NUM_CONFIGS;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_metadata_open()
+ *
+ * Parametric MC parameter coding state open function
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_metadata_open(
+ const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
+ const int16_t lfe_index, /* i : channel index of LFE */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */
+)
+{
+ int16_t i;
+ uint16_t config_index;
+ int16_t nchan_setup;
+
+ nchan_setup = ivas_mc_ls_setup_get_num_channels( mc_ls_setup );
+
+ /* get coding band mappings */
+ set_s( hMetadataPMC->coding_band_mapping, 0, PARAM_MC_MAX_PARAMETER_BANDS );
+
+ /* set coding scheme */
+ ivas_param_mc_set_coding_scheme( mc_ls_setup, ivas_total_brate, hMetadataPMC );
+
+ /* get configuration index */
+ config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate );
+ if ( config_index == PARAM_MC_NUM_CONFIGS )
+ {
+ assert( 0 && "ParamMC configuration index not found!" );
+ }
+
+ /* Band Grouping */
+ if ( hMetadataPMC->num_parameter_bands == 20 )
+ {
+ mvs2s( param_mc_coding_band_mapping_20, hMetadataPMC->coding_band_mapping, 20 );
+ }
+ else if ( hMetadataPMC->num_parameter_bands == 14 )
+ {
+ mvs2s( param_mc_coding_band_mapping_14, hMetadataPMC->coding_band_mapping, 14 );
+ }
+ else if ( hMetadataPMC->num_parameter_bands == 10 )
+ {
+ mvs2s( param_mc_coding_band_mapping_10, hMetadataPMC->coding_band_mapping, 10 );
+ }
+ else
+ {
+ assert( 0 && "nbands must be 20 or 14!" );
+ }
+
+ /* create map of all possible ICCs */
+ ivas_param_mc_create_full_icc_mapping( nchan_setup, lfe_index, hMetadataPMC->icc_map_full, &hMetadataPMC->icc_map_size_full );
+ hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf;
+ hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf;
+ hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors;
+
+ /* set default ICC maps */
+ for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ )
+ {
+ ivas_param_mc_default_icc_map( hMetadataPMC->icc_mapping_conf, hMetadataPMC->icc_mapping[i] );
+ }
+
+ /* init remaining flags and indices */
+ hMetadataPMC->param_frame_idx = 0;
+ hMetadataPMC->flag_use_adaptive_icc_map = 0;
+ hMetadataPMC->bAttackPresent = 0;
+ hMetadataPMC->attackIndex = 0;
+ hMetadataPMC->lfe_on = 1;
+
+ /* set coded bwidth to FB at the beginning */
+ hMetadataPMC->coded_bwidth = FB;
+ hMetadataPMC->last_coded_bwidth = FB;
+
+ ivas_param_mc_set_coded_bands( hMetadataPMC );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_set_coded_bands()
+ *
+ * Parametric MC: set number of actually coded parameters bands based on the
+ * coded band width
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_set_coded_bands(
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */
+)
+{
+ int16_t i;
+
+ /* set number of coded bands*/
+ switch ( hMetadataPMC->num_parameter_bands )
+ {
+ case 20:
+ hMetadataPMC->nbands_coded = param_mc_bands_coded_20[hMetadataPMC->coded_bwidth];
+ break;
+ case 14:
+ hMetadataPMC->nbands_coded = param_mc_bands_coded_14[hMetadataPMC->coded_bwidth];
+ break;
+ case 10:
+ hMetadataPMC->nbands_coded = param_mc_bands_coded_10[hMetadataPMC->coded_bwidth];
+ }
+
+ /* set number of bands per parameter frame set */
+ for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ )
+ {
+ hMetadataPMC->nbands_in_param_frame[i] = 0;
+ }
+
+ for ( i = 0; i < hMetadataPMC->nbands_coded; i++ )
+ {
+ hMetadataPMC->nbands_in_param_frame[hMetadataPMC->coding_band_mapping[i]]++;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_metadata_close()
+ *
+ * Parametric MC parameter coding state close function
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_metadata_close(
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */
+)
+{
+ uint16_t i;
+
+ /* adaptive ICC mapping */
+ for ( i = 0; i < 2; i++ )
+ {
+ if ( hMetadataPMC->icc_map_full[i] )
+ {
+ free( hMetadataPMC->icc_map_full[i] );
+ hMetadataPMC->icc_map_full[i] = NULL;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_getNumTransportChannels()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+/* r : number of IVAS transport channels */
+int16_t ivas_param_mc_getNumTransportChannels(
+ const int32_t ivas_total_bitrate, /* i : IVAS total bitrate */
+ const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */
+)
+{
+ int16_t nchan_transport;
+ int16_t config_index;
+
+ config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_bitrate );
+
+ nchan_transport = ivas_param_mc_conf[config_index].num_transport_chan;
+
+ return nchan_transport;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_create_full_icc_mapping()
+ *
+ * create the map of all possible ICCs for a certain internal setup
+ * indicated by the number of channels and LFE index
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_create_full_icc_mapping(
+ const int16_t n_channels, /* i : number of channels with LFE for the internal setup */
+ const int16_t lfe_index, /* i : channel index of the LFE */
+ int16_t *icc_map[2], /* o : map of all possible ICCs */
+ int16_t *icc_map_size_full /* o : number of all possible ICCs */
+)
+{
+ int16_t i, k, l;
+
+ l = 0;
+
+ /* number of all possible ICCs is the number of non-diagonal upper elements of a
+ * ICC matrix for all channels not including the LFE plus one static ICC for the
+ * combination (LFE/center) */
+ *icc_map_size_full = ( n_channels - 2 ) * ( n_channels - 1 ) / 2 + 1;
+
+ /* allocate memory for the map */
+ for ( i = 0; i < 2; i++ )
+ {
+ icc_map[i] = (int16_t *) malloc( *icc_map_size_full * sizeof( int16_t ) );
+ }
+
+ /* create map (non-LFE ICCs) */
+ for ( i = 0; i < n_channels; i++ )
+ {
+ if ( i != lfe_index )
+ {
+ for ( k = i + 1; k < n_channels; k++ )
+ {
+ if ( k != lfe_index )
+ {
+ icc_map[0][l] = i;
+ icc_map[1][l] = k;
+ l++;
+ }
+ }
+ }
+ }
+
+ /* last one is the fixed mapping center -> LFE */
+ assert( l == *icc_map_size_full - 1 );
+
+ icc_map[0][l] = 2;
+ icc_map[1][l] = lfe_index;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_default_icc_map()
+ *
+ * get the default ICC map for a certain internal setup
+ * indicated by the number of channels from the table ROM
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_default_icc_map(
+ const PARAM_MC_ICC_MAPPING *hIccMapping, /* i : ICC mapping table */
+ int16_t icc_map[PARAM_MC_SZ_ICC_MAP][2] /* o : copy of map from ROM table */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < hIccMapping->icc_map_size_lfe; i++ )
+ {
+ icc_map[i][0] = hIccMapping->icc_mapping[i][0];
+ icc_map[i][1] = hIccMapping->icc_mapping[i][1];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_get_num_param_bands()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+static int16_t ivas_param_mc_get_num_param_bands(
+ const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ int16_t num_parameter_bands;
+
+ num_parameter_bands = 0;
+
+ /* parameter bands */
+ switch ( mc_ls_setup )
+ {
+ case MC_LS_SETUP_5_1:
+ switch ( ivas_total_brate )
+ {
+ case IVAS_48k:
+ num_parameter_bands = 10;
+ break;
+ case IVAS_64k:
+ case IVAS_80k:
+ num_parameter_bands = 14;
+ break;
+ default:
+ assert( 0 && "PARAM_MC: bitrate for CICP6 not supported!" );
+ }
+ break;
+
+ case MC_LS_SETUP_7_1:
+ switch ( ivas_total_brate )
+ {
+ case IVAS_48k:
+ num_parameter_bands = 10;
+ break;
+ case IVAS_64k:
+ case IVAS_80k:
+ num_parameter_bands = 14;
+ break;
+ case IVAS_96k:
+ num_parameter_bands = 20;
+ break;
+ }
+ break;
+ case MC_LS_SETUP_5_1_2:
+ switch ( ivas_total_brate )
+ {
+ case IVAS_48k:
+ num_parameter_bands = 10;
+ break;
+ case IVAS_64k:
+ case IVAS_80k:
+ num_parameter_bands = 14;
+ break;
+ case IVAS_96k:
+ num_parameter_bands = 20;
+ break;
+ }
+ break;
+ case MC_LS_SETUP_5_1_4:
+ switch ( ivas_total_brate )
+ {
+ case IVAS_96k:
+ num_parameter_bands = 14;
+ break;
+ case IVAS_128k:
+ num_parameter_bands = 20;
+ break;
+ }
+ break;
+ case MC_LS_SETUP_7_1_4:
+ switch ( ivas_total_brate )
+ {
+ case IVAS_128k:
+ num_parameter_bands = 14;
+ break;
+ case IVAS_160k:
+ num_parameter_bands = 20;
+ break;
+ }
+ break;
+ default:
+ assert( 0 && "PARAM_MC: channel configuration not supportet!" );
+ }
+
+ return num_parameter_bands;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Local functions
+ *------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_set_coding_scheme()
+ *
+ * set Parametric MC parameter coding tables based on format and bitrate
+ *------------------------------------------------------------------------*/
+
+static void ivas_param_mc_set_coding_scheme(
+ const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: Parametric MC metadata handle */
+)
+{
+ /* quantizer and coding tables */
+ switch ( mc_ls_setup )
+ {
+ case MC_LS_SETUP_5_1:
+ /* ICC */
+ hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp6_48_16bits[0];
+ hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0];
+ hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0];
+ hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0];
+ hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
+ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
+ hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
+ /* ILD */
+ hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp6_48_16bits[0];
+ hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0];
+ hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0];
+ hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0];
+ hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
+ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
+ hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
+ break;
+ case MC_LS_SETUP_7_1:
+ /* ICC */
+ hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp12_48_16bits[0];
+ hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0];
+ hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0];
+ hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0];
+ hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
+ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
+ hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
+ /* ILD */
+ hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp12_48_16bits[0];
+ hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0];
+ hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0];
+ hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0];
+ hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
+ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
+ hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
+ break;
+ case MC_LS_SETUP_5_1_2:
+ /* ICC */
+ hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp14_48_16bits[0];
+ hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0];
+ hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0];
+ hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0];
+ hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
+ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
+ hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
+ /* ILD */
+ hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp14_48_16bits[0];
+ hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0];
+ hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0];
+ hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0];
+ hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
+ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
+ hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
+ break;
+ case MC_LS_SETUP_5_1_4:
+ case MC_LS_SETUP_7_1_4:
+ /* ICC */
+ hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_combined_48_16bits[0];
+ hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0];
+ hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0];
+ hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0];
+ hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
+ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
+ hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
+ /* ILD */
+ hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_combined_48_16bits[0];
+ hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0];
+ hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0];
+ hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0];
+ hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
+ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
+ hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
+ break;
+ default:
+ assert( 0 && "PARAM_MC: channel configuration not supported!" );
+ }
+
+ hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands( mc_ls_setup, ivas_total_brate );
+
+ return;
+}
diff --git a/lib_com/ivas_mcmasa_com.c b/lib_com/ivas_mcmasa_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..34196431960ff0c06977c3703a7cb0632965f3d8
--- /dev/null
+++ b/lib_com/ivas_mcmasa_com.c
@@ -0,0 +1,129 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_cnst.h"
+#include "ivas_prot.h"
+#include "options.h"
+#include "wmc_auto.h"
+
+
+/*--------------------------------------------------------------------------*
+ * ivas_mcmasa_setNumTransportChannels()
+ *
+ * Set number of transport channels in McMASA
+ *--------------------------------------------------------------------------*/
+
+void ivas_mcmasa_setNumTransportChannels(
+ int16_t *nchan_transport, /* o : Pointer to number of transport channels to be set */
+ int16_t *element_mode, /* o : Pointer to element mode to be set */
+ const int32_t ivas_total_brate /* i : Total bitrate of IVAS */
+)
+{
+ if ( ivas_total_brate >= IVAS_48k )
+ {
+ *nchan_transport = 2;
+ *element_mode = IVAS_CPE_MDCT;
+ }
+ else
+ {
+ *nchan_transport = 1;
+ *element_mode = IVAS_SCE;
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * ivas_mcmasa_set_separate_channel_mode()
+ *
+ * Set separate channel parameters in McMASA based on bitrate
+ *--------------------------------------------------------------------------*/
+
+void ivas_mcmasa_set_separate_channel_mode(
+ uint8_t *separateChannelEnabled, /* o : Pointer to separate channel toggle */
+ int16_t *separateChannelIndex, /* o : Pointer to separate channel index */
+ const int32_t ivas_total_brate /* i : Total bitrate of IVAS */
+)
+{
+ if ( ivas_total_brate >= MCMASA_SEPARATE_BRATE )
+ {
+ *separateChannelEnabled = 1;
+ *separateChannelIndex = 2; /* Center channel */
+ }
+ else
+ {
+ *separateChannelEnabled = 0;
+ *separateChannelIndex = 0;
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * ivas_mcmasa_split_brate()
+ *
+ * Split the total bitrate to elements in McMASA
+ *--------------------------------------------------------------------------*/
+
+void ivas_mcmasa_split_brate(
+ const uint8_t separateChannelEnabled, /* i : Transport running in "separate channel" mode */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate available to be split */
+ const int16_t nSCE, /* i : Number of SCEs in use (0 or 1) */
+ const int16_t nCPE, /* i : Number of CPEs in use (0 or 1) */
+ int32_t *brate_sce, /* o : Pointer to SCE element bitrate */
+ int32_t *brate_cpe /* o : Pointer to CPE element bitrate */
+)
+{
+ if ( separateChannelEnabled )
+ {
+ /* 25% of total bitrate is used for SCE below 96 kb/s (separated mono channel), otherwise 30% */
+ if ( ivas_total_brate < IVAS_96k )
+ {
+ *brate_sce = (int32_t) ( MCMASA_MONOBITRATIO_64k * ivas_total_brate );
+ }
+ else
+ {
+ *brate_sce = (int32_t) ( MCMASA_MONOBITRATIO * ivas_total_brate );
+ }
+
+ *brate_cpe = ivas_total_brate - *brate_sce;
+ }
+ else
+ {
+ *brate_sce = nSCE > 0 ? ivas_total_brate / ( nCPE + nSCE ) : 0;
+ *brate_cpe = nCPE > 0 ? ivas_total_brate / ( nCPE + nSCE ) : 0;
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_mct_com.c b/lib_com/ivas_mct_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..97c5f5dd8c982fda7ff0b57fc6507869fb957d94
--- /dev/null
+++ b/lib_com/ivas_mct_com.c
@@ -0,0 +1,194 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "ivas_prot.h"
+#include "prot.h"
+#include "wmc_auto.h"
+#include
+
+
+/*-------------------------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------------------------*/
+
+#define MIN_SAFETY_BITS_LFE 30
+#define MIN_SAFETY_BITS_MC 5
+
+
+/*-------------------------------------------------------------------*
+ * splitAvailableBitsMCT()
+ *
+ * split available TCX bits among channels
+ *-------------------------------------------------------------------*/
+
+void splitAvailableBitsMCT(
+ void **sts, /* i/o: encoder/decoder state structure */
+ const int16_t total_bits, /* i : total number of available bits */
+ const int16_t split_ratio[MCT_MAX_CHANNELS], /* i : ratio for splitting the bits */
+ const int16_t enc_dec, /* i : encoder or decoder flag */
+ const int16_t nchan /* i : number of channels */
+)
+{
+ int16_t i, k, nSubframes, diff, bits_split, max_chn, tmp;
+ int16_t *bits_frame_channel;
+ int16_t min_chan_bits[MCT_MAX_CHANNELS], min_bits_tot, remaining_bits;
+ int16_t core[MCT_MAX_CHANNELS];
+ MCT_CHAN_MODE mct_chan_mode[MCT_MAX_CHANNELS];
+ min_bits_tot = 0;
+
+ for ( i = 0; i < nchan; i++ )
+ {
+ if ( enc_dec == ENC )
+ {
+ mct_chan_mode[i] = ( (Encoder_State *) sts[i] )->mct_chan_mode;
+ core[i] = ( (Encoder_State *) sts[i] )->core;
+ }
+ else
+ {
+ mct_chan_mode[i] = ( (Decoder_State *) sts[i] )->mct_chan_mode;
+ core[i] = ( (Decoder_State *) sts[i] )->core;
+ }
+ }
+
+ for ( i = 0; i < nchan; i++ )
+ {
+ if (
+ mct_chan_mode[i] != MCT_CHAN_MODE_IGNORE )
+ {
+ min_chan_bits[i] = 0;
+
+ nSubframes = ( core[i] == TCX_20_CORE ) ? 1 : NB_DIV;
+
+ for ( k = 0; k < nSubframes; k++ )
+ {
+ min_chan_bits[i] += SMDCT_MINIMUM_ARITH_BITS + MIN_SAFETY_BITS_MC;
+ }
+ min_bits_tot += min_chan_bits[i];
+ }
+ }
+
+ remaining_bits = total_bits - min_bits_tot;
+
+ /*initial value of bits already given*/
+ bits_split = 0;
+
+ tmp = 0;
+ max_chn = 0;
+ for ( i = 0; i < nchan; i++ )
+ {
+ if ( enc_dec == ENC )
+ {
+ bits_frame_channel = &( (Encoder_State *) sts[i] )->bits_frame_channel;
+ }
+ else /* DEC */
+ {
+ bits_frame_channel = &( (Decoder_State *) sts[i] )->bits_frame_channel;
+ }
+
+ if (
+ mct_chan_mode[i] != MCT_CHAN_MODE_IGNORE )
+ {
+ assert( split_ratio[i] >= 1 && split_ratio[i] < BITRATE_MCT_RATIO_RANGE );
+ *bits_frame_channel = split_ratio[i] * remaining_bits / BITRATE_MCT_RATIO_RANGE + min_chan_bits[i];
+ bits_split += *bits_frame_channel;
+
+ /*determine channel with most bits (energy)*/
+ if ( *bits_frame_channel > tmp )
+ {
+ tmp = *bits_frame_channel;
+ max_chn = i;
+ }
+ }
+ }
+
+ /*if bits distributed are more than available bits, substract the proportional amount of bits from all channels*/
+ if ( bits_split != total_bits )
+ {
+ diff = bits_split - total_bits;
+
+ /*re-count bits distributed to each channel*/
+ bits_split = 0;
+
+ for ( i = 0; i < nchan; i++ )
+ {
+ if ( enc_dec == ENC )
+ {
+ bits_frame_channel = &( (Encoder_State *) sts[i] )->bits_frame_channel;
+ }
+ else /* DEC */
+ {
+ bits_frame_channel = &( (Decoder_State *) sts[i] )->bits_frame_channel;
+ }
+
+ if (
+ mct_chan_mode[i] != MCT_CHAN_MODE_IGNORE )
+ {
+ *bits_frame_channel -= diff * split_ratio[i] / BITRATE_MCT_RATIO_RANGE;
+ *bits_frame_channel = max( min_chan_bits[i], *bits_frame_channel );
+ bits_split += *bits_frame_channel;
+ }
+ }
+ }
+
+ /*if there any bits left assign them to the channel with the maximum energy (or more bits)*/
+ if ( total_bits != bits_split )
+ {
+ if ( enc_dec == ENC )
+ {
+ bits_frame_channel = &( (Encoder_State *) sts[max_chn] )->bits_frame_channel;
+ }
+ else /* DEC */
+ {
+ bits_frame_channel = &( (Decoder_State *) sts[max_chn] )->bits_frame_channel;
+ }
+
+ *bits_frame_channel += ( total_bits - bits_split );
+
+ /*if all channels are silent assign bits to ch 0*/
+ if ( enc_dec == ENC )
+ {
+ if ( ( (Encoder_State *) sts[max_chn] )->mct_chan_mode == MCT_CHAN_MODE_IGNORE )
+ {
+ assert( bits_split == 0 );
+
+ ( (Encoder_State *) sts[max_chn] )->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
+ ( (Encoder_State *) sts[max_chn] )->side_bits_frame_channel = ( ( (Encoder_State *) sts[max_chn] )->core ) * ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL );
+ *bits_frame_channel -= ( (Encoder_State *) sts[max_chn] )->side_bits_frame_channel;
+ }
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_mdct_core_com.c b/lib_com/ivas_mdct_core_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..afb5303a7aa82c774655b53c89546ef91656433a
--- /dev/null
+++ b/lib_com/ivas_mdct_core_com.c
@@ -0,0 +1,81 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "ivas_prot.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * ivas_mdct_tcx10_bit_distribution()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void ivas_mdct_tcx10_bit_distribution(
+ int16_t target_bitsTCX10[NB_DIV], /* o : target bit distribution */
+ const int16_t nbits_tcx, /* i : TCX bits */
+ const int16_t nTnsBitsTCX10[NB_DIV] /* i : TNS bits */
+)
+{
+ int16_t k;
+ int16_t min_required_bits = NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL + SMDCT_MINIMUM_ARITH_BITS;
+
+ for ( k = 0; k < 2; k++ )
+ {
+ if ( nbits_tcx & 1 )
+ {
+ target_bitsTCX10[k] = nbits_tcx / 2 + ( k == 0 ? 1 : 0 ) - nTnsBitsTCX10[k];
+ }
+ else
+ {
+ target_bitsTCX10[k] = nbits_tcx / 2 - nTnsBitsTCX10[k];
+ }
+ }
+
+ if ( target_bitsTCX10[0] < min_required_bits )
+ {
+ /*redistribute bits*/
+ target_bitsTCX10[1] -= ( min_required_bits - target_bitsTCX10[0] );
+ target_bitsTCX10[0] = min_required_bits;
+ }
+ else if ( target_bitsTCX10[1] < min_required_bits )
+ {
+ /*redistribute bits*/
+ target_bitsTCX10[0] -= ( min_required_bits - target_bitsTCX10[1] );
+ target_bitsTCX10[1] = min_required_bits;
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_mdct_imdct.c b/lib_com/ivas_mdct_imdct.c
new file mode 100644
index 0000000000000000000000000000000000000000..656788717ed7323962a01849ddc46434abdd0cef
--- /dev/null
+++ b/lib_com/ivas_mdct_imdct.c
@@ -0,0 +1,379 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "prot.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
+#include "ivas_stat_com.h"
+#include "wmc_auto.h"
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local constants
+ *------------------------------------------------------------------------------------------*/
+
+#define IVAS_MDCT_SCALING_GAIN_48k 1.9699011974118126e-06f
+#define IVAS_MDCT_SCALING_GAIN_32k 2.9548517961177197e-06f
+#define IVAS_MDCT_SCALING_GAIN_16k 5.909703592235439e-06f
+
+#define IVAS_IMDCT_SCALING_GAIN 2115.165304808f
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_tda()
+ *
+ * Time domain aliasing
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_tda(
+ const float *pIn, /* i : time domain buffer of size 2*length */
+ float *pOut, /* o : time domain buffer of size length */
+ const int16_t length /* i : length of time alised signal buffer */
+)
+{
+ int16_t i;
+ int16_t len_by_2 = length >> 1;
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ pOut[i] = -pIn[len_by_2 - i - 1] + pIn[len_by_2 + i];
+ pOut[len_by_2 + i] = pIn[length * 2 - i - 1] + pIn[length + i];
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_dct_windowing()
+ *
+ * Windowing block, input is passed through Fielder window
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_dct_windowing(
+ const int16_t fade_len,
+ const int16_t full_len,
+ const int16_t dct_len,
+ const int16_t zero_pad_len,
+ const float *pWindow_coeffs,
+ const int16_t frame_len,
+ float *pOut_buf,
+ float *pBuffer_prev,
+ float *pTemp_lfe )
+{
+ int16_t i;
+ int16_t rem_len = 0;
+
+ mvr2r( pBuffer_prev, pOut_buf + zero_pad_len, fade_len );
+
+ mvr2r( pTemp_lfe, ( pOut_buf + fade_len + zero_pad_len ), dct_len );
+
+ for ( i = 0; i < zero_pad_len; i++ )
+ {
+ pOut_buf[i] = 0.0f;
+ }
+
+ mvr2r( ( pOut_buf + full_len - fade_len ), pBuffer_prev, fade_len );
+
+ for ( i = 0; i < fade_len; i++ )
+ {
+ pOut_buf[zero_pad_len + i] = pOut_buf[zero_pad_len + i] * pWindow_coeffs[i];
+ }
+
+ rem_len = full_len - ( zero_pad_len * 3 + fade_len );
+
+ for ( i = 0; i < rem_len; i++ )
+ {
+ pOut_buf[zero_pad_len * 3 + fade_len + i] = pOut_buf[zero_pad_len * 3 + fade_len + i] * pWindow_coeffs[fade_len - i - 1];
+ }
+
+ for ( i = 0; i < frame_len - full_len; i++ )
+ {
+ pOut_buf[full_len + i] = 0.0f;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_mdct()
+ *
+ * MDCT implementation
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_mdct(
+ const float *pIn,
+ float *pOut,
+ const int16_t length )
+{
+ const float *pTwid_re, *pTwid_im;
+ int16_t i, len_by_2;
+ float re[IVAS_480_PT_LEN], im[IVAS_480_PT_LEN];
+ float ivas_mdct_scaling_gain;
+
+ len_by_2 = length >> 1;
+ ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain( len_by_2 );
+
+ ivas_get_twid_factors( length, &pTwid_re, &pTwid_im );
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ pOut[i] = -pIn[len_by_2 - i - 1] + pIn[len_by_2 + i];
+ pOut[len_by_2 + i] = pIn[length * 2 - i - 1] + pIn[length + i];
+ }
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ re[i] = -( pOut[2 * i] * pTwid_re[i] + pOut[length - 1 - 2 * i] * pTwid_im[i] );
+ im[i] = pOut[length - 1 - 2 * i] * pTwid_re[i] - pOut[2 * i] * pTwid_im[i];
+ }
+
+ DoFFT( &re[0], &im[0], len_by_2 );
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ re[i] = re[i] * ivas_mdct_scaling_gain;
+ im[i] = im[i] * ivas_mdct_scaling_gain;
+ }
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ float tmp;
+ tmp = re[i] * pTwid_re[i] - im[i] * pTwid_im[i];
+ im[i] = im[i] * pTwid_re[i] + re[i] * pTwid_im[i];
+ re[i] = tmp;
+ }
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ pOut[length - 2 * i - 1] = re[i];
+ pOut[2 * i] = im[i];
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_ifft_cplx()
+ *
+ * Complex IFFT implementation using DoFFT
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_ifft_cplx(
+ float *re,
+ float *im,
+ const int16_t length )
+{
+ int16_t i;
+ float ivas_imdct_one_by_powergain = IVAS_IMDCT_SCALING_GAIN;
+ /*re-arrange inputs to use fft as ifft */
+ re[0] = re[0] * ivas_imdct_one_by_powergain;
+ im[0] = im[0] * ivas_imdct_one_by_powergain;
+
+ for ( i = 1; i <= length >> 1; i++ )
+ {
+ float tmp = re[length - i] * ivas_imdct_one_by_powergain;
+ re[length - i] = re[i] * ivas_imdct_one_by_powergain;
+ re[i] = tmp;
+
+ tmp = im[length - i] * ivas_imdct_one_by_powergain;
+ im[length - i] = im[i] * ivas_imdct_one_by_powergain;
+ im[i] = tmp;
+ }
+
+ DoFFT( re, im, (int16_t) length );
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_itda()
+ *
+ * Inverse time domain alias implementation
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_itda(
+ const float *re, /* i : time alised signal after IDCT */
+ float *pOut, /* o : time domain buffer of size 2*length */
+ const int16_t length /* i : length of time alised signal buffer */
+)
+{
+ int16_t i;
+ int16_t len_by_2 = length >> 1;
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ pOut[i] = -re[len_by_2 - i - 1];
+ pOut[len_by_2 + i] = re[i];
+ pOut[length + i] = re[len_by_2 + i];
+ pOut[3 * len_by_2 + i] = re[length - i - 1];
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_imdct()
+ *
+ * IMDCT implementation
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_imdct(
+ const float *pIn,
+ float *pOut,
+ const int16_t length )
+{
+ const float *pTwid_re, *pTwid_im;
+ int16_t len_by_2 = length >> 1;
+ int16_t i;
+ float re[IVAS_480_PT_LEN];
+ float im[IVAS_480_PT_LEN];
+
+ ivas_get_twid_factors( length, &pTwid_re, &pTwid_im );
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ re[i] = pIn[length - 2 * i - 1] * pTwid_re[i] + pIn[2 * i] * pTwid_im[i]; /*stl_arr_index*/
+ im[i] = -pIn[length - 2 * i - 1] * pTwid_im[i] + pIn[2 * i] * pTwid_re[i]; /*stl_arr_index*/
+ }
+
+ ivas_ifft_cplx( &re[0], &im[0], len_by_2 );
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ float tmp;
+ tmp = re[i] * pTwid_re[i] + im[i] * pTwid_im[i];
+ im[i] = -re[i] * pTwid_im[i] + im[i] * pTwid_re[i];
+ re[i] = tmp;
+ }
+
+ for ( i = ( len_by_2 - 1 ); i >= 0; i-- )
+ {
+ re[2 * i + 1] = im[( len_by_2 - 1 ) - i];
+ re[2 * i] = -re[i];
+ }
+
+ for ( i = 0; i < len_by_2; i++ )
+ {
+ pOut[i] = -re[len_by_2 - i - 1];
+ pOut[len_by_2 + i] = re[i];
+ pOut[length + i] = re[len_by_2 + i];
+ pOut[3 * len_by_2 + i] = re[length - i - 1];
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_twid_factors()
+ *
+ * Sets/Maps the fft twiddle tables based on fft length
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_get_twid_factors(
+ const int16_t length,
+ const float **pTwid_re,
+ const float **pTwid_im )
+{
+ if ( length == 480 )
+ {
+ *pTwid_re = &ivas_cos_twiddle_480[0];
+ *pTwid_im = &ivas_sin_twiddle_480[0];
+ }
+ else if ( length == 320 )
+ {
+ *pTwid_re = &ivas_cos_twiddle_320[0];
+ *pTwid_im = &ivas_sin_twiddle_320[0];
+ }
+ else if ( length == 160 )
+ {
+ *pTwid_re = &ivas_cos_twiddle_160[0];
+ *pTwid_im = &ivas_sin_twiddle_160[0];
+ }
+ else if ( length == 80 )
+ {
+ *pTwid_re = &ivas_cos_twiddle_80[0];
+ *pTwid_im = &ivas_sin_twiddle_80[0];
+ }
+ else
+ {
+ assert( !"Not supported FFT length!" );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_mdct_scaling_gain()
+ *
+ * Get scaling gain for MDCT functions
+ *-----------------------------------------------------------------------------------------*/
+
+float ivas_get_mdct_scaling_gain(
+ const int16_t dct_len_by_2 )
+{
+ float gain = 0.0f;
+
+ switch ( dct_len_by_2 )
+ {
+ case L_FRAME48k >> 2:
+ {
+ gain = IVAS_MDCT_SCALING_GAIN_48k;
+ break;
+ }
+ case L_FRAME32k >> 2:
+ {
+ gain = IVAS_MDCT_SCALING_GAIN_32k;
+ break;
+ }
+ case L_FRAME16k >> 2:
+ {
+ gain = IVAS_MDCT_SCALING_GAIN_16k;
+ break;
+ }
+ default:
+ {
+ assert( !"Unsupported frame length!" );
+ break;
+ }
+ }
+
+ return gain;
+}
diff --git a/lib_com/ivas_mdft_imdft.c b/lib_com/ivas_mdft_imdft.c
new file mode 100644
index 0000000000000000000000000000000000000000..73a73231690d3c2509d0a477703951f14b72b89b
--- /dev/null
+++ b/lib_com/ivas_mdft_imdft.c
@@ -0,0 +1,310 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "prot.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
+#include
+#include "wmc_auto.h"
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Local constants
+ *-----------------------------------------------------------------------------------------*/
+
+#define IVAS_ONE_BY_960 0.001041666666666666f
+#define IVAS_ONE_BY_640 0.0015625f
+#define IVAS_ONE_BY_320 0.003125f
+#define IVAS_ONE_BY_240 0.004166666666666667f
+#define IVAS_ONE_BY_160 0.00625f
+#define IVAS_ONE_BY_80 0.0125f
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_mdft_twid_factors()
+ *
+ * get twiddle tables for MDFT
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_get_mdft_twid_factors(
+ const int16_t length,
+ const float **ppTwid )
+{
+ switch ( length )
+ {
+ case L_FRAME48k:
+ *ppTwid = &ivas_mdft_coeff_cos_twid_960[0];
+ break;
+ case L_FRAME32k:
+ *ppTwid = &ivas_mdft_coeff_cos_twid_640[0];
+
+ break;
+ case L_FRAME16k:
+ *ppTwid = &ivas_mdft_coeff_cos_twid_320[0];
+ break;
+ case IVAS_240_PT_LEN:
+ *ppTwid = &ivas_mdft_coeff_cos_twid_240[0];
+ break;
+ case IVAS_160_PT_LEN:
+ *ppTwid = &ivas_mdft_coeff_cos_twid_160[0];
+ break;
+ case IVAS_120_PT_LEN:
+ *ppTwid = &ivas_mdft_coeff_cos_twid_120[0];
+ break;
+ case IVAS_80_PT_LEN:
+ *ppTwid = &ivas_mdft_coeff_cos_twid_80[0];
+ break;
+ case IVAS_40_PT_LEN:
+ *ppTwid = &ivas_mdft_coeff_cos_twid_40[0];
+ break;
+
+ default:
+ assert( !"Not supported FFT length!" );
+ break;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_imdft_twid_factors()
+ *
+ * get twiddle tables for IMDFT
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_get_imdft_twid_factors(
+ const int16_t length,
+ const float **ppTwid )
+{
+ switch ( length )
+ {
+ case L_FRAME48k:
+ *ppTwid = ivas_mdft_coeff_cos_twid_960;
+ break;
+ case L_FRAME32k:
+ *ppTwid = ivas_mdft_coeff_cos_twid_640;
+ break;
+ case L_FRAME16k:
+ *ppTwid = ivas_mdft_coeff_cos_twid_320;
+ break;
+ case 240:
+ *ppTwid = ivas_mdft_coeff_cos_twid_240;
+ break;
+ case 160:
+ *ppTwid = ivas_mdft_coeff_cos_twid_160;
+ break;
+ case 80:
+ *ppTwid = ivas_mdft_coeff_cos_twid_80;
+ break;
+ default:
+ assert( !"Not supported FFT length!" );
+ }
+
+ return;
+}
+
+
+static void get_one_by_length(
+ float *one_by_length,
+ const int16_t length )
+{
+ if ( length == L_FRAME48k )
+ {
+ *one_by_length = IVAS_ONE_BY_960;
+ }
+ else if ( length == L_FRAME32k )
+ {
+ *one_by_length = IVAS_ONE_BY_640;
+ }
+ else if ( length == L_FRAME16k )
+ {
+ *one_by_length = IVAS_ONE_BY_320;
+ }
+ else if ( length == IVAS_240_PT_LEN )
+ {
+ *one_by_length = IVAS_ONE_BY_240;
+ }
+ else if ( length == IVAS_160_PT_LEN )
+ {
+ *one_by_length = IVAS_ONE_BY_160;
+ }
+ else if ( length == IVAS_80_PT_LEN )
+ {
+ *one_by_length = IVAS_ONE_BY_80;
+ }
+ else
+ {
+ assert( !"Not supported FFT length!" );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_ifft_cplx1()
+ *
+ * Complex IFFT implementation using fft()
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_ifft_cplx1(
+ float *re,
+ float *im,
+ const int16_t length )
+{
+ int16_t i;
+ float one_by_length, tmp;
+
+ get_one_by_length( &one_by_length, length );
+
+ /* re-arrange inputs to use fft as ifft */
+ re[0] = re[0] * one_by_length;
+ im[0] = im[0] * one_by_length;
+
+ for ( i = 1; i <= length >> 1; i++ )
+ {
+ tmp = re[length - i] * one_by_length; /*stl_arr_index*/
+ re[length - i] = re[i] * one_by_length; /*stl_arr_index*/
+ re[i] = tmp;
+
+ tmp = im[length - i] * one_by_length; /*stl_arr_index*/
+ im[length - i] = im[i] * one_by_length; /*stl_arr_index*/
+ im[i] = tmp;
+ }
+
+ fft( re, im, length, 1 );
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+* Function ivas_mdft()
+
+* MDFT implementation
+*-----------------------------------------------------------------------------------------*/
+
+void ivas_mdft(
+ const float *pIn, /* i : input time-domain signal */
+ float *pOut_re, /* o : Real part of MDFT signal */
+ float *pOut_im, /* o : Imag. part of MDFT signal */
+ const int16_t input_length, /* i : signal length */
+ const int16_t mdft_length /* i : MDFT length */
+)
+{
+ float re[L_FRAME48k];
+ float im[L_FRAME48k];
+ int16_t j, len_by_2;
+ const float *pTwid;
+
+ len_by_2 = mdft_length >> 1;
+
+ ivas_get_mdft_twid_factors( mdft_length, &pTwid );
+
+ if ( mdft_length == input_length )
+ {
+ for ( j = 0; j < mdft_length; j++ )
+ {
+ re[j] = pIn[j] * pTwid[j];
+ im[j] = -pIn[j] * pTwid[mdft_length - j];
+ }
+ }
+ else
+ {
+ for ( j = 0; j < mdft_length; j++ )
+ {
+ re[j] = pIn[j] * pTwid[j] - pIn[j + mdft_length] * pTwid[mdft_length - j];
+ im[j] = -pIn[j] * pTwid[mdft_length - j] - pIn[j + mdft_length] * pTwid[j];
+ }
+ }
+
+ fft( re, im, mdft_length, 1 );
+
+ for ( j = 0; j < len_by_2; j++ )
+ {
+ pOut_re[2 * j] = re[j];
+ pOut_re[2 * j + 1] = re[mdft_length - j - 1];
+
+ pOut_im[2 * j] = im[j];
+ pOut_im[2 * j + 1] = -im[mdft_length - j - 1];
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_imdft()
+ *
+ * iMDFT implementation
+ * out buffer needs to have 2*length worth memory
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_imdft(
+ const float *pRe, /* i : Real part of MDFT signal */
+ const float *pIm, /* i : Imag. part of MDFT signal */
+ float *pOut, /* o : output time-domain signal */
+ const int16_t length /* i : signal length */
+)
+{
+ float *re_tmp = pOut;
+ float *im_tmp = pOut + length;
+ float tmp;
+ int16_t j;
+ int16_t len_by_2 = length >> 1;
+ const float *pTwid;
+
+ ivas_get_imdft_twid_factors( length, &pTwid );
+
+ for ( j = 0; j < len_by_2; j++ )
+ {
+ re_tmp[j] = pRe[2 * j];
+ re_tmp[j + len_by_2] = pRe[length - 2 * j - 1];
+
+ im_tmp[j] = pIm[2 * j];
+ im_tmp[j + len_by_2] = -pIm[length - 2 * j - 1];
+ }
+
+ ivas_ifft_cplx1( re_tmp, im_tmp, length );
+
+ for ( j = 0; j < length; j++ )
+ {
+ tmp = re_tmp[j] * pTwid[j] - im_tmp[j] * pTwid[length - j];
+ im_tmp[j] = -( re_tmp[j] * pTwid[length - j] + im_tmp[j] * pTwid[j] );
+ re_tmp[j] = tmp;
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..31874a7b52b295b9224516cb327b3ee778d4d607
--- /dev/null
+++ b/lib_com/ivas_omasa_com.c
@@ -0,0 +1,569 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include
+#include "ivas_cnst.h"
+#include "ivas_prot.h"
+#include "prot.h"
+#include "ivas_rom_com.h"
+#include
+
+/*---------------------------------------------------------------
+ * Local constants
+ *---------------------------------------------------------------*/
+
+#define GAMMA_ISM_LOW_IMP 0.8f
+#define GAMMA_ISM_MEDIUM_IMP 1.2f
+#define GAMMA_ISM_HIGH_IMP 1.4f
+
+#define GAMMA_ISM_LOW_IMP2 0.9f
+#define GAMMA_ISM_MEDIUM_IMP2 1.2f
+#define GAMMA_ISM_HIGH_IMP2 1.35f
+
+#define GAMMA_ISM_LOW_IMP3 0.85f
+#define GAMMA_ISM_MEDIUM_IMP3 1.15f
+#define GAMMA_ISM_HIGH_IMP3 1.3f
+
+#define GAMMA_ISM_LOW_IMP4 0.8f
+#define GAMMA_ISM_MEDIUM_IMP4 1.0f
+#define GAMMA_ISM_HIGH_IMP4 1.2f
+
+
+/*---------------------------------------------------------------
+ * ivas_omasa_ism_mode_select()
+ *
+ * selects the ISM mode base on IVAS total bit-rate and
+ * the number of objects in the combined ISM MASA format mode
+ * ---------------------------------------------------------------*/
+
+/*! r : ISM format mode */
+ISM_MODE ivas_omasa_ism_mode_select(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t nchan_ism /* i : number of input ISM's */
+)
+{
+ ISM_MODE ism_mode = ISM_MODE_NONE;
+
+ switch ( nchan_ism )
+ {
+ case 1:
+ if ( ivas_total_brate >= IVAS_24k4 )
+ {
+ ism_mode = ISM_MASA_MODE_DISC;
+ }
+ else
+ {
+ ism_mode = ISM_MODE_NONE;
+ }
+ break;
+ case 2:
+ if ( ivas_total_brate >= IVAS_48k )
+ {
+ ism_mode = ISM_MASA_MODE_DISC;
+ }
+ else if ( ivas_total_brate >= IVAS_32k )
+ {
+ ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
+ }
+ else
+ {
+ ism_mode = ISM_MODE_NONE;
+ }
+ break;
+ case 3:
+ if ( ivas_total_brate >= IVAS_96k )
+ {
+ ism_mode = ISM_MASA_MODE_DISC;
+ }
+ else if ( ivas_total_brate >= IVAS_64k )
+ {
+ ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
+ }
+ else if ( ivas_total_brate >= IVAS_32k )
+ {
+ ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ;
+ }
+ else
+ {
+ ism_mode = ISM_MODE_NONE;
+ }
+ break;
+ case 4:
+ if ( ivas_total_brate >= IVAS_128k )
+ {
+ ism_mode = ISM_MASA_MODE_DISC;
+ }
+ else if ( ivas_total_brate >= IVAS_64k )
+ {
+ ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
+ }
+ else if ( ivas_total_brate >= IVAS_32k )
+ {
+ ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ;
+ }
+ else
+ {
+ ism_mode = ISM_MODE_NONE;
+ }
+ break;
+ }
+
+ return ism_mode;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_set_omasa_TC()
+ *
+ * set number of transport channels in OMASA format
+ * ---------------------------------------------------------------*/
+
+void ivas_set_omasa_TC(
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ const int16_t nchan_ism, /* i : number of input ISMs */
+ int16_t *nSCE, /* o : number of SCEs */
+ int16_t *nCPE /* o : number of CPEs */
+)
+{
+ switch ( ism_mode )
+ {
+ case ISM_MASA_MODE_MASA_ONE_OBJ:
+ case ISM_MASA_MODE_PARAM_ONE_OBJ:
+ *nCPE = 1;
+ *nSCE = 1;
+ break;
+ case ISM_MASA_MODE_DISC:
+ *nCPE = 1;
+ *nSCE = nchan_ism;
+ break;
+ case ISM_MODE_NONE:
+ *nCPE = 1;
+ *nSCE = 0;
+ break;
+ default:
+ break;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_interformat_brate()
+ *
+ * Bit-budget distribution in case of combined-format coding
+ * ---------------------------------------------------------------*/
+
+/*! r: adjusted bitrate */
+int32_t ivas_interformat_brate(
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ const int16_t nchan_ism, /* i : number of ISM channels */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t ism_imp, /* i : ISM importance flag */
+ const int16_t limit_flag /* i : flag to limit the bitrate increase */
+)
+{
+ int32_t element_brate_out;
+ int16_t nBits, limit_low, limit_high;
+
+ nBits = (int16_t) ( element_brate / FRAMES_PER_SEC );
+
+ if ( ism_imp == ISM_INACTIVE_IMP )
+ {
+ nBits = BITS_ISM_INACTIVE;
+ }
+ else
+ {
+ if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate <= 24000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) /* for border case in DISC mode */
+ {
+ if ( limit_flag == 1 && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) )
+ {
+ return element_brate;
+ }
+
+ if ( ism_imp == ISM_LOW_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP4 );
+ }
+ else if ( ism_imp == ISM_MEDIUM_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP4 );
+ if ( limit_flag == -1 )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 );
+ }
+ }
+ else /* ISM_HIGH_IMP */
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 );
+ if ( limit_flag == -1 )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 );
+ }
+ }
+ }
+ else if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ||
+ ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */
+ )
+ {
+ if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && element_brate == IVAS_13k2 )
+ {
+ if ( ism_imp == ISM_LOW_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 );
+ }
+ else if ( ism_imp == ISM_MEDIUM_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 );
+ }
+ else /* ISM_HIGH_IMP */
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 );
+ }
+ }
+ else
+ {
+ if ( ism_imp == ISM_LOW_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 );
+ }
+ else if ( ism_imp == ISM_MEDIUM_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 );
+ }
+ else /* ISM_HIGH_IMP */
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 );
+ }
+ }
+ }
+ else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && element_brate == 16000 )
+ {
+ if ( ism_imp == ISM_LOW_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP );
+ }
+ else if ( ism_imp == ISM_MEDIUM_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP );
+ }
+ else /* ISM_HIGH_IMP */
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 );
+ }
+ }
+ else
+ {
+ if ( ism_imp == ISM_LOW_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP );
+ }
+ else if ( ism_imp == ISM_MEDIUM_IMP )
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP );
+ }
+ else /* ISM_HIGH_IMP */
+ {
+ nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP );
+ }
+ }
+ }
+
+ limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC;
+ if ( ism_imp == ISM_INACTIVE_IMP )
+ {
+ limit_low = BITS_ISM_INACTIVE;
+ }
+ else if ( element_brate >= SCE_CORE_16k_LOW_LIMIT )
+ {
+ limit_low = SCE_CORE_16k_LOW_LIMIT / FRAMES_PER_SEC;
+ }
+
+ limit_high = IVAS_512k / FRAMES_PER_SEC;
+ if ( element_brate < SCE_CORE_16k_LOW_LIMIT )
+ {
+ limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
+ }
+
+ nBits = check_bounds_s( nBits, limit_low, limit_high );
+
+ element_brate_out = nBits * FRAMES_PER_SEC;
+
+ return element_brate_out;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_combined_format_brate_sanity()
+ *
+ * Sanity check in combined format coding
+ * ---------------------------------------------------------------*/
+
+void ivas_combined_format_brate_sanity(
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t core, /* i : core */
+ const int32_t total_brate, /* i : total bitrate */
+ int32_t *core_brate, /* i/o: core bitrate */
+ int16_t *inactive_coder_type_flag, /* o : inactive coder_type flag */
+ int16_t *diff_nBits /* o : number of differential bits */
+)
+{
+ int16_t limit_high, nBits;
+ int32_t brate_diff;
+
+ brate_diff = total_brate - *core_brate;
+
+ /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by
+ low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget
+ for ACELP core-coding @12.8 kHz is too high */
+
+ if ( element_brate < ACELP_12k8_HIGH_LIMIT )
+ {
+ limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
+ nBits = (int16_t) ( *core_brate / FRAMES_PER_SEC );
+
+ *diff_nBits = nBits - limit_high;
+ if ( *diff_nBits > 0 )
+ {
+ if ( core == TCX_20_CORE || core == TCX_10_CORE )
+ {
+ *diff_nBits = 0;
+ }
+ else /* ACELP core */
+ {
+ *core_brate -= ( *diff_nBits * FRAMES_PER_SEC );
+ }
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * set inactive coder_type flag in ACELP core
+ *-----------------------------------------------------------------*/
+
+ if ( core == ACELP_CORE )
+ {
+ *inactive_coder_type_flag = 0; /* AVQ by default */
+ if ( *core_brate + brate_diff <= MAX_GSC_INACTIVE_BRATE )
+ {
+ *inactive_coder_type_flag = 1; /* GSC */
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * bits_index_ism_ratio()
+ *
+ *
+ * ---------------------------------------------------------------*/
+
+/*!r : number of bits for ISM ratio index */
+int16_t bits_index_ism_ratio(
+ const int16_t nchan_ism /* i : number of objects */
+)
+{
+ int16_t bits_index;
+
+ bits_index = 0;
+ if ( nchan_ism == 2 )
+ {
+ bits_index = 3;
+ }
+ else if ( nchan_ism == 3 )
+ {
+ bits_index = 6;
+ }
+ else if ( nchan_ism == 4 )
+ {
+ bits_index = 7;
+ }
+ else
+ {
+ assert( ( nchan_ism >= 2 && nchan_ism <= 4 ) && "Wrong number of objects for MASA_ISM." );
+ }
+
+ return bits_index;
+}
+
+
+/*---------------------------------------------------------------
+ * calculate_nbits_meta()
+ *
+ *
+ * ---------------------------------------------------------------*/
+
+void calculate_nbits_meta(
+ const int16_t nchan_ism,
+ float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS],
+ float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],
+ const int16_t numSf,
+ const int16_t numCodingBands,
+ int16_t *bits_ism,
+ const int16_t idx_sep_obj,
+ const int16_t ism_imp )
+{
+ int16_t sf, band, obj;
+ float priority[MAX_NUM_OBJECTS], max_p;
+
+ if ( nchan_ism > 1 )
+ {
+ set_f( priority, 0.0f, nchan_ism );
+ for ( sf = 0; sf < numSf; sf++ )
+ {
+ for ( band = 0; band < numCodingBands; band++ )
+ {
+ for ( obj = 0; obj < nchan_ism; obj++ )
+ {
+ priority[obj] = max( priority[obj], ( q_energy_ratio_ism[sf][band][obj] * ( 1 - masa_to_total_energy_ratio[sf][band] ) ) );
+ }
+ }
+ }
+ }
+ else
+ {
+ priority[0] = 1;
+ }
+
+ /* decide parameters for ISM metadata quantization */
+ maximum( priority, nchan_ism, &max_p );
+ for ( obj = 0; obj < nchan_ism; obj++ )
+ {
+ if ( obj == idx_sep_obj )
+ {
+ if ( ism_imp == 3 )
+ {
+ priority[obj] = 1;
+ }
+ else if ( ism_imp == 2 )
+ {
+ priority[obj] = ( 1 + max_p ) * 0.5f;
+ }
+ else
+ {
+ priority[obj] = max_p;
+ }
+ }
+ bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - ( (int16_t) ( priority[obj] * 1000.0f ) ) * 0.001f ) * 6 );
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * ivas_get_stereo_panning_gains()
+ *
+ *
+ *---------------------------------------------------------------*/
+
+void ivas_get_stereo_panning_gains(
+ const float aziDeg,
+ const float eleDeg,
+ float panningGains[2] )
+{
+ float aziRad, eleRad;
+ float y, mappedX, aziRadMapped, A, A2, A3;
+ const float LsAngleRad = 30.0f * PI_OVER_180;
+ /* Convert azi and ele to an azi value of the cone of confusion */
+ aziRad = aziDeg * PI_OVER_180;
+ eleRad = eleDeg * PI_OVER_180;
+ y = ( sinf( aziRad ) * cosf( eleRad ) );
+ mappedX = sqrtf( max( 0.0f, 1.0f - ( y * y ) ) );
+ aziRadMapped = atan2f( y, mappedX );
+
+ if ( aziRadMapped >= LsAngleRad )
+ { /* Left side */
+ panningGains[0] = 1.0f;
+ panningGains[1] = 0.0f;
+ }
+ else if ( aziRadMapped <= -LsAngleRad )
+ { /* Right side */
+ panningGains[0] = 0.0f;
+ panningGains[1] = 1.0f;
+ }
+ else /* Tangent panning law */
+ {
+ A = tanf( aziRadMapped ) / tanf( LsAngleRad );
+ A2 = ( A - 1.0f ) / max( 0.001f, A + 1.0f );
+ A3 = 1.0f / ( A2 * A2 + 1.0f );
+ panningGains[0] = sqrtf( A3 );
+ panningGains[1] = sqrtf( 1.0f - A3 );
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * calculate_brate_limit_flag()
+ *
+ *
+ *---------------------------------------------------------------*/
+
+/*! r: limitation flag */
+int16_t calculate_brate_limit_flag(
+ const int16_t ism_imp[], /* i : ISM importance flags */
+ const int16_t nchan_ism /* i : number of objects */
+)
+{
+ int16_t n;
+ int16_t brate_limit_flag;
+ int16_t nzeros;
+
+ brate_limit_flag = 0;
+ nzeros = 0;
+ for ( n = 0; n < nchan_ism; n++ )
+ {
+ brate_limit_flag += ism_imp[n];
+ if ( ism_imp[n] == 0 )
+ {
+ nzeros++;
+ }
+ }
+
+ if ( brate_limit_flag >= (int16_t) ( nchan_ism * 2.5f ) )
+ {
+ brate_limit_flag = 1;
+ }
+ else
+ {
+ if ( nzeros / (float) nchan_ism >= 0.5f )
+ {
+ brate_limit_flag = -1; /* there is no limitation, on the contrary */
+ }
+ }
+
+ return brate_limit_flag;
+}
diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools.c
new file mode 100644
index 0000000000000000000000000000000000000000..a9dcffd1e69f6319c49145ad9d3282787bd0b634
--- /dev/null
+++ b/lib_com/ivas_pca_tools.c
@@ -0,0 +1,1118 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_prot.h"
+#include "ivas_cnst.h"
+#include
+#include
+#include "ivas_rom_com.h"
+#include "wmc_auto.h"
+#include "prot.h"
+
+
+/*---------------------------------------------------------------------*
+ * eye_matrix()
+ *
+ *---------------------------------------------------------------------*/
+
+void eye_matrix(
+ float *mat,
+ const int16_t n,
+ const float d )
+{
+ int16_t i;
+
+ for ( i = 0; i < n * n; i++ )
+ {
+ mat[i] = 0.0f;
+ }
+ for ( i = 0; i < n; i++ )
+ {
+ mat[i * n + i] = d;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * cov()
+ *
+ * Compute covariance of input channels
+ *---------------------------------------------------------------------*/
+
+void cov_subfr(
+ float **ptr_sig,
+ float *r,
+ const int16_t n_channels,
+ const int16_t len )
+{
+ float s;
+ int16_t j, k, l;
+ float *t, *tt;
+
+ /* Compute diagonal r[k][k] */
+ for ( k = 0; k < n_channels; k++ )
+ {
+ t = &ptr_sig[k][0];
+ s = t[0] * t[0];
+ for ( j = 1; j < len; j++ )
+ {
+ s += t[j] * t[j];
+ }
+ r[k * n_channels + k] = s;
+ }
+
+ /* Compute off-diagonal r[k][l] = r[l][k] */
+ for ( k = 0; k < ( n_channels - 1 ); k++ )
+ {
+ t = &ptr_sig[k][0];
+ for ( l = k + 1; l < n_channels; l++ )
+ {
+ tt = &ptr_sig[l][0];
+ s = t[0] * tt[0];
+ for ( j = 1; j < len; j++ )
+ {
+ s += t[j] * tt[j];
+ }
+ r[k * n_channels + l] = s;
+ r[l * n_channels + k] = s;
+ }
+ }
+
+ return;
+}
+
+
+static void house_refl(
+ const float *px,
+ const int16_t sizex,
+ float *pu,
+ float *normu )
+{
+ int16_t i;
+
+ mvr2r( px, pu, sizex );
+ ( *normu ) = dotp( pu, pu, sizex );
+ ( *normu ) = sqrtf( *normu );
+
+ if ( ( *normu ) == 0.f )
+ {
+ pu[0] = SQRT2;
+ }
+ else
+ {
+ float rcp = 1.f / ( *normu );
+
+ for ( i = 0; i < sizex; i++ )
+ {
+ pu[i] *= rcp;
+ }
+ if ( pu[0] >= 0.f )
+ {
+ pu[0] += 1;
+ ( *normu ) = -( *normu );
+ }
+ else
+ {
+ pu[0] -= 1;
+ }
+
+ rcp = inv_sqrt( fabsf( pu[0] ) );
+
+ for ( i = 0; i < sizex; i++ )
+ {
+ pu[i] *= rcp;
+ }
+ }
+
+ return;
+}
+
+
+static void house_qr(
+ const float *pA,
+ float *pQ,
+ float *pR,
+ const int16_t n )
+{
+ int16_t n_rows = FOA_CHANNELS;
+ float A[FOA_CHANNELS * FOA_CHANNELS];
+ float U[FOA_CHANNELS * FOA_CHANNELS];
+ float pu[FOA_CHANNELS];
+ float pa[FOA_CHANNELS];
+ float pv[FOA_CHANNELS];
+ int16_t i, j, k, c, s, r;
+
+ mvr2r( pA, A, FOA_CHANNELS * FOA_CHANNELS );
+ set_zero( U, FOA_CHANNELS * FOA_CHANNELS );
+ set_zero( pR, FOA_CHANNELS * FOA_CHANNELS );
+
+ for ( k = 0; k < n_rows; k++ )
+ {
+ for ( i = 0; i < n_rows; i++ )
+ {
+ pa[i] = A[i * n + k];
+ }
+
+ house_refl( &pa[k], n_rows - k, pu, &pR[k * n_rows + k] );
+ U[k * n_rows + k] = pu[0];
+ for ( c = k + 1; c < n_rows; c++ )
+ {
+ for ( i = 0; i < n_rows; i++ )
+ {
+ pa[i] = A[i * n + c];
+ }
+ pv[c - k - 1] = dotp( pu, &pa[k], n_rows - k );
+ U[c * n_rows + k] = pu[c - k];
+ }
+
+ i = 0;
+ for ( s = k; s < n_rows; s++ )
+ {
+ j = 0;
+ for ( r = k + 1; r < n_rows; r++ )
+ {
+ A[s * n_rows + r] -= ( pu[i] * pv[j] );
+ j++;
+ }
+ i++;
+ }
+
+ for ( r = k + 1; r < n_rows; r++ )
+ {
+ pR[k * n_rows + r] = A[k * n_rows + r];
+ }
+ }
+
+ eye_matrix( pQ, FOA_CHANNELS, 1.0f );
+
+ for ( k = FOA_CHANNELS - 1; k >= 0; k-- )
+ {
+ for ( i = 0; i < n_rows; i++ )
+ {
+ pu[i] = U[i * n + k];
+ }
+
+ for ( s = k; s < n_rows; s++ )
+ {
+ for ( i = 0; i < n_rows; i++ )
+ {
+ pa[i] = pQ[i * n + s];
+ }
+ pv[s - k] = dotp( &pu[k], &pa[k], n_rows - k );
+ }
+ for ( s = k; s < n_rows; s++ )
+ {
+ for ( r = k; r < n_rows; r++ )
+ {
+ pQ[s * n_rows + r] -= U[s * n_rows + k] * pv[r - k];
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * eig_qr()
+ *
+ * Compute eigenvalue decomposition by QR method
+ *---------------------------------------------------------------------*/
+
+void eig_qr(
+ const float *A,
+ const int16_t num_iter,
+ float *EV,
+ float *Vals,
+ const int16_t n )
+{
+ int16_t i;
+ int16_t breakcnd, iter_num;
+ float Ak[FOA_CHANNELS * FOA_CHANNELS], Qk[FOA_CHANNELS * FOA_CHANNELS], Rk[FOA_CHANNELS * FOA_CHANNELS], D[FOA_CHANNELS * FOA_CHANNELS], d;
+
+ assert( n <= FOA_CHANNELS );
+ breakcnd = 1;
+ iter_num = 0;
+
+ /* check zero matrix */
+ d = dotp( A, A, n * n );
+ if ( d != 0. )
+ {
+ breakcnd = 0;
+ }
+
+ /* duplicate */
+ mvr2r( A, Ak, n * n );
+
+ /* identity */
+ set_zero( EV, n * n );
+ for ( i = 0; i < n; i++ )
+ {
+ EV[i * n + i] = 1.0f;
+ }
+
+ set_zero( Vals, n );
+
+ while ( breakcnd == 0 )
+ {
+ iter_num++;
+ mvr2r( Ak, D, n * n );
+
+ /* set diagonal */
+ for ( i = 0; i < n; i++ )
+ {
+ D[i * n + i] = Vals[i];
+ }
+
+ /* stop condition */
+ d = dotp( D, D, n * n );
+ d = sqrtf( d ); /* Frobenius norm */
+
+ if ( ( d < 1e-10f ) || ( iter_num >= num_iter ) )
+ {
+ breakcnd = 1;
+ }
+
+ house_qr( Ak, Qk, Rk, n );
+
+ matrix_product( Qk, n, n, 0, Rk, n, n, 0, Ak );
+ matrix_product( Qk, n, n, 0, EV, n, n, 0, D );
+
+ mvr2r( D, EV, n * n );
+ }
+
+ /* get diagonal */
+ for ( i = 0; i < n; i++ )
+ {
+ Vals[i] = Ak[i * n + i];
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * exhst_4x4()
+ *
+ * Find optimal permutation of eigenvectors
+ *---------------------------------------------------------------------*/
+
+void exhst_4x4(
+ float *cost_mtx,
+ int16_t *path,
+ const int16_t maximize )
+{
+ int16_t i, j, k, l;
+ float opt_val, cost;
+
+ if ( maximize == 0 )
+ {
+ opt_val = 1e30f;
+ }
+ else
+ {
+ opt_val = -1e30f;
+ }
+
+ for ( i = 0; i < 1; i++ )
+ {
+ for ( j = 0; j < 4; j++ )
+ {
+ if ( j != i )
+ {
+ for ( k = 0; k < 4; k++ )
+ {
+ if ( ( k != i ) && ( k != j ) )
+ {
+ for ( l = 0; l < 4; l++ )
+ {
+ if ( ( l != i ) && ( l != j ) && ( l != k ) )
+ {
+ cost = cost_mtx[0 * 4 + i] + cost_mtx[1 * 4 + j] + cost_mtx[2 * 4 + k] + cost_mtx[3 * 4 + l];
+ if ( ( ( maximize == 0 ) && ( opt_val > cost ) ) || ( ( maximize != 0 ) && ( opt_val < cost ) ) )
+ {
+ opt_val = cost;
+ path[0] = i;
+ path[1] = j;
+ path[2] = k;
+ path[3] = l;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * mat2dquat()
+ *
+ * Convert 4D matrix -> double quaternion
+ *---------------------------------------------------------------------*/
+
+void mat2dquat(
+ const float *a,
+ float *ql,
+ float *qr )
+{
+ float AM[16], M2[16], tmp_l, tmp_r, temp, ql_max, qr_max;
+ int16_t i, j, k, i_ql, i_qr;
+
+ /* compute associate matrix */
+ AM[0 * 4 + 0] = ( a[0 * 4 + 0] + a[1 * 4 + 1] + a[2 * 4 + 2] + a[3 * 4 + 3] ) / 4.0f;
+ AM[1 * 4 + 0] = ( a[1 * 4 + 0] - a[0 * 4 + 1] + a[3 * 4 + 2] - a[2 * 4 + 3] ) / 4.0f;
+ AM[2 * 4 + 0] = ( a[2 * 4 + 0] - a[3 * 4 + 1] - a[0 * 4 + 2] + a[1 * 4 + 3] ) / 4.0f;
+ AM[3 * 4 + 0] = ( a[3 * 4 + 0] + a[2 * 4 + 1] - a[1 * 4 + 2] - a[0 * 4 + 3] ) / 4.0f;
+ AM[0 * 4 + 1] = ( a[1 * 4 + 0] - a[0 * 4 + 1] - a[3 * 4 + 2] + a[2 * 4 + 3] ) / 4.0f;
+ AM[1 * 4 + 1] = ( -a[0 * 4 + 0] - a[1 * 4 + 1] + a[2 * 4 + 2] + a[3 * 4 + 3] ) / 4.0f;
+ AM[2 * 4 + 1] = ( -a[3 * 4 + 0] - a[2 * 4 + 1] - a[1 * 4 + 2] - a[0 * 4 + 3] ) / 4.0f;
+ AM[3 * 4 + 1] = ( a[2 * 4 + 0] - a[3 * 4 + 1] + a[0 * 4 + 2] - a[1 * 4 + 3] ) / 4.0f;
+ AM[0 * 4 + 2] = ( a[2 * 4 + 0] + a[3 * 4 + 1] - a[0 * 4 + 2] - a[1 * 4 + 3] ) / 4.0f;
+ AM[1 * 4 + 2] = ( a[3 * 4 + 0] - a[2 * 4 + 1] - a[1 * 4 + 2] + a[0 * 4 + 3] ) / 4.0f;
+ AM[2 * 4 + 2] = ( -a[0 * 4 + 0] + a[1 * 4 + 1] - a[2 * 4 + 2] + a[3 * 4 + 3] ) / 4.0f;
+ AM[3 * 4 + 2] = ( -a[1 * 4 + 0] - a[0 * 4 + 1] - a[3 * 4 + 2] - a[2 * 4 + 3] ) / 4.0f;
+ AM[0 * 4 + 3] = ( a[3 * 4 + 0] - a[2 * 4 + 1] + a[1 * 4 + 2] - a[0 * 4 + 3] ) / 4.0f;
+ AM[1 * 4 + 3] = ( -a[2 * 4 + 0] - a[3 * 4 + 1] - a[0 * 4 + 2] - a[1 * 4 + 3] ) / 4.0f;
+ AM[2 * 4 + 3] = ( a[1 * 4 + 0] + a[0 * 4 + 1] - a[3 * 4 + 2] - a[2 * 4 + 3] ) / 4.0f;
+ AM[3 * 4 + 3] = ( -a[0 * 4 + 0] + a[1 * 4 + 1] + a[2 * 4 + 2] - a[3 * 4 + 3] ) / 4.0f;
+
+ /* compute squared matrix */
+ for ( i = 0; i < 16; i++ )
+ {
+ M2[i] = AM[i] * AM[i];
+ }
+
+ /* determine (absolute) left and right terms */
+ i_ql = 0;
+ i_qr = 0;
+ ql_max = -1;
+ qr_max = -1;
+
+ for ( i = 0; i < 4; i++ )
+ {
+ tmp_l = 0.f;
+ tmp_r = 0.f;
+ for ( j = 0; j < 4; j++ )
+ {
+ /* sum over row */
+ tmp_l += M2[i * 4 + j];
+ /* sum over column */
+ tmp_r += M2[j * 4 + i];
+ }
+
+ ql[i] = sqrtf( tmp_l );
+ if ( ql[i] > ql_max )
+ {
+ ql_max = ql[i];
+ i_ql = i;
+ }
+
+ qr[i] = sqrtf( tmp_r );
+ if ( qr[i] > qr_max )
+ {
+ qr_max = qr[i];
+ i_qr = i;
+ }
+ }
+
+ /* set signs */
+ for ( k = 0; k < 4; k++ )
+ {
+ if ( AM[i_ql * 4 + k] < 0 )
+ {
+ qr[k] = -qr[k];
+ }
+ }
+
+ for ( k = 0; k < 4; k++ )
+ {
+ temp = AM[k * 4 + i_qr] * ( ql[k] * qr[i_qr] );
+ if ( temp < 0 )
+ {
+ ql[k] = -ql[k];
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * dquat2mat()
+ *
+ * Convert double quaternion -> 4D matrix
+ *---------------------------------------------------------------------*/
+
+void dquat2mat(
+ const float *ql,
+ const float *qr,
+ float *m )
+{
+ float a, b, c, d;
+ float w, x, y, z;
+ float aw, ax, ay, az;
+ float bw, bx, by, bz;
+ float cw, cx, cy, cz;
+ float dw, dx, dy, dz;
+
+ a = ql[0];
+ b = ql[1];
+ c = ql[2];
+ d = ql[3];
+ w = qr[0];
+ x = qr[1];
+ y = qr[2];
+ z = qr[3];
+ aw = a * w;
+ ax = a * x;
+ ay = a * y;
+ az = a * z;
+ bw = b * w;
+ bx = b * x;
+ by = b * y;
+ bz = b * z;
+ cw = c * w;
+ cx = c * x;
+ cy = c * y;
+ cz = c * z;
+ dw = d * w;
+ dx = d * x;
+ dy = d * y;
+ dz = d * z;
+ m[0] = aw - bx - cy - dz;
+ m[1] = -ax - bw + cz - dy;
+ m[2] = -ay - bz - cw + dx;
+ m[3] = -az + by - cx - dw;
+ m[4] = bw + ax - dy + cz;
+ m[5] = -bx + aw + dz + cy;
+ m[6] = -by + az - dw - cx;
+ m[7] = -bz - ay - dx + cw;
+ m[8] = cw + dx + ay - bz;
+ m[9] = -cx + dw - az - by;
+ m[10] = -cy + dz + aw + bx;
+ m[11] = -cz - dy + ax - bw;
+ m[12] = dw - cx + by + az;
+ m[13] = -dx - cw - bz + ay;
+ m[14] = -dy - cz + bw - ax;
+ m[15] = -dz + cy + bx + aw;
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * quat_shortestpath()
+ *
+ * Shortest path verification (prior to quaternion interpolation)
+ *---------------------------------------------------------------------*/
+
+void quat_shortestpath(
+ const float *q00,
+ float *q01,
+ const float *q10,
+ float *q11 )
+{
+ float d0, d1;
+ int16_t res, i;
+
+ d0 = dotp( q00, q01, IVAS_PCA_INTERP );
+ d1 = dotp( q10, q11, IVAS_PCA_INTERP );
+
+ res = 0;
+ if ( ( d0 < 0. ) && ( d1 < 0. ) )
+ {
+ res = 1;
+ }
+ else
+ {
+ if ( d0 < 0. )
+ {
+ if ( ( -d0 ) > d1 )
+ {
+ res = 1;
+ }
+ }
+ else
+ {
+ if ( d1 < 0. )
+ {
+ if ( ( -d1 ) > d0 )
+ {
+ res = 1;
+ }
+ }
+ }
+ }
+
+ if ( res )
+ {
+ for ( i = 0; i < IVAS_PCA_INTERP; i++ )
+ {
+ q01[i] = -q01[i];
+ q11[i] = -q11[i];
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * mat_det4()
+ *
+ * Compute determinant of 4D matrix - brute-force version
+ *---------------------------------------------------------------------*/
+
+float mat_det4(
+ const float *m )
+{
+ float d;
+
+#define a11 m[0]
+#define a12 m[1]
+#define a13 m[2]
+#define a14 m[3]
+#define a21 m[4]
+#define a22 m[5]
+#define a23 m[6]
+#define a24 m[7]
+#define a31 m[8]
+#define a32 m[9]
+#define a33 m[10]
+#define a34 m[11]
+#define a41 m[12]
+#define a42 m[13]
+#define a43 m[14]
+#define a44 m[15]
+
+ /* 4! = 24 terms -> complexity = 24x(4 INDIRECT + 3 MULT) + 23 ADD */
+ d = a11 * a22 * a33 * a44 + a11 * a24 * a32 * a43 + a11 * a23 * a34 * a42 - a11 * a24 * a33 * a42 - a11 * a22 * a34 * a43 -
+ a11 * a23 * a32 * a44 - a12 * a21 * a33 * a44 - a12 * a23 * a34 * a41 - a12 * a24 * a31 * a43 + a12 * a24 * a33 * a41 +
+ a12 * a21 * a34 * a43 + a12 * a23 * a31 * a44 + a13 * a21 * a32 * a44 + a13 * a22 * a34 * a41 + a13 * a24 * a31 * a42 -
+ a13 * a24 * a32 * a41 - a13 * a21 * a34 * a42 - a13 * a22 * a31 * a44 - a14 * a21 * a32 * a43 - a14 * a22 * a33 * a41 -
+ a14 * a23 * a31 * a42 + a14 * a23 * a32 * a41 + a14 * a21 * a33 * a42 + a14 * a22 * a31 * a43;
+
+ return d;
+}
+
+
+static void norm_quat(
+ float *q )
+{
+ float norm_q;
+ int16_t i;
+
+ norm_q = dotp( q, q, IVAS_PCA_INTERP );
+
+ norm_q = inv_sqrt( norm_q ); // TODO: possible division by 0
+
+ for ( i = 0; i < IVAS_PCA_INTERP; i++ )
+ {
+ q[i] *= norm_q;
+ }
+
+ return;
+}
+
+
+static void quat_nlerp_preproc(
+ const float *q0,
+ const float *q1,
+ const float alpha,
+ float *q_slerp )
+{
+ int16_t i;
+
+ for ( i = 0; i < IVAS_PCA_INTERP; i++ )
+ {
+ q_slerp[i] = alpha * q0[i] + ( 1.0f - alpha ) * q1[i];
+ }
+
+ norm_quat( q_slerp );
+
+ return;
+}
+
+
+void pca_interp_preproc(
+ const float *prev_ql,
+ const float *prev_qr,
+ const float *ql,
+ const float *qr,
+ const int16_t len,
+ float *ql_interp,
+ float *qr_interp )
+{
+ float alpha;
+ int16_t j;
+
+ for ( j = 0; j < len; j++ )
+ {
+ alpha = (float) j / (float) ( len - 1 ); // the increment can be updated by simple delta
+ alpha = 0.5f * ( 1.f - cosf( EVS_PI * alpha ) );
+ alpha = 1 - alpha;
+ quat_nlerp_preproc( prev_ql, ql, alpha, &ql_interp[j * IVAS_PCA_INTERP] );
+ quat_nlerp_preproc( prev_qr, qr, alpha, &qr_interp[j * IVAS_PCA_INTERP] );
+ }
+
+ return;
+}
+
+
+static float acos_clip(
+ float v )
+{
+ float ph;
+
+ v = check_bounds( v, -1.0f, 1.0f );
+
+ ph = acosf( v );
+
+ return ph;
+}
+
+
+static void sp2cart(
+ const float ph1,
+ const float ph2,
+ const float ph3,
+ float *q )
+{
+ float s1, s2, s1s2;
+
+ s1 = sinf( ph1 );
+ s2 = sinf( ph2 );
+ s1s2 = s1 * s2;
+ q[3] = sinf( ph3 ) * s1s2;
+ q[2] = cosf( ph3 ) * s1s2;
+ q[1] = cosf( ph2 ) * s1;
+ q[0] = cosf( ph1 );
+
+ return;
+}
+
+static int16_t calc_n2(
+ const float ph1 )
+{
+ int16_t n2;
+
+ n2 = (int16_t) roundf( 90.f * sinf( ph1 ) );
+
+ if ( n2 % 2 == 0 )
+ {
+ n2++;
+ }
+
+ return n2;
+}
+
+
+static int16_t calc_n3(
+ const float ph1,
+ const float ph2 )
+{
+ int16_t n3;
+
+ n3 = (int16_t) roundf( 180.f * sinf( ph1 ) * sinf( ph2 ) );
+
+ if ( n3 == 0 )
+ {
+ n3 = 1;
+ }
+ else
+ {
+ if ( ( n3 % 2 ) == 1 )
+ {
+ n3++;
+ }
+ }
+
+ return n3;
+}
+
+
+static void q_ang_2surv(
+ const float a,
+ const int16_t N,
+ float *a_q,
+ int16_t *index )
+{
+ float d, v;
+ int16_t temp;
+
+ if ( N == 1 )
+ {
+ a_q[0] = 0.f;
+ a_q[1] = 0.f;
+ index[0] = 0;
+ index[1] = 0;
+ return;
+ }
+ d = EVS_PI / ( N - 1 );
+ if ( a >= EVS_PI )
+ {
+ index[0] = N - 1;
+ index[1] = N - 2;
+ }
+ else
+ {
+ if ( a <= 0 )
+ {
+ index[0] = 0;
+ index[1] = 1;
+ }
+ else
+ {
+ v = a / d;
+ index[0] = (int16_t) floorf( v );
+ index[1] = (int16_t) ceilf( v );
+
+ if ( index[0] == index[1] )
+ {
+ /*printf("warning: identical indices\n"); */
+ }
+ else
+ {
+ if ( ( v - index[0] ) < ( index[1] - v ) )
+ {
+ temp = index[1];
+ index[1] = index[0];
+ index[0] = temp;
+ }
+ }
+ }
+ }
+ a_q[0] = index[0] * d;
+ a_q[1] = index[1] * d;
+
+ return;
+}
+
+
+static void q_ang_circ(
+ const float a,
+ const int16_t N,
+ float *a_q,
+ int16_t *index )
+{
+ float d;
+ if ( N == 1 )
+ {
+ *a_q = 0.f;
+ *index = 0;
+
+ return;
+ }
+
+ d = PI2 / N;
+
+ if ( a >= PI2 )
+ {
+ *index = N;
+ }
+ else
+ {
+ if ( a <= 0.f )
+ {
+ *index = 0;
+ }
+ else
+ {
+ *index = (int16_t) roundf( a / d );
+ }
+ }
+
+ if ( *index == N )
+ {
+ *index = 0;
+ }
+
+ assert( ( *index >= 0 ) && ( *index <= ( N - 1 ) ) );
+ *a_q = *index * d;
+
+ return;
+}
+
+
+static int16_t sel_q(
+ const float *q,
+ const float *q_cand,
+ const int16_t n )
+{
+ int16_t i, i_min, j;
+ float d, d_min, temp;
+ const float *p;
+
+ i_min = -1;
+ d_min = 1e30f;
+ p = q_cand;
+
+ for ( i = 0; i < n; i++ )
+ {
+ d = 0.f;
+ for ( j = 0; j < 4; j++ )
+ {
+ temp = q[j] - p[j];
+ d += temp * temp;
+ }
+
+ if ( d < d_min )
+ {
+ d_min = d;
+ i_min = i;
+ }
+ p += 4;
+ }
+ assert( i_min >= 0 );
+
+ return i_min;
+}
+
+
+static int16_t get_pca_offset_n2(
+ const int16_t index1 )
+{
+ int16_t index2;
+
+ if ( index1 <= IVAS_PCA_N1_EQ )
+ {
+ index2 = ivas_pca_offset_n2[index1];
+ }
+ else
+ {
+ index2 = ivas_pca_offset_n2[IVAS_PCA_N1 - 1 - index1];
+ }
+
+ return index2;
+}
+
+
+/*---------------------------------------------------------------------*
+ * pca_enc_s3()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+void pca_enc_s3(
+ float *q,
+ int32_t *index )
+{
+ float ph1, ph2, ph3, r, v;
+ float ph1_q[2], ph2_q[4], ph3_q[4];
+ int16_t n1, n2[2], n3[4];
+ int16_t ind1[2], ind2[4], ind3[4], index1, index2, index3;
+ int16_t i, j;
+ float q_cand[4 * 4];
+
+ n1 = IVAS_PCA_N1;
+ ph1 = acos_clip( q[0] );
+ if ( fabsf( fabsf( q[0] ) - 1.0f ) < IVAS_PCA_QUAT_EPS )
+ {
+ if ( q[0] > 0 )
+ {
+ *ph1_q = 0.f;
+ index1 = 0;
+ }
+ else
+ {
+ *ph1_q = EVS_PI;
+ index1 = n1 - 1;
+ }
+
+ sp2cart( *ph1_q, 0.f, 0.f, q );
+
+ *index = ivas_pca_offset_index1[index1];
+
+ return;
+ }
+
+ q_ang_2surv( ph1, n1, ph1_q, ind1 );
+
+ r = sqrtf( q[1] * q[1] + q[2] * q[2] + q[3] * q[3] );
+
+ v = q[1] / r;
+ ph2 = acos_clip( v );
+
+ if ( fabs( fabs( v ) - 1.0f ) < IVAS_PCA_QUAT_EPS )
+ {
+ for ( i = 0; i < 2; i++ )
+ {
+ n2[i] = calc_n2( ph1_q[i] );
+ if ( v > 0 )
+ {
+ ph2_q[i] = 0;
+ ind2[i] = 0;
+ }
+ else
+ {
+ ph2_q[i] = EVS_PI;
+ ind2[i] = n2[i] - 1;
+ }
+
+ sp2cart( ph1_q[i], ph2_q[i], 0, &q_cand[4 * i] );
+ }
+
+ j = sel_q( q, q_cand, 2 );
+
+ mvr2r( q_cand + 4 * j, q, 4 );
+ index1 = ind1[j];
+ index2 = ind2[j];
+
+ index2 += get_pca_offset_n2( index1 );
+
+ *index = ivas_pca_offset_index1[index1] + ivas_pca_offset_index2[index2];
+
+ return;
+ }
+
+ for ( i = 0; i < 2; i++ )
+ {
+ n2[i] = calc_n2( ph1_q[i] );
+ q_ang_2surv( ph2, n2[i], ph2_q + 2 * i, ind2 + 2 * i );
+ }
+ r = sqrtf( q[2] * q[2] + q[3] * q[3] );
+ v = q[2] / r;
+ ph3 = acos_clip( v );
+
+ if ( q[3] < 0 )
+ {
+ ph3 = PI2 - ph3;
+ }
+
+ for ( i = 0; i < 4; i++ )
+ {
+ n3[i] = calc_n3( ph1_q[i >> 1], ph2_q[i] );
+ q_ang_circ( ph3, n3[i], ph3_q + i, ind3 + i );
+ sp2cart( ph1_q[i >> 1], ph2_q[i], ph3_q[i], q_cand + ( 4 * i ) );
+ }
+
+ j = sel_q( q, q_cand, 4 );
+
+ mvr2r( q_cand + 4 * j, q, 4 );
+
+ index1 = ind1[j >> 1];
+ index2 = ind2[j];
+ index3 = ind3[j];
+ index2 += get_pca_offset_n2( index1 );
+
+ *index = ivas_pca_offset_index1[index1] + ivas_pca_offset_index2[index2] + index3;
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * pca_dec_s3()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+void pca_dec_s3(
+ const int32_t index,
+ float *q )
+{
+ float ph1_q, ph2_q, ph3_q;
+ int32_t j;
+ int16_t i;
+ int16_t n1, n2, n3;
+ int16_t index1, index2, index3;
+ float d;
+
+ j = index;
+ index1 = -1;
+ for ( i = 0; i < IVAS_PCA_N1; i++ )
+ {
+ if ( j < ivas_pca_offset_index1[i + 1] )
+ {
+ index1 = i;
+ break;
+ }
+ }
+
+ assert( index1 > -1 );
+
+ n1 = IVAS_PCA_N1;
+ d = EVS_PI / ( n1 - 1 );
+ ph1_q = index1 * d;
+ n2 = calc_n2( ph1_q );
+
+ j -= ivas_pca_offset_index1[index1];
+ index2 = -1;
+
+ for ( i = 0; i < n2; i++ )
+ {
+ if ( j < ivas_pca_offset_index2[i + get_pca_offset_n2( index1 ) + 1] )
+ {
+ index2 = i;
+ break;
+ }
+ }
+
+ assert( index2 > -1 );
+
+ if ( n2 == 1 )
+ {
+ ph2_q = 0;
+ }
+ else
+ {
+ d = EVS_PI / ( n2 - 1 );
+ ph2_q = index2 * d;
+ }
+
+ j -= ivas_pca_offset_index2[index2 + get_pca_offset_n2( index1 )];
+
+ index3 = (int16_t) j;
+
+ n3 = calc_n3( ph1_q, ph2_q );
+
+ if ( n3 == 1 )
+ {
+ ph3_q = 0;
+ }
+ else
+ {
+ d = PI2 / n3;
+ ph3_q = d * index3;
+ }
+ sp2cart( ph1_q, ph2_q, ph3_q, q );
+
+ return;
+}
diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h
new file mode 100644
index 0000000000000000000000000000000000000000..7af0edb72e4e61e638b949db0e6ba68f913a9835
--- /dev/null
+++ b/lib_com/ivas_prot.h
@@ -0,0 +1,5996 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_PROT_H
+#define IVAS_PROT_H
+
+#include
+#include "options.h"
+#include
+#include "typedef.h"
+#include "stat_enc.h"
+#include "stat_dec.h"
+#include "stat_com.h"
+#include "ivas_stat_enc.h"
+#include "ivas_stat_dec.h"
+#include "ivas_stat_com.h"
+#include "ivas_error_utils.h"
+
+/* clang-format off */
+
+/*----------------------------------------------------------------------------------*
+ * General IVAS prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_enc(
+ Encoder_Struct *st_ivas, /* i : IVAS encoder structure */
+ const int16_t *data, /* i : input signal */
+ const int16_t n_samples /* i : number of input samples */
+);
+
+void stereo_dmx_evs_enc(
+ STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS, /* i/o: Stereo downmix for EVS encoder handle */
+ const int32_t input_Fs, /* i : input sampling rate */
+ int16_t data[CPE_CHANNELS * L_FRAME48k], /* i/o: input signal */
+ const int16_t n_samples, /* i : number of input samples */
+ const bool is_binaural /* i : indication that input is binaural audio */
+);
+
+/*! r: number of channels to be analysed */
+int16_t getNumChanAnalysis(
+ Encoder_Struct *st_ivas /* i : IVAS encoder structure */
+);
+
+void copy_encoder_config(
+ Encoder_Struct *st_ivas, /* i : IVAS encoder structure */
+ Encoder_State *st, /* o : encoder state structure */
+ const int16_t flag_all /* i : flag 1==update all, 0=partial update */
+);
+
+void ivas_write_format(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+void ivas_write_format_sid(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int16_t element_mode, /* i : element bitrate */
+ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */
+);
+
+ivas_error create_sce_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const int16_t sce_id, /* i : SCE # identifier */
+ const int32_t element_brate /* i : element bitrate */
+);
+
+ivas_error create_cpe_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const int16_t cpe_id, /* i : CPE # identifier */
+ const int32_t element_brate /* i : element bitrate */
+);
+
+ivas_error create_mct_enc(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+ivas_error mct_enc_reconfigure(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const uint16_t b_nchan_change /* i : flag indicating different channel count */
+);
+
+ivas_error ivas_sba_enc_reconfigure(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+void destroy_sce_enc(
+ SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */
+);
+
+void destroy_cpe_enc(
+ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */
+);
+
+void ivas_mct_enc_close(
+ MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */
+);
+
+ivas_error ivas_corecoder_enc_reconfig(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const int16_t nSCE_old, /* i : number of SCEs in previous frame */
+ const int16_t nCPE_old, /* i : number of CPEs in previous frame */
+ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */
+ const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */
+ const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */
+ const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */
+);
+
+ivas_error ivas_sce_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const int16_t sce_id, /* i : SCE # identifier */
+ const float data_f[], /* i : input signal for single channel */
+ const int16_t input_frame, /* i : input frame length per channel */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+ivas_error ivas_cpe_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const int16_t cpe_id, /* i : CPE # identifier */
+ const float data_f_ch0[], /* i : input signal for channel 0 */
+ const float data_f_ch1[], /* i : input signal for channel 1 */
+ const int16_t input_frame, /* i : input frame length per channel */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+ivas_error ivas_mct_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ float *data[MCT_MAX_CHANNELS], /* i : input signal buffers */
+ const int16_t input_frame, /* i : input frame length per channel */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+ivas_error pre_proc_front_ivas(
+ SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ const int32_t element_brate, /* i : SCE/CPE element bitrate */
+ const int16_t nb_bits_metadata, /* i : number of metadata bits */
+ const int16_t input_frame, /* i : frame length */
+ const int16_t n, /* i : channel number */
+ float old_inp_12k8[], /* o : buffer of old input signal */
+ float old_inp_16k[], /* o : buffer of old input signal @16kHz */
+ float *ener, /* o : residual energy from Levinson-Durbin */
+ float *relE, /* o : frame relative energy */
+ float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */
+ float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */
+ float epsP[M + 1], /* o : LP prediction errors */
+ float lsp_new[M], /* o : LSPs at the end of the frame */
+ float lsp_mid[M], /* o : LSPs in the middle of the frame */
+ int16_t *vad_hover_flag, /* o : VAD hangover flag */
+ int16_t *attack_flag, /* o : flag signaling attack */
+ float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */
+ float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */
+ float old_wsp[], /* o : weighted input signal buffer */
+ float pitch_fr[NB_SUBFR], /* o : fractional pitch values */
+ float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */
+ int16_t *loc_harm, /* o : harmonicity flag */
+ float *cor_map_sum, /* o : speech/music clasif. parameter */
+ int16_t *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */
+ float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */
+ float fft_buff[2 * L_FFT], /* o : FFT buffer */
+ const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */
+ const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */
+ const float currFlatness, /* i : flatness parameter */
+ const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */
+ float fr_bands_LR[CPE_CHANNELS][2 * NB_BANDS], /* i : energy in frequency bands */
+ const float Etot_LR[CPE_CHANNELS], /* i : total energy Left & Right channel */
+ float lf_E_LR[CPE_CHANNELS][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */
+ const int16_t localVAD_HE_SAD_LR[CPE_CHANNELS], /* i : HE-SAD flag without hangover, LR channels */
+ float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */
+ const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */
+ const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */
+ const int16_t force_front_vad, /* i : flag to force VAD decision */
+ const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+ivas_error pre_proc_ivas(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t last_element_mode, /* i : last element mode */
+ const int32_t element_brate, /* i : element bitrate */
+ const int32_t last_element_brate, /* i : last element bitrate */
+ const int16_t input_frame, /* i : frame length */
+ float old_inp_12k8[], /* i/o: buffer of old input signal */
+ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */
+ float **inp, /* o : ptr. to inp. signal in the current frame*/
+ float *ener, /* o : residual energy from Levinson-Durbin */
+ float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */
+ float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */
+ float epsP[M + 1], /* i/o: LP prediction errors */
+ float lsp_new[M], /* i/o: LSPs at the end of the frame */
+ float lsp_mid[M], /* i/o: LSPs in the middle of the frame */
+ float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
+ int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */
+ const float old_wsp[], /* i : weighted input signal buffer */
+ const int16_t loc_harm, /* i : harmonicity flag */
+ const float cor_map_sum, /* i : speech/music clasif. parameter */
+ const int16_t vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */
+ const float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */
+ const float fft_buff[2 * L_FFT], /* i : FFT buffer */
+ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
+ const int16_t vad_hover_flag, /* i : VAD hangover flag */
+ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
+);
+
+ivas_error ivas_compute_core_buffers(
+ Encoder_State *st, /* i/o: encoder state structure */
+ float **inp16k_out, /* o : ptr. to inp. signal in the current frame*/
+ float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */
+ float new_inp_resamp16k[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
+ const int16_t input_frame, /* i : frame length */
+ const int16_t last_element_mode, /* i : last element mode */
+ const int32_t sr_core, /* i : core-coder sampling rate */
+ float *ener, /* o : residual energy from Levinson-Durbin */
+ float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */
+ float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */
+ float epsP[M + 1], /* i/o: LP prediction errors */
+ float lsp_new[M], /* i/o: LSPs at the end of the frame */
+ float lsp_mid[M] /* i/o: LSPs in the middle of the frame */
+);
+
+/*! r: number of clipped samples */
+uint32_t ivas_syn_output(
+ float *synth[], /* i/o: float synthesis signal */
+ const int16_t output_frame, /* i : output frame length (one channel) */
+ const int16_t n_channels, /* i : number of output channels */
+ int16_t *synth_out /* o : integer 16 bits synthesis signal */
+);
+
+void ivas_syn_output_f(
+ float *synth[], /* i/o: float synthesis signal */
+ const int16_t output_frame, /* i : output frame length (one channel) */
+ const int16_t n_channels, /* i : number of output channels */
+ float *synth_out /* o : integer 16 bits synthesis signal */
+);
+
+void ivas_initialize_handles_enc(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+ivas_error ivas_init_encoder(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+void destroy_core_enc(
+ ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */
+);
+
+void ivas_destroy_enc(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+ivas_error ivas_initialize_MD_bstr_enc(
+ BSTR_ENC_HANDLE *hBstr, /* o : encoder MD bitstream handle */
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+void ivas_destroy_MD_bstr_enc(
+ BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */
+);
+
+ivas_error ivas_init_decoder_front(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+ivas_error ivas_init_decoder(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC
+ivas_error ivas_output_buff_dec(
+ float *p_output_f[], /* i/o: output audio buffers */
+ const int16_t nchan_out_buff_old, /* i : previous frame number of output channels*/
+ const int16_t nchan_out_buff /* i : number of output channels */
+);
+#endif
+
+ivas_error stereo_dmx_evs_init_encoder(
+ STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS, /* o : Stereo downmix for EVS encoder handle */
+ const int32_t input_Fs /* i : input sampling rate */
+);
+
+void stereo_dmx_evs_close_encoder(
+ STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */
+);
+
+ivas_error ivas_dec(
+ Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
+ int16_t *data /* o : output synthesis signal */
+);
+
+ivas_error ivas_dec_setup(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */
+ int16_t *data /* o : output synthesis signal */
+);
+
+ivas_error create_sce_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t cpe_id, /* i : SCE # identifier */
+ const int32_t element_brate /* i : element bitrate */
+);
+
+ivas_error create_cpe_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t cpe_id, /* i : CPE # identifier */
+ const int32_t element_brate /* i : element bitrate */
+);
+
+ivas_error create_mct_dec(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
+);
+
+ivas_error mct_dec_reconfigure(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const uint16_t b_nchan_change /* i : flag indicating different channel count */
+);
+
+void destroy_sce_dec(
+ SCE_DEC_HANDLE hSCE /* i/o: SCE decoder structure */
+);
+
+void destroy_cpe_dec(
+ CPE_DEC_HANDLE hCPE /* i/o: CPE decoder structure */
+);
+
+void ivas_mct_dec_close(
+ MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */
+);
+
+ivas_error ivas_corecoder_dec_reconfig(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nSCE_old, /* i : number of SCEs in previous frame */
+ int16_t nCPE_old, /* i : number of CPEs in previous frame */
+ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */
+ const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */
+ const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */
+ const int32_t brate_CPE /* i : bitrate to be set for the CPEs */
+);
+
+ivas_error ivas_hp20_dec_reconfig(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nchan_hp20_old /* i : number of HP20 filters in previous frame*/
+);
+
+ivas_error ivas_sce_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t sce_id, /* i : SCE # identifier */
+ float *output[1], /* o : output synthesis signal */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+ivas_error ivas_cpe_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t cpe_id, /* i : CPE # identifier */
+ float *output[CPE_CHANNELS], /* o : output synthesis signal */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+ivas_error ivas_mct_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ float *output[], /* o : output synthesis signal */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+/*! r: number of channels to be synthesised */
+int16_t getNumChanSynthesis(
+ Decoder_Struct *st_ivas /* i : IVAS decoder structure */
+);
+
+void copy_decoder_config(
+ Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
+ Decoder_State *st /* o : decoder state structure */
+);
+
+void destroy_core_dec(
+ DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */
+);
+
+void ivas_destroy_dec(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_initialize_handles_dec(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+ivas_error ivas_core_enc(
+ SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */
+ const int16_t n_CoreChannels, /* i : number of core channels to be coded */
+#ifdef FIX_854_ARRAY_SIZE_MISMATCH
+ float old_inp_12k8[][L_INP_12k8], /* i : buffer of old input signal */
+ float old_inp_16k[][L_INP], /* i : buffer of old input signal */
+ float ener[], /* i : residual energy from Levinson-Durbin */
+ float A[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */
+ float Aw[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */
+ float epsP[][M + 1], /* i : LP prediction errors */
+ float lsp_new[][M], /* i : LSPs at the end of the frame */
+ float lsp_mid[][M], /* i : LSPs in the middle of the frame */
+ const int16_t vad_hover_flag[], /* i : VAD hanglover flag */
+ int16_t attack_flag[], /* i : attack flag (GSC or TC) */
+ float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */
+ float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */
+ float old_wsp[][L_WSP], /* i : weighted input signal buffer */
+ const int16_t loc_harm[], /* i : harmonicity flag */
+ const float cor_map_sum[], /* i : speech/music clasif. parameter */
+ const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */
+ float enerBuffer[][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */
+ float fft_buff[][2 * L_FFT], /* i : FFT buffer */
+#else
+ float old_inp_12k8[CPE_CHANNELS][L_INP_12k8], /* i : buffer of old input signal */
+ float old_inp_16k[CPE_CHANNELS][L_INP], /* i : buffer of old input signal */
+ float ener[CPE_CHANNELS], /* i : residual energy from Levinson-Durbin */
+ float A[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */
+ float Aw[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */
+ float epsP[CPE_CHANNELS][M + 1], /* i : LP prediction errors */
+ float lsp_new[CPE_CHANNELS][M], /* i : LSPs at the end of the frame */
+ float lsp_mid[CPE_CHANNELS][M], /* i : LSPs in the middle of the frame */
+ const int16_t vad_hover_flag[CPE_CHANNELS], /* i : VAD hanglover flag */
+ int16_t attack_flag[CPE_CHANNELS], /* i : attack flag (GSC or TC) */
+ float realBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */
+ float imagBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */
+ float old_wsp[CPE_CHANNELS][L_WSP], /* i : weighted input signal buffer */
+ const int16_t loc_harm[CPE_CHANNELS], /* i : harmonicity flag */
+ const float cor_map_sum[CPE_CHANNELS], /* i : speech/music clasif. parameter */
+ const int16_t vad_flag_dtx[CPE_CHANNELS], /* i : HE-SAD flag with additional DTX HO */
+ float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */
+ float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */
+#endif
+ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */
+ const int16_t ivas_format, /* i : IVAS format */
+ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
+);
+
+ivas_error ivas_core_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */
+ const int16_t n_channels, /* i : number of channels to be decoded */
+#ifdef FIX_854_ARRAY_SIZE_MISMATCH
+ float *output[], /* o : output synthesis signal */
+ float outputHB[][L_FRAME48k], /* o : output HB synthesis signal */
+#else
+ float *output[CPE_CHANNELS], /* o : output synthesis signal */
+ float outputHB[CPE_CHANNELS][L_FRAME48k], /* o : output HB synthesis signal */
+#endif
+ float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */
+ const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */
+);
+
+void encod_gen_2sbfr(
+ Encoder_State *st, /* i/o: state structure */
+ const float speech[], /* i : input speech */
+ const float Aw[], /* i : weighted A(z) unquantized for subframes */
+ const float Aq[], /* i : LP coefficients */
+ const float *res, /* i : residual signal */
+ float *syn, /* i/o: core synthesis */
+ float *exc, /* i/o: current non-enhanced excitation */
+ float *exc2, /* i/o: current enhanced excitation */
+ float *pitch_buf, /* i/o: floating pitch values for each subframe */
+ float *voice_factors, /* o : voicing factors */
+ float *bwe_exc, /* o : excitation for SWB TBE */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const float tdm_Pri_pitch_buf[] /* i : pitch values for primary channel */
+);
+
+void decod_gen_2sbfr(
+ Decoder_State *st, /* i/o: decoder static memory */
+ const int16_t sharpFlag, /* i : formant sharpening flag */
+ const float *Aq, /* i : LP filter coefficient */
+ float *pitch_buf, /* o : floating pitch values for each subframe */
+ float *voice_factors, /* o : voicing factors */
+ float *exc, /* i/o: adapt. excitation exc */
+ float *exc2, /* i/o: adapt. excitation/total exc */
+ float *bwe_exc, /* o : excitation for SWB TBE */
+ float *gain_buf, /* o : floating pitch gain for each subframe */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const float tdm_Pri_pitch_buf[] /* i : pitch values for primary channel */
+);
+
+void synchro_synthesis(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *output[CPE_CHANNELS], /* i/o: output synthesis signal */
+ const int16_t output_frame, /* i : Number of samples */
+ const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */
+);
+
+void stereo_tcx_init_enc(
+ Encoder_State *st /* i/o: encoder state structure */
+);
+
+void stereo_tcx_core_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */
+ const float new_samples_16k[], /* i : buffer of input signal @16 kHz */
+ const float Aw[], /* i : weighted A(z) unquant. for subframes */
+ float lsp_new[], /* i : LSPs at the end of the frame */
+ float lsp_mid[], /* i : LSPs in the middle of the frame */
+ float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */
+ const int16_t last_element_mode, /* i : last element mode */
+ const int16_t vad_hover_flag /* i : VAD hangover flag */
+);
+
+void stereo_tcx_core_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const FRAME_MODE frameMode, /* i : Decoder frame mode */
+ float *signal_out, /* o : synthesis @internal_Fs */
+ float *signal_outFB, /* o : synthesis @output_Fs */
+ float pitch_buf[], /* o : floating pitch for each subframe */
+ const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */
+ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */
+ const int16_t last_element_mode, /* i : last element mode */
+ const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */
+ const int16_t nchan_out, /* i : number of output channels */
+ const IVAS_FORMAT ivas_format /* i : IVAS format */
+);
+
+void stereo_tcx_init_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
+ const int16_t last_element_mode /* i : element mode of previous frame */
+);
+
+/*! r: S/M decision (0 = speech or noise, 1 = unclear, 2 = music) */
+int16_t ivas_smc_gmm(
+ Encoder_State *st, /* i/o: encoder state structure */
+ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */
+ const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */
+ const float Etot, /* i : total frame energy */
+ const float lsp_new[M], /* i : LSPs in current frame */
+ const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */
+ const float epsP[M + 1], /* i : LP prediciton error */
+ const float PS[], /* i : energy spectrum */
+ const float non_sta, /* i : unbound non-stationarity */
+ const float relE, /* i : relative frame energy */
+ int16_t *high_lpn_flag, /* i/o: sp/mus LPN flag */
+ const int16_t flag_spitch /* i : flag to indicate very short stable pitch */
+);
+
+void ivas_smc_mode_selection(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int32_t element_brate, /* i : element bitrate */
+ int16_t smc_dec, /* i : raw decision of the 1st stage classifier */
+ const float relE, /* i : relative frame energy */
+ const float Etot, /* i : total frame energy */
+ int16_t *attack_flag, /* i/o: attack flag (GSC or TC) */
+ const float *inp, /* i : input signal */
+ const float S_map[], /* i : short-term correlation map */
+ const int16_t flag_spitch /* i : flag to indicate very short stable pitch */
+);
+
+/*! r: S/M decision (0=speech or noise,1=unclear,2=music) */
+int16_t ivas_acelp_tcx20_switching(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float *inp, /* i : new input signal */
+ const float *wsp, /* i : input weighted signal */
+ const float non_staX, /* i : unbound non-stationarity for sp/mu clas */
+ const float *pitch_fr, /* i : fraction pitch values */
+ const float *voicing_fr, /* i : fractional voicing values */
+ const float currFlatness, /* i : flatness */
+ const float lsp_mid[M], /* i : LSPs at the middle of the frame */
+ const float stab_fac, /* i : LP filter stability */
+ float *res_cod_SNR_M,
+ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
+);
+
+void ivas_decision_matrix_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int32_t element_brate, /* i : element bitrate */
+ const float fft_buff[], /* i : FFT buffer */
+ const float enerBuffer[], /* i : energy buffer */
+ const int16_t last_element_mode /* i : last element mode */
+);
+
+void ivas_signaling_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t tdm_SM_flag, /* i : channel combination scheme flag in TD stereo */
+ const int16_t tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo*/
+);
+
+void ivas_decision_matrix_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t *sharpFlag, /* o : formant sharpening flag */
+ int16_t *core_switching_flag, /* o : ACELP->HQ switching frame flag */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t nchan_out /* i : Number of output channels */
+);
+
+void set_bw_stereo(
+ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structures */
+);
+
+/*! r: flag indicating whether the coded BW has changed */
+int16_t set_bw_mct(
+ CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */
+ const int16_t nCPE /* i : number of CPEs */
+);
+
+void acelp_fast(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t cdk_index, /* i : codebook index */
+ const float dn_orig[L_SUBFR], /* i : corr. between target and h[]. */
+ const float cn[L_SUBFR], /* i : residual after long term prediction */
+ const float H[L_SUBFR], /* i : impulse response of weighted synt.filter*/
+ float code[L_SUBFR], /* o : algebraic (fixed) codebook excitation */
+ float y[], /* o : filtered fixed codebook excitation */
+ const int16_t L_subfr /* i : subframe length */
+);
+
+void dec_acelp_fast(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int16_t cdk_index, /* i : codebook index */
+ float code[], /* o : algebraic (fixed) codebook excitation */
+ const int16_t L_subfr /* i : subframe length */
+);
+
+void set_transient_stereo(
+ CPE_ENC_HANDLE hCPE, /* i : CPE structure */
+ float currFlatness[] /* i/o: current flatness */
+);
+
+/*! r: preliminary flag to force ACELP */
+int16_t transient_analysis(
+ TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */
+ const float cor_map_LT[], /* i : LT correlation map */
+ const float multi_harm_limit /* i : multi harminic threshold */
+);
+
+void ivas_post_proc(
+ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ const int16_t n, /* i : channel number */
+ float synth[], /* i/o: output synthesis signal */
+ float *output[CPE_CHANNELS], /* i/o: output synthesis signal */
+ const int16_t output_frame, /* i : output frame length */
+ const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */
+);
+
+void ivas_renderer_select(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+ivas_error ivas_mc_enc_config(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+ivas_error ivas_mc_dec_config(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t idx, /* i : LS config. index */
+ uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */
+ int16_t *data /* o : output synthesis signal */
+);
+
+/*! r: MC format mode (MCT, McMASA, ParamMC) */
+MC_MODE ivas_mc_mode_select(
+ const MC_LS_SETUP mc_ls_setup, /* i : loudspeaker setup (CICP) */
+ const int32_t total_brate /* i : IVAS total bitrate */
+);
+
+/*! r: number of loudspeaker channels */
+int16_t ivas_mc_ls_setup_get_num_channels(
+ const MC_LS_SETUP mc_ls_setup /* i : loudspeaker setup (CICP) */
+);
+
+/*! r: output configuration*/
+AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config(
+ const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup */
+);
+
+/*! r: multi channel loudspeaker setup */
+MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup(
+ const AUDIO_CONFIG output_config /* i : output audio configuration */
+);
+
+void smooth_dft2td_transition(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *output[CPE_CHANNELS], /* i/o: synthesis @external Fs */
+ const int16_t output_frame /* i : output frame length */
+);
+
+
+/*! r: flag indicating a valid bitrate */
+int16_t is_IVAS_bitrate(
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+int16_t is_DTXrate(
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+int16_t is_SIDrate(
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+void ivas_mdft(
+ const float *pIn, /* i : input time-domain signal */
+ float *pOut_re, /* o : Real part of MDFT signal */
+ float *pOut_im, /* o : Imag. part of MDFT signal */
+ const int16_t length, /* i : signal length */
+ const int16_t mdft_length /* i : MDFT length */
+);
+
+void ivas_imdft(
+ const float *pRe, /* i : Real part of MDFT signal */
+ const float *pIm, /* i : Imag. part of MDFT signal */
+ float *pOut, /* o : output time-domain signal */
+ const int16_t length /* i : signal length */
+);
+
+void TonalMdctConceal_create_concealment_noise(
+ float concealment_noise[L_FRAME48k],
+ CPE_DEC_HANDLE hCPE,
+ const int16_t L_frameTCX,
+ const int16_t L_frame,
+ const int16_t idchan,
+ const int16_t subframe_idx,
+ const int16_t core,
+ const float crossfade_gain,
+ const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode
+);
+
+void TonalMdctConceal_whiten_noise_shape(
+ Decoder_State *st,
+ const int16_t L_frame,
+ const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE
+);
+
+/*! r: IGF start line */
+int16_t get_igf_startline(
+ Decoder_State *st, /* i : decoder state */
+ const int16_t L_frame, /* i : length of the frame */
+ const int16_t L_frameTCX /* i : full band frame length */
+);
+
+float rand_triangular_signed(
+ int16_t *seed );
+
+void dtx_read_padding_bits(
+ DEC_CORE_HANDLE st,
+ const int16_t num_bits
+);
+
+void ivas_apply_non_diegetic_panning(
+ float *output_f[], /* i/o: core-coder transport mono channel/stereo output */
+ const float non_diegetic_pan_gain, /* i : non-diegetic panning gain */
+ const int16_t output_frame /* i : output frame length per channel */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * JBM prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_jbm_dec_tc(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *data /* o : output synthesis signals */
+);
+
+ivas_error ivas_jbm_dec_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const uint16_t nSamplesAsked, /* i : number of samples wanted */
+ uint16_t *nSamplesRendered, /* o : number of samples rendered */
+ uint16_t *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */
+ int16_t *data /* o : output synthesis signal */
+);
+
+ivas_error ivas_jbm_dec_flush_renderer(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t 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 */
+ uint16_t *nSamplesRendered, /* o : number of samples flushed */
+ int16_t *data /* o : output synthesis signal */
+);
+
+void ivas_jbm_dec_feed_tc_to_renderer(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */
+ int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/
+ float *data /* i/o: transport channels/output synthesis signal */
+);
+
+ivas_error ivas_jbm_dec_set_discard_samples(
+ Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */
+);
+
+void ivas_jbm_dec_get_adapted_linear_interpolator(
+ const int16_t default_interp_length, /* i : default length of the (full-frame) interpolator */
+ const int16_t interp_length, /* i : length of the interpolator to be created */
+ float *interpolator /* o : the interpolator */
+);
+
+void ivas_jbm_dec_get_adapted_subframes(
+ const int16_t nCldfbTs, /* i : number of time slots in the current frame */
+ int16_t *subframe_nbslots, /* i/o: subframe grid */
+ int16_t *nb_subframes /* i/o: number of subframes in the frame */
+);
+
+void ivas_jbm_dec_get_md_map(
+ const int16_t default_len, /* i : default frame length in metadata slots */
+ const int16_t len, /* i : length of the modfied frames in metadata slots */
+ const int16_t subframe_len, /* i : default length of a subframe */
+ const int16_t offset, /* i : current read offset into the md buffer */
+ const int16_t buf_len, /* i : length of the metadata buffer */
+ int16_t *map /* o : metadata index map */
+);
+
+int16_t ivas_jbm_dec_get_num_tc_channels(
+ Decoder_Struct *st_ivas /* i : IVAS decoder handle */
+);
+
+void ivas_jbm_dec_copy_tc_no_tsm(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ float *tc[], /* i : transport channels */
+ const int16_t output_frame /* i : output frame size */
+);
+
+void ivas_jbm_dec_get_md_map_even_spacing(
+ const int16_t len, /* i : length of the modfied frames in metadata slots */
+ const int16_t subframe_len, /* i : default length of a subframe */
+ const int16_t offset, /* i : current read offset into the md buffer */
+ const int16_t buf_len, /* i : length of the metadata buffer */
+ int16_t *map /* o : metadata index map */
+);
+
+TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode(
+ Decoder_Struct *st_ivas /* i : IVAS decoder handle */
+);
+
+/*! r: render granularity */
+int16_t ivas_jbm_dec_get_render_granularity(
+ const RENDERER_TYPE rendererType, /* i : renderer type */
+ const IVAS_FORMAT ivas_format, /* i : ivas format */
+ const MC_MODE mc_mode, /* i : MC mode */
+ const int32_t output_Fs /* i : sampling rate */
+);
+
+ivas_error ivas_jbm_dec_tc_buffer_open(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */
+ const int16_t nchan_transport_jbm, /* i : number of real transport channels */
+ const int16_t nchan_transport_internal, /* i : number of totally buffered channels */
+ const int16_t nchan_full, /* i : number of channels to fully store */
+ const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */
+);
+
+ivas_error ivas_jbm_dec_tc_buffer_reconfigure(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */
+ const int16_t nchan_transport_jbm, /* i : new number of real transport channels */
+ const int16_t nchan_transport_internal, /* i : new number of totally buffered channels */
+ const int16_t nchan_full, /* i : new number of channels to fully store */
+ const int16_t n_samples_granularity /* i : new granularity of the renderer/buffer */
+);
+
+void ivas_jbm_dec_tc_buffer_close(
+ DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */
+);
+
+void ivas_jbm_dec_td_renderers_adapt_subframes(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+ivas_error ivas_jbm_dec_metadata_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_jbm_masa_sf_to_sf_map(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * ISM prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_ism_config(
+ const int32_t ism_total_brate, /* i : ISM total bitrate */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t nchan_ism, /* i : number of objects */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ const int16_t ism_extended_metadata_flag, /* i : extended metadata flag */
+ const int16_t null_metadata_flag[MAX_NUM_OBJECTS], /* i : NULL MD flag */
+ const int16_t ism_imp[], /* i : ISM importance flags */
+ int32_t element_brate[], /* o : element bitrate per object */
+ int32_t total_brate[], /* o : total bitrate per object */
+ int16_t nb_bits_metadata[], /* i/o: number of metadata bits */
+ const int16_t combined_format_flag /* i : flag indicating combined format */
+);
+
+void bitbudget_to_brate(
+ const int16_t x[], /* i : bitbudgets */
+ int32_t y[], /* o : bitrates */
+ const int16_t N /* i : number of entries to be converted */
+);
+
+void ivas_ism_reset_metadata(
+ ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handles */
+);
+
+void ivas_ism_reset_metadata_API(
+ ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handles */
+);
+
+/*! r: index of the winning codeword */
+int16_t ism_quant_meta(
+ const float val, /* i : scalar value to quantize */
+ float *valQ, /* o : quantized value */
+ const float borders[], /* i : level borders */
+ const float q_step, /* i : quantization step */
+ const float q_step_border, /* i : quantization step at the border */
+ const int16_t cbsize /* i : codebook size */
+);
+
+/*! r: dequantized value */
+float ism_dequant_meta(
+ const int16_t idx, /* i : quantizer index */
+ const float borders[], /* i : level borders */
+ const float q_step, /* i : quantization step */
+ const float q_step_border, /* i : quantization step at the border */
+ const int16_t cbsize /* i : codebook size */
+);
+
+ivas_error ivas_set_ism_metadata(
+ ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */
+ const float azimuth, /* i : azimuth value */
+ const float elevation, /* i : elevation value */
+ const float radius_meta, /* i : radius */
+ const float yaw, /* i : yaw */
+ const float pitch, /* i : pitch */
+ const int16_t non_diegetic_flag /* i : non-diegetic object flag */
+);
+
+ivas_error ivas_ism_metadata_enc_create(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const int16_t n_ISms, /* i : number of objects */
+ int32_t element_brate_tmp[] /* o : element bitrate per object */
+);
+
+ivas_error ivas_ism_metadata_dec_create(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t n_ISms, /* i : number of objects */
+ int32_t element_brate_tmp[] /* o : element bitrate per object */
+);
+
+ivas_error ivas_ism_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ float *data[MAX_NUM_OBJECTS], /* i : input signal */
+ const int16_t input_frame, /* i : input frame length per channel */
+ int16_t *nb_bits_metadata, /* i : number of metadata bits */
+ const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */
+);
+
+ivas_error ivas_ism_metadata_enc(
+ int32_t *ism_total_brate, /* i/o: ISM total bitrate */
+ const int16_t nchan_ism, /* i : number of ISM channels */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ int16_t nb_bits_metadata[], /* o : number of metadata bits */
+ const int16_t localVAD[], /* i : VAD flag */
+ const int16_t ism_mode, /* i : ISM mode */
+ const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */
+ const int16_t ism_extended_metadata_flag, /* i : Extended metadata flag */
+ const float lp_noise_CPE, /* i : LP filtered total noise estimation */
+ const int16_t flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */
+ int16_t *omasa_stereo_sw_cnt,
+ const int16_t ini_frame
+);
+
+ivas_error ivas_ism_metadata_dec(
+ const int32_t ism_total_brate, /* i : ISM total bitrate */
+ const int16_t nchan_ism, /* i : number of ISM channels */
+ int16_t *nchan_transport, /* o : number of transport channels */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder handles */
+ const int16_t bfi, /* i : bfi flag */
+ int16_t nb_bits_metadata[], /* o : number of metadata bits */
+ ISM_MODE ism_mode, /* i : ISM mode */
+ ISM_DTX_DATA_DEC hISMDTX, /* i/o: ISM DTX structure */
+ const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */
+ int16_t *ism_extended_metadata_flag, /* i/o: Extended metadata active in renderer */
+ int16_t *ism_extmeta_cnt, /* i/o: Number of change frames observed */
+ DEC_CORE_HANDLE st0 /* i : core-coder handle */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * Parametric ISM prototypes
+ *----------------------------------------------------------------------------------*/
+
+/*! r: ISM format mode */
+ISM_MODE ivas_ism_mode_select(
+ const int16_t nchan_inp, /* i : number of input objects */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+ivas_error ivas_param_ism_enc_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+void ivas_param_ism_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ float *data[MAX_NUM_OBJECTS], /* i : input signal */
+ const int16_t input_frame /* i : input frame length per channel */
+);
+
+void ivas_param_ism_enc_close(
+ PARAM_ISM_CONFIG_HANDLE *hParamIsm, /* i/o: ParamISM handle */
+ const int32_t input_Fs /* i : input sampling_rate */
+);
+
+void ivas_ism_metadata_close(
+ ISM_METADATA_HANDLE hIsmMetaData[], /* i/o : object metadata handles */
+ const int16_t first_idx /* i : index of first handle to deallocate */
+);
+
+void ivas_param_ism_stereo_dmx(
+ Encoder_Struct *st_ivas, /* i : IVAS encoder structure */
+ float *data[MAX_NUM_OBJECTS], /* i/o: input signal/stereo dmx */
+ const int16_t input_frame /* i : Length of input frame */
+);
+
+void ivas_param_ism_config(
+ PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */
+ const int16_t nchan_ism /* i : number of ISM channels */
+);
+
+ivas_error ivas_ism_enc_config(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+ivas_error ivas_ism_dec_config(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const ISM_MODE last_ism_mode, /* i/o: last ISM mode */
+ uint16_t *nSamplesRendered, /* o : number of samples flushed on renderer change*/
+ int16_t *data /* o : output synthesis signal */
+);
+
+ivas_error ivas_param_ism_dec_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_param_ism_dec_close(
+ PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */
+ const AUDIO_CONFIG output_config /* i : output audio configuration */
+);
+
+void ivas_param_ism_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */
+);
+
+void ivas_ism_dec_digest_tc(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_param_ism_dec_digest_tc(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint16_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */
+ float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output */
+);
+
+void ivas_ism_param_dec_tc_gain_ajust(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint16_t nSamples, /* i : number of samples to be compensate */
+ const uint16_t nFadeLength, /* i : length of the crossfade in samples */
+ float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output */
+);
+
+void ivas_param_ism_dec_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
+ uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
+ uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
+ float *output_f[] /* o : rendered time signal */
+);
+
+void ivas_param_ism_params_to_masa_param_mapping(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * ISM DTX prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_ism_dtx_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+/*! r: indication of DTX frame */
+int16_t ivas_ism_dtx_enc(
+ ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */
+ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t nchan_ism, /* i : number of objects */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ int16_t vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ int16_t md_diff_flag[], /* o : metadata differential flag */
+ int16_t *sid_flag /* o : indication of SID frame */
+);
+
+ivas_error ivas_ism_dtx_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ int16_t *nb_bits_metadata /* o : number of metadata bits */
+);
+
+void ivas_ism_metadata_sid_enc(
+ ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */
+ const int16_t flag_noisy_speech, /* i : noisy speech flag */
+ const int16_t nchan_ism, /* i : number of objects */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ const int16_t sid_flag, /* i : indication of SID frame */
+ const int16_t md_diff_flag[], /* i : metadata differental flag */
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ int16_t nb_bits_metadata[] /* o : number of metadata bits */
+);
+
+void ivas_ism_metadata_sid_dec(
+ SCE_DEC_HANDLE hSCE[MAX_SCE], /* i/o: SCE decoder structure */
+ const int32_t ism_total_brate, /* i : ISM total bitrate */
+ const int16_t bfi, /* i : bfi flag */
+ const int16_t nchan_ism, /* i : number of objects */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ int16_t *flag_noisy_speech, /* o : noisy speech flag */
+ int16_t *sce_id_dtx, /* o : SCE DTX ID */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ int16_t nb_bits_metadata[] /* o : number of metadata bits */
+);
+
+void ivas_ism_get_sce_id_dtx(
+ ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */
+ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t input_frame /* i : input frame length per channel */
+);
+
+void ivas_param_ism_compute_noisy_speech_flag(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+void ivas_ism_coh_estim_dtx_enc(
+ ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */
+ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t input_frame /* i : input frame length */
+);
+
+void update_last_metadata(
+ const int16_t nchan_ism, /* i : number of objects */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ const int16_t updt_flag[] /* i : last metadata update flag */
+);
+
+void ivas_get_ism_sid_quan_bitbudget(
+ const int16_t nchan_ism, /* i : number of objects */
+ int16_t *nBits_azimuth, /* o : number of Q bits for azimuth */
+ int16_t *nBits_elevation, /* o : number of Q bits for elevation */
+ float *q_step, /* o : quantization step */
+ float *q_step_border, /* o : quantization step at the border */
+ int16_t *nBits_coh, /* o : number of Q bits for coherence */
+ int16_t *nBits_sce_id /* o : number of Q bits for sce_id_dtx */
+);
+
+void ivas_ism_dtx_limit_noise_energy_for_near_silence(
+ SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */
+ const int16_t sce_id_dtx, /* i : SCE DTX ID */
+ const int16_t nchan_transport /* i : number of transport channels */
+);
+
+/*----------------------------------------------------------------------------------*
+ * DFT Stereo prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error stereo_dft_enc_create(
+ STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* o : encoder DFT stereo handle */
+ const int32_t input_Fs, /* i : input sampling rate */
+ const int16_t max_bwidth /* i : maximum encoded bandwidth */
+);
+
+void stereo_dft_enc_reset(
+ STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */
+);
+
+void stereo_enc_itd_init(
+ ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */
+);
+
+void stereo_dft_enc_update(
+ STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */
+ const int16_t max_bwidth /* i : maximum encoded bandwidth */
+);
+
+void stereo_dft_enc_destroy(
+ STEREO_DFT_ENC_DATA_HANDLE *hStereoDft /* i/o: encoder DFT stereo handle */
+);
+
+void stereo_dft_enc_analyze(
+ Encoder_State **sts, /* i/o: encoder state structure */
+ const int16_t n_channels, /* i : number of input channels */
+ const int16_t input_frame, /* i : input frame length */
+ STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */
+ STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: encoder MDCT stereo handle */
+ float DFT[CPE_CHANNELS][STEREO_DFT_N_MAX_ENC], /* o : DFT buffers */
+ float *input_mem[CPE_CHANNELS] /* i/o: input buffer memory */
+);
+
+float stereo_dft_enc_synthesize(
+ STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */
+ float *output, /* o : output synthesis */
+ const int16_t chan, /* i : channel number */
+ const int32_t input_Fs, /* i : input sampling rate */
+ const int32_t output_sampling_rate, /* i : output sampling rate */
+ const int16_t L_frame /* i : frame length at internal Fs */
+);
+
+void stereo_dft_enc_process(
+ CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */
+ const int16_t vad_flag_dtx[], /* i : VAD dtx flags */
+ const int16_t vad_hover_flag[], /* i : VAD hangover flags */
+ const int16_t input_frame /* i : input frame length */
+);
+
+void stereo_dft_enc_res(
+ STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */
+ const float *input_8k, /* i : input buffer sampled at 8kHz */
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ int16_t *nb_bits, /* o : number of bits written */
+ const int16_t max_bits
+);
+
+void stereo_dft_enc_write_BS(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ int16_t *nb_bits /* o : number of bits written */
+);
+
+void stereo_dtf_cng(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */
+ const int16_t output_frame /* i : output frame size */
+);
+
+void stereo_dft_cng_side_gain(
+ STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo encoder handle */
+ STEREO_CNG_ENC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */
+ const int32_t core_brate, /* i : core bitrate */
+ const int32_t last_core_brate, /* i : last core bitrate */
+ const int16_t bwidth /* i : audio band-width */
+);
+
+void stereo_dft_quantize_res_gains(
+ const float *g,
+ const float *r,
+ float *gq,
+ float *rq,
+ int16_t *ig,
+ int16_t *ir
+);
+
+void stereo_dft_dequantize_itd(
+ int16_t *ind,
+ float *out,
+ const int32_t output_Fs
+);
+
+void stereo_dft_enc_sid_calc_coh(
+ STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo handle */
+ float prev_cohBand[2*(STEREO_DFT_BAND_MAX/2)], /* i/o: Previous coherence */
+ int16_t *td_active, /* i/o: TD stereo mode indicator */
+ int16_t *first_SID, /* i/o: First SID indicator */
+ float *cohBand /* i/o: Coherence per band */
+);
+
+void stereo_dft_enc_sid_coh(
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ float *mem_cohBand, /* i/o: Coherence memory */
+ const int16_t nbands, /* i : number of DFT stereo bands */
+ int16_t *nb_bits, /* i/o: number of bits written */
+ float *cohBand /* i/o: Coherence per band */
+);
+
+void stereo_dft_dec_sid_coh(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int16_t nbands, /* i : number of DFT stereo bands */
+ float *coh, /* i/o: coherence */
+ int16_t *nb_bits /* i/o: number of bits read */
+);
+
+ivas_error stereo_dft_dec_create(
+ STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */
+ const int32_t element_brate, /* i : element bitrate */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */
+ const int16_t nchan_transport /* i : number of transport channels */
+);
+
+void stereo_dft_dec_reset(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: decoder DFT stereo handle */
+);
+
+void stereo_dft_dec_update(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */
+ const int16_t output_frame, /* i : output frame length */
+ const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */
+);
+
+void stereo_dft_dec_destroy(
+ STEREO_DFT_DEC_DATA_HANDLE *hStereoDft /* i/o: decoder DFT stereo handle */
+);
+
+void stereo_dft_dec_analyze(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ const float *input, /* i : input signal */
+ float out_DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */
+ const int16_t chan, /* i : channel number */
+ const int16_t input_frame, /* i : input frame size */
+ const int16_t output_frame, /* i : output frame size */
+ const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : signal type to analyze */
+ const int16_t k_offset, /* i : offset of DFT */
+ const int16_t delay /* i : delay in samples for input signal */
+);
+
+void stereo_dft_dec_synthesize(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers */
+ const int16_t chan, /* i : channel number */
+ float output[L_FRAME48k], /* o : output synthesis signal */
+ const int16_t output_frame /* i : output frame length */
+);
+
+void stereo_dft_dec(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */
+ Decoder_State *st0, /* i/o: decoder state structure */
+ float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */
+ float *input_mem, /* i/o: mem of buffer DFT analysis */
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */
+ const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */
+ const int16_t sba_mono_flag, /* i : signal mono output for SBA DirAC */
+ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD handle for upmixing */
+ const int16_t cross_fade_start_offset, /* i : SPAR mixer delay compensation */
+ const int32_t output_Fs, /* i : Fs for delay calculation */
+ const int16_t nchan_transport, /* i : number of transpor channels */
+ const int16_t num_md_sub_frames /* i : number of MD subframes */
+);
+
+void stereo_dft_res_ecu(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */
+ float *pDFT_RES, /* i/o: residual signal */
+ float *const DFT_PRED_RES, /* i/o: residual prediction signal */
+ const int16_t k, /* i : Subframe index */
+ const int16_t output_frame, /* i : Output frame length */
+ const int16_t prev_bfi, /* i : Previous BFI */
+ const float dmx_nrg, /* i : Down-mix energy */
+ int16_t *num_plocs, /* i/o: Number of peak locations */
+ int16_t *plocs, /* i/o: Peak locations (bin) */
+ float *plocsi, /* i/o: Peak locations (fractional) */
+ float *input_mem /* o : Residual DFT buffer input mem */
+);
+
+void stereo_dft_res_subst_spec(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */
+ float *pDFT_RES, /* i/o: residual signal */
+ const float *const DFT_PRED_RES, /* i : residual prediction signal */
+ const int16_t time_offs, /* i : Time offset for phase adjustm. */
+ const int16_t L_res, /* i : bandwidth of residual signal */
+ const int16_t L_ana, /* i : Length of FFT analysis */
+ const int16_t k, /* i : Subframe index */
+ int16_t *num_plocs, /* i/o: Number of peak locations */
+ int16_t *plocs, /* i/o: Peak locations (bin) */
+ float *plocsi, /* i/o: Peak locations (fractional) */
+ const int16_t analysis_flag /* i : Flag for running peak analysis */
+);
+
+void stereo_dft_res_ecu_burst_att(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */
+ float *pDFT_RES, /* i/o: residual signal /att. residual */
+ const float dmx_nrg, /* i : dmx energy of current frame */
+ const int16_t L_res, /* i : Bandwidth of residual */
+ const int16_t L_ana /* i : Length of FFT analysis */
+);
+
+/*! r: total energy of downmix with maximum swb bandwidth max */
+float stereo_dft_dmx_swb_nrg(
+ const float *dmx_k0, /* i : first subframe spectrum */
+ const float *dmx_k1, /* i : second subframe spectrum */
+ const int16_t frame_length /* i : frame lanegth */
+);
+
+int16_t stereo_dft_sg_recovery(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */
+);
+
+void stereo_dft_dec_res(
+ CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */
+ float res_buf[STEREO_DFT_BUF_MAX], /* i : residual buffer */
+ float *output /* o : output frame */
+);
+
+/*! r: Decision to enable or disable BPF on DFT stereo residual */
+int16_t res_bpf_adapt(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */
+ const float *bpf_error_signal_8k, /* i : BPF modification signal */
+ float res_buf[STEREO_DFT_BUF_MAX] /* i : residual buffer */
+);
+
+void bpf_pitch_coherence(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const float pitch_buf[] /* i : pitch for each subframe [0,1,2,3] */
+);
+
+void stereo_dft_dec_read_BS(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int32_t element_brate, /* i : element bitrate */
+ int32_t *total_brate, /* o : total bitrate */
+ Decoder_State *st, /* i/o: decoder state structure */
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */
+ const int16_t bwidth, /* i : bandwidth */
+ const int16_t output_frame, /* i : output frame length */
+ float res_buf[STEREO_DFT_BUF_MAX], /* o : residual buffer */
+ int16_t *nb_bits, /* o : number of bits read */
+ float *coh, /* i/o: Coherence */
+ const int16_t ivas_format /* i : ivas format */
+);
+
+void stereo_dft_dec_smooth_parameters(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */
+ const int16_t prev_sid_nodata, /* i : Previous SID/No data indicator */
+ const int16_t active_frame_counter, /* i : Active frame counter */
+ const int32_t element_brate /* i : Element bitrate */
+);
+
+void stereo_dft_generate_res_pred(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */
+ const float samp_ratio, /* i : sampling ratio */
+ float *pDFT_DMX, /* i : downmix signal */
+ float *DFT_PRED_RES, /* o : residual prediction signal */
+ float *pPredGain, /* i : residual prediction gains */
+ const int16_t k, /* i : subframe index */
+ float *ap_filt_DMX, /* i : enhanced stereo filling signal */
+ int16_t *stop, /* o : last FD stereo filling bin */
+ const int16_t bfi /* i : BFI flag */
+);
+
+void stereo_dft_dec_core_switching(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float output[], /* i/o: synthesis @internal Fs */
+ float synth[], /* i : synthesis @output Fs */
+ float hb_synth[], /* i/o: hb synthesis */
+ float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */
+ const int16_t output_frame, /* i : output frame length */
+ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
+ const int16_t sba_dirac_stereo_dtx_flag /* i : DTX indicator for SBA DirAC stereo */
+);
+
+void init_basic_allpass(
+ basic_allpass_t *ap, /* i/o: basic allpass structure */
+ const float *gains, /* i : allpass filter gains */
+ const int16_t *delays /* i : allpass filter delays */
+);
+
+void filter_with_allpass(
+ const float *sig, /* i : allpass input signal */
+ float *out, /* o : filtered output */
+ const int16_t len, /* i : length of input */
+ basic_allpass_t *ap /* i/o: basic allpass structure */
+);
+
+/*! r: used GR order */
+int16_t write_bitstream_adapt_GR(
+ BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */
+ const int16_t Indice, /* i : identifier for bitstream index */
+ const int16_t *in, /* i : values to be written in bitstream */
+ const int16_t len, /* i : values vector length */
+ const int16_t GR_ord, /* i : GR order to be used */
+ const int16_t sp_aud_decision /* i : speech/music 0/1 */
+);
+
+/*! r: used GR order */
+int16_t adapt_GR_ief(
+ const int16_t *in, /* i : vector to encode */
+ int16_t *in_diff, /* o : encoded symbols in case of differential encoding */
+ const int16_t *prev, /* i : previous frame data */
+ const int16_t len, /* i : input vector length */
+ const int16_t no_symb, /* i : number of symbols */
+ int16_t *nbits, /* o : number of used bits */
+ int16_t *in_enc, /* o : symbold actually encoded after adapt_GR */
+ const int16_t *map0, /* i : mapping array */
+ const int16_t no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */
+ int16_t *nbits_diff, /* o : number bits in diff encoding */
+ const int16_t side_gain_counter, /* i : number of frames since last abs coding */
+ float *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */
+ const int16_t try_diff /* i : diff coding allowed 1/0 */
+);
+
+/*! r: used GR order */
+int16_t adapt_GR_rpg1_ief(
+ const int16_t *in, /* i : res pred gains input vector */
+ int16_t *in_diff, /* o : encoded symbols in case of differential encoding */
+ const int16_t *prev, /* i : previous frame data */
+ const int16_t len, /* i : input vector length */
+ const int16_t no_symb, /* i : number of symbols */
+ int16_t *nbits, /* o : number of used bits */
+ int16_t *in_enc, /* o : symbold actually encoded after adapt_GR */
+ const int16_t *maps, /* i : mapping array */
+ int16_t *nbits_diff, /* o : estimated no of bits for differential encoding */
+ const int16_t no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */
+ const int16_t try_diff /* i : diff coding allowed 1/0 */
+);
+
+/*! r: number of bits written */
+int16_t write_GR1(
+ BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */
+ const int16_t ind, /* i : bitstream index */
+ const int16_t *in, /* i : input vector */
+ const int16_t len /* i : vector length */
+);
+
+/*! r: number of bits written */
+int16_t write_bitstream_GR(
+ BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */
+ const int16_t ind, /* i : bitstream index */
+ const int16_t *in, /* i : input date to be written */
+ const int16_t len, /* i : input data length */
+ const int16_t GR_ord /* i : GR order to be used */
+);
+
+/*! r: number of bits read */
+int16_t read_flag_EC_DFT(
+ const uint16_t *bit_stream, /* i : bitstream */
+ int16_t *flag /* o : flag value */
+);
+
+/*! r: number of bits read */
+int16_t read_BS_GR(
+ const uint16_t *bit_stream, /* i : bitstream to be read */
+ const int16_t nb, /* i : starting point in bitstream */
+ int16_t *ind1, /* o : data array read */
+ const int16_t len, /* i : number of params to be read */
+ int16_t *GR_ord /* o : GR order to be used */
+);
+
+/*! r: number of bits read */
+int16_t read_BS_adapt_GR_rpg(
+ const uint16_t *bit_stream, /* i : bitstream to be read */
+ const int16_t nb, /* i : starting point in bitstream */
+ int16_t *ind1_pred, /* o : decoded res pred gains */
+ const int16_t start, /* i : starting subband */
+ const int16_t total_no, /* i : number of params to be read */
+ int16_t *GR_ord /* o : GR order - read */
+);
+
+/*! r: value read on nbits from bitstream */
+int16_t get_value(
+ const uint16_t *bit_stream, /* i : bitstream */
+ const int16_t nbits /* i : number of bits to be read */
+);
+
+/*! r: number of bits read */
+int16_t read_itd(
+ Decoder_State *st, /* i : decoder state */
+ int16_t *pI /* o : decoded ITD value */
+);
+
+/*! r: number of bits read */
+int16_t read_BS_adapt_GR_sg(
+ const uint16_t *bit_stream, /* i : bitstream to be read */
+ const int16_t nb, /* i : starting position to be read */
+ int16_t *ind1, /* o : decoded side gain values */
+ const int16_t len, /* i : number of params to be read */
+ int16_t *GR_ord, /* o : GR order to be used */
+ const int16_t *map0 /* i : mapping array for side gains */
+);
+
+void stereo_dft_hybrid_ITD_flag(
+ STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */
+ const int32_t input_Fs, /* i : CPE element sampling rate */
+ const int16_t hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */
+);
+
+void stereo_dft_enc_compute_itd(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ float *DFT_L,
+ float *DFT_R,
+ const int16_t k_offset,
+ const int16_t input_frame,
+ const int16_t vad_flag_dtx[],
+ const int16_t vad_hover_flag[],
+ float *bin_nrgL,
+ float *bin_nrgR
+);
+
+void stereo_dft_config(
+ STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */
+ const int32_t brate, /* i : IVAS/CPE/nominal total bitrate */
+ int16_t *bits_frame_nominal, /* o : primary channel nominal bits per frame */
+ int16_t *bits_frame_nominal_2 /* o : secondary channel nominal bits per frame*/
+);
+
+int16_t stereo_dft_band_config(
+ int16_t *band_limits, /* o : DFT band limits */
+ const int16_t band_res, /* i : DFT band resolution */
+ const int16_t NFFT, /* i : analysis/synthesis window length */
+ const int16_t enc_dec /* i : flag to indicate enc vs dec */
+);
+
+void stereo_td_itd(
+ ITD_DATA *hITD, /* i/o: ITD data structure */
+ float input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */
+ const int16_t hybrid_itd_flag, /* i : flag for hybrid TD/FD ITD processing */
+ const int16_t dft_ovl, /* i : size of DFT overlap */
+ Encoder_State **sts, /* i/o: Encoder state structure */
+ const int16_t input_frame, /* i : input frame length */
+ float *input_mem[CPE_CHANNELS] /* i/o: input buffer memory */
+);
+
+void stereo_dft_dmx_out_reset(
+ STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */
+);
+
+void stereo_dft_unify_dmx(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */
+ Decoder_State *st0, /* i/o: decoder state structure */
+ float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */
+ float *input_mem, /* i/o: mem of buffer DFT analysis */
+ const int16_t prev_sid_nodata /* i : Previous SID/No data indicator */
+);
+
+void add_HB_to_mono_dmx(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float output[L_FRAME48k], /* i/o: output synthesis */
+ float outputHB[L_FRAME48k], /* i : HB synthesis */
+ const int16_t last_core, /* i : last core, primary channel */
+ const int16_t output_frame /* i : frame length */
+);
+
+/*----------------------------------------------------------------------------------*
+ * Range Coder prototypes
+ *----------------------------------------------------------------------------------*/
+
+void rc_uni_enc_init(
+ RangeUniEncState *rc_st_enc /* i/o: RC state handle */
+);
+
+void rc_uni_enc_encode_fast(
+ RangeUniEncState *rc_st_enc, /* i/o: RC state handle */
+ const uint16_t cum_freq, /* i : Cumulative frequency up to symbol */
+ const uint16_t sym_freq, /* i : Symbol frequency */
+ const uint16_t tot_shift /* i : Total frequency as a power of 2 */
+);
+
+void rc_uni_enc_encode_symbol_fastS(
+ RangeUniEncState *rc_st_enc, /* i/o: Encoder state */
+ const uint16_t symbol, /* i : Symbol to encode */
+ const uint16_t cum_freq[], /* i : Cumulative frequency up to symbol */
+ const uint16_t sym_freq[], /* i : Symbol frequency */
+ const uint16_t tot_shift /* i : Total frequency as a power of 2 */
+);
+
+void rc_uni_enc_encode_bits(
+ RangeUniEncState *rc_st_enc, /* i/o: RC state handle */
+ const uint16_t value, /* i : Value to encode */
+ const int16_t bits /* i : Number of bits */
+);
+
+/*! r: Total number of bits produced */
+int16_t rc_uni_enc_virtual_finish(
+ RangeUniEncState *rc_st_enc /* i : RC state handle */
+);
+
+/*! r: Total number of bits produced */
+int16_t rc_uni_enc_finish(
+ RangeUniEncState *rc_st_enc /* i/o: RC state handle */
+);
+
+void rc_uni_dec_init(
+ RangeUniDecState *rc_st_dec, /* i/o: RC state handle */
+ uint16_t *bit_buffer, /* i : Bit buffer */
+ const int16_t max_available_bits /* i : Total maximum bits available */
+);
+
+/*! r: Read symbol */
+uint16_t rc_uni_dec_read_symbol_fastS(
+ RangeUniDecState *rc_st_dec, /* i/o: Decoder State */
+ const uint16_t cum_freq_table[], /* i : Cumulative frequency up to symbol */
+ const uint16_t sym_freq_table[], /* i : Symbol frequency */
+ const uint16_t alphabet_size, /* i : Number of symbols in the alphabet */
+ const uint16_t tot_shift /* i : Total frequency as a power of 2 */
+);
+
+/*! r: Read bit */
+uint16_t rc_uni_dec_read_bit(
+ RangeUniDecState *rc_st_dec /* i/o: RC state handle */
+);
+
+/*! r: Read bit */
+uint16_t rc_uni_dec_read_bit_prob_fast(
+ RangeUniDecState *rc_st_dec, /* i/o: RC state handle */
+ const int16_t freq0, /* i : Frequency for symbol 0 */
+ const uint16_t tot_shift /* i : Total frequency as a power of 2 */
+);
+
+/*! r: Read bits */
+uint16_t rc_uni_dec_read_bits(
+ RangeUniDecState *rc_st_dec, /* i/o: RC state handle */
+ const int16_t bits /* i : Number of bits */
+);
+
+/*! r: Total number of bits consumed */
+int16_t rc_uni_dec_virtual_finish(
+ RangeUniDecState *rc_st_dec /* i/o: RC state handle */
+);
+
+/*! r: Total number of bits consumed */
+int16_t rc_uni_dec_finish(
+ RangeUniDecState *rc_st_dec /* i/o: RC state handle */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * ECLVQ Stereo prototypes
+ *----------------------------------------------------------------------------------*/
+
+float ECSQ_dequantize_gain(
+ const int16_t index
+);
+
+void ECSQ_quantize_vector(
+ const float *input,
+ const float global_gain,
+ const int16_t N,
+ int16_t *output
+);
+
+float ECSQ_compute_optimal_gain(
+ const float *input,
+ const int16_t N,
+ const int16_t *output
+);
+
+void ECSQ_init_instance(
+ ECSQ_instance *ecsq_inst,
+ const int16_t config_index,
+ void *ac_handle
+);
+
+int32_t ECSQ_encode_target_SNR(
+ ECSQ_instance *ecsq_inst,
+ const float *input,
+ const int16_t N,
+ const float target_SNR,
+ const int16_t max_bits,
+ float *output,
+ int16_t *global_gain_index_output
+);
+
+void ECSQ_decode(
+ ECSQ_instance *ecsq_inst,
+ const int16_t N,
+ int16_t *output
+);
+
+void ECSQ_dequantize_vector(
+ const int16_t *input,
+ const float global_gain,
+ const int16_t N,
+ float *output
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * ICA Stereo prototypes
+ *----------------------------------------------------------------------------------*/
+
+void stereo_tca_init_enc(
+ STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo TCA encoder handle */
+ const int32_t input_Fs /* i : input sampling frequency */
+);
+
+void stereo_tca_enc(
+ CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */
+ const int16_t input_frame /* i : length of a frame per channel */
+);
+
+void stereo_tca_init_dec(
+ STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle */
+);
+
+void stereo_tca_dec(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *synth[CPE_CHANNELS], /* i/o: output synth */
+ const int16_t output_frame /* i : length of a frame per channel */
+);
+
+void stereo_tca_scale_R_channel(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *output, /* i/o: output synthesis, R channel */
+ const int16_t output_frame /* i : frame length */
+);
+
+void adjustTargetSignal(
+ float *target,
+ const int16_t prevShift,
+ const int16_t currShift,
+ const int16_t L_shift_adapt,
+ const int16_t method
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * IC-BWE Stereo prototypes
+ *----------------------------------------------------------------------------------*/
+
+void stereo_icBWE_init_enc(
+ STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */
+);
+
+void spectral_balancer(
+ float *signal,
+ float *mem,
+ const int16_t lg,
+ const int16_t coeff_set
+);
+
+void stereo_icBWE_preproc(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ const int16_t input_frame, /* i : input frame length */
+ float shb_speech_nonref[] /* o : SHB speech non-ref channel */
+);
+
+void stereo_icBWE_enc(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ const float shb_speech_ref[], /* i : SHB speech ref channel */
+ float shb_speech_nonref[], /* i/o: SHB speech non-ref channel */
+ const float *voice_factors /* i : voicing factors */
+);
+
+void stereo_icBWE_init_dec(
+ STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */
+);
+
+void stereo_icBWE_dec(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *synthRef, /* i/o: Reference channel HB synthesis at output Fs */
+ float *synth, /* o : Non reference channel HB synthesis at output Fs */
+ const float *fb_synth_ref, /* i : ref. high-band synthesis 16-20 kHz */
+ const float *voice_factors, /* i : voicing factors */
+ const int16_t output_frame /* i : frame length */
+);
+
+void stereo_icBWE_decproc(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *output[CPE_CHANNELS], /* i/o: output symthesis */
+ float outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */
+ const int16_t last_core, /* i : last core, primary channel */
+ const int16_t last_bwidth, /* i : last bandwidth */
+ const int16_t output_frame /* i : frame length */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * Stereo classifiers prototypes
+ *----------------------------------------------------------------------------------*/
+
+/*! r: element mode */
+int16_t select_stereo_mode(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate /* i : IVAS total brate */
+);
+
+void stereo_classifier_init(
+ STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */
+);
+
+void stereo_classifier_features(
+ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */
+ const int16_t idchan, /* i : channel ID */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t vad_flag, /* i : VAD flag */
+ const float lsf_new[], /* i : LSFs at the end of the frame */
+ const float epsP[], /* i : LP analysis residual energies for each iteration*/
+ const int16_t pitch[], /* i : open-loop pitch values for quantiz. */
+ const float voicing[], /* i : OL maximum normalized correlation */
+ const float cor_map_sum, /* i : speech/music clasif. parameter */
+ const float non_staX, /* i : unbound non-stationarity for sp/mu clas. */
+ const float sp_div, /* i : spectral diversity feature */
+ const int16_t clas /* i : signal class */
+);
+
+void unclr_classifier_dft(
+ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */
+);
+
+void unclr_classifier_td(
+ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */
+);
+
+void xtalk_classifier_dft(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ const int16_t itd, /* i : ITD from DFT stereo - used as a feature */
+ const float gcc_phat[] /* i : GPHAT cross-channel correlation function */
+);
+
+void xtalk_classifier_td(
+ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * TD Stereo prototypes
+ *----------------------------------------------------------------------------------*/
+
+void stereo_td_init_enc(
+ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
+ const int16_t last_element_mode /* i : last element mode */
+);
+
+ivas_error stereo_set_tdm(
+ CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */
+ const int16_t input_frame /* i : input frame length per channel */
+);
+
+void stereo_tdm_prep_dwnmx (
+ CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */
+ const float *input1, /* i : right channel input */
+ const int16_t input_frame /* i : frame lenght */
+);
+
+int16_t stereo_tdm_ener_analysis(
+ const int16_t ivas_format, /* i : IVAS format */
+ CPE_ENC_HANDLE hCPE, /* i : CPE structure */
+ const int16_t input_frame, /* i : Number of samples */
+ int16_t *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */
+ int16_t *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */
+);
+
+void stereo_tdm_downmix(
+ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i : TD stereo IVAS encoder structure */
+ float *Left_in, /* i/o: Left channel -> Primary channel */
+ float *Right_in, /* i/o: Right channel -> Secondary channel */
+ const int16_t input_frame, /* i : Number of samples */
+ const int16_t tdm_ratio_idx, /* i : TDM ratio index */
+ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */
+ const int16_t tdm_ratio_idx_SM /* i : TDM ratio index for SM mode */
+);
+
+void stereo_td_init_dec(
+ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */
+ const int16_t last_element_mode /* i : last element mode */
+);
+
+void tdm_configure_dec(
+ const int16_t ivas_format, /* i : IVAS format */
+ const int16_t ism_mode, /* i : ISM mode in combined format */
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ int16_t *tdm_ratio_idx, /* o : ratio index */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+void tdm_upmix_plain(
+ float Left[], /* o : left channel */
+ float Right[], /* o : right channel */
+ const float PCh_2_L[], /* i : primary channel */
+ const float SCh_2_R[], /* i : secondary channel */
+ const float LR_ratio, /* i : mixing ratio */
+ const float inv_den_LR_ratio, /* i : inverse mixing ration */
+ const int16_t start_index, /* i : start index */
+ const int16_t end_index, /* i : end index */
+ const int16_t plus_minus_flag /* i : plus/minus flag */
+);
+
+void stereo_tdm_combine(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *PCh_2_L, /* i/o: Primary channel -> output as L channel */
+ float *SCh_2_R, /* i/o: Seconday channel -> output as R channel */
+ const int16_t output_frame, /* i : Number of samples */
+ const int16_t flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */
+ const int16_t tdm_ratio_idx /* i : TDM ratio index */
+);
+
+/*! r: replication decision; 1 = Use old LP */
+int16_t tdm_lp_comparison(
+ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
+ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */
+ Encoder_State *st, /* i/o: Encoder structure */
+ const float *speech, /* i : Current speech frame */
+ const float *A_Pch, /* i : primary channel LP coefficients */
+ const float *A_SCh, /* i : secondary channel LP coefficients */
+ const int16_t m, /* i : filter length */
+ const float *isp_PCh, /* i : primary channel LSPs */
+ const float *isp_SCh, /* i : secondary channel LSPs */
+ const int16_t L_frame, /* i : frame length */
+ const int32_t element_brate_wo_meta /* i : element bitrate without metadata */
+);
+
+/*! r: replication decision; 1 = Use old LP */
+void tdm_ol_pitch_comparison(
+ CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */
+ float pitch_fr[CPE_CHANNELS][NB_SUBFR], /* i/o: fractional pitch values */
+ float voicing_fr[CPE_CHANNELS][NB_SUBFR] /* i/o: fractional pitch gains */
+);
+
+void tdm_configure_enc(
+ const int16_t ivas_format, /* i : IVAS format */
+ const int16_t ism_mode, /* i : ISM mode in combined format */
+ CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */
+ const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */
+ const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */
+ const int16_t tdm_ratio_idx, /* i : ratio index */
+ const int16_t tdm_ratio_idx_SM, /* i : ratio index in SM mode */
+ const int16_t attack_flag, /* i : Primary channel attack flag */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+ivas_error signaling_enc_secondary(
+ Encoder_State *st, /* i/o: Encoder structure */
+ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */
+ const int16_t tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag */
+);
+
+void tdm_bit_alloc(
+ const int16_t ivas_format, /* i : IVAS format */
+ const int16_t ism_mode, /* i : ISM mode in combined format */
+ const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */
+ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */
+ int32_t *total_brate_pri, /* o : Allocated primary channel bitrate */
+ int32_t *total_brate_sec, /* o : Allocated secondary channel bitrate */
+ int16_t *tdm_low_rate_mode, /* o : secondary channel low rate mode flag */
+ const int16_t coder_type, /* i : secondary channel coder type */
+ const int16_t ener_ratio_idx, /* i : correlation ratio indexe */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const int16_t bwidth_pri, /* i : bandwidth of the primary channel */
+ const int16_t bwidth_sec, /* i : bandwidth of the secondary channel */
+ const int16_t flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan. */
+ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */
+ const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */
+ const int16_t tdm_inst_ratio_idx /* i : instantaneous correlation ratio index */
+);
+
+void td_stereo_param_updt(
+ const float lsp_old_PCh[], /* i : primary channel old LSPs */
+ const float lsf_old_PCh[], /* i : primary channel old LSFs */
+ const float pitch_buf_PCh[], /* i : primary channel pitch buffer */
+ float tdm_lspQ_PCh[], /* o : Q LSPs for primary channel */
+ float tdm_lsfQ_PCh[], /* o : Q LSFs for primary channel */
+ float tdm_Pri_pitch_buf[], /* o : pitch values for primary channel */
+ const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */
+ const int16_t tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */
+);
+
+void gsc_enc(
+ Encoder_State *st, /* i/o: State structure */
+ float res_dct_in[], /* i : dct of residual signal */
+ float exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */
+ const int16_t Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/
+ const int16_t bits_used, /* i : Number of bit used before frequency Q */
+ const int16_t nb_subfr, /* i : Number of subframe considered */
+ const float *lsf_new, /* i : ISFs at the end of the frame */
+ float *exc_wo_nf, /* o : excitation (in f domain) w/o noisefill */
+ float *tmp_noise /* o : long-term noise energy */
+);
+
+void tdm_low_rate_enc(
+ Encoder_State *st, /* i/o: State structure */
+ const float Aq[], /* i : 12k8 Lp coefficient */
+ const float *res, /* i : residual signal */
+ float *synth, /* i/o: core synthesis */
+ float *exc, /* i/o: current non-enhanced excitation */
+ float *pitch_buf, /* i/o: floating pitch values for each subframe */
+ float *voice_factors, /* o : voicing factors */
+ float *bwe_exc, /* o : excitation for SWB TBE */
+ const int16_t attack_flag, /* i : attck flag */
+ const float *lsf_new, /* i : current frame ISF vector */
+ float *tmp_noise /* o : long-term noise energy */
+);
+
+/*! r: value of the indice */
+uint16_t get_indice_st(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t pos, /* i : absolute position in the bitstream */
+ const int16_t nb_bits /* i : number of bits to quantize the indice */
+);
+
+void tdm_low_rate_dec(
+ Decoder_State *st, /* i/o: decoder static memory */
+ float dct_epit[], /* o : GSC excitation in DCT domain */
+ float *tmp_noise, /* o : long term temporary noise energy */
+ float *pitch_buf, /* o : floating pitch values for each subframe */
+ float *voice_factors, /* o : voicing factors */
+ float *exc, /* i/o: adapt. excitation exc */
+ float *exc2, /* i/o: adapt. excitation/total exc */
+ float *bwe_exc, /* o : excitation for SWB TBE */
+ const float *lsf_new /* i : ISFs at the end of the frame */
+);
+
+void tdm_SCh_LSF_intra_pred(
+ const int32_t element_brate, /* i : element bitrate */
+ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */
+ float *pred_lsf_SCh /* o : predicted secondary channel LSFs */
+);
+
+void tdm_SCh_lsf_reuse(
+ const int16_t enc_dec, /* i : encoder/decoder flag */
+ const int32_t element_brate, /* i : element bitrate */
+ float lsf_new[M], /* i/o: LSFs at the end of the frame */
+ float lsp_new[M], /* i/o: LSPs at the end of the frame */
+ const float tdm_lsfQ_PCh[M], /* i : primary channel LSFs */
+ const float lsf_wgts[M], /* i : LSF weights */
+ int16_t *beta_index /* i/o: quantization index */
+);
+
+void first_VQstages(
+ const float *const *cb,
+ const float u[], /* i : vector to be encoded (prediction and mean removed) */
+ const int16_t *levels, /* i : number of levels in each stage */
+ const int16_t stagesVQ, /* i : number of stages */
+ const float w[], /* i : weights */
+ const int16_t N, /* i : vector dimension */
+ const int16_t max_inner, /* i : maximum number of swaps in inner loop */
+ int16_t indices_VQstage[]
+);
+
+UWord32 index_lvq_SHB(
+ const int16_t idx_lead,
+ const int16_t idx_scale,
+ const int16_t nbits,
+ float *lat_cv,
+ const int16_t mode
+);
+
+void deindex_lvq_SHB(
+ UWord32 index,
+ float *out,
+ const int16_t nbits,
+ const int16_t mode
+);
+
+/*----------------------------------------------------------------------------------*
+ * MDCT Stereo prototypes
+ *----------------------------------------------------------------------------------*/
+
+void stereo_td_itd_mdct_stereo(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder handle */
+ const int16_t vad_flag_dtx[], /* i : VAD dtx flags */
+ const int16_t vad_hover_flag[], /* i : VAD hangover flags */
+ const int16_t input_frame /* i : frame length */
+);
+
+void QuantizeTCXSpectrum(
+ Encoder_State *st, /* i : state handle */
+ const int16_t frame_cnt, /* i : frame counter in the super_frame */
+ const float *x_orig, /* i : shaped MDCT spectrum */
+ const float *gainlpc, /* i : FDNS gains */
+ const Word16 *Aqind, /* i : frame-independent quantized coefficients (M+1) */
+ const int16_t tnsSize, /* i : number of tns parameters put into prm */
+ const int16_t nb_bits, /* i : bit budget */
+ const int16_t vad_hover_flag, /* i : VAD hangover flag */
+ int16_t *pL_frameTCX, /* o : full frame length */
+ int16_t *pL_frame, /* o : frame length */
+ int16_t *pL_spec, /* o : length of the coded spectrum */
+ int16_t *ptcx_offset, /* o : folding point offset relative to the end of the previous frame */
+ int16_t *pnoiseFillingBorder, /* o : noise filling border */
+ float spectrum[], /* o : quantized MDCT spectrum */
+ CONTEXT_HM_CONFIG *hm_cfg, /* o : Context-based harmonic model configuration */
+ int16_t *hm_active, /* o : flag indicating if the harmonic model is active */
+ float lf_deemph_fact[], /* o : low frequency deemphasis factors */
+ int16_t *nf_seed, /* o : noise filling random seed */
+ float *ener, /* o : energy of the quantized spectrum */
+ float *gain_tcx, /* o : global gain */
+ int16_t prm[] /* o : tcx parameters */
+);
+
+void EstimateStereoTCXNoiseLevel(
+ Encoder_State **sts, /* i : state handle */
+ float *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */
+ float gain_tcx[][NB_DIV], /* i : global gain */
+ int16_t L_frame[][NB_DIV], /* i : frame length */
+ int16_t noiseFillingBorder[][NB_DIV], /* i : noise filling border */
+ int16_t hm_active[][NB_DIV], /* i : flag indicating if the harmonic model is active */
+ const int16_t ignore_chan[], /* i : flag indicating whether the channel should be ignored */
+ float fac_ns[][NB_DIV], /* o : noise filling level */
+ int16_t param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */
+ const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
+);
+
+void TNSAnalysisStereo(
+ Encoder_State **sts, /* i : state handle */
+ float *mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* o : MDST spectrum */
+ const int16_t bWhitenedDomain, /* i : whitened domain flag */
+ int16_t tnsSize[MCT_MAX_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm */
+ int16_t tnsBits[MCT_MAX_CHANNELS][NB_DIV], /* i : number of tns bits in the frame */
+ int16_t param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */
+ const int16_t mct_on /* i : flag mct block (1) or stereo (0) */
+);
+
+void InternalTCXDecoder(
+ Encoder_State *st, /* i/o: state handle */
+ const int16_t frame_cnt, /* i : frame counter in the super_frame */
+ const int16_t L_frameTCX, /* i : full frame length */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t L_spec, /* i : length of the coded spectrum */
+ const int16_t tcx_offset, /* i : folding point offset relative to the end of the previous frame */
+ const int16_t noiseFillingBorder, /* i : noise filling border */
+ const float *x_quant, /* i : quantized spectrum */
+ const float ener, /* i : energy of the quantized spectrum */
+ float lf_deemph_fact[], /* i/o: low frequency deemphasis factors */
+ const float fac_ns, /* i : noise filling level */
+ const int16_t nf_seed, /* i : noise filling random seed */
+ const float *A, /* i : LPC representation of the FDNS gains */
+ float *gainlpc, /* i/o: FDNS gains */
+ const int16_t hm_active, /* i : flag indicating if the harmonic model is active */
+ float gain_tcx, /* i/o: global gain / quantized global gain */
+ float spectrum[], /* o : dequantized spectrum */
+ float synth[], /* o : time domain signal */
+ int16_t *gain_tcx_q /* o : quantized global gain (at low bitrates) */
+);
+
+void stereo_mdct_core_enc(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ float new_samples[CPE_CHANNELS][L_INP], /* i : new samples */
+ float old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP */
+ float pitch_buf[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe */
+);
+
+void initMdctStereoEncData(
+ STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int16_t element_mode, /* i : element mode */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t bwidth, /* i : bandwidth */
+ const int16_t igf, /* i : flag indicating IGF activity */
+ const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */
+ const int16_t mem_init /* i : initialize memory after malloc */
+);
+
+ivas_error initMdctItdHandling(
+ STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */
+ const int32_t input_Fs /* i : input sampling rate */
+);
+
+void stereo_mdct_enc_destroy(
+ STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle */
+);
+
+void initMdctStereoDecData(
+ STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */
+ const int16_t igf, /* i : flag indicating IGF activity */
+ const H_IGF_GRID igfGrid, /* i : IGF grid configuration */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t bwidth /* i : audio bandwidth */
+);
+
+void stereo_mdct_init_bands(
+ const int16_t L_frame, /* i : frame length */
+ const int16_t tmp_tcx_mode, /* i : tcx mode (TCX10, TCX 20), -1 if transition frame */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t igf, /* i : flag indicating if IGF is used */
+ const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */
+ int16_t *sfbOffset, /* o : sfb offset table */
+ int16_t *sfbCnt /* o : number of sfbs */
+);
+
+void stereo_mdct_init_igf_start_band(
+ STEREO_MDCT_BAND_PARAMETERS *stbParams, /* i/o: stereo frequency band parameters */
+ const float transFac, /* i : transform factor */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int32_t element_brate /* i : element bitrate */
+);
+
+void init_tcx_enc_info(
+ Encoder_State *st, /* i : coder memory state */
+ int16_t *L_frame,
+ int16_t *L_frameTCX,
+ int16_t *L_spec
+);
+
+void decoder_tcx_invQ(
+ Decoder_State *st, /* i/o: coder memory state */
+ int16_t prm[], /* i : parameters */
+ float A[], /* i : coefficients NxAz[M+1] */
+ Word16 Aind[], /* i : frame-independent coefficients Az[M+1] */
+ const int16_t L_spec,
+ const int16_t L_frame,
+ const int16_t L_frameTCX,
+ float x[],
+ float gainlpc2[],
+ float xn_buf[],
+ int16_t *fUseTns, /* o : flag that is set if TNS data is present */
+ STnsData *tnsData,
+ float *gain_tcx,
+ const int16_t **prm_sqQ,
+ int16_t *nf_seed,
+ const int16_t bfi, /* i : Bad frame indicator */
+ const int16_t frame_cnt /* i : frame counter in the super frame */
+);
+
+void decoder_tcx_noisefilling(
+ Decoder_State *st, /* i/o: coder memory state */
+ float concealment_noise[L_FRAME48k],
+ const float A[], /* i : coefficients NxAz[M+1] */
+ const int16_t L_frameTCX_glob,
+ const int16_t L_spec,
+ const int16_t L_frame,
+ const int16_t L_frameTCX,
+ float x[],
+ float gainlpc2[],
+ int16_t *temp_concealment_method,
+ const float gain_tcx,
+ const int16_t *prm_sqQ,
+ int16_t nf_seed,
+ const int16_t bfi, /* i : Bad frame indicator */
+ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
+ const int16_t frame_cnt /* i : frame counter in the super frame */
+);
+
+void decoder_tcx_noiseshaping_igf(
+ Decoder_State *st, /* i/o: coder memory state */
+ const int16_t L_spec,
+ const int16_t L_frame,
+ const int16_t L_frameTCX,
+ const int16_t left_rect,
+ float x[],
+ const float gainlpc2[],
+ int16_t *temp_concealment_method,
+ const int16_t bfi /* i : Bad frame indicator */
+);
+
+void decoder_tcx_tns(
+ Decoder_State *st, /* i/o: coder memory state */
+ const int16_t L_frame_glob,
+ const int16_t L_spec,
+ const int16_t L_frame,
+ const int16_t L_frameTCX,
+ float x[N_MAX],
+ const int16_t fUseTns, /* i : flag that is set if TNS data is present */
+ STnsData *tnsData,
+ const int16_t bfi, /* i : Bad frame indicator */
+ const int16_t frame_cnt, /* i : frame counter in the super frame */
+ const int16_t whitenedDomain
+);
+
+void decoder_tcx_imdct(
+ Decoder_State *st, /* i/o: coder memory state */
+ const int16_t L_frame_glob, /* i : frame length */
+ const int16_t L_frameTCX_glob,
+ const int16_t L_spec,
+ const int16_t tcx_offset,
+ const int16_t tcx_offsetFB,
+ const int16_t L_frame,
+ const int16_t L_frameTCX,
+ const int16_t left_rect,
+ float x[N_MAX],
+ float xn_buf[],
+ const uint16_t kernelType, /* i : TCX transform kernel type */
+ const int16_t fUseTns, /* i : flag that is set if TNS data is present */
+ float synth[], /* i/o: synth[-M..L_frame] */
+ float synthFB[],
+ const int16_t bfi, /* i : Bad frame indicator */
+ const int16_t frame_cnt, /* i : frame counter in the super frame */
+ const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */
+);
+
+void init_tcx_info(
+ Decoder_State *st, /* i/o: coder memory state */
+ const int16_t L_frame_glob, /* i : global frame length */
+ const int16_t L_frameTCX_glob, /* i : FB global frame length */
+ const int16_t frame_cnt, /* i : frame counter in the super_frame */
+ const int16_t bfi, /* i : bad frame indicator */
+ int16_t *tcx_offset, /* o : folding point offset relative to the end of the previous frame */
+ int16_t *tcx_offsetFB, /* o : FB folding point offset relative to the end of the previous frame*/
+ int16_t *L_frame, /* o : frame length */
+ int16_t *L_frameTCX, /* o : TCX frame length */
+ int16_t *left_rect, /* o : left part is rectangular */
+ int16_t *L_spec /* o : spectrum length */
+);
+
+void decoder_tcx_IGF_mono(
+ Decoder_State *st, /* i/o: coder memory state */
+ float x[], /* o : de-quatized coefficients */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t left_rect, /* i : left part is rectangular */
+ const int16_t bfi, /* i : bad frame indicator */
+ const int16_t frame_cnt /* i : frame counter in the super_frame */
+);
+
+void decoder_tcx_IGF_stereo(
+ Decoder_State **sts, /* i/o: coder memory states */
+ STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo structure */
+ int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */
+ float *x[CPE_CHANNELS][NB_DIV], /* o : de-quatized coefficients */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t left_rect, /* i : left part is rectangular */
+ const int16_t k, /* i : Subframe index */
+ const int16_t bfi, /* i : bad frame indicator */
+ const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
+);
+
+void ms_processing(
+ STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */
+ Encoder_State **sts, /* i/o: Encoder state structure */
+ int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */
+ const int16_t iSubframe, /* i : subframe number */
+ float x_0[], /* i/o: spectrum 1 */
+ float x_1[], /* i/o: spectrum 2 */
+ int16_t maxSfb /* i : number of stereo frequency bands */
+);
+
+void ms_inv_mask_processing(
+ STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */
+ Encoder_State **sts, /* i/o: Encoder state structure */
+ int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */
+ const int16_t iSubframe, /* i : subframe number */
+ const float x_0[], /* i : spectrum 1 */
+ const float x_1[], /* i : spectrum 2 */
+ float x_inv_0[], /* o : inverse spectrum 1 */
+ float x_inv_1[], /* o : inverse spectrum 2 */
+ int16_t maxSfb /* i : number of stereo frequency bands */
+);
+
+void IGFDecApplyStereo(
+ const IGF_DEC_INSTANCE_HANDLE hIGFDecL, /* i : instance handle of IGF Decoder */
+ const IGF_DEC_INSTANCE_HANDLE hIGFDecR, /* i : instance handle of IGF Decoder */
+ float *spectrumL, /* i/o: L MDCT spectrum */
+ float *spectrumR, /* i/o: R MDCT spectrum */
+ const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
+ const int16_t *coreMsMask,
+ const int16_t restrict_hopsize,
+ const int16_t bfi, /* i : frame loss == 1, frame good == 0 */
+ const int16_t bfi_apply_damping /* i : decoder element mode */
+);
+
+void IGFEncStereoEncoder(
+ STEREO_MDCT_BAND_PARAMETERS *sfbParam, /* i/o: sfb parameters for the right channel */
+ const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : IGF handle */
+ const float *mdctSpectrumL, /* i : left spectrum */
+ const float *mdctSpectrumR, /* i : right spectrum */
+ int16_t *msMask, /* i/o: MS mask */
+ int16_t *igfStereoMode, /* o : IGF stereo mode */
+ const int16_t mdct_stereo_mode, /* i : MDCT stereo mode */
+ const int16_t isTCX20, /* i : flag for indicating TCX20 */
+ const int16_t isTransition /* i : flag for transtition */
+);
+
+void IGFDecReplicateTCX10State(
+ IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: instance handle of IGF Decoder */
+);
+
+void InitPsychLPC(
+ const int32_t sr_core, /* i : sampling rate of core-coder */
+ const int16_t L_frame, /* i : frame length */
+ const TCX_CONFIG_HANDLE hTcxCfg /* i : TCX configuration handle */
+);
+
+void SetCurrentPsychParams(
+ const int16_t core,
+ const int16_t last_frame_was_concealed_cng,
+ TCX_CONFIG_HANDLE hTcxCfg
+);
+
+void stereo_coder_tcx(
+ STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */
+ Encoder_State **sts, /* i/o: encoder state structure */
+ int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */
+ float *mdst_spectrum[CPE_CHANNELS][NB_DIV], /* i/o: MDST spectrum */
+ float *inv_spectrum[CPE_CHANNELS][NB_DIV], /* i/o: inverse spectrum */
+ float *inv_mdst_spectrum[CPE_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */
+ const int16_t mct_on /* i : flag mct block (1) or stereo (0) */
+);
+
+void stereo_decoder_tcx(
+ STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: MDCT stereo decoder structure */
+ int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */
+ float *spec_r_0[NB_DIV], /* i/o: spectrum right channel */
+ float *spec_l[NB_DIV], /* i/o: spectrum left channel */
+ float *spec_r[NB_DIV], /* i/o: spectrum right channel */
+ const int16_t mdct_stereo_mode[], /* i : stereo mode (FB/band wise MS, dual mono */
+ const int16_t core_l, /* i : core for left channel (TCX20/TCX10) */
+ const int16_t core_r, /* i : core for right channel (TCX20/TCX10) */
+ const int16_t igf, /* i : flag for IGF activity */
+ const int16_t L_frameTCX_l, /* i : TCX frame length of left channel */
+ const int16_t L_frameTCX_r, /* i : TCX frame length of right channel */
+ const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */
+ const int16_t last_core_l, /* i : last core for left channel */
+ const int16_t last_core_r, /* i : last core for right channel */
+ const int16_t tmp_plc_upmix /* i : indicates temp upmix for PLC decision */
+);
+
+void stereo_mdct_core_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *signal_out[CPE_CHANNELS], /* o : synthesis @internal_FS */
+ float signal_outFB[CPE_CHANNELS][L_FRAME48k] /* o : synthesis @output_FS */
+);
+
+void splitAvailableBits(
+ const int16_t total_bits, /* i : total available bits for TCX coding */
+ const int16_t split_ratio, /* i : split ratio */
+ const int16_t isSBAStereoMode, /* i : signal core coding for SBA */
+ int16_t *bits_ch0, /* o : bits for channel 0 */
+ int16_t *bits_ch1 /* o : bits for channel 1 */
+);
+
+int16_t write_stereo_to_bitstream
+(
+ STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */
+ Encoder_State **sts, /* i/o: Encoder state structure */
+ int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */
+ const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */
+ BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */
+);
+
+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 int16_t mct_on, /* i : flag mct block (1) or stereo (0) */
+ const int16_t isSBAStereoMode, /* i : flag core coding for SBA */
+ Decoder_State *st0, /* i/o: decoder state structure for Bstr */
+ int16_t ms_mask[NB_DIV][MAX_SFB] /* o : bandwise MS mask */
+);
+
+void FindSplitRatio(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ Encoder_State **sts /* i/o: Encoder state structure */
+);
+
+void ComputeSpectrumNoiseMeasure(
+ const float *powerSpec,
+ const int16_t L_frame,
+ const int16_t startLine,
+ const int16_t resetMemory,
+ int16_t *noiseFlags,
+ const int16_t lowpassLine
+);
+
+void IGFSaveSpectrumForITF(
+ IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */
+ const int16_t igfGridIdx, /* i : IGF grid index */
+ const float *pITFSpectrum /* i : MDCT spectrum */
+);
+
+void convert_coeffs_to_higher_res(
+ const float *in1, /* i : first subframe input */
+ const float *in2, /* i : second subframe input */
+ float *out, /* o : converted output */
+ const int16_t len /* i : length of subframes */
+);
+
+void sns_compute_scf(
+ float spectrum[],
+ const PsychoacousticParameters *pPsychParams,
+ const int16_t L_frame,
+ float *scf
+);
+
+void sns_interpolate_scalefactors(
+ float *scf_int, /* o : interpolated scalefactors for spectrum shaping */
+ const float *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */
+ int16_t encoder_side /* i : flag, if scalefactors have to be inverted */
+);
+
+void sns_shape_spectrum(
+ float spectrum[], /* i/o: spectrum to be shaped */
+ const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */
+ const float *scf_int, /* i : already interpolated SNS scalefactors */
+ const int16_t L_frame /* i : frame length */
+);
+
+int16_t quantize_sns(
+ float sns_in[CPE_CHANNELS][NB_DIV][M],
+ float snsQ_out[CPE_CHANNELS][NB_DIV][M],
+ Encoder_State **sts,
+ int16_t *indices,
+ int16_t *zero_side_flag,
+ int16_t *sns_stereo_mode
+);
+
+void dequantize_sns(
+ int16_t indices[CPE_CHANNELS][NPRM_LPC_NEW],
+ float snsQ_out[CPE_CHANNELS][NB_DIV][M],
+ Decoder_State **sts
+);
+
+void sns_avq_cod(
+ const float *sns, /* i : Input sns vectors */
+ const float *snsmid, /* i : Input mid-sns vectors */
+ float *sns_q, /* o : Quantized LFS vectors */
+ float *snsmid_q, /* o : Quantized mid-LFS vectors */
+ int16_t *index, /* o : Quantization indices */
+ const int16_t core, /* i : core */
+ const int16_t L_frame,
+ const int16_t low_brate_mode /* i : flag low bit operating mode */
+);
+
+void sns_avq_cod_stereo(
+ const float *snsl, /* i : Input sns vector (left channel) */
+ const float *snsr, /* i : Input sns vector (right channel) */
+ const int16_t L_frame,
+ float *snsl_q, /* o : Quantized sns vector (left channel) */
+ float *snsr_q, /* o : Quantized sns vector (right channel) */
+ int16_t *indexl, /* o : Quantization indices (left channel) */
+ int16_t *indexr /* o : Quantization indices (right channel) */
+);
+
+void sns_avq_dec(
+ int16_t *index, /* i : Quantization indices */
+ float SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t numlpc /* i : Number of sets of lpc */
+);
+
+void sns_avq_dec_stereo(
+ int16_t *indexl, /* i : Quantization indices (left channel) */
+ int16_t *indexr, /* i : Quantization indices (right channe) */
+ const int16_t L_frame, /* i : frame length */
+ float *SNS_Ql, /* o : Quantized SNS vectors (left channel) */
+ float *SNS_Qr /* o : Quantized SNS vectors (right channe) */
+);
+
+void convertToMS(
+ const int16_t L_frame, /* i : frame length */
+ float x0[], /* i/o: mid/left channel coefficients */
+ float x1[], /* i/o: side/right channel coefficients */
+ const float norm_fac /* i : normalization factor */
+);
+
+void inverseMS(
+ const int16_t L_frame, /* i : frame length */
+ float x0[], /* i/o: mid/left channel coefficients */
+ float x1[], /* i/o: side/right channel coefficients */
+ const float norm_fac /* i : normalization factor */
+);
+
+void stereoFdCngCoherence(
+ Encoder_State **sts, /* i/o: core encoder structures */
+ const int16_t last_element_mode, /* i : last element mode */
+ float fft_buff[CPE_CHANNELS][2 * L_FFT] /* i : fft buffers for L and R channels */
+);
+
+void FdCngEncodeMDCTStereoSID(
+ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder state structure */
+);
+
+void FdCngDecodeMDCTStereoSID(
+ CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
+);
+
+ivas_error initMdctStereoDtxData(
+ CPE_DEC_HANDLE hCPE /* i/o: CPE decoder handle */
+);
+
+void synchonize_channels_mdct_sid(
+ Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */
+ const int16_t n /* i : channel number */
+);
+
+void updateBuffersForDmxMdctStereo(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */
+ const int16_t output_frame, /* i : output frame length */
+ float *output[CPE_CHANNELS], /* i/o: decoder output */
+ float synth[CPE_CHANNELS][L_FRAME48k] /* i/o: decoder synthesis */
+);
+
+void applyDmxMdctStereo(
+ const CPE_DEC_HANDLE hCPE, /* i : CPE handle */
+ float *output[CPE_CHANNELS], /* o : output from core decoder */
+ const int16_t output_frame /* i : output frame length */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * Front-VAD prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error front_vad_create(
+ FRONT_VAD_ENC_HANDLE *hFrontVad, /* i/o: front-VAD handle */
+ const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */
+);
+
+void front_vad_destroy(
+ FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */
+);
+
+ivas_error front_vad(
+ 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: front-VAD handles */
+ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
+ const int16_t input_frame, /* i : frame length */
+ int16_t vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */
+ float fr_bands[][2 * NB_BANDS], /* i : energy in frequency bands */
+ float Etot_LR[], /* o : total energy Left & Right channel */
+ float lf_E[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */
+ int16_t localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels */
+ int16_t vad_hover_flag[], /* o : VAD hangover flag */
+ float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */
+ float *PS_out, /* o : energy spectrum */
+ float *Bin_E_out /* o : log-energy spectrum of the current frame*/
+);
+
+ivas_error front_vad_spar(
+ SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */
+ const float *omni_in, /* i : omnidirectional input signal */
+ ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */
+ const int16_t input_frame /* i : input frame length */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * Stereo CNG prototypes
+ *----------------------------------------------------------------------------------*/
+
+void stereo_enc_cng_init(
+ STEREO_CNG_ENC_HANDLE hStereoCng /* i/o: stereo CNG encoder structure */
+);
+
+void stereo_cng_upd_counters(
+ STEREO_CNG_ENC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */
+ const int32_t element_mode, /* i : element mode */
+ const int16_t nbands, /* i : Number of bands in active */
+ const float sidSideGain[], /* i : SID side gains */
+ const int16_t burst_ho_count, /* i : Hang-over count */
+ int16_t *coh_fade_counter /* i : Coherence fade counter */
+);
+
+void stereo_cng_init_dec(
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */
+ const int16_t *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */
+);
+
+void stereo_cng_compute_PScorr(
+ float *output[CPE_CHANNELS], /* i : Output signal */
+ float *c_PS_LT, /* i/o: Correlation */
+ const int16_t L_frame_0, /* i : L_frame channel 0 */
+ const int16_t L_frame_1 /* i : L_frame channel 1 */
+);
+
+void stereo_cng_dec_update(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+void stereo_cna_update_params(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *output[CPE_CHANNELS], /* i : Output signal */
+ const int16_t output_frame, /* i : Output frame length */
+ const int16_t tdm_ratio_idx /* i : TDM ratio index */
+);
+
+void dtx_enc_init(
+ Encoder_State *st, /* i : Encoder state handle */
+ const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */
+ const int16_t interval_SID /* i : interval for SID update */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * Framework general prototypes
+ *----------------------------------------------------------------------------------*/
+
+void mvr2r_inc(
+ const float x[], /* i : input vector */
+ const int16_t x_inc, /* i : increment for vector x[] */
+ float y[], /* o : output vector */
+ const int16_t y_inc, /* i : increment for vector y[] */
+ const int16_t n /* i : vector size */
+);
+
+void v_add_inc(
+ const float x1[], /* i : Input vector 1 */
+ const int16_t x_inc, /* i : Increment for input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ const int16_t x2_inc, /* i : Increment for input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 + vector 2 */
+ const int16_t y_inc, /* i : increment for vector y[] */
+ const int16_t N /* i : Vector length */
+);
+
+void v_mult_inc(
+ const float x1[], /* i : Input vector 1 */
+ const int16_t x1_inc, /* i : Increment for input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ const int16_t x2_inc, /* i : Increment for input vector 1 */
+ float y[], /* o : Output vector that contains vector 1 .* vector 2 */
+ const int16_t y_inc, /* i : increment for vector y[] */
+ const int16_t N /* i : Vector length */
+);
+
+void v_addc(
+ const float x[], /* i : Input vector */
+ const float c, /* i : Constant */
+ float y[], /* o : Output vector that contains c*x */
+ const int16_t N /* i : Vector length */
+);
+
+void v_min(
+ const float x1[], /* i : Input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 .* vector 2 */
+ const int16_t N /* i : Vector length */
+);
+
+void v_sqrt(
+ const float x[], /* i : Input vector */
+ float y[], /* o : Output vector that contains sqrt(x) */
+ const int16_t N /* i : Vector length */
+);
+
+/*! r: sum abs of all vector elements */
+float sumAbs(
+ const float *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+void mvc2c(
+ const uint8_t x[], /* i : input vector */
+ uint8_t y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+/*! r: the dot product x'*A*A'*x */
+float dot_product_cholesky(
+ const float *x, /* i : vector x */
+ const float *A, /* i : Cholesky matrix A */
+ const int16_t N /* i : vector & matrix size */
+);
+
+void v_mult_mat(
+ float *y, /* o : the product x*A */
+ const float *x, /* i : vector x */
+ const float *A, /* i : matrix A */
+ const int16_t N, /* i : number of rows */
+ const int16_t C /* i : number of columns */
+);
+
+/*! r: log(sum(exp(X)) of the input array X */
+float logsumexp(
+ const float X[], /* i : input array X */
+ const int16_t N /* i : number of elements in array X */
+);
+
+/*! r: mapped output value */
+float lin_interp(
+ const float x, /* i : the value to be mapped */
+ const float x1, /* i : source range interval: low end */
+ const float y1, /* i : source range interval: high end */
+ const float x2, /* i : target range interval: low */
+ const float y2, /* i : target range interval: high */
+ const int16_t flag_sat /* i : flag to indicate whether to apply saturation */
+);
+
+/*! r: Adjusted value */
+float check_bounds(
+ const float value, /* i : Input value */
+ const float low, /* i : Low limit */
+ const float high /* i : High limit */
+);
+
+/*! r: Adjusted value */
+int16_t check_bounds_s(
+ const int16_t value, /* i : Input value */
+ const int16_t low, /* i : Low limit */
+ const int16_t high /* i : High limit */
+);
+
+ivas_error stereo_memory_enc(
+ CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */
+ const int32_t input_Fs, /* i : input sampling rate */
+ const int16_t max_bwidth, /* i : maximum audio bandwidth */
+ float *tdm_last_ratio, /* o : TD stereo last ratio */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int16_t nchan_transport /* i : number transport chans */
+
+);
+
+ivas_error stereo_memory_dec(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */
+ const int16_t nb_bits_metadata, /* i : number of metadata bits */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const MC_MODE mc_mode, /* i : MC mode */
+ const int16_t nchan_transport /* i : number of transport channels */
+);
+
+void stereo_switching_enc(
+ CPE_ENC_HANDLE hCPE, /* i : CPE structure */
+ float old_input_signal_pri[], /* i : old input signal of primary channel */
+ const int16_t input_frame /* i : input frame length */
+);
+
+void stereo_switching_dec(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+void stereo_td2dft_update(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ const int16_t n, /* i : channel number */
+ float output[], /* i/o: synthesis @internal Fs */
+ float synth[], /* i/o: synthesis @output Fs */
+ float hb_synth[], /* i/o: hb synthesis */
+ const int16_t output_frame /* i : frame length */
+);
+
+void stereo_mdct2dft_update(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float output0[], /* i/o: synthesis @internal Fs, ch0 */
+ float synth0[] /* i/o: synthesis @output Fs, ch0 */
+);
+
+/*! r: number of bits written */
+int16_t write_GR0(
+ BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */
+ const int16_t ind, /* i : bitstream index */
+ const int16_t *in, /* i : data to be encoded */
+ const int16_t len /* i : input data length */
+);
+
+/*! r: number of bits read */
+int16_t read_GR0(
+ const uint16_t *bit_stream, /* i : bitstream to be read */
+ int16_t *ind, /* o : parameters read */
+ const int16_t len /* i : number of params to be read */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * MCT prototypes
+ *----------------------------------------------------------------------------------*/
+
+void ivas_mdct_core_whitening_enc(
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ float new_samples[CPE_CHANNELS][L_INP], /* i : new samples */
+ float old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP */
+ float pitch_buf[CPE_CHANNELS][NB_SUBFR16k], /* o : floating pitch for each subframe */
+ float *mdst_spectrum_long[CPE_CHANNELS], /* o : buffer for MDST spectrum */
+ int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* o : buffer TNS bits */
+ float *orig_spectrum_long[CPE_CHANNELS], /* o : origingal spectrum w/o whitening */
+ int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* o : size of TNS */
+ int16_t p_param[CPE_CHANNELS][NB_DIV], /* o : pointer to parameter array */
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */
+ const int16_t nChannels /* i : total number of coded channels */
+);
+
+void ivas_mct_core_enc(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */
+ CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */
+ const int16_t nChannels, /* i : number of channels to be coded */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t switch_bw, /* i : flag bandwidth switch occurance */
+ const int16_t lfe_bits, /* i : bits spent for LFE */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+);
+
+void ivas_mdct_quant_coder(
+ CPE_ENC_HANDLE hCPE, /* i/o: Encoder CPE handle */
+ int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* i : bits needed for TNS parameters */
+ int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* i : size of TNS */
+ int16_t p_param[CPE_CHANNELS][NB_DIV], /* i : pointer to parameter array */
+ const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
+);
+
+void apply_MCT_enc(
+ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */
+ Encoder_State **sts, /* i/o: encoder state structure */
+ float *mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: MDST spectrum */
+ float *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse spectrum */
+ float *inv_mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */
+ const int16_t nchan /* i : number of channels */
+);
+
+void write_mct_bitstream(
+ Encoder_State **sts, /* i/o: encoder state structure */
+ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */
+ const int16_t nchan /* i : number of channels */
+);
+
+void splitAvailableBitsMCT(
+ void **sts, /* i/o: encoder/decoder state structure */
+ const int16_t total_bits, /* i : total number of available bits */
+ const int16_t split_ratio[MCT_MAX_CHANNELS], /* i : ratio for splitting the bits */
+ const int16_t enc_dec, /* i : encoder or decoder flag */
+ const int16_t nchan /* i : number of channels */
+);
+
+void getChannelEnergies(
+ Encoder_State **sts, /* i : Encoder state structure */
+ float nrg[MCT_MAX_CHANNELS], /* o : energies */
+ const int16_t nchan /* i : number of channels */
+);
+
+void mctStereoIGF_enc(
+ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */
+ Encoder_State **sts, /* i/o: encoder state structure */
+ float *orig_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i : MDCT spectrum for ITF */
+ float powerSpec[MCT_MAX_CHANNELS][L_FRAME48k], /* i/o: MDCT^2 + MDST^2 spectrum,or estimate */
+ float *powerSpecMsInv[MCT_MAX_CHANNELS][NB_DIV], /* i : same as above but for inverse spect. */
+ float *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i : inverse spectrum */
+ const int16_t sp_aud_decision0[MCT_MAX_CHANNELS] /* i : speech audio decision */
+);
+
+void ivas_mdct_dec_side_bits_frame_channel(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ int16_t param_lpc[MCT_MAX_CHANNELS][NPRM_LPC_NEW], /* o : lpc_parameters */
+ int16_t p_param[CPE_CHANNELS][NB_DIV], /* o : pointer to param buffer */
+ Decoder_State *st0, /* i : pointer to bitstream handle */
+ int16_t nTnsBitsTCX10[CPE_CHANNELS][NB_DIV], /* o : number of bits for TNS */
+ int16_t param[CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV], /* i/o: parameters buffer */
+ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
+ const int16_t odd_channel_cpe /* i : flag cpe with odd nb of tc channels */
+);
+
+void ivas_mct_side_bits(
+ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */
+ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */
+ const int16_t nCPE, /* i : number of CPEs */
+ Decoder_State *st0, /* i : decoder handle for Bstr */
+ const int16_t bfi, /* i : BFI flag */
+ uint16_t *bitstream, /* o : bitstream indices */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t nb_bits_metadata /* i : number of metadata bits */
+);
+
+void ivas_mdct_core_invQ(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */
+ int16_t nTnsBitsTCX10[CPE_CHANNELS][NB_DIV], /* i : number of TNS bits */
+ int16_t p_param[CPE_CHANNELS][NB_DIV], /* i : pointer to param buffer */
+ int16_t param_lpc[CPE_CHANNELS][NPRM_LPC_NEW], /* i : lpc parameters */
+ int16_t param[CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV], /* i : param buffer */
+ int16_t fUseTns[CPE_CHANNELS][NB_DIV], /* i : flag TNS enabled */
+ STnsData tnsData[CPE_CHANNELS][NB_DIV], /* i : TNS parameter */
+ float *x_0[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */
+ float *x[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */
+ float Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* i : LP coefficients */
+ int16_t ms_mask[NB_DIV][MAX_SFB], /* i : M/S mask */
+ const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
+);
+
+void ivas_mdct_core_reconstruct(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ float *x[][NB_DIV], /* i/o: pointers to synthesis @internal_FS */
+ float signal_outFB[CPE_CHANNELS][L_FRAME_PLUS], /* o : synthesis @output_FS */
+ int16_t fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */
+ const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
+);
+
+void ivas_mdct_core_tns_ns(
+ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
+ int16_t fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */
+ STnsData tnsData[CPE_CHANNELS][NB_DIV], /* o : TNS parameter */
+ float *x[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS */
+ float Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients */
+ const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
+);
+
+void ivas_mct_core_dec(
+ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */
+ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */
+ const int16_t nCPE, /* i : number of CPEs */
+ float *signal_out[] /* o : synthesis @internal_FS */
+);
+
+void ivas_mct_dec_mct(
+ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */
+ Decoder_State **sts, /* i/o: decoder state structure */
+ const int16_t nchan /* i : number of channels */
+);
+
+void apply_MCT_dec(
+ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */
+ Decoder_State **sts, /* i/o: decoder state structure */
+ float *x[MCT_MAX_CHANNELS][NB_DIV] /* i/o: decoded and dequan. spect. input to MCT */
+);
+
+void mctStereoIGF_dec(
+ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */
+ Decoder_State **sts, /* i/o: decoder state structure */
+ float *x[MCT_MAX_CHANNELS][NB_DIV], /* i/o: decoded and dequantized spectrum */
+ const int16_t bfi /* i : bad frame flag */
+);
+
+void ivas_mdct_tcx10_bit_distribution(
+ int16_t target_bitsTCX10[NB_DIV], /* o : target bit distribution */
+ const int16_t bits_frame_channel, /* i : bits frame channel */
+ const int16_t nTnsBitsTCX10[NB_DIV] /* i : TNS bits */
+);
+
+void enc_prm_igf_mdct(
+ Encoder_State *st, /* i : Encoder state handle */
+ BSTR_ENC_HANDLE hBstr /* i/o: Bitstream handle */
+);
+
+void mdct_read_IGF_bits(
+ Decoder_State *st, /* i/o: Encoder state handle */
+ Decoder_State *st0 /* i : pointer to handle where bstr is read */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * Q Metadata prototypes for DirAC and MASA
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_qmetadata_enc_encode(
+ BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */
+ IVAS_QMETADATA *hQMetaData, /* i/o: q_metadata handle */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+);
+
+ivas_error ivas_qmetadata_enc_encode_hr_384_512(
+ BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */
+ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */
+ const int16_t bits_sph_idx,
+ const int16_t bits_sp_coh
+);
+
+void deindex_sph_idx(
+ const uint16_t sphIndex, /* i : Spherical index */
+ const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */
+ float *theta, /* o : Elevation */
+ float *phi /* o : Azimuth */
+);
+
+/*! r: output index for direction */
+uint16_t index_theta_phi_16(
+ float * p_theta, /* i/o: input elevation to be indexed */
+ float * p_phi, /* i/o: input azimuth to be indexed */
+ const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */
+);
+
+void reset_metadata_spatial(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */
+ const int32_t element_brate, /* i : element bitrate */
+ int32_t *total_brate, /* o : total bitrate */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t nb_bits_metadata /* i : number of meatdata bits */
+);
+
+/*! r: number of bits written */
+void ivas_qmetadata_enc_sid_encode(
+ BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */
+ IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */
+ const int16_t masa_sid_descriptor, /* i : description of MASA SID coding structure*/
+ const int16_t ivas_format /* i : ivas format */
+);
+
+/*! r: number of bits read */
+int16_t ivas_qmetadata_dec_decode(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ uint16_t *bitstream, /* i : bitstream */
+ int16_t *index, /* i/o: bitstream position */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+);
+
+/*! r: number of bits read */
+int16_t ivas_qmetadata_dec_decode_hr_384_512(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */
+ uint16_t *bitstream, /* i : bitstream */
+ int16_t *index, /* i/o: bitstream position */
+ const SPHERICAL_GRID_DATA *sph_grid16, /* i : spherical grid for deindexing */
+ const int16_t bits_sph_idx,
+ const int16_t bits_sp_coh,
+ const uint8_t ncoding_bands_config
+);
+
+/*! r: number of bits read */
+int16_t ivas_qmetadata_dec_sid_decode(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ uint16_t *bitstream, /* i : bitstream */
+ int16_t *index, /* i/o: bitstream position */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ int16_t *element_mode, /* o : element mode */
+ const int16_t ivas_format /* i : IVAS format */
+);
+
+void ivas_qmetadata_to_dirac(
+ const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */
+ DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */
+ MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
+ int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */
+);
+
+ivas_error ivas_qmetadata_open(
+ IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */
+);
+
+ivas_error ivas_qmetadata_allocate_memory(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ const int16_t nbands, /* i : new number of frequency bands */
+ const int16_t ndirs, /* i : new number of directions */
+ const int16_t coherence_flag /* i : new coherence coding status */
+);
+
+void ivas_qmetadata_close(
+ IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */
+);
+
+void restore_metadata_buffer(
+ BSTR_ENC_HANDLE hMetaData,
+ const int16_t next_ind_start,
+ const int16_t bit_pos_start
+);
+
+/*! r: codeword index */
+int16_t masa_sq(
+ const float in, /* i : input value */
+ const float *threshold, /* i : partition */
+ const int16_t cb_sz /* i : codebook size */
+);
+
+void ivas_qmetadata_azimuth_elevation_to_direction_vector(
+ const float az, /* i : azimuth */
+ const float el, /* i : elevation */
+ float *dv /* o : direction vector */
+);
+
+void ivas_qmetadata_direction_vector_to_azimuth_elevation(
+ const float *dv, /* i : direction vector */
+ float *az, /* o : azimuth */
+ float *el /* o : elevation */
+);
+
+ivas_error only_reduce_bits_direction(
+ int16_t *reduce_bits_out,
+ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
+ int16_t reduce_bits,
+ const int16_t coding_subbands,
+ const int16_t no_subframes,
+ int16_t *ind_order
+);
+
+void quantize_direction_frame(
+ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
+ float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES],
+ float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES],
+ const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/
+);
+
+/*! r: quantized spherical index */
+uint16_t quantize_direction(
+ const float theta, /* i : input elevation value */
+ float phi, /* i : input azimuth value */
+ const int16_t no_bits, /* i : number of bits */
+ float *theta_q, /* o : quantized elevation */
+ float *phi_q, /* o : quantized azimuth */
+ uint16_t *index_theta, /* o : quantized elevation index */
+ uint16_t *index_phi, /* o : quantized azimuth index */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+);
+
+int16_t quantize_direction2D(
+ float phi, /* i : input azimuth value */
+ const int16_t no_cw, /* i : number of bits */
+ float *phi_q, /* o : quantized azimuth value */
+ uint16_t *index_phi, /* o : quantized azimuth index */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+);
+
+/*! r :companded azimuth value */
+float companding_azimuth(
+ const float azi, /* i : input azimuth value */
+ const MC_LS_SETUP mc_format, /* i : input channel format */
+ const int16_t theta_flag, /* i : zero/non zero elevation flag */
+ const int16_t direction /* i : direction of companding (direct or inverse)*/
+);
+
+/*! r: index azimuth */
+int16_t quantize_phi_chan_lbr(
+ const float phi, /* i : azimuth value */
+ float *phi_hat, /* o : quantized azimuth */
+ const int16_t n /* i : azimuth codebook size */
+);
+
+/*! r: index azimuth */
+int16_t quantize_phi_chan_compand(
+ float phi, /* i : azimuth value */
+ float *phi_hat, /* o : quantized azimuth */
+ const int16_t n, /* i : azimuth codebook size */
+ const int16_t theta_flag, /* i : flag signaling high elevation */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+);
+
+void quantize_direction_frame2D(
+ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
+ float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* i : input azimuth values */
+ float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] /* i : input elevation values */
+);
+
+void small_requantize_direction_frame(
+ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
+ float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* i : input azimuth values */
+ float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* i : input elevation values */
+ const int16_t raw_flag[MASA_MAXIMUM_CODING_SUBBANDS], /* i : raw/EC encoding mode for each subband */
+ int16_t bits_dir_bands[MASA_MAXIMUM_CODING_SUBBANDS], /* i/o: number of bits per subband */
+ int16_t *diff /* i/o: number of bits to be reduced */
+);
+
+/*! r: index azimuth */
+int16_t quantize_phi(
+ float phi, /* i : azimuth value */
+ const int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */
+ float *phi_hat, /* o : quantized azimuth */
+ const int16_t n /* i : azimuth codebook size */
+);
+
+/*! r: decoded elevation value */
+float deindex_elevation(
+ uint16_t *id_th, /* i : input index */
+ const int16_t no_bits, /* i : number of bits for the spherical grid */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+);
+
+float deindex_azimuth(
+ int16_t id_phi, /* i : index */
+ const int16_t no_bits, /* i : number of bits for the spherical grid */
+ const int16_t id_th, /* i : elevation index */
+ const int16_t remap, /* i : remapping flag */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+);
+
+void deindex_spherical_component(
+ const uint16_t sph_idx, /* i : spherical index */
+ float *az, /* o : decoded azimuth value */
+ float *el, /* o : decoded elevation value */
+ uint16_t *az_idx, /* o : azimuth index */
+ uint16_t *el_idx, /* o : elevation index */
+ const uint16_t no_bits, /* i : number of bits for the spherical grid */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+);
+
+void small_reduction_direction(
+ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
+ uint16_t bits_dir[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], /* i : bit allocation in tF tiles */
+ const int16_t raw_flag[MASA_MAXIMUM_CODING_SUBBANDS], /* i : raw/EC coding indicator for each subband*/
+ int16_t *diff /* i/o: number of bits that need to be reduced */
+);
+
+uint16_t ivas_qmetadata_reorder_generic(
+ const int16_t signed_value
+);
+
+int16_t ivas_qmetadata_dereorder_generic(
+ const uint16_t uns_value /* i : unsigned value to reorder */
+);
+
+/*! r: projected azimuth index */
+int16_t ivas_dirac_project_azimuth_index(
+ const int16_t az_idx, /* i : azimuth index */
+ const int16_t az_alph, /* i : number of azimuth symbols */
+ const int16_t az_alph_proj /* i : size of projected alphabet */
+);
+
+/*! r: projected elevation index */
+int16_t ivas_dirac_project_elevation_index(
+ const int16_t el_idx, /* i : elevation index */
+ const int16_t el_alph, /* i : number of elevation symbols */
+ const int16_t el_alph_proj /* i : size of projected alphabet */
+);
+
+/*! r: projected index in channel mode */
+int16_t ivas_chan_project_elevation_index(
+ const int16_t el_idx, /* i : elevation index */
+ const int16_t el_alph, /* i : number of elevation symbols */
+ const int16_t el_alph_proj /* i : size of projected alphabet */
+);
+
+void ivas_dirac_param_est_enc(
+ DIRAC_ENC_HANDLE hDirAC,
+ IVAS_QDIRECTION *q_direction,
+ const uint8_t useLowerRes,
+ float *data_f[],
+ float **pp_fr_real,
+ float **pp_fr_imag,
+ const int16_t input_frame,
+ const IVAS_FORMAT ivas_format ,
+ const int16_t hodirac_flag,
+ const int16_t nchan_fb_in,
+ int16_t *mono_frame_count,
+ int16_t *dirac_mono_flag
+ );
+
+
+void ivas_sba_config(
+ const int32_t sba_total_brate, /* i : SBA total bitrate */
+ int16_t sba_order, /* i : Ambisonic (SBA) order */
+ int16_t nb_channels, /* i : Number of Ambisonic (SBA) channels */
+ int16_t *nchan_transport, /* o : number of transport channels */
+ const int16_t sba_planar, /* i : SBA planar flag */
+ int16_t *nSCE, /* o : number of SCEs */
+ int16_t *nCPE, /* o : number of CPEs */
+ int16_t *element_mode /* o : element mode of the core coder */
+);
+
+void ivas_sba_set_cna_cng_flag(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+ivas_error ivas_sba_dec_reconfigure(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ uint16_t *nSamplesFlushed, /* o : number of samples flushed */
+ int16_t *data /* o : output synthesis signal */
+);
+
+ivas_error ivas_sba_digest_tc(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t nCldfbSlots, /* i : number of CLDFB slots */
+ const int16_t nSamplesForRendering, /* i : number of samples provided */
+ float *data[] /* i : transport channel samples */
+);
+
+void ivas_init_dec_get_num_cldfb_instances(
+ Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
+ int16_t *numCldfbAnalyses, /* o : number of CLDFB analysis instances */
+ int16_t *numCldfbSyntheses /* o : number of CLDFB synthesis instances */
+);
+
+ivas_error ivas_cldfb_dec_reconfig(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */
+ int16_t numCldfbAnalyses_old, /* i : number of CLDFB analysis instances in previous frame */
+ const int16_t numCldfbSyntheses_old /* i : number of CLDFB synthesis instances in previous frame */
+);
+
+/*! r: Ambisonic (SBA) order */
+int16_t ivas_sba_get_order(
+ const int16_t nb_channels, /* i : Number of ambisonic channels */
+ const int16_t sba_planar /* i : SBA planar flag */
+);
+
+/*! r: Ambisonic (SBA) order used for analysis and coding */
+int16_t ivas_sba_get_analysis_order(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+);
+
+/*! r: number of Ambisonic channels */
+int16_t ivas_sba_get_nchan(
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int16_t sba_planar /* i : SBA planar flag */
+);
+
+/*! r: number of ambisonics metadata channels */
+int16_t ivas_sba_get_nchan_metadata(
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+void ivas_sba_get_spar_hoa_ch_ind(
+ const int16_t num_md_chs, /* i : number of MD channels */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ int16_t HOA_md_ind[IVAS_SPAR_MAX_CH]
+);
+
+/*! r: flag indicating to code SPAR HOA MD for all bands */
+void ivas_sba_get_spar_hoa_md_flag(
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ int16_t *spar_hoa_md_flag,
+ int16_t *spar_hoa_dirac2spar_md_flag
+);
+
+void ivas_sba_zero_vert_comp(
+ float *sba_data[], /* i : SBA signals */
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int16_t sba_planar, /* i : SBA planar flag */
+ const int16_t input_frame /* i : input frame length */
+);
+
+void ivas_sba_getTCs(
+ float *sba_data[], /* i : SBA signals */
+ Encoder_Struct *st_ivas, /* i/o: Encoder struct */
+ const int16_t input_frame /* i : frame length */
+);
+
+/*! r: SBA DirAC stereo flag */
+int16_t ivas_sba_remapTCs(
+ float *sba_data[], /* i/o: SBA signals */
+ Decoder_Struct *st_ivas, /* i/o: decoder struct */
+ const int16_t output_frame /* i : frame length */
+);
+
+void ivas_sba_dirac_stereo_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output[CPE_CHANNELS], /* o : output synthesis signal */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t mcmasa /* i : McMASA flag */
+);
+
+void ivas_sba_dirac_stereo_config(
+ STEREO_DFT_CONFIG_DATA_HANDLE hConfig /* o : DFT stereo configuration */
+);
+
+/*! r: HO-DirAC flag */
+int16_t ivas_get_hodirac_flag(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+);
+
+int16_t ivas_get_sba_dirac_stereo_flag(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_sba_dirac_stereo_smooth_parameters(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */
+ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD handle for upmixing */
+ const int16_t cross_fade_start_offset, /* i : SPAR mixer delay compensation */
+ const int32_t output_Fs, /* i : Fs for delay calculation */
+ const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix */
+);
+
+void ivas_sba2mc_cldfb(
+ IVAS_OUTPUT_SETUP hInSetup, /* i : Format of input layout */
+ float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb real part */
+ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part */
+ const int16_t nb_channels_out, /* i : nb of output channels */
+ const int16_t nb_bands, /* i : nb of CLDFB bands to process */
+ const int16_t nb_timeslots, /* i : number of time slots to process */
+ const float *hoa_dec_mtx /* i : HOA decoding mtx */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * DirAC prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_dirac_enc_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+ivas_error ivas_dirac_enc_reconfigure(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+void ivas_dirac_enc_close(
+ DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */
+ const int32_t input_Fs /* i : input sampling_rate */
+);
+
+ivas_error ivas_dirac_enc(
+ 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 */
+ float *data_f[], /* i/o: SBA channels */
+ float **ppIn_FR_real, /* o : real freq domain values */
+ float **ppIn_FR_imag, /* o : imag freq domain values */
+ const int16_t input_frame, /* i : input frame length */
+ const int16_t dtx_vad, /* i : DTX vad flag */
+ const IVAS_FORMAT ivas_format, /* i : ivas format */
+ const int16_t hodirac_flag /* i : hodirac flag */
+);
+
+ivas_error ivas_dirac_config(
+ void *st_ivas, /* i/o: IVAS encoder/decoder state structure */
+ const int16_t enc_dec /* i : encoder or decoder flag */
+);
+
+void ivas_dirac_config_bands(
+ int16_t *band_grouping, /* o : band grouping */
+ const int16_t nbands, /* i : number of bands */
+ const int16_t max_band, /* i : maximal band index +1 */
+ int16_t *dirac_to_spar_md_bands, /* o : mapping of DirAC parameter band index to SPAR FB band index */
+ const int8_t useLowerBandRes, /* i : flag indicating lower band resolution for DirAC */
+ const int16_t enc_param_start_band, /* i : band index of first DirAC parameter band */
+ IVAS_FB_MIXER_HANDLE hFbMdft
+);
+
+void ivas_get_dirac_sba_max_md_bits(
+ const int32_t sba_total_brate,
+ int16_t *bits_frame_nominal,
+ int16_t *metadata_max_bits,
+ int16_t *qmetadata_max_bit_req,
+ const int16_t nbands
+);
+
+ivas_error ivas_dirac_sba_config(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ int16_t *element_mode, /* o : element mode of the core coder */
+ int32_t sba_total_brate, /* i : SBA total bitrate */
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int16_t nbands /* i : number of frequency bands */
+);
+
+ivas_error ivas_dirac_dec_config(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const DIRAC_CONFIG_FLAG flag_configopen /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
+);
+
+void ivas_dirac_dec_close(
+ DIRAC_DEC_HANDLE *hDirAC_out
+);
+
+void ivas_dirac_dec_read_BS(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ Decoder_State *st, /* i/o: decoder Core state structure */
+ DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q metadata */
+ int16_t *nb_bits, /* o : number of bits read */
+ const int16_t last_bit_pos, /* i : last read bitstream position */
+ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
+ int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */
+);
+
+void generate_masking_noise_lb_dirac(
+ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
+ float *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */
+ const int16_t nCldfbTs, /* i : number of CLDFB slots that will be rendered */
+ const int16_t cna_flag /* i : CNA flag for LB and HB */
+);
+
+void ivas_dirac_dec_set_md_map(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nCldfbTs /* i : number of CLDFB time slots */
+);
+
+void ivas_dirac_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t num_subframes /* i : number of subframes to render */
+);
+
+void ivas_dirac_dec_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
+ uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
+ uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
+ float *output_f[] /* o : rendered time signal */
+);
+
+void ivas_dirac_dec_render_sf(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ float *pppQMfFrame_ts_re[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX],
+ float *pppQMfFrame_ts_im[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX]
+);
+
+ivas_error ivas_td_decorr_reconfig_dec(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate, /* i : total IVAS bitrate */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int32_t output_Fs, /* i : output sampling rate */
+ ivas_td_decorr_state_t **hTdDecorr, /* i/o: TD decorrelator handle */
+ uint16_t *useTdDecorr /* i/o: TD decorrelator flag */
+);
+
+void computeDiffuseness_mdft(
+ float **buffer_intensity[DIRAC_NUM_DIMS],
+ const float *buffer_energy,
+ const int16_t num_freq_bands,
+ const uint16_t no_col_avg_diff,
+ float *diffuseness
+);
+
+void computeDirectionVectors(
+ float *intensity_real_x,
+ float *intensity_real_y,
+ float *intensity_real_z,
+ const int16_t enc_param_start_band,
+ const int16_t num_frequency_bands,
+ float *direction_vector_x,
+ float *direction_vector_y,
+ float *direction_vector_z
+);
+
+void computeDiffuseness(
+ float *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF],
+ const float *buffer_energy,
+ const int16_t num_freq_bands,
+ float *diffuseness
+);
+
+
+void ivas_dirac_dec_get_response(
+ const int16_t azimuth,
+ const int16_t elevation,
+ float *response,
+ const int16_t ambisonics_order
+);
+
+void calculate_hodirac_sector_parameters(
+ DIRAC_ENC_HANDLE hDirAC,
+ float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */
+ float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector, imaginary part */
+ const float beta, /* i : forgetting factor for average filtering */
+ const int16_t *band_grouping, /* i : indices of band groups */
+ const int16_t N_bands, /* i : number of bands (groups) */
+ const int16_t enc_param_start_band, /* i : first band to process */
+ float *azi, /* o : array of sector azimuth angles, flat */
+ float *ele, /* o : array of sector elevation angles, flat */
+ float *diff, /* o : array of sector diffuseness values, flat */
+ float *ene /* o : array of sector energy values, flat */
+);
+
+void ivas_mc_paramupmix_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */
+ BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */
+ float *data_f[], /* i/o: input/transport MC data */
+ const int16_t input_frame /* i : input frame length */
+);
+
+ivas_error ivas_mc_paramupmix_enc_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+void ivas_mc_paramupmix_enc_close(
+ MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */
+ const int32_t input_Fs /* i : input sampling rate */
+);
+
+void ivas_mc_paramupmix_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */
+);
+
+ivas_error ivas_mc_paramupmix_dec_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_mc_paramupmix_dec_close(
+ MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out /* i/o: Parametric MC decoder handle */
+);
+
+void ivas_mc_paramupmix_dec_read_BS(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ Decoder_State *st, /* i/o: decoder state structure */
+ MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */
+ int16_t *nb_bits /* o : number of bits written */
+);
+
+void ivas_mc_paramupmix_dec_digest_tc(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */
+ const int16_t nSamplesForRendering /* i : number of samples provided */
+);
+
+void ivas_mc_paramupmix_dec_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
+ uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
+ uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
+ float *input_f[], /* i : core-coder transport channels */
+ float *output_f[] /* i/o: synthesized core-coder transport channels */
+);
+
+void ivas_param_mc_metadata_open(
+ const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
+ const int16_t lfe_index, /* i : channel index of LFE */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */
+);
+
+void ivas_param_mc_set_coded_bands(
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */
+);
+
+void ivas_param_mc_metadata_close(
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */
+);
+
+void ivas_param_mc_create_full_icc_mapping(
+ const int16_t n_channels, /* i : number of channels with LFE for the internal setup */
+ const int16_t lfe_index, /* i : channel index of the LFE */
+ int16_t *icc_map[2], /* o : map of all possible ICCs */
+ int16_t *icc_map_size_full /* o : number of all possible ICCs */
+);
+
+/*! r: number of IVAS transport channels */
+int16_t ivas_param_mc_getNumTransportChannels(
+ const int32_t ivas_total_bitrate, /* i : IVAS total bitrate */
+ const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */
+);
+
+ivas_error ivas_param_mc_enc_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+ivas_error ivas_param_mc_enc_reconfig(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+void ivas_param_mc_enc_close(
+ PARAM_MC_ENC_HANDLE *hParamMC, /* i/o: Parametric MC encoder handle */
+ const int32_t input_Fs /* i : input sampling rate */
+);
+
+void ivas_param_mc_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */
+ BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */
+ float *data_f[], /* i/o: input/transport MC data */
+ const int16_t input_frame /* i : input frame length */
+);
+
+ivas_error ivas_param_mc_dec_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+ivas_error ivas_param_mc_dec_reconfig(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_param_mc_dec_close(
+ PARAM_MC_DEC_HANDLE *hParamMC /* i/o: Parametric MC decoder handle */
+);
+
+void ivas_param_mc_dec_read_BS(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ Decoder_State *st, /* i/o: decoder state structure */
+ PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder ParamMC handle */
+ int16_t *nb_bits /* o : number of bits written */
+);
+
+void ivas_param_mc_dec_digest_tc(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */
+ float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output*/
+);
+
+void ivas_param_mc_dec_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
+ uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
+ uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
+ float *output_f[] /* o : rendered time signal */
+);
+
+void ivas_param_mc_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */
+);
+
+void ivas_param_mc_default_icc_map(
+ const PARAM_MC_ICC_MAPPING * hIccMapping, /* i : handle to ICC mapping configuration */
+ int16_t icc_map[PARAM_MC_SZ_ICC_MAP][2] /* o : copy of map from the configuration */
+);
+
+/*! r: number of cldfb synthesis instances */
+int16_t param_mc_get_num_cldfb_syntheses(
+ Decoder_Struct *st_ivas /* i : IVAS decoder structure */
+);
+
+/*! r: index into the ParamMC configuration tables */
+uint16_t ivas_param_mc_get_configuration_index(
+ const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
+ const int32_t ivas_total_brate /* i : total bitrate */
+);
+
+int16_t matrix_product(
+ const float *X, /* i : left hand matrix */
+ const int16_t rowsX, /* i : number of rows of the left hand matrix */
+ const int16_t colsX, /* i : number of columns of the left hand matrix */
+ const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
+ const float *Y, /* i : right hand matrix */
+ const int16_t rowsY, /* i : number of rows of the right hand matrix */
+ const int16_t colsY, /* i : number of columns of the right hand matrix */
+ const int16_t transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
+ float *Z /* o : resulting matrix after the matrix multiplication */
+);
+
+void mat2svdMat(
+ const float *mat, /* i : matrix as column ordered vector */
+ float svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry */
+ const int16_t nRows, /* i : number of rows of the matrix */
+ const int16_t mCols, /* i : number of columns of the matrix */
+ const int16_t transpose /* i : flag indication transposition */
+);
+
+void svdMat2mat(
+ float svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry */
+ float *mat, /* o : matrix as column ordered vector */
+ const int16_t nRows, /* i : number of rows of the matrix */
+ const int16_t mCols /* i : number of columns of the matrix */
+);
+
+int16_t matrix_diag_product(
+ const float *X, /* i : left hand matrix */
+ const int16_t rowsX, /* i : number of rows of the left hand matrix */
+ const int16_t colsX, /* i : number of columns of the left hand matrix */
+ const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
+ const float *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements */
+ const int16_t entriesY, /* i : number of entries in the diagonal */
+ float *Z /* o : resulting matrix after the matrix multiplication */
+);
+
+int16_t diag_matrix_product(
+ const float *Y, /* i : left hand diagonal matrix as vector containing the diagonal elements */
+ const int16_t entriesY, /* i : length of the diagonal of the left hand matrix */
+ const float *X, /* i : right hand matrix */
+ const int16_t rowsX, /* i : number of rows of the right hand matrix */
+ const int16_t colsX, /* i : number of columns of the right hand matrix */
+ const int16_t transpX, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
+ float *Z /* o : resulting matrix after the matrix multiplication */
+);
+
+int16_t matrix_product_diag(
+ const float *X, /* i : left hand matrix */
+ const int16_t rowsX, /* i : number of rows of the left hand matrix */
+ const int16_t colsX, /* i : number of columns of the left hand matrix */
+ const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
+ const float *Y, /* i : right hand matrix */
+ const int16_t rowsY, /* i : number of rows of the right hand matrix */
+ const int16_t colsY, /* i : number of columns of the right hand matrix */
+ const int16_t transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
+ float *Z /* o : resulting matrix after the matrix multiplication */
+);
+
+void cmplx_matrix_square(
+ const float *realX, /* i : real part of the matrix */
+ const float *imagX, /* i : imaginary part of the matrix */
+ const int16_t mRows, /* i : number of rows of the matrix */
+ const int16_t nCols, /* i : number of columns of the matrix */
+ float *realZ, /* o : real part of the resulting matrix */
+ float *imagZ /* o : imaginary part of the resulting matrix */
+);
+
+int16_t computeMixingMatrices(
+ const int16_t num_inputs, /* i : number of input channels */
+ const int16_t num_outputs, /* i : number of output channels */
+ const float *Cx, /* i : input channel covariance matrix */
+ const float *Cy, /* i : target covariance matrix */
+ const float *Q, /* i : prototype matrix (usually a upmix matrix) */
+ const int16_t energy_compensation_flag, /* i : flag indicating that the energy compensation should be performed (i.e. no residual mixing matrix will follow) */
+ const float reg_Sx, /* i : regularization factor for the input channel singular values */
+ const float reg_ghat, /* i : regularization factor for the normalization matrix */
+ float *mixing_matrix, /* o : resulting mixing matrix */
+ float *Cr /* o : residual covariance matrix */
+);
+
+int16_t computeMixingMatricesResidual(
+ const int16_t num_outputs, /* i : number of output channels */
+ const float *Cx, /* i : vector containing the diagonal diffuse prototype covariance */
+ const float *Cy, /* i : matrix containing the missing cov (Cr from computeMixingMatrices()) */
+ const float reg_Sx, /* i : regularization factor for the input channel singular values */
+ const float reg_ghat, /* i : regularization factor for the normalization matrix */
+ float *mixing_matrix /* o : resulting residual mixing matrix */
+);
+
+/*! r: error or success */
+int16_t svd(
+ float InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */
+ float singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) */
+ float singularValues[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) */
+ float singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) */
+ const int16_t nChannelsL, /* i : number of rows in the matrix to be decomposed */
+ const int16_t nChannelsC /* i : number of columns in the matrix to be decomposed */
+);
+
+ivas_error ivas_dirac_dec_output_synthesis_cov_open(
+ DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */
+ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: handle for the covariance synthesis state */
+ const int16_t max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */
+ const int16_t interp_length, /* i : length for interpolating the mixing matrices in time slots */
+ const int16_t num_param_bands, /* i : number of parameter bands */
+ const int16_t num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */
+ const int16_t nchan_in, /* i : number of input (transport) channels */
+ const int16_t nchan_out, /* i : number of output channels */
+ const float *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */
+);
+
+void ivas_dirac_dec_output_synthesis_get_interpolator(
+ DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */
+ const uint16_t interp_length /* i : interpolator length */
+);
+
+void ivas_dirac_dec_output_synthesis_cov_init(
+ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */
+ const int16_t nchan_in, /* i : number of input (tranport) channels */
+ const int16_t nchan_out, /* i : number of output channels */
+ const int16_t n_param_bands, /* i : number of total parameter bands */
+ const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */
+);
+
+void ivas_dirac_dec_output_synthesis_cov_close(
+ DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */
+ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state /* i/o: handle for the covariance synthesis state */
+);
+
+void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot(
+ float *RealBuffer, /* i : input channel filter bank samples (real part) */
+ float *ImagBuffer, /* i : input channel filter bank samples (imaginary part */
+ float cx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */
+ float cx_imag[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */
+ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */
+ const int16_t nchan_in /* i : number of input channels */
+);
+
+void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot(
+ float *Cldfb_RealBuffer_in, /* i : input channel filter bank samples (real part) */
+ float *Cldfb_ImagBuffer_in, /* i : input channel filter bank samples (imaginary part) */
+ float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) */
+ float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) */
+ float *mixing_matrix[], /* i : parameter band wise mixing matrices (direct part) */
+ float *mixing_matrix_res[], /* i : parameter band wise mixing matrices (residual part) */
+ const uint16_t slot_idx_sfr, /* i : time slot index for the current slot within the current subframe */
+ const uint16_t slot_idx_tot, /* i : time slot index for the current slot within the frame */
+ const int16_t nX, /* i : number of input channels */
+ const int16_t nY, /* i : number of output channels */
+ PARAM_MC_DEC_HANDLE hParamMC /* i : handle to the Parametric MC decoder state */
+);
+
+int16_t computeMixingMatricesISM(
+ const int16_t num_inputs,
+ const int16_t num_responses,
+ const int16_t num_outputs,
+ const float *responses,
+ const float *ener,
+ const float *Cx_diag,
+ const float *Cy_diag,
+ const float *Q,
+ const int16_t energy_compensation_flag,
+ const float reg_Sx,
+ const float reg_ghat,
+ float *mixing_matrix
+);
+
+void FdCngEncodeDiracMDCTStereoSID(
+ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder state structure */
+);
+
+void FdCngDecodeDiracMDCTStereoSID(
+ CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * SPAR prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_spar_enc_open(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */
+ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */
+);
+
+void ivas_spar_enc_close(
+ SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */
+ const int32_t input_Fs, /* i : input sampling rate */
+ const int16_t nchan_inp, /* i : number of input channels */
+ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */
+);
+
+ivas_error ivas_spar_enc(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ float *data_f[], /* i/o: input/transport audio channels */
+ const int16_t input_frame, /* i : input frame length */
+ int16_t *nb_bits_metadata, /* i : number of MD bits written */
+ BSTR_ENC_HANDLE hMetaData /* o : MetaData handle */
+);
+
+ivas_error ivas_spar_dec_open(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */
+);
+
+void ivas_spar_dec_close(
+ SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */
+);
+
+ivas_error ivas_spar_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */
+ int16_t *nb_bits_read /* o : number of MD bits read */
+);
+
+void ivas_spar_config(
+ int32_t ivas_total_brate, /* i : codec total bitrate */
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ int16_t *nchan_transport, /* o : number of transport channels */
+ int16_t *nSCE, /* o : number of SCEs */
+ int16_t *nCPE, /* o : number of CPEs */
+ int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */
+ const int16_t sid_format /* i : IVAS format indicator from SID frame */
+);
+
+ivas_error ivas_sba_upmixer_renderer(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */
+ float *output[], /* i/o: transport/output audio channels */
+ const int16_t output_frame /* i : output frame length */
+);
+
+ivas_error ivas_sba_linear_renderer(
+ float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t nchan_in, /* i : number of input ambisonics channels */
+ const int16_t nchan_ism, /* i : number of objects */
+ const AUDIO_CONFIG output_config, /* i : output audio configuration */
+ const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */
+);
+
+void ivas_sba_mix_matrix_determiner(
+ SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */
+ float *output[], /* i/o: transport/output audio channels */
+ const int16_t bfi, /* i : BFI flag */
+ const int16_t nchan_remapped, /* i : num channels after remapping of TCs */
+ const int16_t output_frame, /* i : output frame length */
+ const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix */
+);
+
+/* AGC */
+/*! r: AGC enable flag */
+int16_t ivas_agc_enc_get_flag(
+ const int16_t nchan_transport /* i : number of transport channels */
+);
+
+ivas_error ivas_spar_agc_enc_open(
+ ivas_agc_enc_state_t **hAgcEnc, /* i/o: AGC decoder handle */
+ const int32_t input_Fs, /* i : input sampling rate */
+ const int16_t nchan_inp /* i : number of input channels */
+);
+
+void ivas_spar_agc_enc_close(
+ ivas_agc_enc_state_t **hAgcEnc /* i/o: AGC encoder handle */
+);
+
+void ivas_agc_enc_process(
+ ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */
+ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */
+ float **ppPcm_in, /* i : input audio channels */
+ float **ppPcm_out, /* o : output audio channels */
+ const int16_t n_channels, /* i : number of channels */
+ const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */
+);
+
+ivas_error ivas_spar_agc_dec_open(
+ ivas_agc_dec_state_t **hAgcDec, /* i/o: AGC decoder handle */
+ const int32_t output_Fs /* i : output sampling rate */
+);
+
+void ivas_spar_agc_dec_close(
+ ivas_agc_dec_state_t **hAgcDec /* i/o: AGC decoder handle */
+);
+
+ivas_error ivas_spar_md_enc_init
+(
+ ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */
+ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+);
+
+void ivas_agc_dec_process(
+ ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */
+ float *pcm_in[], /* i : input audio channels */
+ float *pcm_out[], /* o : output audio channels */
+ const int16_t n_channels, /* i : number of channels */
+ const int16_t output_Fs /* i : output sampling rate */
+);
+
+void ivas_agc_read_bits(
+ ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */
+ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/
+ const int16_t n_channels, /* i : number of channels */
+ const int16_t AGC_flag /* i : AGC on/off flag */
+);
+
+void ivas_agc_initWindowFunc(
+ float *pWinFunc,
+ const int16_t length
+);
+
+void ivas_agc_calcGainParams(
+ uint16_t *absEmin,
+ uint16_t *betaE,
+ uint16_t *maxAttExp,
+ const int16_t numCoeffs
+);
+
+float ivas_get_mdct_scaling_gain(
+ const int16_t dct_len_by_2
+);
+
+void ivas_get_twid_factors(
+ const int16_t length,
+ const float **pTwid_re,
+ const float **pTwid_im
+);
+
+int16_t ivas_get_bw_idx_from_sample_rate(
+ const int32_t sampling_rate /* i : sampling rate */
+);
+
+/*! r: config. table index */
+int16_t ivas_get_spar_table_idx(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order, /* i : IVAS SBA order */
+ const int16_t bwidth, /* i : audio bandwidth */
+ int16_t *bitlen, /* o : number of bits */
+ int16_t *ind /* o : indice */
+);
+
+/*! r: number of transport channels */
+int16_t ivas_get_sba_num_TCs(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order /* i : IVAS SBA order */
+);
+
+void ivas_spar_set_bitrate_config(
+ ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */
+ const int16_t table_idx, /* i : config. table index */
+ const int16_t num_bands, /* i : number of bands */
+ const int16_t dirac2spar_md_flag,
+ const int16_t enc_flag,
+ const int16_t pca_flag,
+ const int16_t agc_flag
+);
+
+void ivas_spar_bitrate_dist(
+ int32_t core_brates_act[], /* o : bitrates per core-coder */
+ const int16_t nAvailBits, /* i : number of available bits */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int16_t bwidth /* i : audio bandwidth */
+);
+
+void ivas_mdct(
+ const float *pIn,
+ float *pOut,
+ const int16_t length
+);
+
+void ivas_dct_windowing(
+ const int16_t fade_len,
+ const int16_t full_len,
+ const int16_t dct_len,
+ const int16_t zero_pad_len,
+ const float *pWindow_coeffs,
+ const int16_t frame_len,
+ float *pOut_buf,
+ float *pBuffer_prev,
+ float *pTemp_lfe
+);
+
+void ivas_tda(
+ const float *pIn,
+ float *pOut,
+ const int16_t length
+);
+
+void ivas_imdct(
+ const float *pIn,
+ float *pOut,
+ const int16_t length
+);
+
+void ivas_itda(
+ const float *re,
+ float *pOut,
+ const int16_t length
+);
+
+void ivas_spar_get_cldfb_gains(
+ SPAR_DEC_HANDLE hSpar,
+ HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0,
+ HANDLE_CLDFB_FILTER_BANK cldfbSynDec0,
+ const DECODER_CONFIG_HANDLE hDecoderConfig
+);
+
+/*! r: 1 if prediction residual channel */
+int16_t ivas_is_res_channel(
+ const int16_t ch, /* i : ch index in WYZX ordering */
+ const int16_t nchan_transport /* i : number of transport channels (1-4) */
+);
+
+void ivas_spar_dec_agc_pca(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ float *output[], /* i/o: input/output audio channels */
+ const int16_t output_frame /* i : output frame length */
+);
+
+void ivas_spar_dec_set_render_map(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nCldfbTs /* i : number of CLDFB time slots */
+);
+
+void ivas_spar_dec_set_render_params(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const int16_t n_cldfb_slots /* i : number of cldfb slots in this frame */
+);
+
+void ivas_spar_dec_digest_tc(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t nCldfbSlots, /* i : number of CLDFB slots */
+ const int16_t nSamplesForRendering /* i : number of samples provided */
+);
+
+void ivas_sba_dec_digest_tc(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const int16_t nCldfbSlots, /* i : number of CLDFB slots */
+ const int16_t nSamplesForRendering /* i : number of samples provided */
+);
+
+ivas_error ivas_sba_dec_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
+ uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
+ uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
+ float *output_f[] /* o : rendered time signal */
+);
+
+void ivas_spar_dec_upmixer_sf(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ float *output[], /* o : output audio channels */
+ const int16_t nchan_internal /* i : number of internal channels */
+);
+
+void ivas_spar_dec_upmixer(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ float *output[], /* i/o: input/output audio channels */
+ const int16_t nchan_internal, /* i : number of internal channels */
+ const int16_t output_frame /* i : output frame length */
+);
+
+/* MD module */
+ivas_error ivas_spar_md_enc_open(
+ ivas_spar_md_enc_state_t **hMdEnc, /* i/o: SPAR MD encoder handle */
+ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+);
+
+void ivas_spar_md_enc_close(
+ ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */
+);
+
+ivas_error ivas_spar_md_enc_process(
+ ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */
+ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */
+ const int16_t dtx_vad,
+ const int16_t nchan_inp,
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */
+ const int16_t dyn_active_w_flag, /* i : flag to indicate dynamic active W */
+ const int16_t dirac_mono_flag /* i : flag to indicate mono only mode in SBA */
+);
+
+void ivas_compute_spar_params(
+ float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ const int16_t i_ts,
+ float ***mixer_mat,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t dtx_vad,
+ const int16_t num_ch,
+ const int16_t bands_bw,
+ const int16_t active_w,
+ const int16_t active_w_vlbr,
+ ivas_spar_md_com_cfg *hSparCfg,
+ ivas_spar_md_t *hSparMd,
+ float *pWscale,
+ const int16_t from_dirac,
+ const int16_t dyn_active_w_flag
+);
+
+void ivas_create_fullr_dmx_mat(
+ float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ float ***mixer_mat,
+ const int16_t in_chans,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t active_w,
+ ivas_spar_md_com_cfg *hMdCfg
+);
+
+void ivas_calc_c_p_coeffs(
+ ivas_spar_md_t *pSparMd,
+ float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ const int16_t i_ts,
+ float ***mixer_mat,
+ const int16_t num_ch,
+ const int16_t num_dmx,
+ const int16_t band_idx,
+ const int16_t dtx_vad,
+ const int16_t compute_p_flag,
+ const int16_t dyn_active_w_flag
+);
+
+void ivas_get_spar_md_from_dirac(
+ float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES],
+ float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES],
+ float diffuseness[IVAS_MAX_NUM_BANDS],
+ const int16_t n_ts,
+ float ***mixer_mat,
+ ivas_spar_md_t *hSpar_md,
+ ivas_spar_md_com_cfg *hSpar_md_cfg,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t order,
+ const int16_t dtx_vad,
+ float Wscale_d[IVAS_MAX_NUM_BANDS],
+ const uint8_t useLowerRes,
+ const int16_t active_w_vlbr,
+ const int16_t dyn_active_w_flag
+);
+
+/*! r: number of MD subframes */
+int16_t ivas_get_spar_dec_md_num_subframes(
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int32_t ivas_last_active_brate /* i : IVAS last active bitrate */
+);
+
+ivas_error ivas_spar_md_dec_matrix_open(
+ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */
+ const int16_t num_channels, /* i : number of internal channels */
+ const int16_t num_md_sub_frames
+);
+
+void ivas_spar_md_dec_matrix_close(
+ ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */
+ const int16_t num_channels /* i : number of internal channels */
+);
+
+ivas_error ivas_spar_md_dec_open(
+ ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */
+ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */
+ const int16_t num_channels, /* i : number of internal channels */
+ const int16_t sba_order, /* i : SBA order */
+ const int16_t sid_format, /* i : SID format */
+ const int32_t last_active_ivas_total_brate /* i : IVAS last active bitrate */
+);
+
+void ivas_spar_md_dec_close(
+ ivas_spar_md_dec_state_t **hMdDec /* i/o: SPAR MD decoder handle */
+);
+
+void ivas_spar_get_parameters(
+ SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */
+ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */
+ const int16_t ts, /* i : time slot index */
+ const int16_t num_ch_out, /* i : number of channels out */
+ const int16_t num_ch_in, /* i : number of channels in */
+ const int16_t num_spar_bands, /* i : number of SPAR bands */
+ float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */
+);
+
+ivas_error ivas_spar_md_dec_init(
+ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */
+ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */
+ const int16_t num_channels, /* i : number of internal channels */
+ const int16_t sba_order /* i : SBA order */
+);
+
+void ivas_spar_md_dec_process(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/
+ const int16_t num_bands_out, /* i : number of output bands */
+ const int16_t sba_order /* i : SBA order */
+);
+
+void ivas_spar_to_dirac(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */
+ const int16_t dtx_vad, /* i : DTX frame flag */
+ const int16_t num_bands_out, /* i : number of output bands */
+ const int16_t bw, /* i : band joining factor */
+ const int16_t dyn_active_w_flag /* i : dynamic active W flag */
+);
+
+void ivas_spar_update_md_hist(
+ ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */
+);
+
+int16_t ivas_spar_chk_zero_coefs(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
+);
+
+void ivas_spar_smooth_md_dtx(
+ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */
+ const int16_t num_bands_out, /* i : number of output bands */
+ const int16_t num_md_sub_frames /* i : number of metadata subframes */
+);
+
+void ivas_spar_setup_md_smoothing(
+ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */
+ const int16_t num_bands_out, /* i : number of output bands */
+ const int16_t num_md_sub_frames /* i : number of metadata subframes */
+);
+
+void ivas_spar_dec_gen_umx_mat(
+ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t num_bands_out, /* i : number of output bands */
+ const int16_t bfi, /* i : bad frame indicator */
+ const int16_t num_md_sub_frames
+);
+
+/* Covariance module */
+ivas_error ivas_spar_covar_enc_open(
+ ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */
+ ivas_filterbank_t *pFb, /* i/o: FB handle */
+ const int32_t input_Fs, /* i : input sampling rate */
+ const int16_t nchan_inp, /* i : number of input channels */
+ const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+void ivas_spar_covar_enc_close(
+ ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */
+ const int16_t nchan_inp /* i : number of input channels */
+);
+
+void ivas_enc_cov_handler_process(
+ ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */
+ float **ppIn_FR_real,
+ float **ppIn_FR_imag,
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ ivas_filterbank_t *pFb, /* i/o: FB handle */
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t nchan_inp,
+ const int16_t dtx_vad,
+ const int16_t transient_det[2],
+ const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH],
+ int16_t *res_ind,
+ const int16_t *remix_order,
+ int16_t *dyn_active_w_flag,
+ const int16_t nchan_transport,
+ const int16_t is_sba
+);
+
+ivas_error ivas_spar_covar_smooth_enc_open(
+ ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */
+ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */
+ ivas_filterbank_t *pFb, /* i/o: FB handle */
+ const int16_t nchan_inp, /* i : number of input channels */
+ const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+void ivas_spar_covar_smooth_enc_close(
+ ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */
+ const int16_t nchan_inp /* i : number of input channels */
+);
+
+void ivas_cov_smooth_process(
+ ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ ivas_filterbank_t *pFb, /* i/o: FB handle */
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t num_ch,
+ const int16_t transient_det[2]
+);
+
+/* Transient detector module */
+ivas_error ivas_transient_det_open(
+ ivas_trans_det_state_t **hTranDet, /* i/o: Transient detector handle */
+ const int32_t sampling_rate /* i : sampling rate */
+);
+
+void ivas_transient_det_close(
+ ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */
+);
+
+void ivas_transient_det_process(
+ ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */
+ float *pIn_pcm, /* i : input audio channels */
+ const int16_t frame_len, /* i : frame length in samples */
+ int16_t transient_det[2] /* o : transient det outputs */
+);
+
+void ivas_td_decorr_get_ducking_gains(
+ ivas_trans_det_state_t *hTranDet, /* i/o: Transient detector handle */
+ float *pIn_pcm,
+ float *pIn_duck_gains,
+ float *pOut_duck_gains,
+ const int16_t frame_len,
+ const int16_t tdet_flag
+);
+
+ivas_error ivas_td_decorr_dec_open(
+ ivas_td_decorr_state_t **hTdDecorr, /* i/o: TD decorrelator handle */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const int16_t nchan_internal, /* i : number of internal channels */
+ const int16_t ducking_flag /* i : ducking flag */
+);
+
+void ivas_td_decorr_dec_close(
+ ivas_td_decorr_state_t **hTdDecorr /* i/o: TD decorrelator handle */
+);
+
+void ivas_td_decorr_process(
+ ivas_td_decorr_state_t *hTdDecorr, /* i/o: SPAR Covar. decoder handle */
+ float *pcm_in[], /* i : input audio channels */
+ float **ppOut_pcm, /* o : output audio channels */
+ const int16_t output_frame /* i : output frame length */
+);
+
+void ivas_td_decorr_APD_iir_filter(
+ ivas_td_decorr_APD_filt_state_t *filter_state,
+ float *pIn_out,
+ const int16_t num_APD_sections,
+ const int16_t length
+);
+
+#define IVAS_CMULT_FLOAT( in1_re, in1_im, in2_re, in2_im, out1_re, out1_im ) \
+ out1_re = ( in1_re * in2_re ) - ( in1_im * in2_im ); MAC(1); MULT(1); \
+ out1_im = ( in1_re * in2_im ) + ( in2_re * in1_im ); MAC(1); MULT(1);
+
+#define IVAS_CALCULATE_ABS( re, im, out ) \
+ out = (float) sqrt( ( re * re ) + ( im * im ) ); MAC(1); MULT(1); SQRT(1);
+
+#define IVAS_CALCULATE_RABS( re, out ) \
+ out = (float) sqrt( re * re ); MULT(1); SQRT(1);
+
+#define IVAS_CALCULATE_SQ_ABS( re, im, out ) \
+ out = (float) ( ( re * re ) + ( im * im ) ); MAC(1); MULT(1);
+
+#define IVAS_RMULT_DOUBLE( in1_re, in2_re, out1_re ) \
+ out1_re = ( in1_re * in2_re ); DMULT(1); \
+
+#define IVAS_CALCULATE_SQ_ABS_N( re, out ) \
+ out = (float) ( re * re ); MULT(1);
+
+#define IVAS_RMULT_FLOAT( in1_re, in2_re, out1_re ) \
+ out1_re = ( in1_re * in2_re ); MULT(1);
+
+
+/* PCA */
+void ivas_pca_enc_init(
+ PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */
+);
+
+void ivas_pca_enc(
+ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */
+ PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */
+ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */
+ float *data_f[8], /* i : input/transformed audio channels */
+ const int16_t input_frame, /* i : input frame length */
+ const int16_t n_channels /* i : number of channels */
+);
+
+void ivas_pca_read_bits(
+ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/
+ PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */
+);
+
+void ivas_pca_dec_init(
+ PCA_DEC_STATE *hPCA /* i/o: PCA decoder structure */
+);
+
+void ivas_pca_dec(
+ PCA_DEC_STATE *hPCA, /* i/o: PCA decoder structure */
+ const int16_t n_samples, /* i : output frame length */
+ const int16_t n_channels, /* i : number of channels */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int32_t last_ivas_total_brate, /* i : last IVAS total bitrate */
+ const int16_t bfi, /* i : bad frame indicator */
+ float *pcm_out[] /* o : output audio channels */
+);
+
+/* PCA utilities */
+void eye_matrix(
+ float *mat,
+ const int16_t n,
+ const float d
+);
+
+void cov_subfr(
+ float **ptr_sig,
+ float *r,
+ const int16_t n_channels,
+ const int16_t len
+);
+
+void eig_qr(
+ const float *A,
+ const int16_t num_iter,
+ float *EV, float *Vals,
+ const int16_t n
+);
+
+void exhst_4x4(
+ float *cost_mtx,
+ int16_t *path,
+ const int16_t maximize
+);
+
+float mat_det4(
+ const float *m
+);
+
+/* quaternion utilities */
+void mat2dquat(
+ const float *a,
+ float *ql,
+ float *qr
+);
+
+void dquat2mat(
+ const float *ql,
+ const float *qr,
+ float *m
+);
+
+void quat_shortestpath(
+ const float *q00,
+ float *q01,
+ const float *q10,
+ float *q11
+);
+
+void pca_interp_preproc(
+ const float *prev_ql,
+ const float *prev_qr,
+ const float *ql,
+ const float *qr,
+ const int16_t len,
+ float *ql_interp,
+ float *qr_interp
+);
+
+void pca_enc_s3(
+ float *q,
+ int32_t *index
+);
+
+void pca_dec_s3(
+ const int32_t index,
+ float *q
+);
+
+int16_t ivas_get_bits_to_encode(
+ int32_t val
+);
+
+void ivas_huffman_encode(
+ ivas_huffman_cfg_t *huff_cfg,
+ int16_t in,
+ int16_t *hcode,
+ int16_t *hlen
+);
+
+void ivas_spar_huff_coeffs_com_init(
+ ivas_huff_coeffs_t *pHuff_coeffs,
+ ivas_spar_md_com_cfg *pSpar_cfg,
+ const int16_t table_idx,
+ const int16_t enc_dec
+);
+
+void ivas_spar_arith_coeffs_com_init(
+ ivas_arith_coeffs_t *pArith_coeffs,
+ ivas_spar_md_com_cfg *pSpar_cfg,
+ const int16_t table_idx,
+ const int16_t enc_dec
+);
+
+int16_t ivas_arith_encode_cmplx_cell_array(
+ ivas_arith_t *pArith_re,
+ ivas_arith_t *pArith_re_diff,
+ const int16_t *pDo_diff,
+ const int16_t nB,
+ int16_t *pSymbol_re,
+ int16_t *pSymbol_old_re,
+ ivas_cell_dim_t *pCell_dims,
+ BSTR_ENC_HANDLE hMetaData,
+ const int16_t any_diff ,
+ const int16_t wc_strat_arith
+);
+
+ivas_error ivas_huffman_decode(
+ ivas_huffman_cfg_t *huff_cfg,
+ Decoder_State *st0,
+ int16_t *dec_out
+);
+
+void ivas_arith_decode_cmplx_cell_array(
+ ivas_arith_t *pArith_re,
+ ivas_arith_t *pArith_re_diff,
+ Decoder_State *st0,
+ ivas_cell_dim_t *pCell_dims,
+ int16_t *pDo_diff, const int16_t nB,
+ int16_t *pSymbol_re,
+ int16_t *pSymbol_re_old
+);
+
+void ivas_ari_start_decoding_14bits_ext_1_lfe(
+ Decoder_State *st,
+ Tastat *s,
+ int16_t *extra_bits_read
+);
+
+uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe(
+ Decoder_State *st, Tastat *s,
+ const uint16_t *cum_freq,
+ int16_t *extra_bits_read
+);
+
+void ivas_ari_done_decoding_14bits_ext_1_lfe(
+ Decoder_State *st,
+ const int16_t extra_bits_read
+);
+
+void ivas_ari_done_encoding_14bits(
+ BSTR_ENC_HANDLE hBstr, Tastat *s
+);
+
+void ivas_ari_encode_14bits_ext(
+ BSTR_ENC_HANDLE hBstr,
+ Tastat *s,
+ int32_t symbol,
+ const uint16_t *cum_freq
+);
+
+void ivas_wrap_arround(
+ int16_t *pArr,
+ const int16_t min_val,
+ const int16_t max_val,
+ const int16_t length
+);
+
+void ivas_get_cum_freq_model(
+ const int16_t *pFreq_model,
+ const int16_t length,
+ int16_t *pCum_freq_model
+);
+
+int16_t ivas_map_num_pred_r_to_idx(
+ const int16_t num_quant_points_pred_r,
+ const int16_t active_w_flag
+);
+
+int16_t ivas_map_num_drct_r_to_idx(
+ const int16_t num_quant_points_drct_r
+);
+
+int16_t ivas_map_num_decd_r_to_idx(
+ const int16_t num_quant_points_decd_r
+);
+
+/* Quantization utilities */
+void ivas_quantise_real_values(
+ const float *values,
+ const int16_t q_levels,
+ const float min_value,
+ const float max_value,
+ int16_t *index,
+ float *quant,
+ const int16_t dim
+);
+
+void ivas_spar_get_uniform_quant_strat(
+ ivas_spar_md_com_cfg *pSpar_md_com_cfg,
+ const int16_t table_idx
+);
+
+void ivas_spar_quant_dtx_init(
+ ivas_spar_md_t *spar_md,
+ float *min_max
+);
+
+void ivas_map_prior_coeffs_quant(
+ ivas_spar_md_prev_t *pSpar_md_prior,
+ ivas_spar_md_com_cfg *pSpar_md_cfg,
+ const int16_t qsi,
+ const int16_t nB
+);
+
+void ivas_copy_band_coeffs_idx_to_arr(
+ ivas_band_coeffs_ind_t *pBands_idx,
+ const int16_t nB,
+ int16_t *pSymbol_re,
+ ivas_cell_dim_t *pCell_dims,
+ const ivas_coeffs_type_t coeff_type
+);
+
+void ivas_clear_band_coeffs(
+ ivas_band_coeffs_t *pband_coeffs,
+ const uint16_t num_bands
+);
+
+void ivas_clear_band_coeff_idx(
+ ivas_band_coeffs_ind_t *pband_coeff_idx,
+ const uint16_t num_bands
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * MASA prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_masa_dec_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
+);
+
+void ivas_masa_dec_close(
+ MASA_DECODER_HANDLE *hMasa /* i/o: MASA metadata structure */
+);
+
+ivas_error ivas_masa_decode(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t *nb_bits_read /* o : number of bits read */
+);
+
+void generate_gridEq(
+ SPHERICAL_GRID_DATA *data /* o : data structure for grid */
+);
+
+ivas_error ivas_masa_enc_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+void ivas_masa_enc_close(
+ MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */
+);
+
+void ivas_masa_enc_reconfigure(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+ivas_error ivas_masa_dec_reconfigure(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */
+ int16_t *data /* o : output synthesis signal */
+);
+
+ivas_error ivas_masa_encode(
+ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */
+ int16_t *nb_bits_metadata, /* o : number of metadata bits written */
+ const int16_t nchan_transport, /* i : number of MASA input/transport channels */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t Opt_DTX_ON, /* i : DTX on flag */
+ const int16_t element_mode, /* i : element mode */
+ const ISM_MODE ism_mode, /* i : ISM format mode */
+ const int16_t nchan_ism, /* i : number of ISM channels */
+ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */
+ const int16_t idx_separated_object, /* i : index of the separated object */
+ OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */
+ const int16_t ism_imp, /* i : importance of separated object */
+ const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */
+);
+
+void ivas_masa_estimate_energy(
+ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */
+ float *data_f[], /* i : Input audio channels */
+ const int16_t input_frame, /* i : frame length */
+ const int16_t nchan_transport /* i : number of MASA input/transport channels */
+);
+
+ivas_error ivas_masa_enc_config(
+ Encoder_Struct* st_ivas /* i/o: IVAS encoder structure */
+);
+
+void ivas_masa_set_elements(
+ const int32_t ivas_total_brate, /* i : codec total bitrate */
+ const int16_t mc_mode, /* i : MC format mode */
+ const int16_t nchan_transport, /* i : number of MASA input/transport channels */
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ int16_t *element_mode, /* o : element mode */
+ int16_t *nSCE, /* o : number of SCEs */
+ int16_t *nCPE, /* o : number of CPEs */
+ const int16_t ivas_format, /* i : IVAS format */
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ const int32_t ism_total_brate /* i : initial ISM total bitrate */
+);
+
+/*! r: valid or not 1/0 */
+int16_t valid_ratio_index(
+ int16_t index, /* i : index to be checked */
+ const int16_t K, /* i : L1 norm to check against */
+ const int16_t len /* i : vector length */
+);
+
+void reconstruct_ism_ratios(
+ int16_t *ratio_ism_idx,
+ const int16_t nchan_ism,
+ const float step,
+ float *q_energy_ratio_ism
+);
+
+void distribute_evenly_ism(
+ int16_t *idx,
+ const int16_t K,
+ const int16_t nchan_ism
+);
+
+int16_t ivas_qmetadata_DecodeExtendedGR(
+ uint16_t* bitstream,
+ int16_t* index,
+ const int16_t alph_size,
+ const int16_t gr_param
+);
+
+int16_t ivas_qmetadata_encode_extended_gr_length(
+ const uint16_t value,
+ const uint16_t alphabet_size,
+ const int16_t gr_param);
+
+void ivas_qmetadata_encode_extended_gr(
+ BSTR_ENC_HANDLE hMetaData, /* i/o: q_metadata handle */
+ const uint16_t value, /* i : value to be encoded */
+ const uint16_t alphabet_size, /* i : alphabet size */
+ const int16_t gr_param); /* i : GR order */
+
+/*! r: CPE bitrate value */
+int32_t calculate_cpe_brate_MASA_ISM(
+ const ISM_MODE ism_mode, /* i : ism mode */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t nchan_ism /* i : number of objects */
+);
+
+void ivas_merge_masa_metadata(
+ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */
+ OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */
+);
+
+void ivas_masa_combine_directions(
+ MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */
+);
+
+/*!r : number of bits for ISM ratio index */
+int16_t bits_index_ism_ratio(
+ const int16_t nchan_ism /* i : number of objects */
+);
+
+void calculate_nbits_meta(
+ const int16_t nchan_ism,
+ float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS],
+ float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],
+ const int16_t numSf,
+ const int16_t numCodingBands,
+ int16_t* bits_ism,
+ const int16_t idx_sep_obj,
+ const int16_t ism_imp
+);
+
+/*! r: limitation flag */
+int16_t calculate_brate_limit_flag(
+ const int16_t ism_imp[], /* i : ISM importance flags */
+ const int16_t nchan_ism /* i : number of objects */
+);
+
+void ivas_get_stereo_panning_gains(
+ const float aziDeg,
+ const float eleDeg,
+ float panningGains[2]
+);
+
+void ivas_masa_set_coding_config(
+ MASA_CODEC_CONFIG* config, /* i/o: MASA coding config structure */
+ int16_t* band_mapping, /* o : Band mapping used */
+ const int32_t ivas_total_brate, /* i : codec total bitrate */
+ const int16_t nchan_transport, /* i : number of transport channel (mono/stereo) */
+ const uint8_t isMcMasa /* i : toggle for selecting McMASA specific config */
+);
+
+/*! r: Surround coherence significant flag */
+uint8_t ivas_masa_surrcoh_signicant(
+ float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */
+ float diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */
+ const int16_t nSubFrames, /* i : Number of sub frames */
+ const int16_t nBands /* i : Number of frequency bands */
+);
+
+void masa_compensate_two_dir_energy_ratio_index(
+ const int16_t ratio_index_1, /* i : Input ratio for direction 1 */
+ const int16_t ratio_index_2, /* i : Input ratio for direction 2 */
+ int16_t *ratio_index_mod1, /* o : Output modified ratio for direction 1 */
+ int16_t *ratio_index_mod2, /* o : Output modified ratio for direction 2 */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+);
+
+void ivas_set_qmetadata_maxbit_req(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* o : qmetadata structure where the requirement value is set */
+ const IVAS_FORMAT ivas_format /* i : IVAS format */
+);
+
+/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */
+int16_t ivas_get_df_ratio_bits_hodirac(
+ const int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */
+);
+
+/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */
+int16_t ivas_get_df_ratio_bits(
+ const int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */
+);
+
+void masa_sample_rate_band_correction(
+ MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */
+ int16_t *band_mapping, /* i/o: Band mapping used and modified */
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: QMetadata structure for modification */
+ const uint8_t maxBand, /* i : max band */
+ uint8_t is_encoder, /* i : signals if called at encoder */
+ MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */
+);
+
+void invdct4_transform(
+ float *v, /* i : input vector */
+ uint8_t *invdct_v /* o : transformed vector */
+);
+
+void update_bits_next_block(
+ IVAS_QDIRECTION *q_direction, /* i/o: qdirection */
+ int16_t *p_diff, /* i/o: bits to be transferred */
+ const int16_t j, /* i : current subband index */
+ const int16_t max_i, /* i : max number of subands */
+ const int16_t max_k /* i : max number of subframe */
+);
+
+void ivas_masa_prerender(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ float *output[], /* i/o: synthesized core-coder transport channels */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t nchan_remapped /* i : number of transports used in core */
+);
+
+void ivas_spar_param_to_masa_param_mapping(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */
+ float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */
+ float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */
+ const int16_t subframe /* i : Subframe to map */
+);
+
+
+/*---------------------------------------------------------------------------------*
+ * Binaural FastConv Renderer Prototypes
+*-----------------------------------------------------------------------------------*/
+
+ivas_error ivas_binRenderer_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_binRenderer_close(
+ BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: decoder binaural renderer handle */
+);
+
+void ivas_binaural_hrtf_close(
+ HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i/o: decoder binaural hrtf handle */
+);
+
+void ivas_init_binaural_hrtf(
+ HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */
+);
+
+ivas_error ivas_allocate_binaural_hrtf(
+ HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */
+ const AUDIO_CONFIG input_config, /* i : input audio configuration */
+ const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */
+ const RENDERER_TYPE renderer_type, /* i : renderer type */
+ const int16_t allocate_init_flag /* i : Memory allocation flag */
+);
+
+
+void ivas_binRenderer(
+ BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */
+ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle */
+ int16_t subframe_idx, /* i : subframe index */
+ const int16_t numTimeSlots, /* i : number of time slots to process */
+ float Cldfb_RealBuffer_Binaural[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */
+ float Cldfb_ImagBuffer_Binaural[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */
+ float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */
+ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] /* i : LS signals */
+);
+
+void ivas_binaural_add_LFE(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ int16_t output_frame, /* i : length of input frame */
+ float *input_f[], /* i : transport channels */
+ float *output_f[] /* o : synthesized core-coder transport channels/DirAC output */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * renderer prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_ism_renderer_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_ism_renderer_close(
+ ISM_RENDERER_HANDLE *hIsmRendererData /* i/o: ISM renderer handle */
+);
+
+void ivas_ism_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[], /* i/o: core-coder transport channels/object output */
+ const int16_t output_frame /* i : output frame length per channel */
+);
+
+void ivas_ism_render_sf(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[], /* i/o: core-coder transport channels/object output */
+ const int16_t n_samples_to_render /* i : output frame length per channel */
+);
+
+void ivas_ism_get_stereo_gains(
+ const float azimuth, /* i : object azimuth */
+ const float elevation, /* i : object elevation */
+ float *left_gain, /* o : left channel gain */
+ float *right_gain /* o : right channel gain */
+);
+
+void ivas_mc2sba(
+ IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */
+ float *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */
+ float *buffer_td[], /* o : MC signals (on input) and the HOA3 (on output) */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t sba_order, /* i : SBA order */
+ const float gain_lfe /* i : gain for LFE, 0=ignore LFE */
+);
+
+void ivas_param_mc_mc2sba_cldfb(
+ IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */
+ float *hoa_encoder, /* i : HOA3 encoder for the transported MC format */
+ const int16_t slot_idx, /* i : current slot in the subframe */
+ float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */
+ float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */
+ const int16_t nBands, /* i : number of synth CLDFB bands */
+ const float gain_lfe /* i : gain applied to LFE */
+);
+
+void ivas_ism2sba(
+ float *buffer_td[], /* i/o: TD signal buffers */
+ ISM_RENDERER_HANDLE hIsmRendererData, /* i/o: renderer data */
+ const ISM_METADATA_HANDLE hIsmMetaData[], /* i : object metadata */
+ const int16_t nchan_ism, /* i : number of objects */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t sba_order /* i : SBA order */
+);
+
+void ivas_ism2sba_sf(
+ float *buffer_in[], /* i : TC buffer */
+ float *buffer_out[], /* o : TD signal buffers */
+ ISM_RENDERER_HANDLE hIsmRendererData, /* i/o: renderer data */
+ const int16_t num_objects, /* i : number of objects */
+ const int16_t n_samples_to_render, /* i : output frame length per channel */
+ const int16_t offset, /* i : offset for the interpolatr */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * 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 */
+);
+
+ivas_error vbap_init_data(
+ VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */
+ const float *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */
+ const float *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */
+ const int16_t num_speaker_nodes, /* i : number of speaker nodes in the set */
+ const IVAS_FORMAT ivas_format /* i : IVAS format */
+);
+
+void vbap_free_data(
+ VBAP_HANDLE *hVBAPdata /* i/o: VBAP handle to be freed */
+);
+
+void vbap_determine_gains(
+ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */
+ float *gains, /* o : gain vector for speaker nodes for given direction */
+ const int16_t azi_deg, /* i : azimuth in degrees for panning direction (positive left) */
+ const int16_t ele_deg, /* i : elevation in degrees for panning direction (positive up) */
+ const int16_t use_object_mode /* i : select between object mode panning and spatial mode panning */
+);
+
+void v_sort_ind(
+ float *x, /* i/o: Vector to be sorted */
+ int16_t *idx, /* o : Original index positions */
+ const int16_t len /* i : vector length */
+);
+
+/*----------------------------------------------------------------------------------*
+ * LS Renderer prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_ls_setup_conversion_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_ls_setup_conversion_close(
+ LSSETUP_CONVERSION_HANDLE *hLsSetUpConversion /* i/o: LS converter handle */
+);
+
+
+void ivas_ls_setup_conversion(
+ Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
+ const int16_t input_chans, /* i : number of input channels to the renderer */
+ const int16_t output_frame, /* i : frame length */
+ float *input[], /* i : LS input/output synthesis signal */
+ float *output[] /* i/o: LS input/output synthesis signal */
+);
+
+void ivas_ls_setup_conversion_process_mdct(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output[] /* i/o: output synthesis signal */
+);
+
+void ivas_ls_setup_conversion_process_mdct_param_mc(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *x[][NB_DIV] /* i/o: output synthesis signal */
+);
+
+void ivas_lssetupconversion_process_param_mc(
+ Decoder_Struct *st_ivas, /* i/o: LS setup conversion renderer handle */
+ const int16_t num_timeslots, /* i : number of time slots to process */
+ float Cldfb_RealBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */
+ float Cldfb_ImagBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */
+ int16_t channel_active[MAX_CICP_CHANNELS] /* i : bitmap indicating which output channels are active */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * Custom loudspeaker setup prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_ls_custom_open(
+ LSSETUP_CUSTOM_HANDLE *hLsSetupCustom /* o : Custom loudspeaker setup handle */
+);
+
+ivas_error ivas_ls_custom_output_init(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
+);
+
+void ivas_ls_custom_setup(
+ IVAS_OUTPUT_SETUP_HANDLE hOutSetup, /* o : IVAS output setup handle */
+ const LSSETUP_CUSTOM_STRUCT *hLsSetupCustom /* i : Custom loudspeaker setup handle */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * McMASA prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_mcmasa_enc_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+void ivas_mcmasa_enc_close(
+ MCMASA_ENC_HANDLE *hMcMasa, /* i/o: encoder McMASA handle */
+ const int32_t input_Fs /* i : input sampling rate */
+);
+
+ivas_error ivas_mcmasa_enc_reconfig(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+ivas_error ivas_mcmasa_dec_reconfig(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
+);
+
+void ivas_mcmasa_setNumTransportChannels(
+ int16_t* nchan_transport, /* o : Pointer to number of transport channels to be set */
+ int16_t* element_mode, /* o : Pointer to element mode to be set */
+ const int32_t ivas_total_brate /* i : Total bitrate of IVAS */
+);
+
+void ivas_mcmasa_set_separate_channel_mode(
+ uint8_t *separateChannelEnabled, /* o : Pointer to separate channel toggle */
+ int16_t *separateChannelIndex, /* o : Pointer to separate channel index */
+ const int32_t ivas_total_brate /* i : Total bitrate of IVAS */
+);
+
+void ivas_mcmasa_split_brate(
+ const uint8_t separateChannelEnabled, /* i : Transport running in "separate channel" mode */
+ const int32_t ivas_total_brate, /* i : Total bitrate available to be split */
+ const int16_t nSCE, /* i : Number of SCEs in use (0 or 1) */
+ const int16_t nCPE, /* i : Number of CPEs in use (0 or 1) */
+ int32_t *brate_sce, /* o : Pointer to SCE element bitrate */
+ int32_t *brate_cpe /* o : Pointer to CPE element bitrate */
+);
+
+void ivas_mcmasa_enc(
+ MCMASA_ENC_HANDLE hMcMasa, /* i/o: Encoder McMASA handle */
+ IVAS_QMETADATA_HANDLE hQMeta, /* o : Qmetadata handle */
+ MASA_ENCODER_HANDLE hMasa, /* i/o: Encoder MASA handle */
+ float *data_f[], /* i : Input frame of audio */
+ const int16_t input_frame, /* i : Input frame size */
+ const int16_t nchan_transport, /* i : Number of transport channels */
+ const int16_t nchan_inp /* i : Number of input channels */
+);
+
+void ivas_mcmasa_param_est_enc(
+ MCMASA_ENC_HANDLE hMcMasa, /* i/o: Encoder McMASA handle */
+ MASA_ENCODER_HANDLE hMasa, /* i/o: Encoder MASA handle */
+ float *data_f[], /* i : Input frame of audio */
+ float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation */
+ float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth */
+ float energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio*/
+ float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence */
+ float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence */
+ const int16_t input_frame, /* i : Input frame size */
+ const int16_t nchan_inp /* i : Number of input channels */
+);
+
+void ivas_mcmasa_dmx_modify(
+ const int16_t n_samples, /* i : input frame length in samples */
+ float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format */
+ const int16_t n_chnls_dmx_old, /* i : number of downmix channels in the old format */
+ const int16_t n_chnls_dmx_new /* i : number of downmix channels in the target format */
+);
+
+void v_multc_acc(
+ const float x[], /* i : Input vector */
+ const float c, /* i : Constant */
+ float y[], /* o : Output vector that contains y + c*x */
+ const int16_t N /* i : Vector length */
+);
+
+void lls_interp_n(
+ float x[], /* i/o: input/output vector */
+ const int16_t N, /* i : length of the input vector */
+ float *a, /* o : calculated slope */
+ float *b, /* o : calculated offset */
+ const int16_t upd /* i : use 1 to update x[] with the interpolated output*/
+);
+
+void computeReferencePower_enc(
+ const int16_t *band_grouping, /* i : Band grouping for estimation */
+ float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */
+ float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */
+ float *reference_power, /* o : Estimated power */
+ const int16_t enc_param_start_band, /* i : first band to process */
+ const int16_t num_freq_bands, /* i : Number of frequency bands */
+ const IVAS_FORMAT ivas_format, /* i : ivas_format */
+ int16_t ref_power_w, /* i : use 0 if hodirac is enabled */
+ const int16_t nchan_ana, /* i : number of analysis channels */
+ int16_t *mono_frame_count,
+ int16_t *dirac_mono_flag
+);
+
+ivas_error ivas_mono_dmx_renderer_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+
+void ivas_mono_dmx_renderer_close(
+ MONO_DOWNMIX_RENDERER_HANDLE *hMonoDmxRenderer /* i/ i/o: Mono downmix structure */
+);
+
+void ivas_mono_downmix_render_passive(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[], /* i/o: synthesized core-coder transport channels/mono output */
+ const int16_t output_frame /* i : output frame length */
+);
+
+void ivas_mono_stereo_downmix_mcmasa(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[], /* i/o: synthesized core-coder transport channels/mono or stereo output */
+ int16_t output_frame /* i : output frame length per channel */
+);
+
+void ivas_lfe_synth_with_filters(
+ MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, /* i/o: LFE synthesis structure for McMASA */
+ float *data_f[], /* o : output signals */
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t separateChannelIndex, /* i : separate channel index */
+ const int16_t lfeChannelIndex /* i : LFE channel index */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * LFE encoder low pass filter prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_create_lfe_lpf_enc(
+ ivas_filters_process_state_t **hLfeLpf, /* o : LFE LPF handle */
+ const int32_t input_Fs /* i : input sampling rate */
+);
+
+void ivas_lfe_lpf_enc_close(
+ ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */
+);
+
+void ivas_lfe_lpf_enc_apply(
+ ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */
+ float data_lfe_ch[], /* i/o: LFE signal */
+ const int16_t input_frame /* i : input frame length per channel */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * LFE Coding prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_create_lfe_enc(
+ LFE_ENC_HANDLE *hLFE, /* o : IVAS LFE encoder structure */
+ const int32_t input_Fs /* i : input sampling rate */
+);
+
+void ivas_lfe_enc_close(
+ LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */
+);
+
+void ivas_lfe_enc(
+ LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */
+ float data_lfe_ch[], /* i : input LFE signal */
+ const int16_t input_frame, /* i : input frame length per channel */
+ BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */
+);
+
+ivas_error ivas_create_lfe_dec(
+ LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const int32_t binauralization_delay_ns /* i : additional LFE delay to sync with binaural renderer */
+);
+
+void ivas_lfe_dec_close(
+ LFE_DEC_HANDLE *hLFE /* i/o: LFE encoder handle */
+);
+
+void ivas_lfe_dec(
+ LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */
+ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/
+ const int16_t output_frame, /* i : output frame length per channel */
+ const int16_t bfi, /* i : BFI flag */
+ float output_lfe_ch[] /* o : output LFE synthesis */
+);
+
+void ivas_lfe_tdplc(
+ LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */
+ const float *prevsynth, /* i : previous frame synthesis */
+ float *ytda, /* o : output time-domain buffer */
+ const int16_t output_frame /* i : output frame length */
+);
+
+void ivas_lfe_window_init(
+ LFE_WINDOW_HANDLE hLFEWindow, /* i/o: LFE window handle */
+ const int32_t sampling_rate, /* i : sampling rate */
+ const int16_t frame_len /* i : frame length in samples */
+);
+
+void ivas_lfe_lpf_select_filt_coeff(
+ const int32_t sampling_rate, /* i : sampling rate */
+ const int16_t order, /* i : filter order */
+ const float **ppFilt_coeff /* o : filter coefficients */
+);
+
+void ivas_filters_init(
+ ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */
+ const float *filt_coeff, /* i : filter coefficients */
+ const int16_t order /* i : filter order */
+);
+
+void ivas_filter_process(
+ ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */
+ float *pIn_Out, /* i : signal subject to filtering */
+ const int16_t length /* i : filter order */
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * OSBA prototypes
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_osba_enc_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+void ivas_osba_enc_close(
+ OSBA_ENC_HANDLE *hOSba /* i/o: encoder OSBA handle */
+);
+
+ivas_error ivas_osba_enc_reconfig(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+void ivas_osba_enc(
+ OSBA_ENC_HANDLE hOSba, /* i/o: OSBA encoder handle */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */
+ float *data_in_f[], /* i/o: Input / transport audio signals */
+ const int16_t input_frame, /* i : Input frame size */
+ const int16_t nchan_ism, /* i : Number of objects for parameter analysis*/
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ const int16_t sba_analysis_order, /* i : SBA order evaluated in SBA encoder */
+ const int32_t input_Fs, /* i : input sampling rate */
+ const int16_t sba_planar /* i : planar SBA flag */
+);
+
+ivas_error ivas_osba_data_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
+);
+
+ivas_error ivas_osba_dirac_td_binaural_jbm(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
+ uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
+ uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
+ float *output_f[] /* o : rendered time signal */
+);
+
+ivas_error ivas_osba_dirac_td_binaural(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output[], /* o : output synthesis signal */
+ const int16_t output_frame /* i : output frame length per channel */
+);
+
+ivas_error ivas_osba_ism_metadata_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int32_t ism_total_brate, /* i : ISM total bitrate */
+ int16_t *nchan_ism, /* o : number of ISM separated channels */
+ int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */
+);
+
+ivas_error ivas_osba_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[], /* i/o: core-coder transport channels/object output */
+ const int16_t output_frame /* i : output frame length per channel */
+);
+
+void ivas_osba_data_close(
+ SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */
+);
+
+
+/*----------------------------------------------------------------------------------*
+* OMASA prototypes
+*---------------------------------------------------------------------------------*/
+
+ivas_error ivas_omasa_enc_open(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
+);
+
+void ivas_omasa_enc_close(
+ OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */
+);
+
+ivas_error ivas_omasa_enc_config(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+ivas_error ivas_omasa_dec_config(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */
+ int16_t *data /* o : output synthesis signal */
+);
+
+void ivas_omasa_set_config(
+ OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */
+ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */
+ const int32_t input_Fs, /* i : Input sample rate */
+ const ISM_MODE ism_mode /* i : ISM mode */
+);
+
+void ivas_omasa_enc(
+ OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */
+ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */
+ float *data_in_f[], /* i/o: Input / transport audio signals */
+ const int16_t input_frame, /* i : Input frame size */
+ const int16_t nchan_transport, /* i : Number of transport channels */
+ const int16_t nchan_ism, /* i : Number of objects for parameter analysis*/
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ float *data_separated_object, /* o : Separated object audio signal */
+ int16_t* idx_separated_object /* o : Index of the separated object */
+);
+
+void ivas_set_surplus_brate_enc(
+ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
+);
+
+void ivas_set_surplus_brate_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ int32_t *ism_total_brate /* i : ISM total bitrate */
+);
+
+void ivas_set_ism_importance_interformat(
+ const int32_t ism_total_brate, /* i/o: ISms total bitrate */
+ const int16_t nchan_transport, /* i : number of transported channels */
+ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
+ SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */
+ const float lp_noise_CPE, /* i : LP filtered total noise estimation */
+ int16_t ism_imp[] /* o : ISM importance flags */
+);
+
+/*! r: flag for using less bitrate for objects in OMASA */
+int16_t ivas_omasa_ener_brate(
+ const int16_t nchan_ism, /* i : number of ISMs */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ float *data_f[], /* i : Input / transport audio signals */
+ const int16_t input_frame /* i : Input frame size */
+);
+
+/*! r: adjusted bitrate */
+int32_t ivas_interformat_brate(
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ const int16_t nchan_ism, /* i : number of ISM channels */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t ism_imp, /* i : ISM importance flag */
+ const int16_t limit_flag /* i : flag to limit the bitrate increase */
+);
+
+void ivas_combined_format_brate_sanity(
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t core, /* i : core */
+ const int32_t total_brate, /* i : total bitrate */
+ int32_t *core_brate, /* i/o: core bitrate */
+ int16_t *inactive_coder_type_flag, /* o : inactive coder_type flag */
+ int16_t *diff_nBits /* o : number of differential bits */
+);
+
+ISM_MODE ivas_omasa_ism_mode_select(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t nchan_ism /* i : number of input ISM's */
+);
+
+void ivas_set_omasa_TC(
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ const int16_t nchan_ism, /* i : number of input ISMs */
+ int16_t *nSCE, /* o : number of SCEs */
+ int16_t *nCPE /* o : number of CPEs */
+);
+
+void ivas_merge_masa_transports(
+ float data_in_f1[][L_FRAME48k], /* i : Transport audio signals 1 */
+ float *data_in_f2[], /* i : Transport audio signals 2 */
+ float *data_out_f[], /* o : Merged transport audio signals */
+ const int16_t input_frame, /* i : Input frame size */
+ const int16_t num_transport_channels /* i : Number of transport audio signals */
+);
+
+ivas_error ivas_omasa_data_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
+);
+
+void ivas_omasa_data_close(
+ MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */
+);
+
+ivas_error ivas_omasa_ism_metadata_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int32_t ism_total_brate, /* i : ISM total bitrate */
+ int16_t *nchan_ism, /* o : number of ISM separated channels */
+ int16_t *nchan_transport_ism, /* o : number of ISM TCs */
+ const int16_t dirac_bs_md_write_idx, /* i : DirAC bitstream write index */
+ int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */
+);
+
+ivas_error ivas_omasa_dirac_td_binaural(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output[], /* o : output synthesis signal */
+ const int16_t output_frame /* i : output frame length per channel */
+);
+
+ivas_error ivas_omasa_dirac_td_binaural_jbm(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint16_t nSamplesAsked, /* i : number of samples requested */
+ uint16_t *nSamplesRendered, /* o : number of samples rendered */
+ uint16_t *nSamplesAvailable, /* o : number of samples still to render */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ float *output_f[] /* o : rendered time signal */
+);
+
+void ivas_omasa_dirac_rend(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output[], /* o : output synthesis signal */
+ const int16_t output_frame /* i : output frame length per channel */
+);
+
+void ivas_omasa_rearrange_channels(
+ float *output[], /* o : output synthesis signal */
+ const int16_t nchan_transport_ism, /* i : number of ISM TCs */
+ const int16_t output_frame /* i : output frame length per channel */
+);
+
+void ivas_omasa_dirac_rend_jbm(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint16_t nSamplesAsked, /* i : number of samples requested */
+ uint16_t *nSamplesRendered, /* o : number of samples rendered */
+ uint16_t *nSamplesAvailable, /* o : number of samples still to render */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ float *output_f[] /* o : rendered time signal */
+);
+
+void ivas_omasa_preProcessStereoTransportsForMovedObjects(
+ Decoder_Struct *st_ivas,
+ float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
+ float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
+ const int16_t nBins,
+ const int16_t subframe
+);
+
+ivas_error ivas_omasa_separate_object_renderer_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_omasa_separate_object_renderer_close(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void ivas_omasa_separate_object_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float input_f[][L_FRAME48k], /* i : separated object signal */
+ float *output_f[], /* i/o: output signals */
+ const int16_t output_frame /* i : output frame length per channel */
+);
+
+void ivas_omasa_separate_object_render_jbm(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const uint16_t nSamplesRendered, /* i : number of samples rendered */
+ float *output_f[], /* o : rendered time signal */
+ const int16_t subframes_rendered, /* i : number of subframes rendered */
+ const int16_t slots_rendered /* i : number of CLDFB slots rendered */
+);
+
+void ivas_omasa_encode_masa_to_total(
+ float masa_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],
+ BSTR_ENC_HANDLE hMetaData,
+ const int16_t low_bitrate_mode,
+ const int16_t nbands,
+ const int16_t nblocks
+);
+
+void ivas_omasa_decode_masa_to_total(
+ uint16_t *bit_stream,
+ int16_t *index,
+ float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],
+ const int16_t nbands,
+ const int16_t nblocks
+);
+
+void ivas_omasa_modify_masa_energy_ratios(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS]
+);
+
+
+/*----------------------------------------------------------------------------------*
+ * TD Binaural Object renderer
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_td_binaural_open(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+ivas_error ivas_td_binaural_renderer(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output[], /* i/o: SCE channels / Binaural synthesis */
+ const int16_t output_frame /* i : output frame length */
+);
+
+ivas_error ivas_td_binaural_renderer_sf(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output[], /* i/o: SCE channels / Binaural synthesis */
+ const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */
+);
+
+/*----------------------------------------------------------------------------------*
+ * Filter-bank (FB) Mixer
+ *----------------------------------------------------------------------------------*/
+
+ivas_error ivas_fb_set_cfg(
+ IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */
+ const int16_t ivas_format, /* i : IVAS format */
+ const int16_t num_in_chans, /* i : number of FB input channels */
+ const int16_t num_out_chans, /* i : number of FB output channels */
+ const int16_t active_w_mixing, /* i : active_w_mixing flag */
+ const int32_t sampling_Fs, /* i : sampling rate */
+ const int16_t nachan_dirac_ana /* i : number of DirAR analysis channels */
+);
+
+ivas_error ivas_FB_mixer_open(
+ IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */
+ const int32_t sampling_rate, /* i : sampling rate */
+ IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */
+ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */
+);
+
+void ivas_FB_mixer_close(
+ IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */
+ const int32_t sampling_rate, /* i : sampling rate in Hz */
+ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */
+);
+
+void ivas_fb_mixer_pcm_ingest(
+ IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */
+ float *pcm_in[], /* i : input audio channels */
+ float **ppOut_pcm, /* o : output audio channels */
+ const int16_t frame_length, /* i : frame length */
+ const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH]
+);
+
+void ivas_fb_mixer_update_prior_input(
+ IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */
+ float *pcm_in[], /* i : input audio channels */
+ const int16_t length, /* i : length of time slot */
+ const int16_t nchan_fb_in /* i : number of analysis channels */
+);
+
+void ivas_fb_mixer_get_windowed_fr(
+ IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */
+ float *pcm_in[], /* i : input audio channels */
+ float *frame_f_real[], /* o : real freq domain values */
+ float *frame_f_imag[], /* o : imag freq domain values */
+ const int16_t length, /* i : number of new samples in time slot */
+ const int16_t mdft_len, /* i : MDFT frame length */
+ const int16_t nchan_fb_in /* i : number of analysis channels */
+);
+
+void ivas_fb_mixer_process(
+ IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */
+ float ***mixer_mat, /* i : mixer matrix */
+ float **ppOut_pcm, /* o : output audio channels */
+ const int16_t frame_len, /* i : frame length in samples */
+ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */
+);
+
+void ivas_fb_mixer_get_in_out_mapping(
+ const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */
+ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */
+);
+
+void ivas_fb_mixer_cross_fading(
+ IVAS_FB_MIXER_HANDLE hFbMixer,
+ float **ppOut_pcm,
+ float *pMdft_out_old,
+ float *pMdft_out_new,
+ const int16_t ch,
+ const int16_t frame_len,
+ const int16_t cf_offset
+);
+
+/*! r: number of spectral bands */
+int16_t ivas_get_num_bands_from_bw_idx(
+ const int16_t bwidth /* i : audio bandwidth */
+);
+
+
+/* clang-format on */
+
+#endif /* IVAS_PROT_H */
diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..57adf7c6aae2048cad144afefbaffe5e418b4cb8
--- /dev/null
+++ b/lib_com/ivas_qmetadata_com.c
@@ -0,0 +1,666 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "ivas_prot.h"
+#include "prot.h"
+#include "cnst.h"
+#include "wmc_auto.h"
+
+/*-----------------------------------------------------------------------*
+ * Local constants
+ *-----------------------------------------------------------------------*/
+
+#define MASA_DIR_RATIO_COMP_MAX_IDX_STEPS 2
+
+/*-----------------------------------------------------------------------*
+ * Local function prototypes
+ *-----------------------------------------------------------------------*/
+
+static void ivas_qmetadata_free_memory( IVAS_QMETADATA_HANDLE hQMetaData );
+
+
+/*-----------------------------------------------------------------------*
+ * ivas_qmetadata_open()
+ *
+ * Allocate Q Metadata handle
+ *-----------------------------------------------------------------------*/
+
+ivas_error ivas_qmetadata_open(
+ IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */
+)
+{
+ /* allocate MetaData handle */
+ if ( ( *hQMetaData = (IVAS_QMETADATA_HANDLE) malloc( sizeof( IVAS_QMETADATA ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" );
+ }
+
+ ( *hQMetaData )->q_direction = NULL;
+ ( *hQMetaData )->surcoh_band_data = NULL;
+ ( *hQMetaData )->bandMap = NULL;
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * ivas_qmetadata_allocate_memory()
+ *
+ * Allocates dynamic memory for qmetadata. Also reallocates automatically
+ * if relevant parameters have changed. To function properly, this function
+ * assumes that qmetadata contains parameter values for nbands, ndirs and
+ * coherence_flag corresponding to the currently reserved memory. This function
+ * then compares them to provided new values given in call and allocates or
+ * reallocates as necessary. The parameter values in qmetadata are updated
+ * accordingly. In addition, parameters inside qdirection config are
+ * set here to their default values out of practicality.
+ *-----------------------------------------------------------------------*/
+
+ivas_error ivas_qmetadata_allocate_memory(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
+ const int16_t nbands, /* i : new number of frequency bands */
+ const int16_t ndirs, /* i : new number of directions */
+ const int16_t coherence_flag /* i : new coherence coding status */
+)
+{
+ int16_t j, dir;
+ uint8_t do_realloc;
+
+
+ /* Check if we need to reallocate memory or do we need to do the first time allocation. */
+ if ( hQMetaData->q_direction != NULL )
+ {
+ do_realloc = nbands != hQMetaData->q_direction->cfg.nbands;
+ do_realloc |= ndirs != hQMetaData->no_directions;
+ do_realloc |= coherence_flag != hQMetaData->coherence_flag;
+ }
+ else
+ {
+ do_realloc = TRUE;
+ }
+
+ if ( do_realloc )
+ {
+ ivas_qmetadata_free_memory( hQMetaData );
+
+ hQMetaData->numCodingBands = (uint8_t) nbands;
+ hQMetaData->no_directions = ndirs;
+ hQMetaData->coherence_flag = coherence_flag;
+
+ if ( ( hQMetaData->q_direction = (IVAS_QDIRECTION *) malloc( sizeof( IVAS_QDIRECTION ) * ndirs ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" );
+ }
+
+ for ( dir = 0; dir < hQMetaData->no_directions; dir++ )
+ {
+ hQMetaData->q_direction[dir].cfg.nbands = nbands;
+ if ( nbands == 0 )
+ {
+ hQMetaData->q_direction[dir].band_data = NULL;
+ }
+ else
+ {
+ if ( ( hQMetaData->q_direction[dir].band_data = (IVAS_QDIRECTION_BAND_DATA *) malloc( sizeof( IVAS_QDIRECTION_BAND_DATA ) * hQMetaData->q_direction[dir].cfg.nbands ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" );
+ }
+
+ for ( j = 0; j < nbands; j++ )
+ {
+ set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES );
+ set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES );
+ set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES );
+ }
+ }
+
+ if ( coherence_flag )
+ {
+ hQMetaData->q_direction[dir].coherence_band_data = (IVAS_QDIRECTION_BAND_COHERENCE_DATA *) malloc( sizeof( IVAS_QDIRECTION_BAND_COHERENCE_DATA ) * hQMetaData->q_direction[dir].cfg.nbands );
+ }
+ else
+ {
+ hQMetaData->q_direction[dir].coherence_band_data = NULL;
+ }
+
+ /* These default values are set here to get them conveniently in one place */
+ hQMetaData->q_direction[dir].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES;
+ hQMetaData->q_direction[dir].cfg.search_effort = 3;
+ hQMetaData->q_direction[dir].cfg.start_band = 0;
+ hQMetaData->q_direction[dir].cfg.mc_ls_setup = MC_LS_SETUP_INVALID;
+ }
+
+ if ( coherence_flag )
+ {
+ if ( ( hQMetaData->surcoh_band_data = (IVAS_SURROUND_COHERENCE_BAND_DATA *) malloc( sizeof( IVAS_SURROUND_COHERENCE_BAND_DATA ) * hQMetaData->q_direction[0].cfg.nbands ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" );
+ }
+ }
+ else
+ {
+ hQMetaData->surcoh_band_data = NULL;
+ }
+ }
+
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * ivas_qmetadata_free_memory()
+ *
+ * free dynamic part of Q Metadata memory
+ *-----------------------------------------------------------------------*/
+
+static void ivas_qmetadata_free_memory(
+ IVAS_QMETADATA_HANDLE hQMetaData /* i/o: q_metadata handle */
+)
+{
+ int16_t dir;
+
+ if ( hQMetaData == NULL )
+ {
+ return;
+ }
+
+ if ( hQMetaData->q_direction != NULL )
+ {
+ for ( dir = 0; dir < hQMetaData->no_directions; dir++ )
+ {
+ if ( hQMetaData->q_direction[dir].band_data != NULL )
+ {
+ free( hQMetaData->q_direction[dir].band_data );
+ hQMetaData->q_direction[dir].band_data = NULL;
+ }
+ if ( hQMetaData->q_direction[dir].coherence_band_data != NULL )
+ {
+ free( hQMetaData->q_direction[dir].coherence_band_data );
+ hQMetaData->q_direction[dir].coherence_band_data = NULL;
+ }
+ }
+
+ free( hQMetaData->q_direction );
+ hQMetaData->q_direction = NULL;
+ }
+
+ if ( hQMetaData->surcoh_band_data != NULL )
+ {
+ free( hQMetaData->surcoh_band_data );
+ hQMetaData->surcoh_band_data = NULL;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * ivas_qmetadata_close()
+ *
+ * close Q Metadata
+ *-----------------------------------------------------------------------*/
+
+void ivas_qmetadata_close(
+ IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */
+)
+{
+ if ( hQMetaData == NULL || *hQMetaData == NULL )
+ {
+ return;
+ }
+
+ ivas_qmetadata_free_memory( *hQMetaData );
+
+ free( *hQMetaData );
+ *hQMetaData = NULL;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * masa_sq()
+ *
+ * scalar quantization using partition
+ *------------------------------------------------------------------------*/
+
+/*! r: codeword index */
+int16_t masa_sq(
+ const float in, /* i : input value */
+ const float *threshold, /* i : partition */
+ const int16_t cb_sz /* i : codebook size */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < cb_sz; i++ )
+ {
+ if ( in < threshold[i + 1] )
+ {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * only_reduce_bits_direction()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+ivas_error only_reduce_bits_direction(
+ int16_t *reduce_bits_out,
+ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
+ int16_t reduce_bits,
+ const int16_t coding_subbands,
+ const int16_t no_subframes,
+ int16_t *ind_order )
+{
+ int16_t j, k, red_times, rem, n;
+ int16_t max_nb, delta;
+ int16_t *bits_dir0;
+
+ int16_t bits_sph_idx_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES];
+ float penalty[MASA_MAXIMUM_CODING_SUBBANDS];
+ for ( j = 0; j < coding_subbands; j++ )
+ {
+ for ( k = 0; k < no_subframes; k++ )
+ {
+ bits_sph_idx_orig[j][k] = q_direction->band_data[j].bits_sph_idx[k];
+ }
+ }
+ n = 0;
+ delta = 1;
+
+ if ( reduce_bits > 0 )
+ {
+ red_times = reduce_bits / ( coding_subbands * no_subframes ); /* number of complete reductions by 1 bit */
+ if ( red_times > 0 )
+ {
+ for ( j = 0; j < coding_subbands; j++ )
+ {
+ bits_dir0 = (int16_t *) q_direction->band_data[j].bits_sph_idx;
+ for ( k = 0; k < no_subframes; k++ )
+ {
+ bits_dir0[k] -= red_times;
+ reduce_bits -= red_times;
+
+ if ( bits_dir0[k] < MASA_MIN_BITS_TF )
+ {
+ reduce_bits += ( MASA_MIN_BITS_TF - bits_dir0[k] );
+ bits_dir0[k] = MASA_MIN_BITS_TF;
+ }
+ }
+ }
+ }
+
+ rem = reduce_bits; /* -coding_subbands*no_subframes*red_times; */
+ while ( n < rem )
+ {
+ max_nb = 0;
+ for ( j = 0; j < coding_subbands; j++ )
+ {
+ bits_dir0 = (int16_t *) q_direction->band_data[j].bits_sph_idx;
+ for ( k = 0; k < no_subframes; k++ )
+ {
+ if ( ( n < rem ) && ( bits_dir0[k] > MASA_MIN_BITS_TF - delta ) )
+ {
+ bits_dir0[k] -= 1;
+ n++;
+ }
+
+ if ( max_nb < bits_dir0[k] )
+ {
+ max_nb = bits_dir0[k];
+ }
+ }
+ }
+
+ if ( max_nb <= MASA_MIN_BITS_TF )
+ {
+ delta += 1;
+ }
+ }
+
+ reduce_bits = 0;
+ }
+
+ if ( ind_order[0] == -1 )
+ {
+ for ( j = 0; j < coding_subbands; j++ )
+ {
+ ind_order[j] = j;
+ }
+ }
+ else
+ {
+ for ( j = 0; j < coding_subbands; j++ )
+ {
+ penalty[j] = 0.0f;
+ for ( k = 0; k < no_subframes; k++ )
+ {
+ if ( bits_sph_idx_orig[j][k] > 0 )
+ {
+ penalty[j] += ( bits_sph_idx_orig[j][k] - q_direction->band_data[j].bits_sph_idx[k] ) / (float) bits_sph_idx_orig[j][k];
+ }
+ }
+ penalty[j] /= no_subframes;
+ }
+ sort_desc_ind( penalty, coding_subbands, ind_order );
+ }
+
+ *reduce_bits_out = -reduce_bits;
+
+ return IVAS_ERR_OK;
+}
+
+
+/*---------------------------------------------------------------
+ * update_bits_next_block()
+ *
+ * Transfer the saved bits to the next subbands
+ *---------------------------------------------------------------*/
+
+void update_bits_next_block(
+ IVAS_QDIRECTION *q_direction, /* i/o: qdirection */
+ int16_t *p_diff, /* i/o: bits to be transferred */
+ const int16_t j, /* i : subband to update bit alloc to*/
+ const int16_t max_i, /* i : number of subbands */
+ const int16_t max_k /* i : n umber of subframes */
+)
+{
+ int16_t diff;
+ int16_t k;
+ diff = *p_diff;
+ if ( diff < 0 )
+ {
+ /* increase bits for next subbands */
+ k = 0;
+ while ( ( diff < 0 ) && ( j < max_i ) && ( k < max_k ) )
+ {
+ if ( q_direction->band_data[j].bits_sph_idx[k] < MASA_DIRECTION_MAX_BITS )
+ {
+ q_direction->band_data[j].bits_sph_idx[k] += 1;
+ diff++;
+ }
+ k++;
+ }
+ }
+ else
+ {
+ k = 0;
+ while ( ( diff > 0 ) && ( k < max_k ) )
+ {
+ if ( q_direction->band_data[j].bits_sph_idx[k] > 0 )
+ {
+ q_direction->band_data[j].bits_sph_idx[k] -= 1;
+ diff--;
+ }
+ }
+ }
+ *p_diff = diff;
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * invdct4_transform()
+ *
+ * Inverse DCT transform for 4D vector
+ *---------------------------------------------------------------*/
+
+void invdct4_transform(
+ float *v, /* i : input vector */
+ uint8_t *invdct_v /* o : inverse transformed vector */
+)
+{
+ float a, b, c, d;
+ int16_t i;
+ float f_invdct_v[4];
+
+ a = v[0] + v[2];
+ b = v[0] - v[2];
+ c = 1.306562964876376f * v[1] + 0.541196100146198f * v[3];
+ d = 0.541196100146198f * v[1] - 1.306562964876376f * v[3];
+ f_invdct_v[0] = 128 * ( a + c );
+ f_invdct_v[1] = 128 * ( b + d );
+ f_invdct_v[2] = 128 * ( b - d );
+ f_invdct_v[3] = 128 * ( a - c );
+
+ for ( i = 0; i < 4; i++ )
+ {
+ if ( f_invdct_v[i] < 0.0 )
+ {
+ invdct_v[i] = 0;
+ }
+ else
+ {
+ if ( f_invdct_v[i] > 255.0f )
+ {
+ f_invdct_v[i] = 255.0f;
+ }
+ invdct_v[i] = (uint8_t) f_invdct_v[i];
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * masa_compensate_two_dir_energy_ratio_index()
+ *
+ * Calculated compensated direct-to-total ratios for direction
+ * quantization with two directions. This allows maintaining
+ * direction accuracy while reusing one direction quantizers
+ * separately for both directions.
+ *--------------------------------------------------------------*/
+
+void masa_compensate_two_dir_energy_ratio_index(
+ const int16_t ratio_index_1, /* i : Input ratio for direction 1 */
+ const int16_t ratio_index_2, /* i : Input ratio for direction 2 */
+ int16_t *ratio_index_mod1, /* o : Output modified ratio for direction 1 */
+ int16_t *ratio_index_mod2, /* o : Output modified ratio for direction 2 */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+)
+{
+ float ratio1, ratio2;
+ float ratioSum;
+
+ ratio1 = 1.0f - diffuseness_reconstructions[ratio_index_1];
+ ratio2 = 1.0f - diffuseness_reconstructions[ratio_index_2];
+
+ if ( !hodirac_flag )
+ {
+ ratioSum = ratio1 + ratio2;
+ if ( ratio1 >= ratio2 )
+ {
+ ratio2 = ratio2 / ratio1 * ratioSum;
+ ratio1 = ratioSum;
+ }
+ else
+ {
+ ratio1 = ratio1 / ratio2 * ratioSum;
+ ratio2 = ratioSum;
+ }
+ }
+
+ *ratio_index_mod1 = masa_sq( 1.0f - ratio1, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS );
+ *ratio_index_mod2 = masa_sq( 1.0f - ratio2, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS );
+
+ /* Limit maximum accuracy increase to conserve bits */
+ *ratio_index_mod1 = ( ratio_index_1 - *ratio_index_mod1 ) > MASA_DIR_RATIO_COMP_MAX_IDX_STEPS ? ratio_index_1 - MASA_DIR_RATIO_COMP_MAX_IDX_STEPS : *ratio_index_mod1;
+ *ratio_index_mod2 = ( ratio_index_2 - *ratio_index_mod2 ) > MASA_DIR_RATIO_COMP_MAX_IDX_STEPS ? ratio_index_2 - MASA_DIR_RATIO_COMP_MAX_IDX_STEPS : *ratio_index_mod2;
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * set_qmetadata_maxbit_req()
+ *
+ * Sets proper value for qmetadata_max_bit_req limit
+ *--------------------------------------------------------------*/
+
+void ivas_set_qmetadata_maxbit_req(
+ IVAS_QMETADATA_HANDLE hQMetaData, /* o : qmetadata structure where the requirement value is set */
+ const IVAS_FORMAT ivas_format /* i : IVAS format */
+)
+{
+ if ( ivas_format == SBA_FORMAT )
+ {
+ hQMetaData->qmetadata_max_bit_req = QMETADATA_MAXBIT_REQ_SBA;
+ }
+ else /* MASA_FORMAT */
+ {
+ hQMetaData->qmetadata_max_bit_req = QMETADATA_MAXBIT_REQ_MASA;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_qmetadata_azimuth_elevation_to_direction_vector()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+void ivas_qmetadata_azimuth_elevation_to_direction_vector(
+ const float az, /* i : azimuth */
+ const float el, /* i : elevation */
+ float *dv /* o : direction vector */
+)
+{
+ float radius_length;
+
+
+ dv[2] = sinf( el * PI_OVER_180 );
+ radius_length = cosf( el * PI_OVER_180 );
+ dv[0] = radius_length * cosf( az * PI_OVER_180 );
+ dv[1] = radius_length * sinf( az * PI_OVER_180 );
+
+ return;
+}
+
+/*-------------------------------------------------------------------------
+ * ivas_qmetadata_direction_vector_to_azimuth_elevation()
+ *
+ * azimuth between [-180, 180]
+ * elevation between [-90 and 90]
+ *------------------------------------------------------------------------*/
+
+void ivas_qmetadata_direction_vector_to_azimuth_elevation(
+ const float *dv, /* i : direction vector */
+ float *az, /* o : azimuth */
+ float *el /* o : elevation */
+)
+{
+ /* note: dv does not need to have unit L_2 norm, because the conversion is scale invariant */
+
+ *el = atan2f( dv[2], sqrtf( dv[0] * dv[0] + dv[1] * dv[1] ) ) * _180_OVER_PI;
+ *az = atan2f( dv[1], dv[0] ) * _180_OVER_PI;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_get_df_ratio_bits_hodirac()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+/*! r: bits to be used for quantizing ratio of ratios */
+int16_t ivas_get_df_ratio_bits_hodirac(
+ const int16_t index_diff /* i : index of quantized diffuse-to-total ratio */
+)
+{
+ int16_t dfRatio_bits;
+
+ if ( index_diff >= DIFF_DFRATIO_1BIT_LIMIT_IDX )
+ {
+ dfRatio_bits = 1;
+ }
+ else if ( index_diff >= DIFF_DFRATIO_2BIT_LIMIT_IDX_HODIRAC )
+ {
+ dfRatio_bits = 2;
+ }
+ else
+ {
+ dfRatio_bits = 3;
+ }
+
+ return dfRatio_bits;
+}
+
+/*---------------------------------------------------------------
+ * ivas_get_df_ratio_bits()
+ *
+ * Gives quantization accuracy for distribution factor of
+ * direct-to-total ratios based on the diffuse-to-total ratio
+ * index
+ *--------------------------------------------------------------*/
+
+/*! r: bits to be used for quantizing ratio of ratios */
+int16_t ivas_get_df_ratio_bits(
+ const int16_t index_diff /* i : index of quantized diffuse-to-total ratio */
+)
+{
+ int16_t dfRatio_bits;
+
+ if ( index_diff >= DIFF_DFRATIO_1BIT_LIMIT_IDX )
+ {
+ dfRatio_bits = 1;
+ }
+ else if ( index_diff >= DIFF_DFRATIO_2BIT_LIMIT_IDX )
+ {
+ dfRatio_bits = 2;
+ }
+ else
+ {
+ dfRatio_bits = 3;
+ }
+
+ return dfRatio_bits;
+}
diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..e754fb692bbd3ab149ffcf930c7931c3115e930d
--- /dev/null
+++ b/lib_com/ivas_qspherical_com.c
@@ -0,0 +1,482 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "ivas_prot.h"
+#include "prot.h"
+#include "cnst.h"
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------------------
+ * ivas_qmetadata_reorder_generic()
+ *
+ *------------------------------------------------------------------------*/
+
+uint16_t ivas_qmetadata_reorder_generic(
+ const int16_t signed_value )
+{
+ uint16_t unsigned_value;
+
+ if ( signed_value < 0 )
+ {
+ unsigned_value = ( ( uint16_t ) - ( signed_value + 1 ) << 1 ) + 1;
+ }
+ else
+ {
+ unsigned_value = (uint16_t) signed_value << 1;
+ }
+
+ return unsigned_value;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_qmetadata_dereorder_generic()
+ *
+ * Returns the original value of the array "folded" by ReorderGeneric
+ *------------------------------------------------------------------------*/
+
+/*! r: "Unfolded" value, positive or negative depending on the value of the input */
+int16_t ivas_qmetadata_dereorder_generic(
+ const uint16_t uns_value /* i : unsigned value result of ReorderGeneric */
+)
+{
+ if ( ( uns_value & 1 ) != 0 )
+ {
+ return -(int16_t) ( uns_value >> 1 ) - 1;
+ }
+ else
+ {
+ return (int16_t) ( uns_value >> 1 );
+ }
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_project_elevation_index()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+/*! r: projected elevation index */
+int16_t ivas_dirac_project_elevation_index(
+ const int16_t el_idx, /* i : elevation index */
+ const int16_t el_alph, /* i : number of elevation symbols */
+ const int16_t el_alph_proj /* i : size of projected alphabet */
+)
+{
+ int16_t el_idx_proj;
+
+ /* evaluate floor((el_idx / (el_alph - 1)) * (el_alph_proj - 1) + 0.5) using only integer */
+ el_idx_proj = ( 2 * el_idx * ( el_alph_proj - 1 ) + ( el_alph - 1 ) ) / ( 2 * ( el_alph - 1 ) );
+
+ return el_idx_proj;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_chan_project_elevation_index()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+/*! r: projected index in channel mode */
+int16_t ivas_chan_project_elevation_index(
+ const int16_t el_idx, /* i : elevation index */
+ const int16_t el_alph, /* i : number of elevation symbols */
+ const int16_t el_alph_proj /* i : size of projected alphabet */
+)
+{
+ int16_t el_idx_proj;
+
+ /* evaluate floor((el_idx / (el_alph - 1)) * (el_alph_proj - 1) + 0.5) using only integer */
+ if ( el_idx == el_alph - 1 )
+ {
+ el_idx_proj = el_alph_proj - 1;
+ }
+ else
+ {
+ el_idx_proj = ( 2 * el_idx * el_alph_proj + el_alph ) / ( 2 * el_alph );
+ }
+
+ return el_idx_proj;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_project_azimuth_index()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+/*! r: projected azimuth index */
+int16_t ivas_dirac_project_azimuth_index(
+ const int16_t az_idx, /* i : azimuth index */
+ const int16_t az_alph, /* i : number of azimuth symbols */
+ const int16_t az_alph_proj /* i : size of projected alphabet */
+)
+{
+ int16_t az_idx_proj;
+
+ if ( az_alph_proj == 1 )
+ {
+ return 0;
+ }
+
+ /* evaluate floor((az_idx / az_alph) * az_alph_proj + 0.5) using only integer */
+ az_idx_proj = ( 2 * az_idx * az_alph_proj + az_alph ) / ( 2 * az_alph );
+
+ if ( az_idx_proj == az_alph_proj )
+ {
+ az_idx_proj = 0;
+ }
+
+ return az_idx_proj;
+}
+
+
+/*-------------------------------------------------------------------------
+ * small_reduction_direction()
+ *
+ * Compute the allocated bit reduction in spherical indexing for bit budget
+ * is exceeded by diff. bits
+ *------------------------------------------------------------------------*/
+
+void small_reduction_direction(
+ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */
+ uint16_t bits_dir[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES],
+ const int16_t raw_flag[MASA_MAXIMUM_CODING_SUBBANDS],
+ int16_t *diff )
+{
+ int16_t i, j, k;
+
+ for ( k = 0; ( k < 2 ) && ( *diff > 0 ); k++ )
+ {
+ for ( i = q_direction->cfg.start_band; ( i < q_direction->cfg.nbands ) && ( *diff > 0 ); i++ )
+ {
+ if ( raw_flag[i] == 1 )
+ {
+ for ( j = 0; ( j < q_direction->cfg.nblocks ) && ( *diff > 0 ); j++ )
+ {
+ if ( bits_dir[i][j] > MASA_MIN_BITS_TF )
+ {
+ bits_dir[i][j] -= 1;
+ ( *diff )--;
+ }
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * quantize_phi()
+ *
+ * Quantize azimuth.
+ * Input phi expected to be an angle in degree between 0 and 360.
+ *-----------------------------------------------------------------------*/
+
+/*! r: index azimuth */
+int16_t quantize_phi(
+ float phi, /* i : azimuth value */
+ const int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */
+ float *phi_hat, /* o : quantized azimuth */
+ const int16_t n /* i : azimuth codebook size */
+)
+{
+ int16_t id_phi;
+ float dd;
+ float delta_phi;
+
+
+ delta_phi = 360.0f / (float) n;
+
+ if ( n == 1 )
+ {
+ *phi_hat = 0;
+
+ return 0;
+ }
+
+ if ( ( flag_delta == 1 ) && ( n > 2 ) )
+ {
+ dd = delta_phi / 2.0f;
+ }
+ else
+ {
+ dd = 0;
+ }
+ id_phi = (int16_t) round_f( ( ( phi - 180 - dd ) / (float) delta_phi ) );
+ assert( fabsf( ( phi - 180 - dd ) / (float) delta_phi ) - abs( id_phi ) <= 0.5 );
+
+ if ( id_phi + ( n >> 1 ) < 0 )
+ {
+ id_phi += 1;
+ }
+
+ if ( id_phi - ( n >> 1 ) >= 0 )
+ {
+ id_phi = -( n >> 1 );
+ }
+
+ if ( id_phi == -( ( n >> 1 ) + ( n % 2 ) ) )
+ {
+ id_phi += ( n % 2 );
+ }
+ else
+ {
+ if ( id_phi == ( ( n >> 1 ) + ( n % 2 ) ) )
+ {
+ if ( n % 2 )
+ {
+ id_phi -= 1;
+ }
+ else
+ {
+ id_phi = -id_phi;
+ }
+ }
+ }
+
+ *phi_hat = id_phi * delta_phi + dd + 180;
+
+ id_phi += ( n >> 1 );
+
+ return id_phi;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * companding_azimuth()
+ *
+ * Compand azimuth based on the format
+ *-----------------------------------------------------------------------*/
+
+/*! r: companded azimuth value */
+float companding_azimuth(
+ const float azi, /* i : input azimuth value */
+ const MC_LS_SETUP mc_format, /* i : input channel format */
+ const int16_t theta_flag, /* i : zero/non zero elevation flag */
+ const int16_t direction /* i : direction of companding (direct or inverse)*/
+)
+{
+ const float pointsA[] = { 0.0f, 60.0f, 110.0f, 150.0f, 180.0f, 0.0f, 50.0f, 90.0f, 150.0f, 180.0f, 0.0f, 30.0f, 80.0f, 150.0f, 180.0f };
+ const float pointsB[] = { 0.0f, 90.0f, 110.0f, 170.0f, 180.0f, 0.0f, 90.0f, 110.0f, 170.0f, 180.0f, 0.0f, 10.0f, 100.0f, 170.0f, 180.0f };
+ const float *pA, *pB;
+ int16_t no_points;
+ float comp_azi;
+ int16_t i, not_done, start;
+ float abs_azi;
+
+ if ( mc_format == MC_LS_SETUP_5_1 || mc_format == MC_LS_SETUP_5_1_2 || mc_format == MC_LS_SETUP_5_1_4 ) /* 5.1, 5.1+2 or 5.1+4*/
+ {
+ start = 5;
+ }
+ else
+ {
+ start = 0;
+ }
+
+ /* theta flag 1 is for non zero, larger than a threshold elevation */
+ if ( ( theta_flag == 1 ) && ( ( mc_format == MC_LS_SETUP_5_1_2 ) || ( mc_format == MC_LS_SETUP_5_1_4 ) || ( mc_format == MC_LS_SETUP_7_1_4 ) ) ) /* 5.1+2, 5.1+4 or 7.1+4*/
+ {
+ start = 10;
+ }
+ no_points = 5;
+
+ pA = &pointsA[start];
+ pB = &pointsB[start];
+
+ if ( direction == -1 ) /* inverse companding */
+ {
+ pA = &pointsB[start];
+ pB = &pointsA[start];
+ }
+ else
+ {
+ if ( direction != 1 )
+ {
+ printf( "Wrong direction in companding" );
+ }
+ }
+
+ not_done = 1;
+ abs_azi = fabsf( azi );
+
+ comp_azi = azi;
+ i = 0;
+ while ( not_done && ( i < no_points - 1 ) )
+ {
+ if ( abs_azi <= pA[i + 1] )
+ {
+ not_done = 0;
+ /* calculate companding */
+ comp_azi = pB[i] + ( pB[i + 1] - pB[i] ) / ( pA[i + 1] - pA[i] ) * ( abs_azi - pA[i] );
+ }
+ else
+ {
+ i++;
+ }
+ }
+
+ if ( azi < 0 )
+ {
+ comp_azi = -comp_azi;
+ }
+
+ if ( not_done == 1 )
+ {
+ comp_azi = azi;
+ }
+
+ return comp_azi;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * quantize_phi_chan_lbr()
+ *
+ * Quantize azimuth in low-bitrate channel mode.
+ * Input phi expected to be an angle in degree between 0 and 360.
+ *-----------------------------------------------------------------------*/
+
+/*! r: index azimuth */
+int16_t quantize_phi_chan_lbr(
+ const float phi, /* i : azimuth value */
+ float *phi_hat, /* o : quantized azimuth */
+ const int16_t n /* i : azimuth codebook size */
+)
+{
+ int16_t id_phi;
+
+
+ if ( n <= 1 )
+ {
+ *phi_hat = 0;
+
+ return 0;
+ }
+
+ id_phi = squant( fabsf( phi ), phi_hat, cb_azi_chan, n >> 1 );
+
+ if ( phi < 0 && id_phi > 0 )
+ {
+ id_phi = 2 * id_phi - 1;
+ *phi_hat = -*phi_hat;
+ }
+ else
+ {
+ id_phi *= 2;
+ }
+
+ return id_phi;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * quantize_phi_chan_compand()
+ *
+ * Quantize azimuth.
+ * Input phi expected to be an angle in degree between 0 and 360.
+ *-----------------------------------------------------------------------*/
+
+/*! r: index azimuth */
+int16_t quantize_phi_chan_compand(
+ float phi, /* i : azimuth value */
+ float *phi_hat, /* o : quantized azimuth */
+ const int16_t n, /* i : azimuth codebook size */
+ const int16_t theta_flag, /* i : flag signaling high elevation */
+ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */
+)
+{
+ int16_t id_phi;
+ float delta_phi;
+
+
+ if ( n <= 1 )
+ {
+ *phi_hat = 0;
+
+ return 0;
+ }
+
+ phi = companding_azimuth( phi - 180, mc_format, theta_flag, 1 );
+
+ /* quantize companded value */
+ delta_phi = 360.0f / (float) n;
+ id_phi = (int16_t) round_f( ( phi / (float) delta_phi ) );
+
+ if ( id_phi + ( n >> 1 ) < 0 )
+ {
+ id_phi += 1;
+ }
+ if ( id_phi - ( n >> 1 ) >= 0 )
+ {
+ id_phi = -( n >> 1 );
+ }
+
+ if ( id_phi == -( ( n >> 1 ) + ( n % 2 ) ) )
+ {
+ id_phi += ( n % 2 );
+ }
+ else
+ {
+ if ( id_phi == ( ( n >> 1 ) + ( n % 2 ) ) )
+ {
+ if ( n % 2 )
+ {
+ id_phi -= 1;
+ }
+ else
+ {
+ id_phi = -id_phi;
+ }
+ }
+ }
+ *phi_hat = id_phi * delta_phi;
+
+ id_phi += ( n >> 1 );
+
+
+ *phi_hat = companding_azimuth( *phi_hat, mc_format, theta_flag, -1 ) + 180;
+
+ return id_phi;
+}
diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..da44adbdf95f891bce7bf177c2cd871e67b21283
--- /dev/null
+++ b/lib_com/ivas_rom_com.c
@@ -0,0 +1,6538 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository. All Rights Reserved.
+
+ This software is protected by copyright law and by international treaties.
+ The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository retain full ownership rights in their respective contributions in
+ the software. This notice grants no license of any kind, including but not limited to patent
+ license, nor is any license granted by implication, estoppel or otherwise.
+
+ Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
+ contributions.
+
+ This software is provided "AS IS", without any express or implied warranties. The software is in the
+ development stage. It is intended exclusively for experts who have experience with such software and
+ solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
+ and fitness for a particular purpose are hereby disclaimed and excluded.
+
+ Any dispute, controversy or claim arising under or in relation to providing this software shall be
+ submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
+ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
+ the United Nations Convention on Contracts on the International Sales of Goods.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "wmc_auto.h"
+
+/* clang-format off */
+
+/*----------------------------------------------------------------------------------*
+ * Table of IVAS bitrates
+ *----------------------------------------------------------------------------------*/
+
+const int32_t ivas_brate_tbl[SIZE_IVAS_BRATE_TBL] =
+{
+ FRAME_NO_DATA, IVAS_SID_5k2,
+ IVAS_13k2, IVAS_16k4, IVAS_24k4, IVAS_32k, IVAS_48k,
+ IVAS_64k, IVAS_80k, IVAS_96k, IVAS_128k, IVAS_160k,
+ IVAS_192k, IVAS_256k, IVAS_384k, IVAS_512k
+};
+
+
+/*-------------------------------------------------------------------------
+ * DFT Stereo ROM tables
+ *------------------------------------------------------------------------*/
+
+/*4xERB scale: max of 14 bands*/
+const int16_t dft_band_limits_erb4[STEREO_DFT_ERB4_BANDS] =
+{
+ 1, 3, 5, 10, 18, 26, 41, 56, 84, 132, 214, 342, 470, 601
+};
+
+/*8xERB scale: max of 8 bands*/
+const int16_t dft_band_limits_erb8[STEREO_DFT_ERB8_BANDS] =
+{
+ 1, 5, 18, 41, 84, 214, 470, 601
+};
+
+const float dft_res_cod_alpha[STEREO_DFT_BAND_MAX] =
+{
+ .8f, .8f, .5f, .5f, .3f, .3f, .2f, .2f
+};
+
+const int16_t dft_band_ipd[3][4] =
+{
+ {0,8,10,13},
+ {0,5,6,8},
+ {0,2,3,4}
+};
+
+const int16_t dft_band_res_cod[3][4] =
+{
+ {0,8,10,11},
+ {0,5,6,7},
+ {0,5,6,7}
+};
+
+const float dft_res_gains_q[][2] =
+{
+ /* quantization points for joint quantization of prediction gain and residual energy */
+
+ /* column 1 (|ILD| = 0): */
+ { 0.000000f, 0.000000f },
+ { 0.000000f, 0.116982f },
+ { 0.000000f, 0.226991f },
+ { 0.000000f, 0.340693f },
+ { 0.000000f, 0.464549f },
+ { 0.000000f, 0.605079f },
+ { 0.000000f, 0.776250f },
+ { 0.000000f, 1.000000f },
+
+ /* column 2 (|ILD| = 2): */
+ { 0.114623f, 0.000000f },
+ { 0.116171f, 0.115424f },
+ { 0.120448f, 0.223857f },
+ { 0.127733f, 0.335704f },
+ { 0.138966f, 0.457149f },
+ { 0.155840f, 0.594270f },
+ { 0.182248f, 0.760034f },
+ { 0.226274f, 0.974064f },
+
+ /* column 3 (|ILD| = 4): */
+ { 0.226274f, 0.000000f },
+ { 0.229210f, 0.110915f },
+ { 0.237306f, 0.214802f },
+ { 0.251046f, 0.321340f },
+ { 0.272098f, 0.435947f },
+ { 0.303429f, 0.563535f },
+ { 0.351766f, 0.714464f },
+ { 0.430506f, 0.902588f },
+
+ /* column 4 (|ILD| = 6): */
+ { 0.332279f, 0.000000f },
+ { 0.336318f, 0.103909f },
+ { 0.347423f, 0.200786f },
+ { 0.366155f, 0.299242f },
+ { 0.394585f, 0.403641f },
+ { 0.436296f, 0.517359f },
+ { 0.499282f, 0.647470f },
+ { 0.598480f, 0.801138f },
+
+ /* column 5 (|ILD| = 8): */
+ { 0.430506f, 0.000000f },
+ { 0.435293f, 0.095060f },
+ { 0.448405f, 0.183172f },
+ { 0.470357f, 0.271705f },
+ { 0.503282f, 0.363897f },
+ { 0.550751f, 0.461614f },
+ { 0.620606f, 0.568856f },
+ { 0.726386f, 0.687287f },
+
+ /* column 6 (|ILD| = 10): */
+ { 0.519494f, 0.000000f },
+ { 0.524665f, 0.085097f },
+ { 0.538769f, 0.163459f },
+ { 0.562182f, 0.241193f },
+ { 0.596843f, 0.320512f },
+ { 0.645875f, 0.402058f },
+ { 0.716076f, 0.487487f },
+ { 0.818182f, 0.574960f },
+
+ /* column 7 (|ILD| = 13): */
+ { 0.634158f, 0.000000f },
+ { 0.639318f, 0.069554f },
+ { 0.653296f, 0.132950f },
+ { 0.676201f, 0.194597f },
+ { 0.709442f, 0.255549f },
+ { 0.755149f, 0.315316f },
+ { 0.818046f, 0.373555f },
+ { 0.904547f, 0.426375f },
+
+ /* column 8 (|ILD| = 16): */
+ { 0.726386f, 0.000000f },
+ { 0.731048f, 0.054862f },
+ { 0.743597f, 0.104384f },
+ { 0.763914f, 0.151643f },
+ { 0.792863f, 0.197003f },
+ { 0.831670f, 0.239542f },
+ { 0.883261f, 0.278217f },
+ { 0.950993f, 0.309212f },
+
+ /* column 9 (|ILD| = 19): */
+ { 0.798235f, 0.000000f },
+ { 0.802164f, 0.042077f },
+ { 0.812683f, 0.079739f },
+ { 0.829536f, 0.115098f },
+ { 0.853180f, 0.148173f },
+ { 0.884212f, 0.178009f },
+ { 0.924333f, 0.203506f },
+ { 0.975135f, 0.221614f },
+
+ /* column 10 (|ILD| = 22): */
+ { 0.852825f, 0.000000f },
+ { 0.855976f, 0.031585f },
+ { 0.864374f, 0.059662f },
+ { 0.877717f, 0.085671f },
+ { 0.896203f, 0.109492f },
+ { 0.920064f, 0.130302f },
+ { 0.950256f, 0.147176f },
+ { 0.987460f, 0.157870f },
+
+ /* column 11 (|ILD| = 25): */
+ { 0.893520f, 0.000000f },
+ { 0.895958f, 0.023331f },
+ { 0.902435f, 0.043958f },
+ { 0.912657f, 0.062866f },
+ { 0.926684f, 0.079898f },
+ { 0.944559f, 0.094403f },
+ { 0.966814f, 0.105673f },
+ { 0.993695f, 0.112114f },
+
+ /* column 12 (|ILD| = 30): */
+ { 0.938693f, 0.000000f },
+ { 0.940202f, 0.013738f },
+ { 0.944192f, 0.025807f },
+ { 0.950441f, 0.036736f },
+ { 0.958923f, 0.046392f },
+ { 0.969577f, 0.054375f },
+ { 0.982605f, 0.060264f },
+ { 0.998002f, 0.063182f },
+
+ /* column 13 (|ILD| = 35): */
+ { 0.965056f, 0.000000f },
+ { 0.965951f, 0.007932f },
+ { 0.968314f, 0.014873f },
+ { 0.971997f, 0.021112f },
+ { 0.976963f, 0.026561f },
+ { 0.983149f, 0.030984f },
+ { 0.990633f, 0.034143f },
+ { 0.999368f, 0.035554f },
+
+ /* column 14 (|ILD| = 40): */
+ { 0.980198f, 0.000000f },
+ { 0.980717f, 0.004528f },
+ { 0.982085f, 0.008481f },
+ { 0.984212f, 0.012019f },
+ { 0.987068f, 0.015088f },
+ { 0.990608f, 0.017552f },
+ { 0.994866f, 0.019278f },
+ { 0.999800f, 0.019998f },
+
+ /* column 15 (|ILD| = 45): */
+ { 0.988816f, 0.000000f },
+ { 0.989113f, 0.002568f },
+ { 0.989895f, 0.004807f },
+ { 0.991109f, 0.006806f },
+ { 0.992735f, 0.008532f },
+ { 0.994746f, 0.009911f },
+ { 0.997156f, 0.010865f },
+ { 0.999937f, 0.011246f },
+
+ /* column 16 (|ILD| = 50): */
+ { 0.993695f, 0.000000f },
+ { 0.993864f, 0.001451f },
+ { 0.994308f, 0.002715f },
+ { 0.994996f, 0.003842f },
+ { 0.995917f, 0.004813f },
+ { 0.997054f, 0.005586f },
+ { 0.998414f, 0.006117f },
+ { 0.999980f, 0.006324f }
+};
+
+const float dft_trigo_12k8[STEREO_DFT_N_12k8_ENC / 4 + 1] =
+{
+ 0.0000000f, 0.0122715f, 0.0245412f, 0.0368072f, 0.0490677f, 0.0613207f, 0.0735646f, 0.0857973f, 0.0980171f, 0.1102222f, 0.1224107f, 0.1345807f, 0.1467305f, 0.1588581f,
+ 0.1709619f, 0.1830399f, 0.1950903f, 0.2071114f, 0.2191012f, 0.2310581f, 0.2429802f, 0.2548657f, 0.2667128f, 0.2785197f, 0.2902847f, 0.3020059f, 0.3136817f, 0.3253103f,
+ 0.3368899f, 0.3484187f, 0.3598950f, 0.3713172f, 0.3826834f, 0.3939920f, 0.4052413f, 0.4164296f, 0.4275551f, 0.4386162f, 0.4496113f, 0.4605387f, 0.4713967f, 0.4821838f,
+ 0.4928982f, 0.5035384f, 0.5141027f, 0.5245897f, 0.5349976f, 0.5453250f, 0.5555702f, 0.5657318f, 0.5758082f, 0.5857979f, 0.5956993f, 0.6055110f, 0.6152316f, 0.6248595f,
+ 0.6343933f, 0.6438315f, 0.6531728f, 0.6624158f, 0.6715590f, 0.6806010f, 0.6895405f, 0.6983762f, 0.7071068f, 0.7157308f, 0.7242471f, 0.7326543f, 0.7409511f, 0.7491364f,
+ 0.7572088f, 0.7651673f, 0.7730105f, 0.7807372f, 0.7883464f, 0.7958369f, 0.8032075f, 0.8104572f, 0.8175848f, 0.8245893f, 0.8314696f, 0.8382247f, 0.8448536f, 0.8513552f,
+ 0.8577286f, 0.8639729f, 0.8700870f, 0.8760701f, 0.8819213f, 0.8876396f, 0.8932243f, 0.8986745f, 0.9039893f, 0.9091680f, 0.9142098f, 0.9191139f, 0.9238795f, 0.9285061f,
+ 0.9329928f, 0.9373390f, 0.9415441f, 0.9456073f, 0.9495282f, 0.9533060f, 0.9569403f, 0.9604305f, 0.9637761f, 0.9669765f, 0.9700313f, 0.9729400f, 0.9757021f, 0.9783174f,
+ 0.9807853f, 0.9831055f, 0.9852776f, 0.9873014f, 0.9891765f, 0.9909026f, 0.9924795f, 0.9939070f, 0.9951847f, 0.9963126f, 0.9972905f, 0.9981181f, 0.9987955f, 0.9993224f,
+ 0.9996988f, 0.9999247f, 1.0000000f
+};
+
+const float dft_trigo_32k[STEREO_DFT_N_32k_ENC / 4 + 1] =
+{
+ 0.0000000f, 0.0049087f, 0.0098173f, 0.0147257f, 0.0196337f, 0.0245412f, 0.0294482f, 0.0343544f, 0.0392598f, 0.0441643f, 0.0490677f, 0.0539699f, 0.0588708f, 0.0637703f,
+ 0.0686683f, 0.0735646f, 0.0784591f, 0.0833517f, 0.0882424f, 0.0931309f, 0.0980171f, 0.1029010f, 0.1077825f, 0.1126613f, 0.1175374f, 0.1224107f, 0.1272810f, 0.1321483f,
+ 0.1370123f, 0.1418731f, 0.1467305f, 0.1515843f, 0.1564345f, 0.1612809f, 0.1661234f, 0.1709619f, 0.1757963f, 0.1806264f, 0.1854522f, 0.1902736f, 0.1950903f, 0.1999024f,
+ 0.2047096f, 0.2095119f, 0.2143092f, 0.2191012f, 0.2238880f, 0.2286695f, 0.2334454f, 0.2382156f, 0.2429802f, 0.2477389f, 0.2524916f, 0.2572382f, 0.2619786f, 0.2667128f,
+ 0.2714404f, 0.2761616f, 0.2808761f, 0.2855838f, 0.2902847f, 0.2949785f, 0.2996653f, 0.3043448f, 0.3090170f, 0.3136817f, 0.3183389f, 0.3229884f, 0.3276302f, 0.3322640f,
+ 0.3368899f, 0.3415076f, 0.3461171f, 0.3507182f, 0.3553109f, 0.3598950f, 0.3644705f, 0.3690372f, 0.3735950f, 0.3781438f, 0.3826834f, 0.3872139f, 0.3917350f, 0.3962467f,
+ 0.4007488f, 0.4052413f, 0.4097240f, 0.4141969f, 0.4186597f, 0.4231125f, 0.4275551f, 0.4319874f, 0.4364092f, 0.4408206f, 0.4452213f, 0.4496113f, 0.4539905f, 0.4583587f,
+ 0.4627159f, 0.4670620f, 0.4713967f, 0.4757202f, 0.4800321f, 0.4843325f, 0.4886212f, 0.4928982f, 0.4971633f, 0.5014164f, 0.5056574f, 0.5098862f, 0.5141027f, 0.5183069f,
+ 0.5224986f, 0.5266776f, 0.5308440f, 0.5349976f, 0.5391383f, 0.5432660f, 0.5473807f, 0.5514821f, 0.5555702f, 0.5596450f, 0.5637063f, 0.5677540f, 0.5717880f, 0.5758082f,
+ 0.5798145f, 0.5838069f, 0.5877853f, 0.5917494f, 0.5956993f, 0.5996348f, 0.6035559f, 0.6074625f, 0.6113544f, 0.6152316f, 0.6190939f, 0.6229414f, 0.6267738f, 0.6305912f,
+ 0.6343933f, 0.6381801f, 0.6419516f, 0.6457076f, 0.6494480f, 0.6531728f, 0.6568819f, 0.6605751f, 0.6642524f, 0.6679137f, 0.6715590f, 0.6751880f, 0.6788007f, 0.6823972f,
+ 0.6859771f, 0.6895405f, 0.6930874f, 0.6966175f, 0.7001308f, 0.7036273f, 0.7071068f, 0.7105693f, 0.7140146f, 0.7174427f, 0.7208536f, 0.7242471f, 0.7276231f, 0.7309816f,
+ 0.7343225f, 0.7376457f, 0.7409511f, 0.7442387f, 0.7475083f, 0.7507599f, 0.7539935f, 0.7572088f, 0.7604060f, 0.7635848f, 0.7667452f, 0.7698871f, 0.7730105f, 0.7761152f,
+ 0.7792012f, 0.7822685f, 0.7853169f, 0.7883464f, 0.7913569f, 0.7943484f, 0.7973207f, 0.8002737f, 0.8032075f, 0.8061220f, 0.8090170f, 0.8118925f, 0.8147485f, 0.8175848f,
+ 0.8204014f, 0.8231983f, 0.8259753f, 0.8287325f, 0.8314696f, 0.8341867f, 0.8368838f, 0.8395606f, 0.8422172f, 0.8448536f, 0.8474695f, 0.8500651f, 0.8526402f, 0.8551947f,
+ 0.8577286f, 0.8602419f, 0.8627344f, 0.8652061f, 0.8676570f, 0.8700870f, 0.8724960f, 0.8748840f, 0.8772509f, 0.8795967f, 0.8819213f, 0.8842246f, 0.8865066f, 0.8887673f,
+ 0.8910065f, 0.8932243f, 0.8954206f, 0.8975952f, 0.8997483f, 0.9018797f, 0.9039893f, 0.9060771f, 0.9081432f, 0.9101873f, 0.9122095f, 0.9142098f, 0.9161880f, 0.9181441f,
+ 0.9200781f, 0.9219899f, 0.9238795f, 0.9257469f, 0.9275919f, 0.9294146f, 0.9312149f, 0.9329928f, 0.9347482f, 0.9364810f, 0.9381913f, 0.9398790f, 0.9415441f, 0.9431864f,
+ 0.9448060f, 0.9464029f, 0.9479770f, 0.9495282f, 0.9510565f, 0.9525619f, 0.9540444f, 0.9555039f, 0.9569403f, 0.9583537f, 0.9597440f, 0.9611112f, 0.9624552f, 0.9637761f,
+ 0.9650737f, 0.9663480f, 0.9675991f, 0.9688268f, 0.9700313f, 0.9712123f, 0.9723699f, 0.9735041f, 0.9746149f, 0.9757021f, 0.9767659f, 0.9778061f, 0.9788228f, 0.9798158f,
+ 0.9807853f, 0.9817311f, 0.9826533f, 0.9835518f, 0.9844266f, 0.9852776f, 0.9861050f, 0.9869085f, 0.9876883f, 0.9884443f, 0.9891765f, 0.9898849f, 0.9905693f, 0.9912300f,
+ 0.9918667f, 0.9924795f, 0.9930685f, 0.9936335f, 0.9941745f, 0.9946916f, 0.9951847f, 0.9956539f, 0.9960990f, 0.9965202f, 0.9969173f, 0.9972905f, 0.9976395f, 0.9979646f,
+ 0.9982656f, 0.9985426f, 0.9987955f, 0.9990243f, 0.9992290f, 0.9994097f, 0.9995663f, 0.9996988f, 0.9998072f, 0.9998916f, 0.9999518f, 0.9999880f, 1.0000000f
+};
+
+const float dft_trigo_48k[STEREO_DFT_N_MAX_ENC / 4 + 1] =
+{
+ 0.0000000f, 0.0032725f, 0.0065449f, 0.0098173f, 0.0130896f, 0.0163617f, 0.0196337f, 0.0229054f, 0.0261769f, 0.0294482f, 0.0327191f, 0.0359896f, 0.0392598f, 0.0425296f,
+ 0.0457989f, 0.0490677f, 0.0523360f, 0.0556037f, 0.0588708f, 0.0621373f, 0.0654031f, 0.0686683f, 0.0719327f, 0.0751963f, 0.0784591f, 0.0817211f, 0.0849822f, 0.0882424f,
+ 0.0915016f, 0.0947599f, 0.0980171f, 0.1012733f, 0.1045285f, 0.1077825f, 0.1110353f, 0.1142870f, 0.1175374f, 0.1207866f, 0.1240345f, 0.1272810f, 0.1305262f, 0.1337700f,
+ 0.1370123f, 0.1402532f, 0.1434926f, 0.1467305f, 0.1499668f, 0.1532014f, 0.1564345f, 0.1596658f, 0.1628955f, 0.1661234f, 0.1693495f, 0.1725738f, 0.1757963f, 0.1790169f,
+ 0.1822355f, 0.1854522f, 0.1886670f, 0.1918797f, 0.1950903f, 0.1982989f, 0.2015053f, 0.2047096f, 0.2079117f, 0.2111116f, 0.2143092f, 0.2175045f, 0.2206974f, 0.2238880f,
+ 0.2270763f, 0.2302620f, 0.2334454f, 0.2366262f, 0.2398045f, 0.2429802f, 0.2461533f, 0.2493238f, 0.2524916f, 0.2556567f, 0.2588190f, 0.2619786f, 0.2651354f, 0.2682894f,
+ 0.2714404f, 0.2745886f, 0.2777338f, 0.2808761f, 0.2840153f, 0.2871515f, 0.2902847f, 0.2934147f, 0.2965416f, 0.2996653f, 0.3027858f, 0.3059030f, 0.3090170f, 0.3121277f,
+ 0.3152350f, 0.3183389f, 0.3214395f, 0.3245366f, 0.3276302f, 0.3307203f, 0.3338069f, 0.3368899f, 0.3399692f, 0.3430450f, 0.3461171f, 0.3491854f, 0.3522500f, 0.3553109f,
+ 0.3583679f, 0.3614212f, 0.3644705f, 0.3675159f, 0.3705574f, 0.3735950f, 0.3766285f, 0.3796580f, 0.3826834f, 0.3857048f, 0.3887220f, 0.3917350f, 0.3947439f, 0.3977485f,
+ 0.4007488f, 0.4037449f, 0.4067366f, 0.4097240f, 0.4127070f, 0.4156856f, 0.4186597f, 0.4216294f, 0.4245945f, 0.4275551f, 0.4305111f, 0.4334625f, 0.4364092f, 0.4393513f,
+ 0.4422887f, 0.4452213f, 0.4481492f, 0.4510723f, 0.4539905f, 0.4569039f, 0.4598124f, 0.4627159f, 0.4656145f, 0.4685081f, 0.4713967f, 0.4742803f, 0.4771588f, 0.4800321f,
+ 0.4829003f, 0.4857634f, 0.4886212f, 0.4914739f, 0.4943212f, 0.4971633f, 0.5000000f, 0.5028314f, 0.5056574f, 0.5084780f, 0.5112931f, 0.5141027f, 0.5169069f, 0.5197055f,
+ 0.5224986f, 0.5252860f, 0.5280679f, 0.5308440f, 0.5336145f, 0.5363793f, 0.5391383f, 0.5418916f, 0.5446390f, 0.5473807f, 0.5501164f, 0.5528463f, 0.5555702f, 0.5582882f,
+ 0.5610003f, 0.5637063f, 0.5664062f, 0.5691001f, 0.5717880f, 0.5744697f, 0.5771452f, 0.5798145f, 0.5824777f, 0.5851346f, 0.5877853f, 0.5904296f, 0.5930676f, 0.5956993f,
+ 0.5983246f, 0.6009435f, 0.6035559f, 0.6061619f, 0.6087614f, 0.6113544f, 0.6139408f, 0.6165207f, 0.6190939f, 0.6216606f, 0.6242205f, 0.6267738f, 0.6293204f, 0.6318602f,
+ 0.6343933f, 0.6369196f, 0.6394390f, 0.6419516f, 0.6444573f, 0.6469562f, 0.6494480f, 0.6519330f, 0.6544109f, 0.6568819f, 0.6593458f, 0.6618027f, 0.6642524f, 0.6666951f,
+ 0.6691306f, 0.6715590f, 0.6739801f, 0.6763941f, 0.6788007f, 0.6812002f, 0.6835923f, 0.6859771f, 0.6883546f, 0.6907247f, 0.6930874f, 0.6954426f, 0.6977905f, 0.7001308f,
+ 0.7024637f, 0.7047890f, 0.7071068f, 0.7094170f, 0.7117196f, 0.7140146f, 0.7163019f, 0.7185816f, 0.7208536f, 0.7231179f, 0.7253744f, 0.7276231f, 0.7298641f, 0.7320972f,
+ 0.7343225f, 0.7365399f, 0.7387495f, 0.7409511f, 0.7431448f, 0.7453306f, 0.7475083f, 0.7496781f, 0.7518398f, 0.7539935f, 0.7561391f, 0.7582766f, 0.7604060f, 0.7625272f,
+ 0.7646403f, 0.7667452f, 0.7688418f, 0.7709303f, 0.7730105f, 0.7750824f, 0.7771460f, 0.7792012f, 0.7812482f, 0.7832867f, 0.7853169f, 0.7873387f, 0.7893520f, 0.7913569f,
+ 0.7933533f, 0.7953413f, 0.7973207f, 0.7992915f, 0.8012538f, 0.8032075f, 0.8051526f, 0.8070891f, 0.8090170f, 0.8109362f, 0.8128467f, 0.8147485f, 0.8166416f, 0.8185259f,
+ 0.8204014f, 0.8222682f, 0.8241262f, 0.8259753f, 0.8278156f, 0.8296471f, 0.8314696f, 0.8332833f, 0.8350880f, 0.8368838f, 0.8386706f, 0.8404484f, 0.8422172f, 0.8439770f,
+ 0.8457278f, 0.8474695f, 0.8492022f, 0.8509257f, 0.8526402f, 0.8543455f, 0.8560416f, 0.8577286f, 0.8594064f, 0.8610750f, 0.8627344f, 0.8643845f, 0.8660254f, 0.8676570f,
+ 0.8692793f, 0.8708923f, 0.8724960f, 0.8740903f, 0.8756753f, 0.8772509f, 0.8788171f, 0.8803739f, 0.8819213f, 0.8834592f, 0.8849876f, 0.8865066f, 0.8880161f, 0.8895161f,
+ 0.8910065f, 0.8924874f, 0.8939588f, 0.8954206f, 0.8968727f, 0.8983153f, 0.8997483f, 0.9011716f, 0.9025853f, 0.9039893f, 0.9053836f, 0.9067683f, 0.9081432f, 0.9095084f,
+ 0.9108638f, 0.9122095f, 0.9135455f, 0.9148716f, 0.9161880f, 0.9174945f, 0.9187912f, 0.9200781f, 0.9213551f, 0.9226223f, 0.9238795f, 0.9251269f, 0.9263644f, 0.9275919f,
+ 0.9288096f, 0.9300172f, 0.9312149f, 0.9324027f, 0.9335804f, 0.9347482f, 0.9359059f, 0.9370536f, 0.9381913f, 0.9393190f, 0.9404366f, 0.9415441f, 0.9426415f, 0.9437288f,
+ 0.9448060f, 0.9458732f, 0.9469301f, 0.9479770f, 0.9490136f, 0.9500402f, 0.9510565f, 0.9520627f, 0.9530586f, 0.9540444f, 0.9550199f, 0.9559853f, 0.9569403f, 0.9578852f,
+ 0.9588197f, 0.9597440f, 0.9606581f, 0.9615618f, 0.9624552f, 0.9633384f, 0.9642112f, 0.9650737f, 0.9659258f, 0.9667676f, 0.9675991f, 0.9684202f, 0.9692309f, 0.9700313f,
+ 0.9708212f, 0.9716008f, 0.9723699f, 0.9731287f, 0.9738770f, 0.9746149f, 0.9753423f, 0.9760593f, 0.9767659f, 0.9774620f, 0.9781476f, 0.9788228f, 0.9794874f, 0.9801416f,
+ 0.9807853f, 0.9814185f, 0.9820411f, 0.9826533f, 0.9832549f, 0.9838460f, 0.9844266f, 0.9849966f, 0.9855561f, 0.9861050f, 0.9866433f, 0.9871711f, 0.9876883f, 0.9881950f,
+ 0.9886910f, 0.9891765f, 0.9896514f, 0.9901157f, 0.9905693f, 0.9910124f, 0.9914449f, 0.9918667f, 0.9922779f, 0.9926785f, 0.9930685f, 0.9934478f, 0.9938165f, 0.9941745f,
+ 0.9945219f, 0.9948586f, 0.9951847f, 0.9955002f, 0.9958049f, 0.9960990f, 0.9963825f, 0.9966552f, 0.9969173f, 0.9971688f, 0.9974095f, 0.9976395f, 0.9978589f, 0.9980676f,
+ 0.9982656f, 0.9984529f, 0.9986295f, 0.9987955f, 0.9989507f, 0.9990952f, 0.9992290f, 0.9993522f, 0.9994646f, 0.9995663f, 0.9996573f, 0.9997376f, 0.9998072f, 0.9998661f,
+ 0.9999143f, 0.9999518f, 0.9999786f, 0.9999946f, 1.0000000f
+};
+
+/* tables for adaptive Golomb-Rice coding of DFT stereo parameters */
+const int16_t dft_code_itd[] =
+{
+ 0, 3, 4, 13, 8, 9, 12, 5, 10, 44, 23, 60, 45, 31, 235, 59, 28, 61, 234, 116
+};
+
+const int16_t dft_len_itd[] =
+{
+ 2, 3, 4, 4, 4, 4, 4, 4, 4, 6, 5, 6, 6, 5, 8, 6, 5, 6, 8, 7
+};
+
+const int16_t dft_maps_rpg[] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 2, 0, 1, 3, 4, 5, 6, 7,
+ 6, 2, 0, 1, 3, 4, 5, 7,
+ 7, 5, 2, 0, 1, 3, 4, 6,
+ 7, 6, 4, 3, 1, 0, 2, 5,
+ 7, 6, 5, 3, 2, 1, 0, 4,
+ 7, 6, 5, 4, 3, 2, 0, 1,
+ 7, 6, 5, 4, 3, 2, 0, 1,
+ 6, 5, 4, 3, 1, 0, 2, 7,
+};
+
+const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 15, 4, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 12, 9, 4, 1, 0, 2, 3, 5, 6, 7, 8, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 16, 14, 8, 4, 2, 0, 1, 3, 5, 6, 7, 9, 10, 11, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 18, 16, 14, 10, 5, 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 21, 19, 17, 15, 8, 4, 2, 0, 1, 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 21, 19, 17, 15, 12, 8, 4, 0, 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 21, 19, 17, 15, 13, 11, 9, 3, 0, 1, 2, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 24, 22, 20, 18, 16, 14, 12, 9, 6, 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 15, 17, 19, 21, 23, 25, 26, 27, 28, 29, 30,
+ 25, 23, 21, 19, 17, 15, 13, 11, 9, 6, 0, 1, 2, 3, 4, 5, 7, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 27, 28, 29, 30,
+ 27, 25, 23, 21, 19, 17, 15, 13, 11, 8, 5, 0, 1, 2, 3, 4, 6, 7, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 29, 30,
+ 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 0, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 28, 29, 30,
+ 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 30,
+ 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
+ 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
+ 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 0, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29,
+ 30, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28,
+ 30, 29, 28, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26,
+ 30, 29, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 9, 7, 6, 4, 3, 2, 1, 0, 5, 8, 11, 13, 15, 17, 19, 21, 23, 25, 27,
+ 30, 29, 28, 27, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 7, 5, 4, 3, 2, 1, 0, 6, 9, 11, 13, 15, 17, 19, 21, 23, 25,
+ 30, 29, 28, 27, 26, 25, 23, 21, 19, 17, 15, 13, 11, 10, 8, 7, 5, 4, 3, 2, 1, 0, 6, 9, 12, 14, 16, 18, 20, 22, 24,
+ 30, 29, 28, 27, 26, 25, 24, 23, 22, 20, 18, 16, 14, 12, 10, 8, 7, 6, 5, 4, 2, 1, 0, 3, 9, 11, 13, 15, 17, 19, 21,
+ 30, 29, 28, 27, 26, 25, 24, 23, 22, 20, 18, 16, 14, 13, 11, 10, 9, 7, 6, 5, 3, 2, 1, 0, 4, 8, 12, 15, 17, 19, 21,
+ 30, 29, 28, 27, 26, 25, 24, 23, 22, 20, 18, 16, 14, 13, 12, 11, 10, 9, 7, 6, 5, 3, 1, 0, 2, 4, 8, 15, 17, 19, 21,
+ 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 17, 15, 13, 12, 11, 9, 8, 7, 6, 4, 3, 2, 1, 0, 5, 10, 14, 16, 18,
+ 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 15, 13, 12, 11, 10, 9, 7, 6, 5, 3, 1, 0, 2, 4, 8, 14, 16,
+ 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 11, 10, 8, 7, 6, 5, 3, 2, 0, 1, 4, 9, 12,
+ 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 3, 2, 1, 0, 4, 15,
+ 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 0, 1,
+ 30, 29, 28, 27, 26, 25, 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
+};
+
+
+/*-------------------------------------------------------------------------
+ * Range Coder ROM tables
+ *------------------------------------------------------------------------*/
+
+/* Create separate tables for cumulative frequency and symbol frequency */
+const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS] =
+{
+ { 0,16,47,153,241,269,325,468,591,674,798,912,1017,1082,1183,1277,1364,16384 },
+ { 0,7401,7844,7886,7899,12065,12718,12790,12805,14099,14476,14533,14549,15058,15264,15299,15310,16384 },
+ { 0,4362,6345,6864,7038,9037,11049,11736,12002,12569,13301,13656,13822,14021,14334,14515,14607,16384 },
+ { 0,2955,5183,5822,6013,8153,10671,11614,11943,12586,13540,14025,14232,14437,14770,14978,15080,16384 },
+ { 0,3155,4981,5615,5855,7969,9953,10739,11073,11936,12837,13208,13383,13767,14203,14400,14498,16384 },
+ { 0,1216,2630,3264,3558,4831,6679,7661,8157,8709,9622,10204,10542,10799,11243,11568,11777,16384 },
+ { 0,1759,3641,4350,4612,6325,8678,9732,10161,10790,11790,12361,12642,12883,13295,13566,13720,16384 },
+ { 0,1109,2705,3433,3732,5226,7532,8732,9263,9978,11142,11842,12188,12490,12986,13321,13520,16384 },
+ { 0,11524,13046,13170,13191,14956,15708,15813,15837,16028,16162,16195,16204,16245,16282,16295,16300,16384 },
+ { 0,8027,10586,10909,10974,13291,14861,15157,15232,15535,15824,15914,15943,16014,16090,16123,16136,16384 },
+ { 0,834,2034,2674,2997,4087,5843,6891,7455,8030,9013,9688,10085,10376,10893,11277,11528,16384 },
+ { 0,6038,9086,9451,9519,12332,14521,14913,15003,15329,15711,15848,15893,15955,16045,16091,16111,16384 },
+ { 0,4732,7685,8354,8545,10717,12924,13618,13852,14291,14842,15083,15181,15314,15491,15582,15625,16384 },
+ { 0,745,1783,2347,2655,3537,4963,5864,6406,6863,7664,8248,8634,8891,9351,9708,9958,16384 },
+ { 0,3957,6794,7669,7998,9743,11676,12498,12869,13313,13894,14186,14332,14498,14714,14835,14906,16384 },
+ { 0,2779,5388,6021,6201,8582,11352,12260,12544,13117,13981,14408,14580,14751,15039,15213,15298,16384 },
+ { 0,448,1160,1625,1920,2576,3706,4518,5053,5474,6234,6835,7262,7531,8032,8446,8758,16384 },
+ { 0,1,2,1555,2246,2247,2248,3489,4112,5449,6596,7302,7710,8311,8876,9266,9517,16384 },
+ { 0,2496,4910,5544,5722,8049,10799,11689,11973,12583,13467,13878,14047,14234,14537,14712,14803,16384 },
+ { 0,921,2222,2880,3188,4407,6321,7406,7955,8573,9616,10296,10679,10978,11502,11880,12118,16384 },
+ { 0,2620,4443,5017,5233,7072,9213,10083,10441,11049,11954,12442,12676,12918,13310,13565,13705,16384 },
+ { 0,11205,13084,13178,13187,15164,16010,16081,16091,16213,16303,16321,16325,16340,16355,16360,16362,16384 },
+ { 0,358,916,1288,1542,2055,2937,3594,4062,4399,5017,5524,5907,6136,6573,6941,7236,16384 },
+ { 0,3575,5093,5536,5735,7408,9185,9878,10188,10727,11497,11933,12165,12410,12794,13019,13166,16384 },
+ { 0,1,2,640,1036,1037,1038,1670,2096,2696,3287,3732,4056,4417,4800,5106,5339,16384 },
+ { 0,969,1397,1518,1578,2633,3338,3566,3675,4197,4664,4857,4957,5288,5625,5783,5874,16384 },
+ { 0,10458,12104,12294,12331,14246,15264,15437,15481,15752,15971,16031,16050,16120,16186,16210,16218,16384 },
+ { 0,7178,9744,10039,10093,12701,14612,14961,15042,15360,15732,15869,15917,15978,16070,16117,16139,16384 },
+ { 0,1298,2418,2879,3113,4146,5509,6227,6621,7053,7755,8229,8539,8776,9186,9492,9714,16384 },
+ { 0,4957,7785,8252,8357,10978,13372,13955,14114,14561,15140,15378,15464,15570,15730,15820,15860,16384 },
+ { 0,4823,8164,8570,8647,11604,14169,14653,14763,15105,15554,15727,15785,15852,15960,16018,16045,16384 },
+ { 0,4735,7010,7517,7660,9986,12230,12914,13131,13666,14374,14689,14814,14972,15212,15342,15404,16384 },
+ { 0,3363,5881,6658,6941,8864,11113,12015,12368,12889,13643,14019,14203,14394,14665,14823,14906,16384 },
+ { 0,2569,4996,5779,6068,7917,10251,11209,11602,12129,12918,13321,13520,13696,13976,14155,14259,16384 },
+ { 0,209,577,848,1046,1378,1982,2465,2835,3072,3513,3893,4202,4374,4703,4994,5241,16384 },
+ { 0,2074,4337,5048,5274,7319,10003,11066,11446,12105,13112,13652,13885,14100,14464,14691,14810,16384 },
+ { 0,1619,3560,4288,4550,6381,8955,10102,10543,11239,12362,12982,13261,13516,13958,14234,14381,16384 },
+ { 0,89,257,441,582,734,1024,1325,1568,1716,1983,2222,2430,2545,2750,2941,3109,16384 },
+ { 0,2202,3563,4044,4264,5686,7344,8100,8476,9006,9835,10331,10612,10864,11304,11599,11787,16384 },
+ { 0,1220,2801,3492,3784,5223,7387,8496,8998,9640,10711,11369,11711,11993,12486,12829,13035,16384 },
+ { 0,12626,13813,13903,13917,15396,15906,15972,15987,16139,16230,16251,16257,16289,16315,16323,16326,16384 },
+ { 0,1579,3191,3831,4099,5678,7788,8761,9206,9842,10821,11388,11681,11958,12417,12722,12902,16384 },
+ { 0,597,1514,2064,2379,3237,4679,5637,6213,6733,7649,8316,8755,9052,9599,10023,10323,16384 },
+ { 0,9273,11762,12080,12151,14038,15210,15446,15514,15725,15929,15995,16019,16068,16124,16148,16158,16384 },
+ { 0,9238,11681,11852,11872,14306,15644,15801,15828,16013,16183,16231,16243,16266,16297,16312,16318,16384 },
+ { 0,6791,9200,9531,9594,12240,14178,14552,14639,15064,15506,15643,15687,15785,15908,15960,15983,16384 },
+ { 0,7175,10415,10905,11033,13038,14621,15002,15123,15367,15651,15762,15806,15864,15938,15974,15992,16384 },
+ { 0,5060,7703,8132,8225,10934,13270,13778,13911,14397,14972,15173,15242,15367,15537,15619,15654,16384 },
+ { 0,3721,6311,6857,6992,9557,12180,12895,13098,13671,14418,14718,14830,14984,15212,15333,15390,16384 },
+ { 0,5971,9288,10044,10269,11991,13680,14228,14437,14750,15130,15293,15374,15459,15579,15642,15677,16384 },
+ { 0,3047,5311,5907,6078,8339,10850,11679,11946,12580,13442,13854,14024,14220,14534,14716,14810,16384 },
+ { 0,2061,4280,4993,5228,7201,9735,10735,11097,11708,12606,13082,13295,13498,13836,14043,14161,16384 },
+ { 0,4738,7949,8880,9234,10781,12502,13214,13531,13897,14355,14593,14718,14835,14998,15096,15153,16384 },
+ { 0,3237,5045,5632,5860,7609,9702,10608,10986,11571,12476,12978,13230,13451,13830,14074,14208,16384 },
+ { 0,1833,3889,4677,5028,6422,8379,9378,9884,10350,11086,11545,11809,12003,12327,12559,12711,16384 },
+ { 0,3989,6858,7352,7459,10254,12936,13571,13735,14240,14895,15153,15242,15364,15548,15646,15690,16384 },
+ { 0,1463,3197,3909,4220,5626,7609,8632,9127,9657,10520,11078,11380,11607,11991,12265,12442,16384 },
+ { 0,14233,15083,15108,15110,16069,16300,16314,16316,16352,16370,16373,16374,16377,16380,16381,16382,16384 },
+ { 0,1,2,2610,3293,3294,3295,5097,5671,8467,10332,11119,11437,12223,12850,13185,13345,16384 },
+ { 0,2010,4053,4696,4910,6879,9391,10386,10750,11393,12376,12886,13119,13348,13726,13967,14099,16384 },
+ { 0,7586,10517,10758,10791,13543,15346,15577,15619,15846,16082,16150,16169,16202,16245,16265,16273,16384 },
+ { 0,3059,5772,6369,6524,9041,11801,12582,12813,13361,14115,14439,14567,14714,14944,15075,15141,16384 },
+ { 0,8643,10594,10813,10856,13274,14686,14920,14975,15350,15680,15771,15799,15897,16003,16042,16057,16384 },
+ { 0,6720,8878,9325,9467,11564,13248,13744,13929,14384,14880,15087,15167,15311,15488,15569,15607,16384 },
+};
+
+const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] =
+{
+ { 16,31,106,88,28,56,143,123,83,124,114,105,65,101,94,87,15020 },
+ { 7401,443,42,13,4166,653,72,15,1294,377,57,16,509,206,35,11,1074 },
+ { 4362,1983,519,174,1999,2012,687,266,567,732,355,166,199,313,181,92,1777 },
+ { 2955,2228,639,191,2140,2518,943,329,643,954,485,207,205,333,208,102,1304 },
+ { 3155,1826,634,240,2114,1984,786,334,863,901,371,175,384,436,197,98,1886 },
+ { 1216,1414,634,294,1273,1848,982,496,552,913,582,338,257,444,325,209,4607 },
+ { 1759,1882,709,262,1713,2353,1054,429,629,1000,571,281,241,412,271,154,2664 },
+ { 1109,1596,728,299,1494,2306,1200,531,715,1164,700,346,302,496,335,199,2864 },
+ { 11524,1522,124,21,1765,752,105,24,191,134,33,9,41,37,13,5,84 },
+ { 8027,2559,323,65,2317,1570,296,75,303,289,90,29,71,76,33,13,248 },
+ { 834,1200,640,323,1090,1756,1048,564,575,983,675,397,291,517,384,251,4856 },
+ { 6038,3048,365,68,2813,2189,392,90,326,382,137,45,62,90,46,20,273 },
+ { 4732,2953,669,191,2172,2207,694,234,439,551,241,98,133,177,91,43,759 },
+ { 745,1038,564,308,882,1426,901,542,457,801,584,386,257,460,357,250,6426 },
+ { 3957,2837,875,329,1745,1933,822,371,444,581,292,146,166,216,121,71,1478 },
+ { 2779,2609,633,180,2381,2770,908,284,573,864,427,172,171,288,174,85,1086 },
+ { 448,712,465,295,656,1130,812,535,421,760,601,427,269,501,414,312,7626 },
+ { 1,1,1553,691,1,1,1241,623,1337,1147,706,408,601,565,390,251,6867 },
+ { 2496,2414,634,178,2327,2750,890,284,610,884,411,169,187,303,175,91,1581 },
+ { 921,1301,658,308,1219,1914,1085,549,618,1043,680,383,299,524,378,238,4266 },
+ { 2620,1823,574,216,1839,2141,870,358,608,905,488,234,242,392,255,140,2679 },
+ { 11205,1879,94,9,1977,846,71,10,122,90,18,4,15,15,5,2,22 },
+ { 358,558,372,254,513,882,657,468,337,618,507,383,229,437,368,295,9148 },
+ { 3575,1518,443,199,1673,1777,693,310,539,770,436,232,245,384,225,147,3218 },
+ { 1,1,638,396,1,1,632,426,600,591,445,324,361,383,306,233,11045 },
+ { 969,428,121,60,1055,705,228,109,522,467,193,100,331,337,158,91,10510 },
+ { 10458,1646,190,37,1915,1018,173,44,271,219,60,19,70,66,24,8,166 },
+ { 7178,2566,295,54,2608,1911,349,81,318,372,137,48,61,92,47,22,245 },
+ { 1298,1120,461,234,1033,1363,718,394,432,702,474,310,237,410,306,222,6670 },
+ { 4957,2828,467,105,2621,2394,583,159,447,579,238,86,106,160,90,40,524 },
+ { 4823,3341,406,77,2957,2565,484,110,342,449,173,58,67,108,58,27,339 },
+ { 4735,2275,507,143,2326,2244,684,217,535,708,315,125,158,240,130,62,980 },
+ { 3363,2518,777,283,1923,2249,902,353,521,754,376,184,191,271,158,83,1478 },
+ { 2569,2427,783,289,1849,2334,958,393,527,789,403,199,176,280,179,104,2125 },
+ { 209,368,271,198,332,604,483,370,237,441,380,309,172,329,291,247,11143 },
+ { 2074,2263,711,226,2045,2684,1063,380,659,1007,540,233,215,364,227,119,1574 },
+ { 1619,1941,728,262,1831,2574,1147,441,696,1123,620,279,255,442,276,147,2003 },
+ { 89,168,184,141,152,290,301,243,148,267,239,208,115,205,191,168,13275 },
+ { 2202,1361,481,220,1422,1658,756,376,530,829,496,281,252,440,295,188,4597 },
+ { 1220,1581,691,292,1439,2164,1109,502,642,1071,658,342,282,493,343,206,3349 },
+ { 12626,1187,90,14,1479,510,66,15,152,91,21,6,32,26,8,3,58 },
+ { 1579,1612,640,268,1579,2110,973,445,636,979,567,293,277,459,305,180,3482 },
+ { 597,917,550,315,858,1442,958,576,520,916,667,439,297,547,424,300,6061 },
+ { 9273,2489,318,71,1887,1172,236,68,211,204,66,24,49,56,24,10,226 },
+ { 9238,2443,171,20,2434,1338,157,27,185,170,48,12,23,31,15,6,66 },
+ { 6791,2409,331,63,2646,1938,374,87,425,442,137,44,98,123,52,23,401 },
+ { 7175,3240,490,128,2005,1583,381,121,244,284,111,44,58,74,36,18,392 },
+ { 5060,2643,429,93,2709,2336,508,133,486,575,201,69,125,170,82,35,730 },
+ { 3721,2590,546,135,2565,2623,715,203,573,747,300,112,154,228,121,57,994 },
+ { 5971,3317,756,225,1722,1689,548,209,313,380,163,81,85,120,63,35,707 },
+ { 3047,2264,596,171,2261,2511,829,267,634,862,412,170,196,314,182,94,1574 },
+ { 2061,2219,713,235,1973,2534,1000,362,611,898,476,213,203,338,207,118,2223 },
+ { 4738,3211,931,354,1547,1721,712,317,366,458,238,125,117,163,98,57,1231 },
+ { 3237,1808,587,228,1749,2093,906,378,585,905,502,252,221,379,244,134,2176 },
+ { 1833,2056,788,351,1394,1957,999,506,466,736,459,264,194,324,232,152,3673 },
+ { 3989,2869,494,107,2795,2682,635,164,505,655,258,89,122,184,98,44,694 },
+ { 1463,1734,712,311,1406,1983,1023,495,530,863,558,302,227,384,274,177,3942 },
+ { 14233,850,25,2,959,231,14,2,36,18,3,1,3,3,1,1,2 },
+ { 1,1,2608,683,1,1,1802,574,2796,1865,787,318,786,627,335,160,3039 },
+ { 2010,2043,643,214,1969,2512,995,364,643,983,510,233,229,378,241,132,2285 },
+ { 7586,2931,241,33,2752,1803,231,42,227,236,68,19,33,43,20,8,111 },
+ { 3059,2713,597,155,2517,2760,781,231,548,754,324,128,147,230,131,66,1243 },
+ { 8643,1951,219,43,2418,1412,234,55,375,330,91,28,98,106,39,15,327 },
+ { 6720,2158,447,142,2097,1684,496,185,455,496,207,80,144,177,81,38,777 },
+};
+
+
+/*-------------------------------------------------------------------------
+ * ECLVQ Stereo ROM tables
+ *------------------------------------------------------------------------*/
+
+/* table with round(ECSQ_PROB_TOTAL / index) for entropy coding, with i in {1, .., ECSQ_SEGMENT_SIZE} */
+const uint16_t ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE] =
+{
+ 0, 16384, 8192, 5461, 4096, 3277, 2731, 2341, 2048
+};
+
+
+/*-------------------------------------------------------------------------
+ * Stereo ICA analysis ROM tables
+ *------------------------------------------------------------------------*/
+
+const float ica_sincInterp2[2*SINC_ORDER1+1] =
+{
+ 0.0f,-0.002323f,0.0f, 0.003486f, 0.0f,-0.005865f,0.0f, 0.009735f, 0.0f,-0.015447f,0.0f, 0.023503f,
+ 0.0f,-0.034727f,0.0f, 0.050649f, 0.0f,-0.074578f,0.0f, 0.115220f, 0.0f,-0.204776f,0.0f, 0.634114f,
+ 1.0f, 0.634114f,0.0f,-0.204776f, 0.0f, 0.115220f,0.0f,-0.074578f, 0.0f, 0.050649f,0.0f,-0.034727f,
+ 0.0f, 0.023503f,0.0f,-0.015447f, 0.0f, 0.009735f,0.0f,-0.005865f, 0.0f, 0.003486f,0.0f,-0.002323f, 0.0f
+};
+
+const float ica_sincInterp4[2*SINC_ORDER1+1] =
+{
+ 0.0f,-0.003285f,-0.005537f,-0.004930f, 0.0f, 0.008295f, 0.015189f, 0.013767f, 0.0f,-0.021845f,-0.038282f,-0.033239f,
+ 0.0f, 0.049111f, 0.083913f, 0.071628f, 0.0f,-0.105469f,-0.183615f,-0.162946f, 0.0f, 0.289597f, 0.626641f, 0.896773f,
+ 1.0f, 0.896773f, 0.626641f, 0.289597f, 0.0f,-0.162946f,-0.183615f,-0.105469f, 0.0f, 0.071628f, 0.083913f, 0.049111f,
+ 0.0f,-0.033239f,-0.038282f,-0.021845f, 0.0f, 0.013767f, 0.015189f, 0.008295f, 0.0f,-0.004930f,-0.005537f,-0.003285f, 0.0f
+};
+
+const float ica_sincInterp6[2*SINC_ORDER1+1] =
+{
+ 0.0f,-0.003484f,-0.007192f,-0.010460f,-0.011712f,-0.008798f, 0.0f, 0.014603f, 0.032045f, 0.046341f, 0.049731f, 0.035255f,
+ 0.0f,-0.052090f,-0.109007f,-0.151947f,-0.159196f,-0.111867f, 0.0f, 0.172831f, 0.388013f, 0.614328f, 0.814030f, 0.951171f,
+ 1.0f, 0.951171f, 0.814030f, 0.614328f, 0.388013f, 0.172831f, 0.0f,-0.111867f,-0.159196f,-0.151947f,-0.109007f,-0.052090f,
+ 0.0f, 0.035255f, 0.049731f, 0.046341f, 0.032045f, 0.014603f, 0.0f,-0.008798f,-0.011712f,-0.010460f,-0.007192f,-0.003484f, 0.0f
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * Stereo IC-BWE ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const float icbwe_gsMapping_tbl[16] =
+{
+ -2.0000000f, -1.3494960f, -0.9607952f, -0.7098941f, -0.5589364f, -0.4453763f, -0.3429649f, -0.2527705f,
+ -0.1690688f, -0.0987095f, -0.0700000f, -0.0500000f, -0.0200000f, 0.0000000f, 0.0400000f, 0.0800000f
+};
+
+const float icbwe_gsMappingDFT_tbl[128] =
+{
+ -5.0000000f, -4.5000000f, -4.0000000f, -3.5000000f, -3.0000000f, -2.5000000f, -1.9000000f, -1.5474502f,
+ -1.5002078f, -1.4469336f, -1.3902478f, -1.3770106f, -1.3094972f, -1.2608015f, -1.0926061f, -1.0843442f,
+ -1.0345038f, -1.0286606f, -1.0161779f, -1.0036838f, -0.9812821f, -0.9698121f, -0.9573308f, -0.9405646f,
+ -0.9297086f, -0.9131601f, -0.9025761f, -0.8860643f, -0.8736950f, -0.8564931f, -0.8403996f, -0.8352164f,
+ -0.8241847f, -0.8038731f, -0.7923367f, -0.7789138f, -0.7679189f, -0.7595301f, -0.7566783f, -0.7507762f,
+ -0.7428076f, -0.7386452f, -0.7339793f, -0.7300271f, -0.7243238f, -0.7188097f, -0.7090309f, -0.7047743f,
+ -0.7000968f, -0.6903794f, -0.6844128f, -0.6792722f, -0.6724832f, -0.6680448f, -0.6638050f, -0.6587732f,
+ -0.6519668f, -0.6454810f, -0.6418348f, -0.6352437f, -0.6296001f, -0.6244346f, -0.6182194f, -0.6134241f,
+ -0.6093079f, -0.6042419f, -0.5995789f, -0.5946505f, -0.5897729f, -0.5851547f, -0.5806601f, -0.5759744f,
+ -0.5720182f, -0.5669503f, -0.5630283f, -0.5573819f, -0.5511614f, -0.5438205f, -0.5364699f, -0.5282783f,
+ -0.5198154f, -0.5095584f, -0.4986083f, -0.4861976f, -0.4725366f, -0.4591254f, -0.4449745f, -0.4310394f,
+ -0.4169318f, -0.4033374f, -0.3898838f, -0.3766562f, -0.3616849f, -0.3472800f, -0.3326788f, -0.3194550f,
+ -0.3060711f, -0.2916924f, -0.2783983f, -0.2642500f, -0.2506378f, -0.2368909f, -0.2203000f, -0.2036115f,
+ -0.1869981f, -0.1709912f, -0.1561569f, -0.1420659f, -0.1263750f, -0.1107119f, -0.0953914f, -0.0805369f,
+ -0.0660773f, -0.0529481f, -0.0401913f, -0.0287031f, -0.0184659f, -0.0094214f, 0.0000000f, 0.0073561f,
+ 0.0155180f, 0.0224511f, 0.0298570f, 0.0375954f, 0.0457853f, 0.0549424f, 0.0659733f, 0.0785186f
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * TD Stereo ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const float tdm_ratio_tabl[TDM_NQ+1] =
+{
+ 0.00f, 0.00f, 0.0109f, 0.0245f, 0.0432f, 0.0670f, 0.0955f, 0.1284f,
+ 0.1654f, 0.2061f, 0.2500f, 0.2966f, 0.3455f, 0.3960f, 0.4477f, 0.5000f,
+ 0.5523f, 0.6040f, 0.6545f, 0.7034f, 0.7500f, 0.7939f, 0.8346f, 0.8716f,
+ 0.9045f, 0.9330f, 0.9568f, 0.9755f, 0.9891f, 1.0000f, 1.0000f, 1.0000f
+};
+const float tdm_den_ratio_tabl[TDM_NQ+1] = /* 1.0f/(2*LR_ratio*LR_ratio-2*LR_ratio+1) */
+{
+ 1.0000f, 1.0000f, 1.0221f, 1.0501f, 1.0902f, 1.1429f, 1.2088f, 1.2884f,
+ 1.3815f, 1.4864f, 1.6000f, 1.7161f, 1.8257f, 1.9171f, 1.9784f, 2.0000f,
+ 1.9784f, 1.9171f, 1.8257f, 1.7161f, 1.6000f, 1.4864f, 1.3815f, 1.2884f,
+ 1.2088f, 1.1429f, 1.0902f, 1.0501f, 1.0221f, 1.0000f, 1.0000f, 1.0000f
+};
+
+const int16_t tdm_bit_allc_tbl[5][6] =
+{
+ /* IC -- UC -- GC -- TM --AC */
+ { 1650, 3500, 0, 4400, 0, 5000 }, /* IVAS_13k2 */
+ { 1650, 3500, 0, 5000, 0, 5000 }, /* IVAS_16k4 */
+ { 1650, 3500, 0, 6000, 0, 5000 }, /* IVAS_24k4 */
+ { 1650, 6050, 0, 10000, 0, 10000 }, /* IVAS_32k */
+ { 1650, 6050, 0, 13000, 0, 14000 } /* IVAS_48k */
+};
+
+/* LSFs Intra-frame prediction tables */
+const float tdm_LSF_MEAN_RE_USE_OUT[M] =
+{
+ 301.292f, 521.300f, 870.818f, 1340.278f, 1712.099f, 2091.456f, 2488.523f, 2841.096f, 3196.565f, 3593.040f, 3958.366f, 4293.334f, 4710.319f, 5118.806f, 5546.761f, 5918.579f,
+};
+
+const float tdm_LSF_MEAN_RE_USE_IN[M] =
+{
+ 286.414f, 522.366f, 887.297f, 1347.961f, 1725.604f, 2102.356f, 2511.703f, 2853.093f, 3211.319f, 3612.072f, 3970.889f, 4327.774f, 4732.423f, 5154.984f, 5572.849f, 5964.332f,
+};
+
+const float tdm_LSF_MEAN_RE_USE[M] =
+{
+ 265.534222F, 534.776631F, 919.574509F, 1346.991675F, 1756.991835F, 2123.061862F, 2556.845807F, 2927.484493F,
+ 3299.107307F, 3686.249102F, 4034.473656F, 4393.818819F, 4781.683038F, 5155.954294F, 5542.569582F, 5927.377309F
+};
+
+const float tdm_Beta_Q1bit_re_use_13k2[2] = { 0.97F, 0.75F };
+const float tdm_Beta_Q1bit_re_use_16k4[2] = { 0.95F, 0.71F };
+const float tdm_Beta_Q1bit_re_use_24k4_32k[2] = { 0.93F, 0.73F };
+const float tdm_Beta_Q1bit_re_use_48k[2] = { 0.97F, 0.77F };
+
+const float tdm_RE_USE_adaptive_beta_prd_diag_3[15 + 16 + 15] =
+{
+ 0.8859f, 0.2060f,
+ 0.0585f, 0.8245f, 0.2294f,
+ 0.0365f, 0.8175f, 0.1696f,
+ -0.0060f, 0.8483f, 0.2061f,
+ 0.0663f, 0.8983f, 0.1357f,
+ 0.0664f, 0.7951f, 0.1934f,
+ 0.0935f, 0.7948f, 0.1685f,
+ 0.1109f, 0.7960f, 0.1828f,
+ 0.1073f, 0.7835f, 0.1804f,
+ 0.1479f, 0.7362f, 0.1982f,
+ 0.1335f, 0.7621f, 0.1900f,
+ 0.1903f, 0.7369f, 0.1715f,
+ 0.1785f, 0.7214f, 0.1646f,
+ 0.1967f, 0.6891f, 0.1229f,
+ 0.2043f, 0.6317f, 0.0543f,
+ 0.1767f, 0.5396f,
+};
+
+const float tdm_LSF_MEAN_PRED_QNT[M] =
+{
+ 391.31345F, 608.50453F, 968.00585F, 1354.23965F, 1709.71084F, 2080.49872F, 2450.64009F, 2796.96588F,
+ 3196.19608F, 3554.17092F, 3915.02370F, 4283.81121F, 4707.59835F, 5109.79026F, 5526.44936F, 5903.42625F
+};
+
+const float tdm_LSF_MEAN_PRED_QNT_IN[M] =
+{
+ 288.540f, 535.469f, 899.738f, 1342.313f, 1730.736f, 2107.070f, 2491.455f, 2859.828f, 3239.279f, 3625.673f, 3992.540f, 4356.748f, 4752.356f, 5153.685f, 5567.107f, 5972.623f,
+};
+const float tdm_LSF_MEAN_PRED_QNT_OUT[M] =
+{
+ 286.414f, 522.366f, 887.297f, 1347.961f, 1725.604f, 2102.356f, 2511.703f, 2853.093f, 3211.319f, 3612.072f, 3970.889f, 4327.774f, 4732.423f, 5154.984f, 5572.849f, 5964.332f,
+};
+
+const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15] =
+{
+ 0.7040f, 0.1203f,
+ -0.1119f, 0.7340f, 0.1803f,
+ 0.0253f, 0.6702f, 0.1901f,
+ -0.1847f, 0.7892f, 0.3010f,
+ -0.0418f, 0.8716f, 0.1837f,
+ 0.0033f, 0.6915f, 0.2394f,
+ 0.0213f, 0.6728f, 0.2441f,
+ 0.0705f, 0.7549f, 0.1983f,
+ 0.0752f, 0.7152f, 0.2173f,
+ 0.0886f, 0.6163f, 0.3067f,
+ 0.0217f, 0.8121f, 0.2021f,
+ 0.1584f, 0.7311f, 0.1746f,
+ 0.1204f, 0.7296f, 0.1978f,
+ 0.1231f, 0.7502f, 0.1234f,
+ 0.1709f, 0.6372f, 0.1060f,
+ 0.1193f, 0.6574f,
+};
+
+const int16_t fast_FCB_bits_2sfr[] = {8, 14, 18, 20, 24, 128/*stop value*/};
+
+const int16_t fast_FCB_rates_2sfr[] = {/*16*50,*/ (8+14)*50, 28*50, 32*50, 34*50, 36*50, 38*50, 40*50, 42*50, 44*50, 48*50};
+
+
+/*----------------------------------------------------------------------------------*
+ * MDCT Stereo ROM tables
+ *----------------------------------------------------------------------------------*/
+
+ /* PsychLPC */
+
+const SpectrumWarping sw32000Hz[] =
+{{
+ {
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6,
+ 6, 8, 8, 8, 8, 8, 10, 10, 10, 10, 12, 12, 12, 12, 14, 14,
+ 14, 16, 18, 18, 18, 20, 22, 22, 22, 24, 26, 26, 26, 28, 30, 32
+ },
+ {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5,
+ 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10
+ },
+}};
+
+const SpectrumWarping sw25600Hz[] =
+{{
+ {
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6,
+ 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 12, 12, 12,
+ 12, 12, 14, 14, 14, 14, 14, 16, 16, 18, 18, 18, 18, 18, 20, 20
+ },
+ {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7
+ },
+}};
+
+const SpectrumWarping sw16000Hz[] =
+{{
+ {
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
+ },
+ {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
+ },
+}};
+
+const MDCTStereoBands_config mdctStereoBands_32000_640[] =
+{{
+ /*TCX 20*/
+ { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
+ 12, 20, 20, 20, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 42,
+ 64, 64, 96, 160},
+ {44, 41,38, 29},/*number of bands for frame lengths 960, 640, 512, 320 respectively*/
+
+ /*TCX 10*/
+ {
+ 4, 4, 4, 4, 4, 8, 8, 8, 8, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 20, 32, 32,
+ 32, 48, 80
+ },
+ {33, 29, 26, 18}/*number of bands for frame lengths 480, 320, 256, 160 respectively*/
+}};
+
+const float nf_tw_smoothing_coeffs[N_LTP_GAIN_MEMS] =
+{
+ 0.4f,0.2f,0.2f,0.2f
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * Stereo DTX tables
+ *----------------------------------------------------------------------------------*/
+
+const float dft_cng_coh_pred[STEREO_DFT_N_COH_PRED][STEREO_DFT_COH_PRED_COEFFS] =
+{
+ { 0.601337f, -0.101048f, 1.269064f, 0.085044f, 0.279032f, 0.669925f, 0.081573f, 0.188857f, -0.172930f, 0.321477f, 0.009332f, -0.084341f, 0.362245f, -0.426671f, 0.758383f},
+ { 0.855349f, 0.420736f, 0.413285f, -0.009366f, -0.399699f, 1.385802f, 0.012428f, -0.015338f, 0.156471f, 0.517438f, 0.160248f, -0.303634f, 0.477768f, -0.560747f, 1.382583f},
+ { 0.202543f, 0.048819f, 0.263407f, 0.023538f, 0.092021f, 0.395655f, 0.013064f, -0.011127f, 0.035466f, 0.976055f, 0.009968f, 0.162957f, 0.383185f, -0.365493f, 2.534677f},
+ { 1.393664f, -0.131401f, 0.989429f, 0.738330f, 0.683865f, 0.001677f, -0.225448f, -0.012158f, 1.084608f, -0.115464f, 0.022371f, -0.045560f, -0.336230f, 0.422742f, 0.499163f}
+};
+
+const int16_t dft_cng_coh_u2i[9] = { 4, 5, 3, 6, 2, 7, 1, 8, 0 }; /* Coherence unary codeword -> residual codeword conversion table */
+
+const int16_t dft_cng_coh_i2u[9] = { 8, 6, 4, 2, 0, 1, 3, 5, 7 }; /* Coherence residual codeword -> unary codeword conversion table */
+
+const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1] = { 15, 16, 17, 18 };
+
+const float dft_cng_alpha_bits[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS] =
+{
+ { 0.1f, 0.6f },
+ { 0.1f, 0.6f },
+ { 0.1f, 0.7f },
+ { 0.1f, 0.9f },
+ { 0.2f, 0.9f }
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * DirAC ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const float diffuseness_reconstructions[DIRAC_DIFFUSE_LEVELS] =
+{
+ 0.0f,
+ 0.03955078125f,
+ 0.089599609375f,
+ 0.158935546875f,
+ 0.308349609375f,
+ 0.473876953125f,
+ 0.63232421875f,
+ 0.85009765625f
+};
+
+const float diffuseness_thresholds[DIRAC_DIFFUSE_LEVELS + 1] =
+{
+ 0.0f,
+ 0.01904296875f,
+ 0.06298828125f,
+ 0.119384765625f,
+ 0.22119140625f,
+ 0.399169921875f,
+ 0.547607421875f,
+ 0.734619140625f,
+ 2.0f /* out-of-range large value to make searching easier */
+};
+
+const int16_t DirAC_band_grouping_12[12 + 1] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 11, 17, 25, 40, 60
+};
+
+
+const int16_t DirAC_band_grouping_6[6 + 1] =
+{
+ 0, 1, 4, 8, 20, 30, 60
+};
+
+const int16_t DirAC_band_grouping_5[5 + 1] =
+{
+ 0, 1, 3, 7, 15, 60
+};
+
+const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1] =
+{
+ 0, 4, 8, 12, 16
+};
+
+const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1] =
+{
+ 0, 1, 2, 3, 4
+};
+
+const float c_weights[DIRAC_NO_FB_BANDS_MAX] = { 9.962447e-02f, 9.627997e-01f, 9.926667e-01f, 9.981028e-01f, 9.996648e-01f, 1.000000e+00f, 9.997692e-01f, 9.992002e-01f, 9.983890e-01f, 9.973818e-01f, 9.962037e-01f, 9.948692e-01f, 9.933876e-01f, 9.917654e-01f, 9.900073e-01f, 9.881169e-01f, 9.860975e-01f, 9.839516e-01f, 9.816818e-01f, 9.792906e-01f, 9.767801e-01f, 9.741527e-01f, 9.714106e-01f, 9.685560e-01f, 9.655913e-01f, 9.625187e-01f, 9.593406e-01f, 9.560594e-01f, 9.526774e-01f, 9.491970e-01f, 9.456208e-01f, 9.419512e-01f, 9.381908e-01f, 9.343420e-01f, 9.304075e-01f, 9.263898e-01f, 9.222915e-01f, 9.181152e-01f, 9.138636e-01f, 9.095392e-01f, 9.051447e-01f, 9.006827e-01f, 8.961559e-01f, 8.915668e-01f, 8.869181e-01f, 8.822123e-01f, 8.774521e-01f, 8.726400e-01f, 8.677785e-01f, 8.628702e-01f, 8.579176e-01f, 8.529231e-01f, 8.478893e-01f, 8.428184e-01f, 8.377130e-01f, 8.325753e-01f, 8.274077e-01f, 8.222124e-01f, 8.169917e-01f, 8.117478e-01f, 8.064829e-01f, 8.011990e-01f, 7.958982e-01f, 7.905827e-01f, 7.852543e-01f, 7.799150e-01f, 7.745667e-01f, 7.692112e-01f, 7.638505e-01f, 7.584861e-01f, 7.531199e-01f, 7.477535e-01f, 7.423885e-01f, 7.370265e-01f, 7.316691e-01f, 7.263176e-01f, 7.209736e-01f, 7.156384e-01f, 7.103134e-01f, 7.049999e-01f, 6.996990e-01f, 6.944121e-01f, 6.891403e-01f, 6.838847e-01f, 6.786464e-01f, 6.734265e-01f, 6.682258e-01f, 6.630455e-01f, 6.578863e-01f, 6.527492e-01f, 6.476350e-01f, 6.425445e-01f, 6.374784e-01f, 6.324376e-01f, 6.274226e-01f, 6.224341e-01f, 6.174729e-01f, 6.125393e-01f, 6.076341e-01f, 6.027577e-01f, 5.979106e-01f, 5.930932e-01f, 5.883061e-01f, 5.835497e-01f, 5.788242e-01f, 5.741301e-01f, 5.694676e-01f, 5.648372e-01f, 5.602390e-01f, 5.556734e-01f, 5.511404e-01f, 5.466405e-01f, 5.421737e-01f, 5.377402e-01f, 5.333402e-01f, 5.289738e-01f, 5.246411e-01f, 5.203422e-01f, 5.160771e-01f, 5.118460e-01f, 5.076489e-01f, 5.034858e-01f, 4.993567e-01f, 4.952616e-01f, 4.912005e-01f, 4.871734e-01f, 4.831802e-01f, 4.792209e-01f, 4.752955e-01f, 4.714037e-01f, 4.675457e-01f, 4.637212e-01f, 4.599302e-01f, 4.561725e-01f, 4.524481e-01f, 4.487567e-01f, 4.450983e-01f, 4.414728e-01f, 4.378799e-01f, 4.343195e-01f, 4.307915e-01f, 4.272956e-01f, 4.238318e-01f, 4.203997e-01f, 4.169993e-01f, 4.136303e-01f, 4.102926e-01f, 4.069859e-01f, 4.037101e-01f, 4.004649e-01f, 3.972501e-01f, 3.940655e-01f, 3.909109e-01f, 3.877861e-01f, 3.846909e-01f, 3.816250e-01f, 3.785882e-01f, 3.755803e-01f, 3.726010e-01f, 3.696501e-01f, 3.667275e-01f, 3.638328e-01f, 3.609658e-01f, 3.581263e-01f, 3.553141e-01f, 3.525289e-01f, 3.497705e-01f, 3.470387e-01f, 3.443331e-01f, 3.416537e-01f, 3.390001e-01f, 3.363720e-01f, 3.337694e-01f, 3.311919e-01f, 3.286393e-01f, 3.261114e-01f, 3.236079e-01f, 3.211286e-01f, 3.186733e-01f, 3.162418e-01f, 3.138337e-01f, 3.114490e-01f, 3.090872e-01f, 3.067484e-01f, 3.044321e-01f, 3.021382e-01f, 2.998664e-01f, 2.976166e-01f, 2.953885e-01f, 2.931819e-01f, 2.909966e-01f, 2.888323e-01f, 2.866889e-01f, 2.845661e-01f, 2.824637e-01f, 2.803816e-01f, 2.783194e-01f, 2.762770e-01f, 2.742543e-01f, 2.722509e-01f, 2.702667e-01f, 2.683014e-01f, 2.663550e-01f, 2.644271e-01f, 2.625177e-01f, 2.606264e-01f, 2.587531e-01f, 2.568977e-01f, 2.550599e-01f, 2.532395e-01f, 2.514364e-01f, 2.496503e-01f, 2.478811e-01f, 2.461287e-01f, 2.443928e-01f, 2.426732e-01f, 2.409698e-01f, 2.392824e-01f, 2.376109e-01f, 2.359550e-01f, 2.343146e-01f, 2.326895e-01f, 2.310797e-01f, 2.294848e-01f, 2.279047e-01f, 2.263394e-01f, 2.247886e-01f, 2.232521e-01f, 2.217299e-01f, 2.202217e-01f, 2.187274e-01f, 2.172469e-01f, 2.157800e-01f, 2.143266e-01f, 2.128865e-01f, 2.114596e-01f, 2.100457e-01f, 2.086447e-01f, 2.072564e-01f, 2.058808e-01f };
+
+/*----------------------------------------------------------------------*
+* SPAR ROM tables
+*-----------------------------------------------------------------------*/
+
+const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN] =
+{
+/* When AGC is ON additional (AGC_BITS_PER_CH+1) bits may be taken from each core-coder channel
+ so minimum core-coder bitrate per channel can be min core-coder bitrates as per the table - AGC_BITS_PER_CH */
+ { 13200, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, { { 10000, 8150, 13150 } },
+ { { 15, 1, 5, 1 },{ 15, 1, 3, 1 },{ 7, 1, 3, 1 } }, 0, 0, 0 },
+
+ { 16400, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, { { 13200, 11350, 16350 } },
+ { { 15, 1, 5, 1 },{ 15, 1, 3, 1 },{ 7, 1, 3, 1 } }, 0, 0, 0 },
+
+ { 24400, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, { { 16400, 14850, 24350 } },
+ { { 15, 1, 5, 1 },{ 15, 1, 3, 1 },{ 7, 1, 3, 1 } }, 0, 0, 0 },
+
+ { 32000, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, { { 24000, 20450, 31950 } },
+ { { 21, 1, 5, 1 },{ 15, 1, 5, 1 },{ 15, 1, 3, 1 } }, 0, 0, 0 },
+
+ { 48000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0, { { 24000, 21000, 31950 },{ 16000, 15000, 20400 } },
+ { { 15, 7, 5, 1 },{ 15, 7, 3, 1 },{ 7, 7, 3, 1 } }, 1, 0, 0 },
+
+ { 64000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0, { { 38000, 34050, 56000 },{ 16000, 15600, 20400 } },{ { 21, 7, 5, 1 },{ 15, 7, 5, 1 },{ 15, 7, 3, 1 } }, 1, 1, 0 },
+
+ { 80000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0, { { 46000, 43000, 56000 },{ 24000, 23000, 31950 } },
+ { { 21, 7, 5, 1 },{ 15, 7, 5, 1 },{ 15, 7, 3, 1 } }, 1, 0, 0 },
+
+ { 96000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0, { { 47000, 42600, 56000 },{ 23000, 22600, 31950 },{ 16000, 15600, 20400 } },
+ { { 21, 9, 9, 1 },{ 21, 7, 5, 1 },{ 21, 7, 5, 1 } }, 1, 0, 0 },
+
+ { 128000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0, { { 55000, 50000, 56000 },{ 36000, 36000, 56000 },{ 27000, 27000, 31950 } },
+ { { 21, 11, 9, 1 },{ 21, 9, 7, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 },
+
+ { 160000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0, { { 74000, 70900, 112000 },{ 41000, 40050, 56000 },{ 35000, 34050, 56000 } },
+ { { 21, 11, 11, 1 },{ 21, 9, 9, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 },
+
+ { 192000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0, { { 90000, 87900, 112000 },{ 50000, 48050, 56000 },{ 42000, 41050, 56000 } },
+ { { 21, 11, 11, 1 },{ 21, 9, 9, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 },
+
+ { 256000, 0, SBA_FOA_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 90000, 85000, 112000 },{ 70000, 69000, 112000 },{ 50000, 48950, 56000 },{ 36400, 35600, 56000 } },
+ { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 },
+
+ { 256000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 84650, 83000, 112000 },{ 65850, 64550, 56000 },{ 47000, 46100, 48000 },{ 28200, 27650, 40000 } },
+ { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 },
+
+ { 256000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 76300, 73550, 112000 },{ 59350, 57200, 56000 },{ 42400, 40850, 48000 },{ 25450, 24500, 40000 } },
+ { { 31, 11, 11, 1 },{ 1, 1, 1, 1 }, { 1, 1, 1, 1 } }, 1, 2, 0 },
+
+ { 384000, 0, SBA_FOA_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 128000, 128000, 128000 },{ 100000, 100000, 128000 },{ 79850, 79850, 104000 },{ 66600, 66600, 104000 } },
+ { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 },
+
+ { 384000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 128000, 128000, 128000 },{ 105350, 103300, 112000 },{ 75200, 73750, 96000 },{ 45100, 44250, 48000 } },
+ { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 },
+
+ { 384000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 124300, 121550, 128000 },{ 96700, 94550, 112000 },{ 69050, 67500, 96000 },{ 41450, 40500, 48000 } },
+ { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 },
+
+ { 512000, 0, SBA_FOA_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 128000, 128000, 128000 }, {118450, 118450, 128000 } },
+ { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 },
+
+ { 512000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 124000, 124000, 128000 },{ 124000, 124000, 128000 },{ 125200, 118450, 128000 },{ 76300, 73000, 128000 } },
+ { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 },
+
+ { 512000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 118000, 118000, 128000 },{ 118000, 118000, 128000 },{ 117200, 109250, 128000 },{ 72300, 69000, 128000 } },
+ { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 },
+};
+
+const ivas_freq_models_t ivas_arith_pred_r_consts[TOTAL_PRED_QUANT_STRATS_ARITH] =
+{
+ /* entry for 1 quantization points */
+ {
+ /* pred_R real */
+ {
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ },
+ /* pred_R real differential */
+ {
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ },
+ /* pred_R real : values for general and differential */
+ { 0 },{ 0 },
+ /* pred_R real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 7 quantization points for br_table_idx >= 2 */
+ {
+ /* pred_R real */
+ {
+ { 0,546,1092,2184,8740,2184,1092,546, },
+ { 0,1779,2116,2516,3562,2516,2116,1779, },
+ { 0,1848,2614,5229,2614,1848,1307,924, },
+ { 0,924,1307,1848,2614,5229,2614,1848, },
+ },
+ /* pred_R real differential */
+ {
+ { 0,125,399,1269,12798,1269,399,125, },
+ { 0,744,1327,2365,7512,2365,1327,744, },
+ { 0,1354,2413,7664,2413,1354,760,426, },
+ { 0,426,760,1354,2413,7664,2413,1354, },
+ },
+ /* pred_R real : values for general and differential */
+ { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 },
+ /* pred_R real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 15 quantization points for br_table_idx >= 2 */
+ {
+ /* pred_R real */
+ {
+ { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, },
+ { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, },
+ { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, },
+ { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, },
+ },
+ /* pred_R real differential */
+ {
+ { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, },
+ { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, },
+ { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, },
+ { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, },
+ },
+ /* pred_R real : values for general and differential */
+ { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 },
+ { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 },
+ /* pred_R real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 21 quantization points for br_table_idx >= 2 */
+ {
+ /* pred_R real */
+ {
+ { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, },
+ { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, },
+ { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, },
+ { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, },
+ },
+ /* pred_R real differential */
+ {
+ { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, },
+ { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, },
+ { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, },
+ { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, },
+ },
+ /* pred_R real : values for general and differential */
+ { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 },
+ { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 },
+ /* pred_R real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 31 quantization points */
+ {
+ /* pred real */
+ {
+ { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, },
+ { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, },
+ { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, },
+ { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }
+ },
+ /* pred real differential */
+ {
+ { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, },
+ { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, },
+ { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, },
+ { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }
+ },
+ /* pred real : values for general and differential */
+ { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 },
+ { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 },
+ /* pred real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 7 quantization points for br_table_idx < 2 */
+ {
+ /* pred_R real */
+ {
+ { 0,327,778,1851,10472,1851,778,327, },
+ { 0,1057,1630,2514,5982,2514,1630,1057, },
+ { 0,1668,2572,6122,2572,1668,1081,701, },
+ { 0,701,1081,1668,2572,6122,2572,1668, },
+ },
+ /* pred_R real differential */
+ {
+ { 0,125,399,1269,12798,1269,399,125, },
+ { 0,744,1327,2365,7512,2365,1327,744, },
+ { 0,1354,2413,7664,2413,1354,760,426, },
+ { 0,426,760,1354,2413,7664,2413,1354, },
+ },
+ /* pred_R real : values for general and differential */
+ { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 },
+ /* pred_R real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 15 quantization points for br_table_idx < 2 */
+ {
+ /* pred real */
+ {
+ { 0,9,23,56,133,318,757,1800,10192,1800,757,318,133,56,23,9, },
+ { 0,156,240,371,573,883,1363,2102,5008,2102,1363,883,573,371,240,156, },
+ { 0,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241,156,101, },
+ { 0,101,156,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241, }
+ },
+ /* pred real differential */
+ {
+ { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, },
+ { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, },
+ { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, },
+ { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }
+ },
+ /* pred real : values for general and differential */
+ {-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7},
+ { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 },
+ /* pred real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 21 quantization points for br_table_idx < 2 */
+ {
+ /* pred_R real */
+ {
+ { 0,1,1,4,9,23,56,133,318,756,1799,10184,1799,756,318,133,56,23,9,4,1,1, },
+ { 0,41,64,98,152,234,362,558,861,1329,2049,4888,2049,1329,861,558,362,234,152,98,64,41, },
+ { 0,64,98,152,235,362,559,862,1330,2051,4891,2051,1330,862,559,362,235,152,98,64,41,26, },
+ { 0,26,41,64,98,152,235,362,559,862,1330,2051,4891,2051,1330,862,559,362,235,152,98,64, },
+ },
+ /* pred_R real differential */
+ {
+ { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, },
+ { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, },
+ { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, },
+ { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, },
+ },
+ /* pred_R real : values for general and differential */
+ { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 },
+ { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 },
+ /* pred_R real : num dyn models for general and differential */
+ 4, 4
+ }
+};
+
+const ivas_freq_models_t ivas_arith_drct_r_consts[TOTAL_DRCT_QUANT_STRATS] =
+{
+ /* entry for 1 quantization points */
+ {
+ /* drct real */
+ {
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ },
+ /* drct real differential */
+ {
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ },
+ /* drct real : values for general and differential */
+ {0},{ 0 },
+ /* drct real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 7 quantization points */
+ { /* drct real */
+ {
+ { 0,125,399,1269,12798,1269,399,125, },
+ { 0,744,1327,2365,7512,2365,1327,744, },
+ { 0,988,1244,1568,1976,2489,3136,4983, },
+ { 0,2111,2262,2425,2788,2425,2262,2111, },
+ },
+ /* drct real differential */
+ {
+ { 0,125,399,1269,12798,1269,399,125, },
+ { 0,744,1327,2365,7512,2365,1327,744, },
+ { 0,1354,2413,7664,2413,1354,760,426, },
+ { 0,426,760,1354,2413,7664,2413,1354, },
+ },
+ /* drct real : values for general and differential */
+ { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 },
+ /* drct real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 9 quantization points */
+ {
+ /* drct real */
+ {
+ { 0,39,125,397,1263,12736,1263,397,125,39, },
+ { 0,397,708,1262,2250,7150,2250,1262,708,397, },
+ { 0,573,722,909,1146,1444,1819,2292,2888,4591, },
+ { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, },
+ },
+ /* drct real differential */
+ {
+ { 0,39,125,397,1263,12736,1263,397,125,39, },
+ { 0,397,708,1262,2250,7150,2250,1262,708,397, },
+ { 0,716,1276,2274,7225,2274,1276,716,402,225, },
+ { 0,225,402,716,1276,2274,7225,2274,1276,716, }
+ },
+ /* drct real : values for general and differential */
+ { -4,-3,-2,-1,0,1,2,3,4 },{ -4,-3,-2,-1,0,1,2,3,4 },
+ /* drct real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 11 quantization points */
+ {
+ /* drct real */
+ {
+ { 0,12,39,125,397,1261,12716,1261,397,125,39,12, },
+ { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, },
+ { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, },
+ { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, },
+ },
+ /* drct real differential */
+ {
+ { 0,12,39,125,397,1261,12716,1261,397,125,39,12, },
+ { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, },
+ { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, },
+ { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, },
+ },
+ /* drct real : values for general and differential */
+ { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 },
+ /* drct real : num dyn models for general and differential */
+ 4, 4
+ }
+};
+
+const ivas_freq_models_t ivas_arith_decd_r_consts[TOTAL_DECD_QUANT_STRATS] =
+{
+ /* entry for 1 quantization points */
+ {
+ /* decd real */
+ {
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ },
+ /* decd real differential */
+ {
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ { 0,16384, },
+ },
+ /* decd real : values for general and differential */
+ { 0 },{ 0 },
+ /* decd real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 3 quantization points */
+ {
+ /* decd real */
+ {
+ { 0,11917,2978,1489, },
+ { 0,8840,4419,3125, },
+ { 0,4567,7250,4567, },
+ { 0,5203,5978,5203, },
+ },
+ /* decd real differential */
+ {
+ { 0,1356,13672,1356, },
+ { 0,3166,10052,3166, },
+ { 0,10984,3459,1941, },
+ { 0,1941,3459,10984, },
+ },
+ /* decd real : values for general and differential */
+ { 0,1,2 },{-1,0,1},
+ /* decd real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 5 quantization points */
+ {
+ /* decd real */
+ {
+ { 0,11157,2788,1394,697,348, },
+ { 0,7186,3592,2540,1796,1270, },
+ { 0,2512,3166,5028,3166,2512, },
+ { 0,3048,3267,3754,3267,3048, },
+ },
+ /* decd real differential */
+ {
+ { 0,406,1289,12994,1289,406, },
+ { 0,1460,2601,8262,2601,1460, },
+ { 0,2707,8599,2707,1519,852, },
+ { 0,852,1519,2707,8599,2707, },
+ },
+ /* decd real : values for general and differential */
+ { 0,1,2,3,4 },{ -2,-1,0,1,2 },
+ /* decd real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 7 quantization points */
+ {
+ /* decd real */
+ {
+ { 0,10983,2744,1372,686,343,171,85, },
+ { 0,6573,3285,2322,1642,1161,821,580, },
+ { 0,1603,2020,2546,4046,2546,2020,1603, },
+ { 0,2111,2262,2425,2788,2425,2262,2111, },
+ },
+ /* decd real differential */
+ {
+ { 0,125,399,1269,12798,1269,399,125, },
+ { 0,744,1327,2365,7512,2365,1327,744, },
+ { 0,1354,2413,7664,2413,1354,760,426, },
+ { 0,426,760,1354,2413,7664,2413,1354, }
+ },
+ /* decd real : values for general and differential */
+ { 0,1,2,3,4,5,6 },{ -3,-2,-1,0,1,2,3 },
+ /* decd real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 9 quantization points */
+ { /* decd real */
+ {
+ { 0,10941,2734,1367,683,341,170,85,42,21, },
+ { 0,6305,3150,2227,1575,1113,787,556,393,278, },
+ { 0,1101,1388,1749,2203,3502,2203,1749,1388,1101, },
+ { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, },
+ },
+ /* decd real differential */
+ {
+ { 0,39,125,397,1263,12736,1263,397,125,39, },
+ { 0,397,708,1262,2250,7150,2250,1262,708,397, },
+ { 0,716,1276,2274,7225,2274,1276,716,402,225, },
+ { 0,225,402,716,1276,2274,7225,2274,1276,716, }
+ },
+ /* decd real : values for general and differential */
+ { 0,1,2,3,4,5,6,7,8 },{ -4,-3,-2,-1,0,1,2,3,4 },
+ /* decd real : num dyn models for general and differential */
+ 4, 4
+ },
+ /* entry for 11 quantization points */
+ {
+ /* decd real */
+ {
+ { 0,10932,2731,1365,682,341,170,85,42,21,10,5, },
+ { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, },
+ { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, },
+ { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, },
+ },
+ /* decd real differential */
+ {
+ { 0,12,39,125,397,1261,12716,1261,397,125,39,12, },
+ { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, },
+ { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, },
+ { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, },
+ },
+ /* decd real : values for general and differential */
+ { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 },
+ /* decd real : num dyn models for general and differential */
+ 4, 4
+ }
+};
+
+const ivas_huff_models_t ivas_huff_pred_r_consts[TOTAL_PRED_QUANT_STRATS_HUFF] =
+{
+ /* entry for 1 quantization points for br_table_idx */
+ {{{ 0 }}, {{ 0 }}},
+ /* entry for 7 quantization points for br_table_idx */
+ {
+ /* pred_R codebook */
+ { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, },
+ /* pred_R differential codebook */
+ { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, },
+ },
+ /* entry for 15 quantization points for br_table_idx */
+ {
+ /* pred_r codebook */
+ { { -7,4,2 },{ -6,4,3 },{ -5, 4, 4 },{ -4, 4, 5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },
+ { 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 } },
+ /* pred_r differential codebook */
+ { { -7,4,2 },{ -6,4,3 },{ -5, 4, 4 },{ -4, 4, 5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },
+ { 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 } },
+ },
+ /* entry for 21 quantization points for br_table_idx=0 */
+ {
+ /* pred_r codebook */
+ { {-10,5,22},{-9,5,23},{-8,5,24},{-7,5,25},{-6,5,26}, { -5, 4, 0 },{ -4, 4, 1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },
+ { 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{6,5,27},{7,5,28},{8,5,29},{9,5,30},{10,5,31} },
+ /* pred_r differential codebook */
+ { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5, 4, 0 },{ -4, 4, 1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },
+ { 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 } },
+ },
+
+ /* entry for 31 quantization points for br_table_idx>0 */
+ {
+ /* pred_r codebook */
+ { {-15,5,2},{-14,5,3},{-13,5,4},{-12,5,5},{-11,5,6}, { -10,5,7 },{ -9,5,8 },{ -8,5,9 },
+ { -7,5,10 },{ -6,5,11 },{ -5, 5, 12 },{ -4, 5, 13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },
+ { 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },
+ { 8,5,24 },{ 9,5,25 },{ 10,5,26 },{11,5,27},{12,5,28},{13,5,29},{14,5,30},{15,5,31} },
+ /* pred_r differential codebook */
+ { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },
+ { -7,5,10 },{ -6,5,11 },{ -5, 5, 12 },{ -4, 5, 13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },
+ { 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },
+ { 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 } },
+ },
+ };
+
+ const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS] =
+{
+ /* entry for 1 quantization points */
+ {{{ 0 }}, {{ 0 }}},
+ /* entry for 7 quantization points */
+ {
+ /* drct_r codebook */
+ { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } },
+ /* drct_r differential codebook */
+ { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } },
+ },
+ /* entry for 9 quantization points */
+ {
+ /* drct_r codebook */
+ { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } },
+ /* drct_r differential codebook */
+ { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } },
+ },
+ /* entry for 11 quantization points */
+ {
+ /* drct_r codebook */
+ { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } },
+ /* drct_r differential codebook */
+ { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } },
+ },
+};
+
+const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS] =
+{
+ /* entry for 1 quantization points */
+ {{{ 0 }}, {{ 0 }}},
+ /* entry for 3 quantization points */
+ {
+ /* decd_r codebook */
+ { { 0, 2, 2 },{ 1, 1, 0 },{ 2,2,3 } },
+ /* decd_r differential codebook */
+ { { -1, 2, 2 },{ 0, 1, 0 },{ 1,2,3 } },
+ },
+ /* entry for 5 quantization points */
+ {
+ /* decd_r codebook */
+ { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 } },
+ /* decd_r differential codebook */
+ { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 } },
+ },
+ /* entry for 7 quantization points */
+ {
+ /* decd_r */
+ { { 0, 3, 2 },{ 1, 3, 3 },{ 2,3,4 },{ 3,3,0 },{ 4,3,5 },{ 5,3,6 },{ 6,3,7 } },
+ /* decd_r codebook differential codebook */
+ { { -3, 3, 2 },{ -2, 3, 3 },{ -1,3,4 },{ 0,3,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } },
+ },
+ /* entry for 9 quantization points */
+ {
+ /* decd_r codebook */
+ { { 0, 4, 14 },{ 1,3,0 },{ 2,3,1 },{ 3,3,2 },{ 4,3,3 },{ 5,3,4 },{ 6,3,5 },{ 7,3,6 },{ 8,4,15 } },
+ /* decd_r differential codebook */
+ { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } },
+ },
+ /* entry for 11 quantization points */
+ {
+ /* decd_r codebook */
+ { { 0, 4, 10 },{ 1, 4, 11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 } },
+ /* decd_r differential codebook */
+ { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } },
+ },
+};
+
+/* DTX quantization and bitstream constants */
+
+const float dtx_pd_real_min_max[2] = { 0, 1.6f };
+const int16_t dtx_pd_real_q_levels[3][3] = { { 7,7,7 },{ 7,7,0 },{ 3,0,0 } };
+const int16_t dtx_pr_real_q_levels[3][3] = { { 9,9,9 },{ 9,7,9 },{ 9,5,7 } };
+const int16_t pr_pr_idx_pairs[3][3][2] = { { { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 1, 3 },{ 0, 0 } } };
+const int16_t pr_pd_idx_pairs[3][3][2] = { { { 1, 1 },{ 2, 2 },{ 3, 3 } },{ { 1, 1 },{ 3, 2 },{ 2, 0 } },{ { 2, 1 },{ 0, 0 },{ 0, 0 } } };
+
+const int16_t remix_order_set[1][DIRAC_MAX_ANA_CHANS] = { /* WYZX --> WYXZ... */
+ { 0, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10 }
+};
+
+const int16_t HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15};
+const int16_t HOA_keep_ind_spar[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 8, 9, 10, 10, 10, 10};
+const int16_t HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+
+
+/*----------------------------------------------------------------------*
+* PCA ROM tables
+*-----------------------------------------------------------------------*/
+
+const int32_t ivas_pca_offset_index1[IVAS_PCA_N1 + 1] =
+{
+ 0, 1, 9, 61, 163, 359, 685, 1125, 1747,
+ 2519, 3521, 4713, 6183, 7883, 9809, 12093, 14633, 17575,
+ 20807, 24343, 28181, 32487, 37121, 42097, 47405, 53057, 59061,
+ 65421, 72137, 79205, 86625, 94415, 102345, 110629, 119263, 128017,
+ 137097, 146515, 156043, 165637, 175551, 185515, 195535, 205837, 216183,
+ 226545, 236911, 247273, 257619, 267921, 277941, 287905, 297819, 307413,
+ 316941, 326359, 335439, 344193, 352827, 361111, 369041, 376831, 384251,
+ 391319, 398035, 404395, 410399, 416051, 421359, 426335, 430969, 435275,
+ 439113, 442649, 445881, 448823, 451363, 453647, 455573, 457273, 458743,
+ 459935, 460937, 461709, 462331, 462771, 463097, 463293, 463395, 463447,
+ 463455, 463456
+};
+
+const int16_t ivas_pca_offset_index2[2692] =
+{
+ 0, 1, 0, 1, 7, 8, 0, 1, 7, 19,
+ 33, 45, 51, 52, 0, 1, 9, 23, 41, 61,
+ 79, 93, 101, 102, 0, 1, 7, 21, 39, 61,
+ 85, 111, 135, 157, 175, 189, 195, 196, 0, 1,
+ 7, 19, 37, 59, 85, 115, 147, 179, 211, 241,
+ 267, 289, 307, 319, 325, 326, 0, 1, 7, 21,
+ 41, 65, 95, 127, 163, 201, 239, 277, 313, 345,
+ 375, 399, 419, 433, 439, 440, 0, 1, 7, 19,
+ 37, 61, 91, 125, 163, 203, 245, 289, 333, 377,
+ 419, 459, 497, 531, 561, 585, 603, 615, 621, 622,
+ 0, 1, 7, 21, 41, 67, 97, 133, 173, 217,
+ 263, 311, 361, 411, 461, 509, 555, 599, 639, 675,
+ 705, 731, 751, 765, 771, 772, 0, 1, 7, 19,
+ 37, 61, 91, 127, 167, 211, 259, 309, 363, 417,
+ 473, 529, 585, 639, 693, 743, 791, 835, 875, 911,
+ 941, 965, 983, 995, 1001, 1002, 0, 1, 7, 21,
+ 41, 67, 99, 135, 177, 223, 273, 327, 383, 443,
+ 503, 565, 627, 689, 749, 809, 865, 919, 969, 1015,
+ 1057, 1093, 1125, 1151, 1171, 1185, 1191, 1192, 0, 1,
+ 7, 19, 37, 61, 91, 127, 169, 215, 265, 319,
+ 377, 437, 501, 567, 633, 701, 769, 837, 903, 969,
+ 1033, 1093, 1151, 1205, 1255, 1301, 1343, 1379, 1409, 1433,
+ 1451, 1463, 1469, 1470, 0, 1, 7, 21, 41, 67,
+ 99, 137, 179, 227, 279, 335, 395, 459, 525, 595,
+ 667, 739, 813, 887, 961, 1033, 1105, 1175, 1241, 1305,
+ 1365, 1421, 1473, 1521, 1563, 1601, 1633, 1659, 1679, 1693,
+ 1699, 1700, 0, 1, 9, 23, 43, 69, 101, 139,
+ 183, 231, 285, 343, 405, 471, 541, 613, 689, 765,
+ 843, 923, 1003, 1083, 1161, 1237, 1313, 1385, 1455, 1521,
+ 1583, 1641, 1695, 1743, 1787, 1825, 1857, 1883, 1903, 1917,
+ 1925, 1926, 0, 1, 7, 21, 41, 67, 99, 137,
+ 179, 227, 281, 339, 401, 467, 537, 611, 687, 767,
+ 849, 931, 1015, 1099, 1185, 1269, 1353, 1435, 1517, 1597,
+ 1673, 1747, 1817, 1883, 1945, 2003, 2057, 2105, 2147, 2185,
+ 2217, 2243, 2263, 2277, 2283, 2284, 0, 1, 7, 21,
+ 41, 67, 99, 137, 181, 231, 285, 345, 409, 477,
+ 549, 625, 705, 787, 871, 957, 1045, 1135, 1225, 1315,
+ 1405, 1495, 1583, 1669, 1753, 1835, 1915, 1991, 2063, 2131,
+ 2195, 2255, 2309, 2359, 2403, 2441, 2473, 2499, 2519, 2533,
+ 2539, 2540, 0, 1, 7, 19, 39, 65, 97, 135,
+ 177, 225, 279, 337, 401, 469, 541, 617, 697, 781,
+ 867, 955, 1045, 1137, 1231, 1327, 1423, 1519, 1615, 1711,
+ 1805, 1897, 1987, 2075, 2161, 2245, 2325, 2401, 2473, 2541,
+ 2605, 2663, 2717, 2765, 2807, 2845, 2877, 2903, 2923, 2935,
+ 2941, 2942, 0, 1, 7, 21, 41, 67, 99, 137,
+ 181, 229, 283, 343, 407, 477, 551, 629, 711, 797,
+ 885, 977, 1071, 1167, 1265, 1365, 1465, 1565, 1667, 1767,
+ 1867, 1967, 2065, 2161, 2255, 2347, 2435, 2521, 2603, 2681,
+ 2755, 2825, 2889, 2949, 3003, 3051, 3095, 3133, 3165, 3191,
+ 3211, 3225, 3231, 3232, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 347, 413, 483, 559, 639,
+ 723, 811, 903, 997, 1093, 1193, 1295, 1399, 1503, 1609,
+ 1715, 1821, 1927, 2033, 2137, 2241, 2343, 2443, 2539, 2633,
+ 2725, 2813, 2897, 2977, 3053, 3123, 3189, 3249, 3305, 3355,
+ 3399, 3437, 3469, 3495, 3515, 3529, 3535, 3536, 0, 1,
+ 7, 21, 41, 67, 99, 137, 181, 231, 287, 349,
+ 415, 487, 563, 645, 731, 821, 915, 1011, 1111, 1213,
+ 1317, 1423, 1531, 1641, 1751, 1863, 1975, 2087, 2197, 2307,
+ 2415, 2521, 2625, 2727, 2827, 2923, 3017, 3107, 3193, 3275,
+ 3351, 3423, 3489, 3551, 3607, 3657, 3701, 3739, 3771, 3797,
+ 3817, 3831, 3837, 3838, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 285, 345, 411, 481, 557, 637,
+ 721, 809, 901, 997, 1097, 1199, 1305, 1413, 1523, 1635,
+ 1749, 1863, 1979, 2095, 2211, 2327, 2443, 2557, 2671, 2783,
+ 2893, 3001, 3107, 3209, 3309, 3405, 3497, 3585, 3669, 3749,
+ 3825, 3895, 3961, 4021, 4075, 4125, 4169, 4207, 4239, 4265,
+ 4285, 4299, 4305, 4306, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 347, 413, 485, 561, 643,
+ 729, 819, 913, 1011, 1113, 1217, 1325, 1435, 1547, 1663,
+ 1779, 1897, 2017, 2137, 2257, 2377, 2497, 2617, 2737, 2855,
+ 2971, 3087, 3199, 3309, 3417, 3521, 3623, 3721, 3815, 3905,
+ 3991, 4073, 4149, 4221, 4287, 4347, 4403, 4453, 4497, 4535,
+ 4567, 4593, 4613, 4627, 4633, 4634, 0, 1, 7, 21,
+ 41, 67, 99, 137, 181, 231, 287, 349, 415, 487,
+ 565, 647, 733, 825, 921, 1021, 1125, 1231, 1341, 1453,
+ 1569, 1687, 1807, 1929, 2051, 2175, 2299, 2425, 2551, 2677,
+ 2801, 2925, 3047, 3169, 3289, 3407, 3523, 3635, 3745, 3851,
+ 3955, 4055, 4151, 4243, 4329, 4411, 4489, 4561, 4627, 4689,
+ 4745, 4795, 4839, 4877, 4909, 4935, 4955, 4969, 4975, 4976,
+ 0, 1, 7, 21, 41, 67, 99, 137, 181, 231,
+ 287, 349, 417, 489, 567, 649, 737, 829, 925, 1025,
+ 1129, 1237, 1349, 1463, 1581, 1701, 1823, 1947, 2073, 2201,
+ 2329, 2459, 2589, 2719, 2849, 2979, 3107, 3235, 3361, 3485,
+ 3607, 3727, 3845, 3959, 4071, 4179, 4283, 4383, 4479, 4571,
+ 4659, 4741, 4819, 4891, 4959, 5021, 5077, 5127, 5171, 5209,
+ 5241, 5267, 5287, 5301, 5307, 5308, 0, 1, 7, 21,
+ 41, 67, 99, 137, 181, 231, 287, 349, 417, 489,
+ 567, 651, 739, 831, 929, 1031, 1137, 1247, 1361, 1477,
+ 1597, 1719, 1843, 1969, 2097, 2227, 2359, 2491, 2625, 2759,
+ 2893, 3027, 3161, 3293, 3425, 3555, 3683, 3809, 3933, 4055,
+ 4175, 4291, 4405, 4515, 4621, 4723, 4821, 4913, 5001, 5085,
+ 5163, 5235, 5303, 5365, 5421, 5471, 5515, 5553, 5585, 5611,
+ 5631, 5645, 5651, 5652, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 491, 569, 653,
+ 741, 835, 933, 1035, 1141, 1251, 1365, 1483, 1603, 1727,
+ 1853, 1983, 2115, 2249, 2383, 2519, 2657, 2795, 2933, 3071,
+ 3209, 3347, 3485, 3621, 3755, 3889, 4021, 4151, 4277, 4401,
+ 4521, 4639, 4753, 4863, 4969, 5071, 5169, 5263, 5351, 5435,
+ 5513, 5587, 5655, 5717, 5773, 5823, 5867, 5905, 5937, 5963,
+ 5983, 5997, 6003, 6004, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 491, 569, 653,
+ 741, 835, 933, 1037, 1145, 1257, 1373, 1491, 1613, 1739,
+ 1867, 1997, 2131, 2267, 2405, 2543, 2683, 2825, 2967, 3109,
+ 3251, 3393, 3535, 3677, 3817, 3955, 4093, 4229, 4363, 4493,
+ 4621, 4747, 4869, 4987, 5103, 5215, 5323, 5427, 5525, 5619,
+ 5707, 5791, 5869, 5943, 6011, 6073, 6129, 6179, 6223, 6261,
+ 6293, 6319, 6339, 6353, 6359, 6360, 0, 1, 7, 21,
+ 41, 67, 99, 137, 181, 231, 287, 349, 417, 491,
+ 569, 653, 743, 837, 935, 1039, 1147, 1259, 1375, 1495,
+ 1619, 1745, 1875, 2007, 2143, 2281, 2421, 2563, 2705, 2849,
+ 2993, 3139, 3285, 3431, 3577, 3723, 3867, 4011, 4153, 4295,
+ 4435, 4573, 4709, 4841, 4971, 5097, 5221, 5341, 5457, 5569,
+ 5677, 5781, 5879, 5973, 6063, 6147, 6225, 6299, 6367, 6429,
+ 6485, 6535, 6579, 6617, 6649, 6675, 6695, 6709, 6715, 6716,
+ 0, 1, 7, 21, 41, 67, 99, 137, 181, 231,
+ 287, 349, 417, 491, 569, 653, 743, 837, 937, 1041,
+ 1149, 1261, 1377, 1497, 1621, 1749, 1879, 2013, 2149, 2287,
+ 2429, 2573, 2717, 2863, 3011, 3159, 3309, 3459, 3609, 3759,
+ 3909, 4057, 4205, 4351, 4495, 4639, 4781, 4919, 5055, 5189,
+ 5319, 5447, 5571, 5691, 5807, 5919, 6027, 6131, 6231, 6325,
+ 6415, 6499, 6577, 6651, 6719, 6781, 6837, 6887, 6931, 6969,
+ 7001, 7027, 7047, 7061, 7067, 7068, 0, 1, 7, 21,
+ 41, 67, 99, 137, 181, 231, 287, 349, 417, 491,
+ 569, 653, 743, 837, 937, 1041, 1149, 1261, 1377, 1497,
+ 1621, 1749, 1881, 2015, 2153, 2293, 2435, 2579, 2725, 2873,
+ 3023, 3175, 3327, 3479, 3633, 3787, 3941, 4093, 4245, 4397,
+ 4547, 4695, 4841, 4985, 5127, 5267, 5405, 5539, 5671, 5799,
+ 5923, 6043, 6159, 6271, 6379, 6483, 6583, 6677, 6767, 6851,
+ 6929, 7003, 7071, 7133, 7189, 7239, 7283, 7321, 7353, 7379,
+ 7399, 7413, 7419, 7420, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 489, 567, 651,
+ 741, 835, 935, 1039, 1147, 1259, 1377, 1499, 1625, 1753,
+ 1885, 2021, 2159, 2301, 2445, 2591, 2739, 2889, 3041, 3195,
+ 3349, 3505, 3661, 3817, 3973, 4129, 4285, 4441, 4595, 4749,
+ 4901, 5051, 5199, 5345, 5489, 5631, 5769, 5905, 6037, 6165,
+ 6291, 6413, 6531, 6643, 6751, 6855, 6955, 7049, 7139, 7223,
+ 7301, 7373, 7441, 7503, 7559, 7609, 7653, 7691, 7723, 7749,
+ 7769, 7783, 7789, 7790, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 491, 571, 657,
+ 747, 843, 945, 1051, 1161, 1277, 1397, 1521, 1649, 1781,
+ 1915, 2053, 2195, 2339, 2485, 2635, 2787, 2941, 3095, 3251,
+ 3409, 3567, 3725, 3885, 4045, 4205, 4363, 4521, 4679, 4835,
+ 4989, 5143, 5295, 5445, 5591, 5735, 5877, 6015, 6149, 6281,
+ 6409, 6533, 6653, 6769, 6879, 6985, 7087, 7183, 7273, 7359,
+ 7439, 7513, 7581, 7643, 7699, 7749, 7793, 7831, 7863, 7889,
+ 7909, 7923, 7929, 7930, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 491, 571, 657,
+ 747, 843, 943, 1049, 1159, 1273, 1393, 1517, 1645, 1777,
+ 1913, 2051, 2193, 2337, 2485, 2635, 2787, 2941, 3097, 3255,
+ 3415, 3575, 3737, 3899, 4061, 4223, 4385, 4547, 4709, 4869,
+ 5029, 5187, 5343, 5497, 5649, 5799, 5947, 6091, 6233, 6371,
+ 6507, 6639, 6767, 6891, 7011, 7125, 7235, 7341, 7441, 7537,
+ 7627, 7713, 7793, 7867, 7935, 7997, 8053, 8103, 8147, 8185,
+ 8217, 8243, 8263, 8277, 8283, 8284, 0, 1, 7, 21,
+ 41, 67, 99, 137, 181, 231, 287, 349, 417, 491,
+ 571, 655, 745, 841, 941, 1047, 1157, 1271, 1389, 1513,
+ 1641, 1773, 1907, 2045, 2187, 2331, 2479, 2629, 2783, 2939,
+ 3097, 3257, 3417, 3579, 3743, 3907, 4071, 4235, 4399, 4563,
+ 4727, 4891, 5055, 5217, 5377, 5537, 5695, 5851, 6005, 6155,
+ 6303, 6447, 6589, 6727, 6861, 6993, 7121, 7245, 7363, 7477,
+ 7587, 7693, 7793, 7889, 7979, 8063, 8143, 8217, 8285, 8347,
+ 8403, 8453, 8497, 8535, 8567, 8593, 8613, 8627, 8633, 8634,
+ 0, 1, 7, 21, 41, 67, 99, 137, 181, 231,
+ 287, 349, 417, 491, 571, 657, 749, 845, 947, 1053,
+ 1165, 1281, 1401, 1527, 1657, 1791, 1929, 2069, 2213, 2361,
+ 2511, 2663, 2819, 2977, 3137, 3299, 3463, 3627, 3793, 3959,
+ 4125, 4293, 4461, 4629, 4795, 4961, 5127, 5291, 5455, 5617,
+ 5777, 5935, 6091, 6243, 6393, 6541, 6685, 6825, 6963, 7097,
+ 7227, 7353, 7473, 7589, 7701, 7807, 7909, 8005, 8097, 8183,
+ 8263, 8337, 8405, 8467, 8523, 8573, 8617, 8655, 8687, 8713,
+ 8733, 8747, 8753, 8754, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 491, 571, 657,
+ 747, 843, 943, 1049, 1159, 1275, 1395, 1519, 1647, 1779,
+ 1915, 2055, 2199, 2345, 2495, 2647, 2803, 2961, 3121, 3283,
+ 3447, 3613, 3779, 3947, 4115, 4285, 4455, 4625, 4795, 4965,
+ 5133, 5301, 5467, 5633, 5797, 5959, 6119, 6277, 6433, 6585,
+ 6735, 6881, 7025, 7165, 7301, 7433, 7561, 7685, 7805, 7921,
+ 8031, 8137, 8237, 8333, 8423, 8509, 8589, 8663, 8731, 8793,
+ 8849, 8899, 8943, 8981, 9013, 9039, 9059, 9073, 9079, 9080,
+ 0, 1, 7, 19, 39, 65, 97, 135, 179, 229,
+ 285, 347, 415, 489, 567, 651, 741, 835, 935, 1041,
+ 1151, 1265, 1385, 1509, 1637, 1769, 1905, 2045, 2189, 2335,
+ 2485, 2637, 2793, 2951, 3111, 3273, 3437, 3603, 3771, 3939,
+ 4109, 4279, 4451, 4623, 4795, 4967, 5139, 5309, 5479, 5647,
+ 5815, 5981, 6145, 6307, 6467, 6625, 6781, 6933, 7083, 7229,
+ 7373, 7513, 7649, 7781, 7909, 8033, 8153, 8267, 8377, 8483,
+ 8583, 8677, 8767, 8851, 8929, 9003, 9071, 9133, 9189, 9239,
+ 9283, 9321, 9353, 9379, 9399, 9411, 9417, 9418, 0, 1,
+ 7, 21, 41, 67, 99, 137, 181, 231, 287, 349,
+ 417, 491, 571, 657, 747, 843, 945, 1051, 1163, 1279,
+ 1399, 1525, 1655, 1789, 1927, 2069, 2213, 2361, 2513, 2667,
+ 2825, 2985, 3147, 3311, 3477, 3645, 3815, 3985, 4157, 4329,
+ 4503, 4677, 4851, 5025, 5199, 5371, 5543, 5713, 5883, 6051,
+ 6217, 6381, 6543, 6703, 6861, 7015, 7167, 7315, 7459, 7601,
+ 7739, 7873, 8003, 8129, 8249, 8365, 8477, 8583, 8685, 8781,
+ 8871, 8957, 9037, 9111, 9179, 9241, 9297, 9347, 9391, 9429,
+ 9461, 9487, 9507, 9521, 9527, 9528, 0, 1, 7, 21,
+ 41, 67, 99, 137, 181, 231, 287, 349, 417, 491,
+ 571, 657, 749, 845, 947, 1055, 1167, 1285, 1407, 1533,
+ 1663, 1797, 1935, 2077, 2223, 2373, 2525, 2681, 2839, 3001,
+ 3165, 3331, 3499, 3669, 3839, 4011, 4185, 4359, 4533, 4709,
+ 4885, 5061, 5235, 5409, 5583, 5755, 5925, 6095, 6263, 6429,
+ 6593, 6755, 6913, 7069, 7221, 7371, 7517, 7659, 7797, 7931,
+ 8061, 8187, 8309, 8427, 8539, 8647, 8749, 8845, 8937, 9023,
+ 9103, 9177, 9245, 9307, 9363, 9413, 9457, 9495, 9527, 9553,
+ 9573, 9587, 9593, 9594, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 491, 571, 655,
+ 745, 841, 941, 1047, 1157, 1273, 1393, 1517, 1647, 1781,
+ 1919, 2061, 2207, 2355, 2507, 2663, 2821, 2981, 3145, 3311,
+ 3479, 3649, 3821, 3993, 4167, 4341, 4517, 4693, 4869, 5045,
+ 5221, 5397, 5573, 5747, 5921, 6093, 6265, 6435, 6603, 6769,
+ 6933, 7093, 7251, 7407, 7559, 7707, 7853, 7995, 8133, 8267,
+ 8397, 8521, 8641, 8757, 8867, 8973, 9073, 9169, 9259, 9343,
+ 9423, 9497, 9565, 9627, 9683, 9733, 9777, 9815, 9847, 9873,
+ 9893, 9907, 9913, 9914, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 491, 571, 657,
+ 747, 843, 945, 1051, 1163, 1279, 1401, 1527, 1657, 1791,
+ 1929, 2071, 2217, 2367, 2519, 2675, 2835, 2997, 3161, 3327,
+ 3495, 3665, 3837, 4011, 4185, 4361, 4537, 4715, 4893, 5071,
+ 5249, 5427, 5603, 5779, 5953, 6127, 6299, 6469, 6637, 6803,
+ 6967, 7129, 7289, 7445, 7597, 7747, 7893, 8035, 8173, 8307,
+ 8437, 8563, 8685, 8801, 8913, 9019, 9121, 9217, 9307, 9393,
+ 9473, 9547, 9615, 9677, 9733, 9783, 9827, 9865, 9897, 9923,
+ 9943, 9957, 9963, 9964, 0, 1, 7, 21, 41, 67,
+ 99, 137, 181, 231, 287, 349, 417, 491, 571, 657,
+ 749, 845, 947, 1055, 1167, 1285, 1407, 1533, 1663, 1799,
+ 1939, 2083, 2229, 2379, 2533, 2689, 2849, 3011, 3177, 3345,
+ 3515, 3687, 3861, 4035, 4211, 4387, 4565, 4743, 4921, 5099,
+ 5277, 5455, 5633, 5809, 5985, 6159, 6333, 6505, 6675, 6843,
+ 7009, 7171, 7331, 7487, 7641, 7791, 7937, 8081, 8221, 8357,
+ 8487, 8613, 8735, 8853, 8965, 9073, 9175, 9271, 9363, 9449,
+ 9529, 9603, 9671, 9733, 9789, 9839, 9883, 9921, 9953, 9979,
+ 9999, 10013, 10019, 10020, 0, 1, 7, 19, 39, 65,
+ 97, 135, 179, 229, 285, 347, 415, 489, 567, 651,
+ 741, 837, 937, 1043, 1153, 1269, 1389, 1513, 1643, 1777,
+ 1915, 2057, 2203, 2351, 2503, 2659, 2817, 2979, 3143, 3309,
+ 3477, 3647, 3819, 3993, 4169, 4345, 4523, 4701, 4881, 5061,
+ 5241, 5421, 5601, 5779, 5957, 6133, 6309, 6483, 6655, 6825,
+ 6993, 7159, 7323, 7485, 7643, 7799, 7951, 8099, 8245, 8387,
+ 8525, 8659, 8789, 8913, 9033, 9149, 9259, 9365, 9465, 9561,
+ 9651, 9735, 9813, 9887, 9955, 10017, 10073, 10123, 10167, 10205,
+ 10237, 10263, 10283, 10295, 10301, 10302, 0, 1, 7, 21,
+ 41, 67, 99, 137, 181, 231, 287, 349, 417, 491,
+ 571, 655, 745, 841, 941, 1047, 1159, 1275, 1395, 1521,
+ 1651, 1785, 1923, 2065, 2211, 2361, 2513, 2669, 2829, 2991,
+ 3155, 3321, 3491, 3663, 3837, 4011, 4187, 4365, 4543, 4723,
+ 4903, 5083, 5263, 5443, 5623, 5803, 5981, 6159, 6335, 6509,
+ 6683, 6855, 7025, 7191, 7355, 7517, 7677, 7833, 7985, 8135,
+ 8281, 8423, 8561, 8695, 8825, 8951, 9071, 9187, 9299, 9405,
+ 9505, 9601, 9691, 9775, 9855, 9929, 9997, 10059, 10115, 10165,
+ 10209, 10247, 10279, 10305, 10325, 10339, 10345, 10346, 0, 1,
+ 7, 21, 41, 67, 99, 137, 181, 231, 287, 349,
+ 417, 491, 571, 655, 745, 841, 943, 1049, 1161, 1277,
+ 1397, 1523, 1653, 1787, 1925, 2067, 2213, 2363, 2517, 2673,
+ 2833, 2995, 3159, 3327, 3497, 3669, 3843, 4019, 4195, 4373,
+ 4551, 4731, 4911, 5091, 5271, 5451, 5631, 5811, 5989, 6167,
+ 6343, 6519, 6693, 6865, 7035, 7203, 7367, 7529, 7689, 7845,
+ 7999, 8149, 8295, 8437, 8575, 8709, 8839, 8965, 9085, 9201,
+ 9313, 9419, 9521, 9617, 9707, 9791, 9871, 9945, 10013, 10075,
+ 10131, 10181, 10225, 10263, 10295, 10321, 10341, 10355, 10361, 10362,
+ 0, 1, 7, 21, 41, 67, 99, 137, 181, 231,
+ 287, 349, 417, 491, 571, 657, 747, 843, 945, 1051,
+ 1163, 1279, 1399, 1525, 1655, 1789, 1927, 2069, 2215, 2365,
+ 2519, 2675, 2835, 2997, 3161, 3329, 3499, 3671, 3845, 4021,
+ 4197, 4375, 4553, 4733, 4913, 5093, 5273, 5453, 5633, 5813,
+ 5991, 6169, 6345, 6521, 6695, 6867, 7037, 7205, 7369, 7531,
+ 7691, 7847, 8001, 8151, 8297, 8439, 8577, 8711, 8841, 8967,
+ 9087, 9203, 9315, 9421, 9523, 9619, 9709, 9795, 9875, 9949,
+ 10017, 10079, 10135, 10185, 10229, 10267, 10299, 10325, 10345, 10359,
+ 10365, 10366
+};
+
+const int16_t ivas_pca_offset_n2[IVAS_PCA_N1] =
+{
+ 0, 2, 6, 14, 24, 38, 56, 76, 100, 126, 156, 188,
+ 224, 262, 302, 346, 392, 442, 494, 548, 604, 664, 726, 790,
+ 856, 924, 994, 1066, 1140, 1216, 1294, 1374, 1454, 1536, 1620, 1704,
+ 1790, 1878, 1966, 2054, 2144, 2234, 2324, 2416, 2508, 2600, 2692, 2784,
+ 2876, 2968, 3058, 3148, 3238, 3326, 3414, 3502, 3588, 3672, 3756, 3838,
+ 3918, 3998, 4076, 4152, 4226, 4298, 4368, 4436, 4502, 4566, 4628, 4688,
+ 4744, 4798, 4850, 4900, 4946, 4990, 5030, 5068, 5104, 5136, 5166, 5192,
+ 5216, 5236, 5254, 5268, 5278, 5286, 5290
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * Parametric MC ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const int16_t param_mc_band_grouping_20[20 + 1] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 17, 20, 23, 27, 33, 40, 52, 60
+};
+
+const int16_t param_mc_coding_band_mapping_20[20] =
+{
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+const int16_t param_mc_bands_coded_20[4] =
+{
+ 10, 14, 18, 20
+};
+
+const int16_t param_mc_band_grouping_14[14 + 1] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 28, 40, 60
+};
+
+const int16_t param_mc_coding_band_mapping_14[14] =
+{
+ 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
+};
+
+const int16_t param_mc_bands_coded_14[4] =
+{
+ 8, 11, 13, 14
+};
+
+const int16_t param_mc_band_grouping_10[10 + 1] =
+{
+ 0, 1, 2, 3, 5, 7, 10, 14, 20, 40, 60
+};
+
+
+const int16_t param_mc_bands_coded_10[4] =
+{
+ 6, 8, 9, 10
+};
+
+const int16_t param_mc_coding_band_mapping_10[10] =
+{
+ 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
+};
+
+const int16_t Param_MC_index[MAX_CICP_CHANNELS] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+};
+
+const float ivas_param_mc_dmx_fac_CICP6_2tc[12] =
+{
+ 1.0f, 0.0f, INV_SQRT2, INV_SQRT2, 1.0f, 0.0f, /*Lt*/
+ 0.0f, 1.0f, INV_SQRT2, INV_SQRT2, 0.0f, 1.0f /*Rt*/
+};
+
+const float ivas_param_mc_dmx_fac_CICP12_2tc[16] =
+{
+ 1.0f, 0.0f, INV_SQRT2, INV_SQRT2, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/
+ 0.0f, 1.0f, INV_SQRT2, INV_SQRT2, 0.0f, 1.0f, 0.0f, 1.0f /*Rt*/
+};
+
+const float ivas_param_mc_dmx_fac_CICP12_3tc[24] =
+{
+ 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/
+ 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rt*/
+ 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f /*Ct*/
+};
+
+const float ivas_param_mc_dmx_fac_CICP14_2tc[16] =
+{
+ 1.0f, 0.0f, INV_SQRT2, INV_SQRT2, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/
+ 0.0f, 1.0f, INV_SQRT2, INV_SQRT2, 0.0f, 1.0f, 0.0f, 1.0f /*Rt*/
+};
+const float ivas_param_mc_dmx_fac_CICP14_3tc[24] =
+{
+ 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/
+ 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rt*/
+ 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, /*Ct*/
+};
+
+const float ivas_param_mc_dmx_fac_CICP16_3tc[30] =
+{
+ 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/
+ 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rt*/
+ 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f /*Ct*/
+};
+
+const float ivas_param_mc_dmx_fac_CICP19_3tc[36] =
+{
+ 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/
+ 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rt*/
+ 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f /*Ct*/
+};
+
+const float ivas_param_mc_dmx_fac_CICP19_4tc[48] =
+{
+ 1.0f, 0.0f, INV_SQRT2, INV_SQRT2, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, /*Lht*/
+ 0.0f, 1.0f, INV_SQRT2, INV_SQRT2, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, /*Rht*/
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lut*/
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rut*/
+};
+
+/* Coefficient for Parametric MC ILD factorization */
+const float ivas_param_mc_ild_fac_CICP6_2tc[6] =
+{
+ 0.391608498887651f,
+ 0.391608498887651f,
+ 0.208150823035836f,
+ 0.323713613305539f,
+ 0.323713613305539f,
+ 0.208150823035836f,
+};
+
+const float ivas_param_mc_ild_fac_CICP12_2tc[8] =
+{
+ 0.365151211522008f,
+ 0.365151211522008f,
+ 0.208008958987949f,
+ 0.209863469733018f,
+ 0.209863469733018f,
+ 0.171473949468979f,
+ 0.171473949468979f,
+ 0.208008958987949f
+};
+
+const float ivas_param_mc_ild_fac_CICP12_3tc[8] =
+{
+ 0.5f,
+ 0.5f,
+ 0.29f,
+ 0.29f,
+ 0.2f,
+ 0.2f,
+ 1.0f,
+ 0.25f
+};
+
+const float ivas_param_mc_ild_fac_CICP14_2tc[8] =
+{
+ 0.36427054f,
+ 0.36427054f,
+ 0.18290930f,
+ 0.21193730f,
+ 0.21193730f,
+ 0.24564756f,
+ 0.24564756f,
+ 0.20800895f
+};
+
+const float ivas_param_mc_ild_fac_CICP14_3tc[8] =
+{
+ 0.49716263f,
+ 0.49716263f,
+ 0.25198298f,
+ 0.25198298f,
+ 0.29498283f,
+ 0.29498283f,
+ 1.0f,
+ 0.25f
+};
+
+const float ivas_param_mc_ild_fac_CICP16_3tc[10] =
+{
+ 0.34f,
+ 0.34f,
+ 0.22f,
+ 0.22f,
+ 0.20f,
+ 0.20f,
+ 0.18f,
+ 0.18f,
+ 1.0f,
+ 0.25f,
+};
+
+const float ivas_param_mc_ild_fac_CICP19_3tc[12] =
+{
+ 0.3f,
+ 0.3f,
+ 0.17f,
+ 0.17f,
+ 0.12f,
+ 0.12f,
+ 0.19f,
+ 0.19f,
+ 0.19f,
+ 0.19f,
+ 1.0f,
+ 0.5f
+};
+
+const float ivas_param_mc_ild_fac_CICP19_4tc[12] =
+{
+ 0.35f,
+ 0.35f,
+ 0.17f,
+ 0.22f,
+ 0.2f,
+ 0.2f,
+ 0.2f,
+ 0.5f,
+ 0.5f,
+ 0.5f,
+ 0.5f,
+ 0.2f,
+};
+
+const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP6_2tc =
+{
+ 5,
+ 6,
+ {0,1,2,4,5,3},
+ {1,1,2,1,1,2},
+ {{0},{1},{0,1},{0},{1},{0,1}}
+};
+
+const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP12_2tc =
+{
+ 7,
+ 8,
+ {0,1,2,4,5,6,7,3},
+ {1,1,2,1,1,1,1,2},
+ {{0},{1},{0,1},{0},{1},{0},{1},{0,1}}
+};
+
+const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP12_3tc =
+{
+ 6,
+ 8,
+ {0,1,4,5,6,7,2,3},
+ {1,1,1,1,1,1,1,1},
+ {{0},{1},{0},{1},{0},{1},{2},{2}}
+};
+
+const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP14_2tc =
+{
+ 7,
+ 8,
+ {0,1,2,4,5,6,7,3},
+ {1,1,2,1,1,1,1,2},
+ {{0},{1},{0,1},{0},{1},{0},{1},{0,1}}
+};
+
+const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP14_3tc =
+{
+ 6,
+ 8,
+ {0,1,4,5,6,7,2,3},
+ {1,1,1,1,1,1,1,1},
+ {{0},{1},{0},{1},{0},{1},{2},{2}}
+};
+
+const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP16_3tc =
+{
+ 8,
+ 10,
+ {0,1,4,5,6,7,8,9,2,3},
+ {1,1,1,1,1,1,1,1,1,1},
+ {{0},{1},{0},{1},{0},{1},{0},{1},{2},{2}}
+};
+
+const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP19_3tc =
+{
+ 10,
+ 12,
+ {0,1,4,5,6,7,8,9,10,11,2,3},
+ {1,1,1,1,1,1,1,1,1,1,1,1},
+ {{0},{1},{0},{1},{0},{1},{0},{1},{0},{1},{2},{2}}
+};
+
+const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP19_4tc =
+{
+ 11,
+ 12,
+ {0,1,2,4,5,6,7,8,9,10,11,3},
+ {1,1,2,1,1,1,1,1,1,1,1,2},
+ {{0},{1},{0,1},{0},{1},{0},{1},{2},{3},{2},{3},{0,1}}
+};
+
+const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP6_2tc =
+{
+ 4,
+ 5,
+ { { 0, 4 }, /* L/LS */
+ { 1, 5 }, /* R/RS */
+ { 0, 2 }, /* L/C */
+ { 1, 2 }, /* R/C */
+ { 2, 3 }} /* C/LFE */
+};
+
+const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP12_2tc =
+{
+ 6,
+ 7,
+ { { 0, 4 }, /* L/LS */
+ { 1, 5 }, /* R/RS */
+ { 0, 2 }, /* L/C */
+ { 1, 2 }, /* R/C */
+ { 2, 6 }, /* C/BLS */
+ { 2, 7 }, /* C/BRS */
+ { 2, 3 } /* C/LFE */
+ }
+};
+
+const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP12_3tc =
+{
+ 6,
+ 7,
+ { { 0, 4 }, /* L/LS */
+ { 1, 5 }, /* R/RS */
+ { 0, 2 }, /* L/C */
+ { 1, 2 }, /* R/C */
+ { 0, 6 }, /* L/BLS */
+ { 1, 7 }, /* R/BRS */
+ { 2, 3 } /* C/LFE */
+ }
+};
+
+const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP14_2tc =
+{
+ 6,
+ 7,
+ { { 0, 4 }, /* L/LS */
+ { 1, 5 }, /* R/RS */
+ { 0, 2 }, /* L/C */
+ { 1, 2 }, /* R/C */
+ { 2, 6 }, /* C/UFL */
+ { 2, 7 }, /* C/UFR */
+ { 2, 3 } /* C/LFE */
+ }
+};
+const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP14_3tc =
+{
+ 6,
+ 7,
+ { { 0, 4 }, /* L/LS */
+ { 1, 5 }, /* R/RS */
+ { 0, 2 }, /* L/C */
+ { 1, 2 }, /* R/C */
+ { 0, 6 }, /* L/UFL */
+ { 1, 7 }, /* R/UFR */
+ { 2, 3 } /* C/LFE */
+ }
+};
+
+const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP16_3tc =
+{
+ 8,
+ 9,
+ { { 0, 4 }, /* L/LS */
+ { 1, 5 }, /* R/RS */
+ { 0, 2 }, /* L/C */
+ { 1, 2 }, /* R/C */
+ { 0, 6 }, /* L/UFL */
+ { 1, 7 }, /* R/UFR */
+ { 4, 8 }, /* LS/UBL */
+ { 5, 9 }, /* RS/UBR */
+ { 2, 3 } /* C/LFE */
+ }
+};
+
+const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP19_3tc =
+{
+ 10,
+ 11,
+ { { 0, 4 }, /* L/LS */
+ { 1, 5 }, /* R/RS */
+ { 0, 2 }, /* L/C */
+ { 1, 2 }, /* R/C */
+ { 0, 6 }, /* L/LBS */
+ { 1, 7 }, /* R/RBS */
+ { 0, 8 }, /* L/UFL */
+ { 1, 9 }, /* R/UFR */
+ { 6, 10 }, /* LBS/UBL */
+ { 7, 11 }, /* RBS/UBR */
+ { 2, 3 } /* C/LFE */
+ }
+};
+
+const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP19_4tc =
+{
+ 8,
+ 9,
+ { { 0, 4 }, /* L/LS */
+ { 1, 5 }, /* R/RS */
+ { 0, 2 }, /* L/C */
+ { 1, 2 }, /* R/C */
+ { 0, 6 }, /* L/LBS */
+ { 1, 7 }, /* R/RBS */
+ { 8, 10 }, /*UFL/UBL */
+ { 9, 11 }, /*UFR/UBR */
+ { 2, 3 } /* C/LFE */
+ }
+};
+
+const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] =
+{
+ /* CICP6 48000 */
+ {
+ MC_LS_SETUP_5_1,
+ 6,
+ 2,
+ IVAS_48k,
+ &ivas_param_mc_ild_mapping_CICP6_2tc,
+ &ivas_param_mc_icc_mapping_CICP6_2tc,
+ &ivas_param_mc_dmx_fac_CICP6_2tc[0],
+ &ivas_param_mc_ild_fac_CICP6_2tc[0]
+ },
+ /* CICP6 64000 */
+ {
+ MC_LS_SETUP_5_1,
+ 6,
+ 2,
+ IVAS_64k,
+ &ivas_param_mc_ild_mapping_CICP6_2tc,
+ &ivas_param_mc_icc_mapping_CICP6_2tc,
+ &ivas_param_mc_dmx_fac_CICP6_2tc[0],
+ &ivas_param_mc_ild_fac_CICP6_2tc[0]
+ },
+ /* CICP6 80000 */
+ {
+ MC_LS_SETUP_5_1,
+ 6,
+ 2,
+ IVAS_80k,
+ &ivas_param_mc_ild_mapping_CICP6_2tc,
+ &ivas_param_mc_icc_mapping_CICP6_2tc,
+ &ivas_param_mc_dmx_fac_CICP6_2tc[0],
+ &ivas_param_mc_ild_fac_CICP6_2tc[0]
+ },
+ /* CICP12 48000 */
+ {
+ MC_LS_SETUP_7_1,
+ 8,
+ 2,
+ IVAS_48k,
+ &ivas_param_mc_ild_mapping_CICP12_2tc,
+ &ivas_param_mc_icc_mapping_CICP12_2tc,
+ &ivas_param_mc_dmx_fac_CICP12_2tc[0],
+ &ivas_param_mc_ild_fac_CICP12_2tc[0]
+ },
+ /* CICP12 64000 */
+ {
+ MC_LS_SETUP_7_1,
+ 8,
+ 2,
+ IVAS_64k,
+ &ivas_param_mc_ild_mapping_CICP12_2tc,
+ &ivas_param_mc_icc_mapping_CICP12_2tc,
+ &ivas_param_mc_dmx_fac_CICP12_2tc[0],
+ &ivas_param_mc_ild_fac_CICP12_2tc[0]
+ },
+ /* CICP12 80000 */
+ {
+ MC_LS_SETUP_7_1,
+ 8,
+ 2,
+ IVAS_80k,
+ &ivas_param_mc_ild_mapping_CICP12_2tc,
+ &ivas_param_mc_icc_mapping_CICP12_2tc,
+ &ivas_param_mc_dmx_fac_CICP12_2tc[0],
+ &ivas_param_mc_ild_fac_CICP12_2tc[0]
+ },
+ /* CICP12 96000 */
+ {
+ MC_LS_SETUP_7_1,
+ 8,
+ 3,
+ IVAS_96k,
+ &ivas_param_mc_ild_mapping_CICP12_3tc,
+ &ivas_param_mc_icc_mapping_CICP12_3tc,
+ &ivas_param_mc_dmx_fac_CICP12_3tc[0],
+ &ivas_param_mc_ild_fac_CICP12_3tc[0]
+ },
+ /* CICP14 48000 */
+ {
+ MC_LS_SETUP_5_1_2,
+ 8,
+ 2,
+ IVAS_48k,
+ &ivas_param_mc_ild_mapping_CICP14_2tc,
+ &ivas_param_mc_icc_mapping_CICP14_2tc,
+ &ivas_param_mc_dmx_fac_CICP14_2tc[0],
+ &ivas_param_mc_ild_fac_CICP14_2tc[0]
+ },
+ /* CICP14 64000 */
+ {
+ MC_LS_SETUP_5_1_2,
+ 8,
+ 2,
+ IVAS_64k,
+ &ivas_param_mc_ild_mapping_CICP14_2tc,
+ &ivas_param_mc_icc_mapping_CICP14_2tc,
+ &ivas_param_mc_dmx_fac_CICP14_2tc[0],
+ &ivas_param_mc_ild_fac_CICP14_2tc[0]
+ },
+ /* CICP14 80000 */
+ {
+ MC_LS_SETUP_5_1_2,
+ 8,
+ 2,
+ IVAS_80k,
+ &ivas_param_mc_ild_mapping_CICP14_2tc,
+ &ivas_param_mc_icc_mapping_CICP14_2tc,
+ &ivas_param_mc_dmx_fac_CICP14_2tc[0],
+ &ivas_param_mc_ild_fac_CICP14_2tc[0]
+ },
+ /* CICP14 96000 */
+ {
+ MC_LS_SETUP_5_1_2,
+ 8,
+ 3,
+ IVAS_96k,
+ &ivas_param_mc_ild_mapping_CICP14_3tc,
+ &ivas_param_mc_icc_mapping_CICP14_3tc,
+ &ivas_param_mc_dmx_fac_CICP14_3tc[0],
+ &ivas_param_mc_ild_fac_CICP14_3tc[0]
+ },
+ /* CICP16 96000 */
+ {
+ MC_LS_SETUP_5_1_4,
+ 10,
+ 3,
+ IVAS_96k,
+ &ivas_param_mc_ild_mapping_CICP16_3tc,
+ &ivas_param_mc_icc_mapping_CICP16_3tc,
+ &ivas_param_mc_dmx_fac_CICP16_3tc[0],
+ &ivas_param_mc_ild_fac_CICP16_3tc[0]
+ },
+ /* CICP16 128000 */
+ {
+ MC_LS_SETUP_5_1_4,
+ 10,
+ 3,
+ IVAS_128k,
+ &ivas_param_mc_ild_mapping_CICP16_3tc,
+ &ivas_param_mc_icc_mapping_CICP16_3tc,
+ &ivas_param_mc_dmx_fac_CICP16_3tc[0],
+ &ivas_param_mc_ild_fac_CICP16_3tc[0]
+ },
+ /* CICP19 128000 */
+ {
+ MC_LS_SETUP_7_1_4,
+ 12,
+ 3,
+ IVAS_128k,
+ &ivas_param_mc_ild_mapping_CICP19_3tc,
+ &ivas_param_mc_icc_mapping_CICP19_3tc,
+ &ivas_param_mc_dmx_fac_CICP19_3tc[0],
+ &ivas_param_mc_ild_fac_CICP19_3tc[0]
+ },
+ /* CICP19 160000 */
+ {
+ MC_LS_SETUP_7_1_4,
+ 12,
+ 4,
+ IVAS_160k,
+ &ivas_param_mc_ild_mapping_CICP19_4tc,
+ &ivas_param_mc_icc_mapping_CICP19_4tc,
+ &ivas_param_mc_dmx_fac_CICP19_4tc[0],
+ &ivas_param_mc_ild_fac_CICP19_4tc[0]
+ }
+};
+
+const float ivas_param_mc_quant_ild_5d1_48[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ -100.0f, -20.0f, -13.0f, -10.0f,
+ -8.0f, -5.5f, -3.5f, -1.5f, 0.0f, 1.5f, 3.5f, 5.5f, 8.0f, 10.0f, 13.0f, 20.0f
+};
+
+/* Quantizer for ICCs in Parametric MC Processing */
+const float ivas_param_mc_quant_icc[PARAM_MC_SZ_ICC_QUANTIZER] =
+{
+ -0.99f, -0.589f, 0.0f, 0.36764f, 0.60092f, 0.84118f, 0.937f, 1.0f
+};
+
+/* Alphabet for delta coding for the ICCs in Parametric MC processing */
+const uint16_t ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] =
+{
+ 0, 24, 224, 20873, 42384, 51699, 57122, 60572, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] =
+{
+ 24, 200, 20649, 21511, 9315, 5423, 3450, 4963
+};
+
+const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] =
+{
+ 0, 4, 9, 124, 447, 1311, 4453, 18116, 48636, 60573, 63692, 64746, 65327, 65531, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] =
+{
+ 4, 5, 115, 323, 864, 3142, 13663, 30520, 11937, 3119, 1054, 581, 204, 3, 1
+};
+
+const uint16_t ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] =
+{
+ 0, 30, 848, 26611, 47846, 57358, 61679, 63237, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] =
+{
+ 30, 818, 25763, 21235, 9512, 4321, 1558, 2298
+};
+
+const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] =
+{
+ 0, 2, 7, 53, 243, 979, 3994, 16732, 49642, 61343, 64331, 65158, 65438, 65532, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] =
+{
+ 2, 5, 46, 190, 736, 3015, 12738, 32910, 11701, 2988, 827, 280, 94, 2, 1
+};
+
+const uint16_t ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] =
+{
+ 0, 46, 826, 27798, 49552, 58447, 62046, 63284, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER ]={
+ 46, 780, 26972, 21754, 8895, 3599, 1238, 2251
+};
+
+const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] =
+{
+ 0, 3, 8, 36, 172, 763, 3436, 15845, 50168, 62005, 64676, 65298, 65481, 65533, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2* PARAM_MC_SZ_ICC_QUANTIZER - 1] =
+{
+ 3, 5, 28, 136, 591, 2673, 12409, 34323, 11837, 2671, 622, 183, 52, 1, 1
+};
+
+const uint16_t ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] =
+{
+ 0, 34, 552, 24717, 45819, 54772, 59054, 61166, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] =
+{
+ 34, 518, 24165, 21102, 8953, 4282, 2112, 4369
+};
+
+const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] =
+{
+ 0, 3, 7, 74, 304, 1009, 3870, 16502, 49834, 61384, 64217, 65020, 65369, 65531, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] =
+{
+ 3, 4, 67, 230, 705, 2861, 12632, 33332, 11550, 2833, 803, 349, 162, 3, 1
+};
+
+const uint16_t ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] =
+{
+ 0, 1092, 5574, 8315, 10652, 13875, 19656, 27664, 36284, 47058, 56251, 62579, 65118, 65462, 65513, 65532, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ 1092, 4482, 2741, 2337, 3223, 5781, 8008, 8620, 10774, 9193, 6328, 2539, 344, 51, 19, 3
+};
+
+const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ 0, 1, 2, 3, 5, 38, 146, 352, 638, 997, 1559, 2323, 3570, 5859, 10556, 21075, 44682, 55617, 60408, 62739, 63833, 64443, 64809, 65074, 65279, 65400, 65484, 65531, 65532, 65533, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] =
+{
+ 1, 1, 1, 2, 33, 108, 206, 286, 359, 562, 764, 1247, 2289, 4697, 10519, 23607, 10935, 4791, 2331, 1094, 610, 366, 265, 205, 121, 84, 47, 1, 1, 1, 1
+};
+
+const uint16_t ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] =
+{
+ 0, 967, 6335, 9941, 12837, 16652, 22416, 29814, 38807, 48497, 57184, 62661, 64916, 65466, 65514, 65530, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ 967, 5368, 3606, 2896, 3815, 5764, 7398, 8993, 9690, 8687, 5477, 2255, 550, 48, 16, 5
+};
+
+const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ 0, 1, 2, 3, 5, 18, 61, 149, 320, 592, 1083, 1793, 2974, 5257, 10133, 21274, 44342, 55891, 60895, 63174, 64244, 64793, 65100, 65287, 65406, 65477, 65517, 65531, 65532, 65533, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] =
+{
+ 1, 1, 1, 2, 13, 43, 88, 171, 272, 491, 710, 1181, 2283, 4876, 11141, 23068, 11549, 5004, 2279, 1070, 549, 307, 187, 119, 71, 40, 14, 1, 1, 1, 1
+};
+
+const uint16_t ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] =
+{
+ 0, 229, 7068, 10910, 13856, 17467, 22629, 29174, 36906, 46558, 55579, 61802, 65222, 65505, 65527, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ 229, 6839, 3842, 2946, 3611, 5162, 6545, 7732, 9652, 9021, 6223, 3420, 283, 22, 7, 1
+};
+
+const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ 0, 1, 2, 3, 4, 12, 56, 153, 278, 475, 856, 1430, 2489, 4723, 9580, 20685, 45423, 56274, 60948, 63097, 64128, 64679, 65002, 65208, 65348, 65445, 65517, 65531, 65532, 65533, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] =
+{
+ 1, 1, 1, 1, 8, 44, 97, 125, 197, 381, 574, 1059, 2234, 4857, 11105, 24738, 10851, 4674, 2149, 1031, 551, 323, 206, 140, 97, 72, 14, 1, 1, 1, 1
+};
+
+const uint16_t ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS+1] =
+{
+ 0, 1453, 8326, 12221, 15164, 18764, 24177, 31297, 39520, 49154, 57135, 62460, 64821, 65468, 65514, 65530, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ 1453, 6873, 3895, 2943, 3600, 5413, 7120, 8223, 9634, 7981, 5325, 2361, 647, 46, 16, 5
+};
+
+const uint16_t ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] =
+{
+ 0, 1, 2, 3, 5, 29, 98, 220, 414, 699, 1186, 1876, 3049, 5304, 10013, 20612, 45247, 56109, 60818, 63022, 64081, 64647, 64977, 65198, 65348, 65443, 65502, 65530, 65532, 65533, 65534, 65535
+};
+
+const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] =
+{
+ 1, 1, 1, 2, 24, 69, 122, 194, 285, 487, 690, 1173, 2255, 4709, 10599, 24635, 10862, 4709, 2204, 1059, 566, 330, 221, 150, 95, 59, 28, 2, 1, 1, 1
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * Parametric Upmix MC ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const int16_t ivas_param_upmx_mx_qmap[2][33] =
+{
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
+ { 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0 }
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * MASA ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const float diffuseness_reconstructions_hr[HR_MASA_ER_LEVELS] =
+{
+ 0.00f,
+ 0.0142822265625f,
+ 0.030029296875f,
+ 0.052001953125f,
+ 0.07708740234375f,
+ 0.10528564453125f,
+ 0.14483642578125f,
+ 0.19573974609375f,
+ 0.26568603515625f,
+ 0.35467529296875f,
+ 0.436279296875f,
+ 0.510498046875f,
+ 0.5943603515625f,
+ 0.6878662109375f,
+ 0.80096435546875f,
+ 0.93365478515625f
+};
+const float diffuseness_thresholds_hr[HR_MASA_ER_LEVELS + 1] =
+{
+ 0.0f,
+ 0.009521484375f,
+ 0.01904296875f,
+ 0.0410156250f,
+ 0.06298828125f,
+ 0.0911865234375f,
+ 0.119384765625f,
+ 0.1702880859375f,
+ 0.22119140625f,
+ 0.3101806640625f,
+ 0.399169921875f,
+ 0.473388671875f,
+ 0.547607421875f,
+ 0.641113281250f,
+ 0.734619140625f,
+ 0.8673095703125f,
+ 2.0f /* out-of-range large value to make searching easier */
+};
+const int16_t bits_direction_masa[DIRAC_DIFFUSE_LEVELS] =
+{
+ 11,
+ 11,
+ 10,
+ 9,
+ 7,
+ 6,
+ 5,
+ 3
+};
+
+
+const float coherence_cb0_masa[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH] =
+{
+ /* this is the same */
+ 0.0478f, 0.2547f, 0.5515f, 0.9865f, 1.3573f, 1.6838f, 1.9674f, 0.0f,
+ 0.1211f, 0.4123f, 0.6997f, 1.0154f, 1.4197f, 1.7971f, 0.0f, 0.0f,
+ 0.1614f, 0.5674f, 0.9708f, 1.3699f, 1.7357f, 0.0f, 0.0f, 0.0f,
+ 0.2349f, 0.7306f, 1.2051f, 1.6547f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.2381f, 0.7185f, 1.1758f, 1.6335f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.2400f, 0.7027f, 1.1407f, 1.6243f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.3518f, 0.9398f, 1.6454f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+
+ 0.1445f, 0.3432f, 0.5351f, 0.7524f, 1.0095f, 1.3210f, 1.7399f, 0.0f,
+ 0.2002f, 0.4447f, 0.6869f, 0.9593f, 1.3090f, 1.7029f, 0.0f, 0.0f,
+ 0.2617f, 0.5556f, 0.8645f, 1.2185f, 1.6051f, 0.0f, 0.0f, 0.0f,
+ 0.3318f, 0.6810f, 1.0445f, 1.4710f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.3324f, 0.6588f, 0.9980f, 1.4164f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.3378f, 0.6658f, 1.0009f, 1.4269f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.3986f, 0.8244f, 1.3526f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f
+
+ /* 0.0478f, 0.2547f, 1.9674f, 0.9865f, 0.5515f, 1.6838f, 1.3573f, 0.0f,
+ 0.1211f, 0.4123f, 0.6997f, 1.0154f, 1.4197f, 1.7971f, 0.0f, 0.0f,
+ 0.5674f, 0.9708f, 0.1614f, 1.3699f, 1.7357f, 0.0f, 0.0f, 0.0f,
+ 0.7306f, 1.2051f, 0.2349f, 1.6547f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.7185f, 1.1758f, 0.2381f, 1.6335f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.7027f, 1.1407f, 0.2400f, 1.6243f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.9398f, 1.6454f, 0.3518f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+
+ 0.3432f, 0.1445f, 0.5351f, 0.7524f, 1.0095f, 1.3210f, 1.7399f, 0.0f,
+ 0.4447f, 0.2002f, 0.6869f, 0.9593f, 1.3090f, 1.7029f, 0.0f, 0.0f,
+ 0.5556f, 0.2617f, 0.8645f, 1.2185f, 1.6051f, 0.0f, 0.0f, 0.0f,
+ 0.6810f, 0.3318f, 1.0445f, 1.4710f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.6588f, 0.3324f, 0.9980f, 1.4164f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.6658f, 0.3378f, 1.0009f, 1.4269f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.3986f, 0.8244f, 1.3526f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f */
+};
+
+const float coherence_cb1_masa[MASA_NO_CV_COH1*MASA_MAXIMUM_CODING_SUBBANDS] =
+{
+ -0.0019f, 0.2597f, -0.2696f, 0.6269f, -0.6295f,
+ -0.0055f, 0.2582f, -0.2784f, 0.6473f, -0.6538f,
+ -0.0029f, 0.2506f, -0.2630f, 0.6498f, -0.6540f,
+ -0.0004f, 0.2546f, -0.2579f, 0.6851f, -0.6743f,
+ 0.0017f, 0.2521f, -0.2479f, 0.7217f, -0.7157f
+};
+
+const int16_t len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS] = { 7, 6, 5, 4, 4, 4, 3, 2 };
+
+const uint8_t sur_coherence_cb_masa[MASA_MAX_NO_CV_SUR_COH*MASA_NO_CB_SUR_COH] =
+{
+ 16, 99, 0, 0, 0, 0, 0, 0,
+ 12, 64, 167, 0, 0, 0, 0, 0,
+ 10, 45, 100, 218, 0, 0, 0, 0,
+ 8, 34, 70, 124, 235, 0, 0, 0,
+ 7, 27, 55, 90, 141, 242, 0, 0,
+ 7, 23, 45, 71, 105, 153, 247, 0,
+ 6, 20, 38, 60, 86, 119, 165, 249
+};
+
+const int16_t idx_cb_sur_coh_masa[MASA_MAX_NO_CV_SUR_COH] = { 0, 1, 2, 3, 4, 5, 5, 6 };
+
+const int16_t len_huf_masa[MASA_NO_CV_COH1] = { 4, 2, 1, 3, 4 };
+
+const int16_t huff_code_av_masa[MASA_NO_CV_COH1] = { 15, 2, 0, 6, 14 };
+
+const int16_t no_theta_masa[NO_SPHERICAL_GRIDS-2] = /* from 1 to 11 bits */
+{ /*1, 1,*/ 2 ,2 , 4, 5, 6, 7, 10, 14, 19
+ /*0, 2, 8, 6, 7, 12, 14, 16*/
+};
+
+const int16_t no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA] = /* from 1 to 11 bits*/
+{
+ { 2 },
+ { 4 },
+ { 4, 2 },
+ { 8, 4 }, /* 8, 4*/
+ { 12, 7, 2, 1 }, /* 12, */
+ { 14, 13, 9, 2, 1 },
+ { 22, 21, 17, 11, 3, 1 },
+ { 33, 32, 29, 23, 17, 9, 1 },
+ { 48, 47, 45, 41, 35, 28, 20, 12, 2, 1 },
+ { 60, 60, 58, 56, 54, 50, 46, 41, 36, 30, 23, 17, 10, 1 },
+ { 89, 89, 88, 86, 84, 81, 77, 73, 68, 63, 57, 51, 44, 38, 30, 23, 15, 8, 1 }
+};
+
+const float delta_theta_masa[NO_SPHERICAL_GRIDS - 2] =
+{ /*180.0f, 90.0f,*/ 45.0f, 45.0f, 36.0f, 25.5f, 20.0f, /*14.9f*/ 15.0f, 10.78f, 6.7f, 5.0f };
+/* spheres
+11 (10.9951) : (4.05,5) 89 89 88 86 84 81 77 73 68 63 57 51 44 38 30 23 15 8 1
+10 (10.0000): (6, 6.7) 60 60 58 56 54 50 46 41 36 30 23 17 10 1
+9 (8.9944): (7.5, 10.78) 48 47 45 41 35 28 20 12 2 1
+8 (7.9944): (10.8, 14.9) 33 32 29 23 17 9 1
+7 (7.0000): (16.5,20) 22 21 17 11 3 1
+6 (6.0000): (25,25.5) 14 13 9 2 1
+5 (5.0000): (36,36) 10 8 2 1
+4 (4.0000): (45 45) 8 4 (no +-90)
+3 (3.0000) (90,45) 4 2 (no +-90)
+2 (2.0000) (90,90) 4 (no +-90)
+1 () 2
+*/
+
+const float azimuth_cb[8] =
+{
+ 0.0f, -180.0f, -90.0f, 90.0f, -45.0f, 45.0f, -135.0f, 135.0f
+};
+
+const int16_t MASA_band_grouping_24[24 + 1] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 40, 60
+};
+
+const int16_t MASA_band_mapping_24_to_18[18 + 1] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 17, 20, 21, 22, 23, 24
+};
+
+const int16_t MASA_band_mapping_24_to_12[12 + 1] =
+{
+ 0, 1, 2, 3, 4, 5, 7, 9, 12, 15, 20, 22, 24
+};
+
+const int16_t MASA_band_mapping_24_to_8[8 + 1] =
+{
+ 0, 1, 2, 3, 5, 8, 12, 20, 24
+};
+
+const int16_t MASA_band_mapping_24_to_5[5 + 1] =
+{
+ 0, 1, 3, 7, 15, 24
+};
+
+const int16_t MASA_grouping_8_to_5[8] =
+{
+ 0, 1, 1, 2, 3, 3, 4, 4
+};
+
+const int16_t MASA_grouping_12_to_5[12] =
+{
+ 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4
+};
+
+const int16_t MASA_grouping_18_to_5[18] =
+{
+ 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4
+};
+
+const int16_t MASA_grouping_24_to_5[24] =
+{
+ 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4
+};
+
+/* IVAS_13k2, IVAS_16k4, IVAS_24k4, IVAS_32k, IVAS_48k, IVAS_64k, IVAS_80k, IVAS_96k, IVAS_128k, IVAS_160k, IVAS_192k, IVAS_256k, IVAS_384k, IVAS_512k */
+const int16_t masa_bits[IVAS_NUM_ACTIVE_BRATES] =
+{
+ 50, 60, 70, 85, 140, 180, 220, 256, 350, 432, 528, 832, 1024, MASA_MAX_BITS
+};
+
+const int16_t masa_bits_LR_stereo[4] =
+{
+ 50, 50, 60, 70
+};
+
+const int16_t mcmasa_bits[IVAS_NUM_ACTIVE_BRATES] =
+{
+ 50, 70, 80, 120, 140, 160, 220, 256, 288, 432, 528, 832, 1024, MASA_MAX_BITS
+};
+
+const uint8_t masa_nbands[IVAS_NUM_ACTIVE_BRATES] =
+{
+ 5, 5, 5, 5, 5, 5, 5, 5, 8, 12, 18, 24, 24, 24
+};
+
+const uint8_t masa_joined_nbands[IVAS_NUM_ACTIVE_BRATES] =
+{
+ 5, 5, 5, 8, 12, 12, 12, 18, 18, 18, 18, 24, 24, 24
+};
+
+const uint8_t masa_twodir_bands[IVAS_NUM_ACTIVE_BRATES] =
+{
+ 0, 0, 0, 0, 0, 1, 1, 1, 3, 4, 6, 6, 9, 24
+};
+
+const uint8_t masa_twodir_bands_joined[IVAS_NUM_ACTIVE_BRATES] =
+{
+ 0, 0, 0, 0, 0, 2, 2, 3, 4, 6, 8, 9, 12, MASA_MAXIMUM_TWO_DIR_BANDS
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * Multi-channel LS setups
+ *----------------------------------------------------------------------------------*/
+
+const float ls_azimuth_CICP2[2] = { 30.0f, -30.0f };
+const float ls_elevation_CICP2[2] = { 0.0f, 0.0f };
+
+const float ls_azimuth_CICP6[5] = { 30.0f, -30.0f, 0.0f, 110.0f, -110.0f };
+const float ls_elevation_CICP6[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
+
+const float ls_azimuth_CICP12[7] = { 30.0f, -30.0f, 0.0f, 110.0f, -110.0f, 135.0f, -135.0f };
+const float ls_elevation_CICP12[7] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
+
+const float ls_azimuth_CICP14[7] = { 30.0f, -30.0f, 0.0f, 110.0f, -110.0f, 30.0f, -30.0f };
+const float ls_elevation_CICP14[7] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 35.0f, 35.0f };
+
+const float ls_azimuth_CICP16[9] = { 30.0f, -30.0f, 0.0f, 110.0f, -110.0f, 30.0f, -30.0f, 110.0f, -110.0f };
+const float ls_elevation_CICP16[9] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 35.0f, 35.0f, 35.0f, 35.0f };
+
+const float ls_azimuth_CICP19[11] = { 30.0f, -30.0f, 0.0f, 135.0f, -135.0f, 90.0f, -90.0f, 30.0f, -30.0f, 135.0f, -135.0f };
+const float ls_elevation_CICP19[11] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 35.0f, 35.0f, 35.0f, 35.0f };
+
+const float cb_azi_chan[] = { 0.0f, 30.0f, 110.0f, 135.0f };
+
+const float McMASA_LFEGain_vectors[64] =
+{
+ 0.38f, 0.33f, 0.19f, 0.20f, /* 1st bit */
+ -0.16f, -0.22f, -0.35f, -0.34f,
+ 0.50f, 0.50f, 0.50f, 0.50f, /* 2nd bit*/
+ -0.80f, -0.40f, 1.02f, 0.10f,
+ -0.50f, -0.50f, -0.50f, -0.50f, /* 3rd bit */
+ -0.56f, -0.12f, -0.78f, 1.36f,
+ -1.02f, 1.18f, -0.57f, 0.33f,
+ 0.72f, -1.13f, 0.97f, -0.62f,
+ -0.91f, 0.93f, 1.00f, -1.10f, /* 4th bit*/
+ 1.73f, -0.23f, -0.78f, -0.84f,
+ 0.95f, -1.60f, -0.34f, 0.93f,
+ 0.87f, 0.47f, -1.90f, 0.52f,
+ 0.67f, 1.42f, -0.97f, -1.24f,
+ 0.83f, 0.58f, 0.61f, -2.04f,
+ -0.80f, -1.58f, 0.82f, 1.42f,
+ -2.14f, 0.26f, 0.84f, 1.02f
+};
+
+/*----------------------------------------------------------------------------------*
+ * OMASA ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const int32_t sep_object_brate[][MAX_NUM_OBJECTS] =
+{
+ {0, 0, 0, 0}, /* 13k2 */
+ {0, 0, 0, 0}, /* 16k4 */
+ {9600, 0, 0, 0}, /* 24k4 */
+ {IVAS_13k2, 0, 0, 0}, /* 32k */
+ {16000, 11000, 0, 0}, /* 48k */
+ {16000, 11700, 0, 0}, /* 64k */
+ {20000, 16000, 0, 0}, /* 80k */
+ {IVAS_32k, 20000, 20000, 0}, /* 96k */
+ {IVAS_32k, IVAS_24k4, 24000, 24000}, /* 128k */
+ {IVAS_48k, IVAS_32k, IVAS_24k4, 24000}, /* 160k */
+ {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */
+ {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */
+ {IVAS_128k, IVAS_80k, IVAS_64k, IVAS_48k}, /* 384k */
+ {IVAS_128k, IVAS_96k, IVAS_80k, IVAS_64k} /* 512k */
+};
+
+/* column wise DCT matrices for 4 5, and 8 dim */
+const float dct4[4*4] =
+{
+ 0.5000f, 0.6533f, 0.5000f, 0.2706f,
+ 0.5000f, 0.2706f, -0.5000f, -0.6533f,
+ 0.5000f, -0.2706f, -0.5000f, 0.6533f,
+ 0.5000f, -0.6533f, 0.5000f, -0.2706f
+};
+
+const float dct5[5*5] =
+{
+ 0.4472f, 0.6015f, 0.5117f, 0.3717f, 0.1954f,
+ 0.4472f, 0.3717f, -0.1954f, -0.6015f, -0.5117f,
+ 0.4472f, 0.0000f, -0.6325f, -0.0000f, 0.6325f,
+ 0.4472f, -0.3717f, -0.1954f, 0.6015f, -0.5117f,
+ 0.4472f, -0.6015f, 0.5117f, -0.3717f, 0.1954f
+};
+
+const float dct8[8*8] =
+{
+ 0.3536f, 0.4904f, 0.4619f, 0.4157f, 0.3536f, 0.2778f, 0.1913f, 0.0975f,
+ 0.3536f, 0.4157f, 0.1913f, -0.0975f, -0.3536f, -0.4904f, -0.4619f, -0.2778f,
+ 0.3536f, 0.2778f, -0.1913f, -0.4904f, -0.3536f, 0.0975f, 0.4619f, 0.4157f,
+ 0.3536f, 0.0975f, -0.4619f, -0.2778f, 0.3536f, 0.4157f, -0.1913f, -0.4904f,
+ 0.3536f, -0.0975f, -0.4619f, 0.2778f, 0.3536f, -0.4157f, -0.1913f, 0.4904f,
+ 0.3536f, -0.2778f, -0.1913f, 0.4904f, -0.3536f, -0.0975f, 0.4619f, -0.4157f,
+ 0.3536f, -0.4157f, 0.1913f, 0.0975f, -0.3536f, 0.4904f, -0.4619f, 0.2778f,
+ 0.3536f, -0.4904f, 0.4619f, -0.4157f, 0.3536f, -0.2778f, 0.1913f, -0.0975f
+};
+
+const float dct12[12*12]=
+{
+ 0.2887f, 0.4048f, 0.3943f, 0.3772f, 0.3536f, 0.3239f, 0.2887f, 0.2485f, 0.2041f, 0.1562f, 0.1057f, 0.0533f,
+ 0.2887f, 0.3772f, 0.2887f, 0.1562f, 0.0000f, -0.1562f, -0.2887f, -0.3772f, -0.4082f, -0.3772f, -0.2887f, -0.1562f,
+ 0.2887f, 0.3239f, 0.1057f, -0.1562f, -0.3536f, -0.4048f, -0.2887f, -0.0533f, 0.2041f, 0.3772f, 0.3943f, 0.2485f,
+ 0.2887f, 0.2485f, -0.1057f, -0.3772f, -0.3536f, -0.0533f, 0.2887f, 0.4048f, 0.2041f, -0.1562f, -0.3943f, -0.3239f,
+ 0.2887f, 0.1562f, -0.2887f, -0.3772f, -0.0000f, 0.3772f, 0.2887f, -0.1562f, -0.4082f, -0.1562f, 0.2887f, 0.3772f,
+ 0.2887f, 0.0533f, -0.3943f, -0.1562f, 0.3536f, 0.2485f, -0.2887f, -0.3239f, 0.2041f, 0.3772f, -0.1057f, -0.4048f,
+ 0.2887f, -0.0533f, -0.3943f, 0.1562f, 0.3536f, -0.2485f, -0.2887f, 0.3239f, 0.2041f, -0.3772f, -0.1057f, 0.4048f,
+ 0.2887f, -0.1562f, -0.2887f, 0.3772f, 0.0000f, -0.3772f, 0.2887f, 0.1562f, -0.4082f, 0.1562f, 0.2887f, -0.3772f,
+ 0.2887f, -0.2485f, -0.1057f, 0.3772f, -0.3536f, 0.0533f, 0.2887f, -0.4048f, 0.2041f, 0.1562f, -0.3943f, 0.3239f,
+ 0.2887f, -0.3239f, 0.1057f, 0.1562f, -0.3536f, 0.4048f, -0.2887f, 0.0533f, 0.2041f, -0.3772f, 0.3943f, -0.2485f,
+ 0.2887f, -0.3772f, 0.2887f, -0.1562f, -0.0000f, 0.1562f, -0.2887f, 0.3772f, -0.4082f, 0.3772f, -0.2887f, 0.1562f,
+ 0.2887f, -0.4048f, 0.3943f, -0.3772f, 0.3536f, -0.3239f, 0.2887f, -0.2485f, 0.2041f, -0.1562f, 0.1057f, -0.0533f
+};
+
+/*----------------------------------------------------------------------------------*
+ * ISM ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const float ism_azimuth_borders[4] =
+{
+ ISM_AZIMUTH_MIN, ISM_AZIMUTH_LOW_BORDER, ISM_AZIMUTH_HIGH_BORDER, ISM_AZIMUTH_MAX
+};
+
+const float ism_elevation_borders[4] =
+{
+ ISM_ELEVATION_MIN, ISM_ELEVATION_LOW_BORDER, ISM_ELEVATION_HIGH_BORDER, ISM_ELEVATION_MAX
+};
+
+
+/*----------------------------------------------------------------------------------*
+ * Param ISM ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1] =
+{
+ 0, 1, 2, 3, 4, 6, 8, 11, 15, 21, 31, 60
+};
+
+/*----------------------------------------------------------------------------------*
+ * LFE coding ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const float ivas_lfe_window_coeff_48k[IVAS_LFE_FADE_LEN_48K] =
+{
+ 0.000111037183489911f, 0.000184173600662723f, 0.000260431056232165f, 0.000343096680773904f,
+ 0.000433557036912299f, 0.000532702330090964f, 0.000641245198570983f, 0.000759825620233343f,
+ 0.000889053268887781f, 0.00102952705612861f, 0.00118184503626756f, 0.00134660978209878f,
+ 0.00152443144932643f, 0.00171592958031516f, 0.00192173418063960f, 0.00214248635511166f,
+ 0.00237883866481051f, 0.00263145529985620f, 0.00290101212545378f, 0.00318819663720802f,
+ 0.00349370784884686f, 0.00381825612758351f, 0.00416256298736225f, 0.00452736084701996f,
+ 0.00491339275828344f, 0.00532141210711066f, 0.00575218229092557f, 0.00620647637363723f,
+ 0.00668507671987614f, 0.00718877460956053f, 0.00771836983367896f, 0.00827467027201698f,
+ 0.00885849145344304f, 0.00947065609929077f, 0.0101119936503206f, 0.0107833397777077f,
+ 0.0114855358784815f, 0.0122194285558262f, 0.0129858690846493f, 0.0137857128628235f,
+ 0.0146198188485090f, 0.0154890489839742f, 0.0163942676063398f, 0.0173363408456805f,
+ 0.0183161360109349f, 0.0193345209640845f, 0.0203923634830761f, 0.0214905306139788f,
+ 0.0226298880128789f, 0.0238112992780310f, 0.0250356252727999f, 0.0263037234399395f,
+ 0.0276164471077718f, 0.0289746447888419f, 0.0303791594716384f, 0.0318308279059821f,
+ 0.0333304798826995f, 0.0348789375082095f, 0.0364770144746630f, 0.0381255153262869f,
+ 0.0398252347225964f, 0.0415769566991470f, 0.0433814539265092f, 0.0452394869681573f,
+ 0.0471518035379721f, 0.0491191377580651f, 0.0511422094176377f, 0.0532217232335982f,
+ 0.0553583681136604f, 0.0575528164226564f, 0.0598057232527990f, 0.0621177256986303f,
+ 0.0644894421373997f, 0.0669214715156123f, 0.0694143926424920f, 0.0719687634911028f,
+ 0.0745851205078720f, 0.0772639779312550f, 0.0800058271202837f, 0.0828111358937321f,
+ 0.0856803478806326f, 0.0886138818828696f, 0.0916121312505734f, 0.0946754632710273f,
+ 0.0978042185717987f, 0.100998710538792f, 0.104259224749915f, 0.107586018425039f,
+ 0.110979319892929f, 0.114439328075791f, 0.117966211992097f, 0.121560110278315f,
+ 0.125221130730162f, 0.128949349863999f, 0.132744812498936f, 0.136607531360247f,
+ 0.140537486704635f, 0.144534625967897f, 0.148598863435505f, 0.152730079936616f,
+ 0.156928122561981f, 0.161192804406232f, 0.165523904334983f, 0.169921166777162f,
+ 0.174384301542983f, 0.178912983667934f, 0.183506853283123f, 0.188165515512334f,
+ 0.192888540396077f, 0.197675462842929f, 0.202525782608415f, 0.207438964301664f,
+ 0.212414437420042f, 0.217451596411945f, 0.222549800767893f, 0.227708375140074f,
+ 0.232926609490399f, 0.238203759267182f, 0.243539045610445f, 0.248931655585895f,
+ 0.254380742447540f, 0.259885425928913f, 0.265444792562823f, 0.271057896029545f,
+ 0.276723757533309f, 0.282441366206947f, 0.288209679544493f, 0.294027623861544f,
+ 0.299894094783121f, 0.305807957758767f, 0.311768048604592f, 0.317773174071915f,
+ 0.323822112442170f, 0.329913614147682f, 0.336046402417904f, 0.342219173950673f,
+ 0.348430599608033f, 0.354679325136114f, 0.360963971908571f, 0.367283137693016f,
+ 0.373635397439901f, 0.380019304093226f, 0.386433389422488f, 0.392876164875198f,
+ 0.399346122449318f, 0.405841735584931f, 0.412361460074412f, 0.418903734990401f,
+ 0.425466983630787f, 0.432049614479962f, 0.438650022185529f, 0.445266588549660f,
+ 0.451897683534280f, 0.458541666279211f, 0.465196886132432f, 0.471861683691556f,
+ 0.478534391855649f, 0.485213336886453f, 0.491896839478123f, 0.498583215834516f,
+ 0.505270778753096f, 0.511957838714501f, 0.518642704976797f, 0.525323686673448f,
+ 0.531999093914013f, 0.538667238886587f, 0.545326436960981f, 0.551975007791651f,
+ 0.558611276419351f, 0.565233574370526f, 0.571840240753416f, 0.578429623349869f,
+ 0.585000079701846f, 0.591549978191620f, 0.598077699114643f, 0.604581635744092f,
+ 0.611060195386091f, 0.617511800424606f, 0.623934889355033f, 0.630327917805494f,
+ 0.636689359544871f, 0.643017707476609f, 0.649311474617338f, 0.655569195059378f,
+ 0.661789424916185f, 0.667970743249834f, 0.674111752979635f, 0.680211081770987f,
+ 0.686267382903617f, 0.692279336118339f, 0.698245648441503f, 0.704165054986320f,
+ 0.710036319730275f, 0.715858236267842f, 0.721629628537765f, 0.727349351524163f,
+ 0.733016291930776f, 0.738629368827644f, 0.744187534269598f, 0.749689773885909f,
+ 0.755135107440516f, 0.760522589362248f, 0.765851309244508f, 0.771120392313900f,
+ 0.776328999867319f, 0.781476329677057f, 0.786561616363500f, 0.791584131735037f,
+ 0.796543185094819f, 0.801438123514058f, 0.806268332071584f, 0.811033234059390f,
+ 0.815732291153985f, 0.820365003553343f, 0.824930910079335f, 0.829429588245527f,
+ 0.833860654290276f, 0.838223763175109f, 0.842518608548382f, 0.846744922674278f,
+ 0.850902476327233f, 0.854991078651907f, 0.859010576988885f, 0.862960856666304f,
+ 0.866841840757651f, 0.870653489806038f, 0.874395801515260f, 0.878068810408014f,
+ 0.881672587451697f, 0.885207239652212f, 0.888672909616291f, 0.892069775082842f,
+ 0.895398048423911f, 0.898657976115850f, 0.901849838181344f, 0.904973947602979f,
+ 0.908030649709079f, 0.911020321532565f, 0.913943371143645f, 0.916800236957154f,
+ 0.919591387015427f, 0.922317318247601f, 0.924978555706293f, 0.927575651782607f,
+ 0.930109185400495f, 0.932579761191496f, 0.934988008650908f, 0.937334581276497f,
+ 0.939620155690861f, 0.941845430748583f, 0.944011126629350f, 0.946117983918227f,
+ 0.948166762674299f, 0.950158241488903f, 0.952093216534711f, 0.953972500606916f,
+ 0.955796922157805f, 0.957567324326003f, 0.959284563961681f, 0.960949510649049f,
+ 0.962563045727414f, 0.964126061312150f, 0.965639459316855f, 0.967104150478033f,
+ 0.968521053383593f, 0.969891093506458f, 0.971215202244581f, 0.972494315968637f,
+ 0.973729375078655f, 0.974921323070827f, 0.976071105615721f, 0.977179669649101f,
+ 0.978247962476515f, 0.979276930892814f, 0.980267520317711f, 0.981220673948460f,
+ 0.982137331930712f, 0.983018430548546f, 0.983864901434662f, 0.984677670801652f,
+ 0.985457658695232f, 0.986205778270287f, 0.986922935090503f, 0.987610026452330f,
+ 0.988267940733967f, 0.988897556770000f, 0.989499743252276f, 0.990075358157522f,
+ 0.990625248202194f, 0.991150248324956f, 0.991651181197124f, 0.992128856761388f,
+ 0.992584071799021f, 0.993017609525750f, 0.993430239216404f, 0.993822715858368f,
+ 0.994195779833855f, 0.994550156630899f, 0.994886556582961f, 0.995205674636936f,
+ 0.995508190149341f, 0.995794766710354f, 0.996066051995373f, 0.996322677643671f,
+ 0.996565259163689f, 0.996794395864463f, 0.997010670812624f, 0.997214650814370f,
+ 0.997406886421766f, 0.997587911962687f, 0.997758245593683f, 0.997918389375006f,
+ 0.998068829367008f, 0.998210035747091f, 0.998342462946368f, 0.998466549805146f,
+ 0.998582719746365f, 0.998691380966053f, 0.998792926639904f, 0.998887735145004f,
+ 0.998976170295797f, 0.999058581593303f, 0.999135304486653f, 0.999206660645980f,
+ 0.999272958245696f, 0.999334492257230f, 0.999391544750254f, 0.999444385201492f,
+ 0.999493270810174f, 0.999538446819229f, 0.999580146841343f, 0.999618593188994f,
+ 0.999653997207632f, 0.999686559611161f, 0.999716470818948f, 0.999743911293550f,
+ 0.999769051878447f, 0.999792054135046f, 0.999813070678259f, 0.999832245510030f,
+ 0.999849714350153f, 0.999865604963813f, 0.999880037485284f, 0.999893124737258f,
+ 0.999904972545323f, 0.999915680047131f, 0.999925339995826f, 0.999934039057369f,
+ 0.999941858101379f, 0.999948872485197f, 0.999955152330868f, 0.999960762794806f,
+ 0.999965764329904f, 0.999970212939921f, 0.999974160425965f, 0.999977654624967f,
+ 0.999980739640031f, 0.999983456062595f, 0.999985841186357f, 0.999987929212949f,
+ 0.999989751449364f, 0.999991336497160f, 0.999992710433503f, 0.999993896984110f,
+ 0.999994917688186f, 0.999995792055471f, 0.999996537715509f, 0.999997170559301f,
+ 0.999997704873475f, 0.999998153467165f, 0.999998527791754f, 0.999998838053703f,
+ 0.999999093320636f, 0.999999301620911f, 0.999999470036880f, 0.999999604792064f,
+ 0.999999711332472f, 0.999999794402277f, 0.999999858114104f, 0.999999906014144f,
+ 0.999999941142332f, 0.999999966087832f, 0.999999983040042f, 0.999999993835372f
+};
+
+const float ivas_lfe_window_coeff_32k[IVAS_LFE_FADE_LEN_32K] =
+{
+ 0.000135992220705702f, 0.000243900754874608f, 0.000366502488193403f, 0.000507754555407233f,
+ 0.000670037413867230f, 0.000855400185342017f, 0.00106582120537505f, 0.00130328810233523f,
+ 0.00156982797844358f, 0.00186752014891622f, 0.00219850171292337f, 0.00256496978060437f,
+ 0.00296918195815542f, 0.00341345582581521f, 0.00390016777110998f, 0.00443175136707306f,
+ 0.00501069540002978f, 0.00563954160739932f, 0.00632088216212532f, 0.00705735692705637f,
+ 0.00785165049501826f, 0.00870648902594829f, 0.00962463688994814f, 0.0106088931237052f,
+ 0.0116620877070005f, 0.0127870776657112f, 0.0139867430076699f, 0.0152639824978695f,
+ 0.0166217092797368f, 0.0180628463495039f, 0.0195903218910554f, 0.0212070644790028f,
+ 0.0229159981581294f, 0.0247200374077382f, 0.0266220819998311f, 0.0286250117604275f,
+ 0.0307316812437090f, 0.0329449143290351f, 0.0352674987512187f, 0.0377021805747777f,
+ 0.0402516586231834f, 0.0429185788744125f, 0.0457055288343670f, 0.0486150318999676f,
+ 0.0516495417239329f, 0.0548114365934440f, 0.0581030138350493f, 0.0615264842582949f,
+ 0.0650839666506623f, 0.0687774823364692f, 0.0726089498124248f, 0.0765801794725421f,
+ 0.0806928684350862f, 0.0849485954841849f, 0.0893488161386407f, 0.0938948578603667f,
+ 0.0985879154147218f, 0.103429046394834f, 0.108419166921795f, 0.113559047532359f,
+ 0.118849309265507f, 0.124290419958929f, 0.129882690766145f, 0.135626272904605f,
+ 0.141521154644746f, 0.147567158549505f, 0.153763938973404f, 0.160110979829776f,
+ 0.166607592634260f, 0.173252914832108f, 0.180045908416344f, 0.186985358843200f,
+ 0.194069874250690f, 0.201297884985540f, 0.208667643443083f, 0.216177224224055f,
+ 0.223824524611575f, 0.231607265370904f, 0.239522991873889f, 0.247569075549288f,
+ 0.255742715659461f, 0.264040941403189f, 0.272460614343670f, 0.280998431159973f,
+ 0.289650926719540f, 0.298414477468569f, 0.307285305136374f, 0.316259480749104f,
+ 0.325332928947464f, 0.334501432602363f, 0.343760637721723f, 0.353106058640944f,
+ 0.362533083488876f, 0.372036979920440f, 0.381612901106401f, 0.391255891970138f,
+ 0.400960895660650f, 0.410722760250415f, 0.420536245646151f, 0.430396030699960f,
+ 0.440296720507817f, 0.450232853881834f, 0.460198910982274f, 0.470189321094825f,
+ 0.480198470538230f, 0.490220710686965f, 0.500250366093333f, 0.510281742692964f,
+ 0.520309136077485f, 0.530326839817815f, 0.540329153821353f, 0.550310392706136f,
+ 0.560264894174896f, 0.570187027371852f, 0.580071201204973f, 0.589911872616473f,
+ 0.599703554784248f, 0.609440825237056f, 0.619118333866323f, 0.628730810817558f,
+ 0.638273074244583f, 0.647740037909930f, 0.657126718615052f, 0.666428243444252f,
+ 0.675639856806586f, 0.684756927260328f, 0.693774954105018f, 0.702689573726534f,
+ 0.711496565681117f, 0.720191858504788f, 0.728771535235148f, 0.737231838633124f,
+ 0.745569176092876f, 0.753780124228688f, 0.761861433128389f, 0.769810030263551f,
+ 0.777623024047447f, 0.785297707032555f, 0.792831558740175f, 0.800222248115570f,
+ 0.807467635602894f, 0.814565774835047f, 0.821514913934526f, 0.828313496422214f,
+ 0.834960161732055f, 0.841453745330485f, 0.847793278440476f, 0.853977987371046f,
+ 0.860007292454100f, 0.865880806591466f, 0.871598333416011f, 0.877159865071782f,
+ 0.882565579619094f, 0.887815838071573f, 0.892911181073134f, 0.897852325223955f,
+ 0.902640159065461f, 0.907275738735386f, 0.911760283304927f, 0.916095169810981f,
+ 0.920281927997422f, 0.924322234780251f, 0.928217908452363f, 0.931970902644524f,
+ 0.935583300059946f, 0.939057306000627f, 0.942395241704333f, 0.945599537511766f,
+ 0.948672725884068f, 0.951617434291347f, 0.954436377993401f, 0.957132352734204f,
+ 0.959708227372067f, 0.962166936467612f, 0.964511472851888f, 0.966744880197007f,
+ 0.968870245611698f, 0.970890692284040f, 0.972809372193449f, 0.974629458913696f,
+ 0.976354140528315f, 0.977986612679290f, 0.979530071769289f, 0.980987708337022f,
+ 0.982362700624510f, 0.983658208354169f, 0.984877366732620f, 0.986023280697072f,
+ 0.987099019418999f, 0.988107611078563f, 0.989052037921982f, 0.989935231612664f,
+ 0.990760068885503f, 0.991529367512303f, 0.992245882584772f, 0.992912303120025f,
+ 0.993531248991970f, 0.994105268190439f, 0.994636834408346f, 0.995128344955654f,
+ 0.995582118997414f, 0.996000396111680f, 0.996385335161686f, 0.996739013475302f,
+ 0.997063426323498f, 0.997360486688307f, 0.997632025309661f, 0.997879790999405f,
+ 0.998105451209848f, 0.998310592843372f, 0.998496723288846f, 0.998665271669997f,
+ 0.998817590290322f, 0.998954956258775f, 0.999078573280101f, 0.999189573593561f,
+ 0.999289020043705f, 0.999377908266854f, 0.999457168977167f, 0.999527670336312f,
+ 0.999590220391194f, 0.999645569564531f, 0.999694413183629f, 0.999737394033262f,
+ 0.999775104919193f, 0.999808091229614f, 0.999836853482484f, 0.999861849847578f,
+ 0.999883498632868f, 0.999902180725714f, 0.999918241980199f, 0.999931995542854f,
+ 0.999943724109857f, 0.999953682109695f, 0.999962097806132f, 0.999969175317172f,
+ 0.999975096546511f, 0.999980023024807f, 0.999984097658787f, 0.999987446387008f,
+ 0.999990179741692f, 0.999992394316756f, 0.999994174142692f, 0.999995591969534f,
+ 0.999996710459602f, 0.999997583292189f, 0.999998256182726f, 0.999998767819300f,
+ 0.999999150719701f, 0.999999432012418f, 0.999999634145194f, 0.999999775524907f,
+ 0.999999871092647f, 0.999999932837961f, 0.999999970256211f, 0.999999990753058f
+};
+
+const float ivas_lfe_window_coeff_16k[IVAS_LFE_FADE_LEN_16K] =
+{
+ 0.000192322041967661f, 0.000432042541451336f, 0.000754275578824202f, 0.00117365342860051f,
+ 0.00170559736282027f, 0.00236656267363075f, 0.00317404503675108f, 0.00414654286875000f,
+ 0.00530350017263264f, 0.00666523498873026f, 0.00825285493787745f, 0.0100881605116261f,
+ 0.0121935365995684f, 0.0145918327721377f, 0.0173062329286553f, 0.0203601150332032f,
+ 0.0237769017796244f, 0.0275799031448139f, 0.0317921519028702f, 0.0364362332793203f,
+ 0.0415341100227591f, 0.0471069442593880f, 0.0531749175728265f, 0.0597570508160612f,
+ 0.0668710252134883f, 0.0745330063478375f, 0.0827574726486089f, 0.0915570500049407f,
+ 0.100942354116142f, 0.110921842167215f, 0.121501675374497f, 0.132685593888120f,
+ 0.144474805463665f, 0.156867889225514f, 0.169860715739713f, 0.183446384495299f,
+ 0.197615179761091f, 0.212354545640879f, 0.227649080995091f, 0.243480554732640f,
+ 0.259827941804377f, 0.276667480050824f, 0.293972747873422f, 0.311714762512102f,
+ 0.329862098524320f, 0.348381025873702f, 0.367235666851846f, 0.386388170876560f,
+ 0.405798906035553f, 0.425426666078274f, 0.445228891401677f, 0.465161902430052f,
+ 0.485181143655975f, 0.505241436490520f, 0.525297238967270f, 0.545302910257632f,
+ 0.565212977885414f, 0.584982405477527f, 0.604566858855629f, 0.623922968261127f,
+ 0.643008584513597f, 0.661783026930517f, 0.680207320884341f, 0.698244422941288f,
+ 0.715859431614468f, 0.733019781871777f, 0.749695421665815f, 0.765858968898205f,
+ 0.781485847393429f, 0.796554400636541f, 0.811045982224021f, 0.824945022186269f,
+ 0.838239068562518f, 0.850918803842860f, 0.862978036135913f, 0.874413665172658f,
+ 0.885225623515076f, 0.895416793600184f, 0.904992901513335f, 0.913962388646463f,
+ 0.922336262654064f, 0.930127929368794f, 0.937353007575688f, 0.944029128765173f,
+ 0.950175724185808f, 0.955813801693484f, 0.960965715039994f, 0.965654928355726f,
+ 0.969905778654342f, 0.973743239217655f, 0.977192686702912f, 0.980279674750013f,
+ 0.983029716751026f, 0.985468080278805f, 0.987619595456638f, 0.989508479289711f,
+ 0.991158177676277f, 0.992591226478046f, 0.993829132663272f, 0.994892276151289f,
+ 0.995799832594078f, 0.996569716939470f, 0.997218547242656f, 0.997761627838482f,
+ 0.998212950666223f, 0.998585213259802f, 0.998889851686633f, 0.999137086542491f,
+ 0.999335979990921f, 0.999494501774465f, 0.999619602119988f, 0.999717289508270f,
+ 0.999792711373630f, 0.999850235936272f, 0.999893533540622f, 0.999925656069088f,
+ 0.999949113214013f, 0.999965944612802f, 0.999977787074566f, 0.999985936344066f,
+ 0.999991403054165f, 0.999994962706365f, 0.999997199686635f, 0.999998545467760f,
+ 0.999999311268578f, 0.999999715534135f, 0.999999906669617f, 0.999999981506116f
+};
+
+const float ivas_lpf_4_butter_16k_sos[IVAS_BIQUAD_FILT_LEN << 2] =
+{
+ 3.97464794223146e-07f, 7.94929601777927e-07f, 3.97464788468481e-07f, 1.f,
+ -1.90746797905194f, 0.909956295365785f, 1.f, 1.99999996645833f,
+ 1.00000001447843f, 1.f, -1.95913666348268f, 0.961692382252710f
+};
+
+const float ivas_lpf_4_butter_32k_sos[IVAS_BIQUAD_FILT_LEN << 2] =
+{
+ 2.56674586654460e-08f, 5.13349181918215e-08f, 2.56674582938215e-08f, 1,
+ -1.95329015717623f, 0.953926661219383f, 1, 1.99999996645833f,
+ 1.00000001447843f, 1, -1.98000953138860f, 0.980654742275836f
+};
+
+const float ivas_lpf_4_butter_48k_sos[IVAS_BIQUAD_FILT_LEN << 2] =
+{
+ 5.12617881476274e-09f, 1.02523584294987e-08f, 5.12617879059970e-09f,
+ 1.0, -1.96875982668433f, 0.969044914826862f, 1.f , 1.99999984394358f,
+ 1.00000000471366f, 1.f , -1.98677297369091f, 0.987060670205863f
+};
+
+const float ivas_lpf_2_butter_16k[IVAS_BIQUAD_FILT_LEN << 1] =
+{
+ 0.000628720643081143f, 0.00125744128616229f, 0.000628720643081143f, 1.f, -1.92783286977036f, 0.930347752342683f
+};
+
+const float ivas_lpf_2_butter_32k[IVAS_BIQUAD_FILT_LEN << 1] =
+{
+ 0.000159990787823749f, 0.000319981575647499f, 0.000159990787823749f, 1.f, -1.96390539174033f, 0.964545354891623f
+};
+
+const float ivas_lpf_2_butter_48k[IVAS_BIQUAD_FILT_LEN << 1] =
+{
+ 7.15317998432330e-05f, 0.000143063599686466f, 7.15317998432330e-05f, 1.f, -1.97593552482925f, 0.976221652028620f
+};
+
+const ivas_lfe_freq_models ivas_str_lfe_freq_models =
+{
+ { 16384, 14924, 13463, 12003, 10542, 9082, 7622, 6161,
+ 4701, 4336, 3970, 3605, 3240, 2875, 2510, 2145,
+ 1780, 1689, 1597, 1506, 1415, 1323, 1232, 1141,
+ 1050, 1004, 958, 913, 867, 821, 776, 730,
+ 685, 639, 593, 548, 502, 456, 411, 365,
+ 319, 297, 274, 251, 228, 205, 183, 160,
+ 137, 126, 114, 103, 91, 80, 68, 57,
+ 46, 40, 34, 29, 23, 17, 11, 6, 0 },
+
+ { 16384, 13463, 10542, 7622, 4701, 3970, 3240, 2510,
+ 1780, 1597, 1415, 1232, 1050, 958, 867, 776,
+ 685, 593, 502, 411, 319, 274, 228, 183,
+ 137, 114, 91, 68, 46, 34, 23, 11, 0 },
+
+ { 16384, 4701, 1780, 1050, 685, 319, 137, 46,
+ 0, },
+
+ { 16384, 3277, 0 },
+
+ { 16384, 13463, 10542, 7622, 4701, 3970, 3240, 2510,
+ 1780, 1597, 1415, 1232, 1050, 958, 867, 776,
+ 685, 593, 502, 411, 319, 274, 228, 183,
+ 137, 114, 91, 68, 46, 34, 23, 11,
+ 0 },
+
+ { 16384, 10542, 4701, 3240, 1780, 1415, 1050, 867,
+ 685, 502, 319, 228, 137, 91, 46, 23,
+ 0 },
+
+ { 16384, 4468, 1489, 745, 0 }, 0,
+};
+
+const int16_t ivas_lfe_num_ele_in_coder_models[2][4] =
+{
+ { 63, 31, 7, 1 },{ 31, 15, 3, 0 }
+};
+
+const int16_t ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 8, 6 };
+
+const int16_t ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 1, 0 };
+
+const float ivas_lfe_lpf_delay[2] = { 0.00175f, 0.0035f };
+
+const double d_hamm_lfe_plc[LFE_PLC_LENANA / 2] =
+{
+ 0.08000000000000002, 0.08015895227847719, 0.08063569926248770, 0.08142991147368656, 0.08254104003450596, 0.08396831704748331, 0.08571075612595230, 0.08776715307573196,
+ 0.09013608672734141, 0.09281591991816535, 0.09580480062389246, 0.09910066323844335, 0.10270123000150438, 0.10660401257268071, 0.11080631375118072, 0.11530522933984272,
+ 0.12009765015221685, 0.12518026416131367, 0.13054955878853602, 0.13620182333121073, 0.14213315152704381, 0.14833944425372619, 0.15481641236182375, 0.16155957963899570,
+ 0.16856428590349043, 0.17582569022478273, 0.18333877426912554, 0.19109834576770490, 0.19909904210500018, 0.20733533402487142, 0.21580152945181053, 0.22449177742471671,
+ 0.23340007214047787, 0.24252025710456171, 0.25184602938575001, 0.26137094397207467, 0.27108841822494550, 0.28099173642839037, 0.29107405443026624, 0.30132840437223085,
+ 0.31174769950520753, 0.32232473908701620, 0.33305221335878232, 0.34392270859668939, 0.35492871223557998, 0.36606261806086549, 0.37731673146515798, 0.38868327476598852,
+ 0.40015439258093899, 0.41172215725647360, 0.42337857434671339, 0.43511558813837425, 0.44692508721804453, 0.45879891007795709, 0.47072885075638249, 0.48270666450874267,
+ 0.49472407350552849, 0.50677277255308162, 0.51884443483328757, 0.53093071765821398, 0.54302326823571601, 0.55511372944202464, 0.56719374559732838, 0.57925496824035816,
+ 0.59128906189798180, 0.60328770984582458, 0.61524261985593010, 0.62714552992749328, 0.63898821399670414, 0.65076248762175315, 0.66246021363907504, 0.67407330778691554,
+ 0.68559374429233988, 0.69701356141781945, 0.70832486696356345, 0.71951984372179334, 0.73059075487919101, 0.74152994936378558, 0.75232986713258543, 0.76298304439630038,
+ 0.77348211877754336, 0.78381983439894576, 0.79398904689767136, 0.80398272836286389, 0.81379397219261318, 0.82341599786708708, 0.83284215563452701, 0.84206593110687011,
+ 0.85108094976182280, 0.85988098134827329, 0.86845994419199846, 0.87681190939868969, 0.88493110495139349, 0.89281191969953333, 0.90044890723675941, 0.90783678966494241,
+ 0.91497046124171255, 0.92184499190902180, 0.92845563070029180, 0.93479780902379184, 0.94086714381997805, 0.94665944059061280, 0.95217069629756890, 0.95739710212931617,
+ 0.96233504613317988, 0.96698111571154954, 0.97133209998031445, 0.97538499198789563, 0.97913699079334116, 0.98258550340204664, 0.98572814655776630, 0.98856274838967395,
+ 0.99108734991333569, 0.99330020638455863, 0.99519978850517732, 0.99678478347994692, 0.99805409592381300, 0.99900684861892730, 0.99964238312089115, 0.99996026021380402
+};
+
+
+/*------------------------------------------------------------------------------------------*
+ * MDFT/iMDFT ROM tables
+ *------------------------------------------------------------------------------------------*/
+
+const float ivas_mdft_coeff_cos_twid_960[IVAS_960_PT_LEN + 1] =
+{
+ 1.00000000000000f, 0.999998661349528f, 0.999994645401697f, 0.999987952167257f,
+ 0.999978581664129f, 0.999966533917401f, 0.999951808959328f, 0.999934406829333f,
+ 0.999914327574007f, 0.999891571247108f, 0.999866137909562f, 0.999838027629461f,
+ 0.999807240482065f, 0.999773776549800f, 0.999737635922260f, 0.999698818696204f,
+ 0.999657324975557f, 0.999613154871411f, 0.999566308502021f, 0.999516785992811f,
+ 0.999464587476366f, 0.999409713092437f, 0.999352162987941f, 0.999291937316955f,
+ 0.999229036240723f, 0.999163459927649f, 0.999095208553300f, 0.999024282300407f,
+ 0.998950681358860f, 0.998874405925711f, 0.998795456205172f, 0.998713832408616f,
+ 0.998629534754574f, 0.998542563468736f, 0.998452918783950f, 0.998360600940223f,
+ 0.998265610184716f, 0.998167946771749f, 0.998067610962796f, 0.997964603026487f,
+ 0.997858923238604f, 0.997750571882084f, 0.997639549247016f, 0.997525855630641f,
+ 0.997409491337352f, 0.997290456678690f, 0.997168751973348f, 0.997044377547164f,
+ 0.996917333733128f, 0.996787620871373f, 0.996655239309180f, 0.996520189400975f,
+ 0.996382471508325f, 0.996242085999945f, 0.996099033251687f, 0.995953313646548f,
+ 0.995804927574662f, 0.995653875433303f, 0.995500157626885f, 0.995343774566954f,
+ 0.995184726672197f, 0.995023014368432f, 0.994858638088611f, 0.994691598272820f,
+ 0.994521895368273f, 0.994349529829318f, 0.994174502117428f, 0.993996812701206f,
+ 0.993816462056378f, 0.993633450665799f, 0.993447779019444f, 0.993259447614414f,
+ 0.993068456954926f, 0.992874807552322f, 0.992678499925058f, 0.992479534598710f,
+ 0.992277912105967f, 0.992073632986633f, 0.991866697787626f, 0.991657107062973f,
+ 0.991444861373810f, 0.991229961288385f, 0.991012407382049f, 0.990792200237260f,
+ 0.990569340443577f, 0.990343828597665f, 0.990115665303286f, 0.989884851171301f,
+ 0.989651386819670f, 0.989415272873448f, 0.989176509964781f, 0.988935098732911f,
+ 0.988691039824167f, 0.988444333891970f, 0.988194981596825f, 0.987942983606322f,
+ 0.987688340595138f, 0.987431053245027f, 0.987171122244825f, 0.986908548290446f,
+ 0.986643332084879f, 0.986375474338188f, 0.986104975767509f, 0.985831837097047f,
+ 0.985556059058078f, 0.985277642388941f, 0.984996587835043f, 0.984712896148850f,
+ 0.984426568089892f, 0.984137604424753f, 0.983846005927077f, 0.983551773377562f,
+ 0.983254907563955f, 0.982955409281056f, 0.982653279330712f, 0.982348518521816f,
+ 0.982041127670304f, 0.981731107599154f, 0.981418459138384f, 0.981103183125046f,
+ 0.980785280403230f, 0.980464751824058f, 0.980141598245680f, 0.979815820533276f,
+ 0.979487419559051f, 0.979156396202234f, 0.978822751349072f, 0.978486485892835f,
+ 0.978147600733806f, 0.977806096779282f, 0.977461974943572f, 0.977115236147994f,
+ 0.976765881320872f, 0.976413911397535f, 0.976059327320311f, 0.975702130038529f,
+ 0.975342320508513f, 0.974979899693582f, 0.974614868564045f, 0.974247228097201f,
+ 0.973876979277334f, 0.973504123095711f, 0.973128660550580f, 0.972750592647168f,
+ 0.972369920397677f, 0.971986644821279f, 0.971600766944121f, 0.971212287799312f,
+ 0.970821208426928f, 0.970427529874007f, 0.970031253194544f, 0.969632379449492f,
+ 0.969230909706754f, 0.968826845041188f, 0.968420186534595f, 0.968010935275723f,
+ 0.967599092360260f, 0.967184658890834f, 0.966767635977008f, 0.966348024735277f,
+ 0.965925826289068f, 0.965501041768733f, 0.965073672311547f, 0.964643719061708f,
+ 0.964211183170329f, 0.963776065795440f, 0.963338368101980f, 0.962898091261798f,
+ 0.962455236453647f, 0.962009804863184f, 0.961561797682962f, 0.961111216112432f,
+ 0.960658061357935f, 0.960202334632705f, 0.959744037156857f, 0.959283170157394f,
+ 0.958819734868193f, 0.958353732530011f, 0.957885164390477f, 0.957414031704088f,
+ 0.956940335732209f, 0.956464077743065f, 0.955985259011744f, 0.955503880820186f,
+ 0.955019944457187f, 0.954533451218389f, 0.954044402406280f, 0.953552799330194f,
+ 0.953058643306297f, 0.952561935657595f, 0.952062677713924f, 0.951560870811948f,
+ 0.951056516295154f, 0.950549615513851f, 0.950040169825165f, 0.949528180593037f,
+ 0.949013649188214f, 0.948496576988253f, 0.947976965377510f, 0.947454815747144f,
+ 0.946930129495106f, 0.946402908026138f, 0.945873152751771f, 0.945340865090320f,
+ 0.944806046466878f, 0.944268698313317f, 0.943728822068278f, 0.943186419177173f,
+ 0.942641491092178f, 0.942094039272230f, 0.941544065183021f, 0.940991570296997f,
+ 0.940436556093355f, 0.939879024058033f, 0.939318975683713f, 0.938756412469813f,
+ 0.938191335922484f, 0.937623747554606f, 0.937053648885784f, 0.936481041442343f,
+ 0.935905926757326f, 0.935328306370488f, 0.934748181828292f, 0.934165554683908f,
+ 0.933580426497202f, 0.932992798834739f, 0.932402673269775f, 0.931810051382254f,
+ 0.931214934758804f, 0.930617324992729f, 0.930017223684012f, 0.929414632439304f,
+ 0.928809552871924f, 0.928201986601852f, 0.927591935255724f, 0.926979400466833f,
+ 0.926364383875118f, 0.925746887127164f, 0.925126911876195f, 0.924504459782072f,
+ 0.923879532511287f, 0.923252131736957f, 0.922622259138823f, 0.921989916403245f,
+ 0.921355105223193f, 0.920717827298248f, 0.920078084334595f, 0.919435878045019f,
+ 0.918791210148898f, 0.918144082372204f, 0.917494496447491f, 0.916842454113897f,
+ 0.916187957117136f, 0.915531007209492f, 0.914871606149819f, 0.914209755703531f,
+ 0.913545457642601f, 0.912878713745555f, 0.912209525797468f, 0.911537895589956f,
+ 0.910863824921176f, 0.910187315595818f, 0.909508369425101f, 0.908826988226768f,
+ 0.908143173825081f, 0.907456928050819f, 0.906768252741266f, 0.906077149740215f,
+ 0.905383620897955f, 0.904687668071273f, 0.903989293123443f, 0.903288497924226f,
+ 0.902585284349861f, 0.901879654283062f, 0.901171609613013f, 0.900461152235364f,
+ 0.899748284052222f, 0.899033006972149f, 0.898315322910159f, 0.897595233787707f,
+ 0.896872741532688f, 0.896147848079432f, 0.895420555368697f, 0.894690865347664f,
+ 0.893958779969932f, 0.893224301195515f, 0.892487430990834f, 0.891748171328711f,
+ 0.891006524188368f, 0.890262491555416f, 0.889516075421856f, 0.888767277786068f,
+ 0.888016100652807f, 0.887262546033203f, 0.886506615944746f, 0.885748312411291f,
+ 0.884987637463042f, 0.884224593136556f, 0.883459181474733f, 0.882691404526809f,
+ 0.881921264348355f, 0.881148763001268f, 0.880373902553765f, 0.879596685080383f,
+ 0.878817112661965f, 0.878035187385663f, 0.877250911344924f, 0.876464286639493f,
+ 0.875675315375400f, 0.874883999664958f, 0.874090341626759f, 0.873294343385663f,
+ 0.872496007072797f, 0.871695334825548f, 0.870892328787557f, 0.870086991108712f,
+ 0.869279323945144f, 0.868469329459222f, 0.867657009819544f, 0.866842367200935f,
+ 0.866025403784439f, 0.865206121757311f, 0.864384523313017f, 0.863560610651224f,
+ 0.862734385977792f, 0.861905851504774f, 0.861075009450407f, 0.860241862039105f,
+ 0.859406411501453f, 0.858568660074204f, 0.857728610000272f, 0.856886263528723f,
+ 0.856041622914771f, 0.855194690419775f, 0.854345468311227f, 0.853493958862751f,
+ 0.852640164354092f, 0.851784087071117f, 0.850925729305802f, 0.850065093356229f,
+ 0.849202181526579f, 0.848336996127127f, 0.847469539474235f, 0.846599813890344f,
+ 0.845727821703973f, 0.844853565249707f, 0.843977046868193f, 0.843098268906136f,
+ 0.842217233716287f, 0.841333943657443f, 0.840448401094438f, 0.839560608398136f,
+ 0.838670567945424f, 0.837778282119209f, 0.836883753308409f, 0.835986983907947f,
+ 0.835087976318743f, 0.834186732947712f, 0.833283256207754f, 0.832377548517748f,
+ 0.831469612302545f, 0.830559449992965f, 0.829647064025785f, 0.828732456843738f,
+ 0.827815630895502f, 0.826896588635696f, 0.825975332524873f, 0.825051865029513f,
+ 0.824126188622016f, 0.823198305780696f, 0.822268218989775f, 0.821335930739376f,
+ 0.820401443525514f, 0.819464759850093f, 0.818525882220897f, 0.817584813151584f,
+ 0.816641555161679f, 0.815696110776568f, 0.814748482527489f, 0.813798672951530f,
+ 0.812846684591615f, 0.811892519996505f, 0.810936181720784f, 0.809977672324859f,
+ 0.809016994374948f, 0.808054150443073f, 0.807089143107059f, 0.806121974950521f,
+ 0.805152648562858f, 0.804181166539250f, 0.803207531480645f, 0.802231745993758f,
+ 0.801253812691061f, 0.800273734190774f, 0.799291513116864f, 0.798307152099032f,
+ 0.797320653772707f, 0.796332020779044f, 0.795341255764910f, 0.794348361382882f,
+ 0.793353340291235f, 0.792356195153942f, 0.791356928640660f, 0.790355543426726f,
+ 0.789352042193150f, 0.788346427626606f, 0.787338702419428f, 0.786328869269598f,
+ 0.785316930880745f, 0.784302889962131f, 0.783286749228650f, 0.782268511400816f,
+ 0.781248179204759f, 0.780225755372213f, 0.779201242640517f, 0.778174643752598f,
+ 0.777145961456971f, 0.776115198507728f, 0.775082357664531f, 0.774047441692607f,
+ 0.773010453362737f, 0.771971395451250f, 0.770930270740018f, 0.769887082016445f,
+ 0.768841832073460f, 0.767794523709512f, 0.766745159728562f, 0.765693742940071f,
+ 0.764640276159000f, 0.763584762205796f, 0.762527203906388f, 0.761467604092177f,
+ 0.760405965600031f, 0.759342291272276f, 0.758276583956687f, 0.757208846506485f,
+ 0.756139081780323f, 0.755067292642284f, 0.753993481961869f, 0.752917652613995f,
+ 0.751839807478977f, 0.750759949442534f, 0.749678081395770f, 0.748594206235171f,
+ 0.747508326862597f, 0.746420446185274f, 0.745330567115786f, 0.744238692572067f,
+ 0.743144825477394f, 0.742048968760379f, 0.740951125354959f, 0.739851298200392f,
+ 0.738749490241246f, 0.737645704427393f, 0.736539943713999f, 0.735432211061519f,
+ 0.734322509435686f, 0.733210841807505f, 0.732097211153246f, 0.730981620454432f,
+ 0.729864072697836f, 0.728744570875469f, 0.727623117984575f, 0.726499717027620f,
+ 0.725374371012288f, 0.724247082951467f, 0.723117855863248f, 0.721986692770910f,
+ 0.720853596702919f, 0.719718570692913f, 0.718581617779698f, 0.717442741007240f,
+ 0.716301943424654f, 0.715159228086199f, 0.714014598051268f, 0.712868056384380f,
+ 0.711719606155171f, 0.710569250438390f, 0.709416992313883f, 0.708262834866593f,
+ 0.707106781186548f, 0.705948834368849f, 0.704788997513670f, 0.703627273726243f,
+ 0.702463666116852f, 0.701298177800824f, 0.700130811898524f, 0.698961571535339f,
+ 0.697790459841680f, 0.696617479952964f, 0.695442635009612f, 0.694265928157036f,
+ 0.693087362545636f, 0.691906941330786f, 0.690724667672829f, 0.689540544737067f,
+ 0.688354575693754f, 0.687166763718086f, 0.685977111990193f, 0.684785623695130f,
+ 0.683592302022871f, 0.682397150168297f, 0.681200171331188f, 0.680001368716218f,
+ 0.678800745532942f, 0.677598304995789f, 0.676394050324054f, 0.675187984741891f,
+ 0.673980111478298f, 0.672770433767117f, 0.671558954847018f, 0.670345677961497f,
+ 0.669130606358858f, 0.667913743292216f, 0.666695092019479f, 0.665474655803342f,
+ 0.664252437911282f, 0.663028441615542f, 0.661802670193130f, 0.660575126925805f,
+ 0.659345815100069f, 0.658114738007160f, 0.656881898943041f, 0.655647301208395f,
+ 0.654410948108610f, 0.653172842953777f, 0.651932989058674f, 0.650691389742765f,
+ 0.649448048330184f, 0.648202968149730f, 0.646956152534857f, 0.645707604823667f,
+ 0.644457328358897f, 0.643205326487914f, 0.641951602562703f, 0.640696159939861f,
+ 0.639439001980585f, 0.638180132050665f, 0.636919553520476f, 0.635657269764965f,
+ 0.634393284163646f, 0.633127600100588f, 0.631860220964409f, 0.630591150148264f,
+ 0.629320391049838f, 0.628047947071334f, 0.626773821619470f, 0.625498018105461f,
+ 0.624220539945018f, 0.622941390558334f, 0.621660573370077f, 0.620378091809381f,
+ 0.619093949309834f, 0.617808149309472f, 0.616520695250769f, 0.615231590580627f,
+ 0.613940838750366f, 0.612648443215719f, 0.611354407436817f, 0.610058734878182f,
+ 0.608761429008721f, 0.607462493301711f, 0.606161931234795f, 0.604859746289968f,
+ 0.603555941953571f, 0.602250521716282f, 0.600943489073102f, 0.599634847523352f,
+ 0.598324600570659f, 0.597012751722948f, 0.595699304492433f, 0.594384262395609f,
+ 0.593067628953237f, 0.591749407690343f, 0.590429602136201f, 0.589108215824328f,
+ 0.587785252292473f, 0.586460715082607f, 0.585134607740916f, 0.583806933817786f,
+ 0.582477696867802f, 0.581146900449730f, 0.579814548126514f, 0.578480643465260f,
+ 0.577145190037234f, 0.575808191417845f, 0.574469651186643f, 0.573129572927301f,
+ 0.571787960227612f, 0.570444816679478f, 0.569100145878898f, 0.567753951425961f,
+ 0.566406236924833f, 0.565057005983753f, 0.563706262215017f, 0.562354009234973f,
+ 0.561000250664010f, 0.559644990126546f, 0.558288231251022f, 0.556929977669890f,
+ 0.555570233019602f, 0.554209000940606f, 0.552846285077328f, 0.551482089078169f,
+ 0.550116416595494f, 0.548749271285616f, 0.547380656808797f, 0.546010576829228f,
+ 0.544639035015027f, 0.543266035038224f, 0.541891580574752f, 0.540515675304440f,
+ 0.539138322911000f, 0.537759527082020f, 0.536379291508950f, 0.534997619887097f,
+ 0.533614515915612f, 0.532229983297479f, 0.530844025739510f, 0.529456646952329f,
+ 0.528067850650368f, 0.526677640551852f, 0.525286020378792f, 0.523892993856974f,
+ 0.522498564715949f, 0.521102736689023f, 0.519705513513249f, 0.518306898929413f,
+ 0.516906896682028f, 0.515505510519320f, 0.514102744193222f, 0.512698601459362f,
+ 0.511293086077052f, 0.509886201809281f, 0.508477952422700f, 0.507068341687617f,
+ 0.505657373377985f, 0.504245051271389f, 0.502831379149042f, 0.501416360795769f,
+ 0.500000000000000f, 0.498582300553759f, 0.497163266252654f, 0.495742900895868f,
+ 0.494321208286145f, 0.492898192229784f, 0.491473856536628f, 0.490048205020053f,
+ 0.488621241496955f, 0.487192969787746f, 0.485763393716340f, 0.484332517110141f,
+ 0.482900343800037f, 0.481466877620387f, 0.480032122409011f, 0.478596082007181f,
+ 0.477158760259609f, 0.475720161014437f, 0.474280288123229f, 0.472839145440959f,
+ 0.471396736825998f, 0.469953066140108f, 0.468508137248432f, 0.467061954019477f,
+ 0.465614520325111f, 0.464165840040552f, 0.462715917044350f, 0.461264755218387f,
+ 0.459812358447860f, 0.458358730621271f, 0.456903875630421f, 0.455447797370393f,
+ 0.453990499739547f, 0.452531986639508f, 0.451072261975153f, 0.449611329654607f,
+ 0.448149193589223f, 0.446685857693580f, 0.445221325885468f, 0.443755602085881f,
+ 0.442288690219001f, 0.440820594212194f, 0.439351317995994f, 0.437880865504095f,
+ 0.436409240673342f, 0.434936447443717f, 0.433462489758331f, 0.431987371563412f,
+ 0.430511096808295f, 0.429033669445413f, 0.427555093430282f, 0.426075372721496f,
+ 0.424594511280713f, 0.423112513072644f, 0.421629382065045f, 0.420145122228703f,
+ 0.418659737537428f, 0.417173231968043f, 0.415685609500371f, 0.414196874117224f,
+ 0.412707029804395f, 0.411216080550645f, 0.409724030347695f, 0.408230883190212f,
+ 0.406736643075800f, 0.405241314004990f, 0.403744899981227f, 0.402247405010863f,
+ 0.400748833103141f, 0.399249188270190f, 0.397748474527011f, 0.396246695891466f,
+ 0.394743856384267f, 0.393239960028970f, 0.391735010851956f, 0.390229012882428f,
+ 0.388721970152396f, 0.387213886696666f, 0.385704766552831f, 0.384194613761262f,
+ 0.382683432365090f, 0.381171226410203f, 0.379657999945233f, 0.378143757021541f,
+ 0.376628501693211f, 0.375112238017038f, 0.373594970052516f, 0.372076701861829f,
+ 0.370557437509836f, 0.369037181064067f, 0.367515936594704f, 0.365993708174577f,
+ 0.364470499879150f, 0.362946315786509f, 0.361421159977355f, 0.359895036534988f,
+ 0.358367949545300f, 0.356839903096763f, 0.355310901280416f, 0.353780948189858f,
+ 0.352250047921234f, 0.350718204573223f, 0.349185422247033f, 0.347651705046382f,
+ 0.346117057077493f, 0.344581482449081f, 0.343044985272340f, 0.341507569660936f,
+ 0.339969239730994f, 0.338429999601086f, 0.336889853392220f, 0.335348805227832f,
+ 0.333806859233771f, 0.332264019538291f, 0.330720290272038f, 0.329175675568039f,
+ 0.327630179561693f, 0.326083806390759f, 0.324536560195342f, 0.322988445117886f,
+ 0.321439465303162f, 0.319889624898253f, 0.318338928052550f, 0.316787378917734f,
+ 0.315234981647770f, 0.313681740398892f, 0.312127659329594f, 0.310572742600619f,
+ 0.309016994374947f, 0.307460418817785f, 0.305903020096554f, 0.304344802380877f,
+ 0.302785769842575f, 0.301225926655645f, 0.299665276996257f, 0.298103825042740f,
+ 0.296541574975571f, 0.294978530977364f, 0.293414697232857f, 0.291850077928904f,
+ 0.290284677254463f, 0.288718499400580f, 0.287151548560387f, 0.285583828929082f,
+ 0.284015344703923f, 0.282446100084212f, 0.280876099271292f, 0.279305346468526f,
+ 0.277733845881292f, 0.276161601716971f, 0.274588618184932f, 0.273014899496527f,
+ 0.271440449865074f, 0.269865273505849f, 0.268289374636071f, 0.266712757474899f,
+ 0.265135426243408f, 0.263557385164591f, 0.261978638463337f, 0.260399190366428f,
+ 0.258819045102521f, 0.257238206902140f, 0.255656679997665f, 0.254074468623318f,
+ 0.252491577015158f, 0.250908009411060f, 0.249323770050712f, 0.247738863175598f,
+ 0.246153293028993f, 0.244567063855944f, 0.242980179903264f, 0.241392645419519f,
+ 0.239804464655017f, 0.238215641861795f, 0.236626181293610f, 0.235036087205927f,
+ 0.233445363855905f, 0.231854015502391f, 0.230262046405902f, 0.228669460828619f,
+ 0.227076263034373f, 0.225482457288634f, 0.223888047858498f, 0.222293039012681f,
+ 0.220697435021501f, 0.219101240156870f, 0.217504458692281f, 0.215907094902801f,
+ 0.214309153065051f, 0.212710637457203f, 0.211111552358965f, 0.209511902051569f,
+ 0.207911690817759f, 0.206310922941784f, 0.204709602709380f, 0.203107734407763f,
+ 0.201505322325617f, 0.199902370753082f, 0.198298883981741f, 0.196694866304610f,
+ 0.195090322016128f, 0.193485255412143f, 0.191879670789901f, 0.190273572448036f,
+ 0.188666964686555f, 0.187059851806832f, 0.185452238111591f, 0.183844127904898f,
+ 0.182235525492147f, 0.180626435180053f, 0.179016861276633f, 0.177406808091201f,
+ 0.175796279934354f, 0.174185281117962f, 0.172573815955152f, 0.170961888760301f,
+ 0.169349503849025f, 0.167736665538162f, 0.166123378145765f, 0.164509645991092f,
+ 0.162895473394589f, 0.161280864677881f, 0.159665824163761f, 0.158050356176180f,
+ 0.156434465040231f, 0.154818155082141f, 0.153201430629259f, 0.151584296010041f,
+ 0.149966755554045f, 0.148348813591913f, 0.146730474455362f, 0.145111742477173f,
+ 0.143492621991180f, 0.141873117332253f, 0.140253232836296f, 0.138632972840227f,
+ 0.137012341681968f, 0.135391343700438f, 0.133769983235535f, 0.132148264628130f,
+ 0.130526192220052f, 0.128903770354076f, 0.127281003373913f, 0.125657895624201f,
+ 0.124034451450485f, 0.122410675199216f, 0.120786571217731f, 0.119162143854244f,
+ 0.117537397457838f, 0.115912336378446f, 0.114286964966846f, 0.112661287574648f,
+ 0.111035308554278f, 0.109409032258971f, 0.107782463042760f, 0.106155605260457f,
+ 0.104528463267653f, 0.102901041420696f, 0.101273344076683f, 0.0996453755934510f,
+ 0.0980171403295608f, 0.0963886426442880f, 0.0947598868976111f, 0.0931308774501999f,
+ 0.0915016186634025f, 0.0898721148992351f, 0.0882423705203694f, 0.0866123898901223f,
+ 0.0849821773724418f, 0.0833517373318973f, 0.0817210741336683f, 0.0800901921435302f,
+ 0.0784590957278450f, 0.0768277892535488f, 0.0751962770881400f, 0.0735645635996675f,
+ 0.0719326531567196f, 0.0703005501284112f, 0.0686682588843738f, 0.0670357837947423f,
+ 0.0654031292301431f, 0.0637702995616845f, 0.0621372991609429f, 0.0605041323999515f,
+ 0.0588708036511890f, 0.0572373172875686f, 0.0556036776824248f, 0.0539698892095020f,
+ 0.0523359562429437f, 0.0507018831572809f, 0.0490676743274181f, 0.0474333341286244f,
+ 0.0457988669365209f, 0.0441642771270675f, 0.0425295690765532f, 0.0408947471615835f,
+ 0.0392598157590687f, 0.0376247792462120f, 0.0359896420004986f, 0.0343544083996823f,
+ 0.0327190828217762f, 0.0310836696450389f, 0.0294481732479632f, 0.0278125980092656f,
+ 0.0261769483078731f, 0.0245412285229125f, 0.0229054430336971f, 0.0212695962197177f,
+ 0.0196336924606285f, 0.0179977361362357f, 0.0163617316264867f, 0.0147256833114587f,
+ 0.0130895955713446f, 0.0114534727864437f, 0.00981731933714973f, 0.00818113960393724f,
+ 0.00654493796735196f, 0.00490871880799808f, 0.00327248650652671f, 0.00163624544362412f,
+ 0.00000000000000000f
+};
+
+const float ivas_mdft_coeff_cos_twid_640[IVAS_640_PT_LEN + 1] =
+{
+ 1.00000000000000f, 0.999996988037278f, 0.999987952167257f, 0.999972892444367f,
+ 0.999951808959328f, 0.999924701839145f, 0.999891571247108f, 0.999852417382795f,
+ 0.999807240482065f, 0.999756040817060f, 0.999698818696204f, 0.999635574464198f,
+ 0.999566308502021f, 0.999491021226926f, 0.999409713092437f, 0.999322384588350f,
+ 0.999229036240723f, 0.999129668611881f, 0.999024282300407f, 0.998912877941140f,
+ 0.998795456205172f, 0.998672017799843f, 0.998542563468736f, 0.998407093991674f,
+ 0.998265610184716f, 0.998118112900149f, 0.997964603026487f, 0.997805081488460f,
+ 0.997639549247016f, 0.997468007299307f, 0.997290456678690f, 0.997106898454717f,
+ 0.996917333733128f, 0.996721763655847f, 0.996520189400975f, 0.996312612182778f,
+ 0.996099033251687f, 0.995879453894286f, 0.995653875433303f, 0.995422299227608f,
+ 0.995184726672197f, 0.994941159198190f, 0.994691598272820f, 0.994436045399422f,
+ 0.994174502117428f, 0.993906970002356f, 0.993633450665799f, 0.993353945755417f,
+ 0.993068456954926f, 0.992776985984091f, 0.992479534598710f, 0.992176104590609f,
+ 0.991866697787626f, 0.991551316053606f, 0.991229961288385f, 0.990902635427780f,
+ 0.990569340443577f, 0.990230078343521f, 0.989884851171301f, 0.989533661006540f,
+ 0.989176509964781f, 0.988813400197476f, 0.988444333891970f, 0.988069313271492f,
+ 0.987688340595138f, 0.987301418157858f, 0.986908548290446f, 0.986509733359519f,
+ 0.986104975767509f, 0.985694277952645f, 0.985277642388941f, 0.984855071586178f,
+ 0.984426568089892f, 0.983992134481354f, 0.983551773377562f, 0.983105487431216f,
+ 0.982653279330712f, 0.982195151800116f, 0.981731107599154f, 0.981261149523195f,
+ 0.980785280403230f, 0.980303503105861f, 0.979815820533276f, 0.979322235623241f,
+ 0.978822751349072f, 0.978317370719628f, 0.977806096779282f, 0.977288932607910f,
+ 0.976765881320872f, 0.976236946068990f, 0.975702130038529f, 0.975161436451181f,
+ 0.974614868564045f, 0.974062429669605f, 0.973504123095711f, 0.972939952205560f,
+ 0.972369920397677f, 0.971794031105889f, 0.971212287799312f, 0.970624693982323f,
+ 0.970031253194544f, 0.969431969010818f, 0.968826845041188f, 0.968215884930876f,
+ 0.967599092360260f, 0.966976471044852f, 0.966348024735277f, 0.965713757217249f,
+ 0.965073672311547f, 0.964427773873996f, 0.963776065795440f, 0.963118552001719f,
+ 0.962455236453647f, 0.961786123146989f, 0.961111216112432f, 0.960430519415566f,
+ 0.959744037156857f, 0.959051773471624f, 0.958353732530011f, 0.957649918536965f,
+ 0.956940335732209f, 0.956224988390216f, 0.955503880820186f, 0.954777017366017f,
+ 0.954044402406280f, 0.953306040354194f, 0.952561935657595f, 0.951812092798916f,
+ 0.951056516295154f, 0.950295210697844f, 0.949528180593037f, 0.948755430601263f,
+ 0.947976965377510f, 0.947192789611197f, 0.946402908026138f, 0.945607325380521f,
+ 0.944806046466878f, 0.943999076112052f, 0.943186419177173f, 0.942368080557626f,
+ 0.941544065183021f, 0.940714378017165f, 0.939879024058033f, 0.939038008337734f,
+ 0.938191335922484f, 0.937339011912575f, 0.936481041442343f, 0.935617429680138f,
+ 0.934748181828292f, 0.933873303123092f, 0.932992798834739f, 0.932106674267327f,
+ 0.931214934758804f, 0.930317585680942f, 0.929414632439304f, 0.928506080473216f,
+ 0.927591935255724f, 0.926672202293573f, 0.925746887127164f, 0.924815995330528f,
+ 0.923879532511287f, 0.922937504310623f, 0.921989916403245f, 0.921036774497350f,
+ 0.920078084334595f, 0.919113851690058f, 0.918144082372204f, 0.917168782222852f,
+ 0.916187957117136f, 0.915201612963474f, 0.914209755703531f, 0.913212391312179f,
+ 0.912209525797468f, 0.911201165200584f, 0.910187315595818f, 0.909167983090522f,
+ 0.908143173825081f, 0.907112893972869f, 0.906077149740215f, 0.905035947366364f,
+ 0.903989293123443f, 0.902937193316419f, 0.901879654283062f, 0.900816682393908f,
+ 0.899748284052222f, 0.898674465693954f, 0.897595233787707f, 0.896510594834693f,
+ 0.895420555368697f, 0.894325121956035f, 0.893224301195515f, 0.892118099718401f,
+ 0.891006524188368f, 0.889889581301463f, 0.888767277786068f, 0.887639620402854f,
+ 0.886506615944746f, 0.885368271236879f, 0.884224593136556f, 0.883075588533209f,
+ 0.881921264348355f, 0.880761627535558f, 0.879596685080383f, 0.878426444000357f,
+ 0.877250911344924f, 0.876070094195407f, 0.874883999664958f, 0.873692634898524f,
+ 0.872496007072797f, 0.871294123396174f, 0.870086991108712f, 0.868874617482085f,
+ 0.867657009819544f, 0.866434175455865f, 0.865206121757311f, 0.863972856121587f,
+ 0.862734385977792f, 0.861490718786378f, 0.860241862039105f, 0.858987823258990f,
+ 0.857728610000272f, 0.856464229848356f, 0.855194690419775f, 0.853919999362139f,
+ 0.852640164354092f, 0.851355193105265f, 0.850065093356229f, 0.848769872878448f,
+ 0.847469539474235f, 0.846164100976699f, 0.844853565249707f, 0.843537940187827f,
+ 0.842217233716287f, 0.840891453790923f, 0.839560608398136f, 0.838224705554838f,
+ 0.836883753308409f, 0.835537759736646f, 0.834186732947712f, 0.832830681080094f,
+ 0.831469612302545f, 0.830103534814044f, 0.828732456843738f, 0.827356386650900f,
+ 0.825975332524873f, 0.824589302785025f, 0.823198305780696f, 0.821802349891147f,
+ 0.820401443525514f, 0.818995595122750f, 0.817584813151584f, 0.816169106110459f,
+ 0.814748482527489f, 0.813322950960406f, 0.811892519996505f, 0.810457198252595f,
+ 0.809016994374948f, 0.807571917039244f, 0.806121974950521f, 0.804667176843123f,
+ 0.803207531480645f, 0.801743047655882f, 0.800273734190774f, 0.798799599936358f,
+ 0.797320653772707f, 0.795836904608884f, 0.794348361382882f, 0.792855033061574f,
+ 0.791356928640660f, 0.789854057144609f, 0.788346427626606f, 0.786834049168500f,
+ 0.785316930880745f, 0.783795081902349f, 0.782268511400816f, 0.780737228572095f,
+ 0.779201242640517f, 0.777660562858748f, 0.776115198507728f, 0.774565158896617f,
+ 0.773010453362737f, 0.771451091271519f, 0.769887082016445f, 0.768318435018988f,
+ 0.766745159728562f, 0.765167265622459f, 0.763584762205797f, 0.761997659011457f,
+ 0.760405965600031f, 0.758809691559762f, 0.757208846506485f, 0.755603440083571f,
+ 0.753993481961870f, 0.752378981839648f, 0.750759949442534f, 0.749136394523459f,
+ 0.747508326862597f, 0.745875756267305f, 0.744238692572067f, 0.742597145638433f,
+ 0.740951125354959f, 0.739300641637149f, 0.737645704427393f, 0.735986323694910f,
+ 0.734322509435686f, 0.732654271672413f, 0.730981620454432f, 0.729304565857669f,
+ 0.727623117984575f, 0.725937286964068f, 0.724247082951467f, 0.722552516128436f,
+ 0.720853596702919f, 0.719150334909079f, 0.717442741007240f, 0.715730825283819f,
+ 0.714014598051268f, 0.712294069648014f, 0.710569250438390f, 0.708840150812579f,
+ 0.707106781186548f, 0.705369152001986f, 0.703627273726243f, 0.701881156852263f,
+ 0.700130811898524f, 0.698376249408973f, 0.696617479952964f, 0.694854514125194f,
+ 0.693087362545636f, 0.691316035859480f, 0.689540544737067f, 0.687760899873822f,
+ 0.685977111990193f, 0.684189191831585f, 0.682397150168297f, 0.680600997795453f,
+ 0.678800745532942f, 0.676996404225349f, 0.675187984741891f, 0.673375497976352f,
+ 0.671558954847018f, 0.669738366296610f, 0.667913743292216f, 0.666085096825230f,
+ 0.664252437911282f, 0.662415777590172f, 0.660575126925805f, 0.658730497006124f,
+ 0.656881898943041f, 0.655029343872374f, 0.653172842953777f, 0.651312407370671f,
+ 0.649448048330184f, 0.647579777063073f, 0.645707604823667f, 0.643831542889792f,
+ 0.641951602562703f, 0.640067795167023f, 0.638180132050665f, 0.636288624584773f,
+ 0.634393284163646f, 0.632494122204673f, 0.630591150148264f, 0.628684379457781f,
+ 0.626773821619470f, 0.624859488142386f, 0.622941390558334f, 0.621019540421789f,
+ 0.619093949309834f, 0.617164628822086f, 0.615231590580627f, 0.613294846229936f,
+ 0.611354407436817f, 0.609410285890327f, 0.607462493301711f, 0.605511041404326f,
+ 0.603555941953571f, 0.601597206726822f, 0.599634847523352f, 0.597668876164268f,
+ 0.595699304492433f, 0.593726144372402f, 0.591749407690343f, 0.589769106353971f,
+ 0.587785252292473f, 0.585797857456439f, 0.583806933817786f, 0.581812493369691f,
+ 0.579814548126514f, 0.577813110123727f, 0.575808191417845f, 0.573799804086349f,
+ 0.571787960227612f, 0.569772671960834f, 0.567753951425961f, 0.565731810783613f,
+ 0.563706262215017f, 0.561677317921925f, 0.559644990126546f, 0.557609291071472f,
+ 0.555570233019602f, 0.553527828254070f, 0.551482089078169f, 0.549433027815281f,
+ 0.547380656808797f, 0.545324988422047f, 0.543266035038224f, 0.541203809060310f,
+ 0.539138322911000f, 0.537069589032630f, 0.534997619887097f, 0.532922427955790f,
+ 0.530844025739510f, 0.528762425758396f, 0.526677640551852f, 0.524589682678469f,
+ 0.522498564715949f, 0.520404299261031f, 0.518306898929413f, 0.516206376355680f,
+ 0.514102744193222f, 0.511996015114163f, 0.509886201809281f, 0.507773316987935f,
+ 0.505657373377985f, 0.503538383725718f, 0.501416360795769f, 0.499291317371047f,
+ 0.497163266252654f, 0.495032220259813f, 0.492898192229784f, 0.490761195017794f,
+ 0.488621241496955f, 0.486478344558187f, 0.484332517110141f, 0.482183772079123f,
+ 0.480032122409011f, 0.477877581061184f, 0.475720161014437f, 0.473559875264908f,
+ 0.471396736825998f, 0.469230758728290f, 0.467061954019477f, 0.464890335764274f,
+ 0.462715917044350f, 0.460538710958240f, 0.458358730621271f, 0.456175989165483f,
+ 0.453990499739547f, 0.451802275508688f, 0.449611329654607f, 0.447417675375397f,
+ 0.445221325885468f, 0.443022294415467f, 0.440820594212194f, 0.438616238538528f,
+ 0.436409240673342f, 0.434199613911428f, 0.431987371563412f, 0.429772526955677f,
+ 0.427555093430282f, 0.425335084344881f, 0.423112513072644f, 0.420887393002174f,
+ 0.418659737537428f, 0.416429560097637f, 0.414196874117224f, 0.411961693045722f,
+ 0.409724030347695f, 0.407483899502658f, 0.405241314004990f, 0.402996287363860f,
+ 0.400748833103141f, 0.398498964761330f, 0.396246695891466f, 0.393992040061048f,
+ 0.391735010851956f, 0.389475621860365f, 0.387213886696666f, 0.384949818985382f,
+ 0.382683432365090f, 0.380414740488332f, 0.378143757021541f, 0.375870495644950f,
+ 0.373594970052516f, 0.371317193951838f, 0.369037181064066f, 0.366754945123831f,
+ 0.364470499879150f, 0.362183859091351f, 0.359895036534988f, 0.357604045997758f,
+ 0.355310901280416f, 0.353015616196696f, 0.350718204573223f, 0.348418680249435f,
+ 0.346117057077493f, 0.343813348922205f, 0.341507569660936f, 0.339199733183530f,
+ 0.336889853392220f, 0.334577944201551f, 0.332264019538291f, 0.329948093341349f,
+ 0.327630179561693f, 0.325310292162263f, 0.322988445117886f, 0.320664652415197f,
+ 0.318338928052550f, 0.316011286039934f, 0.313681740398892f, 0.311350305162432f,
+ 0.309016994374947f, 0.306681822092128f, 0.304344802380877f, 0.302005949319228f,
+ 0.299665276996257f, 0.297322799511999f, 0.294978530977364f, 0.292632485514051f,
+ 0.290284677254463f, 0.287935120341621f, 0.285583828929082f, 0.283230817180850f,
+ 0.280876099271292f, 0.278519689385053f, 0.276161601716971f, 0.273801850471989f,
+ 0.271440449865074f, 0.269077414121127f, 0.266712757474898f, 0.264346494170904f,
+ 0.261978638463337f, 0.259609204615985f, 0.257238206902140f, 0.254865659604515f,
+ 0.252491577015158f, 0.250115973435366f, 0.247738863175599f, 0.245360260555389f,
+ 0.242980179903264f, 0.240598635556650f, 0.238215641861795f, 0.235831213173673f,
+ 0.233445363855905f, 0.231058108280671f, 0.228669460828619f, 0.226279435888785f,
+ 0.223888047858498f, 0.221495311143304f, 0.219101240156870f, 0.216705849320900f,
+ 0.214309153065051f, 0.211911165826842f, 0.209511902051569f, 0.207111376192219f,
+ 0.204709602709380f, 0.202306596071156f, 0.199902370753082f, 0.197496941238030f,
+ 0.195090322016128f, 0.192682527584672f, 0.190273572448036f, 0.187863471117585f,
+ 0.185452238111591f, 0.183039887955141f, 0.180626435180053f, 0.178211894324786f,
+ 0.175796279934354f, 0.173379606560240f, 0.170961888760301f, 0.168543141098691f,
+ 0.166123378145766f, 0.163702614477995f, 0.161280864677881f, 0.158858143333862f,
+ 0.156434465040231f, 0.154009844397046f, 0.151584296010041f, 0.149157834490539f,
+ 0.146730474455362f, 0.144302230526747f, 0.141873117332253f, 0.139443149504679f,
+ 0.137012341681968f, 0.134580708507126f, 0.132148264628130f, 0.129715024697841f,
+ 0.127281003373913f, 0.124846215318711f, 0.122410675199216f, 0.119974397686941f,
+ 0.117537397457838f, 0.115099689192216f, 0.112661287574648f, 0.110222207293883f,
+ 0.107782463042759f, 0.105342069518114f, 0.102901041420696f, 0.100459393455077f,
+ 0.0980171403295608f, 0.0955742967560992f, 0.0931308774501999f, 0.0906868971308382f,
+ 0.0882423705203696f, 0.0857973123444399f, 0.0833517373318975f, 0.0809056602147037f,
+ 0.0784590957278450f, 0.0760120586092433f, 0.0735645635996675f, 0.0711166254426455f,
+ 0.0686682588843738f, 0.0662194786736304f, 0.0637702995616845f, 0.0613207363022087f,
+ 0.0588708036511890f, 0.0564205163668375f, 0.0539698892095020f, 0.0515189369415775f,
+ 0.0490676743274181f, 0.0466161161332467f, 0.0441642771270675f, 0.0417121720785753f,
+ 0.0392598157590687f, 0.0368072229413588f, 0.0343544083996823f, 0.0319013869096110f,
+ 0.0294481732479634f, 0.0269947821927155f, 0.0245412285229123f, 0.0220875270185784f,
+ 0.0196336924606283f, 0.0171797396307788f, 0.0147256833114584f, 0.0122715382857199f,
+ 0.00981731933714973f, 0.00736304124977978f, 0.00490871880799808f, 0.00245436679646048f,
+ 0.00000000000000000f
+};
+
+const float ivas_mdft_coeff_cos_twid_320[IVAS_320_PT_LEN + 1] =
+{
+ 1.00000000000000f, 0.999987952167257f, 0.999951808959328f, 0.999891571247108f,
+ 0.999807240482065f, 0.999698818696204f, 0.999566308502021f, 0.999409713092437f,
+ 0.999229036240723f, 0.999024282300407f, 0.998795456205172f, 0.998542563468736f,
+ 0.998265610184716f, 0.997964603026487f, 0.997639549247016f, 0.997290456678690f,
+ 0.996917333733128f, 0.996520189400975f, 0.996099033251687f, 0.995653875433303f,
+ 0.995184726672197f, 0.994691598272820f, 0.994174502117428f, 0.993633450665799f,
+ 0.993068456954926f, 0.992479534598710f, 0.991866697787626f, 0.991229961288385f,
+ 0.990569340443577f, 0.989884851171301f, 0.989176509964781f, 0.988444333891970f,
+ 0.987688340595138f, 0.986908548290446f, 0.986104975767509f, 0.985277642388941f,
+ 0.984426568089892f, 0.983551773377562f, 0.982653279330712f, 0.981731107599154f,
+ 0.980785280403230f, 0.979815820533276f, 0.978822751349072f, 0.977806096779282f,
+ 0.976765881320872f, 0.975702130038529f, 0.974614868564045f, 0.973504123095711f,
+ 0.972369920397677f, 0.971212287799312f, 0.970031253194544f, 0.968826845041188f,
+ 0.967599092360260f, 0.966348024735277f, 0.965073672311547f, 0.963776065795440f,
+ 0.962455236453647f, 0.961111216112432f, 0.959744037156857f, 0.958353732530011f,
+ 0.956940335732209f, 0.955503880820186f, 0.954044402406280f, 0.952561935657595f,
+ 0.951056516295154f, 0.949528180593037f, 0.947976965377510f, 0.946402908026138f,
+ 0.944806046466878f, 0.943186419177173f, 0.941544065183021f, 0.939879024058033f,
+ 0.938191335922484f, 0.936481041442343f, 0.934748181828292f, 0.932992798834739f,
+ 0.931214934758804f, 0.929414632439304f, 0.927591935255724f, 0.925746887127164f,
+ 0.923879532511287f, 0.921989916403245f, 0.920078084334595f, 0.918144082372204f,
+ 0.916187957117136f, 0.914209755703531f, 0.912209525797468f, 0.910187315595818f,
+ 0.908143173825081f, 0.906077149740215f, 0.903989293123443f, 0.901879654283062f,
+ 0.899748284052222f, 0.897595233787707f, 0.895420555368697f, 0.893224301195515f,
+ 0.891006524188368f, 0.888767277786068f, 0.886506615944746f, 0.884224593136556f,
+ 0.881921264348355f, 0.879596685080383f, 0.877250911344924f, 0.874883999664958f,
+ 0.872496007072797f, 0.870086991108712f, 0.867657009819544f, 0.865206121757311f,
+ 0.862734385977792f, 0.860241862039105f, 0.857728610000272f, 0.855194690419775f,
+ 0.852640164354092f, 0.850065093356229f, 0.847469539474235f, 0.844853565249707f,
+ 0.842217233716287f, 0.839560608398136f, 0.836883753308409f, 0.834186732947712f,
+ 0.831469612302545f, 0.828732456843738f, 0.825975332524873f, 0.823198305780696f,
+ 0.820401443525514f, 0.817584813151584f, 0.814748482527489f, 0.811892519996505f,
+ 0.809016994374948f, 0.806121974950521f, 0.803207531480645f, 0.800273734190774f,
+ 0.797320653772707f, 0.794348361382882f, 0.791356928640660f, 0.788346427626606f,
+ 0.785316930880745f, 0.782268511400816f, 0.779201242640517f, 0.776115198507728f,
+ 0.773010453362737f, 0.769887082016445f, 0.766745159728562f, 0.763584762205797f,
+ 0.760405965600031f, 0.757208846506485f, 0.753993481961870f, 0.750759949442534f,
+ 0.747508326862597f, 0.744238692572067f, 0.740951125354959f, 0.737645704427393f,
+ 0.734322509435686f, 0.730981620454432f, 0.727623117984575f, 0.724247082951467f,
+ 0.720853596702919f, 0.717442741007240f, 0.714014598051268f, 0.710569250438390f,
+ 0.707106781186548f, 0.703627273726243f, 0.700130811898524f, 0.696617479952964f,
+ 0.693087362545636f, 0.689540544737067f, 0.685977111990193f, 0.682397150168297f,
+ 0.678800745532942f, 0.675187984741891f, 0.671558954847018f, 0.667913743292216f,
+ 0.664252437911282f, 0.660575126925805f, 0.656881898943041f, 0.653172842953777f,
+ 0.649448048330184f, 0.645707604823667f, 0.641951602562703f, 0.638180132050665f,
+ 0.634393284163646f, 0.630591150148264f, 0.626773821619470f, 0.622941390558334f,
+ 0.619093949309834f, 0.615231590580627f, 0.611354407436817f, 0.607462493301711f,
+ 0.603555941953571f, 0.599634847523352f, 0.595699304492433f, 0.591749407690343f,
+ 0.587785252292473f, 0.583806933817786f, 0.579814548126514f, 0.575808191417845f,
+ 0.571787960227612f, 0.567753951425961f, 0.563706262215017f, 0.559644990126546f,
+ 0.555570233019602f, 0.551482089078169f, 0.547380656808797f, 0.543266035038224f,
+ 0.539138322911000f, 0.534997619887097f, 0.530844025739510f, 0.526677640551852f,
+ 0.522498564715949f, 0.518306898929413f, 0.514102744193222f, 0.509886201809281f,
+ 0.505657373377985f, 0.501416360795769f, 0.497163266252654f, 0.492898192229784f,
+ 0.488621241496955f, 0.484332517110141f, 0.480032122409011f, 0.475720161014437f,
+ 0.471396736825998f, 0.467061954019477f, 0.462715917044350f, 0.458358730621271f,
+ 0.453990499739547f, 0.449611329654607f, 0.445221325885468f, 0.440820594212194f,
+ 0.436409240673342f, 0.431987371563412f, 0.427555093430282f, 0.423112513072644f,
+ 0.418659737537428f, 0.414196874117224f, 0.409724030347695f, 0.405241314004990f,
+ 0.400748833103141f, 0.396246695891466f, 0.391735010851956f, 0.387213886696666f,
+ 0.382683432365090f, 0.378143757021541f, 0.373594970052516f, 0.369037181064066f,
+ 0.364470499879150f, 0.359895036534988f, 0.355310901280416f, 0.350718204573223f,
+ 0.346117057077493f, 0.341507569660936f, 0.336889853392220f, 0.332264019538291f,
+ 0.327630179561693f, 0.322988445117886f, 0.318338928052550f, 0.313681740398892f,
+ 0.309016994374947f, 0.304344802380877f, 0.299665276996257f, 0.294978530977364f,
+ 0.290284677254463f, 0.285583828929082f, 0.280876099271292f, 0.276161601716971f,
+ 0.271440449865074f, 0.266712757474898f, 0.261978638463337f, 0.257238206902140f,
+ 0.252491577015158f, 0.247738863175599f, 0.242980179903264f, 0.238215641861795f,
+ 0.233445363855905f, 0.228669460828619f, 0.223888047858498f, 0.219101240156870f,
+ 0.214309153065051f, 0.209511902051569f, 0.204709602709380f, 0.199902370753082f,
+ 0.195090322016128f, 0.190273572448036f, 0.185452238111591f, 0.180626435180053f,
+ 0.175796279934354f, 0.170961888760301f, 0.166123378145766f, 0.161280864677881f,
+ 0.156434465040231f, 0.151584296010041f, 0.146730474455362f, 0.141873117332253f,
+ 0.137012341681968f, 0.132148264628130f, 0.127281003373913f, 0.122410675199216f,
+ 0.117537397457838f, 0.112661287574648f, 0.107782463042759f, 0.102901041420696f,
+ 0.0980171403295608f, 0.0931308774501999f, 0.0882423705203696f, 0.0833517373318975f,
+ 0.0784590957278450f, 0.0735645635996675f, 0.0686682588843738f, 0.0637702995616845f,
+ 0.0588708036511890f, 0.0539698892095020f, 0.0490676743274181f, 0.0441642771270675f,
+ 0.0392598157590687f, 0.0343544083996823f, 0.0294481732479634f, 0.0245412285229123f,
+ 0.0196336924606283f, 0.0147256833114584f, 0.00981731933714973f, 0.00490871880799808f,
+ 0.0000000000000000f
+};
+
+const float ivas_mdft_coeff_cos_twid_240[IVAS_240_PT_LEN + 1] =
+{
+ 1.0000000000f, 0.9999785817f, 0.9999143276f, 0.9998072405f, 0.9996573250f, 0.9994645875f,
+ 0.9992290362f, 0.9989506814f, 0.9986295348f, 0.9982656102f, 0.9978589232f, 0.9974094913f,
+ 0.9969173337f, 0.9963824715f, 0.9958049276f, 0.9951847267f, 0.9945218954f, 0.9938164621f,
+ 0.9930684570f, 0.9922779121f, 0.9914448614f, 0.9905693404f, 0.9896513868f, 0.9886910398f,
+ 0.9876883406f, 0.9866433321f, 0.9855560591f, 0.9844265681f, 0.9832549076f, 0.9820411277f,
+ 0.9807852804f, 0.9794874196f, 0.9781476007f, 0.9767658813f, 0.9753423205f, 0.9738769793f,
+ 0.9723699204f, 0.9708212084f, 0.9692309097f, 0.9675990924f, 0.9659258263f, 0.9642111832f,
+ 0.9624552365f, 0.9606580614f, 0.9588197349f, 0.9569403357f, 0.9550199445f, 0.9530586433f,
+ 0.9510565163f, 0.9490136492f, 0.9469301295f, 0.9448060465f, 0.9426414911f, 0.9404365561f,
+ 0.9381913359f, 0.9359059268f, 0.9335804265f, 0.9312149348f, 0.9288095529f, 0.9263643839f,
+ 0.9238795325f, 0.9213551052f, 0.9187912101f, 0.9161879571f, 0.9135454576f, 0.9108638249f,
+ 0.9081431738f, 0.9053836209f, 0.9025852843f, 0.8997482841f, 0.8968727415f, 0.8939587800f,
+ 0.8910065242f, 0.8880161007f, 0.8849876375f, 0.8819212643f, 0.8788171127f, 0.8756753154f,
+ 0.8724960071f, 0.8692793239f, 0.8660254038f, 0.8627343860f, 0.8594064115f, 0.8560416229f,
+ 0.8526401644f, 0.8492021815f, 0.8457278217f, 0.8422172337f, 0.8386705679f, 0.8350879763f,
+ 0.8314696123f, 0.8278156309f, 0.8241261886f, 0.8204014435f, 0.8166415552f, 0.8128466846f,
+ 0.8090169944f, 0.8051526486f, 0.8012538127f, 0.7973206538f, 0.7933533403f, 0.7893520422f,
+ 0.7853169309f, 0.7812481792f, 0.7771459615f, 0.7730104534f, 0.7688418321f, 0.7646402762f,
+ 0.7604059656f, 0.7561390818f, 0.7518398075f, 0.7475083269f, 0.7431448255f, 0.7387494902f,
+ 0.7343225094f, 0.7298640727f, 0.7253743710f, 0.7208535967f, 0.7163019434f, 0.7117196062f,
+ 0.7071067812f, 0.7024636661f, 0.6977904598f, 0.6930873625f, 0.6883545757f, 0.6835923020f,
+ 0.6788007455f, 0.6739801115f, 0.6691306064f, 0.6642524379f, 0.6593458151f, 0.6544109481f,
+ 0.6494480483f, 0.6444573284f, 0.6394390020f, 0.6343932842f, 0.6293203910f, 0.6242205399f,
+ 0.6190939493f, 0.6139408388f, 0.6087614290f, 0.6035559420f, 0.5983246006f, 0.5930676290f,
+ 0.5877852523f, 0.5824776969f, 0.5771451900f, 0.5717879602f, 0.5664062369f, 0.5610002507f,
+ 0.5555702330f, 0.5501164166f, 0.5446390350f, 0.5391383229f, 0.5336145159f, 0.5280678507f,
+ 0.5224985647f, 0.5169068967f, 0.5112930861f, 0.5056573734f, 0.5000000000f, 0.4943212083f,
+ 0.4886212415f, 0.4829003438f, 0.4771587603f, 0.4713967368f, 0.4656145203f, 0.4598123584f,
+ 0.4539904997f, 0.4481491936f, 0.4422886902f, 0.4364092407f, 0.4305110968f, 0.4245945113f,
+ 0.4186597375f, 0.4127070298f, 0.4067366431f, 0.4007488331f, 0.3947438564f, 0.3887219702f,
+ 0.3826834324f, 0.3766285017f, 0.3705574375f, 0.3644704999f, 0.3583679495f, 0.3522500479f,
+ 0.3461170571f, 0.3399692397f, 0.3338068592f, 0.3276301796f, 0.3214394653f, 0.3152349816f,
+ 0.3090169944f, 0.3027857698f, 0.2965415750f, 0.2902846773f, 0.2840153447f, 0.2777338459f,
+ 0.2714404499f, 0.2651354262f, 0.2588190451f, 0.2524915770f, 0.2461532930f, 0.2398044647f,
+ 0.2334453639f, 0.2270762630f, 0.2206974350f, 0.2143091531f, 0.2079116908f, 0.2015053223f,
+ 0.1950903220f, 0.1886669647f, 0.1822355255f, 0.1757962799f, 0.1693495038f, 0.1628954734f,
+ 0.1564344650f, 0.1499667556f, 0.1434926220f, 0.1370123417f, 0.1305261922f, 0.1240344515f,
+ 0.1175373975f, 0.1110353086f, 0.1045284633f, 0.0980171403f, 0.0915016187f, 0.0849821774f,
+ 0.0784590957f, 0.0719326532f, 0.0654031292f, 0.0588708037f, 0.0523359562f, 0.0457988669f,
+ 0.0392598158f, 0.0327190828f, 0.0261769483f, 0.0196336925f, 0.0130895956f, 0.0065449380f,
+ 0.000000000f
+};
+const float ivas_mdft_coeff_cos_twid_160[IVAS_160_PT_LEN + 1] =
+{
+ 1.0000000000f, 0.9999518090f, 0.9998072405f, 0.9995663085f, 0.9992290362f, 0.9987954562f,
+ 0.9982656102f, 0.9976395492f, 0.9969173337f, 0.9960990333f, 0.9951847267f, 0.9941745021f,
+ 0.9930684570f, 0.9918666978f, 0.9905693404f, 0.9891765100f, 0.9876883406f, 0.9861049758f,
+ 0.9844265681f, 0.9826532793f, 0.9807852804f, 0.9788227513f, 0.9767658813f, 0.9746148686f,
+ 0.9723699204f, 0.9700312532f, 0.9675990924f, 0.9650736723f, 0.9624552365f, 0.9597440372f,
+ 0.9569403357f, 0.9540444024f, 0.9510565163f, 0.9479769654f, 0.9448060465f, 0.9415440652f,
+ 0.9381913359f, 0.9347481818f, 0.9312149348f, 0.9275919353f, 0.9238795325f, 0.9200780843f,
+ 0.9161879571f, 0.9122095258f, 0.9081431738f, 0.9039892931f, 0.8997482841f, 0.8954205554f,
+ 0.8910065242f, 0.8865066159f, 0.8819212643f, 0.8772509113f, 0.8724960071f, 0.8676570098f,
+ 0.8627343860f, 0.8577286100f, 0.8526401644f, 0.8474695395f, 0.8422172337f, 0.8368837533f,
+ 0.8314696123f, 0.8259753325f, 0.8204014435f, 0.8147484825f, 0.8090169944f, 0.8032075315f,
+ 0.7973206538f, 0.7913569286f, 0.7853169309f, 0.7792012426f, 0.7730104534f, 0.7667451597f,
+ 0.7604059656f, 0.7539934820f, 0.7475083269f, 0.7409511254f, 0.7343225094f, 0.7276231180f,
+ 0.7208535967f, 0.7140145981f, 0.7071067812f, 0.7001308119f, 0.6930873625f, 0.6859771120f,
+ 0.6788007455f, 0.6715589548f, 0.6642524379f, 0.6568818989f, 0.6494480483f, 0.6419516026f,
+ 0.6343932842f, 0.6267738216f, 0.6190939493f, 0.6113544074f, 0.6035559420f, 0.5956993045f,
+ 0.5877852523f, 0.5798145481f, 0.5717879602f, 0.5637062622f, 0.5555702330f, 0.5473806568f,
+ 0.5391383229f, 0.5308440257f, 0.5224985647f, 0.5141027442f, 0.5056573734f, 0.4971632663f,
+ 0.4886212415f, 0.4800321224f, 0.4713967368f, 0.4627159170f, 0.4539904997f, 0.4452213259f,
+ 0.4364092407f, 0.4275550934f, 0.4186597375f, 0.4097240303f, 0.4007488331f, 0.3917350109f,
+ 0.3826834324f, 0.3735949701f, 0.3644704999f, 0.3553109013f, 0.3461170571f, 0.3368898534f,
+ 0.3276301796f, 0.3183389281f, 0.3090169944f, 0.2996652770f, 0.2902846773f, 0.2808760993f,
+ 0.2714404499f, 0.2619786385f, 0.2524915770f, 0.2429801799f, 0.2334453639f, 0.2238880479f,
+ 0.2143091531f, 0.2047096027f, 0.1950903220f, 0.1854522381f, 0.1757962799f, 0.1661233781f,
+ 0.1564344650f, 0.1467304745f, 0.1370123417f, 0.1272810034f, 0.1175373975f, 0.1077824630f,
+ 0.0980171403f, 0.0882423705f, 0.0784590957f, 0.0686682589f, 0.0588708037f, 0.0490676743f,
+ 0.0392598158f, 0.0294481732f, 0.0196336925f, 0.0098173193f, 0.000000000f
+};
+
+const float ivas_mdft_coeff_cos_twid_80[IVAS_80_PT_LEN + 1] =
+{
+ 1.0000000000f, 0.9998072405f, 0.9992290362f, 0.9982656102f, 0.9969173337f, 0.9951847267f,
+ 0.9930684570f, 0.9905693404f, 0.9876883406f, 0.9844265681f, 0.9807852804f, 0.9767658813f,
+ 0.9723699204f, 0.9675990924f, 0.9624552365f, 0.9569403357f, 0.9510565163f, 0.9448060465f,
+ 0.9381913359f, 0.9312149348f, 0.9238795325f, 0.9161879571f, 0.9081431738f, 0.8997482841f,
+ 0.8910065242f, 0.8819212643f, 0.8724960071f, 0.8627343860f, 0.8526401644f, 0.8422172337f,
+ 0.8314696123f, 0.8204014435f, 0.8090169944f, 0.7973206538f, 0.7853169309f, 0.7730104534f,
+ 0.7604059656f, 0.7475083269f, 0.7343225094f, 0.7208535967f, 0.7071067812f, 0.6930873625f,
+ 0.6788007455f, 0.6642524379f, 0.6494480483f, 0.6343932842f, 0.6190939493f, 0.6035559420f,
+ 0.5877852523f, 0.5717879602f, 0.5555702330f, 0.5391383229f, 0.5224985647f, 0.5056573734f,
+ 0.4886212415f, 0.4713967368f, 0.4539904997f, 0.4364092407f, 0.4186597375f, 0.4007488331f,
+ 0.3826834324f, 0.3644704999f, 0.3461170571f, 0.3276301796f, 0.3090169944f, 0.2902846773f,
+ 0.2714404499f, 0.2524915770f, 0.2334453639f, 0.2143091531f, 0.1950903220f, 0.1757962799f,
+ 0.1564344650f, 0.1370123417f, 0.1175373975f, 0.0980171403f, 0.0784590957f, 0.0588708037f,
+ 0.0392598158f, 0.0196336925f, 0.000000000f
+};
+
+const float ivas_mdft_coeff_cos_twid_40[IVAS_40_PT_LEN + 1] =
+{
+ 1.0000000000f, 0.9992290362f, 0.9969173337f, 0.9930684570f, 0.9876883406f, 0.9807852804f,
+ 0.9723699204f, 0.9624552365f, 0.9510565163f, 0.9381913359f, 0.9238795325f, 0.9081431738f,
+ 0.8910065242f, 0.8724960071f, 0.8526401644f, 0.8314696123f, 0.8090169944f, 0.7853169309f,
+ 0.7604059656f, 0.7343225094f, 0.7071067812f, 0.6788007455f, 0.6494480483f, 0.6190939493f,
+ 0.5877852523f, 0.5555702330f, 0.5224985647f, 0.4886212415f, 0.4539904997f, 0.4186597375f,
+ 0.3826834324f, 0.3461170571f, 0.3090169944f, 0.2714404499f, 0.2334453639f, 0.1950903220f,
+ 0.1564344650f, 0.1175373975f, 0.0784590957f, 0.0392598158f, 0.000000000f
+};
+
+const float ivas_sin_twiddle_480[IVAS_480_PT_LEN >> 1] =
+{
+ -0.000818122995607253f, -0.00736304124977957f, -0.0139076440957708f, -0.0204516511845773f,
+ -0.0269947821927154f, -0.0335367568342299f, -0.0400772948727007f, -0.0466161161332467f,
+ -0.0531529405145281f, -0.0596874880007445f, -0.0662194786736303f, -0.0727486327244454f,
+ -0.0792746704659607f, -0.0857973123444399f, -0.0923162789516138f, -0.0988312910366500f,
+ -0.105342069518114f, -0.111848335495926f, -0.118349810263305f, -0.124846215318711f,
+ -0.131337272377774f, -0.137822703385212f, -0.144302230526747f, -0.150775576241001f,
+ -0.157242463231389f, -0.163702614477995f, -0.170155753249442f, -0.176601603114742f,
+ -0.183039887955141f, -0.189470331975943f, -0.195892659718330f, -0.202306596071156f,
+ -0.208711866282735f, -0.215108195972610f, -0.221495311143304f, -0.227872938192063f,
+ -0.234240803922570f, -0.240598635556650f, -0.246946160745958f, -0.253283107583640f,
+ -0.259609204615985f, -0.265924180854051f, -0.272227765785273f, -0.278519689385053f,
+ -0.284799682128326f, -0.291067475001103f, -0.297322799511998f, -0.303565387703730f,
+ -0.309794972164597f, -0.316011286039934f, -0.322214063043544f, -0.328403037469105f,
+ -0.334577944201551f, -0.340738518728429f, -0.346884497151231f, -0.353015616196696f,
+ -0.359131613228090f, -0.365232226256457f, -0.371317193951838f, -0.377386255654469f,
+ -0.383439151385947f, -0.389475621860365f, -0.395495408495417f, -0.401498253423481f,
+ -0.407483899502658f, -0.413452090327791f, -0.419402570241451f, -0.425335084344881f,
+ -0.431249378508924f, -0.437145199384900f, -0.443022294415467f, -0.448880411845434f,
+ -0.454719300732547f, -0.460538710958240f, -0.466338393238348f, -0.472118099133784f,
+ -0.477877581061184f, -0.483616592303511f, -0.489334887020625f, -0.495032220259813f,
+ -0.500708347966279f, -0.506363026993606f, -0.511996015114162f, -0.517607071029487f,
+ -0.523195954380619f, -0.528762425758396f, -0.534306246713712f, -0.539827179767727f,
+ -0.545324988422047f, -0.550799437168844f, -0.556250291500956f, -0.561677317921925f,
+ -0.567080283956001f, -0.572458958158102f, -0.577813110123727f, -0.583142510498826f,
+ -0.588446930989624f, -0.593726144372402f, -0.598979924503229f, -0.604208046327650f,
+ -0.609410285890327f, -0.614586420344631f, -0.619736227962191f, -0.624859488142386f,
+ -0.629955981421804f, -0.635025489483634f, -0.640067795167023f, -0.645082682476378f,
+ -0.650069936590618f, -0.655029343872374f, -0.659960691877147f, -0.664863769362399f,
+ -0.669738366296610f, -0.674584273868271f, -0.679401284494831f, -0.684189191831585f,
+ -0.688947790780520f, -0.693676877499095f, -0.698376249408973f, -0.703045705204703f,
+ -0.707685044862340f, -0.712294069648014f, -0.716872582126442f, -0.721420386169390f,
+ -0.725937286964068f, -0.730423091021479f, -0.734877606184707f, -0.739300641637149f,
+ -0.743692007910687f, -0.748051516893805f, -0.752378981839648f, -0.756674217374021f,
+ -0.760937039503328f, -0.765167265622459f, -0.769364714522605f, -0.773529206399025f,
+ -0.777660562858748f, -0.781758606928213f, -0.785823163060853f, -0.789854057144609f,
+ -0.793851116509396f, -0.797814169934493f, -0.801743047655882f, -0.805637581373517f,
+ -0.809497604258536f, -0.813322950960406f, -0.817113457614006f, -0.820868961846646f,
+ -0.824589302785025f, -0.828274321062119f, -0.831923858824010f, -0.835537759736646f,
+ -0.839115868992540f, -0.842658033317402f, -0.846164100976699f, -0.849633921782164f,
+ -0.853067347098221f, -0.856464229848356f, -0.859824424521420f, -0.863147787177854f,
+ -0.866434175455865f, -0.869683448577516f, -0.872895467354761f, -0.876070094195407f,
+ -0.879207193109004f, -0.882306629712678f, -0.885368271236879f, -0.888391986531075f,
+ -0.891377646069366f, -0.894325121956035f, -0.897234287931024f, -0.900105019375345f,
+ -0.902937193316419f, -0.905730688433339f, -0.908485385062073f, -0.911201165200584f,
+ -0.913877912513892f, -0.916515512339049f, -0.919113851690058f, -0.921672819262709f,
+ -0.924192305439348f, -0.926672202293573f, -0.929112403594856f, -0.931512804813095f,
+ -0.933873303123092f, -0.936193797408954f, -0.938474188268430f, -0.940714378017165f,
+ -0.942914270692887f, -0.945073772059515f, -0.947192789611197f, -0.949271232576274f,
+ -0.951309011921168f, -0.953306040354194f, -0.955262232329299f, -0.957177504049732f,
+ -0.959051773471624f, -0.960884960307514f, -0.962676986029777f, -0.964427773873996f,
+ -0.966137248842248f, -0.967805337706313f, -0.969431969010818f, -0.971017073076290f,
+ -0.972560582002147f, -0.974062429669605f, -0.975522551744506f, -0.976940885680082f,
+ -0.978317370719628f, -0.979651947899104f, -0.980944560049668f, -0.982195151800116f,
+ -0.983403669579260f, -0.984570061618221f, -0.985694277952645f, -0.986776270424848f,
+ -0.987815992685872f, -0.988813400197476f, -0.989768450234042f, -0.990681101884405f,
+ -0.991551316053606f, -0.992379055464567f, -0.993164284659685f, -0.993906970002356f,
+ -0.994607079678411f, -0.995264583697482f, -0.995879453894286f, -0.996451663929828f,
+ -0.996981189292537f, -0.997468007299307f, -0.997912097096476f, -0.998313439660714f,
+ -0.998672017799843f, -0.998987816153568f, -0.999260821194138f, -0.999491021226926f,
+ -0.999678406390929f, -0.999822968659191f, -0.999924701839145f, -0.999983601572879f
+};
+
+const float ivas_cos_twiddle_480[IVAS_480_PT_LEN >> 1] =
+{
+ 0.999999665337326f, 0.999972892444367f, 0.999903284040864f, 0.999790843108610f,
+ 0.999635574464198f, 0.999437484758823f, 0.999196582477986f, 0.998912877941140f,
+ 0.998586383301244f, 0.998217112544241f, 0.997805081488460f, 0.997350307783942f,
+ 0.996852810911678f, 0.996312612182778f, 0.995729734737558f, 0.995104203544548f,
+ 0.994436045399422f, 0.993725288923851f, 0.992971964564277f, 0.992176104590609f,
+ 0.991337743094838f, 0.990456915989581f, 0.989533661006540f, 0.988568017694885f,
+ 0.987560027419562f, 0.986509733359519f, 0.985417180505858f, 0.984282415659908f,
+ 0.983105487431216f, 0.981886446235473f, 0.980625344292344f, 0.979322235623241f,
+ 0.977977176049001f, 0.976590223187499f, 0.975161436451181f, 0.973690877044515f,
+ 0.972178607961371f, 0.970624693982323f, 0.969029201671875f, 0.967392199375607f,
+ 0.965713757217249f, 0.963993947095677f, 0.962232842681832f, 0.960430519415566f,
+ 0.958587054502409f, 0.956702526910263f, 0.954777017366017f, 0.952810608352092f,
+ 0.950803384102905f, 0.948755430601263f, 0.946666835574676f, 0.944537688491606f,
+ 0.942368080557626f, 0.940158104711519f, 0.937907855621296f, 0.935617429680138f,
+ 0.933286925002268f, 0.930916441418752f, 0.928506080473216f, 0.926055945417500f,
+ 0.923566141207236f, 0.921036774497350f, 0.918467953637493f, 0.915859788667400f,
+ 0.913212391312179f, 0.910525874977521f, 0.907800354744844f, 0.905035947366364f,
+ 0.902232771260093f, 0.899390946504765f, 0.896510594834693f, 0.893591839634558f,
+ 0.890634805934118f, 0.887639620402854f, 0.884606411344546f, 0.881535308691775f,
+ 0.878426444000357f, 0.875279950443708f, 0.872095962807140f, 0.868874617482085f,
+ 0.865616052460258f, 0.862320407327736f, 0.858987823258990f, 0.855618443010829f,
+ 0.852212410916289f, 0.848769872878448f, 0.845290976364179f, 0.841775870397828f,
+ 0.838224705554838f, 0.834637633955290f, 0.831014809257393f, 0.827356386650900f,
+ 0.823662522850458f, 0.819933376088899f, 0.816169106110459f, 0.812369874163934f,
+ 0.808535842995778f, 0.804667176843123f, 0.800764041426753f, 0.796826603943998f,
+ 0.792855033061574f, 0.788849498908361f, 0.784810173068109f, 0.780737228572095f,
+ 0.776630839891703f, 0.772491182930959f, 0.768318435018988f, 0.764112774902423f,
+ 0.759874382737746f, 0.755603440083571f, 0.751300129892866f, 0.746964636505118f,
+ 0.742597145638433f, 0.738197844381584f, 0.733766921185995f, 0.729304565857669f,
+ 0.724810969549055f, 0.720286324750863f, 0.715730825283819f, 0.711144666290356f,
+ 0.706528044226263f, 0.701881156852263f, 0.697204203225545f, 0.692497383691237f,
+ 0.687760899873822f, 0.682994954668502f, 0.678199752232508f, 0.673375497976352f,
+ 0.668522398555031f, 0.663640661859171f, 0.658730497006124f, 0.653792114331011f,
+ 0.648825725377709f, 0.643831542889792f, 0.638809780801415f, 0.633760654228152f,
+ 0.628684379457781f, 0.623581173941019f, 0.618451256282204f, 0.613294846229936f,
+ 0.608112164667659f, 0.602903433604202f, 0.597668876164268f, 0.592408716578875f,
+ 0.587123180175754f, 0.581812493369691f, 0.576476883652835f, 0.571116579584947f,
+ 0.565731810783613f, 0.560322807914407f, 0.554889802681009f, 0.549433027815281f,
+ 0.543952717067296f, 0.538449105195327f, 0.532922427955790f, 0.527372922093143f,
+ 0.521800825329746f, 0.516206376355680f, 0.510589814818519f, 0.504951381313066f,
+ 0.499291317371047f, 0.493609865450762f, 0.487907268926702f, 0.482183772079123f,
+ 0.476439620083580f, 0.470675059000427f, 0.464890335764274f, 0.459085698173413f,
+ 0.453261394879198f, 0.447417675375397f, 0.441554789987504f, 0.435672989862017f,
+ 0.429772526955677f, 0.423853654024676f, 0.417916624613831f, 0.411961693045722f,
+ 0.405989114409798f, 0.399999144551449f, 0.393992040061048f, 0.387968058262959f,
+ 0.381927457204511f, 0.375870495644949f, 0.369797433044349f, 0.363708529552499f,
+ 0.357604045997758f, 0.351484243875885f, 0.345349385338836f, 0.339199733183530f,
+ 0.333035550840599f, 0.326857102363098f, 0.320664652415198f, 0.314458466260842f,
+ 0.308238809752391f, 0.302005949319228f, 0.295760151956351f, 0.289501685212929f,
+ 0.283230817180850f, 0.276947816483228f, 0.270652952262902f, 0.264346494170904f,
+ 0.258028712354909f, 0.251699877447663f, 0.245360260555389f, 0.239010133246176f,
+ 0.232649767538342f, 0.226279435888785f, 0.219899411181310f, 0.213509966714943f,
+ 0.207111376192219f, 0.200703913707458f, 0.194287853735029f, 0.187863471117585f,
+ 0.181431041054297f, 0.174990839089060f, 0.168543141098691f, 0.162088223281113f,
+ 0.155626362143520f, 0.149157834490539f, 0.142682917412363f, 0.136201888272891f,
+ 0.129715024697841f, 0.123222604562857f, 0.116724905981611f, 0.110222207293883f,
+ 0.103714787053643f, 0.0972029240171147f, 0.0906868971308382f, 0.0841669855197180f,
+ 0.0776434684750678f, 0.0711166254426455f, 0.0645867360106837f, 0.0580540798979125f,
+ 0.0515189369415777f, 0.0449815870854525f, 0.0384423103678466f, 0.0319013869096108f,
+ 0.0253590969021360f, 0.0188157205953513f, 0.0122715382857199f, 0.00572683030423125f
+};
+
+const float ivas_sin_twiddle_320[IVAS_320_PT_LEN >> 1] =
+{
+ -0.00122718432228885f, -0.0110444371277961f, -0.0208606254474658f, -0.0306748031766366f,
+ -0.0404860244044325f, -0.0502933435049309f, -0.0600958152283046f, -0.0698924947919266f,
+ -0.0796824379714301f, -0.0894647011917154f, -0.0992383416178931f, -0.109002417246156f,
+ -0.118755986994574f, -0.128498110793793f, -0.138227849677645f, -0.147944265873646f,
+ -0.157646422893378f, -0.167333385622756f, -0.177004220412149f, -0.186657995166372f,
+ -0.196293779434521f, -0.205910644499654f, -0.215507663468299f, -0.225083911359793f,
+ -0.234638465195433f, -0.244170404087435f, -0.253678809327687f, -0.263162764476304f,
+ -0.272621355449949f, -0.282053670609936f, -0.291458800850100f, -0.300835839684411f,
+ -0.310183883334351f, -0.319502030816016f, -0.328789384026957f, -0.338045047832741f,
+ -0.347268130153228f, -0.356457742048546f, -0.365612997804774f, -0.374733015019307f,
+ -0.383816914685905f, -0.392863821279410f, -0.401872862840135f, -0.410843171057904f,
+ -0.419773881355741f, -0.428664132973198f, -0.437513069049322f, -0.446319836705237f,
+ -0.455083587126344f, -0.463803475644138f, -0.472478661817616f, -0.481108309514277f,
+ -0.489691586990715f, -0.498227666972782f, -0.506715726735323f, -0.515154948181472f,
+ -0.523544517921500f, -0.531883627351215f, -0.540171472729893f, -0.548407255257747f,
+ -0.556590181152914f, -0.564719461727967f, -0.572794313465923f, -0.580813958095765f,
+ -0.588777622667452f, -0.596684539626417f, -0.604533946887548f, -0.612325087908634f,
+ -0.620057211763289f, -0.627729573213322f, -0.635341432780567f, -0.642892056818157f,
+ -0.650380717581231f, -0.657806693297079f, -0.665169268234704f, -0.672467732773812f,
+ -0.679701383473197f, -0.686869523138552f, -0.693971460889654f, -0.701006512226963f,
+ -0.707973999097587f, -0.714873249960641f, -0.721703599851967f, -0.728464390448225f,
+ -0.735154970130347f, -0.741774694046338f, -0.748322924173428f, -0.754799029379569f,
+ -0.761202385484262f, -0.767532375318718f, -0.773788388785342f, -0.779969822916534f,
+ -0.786076081932809f, -0.792106577300212f, -0.798060727787049f, -0.803937959519903f,
+ -0.809737706038947f, -0.815459408352540f, -0.821102514991105f, -0.826666482060278f,
+ -0.832150773293332f, -0.837554860102865f, -0.842878221631741f, -0.848120344803297f,
+ -0.853280724370791f, -0.858358862966099f, -0.863354271147654f, -0.868266467447619f,
+ -0.873094978418290f, -0.877839338677730f, -0.882499090954623f, -0.887073786132345f,
+ -0.891562983292255f, -0.895966249756185f, -0.900283161128150f, -0.904513301335247f,
+ -0.908656262667757f, -0.912711645818445f, -0.916679059921043f, -0.920558122587921f,
+ -0.924348459946945f, -0.928049706677513f, -0.931661506045761f, -0.935183509938948f,
+ -0.938615378899008f, -0.941956782155269f, -0.945207397656329f, -0.948366912101102f,
+ -0.951435020969008f, -0.954411428549330f, -0.957295847969710f, -0.960088001223801f,
+ -0.962787619198060f, -0.965394441697689f, -0.967908217471710f, -0.970328704237180f,
+ -0.972655668702548f, -0.974888886590136f, -0.977028142657754f, -0.979073230719452f,
+ -0.981023953665385f, -0.982880123480816f, -0.984641561264233f, -0.986308097244599f,
+ -0.987879570797705f, -0.989355830461661f, -0.990736733951487f, -0.992022148172831f,
+ -0.993211949234795f, -0.994306022461875f, -0.995304262405018f, -0.996206572851780f,
+ -0.997012866835602f, -0.997723066644192f, -0.998337103827013f, -0.998854919201885f,
+ -0.999276462860683f, -0.999601694174153f, -0.999830581795823f, -0.999963103665029f
+};
+
+const float ivas_cos_twiddle_320[IVAS_320_PT_LEN >> 1] =
+{
+ 0.999999247009036f, 0.999939008344274f, 0.999782393476671f, 0.999529417501093f,
+ 0.999180104799892f, 0.998734489040553f, 0.998192613172451f, 0.997554529422708f,
+ 0.996820299291166f, 0.995989993544452f, 0.995063692209162f, 0.994041484564148f,
+ 0.992923469131909f, 0.991709753669100f, 0.990400455156143f, 0.988995699785954f,
+ 0.987495622951779f, 0.985900369234146f, 0.984210092386929f, 0.982424955322528f,
+ 0.980545130096168f, 0.978570797889318f, 0.976502148992226f, 0.974339382785576f,
+ 0.972082707721278f, 0.969732341302371f, 0.967288510062064f, 0.964751449541896f,
+ 0.962121404269042f, 0.959398627732738f, 0.956583382359856f, 0.953675939489602f,
+ 0.950676579347373f, 0.947585591017741f, 0.944403272416596f, 0.941129930262426f,
+ 0.937765880046764f, 0.934311446003768f, 0.930766961078984f, 0.927132766897244f,
+ 0.923409213729749f, 0.919596660460302f, 0.915695474550723f, 0.911706032005430f,
+ 0.907628717335198f, 0.903463923520102f, 0.899212051971637f, 0.894873512494035f,
+ 0.890448723244758f, 0.885938110694205f, 0.881342109584601f, 0.876661162888100f,
+ 0.871895721764085f, 0.867046245515693f, 0.862113201545536f, 0.857097065310660f,
+ 0.851998320276715f, 0.846817457871361f, 0.841554977436898f, 0.836211386182145f,
+ 0.830787199133548f, 0.825282939085545f, 0.819699136550175f, 0.814036329705948f,
+ 0.808295064345975f, 0.802475893825360f, 0.796579379007870f, 0.790606088211875f,
+ 0.784556597155575f, 0.778431488901510f, 0.772231353800360f, 0.765956789434051f,
+ 0.759608400558158f, 0.753186799043613f, 0.746692603817734f, 0.740126440804576f,
+ 0.733488942864595f, 0.726780749733659f, 0.720002507961382f, 0.713154870848815f,
+ 0.706238498385475f, 0.699254057185735f, 0.692202220424575f, 0.685083667772700f,
+ 0.677899085331031f, 0.670649165564576f, 0.663334607235692f, 0.655956115336735f,
+ 0.648514401022112f, 0.641010181539737f, 0.633444180161903f, 0.625817126115569f,
+ 0.618129754512079f, 0.610382806276310f, 0.602577028075254f, 0.594713172246063f,
+ 0.586791996723527f, 0.578814264967032f, 0.570780745886967f, 0.562692213770623f,
+ 0.554549448207560f, 0.546353234014470f, 0.538104361159537f, 0.529803624686295f,
+ 0.521451824637002f, 0.513049765975530f, 0.504598258509780f, 0.496098116813633f,
+ 0.487550160148436f, 0.478955212384045f, 0.470314101919413f, 0.461627661602753f,
+ 0.452896728651262f, 0.444122144570429f, 0.435304755072932f, 0.426445409997122f,
+ 0.417544963225117f, 0.408604272600502f, 0.399624199845647f, 0.390605610478656f,
+ 0.381549373729942f, 0.372456362458452f, 0.363327453067539f, 0.354163525420491f,
+ 0.344965462755725f, 0.335734151601668f, 0.326470481691301f, 0.317175345876411f,
+ 0.307849640041535f, 0.298494263017610f, 0.289110116495347f, 0.279698104938318f,
+ 0.270259135495788f, 0.260794117915276f, 0.251303964454877f, 0.241789589795333f,
+ 0.232251910951879f, 0.222691847185850f, 0.213110319916091f, 0.203508252630144f,
+ 0.193886570795236f, 0.184246201769091f, 0.174588074710540f, 0.164913120489970f,
+ 0.155222271599607f, 0.145516462063635f, 0.135796627348180f, 0.126063704271142f,
+ 0.116318630911905f, 0.106562346520921f, 0.0967957914291864f, 0.0870199069576083f,
+ 0.0772356353262796f, 0.0674439195636641f, 0.0576457034157070f, 0.0478419312548745f,
+ 0.0380335479891316f, 0.0282214989708730f, 0.0184067299058048f, 0.00859018676179777f
+};
+
+const float ivas_sin_twiddle_160[IVAS_160_PT_LEN >> 1] =
+{
+ -0.00245436679646029f, -0.0220875270185783f, -0.0417121720785753f, -0.0613207363022086f,
+ -0.0809056602147038f, -0.100459393455076f, -0.119974397686940f, -0.139443149504679f,
+ -0.158858143333861f, -0.178211894324786f, -0.197496941238030f, -0.216705849320900f,
+ -0.235831213173673f, -0.254865659604515f, -0.273801850471989f, -0.292632485514050f,
+ -0.311350305162432f, -0.329948093341349f, -0.348418680249435f, -0.366754945123831f,
+ -0.384949818985382f, -0.402996287363860f, -0.420887393002174f, -0.438616238538528f,
+ -0.456175989165483f, -0.473559875264908f, -0.490761195017794f, -0.507773316987935f,
+ -0.524589682678469f, -0.541203809060310f, -0.557609291071472f, -0.573799804086349f,
+ -0.589769106353971f, -0.605511041404326f, -0.621019540421789f, -0.636288624584773f,
+ -0.651312407370671f, -0.666085096825230f, -0.680600997795453f, -0.694854514125194f,
+ -0.708840150812579f, -0.722552516128436f, -0.735986323694910f, -0.749136394523459f,
+ -0.761997659011457f, -0.774565158896617f, -0.786834049168500f, -0.798799599936358f,
+ -0.810457198252595f, -0.821802349891147f, -0.832830681080094f, -0.843537940187827f,
+ -0.853919999362139f, -0.863972856121587f, -0.873692634898524f, -0.883075588533209f,
+ -0.892118099718401f, -0.900816682393908f, -0.909167983090522f, -0.917168782222852f,
+ -0.924815995330528f, -0.932106674267327f, -0.939038008337734f, -0.945607325380521f,
+ -0.951812092798916f, -0.957649918536965f, -0.963118552001719f, -0.968215884930876f,
+ -0.972939952205560f, -0.977288932607910f, -0.981261149523195f, -0.984855071586178f,
+ -0.988069313271492f, -0.990902635427780f, -0.993353945755417f, -0.995422299227608f,
+ -0.997106898454717f, -0.998407093991674f, -0.999322384588350f, -0.999852417382795f
+};
+
+const float ivas_cos_twiddle_160[IVAS_160_PT_LEN >> 1] =
+{
+ 0.999996988037278f, 0.999756040817060f, 0.999129668611881f, 0.998118112900149f,
+ 0.996721763655847f, 0.994941159198190f, 0.992776985984091f, 0.990230078343521f,
+ 0.987301418157858f, 0.983992134481354f, 0.980303503105861f, 0.976236946068990f,
+ 0.971794031105889f, 0.966976471044852f, 0.961786123146989f, 0.956224988390216f,
+ 0.950295210697844f, 0.943999076112052f, 0.937339011912575f, 0.930317585680942f,
+ 0.922937504310623f, 0.915201612963474f, 0.907112893972869f, 0.898674465693954f,
+ 0.889889581301463f, 0.880761627535558f, 0.871294123396174f, 0.861490718786378f,
+ 0.851355193105265f, 0.840891453790923f, 0.830103534814044f, 0.818995595122750f,
+ 0.807571917039244f, 0.795836904608884f, 0.783795081902349f, 0.771451091271519f,
+ 0.758809691559762f, 0.745875756267305f, 0.732654271672413f, 0.719150334909079f,
+ 0.705369152001986f, 0.691316035859480f, 0.676996404225349f, 0.662415777590172f,
+ 0.647579777063073f, 0.632494122204673f, 0.617164628822086f, 0.601597206726822f,
+ 0.585797857456439f, 0.569772671960834f, 0.553527828254070f, 0.537069589032630f,
+ 0.520404299261031f, 0.503538383725718f, 0.486478344558187f, 0.469230758728290f,
+ 0.451802275508688f, 0.434199613911428f, 0.416429560097637f, 0.398498964761330f,
+ 0.380414740488332f, 0.362183859091351f, 0.343813348922205f, 0.325310292162263f,
+ 0.306681822092128f, 0.287935120341621f, 0.269077414121127f, 0.250115973435366f,
+ 0.231058108280671f, 0.211911165826842f, 0.192682527584672f, 0.173379606560240f,
+ 0.154009844397046f, 0.134580708507126f, 0.115099689192216f, 0.0955742967560992f,
+ 0.0760120586092433f, 0.0564205163668375f, 0.0368072229413588f, 0.0171797396307788f
+};
+
+const float ivas_mdft_coeff_cos_twid_120[IVAS_120_PT_LEN + 1] =
+{
+ 1.0000000000f, 0.9999143276f, 0.9996573250f, 0.9992290362f, 0.9986295348f, 0.9978589232f, 0.9969173337f,
+ 0.9958049276f, 0.9945218954f, 0.9930684570f, 0.9914448614f, 0.9896513868f, 0.9876883406f, 0.9855560591f,
+ 0.9832549076f, 0.9807852804f, 0.9781476007f, 0.9753423205f, 0.9723699204f, 0.9692309097f, 0.9659258263f,
+ 0.9624552365f, 0.9588197349f, 0.9550199445f, 0.9510565163f, 0.9469301295f, 0.9426414911f, 0.9381913359f,
+ 0.9335804265f, 0.9288095529f, 0.9238795325f, 0.9187912101f, 0.9135454576f, 0.9081431738f, 0.9025852843f,
+ 0.8968727415f, 0.8910065242f, 0.8849876375f, 0.8788171127f, 0.8724960071f, 0.8660254038f, 0.8594064115f,
+ 0.8526401644f, 0.8457278217f, 0.8386705679f, 0.8314696123f, 0.8241261886f, 0.8166415552f, 0.8090169944f,
+ 0.8012538127f, 0.7933533403f, 0.7853169309f, 0.7771459615f, 0.7688418321f, 0.7604059656f, 0.7518398075f,
+ 0.7431448255f, 0.7343225094f, 0.7253743710f, 0.7163019434f, 0.7071067812f, 0.6977904598f, 0.6883545757f,
+ 0.6788007455f, 0.6691306064f, 0.6593458151f, 0.6494480483f, 0.6394390020f, 0.6293203910f, 0.6190939493f,
+ 0.6087614290f, 0.5983246006f, 0.5877852523f, 0.5771451900f, 0.5664062369f, 0.5555702330f, 0.5446390350f,
+ 0.5336145159f, 0.5224985647f, 0.5112930861f, 0.5000000000f, 0.4886212415f, 0.4771587603f, 0.4656145203f,
+ 0.4539904997f, 0.4422886902f, 0.4305110968f, 0.4186597375f, 0.4067366431f, 0.3947438564f, 0.3826834324f,
+ 0.3705574375f, 0.3583679495f, 0.3461170571f, 0.3338068592f, 0.3214394653f, 0.3090169944f, 0.2965415750f,
+ 0.2840153447f, 0.2714404499f, 0.2588190451f, 0.2461532930f, 0.2334453639f, 0.2206974350f, 0.2079116908f,
+ 0.1950903220f, 0.1822355255f, 0.1693495038f, 0.1564344650f, 0.1434926220f, 0.1305261922f, 0.1175373975f,
+ 0.1045284633f, 0.0915016187f, 0.0784590957f, 0.0654031292f, 0.0523359562f, 0.0392598158f, 0.0261769483f,
+ 0.0130895956f, 0.0000000000f
+};
+
+const float ivas_sin_twiddle_80[IVAS_80_PT_LEN >> 1] =
+{
+ -0.00490871880799799f, -0.0441642771270674f, -0.0833517373318975f, -0.122410675199216f,
+ -0.161280864677880f, -0.199902370753082f, -0.238215641861795f, -0.276161601716971f,
+ -0.313681740398891f, -0.350718204573223f, -0.387213886696666f, -0.423112513072644f,
+ -0.458358730621271f, -0.492898192229784f, -0.526677640551852f, -0.559644990126546f,
+ -0.591749407690343f, -0.622941390558334f, -0.653172842953777f, -0.682397150168297f,
+ -0.710569250438390f, -0.737645704427393f, -0.763584762205797f, -0.788346427626606f,
+ -0.811892519996505f, -0.834186732947712f, -0.855194690419775f, -0.874883999664958f,
+ -0.893224301195515f, -0.910187315595818f, -0.925746887127164f, -0.939879024058033f,
+ -0.952561935657595f, -0.963776065795440f, -0.973504123095711f, -0.981731107599154f,
+ -0.988444333891970f, -0.993633450665799f, -0.997290456678690f, -0.999409713092437f
+};
+
+const float ivas_cos_twiddle_80[IVAS_80_PT_LEN >> 1] =
+{
+ 0.999987952167257f, 0.999024282300407f, 0.996520189400975f, 0.992479534598710f,
+ 0.986908548290446f, 0.979815820533276f, 0.971212287799312f, 0.961111216112432f,
+ 0.949528180593037f, 0.936481041442343f, 0.921989916403245f, 0.906077149740215f,
+ 0.888767277786068f, 0.870086991108712f, 0.850065093356229f, 0.828732456843738f,
+ 0.806121974950521f, 0.782268511400816f, 0.757208846506485f, 0.730981620454432f,
+ 0.703627273726243f, 0.675187984741891f, 0.645707604823667f, 0.615231590580627f,
+ 0.583806933817786f, 0.551482089078169f, 0.518306898929413f, 0.484332517110141f,
+ 0.449611329654607f, 0.414196874117224f, 0.378143757021541f, 0.341507569660936f,
+ 0.304344802380877f, 0.266712757474898f, 0.228669460828619f, 0.190273572448036f,
+ 0.151584296010041f, 0.112661287574648f, 0.0735645635996675f, 0.0343544083996823f
+};
+
+const int16_t dirac_gains_P_idx[16] =
+{
+ -1, 1, 0, 1, 4, 3, 2, 3, 4, 8, 7, 6, 5, 6, 7, 8
+};
+
+const float dirac_gains_norm_term[9] =
+{
+ 1.000000e+00f, 7.071068e-01f, 1.000000e+00f, 4.082483e-01f, 2.041242e-01f, 1.000000e+00f, 2.886751e-01f, 9.128709e-02f, 3.726780e-02f
+};
+
+const float dirac_gains_Pnm[91][9] =
+{
+ {-1.000000e+00f,-0.000000e+00f,1.000000e+00f,-0.000000e+00f,0.000000e+00f,-1.000000e+00f,-0.000000e+00f,0.000000e+00f,-0.000000e+00f},
+ {-9.998477e-01f,1.745221e-02f,9.995431e-01f,-5.234867e-02f,9.137391e-04f,-9.990864e-01f,1.046734e-01f,-4.568000e-03f,7.973384e-05f},
+ {-9.993909e-01f,3.489930e-02f,9.981732e-01f,-1.046341e-01f,3.653884e-03f,-9.963478e-01f,2.090770e-01f,-1.825829e-02f,6.375900e-04f},
+ {-9.986295e-01f,5.233614e-02f,9.958913e-01f,-1.567932e-01f,8.217215e-03f,-9.917910e-01f,3.129416e-01f,-4.102976e-02f,2.150287e-03f},
+ {-9.975641e-01f,6.975590e-02f,9.927012e-01f,-2.087579e-01f,1.459766e-02f,-9.854290e-01f,4.159897e-01f,-7.281048e-02f,5.091363e-03f},
+ {-9.961947e-01f,8.715547e-02f,9.886059e-01f,-2.604715e-01f,2.278823e-02f,-9.772766e-01f,5.179674e-01f,-1.135075e-01f,9.930593e-03f},
+ {-9.945220e-01f,1.045284e-01f,9.836106e-01f,-3.118673e-01f,3.277856e-02f,-9.673560e-01f,6.186047e-01f,-1.629950e-01f,1.713145e-02f},
+ {-9.925461e-01f,1.218695e-01f,9.777218e-01f,-3.628832e-01f,4.455650e-02f,-9.556924e-01f,7.176415e-01f,-2.211219e-01f,2.715038e-02f},
+ {-9.902681e-01f,1.391732e-01f,9.709461e-01f,-4.134564e-01f,5.810756e-02f,-9.423163e-01f,8.148217e-01f,-2.877103e-01f,4.043508e-02f},
+ {-9.876884e-01f,1.564343e-01f,9.632925e-01f,-4.635251e-01f,7.341509e-02f,-9.272624e-01f,9.098945e-01f,-3.625562e-01f,5.742321e-02f},
+ {-9.848077e-01f,1.736484e-01f,9.547693e-01f,-5.130307e-01f,9.046126e-02f,-9.105685e-01f,1.002619e+00f,-4.454347e-01f,7.854224e-02f},
+ {-9.816272e-01f,1.908091e-01f,9.453878e-01f,-5.619103e-01f,1.092244e-01f,-8.922793e-01f,1.092752e+00f,-5.360881e-01f,1.042050e-01f},
+ {-9.781475e-01f,2.079115e-01f,9.351591e-01f,-6.101044e-01f,1.296816e-01f,-8.724410e-01f,1.180063e+00f,-6.342387e-01f,1.348115e-01f},
+ {-9.743701e-01f,2.249510e-01f,9.240957e-01f,-6.575567e-01f,1.518089e-01f,-8.511051e-01f,1.264332e+00f,-7.395903e-01f,1.707479e-01f},
+ {-9.702957e-01f,2.419219e-01f,9.122107e-01f,-7.042075e-01f,1.755787e-01f,-8.283265e-01f,1.345341e+00f,-8.518162e-01f,2.123816e-01f},
+ {-9.659258e-01f,2.588191e-01f,8.995191e-01f,-7.500002e-01f,2.009620e-01f,-8.041639e-01f,1.422883e+00f,-9.705719e-01f,2.600640e-01f},
+ {-9.612616e-01f,2.756374e-01f,8.860360e-01f,-7.948789e-01f,2.279279e-01f,-7.786796e-01f,1.496760e+00f,-1.095492e+00f,3.141272e-01f},
+ {-9.563048e-01f,2.923716e-01f,8.717782e-01f,-8.387891e-01f,2.564435e-01f,-7.519395e-01f,1.566788e+00f,-1.226191e+00f,3.748840e-01f},
+ {-9.510565e-01f,3.090171e-01f,8.567626e-01f,-8.816782e-01f,2.864747e-01f,-7.240118e-01f,1.632789e+00f,-1.362268e+00f,4.426280e-01f},
+ {-9.455186e-01f,3.255681e-01f,8.410082e-01f,-9.234920e-01f,3.179837e-01f,-6.949692e-01f,1.694595e+00f,-1.503298e+00f,5.176268e-01f},
+ {-9.396926e-01f,3.420202e-01f,8.245332e-01f,-9.641815e-01f,3.509334e-01f,-6.648846e-01f,1.752055e+00f,-1.648848e+00f,6.001316e-01f},
+ {-9.335804e-01f,3.583678e-01f,8.073587e-01f,-1.003696e+00f,3.852825e-01f,-6.338369e-01f,1.805025e+00f,-1.798461e+00f,6.903643e-01f},
+ {-9.271840e-01f,3.746064e-01f,7.895051e-01f,-1.041987e+00f,4.209899e-01f,-6.019047e-01f,1.853375e+00f,-1.951675e+00f,7.885275e-01f},
+ {-9.205049e-01f,3.907311e-01f,7.709939e-01f,-1.079010e+00f,4.580124e-01f,-5.691693e-01f,1.896987e+00f,-2.108013e+00f,8.947984e-01f},
+ {-9.135456e-01f,4.067366e-01f,7.518480e-01f,-1.114717e+00f,4.963039e-01f,-5.357154e-01f,1.935757e+00f,-2.266981e+00f,1.009325e+00f},
+ {-9.063079e-01f,4.226184e-01f,7.320906e-01f,-1.149067e+00f,5.358188e-01f,-5.016273e-01f,1.969593e+00f,-2.428084e+00f,1.132234e+00f},
+ {-8.987941e-01f,4.383712e-01f,7.117461e-01f,-1.182016e+00f,5.765077e-01f,-4.669925e-01f,1.998415e+00f,-2.590808e+00f,1.263622e+00f},
+ {-8.910065e-01f,4.539906e-01f,6.908387e-01f,-1.213526e+00f,6.183225e-01f,-4.318987e-01f,2.022162e+00f,-2.754647e+00f,1.403563e+00f},
+ {-8.829476e-01f,4.694716e-01f,6.693946e-01f,-1.243556e+00f,6.612108e-01f,-3.964354e-01f,2.040781e+00f,-2.919073e+00f,1.552099e+00f},
+ {-8.746198e-01f,4.848095e-01f,6.474397e-01f,-1.272072e+00f,7.051207e-01f,-3.606927e-01f,2.054234e+00f,-3.083563e+00f,1.709246e+00f},
+ {-8.660253e-01f,5.000000e-01f,6.250001e-01f,-1.299038e+00f,7.500000e-01f,-3.247595e-01f,2.062500e+00f,-3.247595e+00f,1.875000e+00f},
+ {-8.571672e-01f,5.150381e-01f,6.021037e-01f,-1.324421e+00f,7.957926e-01f,-2.887278e-01f,2.065570e+00f,-3.410637e+00f,2.049318e+00f},
+ {-8.480480e-01f,5.299194e-01f,5.787782e-01f,-1.348191e+00f,8.424437e-01f,-2.526874e-01f,2.063448e+00f,-3.572164e+00f,2.232136e+00f},
+ {-8.386706e-01f,5.446391e-01f,5.550525e-01f,-1.370318e+00f,8.898951e-01f,-2.167299e-01f,2.056155e+00f,-3.731644e+00f,2.423358e+00f},
+ {-8.290377e-01f,5.591928e-01f,5.309552e-01f,-1.390776e+00f,9.380897e-01f,-1.809446e-01f,2.043725e+00f,-3.888559e+00f,2.622865e+00f},
+ {-8.191521e-01f,5.735765e-01f,5.065152e-01f,-1.409539e+00f,9.869699e-01f,-1.454202e-01f,2.026202e+00f,-4.042392e+00f,2.830513e+00f},
+ {-8.090171e-01f,5.877852e-01f,4.817629e-01f,-1.426585e+00f,1.036474e+00f,-1.102460e-01f,2.003651e+00f,-4.192627e+00f,3.046121e+00f},
+ {-7.986355e-01f,6.018150e-01f,4.567280e-01f,-1.441893e+00f,1.086544e+00f,-7.550830e-02f,1.976144e+00f,-4.338763e+00f,3.269493e+00f},
+ {-7.880108e-01f,6.156614e-01f,4.314414e-01f,-1.455444e+00f,1.137117e+00f,-4.129366e-02f,1.943771e+00f,-4.480302e+00f,3.500396e+00f},
+ {-7.771459e-01f,6.293205e-01f,4.059335e-01f,-1.467221e+00f,1.188133e+00f,-7.685401e-03f,1.906632e+00f,-4.616763e+00f,3.738582e+00f},
+ {-7.660444e-01f,6.427876e-01f,3.802360e-01f,-1.477211e+00f,1.239528e+00f,2.523343e-02f,1.864843e+00f,-4.747667e+00f,3.983766e+00f},
+ {-7.547096e-01f,6.560589e-01f,3.543800e-01f,-1.485402e+00f,1.291240e+00f,5.738307e-02f,1.818529e+00f,-4.872555e+00f,4.235647e+00f},
+ {-7.431449e-01f,6.691306e-01f,3.283964e-01f,-1.491783e+00f,1.343207e+00f,8.868646e-02f,1.767831e+00f,-4.990988e+00f,4.493906e+00f},
+ {-7.313538e-01f,6.819984e-01f,3.023174e-01f,-1.496346e+00f,1.395365e+00f,1.190676e-01f,1.712898e+00f,-5.102528e+00f,4.758184e+00f},
+ {-7.193397e-01f,6.946585e-01f,2.761744e-01f,-1.499086e+00f,1.447651e+00f,1.484544e-01f,1.653893e+00f,-5.206765e+00f,5.028115e+00f},
+ {-7.071068e-01f,7.071068e-01f,2.500000e-01f,-1.500000e+00f,1.500000e+00f,1.767767e-01f,1.590990e+00f,-5.303301e+00f,5.303301e+00f},
+ {-6.946585e-01f,7.193397e-01f,2.238256e-01f,-1.499086e+00f,1.552349e+00f,2.039685e-01f,1.524373e+00f,-5.391762e+00f,5.583331e+00f},
+ {-6.819984e-01f,7.313538e-01f,1.976825e-01f,-1.496346e+00f,1.604635e+00f,2.299670e-01f,1.454233e+00f,-5.471792e+00f,5.867779e+00f},
+ {-6.691307e-01f,7.431448e-01f,1.716038e-01f,-1.491783e+00f,1.656792e+00f,2.547115e-01f,1.380777e+00f,-5.543053e+00f,6.156183e+00f},
+ {-6.560589e-01f,7.547096e-01f,1.456200e-01f,-1.485402e+00f,1.708760e+00f,2.781472e-01f,1.304214e+00f,-5.605237e+00f,6.448089e+00f},
+ {-6.427876e-01f,7.660444e-01f,1.197639e-01f,-1.477212e+00f,1.760472e+00f,3.002205e-01f,1.224767e+00f,-5.658049e+00f,6.743000e+00f},
+ {-6.293203e-01f,7.771461e-01f,9.406608e-02f,-1.467221e+00f,1.811868e+00f,3.208840e-01f,1.142662e+00f,-5.701226e+00f,7.040430e+00f},
+ {-6.156614e-01f,7.880108e-01f,6.855855e-02f,-1.455444e+00f,1.862883e+00f,3.400929e-01f,1.058135e+00f,-5.734527e+00f,7.339859e+00f},
+ {-6.018151e-01f,7.986354e-01f,4.327216e-02f,-1.441893e+00f,1.913455e+00f,3.578070e-01f,9.714287e-01f,-5.757732e+00f,7.640767e+00f},
+ {-5.877852e-01f,8.090171e-01f,1.823708e-02f,-1.426585e+00f,1.963526e+00f,3.739910e-01f,8.827875e-01f,-5.770657e+00f,7.942629e+00f},
+ {-5.735764e-01f,8.191520e-01f,-6.515074e-03f,-1.409539e+00f,2.013030e+00f,3.886124e-01f,7.924678e-01f,-5.773133e+00f,8.244888e+00f},
+ {-5.591928e-01f,8.290376e-01f,-3.095508e-02f,-1.390776e+00f,2.061910e+00f,4.016449e-01f,7.007229e-01f,-5.765026e+00f,8.547005e+00f},
+ {-5.446391e-01f,8.386706e-01f,-5.505246e-02f,-1.370318e+00f,2.110105e+00f,4.130656e-01f,6.078163e-01f,-5.746228e+00f,8.848414e+00f},
+ {-5.299193e-01f,8.480480e-01f,-7.877823e-02f,-1.348191e+00f,2.157557e+00f,4.228564e-01f,5.140093e-01f,-5.716654e+00f,9.148557e+00f},
+ {-5.150380e-01f,8.571674e-01f,-1.021038e-01f,-1.324421e+00f,2.204208e+00f,4.310043e-01f,4.195672e-01f,-5.676254e+00f,9.446875e+00f},
+ {-5.000001e-01f,8.660253e-01f,-1.249999e-01f,-1.299038e+00f,2.250000e+00f,4.375000e-01f,3.247599e-01f,-5.625000e+00f,9.742785e+00f},
+ {-4.848095e-01f,8.746197e-01f,-1.474395e-01f,-1.272072e+00f,2.294879e+00f,4.423398e-01f,2.298521e-01f,-5.562896e+00f,1.003573e+01f},
+ {-4.694715e-01f,8.829476e-01f,-1.693947e-01f,-1.243556e+00f,2.338789e+00f,4.455244e-01f,1.351145e-01f,-5.489975e+00f,1.032514e+01f},
+ {-4.539906e-01f,8.910065e-01f,-1.908388e-01f,-1.213526e+00f,2.381678e+00f,4.470587e-01f,4.081347e-02f,-5.406296e+00f,1.061045e+01f},
+ {-4.383711e-01f,8.987940e-01f,-2.117461e-01f,-1.182016e+00f,2.423492e+00f,4.469530e-01f,-5.278682e-02f,-5.311945e+00f,1.089110e+01f},
+ {-4.226183e-01f,9.063078e-01f,-2.320906e-01f,-1.149067e+00f,2.464181e+00f,4.452218e-01f,-1.454199e-01f,-5.207041e+00f,1.116653e+01f},
+ {-4.067367e-01f,9.135454e-01f,-2.518479e-01f,-1.114717e+00f,2.503696e+00f,4.418841e-01f,-2.368270e-01f,-5.091725e+00f,1.143620e+01f},
+ {-3.907311e-01f,9.205048e-01f,-2.709937e-01f,-1.079010e+00f,2.541987e+00f,4.369636e-01f,-3.267503e-01f,-4.966168e+00f,1.169956e+01f},
+ {-3.746066e-01f,9.271839e-01f,-2.895049e-01f,-1.041988e+00f,2.579010e+00f,4.304885e-01f,-4.149371e-01f,-4.830570e+00f,1.195608e+01f},
+ {-3.583679e-01f,9.335804e-01f,-3.073587e-01f,-1.003696e+00f,2.614717e+00f,4.224911e-01f,-5.011396e-01f,-4.685155e+00f,1.220525e+01f},
+ {-3.420201e-01f,9.396927e-01f,-3.245333e-01f,-9.641814e-01f,2.649067e+00f,4.130083e-01f,-5.851153e-01f,-4.530170e+00f,1.244654e+01f},
+ {-3.255681e-01f,9.455186e-01f,-3.410081e-01f,-9.234920e-01f,2.682016e+00f,4.020810e-01f,-6.666291e-01f,-4.365895e+00f,1.267948e+01f},
+ {-3.090170e-01f,9.510564e-01f,-3.567626e-01f,-8.816779e-01f,2.713525e+00f,3.897543e-01f,-7.454509e-01f,-4.192628e+00f,1.290358e+01f},
+ {-2.923717e-01f,9.563047e-01f,-3.717781e-01f,-8.387894e-01f,2.743556e+00f,3.760769e-01f,-8.213612e-01f,-4.010692e+00f,1.311838e+01f},
+ {-2.756374e-01f,9.612617e-01f,-3.860361e-01f,-7.948790e-01f,2.772072e+00f,3.611015e-01f,-8.941467e-01f,-3.820433e+00f,1.332343e+01f},
+ {-2.588190e-01f,9.659258e-01f,-3.995190e-01f,-7.499999e-01f,2.799038e+00f,3.448846e-01f,-9.636030e-01f,-3.622222e+00f,1.351832e+01f},
+ {-2.419219e-01f,9.702957e-01f,-4.122107e-01f,-7.042072e-01f,2.824421e+00f,3.274858e-01f,-1.029536e+00f,-3.416446e+00f,1.370262e+01f},
+ {-2.249510e-01f,9.743701e-01f,-4.240956e-01f,-6.575566e-01f,2.848191e+00f,3.089685e-01f,-1.091760e+00f,-3.203517e+00f,1.387596e+01f},
+ {-2.079118e-01f,9.781476e-01f,-4.351591e-01f,-6.101051e-01f,2.870318e+00f,2.893990e-01f,-1.150101e+00f,-2.983865e+00f,1.403797e+01f},
+ {-1.908090e-01f,9.816272e-01f,-4.453879e-01f,-5.619099e-01f,2.890776e+00f,2.688461e-01f,-1.204397e+00f,-2.757931e+00f,1.418832e+01f},
+ {-1.736482e-01f,9.848077e-01f,-4.547695e-01f,-5.130303e-01f,2.909539e+00f,2.473820e-01f,-1.254495e+00f,-2.526181e+00f,1.432668e+01f},
+ {-1.564344e-01f,9.876883e-01f,-4.632923e-01f,-4.635254e-01f,2.926584e+00f,2.250811e-01f,-1.300254e+00f,-2.289093e+00f,1.445277e+01f},
+ {-1.391731e-01f,9.902681e-01f,-4.709463e-01f,-4.134560e-01f,2.941893e+00f,2.020205e-01f,-1.341547e+00f,-2.047161e+00f,1.456631e+01f},
+ {-1.218693e-01f,9.925461e-01f,-4.777218e-01f,-3.628827e-01f,2.955444e+00f,1.782789e-01f,-1.378258e+00f,-1.800889e+00f,1.466707e+01f},
+ {-1.045285e-01f,9.945219e-01f,-4.836107e-01f,-3.118677e-01f,2.967221e+00f,1.539375e-01f,-1.410285e+00f,-1.550796e+00f,1.475483e+01f},
+ {-8.715577e-02f,9.961947e-01f,-4.886058e-01f,-2.604724e-01f,2.977212e+00f,1.290786e-01f,-1.437538e+00f,-1.297406e+00f,1.482941e+01f},
+ {-6.975648e-02f,9.975641e-01f,-4.927011e-01f,-2.087597e-01f,2.985402e+00f,1.037861e-01f,-1.459940e+00f,-1.041256e+00f,1.489065e+01f},
+ {-5.233594e-02f,9.986295e-01f,-4.958915e-01f,-1.567926e-01f,2.991783e+00f,7.814553e-02f,-1.477429e+00f,-7.828888e-01f,1.493841e+01f},
+ {-3.489946e-02f,9.993909e-01f,-4.981730e-01f,-1.046346e-01f,2.996346e+00f,5.224292e-02f,-1.489957e+00f,-5.228543e-01f,1.497260e+01f},
+ {-1.745235e-02f,9.998478e-01f,-4.995431e-01f,-5.234908e-02f,2.999086e+00f,2.616524e-02f,-1.497488e+00f,-2.617055e-01f,1.499315e+01f},
+ {-4.371139e-08f,1.000000e+00f,-5.000000e-01f,-1.311342e-07f,3.000000e+00f,6.556709e-08f,-1.500000e+00f,-6.556709e-07f,1.500000e+01f}
+};
+
+const float dirac_gains_trg_term[181][2] =
+{
+ {-1.000000e+00f,8.742278e-08f},
+ {-9.998477e-01f,-1.745246e-02f},
+ {-9.993908e-01f,-3.489945e-02f},
+ {-9.986295e-01f,-5.233605e-02f},
+ {-9.975641e-01f,-6.975647e-02f},
+ {-9.961947e-01f,-8.715564e-02f},
+ {-9.945219e-01f,-1.045285e-01f},
+ {-9.925461e-01f,-1.218693e-01f},
+ {-9.902681e-01f,-1.391732e-01f},
+ {-9.876884e-01f,-1.564344e-01f},
+ {-9.848077e-01f,-1.736483e-01f},
+ {-9.816272e-01f,-1.908090e-01f},
+ {-9.781476e-01f,-2.079116e-01f},
+ {-9.743701e-01f,-2.249511e-01f},
+ {-9.702957e-01f,-2.419219e-01f},
+ {-9.659258e-01f,-2.588191e-01f},
+ {-9.612617e-01f,-2.756374e-01f},
+ {-9.563048e-01f,-2.923716e-01f},
+ {-9.510565e-01f,-3.090170e-01f},
+ {-9.455186e-01f,-3.255681e-01f},
+ {-9.396926e-01f,-3.420202e-01f},
+ {-9.335805e-01f,-3.583679e-01f},
+ {-9.271839e-01f,-3.746065e-01f},
+ {-9.205049e-01f,-3.907312e-01f},
+ {-9.135455e-01f,-4.067366e-01f},
+ {-9.063078e-01f,-4.226183e-01f},
+ {-8.987941e-01f,-4.383711e-01f},
+ {-8.910065e-01f,-4.539906e-01f},
+ {-8.829476e-01f,-4.694716e-01f},
+ {-8.746198e-01f,-4.848095e-01f},
+ {-8.660254e-01f,-5.000001e-01f},
+ {-8.571673e-01f,-5.150380e-01f},
+ {-8.480480e-01f,-5.299193e-01f},
+ {-8.386706e-01f,-5.446390e-01f},
+ {-8.290377e-01f,-5.591928e-01f},
+ {-8.191521e-01f,-5.735765e-01f},
+ {-8.090171e-01f,-5.877852e-01f},
+ {-7.986355e-01f,-6.018151e-01f},
+ {-7.880108e-01f,-6.156614e-01f},
+ {-7.771459e-01f,-6.293205e-01f},
+ {-7.660444e-01f,-6.427876e-01f},
+ {-7.547097e-01f,-6.560590e-01f},
+ {-7.431448e-01f,-6.691306e-01f},
+ {-7.313537e-01f,-6.819983e-01f},
+ {-7.193397e-01f,-6.946585e-01f},
+ {-7.071068e-01f,-7.071068e-01f},
+ {-6.946585e-01f,-7.193397e-01f},
+ {-6.819983e-01f,-7.313537e-01f},
+ {-6.691307e-01f,-7.431448e-01f},
+ {-6.560590e-01f,-7.547097e-01f},
+ {-6.427876e-01f,-7.660444e-01f},
+ {-6.293203e-01f,-7.771460e-01f},
+ {-6.156614e-01f,-7.880108e-01f},
+ {-6.018151e-01f,-7.986355e-01f},
+ {-5.877852e-01f,-8.090170e-01f},
+ {-5.735765e-01f,-8.191520e-01f},
+ {-5.591928e-01f,-8.290376e-01f},
+ {-5.446391e-01f,-8.386706e-01f},
+ {-5.299193e-01f,-8.480480e-01f},
+ {-5.150380e-01f,-8.571673e-01f},
+ {-5.000001e-01f,-8.660254e-01f},
+ {-4.848095e-01f,-8.746197e-01f},
+ {-4.694716e-01f,-8.829476e-01f},
+ {-4.539906e-01f,-8.910065e-01f},
+ {-4.383711e-01f,-8.987941e-01f},
+ {-4.226183e-01f,-9.063078e-01f},
+ {-4.067367e-01f,-9.135454e-01f},
+ {-3.907312e-01f,-9.205049e-01f},
+ {-3.746066e-01f,-9.271839e-01f},
+ {-3.583679e-01f,-9.335805e-01f},
+ {-3.420201e-01f,-9.396926e-01f},
+ {-3.255681e-01f,-9.455186e-01f},
+ {-3.090170e-01f,-9.510565e-01f},
+ {-2.923717e-01f,-9.563047e-01f},
+ {-2.756374e-01f,-9.612617e-01f},
+ {-2.588190e-01f,-9.659258e-01f},
+ {-2.419219e-01f,-9.702957e-01f},
+ {-2.249510e-01f,-9.743701e-01f},
+ {-2.079117e-01f,-9.781476e-01f},
+ {-1.908090e-01f,-9.816272e-01f},
+ {-1.736482e-01f,-9.848077e-01f},
+ {-1.564344e-01f,-9.876884e-01f},
+ {-1.391731e-01f,-9.902681e-01f},
+ {-1.218693e-01f,-9.925461e-01f},
+ {-1.045285e-01f,-9.945219e-01f},
+ {-8.715577e-02f,-9.961947e-01f},
+ {-6.975648e-02f,-9.975641e-01f},
+ {-5.233594e-02f,-9.986295e-01f},
+ {-3.489946e-02f,-9.993908e-01f},
+ {-1.745235e-02f,-9.998477e-01f},
+ {-4.371139e-08f,-1.000000e+00f},
+ {1.745238e-02f,-9.998477e-01f},
+ {3.489950e-02f,-9.993908e-01f},
+ {5.233597e-02f,-9.986295e-01f},
+ {6.975651e-02f,-9.975641e-01f},
+ {8.715580e-02f,-9.961947e-01f},
+ {1.045284e-01f,-9.945219e-01f},
+ {1.218693e-01f,-9.925461e-01f},
+ {1.391731e-01f,-9.902681e-01f},
+ {1.564345e-01f,-9.876884e-01f},
+ {1.736482e-01f,-9.848077e-01f},
+ {1.908089e-01f,-9.816272e-01f},
+ {2.079117e-01f,-9.781476e-01f},
+ {2.249510e-01f,-9.743701e-01f},
+ {2.419219e-01f,-9.702957e-01f},
+ {2.588191e-01f,-9.659258e-01f},
+ {2.756374e-01f,-9.612617e-01f},
+ {2.923717e-01f,-9.563048e-01f},
+ {3.090170e-01f,-9.510565e-01f},
+ {3.255681e-01f,-9.455186e-01f},
+ {3.420202e-01f,-9.396926e-01f},
+ {3.583680e-01f,-9.335804e-01f},
+ {3.746066e-01f,-9.271839e-01f},
+ {3.907311e-01f,-9.205049e-01f},
+ {4.067366e-01f,-9.135455e-01f},
+ {4.226182e-01f,-9.063078e-01f},
+ {4.383712e-01f,-8.987941e-01f},
+ {4.539905e-01f,-8.910065e-01f},
+ {4.694716e-01f,-8.829476e-01f},
+ {4.848096e-01f,-8.746197e-01f},
+ {5.000000e-01f,-8.660254e-01f},
+ {5.150381e-01f,-8.571673e-01f},
+ {5.299193e-01f,-8.480481e-01f},
+ {5.446390e-01f,-8.386706e-01f},
+ {5.591929e-01f,-8.290375e-01f},
+ {5.735765e-01f,-8.191521e-01f},
+ {5.877852e-01f,-8.090170e-01f},
+ {6.018150e-01f,-7.986355e-01f},
+ {6.156615e-01f,-7.880107e-01f},
+ {6.293204e-01f,-7.771460e-01f},
+ {6.427876e-01f,-7.660444e-01f},
+ {6.560590e-01f,-7.547095e-01f},
+ {6.691306e-01f,-7.431449e-01f},
+ {6.819984e-01f,-7.313537e-01f},
+ {6.946584e-01f,-7.193398e-01f},
+ {7.071068e-01f,-7.071068e-01f},
+ {7.193398e-01f,-6.946584e-01f},
+ {7.313537e-01f,-6.819983e-01f},
+ {7.431448e-01f,-6.691306e-01f},
+ {7.547096e-01f,-6.560590e-01f},
+ {7.660444e-01f,-6.427876e-01f},
+ {7.771460e-01f,-6.293204e-01f},
+ {7.880108e-01f,-6.156615e-01f},
+ {7.986355e-01f,-6.018150e-01f},
+ {8.090170e-01f,-5.877852e-01f},
+ {8.191521e-01f,-5.735765e-01f},
+ {8.290376e-01f,-5.591929e-01f},
+ {8.386706e-01f,-5.446391e-01f},
+ {8.480481e-01f,-5.299193e-01f},
+ {8.571673e-01f,-5.150381e-01f},
+ {8.660254e-01f,-5.000000e-01f},
+ {8.746197e-01f,-4.848096e-01f},
+ {8.829476e-01f,-4.694716e-01f},
+ {8.910065e-01f,-4.539905e-01f},
+ {8.987941e-01f,-4.383712e-01f},
+ {9.063078e-01f,-4.226183e-01f},
+ {9.135454e-01f,-4.067366e-01f},
+ {9.205049e-01f,-3.907311e-01f},
+ {9.271839e-01f,-3.746066e-01f},
+ {9.335804e-01f,-3.583679e-01f},
+ {9.396926e-01f,-3.420201e-01f},
+ {9.455186e-01f,-3.255681e-01f},
+ {9.510565e-01f,-3.090170e-01f},
+ {9.563048e-01f,-2.923717e-01f},
+ {9.612617e-01f,-2.756374e-01f},
+ {9.659258e-01f,-2.588190e-01f},
+ {9.702957e-01f,-2.419219e-01f},
+ {9.743701e-01f,-2.249510e-01f},
+ {9.781476e-01f,-2.079117e-01f},
+ {9.816272e-01f,-1.908090e-01f},
+ {9.848077e-01f,-1.736482e-01f},
+ {9.876884e-01f,-1.564345e-01f},
+ {9.902681e-01f,-1.391731e-01f},
+ {9.925461e-01f,-1.218693e-01f},
+ {9.945219e-01f,-1.045285e-01f},
+ {9.961947e-01f,-8.715574e-02f},
+ {9.975641e-01f,-6.975647e-02f},
+ {9.986295e-01f,-5.233596e-02f},
+ {9.993908e-01f,-3.489950e-02f},
+ {9.998477e-01f,-1.745241e-02f},
+ {1.000000e+00f,0.000000e+00f}
+};
+
+/*----------------------------------------------------------------------------------*
+ * FB ROM tables
+ *----------------------------------------------------------------------------------*/
+
+const float ivas_fb_cf_4ms_48k[IVAS_FB_4MS_48K_SAMP] =
+{
+ 0.0000167330f, 0.0001505907f, 0.0004182700f, 0.0008196995f, 0.0013547717f, 0.0020233432f, 0.0028252351f, 0.0037602327f,
+ 0.0048280857f, 0.0060285082f, 0.0073611788f, 0.0088257407f, 0.0104218019f, 0.0121489350f, 0.0140066776f, 0.0159945324f,
+ 0.0181119671f, 0.0203584149f, 0.0227332744f, 0.0252359097f, 0.0278656508f, 0.0306217938f, 0.0335036006f, 0.0365102998f,
+ 0.0396410864f, 0.0428951221f, 0.0462715360f, 0.0497694239f, 0.0533878494f, 0.0571258438f, 0.0609824063f, 0.0649565044f,
+ 0.0690470742f, 0.0732530206f, 0.0775732174f, 0.0820065080f, 0.0865517057f, 0.0912075934f, 0.0959729248f, 0.1008464240f,
+ 0.1058267862f, 0.1109126781f, 0.1161027381f, 0.1213955767f, 0.1267897769f, 0.1322838945f, 0.1378764585f, 0.1435659718f,
+ 0.1493509111f, 0.1552297276f, 0.1612008475f, 0.1672626721f, 0.1734135785f, 0.1796519200f, 0.1859760265f, 0.1923842047f,
+ 0.1988747391f, 0.2054458921f, 0.2120959043f, 0.2188229954f, 0.2256253644f, 0.2325011901f, 0.2394486317f, 0.2464658292f,
+ 0.2535509039f, 0.2607019590f, 0.2679170800f, 0.2751943352f, 0.2825317763f, 0.2899274389f, 0.2973793430f, 0.3048854936f,
+ 0.3124438810f, 0.3200524817f, 0.3277092588f, 0.3354121622f, 0.3431591298f, 0.3509480875f, 0.3587769500f, 0.3666436213f,
+ 0.3745459953f, 0.3824819564f, 0.3904493799f, 0.3984461328f, 0.4064700741f, 0.4145190556f, 0.4225909225f, 0.4306835136f,
+ 0.4387946624f, 0.4469221974f, 0.4550639426f, 0.4632177182f, 0.4713813414f, 0.4795526264f, 0.4877293857f, 0.4959094302f,
+ 0.5040905698f, 0.5122706143f, 0.5204473736f, 0.5286186586f, 0.5367822818f, 0.5449360574f, 0.5530778026f, 0.5612053376f,
+ 0.5693164864f, 0.5774090775f, 0.5854809444f, 0.5935299259f, 0.6015538672f, 0.6095506201f, 0.6175180436f, 0.6254540047f,
+ 0.6333563787f, 0.6412230500f, 0.6490519125f, 0.6568408702f, 0.6645878378f, 0.6722907412f, 0.6799475183f, 0.6875561190f,
+ 0.6951145064f, 0.7026206570f, 0.7100725611f, 0.7174682237f, 0.7248056648f, 0.7320829200f, 0.7392980410f, 0.7464490961f,
+ 0.7535341708f, 0.7605513683f, 0.7674988099f, 0.7743746356f, 0.7811770046f, 0.7879040957f, 0.7945541079f, 0.8011252609f,
+ 0.8076157953f, 0.8140239735f, 0.8203480800f, 0.8265864215f, 0.8327373279f, 0.8387991525f, 0.8447702724f, 0.8506490889f,
+ 0.8564340282f, 0.8621235415f, 0.8677161055f, 0.8732102231f, 0.8786044233f, 0.8838972619f, 0.8890873219f, 0.8941732138f,
+ 0.8991535760f, 0.9040270752f, 0.9087924066f, 0.9134482943f, 0.9179934920f, 0.9224267826f, 0.9267469794f, 0.9309529258f,
+ 0.9350434956f, 0.9390175937f, 0.9428741562f, 0.9466121506f, 0.9502305761f, 0.9537284640f, 0.9571048779f, 0.9603589136f,
+ 0.9634897002f, 0.9664963994f, 0.9693782062f, 0.9721343492f, 0.9747640903f, 0.9772667256f, 0.9796415851f, 0.9818880329f,
+ 0.9840054676f, 0.9859933224f, 0.9878510650f, 0.9895781981f, 0.9911742593f, 0.9926388212f, 0.9939714918f, 0.9951719143f,
+ 0.9962397673f, 0.9971747649f, 0.9979766568f, 0.9986452283f, 0.9991803005f, 0.9995817300f, 0.9998494093f, 0.9999832670f,
+};
+
+const float ivas_fb_cf_4ms_32k[IVAS_FB_4MS_32K_SAMP] =
+{
+ 0.0000376491f, 0.0003388077f, 0.0009409435f, 0.0018436939f, 0.0030465150f, 0.0045486823f, 0.0063492909f, 0.0084472563f,
+ 0.0108413146f, 0.0135300239f, 0.0165117645f, 0.0197847403f, 0.0233469798f, 0.0271963373f, 0.0313304940f, 0.0357469598f,
+ 0.0404430742f, 0.0454160085f, 0.0506627672f, 0.0561801898f, 0.0619649529f, 0.0680135719f, 0.0743224034f, 0.0808876472f,
+ 0.0877053486f, 0.0947714009f, 0.1020815477f, 0.1096313857f, 0.1174163672f, 0.1254318027f, 0.1336728642f, 0.1421345874f,
+ 0.1508118753f, 0.1596995011f, 0.1687921112f, 0.1780842286f, 0.1875702559f, 0.1972444793f, 0.2071010713f, 0.2171340946f,
+ 0.2273375058f, 0.2377051587f, 0.2482308081f, 0.2589081140f, 0.2697306445f, 0.2806918807f, 0.2917852200f, 0.3030039800f,
+ 0.3143414030f, 0.3257906599f, 0.3373448539f, 0.3489970253f, 0.3607401553f, 0.3725671702f, 0.3844709459f, 0.3964443119f,
+ 0.4084800560f, 0.4205709283f, 0.4327096457f, 0.4448888964f, 0.4571013438f, 0.4693396318f, 0.4815963885f, 0.4938642309f,
+ 0.5061357691f, 0.5184036115f, 0.5306603682f, 0.5428986562f, 0.5551111036f, 0.5672903543f, 0.5794290717f, 0.5915199440f,
+ 0.6035556881f, 0.6155290541f, 0.6274328298f, 0.6392598447f, 0.6510029747f, 0.6626551461f, 0.6742093401f, 0.6856585970f,
+ 0.6969960200f, 0.7082147800f, 0.7193081193f, 0.7302693555f, 0.7410918860f, 0.7517691919f, 0.7622948413f, 0.7726624942f,
+ 0.7828659054f, 0.7928989287f, 0.8027555207f, 0.8124297441f, 0.8219157714f, 0.8312078888f, 0.8403004989f, 0.8491881247f,
+ 0.8578654126f, 0.8663271358f, 0.8745681973f, 0.8825836328f, 0.8903686143f, 0.8979184523f, 0.9052285991f, 0.9122946514f,
+ 0.9191123528f, 0.9256775966f, 0.9319864281f, 0.9380350471f, 0.9438198102f, 0.9493372328f, 0.9545839915f, 0.9595569258f,
+ 0.9642530402f, 0.9686695060f, 0.9728036627f, 0.9766530202f, 0.9802152597f, 0.9834882355f, 0.9864699761f, 0.9891586854f,
+ 0.9915527437f, 0.9936507091f, 0.9954513177f, 0.9969534850f, 0.9981563061f, 0.9990590565f, 0.9996611923f, 0.9999623509f,
+};
+
+const float ivas_fb_cf_4ms_16k[IVAS_FB_4MS_16K_SAMP] =
+{
+ 0.0001505907f, 0.0013547717f, 0.0037602327f, 0.0073611788f, 0.0121489350f, 0.0181119671f, 0.0252359097f, 0.0335036006f,
+ 0.0428951221f, 0.0533878494f, 0.0649565044f, 0.0775732174f, 0.0912075934f, 0.1058267862f, 0.1213955767f, 0.1378764585f,
+ 0.1552297276f, 0.1734135785f, 0.1923842047f, 0.2120959043f, 0.2325011901f, 0.2535509039f, 0.2751943352f, 0.2973793430f,
+ 0.3200524817f, 0.3431591298f, 0.3666436213f, 0.3904493799f, 0.4145190556f, 0.4387946624f, 0.4632177182f, 0.4877293857f,
+ 0.5122706143f, 0.5367822818f, 0.5612053376f, 0.5854809444f, 0.6095506201f, 0.6333563787f, 0.6568408702f, 0.6799475183f,
+ 0.7026206570f, 0.7248056648f, 0.7464490961f, 0.7674988099f, 0.7879040957f, 0.8076157953f, 0.8265864215f, 0.8447702724f,
+ 0.8621235415f, 0.8786044233f, 0.8941732138f, 0.9087924066f, 0.9224267826f, 0.9350434956f, 0.9466121506f, 0.9571048779f,
+ 0.9664963994f, 0.9747640903f, 0.9818880329f, 0.9878510650f, 0.9926388212f, 0.9962397673f, 0.9986452283f, 0.9998494093f,
+};
+
+const float ivas_fb_fcs_12band_1ms[IVAS_FB_BANDS_12] =
+{
+ 0.0083333333f, 0.0250000000f, 0.0416666667f, 0.0583333333f,
+ 0.0750000000f, 0.0916666667f, 0.1083333333f, 0.1416666667f,
+ 0.2166666667f, 0.3333333333f, 0.5083333333f, 0.8083333333f
+};
+
+const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] =
+{
+ { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 291, 367 },
+ { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 260, 47 },
+ { 24, 30, 30, 30, 30, 30, 42, 75, 122, 73, 0, 0 }
+};
+
+const int16_t ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] =
+{
+ {0, 9, 25, 41, 57, 73, 88, 110, 158, 246, 380, 593 },
+ {0, 9, 25, 41, 57, 73, 88, 110, 158, 246, 380, 593 },
+ {0, 9, 25, 41, 57, 73, 88, 110, 159, 247, 0, 0 }
+};
+
+const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] =
+{
+ {
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_0 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_1 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_2 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_2,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_3 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_3,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_4 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_4,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_5 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_5,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_6 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_6,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_7 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_7,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_8 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_8,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_9 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_9,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_10 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_10,
+ IVAS_FB_12_1MS_48K_END_BINS_BAND_11 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_11
+ },
+ {
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_0 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_0,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_1 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_1,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_2 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_2,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_3 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_3,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_4 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_4,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_5 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_5,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_6 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_6,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_7 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_7,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_8 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_8,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_9 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_9,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_10 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_10,
+ IVAS_FB_12_1MS_32K_END_BINS_BAND_11 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_11
+ },
+ {
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_0 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_0,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_1 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_1,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_2 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_2,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_3 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_3,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_4 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_4,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_5 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_5,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_6 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_6,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_7 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_7,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_8 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_8,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_9 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_9,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_10 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_10,
+ IVAS_FB_12_1MS_16K_END_BINS_BAND_11 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_11
+ },
+};
+
+const int16_t ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] =
+{
+ {
+ IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1,
+ IVAS_FB_12_1MS_48K_START_OFFSET_BAND_2, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_3,
+ IVAS_FB_12_1MS_48K_START_OFFSET_BAND_4, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_5,
+ IVAS_FB_12_1MS_48K_START_OFFSET_BAND_6, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_7,
+ IVAS_FB_12_1MS_48K_START_OFFSET_BAND_8, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_9,
+ IVAS_FB_12_1MS_48K_START_OFFSET_BAND_10, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_11
+ },
+ {
+ IVAS_FB_12_1MS_32K_START_OFFSET_BAND_0, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_1,
+ IVAS_FB_12_1MS_32K_START_OFFSET_BAND_2, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_3,
+ IVAS_FB_12_1MS_32K_START_OFFSET_BAND_4, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_5,
+ IVAS_FB_12_1MS_32K_START_OFFSET_BAND_6, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_7,
+ IVAS_FB_12_1MS_32K_START_OFFSET_BAND_8, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_9,
+ IVAS_FB_12_1MS_32K_START_OFFSET_BAND_10, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_11
+ },
+ {
+ IVAS_FB_12_1MS_16K_START_OFFSET_BAND_0, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_1,
+ IVAS_FB_12_1MS_16K_START_OFFSET_BAND_2, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_3,
+ IVAS_FB_12_1MS_16K_START_OFFSET_BAND_4, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_5,
+ IVAS_FB_12_1MS_16K_START_OFFSET_BAND_6, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_7,
+ IVAS_FB_12_1MS_16K_START_OFFSET_BAND_8, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_9,
+ IVAS_FB_12_1MS_16K_START_OFFSET_BAND_10, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_11
+ },
+};
+
+const float ivas_fb_cf_1ms_48k[IVAS_FB_1MS_48K_SAMP] =
+{
+ 0.0002677063f, 0.0024076367f, 0.0066783340f, 0.0130615104f, 0.0215298321f, 0.0320470366f, 0.0445680875f, 0.0590393678f,
+ 0.0753989092f, 0.0935766577f, 0.1134947733f, 0.1350679637f, 0.1582038490f, 0.1828033579f, 0.2087611516f, 0.2359660747f,
+ 0.2643016316f, 0.2936464851f, 0.3238749760f, 0.3548576614f, 0.3864618685f, 0.4185522633f, 0.4509914298f, 0.4836404586f,
+ 0.5163595414f, 0.5490085702f, 0.5814477367f, 0.6135381315f, 0.6451423386f, 0.6761250240f, 0.7063535149f, 0.7356983684f,
+ 0.7640339253f, 0.7912388484f, 0.8171966421f, 0.8417961510f, 0.8649320363f, 0.8865052267f, 0.9064233423f, 0.9246010908f,
+ 0.9409606322f, 0.9554319125f, 0.9679529634f, 0.9784701679f, 0.9869384896f, 0.9933216660f, 0.9975923633f, 0.9997322937f,
+};
+
+const float ivas_fb_cf_1ms_32k[IVAS_FB_1MS_32K_SAMP] =
+{
+ 0.0006022719f, 0.0054117450f, 0.0149843734f, 0.0292279674f, 0.0480053534f, 0.0711356950f, 0.0983962343f, 0.1295244373f,
+ 0.1642205226f, 0.2021503478f, 0.2429486279f, 0.2862224533f, 0.3315550733f, 0.3785099100f, 0.4266347628f, 0.4754661628f,
+ 0.5245338372f, 0.5733652372f, 0.6214900900f, 0.6684449267f, 0.7137775467f, 0.7570513721f, 0.7978496522f, 0.8357794774f,
+ 0.8704755627f, 0.9016037657f, 0.9288643050f, 0.9519946466f, 0.9707720326f, 0.9850156266f, 0.9945882550f, 0.9993977281f,
+};
+
+const float ivas_fb_cf_1ms_16k[IVAS_FB_1MS_16K_SAMP] =
+{
+ 0.0024076367f, 0.0215298321f, 0.0590393678f, 0.1134947733f, 0.1828033579f, 0.2643016316f, 0.3548576614f, 0.4509914298f,
+ 0.5490085702f, 0.6451423386f, 0.7356983684f, 0.8171966421f, 0.8865052267f, 0.9409606322f, 0.9784701679f, 0.9975923633f,
+ };
+
+
+const float ivas_fb_fr_12band_1ms_re[IVAS_FB_12_1MS_LEN] =
+{
+ 0.9748788957f, 0.9427895242f, 0.8792742509f, 0.7856320394f, 0.6637543553f, 0.5159842697f, 0.3449612971f, 0.1523029468f,
+ -0.0629462677f, -0.2915070279f, -0.5097704228f, -0.6945723663f, -0.8280677163f, -0.8984664279f, -0.9013544787f, -0.8399030468f,
+ -0.7243177987f, -0.5703726081f, -0.3972779762f, -0.2251611328f, -0.0723653847f, 0.0469440290f, 0.1248973653f, 0.1617697860f,
+ 0.1709641074f, 0.1694810686f, 0.1629475939f, 0.1522105989f, 0.1386564071f, 0.1233728939f, 0.1073854103f, 0.0914740522f,
+ 0.0762871837f, 0.0622709857f, 0.0497418146f, 0.0388592902f, 0.0296823509f, 0.0221628349f, 0.0161914497f, 0.0115997684f,
+ 0.0081967931f, 0.0057721783f, 0.0041230995f, 0.0030548577f, 0.0023984605f, 0.0020073250f, 0.0017670262f, 0.0015886054f,
+ 0.0014126895f, 0.0012008765f, 0.0009366259f, 0.0006164015f, 0.0002494051f, -0.0001501884f, -0.0005632461f, -0.0009716328f,
+ -0.0013573205f, -0.0017064484f, -0.0020074979f, -0.0022538257f, -0.0024412527f, -0.0025696364f, -0.0026403325f, -0.0026573398f,
+ -0.0026249989f, -0.0025490667f, -0.0024348276f, -0.0022882409f, -0.0021144573f, -0.0019190182f, -0.0017066606f, -0.0014824738f,
+ -0.0012508539f, -0.0010165332f, -0.0007835930f, -0.0005563371f, -0.0003383404f, -0.0001331992f, 0.0000563549f, 0.0002277657f,
+ 0.0003794289f, 0.0005100093f, 0.0006190856f, 0.0007064556f, 0.0007726658f, 0.0008183240f, 0.0008445608f, 0.0008523932f,
+ 0.0008431696f, 0.0008180214f, 0.0007783263f, 0.0007252567f, 0.0006602600f, 0.0005846794f, 0.0005002207f, 0.0004085983f,
+ 0.0003119450f, 0.0002124378f, 0.0001126202f, 0.0000149855f, -0.0000777886f, -0.0001632865f, -0.0002391747f, -0.0003036357f,
+ -0.0003551891f, -0.0003930613f, -0.0004169567f, -0.0004273258f, -0.0004250606f, -0.0004116574f, -0.0003888481f, -0.0003586881f,
+ -0.0003231696f, -0.0002842913f, -0.0002437103f, -0.0002028533f, -0.0001626543f, -0.0001237419f, -0.0000862804f, -0.0000502315f,
+ -0.0000152759f, 0.0000188864f, 0.0000525857f, 0.0000859011f, 0.0001187387f, 0.0001506215f, 0.0001808384f, 0.0002083291f,
+ 0.0002319112f, 0.0002502468f, 0.0002621167f, 0.0002664223f, 0.0002624512f, 0.0002498541f, 0.0002288448f, 0.0002001024f,
+ 0.0001648717f, 0.0001247734f, 0.0000818072f, 0.0000380927f, -0.0000041840f, -0.0000430463f, -0.0000767750f, -0.0001041381f,
+ -0.0001243744f, -0.0001373295f, -0.0001433435f, -0.0001432806f, -0.0001383279f, -0.0001299462f, -0.0001196234f, -0.0001088038f,
+ -0.0000986591f, -0.0000900582f, -0.0000834123f, -0.0000787307f, -0.0000755665f, -0.0000731664f, -0.0000705050f, -0.0000664967f,
+ -0.0000600718f, -0.0000503921f, -0.0000369061f, -0.0000195076f, 0.0000014839f, 0.0000252601f, 0.0000506406f, 0.0000761070f,
+ 0.0000999980f, 0.0001206038f, 0.0001363885f, 0.0001460830f, 0.0001488707f, 0.0001444187f, 0.0001329747f, 0.0001153008f,
+ 0.0000926636f, 0.0000666729f, 0.0000391891f,
+ 0.0080195493f, 0.0152804795f, 0.0297236427f, 0.0512076944f, 0.0795504278f, 0.1146345202f, 0.1565217749f, 0.2067150266f,
+ 0.2696514371f, 0.3398196482f, 0.3975948769f, 0.4239235527f, 0.4051207537f, 0.3335063336f, 0.2086503840f, 0.0374772593f,
+ -0.1663484542f, -0.3839925014f, -0.5936160820f, -0.7729897529f, -0.9021602868f, -0.9658914408f, -0.9555491003f, -0.8702102709f,
+ -0.7168585697f, -0.5096278055f, -0.2682088520f, -0.0155786468f, 0.2246238492f, 0.4308147261f, 0.5858672047f, 0.6790005846f,
+ 0.7068091556f, 0.6734550535f, 0.5898178925f, 0.4719496963f, 0.3387034057f, 0.2092646386f, 0.1002222301f, 0.0233145798f,
+ -0.0225492413f, -0.0508402802f, -0.0698819559f, -0.0814769049f, -0.0871540019f, -0.0880955245f, -0.0854373943f, -0.0801296337f,
+ -0.0730507304f, -0.0649236398f, -0.0563762037f, -0.0478921962f, -0.0398550173f, -0.0325224860f, -0.0260651486f, -0.0205564484f,
+ -0.0160078488f, -0.0123673601f, -0.0095503829f, -0.0074410094f, -0.0059169243f, -0.0048497092f, -0.0041229035f, -0.0036294834f,
+ -0.0032833863f, -0.0030140242f, -0.0027726134f, -0.0025247022f, -0.0022531837f, -0.0019502609f, -0.0016189799f, -0.0012659033f,
+ -0.0009025224f, -0.0005393948f, -0.0001881199f, 0.0001429077f, 0.0004458867f, 0.0007165584f, 0.0009512703f, 0.0011491538f,
+ 0.0013092799f, 0.0014325460f, 0.0015192234f, 0.0015708276f, 0.0015881374f, 0.0015730908f, 0.0015271608f, 0.0014531585f,
+ 0.0013537657f, 0.0012330943f, 0.0010952099f, 0.0009453732f, 0.0007885040f, 0.0006301505f, 0.0004749667f, 0.0003275524f,
+ 0.0001910823f, 0.0000681798f, -0.0000401798f, -0.0001336577f, -0.0002133415f, -0.0002805985f, -0.0003376335f, -0.0003863124f,
+ -0.0004286391f, -0.0004657017f, -0.0004982282f, -0.0005257791f, -0.0005474775f, -0.0005614835f, -0.0005658893f, -0.0005584023f,
+ -0.0005372971f, -0.0005011582f, -0.0004497305f, -0.0003835612f, -0.0003046159f, -0.0002157155f, -0.0001208702f, -0.0000245120f,
+ 0.0000683937f, 0.0001532153f, 0.0002256208f, 0.0002823819f, 0.0003212462f, 0.0003415271f, 0.0003437577f, 0.0003299911f,
+ 0.0003032103f, 0.0002673723f, 0.0002266573f, 0.0001853871f, 0.0001472716f, 0.0001153747f, 0.0000915248f, 0.0000764751f,
+ 0.0000695838f, 0.0000692286f, 0.0000727574f, 0.0000771057f, 0.0000789150f, 0.0000752114f, 0.0000635256f, 0.0000424610f,
+ 0.0000116537f, -0.0000279010f, -0.0000741391f, -0.0001238800f, -0.0001733508f, -0.0002183440f, -0.0002548569f, -0.0002793014f,
+ -0.0002890885f, -0.0002827170f, -0.0002601490f, -0.0002226568f, -0.0001729141f, -0.0001145795f, -0.0000521398f, 0.0000096825f,
+ 0.0114335951f, 0.0118220569f, 0.0126166715f, 0.0138498428f, 0.0155597951f, 0.0177826837f, 0.0205365788f, 0.0238116184f,
+ 0.0275499857f, 0.0316384404f, 0.0358879435f, 0.0400334899f, 0.0437164087f, 0.0464960697f, 0.0478357348f, 0.0471294159f,
+ 0.0436878423f, 0.0367814109f, 0.0256142984f, 0.0093791332f, -0.0128147904f, -0.0419091622f, -0.0791441084f, -0.1267865122f,
+ -0.1929101618f, -0.2825839913f, -0.3844663503f, -0.4796058889f, -0.5493419153f, -0.5770955026f, -0.5509547813f, -0.4652700670f,
+ -0.3217444363f, -0.1294222853f, 0.0961203110f, 0.3345074656f, 0.5628461809f, 0.7584007007f, 0.9012417605f, 0.9766103137f,
+ 0.9766601036f, 0.9013929608f, 0.7586588937f, 0.5632193167f, 0.3350048195f, 0.0967502546f, -0.1286537645f, -0.3208359645f,
+ -0.4642258941f, -0.5497861643f, -0.5758205512f, -0.5479856830f, -0.4781988983f, -0.3830435617f, -0.2811824725f, -0.1915676007f,
+ -0.1255389320f, -0.0780249233f, -0.0409475096f, -0.0120357725f, 0.0099548733f, 0.0259692697f, 0.0369008806f, 0.0435579897f,
+ 0.0467369910f, 0.0471666204f, 0.0455359048f, 0.0424502401f, 0.0384477095f, 0.0339708748f, 0.0293829220f, 0.0249536436f,
+ 0.0208784147f, 0.0172747220f, 0.0142030489f, 0.0116695065f, 0.0096461650f, 0.0080756116f, 0.0068882718f, 0.0060058072f,
+ 0.0053538953f, 0.0048628684f, 0.0044756795f, 0.0041456204f, 0.0038402965f, 0.0035372856f, 0.0032255714f, 0.0029004385f,
+ 0.0025638810f, 0.0022199121f, 0.0018750824f, 0.0015349035f, 0.0012050131f, 0.0008888342f, 0.0005893582f, 0.0003077151f,
+ 0.0000451990f, -0.0001977660f, -0.0004197988f, -0.0006196394f, -0.0007948001f, -0.0009428845f, -0.0010607326f, -0.0011459111f,
+ -0.0011961438f, -0.0012107318f, -0.0011899721f, -0.0011362537f, -0.0010532349f, -0.0009464869f, -0.0008223739f, -0.0006883049f,
+ -0.0005514485f, -0.0004188116f, -0.0002960338f, -0.0001875645f, -0.0000957748f, -0.0000214335f, 0.0000367443f, 0.0000812780f,
+ 0.0001159924f, 0.0001449821f, 0.0001725036f, 0.0002019612f, 0.0002358809f, 0.0002751586f, 0.0003193210f, 0.0003661738f,
+ 0.0004124154f, 0.0004536598f, 0.0004853030f, 0.0005027457f, 0.0005022926f, 0.0004813241f, 0.0004389844f, 0.0003760837f,
+ 0.0002954100f, 0.0002012644f, 0.0000993832f, -0.0000038301f, -0.0001016317f, -0.0001878100f, -0.0002570235f, -0.0003055296f,
+ -0.0003312954f, -0.0003343869f, -0.0003167133f, -0.0002820121f, -0.0002352424f, -0.0001822598f, -0.0001290196f, -0.0000811569f,
+ -0.0000432400f, -0.0000185020f, -0.0000083679f, -0.0000125164f, -0.0000287954f, -0.0000536548f, -0.0000824102f, -0.0001099335f,
+ -0.0001310885f, -0.0001414598f, -0.0001377171f, -0.0001181463f, -0.0000827338f, -0.0000333400f, 0.0000265889f, 0.0000922209f,
+ 0.0001579388f, 0.0002177817f, 0.0002661695f, 0.0002983587f, 0.0003110497f, 0.0003026261f, 0.0002734474f, 0.0002257288f,
+ 0.0001634460f, 0.0000918569f, 0.0000170963f, -0.0000545144f, -0.0001169830f, -0.0001653182f, -0.0001959140f, -0.0002069779f,
+ -0.0001985967f, -0.0001727902f, -0.0001331990f, -0.0000847800f, -0.0000332059f, 0.0000156408f, 0.0000563515f, 0.0000844666f,
+ 0.0000970039f, 0.0000926836f, 0.0000721249f, 0.0000377027f, -0.0000066339f, -0.0000558449f, -0.0001042571f, -0.0001462224f,
+ -0.0001766430f, -0.0001915709f, -0.0001885647f, -0.0001670193f, -0.0001281871f, -0.0000751314f, -0.0000123776f, 0.0000544678f,
+ 0.0001193245f, 0.0001761818f, 0.0002197499f, 0.0002459308f, 0.0002522801f, 0.0002382003f, 0.0002050537f,
+ 0.0023329977f, 0.0022744367f, 0.0021570870f, 0.0019806181f, 0.0017457340f, 0.0014542507f, 0.0011108455f, 0.0007223346f,
+ 0.0002992379f, -0.0001466015f, -0.0006012791f, -0.0010533907f, -0.0014941798f, -0.0019241070f, -0.0023530883f, -0.0028080809f,
+ -0.0033317792f, -0.0039896152f, -0.0048647785f, -0.0060629391f, -0.0077015456f, -0.0099112032f, -0.0128179487f, -0.0165415563f,
+ -0.0211707180f, -0.0267603854f, -0.0333010728f, -0.0407193019f, -0.0488429494f, -0.0574105466f, -0.0660338484f, -0.0742229694f,
+ -0.0813438415f, -0.0866673269f, -0.0893099408f, -0.0883179181f, -0.0825536818f, -0.0708351065f, -0.0516356322f, -0.0231563648f,
+ 0.0229208886f, 0.1000615986f, 0.2093510203f, 0.3390457527f, 0.4725528568f, 0.5906840617f, 0.6745849094f, 0.7082031015f,
+ 0.6806592553f, 0.5877917414f, 0.4330061655f, 0.2270823403f, -0.0128552066f, -0.2652258122f, -0.5063946175f, -0.7133884257f,
+ -0.8665187769f, -0.9516510020f, -0.9617959599f, -0.8978644321f, -0.7684707435f, -0.5888227503f, -0.3788375243f, -0.1607017417f,
+ 0.0437915599f, 0.2158527937f, 0.3418541386f, 0.4148932359f, 0.4353978994f, 0.4110138144f, 0.3553491439f, 0.2873311989f,
+ 0.2264012967f, 0.1778272597f, 0.1368656384f, 0.1016489237f, 0.0716971046f, 0.0466686361f, 0.0262587636f, 0.0101140856f,
+ -0.0021717142f, -0.0110521236f, -0.0170125125f, -0.0205483075f, -0.0221473891f, -0.0222696986f, -0.0213345382f, -0.0197075856f,
+ -0.0176958703f, -0.0155434695f, -0.0134339314f, -0.0114932096f, -0.0097973566f, -0.0083798220f, -0.0072413978f, -0.0063587120f,
+ -0.0056935805f, -0.0052001373f, -0.0048316507f, -0.0045448649f, -0.0043035469f, -0.0040798367f, -0.0038548953f, -0.0036180007f,
+ -0.0033653668f, -0.0030981742f, -0.0028208099f, -0.0025389671f, -0.0022582881f, -0.0019832510f, -0.0017166811f, -0.0014595950f,
+ -0.0012115153f, -0.0009709890f, -0.0007362895f, -0.0005061076f, -0.0002801409f, -0.0000595032f, 0.0001531427f, 0.0003536750f,
+ 0.0005368997f, 0.0006970650f, 0.0008285636f, 0.0009265836f, 0.0009877836f, 0.0010107351f, 0.0009962610f, 0.0009474346f,
+ 0.0008694403f, 0.0007691024f, 0.0006543506f, 0.0005334591f, 0.0004143726f, 0.0003039581f, 0.0002074999f, 0.0001282497f,
+ 0.0000673202f, 0.0000236838f, -0.0000054823f, -0.0000243922f, -0.0000379908f, -0.0000513567f, -0.0000689891f, -0.0000943029f,
+ -0.0001291385f, -0.0001735855f, -0.0002258909f, -0.0002827035f, -0.0003393834f, -0.0003905818f, -0.0004307882f, -0.0004550220f,
+ -0.0004593576f, -0.0004414605f, -0.0004008453f, -0.0003390565f, -0.0002595254f, -0.0001673445f, -0.0000687564f, 0.0000293658f,
+ 0.0001202144f, 0.0001976297f, 0.0002567251f, 0.0002942795f, 0.0003090663f, 0.0003018805f, 0.0002754671f, 0.0002341572f,
+ 0.0001834501f, 0.0001293884f, 0.0000779842f, 0.0000345648f, 0.0000032926f, -0.0000132797f, -0.0000143893f, -0.0000011447f,
+ 0.0000236778f, 0.0000559218f, 0.0000905679f, 0.0001222509f, 0.0001458957f, 0.0001572350f, 0.0001533249f, 0.0001328377f,
+ 0.0000962676f, 0.0000458655f, -0.0000145297f, -0.0000799026f, -0.0001445204f, -0.0002025425f, -0.0002485698f, -0.0002782267f,
+ -0.0002885684f, -0.0002784187f, -0.0002484615f, -0.0002012166f, -0.0001407652f, -0.0000723891f, -0.0000020250f, 0.0000642779f,
+ 0.0006545440f, 0.0006092123f, 0.0005211283f, 0.0003952715f, 0.0002383557f, 0.0000584198f, -0.0001362653f, -0.0003375075f,
+ -0.0005383555f, -0.0007329456f, -0.0009174331f, -0.0010891536f, -0.0012472468f, -0.0013911728f, -0.0015212364f, -0.0016367530f,
+ -0.0017368889f, -0.0018188830f, -0.0018796284f, -0.0019142370f, -0.0019185646f, -0.0018880671f, -0.0018210801f, -0.0017174793f,
+ -0.0015821304f, -0.0014225231f, -0.0012516143f, -0.0010835462f, -0.0009352781f, -0.0008198418f, -0.0007467438f, -0.0007129147f,
+ -0.0007027599f, -0.0006778296f, -0.0005783377f, -0.0003132968f, 0.0002340159f, 0.0012135056f, 0.0027962862f, 0.0051783222f,
+ 0.0085600080f, 0.0131460500f, 0.0191158420f, 0.0266218006f, 0.0357510579f, 0.0465271020f, 0.0588638446f, 0.0725784015f,
+ 0.0873370030f, 0.1026908595f, 0.1180068601f, 0.1325484280f, 0.1453642259f, 0.1554807068f, 0.1616648578f, 0.1632688310f,
+ 0.1549027767f, 0.1198428714f, 0.0449861804f, -0.0696229208f, -0.2158023005f, -0.3790883171f, -0.5408894679f, -0.6808851285f,
+ -0.7797705919f, -0.8217682544f, -0.7968116423f, -0.7019652931f, -0.5420418321f, -0.3292210214f, -0.0818128466f, 0.1777726196f,
+ 0.4255266516f, 0.6385776439f, 0.7977664747f, 0.8898038418f, 0.9086949642f, 0.8563086554f, 0.7419773576f, 0.5812252250f,
+ 0.3937408613f, 0.2008871303f, 0.0230173731f, -0.1230428784f, -0.2260664125f, -0.2818374636f, -0.2937072611f, -0.2733437698f,
+ -0.2408584071f, -0.2098412063f, -0.1806909043f, -0.1526536550f, -0.1261957677f, -0.1017094943f, -0.0795968657f, -0.0600974864f,
+ -0.0433545981f, -0.0293681726f, -0.0180470916f, -0.0092000126f, -0.0025796754f, 0.0021127195f, 0.0051910943f, 0.0069776293f,
+ 0.0077756050f, 0.0078657031f, 0.0074886765f, 0.0068470105f, 0.0060965069f, 0.0053530166f, 0.0046907222f, 0.0041521192f,
+ 0.0037501212f, 0.0034789031f, 0.0033170573f, 0.0032371863f, 0.0032080612f, 0.0032016671f, 0.0031933530f, 0.0031660244f,
+ 0.0031082781f, 0.0030162723f, 0.0028905427f, 0.0027365419f, 0.0025611068f, 0.0023726939f, 0.0021783369f, 0.0019843040f,
+ 0.0017939931f, 0.0016092783f, 0.0014293389f, 0.0012525382f, 0.0010758415f, 0.0008968234f, 0.0007132020f, 0.0005245511f,
+ 0.0003315658f, 0.0001372209f, -0.0000543880f, -0.0002374465f, -0.0004059085f, -0.0005532434f, -0.0006739838f, -0.0007634986f,
+ -0.0008192976f, -0.0008405529f, -0.0008289575f, -0.0007878678f, -0.0007226939f, -0.0006397231f, -0.0005461962f, -0.0004490215f,
+ -0.0003547907f, -0.0002686412f, -0.0001944601f, -0.0001340918f, -0.0000878707f, -0.0000542351f, -0.0000305758f, -0.0000131627f,
+ 0.0000018427f, 0.0000183480f, 0.0000393727f, 0.0000671196f, 0.0001022671f, 0.0001443061f, 0.0001911748f, 0.0002398911f,
+ 0.0002864880f, 0.0003268414f, 0.0003567538f, 0.0003727940f, 0.0003723297f, 0.0003541905f, 0.0003184856f, 0.0002669707f,
+ 0.0002025844f, 0.0001295158f, 0.0000525132f, -0.0000232393f, -0.0000928921f, -0.0001520697f, -0.0001975396f, -0.0002271978f,
+ -0.0002404958f, -0.0002381708f,
+ -0.0001556937f, -0.0002232588f, -0.0003000471f, -0.0003807341f, -0.0004589754f, -0.0005276096f, -0.0005796476f, -0.0006085059f,
+ -0.0006090117f, -0.0005773878f, -0.0005120302f, -0.0004130497f, -0.0002827174f, -0.0001245430f, 0.0000565230f, 0.0002553084f,
+ 0.0004662156f, 0.0006844691f, 0.0009056254f, 0.0011266188f, 0.0013448100f, 0.0015587720f, 0.0017669159f, 0.0019681955f,
+ 0.0021605643f, 0.0023419522f, 0.0025089038f, 0.0026581873f, 0.0027858518f, 0.0028896115f, 0.0029682393f, 0.0030244845f,
+ 0.0030642863f, 0.0030995791f, 0.0031464520f, 0.0032269718f, 0.0033653351f, 0.0035879808f, 0.0039171130f, 0.0043689626f,
+ 0.0049448001f, 0.0056281538f, 0.0063744051f, 0.0071088295f, 0.0077167468f, 0.0080450691f, 0.0078953687f, 0.0070318498f,
+ 0.0051792603f, 0.0020396552f, -0.0027043718f, -0.0093630158f, -0.0182327050f, -0.0295599145f, -0.0435368078f, -0.0602568291f,
+ -0.0797235538f, -0.1017981297f, -0.1262457047f, -0.1526688648f, -0.1806793505f, -0.2098138162f, -0.2408276962f, -0.2733223455f,
+ -0.2937063941f, -0.2818656143f, -0.2261282142f, -0.1231384900f, 0.0228924303f, 0.2007416620f, 0.3935871743f, 0.5810779624f,
+ 0.7418520015f, 0.8562199711f, 0.9086554096f, 0.8898222505f, 0.7978469922f, 0.6387191949f, 0.4257228188f, 0.1780121397f,
+ -0.0815452149f, -0.3289431293f, -0.5417726272f, -0.7017230773f, -0.7966125143f, -0.8216246380f, -0.7796902592f, -0.6808705368f,
+ -0.5409377623f, -0.3791916953f, -0.2159490132f, -0.0697984743f, 0.0447973984f, 0.1196560777f, 0.1547311650f, 0.1631223252f,
+ 0.1615491774f, 0.1553970134f, 0.1453090286f, 0.1325143072f, 0.1179833627f, 0.1026659817f, 0.0872986185f, 0.0725159741f,
+ 0.0587697393f, 0.0463978659f, 0.0355880008f, 0.0264313485f, 0.0189090552f, 0.0129379217f, 0.0083680105f, 0.0050209526f,
+ 0.0026911244f, 0.0011756268f, 0.0002742518f, -0.0001893835f, -0.0003713645f, -0.0003945662f, -0.0003559061f, -0.0003199311f,
+ -0.0003286406f, -0.0003992283f, -0.0005347052f, -0.0007234444f, -0.0009489211f, -0.0011892232f, -0.0014247925f, -0.0016368658f,
+ -0.0018128572f, -0.0019435092f, -0.0020262245f, -0.0020613098f, -0.0020539729f, -0.0020103196f, -0.0019388124f, -0.0018466470f,
+ -0.0017412840f, -0.0016275801f, -0.0015096821f, -0.0013889666f, -0.0012662678f, -0.0011404183f, -0.0010105747f, -0.0008750310f,
+ -0.0007333545f, -0.0005851730f, -0.0004319169f, -0.0002754165f, -0.0001192014f, 0.0000330890f, 0.0001767485f, 0.0003076493f,
+ 0.0004214404f, 0.0005150718f, 0.0005859601f, 0.0006332532f, 0.0006568484f, 0.0006583487f, 0.0006399242f, 0.0006050121f,
+ 0.0005571017f, 0.0005002994f, 0.0004381601f, 0.0003742519f, 0.0003111446f, 0.0002510679f, 0.0001951108f, 0.0001440004f,
+ 0.0000974938f, 0.0000552356f, 0.0000162701f, -0.0000201054f, -0.0000548020f, -0.0000881717f, -0.0001205191f, -0.0001514697f,
+ -0.0001805617f, -0.0002067517f, -0.0002290677f, -0.0002462077f, -0.0002572013f, -0.0002610364f, -0.0002572665f, -0.0002456071f,
+ -0.0002264461f, -0.0002003792f, -0.0001686145f,
+ -0.0002097915f, -0.0002547683f, -0.0002867440f, -0.0003037080f, -0.0003049864f, -0.0002912099f, -0.0002641320f, -0.0002263469f,
+ -0.0001809155f, -0.0001309730f, -0.0000793326f, -0.0000281672f, 0.0000212324f, 0.0000685537f, 0.0001144458f, 0.0001603457f,
+ 0.0002082167f, 0.0002601799f, 0.0003181336f, 0.0003833534f, 0.0004561750f, 0.0005357423f, 0.0006199091f, 0.0007052503f,
+ 0.0007872414f, 0.0008605303f, 0.0009193285f, 0.0009578246f, 0.0009706279f, 0.0009531437f, 0.0009018903f, 0.0008146822f,
+ 0.0006907085f, 0.0005304701f, 0.0003356294f, 0.0001087751f, -0.0001468322f, -0.0004275067f, -0.0007293282f, -0.0010482464f,
+ -0.0013801011f, -0.0017205409f, -0.0020649160f, -0.0024081360f, -0.0027446427f, -0.0030684675f, -0.0033735725f, -0.0036543691f,
+ -0.0039066272f, -0.0041285253f, -0.0043220448f, -0.0044942599f, -0.0046587239f, -0.0048362859f, -0.0050555995f, -0.0053524607f,
+ -0.0057684191f, -0.0063476637f, -0.0071329714f, -0.0081596433f, -0.0094487437f, -0.0109984997f, -0.0127758558f, -0.0147068954f,
+ -0.0166688890f, -0.0184823228f, -0.0199064468f, -0.0206359860f, -0.0203032667f, -0.0184822593f, -0.0146993237f, -0.0084456516f,
+ 0.0008037916f, 0.0135712038f, 0.0303539710f, 0.0516053773f, 0.0777267032f, 0.1090646438f, 0.1459928995f, 0.1890045882f,
+ 0.2399569411f, 0.3035491657f, 0.3744326411f, 0.4330381754f, 0.4602649242f, 0.4422767198f, 0.3711532515f, 0.2461380555f,
+ 0.0737670473f, -0.1327449736f, -0.3550430014f, -0.5718089399f, -0.7613406410f, -0.9042683903f, -0.9859824923f, -0.9986999813f,
+ -0.9431316453f, -0.8322426947f, -0.6838587489f, -0.5090121248f, -0.3164353275f, -0.1160643779f, 0.0821150478f, 0.2684309672f,
+ 0.4341770987f, 0.5719923883f, 0.6762928566f, 0.7434950500f, 0.7721889543f, 0.7631234448f, 0.7191049971f, 0.6447409999f,
+ 0.5461062812f, 0.4303073808f, 0.3050115994f, 0.1779422698f, 0.0563953149f, -0.0532072816f, -0.1456894384f, -0.2173979596f,
+ -0.2663715333f, -0.2923808160f, -0.2968590700f, -0.2826977783f, -0.2539702782f, -0.2155328992f, -0.1726410340f, -0.1304388234f,
+ -0.0937203765f, -0.0651894568f, -0.0434204585f, -0.0262320261f, -0.0128620020f, -0.0027758731f, 0.0045023778f, 0.0094378307f,
+ 0.0124649620f, 0.0139956053f, 0.0143989384f, 0.0140037462f, 0.0130866052f, 0.0118760507f, 0.0105485285f, 0.0092355458f,
+ 0.0080250843f, 0.0069705449f, 0.0060949377f, 0.0053998515f, 0.0048701054f, 0.0044812646f, 0.0042032151f, 0.0040054335f,
+ 0.0038588251f, 0.0037386836f, 0.0036248683f, 0.0035029301f, 0.0033631517f, 0.0032005638f, 0.0030135068f, 0.0028032324f,
+ 0.0025725319f, 0.0023254060f, 0.0020660644f, 0.0017988746f, 0.0015277862f, 0.0012565431f, 0.0009884144f, 0.0007265302f,
+ 0.0004737413f, 0.0002329236f, 0.0000068230f, -0.0002017617f, -0.0003902098f, -0.0005560211f, -0.0006970975f, -0.0008117494f,
+ -0.0008989567f, -0.0009583547f, -0.0009904048f, -0.0009962992f, -0.0009780085f, -0.0009380932f, -0.0008796449f, -0.0008060398f,
+ -0.0007208281f, -0.0006274895f, -0.0005293371f, -0.0004293314f, -0.0003300469f, -0.0002335751f, -0.0001415683f, -0.0000552272f,
+ 0.0000245975f, 0.0000973664f, 0.0001627306f, 0.0002204858f, 0.0002704729f, 0.0003125597f, 0.0003465872f, 0.0003723927f,
+ 0.0003898040f, 0.0003986947f, 0.0003990072f, 0.0003908172f, 0.0003743577f, 0.0003500669f, 0.0003185900f, 0.0002807935f,
+ 0.0002377348f, 0.0001906413f, 0.0001408526f, 0.0000897771f, 0.0000388229f, -0.0000106507f, -0.0000573934f, -0.0001003004f,
+ -0.0001384514f, -0.0001711250f, -0.0001978125f, -0.0002182105f, -0.0002322144f, -0.0002398964f, -0.0002414880f,
+ -0.0001596129f, -0.0001562496f, -0.0001498931f, -0.0001412337f, -0.0001312006f, -0.0001208315f, -0.0001111500f, -0.0001030067f,
+ -0.0000969764f, -0.0000932334f, -0.0000915268f, -0.0000911372f, -0.0000909596f, -0.0000895515f, -0.0000853138f, -0.0000765980f,
+ -0.0000619367f, -0.0000401498f, -0.0000105563f, 0.0000269865f, 0.0000719478f, 0.0001231977f, 0.0001789736f, 0.0002370733f,
+ 0.0002949065f, 0.0003497691f, 0.0003989259f, 0.0004399015f, 0.0004705253f, 0.0004891741f, 0.0004947225f, 0.0004866983f,
+ 0.0004651169f, 0.0004305530f, 0.0003838811f, 0.0003263054f, 0.0002590637f, 0.0001834786f, 0.0001006881f, 0.0000117772f,
+ -0.0000824234f, -0.0001810986f, -0.0002835801f, -0.0003890188f, -0.0004964869f, -0.0006046168f, -0.0007117406f, -0.0008155628f,
+ -0.0009134018f, -0.0010019440f, -0.0010776210f, -0.0011364499f, -0.0011745303f, -0.0011879291f, -0.0011732401f, -0.0011274376f,
+ -0.0010484260f, -0.0009347877f, -0.0007862674f, -0.0006033735f, -0.0003877877f, -0.0001418301f, 0.0001311620f, 0.0004274542f,
+ 0.0007424943f, 0.0010715568f, 0.0014092217f, 0.0017500212f, 0.0020878151f, 0.0024164922f, 0.0027293133f, 0.0030197921f,
+ 0.0032811287f, 0.0035074177f, 0.0036932727f, 0.0038354464f, 0.0039326233f, 0.0039873724f, 0.0040058742f, 0.0039999004f,
+ 0.0039859967f, 0.0039869775f, 0.0040299079f, 0.0041465214f, 0.0043693426f, 0.0047305856f, 0.0052560067f, 0.0059622775f,
+ 0.0068486582f, 0.0078935236f, 0.0090446101f, 0.0102161743f, 0.0112791696f, 0.0120612232f, 0.0123383309f, 0.0118401814f,
+ 0.0102443788f, 0.0071893168f, 0.0022697611f, -0.0049422577f, -0.0149080197f, -0.0281014987f, -0.0450597042f, -0.0665503452f,
+ -0.0947658820f, -0.1311459738f, -0.1730055990f, -0.2155698254f, -0.2537148355f, -0.2822005637f, -0.2961808714f, -0.2915797030f,
+ -0.2654897618f, -0.2164403253f, -0.1446028708f, -0.0518524544f, 0.0582677361f, 0.1807212874f, 0.3092454104f, 0.4367256082f,
+ 0.5556248313f, 0.6584663388f, 0.7383128514f, 0.7892352587f, 0.8067145259f, 0.7879751516f, 0.7322001587f, 0.6406413437f,
+ 0.5165833320f, 0.3651995965f, 0.1932631326f, 0.0087845907f, -0.1794730708f, -0.3624711894f, -0.5314826505f, -0.6784496714f,
+ -0.7975387008f, -0.8869066714f, -0.9460978228f, -0.9743683484f, -0.9716887763f, -0.9388912477f, -0.8776913880f, -0.7906217616f,
+ -0.6809617759f, -0.5526158639f, -0.4099903122f, -0.2578384472f, -0.1011091221f, 0.0552204273f, 0.2063009082f, 0.3475689337f,
+ 0.4748858634f, 0.5846665399f, 0.6739816770f, 0.7406414471f, 0.7832480152f, 0.8012243690f, 0.7948108464f, 0.7650372454f,
+ 0.7136651972f, 0.6431094919f, 0.5563357930f, 0.4567441179f, 0.3480375726f, 0.2340859886f, 0.1187851647f, 0.0059210218f,
+ -0.1009603020f, -0.1986681163f, -0.2844680876f, -0.3561617036f, -0.4121449494f, -0.4514415411f, -0.4737129527f, -0.4792427680f,
+ -0.4688992715f, -0.4440758562f, -0.4066146191f, -0.3587143469f, -0.3028292405f, -0.2415605597f, -0.1775478604f, -0.1133622284f,
+ -0.0514077865f, 0.0061666480f, 0.0575405302f, 0.1012784567f, 0.1363672493f, 0.1622340919f, 0.1787438032f, 0.1861777807f,
+ 0.1851944065f, 0.1767749919f, 0.1621564237f, 0.1427557163f, 0.1200884424f, 0.0956867818f, 0.0710192746f, 0.0474178663f,
+ 0.0260137499f, 0.0076867119f, -0.0069716085f, -0.0176776741f, -0.0244598245f, -0.0276479905f, -0.0278485265f, -0.0259604376f,
+ -0.0231942463f, -0.0203712397f, -0.0176250103f, -0.0150030188f, -0.0125853805f, -0.0104245492f, -0.0085536471f, -0.0069822366f,
+ -0.0057037888f, -0.0046971305f, -0.0039324091f, -0.0033733475f, -0.0029816582f, -0.0027187689f, -0.0025487112f, -0.0024389400f,
+ -0.0023618935f, -0.0022949607f, -0.0022210429f, -0.0021279181f, -0.0020081783f, -0.0018582858f, -0.0016782193f, -0.0014704729f,
+ -0.0012396507f, -0.0009915718f, -0.0007329515f, -0.0004706874f, -0.0002116789f, 0.0000376970f, 0.0002716276f, 0.0004852251f,
+ 0.0006744554f, 0.0008363689f, 0.0009689456f, 0.0010712272f, 0.0011431025f, 0.0011853673f, 0.0011994712f, 0.0011875293f,
+ 0.0011520531f, 0.0010959403f, 0.0010222139f, 0.0009340189f, 0.0008343934f, 0.0007262955f, 0.0006124255f, 0.0004952948f,
+ 0.0003771045f, 0.0002598545f, 0.0001452665f, 0.0000349171f, -0.0000698172f, -0.0001676287f, -0.0002573385f, -0.0003377893f,
+ -0.0004079306f, -0.0004667485f, -0.0005133801f, -0.0005470765f, -0.0005673356f, -0.0005738781f, -0.0005667759f, -0.0005464152f,
+ -0.0005135934f, -0.0004694478f, -0.0004155042f, -0.0003535607f, -0.0002856874f, -0.0002140732f, -0.0001409939f, -0.0000686445f,
+ 0.0000008966f, 0.0000658187f, 0.0001245893f, 0.0001760633f, 0.0002194479f, 0.0002543579f, 0.0002807311f, 0.0002988367f,
+ 0.0003091550f, 0.0003123597f, 0.0003091881f, 0.0003004253f, 0.0002867930f, 0.0002689588f, 0.0002474626f, 0.0002227630f,
+ 0.0001952039f, 0.0001650929f, 0.0001326952f, 0.0000983261f, 0.0000623480f, 0.0000252528f, -0.0000123602f, -0.0000497334f,
+ -0.0000860060f, -0.0001202016f, -0.0001513162f, -0.0001783353f, -0.0002003408f, -0.0002165359f, -0.0002263463f, -0.0002294298f,
+ -0.0002257477f, -0.0002155386f, -0.0001993478f, -0.0001779591f, -0.0001523829f, -0.0001237555f, -0.0000933024f, -0.0000622262f,
+ -0.0000316695f, -0.0000026169f, 0.0000241191f, 0.0000479620f, 0.0000685482f, 0.0000857501f, 0.0000996158f, 0.0001103594f,
+ 0.0001182780f, 0.0001237279f, 0.0001270411f, 0.0001285109f, 0.0001283284f, 0.0001265953f, 0.0001232928f, 0.0001183261f,
+ 0.0001115250f, 0.0001027124f, 0.0000917214f, 0.0000784695f, 0.0000629720f, 0.0000454005f, 0.0000260736f, 0.0000054844f,
+ -0.0000157413f, -0.0000368512f, -0.0000570374f, -0.0000754661f, -0.0000913623f, -0.0001040431f, -0.0001129942f,
+ -0.0001518039f, -0.0001490944f, -0.0001437563f, -0.0001359447f, -0.0001258775f, -0.0001138183f, -0.0001000584f, -0.0000848958f,
+ -0.0000686184f, -0.0000514869f, -0.0000337271f, -0.0000155230f, 0.0000029786f, 0.0000216627f, 0.0000404299f, 0.0000591833f,
+ 0.0000778062f, 0.0000961486f, 0.0001140075f, 0.0001311212f, 0.0001471607f, 0.0001617373f, 0.0001744077f, 0.0001846979f,
+ 0.0001921197f, 0.0001962050f, 0.0001965285f, 0.0001927436f, 0.0001846019f, 0.0001719815f, 0.0001548948f, 0.0001335028f,
+ 0.0001081065f, 0.0000791461f, 0.0000471762f, 0.0000128542f, -0.0000230952f, -0.0000598950f, -0.0000967535f, -0.0001328756f,
+ -0.0001674945f, -0.0001998742f, -0.0002293319f, -0.0002552303f, -0.0002769922f, -0.0002940867f, -0.0003060409f, -0.0003124253f,
+ -0.0003128705f, -0.0003070572f, -0.0002947414f, -0.0002757524f, -0.0002500272f, -0.0002176130f, -0.0001787066f, -0.0001336551f,
+ -0.0000829924f, -0.0000274293f, 0.0000321218f, 0.0000945733f, 0.0001586548f, 0.0002229603f, 0.0002859566f, 0.0003460483f,
+ 0.0004015979f, 0.0004510007f, 0.0004927070f, 0.0005252984f, 0.0005475019f, 0.0005582587f, 0.0005567241f, 0.0005423236f,
+ 0.0005147357f, 0.0004739352f, 0.0004201606f, 0.0003539484f, 0.0002760880f, 0.0001876525f, 0.0000899450f, -0.0000154720f,
+ -0.0001268367f, -0.0002421597f, -0.0003592929f, -0.0004759036f, -0.0005895563f, -0.0006976915f, -0.0007977237f, -0.0008870259f,
+ -0.0009630432f, -0.0010232813f, -0.0010654313f, -0.0010873564f, -0.0010872233f, -0.0010634782f, -0.0010149807f, -0.0009409632f,
+ -0.0008411655f, -0.0007157758f, -0.0005655665f, -0.0003918178f, -0.0001964570f, 0.0000180385f, 0.0002485007f, 0.0004912017f,
+ 0.0007417257f, 0.0009951609f, 0.0012460131f, 0.0014884994f, 0.0017165405f, 0.0019242012f, 0.0021057906f, 0.0022564772f,
+ 0.0023724911f, 0.0024518980f, 0.0024948363f, 0.0025043647f, 0.0024865838f, 0.0024513953f, 0.0024122725f, 0.0023867094f,
+ 0.0023953488f, 0.0024618909f, 0.0026112876f, 0.0028689594f, 0.0032578396f, 0.0037969386f, 0.0044971599f, 0.0053595648f,
+ 0.0063700240f, 0.0074979980f, 0.0086900568f, 0.0098707813f, 0.0109344936f, 0.0117523261f, 0.0121588428f, 0.0119927747f,
+ 0.0108338004f, 0.0076669462f, 0.0015951619f, -0.0077015608f, -0.0201874668f, -0.0355062002f, -0.0530094339f, -0.0717877750f,
+ -0.0907221346f, -0.1085412898f, -0.1238936126f, -0.1354215686f, -0.1418421064f, -0.1420235850f, -0.1350600376f, -0.1203351392f,
+ -0.0975759142f, -0.0668903695f, -0.0287893898f, 0.0158109005f, 0.0656049927f, 0.1189337419f, 0.1738373906f, 0.2281255290f,
+ 0.2794600956f, 0.3254494085f, 0.3637483740f, 0.3921617568f, 0.4087452458f, 0.4119008001f, 0.4004612717f, 0.3737611396f,
+ 0.3316892920f, 0.2747217255f, 0.2039316066f, 0.1209761088f, 0.0280593378f, -0.0721274395f, -0.1764869974f, -0.2816158102f,
+ -0.3839191559f, -0.4797372694f, -0.5654782669f, -0.6377526073f, -0.6935042311f, -0.7301330421f, -0.7456040786f, -0.7385387273f,
+ -0.7082842960f, -0.6549586998f, -0.5794681743f, -0.4834966938f, -0.3694669951f, -0.2404740552f, -0.1001929952f, 0.0472356415f,
+ 0.1973394347f, 0.3454617961f, 0.4869187455f, 0.6171590292f, 0.7319219537f, 0.8273869572f, 0.9003096301f, 0.9481388242f,
+ 0.9691107389f, 0.9623160652f, 0.9277378915f, 0.8662587282f, 0.7796363134f, 0.6704507997f, 0.5420235210f, 0.3983429587f,
+ 0.2439770306f, 0.0835515600f, -0.0785437339f, -0.2379253926f, -0.3902709949f, -0.5314762215f, -0.6577657562f, -0.7658017175f,
+ -0.8527727865f, -0.9164711922f, -0.9553496178f, -0.9685606622f, -0.9559747754f, -0.9181785555f, -0.8564517514f, -0.7727251920f,
+ -0.6695198086f, -0.5498696134f, -0.4172301964f, -0.2753762088f, -0.1282903603f, 0.0199522336f, 0.1653013209f, 0.3038465453f,
+ 0.4319271716f, 0.5462330255f, 0.6438939828f, 0.7225552652f, 0.7804366545f, 0.8163739029f, 0.8298414763f, 0.8209560951f,
+ 0.7904613476f, 0.7396940415f, 0.6705336701f, 0.5853367342f, 0.4868582109f, 0.3781627335f, 0.2625283931f, 0.1433461974f,
+ 0.0240183452f, -0.0921415681f, -0.2020034062f, -0.3027076056f, -0.3917420558f, -0.4670065944f, -0.5268634348f, -0.5701722713f,
+ -0.5963093708f, -0.6051704118f, -0.5971574290f, -0.5731506218f, -0.5344663552f, -0.4828029698f, -0.4201764962f, -0.3488485038f,
+ -0.2712486558f, -0.1898944962f, -0.1073111782f, -0.0259536082f, 0.0518664854f, 0.1240464667f, 0.1887496815f, 0.2444518757f,
+ 0.2899758594f, 0.3245137882f, 0.3476366187f, 0.3592909899f, 0.3597839221f, 0.3497564092f, 0.3301470195f, 0.3021472383f,
+ 0.2671501836f, 0.2266948496f, 0.1824077493f, 0.1359442498f, 0.0889314191f, 0.0429145298f, -0.0006912934f, -0.0406425334f,
+ -0.0759009165f, -0.1056580541f, -0.1293508553f, -0.1466672055f, -0.1575424230f, -0.1621466320f, -0.1608642639f, -0.1542663510f,
+ -0.1430773876f, -0.1281377523f, -0.1103638299f, -0.0907069045f, -0.0701130981f, -0.0494852310f, -0.0296487968f, -0.0113224665f,
+ 0.0049049322f, 0.0185912359f, 0.0294499482f, 0.0373525686f, 0.0423229093f, 0.0445255530f, 0.0442471860f, 0.0418741009f,
+ 0.0378642492f, 0.0327185225f, 0.0269484800f, 0.0210472303f, 0.0154578360f, 0.0105498876f, 0.0065912187f, 0.0037323571f,
+ 0.0018671281f, 0.0006505029f, -0.0001484215f, -0.0006222332f, -0.0008521845f, -0.0009057969f, -0.0008424506f, -0.0007103595f,
+ -0.0005491202f, -0.0003884807f, -0.0002503188f, -0.0001485007f, -0.0000907440f, -0.0000790482f, -0.0001114146f, -0.0001824655f,
+ -0.0002849020f, -0.0004100554f, -0.0005489962f, -0.0006928821f, -0.0008336988f, -0.0009643687f, -0.0010791665f, -0.0011736223f,
+ -0.0012446927f, -0.0012905298f, -0.0013105005f, -0.0013048967f, -0.0012748875f, -0.0012222325f, -0.0011492257f, -0.0010584505f,
+ -0.0009527473f, -0.0008350241f, -0.0007082563f, -0.0005753473f, -0.0004391546f, -0.0003023856f, -0.0001676358f, -0.0000373054f,
+ 0.0000863632f, 0.0002013598f, 0.0003058750f, 0.0003983709f, 0.0004775550f, 0.0005424460f, 0.0005923474f, 0.0006269020f,
+ 0.0006460595f, 0.0006501134f, 0.0006396557f, 0.0006155940f, 0.0005790906f, 0.0005315601f, 0.0004745961f, 0.0004099540f,
+ 0.0003394710f, 0.0002650418f, 0.0001885408f, 0.0001117995f, 0.0000365379f, -0.0000356487f, -0.0001033434f, -0.0001653071f,
+ -0.0002205157f, -0.0002681453f, -0.0003075938f, -0.0003384554f, -0.0003605306f, -0.0003737941f, -0.0003783989f, -0.0003746427f,
+ -0.0003629698f, -0.0003439392f, -0.0003182272f, -0.0002865979f, -0.0002499066f, -0.0002090714f, -0.0001650754f, -0.0001189372f,
+ -0.0000717098f, -0.0000244485f, 0.0000217960f, 0.0000660121f, 0.0001072384f, 0.0001445996f, 0.0001773182f, 0.0002047476f,
+ 0.0002263802f, 0.0002418727f, 0.0002510450f, 0.0002538948f, 0.0002505843f, 0.0002414409f, 0.0002269326f, 0.0002076567f,
+ 0.0001843057f, 0.0001576490f, 0.0001284948f, 0.0000976709f, 0.0000659883f, 0.0000342273f, 0.0000031084f, -0.0000267131f,
+ -0.0000546656f, -0.0000802581f, -0.0001030882f, -0.0001228320f, -0.0001392462f, -0.0001521538f, -0.0001614454f, -0.0001670654f,
+ -0.0001690150f, -0.0001673428f, -0.0001621512f, -0.0001535906f, -0.0001418693f, -0.0001272490f, -0.0001100543f, -0.0000906661f,
+ -0.0000695268f, -0.0000471286f, -0.0000240107f, -0.0000007413f, 0.0000220928f, 0.0000439109f, 0.0000641527f, 0.0000823053f,
+ 0.0000979177f, 0.0001106244f, 0.0001201540f, 0.0001263447f, 0.0001291432f, 0.0001286087f, 0.0001249010f, 0.0001182738f,
+ -0.0000677642f, -0.0000523826f, -0.0000355858f, -0.0000177135f, 0.0000008632f, 0.0000197497f, 0.0000385362f, 0.0000568069f,
+ 0.0000741490f, 0.0000901630f, 0.0001044714f, 0.0001167282f, 0.0001266271f, 0.0001339090f, 0.0001383682f, 0.0001398580f,
+ 0.0001382933f, 0.0001336542f, 0.0001259858f, 0.0001153988f, 0.0001020662f, 0.0000862221f, 0.0000681561f, 0.0000482094f,
+ 0.0000267679f, 0.0000042570f, -0.0000188674f, -0.0000421254f, -0.0000650225f, -0.0000870579f, -0.0001077348f, -0.0001265690f,
+ -0.0001431007f, -0.0001569032f, -0.0001675946f, -0.0001748464f, -0.0001783945f, -0.0001780466f, -0.0001736910f, -0.0001653012f,
+ -0.0001529419f, -0.0001367694f, -0.0001170335f, -0.0000940728f, -0.0000683121f, -0.0000402526f, -0.0000104645f, 0.0000204271f,
+ 0.0000517530f, 0.0000828177f, 0.0001129118f, 0.0001413312f, 0.0001673905f, 0.0001904409f, 0.0002098828f, 0.0002251816f,
+ 0.0002358781f, 0.0002416012f, 0.0002420750f, 0.0002371285f, 0.0002266990f, 0.0002108387f, 0.0001897144f, 0.0001636105f,
+ 0.0001329251f, 0.0000981694f, 0.0000599596f, 0.0000190121f, -0.0000238695f, -0.0000678035f, -0.0001118486f, -0.0001550177f,
+ -0.0001963012f, -0.0002346852f, -0.0002691787f, -0.0002988340f, -0.0003227757f, -0.0003402211f, -0.0003505078f, -0.0003531107f,
+ -0.0003476646f, -0.0003339751f, -0.0003120340f, -0.0002820207f, -0.0002443090f, -0.0001994588f, -0.0001482132f, -0.0000914813f,
+ -0.0000303277f, 0.0000340527f, 0.0001003514f, 0.0001671757f, 0.0002330697f, 0.0002965468f, 0.0003561116f, 0.0004102952f,
+ 0.0004576768f, 0.0004969199f, 0.0005267939f, 0.0005462097f, 0.0005542410f, 0.0005501582f, 0.0005334466f, 0.0005038372f,
+ 0.0004613187f, 0.0004061612f, 0.0003389189f, 0.0002604423f, 0.0001718676f, 0.0000746148f, -0.0000296392f, -0.0001389767f,
+ -0.0002512831f, -0.0003642749f, -0.0004755563f, -0.0005826556f, -0.0006830878f, -0.0007743933f, -0.0008542007f, -0.0009202618f,
+ -0.0009705111f, -0.0010030942f, -0.0010164239f, -0.0010092036f, -0.0009804838f, -0.0009296846f, -0.0008566574f, -0.0007617096f,
+ -0.0006456731f, -0.0005099278f, -0.0003564679f, -0.0001879096f, -0.0000075330f, 0.0001807554f, 0.0003724395f, 0.0005625175f,
+ 0.0007456177f, 0.0009162481f, 0.0010690442f, 0.0011991672f, 0.0013026871f, 0.0013771151f, 0.0014218793f, 0.0014389208f,
+ 0.0014331600f, 0.0014130261f, 0.0013907522f, 0.0013826603f, 0.0014090891f, 0.0014942408f, 0.0016655626f, 0.0019530043f,
+ 0.0023877813f, 0.0030010282f, 0.0038221874f, 0.0048773753f, 0.0061889900f, 0.0077755997f, 0.0096751224f, 0.0119741302f,
+ 0.0145439912f, 0.0169456183f, 0.0187073400f, 0.0194030360f, 0.0186550704f, 0.0161628228f, 0.0117223361f, 0.0052458122f,
+ -0.0032269514f, -0.0135216735f, -0.0253307510f, -0.0382203402f, -0.0516449105f, -0.0649674012f, -0.0774853341f, -0.0884609329f,
+ -0.0971548077f, -0.1028611423f, -0.1049434729f, -0.1028690049f, -0.0962403901f, -0.0848231076f, -0.0685674901f, -0.0476239362f,
+ -0.0223507100f, 0.0066865637f, 0.0387237751f, 0.0728157951f, 0.1078619795f, 0.1426392416f, 0.1758415350f, 0.2061246656f,
+ 0.2321547755f, 0.2526589705f, 0.2664761293f, 0.2726061478f, 0.2702555997f, 0.2588781212f, 0.2382077111f, 0.2082835801f,
+ 0.1694652065f, 0.1224367910f, 0.0682004341f, 0.0080579540f, -0.0564185505f, -0.1234266811f, -0.1909833663f, -0.2569826708f,
+ -0.3192601922f, -0.3756619825f, -0.4241159008f, -0.4627029725f, -0.4897264437f, -0.5037760457f, -0.5037852577f, -0.4890793474f,
+ -0.4594123986f, -0.4149916704f, -0.3564881936f, -0.2850327525f, -0.2021970477f, -0.1099601299f, -0.0106608717f, 0.0930624757f,
+ 0.1983439454f, 0.3021708437f, 0.4014716150f, 0.4932080681f, 0.5744690342f, 0.6425626416f, 0.6951041455f, 0.7300965662f,
+ 0.7460013189f, 0.7417965309f, 0.7170208283f, 0.6718010612f, 0.6068626327f, 0.5235219179f, 0.4236604995f, 0.3096818407f,
+ 0.1844512322f, 0.0512207469f, -0.0864589501f, -0.2248372460f, -0.3600700554f, -0.4883307618f, -0.6059225628f, -0.7093885522f,
+ -0.7956164474f, -0.8619344004f, -0.9061952044f, -0.9268458353f, -0.9229804407f, -0.8943745512f, -0.8414997451f, -0.7655175933f,
+ -0.6682534406f, -0.5521499681f, -0.4202024874f, -0.2758769248f, -0.1230137793f, 0.0342802674f, 0.1917486212f, 0.3451070280f,
+ 0.4901663081f, 0.6229542130f, 0.7398298367f, 0.8375910214f, 0.9135663759f, 0.9656969770f, 0.9925961604f, 0.9936618731f,
+ 0.9690844417f, 0.9196504635f, 0.8467117373f, 0.7522210603f, 0.6386799560f, 0.5090760386f, 0.3668025779f, 0.2155702981f,
+ 0.0593086479f, -0.0979369079f, -0.2521117236f, -0.3992577525f, -0.5356173001f, -0.6577304376f, -0.7625247715f, -0.8473940864f,
+ -0.9102647317f, -0.9496471895f, -0.9646722171f, -0.9551100144f, -0.9213725472f, -0.8644985297f, -0.7861220221f, -0.6884251575f,
+ -0.5740767467f, -0.4461581538f, -0.3080788471f, -0.1634836803f, -0.0161547423f, 0.1300897818f, 0.2714967454f, 0.4044766502f,
+ 0.5256968794f, 0.6321672656f, 0.7213155657f, 0.7910510602f, 0.8398145087f, 0.8666133944f, 0.8710415117f, 0.8532826677f,
+ 0.8140984457f, 0.7548006627f, 0.6772093367f, 0.5835975864f, 0.4766250203f, 0.3592616720f, 0.2347045793f, 0.1062894680f,
+ -0.0226000741f, -0.1486233373f, -0.2685707508f, -0.3794472128f, -0.4785483597f, -0.5635277262f, -0.6324531653f, -0.6838510882f,
+ -0.7167375675f, -0.7306356074f, -0.7255783918f, -0.7020986046f, -0.6612044089f, -0.6043429290f, -0.5333525140f, -0.4504052564f,
+ -0.3579415767f, -0.2585987895f, -0.1551357820f, -0.0503559257f, 0.0529695663f, 0.1521757603f, 0.2447735547f, 0.3285128639f,
+ 0.4014377748f, 0.4619323450f, 0.5087559395f, 0.5410673824f, 0.5584374718f, 0.5608498058f, 0.5486901404f, 0.5227248799f,
+ 0.4840695396f, 0.4341483415f, 0.3746462780f, 0.3074552135f, 0.2346156774f, 0.1582561348f, 0.0805315031f, 0.0035627058f,
+ -0.0706210625f, -0.1401357650f, -0.2032902555f, -0.2586270896f, -0.3049554547f, -0.3413754822f, -0.3672935096f, -0.3824281003f,
+ -0.3868069422f, -0.3807549745f, -0.3648743722f, -0.3400172139f, -0.3072518737f, -0.2678243125f, -0.2231155831f, -0.1745969158f,
+ -0.1237838039f, -0.0721904757f, -0.0212861041f, 0.0275460057f, 0.0730451234f, 0.1141047432f, 0.1497983924f, 0.1793990348f,
+ 0.2023917050f, 0.2184792403f, 0.2275811871f, 0.2298261737f, 0.2255382274f, 0.2152176942f, 0.1995175598f, 0.1792160900f,
+ 0.1551867943f, 0.1283667617f, 0.0997244393f, 0.0702278948f, 0.0408145632f, 0.0123633806f, -0.0143298873f, -0.0385734628f,
+ -0.0597959924f, -0.0775582602f, -0.0915599770f, -0.1016416466f, -0.1077816401f, -0.1100888003f, -0.1087910023f, -0.1042202530f,
+ -0.0967949724f, -0.0870002132f, -0.0753665756f, -0.0624486407f, -0.0488036800f, -0.0349714234f, -0.0214555345f, -0.0087074338f,
+ 0.0028870743f, 0.0130179511f, 0.0214576480f, 0.0280642424f, 0.0327810674f, 0.0356329290f, 0.0367192621f, 0.0362045427f,
+ 0.0343065259f, 0.0312827821f, 0.0274162441f, 0.0230002982f, 0.0183241826f, 0.0136591847f, 0.0092463500f, 0.0052860575f,
+ 0.0019300215f, -0.0007241258f, -0.0026354098f, -0.0038192546f, -0.0043449892f, -0.0043308242f, -0.0039467893f, -0.0034183427f,
+ -0.0028980777f, -0.0024111931f, -0.0019661658f, -0.0015766458f, -0.0012505436f, -0.0009916652f, -0.0007991070f, -0.0006687325f,
+ -0.0005935987f, -0.0005651424f, -0.0005737315f, -0.0006095407f, -0.0006629742f, -0.0007252278f, -0.0007885086f, -0.0008463178f,
+ -0.0008934778f, -0.0009262011f, -0.0009419761f, -0.0009394996f, -0.0009184875f, -0.0008795438f, -0.0008239543f, -0.0007535478f,
+ -0.0006705140f, -0.0005772899f, -0.0004764213f, -0.0003704871f, -0.0002620058f, -0.0001533948f, -0.0000469126f, 0.0000553574f,
+ 0.0001515421f, 0.0002399825f, 0.0003192564f, 0.0003881782f, 0.0004458153f, 0.0004914859f, 0.0005247706f, 0.0005455066f,
+ 0.0005537921f, 0.0005499733f, 0.0005346385f, 0.0005085956f, 0.0004728546f, 0.0004285952f, 0.0003771392f, 0.0003199107f,
+ 0.0002584034f, 0.0001941376f, 0.0001286276f, 0.0000633423f, -0.0000003230f, -0.0000610784f, -0.0001177585f, -0.0001693439f,
+ -0.0002149716f, -0.0002539451f, -0.0002857364f, -0.0003099879f, -0.0003265074f, -0.0003352642f, -0.0003363800f, -0.0003301214f,
+ -0.0003168882f, -0.0002972036f, -0.0002717009f, -0.0002411115f, -0.0002062492f, -0.0001679960f, -0.0001272837f, -0.0000850767f,
+ -0.0000423512f, -0.0000000757f, 0.0000408118f, 0.0000794235f, 0.0001149437f, 0.0001466472f, 0.0001739170f, 0.0001962578f,
+ 0.0002133072f, 0.0002248417f, 0.0002307793f, 0.0002311773f, 0.0002262259f, 0.0002162377f, 0.0002016344f, 0.0001829302f,
+ 0.0001607141f, 0.0001356302f, 0.0001083590f, 0.0000795981f, 0.0000500456f, 0.0000203831f, -0.0000087366f, -0.0000367025f,
+ -0.0000629538f, -0.0000869878f, -0.0001083652f, -0.0001267149f, -0.0001417362f, -0.0001532019f, -0.0001609587f, -0.0001649294f,
+ -0.0001651125f, -0.0001615824f, -0.0001544884f, -0.0001440526f, -0.0001305669f, -0.0001143883f, -0.0000959318f, -0.0000756626f,
+ -0.0000540855f, -0.0000317331f, -0.0000091523f, 0.0000131100f, 0.0000345222f, 0.0000545822f, 0.0000728319f, 0.0000888696f,
+ 0.0001023607f, 0.0001130460f, 0.0001207471f, 0.0001253683f, 0.0001268968f, 0.0001253988f, 0.0001210137f, 0.0001139460f,
+ -0.0000409890f, -0.0000231831f, -0.0000044979f, 0.0000146405f, 0.0000337894f, 0.0000524983f, 0.0000703210f, 0.0000868245f,
+ 0.0001016007f, 0.0001142746f, 0.0001245146f, 0.0001320387f, 0.0001366230f, 0.0001381059f, 0.0001363940f, 0.0001314632f,
+ 0.0001233624f, 0.0001122120f, 0.0000982042f, 0.0000815988f, 0.0000627207f, 0.0000419531f, 0.0000197321f, -0.0000034635f,
+ -0.0000271191f, -0.0000506974f, -0.0000736478f, -0.0000954205f, -0.0001154773f, -0.0001333068f, -0.0001484351f, -0.0001604403f,
+ -0.0001689621f, -0.0001737145f, -0.0001744920f, -0.0001711796f, -0.0001637549f, -0.0001522934f, -0.0001369666f, -0.0001180419f,
+ -0.0000958757f, -0.0000709093f, -0.0000436571f, -0.0000146989f, 0.0000153358f, 0.0000457778f, 0.0000759362f, 0.0001051099f,
+ 0.0001326066f, 0.0001577542f, 0.0001799192f, 0.0001985179f, 0.0002130330f, 0.0002230225f, 0.0002281351f, 0.0002281154f,
+ 0.0002228168f, 0.0002122035f, 0.0001963592f, 0.0001754845f, 0.0001499022f, 0.0001200490f, 0.0000864751f, 0.0000498314f,
+ 0.0000108634f, -0.0000296076f, -0.0000706952f, -0.0001114718f, -0.0001509832f, -0.0001882759f, -0.0002224138f, -0.0002525068f,
+ -0.0002777271f, -0.0002973368f, -0.0003107015f, -0.0003173138f, -0.0003168019f, -0.0003089482f, -0.0002936908f, -0.0002711354f,
+ -0.0002415497f, -0.0002053687f, -0.0001631812f, -0.0001157294f, -0.0000638885f, -0.0000086610f, 0.0000488496f, 0.0001074488f,
+ 0.0001658824f, 0.0002228496f, 0.0002770388f, 0.0003271423f, 0.0003718955f, 0.0004100930f, 0.0004406281f, 0.0004625082f,
+ 0.0004748944f, 0.0004771120f, 0.0004686867f, 0.0004493486f, 0.0004190617f, 0.0003780176f, 0.0003266564f, 0.0002656483f,
+ 0.0001959041f, 0.0001185450f, 0.0000349034f, -0.0000535185f, -0.0001450543f, -0.0002379235f, -0.0003302403f, -0.0004200698f,
+ -0.0005054364f, -0.0005843853f, -0.0006549896f, -0.0007154171f, -0.0007639381f, -0.0007990015f, -0.0008192451f, -0.0008235853f,
+ -0.0008112325f, -0.0007817958f, -0.0007353001f, -0.0006723017f, -0.0005938949f, -0.0005018237f, -0.0003984545f, -0.0002868589f,
+ -0.0001707179f, -0.0000543437f, 0.0000575249f, 0.0001597921f, 0.0002473552f, 0.0003152810f, 0.0003593211f, 0.0003761803f,
+ 0.0003641895f, 0.0003236064f, 0.0002574060f, 0.0001714998f, 0.0000755882f, -0.0000168765f, -0.0000877911f, -0.0001149323f,
+ -0.0000708145f, 0.0000759664f, 0.0003632082f, 0.0008340171f, 0.0015932147f, 0.0027965684f, 0.0044938862f, 0.0066209827f,
+ 0.0090614394f, 0.0116532691f, 0.0142012098f, 0.0164868538f, 0.0182824288f, 0.0193635282f, 0.0195233202f, 0.0185852780f,
+ 0.0164156862f, 0.0129338578f, 0.0081207820f, 0.0020247377f, -0.0052355839f, -0.0134714261f, -0.0224272216f, -0.0317873061f,
+ -0.0411854169f, -0.0502171478f, -0.0584545493f, -0.0654627361f, -0.0708175739f, -0.0741240923f, -0.0750346389f, -0.0732663141f,
+ -0.0686167330f, -0.0609776578f, -0.0503456776f, -0.0368295907f, -0.0206538852f, -0.0021581782f, 0.0182077069f, 0.0398928946f,
+ 0.0622588452f, 0.0845965541f, 0.1061472474f, 0.1261258801f, 0.1437468496f, 0.1582510183f, 0.1689332690f, 0.1751695690f,
+ 0.1764426874f, 0.1723655442f, 0.1627013795f, 0.1473798510f, 0.1265084200f, 0.1003783769f, 0.0694651504f, 0.0344225859f,
+ -0.0039288047f, -0.0446195451f, -0.0865544564f, -0.1285410062f, -0.1693219800f, -0.2076116501f, -0.2421343744f, -0.2716645414f,
+ -0.2950666012f, -0.3113339711f, -0.3196255083f, -0.3192983638f, -0.3099360208f, -0.2913705151f, -0.2636979059f, -0.2272863207f,
+ -0.1827760335f, -0.1310713384f, -0.0733241526f, -0.0109096078f, 0.0546059294f, 0.1215036544f, 0.1879570196f, 0.2520811416f,
+ 0.3119856181f, 0.3658292498f, 0.4118751262f, 0.4485444179f, 0.4744672713f, 0.4885291873f, 0.4899114116f, 0.4781239515f,
+ 0.4530300662f, 0.4148612531f, 0.3642220549f, 0.3020842490f, 0.2297703310f, 0.1489264657f, 0.0614854435f, -0.0303795649f,
+ -0.1243093268f, -0.2178195955f, -0.3083672722f, -0.3934199265f, -0.4705267388f, -0.5373888894f, -0.5919273479f, -0.6323460927f,
+ -0.6571888364f, -0.6653875249f, -0.6563010343f, -0.6297427848f, -0.5859962378f, -0.5258176130f, -0.4504254723f, -0.3614772269f,
+ -0.2610329551f, -0.1515073286f, -0.0356107555f, 0.0837187871f, 0.2033915080f, 0.3202471384f, 0.4311396943f, 0.5330233362f,
+ 0.6230369707f, 0.6985851980f, 0.7574133141f, 0.7976741718f, 0.8179849388f, 0.8174720079f, 0.7958026627f, 0.7532024103f,
+ 0.6904573239f, 0.6089011023f, 0.5103870229f, 0.3972453408f, 0.2722271452f, 0.1384360281f, -0.0007506793f, -0.1417690856f,
+ -0.2809620112f, -0.4146758861f, -0.5393586304f, -0.6516558729f, -0.7485028256f, -0.8272092868f, -0.8855353494f, -0.9217556888f,
+ -0.9347105366f, -0.9238418625f, -0.8892136169f, -0.8315153830f, -0.7520491685f, -0.6526996069f, -0.5358882111f, -0.4045128580f,
+ -0.2618739995f, -0.1115895724f, 0.0424992034f, 0.1964285728f, 0.3462168980f, 0.4879703230f, 0.6179866516f, 0.7328545277f,
+ 0.8295452782f, 0.9054947981f, 0.9586733060f, 0.9876409196f, 0.9915876025f, 0.9703562358f, 0.9244482541f, 0.8550115930f,
+ 0.7638112998f, 0.6531839260f, 0.5259766298f, 0.3854793593f, 0.2353470917f, 0.0794266997f, -0.0783736011f, -0.2341094912f,
+ -0.3838855272f, -0.5239604170f, -0.6508401618f, -0.7613664334f, -0.8527950879f, -0.9228648741f, -0.9698533854f, -0.9926197484f,
+ -0.9906323266f, -0.9639812550f, -0.9133750995f, -0.8401220648f, -0.7460959702f, -0.6336880996f, -0.5057459675f, -0.3655007408f,
+ -0.2164850263f, -0.0624432571f, 0.0927631497f, 0.2452533396f, 0.3912248813f, 0.5270493663f, 0.6493633998f, 0.7551526079f,
+ 0.8418266049f, 0.9072829806f, 0.9499587608f, 0.9688680208f, 0.9636247817f, 0.9344506105f, 0.8821668237f, 0.8081715061f,
+ 0.7144020216f, 0.6032839905f, 0.4776681160f, 0.3407564859f, 0.1960202987f, 0.0471111158f, -0.1022320452f, -0.2482774188f,
+ -0.3873945568f, -0.5161453835f, -0.6313699144f, -0.7302645031f, -0.8104506434f, -0.8700326423f, -0.9076427350f, -0.9224725808f,
+ -0.9142903937f, -0.8834433701f, -0.8308454204f, -0.7579506175f, -0.6667131091f, -0.5595346127f, -0.4392008921f, -0.3088089180f,
+ -0.1716866150f, -0.0313073005f, 0.1087989808f, 0.2451349347f, 0.3743240333f, 0.4931948249f, 0.5988594260f, 0.6887842282f,
+ 0.7608510829f, 0.8134074688f, 0.8453044545f, 0.8559215759f, 0.8451781058f, 0.8135305285f, 0.7619564059f, 0.6919251500f,
+ 0.6053565671f, 0.5045683259f, 0.3922137963f, 0.2712119195f, 0.1446709795f, 0.0158082697f, -0.1121322505f, -0.2359621952f,
+ -0.3526287795f, -0.4592906218f, -0.5533874164f, -0.6327017647f, -0.6954116543f, -0.7401323484f, -0.7659467130f, -0.7724233338f,
+ -0.7596220816f, -0.7280871206f, -0.6788276697f, -0.6132871451f, -0.5333015981f, -0.4410486347f, -0.3389882280f, -0.2297970351f,
+ -0.1162979714f, -0.0013869076f, 0.1120416061f, 0.2211676650f, 0.3233165238f, 0.4160245192f, 0.4970987736f, 0.5646692200f,
+ 0.6172317171f, 0.6536812560f, 0.6733345403f, 0.6759414941f, 0.6616855531f, 0.6311728784f, 0.5854109229f, 0.5257770441f,
+ 0.4539781120f, 0.3720022713f, 0.2820642158f, 0.1865454701f, 0.0879312930f, -0.0112541288f, -0.1085124968f, -0.2014345624f,
+ -0.2877600257f, -0.3654326821f, -0.4326494615f, -0.4879021964f, -0.5300111477f, -0.5581495604f, -0.5718587503f, -0.5710534933f,
+ -0.5560177281f, -0.5273908494f, -0.4861450978f, -0.4335547859f, -0.3711582904f, -0.3007139250f, -0.2241509378f, -0.1435169935f,
+ -0.0609235618f, 0.0215093313f, 0.1017075454f, 0.1776950580f, 0.2476426746f, 0.3099120105f, 0.3630936929f, 0.4060388941f,
+ 0.4378835058f, 0.4580644620f, 0.4663279432f, 0.4627294004f, 0.4476255675f, 0.4216588257f, 0.3857344863f, 0.3409917280f,
+ 0.2887690825f, 0.2305654810f, 0.1679979813f, 0.1027573461f, 0.0365626923f, -0.0288835867f, -0.0919394404f, -0.1510642130f,
+ -0.2048561002f, -0.2520851099f, -0.2917207545f, -0.3229538699f, -0.3452121154f, -0.3581688961f, -0.3617456210f, -0.3561073997f,
+ -0.3416524423f, -0.3189955996f, -0.2889466186f, -0.2524838235f, -0.2107240303f, -0.1648895947f, -0.1162735377f, -0.0662037318f,
+ -0.0160071241f, 0.0330250452f, 0.0796701284f, 0.1228042256f, 0.1614288774f, 0.1946936678f, 0.2219142443f, 0.2425853919f,
+ 0.2563889487f, 0.2631964891f, 0.2630668532f, 0.2562387302f, 0.2431186436f, 0.2242647892f, 0.2003672939f, 0.1722255274f,
+ 0.1407231814f, 0.1068018529f, 0.0714339071f, 0.0355953755f, 0.0002396385f, -0.0337274180f, -0.0654701262f, -0.0942430905f,
+ -0.1194080954f, -0.1404475082f, -0.1569739116f, -0.1687358288f, -0.1756195042f, -0.1776468257f, -0.1749695713f, -0.1678602690f,
+ -0.1567000359f, -0.1419638484f, -0.1242037381f, -0.1040304695f, -0.0820942616f, -0.0590651422f, -0.0356134981f, -0.0123913771f,
+ 0.0099849609f, 0.0309507800f, 0.0500065129f, 0.0667289886f, 0.0807800207f, 0.0919121972f, 0.0999718200f, 0.1048990098f,
+ 0.1067250926f, 0.1055674412f, 0.1016220359f, 0.0951540418f, 0.0864867765f, 0.0759894469f, 0.0640640860f, 0.0511321002f,
+ 0.0376208624f, 0.0239507391f, 0.0105229429f, -0.0022914718f, -0.0141611639f, -0.0248023986f, -0.0339850878f, -0.0415368905f,
+ -0.0473453103f, -0.0513578334f, -0.0535801684f, -0.0540727489f, -0.0529456678f, -0.0503522968f, -0.0464818329f, -0.0415510875f,
+ -0.0357957930f, -0.0294617627f, -0.0227961726f, -0.0160392815f, -0.0094168137f, -0.0031332654f, 0.0026337157f, 0.0077376956f,
+ 0.0120665112f, 0.0155439285f, 0.0181299546f, 0.0198198008f, 0.0206416522f, 0.0206533153f, 0.0199379832f, 0.0185992414f,
+ 0.0167556135f, 0.0145347842f, 0.0120678335f, 0.0094835966f, 0.0069034859f, 0.0044368299f, 0.0021770482f, 0.0001986183f,
+ -0.0014448717f, -0.0027217639f, -0.0036221831f, -0.0041570536f, -0.0043559653f, -0.0042644747f, -0.0039403827f, -0.0034499387f,
+ -0.0028631090f, -0.0022496331f, -0.0016738218f, -0.0011929502f, -0.0008370454f, -0.0005846760f, -0.0004048972f, -0.0002842065f,
+ -0.0002119725f, -0.0001785258f, -0.0001746762f, -0.0001920559f, -0.0002230524f, -0.0002610877f, -0.0003005688f, -0.0003370221f,
+ -0.0003669912f, -0.0003880546f, -0.0003986770f, -0.0003981548f, -0.0003864480f, -0.0003640945f, -0.0003320500f, -0.0002916028f,
+ -0.0002442394f, -0.0001915781f, -0.0001352688f, -0.0000769517f, -0.0000181891f, 0.0000395524f, 0.0000949441f, 0.0001467973f,
+ 0.0001940871f, 0.0002359457f, 0.0002716760f, 0.0003007405f, 0.0003227698f, 0.0003375491f, 0.0003450236f, 0.0003452833f,
+ 0.0003385643f, 0.0003252319f, 0.0003057766f, 0.0002807946f, 0.0002509791f, 0.0002170975f, 0.0001799788f, 0.0001404893f,
+ 0.0000995183f, 0.0000579532f, 0.0000166659f, -0.0000235093f, -0.0000617873f, -0.0000974508f, -0.0001298571f, -0.0001584526f,
+ -0.0001827754f, -0.0002024649f, -0.0002172605f, -0.0002270070f, -0.0002316506f, -0.0002312399f, -0.0002259201f, -0.0002159308f,
+ -0.0002015976f, -0.0001833276f, -0.0001615981f, -0.0001369497f, -0.0001099729f, -0.0000812980f, -0.0000515797f, -0.0000214856f,
+ 0.0000083213f, 0.0000371946f, 0.0000645215f, 0.0000897344f, 0.0001123264f, 0.0001318594f, 0.0001479763f, 0.0001604052f,
+ 0.0001689663f, 0.0001735714f, 0.0001742252f, 0.0001710200f, 0.0001641324f, 0.0001538135f, 0.0001403825f, 0.0001242143f,
+ 0.0001057308f, 0.0000853884f, 0.0000636683f, 0.0000410646f, 0.0000180754f, -0.0000048078f, -0.0000271075f, -0.0000483697f,
+ -0.0000681699f, -0.0000861206f, -0.0001018770f, -0.0001151429f, -0.0001256753f, -0.0001332891f, -0.0001378602f, -0.0001393293f,
+ -0.0001377022f, -0.0001330520f, -0.0001255166f, -0.0001152976f, -0.0001026555f, -0.0000879046f, -0.0000714049f, -0.0000535546f,
+ -0.0000347786f, -0.0000155193f, 0.0000037762f, 0.0000226667f, 0.0000407288f, 0.0000575664f, 0.0000728215f, 0.0000861808f,
+ 0.0000582411f, 0.0000747547f, 0.0000898871f, 0.0001032552f, 0.0001145066f, 0.0001233290f, 0.0001294588f, 0.0001326885f,
+ 0.0001328735f, 0.0001299377f, 0.0001238768f, 0.0001147609f, 0.0001027340f, 0.0000880132f, 0.0000708843f, 0.0000516966f,
+ 0.0000308558f, 0.0000088150f, -0.0000139353f, -0.0000368781f, -0.0000594822f, -0.0000812142f, -0.0001015508f, -0.0001199912f,
+ -0.0001360692f, -0.0001493631f, -0.0001595073f, -0.0001661997f, -0.0001692106f, -0.0001683879f, -0.0001636621f, -0.0001550493f,
+ -0.0001426526f, -0.0001266610f, -0.0001073481f, -0.0000850672f, -0.0000602464f, -0.0000333807f, -0.0000050232f, 0.0000242254f,
+ 0.0000537286f, 0.0000828270f, 0.0001108523f, 0.0001371418f, 0.0001610527f, 0.0001819781f, 0.0001993603f, 0.0002127056f,
+ 0.0002215967f, 0.0002257043f, 0.0002247967f, 0.0002187482f, 0.0002075440f, 0.0001912841f, 0.0001701836f, 0.0001445712f,
+ 0.0001148842f, 0.0000816622f, 0.0000455367f, 0.0000072204f, -0.0000325082f, -0.0000728185f, -0.0001128466f, -0.0001517120f,
+ -0.0001885378f, -0.0002224679f, -0.0002526873f, -0.0002784386f, -0.0002990404f, -0.0003139008f, -0.0003225330f, -0.0003245650f,
+ -0.0003197504f, -0.0003079739f, -0.0002892583f, -0.0002637651f, -0.0002317973f, -0.0001937968f, -0.0001503441f, -0.0001021521f,
+ -0.0000500632f, 0.0000049600f, 0.0000618411f, 0.0001194039f, 0.0001763844f, 0.0002314533f, 0.0002832366f, 0.0003303508f,
+ 0.0003714378f, 0.0004052165f, 0.0004305340f, 0.0004464367f, 0.0004522372f, 0.0004476003f, 0.0004326187f, 0.0004079029f,
+ 0.0003746497f, 0.0003347161f, 0.0002906568f, 0.0002457555f, 0.0002040014f, 0.0001700503f, 0.0001491128f, 0.0001468223f,
+ 0.0001690255f, 0.0002215535f, 0.0003099526f, 0.0004392070f, 0.0006136491f, 0.0008369098f, 0.0011153908f, 0.0014626641f,
+ 0.0018595375f, 0.0022395932f, 0.0025311249f, 0.0026688715f, 0.0025944027f, 0.0022604100f, 0.0016336976f, 0.0006981998f,
+ -0.0005431676f, -0.0020672947f, -0.0038308355f, -0.0057710271f, -0.0078076165f, -0.0098456303f, -0.0117790591f, -0.0134951832f,
+ -0.0148794917f, -0.0158209062f, -0.0162171833f, -0.0159802046f, -0.0150409946f, -0.0133541921f, -0.0109018245f, -0.0076961552f,
+ -0.0037814932f, 0.0007651902f, 0.0058348824f, 0.0112884531f, 0.0169598389f, 0.0226604555f, 0.0281847079f, 0.0333164681f,
+ 0.0378363117f, 0.0415293031f, 0.0441930617f, 0.0456458479f, 0.0457343703f, 0.0443410397f, 0.0413903773f, 0.0368543265f,
+ 0.0307562218f, 0.0231732263f, 0.0142370712f, 0.0041330029f, -0.0069031215f, -0.0185895710f, -0.0306052464f, -0.0425978140f,
+ -0.0541932843f, -0.0650067808f, -0.0746542114f, -0.0827644992f, -0.0889920115f, -0.0930287926f, -0.0946162074f, -0.0935555973f,
+ -0.0897175729f, -0.0830495883f, -0.0735814928f, -0.0614287943f, -0.0467934430f, -0.0299620019f, -0.0113011569f, 0.0087494102f,
+ 0.0296866709f, 0.0509562355f, 0.0719663997f, 0.0921039151f, 0.1107510726f, 0.1273036411f, 0.1411891551f, 0.1518850212f,
+ 0.1589358970f, 0.1619698015f, 0.1607124306f, 0.1549991925f, 0.1447845216f, 0.1301481022f, 0.1112977047f, 0.0885684336f,
+ 0.0624182781f, 0.0334199675f, 0.0022492343f, -0.0303302958f, -0.0634852726f, -0.0963334260f, -0.1279665024f, -0.1574747445f,
+ -0.1839722700f, -0.2066226519f, -0.2246639837f, -0.2374326975f, -0.2443854241f, -0.2451182136f, -0.2393824923f, -0.2270972049f,
+ -0.2083566840f, -0.1834338958f, -0.1527788314f, -0.1170119438f, -0.0769126672f, -0.0334031935f, 0.0124721800f, 0.0595716856f,
+ 0.1066841340f, 0.1525596967f, 0.1959426466f, 0.2356052084f, 0.2703816159f, 0.2992014435f, 0.3211212759f, 0.3353538037f,
+ 0.3412934754f, 0.3385379160f, 0.3269044144f, 0.3064409015f, 0.2774309795f, 0.2403927139f, 0.1960710651f, 0.1454240053f,
+ 0.0896025447f, 0.0299250576f, -0.0321535327f, -0.0950769985f, -0.1572266359f, -0.2169627100f, -0.2726674612f, -0.3227885475f,
+ -0.3658817647f, -0.4006518763f, -0.4259904152f, -0.4410093734f, -0.4450697851f, -0.4378043259f, -0.4191331941f, -0.3892727036f,
+ -0.3487362065f, -0.2983271575f, -0.2391243433f, -0.1724595094f, -0.0998878249f, -0.0231518277f, 0.0558603212f, 0.1351612774f,
+ 0.2127145048f, 0.2864865610f, 0.3545003342f, 0.4148878376f, 0.4659411557f, 0.5061601567f, 0.5342956523f, 0.5493867774f,
+ 0.5507914983f, 0.5382093212f, 0.5116954608f, 0.4716659463f, 0.4188933721f, 0.3544932422f, 0.2799011075f, 0.1968409421f,
+ 0.1072854415f, 0.0134091535f, -0.0824644450f, -0.1779206367f, -0.2705144779f, -0.3578335937f, -0.4375611342f, -0.5075372480f,
+ -0.5658174366f, -0.6107262192f, -0.6409046287f, -0.6553502097f, -0.6534483577f, -0.6349940579f, -0.6002033141f, -0.5497138242f,
+ -0.4845747300f, -0.4062255582f, -0.3164647475f, -0.2174084443f, -0.1114405017f, -0.0011548715f, 0.1107082189f, 0.2213307209f,
+ 0.3278881365f, 0.4276219846f, 0.5179114992f, 0.5963426829f, 0.6607728958f, 0.7093892437f, 0.7407591825f, 0.7538719283f,
+ 0.7481694943f, 0.7235664280f, 0.6804576085f, 0.6197137625f, 0.5426646818f, 0.4510704345f, 0.3470811862f, 0.2331865442f,
+ 0.1121556241f, -0.0130307134f, -0.1392537831f, -0.2633353122f, -0.3821180118f, -0.4925464326f, -0.5917460154f, -0.6770982854f,
+ -0.7463102071f, -0.7974758632f, -0.8291287887f, -0.8402835311f, -0.8304652631f, -0.7997265817f, -0.7486509433f, -0.6783425346f,
+ -0.5904027183f, -0.4868935511f, -0.3702891985f, -0.2434164031f, -0.1093854415f, 0.0284867240f, 0.1667591937f, 0.3019536886f,
+ 0.4306427342f, 0.5495372068f, 0.6555710008f, 0.7459806116f, 0.8183775659f, 0.8708117817f, 0.9018241781f, 0.9104871053f,
+ 0.8964314857f, 0.8598598737f, 0.8015450208f, 0.7228138795f, 0.6255173800f, 0.5119866531f, 0.3849767570f, 0.2475992600f,
+ 0.1032453598f, -0.0444985629f, -0.1919408168f, -0.3353774466f, -0.4711860685f, -0.5959181193f, -0.7063871285f, -0.7997507598f,
+ -0.8735844695f, -0.9259448860f, -0.9554212155f, -0.9611733371f, -0.9429555253f, -0.9011251664f, -0.8366361515f, -0.7510170890f,
+ -0.6463347988f, -0.5251440036f, -0.3904244118f, -0.2455067964f, -0.0939898753f, 0.0603498686f, 0.2136531983f, 0.3620754993f,
+ 0.5018841040f, 0.6295530127f, 0.7418526589f, 0.8359323337f, 0.9093932351f, 0.9603501538f, 0.9874803034f, 0.9900578955f,
+ 0.9679736807f, 0.9217387716f, 0.8524727897f, 0.7618764115f, 0.6521892146f, 0.5261336069f, 0.3868465674f, 0.2378005415f,
+ 0.0827159689f, -0.0745329240f, -0.2300158926f, -0.3798465481f, -0.5202802756f, -0.6478099233f, -0.7592521853f, -0.8518447888f,
+ -0.9233379834f, -0.9720085218f, -0.9966758999f, -0.9967463299f, -0.9722295329f, -0.9237392201f, -0.8524778646f, -0.7602073639f,
+ -0.6492055631f, -0.5222103755f, -0.3823523682f, -0.2330778865f, -0.0780642593f, 0.0788705421f, 0.2338618240f, 0.3830931459f,
+ 0.5228902075f, 0.6498111734f, 0.7607313594f, 0.8529200672f, 0.9241077914f, 0.9725420391f, 0.9970304792f, 0.9969702721f,
+ 0.9723629327f, 0.9238142869f, 0.8525195846f, 0.7602340753f, 0.6492298214f, 0.5222397619f, 0.3823904496f, 0.2331250710f,
+ 0.0781186890f, -0.0788122482f, -0.2338038630f, -0.3830399929f, -0.5228461462f, -0.6497799862f, -0.7607160866f, -0.8529228980f,
+ -0.9241300035f, -0.9725840329f, -0.9970918334f, -0.9970498578f, -0.9724590238f, -0.9239246994f, -0.8526417953f, -0.7603653504f,
+ -0.6493673160f, -0.5223806210f, -0.3825318778f, -0.2332644031f, -0.0782534324f, 0.0786843684f, 0.2336848810f, 0.3829316749f,
+ 0.5227499799f, 0.6496971643f, 0.7606475046f, 0.8528691455f, 0.9240913688f, 0.9725605024f, 0.9970831041f, 0.9970553461f,
+ 0.9724778870f, 0.9239558554f, 0.8526839539f, 0.7604170426f, 0.6494269334f, 0.5224464521f, 0.3826021525f, 0.2333373314f,
+ 0.0783272488f, -0.0786113681f, -0.2336143011f, -0.3828649893f, -0.5226885022f, -0.6496420279f, -0.7605996436f, -0.8528292862f,
+ -0.9240600225f, -0.9725379675f, -0.9970694696f, -0.9970505028f, -0.9724815391f, -0.9239675382f, -0.8527030511f, -0.7604428078f,
+ -0.6494585103f, -0.5224828981f, -0.3826424594f, -0.2333804494f, -0.0783721069f, 0.0785658395f, 0.2335691502f, 0.3828212223f,
+ 0.5226470656f, 0.6496037895f, 0.7605653778f, 0.8527996583f, 0.9240355773f, 0.9725191181f, 0.9970564910f, 0.9970435264f,
+ 0.9724805522f, 0.9239723853f, 0.8527134405f, 0.7604583197f, 0.6494786105f, 0.5225069525f, 0.3826697534f, 0.2334102074f,
+ 0.0784035151f, -0.0785336112f, -0.2335369252f, -0.3827897961f, -0.5226171847f, -0.6495761346f, -0.7605405475f, -0.8527781579f,
+ -0.9240178096f, -0.9725053787f, -0.9970469656f, -0.9970382927f, -0.9724795834f, -0.9239755567f, -0.8527205369f, -0.7604690457f,
+ -0.6494926000f, -0.5225237804f, -0.3826889457f, -0.2334312532f, -0.0784258768f, 0.0785104868f, 0.2335135965f, 0.3827668158f,
+ 0.5225950899f, 0.6495554361f, 0.7605217198f, 0.8527616288f, 0.9240039504f, 0.9724944950f, 0.9970392893f, 0.9970339749f,
+ 0.9724786893f, 0.9239780624f, 0.8527263292f, 0.7604779239f, 0.6495042812f, 0.5225379070f, 0.3827050967f, 0.2334489562f,
+ 0.0784446231f, -0.0784912259f, -0.2334943534f, -0.3827481104f, -0.5225774136f, -0.6495392378f, -0.7605073937f, -0.8527495050f,
+ -0.9239942880f, -0.9724874781f, -0.9970350256f, -0.9970324969f, -0.9724799577f, -0.9239819717f, -0.8527327136f, -0.7604865652f,
+ -0.6495149161f, -0.5225502352f, -0.3827187881f, -0.2334636585f, -0.0784599687f, 0.0784756139f, 0.2334788543f, 0.3827330998f,
+ 0.5225632570f, 0.6495262837f, 0.7604959669f, 0.8527398987f, 0.9239867563f, 0.9724822286f, 0.9970322117f,
+};
+
+const float ivas_fb_fr_12band_1ms_im[IVAS_FB_12_1MS_LEN] =
+{
+ -0.0898684611f, -0.2670421131f, -0.4365041728f, -0.5932908852f, -0.7325431118f, -0.8497696909f, -0.9406026758f, -1.0013422309f,
+ -1.0229026702f, -0.9881074062f, -0.8887876846f, -0.7310424395f, -0.5284210279f, -0.2997529481f, -0.0664760115f, 0.1499611207f,
+ 0.3307974571f, 0.4621685196f, 0.5367125342f, 0.5543493827f, 0.5220560680f, 0.4529408018f, 0.3642519877f, 0.2760859332f,
+ 0.2047354522f, 0.1503391462f, 0.1061445796f, 0.0699189586f, 0.0406773254f, 0.0176462883f, 0.0000989137f, -0.0126721698f,
+ -0.0213825135f, -0.0267263252f, -0.0293754264f, -0.0299501298f, -0.0290147562f, -0.0270589183f, -0.0244976437f, -0.0216640086f,
+ -0.0188153473f, -0.0161349368f, -0.0137427038f, -0.0117024055f, -0.0100340803f, -0.0087231409f, -0.0077319011f, -0.0070077840f,
+ -0.0064920884f, -0.0061256992f, -0.0058543602f, -0.0056314631f, -0.0054200843f, -0.0051933287f, -0.0049340271f, -0.0046335801f,
+ -0.0042904244f, -0.0039083723f, -0.0034948095f, -0.0030592765f, -0.0026120102f, -0.0021631376f, -0.0017217846f, -0.0012959083f,
+ -0.0008918976f, -0.0005148542f, -0.0001684643f, 0.0001445255f, 0.0004223858f, 0.0006639324f, 0.0008686856f, 0.0010364896f,
+ 0.0011677783f, 0.0012632724f, 0.0013243012f, 0.0013525145f, 0.0013501876f, 0.0013198910f, 0.0012647346f, 0.0011879780f,
+ 0.0010932175f, 0.0009839640f, 0.0008638145f, 0.0007360481f, 0.0006038306f, 0.0004698724f, 0.0003366939f, 0.0002063576f,
+ 0.0000807864f, -0.0000384546f, -0.0001498232f, -0.0002520137f, -0.0003436527f, -0.0004235485f, -0.0004904478f, -0.0005433364f,
+ -0.0005812551f, -0.0006036329f, -0.0006101286f, -0.0006009525f, -0.0005766848f, -0.0005385389f, -0.0004881156f, -0.0004275804f,
+ -0.0003593427f, -0.0002861534f, -0.0002107341f, -0.0001358351f, -0.0000638656f, 0.0000030299f, 0.0000632842f, 0.0001157628f,
+ 0.0001599820f, 0.0001958747f, 0.0002239118f, 0.0002447961f, 0.0002595218f, 0.0002690444f, 0.0002743352f, 0.0002760865f,
+ 0.0002748168f, 0.0002706555f, 0.0002635301f, 0.0002530421f, 0.0002387283f, 0.0002200029f, 0.0001964510f, 0.0001677833f,
+ 0.0001341045f, 0.0000958227f, 0.0000538421f, 0.0000093907f, -0.0000358838f, -0.0000801695f, -0.0001214720f, -0.0001579178f,
+ -0.0001877626f, -0.0002096837f, -0.0002227536f, -0.0002266623f, -0.0002216081f, -0.0002084174f, -0.0001883368f, -0.0001630566f,
+ -0.0001344297f, -0.0001044404f, -0.0000749065f, -0.0000474557f, -0.0000232739f, -0.0000031484f, 0.0000126922f, 0.0000244381f,
+ 0.0000327553f, 0.0000385592f, 0.0000429983f, 0.0000471857f, 0.0000521670f, 0.0000586725f, 0.0000671313f, 0.0000774992f,
+ 0.0000893598f, 0.0001018532f, 0.0001138697f, 0.0001240625f, 0.0001311002f, 0.0001337149f, 0.0001309532f, 0.0001221967f,
+ 0.0001073512f, 0.0000867866f, 0.0000614274f, 0.0000325927f, 0.0000019882f, -0.0000285322f, -0.0000570333f, -0.0000817625f,
+ -0.0001012133f, -0.0001143489f, -0.0001206018f,
+ 0.0115080962f, 0.0339059662f, 0.0543805639f, 0.0716908215f, 0.0844892131f, 0.0915170903f, 0.0912773099f, 0.0825231458f,
+ 0.0581340647f, 0.0023722407f, -0.0920729561f, -0.2188408880f, -0.3647527624f, -0.5119701616f, -0.6406838355f, -0.7316665697f,
+ -0.7689724827f, -0.7420606704f, -0.6473949518f, -0.4890788171f, -0.2786409816f, -0.0338325103f, 0.2232845090f, 0.4688402469f,
+ 0.6798489622f, 0.8368463063f, 0.9260768759f, 0.9410292369f, 0.8830777791f, 0.7612013021f, 0.5907780504f, 0.3916368742f,
+ 0.1855876370f, -0.0062576017f, -0.1660331877f, -0.2812632874f, -0.3462706324f, -0.3628576835f, -0.3399405921f, -0.2936025661f,
+ -0.2446360780f, -0.2029515435f, -0.1662608743f, -0.1331801236f, -0.1036965299f, -0.0778301527f, -0.0556266777f, -0.0370208473f,
+ -0.0218709516f, -0.0099359945f, -0.0009127909f, 0.0055587915f, 0.0098621029f, 0.0123923627f, 0.0135300104f, 0.0136320444f,
+ 0.0130144200f, 0.0119494969f, 0.0106574266f, 0.0093099072f, 0.0080287757f, 0.0068943240f, 0.0059483248f, 0.0052043487f,
+ 0.0046523406f, 0.0042685237f, 0.0040192551f, 0.0038688810f, 0.0037816102f, 0.0037267014f, 0.0036781232f, 0.0036173442f,
+ 0.0035313060f, 0.0034136237f, 0.0032617350f, 0.0030774362f, 0.0028640174f, 0.0026268424f, 0.0023709699f, 0.0021021154f,
+ 0.0018248805f, 0.0015440826f, 0.0012634327f, 0.0009870117f, 0.0007181238f, 0.0004606754f, 0.0002179850f, -0.0000060719f,
+ -0.0002083660f, -0.0003855837f, -0.0005355681f, -0.0006564697f, -0.0007479765f, -0.0008103905f, -0.0008456256f, -0.0008561209f,
+ -0.0008455816f, -0.0008177548f, -0.0007769991f, -0.0007270455f, -0.0006715492f, -0.0006129898f, -0.0005533521f, -0.0004932746f,
+ -0.0004329280f, -0.0003714208f, -0.0003078363f, -0.0002408007f, -0.0001695470f, -0.0000934908f, -0.0000131639f, 0.0000703507f,
+ 0.0001547277f, 0.0002371760f, 0.0003140053f, 0.0003815783f, 0.0004360445f, 0.0004743392f, 0.0004939265f, 0.0004936813f,
+ 0.0004734847f, 0.0004348607f, 0.0003803348f, 0.0003137905f, 0.0002396098f, 0.0001628232f, 0.0000881507f, 0.0000200989f,
+ -0.0000379279f, -0.0000834126f, -0.0001153958f, -0.0001340265f, -0.0001409462f, -0.0001385916f, -0.0001303365f, -0.0001196396f,
+ -0.0001100798f, -0.0001045123f, -0.0001051708f, -0.0001129953f, -0.0001279408f, -0.0001485750f, -0.0001726416f, -0.0001969197f,
+ -0.0002179800f, -0.0002321940f, -0.0002365365f, -0.0002285757f, -0.0002071506f, -0.0001721838f, -0.0001251084f, -0.0000684218f,
+ -0.0000058329f, 0.0000584158f, 0.0001195994f, 0.0001732950f, 0.0002154726f, 0.0002432129f, 0.0002546651f, 0.0002495466f,
+ 0.0002438301f, 0.0007109472f, 0.0011162460f, 0.0013967943f, 0.0014698785f, 0.0012150300f, 0.0004822469f, -0.0009199449f,
+ -0.0032069948f, -0.0066234807f, -0.0114150534f, -0.0178284637f, -0.0260733522f, -0.0363216183f, -0.0486605071f, -0.0630990061f,
+ -0.0795130312f, -0.0976712096f, -0.1171685259f, -0.1374957541f, -0.1579441550f, -0.1777994651f, -0.1961712153f, -0.2131191727f,
+ -0.2256033924f, -0.2176912218f, -0.1719241079f, -0.0821949125f, 0.0489542717f, 0.2117008349f, 0.3903676656f, 0.5654257562f,
+ 0.7160273175f, 0.8226483779f, 0.8696490849f, 0.8473276976f, 0.7533117569f, 0.5930248684f, 0.3792476318f, 0.1307497118f,
+ -0.1297731860f, -0.3782729365f, -0.5920556328f, -0.7523549294f, -0.8463947331f, -0.8687564040f, -0.8218173622f, -0.7152833962f,
+ -0.5647972104f, -0.3898836504f, -0.2113895751f, -0.0488408019f, 0.0820902688f, 0.1715873934f, 0.2171153181f, 0.2247885078f,
+ 0.2120719043f, 0.1949040588f, 0.1763288922f, 0.1562894837f, 0.1356771490f, 0.1152063262f, 0.0955845402f, 0.0773202283f,
+ 0.0608172272f, 0.0463072409f, 0.0339148674f, 0.0236334444f, 0.0153777062f, 0.0089786185f, 0.0042273050f, 0.0008767894f,
+ -0.0013231927f, -0.0026245282f, -0.0032557343f, -0.0034239005f, -0.0032991260f, -0.0030209159f, -0.0026903446f, -0.0023798808f,
+ -0.0021307088f, -0.0019640207f, -0.0018807705f, -0.0018724257f, -0.0019209336f, -0.0020075151f, -0.0021115303f, -0.0022167724f,
+ -0.0023088853f, -0.0023794235f, -0.0024222081f, -0.0024359169f, -0.0024201044f, -0.0023771902f, -0.0023088214f, -0.0022179019f,
+ -0.0021056723f, -0.0019740384f, -0.0018233675f, -0.0016550209f, -0.0014695894f, -0.0012693378f, -0.0010565212f, -0.0008354568f,
+ -0.0006106656f, -0.0003884494f, -0.0001748112f, 0.0000233719f, 0.0002004956f, 0.0003512145f, 0.0004724032f, 0.0005620267f,
+ 0.0006206994f, 0.0006502675f, 0.0006548938f, 0.0006393557f, 0.0006097638f, 0.0005717449f, 0.0005310334f, 0.0004917912f,
+ 0.0004573339f, 0.0004288066f, 0.0004062166f, 0.0003875516f, 0.0003701287f, 0.0003500723f, 0.0003238297f, 0.0002877917f,
+ 0.0002397329f, 0.0001783203f, 0.0001042514f, 0.0000194643f, -0.0000721397f, -0.0001658244f, -0.0002556635f, -0.0003358859f,
+ -0.0004006984f, -0.0004456200f, -0.0004672301f, -0.0004642525f, -0.0004370215f, -0.0003881655f, -0.0003217097f, -0.0002433639f,
+ -0.0001593403f, -0.0000763999f, -0.0000005923f, 0.0000626983f, 0.0001098436f, 0.0001386930f, 0.0001493084f, 0.0001433260f,
+ 0.0001242838f, 0.0000966497f, 0.0000658480f, 0.0000371218f, 0.0000154755f, 0.0000046144f, 0.0000070450f, 0.0000233058f,
+ 0.0000523967f, 0.0000914031f, 0.0001362820f, 0.0001818299f, 0.0002227029f, 0.0002535449f, 0.0002700191f, 0.0002688537f,
+ 0.0002486530f, 0.0002096567f, 0.0001541806f, 0.0000860074f, 0.0000104494f, -0.0000665586f, -0.0001386343f, -0.0001999605f,
+ -0.0002454664f, -0.0002717048f, -0.0002768116f, -0.0002610555f, -0.0002264389f, -0.0001768539f, -0.0001173333f, -0.0000538987f,
+ 0.0000073883f, 0.0000606831f, 0.0001012735f, 0.0001257023f, 0.0001324276f, 0.0001216280f, 0.0000954836f, 0.0000576109f,
+ 0.0000129868f, -0.0000328906f, -0.0000742744f, -0.0001060758f, -0.0001240987f, -0.0001257785f, -0.0001101631f, -0.0000783123f,
+ -0.0000329127f, 0.0000217021f, 0.0000802673f, 0.0001368394f, 0.0001856737f, 0.0002215380f, 0.0002405175f, 0.0002401550f,
+ 0.0002199754f, 0.0001812890f, 0.0001273345f, 0.0000627166f, -0.0000067866f, -0.0000750345f, -0.0001358771f,
+ -0.0002517773f, -0.0007530438f, -0.0012480393f, -0.0017311495f, -0.0021966783f, -0.0026372659f, -0.0030463219f, -0.0034173391f,
+ -0.0037471961f, -0.0040359970f, -0.0042905892f, -0.0045239611f, -0.0047578551f, -0.0050204690f, -0.0053469980f, -0.0057745962f,
+ -0.0063401820f, -0.0070723578f, -0.0079867916f, -0.0090758990f, -0.0103033224f, -0.0115933185f, -0.0128269170f, -0.0138337134f,
+ -0.0143928060f, -0.0142296836f, -0.0130247299f, -0.0104168701f, -0.0060212390f, 0.0005608679f, 0.0097154142f, 0.0218030935f,
+ 0.0371260945f, 0.0559219991f, 0.0783277405f, 0.1044019092f, 0.1340918009f, 0.1673695867f, 0.2042412889f, 0.2460845096f,
+ 0.2951830943f, 0.3416235468f, 0.3646126368f, 0.3480671745f, 0.2830729765f, 0.1678292828f, 0.0080159731f, -0.1838899497f,
+ -0.3900215384f, -0.5892675140f, -0.7598185700f, -0.8818480868f, -0.9399786297f, -0.9252325823f, -0.8362335185f, -0.6794898766f,
+ -0.4687496028f, -0.2234686369f, 0.0333794198f, 0.2779351658f, 0.4881469775f, 0.6462666955f, 0.7407620319f, 0.7675102118f,
+ 0.7300140555f, 0.6387574230f, 0.5096096451f, 0.3616936194f, 0.2146955649f, 0.0863068159f, -0.0104489874f, -0.0693762132f,
+ -0.0979362074f, -0.1120025953f, -0.1187847101f, -0.1195709435f, -0.1158142700f, -0.1086494413f, -0.0991759892f, -0.0882830476f,
+ -0.0767682730f, -0.0652504848f, -0.0542380863f, -0.0440837698f, -0.0350361951f, -0.0272194074f, -0.0206775342f, -0.0153683003f,
+ -0.0112022098f, -0.0080423433f, -0.0057368530f, -0.0041194819f, -0.0030341283f, -0.0023328322f, -0.0018922260f, -0.0016079045f,
+ -0.0014038691f, -0.0012238901f, -0.0010359885f, -0.0008223621f, -0.0005812568f, -0.0003172104f, -0.0000423446f, 0.0002317528f,
+ 0.0004920317f, 0.0007298898f, 0.0009380570f, 0.0011144792f, 0.0012583706f, 0.0013727541f, 0.0014603320f, 0.0015255024f,
+ 0.0015706934f, 0.0015984889f, 0.0016087944f, 0.0016013362f, 0.0015736524f, 0.0015238602f, 0.0014491647f, 0.0013485610f,
+ 0.0012214393f, 0.0010698662f, 0.0008969515f, 0.0007085113f, 0.0005110819f, 0.0003130098f, 0.0001222403f, -0.0000529128f,
+ -0.0002059168f, -0.0003312324f, -0.0004261003f, -0.0004894620f, -0.0005232055f, -0.0005306961f, -0.0005175051f, -0.0004896578f,
+ -0.0004540531f, -0.0004166844f, -0.0003830510f, -0.0003566394f, -0.0003395923f, -0.0003316443f, -0.0003311733f, -0.0003346124f,
+ -0.0003378214f, -0.0003358194f, -0.0003242611f, -0.0002992259f, -0.0002585275f, -0.0002012956f, -0.0001289055f, -0.0000441984f,
+ 0.0000480368f, 0.0001421911f, 0.0002316974f, 0.0003103339f, 0.0003721995f, 0.0004129378f, 0.0004295640f, 0.0004213762f,
+ 0.0003894462f, 0.0003371019f, 0.0002690431f, 0.0001914421f, 0.0001108048f, 0.0000338794f, -0.0000335063f, -0.0000864746f,
+ -0.0001220386f, -0.0001388528f, -0.0001377697f, -0.0001212160f, -0.0000933503f, -0.0000591266f, -0.0000241894f, 0.0000061837f,
+ 0.0000272190f, 0.0000355810f, 0.0000293086f, 0.0000084300f, -0.0000254463f, -0.0000689080f, -0.0001174917f, -0.0001657726f,
+ -0.0002083169f, -0.0002398873f, -0.0002563684f, -0.0002548515f, -0.0002343135f, -0.0001953996f, -0.0001407304f, -0.0000743265f,
+ -0.0000015627f, 0.0000716768f, 0.0001392424f, 0.0001956345f, 0.0002362192f, 0.0002579841f, 0.0002595163f, 0.0002414285f,
+ -0.0000940837f, -0.0002770282f, -0.0004449239f, -0.0005888728f, -0.0007019644f, -0.0007792340f, -0.0008182743f, -0.0008186617f,
+ -0.0007820794f, -0.0007112881f, -0.0006099783f, -0.0004815832f, -0.0003292359f, -0.0001547948f, 0.0000407443f, 0.0002577725f,
+ 0.0004970701f, 0.0007599305f, 0.0010467681f, 0.0013572172f, 0.0016888066f, 0.0020376007f, 0.0023974682f, 0.0027617602f,
+ 0.0031234670f, 0.0034780578f, 0.0038243130f, 0.0041678751f, 0.0045219223f, 0.0049104098f, 0.0053672600f, 0.0059379719f,
+ 0.0066758931f, 0.0076410668f, 0.0088925844f, 0.0104843046f, 0.0124532460f, 0.0148130444f, 0.0175396030f, 0.0205645423f,
+ 0.0237604835f, 0.0269378529f, 0.0298327415f, 0.0321108152f, 0.0333602127f, 0.0331056565f, 0.0308069668f, 0.0258845713f,
+ 0.0177205355f, 0.0056930577f, -0.0108298743f, -0.0324583065f, -0.0598208742f, -0.0935922245f, -0.1346769337f, -0.1852485101f,
+ -0.2520452044f, -0.3349618030f, -0.4178137014f, -0.4806851731f, -0.5066093847f, -0.4828480682f, -0.4029110854f, -0.2674540766f,
+ -0.0845343107f, 0.1312173509f, 0.3601564597f, 0.5799075204f, 0.7679640489f, 0.9043772480f, 0.9741394604f, 0.9690106520f,
+ 0.8885379519f, 0.7401510478f, 0.5383256422f, 0.3028982916f, 0.0567716151f, -0.1767567296f, -0.3766491619f, -0.5265275449f,
+ -0.6164139497f, -0.6437430944f, -0.6133407543f, -0.5366180838f, -0.4297512054f, -0.3115454630f, -0.2005356394f, -0.1128598350f,
+ -0.0539105809f, -0.0139443690f, 0.0156565191f, 0.0370291041f, 0.0516278850f, 0.0605689917f, 0.0649188950f, 0.0656033918f,
+ 0.0635061831f, 0.0593951272f, 0.0539682831f, 0.0478045414f, 0.0413946012f, 0.0351122976f, 0.0292427409f, 0.0239693774f,
+ 0.0194022319f, 0.0155752485f, 0.0124736580f, 0.0100363326f, 0.0081800382f, 0.0068024870f, 0.0058015196f, 0.0050760480f,
+ 0.0045392915f, 0.0041164842f, 0.0037525515f, 0.0034068962f, 0.0030568884f, 0.0026909558f, 0.0023097105f, 0.0019188491f,
+ 0.0015296237f, 0.0011527869f, 0.0007995822f, 0.0004773732f, 0.0001916221f, -0.0000568089f, -0.0002688493f, -0.0004487434f,
+ -0.0006009421f, -0.0007311394f, -0.0008434559f, -0.0009415801f, -0.0010266406f, -0.0010987560f, -0.0011556747f, -0.0011947058f,
+ -0.0012119146f, -0.0012041634f, -0.0011684945f, -0.0011039351f, -0.0010107180f, -0.0008915962f, -0.0007507109f, -0.0005943565f,
+ -0.0004295220f, -0.0002642519f, -0.0001060642f, 0.0000378186f, 0.0001618981f, 0.0002620189f, 0.0003364193f, 0.0003850258f,
+ 0.0004100438f, 0.0004149209f, 0.0004045652f, 0.0003841255f, 0.0003590482f, 0.0003339070f, 0.0003125425f, 0.0002971555f,
+ 0.0002887091f, 0.0002863958f, 0.0002883494f, 0.0002914552f, 0.0002922766f, 0.0002870530f, 0.0002726535f, 0.0002465517f,
+ 0.0002076047f, 0.0001558242f, 0.0000928493f, 0.0000214333f, -0.0000544032f, -0.0001301223f, -0.0002007286f, -0.0002616070f,
+ -0.0003086144f, -0.0003388183f, -0.0003504396f, -0.0003433413f, -0.0003187137f, -0.0002792588f, -0.0002286183f, -0.0001713141f,
+ -0.0001120267f, -0.0000554389f,
+ -0.0001958521f, -0.0002037772f, -0.0001928163f, -0.0001589424f, -0.0001002894f, -0.0000163380f, 0.0000907887f, 0.0002175831f,
+ 0.0003582211f, 0.0005062409f, 0.0006538405f, 0.0007937851f, 0.0009186699f, 0.0010227885f, 0.0011010838f, 0.0011507705f,
+ 0.0011698159f, 0.0011582816f, 0.0011163741f, 0.0010456753f, 0.0009469803f, 0.0008217234f, 0.0006698794f, 0.0004918730f,
+ 0.0002867091f, 0.0000544686f, -0.0002054280f, -0.0004913183f, -0.0008012958f, -0.0011303304f, -0.0014731078f, -0.0018216574f,
+ -0.0021695528f, -0.0025102922f, -0.0028430159f, -0.0031713537f, -0.0035102261f, -0.0038841898f, -0.0043342737f, -0.0049142608f,
+ -0.0056961483f, -0.0067625723f, -0.0082096287f, -0.0101339707f, -0.0126325271f, -0.0157836972f, -0.0196448900f, -0.0242284914f,
+ -0.0294998526f, -0.0353498489f, -0.0415975524f, -0.0479616035f, -0.0540728812f, -0.0594457699f, -0.0635064362f, -0.0655612395f,
+ -0.0648457799f, -0.0604784184f, -0.0515339488f, -0.0369448838f, -0.0155927126f, 0.0139806398f, 0.0539164770f, 0.1128370459f,
+ 0.2004901808f, 0.3114870438f, 0.4296920027f, 0.5365714345f, 0.6133195725f, 0.6437584042f, 0.6164735032f, 0.5266348467f,
+ 0.3768028330f, 0.1769504498f, -0.0565487403f, -0.3026608074f, -0.5380905144f, -0.7399360850f, -0.8883601949f, -0.9688847331f,
+ -0.9740762507f, -0.9043827765f, -0.7680389511f, -0.5800469251f, -0.3603504723f, -0.1314519403f, 0.0842759659f, 0.2671900601f,
+ 0.4026590428f, 0.4826236485f, 0.5064248335f, 0.4805483640f, 0.4177275519f, 0.3349242893f, 0.2520497692f, 0.1852850777f,
+ 0.1347332064f, 0.0936551449f, 0.0598782099f, 0.0325001596f, 0.0108498369f, -0.0056970597f, -0.0177459594f, -0.0259244265f,
+ -0.0308505634f, -0.0331397240f, -0.0333704132f, -0.0320833599f, -0.0297560793f, -0.0268041178f, -0.0235666816f, -0.0203132117f,
+ -0.0172390062f, -0.0144767230f, -0.0120991121f, -0.0101332076f, -0.0085666335f, -0.0073617255f, -0.0064621794f, -0.0058047936f,
+ -0.0053242015f, -0.0049609363f, -0.0046632383f, -0.0043912873f, -0.0041162231f, -0.0038213107f, -0.0034990867f, -0.0031507115f,
+ -0.0027824416f, -0.0024044438f, -0.0020276438f, -0.0016629392f, -0.0013190459f, -0.0010025416f, -0.0007168319f, -0.0004629763f,
+ -0.0002395008f, -0.0000436500f, 0.0001284164f, 0.0002803877f, 0.0004156585f, 0.0005364447f, 0.0006439523f, 0.0007379710f,
+ 0.0008173893f, 0.0008801810f, 0.0009241189f, 0.0009469386f, 0.0009470262f, 0.0009235256f, 0.0008768074f, 0.0008083660f,
+ 0.0007209842f, 0.0006183917f, 0.0005051683f, 0.0003862499f, 0.0002667034f, 0.0001512287f, 0.0000439630f, -0.0000518813f,
+ -0.0001340642f, -0.0002014693f, -0.0002539655f, -0.0002923568f, -0.0003181036f, -0.0003331509f, -0.0003396076f, -0.0003395633f,
+ -0.0003348303f, -0.0003268422f, -0.0003165265f, -0.0003043290f, -0.0002902270f, -0.0002738620f, -0.0002546506f, -0.0002319638f,
+ -0.0002052612f, -0.0001742433f, -0.0001389381f, -0.0000997698f, -0.0000575586f, -0.0000134887f, 0.0000309765f, 0.0000742026f,
+ 0.0001145147f, 0.0001503321f, 0.0001802885f,
+ -0.0001277341f, -0.0000801832f, -0.0000218515f, 0.0000429946f, 0.0001101725f, 0.0001753791f, 0.0002352234f, 0.0002868790f,
+ 0.0003289280f, 0.0003607437f, 0.0003830779f, 0.0003971613f, 0.0004050891f, 0.0004087434f, 0.0004101314f, 0.0004103021f,
+ 0.0004098229f, 0.0004078547f, 0.0004029032f, 0.0003921299f, 0.0003724071f, 0.0003398196f, 0.0002909307f, 0.0002223256f,
+ 0.0001319189f, 0.0000183492f, -0.0001178379f, -0.0002750908f, -0.0004498764f, -0.0006379165f, -0.0008333771f, -0.0010303574f,
+ -0.0012220954f, -0.0014025519f, -0.0015654459f, -0.0017057905f, -0.0018186276f, -0.0019004727f, -0.0019477420f, -0.0019582025f,
+ -0.0019292104f, -0.0018593672f, -0.0017467341f, -0.0015908909f, -0.0013912094f, -0.0011493707f, -0.0008675713f, -0.0005513213f,
+ -0.0002071950f, 0.0001544857f, 0.0005229288f, 0.0008847642f, 0.0012288921f, 0.0015452051f, 0.0018312322f, 0.0020914322f,
+ 0.0023452820f, 0.0026261558f, 0.0029898311f, 0.0035112352f, 0.0042918405f, 0.0054520943f, 0.0071361390f, 0.0094977907f,
+ 0.0127016847f, 0.0169013256f, 0.0222371991f, 0.0288065364f, 0.0366610177f, 0.0457690119f, 0.0560179682f, 0.0671701450f,
+ 0.0788774558f, 0.0906296100f, 0.1017925366f, 0.1115401869f, 0.1189349031f, 0.1228106313f, 0.1219422410f, 0.1147682442f,
+ 0.0998698743f, 0.0698963887f, 0.0088203751f, -0.0909692208f, -0.2234220627f, -0.3756331554f, -0.5300042260f, -0.6668887743f,
+ -0.7671574389f, -0.8148547416f, -0.7993524069f, -0.7169019655f, -0.5713321080f, -0.3737662567f, -0.1415729584f, 0.1036716588f,
+ 0.3378392047f, 0.5399814296f, 0.7022792290f, 0.8235847390f, 0.9011912110f, 0.9335195531f, 0.9210148943f, 0.8662582998f,
+ 0.7738442006f, 0.6501373474f, 0.5028823140f, 0.3407552797f, 0.1728427401f, 0.0081212390f, -0.1450610431f, -0.2794406314f,
+ -0.3892283922f, -0.4703883896f, -0.5208081709f, -0.5403348331f, -0.5306924278f, -0.4952731730f, -0.4388331926f, -0.3670992988f,
+ -0.2863302758f, -0.2028454693f, -0.1225716070f, -0.0506164333f, 0.0090788383f, 0.0540159375f, 0.0833026194f, 0.0977385677f,
+ 0.0999946466f, 0.0952552716f, 0.0880995668f, 0.0797728807f, 0.0706660863f, 0.0613242080f, 0.0521689821f, 0.0435466445f,
+ 0.0356893133f, 0.0287479136f, 0.0227869173f, 0.0178107854f, 0.0137689980f, 0.0105778434f, 0.0081277168f, 0.0062997686f,
+ 0.0049716376f, 0.0040285807f, 0.0033660981f, 0.0028959547f, 0.0025456890f, 0.0022606635f, 0.0020013537f, 0.0017429261f,
+ 0.0014715303f, 0.0011828460f, 0.0008784722f, 0.0005645174f, 0.0002487848f, -0.0000600208f, -0.0003540749f, -0.0006264965f,
+ -0.0008722305f, -0.0010875779f, -0.0012705059f, -0.0014199592f, -0.0015359444f, -0.0016188954f, -0.0016697727f, -0.0016896254f,
+ -0.0016797991f, -0.0016416978f, -0.0015770686f, -0.0014878777f, -0.0013765796f, -0.0012459990f, -0.0010995021f, -0.0009408124f,
+ -0.0007740525f, -0.0006034858f, -0.0004334565f, -0.0002681040f, -0.0001112695f, 0.0000337496f, 0.0001642534f, 0.0002782887f,
+ 0.0003746198f, 0.0004527614f, 0.0005128644f, 0.0005556551f, 0.0005822707f, 0.0005941545f, 0.0005928931f, 0.0005801213f,
+ 0.0005574074f, 0.0005262036f, 0.0004878004f, 0.0004433324f, 0.0003937929f, 0.0003400774f, 0.0002830311f, 0.0002234973f,
+ 0.0001623637f, 0.0001005861f, 0.0000392083f, -0.0000206541f, -0.0000778269f, -0.0001311308f, -0.0001794168f, -0.0002216378f,
+ -0.0002568858f, -0.0002844591f, -0.0003038790f, -0.0003149350f, -0.0003176698f, -0.0003123947f, -0.0002996434f, -0.0002801639f,
+ -0.0002548507f, -0.0002247269f, -0.0001908697f, -0.0001543953f, -0.0001163917f, -0.0000779152f, -0.0000399357f,
+ 0.0000094413f, 0.0000277999f, 0.0000446903f, 0.0000593280f, 0.0000712651f, 0.0000803871f, 0.0000870097f, 0.0000917822f,
+ 0.0000956902f, 0.0000998716f, 0.0001055506f, 0.0001138098f, 0.0001255136f, 0.0001411003f, 0.0001605589f, 0.0001832996f,
+ 0.0002082298f, 0.0002337307f, 0.0002578403f, 0.0002783202f, 0.0002929118f, 0.0002994416f, 0.0002960857f, 0.0002814451f,
+ 0.0002547522f, 0.0002158569f, 0.0001653321f, 0.0001043455f, 0.0000346623f, -0.0000415774f, -0.0001219205f, -0.0002038633f,
+ -0.0002849129f, -0.0003628240f, -0.0004355962f, -0.0005016356f, -0.0005596549f, -0.0006087461f, -0.0006481918f, -0.0006774810f,
+ -0.0006960781f, -0.0007034418f, -0.0006988166f, -0.0006813178f, -0.0006497978f, -0.0006030351f, -0.0005396896f, -0.0004585888f,
+ -0.0003587409f, -0.0002396693f, -0.0001014165f, 0.0000551454f, 0.0002283928f, 0.0004157251f, 0.0006137740f, 0.0008182856f,
+ 0.0010244618f, 0.0012269217f, 0.0014201288f, 0.0015983649f, 0.0017561723f, 0.0018882664f, 0.0019899370f, 0.0020568553f,
+ 0.0020854261f, 0.0020725003f, 0.0020157272f, 0.0019132331f, 0.0017640560f, 0.0015678593f, 0.0013255131f, 0.0010388553f,
+ 0.0007114008f, 0.0003480516f, -0.0000442075f, -0.0004568793f, -0.0008795218f, -0.0013009102f, -0.0017091380f, -0.0020936476f,
+ -0.0024460089f, -0.0027628964f, -0.0030473913f, -0.0033126371f, -0.0035830824f, -0.0038981281f, -0.0043122790f, -0.0048977534f,
+ -0.0057421929f, -0.0069491136f, -0.0086317888f, -0.0109107455f, -0.0139027684f, -0.0177154927f, -0.0224311200f, -0.0280995831f,
+ -0.0347172313f, -0.0422222045f, -0.0504683384f, -0.0592304787f, -0.0681714904f, -0.0768802892f, -0.0848233610f, -0.0916208280f,
+ -0.0960365098f, -0.0934965965f, -0.0788165513f, -0.0493177686f, -0.0041840764f, 0.0557190363f, 0.1279300009f, 0.2085541449f,
+ 0.2925373176f, 0.3740109184f, 0.4467123250f, 0.5044329150f, 0.5414803943f, 0.5531103895f, 0.5359083733f, 0.4880865671f,
+ 0.4096810759f, 0.3026295623f, 0.1707255672f, 0.0194488912f, -0.1443186247f, -0.3126736143f, -0.4771477585f, -0.6292070969f,
+ -0.7607694851f, -0.8646983027f, -0.9352529748f, -0.9684532025f, -0.9623535812f, -0.9171949326f, -0.8354559290f, -0.7219447724f,
+ -0.5842261616f, -0.4299994224f, -0.2647671304f, -0.0936718584f, 0.0778573928f, 0.2444955397f, 0.4011508179f, 0.5431562386f,
+ 0.6663917866f, 0.7674190691f, 0.8435687444f, 0.8930187210f, 0.9148305827f, 0.9089668951f, 0.8762704359f, 0.8184215785f,
+ 0.7378630625f, 0.6377054994f, 0.5216082533f, 0.3936475943f, 0.2581703422f, 0.1196438490f, -0.0174973196f, -0.1489983380f,
+ -0.2709234334f, -0.3797794589f, -0.4726225629f, -0.5471418581f, -0.6017198326f, -0.6354657299f, -0.6482230521f, -0.6405498448f,
+ -0.6136745009f, -0.5694280123f, -0.5101568311f, -0.4386191067f, -0.3578694342f, -0.2711360702f, -0.1816960690f, -0.0927527129f,
+ -0.0073202620f, 0.0718799659f, 0.1425082935f, 0.2026771758f, 0.2510012829f, 0.2866256582f, 0.3092317499f, 0.3190214225f,
+ 0.3166807736f, 0.3033253264f, 0.2804301957f, 0.2497478163f, 0.2132181238f, 0.1728741342f, 0.1307484916f, 0.0887835046f,
+ 0.0487503059f, 0.0121784205f, -0.0196990379f, -0.0459852335f, -0.0661399413f, -0.0799836583f, -0.0876812985f, -0.0897120098f,
+ -0.0868204670f, -0.0799602374f, -0.0702221831f, -0.0587644272f, -0.0467300423f, -0.0351807009f, -0.0250131586f, -0.0169220452f,
+ -0.0110491061f, -0.0067999510f, -0.0036452141f, -0.0013776515f, 0.0001725658f, 0.0011515063f, 0.0016931166f, 0.0019128947f,
+ 0.0019119195f, 0.0017731008f, 0.0015641080f, 0.0013360166f, 0.0011263428f, 0.0009592385f, 0.0008486058f, 0.0007990396f,
+ 0.0008087142f, 0.0008704662f, 0.0009741845f, 0.0011076612f, 0.0012583569f, 0.0014138649f, 0.0015630668f, 0.0016962130f,
+ 0.0018055792f, 0.0018852562f, 0.0019314544f, 0.0019421196f, 0.0019170260f, 0.0018573192f, 0.0017655022f, 0.0016449753f,
+ 0.0014999823f, 0.0013351861f, 0.0011556142f, 0.0009662892f, 0.0007721962f, 0.0005779798f, 0.0003879485f, 0.0002058452f,
+ 0.0000348998f, -0.0001223239f, -0.0002638249f, -0.0003882481f, -0.0004947379f, -0.0005829688f, -0.0006529761f, -0.0007051597f,
+ -0.0007401195f, -0.0007586609f, -0.0007616586f, -0.0007500873f, -0.0007249274f, -0.0006872277f, -0.0006380521f, -0.0005785652f,
+ -0.0005100019f, -0.0004337551f, -0.0003513433f, -0.0002644761f, -0.0001749961f, -0.0000849056f, 0.0000037265f, 0.0000887799f,
+ 0.0001682047f, 0.0002400620f, 0.0003026539f, 0.0003545629f, 0.0003947614f, 0.0004226221f, 0.0004379830f, 0.0004411096f,
+ 0.0004327050f, 0.0004138228f, 0.0003858290f, 0.0003502817f, 0.0003088683f, 0.0002632783f, 0.0002151470f, 0.0001659510f,
+ 0.0001169830f, 0.0000692900f, 0.0000236931f, -0.0000192281f, -0.0000590766f, -0.0000956193f, -0.0001287082f, -0.0001582520f,
+ -0.0001841434f, -0.0002062459f, -0.0002243482f, -0.0002381838f, -0.0002474218f, -0.0002517193f, -0.0002507430f, -0.0002442414f,
+ -0.0002320758f, -0.0002142901f, -0.0001911276f, -0.0001630744f, -0.0001308436f, -0.0000953784f, -0.0000577970f, -0.0000193582f,
+ 0.0000186239f, 0.0000548367f, 0.0000880630f, 0.0001172340f, 0.0001415074f, 0.0001602936f, 0.0001732965f, 0.0001804997f,
+ 0.0001821637f, 0.0001787723f, 0.0001709948f, 0.0001596078f, 0.0001454431f, 0.0001293085f, 0.0001119454f, 0.0000939706f,
+ 0.0000758637f, 0.0000579434f, 0.0000403900f, 0.0000232563f, 0.0000065182f, -0.0000098944f, -0.0000260374f, -0.0000419222f,
+ -0.0000574677f, -0.0000724909f, -0.0000866869f, -0.0000996508f, -0.0001108899f, -0.0001198747f, -0.0001260737f, -0.0001290184f,
+ -0.0001283426f, -0.0001238392f, -0.0001154831f, -0.0001034619f, -0.0000881663f, -0.0000701856f, -0.0000502629f,
+ 0.0000100257f, 0.0000298715f, 0.0000491016f, 0.0000673457f, 0.0000842719f, 0.0000996175f, 0.0001131774f, 0.0001248226f,
+ 0.0001344760f, 0.0001421200f, 0.0001477626f, 0.0001514384f, 0.0001531732f, 0.0001529862f, 0.0001508606f, 0.0001467558f,
+ 0.0001405885f, 0.0001322589f, 0.0001216448f, 0.0001086385f, 0.0000931503f, 0.0000751504f, 0.0000546725f, 0.0000318520f,
+ 0.0000069213f, -0.0000197639f, -0.0000477443f, -0.0000764464f, -0.0001052188f, -0.0001333354f, -0.0001600439f, -0.0001845767f,
+ -0.0002062035f, -0.0002242408f, -0.0002380992f, -0.0002472837f, -0.0002514295f, -0.0002502882f, -0.0002437508f, -0.0002318205f,
+ -0.0002146257f, -0.0001923855f, -0.0001654183f, -0.0001341069f, -0.0000989108f, -0.0000603353f, -0.0000189514f, 0.0000246284f,
+ 0.0000697235f, 0.0001156056f, 0.0001614708f, 0.0002064618f, 0.0002496452f, 0.0002900437f, 0.0003266238f, 0.0003583420f,
+ 0.0003841453f, 0.0004030314f, 0.0004140579f, 0.0004164107f, 0.0004094151f, 0.0003926023f, 0.0003657128f, 0.0003287519f,
+ 0.0002819762f, 0.0002259319f, 0.0001614203f, 0.0000895170f, 0.0000115172f, -0.0000710597f, -0.0001565398f, -0.0002430985f,
+ -0.0003288369f, -0.0004117862f, -0.0004899853f, -0.0005614798f, -0.0006243974f, -0.0006769402f, -0.0007174577f, -0.0007444335f,
+ -0.0007565586f, -0.0007527147f, -0.0007320491f, -0.0006939555f, -0.0006381507f, -0.0005646499f, -0.0004738416f, -0.0003664521f,
+ -0.0002436140f, -0.0001068131f, 0.0000420546f, 0.0002007573f, 0.0003666837f, 0.0005369393f, 0.0007083151f, 0.0008774032f,
+ 0.0010405725f, 0.0011941030f, 0.0013341657f, 0.0014569762f, 0.0015587822f, 0.0016360436f, 0.0016854353f, 0.0017040651f,
+ 0.0016895002f, 0.0016400311f, 0.0015547178f, 0.0014336912f, 0.0012781928f, 0.0010908735f, 0.0008757648f, 0.0006385002f,
+ 0.0003861185f, 0.0001271046f, -0.0001290952f, -0.0003723192f, -0.0005925672f, -0.0007805994f, -0.0009292471f, -0.0010343329f,
+ -0.0010963449f, -0.0011215032f, -0.0011235784f, -0.0011247650f, -0.0011572825f, -0.0012635736f, -0.0014972500f, -0.0019220776f,
+ -0.0026119000f, -0.0036479956f, -0.0051179657f, -0.0071115979f, -0.0097197636f, -0.0130315445f, -0.0171388264f, -0.0221826026f,
+ -0.0285136326f, -0.0361307186f, -0.0442081981f, -0.0516559897f, -0.0573925315f, -0.0603652434f, -0.0596331395f, -0.0544264019f,
+ -0.0442109616f, -0.0287331963f, -0.0080564058f, 0.0174234593f, 0.0469759993f, 0.0795551974f, 0.1138332879f, 0.1482526191f,
+ 0.1810898747f, 0.2105329869f, 0.2347647762f, 0.2520519356f, 0.2608332916f, 0.2598051239f, 0.2479978629f, 0.2248419603f,
+ 0.1902182120f, 0.1444910892f, 0.0885218306f, 0.0236611727f, -0.0482797215f, -0.1250786276f, -0.2041714722f, -0.2827382419f,
+ -0.3578034522f, -0.4263466673f, -0.4854197016f, -0.5322651608f, -0.5644323798f, -0.5798852692f, -0.5770983111f, -0.5551358084f,
+ -0.5137115562f, -0.4532252989f, -0.3747746885f, -0.2801408533f, -0.1717482321f, -0.0525987506f, 0.0738169580f, 0.2036293318f,
+ 0.3327161135f, 0.4568415935f, 0.5718029559f, 0.6735794476f, 0.7584777874f, 0.8232695197f, 0.8653138344f, 0.8826624233f,
+ 0.8741407389f, 0.8394039127f, 0.7789631089f, 0.6941829200f, 0.5872472518f, 0.4610970982f, 0.3193391719f, 0.1661318331f,
+ 0.0060481020f, -0.1560745385f, -0.3152984295f, -0.4667504424f, -0.6057916885f, -0.7281716821f, -0.8301830623f, -0.9087761258f,
+ -0.9618416393f, -0.9883769508f, -0.9880544909f, -0.9610885174f, -0.9083986381f, -0.8315930415f, -0.7329302137f, -0.6152510066f,
+ -0.4818998000f, -0.3366264325f, -0.1834804423f, -0.0266942820f, 0.1294357761f, 0.2806718111f, 0.4229523505f, 0.5525059678f,
+ 0.6659544948f, 0.7604051258f, 0.8335268161f, 0.8836105772f, 0.9096104660f, 0.9111656060f, 0.8886015017f, 0.8429119395f,
+ 0.7757211639f, 0.6892286142f, 0.5861371807f, 0.4695681223f, 0.3429645973f, 0.2099875350f, 0.0744064202f, -0.0600110582f,
+ -0.1896077300f, -0.3109402608f, -0.4208745383f, -0.5166699060f, -0.5960503378f, -0.6572602031f, -0.6991036150f, -0.7209660923f,
+ -0.7228185799f, -0.7052037113f, -0.6692054230f, -0.6164028870f, -0.5488108092f, -0.4688079424f, -0.3790565546f, -0.2824152817f,
+ -0.1818484683f, -0.0803346471f, 0.0192227465f, 0.1140799262f, 0.2017298411f, 0.2799697880f, 0.3469574836f, 0.4012543426f,
+ 0.4418547649f, 0.4682010863f, 0.4801839581f, 0.4781287434f, 0.4627686220f, 0.4352058330f, 0.3968625180f, 0.3494232322f,
+ 0.2947711136f, 0.2349201359f, 0.1719456583f, 0.1079157418f, 0.0448253472f, -0.0154643795f, -0.0712800080f, -0.1211812328f,
+ -0.1639966775f, -0.1988491244f, -0.2251698043f, -0.2427015611f, -0.2514912990f, -0.2518722833f, -0.2444373910f, -0.2300045092f,
+ -0.2095756919f, -0.1842916891f, -0.1553837364f, -0.1241243795f, -0.0917792284f, -0.0595613097f, -0.0285896618f, 0.0001465056f,
+ 0.0258169100f, 0.0477717562f, 0.0655551910f, 0.0789104778f, 0.0877769862f, 0.0922794468f, 0.0927101873f, 0.0895053265f,
+ 0.0832161440f, 0.0744769454f, 0.0639709607f, 0.0523956967f, 0.0404293889f, 0.0286998006f, 0.0177569270f, 0.0080503829f,
+ -0.0000871632f, -0.0064505432f, -0.0109653717f, -0.0136854786f, -0.0147827090f, -0.0145338644f, -0.0132999155f, -0.0115279496f,
+ -0.0097143162f, -0.0081066262f, -0.0066892166f, -0.0054526910f, -0.0044043619f, -0.0035430638f, -0.0028610848f, -0.0023435648f,
+ -0.0019710460f, -0.0017207440f, -0.0015686177f, -0.0014906099f, -0.0014640505f, -0.0014684367f, -0.0014861739f, -0.0015028429f,
+ -0.0015073922f, -0.0014919944f, -0.0014518622f, -0.0013848537f, -0.0012910935f, -0.0011724856f, -0.0010322928f, -0.0008746803f,
+ -0.0007043572f, -0.0005262236f, -0.0003451249f, -0.0001656257f, 0.0000081168f, 0.0001724644f, 0.0003243294f, 0.0004612043f,
+ 0.0005811330f, 0.0006826956f, 0.0007649539f, 0.0008274212f, 0.0008700054f, 0.0008929815f, 0.0008969444f, 0.0008827894f,
+ 0.0008516741f, 0.0008050045f, 0.0007444000f, 0.0006716783f, 0.0005888158f, 0.0004979255f, 0.0004012090f, 0.0003009243f,
+ 0.0001993306f, 0.0000986487f, 0.0000010025f, -0.0000916200f, -0.0001774214f, -0.0002548259f, -0.0003225212f, -0.0003794749f,
+ -0.0004249577f, -0.0004585414f, -0.0004801021f, -0.0004897991f, -0.0004880609f, -0.0004755490f, -0.0004531324f, -0.0004218435f,
+ -0.0003828474f, -0.0003373970f, -0.0002868049f, -0.0002324032f, -0.0001755218f, -0.0001174565f, -0.0000594555f, -0.0000026960f,
+ 0.0000517227f, 0.0001027959f, 0.0001496166f, 0.0001913889f, 0.0002274293f, 0.0002571799f, 0.0002802094f, 0.0002962259f,
+ 0.0003050777f, 0.0003067640f, 0.0003014323f, 0.0002893851f, 0.0002710700f, 0.0002470789f, 0.0002181291f, 0.0001850528f,
+ 0.0001487686f, 0.0001102623f, 0.0000705516f, 0.0000306614f, -0.0000084134f, -0.0000457325f, -0.0000804436f, -0.0001118002f,
+ -0.0001391858f, -0.0001621210f, -0.0001802753f, -0.0001934613f, -0.0002016344f, -0.0002048759f, -0.0002033834f, -0.0001974478f,
+ -0.0001874396f, -0.0001737844f, -0.0001569508f, -0.0001374298f, -0.0001157277f, -0.0000923513f, -0.0000678073f, -0.0000425930f,
+ -0.0000172000f, 0.0000078915f, 0.0000322093f, 0.0000552949f, 0.0000767028f, 0.0000960105f, 0.0001128219f, 0.0001267820f,
+ 0.0001375845f, 0.0001449888f, 0.0001488284f, 0.0001490265f, 0.0001456006f, 0.0001386719f, 0.0001284619f, 0.0001152928f,
+ 0.0000995735f, 0.0000817902f, 0.0000624834f, 0.0000422315f, 0.0000216225f, 0.0000012352f, -0.0000183878f, -0.0000367552f,
+ 0.0001023410f, 0.0001121154f, 0.0001195973f, 0.0001245785f, 0.0001269032f, 0.0001264687f, 0.0001232335f, 0.0001172154f,
+ 0.0001084967f, 0.0000972190f, 0.0000835860f, 0.0000678549f, 0.0000503359f, 0.0000313814f, 0.0000113831f, -0.0000092410f,
+ -0.0000300509f, -0.0000505985f, -0.0000704325f, -0.0000891123f, -0.0001062126f, -0.0001213366f, -0.0001341197f, -0.0001442414f,
+ -0.0001514272f, -0.0001554600f, -0.0001561797f, -0.0001534931f, -0.0001473717f, -0.0001378600f, -0.0001250712f, -0.0001091929f,
+ -0.0000904812f, -0.0000692631f, -0.0000459277f, -0.0000209260f, 0.0000052416f, 0.0000320286f, 0.0000588582f, 0.0000851296f,
+ 0.0001102367f, 0.0001335760f, 0.0001545675f, 0.0001726629f, 0.0001873663f, 0.0001982416f, 0.0002049310f, 0.0002071594f,
+ 0.0002047497f, 0.0001976225f, 0.0001858068f, 0.0001694347f, 0.0001487471f, 0.0001240832f, 0.0000958818f, 0.0000646662f,
+ 0.0000310422f, -0.0000043212f, -0.0000406957f, -0.0000773156f, -0.0001133832f, -0.0001480928f, -0.0001806368f, -0.0002102303f,
+ -0.0002361185f, -0.0002576013f, -0.0002740408f, -0.0002848864f, -0.0002896805f, -0.0002880829f, -0.0002798740f, -0.0002649766f,
+ -0.0002434546f, -0.0002155298f, -0.0001815742f, -0.0001421204f, -0.0000978454f, -0.0000495727f, 0.0000017521f, 0.0000550676f,
+ 0.0001092294f, 0.0001630223f, 0.0002152001f, 0.0002645008f, 0.0003096899f, 0.0003495759f, 0.0003830534f, 0.0004091148f,
+ 0.0004268910f, 0.0004356569f, 0.0004348671f, 0.0004241540f, 0.0004033574f, 0.0003725151f, 0.0003318867f, 0.0002819362f,
+ 0.0002233505f, 0.0001570144f, 0.0000840236f, 0.0000056513f, -0.0000766447f, -0.0001612647f, -0.0002464668f, -0.0003304197f,
+ -0.0004112104f, -0.0004869065f, -0.0005555699f, -0.0006153285f, -0.0006643921f, -0.0007011284f, -0.0007240766f, -0.0007320225f,
+ -0.0007240025f, -0.0006993717f, -0.0006577934f, -0.0005992952f, -0.0005242405f, -0.0004333727f, -0.0003277670f, -0.0002088657f,
+ -0.0000784141f, 0.0000615090f, 0.0002085679f, 0.0003601400f, 0.0005134039f, 0.0006653091f, 0.0008126807f, 0.0009521955f,
+ 0.0010805136f, 0.0011942726f, 0.0012902629f, 0.0013654507f, 0.0014172107f, 0.0014433822f, 0.0014425598f, 0.0014141671f,
+ 0.0013587836f, 0.0012781916f, 0.0011756894f, 0.0010560340f, 0.0009256640f, 0.0007924355f, 0.0006656655f, 0.0005555507f,
+ 0.0004729584f, 0.0004284373f, 0.0004317362f, 0.0004903651f, 0.0006089185f, 0.0007872127f, 0.0010196237f, 0.0012928786f,
+ 0.0015857907f, 0.0018667312f, 0.0020943919f, 0.0022145657f, 0.0021631986f, 0.0018604759f, 0.0012208798f, 0.0000292075f,
+ -0.0021197116f, -0.0054807990f, -0.0100496540f, -0.0156837116f, -0.0221176153f, -0.0289836659f, -0.0358300499f, -0.0421477124f,
+ -0.0473972472f, -0.0510405877f, -0.0525715807f, -0.0515476777f, -0.0476183263f, -0.0405511583f, -0.0302526219f, -0.0167837577f,
+ -0.0003687048f, 0.0186033188f, 0.0395840702f, 0.0618793275f, 0.0846695731f, 0.1070368665f, 0.1279977851f, 0.1465405975f,
+ 0.1616659442f, 0.1724289210f, 0.1779814634f, 0.1776128485f, 0.1707870983f, 0.1571752579f, 0.1366814829f, 0.1094613028f,
+ 0.0759313883f, 0.0367697773f, -0.0070935349f, -0.0544959696f, -0.1040711201f, -0.1542864664f, -0.2034887901f, -0.2499561795f,
+ -0.2919547949f, -0.3277987591f, -0.3559109665f, -0.3748828886f, -0.3835310580f, -0.3809483068f, -0.3665476249f, -0.3400970096f,
+ -0.3017436398f, -0.2520263114f, -0.1918751666f, -0.1225984212f, -0.0458559702f, 0.0363795557f, 0.1218735116f, 0.2081903173f,
+ 0.2927633059f, 0.3729712075f, 0.4462190576f, 0.5100209195f, 0.5620818683f, 0.6003764644f, 0.6232211630f, 0.6293380722f,
+ 0.6179078583f, 0.5886097344f, 0.5416469980f, 0.4777568614f, 0.3982039462f, 0.3047571785f, 0.1996504916f, 0.0855281262f,
+ -0.0346240344f, -0.1575593206f, -0.2798609975f, -0.3980402954f, -0.5086387923f, -0.6083321215f, -0.6940317623f, -0.7629817970f,
+ -0.8128474994f, -0.8417929488f, -0.8485450365f, -0.8324417371f, -0.7934628536f, -0.7322420813f, -0.6500596798f, -0.5488157513f,
+ -0.4309846022f, -0.2995513767f, -0.1579325879f, -0.0098828159f, 0.1406098406f, 0.2894364546f, 0.4324848701f, 0.5657586229f,
+ 0.6854937093f, 0.7882695488f, 0.8711108731f, 0.9315772485f, 0.9678376107f, 0.9787272513f, 0.9637856763f, 0.9232737576f,
+ 0.8581699744f, 0.7701451849f, 0.6615174635f, 0.5351870989f, 0.3945560458f, 0.2434310351f, 0.0859296286f, -0.0736424535f,
+ -0.2310634168f, -0.3823114335f, -0.5235213255f, -0.6510808750f, -0.7617398230f, -0.8526941807f, -0.9216599849f, -0.9669314227f,
+ -0.9874241586f, -0.9827015967f, -0.9529842399f, -0.8991414091f, -0.8226659724f, -0.7256325245f, -0.6106403919f, -0.4807428752f,
+ -0.3393647947f, -0.1902104941f, -0.0371648883f, 0.1158098198f, 0.2647789049f, 0.4059385830f, 0.5357153558f, 0.6508586114f,
+ 0.7485239966f, 0.8263453865f, 0.8824935656f, 0.9157201366f, 0.9253855645f, 0.9114707230f, 0.8745717535f, 0.8158785137f,
+ 0.7371373367f, 0.6405992467f, 0.5289551681f, 0.4052600056f, 0.2728477634f, 0.1352400975f, -0.0039491512f, -0.1411108055f,
+ -0.2727359386f, -0.3955076155f, -0.5063863406f, -0.6026869640f, -0.6821450593f, -0.7429710985f, -0.7838911084f, -0.8041728778f,
+ -0.8036371970f, -0.7826540315f, -0.7421239451f, -0.6834454939f, -0.6084696882f, -0.5194429622f, -0.4189403872f, -0.3097911110f,
+ -0.1949981889f, -0.0776550965f, 0.0391387290f, 0.1523609846f, 0.2591459713f, 0.3568583179f, 0.4431590282f, 0.5160621741f,
+ 0.5739808402f, 0.6157612575f, 0.6407044060f, 0.6485747369f, 0.6395960249f, 0.6144347317f, 0.5741715934f, 0.5202624757f,
+ 0.4544898084f, 0.3789061628f, 0.2957717132f, 0.2074874749f, 0.1165262725f, 0.0253634355f, -0.0635908373f, -0.1480555764f,
+ -0.2259378928f, -0.2953850427f, -0.3548284161f, -0.4030183987f, -0.4390493642f, -0.4623743329f, -0.4728091652f, -0.4705264349f,
+ -0.4560394511f, -0.4301771396f, -0.3940507708f, -0.3490137022f, -0.2966155068f, -0.2385519527f, -0.1766124162f, -0.1126263061f,
+ -0.0484101006f, 0.0142835032f, 0.0738128901f, 0.1286900297f, 0.1776170652f, 0.2195161266f, 0.2535516850f, 0.2791450556f,
+ 0.2959808562f, 0.3040055207f, 0.3034181575f, 0.2946543119f, 0.2783633373f, 0.2553803089f, 0.2266934879f, 0.1934085139f,
+ 0.1567104961f, 0.1178252714f, 0.0779810094f, 0.0383713679f, 0.0001212356f, -0.0357439328f, -0.0683244197f, -0.0968674883f,
+ -0.1207831483f, -0.1396541129f, -0.1532399189f, -0.1614752576f, -0.1644628650f, -0.1624613596f, -0.1558686952f, -0.1452018785f,
+ -0.1310738418f, -0.1141682734f, -0.0952134023f, -0.0749555678f, -0.0541335559f, -0.0334544361f, -0.0135717544f, 0.0049333847f,
+ 0.0215677075f, 0.0359373755f, 0.0477554333f, 0.0568451598f, 0.0631392301f, 0.0666750625f, 0.0675865095f, 0.0660925397f,
+ 0.0624832536f, 0.0571040881f, 0.0503386382f, 0.0425910695f, 0.0342685282f, 0.0257645482f, 0.0174437200f, 0.0096285741f,
+ 0.0025886897f, -0.0034671163f, -0.0083958582f, -0.0121219514f, -0.0146360592f, -0.0159904888f, -0.0162924414f, -0.0156942489f,
+ -0.0143825819f, -0.0125652661f, -0.0104587259f, -0.0082734050f, -0.0062022974f, -0.0044063851f, -0.0030085782f, -0.0020299468f,
+ -0.0013564795f, -0.0008863453f, -0.0005771741f, -0.0003938621f, -0.0003061649f, -0.0002866266f, -0.0003117925f, -0.0003614869f,
+ -0.0004195045f, -0.0004730462f, -0.0005129312f, -0.0005329799f, -0.0005299127f, -0.0005026982f, -0.0004523006f, -0.0003810636f,
+ -0.0002924326f, -0.0001904381f, -0.0000794736f, 0.0000360876f, 0.0001520218f, 0.0002645035f, 0.0003701407f, 0.0004661098f,
+ 0.0005501197f, 0.0006204662f, 0.0006759537f, 0.0007159048f, 0.0007400667f, 0.0007486024f, 0.0007420006f, 0.0007210650f,
+ 0.0006868352f, 0.0006405800f, 0.0005837296f, 0.0005178714f, 0.0004446899f, 0.0003659600f, 0.0002834907f, 0.0001991139f,
+ 0.0001146287f, 0.0000317867f, -0.0000477626f, -0.0001224860f, -0.0001910156f, -0.0002521590f, -0.0003049377f, -0.0003485879f,
+ -0.0003825850f, -0.0004066332f, -0.0004206749f, -0.0004248679f, -0.0004195832f, -0.0004053722f, -0.0003829556f, -0.0003531864f,
+ -0.0003170337f, -0.0002755456f, -0.0002298325f, -0.0001810330f, -0.0001302996f, -0.0000787683f, -0.0000275484f, 0.0000223042f,
+ 0.0000697938f, 0.0001140082f, 0.0001541235f, 0.0001894239f, 0.0002193054f, 0.0002432921f, 0.0002610376f, 0.0002723377f,
+ 0.0002771279f, 0.0002754901f, 0.0002676451f, 0.0002539525f, 0.0002348963f, 0.0002110770f, 0.0001831908f, 0.0001520155f,
+ 0.0001183840f, 0.0000831661f, 0.0000472400f, 0.0000114735f, -0.0000233037f, -0.0000563155f, -0.0000868623f, -0.0001143311f,
+ -0.0001382112f, -0.0001580971f, -0.0001736964f, -0.0001848263f, -0.0001914138f, -0.0001934872f, -0.0001911719f, -0.0001846781f,
+ -0.0001742945f, -0.0001603745f, -0.0001433301f, -0.0001236179f, -0.0001017335f, -0.0000781989f, -0.0000535563f, -0.0000283571f,
+ -0.0000031551f, 0.0000215050f, 0.0000450945f, 0.0000671132f, 0.0000870967f, 0.0001046293f, 0.0001193514f, 0.0001309712f,
+ 0.0001392702f, 0.0001441122f, 0.0001454457f, 0.0001433077f, 0.0001378215f, 0.0001291946f, 0.0001177105f, 0.0001037219f,
+ 0.0000876371f, 0.0000699088f, 0.0000510177f, 0.0000314597f, 0.0000117289f, -0.0000076947f, -0.0000263593f, -0.0000438511f,
+ 0.0001150132f, 0.0001210457f, 0.0001243256f, 0.0001247272f, 0.0001221905f, 0.0001167241f, 0.0001084050f, 0.0000973782f,
+ 0.0000838538f, 0.0000681026f, 0.0000504506f, 0.0000312726f, 0.0000109840f, -0.0000099676f, -0.0000311119f, -0.0000519657f,
+ -0.0000720435f, -0.0000908672f, -0.0001079775f, -0.0001229433f, -0.0001353725f, -0.0001449210f, -0.0001513017f, -0.0001542924f,
+ -0.0001537428f, -0.0001495795f, -0.0001418111f, -0.0001305291f, -0.0001159099f, -0.0000982119f, -0.0000777730f, -0.0000550042f,
+ -0.0000303824f, -0.0000044402f, 0.0000222446f, 0.0000490630f, 0.0000753874f, 0.0001005877f, 0.0001240454f, 0.0001451693f,
+ 0.0001634096f, 0.0001782724f, 0.0001893315f, 0.0001962400f, 0.0001987389f, 0.0001966654f, 0.0001899567f, 0.0001786543f,
+ 0.0001629038f, 0.0001429540f, 0.0001191532f, 0.0000919438f, 0.0000618549f, 0.0000294929f, -0.0000044692f, -0.0000393044f,
+ -0.0000742456f, -0.0001085004f, -0.0001412677f, -0.0001717545f, -0.0001991934f, -0.0002228606f, -0.0002420939f, -0.0002563091f,
+ -0.0002650175f, -0.0002678393f, -0.0002645180f, -0.0002549296f, -0.0002390911f, -0.0002171644f, -0.0001894582f, -0.0001564244f,
+ -0.0001186528f, -0.0000768603f, -0.0000318787f, 0.0000153623f, 0.0000638538f, 0.0001125289f, 0.0001602850f, 0.0002060085f,
+ 0.0002485978f, 0.0002869886f, 0.0003201766f, 0.0003472410f, 0.0003673652f, 0.0003798567f, 0.0003841643f, 0.0003798944f,
+ 0.0003668225f, 0.0003449050f, 0.0003142851f, 0.0002752981f, 0.0002284708f, 0.0001745194f, 0.0001143417f, 0.0000490064f,
+ -0.0000202635f, -0.0000921091f, -0.0001650610f, -0.0002375657f, -0.0003080181f, -0.0003747934f, -0.0004362837f, -0.0004909328f,
+ -0.0005372734f, -0.0005739597f, -0.0005998016f, -0.0006137920f, -0.0006151340f, -0.0006032611f, -0.0005778563f, -0.0005388644f,
+ -0.0004865040f, -0.0004212729f, -0.0003439544f, -0.0002556177f, -0.0001576201f, -0.0000516007f, 0.0000605233f, 0.0001765734f,
+ 0.0002941267f, 0.0004105520f, 0.0005230524f, 0.0006287329f, 0.0007246810f, 0.0008080802f, 0.0008763365f, 0.0009272432f,
+ 0.0009591516f, 0.0009711764f, 0.0009633904f, 0.0009370386f, 0.0008947118f, 0.0008405162f, 0.0007801566f, 0.0007209907f,
+ 0.0006719403f, 0.0006433567f, 0.0006466802f, 0.0006940691f, 0.0007977534f, 0.0009694468f, 0.0012193921f, 0.0015557448f,
+ 0.0019833924f, 0.0025041582f, 0.0031158854f, 0.0038235626f, 0.0046346272f, 0.0054390989f, 0.0060159327f, 0.0061653048f,
+ 0.0057248818f, 0.0045689017f, 0.0026174491f, -0.0001576249f, -0.0037279496f, -0.0080071970f, -0.0128521554f, -0.0180669900f,
+ -0.0234101334f, -0.0286038762f, -0.0333460639f, -0.0373236148f, -0.0402271782f, -0.0417664366f, -0.0416853226f, -0.0397765655f,
+ -0.0358948666f, -0.0299681460f, -0.0220062759f, -0.0121068734f, -0.0004577646f, 0.0126640959f, 0.0268973823f, 0.0418047890f,
+ 0.0568849057f, 0.0715872627f, 0.0853301253f, 0.0975204815f, 0.1075755810f, 0.1149452916f, 0.1191344911f, 0.1197246774f,
+ 0.1163939799f, 0.1089347803f, 0.0972682074f, 0.0814548499f, 0.0617011436f, 0.0383610136f, 0.0119325064f, -0.0169506961f,
+ -0.0475328132f, -0.0789543128f, -0.1102746589f, -0.1404988789f, -0.1686072305f, -0.1935871058f, -0.2144662161f, -0.2303460115f,
+ -0.2404342559f, -0.2440756538f, -0.2407794617f, -0.2302430666f, -0.2123706161f, -0.1872859065f, -0.1553388989f, -0.1171054066f,
+ -0.0733797097f, -0.0251600584f, 0.0263727389f, 0.0798832323f, 0.1339151136f, 0.1869300341f, 0.2373504277f, 0.2836051694f,
+ 0.3241767553f, 0.3576486211f, 0.3827511531f, 0.3984049546f, 0.4037599595f, 0.3982290834f, 0.3815152127f, 0.3536305207f,
+ 0.3149072795f, 0.2659995936f, 0.2078757153f, 0.1418008973f, 0.0693110001f, -0.0078226274f, -0.0876362185f, -0.1680235605f,
+ -0.2467916047f, -0.3217202299f, -0.3906245377f, -0.4514179183f, -0.5021740836f, -0.5411862254f, -0.5670215229f, -0.5785692885f,
+ -0.5750812186f, -0.5562023763f, -0.5219918070f, -0.4729319281f, -0.4099261771f, -0.3342846951f, -0.2476981973f, -0.1522004957f,
+ -0.0501205046f, 0.0559751503f, 0.1633474747f, 0.2691567323f, 0.3705384397f, 0.4646816888f, 0.5489076127f, 0.6207458062f,
+ 0.6780064885f, 0.7188463213f, 0.7418258915f, 0.7459571192f, 0.7307390569f, 0.6961809001f, 0.6428113176f, 0.5716736392f,
+ 0.4843067689f, 0.3827121551f, 0.2693074809f, 0.1468681897f, 0.0184582454f, -0.1126480739f, -0.2430513537f, -0.3693168934f,
+ -0.4880668522f, -0.5960721328f, -0.6903415076f, -0.7682054473f, -0.8273923237f, -0.8660947411f, -0.8830241082f, -0.8774517523f,
+ -0.8492353530f, -0.7988297417f, -0.7272816665f, -0.6362084256f, -0.5277608621f, -0.4045714971f, -0.2696891599f, -0.1265016829f,
+ 0.0213512370f, 0.1700728247f, 0.3158090264f, 0.4547507613f, 0.5832357292f, 0.6978471330f, 0.7955064526f, 0.8735578646f,
+ 0.9298417700f, 0.9627555531f, 0.9712996189f, 0.9551076043f, 0.9144595827f, 0.8502781043f, 0.7641067542f, 0.6580721014f,
+ 0.5348295632f, 0.3974950823f, 0.2495638365f, 0.0948188243f, -0.0627690415f, -0.2191456458f, -0.3702816044f, -0.5122788950f,
+ -0.6414754270f, -0.7545417373f, -0.8485716286f, -0.9211570287f, -0.9704889399f, -0.9954247591f, -0.9954218673f, -0.9705217574f,
+ -0.9213839861f, -0.8492714879f, -0.7560202971f, -0.6439925425f, -0.5160173451f, -0.3753189325f, -0.2254355616f, -0.0701299883f,
+ 0.0867051692f, 0.2411456382f, 0.3893340590f, 0.5275770178f, 0.6524375705f, 0.7608213615f, 0.8500537691f, 0.9179464760f,
+ 0.9628514821f, 0.9837014823f, 0.9800353577f, 0.9520083832f, 0.9003867192f, 0.8265265439f, 0.7323382228f, 0.6202366175f,
+ 0.4930786891f, 0.3540901510f, 0.2067829436f, 0.0548657749f, -0.0978500833f, -0.2475472308f, -0.3904984352f, -0.5231602531f,
+ -0.6422616826f, -0.7448855335f, -0.8285405425f, -0.8912223677f, -0.9314620191f, -0.9483604838f, -0.9416087836f, -0.9114929628f,
+ -0.8588840025f, -0.7852129374f, -0.6924319284f, -0.5829623058f, -0.4596310148f, -0.3255970991f, -0.1842701886f, -0.0392230686f,
+ 0.1058993714f, 0.2474725071f, 0.3819832739f, 0.5061180987f, 0.6168452203f, 0.7114893652f, 0.7877968946f, 0.8439898530f,
+ 0.8788075843f, 0.8915349645f, 0.8820165939f, 0.8506567100f, 0.7984048958f, 0.7267280723f, 0.6375695654f, 0.5332964054f,
+ 0.4166362696f, 0.2906057742f, 0.1584319899f, 0.0234692546f, -0.1108865770f, -0.2412842200f, -0.3645012037f, -0.4775241203f,
+ -0.5776228825f, -0.6624171300f, -0.7299331734f, -0.7786500916f, -0.8075339158f, -0.8160591222f, -0.8042170147f, -0.7725108907f,
+ -0.7219382530f, -0.6539606307f, -0.5704619141f, -0.4736963677f, -0.3662277643f, -0.2508612725f, -0.1305699260f, -0.0084175965f,
+ 0.1125195105f, 0.2292308248f, 0.3388468469f, 0.4387101575f, 0.5264402212f, 0.5999904058f, 0.6576958356f, 0.6983109662f,
+ 0.7210360284f, 0.7255318034f, 0.7119224786f, 0.6807866622f, 0.6331369228f, 0.5703885257f, 0.4943182949f, 0.4070147863f,
+ 0.3108211535f, 0.2082722739f, 0.1020278156f, -0.0051969757f, -0.1107009698f, -0.2118655199f, -0.3062197747f, -0.3915012914f,
+ -0.4657104605f, -0.5271574266f, -0.5745004072f, -0.6067745424f, -0.6234106746f, -0.6242437161f, -0.6095105484f, -0.5798376568f,
+ -0.5362189802f, -0.4799846893f, -0.4127618434f, -0.3364280618f, -0.2530595200f, -0.1648746973f, -0.0741754031f, 0.0167133565f,
+ 0.1055030935f, 0.1899996005f, 0.2681572959f, 0.3381288062f, 0.3983085785f, 0.4473694991f, 0.4842916874f, 0.5083828586f,
+ 0.5192898714f, 0.5170013229f, 0.5018412808f, 0.4744544796f, 0.4357835192f, 0.3870388112f, 0.3296621862f, 0.2652852328f,
+ 0.1956835517f, 0.1227281969f, 0.0483356232f, -0.0255825221f, -0.0971684532f, -0.1646648843f, -0.2264580855f, -0.2811163005f,
+ -0.3274226190f, -0.3644015563f, -0.3913387774f, -0.4077935926f, -0.4136040520f, -0.4088846629f, -0.3940169539f, -0.3696332868f,
+ -0.3365944947f, -0.2959620717f, -0.2489657697f, -0.1969675619f, -0.1414230072f, -0.0838410952f, -0.0257436705f, 0.0313744817f,
+ 0.0860838469f, 0.1370557180f, 0.1830941784f, 0.2231637715f, 0.2564122248f, 0.2821877493f, 0.3000505886f, 0.3097786572f,
+ 0.3113672668f, 0.3050231025f, 0.2911527592f, 0.2703462881f, 0.2433563271f, 0.2110734944f, 0.1744988056f, 0.1347139397f,
+ 0.0928502123f, 0.0500571304f, 0.0074713874f, -0.0338128732f, -0.0727717585f, -0.1084765990f, -0.1401155933f, -0.1670116352f,
+ -0.1886359510f, -0.2046172992f, -0.2147466154f, -0.2189771152f, -0.2174199887f, -0.2103359435f, -0.1981229573f, -0.1813006959f,
+ -0.1604921331f, -0.1364029689f, -0.1097994880f, -0.0814855216f, -0.0522791841f, -0.0229900383f, 0.0056026879f, 0.0327702587f,
+ 0.0578524543f, 0.0802730249f, 0.0995522334f, 0.1153162297f, 0.1273031071f, 0.1353655831f, 0.1394703527f, 0.1396942492f,
+ 0.1362174419f, 0.1293139704f, 0.1193399898f, 0.1067201472f, 0.0919325573f, 0.0754928613f, 0.0579378715f, 0.0398092914f,
+ 0.0216379870f, 0.0039292462f, -0.0128505743f, -0.0282856818f, -0.0420204769f, -0.0537669816f, -0.0633099271f, -0.0705094521f,
+ -0.0753014229f, -0.0776954715f, -0.0777709009f, -0.0756706792f, -0.0715937815f, -0.0657861933f, -0.0585309019f, -0.0501372415f,
+ -0.0409299405f, -0.0312382391f, -0.0213854050f, -0.0116789736f, -0.0024019780f, 0.0061945814f, 0.0138978546f, 0.0205376997f,
+ 0.0259896162f, 0.0301760169f, 0.0330658894f, 0.0346729129f, 0.0350521841f, 0.0342957066f, 0.0325268747f, 0.0298941639f,
+ 0.0265643082f, 0.0227151980f, 0.0185287912f, 0.0141842567f, 0.0098516209f, 0.0056860875f, 0.0018232500f, -0.0016247097f,
+ -0.0045716876f, -0.0069591888f, -0.0087566559f, -0.0099606909f, -0.0105931800f, -0.0106985104f, -0.0103399437f, -0.0095954160f,
+ -0.0085528538f, -0.0073053349f, -0.0059461694f, -0.0045642672f, -0.0032398065f, -0.0020405892f, -0.0010189826f, -0.0002098435f,
+ 0.0003708603f, 0.0007263907f, 0.0008791003f, 0.0008719916f, 0.0007765784f, 0.0006548666f, 0.0005262292f, 0.0003982537f,
+ 0.0002793177f, 0.0001753141f, 0.0000904043f, 0.0000267020f, -0.0000151645f, -0.0000359786f, -0.0000374823f, -0.0000222110f,
+ 0.0000068647f, 0.0000464960f, 0.0000934169f, 0.0001444514f, 0.0001966810f, 0.0002474932f, 0.0002946695f, 0.0003363826f,
+ 0.0003712266f, 0.0003981800f, 0.0004166001f, 0.0004261695f, 0.0004268735f, 0.0004189444f, 0.0004028356f, 0.0003791712f,
+ 0.0003487233f, 0.0003123700f, 0.0002710780f, 0.0002258678f, 0.0001778001f, 0.0001279460f, 0.0000773754f, 0.0000271305f,
+ -0.0000217852f, -0.0000684311f, -0.0001119393f, -0.0001515353f, -0.0001865458f, -0.0002164146f, -0.0002407060f, -0.0002591149f,
+ -0.0002714651f, -0.0002777121f, -0.0002779362f, -0.0002723393f, -0.0002612330f, -0.0002450307f, -0.0002242325f, -0.0001994145f,
+ -0.0001712119f, -0.0001403075f, -0.0001074144f, -0.0000732647f, -0.0000385932f, -0.0000041262f, 0.0000294329f, 0.0000614144f,
+ 0.0000911952f, 0.0001182080f, 0.0001419530f, 0.0001620054f, 0.0001780247f, 0.0001897598f, 0.0001970554f, 0.0001998531f,
+ 0.0001981941f, 0.0001922157f, 0.0001821496f, 0.0001683132f, 0.0001511033f, 0.0001309836f, 0.0001084739f, 0.0000841346f,
+ 0.0000585541f, 0.0000323319f, 0.0000060653f, -0.0000196656f, -0.0000443104f, -0.0000673606f, -0.0000883586f, -0.0001069066f,
+ -0.0001226716f, -0.0001353906f, -0.0001448717f, -0.0001509959f, -0.0001537153f, -0.0001530521f, -0.0001490949f, -0.0001419958f,
+ -0.0001319651f, -0.0001192675f, -0.0001042156f, -0.0000871648f, -0.0000685059f, -0.0000486591f, -0.0000280649f, -0.0000071771f,
+ 0.0000135476f, 0.0000336575f, 0.0000527172f, 0.0000703161f, 0.0000860792f, 0.0000996749f, 0.0001108247f, 0.0001193085f,
+ 0.0001249716f, 0.0001277272f, 0.0001275584f, 0.0001245179f, 0.0001187256f, 0.0001103637f, 0.0000996709f, 0.0000869347f,
+ 0.0001080714f, 0.0000990683f, 0.0000875489f, 0.0000737219f, 0.0000578554f, 0.0000402709f, 0.0000213391f, 0.0000014712f,
+ -0.0000188884f, -0.0000392732f, -0.0000592037f, -0.0000782001f, -0.0000957929f, -0.0001115356f, -0.0001250152f, -0.0001358638f,
+ -0.0001437678f, -0.0001484773f, -0.0001498120f, -0.0001476681f, -0.0001420207f, -0.0001329265f, -0.0001205227f, -0.0001050259f,
+ -0.0000867271f, -0.0000659874f, -0.0000432293f, -0.0000189302f, 0.0000063897f, 0.0000321758f, 0.0000578526f, 0.0000828338f,
+ 0.0001065369f, 0.0001283935f, 0.0001478642f, 0.0001644485f, 0.0001776986f, 0.0001872284f, 0.0001927257f, 0.0001939584f,
+ 0.0001907842f, 0.0001831541f, 0.0001711180f, 0.0001548245f, 0.0001345226f, 0.0001105567f, 0.0000833641f, 0.0000534651f,
+ 0.0000214568f, -0.0000120012f, -0.0000461970f, -0.0000803840f, -0.0001137931f, -0.0001456534f, -0.0001752051f, -0.0002017210f,
+ -0.0002245193f, -0.0002429841f, -0.0002565765f, -0.0002648525f, -0.0002674704f, -0.0002642056f, -0.0002549531f, -0.0002397370f,
+ -0.0002187078f, -0.0001921470f, -0.0001604577f, -0.0001241645f, -0.0000838982f, -0.0000403913f, 0.0000055419f, 0.0000530134f,
+ 0.0001010845f, 0.0001487757f, 0.0001950921f, 0.0002390326f, 0.0002796173f, 0.0003158959f, 0.0003469755f, 0.0003720281f,
+ 0.0003903206f, 0.0004012217f, 0.0004042346f, 0.0003990046f, 0.0003853554f, 0.0003632970f, 0.0003330658f, 0.0002951288f,
+ 0.0002502244f, 0.0001993576f, 0.0001438330f, 0.0000852306f, 0.0000254212f, -0.0000334924f, -0.0000891888f, -0.0001392362f,
+ -0.0001811447f, -0.0002125359f, -0.0002312354f, -0.0002355083f, -0.0002241797f, -0.0001969318f, -0.0001544184f, -0.0000986120f,
+ -0.0000328538f, 0.0000377552f, 0.0001064640f, 0.0001643821f, 0.0002009417f, 0.0002030084f, 0.0001564122f, 0.0000272101f,
+ -0.0002474236f, -0.0007077450f, -0.0013549123f, -0.0021692285f, -0.0031123474f, -0.0041302220f, -0.0051556983f, -0.0061124129f,
+ -0.0069187044f, -0.0074922749f, -0.0077547251f, -0.0076363116f, -0.0070802717f, -0.0060468886f, -0.0045167944f, -0.0024936150f,
+ -0.0000055857f, 0.0028937610f, 0.0061260810f, 0.0095897406f, 0.0131624981f, 0.0167051532f, 0.0200661755f, 0.0230870624f,
+ 0.0256083449f, 0.0274759454f, 0.0285477406f, 0.0287000110f, 0.0278335968f, 0.0258794506f, 0.0228034121f, 0.0186099337f,
+ 0.0133446258f, 0.0070954201f, -0.0000077076f, -0.0077945612f, -0.0160580606f, -0.0245590879f, -0.0330327072f, -0.0411956451f,
+ -0.0487548015f, -0.0554165787f, -0.0608967236f, -0.0649304010f, -0.0672821451f, -0.0677553773f, -0.0662011304f, -0.0625256765f,
+ -0.0566967379f, -0.0487480334f, -0.0387819173f, -0.0269699584f, -0.0135513300f, 0.0011710168f, 0.0168363911f, 0.0330344995f,
+ 0.0493155343f, 0.0652019647f, 0.0802017491f, 0.0938226053f, 0.1055869534f, 0.1150470840f, 0.1218001096f, 0.1255022179f,
+ 0.1258817753f, 0.1227508252f, 0.1160145780f, 0.1056785154f, 0.0918528133f, 0.0747538316f, 0.0547025267f, 0.0321197033f,
+ 0.0075181359f, -0.0185083336f, -0.0452985039f, -0.0721400382f, -0.0982878107f, -0.1229839236f, -0.1454788614f, -0.1650532162f,
+ -0.1810393625f, -0.1928424604f, -0.1999601464f, -0.2020003079f, -0.1986963539f, -0.1899194667f, -0.1756873734f, -0.1561692785f,
+ -0.1316866814f, -0.1027099283f, -0.0698504512f, -0.0338487823f, 0.0044414588f, 0.0440732723f, 0.0840292465f, 0.1232472348f,
+ 0.1606481100f, 0.1951648730f, 0.2257723487f, 0.2515166502f, 0.2715435877f, 0.2851251931f, 0.2916835749f, 0.2908113564f,
+ 0.2822880398f, 0.2660917210f, 0.2424057072f, 0.2116197075f, 0.1743254190f, 0.1313064718f, 0.0835228630f, 0.0320901527f,
+ -0.0217461395f, -0.0766403699f, -0.1311801252f, -0.1839222820f, -0.2334308512f, -0.2783156266f, -0.3172706001f, -0.3491110990f,
+ -0.3728086001f, -0.3875222240f, -0.3926259708f, -0.3877308633f, -0.3727012727f, -0.3476648529f, -0.3130156636f, -0.2694102425f,
+ -0.2177565698f, -0.1591960621f, -0.0950789218f, -0.0269333587f, 0.0435706287f, 0.1146620553f, 0.1845133465f, 0.2512872136f,
+ 0.3131848107f, 0.3684939113f, 0.4156358207f, 0.4532097440f, 0.4800333796f, 0.4951785767f, 0.4980010130f, 0.4881629819f,
+ 0.4656485511f, 0.4307705397f, 0.3841689741f, 0.3268008962f, 0.2599216377f, 0.1850578889f, 0.1039731292f, 0.0186261878f,
+ -0.0688760906f, -0.1563309363f, -0.2414952059f, -0.3221429964f, -0.3961238341f, -0.4614199206f, -0.5162009081f, -0.5588747253f,
+ -0.5881330481f, -0.6029901331f, -0.6028138835f, -0.5873482068f, -0.5567259364f, -0.5114718287f, -0.4524953996f, -0.3810736314f,
+ -0.2988238434f, -0.2076672897f, -0.1097842922f, -0.0075619595f, 0.0964642567f, 0.1996737260f, 0.2994269495f, 0.3931333240f,
+ 0.4783186205f, 0.5526904067f, 0.6141996858f, 0.6610970894f, 0.6919820919f, 0.7058438677f, 0.7020926210f, 0.6805804458f,
+ 0.6416110407f, 0.5859378797f, 0.5147507447f, 0.4296508188f, 0.3326148490f, 0.2259491718f, 0.1122346729f, -0.0057360023f,
+ -0.1250274487f, -0.2426350011f, -0.3555608763f, -0.4608910229f, -0.5558706911f, -0.6379767588f, -0.7049849023f, -0.7550298238f,
+ -0.7866568993f, -0.7988638266f, -0.7911310876f, -0.7634403277f, -0.7162800506f, -0.6506383584f, -0.5679827902f, -0.4702276607f,
+ -0.3596896122f, -0.2390324220f, -0.1112023801f, 0.0206441788f, 0.1532193990f, 0.2831865095f, 0.4072444271f, 0.5222121895f,
+ 0.6251110517f, 0.7132421052f, 0.7842573939f, 0.8362226383f, 0.8676698916f, 0.8776386903f, 0.8657045557f, 0.8319940114f,
+ 0.7771856339f, 0.7024969994f, 0.6096577639f, 0.5008694615f, 0.3787529642f, 0.2462848589f, 0.1067243047f, -0.0364678261f,
+ -0.1797154905f, -0.3194175307f, -0.4520389446f, -0.5742010518f, -0.6827682255f, -0.7749289589f, -0.8482691444f, -0.9008356561f,
+ -0.9311885385f, -0.9384404163f, -0.9222820323f, -0.8829932011f, -0.8214388065f, -0.7390498855f, -0.6377901922f, -0.5201090426f,
+ -0.3888815657f, -0.2473378465f, -0.0989827048f, 0.0524918607f, 0.2032993783f, 0.3496543888f, 0.4878683054f, 0.6144431772f,
+ 0.7261609761f, 0.8201660863f, 0.8940388909f, 0.9458585157f, 0.9742531243f, 0.9784364026f, 0.9582292951f, 0.9140663528f,
+ 0.8469865241f, 0.7586085363f, 0.6510914981f, 0.5270816374f, 0.3896465540f, 0.2421985725f, 0.0884091910f, -0.0678832812f,
+ -0.2227704771f, -0.3723727403f, -0.5129372944f, -0.6409334118f, -0.7531420237f, -0.8467376100f, -0.9193601068f, -0.9691751619f,
+ -0.9949209725f, -0.9959407463f, -0.9721996606f, -0.9242862434f, -0.8533978301f, -0.7613110254f, -0.6503400677f, -0.5232887671f,
+ -0.3833452070f, -0.2339716460f, -0.0788505878f, 0.0781931324f, 0.2332895986f, 0.3826182078f, 0.5225019620f, 0.6494973950f,
+ 0.7604792743f, 0.8527171215f, 0.9239423238f, 0.9724036977f, 0.9969105248f, 0.9968616872f, 0.9722604412f, 0.9237142440f,
+ 0.8524198184f, 0.7601336589f, 0.6491288368f, 0.5221390436f, 0.3822913495f, 0.2330292358f, 0.0780278756f, -0.0788963298f,
+ -0.2338796641f, -0.3831062116f, -0.5229017760f, -0.6498243415f, -0.7607488022f, -0.8529439154f, -0.9241395420f, -0.9725825570f,
+ -0.9970800142f, -0.9970285365f, -0.9724291748f, -0.9238873987f, -0.8525981906f, -0.7603166365f, -0.6493147113f, -0.5223253486f,
+ -0.3824751467f, -0.2332073920f, -0.0781972729f, 0.0787386074f, 0.2337362092f, 0.3829791953f, 0.5227929031f, 0.6497348216f,
+ 0.7606793588f, 0.8528947992f, 0.9241105706f, 0.9725731485f, 0.9970892373f, 0.9970551505f, 0.9724716796f, 0.9239440737f,
+ 0.8526671417f, 0.7603958321f, 0.6494020269f, 0.5224186015f, 0.3825721394f, 0.2333059467f, 0.0782952740f, -0.0786431789f,
+ -0.2336452368f, -0.3828943954f, -0.5227157923f, -0.6496666924f, -0.7606212560f, -0.8528475077f, -0.9240746034f, -0.9725487476f,
+ -0.9970763762f, -0.9970535479f, -0.9724808145f, -0.9239632108f, -0.8526953557f, -0.7604320409f, -0.6494450222f, -0.5224670848f,
+ -0.3826247539f, -0.2333613129f, -0.0783520192f, 0.0785863895f, 0.2335896751f, 0.3828412460f, 0.5226661333f, 0.6496214780f,
+ 0.7605813048f, 0.8528134912f, 0.9240470409f, 0.9725280010f, 0.9970626504f, 0.9970468907f, 0.9724811225f, 0.9239702338f,
+ 0.8527087070f, 0.7604512067f, 0.6494693756f, 0.5224958998f, 0.3826572234f, 0.2333965660f, 0.0783891427f, -0.0785483312f,
+ -0.2335516168f, -0.3828041004f, -0.5226307686f, -0.6495886980f, -0.7605518286f, -0.8527879374f, -0.9240259128f, -0.9725116771f,
+ -0.9970513761f, -0.9970407770f, -0.9724801457f, -0.9239742417f, -0.8527174266f, -0.7604642572f, -0.6494862818f, -0.5225161097f,
+ -0.3826801252f, -0.2334215076f, -0.0784154487f, 0.0785213402f, 0.2335246089f, 0.3827777168f, 0.5226056112f, 0.6495653171f,
+ 0.7605307154f, 0.8527695153f, 0.9240105331f, 0.9724996141f, 0.9970428253f, 0.9970358530f, 0.9724788823f, 0.9239765920f,
+ 0.8527232652f, 0.7604733819f, 0.6494984183f, 0.5225309161f, 0.3826971989f, 0.2334403933f, 0.0784356488f, -0.0785003550f,
+ -0.2335033857f, -0.3827568073f, -0.5225855558f, -0.6495466309f, -0.7605138718f, -0.8527549335f, -0.9239985644f, -0.9724905323f,
+ -0.9970368187f, -0.9970330198f, -0.9724792289f, -0.9239800349f, -0.8527296357f, -0.7604824344f, -0.6495098398f, -0.5225443385f,
+ -0.3827122124f, -0.2334565601f, -0.0784525165f, 0.0784832397f, 0.2334864657f, 0.3827405037f, 0.5225702598f, 0.6495326959f,
+ 0.7605016087f, 0.8527446058f, 0.9239903860f, 0.9724846653f, 0.9970333725f, 0.9970320501f, 0.9724807380f, 0.9239839714f,
+ 0.8527358952f, 0.7604908594f, 0.6495202224f, 0.5225564219f, 0.3827256949f, 0.2334710996f, 0.0784677378f,
+};
+
+
+const float ivas_fb_resp_cheby_ramp_32del[IVAS_FB_1MS_32K_SAMP + 1] =
+{
+ 0.010231040569020f, 0.007495943710050f, 0.010178929162785f, 0.013398453336031f,
+ 0.017224667421257f, 0.021716621502222f, 0.026933804139047f, 0.032948050269901f,
+ 0.039809603616101f, 0.047574690662976f, 0.056302264669850f, 0.066034303975194f,
+ 0.076798058466510f, 0.088625188565940f, 0.101547758277136f, 0.115583678333348f,
+ 0.130755763247409f, 0.147071750845082f, 0.164507415202116f, 0.183014970904299f,
+ 0.202613741800170f, 0.223272731589440f, 0.244918942156018f, 0.267509604208255f,
+ 0.290972907623430f, 0.315243955993690f, 0.340239023615672f, 0.365855210507665f,
+ 0.392018902968585f, 0.418630748275114f, 0.445572918038597f, 0.472730394874248f,
+ 0.500000000000000f
+};
+
+const float ivas_fb_resp_cheby_ramp_16del[IVAS_FB_1MS_16K_SAMP + 1] =
+{
+ 0.010924831305822f, 0.013910402297200f, 0.022265243822209f, 0.033383809618597f,
+ 0.047654785522720f, 0.065424889526712f, 0.087005871336219f, 0.112572807795153f,
+ 0.142228383484898f, 0.175983302431557f, 0.213688773924401f, 0.255075179343390f,
+ 0.299758845354607f, 0.347229042543433f, 0.396890172892483f, 0.448063390053926f,
+ 0.500000000000000f
+};
+
+const int16_t ivas_num_active_bands[FB - WB + 1] =
+{
+ IVAS_16K_12BANDS_ACTIVE_BANDS, IVAS_FB_BANDS_12, IVAS_FB_BANDS_12
+};
+
+/*------------------------------------------------------------------------------------------*
+ * SNS MSVQ codebooks and means
+ *------------------------------------------------------------------------------------------*/
+
+const int16_t ivas_sns_cdbks_tcx20_levels[SNS_MSVQ_NSTAGES_TCX20] = { 128, 64, 32, 32 };
+
+const int16_t ivas_sns_cdbks_tcx20_bits[SNS_MSVQ_NSTAGES_TCX20] = { 7, 6, 5, 5 };
+
+/* pre-rounded codebook vectors for singed Q4.12 represantation */
+const float ivas_sns_cdbk_tcx20_stage1[ 128 * 16 ] =
+{
+ -1.8305664f, -2.0878906f, -0.9638672f, 2.8059082f, 2.668213f, 1.1638184f, 1.390625f, 1.217041f, 1.3850098f, 0.44555664f, -0.47045898f, -0.5307617f, -0.810791f, -1.1647949f, -1.4560547f, -1.7612305f,
+ -2.5979004f, -3.3308105f, -1.8554688f, -0.3605957f, 1.6828613f, 2.5871582f, 0.98168945f, 0.22436523f, -0.13110352f, 0.16699219f, 1.5004883f, 0.3293457f, 0.33569336f, 1.1591797f, 0.1796875f, -0.8718262f,
+ 1.982666f, 2.2011719f, 1.1525879f, 0.8093262f, 0.86499023f, 1.1618652f, 1.2888184f, 1.3618164f, 1.0827637f, 0.83251953f, 0.12011719f, -0.7182617f, -2.1948242f, -3.0500488f, -3.3571777f, -3.53833f,
+ 0.15771484f, 1.1040039f, 0.39282227f, -0.6479492f, -1.0939941f, -1.0437012f, -1.2055664f, -1.1469727f, -0.998291f, -0.37768555f, 0.3486328f, 1.081543f, 1.2700195f, 1.2143555f, 0.8371582f, 0.107666016f,
+ 0.24438477f, -0.70751953f, -1.1660156f, -1.1777344f, -0.24536133f, 0.39624023f, 1.112793f, 1.232666f, 1.3540039f, 1.088623f, 0.9001465f, 0.9003906f, -0.030761719f, -0.83740234f, -1.2800293f, -1.7849121f,
+ -0.91918945f, -0.18603516f, -0.7397461f, -1.5285645f, -1.7453613f, -1.2680664f, -0.9445801f, 0.2434082f, 1.3000488f, 1.6604004f, 1.2814941f, 1.0026855f, 0.71484375f, 0.56347656f, 0.47509766f, 0.09008789f,
+ 2.4824219f, 1.4541016f, 0.91064453f, 0.6765137f, 0.5678711f, 0.6965332f, 0.7609863f, 0.70410156f, 0.36108398f, -0.032470703f, -0.69140625f, -1.1281738f, -1.4833984f, -1.5556641f, -1.7043457f, -2.0187988f,
+ 2.41333f, 1.4936523f, 0.9902344f, 0.9104004f, 0.7211914f, 0.5522461f, 0.09326172f, -0.21655273f, -0.49560547f, -0.4873047f, -0.7363281f, -0.9211426f, -1.0041504f, -0.9875488f, -1.0681152f, -1.2578125f,
+ -0.814209f, 1.2546387f, 1.6965332f, 1.420166f, 0.99560547f, 1.1420898f, 1.0039062f, 0.9289551f, 0.6604004f, 0.22485352f, -0.6530762f, -1.2009277f, -1.2949219f, -1.3759766f, -1.7175293f, -2.2705078f,
+ -1.3979492f, 0.18896484f, 0.34814453f, -0.052001953f, -0.38623047f, -0.25878906f, -0.3371582f, -0.109375f, -0.08227539f, 0.07495117f, -0.019042969f, 0.1184082f, 0.30566406f, 0.5102539f, 0.6755371f, 0.4206543f,
+ 1.0683594f, 1.9543457f, 2.1296387f, 2.071045f, 1.5754395f, 1.1333008f, 0.4248047f, -0.19799805f, -0.84350586f, -1.079834f, -1.3415527f, -1.3908691f, -1.3967285f, -1.3078613f, -1.3322754f, -1.4663086f,
+ 2.3891602f, 2.5097656f, 1.144043f, 0.36572266f, -0.16894531f, -0.23388672f, 0.26879883f, 0.7692871f, 0.54589844f, 0.5180664f, -0.26879883f, -0.92211914f, -1.2089844f, -1.4658203f, -1.9033203f, -2.338623f,
+ -1.3549805f, 1.3427734f, 1.5871582f, 1.9365234f, 0.58935547f, 0.4892578f, -0.17675781f, -0.19458008f, 0.11352539f, 0.01928711f, 0.30419922f, -0.23291016f, -2.1499023f, -1.2368164f, -0.20922852f, -0.8269043f,
+ 0.8769531f, -1.5319824f, -1.6025391f, -1.3833008f, -0.57299805f, -0.8847656f, -0.90600586f, -0.986084f, -1.1860352f, -1.3520508f, -1.2216797f, -0.49902344f, 1.5070801f, 4.0805664f, 2.208496f, 3.4538574f,
+ 4.114258f, 3.3249512f, 2.2033691f, 1.0500488f, 0.14770508f, -0.36547852f, -0.748291f, -0.8503418f, -1.0917969f, -1.0305176f, -1.1955566f, -1.2768555f, -1.1767578f, -1.0061035f, -0.9506836f, -1.1477051f,
+ 0.7878418f, 2.513916f, 1.0112305f, -0.767334f, -1.3525391f, -0.86865234f, 0.42456055f, 1.4470215f, 1.2680664f, 1.1574707f, -0.41333008f, -0.92993164f, -0.9226074f, -0.92285156f, -0.80859375f, -1.6242676f,
+ -2.2216797f, -1.2346191f, -0.4008789f, 0.59765625f, -0.49389648f, 1.1911621f, 0.032470703f, 1.3654785f, 0.43139648f, 1.2021484f, 1.6652832f, 0.58862305f, -0.29541016f, -0.99560547f, -1.0366211f, -0.39526367f,
+ -1.8601074f, -2.9248047f, 0.14648438f, 0.61157227f, 0.6274414f, -1.3579102f, 0.48095703f, -0.4399414f, 0.57006836f, 1.1831055f, -1.1950684f, 0.828125f, 1.2575684f, 1.5888672f, 0.5510254f, -0.06762695f,
+ 2.1816406f, 2.8918457f, 2.9243164f, 2.5839844f, 2.2548828f, 1.7543945f, 0.92626953f, 0.45751953f, -0.17285156f, -0.9650879f, -1.7875977f, -2.3608398f, -2.6245117f, -2.6313477f, -2.6652832f, -2.767334f,
+ 2.0964355f, 0.20458984f, -1.2553711f, -2.0012207f, -1.9951172f, -1.407959f, -1.0788574f, -0.47460938f, -0.01928711f, 0.45239258f, 0.73779297f, 0.9333496f, 1.0112305f, 1.1274414f, 0.90893555f, 0.7597656f,
+ -1.2897949f, 0.13867188f, 0.4831543f, 0.6274414f, 0.5175781f, 0.54541016f, 0.46826172f, 0.548584f, 0.39135742f, 0.4975586f, 0.38671875f, -0.022705078f, -0.36083984f, -0.8190918f, -1.0593262f, -1.0527344f,
+ 0.80029297f, 0.57250977f, 0.068359375f, -0.70996094f, -1.0571289f, -0.92041016f, -0.74121094f, -0.3017578f, 0.1850586f, 0.7922363f, 0.76171875f, 0.55859375f, 0.39135742f, 0.22363281f, -0.09790039f, -0.5253906f,
+ 4.5966797f, 2.5993652f, 0.8737793f, -0.9536133f, -0.07006836f, 2.6501465f, 1.3757324f, -0.8967285f, -1.6777344f, -1.2912598f, -0.5917969f, -1.3334961f, -1.4775391f, -0.6760254f, -1.0019531f, -2.1257324f,
+ -1.0061035f, 0.67407227f, 0.9157715f, 0.9851074f, 0.78564453f, -0.009277344f, -0.40039062f, -0.12524414f, -0.18310547f, -0.0029296875f, -0.38989258f, -0.40820312f, -0.37158203f, -0.15551758f, 0.010253906f, -0.3178711f,
+ -1.3325195f, 0.7138672f, 1.6359863f, 2.2177734f, 1.659668f, 1.9414062f, 1.0874023f, 1.3305664f, 1.4523926f, 1.2883301f, -0.56225586f, -2.0280762f, -2.8566895f, -2.5690918f, -2.1638184f, -1.8144531f,
+ 0.0925293f, 1.5366211f, 2.095459f, 1.9145508f, 1.4782715f, 0.8676758f, -0.34643555f, -0.21826172f, -1.1254883f, -1.1550293f, -0.92211914f, -0.5473633f, -0.89868164f, -0.77441406f, -0.8112793f, -1.1855469f,
+ 2.2070312f, 3.5219727f, 1.9643555f, 0.5649414f, -0.021728516f, 0.14941406f, 0.15991211f, 0.21850586f, -1.1708984f, -1.1306152f, -0.32299805f, -0.064453125f, -1.4772949f, -1.6064453f, -1.3984375f, -1.5932617f,
+ 2.5195312f, 2.3515625f, 1.3063965f, 0.20825195f, -0.609375f, -1.088623f, -1.3623047f, -1.2600098f, -1.3369141f, -1.0693359f, -0.8010254f, -0.42773438f, -0.15234375f, 0.44799805f, 0.5998535f, 0.6743164f,
+ 1.5209961f, 1.0463867f, 0.74560547f, 0.51342773f, 0.34448242f, 0.21533203f, -0.028320312f, -0.084228516f, 0.08618164f, 0.12475586f, -0.3557129f, -0.5698242f, -0.63012695f, -0.6933594f, -0.9638672f, -1.2717285f,
+ -0.5739746f, -0.20629883f, -0.9890137f, -1.8708496f, -1.9855957f, -1.6159668f, -1.6103516f, -1.3623047f, -0.9399414f, -0.067871094f, 0.9128418f, 1.7995605f, 2.1074219f, 2.2941895f, 2.331787f, 1.7766113f,
+ 3.6323242f, 1.9743652f, 0.3935547f, -0.6862793f, -1.1130371f, -1.0187988f, -0.8935547f, -0.5998535f, -0.4345703f, -0.2290039f, -0.26416016f, -0.21484375f, -0.13208008f, 0.009765625f, -0.16601562f, -0.2578125f,
+ -0.0871582f, 1.651123f, 1.8327637f, 0.54125977f, 0.23999023f, 1.421875f, 0.79663086f, 1.309082f, 0.98217773f, 1.2548828f, -1.8842773f, -1.8806152f, -1.5390625f, -1.3496094f, -1.2785645f, -2.0100098f,
+ -2.2109375f, -0.70288086f, 1.1103516f, 2.2207031f, 2.3356934f, 2.010498f, 1.638916f, 1.4345703f, 1.0351562f, 0.5690918f, -0.11035156f, -0.88256836f, -1.5859375f, -2.0117188f, -2.31958f, -2.5310059f,
+ -1.6091309f, -2.519287f, -2.4504395f, 0.26660156f, 2.321289f, 2.5898438f, 3.5390625f, -1.0505371f, -1.2543945f, -0.27734375f, 0.94873047f, 1.3859863f, 0.7109375f, -1.0185547f, -1.2666016f, -0.31689453f,
+ 0.94433594f, 2.465332f, 2.668457f, 1.9997559f, 1.2949219f, 1.0178223f, 0.888916f, 0.7038574f, 0.29248047f, -0.050048828f, -0.77001953f, -1.4472656f, -2.0839844f, -2.5202637f, -2.6381836f, -2.7663574f,
+ -0.14160156f, -0.3083496f, -0.5864258f, -1.2387695f, -1.4682617f, -1.1057129f, -0.7817383f, -0.5292969f, -0.06323242f, 0.54003906f, 0.8947754f, 1.3034668f, 1.3681641f, 1.1462402f, 0.7866211f, 0.18408203f,
+ 0.40478516f, -0.94018555f, -1.2241211f, -1.1057129f, -0.43066406f, -0.07324219f, 2.0061035f, 4.0029297f, 0.48828125f, 0.20117188f, 0.16235352f, -0.4182129f, -0.7751465f, -0.74072266f, -0.7463379f, -0.81152344f,
+ -2.7770996f, -2.1079102f, -1.5097656f, -1.515625f, -1.0080566f, -0.036621094f, 0.3708496f, 1.060791f, 1.3742676f, 1.2963867f, 0.9782715f, 1.0876465f, 0.9584961f, 0.8691406f, 0.7578125f, 0.20092773f,
+ 1.8244629f, 2.9589844f, 2.7573242f, 1.1542969f, 0.87109375f, 1.3430176f, 0.9003906f, 0.8564453f, 0.41308594f, -0.40551758f, -2.0913086f, -2.3833008f, -2.1589355f, -1.9533691f, -1.9741211f, -2.1125488f,
+ 2.1027832f, 1.2624512f, 1.0627441f, 0.8051758f, 0.22583008f, -0.12939453f, -0.3996582f, -0.54052734f, -0.74975586f, -0.7180176f, -0.7895508f, -0.7229004f, -0.6113281f, -0.2956543f, -0.21484375f, -0.28710938f,
+ 0.15161133f, 2.585205f, 1.7568359f, 0.9177246f, 0.37329102f, -0.16088867f, -0.4633789f, -0.21801758f, -0.09277344f, -0.021484375f, -0.22631836f, -0.42382812f, -0.66625977f, -0.8803711f, -1.0666504f, -1.5649414f,
+ -2.6091309f, -1.9162598f, -1.4050293f, -1.5510254f, -1.4436035f, -0.76904297f, -0.6994629f, -0.28881836f, -0.09326172f, 0.4140625f, 0.6401367f, 1.267334f, 1.7597656f, 2.1586914f, 2.4848633f, 2.0510254f,
+ -0.08935547f, 1.982666f, 2.4018555f, 1.3012695f, 0.122802734f, 0.8886719f, 1.3410645f, 1.0705566f, 0.115234375f, -0.2043457f, -0.97094727f, -2.4370117f, -2.147705f, -1.3283691f, -0.74731445f, -1.298584f,
+ 2.5476074f, 0.140625f, -0.8376465f, -1.244873f, -1.2324219f, -0.7644043f, -0.34521484f, 0.3581543f, 0.60839844f, 0.5698242f, 0.3034668f, 0.06274414f, 0.27563477f, 0.35498047f, -0.28588867f, -0.5109863f,
+ -0.5878906f, 1.0141602f, 1.5241699f, 1.2287598f, 0.76123047f, 0.6047363f, 0.2199707f, 0.21044922f, 0.15185547f, 0.15307617f, -0.115478516f, -0.46313477f, -0.689209f, -0.9284668f, -1.3129883f, -1.770752f,
+ 1.4040527f, -0.9628906f, -1.3322754f, -0.79785156f, 0.06591797f, -0.045166016f, -0.33520508f, -0.6257324f, -0.91748047f, -0.9824219f, -0.9892578f, -0.84472656f, -0.66137695f, -0.057861328f, 2.248291f, 4.8339844f,
+ 2.727539f, 3.736084f, 3.4023438f, 2.6699219f, 1.3686523f, 0.091308594f, -0.7897949f, -1.1069336f, -1.4260254f, -1.4335938f, -1.5388184f, -1.5930176f, -1.5603027f, -1.5078125f, -1.473877f, -1.565918f,
+ 1.2629395f, 2.5461426f, 1.8774414f, -0.051513672f, -1.0480957f, -0.94873047f, -0.40551758f, 0.21875f, 0.01977539f, -0.1484375f, -0.44140625f, -0.5810547f, -0.5349121f, -0.4650879f, -0.51831055f, -0.7819824f,
+ -2.1455078f, -0.25683594f, 1.3151855f, 1.635498f, 1.4401855f, 0.89624023f, 0.8405762f, 0.9350586f, 0.9802246f, 0.67041016f, -0.13085938f, -0.59521484f, -0.9729004f, -1.145752f, -1.4951172f, -1.9714355f,
+ -2.1291504f, -2.1418457f, -0.46704102f, 0.73291016f, 1.2219238f, -0.27856445f, -0.30517578f, 1.1865234f, 0.87231445f, -0.060791016f, 0.060058594f, 0.43701172f, 0.79174805f, 0.9128418f, -0.046142578f, -0.7866211f,
+ 3.130127f, 2.7661133f, 1.8110352f, 1.4995117f, 1.095459f, 0.8935547f, 0.8383789f, 0.5913086f, 0.21923828f, -0.1965332f, -0.982666f, -1.7121582f, -2.2011719f, -2.409912f, -2.5390625f, -2.803711f,
+ 1.5769043f, 0.34960938f, -0.17211914f, -0.4428711f, -0.62597656f, -0.57055664f, -0.6516113f, -0.43676758f, -0.38208008f, -0.18725586f, -0.16992188f, -0.0034179688f, 0.15356445f, 0.39404297f, 0.56396484f, 0.60424805f,
+ 0.12768555f, 0.2109375f, 0.16137695f, 0.063964844f, 0.13012695f, 0.39526367f, 0.5834961f, 0.62353516f, 0.50683594f, 0.37402344f, 0.060546875f, -0.13232422f, -0.37719727f, -0.6010742f, -0.8376465f, -1.2895508f,
+ 0.6723633f, 1.9140625f, 0.3737793f, -1.2988281f, -1.7912598f, -1.2351074f, -0.44628906f, 0.5895996f, 0.6838379f, 0.58935547f, 0.22460938f, -0.013183594f, -0.16479492f, 0.072021484f, 0.14501953f, -0.3149414f,
+ 4.0183105f, 2.2834473f, 1.317627f, 1.2583008f, 1.5627441f, 0.9851074f, 0.12817383f, -0.2944336f, -0.65527344f, -0.9675293f, -1.3979492f, -1.5356445f, -1.5737305f, -1.5908203f, -1.6887207f, -1.8493652f,
+ 0.8132324f, 0.6748047f, 0.44433594f, 0.35375977f, 0.09863281f, 0.048095703f, -0.15063477f, -0.12646484f, -0.18432617f, -0.15258789f, -0.30517578f, -0.29101562f, -0.31201172f, -0.23876953f, -0.26635742f, -0.40551758f,
+ 0.29345703f, 2.6530762f, 3.4177246f, 2.5812988f, 2.1159668f, 1.3947754f, 0.9523926f, 0.41479492f, -0.15844727f, -0.9025879f, -1.5444336f, -1.9780273f, -2.2106934f, -2.2788086f, -2.3234863f, -2.4267578f,
+ 0.75805664f, 2.5563965f, 2.8410645f, 2.2597656f, 0.3876953f, -1.067627f, -1.425293f, -0.795166f, -0.6105957f, -0.66381836f, -0.9675293f, -1.0371094f, -0.88916016f, -0.5444336f, -0.19042969f, -0.6118164f,
+ 1.7177734f, 3.0668945f, 3.2519531f, 2.4799805f, 0.7363281f, -0.8156738f, -0.8125f, 0.1430664f, 0.34375f, -0.27563477f, -1.4462891f, -1.4350586f, -1.4143066f, -1.6706543f, -1.8481445f, -2.0212402f,
+ 2.756836f, 1.090332f, 0.61572266f, 0.1928711f, -0.34521484f, -0.47509766f, -0.36767578f, -0.0637207f, 0.14233398f, 0.19580078f, -0.16015625f, -0.43286133f, -0.6472168f, -0.5493164f, -0.80737305f, -1.1452637f,
+ 1.0544434f, 1.0671387f, 1.1149902f, 1.1230469f, 0.78637695f, 0.64282227f, 0.4868164f, 0.3413086f, 0.13769531f, -0.13085938f, -0.64990234f, -0.89453125f, -1.074707f, -1.114502f, -1.3056641f, -1.5842285f,
+ -1.8156738f, -1.3222656f, -1.4528809f, -1.8908691f, -1.8740234f, -1.1118164f, -1.1750488f, -0.5734863f, 0.16308594f, 1.5822754f, 2.0114746f, 1.8625488f, 1.6049805f, 1.5942383f, 1.5368652f, 0.8605957f,
+ 3.2451172f, 2.7807617f, 1.2692871f, 0.5222168f, 0.119384766f, -0.06616211f, -0.15722656f, -0.10424805f, -0.27197266f, -0.45263672f, -0.83618164f, -1.1611328f, -1.333252f, -1.2722168f, -1.2016602f, -1.0800781f,
+ 0.17333984f, 2.4299316f, 2.3254395f, 1.3701172f, 0.47509766f, 0.72216797f, 0.072753906f, -0.037597656f, -0.41845703f, -0.8137207f, -1.5649414f, -2.4125977f, -1.3486328f, -0.53027344f, -0.10546875f, -0.33740234f,
+ -2.5983887f, -1.9645996f, -0.5678711f, 0.48999023f, 0.86743164f, 0.62158203f, 1.189209f, 1.3269043f, 1.182373f, 1.0024414f, 0.54785156f, 0.25634766f, -0.12133789f, -0.44140625f, -0.7026367f, -1.0881348f,
+ 0.071777344f, -2.279541f, -2.057373f, -0.25512695f, 2.2199707f, 2.541748f, 0.8342285f, 0.7907715f, 0.5048828f, -0.1303711f, 0.2631836f, -0.37036133f, -0.5187988f, -0.42285156f, -0.66845703f, -0.52368164f,
+ 1.3261719f, 3.1193848f, 2.583496f, 0.6767578f, -0.022460938f, 0.5214844f, 0.6105957f, 1.0021973f, 0.66845703f, 0.8640137f, -0.37353516f, -2.0703125f, -2.3225098f, -2.136963f, -2.057129f, -2.3894043f,
+ 1.4580078f, 2.0153809f, 1.0583496f, -0.12792969f, -0.6064453f, -0.7011719f, -0.96118164f, -0.8588867f, -0.7414551f, -0.18896484f, 0.1550293f, 0.46166992f, 0.3881836f, 0.16113281f, -0.37109375f, -1.140625f,
+ 1.6044922f, 0.8898926f, -0.053222656f, -0.26611328f, 0.084228516f, 0.5666504f, 0.9013672f, 1.1362305f, 1.1520996f, 0.74243164f, 0.5168457f, 0.11206055f, -0.8305664f, -1.7199707f, -2.109375f, -2.7270508f,
+ -1.3208008f, -0.083984375f, -0.24169922f, -0.95043945f, -1.2331543f, -0.564209f, -0.018798828f, 0.95654297f, 1.142334f, 1.1772461f, 0.8063965f, 0.43359375f, 0.08227539f, 0.07446289f, 0.099853516f, -0.359375f,
+ 2.0480957f, 2.739746f, 2.1257324f, 1.1525879f, 0.7644043f, 0.5031738f, 0.2758789f, 0.19311523f, -0.08642578f, -0.15893555f, -0.89990234f, -1.2700195f, -1.5583496f, -1.791748f, -1.9023438f, -2.135254f,
+ 2.2700195f, 2.2856445f, 1.5393066f, 0.77563477f, 0.23632812f, -0.017578125f, -0.23071289f, -0.19995117f, -0.26342773f, -0.17700195f, -0.5046387f, -0.6687012f, -0.8383789f, -1.057373f, -1.3330078f, -1.8166504f,
+ 0.66015625f, 1.6772461f, 1.604248f, 1.5366211f, 1.1013184f, 0.8173828f, 0.5605469f, 0.7155762f, 0.5270996f, 0.23291016f, -0.37719727f, -0.8352051f, -1.3342285f, -1.7580566f, -2.2695312f, -2.8588867f,
+ 0.21484375f, -0.44580078f, -0.85253906f, -1.0334473f, -0.95043945f, -0.592041f, -0.47558594f, -0.20092773f, -0.06323242f, 0.16040039f, 0.24414062f, 0.5144043f, 0.70947266f, 0.8796387f, 0.9663086f, 0.92529297f,
+ -0.047851562f, 1.6748047f, 2.0949707f, 2.3344727f, 1.7766113f, 1.7685547f, 0.35913086f, 0.47509766f, -0.055664062f, -0.08251953f, -0.76049805f, -1.8425293f, -2.8457031f, -2.4018555f, -1.144043f, -1.3034668f,
+ 2.0942383f, 1.1809082f, 0.54345703f, 0.18408203f, -0.44360352f, -0.5373535f, 0.12182617f, 0.7114258f, 0.8088379f, 0.7709961f, -0.12866211f, -1.1555176f, -1.4138184f, -1.0009766f, -0.83081055f, -0.90478516f,
+ -1.0332031f, 1.6005859f, 0.46875f, 1.6149902f, -0.23095703f, 1.0908203f, 0.068359375f, 0.5266113f, 0.18701172f, -0.12792969f, -0.22509766f, -0.4819336f, -0.5058594f, -0.390625f, -1.2128906f, -1.3486328f,
+ 1.7792969f, 0.7167969f, -0.40039062f, -1.1201172f, -1.5458984f, -1.5344238f, -1.5107422f, -1.3601074f, -1.2751465f, -0.93847656f, -0.40795898f, 0.49145508f, 1.2475586f, 2.0236816f, 2.0373535f, 1.7973633f,
+ 2.8059082f, 2.769043f, 1.6977539f, 0.44458008f, -0.41308594f, -0.6376953f, -0.80566406f, -0.81030273f, -0.93115234f, -0.66845703f, -0.7155762f, -0.6870117f, -0.6052246f, -0.46142578f, -0.41967773f, -0.56225586f,
+ 1.9963379f, 2.9060059f, 1.5930176f, -0.34716797f, -0.7993164f, 0.061279297f, 1.0302734f, 1.1359863f, 0.7434082f, -0.07397461f, -1.3549805f, -1.2399902f, -1.2802734f, -1.2973633f, -1.4362793f, -1.6364746f,
+ -2.3041992f, -0.73999023f, 0.11791992f, 0.3215332f, 0.45092773f, 0.45751953f, 0.7368164f, 0.7216797f, 0.19238281f, 0.75439453f, 0.17822266f, -0.46679688f, -0.41210938f, 0.029785156f, 0.20996094f, -0.24829102f,
+ -0.9016113f, -1.2150879f, -0.13208008f, 0.7023926f, 0.81225586f, -0.57055664f, -1.0405273f, -0.5344238f, 0.1706543f, 0.579834f, 0.80810547f, 0.4790039f, 0.3671875f, 0.24829102f, 0.32202148f, -0.095214844f,
+ 1.4807129f, 1.8234863f, 1.7661133f, 2.5449219f, 2.6020508f, 1.9316406f, 1.3154297f, 1.1328125f, 0.5263672f, -0.17895508f, -1.1706543f, -2.199707f, -2.7531738f, -2.8725586f, -2.9294434f, -3.0187988f,
+ 2.6689453f, 0.5949707f, -0.45043945f, -0.7963867f, -0.91625977f, -0.90722656f, -0.98413086f, -0.8354492f, -0.6953125f, -0.3955078f, -0.2849121f, 0.04296875f, 0.43066406f, 0.7241211f, 0.81591797f, 0.9880371f,
+ -0.15112305f, -0.33618164f, -0.3256836f, -0.111083984f, -0.048339844f, 0.08129883f, 0.068115234f, 0.17138672f, 0.20385742f, 0.2590332f, 0.123291016f, 0.11621094f, 0.03100586f, 0.06201172f, 0.06591797f, -0.2097168f,
+ 1.2731934f, 0.29223633f, -0.14038086f, -0.29956055f, -0.6376953f, -0.56762695f, -0.15844727f, 0.46020508f, 0.6569824f, 0.68188477f, 0.28393555f, -0.18676758f, -0.43164062f, -0.3347168f, -0.38256836f, -0.5083008f,
+ 4.678711f, 2.80542f, 1.126709f, -0.48461914f, -0.8273926f, 0.7895508f, 2.3266602f, 0.4375f, -1.6252441f, -1.8422852f, -1.4978027f, -0.8730469f, -1.3171387f, -1.671875f, -1.0270996f, -0.998291f,
+ -1.3620605f, 0.63916016f, 1.1337891f, 0.3178711f, 0.06591797f, 1.0673828f, 0.91503906f, 0.4387207f, -0.18359375f, -0.22875977f, -0.6660156f, -0.69799805f, -0.17236328f, -0.21118164f, -0.24951172f, -0.8066406f,
+ -0.44873047f, 1.4709473f, 2.5039062f, 2.7050781f, 1.9462891f, 0.3642578f, -0.30078125f, 0.6467285f, 0.9680176f, 0.9716797f, -1.498291f, -1.8183594f, -1.8544922f, -1.847168f, -1.605957f, -2.2028809f,
+ 0.47460938f, 1.574707f, 1.7148438f, 2.1083984f, 1.7241211f, 0.44189453f, -0.40551758f, -0.18847656f, 0.13232422f, -0.0031738281f, -0.79467773f, -1.1843262f, -1.2902832f, -1.2416992f, -1.3430176f, -1.7194824f,
+ 1.9831543f, 3.927246f, 2.9868164f, 1.2749023f, 0.265625f, 0.02734375f, 0.079833984f, 0.47070312f, -0.7956543f, -1.2663574f, -1.638916f, -1.8222656f, -1.3908691f, -1.4194336f, -1.3027344f, -1.3791504f,
+ 0.2097168f, 1.8005371f, 1.479248f, 0.62109375f, 0.091552734f, -0.38549805f, -0.93530273f, -0.923584f, -0.91259766f, -0.6557617f, -0.5842285f, -0.27563477f, 0.007080078f, 0.25585938f, 0.25219727f, -0.044677734f,
+ 0.51293945f, 1.0280762f, 0.84033203f, 0.62841797f, 0.5317383f, 0.5251465f, 0.26953125f, 0.09423828f, 0.032958984f, -0.052734375f, -0.48999023f, -0.6513672f, -0.6411133f, -0.6369629f, -0.84375f, -1.1477051f,
+ -1.2319336f, -0.08203125f, -0.23632812f, -0.8339844f, -1.0866699f, -0.88793945f, -1.0917969f, -0.83251953f, -0.79467773f, -0.45751953f, -0.25830078f, 0.43041992f, 1.1853027f, 1.7946777f, 2.3452148f, 2.0378418f,
+ 4.881592f, 2.1987305f, 0.6430664f, -0.15478516f, -0.36206055f, -0.4753418f, -0.5410156f, -0.1965332f, -0.072753906f, -0.10888672f, -0.5263672f, -0.8588867f, -0.94506836f, -0.99487305f, -1.1523438f, -1.3347168f,
+ -0.5546875f, 2.1118164f, 2.2026367f, 0.70703125f, -0.21142578f, 0.8679199f, 1.1367188f, 1.012207f, 0.9904785f, 1.2463379f, 0.21801758f, -1.9433594f, -2.9155273f, -2.2661133f, -0.97631836f, -1.6257324f,
+ -0.80908203f, 1.0163574f, 1.546875f, 2.0847168f, 1.9309082f, 1.6364746f, 1.057373f, 1.1618652f, 0.76049805f, 0.29858398f, -0.46484375f, -1.0957031f, -1.6264648f, -2.0043945f, -2.5080566f, -2.9853516f,
+ -0.29760742f, -1.7080078f, -1.5229492f, 1.3574219f, 4.701172f, 1.6962891f, 4.1030273f, -0.4194336f, -1.0739746f, -1.0820312f, 0.4255371f, -1.0825195f, -1.3613281f, -1.1777344f, -1.3232422f, -1.2341309f,
+ 1.7912598f, 1.7314453f, 1.8457031f, 2.1989746f, 1.9145508f, 1.0024414f, 0.51538086f, 0.44506836f, -0.075683594f, -0.5439453f, -1.1616211f, -1.5820312f, -1.8642578f, -1.9123535f, -2.0385742f, -2.2666016f,
+ -0.03100586f, -1.7485352f, -1.767334f, -1.9833984f, -1.4570312f, -0.84716797f, -0.50390625f, 0.040771484f, 0.43554688f, 0.62402344f, 0.9133301f, 1.4772949f, 1.7192383f, 1.2922363f, 0.80029297f, 1.0356445f,
+ -1.1809082f, -2.032959f, -2.0617676f, -1.9443359f, -1.6447754f, -0.8874512f, 3.0722656f, 2.6242676f, 2.3166504f, 3.4455566f, 1.090332f, -0.19970703f, -0.23510742f, -0.6906738f, -0.40576172f, -1.2653809f,
+ -2.2512207f, -1.9179688f, -2.1035156f, -2.3461914f, -2.14917f, -1.1347656f, -0.56689453f, 0.8166504f, 1.857666f, 2.114502f, 1.755127f, 1.9160156f, 1.6611328f, 1.1904297f, 0.8239746f, 0.33398438f,
+ 0.8227539f, 2.0544434f, 2.3171387f, 0.90234375f, 0.515625f, 1.0241699f, 0.6188965f, 0.296875f, -0.171875f, -0.6345215f, -1.2004395f, -1.1652832f, -1.1635742f, -1.2021484f, -1.3903809f, -1.6240234f,
+ 1.2287598f, 1.5820312f, 1.2756348f, 0.6843262f, 0.33911133f, 0.09472656f, -0.26733398f, -0.4711914f, -0.3137207f, -0.19116211f, -0.56884766f, -0.67944336f, -0.5612793f, -0.55444336f, -0.69506836f, -0.90234375f,
+ 1.5776367f, 2.6791992f, 2.3059082f, 1.375f, 0.7619629f, 0.08251953f, -0.6166992f, -0.8574219f, -1.0148926f, -1.0390625f, -1.0976562f, -0.8730469f, -0.7844238f, -0.7331543f, -0.7426758f, -1.0231934f,
+ -2.173584f, -1.3400879f, -0.8208008f, -0.95996094f, -0.6999512f, -0.010253906f, -0.19384766f, 0.25561523f, 0.3786621f, 0.72998047f, 0.4699707f, 0.4416504f, 0.49975586f, 0.9416504f, 1.4606934f, 1.0205078f,
+ -0.2631836f, 1.3510742f, 1.3837891f, 2.0864258f, 1.8503418f, 1.8864746f, 0.8581543f, 0.5866699f, 0.103759766f, -0.9616699f, -1.8740234f, -2.5600586f, -1.1362305f, -0.9301758f, -1.4404297f, -0.94091797f,
+ 2.7443848f, 0.5695801f, -0.21679688f, -0.6513672f, -0.14672852f, 0.5019531f, 0.23754883f, -0.19091797f, -0.27685547f, -0.15332031f, -0.31201172f, -0.35742188f, -0.2529297f, -0.25024414f, -0.62646484f, -0.61816406f,
+ 0.045898438f, 0.24243164f, 0.36865234f, 0.9145508f, 0.96777344f, 1.0041504f, 0.9550781f, 0.9213867f, 0.7089844f, 0.4296875f, -0.1328125f, -0.5522461f, -0.9333496f, -1.2285156f, -1.607666f, -2.1037598f,
+ 4.209961f, 1.2607422f, -0.85791016f, -1.416748f, -1.4013672f, -0.8574219f, -1.0410156f, -1.4523926f, -1.7346191f, -1.7731934f, -1.5373535f, -1.026123f, 0.8515625f, 0.21533203f, 2.2263184f, 4.3342285f,
+ 4.5341797f, 4.130371f, 2.7658691f, 2.1801758f, 0.90478516f, 0.5617676f, -0.1303711f, -1.1745605f, -1.5371094f, -1.5292969f, -1.6901855f, -1.7126465f, -1.7119141f, -1.7536621f, -1.8623047f, -1.9750977f,
+ 0.6777344f, 2.2624512f, 1.1889648f, -0.5876465f, -0.81347656f, 0.38916016f, 0.11694336f, 0.15283203f, -0.5698242f, -0.5168457f, -0.41845703f, -0.3544922f, -0.46191406f, -0.24804688f, -0.14038086f, -0.6772461f,
+ -1.3227539f, -0.38085938f, 0.23852539f, 0.76123047f, 1.0078125f, 1.1433105f, 0.9753418f, 0.7734375f, 0.32373047f, 0.08959961f, -0.19482422f, -0.43603516f, -0.5715332f, -0.6135254f, -0.7351074f, -1.0581055f,
+ -1.3225098f, -1.4675293f, -1.3000488f, -0.59375f, 0.022705078f, 0.57299805f, 0.5710449f, 0.36547852f, 0.5119629f, 0.77685547f, 0.623291f, 0.43408203f, 0.41210938f, 0.5258789f, 0.2434082f, -0.37597656f,
+ 2.3742676f, 3.3117676f, 3.0449219f, 2.4208984f, 1.2329102f, 0.63793945f, 0.32666016f, 0.15161133f, -0.25610352f, -1.0283203f, -1.7250977f, -1.9707031f, -2.0761719f, -2.1174316f, -2.1105957f, -2.2165527f,
+ 0.87109375f, 0.5085449f, 0.19018555f, -0.10913086f, -0.36328125f, -0.3725586f, -0.4946289f, -0.38671875f, -0.38183594f, -0.21801758f, -0.2331543f, -0.088378906f, 0.0234375f, 0.24194336f, 0.40649414f, 0.40600586f,
+ 1.0517578f, 0.5126953f, 0.23608398f, 0.31835938f, 0.3605957f, 0.39941406f, 0.38012695f, 0.50390625f, 0.54541016f, 0.37329102f, -0.24731445f, -0.5891113f, -0.6791992f, -0.7324219f, -1.0258789f, -1.407959f,
+ -0.66625977f, 1.7709961f, 1.2971191f, 0.15283203f, -1.0664062f, -0.7583008f, 0.16821289f, 0.5007324f, 0.35058594f, 0.14086914f, 0.5217285f, -0.13452148f, -1.2158203f, -0.34375f, 0.033447266f, -0.751709f,
+ 3.684082f, 3.3139648f, 2.0878906f, 1.1911621f, 0.607666f, 0.1472168f, 0.15258789f, 0.10083008f, -0.2355957f, -0.45239258f, -1.2746582f, -1.7348633f, -1.8305664f, -1.8266602f, -1.8925781f, -2.03833f,
+ 0.5786133f, 0.7692871f, 0.4777832f, 0.05493164f, -0.12597656f, -0.08227539f, -0.095703125f, 0.05444336f, 0.19848633f, 0.3190918f, 0.030273438f, -0.06738281f, -0.17138672f, -0.2854004f, -0.59375f, -1.0615234f,
+ -0.98413086f, 1.059082f, 2.3671875f, 2.3381348f, 2.529541f, 2.1052246f, 1.887207f, 1.2434082f, 0.54956055f, -0.12646484f, -0.9199219f, -1.6921387f, -2.3168945f, -2.5715332f, -2.6733398f, -2.7949219f,
+ 2.5153809f, 3.854248f, 2.8759766f, 1.9558105f, -0.30126953f, -1.3845215f, -1.4958496f, -1.2636719f, -1.1201172f, -0.84887695f, -1.1677246f, -0.63061523f, -0.4970703f, -0.76904297f, -0.72998047f, -0.9926758f,
+ 0.4025879f, 2.572998f, 3.1643066f, 2.5009766f, 1.3688965f, -0.08691406f, -0.63500977f, -0.119140625f, 0.0073242188f, -0.5070801f, -0.7023926f, -2.0339355f, -2.0788574f, -1.8864746f, -0.9301758f, -1.0368652f,
+ 2.1965332f, 1.2878418f, 0.50878906f, -0.119140625f, -0.49267578f, -0.6008301f, -0.75219727f, -0.56518555f, -0.5427246f, -0.4038086f, -0.43408203f, -0.28198242f, -0.13745117f, 0.06958008f, 0.14331055f, 0.1237793f,
+ 0.5012207f, 2.1748047f, 1.7189941f, 0.1274414f, -0.2644043f, 0.46875f, 0.37963867f, 0.7302246f, 0.23413086f, 0.41845703f, -0.7944336f, -0.8984375f, -0.6816406f, -1.0744629f, -1.190918f, -1.8496094f,
+ -2.3083496f, -2.19458f, -2.2111816f, -2.4804688f, -2.3293457f, -1.651123f, -1.3820801f, -0.78125f, -0.14477539f, 0.8547363f, 1.6848145f, 2.4699707f, 2.5429688f, 2.793457f, 2.9118652f, 2.2253418f,
+ 1.7553711f, 2.8996582f, 1.9260254f, 0.40551758f, -0.0234375f, 0.44506836f, 0.31152344f, 0.1809082f, -0.47607422f, -0.4807129f, -1.204834f, -1.3293457f, -1.2412109f, -1.0134277f, -0.89501953f, -1.2602539f,
+ 0.2253418f, 2.2539062f, 2.265625f, 0.57128906f, -0.7661133f, -0.6245117f, 0.21313477f, 1.2248535f, 0.8737793f, -0.12524414f, -0.9609375f, -2.416504f, -1.1223145f, -0.70532227f, -0.31469727f, -0.592041f,
+};
+
+const float ivas_sns_cdbk_tcx20_stage2[ 64 * 16 ] =
+{
+ -1.1569824f, -0.4765625f, 0.008056641f, 0.47802734f, 0.38330078f, -0.075683594f, -0.3737793f, -0.29516602f, -0.1352539f, 0.012939453f, 0.22241211f, 0.375f, 0.31689453f, 0.20874023f, 0.2541504f, 0.25439453f,
+ -0.40600586f, -0.22070312f, -0.04272461f, 0.15893555f, -0.25195312f, -0.6623535f, -0.27172852f, 0.28735352f, 0.35742188f, 0.20166016f, 0.052246094f, -0.3647461f, -0.4506836f, 0.1862793f, 0.66796875f, 0.7585449f,
+ 0.02734375f, -0.2097168f, -0.39819336f, -0.54296875f, -0.46850586f, -0.25146484f, -0.26953125f, -0.07495117f, 0.375f, 0.9343262f, 0.91625977f, 0.4267578f, 0.026123047f, -0.15576172f, -0.11425781f, -0.22021484f,
+ 0.011230469f, 0.37573242f, 0.8432617f, 0.7006836f, 0.5830078f, -0.49658203f, -0.84155273f, -0.46069336f, -0.16894531f, -0.006591797f, -0.075683594f, -0.2253418f, -0.2097168f, -0.12719727f, 0.006591797f, 0.092041016f,
+ 0.42382812f, 0.19360352f, 0.076171875f, 0.44091797f, 0.11401367f, -0.39819336f, -0.12207031f, 0.34960938f, 0.51660156f, -0.024902344f, -0.5324707f, -0.068359375f, 0.5083008f, -0.06591797f, -0.68359375f, -0.7277832f,
+ -0.12182617f, 0.15332031f, 0.3022461f, 0.23754883f, 0.2722168f, 0.8046875f, 0.76831055f, 0.28808594f, -0.05493164f, -0.29711914f, -0.45629883f, -0.42944336f, -0.42871094f, -0.4416504f, -0.35107422f, -0.24536133f,
+ -0.19873047f, -0.010253906f, -0.030517578f, -0.041748047f, 0.052490234f, 0.07446289f, 0.026123047f, -0.026611328f, 0.18579102f, 0.22485352f, 0.1965332f, 0.1538086f, 0.044677734f, -0.111328125f, -0.24853516f, -0.29052734f,
+ 0.7648926f, 0.47973633f, 0.31347656f, 0.1496582f, 0.23242188f, 0.16918945f, 0.05859375f, -0.12548828f, -0.18017578f, -0.19555664f, -0.17138672f, -0.19165039f, -0.23510742f, -0.3330078f, -0.37939453f, -0.3564453f,
+ -0.6201172f, -0.2915039f, -0.15234375f, 0.15966797f, 0.41430664f, 0.61206055f, 0.4453125f, 0.19360352f, -0.107666016f, -0.40429688f, -0.10424805f, 0.40649414f, 0.37817383f, -0.012939453f, -0.3857422f, -0.53100586f,
+ -0.6376953f, -0.01953125f, 0.32958984f, -0.27905273f, -0.21191406f, 0.8327637f, 0.28515625f, -0.31225586f, -0.4375f, -0.34204102f, -0.010498047f, 0.0546875f, 0.099365234f, 0.114746094f, 0.22973633f, 0.30444336f,
+ -0.76538086f, -0.5390625f, -0.38330078f, -0.39501953f, -0.21923828f, 0.19311523f, 0.1899414f, -0.08642578f, -0.044921875f, 0.13500977f, 0.4543457f, 0.6777344f, 0.5891113f, 0.30078125f, 0.04321289f, -0.14990234f,
+ 0.34838867f, -0.21826172f, 0.018066406f, 0.06689453f, 0.40063477f, 0.34570312f, -0.548584f, -0.86035156f, -0.24023438f, 0.60668945f, 0.22363281f, -0.05053711f, 0.13916016f, 0.02709961f, -0.07470703f, -0.18383789f,
+ 0.13842773f, 0.05444336f, 0.20629883f, -0.11450195f, -0.77563477f, -0.57543945f, 0.7011719f, 0.20117188f, -0.33984375f, 0.18481445f, 0.38232422f, -0.2097168f, -0.040771484f, 0.13476562f, 0.0769043f, -0.024658203f,
+ -0.24829102f, -0.47998047f, -0.7248535f, -0.64575195f, -0.2529297f, 0.43725586f, 0.6335449f, 0.6464844f, 0.53930664f, 0.33398438f, 0.13891602f, 0.30639648f, 0.3293457f, -0.07446289f, -0.3918457f, -0.54711914f,
+ -0.043945312f, -0.5168457f, -0.3779297f, 0.67089844f, 0.2548828f, -0.4663086f, -0.5402832f, -0.22338867f, 0.092285156f, 0.016845703f, 0.24780273f, 0.46850586f, 0.49902344f, 0.2734375f, -0.0925293f, -0.26245117f,
+ 0.014892578f, 0.3540039f, 0.35229492f, -0.13085938f, -0.49829102f, -0.52563477f, -0.05883789f, 0.024658203f, -0.29492188f, -0.4638672f, -0.17333984f, 0.3791504f, 0.47314453f, 0.29516602f, 0.19165039f, 0.060791016f,
+ -0.21264648f, -0.875f, -0.82958984f, -0.5048828f, -0.31835938f, -0.1430664f, 0.19580078f, 0.29174805f, 0.28637695f, 0.15356445f, 0.16894531f, 0.2241211f, 0.27734375f, 0.31835938f, 0.4091797f, 0.55810547f,
+ -1.2670898f, 0.016845703f, 0.36254883f, 0.65893555f, 0.59814453f, 0.49389648f, 0.18041992f, 0.1821289f, 0.15942383f, -0.016357422f, -0.18847656f, -0.36547852f, -0.3413086f, -0.2553711f, -0.14868164f, -0.06958008f,
+ 0.10644531f, 0.7878418f, 0.09643555f, -0.5786133f, -0.40966797f, 0.07055664f, 0.39819336f, 0.31030273f, 0.10986328f, 0.14013672f, 0.2680664f, 0.32861328f, 0.04296875f, -0.39648438f, -0.6052246f, -0.66967773f,
+ -0.49658203f, 0.26416016f, 0.657959f, 0.41137695f, 0.28881836f, 0.22338867f, 0.15527344f, -0.08325195f, -0.118652344f, 0.08544922f, 0.2841797f, 0.15258789f, -0.18554688f, -0.48388672f, -0.5810547f, -0.5734863f,
+ 0.22314453f, 0.37402344f, 0.2163086f, -0.5078125f, -0.95703125f, -1.1442871f, -0.35302734f, 0.68359375f, 0.67089844f, 0.31811523f, 0.12792969f, -0.15478516f, -0.0026855469f, 0.18237305f, 0.16870117f, 0.15429688f,
+ 0.26464844f, -0.11401367f, -0.106933594f, 0.26538086f, 0.51660156f, 0.5373535f, 0.35888672f, 0.16870117f, 0.20825195f, 0.2409668f, 0.14013672f, -0.0546875f, -0.3334961f, -0.58691406f, -0.74243164f, -0.7624512f,
+ 0.73779297f, -0.14477539f, -0.37646484f, -0.1003418f, 0.1027832f, 0.14160156f, 0.06738281f, -0.05444336f, -0.016357422f, -0.0234375f, -0.022216797f, -0.049316406f, -0.061035156f, -0.10864258f, -0.09057617f, -0.0017089844f,
+ 1.0466309f, 0.6826172f, 0.1315918f, -0.21020508f, -0.104003906f, -0.21191406f, -0.3256836f, -0.4729004f, -0.59765625f, -0.50805664f, -0.2043457f, 0.033935547f, 0.115722656f, 0.09423828f, 0.18017578f, 0.34960938f,
+ -0.9074707f, -0.25634766f, 0.14331055f, 0.03515625f, -0.076171875f, -0.1340332f, -0.0073242188f, 0.20922852f, 0.40063477f, 0.5883789f, 0.64868164f, 0.50024414f, 0.19238281f, -0.22338867f, -0.47998047f, -0.6333008f,
+ 0.40429688f, 0.021972656f, 0.059814453f, 0.5866699f, 1.2155762f, 0.35351562f, -0.17480469f, -0.0703125f, -0.09448242f, -0.24975586f, -0.39672852f, -0.3347168f, -0.3479004f, -0.38671875f, -0.36743164f, -0.21948242f,
+ 0.71850586f, -0.052246094f, -0.3918457f, -0.13745117f, 0.13793945f, 0.20458984f, 0.13623047f, -0.15039062f, -0.22436523f, -0.2446289f, 0.12158203f, 0.58496094f, 0.5527344f, -0.028320312f, -0.60180664f, -0.6254883f,
+ 0.007080078f, 0.32910156f, 0.41210938f, 0.033203125f, -0.2097168f, -0.06665039f, -0.15307617f, 0.020507812f, 0.33203125f, 0.8874512f, 0.7089844f, -0.4128418f, -0.71484375f, -0.4958496f, -0.29223633f, -0.38476562f,
+ -0.84765625f, 0.3466797f, 0.107910156f, -0.3659668f, -0.48583984f, -0.41552734f, -0.38232422f, -0.26953125f, 0.019042969f, 0.25219727f, 0.40039062f, 0.3984375f, 0.38427734f, 0.29785156f, 0.29589844f, 0.26391602f,
+ 0.47680664f, -0.0056152344f, -0.15307617f, -0.33764648f, -0.30737305f, 0.24511719f, 0.8847656f, 0.61035156f, -0.32861328f, -0.6430664f, -0.43823242f, -0.1899414f, -0.12475586f, -0.084228516f, 0.111328125f, 0.28393555f,
+ 1.0576172f, -0.23535156f, -0.9638672f, -0.84716797f, 0.3137207f, 1.1804199f, 0.7871094f, 0.14257812f, -0.018798828f, -0.21801758f, -0.20703125f, -0.11816406f, -0.10449219f, -0.16210938f, -0.3491211f, -0.25708008f,
+ -0.028564453f, -0.43652344f, -0.20336914f, 0.13623047f, 0.17822266f, 0.2175293f, -0.026367188f, -0.4050293f, -0.6472168f, -0.670166f, -0.26391602f, 0.3864746f, 0.685791f, 0.53808594f, 0.29077148f, 0.24853516f,
+ -0.32836914f, -0.09106445f, -0.11254883f, -0.34277344f, -0.5786133f, -0.5319824f, -0.45410156f, -0.34716797f, -0.2163086f, -0.1862793f, -0.09448242f, 0.14550781f, 0.32739258f, 0.6513672f, 1.0861816f, 1.0732422f,
+ 0.17163086f, 0.26391602f, 0.19165039f, 0.028320312f, -0.05517578f, 0.14355469f, 0.09057617f, 0.03125f, -0.20532227f, -0.36889648f, -0.58569336f, -0.7468262f, -0.75634766f, -0.04272461f, 0.84814453f, 0.9921875f,
+ 0.61376953f, -0.18969727f, -0.4868164f, -0.45410156f, -0.42089844f, -0.39868164f, -0.34399414f, -0.25610352f, -0.104003906f, 0.11791992f, 0.3408203f, 0.4416504f, 0.40942383f, 0.31689453f, 0.22802734f, 0.18603516f,
+ -0.5876465f, 0.19213867f, 0.30737305f, 0.46264648f, 0.37817383f, 0.08276367f, -0.36279297f, -0.51904297f, -0.53125f, -0.42382812f, -0.27075195f, -0.15063477f, -0.026611328f, 0.21655273f, 0.5439453f, 0.6879883f,
+ -0.5786133f, -0.046875f, 0.0390625f, -0.026123047f, 0.034423828f, -0.28442383f, -0.5217285f, 0.07299805f, 0.7167969f, 0.84106445f, -0.34570312f, -0.3466797f, 0.25512695f, 0.31958008f, 0.12207031f, -0.2512207f,
+ -0.19604492f, 0.11645508f, 0.17895508f, 0.2697754f, 0.4050293f, 0.2927246f, 0.09667969f, -0.12817383f, -0.14550781f, -0.1706543f, -0.16308594f, -0.13354492f, -0.11376953f, -0.14282227f, -0.12866211f, -0.037353516f,
+ -0.2084961f, -0.2878418f, -0.23657227f, -0.11816406f, 0.016357422f, 0.059326172f, 0.067871094f, -0.033447266f, -0.013427734f, 0.0029296875f, 0.068603516f, 0.12548828f, 0.14624023f, 0.11279297f, 0.11254883f, 0.18530273f,
+ -0.13549805f, 1.1516113f, 0.5197754f, -0.064453125f, -0.2409668f, -0.1274414f, -0.021484375f, -0.07104492f, -0.095458984f, -0.11987305f, -0.12573242f, -0.18701172f, -0.20874023f, -0.21459961f, -0.08081055f, 0.021484375f,
+ -0.33520508f, -0.6520996f, -0.2927246f, 0.8496094f, 0.6022949f, 0.35229492f, 0.1484375f, 0.06347656f, -0.13232422f, -0.390625f, -0.41137695f, -0.27294922f, -0.1694336f, -0.027832031f, 0.18310547f, 0.48510742f,
+ 0.22802734f, 0.8112793f, 0.25610352f, -0.5793457f, 0.18774414f, 0.74902344f, 0.122802734f, -0.38842773f, -0.57714844f, -0.842041f, -0.97314453f, -0.74975586f, 0.20605469f, 1.4348145f, 0.22973633f, -0.115722656f,
+ -0.103759766f, 0.055664062f, -0.29663086f, -0.3864746f, -0.36743164f, -0.38549805f, -0.22802734f, -0.19311523f, -0.11816406f, -0.11645508f, 0.2578125f, 1.0197754f, 1.0957031f, 0.7624512f, -0.19189453f, -0.8034668f,
+ 0.31860352f, -0.32495117f, -0.25756836f, 0.4501953f, 0.74731445f, 0.26293945f, -0.5578613f, -0.6347656f, 0.056152344f, 1.1223145f, 0.27783203f, -0.8347168f, -0.96850586f, -0.2019043f, 0.5266113f, 0.018798828f,
+ 0.2434082f, 0.05126953f, -0.16088867f, -0.2434082f, -0.15234375f, 0.037353516f, 0.06982422f, -0.015136719f, -0.607666f, 0.14428711f, 0.94433594f, 0.37109375f, -0.3083496f, -0.34765625f, -0.12060547f, 0.09448242f,
+ 0.13427734f, 0.47021484f, -0.4387207f, -0.8562012f, -0.6101074f, -0.10913086f, 0.1430664f, 0.18334961f, 0.103759766f, -0.034423828f, -0.06738281f, 0.036376953f, 0.12670898f, 0.18603516f, 0.33496094f, 0.39697266f,
+ 1.0314941f, -0.5073242f, 0.050048828f, 0.31860352f, -0.055908203f, -0.6105957f, -0.31860352f, -0.056396484f, 0.072753906f, 0.056884766f, -0.053466797f, -0.06933594f, -0.08666992f, -0.038330078f, 0.047851562f, 0.21875f,
+ 0.47192383f, 0.58447266f, 0.6154785f, -0.078125f, -0.6315918f, -0.92626953f, -0.89501953f, -0.46069336f, -0.14819336f, -0.03125f, 0.046142578f, 0.14086914f, 0.12646484f, 0.25390625f, 0.47753906f, 0.4543457f,
+ -1.1186523f, -0.5427246f, -0.36108398f, -0.13378906f, -0.0048828125f, 0.2939453f, 0.45581055f, 0.3972168f, 0.2421875f, -0.18725586f, -0.576416f, -0.25805664f, 0.115722656f, 0.517334f, 0.6699219f, 0.4909668f,
+ -0.8635254f, -0.1977539f, -0.067871094f, -0.060058594f, 0.08251953f, 0.5378418f, 0.0007324219f, -0.067871094f, -0.0053710938f, 0.513916f, 0.42993164f, -0.3544922f, -0.6711426f, -0.15454102f, 0.5522461f, 0.3256836f,
+ 0.62231445f, 0.44702148f, 0.3725586f, 0.15454102f, -0.13916016f, -0.40576172f, -0.49829102f, -0.3881836f, -0.13867188f, 0.2355957f, 0.5095215f, 0.3972168f, 0.0793457f, -0.22802734f, -0.44213867f, -0.5776367f,
+ -0.64086914f, 0.17944336f, 1.0073242f, 0.46972656f, -0.33007812f, -0.33569336f, -0.016357422f, -0.064208984f, -0.08105469f, -0.14916992f, -0.05444336f, 0.016845703f, -0.010009766f, -0.08911133f, -0.012207031f, 0.10961914f,
+ 0.47485352f, -0.13232422f, 0.21044922f, 0.36645508f, -0.11303711f, -0.8552246f, -0.7819824f, 0.8149414f, 1.0595703f, -0.46044922f, -0.359375f, -0.04296875f, -0.21948242f, -0.24584961f, 0.037353516f, 0.24707031f,
+ 0.28710938f, -0.68530273f, 0.22631836f, 0.119384766f, -0.17114258f, -0.29833984f, 0.33618164f, 0.49438477f, 0.4248047f, 0.171875f, 0.20385742f, 0.08935547f, -0.20922852f, -0.38671875f, -0.3569336f, -0.24584961f,
+ 0.33544922f, 0.27172852f, 0.040283203f, -0.072509766f, -0.008544922f, -0.095458984f, -0.19897461f, -0.2980957f, -0.17480469f, -0.12133789f, -0.060791016f, 0.012451172f, 0.087890625f, 0.059814453f, 0.068115234f, 0.1550293f,
+ 1.1574707f, 0.5593262f, -0.16137695f, -0.44140625f, -0.38305664f, -0.24731445f, -0.0056152344f, 0.10961914f, 0.21948242f, 0.22314453f, -0.0036621094f, -0.20166016f, -0.27416992f, -0.28295898f, -0.21240234f, -0.055419922f,
+ -0.75561523f, -0.84399414f, -0.079589844f, 0.29614258f, 0.24389648f, 0.3671875f, 0.5605469f, 0.3630371f, 0.26220703f, 0.17895508f, 0.06274414f, -0.052734375f, -0.14526367f, -0.21069336f, -0.1550293f, -0.091796875f,
+ 0.32055664f, 0.47436523f, 0.56640625f, 0.517334f, 0.42260742f, 0.2890625f, 0.12719727f, -0.23291016f, -0.5283203f, -0.7036133f, -0.6333008f, -0.40454102f, -0.23364258f, -0.1628418f, -0.011962891f, 0.19335938f,
+ -0.05493164f, 0.5136719f, 0.30395508f, 0.49072266f, 0.3581543f, -0.09301758f, -0.38183594f, -0.4338379f, -0.57299805f, -0.4794922f, -0.17651367f, 0.42651367f, 0.56103516f, 0.28149414f, -0.22875977f, -0.51416016f,
+ 0.2709961f, -0.26635742f, -0.44995117f, -0.079589844f, 0.21728516f, 0.43017578f, 0.4206543f, 0.47827148f, 0.58691406f, 0.27612305f, -0.26391602f, -0.65771484f, -0.67944336f, -0.3935547f, -0.11791992f, 0.2277832f,
+ -0.80078125f, 0.18066406f, 0.12036133f, -0.39575195f, -0.60009766f, -0.13134766f, 0.77685547f, 0.5834961f, 0.4248047f, 0.15820312f, 0.08520508f, -0.060058594f, -0.1652832f, -0.17700195f, -0.0234375f, 0.023925781f,
+ 0.28100586f, 0.4013672f, 0.5695801f, 0.1394043f, -0.20532227f, -0.18286133f, 0.40698242f, 0.703125f, 0.54907227f, 0.09301758f, -0.47631836f, -0.62597656f, -0.4975586f, -0.39160156f, -0.41259766f, -0.3515625f,
+ 0.3227539f, -1.0678711f, -1.1435547f, 0.068603516f, 0.7546387f, 0.38745117f, 0.09008789f, -0.0007324219f, -0.12792969f, 0.076416016f, 0.24853516f, 0.28735352f, 0.076660156f, -0.041748047f, -0.01977539f, 0.08911133f,
+ 0.6101074f, -0.22070312f, -0.5324707f, -0.119384766f, 0.10473633f, 0.16333008f, -0.15112305f, -0.34472656f, -0.39746094f, -0.43652344f, -0.23876953f, 0.0017089844f, 0.056152344f, 0.22973633f, 0.50024414f, 0.7751465f,
+};
+
+const float ivas_sns_cdbk_tcx20_stage3[ 32 * 16 ] =
+{
+ -0.12109375f, -0.32348633f, -0.25976562f, 0.21435547f, 0.4814453f, 0.14819336f, -0.22363281f, -0.31030273f, -0.13256836f, 0.10107422f, 0.33276367f, 0.32495117f, 0.16577148f, -0.079833984f, -0.16210938f, -0.15527344f,
+ 0.088378906f, -0.0146484375f, -0.13378906f, -0.29003906f, 0.873291f, -0.3125f, -0.19384766f, 0.19311523f, -0.09863281f, 0.052734375f, -0.13110352f, -0.021972656f, -0.07861328f, -0.01977539f, -0.07373047f, 0.1616211f,
+ -0.115722656f, 0.28100586f, 0.2697754f, -0.10522461f, -0.107910156f, -0.2866211f, -0.36694336f, -0.33862305f, -0.15844727f, 0.01928711f, 0.17382812f, 0.21118164f, 0.2697754f, 0.17260742f, 0.07299805f, 0.009033203f,
+ 0.08154297f, 0.037841797f, -0.25878906f, -0.30444336f, -0.064208984f, 0.1303711f, 0.36669922f, 0.39916992f, 0.3400879f, 0.14331055f, -0.01171875f, -0.12060547f, -0.17041016f, -0.23071289f, -0.20825195f, -0.13012695f,
+ -0.024902344f, -0.6298828f, 0.7861328f, -0.010986328f, -0.12695312f, -0.08618164f, 0.022705078f, 0.049316406f, 0.004638672f, -0.13647461f, -0.09863281f, 0.0f, 0.06518555f, 0.014404297f, 0.060546875f, 0.111083984f,
+ -0.39404297f, 0.16821289f, 0.28564453f, -0.08666992f, -0.16088867f, 0.052246094f, 0.26000977f, 0.057128906f, -0.050048828f, -0.07836914f, 0.016601562f, 0.05883789f, 0.07373047f, -0.03955078f, -0.08520508f, -0.07763672f,
+ 0.011962891f, -0.114990234f, -0.10229492f, -0.07080078f, 0.009765625f, -0.03125f, -0.15600586f, -0.014892578f, 0.10546875f, -0.040283203f, -0.48095703f, -0.2783203f, 0.5905762f, 0.66137695f, 0.13842773f, -0.22802734f,
+ 0.48706055f, 0.18286133f, -0.20678711f, -0.17651367f, -0.19750977f, -0.3178711f, -0.2524414f, 0.0087890625f, 0.2866211f, 0.25708008f, 0.18969727f, 0.11694336f, 0.049316406f, -0.05517578f, -0.17700195f, -0.19482422f,
+ 0.122802734f, -0.09667969f, 0.05444336f, 0.17358398f, 0.22924805f, 0.35229492f, 0.40307617f, 0.031982422f, -0.16064453f, -0.14819336f, -0.103027344f, -0.088134766f, -0.13623047f, -0.23510742f, -0.2434082f, -0.15600586f,
+ -0.5810547f, -0.0146484375f, -0.43432617f, -0.07397461f, 0.30444336f, 0.36035156f, 0.19213867f, 0.12890625f, 0.13061523f, 0.031982422f, -0.024902344f, -0.059326172f, -0.048583984f, -0.030517578f, 0.03149414f, 0.087646484f,
+ -0.1171875f, 0.016357422f, 0.15234375f, 0.38916016f, 0.2783203f, -0.007080078f, -0.07373047f, -0.2055664f, -0.30004883f, -0.35839844f, -0.23388672f, -0.033935547f, 0.08520508f, 0.10913086f, 0.125f, 0.17480469f,
+ -0.107666016f, 0.06274414f, -0.0048828125f, 0.12792969f, -0.023925781f, -0.2199707f, -0.084228516f, 0.34399414f, 0.22753906f, -0.39697266f, -0.32421875f, 0.48779297f, 0.43554688f, -0.15429688f, -0.22436523f, -0.14550781f,
+ 0.0031738281f, -0.03955078f, 0.06738281f, -0.017822266f, -0.2644043f, 0.30493164f, 0.30200195f, -0.32495117f, -0.5007324f, 0.15478516f, 0.60961914f, 0.15527344f, -0.1899414f, -0.14526367f, 0.017822266f, -0.1315918f,
+ 0.036621094f, -0.11669922f, -0.33691406f, -0.5373535f, -0.13598633f, 0.3046875f, 0.3215332f, -0.10620117f, -0.1640625f, -0.08569336f, 0.012451172f, 0.10839844f, 0.20117188f, 0.17553711f, 0.15258789f, 0.16967773f,
+ -0.4362793f, -0.47265625f, -0.16870117f, -0.111083984f, -0.1772461f, -0.1430664f, 0.015136719f, 0.12719727f, 0.13647461f, 0.12988281f, 0.19238281f, 0.22827148f, 0.23266602f, 0.17504883f, 0.14453125f, 0.12768555f,
+ -0.07495117f, 0.19604492f, 0.13110352f, -0.10131836f, -0.0078125f, -0.18847656f, -0.048828125f, 0.33862305f, 0.2578125f, -0.17089844f, -0.40698242f, -0.28857422f, -0.048339844f, 0.048828125f, 0.14916992f, 0.21459961f,
+ -0.27734375f, -0.072509766f, 0.26049805f, 0.39038086f, 0.2277832f, 0.020751953f, -0.12109375f, -0.080322266f, 0.171875f, 0.36743164f, 0.107421875f, -0.19311523f, -0.22607422f, -0.20654297f, -0.19799805f, -0.17041016f,
+ 0.1352539f, 0.40039062f, -0.15649414f, -0.25341797f, 0.31054688f, 0.5410156f, -0.32958984f, -0.42871094f, 0.14794922f, 0.17333984f, -0.17871094f, -0.23730469f, -0.026611328f, -0.013427734f, -0.046142578f, -0.037841797f,
+ -0.30395508f, 0.12841797f, 0.20825195f, -0.119628906f, -0.3317871f, -0.3190918f, -0.11206055f, 0.10205078f, 0.32470703f, 0.36254883f, 0.2626953f, 0.016113281f, -0.12890625f, -0.16479492f, -0.005126953f, 0.080566406f,
+ 0.34375f, 0.35888672f, 0.4765625f, 0.13623047f, -0.115722656f, -0.053222656f, 0.080566406f, -0.012207031f, -0.022216797f, -0.09863281f, -0.080566406f, -0.13574219f, -0.18383789f, -0.26123047f, -0.2578125f, -0.17504883f,
+ 0.01171875f, -0.015625f, 0.2680664f, -0.23461914f, -0.35717773f, 0.6381836f, -0.30664062f, 0.08129883f, -0.05493164f, 0.10058594f, -0.026855469f, -0.10180664f, -0.013671875f, -0.06347656f, 0.00048828125f, 0.07446289f,
+ -0.1015625f, 0.05053711f, 0.092285156f, 0.038330078f, -0.03491211f, 0.16479492f, 0.0859375f, 0.0036621094f, -0.15454102f, -0.09106445f, 0.026367188f, -0.23950195f, -0.43676758f, -0.27783203f, 0.21850586f, 0.6555176f,
+ -0.16064453f, 0.032958984f, 0.08325195f, 0.052978516f, -0.041748047f, 0.08959961f, 0.16552734f, 0.057373047f, -0.08154297f, 0.21362305f, 0.048583984f, -0.7026367f, -0.27685547f, 0.51000977f, 0.27197266f, -0.26245117f,
+ 0.62109375f, 0.00390625f, 0.08081055f, 0.16748047f, 0.08276367f, -0.11254883f, -0.20825195f, -0.3076172f, -0.24926758f, -0.15332031f, 0.0007324219f, 0.087646484f, 0.11303711f, 0.022705078f, -0.068847656f, -0.080322266f,
+ 0.40844727f, -0.390625f, -0.35473633f, 0.21777344f, 0.21972656f, -0.0107421875f, 0.111328125f, 0.21459961f, 0.1430664f, -0.08935547f, -0.19165039f, -0.2368164f, -0.1340332f, -0.034179688f, 0.030761719f, 0.09667969f,
+ -0.2199707f, 0.8208008f, -0.32104492f, 0.118896484f, -0.006591797f, -0.1328125f, 0.0078125f, -0.013183594f, -0.05493164f, -0.024414062f, 0.06542969f, -0.0014648438f, -0.055664062f, -0.06762695f, -0.07055664f, -0.044677734f,
+ -0.14770508f, -0.16967773f, -0.1105957f, 0.6333008f, -0.4025879f, -0.3515625f, 0.29736328f, 0.0859375f, 0.024414062f, -0.07128906f, 0.010253906f, 0.0007324219f, -0.021728516f, 0.01977539f, 0.083496094f, 0.12060547f,
+ -0.06738281f, 0.030517578f, 0.019042969f, 0.16308594f, 0.16796875f, 0.037109375f, 0.059326172f, 0.07397461f, 0.03540039f, 0.05517578f, 0.06982422f, 0.061523438f, 0.1940918f, 0.20605469f, -0.3178711f, -0.7878418f,
+ 0.1274414f, -0.040771484f, -0.21704102f, -0.025634766f, 0.012451172f, -0.033203125f, -0.15771484f, 0.052001953f, -0.19165039f, -0.26342773f, 0.032226562f, 0.7976074f, -0.4807129f, -0.21582031f, 0.36499023f, 0.2397461f,
+ 0.46044922f, 0.21435547f, 0.0847168f, -0.24414062f, -0.49902344f, -0.16577148f, 0.30151367f, 0.049560547f, -0.07470703f, -0.21459961f, -0.13256836f, -0.009277344f, 0.06665039f, 0.029052734f, 0.0390625f, 0.095214844f,
+ 0.17895508f, -0.31396484f, -0.033203125f, -0.02734375f, -0.0637207f, -0.11791992f, -0.03466797f, 0.0061035156f, 0.07324219f, 0.072753906f, 0.14916992f, 0.13671875f, 0.12524414f, 0.017333984f, -0.08178711f, -0.08618164f,
+ 0.13330078f, -0.15893555f, -0.22045898f, -0.032226562f, -0.07739258f, -0.25463867f, -0.32299805f, -0.2614746f, 0.039794922f, 0.18554688f, 0.1262207f, -0.04321289f, -0.010498047f, 0.13330078f, 0.31860352f, 0.44506836f,
+};
+
+const float ivas_sns_cdbk_tcx20_stage4[ 32 * 16 ] =
+{
+ -0.0056152344f, -0.03955078f, 0.071777344f, 0.26879883f, 0.44140625f, -0.08203125f, -0.20092773f, -0.009277344f, 0.05810547f, -0.06347656f, -0.07910156f, -0.05126953f, -0.07006836f, -0.068847656f, -0.07885742f, -0.09082031f,
+ -0.011962891f, -0.060302734f, 0.011962891f, 0.049804688f, -0.044677734f, 0.037841797f, 0.099121094f, 0.06274414f, 0.022216797f, -0.09057617f, 0.00390625f, 0.38452148f, 0.1027832f, -0.5292969f, -0.3269043f, 0.28881836f,
+ -0.3557129f, 0.3815918f, 0.10839844f, 0.08203125f, 0.03149414f, -0.0024414062f, -0.0036621094f, -0.02758789f, -0.03125f, -0.096191406f, -0.09326172f, -0.103515625f, -0.07006836f, 0.008056641f, 0.06616211f, 0.10644531f,
+ 0.038330078f, 0.022460938f, -0.22070312f, 0.529541f, -0.3540039f, 0.29907227f, -0.16235352f, -0.03955078f, 0.053222656f, -0.07348633f, -0.051513672f, 0.021484375f, 0.04638672f, 0.029541016f, -0.052001953f, -0.08618164f,
+ 0.075927734f, -0.19604492f, 0.046875f, -0.00048828125f, -0.052978516f, -0.03491211f, 0.19067383f, 0.08520508f, -0.16113281f, -0.29785156f, -0.22558594f, -0.07006836f, 0.053955078f, 0.1550293f, 0.19042969f, 0.2409668f,
+ 0.08227539f, 0.26464844f, -0.15332031f, -0.140625f, -0.0068359375f, 0.060302734f, -0.05126953f, -0.23339844f, -0.28442383f, -0.14160156f, 0.0793457f, 0.23828125f, 0.20678711f, 0.09716797f, 0.014892578f, -0.032470703f,
+ 0.20581055f, -0.19702148f, 0.053466797f, 0.026855469f, -0.011962891f, -0.04663086f, -0.11254883f, 0.060058594f, 0.33984375f, 0.33447266f, -0.14257812f, -0.37719727f, -0.21850586f, 0.016845703f, 0.08325195f, -0.013916016f,
+ 0.34375f, -0.38623047f, -0.06542969f, -0.07348633f, -0.107421875f, 0.037353516f, 0.14477539f, 0.01586914f, 0.0026855469f, 0.08959961f, 0.19433594f, 0.1027832f, -0.03149414f, -0.060058594f, -0.1003418f, -0.10668945f,
+ 0.12841797f, 0.01953125f, 0.16333008f, 0.22827148f, -0.16015625f, -0.42016602f, -0.19067383f, 0.08642578f, 0.08520508f, -0.022705078f, 0.011230469f, 0.013671875f, -0.0034179688f, 0.019042969f, -0.005859375f, 0.047851562f,
+ 0.02734375f, 0.008056641f, -0.07470703f, 0.114990234f, 0.0021972656f, -0.41796875f, 0.5605469f, -0.28735352f, 0.022949219f, -0.07739258f, -0.028808594f, 0.1928711f, 0.056152344f, 0.0053710938f, -0.048583984f, -0.055419922f,
+ -0.037109375f, 0.12939453f, -0.38671875f, -0.095214844f, 0.0021972656f, -0.012451172f, 0.19677734f, 0.2578125f, 0.12670898f, -0.10180664f, -0.087890625f, 0.009521484f, 0.1418457f, 0.14526367f, -0.076660156f, -0.21166992f,
+ 0.29711914f, 0.06616211f, -0.375f, -0.080566406f, 0.1484375f, -0.0007324219f, -0.020996094f, 0.013427734f, -0.014160156f, -0.11279297f, -0.08081055f, -0.056152344f, -0.13769531f, -0.060546875f, 0.10595703f, 0.30810547f,
+ -0.025146484f, 0.023925781f, -0.02758789f, -0.0009765625f, 0.08178711f, -0.13452148f, -0.022949219f, 0.6875f, -0.39794922f, -0.123046875f, 0.06738281f, 0.04345703f, -0.053955078f, -0.0146484375f, -0.045410156f, -0.05810547f,
+ 0.0146484375f, 0.041748047f, -0.024902344f, 0.005126953f, -0.079589844f, -0.04638672f, -0.028320312f, 0.021972656f, -0.11450195f, -0.118896484f, -0.041748047f, -0.001953125f, -0.2783203f, 0.33154297f, 0.64575195f, -0.32543945f,
+ -0.13989258f, -0.020019531f, 0.3137207f, -0.53271484f, 0.3154297f, 0.037353516f, -0.04272461f, -0.059326172f, -0.05444336f, -0.009765625f, -0.0073242188f, 0.015380859f, 0.0769043f, 0.08251953f, 0.01171875f, 0.013427734f,
+ -0.049804688f, 0.022949219f, -0.08227539f, -0.08544922f, 0.012451172f, 0.015380859f, -0.2241211f, 0.15625f, -0.19750977f, 0.5703125f, -0.3684082f, 0.072753906f, 0.4711914f, -0.35888672f, 0.14697266f, -0.10205078f,
+ -0.17138672f, -0.19067383f, -0.21411133f, -0.030517578f, 0.09667969f, -0.087402344f, -0.09643555f, 0.017089844f, 0.08666992f, 0.041503906f, 0.05908203f, 0.034179688f, 0.08129883f, 0.12841797f, 0.12011719f, 0.12548828f,
+ -0.044921875f, 0.0061035156f, 0.037841797f, 0.017089844f, 0.064453125f, 0.008300781f, -0.20532227f, -0.025146484f, 0.07397461f, 0.06225586f, -0.15991211f, -0.27612305f, 0.44873047f, 0.14111328f, -0.40893555f, 0.26049805f,
+ -0.14941406f, 0.17773438f, 0.022949219f, -0.125f, 0.00048828125f, 0.19018555f, 0.03857422f, -0.039794922f, 0.09448242f, 0.20214844f, 0.22436523f, 0.111572266f, -0.08081055f, -0.16992188f, -0.25146484f, -0.24633789f,
+ -0.09350586f, 0.028076172f, -0.04272461f, 0.05419922f, 0.01586914f, -0.16870117f, -0.30395508f, -0.17285156f, 0.0690918f, 0.30541992f, 0.23266602f, -0.09082031f, 0.1340332f, 0.3449707f, 0.036621094f, -0.3486328f,
+ -0.20019531f, -0.10449219f, 0.041992188f, 0.09350586f, 0.010253906f, 0.04711914f, 0.26342773f, 0.23852539f, 0.13598633f, -0.04296875f, -0.063964844f, -0.13769531f, -0.18164062f, -0.10083008f, -0.033691406f, 0.03491211f,
+ 0.14648438f, 0.02758789f, 0.33984375f, -0.005126953f, -0.09887695f, 0.04272461f, -0.18652344f, -0.33129883f, -0.14208984f, 0.040039062f, 0.036376953f, -0.072509766f, -0.119628906f, -0.0017089844f, 0.09448242f, 0.23046875f,
+ 0.23852539f, 0.26513672f, 0.034179688f, 0.04272461f, 0.05053711f, 0.03466797f, 0.12182617f, 0.03930664f, -0.018066406f, -0.095947266f, -0.107666016f, -0.16040039f, -0.17211914f, -0.12524414f, -0.09716797f, -0.05078125f,
+ -0.08178711f, -0.05126953f, -0.20507812f, 0.115478516f, 0.14453125f, -0.010986328f, -0.16357422f, -0.05102539f, 0.037597656f, 0.24365234f, 0.38452148f, 0.05444336f, -0.40283203f, -0.21972656f, 0.0793457f, 0.12695312f,
+ -0.2548828f, -0.28222656f, 0.19628906f, 0.2890625f, 0.047851562f, -0.034179688f, 0.012451172f, -0.1159668f, -0.20947266f, -0.08154297f, 0.13427734f, 0.16333008f, 0.07885742f, 0.05078125f, 0.013427734f, -0.0078125f,
+ -0.067871094f, 0.02368164f, -0.010986328f, -0.037109375f, -0.19140625f, 0.118896484f, -0.020019531f, -0.3955078f, 0.5673828f, -0.02758789f, -0.23950195f, 0.103759766f, -0.04736328f, 0.029785156f, 0.07495117f, 0.118896484f,
+ 0.095214844f, -0.0078125f, 0.36035156f, -0.075927734f, -0.20385742f, 0.0625f, 0.15332031f, 0.044921875f, 0.0041503906f, -0.13793945f, -0.1472168f, 0.015136719f, 0.17504883f, 0.1105957f, -0.14648438f, -0.30151367f,
+ 0.063964844f, -0.0234375f, 0.07739258f, -0.24169922f, 0.041015625f, 0.18823242f, -0.43701172f, 0.25976562f, 0.25097656f, -0.37182617f, 0.040771484f, 0.2590332f, 0.0036621094f, -0.044677734f, -0.03173828f, -0.03466797f,
+ 0.025390625f, 0.09301758f, 0.11328125f, -0.027832031f, -0.0087890625f, -0.0703125f, 0.028320312f, -0.052734375f, -0.1953125f, -0.32617188f, 0.67871094f, -0.07397461f, -0.15039062f, -0.0703125f, -0.02758789f, 0.064697266f,
+ -0.049560547f, 0.15551758f, -0.016113281f, -0.27661133f, -0.30371094f, -0.13427734f, 0.08203125f, 0.09814453f, 0.07495117f, 0.038330078f, 0.055664062f, -0.00390625f, -0.018554688f, 0.0390625f, 0.10620117f, 0.15283203f,
+ -0.04321289f, -0.18408203f, -0.045654297f, -0.05029297f, 0.21191406f, 0.5300293f, 0.09716797f, -0.12866211f, -0.09423828f, -0.08666992f, -0.087890625f, -0.09643555f, -0.045166016f, 0.021972656f, -0.013183594f, 0.014160156f,
+ -0.0017089844f, -0.014160156f, -0.048339844f, -0.037109375f, -0.0949707f, -0.005859375f, 0.48388672f, -0.17480469f, -0.19140625f, 0.5727539f, -0.18920898f, -0.26391602f, 0.0048828125f, 0.067871094f, -0.045654297f, -0.06201172f,
+};
+
+const float *const ivas_sns_cdbks_tcx20[SNS_MSVQ_NSTAGES_TCX20] = { ivas_sns_cdbk_tcx20_stage1, ivas_sns_cdbk_tcx20_stage2, ivas_sns_cdbk_tcx20_stage3, ivas_sns_cdbk_tcx20_stage4 };
+
+const int16_t ivas_sns_cdbks_tcx10_levels[SNS_MSVQ_NSTAGES_TCX10] = { 128, 32, 8 };
+
+const int16_t ivas_sns_cdbks_tcx10_bits[SNS_MSVQ_NSTAGES_TCX10] = { 7, 5, 3 };
+
+const float ivas_sns_cdbk_tcx10_stage1[ 128 * 16 ] =
+{
+ 1.0144043f, 1.1826172f, 0.3269043f, -0.6411133f, -1.2163086f, -1.1411133f, -1.1525879f, -0.8898926f, -0.19604492f, 0.7402344f, 1.1782227f, 1.0830078f, 0.78222656f, 0.26953125f, -0.33203125f, -1.0080566f,
+ -0.38916016f, -0.31347656f, -1.1826172f, -2.036621f, -2.086914f, -1.8569336f, -1.637207f, -1.3156738f, -0.4182129f, 0.50634766f, 1.2770996f, 1.3771973f, 1.8566895f, 2.3503418f, 2.3015137f, 1.5678711f,
+ 0.43652344f, 1.8859863f, 2.8059082f, 2.2385254f, 1.5480957f, 0.14331055f, 0.07299805f, -1.1218262f, -1.1103516f, -0.7336426f, -0.4194336f, -0.89624023f, -1.0429688f, -0.79785156f, -1.204834f, -1.8046875f,
+ 1.5612793f, 0.9321289f, 0.58740234f, 0.46313477f, 0.21899414f, 0.0625f, -0.16918945f, -0.34423828f, -0.44726562f, -0.61035156f, -0.6398926f, -0.57177734f, -0.38500977f, -0.25927734f, -0.20898438f, -0.18945312f,
+ 1.0131836f, 1.9333496f, 0.8395996f, -0.4963379f, -0.66015625f, -0.38012695f, 0.056396484f, 0.31201172f, 0.810791f, 0.66674805f, -0.022705078f, -0.7980957f, -0.9230957f, -0.63134766f, -0.68530273f, -1.034668f,
+ -0.842041f, -0.08642578f, 0.49243164f, 0.5827637f, 1.1630859f, 1.3693848f, 0.7233887f, 0.2705078f, 0.34692383f, 0.0068359375f, -0.2319336f, -0.33032227f, -0.5895996f, -0.67626953f, -0.9953613f, -1.2033691f,
+ 2.0810547f, 1.8205566f, 1.1000977f, 0.47216797f, 0.08251953f, -0.48510742f, -0.67285156f, -0.55322266f, -0.4777832f, -0.546875f, -0.579834f, -0.5891113f, -0.5119629f, -0.4255371f, -0.32910156f, -0.38500977f,
+ 1.730957f, 1.3063965f, 0.53466797f, 0.23144531f, 0.04248047f, 0.0036621094f, 0.0949707f, 0.15942383f, 0.1977539f, 0.19946289f, 0.21899414f, 0.064697266f, -0.43408203f, -0.94750977f, -1.5297852f, -1.8735352f,
+ 1.6611328f, 2.8601074f, 1.7668457f, -0.12988281f, -0.27978516f, 1.199707f, 1.4865723f, 1.220459f, 0.61865234f, -1.2509766f, -1.5700684f, -1.3425293f, -1.3532715f, -1.3083496f, -1.5671387f, -2.0112305f,
+ 1.8820801f, 0.6086426f, -0.52319336f, -1.5842285f, -1.2685547f, -0.9067383f, -0.6323242f, -0.203125f, -0.25878906f, 0.091796875f, 0.18286133f, 1.2060547f, 1.0129395f, -0.049560547f, -0.1274414f, 0.5698242f,
+ 0.60498047f, 1.1367188f, 1.5297852f, 1.9936523f, 1.9726562f, 1.9311523f, 1.7668457f, 1.3752441f, 0.939209f, 0.020019531f, -0.72558594f, -1.3706055f, -2.269043f, -2.7990723f, -3.010254f, -3.0957031f,
+ -0.9187012f, 0.107177734f, 0.32495117f, -0.051513672f, -0.2746582f, 0.2043457f, 0.8605957f, 0.30737305f, 0.064208984f, -0.1743164f, -0.5998535f, -0.7624512f, -0.10864258f, 0.49975586f, 0.40283203f, 0.118896484f,
+ 1.0822754f, 0.7507324f, 0.47460938f, 0.00390625f, -0.28881836f, -0.5131836f, -0.62158203f, -0.6550293f, -0.59228516f, -0.42895508f, -0.17675781f, 0.061035156f, 0.119140625f, 0.037109375f, 0.24267578f, 0.5046387f,
+ -2.3117676f, -1.2453613f, -0.7062988f, -0.83813477f, -0.5036621f, 0.040039062f, 0.6281738f, 0.93115234f, 0.826416f, 0.3791504f, 0.19970703f, -0.023925781f, 0.35913086f, 0.953125f, 0.87280273f, 0.43969727f,
+ 3.8930664f, 4.2009277f, 3.1296387f, 2.685791f, 2.1108398f, 2.032959f, 0.046142578f, -1.3862305f, -1.6176758f, -1.9997559f, -2.130371f, -2.1767578f, -2.213623f, -2.2236328f, -2.1501465f, -2.201416f,
+ -1.3452148f, -0.43041992f, 0.38720703f, 1.0549316f, 1.4541016f, 1.6882324f, 1.3688965f, 0.44335938f, -0.037109375f, -0.23144531f, -0.5349121f, -0.7902832f, -0.81152344f, -0.73876953f, -0.6965332f, -0.78027344f,
+ 2.1210938f, 2.654541f, 2.0202637f, 1.1313477f, 0.42333984f, -0.13598633f, -0.31591797f, -0.38500977f, -0.37548828f, -0.7619629f, -0.9873047f, -1.046875f, -0.9699707f, -0.99975586f, -1.0686035f, -1.3034668f,
+ 2.0297852f, 0.09301758f, -1.026123f, -1.6860352f, -0.5925293f, 0.7067871f, 1.1433105f, -0.31152344f, -0.8725586f, -0.37524414f, 0.09326172f, -0.4165039f, -0.375f, -0.32592773f, 0.65185547f, 1.2634277f,
+ 0.49169922f, 1.6848145f, 1.8188477f, 2.048584f, 1.3818359f, 1.3059082f, 0.8100586f, 0.15429688f, -0.40161133f, -1.7539062f, -2.8208008f, -1.5043945f, -0.54663086f, -0.9963379f, -0.7890625f, -0.8833008f,
+ 0.60131836f, 1.9431152f, 1.1845703f, -0.50927734f, -0.51708984f, 0.7182617f, 0.6542969f, 0.06665039f, -0.48120117f, -0.9313965f, -1.0275879f, -0.9108887f, -0.48168945f, 0.055664062f, 0.17333984f, -0.5378418f,
+ 0.5378418f, 0.47216797f, 0.17480469f, -0.3022461f, -0.19726562f, -0.030517578f, -0.008544922f, 0.009277344f, -0.033935547f, -0.022705078f, 0.20629883f, 0.45239258f, 0.18237305f, -0.14233398f, -0.50561523f, -0.7922363f,
+ -2.0576172f, -2.215088f, -1.0456543f, -0.07910156f, 1.4833984f, 1.3276367f, -0.119140625f, -0.638916f, -0.06713867f, 0.8666992f, -0.25634766f, -0.041503906f, 1.1413574f, 1.0339355f, 0.5041504f, 0.16333008f,
+ 2.7668457f, 2.9187012f, 1.6850586f, 0.47216797f, -0.3696289f, -0.70288086f, -0.7890625f, -1.034668f, -0.8354492f, -0.69262695f, -0.6418457f, -0.70751953f, -0.6467285f, -0.49682617f, -0.49023438f, -0.43530273f,
+ 0.104003906f, 0.9812012f, 1.1506348f, 0.9128418f, 0.81933594f, 0.8522949f, 0.7446289f, 0.46069336f, 0.31347656f, -0.06542969f, -0.49536133f, -0.85302734f, -1.0515137f, -1.0839844f, -1.2729492f, -1.5166016f,
+ 0.5107422f, 1.4162598f, 2.0109863f, 2.331787f, 1.6552734f, 0.8979492f, 0.6035156f, 0.2487793f, 0.26049805f, -0.26416016f, -0.7624512f, -1.2497559f, -1.8212891f, -1.807373f, -1.8876953f, -2.1430664f,
+ 0.23461914f, 0.3942871f, -0.2163086f, -1.0683594f, -1.3544922f, -1.2963867f, -1.2163086f, -1.192627f, -0.8947754f, -0.36083984f, 0.29248047f, 0.6989746f, 1.1608887f, 1.6723633f, 1.8217773f, 1.324707f,
+ 3.0012207f, 3.3725586f, 2.8825684f, 2.7036133f, 2.4111328f, 2.5178223f, 1.418457f, 0.048583984f, -0.7297363f, -1.8293457f, -2.4519043f, -2.5717773f, -2.6826172f, -2.7434082f, -2.6733398f, -2.673584f,
+ 0.061035156f, 0.7324219f, 1.2775879f, 0.8625488f, 0.2524414f, 0.092285156f, -0.13500977f, -0.41674805f, -0.52075195f, -0.7026367f, -0.69262695f, -0.5744629f, -0.4494629f, -0.08886719f, 0.17211914f, 0.1303711f,
+ 2.1413574f, 1.7810059f, 0.7092285f, -0.37304688f, -0.6828613f, -0.54296875f, -0.5942383f, -0.9050293f, -0.97558594f, -0.8232422f, -0.6015625f, -0.57128906f, 0.021484375f, 0.59887695f, 0.5192871f, 0.29882812f,
+ -1.3076172f, -0.99609375f, -0.7758789f, -0.83374023f, -0.8322754f, -0.72924805f, -0.5461426f, -0.1652832f, 0.4482422f, 1.0227051f, 1.440918f, 1.338623f, 0.89331055f, 0.6164551f, 0.42700195f, -0.0009765625f,
+ 2.084961f, 3.2036133f, 2.5375977f, 0.7463379f, 0.24682617f, 0.7133789f, 0.46118164f, -0.16430664f, -0.31347656f, -1.1755371f, -1.5986328f, -1.6252441f, -1.3684082f, -1.1738281f, -1.1335449f, -1.440918f,
+ -0.22070312f, 0.74121094f, 0.9091797f, 0.25f, 0.15161133f, 0.5371094f, 0.74902344f, 1.0612793f, 1.1540527f, 0.22924805f, -0.74438477f, -1.1445312f, -1.0881348f, -0.7956543f, -0.7746582f, -1.0144043f,
+ 1.8095703f, 2.084961f, 0.859375f, -0.22167969f, -0.49951172f, -0.58496094f, -0.548584f, -0.35595703f, -0.23828125f, 0.018066406f, -0.119384766f, 0.16845703f, 0.03491211f, -0.8540039f, -1.0222168f, -0.53027344f,
+ -2.2055664f, -2.6103516f, -2.4230957f, -2.2021484f, -0.9482422f, 1.682373f, 2.345459f, 2.1347656f, 1.9140625f, 1.019043f, 0.6623535f, 0.62719727f, 0.85546875f, 0.8095703f, -0.23144531f, -1.4296875f,
+ 3.0585938f, 3.8530273f, 2.633789f, 0.8532715f, -0.09008789f, -0.52685547f, -0.60375977f, -0.7915039f, -0.861084f, -1.2512207f, -1.3881836f, -1.3081055f, -1.1264648f, -0.88378906f, -0.6906738f, -0.8774414f,
+ 0.91845703f, 1.7211914f, 0.89575195f, -0.07543945f, -0.3798828f, -0.49023438f, -0.5810547f, -0.57666016f, -0.4921875f, -0.36206055f, -0.23706055f, -0.22924805f, -0.15600586f, 0.03100586f, 0.0703125f, -0.057128906f,
+ 1.3344727f, 1.2441406f, 0.20483398f, -1.0561523f, -1.0715332f, -0.12084961f, 0.96728516f, 1.5930176f, 1.1330566f, 0.115722656f, -0.45532227f, -0.44140625f, -0.5053711f, -0.8222656f, -0.96972656f, -1.1499023f,
+ -1.8754883f, -2.5437012f, -2.1186523f, 0.6845703f, 1.7653809f, 3.8078613f, 1.5759277f, -0.59228516f, -0.22167969f, 0.5510254f, 1.770752f, 1.2670898f, -0.85180664f, -1.3605957f, -1.5881348f, -0.27026367f,
+ 2.5178223f, 2.0725098f, 1.2094727f, 0.30126953f, -0.29370117f, -0.095947266f, 0.45141602f, 0.4663086f, 0.22338867f, -0.5546875f, -1.3134766f, -1.3378906f, -0.842041f, -0.87231445f, -1.0029297f, -0.92944336f,
+ 2.199707f, 1.7602539f, 1.2255859f, 0.74243164f, 0.45288086f, 0.3161621f, 0.076660156f, -0.23266602f, -0.5065918f, -0.6386719f, -0.6906738f, -0.6977539f, -0.798584f, -0.9692383f, -1.0688477f, -1.1706543f,
+ 0.3564453f, 1.670166f, 2.1064453f, 0.765625f, 0.767334f, 1.4802246f, 1.4580078f, 0.8364258f, 0.5427246f, -1.2788086f, -1.7922363f, -1.552002f, -1.4414062f, -0.9494629f, -1.151123f, -1.8183594f,
+ 0.35375977f, -0.44604492f, -1.1108398f, -1.5837402f, -1.3947754f, -0.6669922f, -0.16113281f, 0.10571289f, 0.3190918f, 0.5788574f, 0.6821289f, 0.7907715f, 0.7709961f, 0.59375f, 0.5800781f, 0.58813477f,
+ 1.2800293f, 2.3510742f, 2.9519043f, 2.9152832f, 2.5854492f, 1.7675781f, 1.0688477f, 0.4387207f, -0.19555664f, -1.513916f, -2.340332f, -2.5202637f, -2.3115234f, -2.1765137f, -2.1308594f, -2.1696777f,
+ -1.6928711f, -0.26049805f, 0.19189453f, -0.04711914f, 0.061279297f, 0.15258789f, 0.17089844f, 0.10205078f, 0.08691406f, 0.076660156f, 0.039794922f, 0.025878906f, 0.0014648438f, 0.265625f, 0.46240234f, 0.3630371f,
+ 1.4794922f, 0.9511719f, 0.1184082f, -0.7175293f, -1.15625f, -0.8388672f, 0.068847656f, 0.49609375f, 0.45629883f, -0.12768555f, -0.79907227f, -0.7434082f, -0.20336914f, -0.00390625f, 0.27514648f, 0.74438477f,
+ -1.628418f, -0.46142578f, 0.087402344f, -0.056152344f, 0.10913086f, 0.58813477f, 0.9543457f, 1.532959f, 1.3303223f, 0.35180664f, -0.21435547f, -0.49267578f, -0.5546875f, -0.34765625f, -0.4658203f, -0.7324219f,
+ 2.887207f, 4.0615234f, 3.1860352f, 1.532959f, 0.4165039f, 0.19067383f, 0.57055664f, -0.7878418f, -1.2619629f, -1.8005371f, -1.6381836f, -1.4213867f, -1.5876465f, -1.5568848f, -1.2424316f, -1.548584f,
+ 0.1184082f, 0.16186523f, 0.17089844f, 0.52856445f, 0.48364258f, 0.23583984f, 0.091796875f, 0.4477539f, 0.56103516f, 0.3972168f, 0.27197266f, 0.17138672f, -0.1850586f, -0.74194336f, -1.204834f, -1.5085449f,
+ 3.7294922f, 2.5002441f, 1.5256348f, 0.701416f, 0.19116211f, 0.07861328f, 0.24267578f, 0.4243164f, 0.23217773f, -0.4404297f, -1.0891113f, -1.3295898f, -1.3798828f, -1.6437988f, -1.8586426f, -1.8840332f,
+ -1.0793457f, -0.54956055f, -0.53271484f, -0.8959961f, -0.7878418f, -0.50390625f, -0.45898438f, -0.45410156f, -0.14868164f, 0.07495117f, 0.30126953f, 0.5197754f, 0.8623047f, 1.3652344f, 1.3466797f, 0.9406738f,
+ 0.8203125f, 1.934082f, 2.6530762f, 2.293457f, 1.5932617f, 0.25708008f, 0.46289062f, 0.7038574f, 0.39990234f, -1.3444824f, -1.871582f, -1.7602539f, -1.8720703f, -1.1584473f, -1.3552246f, -1.7556152f,
+ 0.6022949f, 1.5651855f, 2.024414f, 1.043457f, 0.5551758f, 0.29516602f, -0.059326172f, -0.29589844f, -0.28930664f, -0.6899414f, -0.87158203f, -0.8222656f, -0.8574219f, -0.74438477f, -0.65722656f, -0.7980957f,
+ 0.7392578f, 1.7915039f, 1.7841797f, 1.0437012f, 0.2434082f, -0.5f, -0.76123047f, -0.9995117f, -0.77856445f, -0.61450195f, -0.4025879f, -0.36132812f, -0.16894531f, 0.123046875f, -0.3190918f, -0.8190918f,
+ -3.3479004f, -2.8823242f, -1.7409668f, -0.01928711f, 1.5759277f, 1.565918f, -0.14379883f, -1.1428223f, -0.46923828f, 1.5456543f, 0.080566406f, 0.15551758f, 1.5246582f, 1.2470703f, 1.1359863f, 0.9152832f,
+ 3.6564941f, 2.3999023f, 1.4855957f, 0.71728516f, 0.45483398f, 0.25854492f, -0.13500977f, -0.5534668f, -0.7763672f, -1.0727539f, -1.2416992f, -1.2087402f, -1.0163574f, -1.0344238f, -0.97924805f, -0.9543457f,
+ -0.26391602f, 0.7937012f, 1.5644531f, 1.7453613f, 1.2094727f, 1.2302246f, 1.0932617f, 1.0627441f, 1.1040039f, 0.16601562f, -1.6494141f, -2.2905273f, -1.9121094f, -1.423584f, -0.94140625f, -1.487793f,
+ 1.7485352f, 1.9509277f, 1.1413574f, 0.23828125f, 0.20532227f, 0.71972656f, 1.0627441f, 0.84375f, 0.6599121f, 0.11010742f, -0.41723633f, -1.0415039f, -1.4494629f, -1.7270508f, -1.9189453f, -2.126709f,
+ 1.7670898f, -0.14770508f, -0.9782715f, 0.0007324219f, 2.0344238f, 0.28637695f, -0.53125f, -1.2973633f, -1.4816895f, -1.2402344f, -1.1208496f, -1.1516113f, -0.68237305f, -0.05883789f, 1.3154297f, 3.286377f,
+ 2.586914f, 3.0708008f, 3.369629f, 2.663086f, 1.8154297f, 0.54467773f, 0.5966797f, 0.45703125f, -0.5554199f, -1.7521973f, -2.234375f, -2.2390137f, -2.147461f, -2.0239258f, -2.0800781f, -2.0722656f,
+ -0.17993164f, 0.5961914f, 0.1184082f, -0.6855469f, -0.8725586f, -0.7883301f, -0.72094727f, -0.5744629f, -0.20922852f, 0.171875f, 0.41430664f, 0.54711914f, 0.49438477f, 0.564209f, 0.64819336f, 0.4765625f,
+ 2.9692383f, 1.6333008f, 0.5463867f, -0.6401367f, -1.1271973f, -1.4199219f, -1.4353027f, -1.2783203f, -1.0517578f, -0.7229004f, -0.4267578f, -0.39233398f, 0.44873047f, 0.67211914f, 0.89453125f, 1.3300781f,
+ -0.7512207f, 0.11035156f, 0.47998047f, -0.0949707f, -0.30981445f, 0.028808594f, 0.04272461f, 0.25756836f, 0.88378906f, 1.1179199f, 0.33569336f, -0.30126953f, -0.36132812f, -0.29223633f, -0.4194336f, -0.7260742f,
+ 3.871582f, 3.6723633f, 2.5690918f, 1.3596191f, 1.0322266f, 1.0532227f, 0.7524414f, 0.15966797f, -0.42114258f, -1.3811035f, -1.967041f, -2.2060547f, -2.1699219f, -2.125f, -2.0786133f, -2.121582f,
+ 0.41601562f, 0.4086914f, 0.12915039f, 0.44995117f, 1.0292969f, 1.5f, 1.4731445f, 1.0021973f, 0.53149414f, -0.10473633f, -0.49121094f, -0.6335449f, -1.0283203f, -1.3818359f, -1.5666504f, -1.7338867f,
+ 1.0354004f, 0.7351074f, -0.04321289f, -0.86328125f, -1.1411133f, -0.89990234f, -0.3876953f, 0.2421875f, 0.7763672f, 0.7036133f, 0.4814453f, 0.25952148f, 0.16503906f, -0.0925293f, -0.35668945f, -0.6142578f,
+ -2.5014648f, -2.2893066f, -2.4162598f, -2.5559082f, -2.2287598f, -1.3945312f, -0.8725586f, -0.30419922f, 0.30200195f, 1.078125f, 1.8603516f, 1.8320312f, 2.2028809f, 2.7680664f, 2.5114746f, 2.0083008f,
+ 1.4338379f, 2.6071777f, 2.8693848f, 1.9367676f, 1.357666f, 0.54052734f, 0.0073242188f, -0.39257812f, -0.7956543f, -1.501709f, -1.6374512f, -1.4631348f, -1.3227539f, -1.2058105f, -1.0966797f, -1.3371582f,
+ 0.41577148f, 0.41992188f, 0.01171875f, -0.041748047f, 0.022460938f, 0.24536133f, 0.36010742f, 0.3203125f, 0.16088867f, -0.055664062f, -0.23950195f, -0.4645996f, -0.37817383f, -0.17480469f, -0.19140625f, -0.4104004f,
+ 0.1303711f, 1.1894531f, 0.9506836f, -0.5930176f, -1.2092285f, -0.53027344f, 0.7734375f, 0.6401367f, 0.54956055f, 0.3388672f, -0.5241699f, -0.9995117f, -0.2709961f, 0.33789062f, -0.091552734f, -0.69140625f,
+ -2.5305176f, -1.4348145f, -0.14941406f, 0.8322754f, 1.2192383f, 1.2817383f, 0.94140625f, 0.5319824f, 0.37402344f, 0.31469727f, 0.23120117f, 0.010498047f, -0.21533203f, -0.3239746f, -0.45751953f, -0.6254883f,
+ 1.7978516f, 2.154541f, 1.6486816f, 0.77490234f, 0.38378906f, 0.24902344f, -0.34985352f, -0.9355469f, -1.130127f, -1.3525391f, -1.317627f, -1.0749512f, -0.7229004f, -0.31201172f, 0.06225586f, 0.12475586f,
+ 0.8828125f, 0.72802734f, 0.59594727f, 0.3737793f, 0.5258789f, 0.72753906f, 0.43017578f, 0.18725586f, 0.06640625f, -0.23266602f, -0.42578125f, -0.50512695f, -0.5432129f, -0.6281738f, -0.92529297f, -1.2570801f,
+ 1.46875f, 2.616455f, 2.7822266f, 1.1652832f, 0.45581055f, 1.2355957f, 1.2653809f, 0.935791f, 0.5776367f, -0.87597656f, -2.5498047f, -2.6628418f, -2.2028809f, -1.3466797f, -0.9621582f, -1.9025879f,
+ 1.5563965f, 0.4855957f, -0.31933594f, -0.8959961f, -1.0634766f, -1.0183105f, -0.9716797f, -0.8378906f, -0.4987793f, -0.14331055f, 0.14428711f, 0.31445312f, 0.6821289f, 0.88623047f, 0.87890625f, 0.8005371f,
+ 1.9968262f, 2.7993164f, 2.0898438f, 0.9248047f, 0.85009766f, 1.4089355f, 1.6706543f, 1.3681641f, 1.1982422f, 0.33544922f, -0.95288086f, -2.145996f, -2.8188477f, -2.941162f, -2.8947754f, -2.8886719f,
+ -0.75439453f, 0.16137695f, 0.33740234f, -0.19702148f, 0.5197754f, 1.2861328f, 0.42236328f, -0.20092773f, -0.11743164f, -0.69018555f, -1.1972656f, -0.7453613f, -0.053466797f, 0.39208984f, 0.7512207f, 0.08544922f,
+ 2.1848145f, 1.0153809f, 0.14331055f, -0.6489258f, -0.71435547f, -0.55566406f, -0.40966797f, -0.25634766f, -0.08081055f, -0.01586914f, -0.0053710938f, -0.09667969f, -0.12231445f, -0.03466797f, -0.11303711f, -0.2902832f,
+ -1.2324219f, -0.42993164f, -0.30273438f, -0.8486328f, -0.9147949f, -0.7001953f, 0.03955078f, 0.7734375f, 0.99438477f, 0.46484375f, 0.13891602f, 0.11425781f, 0.41381836f, 0.7363281f, 0.6113281f, 0.14208984f,
+ 3.2854004f, 4.0998535f, 3.8623047f, 2.496582f, 1.4880371f, -0.044189453f, -0.55981445f, -1.1950684f, -1.519043f, -1.6992188f, -1.7475586f, -1.7741699f, -1.7507324f, -1.697998f, -1.6628418f, -1.5812988f,
+ -0.28393555f, 0.36254883f, 0.7150879f, 1.1523438f, 1.5422363f, 1.6831055f, 0.8269043f, -0.0107421875f, -0.48364258f, -0.6828613f, -0.78930664f, -0.6608887f, -0.6298828f, -0.8183594f, -0.8984375f, -1.0241699f,
+ 2.4472656f, 3.3598633f, 2.1152344f, 0.58740234f, 0.088134766f, 0.080566406f, 0.12768555f, -0.83447266f, -0.66308594f, 0.3178711f, -0.046875f, -1.7287598f, -1.8405762f, -1.4956055f, -1.1696777f, -1.3449707f,
+ 0.053955078f, -0.54907227f, -0.64941406f, -0.40527344f, -0.1496582f, -0.067871094f, -0.1328125f, -0.15991211f, 0.044677734f, 0.25585938f, 0.31835938f, 0.16113281f, 0.25756836f, 0.36523438f, 0.30444336f, 0.3527832f,
+ 0.20654297f, 1.2531738f, 1.6928711f, 2.6262207f, 2.7858887f, 2.2766113f, 1.0957031f, 0.32495117f, -0.79711914f, -1.7229004f, -2.0270996f, -1.2214355f, -1.1369629f, -2.0170898f, -1.7719727f, -1.5671387f,
+ 2.3149414f, 2.991455f, 1.5952148f, -0.14819336f, -0.6477051f, -0.16430664f, 0.07470703f, -0.28759766f, -0.4309082f, -0.782959f, -0.9194336f, -0.9182129f, -0.76708984f, -0.43164062f, -0.51586914f, -0.96240234f,
+ -0.13427734f, 0.3479004f, 0.4909668f, 0.038330078f, -0.26342773f, -0.3449707f, -0.41430664f, -0.3930664f, -0.16748047f, 0.009521484f, 0.1977539f, 0.0703125f, 0.20703125f, 0.43969727f, 0.24658203f, -0.33032227f,
+ -2.4680176f, -2.8671875f, -1.8813477f, 0.0925293f, 2.0136719f, 1.6013184f, 0.009277344f, -0.20214844f, 0.53344727f, 1.6809082f, 0.20605469f, 0.18408203f, 1.1643066f, 0.7697754f, -0.21728516f, -0.6196289f,
+ 3.2966309f, 3.043457f, 1.8188477f, 0.35595703f, -0.5317383f, -1.1340332f, -1.4089355f, -1.5368652f, -1.5805664f, -1.4577637f, -1.1005859f, -0.7077637f, 0.3149414f, 0.13671875f, 0.09887695f, 0.39257812f,
+ 1.1394043f, 2.0166016f, 1.6103516f, 0.43041992f, 0.8642578f, 1.6750488f, 0.87231445f, -0.23657227f, -1.2756348f, -1.3154297f, -1.0163574f, -0.611084f, -0.8654785f, -0.96191406f, -0.888916f, -1.4370117f,
+ 1.2382812f, 2.4553223f, 2.6896973f, 1.0947266f, 0.8881836f, 0.6599121f, 0.5114746f, 0.54296875f, 0.5046387f, -0.7314453f, -1.0595703f, -1.0734863f, -1.7263184f, -1.8920898f, -1.9853516f, -2.1169434f,
+ 1.7275391f, 1.0910645f, 0.24316406f, -1.076416f, -1.8234863f, -2.0952148f, -1.9289551f, -1.7150879f, -1.1884766f, -0.40429688f, 0.6279297f, 1.0185547f, 1.0893555f, 1.3093262f, 1.5356445f, 1.5893555f,
+ 2.8112793f, 3.1445312f, 2.5549316f, 0.8642578f, 0.45751953f, 1.5227051f, 1.6352539f, 0.92749023f, -0.56347656f, -1.8974609f, -2.1052246f, -2.085205f, -1.9211426f, -1.7441406f, -1.8710938f, -1.7302246f,
+ 0.46118164f, 0.93188477f, 0.859375f, 0.25732422f, -0.083496094f, -0.11010742f, -0.5197754f, -0.7607422f, -0.90966797f, -1.2976074f, -1.0537109f, -0.685791f, 0.013183594f, 0.83984375f, 1.1577148f, 0.9003906f,
+ 3.130371f, 1.8466797f, 0.7558594f, -0.33569336f, -0.7277832f, -0.85498047f, -0.7219238f, -0.6804199f, -0.5666504f, -0.50097656f, -0.49169922f, -0.2824707f, -0.16015625f, -0.3659668f, -0.2529297f, 0.20898438f,
+ -1.7817383f, -0.7636719f, -0.35620117f, -0.9194336f, -0.89990234f, -0.30371094f, 0.16333008f, 0.53393555f, 1.2219238f, 1.6164551f, 1.0964355f, 0.36914062f, 0.19091797f, 0.19116211f, -0.06689453f, -0.2919922f,
+ 2.9470215f, 2.9702148f, 2.4978027f, 1.8425293f, 1.1940918f, 0.48754883f, 0.040771484f, -0.4560547f, -0.71777344f, -1.255127f, -1.7084961f, -1.8168945f, -1.6584473f, -1.5026855f, -1.380127f, -1.4846191f,
+ -0.42797852f, 0.39672852f, 1.0322266f, 0.8232422f, 0.57055664f, 0.99194336f, 1.0778809f, 0.47460938f, 0.11987305f, -0.65625f, -1.3706055f, -1.3859863f, -0.93652344f, -0.296875f, -0.060302734f, -0.35253906f,
+ 3.0546875f, 1.5651855f, 0.72753906f, 0.024658203f, -0.087646484f, -0.13623047f, -0.22338867f, -0.051513672f, -0.01977539f, -0.13867188f, -0.29052734f, -0.4897461f, -0.6779785f, -0.89501953f, -1.0483398f, -1.3132324f,
+ -2.329834f, -1.6538086f, -1.5170898f, -1.8430176f, -1.7233887f, -0.94091797f, -0.39746094f, 0.51293945f, 1.3725586f, 1.703125f, 1.6044922f, 1.3227539f, 1.2766113f, 1.1901855f, 0.91308594f, 0.5095215f,
+ 2.1574707f, 3.0603027f, 2.765625f, 1.7712402f, 0.6225586f, -0.6166992f, -1.060791f, -1.5693359f, -1.4384766f, -1.7651367f, -1.7729492f, -1.0949707f, -0.46020508f, -0.0690918f, -0.05444336f, -0.47509766f,
+ 2.2287598f, 2.074707f, 1.065918f, 0.068603516f, -0.88061523f, -1.3867188f, -1.3818359f, -1.2768555f, -0.8725586f, -0.45751953f, -0.083984375f, -0.022460938f, 0.36108398f, 0.47192383f, 0.12597656f, -0.03466797f,
+ 1.2832031f, 2.3029785f, 1.6501465f, -0.19360352f, -0.94384766f, -0.11206055f, 1.2709961f, 1.0712891f, 0.9008789f, -0.6833496f, -1.9458008f, -1.3894043f, -0.7553711f, -0.17016602f, -0.6489258f, -1.637207f,
+ -0.5410156f, -1.4377441f, -0.87109375f, 0.72143555f, 2.3781738f, 1.8154297f, 0.05834961f, -0.24487305f, 0.27124023f, 1.1665039f, -0.2692871f, -0.24609375f, 0.4802246f, -0.34033203f, -1.2138672f, -1.7270508f,
+ 2.6340332f, 1.8164062f, 0.6784668f, -0.16235352f, -0.64208984f, -0.7529297f, -0.32080078f, 0.12548828f, 0.14257812f, -0.51123047f, -1.1225586f, -1.2424316f, -0.41625977f, -0.21459961f, -0.12768555f, 0.115722656f,
+ 1.6694336f, 1.4055176f, 1.2404785f, 1.4047852f, 1.1928711f, 0.6352539f, 0.19091797f, 0.040527344f, -0.056884766f, -0.5456543f, -0.94018555f, -1.1928711f, -1.1975098f, -1.208252f, -1.2277832f, -1.4104004f,
+ 0.92211914f, 2.1171875f, 1.9343262f, 0.67529297f, 0.21362305f, 0.7409668f, 0.51538086f, 0.0625f, -0.16113281f, -0.91918945f, -1.6809082f, -1.9360352f, -1.3974609f, -0.3359375f, 0.015625f, -0.7668457f,
+ 0.25463867f, 0.27246094f, -0.6647949f, -1.6083984f, -1.6931152f, -1.6413574f, -1.2963867f, 0.03149414f, 1.244873f, 0.9958496f, 0.88183594f, 0.7229004f, 0.6281738f, 1.152832f, 0.7297363f, -0.010498047f,
+ 0.27026367f, 1.5710449f, 2.415039f, 2.5617676f, 2.4665527f, 2.0825195f, 1.2067871f, 1.4360352f, 1.3601074f, -0.64990234f, -2.3432617f, -2.7763672f, -2.7404785f, -2.4682617f, -2.0534668f, -2.338623f,
+ -1.222168f, -0.23828125f, 0.42578125f, 0.41064453f, 0.033203125f, -0.22485352f, -0.31201172f, -0.5358887f, -0.5847168f, -0.4008789f, 0.018066406f, 0.2524414f, 0.36035156f, 0.55249023f, 0.7241211f, 0.74121094f,
+ 1.2573242f, 1.1115723f, 0.8808594f, 0.30810547f, -0.3330078f, -0.22290039f, 0.3894043f, 0.5810547f, 0.515625f, -0.11450195f, -0.8071289f, -0.9470215f, -0.68603516f, -0.69140625f, -0.68188477f, -0.5600586f,
+ -0.8679199f, -0.78100586f, -0.484375f, -0.22045898f, 0.21899414f, 0.6074219f, 0.4650879f, 0.6303711f, 0.52783203f, 0.1328125f, 0.10913086f, 0.28027344f, 0.15795898f, -0.02734375f, -0.22827148f, -0.52075195f,
+ 4.7766113f, 4.218994f, 2.694336f, 1.4052734f, 0.46484375f, 0.12695312f, -0.52441406f, -1.1826172f, -1.3425293f, -1.4343262f, -1.5407715f, -1.5932617f, -1.5834961f, -1.5500488f, -1.4814453f, -1.4541016f,
+ -1.1142578f, 0.16772461f, 1.0881348f, 0.9880371f, 0.6081543f, 0.39868164f, 0.22387695f, 0.01953125f, 0.011230469f, 0.06982422f, -0.13208008f, -0.43896484f, -0.5744629f, -0.34423828f, -0.4321289f, -0.5390625f,
+ 2.583496f, 2.133545f, 1.5522461f, 1.1113281f, 1.237793f, 1.3144531f, 0.93115234f, 0.35742188f, -0.20263672f, -0.76342773f, -1.1687012f, -1.4487305f, -1.6181641f, -1.8156738f, -2.0007324f, -2.203125f,
+ -2.0124512f, -1.4799805f, -1.4538574f, -1.4958496f, -1.1079102f, -0.4272461f, -0.17285156f, 0.080322266f, 0.3112793f, 0.5344238f, 0.6477051f, 0.64208984f, 1.0615234f, 1.8166504f, 1.7543945f, 1.3015137f,
+ 0.86035156f, 1.9960938f, 2.592041f, 2.7302246f, 2.2209473f, 1.1103516f, 0.720459f, -0.033691406f, -0.48901367f, -1.1772461f, -2.2160645f, -2.621338f, -2.5187988f, -1.5297852f, -0.41210938f, -1.2324219f,
+ -0.0390625f, 0.7182617f, 1.293457f, 1.6416016f, 1.7243652f, 0.44335938f, -0.36767578f, -0.62646484f, -0.14038086f, -0.39379883f, -1.5004883f, -1.2729492f, -0.65112305f, -0.21801758f, -0.15991211f, -0.45117188f,
+ 0.4506836f, 1.1796875f, 1.0358887f, 0.4663086f, 0.12597656f, -0.20898438f, -0.2524414f, -0.18115234f, -0.17993164f, -0.23266602f, -0.12768555f, -0.010009766f, -0.23925781f, -0.46972656f, -0.58251953f, -0.7739258f,
+ -3.7177734f, -3.4355469f, -1.828125f, 0.23046875f, 1.5246582f, 1.4841309f, 0.20214844f, -0.1538086f, 0.41015625f, 1.4714355f, 0.095214844f, 0.12524414f, 1.3300781f, 1.3466797f, 0.51538086f, 0.40014648f,
+ 4.776123f, 2.9377441f, 1.6135254f, 0.27954102f, -0.32666016f, -0.5793457f, -0.78466797f, -0.77001953f, -0.76538086f, -0.8562012f, -0.86694336f, -0.8532715f, -0.77905273f, -0.9621582f, -1.0119629f, -1.0510254f,
+ -0.8840332f, -0.5324707f, 0.2368164f, 2.0664062f, 2.5444336f, 1.9240723f, 1.4997559f, 1.230957f, 0.736084f, 0.2121582f, -0.61987305f, -0.9506836f, -1.2260742f, -1.7910156f, -2.0410156f, -2.4060059f,
+ 1.1203613f, 2.241455f, 1.5061035f, 0.26416016f, 0.083496094f, 0.087646484f, 0.00390625f, 0.03100586f, 0.08154297f, -0.39648438f, -0.56689453f, -0.62158203f, -0.7219238f, -0.796875f, -0.9807129f, -1.3356934f,
+ 0.8803711f, -0.5605469f, -0.89404297f, -1.1616211f, -0.9255371f, -1.3374023f, -1.1962891f, -1.2824707f, -1.3156738f, -1.2546387f, -1.0393066f, -0.041015625f, 1.5158691f, 1.6071777f, 2.4050293f, 4.5998535f,
+ 2.1367188f, 3.0183105f, 2.89917f, 2.105713f, 1.6914062f, 1.2595215f, 1.072998f, 0.5095215f, 0.26293945f, -0.62719727f, -1.6728516f, -2.331543f, -2.5375977f, -2.6152344f, -2.5966797f, -2.5751953f,
+ 0.45410156f, 0.56274414f, -0.091552734f, -0.82177734f, -0.8930664f, -0.40722656f, 0.024902344f, 0.008056641f, -0.09692383f, -0.19360352f, -0.25634766f, -0.25048828f, 0.14941406f, 0.73461914f, 0.7668457f, 0.31030273f,
+ 0.8791504f, 1.3742676f, 0.6760254f, -0.22192383f, -0.8535156f, -1.0957031f, -1.0690918f, -1.1728516f, -0.9848633f, -0.6647949f, -0.11669922f, 0.06738281f, 0.6196289f, 1.0905762f, 0.9074707f, 0.5654297f,
+ -0.26635742f, -0.29956055f, -0.8881836f, -1.2294922f, -0.69311523f, 0.011230469f, 0.5498047f, 0.9824219f, 1.184082f, 1.0895996f, 0.5878906f, 0.06738281f, -0.08911133f, -0.05029297f, -0.27319336f, -0.68359375f,
+ 3.256836f, 3.5593262f, 2.2746582f, 1.1318359f, 0.3149414f, -0.02368164f, 0.27172852f, -0.19335938f, -0.48779297f, -0.9663086f, -0.9187012f, -1.0222168f, -1.512207f, -1.6816406f, -1.8964844f, -2.1069336f,
+ -0.057617188f, -0.45092773f, -0.9638672f, -0.72143555f, 0.20703125f, 1.4692383f, 1.921875f, 1.6833496f, 1.3933105f, 0.6699219f, 0.17333984f, -0.43798828f, -0.9772949f, -1.1477051f, -1.3552246f, -1.4057617f,
+};
+
+const float ivas_sns_cdbk_tcx10_stage2[ 32 * 16 ] =
+{
+ 0.30615234f, 0.48828125f, -0.02709961f, -0.47680664f, -0.5300293f, -0.25463867f, -0.13305664f, -0.14941406f, -0.14819336f, 0.08666992f, 0.28833008f, 0.27514648f, 0.099365234f, -0.017578125f, 0.033203125f, 0.15893555f,
+ 0.40942383f, -0.044189453f, -0.088378906f, 0.38720703f, 0.5151367f, 0.42236328f, 0.34960938f, 0.2680664f, 0.037597656f, -0.19970703f, -0.31054688f, -0.32617188f, -0.38452148f, -0.38085938f, -0.38598633f, -0.2692871f,
+ -0.16040039f, -0.37548828f, -0.41479492f, -0.1237793f, 0.25708008f, 0.29589844f, 0.045410156f, -0.04345703f, -0.11450195f, -0.2019043f, 0.032470703f, 0.5847168f, 1.074707f, 0.3178711f, -0.43847656f, -0.73535156f,
+ -0.72021484f, 0.0859375f, 0.36450195f, 0.07739258f, -0.03857422f, -0.020263672f, 0.2277832f, 0.23657227f, -0.061523438f, -0.6010742f, -0.5341797f, -0.014160156f, 0.3154297f, 0.35327148f, 0.27368164f, 0.05517578f,
+ 0.17041016f, -0.1340332f, -0.17480469f, -0.16430664f, -0.15039062f, -0.16210938f, 0.20776367f, 0.78881836f, 0.8288574f, 0.2783203f, -0.099609375f, -0.26513672f, -0.29541016f, -0.31860352f, -0.3034668f, -0.20629883f,
+ 0.66967773f, 0.6286621f, 0.5107422f, 0.36791992f, 0.0949707f, -0.26904297f, -0.43603516f, -0.5292969f, -0.50219727f, -0.28881836f, -0.08081055f, 0.07861328f, -0.040771484f, -0.15014648f, -0.076416016f, 0.022705078f,
+ -0.14648438f, -0.46923828f, -0.43554688f, -0.11254883f, 0.021728516f, -0.06274414f, -0.10620117f, -0.23876953f, -0.34277344f, -0.21069336f, 0.010009766f, 0.26293945f, 0.36938477f, 0.4560547f, 0.5004883f, 0.5041504f,
+ -0.6381836f, -0.37841797f, -0.12036133f, 0.46875f, 0.6027832f, 0.40478516f, 0.3227539f, 0.2175293f, 0.029296875f, 0.009521484f, 0.091552734f, 0.014160156f, -0.19921875f, -0.27270508f, -0.3071289f, -0.24560547f,
+ 1.0043945f, 0.034423828f, -0.36523438f, -0.1628418f, -0.17504883f, -0.16357422f, 0.01977539f, 0.041992188f, -0.092041016f, -0.12548828f, -0.1381836f, -0.15527344f, -0.13720703f, -0.041992188f, 0.11791992f, 0.33789062f,
+ -0.29882812f, -0.056640625f, 0.22631836f, 0.35375977f, 0.40576172f, 0.053466797f, -0.33154297f, -0.58374023f, -0.59887695f, -0.13867188f, 0.35302734f, 0.4267578f, 0.12548828f, -0.052490234f, 0.022949219f, 0.09301758f,
+ -0.62060547f, -0.6557617f, -0.3918457f, -0.23461914f, -0.10498047f, -0.024169922f, 0.10473633f, 0.2746582f, 0.33642578f, 0.2866211f, 0.2980957f, 0.35498047f, 0.22167969f, 0.06298828f, 0.0036621094f, 0.087890625f,
+ -0.24169922f, 0.39331055f, 0.45410156f, -0.013671875f, -0.028076172f, 0.032226562f, -0.03491211f, 0.13916016f, 0.57006836f, 0.30078125f, -0.028564453f, -0.08300781f, -0.23266602f, -0.25585938f, -0.40356445f, -0.56762695f,
+ -0.25463867f, 0.20141602f, 0.13623047f, 0.021972656f, 0.018798828f, 0.35424805f, 0.30541992f, -0.043945312f, -0.032226562f, 0.4873047f, 0.2692871f, -0.57910156f, -0.86279297f, -0.46435547f, 0.21459961f, 0.2277832f,
+ 0.10083008f, -0.0048828125f, 0.15429688f, 0.58935547f, 0.58325195f, 0.15014648f, -0.1394043f, -0.30566406f, -0.39794922f, -0.42016602f, -0.4350586f, -0.49121094f, -0.24169922f, 0.07788086f, 0.3359375f, 0.4440918f,
+ -0.8688965f, -0.12646484f, 0.37768555f, 0.3232422f, -0.09790039f, -0.3017578f, -0.11328125f, 0.06982422f, 0.10864258f, 0.10180664f, 0.019042969f, -0.020751953f, -0.025878906f, 0.01977539f, 0.15820312f, 0.37646484f,
+ 0.04272461f, 0.020996094f, 0.31860352f, 0.23291016f, -0.33081055f, -0.80322266f, -0.73657227f, -0.34106445f, 0.011962891f, 0.27807617f, 0.45922852f, 0.49145508f, 0.3022461f, 0.14160156f, -0.017333984f, -0.07055664f,
+ -0.33544922f, 0.075683594f, -0.29907227f, -0.7363281f, -0.6525879f, -0.17797852f, 0.36279297f, 0.41870117f, 0.25170898f, 0.10473633f, 0.030273438f, -0.11254883f, 0.026855469f, 0.3503418f, 0.42382812f, 0.26904297f,
+ 0.3544922f, 0.67529297f, 0.38671875f, 0.009521484f, -0.040771484f, 0.08984375f, 0.2446289f, 0.16455078f, -0.17333984f, -0.4404297f, -0.46533203f, -0.40039062f, -0.28222656f, -0.1875f, -0.036865234f, 0.10205078f,
+ 0.4255371f, 0.16113281f, -0.11669922f, -0.16040039f, -0.14379883f, -0.2055664f, -0.0769043f, -0.055419922f, -0.19677734f, -0.44921875f, -0.3100586f, 0.10839844f, 0.5698242f, 0.5554199f, 0.11328125f, -0.21850586f,
+ -0.2980957f, -0.51660156f, -0.51000977f, -0.23046875f, 0.24658203f, 0.49682617f, 0.44580078f, 0.4501953f, 0.15917969f, -0.25317383f, -0.34301758f, -0.25146484f, -0.045898438f, 0.07885742f, 0.19018555f, 0.38085938f,
+ 0.32836914f, 0.41186523f, 0.40966797f, 0.23071289f, -0.27294922f, -0.7373047f, -0.33129883f, 0.2084961f, 0.29248047f, 0.023925781f, -0.22290039f, -0.2241211f, -0.10595703f, -0.109375f, -0.049072266f, 0.14770508f,
+ -0.17578125f, 0.35791016f, 0.71240234f, 0.55444336f, 0.37963867f, 0.25317383f, 0.0007324219f, -0.17456055f, -0.19921875f, -0.18261719f, -0.1381836f, -0.13476562f, -0.2697754f, -0.36523438f, -0.3803711f, -0.23730469f,
+ 0.18774414f, -0.33813477f, -0.40356445f, -0.16430664f, -0.35253906f, -0.5744629f, -0.40454102f, 0.03930664f, 0.28295898f, 0.24194336f, 0.11450195f, -0.011962891f, 0.15576172f, 0.29174805f, 0.39453125f, 0.5402832f,
+ 0.22485352f, -0.44970703f, -0.048583984f, 0.5905762f, 0.5395508f, -0.08300781f, -0.50219727f, -0.24121094f, 0.2331543f, 0.15942383f, -0.044433594f, 0.043701172f, -0.01928711f, -0.19824219f, -0.17260742f, -0.03173828f,
+ 0.86157227f, 0.21875f, 0.039794922f, 0.023925781f, -0.0925293f, -0.16845703f, -0.11669922f, 0.080322266f, 0.061279297f, 0.123535156f, 0.23388672f, 0.23022461f, 0.0056152344f, -0.33666992f, -0.5786133f, -0.5854492f,
+ 0.5175781f, 0.14453125f, -0.21850586f, -0.46777344f, 0.28515625f, 0.9855957f, 0.04296875f, -0.60424805f, -0.40625f, 0.07104492f, -0.0793457f, -0.111083984f, 0.017333984f, 0.021728516f, -0.1381836f, -0.060791016f,
+ 0.48950195f, -0.4885254f, -0.7644043f, -0.43164062f, -0.08203125f, 0.11401367f, 0.2331543f, 0.1472168f, 0.03540039f, 0.18945312f, 0.30737305f, 0.25976562f, 0.095458984f, -0.0234375f, -0.07739258f, -0.00390625f,
+ -0.111816406f, 0.22485352f, 0.00048828125f, -0.32177734f, -0.1508789f, 0.43017578f, 0.7011719f, 0.35229492f, -0.12060547f, -0.23291016f, 0.15258789f, 0.19702148f, -0.064208984f, -0.21606445f, -0.3857422f, -0.4543457f,
+ -0.22290039f, -0.33740234f, 0.068359375f, 0.09277344f, 0.04638672f, 0.21899414f, -0.03564453f, 0.036621094f, 0.6125488f, 0.5058594f, -0.4128418f, -0.69140625f, -0.5534668f, 0.16235352f, 0.54418945f, -0.034179688f,
+ -0.013916016f, 0.41259766f, 0.28393555f, -0.13085938f, -0.35058594f, -0.3713379f, -0.2619629f, -0.2854004f, -0.36401367f, -0.41210938f, -0.30444336f, -0.16552734f, 0.076416016f, 0.40722656f, 0.72143555f, 0.75878906f,
+ -0.78149414f, 0.05517578f, 0.09863281f, -0.35083008f, -0.29174805f, 0.1352539f, 0.10620117f, -0.3515625f, -0.27514648f, 0.15917969f, 0.34326172f, 0.2626953f, 0.39916992f, 0.42089844f, 0.20947266f, -0.1394043f,
+ -0.20361328f, -0.21557617f, -0.16308594f, -0.041748047f, -0.111083984f, -0.057617188f, 0.0390625f, 0.013183594f, 0.17358398f, 0.74902344f, 0.9448242f, 0.4477539f, -0.09423828f, -0.32739258f, -0.50634766f, -0.6467285f,
+};
+
+const float ivas_sns_cdbk_tcx10_stage3[ 8 * 16 ] =
+{
+ 0.15209961f, -0.12768555f, 0.09375f, -0.083496094f, -0.25390625f, 0.12524414f, 0.2993164f, -0.09863281f, -0.34814453f, -0.2434082f, -0.11254883f, -0.060058594f, 0.032470703f, 0.15527344f, 0.23413086f, 0.2355957f,
+ -0.16235352f, -0.111083984f, -0.3173828f, -0.25634766f, 0.13842773f, 0.29858398f, 0.10498047f, 0.11743164f, 0.26611328f, 0.05444336f, -0.1459961f, -0.19238281f, 0.041748047f, 0.2097168f, 0.07421875f, -0.12011719f,
+ -0.05078125f, 0.14770508f, -0.1003418f, -0.32104492f, -0.17504883f, -0.18652344f, -0.27148438f, -0.07788086f, 0.0036621094f, -0.04296875f, 0.10131836f, 0.34985352f, 0.3083496f, 0.10107422f, 0.0769043f, 0.13696289f,
+ -0.19140625f, -0.030273438f, 0.22509766f, 0.079589844f, -0.27148438f, -0.19604492f, 0.27929688f, 0.3503418f, 0.10424805f, 0.0061035156f, 0.06542969f, 0.11669922f, 0.036865234f, -0.1303711f, -0.22705078f, -0.21655273f,
+ 0.26538086f, -0.20825195f, -0.25073242f, 0.119628906f, 0.27270508f, 0.17797852f, -0.0024414062f, -0.12768555f, -0.22802734f, 0.0075683594f, 0.2133789f, 0.19482422f, 0.045898438f, -0.1184082f, -0.17797852f, -0.18383789f,
+ 0.2565918f, 0.24658203f, 0.1015625f, -0.029296875f, -0.14355469f, -0.13989258f, -0.20751953f, -0.19677734f, 0.17504883f, 0.41601562f, 0.13085938f, -0.20532227f, -0.16235352f, 0.040771484f, -0.037353516f, -0.24511719f,
+ -0.0871582f, 0.022949219f, 0.00048828125f, 0.07397461f, 0.14379883f, 0.067871094f, 0.0036621094f, 0.1171875f, 0.087402344f, 0.0012207031f, -0.075927734f, -0.11352539f, -0.31420898f, -0.38916016f, -0.022949219f, 0.484375f,
+ -0.1821289f, 0.060058594f, 0.24780273f, 0.41674805f, 0.2890625f, -0.1472168f, -0.20581055f, -0.083984375f, -0.060302734f, -0.19921875f, -0.17651367f, -0.08984375f, 0.011230469f, 0.13110352f, 0.080078125f, -0.09106445f,
+};
+
+const float *const ivas_sns_cdbks_tcx10[SNS_MSVQ_NSTAGES_TCX10] = { ivas_sns_cdbk_tcx10_stage1, ivas_sns_cdbk_tcx10_stage2, ivas_sns_cdbk_tcx10_stage3};
+
+const int16_t ivas_sns_cdbks_side_tcx20_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 32 };
+const int16_t ivas_sns_cdbks_side_tcx20_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 5 };
+const int16_t ivas_sns_cdbks_side_tcx10_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 8 };
+const int16_t ivas_sns_cdbks_side_tcx10_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 3 };
+
+const float ivas_sns_cdbks_side_tcx20_stage1[ 32 * 16 ] =
+{
+ -0.11376953f, -0.06591797f, 0.041992188f, 0.044677734f, 0.17871094f, -0.02758789f, -0.32592773f, -0.21069336f, -0.049072266f, 0.0126953125f, 0.012939453f, 0.015136719f, 0.08203125f, 0.12670898f, 0.12695312f, 0.15112305f,
+ -0.017089844f, 0.09326172f, 0.2355957f, 0.2241211f, 0.107421875f, 0.05029297f, 0.039794922f, -0.0073242188f, -0.048339844f, -0.0871582f, -0.08520508f, -0.12060547f, -0.111572266f, -0.10620117f, -0.08911133f, -0.078125f,
+ -0.26635742f, 0.27368164f, 0.4543457f, 0.1821289f, 0.6513672f, 0.18066406f, 0.14575195f, -0.008056641f, 0.2631836f, -0.045898438f, -0.52001953f, -0.1628418f, 0.038330078f, -0.31811523f, -0.4321289f, -0.43603516f,
+ -0.044189453f, -0.10449219f, -0.091796875f, -0.10620117f, -0.09423828f, 0.09326172f, 0.2697754f, 0.16577148f, 0.06201172f, 0.010986328f, 0.021728516f, -0.023925781f, -0.036621094f, -0.03930664f, -0.04345703f, -0.03930664f,
+ 0.4099121f, 0.06323242f, -0.021972656f, -0.014404297f, -0.013916016f, -0.018554688f, -0.052246094f, -0.051757812f, -0.03173828f, -0.03491211f, -0.02758789f, -0.05859375f, -0.045410156f, -0.042236328f, -0.038085938f, -0.021484375f,
+ 0.0024414062f, 0.030761719f, 0.020263672f, 0.013671875f, -0.009033203f, 0.012939453f, 0.009521484f, -0.030273438f, -0.048339844f, -0.022216797f, 0.011962891f, -0.017333984f, -0.011474609f, -0.0007324219f, 0.011962891f, 0.025634766f,
+ 0.17358398f, 0.22387695f, 0.19702148f, -0.019042969f, -0.27514648f, -0.5378418f, -0.30688477f, -0.03540039f, 0.0007324219f, -0.049560547f, 0.07519531f, 0.052246094f, 0.12670898f, 0.16308594f, 0.12133789f, 0.09033203f,
+ -0.32006836f, -0.29125977f, -0.24731445f, -0.17797852f, -0.140625f, -0.10595703f, -0.12670898f, -0.10864258f, -0.08618164f, -0.07421875f, 0.030517578f, 0.15917969f, 0.24975586f, 0.31518555f, 0.40893555f, 0.5151367f,
+ -0.49658203f, -0.033691406f, 0.083740234f, 0.04272461f, 0.03466797f, 0.053955078f, 0.03466797f, 0.02368164f, 0.037597656f, 0.03173828f, 0.028320312f, 0.00024414062f, 0.028564453f, 0.030761719f, 0.044189453f, 0.055419922f,
+ -0.040527344f, 0.022460938f, 0.009765625f, 0.036865234f, 0.055664062f, 0.046875f, 0.032470703f, 0.08105469f, 0.095703125f, 0.04296875f, -0.0087890625f, -0.064697266f, -0.057373047f, -0.04711914f, -0.09765625f, -0.107666016f,
+ 0.27148438f, 0.3696289f, 0.39672852f, 0.38427734f, 0.30151367f, 0.21655273f, 0.15551758f, 0.12133789f, -0.008056641f, -0.12792969f, -0.22973633f, -0.39111328f, -0.4465332f, -0.46826172f, -0.35986328f, -0.18530273f,
+ -0.3166504f, -0.2758789f, -0.22290039f, -0.1850586f, -0.15771484f, -0.1184082f, -0.04638672f, 0.032470703f, 0.10961914f, 0.16821289f, 0.20336914f, 0.1665039f, 0.20019531f, 0.19970703f, 0.14233398f, 0.1003418f,
+ -0.028076172f, -0.02734375f, -0.06665039f, -0.099365234f, -0.10522461f, -0.10546875f, -0.056884766f, 0.017333984f, 0.061523438f, 0.07836914f, 0.087890625f, 0.051513672f, 0.05419922f, 0.051757812f, 0.04272461f, 0.043945312f,
+ -0.14404297f, -0.3088379f, -0.07885742f, 0.053222656f, 0.064208984f, 0.032226562f, 0.057617188f, 0.05810547f, 0.05126953f, 0.041748047f, 0.053955078f, 0.015136719f, 0.028808594f, 0.033691406f, 0.0234375f, 0.018554688f,
+ 0.49609375f, 0.45263672f, 0.2915039f, 0.15649414f, 0.052246094f, 0.017578125f, -0.050048828f, -0.06640625f, -0.10839844f, -0.15063477f, -0.17138672f, -0.20532227f, -0.18432617f, -0.17553711f, -0.19213867f, -0.16235352f,
+ -0.0056152344f, -0.030761719f, -0.092285156f, -0.1262207f, -0.15917969f, -0.12011719f, -0.1105957f, -0.13354492f, -0.12915039f, -0.09863281f, 0.017578125f, 0.12866211f, 0.21850586f, 0.24853516f, 0.1875f, 0.20532227f,
+ -0.011230469f, -0.061035156f, -0.032226562f, 0.18139648f, 0.068359375f, -0.13916016f, -0.1015625f, 0.0017089844f, -0.004638672f, 0.009765625f, 0.03149414f, -0.0068359375f, 0.0043945312f, 0.023925781f, 0.017333984f, 0.018066406f,
+ -0.045166016f, -0.05493164f, -0.04296875f, 0.053710938f, 0.2121582f, 0.25195312f, 0.08911133f, -0.034179688f, -0.049560547f, -0.06225586f, -0.061523438f, -0.07836914f, -0.052490234f, -0.044189453f, -0.046142578f, -0.03540039f,
+ 0.08129883f, 0.20532227f, 0.04296875f, 0.11010742f, 0.3720703f, 0.4272461f, 0.31884766f, 0.19335938f, 0.015625f, -0.17895508f, -0.20214844f, -0.38330078f, -0.2487793f, -0.20581055f, -0.24560547f, -0.30297852f,
+ -0.40112305f, -0.2043457f, -0.048828125f, 0.018798828f, -0.080322266f, 0.016113281f, 0.13427734f, 0.2734375f, 0.3503418f, 0.35766602f, 0.19165039f, -0.056884766f, -0.11645508f, -0.1574707f, -0.14990234f, -0.12719727f,
+ 0.2763672f, 0.27905273f, 0.2241211f, 0.035888672f, -0.10253906f, -0.061523438f, -0.08544922f, -0.19848633f, -0.25634766f, -0.22729492f, -0.20019531f, -0.12548828f, -0.0026855469f, 0.08178711f, 0.14819336f, 0.21411133f,
+ -0.11425781f, -0.068603516f, 0.2446289f, -0.0031738281f, -0.04321289f, -0.033203125f, 0.024414062f, -0.0036621094f, -0.022460938f, 0.0017089844f, 0.018554688f, -0.014892578f, -0.010253906f, 0.0021972656f, 0.0068359375f, 0.015380859f,
+ 0.080322266f, 0.23852539f, 0.16894531f, 0.029052734f, -0.043701172f, -0.10571289f, -0.07788086f, -0.037109375f, -0.0063476562f, -0.025878906f, -0.036865234f, -0.06347656f, -0.04321289f, -0.03173828f, -0.032470703f, -0.012451172f,
+ -0.072265625f, -0.17602539f, -0.29736328f, -0.35253906f, -0.34814453f, -0.25732422f, -0.2097168f, -0.1850586f, -0.11230469f, -0.052978516f, 0.09643555f, 0.3071289f, 0.3930664f, 0.56689453f, 0.40625f, 0.2939453f,
+ -0.24194336f, -0.11010742f, -0.05102539f, 0.03930664f, -0.061523438f, -0.018554688f, 0.010986328f, 0.04296875f, -0.21557617f, -0.01928711f, 0.009277344f, 0.048095703f, 0.26342773f, 0.36791992f, 0.13232422f, -0.19604492f,
+ 0.16210938f, 0.16381836f, 0.14404297f, 0.1081543f, 0.08959961f, 0.11450195f, 0.11743164f, 0.11645508f, 0.13110352f, 0.11303711f, 0.021240234f, -0.15844727f, -0.21166992f, -0.27368164f, -0.33813477f, -0.29956055f,
+ -0.14624023f, 0.068603516f, 0.24731445f, 0.38916016f, 0.31860352f, 0.27416992f, 0.19165039f, 0.13793945f, 0.06958008f, -0.018798828f, -0.1159668f, -0.2849121f, -0.3581543f, -0.3803711f, -0.25952148f, -0.1328125f,
+ -0.64819336f, -0.5800781f, -0.15527344f, -0.07104492f, -0.08300781f, 0.009765625f, 0.10620117f, 0.10571289f, 0.13989258f, 0.12988281f, 0.1743164f, 0.18408203f, 0.09375f, 0.12524414f, 0.20678711f, 0.26220703f,
+ 0.07836914f, 0.16430664f, -0.014404297f, -0.20898438f, -0.08984375f, 0.04296875f, 0.06713867f, 0.0075683594f, -0.037109375f, -0.029296875f, -0.020019531f, -0.03173828f, 0.0036621094f, 0.016113281f, 0.015380859f, 0.035888672f,
+ -0.02368164f, -0.14282227f, -0.36645508f, -0.11279297f, 0.042236328f, 0.14086914f, 0.041503906f, 0.009277344f, 0.039794922f, 0.055419922f, 0.061523438f, 0.040771484f, 0.056152344f, 0.064208984f, 0.052490234f, 0.041503906f,
+ 0.23120117f, 0.21533203f, 0.16748047f, 0.15649414f, 0.1262207f, 0.10498047f, 0.08691406f, 0.020019531f, -0.03466797f, -0.12841797f, -0.18579102f, -0.29492188f, -0.2705078f, -0.17236328f, -0.06933594f, 0.04736328f,
+ -0.19580078f, -0.14624023f, -0.11303711f, -0.055908203f, -0.052001953f, -0.009033203f, 0.022949219f, -0.0068359375f, -0.032470703f, 0.0017089844f, 0.045410156f, 0.025146484f, 0.039794922f, 0.07543945f, 0.1574707f, 0.24267578f,
+};
+
+const float ivas_sns_cdbks_side_tcx20_stage2[ 32 * 16 ] =
+{
+ -0.013916016f, 0.0007324219f, 0.017089844f, 0.005859375f, 0.056152344f, -0.08178711f, -0.2927246f, 0.00390625f, 0.140625f, 0.03881836f, 0.010498047f, 0.038330078f, 0.042236328f, 0.020751953f, 0.005859375f, 0.0075683594f,
+ -0.07104492f, -0.10253906f, 0.038085938f, 0.091552734f, 0.118896484f, 0.13476562f, 0.05078125f, -0.111328125f, -0.13842773f, -0.20727539f, -0.25732422f, -0.15063477f, 0.032470703f, 0.08129883f, 0.17578125f, 0.31469727f,
+ 0.0715332f, 0.029052734f, 0.01953125f, 0.008056641f, 0.0234375f, 0.020751953f, 0.032226562f, 0.021972656f, 0.03466797f, 0.017822266f, -0.037841797f, -0.14038086f, -0.21679688f, -0.11035156f, 0.057617188f, 0.16845703f,
+ -0.1081543f, -0.02734375f, -0.08251953f, -0.08227539f, -0.07910156f, 0.049804688f, 0.10253906f, 0.23876953f, 0.25683594f, 0.03173828f, -0.15820312f, -0.14648438f, -0.008056641f, -0.00048828125f, -0.014404297f, 0.02734375f,
+ -0.022705078f, 0.028076172f, 0.14111328f, -0.06762695f, -0.07348633f, 0.16259766f, -0.0073242188f, -0.06567383f, -0.028564453f, -0.0107421875f, -0.023925781f, 0.0126953125f, -0.005859375f, -0.006591797f, -0.014160156f, -0.018066406f,
+ -0.09741211f, -0.092041016f, -0.061523438f, -0.011962891f, 0.006591797f, 0.041748047f, 0.008300781f, -0.017578125f, -0.08520508f, -0.12573242f, -0.06298828f, 0.13696289f, 0.25195312f, 0.15332031f, 0.001953125f, -0.04663086f,
+ -0.20239258f, 0.2705078f, 0.059326172f, 0.0041503906f, 0.022216797f, -0.009765625f, -0.026611328f, -0.02734375f, -0.032714844f, -0.016845703f, -0.025878906f, -0.0014648438f, -0.0075683594f, -0.009521484f, 0.004638672f, -0.0009765625f,
+ 0.064453125f, -0.26708984f, 0.122802734f, 0.025634766f, -0.0063476562f, 0.0043945312f, 0.008544922f, -0.0017089844f, 0.0061035156f, -0.007080078f, -0.018798828f, 0.011962891f, 0.008544922f, 0.010009766f, 0.020263672f, 0.018310547f,
+ -0.0007324219f, -0.037597656f, -0.036376953f, -0.015625f, 0.0056152344f, -0.0056152344f, -0.0029296875f, 0.032714844f, 0.047607422f, 0.019042969f, -0.010498047f, 0.017578125f, 0.0126953125f, 0.0043945312f, -0.013427734f, -0.016845703f,
+ 0.06933594f, 0.052978516f, 0.061035156f, 0.13378906f, 0.13427734f, 0.0053710938f, -0.099365234f, -0.18334961f, -0.21850586f, -0.083496094f, 0.020263672f, 0.05883789f, 0.013427734f, 0.011474609f, 0.01953125f, 0.0041503906f,
+ 0.0036621094f, -0.05053711f, -0.005126953f, 0.19091797f, -0.18798828f, -0.0546875f, 0.00048828125f, -0.021728516f, -0.001953125f, 0.0017089844f, 0.0041503906f, 0.024902344f, 0.022216797f, 0.02758789f, 0.02709961f, 0.01928711f,
+ 0.024658203f, -0.0041503906f, -0.026611328f, -0.0859375f, -0.06323242f, -0.068603516f, -0.07495117f, -0.050048828f, -0.061035156f, -0.0061035156f, 0.056396484f, 0.088378906f, 0.05883789f, 0.06738281f, 0.07763672f, 0.06738281f,
+ 0.13696289f, 0.08496094f, 0.07104492f, 0.046875f, 0.024658203f, 0.0048828125f, -0.0107421875f, -0.006591797f, 0.014160156f, -0.0073242188f, -0.041503906f, -0.02709961f, -0.041503906f, -0.060791016f, -0.09277344f, -0.095214844f,
+ -0.16772461f, 0.06665039f, 0.1821289f, 0.07397461f, -0.020019531f, 0.055419922f, 0.0390625f, -0.12011719f, -0.107910156f, 0.123291016f, 0.37939453f, 0.032714844f, -0.16137695f, -0.15234375f, -0.10546875f, -0.11743164f,
+ -0.013183594f, -0.011230469f, -0.037353516f, 0.0026855469f, -0.04638672f, -0.24438477f, 0.099853516f, 0.1105957f, 0.008544922f, 0.010253906f, 0.013183594f, 0.03857422f, 0.016601562f, 0.014892578f, 0.01928711f, 0.018066406f,
+ 0.044189453f, 0.07763672f, -0.03491211f, -0.18359375f, 0.15722656f, 0.061279297f, -0.029541016f, -0.018798828f, -0.023925781f, 0.0007324219f, -0.010498047f, 0.0087890625f, -0.0056152344f, -0.009277344f, -0.014892578f, -0.018798828f,
+ 0.13696289f, 0.011230469f, -0.033447266f, -0.017333984f, -0.07763672f, -0.122558594f, -0.076416016f, -0.017333984f, 0.14257812f, 0.21313477f, 0.14575195f, 0.032226562f, -0.083740234f, -0.12036133f, -0.076171875f, -0.057373047f,
+ 0.029541016f, -0.12231445f, -0.2475586f, 0.0949707f, 0.18896484f, 0.026123047f, 0.012939453f, 0.030029297f, 0.009033203f, -0.009277344f, -0.025634766f, 0.0087890625f, -0.0024414062f, -0.0017089844f, 0.0087890625f, -0.00024414062f,
+ -0.03857422f, -0.03881836f, -0.08886719f, -0.068847656f, 0.022216797f, 0.10229492f, 0.12841797f, 0.083984375f, 0.06567383f, 0.08178711f, 0.075927734f, 0.040039062f, -0.047851562f, -0.09448242f, -0.103515625f, -0.119140625f,
+ 0.009277344f, 0.046875f, 0.08178711f, 0.037597656f, 0.0063476562f, -0.038330078f, -0.01171875f, 0.28222656f, 0.027832031f, -0.25195312f, -0.12817383f, 0.01586914f, 0.011474609f, -0.014404297f, -0.044189453f, -0.030761719f,
+ 0.0637207f, 0.12426758f, 0.095458984f, -0.13378906f, -0.26293945f, -0.06323242f, 0.033203125f, 0.06591797f, 0.048583984f, 0.026367188f, 0.005859375f, 0.01977539f, -0.0029296875f, -0.005859375f, -0.0007324219f, -0.013183594f,
+ -0.016845703f, -0.052246094f, -0.057373047f, 0.008056641f, -0.01171875f, -0.068847656f, -0.0859375f, -0.016357422f, -0.012207031f, 0.046875f, 0.18164062f, 0.2692871f, 0.13476562f, -0.024414062f, -0.1274414f, -0.16723633f,
+ -0.021972656f, -0.053955078f, -0.022705078f, -0.00048828125f, 0.072021484f, 0.083496094f, 0.056640625f, -0.014892578f, 0.028320312f, 0.09399414f, 0.061279297f, -0.48779297f, -0.018554688f, 0.1550293f, 0.05859375f, 0.0107421875f,
+ 0.38476562f, -0.049316406f, -0.0793457f, -0.025146484f, -0.02319336f, -0.020751953f, 0.026855469f, -0.00048828125f, -0.052490234f, -0.033935547f, -0.04638672f, -0.0107421875f, -0.018066406f, -0.022216797f, -0.016113281f, -0.013427734f,
+ -0.23852539f, -0.064941406f, -0.018066406f, -0.0034179688f, 0.040283203f, 0.01928711f, 0.018310547f, 0.030761719f, 0.030029297f, 0.028564453f, 0.010253906f, 0.037109375f, 0.021484375f, 0.03491211f, 0.03515625f, 0.018798828f,
+ 0.03857422f, 0.028808594f, 0.025878906f, 0.04321289f, 0.03491211f, -0.021972656f, -0.03466797f, -0.01953125f, -0.02368164f, -0.095214844f, -0.13891602f, -0.032714844f, 0.013671875f, 0.05883789f, 0.064697266f, 0.057861328f,
+ -0.014892578f, 0.014892578f, 0.0126953125f, 0.045410156f, 0.0073242188f, 0.08300781f, 0.17797852f, 0.030761719f, -0.11743164f, -0.071777344f, -0.048095703f, -0.007080078f, -0.016113281f, -0.024414062f, -0.033203125f, -0.03881836f,
+ 0.0690918f, -0.049072266f, -0.23413086f, -0.3227539f, -0.15258789f, -0.028320312f, 0.05883789f, 0.055908203f, 0.08618164f, 0.08203125f, 0.052246094f, 0.0546875f, 0.022216797f, 0.07885742f, 0.13061523f, 0.095947266f,
+ -0.13452148f, -0.026855469f, 0.107177734f, 0.16040039f, 0.13305664f, 0.043701172f, 0.0087890625f, 0.020019531f, 0.040039062f, 0.017578125f, -0.030029297f, -0.024902344f, -0.067871094f, -0.08666992f, -0.076416016f, -0.083740234f,
+ -0.01953125f, -0.059814453f, -0.061279297f, 0.008056641f, 0.031982422f, 0.08203125f, -0.045166016f, -0.25561523f, -0.02758789f, 0.10522461f, 0.06274414f, 0.046875f, 0.029052734f, 0.03173828f, 0.04248047f, 0.028564453f,
+ -0.050048828f, 0.084472656f, 0.27172852f, 0.053222656f, -0.063964844f, -0.12988281f, -0.07299805f, -0.051757812f, -0.036621094f, -0.0014648438f, -0.0009765625f, 0.021728516f, 0.009033203f, -0.0007324219f, -0.013183594f, -0.018554688f,
+ 0.0847168f, 0.18920898f, -0.1796875f, -0.01586914f, -0.017822266f, -0.021728516f, 0.006591797f, -0.0075683594f, -0.019042969f, -0.0107421875f, -0.0146484375f, 0.014160156f, 0.0034179688f, -0.0056152344f, -0.0036621094f, -0.0017089844f,
+};
+
+const float *const ivas_sns_cdbks_side_tcx20[SNS_MSVQ_NSTAGES_SIDE] = { ivas_sns_cdbks_side_tcx20_stage1, ivas_sns_cdbks_side_tcx20_stage2 };
+
+const float ivas_sns_cdbks_side_tcx10_stage1[ 32 * 16 ] =
+{
+ -0.23950195f, -0.203125f, -0.17822266f, -0.1315918f, -0.123291016f, -0.095947266f, -0.106933594f, -0.16552734f, -0.14941406f, -0.075683594f, 0.026367188f, 0.1015625f, 0.17041016f, 0.2770996f, 0.37890625f, 0.5148926f,
+ 0.12890625f, 0.20825195f, 0.22924805f, 0.2998047f, 0.24267578f, 0.14477539f, 0.07861328f, 0.024658203f, -0.076171875f, -0.18432617f, -0.26660156f, -0.33251953f, -0.2758789f, -0.13964844f, -0.030517578f, -0.05126953f,
+ -0.14160156f, -0.13305664f, -0.111816406f, -0.037353516f, -0.038085938f, 0.051513672f, 0.07348633f, 0.0073242188f, 0.044921875f, -0.0234375f, -0.123291016f, -0.01171875f, 0.28100586f, 0.24194336f, 0.0703125f, -0.1496582f,
+ 0.053466797f, 0.122802734f, 0.1394043f, 0.099853516f, 0.078125f, 0.018554688f, 0.034423828f, 0.103759766f, 0.06542969f, -0.030273438f, -0.09887695f, -0.099609375f, -0.060058594f, -0.119628906f, -0.18237305f, -0.12451172f,
+ -0.04345703f, -0.033447266f, -0.06665039f, -0.06518555f, -0.048828125f, -0.11645508f, -0.2055664f, -0.20263672f, -0.15576172f, -0.0009765625f, 0.103759766f, 0.21191406f, 0.24414062f, 0.14526367f, 0.09863281f, 0.13476562f,
+ 0.05810547f, 0.22558594f, 0.10180664f, -0.08618164f, -0.07470703f, 0.052246094f, 0.052490234f, -0.042236328f, -0.07055664f, -0.037109375f, -0.024169922f, -0.03149414f, -0.031982422f, -0.040527344f, -0.038085938f, -0.013183594f,
+ 0.020019531f, -0.033447266f, -0.14550781f, -0.42089844f, -0.19604492f, 0.038085938f, 0.026611328f, 0.016357422f, 0.038330078f, 0.057861328f, 0.06762695f, 0.08081055f, 0.091308594f, 0.10180664f, 0.11987305f, 0.13720703f,
+ 0.13671875f, 0.30566406f, 0.4716797f, 0.54785156f, 0.39819336f, 0.27075195f, 0.17602539f, 0.092041016f, -0.013183594f, -0.17163086f, -0.3166504f, -0.42138672f, -0.53271484f, -0.45898438f, -0.27416992f, -0.21044922f,
+ -0.38989258f, -0.37597656f, -0.3696289f, -0.2915039f, -0.26098633f, -0.19921875f, -0.15136719f, -0.09057617f, -0.040771484f, 0.13354492f, 0.30126953f, 0.3857422f, 0.40649414f, 0.31103516f, 0.30004883f, 0.3317871f,
+ 0.35107422f, 0.5229492f, 0.41870117f, 0.14355469f, -0.037597656f, -0.13134766f, -0.18383789f, -0.18066406f, -0.15771484f, -0.17480469f, -0.17041016f, -0.15209961f, -0.08251953f, -0.06616211f, -0.064453125f, -0.03466797f,
+ -0.66845703f, -0.31030273f, -0.21435547f, -0.11987305f, -0.103271484f, 0.080322266f, 0.21801758f, 0.20874023f, 0.1015625f, 0.032958984f, -0.043945312f, 0.078125f, 0.07324219f, 0.07763672f, 0.20727539f, 0.38208008f,
+ -0.17163086f, -0.1171875f, -0.03491211f, 0.060302734f, 0.1809082f, 0.33666992f, 0.3955078f, 0.27172852f, 0.12841797f, -0.036865234f, -0.17163086f, -0.21289062f, -0.20800781f, -0.17333984f, -0.125f, -0.12231445f,
+ -0.1875f, -0.3996582f, -0.017822266f, 0.10058594f, 0.057617188f, 0.028320312f, 0.05493164f, 0.04272461f, 0.041503906f, 0.046875f, 0.041748047f, 0.0546875f, 0.06201172f, 0.03149414f, 0.013427734f, 0.028564453f,
+ 0.34814453f, 0.234375f, -0.05493164f, -0.1821289f, -0.2878418f, -0.31176758f, -0.28100586f, -0.19824219f, -0.15673828f, -0.08251953f, 0.030273438f, 0.13647461f, 0.2211914f, 0.20776367f, 0.16455078f, 0.21240234f,
+ -0.057861328f, -0.10571289f, 0.08984375f, 0.30444336f, 0.18945312f, 0.14770508f, 0.09082031f, -0.020996094f, -0.053466797f, -0.044433594f, -0.07128906f, -0.08886719f, -0.079833984f, -0.0859375f, -0.09790039f, -0.1159668f,
+ 0.17626953f, 0.26049805f, 0.2175293f, 0.21020508f, 0.20141602f, 0.27734375f, 0.21606445f, -0.0012207031f, -0.010986328f, -0.11694336f, -0.2331543f, -0.15844727f, -0.08081055f, -0.08886719f, -0.35717773f, -0.5114746f,
+ -0.38134766f, -0.4855957f, -0.35986328f, -0.16137695f, -0.026123047f, 0.009033203f, -0.0126953125f, 0.040283203f, 0.095458984f, 0.15454102f, 0.16333008f, 0.19140625f, 0.21142578f, 0.203125f, 0.17993164f, 0.1784668f,
+ 0.05834961f, 0.06298828f, 0.041015625f, 0.031982422f, 0.07910156f, 0.06713867f, -0.028808594f, -0.05053711f, -0.024902344f, -0.17822266f, -0.3227539f, -0.1665039f, -0.0053710938f, 0.05517578f, 0.119384766f, 0.26123047f,
+ 0.047851562f, -0.042236328f, -0.24145508f, -0.038330078f, 0.052734375f, 0.068603516f, 0.05810547f, 0.011962891f, -0.013916016f, -0.010986328f, 0.020019531f, 0.02758789f, 0.03100586f, 0.02319336f, 0.014160156f, -0.008056641f,
+ -0.0036621094f, 0.0014648438f, 0.013671875f, 0.0f, 0.021240234f, 0.033447266f, 0.014892578f, 0.004638672f, 0.056884766f, 0.13427734f, 0.08691406f, -0.005126953f, -0.072753906f, -0.095214844f, -0.10961914f, -0.08105469f,
+ -0.15966797f, -0.110839844f, -0.13012695f, -0.071777344f, -0.064941406f, -0.056396484f, -0.046142578f, -0.012207031f, 0.048583984f, 0.036865234f, -0.00048828125f, -0.024414062f, -0.012939453f, 0.092041016f, 0.21435547f, 0.29858398f,
+ 0.55981445f, 0.15820312f, -0.012451172f, -0.04321289f, -0.05810547f, -0.014892578f, -0.021484375f, -0.038330078f, -0.033691406f, -0.037597656f, -0.0690918f, -0.076416016f, -0.0637207f, -0.064697266f, -0.0847168f, -0.099853516f,
+ -0.039794922f, -0.032714844f, -0.030273438f, -0.051513672f, -0.03564453f, -0.041015625f, -0.0390625f, 0.017822266f, 0.051513672f, 0.013916016f, -0.044677734f, -0.061035156f, -0.012207031f, 0.07299805f, 0.123291016f, 0.10888672f,
+ 0.45117188f, 0.46704102f, 0.38916016f, 0.23242188f, 0.16430664f, 0.1809082f, 0.20922852f, 0.033935547f, -0.13720703f, -0.2758789f, -0.39941406f, -0.3840332f, -0.31054688f, -0.28466797f, -0.28955078f, -0.04663086f,
+ -0.088134766f, -0.22973633f, -0.4194336f, -0.49487305f, -0.4038086f, -0.27734375f, -0.2253418f, -0.1315918f, -0.044677734f, 0.12036133f, 0.24951172f, 0.31103516f, 0.52124023f, 0.484375f, 0.32739258f, 0.30126953f,
+ 0.33203125f, 0.29614258f, 0.1796875f, 0.06689453f, 0.100097656f, 0.13867188f, 0.03491211f, -0.032714844f, -0.12060547f, -0.2097168f, -0.29638672f, -0.20898438f, -0.08227539f, -0.16821289f, -0.16015625f, 0.13134766f,
+ -0.44189453f, 0.017578125f, 0.07397461f, 0.033447266f, 0.044189453f, 0.04711914f, 0.030273438f, 0.040771484f, 0.041015625f, 0.022949219f, 0.004638672f, 0.018798828f, 0.028564453f, 0.018798828f, -0.00048828125f, 0.020751953f,
+ -0.36621094f, -0.23388672f, -0.08178711f, -0.015136719f, -0.049072266f, 0.07910156f, 0.23120117f, 0.28320312f, 0.38378906f, 0.29223633f, 0.099365234f, -0.0087890625f, -0.09814453f, -0.16455078f, -0.18945312f, -0.16186523f,
+ -0.17041016f, -0.18359375f, -0.19018555f, -0.15820312f, -0.20239258f, -0.21875f, -0.13110352f, 0.010009766f, 0.12011719f, 0.25097656f, 0.25024414f, 0.2055664f, 0.14526367f, 0.13964844f, 0.103759766f, 0.029052734f,
+ 0.06982422f, 0.072265625f, 0.18261719f, 0.025390625f, -0.2475586f, -0.2861328f, -0.111572266f, -0.037109375f, 0.0036621094f, 0.031982422f, 0.043945312f, 0.057373047f, 0.078125f, 0.072021484f, 0.028564453f, 0.016357422f,
+ 0.07836914f, 0.13549805f, 0.1743164f, 0.15478516f, 0.12573242f, -0.009521484f, -0.1508789f, -0.1965332f, -0.19604492f, -0.103027344f, -0.045898438f, -0.026123047f, 0.020263672f, 0.023925781f, 0.013183594f, 0.0014648438f,
+ 0.25341797f, 0.22558594f, 0.2241211f, 0.17114258f, 0.18164062f, 0.16894531f, 0.16503906f, 0.20239258f, 0.17041016f, 0.025878906f, -0.16625977f, -0.24121094f, -0.31982422f, -0.4008789f, -0.38256836f, -0.27783203f,
+}
+;
+
+const float ivas_sns_cdbks_side_tcx10_stage2[ 8 * 16 ] =
+{
+ -0.13989258f, -0.024658203f, 0.12670898f, 0.027832031f, 0.06689453f, 0.12817383f, 0.07495117f, -0.01977539f, -0.05834961f, -0.07543945f, -0.06542969f, -0.0546875f, -0.04345703f, -0.0063476562f, 0.034179688f, 0.029541016f,
+ -0.06713867f, -0.11450195f, -0.09790039f, -0.091308594f, -0.12182617f, -0.010009766f, 0.10986328f, 0.115478516f, 0.060058594f, 0.038085938f, 0.020507812f, 0.017333984f, 0.024169922f, 0.028320312f, 0.038330078f, 0.05053711f,
+ 0.05517578f, 0.030517578f, 0.0390625f, 0.05810547f, 0.021484375f, 0.032470703f, 0.040039062f, -0.0087890625f, -0.055908203f, -0.023925781f, 0.037109375f, 0.06347656f, 0.02709961f, -0.07373047f, -0.1274414f, -0.115234375f,
+ 0.11206055f, 0.2006836f, 0.045410156f, -0.10839844f, -0.1418457f, -0.08520508f, -0.032470703f, 0.033935547f, 0.044189453f, 0.006591797f, -0.012451172f, -0.018554688f, -0.013427734f, -0.010498047f, -0.0078125f, -0.012207031f,
+ -0.041748047f, -0.07373047f, -0.14819336f, 0.021240234f, 0.16015625f, 0.119140625f, 0.055908203f, 0.08081055f, 0.12548828f, 0.05419922f, -0.030761719f, -0.040771484f, -0.060302734f, -0.07128906f, -0.07763672f, -0.072509766f,
+ -0.07446289f, -0.041259766f, -0.040527344f, -0.068603516f, -0.042236328f, -0.03857422f, -0.05126953f, -0.08886719f, -0.055419922f, 0.036865234f, 0.09033203f, 0.06689453f, 0.08911133f, 0.13110352f, 0.08129883f, 0.0053710938f,
+ -0.052978516f, 0.033691406f, 0.16015625f, 0.171875f, 0.024658203f, -0.1328125f, -0.1394043f, -0.041992188f, 0.0068359375f, 0.020263672f, 0.008544922f, 0.0014648438f, -0.011474609f, -0.030273438f, -0.022460938f, 0.00390625f,
+ 0.20898438f, -0.011230469f, -0.08496094f, -0.010986328f, 0.032958984f, -0.013183594f, -0.057861328f, -0.07104492f, -0.06689453f, -0.056396484f, -0.047851562f, -0.03491211f, -0.011962891f, 0.032714844f, 0.08178711f, 0.11035156f,
+};
+
+const float *const ivas_sns_cdbks_side_tcx10[SNS_MSVQ_NSTAGES_SIDE] = { ivas_sns_cdbks_side_tcx10_stage1, ivas_sns_cdbks_side_tcx10_stage2 };
+
+const int16_t sns_1st_cdbk[2][2][8 * 32] =
+{
+ { /* split 1 */
+ { /* TCX 20 */
+ -10900, -11064, -10637, -10471, -9051, -6381, -4688, -2438,
+ -2119, -5087, -6702, -8118, -7586, -6343, -4828, -3406,
+ 2004, -3443, -4289, -3757, -3234, -2952, -2313, -1781,
+ 1749, 5598, 3916, 732, -1472, -2964, -3275, -2332,
+ -11978, -14369, -5600, -545, 981, -929, -57, 1903,
+ 1745, 391, 202, 115, 256, -291, -862, -1637,
+ -4052, 2059, 4709, 6768, 5595, 1975, -1723, -1218,
+ 2093, 7263, 8679, 7576, 3701, -2438, -4389, -2686,
+ -7120, -6279, -5715, -5520, -4752, -3125, -1856, -438,
+ 8131, -2543, -6285, -6723, -5588, -4321, -3264, -2164,
+ -653, -1301, -660, 608, 1598, 1805, 1698, 760,
+ 4882, 9309, 6333, 1734, 284, 364, 560, 1015,
+ -7686, -5737, -3443, -1642, 245, 1531, 1827, 1769,
+ -1468, 3782, 144, -5130, -6883, -5165, -1497, 2072,
+ -12937, -8429, -2619, 2894, 5004, 4710, 4627, 3740,
+ 3198, 3928, 4358, 4554, 3887, 2844, 1299, 129,
+ -13828, -12296, -9364, -7918, -5571, -1909, 307, 2047,
+ -4314, -1211, -559, -1061, -1928, -2228, -2359, -1902,
+ -309, -3224, -3404, -1895, -743, -59, 757, 908,
+ 10914, 5865, 1599, -386, -1392, -2285, -2236, -2042,
+ -11825, -16241, -11402, -3627, 6556, 8953, 6421, 1546,
+ 6102, 777, -301, 536, 902, 541, 210, -429,
+ -3052, 3997, 5389, 1842, -344, 1556, 2667, 2428,
+ 11788, 10894, 7448, 5423, 2372, -677, -2385, -3839,
+ -45, -7602, -8923, -7179, -3273, 65, 4500, 6726,
+ 5895, 626, -1610, -2598, -3240, -3540, -2930, -2156,
+ -971, 461, 1494, 4907, 5859, 5199, 3678, 2502,
+ 10766, 5297, 1844, 1236, 2498, 3503, 2846, 838,
+ -7816, -1212, 891, 2387, 1317, 2225, 1859, 1602,
+ 2376, 5357, 2088, -2719, -3419, -420, 2431, 2943,
+ -8383, -795, 4351, 7026, 7460, 7191, 5262, 3796,
+ 1522, 6283, 8714, 8222, 7434, 5768, 3586, 1499,
+ },
+ { /* TCX 10 */
+ -15596, -16321, -10264, -1002, 5955, 5543, -29, -1688,
+ 17, -3794, -6207, -7356, -6998, -6081, -4453, -2448,
+ -12543, -11530, -10186, -8817, -7083, -4440, -1946, 892,
+ 5198, 2751, -274, -2574, -4561, -6087, -5944, -4600,
+ -683, -2640, -2753, -1195, -239, -217, -286, 90,
+ -1400, -1146, -1853, -2845, -3456, -3788, -3171, -1969,
+ -1835, 392, 1725, 1209, -392, -1640, -2001, -1608,
+ 5770, 7707, 5210, 2112, -382, -2088, -2634, -3007,
+ -10766, -8101, -5137, -3754, -1881, 331, 2339, 3679,
+ -2637, -4640, -5811, -5651, -3790, -1359, 913, 1893,
+ -7793, -4768, -1762, -545, -717, -837, -441, -75,
+ 4030, 1770, 467, 379, 10, -1330, -2398, -2290,
+ -9395, -6952, -2494, 2022, 4753, 5614, 4443, 2642,
+ -1486, 1748, 859, -2586, -3368, -638, 2761, 3269,
+ -2408, 306, 3633, 6567, 5950, 2474, -621, -1421,
+ 5478, 7986, 9498, 8165, 5477, 1244, -523, -1586,
+ -13564, -14673, -10597, -5504, 1575, 8248, 7662, 4025,
+ 4978, -682, -3586, -4305, -3703, -3001, -2227, -1278,
+ -8002, -6831, -5558, -4868, -4243, -3393, -2486, -1110,
+ 11485, 5472, 1645, -533, -1792, -2814, -3169, -2706,
+ 1617, 421, 232, 1382, 2162, 2017, 1318, 744,
+ 3677, 5212, 1990, -1514, -2894, -2441, -451, 592,
+ 731, 4295, 5860, 3756, 1991, 1437, 869, 127,
+ 12736, 11722, 7768, 4682, 1574, -744, -1989, -3131,
+ -3490, -4269, -3681, -1531, 1111, 3327, 4138, 3815,
+ 7344, 1400, -1302, -1502, -1015, 57, 1212, 1498,
+ -4836, -1881, 1071, 2055, 2114, 2465, 2093, 1458,
+ 8569, 5879, 3654, 2879, 2530, 1703, 781, -233,
+ -3709, -990, 2338, 6227, 7083, 7102, 5657, 3401,
+ 3389, 6392, 5267, 1011, 275, 3519, 5236, 4339,
+ 599, 3752, 6943, 9211, 8152, 5568, 3337, 1838,
+ 9885, 9591, 7905, 8068, 7929, 7421, 4234, 757,
+ }
+ },
+ { /* split 2 */
+ { /* TCX 20 */
+ -178, -3476, -5982, -7081, -7548, -7440, -6859, -5798,
+ -3596, -3670, -1501, 770, 812, -286, -2001, -3377,
+ -3998, -5191, -4988, -4421, -3889, -3571, -2738, -1969,
+ -2981, -2687, -1501, -83, 1136, 2377, 3248, 4105,
+ 1842, -41, -1972, -4282, -6779, -8405, -8674, -7835,
+ -259, 571, 2124, 3344, 2959, 1407, -750, -2523,
+ -524, -1956, -2855, -3202, -3939, -4666, -4907, -4782,
+ -5110, -4768, -3017, -663, 4188, 9210, 16602, 21081,
+ 4373, 4846, -603, -6495, -7289, -5540, -4749, -5527,
+ -1448, -1043, -619, -105, 356, 362, 542, 857,
+ 1373, -752, -5334, -6244, -3001, -932, -1040, -3125,
+ -2403, -1397, 612, 2449, 3920, 5231, 6819, 8581,
+ 2183, 1211, -111, -1084, -2836, -4977, -6701, -7284,
+ -751, 1255, 3408, 6474, 7503, 7026, 5413, 4464,
+ 935, 850, 589, 353, 160, -434, -939, -931,
+ 268, 2284, 3884, 5423, 6680, 7996, 9244, 9472,
+ 1075, 113, -1289, -4457, -7512, -5930, -1799, -571,
+ -3689, -4254, -3755, -2995, -1581, -135, 1049, 1589,
+ -1166, -1752, -1790, -1897, -1927, -1831, -1359, -805,
+ -1494, -735, 635, 1993, 2909, 3546, 4226, 4956,
+ 4435, 4299, 4269, 1328, -3731, -7621, -9319, -9170,
+ 1358, 2227, 3873, 4469, 4692, 4057, 2601, 1608,
+ 813, 398, -499, -666, -1286, -2271, -3316, -4025,
+ -3300, -1255, 2181, 6431, 10002, 12760, 13549, 12584,
+ 3714, 4180, 484, -2905, -2864, -1359, -1256, -2477,
+ 308, 868, 1373, 1629, 1793, 1834, 1814, 1746,
+ 1472, 798, -282, -1935, -1818, 320, 2221, 2914,
+ 2281, 3240, 2988, 1400, 2383, 4072, 5667, 6675,
+ 2672, 2678, 2874, 2096, -226, -2301, -3861, -4534,
+ 4988, 7231, 7641, 7731, 7061, 6447, 5411, 3513,
+ 3978, 4156, 4126, 2896, 1469, 759, 368, -68,
+ -264, 4210, 8534, 11008, 11606, 11888, 11072, 8949,
+ },
+ { /* TCX 10 */
+ -2852, -6158, -7231, -7830, -8012, -7922, -7556, -6706,
+ -3911, -5340, -5053, -4741, -4805, -4484, -3727, -3037,
+ -966, -1461, -1694, -2427, -3081, -3037, -2547, -2230,
+ -3455, -3315, -2451, -836, 1383, 3196, 3720, 3379,
+ 3052, 281, -3351, -6866, -9051, -9586, -8983, -8236,
+ -748, -4465, -4314, -2251, 29, -40, -3963, -6195,
+ 200, 1293, 2535, 2803, 1603, -186, -1397, -1697,
+ -1707, -265, 2196, 5295, 5894, 4216, 3440, 3826,
+ -237, -2133, -2279, -3149, -4377, -5638, -6520, -6764,
+ -2407, -2049, -1246, -664, -521, -430, -349, -211,
+ 3874, 1335, -1501, -2055, -1268, -990, -1852, -2871,
+ -1883, -1845, -1681, -484, 384, 2035, 5839, 9597,
+ 275, 380, 1048, 424, -1146, -3012, -4431, -5104,
+ -1699, -484, 756, 1261, 1279, 1377, 1975, 2590,
+ 2139, 4502, 3645, 4975, 6491, 5972, 5012, 4346,
+ -3821, -2581, -433, 2667, 6436, 10038, 11311, 8783,
+ 2359, -2689, -6604, -7039, -5992, -4268, -3711, -4840,
+ -2776, -4251, -4539, -3672, -2494, -1055, 280, 695,
+ 491, 866, 822, -44, -1009, -1165, -831, -538,
+ -1024, 91, 786, 1295, 2433, 3910, 4975, 5403,
+ 3117, 2590, 2337, -667, -4580, -8147, -9400, -9523,
+ -103, -630, -831, 669, 3062, 3398, 549, -1690,
+ 2113, 3467, 4279, 5047, 5344, 3361, 127, -2313,
+ -1199, 1153, 2914, 3688, 4260, 5421, 7471, 8831,
+ 2815, 2184, 316, -3058, -5596, -5564, -4343, -3793,
+ 922, 126, -1414, -1731, -1007, 359, 2029, 3088,
+ 4889, 4619, 2537, 1114, 950, 946, 799, 419,
+ -4271, -3750, -3359, -484, 1448, 4106, 10487, 20479,
+ 3818, 4687, 4064, 2212, -172, -2287, -3535, -4041,
+ 884, 2456, 3394, 2925, 2182, 2323, 2583, 2507,
+ 4767, 8057, 8263, 6461, 5003, 4055, 2923, 1845,
+ 19, 3813, 6926, 8432, 10141, 10850, 9692, 8383,
+ }
+ }
+};
+
+const int16_t sns_1st_means_16k[2][16] =
+{
+ { /* TCX 20 */
+ 14210, 19017, 14362, 9309, 5385, 2674, 1055, -211, -1407, -3059, -4393, -8597, -11180, -11756, -12131, -13281,
+ },
+ { /* TCX 10*/
+ 12018, 15915, 11089, 6015, 847, -705, -539, -1548, -893, -2163, -1806, -4189, -7017, -8670, -8874, -9480,
+ }
+};
+
+const int16_t sns_1st_means_25k6[2][16] =
+{
+ { /* TCX 20 */
+ 14973, 20323, 16461, 9554, 4017, 3103, 1602, 1694, -221, -1401, -6817, -10071, -11503, -11805, -13158, -16749,
+ },
+ { /* TCX 10 */
+ 15560, 19489, 14623, 5595, 2084, 1699, 775, -1312, -2195, -6101, -9078, -9465, -7825, -6603, -7281, -9960,
+ }
+};
+
+const int16_t sns_1st_means_32k[2][16] =
+{
+ { /* TCX 20 */
+ 15041, 20603, 16969, 10289, 4973, 4283, 3003, 3316, 1684, -259, -6614, -9535, -10363, -11834, -16625, -24930,
+ },
+ { /* TCX 10 */
+ 16510, 20660, 16025, 7224, 3921, 3868, 2623, 742, -1316, -6269, -8284, -7288, -6380, -8410, -13351, -20277,
+ }
+};
+
+
+/*----------------------------------------------------------------------*
+ * MC ParamUpmix ROM tables
+ *-----------------------------------------------------------------------*/
+
+const ACPL_QUANT_TABLE ivas_mc_paramupmix_alpha_quant_table[] =
+{
+ /* Alfa Fine */
+ {
+ 33, /* nquant */
+ 16, /* offset */
+ { -2.000000e+000f, -1.809375e+000f, -1.637500e+000f, -1.484375e+000f, -1.350000e+000f, -1.234375e+000f, -1.137500e+000f, -1.059375e+000f, -1.000000e+000f, -9.406250e-001f,
+ -8.625000e-001f, -7.656250e-001f, -6.500000e-001f, -5.156250e-001f, -3.625000e-001f, -1.906250e-001f, +0.000000e+000f, +1.906250e-001f, +3.625000e-001f, +5.156250e-001f,
+ +6.500000e-001f, +7.656250e-001f, +8.625000e-001f, +9.406250e-001f, +1.000000e+000f, +1.059375e+000f, +1.137500e+000f, +1.234375e+000f, +1.350000e+000f, +1.484375e+000f,
+ +1.637500e+000f, +1.809375e+000f, +2.000000e+000f } /* data */
+ },
+ { /* Alfa Coarse */
+ 17, /* nquant */
+ 8, /* offset */
+ { -2.000000e+000f, -1.637500e+000f, -1.350000e+000f, -1.137500e+000f, -1.000000e+000f, -8.625000e-001f, -6.500000e-001f, -3.625000e-001f, +0.000000e+000f, +3.625000e-001f,
+ +6.500000e-001f, +8.625000e-001f, +1.000000e+000f, +1.137500e+000f, +1.350000e+000f, +1.637500e+000f, +2.000000e+000f } /* data */
+ }
+};
+
+const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[2][9] =
+{
+ {
+ /* Beta Fine #1 */
+ {
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +2.375000e-001f, +5.500000e-001f, +9.375000e-001f, +1.400000e+000f, +1.937500e+000f, +2.550000e+000f, +3.237500e+000f, +4.000000e+000f } /* data */
+ },
+ { /* Beta Fine #2 */
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +2.035449e-001f, +4.713672e-001f, +8.034668e-001f, +1.199844e+000f, +1.660498e+000f, +2.185430e+000f, +2.774639e+000f, +3.428125e+000f } /* data */
+ },
+ { /* Beta Fine #3 */
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +1.729297e-001f, +4.004688e-001f, +6.826172e-001f, +1.019375e+000f, +1.410742e+000f, +1.856719e+000f, +2.357305e+000f, +2.912500e+000f } /* data */
+ },
+ { /* Beta Fine #4 */
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +1.456543e-001f, +3.373047e-001f, +5.749512e-001f, +8.585938e-001f, +1.188232e+000f, +1.563867e+000f, +1.985498e+000f, +2.453125e+000f } /* data */
+ },
+ { /* Beta Fine #5 */
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +1.217188e-001f, +2.818750e-001f, +4.804688e-001f, +7.175000e-001f, +9.929688e-001f, +1.306875e+000f, +1.659219e+000f, +2.050000e+000f } /* data */
+ },
+ { /* Beta Fine #6 */
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +1.011230e-001f, +2.341797e-001f, +3.991699e-001f, +5.960938e-001f, +8.249512e-001f, +1.085742e+000f, +1.378467e+000f, +1.703125e+000f } /* data */
+ },
+ { /* Beta Fine #7 */
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +8.386719e-002f, +1.942188e-001f, +3.310547e-001f, +4.943750e-001f, +6.841797e-001f, +9.004688e-001f, +1.143242e+000f, +1.412500e+000f } /* data */
+ },
+ { /* Beta Fine #8 */
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +6.995117e-002f, +1.619922e-001f, +2.761230e-001f, +4.123438e-001f, +5.706543e-001f, +7.510547e-001f, +9.535449e-001f, +1.178125e+000f } /* data */
+ },
+ { /* Beta Fine #9 */
+ 9, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +5.937500e-002f, +1.375000e-001f, +2.343750e-001f, +3.500000e-001f, +4.843750e-001f, +6.375000e-001f, +8.093750e-001f, +1.000000e+000f } /* data */
+ }
+ },
+ {
+ /* Beta Coarse #1 */
+ {
+ 5, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +5.500000e-001f, +1.400000e+000f, +2.550000e+000f, +4.000000e+000f } /* data */
+ },
+ { /* Beta Coarse #2 */
+ 5, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +4.004688e-001f, +1.019375e+000f, +1.856719e+000f, +2.912500e+000f } /* data */
+ },
+ { /* Beta Coarse #3 */
+ 5, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +2.818750e-001f, +7.175000e-001f, +1.306875e+000f, +2.050000e+000f } /* data */
+ },
+ { /* Beta Coarse #4 */
+ 5, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +1.942188e-001f, +4.943750e-001f, +9.004688e-001f, +1.412500e+000f } /* data */
+ },
+ { /* Beta Coarse #5 */
+ 5, /* nquant */
+ 0, /* offset */
+ { +0.000000e+000f, +1.375000e-001f, +3.500000e-001f, +6.375000e-001f, +1.000000e+000f } /* data */
+ }
+ }
+};
+
+/* clang-format on */
diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h
new file mode 100644
index 0000000000000000000000000000000000000000..9823e5ea30568427aabd1d73a02ff84f1bfd815d
--- /dev/null
+++ b/lib_com/ivas_rom_com.h
@@ -0,0 +1,458 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_ROM_COM_H
+#define IVAS_ROM_COM_H
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "ivas_cnst.h"
+#include "stat_com.h"
+#include "ivas_stat_com.h"
+
+
+/*----------------------------------------------------------------------------------*
+ * General IVAS ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const int32_t ivas_brate_tbl[];
+
+/*-------------------------------------------------------------------------
+ * DFT Stereo ROM tables
+ *------------------------------------------------------------------------*/
+
+extern const int16_t dft_band_limits_erb4[];
+extern const int16_t dft_band_limits_erb8[];
+extern const int16_t dft_band_ipd[3][4];
+extern const int16_t dft_band_res_cod[3][4];
+
+extern const float dft_res_gains_q[][2];
+extern const float dft_res_cod_alpha[STEREO_DFT_BAND_MAX];
+
+extern const float dft_trigo_12k8[STEREO_DFT_N_12k8_ENC / 4 + 1];
+extern const float dft_trigo_32k[STEREO_DFT_N_32k_ENC / 4 + 1];
+extern const float dft_trigo_48k[STEREO_DFT_N_MAX_ENC / 4 + 1];
+
+/* Golomb-Rice encoding tables */
+extern const int16_t dft_maps_rpg[];
+extern const int16_t dft_code_itd[];
+extern const int16_t dft_len_itd[];
+extern const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G];
+
+/*----------------------------------------------------------------------------------*
+ * Range Coder ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS];
+extern const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS];
+
+/*----------------------------------------------------------------------------------*
+ * ECLVQ Stereo ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const uint16_t ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE];
+
+/*----------------------------------------------------------------------------------*
+ * Stereo ICA ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const float ica_sincInterp2[];
+extern const float ica_sincInterp4[];
+extern const float ica_sincInterp6[];
+
+/*----------------------------------------------------------------------------------*
+ * Stereo IC-BWE ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const float icbwe_gsMapping_tbl[];
+extern const float icbwe_gsMappingDFT_tbl[];
+
+/*----------------------------------------------------------------------------------*
+ * TD Stereo ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const float tdm_ratio_tabl[];
+extern const float tdm_den_ratio_tabl[];
+extern const int16_t tdm_bit_allc_tbl[5][6];
+
+/* LSFs Intra-frame prediction tables */
+extern const float tdm_LSF_MEAN_RE_USE_OUT[M];
+extern const float tdm_LSF_MEAN_RE_USE_IN[M];
+extern const float tdm_LSF_MEAN_RE_USE[M];
+
+extern const float tdm_Beta_Q1bit_re_use_13k2[2];
+extern const float tdm_Beta_Q1bit_re_use_16k4[2];
+extern const float tdm_Beta_Q1bit_re_use_24k4_32k[2];
+extern const float tdm_Beta_Q1bit_re_use_48k[2];
+
+extern const float tdm_RE_USE_adaptive_beta_prd_diag_3[15 + 16 + 15];
+
+extern const float tdm_LSF_MEAN_PRED_QNT_OUT[M];
+extern const float tdm_LSF_MEAN_PRED_QNT_IN[M];
+extern const float tdm_LSF_MEAN_PRED_QNT[M];
+extern const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15];
+
+extern const int16_t fast_FCB_bits_2sfr[];
+extern const int16_t fast_FCB_rates_2sfr[];
+
+/*----------------------------------------------------------------------------------*
+ * MDCT Stereo ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const SpectrumWarping sw16000Hz[]; /* PsychLPC */
+extern const SpectrumWarping sw25600Hz[]; /* PsychLPC */
+extern const SpectrumWarping sw32000Hz[]; /* PsychLPC */
+
+extern const MDCTStereoBands_config mdctStereoBands_32000_640[];
+extern const float nf_tw_smoothing_coeffs[N_LTP_GAIN_MEMS];
+
+/*----------------------------------------------------------------------------------*
+ * Stereo DTX ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const float dft_cng_coh_pred[][STEREO_DFT_COH_PRED_COEFFS];
+extern const int16_t dft_cng_coh_u2i[9];
+extern const int16_t dft_cng_coh_i2u[9];
+extern const float dft_cng_alpha_bits[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS];
+extern const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1];
+
+/*----------------------------------------------------------------------------------*
+ * DirAC ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const float diffuseness_reconstructions[DIRAC_DIFFUSE_LEVELS];
+extern const float diffuseness_thresholds[DIRAC_DIFFUSE_LEVELS + 1];
+extern const int16_t DirAC_band_grouping_12[12 + 1];
+extern const int16_t DirAC_band_grouping_6[6 + 1];
+extern const int16_t DirAC_band_grouping_5[5 + 1];
+extern const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1];
+extern const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1];
+
+extern const float c_weights[DIRAC_NO_FB_BANDS_MAX];
+
+extern const float w_nm[NUM_ANA_SECTORS][9];
+extern const float x_nm[NUM_ANA_SECTORS][9];
+extern const float y_nm[NUM_ANA_SECTORS][9];
+extern const float z_nm[NUM_ANA_SECTORS][9];
+
+/*------------------------------------------------------------------------------------------*
+ * SPAR ROM tables
+ *------------------------------------------------------------------------------------------*/
+
+extern const ivas_freq_models_t ivas_arith_pred_r_consts[TOTAL_PRED_QUANT_STRATS_ARITH];
+extern const ivas_freq_models_t ivas_arith_drct_r_consts[TOTAL_DRCT_QUANT_STRATS];
+extern const ivas_freq_models_t ivas_arith_decd_r_consts[TOTAL_DECD_QUANT_STRATS];
+extern const ivas_huff_models_t ivas_huff_pred_r_consts[TOTAL_PRED_QUANT_STRATS_HUFF];
+extern const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS];
+extern const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS];
+extern const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN];
+extern const int16_t remix_order_set[1][DIRAC_MAX_ANA_CHANS];
+extern const int16_t HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN];
+extern const int16_t HOA_keep_ind_spar[IVAS_SPAR_MAX_CH];
+extern const int16_t HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH];
+
+extern const float dtx_pd_real_min_max[2];
+extern const int16_t dtx_pd_real_q_levels[3][3];
+extern const int16_t dtx_pr_real_q_levels[3][3];
+extern const int16_t pr_pr_idx_pairs[3][3][2];
+extern const int16_t pr_pd_idx_pairs[3][3][2];
+
+
+/*----------------------------------------------------------------------*
+ * PCA ROM tables
+ *-----------------------------------------------------------------------*/
+
+extern const int32_t ivas_pca_offset_index1[IVAS_PCA_N1 + 1];
+extern const int16_t ivas_pca_offset_index2[2692];
+extern const int16_t ivas_pca_offset_n2[IVAS_PCA_N1];
+
+
+/*----------------------------------------------------------------------------------*
+ * Parametric MC ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const int16_t param_mc_band_grouping_20[20 + 1];
+extern const int16_t param_mc_coding_band_mapping_20[20];
+extern const int16_t param_mc_bands_coded_20[4];
+extern const int16_t param_mc_band_grouping_14[14 + 1];
+extern const int16_t param_mc_coding_band_mapping_14[14];
+extern const int16_t param_mc_bands_coded_14[4];
+extern const int16_t param_mc_band_grouping_10[10 + 1];
+extern const int16_t param_mc_coding_band_mapping_10[10];
+extern const int16_t param_mc_bands_coded_10[4];
+extern const int16_t param_mc_start_bin_per_band_20[20];
+extern const int16_t param_mc_active_bins_per_band_20[20];
+extern const int16_t param_mc_start_bin_per_band_14[14];
+extern const int16_t param_mc_active_bins_per_band_14[14];
+extern const int16_t param_mc_start_bin_per_band_10[10];
+extern const int16_t param_mc_active_bins_per_band_10[10];
+extern const int16_t Param_MC_index[MAX_CICP_CHANNELS];
+extern const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS];
+extern const float ivas_param_mc_quant_ild_5d1_48[PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const float ivas_param_mc_quant_icc[PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1];
+extern const uint16_t ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1];
+extern const uint16_t ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1];
+extern const uint16_t ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1];
+
+extern const uint16_t ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1];
+extern const uint16_t ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1];
+extern const uint16_t ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1];
+extern const uint16_t ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1];
+
+extern const uint16_t ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1];
+extern const uint16_t ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1];
+extern const uint16_t ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1];
+extern const uint16_t ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1];
+
+extern const uint16_t ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1];
+extern const uint16_t ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const uint16_t ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS];
+extern const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1];
+extern const uint16_t ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1];
+extern const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER];
+extern const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1];
+
+/*----------------------------------------------------------------------------------*
+ * Parametric Upmix MC ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const int16_t ivas_param_upmx_mx_qmap[2][33];
+
+
+/*----------------------------------------------------------------------------------*
+ * MASA ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const int16_t bits_direction_masa[DIRAC_DIFFUSE_LEVELS];
+extern const int16_t no_theta_masa[NO_SPHERICAL_GRIDS - 2];
+extern const int16_t no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA];
+
+extern const float delta_theta_masa[NO_SPHERICAL_GRIDS - 2];
+
+extern const float azimuth_cb[8];
+extern const float coherence_cb0_masa[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH];
+extern const float coherence_cb1_masa[MASA_NO_CV_COH1 * MASA_MAXIMUM_CODING_SUBBANDS]; /* 25 */
+extern const int16_t len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS];
+extern const uint8_t sur_coherence_cb_masa[MASA_NO_CB_SUR_COH * MASA_MAX_NO_CV_SUR_COH];
+extern const int16_t idx_cb_sur_coh_masa[MASA_NO_CV_COH];
+extern const int16_t len_huf_masa[MASA_NO_CV_COH1];
+extern const int16_t huff_code_av_masa[MASA_NO_CV_COH1];
+
+extern const int16_t MASA_band_grouping_24[24 + 1];
+extern const int16_t MASA_band_mapping_24_to_18[18 + 1];
+extern const int16_t MASA_band_mapping_24_to_12[12 + 1];
+extern const int16_t MASA_band_mapping_24_to_8[8 + 1];
+extern const int16_t MASA_band_mapping_24_to_5[5 + 1];
+
+extern const int16_t MASA_grouping_8_to_5[8];
+extern const int16_t MASA_grouping_12_to_5[12];
+extern const int16_t MASA_grouping_18_to_5[18];
+extern const int16_t MASA_grouping_24_to_5[24];
+extern const int16_t masa_bits[14];
+extern const int16_t masa_bits_LR_stereo[4];
+extern const int16_t mcmasa_bits[];
+extern const uint8_t masa_nbands[];
+extern const uint8_t masa_joined_nbands[];
+extern const uint8_t masa_twodir_bands[];
+extern const uint8_t masa_twodir_bands_joined[];
+
+extern const float diffuseness_reconstructions_hr[HR_MASA_ER_LEVELS];
+extern const float diffuseness_thresholds_hr[HR_MASA_ER_LEVELS + 1];
+
+/* Multi-channel input and output setups */
+extern const float ls_azimuth_CICP2[2];
+extern const float ls_elevation_CICP2[2];
+extern const float ls_azimuth_CICP6[5];
+extern const float ls_elevation_CICP6[5];
+extern const float ls_azimuth_CICP12[7];
+extern const float ls_elevation_CICP12[7];
+extern const float ls_azimuth_CICP14[7];
+extern const float ls_elevation_CICP14[7];
+extern const float ls_azimuth_CICP16[9];
+extern const float ls_elevation_CICP16[9];
+extern const float ls_azimuth_CICP19[11];
+extern const float ls_elevation_CICP19[11];
+
+extern const float cb_azi_chan[];
+
+extern const float McMASA_LFEGain_vectors[64];
+
+/*----------------------------------------------------------------------------------*
+ * MASA and ISM (OMASA) combined format ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const int32_t sep_object_brate[][MAX_NUM_OBJECTS];
+extern const float dct4[];
+extern const float dct5[];
+extern const float dct8[];
+extern const float dct12[];
+
+/*----------------------------------------------------------------------------------*
+ * ISM ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const float ism_azimuth_borders[4];
+extern const float ism_elevation_borders[4];
+
+/*----------------------------------------------------------------------------------*
+ * Param ISM ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1];
+
+/*----------------------------------------------------------------------------------*
+ * LFE coding ROM tables
+ *----------------------------------------------------------------------------------*/
+
+extern const float ivas_lpf_4_butter_16k_sos[IVAS_BIQUAD_FILT_LEN << 2];
+extern const float ivas_lpf_4_butter_32k_sos[IVAS_BIQUAD_FILT_LEN << 2];
+extern const float ivas_lpf_4_butter_48k_sos[IVAS_BIQUAD_FILT_LEN << 2];
+extern const float ivas_lpf_2_butter_16k[IVAS_BIQUAD_FILT_LEN << 1];
+extern const float ivas_lpf_2_butter_32k[IVAS_BIQUAD_FILT_LEN << 1];
+extern const float ivas_lpf_2_butter_48k[IVAS_BIQUAD_FILT_LEN << 1];
+
+extern const float ivas_lfe_window_coeff_48k[IVAS_LFE_FADE_LEN_48K];
+extern const float ivas_lfe_window_coeff_32k[IVAS_LFE_FADE_LEN_32K];
+extern const float ivas_lfe_window_coeff_16k[IVAS_LFE_FADE_LEN_16K];
+
+extern const int16_t ivas_lfe_num_ele_in_coder_models[2][4];
+extern const int16_t ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP];
+extern const int16_t ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP];
+extern const ivas_lfe_freq_models ivas_str_lfe_freq_models;
+extern const float ivas_lfe_lpf_delay[2];
+
+extern const double d_hamm_lfe_plc[LFE_PLC_LENANA / 2];
+
+extern const float ivas_sin_twiddle_480[IVAS_480_PT_LEN >> 1];
+extern const float ivas_cos_twiddle_480[IVAS_480_PT_LEN >> 1];
+extern const float ivas_sin_twiddle_320[IVAS_320_PT_LEN >> 1];
+extern const float ivas_cos_twiddle_320[IVAS_320_PT_LEN >> 1];
+extern const float ivas_sin_twiddle_160[IVAS_160_PT_LEN >> 1];
+extern const float ivas_cos_twiddle_160[IVAS_160_PT_LEN >> 1];
+extern const float ivas_sin_twiddle_80[IVAS_80_PT_LEN >> 1];
+extern const float ivas_cos_twiddle_80[IVAS_80_PT_LEN >> 1];
+
+/*------------------------------------------------------------------------------------------*
+ * MDFT/iMDFT ROM tables
+ *------------------------------------------------------------------------------------------*/
+
+extern const float ivas_mdft_coeff_cos_twid_240[IVAS_240_PT_LEN + 1];
+extern const float ivas_mdft_coeff_cos_twid_160[IVAS_160_PT_LEN + 1];
+extern const float ivas_mdft_coeff_cos_twid_120[IVAS_120_PT_LEN + 1];
+extern const float ivas_mdft_coeff_cos_twid_80[IVAS_80_PT_LEN + 1];
+extern const float ivas_mdft_coeff_cos_twid_40[IVAS_40_PT_LEN + 1];
+extern const float ivas_mdft_coeff_cos_twid_960[IVAS_960_PT_LEN + 1];
+extern const float ivas_mdft_coeff_cos_twid_640[IVAS_640_PT_LEN + 1];
+extern const float ivas_mdft_coeff_cos_twid_320[IVAS_320_PT_LEN + 1];
+extern const int16_t dirac_gains_P_idx[16];
+extern const float dirac_gains_norm_term[9];
+extern const float dirac_gains_Pnm[91][9];
+extern const float dirac_gains_trg_term[181][2];
+
+/*------------------------------------------------------------------------------------------*
+ * FB ROM tables
+ *------------------------------------------------------------------------------------------*/
+
+extern const float ivas_fb_fcs_12band_1ms[IVAS_FB_BANDS_12];
+
+extern const float ivas_fb_fr_12band_1ms_re[IVAS_FB_12_1MS_LEN];
+extern const float ivas_fb_fr_12band_1ms_im[IVAS_FB_12_1MS_LEN];
+
+extern const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12];
+extern const int16_t ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12];
+extern const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12];
+extern const int16_t ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12];
+
+extern const float ivas_fb_cf_4ms_48k[IVAS_FB_4MS_48K_SAMP];
+extern const float ivas_fb_cf_1ms_48k[IVAS_FB_1MS_48K_SAMP];
+extern const float ivas_fb_cf_4ms_32k[IVAS_FB_4MS_32K_SAMP];
+extern const float ivas_fb_cf_1ms_32k[IVAS_FB_1MS_32K_SAMP];
+extern const float ivas_fb_cf_4ms_16k[IVAS_FB_4MS_16K_SAMP];
+extern const float ivas_fb_cf_1ms_16k[IVAS_FB_1MS_16K_SAMP];
+
+extern const float ivas_fb_resp_cheby_ramp_32del[IVAS_FB_1MS_32K_SAMP + 1];
+extern const float ivas_fb_resp_cheby_ramp_16del[IVAS_FB_1MS_16K_SAMP + 1];
+
+extern const int16_t ivas_num_active_bands[FB - WB + 1];
+
+/*------------------------------------------------------------------------------------------*
+ * SNS MSVQ codebooks and means
+ *------------------------------------------------------------------------------------------*/
+
+extern const int16_t ivas_sns_cdbks_tcx20_levels[];
+extern const int16_t ivas_sns_cdbks_tcx20_bits[];
+
+extern const int16_t ivas_sns_cdbks_tcx10_levels[];
+extern const int16_t ivas_sns_cdbks_tcx10_bits[];
+
+extern const float *const ivas_sns_cdbks_tcx20[];
+extern const float *const ivas_sns_cdbks_tcx10[];
+
+extern const int16_t ivas_sns_cdbks_side_tcx20_levels[];
+extern const int16_t ivas_sns_cdbks_side_tcx20_bits[];
+extern const int16_t ivas_sns_cdbks_side_tcx10_levels[];
+extern const int16_t ivas_sns_cdbks_side_tcx10_bits[];
+
+extern const float *const ivas_sns_cdbks_side_tcx20[];
+extern const float *const ivas_sns_cdbks_side_tcx10[];
+
+/* means and codebooks for the split VQ in the 2-stage SNS VQ */
+extern const int16_t sns_1st_cdbk[2][2][8 * 32];
+extern const int16_t sns_1st_means_16k[2][16];
+extern const int16_t sns_1st_means_25k6[2][16];
+extern const int16_t sns_1st_means_32k[2][16];
+
+
+/*----------------------------------------------------------------------*
+ * MC ParamUpmix ROM tables
+ *-----------------------------------------------------------------------*/
+
+extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_alpha_quant_table[];
+extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[2][9];
+
+/* IVAS_ROM_COM_H */
+#endif
diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c
new file mode 100644
index 0000000000000000000000000000000000000000..fd1bb70fdce6bc28348aa623761bc08a79a86988
--- /dev/null
+++ b/lib_com/ivas_sba_config.c
@@ -0,0 +1,336 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include "cnst.h"
+#include "ivas_cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "ivas_stat_com.h"
+#include "ivas_rom_com.h"
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------------*
+ * ivas_sba_config()
+ *
+ * Configure SBA coding
+ *-------------------------------------------------------------------*/
+
+void ivas_sba_config(
+ const int32_t sba_total_brate, /* i : SBA total bitrate */
+ int16_t sba_order, /* i : Ambisonic (SBA) order */
+ int16_t nb_channels, /* i : Number of ambisonic channels */
+ int16_t *nchan_transport, /* o : number of transport channels */
+ const int16_t sba_planar, /* i : SBA Planar flag */
+ int16_t *nSCE, /* o : number of SCEs */
+ int16_t *nCPE, /* o : number of CPEs */
+ int16_t *element_mode /* o : element mode of the core coder */
+)
+{
+ if ( ( sba_order < 0 ) && ( nb_channels < 0 ) )
+ {
+ assert( 0 && "Either order or number of channels must be positive" );
+ }
+ else if ( sba_order < 0 )
+ {
+ sba_order = ivas_sba_get_order( nb_channels, sba_planar );
+ }
+ else if ( nb_channels < 0 )
+ {
+ nb_channels = ivas_sba_get_nchan( sba_order, sba_planar );
+ }
+ else
+ {
+ if ( sba_planar )
+ {
+ assert( ( ( 2 * sba_order ) + 1 == nb_channels ) && "Order and number of channels do not correspond!" );
+ }
+ else
+ {
+ assert( ( ( sba_order + 1 ) * ( sba_order + 1 ) == nb_channels ) && "Order and number of channels do not correspond!" );
+ }
+ }
+
+ if ( nchan_transport != NULL )
+ {
+ *nchan_transport = ivas_get_sba_num_TCs( sba_total_brate, sba_order );
+ }
+
+ /* Configure core coder number of elements*/
+ if ( nchan_transport != NULL && nSCE != NULL && nCPE != NULL )
+ {
+ if ( *nchan_transport == 1 )
+ {
+ *nSCE = 1;
+ *nCPE = 0;
+ *element_mode = IVAS_SCE;
+ }
+ else
+ {
+ *nSCE = 0;
+ *nCPE = *nchan_transport / 2;
+ if ( 2 * ( *nCPE ) != *nchan_transport )
+ {
+ ( *nCPE )++;
+ }
+ *element_mode = IVAS_CPE_MDCT;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_sba_get_order()
+ *
+ * Get Ambisonic order from number of ambisonic channels
+ *-------------------------------------------------------------------*/
+
+/*! r: Ambisonic (SBA) order */
+int16_t ivas_sba_get_order(
+ const int16_t nb_channels, /* i : Number of ambisonic channels */
+ const int16_t sba_planar /* i : SBA Planar flag */
+)
+{
+ int16_t sba_order;
+
+ if ( sba_planar )
+ {
+ sba_order = ( nb_channels - 1 ) / 2;
+ assert( ( 2 * sba_order + 1 == nb_channels ) && "Number of channels not supported in Planar SBA!" );
+ }
+ else
+ {
+ sba_order = (int16_t) sqrtf( (float) nb_channels ) - 1;
+ assert( ( ( sba_order + 1 ) * ( sba_order + 1 ) == nb_channels ) && "Number of channels not supported in SBA!" );
+ }
+
+ assert( ( sba_order <= 3 ) && "Error: SBA order must be <= 3!" );
+
+ return ( sba_order );
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_sba_get_analysis_order()
+ *
+ * Get Ambisonic order used for analysis and coding
+ *-------------------------------------------------------------------*/
+
+/*! r: Ambisonic (SBA) order used for analysis and coding */
+int16_t ivas_sba_get_analysis_order(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+)
+{
+ int16_t sba_analysis_order;
+
+ sba_analysis_order = sba_order;
+
+ if ( ivas_total_brate < SBA_MIN_BRATE_HOA )
+ {
+ /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */
+ sba_analysis_order = SBA_FOA_ORDER;
+ }
+
+ return sba_analysis_order;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_sba_get_nchan()
+ *
+ * Get number of Ambisonic channels
+ *-------------------------------------------------------------------*/
+
+/*! r: number of Ambisonic channels */
+int16_t ivas_sba_get_nchan(
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int16_t sba_planar /* i : SBA planar flag */
+)
+{
+ int16_t nb_channels;
+
+ if ( sba_planar )
+ {
+ nb_channels = ( 2 * sba_order ) + 1;
+ }
+ else
+ {
+ nb_channels = ( sba_order + 1 ) * ( sba_order + 1 );
+ }
+
+ return ( nb_channels );
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_sba_get_nchan_metadata()
+ *
+ * Get number of Ambisonic channels for metadata coding
+ *-------------------------------------------------------------------*/
+
+/*! r: number of ambisonics metadata channels */
+int16_t ivas_sba_get_nchan_metadata(
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ int16_t nb_channels;
+
+ if ( sba_order == SBA_FOA_ORDER )
+ {
+ nb_channels = FOA_CHANNELS;
+ }
+ else
+ {
+ if ( ivas_total_brate >= IVAS_512k )
+ {
+ nb_channels = IVAS_SPAR_MAX_CH;
+ nb_channels = min( nb_channels, ( sba_order + 1 ) * ( sba_order + 1 ) );
+ }
+ else
+ {
+ /* FOA + planar HOA */
+ nb_channels = FOA_CHANNELS + 2 * ( sba_order - 1 );
+ }
+ }
+
+ return ( nb_channels );
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_sba_get_spar_hoa_ch_ind()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+/*! r: flag indicating to code SPAR HOA MD for all bands */
+void ivas_sba_get_spar_hoa_ch_ind(
+ const int16_t num_md_chs, /* i : number of MD channels */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] )
+{
+ int16_t ch;
+ const int16_t *hoa_ind;
+
+ if ( ivas_total_brate >= IVAS_512k )
+ {
+ hoa_ind = HOA_keep_ind_spar512;
+ }
+ else
+ {
+ hoa_ind = HOA_keep_ind_spar;
+ }
+
+ for ( ch = 0; ch < num_md_chs; ch++ )
+ {
+ HOA_md_ind[ch] = hoa_ind[ch];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_sba_get_spar_hoa_md_flag()
+ *
+ * Get the flag to code SPAR HOA MD for all band
+ *-------------------------------------------------------------------*/
+
+void ivas_sba_get_spar_hoa_md_flag(
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ int16_t *spar_hoa_md_flag,
+ int16_t *spar_hoa_dirac2spar_md_flag )
+{
+ if ( sba_order > 1 && ivas_total_brate >= IVAS_256k )
+ {
+ *spar_hoa_md_flag = 1;
+ }
+ else
+ {
+ *spar_hoa_md_flag = 0;
+ }
+
+ if ( sba_order > 1 && ivas_total_brate >= IVAS_512k )
+ {
+ *spar_hoa_dirac2spar_md_flag = 0;
+ }
+ else
+ {
+ *spar_hoa_dirac2spar_md_flag = 1;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_sba_zero_vert_comp()
+ *
+ * Zero vertical Ambisonics components
+ *-------------------------------------------------------------------*/
+
+void ivas_sba_zero_vert_comp(
+ float *sba_data[], /* i : SBA signals */
+ const int16_t sba_order, /* i : SBA order */
+ const int16_t sba_planar, /* i : SBA planar flag */
+ const int16_t input_frame /* i : frame length */
+)
+{
+ int16_t i, j;
+
+ /* Channels in the range i^2+1 to (i+1)^2 -1 are zeroed (retain only first and last channel for that order) */
+ for ( i = 1; i <= sba_order; i++ )
+ {
+ /* Keep Z if not planar */
+ if ( !sba_planar && i == 1 )
+ {
+ continue;
+ }
+
+ for ( j = ( i * i + 1 ); j < ( ( i + 1 ) * ( i + 1 ) - 1 ); j++ )
+ {
+ set_zero( sba_data[j], input_frame );
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_sns_com.c b/lib_com/ivas_sns_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..4708b32c29434a5abde573b7ddb6e099cbcb0997
--- /dev/null
+++ b/lib_com/ivas_sns_com.c
@@ -0,0 +1,294 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "prot.h"
+#include "ivas_prot.h"
+#include "rom_com.h"
+#include "ivas_rom_com.h"
+#include
+#include
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------------
+ * sns_compute_scf()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void sns_compute_scf(
+ float spectrum[],
+ const PsychoacousticParameters *pPsychParams,
+ const int16_t L_frame,
+ float *scf )
+{
+ int16_t i, n, k;
+ float x[FDNS_NPTS], xs[FDNS_NPTS], sum, mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS];
+ float tilt;
+ const uint8_t nBands = pPsychParams->nBands;
+ const uint8_t *bandLengths = pPsychParams->bandLengths;
+ int8_t bw = 0;
+
+
+ const float w_0 = 1.0f / 12.0f;
+ const float w_1 = 2.0f / 12.0f;
+ const float w_2 = 0.25f; /* 3.0f / 12.0f */
+ const float w_3 = w_2;
+ const float w_4 = w_1;
+ const float w_5 = w_0;
+
+ const float scale_log = INV_LOG_2 * 0.5f;
+
+ assert( nBands == FDNS_NPTS );
+
+ set_f( x, 0.0f, FDNS_NPTS );
+
+ if ( bandLengths == NULL )
+ {
+ bw = (int8_t) ( L_frame / nBands );
+ /* Energy per band */
+ k = 0;
+ for ( i = 0; i < nBands; ++i )
+ {
+ x[i] = 0.0f;
+ for ( n = 0; n < bw; ++n, ++k )
+ {
+ x[i] += spectrum[k];
+ }
+ x[i] /= bw;
+ }
+ }
+ else
+ {
+ /* Energy per band */
+ k = 0;
+ for ( i = 0; i < nBands; ++i )
+ {
+ x[i] = 0.0f;
+ for ( n = 0; n < bandLengths[i]; ++n, ++k )
+ {
+ x[i] += spectrum[k];
+ }
+ x[i] /= bandLengths[i];
+ }
+ }
+
+ /* Smoothing */
+ xs[0] = 0.75f * x[0] + 0.25f * x[1];
+
+ for ( i = 1; i < FDNS_NPTS - 1; i++ )
+ {
+ xs[i] = 0.5f * x[i] + 0.25f * x[i - 1] + 0.25f * x[i + 1];
+ }
+
+ xs[FDNS_NPTS - 1] = 0.75f * x[FDNS_NPTS - 1] + 0.25f * x[FDNS_NPTS - 2];
+
+ /* Pre-emphasis */
+ switch ( L_frame )
+ {
+ case L_FRAME16k:
+ tilt = 19.f;
+ break;
+ case L_FRAME25_6k:
+ tilt = 22.f;
+ break;
+ case L_FRAME32k:
+ tilt = 23.5f;
+ break;
+ default:
+ tilt = 0.f;
+ assert( !"illegal frame length in sns_compute_scf" );
+ }
+
+ for ( i = 0; i < FDNS_NPTS; i++ )
+ {
+ xs[i] = xs[i] * powf( 10.0f, (float) i * (float) tilt / ( (float) FDNS_NPTS - 1.0f ) / 10.0f );
+ }
+
+ /* Noise floor at -40dB */
+ sum = sum_f( xs, FDNS_NPTS );
+ mean = sum / FDNS_NPTS;
+
+ nf = mean * powf( 10.0f, -4.0f );
+ nf = max( nf, powf( 2.0f, -32.0f ) );
+
+
+ for ( i = 0; i < FDNS_NPTS; i++ )
+ {
+ if ( xs[i] < nf )
+ {
+ xs[i] = nf;
+ }
+ }
+
+ /* Log-domain */
+ for ( i = 0; i < FDNS_NPTS; i++ )
+ {
+ xl[i] = logf( xs[i] ) * scale_log;
+ }
+
+ /* Downsampling */
+ xl4[0] = w_0 * xl[0] +
+ w_1 * xl[0] +
+ w_2 * xl[1] +
+ w_3 * xl[2] +
+ w_4 * xl[3] +
+ w_5 * xl[4];
+
+
+ for ( n = 1; n < SNS_NPTS - 1; n++ )
+ {
+ int16_t n4 = 4 * n;
+ xl4[n] = w_0 * xl[n4 - 1] +
+ w_1 * xl[n4] +
+ w_2 * xl[n4 + 1] +
+ w_3 * xl[n4 + 2] +
+ w_4 * xl[n4 + 3] +
+ w_5 * xl[n4 + 4];
+ }
+
+ xl4[SNS_NPTS - 1] = w_0 * xl[FDNS_NPTS - 5] +
+ w_1 * xl[FDNS_NPTS - 4] +
+ w_2 * xl[FDNS_NPTS - 3] +
+ w_3 * xl[FDNS_NPTS - 2] +
+ w_4 * xl[FDNS_NPTS - 1] +
+ w_5 * xl[FDNS_NPTS - 1];
+
+ /* Remove mean and scaling */
+ sum = sum_f( xl4, SNS_NPTS );
+ mean = sum / SNS_NPTS;
+
+ for ( i = 0; i < SNS_NPTS; i++ )
+ {
+ scf[i] = 0.85f * ( xl4[i] - mean );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------
+ * sns_interpolate_scalefactors()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void sns_interpolate_scalefactors(
+ float *scf_int, /* o : interpolated scalefactors for spectrum shaping*/
+ const float *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */
+ int16_t encoder_side /* i : flag, if scalefactors have to be inverted */
+)
+{
+ int16_t n;
+
+ /* Interpolation */
+ scf_int[0] = scf[0];
+ scf_int[1] = scf[0];
+
+ for ( n = 0; n <= M - 2; n++ )
+ {
+ scf_int[n * 4 + 2] = scf[n] + ( scf[n + 1] - scf[n] ) / 8.f;
+ scf_int[n * 4 + 3] = scf[n] + 3.f * ( scf[n + 1] - scf[n] ) / 8.f;
+ scf_int[n * 4 + 4] = scf[n] + 5.f * ( scf[n + 1] - scf[n] ) / 8.f;
+ scf_int[n * 4 + 5] = scf[n] + 7.f * ( scf[n + 1] - scf[n] ) / 8.f;
+ }
+
+ scf_int[FDNS_NPTS - 2] = scf[M - 1] + ( scf[M - 1] - scf[M - 2] ) / 8.f;
+ scf_int[FDNS_NPTS - 1] = scf[M - 1] + 3.f * ( scf[M - 1] - scf[M - 2] ) / 8.f;
+
+ /* Inversion at encoder-side */
+ if ( encoder_side == ENC )
+ {
+ for ( n = 0; n < FDNS_NPTS; n++ )
+ {
+ scf_int[n] = -scf_int[n];
+ }
+ }
+
+ /* Linear domain */
+ for ( n = 0; n < FDNS_NPTS; n++ )
+ {
+ scf_int[n] = powf( 2.f, scf_int[n] );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------
+ * sns_shape_spectrum()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void sns_shape_spectrum(
+ float spectrum[], /* i/o: spectrum to be shaped */
+ const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */
+ const float *scf_int, /* i : already interpolated SNS scalefactors */
+ const int16_t L_frame /* i : frame length */
+)
+{
+ int16_t i, n, k, bw;
+ const uint8_t nBands = pPsychParams->nBands;
+ const uint8_t *bandLengths = pPsychParams->bandLengths;
+
+ if ( bandLengths == NULL )
+ {
+ bw = L_frame / nBands;
+
+ /* Shape spectrum */
+ k = 0;
+ for ( i = 0; i < nBands; ++i )
+ {
+ for ( n = 0; n < bw; ++n, ++k )
+ {
+ spectrum[k] *= scf_int[i];
+ }
+ }
+ }
+ else
+ {
+ /* Shape spectrum */
+ k = 0;
+ for ( i = 0; i < nBands; ++i )
+ {
+ for ( n = 0; n < bandLengths[i]; ++n, ++k )
+ {
+ spectrum[k] *= scf_int[i];
+ }
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..e80dbf42890c77812cc9c7740db25185dd94edd9
--- /dev/null
+++ b/lib_com/ivas_spar_com.c
@@ -0,0 +1,2080 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "math.h"
+#include "options.h"
+#include "ivas_stat_com.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "rom_com.h"
+#include "ivas_rom_com.h"
+#include "cnst.h"
+#include
+#include "wmc_auto.h"
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local constants
+ *------------------------------------------------------------------------------------------*/
+
+#define IVAS_FLT_EPS ( 1e-10F )
+#define IVAS_DBL_EPS ( (double) 1e-20 )
+
+#define IVAS_REMIX_MULT_FAC ( 0.5f )
+
+#define IVAS_ACTIVEW_DM_F ( 1.0f )
+#define IVAS_ACTIVEW_DM_F_DTX ( 0.25f )
+#define IVAS_ACTIVEW_DM_F_VLBR ( 0.25f )
+#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH ( 3.0f )
+
+#define IVAS_P_NORM_SCALING ( 1.0f )
+#define IVAS_P_NORM_SCALING_DTX ( 0.75f )
+
+#define IVAS_MAT_DIM_3 ( 3 )
+#define IVAS_MAT_DIM_2 ( 2 )
+#define IVAS_MAT_DIM_1 ( 1 )
+#define MAX_MAT_DIM ( FOA_CHANNELS - 1 )
+
+/*------------------------------------------------------------------------------------------*
+ * Static functions declaration
+ *------------------------------------------------------------------------------------------*/
+
+
+static void ivas_get_pred_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t start_band, const int16_t end_band, const int16_t active_w, const int16_t active_w_vlbr, const int16_t dtx_vad, const int16_t from_dirac, const int16_t dyn_active_w_flag, const int16_t res_ind );
+
+static void ivas_reorder_array( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t order[IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t start_band, const int16_t end_band );
+
+static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t num_ch, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, const int16_t active_w_vlbr, float *pWscale, const int16_t dyn_active_w_flag );
+
+static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t num_ch, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] );
+
+static int16_t ivas_is_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim );
+
+static void ivas_calc_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim, float out_re[MAX_MAT_DIM][MAX_MAT_DIM] );
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_bw_idx_from_sample_rate()
+ *
+ * Get bwidth index from sample rate.
+ *-----------------------------------------------------------------------------------------*/
+
+/*! r: audio BW index */
+int16_t ivas_get_bw_idx_from_sample_rate(
+ const int32_t sampling_rate /* i : sampling rate */
+)
+{
+ int16_t bwidth = 0;
+
+ switch ( sampling_rate )
+ {
+ case 16000:
+ bwidth = WB;
+ break;
+ case 32000:
+ bwidth = SWB;
+ break;
+ case 48000:
+ bwidth = FB;
+ break;
+ default:
+ assert( !"Unsupported sample rate!" );
+ }
+
+ return bwidth;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_spar_config()
+ *
+ * SPAR configuration function
+ *------------------------------------------------------------------------*/
+
+void ivas_spar_config(
+ int32_t ivas_total_brate, /* i : codec total bitrate */
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ int16_t *nchan_transport, /* o : number of transport channels */
+ int16_t *nSCE, /* o : number of SCEs */
+ int16_t *nCPE, /* o : number of CPEs */
+ int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */
+ const int16_t sid_format /* i : IVAS format indicator from SID frame */
+)
+{
+ if ( ivas_total_brate == IVAS_SID_5k2 )
+ {
+ if ( sid_format == SID_SBA_1TC )
+ {
+ *nchan_transport = 1;
+ }
+ else
+ {
+ *nchan_transport = 2;
+ }
+ }
+ else
+ {
+ *nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_order );
+ }
+
+ *nCPE = ( *nchan_transport > 1 ) ? ( *nchan_transport + 1 ) >> 1 : 0;
+ *nSCE = max( 0, *nchan_transport - ( *nCPE << 1 ) );
+
+ if ( *nchan_transport == 1 )
+ {
+ /* map SPAR SID bitrate to SPAR active bitrate */
+ if ( ivas_total_brate == IVAS_SID_5k2 )
+ {
+ ivas_total_brate = IVAS_32k;
+ }
+ assert( ivas_total_brate == IVAS_32k || ivas_total_brate == IVAS_24k4 || ivas_total_brate == IVAS_16k4 || ivas_total_brate == IVAS_13k2 );
+ if ( ivas_total_brate == IVAS_32k )
+ {
+ *core_nominal_brate = ACELP_24k40;
+ }
+ else if ( ivas_total_brate == IVAS_24k4 )
+ {
+ *core_nominal_brate = ACELP_16k40;
+ }
+ else if ( ivas_total_brate == IVAS_16k4 )
+ {
+ *core_nominal_brate = ACELP_13k20;
+ }
+ else if ( ivas_total_brate == IVAS_13k2 )
+ {
+ *core_nominal_brate = ACELP_9k60;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_spar_table_idx()
+ *
+ * Get SPAR table index
+ *-----------------------------------------------------------------------------------------*/
+
+/*! r: config. table index */
+int16_t ivas_get_spar_table_idx(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int16_t bwidth, /* i : audio bandwidth */
+ int16_t *bitlen, /* o : number of bits */
+ int16_t *ind /* o : indice */
+)
+{
+ int16_t table_idx = 0, ind1[IVAS_SPAR_BR_TABLE_LEN];
+ int16_t i, j = 0, ind2 = -1;
+
+ for ( i = 0; i < IVAS_SPAR_BR_TABLE_LEN; i++ )
+ {
+ ind1[j] = 0;
+ if ( ( ivas_spar_br_table_consts[i].ivas_total_brate == ivas_total_brate ) &&
+ ( ivas_spar_br_table_consts[i].sba_order == sba_order ) )
+ {
+ ind1[j++] = i;
+ }
+ }
+
+ for ( i = 0; i < j; i++ )
+ {
+ if ( ivas_spar_br_table_consts[ind1[i]].bwidth == bwidth )
+ {
+ ind2 = i;
+ break;
+ }
+ }
+ assert( j > 0 ); /* to check if bitrate entry is present */
+ assert( ind2 >= 0 ); /* to check if bw entry is present */
+
+ table_idx = ind1[ind2];
+
+ if ( ind != NULL )
+ {
+ *ind = ind2;
+ }
+
+ if ( bitlen != NULL )
+ {
+ *bitlen = ivas_get_bits_to_encode( j - 1 );
+ }
+
+ return table_idx;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_get_sba_num_TCs()
+ *
+ * Return number of TCs in SBA format
+ *-------------------------------------------------------------------*/
+
+/*! r: number of transport channels */
+int16_t ivas_get_sba_num_TCs(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order /* i : Ambisonic (SBA) order */
+)
+{
+ int16_t table_idx, nchan_transport;
+
+ table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL );
+
+ nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport;
+
+ return nchan_transport;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_pred_coeffs()
+ *
+ * Calculation of prediction coefficients
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_get_pred_coeffs(
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ float ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ float ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ const int16_t in_chans,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t active_w,
+ const int16_t active_w_vlbr,
+ const int16_t dtx_vad,
+ const int16_t from_dirac,
+ const int16_t dyn_active_w_flag,
+ const int16_t res_ind )
+{
+ int16_t i, j, k, b;
+ float abs_value;
+ float w_norm_fac;
+ float div_factor[IVAS_MAX_NUM_BANDS];
+ int16_t pred_dim = in_chans - 1;
+
+ w_norm_fac = ( from_dirac == 1 ) ? 1.0f : 3.0f;
+
+ if ( active_w == 0 )
+ {
+ float pPred_temp[IVAS_MAX_NUM_BANDS];
+
+ set_zero( pPred_temp, IVAS_MAX_NUM_BANDS );
+ for ( k = start_band; k < end_band; k++ )
+ {
+ div_factor[k] = max( 1e-20f, cov_real[0][0][k] );
+ div_factor[k] = 1 / div_factor[k];
+ }
+
+ for ( i = 0; i < pred_dim; i++ )
+ {
+ for ( k = start_band; k < end_band; k++ )
+ {
+ ppPred_coeffs_re[i][k] = cov_real[i + 1][0][k] * div_factor[k];
+
+ IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value );
+
+ pPred_temp[k] += abs_value;
+ }
+ }
+
+ for ( k = start_band; k < end_band; k++ )
+ {
+ pPred_temp[k] = sqrtf( pPred_temp[k] );
+ div_factor[k] = max( 1.0f, pPred_temp[k] );
+ div_factor[k] = 1 / div_factor[k];
+ }
+
+ for ( i = 0; i < pred_dim; i++ )
+ {
+ for ( k = start_band; k < end_band; k++ )
+ {
+ ppPred_coeffs_re[i][k] = ppPred_coeffs_re[i][k] * div_factor[k];
+ ppDM_Fv_re[i][k] = 0;
+ }
+ }
+ }
+ else
+ {
+ float dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS];
+ float real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS];
+ float dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS];
+ float num_f, den_f, passive_g;
+ float activew_quad_thresh, g_th_sq;
+
+ if ( dyn_active_w_flag == 1 )
+ {
+ activew_quad_thresh = 1.0f;
+ }
+ else
+ {
+ activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH;
+ }
+ g_th_sq = activew_quad_thresh * activew_quad_thresh;
+
+ set_zero( dm_alpha, IVAS_MAX_NUM_BANDS );
+
+ for ( i = 1; i < in_chans; i++ )
+ {
+ for ( k = start_band; k < end_band; k++ )
+ {
+ IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value );
+ dm_alpha[k] += abs_value;
+ }
+ }
+
+ for ( k = start_band; k < end_band; k++ )
+ {
+ dm_alpha[k] = sqrtf( dm_alpha[k] );
+ div_factor[k] = max( dm_alpha[k], 1e-20f );
+ div_factor[k] = 1 / div_factor[k];
+ }
+
+ for ( i = 0; i < pred_dim; i++ )
+ {
+ for ( k = start_band; k < end_band; k++ )
+ {
+ dm_v_re[i][k] = cov_real[i + 1][0][k] * div_factor[k];
+ }
+ }
+
+ if ( dtx_vad == 0 )
+ {
+ dm_f_local = IVAS_ACTIVEW_DM_F_DTX;
+ }
+ else
+ {
+ dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_VLBR : IVAS_ACTIVEW_DM_F;
+ }
+
+ for ( b = start_band; b < end_band; b++ )
+ {
+ set_zero( real, pred_dim );
+
+ for ( j = 0; j < pred_dim; j++ )
+ {
+ for ( k = 1; k < in_chans; k++ )
+ {
+ float re;
+
+ IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re );
+ real[j] += re;
+ }
+ }
+ dm_beta_re = 0;
+ for ( k = 0; k < pred_dim; k++ )
+ {
+ float re;
+ IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re );
+ dm_beta_re += re;
+ }
+
+ dm_w = cov_real[0][0][b];
+ den_f = max( dm_w, 1e-20f );
+ passive_g = dm_alpha[b] / den_f;
+
+ if ( dyn_active_w_flag == 1 )
+ {
+ dm_alpha[b] = 0.0f;
+ dm_w = 0.0f;
+ for ( i = 0; i < pred_dim; i++ )
+ {
+ dm_v_re[i][b] = 0.0f;
+ }
+ dm_v_re[res_ind - 1][b] = 1.0f;
+ passive_g = activew_quad_thresh;
+ }
+
+ if ( passive_g < activew_quad_thresh )
+ {
+ /*linear activeW*/
+ dm_y = 0;
+
+ for ( k = 1; k < in_chans; k++ )
+ {
+ dm_y += cov_real[k][k][b];
+ }
+ den_f = max( dm_y, 1e-20f );
+ den_f = max( den_f, w_norm_fac * dm_w );
+ DM_F[b] = ( dm_f_local * dm_alpha[b] ) / den_f;
+ DM_F[b] = min( 1.0f, DM_F[b] );
+
+ den_f = dm_w + ( 2 * dm_alpha[b] * DM_F[b] ) + ( DM_F[b] * DM_F[b] * dm_beta_re );
+ den_f = max( den_f, 1e-20f );
+
+ dm_g[b] = ( dm_alpha[b] + ( DM_F[b] * dm_beta_re ) ) / den_f;
+ }
+ else
+ {
+ float sqrt_val;
+
+ /* quadratic activeW */
+
+ num_f = ( dm_beta_re - ( 2 * dm_alpha[b] * activew_quad_thresh ) );
+
+ sqrt_val = 4 * dm_alpha[b] * dm_alpha[b] * g_th_sq;
+ sqrt_val += dm_beta_re * dm_beta_re;
+ sqrt_val -= 4 * dm_beta_re * g_th_sq * dm_w;
+ sqrt_val = sqrtf( sqrt_val );
+ num_f += sqrt_val;
+
+ den_f = 2 * dm_beta_re * g_th_sq;
+ den_f = max( den_f, 1e-20f );
+ dm_g[b] = activew_quad_thresh;
+ DM_F[b] = ( dm_g[b] * num_f ) / den_f;
+ }
+ }
+
+ for ( i = 0; i < pred_dim; i++ )
+ {
+ for ( b = start_band; b < end_band; b++ )
+ {
+ ppPred_coeffs_re[i][b] = dm_v_re[i][b] * dm_g[b];
+
+ ppDM_Fv_re[i][b] = dm_v_re[i][b] * DM_F[b];
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_Wscaling_factor()
+ *
+ * Calculation of scaling factor for post predicted W channel
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_get_Wscaling_factor(
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ float ***mixer_mat,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t dtx_vad,
+ const int16_t num_ch,
+ const int16_t *pNum_dmx,
+ const int16_t bands_bw,
+ const int16_t active_w,
+ const int16_t active_w_vlbr,
+ float *pWscale,
+ const int16_t dyn_active_w_flag )
+{
+ int16_t b, ch;
+ float dm_f_local, abs_val;
+ float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
+
+ for ( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ )
+ {
+ set_zero( postpred_cov_re[ch], IVAS_SPAR_MAX_CH );
+ }
+
+ if ( dtx_vad == 0 )
+ {
+ dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX;
+ }
+ else
+ {
+ dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE;
+ }
+
+ for ( b = start_band; b < end_band; b++ )
+ {
+ pWscale[b] = 1;
+
+ if ( ( active_w == 1 ) && ( dyn_active_w_flag == 0 ) )
+ {
+ float Gw_sq, g_sq = 0;
+
+ if ( num_ch != pNum_dmx[b * bands_bw] )
+ {
+ ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, b, postpred_cov_re );
+ }
+
+ Gw_sq = cov_real[0][0][b] / max( postpred_cov_re[0][0], IVAS_FLT_EPS );
+
+ for ( ch = 0; ch < num_ch - 1; ch++ )
+ {
+ IVAS_CALCULATE_SQ_ABS_N( pred_coeffs_re[ch][b], abs_val );
+
+ g_sq += abs_val;
+ }
+
+ pWscale[b] = sqrtf( Gw_sq );
+ pWscale[b] = pWscale[b] + sqrtf( Gw_sq + ( 4 * dm_f_local * g_sq ) );
+ pWscale[b] *= 0.5f;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_create_fullr_dmx_mat()
+ *
+ * Calculation of downmix matrix
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_create_fullr_dmx_mat(
+ float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ float ***mixer_mat,
+ const int16_t in_chans,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t active_w,
+ ivas_spar_md_com_cfg *hMdCfg )
+{
+ int16_t i, j, k, b;
+ const int16_t *order;
+ float tmp_p1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
+ float tmp_p2_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
+ float down_mix_mat1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
+ int16_t remix_unmix_order;
+ int16_t nbands;
+ nbands = end_band - start_band;
+ remix_unmix_order = hMdCfg->remix_unmix_order;
+
+ order = remix_order_set[remix_unmix_order];
+
+ for ( i = 0; i < in_chans; i++ )
+ {
+ for ( j = 0; j < in_chans; j++ )
+ {
+ set_zero( &tmp_p1_re[i][j][start_band], nbands );
+ set_zero( &tmp_p2_re[i][j][start_band], nbands );
+ set_zero( &down_mix_mat1_re[i][j][start_band], nbands );
+ }
+ }
+
+ for ( j = 0; j < in_chans; j++ )
+ {
+ for ( b = start_band; b < end_band; b++ )
+ {
+ tmp_p2_re[j][j][b] = 1.0f;
+ }
+ }
+
+ for ( j = 1; j < in_chans; j++ )
+ {
+ for ( b = start_band; b < end_band; b++ )
+ {
+ tmp_p2_re[j][0][b] = -pred_coeffs_re[j - 1][b];
+ }
+ }
+
+ if ( active_w == 1 )
+ {
+ for ( j = 0; j < in_chans; j++ )
+ {
+ for ( b = start_band; b < end_band; b++ )
+ {
+ tmp_p1_re[j][j][b] = 1.0f;
+ }
+ }
+
+ for ( j = 1; j < in_chans; j++ )
+ {
+ for ( b = start_band; b < end_band; b++ )
+ {
+ tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b];
+ }
+ }
+
+ /* 4x4 mult */
+ for ( i = 0; i < in_chans; i++ )
+ {
+ for ( j = 0; j < in_chans; j++ )
+ {
+ for ( k = 0; k < in_chans; k++ )
+ {
+ for ( b = start_band; b < end_band; b++ )
+ {
+ float tmp_re;
+ IVAS_RMULT_FLOAT( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b], tmp_re );
+ down_mix_mat1_re[i][j][b] += tmp_re;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ for ( j = 0; j < in_chans; j++ )
+ {
+ for ( k = 0; k < in_chans; k++ )
+ {
+ for ( b = start_band; b < end_band; b++ )
+ {
+ down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b];
+ }
+ }
+ }
+ }
+
+ if ( remix_unmix_order != 3 )
+ {
+ ivas_reorder_array( down_mix_mat1_re, in_chans, order, mixer_mat, start_band, end_band );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_reorder_array()
+ *
+ * reorders the input matrix based on order
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_reorder_array(
+ float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS],
+ const int16_t in_chans,
+ const int16_t order[IVAS_SPAR_MAX_CH],
+ float ***mixer_mat,
+ const int16_t start_band,
+ const int16_t end_band )
+{
+ int16_t i, j, b, idx;
+
+ for ( i = 0; i < in_chans; i++ )
+ {
+ idx = order[i];
+
+ for ( j = 0; j < in_chans; j++ )
+ {
+ for ( b = start_band; b < end_band; b++ )
+ {
+ mixer_mat[i][j][b] = in_re[idx][j][b];
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calc_post_pred_per_band()
+ *
+ * Calculate post pred mat per band
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_calc_post_pred_per_band(
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ float ***mixer_mat,
+ const int16_t num_ch,
+ const int16_t band_idx,
+ float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] )
+{
+ int16_t i, j, k;
+ float dmx_mat_conj[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
+ float temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
+ float tmp_re;
+
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx];
+ }
+ }
+
+ for ( i = 0; i < num_ch; i++ )
+ {
+ set_zero( postpred_cov_re[i], num_ch );
+ }
+
+ /* num_ch x num_ch mult */
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ temp_mat[i][j] = 0;
+ for ( k = 0; k < num_ch; k++ )
+ {
+ IVAS_RMULT_FLOAT( cov_real[i][k][band_idx], dmx_mat_conj[k][j], tmp_re );
+ temp_mat[i][j] += tmp_re;
+ }
+ }
+ }
+
+ /* num_ch x num_ch mult */
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = i; j < num_ch; j++ )
+ {
+ for ( k = 0; k < num_ch; k++ )
+ {
+ IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re );
+ postpred_cov_re[i][j] += tmp_re;
+ }
+ }
+ }
+
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = 0; j < i; j++ )
+ {
+ postpred_cov_re[i][j] = postpred_cov_re[j][i];
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calc_p_coeffs_per_band()
+ *
+ * Calculate P coeffs per band
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_calc_p_coeffs_per_band(
+ ivas_spar_md_t *pSparMd,
+ const int16_t i_ts,
+ float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ const int16_t num_ch,
+ const int16_t dtx_vad,
+ const int16_t num_dmx,
+ const int16_t band_idx )
+{
+ int16_t i, j, k;
+ int16_t m;
+ float factor = 0;
+ float recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS];
+ float trace = 0;
+ float p_norm_scaling = 0;
+ float cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1];
+ float cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1];
+ int16_t b_ts_idx;
+
+ b_ts_idx = band_idx + i_ts * IVAS_MAX_NUM_BANDS;
+
+ if ( num_dmx != num_ch )
+ {
+ set_zero( pSparMd->band_coeffs[b_ts_idx].P_re, IVAS_SPAR_MAX_CH - 1 );
+ for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ )
+ {
+ set_zero( recon_uu_re[i], IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS );
+ }
+
+ for ( i = num_dmx; i < num_ch; i++ )
+ {
+ for ( j = num_dmx; j < num_ch; j++ )
+ {
+ cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j];
+ }
+ }
+
+ if ( dtx_vad == 1 )
+ {
+ for ( i = 1; i < num_dmx; i++ )
+ {
+ for ( j = 1; j < num_dmx; j++ )
+ {
+ cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j];
+ }
+ }
+
+ if ( num_dmx == 2 )
+ {
+ float re1, re2;
+
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 );
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 );
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] );
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] );
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] );
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] );
+
+ for ( i = 0; i < 2; i++ )
+ {
+ for ( j = 0; j < 2; j++ )
+ {
+ cov_uu_re[i][j] -= recon_uu_re[i][j];
+ }
+ }
+ }
+ else if ( num_dmx == 3 )
+ {
+ float re1[2], re2;
+ set_f( re1, 0, 2 );
+
+ for ( j = 0; j < 2; j++ )
+ {
+ for ( k = 0; k < 2; k++ )
+ {
+ float re;
+
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re );
+ re1[j] += re;
+ }
+ }
+
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 );
+ recon_uu_re[0][0] = re2;
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 );
+ recon_uu_re[0][0] += re2;
+
+ cov_uu_re[0][0] -= recon_uu_re[0][0];
+ }
+ else if ( num_dmx == 4 )
+ {
+ /* Step 1: Multiply C * cov_dd * C' */
+ float re1[3], re;
+
+ for ( i = 0; i < num_ch - num_dmx; i++ )
+ {
+ set_f( re1, 0, 3 );
+ for ( m = 0; m < num_dmx - 1; m++ )
+ {
+ for ( k = 0; k < num_dmx - 1; k++ )
+ {
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re );
+ re1[m] += re;
+ }
+ }
+ for ( j = 0; j < num_ch - num_dmx; j++ )
+ {
+ for ( m = 0; m < num_dmx - 1; m++ )
+ {
+ IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re );
+ recon_uu_re[i][j] += re;
+ }
+ }
+ }
+
+ /* Step 2: cov_uu - recon_uu */
+ for ( i = 0; i < num_ch - num_dmx; i++ )
+ {
+ for ( j = 0; j < num_ch - num_dmx; j++ )
+ {
+ cov_uu_re[i][j] -= recon_uu_re[i][j];
+ }
+ }
+ }
+ }
+
+ p_norm_scaling = IVAS_P_NORM_SCALING;
+
+ if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) )
+ {
+ p_norm_scaling = IVAS_P_NORM_SCALING_DTX;
+ }
+
+ trace = 0.0f;
+
+ for ( i = num_dmx; i < num_ch; i++ )
+ {
+ float tmp_out;
+ IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out );
+ trace += tmp_out;
+ }
+
+ factor = max( 1e-20f, postpred_cov_re[0][0] );
+ factor = max( factor, ( p_norm_scaling * trace ) );
+ factor = 1 / factor;
+
+ /* normalise Hermitian (except for rounding) cov_uu */
+ for ( i = num_dmx; i < num_ch; i++ )
+ {
+ for ( j = num_dmx; j < num_ch; j++ )
+ {
+ if ( i == j )
+ {
+ /* force diagonal to be real */
+ cov_uu_re[i - num_dmx][j - num_dmx] *= factor;
+ }
+ else
+ {
+ /* set off-diag elements to zero */
+ cov_uu_re[i - num_dmx][j - num_dmx] = 0;
+ }
+ }
+ }
+
+ /* take sqrt of max of diags and zero */
+ for ( i = num_dmx; i < num_ch; i++ )
+ {
+ cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) );
+ /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */
+ }
+
+ /* save into MD struct */
+ for ( i = num_dmx; i < num_ch; i++ )
+ {
+ for ( j = num_dmx; j < num_ch; j++ )
+ {
+ if ( i == j )
+ {
+ pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx];
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calc_c_coeffs_per_band()
+ *
+ * Calculate C coeffs per band
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_calc_c_coeffs_per_band(
+ ivas_spar_md_t *pSparMd,
+ const int16_t i_ts,
+ float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ const int16_t num_ch,
+ const int16_t num_dmx,
+ const int16_t band_idx,
+ const int16_t dtx_vad )
+{
+ int16_t i, j, k;
+
+ /* worst case for cov_ud is actually 12 x 3 */
+ float cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1];
+ float cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1];
+ float cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1];
+ float trace_cov_dd_re = 0;
+ float abs_trace;
+ float re;
+ int16_t b_ts_idx;
+
+ b_ts_idx = band_idx + i_ts * IVAS_MAX_NUM_BANDS;
+
+ if ( dtx_vad == 0 )
+ {
+ set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
+ return;
+ }
+
+ for ( i = num_dmx; i < num_ch; i++ )
+ {
+ for ( j = 1; j < num_dmx; j++ )
+ {
+ cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j];
+ }
+ }
+
+ for ( i = 1; i < num_dmx; i++ )
+ {
+ for ( j = 1; j < num_dmx; j++ )
+ {
+ cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j];
+ }
+ }
+
+ for ( i = 0; i < num_dmx - 1; i++ )
+ {
+ trace_cov_dd_re += cov_dd_re[i][i];
+ }
+ trace_cov_dd_re *= 0.005f;
+
+ IVAS_CALCULATE_RABS( trace_cov_dd_re, abs_trace );
+
+ if ( abs_trace < IVAS_FLT_EPS )
+ {
+ /* protection from cases when variance of residual channels is very small */
+ set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
+ }
+ else
+ {
+ for ( i = 0; i < num_dmx - 1; i++ )
+ {
+ cov_dd_re[i][i] += trace_cov_dd_re;
+ }
+ if ( ivas_is_mat_inv( cov_dd_re, num_dmx - 1 ) && ( num_dmx < FOA_CHANNELS ) )
+ {
+ set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
+ }
+ else
+ {
+ ivas_calc_mat_inv( cov_dd_re, num_dmx - 1, cov_dd_re_inv );
+
+ for ( i = 0; i < num_ch - num_dmx; i++ )
+ {
+ for ( j = 0; j < num_dmx - 1; j++ )
+ {
+ pSparMd->band_coeffs[b_ts_idx].C_re[i][j] = 0;
+ for ( k = 0; k < num_dmx - 1; k++ )
+ {
+ IVAS_RMULT_FLOAT( cov_ud_re[i][k], cov_dd_re_inv[k][j], re );
+ pSparMd->band_coeffs[b_ts_idx].C_re[i][j] += re;
+ }
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calc_c_p_coeffs()
+ *
+ * Calculation of C and P coeffs
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_calc_c_p_coeffs(
+ ivas_spar_md_t *pSparMd,
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ const int16_t i_ts,
+ float ***mixer_mat,
+ const int16_t num_ch,
+ const int16_t num_dmx,
+ const int16_t band_idx,
+ const int16_t dtx_vad,
+ const int16_t compute_p_flag,
+ const int16_t dyn_active_w_flag )
+{
+ int16_t i, j;
+ float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
+
+ if ( num_dmx != num_ch )
+ {
+ ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, band_idx, postpred_cov_re );
+
+ if ( num_dmx != 1 )
+ {
+ ivas_calc_c_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad );
+ }
+
+ if ( dyn_active_w_flag )
+ {
+ for ( i = 0; i < num_ch - num_dmx; i++ )
+ {
+ for ( j = 0; j < num_dmx - 1; j++ )
+ {
+ pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re[i][j] = 0.0f;
+ }
+ }
+ }
+ if ( compute_p_flag == 1 )
+ {
+ ivas_calc_p_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx );
+ }
+
+ if ( dyn_active_w_flag )
+ {
+ for ( i = num_dmx; i < num_ch; i++ )
+ {
+ pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re[i - num_dmx] = 0;
+ }
+ }
+ }
+
+ return;
+}
+
+
+static void ivas_calc_mat_det(
+ double in_re[MAX_MAT_DIM][MAX_MAT_DIM],
+ const int16_t dim,
+ double *det_re )
+{
+ if ( dim == IVAS_MAT_DIM_3 )
+ {
+ double re1, re2, re;
+ IVAS_RMULT_DOUBLE( in_re[1][1], in_re[2][2], re1 );
+ IVAS_RMULT_DOUBLE( in_re[1][2], in_re[2][1], re2 );
+ re = re1 - re2;
+
+ IVAS_RMULT_DOUBLE( in_re[0][0], re, re1 );
+
+ *det_re = re1;
+
+ IVAS_RMULT_DOUBLE( in_re[1][0], in_re[2][2], re1 );
+ IVAS_RMULT_DOUBLE( in_re[1][2], in_re[2][0], re2 );
+ re = re1 - re2;
+
+ IVAS_RMULT_DOUBLE( in_re[0][1], re, re1 );
+
+ *det_re -= re1;
+
+ IVAS_RMULT_DOUBLE( in_re[1][0], in_re[2][1], re1 );
+ IVAS_RMULT_DOUBLE( in_re[1][1], in_re[2][0], re2 );
+ re = re1 - re2;
+
+ IVAS_RMULT_DOUBLE( in_re[0][2], re, re1 );
+
+ *det_re += re1;
+ }
+ else if ( dim == IVAS_MAT_DIM_2 )
+ {
+ double re1, re2;
+ IVAS_RMULT_DOUBLE( in_re[0][0], in_re[1][1], re1 );
+ IVAS_RMULT_DOUBLE( in_re[0][1], in_re[1][0], re2 );
+ *det_re = re1 - re2;
+ }
+ else if ( dim == IVAS_MAT_DIM_1 )
+ {
+ *det_re = in_re[0][0];
+ }
+ else
+ {
+ assert( !"matrix dimention not supported!" );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_mat_cofactor()
+ *
+ * Calculate cofactor for invert matrix
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_get_mat_cofactor(
+ double in_re[MAX_MAT_DIM][MAX_MAT_DIM],
+ double out_re[MAX_MAT_DIM][MAX_MAT_DIM],
+ const int16_t row,
+ const int16_t col )
+{
+ int16_t i, j;
+ int16_t r = 0, c = 0;
+
+ for ( i = 0; i < MAX_MAT_DIM; i++ )
+ {
+ for ( j = 0; j < MAX_MAT_DIM; j++ )
+ {
+ if ( i != row && j != col )
+ {
+
+ out_re[r][c++] = in_re[i][j];
+ }
+ }
+ if ( c == 2 )
+ {
+ r++;
+ c = 0;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calc_mat_inv()
+ *
+ * Calculate Invert of a matrix
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_calc_mat_inv(
+ float in_re[MAX_MAT_DIM][MAX_MAT_DIM],
+ const int16_t dim,
+ float out_re[MAX_MAT_DIM][MAX_MAT_DIM] )
+{
+ double det;
+ int16_t i, j;
+ double dbl_in_re[MAX_MAT_DIM][MAX_MAT_DIM];
+ double dbl_out_re[MAX_MAT_DIM][MAX_MAT_DIM];
+
+ for ( i = 0; i < dim; i++ )
+ {
+ for ( j = 0; j < dim; j++ )
+ {
+ dbl_in_re[i][j] = in_re[i][j];
+ }
+ }
+
+ if ( dim == IVAS_MAT_DIM_1 )
+ {
+ det = ( dbl_in_re[0][0] * dbl_in_re[0][0] );
+ /* assert to catch cases when input is singular matrix*/
+ assert( det > 0 );
+ det = 1 / det;
+ dbl_out_re[0][0] = dbl_in_re[0][0] * det;
+ }
+ else if ( dim == IVAS_MAT_DIM_2 )
+ {
+ double det_re;
+ double re;
+
+ ivas_calc_mat_det( dbl_in_re, dim, &det_re );
+ det = ( det_re * det_re );
+ /* assert to catch cases when input is singular matrix*/
+ assert( det > 0 );
+ det = 1 / det;
+
+ IVAS_RMULT_DOUBLE( det_re, dbl_in_re[1][1], re );
+ dbl_out_re[0][0] = re * det;
+
+ IVAS_RMULT_DOUBLE( det_re, dbl_in_re[0][1], re );
+ dbl_out_re[0][1] = -re * det;
+
+ IVAS_RMULT_DOUBLE( det_re, dbl_in_re[1][0], re );
+ dbl_out_re[1][0] = -re * det;
+
+ IVAS_RMULT_DOUBLE( det_re, dbl_in_re[0][0], re );
+ dbl_out_re[1][1] = re * det;
+ }
+ else if ( dim == IVAS_MAT_DIM_3 )
+ {
+ double fac_re[IVAS_MAT_DIM_3][IVAS_MAT_DIM_3];
+ double det_re;
+ int16_t sign = 1;
+
+ ivas_calc_mat_det( dbl_in_re, dim, &det_re );
+ det = det_re > 0 ? 1 / max( IVAS_DBL_EPS, det_re ) : min( det_re, -IVAS_DBL_EPS );
+
+ for ( i = 0; i < dim; i++ )
+ {
+ for ( j = 0; j < dim; j++ )
+ {
+ ivas_get_mat_cofactor( dbl_in_re, fac_re, i, j );
+ ivas_calc_mat_det( fac_re, IVAS_MAT_DIM_2, &dbl_out_re[j][i] );
+ dbl_out_re[j][i] = dbl_out_re[j][i] * det * sign;
+
+ if ( ( ( i + j ) & 1 ) == 0 )
+ {
+ sign = -1;
+ }
+ else
+ {
+ sign = 1;
+ }
+ }
+ }
+ }
+ else
+ {
+ assert( !"matrix dimension not supported!" );
+ }
+
+ for ( i = 0; i < dim; i++ )
+ {
+ for ( j = 0; j < dim; j++ )
+ {
+ out_re[i][j] = (float) dbl_out_re[i][j];
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_is_mat_inv()
+ *
+ * Check if matrix is invertible or not by checking if determinant is 0 or very close to 0
+ *-----------------------------------------------------------------------------------------*/
+
+static int16_t ivas_is_mat_inv(
+ float in_re[MAX_MAT_DIM][MAX_MAT_DIM],
+ const int16_t dim )
+{
+ int16_t is_det_zero = 0;
+ double det, det_re;
+ int16_t i, j;
+ double dbl_in_re[MAX_MAT_DIM][MAX_MAT_DIM];
+
+ for ( i = 0; i < dim; i++ )
+ {
+ for ( j = 0; j < dim; j++ )
+ {
+ dbl_in_re[i][j] = in_re[i][j];
+ }
+ }
+
+ ivas_calc_mat_det( dbl_in_re, dim, &det_re );
+
+ det = ( det_re * det_re );
+
+ if ( det < IVAS_DBL_EPS )
+ {
+ is_det_zero = 1;
+ }
+
+ return is_det_zero;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_compute_spar_params()
+ *
+ *
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_compute_spar_params(
+ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
+ float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS],
+ const int16_t i_ts,
+ float ***mixer_mat,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t dtx_vad,
+ const int16_t num_ch,
+ const int16_t bands_bw,
+ const int16_t active_w,
+ const int16_t active_w_vlbr,
+ ivas_spar_md_com_cfg *hSparCfg,
+ ivas_spar_md_t *hSparMd,
+ float *pWscale,
+ const int16_t from_dirac,
+ const int16_t dyn_active_w_flag )
+{
+ float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS];
+ int16_t b, i, ndm;
+
+ ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, active_w_vlbr, dtx_vad, from_dirac, dyn_active_w_flag, hSparMd->res_ind );
+
+ ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg );
+
+ ivas_get_Wscaling_factor( cov_real, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale, dyn_active_w_flag );
+
+ for ( b = start_band; b < end_band; b++ )
+ {
+ float onebyscale = 1.0f / pWscale[b];
+ for ( i = 0; i < num_ch - 1; i++ )
+ {
+ hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[i] = pred_coeffs_re[i][b] * onebyscale;
+ }
+
+ for ( i = 0; i < num_ch; i++ )
+ {
+ mixer_mat[0][i][b] *= pWscale[b];
+ }
+ }
+
+ for ( b = start_band; b < end_band; b++ )
+ {
+ ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw];
+
+ if ( ndm != num_ch )
+ {
+ ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag );
+
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_spar_md_from_dirac()
+ *
+ *
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_get_spar_md_from_dirac(
+ float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES],
+ float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES],
+ float diffuseness[IVAS_MAX_NUM_BANDS],
+ const int16_t n_ts,
+ float ***mixer_mat,
+ ivas_spar_md_t *hSpar_md,
+ ivas_spar_md_com_cfg *hSpar_md_cfg,
+ const int16_t start_band,
+ const int16_t end_band,
+ const int16_t order,
+ const int16_t dtx_vad,
+ float Wscale_d[IVAS_MAX_NUM_BANDS],
+ const uint8_t useLowerRes,
+ const int16_t active_w_vlbr,
+ const int16_t dyn_active_w_flag )
+{
+ int16_t num_ch, band, i, j;
+ int16_t block, ch;
+ float response_avg[MAX_OUTPUT_CHANNELS];
+ float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS];
+ float cov_real_dirac[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
+ float *pCov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
+ float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS];
+ float Wscale[IVAS_MAX_NUM_BANDS];
+ float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS];
+ float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH];
+ float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH];
+ float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3;
+ int16_t active_w;
+
+ int16_t ndm, foa_ch, hoa2_ch;
+ float P_dir_fact[IVAS_SPAR_MAX_CH - 1];
+ const int16_t *remix_order;
+
+ remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order];
+
+ num_ch = ivas_sba_get_nchan_metadata( order, IVAS_256k /*dummy value as order is always 1 in this function*/ );
+
+ hoa2_ch = ivas_sba_get_nchan_metadata( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ );
+
+ foa_ch = FOA_CHANNELS;
+ diff_norm_order1 = 3.0f;
+ diff_norm_order2 = 5.0f;
+ diff_norm_order3 = 7.0f;
+
+ for ( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ )
+ {
+ for ( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ )
+ {
+ pMixer_mat[i][j] = mixer_mat_local[i][j];
+ }
+ ppMixer_mat[i] = pMixer_mat[i];
+ }
+
+ if ( ( start_band >= 6 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) || ( useLowerRes && start_band >= 3 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) )
+ {
+ float P_norm[3];
+ int16_t idx;
+
+ ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1];
+ P_norm[0] = 0.0f;
+ for ( i = 0; i < max( 0, foa_ch - ndm ); i++ )
+ {
+ P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i];
+ }
+ P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) );
+
+ P_norm[1] = 0.0f;
+ for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ )
+ {
+ P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i];
+ }
+ P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) );
+
+ P_norm[2] = 0.0f;
+ for ( ; i < num_ch - ndm; i++ )
+ {
+ P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i];
+ }
+ P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) );
+
+ for ( i = 0; i < max( 0, foa_ch - ndm ); i++ )
+ {
+ idx = remix_order[i + ndm] - ndm;
+ P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i];
+ P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] );
+ }
+ for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ )
+ {
+ idx = remix_order[i + ndm] - ndm;
+ P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i];
+ P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] );
+ }
+ for ( ; i < num_ch - ndm; i++ )
+ {
+ idx = remix_order[i + ndm] - ndm;
+ P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i];
+ P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] );
+ }
+ }
+
+ for ( int16_t i_ts = 0; i_ts < n_ts; i_ts++ )
+ {
+ for ( band = start_band; band < end_band; band++ )
+ {
+ ndm = hSpar_md_cfg->num_dmx_chans_per_band[band];
+
+ /*SPAR from DirAC*/
+ set_f( response_avg, 0.0f, MAX_OUTPUT_CHANNELS );
+
+ if ( n_ts > 1 )
+ {
+ ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order );
+ }
+ else if ( useLowerRes )
+ {
+ ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order );
+ }
+ else
+ {
+ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
+ {
+ ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order );
+ }
+
+ /* average responses in all subframes*/
+ {
+ float norm;
+ int16_t num_ch_order, hoa2_ch_order;
+
+ num_ch_order = ivas_sba_get_nchan( order, 0 );
+ hoa2_ch_order = ivas_sba_get_nchan( SBA_HOA2_ORDER, 0 );
+
+ for ( ch = 0; ch < num_ch_order; ch++ )
+ {
+ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
+ {
+ response_avg[ch] += response[block][ch];
+ }
+ response_avg[ch] /= MAX_PARAM_SPATIAL_SUBFRAMES;
+ }
+
+ /*normalize 1st order*/
+ norm = 0.0f;
+ for ( ch = 1; ch < foa_ch; ch++ )
+ {
+ norm += response_avg[ch] * response_avg[ch];
+ }
+ norm = max( EPSILON, sqrtf( norm ) );
+ for ( ch = 1; ch < foa_ch; ch++ )
+ {
+ response_avg[ch] /= norm;
+ }
+
+ /*normalize 2nd order*/
+ norm = 0.0f;
+ for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ )
+ {
+ norm += response_avg[ch] * response_avg[ch];
+ }
+ norm = max( EPSILON, sqrtf( norm ) );
+ for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ )
+ {
+ response_avg[ch] /= norm;
+ }
+
+ /*normalize 3rd order*/
+ norm = 0.0f;
+ for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ )
+ {
+ norm += response_avg[ch] * response_avg[ch];
+ }
+ norm = max( EPSILON, sqrtf( norm ) );
+ for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ )
+ {
+ response_avg[ch] /= norm;
+ }
+ }
+ }
+
+ for ( i = FOA_CHANNELS + 1; i < num_ch; i++ )
+ {
+ response_avg[i] = response_avg[HOA_keep_ind[i]];
+ }
+
+ en_ratio_fac = ( 1.0f - diffuseness[band] );
+
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ if ( i == j )
+ {
+ if ( i == 0 )
+ {
+ cov_real_dirac[i][i][band] = 1.0f;
+ }
+ else
+ {
+ cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j];
+
+ if ( hSpar_md_cfg->nchan_transport <= 2 )
+ {
+
+ cov_real_dirac[i][j][band] *= en_ratio_fac;
+ if ( ( i >= ndm ) && ( dtx_vad == 1 ) )
+ {
+ cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) * P_dir_fact[i - ndm];
+ }
+ else
+ {
+ if ( i < foa_ch )
+ {
+ cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1;
+ }
+ else if ( i < hoa2_ch )
+ {
+ cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2;
+ }
+ else
+ {
+ cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order3;
+ }
+ }
+ }
+ else
+ {
+ if ( i < foa_ch )
+ {
+ cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1;
+ }
+ else if ( i < hoa2_ch )
+ {
+ cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2;
+ }
+ else
+ {
+ cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order3;
+ }
+ }
+ }
+ }
+ else
+ {
+ cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j];
+ }
+ }
+ }
+ }
+
+ for ( i = 0; i < num_ch; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ pCov_real[i][j] = cov_real_dirac[i][j];
+ }
+ }
+
+
+ active_w = ( dyn_active_w_flag == 1 ) || ( hSpar_md_cfg->active_w == 1 );
+
+ ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag );
+
+ if ( mixer_mat != NULL )
+ {
+ for ( band = start_band; band < end_band; band++ )
+ {
+ ndm = hSpar_md_cfg->num_dmx_chans_per_band[band];
+
+ for ( i = 0; i < ndm; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat[i][j][band];
+ }
+ }
+
+ for ( i = ndm; i < num_ch; i++ )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0.0f;
+ }
+ }
+
+ if ( ( ndm == 1 ) && ( Wscale_d != NULL ) )
+ {
+ for ( j = 0; j < num_ch; j++ )
+ {
+ mixer_mat[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] *= Wscale_d[band];
+ }
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_dec_get_response()
+ *
+ * calculate reponse, 1 degree resolution
+ *------------------------------------------------------------------------*/
+
+void ivas_dirac_dec_get_response(
+ const int16_t azimuth,
+ const int16_t elevation,
+ float *response,
+ const int16_t ambisonics_order )
+{
+ int16_t index_azimuth, index_elevation;
+ int16_t el, e, az;
+ float cos_1, cos_2, sin_1, cos_az[3];
+ float sin_az[3];
+ float f, c;
+ int16_t l, m;
+ int16_t b, b1, b_2, b1_2, a;
+
+ index_azimuth = ( azimuth + 180 ) % 360;
+ index_elevation = elevation + 90;
+ e = index_elevation > 90 ? -1 : 1;
+ el = index_elevation > 90 ? 180 - index_elevation : index_elevation;
+
+ az = index_azimuth > 180 ? 360 - index_azimuth : index_azimuth;
+ f = index_azimuth > 180 ? -1.0f : 1.0f;
+
+ cos_1 = dirac_gains_trg_term[az][0];
+ cos_2 = cos_1 * cos_1;
+ sin_1 = f * dirac_gains_trg_term[az][1];
+ cos_az[0] = cos_1;
+ cos_az[1] = 2.0f * cos_2 - 1.0f;
+ cos_az[2] = 2.0f * cos_1 * cos_az[1] - cos_az[0];
+ sin_az[0] = sin_1;
+ sin_az[1] = sin_1 * 2.0f * cos_1;
+ sin_az[2] = sin_1 * ( 4.0f * cos_2 - 1.0f );
+
+ response[0] = 1.0f;
+ /* Un-optimized code - for reference */
+ /* for( l = 1; l<= ambisonics_order; l++ ) */
+ /* { */
+ /* int16_t b, b1, a; */
+ /* float c; */
+ /* for( m = 0; m < l; m++ ) */
+ /* { */
+ /* b = l*l+m; */
+ /* a = dirac_gains_P_idx[b]; */
+ /* c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */
+
+ /* if( m%2 == 1 ) */
+ /* { */
+ /* c = c*e; */
+ /* } */
+
+ /* response[b] = c * sin_az[l-m-1]; */
+
+ /* b1 = l*l+2*l-m; */
+ /* response[b1] = c * cos_az[l-m-1]; */
+
+ /* } */
+
+ /* b = l*l+l; */
+ /* a = dirac_gains_P_idx[b]; */
+ /* c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */
+ /* if( l%2 == 1) */
+ /* { */
+ /* c = c*e; */
+ /* } */
+
+ /* response[b] = c; */
+ /* } */
+
+ for ( l = 1; l <= ambisonics_order; l++ )
+ {
+ b_2 = l * l;
+ b1_2 = l * l + 2 * l;
+ for ( m = 0; m < l; m += 2 )
+ {
+ b = b_2 + m;
+ a = dirac_gains_P_idx[b];
+ c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a];
+
+ response[b] = c * sin_az[l - m - 1];
+
+ b1 = b1_2 - m;
+ response[b1] = c * cos_az[l - m - 1];
+ }
+
+ for ( m = 1; m < l; m += 2 )
+ {
+ b = b_2 + m;
+ a = dirac_gains_P_idx[b];
+ c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a];
+ c = c * e;
+
+ response[b] = c * sin_az[l - m - 1];
+
+ b1 = b1_2 - m;
+ response[b1] = c * cos_az[l - m - 1];
+ }
+
+ b = b_2 + l;
+ a = dirac_gains_P_idx[b];
+ c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a];
+ if ( l % 2 == 1 )
+ {
+ c = c * e;
+ }
+
+ response[b] = c;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_bits_to_encode
+ *
+ * Get number of bits required to encode the input value
+ *-----------------------------------------------------------------------------------------*/
+
+int16_t ivas_get_bits_to_encode(
+ int32_t val )
+{
+ int16_t bits_req = 0;
+
+ assert( val >= 0 );
+
+ while ( val )
+ {
+ bits_req++;
+ val >>= 1;
+ }
+
+ return bits_req;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_spar_set_bitrate_config()
+ *
+ * Set SPAR bitrate config
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_spar_set_bitrate_config(
+ ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */
+ const int16_t table_idx, /* i : config. table index */
+ const int16_t num_bands, /* i : number of bands */
+ const int16_t dirac2spar_md_flag,
+ const int16_t enc_flag,
+ const int16_t pca_flag,
+ const int16_t agc_flag )
+{
+ int32_t ivas_total_brate;
+ int16_t i, total_bits, max_bits, code, length;
+ int16_t sba_order;
+ int16_t md_coding_bits_header;
+ int16_t agc_bits, pca_bits, num_PR_bits_dirac_bands;
+ int16_t bits_PR, bits_C, bits_P;
+ int16_t wc_coarse_strat;
+ int16_t n_input, n_dmx, n_dec;
+ int16_t quant_strat;
+ int16_t bands_bw;
+
+ pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport;
+
+ for ( i = 0; i < pSpar_md_cfg->nchan_transport; i++ )
+ {
+ pSpar_md_cfg->max_freq_per_chan[i] = ivas_spar_br_table_consts[table_idx].fpcs;
+ }
+
+ pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w;
+ pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx;
+ ivas_spar_get_uniform_quant_strat( pSpar_md_cfg, table_idx );
+
+ pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode( MAX_QUANT_STRATS );
+
+ /* BLOCK: getEntropyCoderModels */
+
+ pSpar_md_cfg->remix_unmix_order = ivas_spar_br_table_consts[table_idx].dmx_str;
+
+ /* bits per block*/
+ total_bits = 0;
+ max_bits = 0;
+
+ ivas_total_brate = ivas_spar_br_table_consts[table_idx].ivas_total_brate;
+ sba_order = ivas_spar_br_table_consts[table_idx].sba_order;
+ ivas_get_spar_table_idx( ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &length, &code );
+
+ for ( i = 0; i < pSpar_md_cfg->nchan_transport; i++ )
+ {
+ total_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] / FRAMES_PER_SEC );
+ max_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][1] / FRAMES_PER_SEC );
+ }
+
+ pSpar_md_cfg->tgt_bits_per_blk = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) - IVAS_FORMAT_SIGNALING_NBITS_EXTENDED - SBA_PLANAR_BITS - SBA_ORDER_BITS - length - total_bits;
+ pSpar_md_cfg->max_bits_per_blk = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) - IVAS_FORMAT_SIGNALING_NBITS_EXTENDED - SBA_PLANAR_BITS - SBA_ORDER_BITS - length - max_bits;
+
+ md_coding_bits_header = SPAR_NUM_CODING_STRAT_BITS + pSpar_md_cfg->quant_strat_bits;
+
+ pSpar_md_cfg->tgt_bits_per_blk -= md_coding_bits_header;
+ pSpar_md_cfg->max_bits_per_blk -= md_coding_bits_header;
+
+ if ( ivas_total_brate < IVAS_24k4 )
+ {
+ bands_bw = 2;
+ }
+ else
+ {
+ bands_bw = 1;
+ }
+
+ pSpar_md_cfg->tgt_bits_per_blk = (int16_t) ceilf( ( 1.0f * pSpar_md_cfg->tgt_bits_per_blk * num_bands ) / IVAS_MAX_NUM_BANDS );
+ pSpar_md_cfg->max_bits_per_blk = (int16_t) ceilf( ( 1.0f * pSpar_md_cfg->max_bits_per_blk * num_bands ) / IVAS_MAX_NUM_BANDS );
+
+ pSpar_md_cfg->tgt_bits_per_blk += md_coding_bits_header;
+ pSpar_md_cfg->max_bits_per_blk += md_coding_bits_header;
+
+ if ( enc_flag )
+ {
+ /*calculate the actual worst case bits*/
+ if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT )
+ {
+ quant_strat = QUANT_STRAT_0;
+ }
+ else
+ {
+ quant_strat = QUANT_STRAT_2;
+ }
+
+ num_PR_bits_dirac_bands = ( dirac2spar_md_flag == 1 ) ? num_bands - SPAR_DIRAC_SPLIT_START_BAND : 0;
+ num_PR_bits_dirac_bands /= bands_bw;
+ num_PR_bits_dirac_bands = max( 0, num_PR_bits_dirac_bands );
+ num_PR_bits_dirac_bands *= DIRAC_TO_SPAR_HBR_PRED_CHS;
+
+ n_input = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate );
+ n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport;
+ n_dec = n_input - n_dmx;
+ bits_PR = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx].q_lvls[quant_strat][0] ) );
+ num_PR_bits_dirac_bands *= bits_PR;
+ bits_PR = bits_PR * ( n_input - 1 );
+ bits_C = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx].q_lvls[quant_strat][1] ) ) * ( ( n_dmx - 1 ) * n_dec );
+ bits_P = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx].q_lvls[quant_strat][2] ) ) * ( n_dec );
+ wc_coarse_strat = bits_PR + bits_C + bits_P;
+ wc_coarse_strat *= num_bands;
+ wc_coarse_strat /= bands_bw;
+ wc_coarse_strat -= num_PR_bits_dirac_bands;
+ wc_coarse_strat += md_coding_bits_header;
+
+ if ( pSpar_md_cfg->max_bits_per_blk < wc_coarse_strat )
+ {
+ assert( 0 );
+ }
+
+ if ( agc_flag )
+ {
+ if ( pSpar_md_cfg->nchan_transport == 1 )
+ {
+ agc_bits = AGC_BITS_PER_CH;
+ }
+ else
+ {
+ agc_bits = AGC_BITS_PER_CH * pSpar_md_cfg->nchan_transport + AGC_SIGNALLING_BITS;
+ }
+ }
+ else
+ {
+ agc_bits = AGC_SIGNALLING_BITS;
+ }
+
+ if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER )
+ {
+ pca_bits = 1;
+ if ( pca_flag )
+ {
+ pca_bits += IVAS_PCA_QBITS + IVAS_PCA_QBITS - 1;
+ }
+ }
+ else
+ {
+ pca_bits = 0;
+ }
+
+ pSpar_md_cfg->max_md_bits_spar = pSpar_md_cfg->max_bits_per_blk + agc_bits + pca_bits;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_spar_bitrate_dist()
+ *
+ * Set SPAR bitrate distribution
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_spar_bitrate_dist(
+ int32_t core_brates_act[], /* o : bitrates per core-coder */
+ const int16_t nAvailBits, /* i : number of available bits */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const int16_t sba_order, /* i : Ambisonic (SBA) order */
+ const int16_t bwidth /* i : audio bandwidth */
+)
+{
+ int16_t i, nchan_transport, table_idx, bitlen;
+ int16_t core_bits_act[FOA_CHANNELS], core_range_bits[FOA_CHANNELS];
+ int16_t sum_core_act_bits, residual_bits, overflow_bits;
+
+ table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, bwidth, &bitlen, NULL );
+
+ nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport;
+
+ sum_core_act_bits = 0;
+ for ( i = 0; i < nchan_transport; i++ )
+ {
+ core_bits_act[i] = (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] / FRAMES_PER_SEC );
+
+ sum_core_act_bits += core_bits_act[i];
+ }
+
+ residual_bits = nAvailBits - sum_core_act_bits;
+
+ /* First compute core-coder bits as per bitrate distribution table and MD bitrate*/
+ if ( residual_bits > 0 )
+ {
+ for ( i = 0; i < nchan_transport; i++ )
+ {
+ core_range_bits[i] = (int16_t) ( ( ivas_spar_br_table_consts[table_idx].core_brs[i][2] - ivas_spar_br_table_consts[table_idx].core_brs[i][0] ) / FRAMES_PER_SEC );
+ core_bits_act[i] += min( residual_bits, core_range_bits[i] );
+ residual_bits -= core_range_bits[i];
+
+ if ( residual_bits <= 0 )
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ for ( i = 0; i < nchan_transport; i++ )
+ {
+ core_range_bits[i] = (int16_t) ( ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] - ivas_spar_br_table_consts[table_idx].core_brs[i][1] ) / FRAMES_PER_SEC );
+ }
+
+ overflow_bits = -residual_bits;
+
+ for ( i = 0; i < nchan_transport; i++ )
+ {
+ core_bits_act[nchan_transport - 1 - i] -= min( overflow_bits, core_range_bits[nchan_transport - 1 - i] );
+ overflow_bits -= core_range_bits[nchan_transport - 1 - i];
+
+ if ( overflow_bits <= 0 )
+ {
+ break;
+ }
+ }
+
+ if ( overflow_bits > 0 )
+ {
+ int16_t overflow_bits_ch;
+ overflow_bits_ch = overflow_bits / nchan_transport;
+
+ for ( i = 0; i < nchan_transport; i++ )
+ {
+ core_bits_act[i] -= overflow_bits_ch;
+ overflow_bits -= overflow_bits_ch;
+ }
+
+ core_bits_act[nchan_transport - 1] -= max( 0, overflow_bits );
+ }
+ }
+
+ for ( i = 0; i < nchan_transport; i++ )
+ {
+ core_brates_act[i] = core_bits_act[i] * FRAMES_PER_SEC;
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c
new file mode 100644
index 0000000000000000000000000000000000000000..c01f95d1edbbce812a426566fd3e9c6a94120ac2
--- /dev/null
+++ b/lib_com/ivas_spar_com_quant_util.c
@@ -0,0 +1,331 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "math.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
+#include
+#include "wmc_auto.h"
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_quantise_real_values()
+ *
+ * Quantize real values
+ *-----------------------------------------------------------------------------------------*/
+void ivas_quantise_real_values(
+ const float *values,
+ const int16_t q_levels,
+ const float min_value,
+ const float max_value,
+ int16_t *index,
+ float *quant,
+ const int16_t dim )
+{
+ int16_t i;
+ float q_step, one_by_q_step;
+ if ( q_levels == 1 )
+ {
+ for ( i = 0; i < dim; i++ )
+ {
+ quant[i] = 0;
+ index[i] = 0;
+ }
+ }
+ else if ( q_levels && max_value != min_value )
+ {
+ q_step = ( max_value - min_value ) / ( q_levels - 1 );
+ one_by_q_step = ( q_levels - 1 ) / ( max_value - min_value );
+ float val;
+ for ( i = 0; i < dim; i++ )
+ {
+ val = max( min_value, min( values[i], max_value ) );
+ index[i] = (int16_t) round( one_by_q_step * val );
+ quant[i] = index[i] * q_step;
+ }
+ }
+ else
+ {
+ for ( i = 0; i < dim; i++ )
+ {
+ quant[i] = values[i];
+ }
+ }
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_spar_get_uniform_quant_strat()
+ *
+ * Sets the quant strat values
+ *-----------------------------------------------------------------------------------------*/
+void ivas_spar_get_uniform_quant_strat(
+ ivas_spar_md_com_cfg *pSpar_md_com_cfg,
+ const int16_t table_idx )
+{
+ int16_t i;
+ int16_t active_w = ivas_spar_br_table_consts[table_idx].active_w;
+ int16_t PQ_q_lvl, C_q_lvl, Pr_q_lvl, Pc_q_lvl;
+
+ pSpar_md_com_cfg->num_quant_strats = MAX_QUANT_STRATS;
+
+ for ( i = 0; i < pSpar_md_com_cfg->num_quant_strats; i++ )
+ {
+ PQ_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][0];
+ C_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][1];
+ Pr_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][2];
+ Pc_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][3];
+
+ if ( active_w )
+ {
+ pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].PR.min = -1.2f;
+ pSpar_md_com_cfg->quant_strat[i].PR.max = 1.2f;
+
+ pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].C.min = -0.8f;
+ pSpar_md_com_cfg->quant_strat[i].C.max = 0.8f;
+
+ pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].P_r.min = 0;
+ pSpar_md_com_cfg->quant_strat[i].P_r.max = 0.8f;
+
+ pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].P_c.min = -0.8f;
+ pSpar_md_com_cfg->quant_strat[i].P_c.max = 0.8f;
+ }
+ else
+ {
+ pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].PR.max = 1;
+ pSpar_md_com_cfg->quant_strat[i].PR.min = -1;
+
+ pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].C.max = 2;
+ pSpar_md_com_cfg->quant_strat[i].C.min = -2;
+
+ pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].P_r.max = 1.0f;
+ pSpar_md_com_cfg->quant_strat[i].P_r.min = 0;
+
+ pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl;
+ pSpar_md_com_cfg->quant_strat[i].P_c.max = 0.5;
+ pSpar_md_com_cfg->quant_strat[i].P_c.min = -0.5;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_map_prior_coeffs_quant()
+ *
+ * Map prior coeffs
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_map_prior_coeffs_quant(
+ ivas_spar_md_prev_t *pSpar_md_prior,
+ ivas_spar_md_com_cfg *pSpar_md_cfg,
+ const int16_t qsi,
+ const int16_t nB )
+{
+ int16_t i, j;
+
+ if ( qsi != pSpar_md_cfg->prev_quant_idx )
+ {
+ 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];
+ float one_by_q_lvl_PR = 1.0f / max( prev_qs.PR.q_levels[0] - 1, 1 );
+ float one_by_q_lvl_C = 1.0f / max( prev_qs.C.q_levels[0] - 1, 1 );
+ float one_by_q_lvl_P_r = 1.0f / max( prev_qs.P_r.q_levels[0] - 1, 1 );
+ for ( i = 0; i < nB; i++ )
+ {
+ for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ )
+ {
+ pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = (int16_t) round( ( qs.PR.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] * one_by_q_lvl_PR );
+ pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = (int16_t) round( ( qs.P_r.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] * one_by_q_lvl_P_r );
+ }
+ for ( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ )
+ {
+ pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = (int16_t) round( ( qs.C.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] * one_by_q_lvl_C );
+ }
+ }
+ }
+ else
+ {
+ for ( i = 0; i < nB; i++ )
+ {
+ for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ )
+ {
+ pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j];
+ pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j];
+ }
+ for ( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ )
+ {
+ pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j];
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_spar_quant_dtx_init()
+ *
+ * Init SPAR MD with minmax vals
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_spar_quant_dtx_init(
+ ivas_spar_md_t *spar_md,
+ float *min_max )
+{
+ spar_md->min_max[0] = min_max[0];
+ spar_md->min_max[1] = min_max[1];
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_copy_band_coeffs_idx_to_arr()
+ *
+ * Copy pred band coeffs to arr
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_copy_band_coeffs_idx_to_arr(
+ ivas_band_coeffs_ind_t *pBands_idx,
+ const int16_t nB,
+ int16_t *pSymbol_re,
+ ivas_cell_dim_t *pCell_dims,
+ const ivas_coeffs_type_t coeff_type )
+{
+ int16_t i, len;
+ int16_t *pPtr_idx = NULL;
+
+ for ( i = 0; i < nB; i++ )
+ {
+ switch ( coeff_type )
+ {
+ case PRED_COEFF:
+ {
+ pPtr_idx = pBands_idx[i].pred_index_re;
+ break;
+ }
+ case DRCT_COEFF:
+ {
+ pPtr_idx = pBands_idx[i].drct_index_re;
+ break;
+ }
+ case DECD_COEFF:
+ {
+ pPtr_idx = pBands_idx[i].decd_index_re;
+ break;
+ }
+ case DECX_COEFF:
+ {
+ break;
+ }
+ }
+ len = pCell_dims[i].dim1 * pCell_dims[i].dim2;
+ if ( ( coeff_type != DECX_COEFF ) )
+ {
+ mvs2s( pPtr_idx, pSymbol_re, len );
+ pSymbol_re += len;
+ }
+ }
+
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_clear_band_coeffs()
+ *
+ * clear band coeffs array in SPAR MD
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_clear_band_coeffs(
+ ivas_band_coeffs_t *pband_coeffs,
+ const uint16_t num_bands )
+{
+ uint16_t i;
+
+ for ( i = 0; i < num_bands; i++ )
+ {
+ set_zero( (float *) pband_coeffs[i].C_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
+ set_zero( (float *) pband_coeffs[i].P_re, ( IVAS_SPAR_MAX_CH - 1 ) );
+ set_zero( (float *) pband_coeffs[i].C_quant_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
+ set_zero( (float *) pband_coeffs[i].P_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) );
+ set_zero( pband_coeffs[i].pred_re, ( IVAS_SPAR_MAX_CH - 1 ) );
+ set_zero( pband_coeffs[i].pred_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_clear_band_coeff_idx()
+ *
+ * clear band coeffs index array in SPAR MD
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_clear_band_coeff_idx(
+ ivas_band_coeffs_ind_t *pband_coeff_idx,
+ const uint16_t num_bands )
+{
+ uint16_t i = 0;
+
+ for ( i = 0; i < num_bands; i++ )
+ {
+ set_s( pband_coeff_idx[i].pred_index_re, 0, ( IVAS_SPAR_MAX_CH - 1 ) );
+ set_s( pband_coeff_idx[i].drct_index_re, 0, IVAS_SPAR_MAX_C_COEFF );
+ set_s( pband_coeff_idx[i].decd_index_re, 0, ( IVAS_SPAR_MAX_CH - 1 ) );
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h
new file mode 100644
index 0000000000000000000000000000000000000000..4768b1d90dd509f73c447ae5d3d2b2ee82ebeda2
--- /dev/null
+++ b/lib_com/ivas_stat_com.h
@@ -0,0 +1,815 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_STAT_COM
+#define IVAS_STAT_COM
+
+#include
+#include "options.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "ivas_cnst.h"
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of ISM common (encoder & decoder) structure
+ *----------------------------------------------------------------------------------*/
+
+typedef struct
+{
+ int16_t last_angle1_idx; /* last frame index of coded azimuth/yaw */
+ int16_t angle1_diff_cnt; /* FEC counter of consecutive differentially azimuth/yaw coded frames */
+ int16_t last_angle2_idx; /* last frame index of coded elevation/pitch */
+ int16_t angle2_diff_cnt; /* FEC counter of consecutive differentially elevation/pitch coded frames */
+
+} ISM_METADATA_ANGLE, *ISM_METADATA_ANGLE_HANDLE;
+
+/* ISM metadata handle (storage for one frame of read ISM metadata) */
+typedef struct
+{
+ int16_t ism_metadata_flag; /* flag whether metadata are coded in particular frame of particular object */
+ int16_t last_ism_metadata_flag; /* last frame ism_metadata_flag */
+
+ float azimuth; /* azimuth value read from the input metadata file */
+ float elevation; /* elevation value read from the input metadata file */
+ float radius; /* radius value read from the input metadata file */
+ float yaw; /* yaw value read from the input metadata file */
+ float pitch; /* pitch value read from the input metadata file */
+
+ int16_t non_diegetic_flag; /* Non-diegetic (non-headtracked) object flag */
+
+ ISM_METADATA_ANGLE position_angle; /* Angle structs for azimuth and elevation */
+ ISM_METADATA_ANGLE orientation_angle; /* Angle structs for yaw and pitch */
+ int16_t last_radius_idx; /* last frame index of coded radius */
+ int16_t radius_diff_cnt; /* FEC counter of consecutive differentially radius coded frames */
+
+ float last_azimuth; /* MD smoothing in DTX- last Q azimuth value */
+ float last_elevation; /* MD smoothing in DTX - last Q elevation value */
+ float last_true_azimuth; /* MD smoothing in DTX- last true Q azimuth value */
+ float last_true_elevation; /* MD smoothing in DTX- last true Q elevation value */
+
+ int16_t ism_md_fec_cnt_enc; /* counter of continuous frames where MD are not transmitted */
+ int16_t ism_md_inc_diff_cnt; /* counter of continuous frames where MD are transmitted in inactive segments when MD significantly changes */
+ float last_true_radius; /* last true Q radius value */
+
+ int16_t ism_imp; /* ISM importance flag */
+ int16_t ism_md_null_flag;
+ int16_t ism_md_lowrate_flag;
+ float q_azimuth_old;
+ float q_elevation_old;
+
+} ISM_METADATA_FRAME, *ISM_METADATA_HANDLE;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of DFT Stereo common (encoder & decoder) structure
+ *----------------------------------------------------------------------------------*/
+
+typedef struct stereo_dft_config_data_struct
+{
+ int16_t dmx_active;
+ int16_t band_res;
+ int16_t prm_res; /* Send prm every # DFT frames */
+ int16_t res_pred_mode; /* mode : from 0 (off) to 1 (on) */
+ int16_t res_cod_mode; /* mode : from 0 (off) to 3 */
+ int16_t hybrid_itd_flag;
+ int16_t ada_wb_res_cod_mode; /* res_cod_mode for adaptive wide band residual coding */
+
+ int16_t force_mono_transmission;
+
+} STEREO_DFT_CONFIG_DATA, *STEREO_DFT_CONFIG_DATA_HANDLE;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of MDCT stereo common (encoder & decoder) structure
+ *----------------------------------------------------------------------------------*/
+
+typedef struct
+{
+ uint8_t const bandLengthsTCX20[SMDCT_MAX_STEREO_BANDS_TCX20]; /* Length of a band in number of bins. Range is 4..160 */
+ const int16_t bdnCnt_TCX20[4]; /* uppermost band for FB,SWB,WB,NB */
+ uint8_t const bandLengthsTCX10[SMDCT_MAX_STEREO_BANDS_TCX10]; /* Length of a band in number of bins. Range is 2..80, always divisible by 2 */
+ const int16_t bndCnt_TCX10[4]; /* uppermost band for FB,SWB,WB,NB */
+
+} MDCTStereoBands_config;
+
+/* MDCT stereo frequency band structure */
+typedef struct stereo_mdct_dec_band_parameters_struct
+{
+ int16_t sfbOffset[MAX_SFB + 1]; /* stereo frequency band start offsets */
+ int16_t sfbCnt; /* number of stereo frequency bands */
+ int16_t nBandsStereoCore; /* number of stereo frequency bands in the core */
+ int16_t sfbIgfStart; /*index for first IGF band*/
+
+} STEREO_MDCT_BAND_PARAMETERS;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of ECLVQ common (encoder & decoder) structure
+ *----------------------------------------------------------------------------------*/
+
+typedef struct
+{
+ int16_t config_index;
+ int16_t encoding_active; /* internal state specifying if actual encoding is active or only length evaluation is active */
+ int32_t bit_count_estimate; /* uses 22Q10 fixed-point representation */
+ void *ac_handle;
+
+} ECSQ_instance;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of DirAC common (encoder & decoder) structure
+ *----------------------------------------------------------------------------------*/
+
+typedef struct ivas_dirac_config_data_struct
+{
+ int16_t enc_param_start_band;
+ int16_t dec_param_estim;
+ int16_t nbands;
+
+} DIRAC_CONFIG_DATA, *DIRAC_CONFIG_DATA_HANDLE;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of SPAR common structures
+ *----------------------------------------------------------------------------------*/
+
+/* SPAR MD structures */
+typedef struct ivas_band_coeffs_t
+{
+ float pred_re[IVAS_SPAR_MAX_CH - 1];
+ float C_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1];
+ float P_re[IVAS_SPAR_MAX_CH - 1];
+ float pred_quant_re[IVAS_SPAR_MAX_CH - 1];
+ float C_quant_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1];
+ float P_quant_re[IVAS_SPAR_MAX_CH - 1];
+
+} ivas_band_coeffs_t;
+
+typedef struct ivas_band_coeffs_ind_t
+{
+ int16_t pred_index_re[IVAS_SPAR_MAX_CH - 1];
+ int16_t drct_index_re[IVAS_SPAR_MAX_C_COEFF];
+ int16_t decd_index_re[IVAS_SPAR_MAX_CH - 1];
+
+} ivas_band_coeffs_ind_t;
+
+typedef struct ivas_spar_md_t
+{
+ ivas_band_coeffs_t *band_coeffs;
+ ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS];
+ int16_t num_bands;
+ float min_max[2];
+ int16_t dtx_vad;
+ float en_ratio_slow[IVAS_MAX_NUM_BANDS];
+ float ref_pow_slow[IVAS_MAX_NUM_BANDS];
+ int16_t res_ind;
+ int16_t prior_dyn_active_w_flag;
+
+} ivas_spar_md_t;
+
+typedef struct ivas_spar_md_prev_t
+{
+ ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS];
+ ivas_band_coeffs_ind_t band_coeffs_idx_mapped[IVAS_MAX_NUM_BANDS];
+
+} ivas_spar_md_prev_t;
+
+typedef struct ivas_quant_coeffs_t
+{
+ float min;
+ float max;
+ int16_t q_levels[2];
+
+} ivas_quant_coeffs_t;
+
+typedef struct ivas_quant_strat_t
+{
+ ivas_quant_coeffs_t PR;
+ ivas_quant_coeffs_t C;
+ ivas_quant_coeffs_t P_r;
+ ivas_quant_coeffs_t P_c;
+
+} ivas_quant_strat_t;
+
+typedef struct ivas_spar_md_com_cfg
+{
+ int16_t max_freq_per_chan[IVAS_SPAR_MAX_CH];
+ int16_t num_dmx_chans_per_band[IVAS_MAX_NUM_BANDS];
+ int16_t num_decorr_per_band[IVAS_MAX_NUM_BANDS];
+ int16_t active_w;
+ int16_t remix_unmix_order;
+ ivas_quant_strat_t quant_strat[MAX_QUANT_STRATS];
+ int16_t quant_strat_bits;
+ int16_t nchan_transport;
+ int16_t num_quant_strats;
+ int16_t prior_strat;
+ int16_t tgt_bits_per_blk;
+ int16_t max_bits_per_blk;
+ int16_t prev_quant_idx;
+ int16_t agc_bits_ch_idx;
+ int16_t planarCP;
+ int16_t num_umx_chs;
+ int16_t max_md_bits_spar;
+
+} ivas_spar_md_com_cfg;
+
+
+/* arithmetic coder structures */
+typedef struct ivas_cell_dim_t
+{
+ int16_t dim1;
+ int16_t dim2;
+
+} ivas_cell_dim_t;
+
+typedef struct ivas_freq_models_t
+{
+ int16_t freq_model[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS];
+ int16_t diff_freq_model[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS];
+ int16_t vals[IVAS_MAX_QUANT_LEVELS];
+ int16_t diff_vals[IVAS_MAX_QUANT_LEVELS];
+ int16_t num_models;
+ int16_t diff_num_models;
+
+} ivas_freq_models_t;
+
+typedef struct ivas_huff_models_t
+{
+ int16_t code_book[IVAS_MAX_QUANT_LEVELS][3];
+ int16_t diff_code_book[IVAS_MAX_QUANT_LEVELS][3];
+
+} ivas_huff_models_t;
+
+
+/* Entropy coder structures */
+typedef struct ivas_huffman_cfg_t
+{
+ const int16_t *codebook;
+ int16_t min_len;
+ int16_t max_len;
+ int16_t sym_len;
+
+} ivas_huffman_cfg_t;
+
+typedef struct ivas_arith_t
+{
+ int16_t dyn_model_bits;
+ const int16_t *pFreq_model;
+ const int16_t *pAlt_freq_models[IVAS_NUM_PROB_MODELS];
+ const int16_t *vals;
+ int16_t cum_freq[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS];
+ int16_t range;
+ int16_t num_models;
+ float saved_dist_arr[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS];
+
+} ivas_arith_t;
+
+typedef struct ivas_arith_coeffs_t
+{
+ ivas_arith_t pred_arith_re[MAX_QUANT_STRATS];
+ ivas_arith_t drct_arith_re[MAX_QUANT_STRATS];
+ ivas_arith_t decd_arith_re[MAX_QUANT_STRATS];
+ ivas_arith_t pred_arith_re_diff[MAX_QUANT_STRATS];
+ ivas_arith_t drct_arith_re_diff[MAX_QUANT_STRATS];
+ ivas_arith_t decd_arith_re_diff[MAX_QUANT_STRATS];
+
+} ivas_arith_coeffs_t;
+
+typedef struct ivas_huff_coeffs_t
+{
+ ivas_huffman_cfg_t pred_huff_re[MAX_QUANT_STRATS];
+ ivas_huffman_cfg_t drct_huff_re[MAX_QUANT_STRATS];
+ ivas_huffman_cfg_t decd_huff_re[MAX_QUANT_STRATS];
+
+} ivas_huff_coeffs_t;
+
+/* AGC structures */
+typedef struct ivas_agc_chan_data_t
+{
+ int16_t absGainExp;
+ int16_t absGainExpCurr;
+
+} ivas_agc_chan_data_t;
+
+typedef struct ivas_agc_com_state_t
+{
+ float *winFunc;
+ int16_t in_delay; /* TODO: JBM check if this needs to be adjusted in the dec */
+ uint16_t absEmin;
+ uint16_t betaE;
+ uint16_t maxAttExp;
+ uint16_t num_coeff;
+
+} ivas_agc_com_state_t;
+
+/* Covariance structures */
+typedef struct ivas_cov_smooth_state_t
+{
+ float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
+ int16_t prior_bank_idx;
+ float *pSmoothing_factor;
+ int16_t num_bins;
+
+} ivas_cov_smooth_state_t;
+
+typedef struct ivas_cov_smooth_cfg_t
+{
+ float max_update_rate;
+ int16_t min_pool_size;
+ int16_t max_bands;
+ int16_t num_bins;
+
+} ivas_cov_smooth_cfg_t;
+
+
+/* SPAR bitrate constant table structure */
+typedef struct ivas_spar_br_table_t
+{
+ int32_t ivas_total_brate;
+ int16_t isPlanar;
+ int16_t sba_order;
+ int16_t bwidth;
+ int16_t fpcs;
+ int16_t nchan_transport;
+ ivas_spar_pmx_strings_t dmx_str;
+ int16_t active_w;
+ int16_t tmode;
+ int32_t core_brs[FOA_CHANNELS][3];
+ int16_t q_lvls[MAX_QUANT_STRATS][NUM_MD_Q_COEFS_SET];
+ int16_t td_ducking;
+ int16_t agc_bits_ch_idx; /* 0-3, Indicates core-coder channel index from which AGC bits have been taken from*/
+ int16_t usePlanarCoeff;
+
+} ivas_spar_br_table_t;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of MASA common structures
+ *----------------------------------------------------------------------------------*/
+
+typedef struct ivas_MASA_spherical_grid_deindexing
+{
+ float theta_cb[NO_THETA16_MAX];
+ int16_t no_theta;
+ int16_t no_phi[NO_THETA16_MAX];
+
+} SPHERICAL_GRID_DATA;
+
+typedef struct ivas_masa_descriptive_meta_struct
+{
+ uint8_t formatDescriptor[8]; /* 8x 8 bits */
+ uint8_t numberOfDirections; /* 1 bit */
+ uint8_t numberOfChannels; /* 1 bit */
+ uint8_t sourceFormat; /* 2 bits */
+ uint8_t transportDefinition; /* 3 bits */
+ uint8_t channelAngle; /* 3 bits */
+ uint8_t channelDistance; /* 6 bits */
+ uint8_t channelLayout; /* 3 bits, used only when sourceFormat == bit value 10 */
+
+} MASA_DECRIPTIVE_META;
+
+typedef struct ivas_masa_directional_spatial_meta_struct
+{
+ float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
+ float elevation[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
+ float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
+ float spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
+ uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
+
+} MASA_DIRECTIONAL_SPATIAL_META;
+
+typedef struct ivas_masa_common_spatial_meta_struct
+{
+ float diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
+ float surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
+ float remainder_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
+
+} MASA_COMMON_SPATIAL_META;
+
+typedef struct ivas_omasa_meta_struct
+{
+ uint8_t num_dirs;
+ MASA_DIRECTIONAL_SPATIAL_META directional_meta[MASA_MAXIMUM_DIRECTIONS];
+ MASA_COMMON_SPATIAL_META common_meta;
+
+} OMASA_SPATIAL_META, *OMASA_SPATIAL_META_HANDLE;
+
+typedef struct ivas_masa_metadata_frame_struct
+{
+ MASA_DECRIPTIVE_META descriptive_meta;
+ MASA_DIRECTIONAL_SPATIAL_META directional_meta[MASA_MAXIMUM_DIRECTIONS];
+ MASA_COMMON_SPATIAL_META common_meta;
+
+} MASA_METADATA_FRAME, *MASA_METADATA_HANDLE;
+
+typedef struct ivas_masa_config_struct
+{
+ uint16_t max_metadata_bits;
+ int16_t block_grouping[5];
+ int16_t band_grouping[MASA_FREQUENCY_BANDS + 1];
+ uint8_t numCodingBands;
+ uint8_t numTwoDirBands;
+ uint8_t numberOfDirections;
+ uint8_t joinedSubframes;
+ uint8_t useCoherence;
+ uint8_t coherencePresent;
+ uint8_t mergeRatiosOverSubframes;
+ IVAS_FORMAT input_ivas_format;
+
+} MASA_CODEC_CONFIG;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of Qmetadata common structures
+ *----------------------------------------------------------------------------------*/
+
+typedef struct
+{
+ int16_t nbands;
+ int16_t nblocks;
+ int16_t start_band;
+ uint8_t inactiveBands;
+ int16_t search_effort;
+ MC_LS_SETUP mc_ls_setup;
+
+} IVAS_METADATA_CONFIG;
+
+typedef struct ivas_qdirection_band_data_struct
+{
+ uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES];
+ float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES];
+ float elevation[MAX_PARAM_SPATIAL_SUBFRAMES];
+ int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES];
+ int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES];
+
+ float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES];
+ uint8_t distance[MAX_PARAM_SPATIAL_SUBFRAMES];
+
+ uint16_t bits_sph_idx[MAX_PARAM_SPATIAL_SUBFRAMES];
+ uint16_t energy_ratio_index[MAX_PARAM_SPATIAL_SUBFRAMES];
+ uint16_t energy_ratio_index_mod[MAX_PARAM_SPATIAL_SUBFRAMES];
+ uint16_t azimuth_index[MAX_PARAM_SPATIAL_SUBFRAMES];
+ uint16_t elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES];
+ float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES];
+ float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES];
+
+} IVAS_QDIRECTION_BAND_DATA;
+
+typedef struct ivas_qdirection_band_coherence_data_struct
+{
+ uint8_t spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES];
+ uint16_t spread_coherence_dct0_index;
+ uint16_t spread_coherence_dct1_index;
+} IVAS_QDIRECTION_BAND_COHERENCE_DATA;
+
+typedef struct ivas_surround_coherence_band_data_struct
+{
+ uint8_t surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES];
+ uint16_t sur_coherence_index;
+
+} IVAS_SURROUND_COHERENCE_BAND_DATA;
+
+
+typedef struct
+{
+ IVAS_METADATA_CONFIG cfg;
+
+ IVAS_QDIRECTION_BAND_DATA *band_data;
+ IVAS_QDIRECTION_BAND_COHERENCE_DATA *coherence_band_data;
+ int16_t not_in_2D;
+
+} IVAS_QDIRECTION; /* IVAS_QMETADATA; */
+
+typedef struct ivas_masa_qmetadata_frame_struct
+{
+ IVAS_QDIRECTION *q_direction;
+ uint16_t no_directions;
+ int16_t bits_frame_nominal;
+ uint16_t coherence_flag;
+ uint8_t all_coherence_zero;
+ uint8_t twoDirBands[MASA_MAXIMUM_CODING_SUBBANDS];
+ uint8_t numTwoDirBands;
+ int16_t qmetadata_max_bit_req;
+ int16_t metadata_max_bits; /* maximum allowed number of bits for metadata per frame */
+ uint8_t useLowerRes;
+ uint8_t useLowerBandRes;
+ int16_t dirac_mono_flag;
+ IVAS_SURROUND_COHERENCE_BAND_DATA *surcoh_band_data;
+
+ /* Additional helper values to include all data required for writing to output file */
+ uint8_t numCodingBands;
+ int16_t *bandMap;
+ int16_t nchan_transport;
+ int16_t sba_inactive_mode;
+ /* Status values on metadata quality */
+ int16_t ec_flag;
+ float dir_comp_ratio;
+ uint8_t is_masa_ivas_format;
+
+} IVAS_QMETADATA, *IVAS_QMETADATA_HANDLE;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of Parametric MC common (encoder & decoder) structures
+ *----------------------------------------------------------------------------------*/
+
+typedef struct ivas_param_mc_ild_mapping_struct
+{
+ int16_t ild_map_size_wo_lfe;
+ int16_t ild_map_size_lfe;
+ int16_t ild_index[MAX_CICP_CHANNELS];
+ int16_t num_ref_channels[MAX_CICP_CHANNELS];
+ int16_t ref_channel_idx[MAX_CICP_CHANNELS][PARAM_MC_MAX_ILD_REF_CHANNELS];
+
+} PARAM_MC_ILD_MAPPING, *HANDLE_PARAM_MC_ILD_MAPPING;
+
+typedef struct ivas_param_mc_icc_mapping_struct
+{
+ int16_t icc_map_size_wo_lfe;
+ int16_t icc_map_size_lfe;
+ int16_t icc_mapping[PARAM_MC_SZ_ICC_MAP][2];
+
+} PARAM_MC_ICC_MAPPING, *HANDLE_PARAM_MC_ICC_MAPPING;
+
+typedef struct ivas_param_mc_conf_struct /* structure for ROM Table */
+{
+ MC_LS_SETUP mc_ls_setup;
+ int16_t num_input_chan;
+ int16_t num_transport_chan;
+ int32_t ivas_total_brate;
+ const PARAM_MC_ILD_MAPPING *ild_mapping_conf;
+ const PARAM_MC_ICC_MAPPING *icc_mapping_conf;
+ const float *dmx_fac;
+ const float *ild_factors;
+
+} PARAM_MC_CONF;
+
+typedef struct ivas_parametric_mc_metadata_value_coding_info_struct
+{
+ const uint16_t *cum_freq;
+ const uint16_t *sym_freq;
+ const uint16_t *cum_freq_delta;
+ const uint16_t *sym_freq_delta;
+ const float *quantizer;
+ int16_t quantizer_size;
+ int16_t uni_bits;
+
+} PARAM_MC_PARAMETER_CODING_INFO, *HANDLE_PARAM_MC_PARAMETER_CODING_INFO;
+
+typedef struct ivas_parametric_mc_metadata_struct
+{
+ const PARAM_MC_ILD_MAPPING *ild_mapping_conf;
+ const PARAM_MC_ICC_MAPPING *icc_mapping_conf;
+ int16_t icc_mapping[PARAM_MC_PARAMETER_FRAMES][PARAM_MC_SZ_ICC_MAP][2];
+ int16_t *icc_map_full[2];
+ int16_t icc_map_size_full;
+ int16_t param_frame_idx;
+ int16_t flag_use_adaptive_icc_map;
+ const float *ild_factors;
+ int16_t coding_band_mapping[PARAM_MC_MAX_PARAMETER_BANDS];
+ int16_t nbands_in_param_frame[PARAM_MC_PARAMETER_FRAMES];
+ int16_t bAttackPresent;
+ int16_t attackIndex;
+ int16_t nbands_coded;
+ int16_t num_parameter_bands;
+ int16_t coded_bwidth;
+ int16_t last_coded_bwidth;
+ int16_t lfe_on;
+ PARAM_MC_PARAMETER_CODING_INFO icc_coding;
+ PARAM_MC_PARAMETER_CODING_INFO ild_coding;
+
+} IVAS_PARAM_MC_METADATA, *HANDLE_IVAS_PARAM_MC_METADATA;
+
+
+/*----------------------------------------------------------------------------------*
+ * Declaration of LFE common (encoder & decoder) structures
+ *----------------------------------------------------------------------------------*/
+
+typedef struct ivas_lfe_window
+{
+ int16_t dct_len;
+ int16_t fade_len;
+ int16_t zero_pad_len;
+ int16_t full_len;
+ const float *pWindow_coeffs;
+
+} LFE_WINDOW_DATA, *LFE_WINDOW_HANDLE;
+
+typedef struct ivas_lfe_freq_models
+{
+ uint16_t entropy_coder_model_fine_sg1[65];
+ uint16_t entropy_coder_model_fine_sg2[33];
+ uint16_t entropy_coder_model_fine_sg3[9];
+ uint16_t entropy_coder_model_fine_sg4[3];
+ uint16_t entropy_coder_model_coarse_sg1[33];
+ uint16_t entropy_coder_model_coarse_sg2[17];
+ uint16_t entropy_coder_model_coarse_sg3[5];
+ uint16_t entropy_coder_model_coarse_sg4;
+
+} ivas_lfe_freq_models;
+
+typedef struct ivas_filters_process_state_t
+{
+ int16_t order;
+ int16_t filt_len;
+ float num[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN];
+ float den[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN];
+ float state[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN];
+
+} ivas_filters_process_state_t;
+
+
+/*----------------------------------------------------------------------------------*
+ * Transient Detector (TD) structure
+ *----------------------------------------------------------------------------------*/
+
+typedef struct ivas_trans_det_state_t
+{
+ ivas_filters_process_state_t env_hpf;
+ ivas_filters_process_state_t env_fast;
+ ivas_filters_process_state_t env_slow;
+ float in_duck_coeff;
+ float out_duck_coeff;
+ float in_duck_gain;
+ float out_duck_gain;
+ float duck_mult_fac;
+
+} ivas_trans_det_state_t;
+
+
+/*----------------------------------------------------------------------------------*
+ * Time domain decorrelator
+ *----------------------------------------------------------------------------------*/
+
+typedef struct ivas_td_decorr_APD_filt_state_t
+{
+ int16_t order[IVAS_MAX_DECORR_APD_SECTIONS];
+ int16_t idx[IVAS_MAX_DECORR_APD_SECTIONS];
+ float coeffs[IVAS_MAX_DECORR_APD_SECTIONS];
+ float *state[IVAS_MAX_DECORR_APD_SECTIONS];
+
+} ivas_td_decorr_APD_filt_state_t;
+
+typedef struct ivas_td_decorr_state_t
+{
+ ivas_trans_det_state_t *pTrans_det;
+ float *look_ahead_buf;
+ ivas_td_decorr_APD_filt_state_t APD_filt_state[IVAS_MAX_DECORR_CHS];
+
+ int16_t num_apd_outputs;
+ int16_t num_apd_sections;
+ int16_t ducking_flag;
+
+ int16_t offset;
+
+} ivas_td_decorr_state_t;
+
+
+/*----------------------------------------------------------------------------------*
+ * Filter Bank (FB) structures
+ *----------------------------------------------------------------------------------*/
+
+typedef struct ivas_fb_mixer_cfg_t
+{
+ int16_t fb_latency;
+ int16_t num_in_chans;
+ int16_t num_out_chans;
+ int16_t nchan_fb_in;
+ int16_t pcm_offset;
+ int16_t fade_len; /* this sets the stride length; no delay is introduced */
+ int16_t prior_input_length;
+ int16_t windowed_fr_offset;
+ int16_t active_w_mixing;
+ const int16_t *remix_order;
+
+} IVAS_FB_CFG;
+
+typedef struct ivas_fb_consts_t
+{
+ const float *ppFilterbank_FRs[2][IVAS_MAX_NUM_BANDS];
+ float *ppFilterbank_FRs_non48k[2][IVAS_MAX_NUM_BANDS];
+ const int16_t *pFilterbank_bins_per_band;
+ const int16_t *pFilterbank_bins_start_offset;
+
+} ivas_fb_consts_t;
+
+typedef struct ivas_fb_bin_to_band_data_t
+{
+ float *pFb_bin_to_band[IVAS_MAX_NUM_FB_BANDS];
+ const int16_t *pFb_start_bin_per_band;
+ const int16_t *pFb_active_bins_per_band;
+ float pp_cldfb_weights_per_spar_band[CLDFB_NO_CHANNELS_MAX][IVAS_MAX_NUM_FB_BANDS]; /* weights for linear combination of parameters from different SPAR bands*/
+ int16_t p_spar_start_bands[CLDFB_NO_CHANNELS_MAX]; /* the first SPAR band per CLFB band when the weight is > 0 */
+ int16_t p_cldfb_map_to_spar_band[CLDFB_NO_CHANNELS_MAX]; /* a direct mapping from CLDFB band to SPAR band */
+ int16_t p_short_stride_start_bin_per_band[IVAS_MAX_NUM_FB_BANDS];
+ int16_t p_short_stride_num_bins_per_band[IVAS_MAX_NUM_FB_BANDS];
+ float p_short_stride_bin_to_band[2 * MDFT_FB_BANDS_240];
+ float *pp_short_stride_bin_to_band[IVAS_MAX_NUM_FB_BANDS];
+ int16_t short_stride;
+ int16_t num_cldfb_bands;
+
+} ivas_fb_bin_to_band_data_t;
+
+typedef struct ivas_filterbank_t
+{
+ int16_t filterbank_num_bands;
+ ivas_fb_consts_t fb_consts;
+ ivas_fb_bin_to_band_data_t fb_bin_to_band;
+
+} ivas_filterbank_t;
+
+typedef struct ivas_fb_mixer_state_structure
+{
+ IVAS_FB_CFG *fb_cfg;
+
+ int16_t num_diff_bands;
+ ivas_filterbank_t *pFb;
+
+ float *ppFilterbank_inFR_re[IVAS_MAX_FB_MIXER_IN_CH];
+ float *ppFilterbank_inFR_im[IVAS_MAX_FB_MIXER_IN_CH];
+ float *ppFilterbank_prior_input[IVAS_MAX_FB_MIXER_IN_CH];
+ float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH];
+
+ /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */
+ int16_t cross_fade_start_offset;
+ int16_t cross_fade_end_offset;
+ const float *pFilterbank_cross_fade;
+ int16_t ana_window_offset;
+ const float *pAna_window;
+
+ int16_t prior_input_length;
+ int16_t windowed_fr_offset;
+ float cldfb_cross_fade[CLDFB_NO_COL_MAX];
+ int16_t cldfb_cross_fade_start;
+ int16_t cldfb_cross_fade_end;
+
+ int16_t first_frame[IVAS_SPAR_MAX_CH];
+
+} IVAS_FB_MIXER_DATA, *IVAS_FB_MIXER_HANDLE;
+
+
+/*----------------------------------------------------------------------------------*
+ * PARAMETRIC ISM encoder/decoder (common) structure
+ *----------------------------------------------------------------------------------*/
+
+typedef struct ivas_param_ism_data_structure
+{
+ IVAS_FB_MIXER_HANDLE hFbMixer;
+
+ int16_t nbands;
+ int16_t nblocks[MAX_PARAM_ISM_NBANDS];
+ int16_t band_grouping[MAX_PARAM_ISM_NBANDS + 1];
+
+ int16_t azi_index[MAX_NUM_OBJECTS];
+ int16_t ele_index[MAX_NUM_OBJECTS];
+
+ int16_t obj_indices[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE];
+ int16_t power_ratios_idx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS];
+
+ int16_t last_az_sgn[MAX_NUM_OBJECTS];
+ int16_t last_az_diff[MAX_NUM_OBJECTS];
+ int16_t last_el_sgn[MAX_NUM_OBJECTS];
+ int16_t last_el_diff[MAX_NUM_OBJECTS];
+
+ int16_t flag_noisy_speech;
+ int16_t noisy_speech_buffer[PARAM_ISM_HYS_BUF_SIZE];
+ int16_t flag_equal_energy;
+
+ float last_dmx_gain;
+ float last_cardioid_left[MAX_NUM_OBJECTS];
+
+} PARAM_ISM_CONFIG_DATA, *PARAM_ISM_CONFIG_HANDLE;
+
+
+#endif /* IVAS_STAT_COM */
diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..541f90a120484b76fec7bc29abc3b6ebf704000d
--- /dev/null
+++ b/lib_com/ivas_stereo_dft_com.c
@@ -0,0 +1,216 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "ivas_prot.h"
+#include "prot.h"
+#include "cnst.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------------
+ * stereo_dft_config()
+ *
+ * DFT Stereo Configuration function
+ *------------------------------------------------------------------------*/
+
+void stereo_dft_config(
+ STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */
+ const int32_t brate, /* i : IVAS/CPE/nominal total bitrate */
+ int16_t *bits_frame_nominal, /* o : primary channel nominal bits per frame */
+ int16_t *bits_frame_nominal_2 /* o : secondary channel nominal bits per frame*/
+)
+{
+ if ( hConfig != NULL )
+ {
+ hConfig->band_res = STEREO_DFT_BAND_RES_HIGH;
+ hConfig->prm_res = 2;
+ hConfig->dmx_active = STEREO_DFT_DMX_ACTIVE;
+ hConfig->ada_wb_res_cod_mode = 0;
+ }
+
+ *bits_frame_nominal_2 = 5000 / FRAMES_PER_SEC;
+
+ /* ITD, IPD and residual coding is not used in SID/No data */
+ if ( brate == FRAME_NO_DATA )
+ {
+ *bits_frame_nominal = FRAME_NO_DATA;
+ if ( hConfig != NULL )
+ {
+ hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
+ hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
+ hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
+ }
+ }
+ else if ( brate == IVAS_SID_5k2 )
+ {
+ *bits_frame_nominal = SID_2k40 / FRAMES_PER_SEC;
+ if ( hConfig != NULL )
+ {
+ hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
+ hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
+ hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
+ }
+ }
+ else if ( brate <= IVAS_13k2 )
+ {
+ *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC;
+ if ( hConfig != NULL )
+ {
+ hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
+ hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
+ hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
+ }
+ }
+ else if ( brate <= IVAS_16k4 )
+ {
+ *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC;
+ if ( hConfig != NULL )
+ {
+ hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
+ hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
+ hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
+ }
+ }
+ else if ( brate <= IVAS_24k4 )
+ {
+ *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC;
+ if ( hConfig != NULL )
+ {
+ hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
+ hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
+ }
+ }
+ else if ( brate <= IVAS_32k )
+ {
+ *bits_frame_nominal = ACELP_24k40 / FRAMES_PER_SEC;
+ if ( hConfig != NULL )
+ {
+ hConfig->ada_wb_res_cod_mode = 1;
+ hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
+ hConfig->res_cod_mode = STEREO_DFT_RES_COD_1kHz;
+ }
+ }
+ else if ( brate <= IVAS_48k )
+ {
+ *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC;
+ if ( hConfig != NULL )
+ {
+ hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
+ hConfig->res_cod_mode = STEREO_DFT_RES_COD_1_6kHz;
+ }
+ }
+ else
+ {
+ assert( 0 && "Bit-rate not supported by DFT stereo." );
+ }
+
+ if ( hConfig != NULL && hConfig->force_mono_transmission )
+ {
+ hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
+ hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
+ hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
+ hConfig->ada_wb_res_cod_mode = 0;
+ }
+
+ /*sanity check*/
+ if ( hConfig != NULL )
+ {
+ assert( hConfig->prm_res <= STEREO_DFT_NBDIV );
+ /* make sure residual switching and ESF are not active at the same time */
+ assert( !( hConfig->ada_wb_res_cod_mode == 1 && hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF ) );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------------
+ * stereo_dft_band_config()
+ *
+ * Stereo DFT bands condfiguration
+ *------------------------------------------------------------------------*/
+
+int16_t stereo_dft_band_config(
+ int16_t *band_limits, /* o : DFT band limits */
+ const int16_t band_res, /* i : DFT band resolution */
+ const int16_t NFFT, /* i : analysis/synthesis window length */
+ const int16_t enc_dec /* i : flag to indicate enc vs dec */
+)
+{
+ int16_t nbands;
+
+ /*sanity check*/
+ assert( ( band_res == 1 || band_res == 0 || band_res == 2 ) && "stereo DFT: Parameter band resolution not supported!\n" );
+
+ band_limits[0] = 1;
+ nbands = 0;
+ while ( band_limits[nbands++] < NFFT / 2 )
+ {
+ if ( band_res == 0 )
+ {
+ assert( 0 && "stereo DFT: band config failed!\n" );
+ }
+ else if ( band_res == 1 )
+ {
+ if ( enc_dec == ENC )
+ {
+ band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb4[nbands] * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) );
+ }
+ else
+ {
+ band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb4[nbands] * ( (float) ( STEREO_DFT32MS_N_NS ) / STEREO_DFT_N_NS ) );
+ }
+
+ assert( ( nbands < STEREO_DFT_ERB4_BANDS ) && "stereo DFT: band config failed!\n" );
+ }
+ else
+ {
+ if ( enc_dec == ENC )
+ {
+ band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb8[nbands] * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) );
+ }
+ else
+ {
+ band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb8[nbands] * ( (float) ( STEREO_DFT32MS_N_NS ) / STEREO_DFT_N_NS ) );
+ }
+
+ assert( ( nbands < STEREO_DFT_ERB8_BANDS ) && "stereo DFT: band config failed!\n" );
+ }
+ }
+ nbands--;
+ band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/
+
+ return ( nbands );
+}
diff --git a/lib_com/ivas_stereo_eclvq_com.c b/lib_com/ivas_stereo_eclvq_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..f3b4e51fee66330bf5279ea6899df5de1a1c9653
--- /dev/null
+++ b/lib_com/ivas_stereo_eclvq_com.c
@@ -0,0 +1,99 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository. All Rights Reserved.
+
+ This software is protected by copyright law and by international treaties.
+ The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository retain full ownership rights in their respective contributions in
+ the software. This notice grants no license of any kind, including but not limited to patent
+ license, nor is any license granted by implication, estoppel or otherwise.
+
+ Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
+ contributions.
+
+ This software is provided "AS IS", without any express or implied warranties. The software is in the
+ development stage. It is intended exclusively for experts who have experience with such software and
+ solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
+ and fitness for a particular purpose are hereby disclaimed and excluded.
+
+ Any dispute, controversy or claim arising under or in relation to providing this software shall be
+ submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
+ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
+ the United Nations Convention on Contracts on the International Sales of Goods.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h"
+#include
+#include "ivas_prot.h"
+#include "ivas_cnst.h"
+#include
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------
+ * ECSQ_init_instance()
+ *
+ * initialize the encoder or decoder instance ecsq_inst, using the configuration index config_index;
+ * ac_handle is a pointer to a structure containing the bitstream writer and the arithmetic coding state;
+ * the return value is the approximate number of bits written, expressed in 22Q10 fixed-point representation
+ * ---------------------------------------------------------------*/
+
+void ECSQ_init_instance(
+ ECSQ_instance *ecsq_inst,
+ const int16_t config_index,
+ void *ac_handle )
+{
+ ecsq_inst->config_index = config_index;
+ ecsq_inst->encoding_active = 1;
+ ecsq_inst->bit_count_estimate = 0;
+ ecsq_inst->ac_handle = ac_handle;
+
+ return;
+}
+
+/*---------------------------------------------------------------
+ * ECSQ_dequantize_gain()
+ *
+ * dequantize global gain index
+ * ---------------------------------------------------------------*/
+
+float ECSQ_dequantize_gain(
+ const int16_t index )
+{
+ float global_gain;
+
+ global_gain = powf( 10.0f, (float) index * ECLVQ_INV_GLOBAL_GAIN_FACTOR );
+
+ return global_gain;
+}
+
+/*---------------------------------------------------------------
+ * ECSQ_dequantize_vector()
+ *
+ * dequantize an integer-valued vector using optimal reconstruction points, which depend on the value of config_index
+ * ---------------------------------------------------------------*/
+
+void ECSQ_dequantize_vector(
+ const int16_t *input,
+ const float global_gain,
+ const int16_t N,
+ float *output )
+{
+ int16_t i;
+
+ for ( i = 0; i < N; ++i )
+ {
+ output[i] = (float) input[i] * global_gain;
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_stereo_ica_com.c b/lib_com/ivas_stereo_ica_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..31f9447a577376798e8977cd8c9a134819e33594
--- /dev/null
+++ b/lib_com/ivas_stereo_ica_com.c
@@ -0,0 +1,223 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include "cnst.h"
+#include "ivas_cnst.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "wmc_auto.h"
+#include "rom_com.h"
+#include "ivas_rom_com.h"
+
+/*---------------------------------------------------------------
+ * interpTargetChannel()
+ *
+ * Target signal correction for shift variations.
+ * The pointer passsed into this function is assumed to be chanR/chanL + currNCShift.
+ * ---------------------------------------------------------------*/
+
+#define SPREAD_FACTOR1 ( 1.0f / INTERP_FACTOR1 )
+
+static void interpTargetChannel(
+ float *target,
+ const int16_t prevShift,
+ const int16_t currShift,
+ const int16_t L_shift_adapt )
+{
+ int16_t i, j, k, /*m,*/ d, N, signShift, lim1, lim2;
+ const float *win;
+ float *ptr1, *ptr2;
+ float tempBuff1[INTERP_FACTOR1 * ( L_SHIFT_ADAPT_MAX + 2 * N_MAX_SHIFT_CHANGE + 2 )], tempBuff2[L_SHIFT_ADAPT_MAX - 1];
+ float x[4], y[4], tempF, tempF1;
+ float interp_factor2, factor;
+ float spread_factor2;
+ double tempD1, tempD2;
+
+ d = -( currShift - prevShift );
+ signShift = ( d >= 0 ) ? ( 1 ) : ( -1 );
+
+ if ( d == 0 )
+ {
+ /* this can happen in DFT->TD switching */
+ return;
+ }
+
+ N = L_shift_adapt;
+ factor = ( (float) N ) / abs( d );
+ interp_factor2 = factor / INTERP_FACTOR1;
+ spread_factor2 = 1.0f / interp_factor2;
+
+ /* start from (target - N - d + 1) : (extra lag = step1) :to: (target - 1 - d) : (extra lag = d) */
+ /* sinc interp by a factor of 2 */
+ win = ica_sincInterp2 + SINC_ORDER1;
+ ptr1 = target;
+ ptr2 = tempBuff1 + ( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1;
+
+ for ( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < ( N + N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i++ )
+ {
+ if ( i & 0x1 )
+ {
+ ptr2[i] = 0.0f;
+ /* lim1 = ceil((i - SINC_ORDER1)*SPREAD_FACTOR1); */
+ /* lim2 = floor((i + SINC_ORDER1)*SPREAD_FACTOR1); */
+ tempF = ( i - SINC_ORDER1 ) * SPREAD_FACTOR1;
+ lim1 = (int16_t) ( tempF );
+ if ( lim1 < tempF )
+ {
+ lim1++;
+ }
+
+ tempF = ( i + SINC_ORDER1 ) * SPREAD_FACTOR1;
+ lim2 = (int16_t) ( tempF );
+ if ( lim2 > tempF )
+ {
+ lim2--;
+ }
+
+ for ( j = lim1; j <= lim2; j++ )
+ {
+ ptr2[i] += win[j * INTERP_FACTOR1 - i] * ptr1[j];
+ }
+ }
+ else
+ {
+ ptr2[i] = ptr1[(int16_t) ( i * SPREAD_FACTOR1 )];
+ }
+ }
+
+ /* cubic spline interp */
+ ptr1 = ptr2;
+ ptr2 = tempBuff2;
+
+ tempD1 = ( 1.0f / ( 6 * interp_factor2 * interp_factor2 * interp_factor2 ) );
+ tempD2 = 3.0f * tempD1;
+ for ( tempF1 = d * factor - signShift, k = 0; k < N - 1; k++, tempF1 += ( factor - signShift ) )
+ {
+ tempF = tempF1 * spread_factor2 - 1;
+ lim1 = (int16_t) ( tempF );
+ if ( lim1 > tempF )
+ {
+ lim1--;
+ }
+
+ y[0] = ptr1[lim1];
+ y[1] = ptr1[lim1 + 1];
+ y[2] = ptr1[lim1 + 2];
+ y[3] = ptr1[lim1 + 3];
+
+ x[0] = lim1 * interp_factor2;
+ x[1] = x[0] + interp_factor2;
+ x[2] = x[1] + interp_factor2;
+ x[3] = x[2] + interp_factor2;
+
+ ptr2[k] = (float) ( ( y[3] * ( ( tempF1 - x[0] ) * ( tempF1 - x[1] ) * ( tempF1 - x[2] ) ) - y[0] * ( ( tempF1 - x[1] ) * ( tempF1 - x[2] ) * ( tempF1 - x[3] ) ) ) * tempD1 + ( y[1] * ( ( tempF1 - x[0] ) * ( tempF1 - x[2] ) * ( tempF1 - x[3] ) ) - y[2] * ( ( tempF1 - x[0] ) * ( tempF1 - x[1] ) * ( tempF1 - x[3] ) ) ) * tempD2 );
+ }
+
+ ptr1 = target;
+ mvr2r( ptr2, ptr1, N - 1 );
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * Function targetCh_AlignStereoDFT()
+ *
+ * Align target channel in DFT stereo to correct for shift variations
+ * ---------------------------------------------------------------*/
+
+static void targetCh_AlignStereoDFT(
+ float *target,
+ const int16_t prevShift,
+ const int16_t currShift,
+ const int16_t L_shift_adapt )
+{
+ int16_t i;
+ float winSlope, alpha;
+ int16_t d;
+
+ float fadeOutBuff[L_SHIFT_ADAPT_MAX];
+ float fadeInBuff[L_SHIFT_ADAPT_MAX];
+
+ d = -( currShift - prevShift );
+
+ mvr2r( target + d, fadeOutBuff, L_shift_adapt );
+ mvr2r( target, fadeInBuff, L_shift_adapt );
+
+ if ( L_shift_adapt > 0 )
+ {
+ alpha = 0;
+ winSlope = 1.0f / L_shift_adapt;
+ for ( i = 0; i < L_shift_adapt; i++ )
+ {
+ target[i] = alpha * fadeInBuff[i] + ( 1 - alpha ) * fadeOutBuff[i];
+ alpha += winSlope;
+ }
+ }
+ else
+ {
+ mvr2r( fadeInBuff, target, L_shift_adapt );
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------
+ * adjustTargetSignal()
+ *
+ * Target signal correction for shift variations.
+ * ---------------------------------------------------------------*/
+
+void adjustTargetSignal(
+ float *target,
+ const int16_t prevShift,
+ const int16_t currShift,
+ const int16_t L_shift_adapt,
+ const int16_t method )
+{
+ /* inter-frame shift variation and target shifting */
+
+ if ( method == 0 )
+ {
+ interpTargetChannel( target, prevShift, currShift, L_shift_adapt );
+ }
+ else
+ {
+ targetCh_AlignStereoDFT( target, prevShift, currShift, L_shift_adapt );
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_stereo_mdct_bands_com.c b/lib_com/ivas_stereo_mdct_bands_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..35524a20a1a5c6c16675e86f1a869866e718a395
--- /dev/null
+++ b/lib_com/ivas_stereo_mdct_bands_com.c
@@ -0,0 +1,246 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "ivas_prot.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local union
+ *-------------------------------------------------------------------*/
+
+#ifndef BASOP_NOGLOB
+typedef union
+#else /* BASOP_NOGLOB */
+typedef union
+#endif /* BASOP_NOGLOB */
+{
+ MDCTStereoBands_config const *steBands;
+ SpectrumWarping const *lpcBndsParam;
+} SBPARAMS;
+
+
+/*-------------------------------------------------------------------*
+ * stereo_mdct_init_bands()
+ *
+ * initialize stereo band tables for MDCT stereo
+ *-------------------------------------------------------------------*/
+
+void stereo_mdct_init_bands(
+ const int16_t L_frame, /* i : frame length */
+ const int16_t tmp_tcx_mode, /* i : tcx mode (TCX10, TCX 20), -1 if transition frame */
+ const int32_t element_brate, /* i : element bitrate */
+ const int16_t igf, /* i : flag indicating if IGF is used */
+ const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */
+ int16_t *sfbOffset, /* o : sfb offset table */
+ int16_t *sfbCnt /* o : number of sfbs */
+)
+{
+ SBPARAMS sfbParam;
+ int16_t i, cnt, specStartOffset, L_frameTCX, tcx_mode;
+ const uint8_t *sfbWidths;
+
+ if ( tmp_tcx_mode > 0 )
+ {
+ tcx_mode = tmp_tcx_mode;
+ L_frameTCX = ( tcx_mode == TCX_20_CORE ) ? L_frame : ( L_frame / 2 );
+ }
+ else
+ {
+ /*transition frame*/
+ L_frameTCX = L_frame + L_frame / 4;
+ tcx_mode = TCX_20_CORE;
+ }
+
+ /* select table */
+ if ( L_frame == L_FRAME48k )
+ {
+ sfbParam.steBands = mdctStereoBands_32000_640;
+
+ cnt = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bdnCnt_TCX20[0] : sfbParam.steBands->bndCnt_TCX10[0] );
+
+ sfbWidths = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10 );
+ }
+ else
+ {
+ if ( element_brate < IVAS_96k )
+ {
+ sfbParam.steBands = mdctStereoBands_32000_640;
+
+ switch ( L_frame )
+ {
+ case L_FRAME32k:
+ cnt = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bdnCnt_TCX20[1] : sfbParam.steBands->bndCnt_TCX10[1] );
+ break;
+ case L_FRAME25_6k:
+ cnt = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bdnCnt_TCX20[2] : sfbParam.steBands->bndCnt_TCX10[2] );
+ break;
+ case L_FRAME16k:
+ cnt = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bdnCnt_TCX20[3] : sfbParam.steBands->bndCnt_TCX10[3] );
+ break;
+ default:
+ assert( !"Subband division not defined for this frame size" );
+ return;
+ }
+
+ sfbWidths = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10 );
+ }
+ else
+ {
+ switch ( L_frame )
+ {
+ case L_FRAME48k:
+ case L_FRAME32k:
+ sfbParam.lpcBndsParam = sw32000Hz;
+ break;
+ case L_FRAME25_6k:
+ sfbParam.lpcBndsParam = sw25600Hz;
+ break;
+ case L_FRAME16k:
+ sfbParam.lpcBndsParam = sw16000Hz;
+ break;
+ default:
+ assert( !"Subband division not defined for this frame size" );
+ return;
+ }
+
+ sfbWidths = ( tcx_mode == TCX_20_CORE ? sfbParam.lpcBndsParam->bandLengthsTCX20 : sfbParam.lpcBndsParam->bandLengthsTCX10 );
+ cnt = 64;
+ }
+ }
+
+ /* calc sfb offsets */
+ specStartOffset = 0;
+
+ for ( i = 0; i < cnt; i++ )
+ {
+ sfbOffset[i] = min( specStartOffset, L_frameTCX );
+ specStartOffset += sfbWidths[i];
+
+ if ( sfbOffset[i] >= L_frameTCX )
+ {
+ break;
+ }
+ }
+
+ *sfbCnt = i;
+ sfbOffset[*sfbCnt] = min( specStartOffset, L_frameTCX );
+
+ if ( igf )
+ {
+ int16_t sfbOldCnt = *sfbCnt;
+ int16_t igfSfbStep = hIgfGrid->infoIsRefined ? 2 : 1;
+ int16_t k;
+
+ /* modify sfb bands according to igf grid */
+ assert( hIgfGrid != NULL );
+
+ /* find sfb where IGF starts */
+ for ( i = 0; i <= *sfbCnt; i++ )
+ {
+ if ( sfbOffset[i] >= hIgfGrid->startLine )
+ {
+ /* set band border to igf start line */
+ sfbOffset[i] = hIgfGrid->startLine;
+ *sfbCnt = i;
+ break;
+ }
+ }
+ /* change bands above the igf start line to match igf bands */
+ for ( i = 1, k = igfSfbStep; i < hIgfGrid->swb_offset_len; i++, k += igfSfbStep )
+ {
+ sfbOffset[*sfbCnt + i] = hIgfGrid->swb_offset[k];
+ }
+
+ *sfbCnt += ( hIgfGrid->swb_offset_len - 1 );
+
+ /* better save than sorry, overwrite anything that is left above */
+ for ( i = *sfbCnt + 1; i < sfbOldCnt + 1; i++ )
+ {
+ sfbOffset[i] = 0;
+ }
+ }
+ else
+ {
+ if ( sfbOffset[*sfbCnt] < L_frameTCX )
+ {
+ int16_t nMissingBins = L_frameTCX - sfbOffset[*sfbCnt];
+ if ( sfbWidths[i] / 2 < nMissingBins )
+ {
+ ( *sfbCnt )++;
+ }
+ sfbOffset[*sfbCnt] = L_frameTCX;
+ }
+ }
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * stereo_mdct_init_igf_start_band()
+ *
+ * initialize start band of the IGF in MDCT stereo
+ *-------------------------------------------------------------------*/
+
+void stereo_mdct_init_igf_start_band(
+ STEREO_MDCT_BAND_PARAMETERS *stbParams, /* i/o: stereo frequency band parameters */
+ const float transFac, /* i : transform factor */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int32_t element_brate /* i : element bitrate */
+)
+{
+ int16_t i, bitRateIndex, igfStartLine;
+ const int16_t *swb_offset;
+
+ bitRateIndex = IGF_MapBitRateToIndex( element_brate, bwidth, IVAS_CPE_MDCT, 0 );
+ swb_offset = &swb_offset_LB_new[bitRateIndex][1];
+ igfStartLine = IGF_ApplyTransFac( swb_offset[0], transFac );
+
+ for ( i = 0; i < stbParams->sfbCnt; i++ )
+ {
+ if ( igfStartLine == stbParams->sfbOffset[i] )
+ {
+ stbParams->sfbIgfStart = i;
+ break;
+ }
+ }
+
+ stbParams->nBandsStereoCore = stbParams->sfbIgfStart;
+
+
+ return;
+}
diff --git a/lib_com/ivas_stereo_mdct_stereo_com.c b/lib_com/ivas_stereo_mdct_stereo_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..c9151b72df87f1e9d08b63734f7177c668f85579
--- /dev/null
+++ b/lib_com/ivas_stereo_mdct_stereo_com.c
@@ -0,0 +1,65 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "ivas_prot.h"
+#include "wmc_auto.h"
+#include
+
+/*-------------------------------------------------------------------*
+ * splitAvailableBits()
+ *
+ * split available bits between channels based on the split ratio
+ *-------------------------------------------------------------------*/
+
+void splitAvailableBits(
+ const int16_t total_bits, /* i : total available bits for TCX coding */
+ const int16_t split_ratio, /* i : split ratio */
+ const int16_t isSBAStereoMode, /* i : signal core coding for SBA */
+ int16_t *bits_ch0, /* o : bits for channel 0 */
+ int16_t *bits_ch1 /* o : bits for channel 1 */
+)
+{
+ assert( split_ratio >= 1 && split_ratio < SMDCT_BITRATE_RATIO_RANGE );
+
+ *bits_ch0 = split_ratio * total_bits / SMDCT_BITRATE_RATIO_RANGE;
+ /* for SBA mode bias the distribution towards the W channel */
+ if ( split_ratio < 7 && isSBAStereoMode )
+ {
+ *bits_ch0 += (int16_t) ( 0.2 * *bits_ch0 );
+ }
+ *bits_ch1 = total_bits - *bits_ch0;
+
+ return;
+}
diff --git a/lib_com/ivas_stereo_psychlpc_com.c b/lib_com/ivas_stereo_psychlpc_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..ac94d56b0224fe07d8e896dcb5197622559e663b
--- /dev/null
+++ b/lib_com/ivas_stereo_psychlpc_com.c
@@ -0,0 +1,159 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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_rom_com.h"
+#include "ivas_prot.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "wmc_auto.h"
+#include
+
+/*-------------------------------------------------------------------*
+ * SpectrumWeighting_Init()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void SpectrumWeighting_Init(
+ SpectrumWarping const *pSpectrumWarping,
+ const int16_t isTCX20,
+ PsychoacousticParameters *pPsychParams )
+{
+ if ( isTCX20 )
+ {
+ pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX20;
+ }
+ else
+ {
+ pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX10;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * PsychoacousticParameters_Init()
+ *
+ * initialize a PsychoacousticParameters structure
+ *-------------------------------------------------------------------*/
+
+ivas_error PsychoacousticParameters_Init(
+ const int32_t sr_core, /* i : sampling rate of core-coder */
+ const int16_t nBins, /* i : Number of bins (spectral lines) */
+ const int8_t nBands, /* i : Number of spectrum subbands */
+ const int16_t isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */
+ const int16_t isWarped, /* i : Flag indicating if the scale is linear or warped */
+ PsychoacousticParameters *pPsychParams )
+{
+
+ if ( pPsychParams == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "PsychParams handle is NULL" );
+ }
+
+ pPsychParams->nBins = nBins;
+ pPsychParams->nBands = nBands;
+
+ if ( !isWarped )
+ {
+ pPsychParams->bandLengths = NULL;
+ }
+ else
+ {
+ assert( pPsychParams->nBands == 64 );
+ switch ( sr_core )
+ {
+ case 16000:
+ SpectrumWeighting_Init( sw16000Hz, isTCX20, pPsychParams );
+ break;
+ case 25600:
+ SpectrumWeighting_Init( sw25600Hz, isTCX20, pPsychParams );
+ break;
+ case 32000:
+ SpectrumWeighting_Init( sw32000Hz, isTCX20, pPsychParams );
+ break;
+ default:
+ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Subband division not defined for this sampling rate" );
+ }
+ }
+
+ return IVAS_ERR_OK;
+}
+
+/*-------------------------------------------------------------------*
+ * InitPsychLPC()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void InitPsychLPC(
+ const int32_t sr_core, /* i : sampling rate of core-coder */
+ const int16_t L_frame, /* i : frame length */
+ const TCX_CONFIG_HANDLE hTcxCfg /* i : TCX configuration handle */
+)
+{
+ int16_t L_frame_ext = L_frame + L_frame / 4;
+
+ hTcxCfg->psychParamsCurrent = NULL;
+
+ PsychoacousticParameters_Init( sr_core, L_frame / 2, 64, 0, 1, &hTcxCfg->psychParamsTCX10 );
+ PsychoacousticParameters_Init( sr_core, L_frame, 64, 1, 1, &hTcxCfg->psychParamsTCX20 );
+ PsychoacousticParameters_Init( sr_core, L_frame_ext, 64, 1, 0, &hTcxCfg->psychParamsTCX20AfterACELP );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * SetCurrentPsychParams()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void SetCurrentPsychParams(
+ const int16_t core,
+ const int16_t last_frame_was_concealed_cng,
+ TCX_CONFIG_HANDLE hTcxCfg )
+{
+ if ( hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP && !last_frame_was_concealed_cng )
+ {
+ assert( core == TCX_20_CORE );
+ hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX20AfterACELP;
+ }
+ else
+ {
+ hTcxCfg->psychParamsCurrent = ( core == TCX_10_CORE ) ? &hTcxCfg->psychParamsTCX10 : &hTcxCfg->psychParamsTCX20;
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c
new file mode 100644
index 0000000000000000000000000000000000000000..41a552162002b44eedc36819896e3f6530923b46
--- /dev/null
+++ b/lib_com/ivas_stereo_td_bit_alloc.c
@@ -0,0 +1,734 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "stat_enc.h"
+#include "rom_com.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
+#include "ivas_cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------------------------*/
+
+#define NB_RATE_POSS 10 /* Nmbr of possible FCB bitrate for half rate mode*/
+#define MIN_SEC_ACB_RATE ( 2 * 8 * FRAMES_PER_SEC ) /* 2 subfr ACB bitrate */
+#define MIN_SEC_LPC_RATE ( ( 24 + 2 ) * FRAMES_PER_SEC ) /* LPC min rate */
+
+#define MAX_SC_FCB_RATE ( 24 + 1 ) /* Maximum bit for a FCB subfr */
+#define MIN_4SUBFR_FCB_RATE 40 /* Minimum 4 subfr bitrate (4x10 bits) */
+#define MIN_GAIN_BITS 6 /* Minimum number of bits used */
+
+#define TDM_UC_NORMAL_MODE_MBRATE 9000 /* Max bitrate for normal UC if LP coded */
+#define TDM_UC_NORMAL_MODE_MBRATE_LP_R 8200 /* Normal bitrate for normal UC if LP is reused */
+#define TDM_UC_NORMAL_MODE_MINBR_LP_R 7000 /* If bitrate is below 7k, add back MID_LP_BRATE */
+#define MID_LP_BRATE ( 31 + 5 ) * FRAMES_PER_SEC /* average bitrate for LP */
+#define MAX_TDM_UC_BRATE 11000 /* Maximum bitrate for tdm normal UC mode */
+
+#define MIN_SIGN_RATE ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS * FRAMES_PER_SEC ) /* min. 2 time 12 bits FCB, used only when LPC and/or pitch is transmitted */
+#define MIN_FCB_SECRATE2 ( 2 * 16 * FRAMES_PER_SEC ) /* min. 2 time 14 bits FCB, used only when LPC and/or pitch is transmitted */
+
+
+/*-------------------------------------------------------------------*
+ * tdm_bit_alloc()
+ *
+ * Bitbudget distribution between Primary and Secondary channel in TD stereo
+ *-------------------------------------------------------------------*/
+
+void tdm_bit_alloc(
+ const int16_t ivas_format, /* i : IVAS format */
+ const int16_t ism_mode, /* i : ISM mode in combined format */
+ const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */
+ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */
+ int32_t *total_brate_pri, /* o : Allocated primary channel bitrate */
+ int32_t *total_brate_sec, /* o : Allocated secondary channel bitrate */
+ int16_t *tdm_low_rate_mode, /* o : secondary channel low rate mode flag*/
+ const int16_t coder_type, /* i : secondary channel coder type */
+ const int16_t ener_ratio_idx, /* i : correlation ratio indexe */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const int16_t bwidth_pri, /* i : bandwidth of the primary channel */
+ const int16_t bwidth_sec, /* i : bandwidth of the secondary channel */
+ const int16_t flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan.*/
+ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */
+ const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */
+ const int16_t tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */
+)
+{
+ int16_t idx, four_subfr_fcb, two_subfr_fcb;
+ float bit_rate_diff;
+ int16_t BWE_brate, tmp_bits;
+ int16_t tdm_inst_ratio_idx = tdm_inst_ratio_idx_ref;
+ if ( tdm_inst_ratio_idx == TDM_NQ )
+ {
+ tdm_inst_ratio_idx = LRTD_STEREO_MID_IS_PRIM; /* Bit rate almost split half and half*/
+ }
+
+ /* Decision on using the low rate mode or the normal mode */
+ /* default is using the low rate mode for the secondary channel coding*/
+ /* UC and IC are automatically coded with low rate mode */
+ *tdm_low_rate_mode = 1;
+
+ /* Allocating different bitrate to channels */
+ idx = 0;
+ if ( element_brate_wo_meta <= IVAS_13k2 )
+ {
+ idx = 0;
+ }
+ else if ( element_brate_wo_meta <= IVAS_16k4 )
+ {
+ idx = 1;
+ }
+ else if ( element_brate_wo_meta <= IVAS_24k4 )
+ {
+ idx = 2;
+ }
+ else if ( element_brate_wo_meta <= IVAS_32k )
+ {
+ idx = 3;
+ }
+ else if ( element_brate_wo_meta <= IVAS_48k )
+ {
+ idx = 4;
+ }
+
+ if ( coder_type == UNVOICED && tdm_bit_allc_tbl[idx][coder_type] >= 4200 )
+ {
+ *tdm_low_rate_mode = 0;
+ }
+
+ /* Secondary channel based bitrate allocation */
+ *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type];
+
+ /* secondary channel bitrate allocation based on the energy scaling ratio */
+ if ( ( ( ivas_format != MASA_ISM_FORMAT || ism_mode == ISM_MODE_NONE ) && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && coder_type > UNVOICED ) )
+ {
+ bit_rate_diff = (float) ( element_brate_wo_meta - 2 * *total_brate_sec );
+
+ if ( tdm_LRTD_flag == 1 ) /* > element_brate > STEREO_22k or CT0 not used */
+ {
+ /* further adjustment in function of the energy/correlation ratio */
+ if ( coder_type == INACTIVE )
+ {
+ *total_brate_sec = max( *total_brate_sec, (int16_t) ( 0.3f * ( element_brate_wo_meta - 500 ) / 100 ) * 100 );
+ tmp_bits = (int16_t) ( -abs( tdm_inst_ratio_idx - 16 ) * 200 * idx );
+ }
+ else
+ {
+ *total_brate_sec = max( *total_brate_sec, (int16_t) ( 0.5f * ( element_brate_wo_meta - 500 ) / 100 ) * 100 );
+ /* tmp_bits = -abs(tdm_inst_ratio_idx-16)*200*idx; */
+ tmp_bits = (int16_t) ( -abs( tdm_inst_ratio_idx - 16 ) * 100 * idx );
+ }
+
+ /* tmp_bits should be subtract from the secondary channel bitrate */
+ /* If the primary channel doesn't correspond to the channel having the highest correlation to the mono- inverse the bitrate compensation */
+ if ( ( ener_ratio_idx >= LRTD_STEREO_MID_IS_PRIM && tdm_inst_ratio_idx < LRTD_STEREO_MID_IS_PRIM ) || ( ener_ratio_idx < LRTD_STEREO_MID_IS_PRIM && tdm_inst_ratio_idx >= LRTD_STEREO_MID_IS_PRIM ) )
+ {
+ tmp_bits *= -1;
+ }
+ bit_rate_diff = tmp_bits;
+ }
+ else
+ {
+ if ( ener_ratio_idx < LRTD_STEREO_MID_IS_PRIM )
+ {
+ bit_rate_diff = ( LRTD_STEREO_MID_IS_PRIM - ener_ratio_idx ) * bit_rate_diff * 0.05f;
+ }
+ else
+ {
+ bit_rate_diff = ( ener_ratio_idx - LRTD_STEREO_MID_IS_PRIM ) * bit_rate_diff * 0.05f;
+ }
+ }
+ /*bit_rate_diff2 = ((int16_t)(10.f*(-0.5f*ener_ratio_LR+0.5f)*bit_rate_diff)/100)*100;*/
+ *total_brate_sec += ( (int16_t) ( bit_rate_diff / 100 ) * 100 );
+ *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] );
+
+ if ( coder_type == INACTIVE && tdm_LRTD_flag == 0 )
+ {
+ *total_brate_sec = min( *total_brate_sec, MIN_BRATE_SWB_BWE );
+ }
+
+ if ( ( ener_ratio_idx <= 1 || ener_ratio_idx >= 29 ) && coder_type >= UNVOICED )
+ {
+ int16_t delta_brate = 0;
+
+ if ( bwidth_pri > WB )
+ {
+ delta_brate = 600; /* To slightly compensate for SWB BWE instead of WB BWE */
+ if ( element_brate_wo_meta <= IVAS_16k4 )
+ {
+ delta_brate = 1250; /* To compensate for SWB BWE instead of WB BWE */
+ }
+ }
+
+ if ( element_brate_wo_meta <= IVAS_13k2 )
+ {
+ *total_brate_sec = max( *total_brate_sec, 5600 + delta_brate ); /* ~42-47 % of the total bitrate */
+ }
+ else if ( element_brate_wo_meta <= IVAS_16k4 )
+ {
+ *total_brate_sec = max( *total_brate_sec, 6500 + delta_brate ); /* ~40-43 % of the total bitrate */
+ }
+ else if ( element_brate_wo_meta <= IVAS_24k4 )
+ {
+ *total_brate_sec = max( *total_brate_sec, 9000 + delta_brate ); /* ~37-39 % of the total bitrate */
+ }
+ else
+ {
+ *total_brate_sec = max( *total_brate_sec, 9600 + delta_brate ); /* ~30-32% of the total bitrate */
+ }
+ }
+ else
+ {
+ *total_brate_sec = min( *total_brate_sec, (int16_t) ( 0.0045f * element_brate_wo_meta ) * 100 );
+ }
+
+ *total_brate_sec = min( *total_brate_sec, 18000 );
+ }
+ else if ( coder_type == UNVOICED )
+ {
+ if ( tdm_lp_reuse_flag == 0 )
+ {
+ *total_brate_sec += ( 31 + 5 ) * FRAMES_PER_SEC;
+ }
+ }
+
+ if ( coder_type <= UNVOICED )
+ {
+ *total_brate_sec = min( *total_brate_sec, MAX_TDM_UC_BRATE );
+
+ if ( *total_brate_sec >= TDM_UC_NORMAL_MODE_MBRATE && tdm_lp_reuse_flag == 0 )
+ {
+ *tdm_low_rate_mode = 0;
+ }
+ else if ( *total_brate_sec >= TDM_UC_NORMAL_MODE_MBRATE_LP_R )
+ {
+ *tdm_low_rate_mode = 0;
+ }
+ else if ( ( tdm_lp_reuse_flag == 0 && *total_brate_sec < TDM_UC_NORMAL_MODE_MINBR_LP_R && coder_type == UNVOICED ) || ( tdm_lp_reuse_flag == 0 && *total_brate_sec < ( tdm_bit_allc_tbl[idx][0] + MID_LP_BRATE ) ) )
+ {
+ *total_brate_sec += MID_LP_BRATE;
+ }
+ }
+
+ /* verify that primary channel bitrate is higher than the minimum supported bitrate */
+ if ( flag_ACELP16k_pri )
+ {
+ BWE_brate = SWB_TBE_1k75;
+ if ( element_brate_wo_meta < IVAS_24k4 )
+ {
+ BWE_brate = SWB_TBE_1k10;
+ }
+
+ if ( bwidth_pri > WB && tdm_LRTD_flag == 0 )
+ {
+ BWE_brate += ( STEREO_BITS_ICBWE + STEREO_ICBWE_MSFLAG_BITS ) * FRAMES_PER_SEC;
+ }
+ if ( bwidth_pri > SWB && tdm_LRTD_flag == 1 )
+ {
+ BWE_brate += 300;
+ }
+
+ if ( bwidth_pri == FB )
+ {
+ BWE_brate += ( FB_TBE_1k8 - SWB_TBE_1k75 );
+ }
+
+ if ( element_brate_wo_meta - *total_brate_sec - BWE_brate < 14000 )
+ {
+ *total_brate_sec = element_brate_wo_meta - 14000 - BWE_brate;
+ }
+ }
+ else
+ {
+ BWE_brate = SWB_TBE_1k75;
+ if ( bwidth_pri == WB )
+ {
+ BWE_brate = WB_BWE_0k35;
+ if ( tdm_LRTD_flag == 0 )
+ {
+ BWE_brate += 250; /* ICA Brate */
+ }
+ }
+ else if ( tdm_LRTD_flag == 0 )
+ {
+ BWE_brate += 350; /* ICA Brate */
+ }
+ }
+
+ if ( coder_type0 == TRANSITION )
+ {
+ if ( element_brate_wo_meta > IVAS_13k2 )
+ {
+ *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( ACELP_8k00 + BWE_brate ) );
+ }
+ else
+ {
+ *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( ACELP_7k20 + BWE_brate ) );
+ }
+ }
+ else
+ {
+ *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( 5900 + BWE_brate ) );
+
+ if ( coder_type == INACTIVE )
+ {
+ *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[0][0] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */
+ }
+ else
+ {
+ *total_brate_sec = max( *total_brate_sec, 3500 ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */
+ }
+ }
+
+ /* Secondary channel bitrate adjusment */
+ /* First, adjust the bitrate depending of what is transmitted */
+ /* Second, choose the number of subframe for ACELP core depending of the targetted bitratre */
+ /* Finally, verify that the concordance between the number of subframe, the parameters sent and the bitrate available */
+ if ( coder_type == GENERIC /* || coder_type == AUDIO*/ )
+ {
+ /* Adjust the bitrate depending of what is transmitted */
+ /* If LPC are transmitted, ensure enough bits are used */
+ if ( tdm_lp_reuse_flag == 0 )
+ {
+ /* Pitch is transmitted as well, further increase the bitrate */
+ if ( tdm_Pitch_reuse_flag == 0 )
+ {
+ *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE );
+
+ if ( tdm_LRTD_flag == 1 && bwidth_sec == SWB )
+ {
+ /* ensure that there are enough bits to code SWB TBE_1k10 as well */
+ *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE + SWB_TBE_1k10 );
+ }
+ }
+ else /* only LPC is tranmitted -> if ( *total_brate_sec < MIN_SEC_BRATE+MIN_SEC_LPC_RATE ) */
+ {
+ *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_LPC_RATE + MIN_SIGN_RATE );
+ }
+ }
+ else if ( /*tdm_lp_reuse_flag == 1*/ tdm_Pitch_reuse_flag == 0 )
+ {
+ *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SIGN_RATE );
+ }
+
+ /* Choose between 2 and 4 subfr, depending of the bitrate available and prevent the gap between the 2 atlernative */
+ if ( tdm_LRTD_flag == 1 )
+ {
+ four_subfr_fcb = (int16_t) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC );
+ two_subfr_fcb = (int16_t) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC );
+ }
+ else
+ {
+ four_subfr_fcb = (int16_t) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC );
+ two_subfr_fcb = (int16_t) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC );
+ }
+
+ if ( tdm_lp_reuse_flag == 0 )
+ {
+ four_subfr_fcb -= MIN_SEC_LPC_RATE;
+ two_subfr_fcb -= MIN_SEC_LPC_RATE;
+ }
+
+ if ( tdm_Pitch_reuse_flag == 0 )
+ {
+ four_subfr_fcb -= ( MIN_SEC_ACB_RATE + 10 * FRAMES_PER_SEC );
+ two_subfr_fcb -= MIN_SEC_ACB_RATE;
+ }
+
+ /* Too much bits for the 2 subfr model but not enough for the the 4 subfr model -> slightly reduce the 2nd channel bitrate */
+ if ( two_subfr_fcb > 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC && four_subfr_fcb < MIN_4SUBFR_FCB_RATE * FRAMES_PER_SEC )
+ {
+ if ( tdm_LRTD_flag == 1 )
+ {
+ *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC;
+ }
+ else
+ {
+ *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC;
+ }
+
+ if ( tdm_lp_reuse_flag == 0 )
+ {
+ *total_brate_sec += MIN_SEC_LPC_RATE;
+ }
+
+ if ( tdm_Pitch_reuse_flag == 0 )
+ {
+ *total_brate_sec += MIN_SEC_ACB_RATE;
+ }
+ }
+ else if ( four_subfr_fcb >= ( 40 ) * FRAMES_PER_SEC ) /* Enough bits to have minimally 2 x 12 + 2*7 bits FCB */
+ {
+ *tdm_low_rate_mode = 0; /* Use normal rate mode */
+ }
+ else /* Possible slight increase of secondary channel bit budget to compensate for FCB limited flexibility */
+ {
+ int16_t tmp_rate, i;
+ tmp_rate = two_subfr_fcb;
+ idx = NB_RATE_POSS - 2;
+
+ for ( i = 0; i < NB_RATE_POSS; i++ )
+ {
+ if ( tmp_rate <= fast_FCB_rates_2sfr[i] )
+ {
+ idx = i;
+ break;
+ }
+ }
+ *total_brate_sec += ( fast_FCB_rates_2sfr[idx] - tmp_rate );
+ }
+ /* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */
+ if ( element_brate_wo_meta - *total_brate_sec == ACELP_13k20 )
+ {
+ *total_brate_sec += 100;
+ }
+ }
+ /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */
+ if ( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 )
+ {
+ *total_brate_sec -= 100;
+ }
+
+ *total_brate_pri = element_brate_wo_meta - *total_brate_sec;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * td_stereo_param_updt()
+ *
+ * copy certain TD stereo parameters from primary channel to secondary channel
+ *-------------------------------------------------------------------*/
+
+void td_stereo_param_updt(
+ const float lsp_old_PCh[], /* i : primary channel old LSPs */
+ const float lsf_old_PCh[], /* i : primary channel old LSFs */
+ const float pitch_buf_PCh[], /* i : primary channel pitch buffer */
+ float tdm_lspQ_PCh[], /* o : Q LSPs for primary channel */
+ float tdm_lsfQ_PCh[], /* o : Q LSFs for primary channel */
+ float tdm_Pri_pitch_buf[], /* o : pitch values for primary channel */
+ const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */
+ const int16_t tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */
+)
+{
+ int16_t i;
+
+ /* Copy some primary channel information into the secondary channel structure for later usage */
+ if ( tdm_use_IAWB_Ave_lpc == 1 )
+ {
+ mvr2r( IAWB_Ave, tdm_lsfQ_PCh, M );
+ lsf2lsp( tdm_lsfQ_PCh, tdm_lspQ_PCh, M, INT_FS_12k8 );
+ }
+ else if ( flag_ACELP16k == 1 )
+ {
+ mvr2r( lsp_old_PCh, tdm_lspQ_PCh, M );
+ lsp_convert_poly( tdm_lspQ_PCh, L_FRAME, 0 );
+ lsp2lsf( tdm_lspQ_PCh, tdm_lsfQ_PCh, M, INT_FS_12k8 );
+ }
+ else
+ {
+ mvr2r( lsp_old_PCh, tdm_lspQ_PCh, M );
+ mvr2r( lsf_old_PCh, tdm_lsfQ_PCh, M );
+ }
+
+ /* This is only to keep the buffer up-to-date */
+ if ( flag_ACELP16k == 1 )
+ {
+ for ( i = 0; i < NB_SUBFR; i++ )
+ {
+ tdm_Pri_pitch_buf[i] = pitch_buf_PCh[i] * 0.8f;
+ tdm_Pri_pitch_buf[i] = max( tdm_Pri_pitch_buf[i], PIT_MIN );
+ }
+ }
+ else
+ {
+ mvr2r( pitch_buf_PCh, tdm_Pri_pitch_buf, NB_SUBFR );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tdm_SCh_LSF_intra_pred_zero_bits()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void tdm_SCh_LSF_intra_pred_zero_bits(
+ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */
+ float *pred_lsf_SCh, /* o : predicted secondary channel LSFs */
+ const float *lsf_mean, /* i : secondary channel mean LSFs */
+ const float beta /* i : pull to average beta factor */
+)
+{
+ int16_t i;
+
+ /* pulling the LSFs closer to the average */
+ for ( i = 0; i < M; i++ )
+ {
+ pred_lsf_SCh[i] = beta * tdm_lsfQ_PCh[i] + ( 1.0f - beta ) * lsf_mean[i];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tdm_SCh_LSF_intra_pred_tri_diag_mat()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void tdm_SCh_LSF_intra_pred_tri_diag_mat(
+ float *lsf_SCh, /* i/o: secondary channel LSFs */
+ const float *lsf_mean_in, /* i : secondary channel mean LSFs (in) */
+ const float *lsf_mean_out, /* i : secondary channel mean LSFs (out) */
+ const float *prd_diag_3 /* i : secondary channel mean LSFs */
+)
+{
+ int16_t i;
+ float lsf_tmp[M];
+ const float *prd_ptr;
+ float *lsf_tmp_ptr1;
+ float *lsf_tmp_ptr2;
+ float *lsf_SCh_ptr;
+
+ prd_ptr = prd_diag_3;
+
+ v_sub( lsf_SCh, lsf_mean_in, lsf_tmp, M );
+
+ lsf_tmp_ptr1 = lsf_tmp;
+ lsf_SCh_ptr = lsf_SCh;
+
+ lsf_tmp_ptr2 = lsf_tmp_ptr1;
+ *lsf_SCh_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ );
+ ( *lsf_SCh_ptr++ ) += ( *lsf_tmp_ptr1 ) * ( *prd_ptr++ );
+
+ for ( i = 1; i < M - 1; i++ )
+ {
+ lsf_tmp_ptr1 = lsf_tmp_ptr2;
+ *lsf_SCh_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ );
+ lsf_tmp_ptr2 = lsf_tmp_ptr1;
+ *lsf_SCh_ptr += ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ );
+ ( *lsf_SCh_ptr++ ) += ( *lsf_tmp_ptr1 ) * ( *prd_ptr++ );
+ }
+
+ lsf_tmp_ptr1 = lsf_tmp_ptr2;
+ *lsf_SCh_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ );
+ *lsf_SCh_ptr += ( *lsf_tmp_ptr1 ) * ( *prd_ptr );
+
+ v_add( lsf_SCh, lsf_mean_out, lsf_SCh, M );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tdm_SCh_LSF_intra_pred()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tdm_SCh_LSF_intra_pred(
+ const int32_t element_brate, /* i : element bitrate */
+ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */
+ float *pred_lsf_SCh /* o : predicted secondary channel LSFs */
+)
+{
+ float fixed_beta;
+
+ if ( element_brate <= IVAS_13k2 )
+ {
+ fixed_beta = 0.87F;
+ }
+ else if ( element_brate <= IVAS_16k4 )
+ {
+ fixed_beta = 0.94F;
+ }
+ else if ( element_brate <= IVAS_24k4 )
+ {
+ fixed_beta = 0.91F;
+ }
+ else if ( element_brate <= IVAS_32k )
+ {
+ fixed_beta = 0.92F;
+ }
+ else
+ {
+ fixed_beta = 0.91F;
+ }
+
+ tdm_SCh_LSF_intra_pred_zero_bits( tdm_lsfQ_PCh, pred_lsf_SCh, tdm_LSF_MEAN_PRED_QNT, fixed_beta );
+
+ tdm_SCh_LSF_intra_pred_tri_diag_mat( pred_lsf_SCh, tdm_LSF_MEAN_PRED_QNT_IN, tdm_LSF_MEAN_PRED_QNT_OUT, tdm_PRED_QNT_fixed_beta_prd_diag_3 );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tdm_SCh_LSF_intra_pred_one_bit_dec()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void tdm_SCh_LSF_intra_pred_one_bit_dec(
+ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */
+ float *pred_lsf_SCh, /* o : predicted secondary channel LSFs */
+ const float *lsf_mean, /* i : secondary channel mean LSFs */
+ const float *Beta_Q_x, /* i : beta quantization values */
+ const int16_t beta_index /* i : the quantization bits for beta (-1 if beta fixed)*/
+)
+{
+ int16_t i;
+ float beta;
+
+ beta = Beta_Q_x[beta_index];
+
+ /* pulling the LSFs closer to the avergae */
+ for ( i = 0; i < M; i++ )
+ {
+ pred_lsf_SCh[i] = beta * tdm_lsfQ_PCh[i] + ( 1.0f - beta ) * lsf_mean[i];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tdm_SCh_LSF_intra_pred_one_bit_enc()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void tdm_SCh_LSF_intra_pred_one_bit_enc(
+ const float *lsf_SCh, /* i : secondary channel LSFs */
+ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */
+ float *pred_lsf_SCh, /* o : predicted secondary channel LSFs */
+ const float *lsf_mean, /* i : secondary channel mean LSFs */
+ const float *lsf_wgts_new, /* i : Improved wgts for LSFs */
+ const float *Beta_Q_x, /* i : beta quantization values */
+ int16_t *beta_index /* o : the quantization bits for beta (-1 if beta fixed) */
+)
+{
+ int16_t i;
+ float A_temp[M];
+ float B_temp[M];
+ float WD[2];
+
+ for ( i = 0; i < M; i++ )
+ {
+ A_temp[i] = lsf_SCh[i] - lsf_mean[i];
+ B_temp[i] = lsf_mean[i] - tdm_lsfQ_PCh[i];
+ }
+
+ WD[0] = 0.f;
+ WD[1] = 0.f;
+ for ( i = 0; i < M; i++ )
+ {
+ WD[0] += lsf_wgts_new[i] * SQR( A_temp[i] ) + 2.0f * Beta_Q_x[0] * lsf_wgts_new[i] * A_temp[i] * B_temp[i] + lsf_wgts_new[i] * SQR( Beta_Q_x[0] ) * SQR( B_temp[i] );
+ WD[1] += lsf_wgts_new[i] * SQR( A_temp[i] ) + 2.0f * Beta_Q_x[1] * lsf_wgts_new[i] * A_temp[i] * B_temp[i] + lsf_wgts_new[i] * SQR( Beta_Q_x[1] ) * SQR( B_temp[i] );
+ }
+
+ if ( WD[0] < WD[1] )
+ {
+ *beta_index = 0;
+ }
+ else
+ {
+ *beta_index = 1;
+ }
+
+ tdm_SCh_LSF_intra_pred_one_bit_dec( tdm_lsfQ_PCh, pred_lsf_SCh, tdm_LSF_MEAN_RE_USE, Beta_Q_x, *beta_index );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tdm_SCh_lsf_reuse()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void tdm_SCh_lsf_reuse(
+ const int16_t enc_dec, /* i : encoder/decoder flag */
+ const int32_t element_brate, /* i : element bitrate */
+ float lsf_new[M], /* i/o: LSFs at the end of the frame */
+ float lsp_new[M], /* i/o: LSPs at the end of the frame */
+ const float tdm_lsfQ_PCh[M], /* i : primary channel LSFs */
+ const float lsf_wgts[M], /* i : LSF weights */
+ int16_t *beta_index /* i/o: quantization index */
+)
+{
+ const float *Beta_Q1bit_re_use;
+
+ if ( element_brate <= IVAS_13k2 )
+ {
+ Beta_Q1bit_re_use = tdm_Beta_Q1bit_re_use_13k2;
+ }
+ else if ( element_brate <= IVAS_16k4 )
+ {
+ Beta_Q1bit_re_use = tdm_Beta_Q1bit_re_use_16k4;
+ }
+ else if ( element_brate <= IVAS_32k )
+ {
+ Beta_Q1bit_re_use = tdm_Beta_Q1bit_re_use_24k4_32k;
+ }
+ else
+ {
+ Beta_Q1bit_re_use = tdm_Beta_Q1bit_re_use_48k;
+ }
+
+ if ( enc_dec == ENC )
+ {
+ tdm_SCh_LSF_intra_pred_one_bit_enc( lsf_new, tdm_lsfQ_PCh, lsf_new, tdm_LSF_MEAN_RE_USE, lsf_wgts, Beta_Q1bit_re_use, beta_index );
+ }
+ else /* DEC */
+ {
+ tdm_SCh_LSF_intra_pred_one_bit_dec( tdm_lsfQ_PCh, lsf_new, tdm_LSF_MEAN_RE_USE, Beta_Q1bit_re_use, *beta_index );
+ }
+
+ tdm_SCh_LSF_intra_pred_tri_diag_mat( lsf_new, tdm_LSF_MEAN_RE_USE_IN, tdm_LSF_MEAN_RE_USE_OUT, tdm_RE_USE_adaptive_beta_prd_diag_3 );
+
+ lsf2lsp( lsf_new, lsp_new, M, INT_FS_12k8 );
+
+ return;
+}
diff --git a/lib_com/ivas_td_decorr.c b/lib_com/ivas_td_decorr.c
new file mode 100644
index 0000000000000000000000000000000000000000..12c4853bcfcd2e4c74c58c8ceac0e426cda6b632
--- /dev/null
+++ b/lib_com/ivas_td_decorr.c
@@ -0,0 +1,501 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "prot.h"
+#include "ivas_prot.h"
+#include "math.h"
+#include
+#include "wmc_auto.h"
+
+
+/*------------------------------------------------------------------------------------------*
+ * Local constants
+ *------------------------------------------------------------------------------------------*/
+
+static const float ivas_hadamard_decorr_APD_coeff[IVAS_APD_16_SECT][IVAS_APD_16_SECT] = {
+ { 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f },
+ { 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f },
+ { 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f },
+ { 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f },
+ { 0.4f, 0.4f, 0.4f, 0.4f, -0.4f, -0.4f, -0.4f, -0.4f, 0.4f, 0.4f, 0.4f, 0.4f, -0.4f, -0.4f, -0.4f, -0.4f },
+ { 0.4f, -0.4f, 0.4f, -0.4f, -0.4f, 0.4f, -0.4f, 0.4f, 0.4f, -0.4f, 0.4f, -0.4f, -0.4f, 0.4f, -0.4f, 0.4f },
+ { 0.4f, 0.4f, -0.4f, -0.4f, -0.4f, -0.4f, 0.4f, 0.4f, 0.4f, 0.4f, -0.4f, -0.4f, -0.4f, -0.4f, 0.4f, 0.4f },
+ { 0.4f, -0.4f, -0.4f, 0.4f, -0.4f, 0.4f, 0.4f, -0.4f, 0.4f, -0.4f, -0.4f, 0.4f, -0.4f, 0.4f, 0.4f, -0.4f },
+ { 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, -0.4f, -0.4f, -0.4f, -0.4f, -0.4f, -0.4f, -0.4f, -0.4f },
+ { 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f },
+ { 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f },
+ { 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f },
+ { 0.4f, 0.4f, 0.4f, 0.4f, -0.4f, -0.4f, -0.4f, -0.4f, -0.4f, -0.4f, -0.4f, -0.4f, 0.4f, 0.4f, 0.4f, 0.4f },
+ { 0.4f, -0.4f, 0.4f, -0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, -0.4f, 0.4f, 0.4f, -0.4f, 0.4f, -0.4f },
+ { 0.4f, 0.4f, -0.4f, -0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, 0.4f, 0.4f, -0.4f, -0.4f },
+ { 0.4f, -0.4f, -0.4f, 0.4f, -0.4f, 0.4f, 0.4f, -0.4f, -0.4f, 0.4f, 0.4f, -0.4f, 0.4f, -0.4f, -0.4f, 0.4f }
+};
+
+/* For R = 3.^([0:obj.parm_APD_nSections-1]/4); */
+static const float ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = {
+ 1.000000000000000f,
+ 1.316074013710022f,
+ 1.732050776481628f,
+ 2.279507160186768f,
+ 3.000000000000000f,
+ 3.948222038857480f,
+ 5.196152422706630f,
+ 6.838521170864330f,
+ 9.000000000000000f,
+ 11.84466611657240f,
+ 15.58845726811990f,
+ 20.51556351259300f,
+ 27.00000000000000f,
+ 35.53399834971730f,
+ 46.76537180435970f,
+ 61.54669053777900f,
+};
+
+#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f )
+#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f )
+
+/*------------------------------------------------------------------------------------------*
+ * Local functions declaration
+ *------------------------------------------------------------------------------------------*/
+
+static int16_t ivas_get_APD_filt_orders( const int16_t num_out_chans, const int32_t output_Fs, int16_t *APD_filt_orders );
+
+static void ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag );
+
+
+/*-------------------------------------------------------------------------
+ * ivas_td_decorr_reconfig_dec()
+ *
+ * Allocate and initialize time domain decorrelator handle
+ *------------------------------------------------------------------------*/
+
+ivas_error ivas_td_decorr_reconfig_dec(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate, /* i : total IVAS bitrate */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int32_t output_Fs, /* i : output sampling rate */
+ ivas_td_decorr_state_t **hTdDecorr, /* i/o: TD decorrelator handle */
+ uint16_t *useTdDecorr /* i/o: TD decorrelator flag */
+)
+{
+ uint16_t useTdDecorr_new;
+ ivas_error error;
+
+ useTdDecorr_new = 0;
+ if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
+ {
+ if ( nchan_transport == 1 )
+ {
+ useTdDecorr_new = 1;
+ }
+ }
+ else if ( ivas_format == MASA_FORMAT )
+ {
+ if ( ( ivas_total_brate < IVAS_48k && nchan_transport == 1 ) || ivas_total_brate < MASA_STEREO_MIN_BITRATE )
+ {
+ useTdDecorr_new = 1;
+ }
+ }
+ else if ( ivas_format == MC_FORMAT )
+ {
+ if ( ivas_total_brate < IVAS_48k && nchan_transport == 1 )
+ {
+ useTdDecorr_new = 1;
+ }
+ }
+
+ if ( *useTdDecorr != useTdDecorr_new )
+ {
+ *useTdDecorr = useTdDecorr_new;
+
+ if ( *useTdDecorr )
+ {
+ if ( ivas_total_brate >= IVAS_13k2 && ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) )
+ {
+ if ( *hTdDecorr == NULL )
+ {
+ if ( ( error = ivas_td_decorr_dec_open( hTdDecorr, output_Fs, 3, 1 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ if ( ivas_total_brate < IVAS_24k4 )
+ {
+ ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR;
+ }
+ else
+ {
+ ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN;
+ }
+ }
+ else
+ {
+ if ( *hTdDecorr == NULL )
+ {
+ if ( ( error = ivas_td_decorr_dec_open( hTdDecorr, output_Fs, 3, 0 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ else
+ {
+ ivas_td_decorr_init( *hTdDecorr, 3, 0 );
+ }
+ }
+ }
+ else
+ {
+ ivas_td_decorr_dec_close( hTdDecorr );
+ }
+ }
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_td_decorr_dec_open()
+ *
+ * Allocate and initialize time domain decorrelator handle
+ *------------------------------------------------------------------------*/
+
+ivas_error ivas_td_decorr_dec_open(
+ ivas_td_decorr_state_t **hTdDecorr, /* i/o: TD decorrelator handle */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const int16_t nchan_internal, /* i : number of internal channels */
+ const int16_t ducking_flag /* i : ducking flag */
+)
+{
+ int16_t i, j, len;
+ int16_t num_out_chans;
+ ivas_td_decorr_state_t *hTdDecorr_loc;
+ ivas_error error;
+
+ num_out_chans = nchan_internal - 1;
+
+ error = IVAS_ERR_OK;
+
+ if ( ( hTdDecorr_loc = (ivas_td_decorr_state_t *) malloc( sizeof( ivas_td_decorr_state_t ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV decoder" );
+ }
+
+ if ( ( hTdDecorr_loc->look_ahead_buf = (float *) malloc( sizeof( float ) * (int16_t) ( output_Fs * IVAS_DECORR_PARM_LOOKAHEAD_TAU ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV decoder" );
+ }
+ set_f( hTdDecorr_loc->look_ahead_buf, 0, (int16_t) ( output_Fs * IVAS_DECORR_PARM_LOOKAHEAD_TAU ) );
+ hTdDecorr_loc->offset = (int16_t) ( output_Fs * IVAS_DECORR_PARM_LOOKAHEAD_TAU );
+ hTdDecorr_loc->num_apd_sections = ivas_get_APD_filt_orders( num_out_chans, output_Fs, hTdDecorr_loc->APD_filt_state[0].order );
+
+ for ( j = 0; j < num_out_chans; j++ )
+ {
+ for ( i = 0; i < hTdDecorr_loc->num_apd_sections; i++ )
+ {
+ len = hTdDecorr_loc->APD_filt_state[0].order[i];
+
+ if ( ( hTdDecorr_loc->APD_filt_state[j].state[i] = (float *) malloc( sizeof( float ) * len ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV decoder" );
+ }
+
+ set_f( hTdDecorr_loc->APD_filt_state[j].state[i], 0, len );
+ }
+ }
+
+ ivas_td_decorr_init( hTdDecorr_loc, num_out_chans, ducking_flag );
+
+ if ( ducking_flag )
+ {
+ if ( ( error = ivas_transient_det_open( &hTdDecorr_loc->pTrans_det, output_Fs ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ else
+ {
+ hTdDecorr_loc->pTrans_det = NULL;
+ }
+
+ *hTdDecorr = hTdDecorr_loc;
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_td_decorr_dec_close()
+ *
+ * Deallocate time domain decorrelator handle
+ *------------------------------------------------------------------------*/
+
+void ivas_td_decorr_dec_close(
+ ivas_td_decorr_state_t **hTdDecorr /* i/o: TD decorrelator handle */
+)
+{
+ int16_t i, j;
+
+ if ( hTdDecorr == NULL || *hTdDecorr == NULL )
+ {
+ return;
+ }
+
+ free( ( *hTdDecorr )->look_ahead_buf );
+ ( *hTdDecorr )->look_ahead_buf = NULL;
+
+ for ( j = 0; j < ( *hTdDecorr )->num_apd_outputs; j++ )
+ {
+ for ( i = 0; i < ( *hTdDecorr )->num_apd_sections; i++ )
+ {
+ free( ( *hTdDecorr )->APD_filt_state[j].state[i] );
+ ( *hTdDecorr )->APD_filt_state[j].state[i] = NULL;
+ }
+ }
+
+ if ( ( *hTdDecorr )->pTrans_det != NULL )
+ {
+ ivas_transient_det_close( &( *hTdDecorr )->pTrans_det );
+ }
+
+ free( ( *hTdDecorr ) );
+ ( *hTdDecorr ) = NULL;
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_get_APD_filt_orders()
+ *
+ * Calculate the orders of the APD IIR filters and return num APD sections
+ *-----------------------------------------------------------------------------------------*/
+
+static int16_t ivas_get_APD_filt_orders(
+ const int16_t num_out_chans,
+ const int32_t output_Fs,
+ int16_t *APD_filt_orders )
+{
+ int16_t i;
+ int16_t num_apd_sections = 0;
+ float sum_R, R[IVAS_MAX_DECORR_APD_SECTIONS];
+
+ switch ( num_out_chans )
+ {
+ case IVAS_TD_DECORR_OUT_1CH:
+ case IVAS_TD_DECORR_OUT_2CH:
+ num_apd_sections = IVAS_APD_2_SECT;
+ break;
+ case IVAS_TD_DECORR_OUT_3CH:
+ case IVAS_TD_DECORR_OUT_4CH:
+ num_apd_sections = IVAS_APD_4_SECT;
+ break;
+ case IVAS_TD_DECORR_OUT_5CH:
+ case IVAS_TD_DECORR_OUT_6CH:
+ case IVAS_TD_DECORR_OUT_7CH:
+ case IVAS_TD_DECORR_OUT_8CH:
+ num_apd_sections = IVAS_APD_8_SECT;
+ break;
+ default:
+ assert( !"Invalid num out chans" );
+ break;
+ }
+
+ sum_R = 0.0f;
+ for ( i = 0; i < num_apd_sections; i++ )
+ {
+ R[i] = ivas_three_pow_frac[i];
+ sum_R += R[i];
+ }
+
+ for ( i = 0; i < num_apd_sections; i++ )
+ {
+ APD_filt_orders[i] = (int16_t) ceil( output_Fs * IVAS_DECORR_PARM_APD_TAU * R[i] / sum_R );
+ }
+
+ return num_apd_sections;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_td_decorr_init()
+ *
+ * TD decorr Initialisation function
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_td_decorr_init(
+ ivas_td_decorr_state_t *hTdDecorr,
+ const int16_t num_out_chans,
+ const int16_t ducking_flag )
+{
+ int16_t i, j;
+
+ hTdDecorr->ducking_flag = ducking_flag;
+ hTdDecorr->num_apd_outputs = num_out_chans;
+
+ for ( i = 0; i < hTdDecorr->num_apd_outputs; i++ )
+ {
+ for ( j = 0; j < hTdDecorr->num_apd_sections; j++ )
+ {
+ hTdDecorr->APD_filt_state[i].order[j] = hTdDecorr->APD_filt_state[0].order[j];
+ hTdDecorr->APD_filt_state[i].coeffs[j] = ivas_hadamard_decorr_APD_coeff[i][j];
+ hTdDecorr->APD_filt_state[i].idx[j] = 0;
+ }
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_td_decorr_APD_iir_filter()
+ *
+ * APD IIR filter
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_td_decorr_APD_iir_filter(
+ ivas_td_decorr_APD_filt_state_t *filter_state,
+ float *pIn_out,
+ const int16_t num_APD_sections,
+ const int16_t length )
+{
+ int16_t i, k;
+ int16_t idx;
+ float *pIn = pIn_out;
+ float *pOut = pIn_out;
+ float tmp_pIn_buf_i;
+
+ for ( k = 0; k < num_APD_sections; k++ )
+ {
+ float *pFilt_state = filter_state->state[k];
+ float filt_coeff = filter_state->coeffs[k];
+ int16_t order = filter_state->order[k];
+
+ idx = filter_state->idx[k];
+
+ for ( i = 0; i < length; i++ )
+ {
+ tmp_pIn_buf_i = pIn[i];
+
+ pOut[i] = pFilt_state[idx] + pIn[i] * filt_coeff;
+
+ pFilt_state[idx++] = tmp_pIn_buf_i - filt_coeff * pOut[i];
+
+ if ( order == idx )
+ {
+ idx = 0;
+ }
+ }
+ filter_state->idx[k] = idx;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_td_decorr_APD_sections()
+ *
+ * TD decorr all pass delay sections
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_td_decorr_APD_sections(
+ ivas_td_decorr_state_t *hTdDecorr,
+ float **ppOut_pcm,
+ const int16_t output_frame )
+{
+ int16_t i;
+
+ for ( i = 0; i < hTdDecorr->num_apd_outputs; i++ )
+ {
+ ivas_td_decorr_APD_iir_filter( &hTdDecorr->APD_filt_state[i], ppOut_pcm[i], hTdDecorr->num_apd_sections, output_frame );
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_td_decorr_process()
+ *
+ * TD decorr process call
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_td_decorr_process(
+ ivas_td_decorr_state_t *hTdDecorr, /* i/o: SPAR Covar. decoder handle */
+ float *pcm_in[], /* i : input audio channels */
+ float **ppOut_pcm, /* o : output audio channels */
+ const int16_t output_frame /* i : output frame length */
+)
+{
+ int16_t i, j;
+ float in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k];
+
+ /* Look-ahead delay */
+ mvr2r( pcm_in[0], ppOut_pcm[0], output_frame );
+ delay_signal( ppOut_pcm[0], output_frame, hTdDecorr->look_ahead_buf, hTdDecorr->offset );
+
+ /* In ducking gains */
+ if ( hTdDecorr->ducking_flag )
+ {
+ ivas_td_decorr_get_ducking_gains( hTdDecorr->pTrans_det, pcm_in[0], in_duck_gain, out_duck_gain, output_frame, 0 );
+
+ for ( j = 0; j < output_frame; j++ )
+ {
+ ppOut_pcm[0][j] = ppOut_pcm[0][j] * in_duck_gain[j];
+ }
+ }
+
+ for ( i = 1; i < hTdDecorr->num_apd_outputs; i++ )
+ {
+ mvr2r( ppOut_pcm[0], ppOut_pcm[i], output_frame );
+ }
+
+ /* All pass delay section */
+ ivas_td_decorr_APD_sections( hTdDecorr, ppOut_pcm, output_frame );
+
+ /* Out ducking gains */
+ if ( hTdDecorr->ducking_flag )
+ {
+ for ( i = 0; i < hTdDecorr->num_apd_outputs; i++ )
+ {
+ for ( j = 0; j < output_frame; j++ )
+ {
+ ppOut_pcm[i][j] = ppOut_pcm[i][j] * out_duck_gain[j];
+ }
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c
new file mode 100644
index 0000000000000000000000000000000000000000..4e28892da362cd8c38dfeb1569b759c366158438
--- /dev/null
+++ b/lib_com/ivas_tools.c
@@ -0,0 +1,1245 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "options.h"
+#include
+#include "prot.h"
+#include "ivas_prot.h"
+#include "wmc_auto.h"
+#include "ivas_rom_com.h"
+
+/*---------------------------------------------------------------
+ * sumAbs()
+ *
+ * sum of absolute values
+ * ---------------------------------------------------------------*/
+
+/*! r: sum abs of all vector elements */
+float sumAbs(
+ const float *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+)
+{
+ int16_t i;
+ float tmp;
+
+ tmp = 0.0f;
+ for ( i = 0; i < lvec; i++ )
+ {
+ tmp += fabsf( vec[i] );
+ }
+
+ return tmp;
+}
+
+/*---------------------------------------------------------------------*
+ * mvc2c()
+ *
+ * Transfer the contents of vector x[] to vector y[] in char format
+ *---------------------------------------------------------------------*/
+
+void mvc2c(
+ const uint8_t x[], /* i : input vector */
+ uint8_t y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+)
+{
+ int16_t i;
+
+ if ( n <= 0 )
+ {
+ /* no need to 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;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_syn_output()
+ *
+ * Output ivas synthesis signal with compensation for saturation
+ * returns number of clipped samples
+ *-------------------------------------------------------------------*/
+
+/*! r: number of clipped samples */
+uint32_t ivas_syn_output(
+ float *synth[], /* i/o: float synthesis signal */
+ const int16_t output_frame, /* i : output frame length (one channel) */
+ const int16_t n_channels, /* i : number of output channels */
+ int16_t *synth_out /* o : integer 16 bits synthesis signal */
+)
+{
+ int16_t i, n;
+ int16_t synth_loc[MAX_JBM_L_FRAME48k];
+ uint32_t noClipping = 0;
+
+ /*-----------------------------------------------------------------*
+ * float to integer conversion with saturation control
+ *-----------------------------------------------------------------*/
+
+ for ( n = 0; n < n_channels; n++ )
+ {
+ noClipping += mvr2s( synth[n], synth_loc, output_frame );
+
+ for ( i = 0; i < output_frame; i++ )
+ {
+ synth_out[i * n_channels + n] = synth_loc[i];
+ }
+ }
+
+ return noClipping;
+}
+
+
+/*-------------------------------------------------------------------*
+ * 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(
+ float *synth[], /* i/o: float synthesis signal */
+ const int16_t output_frame, /* i : output frame length (one channel) */
+ const int16_t n_channels, /* i : number of output channels */
+ float *synth_out /* o : integer 16 bits synthesis signal */
+)
+{
+ int16_t i, n;
+
+ /*-----------------------------------------------------------------*
+ * float to integer conversion with saturation control
+ *-----------------------------------------------------------------*/
+
+ for ( n = 0; n < n_channels; n++ )
+ {
+ for ( i = 0; i < output_frame; i++ )
+ {
+ synth_out[i * n_channels + n] = synth[n][i];
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * mvr2r_inc()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void mvr2r_inc(
+ const float x[], /* i : input vector */
+ const int16_t x_inc, /* i : increment for vector x[] */
+ float y[], /* o : output vector */
+ const int16_t y_inc, /* i : increment for vector y[] */
+ const int16_t n /* i : vector size */
+)
+{
+ int16_t i;
+ int16_t ix;
+ int16_t iy;
+
+ if ( n <= 0 )
+ {
+ /* cannot transfer vectors with size 0 */
+ return;
+ }
+
+ if ( y < x )
+ {
+ ix = 0;
+ iy = 0;
+ for ( i = 0; i < n; i++ )
+ {
+ y[iy] = x[ix];
+ ix += x_inc;
+ iy += y_inc;
+ }
+ }
+ else
+ {
+ ix = ( n - 1 ) * x_inc;
+ iy = ( n - 1 ) * y_inc;
+ for ( i = n - 1; i >= 0; i-- )
+ {
+ y[iy] = x[ix];
+ ix -= x_inc;
+ iy -= y_inc;
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * v_add_inc()
+ *
+ * Addition of two vectors sample by sample with explicit increments
+ *-------------------------------------------------------------------*/
+
+void v_add_inc(
+ const float x1[], /* i : Input vector 1 */
+ const int16_t x_inc, /* i : Increment for input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ const int16_t x2_inc, /* i : Increment for input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 + vector 2 */
+ const int16_t y_inc, /* i : increment for vector y[] */
+ const int16_t N /* i : Vector length */
+)
+{
+ int16_t i;
+ int16_t ix1 = 0;
+ int16_t ix2 = 0;
+ int16_t iy = 0;
+
+ for ( i = 0; i < N; i++ )
+ {
+ y[iy] = x1[ix1] + x2[ix2];
+ ix1 += x_inc;
+ ix2 += x2_inc;
+ iy += y_inc;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * v_mult_inc()
+ *
+ * Multiplication of two vectors with explicit increments
+ *-------------------------------------------------------------------*/
+
+void v_mult_inc(
+ const float x1[], /* i : Input vector 1 */
+ const int16_t x1_inc, /* i : Increment for input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ const int16_t x2_inc, /* i : Increment for input vector 1 */
+ float y[], /* o : Output vector that contains vector 1 .* vector 2 */
+ const int16_t y_inc, /* i : increment for vector y[i] */
+ const int16_t N /* i : Vector length */
+)
+{
+ int16_t i;
+ int16_t ix1 = 0;
+ int16_t ix2 = 0;
+ int16_t iy = 0;
+
+ for ( i = 0; i < N; i++ )
+ {
+ y[iy] = x1[ix1] * x2[ix2];
+ ix1 += x1_inc;
+ ix2 += x2_inc;
+ iy += y_inc;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * v_addc()
+ *
+ * Addition of constant to vector
+ *-------------------------------------------------------------------*/
+
+void v_addc(
+ const float x[], /* i : Input vector */
+ const float c, /* i : Constant */
+ float y[], /* o : Output vector that contains c*x */
+ const int16_t N /* i : Vector length */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < N; i++ )
+ {
+ y[i] = c + x[i];
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * v_min()
+ *
+ * minimum of two vectors
+ *-------------------------------------------------------------------*/
+
+void v_min(
+ const float x1[], /* i : Input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 .* vector 2 */
+ const int16_t N /* i : Vector length */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < N; i++ )
+ {
+ y[i] = ( x1[i] < x2[i] ) ? x1[i] : x2[i];
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * v_sqrt()
+ *
+ * square root of vector
+ *-------------------------------------------------------------------*/
+
+void v_sqrt(
+ const float x[], /* i : Input vector */
+ float y[], /* o : Output vector that contains sqrt(x) */
+ const int16_t N /* i : Vector length */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < N; i++ )
+ {
+ y[i] = sqrtf( x[i] );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * v_sub_s()
+ *
+ * Subtraction of two vectors
+ *-------------------------------------------------------------------*/
+
+void v_sub_s(
+ const int16_t x1[], /* i : Input vector 1 */
+ const int16_t x2[], /* i : Input vector 2 */
+ int16_t y[], /* o : Output vector that contains vector 1 - vector 2 */
+ const int16_t N /* i : Vector length */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < N; i++ )
+ {
+ y[i] = x1[i] - x2[i];
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * dot_product_cholesky()
+ *
+ * Calculates dot product of type x'*A*A'*x, where x is column vector of size m,
+ * and A is a Cholesky decomposition of some Hermitian matrix S whose size is m*m.
+ * Therefore, S=A*A' where A is upper triangular matrix of size (m*m+m)/2 (zeros ommitted, column-wise)
+ *---------------------------------------------------------------------*/
+
+/*! r: the dot product x'*A*A'*x */
+float dot_product_cholesky(
+ const float *x, /* i : vector x */
+ const float *A, /* i : Cholesky matrix A */
+ const int16_t N /* i : vector & matrix size */
+)
+{
+ int16_t i, j;
+ float suma, tmp_sum;
+ const float *pt_x, *pt_A;
+
+ pt_A = A;
+ suma = 0;
+
+ for ( i = 0; i < N; i++ )
+ {
+ tmp_sum = 0;
+ pt_x = x;
+ for ( j = 0; j <= i; j++ )
+ {
+ tmp_sum += *pt_x++ * *pt_A++;
+ }
+
+ suma += tmp_sum * tmp_sum;
+ }
+
+ return suma;
+}
+
+/*---------------------------------------------------------------------*
+ * v_mult_mat()
+ *
+ * Multiplication of row vector x by matrix A, where x has size Nr and
+ * A has size Nr x Nc ans it is stored column-wise in memory.
+ * The resulting row vector y has size Nc
+ *---------------------------------------------------------------------*/
+
+void v_mult_mat(
+ float *y, /* o : the product x*A */
+ const float *x, /* i : vector x */
+ const float *A, /* i : matrix A */
+ const int16_t Nr, /* i : number of rows */
+ const int16_t Nc /* i : number of columns */
+)
+{
+ int16_t i, j;
+ const float *pt_x, *pt_A;
+ float tmp_y[MAX_V_MULT_MAT];
+ float *pt_y;
+
+ pt_y = tmp_y;
+ pt_A = A;
+ for ( i = 0; i < Nc; i++ )
+ {
+ pt_x = x;
+ *pt_y = 0;
+ for ( j = 0; j < Nr; j++ )
+ {
+ *pt_y += ( *pt_x++ ) * ( *pt_A++ );
+ }
+ pt_y++;
+ }
+
+ mvr2r( tmp_y, y, Nc );
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * logsumexp()
+ *
+ * Compute logarithm of the sum of exponentials of input vector in a numerically stable way
+ *---------------------------------------------------------------------*/
+
+/*! r: log(sum(exp(x)) of the input array x */
+float logsumexp(
+ const float x[], /* i : input array x */
+ const int16_t N /* i : number of elements in array x */
+)
+{
+ float max_exp;
+ float sum;
+ int16_t i;
+
+ max_exp = x[0];
+ sum = 0;
+ for ( i = 1; i < N; i++ )
+ {
+ if ( x[i] > max_exp )
+ {
+ max_exp = x[i];
+ }
+ }
+
+ for ( i = 0; i < N; i++ )
+ {
+ sum += expf( x[i] - max_exp );
+ }
+
+ return logf( sum ) + max_exp;
+}
+
+
+/*---------------------------------------------------------------------*
+ * lin_interp()
+ *
+ * Linearly maps x from source range to the target range
+ *---------------------------------------------------------------------*/
+
+/*! r: mapped output value */
+float lin_interp(
+ const float x, /* i : the value to be mapped */
+ const float x1, /* i : source range interval: low end */
+ const float y1, /* i : source range interval: high end */
+ const float x2, /* i : target range interval: low */
+ const float y2, /* i : target range interval: high */
+ const int16_t flag_sat /* i : flag to indicate whether to apply saturation */
+)
+{
+ if ( x2 - x1 == 0 )
+ {
+ return y1;
+ }
+ else if ( flag_sat )
+ {
+ if ( x >= max( x1, x2 ) )
+ {
+ return x1 > x2 ? y1 : y2;
+ }
+ else if ( x <= min( x1, x2 ) )
+ {
+ return x1 < x2 ? y1 : y2;
+ }
+ }
+
+ return y1 + ( x - x1 ) * ( y2 - y1 ) / ( x2 - x1 );
+}
+
+
+/*-------------------------------------------------------------------*
+ * check_bounds()
+ *
+ * Ensure the input value is within the given limits
+ *-------------------------------------------------------------------*/
+
+/*! r: Adjusted value */
+float check_bounds(
+ const float value, /* i : Input value */
+ const float low, /* i : Low limit */
+ const float high /* i : High limit */
+)
+{
+ float value_adj;
+
+ value_adj = min( max( value, low ), high );
+
+ return value_adj;
+}
+
+
+/*-------------------------------------------------------------------*
+ * check_bounds_s()
+ *
+ * Ensure the input value is within the given limits
+ *-------------------------------------------------------------------*/
+
+/*! r: Adjusted value */
+int16_t check_bounds_s(
+ const int16_t value, /* i : Input value */
+ const int16_t low, /* i : Low limit */
+ const int16_t high /* i : High limit */
+)
+{
+ int16_t value_adj;
+
+ value_adj = min( max( value, low ), high );
+
+ return value_adj;
+}
+
+
+/****************************************************************************/
+/* matrix functions */
+/* matrices are ordered column-wise in memory */
+/****************************************************************************/
+
+/*---------------------------------------------------------------------*
+ * matrix product
+ *
+ * comput the matrix product of two matrices (Z=X*Y)
+ *---------------------------------------------------------------------*/
+
+/*! r: success or failure */
+int16_t matrix_product(
+ const float *X, /* i : left hand matrix */
+ const int16_t rowsX, /* i : number of rows of the left hand matrix */
+ const int16_t colsX, /* i : number of columns of the left hand matrix */
+ const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
+ const float *Y, /* i : right hand matrix */
+ const int16_t rowsY, /* i : number of rows of the right hand matrix */
+ const int16_t colsY, /* i : number of columns of the right hand matrix */
+ const int16_t transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
+ float *Z /* o : resulting matrix after the matrix multiplication */
+)
+{
+ int16_t i, j, k;
+ float *Zp = Z;
+
+ /* Processing */
+ if ( transpX == 1 && transpY == 0 ) /* We use X transpose */
+ {
+ if ( rowsX != rowsY )
+ {
+ return EXIT_FAILURE;
+ }
+ for ( j = 0; j < colsY; ++j )
+ {
+ for ( i = 0; i < colsX; ++i )
+ {
+ ( *Zp ) = 0.0f;
+ for ( k = 0; k < rowsX; ++k )
+ {
+ ( *Zp ) += X[k + i * rowsX] * Y[k + j * rowsY];
+ }
+ Zp++;
+ }
+ }
+ }
+ else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */
+ {
+ if ( colsX != colsY )
+ {
+ return EXIT_FAILURE;
+ }
+ for ( j = 0; j < rowsY; ++j )
+ {
+ for ( i = 0; i < rowsX; ++i )
+ {
+ ( *Zp ) = 0.0f;
+ for ( k = 0; k < colsX; ++k )
+ {
+ ( *Zp ) += X[i + k * rowsX] * Y[j + k * rowsY];
+ }
+ Zp++;
+ }
+ }
+ }
+ else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */
+ {
+ if ( rowsX != colsY )
+ {
+ return EXIT_FAILURE;
+ }
+ for ( j = 0; j < rowsY; ++j )
+ {
+ for ( i = 0; i < colsX; ++i )
+ {
+ ( *Zp ) = 0.0f;
+ for ( k = 0; k < colsX; ++k )
+ {
+ ( *Zp ) += X[k + i * rowsX] * Y[j + k * rowsY];
+ }
+
+ Zp++;
+ }
+ }
+ }
+ else /* Regular case */
+ {
+ if ( colsX != rowsY )
+ {
+ return EXIT_FAILURE;
+ }
+
+ for ( j = 0; j < colsY; ++j )
+ {
+ for ( i = 0; i < rowsX; ++i )
+ {
+ ( *Zp ) = 0.0f;
+ for ( k = 0; k < colsX; ++k )
+ {
+ ( *Zp ) += X[i + k * rowsX] * Y[k + j * rowsY];
+ }
+ Zp++;
+ }
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+
+
+/*---------------------------------------------------------------------*
+ * matrix_diag_product
+ *
+ * compute the product of a matrix with a diagonal of a matrix (Z=X*diag(Y))
+ *---------------------------------------------------------------------*/
+
+/*! r: success or failure */
+int16_t matrix_diag_product(
+ const float *X, /* i : left hand matrix */
+ const int16_t rowsX, /* i : number of rows of the left hand matrix */
+ const int16_t colsX, /* i : number of columns of the left hand matrix */
+ const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
+ const float *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements */
+ const int16_t entriesY, /* i : number of entries in the diagonal */
+ float *Z /* o : resulting matrix after the matrix multiplication */
+)
+{
+ int16_t i, j;
+ float *Zp = Z;
+
+ /* Processing */
+ if ( transpX == 1 ) /* We use X transpose */
+ {
+ if ( rowsX != entriesY )
+ {
+ return EXIT_FAILURE;
+ }
+ for ( j = 0; j < entriesY; ++j )
+ {
+ for ( i = 0; i < colsX; ++i )
+ {
+ *( Zp++ ) = X[j + i * rowsX] * Y[j];
+ }
+ }
+ }
+ else /* Regular case */
+ {
+ if ( colsX != entriesY )
+ {
+ return EXIT_FAILURE;
+ }
+
+ for ( j = 0; j < entriesY; ++j )
+ {
+ for ( i = 0; i < rowsX; ++i )
+ {
+ *( Zp++ ) = *( X++ ) * Y[j];
+ }
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+
+/*---------------------------------------------------------------------*
+ * diag_matrix_product()
+ *
+ * compute the matrix product of a diagonal matrix X with a full matrix Y (Z=diag(Y)*X)
+ *---------------------------------------------------------------------*/
+
+/*! r: success or failure */
+int16_t diag_matrix_product(
+ const float *Y, /* i : left hand diagonal matrix as vector containing the diagonal elements */
+ const int16_t entriesY, /* i : length of the diagonal of the left hand matrix */
+ const float *X, /* i : right hand matrix */
+ const int16_t rowsX, /* i : number of rows of the right hand matrix */
+ const int16_t colsX, /* i : number of columns of the right hand matrix */
+ const int16_t transpX, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
+ float *Z /* o : resulting matrix after the matrix multiplication */
+)
+{
+ int16_t i, j;
+ float *Zp = Z;
+
+ /* Processing */
+ if ( transpX == 1 ) /* We use X transpose */
+ {
+ if ( colsX != entriesY )
+ {
+ return EXIT_FAILURE;
+ }
+ for ( i = 0; i < rowsX; ++i )
+ {
+ for ( j = 0; j < entriesY; ++j )
+ {
+ *( Zp++ ) = X[i + j * rowsX] * Y[j];
+ }
+ }
+ }
+ else /* Regular case */
+ {
+ if ( rowsX != entriesY )
+ {
+ return EXIT_FAILURE;
+ }
+ for ( i = 0; i < colsX; ++i )
+ {
+ for ( j = 0; j < entriesY; ++j )
+ {
+ *( Zp++ ) = *( X++ ) * Y[j];
+ }
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+
+
+/*---------------------------------------------------------------------*
+ * matrix_product_diag()
+ *
+ * compute only the main diagonal of X*Y (Z=diag(X*Y))
+ *---------------------------------------------------------------------*/
+
+/*! r: success or failure */
+int16_t matrix_product_diag(
+ const float *X, /* i : left hand matrix */
+ const int16_t rowsX, /* i : number of rows of the left hand matrix */
+ const int16_t colsX, /* i : number of columns of the left hand matrix */
+ const int16_t transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */
+ const float *Y, /* i : right hand matrix */
+ const int16_t rowsY, /* i : number of rows of the right hand matrix */
+ const int16_t colsY, /* i : number of columns of the right hand matrix */
+ const int16_t transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */
+ float *Z /* o : resulting matrix after the matrix multiplication */
+)
+{
+ int16_t j, k;
+ float *Zp = Z;
+
+ /* Processing */
+ if ( transpX == 1 && transpY == 0 ) /* We use X transpose */
+ {
+ if ( rowsX != rowsY )
+ {
+ return EXIT_FAILURE;
+ }
+
+ for ( j = 0; j < colsY; ++j )
+ {
+ ( *Zp ) = 0.0f;
+ for ( k = 0; k < rowsX; ++k )
+ {
+ ( *Zp ) += X[k + j * rowsX] * Y[k + j * rowsY];
+ }
+ Zp++;
+ }
+ }
+ else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */
+ {
+ if ( colsX != colsY )
+ {
+ return EXIT_FAILURE;
+ }
+ for ( j = 0; j < rowsY; ++j )
+ {
+ ( *Zp ) = 0.0f;
+ for ( k = 0; k < colsX; ++k )
+ {
+ ( *Zp ) += X[j + k * rowsX] * Y[j + k * rowsY];
+ }
+ Zp++;
+ }
+ }
+ else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */
+ {
+ if ( rowsX != colsY )
+ {
+ return EXIT_FAILURE;
+ }
+
+ for ( j = 0; j < rowsY; ++j )
+ {
+
+ ( *Zp ) = 0.0f;
+ for ( k = 0; k < colsX; ++k )
+ {
+ ( *Zp ) += X[k + j * rowsX] * Y[j + k * rowsY];
+ }
+
+ Zp++;
+ }
+ }
+ else /* Regular case */
+ {
+ if ( colsX != rowsY )
+ {
+ return EXIT_FAILURE;
+ }
+
+ for ( j = 0; j < colsY; ++j )
+ {
+ ( *Zp ) = 0.0f;
+ for ( k = 0; k < colsX; ++k )
+ {
+ ( *Zp ) += X[j + k * rowsX] * Y[k + j * rowsY];
+ }
+ Zp++;
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+
+
+/*---------------------------------------------------------------------*
+ * cmplx_matrix_square()
+ *
+ * compute the square of a complex matrix (Z=X*X)
+ *---------------------------------------------------------------------*/
+
+/*! r: success or failure */
+void cmplx_matrix_square(
+ const float *realX, /* i : real part of the matrix */
+ const float *imagX, /* i : imaginary part of the matrix */
+ const int16_t mRows, /* i : number of rows of the matrix */
+ const int16_t nCols, /* i : number of columns of the matrix */
+ float *realZ, /* o : real part of the resulting matrix */
+ float *imagZ /* o : imaginary part of the resulting matrix */
+)
+{
+ int16_t i, j, k;
+ float *realZp, *imagZp;
+ const float *p_real1, *p_real2, *p_imag1, *p_imag2;
+
+ /* resulting matrix is hermitean, we only need to calc the upper triangle */
+ /* we assume transposition needed */
+
+ /* column*column = column/column */
+ for ( i = 0; i < nCols; i++ )
+ {
+ for ( j = i; j < nCols; j++ )
+ {
+ p_real1 = realX + i * mRows;
+ p_imag1 = imagX + i * mRows;
+ p_real2 = realX + j * mRows;
+ p_imag2 = imagX + j * mRows;
+ realZp = realZ + ( i + nCols * j );
+ imagZp = imagZ + ( i + nCols * j );
+ *( realZp ) = 0.0f;
+ *( imagZp ) = 0.0f;
+
+ for ( k = 0; k < mRows; k++ )
+ {
+ *( imagZp ) += *( p_real1 ) * ( *( p_imag2 ) ) - ( *( p_real2 ) ) * ( *( p_imag1 ) );
+ *( realZp ) += *( p_real1++ ) * ( *( p_real2++ ) ) + *( p_imag1++ ) * ( *( p_imag2++ ) );
+ }
+ }
+ }
+
+ /* fill lower triangle */
+ for ( i = 1; i < nCols; i++ )
+ {
+ for ( j = 0; j < i; j++ )
+ {
+ realZ[i + nCols * j] = realZ[j + nCols * i];
+ imagZ[i + nCols * j] = imagZ[j + nCols * i];
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * v_multc_acc()
+ *
+ * Multiplication of vector by constant, accumulate to the output
+ *-------------------------------------------------------------------*/
+
+void v_multc_acc(
+ const float x[], /* i : Input vector */
+ const float c, /* i : Constant */
+ float y[], /* o : Output vector that contains y + c*x */
+ const int16_t N /* i : Vector length */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < N; i++ )
+ {
+ y[i] += c * x[i];
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * lls_interp_n()
+ *
+ * Linear least squares interpolation of an input vector
+ * The function calculates the slope 'a' and the offset 'b' of a LLS estimate for an input vector x such that
+ * y_i = a*i + b where i=1,..,N and (a,b) = min(a,b) [sum_N[(y_i - x_i)^2]]
+ * the interpolated vector is return as x[], if requested
+ *---------------------------------------------------------------------*/
+
+
+void lls_interp_n(
+ float x[], /* i/o: input/output vector */
+ const int16_t N, /* i : length of the input vector */
+ float *a, /* o : calculated slope */
+ float *b, /* o : calculated offset */
+ const int16_t upd /* i : use 1 to update x[] with the interpolated output */
+)
+{
+ int16_t i;
+ const float n_i[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ const float one_by_n[11] = { 0, 1, 0.5f, 0.333f, 0.25f, 0.2f, 0.1666f, 0.14286f, 0.125f, 0.111111f, 0.1f };
+ const float sum_i[12] = { 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 };
+ const float sum_ii[12] = { 0, 0, 1, 5, 14, 30, 55, 91, 140, 204, 285, 385 };
+ float sum_x, sum_ix, slope, offset;
+
+ assert( N > 0 && N <= 10 );
+
+ sum_x = sum_f( x, N );
+ sum_ix = dotp( x, n_i, N );
+
+ slope = ( N * sum_ix - sum_i[N] * sum_x ) / ( N * sum_ii[N] - sum_i[N] * sum_i[N] );
+ offset = ( sum_x - slope * sum_i[N] ) * one_by_n[N];
+
+ if ( upd )
+ {
+ for ( i = 0; i < N; i++ )
+ {
+ x[i] = slope * i + offset;
+ }
+ }
+
+ if ( a != NULL )
+ {
+ *a = slope;
+ }
+
+ if ( b != NULL )
+ {
+ *b = offset;
+ }
+
+ return;
+}
+
+/* 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;
+}
+
+/*-------------------------------------------------------------------*
+ * 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;
+ }
+}
+
+/*-------------------------------------------------------------------------*
+ * v_sort_ind()
+ *
+ * Sort a float array
+ * (modified version of v_sort() to return an index array)
+ *-------------------------------------------------------------------------*/
+
+void v_sort_ind(
+ float *x, /* i/o: Vector to be sorted */
+ int16_t *idx, /* o : Original index positions */
+ const int16_t len /* i : vector length */
+)
+{
+ int16_t i, j;
+ float tempr;
+ int16_t tempi;
+
+ for ( i = 0; i < len; i++ )
+ {
+ idx[i] = i;
+ }
+
+ for ( i = len - 2; i >= 0; i-- )
+ {
+ tempr = x[i];
+ tempi = idx[i];
+ for ( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ )
+ {
+ x[j - 1] = x[j];
+ idx[j - 1] = idx[j];
+ }
+ x[j - 1] = tempr;
+ idx[j - 1] = tempi;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * is_IVAS_bitrate()
+ *
+ * check if the bitrate is IVAS supported active bitrate
+ *-------------------------------------------------------------------*/
+
+/*! r: flag indicating a valid bitrate */
+int16_t is_IVAS_bitrate(
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ int16_t j;
+
+ j = SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES; /* skip NO_DATA and SID bitrates */
+ while ( j < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[j] )
+ {
+ j++;
+ }
+
+ if ( j >= SIZE_IVAS_BRATE_TBL )
+ {
+ return 0;
+ }
+
+ return 1;
+}
+
+
+/*-------------------------------------------------------------------*
+ * is_DTXrate()
+ *
+ * identify DTX frame bitrates
+ *-------------------------------------------------------------------*/
+
+int16_t is_DTXrate(
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ int16_t dtx_rate_flag = 0;
+
+ if ( is_SIDrate( ivas_total_brate ) || ( ivas_total_brate == FRAME_NO_DATA ) )
+ {
+ dtx_rate_flag = 1;
+ }
+
+ return dtx_rate_flag;
+}
+
+/*-------------------------------------------------------------------*
+ * is_SIDrate()
+ *
+ * identify SID frame bitrates
+ *-------------------------------------------------------------------*/
+
+int16_t is_SIDrate(
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+)
+{
+ int16_t sid_rate_flag = 0;
+
+ if ( ( ivas_total_brate == SID_1k75 ) ||
+ ( ivas_total_brate == SID_2k40 ) ||
+ ( ivas_total_brate == IVAS_SID_5k2 ) )
+ {
+ sid_rate_flag = 1;
+ }
+
+ return sid_rate_flag;
+}
+
+
+/*-------------------------------------------------------------------*
+ * rand_triangular_signed()
+ *
+ * generate a random value with a triangular pdf in [-0.5, 0.5]
+ *-------------------------------------------------------------------*/
+
+float rand_triangular_signed(
+ int16_t *seed )
+{
+ float rand_val;
+
+ rand_val = own_random( seed ) * OUTMAX_INV;
+ if ( rand_val <= 0.0f )
+ {
+ /* rand_val in [-1, 0] */
+ return 0.5f * sqrtf( rand_val + 1.0f ) - 0.5f;
+ }
+ else
+ {
+ /* rand_val in (0, 1) */
+ return 0.5f - 0.5f * sqrtf( 1.0f - rand_val );
+ }
+}
diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c
new file mode 100644
index 0000000000000000000000000000000000000000..7e38f8ce6788a08cb1980984e546c4f32325ce66
--- /dev/null
+++ b/lib_com/ivas_transient_det.c
@@ -0,0 +1,342 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "math.h"
+#include "wmc_auto.h"
+#include "prot.h"
+#include "ivas_cnst.h"
+#include "ivas_prot.h"
+#include "ivas_stat_com.h"
+
+/*------------------------------------------------------------------------------------------*
+ * Local constants
+ *------------------------------------------------------------------------------------------*/
+
+#define IVAS_TDET_PARM_ENV_EPS ( 1e-5f )
+#define IVAS_TDET_DUCK_MULT_FAC ( 1.1f )
+#define IVAS_TDET_PARM_TRANS_THR ( 0.1f )
+#define IVAS_TDET_ONLY ( 1 )
+
+/*env_hpf*/
+#define IVAS_C_HPF_48k ( 0.675231906655777f )
+#define IVAS_C_HPF_32k ( 0.554854910159853f )
+#define IVAS_C_HPF_16k ( 0.307863971328499f )
+
+/*env_fast*/
+#define IVAS_C_FAST_48k ( 0.995842001845110f )
+#define IVAS_C_FAST_32k ( 0.993769490623395f )
+#define IVAS_C_FAST_16k ( 0.987577800493881f )
+
+/*env_slow*/
+#define IVAS_C_SLOW_48k ( 0.999739617238810f )
+#define IVAS_C_SLOW_32k ( 0.999609451284012f )
+#define IVAS_C_SLOW_16k ( 0.999219055096324f )
+
+/*induck*/
+#define IVAS_C_IN_DUCK_48k ( 0.999583420126834f )
+#define IVAS_C_IN_DUCK_32k ( 0.999375195271816f )
+#define IVAS_C_IN_DUCK_16k ( 0.998750780924581f )
+
+/*outduck*/
+#define IVAS_C_OUT_DUCK_48k ( 0.999583420126834f )
+#define IVAS_C_OUT_DUCK_32k ( 0.999375195271816f )
+#define IVAS_C_OUT_DUCK_16k ( 0.998750780924581f )
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_transient_det_init()
+ *
+ * Trans det init fucntion
+ *-----------------------------------------------------------------------------------------*/
+
+static void ivas_transient_det_init(
+ ivas_trans_det_state_t *hTranDet, /* i/o: Transient detector handle */
+ const int32_t sampling_rate /* i : sampling rate */
+)
+{
+ int16_t i;
+ float filt_coeff_arr[3][IVAS_BIQUAD_FILT_LEN << 1];
+
+ hTranDet->in_duck_gain = 1.0f;
+ hTranDet->out_duck_gain = 1.0f;
+
+ for ( i = 0; i < 3; i++ )
+ {
+ set_zero( filt_coeff_arr[i], IVAS_BIQUAD_FILT_LEN << 1 );
+ }
+
+ switch ( sampling_rate )
+ {
+ case 48000:
+ /*env_hpf*/
+ filt_coeff_arr[0][0] = IVAS_C_HPF_48k;
+ filt_coeff_arr[0][1] = -IVAS_C_HPF_48k;
+ filt_coeff_arr[0][3] = 1.0f;
+ filt_coeff_arr[0][4] = -IVAS_C_HPF_48k;
+ /*env_fast*/
+ filt_coeff_arr[1][0] = 1.0f - IVAS_C_FAST_48k;
+ filt_coeff_arr[1][3] = 1.0f;
+ filt_coeff_arr[1][4] = -IVAS_C_FAST_48k;
+ /*env_slow*/
+ filt_coeff_arr[2][0] = 1.0f - IVAS_C_SLOW_48k;
+ filt_coeff_arr[2][3] = 1.0f;
+ filt_coeff_arr[2][4] = -IVAS_C_SLOW_48k;
+ hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_48k;
+ hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_48k;
+ break;
+ case 32000:
+ /*env_hpf*/
+ filt_coeff_arr[0][0] = IVAS_C_HPF_32k;
+ filt_coeff_arr[0][1] = -IVAS_C_HPF_32k;
+ filt_coeff_arr[0][3] = 1.0f;
+ filt_coeff_arr[0][4] = -IVAS_C_HPF_32k;
+ /*env_fast*/
+ filt_coeff_arr[1][0] = 1.0f - IVAS_C_FAST_32k;
+ filt_coeff_arr[1][3] = 1.0f;
+ filt_coeff_arr[1][4] = -IVAS_C_FAST_32k;
+ /*env_slow*/
+ filt_coeff_arr[2][0] = 1.0f - IVAS_C_SLOW_32k;
+ filt_coeff_arr[2][3] = 1.0f;
+ filt_coeff_arr[2][4] = -IVAS_C_SLOW_32k;
+ hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_32k;
+ hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_32k;
+ break;
+ case 16000:
+ /*env_hpf*/
+ filt_coeff_arr[0][0] = IVAS_C_HPF_16k;
+ filt_coeff_arr[0][1] = -IVAS_C_HPF_16k;
+ filt_coeff_arr[0][3] = 1.0f;
+ filt_coeff_arr[0][4] = -IVAS_C_HPF_16k;
+ /*env_fast*/
+ filt_coeff_arr[1][0] = 1.0f - IVAS_C_FAST_16k;
+ filt_coeff_arr[1][3] = 1.0f;
+ filt_coeff_arr[1][4] = -IVAS_C_FAST_16k;
+ /*env_slow*/
+ filt_coeff_arr[2][0] = 1.0f - IVAS_C_SLOW_16k;
+ filt_coeff_arr[2][3] = 1.0f;
+ filt_coeff_arr[2][4] = -IVAS_C_SLOW_16k;
+ hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_16k;
+ hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_16k;
+ break;
+ }
+
+ ivas_filters_init( &hTranDet->env_hpf, (const float *) filt_coeff_arr[0], IVAS_FILTER_ORDER_1 );
+ ivas_filters_init( &hTranDet->env_fast, (const float *) filt_coeff_arr[1], IVAS_FILTER_ORDER_1 );
+ ivas_filters_init( &hTranDet->env_slow, (const float *) filt_coeff_arr[2], IVAS_FILTER_ORDER_1 );
+
+ hTranDet->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_transient_det_open()
+ *
+ * Allocate and initialize SPAR TD handle
+ *------------------------------------------------------------------------*/
+
+ivas_error ivas_transient_det_open(
+ ivas_trans_det_state_t **hTranDet_in, /* i/o: Transient detector handle */
+ const int32_t sampling_rate /* i : sampling rate */
+)
+{
+ ivas_trans_det_state_t *hTranDet;
+
+ if ( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL )
+ {
+ return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR TD\n" );
+ }
+
+ ivas_transient_det_init( hTranDet, sampling_rate );
+
+ *hTranDet_in = hTranDet;
+
+ return IVAS_ERR_OK;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_transient_det_close()
+ *
+ * Deallocate and initialize Transient detector handle
+ *------------------------------------------------------------------------*/
+
+void ivas_transient_det_close(
+ ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */
+)
+{
+ if ( hTranDet == NULL || *hTranDet == NULL )
+ {
+ return;
+ }
+
+ free( *hTranDet );
+ *hTranDet = NULL;
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_transient_det_process()
+ *
+ * Transient detection process call
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_transient_det_process(
+ ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */
+ float *pIn_pcm, /* i : input audio channels */
+ const int16_t frame_len, /* i : frame length in samples */
+ int16_t transient_det[2] /* o : transient det outputs */
+)
+{
+ float in_duck_gain[L_FRAME48k];
+ int16_t num_sf, sf, sf_samp, idx;
+ float mem = hTranDet->in_duck_gain;
+
+ ivas_td_decorr_get_ducking_gains( hTranDet, pIn_pcm, in_duck_gain, NULL, frame_len, IVAS_TDET_ONLY );
+
+ transient_det[0] = 0;
+ transient_det[1] = 0;
+ if ( mem - hTranDet->in_duck_gain > IVAS_TDET_PARM_TRANS_THR )
+ {
+ transient_det[0] = 1;
+ }
+
+ num_sf = 16;
+ sf_samp = frame_len / num_sf;
+ for ( sf = 1; sf <= num_sf; sf++ )
+ {
+ idx = ( sf_samp * sf ) - 1;
+ if ( ( mem - in_duck_gain[idx] ) > ( IVAS_TDET_PARM_TRANS_THR * 1.1f ) )
+ {
+ transient_det[1] = 1;
+ }
+ mem = in_duck_gain[idx];
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_calc_duck_gain()
+ *
+ * Calculate ducking gain utility
+ *-----------------------------------------------------------------------------------------*/
+
+static float ivas_calc_duck_gain(
+ const float duck_gain,
+ const float duck_coeff,
+ const float env_1,
+ const float env_2,
+ const float duck_mult_fac )
+{
+ float duck_gain_out;
+
+ duck_gain_out = ( duck_gain - 1 ) * duck_coeff + 1;
+
+ if ( ( duck_mult_fac * env_1 ) < duck_gain_out * env_2 )
+ {
+ duck_gain_out = duck_mult_fac * ( env_1 / env_2 );
+ }
+
+ return duck_gain_out;
+}
+
+
+/*-----------------------------------------------------------------------------------------*
+ * Function ivas_td_decorr_get_ducking_gains()
+ *
+ * Calculate in/out ducking gains
+ *-----------------------------------------------------------------------------------------*/
+
+void ivas_td_decorr_get_ducking_gains(
+ ivas_trans_det_state_t *hTranDet, /* i/o: Transient detector handle */
+ float *pIn_pcm,
+ float *pIn_duck_gains,
+ float *pOut_duck_gains,
+ const int16_t frame_len,
+ const int16_t tdet_flag )
+{
+ int16_t i;
+ float e_fast[L_FRAME48k], e_slow[L_FRAME48k];
+ float in_duck_gain = hTranDet->in_duck_gain;
+ float out_duck_gain = hTranDet->out_duck_gain;
+ float in_duck_coeff = hTranDet->in_duck_coeff;
+ float out_duck_coeff = hTranDet->out_duck_coeff;
+ float duck_mult_fac = hTranDet->duck_mult_fac;
+
+ mvr2r( pIn_pcm, e_fast, frame_len );
+
+ /* env hpf */
+ ivas_filter_process( &hTranDet->env_hpf, e_fast, frame_len );
+
+ for ( i = 0; i < frame_len; i++ )
+ {
+ e_fast[i] = (float) fabs( e_fast[i] ) + IVAS_TDET_PARM_ENV_EPS;
+ e_slow[i] = e_fast[i];
+ }
+
+ /* env fast*/
+ ivas_filter_process( &hTranDet->env_fast, e_fast, frame_len );
+
+ /* env slow */
+ ivas_filter_process( &hTranDet->env_slow, e_slow, frame_len );
+
+ if ( tdet_flag )
+ {
+ for ( i = 0; i < frame_len; i++ )
+ {
+ in_duck_gain = ivas_calc_duck_gain( in_duck_gain, in_duck_coeff, e_slow[i], e_fast[i], duck_mult_fac );
+ pIn_duck_gains[i] = in_duck_gain;
+ }
+ hTranDet->in_duck_gain = in_duck_gain;
+ }
+ else
+ {
+ for ( i = 0; i < frame_len; i++ )
+ {
+ in_duck_gain = ivas_calc_duck_gain( in_duck_gain, in_duck_coeff, e_slow[i], e_fast[i], duck_mult_fac );
+ pIn_duck_gains[i] = in_duck_gain;
+ out_duck_gain = ivas_calc_duck_gain( out_duck_gain, out_duck_coeff, e_fast[i], e_slow[i], duck_mult_fac );
+ pOut_duck_gains[i] = out_duck_gain;
+ }
+ hTranDet->in_duck_gain = in_duck_gain;
+ hTranDet->out_duck_gain = out_duck_gain;
+ }
+
+ return;
+}
diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c
new file mode 100644
index 0000000000000000000000000000000000000000..fdaa4a7a7c4d6560bcfde0820a9a264d67479915
--- /dev/null
+++ b/lib_com/lag_wind.c
@@ -0,0 +1,164 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "prot.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------------------------*/
+
+#define kLagWinThGain1 0.6f
+#define kLagWinThGain2 0.3f
+
+
+/*-------------------------------------------------------------*
+ * procedure lag_wind() *
+ * ~~~~~~~~~ *
+ * lag windowing of the autocorrelations *
+ *-------------------------------------------------------------*/
+
+void lag_wind(
+ float r[], /* i/o: autocorrelations */
+ const int16_t m, /* i : order of LP filter */
+ const int32_t sr_core, /* i : sampling rate */
+ const int16_t strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */
+)
+{
+ int16_t i;
+ const float *wnd;
+
+ assert( 0 <= strength && strength <= NUM_LAGW_STRENGTHS );
+
+ switch ( sr_core )
+ {
+ case 8000:
+ assert( m <= 16 );
+ assert( strength == LAGW_STRONG );
+ wnd = lag_window_8k;
+ break;
+ case 12800:
+ assert( m <= 16 );
+ wnd = lag_window_12k8[strength];
+ break;
+ case 16000:
+ assert( m <= 16 );
+ wnd = lag_window_16k[strength];
+ break;
+ case 24000:
+ case 25600:
+ assert( m <= 16 );
+ wnd = lag_window_25k6[strength];
+ break;
+ case 32000:
+ assert( m <= 16 );
+ wnd = lag_window_32k[strength];
+ break;
+ case 48000:
+ assert( m <= 16 );
+ assert( strength == LAGW_STRONG );
+ wnd = lag_window_48k;
+ break;
+ default:
+ assert( !"Lag window not implemented for this sampling rate" );
+ return;
+ }
+
+ for ( i = 0; i <= m; ++i )
+ {
+ r[i] *= wnd[i];
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------*
+ * procedure adapt_lag_wind()
+ *
+ *
+ *-------------------------------------------------------------*/
+
+void adapt_lag_wind(
+ float r[], /* i/o: autocorrelations */
+ const int16_t m, /* i : order of LP filter */
+ const int16_t Top, /* i : open loop pitch lags from curr. frame (or NULL if n/a) */
+ const float Tnc, /* i : open loop pitch gains from curr. frame (NULL if n/a) */
+ const int32_t sr_core /* i : core sampling rate */
+)
+{
+ int16_t strength;
+ int16_t pitch_lag;
+ float pitch_gain;
+
+ pitch_lag = (int16_t) Top;
+ pitch_gain = (float) Tnc;
+
+ if ( pitch_lag < 80 )
+ {
+ if ( pitch_gain > kLagWinThGain1 )
+ {
+ strength = LAGW_STRONG;
+ }
+ else
+ {
+ strength = LAGW_MEDIUM;
+ }
+ }
+ else if ( pitch_lag < 160 )
+ {
+ if ( pitch_gain > kLagWinThGain2 )
+ {
+ strength = LAGW_MEDIUM;
+ }
+ else
+ {
+ strength = LAGW_WEAK;
+ }
+ }
+ else
+ {
+ strength = LAGW_WEAK;
+ }
+
+ lag_wind( r, m, sr_core, strength );
+
+ return;
+}
diff --git a/lib_com/lerp.c b/lib_com/lerp.c
new file mode 100644
index 0000000000000000000000000000000000000000..60e7bf628e415ed8bef6c440aaee372eb04f9dbb
--- /dev/null
+++ b/lib_com/lerp.c
@@ -0,0 +1,183 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------*
+ * Local function prototypes
+ *-------------------------------------------------------------*/
+
+static void lerp_proc( const float *f, float *f_out, const int16_t bufferNewSize, const int16_t bufferOldSize );
+
+
+/*-------------------------------------------------------------*
+ * procedure lerp() *
+ * *
+ * *
+ *-------------------------------------------------------------*/
+
+void lerp(
+ const float *f,
+ float *f_out,
+ const int16_t bufferNewSize,
+ const int16_t bufferOldSize_inp )
+{
+ float maxFac;
+ int16_t bufferOldSize, tmpNewSize;
+
+ maxFac = 507.0 / 128.0;
+ bufferOldSize = bufferOldSize_inp;
+
+ if ( (float) bufferNewSize / bufferOldSize > maxFac )
+ {
+ tmpNewSize = bufferOldSize * 2;
+ while ( bufferNewSize > bufferOldSize )
+ {
+ if ( (float) bufferNewSize / bufferOldSize <= maxFac )
+ {
+ tmpNewSize = bufferNewSize;
+ }
+
+ lerp_proc( f, f_out, tmpNewSize, bufferOldSize );
+
+ f = f_out;
+ bufferOldSize = tmpNewSize;
+ tmpNewSize *= 2;
+ }
+ }
+ else if ( (float) bufferOldSize / bufferNewSize > maxFac )
+ {
+ tmpNewSize = bufferOldSize / 2;
+ while ( bufferNewSize < bufferOldSize )
+ {
+ if ( (float) bufferOldSize / bufferNewSize <= maxFac )
+ {
+ tmpNewSize = bufferNewSize;
+ }
+
+ lerp_proc( f, f_out, tmpNewSize, bufferOldSize );
+
+ f = f_out;
+ bufferOldSize = tmpNewSize;
+ tmpNewSize /= 2;
+ }
+ }
+ else
+ {
+ lerp_proc( f, f_out, bufferNewSize, bufferOldSize );
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------*
+ * procedure lerp_proc() *
+ * *
+ * *
+ *-------------------------------------------------------------*/
+
+static void lerp_proc(
+ const float *f,
+ float *f_out,
+ const int16_t bufferNewSize,
+ const int16_t bufferOldSize )
+{
+ int16_t i, idx;
+ float pos, shift, diff;
+ float buf[2 * L_FRAME_MAX];
+ Word16 tmp;
+
+ if ( bufferNewSize == bufferOldSize )
+ {
+ mvr2r( f, buf, bufferNewSize );
+ mvr2r( buf, f_out, bufferNewSize );
+ return;
+ }
+
+ /* Using the basop code to avoid reading beyond end of input for bufferOldSize=320, bufferNewSize=640 */
+ tmp = div_s( bufferOldSize, shl( bufferNewSize, 4 ) );
+ shift = (float) ( L_shl( L_deposit_l( tmp ), 4 - 15 + 16 ) ) / 65536.0f;
+ pos = 0.5f * shift - 0.5f;
+
+ if ( shift < 0.3f )
+ {
+ pos = pos - 0.13f;
+ }
+
+ /* first point of interpolation */
+ if ( pos < 0 )
+ {
+ buf[0] = f[0] + pos * ( f[1] - f[0] );
+ }
+ else
+ {
+ idx = (int16_t) pos;
+ diff = pos - idx;
+ buf[0] = f[idx] + diff * ( f[idx + 1] - f[idx] );
+ }
+
+ pos += shift;
+
+ for ( i = 1; i < bufferNewSize - 1; i++ )
+ {
+ idx = (int16_t) pos;
+ diff = pos - idx;
+
+ buf[i] = f[idx] + diff * ( f[idx + 1] - f[idx] );
+ pos += shift;
+ }
+
+
+ /* last point */
+ idx = (int16_t) pos;
+
+ if ( pos > bufferOldSize - 1 )
+ {
+ idx = bufferOldSize - 2;
+ }
+
+ diff = pos - idx;
+
+ buf[bufferNewSize - 1] = f[idx] + diff * ( f[idx + 1] - f[idx] );
+
+ mvr2r( buf, f_out, bufferNewSize );
+
+ return;
+}
diff --git a/lib_com/limit_t0.c b/lib_com/limit_t0.c
new file mode 100644
index 0000000000000000000000000000000000000000..1176a81327346e47cc8de90872fd86a57215aecf
--- /dev/null
+++ b/lib_com/limit_t0.c
@@ -0,0 +1,231 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------*/
+
+#define LIMIT_PIT_REL_LOWER 2 /* delta interval to extend pitch coding in relative Q */
+#define LIMIT_PIT_REL_UPPER 0
+
+/*-------------------------------------------------*
+ * limit_T0()
+ *
+ * Close-loop pitch lag search limitation
+ *-------------------------------------------------*/
+
+void limit_T0(
+ const int16_t L_frame, /* i : length of the frame */
+ const int16_t delta, /* i : Half the close-loop searched interval */
+ const int16_t pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */
+ const int16_t limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */
+ const int16_t T0, /* i : rough pitch estimate around which the search is done */
+ const int16_t T0_frac, /* i : pitch estimate fractional part */
+ int16_t *T0_min, /* o : lower pitch limit */
+ int16_t *T0_max /* o : higher pitch limit */
+)
+{
+ int16_t delta2, T1;
+ int16_t pit_min, pit_max;
+
+ if ( limit_flag == 0 ) /* restrained Q limits */
+ {
+ /* set limits */
+ if ( L_frame == L_FRAME )
+ {
+ pit_max = PIT_MAX;
+ pit_min = PIT_MIN;
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ pit_max = PIT16k_MAX;
+ pit_min = PIT16k_MIN;
+ }
+
+ delta2 = 2 * delta - 1;
+
+ T1 = T0;
+ if ( T0_frac >= 2 )
+ {
+ T1++;
+ }
+ *T0_min = T1 - delta;
+
+ if ( *T0_min < pit_min )
+ {
+ *T0_min = pit_min;
+ }
+ *T0_max = *T0_min + delta2;
+
+ if ( *T0_max > pit_max )
+ {
+ *T0_max = pit_max;
+ *T0_min = *T0_max - delta2;
+ }
+ }
+ else /* extended Q limits */
+ {
+
+ /* set limits */
+ if ( L_frame == L_FRAME )
+ {
+ pit_max = PIT_MAX;
+ pit_min = PIT_MIN_EXTEND;
+
+ if ( limit_flag == 2 )
+ {
+ pit_min = PIT_MIN_DOUBLEEXTEND;
+ }
+ }
+ else /* L_frame == L_FRAME16k */
+ {
+ pit_max = PIT16k_MAX;
+ pit_min = PIT16k_MIN_EXTEND;
+ }
+
+ delta2 = 2 * delta - 1;
+
+ T1 = T0;
+ if ( T0_frac >= 2 )
+ {
+ T1++;
+ }
+ *T0_min = T1 - delta;
+
+ if ( pit_flag == 0 )
+ {
+ /* subframes with absolute search: keep Q range */
+ if ( *T0_min < pit_min )
+ {
+ *T0_min = pit_min;
+ }
+ *T0_max = *T0_min + delta2;
+
+ if ( *T0_max > pit_max )
+ {
+ *T0_max = pit_max;
+ *T0_min = *T0_max - delta2;
+ }
+ }
+ else
+ {
+ /* subframes with relative search: extend Q range */
+ if ( *T0_min < pit_min - LIMIT_PIT_REL_LOWER )
+ {
+ *T0_min = pit_min - LIMIT_PIT_REL_LOWER;
+ }
+
+ if ( *T0_min < L_INTERPOL )
+ {
+ *T0_min = L_INTERPOL;
+ }
+ *T0_max = *T0_min + delta2;
+
+ if ( *T0_max > pit_max + LIMIT_PIT_REL_UPPER )
+ {
+ *T0_max = pit_max + LIMIT_PIT_REL_UPPER;
+ *T0_min = *T0_max - delta2;
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------*
+ * Routine limit_T0_voiced()
+ *
+ * Close-loop pitch lag search limitation
+ *-------------------------------------------------*/
+
+void limit_T0_voiced(
+ const int16_t nbits,
+ const int16_t res,
+ const int16_t T0, /* i : rough pitch estimate around which the search is done */
+ const int16_t T0_frac, /* i : pitch estimate fractional part */
+ const int16_t T0_res, /* i : pitch resolution */
+ int16_t *T0_min, /* o : lower pitch limit */
+ int16_t *T0_min_frac, /* o : lower pitch limit */
+ int16_t *T0_max, /* o : higher pitch limit */
+ int16_t *T0_max_frac, /* o : higher pitch limit */
+ const int16_t pit_min, /* i : Minimum pitch lag */
+ const int16_t pit_max /* i : Maximum pitch lag */
+)
+{
+ int16_t T1, temp1, temp2;
+
+ /* Mid-point */
+ T1 = T0;
+ if ( ( T0_res > 1 ) && ( T0_frac >= ( T0_res >> 1 ) ) )
+ {
+ T1++;
+ }
+
+ /* Lower-bound */
+ temp1 = ( T1 * res ) - ( 1 << ( nbits - 1 ) );
+ temp2 = temp1 / res;
+ *T0_min = temp2;
+ *T0_min_frac = temp1 - temp2 * res;
+ if ( *T0_min < pit_min )
+ {
+ *T0_min = pit_min;
+ *T0_min_frac = 0;
+ }
+
+ /* Higher-bound */
+ temp1 = ( *T0_min * res ) + *T0_min_frac + ( 1 << nbits ) - 1;
+ temp2 = temp1 / res;
+ *T0_max = temp2;
+ *T0_max_frac = temp1 - temp2 * res;
+ if ( *T0_max > pit_max )
+ {
+ *T0_max = pit_max;
+ *T0_max_frac = res - 1;
+ temp1 = ( *T0_max * res ) + *T0_max_frac - ( 1 << nbits ) + 1;
+ temp2 = temp1 / res;
+ *T0_min = temp2;
+ *T0_min_frac = temp1 - temp2 * res;
+ }
+
+ return;
+}
diff --git a/lib_com/logqnorm.c b/lib_com/logqnorm.c
new file mode 100644
index 0000000000000000000000000000000000000000..04b822a14cfe39a742ab43253658b41120315c3c
--- /dev/null
+++ b/lib_com/logqnorm.c
@@ -0,0 +1,197 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "prot.h" /* Function prototypes */
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------
+ * logqnorm()
+ *
+ * Log quantization for norms of sub-vectors
+ *--------------------------------------------------------------------------*/
+
+void logqnorm(
+ const float *x, /* i : coefficient vector */
+ int16_t *k, /* o : index */
+ const int16_t L, /* i : codebook length */
+ const int16_t N, /* i : sub-vector size */
+ const float *thren /* i : quantization thresholds */
+)
+{
+ int16_t i, j, j1, j2;
+ float temp, power;
+
+
+ temp = 0.0;
+ for ( i = 0; i < N; i++ )
+ {
+ temp += ( x[i] * x[i] );
+ }
+
+ /* sqrt will be done later */
+ temp *= inv_tbl[N];
+
+ if ( thren[0] * thren[0] - temp <= 0 )
+ {
+ *k = 0;
+ }
+ else if ( thren[L - 2] * thren[L - 2] - temp > 0 )
+ {
+ *k = L - 1;
+ }
+ else
+ {
+ power = (float) sqrt( temp );
+
+ j1 = 0;
+ j2 = L - 1;
+ while ( ( j2 - j1 ) > 1 )
+ {
+ j = ( j1 + j2 ) >> 1;
+ if ( power >= thren[j] )
+ {
+ j2 = j;
+ }
+ else
+ {
+ j1 = j;
+ }
+ }
+
+ *k = j2;
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------
+ * logqnorm_2()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void logqnorm_2(
+ const float *env_fl, /* o : index */
+ const int16_t L, /* i : codebook length */
+ const int16_t n_env_band, /* i : sub-vector size */
+ const int16_t nb_sfm, /* i : sub-vector size */
+ int16_t *ynrm, /* o : norm indices */
+ int16_t *normqlg2, /* o : quantized norm values */
+ const float *thren /* i : quantization thresholds */
+)
+{
+ int16_t i, j, j1, j2;
+ float temp, power;
+
+ for ( i = n_env_band; i < nb_sfm; i++ )
+ {
+ temp = env_fl[i - n_env_band];
+ if ( thren[0] - temp <= 0 )
+ {
+ *ynrm = 0;
+ }
+ else if ( thren[L - 2] - temp > 0 )
+ {
+ *ynrm = L - 1;
+ }
+ else
+ {
+ power = temp;
+ j1 = 0;
+ j2 = L - 1;
+ while ( ( j2 - j1 ) > 1 )
+ {
+ j = ( j1 + j2 ) >> 1;
+ if ( power >= thren[j] )
+ {
+ j2 = j;
+ }
+ else
+ {
+ j1 = j;
+ }
+ }
+ *ynrm = j2;
+ }
+ *normqlg2 = dicnlg2[*ynrm];
+ normqlg2++;
+ ynrm++;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------
+ * calc_norm()
+ *
+ * Calculate the norms for the spectral envelope
+ *--------------------------------------------------------------------------*/
+
+void calc_norm(
+ const float *x, /* i : Input vector. */
+ int16_t *norm, /* o : Quantization indices for norms */
+ int16_t *normlg, /* o : Quantized norms in log2 */
+ const int16_t start_band, /* i : Indice of band to start coding */
+ const int16_t num_bands, /* i : Number of bands */
+ const int16_t *band_len, /* i : Length of bands */
+ const int16_t *band_start /* i : Start of bands */
+)
+{
+ int16_t nrm;
+ int16_t band;
+
+ set_s( norm, 0, start_band );
+
+ logqnorm( &x[band_start[start_band]], &nrm, 32, band_len[start_band], thren_HQ );
+ norm[start_band] = nrm;
+ normlg[start_band] = dicnlg2[nrm];
+
+ for ( band = start_band + 1; band < start_band + num_bands; band++ )
+ {
+ logqnorm( &x[band_start[band]], &nrm, 40, band_len[band], thren_HQ );
+ norm[band] = nrm;
+ normlg[band] = dicnlg2[nrm];
+ }
+
+ return;
+}
diff --git a/lib_com/longarith.c b/lib_com/longarith.c
new file mode 100644
index 0000000000000000000000000000000000000000..01a20c8417ea0091294f13b06829e567afcba36f
--- /dev/null
+++ b/lib_com/longarith.c
@@ -0,0 +1,183 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------------*
+ * longadd()
+ *
+ * long addition: a[] = a[] + b[]
+ * Addition of unsigned vectors a[] and b[] without saturation.
+ * All words of b[] are added with carry to the corresponding words in a.
+ * An assertion failure occurs, if lenb exceeds lena or if overflow occurs.
+ *--------------------------------------------------------------------*/
+
+void longadd(
+ uint16_t a[], /* i/o: vector of the length lena */
+ const uint16_t b[], /* i/o: vector of the length lenb */
+ const int16_t lena, /* i/o: length of vector a[] */
+ const int16_t lenb /* i/o: length of vector b[] */
+)
+{
+ int16_t h;
+ int32_t carry = 0;
+
+ assert( lena >= lenb );
+ for ( h = 0; h < lenb; h++ )
+ {
+ carry += ( (uint32_t) a[h] ) + ( (uint32_t) b[h] );
+ a[h] = (uint16_t) carry;
+ carry = carry >> 16;
+ }
+
+ for ( ; h < lena; h++ )
+ {
+ carry = ( (uint32_t) a[h] ) + carry;
+ a[h] = (uint16_t) carry;
+ carry = carry >> 16;
+ }
+
+ assert( carry == 0 ); /* carry != 0 indicates addition overflow */
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * longshiftright()
+ *
+ * long shift right: d[] = a[] >> b
+ * Logical shift right of unsigned vectors a[] by b bit-positions.
+ * Vector d[] is filled with leading zeroes, where lend exceeds lena.
+ * It is allowed to overlay d[] with a[].
+ *--------------------------------------------------------------------*/
+
+void longshiftright(
+ uint16_t a[], /* i : vector of the length lena */
+ const int16_t b, /* i : number of bit positions to shift right */
+ uint16_t d[], /* o : vector of the length lend */
+ int16_t lena, /* i : length of vector a[] */
+ const int16_t lend /* i : length of vector d[] */
+)
+{
+ int16_t intb, fracb, fracb_u, k;
+
+ intb = b >> 4;
+
+ a += intb;
+ lena -= intb;
+
+ fracb = b & 0xF;
+ if ( fracb )
+ {
+ fracb_u = 16 - fracb;
+ for ( k = 0; k < lena - 1; k++ )
+ {
+ d[k] = ( ( a[k] >> fracb ) | ( a[k + 1] << fracb_u ) ) & 0xFFFF;
+ }
+ d[k] = ( a[k] >> fracb );
+ k++;
+ }
+ else
+ {
+ for ( k = 0; k < lena; k++ )
+ {
+ d[k] = a[k];
+ }
+ }
+
+ /* fill remaining upper bits with zero */
+ for ( ; k < lend; k++ )
+ {
+ d[k] = 0;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * longshiftleft()
+ *
+ * long shift left: d[] = a[] << b
+ * Logical shift left of unsigned vectors a[] by b bit-positions.
+ * It is allowed to overlay d[] with a[].
+ *--------------------------------------------------------------------*/
+
+void longshiftleft(
+ const uint16_t a[], /* i : vector of the length len */
+ const int16_t b, /* i : number of bit positions to shift left */
+ uint16_t d[], /* o : vector of the length len */
+ const int16_t len /* i : length of vector a[] and d[] */
+)
+{
+ int16_t intb; /* integer part of b */
+ int16_t fracb; /* shift left value for all upper words a[k] */
+ int16_t fracb_l; /* shift right value for all lower words a[k-1] */
+ int16_t k = len - 1;
+
+ intb = b >> 4;
+ fracb = b & 0xF;
+
+ if ( fracb )
+ {
+ fracb_l = 16 - fracb;
+ for ( ; k > intb; k-- )
+ {
+ d[k] = ( a[k - intb] << fracb ) | ( a[k - intb - 1] >> fracb_l );
+ }
+ d[k] = ( a[k - intb] << fracb );
+ k--;
+ }
+ else
+ {
+ for ( ; k >= intb; k-- )
+ {
+ d[k] = a[k - intb];
+ }
+ }
+
+ for ( ; k >= 0; k-- )
+ {
+ d[k] = 0;
+ }
+
+ return;
+}
diff --git a/lib_com/low_rate_band_att.c b/lib_com/low_rate_band_att.c
new file mode 100644
index 0000000000000000000000000000000000000000..c715e0ac570682d5d54f6b163c85491dfdb9b483
--- /dev/null
+++ b/lib_com/low_rate_band_att.c
@@ -0,0 +1,192 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*--------------------------------------------------------------------------*
+ * fine_gain_pred()
+ *
+ * Fine gain prediction
+ *--------------------------------------------------------------------------*/
+
+void fine_gain_pred(
+ const int16_t *sfm_start, /* i : Sub band start indices */
+ const int16_t *sfm_end, /* i : Sub band end indices */
+ const int16_t *sfm_size, /* i : Sub band bandwidths */
+ const int16_t *i_sort, /* i : Energy sorting indices */
+ const int16_t *K, /* i : Number of pulses per band */
+ const int16_t *maxpulse, /* i : Maximum pulse per band */
+ const int16_t *R, /* i : Bits per sub band (Q3) */
+ const int16_t num_sfm, /* i : Number of sub bands */
+ float *xq, /* i/o: Quantized vector /quantized vector with finegain adj */
+ int16_t *y, /* i/o: Quantized vector */
+ float *fg_pred, /* o : Predicted fine gains */
+ const int16_t core /* i : Core */
+)
+{
+ int16_t i, band;
+ float gp;
+ float xx;
+ float accuracy;
+ int16_t k, bw;
+ float att;
+
+ for ( band = 0; band < num_sfm; band++ )
+ {
+
+ k = K[i_sort[band]];
+ if ( k > 0 )
+ {
+ bw = sfm_size[i_sort[band]];
+ xx = 0;
+ for ( i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++ )
+ {
+ xx += xq[i] * xq[i];
+ }
+
+ if ( xx > 0 )
+ {
+ /* Normalize synthesis to RMS=1.0 */
+ gp = (float) sqrt( bw / xx );
+
+ if ( core == HQ_CORE && R != NULL && R[i_sort[band]] <= 256 )
+ {
+ accuracy = ( (float) k / (float) bw ) * maxpulse[i_sort[band]];
+ att = 1.0f - 0.05f / accuracy;
+ att = max( 0.840896f, att ); /* Limit attenuation to norm quantizer error, 2^-0.25 */
+ gp *= att;
+ }
+
+ fg_pred[band] = gp;
+ }
+ else
+ {
+ fg_pred[band] = 0;
+ }
+ }
+ else
+ {
+ fg_pred[band] = 0;
+ for ( i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++ )
+ {
+ y[i] = 0;
+ xq[i] = 0;
+ }
+ }
+ }
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * get_max_pulses()
+ *
+ * Find the maximum pulse height (in unit pulses) in each band
+ *--------------------------------------------------------------------------*/
+
+void get_max_pulses(
+ const int16_t *band_start, /* i : Sub band start indices */
+ const int16_t *band_end, /* i : Sub band end indices */
+ const int16_t *k_sort, /* i : Indices for sorting by energy */
+ const int16_t *npulses, /* i : Pulses per sub band */
+ const int16_t BANDS, /* i : Number of bands */
+ int16_t *inp_vector, /* i/o: Encoded shape vectors */
+ int16_t *maxpulse /* o : Maximum pulse height per band */
+)
+{
+ int16_t i, k;
+ int16_t npul;
+ int16_t maxp;
+
+ for ( k = 0; k < BANDS; k++ )
+ {
+ npul = npulses[k_sort[k]];
+ maxp = 0;
+ if ( npul > 0 )
+ {
+ for ( i = band_start[k_sort[k]]; i < band_end[k_sort[k]]; i++ )
+ {
+ if ( abs( inp_vector[i] ) > maxp )
+ {
+ maxp = (int16_t) abs( inp_vector[i] );
+ }
+ }
+ }
+ maxpulse[k_sort[k]] = maxp;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * fine_gain_dec()
+ *
+ * Fine gain decoder. Decodes fine gain adjustments and applies correction to
+ * predicted fine gains
+ *--------------------------------------------------------------------------*/
+
+void fine_gain_dec(
+ Decoder_State *st, /* i/o: Decoder state struct */
+ const int16_t *ord, /* i : Indices for energy order */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int16_t *gain_bits, /* i : Gain adjustment bits per sub band */
+ float *fg_pred /* i/o: Predicted gains / Corrected gains */
+)
+{
+ int16_t band;
+ int16_t gbits;
+ int16_t idx;
+ float gain_dbq;
+
+ for ( band = 0; band < num_sfm; band++ )
+ {
+ gbits = gain_bits[ord[band]];
+ if ( fg_pred[band] != 0 && gbits > 0 )
+ {
+ idx = get_next_indice( st, gbits );
+ gain_dbq = finegain[gbits - 1][idx];
+
+ /* Update prediced gain with quantized correction */
+ fg_pred[band] *= (float) pow( 10, gain_dbq * 0.05f );
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/lpc_tools.c b/lib_com/lpc_tools.c
new file mode 100644
index 0000000000000000000000000000000000000000..9c936da11251af22b59e4e336479f3b21ea08ce1
--- /dev/null
+++ b/lib_com/lpc_tools.c
@@ -0,0 +1,333 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*-----------------------------------------------------------------*
+ * Local constants
+ *-----------------------------------------------------------------*/
+
+#define MAX_LEN_LP 960
+#define SCALE1_LPC 2037.1832275390625f /* LSP to LSF conversion factor */
+
+
+/*---------------------------------------------------------------------*
+ * autocorr()
+ *
+ * Compute autocorrelations of input signal
+ *---------------------------------------------------------------------*/
+
+void autocorr(
+ const float *x, /* i : input signal */
+ float *r, /* o : autocorrelations vector */
+ const int16_t m, /* i : order of LP filter */
+ const int16_t len, /* i : window size */
+ const float *wind, /* i : window */
+ const int16_t rev_flag, /* i : flag to reverse window */
+ const int16_t sym_flag, /* i : symmetric window flag */
+ const int16_t no_thr /* i : flag to avoid thresholding */
+)
+{
+ float t[MAX_LEN_LP];
+ float s;
+ int16_t i, j;
+
+ /* Windowing of signal */
+ if ( rev_flag == 1 )
+ {
+ /* time reversed window */
+ for ( i = 0; i < len; i++ )
+ {
+ t[i] = x[i] * wind[len - i - 1];
+ }
+ }
+ else if ( sym_flag == 1 )
+ {
+ /* symmetric window of even length */
+ for ( i = 0; i < len / 2; i++ )
+ {
+ t[i] = x[i] * wind[i];
+ }
+
+ for ( ; i < len; i++ )
+ {
+ t[i] = x[i] * wind[len - 1 - i];
+ }
+ }
+ else /* assymetric window */
+ {
+ for ( i = 0; i < len; i++ )
+ {
+ t[i] = x[i] * wind[i];
+ }
+ }
+
+ /* Compute r[1] to r[m] */
+ for ( i = 0; i <= m; i++ )
+ {
+ s = t[0] * t[i];
+ for ( j = 1; j < len - i; j++ )
+ {
+ s += t[j] * t[i + j];
+ }
+ r[i] = s;
+ }
+
+ if ( r[0] < 100.0f && no_thr == 0 )
+ {
+ r[0] = 100.0f;
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * lev_dur()
+ *
+ * Wiener-Levinson-Durbin algorithm to compute LP parameters from the autocorrelations
+ * of input signal
+ *---------------------------------------------------------------------*/
+
+/*! r: energy of prediction error */
+int16_t lev_dur(
+ float *a, /* o : LP coefficients (a[0] = 1.0) */
+ const float *r, /* i : vector of autocorrelations */
+ const int16_t m, /* i : order of LP filter */
+ float epsP[] /* o : prediction error energy */
+)
+{
+ int16_t i, j, l;
+ float buf[TCXLTP_LTP_ORDER];
+ float *rc; /* reflection coefficients 0,...,m-1 */
+ float s, at, err;
+ int16_t flag = 0;
+
+ rc = &buf[0];
+ rc[0] = ( -r[1] ) / r[0];
+ a[0] = 1.0f;
+ a[1] = rc[0];
+ err = r[0] + r[1] * rc[0];
+ if ( epsP != NULL )
+ {
+ epsP[0] = r[0];
+ epsP[1] = err;
+ }
+
+ for ( i = 2; i <= m; i++ )
+ {
+ s = 0.0f;
+ for ( j = 0; j < i; j++ )
+ {
+ s += r[i - j] * a[j];
+ }
+
+ rc[i - 1] = ( -s ) / err;
+
+ if ( fabs( rc[i - 1] ) > 0.99945f )
+ {
+ flag = 1; /* Test for unstable filter. If unstable keep old A(z) */
+ }
+
+ for ( j = 1; j <= i / 2; j++ )
+ {
+ l = i - j;
+ at = a[j] + rc[i - 1] * a[l];
+ a[l] += rc[i - 1] * a[j];
+ a[j] = at;
+ }
+
+ a[i] = rc[i - 1];
+
+ err += rc[i - 1] * s;
+ if ( err <= 0.0f )
+ {
+ err = 0.01f;
+ }
+
+ if ( epsP != NULL )
+ {
+ epsP[i] = err;
+ }
+ }
+
+ return ( flag );
+}
+
+
+/*---------------------------------------------------------------------*
+ * E_LPC_int_lpc_tcx()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+void E_LPC_int_lpc_tcx(
+ const float lsf_old[], /* i : LSFs from past frame */
+ const float lsf_new[], /* i : LSFs from present frame */
+ float a[] /* o : interpolated LP coefficients */
+)
+{
+ int16_t i;
+ float lsf[M];
+
+ for ( i = 0; i < M; i++ )
+ {
+ lsf[i] = lsf_old[i] * 0.125f + lsf_new[i] * 0.875f;
+ }
+
+ lsp2a_stab( lsf, a, M );
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * lsp_reorder()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+static void lsp_reorder(
+ float *lsp, /* i/o: lsp vector (acos() domain) */
+ float min_dist, /* i : minimum required distance */
+ const int16_t lpcorder /* i : LPC order */
+)
+{
+ int16_t i;
+ float lsp_min, lsp_max;
+
+ /* Verify the LSF ordering and minimum GAP */
+ lsp_min = min_dist;
+
+ for ( i = 0; i < lpcorder; ++i )
+ {
+ if ( lsp[i] < lsp_min )
+ {
+ lsp[i] = lsp_min;
+ }
+ lsp_min = lsp[i] + min_dist;
+ }
+
+ /* Reverify the LSF ordering and minimum GAP in the reverse order (security) */
+ lsp_max = EVS_PI - min_dist;
+
+ /* If danger of unstable filter in case of resonance in HF */
+ if ( lsp[lpcorder - 1] > lsp_max )
+ {
+ /* Reverify the minimum LSF gap in the reverse sense */
+ for ( i = lpcorder - 1; i >= 0; --i )
+ {
+ if ( lsp[i] > lsp_max )
+ {
+ lsp[i] = lsp_max;
+ }
+ lsp_max = lsp[i] - min_dist;
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * E_LPC_lsp_unweight()
+ *
+ * Approximate unweighting
+ *---------------------------------------------------------------------*/
+
+int16_t E_LPC_lsp_unweight(
+ const float lsp_w[], /* i : weighted lsp */
+ float lsp_uw[], /* o : unweighted lsp */
+ float lsf_uw[], /* o : unweighted lsf */
+ const float inv_gamma /* i : inverse weighting factor */
+)
+{
+ float lsp_w_orig[M], lsp_w_diff[M], mean, step;
+ const lsp_unw_triplet *unw_coeffs = NULL;
+ int16_t i;
+
+ /* Table selection */
+ if ( (float) fabs( inv_gamma - 1.0f / 0.94f ) < 0.0001f )
+ {
+ unw_coeffs = p16_gamma0_94to1;
+ }
+ else if ( (float) fabs( inv_gamma - 1.0f / 0.92f ) < 0.0001f )
+ {
+ unw_coeffs = p16_gamma0_92to1;
+ }
+ else
+ {
+ assert( 0 );
+ }
+
+ step = EVS_PI / (float) ( M + 1 );
+ mean = step;
+
+ /* Apply acos() and get mean removed version */
+ for ( i = 0; i < M; ++i )
+ {
+ lsp_w_orig[i] = (float) acos( lsp_w[i] );
+ lsp_w_diff[i] = lsp_w_orig[i] - mean;
+ mean += step;
+ }
+
+ /* Approximate unweighting by 3-tap FIR */
+
+ lsp_uw[0] = lsp_w_orig[0] + unw_coeffs[0][1] * lsp_w_diff[0] + unw_coeffs[0][2] * lsp_w_diff[1];
+ for ( i = 1; i < M - 1; ++i )
+ {
+ lsp_uw[i] = lsp_w_orig[i] + unw_coeffs[i][0] * lsp_w_diff[i - 1] + unw_coeffs[i][1] * lsp_w_diff[i] + unw_coeffs[i][2] * lsp_w_diff[i + 1];
+ }
+
+ lsp_uw[M - 1] = lsp_w_orig[M - 1] + unw_coeffs[M - 1][0] * lsp_w_diff[M - 2] + unw_coeffs[M - 1][1] * lsp_w_diff[M - 1];
+
+ /* Reorder */
+ lsp_reorder( lsp_uw, 50.0f / SCALE1_LPC, M );
+
+ /* Convert to lsf, apply cos() */
+ for ( i = 0; i < M; ++i )
+ {
+ lsf_uw[i] = lsp_uw[i] * SCALE1_LPC;
+ lsp_uw[i] = (float) cos( lsp_uw[i] );
+ }
+
+ return 0;
+}
diff --git a/lib_com/lsf_dec_bfi.c b/lib_com/lsf_dec_bfi.c
new file mode 100644
index 0000000000000000000000000000000000000000..70506b293c18856de3fad6c631b25648dc8fb9d5
--- /dev/null
+++ b/lib_com/lsf_dec_bfi.c
@@ -0,0 +1,298 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * routine: lsf_dec_bfi()
+ *
+ * Estimate the lsfs in case of FER
+ * Bad frame, all active speech coders
+ *---------------------------------------------------------------------*/
+
+void lsf_dec_bfi(
+ const int16_t codec_mode, /* i : codec mode: MODE1 | MODE2 */
+ float *lsf, /* o : estimated LSF vector */
+ const float *lsfold, /* i : past quantized lsf */
+ float *lsf_adaptive_mean, /* i : lsf adaptive mean, updated when BFI==0 */
+ const float lsfBase[], /* i : base for differential lsf coding */
+ float *mem_MA, /* i/o: quantizer memory for MA model */
+ float *mem_AR, /* o : quantizer memory for AR model */
+ const float stab_fac, /* i : lsf stability factor */
+ const int16_t last_coder_type, /* i : last coder type */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t last_good, /* i : last good received frame */
+ const int16_t nbLostCmpt, /* i : counter of consecutive bad frames */
+ const int16_t plcBackgroundNoiseUpdated, /* i : background noise already updated?*/
+ float *lsf_q_cng, /* o : quantized lsfs of background noise */
+ float *lsf_cng, /* i : long term target for fading to bg noise*/
+ float *old_lsf_q_cng, /* i : old quantized lsfs for background noise*/
+ const int16_t Last_GSC_pit_band_idx, /* i : AC mode (GSC) - Last pitch band index */
+ const int16_t Opt_AMR_WB, /* i : IO flag */
+ const int16_t bwidth /* i : coded bandwidth */
+)
+{
+ int16_t i;
+ float alpha, tmp;
+ float lsf_mean[M];
+ const float *pt_meansForFading;
+ const float *pt_meansForMemUpdate;
+ float beta;
+
+ /* init vectors */
+ if ( codec_mode == MODE1 )
+ {
+ pt_meansForMemUpdate = &lsf_mean[0];
+
+ if ( Opt_AMR_WB )
+ {
+ pt_meansForFading = mean_isf_amr_wb;
+ }
+ else
+ {
+ if ( L_frame == L_FRAME )
+ {
+ if ( bwidth == NB )
+ {
+ pt_meansForFading = GENB_Ave;
+ }
+ else
+ {
+ pt_meansForFading = GEWB_Ave;
+ }
+ }
+ else
+ {
+ pt_meansForFading = GEWB2_Ave;
+ }
+ }
+ }
+ else
+ {
+ pt_meansForFading = pt_meansForMemUpdate = lsfBase;
+ if ( lsf_cng != NULL && plcBackgroundNoiseUpdated )
+ {
+ pt_meansForFading = lsf_cng;
+ }
+ }
+
+ /*----------------------------------------------------------------------*
+ * Initialize the alpha factor
+ *----------------------------------------------------------------------*/
+
+ if ( nbLostCmpt <= 3 )
+ {
+ if ( last_coder_type == UNVOICED )
+ {
+ /* clearly unvoiced */
+ alpha = ALPHA_UU;
+ }
+ else if ( last_coder_type == AUDIO || last_good == INACTIVE_CLAS )
+ {
+ if ( Last_GSC_pit_band_idx > 0 && nbLostCmpt > 1 )
+ {
+ alpha = 0.8f;
+ }
+ else
+ {
+ alpha = 0.995f;
+ }
+ }
+ else if ( last_good == UNVOICED_CLAS )
+ {
+ if ( nbLostCmpt <= 1 )
+ {
+ /* if stable, do not flatten the spectrum in the 1st erased frame */
+ alpha = stab_fac * ( 1.0f - 2.0f * ALPHA_U ) + 2.0f * ALPHA_U; /* [0.8, 1.0] */
+ }
+ else if ( nbLostCmpt == 2 )
+ {
+ alpha = ALPHA_U * 1.5f; /* 0.6 */
+ }
+ else
+ {
+ /* go rapidly to CNG spectrum */
+ alpha = ALPHA_U;
+ }
+ }
+ else if ( last_good == UNVOICED_TRANSITION )
+ {
+ alpha = ALPHA_UT;
+ }
+ else if ( last_good == VOICED_CLAS || last_good == ONSET )
+ {
+ /* clearly voiced - mild convergence to the CNG spectrum for the first 3 erased frames */
+ alpha = ALPHA_V;
+ }
+ else if ( last_good == SIN_ONSET )
+ {
+ alpha = ALPHA_S;
+ }
+ else
+ {
+ alpha = ALPHA_VT;
+ }
+ }
+ else
+ {
+ alpha = 1.f / nbLostCmpt;
+ }
+
+ if ( codec_mode == MODE1 )
+ {
+ beta = BETA_FEC;
+ }
+ else
+ {
+ if ( plcBackgroundNoiseUpdated )
+ {
+ beta = 0.f;
+ }
+ else
+ {
+ beta = 0.25f;
+ }
+ }
+
+ for ( i = 0; i < M; i++ )
+ {
+ lsf_mean[i] = beta * pt_meansForFading[i] + ( 1 - beta ) * lsf_adaptive_mean[i];
+ lsf[i] = alpha * lsfold[i] + ( 1.0f - alpha ) * lsf_mean[i]; /* towards the CNG spectral envelope */
+
+ if ( lsf_q_cng != NULL )
+ {
+ lsf_q_cng[i] = max( alpha, 0.8f ) * old_lsf_q_cng[i] + ( 1.0f - max( alpha, 0.8f ) ) * pt_meansForFading[i];
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * - estimate past quantized residual to be used in next frame
+ * - Check A(z) filter stability through lsf ordering
+ *-----------------------------------------------------------------*/
+
+ if ( Opt_AMR_WB )
+ {
+ reorder_isf( lsf, ISF_GAP, M, INT_FS_12k8 );
+ }
+ else
+ {
+ if ( L_frame == L_FRAME )
+ {
+ reorder_lsf( lsf, codec_mode == MODE1 ? MODE1_LSF_GAP : LSF_GAP, M, INT_FS_12k8 );
+
+ if ( lsf_q_cng != NULL )
+ {
+ reorder_lsf( lsf_q_cng, LSF_GAP, M, INT_FS_12k8 );
+ }
+ }
+ else /* L_frame > L_FRAME */
+ {
+ reorder_lsf( lsf, MODE1_LSF_GAP, M, L_frame * FRAMES_PER_SEC );
+ if ( lsf_q_cng != NULL )
+ {
+ reorder_lsf( lsf_q_cng, MODE1_LSF_GAP, M, L_frame * FRAMES_PER_SEC );
+ }
+ }
+ }
+ /* update the AR memory to be used in the next frame */
+ mvr2r( lsf, mem_AR, M );
+
+ for ( i = 0; i < M; i++ )
+ {
+ tmp = lsf[i] - pt_meansForMemUpdate[i];
+ mem_MA[i] = (float) ( tmp - MU_MA * mem_MA[i] ); /* Update with quantized prediction error for MA model */
+ mem_MA[i] *= 0.5f; /* Attenuate the MA Q memory */
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * routine: PlcGetlsfBase()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+const float *PlcGetlsfBase(
+ const int16_t lpcQuantization,
+ const int16_t narrowBand,
+ const int32_t sr_core )
+{
+ if ( lpcQuantization == 0 )
+ {
+ /* high rates, return value is never used; the correct value changes
+ dynamically and is not available during PLC; therefore, the setting
+ is kept as before (without the define PLC_FIX_XSF_HANDLING); the
+ correct value would be isf[m] as returned by lpc_unquantize()
+ during normal decoding */
+
+ if ( sr_core == 32000 )
+ {
+ return means_swb_cleanspeech_lsf32k0;
+ }
+ else if ( sr_core == 25600 )
+ {
+ return means_swb_cleanspeech_lsf25k6;
+ }
+ else
+ {
+ return means_wb_cleanspeech_lsf16k0;
+ }
+ }
+
+ /* lpcQuntization == 1 is left */
+
+ if ( sr_core == INT_FS_16k )
+ {
+ return GEWB2_Ave;
+ }
+
+ /* sr_core == 12.8k is left */
+
+ if ( narrowBand == 0 )
+ {
+ return GEWB_Ave;
+ }
+
+ /* narrowBand == 1 is left */
+ return GENB_Ave;
+}
diff --git a/lib_com/lsf_msvq_ma.c b/lib_com/lsf_msvq_ma.c
new file mode 100644
index 0000000000000000000000000000000000000000..940233e4c3bdc8849597dc33d3323348c9c97f87
--- /dev/null
+++ b/lib_com/lsf_msvq_ma.c
@@ -0,0 +1,175 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "stl.h"
+#include "basop_proto_func.h"
+#include "wmc_auto.h"
+
+/*---------------------------------------------------------------------*
+ * midlsf_dec()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+void midlsf_dec(
+ const float qlsf0[],
+ const float qlsf1[],
+ const int16_t idx,
+ float qlsf[],
+ const int16_t N,
+ const int16_t coder_type,
+ int16_t *mid_lsf_int,
+ const int16_t prev_bfi,
+ const int16_t safety_net )
+{
+ const float *ratio = NULL;
+ int16_t j;
+ int16_t bad_spacing = 0;
+ /* Select codebook */
+ if ( coder_type == UNVOICED )
+ {
+ ratio = tbl_mid_unv_wb_5b;
+ }
+ else
+ {
+ ratio = tbl_mid_gen_wb_5b;
+ }
+
+ for ( j = 0; j < N; j++ )
+ {
+ qlsf[j] = ( 1.0f - ratio[idx * N + j] ) * qlsf0[j] + ratio[idx * N + j] * qlsf1[j];
+ }
+
+ if ( mid_lsf_int != NULL ) /*at the decoder*/
+ {
+ /* check for incorrect LSF ordering */
+ if ( *mid_lsf_int == 1 )
+ {
+ for ( j = 1; j < N; j++ )
+ {
+ if ( qlsf[j] < qlsf[j - 1] )
+ {
+ bad_spacing = 1;
+ break;
+ }
+ }
+ }
+ /* Redo mid-LSF interpolation with 0.4 in case of LSF instability */
+ if ( prev_bfi || ( *mid_lsf_int == 1 && bad_spacing ) )
+ {
+ for ( j = 0; j < N; j++ )
+ {
+ /* redo mid-LSF interpolation with 0.4 */
+ qlsf[j] = 0.4f * qlsf0[j] + 0.6f * qlsf1[j];
+
+ /* ensure correct ordering of LSF indices */
+ if ( j > 0 && j < N && qlsf[j] < qlsf[j - 1] + LSF_GAP_MID )
+ {
+ qlsf[j] = qlsf[j - 1] + LSF_GAP_MID;
+ }
+ }
+ }
+ else
+ {
+ /* otherwise, use regular LSF spacing and ordering as in the encoder */
+ for ( j = 0; j < N; j++ )
+ {
+ if ( j > 0 && j < N && qlsf[j] < qlsf[j - 1] + LSF_GAP_MID )
+ {
+ qlsf[j] = qlsf[j - 1] + LSF_GAP_MID;
+ }
+ }
+ }
+ if ( prev_bfi )
+ {
+ /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */
+ *mid_lsf_int = 1;
+ }
+ if ( safety_net )
+ {
+ /* safety-net encountered -> stop redoing mid-LSF interpolation with 0.4 */
+ *mid_lsf_int = 0;
+ }
+ }
+ else
+ {
+ /* use regular LSF spacing */
+ for ( j = 0; j < N; j++ )
+ {
+ if ( j > 0 && j < N && qlsf[j] < qlsf[j - 1] + LSF_GAP_MID )
+ {
+ qlsf[j] = qlsf[j - 1] + LSF_GAP_MID;
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * lsf_ind_is_active()
+ *
+ *
+ *---------------------------------------------------------------------*/
+
+int16_t lsf_ind_is_active(
+ const Word16 lsf_q_ind[],
+ const float means[],
+ const int16_t narrowband,
+ const int16_t cdk )
+{
+ Word16 lsf[2], min_distance;
+
+ lsf[0] = add( lsf_q_ind[0], LSFM( means[0] ) );
+ move16();
+ lsf[1] = add( lsf_q_ind[1], LSFM( means[1] ) );
+ move16();
+
+ min_distance = lsf[0];
+ min_distance = s_min( min_distance, sub( lsf[1], lsf[0] ) );
+
+ assert( narrowband == 0 || narrowband == 1 );
+ assert( cdk == 0 || cdk == 1 );
+
+ return sub( min_distance, min_distance_thr[narrowband][cdk] ) < 0;
+}
diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c
new file mode 100644
index 0000000000000000000000000000000000000000..eaa94b506fcb016c0e4b6f34e6f8e58301f0f316
--- /dev/null
+++ b/lib_com/lsf_tools.c
@@ -0,0 +1,2620 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "basop_proto_func.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local function prototypes
+ *-------------------------------------------------------------------*/
+
+static float chebps2( const float x, const float *f, const int16_t n );
+static float LPC_chebyshev( float x, float f[], const int16_t n );
+static void get_isppol( const float *isp, float f[], const int16_t n );
+
+/*---------------------------------------------------------------------*
+ * a2isp()
+ *
+ * Compute the ISPs from the LPC coefficients a[] using Chebyshev
+ * polynomials. The found ISPs are in the cosine domain with values
+ * in the range from 1 down to -1.
+ * The table grid[] contains the points (in the cosine domain) at
+ * which the polynomials are evaluated.
+ *
+ * The ISPs are the roots of the two polynomials F1(z) and F2(z)
+ * defined as
+ * F1(z) = [A(z) + z^-M A(z^-1)]
+ * and F2(z) = [A(z) - z^-M A(z^-1)]/ (1-z^-2)
+ *
+ * For an even order M=2N, F1(z) has M/2 conjugate roots on the unit circle
+ * and F2(z) has M/2-1 conjugate roots on the unit circle in addition to two
+ * roots at 0 and pi.
+ *
+ * For a 16th order LP analysis (M=16), F1(z) and F2(z) can be written as
+ *
+ * F1(z) = (1 + a[16]) * PRODUCT (1 - 2 cos(w_i) z^-1 + z^-2 )
+ * i=0,2,...,14
+ *
+ * F2(z) = (1 - a[16]) * PRODUCT (1 - 2 cos(w_i) z^-1 + z^-2 )
+ * i=1,3,...,13
+ *
+ * The ISPs are frequencies w_i, i=0...M-2 plus the last predictor
+ * coefficient a[M].
+ *---------------------------------------------------------------------*/
+
+void a2isp(
+ const float *a, /* i : LP filter coefficients */
+ float *isp, /* o : Immittance spectral pairs */
+ const float *old_isp /* i : ISP vector from past frame */
+)
+{
+ int16_t j, i, nf, ip, order;
+ float xlow, ylow, xhigh, yhigh, xmid, ymid, xint;
+ float f1[NC + 1], f2[NC];
+ float *coef;
+
+ /*-------------------------------------------------------------*
+ * find the sum and diff polynomials F1(z) and F2(z)
+ * F1(z) = [A(z) + z^M A(z^-1)]
+ * F2(z) = [A(z) - z^M A(z^-1)]/(1-z^-2)
+ *
+ * for (i=0; i 1.0f ) || ( a[M] < -1.0f ) )
+ {
+ for ( i = 0; i < M; i++ )
+ {
+ isp[i] = old_isp[i];
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * isp2a()
+ *
+ * Convert ISPs to predictor coefficients a[]
+ *-------------------------------------------------------------------*/
+
+void isp2a(
+ const float *isp, /* i : ISP vector (in the cosine domain) */
+ float *a, /* o : LP filter coefficients */
+ const int16_t m /* i : order of LP analysis */
+)
+{
+ float f1[NC16k + 1], f2[NC16k];
+ int16_t i, j;
+ int16_t nc;
+
+ nc = m / 2;
+
+ /*-----------------------------------------------------------------*
+ * Find the polynomials F1(z) and F2(z) *
+ *-----------------------------------------------------------------*/
+
+ get_isppol( &isp[0], f1, nc );
+ get_isppol( &isp[1], f2, (int16_t) ( nc - 1 ) );
+
+ /*-----------------------------------------------------------------*
+ * Multiply F2(z) by (1 - z^-2) *
+ *-----------------------------------------------------------------*/
+
+ for ( i = nc - 1; i > 1; i-- )
+ {
+ f2[i] -= f2[i - 2];
+ }
+
+ /*-----------------------------------------------------------------*
+ * Scale F1(z) by (1+isp[m-1]) and F2(z) by (1-isp[m-1]) *
+ *-----------------------------------------------------------------*/
+
+ for ( i = 0; i < nc; i++ )
+ {
+ f1[i] *= ( 1.0f + isp[m - 1] );
+ f2[i] *= ( 1.0f - isp[m - 1] );
+ }
+
+ /*-----------------------------------------------------------------*
+ * A(z) = (F1(z)+F2(z))/2 *
+ * F1(z) is symmetric and F2(z) is asymmetric *
+ *-----------------------------------------------------------------*/
+
+ a[0] = 1.0f;
+ for ( i = 1, j = m - 1; i < nc; i++, j-- )
+ {
+ a[i] = (float) ( 0.5f * ( f1[i] + f2[i] ) );
+ a[j] = (float) ( 0.5f * ( f1[i] - f2[i] ) );
+ }
+ a[nc] = (float) ( 0.5f * f1[nc] * ( 1.0f + isp[m - 1] ) );
+ a[m] = isp[m - 1];
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * a2lsp()
+ *
+ * Convert predictor coefficients a[] to LSPs
+ *-------------------------------------------------------------------*/
+
+int16_t a2lsp(
+ float *freq, /* o : LSP vector */
+ const float *a_in, /* i : predictor coefficients */
+ const int16_t order /* i : order of LP analysis */
+)
+{
+ int16_t i, iswitch, offset, STEPindex;
+ int16_t lspnumber, root, notlast, order_by_2;
+ float temp, temp2;
+ float q[20], prev[2];
+ float frequency, LastFreq, STEP;
+ const float *a;
+ float space_min;
+
+ a = &( a_in[1] );
+ order_by_2 = order / 2;
+ LastFreq = 0;
+
+ /* calculate q[z] and p[z] , they are all stored in q */
+ offset = order_by_2;
+ q[0] = (float) ( a[0] + a[order - 1] - 1.0 );
+ q[offset] = (float) ( a[0] - a[order - 1] + 1.0 );
+ for ( i = 1; i < order_by_2; i++ )
+ {
+ q[i] = a[i] + a[order - 1 - i] - q[i - 1];
+ q[i + offset] = a[i] - a[order - 1 - i] + q[i - 1 + offset];
+ }
+
+ q[order_by_2 - 1] = q[order_by_2 - 1] / 2;
+ q[order_by_2 - 1 + offset] = q[order_by_2 - 1 + offset] / 2;
+
+ prev[0] = 9e9f;
+ prev[1] = 9e9f;
+ lspnumber = 0;
+ notlast = 1;
+ iswitch = 0;
+ frequency = 0;
+
+ while ( notlast )
+ {
+ root = 1;
+ offset = iswitch * order_by_2;
+ STEPindex = 0; /* Start with low resolution grid */
+ STEP = STEPS[STEPindex];
+ while ( root )
+ {
+ temp = (float) cos( frequency * 6.2832 );
+ if ( order >= 4 )
+ {
+ temp2 = LPC_chebyshev( temp, q + offset, order_by_2 );
+ }
+ else
+ {
+ temp2 = temp + q[0 + offset];
+ }
+
+ if ( ( temp2 * prev[iswitch] ) <= 0.0 || frequency >= 0.5 )
+ {
+ if ( STEPindex == STEPSNUM - 1 )
+ {
+ if ( fabs( temp2 ) < fabs( prev[iswitch] ) )
+ {
+ freq[lspnumber] = frequency;
+ }
+ else
+ {
+ freq[lspnumber] = frequency - STEP;
+ }
+ if ( ( prev[iswitch] ) < 0.0 )
+ {
+ prev[iswitch] = 9e9f;
+ }
+ else
+ {
+ prev[iswitch] = -9e9f;
+ }
+ root = 0;
+ frequency = LastFreq;
+ STEPindex = 0;
+ }
+ else
+ {
+ if ( STEPindex == 0 )
+ {
+ LastFreq = frequency;
+ }
+ frequency -= STEPS[++STEPindex]; /* Go back one grid step */
+ STEP = STEPS[STEPindex];
+ }
+ }
+ else
+ {
+ prev[iswitch] = temp2;
+ frequency += STEP;
+ }
+ } /* while(root) */
+
+ lspnumber++;
+ if ( lspnumber > order - 1 )
+ {
+ notlast = 0;
+ }
+ iswitch = 1 - iswitch;
+ } /* while (notlast) */
+
+ /* stability check */
+ space_min = 1;
+ for ( i = 1; i < order; i++ )
+ {
+ space_min = ( ( freq[i] - freq[i - 1] ) < space_min ) ? ( freq[i] - freq[i - 1] ) : space_min;
+ }
+
+ if ( space_min <= 0 )
+ {
+ return 0;
+ }
+
+ return 1;
+}
+
+/*-------------------------------------------------------------------*
+ * lsp2a()
+ *
+ * Convert LSPs to predictor coefficients a[]
+ *-------------------------------------------------------------------*/
+
+void lsp2a(
+ float *pc_in, /* i/o: predictor coefficients */
+ float *freq, /* i/o: LSP coefficients */
+ const int16_t order /* i : order of LP analysis */
+)
+{
+ float p[LPC_SHB_ORDER], q[LPC_SHB_ORDER];
+ float a[LPC_SHB_ORDER], a1[LPC_SHB_ORDER], a2[LPC_SHB_ORDER];
+ float b[LPC_SHB_ORDER], b1[LPC_SHB_ORDER], b2[LPC_SHB_ORDER];
+
+ float xx;
+ int16_t i, k;
+ int16_t lspflag;
+ float *pc;
+ int16_t order_by_2;
+
+ lspflag = 1;
+ pc = &( pc_in[1] );
+
+ order_by_2 = order / 2;
+
+ /* check input for ill-conditioned cases */
+ if ( ( freq[0] <= 0.0 ) || ( freq[order - 1] >= 0.5 ) )
+ {
+ lspflag = 0;
+
+ if ( freq[0] <= 0 )
+ {
+ freq[0] = 0.022f;
+ }
+
+ if ( freq[order - 1] >= 0.5 )
+ {
+ freq[order - 1] = 0.499f;
+ }
+ }
+
+ if ( !lspflag )
+ {
+ xx = ( freq[order - 1] - freq[0] ) * recip_order[order];
+ for ( i = 1; i < order; i++ )
+ {
+ freq[i] = freq[i - 1] + xx;
+ }
+ }
+
+ for ( i = 0; i <= order_by_2; i++ )
+ {
+ a[i] = 0.;
+ a1[i] = 0.;
+ a2[i] = 0.;
+ b[i] = 0.;
+ b1[i] = 0.;
+ b2[i] = 0.;
+ }
+
+ for ( i = 0; i < order_by_2; i++ )
+ {
+ p[i] = (float) cos( 6.2832 * freq[2 * i] );
+ q[i] = (float) cos( 6.2832 * freq[2 * i + 1] );
+ }
+
+ a[0] = 0.25f;
+ b[0] = 0.25f;
+
+ for ( i = 0; i < order_by_2; i++ )
+ {
+ a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
+ b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
+ a2[i] = a1[i];
+ a1[i] = a[i];
+ b2[i] = b1[i];
+ b1[i] = b[i];
+ }
+ a[0] = 0.25f;
+ b[0] = -0.25f;
+
+ for ( i = 0; i < order_by_2; i++ )
+ {
+ a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
+ b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
+ a2[i] = a1[i];
+ a1[i] = a[i];
+ b2[i] = b1[i];
+ b1[i] = b[i];
+ }
+
+ pc[0] = 2 * ( a[order_by_2] + b[order_by_2] );
+
+ for ( k = 2; k <= order; k++ )
+ {
+ a[0] = 0.0f;
+ b[0] = 0.0f;
+
+ for ( i = 0; i < order_by_2; i++ )
+ {
+ a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
+ b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
+ a2[i] = a1[i];
+ a1[i] = a[i];
+ b2[i] = b1[i];
+ b1[i] = b[i];
+ }
+ pc[k - 1] = 2 * ( a[order_by_2] + b[order_by_2] );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------*
+ * get_lsppol()
+ *
+ * Find the polynomial F1(z) or F2(z) from the LSPs.
+ * This is performed by expanding the product polynomials:
+ *
+ * F1(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 )
+ * i=0,2,4,..,n-2
+ * F2(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 )
+ * i=1,3,5,..,n-1
+ *
+ * where LSP_i are the LSPs in the cosine domain.
+ *-----------------------------------------------------------*/
+
+static void get_lsppol(
+ const float lsp[], /* i : line spectral freq. (cosine domain) */
+ float f[], /* o : the coefficients of F1 or F2 */
+ const int16_t n, /* i : no of coefficients (m/2) */
+ int16_t flag /* i : 1 ---> F1(z); 2 ---> F2(z) */
+)
+{
+ float b;
+ const float *plsp;
+ int16_t i, j;
+
+ plsp = lsp + flag - 1;
+
+ f[0] = 1.0f;
+ b = -2.0f * *plsp;
+ f[1] = b;
+
+ for ( i = 2; i <= n; i++ )
+ {
+ plsp += 2;
+ b = -2.0f * *plsp;
+ f[i] = b * f[i - 1] + 2.0f * f[i - 2];
+
+ for ( j = i - 1; j > 1; j-- )
+ {
+ f[j] += b * f[j - 1] + f[j - 2];
+ }
+
+ f[1] += b;
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * a2lsp_stab()
+ *
+ * Compute the LSPs from the LPC coefficients a[] using Chebyshev
+ * polynomials. The found LSPs are in the cosine domain with values
+ * in the range from 1 down to -1.
+ * The table grid[] contains the points (in the cosine domain) at
+ * which the polynomials are evaluated.
+ *
+ * The ISPs are the roots of the two polynomials F1(z) and F2(z)
+ * defined as
+ * F1(z) = [A(z) + z^-M A(z^-1)]/ (1+z^-1)
+ * and F2(z) = [A(z) - z^-M A(z^-1)]/ (1-z^-1)
+ *---------------------------------------------------------------------*/
+
+void a2lsp_stab(
+ const float *a, /* i : LP filter coefficients */
+ float *lsp, /* o : LSP vector */
+ const float *old_lsp /* i : LSP vector from past frame */
+)
+{
+ int16_t j, i, nf, ip;
+ float xlow, ylow, xhigh, yhigh, xmid, ymid, xint;
+ float *pf1, *pf2;
+ const float *pa1, *pa2;
+ float f1[NC + 1], f2[NC + 1];
+
+ /*-------------------------------------------------------------*
+ * find the sum and diff polynomials F1(z) and F2(z) *
+ * F1(z) = [A(z) + z^11 A(z^-1)]/(1+z^-1) *
+ * F2(z) = [A(z) - z^11 A(z^-1)]/(1-z^-1) *
+ *-------------------------------------------------------------*/
+
+ pf1 = f1; /* Equivalent code using indices */
+ pf2 = f2;
+ *pf1++ = 1.0f; /* f1[0] = 1.0; */
+ *pf2++ = 1.0f; /* f2[0] = 1.0; */
+ pa1 = a + 1;
+ pa2 = a + M;
+
+ for ( i = 0; i <= NC - 1; i++ ) /* for (i=1, j=M; i<=NC; i++, j--) */
+ {
+ *pf1 = *pa1 + *pa2 - *( pf1 - 1 ); /* f1[i] = a[i]+a[j]-f1[i-1]; */
+ *pf2 = *pa1++ - *pa2-- + *( pf2 - 1 ); /* f2[i] = a[i]-a[j]+f2[i-1]; */
+ pf1++;
+ pf2++;
+ }
+
+ /*---------------------------------------------------------------------*
+ * Find the LSPs (roots of F1(z) and F2(z) ) using the *
+ * Chebyshev polynomial evaluation. *
+ * The roots of F1(z) and F2(z) are alternatively searched. *
+ * We start by finding the first root of F1(z) then we switch *
+ * to F2(z) then back to F1(z) and so on until all roots are found. *
+ * *
+ * - Evaluate Chebyshev pol. at grid points and check for sign change.*
+ * - If sign change track the root by subdividing the interval *
+ * 4 times and ckecking sign change. *
+ *---------------------------------------------------------------------*/
+
+ nf = 0; /* number of found frequencies */
+ ip = 0; /* flag to first polynomial */
+
+ pf1 = f1; /* start with F1(z) */
+
+ xlow = grid100[0];
+ ylow = chebps2( xlow, pf1, NC );
+
+ j = 0;
+ while ( ( nf < M ) && ( j < GRID100_POINTS ) )
+ {
+ j++;
+ xhigh = xlow;
+ yhigh = ylow;
+ xlow = grid100[j];
+ ylow = chebps2( xlow, pf1, NC );
+
+ if ( ylow * yhigh <= 0.0 ) /* if sign change new root exists */
+ {
+ j--;
+ /* divide the interval of sign change by NO_ITER */
+ for ( i = 0; i < NO_ITER; i++ )
+ {
+ xmid = 0.5f * ( xlow + xhigh );
+ ymid = chebps2( xmid, pf1, NC );
+ if ( ylow * ymid <= 0.0 )
+ {
+ yhigh = ymid;
+ xhigh = xmid;
+ }
+ else
+ {
+ ylow = ymid;
+ xlow = xmid;
+ }
+ }
+
+ /* linear interpolation for evaluating the root */
+ ymid = ( yhigh - ylow );
+ xint = xlow;
+ if ( ymid != 0 && ylow != 0 ) /* whenever ylow is 0, it doesn't make sense to compute the remaining part of the equation */
+ {
+ xint -= ylow * ( xhigh - xlow ) / ( ymid );
+ }
+ lsp[nf] = xint; /* new root */
+ nf++;
+ ip = 1 - ip; /* flag to other polynomial */
+ pf1 = ip ? f2 : f1; /* pointer to other polynomial */
+ xlow = xint;
+ ylow = chebps2( xlow, pf1, NC );
+ }
+ }
+
+ /* Check if M roots found */
+ /* if not use the LSPs from previous frame */
+ if ( nf < M )
+ {
+
+ for ( i = 0; i < M; i++ )
+ {
+ lsp[i] = old_lsp[i];
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * lsp2a_stab()
+ *
+ * Convert LSPs to predictor coefficients A[]
+ *-------------------------------------------------------------------*/
+
+void lsp2a_stab(
+ const float *lsp, /* i : LSF vector (in the cosine domain) */
+ float *a, /* o : LP filter coefficients */
+ const int16_t m /* i : order of LP analysis */
+)
+{
+ float f1[NC + 1], f2[NC + 1];
+ int16_t i, k, nc;
+ float *pf1, *pf2, *pf1_1, *pf2_1, *pa1, *pa2;
+
+ nc = m / 2;
+
+ /*-----------------------------------------------------*
+ * Find the polynomials F1(z) and F2(z) *
+ *-----------------------------------------------------*/
+
+ get_lsppol( lsp, f1, nc, 1 );
+ get_lsppol( lsp, f2, nc, 2 );
+
+ /*-----------------------------------------------------*
+ * Multiply F1(z) by (1+z^-1) and F2(z) by (1-z^-1) *
+ *-----------------------------------------------------*/
+
+ pf1 = f1 + nc;
+ pf1_1 = pf1 - 1;
+ pf2 = f2 + nc; /* Version using indices */
+ pf2_1 = pf2 - 1;
+ k = nc - 1;
+ for ( i = 0; i <= k; i++ ) /* for (i = NC; i > 0; i--) */
+ {
+ *pf1-- += *pf1_1--; /* f1[i] += f1[i-1]; */
+ *pf2-- -= *pf2_1--; /* f2[i] -= f2[i-1]; */
+ }
+
+ /*-----------------------------------------------------*
+ * A(z) = (F1(z)+F2(z))/2 *
+ * F1(z) is symmetric and F2(z) is antisymmetric *
+ *-----------------------------------------------------*/
+
+ pa1 = a;
+ *pa1++ = 1.0; /* a[0] = 1.0; */
+ pa2 = a + m;
+ pf1 = f1 + 1;
+ pf2 = f2 + 1;
+ for ( i = 0; i <= k; i++ ) /* for (i=1, j=M; i<=NC; i++, j--) */
+ {
+ *pa1++ = 0.5f * ( *pf1 + *pf2 ); /* a[i] = 0.5*(f1[i] + f2[i]); */
+ *pa2-- = 0.5f * ( *pf1++ - *pf2++ ); /* a[j] = 0.5*(f1[i] - f2[i]); */
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------------
+ * reorder_lsf()
+ *
+ * To make sure that the LSFs are properly ordered and to keep a certain
+ * minimum distance between consecutive LSFs.
+ *--------------------------------------------------------------------------*/
+
+void reorder_lsf(
+ float *lsf, /* i/o: LSF vector */
+ const float min_dist, /* i : minimum required distance */
+ const int16_t n, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+)
+{
+ int16_t i;
+ float lsf_min;
+ float lsf_max;
+
+ /*-----------------------------------------------------------------*
+ * Verify the LSF ordering and minimum GAP
+ *-----------------------------------------------------------------*/
+
+ lsf_min = min_dist;
+ for ( i = 0; i < n; i++ )
+ {
+ if ( lsf[i] < lsf_min )
+ {
+ lsf[i] = lsf_min;
+ }
+ lsf_min = lsf[i] + min_dist;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Reverify the LSF ordering and minimum GAP in the reverse order (security)
+ *------------------------------------------------------------------------------------------*/
+
+ lsf_max = Fs / 2.0f - min_dist;
+
+ if ( lsf[n - 1] > lsf_max ) /* If danger of unstable filter in case of resonance in HF */
+ {
+ for ( i = n - 1; i >= 0; i-- ) /* Reverify the minimum LSF gap in the reverse sens */
+ {
+ if ( lsf[i] > lsf_max )
+ {
+ lsf[i] = lsf_max;
+ }
+
+ lsf_max = lsf[i] - min_dist;
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * space_lsfs()
+ *
+ *-------------------------------------------------------------------*/
+
+void space_lsfs(
+ float *lsfs, /* i/o: Line spectral frequencies */
+ const int16_t order /* i : order of LP analysis */
+)
+{
+ float delta;
+ int16_t i, flag = 1;
+
+ while ( flag == 1 )
+ {
+ flag = 0;
+ for ( i = 0; i <= order; i++ )
+ {
+ delta = (float) ( i == 0 ? lsfs[0] : ( i == order ? 0.5f - lsfs[i - 1] : ( lsfs[i] - lsfs[i - 1] ) ) );
+ if ( delta < SPC )
+ {
+ flag = 1;
+ delta -= SPC_plus;
+ if ( i == order )
+ {
+ lsfs[i - 1] += delta;
+ }
+ else
+ {
+ if ( i == 0 )
+ {
+ lsfs[i] -= delta;
+ }
+ else
+ {
+ delta *= 0.5f;
+ lsfs[i - 1] += delta;
+ lsfs[i] -= delta;
+ }
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * lsp_weights()
+ *
+ *-------------------------------------------------------------------*/
+
+void lsp_weights(
+ const float *lsps, /* i : Line spectral pairs */
+ float *weight, /* o : weights */
+ const int16_t order /* i : order of LP analysis */
+)
+{
+ int16_t i;
+ float delta1, delta2;
+
+ for ( i = 0; i < order; i++ )
+ {
+ delta1 = (float) ( ( i == 0 ) ? lsps[i] : lsps[i] - lsps[i - 1] );
+ delta2 = (float) ( ( i == order - 1 ) ? 0.5f - lsps[i] : lsps[i + 1] - lsps[i] );
+
+ weight[i] = 250 * root_a_over_b( ALPHA_SQ, delta1 * delta2 );
+ }
+
+ if ( order != LPC_SHB_ORDER_WB )
+ {
+ weight[3] *= 1.1f;
+ weight[4] *= 1.1f;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * isf2isp()
+ *
+ * Transformation of ISF to ISP
+ *
+ * ISP are immitance spectral pairs in cosine domain (-1 to 1).
+ * ISF are immitance spectral pairs in frequency domain (0 to fs/2).
+ *-----------------------------------------------------------------------*/
+
+void isf2isp(
+ const float isf[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */
+ float isp[], /* o : isp[m] (range: -1<=val<1) */
+ const int16_t m, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < m - 1; i++ )
+ {
+ isp[i] = (float) cos( isf[i] * EVS_PI / ( Fs / 2.f ) );
+ }
+ isp[m - 1] = (float) cos( isf[m - 1] * EVS_PI / ( Fs / 2.f ) * 2.0 );
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------------*
+ * isp2isf()
+ *
+ * Transformation of ISP to ISF
+ *
+ * ISP are immitance spectral pair in cosine domain (-1 to 1).
+ * ISF are immitance spectral pair in frequency domain (0 to fs/2).
+ *-----------------------------------------------------------------------*/
+
+void isp2isf(
+ const float isp[], /* i : isp[m] (range: -1<=val<1) */
+ float isf[], /* o : isf[m] normalized (range: 0<=val<=fs/2) */
+ const int16_t m, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+)
+{
+ int16_t i;
+
+ /* convert ISPs to frequency domain 0..6400 */
+ for ( i = 0; i < m - 1; i++ )
+ {
+ isf[i] = (float) ( acos( isp[i] ) * ( ( Fs / 2.f ) / EVS_PI ) );
+ }
+ isf[m - 1] = (float) ( acos( isp[m - 1] ) * ( ( Fs / 2.f ) / EVS_PI ) * 0.5f );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * a2rc()
+ *
+ * Convert from LPC to reflection coeff
+ *-------------------------------------------------------------------*/
+
+void a2rc(
+ const float *a, /* i : LPC coefficients */
+ float *refl, /* o : Reflection co-efficients */
+ const int16_t lpcorder /* i : LPC order */
+)
+{
+ float f[M];
+ int16_t m, j, n;
+ float km, denom, x;
+
+ for ( m = 0; m < lpcorder; m++ )
+ {
+ f[m] = -a[m];
+ }
+
+ /* Initialization */
+ for ( m = lpcorder - 1; m >= 0; m-- )
+ {
+ km = f[m];
+ if ( km <= -1.0 || km >= 1.0 )
+ {
+ for ( j = 0; j < lpcorder; j++ )
+ {
+ refl[j] = 0.f;
+ }
+
+ return;
+ }
+
+ refl[m] = -km;
+ denom = 1.0f / ( 1.0f - km * km );
+
+ for ( j = 0; j < m / 2; j++ )
+ {
+ n = m - 1 - j;
+ x = denom * f[j] + km * denom * f[n];
+ f[n] = denom * f[n] + km * denom * f[j];
+ f[j] = x;
+ }
+
+ if ( m & 1 )
+ {
+ f[j] = denom * f[j] + km * denom * f[j];
+ }
+ }
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------------------*
+ * vq_dec_lvq()
+ *
+ * Multi-stage VQ decoder for LSF parameters, last stage LVQ
+ *----------------------------------------------------------------------------------*/
+
+int16_t vq_dec_lvq(
+ int16_t sf_flag, /* i : safety net flag */
+ float x[], /* o : Decoded vector */
+ int16_t indices[], /* i : Indices */
+ const int16_t stages, /* i : Number of stages */
+ const int16_t N, /* i : Vector dimension */
+ const int16_t mode, /* i : mode_lvq, or mode_lvq_p */
+ const int16_t no_bits /* i : no. bits for lattice */
+)
+{
+ float x_lvq[16];
+ int16_t i;
+ int16_t ber_flag;
+
+ /* clear vector */
+ set_f( x, 0, N );
+
+ /*-----------------------------------------------*
+ * add contribution of each stage
+ *-----------------------------------------------*/
+
+ if ( sf_flag == 1 )
+ {
+ for ( i = 0; i < stages - 1; i++ )
+ {
+ v_add( x, &Quantizers[CB_lsf[mode] + i][indices[i] * N], x, N );
+ }
+
+ ber_flag = deindex_lvq( &indices[stages - 1], x_lvq, mode, sf_flag, no_bits );
+ }
+ else
+ {
+ for ( i = 0; i < stages - 1; i++ )
+ {
+ v_add( x, &Quantizers_p[CB_p_lsf[mode] + i][indices[i] * N], x, N );
+ }
+
+ ber_flag = deindex_lvq( &indices[stages - 1], x_lvq, mode, sf_flag, no_bits );
+ }
+
+ v_add( x, x_lvq, x, N );
+
+ return ber_flag;
+}
+
+
+/*----------------------------------------------------------------------------------*
+ * lsf_allocate()
+ *
+ * Calculate number of stages and levels for each stage based on the allowed bit allocation
+ *----------------------------------------------------------------------------------*/
+
+ivas_error lsf_allocate(
+ const int16_t nBits, /* i : Number of bits to use for quantization */
+ const int16_t framemode, /* i : LSF quantizer mode */
+ const int16_t framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */
+ int16_t *stages0, /* o : Number of stages for safety-net quantizer */
+ int16_t *stages1, /* o : Number of stages for predictive quantizer */
+ int16_t levels0[], /* o : Number of vectors for each stage for SFNET */
+ int16_t levels1[], /* o : Number of vectors for each stage for pred */
+ int16_t bits0[], /* o : Number of bits for each stage safety net */
+ int16_t bits1[] /* o : Number of bits for each stage pred */
+)
+{
+ int16_t i;
+ int16_t cumleft;
+ int16_t bits_lvq, n_stages, nbits0;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ /*---------------------------------------------------*
+ * Calculate bit allocation for safety-net quantizer
+ *---------------------------------------------------*/
+
+ cumleft = BitsVQ[framemode];
+ bits_lvq = nBits - cumleft;
+ nbits0 = CBbits[framemode];
+ if ( nbits0 > -1 )
+ {
+ if ( nbits0 > 0 ) /* */
+ {
+ n_stages = 2;
+ levels0[0] = CBsizes[nbits0];
+ bits0[0] = nbits0;
+ bits0[1] = cumleft - nbits0;
+
+ if ( bits0[1] == 0 )
+ {
+ n_stages--;
+ }
+ else
+ {
+ levels0[1] = CBsizes[cumleft - nbits0];
+ }
+ }
+ else /* no bits for VQ stage */
+ {
+ n_stages = 0;
+ }
+
+ *stages0 = n_stages;
+ if ( bits_lvq > 0 )
+ {
+ bits0[n_stages] = bits_lvq;
+ levels0[n_stages] = bits_lvq; /* this is number of bits, not levels */
+ *stages0 = n_stages + 1;
+ }
+ }
+ else
+ {
+ *stages0 = 0;
+ }
+
+ /*---------------------------------------------------*
+ * Calculate bit allocation for predictive quantizer
+ *---------------------------------------------------*/
+
+ if ( framemode_p > -1 )
+ {
+ cumleft = BitsVQ_p[framemode_p];
+ bits_lvq = nBits - cumleft;
+ nbits0 = CBbits_p[framemode_p];
+
+ if ( nbits0 > -1 )
+ {
+ if ( nbits0 > 0 )
+ {
+ if ( framemode_p == 7 )
+ {
+ /* for UNVOICED_WB only */
+ n_stages = 3;
+ for ( i = 0; i < n_stages; i++ )
+ {
+ levels1[i] = CBsizes[nbits0];
+ bits1[i] = nbits0;
+ }
+ bits1[n_stages] = bits_lvq;
+ levels1[n_stages] = bits_lvq;
+ *stages1 = n_stages + 1;
+ }
+ else
+ {
+ n_stages = 1;
+ levels1[0] = CBsizes[nbits0];
+ bits1[0] = nbits0;
+ nbits0 = cumleft - nbits0;
+ if ( nbits0 > 0 )
+ {
+ levels1[1] = CBsizes[nbits0];
+ bits1[1] = nbits0;
+ n_stages = 2;
+ }
+
+ levels1[n_stages] = bits_lvq; /* this is number of bits, not levels */
+ bits1[n_stages] = bits_lvq;
+ *stages1 = n_stages + 1;
+ }
+ }
+ else
+ {
+ *stages1 = 1;
+ bits1[0] = bits_lvq;
+ levels1[0] = bits_lvq;
+ }
+ }
+ }
+
+ return error;
+}
+
+/*----------------------------------------------------------------------------------*
+ * find_pred_mode()
+ *
+ *
+ *----------------------------------------------------------------------------------*/
+
+ivas_error find_pred_mode(
+ int16_t *predmode,
+ const int16_t coder_type,
+ const int16_t bwidth,
+ const int32_t int_fs,
+ int16_t *p_mode_lvq,
+ int16_t *p_mode_lvq_p,
+ const int32_t core_brate )
+{
+ int16_t idx;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ idx = bwidth;
+ if ( idx > 1 )
+ {
+ idx = 1;
+ }
+
+ if ( int_fs == INT_FS_16k )
+ {
+ idx = 2;
+ }
+ else
+ {
+ if ( core_brate >= GENERIC_MA_LIMIT && coder_type == GENERIC && idx == 1 )
+ {
+ idx = 3;
+ }
+ }
+
+ *predmode = predmode_tab[idx][coder_type];
+
+ if ( idx <= 2 )
+ {
+ *p_mode_lvq = NO_CODING_MODES * idx + coder_type;
+ if ( *predmode > 0 )
+ {
+ *p_mode_lvq_p = *p_mode_lvq;
+ }
+ else
+ {
+ *p_mode_lvq_p = -1;
+ }
+ }
+ else /* WB 12.8 with MA pred in GENERIC*/
+ {
+ *p_mode_lvq = NO_CODING_MODES + coder_type;
+ if ( coder_type == GENERIC )
+ {
+ *p_mode_lvq_p = 18;
+ }
+ else
+ {
+ if ( *predmode > 0 )
+ {
+ *p_mode_lvq_p = *p_mode_lvq;
+ }
+ else
+ {
+ *p_mode_lvq_p = -1;
+ }
+ }
+ }
+
+
+ return error;
+}
+
+
+/*---------------------------------------------------------------------------
+ * reorder_isf()
+ *
+ * To make sure that the ISFs are properly ordered and to keep a certain
+ * minimum distance between consecutive ISFs.
+ *--------------------------------------------------------------------------*/
+
+void reorder_isf(
+ float *isf, /* i/o: ISF vector */
+ const float min_dist, /* i : minimum required distance */
+ const int16_t n, /* i : LPC order */
+ const float Fs /* i : sampling frequency */
+)
+{
+ int16_t i;
+ float isf_min;
+ float isf_max;
+
+ /*-----------------------------------------------------------------*
+ * Verify the ISF ordering and minimum GAP
+ *-----------------------------------------------------------------*/
+
+ isf_min = min_dist;
+ for ( i = 0; i < n - 1; i++ )
+ {
+ if ( isf[i] < isf_min )
+ {
+ isf[i] = isf_min;
+ }
+
+ isf_min = isf[i] + min_dist;
+ }
+
+ /*------------------------------------------------------------------------------------------*
+ * Reverify the ISF ordering and minimum GAP in the reverse order (security)
+ *------------------------------------------------------------------------------------------*/
+
+ isf_max = Fs / 2.0f - min_dist;
+
+ if ( isf[n - 2] > isf_max ) /* If danger of unstable filter in case of resonance in HF */
+ {
+ for ( i = n - 2; i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse sens */
+ {
+ if ( isf[i] > isf_max )
+ {
+ isf[i] = isf_max;
+ }
+
+ isf_max = isf[i] - min_dist;
+ }
+ }
+
+ return;
+}
+
+/*----------------------------------------------------------------------------------*
+ * lsf_stab()
+ *
+ * Check LSF stability (distance between old LSFs and current LSFs)
+ *----------------------------------------------------------------------------------*/
+
+/*! r: LP filter stability */
+float lsf_stab(
+ const float *lsf, /* i : LSF vector */
+ const float *lsfold, /* i : old LSF vector */
+ const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode*/
+ const int16_t L_frame /* i : frame length */
+)
+{
+ int16_t i, m;
+ float scale, stab_fac, tmp;
+
+ tmp = 0.0f;
+ if ( Opt_AMR_WB )
+ {
+ m = M - 1;
+ }
+ else
+ {
+ m = M;
+ }
+
+ for ( i = 0; i < m; i++ )
+ {
+ tmp += ( lsf[i] - lsfold[i] ) * ( lsf[i] - lsfold[i] );
+ }
+
+ scale = (float) L_FRAME / (float) L_frame;
+ scale *= scale;
+
+ stab_fac = (float) ( 1.25f - ( scale * tmp / 400000.0f ) );
+
+ if ( stab_fac > 1.0f )
+ {
+ stab_fac = 1.0f;
+ }
+
+ if ( stab_fac < 0.0f )
+ {
+ stab_fac = 0.0f;
+ }
+ return stab_fac;
+}
+
+
+/*---------------------------------------------------------------------
+ * get_isppol()
+ *
+ * Find the polynomial F1(z) or F2(z) from the ISPs.
+ * This is performed by expanding the product polynomials:
+ *
+ * F1(z) = PRODUCT ( 1 - 2 isp_i z^-1 + z^-2 )
+ * i=0,2,...,14
+ * F2(z) = PRODUCT ( 1 - 2 isp_i z^-1 + z^-2 )
+ * i=1,3,...,13
+ *
+ * where isp_i are the ISPs in the cosine domain.
+ *---------------------------------------------------------------------*/
+
+static void get_isppol(
+ const float *isp, /* i : Immitance spectral pairs (cosine domaine) */
+ float f[], /* o : the coefficients of F1 or F2 */
+ const int16_t n /* i : nb. of coefficients (m/2) */
+)
+{
+ float b;
+ int16_t i, j;
+
+ f[0] = 1.0f;
+ b = (float) ( -2.0f * *isp );
+ f[1] = b;
+ for ( i = 2; i <= n; i++ )
+ {
+ isp += 2;
+ b = (float) ( -2.0f * *isp );
+ f[i] = (float) ( b * f[i - 1] + 2.0f * f[i - 2] );
+
+ for ( j = i - 1; j > 1; j-- )
+ {
+ f[j] += b * f[j - 1] + f[j - 2];
+ }
+ f[1] += b;
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------
+ * chebps2()
+ *
+ * Evaluates the Chebyshev polynomial series
+ *
+ * The polynomial order is
+ * n = m/2 (m is the prediction order)
+ * The polynomial is given by
+ * C(x) = f(0)T_n(x) + f(1)T_n-1(x) + ... +f(n-1)T_1(x) + f(n)/2
+ *---------------------------------------------------------------------*/
+
+/*! r: the value of the polynomial C(x) */
+static float chebps2(
+ const float x, /* i : value of evaluation; x=cos(freq) */
+ const float *f, /* i : coefficients of sum or diff polyn. */
+ const int16_t n /* i : order of polynomial */
+)
+{
+ float b1, b2, b0, x2;
+ int16_t i;
+
+ x2 = (float) ( 2.0f * x );
+ b2 = f[0];
+
+ b1 = x2 * b2 + f[1];
+
+ for ( i = 2; i < n; i++ )
+ {
+ b0 = x2 * b1 - b2 + f[i];
+ b2 = b1;
+ b1 = b0;
+ }
+
+ return (float) ( x * b1 - b2 + 0.5f * f[n] );
+}
+
+
+/*---------------------------------------------------------------------
+ * LPC_chebyshev()
+ *
+ * Evaluate a series expansion in Chebyshev polynomials
+ *
+ * The polynomial order is
+ * n = m/2 (m is the prediction order)
+ * The polynomial is given by
+ * C(x) = T_n(x) + f(1)T_n-1(x) + ... +f(n-1)T_1(x) + f(n)/2
+ *---------------------------------------------------------------------*/
+
+static float LPC_chebyshev(
+ float x,
+ float f[],
+ const int16_t n )
+{
+ float b1, b2, b0, x2, val;
+ int16_t i;
+
+ x2 = 2.0f * x;
+ b2 = 1.0f;
+ b1 = x2 + f[0];
+
+ for ( i = 2; i < n; i++ )
+ {
+ b0 = x2 * b1 - b2 + f[i - 1];
+
+ /* was previously casting x2 into float to have this
+ equation evaluated in float to be same
+ same as EVRC-B only code which has 2.0 in equation
+ instead of a float x2. This was causing non-bit-exactness
+ in a very very very rare corner case.
+ Doesnt really matter, but just to be picky! */
+ b2 = b1;
+ b1 = b0;
+ }
+
+ val = ( x * b1 - b2 + f[i - 1] );
+
+ return val;
+}
+
+
+/*-------------------------------------------------------------------*
+ * lsp2isp()
+ *
+ * Convert LSPs to ISPs via predictor coefficients A[]
+ *-------------------------------------------------------------------*/
+
+void lsp2isp(
+ const float *lsp, /* i : LSP vector */
+ float *isp, /* o : ISP filter coefficients */
+ float *stable_isp, /* i/o: ISP filter coefficients */
+ const int16_t m /* i : order of LP analysis */
+)
+{
+ float a[M + 1];
+
+ /* LSP --> A */
+ lsp2a_stab( lsp, a, m );
+
+ /* A --> ISP */
+ a2isp( a, isp, stable_isp );
+
+ /* Update to latest stable ISP */
+ mvr2r( isp, stable_isp, M );
+}
+
+/*-------------------------------------------------------------------*
+ * isp2lsp()
+ *
+ * Convert ISPs to LSPs via predictor coefficients A[]
+ *-------------------------------------------------------------------*/
+
+void isp2lsp(
+ const float *isp, /* i : LSP vector */
+ float *lsp, /* o : ISP filter coefficients */
+ float *stable_lsp, /* i/o: stable LSP filter coefficients */
+ const int16_t m /* i : order of LP analysis */
+)
+{
+ float a[M + 1];
+
+ /* ISP --> A */
+ isp2a( isp, a, m );
+
+ /* A --> LSP */
+ a2lsp_stab( a, lsp, stable_lsp );
+
+ /* Update to latest stable LSP */
+ mvr2r( lsp, stable_lsp, M );
+}
+
+
+/*-------------------------------------------------------------------*
+ * lsf2isf()
+ *
+ * Convert LSPs to ISPs
+ *-------------------------------------------------------------------*/
+
+void lsf2isf(
+ const float *lsf, /* i : LSF vector */
+ float *isf, /* o : ISF vector */
+ float *stable_isp, /* i/o: stable ISP filter coefficients */
+ const int16_t m, /* i : order of LP analysis */
+ const int32_t Fs )
+{
+ float tmp_lsp[M];
+ float tmp_isp[M];
+
+ /* LSF --> LSP */
+ lsf2lsp( lsf, tmp_lsp, m, Fs );
+
+ /* LSP --> ISP */
+ lsp2isp( tmp_lsp, tmp_isp, stable_isp, m );
+
+ /* ISP --> ISF */
+ isp2isf( tmp_isp, isf, m, Fs );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * isf2lsf()
+ *
+ * Convert ISFs to LSFs
+ *-------------------------------------------------------------------*/
+
+void isf2lsf(
+ const float *isf, /* i : ISF vector */
+ float *lsf, /* o : LSF vector */
+ float *stable_lsp, /* i/o: stable LSP filter coefficients */
+ const int16_t m, /* i : order of LP analysis */
+ const int32_t Fs )
+{
+ float tmp_isp[M];
+ float tmp_lsp[M];
+
+ /* ISF --> ISP */
+ isf2isp( isf, tmp_isp, m, Fs );
+
+ /* ISP --> LSP */
+ isp2lsp( tmp_isp, tmp_lsp, stable_lsp, m );
+
+ /* LSP --> LSF */
+ lsp2lsf( tmp_lsp, lsf, m, Fs );
+
+ return;
+}
+
+/*-----------------------------------------------------------------------*
+ * lsp2lsf()
+ *
+ * Transformation of LSPs to LSFs
+ *
+ * LSP are line spectral pair in cosine domain (-1 to 1).
+ * LSF are line spectral frequencies (0 to fs/2).
+ *-----------------------------------------------------------------------*/
+
+void lsp2lsf(
+ const float lsp[], /* i : isp[m] (range: -1<=val<1) */
+ float lsf[], /* o : isf[m] normalized (range: 0<=val<=fs/2) */
+ const int16_t m, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+)
+{
+ int16_t i;
+
+ /* convert LSPs to LSFs */
+ for ( i = 0; i < m; i++ )
+ {
+ lsf[i] = (float) ( acos( lsp[i] ) * ( ( Fs / 2.f ) / EVS_PI ) );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------------*
+ * lsf2lsp()
+ *
+ * Transformation of LSFs to LSPs
+ *
+ * LSP are line spectral pairs in cosine domain (-1 to 1).
+ * LSF are line spectral frequencies (0 to fs/2).
+ *-----------------------------------------------------------------------*/
+
+void lsf2lsp(
+ const float lsf[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */
+ float lsp[], /* o : isp[m] (range: -1<=val<1) */
+ const int16_t m, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+)
+{
+ int16_t i;
+
+ /* convert LSFs to LSPs */
+ for ( i = 0; i < m; i++ )
+ {
+ lsp[i] = (float) cos( lsf[i] * EVS_PI / ( Fs / 2.f ) );
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------------
+ * tcvq_Dec()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+static void tcvq_Dec(
+ int16_t *ind,
+ float *d_out,
+ const int16_t safety_net )
+{
+ int16_t i;
+ int16_t index[9];
+ int16_t stage, state, branch[N_STAGE], codeword[N_STAGE];
+ int16_t fins, iwd;
+ float pred[N_DIM];
+ float D[N_STAGE_VQ][N_DIM];
+ const float( *TCVQ_CB_SUB1 )[128][2], ( *TCVQ_CB_SUB2 )[64][2], ( *TCVQ_CB_SUB3 )[32][2];
+ const float( *IntraCoeff )[2][2];
+
+ mvs2s( ind, index, 9 );
+
+ if ( safety_net )
+ {
+ TCVQ_CB_SUB1 = SN_TCVQ_CB_SUB1;
+ TCVQ_CB_SUB2 = SN_TCVQ_CB_SUB2;
+ TCVQ_CB_SUB3 = SN_TCVQ_CB_SUB3;
+ IntraCoeff = SN_IntraCoeff;
+ }
+ else
+ {
+ TCVQ_CB_SUB1 = AR_TCVQ_CB_SUB1;
+ TCVQ_CB_SUB2 = AR_TCVQ_CB_SUB2;
+ TCVQ_CB_SUB3 = AR_TCVQ_CB_SUB3;
+ IntraCoeff = AR_IntraCoeff;
+ }
+
+ /* Decode Final state */
+ fins = index[0] & 15;
+
+ /* Decode Branch info */
+ branch[0] = index[1] >> 4;
+ branch[1] = index[2] >> 4;
+
+ for ( stage = 2; stage < N_STAGE_VQ - 4; stage++ )
+ {
+ branch[stage] = index[stage + 1] >> 3;
+ }
+
+ branch[4] = fins & 0x1;
+ branch[5] = ( fins >> 1 ) & 0x1;
+ branch[6] = ( fins >> 2 ) & 0x1;
+ branch[7] = ( fins >> 3 ) & 0x1;
+
+ /* Decode Codeword info */
+ for ( stage = 0; stage < 2; stage++ )
+ {
+ codeword[stage] = ( index[stage + 1] & 15 ) << 3;
+ }
+
+ for ( stage = 2; stage < N_STAGE_VQ - 4; stage++ )
+ {
+ codeword[stage] = ( index[stage + 1] & 7 ) << 3;
+ }
+
+ for ( stage = N_STAGE_VQ - 4; stage < N_STAGE_VQ; stage++ )
+ {
+ codeword[stage] = ( index[stage + 1] & 3 ) << 3;
+ }
+
+ state = ( fins >> 2 ) << 2;
+
+ /* stage #1 */
+ iwd = NTRANS2[branch[0] + 2][state] + codeword[0];
+ D[0][0] = TCVQ_CB_SUB1[0][iwd][0];
+ D[0][1] = TCVQ_CB_SUB1[0][iwd][1];
+ state = NTRANS2[branch[0]][state];
+
+ /* stage #2 */
+ pred[0] = IntraCoeff[0][0][0] * D[0][0] + IntraCoeff[0][0][1] * D[0][1];
+ pred[1] = IntraCoeff[0][1][0] * D[0][0] + IntraCoeff[0][1][1] * D[0][1];
+
+ iwd = NTRANS2[branch[1] + 2][state] + codeword[1];
+ D[1][0] = TCVQ_CB_SUB1[1][iwd][0] + pred[0];
+ D[1][1] = TCVQ_CB_SUB1[1][iwd][1] + pred[1];
+ state = NTRANS2[branch[1]][state];
+
+ /* stage #3 - #4 */
+ for ( stage = 2; stage < N_STAGE_VQ - 4; stage++ )
+ {
+ pred[0] = IntraCoeff[stage - 1][0][0] * D[stage - 1][0] + IntraCoeff[stage - 1][0][1] * D[stage - 1][1];
+ pred[1] = IntraCoeff[stage - 1][1][0] * D[stage - 1][0] + IntraCoeff[stage - 1][1][1] * D[stage - 1][1];
+
+ iwd = NTRANS2[branch[stage] + 2][state] + codeword[stage];
+ D[stage][0] = TCVQ_CB_SUB2[stage - 2][iwd][0] + pred[0];
+ D[stage][1] = TCVQ_CB_SUB2[stage - 2][iwd][1] + pred[1];
+ state = NTRANS2[branch[stage]][state];
+ }
+
+ /* stage #5 - #8 */
+ for ( stage = N_STAGE_VQ - 4; stage < N_STAGE_VQ; stage++ )
+ {
+ pred[0] = IntraCoeff[stage - 1][0][0] * D[stage - 1][0] + IntraCoeff[stage - 1][0][1] * D[stage - 1][1];
+ pred[1] = IntraCoeff[stage - 1][1][0] * D[stage - 1][0] + IntraCoeff[stage - 1][1][1] * D[stage - 1][1];
+
+ iwd = NTRANS2[branch[stage] + 2][state] + codeword[stage];
+ D[stage][0] = TCVQ_CB_SUB3[stage - 4][iwd][0] + pred[0];
+ D[stage][1] = TCVQ_CB_SUB3[stage - 4][iwd][1] + pred[1];
+ state = NTRANS2[branch[stage]][state];
+ }
+
+ for ( stage = 0; stage < N_STAGE_VQ; stage++ )
+ {
+ for ( i = 0; i < N_DIM; i++ )
+ {
+ d_out[( N_DIM * stage ) + i] = D[stage][i];
+ }
+ }
+ return;
+}
+
+/*---------------------------------------------------------------------------
+ * qlsf_ARSN_tcvq_Dec_16k()
+ *
+ * Predictive BC-TCQ encoder for LSF quantization
+ *--------------------------------------------------------------------------*/
+
+int16_t qlsf_ARSN_tcvq_Dec_16k(
+ float *y, /* o : Quantized LSF vector */
+ int16_t *indice, /* i : Indices */
+ const int16_t nBits /* i : number of bits */
+)
+{
+ int16_t i;
+ float error_svq_q[M];
+ int16_t safety_net;
+
+ /* Select Mode */
+ safety_net = indice[0];
+
+ if ( safety_net == 1 )
+ {
+ tcvq_Dec( &indice[1], y, safety_net );
+
+ if ( nBits > 30 )
+ {
+ for ( i = 0; i < 8; i++ )
+ {
+ error_svq_q[i] = AR_SVQ_CB1[indice[10]][i];
+ error_svq_q[i + 8] = AR_SVQ_CB2[indice[11]][i];
+ }
+
+ for ( i = 0; i < M; i++ )
+ {
+ y[i] = y[i] + error_svq_q[i] * scale_ARSN[i];
+ }
+ }
+ }
+ else
+ {
+ tcvq_Dec( &indice[1], y, safety_net );
+
+ if ( nBits > 30 )
+ {
+ for ( i = 0; i < 8; i++ )
+ {
+ error_svq_q[i] = AR_SVQ_CB1[indice[10]][i];
+ error_svq_q[i + 8] = AR_SVQ_CB2[indice[11]][i];
+ }
+
+ for ( i = 0; i < M; i++ )
+ {
+ y[i] = y[i] + error_svq_q[i];
+ }
+ }
+ }
+
+ return safety_net;
+}
+
+
+/*-------------------------------------------------------------------*
+ * lsf_syn_mem_backup()
+ *
+ * back-up synthesis filter memory and LSF qunatizer memories (used in SC-VBR)
+ *-------------------------------------------------------------------*/
+
+void lsf_syn_mem_backup(
+ Encoder_State *st, /* i : state structure */
+ float *btilt_code, /* i : tilt code */
+ float *bgc_threshold, /* i : */
+ float *clip_var_bck, /* o : */
+ int16_t *next_force_sf_bck, /* o : */
+ float *lsp_new, /* i : LSP vector to quantize */
+ float *lsp_mid, /* i : mid-frame LSP vector */
+ float *clip_var, /* o : pitch clipping state var */
+ float *mem_AR, /* o : quantizer memory for AR model */
+ float *mem_MA, /* o : quantizer memory for AR model */
+ float *lsp_new_bck, /* o : LSP vector to quantize- backup */
+ float *lsp_mid_bck, /* o : mid-frame LSP vector - backup */
+ float *Bin_E, /* o : FFT Bin energy 128 *2 sets */
+ float *Bin_E_old, /* o : FFT Bin energy 128 sets */
+ float *mem_syn_bck, /* o : synthesis filter memory */
+ float *mem_w0_bck, /* o : memory of the weighting filter */
+ float *streaklimit,
+ int16_t *pstreaklen )
+{
+ int16_t i;
+ LPD_state_HANDLE hLPDmem = st->hLPDmem;
+
+ *clip_var = st->clip_var[0];
+
+ for ( i = 0; i < M; i++ )
+ {
+ mem_AR[i] = st->mem_AR[i];
+ mem_MA[i] = st->mem_MA[i];
+ lsp_new_bck[i] = lsp_new[i];
+ lsp_mid_bck[i] = lsp_mid[i];
+ }
+
+ *streaklimit = st->streaklimit;
+ *pstreaklen = st->pstreaklen;
+
+ for ( i = 0; i < L_FFT; i++ )
+ {
+ Bin_E[i] = st->Bin_E[i];
+ }
+
+ for ( i = 0; i < ( L_FFT / 2 ); i++ )
+ {
+ Bin_E_old[i] = st->Bin_E_old[i];
+ }
+
+ /* back-up memories */
+ for ( i = 0; i < M; i++ )
+ {
+ mem_syn_bck[i] = hLPDmem->mem_syn[i];
+ }
+
+ *mem_w0_bck = hLPDmem->mem_w0;
+
+ *btilt_code = hLPDmem->tilt_code;
+ *bgc_threshold = hLPDmem->gc_threshold;
+ mvr2r( st->clip_var, clip_var_bck, 6 );
+ *next_force_sf_bck = st->next_force_safety_net;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * lsf_syn_mem_restore()
+ *
+ * restore synthesis filter memory and LSF quantizer memories
+ *-------------------------------------------------------------------*/
+
+void lsf_syn_mem_restore(
+ Encoder_State *st, /* o : state structure */
+ float btilt_code, /* i : */
+ float gc_threshold, /* i : */
+ float *clip_var_bck, /* i : */
+ int16_t next_force_sf_bck, /* i : */
+ float *lsp_new, /* o : LSP vector to quantize */
+ float *lsp_mid, /* o : mid-frame LSP vector */
+ float clip_var, /* i : pitch clipping state var */
+ float *mem_AR, /* i : quantizer memory for AR model */
+ float *mem_MA, /* i : quantizer memory for AR model */
+ float *lsp_new_bck, /* i : LSP vector to quantize- backup */
+ float *lsp_mid_bck, /* i : mid-frame LSP vector - backup */
+ float *Bin_E, /* i : FFT Bin energy 128 *2 sets */
+ float *Bin_E_old, /* i : FFT Bin energy 128 sets */
+ float *mem_syn_bck, /* i : synthesis filter memory */
+ float mem_w0_bck, /* i : memory of the weighting filter */
+ const float streaklimit,
+ const int16_t pstreaklen )
+{
+ int16_t i;
+ LPD_state_HANDLE hLPDmem = st->hLPDmem;
+
+ /* restore lsf memories */
+ st->clip_var[0] = clip_var;
+
+ for ( i = 0; i < M; i++ )
+ {
+ st->mem_AR[i] = mem_AR[i];
+ st->mem_MA[i] = mem_MA[i];
+ lsp_new[i] = lsp_new_bck[i];
+ lsp_mid[i] = lsp_mid_bck[i];
+ }
+
+ st->streaklimit = streaklimit;
+ st->pstreaklen = pstreaklen;
+
+ for ( i = 0; i < L_FFT; i++ )
+ {
+ st->Bin_E[i] = Bin_E[i];
+ }
+
+ for ( i = 0; i < ( L_FFT / 2 ); i++ )
+ {
+ st->Bin_E_old[i] = Bin_E_old[i];
+ }
+
+ /* restoring memories */
+ hLPDmem->mem_w0 = mem_w0_bck;
+
+ for ( i = 0; i < M; i++ )
+ {
+ hLPDmem->mem_syn[i] = mem_syn_bck[i];
+ }
+
+ hLPDmem->tilt_code = btilt_code;
+ hLPDmem->gc_threshold = gc_threshold;
+ mvr2r( clip_var_bck, st->clip_var, 6 );
+ st->next_force_safety_net = next_force_sf_bck;
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * lsf_update_memory()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void lsf_update_memory(
+ const int16_t narrowband, /* i : narrowband flag */
+ const float qlsf[], /* i : quantized lsf coefficients */
+ float old_mem_MA[], /* i : MA memory */
+ float mem_MA[] /* o : updated MA memory */
+)
+{
+ int16_t i;
+
+ for ( i = 0; i < M; ++i )
+ {
+ mem_MA[i] = qlsf[i] - lsf_means[narrowband][i] - MU_MA * old_mem_MA[i];
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * tcxlpc_get_cdk()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+/*! r: codebook index */
+int16_t tcxlpc_get_cdk(
+ const int16_t coder_type /* i : GC/VC indicator */
+)
+{
+ int16_t cdk;
+
+ cdk = ( coder_type == VOICED );
+
+ return cdk;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * dec_FDCNG_MSVQ_stage1()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void dec_FDCNG_MSVQ_stage1(
+ int16_t j_full, /* i : index full range */
+ int16_t n, /* i : dimension to generate */
+ const float *invTrfMatrix, /* i : IDCT matrix for synthesis */
+ const DCTTYPE idcttype, /* i : specify which IDCT */
+ float *uq, /* o : synthesized stage1 vector */
+ Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */
+)
+{
+ int16_t col, segm_ind, j;
+ float dct_vec[FDCNG_VQ_MAX_LEN];
+ float idct_vec[FDCNG_VQ_MAX_LEN];
+ const Word8 *cbpW8;
+ const Word16 *dct_col_shift_tab;
+
+ assert( n <= FDCNG_VQ_MAX_LEN );
+ assert( n >= FDCNG_VQ_DCT_MINTRUNC );
+
+ segm_ind = 0;
+ for ( col = 1; col <= FDCNG_VQ_DCT_NSEGM; col++ )
+ {
+ if ( j_full >= cdk1_ivas_cum_entries_per_segment[col] )
+ {
+ segm_ind++;
+ }
+ }
+
+ j = j_full - cdk1_ivas_cum_entries_per_segment[segm_ind]; /* j is the local segment index */
+
+ assert( j < cdk1_ivas_entries_per_segment[segm_ind] );
+
+ /* Word8 column variable Qx storage*/
+ cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */
+ cbpW8 += j * cdk1_ivas_cols_per_segment[segm_ind]; /* adaptive ptr init */
+ dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind];
+
+ for ( col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++ )
+ {
+ dct_vec[col] = (float) shl( (Word16) cbpW8[col], dct_col_shift_tab[col] );
+ /* LOGIC( 1 ) , SHIFT( 1 );
+ in BASOP: s_and(for W8->W16), shl()
+ */
+ }
+ dctT2_N_apply_matrix( (const float *) dct_vec, idct_vec, cdk1_ivas_cols_per_segment[segm_ind], n, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, idcttype );
+
+ /*scale down to original fdcngvq domain and move to Q0 */
+ v_multc( idct_vec, fdcng_dct_scaleF[1], idct_vec, n );
+ /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 ,
+ not really relevant for BASOP loop */
+
+ /*add common mid fdcng vector, in fdcng bands domain */
+ v_add( idct_vec, cdk1r_tr_midQ_truncQ, uq, n );
+ assert( uq_ind == NULL );
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * msvq_dec()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void msvq_dec(
+ const float *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */
+ const int16_t dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */
+ const int16_t offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */
+ const int16_t stages, /* i : Number of stages */
+ const int16_t N, /* i : Vector dimension */
+ const int16_t maxN, /* i : Codebook dimension */
+ const int16_t Idx[], /* i : Indices */
+ const int16_t applyIDCT_flag, /* i : applyIDCT flag */
+ const float *invTrfMatrix, /* i : matrix for IDCT synthesis */
+ float *uq, /* o : quantized vector */
+ Word16 *uq_ind /* o : quantized vector (fixed point) */
+)
+{
+ int16_t i, n, maxn, start;
+ Word16 j;
+ set_zero( uq, N );
+
+ if ( uq_ind )
+ {
+ for ( i = 0; i < N; ++i )
+ {
+ uq_ind[i] = 0;
+ move16();
+ }
+ }
+ for ( i = 0; i < stages; i++ )
+ {
+ if ( dims )
+ {
+ n = dims[i];
+ maxn = n;
+ }
+ else
+ {
+ n = N;
+ maxn = maxN;
+ }
+ if ( offs )
+ {
+ start = offs[i];
+ }
+ else
+ {
+ start = 0;
+ }
+
+ if ( i == 0 && applyIDCT_flag != 0 )
+ {
+ assert( start == 0 );
+ dec_FDCNG_MSVQ_stage1( Idx[0], N, invTrfMatrix, IDCT_T2_XX_24, uq, uq_ind ); /* IDCT_T2 N=24 used for all synthesis */
+ }
+ else
+ {
+ v_add( uq + start, cb[i] + Idx[i] * maxn, uq + start, n );
+ }
+
+#define WMC_TOOL_SKIP
+ IF( uq_ind != NULL )
+ {
+ FOR( j = 0; j < n; ++j )
+ {
+ move16();
+ uq_ind[start + j] = add( uq_ind[start + j], (Word16) ( cb[i][Idx[i] * maxn + j] * 2.0f * 1.28f ) );
+ }
+ }
+#undef WMC_TOOL_SKIP
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * spec2isf()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+static void spec2isf(
+ float spec_r[], /* input spectrum real part (only left half + one zero)*/
+ float spec_i[], /* input spectrum imag part (only left half+right halt with zeros)*/
+ const int16_t speclen, /* length of spectrum (only left half)*/
+ float lsf[],
+ /* locations of LSFs (buffer must be sufficiently long) */ /*15Q16*/
+ const float old_lsf[] /* locations of LSFs (buffer must be sufficiently long) */ /*15Q16*/
+)
+{
+ /*spec_r[] needs a 0 in the end!*/
+ float s;
+ int16_t specix, lsfix, i;
+
+ specix = lsfix = 0;
+ s = spec_r[specix++];
+
+ while ( ( specix < speclen ) && lsfix <= 15 )
+ {
+
+ /*check for next zero crossing*/
+ for ( ; s * spec_r[specix] >= 0; specix++ )
+ {
+ ;
+ }
+
+ lsf[lsfix++] = ( specix - 1 + spec_r[specix - 1] / ( spec_r[specix - 1] - spec_r[specix] ) ) * ( 12800 / 256 );
+
+ /*check for the next zero crossing*/
+ for ( ; s * spec_i[specix] >= 0; specix++ )
+ {
+ ;
+ }
+
+ lsf[lsfix++] = ( specix - 1 + spec_i[specix - 1] / ( spec_i[specix - 1] - spec_i[specix] ) ) * ( 12800 / 256 );
+
+ spec_r[speclen] = s;
+ spec_i[speclen] = s;
+
+ s = -s;
+ }
+
+ if ( lsfix < 16 )
+ {
+ for ( i = 0; i < 16; i++ )
+ {
+ lsf[i] = old_lsf[i];
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * a2isf()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+#define SCALE1_HALF 1018.59161376953f
+
+typedef struct
+{
+ float re;
+ float im;
+} Pfloat;
+
+void a2isf(
+ float *a,
+ float *isf,
+ const float *old_isf,
+ const int16_t lpcOrder )
+{
+ float RealFFT[128];
+ float ImagFFT[128];
+ float RealOut[130];
+ float ImagOut[130];
+ float *ptrReal;
+ float *ptrImag;
+ int16_t n, i, j;
+ const Pfloat *ptwiddle;
+ Pfloat *pwn17, pwn[128], *pwn15, tmpw15;
+ int16_t N = 256;
+ float s[4];
+ float L_tmp, L_tmp1;
+ float lpc[19], fftTmpRe[16], fftTmpIm[16];
+ Pfloat twid[128];
+ float c;
+
+ set_zero( fftTmpRe, 16 );
+ set_zero( fftTmpIm, 16 );
+
+ /* half length FFT */
+ /*c = [sum(a) ((-1).^(1:length(a)))*a];*/
+
+ L_tmp = 0;
+ for ( j = 0; j <= lpcOrder; j++ )
+ {
+ L_tmp += a[j];
+ }
+
+ L_tmp1 = 0;
+ for ( j = 0; j < lpcOrder / 2; j++ )
+ {
+ L_tmp1 -= a[2 * j];
+ L_tmp1 += a[2 * j + 1];
+ }
+ L_tmp1 -= a[2 * j];
+
+ /*s = [1 -2*(c(1)-c(2))/(c(1)+c(2)) 1]';*/
+ s[0] = 1;
+ if ( ( L_tmp + L_tmp1 ) != 0 )
+ {
+ s[1] = -2 * ( ( L_tmp - L_tmp1 ) / ( L_tmp + L_tmp1 ) );
+ }
+ else
+ {
+ s[1] = 1;
+ }
+ s[2] = 1;
+
+ lpc[0] = a[0] * s[0];
+ L_tmp = a[1] * s[0];
+ lpc[1] = L_tmp + ( a[1 - 1] * s[1] );
+
+
+ for ( n = 2; n < 17; n++ )
+ {
+ L_tmp = a[n] * s[0];
+ L_tmp += ( a[n - 1] * s[1] );
+ lpc[n] = L_tmp + ( a[n - 2] * s[2] );
+ }
+ lpc[18] = a[16] * s[0];
+ L_tmp = a[15] * s[0];
+ lpc[17] = L_tmp + ( a[16] * s[1] );
+
+
+ ptrReal = RealFFT;
+ ptrImag = ImagFFT;
+
+ for ( j = 0; j < 9; j++ )
+ {
+ fftTmpRe[j] = lpc[2 * j];
+ fftTmpIm[j] = lpc[2 * j + 1];
+ }
+ fftTmpRe[j] = lpc[2 * j];
+ fftTmpIm[j] = 0;
+ j++;
+
+ for ( ; j < 16; j++ )
+ {
+ fftTmpRe[j] = 0;
+ fftTmpIm[j] = 0;
+ }
+
+ DoRTFTn( fftTmpRe, fftTmpIm, 16 );
+
+ for ( j = 0; j < 16; j++ )
+ {
+ ptrReal[j * 8] = fftTmpRe[j];
+ ptrImag[j * 8] = fftTmpIm[j];
+ }
+
+ ptrReal++;
+ ptrImag++;
+
+ for ( i = 1; i < 8; i++ )
+ {
+ /*X=x(i:8:M/8) .* exp(-j*2*pi*i*(0:M/8-1)/M);*/
+ ptwiddle = (const Pfloat *) w_a[i - 1];
+
+ fftTmpRe[0] = lpc[0];
+ fftTmpIm[0] = lpc[1];
+
+ for ( j = 1; j < 9; j++ )
+ {
+ fftTmpRe[j] = ( lpc[2 * j] * ptwiddle->re ) - ( lpc[2 * j + 1] * ptwiddle->im );
+ fftTmpIm[j] = ( lpc[2 * j + 1] * ptwiddle->re ) + ( lpc[2 * j] * ptwiddle->im );
+ ptwiddle++;
+ }
+
+ fftTmpRe[j] = lpc[2 * j] * ptwiddle->re;
+ fftTmpIm[j] = lpc[2 * j] * ptwiddle->im;
+ ptwiddle++;
+ j++;
+ for ( ; j < 16; j++ )
+ {
+ fftTmpRe[j] = 0;
+ fftTmpIm[j] = 0;
+ ptwiddle++;
+ }
+
+ DoRTFTn( fftTmpRe, fftTmpIm, 16 );
+
+ for ( j = 0; j < 16; j++ )
+ {
+ ptrReal[j * 8] = fftTmpRe[j];
+ ptrImag[j * 8] = fftTmpIm[j];
+ }
+
+ ptrReal++;
+ ptrImag++;
+ }
+
+ c = EVS_PI / ( 2.0f * (float) 128 );
+
+ for ( i = 1; i < 128; i++ )
+ {
+ twid[i - 1].im = (float) sin( c * ( 2.0f * (float) i ) );
+ twid[i - 1].re = (float) cos( c * ( 2.0f * (float) i ) );
+ }
+ ptwiddle = twid;
+
+ /* pre-twiddle */
+ for ( i = 1; i < 128; i++ )
+ {
+ pwn[i - 1].im = (float) sin( c * ( 18.0f * (float) i ) );
+ pwn[i - 1].re = (float) cos( c * ( 18.0f * (float) i ) );
+ }
+
+ pwn17 = pwn;
+ pwn15 = &tmpw15;
+
+ /*Y(1) = real(X(1)) + imag(X(1));*/
+ RealOut[0] = ( RealFFT[0] + ImagFFT[0] );
+ ImagOut[0] = 0;
+
+ /*Y(N/2+1) = 0.5*(X(1) + conj(X(1))).*exp(pi*i*128*(18)/N) - i*0.5*(X(1) - conj(X(1))).*exp(pi*i*128*(16)/N);*/
+ RealOut[128] = 0;
+ ImagOut[128] = ( RealFFT[0] + RealFFT[0] ) - ( ImagFFT[0] + ImagFFT[0] );
+
+ /*Y(2:N/2) = (0.5*(X(2:N/2) + conj(X(N/2:-1:2))) - i*0.5*(X(2:N/2) - conj(X(N/2:-1:2))).*exp(-pi*i*r*(2)/N)).*exp(pi*i*r*(18)/N);*/
+ for ( i = 1; i < N / 2; i++ )
+ {
+ float ReAr = ( RealFFT[i] + RealFFT[N / 2 - i] );
+ float ReBr = ( RealFFT[N / 2 - i] - RealFFT[i] );
+ float ImAr = ( ImagFFT[i] - ImagFFT[N / 2 - i] );
+ float ImBr = -( ImagFFT[i] + ImagFFT[N / 2 - i] );
+
+ tmpw15.re = ( ptwiddle->re * pwn17->re ) + ( ptwiddle->im * pwn17->im );
+ tmpw15.im = ( ptwiddle->re * pwn17->im ) - ( ptwiddle->im * pwn17->re );
+
+ /*RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->re),ImAr, pwn17->im), ReBr, pwn15->v.im), ImBr, pwn15->re); move16();*/
+ RealOut[i] = ( ReAr * pwn17->re ) - ( ImAr * pwn17->im ) - ( ( ReBr * pwn15->im ) + ( ImBr * pwn15->re ) );
+ ImagOut[i] = ( ReAr * pwn17->im ) + ( ImAr * pwn17->re ) + ( ReBr * pwn15->re ) - ( ImBr * pwn15->im );
+
+ ptwiddle++;
+ pwn17++;
+ }
+
+ spec2isf( RealOut, ImagOut, 128, isf, old_isf );
+
+ isf[lpcOrder - 1] = (Float32) ( acos( a[lpcOrder] ) * SCALE1_HALF );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * dctT2_N_apply_matrix()
+ *
+ * dct/idct truncated matrix appl. for DCT basis vector lengths of N
+ *-------------------------------------------------------------------*/
+
+void dctT2_N_apply_matrix(
+ const float *input, /* i : input in fdcng or DCT(fdcng) domain */
+ float *output, /* o : output in DCT(fdcng) or fdcng ordomain */
+ const int16_t dct_dim, /* i : dct processing dim possibly truncated */
+ const int16_t fdcngvq_dim, /* i : fdcng domain length */
+ const float *matrix, /* i : IDCT matrix */
+ const int16_t matrix_row_dim, /* i : */
+ const DCTTYPE dcttype /* i : matrix operation type */
+)
+{
+ int16_t i, j, dim_in, dim_out;
+ int16_t mat_step_col, mat_step_row, mat_step_col_flag;
+ const float *pt_x, *pt_A;
+ float tmp_y[FDCNG_VQ_MAX_LEN];
+ float *pt_y;
+
+ /* non-square DCT_N and IDCT_N matrix application,
+ using a stored format of an IDCT_Nx(FDCNG_VQ_DCT_MAXTRUNC) matrix */
+ /* efficiently parallelized in SIMD */
+
+ assert( dct_dim <= FDCNG_VQ_DCT_MAXTRUNC );
+ assert( fdcngvq_dim <= FDCNG_VQ_MAX_LEN );
+
+ if ( ( dcttype & 1 ) == 0 ) /* even entries are DCTs */
+ {
+ /* DCT_typeII 24,21 -> XX in worst case */
+ dim_in = fdcngvq_dim;
+ dim_out = dct_dim;
+ mat_step_col = matrix_row_dim; /* matrix maximum storage size dependent, width of first row in matrix */
+ mat_step_row = 0;
+ mat_step_col_flag = 1;
+ assert( dcttype == DCT_T2_21_XX || dcttype == DCT_T2_24_XX );
+ }
+ else
+ {
+ assert( ( dcttype & 1 ) != 0 ); /* idct */
+ dim_in = dct_dim;
+ dim_out = fdcngvq_dim;
+ mat_step_col = 1;
+ mat_step_row = matrix_row_dim;
+ mat_step_col_flag = 0;
+ assert( dcttype == IDCT_T2_XX_24 );
+ }
+
+ pt_y = tmp_y;
+ for ( i = 0; i < dim_out; i++ )
+ {
+ pt_x = input;
+ *pt_y = 0;
+
+ /* +i(DCT) or +i*maxTrunc(IDCT) */
+#define WMC_TOOL_SKIP
+ pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag )] ); /* ptr indexing */
+ PTR_INIT( 1 );
+#undef WMC_TOOL_SKIP
+ for ( j = 0; j < dim_in; j++ )
+ {
+#define WMC_TOOL_SKIP
+ *pt_y += ( *pt_x++ ) * ( *pt_A );
+ pt_A += mat_step_col; /* step +maxtrunc or +1 */ /* ptr indexing*/
+ MAC( 1 );
+#undef WMC_TOOL_SKIP
+ }
+ pt_y++;
+ }
+
+ mvr2r( tmp_y, output, dim_out );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * extend_dctN_input()
+ *
+ * (inputN, dctN) -> idct(N_ext) idct_N matrix application loop for
+ * extending, extrapolating a DCT basis vector length of N to N_ext
+ *-------------------------------------------------------------------*/
+
+void extend_dctN_input(
+ const float *input, /* i : input in fdcng domain */
+ const float *dct_input, /* i : input in dctN(fdcng) domain */
+ const int16_t in_dim, /* i : in_dim == N */
+ float *ext_sig, /* o : extended output in fdcng domain */
+ const int16_t out_dim, /* i : output total dim */
+ float *matrix, /* i : idct synthesis matrix N rows, n_cols columns */
+ const int16_t n_cols, /* i : number of columns == DCT truncation length */
+ const DCTTYPE dcttype /* i : matrix operation type */
+)
+{
+ int16_t i, j, i_rev;
+ const float( *ptr )[FDCNG_VQ_DCT_MAXTRUNC] = (void *) matrix;
+
+ /* stored format is an IDCT_Nx(FDCNG_VQ_DCT_MAXTRUNC) matrix */
+ assert( in_dim < FDCNG_VQ_MAX_LEN );
+ assert( out_dim <= FDCNG_VQ_MAX_LEN );
+ assert( out_dim > in_dim );
+ assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC ); /* for *ptr[MAX_TRUNC] adressing*/
+ assert( ( dcttype & 1 ) != 0 ); /* idct tables always in use for this basis vector extension */
+
+ mvr2r( input, ext_sig, in_dim ); /* copy initial part, i.e. only last/tail parts are extended */
+ set_f( &( ext_sig[in_dim] ), 0.0, out_dim - in_dim );
+
+ i_rev = in_dim; /*ptr init*/
+ for ( i = in_dim; i < out_dim; i++ )
+ { /* for each extension sample */
+ /* i = 21 22 23;
+ i_rev = 20 19 18; for odd dctII reflect basis vector
+ */
+ i_rev--;
+
+ for ( j = 0; j < n_cols; j++ ) /* for each available DCT coeff */
+ {
+ /* DCTcoeff * reflected basis vector */
+#define WMC_TOOL_SKIP
+ /* pure ptr MAC operations */
+ ext_sig[i] += dct_input[j] * ptr[i_rev][j]; /* sum up scaled and extended basis vector */
+ MAC( 1 );
+#undef WMC_TOOL_SKIP
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * create_IDCT_N_Matrix()
+ *
+ * inititate idct24 FDCNG_VQ_DCT_MAXTRUNCx N matrix in
+ * RAM from a quantized compressed ROM format
+ *-------------------------------------------------------------------*/
+
+void create_IDCT_N_Matrix(
+ float *inv_matrixFloatQ, /* i/o: RAM buffer */
+ const int16_t N, /* i : DCT length, number of time samples */
+ const int16_t n_cols, /* i : number of dct coeffs (as DCT may be truncated) */
+ const int16_t alloc_size /* i : RAM buffer size in elements */
+)
+{
+ int16_t c, c1, r, r_flip, W16_val;
+ int16_t len;
+ int16_t mat_cpy_size;
+ const Word16 *absval_ptr;
+ const Word8 *idx_ptr;
+ Word16 idx;
+ float( *ptr )[FDCNG_VQ_DCT_MAXTRUNC] = (void *) inv_matrixFloatQ; /* fixed number of columns pointers, to simplifies adressing in ANSIC */
+
+ absval_ptr = unique_idctT2_24coeffsQ16;
+ idx_ptr = idctT2_24_compressed_idx;
+ len = FDCNG_VQ_MAX_LEN;
+
+ if ( N == FDCNG_VQ_MAX_LEN_WB )
+ {
+ absval_ptr = unique_idctT2_21coeffsQ16;
+ idx_ptr = idctT2_21_compressed_idx;
+ len = N;
+ }
+
+ assert( alloc_size >= ( n_cols * len ) ); /* enough space for the full expanded IDCT matrix */
+ assert( N <= len );
+
+ mat_cpy_size = ( n_cols ) * ( len >> 1 ); /* NB integer division of "len" */
+
+ if ( ( len & 1 ) != 0 )
+ { /* odd sized DCT with a non-reflected center row */
+ mat_cpy_size += n_cols;
+ }
+
+ for ( c = 0; c < mat_cpy_size; c++ )
+ {
+ idx = (Word16) ( idx_ptr[c] );
+ W16_val = absval_ptr[abs( idx )];
+
+ if ( idx < 0 )
+ {
+ W16_val = -( W16_val );
+ }
+ inv_matrixFloatQ[c] = ( +1.52587890625e-05f ) * ( (float) W16_val ); /* 1.0/2.^16 scaling to a float-"Q0" , a scaling that is not done in BASOP */
+ }
+
+ /* for even number of coeffs DCT24,
+ flip symmetry for odd, even is used to save 50% IDCT Table ROM */
+ /* for an odd DCT center is not flipped e.g for DCT21 */
+
+ assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC );
+ assert( ( n_cols & 1 ) == 0 );
+
+ for ( c = 0; c < ( n_cols ); c += 2 )
+ {
+ c1 = c + 1;
+ r_flip = len - 1;
+ for ( r = 0; r < ( len / 2 ); r++, r_flip-- )
+ {
+#define WMC_TOOL_SKIP
+ ptr[r_flip][c] = ptr[r][c]; /* flipped */
+ ptr[r_flip][c1] = -( ptr[r][c1] ); /* flipped and sign swapped */
+ MOVE( 2 );
+ MULT( 1 ); /* for negate */
+#undef WMC_TOOL_SKIP
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/lsp_conv_poly.c b/lib_com/lsp_conv_poly.c
new file mode 100644
index 0000000000000000000000000000000000000000..ee567b3e8053341d6b5e319d00b3bac6a4edc0e3
--- /dev/null
+++ b/lib_com/lsp_conv_poly.c
@@ -0,0 +1,661 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------------------------*/
+
+/* The conversion modes. */
+#define DOWNCONV 0
+#define UPCONV 1
+/* The cap of the inverse power spectrum. */
+#define MAXPOWERSPECT 1e-5f
+#define N50 GRID50_POINTS
+#define N40 GRID40_POINTS
+
+
+/*-------------------------------------------------------------------*
+ * Local function prototypes
+ *-------------------------------------------------------------------*/
+
+static void powerspect( const float x[], const int16_t N, float R[], float S[], float G[], const int16_t mode );
+
+static void spectautocorr( const float x[], const int16_t N, const float G[], float r[] );
+
+static void zeros2poly( float x[], float R[], float S[] );
+
+static void polydecomp( float A[], float P[], float Q[] );
+
+static void cheb2poly( float P[] );
+
+
+/*---------------------------------------------------------------------*
+ * lsp_convert_poly()
+ *
+ * Converts the LP filter estimated at 16.0 kHz sampling rate down
+ * 12.8 kHz frequency scale or alternatively from 12.8 kHz up to
+ * 16.0 kHz. The former is called down conversation and latter up
+ * conversion. The resulting LP filter is characterized with its
+ * line spectrum pairs. The original Lp filter can be either in
+ * its immittance, used for the AMR-WB IO mode, or line spectrum
+ * pair representation.
+ *
+ * The conversion is based the autocorrelation computed from the
+ * power spectrum of the LP filter that is truncated or extrapolated
+ * to the desired frequency scale.
+ *---------------------------------------------------------------------*/
+
+int16_t lsp_convert_poly(
+ float w[], /* i/o: LSP or ISP parameters */
+ const int16_t L_frame, /* i : flag for up or down conversion */
+ const int16_t Opt_AMRWB /* i : flag for the AMR-WB IO mode */
+)
+{
+ float epsP[M + 1];
+ float G[GRID50_POINTS], r[M + 1], A[M + 1], A_old[M + 1], R[NC + 1], S[NC + 1];
+ int16_t i;
+ int16_t flag;
+
+ /*---------------------------------------------------------------------*
+ * Because AMR-WB IO uses immittance spectrum frequency representation
+ * instead of line spectrum frequency representation, the input
+ * parameters do not give the zeros of the polynomials R(x) and S(x).
+ * Hence R(x) and S(x) are formed via the polynomial A(z) of the linear
+ * prediction filter.
+ *---------------------------------------------------------------------*/
+
+ if ( Opt_AMRWB )
+ {
+ isp2a( w, A_old, M );
+ polydecomp( A_old, R, S );
+ }
+
+ /*---------------------------------------------------------------------*
+ * Form the polynomials R(x) and S(x) from their zeros that are the
+ * line spectrum pairs of A(z). The polynomial coefficients can be
+ * scaled for convenience, because scaling will not affect the
+ * resulting LP coefficients. Scaling by 128 gives the correct offset
+ * to the power spectrum for n = 16.
+ *---------------------------------------------------------------------*/
+
+ else
+ {
+ zeros2poly( w, R, S );
+ for ( i = 0; i <= NC; i++ )
+ {
+ R[i] *= 128.0f;
+ S[i] *= 128.0f;
+ }
+ lsp2a_stab( w, A_old, M );
+ }
+
+ /*---------------------------------------------------------------------*
+ * Conversion from 16.0 kHz down to 12.8 kHz. The power spectrum
+ * needs to be computed only up to 6.4 kHz, because the upper band
+ * is omitted.
+ *---------------------------------------------------------------------*/
+
+ if ( L_frame == L_FRAME )
+ {
+ powerspect( grid50, N50, R, S, G, DOWNCONV );
+ spectautocorr( grid40, N40, G, r );
+ }
+
+ /*---------------------------------------------------------------------*
+ * Conversion from 12.8 kHz up to 16.0 kHz.
+ * Compute the power spectrum of the LP filter, extrapolate the
+ * power spectrum from 6.4 kHz to 8.0 kHz, and compute auto-
+ * correlation on this power spectrum.
+ *---------------------------------------------------------------------*/
+
+ else
+ {
+ powerspect( grid40, N40, R, S, G, UPCONV );
+ for ( i = N40; i < N50; i++ )
+ {
+ G[i] = G[N40 - 1];
+ }
+
+ spectautocorr( grid50, N50, G, r );
+ }
+
+ /*---------------------------------------------------------------------*
+ * Compute the linear prediction coefficients from the autocorrelation
+ * and convert to line spectrum pairs.
+ *---------------------------------------------------------------------*/
+
+ flag = lev_dur( A, r, M, epsP );
+ a2lsp_stab( A, w, stable_LSP );
+
+ return ( flag );
+}
+
+
+/*---------------------------------------------------------------------*
+ * powerspect()
+ *
+ * Computes the power spectrum G(w) = 1/|A(w)|^2 at N points on
+ * the real axis x = cos w by utilizing the line spectrum frequency
+ * decomposition
+ *
+ * A(z) = (P(z) + Q(z))/2,
+ *
+ * where assuming A(z) of an even degree n,
+ *
+ * P(z) = [A(z) + z^(n+1) A(1/z)]/(1/z + 1),
+ * Q(z) = [A(z) - z^(n+1) A(1/z)]/(1/z - 1).
+ *
+ * The zeros of these polynomials give the line spectrum frequencies
+ * of A(z). It can be shown that for an even n,
+ *
+ * |A(x)|^2 = 2 (1 + x) R(x)^2 + 2 (1 - x) S(x)^2,
+ *
+ * where x = cos w, and R(x) and S(x) are the direct polynomials
+ * resulting from the Chebyshev series representation of P(z)
+ * and Q(z).
+ *
+ * This routine assumes the grid X = 1, x[0], x[1], .., x[m-1],
+ * -, ..., -x[1], -x[0], -1 such that x[i] = cos((i+1)*pi/N) for
+ * evaluating the power spectrum. Only m = (N-1)/2 - 1 grid points
+ * need to be stored, because cos(0) and cos(pi/2) are trivial,
+ * and the points above pi/2 are obtained readily using the symmetry
+ * of cosine.
+ *
+ * The power spectrum can be scaled as a*G[], where a is chosen
+ * for convenience. This is because the scaling has no impact on
+ * the LP coefficients to be determined based on the power spectrum.
+ *---------------------------------------------------------------------*/
+
+static void powerspect(
+ const float x[], /* i : Grid points x[0:N-1] */
+ const int16_t N, /* i : Number of grid points */
+ float R[], /* i : Coefficients of R(x) in R[0:NC] */
+ float S[], /* i : Coefficients of S(x) in S[0:NC] */
+ float G[], /* o : Power spectrum G[0:N] */
+ const int16_t mode /* i : Flag for up or down conversion */
+)
+{
+ float re, ro, se, so;
+ float s0, s1, r0, r1, x0, x1, x2;
+ Word16 i, j;
+ Word16 iuni, imid;
+
+ /* init buffer */
+ for ( i = 0; i < N; i++ )
+ {
+ G[i] = 0;
+ }
+ /*---------------------------------------------------------------------*
+ * Down conversion yields iuni unique grid points that do not have
+ * symmetric counterparts above x = cos(pi/2) = 0.
+ * Set the mid point of the frequency grid.
+ *---------------------------------------------------------------------*/
+
+ if ( mode == DOWNCONV )
+ {
+ iuni = ( GRID50_POINTS - 1 ) / 5 - 1;
+ imid = ( GRID50_POINTS - 1 ) / 2;
+ }
+
+ /*---------------------------------------------------------------------*
+ * Power spectrum at x = cos(pi) = -1 that is not needed in down
+ * conversion. Set the mid point of the frequency grid.
+ *---------------------------------------------------------------------*/
+
+ else
+ {
+ iuni = 0;
+ imid = ( GRID40_POINTS - 1 ) / 2;
+
+ s0 = S[0];
+ for ( j = 1; j <= NC; j++ )
+ {
+ s0 = S[j] - s0;
+ }
+ G[N - 1] = 4.0f * s0 * s0;
+ }
+
+ /*---------------------------------------------------------------------*
+ * Power spectrum at x = cos(0) = 1.
+ *---------------------------------------------------------------------*/
+
+ r0 = R[0];
+ for ( j = 1; j <= NC; j++ )
+ {
+ r0 += R[j];
+ }
+ r0 = max( r0, 0.000000953674316f );
+ G[0] = 4.0f * r0 * r0;
+
+ /*---------------------------------------------------------------------*
+ * Power spectrum at x = cos(pi/2) = 0.
+ *---------------------------------------------------------------------*/
+
+ r0 = R[NC];
+ s0 = S[NC];
+ r0 = r0 * r0;
+ s0 = s0 * s0;
+
+ G[imid] = 2.0f * ( r0 + s0 );
+
+ /*---------------------------------------------------------------------*
+ * Power spectrum at unique points that do not have symmetric
+ * counterparts at x > cos(pi/2) = 0.
+ *---------------------------------------------------------------------*/
+
+ for ( i = 1; i <= iuni; i++ )
+ {
+ x0 = x[i - 1];
+ r0 = R[0];
+ s0 = S[0];
+
+ for ( j = 1; j <= NC; j++ )
+ {
+ r0 = x0 * r0 + R[j];
+ s0 = x0 * s0 + S[j];
+ }
+ r0 = ( 1.0f + x0 ) * r0 * r0;
+ s0 = ( 1.0f - x0 ) * s0 * s0;
+
+ G[i] = 2.0f * ( r0 + s0 );
+ }
+
+ /*---------------------------------------------------------------------*
+ * Power spectrum at points other than x = -1, 0, and 1 and unique
+ * points is computed using the anti-symmetry of the grid relative
+ * to the midpoint x = 0 in order to reduce looping.
+ *---------------------------------------------------------------------*/
+
+ for ( ; i < imid; i++ )
+ {
+ x0 = x[i - 1];
+ x2 = x0 * x0;
+
+ re = R[0];
+ se = S[0];
+ ro = R[1];
+ so = S[1];
+
+ for ( j = 2; j < NC; j += 2 )
+ {
+ re = x2 * re + R[j];
+ ro = x2 * ro + R[j + 1];
+ se = x2 * se + S[j];
+ so = x2 * so + S[j + 1];
+ }
+
+ re = x2 * re + R[j];
+ ro *= x0;
+ se = x2 * se + S[j];
+ so *= x0;
+
+ r0 = re + ro;
+ s0 = se + so;
+ r1 = re - ro;
+ s1 = se - so;
+
+ x1 = 1.0f + x0;
+ x2 = 1.0f - x0;
+
+ r0 = x1 * r0 * r0;
+ s0 = x2 * s0 * s0;
+ r1 = x2 * r1 * r1;
+ s1 = x1 * s1 * s1;
+
+ G[i] = 2.0f * ( r0 + s0 );
+ G[N - i - 1] = 2.0f * ( r1 + s1 );
+ }
+
+ /*---------------------------------------------------------------------*
+ * Compute the power spectrum 1/|A(x)|^2 from |A(x)|^2 with logic
+ * to prevent division by small number and upper bound the spectrum.
+ * This upper bound is implicit in fixed point arithmetic, but is
+ * needed explicitly in floating point implementations to avoid numeric
+ * problems.
+ *---------------------------------------------------------------------*/
+
+ for ( i = 0; i < N; i++ )
+ {
+ if ( G[i] < MAXPOWERSPECT )
+ {
+ G[i] = MAXPOWERSPECT;
+ }
+ G[i] = 1.0f / G[i];
+ }
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * spectautocorr()
+ *
+ * Computes the autocorrelation r[j] for j = 0, 1, ..., M from
+ * the power spectrum P(w) by using the rectangle rule to
+ * approximate the integral
+ *
+ * 1 pi
+ * r[j] = --- I P(w) cos(j*w) dw.
+ * 2*pi -pi
+ *
+ * It is sufficient to evaluate the integrand only from w = 0 to
+ * w = pi due to the symmetry P(-w) = P(w). We can further
+ * employ the relation
+ *
+ * cos(j*(pi - w)) = (-1)^j cos(j*w)
+ *
+ * to use symmetries relative to w = pi/2 for w in (0, pi/2).
+ *
+ * When applying the rectangle rule, it is convenient to evaluate
+ * w = 0, w = pi/2, and w = pi separately. By using a frequency
+ * grid of N points, we can express the rectangle rule as
+ *
+ * r[j] = G[0] + 2*a*G[(N-1)/2] + b*G[N-1]
+ *
+ * M
+ * + 2 sum (G[i] - G[N-i-1]) cos(j*x[i])
+ * i=1
+ *
+ * where G[i] is the power spectrum at x[i] = i*pi/(N-1) and
+ * M = (N-1)/2 - 1 is the number of the grid points in the
+ * interval(0, pi/2). The number of grid points N is assumed odd.
+ *
+ * The coefficients
+ *
+ * b = (-1)^j
+ * a = (1 + (-1)^(j+1))(-1)^floor(j/2)
+ *
+ * follow from the properties of the cosine function. The
+ * computation further uses the recursion
+ *
+ * cos(j*w) = 2*cos(w)*cos((j-1)*w) - cos((j-2)*w)
+ *
+ * Note that the autocorrelation can be scaled for convenience,
+ * because this scaling has no impact on the LP coefficients to be
+ * calculated from the autocorrelation. The expression of r[j] thus
+ * omits the division by N.
+ *
+ * See the powerspect function on the definition of the grid.
+ *
+ * References
+ * J. Makhoul, "Spectral linear prediction: properties and
+ * applications," IEEE Trans. on Acoustics, Speech and Signal
+ * Processing, Vol. 23, No. 3, pp.283-296, June 1975
+ *---------------------------------------------------------------------*/
+
+static void spectautocorr(
+ const float x[], /* i : Grid points x[0:N-1] */
+ const int16_t N, /* i : Number of grid points */
+ const float G[], /* i : Power spectrum G[0:N-1] */
+ float r[] /* o : Autocorrelation r[0:M] */
+)
+{
+ float c[M + 1]; /* c[j] = cos(j*w) */
+ float gp, gn, c2;
+ Word16 i, j;
+ Word16 imid;
+
+ /*---------------------------------------------------------------------*
+ * The midpoint of the cosine table x of N entries. Only the entries
+ * x[0] = cos(d), x[1] = cos(2*d), ..., x[imid-1] = cos((imid-1)*d)
+ * need to be stored due to trivial cos(0), cos(pi/2), cos(pi), and
+ * symmetry relative to pi/2. Here d = pi/(N - 1).
+ *---------------------------------------------------------------------*/
+
+ imid = ( N - 1 ) / 2;
+
+ /*---------------------------------------------------------------------*
+ * Autocorrelation r[j] at zero lag j = 0 for the upper half of the
+ * unit circle, but excluding the points x = cos(0) and x = cos(pi).
+ *---------------------------------------------------------------------*/
+
+ r[0] = G[1];
+ for ( i = 2; i < N - 1; i++ )
+ {
+ r[0] += G[i];
+ }
+
+ /*---------------------------------------------------------------------*
+ * Initialize the autocorrelation r[j] at lags greater than zero
+ * by adding the midpoint x = cos(pi/2) = 0.
+ *---------------------------------------------------------------------*/
+
+ r[1] = 0.0f;
+ r[2] = -G[imid];
+
+ for ( j = 3; j < M; j += 2 )
+ {
+ r[j] = 0.0f;
+ r[j + 1] = -r[j - 1];
+ }
+
+ /*---------------------------------------------------------------------*
+ * Autocorrelation r[j] at lags j = 1, 2, ..., M. The computation
+ * employes the relation cos(j*(pi - w)) = (-1)^j cos(j*w) and
+ * cos(j*w) = 2*cos(w)*cos((j-1)*w) - cos((j-2)*w) for obtaining
+ * the cosine c[j] = cos(j*w).
+ *---------------------------------------------------------------------*/
+
+ c[0] = 1.0f;
+
+ for ( i = 1; i < imid; i++ )
+ {
+ gp = G[i] + G[N - i - 1];
+ gn = G[i] - G[N - i - 1];
+
+ c[1] = x[i - 1];
+ c2 = 2.0f * c[1];
+
+ r[1] += gn * c[1];
+
+ for ( j = 2; j < M; j += 2 )
+ {
+ c[j] = c2 * c[j - 1] - c[j - 2];
+ r[j] += gp * c[j];
+ c[j + 1] = c2 * c[j] - c[j - 1];
+ r[j + 1] += gn * c[j + 1];
+ }
+
+ c[j] = c2 * c[j - 1] - c[j - 2];
+ r[j] += gp * c[j];
+ }
+
+ /*---------------------------------------------------------------------*
+ * Add the endpoints x = cos(0) = 1 and x = cos(pi) = -1 as
+ * well as the lower half of the unit circle.
+ *---------------------------------------------------------------------*/
+
+ gp = G[0] + G[N - 1];
+ gn = G[0] - G[N - 1];
+
+ for ( j = 0; j < M; j += 2 )
+ {
+ r[j] = 2.0f * r[j] + gp;
+ r[j + 1] = 2.0f * r[j + 1] + gn;
+ }
+ r[j] = 2.0f * r[j] + gp;
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * zeros2poly()
+ *
+ * Computes the coefficients of the polynomials
+ *
+ * R(x) = prod (x - x[i]),
+ * i = 0,2,4,...
+ *
+ * S(x) = prod (x - x[i]),
+ * i = 1,3,5,...
+ *
+ * given their zeros x[i] for i = 0, 1, ..., n-1. The routine
+ * assumes n = 1 or even n greater than or equal to 4.
+ *
+ * The polynomial coefficients are returned in R[0:n/2-1] and
+ * S[0:n/2-1]. The leading coefficients are in R[0] and S[0].
+ *
+ * In this implementation, n is set to a compile time constant.
+ *---------------------------------------------------------------------*/
+
+static void zeros2poly(
+ float x[], /* i : Zeros of R(x) and S(x) */
+ float R[], /* o : Coefficients of R(x) */
+ float S[] /* o : Coefficients of S(x) */
+)
+{
+ float xr, xs;
+ Word16 i, j;
+
+ R[0] = 1.0f;
+ R[1] = -*x++;
+ S[0] = 1.0f;
+ S[1] = -*x++;
+
+ for ( i = 2; i <= NC; i++ )
+ {
+ xr = -*x++;
+ xs = -*x++;
+
+ R[i] = xr * R[i - 1];
+ S[i] = xs * S[i - 1];
+
+ for ( j = i - 1; j > 0; j-- )
+ {
+ R[j] += xr * R[j - 1];
+ S[j] += xs * S[j - 1];
+ }
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * polydecomp()
+ *
+ * Computes the coefficients of the symmetric and antisymmetric
+ * polynomials P(z) and Q(z) that define the line spectrum pair
+ * decomposition of a given polynomial A(z) of order n. For even n,
+ *
+ * P(z) = [A(z) + z^(n+1) A(1/z)]/(1/z + 1),
+ * Q(z) = [A(z) - z^(n+1) A(1/z)]/(1/z - 1),
+ *
+ * These polynomials are then expressed in their direct form,
+ * respectively, R(x) and S(x), on the real axis x = cos w using
+ * explicit Chebyshev polynomials of the first kind.
+ *
+ * The coefficients of the polynomials R(x) and S(x) are returned
+ * in R[0:n/2] and S[0:n/2] for the given linear prediction
+ * coefficients A[0:n/2]. Note that R(x) and S(x) are formed in
+ * place such that P(z) is stored in the same array than R(x),
+ * and Q(z) is stored in the same array than S(x).
+ *
+ * The routines assumes n = 16.
+ *---------------------------------------------------------------------*/
+
+static void polydecomp(
+ float A[], /* i : linear prediction coefficients */
+ float R[], /* o : coefficients of R(x) */
+ float S[] /* o : coefficients of S(x) */
+)
+{
+ float *P = &R[0], *Q = &S[0];
+ Word16 i, j;
+
+ P[0] = A[0];
+ Q[0] = A[0];
+ for ( i = 1, j = M; i <= NC; i++, j-- )
+ {
+ P[i] = A[i] + A[j] - P[i - 1];
+ Q[i] = A[i] - A[j] + Q[i - 1];
+ }
+
+ cheb2poly( P );
+ cheb2poly( Q );
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * cheb2poly()
+ *
+ * Computes the coefficients of the explicit Chebyshev polynomial
+ * P(x) = P[0]*x^n + P[1]*x^(n-1) + ... + P[n] given the coefficients
+ * of the series
+ *
+ * C(x) = C[0]*T_n(x) + C[1]*T_n-1(x) + ... + C[n]*T_0(x),
+ *
+ * where T_n(x) is the nth Chebyshev polynomial of the first kind.
+ * This implementation assumes C[0] = 1. Only the value n = 8 is
+ * supported.
+ *
+ * The conversion from C(x) to P(x) is done in place such that the
+ * coefficients of C(x) are given in P[0:8] and those of P(x) are
+ * returned in the same array.
+ *---------------------------------------------------------------------*/
+
+static void cheb2poly(
+ float P[] /* i/o: The coefficients of C(x) and P(x) */
+)
+{
+ float c1, c2, c3, c4, c5, c6, c7, c8;
+
+ c1 = P[1];
+ c2 = P[2];
+ c3 = P[3];
+ c4 = P[4];
+ c5 = P[5];
+ c6 = P[6];
+ c7 = P[7];
+ c8 = P[8];
+
+ P[0] = 128.0f;
+ P[1] = 64.0f * c1;
+ P[2] = 32.0f * c2 - 256.0f;
+ P[3] = 16.0f * c3 - 112.0f * c1;
+ P[4] = 160.0f - 48.0f * c2 + 8.0f * c4;
+ P[5] = 56.0f * c1 - 20.0f * c3 + 4.0f * c5;
+ P[6] = 18.0f * c2 - 32.0f - 8.0f * c4 + 2.0f * c6;
+ P[7] = 5.0f * c3 - 7.0f * c1 - 3.0f * c5 + c7;
+ P[8] = 1.0f - c2 + c4 - c6 + 0.5f * c8;
+
+ return;
+}
diff --git a/lib_com/mime.h b/lib_com/mime.h
new file mode 100644
index 0000000000000000000000000000000000000000..56f2fb4db96c6281ff0f0c57484480e56be8dd02
--- /dev/null
+++ b/lib_com/mime.h
@@ -0,0 +1,447 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 MIME_H
+#define MIME_H
+
+#include
+#include
+#include "options.h"
+#include "typedef.h"
+
+#define AMRWB_MAGIC_NUMBER "#!AMR-WB\n" /* defined in RFC4867 */
+#define EVS_MAGIC_NUMBER "#!EVS_MC1.0\n" /* defined in 26.445 */
+
+static const Word32 AMRWB_IOmode2rate[16] = {
+ 6600, /* AMRWB_IO_6600 */
+ 8850, /* AMRWB_IO_8850 */
+ 12650, /* AMRWB_IO_1265 */
+ 14250, /* AMRWB_IO_1425 */
+ 15850, /* AMRWB_IO_1585 */
+ 18250, /* AMRWB_IO_1825 */
+ 19850, /* AMRWB_IO_1985 */
+ 23050, /* AMRWB_IO_2305 */
+ 23850, /* AMRWB_IO_2385 */
+ 1750, /* AMRWB_IO_SID */
+ -1, /* AMRWB_IO_FUT1 */
+ -1, /* AMRWB_IO_FUT2 */
+ -1, /* AMRWB_IO_FUT3 */
+ -1, /* AMRWB_IO_FUT4 */
+ 0, /* SPEECH_BAD */
+ 0 /* NO_DATA */
+};
+
+static const Word32 PRIMARYmode2rate[16] = {
+ 2800, /* PRIMARY_2800 */
+ 7200, /* PRIMARY_7200 */
+ 8000, /* PRIMARY_8000 */
+ 9600, /* PRIMARY_9600 */
+ 13200, /* PRIMARY_13200 */
+ 16400, /* PRIMARY_16400 */
+ 24400, /* PRIMARY_24400 */
+ 32000, /* PRIMARY_32000 */
+ 48000, /* PRIMARY_48000 */
+ 64000, /* PRIMARY_64000 */
+ 96000, /* PRIMARY_96000 */
+ 128000, /* PRIMARY_128000 */
+ 2400, /* PRIMARY_SID */
+ -1, /* PRIMARY_FUT1 */
+ 0, /* SPEECH_LOST */
+ 0 /* NO_DATA */
+};
+
+/* sorting tables for all AMR-WB IO modes */
+
+static const Word16 sort_660[132] = {
+ 0, 5, 6, 7, 61, 84, 107, 130, 62, 85,
+ 8, 4, 37, 38, 39, 40, 58, 81, 104, 127,
+ 60, 83, 106, 129, 108, 131, 128, 41, 42, 80,
+ 126, 1, 3, 57, 103, 82, 105, 59, 2, 63,
+ 109, 110, 86, 19, 22, 23, 64, 87, 18, 20,
+ 21, 17, 13, 88, 43, 89, 65, 111, 14, 24,
+ 25, 26, 27, 28, 15, 16, 44, 90, 66, 112,
+ 9, 11, 10, 12, 67, 113, 29, 30, 31, 32,
+ 34, 33, 35, 36, 45, 51, 68, 74, 91, 97,
+ 114, 120, 46, 69, 92, 115, 52, 75, 98, 121,
+ 47, 70, 93, 116, 53, 76, 99, 122, 48, 71,
+ 94, 117, 54, 77, 100, 123, 49, 72, 95, 118,
+ 55, 78, 101, 124, 50, 73, 96, 119, 56, 79,
+ 102, 125
+};
+
+static const Word16 sort_885[177] = {
+ 0, 4, 6, 7, 5, 3, 47, 48, 49, 112,
+ 113, 114, 75, 106, 140, 171, 80, 111, 145, 176,
+ 77, 108, 142, 173, 78, 109, 143, 174, 79, 110,
+ 144, 175, 76, 107, 141, 172, 50, 115, 51, 2,
+ 1, 81, 116, 146, 19, 21, 12, 17, 18, 20,
+ 16, 25, 13, 10, 14, 24, 23, 22, 26, 8,
+ 15, 52, 117, 31, 82, 147, 9, 33, 11, 83,
+ 148, 53, 118, 28, 27, 84, 149, 34, 35, 29,
+ 46, 32, 30, 54, 119, 37, 36, 39, 38, 40,
+ 85, 150, 41, 42, 43, 44, 45, 55, 60, 65,
+ 70, 86, 91, 96, 101, 120, 125, 130, 135, 151,
+ 156, 161, 166, 56, 87, 121, 152, 61, 92, 126,
+ 157, 66, 97, 131, 162, 71, 102, 136, 167, 57,
+ 88, 122, 153, 62, 93, 127, 158, 67, 98, 132,
+ 163, 72, 103, 137, 168, 58, 89, 123, 154, 63,
+ 94, 128, 159, 68, 99, 133, 164, 73, 104, 138,
+ 169, 59, 90, 124, 155, 64, 95, 129, 160, 69,
+ 100, 134, 165, 74, 105, 139, 170
+};
+
+static const Word16 sort_1265[253] = {
+ 0, 4, 6, 93, 143, 196, 246, 7, 5, 3,
+ 47, 48, 49, 50, 51, 150, 151, 152, 153, 154,
+ 94, 144, 197, 247, 99, 149, 202, 252, 96, 146,
+ 199, 249, 97, 147, 200, 250, 100, 203, 98, 148,
+ 201, 251, 95, 145, 198, 248, 52, 2, 1, 101,
+ 204, 155, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 156, 31, 102, 205, 9, 33, 11, 103, 206, 54,
+ 157, 28, 27, 104, 207, 34, 35, 29, 46, 32,
+ 30, 55, 158, 37, 36, 39, 38, 40, 105, 208,
+ 41, 42, 43, 44, 45, 56, 106, 159, 209, 57,
+ 66, 75, 84, 107, 116, 125, 134, 160, 169, 178,
+ 187, 210, 219, 228, 237, 58, 108, 161, 211, 62,
+ 112, 165, 215, 67, 117, 170, 220, 71, 121, 174,
+ 224, 76, 126, 179, 229, 80, 130, 183, 233, 85,
+ 135, 188, 238, 89, 139, 192, 242, 59, 109, 162,
+ 212, 63, 113, 166, 216, 68, 118, 171, 221, 72,
+ 122, 175, 225, 77, 127, 180, 230, 81, 131, 184,
+ 234, 86, 136, 189, 239, 90, 140, 193, 243, 60,
+ 110, 163, 213, 64, 114, 167, 217, 69, 119, 172,
+ 222, 73, 123, 176, 226, 78, 128, 181, 231, 82,
+ 132, 185, 235, 87, 137, 190, 240, 91, 141, 194,
+ 244, 61, 111, 164, 214, 65, 115, 168, 218, 70,
+ 120, 173, 223, 74, 124, 177, 227, 79, 129, 182,
+ 232, 83, 133, 186, 236, 88, 138, 191, 241, 92,
+ 142, 195, 245
+};
+
+static const Word16 sort_1425[285] = {
+ 0, 4, 6, 101, 159, 220, 278, 7, 5, 3,
+ 47, 48, 49, 50, 51, 166, 167, 168, 169, 170,
+ 102, 160, 221, 279, 107, 165, 226, 284, 104, 162,
+ 223, 281, 105, 163, 224, 282, 108, 227, 106, 164,
+ 225, 283, 103, 161, 222, 280, 52, 2, 1, 109,
+ 228, 171, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 172, 31, 110, 229, 9, 33, 11, 111, 230, 54,
+ 173, 28, 27, 112, 231, 34, 35, 29, 46, 32,
+ 30, 55, 174, 37, 36, 39, 38, 40, 113, 232,
+ 41, 42, 43, 44, 45, 56, 114, 175, 233, 62,
+ 120, 181, 239, 75, 133, 194, 252, 57, 115, 176,
+ 234, 63, 121, 182, 240, 70, 128, 189, 247, 76,
+ 134, 195, 253, 83, 141, 202, 260, 92, 150, 211,
+ 269, 84, 142, 203, 261, 93, 151, 212, 270, 85,
+ 143, 204, 262, 94, 152, 213, 271, 86, 144, 205,
+ 263, 95, 153, 214, 272, 64, 122, 183, 241, 77,
+ 135, 196, 254, 65, 123, 184, 242, 78, 136, 197,
+ 255, 87, 145, 206, 264, 96, 154, 215, 273, 58,
+ 116, 177, 235, 66, 124, 185, 243, 71, 129, 190,
+ 248, 79, 137, 198, 256, 88, 146, 207, 265, 97,
+ 155, 216, 274, 59, 117, 178, 236, 67, 125, 186,
+ 244, 72, 130, 191, 249, 80, 138, 199, 257, 89,
+ 147, 208, 266, 98, 156, 217, 275, 60, 118, 179,
+ 237, 68, 126, 187, 245, 73, 131, 192, 250, 81,
+ 139, 200, 258, 90, 148, 209, 267, 99, 157, 218,
+ 276, 61, 119, 180, 238, 69, 127, 188, 246, 74,
+ 132, 193, 251, 82, 140, 201, 259, 91, 149, 210,
+ 268, 100, 158, 219, 277
+};
+
+static const Word16 sort_1585[317] = {
+ 0, 4, 6, 109, 175, 244, 310, 7, 5, 3,
+ 47, 48, 49, 50, 51, 182, 183, 184, 185, 186,
+ 110, 176, 245, 311, 115, 181, 250, 316, 112, 178,
+ 247, 313, 113, 179, 248, 314, 116, 251, 114, 180,
+ 249, 315, 111, 177, 246, 312, 52, 2, 1, 117,
+ 252, 187, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 188, 31, 118, 253, 9, 33, 11, 119, 254, 54,
+ 189, 28, 27, 120, 255, 34, 35, 29, 46, 32,
+ 30, 55, 190, 37, 36, 39, 38, 40, 121, 256,
+ 41, 42, 43, 44, 45, 56, 122, 191, 257, 63,
+ 129, 198, 264, 76, 142, 211, 277, 89, 155, 224,
+ 290, 102, 168, 237, 303, 57, 123, 192, 258, 70,
+ 136, 205, 271, 83, 149, 218, 284, 96, 162, 231,
+ 297, 62, 128, 197, 263, 75, 141, 210, 276, 88,
+ 154, 223, 289, 101, 167, 236, 302, 58, 124, 193,
+ 259, 71, 137, 206, 272, 84, 150, 219, 285, 97,
+ 163, 232, 298, 59, 125, 194, 260, 64, 130, 199,
+ 265, 67, 133, 202, 268, 72, 138, 207, 273, 77,
+ 143, 212, 278, 80, 146, 215, 281, 85, 151, 220,
+ 286, 90, 156, 225, 291, 93, 159, 228, 294, 98,
+ 164, 233, 299, 103, 169, 238, 304, 106, 172, 241,
+ 307, 60, 126, 195, 261, 65, 131, 200, 266, 68,
+ 134, 203, 269, 73, 139, 208, 274, 78, 144, 213,
+ 279, 81, 147, 216, 282, 86, 152, 221, 287, 91,
+ 157, 226, 292, 94, 160, 229, 295, 99, 165, 234,
+ 300, 104, 170, 239, 305, 107, 173, 242, 308, 61,
+ 127, 196, 262, 66, 132, 201, 267, 69, 135, 204,
+ 270, 74, 140, 209, 275, 79, 145, 214, 280, 82,
+ 148, 217, 283, 87, 153, 222, 288, 92, 158, 227,
+ 293, 95, 161, 230, 296, 100, 166, 235, 301, 105,
+ 171, 240, 306, 108, 174, 243, 309
+};
+
+static const Word16 sort_1825[365] = {
+ 0, 4, 6, 121, 199, 280, 358, 7, 5, 3,
+ 47, 48, 49, 50, 51, 206, 207, 208, 209, 210,
+ 122, 200, 281, 359, 127, 205, 286, 364, 124, 202,
+ 283, 361, 125, 203, 284, 362, 128, 287, 126, 204,
+ 285, 363, 123, 201, 282, 360, 52, 2, 1, 129,
+ 288, 211, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 212, 31, 130, 289, 9, 33, 11, 131, 290, 54,
+ 213, 28, 27, 132, 291, 34, 35, 29, 46, 32,
+ 30, 55, 214, 37, 36, 39, 38, 40, 133, 292,
+ 41, 42, 43, 44, 45, 56, 134, 215, 293, 198,
+ 299, 136, 120, 138, 60, 279, 58, 62, 357, 139,
+ 140, 295, 156, 57, 219, 297, 63, 217, 137, 170,
+ 300, 222, 64, 106, 61, 78, 294, 92, 142, 141,
+ 135, 221, 296, 301, 343, 59, 298, 184, 329, 315,
+ 220, 216, 265, 251, 218, 237, 352, 223, 157, 86,
+ 171, 87, 164, 351, 111, 302, 65, 178, 115, 323,
+ 72, 192, 101, 179, 93, 73, 193, 151, 337, 309,
+ 143, 274, 69, 324, 165, 150, 97, 338, 110, 310,
+ 330, 273, 68, 107, 175, 245, 114, 79, 113, 189,
+ 246, 259, 174, 71, 185, 96, 344, 100, 322, 83,
+ 334, 316, 333, 252, 161, 348, 147, 82, 269, 232,
+ 260, 308, 353, 347, 163, 231, 306, 320, 188, 270,
+ 146, 177, 266, 350, 256, 85, 149, 116, 191, 160,
+ 238, 258, 336, 305, 255, 88, 224, 99, 339, 230,
+ 228, 227, 272, 242, 241, 319, 233, 311, 102, 74,
+ 180, 275, 66, 194, 152, 325, 172, 247, 244, 261,
+ 117, 158, 166, 354, 75, 144, 108, 312, 94, 186,
+ 303, 80, 234, 89, 195, 112, 340, 181, 345, 317,
+ 326, 276, 239, 167, 118, 313, 70, 355, 327, 253,
+ 190, 176, 271, 104, 98, 153, 103, 90, 76, 267,
+ 277, 248, 225, 262, 182, 84, 154, 235, 335, 168,
+ 331, 196, 341, 249, 162, 307, 148, 349, 263, 321,
+ 257, 243, 229, 356, 159, 119, 67, 187, 173, 145,
+ 240, 77, 304, 332, 314, 342, 109, 254, 81, 278,
+ 105, 91, 346, 318, 183, 250, 197, 328, 95, 155,
+ 169, 268, 226, 236, 264
+};
+
+static const Word16 sort_1985[397] = {
+ 0, 4, 6, 129, 215, 304, 390, 7, 5, 3,
+ 47, 48, 49, 50, 51, 222, 223, 224, 225, 226,
+ 130, 216, 305, 391, 135, 221, 310, 396, 132, 218,
+ 307, 393, 133, 219, 308, 394, 136, 311, 134, 220,
+ 309, 395, 131, 217, 306, 392, 52, 2, 1, 137,
+ 312, 227, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 228, 31, 138, 313, 9, 33, 11, 139, 314, 54,
+ 229, 28, 27, 140, 315, 34, 35, 29, 46, 32,
+ 30, 55, 230, 37, 36, 39, 38, 40, 141, 316,
+ 41, 42, 43, 44, 45, 56, 142, 231, 317, 63,
+ 73, 92, 340, 82, 324, 149, 353, 159, 334, 165,
+ 338, 178, 163, 254, 77, 168, 257, 153, 343, 57,
+ 248, 238, 79, 252, 166, 67, 80, 201, 101, 267,
+ 143, 164, 341, 255, 339, 187, 376, 318, 78, 328,
+ 362, 115, 232, 242, 253, 290, 276, 62, 58, 158,
+ 68, 93, 179, 319, 148, 169, 154, 72, 385, 329,
+ 333, 344, 102, 83, 144, 233, 323, 124, 243, 192,
+ 354, 237, 64, 247, 202, 209, 150, 116, 335, 268,
+ 239, 299, 188, 196, 298, 94, 195, 258, 123, 363,
+ 384, 109, 325, 371, 170, 370, 84, 110, 295, 180,
+ 74, 210, 191, 106, 291, 205, 367, 381, 377, 206,
+ 355, 122, 119, 120, 383, 160, 105, 108, 277, 380,
+ 294, 284, 285, 345, 208, 269, 249, 366, 386, 300,
+ 297, 259, 125, 369, 197, 97, 194, 286, 211, 281,
+ 280, 183, 372, 87, 155, 283, 59, 348, 327, 184,
+ 76, 111, 330, 203, 349, 69, 98, 152, 145, 189,
+ 66, 320, 337, 173, 358, 251, 198, 174, 263, 262,
+ 126, 241, 193, 88, 388, 117, 95, 387, 112, 359,
+ 287, 244, 103, 272, 301, 171, 162, 234, 273, 127,
+ 373, 181, 292, 85, 378, 302, 121, 107, 364, 346,
+ 356, 212, 278, 213, 65, 382, 288, 207, 113, 175,
+ 99, 296, 374, 368, 199, 260, 185, 336, 331, 161,
+ 270, 264, 250, 240, 75, 350, 151, 60, 89, 321,
+ 156, 274, 360, 326, 70, 282, 167, 146, 352, 81,
+ 91, 389, 266, 245, 177, 235, 190, 256, 204, 342,
+ 128, 118, 303, 104, 379, 182, 114, 375, 200, 96,
+ 293, 172, 214, 365, 279, 86, 289, 351, 347, 357,
+ 261, 186, 176, 271, 90, 100, 147, 322, 275, 361,
+ 71, 332, 61, 265, 157, 246, 236
+};
+
+static const Word16 sort_2305[461] = {
+ 0, 4, 6, 145, 247, 352, 454, 7, 5, 3,
+ 47, 48, 49, 50, 51, 254, 255, 256, 257, 258,
+ 146, 248, 353, 455, 151, 253, 358, 460, 148, 250,
+ 355, 457, 149, 251, 356, 458, 152, 359, 150, 252,
+ 357, 459, 147, 249, 354, 456, 52, 2, 1, 153,
+ 360, 259, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 260, 31, 154, 361, 9, 33, 11, 155, 362, 54,
+ 261, 28, 27, 156, 363, 34, 35, 29, 46, 32,
+ 30, 55, 262, 37, 36, 39, 38, 40, 157, 364,
+ 41, 42, 43, 44, 45, 56, 158, 263, 365, 181,
+ 192, 170, 79, 57, 399, 90, 159, 297, 377, 366,
+ 275, 68, 183, 388, 286, 194, 299, 92, 70, 182,
+ 401, 172, 59, 91, 58, 400, 368, 161, 81, 160,
+ 264, 171, 80, 389, 390, 378, 379, 193, 298, 69,
+ 266, 265, 367, 277, 288, 276, 287, 184, 60, 195,
+ 82, 93, 71, 369, 402, 173, 162, 444, 300, 391,
+ 98, 76, 278, 61, 267, 374, 135, 411, 167, 102,
+ 380, 200, 87, 178, 65, 94, 204, 124, 72, 342,
+ 189, 305, 381, 396, 433, 301, 226, 407, 289, 237,
+ 113, 215, 185, 128, 309, 403, 116, 320, 196, 331,
+ 370, 422, 174, 64, 392, 83, 425, 219, 134, 188,
+ 432, 112, 427, 139, 279, 163, 436, 208, 447, 218,
+ 236, 229, 97, 294, 385, 230, 166, 268, 177, 443,
+ 225, 426, 101, 272, 138, 127, 290, 117, 347, 199,
+ 414, 95, 140, 240, 410, 395, 209, 129, 283, 346,
+ 105, 241, 437, 86, 308, 448, 203, 345, 186, 107,
+ 220, 415, 334, 319, 106, 313, 118, 123, 73, 207,
+ 421, 214, 384, 373, 438, 62, 371, 341, 75, 449,
+ 168, 323, 164, 242, 416, 324, 304, 197, 335, 404,
+ 271, 63, 191, 325, 96, 169, 231, 280, 312, 187,
+ 406, 84, 201, 100, 67, 382, 175, 336, 202, 330,
+ 269, 393, 376, 383, 293, 307, 409, 179, 285, 314,
+ 302, 372, 398, 190, 180, 89, 99, 103, 232, 78,
+ 88, 77, 136, 387, 165, 198, 394, 125, 176, 428,
+ 74, 375, 238, 227, 66, 273, 282, 141, 306, 412,
+ 114, 85, 130, 348, 119, 291, 296, 386, 233, 397,
+ 303, 405, 284, 445, 423, 221, 210, 205, 450, 108,
+ 274, 434, 216, 343, 337, 142, 243, 321, 408, 451,
+ 310, 292, 120, 109, 281, 439, 270, 429, 332, 295,
+ 418, 211, 315, 222, 326, 131, 430, 244, 327, 349,
+ 417, 316, 143, 338, 440, 234, 110, 212, 452, 245,
+ 121, 419, 350, 223, 132, 441, 328, 413, 317, 339,
+ 126, 104, 137, 446, 344, 239, 435, 115, 333, 206,
+ 322, 217, 228, 424, 453, 311, 351, 111, 442, 224,
+ 213, 122, 431, 340, 235, 246, 133, 144, 420, 329,
+ 318
+};
+
+static const Word16 sort_2385[477] = {
+ 0, 4, 6, 145, 251, 360, 466, 7, 5, 3,
+ 47, 48, 49, 50, 51, 262, 263, 264, 265, 266,
+ 146, 252, 361, 467, 151, 257, 366, 472, 148, 254,
+ 363, 469, 149, 255, 364, 470, 156, 371, 150, 256,
+ 365, 471, 147, 253, 362, 468, 52, 2, 1, 157,
+ 372, 267, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 268, 31, 152, 153, 154, 155, 258, 259, 260, 261,
+ 367, 368, 369, 370, 473, 474, 475, 476, 158, 373,
+ 9, 33, 11, 159, 374, 54, 269, 28, 27, 160,
+ 375, 34, 35, 29, 46, 32, 30, 55, 270, 37,
+ 36, 39, 38, 40, 161, 376, 41, 42, 43, 44,
+ 45, 56, 162, 271, 377, 185, 196, 174, 79, 57,
+ 411, 90, 163, 305, 389, 378, 283, 68, 187, 400,
+ 294, 198, 307, 92, 70, 186, 413, 176, 59, 91,
+ 58, 412, 380, 165, 81, 164, 272, 175, 80, 401,
+ 402, 390, 391, 197, 306, 69, 274, 273, 379, 285,
+ 296, 284, 295, 188, 60, 199, 82, 93, 71, 381,
+ 414, 177, 166, 456, 308, 403, 98, 76, 286, 61,
+ 275, 386, 135, 423, 171, 102, 392, 204, 87, 182,
+ 65, 94, 208, 124, 72, 350, 193, 313, 393, 408,
+ 445, 309, 230, 419, 297, 241, 113, 219, 189, 128,
+ 317, 415, 116, 328, 200, 339, 382, 434, 178, 64,
+ 404, 83, 437, 223, 134, 192, 444, 112, 439, 139,
+ 287, 167, 448, 212, 459, 222, 240, 233, 97, 302,
+ 397, 234, 170, 276, 181, 455, 229, 438, 101, 280,
+ 138, 127, 298, 117, 355, 203, 426, 95, 140, 244,
+ 422, 407, 213, 129, 291, 354, 105, 245, 449, 86,
+ 316, 460, 207, 353, 190, 107, 224, 427, 342, 327,
+ 106, 321, 118, 123, 73, 211, 433, 218, 396, 385,
+ 450, 62, 383, 349, 75, 461, 172, 331, 168, 246,
+ 428, 332, 312, 201, 343, 416, 279, 63, 195, 333,
+ 96, 173, 235, 288, 320, 191, 418, 84, 205, 100,
+ 67, 394, 179, 344, 206, 338, 277, 405, 388, 395,
+ 301, 315, 421, 183, 293, 322, 310, 384, 410, 194,
+ 184, 89, 99, 103, 236, 78, 88, 77, 136, 399,
+ 169, 202, 406, 125, 180, 440, 74, 387, 242, 231,
+ 66, 281, 290, 141, 314, 424, 114, 85, 130, 356,
+ 119, 299, 304, 398, 237, 409, 311, 417, 292, 457,
+ 435, 225, 214, 209, 462, 108, 282, 446, 220, 351,
+ 345, 142, 247, 329, 420, 463, 318, 300, 120, 109,
+ 289, 451, 278, 441, 340, 303, 430, 215, 323, 226,
+ 334, 131, 442, 248, 335, 357, 429, 324, 143, 346,
+ 452, 238, 110, 216, 464, 249, 121, 431, 358, 227,
+ 132, 453, 336, 425, 325, 347, 126, 104, 137, 458,
+ 352, 243, 447, 115, 341, 210, 330, 221, 232, 436,
+ 465, 319, 359, 111, 454, 228, 217, 122, 443, 348,
+ 239, 250, 133, 144, 432, 337, 326
+};
+
+static const Word16 sort_SID[35] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34
+};
+
+/* pointer table for bit sorting tables */
+static const Word16 *const sort_ptr[16] = { sort_660, sort_885, sort_1265, sort_1425, sort_1585, sort_1825, sort_1985, sort_2305,
+ sort_2385, sort_SID, NULL, NULL, NULL, NULL, NULL, NULL };
+
+/* 4 bit to 3 bit AMR-WB CMR remapping table */
+static const Word16 amrwb_3bit_cmr[16] = {
+ 0x00, /* AMRWB_660 */
+ 0x01, /* AMRWB_885 */
+ 0x02, /* AMRWB_1265 */
+ 0x05, /* AMRWB_1425 */
+ 0x03, /* AMRWB_1585 */
+ 0x06, /* AMRWB_1825 */
+ 0x06, /* AMRWB_1985 -> AMRWB_1825 */
+ 0x06, /* AMRWB_2305 -> AMRWB_1825 */
+ 0x04, /* AMRWB_2385 */
+ 0x07, /* invalid request -> none */
+ 0x07, /* invalid request -> none */
+ 0x07, /* invalid request -> none */
+ 0x07, /* invalid request -> none */
+ 0x07, /* invalid request -> none */
+ 0x07, /* invalid request -> none */
+ 0x07 /* invalid request -> none */
+};
+
+/* 3 bit to 4 bit AMR-WB CMR remapping table */
+static const Word16 amrwb_4bit_cmr[8] = {
+ 0x00, /* AMRWB_660 */
+ 0x01, /* AMRWB_885 */
+ 0x02, /* AMRWB_1265 */
+ 0x04, /* AMRWB_1585 */
+ 0x08, /* AMRWB_2385 */
+ 0x03, /* AMRWB_1425 */
+ 0x05, /* AMRWB_1825 */
+ 0x0f /* invalid */
+};
+#endif
diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c
new file mode 100644
index 0000000000000000000000000000000000000000..c0f3c56ce37faa9c270429681f8a6a0b68e2fa7b
--- /dev/null
+++ b/lib_com/modif_fs.c
@@ -0,0 +1,898 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * modify_Fs()
+ *
+ * Function for resampling of signals
+ *-------------------------------------------------------------------*/
+
+/*! r: length of output */
+int16_t modify_Fs(
+ const float sigIn[], /* i : signal to decimate */
+ const int16_t lg, /* i : length of input + 0 delay signaling */
+ const int32_t fin, /* i : frequency of input */
+ float sigOut[], /* o : decimated signal */
+ const int32_t fout, /* i : frequency of output */
+ float mem[], /* i/o: filter memory */
+ const int16_t nblp /* i : flag indicating if NB low-pass is applied */
+)
+{
+ int16_t i;
+ int16_t lg_out, fac_num, fac_den, filt_len, frac, mem_len;
+ float num_den;
+ int16_t datastep, fracstep;
+ float *sigIn_ptr;
+ float signal_tab[3 * L_FILT_MAX + L_FRAME48k], *signal, *signal_ana; /* 3* as 2* for memory and 1* for future prediction */
+ float A[M + 1], r[M + 1], epsP[M + 1], val;
+ int16_t mem_len_ana;
+ int16_t plus_sample_in;
+ int16_t j;
+ float mu_preemph;
+ float mem_preemph;
+ const Resampling_cfg *cfg_ptr;
+ int16_t flag_low_order = 0;
+ int16_t filt_len_tmp;
+
+ /*-------------------------------------------------------------------*
+ * IIR filters for resampling to/from 8 kHz
+ *-------------------------------------------------------------------*/
+
+ /*-------------------------------------------------------------------*
+ * Find the resampling configuration
+ *-------------------------------------------------------------------*/
+
+ if ( fin == fout )
+ {
+ /* just copy the signal and quit */
+ for ( i = 0; i < lg; i++ )
+ {
+ sigOut[i] = sigIn[i];
+ }
+
+ return lg;
+ }
+ else
+ {
+ /* find the resampling configuration in the lookup table */
+ for ( cfg_ptr = &resampling_cfg_tbl[0]; ( cfg_ptr->fin != 0 ) && !( cfg_ptr->fin == fin && cfg_ptr->fout == fout ); cfg_ptr++ )
+ {
+ }
+
+
+ /* find config with NB 4kHz low-pass */
+ if ( nblp && ( fin > 8000 ) && ( fout == 12800 ) )
+ {
+ flag_low_order = 1;
+ for ( cfg_ptr++; ( cfg_ptr->fin != 0 ) && !( cfg_ptr->fin == fin && cfg_ptr->fout == fout ); cfg_ptr++ )
+ {
+ }
+ }
+
+#define WMC_TOOL_SKIP
+ /* Retrieve and/or calculate the resampling parameters */
+ fac_num = cfg_ptr->fac_num;
+ fac_den = (int16_t) ( ( cfg_ptr->fin * fac_num ) / cfg_ptr->fout );
+ lg_out = ( lg * fac_num ) / fac_den;
+ filt_len = cfg_ptr->filt_len;
+
+ mem_len = 2 * filt_len;
+ plus_sample_in = 0; /* default, regular delay */
+ frac = 0;
+
+ if ( fin == 8000 && fout == 12800 )
+ {
+ plus_sample_in = 7;
+ frac = 4;
+ }
+
+ signal = signal_tab + 2 * L_FILT_MAX + L_FRAME48k - mem_len - lg;
+ signal_ana = signal;
+ mem_len_ana = mem_len;
+#undef WMC_TOOL_SKIP
+ }
+
+ /*-------------------------------------------------------------------*
+ * FIR filters for resampling to/from 12.8, 16, 32, 48 kHz
+ *-------------------------------------------------------------------*/
+
+ /* append filter memory */
+ for ( i = 0; i < 2 * filt_len; i++ )
+ {
+ signal[i] = mem[i];
+ }
+
+ for ( i = 0; i < lg; i++ )
+ {
+ signal[i + ( 2 * filt_len )] = sigIn[i];
+ }
+
+ if ( plus_sample_in > 0 )
+ {
+ autocorr( signal_ana + mem_len_ana + lg - LEN_WIN_SSS, r, 1, LEN_WIN_SSS, wind_sss, 0, 0, 0 );
+
+ mu_preemph = r[1] / r[0];
+ mem_preemph = signal_ana[mem_len_ana + lg - LEN_WIN_SSS - 1];
+ preemph( signal_ana + mem_len_ana + lg - LEN_WIN_SSS, mu_preemph, LEN_WIN_SSS, &mem_preemph );
+
+ /* Autocorrelations */
+ autocorr( signal_ana + mem_len_ana + lg - LEN_WIN_SSS, r, M, LEN_WIN_SSS, wind_sss, 0, 0, 0 );
+
+ lag_wind( r, M, fin, LAGW_STRONG );
+
+ /* Levinson-Durbin */
+ lev_dur( A, r, M, epsP );
+
+ for ( i = 0; i < plus_sample_in; i++ )
+ {
+ val = 0;
+ for ( j = 1; j <= M; j++ )
+ {
+ val -= signal[i + lg + mem_len - j] * A[j];
+ }
+ signal[i + lg + mem_len] = val; /* AZ ringing padding */
+ }
+
+ mem_preemph = signal[mem_len + lg - LEN_WIN_SSS - 1];
+ deemph( signal + mem_len + lg - LEN_WIN_SSS, mu_preemph, LEN_WIN_SSS + plus_sample_in, &mem_preemph );
+ }
+
+ /* interpolation */
+ datastep = fac_den / fac_num;
+ fracstep = fac_den - datastep * fac_num; /* equivalent to datastep = fac_den % fac_num */
+
+ sigIn_ptr = signal + filt_len + plus_sample_in;
+
+ filt_len_tmp = filt_len;
+ if ( flag_low_order )
+ {
+ filt_len_tmp = ( filt_len + 1 ) >> 1;
+ }
+
+ for ( i = 0; i < lg_out; i++ )
+ {
+ sigOut[i] = interpolation( sigIn_ptr, cfg_ptr->filter, frac, fac_num, filt_len_tmp );
+
+ frac = frac + fracstep;
+ if ( frac >= fac_num )
+ {
+ frac = frac - fac_num;
+ sigIn_ptr++;
+ }
+
+ sigIn_ptr += datastep;
+ }
+
+ /* rescaling */
+ if ( ( fac_num > fac_den ) == ( ( cfg_ptr->flags & RS_INV_FAC ) != 0 ) )
+ {
+ num_den = (float) fac_num / fac_den;
+
+ for ( i = 0; i < lg_out; i++ )
+ {
+ sigOut[i] *= num_den;
+ }
+ }
+
+ /* update the filter memory */
+ for ( i = 0; i < 2 * filt_len; i++ )
+ {
+ mem[i] = signal[i + lg];
+ }
+
+ return lg_out;
+}
+
+/*-------------------------------------------------------------------*
+ * modify_Fs_intcub3m_sup()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+/*! r: length of output */
+int16_t modify_Fs_intcub3m_sup(
+ const float sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */
+ const int16_t 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 int32_t fin, /* i : frequency of input */
+ float sigOut[], /* o : decimated signal */
+ const int32_t fout, /* i : frequency of output */
+ int16_t *delayout /* o : delay of output */
+)
+{
+ int16_t i, j, k, i1, i2, k1, k2, k3, kk, cind;
+ int16_t lg_out, fk1, k2d, k3d;
+ float cc[4][4];
+ float vv;
+ const double( *cu )[3] = 0;
+
+ /*-------------------------------------------------------------------*
+ * Find the resampling configuration
+ *-------------------------------------------------------------------*/
+
+ /* check if fin and fout are the same */
+ if ( fin == fout )
+ {
+ /* just copy the signal and quit */
+ for ( i = 0; i < lg; i++ )
+ {
+ sigOut[i] = sigIn[i];
+ }
+
+ *delayout = 0;
+ return lg;
+ }
+ else
+ {
+ /* length of the interpolated signal */
+ lg_out = (int16_t) ( lg * fout / fin );
+
+ /* cc[x][3]*s*s*s + cc[x][2]*s*s + cc[x][1]*s + cc[x][0]; indexes relatives of s : -1 0 1 2 */
+ /* d : cc[x][0] = s[0] */
+ /* b : cc[x][2] =(s[-1]+s[1])/2-s[0] */
+ /* a : cc[x][3] = (s[-1]+s[2]-s[0]-s[1]-4*cc[x][2]) / 6 */
+ /* c : cc[x][1] = s[1]-s[0]-cc[x][3]-cc[x][2] */
+
+ /* coef inits using memory (indexes < 0) */
+ /* cc[2][] : indexes -2 -1 0 1 */
+ cc[2][0] = sigIn[-1] / 3;
+ cc[2][2] = ( sigIn[-2] + sigIn[0] ) / 2 - sigIn[-1];
+ cc[2][3] = ( sigIn[-2] + sigIn[1] - sigIn[-1] - sigIn[0] - 4 * cc[2][2] ) / 6;
+ cc[2][1] = sigIn[0] - sigIn[-1] - cc[2][3] - cc[2][2];
+
+ /* cc[3][] : indexes -1 0 1 2 */
+ cc[3][0] = sigIn[0] / 3;
+ cc[3][2] = ( sigIn[-1] + sigIn[1] ) / 2 - sigIn[0];
+ cc[3][3] = ( sigIn[-1] + sigIn[2] - sigIn[0] - sigIn[1] - 4 * cc[3][2] ) / 6;
+ cc[3][1] = sigIn[1] - sigIn[0] - cc[3][3] - cc[3][2];
+ j = 0;
+
+ if ( fin == 12800 )
+ {
+ if ( fout == 8000 )
+ {
+ cind = 0;
+ }
+ else if ( fout == 16000 )
+ {
+ cind = 1;
+ }
+ else if ( fout == 32000 )
+ {
+ cind = 2;
+ }
+ else if ( fout == 48000 )
+ {
+ cind = 3;
+ }
+ else
+ {
+ printf( "warning, output sampling frequency %d not implemented for input %d", fout, fin );
+ return ( -1 );
+ }
+ }
+ else if ( fin == 16000 )
+ {
+ if ( fout == 12800 )
+ {
+ cind = 4;
+ }
+ else if ( fout == 32000 )
+ {
+ cind = 5;
+ }
+ else if ( fout == 48000 )
+ {
+ cind = 6;
+ }
+ else
+ {
+ printf( "warning, output sampling frequency %d not implemented for input %d", fout, fin );
+ return ( -1 );
+ }
+ }
+ else
+ {
+ printf( "warning, input sampling frequency %d not implemented", fin );
+ return ( -1 );
+ }
+
+ *delayout = ct2[cind][9];
+
+ if ( ct2[cind][12] == 15 )
+ {
+ cu = cu15;
+ }
+
+ if ( ct2[cind][12] == 4 )
+ {
+ cu = cu4;
+ }
+
+ fk1 = 2 * ct2[cind][12] - 2;
+ k2d = fk1 / 2; /* shift of index in cu with respect to the next sample (ex 1.25 -> 0.25 ) */
+ k3d = fk1 - 1; /* to compurte index in cu with respect to the last sample with - sign (ex 1.25 -> -0.75 ) */
+
+ kk = 0;
+ for ( i = 0; i < lg - ct2[cind][11]; )
+ {
+ sigOut[j++] = sigIn[i];
+ for ( k = 0; k < ct2[cind][10]; k++ )
+ {
+ cc[kk][0] = sigIn[i + 1] / 3;
+ cc[kk][2] = ( sigIn[i] + sigIn[i + 2] ) / 2 - sigIn[i + 1];
+ cc[kk][3] = ( sigIn[i] + sigIn[i + 3] - sigIn[i + 1] - sigIn[i + 2] - 4 * cc[kk][2] ) / 6;
+ cc[kk][1] = sigIn[i + 2] - sigIn[i + 1] - cc[kk][3] - cc[kk][2];
+ i++;
+
+ i2 = kk - 2;
+ i1 = kk - 1;
+ if ( i1 < 0 )
+ {
+ i1 += 4;
+ }
+
+ if ( i2 < 0 )
+ {
+ i2 += 4;
+ }
+
+ for ( k1 = ct2[cind][k]; k1 < fk1; k1 += ct2[cind][8] )
+ {
+ k2 = k1 - k2d;
+ k3 = k3d - k1;
+ vv = (float) ( cu[k1][2] * cc[i2][3] + cu[k1][1] * cc[i2][2] + cu[k1][0] * cc[i2][1] + cc[i2][0] );
+ vv += (float) ( cu[k2][2] * cc[i1][3] + cu[k2][1] * cc[i1][2] + cu[k2][0] * cc[i1][1] + cc[i1][0] );
+ vv += (float) ( -cu[k3][2] * cc[kk][3] + cu[k3][1] * cc[kk][2] - cu[k3][0] * cc[kk][1] + cc[kk][0] );
+ sigOut[j++] = vv;
+ }
+
+ kk++;
+ if ( kk == 4 )
+ {
+ kk = 0;
+ }
+ }
+ }
+
+ sigOut[j++] = sigIn[i];
+
+ for ( k = 0; k < ct2[cind][11] - 3; k++ )
+ {
+ cc[kk][0] = sigIn[i + 1] / 3;
+ cc[kk][2] = ( sigIn[i] + sigIn[i + 2] ) / 2 - sigIn[i + 1];
+ cc[kk][3] = ( sigIn[i] + sigIn[i + 3] - sigIn[i + 1] - sigIn[i + 2] - 4 * cc[kk][2] ) / 6;
+ cc[kk][1] = sigIn[i + 2] - sigIn[i + 1] - cc[kk][3] - cc[kk][2];
+ i++;
+
+ i2 = kk - 2;
+ i1 = kk - 1;
+ if ( i1 < 0 )
+ {
+ i1 += 4;
+ }
+
+ if ( i2 < 0 )
+ {
+ i2 += 4;
+ }
+
+ for ( k1 = ct2[cind][k]; k1 < fk1; k1 += ct2[cind][8] )
+ {
+ k2 = k1 - k2d;
+ k3 = k3d - k1;
+ vv = (float) ( cu[k1][2] * cc[i2][3] + cu[k1][1] * cc[i2][2] + cu[k1][0] * cc[i2][1] + cc[i2][0] );
+ vv += (float) ( cu[k2][2] * cc[i1][3] + cu[k2][1] * cc[i1][2] + cu[k2][0] * cc[i1][1] + cc[i1][0] );
+ vv += (float) ( -cu[k3][2] * cc[kk][3] + cu[k3][1] * cc[kk][2] - cu[k3][0] * cc[kk][1] + cc[kk][0] );
+ sigOut[j++] = vv;
+ }
+
+ kk++;
+
+ if ( kk == 4 )
+ {
+ kk = 0;
+ }
+ }
+
+ kk--;
+ if ( kk == -1 )
+ {
+ kk = 3;
+ }
+
+ if ( ct2[cind][10] == 1 )
+ {
+ sigOut[j++] = sigIn[i];
+ }
+
+ for ( k1 = ct2[cind][k]; k1 < fk1; k1 += ct2[cind][8] )
+ {
+ k2 = k1 - k2d;
+ vv = (float) ( cu[k2][2] * cc[kk][3] + cu[k2][1] * cc[kk][2] + cu[k2][0] * cc[kk][1] + cc[kk][0] );
+ sigOut[j++] = vv * 3;
+ }
+
+ if ( ct2[cind][10] < 3 )
+ {
+ sigOut[j++] = sigIn[i + 1];
+ }
+
+ for ( k1 = ct2[cind][k + 1]; k1 < fk1; k1 += ct2[cind][8] )
+ {
+ vv = (float) ( cu[k1][2] * cc[kk][3] + cu[k1][1] * cc[kk][2] + cu[k1][0] * cc[kk][1] + cc[kk][0] );
+ sigOut[j++] = vv * 3;
+ }
+
+ if ( ct2[cind][10] == 1 )
+ {
+ sigOut[j++] = sigIn[i + 2];
+ }
+ }
+
+ return lg_out;
+}
+
+/*-------------------------------------------------------------------*
+ * Interpolate_allpass_steep()
+ *
+ * Interpolation by a factor 2
+ *-------------------------------------------------------------------*/
+
+void Interpolate_allpass_steep(
+ const float *in, /* i : input array of size N */
+ float *mem, /* i/o: memory */
+ const int16_t N, /* i : number of input samples */
+ float *out /* o : output array of size 2*N */
+)
+{
+ int16_t n, k;
+ float temp[ALLPASSSECTIONS_STEEP - 1];
+
+ /* upper allpass filter chain */
+ for ( k = 0; k < N; k++ )
+ {
+ temp[0] = mem[0] + AP2_STEEP[0] * in[k];
+ mem[0] = in[k] - AP2_STEEP[0] * temp[0];
+
+ /* for better performance, unroll this loop */
+ for ( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ )
+ {
+ temp[n] = mem[n] + AP2_STEEP[n] * temp[n - 1];
+ mem[n] = temp[n - 1] - AP2_STEEP[n] * temp[n];
+ }
+
+ out[2 * k + 1] = mem[ALLPASSSECTIONS_STEEP - 1] + AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] * temp[ALLPASSSECTIONS_STEEP - 2];
+ mem[ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] * out[2 * k + 1];
+ }
+
+ /* lower allpass filter chain */
+ for ( k = 0; k < N; k++ )
+ {
+ temp[0] = mem[ALLPASSSECTIONS_STEEP] + AP1_STEEP[0] * in[k];
+ mem[ALLPASSSECTIONS_STEEP] = in[k] - AP1_STEEP[0] * temp[0];
+
+ /* for better performance, unroll this loop */
+ for ( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ )
+ {
+ temp[n] = mem[ALLPASSSECTIONS_STEEP + n] + AP1_STEEP[n] * temp[n - 1];
+ mem[ALLPASSSECTIONS_STEEP + n] = temp[n - 1] - AP1_STEEP[n] * temp[n];
+ }
+
+ out[2 * k] = mem[2 * ALLPASSSECTIONS_STEEP - 1] + AP1_STEEP[ALLPASSSECTIONS_STEEP - 1] * temp[ALLPASSSECTIONS_STEEP - 2];
+ mem[2 * ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP1_STEEP[ALLPASSSECTIONS_STEEP - 1] * out[2 * k];
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * Decimate_allpass_steep()
+ *
+ * Decimation by a factor 2
+ *-------------------------------------------------------------------*/
+
+void Decimate_allpass_steep(
+ const float *in, /* i : input array of size N */
+ float *mem, /* i/o: memory */
+ const int16_t N, /* i : number of input samples */
+ float *out /* o : output array of size N/2 */
+)
+{
+ int16_t n, k;
+ float temp[ALLPASSSECTIONS_STEEP];
+
+ /* upper allpass filter chain */
+ for ( k = 0; k < N / 2; k++ )
+ {
+ temp[0] = mem[0] + AP1_STEEP[0] * in[2 * k];
+ mem[0] = in[2 * k] - AP1_STEEP[0] * temp[0];
+
+ /* for better performance, unroll this loop */
+ for ( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ )
+ {
+ temp[n] = mem[n] + AP1_STEEP[n] * temp[n - 1];
+ if ( fabs( temp[n] ) < 1e-12 )
+ {
+ temp[n] = sign( temp[n] ) * 1e-12f;
+ }
+ mem[n] = temp[n - 1] - AP1_STEEP[n] * temp[n];
+ }
+
+ out[k] = mem[ALLPASSSECTIONS_STEEP - 1] + AP1_STEEP[ALLPASSSECTIONS_STEEP - 1] * temp[ALLPASSSECTIONS_STEEP - 2];
+ mem[ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP1_STEEP[ALLPASSSECTIONS_STEEP - 1] * out[k];
+ }
+
+ /* lower allpass filter chain */
+ temp[0] = mem[ALLPASSSECTIONS_STEEP] + AP2_STEEP[0] * mem[2 * ALLPASSSECTIONS_STEEP];
+ mem[ALLPASSSECTIONS_STEEP] = mem[2 * ALLPASSSECTIONS_STEEP] - AP2_STEEP[0] * temp[0];
+
+ /* for better performance, unroll this loop */
+ for ( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ )
+ {
+ temp[n] = mem[ALLPASSSECTIONS_STEEP + n] + AP2_STEEP[n] * temp[n - 1];
+ if ( fabs( temp[n] ) < 1e-12 )
+ {
+ temp[n] = sign( temp[n] ) * 1e-12f;
+ }
+ mem[ALLPASSSECTIONS_STEEP + n] = temp[n - 1] - AP2_STEEP[n] * temp[n];
+ }
+
+ temp[ALLPASSSECTIONS_STEEP - 1] = mem[2 * ALLPASSSECTIONS_STEEP - 1] + AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] *
+ temp[ALLPASSSECTIONS_STEEP - 2];
+
+ mem[2 * ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] *
+ temp[ALLPASSSECTIONS_STEEP - 1];
+ out[0] = (float) ( ( out[0] + temp[ALLPASSSECTIONS_STEEP - 1] ) * 0.5 );
+
+ for ( k = 1; k < N / 2; k++ )
+ {
+ temp[0] = mem[ALLPASSSECTIONS_STEEP] + AP2_STEEP[0] * in[2 * k - 1];
+ mem[ALLPASSSECTIONS_STEEP] = in[2 * k - 1] - AP2_STEEP[0] * temp[0];
+
+ /* for better performance, unroll this loop */
+ for ( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ )
+ {
+ temp[n] = mem[ALLPASSSECTIONS_STEEP + n] + AP2_STEEP[n] * temp[n - 1];
+ if ( fabs( temp[n] ) < 1e-12 )
+ {
+ temp[n] = sign( temp[n] ) * 1e-12f;
+ }
+ mem[ALLPASSSECTIONS_STEEP + n] = temp[n - 1] - AP2_STEEP[n] * temp[n];
+ }
+
+ temp[ALLPASSSECTIONS_STEEP - 1] = mem[2 * ALLPASSSECTIONS_STEEP - 1] + AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] *
+ temp[ALLPASSSECTIONS_STEEP - 2];
+ mem[2 * ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] *
+ temp[ALLPASSSECTIONS_STEEP - 1];
+ out[k] = (float) ( ( out[k] + temp[ALLPASSSECTIONS_STEEP - 1] ) * 0.5 );
+ }
+
+ /* z^(-1) */
+ mem[2 * ALLPASSSECTIONS_STEEP] = in[N - 1];
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * interpolate_3_over_2_allpass()
+ *
+ * Interpolate 3/2 using allpass iir polyphase filter. Delay 4 samples @48k
+ *-------------------------------------------------------------------*/
+
+void interpolate_3_over_2_allpass(
+ const float *input, /* i : input signal */
+ const int16_t len, /* i : number of input samples */
+ float *out, /* o : output signal */
+ float *mem /* i/o: memory */
+)
+{
+ int16_t i, loop_len;
+ float Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */
+ float out1_buff[L_FRAME32k * 3];
+ float *out1;
+ float mem_temp;
+ const float *filt_coeff = allpass_poles_3_ov_2;
+
+ out1 = out1_buff;
+
+ for ( i = 0; i < len; i++ )
+ {
+ /* Upper branch */
+ Vu[0] = mem[0] + filt_coeff[0] * ( input[i] - mem[1] );
+ Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] );
+ mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] );
+
+ mem[1] = Vu[0];
+ mem[2] = Vu[1];
+ *out1++ = mem[3];
+
+ /* Middle branch */
+ Vm[0] = mem[0] + filt_coeff[3] * ( input[i] - mem[4] );
+ Vm[1] = mem[4] + filt_coeff[4] * ( Vm[0] - mem[5] );
+ mem[6] = mem[5] + filt_coeff[5] * ( Vm[1] - mem[6] );
+
+ mem[4] = Vm[0];
+ mem[5] = Vm[1];
+ *out1++ = mem[6];
+
+ /* Lower branch */
+ Vl[0] = mem[0] + filt_coeff[6] * ( input[i] - mem[7] );
+ Vl[1] = mem[7] + filt_coeff[7] * ( Vl[0] - mem[8] );
+ mem[9] = mem[8] + filt_coeff[8] * ( Vl[1] - mem[9] );
+
+ mem[0] = input[i];
+ mem[7] = Vl[0];
+ mem[8] = Vl[1];
+ *out1++ = mem[9];
+ }
+
+ loop_len = len * 3 / 2;
+
+ /*decimate by 2 and LPF*/
+ for ( i = 0; i < loop_len; i++ )
+ {
+ mem_temp = out1_buff[2 * i];
+ out[i] = ( ( ( 0.0473147f ) * ( mem_temp + mem[10] ) ) + ( ( -0.151521f ) * ( mem[11] + mem[14] ) ) );
+ out[i] = ( out[i] + ( ( 0.614152f ) * ( mem[12] + mem[13] ) ) );
+ mem[10] = mem[11];
+ mem[11] = mem[12];
+ mem[12] = mem[13];
+ mem[13] = mem[14];
+ mem[14] = mem_temp;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * decimate_2_over_3_allpass()
+ *
+ * Decimate 2/3 using allpass iir polyphase filter.
+ *-------------------------------------------------------------------*/
+
+void decimate_2_over_3_allpass(
+ const float *input, /* i : input signal */
+ const int16_t len, /* i : number of input samples */
+ float *out, /* o : output signal */
+ float *mem, /* i/o: memory */
+ float *lp_mem /* i/o: memory */
+)
+{
+ int16_t i, loop_len;
+ float Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */
+ float *out1;
+ float *in;
+ float out1_buff[L_FRAME48k * 2];
+ float tmp;
+ const float *filt_coeff = allpass_poles_3_ov_2;
+ const float *lp_num = decimate_3_ov_2_lowpass_num;
+ const float *lp_den = decimate_3_ov_2_lowpass_den;
+
+ /* Combine the 2nd order iir lpf with the decimation by 2 to improve the efficiency*/
+ out1 = out1_buff;
+
+ *out1++ = lp_num[0] * ( input[0] + lp_mem[0] ) - lp_den[2] * lp_mem[2];
+ *out1++ = lp_num[1] * input[0] - lp_den[2] * lp_mem[1];
+
+ for ( i = 1; i < len; i++ )
+ {
+ tmp = lp_num[0] * ( input[i] + input[i - 1] ) - lp_den[2] * out1[-2];
+ *out1++ = tmp;
+ tmp = lp_num[1] * input[i] - lp_den[2] * out1[-2];
+ *out1++ = tmp;
+ }
+ lp_mem[0] = input[len - 1];
+ lp_mem[1] = out1[-1];
+ lp_mem[2] = out1[-2];
+
+ /* do the all pass polyphase filter with pi/3 cutoff */
+ out1 = out;
+ in = out1_buff;
+ loop_len = (int16_t) len * 2 / 3;
+
+ for ( i = 0; i < loop_len; i++ )
+ {
+ /* Lower branch */
+ Vl[0] = mem[8] + filt_coeff[6] * ( *in - mem[9] );
+ Vl[1] = mem[9] + filt_coeff[7] * ( Vl[0] - mem[10] );
+ mem[11] = mem[10] + filt_coeff[8] * ( Vl[1] - mem[11] );
+
+ mem[8] = *in++;
+ mem[9] = Vl[0];
+ mem[10] = Vl[1];
+ *out1 = mem[11];
+
+ /* Middle branch */
+ Vm[0] = mem[4] + filt_coeff[3] * ( *in - mem[5] );
+ Vm[1] = mem[5] + filt_coeff[4] * ( Vm[0] - mem[6] );
+ mem[7] = mem[6] + filt_coeff[5] * ( Vm[1] - mem[7] );
+
+ mem[4] = *in++;
+ mem[5] = Vm[0];
+ mem[6] = Vm[1];
+ *out1 += mem[7];
+
+ /* Upper branch */
+ Vu[0] = mem[0] + filt_coeff[0] * ( *in - mem[1] );
+ Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] );
+ mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] );
+
+ mem[0] = *in++;
+ mem[1] = Vu[0];
+ mem[2] = Vu[1];
+ *out1++ += mem[3];
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * interpolate_3_over_1_allpass()
+ *
+ * Interpolate 3/1 using allpass iir polyphase filter. Delay 4 samples @48k
+ *-------------------------------------------------------------------*/
+
+void interpolate_3_over_1_allpass(
+ const float *input, /* i : input signal */
+ const int16_t len, /* i : number of input samples */
+ float *out, /* o : output signal */
+ float *mem /* i/o: memory */
+)
+{
+ int16_t i;
+ float Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */
+ float *out1;
+ float mem_temp;
+ const float *filt_coeff = allpass_poles_3_ov_2;
+
+ out1 = &out[0];
+
+ for ( i = 0; i < len; i++ )
+ {
+ /* Upper branch */
+ Vu[0] = mem[0] + filt_coeff[0] * ( input[i] - mem[1] );
+ Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] );
+ mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] );
+
+ mem[1] = Vu[0];
+ mem[2] = Vu[1];
+ *out1++ = mem[3];
+
+ /* Middle branch */
+ Vm[0] = mem[0] + filt_coeff[3] * ( input[i] - mem[4] );
+ Vm[1] = mem[4] + filt_coeff[4] * ( Vm[0] - mem[5] );
+ mem[6] = mem[5] + filt_coeff[5] * ( Vm[1] - mem[6] );
+
+ mem[4] = Vm[0];
+ mem[5] = Vm[1];
+ *out1++ = mem[6];
+
+ /* Lower branch */
+ Vl[0] = mem[0] + filt_coeff[6] * ( input[i] - mem[7] );
+ Vl[1] = mem[7] + filt_coeff[7] * ( Vl[0] - mem[8] );
+ mem[9] = mem[8] + filt_coeff[8] * ( Vl[1] - mem[9] );
+
+ mem[0] = input[i];
+ mem[7] = Vl[0];
+ mem[8] = Vl[1];
+ *out1++ = mem[9];
+ }
+
+ /*LPF*/
+ for ( i = 0; i < len * 3; i++ )
+ {
+ mem_temp = out[i];
+ out[i] = ( ( ( 0.572769f ) * ( mem[12] + mem[11] ) ) - ( ( 0.074005f ) * ( mem_temp + mem[10] ) ) );
+ mem[10] = mem[11];
+ mem[11] = mem[12];
+ mem[12] = mem_temp;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * retro_interp4_5()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void retro_interp4_5(
+ const float *syn,
+ float *pst_old_syn )
+{
+ float *pf5, *pf4;
+ int16_t c;
+
+ /* resample st->pst_old_syn in a reverse way to preserve time-alignment */
+ pf4 = (float *) &pst_old_syn[58];
+ pf5 = (float *) pst_old_syn;
+ for ( c = 0; c < 57; c++ )
+ {
+ *pf5++ = pf4[0];
+ *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1];
+ *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2];
+ *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3];
+ *pf5++ = 0.8f * pf4[3] + 0.2f * pf4[4];
+ pf4 += 4;
+ }
+ *pf5++ = pf4[0];
+ *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1];
+ *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2];
+ *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3];
+ *pf5++ = 0.8f * pf4[3] + 0.2f * syn[0];
+ /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * retro_interp5_4()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void retro_interp5_4(
+ float *pst_old_syn )
+{
+ float *pf5, *pf4;
+ int16_t c;
+
+ /* resample st->pst_old_syn in a reverse way to preserve time-alignment */
+ pf4 = (float *) &pst_old_syn[NBPSF_PIT_MAX - 1];
+ pf5 = pf4;
+ for ( c = 0; c < 58; c++ )
+ {
+ *pf4-- = 0.75f * pf5[0] + 0.25f * pf5[-1];
+ *pf4-- = 0.50f * pf5[-1] + 0.50f * pf5[-2];
+ *pf4-- = 0.25f * pf5[-2] + 0.75f * pf5[-3];
+ *pf4-- = pf5[-4];
+ pf5 -= 5;
+ }
+ /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */
+
+ return;
+}
diff --git a/lib_com/move.h b/lib_com/move.h
new file mode 100644
index 0000000000000000000000000000000000000000..c7bee82cd41d3669da2a06759116db869ce61c29
--- /dev/null
+++ b/lib_com/move.h
@@ -0,0 +1,74 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 _MOVE_H
+#define _MOVE_H
+
+/* BASOP -> FLC brigde: data move counting */
+
+#include "stl.h"
+
+static __inline void move16( void )
+{
+}
+
+static __inline void move32( void )
+{
+}
+
+static __inline void test( void )
+{
+}
+
+static __inline void logic16( void )
+{
+}
+
+static __inline void logic32( void )
+{
+}
+
+
+/*-------- legacy ----------*/
+#define data_move() move16()
+#define L_data_move() move32()
+#define data_move_external() move16()
+#define compare_zero() test()
+/*-------- end legacy ----------*/
+
+#define cast16 move16
+
+#endif /* _MOVE_H */
diff --git a/lib_com/mslvq_com.c b/lib_com/mslvq_com.c
new file mode 100644
index 0000000000000000000000000000000000000000..48384794aa4f882d3d0eaaa861ca9de8c66cd931
--- /dev/null
+++ b/lib_com/mslvq_com.c
@@ -0,0 +1,847 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+#include "ivas_prot.h"
+
+/*-----------------------------------------------------------------*
+ * Local function prototypes
+ *-----------------------------------------------------------------*/
+
+static void decode_comb( Word32 index, float *cv, int16_t idx_lead );
+
+static void decode_sign_pc1( float *c, int16_t idx_sign, const int16_t parity );
+
+static void put_value( float *cv, int16_t *p, float val, const int16_t dim, const int16_t no_new_val );
+
+static void decode_leaders( Word32 index, int16_t idx_lead, float *cv );
+
+static void idx2c( int16_t n, int16_t *p, const int16_t k, Word32 val );
+
+static void divide_64_32( int16_t *x, UWord32 y, UWord32 *result, UWord32 *rem );
+
+
+/*-----------------------------------------------------------------*
+ * permute()
+ * used in CNG-LP coding
+ *-----------------------------------------------------------------*/
+
+void permute(
+ float *pTmp1, /* i/o: vector whose components are to be permuted */
+ const int16_t *perm /* i : permutation info (indexes that should be interchanged), max two perms */
+)
+{
+ int16_t p1, p2;
+ float tmp;
+
+ p1 = perm[0];
+ p2 = perm[1];
+ tmp = pTmp1[p1];
+ pTmp1[p1] = pTmp1[p2];
+ pTmp1[p2] = tmp;
+ p1 = perm[2];
+
+ if ( p1 > -1 )
+ {
+ p2 = perm[3];
+ tmp = pTmp1[p1];
+ pTmp1[p1] = pTmp1[p2];
+ pTmp1[p2] = tmp;
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * make_offset_scale()
+ *
+ *-----------------------------------------------------------------*/
+
+static void make_offset_scale(
+ const UWord32 tab_no_cv[],
+ const Word8 *no_ld,
+ const int16_t no_scl,
+ UWord32 *offset_scale )
+{
+ int16_t i;
+
+ offset_scale[0] = 1;
+ for ( i = 1; i <= no_scl; i++ )
+ {
+ offset_scale[i] = offset_scale[i - 1] + tab_no_cv[(int16_t) no_ld[i - 1]];
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * decode_indexes()
+ *
+ *-----------------------------------------------------------------*/
+
+static int16_t decode_indexes(
+ int16_t *index,
+ const int16_t no_bits,
+ const float *p_scales,
+ const int16_t prediction_flag,
+ float *x_lvq,
+ const int16_t mode_glb )
+{
+ UWord32 index1 = 0, index2, idx_scale;
+ uint16_t i;
+ float scale;
+
+ int16_t len_scales = MAX_NO_SCALES * 2;
+ UWord32 offset_scale1[MAX_NO_SCALES + 1], offset_scale2[MAX_NO_SCALES + 1];
+
+ if ( no_bits <= 2 * LEN_INDICE ) /* the third short is not used */
+ {
+ index[2] = 0;
+ if ( no_bits <= LEN_INDICE )
+ {
+ index[1] = 0;
+ }
+ }
+
+ /* safety check in case of bit errors */
+ for ( i = 0; i < 3; i++ )
+ {
+ if ( index[i] < 0 )
+ {
+ set_f( x_lvq, 0.0f, 2 * LATTICE_DIM );
+ index[i] = 0;
+ return 1;
+ }
+ }
+
+ create_offset( offset_scale1, offset_scale2, mode_glb, prediction_flag );
+ /* first subvector */
+ if ( offset_scale2[MAX_NO_SCALES - 1] > 0 )
+ {
+ divide_64_32( index, offset_scale2[MAX_NO_SCALES], &index1, &index2 );
+ }
+ else
+ {
+ index1 = (UWord32) ( index[0] ); /* this is for very low bitrates, so there is no loss in truncation */
+ index2 = 0;
+ }
+
+ if ( index1 == 0 )
+ {
+ for ( i = 0; i < LATTICE_DIM; i++ )
+ {
+ x_lvq[i] = 0.0;
+ }
+ }
+ else
+ {
+ if ( index1 >= offset_scale1[MAX_NO_SCALES] )
+ {
+ /* safety check in case of bit errors */
+ set_f( x_lvq, 0.0f, 2 * LATTICE_DIM );
+ return 1;
+ }
+
+ /* find idx_scale */
+ i = 1;
+ while ( (int16_t) i <= MAX_NO_SCALES && index1 >= offset_scale1[i] )
+ {
+ i++;
+ }
+
+ idx_scale = i - 1;
+ index1 -= offset_scale1[idx_scale];
+
+ /* find idx_leader */
+ i = 1;
+ while ( index1 >= table_no_cv[i] )
+ {
+ i++;
+ }
+ decode_comb( (Word32) ( index1 - table_no_cv[i - 1] ), x_lvq, i - 1 );
+ scale = p_scales[mode_glb * len_scales + idx_scale];
+ for ( i = 0; i < LATTICE_DIM; i++ )
+ {
+ x_lvq[i] *= scale;
+ }
+ }
+
+ /* second subvector */
+ if ( index2 == 0 )
+ {
+ for ( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ )
+ {
+ x_lvq[i] = 0.0;
+ }
+ }
+ else
+ {
+
+ /* find the index for the scale/truncation */
+ i = 1;
+ while ( index2 >= offset_scale2[i] )
+ {
+ i++;
+ }
+
+ idx_scale = i - 1;
+ index2 -= offset_scale2[idx_scale];
+ /* find the index of the leader vector */
+ i = 1;
+ while ( index2 >= table_no_cv[i] )
+ {
+ i++;
+ }
+ decode_comb( (Word32) ( index2 - table_no_cv[i - 1] ), &x_lvq[LATTICE_DIM], i - 1 );
+
+ scale = p_scales[mode_glb * len_scales + MAX_NO_SCALES + idx_scale];
+ for ( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ )
+ {
+ x_lvq[i] *= scale;
+ }
+ }
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------*
+ * deindex_lvq()
+ *
+ *-----------------------------------------------------------------*/
+
+int16_t deindex_lvq(
+ int16_t *index, /* i : index to be decoded, as an array of 3 shorts */
+ float *x_lvq, /* o : decoded codevector */
+ const int16_t mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */
+ const int16_t sf_flag, /* i : safety net flag */
+ const int16_t no_bits /* i : number of bits for lattice */
+)
+{
+ int16_t i;
+ const float *p_scales;
+ int16_t mode_glb;
+ int16_t ber_flag;
+
+ if ( sf_flag == 1 )
+ {
+ if ( mode < 6 ) /* for NB */
+ {
+ mode_glb = offset_lvq_modes_SN[mode] + offset_in_lvq_mode_SN[mode][no_bits - min_lat_bits_SN[mode]];
+ }
+ else
+ {
+ mode_glb = offset_lvq_modes_SN[mode] + no_bits - min_lat_bits_SN[mode]; /* there is granularity of 1 bit */
+ }
+ p_scales = &scales[0][0];
+ }
+ else
+ {
+ if ( ( mode < 6 ) || ( mode == 12 ) ) /* for NB */
+ {
+ mode_glb = offset_lvq_modes_pred[mode] + offset_in_lvq_mode_pred[mode][no_bits - min_lat_bits_pred[mode]];
+ }
+ else
+ {
+ mode_glb = offset_lvq_modes_pred[mode] + no_bits - min_lat_bits_pred[mode];
+ }
+ p_scales = &scales_p[0][0];
+ }
+
+ /* decode the lattice index into the lattice codevectors for the two subvectors */
+ ber_flag = decode_indexes( index, no_bits, p_scales, 1 - sf_flag, x_lvq, mode_glb );
+
+ if ( sf_flag == 1 )
+ {
+ for ( i = 0; i < 2 * LATTICE_DIM; i++ )
+ {
+ x_lvq[i] *= sigma_MSLVQ[mode][i];
+ }
+ }
+ else
+ {
+ for ( i = 0; i < 2 * LATTICE_DIM; i++ )
+ {
+ x_lvq[i] *= sigma_p[mode][i];
+ }
+ }
+
+ return ber_flag;
+}
+
+/*------------------------------------------------------------------------------------------------------------*
+ * deindex_lvq_cng()
+ *
+ * Note:
+ * The sampling frequency for the LVQ CNG decoder frame can be determined by checking the fully decoded
+ * value of the highest order LSF coefficient. Thus sampling rate information, nor extra codebooks are
+ * not needed for deindex_lvq_cng(), since it is embedded inside the LSF codebooks.
+ *------------------------------------------------------------------------------------------------------------*/
+
+int16_t deindex_lvq_cng(
+ int16_t *index, /* i : index to be decoded, as an array of 3 shorts */
+ float *x_lvq, /* o : decoded codevector */
+ const int16_t idx_cv, /* i : relative mode_lvq, wrt START_CNG */
+ const int16_t no_bits /* i : number of bits for lattice */
+)
+{
+ int16_t i;
+ const float *p_scales;
+ int16_t mode_glb, mode;
+ int16_t ber_flag;
+
+ mode_glb = START_CNG + idx_cv;
+ mode = LVQ_COD_MODES + idx_cv;
+
+ p_scales = &scales[0][0];
+ ber_flag = decode_indexes( index, no_bits, p_scales, 0, x_lvq, mode_glb );
+
+ for ( i = 0; i < 2 * LATTICE_DIM; i++ )
+ {
+ x_lvq[i] *= sigma_MSLVQ[mode][i];
+ }
+
+ /* check if permutting needed */
+ if ( cng_sort[idx_cv] )
+ {
+ permute( x_lvq, perm_MSLVQ[idx_cv] );
+ }
+
+ return ber_flag;
+}
+
+
+/*-----------------------------------------------------------------*
+ * decode_comb()
+ *
+ * combinatorial deindexing of a codevector including the signs
+ *
+ *-----------------------------------------------------------------*/
+
+static void decode_comb(
+ Word32 index, /* i : index to be decoded */
+ float *cv, /* o : decoded codevector */
+ int16_t idx_lead /* i : leader class index */
+)
+{
+ int16_t idx_sign;
+
+ idx_sign = (int16_t) ( index / pi0[idx_lead] );
+ index -= idx_sign * pi0[idx_lead];
+ decode_leaders( index, idx_lead, cv );
+ decode_sign_pc1( cv, idx_sign, pl_par[idx_lead] );
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * decode_leaders()
+ *
+ * decode index of a codevector from the leader class idx_lead
+ *-----------------------------------------------------------------*/
+
+static void decode_leaders(
+ Word32 index, /* i : index to be decoded */
+ int16_t idx_lead, /* i : leader class index */
+ float *cv /* o : decoded codevector */
+)
+{
+ int16_t i, no_vals_loc, no_vals_last, p[LATTICE_DIM], dim_loc, n_crt;
+ Word32 index1;
+ float val_crt;
+
+ no_vals_loc = no_vals[idx_lead];
+ val_crt = vals[idx_lead][no_vals_loc - 1];
+ no_vals_last = no_vals_ind[idx_lead][no_vals_loc - 1];
+
+ for ( i = 0; i < no_vals_last; i++ )
+ {
+ cv[i] = val_crt;
+ }
+
+ val_crt = 1;
+ dim_loc = no_vals_last;
+
+ switch ( no_vals_loc )
+ {
+ case 1:
+ break;
+ case 2:
+ idx2c( LATTICE_DIM, p, no_vals_ind[idx_lead][0], index );
+ put_value( cv, p, vals[idx_lead][0], no_vals_last, no_vals_ind[idx_lead][0] );
+ break;
+ case 4:
+ dim_loc += no_vals_ind[idx_lead][2];
+ n_crt = no_vals_ind[idx_lead][2];
+ index1 = (Word32) index / C_VQ[dim_loc][n_crt];
+ index -= index1 * C_VQ[dim_loc][n_crt];
+ idx2c( dim_loc, p, n_crt, index );
+ put_value( cv, p, vals[idx_lead][2], no_vals_last, no_vals_ind[idx_lead][2] );
+ index = index1;
+ /* FALLTHRU */
+ case 3:
+ dim_loc += no_vals_ind[idx_lead][1];
+ n_crt = no_vals_ind[idx_lead][1];
+ index1 = (Word32) index / C_VQ[dim_loc][n_crt];
+ index -= index1 * C_VQ[dim_loc][n_crt];
+ idx2c( dim_loc, p, n_crt, index );
+ put_value( cv, p, vals[idx_lead][1], dim_loc - n_crt, n_crt );
+ idx2c( LATTICE_DIM, p, no_vals_ind[idx_lead][0], index1 );
+ put_value( cv, p, vals[idx_lead][0], dim_loc, no_vals_ind[idx_lead][0] );
+ break;
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * put_value()
+ *
+ * inserts no_new_val values of val in the codevector cv at the positions given by the array p
+ *-----------------------------------------------------------------*/
+
+static void put_value(
+ float *cv, /* i : input codevector */
+ int16_t *p, /* i : array with positions */
+ float val, /* i : value to be inserted */
+ const int16_t dim, /* i : vector dimension */
+ const int16_t no_new_val /* i : number of values to be inserted */
+)
+{
+ float cv_out[LATTICE_DIM];
+ int16_t i, occ[LATTICE_DIM], cnt;
+
+ for ( i = 0; i < dim + no_new_val; i++ )
+ {
+ occ[i] = 0;
+ }
+
+ for ( i = 0; i < no_new_val; i++ )
+ {
+ cv_out[p[i]] = val;
+ occ[p[i]] = 1;
+ }
+
+ cnt = 0;
+ for ( i = 0; i < dim + no_new_val; i++ )
+ {
+ if ( occ[i] == 0 )
+ {
+ cv_out[i] = cv[cnt++];
+ }
+ }
+
+ for ( i = 0; i < dim + no_new_val; i++ )
+ {
+ cv[i] = cv_out[i];
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * idx2c()
+ *
+ * decode index of binomial combinations, find the positions of k components out of n total components
+ *-----------------------------------------------------------------*/
+
+static void idx2c(
+ int16_t n, /* i : total number of positions (components) */
+ int16_t *p, /* o : array with positions of the k components */
+ const int16_t k, /* i : number of components whose position is to be determined */
+ Word32 val /* i : index to be decoded */
+)
+{
+ int16_t i, skip, pos, k1;
+
+ skip = 0;
+ pos = 0;
+ k1 = k - 1;
+ while ( skip + C_VQ[n - pos - 1][k1] - 1 < val )
+ {
+ skip += C_VQ[n - pos - 1][k1];
+ pos++;
+ }
+
+ p[0] = pos;
+ n -= pos + 1;
+ val -= skip;
+ if ( k == 1 )
+ {
+ return;
+ }
+
+ idx2c( n, p + 1, k1, val );
+
+ /* pos+1 */
+ for ( i = 1; i < k; i++ )
+ {
+ p[i] += pos + 1;
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * decode_sign_pc1()
+ *
+ *-----------------------------------------------------------------*/
+
+static void decode_sign_pc1(
+ float *c, /* o : decoded codevector */
+ int16_t idx_sign, /* i : sign index */
+ const int16_t parity /* i : parity flag (+1/-1/0) */
+)
+{
+ int16_t i, len = LATTICE_DIM, cnt_neg = 1;
+
+ if ( parity )
+ {
+ len -= 1;
+ }
+
+ for ( i = 0; i < len; i++ )
+ {
+ if ( c[i] > 0 )
+ {
+ if ( idx_sign % 2 )
+ {
+ c[i] = -c[i];
+ cnt_neg = -cnt_neg;
+ }
+ idx_sign >>= 1;
+ }
+ }
+
+ if ( len < LATTICE_DIM )
+ {
+ if ( cnt_neg != parity )
+ {
+ c[len] = -c[len];
+ }
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * extract_low()
+ *
+ * (!!!!! function for int64 !!!!)
+ *-----------------------------------------------------------------*/
+
+static UWord32 extract_low(
+ UWord32 x )
+{
+ return ( x & ( 0xffff ) );
+}
+
+/*-----------------------------------------------------------------*
+ * extract_high()
+ *
+ * (!!!!! function for int64 !!!!)
+ *-----------------------------------------------------------------*/
+
+static UWord32 extract_high(
+ UWord32 x )
+{
+ return ( x >> 16 );
+}
+
+/*-----------------------------------------------------------------*
+ * multiply32_32_64()
+ *
+ * (!!!!! function for int64 !!!!)
+ *-----------------------------------------------------------------*/
+
+void multiply32_32_64(
+ UWord32 x,
+ UWord32 y,
+ UWord32 *res )
+{
+ UWord32 tmp, x_tmp[2], y_tmp[2];
+ UWord32 high = 0;
+
+ x_tmp[0] = extract_low( x ); /* lowest 16 bits */
+ x_tmp[1] = extract_high( x );
+ y_tmp[0] = extract_low( y );
+ y_tmp[1] = extract_high( y );
+ tmp = x_tmp[0] * y_tmp[0];
+ high = extract_high( tmp );
+ res[0] = extract_low( tmp );
+ tmp = x_tmp[1] * y_tmp[0] + x_tmp[0] * y_tmp[1] + high; /* x and y are not using all 32 bits */
+ high = extract_high( tmp );
+ res[0] += ( extract_low( tmp ) << 16 );
+ tmp = x_tmp[1] * y_tmp[1] + high;
+ res[1] = tmp;
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * get_no_bits()
+ *
+ * (!!!!! function for int64 !!!!)
+ *-----------------------------------------------------------------*/
+
+static int16_t get_no_bits(
+ UWord32 x )
+{
+ int16_t nb = 0;
+
+ if ( x == 0 )
+ {
+ return 1;
+ }
+
+ while ( x > 0 )
+ {
+ x >>= 1;
+ nb++;
+ }
+
+ return nb;
+}
+
+/*-----------------------------------------------------------------*
+ * divide_64_32()
+ *
+ * (!!!!! function for int64 !!!!)
+ *-----------------------------------------------------------------*/
+
+static void divide_64_32(
+ int16_t *xs, /* i : denominator as array of two int32 */
+ UWord32 y, /* i : nominator on 32 bits */
+ UWord32 *result, /* o : integer division result on 32 bits */
+ UWord32 *rem /* o : integer division reminder on 32 bits */
+)
+{
+ int16_t nb_x1;
+ UWord32 r, q, q1, x_tmp, x[2];
+
+ x[0] = ( ( (UWord32) xs[2] & ( ( 1 << 2 ) - 1 ) ) << ( LEN_INDICE * 2 ) ) + ( xs[1] << LEN_INDICE ) + xs[0];
+ x[1] = xs[2] >> 2;
+
+ /* find number of bits of x[0] and x[1] */
+ nb_x1 = get_no_bits( x[1] );
+
+ /* take the first 32 bits */
+ if ( nb_x1 > 0 )
+ {
+ x_tmp = ( x[1] << ( 32 - nb_x1 ) ) + ( x[0] >> nb_x1 );
+ q = (UWord32) ( x_tmp / y + 0.5 );
+ r = x_tmp - q * y; /* this is the first reminder */
+ r = ( r << nb_x1 ) + ( x[0] & ( ( 1 << nb_x1 ) - 1 ) );
+
+ q1 = (UWord32) ( r / y + 0.5 );
+ *result = ( q << nb_x1 ) + q1;
+ *rem = r - q1 * y;
+ }
+ else
+ {
+ x_tmp = x[0];
+ q = ( (UWord32) ( x_tmp / y + 0.5 ) );
+ *result = q;
+ *rem = x_tmp - q * y;
+ }
+
+ return;
+}
+
+
+/*-----------------------------------------------------------------*
+ * create_offset()
+ *
+ *
+ *-----------------------------------------------------------------*/
+
+void create_offset(
+ UWord32 *offset_scale1,
+ UWord32 *offset_scale2,
+ const int16_t mode,
+ const int16_t prediction_flag )
+{
+ int16_t tmp, tmp1;
+
+ if ( prediction_flag == 0 )
+ {
+ /* safety_net */
+ tmp = no_lead_idx[mode][0];
+ if ( ( tmp <= LIMIT_LEADER ) && ( tmp < no_lead_idx[mode][1] - 2 ) )
+ {
+ tmp += DELTA_LEADER;
+ }
+ make_offset_scale( table_no_cv, leaders_short[tmp], MAX_NO_SCALES, offset_scale1 );
+ make_offset_scale( table_no_cv, leaders_short[no_lead_idx[mode][1]], MAX_NO_SCALES, offset_scale2 );
+ }
+ else
+ {
+ tmp = no_lead_p_idx[mode][0];
+ tmp1 = no_lead_p_idx[mode][1];
+ if ( ( tmp <= LIMIT_LEADER ) && ( tmp < tmp1 - 2 ) )
+ {
+ tmp += DELTA_LEADER;
+ }
+
+ if ( ( tmp == LIMIT_LEADER ) && ( tmp1 == 0 ) )
+ {
+ tmp += DELTA_LEADER;
+ tmp1 = DELTA_LEADER;
+ }
+
+ make_offset_scale( table_no_cv, leaders_short[tmp], MAX_NO_SCALES, offset_scale1 );
+ make_offset_scale( table_no_cv, leaders_short[tmp1], MAX_NO_SCALES, offset_scale2 );
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * sort_desc_ind()
+ *
+ * sorts in descending order and computes indices in the sorted vector
+ *-----------------------------------------------------------------*/
+void sort_desc_ind(
+ float *s, /* i/o: vector to be sorted */
+ const int16_t len, /* i : vector length */
+ int16_t *ind /* o : array of indices */
+)
+{
+ int16_t i, k, sorted, a;
+ float t;
+
+ for ( i = 0; i < len; i++ )
+ {
+ ind[i] = i;
+ }
+ sorted = 0;
+ for ( k = len - 1; k && !sorted; k-- )
+ {
+ sorted = 1;
+ for ( i = 0; i < k; i++ )
+ {
+ if ( s[i] < s[i + 1] )
+ {
+ sorted = 0;
+ t = s[i];
+ s[i] = s[i + 1];
+ s[i + 1] = t;
+ a = ind[i];
+ ind[i] = ind[i + 1];
+ ind[i + 1] = a;
+ }
+ }
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*
+ * deindex_lvq_SHB()
+ *
+ *
+ *-----------------------------------------------------------------*/
+
+void deindex_lvq_SHB(
+ UWord32 index,
+ float *out,
+ const int16_t nbits,
+ const int16_t mode )
+{
+ uint16_t i;
+ const Word8 *p_no_lead;
+ const float *p_scales;
+ float scale;
+ int16_t idx_scale;
+ UWord32 offsets[MAX_NO_SCALES + 1];
+
+ if ( mode == 0 )
+ {
+ p_no_lead = &no_lead_BWE[( nbits - mslvq_SHB_min_bits[0] ) * 3];
+ p_scales = &scales_BWE[( nbits - mslvq_SHB_min_bits[0] ) * 3];
+ }
+ else
+ {
+ p_no_lead = &no_lead_BWE_3b[( nbits - mslvq_SHB_min_bits[1] ) * 3];
+ p_scales = &scales_BWE_3b[( nbits - mslvq_SHB_min_bits[1] ) * 3];
+ }
+
+
+ if ( index == 0 )
+ {
+ set_zero( out, LATTICE_DIM );
+ }
+ else
+ {
+ /* create offsets */
+ offsets[0] = 0;
+ for ( i = 0; i < MAX_NO_SCALES; i++ )
+ {
+ offsets[i + 1] = table_no_cv[p_no_lead[i]] + offsets[i];
+ }
+
+ /* find idx_scale */
+ idx_scale = 0;
+ while ( (int16_t) i <= MAX_NO_SCALES && index >= offsets[idx_scale] )
+ {
+ idx_scale++;
+ }
+ idx_scale--;
+ index -= offsets[idx_scale];
+
+ /* find idx_leader */
+ i = 1;
+ while ( index >= table_no_cv[i] )
+ {
+ i++;
+ }
+ i = i - 1;
+
+ decode_comb( (Word32) ( index - table_no_cv[i] - 1 ), out, i );
+
+ scale = p_scales[idx_scale];
+ for ( i = 0; i < LATTICE_DIM; i++ )
+ {
+ out[i] *= scale * sigma_BWE[mode * LATTICE_DIM + i];
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/nelp.c b/lib_com/nelp.c
new file mode 100644
index 0000000000000000000000000000000000000000..768b92f915f96879b0a2288a93a529db235d7a8e
--- /dev/null
+++ b/lib_com/nelp.c
@@ -0,0 +1,156 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * dequantize_uvg()
+ *
+ * Dequantize unvoiced gains
+ *--------------------------------------------------------------------*/
+
+void dequantize_uvg(
+ int16_t iG1, /* i : gain 1 index */
+ int16_t *iG2, /* i : gain 2 index */
+ float *G, /* o : quantized gain */
+ const int16_t bwidth /* i : audio bandwidth */
+)
+{
+ int16_t i, k;
+ const float( *UVG1CB )[2] = NULL;
+ const float( *UVG2CB1 )[5] = NULL;
+ const float( *UVG2CB2 )[5] = NULL;
+
+ if ( bwidth == NB )
+ {
+ UVG1CB = UVG1CB_NB;
+ UVG2CB1 = UVG2CB1_NB;
+ UVG2CB2 = UVG2CB2_NB;
+ }
+
+ else if ( bwidth == WB || bwidth == SWB )
+ {
+ UVG1CB = UVG1CB_WB;
+ UVG2CB1 = UVG2CB1_WB;
+ UVG2CB2 = UVG2CB2_WB;
+ }
+
+ for ( i = 0; i < 2; i++ )
+ {
+ for ( k = 0; k < 5; k++ )
+ {
+ if ( i == 0 )
+ {
+ G[i * 5 + k] = (float) pow( 10.0, UVG1CB[iG1][i] ) * UVG2CB1[iG2[i]][k];
+ }
+ else if ( i == 1 )
+ {
+ G[i * 5 + k] = (float) pow( 10.0, UVG1CB[iG1][i] ) * UVG2CB2[iG2[i]][k];
+ }
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * generate_nelp_excitation()
+ *
+ * Generate excitation for NELP coding.
+ *--------------------------------------------------------------------*/
+
+void generate_nelp_excitation(
+ int16_t *seed, /* i/o: random number seed */
+ float *Gains, /* i : excitation gains */
+ float *output, /* o : excitation output */
+ float gain_fac /* i : gain factor */
+)
+{
+ int16_t i, len, j;
+ float tmp[31], tmp1[31], tmpf;
+ int16_t k1, k2, I[31], tmpi;
+
+ for ( i = 0; i < 10; i++ )
+ {
+ if ( i == 9 )
+ {
+ len = 31;
+ }
+ else
+ {
+ len = 25;
+ }
+
+ for ( j = 0; j < len; j++ )
+ {
+ tmp[j] = ( ( *seed ) = 521 * ( *seed ) + 259 ) / PCM16_TO_FLT_FAC;
+ tmp1[j] = ABSVAL( tmp[j] );
+ I[j] = j;
+ }
+ for ( k1 = 0; k1 < len - 1; k1++ )
+ {
+ for ( k2 = k1 + 1; k2 < len; k2++ )
+ {
+ if ( tmp1[k2] > tmp1[k1] )
+ {
+ tmpi = I[k2];
+ tmpf = tmp1[k2];
+ tmp1[k2] = tmp1[k1];
+ I[k2] = I[k1];
+ tmp1[k1] = tmpf;
+ I[k1] = tmpi;
+ }
+ }
+ }
+
+ /*using a factor of 1.37 to compensate for the ~ 2.5 ( or 2.73) dB diff between this scheme and EVS-UV */
+ for ( j = 0; j < (int16_t) rint_new( len / 4.0f ); j++ )
+ {
+ output[i * 25 + I[j]] = (float) ( Gains[i] * sqrt( 3.0f ) * tmp[I[j]] * gain_fac );
+ }
+ for ( ; j < len; j++ )
+ {
+ output[i * 25 + I[j]] = 0;
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/options.h b/lib_com/options.h
new file mode 100644
index 0000000000000000000000000000000000000000..31d4cb855c31be54ffd715acd1df07b3a645b4eb
--- /dev/null
+++ b/lib_com/options.h
@@ -0,0 +1,93 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 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 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") */
+
+
+/* #################### End DEBUGGING switches ############################ */
+
+
+#define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */
+
+
+/* ################### Start BE switches ################################# */
+/* only BE switches wrt selection floating point code */
+
+/*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */
+
+#define FIX_854_ARRAY_SIZE_MISMATCH /* VA: issue 854: correct the mismatch between definition and declaration of `ivas_core_dec() */
+#define FIX_785_REMOVE_DEAD_CODE /* VA: issue 785: remove dead code */
+#define FIX_852_FIX_HANDLE_DEREF /* VA: issue 852: Fix missing handle dereferencing of hIsmMetadaData in ivas_ism_metadata_close() */
+
+
+/* #################### End BE switches ################################## */
+
+
+/* #################### Start NON-BE switches ############################ */
+/* any switch which is non-be wrt selection floating point code */
+/* all switches in this category should start with "NONBE_" */
+
+#define NONBE_FIX_838_CRASH_24_4_WB /* FhG: Issue 838: fix encoder crashes for Unified Stereo and MASA 2 TC at 24.4 kbps WB due to missing IGF (re-) allocation */
+#define NONBE_FIX_839_MC_RS_CHANNEL_ALLOC /* FhG: Issues #839: problems with reallocation of the channels on the heap in case of MC RS */
+#define BE_FIX_832_ASAN_ERROR_EFAP_OSBA /* FhG: issue #832: fix ASAN error caused by re-allocating EFAP memories in OSBA*/
+#define NONBE_FIX_819_DOUBLE_PREC_COMB_FORMATS /* VA: issue 820: Double precision arithmetic in combined formats */
+#define NONBE_FIX_849_OMASA_BFI_CRASH /* VA: issue 849: fix OMASA 2TC and FEC crashes */
+
+
+/* ##################### End NON-BE switches ########################### */
+
+/* ################## End DEVELOPMENT switches ######################### */
+
+/* clang-format on */
+
+#endif
diff --git a/lib_com/parameter_bitmaping.c b/lib_com/parameter_bitmaping.c
new file mode 100644
index 0000000000000000000000000000000000000000..720324b1e9175388b5a39dfc87e781be7226820b
--- /dev/null
+++ b/lib_com/parameter_bitmaping.c
@@ -0,0 +1,260 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "stat_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+
+/********************************/
+/* Helper functions */
+/********************************/
+
+/** Put nBits long encoded value from *pStream into bitstream. Using the function EncodeValue for encoding. */
+static int16_t PutIntoBitstream( const int16_t **pStream, TEncodeValue EncodeValue, int16_t index, BSTR_ENC_HANDLE hBstr, const int16_t nBits )
+{
+ const int16_t value = *( *pStream )++;
+ const int16_t codedValue = EncodeValue( value, index );
+
+ push_next_indice( hBstr, codedValue, nBits );
+
+ return value;
+}
+
+/** Get nBits long value from bitstream into *pStream. */
+static int16_t GetFromBitstream(
+ Decoder_State *st,
+ TDecodeValue DecodeValue,
+ uint16_t index,
+ int16_t nFixedBits,
+ int16_t **pStream )
+{
+ int16_t value = 0;
+ if ( DecodeValue != NULL )
+ {
+ DecodeValue( st, index, &value );
+ }
+ else
+ {
+ value = get_next_indice( st, nFixedBits );
+ }
+ *( *pStream )++ = value;
+
+ return value;
+}
+
+
+static int16_t FixedWidthEncoding( int16_t value, int16_t index )
+{
+ (void) index; /* suppress compiler warnings */
+
+ return value;
+}
+
+
+/********************************/
+/* Interface functions */
+/********************************/
+
+void GetParameters(
+ ParamsBitMap const *paramsBitMap,
+ const int16_t nArrayLength,
+ void const *pParameter,
+ int16_t **pStream,
+ int16_t *pnSize,
+ int16_t *pnBits )
+{
+ int16_t index;
+ int16_t iParam, nParams;
+ int16_t value;
+ void const *pSubStruct;
+
+ assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
+
+ nParams = paramsBitMap->nParams;
+ for ( index = 0; index < nArrayLength; index++ )
+ {
+ for ( iParam = 0; iParam < nParams; iParam++ )
+ {
+ ParamBitMap const *const param = ¶msBitMap->params[iParam];
+
+#define WMC_TOOL_SKIP
+ pSubStruct = param->GetParamValue( pParameter, index, &value );
+#undef WMC_TOOL_SKIP
+ /* If a function for encoding/decoding value is defined than it should take care of 0 */
+ if ( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
+ {
+ *( *pStream )++ = value;
+ }
+ else
+ {
+ *( *pStream )++ = value - 1;
+ }
+ ++*pnSize;
+#define WMC_TOOL_SKIP
+ *pnBits += ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( value, index );
+#undef WMC_TOOL_SKIP
+ if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
+ {
+ GetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
+ }
+ }
+ }
+
+ return;
+}
+
+
+void SetParameters(
+ ParamsBitMap const *paramsBitMap,
+ const int16_t nArrayLength,
+ void *pParameter,
+ const int16_t **pStream,
+ int16_t *pnSize )
+{
+ int16_t index;
+ int16_t iParam, nParams;
+ int16_t value;
+ void *pSubStruct;
+
+ assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) );
+
+ nParams = paramsBitMap->nParams;
+ for ( index = 0; index < nArrayLength; index++ )
+ {
+ for ( iParam = 0; iParam < nParams; iParam++ )
+ {
+ ParamBitMap const *const param = ¶msBitMap->params[iParam];
+ /* If a function for encoding/decoding value is defined than it should take care of 0 */
+
+ value = *( *pStream )++ + ( param->fZeroAllowed || ( param->EncodeValue != NULL ) ? 0 : 1 );
+#define WMC_TOOL_SKIP
+ pSubStruct = param->SetParamValue( pParameter, index, value );
+#undef WMC_TOOL_SKIP
+ ++*pnSize;
+ if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
+ {
+ SetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize );
+ }
+ }
+ }
+
+ return;
+}
+
+
+void WriteToBitstream(
+ ParamsBitMap const *paramsBitMap,
+ const int16_t nArrayLength,
+ const int16_t **pStream,
+ int16_t *pnSize,
+ BSTR_ENC_HANDLE hBstr,
+ int16_t *pnBits )
+{
+ int16_t index;
+ int16_t 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++ )
+ {
+ const ParamBitMap *param = ¶msBitMap->params[iParam];
+ int16_t nBits;
+ /* If a function for encoding/decoding value is defined than it should take care of 0 */
+ int16_t fShiftValue;
+ TEncodeValue EncodeValue;
+ int16_t value;
+
+#define WMC_TOOL_SKIP
+ nBits = ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( **pStream, index );
+#undef WMC_TOOL_SKIP
+ fShiftValue = !param->fZeroAllowed && ( param->EncodeValue == NULL );
+ EncodeValue = ( param->EncodeValue == NULL ) ? &FixedWidthEncoding : param->EncodeValue;
+ value = PutIntoBitstream( pStream, EncodeValue, index, hBstr, nBits ) + ( fShiftValue ? 1 : 0 );
+ ++*pnSize;
+ *pnBits += nBits;
+ if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
+ {
+ WriteToBitstream( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
+ }
+ }
+ }
+
+ return;
+}
+
+
+void ReadFromBitstream(
+ ParamsBitMap const *paramsBitMap,
+ const int16_t nArrayLength,
+ Decoder_State *st,
+ int16_t **pStream,
+ int16_t *pnSize )
+{
+ int16_t index;
+ int16_t iParam, nParams;
+ int16_t fShiftValue;
+ int16_t value;
+
+ assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( st != NULL ) );
+
+ nParams = paramsBitMap->nParams;
+ for ( index = 0; index < nArrayLength; index++ )
+ {
+ for ( iParam = 0; iParam < nParams; iParam++ )
+ {
+ ParamBitMap const *param = ¶msBitMap->params[iParam];
+ /* If a function for encoding/decoding value is defined than it should take care of 0 */
+
+ fShiftValue = !param->fZeroAllowed && ( param->EncodeValue == NULL );
+ value = GetFromBitstream( st, param->DecodeValue, index, param->nBits, pStream ) + ( fShiftValue ? 1 : 0 );
+ if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
+ {
+ ReadFromBitstream( param->pSubParamBitMap, value, st, pStream, pnSize );
+ }
+ }
+ }
+
+ *pnSize += nParams * nArrayLength;
+
+ return;
+}
diff --git a/lib_com/phase_dispersion.c b/lib_com/phase_dispersion.c
new file mode 100644
index 0000000000000000000000000000000000000000..eeecc7aaa0d8b61882138313c33ae775fb059811
--- /dev/null
+++ b/lib_com/phase_dispersion.c
@@ -0,0 +1,155 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*-----------------------------------------------------------------------*
+ * phase_dispersion()
+ *
+ * Post-processing to enhance noise at low bitrate
+ *-----------------------------------------------------------------------*/
+
+void phase_dispersion(
+ const float gain_code, /* i : gain of code */
+ const float gain_pit, /* i : gain of pitch */
+ float code[], /* i/o: code vector */
+ const int16_t mode, /* i : level, 0=hi, 1=lo, 2=off */
+ float disp_mem[] /* i/o: static memory (size = 8) */
+)
+{
+ int16_t i, j, state;
+ float *prev_gain_pit, *prev_gain_code, *prev_state;
+ float code2[2 * L_SUBFR];
+ float h_disp[L_SUBFR], *code2_real, *code2_imag, *code_real, *code_imag, *h_real, *h_imag;
+
+ prev_state = disp_mem;
+ prev_gain_code = disp_mem + 1;
+ prev_gain_pit = disp_mem + 2;
+
+ state = 2;
+ if ( gain_pit < 0.6f )
+ {
+ state = 0;
+ }
+ else if ( gain_pit < 0.9f )
+ {
+ state = 1;
+ }
+
+ for ( i = 5; i > 0; i-- )
+ {
+ prev_gain_pit[i] = prev_gain_pit[i - 1];
+ }
+ prev_gain_pit[0] = gain_pit;
+
+ if ( gain_code - 3.0f * *prev_gain_code > 0.0f )
+ {
+ if ( state < 2 )
+ {
+ state++;
+ }
+ }
+ else
+ {
+ j = 0;
+ for ( i = 0; i < 6; i++ )
+ {
+ if ( prev_gain_pit[i] < 0.6f )
+ {
+ j++;
+ }
+ }
+
+ if ( j > 2 )
+ {
+ state = 0;
+ }
+
+ if ( ( state - (int16_t) *prev_state ) > 1 )
+ {
+ state--;
+ }
+ }
+
+ *prev_gain_code = gain_code;
+ *prev_state = (float) state;
+
+ /*-----------------------------------------------------------------*
+ * Circular convolution
+ *-----------------------------------------------------------------*/
+
+ state += mode; /* level of dispersion */
+ if ( state < 2 )
+ {
+ fft_rel( code, L_SUBFR, 6 );
+
+ if ( state == 0 )
+ {
+ mvr2r( low_H, h_disp, L_SUBFR );
+ }
+
+ if ( state == 1 )
+ {
+ mvr2r( mid_H, h_disp, L_SUBFR );
+ }
+
+ code2_real = code2;
+ code2_imag = code2 + L_SUBFR - 1;
+ code_real = code;
+ code_imag = code + L_SUBFR - 1;
+ h_real = h_disp;
+ h_imag = h_disp + L_SUBFR - 1;
+ *code2_real++ = *code_real++ * *h_real++;
+
+ for ( i = 1; i < L_SUBFR / 2; i++ )
+ {
+ *code2_real++ = *code_real * *h_real - *code_imag * *h_imag;
+ *code2_imag-- = *code_real++ * *h_imag-- + *code_imag-- * *h_real++;
+ }
+
+ *code2_real++ = *code_real++ * *h_real++;
+ ifft_rel( code2, L_SUBFR, 6 );
+
+ mvr2r( code2, code, L_SUBFR );
+ }
+
+ return;
+}
diff --git a/lib_com/ppp.c b/lib_com/ppp.c
new file mode 100644
index 0000000000000000000000000000000000000000..d9e553124ec3b9b9827fde1043dd16bc23ff0e03
--- /dev/null
+++ b/lib_com/ppp.c
@@ -0,0 +1,113 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot.h"
+#include "rom_com.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * Interpol_delay()
+ *
+ * Interpolation of pitch lag
+ *--------------------------------------------------------------------*/
+
+void Interpol_delay(
+ float *out, /* o : pitch interpolation output */
+ float *last, /* i : last frame pitch lag */
+ float *current, /* i : current frame pitch lag */
+ int16_t SubNum, /* i : subframe number */
+ const float *frac /* i : interpolation constant */
+)
+{
+ out[0] = ( 1.0f - frac[SubNum] ) * *last + frac[SubNum] * *current;
+ out[1] = ( 1.0f - frac[SubNum + 1] ) * *last + frac[SubNum + 1] * *current;
+ out[2] = ( 1.0f - frac[SubNum + 2] ) * *last + frac[SubNum + 2] * *current;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * deemph_lpc()
+ *
+ * De-emphasis of LP coefficients
+ * convolve LPC with [1 -PREEMPH_FAC] to de-emphasise LPC
+ *--------------------------------------------------------------------*/
+
+void deemph_lpc(
+ float *p_Aq_curr, /* i : LP coefficients current frame */
+ float *p_Aq_old, /* i : LP coefficients previous frame */
+ float *LPC_de_curr, /* o : De-emphasized LP coefficients current frame */
+ float *LPC_de_old, /* o : De-emphasized LP coefficients previous frame */
+ const int16_t deemph_old )
+{
+ int16_t k;
+ float b[M + 2];
+ const float a[2] = { -PREEMPH_FAC, 1.0 };
+
+ b[0] = 1.0;
+ for ( k = 0; k < M; k++ )
+ {
+ b[k + 1] = p_Aq_curr[k];
+ }
+ b[M + 1] = 0.0;
+
+ for ( k = 0; k <= M; k++ )
+ {
+ LPC_de_curr[k] = a[0] * b[k] + a[1] * b[k + 1];
+ }
+
+ if ( deemph_old == 1 )
+ {
+ /* ignoring the 1st value which is 1.0 in this case */
+ b[0] = 1.0;
+ for ( k = 0; k < M; k++ )
+ {
+ b[k + 1] = p_Aq_old[k + 1];
+ }
+ b[M + 1] = 0.0;
+
+ for ( k = 0; k <= M; k++ )
+ {
+ LPC_de_old[k] = a[0] * b[k] + a[1] * b[k + 1];
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/pred_lt4.c b/lib_com/pred_lt4.c
new file mode 100644
index 0000000000000000000000000000000000000000..51a0227eae04e88b45dac4792b0b6fd516580857
--- /dev/null
+++ b/lib_com/pred_lt4.c
@@ -0,0 +1,156 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------------*
+ * pred_lt4()
+ *
+ * Compute the result of long term prediction with fractionnal
+ * interpolation of resolution 1/4.
+ *
+ * On return, exc[0..L_subfr-1] contains the interpolated signal
+ * (adaptive codebook excitation)
+ *-------------------------------------------------------------------*/
+
+void pred_lt4(
+ const float excI[], /* i : input excitation buffer */
+ float excO[], /* o : output excitation buffer */
+ const int16_t T0, /* i : integer pitch lag */
+ int16_t frac, /* i : fraction of lag */
+ const int16_t L_subfr, /* i : subframe size */
+ const float *win, /* i : interpolation window */
+ const int16_t nb_coef, /* i : nb of filter coef */
+ const int16_t up_sample /* i : up_sample */
+)
+{
+ int16_t i, j;
+ float s;
+ const float *x1, *x2, *x0, *c1, *c2;
+
+ x0 = &excI[-T0];
+ frac = -frac;
+
+ if ( frac < 0 )
+ {
+ frac += up_sample;
+ x0--;
+ }
+
+ for ( j = 0; j < L_subfr; j++ )
+ {
+ x1 = x0++;
+ x2 = x1 + 1;
+ c1 = &win[frac];
+ c2 = &win[up_sample - frac];
+
+ s = 0.0f;
+ for ( i = 0; i < nb_coef; i++, c1 += up_sample, c2 += up_sample )
+ {
+ s += ( *x1-- ) * ( *c1 ) + ( *x2++ ) * ( *c2 );
+ }
+ excO[j] = s;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * pred_lt4_tc()
+ *
+ * adapt. search of the second impulse in the same subframe (when appears)
+ * On return, exc[0..L_subfr-1] contains the interpolated signal
+ * (adaptive codebook excitation)
+ *-------------------------------------------------------------------*/
+
+void pred_lt4_tc(
+ float exc[], /* i/o: excitation buffer */
+ const int16_t T0, /* i : integer pitch lag */
+ int16_t frac, /* i : fraction of lag */
+ const float *win, /* i : interpolation window */
+ const int16_t imp_pos, /* i : glottal impulse position */
+ const int16_t i_subfr /* i : subframe index */
+)
+{
+ int16_t i, j;
+ float s;
+ const float *x1, *x2, *x0, *c1, *c2;
+ float excO[L_SUBFR + 1];
+ float excI[2 * L_SUBFR];
+
+ mvr2r( exc + i_subfr - L_SUBFR, excI, 2 * L_SUBFR );
+
+ if ( ( ( T0 + imp_pos - L_IMPULSE2 ) < L_SUBFR ) && ( T0 < L_SUBFR ) )
+ {
+ set_f( excI + L_SUBFR - T0, 0, T0 );
+ set_f( excO, 0, L_SUBFR + 1 );
+ x0 = excI + L_SUBFR;
+ frac = -frac;
+
+ if ( frac < 0 )
+ {
+ frac += PIT_UP_SAMP;
+ x0--;
+ }
+
+ for ( j = T0; j < L_SUBFR + 1; j++ )
+ {
+ x1 = x0++;
+ x2 = x1 + 1;
+ c1 = &win[frac];
+ c2 = &win[PIT_UP_SAMP - frac];
+
+ s = 0.0f;
+ for ( i = 0; i < L_INTERPOL2; i++, c1 += PIT_UP_SAMP, c2 += PIT_UP_SAMP )
+ {
+ s += ( *x1-- ) * ( *c1 ) + ( *x2++ ) * ( *c2 );
+ }
+ excO[j] = s;
+ }
+
+ for ( i = T0; i < L_SUBFR; i++ )
+ {
+ exc[i + i_subfr] += PIT_SHARP * excO[i];
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/preemph.c b/lib_com/preemph.c
new file mode 100644
index 0000000000000000000000000000000000000000..024ad379c2a476d069def064c7a3182f7765194f
--- /dev/null
+++ b/lib_com/preemph.c
@@ -0,0 +1,68 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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
+ ====================================================================================*/
+
+#include
+#include "options.h"
+#include "prot.h"
+#include "wmc_auto.h"
+
+/*-------------------------------------------------------------*
+ * preemph()
+ *
+ * Preemphasis: filtering through 1 - mu z^-1
+ *-------------------------------------------------------------*/
+
+void preemph(
+ float *signal, /* i/o: signal */
+ const float mu, /* i : preemphasis factor */
+ const int16_t L, /* i : vector size */
+ float *mem /* i/o: memory (x[-1]) */
+)
+{
+ int16_t i;
+ float temp;
+
+ temp = signal[L - 1];
+ for ( i = L - 1; i > 0; i-- )
+ {
+ signal[i] = signal[i] - mu * signal[i - 1];
+ }
+
+ signal[0] = signal[0] - mu * ( *mem );
+ *mem = temp;
+
+ return;
+}
diff --git a/lib_com/prot.h b/lib_com/prot.h
new file mode 100644
index 0000000000000000000000000000000000000000..d277cefb1c9c1400ebd59803953923f383a5627f
--- /dev/null
+++ b/lib_com/prot.h
@@ -0,0 +1,10019 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 PROT_H
+#define PROT_H
+
+#include
+#include
+#include
+#include "options.h"
+#include "typedef.h"
+#include "stat_enc.h"
+#include "stat_dec.h"
+#include "stat_com.h"
+#include "ivas_stat_com.h"
+#include "ivas_stat_enc.h"
+#include "ivas_stat_dec.h"
+#include "cnst.h"
+#include "stl.h"
+#include "ivas_error_utils.h"
+
+
+/*----------------------------------------------------------------------------------*
+ * 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 TRUNC
+#define TRUNC( x ) ( (int16_t) ( ( ( x ) >= 32767. ? 32767 : ( ( x ) <= -32768. ? -32768 : ( x ) ) ) + 0.5 ) )
+#endif
+
+#define log_base_2( x ) ( (double) log( (double) ( x ) ) * 1.4426950408889634074f )
+#define round_f( x ) ( ( ( x ) > 0 ) ? (int32_t) ( ( x ) + 0.5f ) : ( -(int32_t) ( ( -x ) + 0.5f ) ) )
+
+#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; \
+ }
+#endif
+
+#ifndef swap
+#define swap( x, y, type ) \
+ { \
+ type u__p; \
+ u__p = x; \
+ x = y; \
+ y = u__p; \
+ }
+#endif
+
+#define set_max( a, b ) \
+ { \
+ if ( ( b ) > *a ) \
+ { \
+ *a = ( b ); \
+ } \
+ } /* If the first argument is already the highes or lowest, nothing is done. */
+#define set_min( a, b ) \
+ { \
+ if ( ( b ) < *a ) \
+ { \
+ *a = ( b ); \
+ } \
+ } /* Otherwise, the 2nd arg is stored at the address of the first arg. */
+
+static __inline Word16 L_Extract_lc( const Word32 L_32, Word16 *p_hi )
+{
+ *p_hi = extract_h( L_32 );
+ return lshr( extract_l( L_32 ), 1 );
+}
+
+/*----------------------------------------------------------------------------------*
+ * MODE1 prototypes
+ *----------------------------------------------------------------------------------*/
+
+/*! r: inverse square root of input value */
+float inv_sqrt(
+ const float x /* i : input value */
+);
+
+/*! r: output random value */
+int16_t own_random(
+ int16_t *seed /* i/o: random seed */
+);
+
+/*! r: sign of x (+1/-1) */
+float sign(
+ const float x /* i : input value of x */
+);
+
+/*! r: logarithm2 of x */
+float log2_f(
+ const float x /* i : input value of x */
+);
+
+int16_t norm_ul(
+ uint32_t UL_var1 );
+
+/*! r: sum of all vector elements */
+int16_t sum_s(
+ const int16_t *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+/*! r: sum of all vector elements */
+int32_t sum_l(
+ const int32_t *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+/*! r: sum of all vector elements */
+float sum_f(
+ const float *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+/*! r: sum of all squared vector elements */
+float sum2_f(
+ const float *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+void set_c(
+ int8_t y[], /* i/o: Vector to set */
+ const int8_t a, /* i : Value to set the vector to */
+ const int32_t N /* i : Length of the vector */
+);
+
+void set_s(
+ int16_t y[], /* i/o: Vector to set */
+ const int16_t a, /* i : Value to set the vector to */
+ const int16_t N /* i : Lenght of the vector */
+);
+
+void set_l(
+ int32_t y[], /* i/o: Vector to set */
+ const int32_t a, /* i : Value to set the vector to */
+ const int16_t N /* i : Length of the vector */
+);
+
+void set_f(
+ float y[], /* i/o: Vector to set */
+ const float a, /* i : Value to set the vector to */
+ const int16_t N /* i : Lenght of the vector */
+);
+
+void set_zero(
+ float *vec, /* o : input vector */
+ const int16_t lvec /* i : length of the vector */
+);
+
+void mvr2r(
+ const float x[], /* i : input vector */
+ float y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+void mvs2s(
+ const int16_t x[], /* i : input vector */
+ int16_t y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+uint32_t mvr2s(
+ const float x[], /* i : input vector */
+ int16_t y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+void mvs2r(
+ const int16_t x[], /* i : input vector */
+ float y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+void mvl2l(
+ const int32_t x[], /* i : input vector */
+ int32_t y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+void AGC_dec(
+ float x[], /* i/o: input/output vector */
+ float mem[], /* i/o: mem[2] should be init to [0,0] */
+ const int16_t n /* i : vector size */
+);
+
+/*! r: index of the maximum value in the input vector */
+int16_t maximum(
+ const float *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ float *max_val /* o : maximum value in the input vector */
+);
+
+/*! r: index of the maximum value in the input vector */
+int16_t maximum_s(
+ const int16_t *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ int16_t *max /* o : maximum value in the input vector */
+);
+
+/*! r: index of the maximum value in the input vector */
+int16_t maximumAbs(
+ const float *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ float *max_val /* o : maximum value in the input vector */
+);
+
+/*! r: index of the minimum value in the input vector */
+int16_t minimum(
+ const float *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ float *min_val /* o : minimum value in the input vector */
+);
+
+/*! r: index of the minimum value in the input vector */
+int16_t minimum_s(
+ const int16_t *vec, /* i : Input vector */
+ const int16_t lvec, /* i : Vector length */
+ int16_t *min_val /* o : minimum value in the input vector */
+);
+
+/*! r: return index with max energy value in vector */
+int16_t emaximum(
+ const float *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ float *ener_max /* o : maximum energy value */
+);
+
+/*! r: vector mean */
+float mean(
+ const float *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+/*! r: dot product of x[] and y[] */
+float dotp(
+ const float x[], /* i : vector x[] */
+ const float y[], /* i : vector y[] */
+ const int16_t n /* i : vector length */
+);
+
+void conv(
+ const float x[], /* i : input vector */
+ const float h[], /* i : impulse response (or second input vector) */
+ float y[], /* o : output vetor (result of convolution) */
+ const int16_t L /* i : vector size */
+);
+
+void fir(
+ const float x[], /* i : input vector */
+ const float h[], /* i : impulse response of the FIR filter */
+ float y[], /* o : output vector (result of filtering) */
+ float mem[], /* i/o: memory of the input signal (M samples) */
+ const int16_t L, /* i : input vector size */
+ const int16_t K, /* i : order of the FIR filter (M+1 coefs.) */
+ const int16_t upd /* i : 1 = update the memory, 0 = not */
+);
+
+void v_add(
+ const float x1[], /* i : Input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 + vector 2 */
+ const int16_t N /* i : Vector length */
+);
+
+void v_sub(
+ const float x1[], /* i : Input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 - vector 2 */
+ const int16_t N /* i : Vector length */
+);
+
+void v_mult(
+ const float x1[], /* i : Input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 .* vector 2*/
+ const int16_t N /* i : Vector length */
+);
+
+void v_multc(
+ const float x[], /* i : Input vector */
+ const float c, /* i : Constant */
+ float y[], /* o : Output vector that contains c*x */
+ const int16_t N /* i : Vector length */
+);
+
+void v_sub_s(
+ const int16_t x1[], /* i : Input vector 1 */
+ const int16_t x2[], /* i : Input vector 2 */
+ int16_t y[], /* o : Output vector that contains vector 1 - vector 2 */
+ const int16_t N /* i : Vector length */
+);
+
+/*! r: index of the winning codeword */
+int16_t squant(
+ const float x, /* i : scalar value to quantize */
+ float *xq, /* o : quantized value */
+ const float cb[], /* i : codebook */
+ const int16_t cbsize /* i : codebook size */
+);
+
+int16_t squant_int(
+ uint8_t x, /* i : scalar value to quantize */
+ uint8_t *xq, /* o : quantized value */
+ const uint8_t *cb, /* i : codebook */
+ const int16_t cbsize /* i : codebook size */
+);
+
+/*! r: index of the winning codevector */
+int16_t vquant(
+ float x[], /* i : vector to quantize */
+ const float x_mean[], /* i : vector mean to subtract (0 if none) */
+ float xq[], /* o : quantized vector */
+ const float cb[], /* i : codebook */
+ const int16_t dim, /* i : dimension of codebook vectors */
+ const int16_t cbsize /* i : codebook size */
+);
+
+/*! r: index of the winning codevector */
+int16_t w_vquant(
+ float x[], /* i : vector to quantize */
+ const float x_mean[], /* i : vector mean to subtract (0 if none) */
+ const int16_t weights[], /* i : error weights */
+ float xq[], /* o : quantized vector */
+ const float cb[], /* i : codebook */
+ const int16_t dim, /* i : dimension of codebook vectors */
+ const int16_t cbsize, /* i : codebook size */
+ const int16_t reverse /* i : reverse codebook vectors */
+);
+
+/*! r: index of the winning codeword */
+int16_t usquant(
+ const float x, /* i : scalar value to quantize */
+ float *xq, /* o : quantized value */
+ const float qlow, /* i : lowest codebook entry (index 0) */
+ const float delta, /* i : quantization step */
+ const int16_t cbsize /* i : codebook size */
+);
+
+/*! r: dequanzited gain */
+float usdequant(
+ const int16_t idx, /* i : quantizer index */
+ const float qlow, /* i : lowest codebook entry (index 0) */
+ const float delta /* i : quantization step */
+);
+
+void v_sort(
+ float *r, /* i/o: Vector to be sorted in place */
+ const int16_t lo, /* i : Low limit of sorting range */
+ const int16_t up /* i : High limit of sorting range */
+);
+
+void sort(
+ uint16_t *x, /* i/o: Vector to be sorted */
+ uint16_t len /* i/o: vector length */
+);
+
+/*! r: variance of vector */
+float var(
+ const float *x, /* i : input vector */
+ const int16_t len /* i : length of inputvector */
+);
+
+/*! r: standard deviation */
+float std_dev(
+ const float *x, /* i : input vector */
+ const int16_t len /* i : length of the input vector */
+);
+
+/*! r: the dot product x'*A*x */
+float dot_product_mat(
+ const float *x, /* i : vector x */
+ const float *A, /* i : matrix A */
+ const int16_t m /* i : vector length */
+);
+
+float root_a(
+ float a );
+
+float root_a_over_b(
+ float a,
+ float b );
+
+void polezero_filter(
+ const float *in, /* i : input vector */
+ float *out, /* o : output vector */
+ const int16_t N, /* i : input vector size */
+ const float *b, /* i : numerator coefficients */
+ const float *a, /* i : denominator coefficients */
+ const int16_t order, /* i : filter order */
+ float *mem /* i/o: filter memory */
+);
+
+double rint_new(
+ double x /* i/o: Round to the nearest integer with mid point exception */
+);
+
+double anint(
+ double x /* i/o: Round to the nearest integer */
+);
+
+/*! r: Output either 1 if Numeric, 0 if NaN or Inf */
+int16_t is_numeric_float(
+ float x /* i : Input value which is checked if numeric or not */
+);
+
+void delay_signal(
+ float x[], /* i/o: signal to be delayed */
+ const int16_t len, /* i : length of the input signal */
+ float mem[], /* i/o: synchronization memory */
+ const int16_t delay /* i : delay in samples */
+);
+
+ivas_error push_indice(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ int16_t id, /* i : ID of the indice */
+ uint16_t value, /* i : value of the quantized indice */
+ int16_t nb_bits /* i : number of bits used to quantize the indice */
+);
+
+ivas_error push_next_indice(
+ BSTR_ENC_HANDLE hBstr,
+ uint16_t value, /* i : value of the quantized indice */
+ int16_t nb_bits /* i : number of bits used to quantize the indice */
+);
+
+ivas_error push_next_bits(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const uint16_t bits[], /* i : bit buffer to pack, sequence of single bits */
+ const int16_t nb_bits /* i : number of bits to pack */
+);
+
+/*! r: maximum number of indices */
+int16_t get_ivas_max_num_indices(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+/*! r: maximum number of indices */
+int16_t get_BWE_max_num_indices(
+ const int32_t extl_brate /* i : extensiona layer bitrate */
+);
+
+/*! r: maximum number of indices */
+int16_t get_ivas_max_num_indices_metadata(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate /* i : IVAS total bitrate */
+);
+
+ivas_error ind_list_realloc(
+ INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */
+ const int16_t max_num_indices, /* i : new maximum number of allowed indices in the list */
+ Encoder_Struct *st_ivas /* i : IVAS encoder structure */
+);
+
+ivas_error check_ind_list_limits(
+ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */
+);
+
+void move_indices(
+ INDICE_HANDLE old_ind_list, /* i/o: old location of indices */
+ INDICE_HANDLE new_ind_list, /* i/o: new location of indices */
+ const int16_t nb_indices /* i : number of moved indices */
+);
+
+/*! r: index of the indice in the list, -1 if not found */
+int16_t find_indice(
+ BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */
+ const int16_t id, /* i : ID of the indice */
+ uint16_t *value, /* o : value of the quantized indice */
+ int16_t *nb_bits /* o : number of bits used to quantize the indice */
+);
+
+/*! r: number of deleted indices */
+uint16_t delete_indice(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t id /* i : ID of the indice */
+);
+
+/*! r: value of the indice */
+uint16_t get_next_indice(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+);
+
+/*! r: value of the indice */
+uint16_t get_next_indice_1(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+void get_next_indice_tmp(
+ Decoder_State *st, /* o : decoder state structure */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+);
+
+/*! r: value of the indice */
+uint16_t get_indice(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t pos, /* i : absolute position in the bitstream */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+);
+
+/*! r: value of the indice */
+uint16_t get_indice_1(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t pos /* i : absolute position in the bitstream */
+);
+
+void reset_indices_enc(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t max_num_indices /* i : max number of indices */
+);
+
+void reset_indices_dec(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+ivas_error write_indices_ivas(
+ Encoder_Struct *st_ivas, /* i/o: encoder state structure */
+ uint16_t *bit_stream, /* i/o: output bitstream */
+ uint16_t *num_bits /* i/o: number of bits written to output */
+);
+
+Word16 rate2EVSmode(
+ const Word32 brate, /* i : bitrate */
+ int16_t *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */
+);
+
+
+/*! r: 1 = OK, 0 = something wrong */
+ivas_error read_indices(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ uint16_t bit_stream[], /* i : bitstream buffer */
+ UWord16 num_bits, /* i : number of bits in bitstream */
+ int16_t *prev_ft_speech,
+ int16_t *CNG,
+ int16_t bfi /* i : bad frame indicator */
+);
+
+
+void ivas_set_bitstream_pointers(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+Decoder_State **reset_elements(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+
+void convertSerialToBytestream(
+ const uint16_t *const serial, /* i : input serial bitstream with values 0 and 1 */
+ const uint16_t num_bits, /* i : number of bits in the input bitstream */
+ uint8_t *const bytestream /* o : output compact bitstream (bytestream) */
+);
+
+void convertBytestreamToSerial(
+ const uint8_t *const bytestream, /* i : input compact bitstream (bytestream) */
+ const uint16_t num_bits, /* i : number of bits in the input bitstream */
+ uint16_t *const serial /* o : output serial bitstream with values 0 and 1 */
+);
+
+void mdct_switching_dec(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+void evs_dec_previewFrame(
+ uint8_t *bitstream, /* i : bitstream pointer */
+ int16_t bitstreamSize, /* i : bitstream size */
+ int16_t *partialCopyFrameType, /* o : frame type of the partial copy */
+ int16_t *partialCopyOffset /* o : offset of the partial copy relative to the primary copy */
+);
+
+
+void getPartialCopyInfo(
+ Decoder_State *st, /* i : decoder state structure */
+ int16_t *sharpFlag );
+
+void get_NextCoderType(
+ uint8_t *bitstream, /* i : bitstream */
+ int16_t *next_coder_type /* o : next coder type */
+);
+
+int16_t print_disclaimer(
+ FILE *fPtr );
+
+void autocorr(
+ const float *x, /* i : input signal */
+ float *r, /* o : autocorrelations vector */
+ const int16_t m, /* i : order of LP filter */
+ const int16_t len, /* i : window size */
+ const float *wind, /* i : window */
+ const int16_t rev_flag, /* i : flag to reverse window */
+ const int16_t sym_flag, /* i : symmetric window flag */
+ const int16_t no_thr /* i : flag to avoid thresholding */
+);
+
+/*! r: energy of prediction error */
+int16_t lev_dur(
+ float *a, /* o : LP coefficients (a[0] = 1.0) */
+ const float *r, /* i : vector of autocorrelations */
+ const int16_t m, /* i : order of LP filter */
+ float epsP[] /* o : prediction error energy */
+);
+
+/*! r: delay value in ns */
+int32_t get_delay(
+ const int16_t enc_dec, /* i : encoder/decoder flag */
+ const int32_t io_fs, /* i : input/output sampling frequency */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */
+);
+
+void decision_matrix_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ int16_t *hq_core_type /* o : HQ core type */
+);
+
+void signaling_enc(
+ Encoder_State *st /* i : encoder state structure */
+);
+
+int16_t signaling_mode1_tcx20_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t push /* i : flag to push indice */
+);
+
+void decision_matrix_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t *sharpFlag, /* o : formant sharpening flag */
+ int16_t *hq_core_type, /* o : HQ core type */
+ int16_t *core_switching_flag /* o : ACELP->HQ switching frame flag */
+);
+
+/*! r: LP filter stability */
+float lsf_stab(
+ const float *lsf, /* i : LSF vector */
+ const float *lsfold, /* i : old LSF vector */
+ const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const int16_t L_frame /* i : frame length */
+);
+
+void amr_wb_dec_init(
+ AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */
+);
+
+void hf_synth_amr_wb_init(
+ AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */
+);
+
+void hf_synth_amr_wb_reset(
+ AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */
+ ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */
+);
+
+void hf_synth_amr_wb(
+ 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 int32_t core_brate, /* i : core bitrate */
+ const int16_t output_frame, /* i : output frame length */
+ const float *Aq, /* i : quantized Az */
+ const float *exc, /* i : excitation at 12.8 kHz */
+ float *synth, /* i/o: synthesis signal at 12.8 kHz */
+ int16_t *amr_io_class, /* i : signal class (determined by FEC algorithm) */
+ float *synth_out, /* i/o: synthesis signal at output Fs */
+ float fmerit, /* i : classify parameter from FEC */
+ const int16_t *hf_gain, /* i : decoded HF gain */
+ const float *voice_factors, /* i : voicing factors */
+ const float pitch_buf[], /* i : pitch buffer */
+ const float ng_ener_ST, /* i : Noise gate - short-term energy */
+ const float *lsf_new /* i : ISF vector */
+);
+
+void hf_cod_init(
+ float *mem_hp400_enc, /* o : memory of hp 400 Hz filter */
+ float *mem_hf1_enc, /* o : HF band-pass filter memory */
+ float *mem_syn_hf_enc, /* o : HF synthesis memory */
+ float *mem_hf2_enc, /* o : HF band-pass filter memory */
+ float *gain_alpha /* o : smoothing gain for transitions between active and inactive frames */
+);
+
+void hf_cod(
+ const int32_t core_brate, /* i : core bitrate */
+ const float *speech16k, /* i : original speech at 16 kHz */
+ const float Aq[], /* i : quantized Aq */
+ const float exc[], /* i : excitation at 12.8 kHz */
+ float synth[], /* i : 12.8kHz synthesis signal */
+ int16_t *seed2_enc, /* i/o: random seed for HF noise gen */
+ float *mem_hp400_enc, /* i/o: memory of hp 400 Hz filter */
+ float *mem_syn_hf_enc, /* i/o: HF synthesis memory */
+ float *mem_hf1_enc, /* i/o: HF band-pass filter memory */
+ float *mem_hf2_enc, /* i/o: HF band-pass filter memory */
+ const int16_t *dtxHangoverCount,
+ float *gain_alpha, /* i/o: smoothing gain for transitions between active and inactive frames */
+ int16_t *hf_gain /* o : HF gain to be transmitted to decoder */
+);
+
+void hf_synth_init(
+ ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */
+);
+
+void hf_synth_reset(
+ ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */
+);
+
+void hf_synth(
+ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t output_frame, /* i : output frame length */
+ const float *Aq, /* i : quantized Az */
+ const float *exc, /* i : excitation at 12.8 kHz */
+ float *synth, /* i/o: 12.8kHz synthesis signal */
+ float *synth16k /* i/o: 16kHz synthesis signal */
+);
+
+int16_t lsp_convert_poly(
+ float w[], /* i/o: LSP or ISP parameters */
+ const int16_t L_frame, /* i : flag for up or down conversion */
+ const int16_t Opt_AMRWB /* i : flag for the AMR-WB IO mode */
+);
+
+/*! r: pulse position */
+int16_t findpulse(
+ const int16_t L_frame, /* i : length of the frame */
+ const float res[], /* i : residual signal */
+ const int16_t T0, /* i : integer pitch */
+ const int16_t enc_dec, /* i : flag enc/dec, 0 - enc, 1 - dec */
+ int16_t *sign /* i/o: sign of the maximum */
+);
+
+void fft_rel(
+ float x[], /* i/o: input/output vector */
+ const int16_t n, /* i : vector length */
+ const int16_t m /* i : log2 of vector length */
+);
+
+void ifft_rel(
+ float io[], /* i/o: input/output vector */
+ const int16_t n, /* i : vector length */
+ const int16_t m /* i : log2 of vector length */
+);
+
+void preemph(
+ float *signal, /* i/o: signal */
+ const float mu, /* i : preemphasis factor */
+ const int16_t L, /* i : vector size */
+ float *mem /* i/o: memory (x[-1]) */
+);
+
+void cb_shape(
+ const int16_t preemphFlag, /* i : flag for pre-emphasis */
+ const int16_t pitchFlag, /* i : flag for pitch sharpening */
+ const int16_t scramblingFlag, /* i : flag for phase scrambling */
+ const int16_t formantFlag, /* i : flag for formant sharpening */
+ const int16_t formantTiltFlag, /* i : flag for formant tilt */
+ const float g1, /* i : formant sharpening numerator weighting */
+ const float g2, /* i : formant sharpening denominator weighting */
+ const float *p_Aq, /* i : LP filter coefficients */
+ float *code, /* i/o: signal to shape */
+ const float tilt_code, /* i : tilt of code */
+ const float pt_pitch, /* i : pointer to current subframe fractional pitch*/
+ const int16_t L_subfr /* i : subfframe length */
+);
+
+void isp2a(
+ const float *isp, /* i : ISP vector (in the cosine domain) */
+ float *a, /* o : LP filter coefficients */
+ const int16_t m /* i : order of LP analysis */
+);
+
+void isp2isf(
+ const float isp[], /* i : isp[m] (range: -1<=val<1) */
+ float isf[], /* o : isf[m] normalized (range: 0<=val<=fs/2) */
+ const int16_t m, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+);
+
+void isf2isp(
+ const float isf[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */
+ float isp[], /* o : isp[m] (range: -1<=val<1) */
+ const int16_t m, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+);
+
+void reorder_isf(
+ float *isf, /* i/o: vector of isfs in the frequency domain (0..0.5)*/
+ const float min_dist, /* i : minimum required distance */
+ const int16_t n, /* i : LPC order */
+ const float Fs /* i : sampling frequency */
+);
+
+void lsp2lsf(
+ const float lsp[], /* i : isp[m] (range: -1<=val<1) */
+ float lsf[], /* o : isf[m] normalized (range: 0<=val<=fs/2) */
+ const int16_t m, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+);
+
+void lsf2lsp(
+ const float lsf[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */
+ float lsp[], /* o : isp[m] (range: -1<=val<1) */
+ const int16_t m, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+);
+
+void lsp2isp(
+ const float *lsp, /* i : LSP vector */
+ float *isp, /* o : ISP filter coefficients */
+ float *stable_isp, /* i/o: ISP filter coefficients */
+ const int16_t m /* i : order of LP analysis */
+);
+
+void isp2lsp(
+ const float *isp, /* i : LSP vector */
+ float *lsp, /* o : ISP filter coefficients */
+ float *stable_lsp, /* i/o: stable LSP filter coefficients */
+ const int16_t m /* i : order of LP analysis */
+);
+
+void reorder_lsf(
+ float *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5)*/
+ const float min_dist, /* i : minimum required distance */
+ const int16_t n, /* i : LPC order */
+ const int32_t Fs /* i : sampling frequency */
+);
+
+void CNG_exc(
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t L_frame, /* i : length of the frame */
+ float *Enew, /* i/o: decoded SID energy */
+ int16_t *seed, /* i/o: random generator seed */
+ float exc[], /* o : current non-enhanced excitation */
+ float exc2[], /* o : current enhanced excitation */
+ float *lp_ener, /* i/o: LP filtered E */
+ const int32_t last_core_brate, /* i : previous frame core bitrate */
+ int16_t *first_CNG, /* i/o: first CNG frame flag for energy init. */
+ int16_t *cng_ener_seed, /* i/o: random generator seed for CNG energy */
+ float bwe_exc[], /* o : excitation for SWB TBE */
+ const int16_t allow_cn_step, /* i : allow CN step */
+ int16_t *last_allow_cn_step, /* i/o: last CN_step */
+ const int16_t num_ho, /* i : number of selected hangover frames */
+ float q_env[],
+ float *lp_env,
+ float *old_env,
+ float *exc_mem,
+ float *exc_mem1,
+ int16_t *sid_bw,
+ int16_t *cng_ener_seed1,
+ float exc3[],
+ const int16_t Opt_AMR_WB, /* i : AMR-WB interop flag */
+ const int16_t element_mode /* i : IVAS Element mode */
+);
+
+void cng_params_upd(
+ const float lsp_new[], /* i : LSP aprameters */
+ const float exc2[], /* i : current enhanced excitation */
+ const int16_t L_frame, /* i : frame length */
+ int16_t *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers */
+ float ho_ener_circ[], /* o : energy buffer for CNG averaging */
+ int16_t *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging */
+ float ho_lsp_circ[], /* o : old LSP buffer for CNG averaging */
+ const int16_t enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */
+ float ho_env_circ[], /* i/o: Envelope buffer */
+ int16_t *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */
+ float cng_exc2_buf[], /* i/o: Excitation buffer */
+ int32_t cng_brate_buf[], /* i/o: last_active_brate buffer */
+ const int32_t last_active_brate, /* i : Last active bitrate */
+ const int16_t element_mode, /* i : Element mode */
+ const int16_t bwidth /* i : audio bandwidth */
+);
+
+void cng_params_postupd(
+ const int16_t ho_circ_ptr, /* i : pointer for CNG averaging buffers */
+ int16_t *cng_buf_cnt, /* i/o: counter for CNG store buffers */
+ const float *cng_exc2_buf, /* i : Excitation buffer */
+ const int32_t *cng_brate_buf, /* i : bitrate buffer */
+ float ho_env_circ[], /* i/o: Envelope buffer */
+ const int16_t element_mode, /* i : Element mode */
+ const int16_t bwidth /* i : audio bandwidth */
+);
+
+void calculate_hangover_attenuation_gain(
+ Encoder_State *st, /* i : encoder state structure */
+ float *att, /* o : attenuation factor */
+ const int16_t vad_hover_flag /* i : VAD hangover flag */
+);
+
+int16_t get_cng_mode(
+ const int32_t last_active_brate /* i : last active bitrate */
+);
+
+void disf_ns_28b(
+ int16_t *indice, /* i : quantized indices, use indice[0] = -1 in the decoder*/
+ float *isf_q /* o : ISF in the frequency domain (0..6400) */
+);
+
+void limit_T0(
+ const int16_t L_frame, /* i : length of the frame */
+ const int16_t delta, /* i : Half the close-loop searched interval */
+ const int16_t pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */
+ const int16_t limit_flag, /* i : flag for limits (0=restrained, 1=extended) */
+ const int16_t T0, /* i : rough pitch estimate around which the search is done */
+ const int16_t T0_frac, /* i : pitch estimate fractional part */
+ int16_t *T0_min, /* o : lower pitch limit */
+ int16_t *T0_max /* o : higher pitch limit */
+);
+
+/*! r: interpolated value */
+float interpolation(
+ const float *x, /* i : input vector */
+ const float *win, /* i : interpolation window */
+ const int16_t frac, /* i : fraction */
+ const int16_t up_samp, /* i : upsampling factor */
+ const int16_t nb_coef /* i : nb of filter coef */
+);
+
+void deemph(
+ float *signal, /* i/o: signal */
+ const float mu, /* i : deemphasis factor */
+ const int16_t L, /* i : vector size */
+ float *mem /* i/o: memory (y[-1]) */
+);
+
+/*! r: tilt of the code */
+float est_tilt(
+ const float *adpt_exc, /* i : adaptive excitation vector */
+ const float gain_pit, /* i : adaptive gain */
+ const float *fixe_exc, /* i : algebraic exctitation vector */
+ const float gain_code, /* i : algebraic code gain */
+ float *voice_fac, /* o : voicing factor */
+ const int16_t L_subfr, /* i : subframe size */
+ const int16_t flag_tilt /* i : flag for special tilt */
+);
+
+void weight_a(
+ const float *a, /* i : LP filter coefficients */
+ float *ap, /* o : weighted LP filter coefficients */
+ const float gamma, /* i : weighting factor */
+ const int16_t m /* i : order of LP filter */
+);
+
+void weight_a_subfr(
+ const int16_t nb_subfr, /* i : number of subframes */
+ const float *a, /* i : LP filter coefficients */
+ float *ap, /* o : weighted LP filter coefficients */
+ const float gamma, /* i : weighting factor */
+ const int16_t m /* i : order of LP filter */
+);
+
+void syn_12k8(
+ const int16_t L_frame, /* i : length of the frame */
+ const float *Aq, /* i : LP filter coefficients */
+ const float *exc, /* i : input signal */
+ float *synth, /* o : output signal */
+ float *mem, /* i/o: initial filter states */
+ const int16_t update_m /* i : update memory flag: 0 --> no memory update */
+); /* 1 --> update of memory */
+
+void syn_filt(
+ const float a[], /* i : LP filter coefficients */
+ const int16_t m, /* i : order of LP filter */
+ const float x[], /* i : input signal */
+ float y[], /* o : output signal */
+ const int16_t l, /* i : size of filtering */
+ float mem[], /* i/o: initial filter states */
+ const int16_t update_m /* i : update memory flag: 0 --> no memory update */
+); /* 1 --> update of memory */
+
+void synth_mem_updt2(
+ const int16_t L_frame, /* i : frame length */
+ const int16_t last_L_frame, /* i : frame length */
+ float old_exc[], /* i/o: excitation buffer */
+ float mem_syn_r[], /* i/o: synthesis filter memory */
+ float mem_syn2[], /* o : synthesis filter memory for find_target */
+ float mem_syn[], /* o : synthesis filter memory for find_target */
+ const int16_t dec /* i : flag for decoder indication */
+);
+
+void int_lsp(
+ const int16_t L_frame, /* i : length of the frame */
+ const float lsp_old[], /* i : LSPs from past frame */
+ const float lsp_new[], /* i : LSPs from present frame */
+ float *Aq, /* o : LP coefficients in both subframes */
+ const int16_t m, /* i : order of LP filter */
+ const float *int_coeffs, /* i : interpolation coefficients */
+ const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */
+);
+
+void int_lsp4(
+ const int16_t L_frame, /* i : length of the frame */
+ const float lsp_old[], /* i : previous end-frame LSPs */
+ const float lsp_mid[], /* i : current mid-frame LSPs */
+ const float lsp_new[], /* i : current end-frame LSPs */
+ float *Aq, /* o : LP coefficients in both subframes */
+ const int16_t m, /* i : order of LP filter */
+ int16_t relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */
+);
+
+/*! r: length of output */
+int16_t modify_Fs(
+ const float sigIn[], /* i : signal to decimate */
+ const int16_t lg, /* i : length of input */
+ const int32_t fin, /* i : frequency of input */
+ float sigOut[], /* o : decimated signal */
+ const int32_t fout, /* i : frequency of output */
+ float mem[], /* i/o: filter memory */
+ const int16_t nblp /* i : flag indicating if NB low-pass is applied */
+);
+
+void pred_lt4(
+ const float excI[], /* i : input excitation buffer */
+ float excO[], /* o : output excitation buffer */
+ const int16_t T0, /* i : integer pitch lag */
+ int16_t frac, /* i : fraction of lag */
+ const int16_t L_subfr, /* i : subframe size */
+ const float *win, /* i : interpolation window */
+ const int16_t nb_coef, /* i : nb of filter coef */
+ const int16_t up_sample /* i : up_sample */
+);
+
+void pred_lt4_tc(
+ float exc[], /* i : excitation buffer */
+ const int16_t T0, /* i : integer pitch lag */
+ int16_t frac, /* i : fraction of lag */
+ const float *win, /* i : interpolation window */
+ const int16_t imp_pos, /* i : glottal impulse position */
+ const int16_t i_subfr /* i : subframe index */
+);
+
+void residu(
+ const float *a, /* i : LP filter coefficients */
+ const int16_t m, /* i : order of LP filter */
+ const float *x, /* i : input signal (usually speech) */
+ float *y, /* o : output signal (usually residual) */
+ const int16_t l /* i : size of filtering */
+);
+
+void calc_residu(
+ const float *speech, /* i : weighted speech signal */
+ float *res, /* o : residual signal */
+ const float *p_Aq, /* i : quantized LP filter coefficients */
+ const int16_t L_frame /* i : size of frame */
+);
+
+/*! r: impulse response energy */
+float enr_1_Az(
+ const float Aq[], /* i : LP filter coefs */
+ const int16_t len /* i : impulse response length */
+);
+
+void Es_pred_enc(
+ float *Es_pred, /* o : predicited scaled innovation energy */
+ int16_t *Es_pred_indice, /* o : indice corresponding to above parameter */
+ const int16_t L_frame, /* i : length of the frame */
+ const int16_t L_subfr, /* i : length of the subframe */
+ const float *res, /* i : residual signal */
+ const float *voicing, /* i : normal. correlattion in three 1/2frames */
+ const int16_t nb_bits, /* i : allocated number of bits */
+ const int16_t no_ltp /* i : no_ltp flag */
+);
+
+void create_offset(
+ UWord32 *offset_scale1,
+ UWord32 *offset_scale2,
+ const int16_t mode,
+ const int16_t prediction_flag );
+
+float mslvq(
+ float *pTmp, /* i : M-dimensional input vector */
+ float *quant, /* o : quantized vector */
+ float *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */
+ int16_t *idx_lead, /* o : leader index for each 8-dim subvector */
+ int16_t *idx_scale, /* o : scale index for each subvector */
+ const float *w, /* i : weights for LSF quantization */
+ const int16_t mode, /* i : number indicating the coding mode */
+ const int16_t mode_glb, /* i : LVQ coding mode */
+ const int16_t pred_flag /* i : prediction flag (0: safety net, 1 - predictive )*/
+);
+
+void permute(
+ float *pTmp1, /* i/o: vector whose components are to be permuted */
+ const int16_t *perm /* i : permutation info (indexes that should be interchanged), max two perms */
+);
+
+void sort_desc_ind(
+ float *s,
+ const int16_t len,
+ int16_t *ind );
+
+float mslvq_cng(
+ int16_t idx_cv, /* i : index of cv from previous stage */
+ float *pTmp, /* i : 16 dimensional input vector */
+ float *quant, /* o : quantized vector */
+ float *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */
+ int16_t *idx_lead, /* o : leader index for each 8-dim subvector */
+ int16_t *idx_scale, /* o : scale index for each subvector */
+ const float *w /* i : weights for LSF quantization */
+);
+
+int16_t deindex_lvq_cng(
+ int16_t *index, /* i : index to be decoded, as an array of 3 short */
+ float *x_lvq, /* o : decoded codevector */
+ const int16_t idx_cv, /* i : relative mode_lvq, wrt START_CNG */
+ const int16_t no_bits /* i : number of bits for lattice */
+);
+
+void multiply32_32_64(
+ UWord32 x, /* i : operand 1 */
+ UWord32 y, /* i : operand 2 */
+ UWord32 *res /* o : result as array of two uint32 */
+);
+
+int16_t deindex_lvq(
+ int16_t *index, /* i : index to be decoded, as an array of 3 short */
+ float *x_lvq, /* o : decoded codevector */
+ const int16_t mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */
+ const int16_t sf_flag, /* i : safety net flag */
+ const int16_t no_bits /* i : number of bits for lattice */
+);
+
+int16_t vq_dec_lvq(
+ int16_t sf_flag, /* i : safety net flag */
+ float x[], /* o : Decoded vector */
+ int16_t indices[], /* i : Indices */
+ const int16_t stages, /* i : Number of stages */
+ const int16_t N, /* i : Vector dimension */
+ const int16_t mode, /* i : lvq coding type */
+ const int16_t no_bits /* i : no. bits for lattice */
+);
+
+void index_lvq(
+ float *quant, /* i : codevector to be indexed (2 8-dim subvectors) */
+ int16_t *idx_lead, /* i : leader class index for each subvector */
+ int16_t *idx_scale, /* i : scale index for each subvector */
+ const int16_t mode, /* i : integer signaling the quantizer structure for the current bitrate */
+ int16_t *index, /* o : encoded index (represented on 3 short each with 15 bits ) */
+ const int16_t prediction_flag /* i : predictive mode or not */
+);
+
+int16_t qlsf_ARSN_tcvq_Dec_16k(
+ float *y, /* o : Quantized LSF vector */
+ int16_t *indice, /* i : Indices */
+ const int16_t nBits /* i : number of bits */
+);
+
+int16_t lsf_bctcvq_encprm(
+ BSTR_ENC_HANDLE hBstr,
+ const int16_t *param_lpc,
+ const int16_t *bits_param_lpc,
+ const int16_t no_indices );
+
+int16_t lsf_bctcvq_decprm(
+ Decoder_State *st,
+ int16_t *param_lpc );
+
+ivas_error lsf_allocate(
+ const int16_t nBits, /* i : Number of bits to use for quantization */
+ const int16_t framemode, /* i : ISF quantizer mode */
+ const int16_t framemode_p, /* i : ISF quantizer mode */
+ int16_t *stages0, /* o : Number of stages for safety-net quantizer */
+ int16_t *stages1, /* o : Number of stages for predictive quantizer */
+ int16_t levels0[], /* o : Number of vectors for each stage for SFNET */
+ int16_t levels1[], /* o : Number of vectors for each stage for pred */
+ int16_t bits0[], /* o : Number of bits for each stage safety net */
+ int16_t bits1[] /* o : Number of bits for each stage predictive */
+);
+
+void disf_2s_36b(
+ int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ float *isf_q, /* o : quantized ISFs in the cosine domain */
+ float *mem_AR, /* i/o: quantizer memory for AR model */
+ float *mem_MA /* i/o: quantizer memory for MA model */
+);
+
+void disf_2s_46b(
+ int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ float *isf_q, /* o : quantized ISFs in the cosine domain */
+ float *mem_AR, /* o : quantizer memory for AR model */
+ float *mem_MA /* i/o: quantizer memory for MA model */
+);
+
+void re8_k2y(
+ const int16_t *k, /* i : Voronoi index k[0..7] */
+ const int16_t m, /* i : Voronoi modulo (m = 2^r = 1<=2) */
+ int16_t *y /* o : 8-dimensional point y[0..7] in RE8 */
+);
+
+void re8_PPV(
+ const float x[], /* i : point in R^8 */
+ int16_t y[] /* o : point in RE8 (8-dimensional integer vector) */
+);
+
+void enhancer(
+ const int16_t codec_mode, /* i : flag indicating Codec Mode */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t cbk_index, /* i : */
+ const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t L_frame, /* i : frame size */
+ const float voice_fac, /* i : subframe voicing estimation */
+ const float stab_fac, /* i : LP filter stablility measure */
+ const float norm_gain_code, /* i : normalized innovative cb. gain */
+ const float gain_inov, /* i : gain of the unscaled innovation */
+ float *gc_threshold, /* i/o: code threshold */
+ float *code, /* i/o: innovation */
+ float *exc2, /* i/o: adapt. excitation/total exc. */
+ const float gain_pit, /* i : Quantized pitch gain */
+ float *dispMem /* i/o: Phase dispersion algorithm memory */
+);
+
+void phase_dispersion(
+ const float gain_code, /* i : gain of code */
+ const float gain_pit, /* i : gain of pitch */
+ float code[], /* i/o: code vector */
+ const int16_t mode, /* i : level, 0=hi, 1=lo, 2=off */
+ float disp_mem[] /* i/o: static memory (size = 8) */
+);
+
+void re8_vor(
+ int16_t y[], /* i : point in RE8 (8-dimensional integer vector) */
+ int16_t *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */
+ int16_t k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 */
+ int16_t c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */
+ int16_t *ka /* o : identifier of absolute leader (needed to index c)*/
+);
+
+void edct(
+ const float *x, /* i : input signal */
+ float *y, /* o : output transform */
+ const int16_t length, /* i : length */
+ const int16_t element_mode /* i : IVAS element mode */
+);
+
+void edst(
+ const float *x, /* i : input signal */
+ float *y, /* o : output transform */
+ const int16_t length, /* i : length */
+ const int16_t element_mode /* i : IVAS element mode */
+);
+
+void edxt(
+ const float *x, /* i : input signal */
+ float *y, /* o : output transform */
+ const int16_t length, /* i : length */
+ const uint16_t kernelType, /* i : kernel type (0 - 3) */
+ const uint16_t synthesis /* i : nonzero for inverse */
+);
+
+void iedct_short(
+ const float *in, /* i : input vector */
+ float *out, /* o : output vector */
+ const int16_t segment_length, /* i : length */
+ const int16_t element_mode /* i : IVAS element mode */
+);
+
+void DoRTFT480(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+);
+
+void DoRTFT320(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+);
+
+void DoRTFT160(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+);
+
+void DoRTFT128(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+);
+
+void DoRTFT120(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+);
+
+void DoRTFT80(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+);
+
+void DoRTFT20(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+);
+
+void DoRTFT40(
+ float *x, /* i/o: real part of input and output data */
+ float *y /* i/o: imaginary part of input and output data */
+);
+
+void DoRTFTn(
+ float *x, /* i/o: real part of input and output data */
+ float *y, /* i/o: imaginary part of input and output data */
+ const int16_t n /* i : size of the FFT n=(2^k) up to 1024 */
+);
+
+void BASOP_cfft(
+ Word32 *re, /* i/o: real part */
+ Word32 *im, /* i/o: imag part */
+ Word16 s, /* i : stride real and imag part */
+ Word16 *scale /* i : scalefactor */
+);
+
+void fft(
+ float *re, /* i/o: real part */
+ float *im, /* i/o: imag part */
+ const int16_t length, /* i : length of fft */
+ const int16_t s /* i : sign */
+);
+
+void rfft(
+ float *x, /* i/o: values */
+ const float *w, /* i : window */
+ const int16_t length, /* i : length of fft */
+ const int16_t isign /* i : sign */
+);
+
+void sinq(
+ const float tmp, /* i : sinus factor cos(tmp*i+phi) */
+ const float phi, /* i : sinus phase cos(tmp*i+phi) */
+ const int16_t N, /* i : size of output */
+ float x[] /* o : output vector */
+);
+
+void edct2(
+ const int16_t n,
+ const int16_t isgn,
+ float *in,
+ float *a,
+ const int16_t *ip,
+ const float *w );
+
+void stat_noise_uv_mod(
+ const int16_t coder_type, /* i : coder type */
+ float noisiness, /* i : noisiness parameter */
+ const float *const lsp_old, /* i : old LSP vector at 4th sfr */
+ const float *const lsp_new, /* i : LSP vector at 4th sfr */
+ const float *const lsp_mid, /* i : LSP vector at 2nd sfr */
+ float *Aq, /* o : A(z) quantized for the 4 subframes */
+ float *exc2, /* o : excitation buffer */
+ const int16_t bfi, /* i : bad frame indicator */
+ float *ge_sm, /* i/o: smoothed excitation gain */
+ int16_t *uv_count, /* i/o: unvoiced counter */
+ int16_t *act_count, /* i/o: activation counter */
+ float lspold_s[], /* i/o: old LSP */
+ int16_t *noimix_seed, /* i/o: mixture seed */
+ float *st_min_alpha, /* i/o: minimum alpha */
+ float *exc_pe, /* i/o: memory of the preemphasis filter */
+ const int32_t bitrate, /* i : core bitrate */
+ const int16_t bwidth /* i : audio bandwidth */
+);
+
+void pre_echo_att(
+ float *Last_frame_ener, /* i/o: Energy of the last frame */
+ float *exc, /* i/o: Excitation of the current frame */
+ const int16_t attack_flag, /* i : attack flag (GSC or TC) */
+ const int16_t last_coder_type, /* i : Last coder type */
+ const int16_t L_frame /* i : frame length */
+);
+
+void limit_band_noise_level_calc(
+ const int16_t *wnorm, /* i : reordered norm of sub-vectors */
+ int16_t *limit, /* o : highest band of bit allocation */
+ const int32_t core_brate, /* i : core bitrate */
+ float *noise_level /* o : noise level */
+);
+
+/*! r: hqswb_clas */
+int16_t peak_avrg_ratio(
+ const int32_t total_brate, /* i : total bitrate */
+ const float *input_hi, /* i : input signal */
+ const int16_t N, /* i : number of coefficients */
+ int16_t *mode_count, /* i/o: HQ_HARMONIC mode count */
+ int16_t *mode_count1 /* i/o: HQ_NORMAL mode count */
+);
+
+/*! r: Number of coefficients in nf codebook */
+int16_t build_nf_codebook(
+ const int16_t flag_32K_env_ho, /* i : Envelope attenuation hangover flag */
+ const float *coeff, /* i : Coded spectral coefficients */
+ const int16_t *sfm_start, /* i : Subband start indices */
+ const int16_t *sfmsize, /* i : Subband widths */
+ const int16_t *sfm_end, /* i : Subband end indices */
+ const int16_t nb_sfm, /* i : Last coded band */
+ const int16_t *R, /* i : Per-band bit allocation */
+ float *CodeBook, /* o : Noise-fill codebook */
+ float *CodeBook_mod /* o : Densified noise-fill codebook */
+);
+
+void apply_noisefill_HQ(
+ const int16_t *R, /* i : bit allocation */
+ const int16_t length, /* i : input frame length */
+ const int16_t flag_32K_env_ho, /* i : envelope stability hangover flag */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t last_sfm, /* i : last coded subband */
+ const float *CodeBook, /* i : Noise-fill codebook */
+ const float *CodeBook_mod, /* i : Densified noise-fill codebook */
+ const int16_t cb_size, /* i : Codebook length */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t *sfmsize, /* i : Subband band width */
+ float *coeff /* i/o: coded/noisefilled spectrum */
+);
+
+void harm_bwe_fine(
+ const int16_t *R, /* i : bit allocation */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t high_sfm, /* i : higher transition band to BWE */
+ const int16_t num_sfm, /* i : total number of bands */
+ const int16_t *norm, /* i : quantization indices for norms */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ int16_t *prev_L_swb_norm, /* i/o: last normalize length */
+ float *coeff, /* i/o: coded/noisefilled normalized spectrum */
+ float *coeff_out, /* o : coded/noisefilled spectrum */
+ float *coeff_fine /* o : BWE fine structure */
+);
+
+void hvq_bwe_fine(
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t num_sfm, /* i : total number of bands */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t *peak_idx, /* i : Peak index */
+ const int16_t Npeaks, /* i : Number of peaks */
+ int16_t *peak_pos, /* i/o: Peak positions */
+ int16_t *prev_L_swb_norm, /* i/o: last normalize length */
+ float *coeff, /* i/o: coded/noisefilled normalized spectrum */
+ int16_t *bwe_peaks, /* o : Positions of peaks in BWE */
+ float *coeff_fine /* o : HVQ BWE fine structure */
+);
+
+void hq_fold_bwe(
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t num_sfm, /* i : Number of subbands */
+ float *coeff /* i/o: coded/noisefilled normalized spectrum */
+);
+
+void apply_nf_gain(
+ const int16_t nf_idx, /* i : noise fill gain index */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t *R, /* i : bit allocation */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ float *coeff /* i/o: coded/noisefilled normalized spectrum */
+
+);
+
+void hq_generic_fine(
+ float *coeff, /* i : coded/noisefilled normalized spectrum */
+ const int16_t last_sfm, /* i : Last coded band */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ float *coeff_out1 /* o : HQ GENERIC input */
+);
+
+void harm_bwe(
+ const float *coeff_fine, /* i : fine structure for BWE */
+ const float *coeff, /* i : coded/noisefilled normalized spectrum */
+ const int16_t num_sfm, /* i : Number of subbands */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t high_sfm, /* i : higher transition band to BWE */
+ const int16_t *R, /* i : bit allocation */
+ const int16_t prev_hq_mode, /* i : previous hq mode */
+ int16_t *norm, /* i/o: quantization indices for norms */
+ float *noise_level, /* i/o: noise levels for harmonic modes */
+ float *prev_noise_level, /* i/o: noise factor in previous frame */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ float *coeff_out, /* o : coded/noisefilled spectrum */
+ const int16_t element_mode /* i : element mode */
+);
+
+void hvq_bwe(
+ const float *coeff, /* i : coded/noisefilled spectrum */
+ const float *coeff_fine, /* i : BWE fine structure */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t *sfm_len, /* i : Subband length */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t prev_hq_mode, /* i : previous hq mode */
+ const int16_t *bwe_peaks, /* i : HVQ bwe peaks */
+ const int16_t bin_th, /* i : HVQ transition bin */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int32_t core_brate, /* i : Core bitrate */
+ const int16_t *R, /* i : Bit allocation */
+ int16_t *norm, /* i/o: quantization indices for norms */
+ float *noise_level, /* i/o: noise levels for harmonic modes */
+ float *prev_noise_level, /* i/o: noise factor in previous frame */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ float *coeff_out /* o : coded/noisefilled spectrum */
+);
+
+void hvq_concat_bands(
+ const int16_t pvq_bands, /* i : Number of bands in concatenated PVQ target */
+ const int16_t *sel_bnds, /* i : Array of selected high bands */
+ const int16_t n_sel_bnds, /* i : Number of selected high bands */
+ int16_t *hvq_band_start, /* o : Band start indices */
+ int16_t *hvq_band_width, /* o : Band widths */
+ int16_t *hvq_band_end /* o : Band end indices */
+);
+
+void hq_generic_bwe(
+ const int16_t HQ_mode, /* i : HQ mode */
+ float *coeff_out1, /* i/o: BWE input & temporary buffer */
+ const float *hq_generic_fenv, /* i : SWB frequency envelopes */
+ float *coeff_out, /* o : SWB signal in MDCT domain */
+ const int16_t hq_generic_offset, /* i : frequency offset for representing hq generic*/
+ int16_t *prev_L_swb_norm, /* i/o: last normalize length */
+ const int16_t hq_generic_exc_clas, /* i : hq generic hf excitation class */
+ const int16_t *sfm_end, /* i : End of bands */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int16_t num_env_bands, /* i : Number of coded envelope bands */
+ const int16_t *R /* i : Bit allocation */
+);
+
+void logqnorm_2(
+ const float *env_fl, /* o : index */
+ const int16_t L, /* i : codebook length */
+ const int16_t n_env_band, /* i : sub-vector size */
+ const int16_t nb_sfm, /* i : sub-vector size */
+ int16_t *ynrm, /* o : norm indices */
+ int16_t *normqlg2, /* o : quantized norm values */
+ const float *thren /* i : quantization thresholds */
+);
+
+void map_hq_generic_fenv_norm(
+ const int16_t hqswb_clas, /* i : signal classification flag */
+ const float *hq_generic_fenv, /* i : HQ GENERIC envelope */
+ int16_t *ynrm, /* o : high band norm indices */
+ int16_t *normqlg2, /* o : high band norm values */
+ const int16_t num_env_bands, /* i : Number coded envelope bands */
+ const int16_t nb_sfm, /* i : Number of envelope bands */
+ const int16_t hq_generic_offset /* i : Freq offset for HQ GENERIC */
+);
+
+/*! r: Number of bits consumed for the delta coding */
+int16_t calc_nor_delta_hf(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const float *t_audio, /* i : transform-domain coefficients */
+ int16_t *ynrm, /* i/o: norm indices */
+ int16_t *Rsubband, /* i/o: sub-band bit allocation */
+ const int16_t num_env_bands, /* i : Number coded envelope bands */
+ const int16_t nb_sfm, /* i : Number of envelope bands */
+ const int16_t *sfmsize, /* i : band length */
+ const int16_t *sfm_start, /* i : Start index of bands */
+ const int16_t core_sfm /* i : index of the end band for core */
+);
+
+/*! r: Number of bits consumed for the delta coding */
+int16_t get_nor_delta_hf(
+ Decoder_State *st, /* i/o: Decoder state */
+ int16_t *ynrm, /* i/o: norm indices */
+ int16_t *Rsubband, /* i/o: sub-band bit allocation */
+ const int16_t num_env_bands, /* i : Number coded envelope bands */
+ const int16_t nb_sfm, /* i : Number of envelope bands */
+ const int16_t core_sfm ); /* i : index of the end band for core */
+
+void hq_wb_nf_bwe(
+ const float *coeff, /* i : coded/noisefilled normal. spectrum */
+ const int16_t is_transient, /* i : is transient flag */
+ const int16_t prev_bfi, /* i : previous bad frame indicator */
+ const float *normq_v, /* i : norms */
+ const int16_t num_sfm, /* i : Number of subbands */
+ const int16_t *sfm_start, /* i : Subband start coefficient */
+ const int16_t *sfm_end, /* i : Subband end coefficient */
+ const int16_t *sfmsize, /* i : Subband band width */
+ const int16_t last_sfm, /* i : last coded subband */
+ const int16_t *R, /* i : bit allocation */
+ const int16_t prev_is_transient, /* i : previous transient flag */
+ float *prev_normq, /* i/o: previous norms */
+ float *prev_env, /* i/o: previous noise envelopes */
+ int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
+ float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */
+ int16_t *prev_R, /* i/o: previous frame bit allocation info. */
+ float *coeff_out /* o : coded/noisefilled spectrum */
+);
+
+/*! r: Number of bits */
+int16_t encode_envelope_indices(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t num_sfm, /* i : Number of subbands */
+ const int16_t numnrmibits, /* i : Bitrate of fall-back coding mode */
+ int16_t *difidx, /* i/o: Diff indices/encoded diff indices */
+ int16_t *LCmode, /* o : Coding mode */
+ const int16_t flag_pack, /* i : indicator of packing or estimating bits */
+ const int16_t flag_HQ2, /* i : indicator of HQ2 core */
+ const int16_t is_transient /* i : transient flag */
+);
+
+void diff_envelope_coding(
+ const int16_t is_transient, /* i : transient indicator */
+ const int16_t num_env_bands, /* i : number of envelope bands to code */
+ const int16_t start_norm, /* i : start of envelope coding */
+ int16_t *ynrm, /* i/o: quantization indices for norms */
+ int16_t *normqlg2, /* i/o: quantized norms */
+ int16_t *difidx /* o : differential code */
+);
+
+/*! r: Number of bits */
+int16_t decode_envelope_indices(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int16_t start_norm, /* i : First SDE encoded norm */
+ const int16_t num_sfm, /* i : Number of norms */
+ const int16_t numnrmibits, /* i : Bitrate of fall-back coding mode */
+ int16_t *ynrm, /* o : Decoded norm indices */
+ const int16_t flag_HQ2, /* i : indicator of HQ2 core */
+ const int16_t is_transient /* i : transient flag */
+);
+
+/*! r: Number of bits */
+void dequantize_norms(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int16_t start_norm, /* i : First SDE encoded norm */
+ const int16_t num_sfm, /* i : Number of norms */
+ const int16_t is_transient, /* i : Transient flag */
+ int16_t *ynrm, /* o : Decoded norm indices */
+ int16_t *normqlg2 /* o : Log2 of decoded norms */
+);
+
+void hq_configure(
+ const int16_t length, /* i : Frame length */
+ const int16_t hqswb_clas, /* i : HQ SWB class */
+ const int32_t core_brate, /* i : core bitrate */
+ int16_t *num_sfm, /* o : Total number of subbands */
+ int16_t *nb_sfm, /* o : Total number of coded bands */
+ int16_t *start_norm, /* o : First norm to be SDE encoded */
+ int16_t *num_sde_norm, /* o : Number of norms for SDE encoding */
+ int16_t *numnrmibits, /* o : Number of bits in fall-back norm encoding */
+ int16_t *hq_generic_offset, /* o : Freq offset for HQ GENERIC */
+ int16_t *sfmsize, /* o : Subband bandwidths */
+ int16_t *sfm_start, /* o : Subband start coefficients */
+ int16_t *sfm_end /* o : Subband end coefficients */
+);
+
+/*! r: Consumed bits */
+int16_t hvq_enc(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t hvq_bits, /* i : HVQ bit budget */
+ const int16_t Npeaks, /* i : Number of peaks */
+ const int16_t *ynrm, /* i : Envelope coefficients */
+ int16_t *R, /* i/o: Bit allocation/updated bit allocation */
+ int16_t *peaks, /* i/o: Peak pos. / Encoded peak pos. */
+ float *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */
+ float *noise_level, /* o : Quantized noise level */
+ const float *pe_gains, /* i : Peak gains */
+ const float *coefs, /* i : spectrum coefficients */
+ float *coefs_out /* o : encoded spectrum coefficients */
+);
+
+/*! r: Consumed bits */
+int16_t hq_classifier_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t length, /* i : Frame length */
+ const float *coefs, /* i : Spectral coefficients */
+ const int16_t is_transient, /* i : Transient flag */
+ int16_t *Npeaks, /* o : Number of identified peaks */
+ int16_t *peaks, /* o : Peak indices */
+ float *pe_gains, /* o : Peak gains */
+ float *nf_gains, /* o : Noise-fill gains */
+ int16_t *hqswb_clas /* o : HQ class */
+);
+
+/*! r: Consumed bits */
+int16_t hq_classifier_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const int32_t core_brate, /* i : Core bitrate */
+ const int16_t length, /* i : Frame length */
+ int16_t *is_transient, /* o : Transient flag */
+ int16_t *hqswb_clas /* o : HQ class */
+);
+
+void hq_bit_allocation(
+ const int32_t core_brate, /* i : Core bitrate */
+ const int16_t length, /* i : Frame length */
+ const int16_t hqswb_clas, /* i : HQ class */
+ int16_t *num_bits, /* i/o: Remaining bit budget */
+ const int16_t *normqlg2, /* i : Quantized norms */
+ const int16_t nb_sfm, /* i : Number sub bands to be encoded */
+ const int16_t *sfmsize, /* i : Sub band bandwidths */
+ float *noise_level, /* o : HVQ noise level */
+ int16_t *R, /* o : Bit allocation per sub band */
+ int16_t *Rsubband, /* o : Fractional bit allocation (Q3) */
+ int16_t *sum, /* o : Sum of allocated shape bits */
+ int16_t *core_sfm, /* o : Last coded band in core */
+ const int16_t num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */
+);
+
+void enforce_zero_for_min_envelope(
+ const int16_t hqswb_clas, /* i : HQ coding class */
+ const int16_t *ynrm, /* i : Envelope indices */
+ float *coefsq, /* i/o: Quantized spectrum/zeroed spectrum */
+ int16_t nb_sfm, /* i : Number of coded sub bands */
+ const int16_t *sfm_start, /* i : Sub band start indices */
+ const int16_t *sfm_end /* i : Sub band end indices */
+);
+
+/*! r: Number of assigned gain bits */
+int16_t assign_gain_bits(
+ const int16_t core, /* i : HQ core */
+ const int16_t BANDS, /* i : Number of bands */
+ const int16_t *band_width, /* i : Sub band bandwidth */
+ int16_t *Rk, /* i/o: Bit allocation/Adjusted bit alloc. (Q3) */
+ int16_t *gain_bits_array, /* o : Assigned gain bits */
+ int16_t *Rcalc /* o : Bit budget for shape quantizer (Q3) */
+);
+
+void apply_envelope(
+ const float *coeff, /* i/o: Coded/noisefilled normalized spectrum */
+ const int16_t *norm, /* i : Envelope */
+ const float *norm_adj, /* i : Envelope adjustment */
+ const int16_t num_sfm, /* i : Total number of bands */
+ const int16_t last_sfm, /* i : Last coded band */
+ const int16_t HQ_mode, /* i : HQ mode */
+ const int16_t length, /* i : Frame length */
+ const int16_t *sfm_start, /* i : Sub band start indices */
+ const int16_t *sfm_end, /* i : Sub band end indices */
+ float *normq_v, /* o : Envelope with adjustment */
+ float *coeff_out, /* o : coded/noisefilled spectrum */
+ float *coeff_out1 /* o : noisefilled spectrum for HQ SWB BWE */
+);
+
+void apply_envelope_enc(
+ float *coeff, /* i/o: Normalized/scaled normalized spectrum */
+ const int16_t *norm, /* i : Envelope */
+ const int16_t num_sfm, /* i : Total number of bands */
+ const int16_t *sfm_start, /* i : Sub band start indices */
+ const int16_t *sfm_end /* i : Sub band end indices */
+);
+
+/*! r: Leading_sign_index, index, size, k_val */
+PvqEntry mpvq_encode_vec(
+ const int16_t *vec_in, /* i : Signed pulse train */
+ const int16_t dim_in, /* i : Dimension */
+ int16_t k_val_local /* i/o: Num unit pulses */
+);
+
+/*! r: Size, dim, k_val */
+PvqEntry get_size_mpvq_calc_offset(
+ const int16_t dim_in, /* i : Dimension */
+ const int16_t k_val_in, /* i : Num unit pulses */
+ uint32_t *h_mem /* o : Offsets */
+);
+
+void mpvq_decode_vec(
+ const PvqEntry *entry, /* i : Sign_ind, index, dim, k_val */
+ uint32_t *h_mem, /* i : A/U offsets */
+ int16_t *vec_out /* o : Pulse train */
+);
+
+/*! r: Multiplication result */
+uint32_t UMult_32_32(
+ const uint32_t UL_var1, /* i : factor 1 */
+ const uint32_t UL_var2 /* i : factor 2 */
+);
+
+/*! r: inverse */
+uint32_t UL_inverse(
+ const uint32_t UL_val, /* i : input value Q_exp */
+ int16_t *exp /* i/o: input exp / result exp */
+);
+
+/*! r: ratio */
+Word16 ratio(
+ const Word32 numer, /* i : numerator */
+ const Word32 denom, /* i : denominator */
+ Word16 *expo /* i/o: input exp / result exp */
+);
+
+/*! r: Angle between 0 and EVS_PI/2 radian (Q14) */
+Word16 atan2_fx(
+ const Word32 y, /* i : near side (Argument must be positive) (Q15) */
+ const Word32 x /* i : opposite side (Q15) */
+);
+
+void pvq_encode_frame(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const float *coefs_norm, /* i : normalized coefficients to encode */
+ float *coefs_quant, /* o : quantized coefficients */
+ float *gopt, /* o : optimal shape gains */
+ int16_t *npulses, /* o : number of pulses per band */
+ int16_t *pulse_vector, /* o : non-normalized pulse shapes */
+ const int16_t *sfm_start, /* i : indices of first coefficients in the bands */
+ const int16_t *sfm_end, /* i : indices of last coefficients in the bands */
+ const int16_t *sfmsize, /* i : band sizes */
+ const int16_t nb_sfm, /* i : total number of bands */
+ const int16_t *R, /* i : bitallocation per band (Q3) */
+ const int16_t pvq_bits, /* i : number of bits avaiable */
+ const int16_t core /* i : core */
+);
+
+void pvq_decode_frame(
+ Decoder_State *st, /* i/o: Decoder state */
+ float *coefs_quant, /* o : quantized coefficients */
+ int16_t *npulses, /* o : number of pulses per band */
+ int16_t *pulse_vector, /* o : non-normalized pulse shapes */
+ const int16_t *sfm_start, /* i : indices of first coeffs in the bands */
+ const int16_t *sfm_end, /* i : indices of last coeffs in the bands */
+ const int16_t *sfmsize, /* i : band sizes */
+ const int16_t nb_sfm, /* i : total number of bands */
+ const int16_t *R, /* i : bitallocation per band (Q3) */
+ const int16_t pvq_bits, /* i : number of bits avaiable */
+ const int16_t core /* i : core */
+);
+
+void srt_vec_ind(
+ const int16_t *linear, /* linear input */
+ int16_t *srt, /* sorted output */
+ int16_t *I, /* index for sorted output */
+ const int16_t length );
+
+void srt_vec_ind_f(
+ const float *linear, /* linear input */
+ float *srt, /* sorted output */
+ int16_t *I, /* index for sorted output */
+ const int16_t length /* length of vector */
+);
+
+/*! r: floor(sqrt(input)) */
+uint32_t floor_sqrt_exact(
+ const uint32_t input /* i : unsigned input [0.. UINT_MAX/4] */
+);
+
+void fine_gain_quant(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t *ord, /* i : Indices for energy order */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int16_t *gain_bits, /* i : Gain adjustment bits per sub band */
+ float *fg_pred, /* i/o: Predicted gains / Corrected gains */
+ const float *gopt /* i : Optimal gains */
+);
+
+void apply_gain(
+ const int16_t *ord, /* i : Indices for energy order */
+ const int16_t *band_start, /* i : Sub band start indices */
+ const int16_t *band_end, /* i : Sub band end indices */
+ const int16_t num_sfm, /* i : Number of bands */
+ const float *gains, /* i : Band gain vector */
+ float *xq /* i/o: float synthesis / gain adjusted synth */
+);
+
+void fine_gain_pred(
+ const int16_t *sfm_start, /* i : Sub band start indices */
+ const int16_t *sfm_end, /* i : Sub band end indices */
+ const int16_t *sfm_size, /* i : Sub band bandwidths */
+ const int16_t *i_sort, /* i : Energy sorting indices */
+ const int16_t *K, /* i : Number of pulses per band */
+ const int16_t *maxpulse, /* i : Maximum pulse per band */
+ const int16_t *R, /* i : Bits per sub band (Q3) */
+ const int16_t num_sfm, /* i : Number of sub bands */
+ float *xq, /* i/o: Quantized vector /quantized vector with finegain adj */
+ int16_t *y, /* i/o: Quantized vector */
+ float *fg_pred, /* o : Predicted fine gains */
+ const int16_t core /* i : Core */
+);
+
+void fine_gain_dec(
+ Decoder_State *st, /* i/o: Decoder state struct */
+ const int16_t *ord, /* i : Indices for energy order */
+ const int16_t num_sfm, /* i : Number of bands */
+ const int16_t *gain_bits, /* i : Gain adjustment bits per sub band */
+ float *fg_pred /* i/o: Predicted gains / Corrected gains */
+);
+
+void get_max_pulses(
+ const int16_t *band_start, /* i : Sub band start indices */
+ const int16_t *band_end, /* i : Sub band end indices */
+ const int16_t *k_sort, /* i : Indices for sorting by energy */
+ const int16_t *npulses, /* i : Pulses per sub band */
+ const int16_t BANDS, /* i : Number of bands */
+ int16_t *inp_vector, /* i/o: Encoded shape vectors */
+ int16_t *maxpulse /* o : Maximum pulse height per band */
+);
+
+Word32 ar_div(
+ Word32 num,
+ Word32 denum );
+
+void ar_encoder_start(
+ PARCODEC arInst,
+ TCQ_PBITSTREAM bsInst,
+ int16_t max_bits );
+
+void ar_decoder_start(
+ PARCODEC arInst,
+ TCQ_PBITSTREAM bsInst );
+
+void ar_encoder_done(
+ PARCODEC arInst );
+
+void ar_decoder_done(
+ PARCODEC arInst );
+
+float GetISCScale(
+ float *quants,
+ int16_t size,
+ Word32 bits_fx,
+ float *magn,
+ float *qscale,
+ Word32 *surplus_fx,
+ float *pulses,
+ int32_t *savedstates,
+ int16_t noTCQ,
+ int32_t *nzpout,
+ int16_t *bcount,
+ float *abuffer,
+ float *mbuffer,
+ float *sbuffer );
+
+Word32 Mult_32_16(
+ Word32 a,
+ Word16 b );
+
+Word32 Mult_32_32(
+ Word32 a,
+ Word32 b );
+
+void decode_position_ari_fx(
+ PARCODEC pardec,
+ Word16 size,
+ Word16 npulses,
+ Word16 *nz,
+ Word32 *position );
+
+void decode_magnitude_usq_fx(
+ ARCODEC *pardec,
+ Word16 size,
+ Word16 npulses,
+ Word16 nzpos,
+ Word32 *positions,
+ Word32 *out );
+
+void decode_mangitude_tcq_fx(
+ ARCODEC *pardec,
+ Word16 size,
+ Word16 npulses,
+ Word16 nzpos,
+ Word32 *positions,
+ Word32 *out,
+ Word32 *surplus_fx );
+
+void decode_signs_fx(
+ ARCODEC *pardec,
+ Word16 size,
+ Word32 *out );
+
+void srt_vec_ind_fx(
+ const Word32 *linear,
+ Word32 *srt,
+ Word16 *I,
+ Word16 length );
+
+Word16 GetScale_fx(
+ Word16 blen,
+ Word32 bits_fx /*Q16*/,
+ Word32 *surplus_fx /*Q16*/
+);
+
+void bit_allocation_second_fx(
+ Word32 *Rk,
+ Word32 *Rk_sort,
+ Word16 BANDS,
+ const Word16 *band_width,
+ Word16 *k_sort,
+ Word16 *k_num,
+ const Word16 *p2a_flags,
+ const Word16 p2a_bands,
+ const Word16 *last_bitalloc,
+ const Word16 input_frame );
+
+Word32 encode_position_ari_fx(
+ PARCODEC parenc,
+ float *quants,
+ Word16 size,
+ Word32 *est_bits_frame_fx );
+
+Word32 encode_magnitude_tcq_fx(
+ ARCODEC *parenc,
+ float *magn_fx,
+ Word16 size,
+ Word16 npulses,
+ Word16 nzpos,
+ Word32 *savedstates,
+ Word32 *est_frame_bits_fx );
+
+Word32 encode_signs_fx(
+ ARCODEC *parenc,
+ float *magn,
+ Word16 size,
+ Word16 npos,
+ Word32 *est_frame_bits_fx );
+
+Word32 encode_magnitude_usq_fx(
+ ARCODEC *parenc,
+ float *magn_fx,
+ Word16 size,
+ Word16 npulses,
+ Word16 nzpos,
+ Word32 *est_frame_bits_fx );
+
+ivas_error tcq_core_LR_enc(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ int32_t inp_vector[],
+ const float coefs_norm[],
+ float coefs_quant[],
+ const int16_t bit_budget, /* number of bits */
+ const int16_t nb_sfm,
+ const int16_t *sfm_start,
+ const int16_t *sfm_end,
+ const int16_t *sfmsize,
+ Word32 *Rk_fx,
+ int16_t *npulses,
+ int16_t *k_sort,
+ const int16_t *p2a_flags,
+ const int16_t p2a_bands,
+ const int16_t *last_bitalloc,
+ const int16_t input_frame,
+ const int16_t adjustFlag,
+ const int16_t is_transient );
+
+void tcq_core_LR_dec(
+ Decoder_State *st,
+ int32_t *inp_vector,
+ const int16_t bit_budget,
+ const int16_t bands,
+ const int16_t *band_start,
+ const int16_t *band_width,
+ Word32 *Rk_fx,
+ int16_t npulses[],
+ int16_t *k_sort,
+ const int16_t *p2a_flags,
+ const int16_t p2a_bands,
+ const int16_t *last_bitalloc,
+ const int16_t input_frame,
+ const int16_t adjustFlag,
+ const int16_t *is_transient );
+
+void InitLSBTCQ(
+ int16_t *bcount );
+
+void TCQLSB(
+ int16_t bcount,
+ float *abuffer,
+ float *mbuffer,
+ float *sbuffer,
+ int16_t *dpath );
+
+void RestoreTCQ(
+ float *magn,
+ int16_t size,
+ int16_t *bcount,
+ float *mbuffer );
+
+void SaveTCQdata(
+ PARCODEC arInst,
+ int16_t *dpath,
+ int16_t bcount );
+
+void LoadTCQdata(
+ PARCODEC arInst,
+ int16_t *dpath,
+ int16_t bcount );
+
+void RestoreTCQdec(
+ int32_t *magn,
+ int16_t size,
+ int16_t *bcount,
+ float *mbuffer );
+
+void TCQLSBdec(
+ int16_t *dpath,
+ float *mbuffer,
+ int16_t bcount );
+
+void bit_allocation_second_fx(
+ Word32 *Rk,
+ Word32 *Rk_sort,
+ Word16 BANDS,
+ const Word16 *band_width,
+ Word16 *k_sort,
+ Word16 *k_num,
+ const Word16 *p2a_flags,
+ const Word16 p2a_bands,
+ const Word16 *last_bitalloc,
+ const Word16 input_frame );
+
+void io_ini_enc(
+ const int32_t argc, /* i : command line arguments number */
+ char *argv[], /* i : command line arguments */
+ FILE **f_input, /* o : input signal file */
+ FILE **f_stream, /* o : output bitstream file */
+ FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */
+ FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */
+ FILE **f_metadata, /* o : metadata files (NULL if N/A) */
+ FILE **f_rf, /* o : channel aware configuration file */
+ int16_t *quietMode, /* o : limit printouts */
+ int16_t *noDelayCmp, /* o : turn off delay compensation */
+ Encoder_Struct *st /* o : IVAS encoder structure */
+);
+
+void read_next_rfparam(
+ int16_t *rf_fec_offset, /* o : RF offset */
+ int16_t *rf_fec_indicator, /* o : RF FEC indicator */
+ FILE *f_rf /* i : file pointer to read parameters */
+);
+
+void read_next_brate(
+ int32_t *total_brate, /* i/o: total bitrate */
+ const int32_t last_total_brate, /* i : last total bitrate */
+ FILE *f_rate, /* i : bitrate switching profile (0 if N/A) */
+ const int16_t element_mode, /* i : IVAS element mode */
+ int32_t input_Fs, /* i : input sampling frequency */
+ int16_t *Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ int16_t *Opt_SC_VBR, /* i/o: SC-VBR flag */
+ int16_t *codec_mode /* i/o: Mode 1 or 2 */
+);
+
+void read_next_bwidth(
+ int16_t *max_bwidth, /* i/o: maximum encoded bandwidth */
+ FILE *f_bwidth, /* i : bandwidth switching profile (0 if N/A) */
+ int32_t *bwidth_profile_cnt, /* i/o: counter of frames for bandwidth switching profile file */
+ int32_t input_Fs /* i : input sampling rate */
+);
+
+
+ivas_error init_encoder(
+ Encoder_State *st, /* i/o: state structure */
+ Encoder_Struct *st_ivas, /* i/o: encoder state structure */
+ const int16_t idchan, /* i : channel ID */
+ const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */
+ const int16_t interval_SID, /* i : interval for SID update */
+ const int16_t vad_only_flag, /* i : flag to indicate front-VAD structure */
+ const ISM_MODE ism_mode /* i : ISM mode */
+ ,
+ const int32_t element_brate /* element bitrate */
+);
+
+void LPDmem_enc_init(
+ LPD_state_HANDLE hLPDmem /* i/o: LP memories */
+);
+
+void destroy_cldfb_encoder(
+ Encoder_State *st /* i/o: state structure */
+);
+ivas_error evs_enc(
+ Encoder_State *st, /* i/o: state structure */
+ const int16_t *data, /* i : input signal */
+ float *mem_hp20_in, /* i/o: hp20 filter memory */
+ const int16_t n_samples /* i : number of input samples */
+);
+void amr_wb_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t *data, /* i : input signal */
+ float *mem_hp20_in, /* i/o: hp20 filter memory */
+ const int16_t n_samples /* i : number of input samples */
+);
+
+void sc_vbr_enc_init(
+ SC_VBR_ENC_HANDLE hSC_VBR /* i/o: SC-VBR encoder handle */
+);
+
+void amr_wb_enc_init(
+ AMRWB_IO_ENC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO encoder handle */
+);
+
+void pre_proc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t input_frame, /* i : frame length */
+ float old_inp_12k8[], /* i/o: buffer of old input signal */
+ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */
+ float **inp, /* o : ptr. to inp. signal in the current frame*/
+ float fr_bands[2 * NB_BANDS], /* i : energy in frequency bands */
+ float *ener, /* o : residual energy from Levinson-Durbin */
+#ifndef FIX_I4_OL_PITCH
+ int16_t pitch_orig[3], /* o : open-loop pitch values for quantization */
+#endif
+ float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */
+ float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */
+ float epsP[M + 1], /* i/o: LP prediction errors */
+ float lsp_new[M], /* i/o: LSPs at the end of the frame */
+ float lsp_mid[M], /* i/o: LSPs in the middle of the frame */
+ int16_t *vad_hover_flag, /* i : VAD hangover flag */
+ int16_t *attack_flag, /* o : attack flag */
+ float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
+ int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */
+ float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */
+ float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */
+ int16_t *hq_core_type /* o : HQ core type */
+);
+#endif
+
+/*! r: HQ_CORE/TCX_20_CORE decision */
+int16_t mdct_classifier(
+ Encoder_State *st, /* i/o: Encoder state variable */
+ const float *fft_buff, /* i : FFT spectrum from fft_rel */
+ const float enerBuffer[], /* i : energy buffer */
+ const int32_t brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */
+);
+
+void MDCT_selector(
+ Encoder_State *st, /* i/o: Encoder State */
+ const float sp_floor, /* i : Noise floor estimate */
+ const float Etot, /* i : Total energy */
+ const float cor_map_sum, /* i : sum of correlation map */
+ const float enerBuffer[] /* i : energy buffer */
+);
+
+void MDCT_selector_reset(
+ TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */
+);
+
+void MDCT_classifier_reset(
+ TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */
+);
+
+ivas_error acelp_core_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float inp[], /* i : input signal of the current frame */
+ const float ener, /* i : residual energy from Levinson-Durbin */
+ float A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */
+ float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes */
+ const float epsP[M + 1], /* i : LP prediction errors */
+ float lsp_new[M], /* i : LSPs at the end of the frame */
+ float lsp_mid[M], /* i : LSPs in the middle of the frame */
+ const int16_t vad_hover_flag, /* i : VAD hangover flag */
+ const int16_t attack_flag, /* i : attack flag (GSC or TC) */
+ float bwe_exc_extended[], /* i/o: bandwidth extended excitation */
+ float *voice_factors, /* o : voicing factors */
+ float old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */
+ float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */
+ int16_t *unbits, /* o : number of unused bits */
+ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
+ const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */
+);
+
+ivas_error acelp_core_switch_dec_bfi(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+void acelp_core_switch_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float inp12k8[], /* i : input signal @12.8 kHz */
+ const float inp16k[], /* i : input signal @16 kHz */
+ const float A[NB_SUBFR16k * ( M + 1 )] /* i : A(z) unquantized for the 4 subframes */
+);
+
+/*! r: length of output */
+int16_t modify_Fs_intcub3m_sup(
+ const float sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */
+ const int16_t lg, /* i : length of input */
+ const int32_t fin, /* i : frequency of input */
+ float sigOut[], /* o : decimated signal */
+ const int32_t fout, /* i : frequency of output */
+ int16_t *delayout /* o : delay of output */
+);
+
+void core_switching_OLA(
+ const float *mem_over_hp, /* i : upsampling filter memory */
+ const int16_t last_L_frame, /* i : last L_frame lengthture */
+ const int32_t output_Fs, /* i : output sampling rate */
+ float *synth, /* i/o: synthesized signal from HQ core */
+ const float *synth_subfr_out, /* i : synthesized signal from ACELP core */
+ float *synth_subfr_bwe, /* i : synthesized BWE from ACELP core */
+ const int16_t output_frame, /* i : output frame length */
+ const int16_t bwidth /* i : output bandwidth */
+);
+
+void retro_interp4_5(
+ const float *syn,
+ float *pst_old_syn );
+
+void retro_interp5_4(
+ float *pst_old_syn );
+
+void core_switching_hq_prepare_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ int16_t *num_bits, /* i/o: bit budget update */
+ const int16_t input_frame, /* i : input frame length */
+ float *wtda_audio,
+ const float *audio );
+
+void core_switching_hq_prepare_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t *num_bits, /* i/o: bit budget update */
+ const int16_t input_frame /* i : input frame length */
+);
+
+ivas_error acelp_core_switch_dec(
+ Decoder_State *st, /* i/o: decoder structure */
+ float *synth_subfr_out, /* o : synthesized ACELP subframe */
+ float *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE */
+ const int16_t output_frame, /* i : input frame length */
+ const int16_t core_switching_flag, /* i : core switching flag */
+ float *mem_synth, /* o : synthesis to overlap */
+ const int16_t nchan_out /* i : number of output channels */
+);
+
+void space_lsfs(
+ float *lsfs,
+ const int16_t order );
+
+void lsp2a(
+ float *pc_in,
+ float *freq,
+ const int16_t order );
+
+void lsp_weights(
+ const float *lsps,
+ float *weight,
+ const int16_t order );
+
+void a2lsp_stab(
+ const float *a, /* i : LP filter coefficients */
+ float *lsp, /* o : Line spectral pairs */
+ const float *old_lsp /* i : LSP vector from past frame */
+);
+
+void lsp2a_stab(
+ const float *lsp, /* i : LSF vector (in the cosine domain) */
+ float *a, /* o : LP filter coefficients */
+ const int16_t m /* i : order of LP analysis */
+);
+
+void isf2lsf(
+ const float *isf, /* i : ISF vector */
+ float *lsf, /* o : LSF vector */
+ float *stable_lsp, /* i/o: LSF vector */
+ const int16_t m, /* i : order of LP analysis */
+ const int32_t Fs );
+
+void lsf2isf(
+ const float *lsf, /* i : LSF vector */
+ float *isf, /* o : ISF vector */
+ float *stable_isp, /* i/o: ISP vector */
+ const int16_t m, /* i : order of LP analysis */
+ const int32_t Fs );
+
+int16_t a2lsp(
+ float *freq, /* o : LSP vector */
+ const float *a, /* i : predictor coefficients */
+ const int16_t order /* i : order of LP analysis */
+);
+
+void ResetSHBbuffer_Enc(
+ TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */
+);
+
+void ResetSHBbuffer_Dec(
+ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ const int16_t extl /* i : BWE extension layer */
+);
+
+void calc_st_filt(
+ const float *apond2, /* i : coefficients of numerator */
+ const float *apond1, /* i : coefficients of denominator */
+ float *parcor0, /* o : 1st parcor calcul. on composed filter */
+ float *sig_ltp_ptr, /* i/o: input of 1/A(gamma1) : scaled by 1/g0 */
+ float *mem_zero, /* i/o: All zero memory */
+ const int16_t L_subfr, /* i : the length of subframe */
+ const int16_t extl /* i : extension layer info */
+);
+
+void scale_st(
+ const float *sig_in, /* i : postfilter input signal */
+ float *sig_out, /* i/o: postfilter output signal */
+ float *gain_prec, /* i/o: last value of gain for subframe */
+ const int16_t L_subfr, /* i : the length of subframe */
+ const int16_t extl /* i : extension layer info */
+);
+
+void filt_mu(
+ const float *sig_in, /* i : signal (beginning at sample -1) */
+ float *sig_out, /* o : output signal */
+ const float parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */
+ const int16_t L_subfr, /* i : the length of subframe */
+ const int16_t extl /* i : extension layer info */
+);
+
+void PostShortTerm(
+ float *sig_in, /* i : input signal (ptr. to current subframe */
+ float *lpccoeff, /* i : LPC coefficients for current subframe */
+ float *sig_out, /* o : postfiltered output */
+ float *mem_stp, /* i/o: postfilter memory */
+ float *ptr_mem_stp, /* i/o: pointer to postfilter memory */
+ float *ptr_gain_prec, /* i/o: for gain adjustment */
+ float *mem_zero, /* i/o: null memory to compute h_st */
+ const float formant_fac /* i : Strength of post-filter [0,1] */
+);
+
+/*! r: Formant filter strength [0,1] */
+float swb_formant_fac(
+ const float lpc_shb2, /* i : 2nd HB LPC coefficient */
+ float *tilt_mem /* i/o: Tilt smoothing memory */
+);
+
+void GenShapedSHBExcitation(
+ float *excSHB, /* o : synthesized shaped shb exctiation */
+ const float *lpc_shb, /* i : lpc coefficients */
+ float *exc16kWhtnd, /* o : whitened synthesized shb excitation */
+ float *mem_csfilt, /* i/o: memory */
+ float *mem_genSHBexc_filt_down_shb, /* i/o: memory */
+ float *state_lpc_syn, /* i/o: memory */
+ const int16_t coder_type, /* i : coding type */
+ const float *bwe_exc_extended, /* i : bandwidth extended excitation */
+ int16_t bwe_seed[], /* i/o: random number generator seed */
+ float voice_factors[], /* i : voicing factor */
+ const int16_t extl, /* i : extension layer */
+ float *tbe_demph, /* i/o: de-emphasis memory */
+ float *tbe_premph, /* i/o: pre-emphasis memory */
+ float *lpc_shb_sf, /* i : LP coefficients */
+ float *shb_ener_sf, /* i : SHB subframe energies */
+ float *shb_res_gshape, /* i : SHB LP residual gain shape */
+ float *shb_res, /* i : SHB residual used in encoder only */
+ int16_t *vf_ind, /* i/o: Mixing factor index */
+ const float formant_fac, /* i : Formant sharpening factor [0..1] */
+ float fb_state_lpc_syn[], /* i/o: memory */
+ float *fb_tbe_demph, /* i/o: fb de-emphasis memory */
+ const int32_t total_brate, /* i : overall bitrate */
+ const int16_t prev_bfi, /* i : previous frame was lost flag */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */
+ float *nlExc16k, /* i/o: NL exc for IC-BWE */
+ float *mixExc16k, /* i/o: exc spreading for IC-BWE */
+ const int32_t extl_brate, /* i : TD BWE bitrate */
+ const int16_t MSFlag, /* i : Multi-source flag */
+ float EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */
+ float *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */
+ float *prev_mix_factor, /* i/o: mixing factor in the previous frame */
+ float *Env_error, /* o : error in SHB residual envelope modelling*/
+ float Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */
+);
+
+void GenSHBSynth(
+ const float *shb_target_speech, /* i : input synthesized speech */
+ float *shb_syn_speech_32k, /* o : output highband component */
+ float Hilbert_Mem[], /* i/o: memory */
+ float state_lsyn_filt_shb_local[], /* i/o: memory */
+ const int16_t L_frame, /* i : ACELP Frame length */
+ int16_t *syn_dm_phase );
+
+void ScaleShapedSHB(
+ const int16_t length, /* i : SHB overlap length */
+ float *synSHB, /* i/o: synthesized shb signal */
+ float *overlap, /* i/o: buffer for overlap-add */
+ const float *subgain, /* i : subframe gain */
+ const float frame_gain, /* i : frame gain */
+ const float *win, /* i : window */
+ const float *subwin /* i : subframes window */
+);
+
+void Interpolate_allpass_steep(
+ const float *in, /* i : input array of size N */
+ float *mem, /* i/o: memory */
+ const int16_t N, /* i : number of input samples */
+ float *out /* o : output array of size 2*N */
+);
+
+void Decimate_allpass_steep(
+ const float *in, /* i : input array of size N */
+ float *mem, /* i/o: memory */
+ const int16_t N, /* i : number of input samples */
+ float *out /* o : output array of size N/2 */
+);
+
+void interpolate_3_over_2_allpass(
+ const float *input, /* i : input signal */
+ const int16_t len, /* i : number of input samples */
+ float *out, /* o : output signal */
+ float *mem /* i/o: memory */
+);
+
+void decimate_2_over_3_allpass(
+ const float *input, /* i : input signal */
+ const int16_t len, /* i : number of input samples */
+ float *out, /* o : output signal */
+ float *mem, /* i/o: memory */
+ float *lp_mem );
+
+void interpolate_3_over_1_allpass(
+ const float *input, /* i : input signal */
+ const int16_t len, /* i : number of input samples */
+ float *out, /* o : output signal */
+ float *mem /* i/o: memory */
+);
+
+void InitSWBencBuffer(
+ TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */
+);
+
+void InitSWBencBufferStates(
+ TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ float *shb_speech /* o : SHB target signal (6-14kHz) at 16kHz */
+);
+
+void swb_tbe_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */
+ const float *new_speech, /* i : original input signal */
+ const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
+ const float voice_factors[], /* i : voicing factors */
+ float *White_exc16k, /* o : shaped white excitation for the FB TBE */
+ const float pitch_buf[] /* i : pitch for each subframe */
+);
+
+void swb_tbe_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */
+ const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
+ const float voice_factors[], /* i : voicing factors */
+ const float old_syn_12k8_16k[], /* i : low band synthesis at 12.8kHz or 16kHz */
+ float *White_exc16k, /* o : shaped white excitation for the FB TBE */
+ float *synth, /* i/o: ACELP core synthesis/final synthesis */
+ float *pitch_buf );
+
+void flip_and_downmix_generic(
+ float input[], /* i : input spectrum */
+ float output[], /* o : output spectrum */
+ const int16_t length, /* i : length of spectra */
+ float mem1_ext[HILBERT_ORDER1], /* i/o: Hilbert filter memory */
+ float mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory */
+ float mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory */
+ int16_t *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */
+);
+
+void non_linearity(
+ const float input[], /* i : input signal */
+ float output[], /* i : output signal */
+ float old_bwe_exc_extended[], /* i/o: memory bugffer */
+ const int16_t length, /* i : input length */
+ float *prev_scale, /* i/o: memory */
+ const int16_t coder_type, /* i : Coder Type */
+ const float *voice_factors, /* i : Voice Factors */
+ const int16_t L_frame /* i : ACELP frame length */
+);
+
+void interp_code_5over2(
+ const float inp_code[], /* i : input vector */
+ float interp_code[], /* o : output vector */
+ const int16_t inp_length /* i : length of the input vector */
+);
+
+void interp_code_4over2(
+ const float inp_code[], /* i : input vector */
+ float interp_code[], /* o : output vector */
+ const int16_t inp_length /* i : length of the input vector */
+);
+
+void flip_spectrum_and_decimby4(
+ const float input[], /* i : input spectrum */
+ float output[], /* o : output spectrum */
+ const int16_t length, /* i : vector length */
+ float mem1[], /* i/o: memory */
+ float mem2[], /* i/o: memory */
+ const int16_t ramp_flag /* i : flag to trigger slow ramp-up of output */
+);
+
+void GenShapedWBExcitation(
+ float *excSHB, /* o : synthesized shaped shb exctiation */
+ const float *lpc_shb, /* i : lpc coefficients */
+ float *exc4kWhtnd, /* o : whitened synthesized shb excitation */
+ float *mem_csfilt, /* i/o: memory */
+ float *mem_genSHBexc_filt_down1, /* i/o: memory */
+ float *mem_genSHBexc_filt_down2, /* i/o: memory */
+ float *mem_genSHBexc_filt_down3, /* i/o: memory */
+ float *state_lpc_syn, /* i/o: memory */
+ const int16_t coder_type, /* i : coding type */
+ const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
+ int16_t bwe_seed[], /* i/o: random number generator seed */
+ const float voice_factors[], /* i : voicing factor */
+ const int16_t uv_flag, /* i : unvoiced flag */
+ const int16_t igf_flag );
+
+void GenWBSynth(
+ const float *input_synspeech, /* i : input synthesized speech */
+ float *shb_syn_speech_16k, /* o : output highband compnent */
+ float *state_lsyn_filt_shb1, /* i/o: memory */
+ float *state_lsyn_filt_shb2 /* i/o: memory */
+);
+
+void wb_tbe_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */
+ const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
+ const float pitch_buf[], /* i : pitch for each subframe */
+ const float voicing[] /* o : OL maximum normalized correlation */
+);
+
+void wb_tbe_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
+ const float voice_factors[], /* i : voicing factors */
+ float *synth /* i/o: ACELP core synthesis/final synthesis */
+);
+
+void tbe_write_bitstream(
+ Encoder_State *st /* i/o: encoder state structure */
+);
+
+void tbe_read_bitstream(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+void GenTransition(
+ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ float *outputHB, /* o : synthesized HB transitions signal */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t L_frame, /* i : ACELP frame length */
+ const int16_t rf_flag, /* i : RF flag */
+ const int32_t total_brate /* i : total bitrate */
+);
+
+void GenTransition_WB(
+ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ float *outputHB, /* o : synthesized HB transitions signal */
+ const int32_t output_Fs /* i : output sampling rate */
+);
+
+void td_bwe_dec_init(
+ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ const int16_t extl, /* i : BWE extension layer */
+ const int32_t output_Fs /* i : output sampling rate */
+);
+
+void TBEreset_enc(
+ TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ const int16_t last_core, /* i : last core */
+ const int16_t bwidth /* i : audio bandwidth */
+);
+
+void TBEreset_dec(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+/*! r: TBE bit consumption per frame */
+int16_t get_tbe_bits(
+ const int32_t total_brate, /* i : overall bitrate */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int16_t rf_mode /* i : channel aware mode */
+);
+
+void fb_tbe_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float new_input[], /* i : input speech at 48 kHz sample rate */
+ const float fb_exc[] /* i : FB excitation from the SWB part */
+);
+
+void fb_tbe_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const float fb_exc[], /* i : FB excitation from the SWB part */
+ float *hb_synth, /* i/o: high-band synthesis */
+ float *fb_synth_ref, /* o : high-band synthesis 16-20 kHz */
+ const int16_t output_frame /* i : output frame length */
+);
+
+void calc_tilt_bwe(
+ const float *sp, /* i : input signal */
+ float *tilt, /* o : signal tilt */
+ const int16_t N /* i : signal length */
+);
+
+void fd_bwe_enc_init(
+ FD_BWE_ENC_HANDLE hBWE_FD /* i/o: FD BWE data handle */
+);
+
+void swb_pre_proc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ float *new_swb_speech, /* o : original input signal at 32kHz */
+ float *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz */
+ float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer */
+ float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer */
+ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */
+);
+
+void wb_pre_proc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t last_element_mode, /* i : last element mode */
+ const float *new_inp_resamp16k, /* i : original input signal */
+ float *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */
+);
+
+void wb_bwe_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float *new_wb_speech /* i : original input signal at 16kHz */
+);
+
+void wb_bwe_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const float output[], /* i : synthesis @internal Fs */
+ float *synth, /* i/o: ACELP core synthesis/final synthesis */
+ float *hb_synth, /* o : SHB synthesis/final synthesis */
+ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
+ const int16_t output_frame, /* i : frame length */
+ const float voice_factors[], /* i : voicing factors */
+ const float pitch_buf[] /* i : pitch buffer */
+);
+
+void swb_bwe_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t last_element_mode, /* i : last element mode */
+ const float *old_input_12k8, /* i : input signal @12.8kHz for SWB BWE */
+ const float *old_input_16k, /* i : input signal @16kHz for SWB BWE */
+ const float *old_syn_12k8_16k, /* i : ACELP core synthesis at 12.8kHz or 16kHz*/
+ const float *new_swb_speech, /* i : original input signal at 32kHz */
+ const float *shb_speech /* i : SHB target signal (6-14kHz) at 16kHz */
+);
+
+void swb_bwe_enc_hr(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float *new_input, /* i : input signal */
+ const int16_t input_frame, /* i : frame length */
+ const int16_t unbits /* i : number of core unused bits */
+);
+
+void fd_bwe_dec_init(
+ FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */
+);
+
+void swb_bwe_dec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const float output[], /* i : synthesis @internal Fs */
+ const float *synth, /* i : ACELP core synthesis/final synthesis */
+ float *hb_synth, /* o : SHB synthesis/final synthesis */
+ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
+ const int16_t output_frame /* i : frame length */
+);
+
+void hr_bwe_dec_init(
+ HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */
+);
+
+void swb_bwe_dec_hr(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const float *syn_12k8_16k, /* i : ACELP core synthesis @16kHz */
+ float *hb_synth, /* o : SHB synthesis */
+ const int16_t output_frame, /* i : frame length */
+ const int16_t unbits, /* i : number of core unused bits */
+ const float pitch_buf[] /* i : pitch buffer */
+);
+
+void swb_hr_noise_fill(
+ const int16_t is_transient, /* i : transient flag */
+ const int16_t spect_start, /* i : spectrum start point */
+ const int16_t spect_end, /* i : spectrum end point */
+ const float tilt_wb, /* i : tilt of wideband signal */
+ const float pitch, /* i : pitch value */
+ const int16_t nq[], /* i : AVQ nq index */
+ int16_t Nsv, /* i : number of subband */
+ int16_t *bwe_highrate_seed, /* i/o: seed of random noise */
+ float *t_audio /* i/o: mdct spectrum */
+);
+
+/*! r: gain */
+float td_postprocess(
+ float hb_synth[], /* i/o: high-band synthesis */
+ const int16_t input_frame, /* i : frame length */
+ const int16_t last_extl /* i : last extension layer */
+);
+
+void calc_normal_length(
+ const int16_t core, /* i : core */
+ const float *sp, /* i : input signal */
+ const int16_t mode, /* i : input mode */
+ const int16_t extl, /* i : extension layer */
+ int16_t *L_swb_norm, /* o : normalize length */
+ int16_t *prev_L_swb_norm /* i/o: last normalize length */
+);
+
+void calc_norm_envelop(
+ const float SWB_signal[], /* i : SWB spectrum */
+ float *envelope, /* o : normalized envelope */
+ const int16_t L_swb_norm, /* i : length of envelope */
+ const int16_t SWB_flength, /* i : Length of input/output */
+ const int16_t st_offset /* i : offset */
+);
+
+void time_envelop_shaping(
+ float werr[], /* i/o: SHB synthesis */
+ float SWB_tenv[], /* i/o: frequency envelope */
+ const int16_t L /* i : frame length */
+);
+
+void time_reduce_pre_echo(
+ const float *synth, /* i : ACELP core synthesis */
+ float *error, /* o : SHB BWE synthesis */
+ float prev_td_energy, /* o : last td energy */
+ const int16_t L /* i : subframe length */
+);
+
+int16_t WB_BWE_gain_pred(
+ float *WB_fenv, /* o : WB frequency envelopes */
+ const float *core_dec_freq, /* i : Frequency domain core decoded signal */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t prev_code_type, /* i : coding type of last frame */
+ const float prev_WB_fenv, /* i : envelope for last frame */
+ const float voice_factors[], /* i : voicing factors */
+ const float pitch_buf[], /* i : pitch buffer */
+ const int32_t last_core_brate, /* i : previous frame core bitrate */
+ const float last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */
+ const int16_t last_extl, /* i : extl. layer for last frame */
+ const float tilt );
+
+void WB_BWE_decoding(
+ const float *core_dec_freq, /* i : Frequency domain core decoded signal */
+ float *WB_fenv, /* i : WB frequency envelopes */
+ float *WB_signal, /* o : WB signal in MDCT domain */
+ const int16_t WB_flength, /* i : Length of input/output */
+ const int16_t mode, /* i : classification for WB signal */
+ const int16_t last_extl, /* i : extl. layer for last frame */
+ float *prev_Energy, /* i/o: energy for last frame */
+ float *prev_WB_fenv, /* i/o: envelope for last frame */
+ int16_t *prev_L_wb_norm, /* i/o: length for last frame wb norm */
+ const int16_t extl, /* i : extension layer */
+ const int16_t coder_type, /* i : coding type */
+ const int32_t total_brate, /* i : core layer bitrate */
+ int16_t *Seed, /* i/o: random generator seed */
+ int16_t *prev_flag, /* i/o: attenu flag of last frame */
+ int16_t prev_coder_type /* i : coding type of last frame */
+);
+
+void SWB_BWE_decoding(
+ const float *core_dec_freq, /* i : Frequency domain core decoded signal */
+ float *SWB_fenv, /* i/o: SWB frequency envelopes */
+ float *SWB_signal, /* o : SWB signal in MDCT domain */
+ const int16_t SWB_flength, /* i : Length of input/output */
+ const int16_t mode, /* i : classification for SWB signal */
+ int16_t *frica_flag, /* o : fricative signal flag */
+ float *prev_Energy, /* i/o: energy for last frame */
+ float *prev_SWB_fenv, /* i/o: envelope for last frame */
+ int16_t *prev_L_swb_norm, /* i/o: length for last frame wb norm */
+ const float tilt_nb, /* i : tilt of synthesis wb signal */
+ int16_t *Seed, /* i/o: random generator seed */
+ const int16_t st_offset, /* i : offset value due to different core */
+ float *prev_weight, /* i/o: excitation weight value of last frame */
+ const int16_t extl, /* i : extension layer */
+ const int16_t last_extl /* i : extension layer of last frame */
+);
+
+void CNG_reset_enc(
+ Encoder_State *st, /* i/o: encoder state structure */
+ float *pitch_buf, /* o : floating pitch for each subframe */
+ float *voice_factors, /* o : voicing factors */
+ int16_t VBR_cng_reset_flag );
+
+void a2isp(
+ const float *a, /* i : LP filter coefficients */
+ float *isp, /* o : Immittance spectral pairs */
+ const float *old_isp /* i : ISP vector from past frame */
+);
+
+void a2isf(
+ float *a,
+ float *isf,
+ const float *old_isf,
+ const int16_t lpcOrder );
+
+void a2rc(
+ const float *a, /* i : LPC coefficients */
+ float *refl, /* o : Reflection co-efficients */
+ const int16_t lpcorder /* i : LPC order */
+);
+
+int16_t lp_filt_exc_enc(
+ const int16_t codec_mode, /* i : codec mode */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t i_subfr, /* i : subframe index */
+ float *exc, /* i/o: pointer to excitation signal frame */
+ const float *h1, /* i : weighted filter input response */
+ const float *xn, /* i : target vector */
+ float *y1, /* o : zero-memory filtered adaptive excitation */
+ float *xn2, /* o : target vector for innovation search */
+ const int16_t L_subfr, /* i : length of vectors for gain quantization */
+ const int16_t L_frame, /* i : frame size */
+ float *g_corr, /* o : ACELP correlation values */
+ const int16_t clip_gain, /* i : adaptive gain clipping flag */
+ float *gain_pit, /* o : adaptive excitation gain */
+ int16_t *lp_flag /* i/o: mode selection */
+);
+
+void updt_tar(
+ const float *x, /* i : old target (for pitch search) */
+ float *x2, /* o : new target (for codebook search) */
+ const float *y, /* i : filtered adaptive codebook vector */
+ const float gain, /* i : adaptive codebook gain */
+ const int16_t L /* i : subframe size */
+);
+
+void analy_sp(
+ const int16_t element_mode, /* i : element mode */
+ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
+ const int32_t input_Fs, /* i : input sampling rate */
+ float *speech, /* i : speech buffer */
+ float *Bin_E, /* o : per bin log energy spectrum */
+ float *Bin_E_old, /* o : per bin log energy spectrum for mid-frame */
+ float *fr_bands, /* o : per band energy spectrum (2 analyses) */
+ float lf_E[], /* o : per bin E for first VOIC_BINS bins (without DC) */
+ float *Etot, /* o : total input energy */
+ const int16_t min_band, /* i : minimum critical band */
+ const int16_t max_band, /* i : maximum critical band */
+ float *band_ener, /* o : energy in critical frequency bands without minimum noise floor E_MIN */
+ float *PS, /* o : Per bin energy spectrum */
+ float *fft_buff /* o : FFT coefficients */
+);
+
+void CNG_enc(
+ Encoder_State *st, /* i/o: State structure */
+ float Aq[], /* o : LP coefficients */
+ const float *speech, /* i : pointer to current frame input speech buffer */
+ float enr, /* i : frame energy output from Levinson recursion */
+ const float *lsp_mid, /* i : mid frame LSPs */
+ float *lsp_new, /* i/o: current frame LSPs */
+ float *lsf_new, /* i/o: current frame LSFs */
+ int16_t *allow_cn_step, /* o : allow CN step */
+ float *q_env,
+ int16_t *sid_bw );
+
+void swb_CNG_enc(
+ Encoder_State *st, /* i/o: State structure */
+ const float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */
+ const float *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz */
+);
+
+void lsf_enc(
+ Encoder_State *st, /* i/o: state structure */
+ float *lsf_new, /* o : quantized LSF vector */
+ float *lsp_new, /* i/o: LSP vector to quantize/quantized */
+ float *lsp_mid, /* i : mid-frame LSP vector */
+ float *Aq, /* o : quantized A(z) for 4 subframes */
+ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
+ const int16_t GSC_IVAS_mode, /* i : GSC IVAS mode */
+ const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */
+);
+
+void isf_enc_amr_wb(
+ Encoder_State *st, /* i/o: state structure */
+ float *isf_new, /* o : quantized ISF vector */
+ float *isp_new, /* i/o: ISP vector to quantize/quantized */
+ float *Aq /* o : quantized A(z) for 4 subframes */
+);
+
+void find_targets(
+ const float *speech, /* i : pointer to the speech frame */
+ const float *mem_syn, /* i : memory of the synthesis filter */
+ const int16_t i_subfr, /* i : subframe index */
+ float *mem_w0, /* i/o: weighting filter denominator memory */
+ const float *p_Aq, /* i : interpolated quantized A(z) filter */
+ const float *res, /* i : residual signal */
+ const int16_t L_subfr, /* i : length of vectors for gain quantization */
+ const float *Ap, /* i : unquantized A(z) filter with bandwidth expansion */
+ const float tilt_fac, /* i : tilt factor */
+ float *xn, /* o : Close-loop Pitch search target vector */
+ float *cn, /* o : target vector in residual domain */
+ float *h1 /* o : impulse response of weighted synthesis filter */
+);
+
+void inov_encode(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const int16_t L_frame, /* i : length of the frame */
+ const int16_t last_L_frame, /* i : length of the last frame */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t bwidth, /* i : input signal bandwidth */
+ const int16_t sharpFlag, /* i : formant sharpening flag */
+ const int16_t i_subfr, /* i : subframe index */
+ const int16_t tc_subfr, /* i : TC subframe index */
+ const float *p_Aq, /* i : LP filter coefficients */
+ const float gain_pit, /* i : adaptive excitation gain */
+ float *cn, /* i/o: target vector in residual domain */
+ const float *exc, /* i : pointer to excitation signal frame */
+ float *h1, /* i/o: weighted filter input response */
+ const float tilt_code, /* i : tilt of of the excitation of previous subframe */
+ const float pt_pitch, /* i : pointer to current subframe fractional pitch */
+ const float *xn2, /* i : target vector for innovation search */
+ float *code, /* o : algebraic excitation */
+ float *y2, /* o : zero-memory filtered algebraic excitation */
+ int16_t *unbits, /* o : number of unused bits for EVS_PI */
+ const int16_t L_subfr /* i : subframe length */
+);
+
+void acelp_1t64(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const float dn[], /* i : corr. between target and h[]. */
+ const float h[], /* i : impulse response of weighted synthesis filter */
+ float code[], /* o : algebraic (fixed) codebook excitation */
+ float y[], /* o : filtered fixed codebook excitation */
+ const int16_t L_subfr /* i : subframe length */
+);
+
+void acelp_2t32(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const float dn[], /* i : corr. between target and h[]. */
+ const float h[], /* i : impulse response of weighted synthesis filter */
+ float code[], /* o : algebraic (fixed) codebook excitation */
+ float y[] /* o : filtered fixed codebook excitation */
+);
+
+int16_t acelp_4t64(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ float dn[], /* i : corr. between target and h[]. */
+ const float cn[], /* i : residual after long term prediction */
+ const float H[], /* i : impulse response of weighted synthesis filter */
+ float R[], /* i : autocorrelation values */
+ const int16_t acelpautoc, /* i : autocorrealtion flag */
+ float code[], /* o : algebraic (fixed) codebook excitation */
+ float y[], /* o : filtered fixed codebook excitation */
+ int16_t nbbits, /* i : number of bits per codebook */
+ const int16_t cmpl_flag, /* i : coomplexity reduction flag */
+ const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */
+);
+
+/*! r: return (2*N)+1 bits */
+int16_t quant_2p_2N1(
+ const int16_t pos1, /* i : position of the pulse 1 */
+ const int16_t pos2, /* i : position of the pulse 2 */
+ const int16_t N /* i : number of bits for position */
+);
+
+void corr_xh(
+ const float *x, /* i : target signal */
+ float *y, /* o : correlation between x[] and h[] */
+ const float *h, /* i : impulse response of weighted synthesis filter */
+ const int16_t L_subfr /* i : length of the subframe */
+);
+
+void find_tilt(
+ const float fr_bands[], /* i : energy in frequency bands */
+ const float bckr[], /* i : per band background noise energy estimate */
+ float ee[2], /* o : lf/hf E ration for present frame */
+ const int16_t pitch[3], /* i : open loop pitch values for 3 half-frames */
+ const float voicing[3], /* i : normalized correlation for 3 half-frames */
+ const float *lf_E, /* i : per bin energy for low frequencies */
+ const float corr_shift, /* i : normalized correlation correction */
+ const int16_t bwidth, /* i : input signal bandwidth */
+ const int16_t max_band, /* i : maximum critical band */
+ float hp_E[], /* o : energy in HF */
+ const int16_t codec_mode, /* i : Mode 1 or 2 */
+ float *bckr_tilt_lt, /* i/o: lf/hf E ratio of background noise */
+ int16_t Opt_vbr_mode );
+
+void init_gp_clip(
+ float mem[] /* o : memory of gain of pitch clipping algorithm */
+);
+
+int16_t gp_clip(
+ const int16_t element_mode, /* i : element mode */
+ const int32_t core_brate, /* i : core bitrate */
+ const float *voicing, /* i : normalized correlations (from OL pitch) */
+ const int16_t i_subfr, /* i : subframe index */
+ const int16_t coder_type, /* i : coding type */
+ const float xn[], /* i : target vector */
+ float mem[] /* i/o: memory of gain of pitch clipping algorithm */
+);
+
+void gp_clip_test_lsf(
+ const int16_t element_mode, /* i : element mode */
+ const int32_t core_brate, /* i : core bitrate */
+ const float lsf[], /* i : LSF vector */
+ float mem[], /* i/o: memory of gain of pitch clipping algorithm */
+ const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */
+);
+
+void gp_clip_test_gain_pit(
+ const int16_t element_mode, /* i : element mode */
+ const int32_t core_brate, /* i : core bitrate */
+ const float gain_pit, /* i : gain of quantized pitch */
+ float mem[] /* i/o: memory of gain of pitch clipping algorithm */
+);
+
+void analy_lp(
+ const float speech[], /* i : pointer to the denoised speech frame */
+ const int16_t L_frame, /* i : length of the frame */
+ const int16_t L_look, /* i : look-ahead length */
+ float *ener, /* o : residual signal energy */
+ float A[], /* o : A(z) filter coefficients */
+ float epsP[], /* o : LP analysis residual energies for each iteration */
+ float lsp_new[], /* o : current frame ISPs */
+ float lsp_mid[], /* o : current mid-frame ISPs */
+ float lsp_old[], /* i/o: previous frame unquantized ISPs */
+ const int16_t Top[2], /* i : open loop pitch lag */
+ const float Tnc[2], /* i : open loop pitch gain */
+ const int32_t sr_core, /* i : internal sampling rate */
+ const int16_t sec_chan_low_rate /* i : TD secondary channel flag */
+);
+
+void analy_lp_AMR_WB(
+ const float speech[], /* i : pointer to the speech frame */
+ float *ener, /* o : residual energy from Levinson-Durbin */
+ float A[], /* o : A(z) filter coefficients */
+ float epsP[], /* o : LP analysis residual energies for each iteration */
+ float isp_new[], /* o : current frame ISPs */
+ float isp_old[], /* i/o: previous frame unquantized ISPs */
+ float isf_new[], /* o : current frame ISFs */
+ const int16_t Top, /* i : open loop pitch lag */
+ const float Tnc /* i : open loop pitch gain */
+);
+
+void noise_est_init(
+ NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */
+);
+
+void speech_music_clas_init(
+ SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */
+);
+
+void long_enr(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float Etot, /* i : total channel energy */
+ const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */
+ const int16_t high_lpn_flag, /* i : sp/mus LPN flag */
+ FRONT_VAD_ENC_HANDLE hFrontVad[CPE_CHANNELS], /* i/o: front-VAD handles */
+ const int16_t n_chan, /* i : number of channels */
+ const int16_t localVAD_HE_SAD_LR[CPE_CHANNELS], /* i : HE-SAD flag without hangover LR channels */
+ const float Etot_LR[CPE_CHANNELS] /* i : total channel energy LR channels */
+);
+
+void noise_est_pre(
+ const float Etot, /* i : Energy of current frame */
+ const int16_t ini_frame, /* i : Frame number (init) */
+ NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation data handle */
+ const int16_t idchan, /* i : channel ID */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t last_element_mode /* i : last element mode */
+);
+
+void noise_est_down(
+ const float fr_bands[], /* i : per band input energy (contains 2 vectors) */
+ float bckr[], /* i/o: per band background noise energy estimate */
+ float tmpN[], /* o : temporary noise update */
+ float enr[], /* o : averaged energy over both subframes */
+ const int16_t min_band, /* i : minimum critical band */
+ const int16_t max_band, /* i : maximum critical band */
+ float *totalNoise, /* o : noise estimate over all critical bands */
+ const float Etot, /* i : Energy of current frame */
+ float *Etot_last, /* i/o: Energy of last frame */
+ float *Etot_v_h2 /* i/o: Energy variaions of noise frames */
+);
+
+void noise_est(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t old_pitch1, /* i : previous frame OL pitch[1] */
+ const float tmpN[], /* i : temporary noise update */
+ const float *epsP, /* i : LP prediction error energies */
+ const float Etot, /* i : total channel E */
+ const float relE, /* i : relative frame energy */
+ const float corr_shift, /* i : normalized correlation correction */
+ const float enr[], /* i : averaged energy over both subframes */
+ float fr_bands[], /* i : spectrum per critical bands of the current frame */
+ float *cor_map_sum, /* o : sum of correlation map from mult-harm analysis */
+ float *ncharX, /* o : noise character for sp/mus classifier */
+ float *sp_div, /* o : soectral diversity feature */
+ float *non_staX, /* o : non-stationarity for sp/mus classifier */
+ int16_t *loc_harm, /* o : multi-harmonicity flag for UV classifier */
+ const float *lf_E, /* i : per bin energy for low frequencies */
+ int16_t *st_harm_cor_cnt, /* i : 1st harm correlation timer */
+ const float Etot_l_lp, /* i : Smoothed low energy */
+ float *sp_floor, /* o : noise floor estimate */
+ float S_map[], /* o : short-term correlation map */
+ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */
+ FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */
+ const int16_t ini_frame /* i : Frame number (init) */
+);
+
+void vad_param_updt(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float corr_shift, /* i : correlation shift */
+ const float corr_shiftR, /* i : correlation shift right channel */
+ const float A[], /* i : A(z) unquantized for the 4 subframes */
+ const int16_t old_pitch1, /* i : previous frame OL pitch[1] */
+ FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */
+ const int16_t n_channels /* i : number of channels */
+);
+
+/*! r: frame multi-harmonicity (1-harmonic, 0-not) */
+int16_t multi_harm(
+ const float Bin_E[], /* i : log energy spectrum of the current frame */
+ float old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor */
+ float cor_map_LT[], /* i/o: LT correlation map */
+ float *multi_harm_limit, /* i/o: multi harminic threshold */
+ const int32_t total_brate, /* i : total bitrate */
+ const int16_t bwidth, /* i : input signal bandwidth */
+ int16_t *cor_strong_limit, /* i/o: HF correlation indicator */
+ float *st_mean_avr_dyn, /* i/o: long term average dynamic */
+ float *st_last_sw_dyn, /* i/o: last dynamic */
+ float *cor_map_sum, /* i : sum of correlation map */
+ float *sp_floor, /* o : noise floor estimate */
+ float S_map[] /* o : short-term correlation map */
+);
+
+void lp_gain_updt(
+ const int16_t i_subfr, /* i : subframe number */
+ const float gain_pit, /* i : Decoded gain pitch */
+ const float norm_gain_code, /* i : Normalised gain code */
+ float *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) */
+ float *lp_gainc, /* i/o: LP-filtered code gain (FEC) */
+ const int16_t L_frame /* i : length of the frame */
+);
+
+void enc_pit_exc(
+ Encoder_State *st, /* i/o: state structure */
+ const float *speech, /* i : Input speech */
+ const float Aw[], /* i : weighted A(z) unquantized for subframes */
+ const float *Aq, /* i : 12k8 Lp coefficient */
+ const float Es_pred, /* i : predicted scaled innov. energy */
+ const float *res, /* i : residual signal */
+ float *synth, /* i/o: core synthesis */
+ float *exc, /* i/o: current non-enhanced excitation */
+ int16_t *T0, /* i/o: close loop integer pitch */
+ int16_t *T0_frac, /* i/o: close-loop pitch period - fractional part */
+ float *pitch_buf, /* i/o: Fractionnal per subframe pitch */
+ const int16_t nb_subfr, /* i : Number of subframe considered */
+ float *gpit, /* o : pitch gain per subframe */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+);
+
+void GSC_enc_init(
+ GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */
+);
+
+void encod_audio(
+ Encoder_State *st, /* i/o: state structure */
+ const float speech[], /* i : input speech */
+ const float Aw[], /* i : weighted A(z) unquantized for subframes */
+ const float Aq[], /* i : 12k8 Lp coefficient */
+ const float *res, /* i : residual signal */
+ float *synth, /* i/o: core synthesis */
+ float *exc, /* i/o: current non-enhanced excitation */
+ float *pitch_buf, /* i/o: floating pitch values for each subframe */
+ float *voice_factors, /* o : voicing factors */
+ float *bwe_exc, /* o : excitation for SWB TBE */
+ const int16_t attack_flag, /* i : attack flag (GSC or TC) */
+ float *lsf_new, /* i : current frame ISF vector */
+ float *tmp_noise, /* o : long-term noise energy */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+);
+
+/*! r: index of the last band where pitch contribution is significant */
+int16_t Pit_exc_contribution_len(
+ Encoder_State *st, /* i/o: state structure */
+ const float *dct_res, /* i : DCT of residual */
+ float *dct_pitex, /* i/o: DCT of pitch contribution */
+ float *pitch_buf, /* i/o: Pitch per subframe */
+ int16_t *hangover /* i : Hangover for the time contribution switching */
+);
+
+int16_t stab_est(
+ float etot, /* i : Total energy of the current frame */
+ float *lt_diff_etot, /* i/o: Long term total energy variation */
+ float *mem_etot, /* i/o: Total energy memory */
+ int16_t *nb_thr_3, /* i/o: Number of consecutives frames of level 3 */
+ int16_t *nb_thr_1, /* i/o: Number of consecutives frames of level 1 */
+ float *thresh, /* i/o: Detection thresold */
+ int16_t *last_music_flag, /* i/o: Previous music detection ouptut */
+ const int16_t vad_flag /* i : VAD flag */
+);
+
+float gsc_gainQ(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t idchan, /* i : channel ID */
+ const float y_gain4[], /* i : gain per band */
+ float y_gainQ[], /* o : quantized gain per band */
+ const int32_t core_brate, /* i : Core rate */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t bwidth, /* i : input signal bandwidth */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */
+ const int32_t core_brate_inp /* i : true core brate */
+);
+
+void Ener_per_band_comp(
+ const float exc_diff[], /* i : gain per band */
+ float y_gain4[], /* o : gain per band to quantize */
+ const int16_t Mband, /* i : Max band */
+ const int16_t Eflag, /* i : flag of highest band */
+ const int16_t L_frame /* i : frame length */
+);
+
+void Comp_and_apply_gain(
+ float exc_diffQ[], /* i/o: gain per band */
+ float Ener_per_bd_iQ[], /* o : Quant Ener per band */
+ float Ener_per_bd_yQ[], /* o : Ener per band for quantize y */
+ int16_t Mbands_gn, /* i : number of bands */
+ const int16_t ReUseGain /* i : Reuse the gain in Ener_per_bd_yQ */
+);
+
+void bands_and_bit_alloc(
+ const int16_t cor_strong_limit, /* i : HF correlation */
+ const int16_t noise_lev, /* i : dwn scaling factor */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/
+ const int16_t bits_used, /* i : Number of bit used before frequency Q */
+ int16_t *bit, /* i/o: Number of bit allowed for frequency quantization */
+ float *ener_vec, /* i/o: Quantized energy vector */
+ int16_t *max_ener_band, /* o : Sorted order */
+ int16_t *bits_per_bands_s, /* i/o: Number of bit allowed per allowed subband (Q3) */
+ int16_t *nb_subbands, /* o : Number of subband allowed */
+ const float *exc_diff, /* i : Difference signal to quantize (encoder side only) */
+ float *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */
+ int16_t *pvq_len, /* o : Number of bin covered with the PVQ */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t bwidth, /* i : input signal bandwidth */
+ const int16_t GSC_noisy_speech, /* i : GSC noisy speech flag */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */
+);
+
+/*! r: average frequency gain */
+float gsc_gaindec(
+ Decoder_State *st, /* i/o: decoder state structure */
+ float y_gainQ[], /* o : quantized gain per band */
+ const int32_t core_brate, /* i : core used */
+ float old_y_gain[], /* i/o: AR gain quantizer for low rate */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t bwidth /* i : input signal bandwidth */
+);
+
+void freq_dnw_scaling(
+ const int16_t cor_strong_limit, /* i : HF correlation */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t noise_lev, /* i : Noise level */
+ const int32_t core_brate, /* i : Core bitrate */
+ float fy_norm[], /* i/o: Frequency quantized parameter */
+ const int16_t L_frame /* i : frame length */
+);
+
+void GSC_dec_init(
+ GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */
+);
+
+void decod_audio(
+ Decoder_State *st, /* i/o: decoder static memory */
+ float dct_epit[], /* o : GSC excitation in DCT domain */
+ const float *Aq, /* i : LP filter coefficient */
+ float *tmp_noise, /* o : long term temporary noise energy */
+ float *pitch_buf, /* o : floating pitch values for each subframe */
+ float *voice_factors, /* o : voicing factors */
+ float *exc_dct_in, /* i/o: adapt. excitation exc */
+ float *exc2, /* i/o: adapt. excitation/total exc */
+ float *bwe_exc, /* o : excitation for SWB TBE */
+ float *lsf_new, /* i : current frame ISF vector */
+ float *gain_buf, /* o : floating pitch gain for each subframe */
+ const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag */
+ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+);
+
+void gsc_dec(
+ Decoder_State *st, /* i/o: State structure */
+ float exc_dct_in[], /* i/o: dct of pitch-only/total excitation */
+ const int16_t pit_band_idx, /* i : pitch band index */
+ const int16_t Diff_len, /* i : */
+ const int16_t bits_used, /* i : total number of bits used */
+ const int16_t nb_subfr, /* i : Number of subframe considered */
+ const int16_t coder_type, /* i : coding type */
+ int16_t *last_bin, /* i : last bin of bit allocation */
+ const float *lsf_new, /* i : ISFs at the end of the frame */
+ float *exc_wo_nf, /* o : excitation (in f domain) without noisefill*/
+ float *tmp_noise /* o : long-term noise energy */
+);
+
+void dec_pit_exc(
+ Decoder_State *st, /* i/o: decoder static memory */
+ const int16_t L_frame, /* i : length of the frame */
+ const float *Aq, /* i : LP filter coefficient */
+ const float Es_pred, /* i : predicted scaled innov. energy */
+ float *pitch_buf, /* o : floating pitch values for each subframe */
+ float *code, /* o : innovation */
+ float *exc, /* i/o: adapt. excitation exc */
+ const int16_t nb_subfr, /* i : Number of subframe considered */
+ float *gain_buf, /* o : floating pitch gain for each subframe */
+ const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+);
+
+void highband_exc_dct_in(
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t *mfreq_bindiv_loc, /* i : bin per bands tables */
+ int16_t last_bin, /* i : last bin of bit allocation */
+ int16_t Diff_len, /* i : number of bin before cut-off frequency */
+ int16_t noise_lev, /* i : pulses dynamic */
+ int16_t pit_band_idx, /* i : bin position of the cut-off frequency */
+ float *exc_diffQ, /* i : frequency coefficients of per band */
+ int16_t *seed_tcx, /* i : Seed for noise */
+ float *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */
+ int16_t nb_subfr, /* i : Number of subframe considered */
+ float *exc_dct_in, /* o : dct of residual signal */
+ int16_t last_coder_type, /* i : coding type of last frame */
+ int16_t *bitallocation_band, /* i : bit allocation flag of each band */
+ const float *lsf_new, /* i : ISFs at the end of the frame */
+ float *last_exc_dct_in, /* i : dct of residual signal of last frame */
+ float *last_ener, /* i : frequency energy of last frame */
+ int16_t *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */
+ int16_t *bitallocation_exc, /* i : flag of decoded coefficients */
+ const int16_t bfi, /* i : bad frame indicator */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t bwidth, /* i : audio bandwidth */
+ float *exc_wo_nf, /* o : excitation (in f domain) without noisefill */
+ const int16_t GSC_noisy_speech, /* i : GSC noisy speech flag */
+ float *lt_ener_per_band_fx, /* i/o: Average per band energy */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t element_mode, /* i : IVAS element moden */
+ const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */
+);
+
+void inact_switch_ematch(
+ float exc2[], /* i/o: CELP/GSC excitation buffer */
+ float dct_exc_tmp[], /* i : GSC excitation in DCT domain */
+ float lt_ener_per_band[], /* i/o: long-term energy per band */
+ const int16_t coder_type, /* i : coder type */
+ const int16_t L_frame, /* i : frame length */
+ const int32_t total_brate, /* i : Total bitrate */
+ const int16_t bfi, /* i : frame lost indicator */
+ const int16_t last_core, /* i : Last core used */
+ const int16_t last_codec_mode, /* i : Last codec mode */
+ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
+ const int16_t element_mode /* i : element mode */
+);
+
+void music_postfilt_init(
+ MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */
+);
+
+void LD_music_post_filter(
+ MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */
+ const float dtc_in[], /* i : input synthesis */
+ float dtc_out[], /* o : output synthesis */
+ const int32_t core_brate, /* i : core bitrate */
+ const int16_t coder_type, /* i : Coder type : -1 in case of IO */
+ const int16_t Last_coder_type /* i : last Coder type */
+);
+
+void Post_music_postP(
+ float dct_buffer_in[], /* i/o: excitation buffer */
+ float exc_buffer_out[], /* o : DCT output buffer */
+ float *exc2, /* i/o: Current excitation to be overwriten */
+ const float *mem_tmp, /* i : previous frame synthesis memory */
+ float *st_mem_syn2, /* i/o: current frame synthesis memory */
+ const float *Aq, /* i : LPC filter coefficients */
+ float *syn /* i/o: 12k8 synthesis */
+);
+
+void Prep_music_postP(
+ float exc_buffer_in[], /* i/o: excitation buffer */
+ float dct_buffer_out[], /* o : DCT output buffer */
+ float filt_lfE[], /* i/o: long term spectrum energy */
+ const int16_t last_core, /* i : last core */
+ const float *pitch_buf, /* i : current frame pitch information */
+ float *LDm_enh_lp_gbin /* o : smoothed suppression gain, per bin FFT */
+);
+
+void speech_music_classif(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const float *new_inp, /* i : new input signal */
+ const float *inp, /* i : input signal to locate attach position */
+ const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */
+ const float lsp_new[M], /* i : LSPs in current frame */
+ const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */
+ const float epsP[M + 1], /* i : LP prediciton error */
+ const float PS[], /* i : energy spectrum */
+ const float Etot, /* i : total frame energy */
+ const float old_cor, /* i : max correlation from previous frame */
+ int16_t *attack_flag, /* o : attack flag (GSC or TC) */
+ const float non_staX, /* i : unbound non-stationarity for sp/mus classifier */
+ const float relE, /* i : relative frame energy */
+ int16_t *high_lpn_flag, /* o : sp/mus LPN flag */
+ const int16_t flag_spitch /* i : flag to indicate very short stable pitch */
+);
+
+void find_wsp(
+ const int16_t L_frame, /* i : length of the frame */
+ const int16_t L_subfr, /* i : length of subframe */
+ const int16_t nb_subfr, /* i : number of subframes */
+ const float *A, /* i : A(z) filter coefficients */
+ float *Aw, /* o : weighted A(z) filter coefficients */
+ const float *speech, /* i : pointer to the denoised speech frame */
+ const float tilt_fact, /* i : tilt factor */
+ float *wsp, /* o : poitnter to the weighted speech frame */
+ float *mem_wsp, /* i/o: W(Z) denominator memory */
+ const float gamma, /* i : weighting factor */
+ const int16_t L_look /* i : look-ahead */
+);
+
+void pitch_ol_init(
+ float *old_thres, /* o : threshold for reinforcement of past pitch influence */
+ int16_t *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */
+ int16_t *delta_pit, /* o : pitch evolution extrapolation */
+ float *old_corr /* o : correlation */
+);
+
+void pitch_ol(
+ int16_t pitch[3], /* o : open loop pitch lag for each half-frame */
+ float voicing[3], /* o : maximum normalized correlation for each half-frame */
+ int16_t *old_pitch, /* i/o: OL pitch of the 2nd half-frame of the last frame */
+ float *old_corr, /* i/o: correlation */
+ float corr_shift, /* i : normalized correlation correction */
+ float *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch */
+ int16_t *delta_pit, /* i/o: old pitch extrapolation correction (added to old pitch) */
+ float *st_old_wsp2, /* i/o: weighted speech memory */
+ const float *wsp, /* i : weighted speech for current frame and look-ahead */
+ float mem_decim2[3], /* i/o: wsp decimation filter memory */
+ const float relE, /* i : relative frame energy */
+ const int16_t L_look, /* i : look-ahead length */
+ const int16_t last_class, /* i : frame classification of last frame */
+ const int16_t bwidth, /* i : audio bandwidth */
+ const int16_t Opt_SC_VBR /* i : SC-VBR flag */
+);
+
+void pitch_ol2(
+ const int16_t pit_min, /* i : pit_min value */
+ const int16_t pitch_ol, /* i : pitch to be improved */
+ float *pitch_fr, /* o : adjusted 1/4 fractional pitch */
+ float *voicing_fr, /* o : adjusted 1/4 fractional voicing */
+ const int16_t pos, /* i : position in frame where to calculate the improv. */
+ const float *wsp, /* i : weighted speech for current frame and look-ahead */
+ const int16_t delta /* i : delta for pitch search */
+);
+
+void StableHighPitchDetect(
+ int16_t *flag_spitch, /* o : flag to indicate very short stable pitch */
+ int16_t pitch[], /* i/o: OL pitch buffer */
+ const float voicing[], /* i : OL pitch gains */
+ const float Bin_E[], /* i : per bin log energy spectrum */
+ const float wsp[], /* i : weighted speech */
+ const int16_t localVAD, /* i : local VAD flag */
+ float *voicing_sm, /* i/o: smoothed open-loop pitch gains */
+ float *voicing0_sm, /* i/o: smoothed high pitch gains */
+ float *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy */
+ int16_t *predecision_flag, /* i/o: predecision flag */
+ float *diff_sm, /* i/o: smoothed pitch frequency difference */
+ float *energy_sm /* i/o: smoothed energy around pitch frequency */
+);
+
+void pitchDoubling_det(
+ const float *wspeech,
+ int16_t *pitch_ol,
+ float *pitch_fr,
+ float *voicing_fr );
+
+void gain_enc_amr_wb(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const float *xn, /* i : target vector */
+ const float *y1, /* i : zero-memory filtered adaptive excitation */
+ const float *y2, /* i : zero-memory filtered algebraic codebook excitation */
+ const float *code, /* i : algebraic excitation */
+ const int32_t core_brate, /* i : core bitrate */
+ float *gain_pit, /* i/o: Pitch gain / Quantized pitch gain */
+ float *gain_code, /* o : Quantized codebook gain */
+ float *gain_inov, /* o : innovation gain */
+ float *norm_gain_code, /* o : norm. gain of the codebook excitation */
+ float *coeff, /* i/o: correlations , -2,, -2 and 2 */
+ const int16_t clip_gain, /* i : gain pitch clipping flag (1 = clipping) */
+ float *past_qua_en /* i/o: gain quantization memory (4 words) */
+);
+
+void gain_enc_lbr(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t gains_mode[], /* i : gain bits */
+ const int16_t coder_type, /* i : coding type */
+ const int16_t i_subfr, /* i : subframe index */
+ const float *xn, /* i : target vector */
+ const float *y1, /* i : zero-memory filtered adaptive excitation */
+ const float *y2, /* i : zero-memory filtered algebraic codebook excitation */
+ const float *code, /* i : algebraic excitation */
+ float *gain_pit, /* o : quantized pitch gain */
+ float *gain_code, /* o : quantized codebook gain */
+ float *gain_inov, /* o : gain of the innovation (used for normalization) */
+ float *norm_gain_code, /* o : norm. gain of the codebook excitation */
+ float *g_corr, /* i/o: correlations , -2,, -2 and 2 */
+ float gains_mem[], /* i/o: pitch gain and code gain from previous subframes */
+ const int16_t clip_gain, /* i : gain pitch clipping flag (1 = clipping) */
+ const int16_t L_subfr /* i : subfr Lenght */
+);
+
+void gain_enc_mless(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t gains_mode[], /* i : gain bits */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t L_frame, /* i : length of the frame */
+ const int16_t i_subfr, /* i : subframe index */
+ const int16_t tc_subfr, /* i : TC subframe index */
+ const float *xn, /* i : target vector */
+ const float *y1, /* i : zero-memory filtered adaptive excitation */
+ const float *y2, /* i : zero-memory filtered algebraic codebook excitation */
+ const float *code, /* i : algebraic excitation */
+ const float Es_pred, /* i : predicted scaled innovation energy */
+ float *gain_pit, /* o : quantized pitch gain */
+ float *gain_code, /* o : quantized codebook gain */
+ float *gain_inov, /* o : innovation gain */
+ float *norm_gain_code, /* o : norm. gain of the codebook excitation */
+ float *coeff, /* i/o: correlations , -2,, -2