PKG_NAME:=backuppc
PKG_VERSION:=3.3.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=BackupPC-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/backuppc
echo "pass: ${PASS}"
echo
echo "It is also recommended to follow the steps in"
- echo "https://wiki.openwrt.org/doc/uci/uhttpd#securing_uhttpd"
+ echo "https://openwrt.org/docs/guide-user/services/webserver/uhttpd#securing_uhttpd"
echo "to secure access to uhttpd."
fi
}
include $(TOPDIR)/rules.mk
PKG_NAME:=netdata
-PKG_VERSION:=1.18.1
+PKG_VERSION:=1.19.0
PKG_RELEASE:=1
PKG_MAINTAINER:=Josef Schlehofer <pepe.schlehofer@gmail.com>, Daniel Engberg <daniel.engberg.lists@pyret.net>
PKG_SOURCE:=$(PKG_NAME)-v$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/netdata/netdata/tar.gz/v$(PKG_VERSION)?
-PKG_HASH:=c788ec01f5228768cbf5032324e041defbac3aaa57a074b98038444fc46ba2d4
+PKG_HASH:=007656f639d3544698af503f35550aeb4d4d5a06b81801bf5acf4ac21db68f6e
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
include $(TOPDIR)/rules.mk
PKG_NAME:=syslog-ng
-PKG_VERSION:=3.24.1
+PKG_VERSION:=3.25.1
PKG_RELEASE:=1
PKG_MAINTAINER:=Josef Schlehofer <josef.schlehofer@nic.cz>
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/balabit/syslog-ng/releases/download/$(PKG_NAME)-$(PKG_VERSION)/
-PKG_HASH:=d4d0a0357b452be96b69d6f741129275530d8f0451e35adc408ad5635059fa3d
+PKG_HASH:=34cb9673bcde58d543890e6c1189f466f938e199f227c524a6fa2f47f4db6817
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1
# More details about these settings can be found here:
# https://www.syslog-ng.com/technical-documents/list/syslog-ng-open-source-edition
-@version: 3.24
+@version: 3.25
@include "scl.conf"
@include "/etc/syslog-ng.d/" # Put any customization files in this directory
PKG_NAME:=zabbix
PKG_VERSION:=4.0.11
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/zabbix
-#see http://wiki.openwrt.org/doc/howto/zabbix for ready to use templates
+#see https://openwrt.org/docs/guide-user/services/network_monitoring/zabbix for ready to use templates
# If you want to know the exact meaning of an UserParameter, you can search in the ieee80211 standard:
-# http://standards.ieee.org/getieee802/download/802.11-2012.pdf
+# https://standards.ieee.org/getieee802/download/802.11-2012.pdf
# example: for mac80211.ACKFailureCount search for dot11ACKFailureCount (page 2145)
# mac80211 phy discovery (like 'phy0')
-#see http://wiki.openwrt.org/doc/howto/zabbix for ready to use templates
+#see https://openwrt.org/docs/guide-user/services/network_monitoring/zabbix for ready to use templates
# network interface discovery
# example: {"data":[{"{#IF}":"lo", "{#NET}":"loopback"},{"{#IF}":"br-lan", "{#NET}":"lan"},{"{#IF}":"eth0.1", "{#NET}":"wan"}]}
-#see http://wiki.openwrt.org/doc/howto/zabbix for ready to use templates
+#see https://openwrt.org/docs/guide-user/services/network_monitoring/zabbix for ready to use templates
# wifi interface discovery
# example: {"data":[{"{#IF}":"wlan0", "{#MODE}":"ap", "{#SSID}":"Openwrt", "{#NET}":"lan", "{#DEV}":"radio0", "{#ENC}":"psk2+ccmp", "{#TYPE}":"mac80211", "{#HWMODE}":"11ng", "{#CHANNEL}":"11", "{#BSSID}":"xx:xx:xx:xx:xx:xx"}]}
include $(TOPDIR)/rules.mk
PKG_NAME:=meson
-PKG_VERSION:=0.52.0
+PKG_VERSION:=0.52.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/mesonbuild/meson/releases/download/$(PKG_VERSION)/
-PKG_HASH:=d60f75f0dedcc4fd249dbc7519d6f3ce6df490033d276ef1cf27453ef4938d32
+PKG_HASH:=0c277472e49950a5537e3de3e60c57b80dbf425788470a1a8ed27446128fc035
PKG_MAINTAINER:=Andre Heider <a.heider@gmail.com>
PKG_LICENSE:=Apache-2.0
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/cifsd-team/cifsd.git
-PKG_SOURCE_DATE:=2019-11-22
-PKG_SOURCE_VERSION:=511ee7e852c0be06b74fbb3eba69760b86658679
-PKG_MIRROR_HASH:=23040d73230ff6afcea46cf9c51a1aab7b706859471de204da4824bfea5934c8
+PKG_SOURCE_DATE:=2019-11-27
+PKG_SOURCE_VERSION:=b8675c8ac144ece00f3e6bcc5436c8ace99e23e9
+PKG_MIRROR_HASH:=3d67af87f30d837f95510663efc42f1451651dc235987408924b56cb277fc8e8
PKG_MAINTAINER:=Andy Walsh <andy.walsh44+github@gmail.com>
PKG_LICENSE:=GPL-2.0-or-later
mips|mipsle) installsuffix="$(GO_MIPS)" ;; \
mips64|mips64le) installsuffix="$(GO_MIPS64)" ;; \
esac ; \
- ldflags="all=-linkmode external -extldflags '$(TARGET_LDFLAGS)'" ; \
+ ldflags="-linkmode external -extldflags '$(TARGET_LDFLAGS)'" ; \
pkg_gcflags="$(GO_PKG_GCFLAGS)" ; \
pkg_ldflags="$(GO_PKG_LDFLAGS)" ; \
for def in $(GO_PKG_LDFLAGS_X); do \
go install \
$$$${installsuffix:+-installsuffix $$$$installsuffix} \
-trimpath \
- -ldflags "$$$$ldflags" \
+ -ldflags "all=$$$$ldflags" \
-v \
$$$${pkg_gcflags:+-gcflags "$$$$pkg_gcflags"} \
- $$$${pkg_ldflags:+-ldflags "$$$$pkg_ldflags"} \
+ $$$${pkg_ldflags:+-ldflags "$$$$pkg_ldflags $$$$ldflags"} \
$(1) \
$$$$targets ; \
retval=$$$$? ; \
GO_VERSION_MAJOR_MINOR:=1.13
-GO_VERSION_PATCH:=4
+GO_VERSION_PATCH:=5
PKG_SOURCE:=go$(PKG_VERSION).src.tar.gz
PKG_SOURCE_URL:=$(GO_SOURCE_URLS)
-PKG_HASH:=95dbeab442ee2746b9acf0934c8e2fc26414a0565c008631b04addb8c02e7624
+PKG_HASH:=27d356e2a0b30d9983b60a788cf225da5f914066b37a6b4f69d457ba55a626ff
PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE
include $(TOPDIR)/rules.mk
PKG_NAME:=lua-rs232
+PKG_SOURCE_DATE:=2019-11-20
+PKG_SOURCE_VERSION:=c106c94d1a5a84e8582c936528303528608776c2
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/srdgame/librs232
-PKG_SOURCE_DATE:=2019-09-17
-PKG_SOURCE_VERSION:=1c29a279484ee4850611b76a6571566e0ec133bb
-PKG_MIRROR_HASH:=c9063a729935135278f17dd98ca31757acfd4405bdf9f6e49d77ed0df8ddc823
+PKG_MIRROR_HASH:=6fcabfd1501b3a7719229334ce73f1cc74f5ac5795b8faf6d65eb2ae6b14f9a5
PKG_MAINTAINER:=Dirk Chang <dirk@kooiot.com>
PKG_LICENSE:=MIT
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/include/librs232/rs232* $(1)/usr/include/librs232
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/librs232* $(1)/usr/lib/
- $(INSTALL_DIR) $(1)/usr/lib/lua/5.1
- $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/lua/5.1/luars232* $(1)/usr/lib/lua/5.1
+ $(INSTALL_DIR) $(1)/usr/lib/lua
+ $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/lua/5.1/luars232* $(1)/usr/lib/lua
$(INSTALL_DIR) $(1)/usr/lib/pkgconfig
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/librs232.pc $(1)/usr/lib/pkgconfig
endef
define Package/lua-rs232/install
$(INSTALL_DIR) $(1)/usr/lib/
$(CP) $(PKG_INSTALL_DIR)/usr/lib/librs232.so* $(1)/usr/lib/
- $(INSTALL_DIR) $(1)/usr/lib/lua/5.1
- $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/lua/5.1/luars232* $(1)/usr/lib/lua/5.1
+ $(INSTALL_DIR) $(1)/usr/lib/lua
+ $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/lua/5.1/luars232* $(1)/usr/lib/lua
endef
$(eval $(call BuildPackage,lua-rs232))
#define MODULE_NAMESPACE "luars232"
#define MODULE_VERSION "1.0.3"
#define MODULE_BUILD "$Id: luars232.c 15 2011-02-23 09:02:20Z sp $"
-@@ -552,9 +551,6 @@
+@@ -553,9 +552,6 @@
lua_pushstring(L, MODULE_BUILD);
lua_setfield(L, -2, "_BUILD");
+++ /dev/null
---- a/bindings/lua/luars232.c
-+++ b/bindings/lua/luars232.c
-@@ -529,7 +529,7 @@ static void create_metatables(lua_State *L, const char *name, const luaL_reg *me
- #endif
- }
-
--RS232_LIB int luaopen_luars232(lua_State *L)
-+RS232_LIB static int luaopen_luars232(lua_State *L)
- {
- int i;
- create_metatables(L, MODULE_NAMESPACE, port_methods);
-@@ -560,6 +560,7 @@ RS232_LIB int luaopen_luars232(lua_State *L)
- return 1;
- }
-
--RS232_LIB int luaopen_rs232_core(lua_State *L){
-+__attribute__((unused))
-+RS232_LIB static int luaopen_rs232_core(lua_State *L){
- return luaopen_luars232(L);
- }
---- a/include/librs232/rs232.h
-+++ b/include/librs232/rs232.h
-@@ -134,7 +134,7 @@ enum rs232_flow_e {
-
- enum rs232_status_e {
- RS232_PORT_CLOSED,
-- RS232_PORT_OPEN,
-+ RS232_PORT_OPEN
- };
-
- enum rs232_dtr_e {
PKG_NPM_NAME:=node-hid
PKG_NAME:=$(PKG_NPM_NAME)
-PKG_VERSION:=0.7.9
+PKG_VERSION:=1.1.0
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NPM_NAME)-$(PKG_VERSION).tgz
PKG_SOURCE_URL:=https://registry.npmjs.org/$(PKG_NPM_NAME)/-/
-PKG_HASH:=a13710ebff0a2d0e60e08442db192a4e891db89d535306d461b8a95ede7dbd90
+PKG_HASH:=a128331388b9a0ac443fb55493e37a9b8043f34699c60453f395ad37b7d5f145
PKG_BUILD_DEPENDS:=node/host
PKG_USE_MIPS16:=0
PKG_LICENSE_FILES:=
include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/nls.mk
define Package/node-hid
SUBMENU:=Node.js
CATEGORY:=Languages
TITLE:=Node.js package to access HID devices
URL:=https://github.com/node-hid/node-hid
- DEPENDS:=+node +node-npm +libusb-1.0 +hidapi +libudev-fbsd
+ DEPENDS:=+node +node-npm +libusb-1.0 +hidapi +libudev-fbsd $(ICONV_DEPENDS)
endef
define Package/node-hid/description
TMPNPM:=$(shell mktemp -u XXXXXXXXXX)
TARGET_CFLAGS+=$(FPIC) -I$(STAGING_DIR)/usr/include/libusb-1.0
+TARGET_LDFLAGS+=$(if $(ICONV_FULL),-liconv)
define Build/Compile
git init $(PKG_BUILD_DIR)
$(CP) $(PKG_INSTALL_DIR)/usr/lib/node_modules/$(PKG_NPM_NAME)/{node_modules,src} \
$(1)/usr/lib/node/$(PKG_NPM_NAME)/
$(INSTALL_DIR) $(1)/usr/lib/node/$(PKG_NPM_NAME)/build/Release
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/node_modules/$(PKG_NPM_NAME)/build/Release/HID.node \
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/node_modules/$(PKG_NPM_NAME)/build/Release/HID*.node \
$(1)/usr/lib/node/$(PKG_NPM_NAME)/build/Release/
$(INSTALL_DIR) $(1)/usr/bin
$(LN) ../lib/node/node-hid/src/show-devices.js $(1)/usr/bin/hid-showdevices
--- /dev/null
+diff -urN a/hidapi/linux/hid.c b/hidapi/linux/hid.c
+--- a/hidapi/linux/hid.c 1985-10-26 17:15:00.000000000 +0900
++++ b/hidapi/linux/hid.c 2019-12-12 11:15:11.164454207 +0900
+@@ -24,6 +24,7 @@
+ /* C */
+ #include <stdio.h>
+ #include <string.h>
++#include <stdarg.h>
+ #include <stdlib.h>
+ #include <locale.h>
+ #include <errno.h>
PKG_NPM_SCOPE:=serialport
PKG_NPM_NAME:=bindings
PKG_NAME:=node-$(PKG_NPM_SCOPE)-$(PKG_NPM_NAME)
-PKG_VERSION:=2.0.8
+PKG_VERSION:=8.0.4
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NPM_NAME)-$(PKG_VERSION).tgz
PKG_SOURCE_URL:=https://registry.npmjs.org/@$(PKG_NPM_SCOPE)/$(PKG_NPM_NAME)/-/
-PKG_HASH:=2e0d0ca6168ba104fe60692e33c76ec44ff9533bf7b657dfc6e00da410728df4
+PKG_HASH:=fd48dba7fd4de42d9908e33c21cd028345c3d481eff668511966313cfac61695
PKG_BUILD_DEPENDS:=node/host
PKG_USE_MIPS16:=0
PKG_NPM_NAME:=serialport
PKG_NAME:=node-$(PKG_NPM_NAME)
-PKG_VERSION:=7.1.5
-PKG_RELEASE:=2
+PKG_VERSION:=8.0.5
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NPM_NAME)-$(PKG_VERSION).tgz
PKG_SOURCE_URL:=https://registry.npmjs.org/$(PKG_NPM_NAME)/-/
-PKG_HASH:=96996a97a5ba9cb2ad5fc5b249e2f653657e9c2bd6a45c8188ad64a76bf93340
+PKG_HASH:=d06e67edcc2d2c6489d8634b3bcef46325ecee0b9f8d9243af3518505608213e
PKG_BUILD_DEPENDS:=node/host
PKG_USE_MIPS16:=0
--- a/package.json
+++ b/package.json
-@@ -41,7 +41,6 @@
+@@ -46,7 +46,6 @@
],
"dependencies": {
- "@serialport/binding-mock": "^2.0.5",
-- "@serialport/bindings": "^2.0.8",
- "@serialport/parser-byte-length": "^2.0.2",
- "@serialport/parser-cctalk": "^2.0.2",
- "@serialport/parser-delimiter": "^2.0.2",
+ "@serialport/binding-mock": "^8.0.4",
+- "@serialport/bindings": "^8.0.4",
+ "@serialport/parser-byte-length": "^8.0.4",
+ "@serialport/parser-cctalk": "^8.0.4",
+ "@serialport/parser-delimiter": "^8.0.4",
include $(TOPDIR)/rules.mk
PKG_NAME:=perl-www
-PKG_VERSION:=6.41
+PKG_VERSION:=6.43
PKG_RELEASE:=1
PKG_SOURCE_URL:=https://cpan.metacpan.org/authors/id/O/OA/OALDERS
PKG_SOURCE:=libwww-perl-$(PKG_VERSION).tar.gz
-PKG_HASH:=8e271add59a2b773839b902a58a9c955b42008700df93eae1aa37167483a064a
+PKG_HASH:=e9849d7ee6fd0e89cc999e63d7612c951afd6aeea6bc721b767870d9df4ac40d
PKG_BUILD_DIR:=$(BUILD_DIR)/perl/libwww-perl-$(PKG_VERSION)
PKG_MAINTAINER:=Marcel Denia <naoir@gmx.net>
PECL_LONGNAME:=Direct I/O functions
PKG_VERSION:=0.1.0
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_HASH:=aab985e374604379d99c9c93207f2c2959ff141740d1a648c0fbd07e0e08a73e
PKG_NAME:=php7-pecl-$(PECL_NAME)
PKG_LICENSE:=PHP-3.01
PKG_LICENSE_FILES:=LICENSE
-PKG_FIXUP:=autoreconf
-
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include ../php7/pecl.mk
PECL_NAME:=pecl_http
PECL_LONGNAME:=Extended HTTP Support
-PKG_VERSION:=3.2.1
-PKG_RELEASE:=1
-PKG_HASH:=9c5ab5ace7f232699bf4d8997dd9135c92bb630357c51d968d1baca698fadc92
+PKG_VERSION:=3.2.3
+PKG_RELEASE:=2
+PKG_HASH:=cf9d2a2ed335e572366025eca1d69e86c585f96ca07db341839a06f52ee4aa88
PKG_NAME:=php7-pecl-http
PKG_SOURCE:=$(PECL_NAME)-$(PKG_VERSION).tgz
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1
-PKG_FIXUP:=autoreconf
-
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include ../php7/pecl.mk
--with-http-libidnkit-dir=no \
--with-http-libidnkit2-dir=no
-$(eval $(call PECLPackage,http,$(PECL_LONGNAME),+icu +libcurl +librt +libevent2 +PACKAGE_libidn:libidn +libidn2 +php7-mod-hash +php7-mod-iconv +php7-mod-session +php7-pecl-raphf +php7-pecl-propro,30))
+$(eval $(call PECLPackage,http,$(PECL_LONGNAME),+icu +libcurl +librt +libevent2 +PACKAGE_libidn:libidn +libidn2 +php7-mod-iconv +php7-mod-session +php7-pecl-raphf +php7-pecl-propro,30))
$(eval $(call BuildPackage,$(PKG_NAME)))
PECL_LONGNAME:=Bindings for the Kerberos library
PKG_VERSION:=1.1.2
-PKG_RELEASE:=2
+PKG_RELEASE:=4
PKG_HASH:=3301e047fc7dc3574da19b2a4b18e15feca5ad39db9335c3353a8e16b855c35b
PKG_NAME:=php7-pecl-krb5
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1
-PKG_FIXUP:=autoreconf
-
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include ../php7/pecl.mk
-CONFIGURE_ARGS+= --with-krb5=shared,"$(STAGING_DIR)/usr"
+CONFIGURE_ARGS+= \
+ --with-krb5=shared,"$(STAGING_DIR)/usr" \
+ --with-krb5config=$(STAGING_DIR)/usr/bin/krb5-config
$(eval $(call PECLPackage,krb5,$(PECL_LONGNAME),+krb5-libs,30))
$(eval $(call BuildPackage,$(PKG_NAME)))
PKG_NAME:=php7-pecl-$(PECL_NAME)
PKG_VERSION=2019-05-30-$(PKG_SOURCE_VERSION)
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/expressif/pecl-event-libevent.git
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_SOURCE_VERSION)
PKG_BUILD_PARALLEL:=1
-PKG_FIXUP:=autoreconf
-
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include ../php7/pecl.mk
PECL_LONGNAME:=Bindings for the libmcrypt library
PKG_VERSION:=1.0.3
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_HASH:=affd675843a079e9efd49ac2f723286dd5bcb0916315aa53e2ae5edd5eadb034
PKG_NAME:=php7-pecl-mcrypt
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1
-PKG_FIXUP:=autoreconf
-
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include ../php7/pecl.mk
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1
-PKG_FIXUP:=autoreconf
+#PKG_FIXUP:=autoreconf
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
PECL_NAME:=raphf
PECL_LONGNAME:=Resource and persistent handles factory
-PKG_VERSION:=2.0.0
+PKG_VERSION:=2.0.1
PKG_RELEASE:=2
-PKG_HASH:=95a59ea0dc3fc172805a6acd8327b122dd159b0a85b253826166457a05efa411
+PKG_HASH:=da3566db17422e5ef08b7ff144162952aabc14cb22407cc6b1d2a2d095812bd0
PKG_NAME:=php7-pecl-raphf
PKG_SOURCE:=$(PECL_NAME)-$(PKG_VERSION).tgz
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1
-PKG_FIXUP:=autoreconf
-
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include ../php7/pecl.mk
PECL_NAME:=redis
PECL_LONGNAME:=PHP extension for interfacing with Redis
-PKG_VERSION:=5.0.2
-PKG_RELEASE:=1
-PKG_HASH:=4e18d7ebe032a562c358d79f94efa5f187ea90db7a56ef648476e24f4fe0b72c
+PKG_VERSION:=5.1.1
+PKG_RELEASE:=2
+PKG_HASH:=621c9d2b4054c797b0e5d5bc5e0f1eeb49bedb37f20e46f838aa4d17d2fe8180
PKG_NAME:=php7-pecl-redis
PKG_SOURCE:=$(PECL_NAME)-$(PKG_VERSION).tgz
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1
-PKG_FIXUP:=autoreconf
-
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include ../php7/pecl.mk
CONFIGURE_ARGS+= \
--enable-redis \
+ --enable-redis-json \
--disable-redis-igbinary \
- --disable-redis-lzf
+ --disable-redis-lzf \
+ --disable-redis-msgpack
-$(eval $(call PECLPackage,$(PECL_NAME),$(PECL_LONGNAME),+php7-mod-hash +php7-mod-session,25))
+$(eval $(call PECLPackage,$(PECL_NAME),$(PECL_LONGNAME),+php7-mod-json +php7-mod-session,25))
$(eval $(call BuildPackage,$(PKG_NAME)))
include $(TOPDIR)/rules.mk
PKG_NAME:=php
-PKG_VERSION:=7.2.25
+PKG_VERSION:=7.4.1
PKG_RELEASE:=1
PKG_MAINTAINER:=Michael Heimpold <mhei@heimpold.de>
-
PKG_LICENSE:=PHP-3.01
PKG_LICENSE_FILES:=LICENSE
PKG_CPE_ID:=cpe:/a:php:php
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=http://www.php.net/distributions/
-PKG_HASH:=746efeedc38e6ff7b1ec1432440f5fa801537adf6cd21e4afb3f040e5b0760a9
+PKG_HASH:=561bb866bdd509094be00f4ece7c3543ec971c4d878645ee81437e291cffc762
-PKG_FIXUP:=libtool autoreconf
PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0
-PHP7_MODULES = \
+PHP7_MODULES= \
bcmath \
calendar ctype curl \
- fileinfo \
dom \
exif \
- ftp \
+ fileinfo filter ftp \
gettext gd gmp \
- hash \
iconv imap intl \
json \
ldap \
pcntl pdo pdo-mysql pdo-pgsql pdo-sqlite pgsql phar \
session shmop simplexml snmp soap sockets sqlite3 sysvmsg sysvsem sysvshm \
tokenizer \
- xml xmlreader xmlwriter zip \
+ xml xmlreader xmlwriter \
+ zip
PKG_CONFIG_DEPENDS:= \
$(patsubst %,CONFIG_PACKAGE_php7-mod-%,$(PHP7_MODULES)) \
- CONFIG_PHP7_FILTER CONFIG_PHP7_LIBXML CONFIG_PHP7_SYSTEMTZDATA CONFIG_PHP7_LIBFREETYPE
+ CONFIG_PHP7_LIBXML CONFIG_PHP7_SYSTEMTZDATA
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
endef
define Package/php7/config
- config PHP7_FILTER
- bool "PHP7 Filter support"
- depends on PACKAGE_php7-cli || PACKAGE_php7-cgi
- default y
-
config PHP7_LIBXML
bool "PHP7 LIBXML support"
depends on PACKAGE_php7-cli || PACKAGE_php7-cgi
define Package/php7
$(call Package/php7/Default)
- DEPENDS:=+libpcre +zlib \
+ DEPENDS:=+libpcre2 +zlib \
+PHP7_LIBXML:libxml2 \
+PHP7_SYSTEMTZDATA:zoneinfo-core
endef
This package contains the FastCGI Process Manager of the PHP7 interpreter.
endef
-define Package/php7-mod-gd/config
- config PHP7_LIBFREETYPE
- bool "Enable Freetype 2 support in php7-mod-gd"
- depends on PACKAGE_php7-mod-gd
- default y
-endef
-
define Package/php7-mod-intl/config
config PHP7_FULLICUDATA
bool "Add dependency to full ICU Data"
--disable-short-tags \
\
--without-valgrind \
- --with-pcre-regex="$(STAGING_DIR)/usr" \
- --with-zlib="$(STAGING_DIR)/usr" \
- --with-zlib-dir="$(STAGING_DIR)/usr"
+ --with-external-pcre \
+ --with-zlib="$(STAGING_DIR)/usr"
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-bcmath),)
CONFIGURE_ARGS+= --enable-bcmath=shared
endif
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-curl),)
- CONFIGURE_ARGS+= --with-curl=shared,"$(STAGING_DIR)/usr"
+ CONFIGURE_ARGS+= --with-curl=shared
else
CONFIGURE_ARGS+= --without-curl
endif
-ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-fileinfo),)
- CONFIGURE_ARGS+= --enable-fileinfo=shared
-else
- CONFIGURE_ARGS+= --disable-fileinfo
-endif
-
-ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-gettext),)
- CONFIGURE_ARGS+= --with-gettext=shared,"$(STAGING_DIR)/usr/lib/libintl-full"
-else
- CONFIGURE_ARGS+= --without-gettext
-endif
-
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-dom),)
CONFIGURE_ARGS+= --enable-dom=shared
else
CONFIGURE_ARGS+= --disable-exif
endif
+ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-fileinfo),)
+ CONFIGURE_ARGS+= --enable-fileinfo=shared,"$(STAGING_DIR)/usr"
+else
+ CONFIGURE_ARGS+= --disable-fileinfo
+endif
+
+ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-filter),)
+ CONFIGURE_ARGS+= --enable-filter=shared,"$(STAGING_DIR)/usr"
+else
+ CONFIGURE_ARGS+= --disable-filter
+endif
+
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-ftp),)
CONFIGURE_ARGS+= --enable-ftp=shared
else
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-gd),)
CONFIGURE_ARGS+= \
- --with-gd=shared \
- --with-jpeg-dir="$(STAGING_DIR)/usr" \
- --with-png-dir="$(STAGING_DIR)/usr" \
- --with-webp-dir="$(STAGING_DIR)/usr" \
- --without-xpm-dir \
- --enable-gd-native-ttf \
- --disable-gd-jis-conv
+ --enable-gd=shared,"$(STAGING_DIR)/usr" \
+ --with-external-gd
else
- CONFIGURE_ARGS+= --without-gd
+ CONFIGURE_ARGS+= --disable-gd
endif
-ifneq ($(CONFIG_PHP7_LIBFREETYPE),)
- CONFIGURE_ARGS+= --with-freetype-dir="$(STAGING_DIR)"
+
+ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-gettext),)
+ CONFIGURE_ARGS+= --with-gettext=shared,"$(STAGING_DIR)/usr/lib/libintl-full"
else
- CONFIGURE_ARGS+= --without-freetype-dir
+ CONFIGURE_ARGS+= --without-gettext
endif
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-gmp),)
CONFIGURE_ARGS+= --without-gmp
endif
-ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-hash),)
- CONFIGURE_ARGS+= --enable-hash=shared
-else
- CONFIGURE_ARGS+= --disable-hash
-endif
-
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-iconv),)
CONFIGURE_ARGS+= --with-iconv=shared,"$(ICONV_PREFIX)"
else
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-imap),)
CONFIGURE_ARGS+= \
--with-imap=shared,"$(STAGING_DIR)/usr" \
- --with-imap-kerberos=no \
+ --with-kerberos=no \
--with-imap-ssl="$(STAGING_DIR)/usr"
else
CONFIGURE_ARGS+= --without-imap
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-ldap),)
CONFIGURE_ARGS+= \
--with-ldap=shared,"$(STAGING_DIR)/usr" \
- --with-ldap-sasl="$(STAGING_DIR)/usr"
+ --with-ldap-sasl
else
CONFIGURE_ARGS+= --without-ldap
endif
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-mbstring),)
- CONFIGURE_ARGS+= --enable-mbstring=shared --enable-mbregex
+ CONFIGURE_ARGS+= \
+ --enable-mbstring=shared \
+ --enable-mbregex
else
CONFIGURE_ARGS+= --disable-mbstring
endif
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-openssl)$(CONFIG_PACKAGE_php7-mod-ftp)$(CONFIG_PACKAGE_php7-mod-imap)$(CONFIG_PACKAGE_php7-mod-snmp),)
CONFIGURE_ARGS+= \
- --with-openssl=shared,"$(STAGING_DIR)/usr" \
+ --with-openssl=shared \
--with-kerberos=no \
--with-openssl-dir="$(STAGING_DIR)/usr"
else
CONFIGURE_ARGS+= --without-pdo-pgsql
endif
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-pdo-sqlite),)
- CONFIGURE_ARGS+= --with-pdo-sqlite=shared,"$(STAGING_DIR)/usr"
+ CONFIGURE_ARGS+= --with-pdo-sqlite=shared
else
CONFIGURE_ARGS+= --without-pdo-sqlite
endif
endif
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-sqlite3),)
- CONFIGURE_ARGS+= --with-sqlite3=shared,"$(STAGING_DIR)/usr"
+ CONFIGURE_ARGS+= --with-sqlite3=shared
else
CONFIGURE_ARGS+= --without-sqlite3
endif
ifneq ($(SDK)$(CONFIG_PACKAGE_php7-mod-xml),)
CONFIGURE_ARGS+= --enable-xml=shared,"$(STAGING_DIR)/usr"
- ifneq ($(CONFIG_PHP7_LIBXML),)
- CONFIGURE_ARGS+= --with-libxml-dir="$(STAGING_DIR)/usr/include/libxml2"
- else
- CONFIGURE_ARGS+= --with-libexpat-dir="$(STAGING_DIR)/usr"
+ ifneq ($(CONFIG_PHP7_LIBXML),y)
+ CONFIGURE_ARGS+= --with-expat
endif
else
CONFIGURE_ARGS+= --disable-xml
endif
ifneq ($(CONFIG_PACKAGE_php7-mod-zip),)
- CONFIGURE_ARGS+= --enable-zip=shared
+ CONFIGURE_ARGS+= --with-zip=shared,"$(STAGING_DIR)/usr"
else
- CONFIGURE_ARGS+= --disable-zip
-endif
-
-ifneq ($(SDK)$(CONFIG_PHP7_FILTER),)
- CONFIGURE_ARGS+= --enable-filter
-else
- CONFIGURE_ARGS+= --disable-filter
+ CONFIGURE_ARGS+= --without-zip
endif
ifneq ($(SDK)$(CONFIG_PHP7_LIBXML),)
- CONFIGURE_ARGS+= --enable-libxml
- CONFIGURE_ARGS+= --with-libxml-dir="$(STAGING_DIR)/usr/include/libxml2"
+ CONFIGURE_ARGS+= --with-libxml
else
- CONFIGURE_ARGS+= --disable-libxml
+ CONFIGURE_ARGS+= --without-libxml
endif
ifneq ($(CONFIG_PHP7_SYSTEMTZDATA),)
php_cv_cc_rpath="no" \
iconv_impl_name="gnu_libiconv" \
ac_cv_php_xml2_config_path="$(STAGING_DIR)/host/bin/xml2-config" \
- ac_cv_u8t_decompose=yes
+ ac_cv_u8t_decompose=yes \
+ ac_cv_have_pcre2_jit=no
define Package/php7/conffiles
/etc/php.ini
define Build/Prepare
$(call Build/Prepare/Default)
- ( cd $(PKG_BUILD_DIR); touch configure.in; ./buildconf --force )
+ ( cd $(PKG_BUILD_DIR); touch configure.ac; ./buildconf --force )
endef
define Build/InstallDev
$(eval $(call BuildModule,dom,DOM,+@PHP7_LIBXML +PACKAGE_php7-mod-dom:libxml2))
$(eval $(call BuildModule,exif,EXIF))
$(eval $(call BuildModule,fileinfo,Fileinfo))
+$(eval $(call BuildModule,filter,Filter))
$(eval $(call BuildModule,ftp,FTP,+PACKAGE_php7-mod-ftp:libopenssl))
-$(eval $(call BuildModule,gd,GD graphics,+PACKAGE_php7-mod-gd:libjpeg +PACKAGE_php7-mod-gd:libpng +PACKAGE_php7-mod-gd:libwebp +PHP7_LIBFREETYPE:libfreetype))
+$(eval $(call BuildModule,gd,GD graphics,+PACKAGE_php7-mod-gd:libgd))
$(eval $(call BuildModule,gettext,Gettext,+PACKAGE_php7-mod-gettext:libintl-full))
$(eval $(call BuildModule,gmp,GMP,+PACKAGE_php7-mod-gmp:libgmp))
-$(eval $(call BuildModule,hash,Hash))
$(eval $(call BuildModule,iconv,iConv,$(ICONV_DEPENDS)))
$(eval $(call BuildModule,imap,IMAP,+PACKAGE_php7-mod-imap:libopenssl +PACKAGE_libpam:libpam +PACKAGE_php7-mod-imap:uw-imap))
$(eval $(call BuildModule,intl,Internationalization Functions,+PACKAGE_php7-mod-intl:icu +PHP7_FULLICUDATA:icu-full-data))
$(eval $(call BuildModule,json,JSON))
$(eval $(call BuildModule,ldap,LDAP,+PACKAGE_php7-mod-ldap:libopenldap +PACKAGE_php7-mod-ldap:libsasl2))
-$(eval $(call BuildModule,mbstring,MBString))
+$(eval $(call BuildModule,mbstring,MBString,+PACKAGE_php7-mod-mbstring:oniguruma))
$(eval $(call BuildModule,mysqli,MySQL Improved Extension,+PACKAGE_php7-mod-mysqli:php7-mod-mysqlnd,30))
-$(eval $(call BuildModule,mysqlnd,MySQL Native Driver,+php7-mod-hash))
+$(eval $(call BuildModule,mysqlnd,MySQL Native Driver))
$(eval $(call BuildModule,opcache,OPcache,,,zend))
$(eval $(call BuildModule,openssl,OpenSSL,+PACKAGE_php7-mod-openssl:libopenssl,15))
$(eval $(call BuildModule,pcntl,PCNTL))
$(eval $(call BuildModule,pdo-pgsql,PDO driver for PostgreSQL,+php7-mod-pdo +PACKAGE_php7-mod-pdo-pgsql:libpq))
$(eval $(call BuildModule,pdo-sqlite,PDO driver for SQLite 3.x,+php7-mod-pdo +PACKAGE_php7-mod-pdo-sqlite:libsqlite3 +PACKAGE_php7-mod-pdo-sqlite:librt))
$(eval $(call BuildModule,pgsql,PostgreSQL,+PACKAGE_php7-mod-pgsql:libpq))
-$(eval $(call BuildModule,phar,Phar Archives,+php7-mod-hash))
+$(eval $(call BuildModule,phar,Phar Archives))
$(eval $(call BuildModule,session,Session))
$(eval $(call BuildModule,shmop,Shared Memory))
$(eval $(call BuildModule,simplexml,SimpleXML,+@PHP7_LIBXML +PACKAGE_php7-mod-simplexml:libxml2))
$(eval $(call BuildModule,xml,XML,+PHP7_LIBXML:libxml2 +!PHP7_LIBXML:libexpat))
$(eval $(call BuildModule,xmlreader,XMLReader,+@PHP7_LIBXML +PACKAGE_php7-mod-dom:php7-mod-dom +PACKAGE_php7-mod-xmlreader:libxml2))
$(eval $(call BuildModule,xmlwriter,XMLWriter,+@PHP7_LIBXML +PACKAGE_php7-mod-xmlwriter:libxml2))
-$(eval $(call BuildModule,zip,ZIP,+PACKAGE_php7-mod-zip:zlib))
+$(eval $(call BuildModule,zip,ZIP,+PACKAGE_php7-mod-zip:libzip))
From: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
-Date: Thu, 7 Mar 2019 19:36:30 +0000
+Date: Thu, 7 Mar 2019 19:42:35 +0000
Subject: Add-support-for-use-of-the-system-timezone-database
# License: MIT
than embedding a copy. Discussed upstream but was not desired.
History:
-r17: adapt for autotool change in 7.2.16RC1
+r18: adapt for autotool change in 7.3.3RC1
+r17: adapt for timelib 2018.01 (in 7.3.2RC1)
r16: adapt for timelib 2017.06 (in 7.2.3RC1)
r15: adapt for timelib 2017.05beta7 (in 7.2.0RC1)
r14: improve check for valid tz file
r1: initial revision
---
ext/date/config0.m4 | 13 ++
- ext/date/lib/parse_tz.c | 536 +++++++++++++++++++++++++++++++++++++++++++++++-
- 2 files changed, 546 insertions(+), 3 deletions(-)
+ ext/date/lib/parse_tz.c | 535 +++++++++++++++++++++++++++++++++++++++++++++++-
+ 2 files changed, 545 insertions(+), 3 deletions(-)
diff --git a/ext/date/config0.m4 b/ext/date/config0.m4
-index e464156..00dae8b 100644
+index 20e4164..a612436 100644
--- a/ext/date/config0.m4
+++ b/ext/date/config0.m4
-@@ -10,6 +10,19 @@ io.h
+@@ -4,6 +4,19 @@ AC_CHECK_HEADERS([io.h])
dnl Check for strtoll, atoll
AC_CHECK_FUNCS(strtoll atoll)
timelib_sources="lib/astro.c lib/dow.c lib/parse_date.c lib/parse_tz.c
lib/timelib.c lib/tm2unixtime.c lib/unixtime2tm.c lib/parse_iso_intervals.c lib/interval.c"
diff --git a/ext/date/lib/parse_tz.c b/ext/date/lib/parse_tz.c
-index 960e528..501b09e 100644
+index 020da31..9b39c6e 100644
--- a/ext/date/lib/parse_tz.c
+++ b/ext/date/lib/parse_tz.c
-@@ -25,8 +25,21 @@
+@@ -26,8 +26,21 @@
#include "timelib.h"
#include "timelib_private.h"
#if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__))
# if defined(__LITTLE_ENDIAN__)
-@@ -67,6 +80,11 @@ static int read_php_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
+@@ -88,6 +101,11 @@ static int read_php_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
{
uint32_t version;
/* read ID */
version = (*tzf)[3] - '0';
*tzf += 4;
-@@ -374,7 +392,429 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz)
+@@ -412,7 +430,429 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz)
}
}
{
int left = 0, right = tzdb->index_size - 1;
-@@ -400,9 +840,48 @@ static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const
+@@ -438,9 +878,48 @@ static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const
return 0;
}
}
const timelib_tzdb_index_entry *timelib_timezone_identifiers_list(const timelib_tzdb *tzdb, int *count)
-@@ -414,7 +893,30 @@ const timelib_tzdb_index_entry *timelib_timezone_identifiers_list(const timelib_
+@@ -452,7 +931,30 @@ const timelib_tzdb_index_entry *timelib_timezone_identifiers_list(const timelib_
int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb)
{
const unsigned char *tzf;
}
static int skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
-@@ -456,12 +958,14 @@ static timelib_tzinfo* timelib_tzinfo_ctor(char *name)
+@@ -494,12 +996,14 @@ static timelib_tzinfo* timelib_tzinfo_ctor(char *name)
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb, int *error_code)
{
const unsigned char *tzf;
tmp = timelib_tzinfo_ctor(timezone);
version = read_preamble(&tzf, tmp, &type);
-@@ -484,6 +988,29 @@ timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb, i
- timelib_tzinfo_dtor(tmp);
- return NULL;
+@@ -534,11 +1038,36 @@ timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb, i
}
-+
+ skip_posix_string(&tzf, tmp);
+
+#ifdef HAVE_SYSTEM_TZDATA
+ if (memmap) {
+ const struct location_info *li;
+ munmap(memmap, maplen);
+ } else {
+#endif
- if (version == 2 || version == 3) {
- if (!skip_64bit_preamble(&tzf, tmp)) {
- /* 64 bit preamble is not in place */
-@@ -501,6 +1028,9 @@ timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb, i
+ if (type == TIMELIB_TZINFO_PHP) {
+ read_location(&tzf, tmp);
} else {
set_default_location_and_comments(&tzf, tmp);
}
+++ /dev/null
-From: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
-Date: Sat, 2 May 2015 10:26:53 +0200
-Subject: dont-gitclean-in-build
-
----
- build/build.mk | 1 -
- 1 file changed, 1 deletion(-)
-
-diff --git a/build/build.mk b/build/build.mk
-index 9452984..b964def 100644
---- a/build/build.mk
-+++ b/build/build.mk
-@@ -63,6 +63,5 @@ gitclean-work:
- @if (test ! -f '.git/info/exclude' || grep -s "git-ls-files" .git/info/exclude); then \
- (echo "Rebuild .git/info/exclude" && echo '*.o' > .git/info/exclude && git svn propget svn:ignore | grep -v config.nice >> .git/info/exclude); \
- fi; \
-- git clean -X -f -d;
-
- .PHONY: $(ALWAYS) snapshot
1 file changed, 17 insertions(+)
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
-index cbe6e91..1999c83 100644
+index f049ae2..6a044ce 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
-@@ -1016,6 +1016,23 @@ static char* guess_timezone(const timelib_tzdb *tzdb)
+@@ -1030,6 +1030,23 @@ static char* guess_timezone(const timelib_tzdb *tzdb)
DATEG(timezone_valid) = 1;
return DATEG(default_timezone);
}
From: Thijs Kinkhorst <thijs@debian.org>
-Date: Wed, 15 Jun 2016 09:18:03 +0200
+Date: Mon, 2 Dec 2019 22:18:43 +0100
Subject: Add patch to remove build timestamps from generated binaries.
---
--- a/ext/standard/info.c
+++ b/ext/standard/info.c
-@@ -830,7 +830,6 @@ PHPAPI void php_print_info(int flag)
+@@ -802,7 +802,6 @@ PHPAPI ZEND_COLD void php_print_info(int flag)
php_info_print_box_end();
php_info_print_table_start();
php_info_print_table_row(2, "System", ZSTR_VAL(php_uname));
#endif
--- a/sapi/apache2handler/config.m4
+++ b/sapi/apache2handler/config.m4
-@@ -67,18 +67,9 @@ if test "$PHP_APXS2" != "no"; then
+@@ -64,18 +64,9 @@ if test "$PHP_APXS2" != "no"; then
fi
APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR`
*aix*)
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
-@@ -2442,9 +2442,9 @@ consult the installation file that came
- SG(request_info).no_headers = 1;
- }
+@@ -2392,9 +2392,9 @@ parent_loop_end:
+ SG(headers_sent) = 1;
+ SG(request_info).no_headers = 1;
#if ZEND_DEBUG
-- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
-+ php_printf("PHP %s (%s) (DEBUG)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
+- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
++ php_printf("PHP %s (%s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
#else
-- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
-+ php_printf("PHP %s (%s)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
+- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
++ php_printf("PHP %s (%s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
#endif
php_request_shutdown((void *) 0);
fcgi_shutdown();
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
-@@ -697,8 +697,8 @@ static int do_cli(int argc, char **argv)
+@@ -645,8 +645,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
goto out;
case 'v': /* show php version & quit */
-- php_printf("PHP %s (%s) (built: %s %s) ( %s)\nCopyright (c) 1997-2018 The PHP Group\n%s",
+- php_printf("PHP %s (%s) (built: %s %s) ( %s)\nCopyright (c) The PHP Group\n%s",
- PHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__,
-+ php_printf("PHP %s (%s) ( %s)\nCopyright (c) 1997-2018 The PHP Group\n%s",
++ php_printf("PHP %s (%s) ( %s)\nCopyright (c) The PHP Group\n%s",
+ PHP_VERSION, cli_sapi_module.name,
#if ZTS
"ZTS "
#else
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
-@@ -1755,9 +1755,9 @@ int main(int argc, char *argv[])
+@@ -1722,9 +1722,9 @@ int main(int argc, char *argv[])
SG(request_info).no_headers = 1;
#if ZEND_DEBUG
-- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
-+ php_printf("PHP %s (%s) (DEBUG)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
+- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
++ php_printf("PHP %s (%s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
#else
-- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
-+ php_printf("PHP %s (%s)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
+- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
++ php_printf("PHP %s (%s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
#endif
php_request_shutdown((void *) 0);
fcgi_shutdown();
--- a/sapi/phpdbg/phpdbg.c
+++ b/sapi/phpdbg/phpdbg.c
-@@ -1697,10 +1697,8 @@ phpdbg_main:
+@@ -1695,10 +1695,8 @@ phpdbg_main:
phpdbg_do_help_cmd(exec);
} else if (show_version) {
phpdbg_out(
-- "phpdbg %s (built: %s %s)\nPHP %s, Copyright (c) 1997-2018 The PHP Group\n%s",
-+ "phpdbg %s\nPHP %s, Copyright (c) 1997-2018 The PHP Group\n%s",
+- "phpdbg %s (built: %s %s)\nPHP %s, Copyright (c) The PHP Group\n%s",
++ "phpdbg %s\nPHP %s, Copyright (c) The PHP Group\n%s",
PHPDBG_VERSION,
- __DATE__,
- __TIME__,
index 86492d7..31c31ff 100644
--- a/sapi/fpm/status.html.in
+++ b/sapi/fpm/status.html.in
-@@ -71,11 +71,6 @@
+@@ -70,11 +70,6 @@
<tr class="h"><th>PID↓</th><th>Start Time</th><th>Start Since</th><th>Requests Served</th><th>Request Duration</th><th>Request method</th><th>Request URI</th><th>Content Length</th><th>User</th><th>Script</th><th>Last Request %CPU</th><th>Last Request Memory</th></tr>
</table>
</div>
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
-@@ -2484,11 +2484,6 @@ static void accel_gen_system_id(void)
+@@ -2652,11 +2652,6 @@ static void accel_gen_system_id(void)
PHP_MD5Update(&context, PHP_VERSION, sizeof(PHP_VERSION)-1);
PHP_MD5Update(&context, ZEND_EXTENSION_BUILD_ID, sizeof(ZEND_EXTENSION_BUILD_ID)-1);
PHP_MD5Update(&context, ZEND_BIN_ID, sizeof(ZEND_BIN_ID)-1);
- PHP_MD5Update(&context, __TIME__, sizeof(__TIME__)-1);
- }
PHP_MD5Final(digest, &context);
- for (i = 0; i < 16; i++) {
- c = digest[i] >> 4;
+ php_hash_bin2hex(accel_system_id, digest, sizeof digest);
+ }
--- a/sapi/litespeed/lsapi_main.c
+++ b/sapi/litespeed/lsapi_main.c
-@@ -1057,9 +1057,9 @@ static int cli_main( int argc, char * ar
+@@ -1284,9 +1284,9 @@ static int cli_main( int argc, char * ar
case 'v':
if (php_request_startup() != FAILURE) {
#if ZEND_DEBUG
-- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
-+ php_printf("PHP %s (%s) (DEBUG)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
+- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
++ php_printf("PHP %s (%s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
#else
-- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
-+ php_printf("PHP %s (%s)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
+- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
++ php_printf("PHP %s (%s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, get_zend_version());
#endif
#ifdef PHP_OUTPUT_NEWAPI
php_output_end_all();
+++ /dev/null
---- a/ext/standard/php_crypt_r.c
-+++ b/ext/standard/php_crypt_r.c
-@@ -96,6 +96,8 @@ void _crypt_extended_init_r(void)
- InterlockedIncrement(&initialized);
- #elif defined(HAVE_SYNC_FETCH_AND_ADD)
- __sync_fetch_and_add(&initialized, 1);
-+#elif (defined(__GNUC__) && (__GNUC__ == 3))
-+ initialized = 1;
- #elif defined(HAVE_ATOMIC_H) /* Solaris 10 defines atomic API within */
- membar_producer();
- atomic_add_int(&initialized, 1);
-From dc8bb6a53bfdfe42d9ae81d4e78c6155ad4bfd6e Mon Sep 17 00:00:00 2001
+From dd6ee0fb6715881b204fb4cb124db9134c1a6c7d Mon Sep 17 00:00:00 2001
From: Michael Heimpold <mhei@heimpold.de>
-Date: Sun, 17 May 2015 16:50:50 +0200
+Date: Mon, 2 Dec 2019 22:42:28 +0100
Subject: [PATCH] ext/opcache: fix detection of shm/mmap
The detection of sysvipc and mmap doesn't work well when cross-compiling,
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
---
- ext/opcache/config.m4 | 122 ++-----------------------------------------------
- 1 file changed, 4 insertions(+), 118 deletions(-)
+ ext/opcache/config.m4 | 10 ++++++++--
+ 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4
-index b7e4835..7b6c0aa 100644
+index 6c40cafc1..63fa5bb55 100644
--- a/ext/opcache/config.m4
+++ b/ext/opcache/config.m4
-@@ -28,127 +28,13 @@ if test "$PHP_OPCACHE" != "no"; then
-
- AC_CHECK_HEADERS([unistd.h sys/uio.h])
-
-- AC_MSG_CHECKING(for sysvipc shared memory support)
-- AC_TRY_RUN([
--#include <sys/types.h>
--#include <sys/wait.h>
--#include <sys/ipc.h>
--#include <sys/shm.h>
--#include <unistd.h>
--#include <string.h>
--
--int main() {
-- pid_t pid;
-- int status;
-- int ipc_id;
-- char *shm;
-- struct shmid_ds shmbuf;
--
-- ipc_id = shmget(IPC_PRIVATE, 4096, (IPC_CREAT | SHM_R | SHM_W));
-- if (ipc_id == -1) {
-- return 1;
-- }
--
-- shm = shmat(ipc_id, NULL, 0);
-- if (shm == (void *)-1) {
-- shmctl(ipc_id, IPC_RMID, NULL);
-- return 2;
-- }
--
-- if (shmctl(ipc_id, IPC_STAT, &shmbuf) != 0) {
-- shmdt(shm);
-- shmctl(ipc_id, IPC_RMID, NULL);
-- return 3;
-- }
--
-- shmbuf.shm_perm.uid = getuid();
-- shmbuf.shm_perm.gid = getgid();
-- shmbuf.shm_perm.mode = 0600;
--
-- if (shmctl(ipc_id, IPC_SET, &shmbuf) != 0) {
-- shmdt(shm);
-- shmctl(ipc_id, IPC_RMID, NULL);
-- return 4;
-- }
--
-- shmctl(ipc_id, IPC_RMID, NULL);
--
-- strcpy(shm, "hello");
--
-- pid = fork();
-- if (pid < 0) {
-- return 5;
-- } else if (pid == 0) {
-- strcpy(shm, "bye");
-- return 6;
-- }
-- if (wait(&status) != pid) {
-- return 7;
-- }
-- if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
-- return 8;
-- }
-- if (strcmp(shm, "bye") != 0) {
-- return 9;
-- }
-- return 0;
--}
--],dnl
-+ AC_CHECK_FUNC(shmget,[
+@@ -89,7 +89,10 @@ int main() {
+ }
+ ]])],[dnl
AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support])
-- msg=yes,msg=no,msg=no)
-- AC_MSG_RESULT([$msg])
--
-- AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support)
-- AC_TRY_RUN([
--#include <sys/types.h>
--#include <sys/wait.h>
--#include <sys/mman.h>
--#include <unistd.h>
--#include <string.h>
--
--#ifndef MAP_ANON
--# ifdef MAP_ANONYMOUS
--# define MAP_ANON MAP_ANONYMOUS
--# endif
--#endif
--#ifndef MAP_FAILED
--# define MAP_FAILED ((void*)-1)
--#endif
--
--int main() {
-- pid_t pid;
-- int status;
-- char *shm;
--
-- shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
-- if (shm == MAP_FAILED) {
-- return 1;
-- }
--
-- strcpy(shm, "hello");
-+ ])
+- msg=yes],[msg=no],[msg=no])
++ msg=yes],[msg=no],[dnl
++ AC_CHECK_FUNC(shmget,[dnl
++ AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support])
++ msg=yes],[msg=no])])
+ AC_MSG_RESULT([$msg])
-- pid = fork();
-- if (pid < 0) {
-- return 5;
-- } else if (pid == 0) {
-- strcpy(shm, "bye");
-- return 6;
-- }
-- if (wait(&status) != pid) {
-- return 7;
-- }
-- if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
-- return 8;
-- }
-- if (strcmp(shm, "bye") != 0) {
-- return 9;
-- }
-- return 0;
--}
--],dnl
-+ AC_CHECK_FUNC(mmap,[
+ AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support)
+@@ -141,7 +144,10 @@ int main() {
+ }
+ ]])],[dnl
AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support])
-- msg=yes,msg=no,msg=no)
-- AC_MSG_RESULT([$msg])
-+ ])
+- msg=yes],[msg=no],[msg=no])
++ msg=yes],[msg=no],[dnl
++ AC_CHECK_FUNC(mmap,[dnl
++ AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support])
++ msg=yes],[msg=no])])
+ AC_MSG_RESULT([$msg])
- AC_MSG_CHECKING(for mmap() using /dev/zero shared memory support)
- AC_TRY_RUN([
+ PHP_CHECK_FUNC_LIB(shm_open, rt)
--
-1.7.10.4
+2.17.1
+++ /dev/null
---- a/ext/gd/libgd/gdkanji.c
-+++ b/ext/gd/libgd/gdkanji.c
-@@ -9,6 +9,11 @@
- #include "gdhelpers.h"
-
- #include <stdarg.h>
-+
-+/* force usage of internal conversation routine */
-+#undef HAVE_ICONV_H
-+#undef HAVE_ICONV
-+
- #if defined(HAVE_ICONV_H) || defined(HAVE_ICONV)
- #include <iconv.h>
- #ifdef HAVE_ERRNO_H
+++ /dev/null
---- a/configure.ac
-+++ b/configure.ac
-@@ -422,7 +422,10 @@ PHP_CHECK_FUNC(gethostname, nsl)
- PHP_CHECK_FUNC(gethostbyaddr, nsl)
- PHP_CHECK_FUNC(yp_get_default_domain, nsl)
-
--PHP_CHECK_FUNC(dlopen, dl)
-+PHP_ADD_LIBRARY(dl)
-+PHP_DEF_HAVE(dlopen)
-+PHP_DEF_HAVE(libdl)
-+ac_cv_func_dlopen=yes
- if test "$ac_cv_func_dlopen" = "yes"; then
- AC_DEFINE(HAVE_LIBDL, 1, [ ])
- fi
---- a/ext/fileinfo/config.m4
-+++ b/ext/fileinfo/config.m4
-@@ -46,6 +46,10 @@ int main(void)
- AC_MSG_RESULT(no)
- AC_MSG_NOTICE(using libmagic strcasestr implementation)
- libmagic_sources="$libmagic_sources libmagic/strcasestr.c"
-+ ],[
-+ dnl cross-compiling; assume not present
-+ AC_MSG_NOTICE(using libmagic strcasestr implementation)
-+ libmagic_sources="$libmagic_sources libmagic/strcasestr.c"
- ])
-
- PHP_NEW_EXTENSION(fileinfo, fileinfo.c $libmagic_sources, $ext_shared,,-I@ext_srcdir@/libmagic)
--- a/ext/phar/config.m4 2016-08-17 21:50:58.000000000 +0200
+++ b/ext/phar/config.m4 2016-09-20 22:21:28.494934775 +0200
-@@ -26,7 +26,7 @@
+@@ -19,7 +19,7 @@
fi
PHP_ADD_EXTENSION_DEP(phar, hash, true)
PHP_ADD_EXTENSION_DEP(phar, spl, true)
--- a/configure.ac 2016-09-20 22:26:38.000000000 +0200
+++ b/configure.ac 2016-09-20 22:42:30.380101556 +0200
-@@ -1454,13 +1454,13 @@
+@@ -1430,13 +1430,13 @@
INLINE_CFLAGS="$INLINE_CFLAGS $standard_libtool_flag"
CXXFLAGS="$CXXFLAGS $standard_libtool_flag \$(PROF_FLAGS)"
+++ /dev/null
-commit f11d40ef88f640fe4764d2731d3061472aefe556
-Author: Philip Prindeville <philipp@redfish-solutions.com>
-Date: Wed Aug 9 20:55:25 2017 -0600
-
- Turn php_syslog() into wrapper for syslog and split lines
-
-diff --git a/Zend/zend_smart_string.h b/Zend/zend_smart_string.h
-index 2282202..12d755e 100644
---- a/Zend/zend_smart_string.h
-+++ b/Zend/zend_smart_string.h
-@@ -136,6 +136,10 @@ static zend_always_inline void smart_string_setl(smart_string *dest, char *src,
- dest->c = src;
- }
-
-+static zend_always_inline void smart_string_reset(smart_string *str) {
-+ str->len = 0;
-+}
-+
- #endif
-
- /*
-diff --git a/configure.ac b/configure.ac
-index cb95d86..a63354f 100644
---- a/configure.ac
-+++ b/configure.ac
-@@ -1478,7 +1478,7 @@ PHP_ADD_SOURCES(main, main.c snprintf.c spprintf.c php_sprintf.c \
- php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
- strlcat.c explicit_bzero.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
- network.c php_open_temporary_file.c \
-- output.c getopt.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
-+ output.c getopt.c php_syslog.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
-
- PHP_ADD_SOURCES_X(main, fastcgi.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, PHP_FASTCGI_OBJS, no)
-
-diff --git a/main/php_syslog.c b/main/php_syslog.c
-new file mode 100644
-index 0000000..c351951
---- /dev/null
-+++ b/main/php_syslog.c
-@@ -0,0 +1,81 @@
-+/*
-+ +----------------------------------------------------------------------+
-+ | PHP Version 7 |
-+ +----------------------------------------------------------------------+
-+ | Copyright (c) 2017 The PHP Group |
-+ +----------------------------------------------------------------------+
-+ | This source file is subject to version 3.01 of the PHP license, |
-+ | that is bundled with this package in the file LICENSE, and is |
-+ | available through the world-wide-web at the following url: |
-+ | http://www.php.net/license/3_01.txt |
-+ | If you did not receive a copy of the PHP license and are unable to |
-+ | obtain it through the world-wide-web, please send a note to |
-+ | license@php.net so we can mail you a copy immediately. |
-+ +----------------------------------------------------------------------+
-+ | Author: Philip Prindeville <philipp@redfish-solutions.com> |
-+ +----------------------------------------------------------------------+
-+*/
-+
-+/* $Id$ */
-+
-+#include <stdio.h>
-+#include <string.h>
-+#include <assert.h>
-+#include <stdlib.h>
-+#include "php.h"
-+#include "php_syslog.h"
-+
-+#include "zend.h"
-+#include "zend_smart_string.h"
-+
-+/*
-+ * The SCO OpenServer 5 Development System (not the UDK)
-+ * defines syslog to std_syslog.
-+ */
-+
-+#ifdef HAVE_STD_SYSLOG
-+#define syslog std_syslog
-+#endif
-+
-+PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */
-+{
-+ const char *ptr;
-+ unsigned char c;
-+ smart_string fbuf = {0};
-+ smart_string sbuf = {0};
-+ va_list args;
-+
-+ va_start(args, format);
-+ zend_printf_to_smart_string(&fbuf, format, args);
-+ smart_string_0(&fbuf);
-+ va_end(args);
-+
-+ for (ptr = fbuf.c; ; ++ptr) {
-+ c = *ptr;
-+ if (c == '\0') {
-+ syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
-+ break;
-+ }
-+
-+ if (c != '\n')
-+ smart_string_appendc(&sbuf, c);
-+ else {
-+ syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
-+ smart_string_reset(&sbuf);
-+ }
-+ }
-+
-+ smart_string_free(&fbuf);
-+ smart_string_free(&sbuf);
-+}
-+
-+/* }}} */
-+
-+/*
-+ * Local variables:
-+ * tab-width: 4
-+ * c-basic-offset: 4
-+ * End:
-+ * vim600: sw=4 ts=4 fdm=marker
-+ * vim<600: sw=4 ts=4
-+ */
-diff --git a/main/php_syslog.h b/main/php_syslog.h
-index be68cc4..4c4ca4e 100644
---- a/main/php_syslog.h
-+++ b/main/php_syslog.h
-@@ -21,6 +21,8 @@
- #ifndef PHP_SYSLOG_H
- #define PHP_SYSLOG_H
-
-+#include "php.h"
-+
- #ifdef PHP_WIN32
- #include "win32/syslog.h"
- #else
-@@ -30,26 +32,12 @@
- #endif
- #endif
-
--/*
-- * The SCO OpenServer 5 Development System (not the UDK)
-- * defines syslog to std_syslog.
-- */
--
--#ifdef syslog
--
--#ifdef HAVE_STD_SYSLOG
--#define php_syslog std_syslog
--#endif
--
--#undef syslog
-+BEGIN_EXTERN_C()
-+PHPAPI void php_syslog(int, const char *format, ...);
-+END_EXTERN_C()
-
- #endif
-
--#ifndef php_syslog
--#define php_syslog syslog
--#endif
--
--#endif
- /*
- * Local variables:
- * tab-width: 4
-diff --git a/win32/build/config.w32 b/win32/build/config.w32
-index 6cbb18b..71cf491 100644
---- a/win32/build/config.w32
-+++ b/win32/build/config.w32
-@@ -241,7 +241,8 @@ ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
- ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
- php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
- strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
-- php_open_temporary_file.c output.c internal_functions.c php_sprintf.c");
-+ php_open_temporary_file.c output.c internal_functions.c php_sprintf.c \
-+ php_syslog.c");
- ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
-
- AC_DEFINE('HAVE_STRNLEN', 1);
+++ /dev/null
---- a/ext/pcre/pcrelib/sljit/sljitNativeMIPS_common.c 2017-11-28 02:22:57.000000000 -0700
-+++ b/ext/pcre/pcrelib/sljit/sljitNativeMIPS_common.c 2017-12-29 17:35:44.231934114 -0700
-@@ -498,12 +498,13 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_gen
-
- SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
- {
-+ sljit_sw fir = 0;
-+
- switch (feature_type) {
- case SLJIT_HAS_FPU:
- #ifdef SLJIT_IS_FPU_AVAILABLE
- return SLJIT_IS_FPU_AVAILABLE;
- #elif defined(__GNUC__)
-- sljit_sw fir;
- asm ("cfc1 %0, $0" : "=r"(fir));
- return (fir >> 22) & 0x1;
- #else
--- /dev/null
+--- a/Zend/zend_alloc.h
++++ b/Zend/zend_alloc.h
+@@ -27,12 +27,12 @@
+ #include "zend.h"
+
+ #ifndef ZEND_MM_ALIGNMENT
+-# define ZEND_MM_ALIGNMENT ((size_t) 8)
++# define ZEND_MM_ALIGNMENT (8)
+ # define ZEND_MM_ALIGNMENT_LOG2 Z_L(3)
+ #elif ZEND_MM_ALIGNMENT < 4
+ # undef ZEND_MM_ALIGNMENT
+ # undef ZEND_MM_ALIGNMENT_LOG2
+-# define ZEND_MM_ALIGNMENT ((size_t) 4)
++# define ZEND_MM_ALIGNMENT (4)
+ # define ZEND_MM_ALIGNMENT_LOG2 Z_L(2)
+ #endif
+
+++ /dev/null
-commit 3763c8f1645983b5abc37c60597e1ecc1bf89019
-Author: Philip Prindeville <philipp@redfish-solutions.com>
-Date: Thu Jan 25 14:18:00 2018 -0700
-
- Always free out_buf in php_iconv_string()
-
-diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
-index 4289242..807bb14 100644
---- a/ext/iconv/iconv.c
-+++ b/ext/iconv/iconv.c
-@@ -699,6 +699,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
- iconv_close(cd);
-
- if (result == (size_t)(-1)) {
-+ zend_string_free(out_buf);
- switch (errno) {
- case EINVAL:
- retval = PHP_ICONV_ERR_ILLEGAL_CHAR;
-@@ -715,7 +716,6 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
-
- default:
- /* other error */
-- zend_string_free(out_buf);
- return PHP_ICONV_ERR_UNKNOWN;
- }
- }
-@@ -988,9 +988,6 @@ static php_iconv_err_t _php_iconv_strpos(size_t *pretval,
- err = php_iconv_string(ndl, ndl_nbytes, &ndl_buf, GENERIC_SUPERSET_NAME, enc);
-
- if (err != PHP_ICONV_ERR_SUCCESS) {
-- if (ndl_buf != NULL) {
-- zend_string_free(ndl_buf);
-- }
- return err;
- }
-
-@@ -2494,9 +2491,6 @@ PHP_NAMED_FUNCTION(php_if_iconv)
- if (err == PHP_ICONV_ERR_SUCCESS && out_buffer != NULL) {
- RETVAL_STR(out_buffer);
- } else {
-- if (out_buffer != NULL) {
-- zend_string_free(out_buffer);
-- }
- RETURN_FALSE;
- }
- }
+++ /dev/null
---- a/ext/ftp/php_ftp.c
-+++ b/ext/ftp/php_ftp.c
-@@ -320,12 +320,14 @@ static void ftp_destructor_ftpbuf(zend_resource *rsrc)
- PHP_MINIT_FUNCTION(ftp)
- {
- #ifdef HAVE_FTP_SSL
-+#if OPENSSL_VERSION_NUMBER < 0x10100000L
- SSL_library_init();
- OpenSSL_add_all_ciphers();
- OpenSSL_add_all_digests();
- OpenSSL_add_all_algorithms();
-
- SSL_load_error_strings();
-+#endif
- #endif
-
- le_ftpbuf = zend_register_list_destructors_ex(ftp_destructor_ftpbuf, NULL, le_ftpbuf_name, module_number);
---- a/ext/openssl/openssl.c
-+++ b/ext/openssl/openssl.c
-@@ -683,6 +683,12 @@ static const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *asn1)
- return M_ASN1_STRING_data(asn1);
- }
-
-+#define OpenSSL_version OpenSSL_version
-+#define OPENSSL_VERSION OPENSSL_VERSION
-+#define X509_getm_notBefore X509_get_notBefore
-+#define X509_getm_notAfter X509_get_notAfter
-+#define EVP_CIPHER_CTX_reset EVP_CIPHER_CTX_cleanup
-+
- #if PHP_OPENSSL_API_VERSION < 0x10002
-
- static int X509_get_signature_nid(const X509 *x)
-@@ -1587,7 +1593,7 @@ PHP_MINFO_FUNCTION(openssl)
- {
- php_info_print_table_start();
- php_info_print_table_row(2, "OpenSSL support", "enabled");
-- php_info_print_table_row(2, "OpenSSL Library Version", SSLeay_version(SSLEAY_VERSION));
-+ php_info_print_table_row(2, "OpenSSL Library Version", OpenSSL_version(OPENSSL_VERSION));
- php_info_print_table_row(2, "OpenSSL Header Version", OPENSSL_VERSION_TEXT);
- php_info_print_table_row(2, "Openssl default config", default_ssl_conf_filename);
- php_info_print_table_end();
-@@ -2361,11 +2367,11 @@ PHP_FUNCTION(openssl_x509_parse)
- add_assoc_string(return_value, "serialNumberHex", hex_serial);
- OPENSSL_free(hex_serial);
-
-- php_openssl_add_assoc_asn1_string(return_value, "validFrom", X509_get_notBefore(cert));
-- php_openssl_add_assoc_asn1_string(return_value, "validTo", X509_get_notAfter(cert));
-+ php_openssl_add_assoc_asn1_string(return_value, "validFrom", X509_getm_notBefore(cert));
-+ php_openssl_add_assoc_asn1_string(return_value, "validTo", X509_getm_notAfter(cert));
-
-- add_assoc_long(return_value, "validFrom_time_t", php_openssl_asn1_time_to_time_t(X509_get_notBefore(cert)));
-- add_assoc_long(return_value, "validTo_time_t", php_openssl_asn1_time_to_time_t(X509_get_notAfter(cert)));
-+ add_assoc_long(return_value, "validFrom_time_t", php_openssl_asn1_time_to_time_t(X509_getm_notBefore(cert)));
-+ add_assoc_long(return_value, "validTo_time_t", php_openssl_asn1_time_to_time_t(X509_getm_notAfter(cert)));
-
- tmpstr = (char *)X509_alias_get0(cert, NULL);
- if (tmpstr) {
-@@ -3455,8 +3461,8 @@ PHP_FUNCTION(openssl_csr_sign)
- php_openssl_store_errors();
- goto cleanup;
- }
-- X509_gmtime_adj(X509_get_notBefore(new_cert), 0);
-- X509_gmtime_adj(X509_get_notAfter(new_cert), 60*60*24*(long)num_days);
-+ X509_gmtime_adj(X509_getm_notBefore(new_cert), 0);
-+ X509_gmtime_adj(X509_getm_notAfter(new_cert), 60*60*24*(long)num_days);
- i = X509_set_pubkey(new_cert, key);
- if (!i) {
- php_openssl_store_errors();
-@@ -6072,7 +6078,7 @@ PHP_FUNCTION(openssl_seal)
-
- /* allocate one byte extra to make room for \0 */
- buf = emalloc(data_len + EVP_CIPHER_CTX_block_size(ctx));
-- EVP_CIPHER_CTX_cleanup(ctx);
-+ EVP_CIPHER_CTX_reset(ctx);
-
- if (EVP_SealInit(ctx, cipher, eks, eksl, &iv_buf[0], pkeys, nkeys) <= 0 ||
- !EVP_SealUpdate(ctx, buf, &len1, (unsigned char *)data, (int)data_len) ||
-@@ -6622,7 +6628,7 @@ PHP_FUNCTION(openssl_encrypt)
- if (free_iv) {
- efree(iv);
- }
-- EVP_CIPHER_CTX_cleanup(cipher_ctx);
-+ EVP_CIPHER_CTX_reset(cipher_ctx);
- EVP_CIPHER_CTX_free(cipher_ctx);
- }
- /* }}} */
-@@ -6709,7 +6715,7 @@ PHP_FUNCTION(openssl_decrypt)
- if (base64_str) {
- zend_string_release(base64_str);
- }
-- EVP_CIPHER_CTX_cleanup(cipher_ctx);
-+ EVP_CIPHER_CTX_reset(cipher_ctx);
- EVP_CIPHER_CTX_free(cipher_ctx);
- }
- /* }}} */
---- a/ext/openssl/xp_ssl.c
-+++ b/ext/openssl/xp_ssl.c
-@@ -56,8 +56,21 @@
- #define HAVE_SSL3 1
- #endif
-
-+#if PHP_OPENSSL_API_VERSION >= 0x10100
-+#define HAVE_TLS 1
-+#endif
-+
-+#ifndef OPENSSL_NO_TLS1_METHOD
-+#define HAVE_TLS1 1
-+#endif
-+
-+#ifndef OPENSSL_NO_TLS1_1_METHOD
- #define HAVE_TLS11 1
-+#endif
-+
-+#ifndef OPENSSL_NO_TLS1_2_METHOD
- #define HAVE_TLS12 1
-+#endif
-
- #ifndef OPENSSL_NO_ECDH
- #define HAVE_ECDH 1
-@@ -78,9 +91,10 @@
- #define STREAM_CRYPTO_IS_CLIENT (1<<0)
- #define STREAM_CRYPTO_METHOD_SSLv2 (1<<1)
- #define STREAM_CRYPTO_METHOD_SSLv3 (1<<2)
--#define STREAM_CRYPTO_METHOD_TLSv1_0 (1<<3)
--#define STREAM_CRYPTO_METHOD_TLSv1_1 (1<<4)
--#define STREAM_CRYPTO_METHOD_TLSv1_2 (1<<5)
-+#define STREAM_CRYPTO_METHOD_TLS (1<<3)
-+#define STREAM_CRYPTO_METHOD_TLSv1_0 (1<<4)
-+#define STREAM_CRYPTO_METHOD_TLSv1_1 (1<<5)
-+#define STREAM_CRYPTO_METHOD_TLSv1_2 (1<<6)
-
- /* Simplify ssl context option retrieval */
- #define GET_VER_OPT(name) \
-@@ -960,9 +974,23 @@ static const SSL_METHOD *php_openssl_select_crypto_method(zend_long method_value
- php_error_docref(NULL, E_WARNING,
- "SSLv3 unavailable in the OpenSSL library against which PHP is linked");
- return NULL;
-+#endif
-+ } else if (method_value == STREAM_CRYPTO_METHOD_TLS) {
-+#ifdef HAVE_TLS
-+ return is_client ? TLS_client_method() : TLS_server_method();
-+#else
-+ php_error_docref(NULL, E_WARNING,
-+ "TLS unavailable in the OpenSSL library against which PHP is linked");
-+ return NULL;
- #endif
- } else if (method_value == STREAM_CRYPTO_METHOD_TLSv1_0) {
-+#ifdef HAVE_TLS1
- return is_client ? TLSv1_client_method() : TLSv1_server_method();
-+#else
-+ php_error_docref(NULL, E_WARNING,
-+ "TLSv1 unavailable in the OpenSSL library against which PHP is linked");
-+ return NULL;
-+#endif
- } else if (method_value == STREAM_CRYPTO_METHOD_TLSv1_1) {
- #ifdef HAVE_TLS11
- return is_client ? TLSv1_1_client_method() : TLSv1_1_server_method();
-@@ -1014,9 +1042,11 @@ static int php_openssl_get_crypto_method_ctx_flags(int method_flags) /* {{{ */
- ssl_ctx_options |= SSL_OP_NO_SSLv3;
- }
- #endif
-+#ifdef HAVE_TLS1
- if (!(method_flags & STREAM_CRYPTO_METHOD_TLSv1_0)) {
- ssl_ctx_options |= SSL_OP_NO_TLSv1;
- }
-+#endif
- #ifdef HAVE_TLS11
- if (!(method_flags & STREAM_CRYPTO_METHOD_TLSv1_1)) {
- ssl_ctx_options |= SSL_OP_NO_TLSv1_1;
include $(TOPDIR)/rules.mk
PKG_NAME:=python-lxml
-PKG_VERSION:=4.4.1
+PKG_VERSION:=4.4.2
PKG_RELEASE:=1
PYPI_NAME:=lxml
-PKG_HASH:=c81cb40bff373ab7a7446d6bbca0190bccc5be3448b47b51d729e37799bb5692
+PKG_HASH:=eff69ddbf3ad86375c344339371168640951c302450c5d3e9936e98d6459db06
PKG_LICENSE:=BSD
PKG_LICENSE_FILES:=LICENSES.txt
include $(TOPDIR)/rules.mk
PKG_NAME:=python-mysqlclient
-PKG_VERSION:=1.4.5
+PKG_VERSION:=1.4.6
PKG_RELEASE:=1
PKG_LICENSE:=GPL-2.0
PYPI_NAME:=mysqlclient
-PKG_HASH:=e80109b0ae8d952b900b31b623181532e5e89376d707dcbeb63f99e69cefe559
+PKG_HASH:=f3fdaa9a38752a3b214a6fe79d7cae3653731a53e577821f9187e67cbecb2e16
PKG_MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>
include ../pypi.mk
include $(TOPDIR)/rules.mk
PKG_NAME:=python-sentry-sdk
-PKG_VERSION:=0.13.2
+PKG_VERSION:=0.13.5
PKG_RELEASE:=1
PYPI_NAME:=sentry-sdk
-PKG_HASH:=ff1fa7fb85703ae9414c8b427ee73f8363232767c9cd19158f08f6e4f0b58fc7
+PKG_HASH:=c6b919623e488134a728f16326c6f0bcdab7e3f59e7f4c472a90eea4d6d8fe82
PKG_MAINTAINER:=Josef Schlehofer <josef.schlehofer@nic.cz>
PKG_LICENSE:=BSD-2-Clause
include $(TOPDIR)/rules.mk
PKG_NAME:=python-simplejson
-PKG_VERSION:=3.16.0
-PKG_RELEASE:=3
+PKG_VERSION:=3.17.0
+PKG_RELEASE:=1
PKG_LICENSE:=MIT
PKG_CPE_ID:=cpe:/a:simplejson_project:simplejson
PYPI_NAME:=simplejson
-PKG_HASH:=b1f329139ba647a9548aa05fb95d046b4a677643070dc2afc05fa2e975d09ca5
+PKG_HASH:=2b4b2b738b3b99819a17feaf118265d0753d5536049ea570b3c43b51c4701e81
include ../pypi.mk
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/rules.mk
PKG_NAME:=python-urllib3
-PKG_VERSION:=1.25.6
+PKG_VERSION:=1.25.7
PKG_RELEASE:=1
PKG_MAINTAINER:=Josef Schlehofer <pepe.schlehofer@gmail.com>
PKG_CPE_ID:=cpe:/a:urllib3_project:urllib3
PYPI_NAME:=urllib3
-PKG_HASH:=9a107b99a5393caf59c7aa3c1249c16e6879447533d0887f4336dde834c7be86
+PKG_HASH:=f3c5fd51747d450d4dcf6f923c81f78f811aab8205fda64b0aba34a4e48b0745
include ../pypi.mk
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/rules.mk
PKG_NAME:=python3-pyroute2
-PKG_VERSION:=0.5.6
+PKG_VERSION:=0.5.7
PKG_RELEASE:=1
PYPI_NAME:=pyroute2
-PKG_HASH:=deae0e6191a04c3ee213c6fae6ed779602ef5da5ca5e2fa533f27bc04326bfbe
+PKG_HASH:=963fce07da2841456d39e3b932b071f6de28d23dadfae014022d67a752916f98
PKG_MAINTAINER:=Martin Matějek <martin.matejek@nic.cz>
PKG_LICENSE:=GPL-2.0-or-later Apache-2.0
# Note: keep in sync with setuptools & pip
PYTHON3_VERSION_MAJOR:=3
PYTHON3_VERSION_MINOR:=8
-PYTHON3_VERSION_MICRO:=0
+PYTHON3_VERSION_MICRO:=1
PYTHON3_VERSION:=$(PYTHON3_VERSION_MAJOR).$(PYTHON3_VERSION_MINOR)
PYTHON_VERSION_MICRO:=$(PYTHON3_VERSION_MICRO)
PKG_NAME:=python3
-PKG_RELEASE:=3
+PKG_RELEASE:=1
PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
-PKG_HASH:=b356244e13fb5491da890b35b13b2118c3122977c2cd825e3eb6e7d462030d84
+PKG_HASH:=75894117f6db7051c1b34f37410168844bbb357c139a8a10a352e9bf8be594e8
PKG_MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>, Jeffery To <jeffery.to@gmail.com>
PKG_LICENSE:=Python/2.0
+++ /dev/null
---- a/Modules/_hashopenssl.c
-+++ b/Modules/_hashopenssl.c
-@@ -42,7 +42,7 @@
- #define PY_OPENSSL_HAS_SHAKE 1
- #endif
-
--#ifdef NID_blake2b512
-+#if defined(NID_blake2b512) && !defined(OPENSSL_NO_BLAKE2)
- #define PY_OPENSSL_HAS_BLAKE2 1
- #endif
-
PKG_NAME:=ruby
PKG_VERSION:=2.6.5
-PKG_RELEASE:=1
+PKG_RELEASE:=3
# First two numbes
PKG_ABI_VERSION:=$(subst $(space),.,$(wordlist 1, 2, $(subst .,$(space),$(PKG_VERSION))))
--disable-install-rdoc \
--disable-install-capi \
--without-gmp \
- --with-out-ext=-test-/array/resize,-test-/bignum,-test-/bug-3571,-test-/bug-5832,-test-/bug_reporter,-test-/class,-test-/debug,-test-/dln/empty,-test-/exception,-test-/fatal,-test-/file,-test-/float,-test-/funcall,-test-/gvl/call_without_gvl,-test-/hash,-test-/integer,-test-/iseq_load,-test-/iter,-test-/load/dot.dot,-test-/marshal/compat,-test-/marshal/internal_ivar,-test-/marshal/usr,-test-/memory_status,-test-/method,-test-/notimplement,-test-/num2int,-test-/path_to_class,-test-/popen_deadlock,-test-/postponed_job,-test-/printf,-test-/proc,-test-/rational,-test-/recursion,-test-/st/foreach,-test-/st/numhash,-test-/st/update,-test-/string,-test-/struct,-test-/symbol,-test-/time,-test-/tracepoint,-test-/typeddata,-test-/vm,-test-/wait_for_single_fd,-test-/win32/console,-test-/win32/dln,-test-/win32/fd_setsize,bigdecimal,cgi/escape,continuation,coverage,dbm,etc,fcntl,fiber,fiddle,gdbm,io/console,io/nonblock,io/wait,json,json/generator,json/parser,mathn/complex,mathn/rational,nkf,objspace,openssl,pathname,pty,racc/cparse,rbconfig/sizeof,readline,ripper,rubyvm,sdbm,socket,syslog,win32,win32ole,win32/resolv,zlib
+ --with-out-ext=-test-/array/resize,-test-/bignum,-test-/bug-3571,-test-/bug-5832,-test-/bug_reporter,-test-/class,-test-/debug,-test-/dln/empty,-test-/exception,-test-/fatal,-test-/file,-test-/float,-test-/funcall,-test-/gvl/call_without_gvl,-test-/hash,-test-/integer,-test-/iseq_load,-test-/iter,-test-/load/dot.dot,-test-/marshal/compat,-test-/marshal/internal_ivar,-test-/marshal/usr,-test-/memory_status,-test-/method,-test-/notimplement,-test-/num2int,-test-/path_to_class,-test-/popen_deadlock,-test-/postponed_job,-test-/printf,-test-/proc,-test-/rational,-test-/recursion,-test-/st/foreach,-test-/st/numhash,-test-/st/update,-test-/string,-test-/struct,-test-/symbol,-test-/time,-test-/tracepoint,-test-/typeddata,-test-/vm,-test-/wait_for_single_fd,-test-/win32/console,-test-/win32/dln,-test-/win32/fd_setsize,bigdecimal,cgi/escape,continuation,coverage,dbm,etc,fcntl,fiber,fiddle,gdbm,io/console,json,json/generator,json/parser,mathn/complex,mathn/rational,nkf,objspace,pty,racc/cparse,rbconfig/sizeof,readline,rubyvm,sdbm,syslog,win32,win32ole,win32/resolv
# Does not compile with this. Workaround is --without-gmp
# https://bugs.ruby-lang.org/issues/11940
$(eval $(call RubyBuildPackage,csv,CSV Reading and Writing,+ruby-date +ruby-forwardable +ruby-misc +ruby-stringio +ruby-strscan))
$(eval $(call RubyBuildPackage,date,Comparable module for handling dates,))
$(eval $(call RubyBuildPackage,dbm,Wrapper for the UNIX-style Database Manager Library,+libdb47))
-$(eval $(call RubyBuildPackage,debuglib,debug library,+ruby-misc +ruby-prettyprint +ruby-tracer))
+$(eval $(call RubyBuildPackage,debuglib,debug library,+ruby-filelib +ruby-prettyprint +ruby-tracer))
$(eval $(call RubyBuildPackage,did-you-mean,did you mean? experience,+ruby-misc))
$(eval $(call RubyBuildPackage,digest,Digest Library,+RUBY_DIGEST_USE_OPENSSL:libopenssl))
$(eval $(call RubyBuildPackage,drb,distributed object system,+ruby-filelib +ruby-ipaddr +ruby-patterns))
$(eval $(call RubyBuildPackage,net,Network Protocols Library,+ruby-time +ruby-digest +ruby-filelib +ruby-socket +ruby-stringio +ruby-strscan +ruby-uri))
$(eval $(call RubyBuildPackage,net-telnet,telnet client,+ruby-net))
$(eval $(call RubyBuildPackage,nkf,Network Kanji Filter,+ruby-enc))
-$(eval $(call RubyBuildPackage,openssl,SSL TLS and general purpose cryptography,+ruby-enc +ruby-ipaddr +ruby-stringio +libopenssl))
+$(eval $(call RubyBuildPackage,openssl,SSL TLS and general purpose cryptography,+ruby-digest +ruby-enc +ruby-ipaddr +ruby-stringio +libopenssl))
$(eval $(call RubyBuildPackage,ostruct,build custom data structures,))
$(eval $(call RubyBuildPackage,optparse,command-line option analysis,+ruby-misc +ruby-time))
$(eval $(call RubyBuildPackage,patterns,design patterns implementation,))
end
exit(1) if failed
-# Add deps from .so
+# From ruby source: grep -E 'rb_require' -R . | grep -E '\.c:.*rb_require.*'
+# Add dependencies of ruby files from ruby lib.so
package_files.each do |(pkg,files)| files.each do |file|
case file
- when /\/nkf\.so$/
- files_requires[file]= files_requires[file] + ["enc/encdb"]
+ when /\/nkf\.so$/ ; files_requires[file]=files_requires[file] + ["enc/encdb"]
+ when /\/objspace\.so$/; files_requires[file]=files_requires[file] + ["tempfile"] # dump_output from ext/objspace/objspace_dump.c
+ when /\/openssl\.so$/; files_requires[file]=files_requires[file] + ["digest"] # Init_ossl_digest from ext/openssl/ossl_digest.c
end
end; end
PKG_NAME:=tcl
TCL_MAJOR_VERSION:=8.6
PKG_VERSION:=${TCL_MAJOR_VERSION}.9
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)$(PKG_VERSION)-src.tar.gz
PKG_SOURCE_URL:=@SF/$(PKG_NAME)
$(INSTALL_DIR) $(1)/usr/lib/pkgconfig
$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/tcl.pc \
$(1)/usr/lib/pkgconfig
+ $(SED) 's,/usr/include,$$$${prefix}/include,g' $(1)/usr/lib/pkgconfig/tcl.pc
+ $(SED) 's,/usr/lib,$$$${prefix}/lib,g' $(1)/usr/lib/pkgconfig/tcl.pc
endef
define Package/tcl/install
include $(TOPDIR)/rules.mk
PKG_NAME:=boost
-PKG_VERSION:=1.71.0
-PKG_SOURCE_VERSION:=1_71_0
-PKG_RELEASE:=5
+PKG_VERSION:=1.72.0
+PKG_SOURCE_VERSION:=1_72_0
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)_$(PKG_SOURCE_VERSION).tar.bz2
PKG_SOURCE_URL:=@SF/$(PKG_NAME)/$(PKG_NAME)/$(PKG_VERSION) https://dl.bintray.com/boostorg/release/$(PKG_VERSION)/source/
-PKG_HASH:=d73a8da01e8bf8c7eda40b4c84915071a8c8a0df4a6734537ddde4a8580524ee
+PKG_HASH:=59c9b274bc451cf91a9ba1dd2c7fdcaf5d60b1b3aa83f2c9fa143417cc660722
PKG_MAINTAINER:=Carlos M. Ferreira <carlosmf.pt@gmail.com>
PKG_LICENSE:=BSL-1.0
endef
define Package/boost/description
-This package provides the Boost v1.71.0 libraries.
+This package provides the Boost v1.72.0 libraries.
Boost is a set of free, peer-reviewed, portable C++ source libraries.
This package provides the following run-time libraries:
- wave
There are many more header-only libraries supported by Boost.
-See more at http://www.boost.org/doc/libs/1_71_0/
+See more at http://www.boost.org/doc/libs/1_72_0/
endef
PKG_BUILD_DEPENDS:=boost/host PACKAGE_python:python PACKAGE_python3:python3
# Invisible config dependency
config boost-context-exclude
bool
- default y if (TARGET_arc700 || TARGET_archs38 || TARGET_octeon || TARGET_octeontx)
+ default y if (TARGET_arc770 || TARGET_archs38 || TARGET_octeon || TARGET_octeontx)
default n
config boost-coroutine-exclude
--- /dev/null
+From 5f7cda29add367c5381775a314ec9f90e311457a Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Fri, 15 Nov 2019 12:43:50 -0800
+Subject: [PATCH] cpu_relax: Fix MIPS check
+
+BOOST_ARCH_MIPS as a macro is totally broken. It always gets defined to either 32
+or 64 with a bunch of zeroes depending on the architecture.
+
+Use GCC's internal define to check the architecture properly.
+
+Signed-off-by: Rosen Penev <rosenp@gmail.com>
+---
+ boost/fiber/detail/cpu_relax.hpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/boost/fiber/detail/cpu_relax.hpp b/boost/fiber/detail/cpu_relax.hpp
+index 72564394..f40545c2 100644
+--- a/boost/fiber/detail/cpu_relax.hpp
++++ b/boost/fiber/detail/cpu_relax.hpp
+@@ -47,7 +47,7 @@ namespace detail {
+ # else
+ # define cpu_relax() asm volatile ("nop" ::: "memory");
+ # endif
+-#elif BOOST_ARCH_MIPS
++#elif BOOST_ARCH_MIPS && (__mips_isa_rev > 1)
+ # define cpu_relax() asm volatile ("pause" ::: "memory");
+ #elif BOOST_ARCH_PPC
+ // http://code.metager.de/source/xref/gnu/glibc/sysdeps/powerpc/sys/platform/ppc.h
+++ /dev/null
-From 83b989ecee478be083db8dc0cc7a5387615bd3cb Mon Sep 17 00:00:00 2001
-From: Andrey Semashev <andrey.semashev@gmail.com>
-Date: Wed, 31 Jul 2019 16:28:05 +0300
-Subject: [PATCH] Added support for utimensat for better POSIX.1-2008
- compliance.
-
-POSIX.1-2008 marks utime as obsolete and replaces it with utimensat.
-uClibc-ng has an option for removing utime, including the corresponding
-header.
-
-Closes https://github.com/boostorg/filesystem/pull/115.
----
- libs/filesystem/src/operations.cpp | 24 ++++++++++++++++++++++--
- 1 file changed, 22 insertions(+), 2 deletions(-)
-
-diff --git a/src/operations.cpp b/src/operations.cpp
-index 9bba1cf7a..038109d35 100644
---- a/libs/filesystem/src/operations.cpp
-+++ b/libs/filesystem/src/operations.cpp
-@@ -62,7 +62,7 @@
- #endif
-
- #ifndef _POSIX_PTHREAD_SEMANTICS
--# define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r()needs this
-+# define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this
- #endif
-
- #include <boost/filesystem/operations.hpp>
-@@ -119,7 +119,9 @@ using std::wstring;
- # include <dirent.h>
- # include <unistd.h>
- # include <fcntl.h>
--# include <utime.h>
-+# if _POSIX_C_SOURCE < 200809L
-+# include <utime.h>
-+# endif
- # include "limits.h"
-
- # else // BOOST_WINDOW_API
-@@ -1459,6 +1461,22 @@ namespace detail
- system::error_code* ec)
- {
- # ifdef BOOST_POSIX_API
-+# if _POSIX_C_SOURCE >= 200809L
-+
-+ struct timespec times[2] = {};
-+
-+ // Keep the last access time unchanged
-+ times[0].tv_nsec = UTIME_OMIT;
-+
-+ times[1].tv_sec = new_time;
-+
-+ if (BOOST_UNLIKELY(::utimensat(AT_FDCWD, p.c_str(), times, 0) != 0))
-+ {
-+ error(BOOST_ERRNO, p, ec, "boost::filesystem::last_write_time");
-+ return;
-+ }
-+
-+# else // _POSIX_C_SOURCE >= 200809L
-
- struct stat path_stat;
- if (error(::stat(p.c_str(), &path_stat)!= 0,
-@@ -1470,6 +1488,8 @@ namespace detail
- error(::utime(p.c_str(), &buf)!= 0 ? BOOST_ERRNO : 0,
- p, ec, "boost::filesystem::last_write_time");
-
-+# endif // _POSIX_C_SOURCE >= 200809L
-+
- # else
-
- handle_wrapper hw(
+++ /dev/null
-From 5f7cda29add367c5381775a314ec9f90e311457a Mon Sep 17 00:00:00 2001
-From: Rosen Penev <rosenp@gmail.com>
-Date: Fri, 15 Nov 2019 12:43:50 -0800
-Subject: [PATCH] cpu_relax: Fix MIPS check
-
-BOOST_ARCH_MIPS as a macro is totally broken. It always gets defined to either 32
-or 64 with a bunch of zeroes depending on the architecture.
-
-Use GCC's internal define to check the architecture properly.
-
-Signed-off-by: Rosen Penev <rosenp@gmail.com>
----
- boost/fiber/detail/cpu_relax.hpp | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/boost/fiber/detail/cpu_relax.hpp b/boost/fiber/detail/cpu_relax.hpp
-index 72564394..f40545c2 100644
---- a/boost/fiber/detail/cpu_relax.hpp
-+++ b/boost/fiber/detail/cpu_relax.hpp
-@@ -47,7 +47,7 @@ namespace detail {
- # else
- # define cpu_relax() asm volatile ("nop" ::: "memory");
- # endif
--#elif BOOST_ARCH_MIPS
-+#elif BOOST_ARCH_MIPS && (__mips_isa_rev > 1)
- # define cpu_relax() asm volatile ("pause" ::: "memory");
- #elif BOOST_ARCH_PPC
- // http://code.metager.de/source/xref/gnu/glibc/sysdeps/powerpc/sys/platform/ppc.h
--- /dev/null
+From 436e1dbe6fcd31523d261d18ad011392f1d6fbbc Mon Sep 17 00:00:00 2001
+From: Oliver Kowalke <oliver.kowalke@gmail.com>
+Date: Sun, 1 Dec 2019 20:40:28 +0100
+Subject: [PATCH] Revert "Cease dependence on Range"
+
+This reverts commit 0c556bb59241e682bbcd3f572815149c5a9b17db.
+
+see #44 (One test fails to compile after boostorg/coroutine submodule updated)
+---
+ boost/coroutine/asymmetric_coroutine.hpp | 12 +++---------
+ 1 file changed, 3 insertions(+), 9 deletions(-)
+
+diff --git a/boost/coroutine/asymmetric_coroutine.hpp b/boost/coroutine/asymmetric_coroutine.hpp
+index ea96981..640896f 100644
+--- a/boost/coroutine/asymmetric_coroutine.hpp
++++ b/boost/coroutine/asymmetric_coroutine.hpp
+@@ -14,6 +14,7 @@
+ #include <boost/assert.hpp>
+ #include <boost/config.hpp>
+ #include <boost/move/move.hpp>
++#include <boost/range.hpp>
+ #include <boost/throw_exception.hpp>
+ #include <boost/utility/explicit_operator_bool.hpp>
+
+@@ -2354,19 +2355,12 @@ end( push_coroutine< R > & c)
+
+ }
+
+-// forward declaration of Boost.Range traits to break dependency on it
+-template<typename C, typename Enabler>
+-struct range_mutable_iterator;
+-
+-template<typename C, typename Enabler>
+-struct range_const_iterator;
+-
+ template< typename Arg >
+-struct range_mutable_iterator< coroutines::push_coroutine< Arg >, void >
++struct range_mutable_iterator< coroutines::push_coroutine< Arg > >
+ { typedef typename coroutines::push_coroutine< Arg >::iterator type; };
+
+ template< typename R >
+-struct range_mutable_iterator< coroutines::pull_coroutine< R >, void >
++struct range_mutable_iterator< coroutines::pull_coroutine< R > >
+ { typedef typename coroutines::pull_coroutine< R >::iterator type; };
+
+ }
+--
+2.24.1
+
--- /dev/null
+From 5f19fd7dc6c4dd37fb0409f08a0b7dbb887dd516 Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Thu, 19 Dec 2019 17:46:46 -0800
+Subject: [PATCH] roots: Fix fma_workaround
+
+fma takes three parameters, not one.
+
+Signed-off-by: Rosen Penev <rosenp@gmail.com>
+---
+ include/boost/math/tools/roots.hpp | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/boost/math/tools/roots.hpp b/boost/math/tools/roots.hpp
+index 8b3ab7eb9..5d7936bb2 100644
+--- a/boost/math/tools/roots.hpp
++++ b/boost/math/tools/roots.hpp
+@@ -861,10 +861,10 @@ Complex complex_newton(F g, Complex guess, int max_iterations = std::numeric_lim
+ namespace detail
+ {
+ #if defined(BOOST_GNU_STDLIB) && !defined(_GLIBCXX_USE_C99_MATH_TR1)
+-float fma_workaround(float f) { return ::fmaf(f); }
+-double fma_workaround(double f) { return ::fma(f); }
++inline float fma_workaround(float x, float y, float z) { return ::fmaf(x, y, z); }
++inline double fma_workaround(double x, double y, double z) { return ::fma(x, y, z); }
+ #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
+-long double fma_workaround(long double f) { return ::fmal(f); }
++inline long double fma_workaround(long double x, long double y, long double z) { return ::fmal(x, y, z); }
+ #endif
+ #endif
+ template<class T>
--- /dev/null
+Index: boost_1_72_0/boost/math/tools/roots.hpp
+===================================================================
+--- boost_1_72_0.orig/boost/math/tools/roots.hpp
++++ boost_1_72_0/boost/math/tools/roots.hpp
+@@ -884,7 +884,11 @@ inline T discriminant(T const& a, T cons
+ template<class T>
+ std::pair<T, T> quadratic_roots_imp(T const& a, T const& b, T const& c)
+ {
+- using std::copysign;
++ #if defined(BOOST_GNU_STDLIB) && !defined(_GLIBCXX_USE_C99_MATH_TR1)
++ using boost::math::copysign;
++ #else
++ using std::copysign;
++ #endif
+ using std::sqrt;
+ if constexpr (std::is_floating_point<T>::value)
+ {
PKG_NAME:=cyrus-sasl
PKG_VERSION:=2.1.27
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_MAINTAINER:=W. Michael Petullo <mike@flyn.org>
ln -sf libsasl2.so $(1)/usr/lib/libsasl.so
$(INSTALL_DIR) $(1)/usr/lib/sasl2
$(CP) $(PKG_INSTALL_DIR)/usr/lib/sasl2/lib*.{a,so*} $(1)/usr/lib/sasl2/
+ $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libsasl2.pc $(1)/usr/lib/pkgconfig/
endef
define Package/libsasl2/install
$(INSTALL_DIR) $(1)/usr/lib/
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/libsasl2.so* $(1)/usr/lib/
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libsasl2.so.* $(1)/usr/lib/
$(INSTALL_DIR) $(1)/usr/lib/sasl2
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/sasl2/lib*.so* $(1)/usr/lib/sasl2/
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/sasl2/lib*.so.* $(1)/usr/lib/sasl2/
endef
$(eval $(call BuildPackage,libsasl2))
include $(TOPDIR)/rules.mk
PKG_NAME:=gnutls
-PKG_VERSION:=3.6.9
-PKG_RELEASE:=2
+PKG_VERSION:=3.6.11.1
+PKG_RELEASE:=1
PKG_USE_MIPS16:=0
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6
-PKG_HASH:=4331fca55817ecdd74450b908a6c29b4f05bb24dd13144c6284aa34d872e1fcb
+PKG_HASH:=fbba12f3db9a55dbf027e14111755817ec44b57eabec3e8089aac8ac6f533cf8
#PKG_FIXUP:=autoreconf gettext-version
PKG_MAINTAINER:=Nikos Mavrogiannopoulos <nmav@gnutls.org>
PKG_LICENSE:=LGPL-2.1-or-later
include $(TOPDIR)/rules.mk
PKG_NAME:=google-authenticator-libpam
-PKG_VERSION:=1.06
+PKG_VERSION:=1.07
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/google/google-authenticator-libpam/tar.gz/$(PKG_VERSION)?
-PKG_HASH:=52f03ec746e8deb1af37911697d096f0fa87583491b7cc460cdf09a6ef0d6b06
+PKG_HASH:=104a158e013585e20287f8d33935e93c711b96281e6dda621a5c19575d0b0405
PKG_MAINTAINER:=Lucian Cristian <lucian.cristian@gmail.com>
PKG_LICENSE:=Apache-2.0
--- /dev/null
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=h2o
+PKG_VERSION:=2.2.6
+PKG_RELEASE:=3
+
+PKG_SOURCE_URL:=https://codeload.github.com/h2o/h2o/tar.gz/v${PKG_VERSION}?
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_HASH:=f8cbc1b530d85ff098f6efc2c3fdbc5e29baffb30614caac59d5c710f7bda201
+
+PKG_MAINTAINER:=James Taylor <james@jtaylor.id.au
+PKG_LICENSE:=MIT
+PKG_LICENSE_FILES:=LICENSE
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+PKG_BUILD_DEPENDS:=ruby/host
+PKG_BUILD_PARALLEL:=1
+
+CMAKE_OPTIONS:= \
+ -DBUILD_SHARED_LIBS=ON \
+ -DWITH_MRUBY=OFF
+
+CMAKE_INSTALL:=1
+
+define Package/libh2o-evloop
+ SECTION:=libs
+ CATEGORY:=Libraries
+ TITLE:=H2O Library compiled with its own event loop
+ URL:=https://h2o.examp1e.net/
+ DEPENDS:=+libwslay +libopenssl +zlib +libyaml +ruby
+endef
+
+define Package/libh2o
+ SECTION:=libs
+ CATEGORY:=Libraries
+ TITLE:=H2O Library compiled with libuv
+ URL:=https://h2o.examp1e.net/
+ DEPENDS:=+libuv +libwslay +libopenssl +zlib +libyaml +ruby
+endef
+
+define Package/libh2o-evloop/install
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/libh2o-evloop.so* $(1)/usr/lib/
+endef
+
+define Package/libh2o/install
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/libh2o.so* $(1)/usr/lib/
+endef
+
+$(eval $(call BuildPackage,libh2o-evloop))
+$(eval $(call BuildPackage,libh2o))
--- /dev/null
+--- a/include/h2o/socket.h
++++ b/include/h2o/socket.h
+@@ -29,6 +29,7 @@
+ #include <stdint.h>
+ #include <sys/socket.h>
+ #include <openssl/ssl.h>
++#include <openssl/opensslconf.h>
+ #include "h2o/cache.h"
+ #include "h2o/memory.h"
+ #include "h2o/openssl_backport.h"
+@@ -45,7 +44,11 @@
+
+ #if OPENSSL_VERSION_NUMBER >= 0x10002000L
+ #define H2O_USE_ALPN 1
++#ifndef OPENSSL_NO_NEXTPROTONEG
+ #define H2O_USE_NPN 1
++#else
++#define H2O_USE_NPN 0
++#endif
+ #elif OPENSSL_VERSION_NUMBER >= 0x10001000L
+ #define H2O_USE_ALPN 0
+ #define H2O_USE_NPN 1
--- /dev/null
+From f7d5cb83826c7e2b1a3dc618b434d85df130a4d5 Mon Sep 17 00:00:00 2001
+From: James Taylor <james@jtaylor.id.au>
+Date: Tue, 10 Dec 2019 21:58:45 +1100
+Subject: [PATCH] Explicitly link against WSLAY when available
+
+When other libraries attempt to link against libh2o and libh2o-evloop that was
+compiled with libwslay available, there are errors from missing symbols
+associated with code which makes use of the wslay library. To rectify this,
+explicitly link against libwslay during the build process.
+
+Fixes #2105
+
+Signed-off-by: James Taylor <james@jtaylor.id.au>
+---
+ CMakeLists.txt | 12 ++++++++++--
+ 1 file changed, 10 insertions(+), 2 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index a68613081..13c2f8a9f 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -519,13 +519,21 @@ SET_TARGET_PROPERTIES(libh2o PROPERTIES
+ OUTPUT_NAME h2o
+ VERSION ${LIBRARY_VERSION}
+ SOVERSION ${LIBRARY_SOVERSION})
+-TARGET_LINK_LIBRARIES(libh2o ${LIBUV_LIBRARIES} ${EXTRA_LIBS})
++IF (WSLAY_FOUND)
++ TARGET_LINK_LIBRARIES(libh2o ${WSLAY_LIBRARIES} ${LIBUV_LIBRARIES} ${EXTRA_LIBS})
++ELSE ()
++ TARGET_LINK_LIBRARIES(libh2o ${LIBUV_LIBRARIES} ${EXTRA_LIBS})
++ENDIF (WSLAY_FOUND)
+ SET_TARGET_PROPERTIES(libh2o-evloop PROPERTIES
+ OUTPUT_NAME h2o-evloop
+ COMPILE_FLAGS "-DH2O_USE_LIBUV=0"
+ VERSION ${LIBRARY_VERSION}
+ SOVERSION ${LIBRARY_SOVERSION})
+-TARGET_LINK_LIBRARIES(libh2o-evloop ${EXTRA_LIBS})
++IF (WSLAY_FOUND)
++ TARGET_LINK_LIBRARIES(libh2o-evloop ${WSLAY_LIBRARIES} ${EXTRA_LIBS})
++ELSE ()
++ TARGET_LINK_LIBRARIES(libh2o-evloop ${EXTRA_LIBS})
++ENDIF (WSLAY_FOUND)
+
+ TARGET_INCLUDE_DIRECTORIES(libh2o PUBLIC ${OPENSSL_INCLUDE_DIR})
+ TARGET_INCLUDE_DIRECTORIES(libh2o-evloop PUBLIC ${OPENSSL_INCLUDE_DIR})
--- /dev/null
+--- a/deps/picotls/include/picotls/openssl.h
++++ b/deps/picotls/include/picotls/openssl.h
+@@ -26,11 +26,14 @@
+ #include <openssl/evp.h>
+ #include <openssl/hmac.h>
+ #include <openssl/x509.h>
++#include <openssl/opensslconf.h>
+ #include "../picotls.h"
+
+ #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
++#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
+ #define PTLS_OPENSSL_HAVE_CHACHA20_POLY1305
+ #endif
++#endif
+
+ extern ptls_key_exchange_algorithm_t ptls_openssl_secp256r1;
+ extern ptls_key_exchange_algorithm_t *ptls_openssl_key_exchanges[];
--- /dev/null
+From 03dbd6757d043581b5d250107b6f1cda6ae203a9 Mon Sep 17 00:00:00 2001
+From: Frederik Deweerdt <fdeweerdt@fastly.com>
+Date: Wed, 25 Oct 2017 13:52:28 -0700
+Subject: [PATCH] Autodetect backtrace and backtrace_symbols_fd
+
+---
+ CMakeLists.txt | 13 +++++++++++++
+ src/main.c | 10 ++++++----
+ 2 files changed, 19 insertions(+), 4 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index abfab1f19..2a26fb98a 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -58,6 +58,19 @@ __sync_add_and_fetch(&a, 1);
+ return 0;
+ }" ARCH_SUPPORTS_64BIT_ATOMICS)
+
++CHECK_C_SOURCE_COMPILES("
++#include <execinfo.h>
++int main(void) {
++void *p[10];
++int ret = backtrace(p, 10);
++backtrace_symbols_fd(p, ret, 2);
++return 0;
++}" LIBC_HAS_BACKTRACE)
++
++IF (LIBC_HAS_BACKTRACE)
++ ADD_DEFINITIONS("-DLIBC_HAS_BACKTRACE")
++ENDIF ()
++
+ SET(WITH_BUNDLED_SSL_DEFAULT "ON")
+ IF ((NOT UNIX) OR CYGWIN)
+ SET(WITH_BUNDLED_SSL_DEFAULT "OFF")
+diff --git a/src/main.c b/src/main.c
+index 7c346af18..edc7d5eb3 100644
+--- a/src/main.c
++++ b/src/main.c
+@@ -48,7 +48,7 @@
+ #include <openssl/crypto.h>
+ #include <openssl/err.h>
+ #include <openssl/ssl.h>
+-#ifdef __GLIBC__
++#ifdef LIBC_HAS_BACKTRACE
+ #include <execinfo.h>
+ #endif
+ #if H2O_USE_PICOTLS
+@@ -1435,7 +1435,8 @@ static void on_sigterm(int signo)
+ notify_all_threads();
+ }
+
+-#ifdef __GLIBC__
++#ifdef LIBC_HAS_BACKTRACE
++
+ static int popen_crash_handler(void)
+ {
+ char *cmd_fullpath = h2o_configurator_get_cmd_path(conf.crash_handler), *argv[] = {cmd_fullpath, NULL};
+@@ -1487,13 +1488,14 @@ static void on_sigfatal(int signo)
+
+ raise(signo);
+ }
+-#endif
++
++#endif /* LIBC_HAS_BACKTRACE */
+
+ static void setup_signal_handlers(void)
+ {
+ h2o_set_signal_handler(SIGTERM, on_sigterm);
+ h2o_set_signal_handler(SIGPIPE, SIG_IGN);
+-#ifdef __GLIBC__
++#ifdef LIBC_HAS_BACKTRACE
+ if ((crash_handler_fd = popen_crash_handler()) == -1)
+ crash_handler_fd = 2;
+ h2o_set_signal_handler(SIGABRT, on_sigfatal);
MAJOR_VERSION:=65
MINOR_VERSION:=1
PKG_VERSION:=$(MAJOR_VERSION).$(MINOR_VERSION)
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(MAJOR_VERSION)_$(MINOR_VERSION)-src.tgz
PKG_SOURCE_URL:=https://github.com/unicode-org/icu/releases/download/release-$(MAJOR_VERSION)-$(MINOR_VERSION)
--- /dev/null
+From 8fda72f6d8e442c5382f21cdd884e2c962bb53bd Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Wed, 11 Dec 2019 13:25:32 -0800
+Subject: [PATCH] ICU-20877 i18n: Don't use C++11 math
+
+It's not available with some libc implementations. Specifically,
+BIONIC and uClibc-ng. uprv_ variants are available.
+
+Signed-off-by: Rosen Penev <rosenp@gmail.com>
+---
+ i18n/decimfmt.cpp | 2 +-
+ i18n/number_decimalquantity.cpp | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/i18n/decimfmt.cpp b/i18n/decimfmt.cpp
+index 4015250e273..0cbaca7e099 100644
+--- a/i18n/decimfmt.cpp
++++ b/i18n/decimfmt.cpp
+@@ -1801,7 +1801,7 @@ bool DecimalFormat::fastFormatDouble(double input, UnicodeString& output) const
+ return false;
+ }
+ if (std::isnan(input)
+- || std::trunc(input) != input
++ || uprv_trunc(input) != input
+ || input <= INT32_MIN
+ || input > INT32_MAX) {
+ return false;
+diff --git a/i18n/number_decimalquantity.cpp b/i18n/number_decimalquantity.cpp
+index abbc23de032..778feb141b4 100644
+--- a/i18n/number_decimalquantity.cpp
++++ b/i18n/number_decimalquantity.cpp
+@@ -452,7 +452,7 @@ void DecimalQuantity::_setToDoubleFast(double n) {
+ for (; i <= -22; i += 22) n /= 1e22;
+ n /= DOUBLE_MULTIPLIERS[-i];
+ }
+- auto result = static_cast<int64_t>(std::round(n));
++ auto result = static_cast<int64_t>(uprv_round(n));
+ if (result != 0) {
+ _setToLong(result);
+ scale -= fracLength;
include $(TOPDIR)/rules.mk
PKG_NAME:=keyutils
-PKG_VERSION:=1.6
-PKG_RELEASE:=3
+PKG_VERSION:=1.6.1
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://people.redhat.com/dhowells/keyutils/
-PKG_HASH:=d3aef20cec0005c0fa6b4be40079885567473185b1a57b629b030e67942c7115
+PKG_HASH:=c8b15722ae51d95b9ad76cc6d49a4c2cc19b0c60f72f61fb9bf43eea7cbd64ce
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
include $(TOPDIR)/rules.mk
PKG_NAME:=libfmt
-PKG_VERSION:=6.0.0
+PKG_VERSION:=6.1.2
PKG_RELEASE:=1
PKG_SOURCE_NAME:=fmt
PKG_SOURCE:=$(PKG_SOURCE_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/fmtlib/$(PKG_SOURCE_NAME)/tar.gz/$(PKG_VERSION)?
-PKG_HASH:=f1907a58d5e86e6c382e51441d92ad9e23aea63827ba47fd647eacc0d3a16c78
+PKG_HASH:=1cafc80701b746085dddf41bd9193e6d35089e1c6ec1940e037fcb9c98f62365
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_SOURCE_NAME)-$(PKG_VERSION)
PKG_MAINTAINER:=Othmar Truniger <github@truniger.ch>
include $(TOPDIR)/rules.mk
PKG_NAME:=libfstrm
-PKG_VERSION:=0.5.0
-PKG_RELEASE:=3
+PKG_VERSION:=0.6.0
+PKG_RELEASE:=1
PKG_SOURCE:=fstrm-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://dl.farsightsecurity.com/dist/fstrm/
-PKG_HASH:=10ee7792a86face1d2271dc591652ab8c7af6976883887c69fdb11f10da135fc
+PKG_HASH:=a7049089eb0861ecaa21150a05613caa6dee4e8545b91191eff2269caa923910
PKG_BUILD_DIR:=$(BUILD_DIR)/fstrm-$(PKG_VERSION)
PKG_NAME:=libgd
PKG_VERSION:=2.2.5
-PKG_RELEASE:=4
+PKG_RELEASE:=5
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://github.com/$(PKG_NAME)/$(PKG_NAME)/releases/download/gd-$(PKG_VERSION)/
--- /dev/null
+--- a/config/gdlib.pc.cmake
++++ b/config/gdlib.pc.cmake
+@@ -5,7 +5,7 @@ includedir=${prefix}/@CMAKE_INSTALL_INCL
+
+ Name: gd
+ Description: GD graphics library
+-Version: @GDLIB_VERSION@
++Version: @GD_VERSION@
+ Cflags: -I${includedir}
+ Libs.private: @LIBGD_DEP_LIBS@
+ Libs: -L${libdir} -lgd
include $(TOPDIR)/rules.mk
PKG_NAME:=libical
-PKG_VERSION:=3.0.4
+PKG_VERSION:=3.0.6
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_HASH:=72b216e10233c3f60cb06062facf41f3b0f70615e5a60b47f9853341a0d5d145
+PKG_HASH:=5c8a21c2b732ece4a33e5c862970b4f35a8548bbcda50de5695f6fc211ac4d97
PKG_SOURCE_URL:=https://github.com/libical/libical/releases/download/v$(PKG_VERSION)/
-PKG_LICENSE:=LGPL-2.1 MPL-2.0
-PKG_LICENSE_FILES:=COPYING
PKG_MAINTAINER:=Jose Zapater <jzapater@gmail.com>
+PKG_LICENSE:=LGPL-2.1-or-later MPL-2.0
+PKG_LICENSE_FILES:=COPYING
+
+CMAKE_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk
CMAKE_OPTIONS += -DWITH_CXX_BINDINGS=false -DICAL_BUILD_DOCS=false -DICAL_GLIB=false
-define Build/InstallDev
- $(INSTALL_DIR) $(1)/usr/include/libical
- $(CP) $(PKG_INSTALL_DIR)/usr/include/libical/* $(1)/usr/include/libical/
- $(INSTALL_DIR) $(1)/usr/lib
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/libical{,ss,vcal}.{a,so*} $(1)/usr/lib/
- $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libical.pc $(1)/usr/lib/pkgconfig/
-endef
-
define Package/libical/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libical{,ss,vcal}.so.* $(1)/usr/lib/
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 1cc7180..295bc20 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
-@@ -161,43 +161,43 @@ endif()
+@@ -170,43 +170,43 @@ endif()
# libicu is highly recommended for RSCALE support
# libicu can be found at http://www.icu-project.org
# RSCALE info at http://tools.ietf.org/html/rfc7529
include $(TOPDIR)/rules.mk
PKG_NAME:=libidn2
-PKG_VERSION:=2.0.5
+PKG_VERSION:=2.3.0
PKG_RELEASE:=1
-PKG_LICENSE:=GPL-2.0-or-later LGPL-3.0-or-later
-PKG_LICENSE_FILES:=COPYING COPYINGv2 COPYING.LESSERv3
-PKG_CPE_ID:=cpe:/a:libidn2_project:libidn2
PKG_SOURCE_URL:=@GNU/libidn
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_HASH:=53f69170886f1fa6fa5b332439c7a77a7d22626a82ef17e2c1224858bb4ca2b8
+PKG_HASH:=e1cb1db3d2e249a6a3eb6f0946777c2e892d5c5dc7bd91c74394fc3a01cab8b5
+
+PKG_MAINTAINER:=
+PKG_CPE_ID:=cpe:/a:libidn2_project:libidn2
PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
SUBMENU:=IP Addresses and Names
TITLE:=GNU IDN2 (Internationalized Domain Name) tool
DEPENDS:=+libidn2
+ LICENSE:=GPL-2.0-or-later
+ LICENSE_FILES:=COPYINGv2
endef
define Package/idn2/description
DEPENDS:=+libunistring $(ICONV_DEPENDS) $(INTL_DEPENDS)
TITLE:=International domain name library (IDNA2008, Punycode and TR46)
URL:=https://www.gnu.org/software/libidn/#libidn2
+ LICENSE:=LGPL-3.0-or-later
+ LICENSE_FILES:=COPYING.LESSERv3
endef
define Package/libidn2/description
include $(TOPDIR)/rules.mk
PKG_NAME:=libimobiledevice
-PKG_SOURCE_DATE:=2019-02-16
-PKG_SOURCE_VERSION:=0584aa90c93ff6ce46927b8d67887cb987ab9545
-PKG_RELEASE:=2
+PKG_SOURCE_DATE:=2019-12-16
+PKG_SOURCE_VERSION:=d04f8ff2e20c42f74161c9cd66502da17b8b0e70
+PKG_RELEASE:=1
-PKG_MAINTAINER:=
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/libimobiledevice/libimobiledevice
+PKG_MIRROR_HASH:=f3ea7b5cd9789dc23ddc464bd00f39813116239cfe4ea1f13f58ce5a8413c361
+
+PKG_MAINTAINER:=Rosen Penev <rosenp@gmail.com>
PKG_LICENSE:=LGPL-2.1-or-later
PKG_LICENSE_FILES:=COPYING.LESSER
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_DATE).tar.gz
-PKG_SOURCE_URL:=https://codeload.github.com/libimobiledevice/libimobiledevice/tar.gz/$(PKG_SOURCE_VERSION)?
-PKG_HASH:=286e294aad60ef04a39ce70512a0e816415167c982f3e6c2988d9a6b8c5ee29b
-PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_SOURCE_VERSION)
-
PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
-include $(INCLUDE_DIR)/nls.mk
define Package/libimobiledevice/Default
TITLE:=A library that talks to Apple devices.
URL:=https://www.libimobiledevice.org/
+ SUBMENU:=libimobiledevice
endef
define Package/libimobiledevice/Default/description
$(call Package/libimobiledevice/Default)
SECTION:=libs
CATEGORY:=Libraries
- DEPENDS:=$(ICONV_DEPENDS) +libplist +libusbmuxd +libopenssl
+ DEPENDS:=+libplist +libusbmuxd +libopenssl
+ LICENSE:=LGPL-2.1-or-later
+ LICENSE_FILES:=COPYING.LESSER
endef
define Package/libimobiledevice/description
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+libimobiledevice
+ LICENSE:=GPL-2.0-or-later
+ ICENSE_FILES:=COPYING
endef
define Package/libimobiledevice-utils/description
This package contains the libimobiledevice utilities.
endef
-CONFIGURE_VARS += ac_cv_sys_file_offset_bits=64
CONFIGURE_ARGS += --without-cython
define Build/InstallDev
--- /dev/null
+From ec2bba4ffe5a0939ba192b014ba594eaa964412f Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Sun, 8 Dec 2019 15:45:19 -0800
+Subject: [PATCH] idevicedate: Fix -Wformat=2 warning
+
+Format functions expect a constant expression, not a variable.
+
+Simplified the code slightly.
+---
+ tools/idevicedate.c | 17 ++++-------------
+ 1 file changed, 4 insertions(+), 13 deletions(-)
+
+diff --git a/tools/idevicedate.c b/tools/idevicedate.c
+index 4de90b63..6dddc185 100644
+--- a/tools/idevicedate.c
++++ b/tools/idevicedate.c
+@@ -38,9 +38,9 @@
+ #include <libimobiledevice/lockdown.h>
+
+ #ifdef _DATE_FMT
+-#define DATE_FMT_LANGINFO() nl_langinfo (_DATE_FMT)
++#define DATE_FMT_LANGINFO nl_langinfo (_DATE_FMT)
+ #else
+-#define DATE_FMT_LANGINFO() ""
++#define DATE_FMT_LANGINFO "%a %b %e %H:%M:%S %Z %Y"
+ #endif
+
+ static void print_usage(int argc, char **argv)
+@@ -75,7 +75,6 @@ int main(int argc, char *argv[])
+ uint64_t datetime = 0;
+ time_t rawtime;
+ struct tm * tmp;
+- char const *format = NULL;
+ char buffer[80];
+ int result = 0;
+
+@@ -131,14 +130,6 @@ int main(int argc, char *argv[])
+ }
+ }
+
+- /* determine a date format */
+- if (!format) {
+- format = DATE_FMT_LANGINFO ();
+- if (!*format) {
+- format = "%a %b %e %H:%M:%S %Z %Y";
+- }
+- }
+-
+ ret = idevice_new(&device, udid);
+ if (ret != IDEVICE_E_SUCCESS) {
+ if (udid) {
+@@ -195,7 +186,7 @@ int main(int argc, char *argv[])
+ tmp = localtime(&rawtime);
+
+ /* finally we format and print the current date */
+- strftime(buffer, 80, format, tmp);
++ strftime(buffer, 80, DATE_FMT_LANGINFO, tmp);
+ puts(buffer);
+ } else {
+ datetime = setdate;
+@@ -217,7 +208,7 @@ int main(int argc, char *argv[])
+
+ if(lockdownd_set_value(client, NULL, "TimeIntervalSince1970", node) == LOCKDOWN_E_SUCCESS) {
+ tmp = localtime(&setdate);
+- strftime(buffer, 80, format, tmp);
++ strftime(buffer, 80, DATE_FMT_LANGINFO, tmp);
+ puts(buffer);
+ } else {
+ printf("ERROR: Failed to set date on device.\n");
+++ /dev/null
---- a/common/userpref.c
-+++ b/common/userpref.c
-@@ -37,6 +37,7 @@
- #include <unistd.h>
- #include <usbmuxd.h>
- #ifdef HAVE_OPENSSL
-+#include <openssl/bn.h>
- #include <openssl/pem.h>
- #include <openssl/rsa.h>
- #include <openssl/x509.h>
-@@ -73,6 +74,11 @@ const ASN1_ARRAY_TYPE pkcs1_asn1_tab[] = {
- };
- #endif
-
-+#if OPENSSL_VERSION_NUMBER < 0x10100000L
-+#define X509_set1_notBefore X509_set_notBefore
-+#define X509_set1_notAfter X509_set_notAfter
-+#endif
-+
- #ifdef WIN32
- #define DIR_SEP '\\'
- #define DIR_SEP_S "\\"
-@@ -420,9 +426,9 @@ userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_da
- /* set key validity */
- ASN1_TIME* asn1time = ASN1_TIME_new();
- ASN1_TIME_set(asn1time, time(NULL));
-- X509_set_notBefore(root_cert, asn1time);
-+ X509_set1_notBefore(root_cert, asn1time);
- ASN1_TIME_set(asn1time, time(NULL) + (60 * 60 * 24 * 365 * 10));
-- X509_set_notAfter(root_cert, asn1time);
-+ X509_set1_notAfter(root_cert, asn1time);
- ASN1_TIME_free(asn1time);
-
- /* use root public key for root cert */
-@@ -453,9 +459,9 @@ userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_da
- /* set key validity */
- ASN1_TIME* asn1time = ASN1_TIME_new();
- ASN1_TIME_set(asn1time, time(NULL));
-- X509_set_notBefore(host_cert, asn1time);
-+ X509_set1_notBefore(host_cert, asn1time);
- ASN1_TIME_set(asn1time, time(NULL) + (60 * 60 * 24 * 365 * 10));
-- X509_set_notAfter(host_cert, asn1time);
-+ X509_set1_notAfter(host_cert, asn1time);
- ASN1_TIME_free(asn1time);
-
- /* use host public key for host cert */
-@@ -533,9 +539,9 @@ userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_da
-
- ASN1_TIME* asn1time = ASN1_TIME_new();
- ASN1_TIME_set(asn1time, time(NULL));
-- X509_set_notBefore(dev_cert, asn1time);
-+ X509_set1_notBefore(dev_cert, asn1time);
- ASN1_TIME_set(asn1time, time(NULL) + (60 * 60 * 24 * 365 * 10));
-- X509_set_notAfter(dev_cert, asn1time);
-+ X509_set1_notAfter(dev_cert, asn1time);
- ASN1_TIME_free(asn1time);
-
- EVP_PKEY* pkey = EVP_PKEY_new();
---- a/src/idevice.c
-+++ b/src/idevice.c
-@@ -36,6 +36,7 @@
- #include <usbmuxd.h>
- #ifdef HAVE_OPENSSL
- #include <openssl/err.h>
-+#include <openssl/rsa.h>
- #include <openssl/ssl.h>
-
- #else
-@@ -49,6 +50,10 @@
-
- #ifdef HAVE_OPENSSL
-
-+#if OPENSSL_VERSION_NUMBER < 0x10100000L
-+#define TLS_method TLSv1_method
-+#endif
-+
- #if OPENSSL_VERSION_NUMBER < 0x10002000L
- static void SSL_COMP_free_compression_methods(void)
- {
-@@ -721,7 +726,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
- }
- BIO_set_fd(ssl_bio, (int)(long)connection->data, BIO_NOCLOSE);
-
-- SSL_CTX *ssl_ctx = SSL_CTX_new(TLSv1_method());
-+ SSL_CTX *ssl_ctx = SSL_CTX_new(TLS_method());
- if (ssl_ctx == NULL) {
- debug_info("ERROR: Could not create SSL context.");
- BIO_free(ssl_bio);
--- /dev/null
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=libirecovery
+PKG_SOURCE_DATE:=2019-12-16
+PKG_SOURCE_VERSION:=db36196d8d9db5a1f92e6934cf931cd00a6ead2d
+PKG_RELEASE:=1
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/libimobiledevice/libirecovery
+PKG_MIRROR_HASH:=635f790b97b7e0001050df6a604c2bcd5cc896213f2a2441f58cf0aa4e00f773
+
+PKG_MAINTAINER:=Rosen Penev <rosenp@gmail.com>
+PKG_LICENSE:=LGPL-2.1-or-later
+PKG_LICENSE_FILES:=COPYING
+
+PKG_FIXUP:=autoreconf
+PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/libirecovery/Default
+ URL:=https://github.com/libimobiledevice/libirecovery
+ SUBMENU:=libimobiledevice
+endef
+
+define Package/libirecovery/Default/description
+ libirecovery is a cross-platform library which implements communication
+ to iBoot/iBSS found on Apple's iOS devices via USB.
+endef
+
+define Package/libirecovery
+ $(call Package/libirecovery/Default)
+ TITLE:=A library that talks to Apple iBoot/iBSS
+ SECTION:=libs
+ CATEGORY:=Libraries
+ DEPENDS:=+libreadline +libusb-1.0
+endef
+
+define Package/libirecovery/description
+ $(call Package/libirecovery/Default/description)
+endef
+
+define Package/irecovery
+ $(call Package/libirecovery/Default)
+ TITLE:=A utility that talks to Apple iBoot/iBSS
+ SECTION:=utils
+ CATEGORY:=Utilities
+ DEPENDS:=+libirecovery
+endef
+
+define Package/irecovery/description
+ $(call Package/libirecovery/Default/description)
+ This package contains the libirecovery utilities.
+endef
+
+CONFIGURE_ARGS += --without-udev
+
+define Build/InstallDev
+ $(INSTALL_DIR) $(1)/usr/include
+ $(CP) $(PKG_INSTALL_DIR)/usr/include/libirecovery.h $(1)/usr/include/
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libirecovery.{a,la,so*} $(1)/usr/lib/
+ $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libirecovery.pc $(1)/usr/lib/pkgconfig/
+endef
+
+define Package/libirecovery/install
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libirecovery.so.* $(1)/usr/lib/
+endef
+
+define Package/irecovery/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(CP) $(PKG_INSTALL_DIR)/usr/bin/irecovery $(1)/usr/bin/
+endef
+
+$(eval $(call BuildPackage,libirecovery))
+$(eval $(call BuildPackage,irecovery))
include $(TOPDIR)/rules.mk
PKG_NAME:=libmbim
-PKG_VERSION:=1.20.2
-PKG_RELEASE:=3
+PKG_VERSION:=1.20.4
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://www.freedesktop.org/software/libmbim
-PKG_HASH:=550fb69e5e57f7646f8eb9ed8d24e44ea869ad846be9c162893f12e43528059b
+PKG_HASH:=ac2708a409b09f1f6f1786a8a9e39c36619aa8d6f285ea943daa7a48ea36d3e8
PKG_MAINTAINER:=Nicholas Smith <nicholas.smith@telcoantennas.com.au>
include $(TOPDIR)/rules.mk
PKG_NAME:=libmicrohttpd
-PKG_VERSION:=0.9.68
+PKG_VERSION:=0.9.69
PKG_RELEASE:=1
PKG_MAINTAINER:=Alexander Couzens <lynxis@fe80.eu>
PKG_LICENSE:=LGPL-2.1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@GNU/libmicrohttpd
-PKG_HASH:=c5716e2a2899abc9e16c8fa7a1a58da88f81aca96a0b7e68a5d4d89e21610b61
+PKG_HASH:=fb9b6b148b787493e637d3083588711e65cbcb726fa02cee2cd543c5de27e37e
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1
include $(TOPDIR)/rules.mk
PKG_NAME:=libplist
-PKG_VERSION:=2.0.0
-PKG_RELEASE:=5
+PKG_SOURCE_VERSION:=2.1.0
+PKG_RELEASE:=2
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
-PKG_SOURCE_URL:=https://www.libimobiledevice.org/downloads
-PKG_HASH:=3a7e9694c2d9a85174ba1fa92417cfabaea7f6d19631e544948dc7e17e82f602
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/libimobiledevice/libplist
+PKG_MIRROR_HASH:=452ef5d6e87461a8b7a47a2274878cf200ccf480b4e81924f22ec1c445e353d0
-PKG_MAINTAINER:=Lukasz Baj <l.baj@radytek.com>
-PKG_LICENSE:=LGPL-2.1-or-later
-PKG_LICENSE_FILES:=COPYING.LESSER
+PKG_MAINTAINER:=Rosen Penev <rosenp@gmail.com>
+PKG_CPE_ID:=cpe:/a:libimobiledevice:libplist
+PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
define Package/libplist/Default
TITLE:=Apple property list
URL:=https://www.libimobiledevice.org/
+ SUBMENU:=libimobiledevice
endef
define Package/libplist/Default/description
CATEGORY:=Libraries
DEPENDS:=+libxml2
TITLE+= library
+ PKG_LICENSE:=LGPL-2.1-or-later
+ PKG_LICENSE_FILES:=COPYING.LESSER
endef
define Package/libplist/description
CATEGORY:=Libraries
DEPENDS:=+libplist $(CXX_DEPENDS)
TITLE+= C++ library
+ PKG_LICENSE:=LGPL-2.1-or-later
+ PKG_LICENSE_FILES:=COPYING.LESSER
endef
define Package/libplistcxx/description
This package contains the libplist C++ shared library.
endef
-define Package/libplist-utils
+define Package/plistutil
$(call Package/libplist/Default)
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+libplist
TITLE+= converter
+ LICENSE:=GPL-2.0-or-later
+ LICENSE_FILES:=COPYING
endef
-define Package/libplist-utils/description
+define Package/plistutil/description
$(call Package/libplist/Default/description)
This package contains the libplist utilities.
endef
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libplist++.so.* $(1)/usr/lib/
endef
-define Package/libplist-utils/install
+define Package/plistutil/install
$(INSTALL_DIR) $(1)/usr/bin
$(CP) $(PKG_INSTALL_DIR)/usr/bin/plistutil $(1)/usr/bin/
endef
$(eval $(call BuildPackage,libplist))
$(eval $(call BuildPackage,libplistcxx))
-$(eval $(call BuildPackage,libplist-utils))
+$(eval $(call BuildPackage,plistutil))
include $(TOPDIR)/rules.mk
PKG_NAME:=libqmi
-PKG_VERSION:=1.24.0
-PKG_RELEASE:=3
+PKG_VERSION:=1.24.2
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://www.freedesktop.org/software/libqmi
-PKG_HASH:=aeb69f90c273467cce246176cba0967c6413f1995a976992770a597c4fe28c79
+PKG_HASH:=4ae4e476f960dbc0d04b1c0368776eb78edffd4421f3e4c074bb2bfb6375b282
PKG_MAINTAINER:=Nicholas Smith <nicholas.smith@telcoantennas.com.au>
include $(TOPDIR)/rules.mk
PKG_NAME:=libtasn1
-PKG_VERSION:=4.14
+PKG_VERSION:=4.15.0
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@GNU/$(PKG_NAME)
-PKG_HASH:=9e604ba5c5c8ea403487695c2e407405820d98540d9de884d6e844f9a9c5ba08
+PKG_HASH:=dd77509fe8f5304deafbca654dc7f0ea57f5841f41ba530cff9a5bf71382739e
PKG_MAINTAINER:=Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
PKG_LICENSE:=LGPL-2.1-or-later
PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/host-build.mk
define Package/libtasn1
SECTION:=libs
--disable-valgrind-tests
define Build/InstallDev
- $(INSTALL_DIR) $(1)/usr/bin
+ # $(INSTALL_DIR) $(1)/usr/bin
+ # $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/* $(1)/usr/bin/
$(INSTALL_DIR) $(1)/usr/include
$(CP) $(PKG_INSTALL_DIR)/usr/include/libtasn1.h $(1)/usr/include/
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libtasn1.so.* $(1)/usr/lib/
endef
+$(eval $(call HostBuild))
$(eval $(call BuildPackage,libtasn1))
include $(TOPDIR)/rules.mk
PKG_NAME:=libugpio
-PKG_VERSION:=0.0.6
-PKG_RELEASE:=2
+PKG_VERSION:=0.0.7
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://github.com/mhei/libugpio/releases/download/v$(PKG_VERSION)
-PKG_HASH:=07d96b46560f42843e46869f45f53d48afee71f9bbcf06f43267fafad0d50b05
+PKG_HASH:=4e0ae6f9cd3d670eb5ba9595a24696a034fda3c7c1900aa9d2cae5a4cd9dab64
PKG_LICENSE:=LGPL-2.1-or-later
PKG_LICENSE_FILES:=COPYING.LESSER
define Package/libugpio/install
$(INSTALL_DIR) $(1)/usr/lib
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/libugpio.so* $(1)/usr/lib/
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libugpio.so.* $(1)/usr/lib/
endef
define Package/gpioctl-sysfs/install
include $(TOPDIR)/rules.mk
PKG_NAME:=libusbmuxd
-PKG_SOURCE_DATE:=2019-03-23
-PKG_SOURCE_VERSION:=873252dc8b4e469c7dc692064ac616104fca5f65
+PKG_SOURCE_VERSION:=2.0.1
PKG_RELEASE:=2
-PKG_MAINTAINER:=Lukasz Baj <l.baj@radytek.com>
-PKG_LICENSE:=LGPL-2.1-or-later
-PKG_LICENSE_FILES:=COPYING.LGPLv2.1
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/libimobiledevice/libusbmuxd
+PKG_MIRROR_HASH:=5078125cd4fe8c7294d4f195a8adfd1fc302101daf5d53e4cc242c3097eef8b6
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_DATE).tar.gz
-PKG_SOURCE_URL:=https://codeload.github.com/libimobiledevice/libusbmuxd/tar.gz/$(PKG_SOURCE_VERSION)?
-PKG_HASH:=47e39ce87b05ca873c16efaa517247aa9db137625dd910d566fb3cd99b4a1d18
-PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_SOURCE_VERSION)
+PKG_MAINTAINER:=Rosen Penev <rosenp@gmail.com>
+PKG_CPE_ID:=cpe:/a:libimobiledevice:libusbmuxd
PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
define Package/libusbmuxd/Default
TITLE:=USB multiplexing daemon
URL:=https://www.libimobiledevice.org/
+ SUBMENU:=libimobiledevice
endef
define Package/libusbmuxd/Default/description
CATEGORY:=Libraries
TITLE+= library
DEPENDS:=+libplist +libpthread +libxml2 +zlib
+ PKG_LICENSE:=LGPL-2.1-or-later
+ PKG_LICENSE_FILES:=COPYING
endef
define Package/libusbmuxd/description
CATEGORY:=Utilities
TITLE+= utilies
DEPENDS:=+libusbmuxd
+ LICENSE:=GPL-2.0-or-later
endef
define Package/libusbmuxd-utils/description
This package contains the libusbmuxd utilities.
endef
-CONFIGURE_ARGS += --with-pic
+TARGET_CFLAGS += $(FPIC)
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include
define Package/libusbmuxd-utils/install
$(INSTALL_DIR) $(1)/usr/bin
- $(CP) $(PKG_INSTALL_DIR)/usr/bin/iproxy $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/iproxy $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/inetcat $(1)/usr/bin/
endef
$(eval $(call BuildPackage,libusbmuxd))
--- /dev/null
+--- a/tools/inetcat.c
++++ b/tools/inetcat.c
+@@ -33,6 +33,7 @@
+ #include <windows.h>
+ #include <winsock2.h>
+ #else
++#include <sys/select.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+ #include <sys/ioctl.h>
include $(TOPDIR)/rules.mk
PKG_NAME:=libuwifi
-PKG_VERSION:=2019-05-27
-PKG_RELEASE:=2
+PKG_VERSION:=2019-12-05
+PKG_RELEASE:=3
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/br101/libuwifi.git
-PKG_SOURCE_VERSION:=bb92bc9b041a077488f2fa5a1716902c7bb23e5b
-PKG_MIRROR_HASH:=c6dc795ef6c2cc87d411d3f907974f634a132c3e732db2597f96ff25a05faa05
+PKG_SOURCE_VERSION:=089bfebd3a8da6e39fd93e33c44368b044c23dde
+PKG_MIRROR_HASH:=a99801ad1dfcf459b00adc582d5e6a31dae9ed10529d114e1e26f5760c6a74f8
PKG_MAINTAINER:=Bruno Randolf <br1@einfach.org>, Nick Hainke <vincent@systemli.org>
PKG_LICENSE:=LGPL-3.0-only
$(CP) $(PKG_BUILD_DIR)/include/uwifi/*.h $(1)/usr/include/uwifi
$(CP) $(PKG_BUILD_DIR)/linux/*.h $(1)/usr/include/uwifi
- $(CP) $(PKG_BUILD_DIR)/ccan $(1)/usr/include/
- $(CP) $(PKG_BUILD_DIR)/config.h $(1)/usr/include/ccan/
-
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/build/libuwifi.{a,so*} $(1)/usr/lib/
endef
+++ /dev/null
-Index: libuwifi-2019-05-27/ccan/build_assert/_info
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/build_assert/_info
-+++ libuwifi-2019-05-27/ccan/build_assert/_info
-@@ -1,4 +1,4 @@
--#include "config.h"
-+#include "../config.h"
- #include <stdio.h>
- #include <string.h>
-
-Index: libuwifi-2019-05-27/ccan/check_type/_info
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/check_type/_info
-+++ libuwifi-2019-05-27/ccan/check_type/_info
-@@ -1,4 +1,4 @@
--#include "config.h"
-+#include "../config.h"
- #include <stdio.h>
- #include <string.h>
-
-Index: libuwifi-2019-05-27/ccan/check_type/check_type.h
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/check_type/check_type.h
-+++ libuwifi-2019-05-27/ccan/check_type/check_type.h
-@@ -1,7 +1,7 @@
- /* CC0 (Public domain) - see LICENSE file for details */
- #ifndef CCAN_CHECK_TYPE_H
- #define CCAN_CHECK_TYPE_H
--#include "config.h"
-+#include "../config.h"
-
- /**
- * check_type - issue a warning or build failure if type is not correct.
-Index: libuwifi-2019-05-27/ccan/container_of/_info
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/container_of/_info
-+++ libuwifi-2019-05-27/ccan/container_of/_info
-@@ -1,4 +1,4 @@
--#include "config.h"
-+#include "../config.h"
- #include <stdio.h>
- #include <string.h>
-
-Index: libuwifi-2019-05-27/ccan/container_of/container_of.h
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/container_of/container_of.h
-+++ libuwifi-2019-05-27/ccan/container_of/container_of.h
-@@ -3,7 +3,7 @@
- #define CCAN_CONTAINER_OF_H
- #include <stddef.h>
-
--#include "config.h"
-+#include "../config.h"
- #include <ccan/check_type/check_type.h>
-
- /**
-Index: libuwifi-2019-05-27/ccan/list/_info
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/list/_info
-+++ libuwifi-2019-05-27/ccan/list/_info
-@@ -1,4 +1,4 @@
--#include "config.h"
-+#include "../config.h"
- #include <stdio.h>
- #include <string.h>
-
-Index: libuwifi-2019-05-27/ccan/str/_info
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/str/_info
-+++ libuwifi-2019-05-27/ccan/str/_info
-@@ -1,4 +1,4 @@
--#include "config.h"
-+#include "../config.h"
- #include <stdio.h>
- #include <string.h>
-
-Index: libuwifi-2019-05-27/ccan/str/debug.c
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/str/debug.c
-+++ libuwifi-2019-05-27/ccan/str/debug.c
-@@ -1,5 +1,5 @@
- /* CC0 (Public domain) - see LICENSE file for details */
--#include "config.h"
-+#include "../config.h"
- #include <ccan/str/str_debug.h>
- #include <assert.h>
- #include <ctype.h>
-Index: libuwifi-2019-05-27/ccan/str/str.h
-===================================================================
---- libuwifi-2019-05-27.orig/ccan/str/str.h
-+++ libuwifi-2019-05-27/ccan/str/str.h
-@@ -1,7 +1,7 @@
- /* CC0 (Public domain) - see LICENSE file for details */
- #ifndef CCAN_STR_H
- #define CCAN_STR_H
--#include "config.h"
-+#include "../config.h"
- #include <string.h>
- #include <stdbool.h>
- #include <limits.h>
PKG_NAME:=libwebp
PKG_VERSION:=1.0.3
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://storage.googleapis.com/downloads.webmproject.org/releases/webp
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
-PKG_USE_MIPS16:=0
include $(INCLUDE_DIR)/package.mk
--- /dev/null
+--- a/src/dsp/dsp.h
++++ b/src/dsp/dsp.h
+@@ -95,7 +95,7 @@ extern "C" {
+ #define WEBP_USE_INTRINSICS
+ #endif
+
+-#if defined(__mips__) && !defined(__mips64) && \
++#if defined(__mips__) && !defined(__mips16) && !defined(__mips64) && \
+ defined(__mips_isa_rev) && (__mips_isa_rev >= 1) && (__mips_isa_rev < 6)
+ #define WEBP_USE_MIPS32
+ #if (__mips_isa_rev >= 2)
--- /dev/null
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=libwslay
+PKG_VERSION:=1.1.0
+PKG_RELEASE=1
+
+PKG_SOURCE:=release-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/tatsuhiro-t/wslay/tar.gz/release-$(PKG_VERSION)?
+PKG_HASH:=df5dca9f03614073cd8bdd22aa3c9b116f841ed3120b2d4463d2382cc44fc594
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/wslay-release-$(PKG_VERSION)
+
+PKG_MAINTAINER:=James Taylor <james@jtaylor.id.au>
+PKG_LICENSE:=MIT
+PKG_LICENSE_FILES:=COPYING
+
+PKG_BUILD_PARALLEL:=1
+PKG_INSTALL:=1
+
+PKG_FIXUP:=autoreconf
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/libwslay
+ SECTION:=libs
+ CATEGORY:=Libraries
+ TITLE:=Wslay is a WebSocket library written in C
+ URL:=https://tatsuhiro-t.github.io/wslay/
+endef
+
+define Package/libwslay/description
+ Wslay is a WebSocket library written in C. It implements the protocol version 13 described
+ in RFC 6455. This library offers 2 levels of API: event-based API and frame-based low-level
+ API. For event-based API, it is suitable for non-blocking reactor pattern style. You can set
+ callbacks in various events. For frame-based API, you can send WebSocket frame directly.
+ Wslay only supports data transfer part of WebSocket protocol and does not perform opening
+ handshake in HTTP.
+endef
+
+define Build/InstallDev
+ $(INSTALL_DIR) $(1)/usr/include/wslay
+ $(CP) $(PKG_INSTALL_DIR)/usr/include/wslay/*.h $(1)/usr/include/wslay/
+
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libwslay.{a,so*} $(1)/usr/lib/
+
+ $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libwslay.pc $(1)/usr/lib/pkgconfig/
+endef
+
+define Package/libwslay/install
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libwslay.so* $(1)/usr/lib/
+endef
+
+$(eval $(call BuildPackage,libwslay))
--- /dev/null
+diff --git a/Makefile.am b/Makefile.am
+index ae8b02f..2e86973 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -20,6 +20,6 @@
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+-SUBDIRS = lib tests examples doc
++SUBDIRS = lib tests
+
+ ACLOCAL_AMFLAGS = -I m4
+diff --git a/configure.ac b/configure.ac
+index 5e83cbf..88f4f03 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -123,9 +123,6 @@ AC_CONFIG_FILES([
+ lib/includes/Makefile
+ lib/includes/wslay/wslayver.h
+ tests/Makefile
+- examples/Makefile
+- doc/Makefile
+- doc/sphinx/conf.py
+ ])
+ AC_OUTPUT
+
include $(TOPDIR)/rules.mk
PKG_NAME:=libxml2
-PKG_VERSION:=2.9.9
-PKG_RELEASE:=4
+PKG_VERSION:=2.9.10
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://xmlsoft.org/sources/
-PKG_HASH:=94fb70890143e3c6549f265cee93ec064c80a84c42ad0f23e85ee1fd6540a871
+PKG_HASH:=aafee193ffb8fe0c82d4afef6ef91972cbaf5feea100edc2f262750611b4be1f
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=COPYING
--- /dev/null
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=libzip
+PKG_VERSION:=1.5.2
+PKG_RELEASE:=2
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
+PKG_SOURCE_URL:=https://libzip.org/download/
+PKG_HASH:=b3de4d4bd49a01e0cab3507fc163f88e1651695b6b9cb25ad174dbe319d4a3b4
+
+PKG_MAINTAINER:=Michael Heimpold <mhei@heimpold.de>
+
+PKG_LICENSE:=BSD-3-Clause
+PKG_LICENSE_FILES:=LICENSE
+
+PKG_BUILD_PARALLEL:=1
+CMAKE_INSTALL:=1
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/libzip/Default
+ TITLE:=libzip ($(2))
+ URL:=https://libzip.org/
+ SECTION:=libs
+ CATEGORY:=Libraries
+ SUBMENU:=Compression
+ DEPENDS:=+zlib $(3)
+ VARIANT:=$(1)
+ PROVIDES:=libzip
+endef
+
+define Package/libzip-$(BUILD_VARIANT)/description
+ A C library for reading, creating, and modifying zip archives.
+endef
+
+Package/libzip-nossl=$(call Package/libzip/Default,nossl,w/o encryption support)
+Package/libzip-openssl=$(call Package/libzip/Default,openssl,OpenSSL,+PACKAGE_libzip-openssl:libopenssl)
+Package/libzip-gnutls=$(call Package/libzip/Default,gnutls,GnuTLS,+PACKAGE_libzip-gnutls:libgnutls)
+Package/libzip-mbedtls=$(call Package/libzip/Default,mbedtls,mbedTLS,+PACKAGE_libzip-mbedtls:libmbedtls)
+
+define Package/zipcmp
+ TITLE:=zipcmp
+ URL:=https://libzip.org/
+ SECTION:=utils
+ CATEGORY:=Utilities
+ SUBMENU:=Compression
+ DEPENDS:=+libzip +USE_MUSL:musl-fts
+endef
+
+define Package/zipcmp/description
+ This package contains the command line tool zipcmp from libzip.
+endef
+
+define Package/zipmerge
+ TITLE:=zipmerge
+ URL:=https://libzip.org/
+ SECTION:=utils
+ CATEGORY:=Utilities
+ SUBMENU:=Compression
+ DEPENDS:=+libzip
+endef
+
+define Package/zipmerge/description
+ This package contains the command line tool zipmerge from libzip.
+endef
+
+define Package/ziptool
+ TITLE:=ziptool
+ URL:=https://libzip.org/
+ SECTION:=utils
+ CATEGORY:=Utilities
+ SUBMENU:=Compression
+ DEPENDS:=+libzip
+endef
+
+define Package/ziptool/description
+ This package contains the command line tool ziptool from libzip.
+endef
+
+CMAKE_OPTIONS += -DENABLE_COMMONCRYPTO=OFF
+ifeq ($(BUILD_VARIANT),gnutls)
+ CMAKE_OPTIONS += -DENABLE_GNUTLS=ON
+else
+ CMAKE_OPTIONS += -DENABLE_GNUTLS=OFF
+endif
+ifeq ($(BUILD_VARIANT),openssl)
+ CMAKE_OPTIONS += -DENABLE_OPENSSL=ON
+else
+ CMAKE_OPTIONS += -DENABLE_OPENSSL=OFF
+endif
+ifeq ($(BUILD_VARIANT),mbedtls)
+ CMAKE_OPTIONS += -DENABLE_MBEDTLS=ON
+else
+ CMAKE_OPTIONS += -DENABLE_MBEDTLS=OFF
+endif
+
+CMAKE_OPTIONS += -DENABLE_BZIP2=OFF
+CMAKE_OPTIONS += -DBUILD_REGRESS=OFF
+CMAKE_OPTIONS += -DBUILD_EXAMPLES=OFF
+CMAKE_OPTIONS += -DBUILD_DOC=OFF
+CMAKE_OPTIONS += -DBUILD_TOOLS=ON
+
+define Package/libzip-$(BUILD_VARIANT)/install
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libzip.so.* $(1)/usr/lib/
+endef
+
+define Package/zipcmp/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/zipcmp $(1)/usr/bin/
+endef
+
+define Package/zipmerge/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/zipmerge $(1)/usr/bin/
+endef
+
+define Package/ziptool/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/ziptool $(1)/usr/bin/
+endef
+
+$(eval $(call BuildPackage,libzip-gnutls))
+$(eval $(call BuildPackage,libzip-mbedtls))
+$(eval $(call BuildPackage,libzip-openssl))
+$(eval $(call BuildPackage,libzip-nossl))
+$(eval $(call BuildPackage,zipcmp))
+$(eval $(call BuildPackage,zipmerge))
+$(eval $(call BuildPackage,ziptool))
--- /dev/null
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -6,7 +6,7 @@ IF(NOT HAVE_GETOPT)
+ ENDIF(NOT HAVE_GETOPT)
+
+ ADD_EXECUTABLE(zipcmp zipcmp.c ${SRC_EXTRA_FILES})
+-TARGET_LINK_LIBRARIES(zipcmp zip)
++TARGET_LINK_LIBRARIES(zipcmp zip ${FTS_LIB})
+ INSTALL(TARGETS zipcmp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+
+ ADD_EXECUTABLE(zipmerge zipmerge.c ${SRC_EXTRA_FILES})
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -22,6 +22,7 @@ OPTION(BUILD_DOC "Build documentation" O
+
+ INCLUDE(CheckFunctionExists)
+ INCLUDE(CheckIncludeFiles)
++INCLUDE(CheckLibraryExists)
+ INCLUDE(CheckSymbolExists)
+ INCLUDE(CheckTypeSize)
+ INCLUDE(CheckCSourceRuns)
+@@ -158,6 +159,20 @@ CHECK_FUNCTION_EXISTS(strtoll HAVE_STRTO
+ CHECK_FUNCTION_EXISTS(strtoull HAVE_STRTOULL)
+
+ CHECK_INCLUDE_FILES("sys/types.h;sys/stat.h;fts.h" HAVE_FTS_H)
++# fts functions may be in external library
++IF(HAVE_FTS_H)
++ CHECK_FUNCTION_EXISTS(fts_open HAVE_FTS_OPEN)
++ IF(NOT HAVE_FTS_OPEN)
++ CHECK_LIBRARY_EXISTS(fts fts_open "" HAVE_LIB_FTS)
++ ENDIF(NOT HAVE_FTS_OPEN)
++ENDIF(HAVE_FTS_H)
++
++IF(HAVE_LIB_FTS)
++ SET(FTS_LIB fts)
++ELSE()
++ SET(FTS_LIB "")
++ENDIF()
++
+ CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H)
+ CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)
+ CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
PKG_NAME:=lmdb
PKG_VERSION:=0.9.24
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=LMDB_$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/LMDB/lmdb/tar.gz/LMDB_$(PKG_VERSION)?
CC="$(TARGET_CC)" \
CFLAGS+="$(TARGET_CFLAGS)" \
LDFLAGS+="$(TARGET_LDFLAGS)" \
- FPIC="$(FPIC)"
+ FPIC="$(FPIC)" \
+ AR="$(TARGET_AR)"
endef
define Build/InstallDev
PKG_NAME:=measurement-kit
PKG_VERSION:=0.10.6
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/measurement-kit/measurement-kit/tar.gz/v$(PKG_VERSION)?
$(call Build/Configure/Default)
endef
+define Build/InstallDev
+ $(INSTALL_DIR) $(1)/usr/include
+ $(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include/
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
+endef
+
define Package/measurement-kit/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/measurement_kit $(1)/usr/bin/
+++ /dev/null
---- a/include/private/catch.hpp
-+++ b/include/private/catch.hpp
-@@ -11095,7 +11095,11 @@ bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) {
- template <typename FP>
- FP step(FP start, FP direction, int steps) {
- for (int i = 0; i < steps; ++i) {
-+#ifndef __UCLIBC__
- start = std::nextafter(start, direction);
-+#else
-+ start = ::nextafterf(start, direction);
-+#endif
- }
- return start;
- }
include $(TOPDIR)/rules.mk
PKG_NAME:=nspr
-PKG_VERSION:=4.23
+PKG_VERSION:=4.24
PKG_RELEASE:=1
PKG_MAINTAINER:=Lucian Cristian <lucian.cristian@gmail.com>
PKG_LICENCE:=MPL-2.0
PKG_SOURCE_URL:= \
https://download.cdn.mozilla.net/pub/$(PKG_NAME)/releases/v$(PKG_VERSION)/src/ \
https://archive.mozilla.org/pub/$(PKG_NAME)/releases/v$(PKG_VERSION)/src/
-PKG_HASH:=4b9d821037faf5723da901515ed9cac8b23ef1ea3729022259777393453477a4
+PKG_HASH:=90a59a0df6a11528749647fe18401cc7e03881e3e63c309f8c520ce06dd413d0
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1
include $(TOPDIR)/rules.mk
PKG_NAME:=nss
-PKG_VERSION:=3.47
-PKG_RELEASE:=1
+PKG_VERSION:=3.48
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:= \
https://download.cdn.mozilla.net/pub/security/$(PKG_NAME)/releases/NSS_$(subst .,_,$(PKG_VERSION))_RTM/src \
https://archive.mozilla.org/pub/security/$(PKG_NAME)/releases/NSS_$(subst .,_,$(PKG_VERSION))_RTM/src
-PKG_HASH:=6cd0c4438b616bdacc0b5f25ff1506b0d07ee97ea6c95d514c5487200a155fa7
+PKG_HASH:=3f9c822a86a4e3e1bfe63e2ed0f922d8b7c2e0b7cafe36774b1c627970d0f8ac
PKG_MAINTAINER:=Lucian Cristian <lucian.cristian@gmail.com>
PKG_LICENCE:=MPL-2.0
export USE_64=1
endif
+ifeq ($(CONFIG_CPU_TYPE),"xscale")
+TARGET_CFLAGS+= -mfloat-abi=softfp
+endif
+
+TARGET_CFLAGS += -D_GNU_SOURCE
TARGET_LDFLAGS += -Wl,--gc-sections,--as-needed
export CROSS_COMPILE=1
$(CP) $(PKG_BUILD_DIR)/dist/build_dir/lib/libfreebl3.so $(1)/usr/lib/
$(CP) $(PKG_BUILD_DIR)/dist/build_dir/lib/libnss3.so $(1)/usr/lib/
+ $(CP) $(PKG_BUILD_DIR)/dist/build_dir/lib/libnssckbi.so $(1)/usr/lib/
$(CP) $(PKG_BUILD_DIR)/dist/build_dir/lib/libnssutil3.so $(1)/usr/lib/
$(CP) $(PKG_BUILD_DIR)/dist/build_dir/lib/libsmime3.so $(1)/usr/lib/
$(CP) $(PKG_BUILD_DIR)/dist/build_dir/lib/libsoftokn3.so $(1)/usr/lib/
diff -Naurp nss-3.28-orig/nss/Makefile nss-3.28/nss/Makefile
--- nss-3.28-orig/nss/Makefile 2016-12-21 05:56:27.000000000 -0600
+++ nss-3.28/nss/Makefile 2016-12-26 22:24:52.695146032 -0600
-@@ -46,7 +46,7 @@ include $(CORE_DEPTH)/coreconf/rules.mk
+@@ -47,7 +47,7 @@ include $(CORE_DEPTH)/coreconf/rules.mk
# (7) Execute "local" rules. (OPTIONAL). #
#######################################################################
ifeq (,$(filter-out WIN%,$(OS_TARGET)))
--- a/nss/coreconf/Linux.mk 2019-04-01 10:08:59.129269177 +0300
+++ b/nss/coreconf/Linux.mk 2019-04-01 10:09:15.557782574 +0300
-@@ -139,6 +139,7 @@
+@@ -143,6 +143,7 @@
DEFINES += -D_REENTRANT
endif
DSO_CFLAGS = -fPIC
DSO_LDOPTS = -shared $(ARCHFLAG) -Wl,--gc-sections
# The linker on Red Hat Linux 7.2 and RHEL 2.1 (GNU ld version 2.11.90.0.8)
-@@ -149,6 +150,7 @@
+@@ -153,6 +154,7 @@
ZDEFS_FLAG = -Wl,-z,defs
DSO_LDOPTS += $(if $(findstring 2.11.90.0.8,$(shell ld -v)),,$(ZDEFS_FLAG))
LDFLAGS += $(ARCHFLAG) -z noexecstack
# library directories.
--- a/nss/coreconf/Linux.mk 2019-04-01 23:10:19.091912203 +0300
+++ b/nss/coreconf/Linux.mk 2019-04-06 14:07:13.499169075 +0300
-@@ -140,7 +140,7 @@
+@@ -144,7 +144,7 @@
endif
ifndef USE_NATIVE
--- a/nss/lib/sqlite/sqlite3.c
+++ b/nss/lib/sqlite/sqlite3.c
-@@ -33761,7 +33761,8 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
+@@ -39626,7 +39626,8 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
if( nTries==1 ){
conchModTime = buf.st_mtimespec;
continue;
}
-@@ -33787,7 +33788,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
+@@ -39652,7 +39653,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
/* don't break the lock on short read or a version mismatch */
return SQLITE_BUSY;
}
include $(TOPDIR)/rules.mk
PKG_NAME:=opencv
-PKG_VERSION:=4.1.1
-PKG_RELEASE:=2
+PKG_VERSION:=4.1.2
+PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/opencv/opencv
PKG_SOURCE_VERSION:=$(PKG_VERSION)
-PKG_MIRROR_HASH:=c8587820421d2f22acdafe4712d068ae490897dc445bdb4aa128ecaa8e65d3a1
+PKG_MIRROR_HASH:=1bd1cad4fa5c8f21499a45869fea40b7886026c048129a01be87b092178258c1
PKG_MAINTAINER:=
PKG_LICENSE:=BSD-3-Clause
+++ /dev/null
---- a/modules/gapi/include/opencv2/gapi/core.hpp
-+++ b/modules/gapi/include/opencv2/gapi/core.hpp
-@@ -392,8 +392,8 @@ namespace core {
- {
- GAPI_Assert(fx != 0. && fy != 0.);
- return in.withSize
-- (Size(static_cast<int>(std::round(in.size.width * fx)),
-- static_cast<int>(std::round(in.size.height * fy))));
-+ (Size(static_cast<int>(round(in.size.width * fx)),
-+ static_cast<int>(round(in.size.height * fy))));
- }
- }
- };
---- a/modules/gapi/include/opencv2/gapi/own/saturate.hpp
-+++ b/modules/gapi/include/opencv2/gapi/own/saturate.hpp
-@@ -81,8 +81,8 @@ static inline DST saturate(SRC x, R round)
- // explicit suffix 'd' for double type
- inline double ceild(double x) { return std::ceil(x); }
- inline double floord(double x) { return std::floor(x); }
--inline double roundd(double x) { return std::round(x); }
--inline double rintd(double x) { return std::rint(x); }
-+inline double roundd(double x) { return round(x); }
-+inline double rintd(double x) { return rint(x); }
-
- } //namespace own
- } //namespace gapi
---- a/modules/gapi/src/backends/fluid/gfluidcore.cpp
-+++ b/modules/gapi/src/backends/fluid/gfluidcore.cpp
-@@ -389,7 +389,7 @@ static void run_arithm_s1(uchar out[], const float in[], int width, const float
- cv::util::suppress_unused_warning(v_op);
- for (; w < width; w++)
- {
-- out[w] = saturate<uchar>(s_op(in[w], scalar[0]), std::roundf);
-+ out[w] = saturate<uchar>(s_op(in[w], scalar[0]), roundf);
- }
- }
-
-@@ -1954,7 +1954,7 @@ GAPI_FLUID_KERNEL(GFluidCartToPolar, cv::gapi::core::GCartToPolar, false)
- {
- float x = in1[l];
- float y = in2[l];
-- float magnitude = std::hypot(y, x);
-+ float magnitude = hypot(y, x);
- float angle_rad = std::atan2(y, x);
- float angle = angleInDegrees?
- angle_rad * static_cast<float>(180 / CV_PI):
+++ /dev/null
---- a/3rdparty/libjasper/jas_stream.c
-+++ b/3rdparty/libjasper/jas_stream.c
-@@ -86,6 +86,10 @@
- #include <io.h>
- #endif
-
-+#ifndef L_tmpnam
-+#define L_tmpnam 20
-+#endif
-+
- #include "jasper/jas_types.h"
- #include "jasper/jas_stream.h"
- #include "jasper/jas_malloc.h"
PKG_NAME:=p11-kit
PKG_VERSION:=0.23.18.1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/p11-glue/p11-kit/releases/download/$(PKG_VERSION)
--without-libffi \
--without-systemd
+CONFIGURE_VARS += \
+ ac_cv_have_decl_program_invocation_short_name=yes
+
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include/p11-kit-1/p11-kit/
$(CP) $(PKG_INSTALL_DIR)/usr/include/p11-kit-1/p11-kit/* $(1)/usr/include/p11-kit-1/p11-kit/
PKG_NAME:=postgresql
PKG_VERSION:=11.3
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_MAINTAINER:=Daniel Golle <daniel@makrotopia.org>
PKG_LICENSE:=PostgreSQL
PKG_CPE_ID:=cpe:/a:postgresql:postgresql
USE_PROCD=1
-EXTRA_COMMANDS="status"
-EXTRA_HELP=" status Show current status of the PostgreSQL server"
-
fix_hosts() {
# make sure localhost (without a dot) is in /etc/hosts
grep -q 'localhost$' /etc/hosts || echo '127.0.0.1 localhost' >> /etc/hosts
/usr/bin/pg_ctl stop -U postgres -D "${pgdata}" -s
}
-status() {
+status_service() {
config_load "postgresql"
config_get pgdata config PGDATA
/usr/bin/pg_ctl status -U postgres -D "${pgdata}"
PKG_NAME:=protobuf
PKG_VERSION:=3.8.0
-PKG_RELEASE:=4
+PKG_RELEASE:=5
PKG_SOURCE:=$(PKG_NAME)-cpp-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/google/protobuf/releases/download/v$(PKG_VERSION)
-Dprotobuf_BUILD_TESTS=OFF \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_SKIP_RPATH=OFF \
+ -DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_INSTALL_RPATH="${STAGING_DIR_HOSTPKG}/lib"
CMAKE_OPTIONS += \
--- /dev/null
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=rpcsvc-proto
+PKG_VERSION:=1.4
+PKG_RELEASE:=2
+
+PKG_SOURCE_URL:=https://github.com/thkukuk/rpcsvc-proto/releases/download/v$(PKG_VERSION)/
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_HASH:=867e46767812784d8dda6d8d931d6fabb30168abb02d87a2a205be6d5a2934a7
+
+PKG_MAINTAINER:=Andy Walsh <andy.walsh44+github@gmail.com>
+PKG_LICENSE:=BSD-3-clause
+PKG_LICENSE_FILES:=COPYING
+
+PKG_FIXUP:=autoreconf
+PKG_REMOVE_FILES:=autogen.sh
+PKG_INSTALL:=1
+
+PKG_BUILD_DEPENDS:=rpcsvc-proto/host
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/nls.mk
+include $(INCLUDE_DIR)/host-build.mk
+
+define Package/rpcsvc-proto
+ SECTION:=libs
+ CATEGORY:=Libraries
+ TITLE:=rpcgen and rpcsvc proto.x files from glibc
+ URL:=https://github.com/thkukuk/rpcsvc-proto
+ DEPENDS:=$(INTL_DEPENDS)
+endef
+
+define Package/rpcsvc-proto/description
+ This package contains rpcsvc proto.x files from glibc, which are missing in libtirpc.
+ Additional it contains rpcgen, which is needed to create header files and sources from protocol files.
+endef
+
+# need to use host tool
+define Build/Prepare
+ $(Build/Prepare/Default)
+ $(SED) 's,.*/rpcgen/rpcgen,\t$(STAGING_DIR_HOSTPKG)/bin/rpcgen,' $(PKG_BUILD_DIR)/rpcsvc/Makefile.am
+endef
+
+define Build/InstallDev
+ $(INSTALL_DIR) $(1)/usr/include
+ $(CP) $(PKG_INSTALL_DIR)/usr/include/rpcsvc $(1)/usr/include/
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/rpcgen $(1)/usr/bin/
+endef
+
+# do we need rpcgen on target?
+define Package/rpcsvc-proto/install
+ # $(INSTALL_DIR) $(1)/usr/bin
+ # $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/rpcgen $(1)/usr/bin/
+endef
+
+$(eval $(call HostBuild))
+$(eval $(call BuildPackage,rpcsvc-proto))
PKG_NAME:=spice
PKG_VERSION:=0.14.2
-PKG_RELEASE:=2
+PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://www.spice-space.org/download/releases/spice-server
PKG_HASH:=b203b3882e06f4c7249a3150d90c84e1a90490d41ead255a3d2cede46f4a29a7
--disable-gstreamer \
--disable-smartcard \
--disable-statistics \
+ --without-sasl \
+ --disable-silent-rules \
$(eval $(call BuildPackage,libspice-server))
--- /dev/null
+Tests build can fail for arc700 for the following causes
+
+ - Missing -stack-protector-all argument when building test progs
+ - Missing linker flag -lgmodule-2.0 -lffi
+
+--- a/server/Makefile.am.orig 2019-12-25 18:31:59.133981942 +0800
++++ b/server/Makefile.am 2019-12-25 18:32:06.308976585 +0800
+@@ -1,5 +1,5 @@
+ NULL =
+-SUBDIRS = . tests
++SUBDIRS = .
+
+ check-valgrind:
+ $(MAKE) -C tests check-valgrind
--- /dev/null
+Tools build can fail because -stack-protector-all is missing
+
+--- a/tools/Makefile.am.orig 2019-12-25 18:51:48.947959673 +0800
++++ b/tools/Makefile.am 2019-12-25 18:51:56.165952726 +0800
+@@ -8,6 +8,7 @@ AM_CPPFLAGS = \
+
+ AM_LDFLAGS = \
+ $(LIBRT) \
++ $(WARN_LDFLAGS) \
+ $(NULL)
+
+ noinst_PROGRAMS = \
include $(TOPDIR)/rules.mk
PKG_NAME:=tinycdb
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE_URL:=http://www.corpit.ru/mjt/tinycdb/
PKG_VERSION:=0.78
PKG_HASH:=50678f432d8ada8d69f728ec11c3140e151813a7847cf30a62d86f3a720ed63c
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_INSTALL:=1
+
include $(INCLUDE_DIR)/package.mk
+# Pass CPPFLAGS in the CFLAGS as otherwise the build system will
+# ignore them.
+TARGET_CFLAGS+=$(TARGET_CPPFLAGS)
+
+MAKE_FLAGS+= \
+ CFLAGS="$(TARGET_CFLAGS)" \
+ LDFLAGS="$(TARGET_LDFLAGS)"
+
+CDB_INST_STRING:=prefix=/usr install install-sharedlib install-piclib
+
define Package/tinycdb
SECTION:=libs
CATEGORY:=Libraries
TITLE:=a Constant DataBase
URL:=http://www.corpit.ru/mjt/tinycdb.html
+ ABI_VERSION=1
endef
define Package/tinycdb/description
TinyCDB is a very fast and simple package for creating and reading constant data bases
endef
-define Build/InstallDev
- cd $(PKG_BUILD_DIR); $(MAKE) DESTDIR=$(1) prefix=/usr install
+define Package/tinycdb/install
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libcdb.so.$(ABI_VERSION) $(1)/usr/lib
endef
+define Build/Compile
+ $(call Build/Compile/Default,shared staticlib piclib)
+endef
+
+define Build/Install
+ $(call Build/Install/Default,$(CDB_INST_STRING))
+endef
+define Build/InstallDev
+ cd $(PKG_BUILD_DIR); $(MAKE) DESTDIR=$(1) $(CDB_INST_STRING)
+endef
$(eval $(call BuildPackage,tinycdb))
include $(TOPDIR)/rules.mk
PKG_NAME:=dovecot
-PKG_VERSION:=2.3.8
-PKG_RELEASE:=1
+PKG_VERSION:=2.3.9
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://dovecot.org/releases/2.3
-PKG_HASH:=c5778d03bf26ab34a605854098035badec455d07adfab38d974f610c8f78b649
+PKG_HASH:=df2c53e5a0463c5c52af682fb11c17eb7f79115d95a861a63cd09329fd7daa9f
PKG_MAINTAINER:=Lucian Cristian <lucian.cristian@gmail.com>
PKG_LICENSE:=LGPL-2.1-only MIT BSD-3-Clause
CONFIGURE_ARGS += \
--libexecdir=/usr/libexec \
+ --without-libunwind \
--without-pam \
--with-notify=dnotify \
--without-lzma \
+++ /dev/null
-#
-# Copyright (C) 2009 David Cooper <dave@kupesoft.com>
-# Copyright (C) 2016-2019 Daniel Dickinson <cshored@thecshore.com>
-#
-# This is free software, licensed under the GNU General Public License v2.
-# See /LICENSE for more information.
-#
-
-include $(TOPDIR)/rules.mk
-
-PKG_NAME:=msmtp-scripts
-PKG_VERSION:=1.2.5.1
-PKG_RELEASE:=1
-
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://launchpad.net/$(PKG_NAME)/1.2/$(PKG_VERSION)/+download
-PKG_HASH:=757aa297a0e0283399fffdc460044bfeb653673695fc02c92215a5e32d104151
-PKG_MAINTAINER:=Daniel F. Dickinson <cshored@thecshore.com>
-
-PKG_LICENSE:=GPL-3.0-or-later
-PKG_LICENSE_FILES:=COPYING
-
-include $(INCLUDE_DIR)/package.mk
-
-define Package/msmtp-scripts/Default
- SECTION:=mail
- CATEGORY:=Mail
- TITLE:=Forwarding only SMTP with queuing
- URL:=https://msmtp-scripts.thecshore.com
-endef
-
-define Package/msmtp-scripts/Default/description
- msmtp-scripts are scripts wrappers around the msmtp SMTP client that
- add queueing, logging to syslog or file, and a subset of sendmail/postfix
- mailq/postsuper/postqueue commands implemented in a compatible fashion.
-endef
-
-define Package/msmtpq-ng
-$(call Package/msmtp-scripts/Default)
- DEPENDS+= +msmtp
- TITLE+= (common)
-endef
-
-define Package/msmtpq-ng/conffiles
-/etc/msmtpq-ng.rc
-endef
-
-define Package/msmtpq-ng/description
- $(call Package/msmtp-scripts/Default/description)
- This package contains the msmtpq-ng and msmtpq-ng-queue
- wrappers around msmtp, which provide the bulk of the
- functionality.
-endef
-
-define Package/msmtpq-ng-mta
-$(call Package/msmtp-scripts/Default)
- TITLE+= (as MTA)
- DEPENDS+=+msmtpq-ng
- ALTERNATIVES:=\
- 400:/usr/sbin/sendmail:/usr/sbin/msmtpq-ng-mta \
- 400:/usr/lib/sendmail:/usr/sbin/msmtpq-ng-mta \
- 400:/usr/sbin/mailq:/usr/sbin/msmtpq-ng-queue-mta \
- 400:/usr/sbin/postqueue:/usr/sbin/msmtpq-ng-queue-mta \
- 400:/usr/sbin/postsuper:/usr/sbin/msmtpq-ng-queue-mta
-endef
-
-define Package/msmtpq-ng-mta/conffiles
-/etc/msmtpq-ng-mta.rc
-endef
-
-define Package/msmtpq-ng-mta/description
- $(call Package/msmtp-scripts/Default/description)
- This package provides sendmail, mailq, postfix,
- and postsuper symlinks to wrappers that configure
- msmtpq-ng for use as the system mail transport
- agent via the sendmail command.
-
-**NB**: In order for msmtpq-ng-mta aka sendmail to
-send mail for non-root users (not just queue it
-after failing), the user must have permissions to
-access /etc/msmtprc -- package msmtp sets msmtprc
-to rw only by root by default as a security measure
-(it _can_ contain information like passwords with
-which to send mail through your email server).
-
-There are a couple of choices. One is to leave
-the default permissions (in which cases the mail
-will queue and fail to send until the mailq -q
-runner which runs in a root crontab sends the mail).
-Another is to give any non-root daemon users (or
-any other users) group access (i.e. create a
-group for all the users who should be able to
-send mail, add the users to it, and give the
-group read-only permissions on the msmtrpc).
-A final option (which is only resonable if you
-have no secrets in msmtprc because you are
-sending unauthenticated mail to a server that
-accepts mail directly for the intended user --
-usually that means a self-hosted system mail
-server, rather than trying to send mail to
-public servers (which don't typically accept
-mail from normal user IP addresses, even if
-you ISP doesn't block the traffic) is to
-make msmtprc world readable.
-
-The first option is probably the best choice
-for most users, as it just means a 15
-minute delay in the mail getting off the
-system, and doesn't involve special permissions
-for non-root daemons or users.
-endef
-
-define Package/msmtpq-ng-mta-smtpd
-$(call Package/msmtp-scripts/Default)
- DEPENDS+= +msmtpq-ng-mta +xinetd
- TITLE+= (localhost SMTPd)
- USERID:=msmtp=482:msmtp=482
-endef
-
-define Package/msmtp-ng-mta-smtpd/description
- $(call Package/msmtp-scripts/Default/description)
- This package uses the -bs option to msmtpq-ng
- (which, like the sendmail -bs command, provides
- SMTP over stdin/stdout) combined with xinetd to
- provide a basic SMTP server. In it's default
- configuration it only accepts connections from
- localhost AND network mail must be released from
- the hold queue before it can be delivered.
-endef
-
-define Package/msmtpq-ng-mta-smtpd/conffiles
-/etc/xinetd.d/ms-mta-smtpd
-endef
-
-define Package/msmtpq-ng-mta/postinst
- mkdir -p $${IPKG_INSTROOT}/etc/crontabs
- if ! grep -q msmtpq-ng-mta $${IPKG_INSTROOT}/etc/crontabs/root 2>/dev/null; then echo $$'\n'"*/60 * * * * /usr/bin/msmtpq-ng-mta -q" >>$${IPKG_INSTROOT}/etc/crontabs/root; fi
-endef
-
-define Build/Configure
- true
-endef
-
-define Build/Compile
- true
-endef
-
-define Package/msmtpq-ng/install
- $(INSTALL_DIR) $(1)/etc
- $(INSTALL_DATA) ./files/msmtpq-ng.rc $(1)/etc/msmtpq-ng.rc
- $(INSTALL_DIR) $(1)/usr/bin
- $(CP) $(PKG_BUILD_DIR)/src/usr/bin/msmtpq-ng $(1)/usr/bin/
- $(SED) "s,nc -vz,printf \"HEAD / HTTP/1.1\\\\r\\\\nHost: \$$$${EMAIL_CONN_TEST_SITE}\\\\r\\\\n\\\\r\\\\n\"|nc," $(1)/usr/bin/msmtpq-ng
- $(CP) $(PKG_BUILD_DIR)/src/usr/bin/msmtpq-ng-queue $(1)/usr/bin/
-endef
-
-define Package/msmtpq-ng-mta/install
- $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/sbin $(1)/usr/lib $(1)/etc/init.d
- $(INSTALL_DATA) ./files/msmtpq-ng-mta.rc $(1)/etc/
- $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/usr/sbin/msmtpq-ng-mta $(1)/usr/sbin/
- $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/usr/sbin//msmtpq-ng-queue-mta $(1)/usr/sbin/
- $(INSTALL_DIR) $(1)/etc/crontabs
- $(INSTALL_BIN) ./files/msmtpq-ng-mta.init $(1)/etc/init.d/msmtpq-ng-mta
-endef
-
-define Package/msmtpq-ng-mta-smtpd/install
- $(INSTALL_DIR) $(1)/etc/xinetd.d
- $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/etc/xinetd.d/ms-mta-smtpd $(1)/etc/xinetd.d/ms-mta-smtpd
-endef
-
-
-$(eval $(call BuildPackage,msmtpq-ng))
-$(eval $(call BuildPackage,msmtpq-ng-mta))
-$(eval $(call BuildPackage,msmtpq-ng-mta-smtpd))
+++ /dev/null
-#!/bin/sh /etc/rc.common
-# Copyright (C) 2006-2016 OpenWrt.org
-
-START=90
-
-boot() {
- if [ ! -d /var/spool/msmtp ]; then
- mkdir -m1777 -p /var/spool/msmtp
- else
- chmod 1777 /var/spool/msmtp
- fi
-
- if [ ! -d /var/lock/msmtp ]; then
- mkdir -m1777 -p /var/lock/msmtp
- else
- chmod 1777 /var/spool/msmtp
- fi
-}
-
+++ /dev/null
-#!/bin/sh
-
-#Q=/var/spool/msmtp/"$(id -un)"
-#LOG=syslog
-#MAXLOGLEVEL=7
-#MSMTP_LOCK_DIR=/var/lock/msmtp/"$(id -un)"
-#MSMTP_UMASK=077
-#MSMTP_LOG_UMASK=007
-#MSMTP_QUEUE_QUIET=true
-#MSMTP_IGNORE_NO_RECIPIENTS=true
-#MSMTP_QUEUE_ONLY=false
-#MSMTP_SEND_DELAY=0
-#MSMTP_MAXIMUM_QUEUE_LIFETIME=345600 # Four days
-#MSMTPQ_NG=msmtpq-ng
-#MSMTPQ_NG_QUEUE=msmtpq-ng-queue
-#MSMTP_CONF=/etc/msmtprc
-EMAIL_CONN_TEST=n
-#EMAIL_CONN_TEST_PING=openwrt.org
-#EMAIL_CONN_TEST_IP=8.8.8.8
-EMAIL_CONN_TEST_SITE=openwrt.org
-#MSMTP_HOLD_SMTP_MAIL=true
-#MSMTP_HOLD_CLI_MAIL=false
+++ /dev/null
-#!/bin/sh
-
-#Q=~/msmtp.queue
-#LOG=~/log/.msmtp.queue.log
-#MAXLOGLEVEL=7
-#MSMTP_LOCK_DIR=~/.msmtp.lock
-EMAIL_CONN_TEST=n
-#EMAIL_CONN_TEST_PING=openwrt.org
-#EMAIL_CONN_TEST_IP=8.8.8.8
-EMAIL_CONN_TEST_SITE=openwrt.org
-#MSMTP_UMASK=077
-#MSMTP_LOG_UMASK=077
-#MSMTP_QUEUE_QUIET=false
-#MSMTP_IGNORE_NO_RECIPIENTS=true
-#MSMTP_QUEUE_ONLY=false
-#MSMTP_SEND_DELAY=0
-#MSMTP_MAXIMUM_QUEUE_LIFETIME=345600 # Four days
-#MSMTP=msmtp
-#MSMTPQ_NG_QUEUE=msmtpq-ng-queue
-#MSMTP_HOLD_SMTP_MAIL=true
-#MSMTP_HOLD_CLI_MAIL=false
-#MSMTP_CONF=/etc/msmtprc
-#LOCK_CMD=flock
include $(TOPDIR)/rules.mk
PKG_NAME:=dovecot-pigeonhole
-PKG_VERSION_PLUGIN:=0.5.8
+PKG_VERSION_PLUGIN:=0.5.9
PKG_VERSION_DOVECOT:=$(shell make --no-print-directory -C ../dovecot/ val.PKG_VERSION V=s)
PKG_VERSION:=$(PKG_VERSION_DOVECOT)-$(PKG_VERSION_PLUGIN)
PKG_RELEASE:=1
PKG_SOURCE:=dovecot-$(DOVECOT_VERSION)-pigeonhole-$(PKG_VERSION_PLUGIN).tar.gz
PKG_SOURCE_URL:=https://pigeonhole.dovecot.org/releases/$(DOVECOT_VERSION)
-PKG_HASH:=8fb860d50c1b1a09aea9e25f8ee89c22e34ecedfb0e11a1c48a7f67310759022
+PKG_HASH:=36da68aae5157b83e21383f711b8977e5b6f5477f369f71e7e22e76a738bbd05
+
+PKG_MAINTAINER:=W. Michael Petullo <mike@flyn.org>
PKG_LICENSE:=LGPL-2.1-or-later
PKG_LICENSE_FILES:=COPYING COPYING.LGPL
PKG_CPE_ID:=cpe:/a:dovecot:pigeonhole
DEPENDS:=+dovecot
EXTRA_DEPENDS:=dovecot (>= $(PKG_VERSION_DOVECOT))
TITLE:=Mail filtering facilities for Dovecot
- MAINTAINER:=W. Michael Petullo <mike@flyn.org>
URL:=https://wiki2.dovecot.org/Pigeonhole
endef
include $(TOPDIR)/rules.mk
PKG_NAME:=postfix
-PKG_RELEASE:=1
+PKG_RELEASE:=3
PKG_VERSION:=3.4.6
PKG_SOURCE_URL:= \
https://cdn.postfix.johnriley.me/mirrors/postfix-release/official/ \
PKG_LICENSE_FILES:=LICENSE
PKG_CPE_ID:=cpe:/a:postfix:postfix
-PKG_BUILD_DEPENDS:=POSTFIX_CDB:tinycdb
PKG_CONFIG_DEPENDS:= \
CONFIG_POSTFIX_TLS \
CONFIG_POSTFIX_SASL \
postfix=25:postfix=25 \
postdrop=26:postdrop=26
URL:=http://www.postfix.org/
- DEPENDS:=+POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +POSTFIX_DB:libdb47 +POSTFIX_SQLITE:libsqlite3 +POSTFIX_MYSQL:libmysqlclient +POSTFIX_PGSQL:libpq +POSTFIX_EAI:icu +POSTFIX_PCRE:libpcre
+ DEPENDS:=+POSTFIX_CDB:tinycdb +POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +POSTFIX_DB:libdb47 +POSTFIX_SQLITE:libsqlite3 +POSTFIX_MYSQL:libmysqlclient +POSTFIX_PGSQL:libpq +POSTFIX_EAI:icu +POSTFIX_PCRE:libpcre
endef
define Package/postfix/description
+++ /dev/null
---- a/src/smtpd/smtpd_check.c
-+++ b/src/smtpd/smtpd_check.c
-@@ -5325,7 +5325,7 @@ char *smtpd_check_queue(SMTPD_STATE *state)
- */
- #define BLOCKS(x) ((x) / fsbuf.block_size)
-
-- fsspace(".", &fsbuf);
-+ fsspace("/overlay", &fsbuf);
- if (msg_verbose)
- msg_info("%s: blocks %lu avail %lu min_free %lu msg_size_limit %lu",
- myname,
include $(TOPDIR)/rules.mk
PKG_NAME:=minidlna
-PKG_RELEASE:=1
+PKG_RELEASE:=2
-PKG_SOURCE_URL=git://minidlna.git.sourceforge.net/gitroot/minidlna/minidlna
PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://git.code.sf.net/p/minidlna/git
PKG_SOURCE_DATE:=2018-04-10
PKG_SOURCE_VERSION:=799e6cf505ec470b2bf0ae4118143380aa16b837
PKG_MIRROR_HASH:=67cc817e671de99e5a3f5ed237f89e22470f1de94819bcaba86c0ba821104af5
option serial '12345678'
option model_number '1'
option root_container '.'
+ option uuid '019f9a56-ff60-44c0-9edc-eae88d09fa05'
list media_dir '/mnt'
option album_art_names 'Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg'
minidlna_cfg_addstr "$cfg" model_number '1'
minidlna_cfg_addstr "$cfg" minissdpsocket
minidlna_cfg_addstr "$cfg" root_container '.'
+ minidlna_cfg_addstr "$cfg" uuid '019f9a56-ff60-44c0-9edc-eae88d09fa05'
config_list_foreach "$cfg" "media_dir" minidlna_cfg_add_media_dir
return 0
PKG_NAME:=motion
PKG_VERSION:=4.2.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_MAINTAINER:=Roger D <rogerdammit@gmail.com>
PKG_LICENSE:=GPLv2
endef
define Package/motion/conffiles
+/etc/config/motion
/etc/motion.conf
endef
--without-webp
define Package/motion/install
- $(INSTALL_DIR) $(1)/etc
+ $(INSTALL_DIR) $(1)/etc/config $(1)/etc/init.d
+ $(INSTALL_CONF) ./files/motion.conf $(1)/etc/config/motion
+ $(INSTALL_BIN) ./files/motion.init $(1)/etc/init.d/motion
$(CP) $(PKG_BUILD_DIR)/motion-dist.conf $(1)/etc/motion.conf
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/motion $(1)/usr/bin/
--- /dev/null
+config motion general
+ option enabled '0'
--- /dev/null
+#!/bin/sh /etc/rc.common
+
+START=94
+USE_PROCD=1
+
+PROG="/usr/bin/motion"
+CONF="/etc/motion.conf"
+
+start_service() {
+ local enabled
+
+ config_load "motion"
+ config_get_bool enabled "general" "enabled" 0
+ [ "$enabled" -gt 0 ] || return 1
+
+ procd_open_instance
+
+ procd_set_param command "$PROG"
+ procd_append_param command -c "$CONF"
+
+ procd_close_instance
+}
--- /dev/null
+From c9bef916853c709fbf7f305da36da33ac4881660 Mon Sep 17 00:00:00 2001
+From: Mr-DaveDev <MotionMrDaveDev@gmail.com>
+Date: Sun, 1 Dec 2019 14:30:10 -0700
+Subject: [PATCH] Remove poll option for mhd
+
+closes #1063
+---
+ webu.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/webu.c
++++ b/webu.c
+@@ -1828,7 +1828,7 @@ static void webu_mhd_opts(struct mhdstar
+ static void webu_mhd_flags(struct mhdstart_ctx *mhdst){
+
+ /* This sets the MHD startup flags based upon what user put into configuration */
+- mhdst->mhd_flags = MHD_USE_THREAD_PER_CONNECTION | MHD_USE_POLL| MHD_USE_SELECT_INTERNALLY;
++ mhdst->mhd_flags = MHD_USE_THREAD_PER_CONNECTION;
+
+ if (mhdst->ipv6) mhdst->mhd_flags = mhdst->mhd_flags | MHD_USE_DUAL_STACK;
+
include $(TOPDIR)/rules.mk
PKG_NAME:=v4l2rtspserver
-PKG_VERSION:=0.1.8
+PKG_VERSION:=0.1.9
PKG_RELEASE:=1
#cannot use codeload as this uses submodules
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/mpromonet/v4l2rtspserver
PKG_SOURCE_VERSION:=v$(PKG_VERSION)
-PKG_MIRROR_HASH:=2df448435fa169b1611e619496ec529baa4caa59627a8a508fb6db59c31e42be
+PKG_MIRROR_HASH:=bcb68170f6b6a3560902673c4145d0311d4f661b2ed3d71ed1ee1a58bdde96d2
-LIVE555_VERSION:=2019.08.28
-LIVE555_HASH:=a3dcd157865186cf883c3a80b4bb09637e91fff96b234b2c780a7f7dcc7a35dc
+LIVE555_VERSION:=2019.11.22
+LIVE555_HASH:=cd10fbd2d28d0bc39c12ec57b9f6b13fab3bfc7005f5ac8f9c94a9eb34179e90
LIVE555_FILE:=live.$(LIVE555_VERSION).tar.gz
PKG_MAINTAINER:=Roger Dammit <rogerdammit@gmail.com>
TARGET_CFLAGS += -ffunction-sections -fdata-sections -flto
TARGET_LDFLAGS += -Wl,--gc-sections,--as-needed
-CMAKE_OPTIONS += -DALSA=OFF -DLIVE555CFLAGS="$(TARGET_CFLAGS) -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLOCALE_NOT_USED -DNO_SSTREAM=1 -DALLOW_RTSP_SERVER_PORT_REUSE=1"
+CMAKE_OPTIONS += -DALSA=OFF -DLIVE555CFLAGS="$(TARGET_CFLAGS) -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLOCALE_NOT_USED -DNO_SSTREAM=1 -DALLOW_RTSP_SERVER_PORT_REUSE=1 -DVERSION=\\\"$(PKG_VERSION)\\\""
define Build/Prepare
$(Build/Prepare/Default)
include $(TOPDIR)/rules.mk
PKG_NAME:=youtube-dl
-PKG_VERSION:=2019.11.22
+PKG_VERSION:=2019.12.25
PKG_RELEASE:=1
PYPI_NAME:=youtube_dl
-PKG_HASH:=0575efd332cb9817f5a1fffd2a1e569e5a7d3642e7c24c7a5c47cbf70f301f25
+PKG_HASH:=5f73e8c66c07d632b0fc69f715247fe76f38a28c0c5f13bd0651ecd193c2f1c6
PKG_MAINTAINER:=Adrian Panella <ianchi74@outlook.com>, Josef Schlehofer <pepe.schlehofer@gmail.com>
PKG_LICENSE:=Unlicense
include $(TOPDIR)/rules.mk
PKG_NAME:=adblock
-PKG_VERSION:=3.8.12
+PKG_VERSION:=3.8.14
PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
* Daily updates, approx. 1.500 entries
* [openphish](https://openphish.com)
* Numerous updates on the same day, approx. 1.800 entries
- * [ransomware tracker](https://ransomwaretracker.abuse.ch)
- * Daily updates, approx. 150 entries
* [reg_cn](https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt)
* Regional blocklist for China, daily updates, approx. 1.600 entries
* [reg_cz](https://raw.githubusercontent.com/qxstyles/turris-hole-czech-block-list/master/turris-hole-czech-block-list)
* Weekly updates, approx. 21.000 entries
* [ut_capitole](https://dsi.ut-capitole.fr/blacklists) (categories "cryptojacking" "ddos" "malware" "phishing" "warez" enabled by default)
* Daily updates, approx. 64.000 entries (a short description of all categories can be found [online](https://dsi.ut-capitole.fr/blacklists/index_en.php))
- * [whocares](http://someonewhocares.org)
+ * [whocares](https://someonewhocares.org)
* Weekly updates, approx. 12.000 entries
* [winhelp](http://winhelp2002.mvps.org)
* Infrequent updates, approx. 15.000 entries
option adb_src_desc 'focus on phishing, numerous updates on the same day, approx. 2.400 entries'
option enabled '0'
-config source 'ransomware'
- option adb_src 'https://ransomwaretracker.abuse.ch/downloads/RW_DOMBL.txt'
- option adb_src_rset '/^([[:alnum:]_-]+\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower(\$1)}'
- option adb_src_desc 'focus on ransomware by abuse.ch, numerous updates on the same day, approx. 1900 entries'
- option enabled '0'
-
config source 'reg_cn'
option adb_src 'https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt'
option adb_src_rset 'BEGIN{FS=\"[|^]\"}/^\|\|([[:alnum:]_-]+\.)+[[:alpha:]]+\^("\\\$third-party")?$/{print tolower(\$3)}'
option enabled '0'
config source 'whocares'
- option adb_src 'http://someonewhocares.org/hosts/hosts'
+ option adb_src 'https://someonewhocares.org/hosts/hosts'
option adb_src_rset '/^127\.0\.0\.1[[:space:]]+([[:alnum:]_-]+\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower(\$2)}'
option adb_src_desc 'broad blocklist, weekly updates, approx. 10.000 entries'
option enabled '0'
#
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-adb_ver="3.8.12"
+adb_ver="3.8.14"
adb_basever=""
adb_enabled=0
adb_debug=0
adb_blacklist="/etc/adblock/adblock.blacklist"
adb_whitelist="/etc/adblock/adblock.whitelist"
adb_rtfile="/tmp/adb_runtime.json"
+adb_sorttmpdir="/tmp"
adb_portlist="53 853 5353"
adb_report=0
adb_repiface="br-lan"
f_log "err" "backup directory '${adb_backupdir}' does not exist/is not mounted yet, please create the directory or raise the 'adb_triggerdelay' to defer the adblock start"
fi
+ # check sort temp directory
+ #
+ if [ ! -d "${adb_sorttmpdir}" ]
+ then
+ f_log "err" "sort temp directory '${adb_sorttmpdir}' does not exist/is not mounted yet, please create the directory or raise the 'adb_triggerdelay' to defer the adblock start"
+ fi
+
# check fetch utility
#
case "${adb_fetchutil}" in
adb_fetchparm="${adb_fetchparm:-"-O"}"
;;
"curl")
- adb_fetchparm="${adb_fetchparm:-"--connect-timeout 10 --insecure -o"}"
+ adb_fetchparm="${adb_fetchparm:-"--connect-timeout 10 --silent --show-error --location --insecure -o"}"
ssl_lib="built-in"
;;
"aria2c")
out_rc="${?}"
if [ "${out_rc}" -eq 0 ]
then
- adb_whitelist_rset="/^([[:alnum:]_-]+\\.)+[[:alpha:]]+([[:space:]]|$)/{gsub(\"\\\\.\",\"\\\\.\",\$1);print tolower(\"^\"\$1\"\\\\|\\\\.\"\$1)}"
+ adb_whitelist_rset="/^([[:alnum:]_-]+\\.)+[[:alpha:]]+([[:space:]]|$)/{gsub(\"\\\\.\",\"\\\\.\",\$1);print tolower(\"^(|.*\\\\.)\"\$1\"$\")}"
awk "${adb_whitelist_rset}" "${adb_tmpdir}/tmp.raw.${mode}" > "${adb_tmpdir}/tmp.rem.${mode}"
out_rc="${?}"
if [ "${out_rc}" -eq 0 ] && [ -n "${adb_dnsallow}" ]
out_rc="${?}"
fi
fi
+ rm -f "${adb_tmpdir}/tmp.raw.${mode}"
fi
;;
"backup")
fi
if [ -s "${adb_tmpdir}/tmp.rem.whitelist" ]
then
- grep -vf "${adb_tmpdir}/tmp.rem.whitelist" "${adb_tmpdir}/${adb_dnsfile}" | eval "${adb_dnsdeny}" >> "${adb_dnsdir}/${adb_dnsfile}"
+ egrep -vf "${adb_tmpdir}/tmp.rem.whitelist" "${adb_tmpdir}/${adb_dnsfile}" | eval "${adb_dnsdeny}" >> "${adb_dnsdir}/${adb_dnsfile}"
else
eval "${adb_dnsdeny}" "${adb_tmpdir}/${adb_dnsfile}" >> "${adb_dnsdir}/${adb_dnsfile}"
fi
awk 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "${source}" > "${temp_tld}"
if [ "${?}" -eq 0 ]
then
- sort -u "${temp_tld}" > "${source}"
+ sort -T "${adb_sorttmpdir}" -u "${temp_tld}" > "${source}"
if [ "${?}" -eq 0 ]
then
cnt_srt="$(wc -l 2>/dev/null < "${source}")"
fi
fi
else
- sort -u "${source}" > "${temp_tld}"
+ sort -T "${adb_sorttmpdir}" -u "${source}" > "${temp_tld}"
if [ "${?}" -eq 0 ]
then
mv -f "${temp_tld}" "${source}"
mem_total="$(awk '/^MemTotal/ {print int($2/1000)}' "/proc/meminfo" 2>/dev/null)"
mem_free="$(awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo" 2>/dev/null)"
f_log "debug" "f_main ::: dns: ${adb_dns}, fetch_util: ${adb_fetchinfo}, force_dns: ${adb_forcedns}, mem_total: ${mem_total:-0}, mem_free: ${mem_free:-0}, max_queue: ${adb_maxqueue}"
-
+
# main loop
#
f_list blacklist
if [ -s "${adb_repdir}/adb_report.raw" ]
then
awk '{printf("%s\t%s\t%s\t%s\t%s\t%s\n", $4,$5,$1,$2,$3,$4)}' "${adb_repdir}/adb_report.raw" | \
- sort -ur | uniq -uf2 | awk '{currA=($6+0);currB=$6;currC=substr($6,length($6),1);
- if(reqA==currB){reqA=0;printf("%s\t%s\n",d,$2)}else if(currC=="+"){reqA=currA;d=$3"\t"$4"\t"$5"\t"$2}}' | sort -ur > "${adb_repdir}/adb_report"
+ sort -T "${adb_sorttmpdir}" -ur | uniq -uf2 | awk '{currA=($6+0);currB=$6;currC=substr($6,length($6),1);
+ if(reqA==currB){reqA=0;printf("%s\t%s\n",d,$2)}else if(currC=="+"){reqA=currA;d=$3"\t"$4"\t"$5"\t"$2}}' | sort -T "${adb_sorttmpdir}" -ur > "${adb_repdir}/adb_report"
fi
if [ -s "${adb_repdir}/adb_report" ]
total="$(wc -l < "${adb_repdir}/adb_report")"
blocked="$(awk '{if($5=="NX")print $4}' "${adb_repdir}/adb_report" | wc -l)"
percent="$(awk -v t="${total}" -v b="${blocked}" 'BEGIN{printf("%.2f %s\n",b/t*100, "%")}')"
- rep_clients="$(awk '{print $3}' "${adb_repdir}/adb_report" | sort | uniq -c | sort -r | awk '{ORS=" ";if(NR<=10) printf("%s_%s ",$1,$2)}')"
- rep_domains="$(awk '{if($5!="NX")print $4}' "${adb_repdir}/adb_report" | sort | uniq -c | sort -r | awk '{ORS=" ";if(NR<=10)printf("%s_%s ",$1,$2)}')"
- rep_blocked="$(awk '{if($5=="NX")print $4}' "${adb_repdir}/adb_report" | sort | uniq -c | sort -r | awk '{ORS=" ";if(NR<=10)printf("%s_%s ",$1,$2)}')"
+ rep_clients="$(awk '{print $3}' "${adb_repdir}/adb_report" | sort -T "${adb_sorttmpdir}" | uniq -c | sort -T "${adb_sorttmpdir}" -r | awk '{ORS=" ";if(NR<=10) printf("%s_%s ",$1,$2)}')"
+ rep_domains="$(awk '{if($5!="NX")print $4}' "${adb_repdir}/adb_report" | sort -T "${adb_sorttmpdir}" | uniq -c | sort -T "${adb_sorttmpdir}" -r | awk '{ORS=" ";if(NR<=10)printf("%s_%s ",$1,$2)}')"
+ rep_blocked="$(awk '{if($5=="NX")print $4}' "${adb_repdir}/adb_report" | sort -T "${adb_sorttmpdir}" | uniq -c | sort -T "${adb_sorttmpdir}" -r | awk '{ORS=" ";if(NR<=10)printf("%s_%s ",$1,$2)}')"
> "${adb_repdir}/adb_report.json"
json_load_file "${adb_repdir}/adb_report.json" >/dev/null 2>&1
PKG_NAME:=addrwatch
PKG_VERSION:=1.0.1
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/fln/addrwatch/tar.gz/v$(PKG_VERSION)?
--- /dev/null
+--- a/src/addrwatch.c
++++ b/src/addrwatch.c
+@@ -4,6 +4,7 @@
+ #include <signal.h>
+ #include <strings.h>
+ #include <unistd.h>
++#include <limits.h>
+ #include <pwd.h>
+ #include <grp.h>
+ #include <argp.h>
PKG_NAME:=apfree-wifidog
PKG_VERSION:=3.11.1716
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/liudf0716/apfree_wifidog.git
procd_close_instance
}
-status() {
+status_service() {
/usr/bin/wdctlx status
}
PKG_NAME:=aria2
PKG_VERSION:=1.35.0
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://github.com/aria2/aria2/releases/download/release-$(PKG_VERSION)/
PKG_HASH:=1e2b7fd08d6af228856e51c07173cfcf987528f1ac97e04c5af4a47642617dfd
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
-PKG_USE_MIPS16:=0
PKG_MAINTAINER:=Imre Kaloz <kaloz@openwrt.org>, \
Hsing-Wang Liao <kuoruan@gmail.com>
include $(TOPDIR)/rules.mk
PKG_NAME:=ariang
-PKG_VERSION:=1.1.1
+PKG_VERSION:=1.1.4
PKG_RELEASE:=1
PKG_SOURCE_URL:=https://codeload.github.com/mayswind/AriaNg-DailyBuild/tar.gz/$(PKG_VERSION)?
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_HASH:=48f3f737a6a79ab140f6bc75b0b6fd377ccbb75c7b7260b38ad4e64dee97d9e8
+PKG_HASH:=0a591564ffb863d5ce55694d26ad63934d364b9408119c191a2f8276f286f2b6
PKG_BUILD_DIR:=$(BUILD_DIR)/AriaNg-DailyBuild-$(PKG_VERSION)
PKG_LICENSE:=MIT
include $(TOPDIR)/rules.mk
PKG_NAME:=arp-scan
-PKG_VERSION:=1.9.6
+PKG_VERSION:=1.9.7
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/royhills/arp-scan/tar.gz/$(PKG_VERSION)?
-PKG_HASH:=971b45c3369816467994797fbcd0076eb8f0ffb9c42764ea6dba25ab3fd490da
+PKG_HASH:=e03c36e4933c655bd0e4a841272554a347cd0136faf42c4a6564059e0761c039
PKG_MAINTAINER:=Sergey Urushkin <urusha.v1.0@gmail.com>
PKG_LICENSE:=GPL-3.0-or-later
include $(TOPDIR)/rules.mk
PKG_NAME:=banip
-PKG_VERSION:=0.3.10
+PKG_VERSION:=0.3.11
PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
then
f_log "info" "log/banIP service started"
"${ban_logread}" -f -e "${ban_sshdaemon}\|luci: failed login" | \
- { grep -qE "Exit before auth|luci: failed login|[0-9]+ \[preauth\]$"; [ $? -eq 0 ] && /etc/init.d/banip refresh; }
+ { grep -q "Exit before auth\|luci: failed login\|error: maximum authentication attempts exceeded"; [ $? -eq 0 ] && /etc/init.d/banip refresh; }
else
f_log "err" "can't start log/banIP service"
fi
#
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-ban_ver="0.3.10"
+ban_ver="0.3.11"
ban_basever=""
ban_enabled=0
ban_automatic="1"
#
if [ -z "${ban_sshdaemon}" ]
then
- utils="dropbear sshd"
+ utils="sshd dropbear"
for util in ${utils}
do
if [ -x "$(command -v "${util}")" ]
then
- ban_sshdaemon="${util}"
- break
+ if [ "$("/etc/init.d/${util}" enabled; printf "%u" ${?})" -eq 0 ]
+ then
+ ban_sshdaemon="${util}"
+ break
+ fi
fi
done
fi
local src_name src_on src_url src_rset src_setipv src_settype src_ruletype src_cat src_log src_addon src_ts src_rc
local wan_input wan_forward lan_input lan_forward target_src target_dst ssh_log luci_log
- ssh_log="$(logread -e "${ban_sshdaemon}" | grep -o "${ban_sshdaemon}.*" | sed 's/:[0-9]*$//g')"
+ if [ "${ban_sshdaemon}" = "dropbear" ]
+ then
+ ssh_log="$(logread -e "${ban_sshdaemon}" | grep -o "${ban_sshdaemon}.*" | sed 's/:[0-9]*$//g')"
+ elif [ "${ban_sshdaemon}" = "sshd" ]
+ then
+ ssh_log="$(logread -e "${ban_sshdaemon}" | grep -o "${ban_sshdaemon}.*" | sed 's/ port.*$//g')"
+ fi
luci_log="$(logread -e "luci: failed login" | grep -o "luci:.*")"
mem_total="$(awk '/^MemTotal/ {print int($2/1000)}' "/proc/meminfo" 2>/dev/null)"
mem_free="$(awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo" 2>/dev/null)"
done
elif [ "${ban_sshdaemon}" = "sshd" ]
then
- src_addon="$(printf "%s\\n" "${ssh_log}" | grep -E "[0-9]+ \[preauth\]$" | awk 'match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}$/){ORS=" ";print substr($0,RSTART,RLENGTH)}')"
+ src_addon="$(printf "%s\\n" "${ssh_log}" | grep -F "error: maximum authentication attempts exceeded" | awk 'match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}$/){ORS=" ";print substr($0,RSTART,RLENGTH)}')"
fi
src_addon="${src_addon} $(printf "%s\\n" "${luci_log}" | awk 'match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}$/){ORS=" ";print substr($0,RSTART,RLENGTH)}')"
;;
done
elif [ "${ban_sshdaemon}" = "sshd" ]
then
- src_addon="$(printf "%s\\n" "${ssh_log}" | grep -E "[0-9]+ \[preauth\]$" | awk 'match($0,/(([0-9A-f]{0,4}::?){1,7}[0-9A-f]{0,4}$)/){ORS=" ";print substr($0,RSTART,RLENGTH)}')"
+ src_addon="$(printf "%s\\n" "${ssh_log}" | grep -F "error: maximum authentication attempts exceeded" | awk 'match($0,/(([0-9A-f]{0,4}::?){1,7}[0-9A-f]{0,4}$)/){ORS=" ";print substr($0,RSTART,RLENGTH)}')"
fi
src_addon="${src_addon} $(printf "%s\\n" "${luci_log}" | awk 'match($0,/(([0-9A-f]{0,4}::?){1,7}[0-9A-f]{0,4}$)/){ORS=" ";print substr($0,RSTART,RLENGTH)}')"
;;
PKG_NAME:=bfdd
PKG_SOURCE_DATE:=2019-08-22
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE_VERSION:=c54534beb524afc3972039f57b56ec65332b43f7
PKG_SOURCE_URL:=https://codeload.github.com/rzalamena/bfdd/tar.gz/$(PKG_SOURCE_VERSION)?
/etc/bfdd/bfdd.json
endef
+TARGET_CFLAGS += -D_GNU_SOURCE
+
define Package/bfdd/install
$(INSTALL_DIR) \
$(1)/usr/sbin \
--- /dev/null
+diff --git a/bfd_packet.c b/bfd_packet.c
+index e8f99f9..2c9fa91 100644
+--- a/bfd_packet.c
++++ b/bfd_packet.c
+@@ -29,6 +29,8 @@
+ #define _UAPI_IPV6_H
+ #endif /* _UAPI_IPV6_H */
+
++#define _GNU_SOURCE
++
+ #include <linux/filter.h>
+ #include <linux/if_ether.h>
+ #include <linux/if_packet.h>
include $(TOPDIR)/rules.mk
PKG_NAME:=cgi-io
-PKG_RELEASE:=14
+PKG_RELEASE:=16
PKG_LICENSE:=GPL-2.0-or-later
$(LN) ../../usr/libexec/cgi-io $(1)/www/cgi-bin/cgi-upload
$(LN) ../../usr/libexec/cgi-io $(1)/www/cgi-bin/cgi-download
$(LN) ../../usr/libexec/cgi-io $(1)/www/cgi-bin/cgi-backup
+ $(LN) ../../usr/libexec/cgi-io $(1)/www/cgi-bin/cgi-exec
endef
$(eval $(call BuildPackage,cgi-io))
return -1;
default:
+ close(fds[1]);
+
now = time(NULL);
strftime(datestr, sizeof(datestr) - 1, "%Y-%m-%d", localtime(&now));
waitpid(pid, &status, 0);
+ close(fds[0]);
+
+ return 0;
+ }
+}
+
+
+static const char *
+lookup_executable(const char *cmd)
+{
+ size_t plen = 0, clen = strlen(cmd) + 1;
+ static char path[PATH_MAX];
+ char *search, *p;
+ struct stat s;
+
+ if (!stat(cmd, &s) && S_ISREG(s.st_mode))
+ return cmd;
+
+ search = getenv("PATH");
+
+ if (!search)
+ search = "/bin:/usr/bin:/sbin:/usr/sbin";
+
+ p = search;
+
+ do {
+ if (*p != ':' && *p != '\0')
+ continue;
+
+ plen = p - search;
+
+ if ((plen + clen) >= sizeof(path))
+ continue;
+
+ strncpy(path, search, plen);
+ sprintf(path + plen, "/%s", cmd);
+
+ if (!stat(path, &s) && S_ISREG(s.st_mode))
+ return path;
+
+ search = p + 1;
+ } while (*p++);
+
+ return NULL;
+}
+
+static char **
+parse_command(const char *cmdline)
+{
+ const char *p = cmdline, *s;
+ char **argv = NULL, *out;
+ size_t arglen = 0;
+ int argnum = 0;
+ bool esc;
+
+ while (isspace(*cmdline))
+ cmdline++;
+
+ for (p = cmdline, s = p, esc = false; p; p++) {
+ if (esc) {
+ esc = false;
+ }
+ else if (*p == '\\' && p[1] != 0) {
+ esc = true;
+ }
+ else if (isspace(*p) || *p == 0) {
+ if (p > s) {
+ argnum += 1;
+ arglen += sizeof(char *) + (p - s) + 1;
+ }
+
+ s = p + 1;
+ }
+
+ if (*p == 0)
+ break;
+ }
+
+ if (arglen == 0)
+ return NULL;
+
+ argv = calloc(1, arglen + sizeof(char *));
+
+ if (!argv)
+ return NULL;
+
+ out = (char *)argv + sizeof(char *) * (argnum + 1);
+ argv[0] = out;
+
+ for (p = cmdline, s = p, esc = false, argnum = 0; p; p++) {
+ if (esc) {
+ esc = false;
+ *out++ = *p;
+ }
+ else if (*p == '\\' && p[1] != 0) {
+ esc = true;
+ }
+ else if (isspace(*p) || *p == 0) {
+ if (p > s) {
+ *out++ = ' ';
+ argv[++argnum] = out;
+ }
+
+ s = p + 1;
+ }
+ else {
+ *out++ = *p;
+ }
+
+ if (*p == 0)
+ break;
+ }
+
+ argv[argnum] = NULL;
+ out[-1] = 0;
+
+ return argv;
+}
+
+static int
+main_exec(int argc, char **argv)
+{
+ char *fields[] = { "sessionid", NULL, "command", NULL, "filename", NULL, "mimetype", NULL };
+ int i, devnull, status, fds[2];
+ bool allowed = false;
+ ssize_t len = 0;
+ const char *exe;
+ char *p, **args;
+ pid_t pid;
+
+ postdecode(fields, 4);
+
+ if (!fields[1] || !session_access(fields[1], "cgi-io", "exec", "read"))
+ return failure(403, 0, "Exec permission denied");
+
+ for (p = fields[5]; p && *p; p++)
+ if (!isalnum(*p) && !strchr(" ()<>@,;:[]?.=%-", *p))
+ return failure(400, 0, "Invalid characters in filename");
+
+ for (p = fields[7]; p && *p; p++)
+ if (!isalnum(*p) && !strchr(" .;=/-", *p))
+ return failure(400, 0, "Invalid characters in mimetype");
+
+ args = fields[3] ? parse_command(fields[3]) : NULL;
+
+ if (!args)
+ return failure(400, 0, "Invalid command parameter");
+
+ /* First check if we find an ACL match for the whole cmdline ... */
+ allowed = session_access(fields[1], "file", args[0], "exec");
+
+ /* Now split the command vector... */
+ for (i = 1; args[i]; i++)
+ args[i][-1] = 0;
+
+ /* Find executable... */
+ exe = lookup_executable(args[0]);
+
+ if (!exe) {
+ free(args);
+ return failure(404, 0, "Executable not found");
+ }
+
+ /* If there was no ACL match, check for a match on the executable */
+ if (!allowed && !session_access(fields[1], "file", exe, "exec")) {
+ free(args);
+ return failure(403, 0, "Access to command denied by ACL");
+ }
+
+ if (pipe(fds)) {
+ free(args);
+ return failure(500, errno, "Failed to spawn pipe");
+ }
+
+ switch ((pid = fork()))
+ {
+ case -1:
+ free(args);
close(fds[0]);
close(fds[1]);
+ return failure(500, errno, "Failed to fork process");
+
+ case 0:
+ devnull = open("/dev/null", O_RDWR);
+
+ if (devnull > -1) {
+ dup2(devnull, 0);
+ dup2(devnull, 2);
+ close(devnull);
+ }
+ else {
+ close(0);
+ close(2);
+ }
+
+ dup2(fds[1], 1);
+ close(fds[0]);
+ close(fds[1]);
+
+ if (chdir("/") < 0) {
+ free(args);
+ return failure(500, errno, "Failed chdir('/')");
+ }
+
+ if (execv(exe, args) < 0) {
+ free(args);
+ return failure(500, errno, "Failed execv(...)");
+ }
+
+ return -1;
+
+ default:
+ close(fds[1]);
+
+ printf("Status: 200 OK\r\n");
+ printf("Content-Type: %s\r\n",
+ fields[7] ? fields[7] : "application/octet-stream");
+
+ if (fields[5])
+ printf("Content-Disposition: attachment; filename=\"%s\"\r\n",
+ fields[5]);
+
+ printf("\r\n");
+ fflush(stdout);
+
+ do {
+ len = splice(fds[0], NULL, 1, NULL, READ_BLOCK, SPLICE_F_MORE);
+ } while (len > 0);
+
+ waitpid(pid, &status, 0);
+
+ close(fds[0]);
+ free(args);
return 0;
}
return main_download(argc, argv);
else if (strstr(argv[0], "cgi-backup"))
return main_backup(argc, argv);
+ else if (strstr(argv[0], "cgi-exec"))
+ return main_exec(argc, argv);
return -1;
}
PKG_SOURCE_URL:=https://download.samba.org/pub/linux-cifs/cifs-utils/
PKG_HASH:=18d8f1bf92c13c4d611502dbd6759e3a766ddc8467ec8a2eda3f589e40b9ac9c
-PKG_MAINTAINER:=Florian Fainelli <florian@openwrt.org>
+PKG_MAINTAINER:=
PKG_LICENSE:=GPL-3.0
PKG_LICENSE_FILES:=COPYING
PKG_CPE_ID:=cpe:/a:debian:cifs-utils
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/cifsd-team/cifsd-tools.git
-PKG_SOURCE_DATE:=2019-11-25
-PKG_SOURCE_VERSION:=49d0c40129fe22161999ffb7e059b90089f23078
-PKG_MIRROR_HASH:=cd3702f1387ab643233200dcf5c244989b6d6efa196c69e842791e434eb3eea7
+PKG_SOURCE_DATE:=2019-11-27
+PKG_SOURCE_VERSION:=06fd4153a5d5af1f96a20234f397bd149a8e4832
+PKG_MIRROR_HASH:=2849d2af471e327abc8d67afc91ca767c410e2b307d6554531a0b387d9ad909a
PKG_MAINTAINER:=Andy Walsh <andy.walsh44+github@gmail.com>
PKG_LICENSE:=GPL-2.0-or-later
$(INSTALL_BIN) ./files/cifsd.init $(1)/etc/init.d/cifsd
# copy examples until we have a wiki page
$(INSTALL_DATA) ./files/cifsd.config.example $(1)/etc/cifs/
- $(INSTALL_DATA) ./files/smb.conf.help $(1)/etc/cifs/
+ $(INSTALL_DATA) $(PKG_BUILD_DIR)/Documentation/configuration.txt $(1)/etc/cifs/
endef
define Package/cifsd-tools/conffiles
config share
option name 'testshare'
option path '/tmp'
+ option read_only 'no'
option guest_ok 'yes'
option create_mask '0666'
option dir_mask '0777'
- option writeable 'yes'
option force_root '1'
[ -n "$browseable" ] && printf "\tbrowseable = %s\n" "$browseable"
[ -n "$read_only" ] && printf "\tread only = %s\n" "$read_only"
- # possible upstream bug?
- if [ "$read_only" = "no" ]; then
- printf "\twriteable = yes\n"
- else
- [ -n "$writeable" ] && printf "\twriteable = %s\n" "$writeable"
- fi
+ [ -n "$writeable" ] && printf "\twriteable = %s\n" "$writeable"
+
[ -n "$guest_ok" ] && printf "\tguest ok = %s\n" "$guest_ok"
[ -n "$inherit_owner" ] && printf "\tinherit owner = %s\n" "$inherit_owner"
exit 1
fi
+ if [ -e /sys/module/cifsd ]; then
+ if [ -e /sys/class/cifsd-control/kill_server ]; then
+ # upstream "BUG": ensure changes in smb.conf are reflected on a running kernel-server
+ echo hard > /sys/class/cifsd-control/kill_server
+ # we need a extra timeout for the reset
+ sleep 5
+ fi
+ fi
+
modprobe cifsd 2> /dev/null
if [ ! -e /sys/module/cifsd ]; then
logger -t 'cifsd' "modprobe of cifsd module failed, can\'t start cifsd!"
logger -t 'cifsd' "Starting CIFS/SMB userspace service."
procd_open_instance
procd_set_param command /usr/sbin/cifsd --n
+ procd_set_param file /var/etc/cifs/smb.conf
procd_close_instance
}
{
logger -t 'cifsd' "Stopping CIFSD userspace service."
killall cifsd > /dev/null 2>&1
- sleep 1
- [ -e /sys/class/cifsd-control/kill_server ] && echo hard > /sys/class/cifsd-control/kill_server
- sleep 2
+
+ [ -e /sys/module/cifsd ] && rmmod cifsd > /dev/null 2>&1
+ # With open smb connections rmmod is not possible, without waiting for the long 'ipc timeout', so we use 'kill_server'!
+ if [ -e /sys/module/cifsd ]; then
+ logger -t 'cifsd' "triggering kill_server"
+ if [ -e /sys/class/cifsd-control/kill_server ]; then
+ echo hard > /sys/class/cifsd-control/kill_server
+ # we need a extra timeout for the reset
+ sleep 5
+ fi
+ fi
+ # next try
[ -e /sys/module/cifsd ] && rmmod cifsd > /dev/null 2>&1
- # With open smb connections rmmod takes longer
+ # check again
if [ -e /sys/module/cifsd ]; then
- sleep 5
- rmmod cifsd > /dev/null 2>&1
+ # wait more...
+ sleep 3
+ fi
+ # last try
+ [ -e /sys/module/cifsd ] && rmmod cifsd > /dev/null 2>&1
+
+ if [ -e /sys/module/cifsd ]; then
+ logger -t 'cifsd' "module still loaded after 8s timeout"
fi
[ -f /tmp/cifsd.lock ] && rm /tmp/cifsd.lock
}
-reload_service() {
- stop_service "$@"
- sleep 1
- start_service "$@"
-}
+# reload_service() {
+ # restart "$@"
+# }
workgroup = |WORKGROUP|
interfaces = |INTERFACES|
bind interfaces only = yes
- ipc timeout = 8
+ ipc timeout = 20
deadtime = 15
map to guest = Bad User
include $(TOPDIR)/rules.mk
PKG_NAME:=coova-chilli
-PKG_VERSION:=1.4
-PKG_RELEASE:=11
+PKG_VERSION:=1.5
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/coova/coova-chilli/tar.gz/$(PKG_VERSION)?
-PKG_HASH:=987647a4c8efe7b1e2d7108d56068e3bd7830d326680f0eaa2c705e4c59c46d9
+PKG_HASH:=75e15fd00a870b8a95df1440977c688a05a109f90b57bf679b931101d427d0fb
PKG_MAINTAINER:=Jaehoon You <teslamint@gmail.com>
PKG_LICENSE:=GPL-2.0-or-later
+++ /dev/null
---- a/src/system.h
-+++ b/src/system.h
-@@ -112,6 +112,11 @@
- #include <signal.h>
- #endif
-
-+#ifdef HAVE_SYS_SYSINFO_H
-+#define _LINUX_SYSINFO_H
-+#include <sys/sysinfo.h>
-+#endif
-+
- #ifdef HAVE_INTTYPES_H
- #define __STDC_FORMAT_MACROS
- #include <inttypes.h>
-@@ -129,15 +134,6 @@
- #include <linux/un.h>
- #endif
-
--#ifdef HAVE_SYS_SYSINFO_H
--#include <sys/sysinfo.h>
--#else
--#ifdef HAVE_LINUX_SYSINFO_H
--#define _LINUX_KERNEL_H
--#include <linux/sysinfo.h>
--#endif
--#endif
--
- #elif defined (__FreeBSD__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
- #include <net/if.h>
- #include <net/bpf.h>
--- /dev/null
+--- a/configure.ac
++++ b/configure.ac
+@@ -397,7 +397,7 @@ AC_ARG_WITH([cyassl],
+ [AS_HELP_STRING([--with-cyassl], [enable support for cyassl])],[],[with_cyassl=no])
+
+ AS_IF([test x"$with_cyassl" != xno],
+- [AC_CHECK_LIB([cyassl], [CyaSSL_Init],
++ [AC_CHECK_LIB([cyassl], [wolfSSL_Init],
+ [AC_SUBST([LIBSSL], ["-lcyassl"])
+ AC_DEFINE([HAVE_CYASSL], [1],
+ [Define if you have cyassl])
+--- a/src/ippool.c
++++ b/src/ippool.c
+@@ -35,6 +35,7 @@ int ippool_print(int fd, struct ippool_t *this) {
+ char * sep = "-- %-15s ------------------------------------------------------------\n";
+
+ #define ERR 0
++#undef USED /* defined in <wolfssl/wolfcrypt/integer.h> */
+ #define USED 1
+ #define FREE 2
+ #define LIST 3
+--- a/src/md5.h
++++ b/src/md5.h
+@@ -35,7 +35,6 @@
+ #define MD5Update MD5_Update
+ #define MD5Final MD5_Final
+
+-typedef struct CYASSL_MD5_CTX MD5_CTX;
+ #else
+
+ struct MD5Context {
+--- a/src/ssl.c
++++ b/src/ssl.c
+@@ -131,7 +131,7 @@ _openssl_env_init(openssl_env *env, char *engine, int server) {
+ */
+ const long options = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION;
+ env->meth = SSLv23_method();
+- env->ctx = SSL_CTX_new(env->meth);
++ env->ctx = SSL_CTX_new((void *)env->meth);
+ SSL_CTX_set_options(env->ctx, options);
+ if (_options.sslciphers) {
+ SSL_CTX_set_cipher_list(env->ctx, _options.sslciphers);
+--- a/src/ssl.h
++++ b/src/ssl.h
+@@ -48,6 +48,8 @@ typedef struct {
+ #include <time.h>
+ #include <string.h>
+
++#define OPENSSL_NO_ENGINE
++#include <cyassl/options.h>
+ #include <cyassl/ssl.h>
+ #include <cyassl/openssl/bio.h>
+ #include <cyassl/openssl/crypto.h>
+++ /dev/null
---- a/src/ms_chap.c
-+++ b/src/ms_chap.c
-@@ -96,18 +96,18 @@ MakeKey(u_char *key, u_char *des_key)
- des_key[6] = Get7Bits(key, 42);
- des_key[7] = Get7Bits(key, 49);
-
-- des_set_odd_parity((des_cblock *)des_key);
-+ DES_set_odd_parity((DES_cblock *)des_key);
- }
-
- static void /* IN 8 octets IN 7 octest OUT 8 octets */
- DesEncrypt(u_char *clear, u_char *key, u_char *cipher)
- {
-- des_cblock des_key;
-- des_key_schedule key_schedule;
-+ DES_cblock des_key;
-+ DES_key_schedule key_schedule;
-
- MakeKey(key, des_key);
-- des_set_key(&des_key, key_schedule);
-- des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
-+ DES_set_key(&des_key, &key_schedule);
-+ DES_ecb_encrypt((DES_cblock *)clear, (DES_cblock *)cipher, &key_schedule, 1);
- }
-
- #define LENGTH 20
---- a/src/ssl.c
-+++ b/src/ssl.c
-@@ -35,11 +35,13 @@ openssl_env * initssl() {
- if (openssl_init == 0) {
- openssl_init = 1;
- #ifdef HAVE_OPENSSL
-+#if OPENSSL_VERSION_NUMBER < 0x10100000L
- if (_options.debug) {
- SSL_load_error_strings();
- }
- SSL_library_init();
- OpenSSL_add_all_algorithms();
-+#endif
- #else
- matrixSslOpen();
- syslog(LOG_DEBUG, "%s(%d): MatrixSslOpen()", __FUNCTION__, __LINE__);
-@@ -55,11 +57,13 @@ openssl_env * initssl_cli() {
- if (openssl_init == 0) {
- openssl_init = 1;
- #ifdef HAVE_OPENSSL
-+#if OPENSSL_VERSION_NUMBER < 0x10100000L
- if (_options.debug) {
- SSL_load_error_strings();
- }
- SSL_library_init();
- OpenSSL_add_all_algorithms();
-+#endif
- #else
- matrixSslOpen();
- syslog(LOG_DEBUG, "%s(%d): MatrixSslOpen()", __FUNCTION__, __LINE__);
-@@ -132,7 +136,7 @@ _openssl_env_init(openssl_env *env, char *engine, int server) {
- if (_options.sslciphers) {
- SSL_CTX_set_cipher_list(env->ctx, _options.sslciphers);
- }
--#ifdef HAVE_OPENSSL_ENGINE
-+#ifndef OPENSSL_NO_ENGINE
- if (engine) {
- retry:
- if ((env->engine = ENGINE_by_id(engine)) == NULL) {
-@@ -609,7 +613,7 @@ openssl_env_free(openssl_env *env) {
- #endif
- #ifdef HAVE_OPENSSL
- if (env->ctx) SSL_CTX_free(env->ctx);
--#ifdef HAVE_OPENSSL_ENGINE
-+#ifndef OPENSSL_NO_ENGINE
- if (env->engine) ENGINE_free(env->engine);
- #endif
- #endif
---- a/src/ssl.h
-+++ b/src/ssl.h
-@@ -41,6 +41,7 @@ typedef struct {
- #include <openssl/ssl.h>
- #include <openssl/pem.h>
- #include <openssl/engine.h>
-+#include <openssl/err.h>
- #elif HAVE_CYASSL
- #include <stdio.h>
- #include <stdlib.h>
--- /dev/null
+From 196b783b5ea7f8d6cf57ddbd41dc1881ef47a1c4 Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Wed, 11 Dec 2019 19:33:58 -0800
+Subject: [PATCH] system.h: Fix compilation with kernel 4.19 + musl
+
+<linux/netlink.h> includes <linux/sysinfo.h> , which redefines struct sysinfo, leading to an error.
+Define the linux header as included to solve compilation.
+
+Signed-off-by: Rosen Penev <rosenp@gmail.com>
+---
+ src/system.h | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/system.h b/src/system.h
+index 257b65b..5c1aa4a 100644
+--- a/src/system.h
++++ b/src/system.h
+@@ -114,6 +114,7 @@
+
+ #ifdef HAVE_SYS_SYSINFO_H
+ #include <sys/sysinfo.h>
++#define _LINUX_SYSINFO_H
+ #else
+ #ifdef HAVE_LINUX_SYSINFO_H
+ #define _LINUX_KERNEL_H
+++ /dev/null
---- a/configure.ac
-+++ b/configure.ac
-@@ -397,7 +397,7 @@ AC_ARG_WITH([cyassl],
- [AS_HELP_STRING([--with-cyassl], [enable support for cyassl])],[],[with_cyassl=no])
-
- AS_IF([test x"$with_cyassl" != xno],
-- [AC_CHECK_LIB([cyassl], [CyaSSL_Init],
-+ [AC_CHECK_LIB([cyassl], [wolfSSL_Init],
- [AC_SUBST([LIBSSL], ["-lcyassl"])
- AC_DEFINE([HAVE_CYASSL], [1],
- [Define if you have cyassl])
---- a/src/ippool.c
-+++ b/src/ippool.c
-@@ -35,6 +35,7 @@ int ippool_print(int fd, struct ippool_t *this) {
- char * sep = "-- %-15s ------------------------------------------------------------\n";
-
- #define ERR 0
-+#undef USED /* defined in <wolfssl/wolfcrypt/integer.h> */
- #define USED 1
- #define FREE 2
- #define LIST 3
---- a/src/md5.h
-+++ b/src/md5.h
-@@ -35,7 +35,6 @@
- #define MD5Update MD5_Update
- #define MD5Final MD5_Final
-
--typedef struct CYASSL_MD5_CTX MD5_CTX;
- #else
-
- struct MD5Context {
---- a/src/ssl.c
-+++ b/src/ssl.c
-@@ -131,7 +131,7 @@ _openssl_env_init(openssl_env *env, char *engine, int server) {
- */
- const long options = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION;
- env->meth = SSLv23_method();
-- env->ctx = SSL_CTX_new(env->meth);
-+ env->ctx = SSL_CTX_new((void *)env->meth);
- SSL_CTX_set_options(env->ctx, options);
- if (_options.sslciphers) {
- SSL_CTX_set_cipher_list(env->ctx, _options.sslciphers);
---- a/src/ssl.h
-+++ b/src/ssl.h
-@@ -48,6 +48,8 @@ typedef struct {
- #include <time.h>
- #include <string.h>
-
-+#define OPENSSL_NO_ENGINE
-+#include <cyassl/options.h>
- #include <cyassl/ssl.h>
- #include <cyassl/openssl/bio.h>
- #include <cyassl/openssl/crypto.h>
+++ /dev/null
---- a/src/redir.c
-+++ b/src/redir.c
-@@ -3358,14 +3358,17 @@ int redir_main(struct redir_t *redir,
- }
-
- #define redir_memcopy(msgtype) \
-+ do { \
- redir_challenge(challenge); \
- redir_chartohex(challenge, hexchal, REDIR_MD5LEN); \
- msg.mtype = msgtype; \
- memcpy(conn.s_state.redir.uamchal, challenge, REDIR_MD5LEN); \
-- if (_options.debug) syslog(LOG_DEBUG, "%s(%d): ---->>> resetting challenge: %s", __FUNCTION__, __LINE__, hexchal)
-+ if (_options.debug) syslog(LOG_DEBUG, "%s(%d): ---->>> resetting challenge: %s", __FUNCTION__, __LINE__, hexchal); \
-+ } while (0)
-
- #ifdef USING_IPC_UNIX
- #define redir_msg_send(msgopt) \
-+ do { \
- msg.mdata.opt = msgopt; \
- memcpy(&msg.mdata.address, address, sizeof(msg.mdata.address)); \
- memcpy(&msg.mdata.baddress, baddress, sizeof(msg.mdata.baddress)); \
-@@ -3375,9 +3378,11 @@ int redir_main(struct redir_t *redir,
- syslog(LOG_ERR, "%s: write() failed! msgfd=%d type=%ld len=%d", \
- strerror(errno), redir->msgfd, msg.mtype, (int)sizeof(msg.mdata)); \
- return redir_main_exit(&socket, forked, rreq); \
-- }
-+ } \
-+ } while (0)
- #else
- #define redir_msg_send(msgopt) \
-+ do { \
- msg.mdata.opt = msgopt; \
- memcpy(&msg.mdata.address, address, sizeof(msg.mdata.address)); \
- memcpy(&msg.mdata.baddress, baddress, sizeof(msg.mdata.baddress)); \
-@@ -3387,7 +3392,8 @@ int redir_main(struct redir_t *redir,
- syslog(LOG_ERR, "%s: msgsnd() failed! msgid=%d type=%ld len=%d", \
- strerror(errno), redir->msgid, msg.mtype, (int)sizeof(msg.mdata)); \
- return redir_main_exit(&socket, forked, rreq); \
-- }
-+ } \
-+ } while (0)
- #endif
-
- /*
PKG_VERSION:=2.7.8
# Release == build
# increase on changes of services files or tld_names.dat
-PKG_RELEASE:=12
+PKG_RELEASE:=14
PKG_LICENSE:=GPL-2.0
PKG_MAINTAINER:=
endef
# shown in LuCI package description
define Package/ddns-scripts/description
- Dynamic DNS Client scripts (with IPv6 support) - Info: http://wiki.openwrt.org/doc/howto/ddns.client
+ Dynamic DNS Client scripts (with IPv6 support) - Info: https://openwrt.org/docs/guide-user/services/ddns/client
endef
# shown in menuconfig <Help>
define Package/ddns-scripts/config
- log file support
- support to run once
Version: $(PKG_VERSION)-$(PKG_RELEASE)
- Info : http://wiki.openwrt.org/doc/howto/ddns.client
+ Info : https://openwrt.org/docs/guide-user/services/ddns/client
endef
###### *************************************************************************
#
-# Please read http://wiki.openwrt.org/doc/uci/ddns
+# Please read https://openwrt.org/docs/guide-user/base-system/ddns
#
config ddns "global"
option ddns_dateformat "%F %R"
. /lib/functions/network.sh
# GLOBAL VARIABLES #
-VERSION="2.7.8-11"
+VERSION="2.7.8-14"
SECTION_ID="" # hold config's section name
VERBOSE=0 # default mode is log to console, but easily changed with parameter
MYPROG=$(basename $0) # my program call name
"able.or.kr" "http://able.or.kr/ddns/src/update.php?hostname=[DOMAIN]&myip=[IP]&ddnsuser=[USERNAME]&pwd=[PASSWORD]"
-"afraid.org-basicauth" "http://[USERNAME]:[PASSWORD]@freedns.afraid.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
-"afraid.org-keyauth" "http://freedns.afraid.org/dynamic/update.php?[PASSWORD]&address=[IP]"
-"afraid.org-v2-basic" "http://[USERNAME]:[PASSWORD]@sync.afraid.org/u/?h=[DOMAIN]&ip=[IP]"
-"afraid.org-v2-token" "http://sync.afraid.org/u/[PASSWORD]/?address=[IP]"
+"afraid.org-basicauth" "https://[USERNAME]:[PASSWORD]@freedns.afraid.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
+"afraid.org-keyauth" "https://freedns.afraid.org/dynamic/update.php?[PASSWORD]&address=[IP]"
+"afraid.org-v2-basic" "https://[USERNAME]:[PASSWORD]@sync.afraid.org/u/?h=[DOMAIN]&ip=[IP]"
+"afraid.org-v2-token" "https://sync.afraid.org/u/[PASSWORD]/?address=[IP]"
"all-inkl.com" "http://[USERNAME]:[PASSWORD]@dyndns.kasserver.com/?myip=[IP]"
#.no-ip.com / noip.com !!! Please install additional package "ddns-scripts_no-ip_com"
#.route53-v1 !!! Please install additional package "ddns-scripts_route53-v1"
-"afraid.org-basicauth" "http://[USERNAME]:[PASSWORD]@freedns.afraid.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
-"afraid.org-keyauth" "http://freedns.afraid.org/dynamic/update.php?[PASSWORD]&address=[IP]"
-"afraid.org-v2-basic" "http://[USERNAME]:[PASSWORD]@v6.sync.afraid.org/u/?h=[DOMAIN]&ip=[IP]"
-"afraid.org-v2-token" "http://v6.sync.afraid.org/u/[PASSWORD]/?address=[IP]"
+"afraid.org-basicauth" "https://[USERNAME]:[PASSWORD]@freedns.afraid.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
+"afraid.org-keyauth" "https://freedns.afraid.org/dynamic/update.php?[PASSWORD]&address=[IP]"
+"afraid.org-v2-basic" "https://[USERNAME]:[PASSWORD]@v6.sync.afraid.org/u/?h=[DOMAIN]&ip=[IP]"
+"afraid.org-v2-token" "https://v6.sync.afraid.org/u/[PASSWORD]/?address=[IP]"
"all-inkl.com" "http://[USERNAME]:[PASSWORD]@dyndns.kasserver.com/?myip=[IP]"
include $(TOPDIR)/rules.mk
PKG_NAME:=dnscrypt-proxy2
-PKG_VERSION:=2.0.29
+PKG_VERSION:=2.0.34
PKG_RELEASE:=1
PKG_SOURCE:=dnscrypt-proxy-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://codeload.github.com/jedisct1/dnscrypt-proxy/tar.gz/$(PKG_VERSION)?
-PKG_HASH:=5c18f0c9d6a89b64d532c98e2bd976f98211a715399c7a1ee81a22c5485673b9
+PKG_SOURCE_URL:=https://codeload.github.com/DNSCrypt/dnscrypt-proxy/tar.gz/$(PKG_VERSION)?
+PKG_HASH:=38ec7df2bdeff6d094d8975c0005c1d896a63b529cba417381b63fcf51d42303
PKG_BUILD_DIR:=$(BUILD_DIR)/dnscrypt-proxy-$(PKG_VERSION)
PKG_MAINTAINER:=Josef Schlehofer <josef.schlehofer@nic.cz>
PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0
-GO_PKG:=github.com/jedisct1/dnscrypt-proxy
+GO_PKG:=github.com/DNSCrypt/dnscrypt-proxy
include $(INCLUDE_DIR)/package.mk
include ../../lang/golang/golang-package.mk
SECTION:=net
CATEGORY:=Network
TITLE:=Flexible DNS proxy with encrypted DNS protocols
- URL:=https://github.com/jedisct1/dnscrypt-proxy
+ URL:=https://github.com/DNSCrypt/dnscrypt-proxy
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
CONFLICTS:=dnscrypt-proxy
endef
include $(TOPDIR)/rules.mk
PKG_NAME:=dnsdist
-PKG_VERSION:=1.3.3
+PKG_VERSION:=1.4.0
PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://downloads.powerdns.com/releases/
-PKG_HASH:=9fb24f9032025955169f3c6e9b0a05b6aa9d6441ec47da08d22de1c1aa23e8cf
+PKG_HASH:=a336fa2c3eb381c2464d9d9790014fd6d4505029ed2c1b73ee1dc9115a2f1dc0
PKG_MAINTAINER:=James Taylor <james@jtaylor.id.au>
PKG_LICENSE:=GPL-2.0-only
PKG_INSTALL:=1
+PKG_BUILD_DEPENDS:=protobuf/host
+
PKG_CONFIG_DEPENDS:= \
CONFIG_DNSDIST_GNUTLS \
CONFIG_DNSDIST_OPENSSL
include $(INCLUDE_DIR)/package.mk
define Package/dnsdist/config
-comment "SSL support"
-
-choice
- prompt "Selected SSL library"
- default DNSDIST_OPENSSSL
-
- config DNSDIST_OPENSSL
- bool "OpenSSL"
-
- config DNSDIST_GNUTLS
- bool "GnuTLS"
-
- config DNSDIST_NOSSL
- bool "No SSL support"
-
-endchoice
+menu "Configuration"
+ depends on PACKAGE_dnsdist
+
+ comment "SSL Support"
+ choice
+ prompt "Selected SSL library"
+ default DNSDIST_OPENSSSL
+
+ config DNSDIST_OPENSSL
+ bool "OpenSSL"
+
+ config DNSDIST_GNUTLS
+ bool "GnuTLS"
+
+ config DNSDIST_NOSSL
+ bool "No SSL support"
+
+ endchoice
+
+ comment "DNS over HTTPS/TLS Support"
+ depends on !DNSDIST_NOSSL
+
+ config DNSDIST_DNS_OVER_HTTPS
+ depends on DNSDIST_OPENSSL
+ depends on !DNSDIST_NOSSL
+ bool "DNS over HTTPS Support"
+ help
+ "Enables DNS over HTTPS Support for dnsdist"
+ default y
+
+ config DNSDIST_DNS_OVER_TLS
+ depends on !DNSDIST_NOSSL
+ bool "DNS over TLS Support"
+ help
+ "Enabled DNS over TLS Support for dnsdist"
+ default y
+endmenu
endef
define Package/dnsdist
CATEGORY:=Network
SUBMENU:=IP Addresses and Names
TITLE:=dnsdist DNS-, DOS- and abuse-aware loadbalancer
- DEPENDS:=+DNSDIST_OPENSSL:libopenssl +DNSDIST_GNUTLS:libgnutls +protobuf +re2 +libedit +libfstrm +libsodium +lua +boost +libnetsnmp +libatomic
+ DEPENDS:= \
+ +DNSDIST_DNS_OVER_HTTPS:libh2o-evloop \
+ +DNSDIST_GNUTLS:libgnutls \
+ +DNSDIST_OPENSSL:libopenssl \
+ +boost \
+ +libatomic \
+ +libcap \
+ +libedit \
+ +libfstrm \
+ +libnetsnmp \
+ +libsodium \
+ +lmdb \
+ +lua \
+ +protobuf \
+ +re2 \
+ +tinycdb
URL:=https://dnsdist.org/
endef
CONFIGURE_ARGS+= \
--enable-dnscrypt \
- $(if $(CONFIG_DNSDIST_NOSSL),,--enable-dns-over-tls) \
- --enable-fstrm \
- --enable-libsodium \
- --enable-protobuf \
- --enable-re2 \
+ --enable-dnstap \
+ --with-libsodium \
+ --with-protobuf \
+ --with-re2 \
--with-lua=lua \
--with-net-snmp \
- $(if $(CONFIG_DNSDIST_GNUTLS),--enable,--disable)-gnutls \
- $(if $(CONFIG_DNSDIST_OPENSSL),--enable,--disable)-libssl
+ $(if $(CONFIG_DNSDIST_GNUTLS),--with,--without)-gnutls \
+ $(if $(CONFIG_DNSDIST_OPENSSL),--with,--without)-libssl \
+ $(if $(CONFIG_DNSDIST_DNS_OVER_TLS),--enable-dns-over-tls,) \
+ $(if $(CONFIG_DNSDIST_DNS_OVER_HTTPS),--enable-dns-over-https,)
define Package/dnsdist/install
$(INSTALL_DIR) $(1)/etc
+++ /dev/null
-From d73bc006c62e4340ab56dd4baba5bc8eb8e1db49 Mon Sep 17 00:00:00 2001
-From: Remi Gacogne <remi.gacogne@powerdns.com>
-Date: Mon, 13 May 2019 16:01:06 +0200
-Subject: [PATCH] SNMP: Use net-snmp-config --netsnmp-agent-libs instead of
- --agent-libs
-
----
- m4/pdns_with_net_snmp.m4 | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/m4/pdns_with_net_snmp.m4 b/m4/pdns_with_net_snmp.m4
-index 8040672e6c..2da80c75fc 100644
---- a/m4/pdns_with_net_snmp.m4
-+++ b/m4/pdns_with_net_snmp.m4
-@@ -10,7 +10,7 @@ AC_DEFUN([PDNS_WITH_NET_SNMP], [
- AS_IF([test "x$with_net_snmp" != "xno"], [
- AS_IF([test "x$with_net_snmp" = "xyes" -o "x$with_net_snmp" = "xauto"], [
- AC_CHECK_PROG([NET_SNMP_CFLAGS], [net-snmp-config], [`net-snmp-config --cflags`])
-- AC_CHECK_PROG([NET_SNMP_LIBS], [net-snmp-config], [`net-snmp-config --agent-libs`])
-+ AC_CHECK_PROG([NET_SNMP_LIBS], [net-snmp-config], [`net-snmp-config --netsnmp-agent-libs`])
- AC_CHECK_DECLS([snmp_select_info2], [ : ], [ : ],
- [AC_INCLUDES_DEFAULT
- #include <net-snmp/net-snmp-config.h>
+++ /dev/null
---- a/m4/pdns_check_os.m4
-+++ b/m4/pdns_check_os.m4
-@@ -35,16 +35,21 @@
- AM_CONDITIONAL([HAVE_LINUX], [test "x$have_linux" = "xyes"])
- AM_CONDITIONAL([HAVE_SOLARIS], [test "x$have_solaris" = "xyes"])
-
-- case "$host" in
-- mips* | powerpc-* )
-- AC_MSG_CHECKING([whether the linker accepts -latomic])
-- LDFLAGS="-latomic $LDFLAGS"
-- AC_LINK_IFELSE([m4_default([],[AC_LANG_PROGRAM()])],
-- [AC_MSG_RESULT([yes])],
-- [AC_MSG_ERROR([Unable to link against libatomic, cannot continue])]
-- )
-- ;;
-- esac
-+ AC_MSG_CHECKING([whether -latomic is needed for __atomic builtins])
-+ AC_LINK_IFELSE(
-+ [AC_LANG_PROGRAM([[#include <stdint.h>]],
-+ [[uint64_t val = 0; __atomic_add_fetch(&val, 1, __ATOMIC_RELAXED);]]
-+ )],
-+ [AC_MSG_RESULT([no])],
-+ [LIBS="$LIBS -latomic"
-+ AC_LINK_IFELSE(
-+ [AC_LANG_PROGRAM([[#include <stdint.h>]],
-+ [[uint64_t val = 0; __atomic_add_fetch(&val, 1, __ATOMIC_RELAXED);]]
-+ )],
-+ [AC_MSG_RESULT([yes])],
-+ [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, cannot continue])]
-+ )]
-+ )
-
- AC_SUBST(THREADFLAGS)
- AC_SUBST([DYNLINKFLAGS], [-export-dynamic])
+++ /dev/null
---- a/tcpiohandler.cc
-+++ b/tcpiohandler.cc
-@@ -369,8 +369,10 @@ public:
- }
-
- if (s_users.fetch_add(1) == 0) {
-+#if OPENSSL_VERSION_NUMBER < 0x10100000L
- ERR_load_crypto_strings();
- OpenSSL_add_ssl_algorithms();
-+#endif
- openssl_thread_setup();
-
- s_ticketsKeyIndex = SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
-@@ -439,6 +441,7 @@ public:
- d_tlsCtx.reset();
-
- if (s_users.fetch_sub(1) == 1) {
-+#if OPENSSL_VERSION_NUMBER < 0x10100000L
- ERR_free_strings();
-
- EVP_cleanup();
-@@ -448,6 +451,7 @@ public:
- CONF_modules_unload(1);
-
- CRYPTO_cleanup_all_ex_data();
-+#endif
- openssl_thread_cleanup();
- }
- }
include $(TOPDIR)/rules.mk
PKG_NAME:=go-ethereum
-PKG_VERSION:=1.9.6
+PKG_VERSION:=1.9.9
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/ethereum/go-ethereum/tar.gz/v${PKG_VERSION}?
-PKG_HASH:=3000f787735ee302088d17d406eafc2ec26eaffc083d876b2fa07ec7dfbb94f9
+PKG_HASH:=52fd34920841c9915d67f28c416ce7e98b654c116b03edee94f6ef06e5a8cf92
PKG_MAINTAINER:=Mislav Novakovic <mislav.novakovic@sartura.hr>
PKG_LICENSE:=GPL-3.0-or-later LGPL-3.0-or-later
include $(TOPDIR)/rules.mk
PKG_NAME:=git
-PKG_VERSION:=2.24.0
+PKG_VERSION:=2.24.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=@KERNEL/software/scm/git/
-PKG_HASH:=9f71d61973626d8b28c4cdf8e2484b4bf13870ed643fed982d68b2cfd754371b
+PKG_HASH:=723f24dce8fdd621a308b6187553fce7d5244205c065fe0a3aebd0b7c3f88562
PKG_INSTALL:=1
PKG_FIXUP:=autoreconf
PKG_BUILD_PARALLEL:=1
-PKG_CPE_ID:=cpe:/a:git:git
+PKG_CPE_ID:=cpe:/a:git-scm:git
include $(INCLUDE_DIR)/package.mk
PKG_NAME:=gnunet-fuse
-PKG_VERSION:=0.11.0
+PKG_VERSION:=0.12.0
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@GNU/gnunet
-PKG_HASH:=4ddf258336c9ce111fe71372aad0bfd792311f6d92753c29293b2cca1fe3bf16
+PKG_HASH:=4d42dc3112f36ada150b3904e207b93373c90d4fbd5a1c6415ee7f5c6a428e3b
PKG_LICENSE:=GPL-3.0
PKG_LICENSE_FILES:=COPYING
--- a/src/fuse/mutex.c
+++ b/src/fuse/mutex.c
-@@ -71,8 +71,13 @@ GNUNET_mutex_create (int isRecursive)
+@@ -68,8 +68,13 @@ GNUNET_mutex_create (int isRecursive)
if (isRecursive)
{
- #if LINUX
+ #ifdef __linux__
+#if defined(__UCLIBC__) || defined(__GLIBC__)
GNUNET_assert (0 == pthread_mutexattr_setkind_np
(&attr, PTHREAD_MUTEX_RECURSIVE_NP));
+ GNUNET_assert (0 == pthread_mutexattr_settype
+ (&attr, PTHREAD_MUTEX_RECURSIVE));
+#endif
- #elif SOMEBSD || GNUNET_freeBSD || GNUNET_freeBSD5
- GNUNET_assert (0 == pthread_mutexattr_setkind_np
+ #elif BSD || SOLARIS || OSX || WINDOWS
+ GNUNET_assert (0 == pthread_mutexattr_settype
(&attr, PTHREAD_MUTEX_RECURSIVE));
-@@ -84,11 +89,16 @@ GNUNET_mutex_create (int isRecursive)
+@@ -78,11 +83,16 @@ GNUNET_mutex_create (int isRecursive)
else
{
- #if LINUX
+ #ifdef __linux__
+#if defined(__UCLIBC__) || defined(__GLIBC__)
GNUNET_assert (0 == pthread_mutexattr_setkind_np
(&attr, PTHREAD_MUTEX_ERRORCHECK_NP));
PKG_NAME:=gnunet
-PKG_VERSION:=0.11.8
+PKG_VERSION:=0.12.0
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@GNU/gnunet
-PKG_HASH:=d21f1b7a5e0c3e1ddf062c87a302db9abb43574bb7bf8c9e8f233b5d0e6675fe
+PKG_HASH:=2184ace2960e4757969f3cd6bc0dba6f136871bf7bcca5d80a7147bde0d2e0af
PKG_LICENSE:=AGPL-3.0
PKG_LICENSE_FILES:=COPYING
include $(TOPDIR)/rules.mk
PKG_NAME:=gnurl
-PKG_VERSION:=7.65.1
-PKG_RELEASE:=1
+PKG_VERSION:=7.67.0
+PKG_RELEASE:=2
-PKG_SOURCE_URL:=https://ftp.gnu.org/gnu/gnunet
+PKG_SOURCE_URL:=@GNU/gnunet
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_HASH:=37bb87993f9219f4c76195031f1b0311afde157a1b852d54f570e3195ad7af01
+PKG_HASH:=2b972454ac3ab8c40f4dd2beeff168dde9666c473a1418f7f69194563e4caa46
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=COPYING
define Package/gnurl/Default
SECTION:=net
CATEGORY:=Network
- URL:=https://gnunet.org/gnurl
+ URL:=https://gnunet.org/en/gnurl.html
MAINTAINER:=Daniel Golle <daniel@makrotopia.org>
endef
include $(TOPDIR)/rules.mk
PKG_NAME:=haproxy
-PKG_VERSION:=2.0.9
+PKG_VERSION:=2.0.12
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://www.haproxy.org/download/2.0/src
-PKG_HASH:=35692801abfd6dde4976cb42fe5cee8aaf61959e743003426073c3141494c589
+PKG_HASH:=7fcf5adb21cd78c4161902f9fcc8d7fc97e1562319a992cbda884436ca9602fd
PKG_MAINTAINER:=Thomas Heil <heil@terminal-consulting.de>, \
Christian Lachner <gladiac@gmail.com>
#!/bin/sh
CLONEURL=https://git.haproxy.org/git/haproxy-2.0.git
-BASE_TAG=v2.0.9
+BASE_TAG=v2.0.12
TMP_REPODIR=tmprepo
PATCHESDIR=patches
--- a/Makefile
+++ b/Makefile
-@@ -327,6 +327,15 @@ ifeq ($(TARGET),linux-glibc)
+@@ -326,6 +326,15 @@ ifeq ($(TARGET),linux-glibc)
USE_GETADDRINFO)
endif
+++ /dev/null
---- a/include/common/openssl-compat.h
-+++ b/include/common/openssl-compat.h
-@@ -217,7 +217,8 @@ static inline int EVP_PKEY_base_id(EVP_PKEY *pkey)
- #define TLSEXT_signature_ecdsa 3
- #endif
-
--#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER < 0x20700000L)
-+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || \
-+ (defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x20700000L))
- #define X509_getm_notBefore X509_get_notBefore
- #define X509_getm_notAfter X509_get_notAfter
- #endif
include $(TOPDIR)/rules.mk
-PKG_NAME:=https_dns_proxy
-PKG_VERSION:=2018-04-23
-PKG_RELEASE=4
+PKG_NAME:=https-dns-proxy
+PKG_VERSION:=2019-12-03
+PKG_RELEASE=2
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
-PKG_MIRROR_HASH:=24b7e4238c37e646f33eee3a374f6b7beb5c167b9c5008cc13b51e5f1f3a44ea
-PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
-PKG_SOURCE_URL:=https://github.com/aarond10/https_dns_proxy/
PKG_SOURCE_PROTO:=git
-PKG_SOURCE_VERSION:=bea68401330e611f6e9b75cec84e2dc4e81e52de
-PKG_MAINTAINER:=Aaron Drew <aarond10@gmail.com>
+PKG_SOURCE_URL:=https://github.com/aarond10/https_dns_proxy
+PKG_SOURCE_DATE:=2019-12-03
+PKG_SOURCE_VERSION:=2adeafb67cbe8d67148219c48334856ae4f3bd75
+PKG_MIRROR_HASH:=58088baa092cd9634652d65f9b5650db88d2e102cb370710654db7b15f2f0e42
+PKG_MAINTAINER:=Stan Grishin <stangri@melmac.net>
PKG_LICENSE:=MIT
+PKG_LICENSE_FILES:=LICENSE
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk
CMAKE_OPTIONS += -DCLANG_TIDY_EXE=
-define Package/https_dns_proxy
- SECTION:=net
- CATEGORY:=Network
- TITLE:=DNS over HTTPS Proxy Server
- DEPENDS:=+libcares +libcurl +libev +ca-bundle
+define Package/https-dns-proxy
+ SECTION:=net
+ CATEGORY:=Network
+ TITLE:=DNS Over HTTPS Proxy
+ DEPENDS:=+libcares +libcurl +libev +ca-bundle
+ CONFLICTS:=https_dns_proxy
endef
-define Package/https_dns_proxy/install
+define Package/https-dns-proxy/install
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d ${1}/etc/config
- $(INSTALL_BIN) $(PKG_BUILD_DIR)/https_dns_proxy $(1)/usr/sbin/
- $(INSTALL_BIN) ./files/https_dns_proxy.init $(1)/etc/init.d/https_dns_proxy
- $(INSTALL_CONF) ./files/https_dns_proxy.config $(1)/etc/config/https_dns_proxy
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/https_dns_proxy $(1)/usr/sbin/https-dns-proxy
+ $(INSTALL_BIN) ./files/https-dns-proxy.init $(1)/etc/init.d/https-dns-proxy
+ $(INSTALL_CONF) ./files/https-dns-proxy.config $(1)/etc/config/https-dns-proxy
endef
-$(eval $(call BuildPackage,https_dns_proxy))
+$(eval $(call BuildPackage,https-dns-proxy))
--- /dev/null
+config https-dns-proxy
+ option bootstrap_dns '8.8.8.8,8.8.4.4'
+ option resolver_url 'https://dns.google/dns-query'
+ option listen_addr '127.0.0.1'
+ option listen_port '5053'
+ option user 'nobody'
+ option group 'nogroup'
+ option ipv4_resolvers '1'
+ option verbosity '0' # fatal = 0, error = 1, warning = 2, info = 3, debug = 4
+
+config https-dns-proxy
+ option bootstrap_dns '1.1.1.1,1.0.0.1'
+ option resolver_url 'https://cloudflare-dns.com/dns-query'
+ option listen_addr '127.0.0.1'
+ option listen_port '5054'
+ option user 'nobody'
+ option group 'nogroup'
+ option ipv4_resolvers '1'
+ option verbosity '0' # fatal = 0, error = 1, warning = 2, info = 3, debug = 4
--- /dev/null
+#!/bin/sh /etc/rc.common
+# Copyright 2019 Stan Grishin (stangri@melmac.net)
+# shellcheck disable=SC2039
+
+export START=80
+export USE_PROCD=1
+
+PROG=/usr/sbin/https-dns-proxy
+
+xappend() { param="$param $1"; }
+
+append_bool() {
+ local section="$1"
+ local option="$2"
+ local value="$3"
+ local default="$4"
+ local _loctmp
+ [ -z "$default" ] && default="0"
+ config_get_bool _loctmp "$section" "$option" "$default"
+ [ "$_loctmp" != "0" ] && xappend "$value"
+}
+
+append_parm() {
+ local section="$1"
+ local option="$2"
+ local switch="$3"
+ local default="$4"
+ local _loctmp
+ config_get _loctmp "$section" "$option" "$default"
+ [ -z "$_loctmp" ] && return 0
+ xappend "$switch $_loctmp"
+}
+
+start_instance() {
+ local cfg="$1" param listen_addr listen_port
+
+ append_parm "$cfg" 'listen_addr' '-a' '127.0.0.1'
+ append_parm "$cfg" 'listen_port' '-p' "$p"
+ append_parm "$cfg" 'bootstrap_dns' '-b'
+ append_parm "$cfg" 'resolver_url' '-r'
+ append_parm "$cfg" 'user' '-u' 'nobody'
+ append_parm "$cfg" 'group' '-g' 'nogroup'
+ append_parm "$cfg" 'edns_subnet' '-e'
+ append_parm "$cfg" 'proxy_server' '-t'
+ append_parm "$cfg" 'logfile' '-l'
+ append_bool "$cfg" 'use_http1' '-x'
+ append_bool "$cfg" 'ipv4_resolvers' '-4'
+
+ config_get verbosity "$cfg" 'verbosity' "0"
+ for i in $(seq 1 $verbosity); do
+ xappend "-v"
+ done
+
+ procd_open_instance
+# shellcheck disable=SC2086
+ procd_set_param command ${PROG} ${param}
+ procd_set_param stderr 1
+ procd_set_param stdout 1
+ procd_set_param respawn
+ procd_close_instance
+
+ config_get listen_addr "$cfg" 'listen_addr' '127.0.0.1'
+ config_get listen_port "$cfg" 'listen_port' "$p"
+
+ # Don't add the any address to dnsmasq
+ case $listen_addr in
+ 0.0.0.0|::ffff:0.0.0.0)
+ listen_addr='127.0.0.1'
+ ;;
+ ::)
+ listen_addr='::1'
+ ;;
+ esac
+
+ config_load 'dhcp'
+# shellcheck disable=SC2154
+ config_foreach dnsmasq_add_doh_server 'dnsmasq' "${listen_addr}#${listen_port}"
+ p="$((p+1))"
+}
+
+service_triggers() {
+ procd_add_reload_trigger 'https-dns-proxy'
+}
+
+start_service() {
+ local p=5053
+ dhcp_backup 'create'
+ config_load 'https-dns-proxy'
+ config_foreach start_instance 'https-dns-proxy'
+ if [ -z "$(uci -q get dhcp.@dnsmasq[0].server)" ]; then
+ dhcp_backup 'restore'
+ fi
+ if [ -n "$(uci -q changes dhcp)" ]; then
+ uci -q commit dhcp
+ [ -x /etc/init.d/dnsmasq ] && /etc/init.d/dnsmasq restart >/dev/null 2>&1
+ fi
+}
+
+stop_service() {
+ dhcp_backup 'restore'
+ if [ -n "$(uci -q changes dhcp)" ]; then
+ uci -q commit dhcp
+ [ -x /etc/init.d/dnsmasq ] && /etc/init.d/dnsmasq restart >/dev/null 2>&1
+ fi
+}
+
+service_triggers() {
+ procd_add_reload_trigger 'https-dns-proxy'
+}
+
+dnsmasq_add_doh_server() {
+ local cfg="$1" value="$2"
+ uci -q add_list dhcp."$cfg".server="$value"
+}
+
+dnsmasq_create_server_backup() {
+ local cfg="$1" i
+ if ! uci -q get "dhcp.$cfg.doh_backup_server" >/dev/null; then
+ for i in $(uci -q get "dhcp.$cfg.server"); do
+ uci -q add_list dhcp."$cfg".doh_backup_server="$i"
+ done
+ fi
+ uci -q del "dhcp.$cfg.server"
+}
+
+dnsmasq_restore_server_backup() {
+ local cfg="$1" i
+ if uci -q get "dhcp.$cfg.doh_backup_server" >/dev/null; then
+ uci -q del "dhcp.$cfg.server"
+ for i in $(uci -q get "dhcp.$cfg.doh_backup_server"); do
+ uci -q add_list dhcp."$cfg".server="$i"
+ done
+ fi
+}
+
+dhcp_backup() {
+ config_load 'dhcp'
+ case "$1" in
+ create)
+ config_foreach dnsmasq_create_server_backup 'dnsmasq';;
+ restore)
+ config_foreach dnsmasq_restore_server_backup 'dnsmasq';;
+ esac
+}
+++ /dev/null
-config https_dns_proxy
- option listen_addr '127.0.0.1'
- option listen_port '5053'
- option bootstrap_dns '8.8.8.8,8.8.4.4'
- option url_prefix 'https://dns.google.com/resolve?'
- option user 'nobody'
- option group 'nogroup'
- option subnet_addr ''
- option proxy_server ''
-
-config https_dns_proxy
- option listen_addr '127.0.0.1'
- option listen_port '5054'
- option bootstrap_dns '1.1.1.1,1.0.0.1'
- option url_prefix 'https://cloudflare-dns.com/dns-query?ct=application/dns-json&'
- option user 'nobody'
- option group 'nogroup'
- option subnet_addr ''
- option proxy_server ''
+++ /dev/null
-#!/bin/sh /etc/rc.common
-# Copyright 2019 Stan Grishin (stangri@melmac.net)
-# shellcheck disable=SC2039
-
-export START=80
-export USE_PROCD=1
-
-PROG=/usr/sbin/https_dns_proxy
-
-xappend() { param="$param $1"; }
-
-append_parm() {
- local section="$1"
- local option="$2"
- local switch="$3"
- local default="$4"
- local _loctmp
- config_get _loctmp "$section" "$option" "$default"
- [ -z "$_loctmp" ] && return 0
- xappend "$switch $_loctmp"
-}
-
-start_instance() {
- local cfg="$1" param listen_addr listen_port
-
- append_parm "$cfg" 'listen_addr' '-a' '127.0.0.1'
- append_parm "$cfg" 'listen_port' '-p' "$p"
- append_parm "$cfg" 'bootstrap_dns' '-b'
- append_parm "$cfg" 'url_prefix' '-r'
- append_parm "$cfg" 'user' '-u' 'nobody'
- append_parm "$cfg" 'group' '-g' 'nogroup'
- append_parm "$cfg" 'subnet_addr' '-e'
- append_parm "$cfg" 'proxy_server' '-t'
-
- procd_open_instance
-# shellcheck disable=SC2086
- procd_set_param command ${PROG} ${param}
- procd_set_param respawn
- procd_close_instance
-
- config_get listen_addr "$cfg" 'listen_addr' '127.0.0.1'
- config_get listen_port "$cfg" 'listen_port' "$p"
- config_load 'dhcp'
-# shellcheck disable=SC2154
- config_foreach dnsmasq_add_doh_server 'dnsmasq' "${listen_addr}#${listen_port}"
- p="$((p+1))"
-}
-
-service_triggers() {
- procd_add_reload_trigger 'https_dns_proxy'
-}
-
-start_service() {
- local p=5053
- dhcp_backup 'create'
- config_load 'https_dns_proxy'
- config_foreach start_instance 'https_dns_proxy'
- if [ -z "$(uci -q get dhcp.@dnsmasq[0].server)" ]; then
- dhcp_backup 'restore'
- fi
- if [ -n "$(uci -q changes dhcp)" ]; then
- uci -q commit dhcp
- [ -x /etc/init.d/dnsmasq ] && /etc/init.d/dnsmasq restart >/dev/null 2>&1
- fi
-}
-
-stop_service() {
- dhcp_backup 'restore'
- if [ -n "$(uci -q changes dhcp)" ]; then
- uci -q commit dhcp
- [ -x /etc/init.d/dnsmasq ] && /etc/init.d/dnsmasq restart >/dev/null 2>&1
- fi
-}
-
-dnsmasq_add_doh_server() {
- local cfg="$1" value="$2"
- uci -q add_list dhcp."$cfg".server="$value"
-}
-
-dnsmasq_create_server_backup() {
- local cfg="$1" i
- if ! uci -q get "dhcp.$cfg.doh_backup_server" >/dev/null; then
- for i in $(uci -q get "dhcp.$cfg.server"); do
- uci -q add_list dhcp."$cfg".doh_backup_server="$i"
- done
- fi
- uci -q del "dhcp.$cfg.server"
-}
-
-dnsmasq_restore_server_backup() {
- local cfg="$1" i
- if uci -q get "dhcp.$cfg.doh_backup_server" >/dev/null; then
- uci -q del "dhcp.$cfg.server"
- for i in $(uci -q get "dhcp.$cfg.doh_backup_server"); do
- uci -q add_list dhcp."$cfg".server="$i"
- done
- fi
-}
-
-dhcp_backup() {
- config_load 'dhcp'
- case "$1" in
- create)
- config_foreach dnsmasq_create_server_backup 'dnsmasq';;
- restore)
- config_foreach dnsmasq_restore_server_backup 'dnsmasq';;
- esac
-}
PKG_NAME:=ibrdtnd
PKG_VERSION:=1.0.1
-PKG_RELEASE:=4
+PKG_RELEASE:=5
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.ibr.cs.tu-bs.de/projects/ibr-dtn/releases
PKG_HASH:=9bd79636154093ab6bf4fd10d6c62d67c6db45141460847b19def327c93771ed
+
PKG_MAINTAINER:=Johannes Morgenroth <jm@m-network.de>
PKG_LICENSE:=Apache-2.0
--without-vmime \
--disable-libdaemon
-TARGET_CXXFLAGS += -std=gnu++03
-
define Package/ibrdtnd/install
$(INSTALL_DIR) $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/dtnd $(1)/usr/sbin/
PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=LICENSE
-PKG_MAINTAINER:=Florian Fainelli <florian@openwrt.org>
+PKG_MAINTAINER:=
PKG_CHECK_FORMAT_SECURITY:=0
--- /dev/null
+if PACKAGE_iputils-ping
+
+config PING_LEGACY_SYMLINKS
+ bool
+ default n
+ prompt "Install legacy ping4 and ping6 symlinks"
+ help
+ Iputils previously generated separate "ping" and "ping6"
+ binaries for supporting IPv4 and IPv6 communication,
+ respectively. Recent versions of iputils have merged
+ support for both address families into a single program.
+ Select this option to install "ping6" and "ping4" symlinks
+ to the unified binary to support compatibility with
+ existing tools that may still expect to find the old
+ names.
+
+endif
--- /dev/null
+if PACKAGE_iputils-tracepath
+
+config TRACEPATH_LEGACY_SYMLINKS
+ bool
+ default n
+ prompt "Install legacy tracepath4 and tracepath6 symlinks"
+ help
+ Iputils previously generated separate "tracepath" and
+ "tracepath6" binaries for supporting IPv4 and IPv6
+ communication, respectively. Recent versions of iputils
+ have merged support for both address families into a
+ single tracepath program. Select this option to install
+ "tracepath6" and "tracepath4" symlinks to the unified
+ binary to support compatibility with existing tools that
+ may still expect to find the old names.
+endif
--- /dev/null
+#
+# Copyright (C) 2006-2010 OpenWrt.org
+# Copyright (C) 2019 Noah Meyerhans <frodo@morgul.net>
+#
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=iputils
+PKG_VERSION:=20190709
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/iputils/iputils/tar.gz/s$(PKG_VERSION)?
+PKG_HASH:=a15720dd741d7538dd2645f9f516d193636ae4300ff7dbc8bfca757bf166490a
+
+PKG_MAINTAINER:=Noah Meyerhans <frodo@morgul.net>
+PKG_LICENSE:=BSD-3-Clause
+PKG_LICENSE_FILES:=LICENSE
+PKG_CPE_ID:=cpe:/a:iputils_project:iputils
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/iputils-s$(PKG_VERSION)
+PKG_BUILD_DEPENDS:=meson/host
+include $(INCLUDE_DIR)/package.mk
+include ../../devel/meson/meson.mk
+
+MESON_ARGS:=-DBUILD_MANS=false \
+ -DBUILD_HTML_MANS=false \
+ -DUSE_CAP=false \
+ -DUSE_CRYPTO=kernel \
+ -DUSE_IDN=false \
+ -DUSE_GETTEXT=false \
+ -DNO_SETCAP_OR_SUID=true \
+ -DBUILD_PING=true \
+ -DBUILD_ARPING=true \
+ -DBUILD_CLOCKDIFF=true \
+ -DBUILD_TRACEPATH=true \
+ -DBUILD_TFTPD=true
+
+define Package/iputils/Default
+ SECTION:=net
+ CATEGORY:=Network
+ TITLE:=iputils
+ URL:=https://github.com/iputils/iputils
+endef
+
+### ping
+
+define Package/iputils-ping
+ $(call Package/iputils/Default)
+ TITLE:=iputils-ping
+ DEPENDS:=+kmod-crypto-md5
+endef
+
+define Package/iputils-ping/config
+ source "$(SOURCE)/Config_ping.in"
+endef
+
+define Package/iputils-ping/description
+ Send ICMP_ECHOREQUEST packets to IP hosts and report on replies
+endef
+
+define Package/iputils-ping/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_SUID) $(MESON_BUILD_DIR)/ping $(1)/usr/bin/
+ifdef CONFIG_PING_LEGACY_SYMLINKS
+ ln -s ping $(1)/usr/bin/ping4
+ ln -s ping $(1)/usr/bin/ping6
+endif
+endef
+
+### arping
+
+define Package/iputils-arping
+ $(call Package/iputils/Default)
+ TITLE:=iputils-arping
+endef
+
+define Package/iputils-arping/description
+ Send ARP REQUEST packets to a neighbor host
+endef
+
+define Package/iputils-arping/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(MESON_BUILD_DIR)/arping $(1)/usr/bin/
+endef
+
+### clockdiff
+
+define Package/iputils-clockdiff
+ $(call Package/iputils/Default)
+ TITLE:=iputils-clockdiff
+endef
+
+define Package/iputils-clockdiff/description
+ Measure the clock difference between two hosts
+endef
+
+define Package/iputils-clockdiff/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(MESON_BUILD_DIR)/clockdiff $(1)/usr/bin/
+endef
+
+### tracepath
+
+define Package/iputils-tracepath
+ $(call Package/iputils/Default)
+ TITLE:=iputils-tracepath
+endef
+
+define Package/iputils-tracepath/description
+ trace network path to a host, discovering PMTU
+endef
+
+define Package/iputils-tracepath/config
+ source "$(SOURCE)/Config_tracepath.in"
+endef
+
+define Package/iputils-tracepath/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(MESON_BUILD_DIR)/tracepath $(1)/usr/bin/
+ifdef CONFIG_TRACEPATH_LEGACY_SYMLINKS
+ ln -s tracepath $(1)/usr/bin/tracepath4
+ ln -s tracepath $(1)/usr/bin/tracepath6
+endif
+endef
+
+### tftp
+
+define Package/iputils-tftpd
+ $(call Package/iputils/Default)
+ TITLE:=iputils-tftpd
+endef
+
+define Package/iputils-tftpd/description
+ Trivial File Transfer Protocol server
+endef
+
+define Package/iputils-tftpd/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(MESON_BUILD_DIR)/tftpd $(1)/usr/bin/
+endef
+
+$(eval $(call BuildPackage,iputils-ping))
+$(eval $(call BuildPackage,iputils-arping))
+$(eval $(call BuildPackage,iputils-clockdiff))
+$(eval $(call BuildPackage,iputils-tracepath))
+$(eval $(call BuildPackage,iputils-tftpd))
PKG_NAME:=kcptun
PKG_VERSION:=20191112
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/xtaci/kcptun/tar.gz/v${PKG_VERSION}?
SUBMENU:=Web Servers/Proxies
TITLE:=Kcptun Config Scripts
URL:=https://github.com/xtaci/kcptun
+ DEPENDS:=$(GO_ARCH_DEPENDS)
endef
define Package/kcptun-config/install
SUBMENU:=Web Servers/Proxies
TITLE:=KCP-based Secure Tunnel $(1)
URL:=https://github.com/xtaci/kcptun
- DEPENDS:=+kcptun-config $$(GO_ARCH_DEPENDS)
+ DEPENDS:=+kcptun-config
endef
define Package/kcptun-$(1)/description
include $(TOPDIR)/rules.mk
PKG_NAME:=knot
-PKG_VERSION:=2.9.1
+PKG_VERSION:=2.9.2
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://secure.nic.cz/files/knot-dns/
-PKG_HASH:=f19121956caa360c387923654f13e4c97b3fb9093d242e110d7e0916b8d8a04d
+PKG_HASH:=298cdf33aa7589b50df7e5833694b24cd2de8b6d17cee7e1673873fe576db6ee
PKG_MAINTAINER:=Daniel Salzman <daniel.salzman@nic.cz>
PKG_LICENSE:=GPL-3.0 LGPL-2.0 0BSD BSD-3-Clause OLDAP-2.8
PKG_NAME:=knxd
PKG_VERSION:=0.14.29
-PKG_RELEASE:=3
+PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/knxd/knxd/tar.gz/$(PKG_VERSION)?
#enable the EIBnet/IP server to answer discovery and description requests (SEARCH, DESCRIPTION)
option Discovery 1
# EIBADDR set our EIB address to EIBADDR (default 0.0.1)
- option eibaddr "0.0.2"
+ option eibaddr "0.0.1"
+ # CLIENTADDRS set client addrs
+ option client_addrs "0.0.2:10"
# LEVEL set error level
option error 0
# PORT listen at TCP port PORT (default 6720)
name = mcast:knxd
[main]
addr = 0.0.1
-background = true
client-addrs = 0.0.2:10
connections = A.tcp,server,B.ip
[server]
append_parm args client_addrs "client-addrs" "0.0.2:10"
append_parm args layer2 "layer2"
append_bool args GroupCache "GroupCache" 0
- append_parm args daemon "daemon" "/var/log/knxd.log"
+ #append_parm args daemon "daemon" "/var/log/knxd.log"
append_parm args error "error" # "5"
append_parm args listen_tcp "listen-tcp" "6720"
append_parm args Interface "Interface" # "eth0"
if [ "$url" == "usb:" ] ; then
url="usb:""$(findknxusb | tail -n1 | sed -e 's/device: \([0-9]:[0-9]:[0-9]\):[0-9].*/\1/')"
fi
- echo "/usr/lib/knxd_args $params $url"
- /usr/lib/knxd_args $params $url > /tmp/etc/knxd.ini
+ echo "/usr/lib/knxd_args $params -b $url"
+ /usr/lib/knxd_args $params -b $url > /tmp/etc/knxd.ini
procd_open_instance
procd_set_param command $PROG "/tmp/etc/knxd.ini"
procd_set_param respawn
+ procd_set_param stdout 1
+ procd_set_param stderr 1
procd_close_instance
}
-stop_service() {
- killall knxd
-}
-
reload_service()
{
restart
include $(TOPDIR)/rules.mk
PKG_NAME:=modemmanager
-PKG_VERSION:=1.12.0
-PKG_RELEASE:=3
+PKG_VERSION:=1.12.2
+PKG_RELEASE:=2
PKG_SOURCE:=ModemManager-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://www.freedesktop.org/software/ModemManager
-PKG_HASH:=3daca86164145fffb589939433f596c13fa077c9a187c0d5820fdd5b4e4a6424
+PKG_HASH:=4f76d2bdd0ed6780837cdde886eaf535f9770f9daa1ff92e63658d06aa5d25ea
PKG_BUILD_DIR:=$(BUILD_DIR)/ModemManager-$(PKG_VERSION)
PKG_MAINTAINER:=Nicholas Smith <nicholas.smith@telcoantennas.com.au>
$(INTL_DEPENDS) \
+glib2 \
+dbus \
+ +ppp \
+MODEMMANAGER_WITH_MBIM:libmbim \
+MODEMMANAGER_WITH_QMI:libqmi
endef
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libmm-glib.so.* $(1)/usr/lib
$(INSTALL_DIR) $(1)/usr/lib/ModemManager
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/ModemManager/libmm-shared-*.so* $(1)/usr/lib/ModemManager
$(CP) $(PKG_INSTALL_DIR)/usr/lib/ModemManager/libmm-plugin-*.so* $(1)/usr/lib/ModemManager
$(INSTALL_DIR) $(1)/etc/dbus-1/system.d
$(INSTALL_DIR) $(1)/usr/share/ModemManager
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/ModemManager/*.conf $(1)/usr/share/ModemManager
+ $(INSTALL_DATA) ./files/modemmanager.common $(1)/usr/share/ModemManager
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/modemmanager.init $(1)/etc/init.d/modemmanager
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/usb
+ $(INSTALL_DATA) ./files/25-modemmanager-usb $(1)/etc/hotplug.d/usb
+
$(INSTALL_DIR) $(1)/etc/hotplug.d/net
$(INSTALL_DATA) ./files/25-modemmanager-net $(1)/etc/hotplug.d/net
$(INSTALL_DIR) $(1)/etc/hotplug.d/tty
$(INSTALL_DATA) ./files/25-modemmanager-tty $(1)/etc/hotplug.d/tty
- $(INSTALL_DIR) $(1)/etc/modemmanager
- $(INSTALL_DATA) ./files/modemmanager.common $(1)/etc/modemmanager/modemmanager.common
-
$(INSTALL_DIR) $(1)/lib/netifd/proto
$(INSTALL_BIN) ./files/modemmanager.proto $(1)/lib/netifd/proto/modemmanager.sh
endef
# Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
# Load common utilities
-. /etc/modemmanager/modemmanager.common
+. /usr/share/ModemManager/modemmanager.common
# We require a interface name
[ -n "${INTERFACE}" ] || exit
# Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
# Load hotplug common utilities
-. /etc/modemmanager/modemmanager.common
+. /usr/share/ModemManager/modemmanager.common
# We require a device name
[ -n "$DEVNAME" ] || exit
--- /dev/null
+#!/bin/sh
+# Copyright (C) 2019 Aleksander Morgado <aleksander@aleksander.es>
+
+# We need to process only full USB device removal events, we don't
+# want to process specific interface removal events.
+[ "$ACTION" = remove ] || exit
+[ -z "${INTERFACE}" ] || exit
+
+# Load common utilities
+. /usr/share/ModemManager/modemmanager.common
+
+mm_clear_modem_wait_status "/sys${DEVPATH}"
+mm_cleanup_interface_by_sysfspath "/sys${DEVPATH}"
################################################################################
# Receives as input argument the full sysfs path of the device
# Returns the physical device sysfs path
+#
+# NOTE: this method only works when the device exists, i.e. it cannot be used
+# on removal hotplug events
mm_find_physdev_sysfs_path() {
local tmp_path="$1"
awk -v sysfspath="${sysfspath}" '!/^#/ && $0 ~ sysfspath { print $2 }' "${MODEMMANAGER_SYSFS_CACHE}"
}
+# Clear the modem wait status from the cache, if any
+mm_clear_modem_wait_status() {
+ local sysfspath="$1"
+
+ local escaped_sysfspath
+
+ [ -f "${MODEMMANAGER_SYSFS_CACHE}" ] && {
+ # escape '/', '\' and '&' for sed...
+ escaped_sysfspath=$(echo "$sysfspath" | sed -e 's/[\/&]/\\&/g')
+ sed -i "/${escaped_sysfspath}/d" "${MODEMMANAGER_SYSFS_CACHE}"
+ }
+}
+
# Sets the modem wait status in the cache
mm_set_modem_wait_status() {
local sysfspath="$1"
local status="$2"
# Remove sysfs line before adding the new one with the new state
- [ -f "${MODEMMANAGER_SYSFS_CACHE}" ] &&
- sed -i "/${sysfspath}/d" "${MODEMMANAGER_SYSFS_CACHE}"
+ mm_clear_modem_wait_status "${sysfspath}"
# Add the new status
echo "${sysfspath} ${status}" >> "${MODEMMANAGER_SYSFS_CACHE}"
}
mm_report_modem_wait() {
- local action=$1
- local sysfspath=$2
+ local sysfspath=$1
local parent_sysfspath status
}
status=$(mm_get_modem_wait_status "${parent_sysfspath}")
-
- [ "$action" = "add" ] && {
- case "${status}" in
- "")
- local cfg
-
- cfg=$(mm_get_modem_config "${parent_sysfspath}")
- if [ -n "${cfg}" ]; then
- mm_log "interface '${cfg}' is set to configure device '${parent_sysfspath}'"
- mm_log "now waiting for modem at sysfs path ${parent_sysfspath}"
- mm_set_modem_wait_status "${parent_sysfspath}" "processed"
- # Launch subshell for the explicit wait
- ( mm_wait_for_modem "${cfg}" "${parent_sysfspath}" ) > /dev/null 2>&1 &
- else
- mm_log "no need to wait for modem at sysfs path ${parent_sysfspath}"
- mm_set_modem_wait_status "${parent_sysfspath}" "ignored"
- fi
- ;;
- "processed")
- mm_log "already waiting for modem at sysfs path ${parent_sysfspath}"
- ;;
- "ignored")
- ;;
- *)
- mm_log "error: unknown status read for device at sysfs path ${parent_sysfspath}"
- ;;
- esac
- return
- }
-
- [ "$action" = "remove" ] && {
- local cfg
-
- [ -n "$status" ] && {
+ case "${status}" in
+ "")
local cfg
- mm_log "cleanup wait for modem at sysfs path ${parent_sysfspath}"
- mm_set_modem_wait_status "${parent_sysfspath}" ""
-
cfg=$(mm_get_modem_config "${parent_sysfspath}")
- [ -n "${cfg}" ] && {
- mm_log "setting interface '$cfg' as unavailable"
- proto_set_available "${cfg}" 0
- }
- }
- return
- }
+ if [ -n "${cfg}" ]; then
+ mm_log "interface '${cfg}' is set to configure device '${parent_sysfspath}'"
+ mm_log "now waiting for modem at sysfs path ${parent_sysfspath}"
+ mm_set_modem_wait_status "${parent_sysfspath}" "processed"
+ # Launch subshell for the explicit wait
+ ( mm_wait_for_modem "${cfg}" "${parent_sysfspath}" ) > /dev/null 2>&1 &
+ else
+ mm_log "no need to wait for modem at sysfs path ${parent_sysfspath}"
+ mm_set_modem_wait_status "${parent_sysfspath}" "ignored"
+ fi
+ ;;
+ "processed")
+ mm_log "already waiting for modem at sysfs path ${parent_sysfspath}"
+ ;;
+ "ignored")
+ ;;
+ *)
+ mm_log "error: unknown status read for device at sysfs path ${parent_sysfspath}"
+ ;;
+ esac
}
################################################################################
config_foreach mm_cleanup_interface_cb interface
}
+mm_cleanup_interface_by_sysfspath() {
+ local dev="$1"
+
+ local cfg
+ cfg=$(mm_get_modem_config "$dev")
+ [ -n "${cfg}" ] || return
+
+ mm_log "setting interface '$cfg' as unavailable"
+ proto_set_available "${cfg}" 0
+}
+
################################################################################
# Event reporting
mm_log "event reported: action=${action}, name=${name}, subsystem=${subsystem}"
mmcli --report-kernel-event="action=${action},name=${name},subsystem=${subsystem}" 1>/dev/null 2>&1 &
- # Wait for modem if a sysfspath is given
- [ -n "${sysfspath}" ] && mm_report_modem_wait "${action}" "${sysfspath}"
+ # Wait for added modem if a sysfspath is given
+ [ -n "${sysfspath}" ] && [ "$action" = "add" ] && mm_report_modem_wait "${sysfspath}"
}
mm_report_event_from_cache_line() {
stop_service() {
# Load common utils
- . /etc/modemmanager/modemmanager.common
+ . /usr/share/ModemManager/modemmanager.common
# Set all configured interfaces as unavailable
mm_cleanup_interfaces
}
start_service() {
# Load common utils
- . /etc/modemmanager/modemmanager.common
+ . /usr/share/ModemManager/modemmanager.common
# Always make sure the rundir exists
mkdir -m 0755 -p "${MODEMMANAGER_RUNDIR}"
}
proto_modemmanager_init_config() {
- proto_config_add_string "device:device"
+ available=1
+ no_device=1
+ proto_config_add_string device
proto_config_add_string apn
proto_config_add_string username
proto_config_add_string password
proto_config_add_string pincode
proto_config_add_string iptype
proto_config_add_boolean lowpower
+ proto_config_add_defaults
}
proto_modemmanager_setup() {
PKG_NAME:=mosh
PKG_VERSION:=1.3.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://mosh.org/
--- /dev/null
+--- a/src/network/network.cc
++++ b/src/network/network.cc
+@@ -60,7 +60,6 @@
+ #define AI_NUMERICSERV 0
+ #endif
+
+-using namespace std;
+ using namespace Network;
+ using namespace Crypto;
+
include $(TOPDIR)/rules.mk
PKG_NAME:=mosquitto
-PKG_VERSION:=1.6.7
+PKG_VERSION:=1.6.8
PKG_RELEASE:=1
PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE.txt
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://mosquitto.org/files/source/
-PKG_HASH:=bcd31a8fbbd053fee328986fadd8666d3058357ded56b9782f7d4f19931d178e
+PKG_HASH:=7df23c81ca37f0e070574fe74414403cf25183016433d07add6134366fb45df6
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/rules.mk
PKG_NAME:=mtr
-PKG_VERSION:=0.92
-PKG_RELEASE:=6
+PKG_VERSION:=0.93
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://www.bitwizard.nl/mtr/files
-PKG_HASH:=f2979db9e2f41aa8e6574e7771767c9afe111d9213814eb47f5e1e71876e4382
+PKG_SOURCE_URL:=ftp://ftp.bitwizard.nl/mtr
+PKG_HASH:=229c673d637bd7dbb96471623785a47e85da0b1944978200c949994c1e6af10d
PKG_MAINTAINER:=Jonathan McCrohan <jmccrohan@gmail.com>
PKG_LICENSE:=GPL-2.0-or-later
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
-PKG_FIXUP:=autoreconf
-
include $(INCLUDE_DIR)/package.mk
-# Creation of .tarball-version is an attempt to make it explicit to configure
-# script the program version. See discussions at link [1] for more details
-#
-# [1] mtr: add autoreconf, https://github.com/openwrt/packages/pull/6962#issuecomment-419156300
-#
-define Build/Prepare
- $(call Build/Prepare/Default)
- echo "$(PKG_VERSION)" >$(PKG_BUILD_DIR)/.tarball-version
-endef
-
define Package/mtr
SECTION:=net
CATEGORY:=Network
running statistics about each machine.
endef
+TARGET_CFLAGS += -ffunction-sections -fdata-sections
+TARGET_LDFLAGS += -Wl,--gc-sections,--as-needed
+
CONFIGURE_ARGS += \
--without-gtk \
$(call autoconf_bool,CONFIG_IPV6,ipv6)
append_parm v1trapaddress host v1trapaddress
append_parm trapsess trapsess trapsess
- procd_set_param command $PROG -Lf /dev/null -f
+ procd_set_param command $PROG -Lf /dev/null -f -r
procd_set_param file $CONFIGFILE
procd_set_param respawn
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://gitlab.com/netify.ai/public/netify-agent.git
-PKG_SOURCE_DATE:=2019-10-21
-PKG_SOURCE_VERSION:=v2.93
-#PKG_SOURCE_VERSION:=4585e2b82c6a34633bc54ac526a635e8a95b28f3
-PKG_MIRROR_HASH:=efbfae112bb4d8d8d22e04ce523484a47b154a4cf57b3992aa28073ba64bd59b
+PKG_SOURCE_DATE:=2019-12-07
+PKG_SOURCE_VERSION:=v2.98
+#PKG_SOURCE_VERSION:=a204805151bc5c35ad09e21913dac25deed13f95
+PKG_MIRROR_HASH:=d235df7f77380e188db75fb885491bf46b2a7a3454f7bf2c85269aeff8f92220
include $(INCLUDE_DIR)/package.mk
CATEGORY:=Network
TITLE:=Netify Agent
URL:=http://www.netify.ai/
- DEPENDS:=+ca-bundle +libcurl +libmnl +libnetfilter-conntrack +libjson-c +libpcap +zlib +libpthread @!USE_UCLIBC
+ DEPENDS:=+ca-bundle +libcurl +libmnl +libnetfilter-conntrack +libpcap +zlib +libpthread @!USE_UCLIBC
# Explicitly depend on libstdcpp rather than $(CXX_DEPENDS). At the moment
# std::unordered_map is only available via libstdcpp which is required for
# performance reasons.
/etc/netifyd.conf
endef
-TARGET_CFLAGS+=-ffunction-sections -fdata-sections
-TARGET_CXXFLAGS+=-ffunction-sections -fdata-sections
+TARGET_CFLAGS+=-ffunction-sections -fdata-sections -Wno-psabi
+TARGET_CXXFLAGS+=-ffunction-sections -fdata-sections -Wno-psabi
TARGET_LDFLAGS+=-Wl,--gc-sections
CONFIGURE_ARGS+= \
include $(TOPDIR)/rules.mk
PKG_NAME:=nextdns
-PKG_VERSION:=1.1.5
-PKG_RELEASE:=3
+PKG_VERSION:=1.3.1
+PKG_RELEASE:=4
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=v$(PKG_VERSION)
PKG_SOURCE_URL:=https://github.com/nextdns/nextdns.git
-PKG_MIRROR_HASH:=01ff61771bcf076f1659167b8676234fdefefac9cd0a05aa1d491a7c5f0145fa
+PKG_MIRROR_HASH:=bb3b1901ba4d65b91f69487c59fbae89654fc22d368d37f3640c6eb457a2a0a1
PKG_MAINTAINER:=Olivier Poitrey <rs@nextdns.io>
PKG_LICENSE:=MIT
include $(TOPDIR)/rules.mk
PKG_NAME:=nlbwmon
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/jow-/nlbwmon.git
}
service_triggers() {
- procd_add_reload_trigger "dhcp" "system"
+ procd_add_reload_trigger "dhcp" "system" "nlbwmon"
config_load dhcp
config_foreach add_interface_trigger dhcp
PKG_NAME:=ntp
PKG_VERSION:=4.2.8p13
-PKG_RELEASE:=3
+PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/
# since some of them might be dynamic interfaces (like IPsec
# tunnels) which aren't known by ubus.
+ mkdir -p "$(dirname "$config_file")"
+
trunc
emit "driftfile /var/lib/ntp/ntp.drift\n"
include $(TOPDIR)/rules.mk
PKG_NAME:=openssh
-PKG_VERSION:=8.0p1
-PKG_RELEASE:=2
+PKG_VERSION:=8.1p1
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/ \
https://ftp.spline.de/pub/OpenBSD/OpenSSH/portable/ \
https://anorien.csc.warwick.ac.uk/pub/OpenBSD/OpenSSH/portable/
-PKG_HASH:=bd943879e69498e8031eb6b7f44d08cdc37d59a7ab689aa0b437320c3481fd68
+PKG_HASH:=02f5dbef3835d0753556f973cd57b4c19b6b1f6cd24c03445e23ac77ca1b93ff
PKG_LICENSE:=BSD ISC
PKG_LICENSE_FILES:=LICENCE
+++ /dev/null
-From 73eb6cef41daba0359c1888e4756108d41b4e819 Mon Sep 17 00:00:00 2001
-From: Darren Tucker <dtucker@dtucker.net>
-Date: Sun, 16 Jun 2019 12:55:27 +1000
-Subject: [PATCH] Include stdio.h for vsnprintf.
-
-Patch from mforney at mforney.org.
----
- openbsd-compat/setproctitle.c | 1 +
- 1 file changed, 1 insertion(+)
-
-diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c
-index dbd1a95a0..e4064323a 100644
---- a/openbsd-compat/setproctitle.c
-+++ b/openbsd-compat/setproctitle.c
-@@ -36,6 +36,7 @@
- #ifndef HAVE_SETPROCTITLE
-
- #include <stdarg.h>
-+#include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #ifdef HAVE_SYS_PSTAT_H
PKG_NAME:=opentracker
PKG_VERSION:=20180526
PKG_RELEASE:=1
-PKG_REV:=6411f1567f64248b0d145493c2e61004d2822623
-PKG_MIRROR_HASH:=bf4b0f16c38eb17ff5cc8e2a8d6d98f26b9de500fecd80436e9b0a75d0a2bde2
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://erdgeist.org/gitweb/opentracker
+PKG_SOURCE_VERSION:=6411f1567f64248b0d145493c2e61004d2822623
+PKG_MIRROR_HASH:=064ffaa69b188f4db5626d5ec57249d921c32dd244dd00bb49b31ad841e35018
+
PKG_MAINTAINER:=Daniel Golle <daniel@makrotopia.org>
PKG_LICENSE:=Beerware
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
-PKG_SOURCE_URL:=git://erdgeist.org/opentracker
-PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
-PKG_SOURCE_VERSION:=$(PKG_REV)
-PKG_SOURCE_PROTO:=git
PKG_BUILD_DEPENDS:=libowfat
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/rules.mk
PKG_NAME:=pagekitec
-PKG_REV:=0.91.171102
+PKG_REV:=0.91.191211
PKG_VERSION:=$(PKG_REV)C
-PKG_RELEASE:=2
+PKG_RELEASE:=1
PKG_LICENSE:=Apache-2.0
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
-PKG_MIRROR_HASH:=9e04b979cff827974ec9e9708daf116867bf1268cdad7dff4ad585172123f6b5
+PKG_MIRROR_HASH:=2f560ae679775758b1b5e5f69cd4d82afa28339ee8ab6ee9e4af11daa6f8be77
PKG_SOURCE_URL:=https://github.com/pagekite/libpagekite.git
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=v$(PKG_REV)
include $(TOPDIR)/rules.mk
PKG_NAME:=pdns-recursor
-PKG_VERSION:=4.2.0
+PKG_VERSION:=4.2.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://downloads.powerdns.com/releases/
-PKG_HASH:=f03c72c1816fdcc645cc539d8c16721d2ec294feac9b5179e78c3db311b7c2c2
+PKG_HASH:=8d8c3235cc5281f0fc51946129f22758778f4c50bfda095d5856feb4c756891f
PKG_MAINTAINER:=James Taylor <james@jtaylor.id.au>
PKG_LICENCE:=GPL-2.0-only
SUBMENU:=IP Addresses and Names
USERID:=pdns:pdns
TITLE:=PowerDNS Recursor
- DEPENDS:=+boost +boost-context +boost-thread +libatomic +liblua +libopenssl +protobuf
+ DEPENDS:=+boost +boost-context +libatomic +liblua +libopenssl +protobuf
URL:=https://www.powerdns.com/recursor.html
endef
#################################
# version-string string reported on version.pdns or version.bind
#
-# version-string=PowerDNS Recursor 4.2.0 (built May 18 2019 15:59:49 by jamestk@zanzabar.cybase.for-no-reason.net)
+# version-string=PowerDNS Recursor 4.2.1
#################################
# webserver Start a webserver (for REST API)
--- /dev/null
+--- a/m4/boost.m4
++++ b/m4/boost.m4
+@@ -667,12 +667,15 @@
+ BOOST_DEFUN([Context],
+ [boost_context_save_LIBS=$LIBS
+ boost_context_save_LDFLAGS=$LDFLAGS
+-if test $boost_major_version -ge 157; then
+- BOOST_THREAD([$1], [$2])
+- m4_pattern_allow([^BOOST_THREAD_(LIBS|LDFLAGS)$])dnl
+- LIBS="$LIBS $BOOST_THREAD_LIBS"
+- LDFLAGS="$LDFLAGS $BOOST_THREAD_LDFLAGS"
+-fi
++# This check is flawed and doesn't actually verify if BOOST::THREAD
++# is required on the system, producing only false positives on the
++# platforms supported by OpenWRT.
++#if test $boost_major_version -ge 157; then
++# BOOST_THREAD([$1], [$2])
++# m4_pattern_allow([^BOOST_THREAD_(LIBS|LDFLAGS)$])dnl
++# LIBS="$LIBS $BOOST_THREAD_LIBS"
++# LDFLAGS="$LDFLAGS $BOOST_THREAD_LDFLAGS"
++#fi
+
+ if test $boost_major_version -ge 161; then
+ BOOST_FIND_LIB([context], [$1],
include $(TOPDIR)/rules.mk
PKG_NAME:=pdns
-PKG_VERSION:=4.2.0
-PKG_RELEASE:=2
+PKG_VERSION:=4.2.1
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://downloads.powerdns.com/releases/
-PKG_HASH:=222007f25e25aad71ac7d8b7f1797a4bcb30781e456d74ed00396e53828a903a
+PKG_HASH:=f65019986b8fcbb1c6fffebcded04b2b397b84395830f4c63e8d119bcfa1aa28
PKG_MAINTAINER:=James Taylor <james@jtaylor.id.au>
PKG_LICENCE:=GPL-2.0-only
PKG_BUILD_PARALLEL:=1
-PKG_BUILD_DEPENDS:=unixodbc/host
+PKG_BUILD_DEPENDS:=unixodbc/host protobuf-c/host
include $(INCLUDE_DIR)/package.mk
# 2: dependencies on other PowerDNS libraries (short name)
# 3: dependencies on other packages
# 4: conditional/inward dependencies
+# 5: friendly display name
define DefinePdnsBackend
PDNS_DEPENDS+= +pdns-backend-$(1)
PKG_CONFIG_DEPENDS+= CONFIG_PACKAGE_pdns-backend$(1)
define Package/pdns-backend-$(1)
$(call Package/pdns/Default)
TITLE+= ($(1))
- DEPENDS+= pdns $$(foreach backend,$(2),+pdns-backend-$$(backend)) $(3)
+ DEPENDS+= pdns $$(foreach backend,$(2),+pdns-backend-$$(backend)) \
+ $$(foreach dependency,$(3),+$$(dependency))
HIDDEN:=1
endef
define Package/pdns/Default/install
$(INSTALL_DIR) $(1)/usr/lib/powerdns/pdns
$(CP) $(PKG_INSTALL_DIR)/usr/lib/powerdns/pdns/lib$(PDNS_BACKEND_$(2)_LIB)backend.so $(1)/usr/lib/powerdns/pdns/
+ if [ "$(PDNS_BACKEND_$(2)_LIB)" == "ldap" ]; then \
+ $(INSTALL_DIR) $(1)/usr/bin; \
+ $(CP) $(PKG_INSTALL_DIR)/usr/bin/zone2ldap $(1)/usr/bin/; \
+ fi
endef
define Package/pdns-ixfrdist/install
define Package/pdns-tools/install
$(INSTALL_DIR) $(1)/usr/bin
- $(CP) $(PKG_INSTALL_DIR)/usr/bin/zone2ldap $(1)/usr/bin/
$(CP) $(PKG_INSTALL_DIR)/usr/bin/dnsgram $(1)/usr/bin/
$(CP) $(PKG_INSTALL_DIR)/usr/bin/dnsreplay $(1)/usr/bin/
$(CP) $(PKG_INSTALL_DIR)/usr/bin/dnsscan $(1)/usr/bin/
#
# api-key=
+#################################
+# axfr-fetch-timeout Maximum time in seconds for inbound AXFR to start or be idle after starting
+#
+# axfr-fetch-timeout=10
+
#################################
# axfr-lower-serial Also AXFR a zone from a master with a lower serial
#
include $(TOPDIR)/rules.mk
PKG_NAME:=pingcheck
-PKG_VERSION:=2017-10-02
-PKG_RELEASE:=2
+PKG_VERSION:=2019-10-08
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
-PKG_MIRROR_HASH:=8c8d1743b8972ade6c75027346fc652f7a1c0f17e2f9bd2e65aad20013d9870e
+PKG_MIRROR_HASH:=0bf82809ce36106825d1a757c4624efcbab1829c1a9bf9e1e055e75ebf83403d
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_URL:=https://github.com/br101/pingcheck
PKG_SOURCE_PROTO:=git
-PKG_SOURCE_VERSION:=12e65e2f3fd2a17db785d28756df43ccade29b1b
+PKG_SOURCE_VERSION:=7223f1b10697735d34f297ca2520495337666df6
PKG_MAINTAINER:=Bruno Randolf <br1@einfach.org>
PKG_LICENSE:=GPL-2.0-or-later
include $(TOPDIR)/rules.mk
PKG_NAME:=prosody
-PKG_VERSION:=0.11.2
-PKG_RELEASE:=3
+PKG_VERSION:=0.11.3
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://prosody.im/downloads/source
-PKG_HASH:=8911f6dc29b9e0c4edf9e61dc23fa22d77bc42c4caf28b809ab843b2f08e4831
+PKG_HASH:=cfdabd6f42a9fc5db300221967c518c26bd4b6e62def721c1626894d6325bf87
+
PKG_MAINTAINER:=Thomas Heil <heil@terminal-consulting.de>
PKG_LICENSE:=MIT/X11
-PKG_BUILD_DEPENDS:=lua/host
PKG_CPE_ID:=cpe:/a:prosody:prosody
-HOST_BUILD_DEPENDS:=$(PKG_BUILD_DEPENDS)
PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
+PKG_BUILD_DEPENDS:=lua/host
include $(INCLUDE_DIR)/package.mk
/etc/prosody/prosody.cfg.lua
endef
-TARGET_CFLAGS += $(FPIC) -std=gnu99
+TARGET_CFLAGS += $(FPIC)
TARGET_LDFLAGS += -shared
MAKE_FLAGS += LD="$(TARGET_CC)"
--- /dev/null
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=restic-rest-server
+PKG_VERSION:=0.9.7
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/rest-server-$(PKG_VERSION)
+PKG_SOURCE:=rest-server-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/restic/rest-server/tar.gz/v${PKG_VERSION}?
+PKG_HASH:=922811cfc49879f7086fe559d25ec1bb4169b2c4a5df3559b499e6292f435661
+
+PKG_LICENSE:=BSD-2-Clause
+PKG_LICENSE_FILES:=LICENSE
+PKG_MAINTAINER:=Markus Weippert <markus@gekmihesg.de>
+
+PKG_BUILD_DEPENDS:=golang/host
+PKG_BUILD_PARALLEL:=1
+PKG_USE_MIPS16:=0
+
+GO_PKG:=github.com/restic/rest-server/
+GO_PKG_BUILD_PKG:=github.com/restic/rest-server/cmd/rest-server/
+GO_PKG_LDFLAGS:=-s -w
+GO_PKG_LDFLAGS_X:=main.version=$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+include ../../lang/golang/golang-package.mk
+
+define Package/restic-rest-server
+ TITLE:=restic REST server
+ URL:=http://github.com/restic/rest-server
+ DEPENDS:=$(GO_ARCH_DEPENDS)
+ SECTION:=net
+ CATEGORY:=Network
+endef
+
+define Package/restic-rest-server/description
+Rest Server is a high performance HTTP server that implements restic's REST backend
+API. It provides secure and efficient way to backup data remotely, using restic
+backup client via the rest: URL.
+endef
+
+define Package/restic-rest-server/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(GO_PKG_BUILD_BIN_DIR)/rest-server $(1)/usr/bin/restic-rest-server
+ $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call GoBinPackage,restic-rest-server))
+$(eval $(call BuildPackage,restic-rest-server))
--- /dev/null
+config rest-server
+ option enabled '0'
+ option path '/mnt/backup' # data directory (default "/tmp/restic")
+ #option append-only '1' # enable append only mode
+ #option cpuprofile '/mnt/backup/cpuprofile' # write CPU profile to file
+ #option debug '1' # output debug messages
+ #option listen ':8000' # listen address (default ":8000")
+ #option log '/mnt/backup/http.log' # log HTTP requests in the combined log format
+ #option private-repos '1' # users can only access their private repo
+ #option prometheus '1' # enable Prometheus metrics
+ #option tls '1' # turn on TLS support
+ #option tls-cert '/mnt/backup/public_key' # TLS certificate path
+ #option tls-key '/mnt/backup/private_key' # TLS key path
--- /dev/null
+#!/bin/sh /etc/rc.common
+
+START=99
+USE_PROCD=1
+
+PROG=/usr/bin/restic-rest-server
+
+start_instance() {
+ local cfg="$1"
+ local var
+ local val
+
+ config_get_bool val "$cfg" 'enabled' '0'
+ [ "$val" = 0 ] && return 1
+
+ procd_open_instance "$cfg"
+ procd_set_param command "$PROG"
+ for var in append_only debug private_repos prometheus tls; do
+ config_get_bool val "$cfg" "$var" 0
+ [ "$val" = 0 ] || procd_append_param command "--${var//_/-}"
+ done
+ for var in cpuprofile listen log path tls_cert tls_key; do
+ config_get val "$cfg" "$var"
+ [ -z "$val" ] || procd_append_param command "--${var//_/-}" "$val"
+ done
+ procd_set_param stdout 1
+ procd_set_param stderr 1
+ procd_set_param respawn
+ procd_close_instance
+}
+
+
+service_triggers() {
+ procd_add_reload_trigger restic-rest-server
+}
+
+start_service() {
+ config_load restic-rest-server
+ config_foreach start_instance rest-server
+}
include $(TOPDIR)/rules.mk
PKG_NAME:=safe-search
-PKG_VERSION:=1.0.1
+PKG_VERSION:=1.0.2
PKG_RELEASE:=1
PKG_LICENSE:=MIT
PKG_MAINTAINER:=Gregory L. Dietsche <Gregory.Dietsche@cuw.edu>
# IMPORTANT: if this file is not working, make sure that dnsmasq is able to READ it!
#
# Google Safe Search Host List
-# Generated on Wed Oct 10 10:18:34 CDT 2018
+# Generated on Sat Dec 7 10:21:21 CST 2019
# From: https://www.google.com/supported_domains
#2001:4860:4802:32::78 forcesafesearch.google.com
2001:4860:4802:32::78 google.com.gi
2001:4860:4802:32::78 google.gl
2001:4860:4802:32::78 google.gm
-2001:4860:4802:32::78 google.gp
2001:4860:4802:32::78 google.gr
2001:4860:4802:32::78 google.com.gt
2001:4860:4802:32::78 google.gy
2001:4860:4802:32::78 google.com.my
2001:4860:4802:32::78 google.co.mz
2001:4860:4802:32::78 google.com.na
-2001:4860:4802:32::78 google.com.nf
2001:4860:4802:32::78 google.com.ng
2001:4860:4802:32::78 google.com.ni
2001:4860:4802:32::78 google.ne
2001:4860:4802:32::78 google.tg
2001:4860:4802:32::78 google.co.th
2001:4860:4802:32::78 google.com.tj
-2001:4860:4802:32::78 google.tk
2001:4860:4802:32::78 google.tl
2001:4860:4802:32::78 google.tm
2001:4860:4802:32::78 google.tn
2001:4860:4802:32::78 www.google.com.gi
2001:4860:4802:32::78 www.google.gl
2001:4860:4802:32::78 www.google.gm
-2001:4860:4802:32::78 www.google.gp
2001:4860:4802:32::78 www.google.gr
2001:4860:4802:32::78 www.google.com.gt
2001:4860:4802:32::78 www.google.gy
2001:4860:4802:32::78 www.google.com.my
2001:4860:4802:32::78 www.google.co.mz
2001:4860:4802:32::78 www.google.com.na
-2001:4860:4802:32::78 www.google.com.nf
2001:4860:4802:32::78 www.google.com.ng
2001:4860:4802:32::78 www.google.com.ni
2001:4860:4802:32::78 www.google.ne
2001:4860:4802:32::78 www.google.tg
2001:4860:4802:32::78 www.google.co.th
2001:4860:4802:32::78 www.google.com.tj
-2001:4860:4802:32::78 www.google.tk
2001:4860:4802:32::78 www.google.tl
2001:4860:4802:32::78 www.google.tm
2001:4860:4802:32::78 www.google.tn
216.239.38.120 google.com.gi
216.239.38.120 google.gl
216.239.38.120 google.gm
-216.239.38.120 google.gp
216.239.38.120 google.gr
216.239.38.120 google.com.gt
216.239.38.120 google.gy
216.239.38.120 google.com.my
216.239.38.120 google.co.mz
216.239.38.120 google.com.na
-216.239.38.120 google.com.nf
216.239.38.120 google.com.ng
216.239.38.120 google.com.ni
216.239.38.120 google.ne
216.239.38.120 google.tg
216.239.38.120 google.co.th
216.239.38.120 google.com.tj
-216.239.38.120 google.tk
216.239.38.120 google.tl
216.239.38.120 google.tm
216.239.38.120 google.tn
216.239.38.120 www.google.com.gi
216.239.38.120 www.google.gl
216.239.38.120 www.google.gm
-216.239.38.120 www.google.gp
216.239.38.120 www.google.gr
216.239.38.120 www.google.com.gt
216.239.38.120 www.google.gy
216.239.38.120 www.google.com.my
216.239.38.120 www.google.co.mz
216.239.38.120 www.google.com.na
-216.239.38.120 www.google.com.nf
216.239.38.120 www.google.com.ng
216.239.38.120 www.google.com.ni
216.239.38.120 www.google.ne
216.239.38.120 www.google.tg
216.239.38.120 www.google.co.th
216.239.38.120 www.google.com.tj
-216.239.38.120 www.google.tk
216.239.38.120 www.google.tl
216.239.38.120 www.google.tm
216.239.38.120 www.google.tn
-config SAMBA4_SERVER_ACL
- bool "ACL support (xattr)"
- depends on PACKAGE_samba4-server
- help
- installs: sharesec
- modules: vfs_acl_xattr vfs_acl_tdb vfs_posixacl
-
- Extended access control list support
- default n
-
-config SAMBA4_SERVER_AD_DC
- bool "Active Directory Domain Controller support (requires krb5-server) (EXPERIMENTAL)"
+config SAMBA4_SERVER_NETBIOS
+ bool "NetBIOS support"
depends on PACKAGE_samba4-server
- select PACKAGE_python-crypto
help
- installs: samba (meta-daemon) python-crypto ntlm_auth
- scripts: samba-tool
+ installs: nmbd (daemon)
- Run as a Active Directory Domain Controller
- see: https://wiki.samba.org/index.php/Setting_up_Samba_as_an_Active_Directory_Domain_Controller
- HINT: see section (# Using the Domain Controller as a File Server)
- NOTE: Extroot is recommend for this setup, as it is not optimized to run completely from RAM/tempfs!
- default n
+ Announce Samba resources via NetBIOS using the nmbd daemon
+ WSD (Web Services for Devices) replaces the functionality of NetBIOS and is provided by the wsdd2 package (selected by default).
+ Note: As of Windows 10 Fall Creators Update (1709) NetBIOS isn't supported unless the old SMB1 feature is reinstalled (not recommended).
+ Network shares can be directly accessed via network paths '\\hostname\sharename' and mounted via 'map network drive' without NetBIOS or WSD.
+ default y
config SAMBA4_SERVER_AVAHI
bool "Avahi support"
depends on PACKAGE_samba4-server
help
installs:
- modules: (vfs_btrfs) vfs_fruit vfs_shadow_copy2 vfs_recycle vfs_fake_perms vfs_readonly vfs_cap vfs_offline vfs_crossrename vfs_catia vfs_streams_xattr
+ modules: (vfs_btrfs) vfs_fruit vfs_shadow_copy2 vfs_recycle vfs_fake_perms vfs_readonly vfs_cap vfs_offline vfs_crossrename vfs_catia vfs_streams_xattr vfs_default_quota
Commonly used VFS modules, vfs_btrfs requires kmod-fs-btrfs to be selected separately
- default y
-
-config SAMBA4_SERVER_QUOTAS
- bool "Disk quota support"
- depends on PACKAGE_samba4-server
- help
- installs:
- modules: vfs_default_quota
-
- Support for disk quotas using the quotas VFS module (vfs_default_quota)
- default n
+ default y
config SAMBA4_SERVER_VFSX
bool "Extended VFS modules"
Additional VFS modules that aren't commonly used, vfs_linux_xfs_sgid requires kmod-fs-xfs to be selected separately
default n
-config SAMBA4_SERVER_NETBIOS
- bool "NetBIOS support"
- depends on PACKAGE_samba4-server
- help
- installs: nmbd (daemon)
-
- Announce Samba resources via NetBIOS using the nmbd daemon
- WSD (Web Services for Devices) replaces the functionality of NetBIOS and is provided by the wsdd2 package (selected by default).
- Note: As of Windows 10 Fall Creators Update (1709) NetBIOS isn't supported unless the old SMB1 feature is reinstalled (not recommended).
- Network shares can be directly accessed via network paths '\\hostname\sharename' and mounted via 'map network drive' without NetBIOS or WSD.
- default y
-
-config SAMBA4_SERVER_WINBIND
- bool "Winbind support"
+config SAMBA4_SERVER_AD_DC
+ bool "Active Directory Domain Controller support (EXPERIMENTAL)"
depends on PACKAGE_samba4-server
+ select SAMBA4_SERVER_VFS
help
- installs: winbindd (daemon) wbinfo
+ installs: samba (meta-daemon) PyCryptodome ntlm_auth
+ scripts: samba-tool
- Support using domain users and groups in local commands, such as chown and chgrp.
- Display domain users and groups in local command's output, such as ls.
- see: https://wiki.samba.org/index.php/Configuring_Winbindd_on_a_Samba_AD_DC
+ Run as a Active Directory Domain Controller
+ see: https://wiki.samba.org/index.php/Setting_up_Samba_as_an_Active_Directory_Domain_Controller
+ HINT: see section (# Using the Domain Controller as a File Server)
+ NOTE: Extroot is recommend for this setup, as it is not optimized to run completely from RAM/tempfs!
default n
include $(TOPDIR)/rules.mk
PKG_NAME:=samba
-PKG_VERSION:=4.9.15
+PKG_VERSION:=4.11.4
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
http://www.nic.funet.fi/index/samba/pub/samba/stable/ \
http://samba.mirror.bit.nl/samba/ftp/stable/ \
https://download.samba.org/pub/samba/stable/
-PKG_HASH:=377102b80b97941bf0d131b828cae8415190e5bdd2928c2e2c954e29f1904496
+PKG_HASH:=b95471ba450757109dce65acfe75dafc719c5cc5d464fc65ee442433a461db24
PKG_MAINTAINER:=Andy Walsh <andy.walsh44+github@gmail.com>
PKG_LICENSE:=GPL-3.0-only
PKG_LICENSE_FILES:=COPYING
PKG_CPE_ID:=cpe:/a:samba:samba
-# samba4=(asn1_compile) e2fsprogs=(compile_et) nfs-kernel-server=(rpcgen)
-HOST_BUILD_DEPENDS:=python/host nfs-kernel-server/host e2fsprogs/host
-PKG_BUILD_DEPENDS:=samba4/host
+# samba4=(asn1_compile,compile_et) rpcsvc-proto=(rpcgen)
+HOST_BUILD_DEPENDS:=python3/host perl/host
+PKG_BUILD_DEPENDS:=samba4/host libtasn1/host rpcsvc-proto/host
PKG_CONFIG_DEPENDS:= \
CONFIG_SAMBA4_SERVER_NETBIOS \
CONFIG_SAMBA4_SERVER_AVAHI \
CONFIG_SAMBA4_SERVER_VFS \
CONFIG_SAMBA4_SERVER_VFSX \
- CONFIG_SAMBA4_SERVER_QUOTAS \
- CONFIG_SAMBA4_SERVER_ACL \
CONFIG_SAMBA4_SERVER_AD_DC \
- CONFIG_SAMBA4_SERVER_WINBIND \
CONFIG_PACKAGE_kmod-fs-btrfs \
CONFIG_PACKAGE_kmod-fs-xfs
include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/version.mk
+include $(TOPDIR)/feeds/packages/lang/python/python3-host.mk
+#include $(TOPDIR)/feeds/packages/lang/python/python-package.mk
+include $(TOPDIR)/feeds/packages/lang/python/python3-package.mk
define Package/samba4/Default
SECTION:=net
define Package/samba4-libs
$(call Package/samba4/Default)
TITLE+= libs
- DEPENDS:= +zlib +libtirpc +libpopt +libcomerr +libreadline \
- +PACKAGE_libcap:libcap +PACKAGE_libpthread:libpthread +PACKAGE_libnettle:libnettle \
- +PACKAGE_libgcrypt:libgcrypt +PACKAGE_libpam:libpam +PACKAGE_dbus:dbus +PACKAGE_libavahi-client:libavahi-client \
+ DEPENDS:= +libtirpc +libreadline +libpopt +libcap +zlib +libgnutls +libtasn1 +libuuid +libopenssl +USE_GLIBC:libpthread \
+ +PACKAGE_libpam:libpam \
+SAMBA4_SERVER_VFS:attr \
- +SAMBA4_SERVER_ACL:acl +SAMBA4_SERVER_ACL:attr \
+ +SAMBA4_SERVER_VFSX:libaio \
+SAMBA4_SERVER_AVAHI:libavahi-client \
- +SAMBA4_SERVER_AD_DC:python-base +SAMBA4_SERVER_AD_DC:python-crypto +SAMBA4_SERVER_AD_DC:libopenssl +SAMBA4_SERVER_AD_DC:libgnutls +SAMBA4_SERVER_AD_DC:libopenldap +SAMBA4_SERVER_AD_DC:jansson +SAMBA4_SERVER_AD_DC:libarchive
+ +SAMBA4_SERVER_AD_DC:python3-cryptodome +SAMBA4_SERVER_AD_DC:libopenldap +SAMBA4_SERVER_AD_DC:jansson +SAMBA4_SERVER_AD_DC:libarchive +SAMBA4_SERVER_AD_DC:acl +SAMBA4_SERVER_AD_DC:attr
endef
define Package/samba4-server
$(call Package/samba4/Default)
TITLE+= server
DEPENDS:= +samba4-libs
+ CONFLICTS:=samba36-server
endef
define Package/samba4-server/description
- installs: smbd, nmbd (daemon) smbpasswd pdbedit testparm
+ installs: smbd (nmbd) smbpasswd pdbedit testparm (nmblookup) (smbcacls sharesec)
+ (samba samba-tool ntlm_auth samba-gpupdate samba_dnsupdate samba_kcc samba_spnupdate samba_upgradedns samba_downgrade_db)
This provides the basic fileserver service and is the minimum needed to serve file shares.
HINT: https://fitzcarraldoblog.wordpress.com/2016/10/17/a-correct-method-of-configuring-samba-for-browsing-smb-shares-in-a-home-network/
endef
-# BUG: We cant add DEPENDS:= +SAMBA4_SERVER_AD_DC:python-crypto, so this only happens here via select!
define Package/samba4-server/config
select PACKAGE_wsdd2
source "$(SOURCE)/Config.in"
endef
define Package/samba4-client/description
- installs: smbclient cifsdd
+ installs: cifsdd smbclient smbget
The smbclient program implements a simple ftp-like client for accessing SMB shares
endef
endef
define Package/samba4-admin/description
- installs: net smbcontrol profiles rpcclient smbcacls smbcquotas
+ installs: net smbcontrol profiles rpcclient dbwrap_tool eventlogadm
+ ldbadd ldbdel ldbedit ldbmodify ldbrename ldbsearch
+ tdbbackup tdbdump tdbrestore tdbtool
Administration tools collection
endef
endef
define Package/samba4-utils/description
- installs: smbstatus smbtree smbget nmblookup mvxattr
+ installs: smbstatus smbtree mvxattr smbtar smbcquotas
Utilities collection
endef
-TARGET_CFLAGS += -ffunction-sections -fdata-sections
-TARGET_LDFLAGS += -Wl,--gc-sections
+TARGET_CFLAGS += $(FPIC) -ffunction-sections -fdata-sections -I$(STAGING_DIR)/usr/include/tirpc
+TARGET_LDFLAGS += -Wl,--gc-sections,--as-needed
+# dont mess with sambas private rpath!
+RSTRIP:=:
CONFIGURE_VARS += \
CPP="$(TARGET_CROSS)cpp"
--disable-cephfs \
--disable-fault-handling \
--disable-glusterfs \
- --disable-rpath \
- --disable-rpath-install \
- --disable-rpath-private-install \
--enable-fhs \
--without-automount \
--without-iconv \
--without-gpgme
HOST_CONFIGURE_ARGS += --disable-avahi --without-quotas --without-acl-support --without-winbind \
- --without-ad-dc --without-json-audit --without-libarchive --disable-python --nopyc --nopyo \
- --disable-gnutls --without-dnsupdate --without-ads --without-ldap
+ --without-ad-dc --without-json --without-libarchive --disable-python --nopyc --nopyo \
+ --without-dnsupdate --without-ads --without-ldap --without-ldb-lmdb
HOST_CONFIGURE_VARS += python_LDFLAGS="" python_LIBDIR=""
# Optional AES-NI support - https://lists.samba.org/archive/samba-technical/2017-September/122738.html
--with-piddir=/var/run \
--with-privatedir=/etc/samba
-ifeq ($(CONFIG_SAMBA4_SERVER_AVAHI),y)
- CONFIGURE_ARGS += --enable-avahi
-else
- CONFIGURE_ARGS += --disable-avahi
-endif
-ifeq ($(CONFIG_SAMBA4_SERVER_QUOTAS),y)
+# features
+ifeq ($(CONFIG_SAMBA4_SERVER_VFS),y)
CONFIGURE_ARGS += --with-quotas
else
CONFIGURE_ARGS += --without-quotas
endif
-ifeq ($(CONFIG_SAMBA4_SERVER_ACL),y)
- CONFIGURE_ARGS += --with-acl-support
+ifeq ($(CONFIG_SAMBA4_SERVER_AVAHI),y)
+ CONFIGURE_ARGS += --enable-avahi
else
- CONFIGURE_ARGS += --without-acl-support
+ CONFIGURE_ARGS += --disable-avahi
endif
+
+# NOTE: We need host python-bin, but target python-config here!
+CONFIGURE_VARS += python_LDFLAGS="" python_LIBDIR=""
ifeq ($(CONFIG_SAMBA4_SERVER_AD_DC),y)
- CONFIGURE_ARGS += --enable-gnutls --with-dnsupdate --with-ads --with-ldap
- TARGET_CFLAGS := -I$(STAGING_DIR)/usr/include/python2.7 $(TARGET_CFLAGS)
-else
- CONFIGURE_ARGS += --without-ad-dc --without-json-audit --without-libarchive --disable-python --nopyc --nopyo \
- --disable-gnutls --without-dnsupdate --without-ads --without-ldap
+ CONFIGURE_ARGS += --without-winbind --without-ldb-lmdb --with-acl-support
CONFIGURE_VARS += \
- python_LDFLAGS="" \
- python_LIBDIR=""
-endif
-ifeq ($(CONFIG_SAMBA4_SERVER_WINBIND),y)
- CONFIGURE_ARGS += --with-winbind
+ PYTHON="$(HOST_PYTHON3_BIN)" \
+ PYTHON_CONFIG="$(STAGING_DIR)/host/bin/$(PYTHON3)-config"
else
- CONFIGURE_ARGS += --without-winbind
+ CONFIGURE_ARGS += --without-winbind --without-ads --without-ldap --without-ldb-lmdb --without-ad-dc \
+ --without-json --without-libarchive --disable-python --nopyc --nopyo --without-dnsupdate --without-acl-support
endif
-SAMBA4_IDMAP_MODULES :=
-SAMBA4_IDMAP_MODULES_SHARED :=
SAMBA4_PDB_MODULES :=pdb_smbpasswd,pdb_tdbsam,
SAMBA4_AUTH_MODULES :=auth_builtin,auth_sam,auth_unix,auth_script,
SAMBA4_VFS_MODULES :=vfs_default,
SAMBA4_VFS_MODULES_SHARED :=
ifeq ($(CONFIG_SAMBA4_SERVER_VFS),y)
- SAMBA4_VFS_MODULES_SHARED :=$(SAMBA4_VFS_MODULES_SHARED)vfs_fruit,vfs_shadow_copy2,vfs_recycle,vfs_fake_perms,vfs_readonly,vfs_cap,vfs_offline,vfs_crossrename,vfs_catia,vfs_streams_xattr,vfs_xattr_tdb,
+ SAMBA4_VFS_MODULES_SHARED :=$(SAMBA4_VFS_MODULES_SHARED)vfs_fruit,vfs_shadow_copy2,vfs_recycle,vfs_fake_perms,vfs_readonly,vfs_cap,vfs_offline,vfs_crossrename,vfs_catia,vfs_streams_xattr,vfs_xattr_tdb,vfs_default_quota,
ifeq ($(CONFIG_PACKAGE_kmod-fs-btrfs),y)
SAMBA4_VFS_MODULES_SHARED :=$(SAMBA4_VFS_MODULES_SHARED)vfs_btrfs,
endif
SAMBA4_VFS_MODULES_SHARED :=$(SAMBA4_VFS_MODULES_SHARED)vfs_linux_xfs_sgid,
endif
endif
-ifeq ($(CONFIG_SAMBA4_SERVER_QUOTAS),y)
- SAMBA4_VFS_MODULES_SHARED :=$(SAMBA4_VFS_MODULES_SHARED)vfs_default_quota,
-endif
-ifeq ($(CONFIG_SAMBA4_SERVER_ACL),y)
- SAMBA4_VFS_MODULES :=$(SAMBA4_VFS_MODULES)vfs_posixacl,
- SAMBA4_VFS_MODULES_SHARED :=$(SAMBA4_VFS_MODULES_SHARED)vfs_acl_xattr,vfs_acl_tdb,
- # vfs_zfsacl needs https://github.com/zfsonlinux/zfs/tree/master/include/sys/zfs_acl.h
- # vfs_nfs4acl_xattr needs https://github.com/notriddle/libdrpc/blob/master/rpc/xdr.h
-endif
ifeq ($(CONFIG_SAMBA4_SERVER_AD_DC),y)
SAMBA4_PDB_MODULES :=$(SAMBA4_PDB_MODULES)pdb_samba_dsdb,pdb_ldapsam,
SAMBA4_AUTH_MODULES :=$(SAMBA4_AUTH_MODULES)auth_samba4,
- SAMBA4_VFS_MODULES_SHARED :=$(SAMBA4_VFS_MODULES_SHARED)vfs_audit,vfs_extd_audit,vfs_full_audit,
-endif
-ifeq ($(CONFIG_SAMBA4_SERVER_WINBIND),y)
- SAMBA4_IDMAP_MODULES :=$(SAMBA4_IDMAP_MODULES)idmap_tdb,idmap_passdb,idmap_nss,nss_info_template,
- SAMBA4_IDMAP_MODULES_SHARED :=$(SAMBA4_IDMAP_MODULES_SHARED)idmap_autorid,idmap_rid,idmap_hash,idmap_tdb2,idmap_script,
-ifeq ($(CONFIG_SAMBA4_SERVER_AD_DC),y)
- SAMBA4_IDMAP_MODULES_SHARED :=$(SAMBA4_IDMAP_MODULES_SHARED)idmap_ad,idmap_ldap,idmap_rfc2307,
- # idmap_ad needs --with-ads
- # idmap_rfc2307 needs ldap headers
-endif
- SAMBA4_AUTH_MODULES :=$(SAMBA4_AUTH_MODULES)auth_winbind,
+ SAMBA4_VFS_MODULES :=$(SAMBA4_VFS_MODULES)vfs_posixacl,
+ SAMBA4_VFS_MODULES_SHARED :=$(SAMBA4_VFS_MODULES_SHARED)vfs_audit,vfs_extd_audit,vfs_full_audit,vfs_acl_xattr,vfs_acl_tdb,
+ # vfs_zfsacl needs https://github.com/zfsonlinux/zfs/tree/master/include/sys/zfs_acl.h
+ # vfs_nfs4acl_xattr needs https://github.com/notriddle/libdrpc/blob/master/rpc/xdr.h
endif
-SAMBA4_MODULES :=${SAMBA4_VFS_MODULES}${SAMBA4_AUTH_MODULES}${SAMBA4_PDB_MODULES}${SAMBA4_IDMAP_MODULES}
-SAMBA4_MODULES_SHARDED :=${SAMBA4_VFS_MODULES_SHARED}${SAMBA4_IDMAP_MODULES_SHARED}
+SAMBA4_MODULES :=${SAMBA4_VFS_MODULES}${SAMBA4_AUTH_MODULES}${SAMBA4_PDB_MODULES}
+SAMBA4_MODULES_SHARDED :=${SAMBA4_VFS_MODULES_SHARED}
CONFIGURE_ARGS += \
--with-static-modules=$(SAMBA4_MODULES)!DEFAULT,!FORCED \
--with-static-modules=!DEFAULT,!FORCED \
--with-shared-modules=!DEFAULT,!FORCED
-# Setup build/install targets
-# CONFIG_PACKAGE_samba4-server
-BUILD_TARGETS_SERVER :=smbd/smbd,smbpasswd,pdbedit,testparm
-# Optional server targets
-ifeq ($(CONFIG_SAMBA4_SERVER_ACL),y)
- BUILD_TARGETS_SERVER :=$(BUILD_TARGETS_SERVER),sharesec
-endif
-ifeq ($(CONFIG_SAMBA4_SERVER_NETBIOS),y)
- BUILD_TARGETS_SERVER :=$(BUILD_TARGETS_SERVER),nmbd
-endif
-ifeq ($(CONFIG_SAMBA4_SERVER_AD_DC),y)
- BUILD_TARGETS_SERVER :=$(BUILD_TARGETS_SERVER),samba,nsstest,ntlm_auth,samba4kinit,samba4kgetcred,samba4kpasswd,samba4ktutil
-endif
-ifeq ($(CONFIG_SAMBA4_SERVER_WINBIND),y)
- BUILD_TARGETS_SERVER :=$(BUILD_TARGETS_SERVER),winbindd,wbinfo,winbind_krb5_locator
-endif
-# CONFIG_PACKAGE_samba4-client
-BUILD_TARGETS_CLIENT :=client/smbclient,client/cifsdd
-# CONFIG_PACKAGE_samba4-admin
-BUILD_TARGETS_ADMIN :=net,smbcontrol,profiles,rpcclient,smbcacls,smbcquotas,eventlogadm
-# CONFIG_PACKAGE_samba4-utils
-BUILD_TARGETS_UTILS :=smbstatus,smbtree,smbget,mvxattr,nmblookup
-
# lib bundling
+PY_VER:=$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR)
# NOTE: bundle + make private, we want to avoid version configuration (build, link) conflicts
-CONFIGURE_ARGS += --builtin-libraries=talloc,tevent,tevent-util,texpect,tdb,ldb,tdr,cmocka
-HOST_CONFIGURE_ARGS += --builtin-libraries=replace --nonshared-binary=asn1_compile
-
+HOST_CONFIGURE_ARGS += --builtin-libraries=replace --nonshared-binary=asn1_compile,compile_et
+SYSTEM_BUNDLED_LIBS:=talloc,tevent,tevent-util,texpect,tdb,ldb,tdr,cmocka,replace,com_err
+PYTHON_BUNDLED_LIBS:=pytalloc-util.cpython-$(PY_VER),pyldb-util.cpython-$(PY_VER)
+# CONFIGURE_ARGS += --builtin-libraries=talloc,tevent,tevent-util,texpect,tdb,ldb,tdr,cmocka,com_err
ifeq ($(CONFIG_SAMBA4_SERVER_AD_DC),y)
-CONFIGURE_ARGS += --bundled-libraries=talloc,tevent,tevent-util,texpect,tdb,ldb,tdr,cmocka,replace,pytalloc-util,pyldb-util,roken,wind,hx509,asn1,heimbase,hcrypto,krb5,gssapi,heimntlm,hdb,kdc,NONE
+ CONFIGURE_ARGS += --bundled-libraries=NONE,$(SYSTEM_BUNDLED_LIBS),$(PYTHON_BUNDLED_LIBS)
else
-CONFIGURE_ARGS += --bundled-libraries=talloc,tevent,tevent-util,texpect,tdb,ldb,tdr,cmocka,replace,roken,wind,hx509,asn1,heimbase,hcrypto,krb5,gssapi,heimntlm,hdb,kdc,NONE
+ CONFIGURE_ARGS += --bundled-libraries=NONE,$(SYSTEM_BUNDLED_LIBS)
endif
-# BUG: --private-libraries, Does not work for System possible libs, will not get "samba4" suffix!
-CONFIGURE_ARGS += --private-libraries=talloc,tevent,tevent-util,texpect,tdb,ldb,tdr,cmocka,replace
-# CONFIGURE_ARGS += --disable-symbol-versions
+CONFIGURE_ARGS += --private-libraries=$(SYSTEM_BUNDLED_LIBS)
+export COMPILE_ET=$(STAGING_DIR_HOSTPKG)/bin/compile_et_samba
+export ASN1_COMPILE=$(STAGING_DIR_HOSTPKG)/bin/asn1_compile_samba
+
+# we dont need GnuTLS for the host helpers
+define Host/Prepare
+ $(call Host/Prepare/Default)
+ $(SED) 's,mandatory=True,mandatory=False,g' $(HOST_BUILD_DIR)/wscript_configure_system_gnutls
+endef
define Host/Compile
(cd $(HOST_BUILD_DIR); \
./buildtools/bin/waf build \
- --targets=asn1_compile \
+ --targets=asn1_compile,compile_et \
)
endef
define Host/Install
$(INSTALL_DIR) $(STAGING_DIR_HOSTPKG)/bin/
- $(INSTALL_BIN) $(HOST_BUILD_DIR)/bin/asn1_compile $(STAGING_DIR_HOSTPKG)/bin/
+ # add host tools suffix, prevent conflicts with krb5
+ $(INSTALL_BIN) $(HOST_BUILD_DIR)/bin/asn1_compile $(STAGING_DIR_HOSTPKG)/bin/asn1_compile_samba
+ $(INSTALL_BIN) $(HOST_BUILD_DIR)/bin/compile_et $(STAGING_DIR_HOSTPKG)/bin/compile_et_samba
endef
define Build/Prepare
define Build/Configure
$(CP) ./waf-cross-answers/$(ARCH).txt $(PKG_BUILD_DIR)/cross-answers.txt
+ echo 'Checking uname sysname type: "$(VERSION_DIST)"' >> $(PKG_BUILD_DIR)/cross-answers.txt
echo 'Checking uname machine type: "$(ARCH)"' >> $(PKG_BUILD_DIR)/cross-answers.txt
echo 'Checking uname release type: "$(LINUX_VERSION)"' >> $(PKG_BUILD_DIR)/cross-answers.txt
echo 'Checking uname version type: "$(VERSION_DIST) Linux-$(LINUX_VERSION) $(shell date +%Y-%m-%d)"' >> $(PKG_BUILD_DIR)/cross-answers.txt
- # NOTE: For some unknown reason this answer is not needed on some hosts/distros, yet needed on others?
+ # NOTE: special answers for freeBSD/CircleCI
echo 'Checking whether POSIX capabilities are available: OK' >> $(PKG_BUILD_DIR)/cross-answers.txt
+ echo 'checking for clnt_create(): OK' >> $(PKG_BUILD_DIR)/cross-answers.txt
$(call Build/Configure/Default)
endef
-# BUG: We need to use "waf install --targets=" otherwise a "make install" or "waf install" will retrigger a full recompile of all possible targets!
+# Build via "waf install", avoid the make wrapper. (Samba logic is 'waf install' = build + install)
define Build/Compile
(cd $(PKG_BUILD_DIR); \
./buildtools/bin/waf install \
--jobs=$(shell nproc) \
--destdir="$(PKG_INSTALL_DIR)" \
- --targets=$(SAMBA4_MODULES)$(SAMBA4_MODULES_SHARDED)$(BUILD_TARGETS_SERVER),$(BUILD_TARGETS_UTILS),$(BUILD_TARGETS_ADMIN),$(BUILD_TARGETS_CLIENT) \
)
endef
define Package/samba4-libs/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/*.so* $(1)/usr/lib/
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/samba/*.so* $(1)/usr/lib/
-
- $(INSTALL_DIR) $(1)/usr/lib/samba/vfs $(1)/usr/lib/samba/idmap $(1)/usr/lib/samba/ldb $(1)/usr/lib/samba/krb5
- if [ -d $(PKG_INSTALL_DIR)/usr/lib/samba/idmap ]; then \
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/samba/idmap $(1)/usr/lib/samba/; \
- fi
- if [ -d $(PKG_INSTALL_DIR)/usr/lib/samba/vfs ]; then \
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/samba/vfs $(1)/usr/lib/samba/; \
- fi
- if [ -d $(PKG_INSTALL_DIR)/usr/lib/samba/krb5 ]; then \
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/samba/krb5 $(1)/usr/lib/samba/; \
- fi
-ifeq ($(CONFIG_SAMBA4_SERVER_AD_DC),y)
- $(INSTALL_DIR) $(1)/usr/lib/python2.7
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/python2.7 $(1)/usr/lib/
-endif
+ # rpath-install
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/samba $(1)/usr/lib/
endef
define Package/samba4-client/install
$(INSTALL_DIR) $(1)/usr/bin
- $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{smbclient,cifsdd} $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{cifsdd,smbclient,smbget} $(1)/usr/bin/
endef
define Package/samba4-admin/install
$(INSTALL_DIR) $(1)/usr/bin
- $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{net,smbcontrol,profiles,rpcclient,smbcacls,smbcquotas} $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{net,smbcontrol,profiles,rpcclient,dbwrap_tool} $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{ldbadd,ldbdel,ldbedit,ldbmodify,ldbrename,ldbsearch} $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{tdbbackup,tdbdump,tdbrestore,tdbtool} $(1)/usr/bin/
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/eventlogadm $(1)/usr/sbin/
endef
define Package/samba4-utils/install
$(INSTALL_DIR) $(1)/usr/bin
- $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{smbstatus,smbtree,smbget,mvxattr,nmblookup} $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{smbstatus,smbtree,mvxattr,smbtar} $(1)/usr/bin/
+ifeq ($(CONFIG_SAMBA4_SERVER_VFS),y)
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/smbcquotas $(1)/usr/bin/
+endif
endef
define Package/samba4-server/install
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{smbpasswd,pdbedit,testparm} $(1)/usr/bin/
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/smbd $(1)/usr/sbin/
-ifeq ($(CONFIG_SAMBA4_SERVER_AD_DC),y)
- $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{samba-tool,ntlm_auth,smbtar} $(1)/usr/bin/
- $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/{samba,samba-gpupdate,samba_dnsupdate,samba_kcc,samba_spnupdate,samba_upgradedns} $(1)/usr/sbin/
- # waf does not install those?
- $(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/{samba4kinit,samba4kgetcred,samba4kpasswd,samba4ktutil} $(1)/usr/bin/
-endif
ifeq ($(CONFIG_SAMBA4_SERVER_NETBIOS),y)
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/nmbd $(1)/usr/sbin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nmblookup $(1)/usr/bin/
endif
-ifeq ($(CONFIG_SAMBA4_SERVER_WINBIND),y)
- $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wbinfo $(1)/usr/bin/
- $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/winbindd $(1)/usr/sbin/
-endif
-ifeq ($(CONFIG_SAMBA4_SERVER_ACL),y)
- $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/sharesec $(1)/usr/bin/
+ifeq ($(CONFIG_SAMBA4_SERVER_AD_DC),y)
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/$(PYTHON3) $(1)/usr/lib/
+ $(INSTALL_DIR) $(1)/usr/share/
+ $(CP) $(PKG_INSTALL_DIR)/usr/share/samba $(1)/usr/share/
+ # fix wrong hardcoded python3 location
+ $(SED) '1s,^#!/.*python3.*,#!/usr/bin/python3,' $(PKG_INSTALL_DIR)/usr/bin/samba-tool
+ $(SED) '1s,^#!/.*python3.*,#!/usr/bin/python3,' $(PKG_INSTALL_DIR)/usr/sbin/{samba-gpupdate,samba_dnsupdate,samba_kcc,samba_spnupdate,samba_upgradedns,samba_downgrade_db}
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{samba-tool,ntlm_auth,oLschema2ldif} $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{sharesec,smbcacls} $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/{samba,samba-gpupdate,samba_dnsupdate,samba_kcc,samba_spnupdate,samba_upgradedns,samba_downgrade_db} $(1)/usr/sbin/
endif
$(INSTALL_DIR) $(1)/etc/config $(1)/etc/samba $(1)/etc/init.d
$(INSTALL_CONF) ./files/samba.config $(1)/etc/config/samba4
/etc/samba/smbpasswd
/etc/samba/secrets.tdb
/etc/samba/passdb.tdb
-/etc/samba/idmap.ldb
/etc/samba/lmhosts
/etc/nsswitch.conf
/etc/krb5.conf
START=98
USE_PROCD=1
+SAMBA_IFACE=""
+
smb_header() {
- config_get samba_iface $1 interface "loopback lan"
+ config_get SAMBA_IFACE $1 interface "lan"
# resolve interfaces
local interfaces
. /lib/functions/network.sh
local net
- for net in $samba_iface; do
+ for net in $SAMBA_IFACE; do
local device
network_is_up $net || continue
network_get_device device "$net"
[ -e /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
- if ! [ -L /etc/samba/smb.conf ]; then
- logger -t 'samba4-server' "Local custom /etc/samba/smb.conf file detected, all luci/config settings are ignored!"
+ if [ ! -L /etc/samba/smb.conf ]; then
+ logger -p daemon.warn -t 'samba4-server' "Local custom /etc/samba/smb.conf file detected, all luci/config settings are ignored!"
fi
}
}
service_triggers() {
- PROCD_RELOAD_DELAY=2000
+ # PROCD_RELOAD_DELAY=1000
procd_add_reload_trigger "dhcp" "system" "samba4"
local i
- for i in $samba_iface; do
+ for i in $SAMBA_IFACE; do
procd_add_reload_interface_trigger $i
done
}
start_service() {
init_config
+
+ if [ ! -e /etc/samba/smb.conf ]; then
+ logger -p daemon.error -t 'samba4-server' "missing config /etc/samba/smb.conf!"
+ exit 1
+ fi
+
+ local nice_value
+ config_get nice_value extra samba_nice 0
# start main AD-DC daemon, will spawn (smbd,nmbd,winbindd) as needed/configured.
if [ "$DISABLE_AD_DC" -ne 1 ] && [ -x /usr/sbin/samba ]; then
procd_open_instance
procd_set_param command /usr/sbin/samba -F
+ procd_set_param nice $nice_value
procd_set_param respawn
- procd_set_param file /var/etc/smb.conf
+ procd_set_param file /etc/samba/smb.conf
+ procd_set_param limits nofile=16384
procd_close_instance
else
# start fileserver daemon
procd_open_instance
procd_set_param command /usr/sbin/smbd -F
+ procd_set_param nice $nice_value
procd_set_param respawn
- procd_set_param file /var/etc/smb.conf
+ procd_set_param file /etc/samba/smb.conf
+ procd_set_param limits nofile=16384
procd_close_instance
# start netbios daemon
if [ "$DISABLE_NETBIOS" -ne 1 ] && [ -x /usr/sbin/nmbd ]; then
procd_open_instance
procd_set_param command /usr/sbin/nmbd -F
+ procd_set_param nice $nice_value
procd_set_param respawn
- procd_set_param file /var/etc/smb.conf
+ procd_set_param file /etc/samba/smb.conf
procd_close_instance
fi
# start winbind daemon
if [ "$DISABLE_WINBIND" -ne 1 ] && [ -x /usr/sbin/winbindd ]; then
procd_open_instance
procd_set_param command /usr/sbin/winbindd -F
+ procd_set_param nice $nice_value
procd_set_param respawn
- procd_set_param file /var/etc/smb.conf
+ procd_set_param file /etc/samba/smb.conf
procd_close_instance
fi
fi
- # lower priority using renice (if found)
- if [ -x /usr/bin/renice ]; then
- [ -x /usr/sbin/samba ] && renice -n 2 $(pidof samba)
- [ -x /usr/sbin/smbd ] && renice -n 2 $(pidof smbd)
- [ -x /usr/sbin/nmbd ] && renice -n 2 $(pidof nmbd)
- [ -x /usr/sbin/winbindd ] && renice -n 2 $(pidof winbindd)
- fi
}
--- /dev/null
+diff --git a/source4/torture/local/nss_tests.c b/source4/torture/local/nss_tests.c
+index 2cd6122..04f13c6 100644
+--- a/source4/torture/local/nss_tests.c
++++ b/source4/torture/local/nss_tests.c
+@@ -247,7 +247,6 @@ static bool test_getgrnam_r(struct torture_context *tctx,
+ return true;
+ }
+
+-
+ static bool test_getgrgid(struct torture_context *tctx,
+ gid_t gid,
+ struct group *grp_p)
+@@ -333,6 +332,7 @@ static bool test_enum_passwd(struct torture_context *tctx,
+ return true;
+ }
+
++#if HAVE_GETPWENT_R
+ static bool test_enum_r_passwd(struct torture_context *tctx,
+ struct passwd **pwd_array_p,
+ size_t *num_pwd_p)
+@@ -381,6 +381,7 @@ static bool test_enum_r_passwd(struct torture_context *tctx,
+
+ return true;
+ }
++#endif
+
+ static bool torture_assert_passwd_equal(struct torture_context *tctx,
+ const struct passwd *p1,
+@@ -432,7 +433,7 @@ static bool test_passwd_r(struct torture_context *tctx)
+ struct passwd *pwd, pwd1, pwd2;
+ size_t num_pwd;
+
+- torture_assert(tctx, test_enum_r_passwd(tctx, &pwd, &num_pwd),
++ torture_assert(tctx, test_enum_passwd(tctx, &pwd, &num_pwd),
+ "failed to enumerate passwd");
+
+ for (i=0; i < num_pwd; i++) {
+@@ -460,7 +461,7 @@ static bool test_passwd_r_cross(struct torture_context *tctx)
+ struct passwd *pwd, pwd1, pwd2, pwd3, pwd4;
+ size_t num_pwd;
+
+- torture_assert(tctx, test_enum_r_passwd(tctx, &pwd, &num_pwd),
++ torture_assert(tctx, test_enum_passwd(tctx, &pwd, &num_pwd),
+ "failed to enumerate passwd");
+
+ for (i=0; i < num_pwd; i++) {
+@@ -531,6 +532,7 @@ static bool test_enum_group(struct torture_context *tctx,
+ return true;
+ }
+
++#if HAVE_GETGRENT_R
+ static bool test_enum_r_group(struct torture_context *tctx,
+ struct group **grp_array_p,
+ size_t *num_grp_p)
+@@ -579,6 +581,7 @@ static bool test_enum_r_group(struct torture_context *tctx,
+
+ return true;
+ }
++#endif
+
+ static bool torture_assert_group_equal(struct torture_context *tctx,
+ const struct group *g1,
+@@ -635,7 +638,7 @@ static bool test_group_r(struct torture_context *tctx)
+ struct group *grp, grp1, grp2;
+ size_t num_grp;
+
+- torture_assert(tctx, test_enum_r_group(tctx, &grp, &num_grp),
++ torture_assert(tctx, test_enum_group(tctx, &grp, &num_grp),
+ "failed to enumerate group");
+
+ for (i=0; i < num_grp; i++) {
+@@ -663,7 +666,7 @@ static bool test_group_r_cross(struct torture_context *tctx)
+ struct group *grp, grp1, grp2, grp3, grp4;
+ size_t num_grp;
+
+- torture_assert(tctx, test_enum_r_group(tctx, &grp, &num_grp),
++ torture_assert(tctx, test_enum_group(tctx, &grp, &num_grp),
+ "failed to enumerate group");
+
+ for (i=0; i < num_grp; i++) {
--- /dev/null
+diff --git a/lib/param/loadparm.h b/lib/param/loadparm.h
+index b5d79b9..3f4eae0 100644
+--- a/lib/param/loadparm.h
++++ b/lib/param/loadparm.h
+@@ -31,6 +31,7 @@
+ #define _LOADPARM_H
+
+ #include <talloc.h>
++#include <time.h>
+
+ struct parmlist_entry {
+ struct parmlist_entry *prev, *next;
+diff --git a/source3/lib/system_smbd.c b/source3/lib/system_smbd.c
+index 3b1ac9c..4044d75 100644
+--- a/source3/lib/system_smbd.c
++++ b/source3/lib/system_smbd.c
+@@ -27,6 +27,8 @@
+ #include "system/passwd.h"
+ #include "nsswitch/winbind_client.h"
+ #include "../lib/util/setid.h"
++#include <grp.h>
++#include <uuid/uuid.h>
+
+ #ifndef HAVE_GETGROUPLIST
+
+diff --git a/source4/torture/local/nss_tests.c b/source4/torture/local/nss_tests.c
+index 2cd6122..0c84ec2 100644
+--- a/source4/torture/local/nss_tests.c
++++ b/source4/torture/local/nss_tests.c
+@@ -20,6 +20,8 @@
+ */
+
+ #include "includes.h"
++#include <grp.h>
++#include <uuid/uuid.h>
+
+ #include "torture/torture.h"
+ #include "torture/local/proto.h"
--- /dev/null
+commit f81e5b71ce78f33250347914dacc75c8463bf102
+Author: Breno Leitao <breno.leitao@gmail.com>
+Date: Wed Mar 29 15:22:38 2017 -0300
+
+ include: Check for previous declaration of uintptr_t
+
+ Adding a extra check before declaring uintptr_t. Currently musl uses
+ macro __DEFINED_uintptr_t once it defines uintptr_t type. Checking
+ this macro before defining it, and, defining it when uintptr_t is
+ defined.
+
+ Signed-off-by: Breno Leitao <breno.leitao@gmail.com>
+
+diff --git a/third_party/cmocka/cmocka.h b/third_party/cmocka/cmocka.h
+index 303d0ae..a2bfc40 100644
+--- a/third_party/cmocka/cmocka.h
++++ b/third_party/cmocka/cmocka.h
+@@ -110,7 +110,7 @@
+ ((LargestIntegralType)(value))
+
+ /* Smallest integral type capable of holding a pointer. */
+-#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
++#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) && !defined(__DEFINED_uintptr_t)
+ # if defined(_WIN32)
+ /* WIN32 is an ILP32 platform */
+ typedef unsigned int uintptr_t;
+@@ -136,6 +136,8 @@
+
+ # define _UINTPTR_T
+ # define _UINTPTR_T_DEFINED
++# define __DEFINED_uintptr_t
++
+ #endif /* !defined(_UINTPTR_T) || !defined(_UINTPTR_T_DEFINED) */
+
+ /* Perform an unsigned cast to uintptr_t. */
--- /dev/null
+diff --git a/nsswitch/wins.c b/nsswitch/wins.c
+index dccb6dd..bb24acb 100644
+--- a/nsswitch/wins.c
++++ b/nsswitch/wins.c
+@@ -39,6 +39,14 @@ static pthread_mutex_t wins_nss_mutex = PTHREAD_MUTEX_INITIALIZER;
+ #define INADDRSZ 4
+ #endif
+
++#ifndef NETDB_INTERNAL
++#define NETDB_INTERNAL -1
++#endif
++
++#ifndef NETDB_SUCCESS
++#define NETDB_SUCCESS 0
++#endif
++
+ NSS_STATUS _nss_wins_gethostbyname_r(const char *hostname,
+ struct hostent *he,
+ char *buffer,
--- /dev/null
+From d90534469c5c43bf2a97e5698a5ddb4b7471f92a Mon Sep 17 00:00:00 2001
+From: Changqing Li <changqing.li@windriver.com>
+Date: Tue, 24 Jul 2018 10:53:16 +0800
+Subject: [PATCH] libldb: fix musl libc unkoown type error
+
+tevent.h:1440:8: error: unknown type name 'pid_t'; did you mean 'div_t'?
+ pid_t *pid,
+ ^~~~~
+ div_t
+
+Signed-off-by: Changqing Li <changqing.li@windriver.com>
+---
+ lib/tevent/tevent.h | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h
+index aa6fe0d..2572696 100644
+--- a/lib/tevent/tevent.h
++++ b/lib/tevent/tevent.h
+@@ -32,6 +32,8 @@
+ #include <talloc.h>
+ #include <sys/time.h>
+ #include <stdbool.h>
++#include <sys/stat.h>
++#include <sys/types.h>
+
+ struct tevent_context;
+ struct tevent_ops;
+--
+2.7.4
+
--- /dev/null
+--- a/source4/dsdb/samdb/ldb_modules/count_attrs.c
++++ b/source4/dsdb/samdb/ldb_modules/count_attrs.c
+@@ -38,6 +38,11 @@
+ #define NULL_REQ_PSEUDO_N -2LL;
+ #define STAR_REQ_PSEUDO_N -4LL;
+
++#ifndef __COMPAR_FN_T
++#define __COMPAR_FN_T
++typedef int (*__compar_fn_t)(const void *, const void *);
++#endif
++
+ struct count_attrs_private {
+ struct tdb_wrap *requested;
+ struct tdb_wrap *duplicates;
--- /dev/null
+diff --git a/source4/dsdb/samdb/ldb_modules/count_attrs.c b/source4/dsdb/samdb/ldb_modules/count_attrs.c
+index b0d1b22..29f1b94 100644
+--- a/source4/dsdb/samdb/ldb_modules/count_attrs.c
++++ b/source4/dsdb/samdb/ldb_modules/count_attrs.c
+@@ -222,7 +222,7 @@ static const char **get_sorted_attrs(TALLOC_CTX *mem_ctx,
+ attrs[i] = a;
+ }
+
+- qsort(attrs, n_attrs, sizeof(char *), (__compar_fn_t)strcasecmp_ptr);
++ qsort(attrs, n_attrs, sizeof(char *), (int (*)(const void *, const void *))strcasecmp_ptr);
+ return attrs;
+ }
+
+@@ -313,7 +313,7 @@ static int count_attrs_search_callback(struct ldb_request *req,
+ }
+
+ qsort(found_attrs, msg->num_elements, sizeof(char *),
+- (__compar_fn_t)strcasecmp_ptr);
++ (int (*)(const void *, const void *))strcasecmp_ptr);
+
+
+ /* find and report duplicates */
--- /dev/null
+--- a/wscript_configure_embedded_heimdal 2019-12-17
++++ b/wscript_configure_embedded_heimdal 2019-12-17
+@@ -1 +1,12 @@
+ conf.RECURSE('source4/heimdal_build')
++
++def check_system_heimdal_binary(name):
++ if conf.LIB_MAY_BE_BUNDLED(name):
++ return False
++ if not conf.find_program(name, var=name.upper()):
++ return False
++ conf.define('USING_SYSTEM_%s' % name.upper(), 1)
++ return True
++
++check_system_heimdal_binary("compile_et")
++check_system_heimdal_binary("asn1_compile")
+--- a/wscript_configure_system_heimdal 2019-12-17
++++ b/wscript_configure_system_heimdal 2019-12-17
+@@ -37,14 +37,6 @@ def check_system_heimdal_lib(name, funct
+ conf.define('USING_SYSTEM_%s' % name.upper(), 1)
+ return True
+
+-def check_system_heimdal_binary(name):
+- if conf.LIB_MAY_BE_BUNDLED(name):
+- return False
+- if not conf.find_program(name, var=name.upper()):
+- return False
+- conf.define('USING_SYSTEM_%s' % name.upper(), 1)
+- return True
+-
+ check_system_heimdal_lib("com_err", "com_right_r com_err", "com_err.h")
+
+ if check_system_heimdal_lib("roken", "rk_socket_set_reuseaddr", "roken.h"):
+@@ -96,7 +88,4 @@ finally:
+ #if conf.CHECK_BUNDLED_SYSTEM('tommath', checkfunctions='mp_init', headers='tommath.h'):
+ # conf.define('USING_SYSTEM_TOMMATH', 1)
+
+-check_system_heimdal_binary("compile_et")
+-check_system_heimdal_binary("asn1_compile")
+-
+ conf.define('USING_SYSTEM_KRB5', 1)
+++ /dev/null
---- a/source3/lib/messages.c
-+++ b/source3/lib/messages.c
-@@ -518,7 +518,7 @@ static NTSTATUS messaging_init_internal(
- return NT_STATUS_ACCESS_DENIED;
- }
-
-- priv_path = private_path("msg.sock");
-+ priv_path = lock_path("msg.sock");
- if (priv_path == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-@@ -662,7 +662,7 @@ NTSTATUS messaging_reinit(struct messagi
-
- msg_ctx->msg_dgm_ref = messaging_dgm_ref(
- msg_ctx, msg_ctx->event_ctx, &msg_ctx->id.unique_id,
-- private_path("msg.sock"), lck_path,
-+ lock_path("msg.sock"), lck_path,
- messaging_recv_cb, msg_ctx, &ret);
-
- if (msg_ctx->msg_dgm_ref == NULL) {
+++ /dev/null
---- a/source4/lib/messaging/messaging.c
-+++ b/source4/lib/messaging/messaging.c
-@@ -350,7 +350,7 @@ static struct imessaging_context *imessa
- goto fail;
- }
-
-- msg->sock_dir = lpcfg_private_path(msg, lp_ctx, "msg.sock");
-+ msg->sock_dir = lpcfg_lock_path(msg, lp_ctx, "msg.sock");
- if (msg->sock_dir == NULL) {
- goto fail;
- }
--- /dev/null
+--- a/source3/lib/messages.c
++++ b/source3/lib/messages.c
+@@ -518,7 +518,7 @@ static NTSTATUS messaging_init_internal(
+ return NT_STATUS_ACCESS_DENIED;
+ }
+
+- priv_path = private_path("msg.sock");
++ priv_path = lock_path(talloc_tos(), "msg.sock");
+ if (priv_path == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+@@ -662,7 +662,7 @@ NTSTATUS messaging_reinit(struct messagi
+
+ msg_ctx->msg_dgm_ref = messaging_dgm_ref(
+ msg_ctx, msg_ctx->event_ctx, &msg_ctx->id.unique_id,
+- private_path("msg.sock"), lck_path,
++ lock_path(talloc_tos(), "msg.sock"), lck_path,
+ messaging_recv_cb, msg_ctx, &ret);
+
+ if (msg_ctx->msg_dgm_ref == NULL) {
--- /dev/null
+--- a/source4/lib/messaging/messaging.c
++++ b/source4/lib/messaging/messaging.c
+@@ -350,7 +350,7 @@ static struct imessaging_context *imessa
+ goto fail;
+ }
+
+- msg->sock_dir = lpcfg_private_path(msg, lp_ctx, "msg.sock");
++ msg->sock_dir = lpcfg_lock_path(msg, lp_ctx, "msg.sock");
+ if (msg->sock_dir == NULL) {
+ goto fail;
+ }
--- /dev/null
+--- a/lib/replace/wscript
++++ b/lib/replace/wscript
+@@ -340,22 +340,13 @@ def configure(conf):
+
+ conf.CHECK_FUNCS('prctl dirname basename')
+
+- strlcpy_in_bsd = False
++ # Not checking for libbsd
++ conf.CHECK_FUNCS('strlcpy strlcat')
++ conf.CHECK_FUNCS('getpeereid')
++ conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h')
++ conf.CHECK_FUNCS('setproctitle_init')
+
+- # libbsd on some platforms provides strlcpy and strlcat
+- if not conf.CHECK_FUNCS('strlcpy strlcat'):
+- if conf.CHECK_FUNCS_IN('strlcpy strlcat', 'bsd', headers='bsd/string.h',
+- checklibc=True):
+- strlcpy_in_bsd = True
+- if not conf.CHECK_FUNCS('getpeereid'):
+- conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h')
+- if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'):
+- conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h')
+- if not conf.CHECK_FUNCS('setproctitle_init'):
+- conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h')
+-
+- if not conf.CHECK_FUNCS('closefrom'):
+- conf.CHECK_FUNCS_IN('closefrom', 'bsd', headers='bsd/unistd.h')
++ conf.CHECK_FUNCS('closefrom')
+
+ conf.CHECK_CODE('''
+ struct ucred cred;
+@@ -698,9 +689,6 @@ def configure(conf):
+
+ # look for a method of finding the list of network interfaces
+ for method in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']:
+- bsd_for_strlcpy = ''
+- if strlcpy_in_bsd:
+- bsd_for_strlcpy = ' bsd'
+ if conf.CHECK_CODE('''
+ #define %s 1
+ #define NO_CONFIG_H 1
+@@ -713,7 +701,7 @@ def configure(conf):
+ #include "test/getifaddrs.c"
+ ''' % method,
+ method,
+- lib='nsl socket' + bsd_for_strlcpy,
++ lib='nsl socket',
+ addmain=False,
+ execute=True):
+ break
+@@ -761,7 +749,6 @@ def build(bld):
+ break
+
+ extra_libs = ''
+- if bld.CONFIG_SET('HAVE_LIBBSD'): extra_libs += ' bsd'
+ if bld.CONFIG_SET('HAVE_LIBRT'): extra_libs += ' rt'
+
+ bld.SAMBA_SUBSYSTEM('LIBREPLACE_HOSTCC',
+ REPLACE_HOSTCC_SOURCE,
+++ /dev/null
---- a/lib/crypto/wscript_configure
-+++ b/lib/crypto/wscript_configure
-@@ -2,11 +2,11 @@
- import Options
- import Utils
-
--if not conf.CHECK_FUNCS_IN('MD5Init', 'bsd', headers='bsd/md5.h',
-- checklibc=True):
-- conf.CHECK_FUNCS_IN('MD5Init', 'md5', headers='sys/md5.h',
-- checklibc=True)
-- conf.CHECK_FUNCS_IN('MD5Init', 'md', headers='sys/md5.h',
-+# if not conf.CHECK_FUNCS_IN('MD5Init', 'bsd', headers='bsd/md5.h',
-+ # checklibc=True):
-+conf.CHECK_FUNCS_IN('MD5Init', 'md5', headers='sys/md5.h',
-+ checklibc=True)
-+conf.CHECK_FUNCS_IN('MD5Init', 'md', headers='sys/md5.h',
- checklibc=True)
- conf.CHECK_FUNCS_IN('CC_MD5_Init', '', headers='CommonCrypto/CommonDigest.h',
- checklibc=True)
---- a/lib/replace/wscript
-+++ b/lib/replace/wscript
-@@ -340,22 +340,13 @@ def configure(conf):
-
- conf.CHECK_FUNCS('prctl dirname basename')
-
-- strlcpy_in_bsd = False
-+ # Not checking for libbsd
-+ conf.CHECK_FUNCS('strlcpy strlcat')
-+ conf.CHECK_FUNCS('getpeereid')
-+ conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h')
-+ conf.CHECK_FUNCS('setproctitle_init')
-
-- # libbsd on some platforms provides strlcpy and strlcat
-- if not conf.CHECK_FUNCS('strlcpy strlcat'):
-- if conf.CHECK_FUNCS_IN('strlcpy strlcat', 'bsd', headers='bsd/string.h',
-- checklibc=True):
-- strlcpy_in_bsd = True
-- if not conf.CHECK_FUNCS('getpeereid'):
-- conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h')
-- if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'):
-- conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h')
-- if not conf.CHECK_FUNCS('setproctitle_init'):
-- conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h')
--
-- if not conf.CHECK_FUNCS('closefrom'):
-- conf.CHECK_FUNCS_IN('closefrom', 'bsd', headers='bsd/unistd.h')
-+ conf.CHECK_FUNCS('closefrom')
-
- conf.CHECK_CODE('''
- struct ucred cred;
-@@ -698,9 +689,6 @@ def configure(conf):
-
- # look for a method of finding the list of network interfaces
- for method in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']:
-- bsd_for_strlcpy = ''
-- if strlcpy_in_bsd:
-- bsd_for_strlcpy = ' bsd'
- if conf.CHECK_CODE('''
- #define %s 1
- #define NO_CONFIG_H 1
-@@ -713,7 +701,7 @@ def configure(conf):
- #include "test/getifaddrs.c"
- ''' % method,
- method,
-- lib='nsl socket' + bsd_for_strlcpy,
-+ lib='nsl socket',
- addmain=False,
- execute=True):
- break
-@@ -761,7 +749,6 @@ def build(bld):
- break
-
- extra_libs = ''
-- if bld.CONFIG_SET('HAVE_LIBBSD'): extra_libs += ' bsd'
-
- bld.SAMBA_SUBSYSTEM('LIBREPLACE_HOSTCC',
- REPLACE_HOSTCC_SOURCE,
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials: "OK"
+Checking whether we can use Linux thread-specific credentials: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: OK
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials: "OK"
+Checking whether we can use Linux thread-specific credentials: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: NO
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials with 32-bit system calls: "OK"
+Checking whether we can use Linux thread-specific credentials with 32-bit system calls: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: NO
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials with 32-bit system calls: "OK"
+Checking whether we can use Linux thread-specific credentials with 32-bit system calls: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: NO
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials with 32-bit system calls: "OK"
+Checking whether we can use Linux thread-specific credentials with 32-bit system calls: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: NO
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials: "OK"
+Checking whether we can use Linux thread-specific credentials: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: NO
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials: "OK"
+Checking whether we can use Linux thread-specific credentials: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: OK
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials: "OK"
+Checking whether we can use Linux thread-specific credentials: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: OK
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials: "OK"
+Checking whether we can use Linux thread-specific credentials: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: NO
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials: "OK"
+Checking whether we can use Linux thread-specific credentials: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: NO
Checking if can we convert from CP850 to UCS-2LE: OK
Checking if can we convert from UTF-8 to UCS-2LE: OK
vfs_fileid checking for statfs() and struct statfs.f_fsid: OK
-Checking whether we can use Linux thread-specific credentials: "OK"
+Checking whether we can use Linux thread-specific credentials: OK
Checking whether fcntl locking is available: OK
Checking whether fcntl lock supports open file description locks: NO
Checking for the maximum value of the 'time_t' type: OK
PKG_NAME:=simple-adblock
PKG_VERSION:=1.8.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_MAINTAINER:=Stan Grishin <stangri@melmac.net>
PKG_LICENSE:=GPL-3.0-or-later
return 0
}
-status() {
+status_service() {
local status="$(tmpfs get status)" error="$(tmpfs get error)" message="$(tmpfs get message)"
- if [ -n "$status" ] && [ -n "$message" ]; then
+ if [ -n "$status" ] && [ -n "$message" ]; then
status="${status}: $message"
fi
[ -n "$status" ] && output "$serviceName $status\\n"
include $(TOPDIR)/rules.mk
PKG_NAME:=softethervpn5
-PKG_VERSION:=5.01.9671
+PKG_VERSION:=5.01.9672
PKG_RELEASE:=1
PKG_MAINTAINER:=Andy Walsh <andy.walsh44+github@gmail.com>
PKG_SOURCE_URL:=https://github.com/SoftEtherVPN/SoftEtherVPN/releases/download/$(PKG_VERSION)/
PKG_SOURCE:=softether-vpn-src-$(PKG_VERSION).tar.gz
-PKG_HASH:=56930110ad5e21a3b7c69008bdb3efd368c0ebafc1d0d97b48a76a3563ec8e24
+PKG_HASH:=7c437d4d02d7e2a936b4c1ff7bc8f5abbf16786746deffa92d5f5f2fd7ba04fb
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/SoftEtherVPN-$(PKG_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/SoftEtherVPN-$(PKG_VERSION)
--- /dev/null
+--- a/src/Mayaqua/Mayaqua.h 2019-07-11
++++ b/src/Mayaqua/Mayaqua.h 2019-07-11
+@@ -178,7 +178,7 @@ int PASCAL WinMain(HINSTANCE hInst, HINS
+ #include <ifaddrs.h>\r
+ #endif // MAYAQUA_SUPPORTS_GETIFADDRS\r
+ \r
+-#ifdef UNIX_LINUX\r
++#if 0\r
+ typedef void *iconv_t;\r
+ iconv_t iconv_open (__const char *__tocode, __const char *__fromcode);\r
+ size_t iconv (iconv_t __cd, char **__restrict __inbuf,\r
+++ /dev/null
-From a4ed6560017d0b9edcd7cab93ca05d80f794ec10 Mon Sep 17 00:00:00 2001
-From: Rosen Penev <rosenp@gmail.com>
-Date: Wed, 10 Jul 2019 17:01:01 -0700
-Subject: [PATCH] Mayaqua: Replace GNU specific sys/poll.h header with POSIX
- poll.h
-
-Fixes warning from the musl libc:
-
-warning redirecting incorrect #include <sys/poll.h> to <poll.h>
----
- src/Mayaqua/Mayaqua.h | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/Mayaqua/Mayaqua.h b/src/Mayaqua/Mayaqua.h
-index 0f46d52a..63c2edc3 100644
---- a/src/Mayaqua/Mayaqua.h
-+++ b/src/Mayaqua/Mayaqua.h
-@@ -157,8 +157,8 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *CmdLine, int CmdShow)
- #ifdef UNIX_SOLARIS\r
- #include <sys/filio.h>\r
- #endif // UNIX_SOLARIS\r
--#include <sys/poll.h>\r
- #include <sys/resource.h>\r
-+#include <poll.h>\r
- #include <pthread.h>\r
- #ifdef UNIX_LINUX\r
- #include <sys/prctl.h>\r
--- /dev/null
+--- a/src/Mayaqua/CMakeLists.txt 2019-07-10
++++ b/src/Mayaqua/CMakeLists.txt 2019-07-11
+@@ -59,7 +59,7 @@ if(UNIX)
+ find_package(ZLIB REQUIRED)
+
+ # In some cases libiconv is not included in libc
+- find_library(LIB_ICONV iconv)
++ find_library(LIB_ICONV iconv HINTS "${ICONV_LIB_PATH}")
+
+ find_library(LIB_RT rt)
+
+++ /dev/null
---- a/src/Mayaqua/Mayaqua.h 2019-07-11
-+++ b/src/Mayaqua/Mayaqua.h 2019-07-11
-@@ -178,7 +178,7 @@ int PASCAL WinMain(HINSTANCE hInst, HINS
- #include <ifaddrs.h>\r
- #endif // MAYAQUA_SUPPORTS_GETIFADDRS\r
- \r
--#ifdef UNIX_LINUX\r
-+#if 0\r
- typedef void *iconv_t;\r
- iconv_t iconv_open (__const char *__tocode, __const char *__fromcode);\r
- size_t iconv (iconv_t __cd, char **__restrict __inbuf,\r
+++ /dev/null
---- a/src/Mayaqua/CMakeLists.txt 2019-07-10
-+++ b/src/Mayaqua/CMakeLists.txt 2019-07-11
-@@ -59,7 +59,7 @@ if(UNIX)
- find_package(ZLIB REQUIRED)
-
- # In some cases libiconv is not included in libc
-- find_library(LIB_ICONV iconv)
-+ find_library(LIB_ICONV iconv HINTS "${ICONV_LIB_PATH}")
-
- find_library(LIB_RT rt)
-
include $(TOPDIR)/rules.mk
PKG_NAME:=sstp-client
-PKG_VERSION:=1.0.12
-PKG_RELEASE:=3
+PKG_VERSION:=1.0.13
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/sstp-client/$(PKG_VERSION)
-PKG_HASH:=487eb406579689803ce0397f6102b18641e4572ac7bc9b9e5f3027c84dcf67ff
-PKG_LICENSE=GPLv2
+PKG_HASH:=961258fca0795d8ad60b047942cf7cb53d025d353fd1e4ba08c2b75799f5321b
-include $(INCLUDE_DIR)/package.mk
+PKG_MAINTAINER:=Federico Di Marco <fededim@gmail.com>
+PKG_LICENSE:=GPL-2.0-or-later
+PKG_LICENSE_FILES:=COPYING
-TARGET_CPPFLAGS += -I$(PKG_BUILD_DIR)/include
+include $(INCLUDE_DIR)/package.mk
define Package/sstp-client
SECTION:=net
DEPENDS=+libevent2 +libopenssl +ppp +resolveip
TITLE:=SSTP-Client is a SSTP client for Linux.
URL:=http://sstp-client.sourceforge.net/
- MAINTAINER:=Federico Di Marco <fededim@gmail.com>
endef
define Package/sstp-client/description
/etc/ppp/peers/peer-sstp-example.txt
endef
+TARGET_CPPFLAGS += -I$(PKG_BUILD_DIR)/include
+
define Package/sstp-client/install
$(INSTALL_DIR) $(1)/usr/{bin,lib}
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/.libs/sstpc $(1)/usr/bin/
$(CP) $(PKG_BUILD_DIR)/src/libsstp-api/.libs/*.so* $(1)/usr/lib/
$(CP) $(PKG_BUILD_DIR)/src/pppd-plugin/.libs/*.so* $(1)/usr/lib/
-
+
$(INSTALL_DIR) $(1)/etc
- $(CP) files/etc $(1)
+ $(CP) files/etc $(1)
$(INSTALL_DIR) $(1)/lib/netifd/proto
$(INSTALL_BIN) ./files/lib/netifd/proto/sstp.sh $(1)/lib/netifd/proto
endef
/* Initialize the OpenSSL library */
status = SSL_library_init();
if (status != 1)
-@@ -487,6 +488,7 @@ static status_t sstp_init_ssl(sstp_client_st *client, sstp_option_st *opt)
-
- /* Load all error strings */
- SSL_load_error_strings();
-+#endif
+@@ -490,6 +491,9 @@ static status_t sstp_init_ssl(sstp_client_st *client, sstp_option_st *opt)
/* Create a new crypto context */
client->ssl_ctx = SSL_CTX_new(SSLv23_client_method());
++#else
++ client->ssl_ctx = SSL_CTX_new(TLS_client_method());
++#endif
+ if (client->ssl_ctx == NULL)
+ {
+ log_err("Could not get SSL crypto context");
local dpddelay
local inactivity
local keyexchange
+ local reqid
config_get mode "$1" mode "route"
config_get local_subnet "$1" local_subnet ""
config_get dpddelay "$1" dpddelay "30s"
config_get inactivity "$1" inactivity
config_get keyexchange "$1" keyexchange "ikev2"
+ config_get reqid "$1" reqid
[ -n "$local_nat" ] && local_subnet=$local_nat
ipsec_xappend " dpddelay=$dpddelay"
[ -n "$inactivity" ] && ipsec_xappend " inactivity=$inactivity"
+ [ -n "$reqid" ] && ipsec_xappend " reqid=$reqid"
if [ "$auth_method" = "psk" ]; then
ipsec_xappend " leftauth=psk"
PKG_NAME:=stubby
PKG_VERSION:=0.2.6
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=COPYING
SUBMENU:=IP Addresses and Names
TITLE+= - (daemon that uses getdns)
USERID:=stubby=410:stubby=410
- DEPENDS:= +libyaml +getdns +ca-certificates
+ DEPENDS:= +libyaml +getdns +ca-certs
endef
define Package/stubby/description
Installation of this package can be achieved at the command line using `opkg
install stubby`, or via the LUCI Web Interface. Installing the stubby package
will also install the required dependency packages, including the
-`ca-certificates` package.
+`ca-bundle` package.
## Configuration
include $(TOPDIR)/rules.mk
PKG_NAME:=stunnel
-PKG_VERSION:=5.55
-PKG_RELEASE:=2
+PKG_VERSION:=5.56
+PKG_RELEASE:=1
PKG_LICENSE:=GPL-2.0-or-later
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
https://www.usenix.org.uk/mirrors/stunnel/archive/$(word 1, $(subst .,$(space),$(PKG_VERSION))).x/
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_HASH:=90de69f41c58342549e74c82503555a6426961b29af3ed92f878192727074c62
+PKG_HASH:=7384bfb356b9a89ddfee70b5ca494d187605bb516b4fff597e167f97e2236b22
PKG_FIXUP:=autoreconf
PKG_FIXUP:=patch-libtool
include $(TOPDIR)/rules.mk
PKG_NAME:=unbound
-PKG_VERSION:=1.9.5
+PKG_VERSION:=1.9.6
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://nlnetlabs.nl/downloads/unbound
-PKG_HASH:=8a8d400f697c61d73d109c250743a1b6b79848297848026d82b43e831045db57
+PKG_HASH:=1d98fc6ea99197a20b4a0e540e87022cf523085786e0fc26de6ebb2720f5aaf0
PKG_MAINTAINER:=Eric Luehrsen <ericluehrsen@gmail.com>
PKG_LICENSE:=BSD-3-Clause
PKG_NAME:=vpnbypass
PKG_VERSION:=1.3.1
-PKG_RELEASE:=4
+PKG_RELEASE:=5
PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Stan Grishin <stangri@melmac.net>
# check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then
/etc/init.d/vpnbypass enable
-
- while uci -q del ucitrack.@vpnbypass[-1]; do :; done
-
- uci -q batch <<-EOF >/dev/null
- add ucitrack vpnbypass
- set ucitrack.@vpnbypass[0].init='vpnbypass'
- del_list ucitrack.@firewall[0].affects='vpnbypass'
- add_list ucitrack.@firewall[0].affects='vpnbypass'
- commit ucitrack
- EOF
fi
exit 0
endef
#!/bin/sh
# check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then
- while uci -q delete ucitrack.@vpnbypass[-1]; do :; done
- uci -q del_list ucitrack.@firewall[0].affects='vpnbypass'
echo "Stopping service and removing rc.d symlink for vpnbypass"
/etc/init.d/vpnbypass stop || true
/etc/init.d/vpnbypass disable || true
service_triggers() {
local ifaces n
config_load network; config_foreach service_triggers_load_interface 'interface';
- procd_add_reload_trigger 'firewall'
- procd_add_reload_trigger 'openvpn'
+ procd_add_reload_trigger 'firewall' 'openvpn' 'vpnbypass'
procd_open_trigger
for n in $ifaces; do procd_add_reload_interface_trigger "$n"; procd_add_interface_trigger "interface.*" "$n" /etc/init.d/vpnbypass reload; done;
output "$serviceName monitoring interfaces: $ifaces $_OK_\\n"
PKG_NAME:=vpnc-scripts
PKG_VERSION:=20151220
-PKG_RELEASE:=1
+PKG_RELEASE:=2
include $(INCLUDE_DIR)/package.mk
reconnect)
run_hooks reconnect
;;
+ attempt-reconnect)
+ run_hooks attempt-reconnect
+ ;;
*)
logger -t openconnect "unknown reason '$reason'. Maybe vpnc-script is out of date" 1>&2
exit 1
PKG_NAME:=wifidog
PKG_VERSION:=1.3.0
-PKG_RELEASE:=4
+PKG_RELEASE:=5
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/wifidog/wifidog-gateway
procd_close_instance
}
-status() {
+status_service() {
/usr/bin/wdctl status
}
include $(TOPDIR)/rules.mk
PKG_NAME:=wsdd2
-PKG_RELEASE:=3
+PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/Andy2244/wsdd2.git
-PKG_SOURCE_DATE:=2018-07-24
-PKG_SOURCE_VERSION:=2c31ba3b720af81848c47dff7ad7c6c30c0c0f50
-PKG_MIRROR_HASH:=eb903a870d99c6001996dbfc22c15e1020278c45ed2441ceb61bc5395f417afa
+PKG_SOURCE_DATE:=2019-12-15
+PKG_SOURCE_VERSION:=8bcc0c1a42767ba518977a7104fe934f5d89ef31
+PKG_MIRROR_HASH:=4eace9130b7e1ddbc5b965fa51286532d3ee2ee14bcd2e116840c7d6d48ad9bc
PKG_MAINTAINER:=Andy Walsh <andy.walsh44+github@gmail.com>
PKG_LICENSE:=GPL-3.0-only
START=99
USE_PROCD=1
+SMB_CONF=""
+BIND_IF_PARM=""
+NB_PARM=""
+WG_PARM=""
+BI_PARM=""
+
+. /lib/functions/network.sh
+
start_service() {
- procd_open_instance
- procd_set_param command /usr/bin/wsdd2 -w
+
+ if [ -e /etc/cifs/smb.conf ] && [ -e /etc/init.d/cifsd ] && /etc/init.d/cifsd running; then
+ SMB_CONF="/etc/cifs/smb.conf"
+ fi
+
+ if [ -e /etc/samba/smb.conf ]; then
+ if [ -e /etc/init.d/samba4 ] && /etc/init.d/samba4 running; then
+ SMB_CONF="/etc/samba/smb.conf"
+ elif [ -e /etc/init.d/samba ] && /etc/init.d/samba running; then
+ SMB_CONF="/etc/samba/smb.conf"
+ fi
+ fi
+
+ if [ -z "$SMB_CONF" ]; then
+ logger -p daemon.error -t 'wsdd2' "samba36/4 or cifsd is not running, can't start wsdd2!"
+ exit 1
+ fi
+
+ local nb_name
+ nb_name="$(grep -i 'netbios name' $SMB_CONF | awk -F'=' '{print $2}' | tr -d ' \n')"
+ if [ -n "$nb_name" ]; then
+ NB_PARM="-N $nb_name"
+ else
+ local hostname
+ hostname="$(cat /proc/sys/kernel/hostname)"
+ NB_PARM="-N $hostname"
+ fi
+
+ local wg_name
+ wg_name="$(grep -i 'workgroup' $SMB_CONF | awk -F'=' '{print $2}' | tr -d ' \n')"
+ if [ -n "$wg_name" ]; then
+ WG_PARM="-G $wg_name"
+ else
+ NB_PARM="-G WORKGROUP"
+ fi
+
+ # resolve lan interface (BUG: No multi-interface binds atm)
+ local ifname
+ if network_get_device ifname lan; then
+ BIND_IF_PARM="-i $ifname"
+ fi
+
+ local board_vendor
+ local board_model
+ local board_sku
+
+ if [ -e /tmp/sysinfo/board_name ]; then
+ board_vendor="$(cat /tmp/sysinfo/board_name | awk -F',' '{print $1}' | tr ' ' '_' | tr -d ' \n')"
+ board_sku="$(cat /tmp/sysinfo/board_name | awk -F',' '{print $2}' | tr ' ' '_' | tr -d ' \n')"
+ fi
+ if [ -e /tmp/sysinfo/model ]; then
+ board_model="$(cat /tmp/sysinfo/model | tr ' ' '_' | tr -d ' \n')"
+ fi
+ if [ -n "$board_vendor" ] && [ -n "$board_model" ]; then
+ if [ -n "$board_sku" ]; then
+ BI_PARM="-b vendor:$board_vendor,model:$board_model,sku:$board_sku"
+ else
+ BI_PARM="-b vendor:$board_vendor,model:$board_model"
+ fi
+ fi
+
+ procd_open_instance
+ procd_set_param command /usr/bin/wsdd2 -w $BIND_IF_PARM $NB_PARM $WG_PARM $BI_PARM
procd_set_param respawn
- procd_set_param file /var/etc/smb.conf
+ procd_set_param file $SMB_CONF
procd_close_instance
}
service_triggers() {
- PROCD_RELOAD_DELAY=3000
- procd_add_reload_trigger "dhcp" "system" "samba4"
+ PROCD_RELOAD_DELAY=1000
+ procd_add_reload_trigger "dhcp" "system" "samba" "samba4" "cifsd"
}
+++ /dev/null
---- a/wsd.c 2018-07-24
-+++ b/wsd.c 2018-09-10
-@@ -96,13 +96,19 @@ static void uuid_endpoint(char *uuid, si
- {
- FILE *fp = fopen("/etc/machine-id", "r");
- int c, i = 0;
-+
-+ if (!fp) {
-+ fp = fopen("/proc/sys/kernel/random/boot_id", "r");
-+ }
-
-- if (!fp)
-+ if (!fp) {
-+ DEBUG(0, W, "Can't open required '/etc/machine-id' or '/proc/sys/kernel/random/boot_id'");
- return;
-+ }
-
- while (i < 36 && (c = getc(fp)) != EOF &&
-- (isdigit(c) || (islower(c) && isxdigit(c)))) {
-- if (i == 8 || i == 13 || i == 18 || i == 23)
-+ ((c == '-') || isdigit(c) || (islower(c) && isxdigit(c)))) {
-+ if ((c != '-') && (i == 8 || i == 13 || i == 18 || i == 23))
- uuid[i++] = '-';
- uuid[i++] = c;
- }
PKG_NAME:=xl2tpd
PKG_VERSION:=1.3.15
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_MAINTAINER:=Yousong Zhou <yszhou4tech@gmail.com>
PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=LICENSE
The following are generic ppp options and should have the same format and
semantics as with other ppp-related protocols. See
-[uci/network#protocol_ppp](https://wiki.openwrt.org/doc/uci/network#protocol_ppp_ppp_over_modem)
+[uci/network#protocol_ppp](https://openwrt.org/docs/guide-user/network/wan/wan_interface_protocols#protocol_ppp_ppp_over_modem)
for details.
username
include $(TOPDIR)/rules.mk
PKG_NAME:=znc
-PKG_VERSION:=1.7.4
+PKG_VERSION:=1.7.5
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://znc.in/releases \
https://znc.in/releases/archive
-PKG_HASH:=b1a32921a8e6d79ee6c5900c8d07293026966db7c05aaac48984231befc49b71
+PKG_HASH:=a8941e1385c8654287a4428018d93459482e9d5eeedf86bef7b020ddc5f24721
PKG_MAINTAINER:=Jonas Gorski <jonas.gorski@gmail.com>
PKG_LICENSE:=Apache-2.0
include $(TOPDIR)/rules.mk
PKG_NAME:=fdk-aac
-PKG_VERSION:=2.0.0
+PKG_VERSION:=2.0.1
PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/mstorsjo/fdk-aac/tar.gz/v$(PKG_VERSION)?
+PKG_HASH:=a4142815d8d52d0e798212a5adea54ecf42bcd4eec8092b37a8cb615ace91dc6
+
PKG_MAINTAINER:=Ted Hess <thess@kitschensync.net>
PKG_LICENSE:=Fraunhofer-FDK-AAC-for-Android
PKG_LICENSE_FILES:=NOTICE
-PKG_SOURCE_URL=https://codeload.github.com/mstorsjo/fdk-aac/tar.gz/v$(PKG_VERSION)?
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_HASH:=6e6c7921713788e31df655911e1d42620b057180b00bf16874f5d630e1d5b9a2
-
PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
PKG_CONFIG_DEPENDS:= CONFIG_FDK-AAC_OPTIMIZE_SPEED
+ifeq ($(BUILD_VARIANT),free)
+PATCH_DIR:=./patches-free
+endif
+
ifeq ($(CONFIG_FDK-AAC_OPTIMIZE_SPEED),y)
TARGET_CFLAGS := $(filter-out -O%,$(TARGET_CFLAGS))
TARGET_CFLAGS += $(TARGET_CFLAGS) -O2 -flto
include $(INCLUDE_DIR)/package.mk
-define Package/fdk-aac
+define Package/fdk-aac/Default
SECTION:=sound
CATEGORY:=Sound
- DEPENDS:=@BUILD_PATENTED
TITLE:=Fraunhofer FDK AAC Codec Library
URL:=https://sourceforge.net/projects/opencore-amr/
endef
-define Package/fdk-aac/description
+define Package/fdk-aac/Default/description
Port of the Fraunhofer FDK AAC Codec Library for Android
endef
+define Package/fdk-aac/Default/config
+ source "$(SOURCE)/Config.in"
+endef
+
+define Package/fdk-aac
+ $(call Package/fdk-aac/Default)
+ DEPENDS:=@BUILD_PATENTED
+ VARIANT:=nonfree
+endef
+
+define Package/fdk-aac/description
+ $(call Package/fdk-aac/Default/description)
+ This is the full patent encumbered version.
+endef
+
define Package/fdk-aac/config
- source "$(SOURCE)/Config.in"
+ $(call Package/fdk-aac/Default/config)
endef
-define Package/fdk-aac/install
- $(INSTALL_DIR) $(1)/usr/lib/
- $(CP) $(PKG_INSTALL_DIR)/usr/lib/libfdk-aac.so* $(1)/usr/lib/
+define Package/fdk-aac-free
+ $(call Package/fdk-aac/Default)
+ VARIANT:=free
+endef
+
+define Package/fdk-aac-free/description
+ $(call Package/fdk-aac/Default/description)
+ This is the free version that only supports LC-AAC.
+endef
+
+define Package/fdk-aac-free/config
+ $(call Package/fdk-aac/Default/config)
endef
define Build/InstallDev
$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/fdk-aac.pc $(1)/usr/lib/pkgconfig/
endef
+define Package/fdk-aac/install
+ $(INSTALL_DIR) $(1)/usr/lib/
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libfdk-aac.so* $(1)/usr/lib/
+endef
+
+define Package/fdk-aac-free/install
+ $(INSTALL_DIR) $(1)/usr/lib/
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libfdk-aac.so* $(1)/usr/lib/
+endef
+
$(eval $(call BuildPackage,fdk-aac))
+$(eval $(call BuildPackage,fdk-aac-free))
--- /dev/null
+From 612384d1b1c44d03f0185ef50c8b53fcb5fccfc3 Mon Sep 17 00:00:00 2001
+From: Wim Taymans <wtaymans@redhat.com>
+Date: Mon, 24 Jun 2019 15:25:52 +0200
+Subject: Remove SBR
+
+---
+ Android.bp | 4 -
+ Makefile.am | 51 -
+ Makefile.vc | 48 -
+ libAACdec/src/aacdec_drc.cpp | 17 +-
+ libAACdec/src/aacdec_drc.h | 10 +-
+ libAACdec/src/aacdecoder.cpp | 185 +--
+ libAACdec/src/aacdecoder.h | 13 -
+ libAACdec/src/aacdecoder_lib.cpp | 231 +--
+ libAACenc/src/aacenc.h | 4 -
+ libAACenc/src/aacenc_lib.cpp | 562 +------
+ libMpegTPDec/include/tp_data.h | 11 -
+ libMpegTPDec/include/tpdec_lib.h | 12 -
+ libMpegTPDec/src/tpdec_asc.cpp | 107 --
+ libMpegTPDec/src/tpdec_lib.cpp | 10 -
+ libMpegTPEnc/include/tpenc_lib.h | 12 -
+ libMpegTPEnc/src/tpenc_asc.cpp | 19 -
+ libSBRdec/include/sbrdecoder.h | 401 -----
+ libSBRdec/src/HFgen_preFlat.cpp | 993 ------------
+ libSBRdec/src/HFgen_preFlat.h | 132 --
+ libSBRdec/src/arm/lpp_tran_arm.cpp | 159 --
+ libSBRdec/src/env_calc.cpp | 3158 ------------------------------------
+ libSBRdec/src/env_calc.h | 182 ---
+ libSBRdec/src/env_dec.cpp | 873 ----------
+ libSBRdec/src/env_dec.h | 119 --
+ libSBRdec/src/env_extr.cpp | 1728 --------------------
+ libSBRdec/src/env_extr.h | 415 -----
+ libSBRdec/src/hbe.cpp | 2202 -------------------------
+ libSBRdec/src/hbe.h | 200 ---
+ libSBRdec/src/huff_dec.cpp | 137 --
+ libSBRdec/src/huff_dec.h | 117 --
+ libSBRdec/src/lpp_tran.cpp | 1471 -----------------
+ libSBRdec/src/lpp_tran.h | 275 ----
+ libSBRdec/src/psbitdec.cpp | 594 -------
+ libSBRdec/src/psbitdec.h | 116 --
+ libSBRdec/src/psdec.cpp | 722 ---------
+ libSBRdec/src/psdec.h | 333 ----
+ libSBRdec/src/psdec_drm.cpp | 108 --
+ libSBRdec/src/psdec_drm.h | 113 --
+ libSBRdec/src/psdecrom_drm.cpp | 108 --
+ libSBRdec/src/pvc_dec.cpp | 683 --------
+ libSBRdec/src/pvc_dec.h | 238 ---
+ libSBRdec/src/sbr_crc.cpp | 192 ---
+ libSBRdec/src/sbr_crc.h | 138 --
+ libSBRdec/src/sbr_deb.cpp | 108 --
+ libSBRdec/src/sbr_deb.h | 113 --
+ libSBRdec/src/sbr_dec.cpp | 1480 -----------------
+ libSBRdec/src/sbr_dec.h | 204 ---
+ libSBRdec/src/sbr_ram.cpp | 191 ---
+ libSBRdec/src/sbr_ram.h | 186 ---
+ libSBRdec/src/sbr_rom.cpp | 1705 -------------------
+ libSBRdec/src/sbr_rom.h | 216 ---
+ libSBRdec/src/sbrdec_drc.cpp | 528 ------
+ libSBRdec/src/sbrdec_drc.h | 149 --
+ libSBRdec/src/sbrdec_freq_sca.cpp | 835 ----------
+ libSBRdec/src/sbrdec_freq_sca.h | 127 --
+ libSBRdec/src/sbrdecoder.cpp | 2023 -----------------------
+ libSBRdec/src/transcendent.h | 372 -----
+ libSBRenc/include/sbr_encoder.h | 483 ------
+ libSBRenc/src/bit_sbr.cpp | 1049 ------------
+ libSBRenc/src/bit_sbr.h | 267 ---
+ libSBRenc/src/cmondata.h | 127 --
+ libSBRenc/src/code_env.cpp | 602 -------
+ libSBRenc/src/code_env.h | 161 --
+ libSBRenc/src/env_bit.cpp | 257 ---
+ libSBRenc/src/env_bit.h | 135 --
+ libSBRenc/src/env_est.cpp | 1985 ----------------------
+ libSBRenc/src/env_est.h | 223 ---
+ libSBRenc/src/fram_gen.cpp | 1965 ----------------------
+ libSBRenc/src/fram_gen.h | 343 ----
+ libSBRenc/src/invf_est.cpp | 610 -------
+ libSBRenc/src/invf_est.h | 181 ---
+ libSBRenc/src/mh_det.cpp | 1396 ----------------
+ libSBRenc/src/mh_det.h | 204 ---
+ libSBRenc/src/nf_est.cpp | 612 -------
+ libSBRenc/src/nf_est.h | 185 ---
+ libSBRenc/src/ps_bitenc.cpp | 624 -------
+ libSBRenc/src/ps_bitenc.h | 173 --
+ libSBRenc/src/ps_const.h | 150 --
+ libSBRenc/src/ps_encode.cpp | 1031 ------------
+ libSBRenc/src/ps_encode.h | 185 ---
+ libSBRenc/src/ps_main.cpp | 606 -------
+ libSBRenc/src/ps_main.h | 270 ---
+ libSBRenc/src/resampler.cpp | 444 -----
+ libSBRenc/src/resampler.h | 159 --
+ libSBRenc/src/sbr.h | 194 ---
+ libSBRenc/src/sbr_def.h | 276 ----
+ libSBRenc/src/sbr_encoder.cpp | 2577 -----------------------------
+ libSBRenc/src/sbr_misc.cpp | 265 ---
+ libSBRenc/src/sbr_misc.h | 127 --
+ libSBRenc/src/sbrenc_freq_sca.cpp | 674 --------
+ libSBRenc/src/sbrenc_freq_sca.h | 132 --
+ libSBRenc/src/sbrenc_ram.cpp | 249 ---
+ libSBRenc/src/sbrenc_ram.h | 199 ---
+ libSBRenc/src/sbrenc_rom.cpp | 910 -----------
+ libSBRenc/src/sbrenc_rom.h | 145 --
+ libSBRenc/src/ton_corr.cpp | 891 ----------
+ libSBRenc/src/ton_corr.h | 258 ---
+ libSBRenc/src/tran_det.cpp | 1092 -------------
+ libSBRenc/src/tran_det.h | 191 ---
+ 99 files changed, 34 insertions(+), 48013 deletions(-)
+ delete mode 100644 libSBRdec/include/sbrdecoder.h
+ delete mode 100644 libSBRdec/src/HFgen_preFlat.cpp
+ delete mode 100644 libSBRdec/src/HFgen_preFlat.h
+ delete mode 100644 libSBRdec/src/arm/lpp_tran_arm.cpp
+ delete mode 100644 libSBRdec/src/env_calc.cpp
+ delete mode 100644 libSBRdec/src/env_calc.h
+ delete mode 100644 libSBRdec/src/env_dec.cpp
+ delete mode 100644 libSBRdec/src/env_dec.h
+ delete mode 100644 libSBRdec/src/env_extr.cpp
+ delete mode 100644 libSBRdec/src/env_extr.h
+ delete mode 100644 libSBRdec/src/hbe.cpp
+ delete mode 100644 libSBRdec/src/hbe.h
+ delete mode 100644 libSBRdec/src/huff_dec.cpp
+ delete mode 100644 libSBRdec/src/huff_dec.h
+ delete mode 100644 libSBRdec/src/lpp_tran.cpp
+ delete mode 100644 libSBRdec/src/lpp_tran.h
+ delete mode 100644 libSBRdec/src/psbitdec.cpp
+ delete mode 100644 libSBRdec/src/psbitdec.h
+ delete mode 100644 libSBRdec/src/psdec.cpp
+ delete mode 100644 libSBRdec/src/psdec.h
+ delete mode 100644 libSBRdec/src/psdec_drm.cpp
+ delete mode 100644 libSBRdec/src/psdec_drm.h
+ delete mode 100644 libSBRdec/src/psdecrom_drm.cpp
+ delete mode 100644 libSBRdec/src/pvc_dec.cpp
+ delete mode 100644 libSBRdec/src/pvc_dec.h
+ delete mode 100644 libSBRdec/src/sbr_crc.cpp
+ delete mode 100644 libSBRdec/src/sbr_crc.h
+ delete mode 100644 libSBRdec/src/sbr_deb.cpp
+ delete mode 100644 libSBRdec/src/sbr_deb.h
+ delete mode 100644 libSBRdec/src/sbr_dec.cpp
+ delete mode 100644 libSBRdec/src/sbr_dec.h
+ delete mode 100644 libSBRdec/src/sbr_ram.cpp
+ delete mode 100644 libSBRdec/src/sbr_ram.h
+ delete mode 100644 libSBRdec/src/sbr_rom.cpp
+ delete mode 100644 libSBRdec/src/sbr_rom.h
+ delete mode 100644 libSBRdec/src/sbrdec_drc.cpp
+ delete mode 100644 libSBRdec/src/sbrdec_drc.h
+ delete mode 100644 libSBRdec/src/sbrdec_freq_sca.cpp
+ delete mode 100644 libSBRdec/src/sbrdec_freq_sca.h
+ delete mode 100644 libSBRdec/src/sbrdecoder.cpp
+ delete mode 100644 libSBRdec/src/transcendent.h
+ delete mode 100644 libSBRenc/include/sbr_encoder.h
+ delete mode 100644 libSBRenc/src/bit_sbr.cpp
+ delete mode 100644 libSBRenc/src/bit_sbr.h
+ delete mode 100644 libSBRenc/src/cmondata.h
+ delete mode 100644 libSBRenc/src/code_env.cpp
+ delete mode 100644 libSBRenc/src/code_env.h
+ delete mode 100644 libSBRenc/src/env_bit.cpp
+ delete mode 100644 libSBRenc/src/env_bit.h
+ delete mode 100644 libSBRenc/src/env_est.cpp
+ delete mode 100644 libSBRenc/src/env_est.h
+ delete mode 100644 libSBRenc/src/fram_gen.cpp
+ delete mode 100644 libSBRenc/src/fram_gen.h
+ delete mode 100644 libSBRenc/src/invf_est.cpp
+ delete mode 100644 libSBRenc/src/invf_est.h
+ delete mode 100644 libSBRenc/src/mh_det.cpp
+ delete mode 100644 libSBRenc/src/mh_det.h
+ delete mode 100644 libSBRenc/src/nf_est.cpp
+ delete mode 100644 libSBRenc/src/nf_est.h
+ delete mode 100644 libSBRenc/src/ps_bitenc.cpp
+ delete mode 100644 libSBRenc/src/ps_bitenc.h
+ delete mode 100644 libSBRenc/src/ps_const.h
+ delete mode 100644 libSBRenc/src/ps_encode.cpp
+ delete mode 100644 libSBRenc/src/ps_encode.h
+ delete mode 100644 libSBRenc/src/ps_main.cpp
+ delete mode 100644 libSBRenc/src/ps_main.h
+ delete mode 100644 libSBRenc/src/resampler.cpp
+ delete mode 100644 libSBRenc/src/resampler.h
+ delete mode 100644 libSBRenc/src/sbr.h
+ delete mode 100644 libSBRenc/src/sbr_def.h
+ delete mode 100644 libSBRenc/src/sbr_encoder.cpp
+ delete mode 100644 libSBRenc/src/sbr_misc.cpp
+ delete mode 100644 libSBRenc/src/sbr_misc.h
+ delete mode 100644 libSBRenc/src/sbrenc_freq_sca.cpp
+ delete mode 100644 libSBRenc/src/sbrenc_freq_sca.h
+ delete mode 100644 libSBRenc/src/sbrenc_ram.cpp
+ delete mode 100644 libSBRenc/src/sbrenc_ram.h
+ delete mode 100644 libSBRenc/src/sbrenc_rom.cpp
+ delete mode 100644 libSBRenc/src/sbrenc_rom.h
+ delete mode 100644 libSBRenc/src/ton_corr.cpp
+ delete mode 100644 libSBRenc/src/ton_corr.h
+ delete mode 100644 libSBRenc/src/tran_det.cpp
+ delete mode 100644 libSBRenc/src/tran_det.h
+
+diff --git a/Android.bp b/Android.bp
+index dce6fdd..95d56df 100644
+--- a/Android.bp
++++ b/Android.bp
+@@ -9,8 +9,6 @@ cc_library_static {
+ "libSYS/src/*.cpp",
+ "libMpegTPDec/src/*.cpp",
+ "libMpegTPEnc/src/*.cpp",
+- "libSBRdec/src/*.cpp",
+- "libSBRenc/src/*.cpp",
+ "libArithCoding/src/*.cpp",
+ "libDRCdec/src/*.cpp",
+ "libSACdec/src/*.cpp",
+@@ -43,8 +41,6 @@ cc_library_static {
+ "libSYS/include",
+ "libMpegTPDec/include",
+ "libMpegTPEnc/include",
+- "libSBRdec/include",
+- "libSBRenc/include",
+ "libArithCoding/include",
+ "libDRCdec/include",
+ "libSACdec/include",
+diff --git a/Makefile.am b/Makefile.am
+index fe6b867..28efc79 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -8,8 +8,6 @@ AM_CPPFLAGS = \
+ -I$(top_srcdir)/libDRCdec/include \
+ -I$(top_srcdir)/libSACdec/include \
+ -I$(top_srcdir)/libSACenc/include \
+- -I$(top_srcdir)/libSBRdec/include \
+- -I$(top_srcdir)/libSBRenc/include \
+ -I$(top_srcdir)/libMpegTPDec/include \
+ -I$(top_srcdir)/libMpegTPEnc/include \
+ -I$(top_srcdir)/libSYS/include \
+@@ -197,49 +195,6 @@ SACENC_SRC = \
+ libSACenc/src/sacenc_tree.cpp \
+ libSACenc/src/sacenc_vectorfunctions.cpp
+
+-SBRDEC_SRC = \
+- libSBRdec/src/HFgen_preFlat.cpp \
+- libSBRdec/src/env_calc.cpp \
+- libSBRdec/src/env_dec.cpp \
+- libSBRdec/src/env_extr.cpp \
+- libSBRdec/src/hbe.cpp \
+- libSBRdec/src/huff_dec.cpp \
+- libSBRdec/src/lpp_tran.cpp \
+- libSBRdec/src/psbitdec.cpp \
+- libSBRdec/src/psdec.cpp \
+- libSBRdec/src/psdec_drm.cpp \
+- libSBRdec/src/psdecrom_drm.cpp \
+- libSBRdec/src/pvc_dec.cpp \
+- libSBRdec/src/sbr_crc.cpp \
+- libSBRdec/src/sbr_deb.cpp \
+- libSBRdec/src/sbr_dec.cpp \
+- libSBRdec/src/sbr_ram.cpp \
+- libSBRdec/src/sbr_rom.cpp \
+- libSBRdec/src/sbrdec_drc.cpp \
+- libSBRdec/src/sbrdec_freq_sca.cpp \
+- libSBRdec/src/sbrdecoder.cpp
+-
+-SBRENC_SRC = \
+- libSBRenc/src/bit_sbr.cpp \
+- libSBRenc/src/code_env.cpp \
+- libSBRenc/src/env_bit.cpp \
+- libSBRenc/src/env_est.cpp \
+- libSBRenc/src/fram_gen.cpp \
+- libSBRenc/src/invf_est.cpp \
+- libSBRenc/src/mh_det.cpp \
+- libSBRenc/src/nf_est.cpp \
+- libSBRenc/src/ps_bitenc.cpp \
+- libSBRenc/src/ps_encode.cpp \
+- libSBRenc/src/ps_main.cpp \
+- libSBRenc/src/resampler.cpp \
+- libSBRenc/src/sbr_encoder.cpp \
+- libSBRenc/src/sbr_misc.cpp \
+- libSBRenc/src/sbrenc_freq_sca.cpp \
+- libSBRenc/src/sbrenc_ram.cpp \
+- libSBRenc/src/sbrenc_rom.cpp \
+- libSBRenc/src/ton_corr.cpp \
+- libSBRenc/src/tran_det.cpp
+-
+ SYS_SRC = \
+ libSYS/src/genericStds.cpp \
+ libSYS/src/syslib_channelMapDescr.cpp
+@@ -250,7 +205,6 @@ libfdk_aac_la_SOURCES = \
+ $(DRCDEC_SRC) \
+ $(MPEGTPDEC_SRC) $(MPEGTPENC_SRC) \
+ $(SACDEC_SRC) $(SACENC_SRC) \
+- $(SBRDEC_SRC) $(SBRENC_SRC) \
+ $(PCMUTILS_SRC) $(FDK_SRC) $(SYS_SRC)
+
+ EXTRA_DIST = \
+@@ -273,11 +227,6 @@ EXTRA_DIST = \
+ $(top_srcdir)/libSACdec/src/*.h \
+ $(top_srcdir)/libSACenc/include/*.h \
+ $(top_srcdir)/libSACenc/src/*.h \
+- $(top_srcdir)/libSBRenc/src/*.h \
+- $(top_srcdir)/libSBRenc/include/*.h \
+- $(top_srcdir)/libSBRdec/src/*.h \
+- $(top_srcdir)/libSBRdec/src/arm/*.cpp \
+- $(top_srcdir)/libSBRdec/include/*.h \
+ $(top_srcdir)/libSYS/include/*.h \
+ $(top_srcdir)/libPCMutils/include/*.h \
+ $(top_srcdir)/libPCMutils/src/*.h \
+diff --git a/Makefile.vc b/Makefile.vc
+index a90b530..ac3c097 100644
+--- a/Makefile.vc
++++ b/Makefile.vc
+@@ -23,8 +23,6 @@ AM_CPPFLAGS = \
+ -IlibDRCdec/include \
+ -IlibSACdec/include \
+ -IlibSACenc/include \
+- -IlibSBRdec/include \
+- -IlibSBRenc/include \
+ -IlibMpegTPDec/include \
+ -IlibMpegTPEnc/include \
+ -IlibSYS/include \
+@@ -181,49 +179,6 @@ SACENC_SRC = \
+ libSACenc/src/sacenc_tree.cpp \
+ libSACenc/src/sacenc_vectorfunctions.cpp
+
+-SBRDEC_SRC = \
+- libSBRdec/src/HFgen_preFlat.cpp \
+- libSBRdec/src/env_calc.cpp \
+- libSBRdec/src/env_dec.cpp \
+- libSBRdec/src/env_extr.cpp \
+- libSBRdec/src/hbe.cpp \
+- libSBRdec/src/huff_dec.cpp \
+- libSBRdec/src/lpp_tran.cpp \
+- libSBRdec/src/psbitdec.cpp \
+- libSBRdec/src/psdec.cpp \
+- libSBRdec/src/psdec_drm.cpp \
+- libSBRdec/src/psdecrom_drm.cpp \
+- libSBRdec/src/pvc_dec.cpp \
+- libSBRdec/src/sbr_crc.cpp \
+- libSBRdec/src/sbr_deb.cpp \
+- libSBRdec/src/sbr_dec.cpp \
+- libSBRdec/src/sbr_ram.cpp \
+- libSBRdec/src/sbr_rom.cpp \
+- libSBRdec/src/sbrdec_drc.cpp \
+- libSBRdec/src/sbrdec_freq_sca.cpp \
+- libSBRdec/src/sbrdecoder.cpp
+-
+-SBRENC_SRC = \
+- libSBRenc/src/bit_sbr.cpp \
+- libSBRenc/src/code_env.cpp \
+- libSBRenc/src/env_bit.cpp \
+- libSBRenc/src/env_est.cpp \
+- libSBRenc/src/fram_gen.cpp \
+- libSBRenc/src/invf_est.cpp \
+- libSBRenc/src/mh_det.cpp \
+- libSBRenc/src/nf_est.cpp \
+- libSBRenc/src/ps_bitenc.cpp \
+- libSBRenc/src/ps_encode.cpp \
+- libSBRenc/src/ps_main.cpp \
+- libSBRenc/src/resampler.cpp \
+- libSBRenc/src/sbr_encoder.cpp \
+- libSBRenc/src/sbr_misc.cpp \
+- libSBRenc/src/sbrenc_freq_sca.cpp \
+- libSBRenc/src/sbrenc_ram.cpp \
+- libSBRenc/src/sbrenc_rom.cpp \
+- libSBRenc/src/ton_corr.cpp \
+- libSBRenc/src/tran_det.cpp
+-
+ SYS_SRC = \
+ libSYS/src/genericStds.cpp \
+ libSYS/src/syslib_channelMapDescr.cpp
+@@ -234,7 +189,6 @@ libfdk_aac_SOURCES = \
+ $(DRCDEC_SRC) \
+ $(MPEGTPDEC_SRC) $(MPEGTPENC_SRC) \
+ $(SACDEC_SRC) $(SACENC_SRC) \
+- $(SBRDEC_SRC) $(SBRENC_SRC) \
+ $(PCMUTILS_SRC) $(FDK_SRC) $(SYS_SRC)
+
+
+@@ -282,8 +236,6 @@ clean:
+ del /f libPCMutils\src\*.obj 2>NUL
+ del /f libSACdec\src\*.obj 2>NUL
+ del /f libSACenc\src\*.obj 2>NUL
+- del /f libSBRdec\src\*.obj 2>NUL
+- del /f libSBRenc\src\*.obj 2>NUL
+ del /f libSYS\src\*.obj 2>NUL
+
+ install: $(INST_DIRS)
+diff --git a/libAACdec/src/aacdec_drc.cpp b/libAACdec/src/aacdec_drc.cpp
+index 922a09e..ae05379 100644
+--- a/libAACdec/src/aacdec_drc.cpp
++++ b/libAACdec/src/aacdec_drc.cpp
+@@ -105,8 +105,6 @@ amm-info@iis.fraunhofer.de
+ #include "channelinfo.h"
+ #include "aac_rom.h"
+
+-#include "sbrdecoder.h"
+-
+ /*
+ * Dynamic Range Control
+ */
+@@ -832,11 +830,11 @@ static int aacDecoder_drcExtractAndMap(
+ return result;
+ }
+
+-void aacDecoder_drcApply(HANDLE_AAC_DRC self, void *pSbrDec,
++void aacDecoder_drcApply(HANDLE_AAC_DRC self,
+ CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+ CDrcChannelData *pDrcChData, FIXP_DBL *extGain,
+ int ch, /* needed only for SBR */
+- int aacFrameSize, int bSbrPresent) {
++ int aacFrameSize) {
+ int band, bin, numBands;
+ int bottom = 0;
+ int modifyBins = 0;
+@@ -867,7 +865,6 @@ void aacDecoder_drcApply(HANDLE_AAC_DRC self, void *pSbrDec,
+ }
+
+ if (self->enable != ON) {
+- sbrDecoder_drcDisable((HANDLE_SBRDECODER)pSbrDec, ch);
+ if (extGain != NULL) {
+ INT gainScale = (INT)*extGain;
+ /* The gain scaling must be passed to the function in the buffer pointed
+@@ -1020,7 +1017,7 @@ void aacDecoder_drcApply(HANDLE_AAC_DRC self, void *pSbrDec,
+ * short blocks must take care that bands fall on
+ * block boundaries!
+ */
+- if (!bSbrPresent) {
++ {
+ bottom = 0;
+
+ if (!modifyBins) {
+@@ -1058,14 +1055,6 @@ void aacDecoder_drcApply(HANDLE_AAC_DRC self, void *pSbrDec,
+ pSpecScale[win] += max_exponent;
+ }
+ }
+- } else {
+- HANDLE_SBRDECODER hSbrDecoder = (HANDLE_SBRDECODER)pSbrDec;
+- numBands = pDrcChData->numBands;
+-
+- /* feed factors into SBR decoder for application in QMF domain. */
+- sbrDecoder_drcFeedChannel(hSbrDecoder, ch, numBands, fact_mantissa,
+- max_exponent, pDrcChData->drcInterpolationScheme,
+- winSeq, pDrcChData->bandTop);
+ }
+
+ return;
+diff --git a/libAACdec/src/aacdec_drc.h b/libAACdec/src/aacdec_drc.h
+index 924ec6f..19018b6 100644
+--- a/libAACdec/src/aacdec_drc.h
++++ b/libAACdec/src/aacdec_drc.h
+@@ -152,10 +152,8 @@ int aacDecoder_drcProlog(
+ UCHAR pceInstanceTag, UCHAR channelMapping[], int validChannels);
+
+ /**
+- * \brief Apply DRC. If SBR is present, DRC data is handed over to the SBR
+- * decoder.
++ * \brief Apply DRC.
+ * \param self AAC decoder instance
+- * \param pSbrDec pointer to SBR decoder instance
+ * \param pAacDecoderChannelInfo AAC decoder channel instance to be processed
+ * \param pDrcDat DRC channel data
+ * \param extGain Pointer to a FIXP_DBL where a externally applyable gain will
+@@ -164,13 +162,11 @@ int aacDecoder_drcProlog(
+ * DFRACT_BITS) to be applied on the gain value.
+ * \param ch channel index
+ * \param aacFrameSize AAC frame size
+- * \param bSbrPresent flag indicating that SBR is present, in which case DRC is
+- * handed over to the SBR instance pSbrDec
+ */
+-void aacDecoder_drcApply(HANDLE_AAC_DRC self, void *pSbrDec,
++void aacDecoder_drcApply(HANDLE_AAC_DRC self,
+ CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+ CDrcChannelData *pDrcDat, FIXP_DBL *extGain, int ch,
+- int aacFrameSize, int bSbrPresent);
++ int aacFrameSize);
+
+ int aacDecoder_drcEpilog(
+ HANDLE_AAC_DRC self, HANDLE_FDK_BITSTREAM hBs,
+diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp
+index 8f03328..2419ecc 100644
+--- a/libAACdec/src/aacdecoder.cpp
++++ b/libAACdec/src/aacdecoder.cpp
+@@ -161,8 +161,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "aacdec_pns.h"
+
+-#include "sbrdecoder.h"
+-
+ #include "sac_dec_lib.h"
+
+ #include "aacdec_hcr.h"
+@@ -249,9 +247,6 @@ void CAacDecoder_SyncQmfMode(HANDLE_AACDECODER self) {
+ }
+ }
+
+- /* Set SBR to current QMF mode. Error does not matter. */
+- sbrDecoder_SetParam(self->hSbrDecoder, SBR_QMF_MODE,
+- (self->qmfModeCurr == MODE_LP));
+ self->psPossible =
+ ((CAN_DO_PS(self->streamInfo.aot) &&
+ !PS_IS_EXPLICITLY_DISABLED(self->streamInfo.aot, self->flags[0]) &&
+@@ -936,7 +931,6 @@ static AAC_DECODER_ERROR CAacDecoder_ExtPayloadParse(
+ FDK_FALLTHROUGH;
+ case EXT_SBR_DATA:
+ if (IS_CHANNEL_ELEMENT(previous_element)) {
+- SBR_ERROR sbrError;
+ UCHAR configMode = 0;
+ UCHAR configChanged = 0;
+
+@@ -944,29 +938,6 @@ static AAC_DECODER_ERROR CAacDecoder_ExtPayloadParse(
+
+ configMode |= AC_CM_ALLOC_MEM;
+
+- sbrError = sbrDecoder_InitElement(
+- self->hSbrDecoder, self->streamInfo.aacSampleRate,
+- self->streamInfo.extSamplingRate,
+- self->streamInfo.aacSamplesPerFrame, self->streamInfo.aot,
+- previous_element, elIndex,
+- 2, /* Signalize that harmonicSBR shall be ignored in the config
+- change detection */
+- 0, configMode, &configChanged, self->downscaleFactor);
+-
+- if (sbrError == SBRDEC_OK) {
+- sbrError = sbrDecoder_Parse(self->hSbrDecoder, hBs,
+- self->pDrmBsBuffer, self->drmBsBufferSize,
+- count, *count, crcFlag, previous_element,
+- elIndex, self->flags[0], self->elFlags);
+- /* Enable SBR for implicit SBR signalling but only if no severe error
+- * happend. */
+- if ((sbrError == SBRDEC_OK) || (sbrError == SBRDEC_PARSE_ERROR)) {
+- self->sbrEnabled = 1;
+- }
+- } else {
+- /* Do not try to apply SBR because initializing the element failed. */
+- self->sbrEnabled = 0;
+- }
+ /* Citation from ISO/IEC 14496-3 chapter 4.5.2.1.5.2
+ Fill elements containing an extension_payload() with an extension_type
+ of EXT_SBR_DATA or EXT_SBR_DATA_CRC shall not contain any other
+@@ -978,9 +949,7 @@ static AAC_DECODER_ERROR CAacDecoder_ExtPayloadParse(
+ } else {
+ /* If this is not a fill element with a known length, we are screwed
+ * and further parsing makes no sense. */
+- if (sbrError != SBRDEC_OK) {
+- self->frameOK = 0;
+- }
++ self->frameOK = 0;
+ }
+ } else {
+ error = AAC_DEC_PARSE_ERROR;
+@@ -1107,54 +1076,10 @@ static AAC_DECODER_ERROR aacDecoder_ParseExplicitMpsAndSbr(
+
+ if ((self->flags[0] & AC_SBR_PRESENT) &&
+ (self->flags[0] & (AC_USAC | AC_RSVD50 | AC_ELD | AC_DRM))) {
+- SBR_ERROR err = SBRDEC_OK;
+- int chElIdx, numChElements = el_cnt[ID_SCE] + el_cnt[ID_CPE] +
+- el_cnt[ID_LFE] + el_cnt[ID_USAC_SCE] +
+- el_cnt[ID_USAC_CPE] + el_cnt[ID_USAC_LFE];
+- INT bitCntTmp = bitCnt;
+-
+- if (self->flags[0] & AC_USAC) {
+- chElIdx = numChElements - 1;
+- } else {
+- chElIdx = 0; /* ELD case */
+- }
+-
+- for (; chElIdx < numChElements; chElIdx += 1) {
+- MP4_ELEMENT_ID sbrType;
+- SBR_ERROR errTmp;
+- if (self->flags[0] & (AC_USAC)) {
+- FDK_ASSERT((self->elements[element_index] == ID_USAC_SCE) ||
+- (self->elements[element_index] == ID_USAC_CPE));
+- sbrType = IS_STEREO_SBR(self->elements[element_index],
+- self->usacStereoConfigIndex[element_index])
+- ? ID_CPE
+- : ID_SCE;
+- } else
+- sbrType = self->elements[chElIdx];
+- errTmp = sbrDecoder_Parse(self->hSbrDecoder, bs, self->pDrmBsBuffer,
+- self->drmBsBufferSize, &bitCnt, -1,
+- self->flags[0] & AC_SBRCRC, sbrType, chElIdx,
+- self->flags[0], self->elFlags);
+- if (errTmp != SBRDEC_OK) {
+- err = errTmp;
+- bitCntTmp = bitCnt;
+- bitCnt = 0;
+- }
+- }
+- switch (err) {
+- case SBRDEC_PARSE_ERROR:
+- /* Can not go on parsing because we do not
+- know the length of the SBR extension data. */
+- FDKpushFor(bs, bitCntTmp);
+- bitCnt = 0;
+- break;
+- case SBRDEC_OK:
+- self->sbrEnabled = 1;
+- break;
+- default:
+- self->frameOK = 0;
+- break;
+- }
++ /* Can not go on parsing because we do not
++ know the length of the SBR extension data. */
++ FDKpushFor(bs, bitCnt);
++ bitCnt = 0;
+ }
+
+ if ((bitCnt > 0) && (self->flags[0] & (AC_USAC | AC_RSVD50))) {
+@@ -1827,14 +1752,8 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ }
+ self->flags[streamIndex] |= (asc->m_sbrPresentFlag) ? AC_SBR_PRESENT : 0;
+ self->flags[streamIndex] |= (asc->m_psPresentFlag) ? AC_PS_PRESENT : 0;
+- if (asc->m_sbrPresentFlag) {
+- self->sbrEnabled = 1;
+- self->sbrEnabledPrev = 1;
+- } else {
+- self->sbrEnabled = 0;
+- self->sbrEnabledPrev = 0;
+- }
+- if (self->sbrEnabled && asc->m_extensionSamplingFrequency) {
++
++ if (asc->m_sbrPresentFlag && asc->m_extensionSamplingFrequency) {
+ if (downscaleFactor != 1 && (downscaleFactor)&1) {
+ return AAC_DEC_UNSUPPORTED_SAMPLINGRATE; /* SBR needs an even downscale
+ factor */
+@@ -1944,31 +1863,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ /* set AC_USAC_SCFGI3 globally if any usac element uses */
+ switch (asc->m_aot) {
+ case AOT_USAC:
+- if (self->sbrEnabled) {
+- for (int _el = 0;
+- _el < (int)self->pUsacConfig[streamIndex]->m_usacNumElements;
+- _el++) {
+- int el = elementOffset + _el;
+- if (IS_USAC_CHANNEL_ELEMENT(self->elements[el])) {
+- if (usacStereoConfigIndex < 0) {
+- usacStereoConfigIndex = self->usacStereoConfigIndex[el];
+- } else {
+- if ((usacStereoConfigIndex != self->usacStereoConfigIndex[el]) ||
+- (self->usacStereoConfigIndex[el] > 0)) {
+- goto bail;
+- }
+- }
+- }
+- }
+-
+- if (usacStereoConfigIndex < 0) {
+- goto bail;
+- }
+-
+- if (usacStereoConfigIndex == 3) {
+- self->flags[streamIndex] |= AC_USAC_SCFGI3;
+- }
+- }
+ break;
+ default:
+ break;
+@@ -1981,39 +1875,11 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ */
+ switch (asc->m_aot) {
+ case AOT_USAC:
+- if (self->sbrEnabled) {
+- const UCHAR map_sbrRatio_2_nAnaBands[] = {16, 24, 32};
+-
+- FDK_ASSERT(asc->m_sc.m_usacConfig.m_sbrRatioIndex > 0);
+- FDK_ASSERT(streamIndex == 0);
+-
+- self->qmfDomain.globalConf.nInputChannels_requested = ascChannels;
+- self->qmfDomain.globalConf.nOutputChannels_requested =
+- (usacStereoConfigIndex == 1) ? 2 : ascChannels;
+- self->qmfDomain.globalConf.flags_requested = 0;
+- self->qmfDomain.globalConf.nBandsAnalysis_requested =
+- map_sbrRatio_2_nAnaBands[asc->m_sc.m_usacConfig.m_sbrRatioIndex -
+- 1];
+- self->qmfDomain.globalConf.nBandsSynthesis_requested = 64;
+- self->qmfDomain.globalConf.nQmfTimeSlots_requested =
+- (asc->m_sc.m_usacConfig.m_sbrRatioIndex == 1) ? 64 : 32;
+- self->qmfDomain.globalConf.nQmfOvTimeSlots_requested =
+- (asc->m_sc.m_usacConfig.m_sbrRatioIndex == 1) ? 12 : 6;
+- self->qmfDomain.globalConf.nQmfProcBands_requested = 64;
+- self->qmfDomain.globalConf.nQmfProcChannels_requested = 1;
+- self->qmfDomain.globalConf.parkChannel =
+- (usacStereoConfigIndex == 3) ? 1 : 0;
+- self->qmfDomain.globalConf.parkChannel_requested =
+- (usacStereoConfigIndex == 3) ? 1 : 0;
+- self->qmfDomain.globalConf.qmfDomainExplicitConfig = 1;
+- }
+ break;
+ case AOT_ER_AAC_ELD:
+ if (self->mpsEnableCurr &&
+ asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign) {
+- SAC_INPUT_CONFIG sac_interface =
+- (self->sbrEnabled && self->hSbrDecoder) ? SAC_INTERFACE_QMF
+- : SAC_INTERFACE_TIME;
++ SAC_INPUT_CONFIG sac_interface = SAC_INTERFACE_TIME;
+ mpegSurroundDecoder_ConfigureQmfDomain(
+ (CMpegSurroundDecoder *)self->pMpegSurroundDecoder, sac_interface,
+ (UINT)self->streamInfo.aacSampleRate, asc->m_aot);
+@@ -2625,34 +2491,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ } else {
+ self->frameOK = 0;
+ }
+- /* Create SBR element for SBR for upsampling for LFE elements,
+- and if SBR was implicitly signaled, because the first frame(s)
+- may not contain SBR payload (broken encoder, bit errors). */
+- if (self->frameOK &&
+- ((self->flags[streamIndex] & AC_SBR_PRESENT) ||
+- (self->sbrEnabled == 1)) &&
+- !(self->flags[streamIndex] &
+- AC_USAC) /* Is done during explicit config set up */
+- ) {
+- SBR_ERROR sbrError;
+- UCHAR configMode = 0;
+- UCHAR configChanged = 0;
+- configMode |= AC_CM_ALLOC_MEM;
+-
+- sbrError = sbrDecoder_InitElement(
+- self->hSbrDecoder, self->streamInfo.aacSampleRate,
+- self->streamInfo.extSamplingRate,
+- self->streamInfo.aacSamplesPerFrame, self->streamInfo.aot, type,
+- previous_element_index, 2, /* Signalize that harmonicSBR shall
+- be ignored in the config change
+- detection */
+- 0, configMode, &configChanged, self->downscaleFactor);
+- if (sbrError != SBRDEC_OK) {
+- /* Do not try to apply SBR because initializing the element
+- * failed. */
+- self->sbrEnabled = 0;
+- }
+- }
+ }
+
+ el_cnt[type]++;
+@@ -3047,7 +2885,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ (8) * sizeof(AUDIO_CHANNEL_TYPE)); /* restore */
+ FDKmemcpy(self->channelIndices, self->channelIndicesPrev,
+ (8) * sizeof(UCHAR)); /* restore */
+- self->sbrEnabled = self->sbrEnabledPrev;
+ } else {
+ /* store or restore the number of channels and the corresponding info */
+ if (self->frameOK && !(flags & AACDEC_CONCEAL)) {
+@@ -3056,7 +2893,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ (8) * sizeof(AUDIO_CHANNEL_TYPE)); /* store */
+ FDKmemcpy(self->channelIndicesPrev, self->channelIndices,
+ (8) * sizeof(UCHAR)); /* store */
+- self->sbrEnabledPrev = self->sbrEnabled;
+ } else {
+ if (self->aacChannels > 0) {
+ if ((self->buildUpStatus == AACDEC_RSV60_BUILD_UP_ON) ||
+@@ -3071,7 +2907,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ (8) * sizeof(AUDIO_CHANNEL_TYPE)); /* restore */
+ FDKmemcpy(self->channelIndices, self->channelIndicesPrev,
+ (8) * sizeof(UCHAR)); /* restore */
+- self->sbrEnabled = self->sbrEnabledPrev;
+ }
+ }
+ }
+@@ -3302,9 +3137,9 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ self->extGain[0] = (FIXP_DBL)TDL_GAIN_SCALING;
+ /* DRC processing */
+ aacDecoder_drcApply(
+- self->hDrcInfo, self->hSbrDecoder, pAacDecoderChannelInfo,
++ self->hDrcInfo, pAacDecoderChannelInfo,
+ &pAacDecoderStaticChannelInfo->drcData, self->extGain, c,
+- self->streamInfo.aacSamplesPerFrame, self->sbrEnabled
++ self->streamInfo.aacSamplesPerFrame
+
+ );
+
+diff --git a/libAACdec/src/aacdecoder.h b/libAACdec/src/aacdecoder.h
+index 20f4c45..0711160 100644
+--- a/libAACdec/src/aacdecoder.h
++++ b/libAACdec/src/aacdecoder.h
+@@ -118,8 +118,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "FDK_qmf_domain.h"
+
+-#include "sbrdecoder.h"
+-
+ #include "aacdec_drc.h"
+
+ #include "pcmdmx_lib.h"
+@@ -152,10 +150,6 @@ typedef struct {
+
+ typedef enum { NOT_DEFINED = -1, MODE_HQ = 0, MODE_LP = 1 } QMF_MODE;
+
+-typedef struct {
+- int bsDelay;
+-} SBR_PARAMS;
+-
+ enum {
+ AACDEC_FLUSH_OFF = 0,
+ AACDEC_RSV60_CFG_CHANGE_ATSC_FLUSH_ON = 1,
+@@ -224,8 +218,6 @@ struct AAC_DECODER_INSTANCE {
+ UCHAR chMapIndex; /*!< Index to access one line of the channelOutputMapping
+ table. This is required because not all 8 channel
+ configurations have the same output mapping. */
+- INT sbrDataLen; /*!< Expected length of the SBR remaining in bitbuffer after
+- the AAC payload has been pared. */
+
+ CProgramConfig pce;
+ CStreamInfo
+@@ -272,12 +264,7 @@ This structure is allocated once for each CPE. */
+ supported) ELD downscale factor discovered in
+ the bitstream */
+
+- HANDLE_SBRDECODER hSbrDecoder; /*!< SBR decoder handle. */
+- UCHAR sbrEnabled; /*!< flag to store if SBR has been detected */
+- UCHAR sbrEnabledPrev; /*!< flag to store if SBR has been detected from
+- previous frame */
+ UCHAR psPossible; /*!< flag to store if PS is possible */
+- SBR_PARAMS sbrParams; /*!< struct to store all sbr parameters */
+
+ UCHAR *pDrmBsBuffer; /*!< Pointer to dynamic buffer which is used to reverse
+ the bits of the DRM SBR payload */
+diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp
+index 7df17b9..bde978e 100644
+--- a/libAACdec/src/aacdecoder_lib.cpp
++++ b/libAACdec/src/aacdecoder_lib.cpp
+@@ -107,8 +107,6 @@ amm-info@iis.fraunhofer.de
+ #include "tpdec_lib.h"
+ #include "FDK_core.h" /* FDK_tools version info */
+
+-#include "sbrdecoder.h"
+-
+ #include "conceal.h"
+
+ #include "aacdec_drc.h"
+@@ -330,13 +328,6 @@ static INT aacDecoder_FreeMemCallback(void *handle,
+ errTp = TRANSPORTDEC_UNKOWN_ERROR;
+ }
+
+- /* free Ram_SbrDecoder and Ram_SbrDecChannel */
+- if (self->hSbrDecoder != NULL) {
+- if (sbrDecoder_FreeMem(&self->hSbrDecoder) != SBRDEC_OK) {
+- errTp = TRANSPORTDEC_UNKOWN_ERROR;
+- }
+- }
+-
+ /* free pSpatialDec and mpsData */
+ if (self->pMpegSurroundDecoder != NULL) {
+ if (mpegSurroundDecoder_FreeMem(
+@@ -368,23 +359,6 @@ static INT aacDecoder_CtrlCFGChangeCallback(
+ return errTp;
+ }
+
+-static INT aacDecoder_SbrCallback(
+- void *handle, HANDLE_FDK_BITSTREAM hBs, const INT sampleRateIn,
+- const INT sampleRateOut, const INT samplesPerFrame,
+- const AUDIO_OBJECT_TYPE coreCodec, const MP4_ELEMENT_ID elementID,
+- const INT elementIndex, const UCHAR harmonicSBR,
+- const UCHAR stereoConfigIndex, const UCHAR configMode, UCHAR *configChanged,
+- const INT downscaleFactor) {
+- HANDLE_SBRDECODER self = (HANDLE_SBRDECODER)handle;
+-
+- INT errTp = sbrDecoder_Header(self, hBs, sampleRateIn, sampleRateOut,
+- samplesPerFrame, coreCodec, elementID,
+- elementIndex, harmonicSBR, stereoConfigIndex,
+- configMode, configChanged, downscaleFactor);
+-
+- return errTp;
+-}
+-
+ static INT aacDecoder_SscCallback(void *handle, HANDLE_FDK_BITSTREAM hBs,
+ const AUDIO_OBJECT_TYPE coreCodec,
+ const INT samplingRate, const INT frameSize,
+@@ -557,7 +531,6 @@ static AAC_DECODER_ERROR setConcealMethod(
+ AAC_DECODER_ERROR errorStatus = AAC_DEC_OK;
+ CConcealParams *pConcealData = NULL;
+ int method_revert = 0;
+- HANDLE_SBRDECODER hSbrDec = NULL;
+ HANDLE_AAC_DRC hDrcInfo = NULL;
+ HANDLE_PCM_DOWNMIX hPcmDmx = NULL;
+ CConcealmentMethod backupMethod = ConcealMethodNone;
+@@ -567,7 +540,6 @@ static AAC_DECODER_ERROR setConcealMethod(
+ /* check decoder handle */
+ if (self != NULL) {
+ pConcealData = &self->concealCommonData;
+- hSbrDec = self->hSbrDecoder;
+ hDrcInfo = self->hDrcInfo;
+ hPcmDmx = self->hPcmUtils;
+ if (self->flags[0] & (AC_USAC | AC_RSVD50 | AC_RSV603DA) && method >= 2) {
+@@ -603,27 +575,6 @@ static AAC_DECODER_ERROR setConcealMethod(
+ /* Get new delay */
+ bsDelay = CConcealment_GetDelay(pConcealData);
+
+- {
+- SBR_ERROR sbrErr = SBRDEC_OK;
+-
+- /* set SBR bitstream delay */
+- sbrErr = sbrDecoder_SetParam(hSbrDec, SBR_SYSTEM_BITSTREAM_DELAY, bsDelay);
+-
+- switch (sbrErr) {
+- case SBRDEC_OK:
+- case SBRDEC_NOT_INITIALIZED:
+- if (self != NULL) {
+- /* save the param value and set later
+- (when SBR has been initialized) */
+- self->sbrParams.bsDelay = bsDelay;
+- }
+- break;
+- default:
+- errorStatus = AAC_DEC_SET_PARAM_FAIL;
+- goto bail;
+- }
+- }
+-
+ errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, bsDelay);
+ if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
+ goto bail;
+@@ -650,8 +601,6 @@ bail:
+ pConcealData, (int)backupMethod, AACDEC_CONCEAL_PARAM_NOT_SPECIFIED,
+ AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, AACDEC_CONCEAL_PARAM_NOT_SPECIFIED,
+ AACDEC_CONCEAL_PARAM_NOT_SPECIFIED);
+- /* Revert SBR bitstream delay */
+- sbrDecoder_SetParam(hSbrDec, SBR_SYSTEM_BITSTREAM_DELAY, backupDelay);
+ /* Revert DRC bitstream delay */
+ aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, backupDelay);
+ /* Revert PCM mixdown bitstream delay */
+@@ -973,14 +922,7 @@ LINKSPEC_CPP HANDLE_AACDECODER aacDecoder_Open(TRANSPORT_TYPE transportFmt,
+ pIn, aacDecoder_CtrlCFGChangeCallback, (void *)aacDec);
+
+ FDKmemclear(&aacDec->qmfDomain, sizeof(FDK_QMF_DOMAIN));
+- /* open SBR decoder */
+- if (SBRDEC_OK != sbrDecoder_Open(&aacDec->hSbrDecoder, &aacDec->qmfDomain)) {
+- err = -1;
+- goto bail;
+- }
+ aacDec->qmfModeUser = NOT_DEFINED;
+- transportDec_RegisterSbrCallback(aacDec->hInput, aacDecoder_SbrCallback,
+- (void *)aacDec->hSbrDecoder);
+
+ if (mpegSurroundDecoder_Open(
+ (CMpegSurroundDecoder **)&aacDec->pMpegSurroundDecoder,
+@@ -1067,9 +1009,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_Fill(HANDLE_AACDECODER self,
+ static void aacDecoder_SignalInterruption(HANDLE_AACDECODER self) {
+ CAacDecoder_SignalInterruption(self);
+
+- if (self->hSbrDecoder != NULL) {
+- sbrDecoder_SetParam(self->hSbrDecoder, SBR_BS_INTERRUPTION, 1);
+- }
+ if (self->mpsEnableUser) {
+ mpegSurroundDecoder_SetParam(
+ (CMpegSurroundDecoder *)self->pMpegSurroundDecoder,
+@@ -1274,7 +1213,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ Tell other modules to clear states if required. */
+ if (flags & AACDEC_CLRHIST) {
+ if (!(self->flags[0] & AC_USAC)) {
+- sbrDecoder_SetParam(self->hSbrDecoder, SBR_CLEAR_HISTORY, 1);
+ mpegSurroundDecoder_SetParam(
+ (CMpegSurroundDecoder *)self->pMpegSurroundDecoder,
+ SACDEC_CLEAR_HISTORY, 1);
+@@ -1393,9 +1331,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+
+ if (!self->qmfDomain.globalConf.qmfDomainExplicitConfig &&
+ self->mpsEnableCurr) {
+- SAC_INPUT_CONFIG sac_interface = (self->sbrEnabled && self->hSbrDecoder)
+- ? SAC_INTERFACE_QMF
+- : SAC_INTERFACE_TIME;
++ SAC_INPUT_CONFIG sac_interface = SAC_INTERFACE_TIME;
+ /* needs to be done before first SBR apply. */
+ mpegSurroundDecoder_ConfigureQmfDomain(
+ (CMpegSurroundDecoder *)self->pMpegSurroundDecoder, sac_interface,
+@@ -1423,8 +1359,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ break;
+ }
+
+- /* sbr decoder */
+-
+ if ((ErrorStatus != AAC_DEC_OK) || (flags & AACDEC_CONCEAL) ||
+ self->pAacDecoderStaticChannelInfo[0]->concealmentInfo.concealState >
+ ConcealState_FadeIn) {
+@@ -1432,110 +1366,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ decoder too */
+ }
+
+- if (self->sbrEnabled && (!(self->flags[0] & AC_USAC_SCFGI3))) {
+- SBR_ERROR sbrError = SBRDEC_OK;
+- int chIdx, numCoreChannel = self->streamInfo.numChannels;
+-
+- /* set params */
+- sbrDecoder_SetParam(self->hSbrDecoder, SBR_SYSTEM_BITSTREAM_DELAY,
+- self->sbrParams.bsDelay);
+- sbrDecoder_SetParam(
+- self->hSbrDecoder, SBR_FLUSH_DATA,
+- (flags & AACDEC_FLUSH) |
+- ((self->flushStatus && !(flags & AACDEC_CONCEAL)) ? AACDEC_FLUSH
+- : 0));
+-
+- if (self->streamInfo.aot == AOT_ER_AAC_ELD) {
+- /* Configure QMF */
+- sbrDecoder_SetParam(self->hSbrDecoder, SBR_LD_QMF_TIME_ALIGN,
+- (self->flags[0] & AC_MPS_PRESENT) ? 1 : 0);
+- }
+-
+- {
+- PCMDMX_ERROR dmxErr;
+- INT maxOutCh = 0;
+-
+- dmxErr = pcmDmx_GetParam(self->hPcmUtils,
+- MAX_NUMBER_OF_OUTPUT_CHANNELS, &maxOutCh);
+- if ((dmxErr == PCMDMX_OK) && (maxOutCh == 1)) {
+- /* Disable PS processing if we have to create a mono output signal.
+- */
+- self->psPossible = 0;
+- }
+- }
+-
+- sbrDecoder_SetParam(self->hSbrDecoder, SBR_SKIP_QMF,
+- (self->mpsEnableCurr) ? 2 : 0);
+-
+- INT_PCM *input;
+- input = (INT_PCM *)self->workBufferCore2;
+- FDKmemcpy(input, pTimeData,
+- sizeof(INT_PCM) * (self->streamInfo.numChannels) *
+- (self->streamInfo.frameSize));
+-
+- /* apply SBR processing */
+- sbrError = sbrDecoder_Apply(self->hSbrDecoder, input, pTimeData,
+- timeDataSize, &self->streamInfo.numChannels,
+- &self->streamInfo.sampleRate,
+- &self->mapDescr, self->chMapIndex,
+- self->frameOK, &self->psPossible);
+-
+- if (sbrError == SBRDEC_OK) {
+- /* Update data in streaminfo structure. Assume that the SBR upsampling
+- factor is either 1, 2, 8/3 or 4. Maximum upsampling factor is 4
+- (CELP+SBR or USAC 4:1 SBR) */
+- self->flags[0] |= AC_SBR_PRESENT;
+- if (self->streamInfo.aacSampleRate != self->streamInfo.sampleRate) {
+- if (self->streamInfo.aacSampleRate >> 2 ==
+- self->streamInfo.sampleRate) {
+- self->streamInfo.frameSize =
+- self->streamInfo.aacSamplesPerFrame >> 2;
+- self->streamInfo.outputDelay = self->streamInfo.outputDelay >> 2;
+- } else if (self->streamInfo.aacSampleRate >> 1 ==
+- self->streamInfo.sampleRate) {
+- self->streamInfo.frameSize =
+- self->streamInfo.aacSamplesPerFrame >> 1;
+- self->streamInfo.outputDelay = self->streamInfo.outputDelay >> 1;
+- } else if (self->streamInfo.aacSampleRate << 1 ==
+- self->streamInfo.sampleRate) {
+- self->streamInfo.frameSize = self->streamInfo.aacSamplesPerFrame
+- << 1;
+- self->streamInfo.outputDelay = self->streamInfo.outputDelay << 1;
+- } else if (self->streamInfo.aacSampleRate << 2 ==
+- self->streamInfo.sampleRate) {
+- self->streamInfo.frameSize = self->streamInfo.aacSamplesPerFrame
+- << 2;
+- self->streamInfo.outputDelay = self->streamInfo.outputDelay << 2;
+- } else if (self->streamInfo.frameSize == 768) {
+- self->streamInfo.frameSize =
+- (self->streamInfo.aacSamplesPerFrame << 3) / 3;
+- self->streamInfo.outputDelay =
+- (self->streamInfo.outputDelay << 3) / 3;
+- } else {
+- ErrorStatus = AAC_DEC_SET_PARAM_FAIL;
+- goto bail;
+- }
+- } else {
+- self->streamInfo.frameSize = self->streamInfo.aacSamplesPerFrame;
+- }
+- self->streamInfo.outputDelay +=
+- sbrDecoder_GetDelay(self->hSbrDecoder);
+-
+- if (self->psPossible) {
+- self->flags[0] |= AC_PS_PRESENT;
+- }
+- for (chIdx = numCoreChannel; chIdx < self->streamInfo.numChannels;
+- chIdx += 1) {
+- self->channelType[chIdx] = ACT_FRONT;
+- self->channelIndices[chIdx] = chIdx;
+- }
+- }
+- if (sbrError == SBRDEC_OUTPUT_BUFFER_TOO_SMALL) {
+- ErrorStatus = AAC_DEC_OUTPUT_BUFFER_TOO_SMALL;
+- goto bail;
+- }
+- }
+-
+ if (self->mpsEnableCurr) {
+ int err, sac_interface, nChannels, frameSize;
+
+@@ -1543,8 +1373,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ frameSize = self->streamInfo.frameSize;
+ sac_interface = SAC_INTERFACE_TIME;
+
+- if (self->sbrEnabled && self->hSbrDecoder)
+- sac_interface = SAC_INTERFACE_QMF;
+ if (self->streamInfo.aot == AOT_USAC) {
+ if (self->flags[0] & AC_USAC_SCFGI3) {
+ sac_interface = SAC_INTERFACE_TIME;
+@@ -1593,50 +1421,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ }
+ }
+
+- /* SBR decoder for Unified Stereo Config (stereoConfigIndex == 3) */
+-
+- if (self->sbrEnabled && (self->flags[0] & AC_USAC_SCFGI3)) {
+- SBR_ERROR sbrError = SBRDEC_OK;
+-
+- /* set params */
+- sbrDecoder_SetParam(self->hSbrDecoder, SBR_SYSTEM_BITSTREAM_DELAY,
+- self->sbrParams.bsDelay);
+-
+- sbrDecoder_SetParam(self->hSbrDecoder, SBR_SKIP_QMF, 1);
+-
+- /* apply SBR processing */
+- sbrError = sbrDecoder_Apply(self->hSbrDecoder, pTimeData, pTimeData,
+- timeDataSize, &self->streamInfo.numChannels,
+- &self->streamInfo.sampleRate,
+- &self->mapDescr, self->chMapIndex,
+- self->frameOK, &self->psPossible);
+-
+- if (sbrError == SBRDEC_OK) {
+- /* Update data in streaminfo structure. Assume that the SBR upsampling
+- * factor is either 1,2 or 4 */
+- self->flags[0] |= AC_SBR_PRESENT;
+- if (self->streamInfo.aacSampleRate != self->streamInfo.sampleRate) {
+- if (self->streamInfo.frameSize == 768) {
+- self->streamInfo.frameSize =
+- (self->streamInfo.aacSamplesPerFrame * 8) / 3;
+- } else if (self->streamInfo.aacSampleRate << 2 ==
+- self->streamInfo.sampleRate) {
+- self->streamInfo.frameSize = self->streamInfo.aacSamplesPerFrame
+- << 2;
+- } else {
+- self->streamInfo.frameSize = self->streamInfo.aacSamplesPerFrame
+- << 1;
+- }
+- }
+-
+- self->flags[0] &= ~AC_PS_PRESENT;
+- }
+- if (sbrError == SBRDEC_OUTPUT_BUFFER_TOO_SMALL) {
+- ErrorStatus = AAC_DEC_OUTPUT_BUFFER_TOO_SMALL;
+- goto bail;
+- }
+- }
+-
+ /* Use dedicated memory for PCM postprocessing */
+ pTimeDataPcmPost = self->pTimeData2;
+ timeDataPcmPostSize = self->timeData2Size;
+@@ -1672,7 +1456,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ /* If SBR and/or MPS is active, the DRC gains are aligned to the QMF
+ domain signal before the QMF synthesis. Therefore the DRC gains
+ need to be delayed by the QMF synthesis delay. */
+- if (self->sbrEnabled) drcDelay = 257;
+ if (self->mpsEnableCurr) drcDelay = 257;
+ /* Take into account concealment delay */
+ drcDelay += CConcealment_GetDelay(&self->concealCommonData) *
+@@ -1693,7 +1476,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ * necessary for FDK_drcDec_ProcessTime, which accepts deinterleaved
+ * audio only. */
+ if ((self->streamInfo.numChannels > 1) &&
+- (0 || (self->sbrEnabled) || (self->mpsEnableCurr))) {
++ (0 || (self->mpsEnableCurr))) {
+ /* interleaving/deinterleaving is performed on upper part of
+ * pTimeDataPcmPost. Check if this buffer is large enough. */
+ if (timeDataPcmPostSize <
+@@ -1766,7 +1549,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ }
+
+ INT interleaved = 0;
+- interleaved |= (self->sbrEnabled) ? 1 : 0;
+ interleaved |= (self->mpsEnableCurr) ? 1 : 0;
+
+ /* do PCM post processing */
+@@ -1804,7 +1586,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ pcmLimiter_SetSampleRate(self->hLimiter, self->streamInfo.sampleRate);
+ pcmLimiterScale += PCM_OUT_HEADROOM;
+
+- if ((self->streamInfo.numChannels == 1) || (self->sbrEnabled) ||
++ if ((self->streamInfo.numChannels == 1) ||
+ (self->mpsEnableCurr)) {
+ pInterleaveBuffer = (PCM_LIM *)pTimeDataPcmPost;
+ } else {
+@@ -1828,7 +1610,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ /* If numChannels = 1 we do not need interleaving. The same applies if
+ SBR or MPS are used, since their output is interleaved already
+ (resampled or not) */
+- if ((self->streamInfo.numChannels == 1) || (self->sbrEnabled) ||
++ if ((self->streamInfo.numChannels == 1) ||
+ (self->mpsEnableCurr)) {
+ scaleValuesSaturate(
+ pTimeData, pTimeDataPcmPost,
+@@ -1972,10 +1754,6 @@ LINKSPEC_CPP void aacDecoder_Close(HANDLE_AACDECODER self) {
+ (CMpegSurroundDecoder *)self->pMpegSurroundDecoder);
+ }
+
+- if (self->hSbrDecoder != NULL) {
+- sbrDecoder_Close(&self->hSbrDecoder);
+- }
+-
+ if (self->hInput != NULL) {
+ transportDec_Close(&self->hInput);
+ }
+@@ -1994,7 +1772,6 @@ LINKSPEC_CPP INT aacDecoder_GetLibInfo(LIB_INFO *info) {
+ return -1;
+ }
+
+- sbrDecoder_GetLibInfo(info);
+ mpegSurroundDecoder_GetLibInfo(info);
+ transportDec_GetLibInfo(info);
+ FDK_toolsGetLibInfo(info);
+diff --git a/libAACenc/src/aacenc.h b/libAACenc/src/aacenc.h
+index 291ea54..798730d 100644
+--- a/libAACenc/src/aacenc.h
++++ b/libAACenc/src/aacenc.h
+@@ -108,8 +108,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "tpenc_lib.h"
+
+-#include "sbr_encoder.h"
+-
+ #define MIN_BUFSIZE_PER_EFF_CHAN 6144
+
+ #ifdef __cplusplus
+@@ -243,8 +241,6 @@ struct AACENC_CONFIG {
+
+ INT audioMuxVersion; /* audio mux version in loas/latm transport format */
+
+- UINT sbrRatio; /* sbr sampling rate ratio: dual- or single-rate */
+-
+ UCHAR useTns; /* flag: use temporal noise shaping */
+ UCHAR usePns; /* flag: use perceptual noise substitution */
+ UCHAR useIS; /* flag: use intensity coding */
+diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp
+index 8df33a4..51f3f49 100644
+--- a/libAACenc/src/aacenc_lib.cpp
++++ b/libAACenc/src/aacenc_lib.cpp
+@@ -122,8 +122,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "pcm_utils.h"
+
+-#include "sbr_encoder.h"
+-#include "../src/sbrenc_ram.h"
+ #include "channel_map.h"
+
+ #include "psy_const.h"
+@@ -199,22 +197,10 @@ typedef struct {
+
+ UCHAR userMetaDataMode; /*!< Meta data library configuration. */
+
+- UCHAR userSbrEnabled; /*!< Enable SBR for ELD. */
+- UINT userSbrRatio; /*!< SBR sampling rate ratio. Dual- or single-rate. */
+-
+ UINT userDownscaleFactor;
+
+ } USER_PARAM;
+
+-/**
+- * SBR extenxion payload struct provides buffers to be filled in SBR encoder
+- * library.
+- */
+-typedef struct {
+- UCHAR data[(1)][(8)][MAX_PAYLOAD_SIZE]; /*!< extension payload data buffer */
+- UINT dataSize[(1)][(8)]; /*!< extension payload data size in bits */
+-} SBRENC_EXT_PAYLOAD;
+-
+ ////////////////////////////////////////////////////////////////////////////////////
+
+ /****************************************************************************
+@@ -231,10 +217,6 @@ struct AACENCODER {
+ AACENC_CONFIG aacConfig;
+ HANDLE_AAC_ENC hAacEnc;
+
+- /* SBR */
+- HANDLE_SBR_ENCODER hEnvEnc; /* SBR encoder */
+- SBRENC_EXT_PAYLOAD *pSbrPayload; /* SBR extension payload */
+-
+ /* Meta Data */
+ HANDLE_FDK_METADATA_ENCODER hMetadataEnc;
+ INT metaDataAllowed; /* Signal whether chosen configuration allows metadata.
+@@ -270,8 +252,6 @@ struct AACENCODER {
+ /* Memory allocation info. */
+ INT nMaxAacElements;
+ INT nMaxAacChannels;
+- INT nMaxSbrElements;
+- INT nMaxSbrChannels;
+
+ UINT encoder_modis;
+
+@@ -293,92 +273,6 @@ typedef struct {
+
+ } ELD_SBR_CONFIGURATOR;
+
+-/**
+- * \brief This table defines ELD/SBR default configurations.
+- */
+-static const ELD_SBR_CONFIGURATOR eldSbrAutoConfigTab[] = {
+- {1, 48000, 0, 2, MODE_1}, {1, 48000, 64000, 0, MODE_1},
+-
+- {1, 44100, 0, 2, MODE_1}, {1, 44100, 64000, 0, MODE_1},
+-
+- {1, 32000, 0, 2, MODE_1}, {1, 32000, 28000, 1, MODE_1},
+- {1, 32000, 56000, 0, MODE_1},
+-
+- {1, 24000, 0, 1, MODE_1}, {1, 24000, 40000, 0, MODE_1},
+-
+- {1, 16000, 0, 1, MODE_1}, {1, 16000, 28000, 0, MODE_1},
+-
+- {1, 15999, 0, 0, MODE_1},
+-
+- {2, 48000, 0, 2, MODE_2}, {2, 48000, 44000, 2, MODE_2},
+- {2, 48000, 128000, 0, MODE_2},
+-
+- {2, 44100, 0, 2, MODE_2}, {2, 44100, 44000, 2, MODE_2},
+- {2, 44100, 128000, 0, MODE_2},
+-
+- {2, 32000, 0, 2, MODE_2}, {2, 32000, 32000, 2, MODE_2},
+- {2, 32000, 68000, 1, MODE_2}, {2, 32000, 96000, 0, MODE_2},
+-
+- {2, 24000, 0, 1, MODE_2}, {2, 24000, 48000, 1, MODE_2},
+- {2, 24000, 80000, 0, MODE_2},
+-
+- {2, 16000, 0, 1, MODE_2}, {2, 16000, 32000, 1, MODE_2},
+- {2, 16000, 64000, 0, MODE_2},
+-
+- {2, 15999, 0, 0, MODE_2}
+-
+-};
+-
+-/*
+- * \brief Configure SBR for ELD configuration.
+- *
+- * This function finds default SBR configuration for ELD based on number of
+- * channels, sampling rate and bitrate.
+- *
+- * \param nChannels Number of audio channels.
+- * \param samplingRate Audio signal sampling rate.
+- * \param bitrate Encoder bitrate.
+- *
+- * \return - pointer to eld sbr configuration.
+- * - NULL, on failure.
+- */
+-static const ELD_SBR_CONFIGURATOR *eldSbrConfigurator(const ULONG nChannels,
+- const ULONG samplingRate,
+- const ULONG bitrate) {
+- int i;
+- const ELD_SBR_CONFIGURATOR *pSetup = NULL;
+-
+- for (i = 0;
+- i < (int)(sizeof(eldSbrAutoConfigTab) / sizeof(ELD_SBR_CONFIGURATOR));
+- i++) {
+- if ((nChannels == eldSbrAutoConfigTab[i].nChannels) &&
+- (samplingRate <= eldSbrAutoConfigTab[i].samplingRate) &&
+- (bitrate >= eldSbrAutoConfigTab[i].bitrateRange)) {
+- pSetup = &eldSbrAutoConfigTab[i];
+- }
+- }
+-
+- return pSetup;
+-}
+-
+-static inline INT isSbrActive(const HANDLE_AACENC_CONFIG hAacConfig) {
+- INT sbrUsed = 0;
+-
+- /* Note: Even if implicit signalling was selected, The AOT itself here is not
+- * AOT_AAC_LC */
+- if ((hAacConfig->audioObjectType == AOT_SBR) ||
+- (hAacConfig->audioObjectType == AOT_PS) ||
+- (hAacConfig->audioObjectType == AOT_MP2_SBR)) {
+- sbrUsed = 1;
+- }
+- if (hAacConfig->audioObjectType == AOT_ER_AAC_ELD &&
+- (hAacConfig->syntaxFlags & AC_SBR_PRESENT)) {
+- sbrUsed = 1;
+- }
+-
+- return (sbrUsed);
+-}
+-
+ static inline INT isPsActive(const AUDIO_OBJECT_TYPE audioObjectType) {
+ INT psUsed = 0;
+
+@@ -399,53 +293,6 @@ static CHANNEL_MODE GetCoreChannelMode(
+ return mappedChannelMode;
+ }
+
+-static SBR_PS_SIGNALING getSbrSignalingMode(
+- const AUDIO_OBJECT_TYPE audioObjectType, const TRANSPORT_TYPE transportType,
+- const UCHAR transportSignaling, const UINT sbrRatio)
+-
+-{
+- SBR_PS_SIGNALING sbrSignaling;
+-
+- if (transportType == TT_UNKNOWN || sbrRatio == 0) {
+- sbrSignaling = SIG_UNKNOWN; /* Needed parameters have not been set */
+- return sbrSignaling;
+- } else {
+- sbrSignaling =
+- SIG_EXPLICIT_HIERARCHICAL; /* default: explicit hierarchical signaling
+- */
+- }
+-
+- if ((audioObjectType == AOT_AAC_LC) || (audioObjectType == AOT_SBR) ||
+- (audioObjectType == AOT_PS) || (audioObjectType == AOT_MP2_AAC_LC) ||
+- (audioObjectType == AOT_MP2_SBR)) {
+- switch (transportType) {
+- case TT_MP4_ADIF:
+- case TT_MP4_ADTS:
+- sbrSignaling = SIG_IMPLICIT; /* For MPEG-2 transport types, only
+- implicit signaling is possible */
+- break;
+-
+- case TT_MP4_RAW:
+- case TT_MP4_LATM_MCP1:
+- case TT_MP4_LATM_MCP0:
+- case TT_MP4_LOAS:
+- default:
+- if (transportSignaling == 0xFF) {
+- /* Defaults */
+- sbrSignaling = SIG_EXPLICIT_HIERARCHICAL;
+- } else {
+- /* User set parameters */
+- /* Attention: Backward compatible explicit signaling does only work
+- * with AMV1 for LATM/LOAS */
+- sbrSignaling = (SBR_PS_SIGNALING)transportSignaling;
+- }
+- break;
+- }
+- }
+-
+- return sbrSignaling;
+-}
+-
+ /****************************************************************************
+ Allocate Encoder
+ ****************************************************************************/
+@@ -672,46 +519,14 @@ AAC_ENCODER_ERROR aacEncDefaultConfig(HANDLE_AACENC_CONFIG hAacConfig,
+
+ config->userAncDataRate = 0;
+
+- /* SBR rate is set to 0 here, which means it should be set automatically
+- in FDKaacEnc_AdjustEncSettings() if the user did not set a rate
+- expilicitely. */
+- config->userSbrRatio = 0;
+-
+- /* SBR enable set to -1 means to inquire ELD audio configurator for reasonable
+- * configuration. */
+- config->userSbrEnabled = (UCHAR)-1;
+-
+ return AAC_ENC_OK;
+ }
+
+-static void aacEncDistributeSbrBits(CHANNEL_MAPPING *channelMapping,
+- SBR_ELEMENT_INFO *sbrElInfo, INT bitRate) {
+- INT codebits = bitRate;
+- int el;
+-
+- /* Copy Element info */
+- for (el = 0; el < channelMapping->nElements; el++) {
+- sbrElInfo[el].ChannelIndex[0] = channelMapping->elInfo[el].ChannelIndex[0];
+- sbrElInfo[el].ChannelIndex[1] = channelMapping->elInfo[el].ChannelIndex[1];
+- sbrElInfo[el].elType = channelMapping->elInfo[el].elType;
+- sbrElInfo[el].bitRate =
+- fMultIfloor(channelMapping->elInfo[el].relativeBits, bitRate);
+- sbrElInfo[el].instanceTag = channelMapping->elInfo[el].instanceTag;
+- sbrElInfo[el].nChannelsInEl = channelMapping->elInfo[el].nChannelsInEl;
+- sbrElInfo[el].fParametricStereo = 0;
+- sbrElInfo[el].fDualMono = 0;
+-
+- codebits -= sbrElInfo[el].bitRate;
+- }
+- sbrElInfo[0].bitRate += codebits;
+-}
+-
+ static INT aacEncoder_LimitBitrate(const HANDLE_TRANSPORTENC hTpEnc,
+ const INT samplingRate,
+ const INT frameLength, const INT nChannels,
+ const CHANNEL_MODE channelMode, INT bitRate,
+- const INT nSubFrames, const INT sbrActive,
+- const INT sbrDownSampleRate,
++ const INT nSubFrames,
+ const UINT syntaxFlags,
+ const AUDIO_OBJECT_TYPE aot) {
+ INT coreSamplingRate;
+@@ -719,89 +534,18 @@ static INT aacEncoder_LimitBitrate(const HANDLE_TRANSPORTENC hTpEnc,
+
+ FDKaacEnc_InitChannelMapping(channelMode, CH_ORDER_MPEG, &cm);
+
+- if (sbrActive) {
+- coreSamplingRate =
+- samplingRate >>
+- (sbrEncoder_IsSingleRatePossible(aot) ? (sbrDownSampleRate - 1) : 1);
+- } else {
+- coreSamplingRate = samplingRate;
+- }
++ coreSamplingRate = samplingRate;
+
+ /* Limit bit rate in respect to the core coder */
+ bitRate = FDKaacEnc_LimitBitrate(hTpEnc, aot, coreSamplingRate, frameLength,
+ nChannels, cm.nChannelsEff, bitRate, -1,
+ NULL, AACENC_BR_MODE_INVALID, nSubFrames);
+
+- /* Limit bit rate in respect to available SBR modes if active */
+- if (sbrActive) {
+- int numIterations = 0;
+- INT initialBitrate, adjustedBitrate;
+- adjustedBitrate = bitRate;
+-
+- /* Find total bitrate which provides valid configuration for each SBR
+- * element. */
+- do {
+- int e;
+- SBR_ELEMENT_INFO sbrElInfo[((8))];
+- FDK_ASSERT(cm.nElements <= ((8)));
+-
+- initialBitrate = adjustedBitrate;
+-
+- /* Get bit rate for each SBR element */
+- aacEncDistributeSbrBits(&cm, sbrElInfo, initialBitrate);
+-
+- for (e = 0; e < cm.nElements; e++) {
+- INT sbrElementBitRateIn, sbrBitRateOut;
+-
+- if (cm.elInfo[e].elType != ID_SCE && cm.elInfo[e].elType != ID_CPE) {
+- continue;
+- }
+- sbrElementBitRateIn = sbrElInfo[e].bitRate;
+-
+- sbrBitRateOut = sbrEncoder_LimitBitRate(sbrElementBitRateIn,
+- cm.elInfo[e].nChannelsInEl,
+- coreSamplingRate, aot);
+-
+- if (sbrBitRateOut == 0) {
+- return 0;
+- }
+-
+- /* If bitrates don't match, distribution and limiting needs to be
+- determined again. Abort element loop and restart with adapted
+- bitrate. */
+- if (sbrElementBitRateIn != sbrBitRateOut) {
+- if (sbrElementBitRateIn < sbrBitRateOut) {
+- adjustedBitrate = fMax(initialBitrate,
+- (INT)fDivNorm((FIXP_DBL)(sbrBitRateOut + 8),
+- cm.elInfo[e].relativeBits));
+- break;
+- }
+-
+- if (sbrElementBitRateIn > sbrBitRateOut) {
+- adjustedBitrate = fMin(initialBitrate,
+- (INT)fDivNorm((FIXP_DBL)(sbrBitRateOut - 8),
+- cm.elInfo[e].relativeBits));
+- break;
+- }
+-
+- } /* sbrElementBitRateIn != sbrBitRateOut */
+-
+- } /* elements */
+-
+- numIterations++; /* restrict iteration to worst case of num elements */
+-
+- } while ((initialBitrate != adjustedBitrate) &&
+- (numIterations <= cm.nElements));
+-
+- /* Unequal bitrates mean that no reasonable bitrate configuration found. */
+- bitRate = (initialBitrate == adjustedBitrate) ? adjustedBitrate : 0;
+- }
+-
+ /* Limit bit rate in respect to available MPS modes if active */
+ if ((aot == AOT_ER_AAC_ELD) && (syntaxFlags & AC_LD_MPS) &&
+ (channelMode == MODE_1)) {
+ bitRate = FDK_MpegsEnc_GetClosestBitRate(
+- aot, MODE_212, samplingRate, (sbrActive) ? sbrDownSampleRate : 0,
++ aot, MODE_212, samplingRate, 0,
+ bitRate);
+ }
+
+@@ -814,25 +558,13 @@ static INT aacEncoder_LimitBitrate(const HANDLE_TRANSPORTENC hTpEnc,
+ * \hAacConfig Internal encoder config
+ * \return Bitrate
+ */
+-static INT FDKaacEnc_GetCBRBitrate(const HANDLE_AACENC_CONFIG hAacConfig,
+- const INT userSbrRatio) {
++static INT FDKaacEnc_GetCBRBitrate(const HANDLE_AACENC_CONFIG hAacConfig) {
+ INT bitrate = FDKaacEnc_GetChannelModeConfiguration(hAacConfig->channelMode)
+ ->nChannelsEff *
+ hAacConfig->sampleRate;
+
+ if (isPsActive(hAacConfig->audioObjectType)) {
+ bitrate = 1 * bitrate; /* 0.5 bit per sample */
+- } else if (isSbrActive(hAacConfig)) {
+- if ((userSbrRatio == 2) ||
+- ((userSbrRatio == 0) &&
+- (hAacConfig->audioObjectType != AOT_ER_AAC_ELD))) {
+- bitrate = (bitrate + (bitrate >> 2)) >> 1; /* 0.625 bits per sample */
+- }
+- if ((userSbrRatio == 1) ||
+- ((userSbrRatio == 0) &&
+- (hAacConfig->audioObjectType == AOT_ER_AAC_ELD))) {
+- bitrate = (bitrate + (bitrate >> 3)); /* 1.125 bits per sample */
+- }
+ } else {
+ bitrate = bitrate + (bitrate >> 1); /* 1.5 bits per sample */
+ }
+@@ -886,10 +618,6 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ return AACENC_INVALID_CONFIG; /* downscaling only allowed for AOT_ER_AAC_ELD
+ */
+ }
+- if (config->userDownscaleFactor > 1 && config->userSbrEnabled == 1) {
+- return AACENC_INVALID_CONFIG; /* downscaling only allowed for AOT_ER_AAC_ELD
+- w/o SBR */
+- }
+ if (config->userDownscaleFactor > 1 && config->userChannelMode == 128) {
+ return AACENC_INVALID_CONFIG; /* disallow downscaling for AAC-ELDv2 */
+ }
+@@ -943,8 +671,6 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ hAacConfig->syntaxFlags |= ((config->userErTools & 0x2) ? AC_ER_HCR : 0);
+ hAacConfig->syntaxFlags |= ((config->userErTools & 0x4) ? AC_ER_RVLC : 0);
+ hAacConfig->syntaxFlags |=
+- ((config->userSbrEnabled == 1) ? AC_SBR_PRESENT : 0);
+- hAacConfig->syntaxFlags |=
+ ((config->userChannelMode == MODE_212) ? AC_LD_MPS : 0);
+ config->userTpType =
+ (config->userTpType != TT_UNKNOWN) ? config->userTpType : TT_MP4_LOAS;
+@@ -974,25 +700,6 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ break;
+ }
+
+- /* Initialize SBR parameters */
+- if ((config->userSbrRatio == 0) && (isSbrActive(hAacConfig))) {
+- /* Automatic SBR ratio configuration
+- * - downsampled SBR for ELD
+- * - otherwise always dualrate SBR
+- */
+- if (hAacConfig->audioObjectType == AOT_ER_AAC_ELD) {
+- hAacConfig->sbrRatio = ((hAacConfig->syntaxFlags & AC_LD_MPS) &&
+- (hAacConfig->sampleRate >= 27713))
+- ? 2
+- : 1;
+- } else {
+- hAacConfig->sbrRatio = 2;
+- }
+- } else {
+- /* SBR ratio has been set by the user, so use it. */
+- hAacConfig->sbrRatio = isSbrActive(hAacConfig) ? config->userSbrRatio : 0;
+- }
+-
+ /* Set default bitrate */
+ hAacConfig->bitRate = config->userBitrate;
+
+@@ -1001,7 +708,7 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ /* Set default bitrate if no external bitrate declared. */
+ if (config->userBitrate == (UINT)-1) {
+ hAacConfig->bitRate =
+- FDKaacEnc_GetCBRBitrate(hAacConfig, config->userSbrRatio);
++ FDKaacEnc_GetCBRBitrate(hAacConfig);
+ }
+ hAacConfig->averageBits = -1;
+ break;
+@@ -1074,33 +781,8 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ }
+ }
+
+- if ((hAacConfig->audioObjectType == AOT_ER_AAC_ELD) &&
+- !(hAacConfig->syntaxFlags & AC_ELD_DOWNSCALE) &&
+- (config->userSbrEnabled == (UCHAR)-1) && (config->userSbrRatio == 0) &&
+- ((hAacConfig->syntaxFlags & AC_LD_MPS) == 0)) {
+- const ELD_SBR_CONFIGURATOR *pConfig = NULL;
+-
+- if (NULL !=
+- (pConfig = eldSbrConfigurator(
+- FDKaacEnc_GetChannelModeConfiguration(hAacConfig->channelMode)
+- ->nChannels,
+- hAacConfig->sampleRate, hAacConfig->bitRate))) {
+- hAacConfig->syntaxFlags |= (pConfig->sbrMode == 0) ? 0 : AC_SBR_PRESENT;
+- hAacConfig->syntaxFlags |= (pConfig->chMode == MODE_212) ? AC_LD_MPS : 0;
+- hAacConfig->channelMode =
+- GetCoreChannelMode(pConfig->chMode, hAacConfig->audioObjectType);
+- hAacConfig->nChannels =
+- FDKaacEnc_GetChannelModeConfiguration(hAacConfig->channelMode)
+- ->nChannels;
+- hAacConfig->sbrRatio =
+- (pConfig->sbrMode == 0) ? 0 : (pConfig->sbrMode == 1) ? 1 : 2;
+- }
+- }
+-
+ {
+- UCHAR tpSignaling =
+- getSbrSignalingMode(hAacConfig->audioObjectType, config->userTpType,
+- config->userTpSignaling, hAacConfig->sbrRatio);
++ UCHAR tpSignaling = SIG_UNKNOWN;
+
+ if ((hAacConfig->audioObjectType == AOT_AAC_LC ||
+ hAacConfig->audioObjectType == AOT_SBR ||
+@@ -1112,15 +794,6 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ /* For backward compatible explicit signaling, AMV1 has to be active */
+ return AACENC_INVALID_CONFIG;
+ }
+-
+- if ((hAacConfig->audioObjectType == AOT_AAC_LC ||
+- hAacConfig->audioObjectType == AOT_SBR ||
+- hAacConfig->audioObjectType == AOT_PS) &&
+- (tpSignaling == 0) && (hAacConfig->sbrRatio == 1)) {
+- /* Downsampled SBR has to be signaled explicitely (for transmission of SBR
+- * sampling fequency) */
+- return AACENC_INVALID_CONFIG;
+- }
+ }
+
+ switch (hAacConfig->bitrateMode) {
+@@ -1135,7 +808,6 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ NULL, hAacConfig->sampleRate, hAacConfig->framelength,
+ hAacConfig->nChannels, hAacConfig->channelMode,
+ hAacConfig->bitRate, hAacConfig->nSubFrames,
+- isSbrActive(hAacConfig), hAacConfig->sbrRatio,
+ hAacConfig->syntaxFlags, hAacConfig->audioObjectType))) {
+ return AACENC_INVALID_CONFIG;
+ }
+@@ -1167,13 +839,6 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ }
+ }
+
+- if ((hAacConfig->nChannels > hAacEncoder->nMaxAacChannels) ||
+- ((FDKaacEnc_GetChannelModeConfiguration(hAacConfig->channelMode)
+- ->nChannelsEff > hAacEncoder->nMaxSbrChannels) &&
+- isSbrActive(hAacConfig))) {
+- return AACENC_INVALID_CONFIG; /* not enough channels allocated */
+- }
+-
+ /* Meta data restriction. */
+ switch (hAacConfig->audioObjectType) {
+ /* Allow metadata support */
+@@ -1198,22 +863,6 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ return err;
+ }
+
+-static INT aacenc_SbrCallback(void *self, HANDLE_FDK_BITSTREAM hBs,
+- const INT sampleRateIn, const INT sampleRateOut,
+- const INT samplesPerFrame,
+- const AUDIO_OBJECT_TYPE coreCodec,
+- const MP4_ELEMENT_ID elementID,
+- const INT elementIndex, const UCHAR harmonicSbr,
+- const UCHAR stereoConfigIndex,
+- const UCHAR configMode, UCHAR *configChanged,
+- const INT downscaleFactor) {
+- HANDLE_AACENCODER hAacEncoder = (HANDLE_AACENCODER)self;
+-
+- sbrEncoder_GetHeader(hAacEncoder->hEnvEnc, hBs, elementIndex, 0);
+-
+- return 0;
+-}
+-
+ INT aacenc_SscCallback(void *self, HANDLE_FDK_BITSTREAM hBs,
+ const AUDIO_OBJECT_TYPE coreCodec,
+ const INT samplingRate, const INT frameSize,
+@@ -1230,7 +879,6 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+ AACENC_ERROR err = AACENC_OK;
+
+ INT aacBufferOffset = 0;
+- HANDLE_SBR_ENCODER *hSbrEncoder = &hAacEncoder->hEnvEnc;
+ HANDLE_AACENC_CONFIG hAacConfig = &hAacEncoder->aacConfig;
+
+ hAacEncoder->nZerosAppended = 0; /* count appended zeros */
+@@ -1245,11 +893,6 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+ return err;
+ }
+ frameLength = hAacConfig->framelength; /* adapt temporal framelength */
+-
+- /* Seamless channel reconfiguration in sbr not fully implemented */
+- if ((prevChMode != hAacConfig->channelMode) && isSbrActive(hAacConfig)) {
+- InitFlags |= AACENC_INIT_STATES;
+- }
+ }
+
+ /* Clear input buffer */
+@@ -1275,78 +918,13 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+ hAacConfig->ancDataBitRate = 0;
+ }
+
+- if ((NULL != hAacEncoder->hEnvEnc) && isSbrActive(hAacConfig) &&
+- ((InitFlags & AACENC_INIT_CONFIG) || (InitFlags & AACENC_INIT_STATES))) {
+- INT sbrError;
+- UINT initFlag = 0;
+- SBR_ELEMENT_INFO sbrElInfo[(8)];
+- CHANNEL_MAPPING channelMapping;
+- CHANNEL_MODE channelMode = isPsActive(hAacConfig->audioObjectType)
+- ? config->userChannelMode
+- : hAacConfig->channelMode;
+- INT numChannels = isPsActive(hAacConfig->audioObjectType)
+- ? config->nChannels
+- : hAacConfig->nChannels;
+-
+- if (FDKaacEnc_InitChannelMapping(channelMode, hAacConfig->channelOrder,
+- &channelMapping) != AAC_ENC_OK) {
+- return AACENC_INIT_ERROR;
+- }
+-
+- /* Check return value and if the SBR encoder can handle enough elements */
+- if (channelMapping.nElements > (8)) {
+- return AACENC_INIT_ERROR;
+- }
+-
+- aacEncDistributeSbrBits(&channelMapping, sbrElInfo, hAacConfig->bitRate);
+-
+- initFlag += (InitFlags & AACENC_INIT_STATES) ? 1 : 0;
+-
+- /* Let the SBR encoder take a look at the configuration and change if
+- * required. */
+- sbrError = sbrEncoder_Init(
+- *hSbrEncoder, sbrElInfo, channelMapping.nElements,
+- hAacEncoder->inputBuffer, hAacEncoder->inputBufferSizePerChannel,
+- &hAacConfig->bandWidth, &aacBufferOffset, &numChannels,
+- hAacConfig->syntaxFlags, &hAacConfig->sampleRate, &hAacConfig->sbrRatio,
+- &frameLength, hAacConfig->audioObjectType, &hAacEncoder->nDelay,
+- (hAacConfig->audioObjectType == AOT_ER_AAC_ELD) ? 1 : TRANS_FAC,
+- (config->userTpHeaderPeriod != 0xFF)
+- ? config->userTpHeaderPeriod
+- : DEFAULT_HEADER_PERIOD_REPETITION_RATE,
+- initFlag);
+-
+- /* Suppress AOT reconfiguration and check error status. */
+- if ((sbrError) || (numChannels != hAacConfig->nChannels)) {
+- return AACENC_INIT_SBR_ERROR;
+- }
+-
+- if (numChannels == 1) {
+- hAacConfig->channelMode = MODE_1;
+- }
+-
+- /* Never use PNS if SBR is active */
+- if (hAacConfig->usePns) {
+- hAacConfig->usePns = 0;
+- }
+-
+- /* estimated bitrate consumed by SBR or PS */
+- hAacConfig->ancDataBitRate = sbrEncoder_GetEstimateBitrate(*hSbrEncoder);
+-
+- } /* sbr initialization */
+-
+ if ((hAacEncoder->hMpsEnc != NULL) && (hAacConfig->syntaxFlags & AC_LD_MPS)) {
+ int coreCoderDelay = DELAY_AACELD(hAacConfig->framelength);
+
+- if (isSbrActive(hAacConfig)) {
+- coreCoderDelay = hAacConfig->sbrRatio * coreCoderDelay +
+- sbrEncoder_GetInputDataDelay(*hSbrEncoder);
+- }
+-
+ if (MPS_ENCODER_OK !=
+ FDK_MpegsEnc_Init(hAacEncoder->hMpsEnc, hAacConfig->audioObjectType,
+ config->userSamplerate, hAacConfig->bitRate,
+- isSbrActive(hAacConfig) ? hAacConfig->sbrRatio : 0,
++ 0,
+ frameLength, /* for dual rate sbr this value is
+ already multiplied by 2 */
+ hAacEncoder->inputBufferSizePerChannel,
+@@ -1365,8 +943,7 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+
+ FDKaacEnc_MapConfig(
+ &hAacEncoder->coderConfig, config,
+- getSbrSignalingMode(hAacConfig->audioObjectType, config->userTpType,
+- config->userTpSignaling, hAacConfig->sbrRatio),
++ SIG_UNKNOWN,
+ hAacConfig);
+
+ /* create flags for transport encoder */
+@@ -1405,11 +982,6 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+ ((InitFlags & AACENC_INIT_CONFIG) || (InitFlags & AACENC_INIT_STATES))) {
+ INT inputDataDelay = DELAY_AAC(hAacConfig->framelength);
+
+- if (isSbrActive(hAacConfig) && hSbrEncoder != NULL) {
+- inputDataDelay = hAacConfig->sbrRatio * inputDataDelay +
+- sbrEncoder_GetInputDataDelay(*hSbrEncoder);
+- }
+-
+ if (FDK_MetadataEnc_Init(hAacEncoder->hMetadataEnc,
+ ((InitFlags & AACENC_INIT_STATES) ? 1 : 0),
+ config->userMetaDataMode, inputDataDelay,
+@@ -1428,10 +1000,6 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+ hAacEncoder->nDelayCore =
+ hAacEncoder->nDelay -
+ fMax(0, FDK_MpegsEnc_GetDecDelay(hAacEncoder->hMpsEnc));
+- } else if (isSbrActive(hAacConfig) && hSbrEncoder != NULL) {
+- hAacEncoder->nDelayCore =
+- hAacEncoder->nDelay -
+- fMax(0, sbrEncoder_GetSbrDecDelay(hAacEncoder->hEnvEnc));
+ } else {
+ hAacEncoder->nDelayCore = hAacEncoder->nDelay;
+ }
+@@ -1497,17 +1065,10 @@ AACENC_ERROR aacEncOpen(HANDLE_AACENCODER *phAacEncoder, const UINT encModules,
+ /* Determine max channel configuration. */
+ if (maxChannels == 0) {
+ hAacEncoder->nMaxAacChannels = (8);
+- hAacEncoder->nMaxSbrChannels = (8);
+ } else {
+ hAacEncoder->nMaxAacChannels = (maxChannels & 0x00FF);
+- if ((hAacEncoder->encoder_modis & ENC_MODE_FLAG_SBR)) {
+- hAacEncoder->nMaxSbrChannels = (maxChannels & 0xFF00)
+- ? (maxChannels >> 8)
+- : hAacEncoder->nMaxAacChannels;
+- }
+
+- if ((hAacEncoder->nMaxAacChannels > (8)) ||
+- (hAacEncoder->nMaxSbrChannels > (8))) {
++ if ((hAacEncoder->nMaxAacChannels > (8))) {
+ err = AACENC_INVALID_CONFIG;
+ goto bail;
+ }
+@@ -1515,7 +1076,6 @@ AACENC_ERROR aacEncOpen(HANDLE_AACENCODER *phAacEncoder, const UINT encModules,
+
+ /* Max number of elements could be tuned any more. */
+ hAacEncoder->nMaxAacElements = fixMin(((8)), hAacEncoder->nMaxAacChannels);
+- hAacEncoder->nMaxSbrElements = fixMin((8), hAacEncoder->nMaxSbrChannels);
+
+ /* In case of memory overlay, allocate memory out of libraries */
+
+@@ -1533,23 +1093,6 @@ AACENC_ERROR aacEncOpen(HANDLE_AACENCODER *phAacEncoder, const UINT encModules,
+ goto bail;
+ }
+
+- /* Open SBR Encoder */
+- if (hAacEncoder->encoder_modis & ENC_MODE_FLAG_SBR) {
+- if (sbrEncoder_Open(
+- &hAacEncoder->hEnvEnc, hAacEncoder->nMaxSbrElements,
+- hAacEncoder->nMaxSbrChannels,
+- (hAacEncoder->encoder_modis & ENC_MODE_FLAG_PS) ? 1 : 0)) {
+- err = AACENC_MEMORY_ERROR;
+- goto bail;
+- }
+-
+- if (NULL == (hAacEncoder->pSbrPayload = (SBRENC_EXT_PAYLOAD *)FDKcalloc(
+- 1, sizeof(SBRENC_EXT_PAYLOAD)))) {
+- err = AACENC_MEMORY_ERROR;
+- goto bail;
+- }
+- } /* (encoder_modis&ENC_MODE_FLAG_SBR) */
+-
+ /* Open Aac Encoder */
+ if (FDKaacEnc_Open(&hAacEncoder->hAacEnc, hAacEncoder->nMaxAacElements,
+ hAacEncoder->nMaxAacChannels, (1)) != AAC_ENC_OK) {
+@@ -1603,11 +1146,6 @@ AACENC_ERROR aacEncOpen(HANDLE_AACENCODER *phAacEncoder, const UINT encModules,
+
+ C_ALLOC_SCRATCH_END(_pLibInfo, LIB_INFO, FDK_MODULE_LAST)
+ }
+- if (transportEnc_RegisterSbrCallback(hAacEncoder->hTpEnc, aacenc_SbrCallback,
+- hAacEncoder) != 0) {
+- err = AACENC_INIT_TP_ERROR;
+- goto bail;
+- }
+ if (transportEnc_RegisterSscCallback(hAacEncoder->hTpEnc, aacenc_SscCallback,
+ hAacEncoder) != 0) {
+ err = AACENC_INIT_TP_ERROR;
+@@ -1655,13 +1193,6 @@ AACENC_ERROR aacEncClose(HANDLE_AACENCODER *phAacEncoder) {
+ hAacEncoder->outBuffer = NULL;
+ }
+
+- if (hAacEncoder->hEnvEnc) {
+- sbrEncoder_Close(&hAacEncoder->hEnvEnc);
+- }
+- if (hAacEncoder->pSbrPayload != NULL) {
+- FDKfree(hAacEncoder->pSbrPayload);
+- hAacEncoder->pSbrPayload = NULL;
+- }
+ if (hAacEncoder->hAacEnc) {
+ FDKaacEnc_Close(&hAacEncoder->hAacEnc);
+ }
+@@ -1825,9 +1356,6 @@ AACENC_ERROR aacEncEncode(const HANDLE_AACENCODER hAacEncoder,
+ for (i = 0; i < MAX_TOTAL_EXT_PAYLOADS; i++) {
+ hAacEncoder->extPayload[i].associatedChElement = -1;
+ }
+- if (hAacEncoder->pSbrPayload != NULL) {
+- FDKmemclear(hAacEncoder->pSbrPayload, sizeof(*hAacEncoder->pSbrPayload));
+- }
+
+ /*
+ * Calculate Meta Data info.
+@@ -1895,41 +1423,6 @@ AACENC_ERROR aacEncEncode(const HANDLE_AACENCODER hAacEncoder,
+ }
+ }
+
+- if ((NULL != hAacEncoder->hEnvEnc) && (NULL != hAacEncoder->pSbrPayload) &&
+- isSbrActive(&hAacEncoder->aacConfig)) {
+- INT nPayload = 0;
+-
+- /*
+- * Encode SBR data.
+- */
+- if (sbrEncoder_EncodeFrame(hAacEncoder->hEnvEnc, hAacEncoder->inputBuffer,
+- hAacEncoder->inputBufferSizePerChannel,
+- hAacEncoder->pSbrPayload->dataSize[nPayload],
+- hAacEncoder->pSbrPayload->data[nPayload])) {
+- err = AACENC_ENCODE_ERROR;
+- goto bail;
+- } else {
+- /* Add SBR extension payload */
+- for (i = 0; i < (8); i++) {
+- if (hAacEncoder->pSbrPayload->dataSize[nPayload][i] > 0) {
+- hAacEncoder->extPayload[nExtensions].pData =
+- hAacEncoder->pSbrPayload->data[nPayload][i];
+- {
+- hAacEncoder->extPayload[nExtensions].dataSize =
+- hAacEncoder->pSbrPayload->dataSize[nPayload][i];
+- hAacEncoder->extPayload[nExtensions].associatedChElement = i;
+- }
+- hAacEncoder->extPayload[nExtensions].dataType =
+- EXT_SBR_DATA; /* Once SBR Encoder supports SBR CRC set
+- EXT_SBR_DATA_CRC */
+- nExtensions++; /* or EXT_SBR_DATA according to configuration. */
+- FDK_ASSERT(nExtensions <= MAX_TOTAL_EXT_PAYLOADS);
+- }
+- }
+- nPayload++;
+- }
+- } /* sbrEnabled */
+-
+ if ((inargs->numAncBytes > 0) &&
+ (getBufDescIdx(inBufDesc, IN_ANCILLRY_DATA) != -1)) {
+ INT idx = getBufDescIdx(inBufDesc, IN_ANCILLRY_DATA);
+@@ -1962,14 +1455,6 @@ AACENC_ERROR aacEncEncode(const HANDLE_AACENCODER hAacEncoder,
+ hAacEncoder->nSamplesRead -= hAacEncoder->nSamplesToRead;
+
+ /*
+- * Delay balancing buffer handling
+- */
+- if (isSbrActive(&hAacEncoder->aacConfig)) {
+- sbrEncoder_UpdateBuffers(hAacEncoder->hEnvEnc, hAacEncoder->inputBuffer,
+- hAacEncoder->inputBufferSizePerChannel);
+- }
+-
+- /*
+ * Make bitstream public
+ */
+ if ((outBufDesc != NULL) && (outBufDesc->numBufs >= 1)) {
+@@ -2043,7 +1528,6 @@ AACENC_ERROR aacEncGetLibInfo(LIB_INFO *info) {
+
+ FDK_toolsGetLibInfo(info);
+ transportEnc_GetLibInfo(info);
+- sbrEncoder_GetLibInfo(info);
+ FDK_MpegsEnc_GetLibInfo(info);
+
+ /* search for next free tab */
+@@ -2242,23 +1726,10 @@ AACENC_ERROR aacEncoder_SetParam(const HANDLE_AACENCODER hAacEncoder,
+ }
+ break;
+ case AACENC_SBR_RATIO:
+- if (settings->userSbrRatio != value) {
+- if (!((value == 0) || (value == 1) || (value == 2))) {
+- err = AACENC_INVALID_CONFIG;
+- break;
+- }
+- settings->userSbrRatio = value;
+- hAacEncoder->InitFlags |=
+- AACENC_INIT_CONFIG | AACENC_INIT_STATES | AACENC_INIT_TRANSPORT;
+- }
++ err = AACENC_INVALID_CONFIG;
+ break;
+ case AACENC_SBR_MODE:
+- if ((settings->userSbrEnabled != value) &&
+- (NULL != hAacEncoder->hEnvEnc)) {
+- settings->userSbrEnabled = value;
+- hAacEncoder->InitFlags |=
+- AACENC_INIT_CONFIG | AACENC_INIT_STATES | AACENC_INIT_TRANSPORT;
+- }
++ err = AACENC_INVALID_CONFIG;
+ break;
+ case AACENC_TRANSMUX:
+ if (settings->userTpType != (TRANSPORT_TYPE)value) {
+@@ -2421,21 +1892,16 @@ UINT aacEncoder_GetParam(const HANDLE_AACENCODER hAacEncoder,
+ value = (UINT)hAacEncoder->aacConfig.framelength;
+ break;
+ case AACENC_SBR_RATIO:
+- value = isSbrActive(&hAacEncoder->aacConfig)
+- ? hAacEncoder->aacConfig.sbrRatio
+- : 0;
++ value = 0;
+ break;
+ case AACENC_SBR_MODE:
+- value =
+- (UINT)(hAacEncoder->aacConfig.syntaxFlags & AC_SBR_PRESENT) ? 1 : 0;
++ value = 0;
+ break;
+ case AACENC_TRANSMUX:
+ value = (UINT)settings->userTpType;
+ break;
+ case AACENC_SIGNALING_MODE:
+- value = (UINT)getSbrSignalingMode(
+- hAacEncoder->aacConfig.audioObjectType, settings->userTpType,
+- settings->userTpSignaling, hAacEncoder->aacConfig.sbrRatio);
++ value = SIG_UNKNOWN;
+ break;
+ case AACENC_PROTECTION:
+ value = (UINT)settings->userTpProtection;
+diff --git a/libMpegTPDec/include/tp_data.h b/libMpegTPDec/include/tp_data.h
+index b015332..180b097 100644
+--- a/libMpegTPDec/include/tp_data.h
++++ b/libMpegTPDec/include/tp_data.h
+@@ -372,15 +372,6 @@ typedef INT (*cbSsc_t)(void *, HANDLE_FDK_BITSTREAM,
+ const INT coreSbrFrameLengthIndex, const INT configBytes,
+ const UCHAR configMode, UCHAR *configChanged);
+
+-typedef INT (*cbSbr_t)(void *self, HANDLE_FDK_BITSTREAM hBs,
+- const INT sampleRateIn, const INT sampleRateOut,
+- const INT samplesPerFrame,
+- const AUDIO_OBJECT_TYPE coreCodec,
+- const MP4_ELEMENT_ID elementID, const INT elementIndex,
+- const UCHAR harmonicSbr, const UCHAR stereoConfigIndex,
+- const UCHAR configMode, UCHAR *configChanged,
+- const INT downscaleFactor);
+-
+ typedef INT (*cbUsac_t)(void *self, HANDLE_FDK_BITSTREAM hBs);
+
+ typedef INT (*cbUniDrc_t)(void *self, HANDLE_FDK_BITSTREAM hBs,
+@@ -401,8 +392,6 @@ typedef struct {
+ callback. */
+ cbSsc_t cbSsc; /*!< Function pointer for SSC parser callback. */
+ void *cbSscData; /*!< User data pointer for SSC parser callback. */
+- cbSbr_t cbSbr; /*!< Function pointer for SBR header parser callback. */
+- void *cbSbrData; /*!< User data pointer for SBR header parser callback. */
+ cbUsac_t cbUsac;
+ void *cbUsacData;
+ cbUniDrc_t cbUniDrc; /*!< Function pointer for uniDrcConfig and
+diff --git a/libMpegTPDec/include/tpdec_lib.h b/libMpegTPDec/include/tpdec_lib.h
+index 30e53c1..04e3d07 100644
+--- a/libMpegTPDec/include/tpdec_lib.h
++++ b/libMpegTPDec/include/tpdec_lib.h
+@@ -435,18 +435,6 @@ int transportDec_RegisterSscCallback(HANDLE_TRANSPORTDEC hTp,
+ const cbSsc_t cbSscParse, void *user_data);
+
+ /**
+- * \brief Register SBR header parser callback.
+- * \param hTp Handle of transport decoder.
+- * \param cbUpdateConfig Pointer to a callback function to handle SBR header
+- * parsing.
+- * \param user_data void pointer for user data passed to the callback as
+- * first parameter.
+- * \return 0 on success.
+- */
+-int transportDec_RegisterSbrCallback(HANDLE_TRANSPORTDEC hTpDec,
+- const cbSbr_t cbSbr, void *user_data);
+-
+-/**
+ * \brief Register USAC SC parser callback.
+ * \param hTp Handle of transport decoder.
+ * \param cbUpdateConfig Pointer to a callback function to handle USAC SC
+diff --git a/libMpegTPDec/src/tpdec_asc.cpp b/libMpegTPDec/src/tpdec_asc.cpp
+index 28bc22d..bee0917 100644
+--- a/libMpegTPDec/src/tpdec_asc.cpp
++++ b/libMpegTPDec/src/tpdec_asc.cpp
+@@ -1296,27 +1296,6 @@ static INT ld_sbr_header(CSAudioSpecificConfig *asc, const INT dsFactor,
+ 1)) {
+ return TRANSPORTDEC_PARSE_ERROR;
+ }
+-
+- /* read elements of the passed channel_configuration until there is ID_NONE */
+- while ((element = channel_configuration_array[channelConfiguration][j]) !=
+- ID_NONE) {
+- /* Setup LFE element for upsampling too. This is essential especially for
+- * channel configs where the LFE element is not at the last position for
+- * example in channel config 13 or 14. It leads to memory leaks if the setup
+- * of the LFE element would be done later in the core. */
+- if (element == ID_SCE || element == ID_CPE || element == ID_LFE) {
+- error |= cb->cbSbr(
+- cb->cbSbrData, hBs, asc->m_samplingFrequency / dsFactor,
+- asc->m_extensionSamplingFrequency / dsFactor,
+- asc->m_samplesPerFrame / dsFactor, AOT_ER_AAC_ELD, element, i++, 0, 0,
+- asc->configMode, &asc->SbrConfigChanged, dsFactor);
+- if (error != TRANSPORTDEC_OK) {
+- goto bail;
+- }
+- }
+- j++;
+- }
+-bail:
+ return error;
+ }
+
+@@ -1353,40 +1332,6 @@ static TRANSPORTDEC_ERROR EldSpecificConfig_Parse(CSAudioSpecificConfig *asc,
+
+ asc->m_extensionSamplingFrequency = asc->m_samplingFrequency
+ << esc->m_sbrSamplingRate;
+-
+- if (cb->cbSbr != NULL) {
+- /* ELD reduced delay mode: LD-SBR initialization has to know the downscale
+- information. Postpone LD-SBR initialization and read ELD extension
+- information first. */
+- switch (asc->m_channelConfiguration) {
+- case 1:
+- case 2:
+- numSbrHeader = 1;
+- break;
+- case 3:
+- numSbrHeader = 2;
+- break;
+- case 4:
+- case 5:
+- case 6:
+- numSbrHeader = 3;
+- break;
+- case 7:
+- case 11:
+- case 12:
+- case 14:
+- numSbrHeader = 4;
+- break;
+- default:
+- numSbrHeader = 0;
+- break;
+- }
+- for (sbrIndex = 0; sbrIndex < numSbrHeader; sbrIndex++) {
+- ldSbrLen += skipSbrHeader(hBs, 0);
+- }
+- } else {
+- return TRANSPORTDEC_UNSUPPORTED_FORMAT;
+- }
+ }
+ esc->m_useLdQmfTimeAlign = 0;
+
+@@ -1751,21 +1696,10 @@ static TRANSPORTDEC_ERROR UsacRsv60DecoderConfig_Parse(
+ usc->element[i].m_noiseFilling = FDKreadBits(hBs, 1);
+ /* end of UsacCoreConfig() */
+ if (usc->m_sbrRatioIndex > 0) {
+- if (cb->cbSbr == NULL) {
+- return TRANSPORTDEC_UNKOWN_ERROR;
+- }
+ /* SbrConfig() ISO/IEC FDIS 23003-3 Table 11 */
+ usc->element[i].m_harmonicSBR = FDKreadBit(hBs);
+ usc->element[i].m_interTes = FDKreadBit(hBs);
+ usc->element[i].m_pvc = FDKreadBit(hBs);
+- if (cb->cbSbr(cb->cbSbrData, hBs, asc->m_samplingFrequency,
+- asc->m_extensionSamplingFrequency,
+- asc->m_samplesPerFrame, asc->m_aot, ID_SCE,
+- channelElementIdx, usc->element[i].m_harmonicSBR,
+- usc->element[i].m_stereoConfigIndex, asc->configMode,
+- &asc->SbrConfigChanged, 1)) {
+- return TRANSPORTDEC_PARSE_ERROR;
+- }
+ /* end of SbrConfig() */
+ }
+ usc->m_nUsacChannels += 1;
+@@ -1780,7 +1714,6 @@ static TRANSPORTDEC_ERROR UsacRsv60DecoderConfig_Parse(
+ usc->element[i].m_noiseFilling = FDKreadBits(hBs, 1);
+ /* end of UsacCoreConfig() */
+ if (usc->m_sbrRatioIndex > 0) {
+- if (cb->cbSbr == NULL) return TRANSPORTDEC_UNKOWN_ERROR;
+ /* SbrConfig() ISO/IEC FDIS 23003-3 */
+ usc->element[i].m_harmonicSBR = FDKreadBit(hBs);
+ usc->element[i].m_interTes = FDKreadBit(hBs);
+@@ -1798,14 +1731,6 @@ static TRANSPORTDEC_ERROR UsacRsv60DecoderConfig_Parse(
+ usc->element[i].m_stereoConfigIndex == 2)
+ ? ID_SCE
+ : ID_CPE;
+- if (cb->cbSbr(cb->cbSbrData, hBs, asc->m_samplingFrequency,
+- asc->m_extensionSamplingFrequency,
+- asc->m_samplesPerFrame, asc->m_aot, el_type,
+- channelElementIdx, usc->element[i].m_harmonicSBR,
+- usc->element[i].m_stereoConfigIndex, asc->configMode,
+- &asc->SbrConfigChanged, 1)) {
+- return TRANSPORTDEC_PARSE_ERROR;
+- }
+ }
+ /* end of SbrConfig() */
+
+@@ -1847,19 +1772,9 @@ static TRANSPORTDEC_ERROR UsacRsv60DecoderConfig_Parse(
+ usc->element[i].m_noiseFilling = 0;
+ usc->m_nUsacChannels += 1;
+ if (usc->m_sbrRatioIndex > 0) {
+- /* Use SBR for upsampling */
+- if (cb->cbSbr == NULL) return ErrorStatus = TRANSPORTDEC_UNKOWN_ERROR;
+ usc->element[i].m_harmonicSBR = (UCHAR)0;
+ usc->element[i].m_interTes = (UCHAR)0;
+ usc->element[i].m_pvc = (UCHAR)0;
+- if (cb->cbSbr(cb->cbSbrData, hBs, asc->m_samplingFrequency,
+- asc->m_extensionSamplingFrequency,
+- asc->m_samplesPerFrame, asc->m_aot, ID_LFE,
+- channelElementIdx, usc->element[i].m_harmonicSBR,
+- usc->element[i].m_stereoConfigIndex, asc->configMode,
+- &asc->SbrConfigChanged, 1)) {
+- return ErrorStatus = TRANSPORTDEC_PARSE_ERROR;
+- }
+ }
+ channelElementIdx++;
+ break;
+@@ -2301,19 +2216,6 @@ static TRANSPORTDEC_ERROR Drm_xHEAACDecoderConfig(
+ if (cb == NULL) {
+ return ErrorStatus;
+ }
+- if (cb->cbSbr != NULL) {
+- usc->element[elemIdx].m_harmonicSBR = FDKreadBit(hBs);
+- usc->element[elemIdx].m_interTes = FDKreadBit(hBs);
+- usc->element[elemIdx].m_pvc = FDKreadBit(hBs);
+- if (cb->cbSbr(cb->cbSbrData, hBs, asc->m_samplingFrequency,
+- asc->m_extensionSamplingFrequency,
+- asc->m_samplesPerFrame, asc->m_aot, ID_SCE, elemIdx,
+- usc->element[elemIdx].m_harmonicSBR,
+- usc->element[elemIdx].m_stereoConfigIndex,
+- asc->configMode, &asc->SbrConfigChanged, 1)) {
+- return ErrorStatus = TRANSPORTDEC_PARSE_ERROR;
+- }
+- }
+ }
+ break;
+ case 2: /* stereo: ID_USAC_CPE */
+@@ -2362,15 +2264,6 @@ static TRANSPORTDEC_ERROR Drm_xHEAACDecoderConfig(
+ usc->element[elemIdx].m_stereoConfigIndex == 2)
+ ? ID_SCE
+ : ID_CPE;
+- if (cb->cbSbr == NULL) return ErrorStatus = TRANSPORTDEC_UNKOWN_ERROR;
+- if (cb->cbSbr(cb->cbSbrData, hBs, asc->m_samplingFrequency,
+- asc->m_extensionSamplingFrequency,
+- asc->m_samplesPerFrame, asc->m_aot, el_type, elemIdx,
+- usc->element[elemIdx].m_harmonicSBR,
+- usc->element[elemIdx].m_stereoConfigIndex,
+- asc->configMode, &asc->SbrConfigChanged, 1)) {
+- return ErrorStatus = TRANSPORTDEC_PARSE_ERROR;
+- }
+ }
+ /*usc->element[elemIdx].m_stereoConfigIndex =*/FDKreadBits(hBs, 2);
+ if (usc->element[elemIdx].m_stereoConfigIndex > 0) {
+diff --git a/libMpegTPDec/src/tpdec_lib.cpp b/libMpegTPDec/src/tpdec_lib.cpp
+index 1976cb9..75b5150 100644
+--- a/libMpegTPDec/src/tpdec_lib.cpp
++++ b/libMpegTPDec/src/tpdec_lib.cpp
+@@ -602,16 +602,6 @@ int transportDec_RegisterSscCallback(HANDLE_TRANSPORTDEC hTpDec,
+ return 0;
+ }
+
+-int transportDec_RegisterSbrCallback(HANDLE_TRANSPORTDEC hTpDec,
+- const cbSbr_t cbSbr, void *user_data) {
+- if (hTpDec == NULL) {
+- return -1;
+- }
+- hTpDec->callbacks.cbSbr = cbSbr;
+- hTpDec->callbacks.cbSbrData = user_data;
+- return 0;
+-}
+-
+ int transportDec_RegisterUsacCallback(HANDLE_TRANSPORTDEC hTpDec,
+ const cbUsac_t cbUsac, void *user_data) {
+ if (hTpDec == NULL) {
+diff --git a/libMpegTPEnc/include/tpenc_lib.h b/libMpegTPEnc/include/tpenc_lib.h
+index 4eb89a7..ba6d672 100644
+--- a/libMpegTPEnc/include/tpenc_lib.h
++++ b/libMpegTPEnc/include/tpenc_lib.h
+@@ -148,18 +148,6 @@ typedef struct TRANSPORTENC *HANDLE_TRANSPORTENC;
+ CHANNEL_MODE transportEnc_GetChannelMode(int noChannels);
+
+ /**
+- * \brief Register SBR heaqder writer callback.
+- * \param hTp Handle of transport decoder.
+- * \param cbUpdateConfig Pointer to a callback function to handle SBR header
+- * writing.
+- * \param user_data void pointer for user data passed to the callback as
+- * first parameter.
+- * \return 0 on success.
+- */
+-int transportEnc_RegisterSbrCallback(HANDLE_TRANSPORTENC hTpEnc,
+- const cbSbr_t cbSbr, void *user_data);
+-
+-/**
+ * \brief Register USAC SC writer callback.
+ * \param hTp Handle of transport decoder.
+ * \param cbUpdateConfig Pointer to a callback function to handle USAC
+diff --git a/libMpegTPEnc/src/tpenc_asc.cpp b/libMpegTPEnc/src/tpenc_asc.cpp
+index 0b484a0..0f84b45 100644
+--- a/libMpegTPEnc/src/tpenc_asc.cpp
++++ b/libMpegTPEnc/src/tpenc_asc.cpp
+@@ -769,25 +769,6 @@ static int transportEnc_writeELDSpecificConfig(HANDLE_FDK_BITSTREAM hBs,
+ FDKwriteBits(hBs, (config->samplingRate == config->extSamplingRate) ? 0 : 1,
+ 1); /* Samplerate Flag */
+ FDKwriteBits(hBs, (config->flags & CC_SBRCRC) ? 1 : 0, 1); /* SBR CRC flag*/
+-
+- if (cb->cbSbr != NULL) {
+- const PCE_CONFIGURATION *pPce;
+- int e, sbrElementIndex = 0;
+-
+- pPce = getPceEntry(config->channelMode);
+-
+- for (e = 0; e < pPce->num_front_channel_elements +
+- pPce->num_side_channel_elements +
+- pPce->num_back_channel_elements +
+- pPce->num_lfe_channel_elements;
+- e++) {
+- if ((pPce->pEl_type[e] == ID_SCE) || (pPce->pEl_type[e] == ID_CPE)) {
+- cb->cbSbr(cb->cbSbrData, hBs, 0, 0, 0, config->aot, pPce->pEl_type[e],
+- sbrElementIndex, 0, 0, 0, NULL, 1);
+- sbrElementIndex++;
+- }
+- }
+- }
+ }
+
+ if ((config->flags & CC_SAC) && (cb->cbSsc != NULL)) {
+diff --git a/libSBRdec/include/sbrdecoder.h b/libSBRdec/include/sbrdecoder.h
+deleted file mode 100644
+index cc55572..0000000
+--- a/libSBRdec/include/sbrdecoder.h
++++ /dev/null
+@@ -1,401 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description: SBR decoder front-end prototypes and definitions.
+-
+-*******************************************************************************/
+-
+-#ifndef SBRDECODER_H
+-#define SBRDECODER_H
+-
+-#include "common_fix.h"
+-
+-#include "FDK_bitstream.h"
+-#include "FDK_audio.h"
+-
+-#include "FDK_qmf_domain.h"
+-
+-#define SBR_DEBUG_EXTHLP \
+- "\
+---- SBR ---\n\
+- 0x00000010 Ancillary data and SBR-Header\n\
+- 0x00000020 SBR-Side info\n\
+- 0x00000040 Decoded SBR-bitstream data, e.g. envelope data\n\
+- 0x00000080 SBR-Bitstream statistics\n\
+- 0x00000100 Miscellaneous SBR-messages\n\
+- 0x00000200 SBR-Energies and gains in the adjustor\n\
+- 0x00000400 Fatal SBR errors\n\
+- 0x00000800 Transposer coefficients for inverse filtering\n\
+-"
+-
+-/* Capability flags */
+-#define CAPF_SBR_LP \
+- 0x00000001 /*!< Flag indicating library's capability of Low Power mode. */
+-#define CAPF_SBR_HQ \
+- 0x00000002 /*!< Flag indicating library's capability of High Quality mode. \
+- */
+-#define CAPF_SBR_DRM_BS \
+- 0x00000004 /*!< Flag indicating library's capability to decode DRM SBR data. \
+- */
+-#define CAPF_SBR_CONCEALMENT \
+- 0x00000008 /*!< Flag indicating library's capability to conceal erroneous \
+- frames. */
+-#define CAPF_SBR_DRC \
+- 0x00000010 /*!< Flag indicating library's capability for Dynamic Range \
+- Control. */
+-#define CAPF_SBR_PS_MPEG \
+- 0x00000020 /*!< Flag indicating library's capability to do MPEG Parametric \
+- Stereo. */
+-#define CAPF_SBR_PS_DRM \
+- 0x00000040 /*!< Flag indicating library's capability to do DRM Parametric \
+- Stereo. */
+-#define CAPF_SBR_ELD_DOWNSCALE \
+- 0x00000080 /*!< Flag indicating library's capability to do ELD decoding in \
+- downscaled mode */
+-#define CAPF_SBR_HBEHQ \
+- 0x00000100 /*!< Flag indicating library's capability to do HQ Harmonic \
+- transposing */
+-
+-typedef enum {
+- SBRDEC_OK = 0, /*!< All fine. */
+- /* SBRDEC_CONCEAL, */
+- /* SBRDEC_NOSYNCH, */
+- /* SBRDEC_ILLEGAL_PROGRAM, */
+- /* SBRDEC_ILLEGAL_TAG, */
+- /* SBRDEC_ILLEGAL_CHN_CONFIG, */
+- /* SBRDEC_ILLEGAL_SECTION, */
+- /* SBRDEC_ILLEGAL_SCFACTORS, */
+- /* SBRDEC_ILLEGAL_PULSE_DATA, */
+- /* SBRDEC_MAIN_PROFILE_NOT_IMPLEMENTED, */
+- /* SBRDEC_GC_NOT_IMPLEMENTED, */
+- /* SBRDEC_ILLEGAL_PLUS_ELE_ID, */
+- SBRDEC_INVALID_ARGUMENT, /*!< */
+- SBRDEC_CREATE_ERROR, /*!< */
+- SBRDEC_NOT_INITIALIZED, /*!< */
+- SBRDEC_MEM_ALLOC_FAILED, /*!< Memory allocation failed. Probably not enough
+- memory available. */
+- SBRDEC_PARSE_ERROR, /*!< */
+- SBRDEC_UNSUPPORTED_CONFIG, /*!< */
+- SBRDEC_SET_PARAM_FAIL, /*!< */
+- SBRDEC_OUTPUT_BUFFER_TOO_SMALL /*!< */
+-} SBR_ERROR;
+-
+-typedef enum {
+- SBR_SYSTEM_BITSTREAM_DELAY, /*!< System: Switch to enable an additional SBR
+- bitstream delay of one frame. */
+- SBR_QMF_MODE, /*!< Set QMF mode, either complex or low power. */
+- SBR_LD_QMF_TIME_ALIGN, /*!< Set QMF type, either LD-MPS or CLDFB. Relevant for
+- ELD streams only. */
+- SBR_FLUSH_DATA, /*!< Set internal state to flush the decoder with the next
+- process call. */
+- SBR_CLEAR_HISTORY, /*!< Clear all internal states (delay lines, QMF states,
+- ...). */
+- SBR_BS_INTERRUPTION /*!< Signal bit stream interruption. Value is ignored. */
+- ,
+- SBR_SKIP_QMF /*!< Enable skipping of QMF step: 1 skip analysis, 2 skip
+- synthesis */
+-} SBRDEC_PARAM;
+-
+-typedef struct SBR_DECODER_INSTANCE *HANDLE_SBRDECODER;
+-
+-#ifdef __cplusplus
+-extern "C" {
+-#endif
+-
+-/**
+- * \brief Allocates and initializes one SBR decoder instance.
+- * \param pSelf Pointer to where a SBR decoder handle is copied into.
+- * \param pQmfDomain Pointer to QMF domain data structure.
+- *
+- * \return Error code.
+- */
+-SBR_ERROR sbrDecoder_Open(HANDLE_SBRDECODER *pSelf,
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain);
+-
+-/**
+- * \brief Initialize a SBR decoder runtime instance. Must be called before
+- * decoding starts.
+- *
+- * \param self Handle to a SBR decoder instance.
+- * \param sampleRateIn Input samplerate of the SBR decoder instance.
+- * \param sampleRateOut Output samplerate of the SBR decoder instance.
+- * \param samplesPerFrame Number of samples per frames.
+- * \param coreCodec Audio Object Type (AOT) of the core codec.
+- * \param elementID Table with MPEG-4 element Ids in canonical order.
+- * \param elementIndex SBR element index
+- * \param harmonicSBR
+- * \param stereoConfigIndex
+- * \param downscaleFactor ELD downscale factor
+- * \param configMode Table with MPEG-4 element Ids in canonical order.
+- * \param configChanged Flag that enforces a complete decoder reset.
+- *
+- * \return Error code.
+- */
+-SBR_ERROR sbrDecoder_InitElement(
+- HANDLE_SBRDECODER self, const int sampleRateIn, const int sampleRateOut,
+- const int samplesPerFrame, const AUDIO_OBJECT_TYPE coreCodec,
+- const MP4_ELEMENT_ID elementID, const int elementIndex,
+- const UCHAR harmonicSBR, const UCHAR stereoConfigIndex,
+- const UCHAR configMode, UCHAR *configChanged, const INT downscaleFactor);
+-
+-/**
+- * \brief Free config dependent SBR memory.
+- * \param self SBR decoder instance handle
+- */
+-SBR_ERROR sbrDecoder_FreeMem(HANDLE_SBRDECODER *self);
+-
+-/**
+- * \brief pass out of band SBR header to SBR decoder
+- *
+- * \param self Handle to a SBR decoder instance.
+- * \param hBs bit stream handle data source.
+- * \param sampleRateIn SBR input sampling rate
+- * \param sampleRateOut SBR output sampling rate
+- * \param samplesPerFrame frame length
+- * \param elementID SBR element ID.
+- * \param elementIndex SBR element index.
+- * \param harmonicSBR
+- * \param stereoConfigIndex
+- * \param downscaleFactor ELD downscale factor
+- *
+- * \return Error code.
+- */
+-INT sbrDecoder_Header(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
+- const INT sampleRateIn, const INT sampleRateOut,
+- const INT samplesPerFrame,
+- const AUDIO_OBJECT_TYPE coreCodec,
+- const MP4_ELEMENT_ID elementID, const INT elementIndex,
+- const UCHAR harmonicSBR, const UCHAR stereoConfigIndex,
+- const UCHAR configMode, UCHAR *configChanged,
+- const INT downscaleFactor);
+-
+-/**
+- * \brief Set a parameter of the SBR decoder runtime instance.
+- * \param self SBR decoder handle.
+- * \param param Parameter which will be set if successfull.
+- * \param value New parameter value.
+- * \return Error code.
+- */
+-SBR_ERROR sbrDecoder_SetParam(HANDLE_SBRDECODER self, const SBRDEC_PARAM param,
+- const INT value);
+-
+-/**
+- * \brief Feed DRC channel data into a SBR decoder runtime instance.
+- *
+- * \param self SBR decoder handle.
+- * \param ch Channel number to which the DRC data is
+- * associated to.
+- * \param numBands Number of DRC bands.
+- * \param pNextFact_mag Pointer to a table with the DRC factor
+- * magnitudes.
+- * \param nextFact_exp Exponent for all DRC factors.
+- * \param drcInterpolationScheme DRC interpolation scheme.
+- * \param winSequence Window sequence from core coder (eight short
+- * or one long window).
+- * \param pBandTop Pointer to a table with the top borders for
+- * all DRC bands.
+- *
+- * \return Error code.
+- */
+-SBR_ERROR sbrDecoder_drcFeedChannel(HANDLE_SBRDECODER self, INT ch,
+- UINT numBands, FIXP_DBL *pNextFact_mag,
+- INT nextFact_exp,
+- SHORT drcInterpolationScheme,
+- UCHAR winSequence, USHORT *pBandTop);
+-
+-/**
+- * \brief Disable SBR DRC for a certain channel.
+- *
+- * \param hSbrDecoder SBR decoder handle.
+- * \param ch Number of the channel that has to be disabled.
+- *
+- * \return None.
+- */
+-void sbrDecoder_drcDisable(HANDLE_SBRDECODER self, INT ch);
+-
+-/**
+- * \brief Parse one SBR element data extension data block. The bit stream
+- * position will be placed at the end of the SBR payload block. The remaining
+- * bits will be returned into *count if a payload length is given
+- * (byPayLen > 0). If no SBR payload length is given (bsPayLen < 0) then
+- * the bit stream position on return will be random after this function
+- * call in case of errors, and any further decoding will be completely
+- * pointless. This function accepts either normal ordered SBR data or reverse
+- * ordered DRM SBR data.
+- *
+- * \param self SBR decoder handle.
+- * \param hBs Bit stream handle as data source.
+- * \param count Pointer to an integer where the amount of parsed SBR
+- * payload bits is stored into.
+- * \param bsPayLen If > 0 this value is the SBR payload length. If < 0,
+- * the SBR payload length is unknown.
+- * \param flags CRC flag (0: EXT_SBR_DATA; 1: EXT_SBR_DATA_CRC)
+- * \param prev_element Previous MPEG-4 element ID.
+- * \param element_index Index of the current element.
+- * \param acFlags Audio codec flags
+- *
+- * \return Error code.
+- */
+-SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
+- UCHAR *pDrmBsBuffer, USHORT drmBsBufferSize,
+- int *count, int bsPayLen, int crcFlag,
+- MP4_ELEMENT_ID prev_element, int element_index,
+- UINT acFlags, UINT acElFlags[]);
+-
+-/**
+- * \brief This function decodes the given SBR bitstreams and applies SBR to the
+- * given time data.
+- *
+- * SBR-processing works InPlace. I.e. the calling function has to provide
+- * a time domain buffer timeData which can hold the completely decoded
+- * result.
+- *
+- * Left and right channel are read and stored according to the
+- * interleaving flag, frame length and number of channels.
+- *
+- * \param self Handle of an open SBR decoder instance.
+- * \param hSbrBs SBR Bitstream handle.
+- * \param input Pointer to input data.
+- * \param timeData Pointer to upsampled output data.
+- * \param timeDataSize Size of timeData.
+- * \param numChannels Pointer to a buffer holding the number of channels in
+- * time data buffer.
+- * \param sampleRate Output samplerate.
+- * \param channelMapping Channel mapping indices.
+- * \param coreDecodedOk Flag indicating if the core decoder did not find any
+- * error (0: core decoder found errors, 1: no errors).
+- * \param psDecoded Pointer to a buffer holding a flag. Input: PS is
+- * possible, Output: PS has been rendered.
+- *
+- * \return Error code.
+- */
+-SBR_ERROR sbrDecoder_Apply(HANDLE_SBRDECODER self, INT_PCM *input,
+- INT_PCM *timeData, const int timeDataSize,
+- int *numChannels, int *sampleRate,
+- const FDK_channelMapDescr *const mapDescr,
+- const int mapIdx, const int coreDecodedOk,
+- UCHAR *psDecoded);
+-
+-/**
+- * \brief Close SBR decoder instance and free memory.
+- * \param self SBR decoder handle.
+- * \return Error Code.
+- */
+-SBR_ERROR sbrDecoder_Close(HANDLE_SBRDECODER *self);
+-
+-/**
+- * \brief Get SBR decoder library information.
+- * \param info Pointer to a LIB_INFO struct, where library information is
+- * written to.
+- * \return 0 on success, -1 if invalid handle or if no free element is
+- * available to write information to.
+- */
+-INT sbrDecoder_GetLibInfo(LIB_INFO *info);
+-
+-/**
+- * \brief Determine the modules output signal delay in samples.
+- * \param self SBR decoder handle.
+- * \return The number of samples signal delay added by the module.
+- */
+-UINT sbrDecoder_GetDelay(const HANDLE_SBRDECODER self);
+-
+-#ifdef __cplusplus
+-}
+-#endif
+-
+-#endif
+diff --git a/libSBRdec/src/HFgen_preFlat.cpp b/libSBRdec/src/HFgen_preFlat.cpp
+deleted file mode 100644
+index 96adbb9..0000000
+--- a/libSBRdec/src/HFgen_preFlat.cpp
++++ /dev/null
+@@ -1,993 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s): Oliver Moser, Manuel Jander, Matthias Hildenbrand
+-
+- Description: QMF frequency pre-whitening for SBR.
+- In the documentation the terms "scale factor" and "exponent"
+- mean the same. Variables containing such information have
+- the suffix "_sf".
+-
+-*******************************************************************************/
+-
+-#include "HFgen_preFlat.h"
+-
+-#define POLY_ORDER 3
+-#define MAXLOWBANDS 32
+-#define LOG10FAC 0.752574989159953f /* == 10/log2(10) * 2^-2 */
+-#define LOG10FAC_INV 0.664385618977472f /* == log2(10)/20 * 2^2 */
+-
+-#define FIXP_CHB FIXP_SGL /* STB sinus Tab used in transformation */
+-#define CHC(a) (FX_DBL2FXCONST_SGL(a))
+-#define FX_CHB2FX_DBL(a) FX_SGL2FX_DBL(a)
+-
+-typedef struct backsubst_data {
+- FIXP_CHB Lnorm1d[3]; /*!< Normalized L matrix */
+- SCHAR Lnorm1d_sf[3];
+- FIXP_CHB Lnormii
+- [3]; /*!< The diagonal data points [i][i] of the normalized L matrix */
+- SCHAR Lnormii_sf[3];
+- FIXP_CHB Bmul0
+- [4]; /*!< To normalize L*x=b, Bmul0 is what we need to multiply b with. */
+- SCHAR Bmul0_sf[4];
+- FIXP_CHB LnormInv1d[6]; /*!< Normalized inverted L matrix (L') */
+- SCHAR LnormInv1d_sf[6];
+- FIXP_CHB
+- Bmul1[4]; /*!< To normalize L'*x=b, Bmul1 is what we need to multiply b
+- with. */
+- SCHAR Bmul1_sf[4];
+-} backsubst_data;
+-
+-/* for each element n do, f(n) = trunc(log2(n))+1 */
+-const UCHAR getLog2[32] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
+- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
+-
+-/** \def BSD_IDX_OFFSET
+- *
+- * bsd[] begins at index 0 with data for numBands=5. The correct bsd[] is
+- * indexed like bsd[numBands-BSD_IDX_OFFSET].
+- */
+-#define BSD_IDX_OFFSET 5
+-
+-#define N_NUMBANDS \
+- MAXLOWBANDS - BSD_IDX_OFFSET + \
+- 1 /*!< Number of backsubst_data elements in bsd */
+-
+-const backsubst_data bsd[N_NUMBANDS] = {
+- {
+- /* numBands=5 */
+- {CHC(0x66c85a52), CHC(0x4278e587), CHC(0x697dcaff)},
+- {-1, 0, 0},
+- {CHC(0x66a61789), CHC(0x5253b8e3), CHC(0x5addad81)},
+- {3, 4, 1},
+- {CHC(0x7525ee90), CHC(0x6e2a1210), CHC(0x6523bb40), CHC(0x59822ead)},
+- {-6, -4, -2, 0},
+- {CHC(0x609e4cad), CHC(0x59c7e312), CHC(0x681eecac), CHC(0x440ea893),
+- CHC(0x4a214bb3), CHC(0x53c345a1)},
+- {1, 0, -1, -1, -3, -5},
+- {CHC(0x7525ee90), CHC(0x58587936), CHC(0x410d0b38), CHC(0x7f1519d6)},
+- {-6, -1, 2, 0},
+- },
+- {
+- /* numBands=6 */
+- {CHC(0x68943285), CHC(0x4841d2c3), CHC(0x6a6214c7)},
+- {-1, 0, 0},
+- {CHC(0x63c5923e), CHC(0x4e906e18), CHC(0x6285af8a)},
+- {3, 4, 1},
+- {CHC(0x7263940b), CHC(0x424a69a5), CHC(0x4ae8383a), CHC(0x517b7730)},
+- {-7, -4, -2, 0},
+- {CHC(0x518aee5f), CHC(0x4823a096), CHC(0x43764a39), CHC(0x6e6faf23),
+- CHC(0x61bba44f), CHC(0x59d8b132)},
+- {1, 0, -1, -2, -4, -6},
+- {CHC(0x7263940b), CHC(0x6757bff2), CHC(0x5bf40fe0), CHC(0x7d6f4292)},
+- {-7, -2, 1, 0},
+- },
+- {
+- /* numBands=7 */
+- {CHC(0x699b4c3c), CHC(0x4b8b702f), CHC(0x6ae51a4f)},
+- {-1, 0, 0},
+- {CHC(0x623a7f49), CHC(0x4ccc91fc), CHC(0x68f048dd)},
+- {3, 4, 1},
+- {CHC(0x7e6ebe18), CHC(0x5701daf2), CHC(0x74a8198b), CHC(0x4b399aa1)},
+- {-8, -5, -3, 0},
+- {CHC(0x464a64a6), CHC(0x78e42633), CHC(0x5ee174ba), CHC(0x5d0008c8),
+- CHC(0x455cff0f), CHC(0x6b9100e7)},
+- {1, -1, -2, -2, -4, -7},
+- {CHC(0x7e6ebe18), CHC(0x42c52efe), CHC(0x45fe401f), CHC(0x7b5808ef)},
+- {-8, -2, 1, 0},
+- },
+- {
+- /* numBands=8 */
+- {CHC(0x6a3fd9b4), CHC(0x4d99823f), CHC(0x6b372a94)},
+- {-1, 0, 0},
+- {CHC(0x614c6ef7), CHC(0x4bd06699), CHC(0x6e59cfca)},
+- {3, 4, 1},
+- {CHC(0x4c389cc5), CHC(0x79686681), CHC(0x5e2544c2), CHC(0x46305b43)},
+- {-8, -6, -3, 0},
+- {CHC(0x7b4ca7c6), CHC(0x68270ac5), CHC(0x467c644c), CHC(0x505c1b0f),
+- CHC(0x67a14778), CHC(0x45801767)},
+- {0, -1, -2, -2, -5, -7},
+- {CHC(0x4c389cc5), CHC(0x5c499ceb), CHC(0x6f863c9f), CHC(0x79059bfc)},
+- {-8, -3, 0, 0},
+- },
+- {
+- /* numBands=9 */
+- {CHC(0x6aad9988), CHC(0x4ef8ac18), CHC(0x6b6df116)},
+- {-1, 0, 0},
+- {CHC(0x60b159b0), CHC(0x4b33f772), CHC(0x72f5573d)},
+- {3, 4, 1},
+- {CHC(0x6206cb18), CHC(0x58a7d8dc), CHC(0x4e0b2d0b), CHC(0x4207ad84)},
+- {-9, -6, -3, 0},
+- {CHC(0x6dadadae), CHC(0x5b8b2cfc), CHC(0x6cf61db2), CHC(0x46c3c90b),
+- CHC(0x506314ea), CHC(0x5f034acd)},
+- {0, -1, -3, -2, -5, -8},
+- {CHC(0x6206cb18), CHC(0x42f8b8de), CHC(0x5bb4776f), CHC(0x769acc79)},
+- {-9, -3, 0, 0},
+- },
+- {
+- /* numBands=10 */
+- {CHC(0x6afa7252), CHC(0x4feed3ed), CHC(0x6b94504d)},
+- {-1, 0, 0},
+- {CHC(0x60467899), CHC(0x4acbafba), CHC(0x76eb327f)},
+- {3, 4, 1},
+- {CHC(0x42415b15), CHC(0x431080da), CHC(0x420f1c32), CHC(0x7d0c1aeb)},
+- {-9, -6, -3, -1},
+- {CHC(0x62b2c7a4), CHC(0x51b040a6), CHC(0x56caddb4), CHC(0x7e74a2c8),
+- CHC(0x4030adf5), CHC(0x43d1dc4f)},
+- {0, -1, -3, -3, -5, -8},
+- {CHC(0x42415b15), CHC(0x64e299b3), CHC(0x4d33b5e8), CHC(0x742cee5f)},
+- {-9, -4, 0, 0},
+- },
+- {
+- /* numBands=11 */
+- {CHC(0x6b3258bb), CHC(0x50a21233), CHC(0x6bb03c19)},
+- {-1, 0, 0},
+- {CHC(0x5ff997c6), CHC(0x4a82706e), CHC(0x7a5aae36)},
+- {3, 4, 1},
+- {CHC(0x5d2fb4fb), CHC(0x685bddd8), CHC(0x71b5e983), CHC(0x7708c90b)},
+- {-10, -7, -4, -1},
+- {CHC(0x59aceea2), CHC(0x49c428a0), CHC(0x46ca5527), CHC(0x724be884),
+- CHC(0x68e586da), CHC(0x643485b6)},
+- {0, -1, -3, -3, -6, -9},
+- {CHC(0x5d2fb4fb), CHC(0x4e3fad1a), CHC(0x42310ba2), CHC(0x71c8b3ce)},
+- {-10, -4, 0, 0},
+- },
+- {
+- /* numBands=12 */
+- {CHC(0x6b5c4726), CHC(0x5128a4a8), CHC(0x6bc52ee1)},
+- {-1, 0, 0},
+- {CHC(0x5fc06618), CHC(0x4a4ce559), CHC(0x7d5c16e9)},
+- {3, 4, 1},
+- {CHC(0x43af8342), CHC(0x531533d3), CHC(0x633660a6), CHC(0x71ce6052)},
+- {-10, -7, -4, -1},
+- {CHC(0x522373d7), CHC(0x434150cb), CHC(0x75b58afc), CHC(0x68474f2d),
+- CHC(0x575348a5), CHC(0x4c20973f)},
+- {0, -1, -4, -3, -6, -9},
+- {CHC(0x43af8342), CHC(0x7c4d3d11), CHC(0x732e13db), CHC(0x6f756ac4)},
+- {-10, -5, -1, 0},
+- },
+- {
+- /* numBands=13 */
+- {CHC(0x6b7c8953), CHC(0x51903fcd), CHC(0x6bd54d2e)},
+- {-1, 0, 0},
+- {CHC(0x5f94abf0), CHC(0x4a2480fa), CHC(0x40013553)},
+- {3, 4, 2},
+- {CHC(0x6501236e), CHC(0x436b9c4e), CHC(0x578d7881), CHC(0x6d34f92e)},
+- {-11, -7, -4, -1},
+- {CHC(0x4bc0e2b2), CHC(0x7b9d12ac), CHC(0x636c1c1b), CHC(0x5fe15c2b),
+- CHC(0x49d54879), CHC(0x7662cfa5)},
+- {0, -2, -4, -3, -6, -10},
+- {CHC(0x6501236e), CHC(0x64b059fe), CHC(0x656d8359), CHC(0x6d370900)},
+- {-11, -5, -1, 0},
+- },
+- {
+- /* numBands=14 */
+- {CHC(0x6b95e276), CHC(0x51e1b637), CHC(0x6be1f7ed)},
+- {-1, 0, 0},
+- {CHC(0x5f727a1c), CHC(0x4a053e9c), CHC(0x412e528c)},
+- {3, 4, 2},
+- {CHC(0x4d178bd4), CHC(0x6f33b4e8), CHC(0x4e028f7f), CHC(0x691ee104)},
+- {-11, -8, -4, -1},
+- {CHC(0x46473d3f), CHC(0x725bd0a6), CHC(0x55199885), CHC(0x58bcc56b),
+- CHC(0x7e7e6288), CHC(0x5ddef6eb)},
+- {0, -2, -4, -3, -7, -10},
+- {CHC(0x4d178bd4), CHC(0x52ebd467), CHC(0x5a395a6e), CHC(0x6b0f724f)},
+- {-11, -5, -1, 0},
+- },
+- {
+- /* numBands=15 */
+- {CHC(0x6baa2a22), CHC(0x5222eb91), CHC(0x6bec1a86)},
+- {-1, 0, 0},
+- {CHC(0x5f57393b), CHC(0x49ec8934), CHC(0x423b5b58)},
+- {3, 4, 2},
+- {CHC(0x77fd2486), CHC(0x5cfbdf2c), CHC(0x46153bd1), CHC(0x65757ed9)},
+- {-12, -8, -4, -1},
+- {CHC(0x41888ee6), CHC(0x6a661db3), CHC(0x49abc8c8), CHC(0x52965848),
+- CHC(0x6d9301b7), CHC(0x4bb04721)},
+- {0, -2, -4, -3, -7, -10},
+- {CHC(0x77fd2486), CHC(0x45424c68), CHC(0x50f33cc6), CHC(0x68ff43f0)},
+- {-12, -5, -1, 0},
+- },
+- {
+- /* numBands=16 */
+- {CHC(0x6bbaa499), CHC(0x5257ed94), CHC(0x6bf456e4)},
+- {-1, 0, 0},
+- {CHC(0x5f412594), CHC(0x49d8a766), CHC(0x432d1dbd)},
+- {3, 4, 2},
+- {CHC(0x5ef5cfde), CHC(0x4eafcd2d), CHC(0x7ed36893), CHC(0x62274b45)},
+- {-12, -8, -5, -1},
+- {CHC(0x7ac438f5), CHC(0x637aab21), CHC(0x4067617a), CHC(0x4d3c6ec7),
+- CHC(0x5fd6e0dd), CHC(0x7bd5f024)},
+- {-1, -2, -4, -3, -7, -11},
+- {CHC(0x5ef5cfde), CHC(0x751d0d4f), CHC(0x492b3c41), CHC(0x67065409)},
+- {-12, -6, -1, 0},
+- },
+- {
+- /* numBands=17 */
+- {CHC(0x6bc836c9), CHC(0x5283997e), CHC(0x6bfb1f5e)},
+- {-1, 0, 0},
+- {CHC(0x5f2f02b6), CHC(0x49c868e9), CHC(0x44078151)},
+- {3, 4, 2},
+- {CHC(0x4c43b65a), CHC(0x4349dcf6), CHC(0x73799e2d), CHC(0x5f267274)},
+- {-12, -8, -5, -1},
+- {CHC(0x73726394), CHC(0x5d68511a), CHC(0x7191bbcc), CHC(0x48898c70),
+- CHC(0x548956e1), CHC(0x66981ce8)},
+- {-1, -2, -5, -3, -7, -11},
+- {CHC(0x4c43b65a), CHC(0x64131116), CHC(0x429028e2), CHC(0x65240211)},
+- {-12, -6, -1, 0},
+- },
+- {
+- /* numBands=18 */
+- {CHC(0x6bd3860d), CHC(0x52a80156), CHC(0x6c00c68d)},
+- {-1, 0, 0},
+- {CHC(0x5f1fed86), CHC(0x49baf636), CHC(0x44cdb9dc)},
+- {3, 4, 2},
+- {CHC(0x7c189389), CHC(0x742666d8), CHC(0x69b8c776), CHC(0x5c67e27d)},
+- {-13, -9, -5, -1},
+- {CHC(0x6cf1ea76), CHC(0x58095703), CHC(0x64e351a9), CHC(0x4460da90),
+- CHC(0x4b1f8083), CHC(0x55f2d3e1)},
+- {-1, -2, -5, -3, -7, -11},
+- {CHC(0x7c189389), CHC(0x5651792a), CHC(0x79cb9b3d), CHC(0x635769c0)},
+- {-13, -6, -2, 0},
+- },
+- {
+- /* numBands=19 */
+- {CHC(0x6bdd0c40), CHC(0x52c6abf6), CHC(0x6c058950)},
+- {-1, 0, 0},
+- {CHC(0x5f133f88), CHC(0x49afb305), CHC(0x45826d73)},
+- {3, 4, 2},
+- {CHC(0x6621a164), CHC(0x6512528e), CHC(0x61449fc8), CHC(0x59e2a0c0)},
+- {-13, -9, -5, -1},
+- {CHC(0x6721cadb), CHC(0x53404cd4), CHC(0x5a389e91), CHC(0x40abcbd2),
+- CHC(0x43332f01), CHC(0x48b82e46)},
+- {-1, -2, -5, -3, -7, -11},
+- {CHC(0x6621a164), CHC(0x4b12cc28), CHC(0x6ffd4df8), CHC(0x619f835e)},
+- {-13, -6, -2, 0},
+- },
+- {
+- /* numBands=20 */
+- {CHC(0x6be524c5), CHC(0x52e0beb3), CHC(0x6c099552)},
+- {-1, 0, 0},
+- {CHC(0x5f087c68), CHC(0x49a62bb5), CHC(0x4627d175)},
+- {3, 4, 2},
+- {CHC(0x54ec6afe), CHC(0x58991a42), CHC(0x59e23e8c), CHC(0x578f4ef4)},
+- {-13, -9, -5, -1},
+- {CHC(0x61e78f6f), CHC(0x4ef5e1e9), CHC(0x5129c3b8), CHC(0x7ab0f7b2),
+- CHC(0x78efb076), CHC(0x7c2567ea)},
+- {-1, -2, -5, -4, -8, -12},
+- {CHC(0x54ec6afe), CHC(0x41c7812c), CHC(0x676f6f8d), CHC(0x5ffb383f)},
+- {-13, -6, -2, 0},
+- },
+- {
+- /* numBands=21 */
+- {CHC(0x6bec1542), CHC(0x52f71929), CHC(0x6c0d0d5e)},
+- {-1, 0, 0},
+- {CHC(0x5eff45c5), CHC(0x499e092d), CHC(0x46bfc0c9)},
+- {3, 4, 2},
+- {CHC(0x47457a78), CHC(0x4e2d99b3), CHC(0x53637ea5), CHC(0x5567d0e9)},
+- {-13, -9, -5, -1},
+- {CHC(0x5d2dc61b), CHC(0x4b1760c8), CHC(0x4967cf39), CHC(0x74b113d8),
+- CHC(0x6d6676b6), CHC(0x6ad114e9)},
+- {-1, -2, -5, -4, -8, -12},
+- {CHC(0x47457a78), CHC(0x740accaa), CHC(0x5feb6609), CHC(0x5e696f95)},
+- {-13, -7, -2, 0},
+- },
+- {
+- /* numBands=22 */
+- {CHC(0x6bf21387), CHC(0x530a683c), CHC(0x6c100c59)},
+- {-1, 0, 0},
+- {CHC(0x5ef752ea), CHC(0x499708c6), CHC(0x474bcd1b)},
+- {3, 4, 2},
+- {CHC(0x78a21ab7), CHC(0x45658aec), CHC(0x4da3c4fe), CHC(0x5367094b)},
+- {-14, -9, -5, -1},
+- {CHC(0x58e2df6a), CHC(0x4795990e), CHC(0x42b5e0f7), CHC(0x6f408c64),
+- CHC(0x6370bebf), CHC(0x5c91ca85)},
+- {-1, -2, -5, -4, -8, -12},
+- {CHC(0x78a21ab7), CHC(0x66f951d6), CHC(0x594605bb), CHC(0x5ce91657)},
+- {-14, -7, -2, 0},
+- },
+- {
+- /* numBands=23 */
+- {CHC(0x6bf749b2), CHC(0x531b3348), CHC(0x6c12a750)},
+- {-1, 0, 0},
+- {CHC(0x5ef06b17), CHC(0x4990f6c9), CHC(0x47cd4c5b)},
+- {3, 4, 2},
+- {CHC(0x66dede36), CHC(0x7bdf90a9), CHC(0x4885b2b9), CHC(0x5188a6b7)},
+- {-14, -10, -5, -1},
+- {CHC(0x54f85812), CHC(0x446414ae), CHC(0x79c8d519), CHC(0x6a4c2f31),
+- CHC(0x5ac8325f), CHC(0x50bf9200)},
+- {-1, -2, -6, -4, -8, -12},
+- {CHC(0x66dede36), CHC(0x5be0d90e), CHC(0x535cc453), CHC(0x5b7923f0)},
+- {-14, -7, -2, 0},
+- },
+- {
+- /* numBands=24 */
+- {CHC(0x6bfbd91d), CHC(0x5329e580), CHC(0x6c14eeed)},
+- {-1, 0, 0},
+- {CHC(0x5eea6179), CHC(0x498baa90), CHC(0x4845635d)},
+- {3, 4, 2},
+- {CHC(0x58559b7e), CHC(0x6f1b231f), CHC(0x43f1789b), CHC(0x4fc8fcb8)},
+- {-14, -10, -5, -1},
+- {CHC(0x51621775), CHC(0x417881a3), CHC(0x6f9ba9b6), CHC(0x65c412b2),
+- CHC(0x53352c61), CHC(0x46db9caf)},
+- {-1, -2, -6, -4, -8, -12},
+- {CHC(0x58559b7e), CHC(0x52636003), CHC(0x4e13b316), CHC(0x5a189cdf)},
+- {-14, -7, -2, 0},
+- },
+- {
+- /* numBands=25 */
+- {CHC(0x6bffdc73), CHC(0x5336d4af), CHC(0x6c16f084)},
+- {-1, 0, 0},
+- {CHC(0x5ee51249), CHC(0x498703cc), CHC(0x48b50e4f)},
+- {3, 4, 2},
+- {CHC(0x4c5616cf), CHC(0x641b9fad), CHC(0x7fa735e0), CHC(0x4e24e57a)},
+- {-14, -10, -6, -1},
+- {CHC(0x4e15f47a), CHC(0x7d9481d6), CHC(0x66a82f8a), CHC(0x619ae971),
+- CHC(0x4c8b2f5f), CHC(0x7d09ec11)},
+- {-1, -3, -6, -4, -8, -13},
+- {CHC(0x4c5616cf), CHC(0x4a3770fb), CHC(0x495402de), CHC(0x58c693fa)},
+- {-14, -7, -2, 0},
+- },
+- {
+- /* numBands=26 */
+- {CHC(0x6c036943), CHC(0x53424625), CHC(0x6c18b6dc)},
+- {-1, 0, 0},
+- {CHC(0x5ee060aa), CHC(0x4982e88a), CHC(0x491d277f)},
+- {3, 4, 2},
+- {CHC(0x425ada5b), CHC(0x5a9368ac), CHC(0x78380a42), CHC(0x4c99aa05)},
+- {-14, -10, -6, -1},
+- {CHC(0x4b0b569c), CHC(0x78a420da), CHC(0x5ebdf203), CHC(0x5dc57e63),
+- CHC(0x46a650ff), CHC(0x6ee13fb8)},
+- {-1, -3, -6, -4, -8, -13},
+- {CHC(0x425ada5b), CHC(0x4323073c), CHC(0x450ae92b), CHC(0x57822ad5)},
+- {-14, -7, -2, 0},
+- },
+- {
+- /* numBands=27 */
+- {CHC(0x6c06911a), CHC(0x534c7261), CHC(0x6c1a4aba)},
+- {-1, 0, 0},
+- {CHC(0x5edc3524), CHC(0x497f43c0), CHC(0x497e6cd8)},
+- {3, 4, 2},
+- {CHC(0x73fb550e), CHC(0x5244894f), CHC(0x717aad78), CHC(0x4b24ef6c)},
+- {-15, -10, -6, -1},
+- {CHC(0x483aebe4), CHC(0x74139116), CHC(0x57b58037), CHC(0x5a3a4f3c),
+- CHC(0x416950fe), CHC(0x62c7f4f2)},
+- {-1, -3, -6, -4, -8, -13},
+- {CHC(0x73fb550e), CHC(0x79efb994), CHC(0x4128cab7), CHC(0x564a919a)},
+- {-15, -8, -2, 0},
+- },
+- {
+- /* numBands=28 */
+- {CHC(0x6c096264), CHC(0x535587cd), CHC(0x6c1bb355)},
+- {-1, 0, 0},
+- {CHC(0x5ed87c76), CHC(0x497c0439), CHC(0x49d98452)},
+- {3, 4, 2},
+- {CHC(0x65dec5bf), CHC(0x4afd1ba3), CHC(0x6b58b4b3), CHC(0x49c4a7b0)},
+- {-15, -10, -6, -1},
+- {CHC(0x459e6eb1), CHC(0x6fd850b7), CHC(0x516e7be9), CHC(0x56f13d05),
+- CHC(0x79785594), CHC(0x58617de7)},
+- {-1, -3, -6, -4, -9, -13},
+- {CHC(0x65dec5bf), CHC(0x6f2168aa), CHC(0x7b41310f), CHC(0x551f0692)},
+- {-15, -8, -3, 0},
+- },
+- {
+- /* numBands=29 */
+- {CHC(0x6c0be913), CHC(0x535dacd5), CHC(0x6c1cf6a3)},
+- {-1, 0, 0},
+- {CHC(0x5ed526b4), CHC(0x49791bc5), CHC(0x4a2eff99)},
+- {3, 4, 2},
+- {CHC(0x59e44afe), CHC(0x44949ada), CHC(0x65bf36f5), CHC(0x487705a0)},
+- {-15, -10, -6, -1},
+- {CHC(0x43307779), CHC(0x6be959c4), CHC(0x4bce2122), CHC(0x53e34d89),
+- CHC(0x7115ff82), CHC(0x4f6421a1)},
+- {-1, -3, -6, -4, -9, -13},
+- {CHC(0x59e44afe), CHC(0x659eab7d), CHC(0x74cea459), CHC(0x53fed574)},
+- {-15, -8, -3, 0},
+- },
+- {
+- /* numBands=30 */
+- {CHC(0x6c0e2f17), CHC(0x53650181), CHC(0x6c1e199d)},
+- {-1, 0, 0},
+- {CHC(0x5ed2269f), CHC(0x49767e9e), CHC(0x4a7f5f0b)},
+- {3, 4, 2},
+- {CHC(0x4faa4ae6), CHC(0x7dd3bf11), CHC(0x609e2732), CHC(0x473a72e9)},
+- {-15, -11, -6, -1},
+- {CHC(0x40ec57c6), CHC(0x683ee147), CHC(0x46be261d), CHC(0x510a7983),
+- CHC(0x698a84cb), CHC(0x4794a927)},
+- {-1, -3, -6, -4, -9, -13},
+- {CHC(0x4faa4ae6), CHC(0x5d3615ad), CHC(0x6ee74773), CHC(0x52e956a1)},
+- {-15, -8, -3, 0},
+- },
+- {
+- /* numBands=31 */
+- {CHC(0x6c103cc9), CHC(0x536ba0ac), CHC(0x6c1f2070)},
+- {-1, 0, 0},
+- {CHC(0x5ecf711e), CHC(0x497422ea), CHC(0x4acb1438)},
+- {3, 4, 2},
+- {CHC(0x46e322ad), CHC(0x73c32f3c), CHC(0x5be7d172), CHC(0x460d8800)},
+- {-15, -11, -6, -1},
+- {CHC(0x7d9bf8ad), CHC(0x64d22351), CHC(0x422bdc81), CHC(0x4e6184aa),
+- CHC(0x62ba2375), CHC(0x40c325de)},
+- {-2, -3, -6, -4, -9, -13},
+- {CHC(0x46e322ad), CHC(0x55bef2a3), CHC(0x697b3135), CHC(0x51ddee4d)},
+- {-15, -8, -3, 0},
+- },
+- {
+- // numBands=32
+- {CHC(0x6c121933), CHC(0x5371a104), CHC(0x6c200ea0)},
+- {-1, 0, 0},
+- {CHC(0x5eccfcd3), CHC(0x49720060), CHC(0x4b1283f0)},
+- {3, 4, 2},
+- {CHC(0x7ea12a52), CHC(0x6aca3303), CHC(0x579072bf), CHC(0x44ef056e)},
+- {-16, -11, -6, -1},
+- {CHC(0x79a3a9ab), CHC(0x619d38fc), CHC(0x7c0f0734), CHC(0x4be3dd5d),
+- CHC(0x5c8d7163), CHC(0x7591065f)},
+- {-2, -3, -7, -4, -9, -14},
+- {CHC(0x7ea12a52), CHC(0x4f1782a6), CHC(0x647cbcb2), CHC(0x50dc0bb1)},
+- {-16, -8, -3, 0},
+- },
+-};
+-
+-/** \def SUM_SAFETY
+- *
+- * SUM_SAFTEY defines the bits needed to right-shift every summand in
+- * order to be overflow-safe. In the two backsubst functions we sum up 4
+- * values. Since one of which is definitely not MAXVAL_DBL (the L[x][y]),
+- * we spare just 2 safety bits instead of 3.
+- */
+-#define SUM_SAFETY 2
+-
+-/**
+- * \brief Solves L*x=b via backsubstitution according to the following
+- * structure:
+- *
+- * x[0] = b[0];
+- * x[1] = (b[1] - x[0]) / L[1][1];
+- * x[2] = (b[2] - x[1]*L[2][1] - x[0]) / L[2][2];
+- * x[3] = (b[3] - x[2]*L[3][2] - x[1]*L[3][1] - x[0]) / L[3][3];
+- *
+- * \param[in] numBands SBR crossover band index
+- * \param[in] b the b in L*x=b (one-dimensional)
+- * \param[out] x output polynomial coefficients (mantissa)
+- * \param[out] x_sf exponents of x[]
+- */
+-static void backsubst_fw(const int numBands, const FIXP_DBL *const b,
+- FIXP_DBL *RESTRICT x, int *RESTRICT x_sf) {
+- int i, k;
+- int m; /* the trip counter that indexes incrementally through Lnorm1d[] */
+-
+- const FIXP_CHB *RESTRICT pLnorm1d = bsd[numBands - BSD_IDX_OFFSET].Lnorm1d;
+- const SCHAR *RESTRICT pLnorm1d_sf = bsd[numBands - BSD_IDX_OFFSET].Lnorm1d_sf;
+- const FIXP_CHB *RESTRICT pLnormii = bsd[numBands - BSD_IDX_OFFSET].Lnormii;
+- const SCHAR *RESTRICT pLnormii_sf = bsd[numBands - BSD_IDX_OFFSET].Lnormii_sf;
+-
+- x[0] = b[0];
+-
+- for (i = 1, m = 0; i <= POLY_ORDER; ++i) {
+- FIXP_DBL sum = b[i] >> SUM_SAFETY;
+- int sum_sf = x_sf[i];
+- for (k = i - 1; k > 0; --k, ++m) {
+- int e;
+- FIXP_DBL mult = fMultNorm(FX_CHB2FX_DBL(pLnorm1d[m]), x[k], &e);
+- int mult_sf = pLnorm1d_sf[m] + x_sf[k] + e;
+-
+- /* check if the new summand mult has a different sf than the sum currently
+- * has */
+- int diff = mult_sf - sum_sf;
+-
+- if (diff > 0) {
+- /* yes, and it requires the sum to be adjusted (scaled down) */
+- sum >>= diff;
+- sum_sf = mult_sf;
+- } else if (diff < 0) {
+- /* yes, but here mult needs to be scaled down */
+- mult >>= -diff;
+- }
+- sum -= (mult >> SUM_SAFETY);
+- }
+-
+- /* - x[0] */
+- if (x_sf[0] > sum_sf) {
+- sum >>= (x_sf[0] - sum_sf);
+- sum_sf = x_sf[0];
+- }
+- sum -= (x[0] >> (sum_sf - x_sf[0] + SUM_SAFETY));
+-
+- /* instead of the division /L[i][i], we multiply by the inverse */
+- int e;
+- x[i] = fMultNorm(sum, FX_CHB2FX_DBL(pLnormii[i - 1]), &e);
+- x_sf[i] = sum_sf + pLnormii_sf[i - 1] + e + SUM_SAFETY;
+- }
+-}
+-
+-/**
+- * \brief Solves L*x=b via backsubstitution according to the following
+- * structure:
+- *
+- * x[3] = b[3];
+- * x[2] = b[2] - L[2][3]*x[3];
+- * x[1] = b[1] - L[1][2]*x[2] - L[1][3]*x[3];
+- * x[0] = b[0] - L[0][1]*x[1] - L[0][2]*x[2] - L[0][3]*x[3];
+- *
+- * \param[in] numBands SBR crossover band index
+- * \param[in] b the b in L*x=b (one-dimensional)
+- * \param[out] x solution vector
+- * \param[out] x_sf exponents of x[]
+- */
+-static void backsubst_bw(const int numBands, const FIXP_DBL *const b,
+- FIXP_DBL *RESTRICT x, int *RESTRICT x_sf) {
+- int i, k;
+- int m; /* the trip counter that indexes incrementally through LnormInv1d[] */
+-
+- const FIXP_CHB *RESTRICT pLnormInv1d =
+- bsd[numBands - BSD_IDX_OFFSET].LnormInv1d;
+- const SCHAR *RESTRICT pLnormInv1d_sf =
+- bsd[numBands - BSD_IDX_OFFSET].LnormInv1d_sf;
+-
+- x[POLY_ORDER] = b[POLY_ORDER];
+-
+- for (i = POLY_ORDER - 1, m = 0; i >= 0; i--) {
+- FIXP_DBL sum = b[i] >> SUM_SAFETY;
+- int sum_sf = x_sf[i]; /* sum's sf but disregarding SUM_SAFETY (added at the
+- iteration's end) */
+-
+- for (k = i + 1; k <= POLY_ORDER; ++k, ++m) {
+- int e;
+- FIXP_DBL mult = fMultNorm(FX_CHB2FX_DBL(pLnormInv1d[m]), x[k], &e);
+- int mult_sf = pLnormInv1d_sf[m] + x_sf[k] + e;
+-
+- /* check if the new summand mult has a different sf than sum currently has
+- */
+- int diff = mult_sf - sum_sf;
+-
+- if (diff > 0) {
+- /* yes, and it requires the sum v to be adjusted (scaled down) */
+- sum >>= diff;
+- sum_sf = mult_sf;
+- } else if (diff < 0) {
+- /* yes, but here mult needs to be scaled down */
+- mult >>= -diff;
+- }
+-
+- /* mult has now the same sf than what it is about to be added to. */
+- /* scale mult down additionally so that building the sum is overflow-safe.
+- */
+- sum -= (mult >> SUM_SAFETY);
+- }
+-
+- x_sf[i] = sum_sf + SUM_SAFETY;
+- x[i] = sum;
+- }
+-}
+-
+-/**
+- * \brief Solves a system of linear equations (L*x=b) with the Cholesky
+- * algorithm.
+- *
+- * \param[in] numBands SBR crossover band index
+- * \param[in,out] b input: vector b, output: solution vector p.
+- * \param[in,out] b_sf input: exponent of b; output: exponent of solution
+- * p.
+- */
+-static void choleskySolve(const int numBands, FIXP_DBL *RESTRICT b,
+- int *RESTRICT b_sf) {
+- int i, e;
+-
+- const FIXP_CHB *RESTRICT pBmul0 = bsd[numBands - BSD_IDX_OFFSET].Bmul0;
+- const SCHAR *RESTRICT pBmul0_sf = bsd[numBands - BSD_IDX_OFFSET].Bmul0_sf;
+- const FIXP_CHB *RESTRICT pBmul1 = bsd[numBands - BSD_IDX_OFFSET].Bmul1;
+- const SCHAR *RESTRICT pBmul1_sf = bsd[numBands - BSD_IDX_OFFSET].Bmul1_sf;
+-
+- /* normalize b */
+- FIXP_DBL bnormed[POLY_ORDER + 1];
+- for (i = 0; i <= POLY_ORDER; ++i) {
+- bnormed[i] = fMultNorm(b[i], FX_CHB2FX_DBL(pBmul0[i]), &e);
+- b_sf[i] += pBmul0_sf[i] + e;
+- }
+-
+- backsubst_fw(numBands, bnormed, b, b_sf);
+-
+- /* normalize b again */
+- for (i = 0; i <= POLY_ORDER; ++i) {
+- bnormed[i] = fMultNorm(b[i], FX_CHB2FX_DBL(pBmul1[i]), &e);
+- b_sf[i] += pBmul1_sf[i] + e;
+- }
+-
+- backsubst_bw(numBands, bnormed, b, b_sf);
+-}
+-
+-/**
+- * \brief Find polynomial approximation of vector y with implicit abscisas
+- * x=0,1,2,3..n-1
+- *
+- * The problem (V^T * V * p = V^T * y) is solved with Cholesky.
+- * V is the Vandermode Matrix constructed with x = 0...n-1;
+- * A = V^T * V; b = V^T * y;
+- *
+- * \param[in] numBands SBR crossover band index (BSD_IDX_OFFSET <= numBands <=
+- * MAXLOWBANDS)
+- * \param[in] y input vector (mantissa)
+- * \param[in] y_sf exponents of y[]
+- * \param[out] p output polynomial coefficients (mantissa)
+- * \param[out] p_sf exponents of p[]
+- */
+-static void polyfit(const int numBands, const FIXP_DBL *const y, const int y_sf,
+- FIXP_DBL *RESTRICT p, int *RESTRICT p_sf) {
+- int i, k;
+- LONG v[POLY_ORDER + 1];
+- int sum_saftey = getLog2[numBands - 1];
+-
+- FDK_ASSERT((numBands >= BSD_IDX_OFFSET) && (numBands <= MAXLOWBANDS));
+-
+- /* construct vector b[] temporarily stored in array p[] */
+- FDKmemclear(p, (POLY_ORDER + 1) * sizeof(FIXP_DBL));
+-
+- /* p[] are the sums over n values and each p[i] has its own sf */
+- for (i = 0; i <= POLY_ORDER; ++i) p_sf[i] = 1 - DFRACT_BITS;
+-
+- for (k = 0; k < numBands; k++) {
+- v[0] = (LONG)1;
+- for (i = 1; i <= POLY_ORDER; i++) {
+- v[i] = k * v[i - 1];
+- }
+-
+- for (i = 0; i <= POLY_ORDER; i++) {
+- if (v[POLY_ORDER - i] != 0 && y[k] != FIXP_DBL(0)) {
+- int e;
+- FIXP_DBL mult = fMultNorm((FIXP_DBL)v[POLY_ORDER - i], y[k], &e);
+- int sf = DFRACT_BITS - 1 + y_sf + e;
+-
+- /* check if the new summand has a different sf than the sum p[i]
+- * currently has */
+- int diff = sf - p_sf[i];
+-
+- if (diff > 0) {
+- /* yes, and it requires the sum p[i] to be adjusted (scaled down) */
+- p[i] >>= fMin(DFRACT_BITS - 1, diff);
+- p_sf[i] = sf;
+- } else if (diff < 0) {
+- /* yes, but here mult needs to be scaled down */
+- mult >>= -diff;
+- }
+-
+- /* mult has now the same sf than what it is about to be added to.
+- scale mult down additionally so that building the sum is
+- overflow-safe. */
+- p[i] += mult >> sum_saftey;
+- }
+- }
+- }
+-
+- p_sf[0] += sum_saftey;
+- p_sf[1] += sum_saftey;
+- p_sf[2] += sum_saftey;
+- p_sf[3] += sum_saftey;
+-
+- choleskySolve(numBands, p, p_sf);
+-}
+-
+-/**
+- * \brief Calculates the output of a POLY_ORDER-degree polynomial function
+- * with Horner scheme:
+- *
+- * y(x) = p3 + p2*x + p1*x^2 + p0*x^3
+- * = p3 + x*(p2 + x*(p1 + x*p0))
+- *
+- * The for loop iterates through the mult/add parts in y(x) as above,
+- * during which regular upscaling ensures a stable exponent of the
+- * result.
+- *
+- * \param[in] p coefficients as in y(x)
+- * \param[in] p_sf exponents of p[]
+- * \param[in] x_int non-fractional integer representation of x as in y(x)
+- * \param[out] out_sf exponent of return value
+- *
+- * \return result y(x)
+- */
+-static FIXP_DBL polyval(const FIXP_DBL *const p, const int *const p_sf,
+- const int x_int, int *out_sf) {
+- FDK_ASSERT(x_int <= 31); /* otherwise getLog2[] needs more elements */
+-
+- int k, x_sf;
+- int result_sf; /* working space to compute return value *out_sf */
+- FIXP_DBL x; /* fractional value of x_int */
+- FIXP_DBL result; /* return value */
+-
+- /* if x == 0, then y(x) is just p3 */
+- if (x_int != 0) {
+- x_sf = getLog2[x_int];
+- x = (FIXP_DBL)x_int << (DFRACT_BITS - 1 - x_sf);
+- } else {
+- *out_sf = p_sf[3];
+- return p[3];
+- }
+-
+- result = p[0];
+- result_sf = p_sf[0];
+-
+- for (k = 1; k <= POLY_ORDER; ++k) {
+- FIXP_DBL mult = fMult(x, result);
+- int mult_sf = x_sf + result_sf;
+-
+- int room = CountLeadingBits(mult);
+- mult <<= room;
+- mult_sf -= room;
+-
+- FIXP_DBL pp = p[k];
+- int pp_sf = p_sf[k];
+-
+- /* equalize the shift factors of pp and mult so that we can sum them up */
+- int diff = pp_sf - mult_sf;
+-
+- if (diff > 0) {
+- diff = fMin(diff, DFRACT_BITS - 1);
+- mult >>= diff;
+- } else if (diff < 0) {
+- diff = fMax(diff, 1 - DFRACT_BITS);
+- pp >>= -diff;
+- }
+-
+- /* downshift by 1 to ensure safe summation */
+- mult >>= 1;
+- mult_sf++;
+- pp >>= 1;
+- pp_sf++;
+-
+- result_sf = fMax(pp_sf, mult_sf);
+-
+- result = mult + pp;
+- /* rarely, mult and pp happen to be almost equal except their sign,
+- and then upon summation, result becomes so small, that it is within
+- the inaccuracy range of a few bits, and then the relative error
+- produced by this function may become HUGE */
+- }
+-
+- *out_sf = result_sf;
+- return result;
+-}
+-
+-void sbrDecoder_calculateGainVec(FIXP_DBL **sourceBufferReal,
+- FIXP_DBL **sourceBufferImag,
+- int sourceBuf_e_overlap,
+- int sourceBuf_e_current, int overlap,
+- FIXP_DBL *RESTRICT GainVec, int *GainVec_exp,
+- int numBands, const int startSample,
+- const int stopSample) {
+- FIXP_DBL p[POLY_ORDER + 1];
+- FIXP_DBL meanNrg;
+- FIXP_DBL LowEnv[MAXLOWBANDS];
+- FIXP_DBL invNumBands = GetInvInt(numBands);
+- FIXP_DBL invNumSlots = GetInvInt(stopSample - startSample);
+- int i, loBand, exp, scale_nrg, scale_nrg_ov;
+- int sum_scale = 5, sum_scale_ov = 3;
+-
+- if (overlap > 8) {
+- FDK_ASSERT(overlap <= 16);
+- sum_scale_ov += 1;
+- sum_scale += 1;
+- }
+-
+- /* exponents of energy values */
+- sourceBuf_e_overlap = sourceBuf_e_overlap * 2 + sum_scale_ov;
+- sourceBuf_e_current = sourceBuf_e_current * 2 + sum_scale;
+- exp = fMax(sourceBuf_e_overlap, sourceBuf_e_current);
+- scale_nrg = sourceBuf_e_current - exp;
+- scale_nrg_ov = sourceBuf_e_overlap - exp;
+-
+- meanNrg = (FIXP_DBL)0;
+- /* Calculate the spectral envelope in dB over the current copy-up frame. */
+- for (loBand = 0; loBand < numBands; loBand++) {
+- FIXP_DBL nrg_ov, nrg;
+- INT reserve = 0, exp_new;
+- FIXP_DBL maxVal = FL2FX_DBL(0.0f);
+-
+- for (i = startSample; i < stopSample; i++) {
+- maxVal |=
+- (FIXP_DBL)((LONG)(sourceBufferReal[i][loBand]) ^
+- ((LONG)sourceBufferReal[i][loBand] >> (SAMPLE_BITS - 1)));
+- maxVal |=
+- (FIXP_DBL)((LONG)(sourceBufferImag[i][loBand]) ^
+- ((LONG)sourceBufferImag[i][loBand] >> (SAMPLE_BITS - 1)));
+- }
+-
+- if (maxVal != FL2FX_DBL(0.0f)) {
+- reserve = fixMax(0, CntLeadingZeros(maxVal) - 2);
+- }
+-
+- nrg_ov = nrg = (FIXP_DBL)0;
+- if (scale_nrg_ov > -31) {
+- for (i = startSample; i < overlap; i++) {
+- nrg_ov += (fPow2Div2(sourceBufferReal[i][loBand] << reserve) +
+- fPow2Div2(sourceBufferImag[i][loBand] << reserve)) >>
+- sum_scale_ov;
+- }
+- } else {
+- scale_nrg_ov = 0;
+- }
+- if (scale_nrg > -31) {
+- for (i = overlap; i < stopSample; i++) {
+- nrg += (fPow2Div2(sourceBufferReal[i][loBand] << reserve) +
+- fPow2Div2(sourceBufferImag[i][loBand] << reserve)) >>
+- sum_scale;
+- }
+- } else {
+- scale_nrg = 0;
+- }
+-
+- nrg = (scaleValue(nrg_ov, scale_nrg_ov) >> 1) +
+- (scaleValue(nrg, scale_nrg) >> 1);
+- nrg = fMult(nrg, invNumSlots);
+-
+- exp_new =
+- exp - (2 * reserve) +
+- 2; /* +1 for addition directly above, +1 for fPow2Div2 in loops above */
+-
+- /* LowEnv = 10*log10(nrg) = log2(nrg) * 10/log2(10) */
+- /* exponent of logarithmic energy is 8 */
+- if (nrg > (FIXP_DBL)0) {
+- int exp_log2;
+- nrg = CalcLog2(nrg, exp_new, &exp_log2);
+- nrg = scaleValue(nrg, exp_log2 - 6);
+- nrg = fMult(FL2FXCONST_SGL(LOG10FAC), nrg);
+- } else {
+- nrg = (FIXP_DBL)0;
+- }
+- LowEnv[loBand] = nrg;
+- meanNrg += fMult(nrg, invNumBands);
+- }
+- exp = 6 + 2; /* exponent of LowEnv: +2 is exponent of LOG10FAC */
+-
+- /* subtract mean before polynomial approximation to reduce dynamic of p[] */
+- for (loBand = 0; loBand < numBands; loBand++) {
+- LowEnv[loBand] = meanNrg - LowEnv[loBand];
+- }
+-
+- /* For numBands < BSD_IDX_OFFSET (== POLY_ORDER+2) we dont get an
+- overdetermined equation system. The calculated polynomial will exactly fit
+- the input data and evaluating the polynomial will lead to the same vector
+- than the original input vector: lowEnvSlope[] == lowEnv[]
+- */
+- if (numBands > POLY_ORDER + 1) {
+- /* Find polynomial approximation of LowEnv */
+- int p_sf[POLY_ORDER + 1];
+-
+- polyfit(numBands, LowEnv, exp, p, p_sf);
+-
+- for (i = 0; i < numBands; i++) {
+- int sf;
+-
+- /* lowBandEnvSlope[i] = tmp; */
+- FIXP_DBL tmp = polyval(p, p_sf, i, &sf);
+-
+- /* GainVec = 10^((mean(y)-y)/20) = 2^( (mean(y)-y) * log2(10)/20 ) */
+- tmp = fMult(tmp, FL2FXCONST_SGL(LOG10FAC_INV));
+- GainVec[i] = f2Pow(tmp, sf - 2,
+- &GainVec_exp[i]); /* -2 is exponent of LOG10FAC_INV */
+- }
+- } else { /* numBands <= POLY_ORDER+1 */
+- for (i = 0; i < numBands; i++) {
+- int sf = exp; /* exponent of LowEnv[] */
+-
+- /* lowBandEnvSlope[i] = LowEnv[i]; */
+- FIXP_DBL tmp = LowEnv[i];
+-
+- /* GainVec = 10^((mean(y)-y)/20) = 2^( (mean(y)-y) * log2(10)/20 ) */
+- tmp = fMult(tmp, FL2FXCONST_SGL(LOG10FAC_INV));
+- GainVec[i] = f2Pow(tmp, sf - 2,
+- &GainVec_exp[i]); /* -2 is exponent of LOG10FAC_INV */
+- }
+- }
+-}
+diff --git a/libSBRdec/src/HFgen_preFlat.h b/libSBRdec/src/HFgen_preFlat.h
+deleted file mode 100644
+index c1fc49d..0000000
+--- a/libSBRdec/src/HFgen_preFlat.h
++++ /dev/null
+@@ -1,132 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s): Manuel Jander, Matthias Hildenbrand
+-
+- Description: QMF frequency pre whitening for SBR
+-
+-*******************************************************************************/
+-
+-#include "common_fix.h"
+-
+-#ifndef HFGEN_PREFLAT_H
+-#define HFGEN_PREFLAT_H
+-
+-#define GAIN_VEC_EXP 6 /* exponent of GainVec[] */
+-
+-/**
+- * \brief Find gain vector to flatten the QMF frequency bands whithout loosing
+- * the fine structure.
+- * \param[in] sourceBufferReal real part of QMF domain data.
+- * \param[in] sourceBufferImag imaginary part of QMF domain data.
+- * \param[in] sourceBuffer_e_overlap exponent of sourceBufferReal.
+- * \param[in] sourceBuffer_e_current exponent of sourceBufferImag.
+- * \param[in] overlap number of overlap samples.
+- * \param[out] GainVec array of gain values (one for each QMF band).
+- * \param[out] GainVec_exp exponents of GainVec (one for each QMF band).
+- * \param[in] numBands number of low bands (k_0).
+- * \param[in] startSample time slot start.
+- * \param[in] stopSample time slot stop.
+- */
+-void sbrDecoder_calculateGainVec(FIXP_DBL **sourceBufferReal,
+- FIXP_DBL **sourceBufferImag,
+- int sourceBuffer_e_overlap,
+- int sourceBuffer_e_current, int overlap,
+- FIXP_DBL GainVec[], int GainVec_exp[],
+- const int numBands, const int startSample,
+- const int stopSample);
+-
+-#endif /* __HFGEN_PREFLAT_H */
+diff --git a/libSBRdec/src/arm/lpp_tran_arm.cpp b/libSBRdec/src/arm/lpp_tran_arm.cpp
+deleted file mode 100644
+index db1948f..0000000
+--- a/libSBRdec/src/arm/lpp_tran_arm.cpp
++++ /dev/null
+@@ -1,159 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s): Arthur Tritthart
+-
+- Description: (ARM optimised) LPP transposer subroutines
+-
+-*******************************************************************************/
+-
+-#if defined(__arm__)
+-
+-#define FUNCTION_LPPTRANSPOSER_func1
+-
+-#ifdef FUNCTION_LPPTRANSPOSER_func1
+-
+-/* Note: This code requires only 43 cycles per iteration instead of 61 on
+- * ARM926EJ-S */
+-static void lppTransposer_func1(FIXP_DBL *lowBandReal, FIXP_DBL *lowBandImag,
+- FIXP_DBL **qmfBufferReal,
+- FIXP_DBL **qmfBufferImag, int loops, int hiBand,
+- int dynamicScale, int descale, FIXP_SGL a0r,
+- FIXP_SGL a0i, FIXP_SGL a1r, FIXP_SGL a1i,
+- const int fPreWhitening,
+- FIXP_DBL preWhiteningGain,
+- int preWhiteningGains_sf) {
+- FIXP_DBL real1, real2, imag1, imag2, accu1, accu2;
+-
+- real2 = lowBandReal[-2];
+- real1 = lowBandReal[-1];
+- imag2 = lowBandImag[-2];
+- imag1 = lowBandImag[-1];
+- for (int i = 0; i < loops; i++) {
+- accu1 = fMultDiv2(a0r, real1);
+- accu2 = fMultDiv2(a0i, imag1);
+- accu1 = fMultAddDiv2(accu1, a1r, real2);
+- accu2 = fMultAddDiv2(accu2, a1i, imag2);
+- real2 = fMultDiv2(a1i, real2);
+- accu1 = accu1 - accu2;
+- accu1 = accu1 >> dynamicScale;
+-
+- accu2 = fMultAddDiv2(real2, a1r, imag2);
+- real2 = real1;
+- imag2 = imag1;
+- accu2 = fMultAddDiv2(accu2, a0i, real1);
+- real1 = lowBandReal[i];
+- accu2 = fMultAddDiv2(accu2, a0r, imag1);
+- imag1 = lowBandImag[i];
+- accu2 = accu2 >> dynamicScale;
+-
+- accu1 <<= 1;
+- accu2 <<= 1;
+- accu1 += (real1 >> descale);
+- accu2 += (imag1 >> descale);
+- if (fPreWhitening) {
+- accu1 = scaleValueSaturate(fMultDiv2(accu1, preWhiteningGain),
+- preWhiteningGains_sf);
+- accu2 = scaleValueSaturate(fMultDiv2(accu2, preWhiteningGain),
+- preWhiteningGains_sf);
+- }
+- qmfBufferReal[i][hiBand] = accu1;
+- qmfBufferImag[i][hiBand] = accu2;
+- }
+-}
+-#endif /* #ifdef FUNCTION_LPPTRANSPOSER_func1 */
+-
+-#endif /* __arm__ */
+diff --git a/libSBRdec/src/env_calc.cpp b/libSBRdec/src/env_calc.cpp
+deleted file mode 100644
+index cb1474f..0000000
+--- a/libSBRdec/src/env_calc.cpp
++++ /dev/null
+@@ -1,3158 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Envelope calculation
+-
+- The envelope adjustor compares the energies present in the transposed
+- highband to the reference energies conveyed with the bitstream.
+- The highband is amplified (sometimes) or attenuated (mostly) to the
+- desired level.
+-
+- The spectral shape of the reference energies can be changed several times per
+- frame if necessary. Each set of energy values corresponding to a certain range
+- in time will be called an <em>envelope</em> here.
+- The bitstream supports several frequency scales and two resolutions. Normally,
+- one or more QMF-subbands are grouped to one SBR-band. An envelope contains
+- reference energies for each SBR-band.
+- In addition to the energy envelopes, noise envelopes are transmitted that
+- define the ratio of energy which is generated by adding noise instead of
+- transposing the lowband. The noise envelopes are given in a coarser time
+- and frequency resolution.
+- If a signal contains strong tonal components, synthetic sines can be
+- generated in individual SBR bands.
+-
+- An overlap buffer of 6 QMF-timeslots is used to allow a more
+- flexible alignment of the envelopes in time that is not restricted to the
+- core codec's frame borders.
+- Therefore the envelope adjustor has access to the spectral data of the
+- current frame as well as the last 6 QMF-timeslots of the previous frame.
+- However, in average only the data of 1 frame is being processed as
+- the adjustor is called once per frame.
+-
+- Depending on the frequency range set in the bitstream, only QMF-subbands
+- between <em>lowSubband</em> and <em>highSubband</em> are adjusted.
+-
+- Scaling of spectral data to maximize SNR (see #QMF_SCALE_FACTOR) as well as a
+- special Mantissa-Exponent format ( see calculateSbrEnvelope() ) are being
+- used. The main entry point for this modules is calculateSbrEnvelope().
+-
+- \sa sbr_scale.h, #QMF_SCALE_FACTOR, calculateSbrEnvelope(), \ref
+- documentationOverview
+-*/
+-
+-#include "env_calc.h"
+-
+-#include "sbrdec_freq_sca.h"
+-#include "env_extr.h"
+-#include "transcendent.h"
+-#include "sbr_ram.h"
+-#include "sbr_rom.h"
+-
+-#include "genericStds.h" /* need FDKpow() for debug outputs */
+-
+-typedef struct {
+- FIXP_DBL nrgRef[MAX_FREQ_COEFFS];
+- FIXP_DBL nrgEst[MAX_FREQ_COEFFS];
+- FIXP_DBL nrgGain[MAX_FREQ_COEFFS];
+- FIXP_DBL noiseLevel[MAX_FREQ_COEFFS];
+- FIXP_DBL nrgSine[MAX_FREQ_COEFFS];
+-
+- SCHAR nrgRef_e[MAX_FREQ_COEFFS];
+- SCHAR nrgEst_e[MAX_FREQ_COEFFS];
+- SCHAR nrgGain_e[MAX_FREQ_COEFFS];
+- SCHAR noiseLevel_e[MAX_FREQ_COEFFS];
+- SCHAR nrgSine_e[MAX_FREQ_COEFFS];
+- /* yet another exponent [0]: for ts < no_cols; [1]: for ts >= no_cols */
+- SCHAR exponent[2];
+-} ENV_CALC_NRGS;
+-
+-static void equalizeFiltBufferExp(FIXP_DBL *filtBuffer, SCHAR *filtBuffer_e,
+- FIXP_DBL *NrgGain, SCHAR *NrgGain_e,
+- int subbands);
+-
+-static void calcNrgPerSubband(FIXP_DBL **analysBufferReal,
+- FIXP_DBL **analysBufferImag, int lowSubband,
+- int highSubband, int start_pos, int next_pos,
+- SCHAR frameExp, FIXP_DBL *nrgEst,
+- SCHAR *nrgEst_e);
+-
+-static void calcNrgPerSfb(FIXP_DBL **analysBufferReal,
+- FIXP_DBL **analysBufferImag, int nSfb,
+- UCHAR *freqBandTable, int start_pos, int next_pos,
+- SCHAR input_e, FIXP_DBL *nrg_est, SCHAR *nrg_est_e);
+-
+-static void calcSubbandGain(FIXP_DBL nrgRef, SCHAR nrgRef_e,
+- ENV_CALC_NRGS *nrgs, int c, FIXP_DBL tmpNoise,
+- SCHAR tmpNoise_e, UCHAR sinePresentFlag,
+- UCHAR sineMapped, int noNoiseFlag);
+-
+-static void calcAvgGain(ENV_CALC_NRGS *nrgs, int lowSubband, int highSubband,
+- FIXP_DBL *sumRef_m, SCHAR *sumRef_e,
+- FIXP_DBL *ptrAvgGain_m, SCHAR *ptrAvgGain_e);
+-
+-static void adjustTimeSlot_EldGrid(FIXP_DBL *ptrReal, ENV_CALC_NRGS *nrgs,
+- UCHAR *ptrHarmIndex, int lowSubbands,
+- int noSubbands, int scale_change,
+- int noNoiseFlag, int *ptrPhaseIndex,
+- int scale_diff_low);
+-
+-static void adjustTimeSlotLC(FIXP_DBL *ptrReal, ENV_CALC_NRGS *nrgs,
+- UCHAR *ptrHarmIndex, int lowSubbands,
+- int noSubbands, int scale_change, int noNoiseFlag,
+- int *ptrPhaseIndex);
+-
+-/**
+- * \brief Variant of adjustTimeSlotHQ() which only regards gain and noise but no
+- * additional harmonics
+- */
+-static void adjustTimeSlotHQ_GainAndNoise(
+- FIXP_DBL *ptrReal, FIXP_DBL *ptrImag,
+- HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env, ENV_CALC_NRGS *nrgs,
+- int lowSubbands, int noSubbands, int scale_change, FIXP_SGL smooth_ratio,
+- int noNoiseFlag, int filtBufferNoiseShift);
+-/**
+- * \brief Variant of adjustTimeSlotHQ() which only adds the additional harmonics
+- */
+-static void adjustTimeSlotHQ_AddHarmonics(
+- FIXP_DBL *ptrReal, FIXP_DBL *ptrImag,
+- HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env, ENV_CALC_NRGS *nrgs,
+- int lowSubbands, int noSubbands, int scale_change);
+-
+-static void adjustTimeSlotHQ(FIXP_DBL *ptrReal, FIXP_DBL *ptrImag,
+- HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env,
+- ENV_CALC_NRGS *nrgs, int lowSubbands,
+- int noSubbands, int scale_change,
+- FIXP_SGL smooth_ratio, int noNoiseFlag,
+- int filtBufferNoiseShift);
+-
+-/*!
+- \brief Map sine flags from bitstream to QMF bands
+-
+- The bitstream carries only 1 sine flag per band (Sfb) and frame.
+- This function maps every sine flag from the bitstream to a specific QMF
+- subband and to a specific envelope where the sine shall start. The result is
+- stored in the vector sineMapped which contains one entry per QMF subband. The
+- value of an entry specifies the envelope where a sine shall start. A value of
+- 32 indicates that no sine is present in the subband. The missing harmonics
+- flags from the previous frame (harmFlagsPrev) determine if a sine starts at
+- the beginning of the frame or at the transient position. Additionally, the
+- flags in harmFlagsPrev are being updated by this function for the next frame.
+-*/
+-static void mapSineFlags(
+- UCHAR *freqBandTable, /*!< Band borders (there's only 1 flag per band) */
+- int nSfb, /*!< Number of bands in the table */
+- ULONG *addHarmonics, /*!< Packed addHarmonics of current frame (aligned to
+- the MSB) */
+- ULONG *harmFlagsPrev, /*!< Packed addHarmonics of previous frame (aligned to
+- the LSB) */
+- ULONG *harmFlagsPrevActive, /*!< Packed sineMapped of previous frame
+- (aligned to the LSB) */
+- int tranEnv, /*!< Transient position */
+- SCHAR *sineMapped) /*!< Resulting vector of sine start positions for each
+- QMF band */
+-
+-{
+- int i;
+- int bitcount = 31;
+- ULONG harmFlagsQmfBands[ADD_HARMONICS_FLAGS_SIZE] = {0};
+- ULONG *curFlags = addHarmonics;
+-
+- /*
+- Format of addHarmonics (aligned to MSB):
+-
+- Up to MAX_FREQ_COEFFS sfb bands can be flagged for a sign.
+- first word = flags for lowest 32 sfb bands in use
+- second word = flags for higest 32 sfb bands (if present)
+-
+- Format of harmFlagsPrev (aligned to LSB):
+-
+- Index is absolute (not relative to lsb) so it is correct even if lsb
+- changes first word = flags for lowest 32 qmf bands (0...31) second word =
+- flags for next higher 32 qmf bands (32...63)
+-
+- */
+-
+- /* Reset the output vector first */
+- FDKmemset(sineMapped, 32,
+- MAX_FREQ_COEFFS * sizeof(SCHAR)); /* 32 means 'no sine' */
+- FDKmemclear(harmFlagsPrevActive, ADD_HARMONICS_FLAGS_SIZE * sizeof(ULONG));
+- for (i = 0; i < nSfb; i++) {
+- ULONG maskSfb =
+- 1 << bitcount; /* mask to extract addHarmonics flag of current Sfb */
+-
+- if (*curFlags & maskSfb) { /* There is a sine in this band */
+- const int lsb = freqBandTable[0]; /* start of sbr range */
+- /* qmf band to which sine should be added */
+- const int qmfBand = (freqBandTable[i] + freqBandTable[i + 1]) >> 1;
+- const int qmfBandDiv32 = qmfBand >> 5;
+- const int maskQmfBand =
+- 1 << (qmfBand &
+- 31); /* mask to extract harmonic flag from prevFlags */
+-
+- /* mapping of sfb with sine to a certain qmf band -> for harmFlagsPrev */
+- harmFlagsQmfBands[qmfBandDiv32] |= maskQmfBand;
+-
+- /*
+- If there was a sine in the last frame, let it continue from the first
+- envelope on else start at the transient position. Indexing of sineMapped
+- starts relative to lsb.
+- */
+- sineMapped[qmfBand - lsb] =
+- (harmFlagsPrev[qmfBandDiv32] & maskQmfBand) ? 0 : tranEnv;
+- if (sineMapped[qmfBand - lsb] < PVC_NTIMESLOT) {
+- harmFlagsPrevActive[qmfBandDiv32] |= maskQmfBand;
+- }
+- }
+-
+- if (bitcount-- == 0) {
+- bitcount = 31;
+- curFlags++;
+- }
+- }
+- FDKmemcpy(harmFlagsPrev, harmFlagsQmfBands,
+- sizeof(ULONG) * ADD_HARMONICS_FLAGS_SIZE);
+-}
+-
+-/*!
+- \brief Restore sineMapped of previous frame
+-
+- For PVC it might happen that the PVC framing (always 0) is out of sync with
+- the SBR framing. The adding of additional harmonics is done based on the SBR
+- framing. If the SBR framing is trailing the PVC framing the sine mapping of
+- the previous SBR frame needs to be used for the overlapping time slots.
+-*/
+-/*static*/ void mapSineFlagsPvc(
+- UCHAR *freqBandTable, /*!< Band borders (there's only 1 flag per
+- band) */
+- int nSfb, /*!< Number of bands in the table */
+- ULONG *harmFlagsPrev, /*!< Packed addHarmonics of previous frame
+- (aligned to the MSB) */
+- ULONG *harmFlagsPrevActive, /*!< Packed sineMapped of previous
+- frame (aligned to the LSB) */
+- SCHAR *sineMapped, /*!< Resulting vector of sine start positions
+- for each QMF band */
+- int sinusoidalPos, /*!< sinusoidal position */
+- SCHAR *sinusoidalPosPrev, /*!< sinusoidal position of previous
+- frame */
+- int trailingSbrFrame) /*!< indication if the SBR framing is
+- trailing the PVC framing */
+-{
+- /* Reset the output vector first */
+- FDKmemset(sineMapped, 32, MAX_FREQ_COEFFS); /* 32 means 'no sine' */
+-
+- if (trailingSbrFrame) {
+- /* restore sineMapped[] of previous frame */
+- int i;
+- const int lsb = freqBandTable[0];
+- const int usb = freqBandTable[nSfb];
+- for (i = lsb; i < usb; i++) {
+- const int qmfBandDiv32 = i >> 5;
+- const int maskQmfBand =
+- 1 << (i & 31); /* mask to extract harmonic flag from prevFlags */
+-
+- /* Two cases need to be distinguished ... */
+- if (harmFlagsPrevActive[qmfBandDiv32] & maskQmfBand) {
+- /* the sine mapping already started last PVC frame -> seamlessly
+- * continue */
+- sineMapped[i - lsb] = 0;
+- } else if (harmFlagsPrev[qmfBandDiv32] & maskQmfBand) {
+- /* sinusoidalPos of prev PVC frame was >= PVC_NTIMESLOT -> sine starts
+- * in this frame */
+- sineMapped[i - lsb] =
+- *sinusoidalPosPrev - PVC_NTIMESLOT; /* we are 16 sbr time slots
+- ahead of last frame now */
+- }
+- }
+- }
+- *sinusoidalPosPrev = sinusoidalPos;
+-}
+-
+-/*!
+- \brief Reduce gain-adjustment induced aliasing for real valued filterbank.
+-*/
+-/*static*/ void aliasingReduction(
+- FIXP_DBL *degreeAlias, /*!< estimated aliasing for each QMF
+- channel */
+- ENV_CALC_NRGS *nrgs,
+- UCHAR *useAliasReduction, /*!< synthetic sine energy for each
+- subband, used as flag */
+- int noSubbands) /*!< number of QMF channels to process */
+-{
+- FIXP_DBL *nrgGain = nrgs->nrgGain; /*!< subband gains to be modified */
+- SCHAR *nrgGain_e =
+- nrgs->nrgGain_e; /*!< subband gains to be modified (exponents) */
+- FIXP_DBL *nrgEst = nrgs->nrgEst; /*!< subband energy before amplification */
+- SCHAR *nrgEst_e =
+- nrgs->nrgEst_e; /*!< subband energy before amplification (exponents) */
+- int grouping = 0, index = 0, noGroups, k;
+- int groupVector[MAX_FREQ_COEFFS];
+-
+- /* Calculate grouping*/
+- for (k = 0; k < noSubbands - 1; k++) {
+- if ((degreeAlias[k + 1] != FL2FXCONST_DBL(0.0f)) && useAliasReduction[k]) {
+- if (grouping == 0) {
+- groupVector[index++] = k;
+- grouping = 1;
+- } else {
+- if (groupVector[index - 1] + 3 == k) {
+- groupVector[index++] = k + 1;
+- grouping = 0;
+- }
+- }
+- } else {
+- if (grouping) {
+- if (useAliasReduction[k])
+- groupVector[index++] = k + 1;
+- else
+- groupVector[index++] = k;
+- grouping = 0;
+- }
+- }
+- }
+-
+- if (grouping) {
+- groupVector[index++] = noSubbands;
+- }
+- noGroups = index >> 1;
+-
+- /*Calculate new gain*/
+- for (int group = 0; group < noGroups; group++) {
+- FIXP_DBL nrgOrig = FL2FXCONST_DBL(
+- 0.0f); /* Original signal energy in current group of bands */
+- SCHAR nrgOrig_e = 0;
+- FIXP_DBL nrgAmp = FL2FXCONST_DBL(
+- 0.0f); /* Amplified signal energy in group (using current gains) */
+- SCHAR nrgAmp_e = 0;
+- FIXP_DBL nrgMod = FL2FXCONST_DBL(
+- 0.0f); /* Signal energy in group when applying modified gains */
+- SCHAR nrgMod_e = 0;
+- FIXP_DBL groupGain; /* Total energy gain in group */
+- SCHAR groupGain_e;
+- FIXP_DBL compensation; /* Compensation factor for the energy change when
+- applying modified gains */
+- SCHAR compensation_e;
+-
+- int startGroup = groupVector[2 * group];
+- int stopGroup = groupVector[2 * group + 1];
+-
+- /* Calculate total energy in group before and after amplification with
+- * current gains: */
+- for (k = startGroup; k < stopGroup; k++) {
+- /* Get original band energy */
+- FIXP_DBL tmp = nrgEst[k];
+- SCHAR tmp_e = nrgEst_e[k];
+-
+- FDK_add_MantExp(tmp, tmp_e, nrgOrig, nrgOrig_e, &nrgOrig, &nrgOrig_e);
+-
+- /* Multiply band energy with current gain */
+- tmp = fMult(tmp, nrgGain[k]);
+- tmp_e = tmp_e + nrgGain_e[k];
+-
+- FDK_add_MantExp(tmp, tmp_e, nrgAmp, nrgAmp_e, &nrgAmp, &nrgAmp_e);
+- }
+-
+- /* Calculate total energy gain in group */
+- FDK_divide_MantExp(nrgAmp, nrgAmp_e, nrgOrig, nrgOrig_e, &groupGain,
+- &groupGain_e);
+-
+- for (k = startGroup; k < stopGroup; k++) {
+- FIXP_DBL tmp;
+- SCHAR tmp_e;
+-
+- FIXP_DBL alpha = degreeAlias[k];
+- if (k < noSubbands - 1) {
+- if (degreeAlias[k + 1] > alpha) alpha = degreeAlias[k + 1];
+- }
+-
+- /* Modify gain depending on the degree of aliasing */
+- FDK_add_MantExp(
+- fMult(alpha, groupGain), groupGain_e,
+- fMult(/*FL2FXCONST_DBL(1.0f)*/ (FIXP_DBL)MAXVAL_DBL - alpha,
+- nrgGain[k]),
+- nrgGain_e[k], &nrgGain[k], &nrgGain_e[k]);
+-
+- /* Apply modified gain to original energy */
+- tmp = fMult(nrgGain[k], nrgEst[k]);
+- tmp_e = nrgGain_e[k] + nrgEst_e[k];
+-
+- /* Accumulate energy with modified gains applied */
+- FDK_add_MantExp(tmp, tmp_e, nrgMod, nrgMod_e, &nrgMod, &nrgMod_e);
+- }
+-
+- /* Calculate compensation factor to retain the energy of the amplified
+- * signal */
+- FDK_divide_MantExp(nrgAmp, nrgAmp_e, nrgMod, nrgMod_e, &compensation,
+- &compensation_e);
+-
+- /* Apply compensation factor to all gains of the group */
+- for (k = startGroup; k < stopGroup; k++) {
+- nrgGain[k] = fMult(nrgGain[k], compensation);
+- nrgGain_e[k] = nrgGain_e[k] + compensation_e;
+- }
+- }
+-}
+-
+-#define INTER_TES_SF_CHANGE 3
+-
+-typedef struct {
+- FIXP_DBL subsample_power_low[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+- FIXP_DBL subsample_power_high[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+- FIXP_DBL gain[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+- SCHAR subsample_power_low_sf[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+- SCHAR subsample_power_high_sf[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+-} ITES_TEMP;
+-
+-static void apply_inter_tes(FIXP_DBL **qmfReal, FIXP_DBL **qmfImag,
+- const QMF_SCALE_FACTOR *sbrScaleFactor,
+- const SCHAR exp[2], const int RATE,
+- const int startPos, const int stopPos,
+- const int lowSubband, const int nbSubband,
+- const UCHAR gamma_idx) {
+- int highSubband = lowSubband + nbSubband;
+- FIXP_DBL *subsample_power_high, *subsample_power_low;
+- SCHAR *subsample_power_high_sf, *subsample_power_low_sf;
+- FIXP_DBL total_power_high = (FIXP_DBL)0;
+- FIXP_DBL total_power_low = (FIXP_DBL)0;
+- FIXP_DBL *gain;
+- int gain_sf[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+-
+- /* gamma[gamma_idx] = {0.0f, 1.0f, 2.0f, 4.0f} */
+- int gamma_sf =
+- (int)gamma_idx - 1; /* perhaps +1 to save one bit? (0.99999f vs 1.f) */
+-
+- int nbSubsample = stopPos - startPos;
+- int i, j;
+-
+- C_ALLOC_SCRATCH_START(pTmp, ITES_TEMP, 1);
+- subsample_power_high = pTmp->subsample_power_high;
+- subsample_power_low = pTmp->subsample_power_low;
+- subsample_power_high_sf = pTmp->subsample_power_high_sf;
+- subsample_power_low_sf = pTmp->subsample_power_low_sf;
+- gain = pTmp->gain;
+-
+- if (gamma_idx > 0) {
+- int preShift2 = 32 - fNormz((FIXP_DBL)nbSubsample);
+- int total_power_low_sf = 1 - DFRACT_BITS;
+- int total_power_high_sf = 1 - DFRACT_BITS;
+-
+- for (i = 0; i < nbSubsample; ++i) {
+- FIXP_DBL bufferReal[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+- FIXP_DBL bufferImag[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+- FIXP_DBL maxVal = (FIXP_DBL)0;
+-
+- int ts = startPos + i;
+-
+- int low_sf = (ts < 3 * RATE) ? sbrScaleFactor->ov_lb_scale
+- : sbrScaleFactor->lb_scale;
+- low_sf = 15 - low_sf;
+-
+- for (j = 0; j < lowSubband; ++j) {
+- bufferImag[j] = qmfImag[startPos + i][j];
+- maxVal |= (FIXP_DBL)((LONG)(bufferImag[j]) ^
+- ((LONG)bufferImag[j] >> (DFRACT_BITS - 1)));
+- bufferReal[j] = qmfReal[startPos + i][j];
+- maxVal |= (FIXP_DBL)((LONG)(bufferReal[j]) ^
+- ((LONG)bufferReal[j] >> (DFRACT_BITS - 1)));
+- }
+-
+- subsample_power_low[i] = (FIXP_DBL)0;
+- subsample_power_low_sf[i] = 0;
+-
+- if (maxVal != FL2FXCONST_DBL(0.f)) {
+- /* multiply first, then shift for safe summation */
+- int preShift = 1 - CntLeadingZeros(maxVal);
+- int postShift = 32 - fNormz((FIXP_DBL)lowSubband);
+-
+- /* reduce preShift because otherwise we risk to square -1.f */
+- if (preShift != 0) preShift++;
+-
+- subsample_power_low_sf[i] += (low_sf + preShift) * 2 + postShift + 1;
+-
+- scaleValues(bufferReal, lowSubband, -preShift);
+- scaleValues(bufferImag, lowSubband, -preShift);
+- for (j = 0; j < lowSubband; ++j) {
+- FIXP_DBL addme;
+- addme = fPow2Div2(bufferReal[j]);
+- subsample_power_low[i] += addme >> postShift;
+- addme = fPow2Div2(bufferImag[j]);
+- subsample_power_low[i] += addme >> postShift;
+- }
+- }
+-
+- /* now get high */
+-
+- maxVal = (FIXP_DBL)0;
+-
+- int high_sf = exp[(ts < 16 * RATE) ? 0 : 1];
+-
+- for (j = lowSubband; j < highSubband; ++j) {
+- bufferImag[j] = qmfImag[startPos + i][j];
+- maxVal |= (FIXP_DBL)((LONG)(bufferImag[j]) ^
+- ((LONG)bufferImag[j] >> (DFRACT_BITS - 1)));
+- bufferReal[j] = qmfReal[startPos + i][j];
+- maxVal |= (FIXP_DBL)((LONG)(bufferReal[j]) ^
+- ((LONG)bufferReal[j] >> (DFRACT_BITS - 1)));
+- }
+-
+- subsample_power_high[i] = (FIXP_DBL)0;
+- subsample_power_high_sf[i] = 0;
+-
+- if (maxVal != FL2FXCONST_DBL(0.f)) {
+- int preShift = 1 - CntLeadingZeros(maxVal);
+- /* reduce preShift because otherwise we risk to square -1.f */
+- if (preShift != 0) preShift++;
+-
+- int postShift = 32 - fNormz((FIXP_DBL)(highSubband - lowSubband));
+- subsample_power_high_sf[i] += (high_sf + preShift) * 2 + postShift + 1;
+-
+- scaleValues(&bufferReal[lowSubband], highSubband - lowSubband,
+- -preShift);
+- scaleValues(&bufferImag[lowSubband], highSubband - lowSubband,
+- -preShift);
+- for (j = lowSubband; j < highSubband; j++) {
+- subsample_power_high[i] += fPow2Div2(bufferReal[j]) >> postShift;
+- subsample_power_high[i] += fPow2Div2(bufferImag[j]) >> postShift;
+- }
+- }
+-
+- /* sum all together */
+- FIXP_DBL new_summand = subsample_power_low[i];
+- int new_summand_sf = subsample_power_low_sf[i];
+-
+- /* make sure the current sum, and the new summand have the same SF */
+- if (new_summand_sf > total_power_low_sf) {
+- int diff = fMin(DFRACT_BITS - 1, new_summand_sf - total_power_low_sf);
+- total_power_low >>= diff;
+- total_power_low_sf = new_summand_sf;
+- } else if (new_summand_sf < total_power_low_sf) {
+- new_summand >>=
+- fMin(DFRACT_BITS - 1, total_power_low_sf - new_summand_sf);
+- }
+-
+- total_power_low += (new_summand >> preShift2);
+-
+- new_summand = subsample_power_high[i];
+- new_summand_sf = subsample_power_high_sf[i];
+- if (new_summand_sf > total_power_high_sf) {
+- total_power_high >>=
+- fMin(DFRACT_BITS - 1, new_summand_sf - total_power_high_sf);
+- total_power_high_sf = new_summand_sf;
+- } else if (new_summand_sf < total_power_high_sf) {
+- new_summand >>=
+- fMin(DFRACT_BITS - 1, total_power_high_sf - new_summand_sf);
+- }
+-
+- total_power_high += (new_summand >> preShift2);
+- }
+-
+- total_power_low_sf += preShift2;
+- total_power_high_sf += preShift2;
+-
+- /* gain[i] = e_LOW[i] */
+- for (i = 0; i < nbSubsample; ++i) {
+- int sf2;
+- FIXP_DBL mult =
+- fMultNorm(subsample_power_low[i], (FIXP_DBL)nbSubsample, &sf2);
+- int mult_sf = subsample_power_low_sf[i] + DFRACT_BITS - 1 + sf2;
+-
+- if (total_power_low != FIXP_DBL(0)) {
+- gain[i] = fDivNorm(mult, total_power_low, &sf2);
+- gain_sf[i] = mult_sf - total_power_low_sf + sf2;
+- gain[i] = sqrtFixp_lookup(gain[i], &gain_sf[i]);
+- if (gain_sf[i] < 0) {
+- gain[i] >>= -gain_sf[i];
+- gain_sf[i] = 0;
+- }
+- } else {
+- if (mult == FIXP_DBL(0)) {
+- gain[i] = FIXP_DBL(0);
+- gain_sf[i] = 0;
+- } else {
+- gain[i] = (FIXP_DBL)MAXVAL_DBL;
+- gain_sf[i] = 0;
+- }
+- }
+- }
+-
+- FIXP_DBL total_power_high_after = (FIXP_DBL)0;
+- int total_power_high_after_sf = 1 - DFRACT_BITS;
+-
+- /* gain[i] = g_inter[i] */
+- for (i = 0; i < nbSubsample; ++i) {
+- if (gain_sf[i] < 0) {
+- gain[i] >>= -gain_sf[i];
+- gain_sf[i] = 0;
+- }
+-
+- /* calculate: gain[i] = 1.0f + gamma * (gain[i] - 1.0f); */
+- FIXP_DBL one = (FIXP_DBL)MAXVAL_DBL >>
+- gain_sf[i]; /* to substract this from gain[i] */
+-
+- /* gamma is actually always 1 according to the table, so skip the
+- * fMultDiv2 */
+- FIXP_DBL mult = (gain[i] - one) >> 1;
+- int mult_sf = gain_sf[i] + gamma_sf;
+-
+- one = FL2FXCONST_DBL(0.5f) >> mult_sf;
+- gain[i] = one + mult;
+- gain_sf[i] += gamma_sf + 1; /* +1 because of fMultDiv2() */
+-
+- /* set gain to at least 0.2f */
+- FIXP_DBL point_two = FL2FXCONST_DBL(0.8f); /* scaled up by 2 */
+- int point_two_sf = -2;
+-
+- FIXP_DBL tmp = gain[i];
+- if (point_two_sf < gain_sf[i]) {
+- point_two >>= gain_sf[i] - point_two_sf;
+- } else {
+- tmp >>= point_two_sf - gain_sf[i];
+- }
+-
+- /* limit and calculate gain[i]^2 too */
+- FIXP_DBL gain_pow2;
+- int gain_pow2_sf;
+- if (tmp < point_two) {
+- gain[i] = FL2FXCONST_DBL(0.8f);
+- gain_sf[i] = -2;
+- gain_pow2 = FL2FXCONST_DBL(0.64f);
+- gain_pow2_sf = -4;
+- } else {
+- /* this upscaling seems quite important */
+- int r = CountLeadingBits(gain[i]);
+- gain[i] <<= r;
+- gain_sf[i] -= r;
+-
+- gain_pow2 = fPow2(gain[i]);
+- gain_pow2_sf = gain_sf[i] << 1;
+- }
+-
+- int room;
+- subsample_power_high[i] =
+- fMultNorm(subsample_power_high[i], gain_pow2, &room);
+- subsample_power_high_sf[i] =
+- subsample_power_high_sf[i] + gain_pow2_sf + room;
+-
+- int new_summand_sf = subsample_power_high_sf[i]; /* + gain_pow2_sf; */
+- if (new_summand_sf > total_power_high_after_sf) {
+- total_power_high_after >>=
+- fMin(DFRACT_BITS - 1, new_summand_sf - total_power_high_after_sf);
+- total_power_high_after_sf = new_summand_sf;
+- } else if (new_summand_sf < total_power_high_after_sf) {
+- subsample_power_high[i] >>= total_power_high_after_sf - new_summand_sf;
+- }
+- total_power_high_after += subsample_power_high[i] >> preShift2;
+- }
+-
+- total_power_high_after_sf += preShift2;
+-
+- int sf2 = 0;
+- FIXP_DBL gain_adj_2 = FL2FX_DBL(0.5f);
+- int gain_adj_2_sf = 1;
+-
+- if ((total_power_high != (FIXP_DBL)0) &&
+- (total_power_high_after != (FIXP_DBL)0)) {
+- gain_adj_2 = fDivNorm(total_power_high, total_power_high_after, &sf2);
+- gain_adj_2_sf = total_power_high_sf - total_power_high_after_sf + sf2;
+- }
+-
+- FIXP_DBL gain_adj = sqrtFixp_lookup(gain_adj_2, &gain_adj_2_sf);
+- int gain_adj_sf = gain_adj_2_sf;
+-
+- for (i = 0; i < nbSubsample; ++i) {
+- gain[i] = fMult(gain[i], gain_adj);
+- gain_sf[i] += gain_adj_sf;
+-
+- /* limit gain */
+- if (gain_sf[i] > INTER_TES_SF_CHANGE) {
+- gain[i] = (FIXP_DBL)MAXVAL_DBL;
+- gain_sf[i] = INTER_TES_SF_CHANGE;
+- }
+- }
+-
+- for (i = 0; i < nbSubsample; ++i) {
+- /* equalize gain[]'s scale factors */
+- gain[i] >>= INTER_TES_SF_CHANGE - gain_sf[i];
+-
+- for (j = lowSubband; j < highSubband; j++) {
+- qmfReal[startPos + i][j] = fMult(qmfReal[startPos + i][j], gain[i]);
+- qmfImag[startPos + i][j] = fMult(qmfImag[startPos + i][j], gain[i]);
+- }
+- }
+- } else { /* gamma_idx == 0 */
+- /* Inter-TES is not active. Still perform the scale change to have a
+- * consistent scaling for all envelopes of this frame. */
+- for (i = 0; i < nbSubsample; ++i) {
+- for (j = lowSubband; j < highSubband; j++) {
+- qmfReal[startPos + i][j] >>= INTER_TES_SF_CHANGE;
+- qmfImag[startPos + i][j] >>= INTER_TES_SF_CHANGE;
+- }
+- }
+- }
+- C_ALLOC_SCRATCH_END(pTmp, ITES_TEMP, 1);
+-}
+-
+-/*!
+- \brief Apply spectral envelope to subband samples
+-
+- This function is called from sbr_dec.cpp in each frame.
+-
+- To enhance accuracy and due to the usage of tables for squareroots and
+- inverse, some calculations are performed with the operands being split
+- into mantissa and exponent. The variable names in the source code carry
+- the suffixes <em>_m</em> and <em>_e</em> respectively. The control data
+- in #hFrameData containts envelope data which is represented by this format but
+- stored in single words. (See requantizeEnvelopeData() for details). This data
+- is unpacked within calculateSbrEnvelope() to follow the described suffix
+- convention.
+-
+- The actual value (comparable to the corresponding float-variable in the
+- research-implementation) of a mantissa/exponent-pair can be calculated as
+-
+- \f$ value = value\_m * 2^{value\_e} \f$
+-
+- All energies and noise levels decoded from the bitstream suit for an
+- original signal magnitude of \f$\pm 32768 \f$ rather than \f$ \pm 1\f$.
+- Therefore, the scale factor <em>hb_scale</em> passed into this function will
+- be converted to an 'input exponent' (#input_e), which fits the internal
+- representation.
+-
+- Before the actual processing, an exponent #adj_e for resulting adjusted
+- samples is derived from the maximum reference energy.
+-
+- Then, for each envelope, the following steps are performed:
+-
+- \li Calculate energy in the signal to be adjusted. Depending on the the value
+- of #interpolFreq (interpolation mode), this is either done seperately for each
+- QMF-subband or for each SBR-band. The resulting energies are stored in
+- #nrgEst_m[#MAX_FREQ_COEFFS] (mantissas) and #nrgEst_e[#MAX_FREQ_COEFFS]
+- (exponents). \li Calculate gain and noise level for each subband:<br> \f$ gain
+- = \sqrt{ \frac{nrgRef}{nrgEst} \cdot (1 - noiseRatio) } \hspace{2cm} noise =
+- \sqrt{ nrgRef \cdot noiseRatio } \f$<br> where <em>noiseRatio</em> and
+- <em>nrgRef</em> are extracted from the bitstream and <em>nrgEst</em> is the
+- subband energy before adjustment. The resulting gains are stored in
+- #nrgGain_m[#MAX_FREQ_COEFFS] (mantissas) and #nrgGain_e[#MAX_FREQ_COEFFS]
+- (exponents), the noise levels are stored in #noiseLevel_m[#MAX_FREQ_COEFFS]
+- and #noiseLevel_e[#MAX_FREQ_COEFFS] (exponents). The sine levels are stored in
+- #nrgSine_m[#MAX_FREQ_COEFFS] and #nrgSine_e[#MAX_FREQ_COEFFS]. \li Noise
+- limiting: The gain for each subband is limited both absolutely and relatively
+- compared to the total gain over all subbands. \li Boost gain: Calculate and
+- apply boost factor for each limiter band in order to compensate for the energy
+- loss imposed by the limiting. \li Apply gains and add noise: The gains and
+- noise levels are applied to all timeslots of the current envelope. A short
+- FIR-filter (length 4 QMF-timeslots) can be used to smooth the sudden change at
+- the envelope borders. Each complex subband sample of the current timeslot is
+- multiplied by the smoothed gain, then random noise with the calculated level
+- is added.
+-
+- \note
+- To reduce the stack size, some of the local arrays could be located within
+- the time output buffer. Of the 512 samples temporarily available there,
+- about half the size is already used by #SBR_FRAME_DATA. A pointer to the
+- remaining free memory could be supplied by an additional argument to
+- calculateSbrEnvelope() in sbr_dec:
+-
+- \par
+- \code
+- calculateSbrEnvelope (&hSbrDec->sbrScaleFactor,
+- &hSbrDec->SbrCalculateEnvelope,
+- hHeaderData,
+- hFrameData,
+- QmfBufferReal,
+- QmfBufferImag,
+- timeOutPtr + sizeof(SBR_FRAME_DATA)/sizeof(Float) +
+- 1); \endcode
+-
+- \par
+- Within calculateSbrEnvelope(), some pointers could be defined instead of the
+- arrays #nrgRef_m, #nrgRef_e, #nrgEst_m, #nrgEst_e, #noiseLevel_m:
+-
+- \par
+- \code
+- fract* nrgRef_m = timeOutPtr;
+- SCHAR* nrgRef_e = nrgRef_m + MAX_FREQ_COEFFS;
+- fract* nrgEst_m = nrgRef_e + MAX_FREQ_COEFFS;
+- SCHAR* nrgEst_e = nrgEst_m + MAX_FREQ_COEFFS;
+- fract* noiseLevel_m = nrgEst_e + MAX_FREQ_COEFFS;
+- \endcode
+-
+- <br>
+-*/
+-void calculateSbrEnvelope(
+- QMF_SCALE_FACTOR *sbrScaleFactor, /*!< Scaling factors */
+- HANDLE_SBR_CALCULATE_ENVELOPE
+- h_sbr_cal_env, /*!< Handle to struct filled by the create-function */
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA hFrameData, /*!< Control data of current frame */
+- PVC_DYNAMIC_DATA *pPvcDynamicData,
+- FIXP_DBL *
+- *analysBufferReal, /*!< Real part of subband samples to be processed */
+- FIXP_DBL *
+- *analysBufferImag, /*!< Imag part of subband samples to be processed */
+- const int useLP,
+- FIXP_DBL *degreeAlias, /*!< Estimated aliasing for each QMF channel */
+- const UINT flags, const int frameErrorFlag) {
+- int c, i, i_stop, j, envNoise = 0;
+- UCHAR *borders = hFrameData->frameInfo.borders;
+- UCHAR *bordersPvc = hFrameData->frameInfo.pvcBorders;
+- int pvc_mode = pPvcDynamicData->pvc_mode;
+- int first_start =
+- ((pvc_mode > 0) ? bordersPvc[0] : borders[0]) * hHeaderData->timeStep;
+- FIXP_SGL *noiseLevels = hFrameData->sbrNoiseFloorLevel;
+- HANDLE_FREQ_BAND_DATA hFreq = &hHeaderData->freqBandData;
+- UCHAR **pFreqBandTable = hFreq->freqBandTable;
+- UCHAR *pFreqBandTableNoise = hFreq->freqBandTableNoise;
+-
+- int lowSubband = hFreq->lowSubband;
+- int highSubband = hFreq->highSubband;
+- int noSubbands = highSubband - lowSubband;
+-
+- /* old high subband before headerchange
+- we asume no headerchange here */
+- int ov_highSubband = hFreq->highSubband;
+-
+- int noNoiseBands = hFreq->nNfb;
+- UCHAR *noSubFrameBands = hFreq->nSfb;
+- int no_cols = hHeaderData->numberTimeSlots * hHeaderData->timeStep;
+-
+- SCHAR sineMapped[MAX_FREQ_COEFFS];
+- SCHAR ov_adj_e = SCALE2EXP(sbrScaleFactor->ov_hb_scale);
+- SCHAR adj_e = 0;
+- SCHAR output_e;
+- SCHAR final_e = 0;
+- /* inter-TES is active in one or more envelopes of the current SBR frame */
+- const int iTES_enable = hFrameData->iTESactive;
+- const int iTES_scale_change = (iTES_enable) ? INTER_TES_SF_CHANGE : 0;
+- SCHAR maxGainLimit_e = (frameErrorFlag) ? MAX_GAIN_CONCEAL_EXP : MAX_GAIN_EXP;
+-
+- UCHAR smooth_length = 0;
+-
+- FIXP_SGL *pIenv = hFrameData->iEnvelope;
+-
+- C_ALLOC_SCRATCH_START(useAliasReduction, UCHAR, 64)
+-
+- /* if values differ we had a headerchange; if old highband is bigger then new
+- one we need to patch overlap-highband-scaling for this frame (see use of
+- ov_highSubband) as overlap contains higher frequency components which would
+- get lost */
+- if (hFreq->highSubband < hFreq->ov_highSubband) {
+- ov_highSubband = hFreq->ov_highSubband;
+- }
+-
+- if (pvc_mode > 0) {
+- if (hFrameData->frameInfo.bordersNoise[0] > bordersPvc[0]) {
+- /* noise envelope of previous frame is trailing into current PVC frame */
+- envNoise = -1;
+- noiseLevels = h_sbr_cal_env->prevSbrNoiseFloorLevel;
+- noNoiseBands = h_sbr_cal_env->prevNNfb;
+- noSubFrameBands = h_sbr_cal_env->prevNSfb;
+- lowSubband = h_sbr_cal_env->prevLoSubband;
+- highSubband = h_sbr_cal_env->prevHiSubband;
+-
+- noSubbands = highSubband - lowSubband;
+- ov_highSubband = highSubband;
+- if (highSubband < h_sbr_cal_env->prev_ov_highSubband) {
+- ov_highSubband = h_sbr_cal_env->prev_ov_highSubband;
+- }
+-
+- pFreqBandTable[0] = h_sbr_cal_env->prevFreqBandTableLo;
+- pFreqBandTable[1] = h_sbr_cal_env->prevFreqBandTableHi;
+- pFreqBandTableNoise = h_sbr_cal_env->prevFreqBandTableNoise;
+- }
+-
+- mapSineFlagsPvc(pFreqBandTable[1], noSubFrameBands[1],
+- h_sbr_cal_env->harmFlagsPrev,
+- h_sbr_cal_env->harmFlagsPrevActive, sineMapped,
+- hFrameData->sinusoidal_position,
+- &h_sbr_cal_env->sinusoidal_positionPrev,
+- (borders[0] > bordersPvc[0]) ? 1 : 0);
+- } else {
+- /*
+- Extract sine flags for all QMF bands
+- */
+- mapSineFlags(pFreqBandTable[1], noSubFrameBands[1],
+- hFrameData->addHarmonics, h_sbr_cal_env->harmFlagsPrev,
+- h_sbr_cal_env->harmFlagsPrevActive,
+- hFrameData->frameInfo.tranEnv, sineMapped);
+- }
+-
+- /*
+- Scan for maximum in bufferd noise levels.
+- This is needed in case that we had strong noise in the previous frame
+- which is smoothed into the current frame.
+- The resulting exponent is used as start value for the maximum search
+- in reference energies
+- */
+- if (!useLP)
+- adj_e = h_sbr_cal_env->filtBufferNoise_e -
+- getScalefactor(h_sbr_cal_env->filtBufferNoise, noSubbands);
+-
+- /*
+- Scan for maximum reference energy to be able
+- to select appropriate values for adj_e and final_e.
+- */
+- if (pvc_mode > 0) {
+- INT maxSfbNrg_e = pPvcDynamicData->predEsg_expMax;
+-
+- /* Energy -> magnitude (sqrt halfens exponent) */
+- maxSfbNrg_e =
+- (maxSfbNrg_e + 1) >> 1; /* +1 to go safe (round to next higher int) */
+-
+- /* Some safety margin is needed for 2 reasons:
+- - The signal energy is not equally spread over all subband samples in
+- a specific sfb of an envelope (Nrg could be too high by a factor of
+- envWidth * sfbWidth)
+- - Smoothing can smear high gains of the previous envelope into the
+- current
+- */
+- maxSfbNrg_e += 6;
+-
+- adj_e = maxSfbNrg_e;
+- // final_e should not exist for PVC fixfix framing
+- } else {
+- for (i = 0; i < hFrameData->frameInfo.nEnvelopes; i++) {
+- INT maxSfbNrg_e =
+- -FRACT_BITS + NRG_EXP_OFFSET; /* start value for maximum search */
+-
+- /* Fetch frequency resolution for current envelope: */
+- for (j = noSubFrameBands[hFrameData->frameInfo.freqRes[i]]; j != 0; j--) {
+- maxSfbNrg_e = fixMax(maxSfbNrg_e, (INT)((LONG)(*pIenv++) & MASK_E));
+- }
+- maxSfbNrg_e -= NRG_EXP_OFFSET;
+-
+- /* Energy -> magnitude (sqrt halfens exponent) */
+- maxSfbNrg_e =
+- (maxSfbNrg_e + 1) >> 1; /* +1 to go safe (round to next higher int) */
+-
+- /* Some safety margin is needed for 2 reasons:
+- - The signal energy is not equally spread over all subband samples in
+- a specific sfb of an envelope (Nrg could be too high by a factor of
+- envWidth * sfbWidth)
+- - Smoothing can smear high gains of the previous envelope into the
+- current
+- */
+- maxSfbNrg_e += 6;
+-
+- if (borders[i] < hHeaderData->numberTimeSlots)
+- /* This envelope affects timeslots that belong to the output frame */
+- adj_e = fMax(maxSfbNrg_e, adj_e);
+-
+- if (borders[i + 1] > hHeaderData->numberTimeSlots)
+- /* This envelope affects timeslots after the output frame */
+- final_e = fMax(maxSfbNrg_e, final_e);
+- }
+- }
+- /*
+- Calculate adjustment factors and apply them for every envelope.
+- */
+- pIenv = hFrameData->iEnvelope;
+-
+- if (pvc_mode > 0) {
+- /* iterate over SBR time slots starting with bordersPvc[i] */
+- i = bordersPvc[0]; /* usually 0; can be >0 if switching from legacy SBR to
+- PVC */
+- i_stop = PVC_NTIMESLOT;
+- FDK_ASSERT(bordersPvc[hFrameData->frameInfo.nEnvelopes] == PVC_NTIMESLOT);
+- } else {
+- /* iterate over SBR envelopes starting with 0 */
+- i = 0;
+- i_stop = hFrameData->frameInfo.nEnvelopes;
+- }
+- for (; i < i_stop; i++) {
+- int k, noNoiseFlag;
+- SCHAR noise_e, input_e = SCALE2EXP(sbrScaleFactor->hb_scale);
+- C_ALLOC_SCRATCH_START(pNrgs, ENV_CALC_NRGS, 1);
+-
+- /*
+- Helper variables.
+- */
+- int start_pos, stop_pos, freq_res;
+- if (pvc_mode > 0) {
+- start_pos =
+- hHeaderData->timeStep *
+- i; /* Start-position in time (subband sample) for current envelope. */
+- stop_pos = hHeaderData->timeStep * (i + 1); /* Stop-position in time
+- (subband sample) for
+- current envelope. */
+- freq_res =
+- hFrameData->frameInfo
+- .freqRes[0]; /* Frequency resolution for current envelope. */
+- FDK_ASSERT(
+- freq_res ==
+- hFrameData->frameInfo.freqRes[hFrameData->frameInfo.nEnvelopes - 1]);
+- } else {
+- start_pos = hHeaderData->timeStep *
+- borders[i]; /* Start-position in time (subband sample) for
+- current envelope. */
+- stop_pos = hHeaderData->timeStep *
+- borders[i + 1]; /* Stop-position in time (subband sample) for
+- current envelope. */
+- freq_res =
+- hFrameData->frameInfo
+- .freqRes[i]; /* Frequency resolution for current envelope. */
+- }
+-
+- /* Always fully initialize the temporary energy table. This prevents
+- negative energies and extreme gain factors in cases where the number of
+- limiter bands exceeds the number of subbands. The latter can be caused by
+- undetected bit errors and is tested by some streams from the
+- certification set. */
+- FDKmemclear(pNrgs, sizeof(ENV_CALC_NRGS));
+-
+- if (pvc_mode > 0) {
+- /* get predicted energy values from PVC module */
+- expandPredEsg(pPvcDynamicData, i, (int)MAX_FREQ_COEFFS, pNrgs->nrgRef,
+- pNrgs->nrgRef_e);
+-
+- if (i == borders[0]) {
+- mapSineFlags(pFreqBandTable[1], noSubFrameBands[1],
+- hFrameData->addHarmonics, h_sbr_cal_env->harmFlagsPrev,
+- h_sbr_cal_env->harmFlagsPrevActive,
+- hFrameData->sinusoidal_position, sineMapped);
+- }
+-
+- if (i >= hFrameData->frameInfo.bordersNoise[envNoise + 1]) {
+- if (envNoise >= 0) {
+- noiseLevels += noNoiseBands; /* The noise floor data is stored in a
+- row [noiseFloor1 noiseFloor2...].*/
+- } else {
+- /* leave trailing noise envelope of past frame */
+- noNoiseBands = hFreq->nNfb;
+- noSubFrameBands = hFreq->nSfb;
+- noiseLevels = hFrameData->sbrNoiseFloorLevel;
+-
+- lowSubband = hFreq->lowSubband;
+- highSubband = hFreq->highSubband;
+-
+- noSubbands = highSubband - lowSubband;
+- ov_highSubband = highSubband;
+- if (highSubband < hFreq->ov_highSubband) {
+- ov_highSubband = hFreq->ov_highSubband;
+- }
+-
+- pFreqBandTable[0] = hFreq->freqBandTableLo;
+- pFreqBandTable[1] = hFreq->freqBandTableHi;
+- pFreqBandTableNoise = hFreq->freqBandTableNoise;
+- }
+- envNoise++;
+- }
+- } else {
+- /* If the start-pos of the current envelope equals the stop pos of the
+- current noise envelope, increase the pointer (i.e. choose the next
+- noise-floor).*/
+- if (borders[i] == hFrameData->frameInfo.bordersNoise[envNoise + 1]) {
+- noiseLevels += noNoiseBands; /* The noise floor data is stored in a row
+- [noiseFloor1 noiseFloor2...].*/
+- envNoise++;
+- }
+- }
+- if (i == hFrameData->frameInfo.tranEnv ||
+- i == h_sbr_cal_env->prevTranEnv) /* attack */
+- {
+- noNoiseFlag = 1;
+- if (!useLP) smooth_length = 0; /* No smoothing on attacks! */
+- } else {
+- noNoiseFlag = 0;
+- if (!useLP)
+- smooth_length = (1 - hHeaderData->bs_data.smoothingLength)
+- << 2; /* can become either 0 or 4 */
+- }
+-
+- /*
+- Energy estimation in transposed highband.
+- */
+- if (hHeaderData->bs_data.interpolFreq)
+- calcNrgPerSubband(analysBufferReal, (useLP) ? NULL : analysBufferImag,
+- lowSubband, highSubband, start_pos, stop_pos, input_e,
+- pNrgs->nrgEst, pNrgs->nrgEst_e);
+- else
+- calcNrgPerSfb(analysBufferReal, (useLP) ? NULL : analysBufferImag,
+- noSubFrameBands[freq_res], pFreqBandTable[freq_res],
+- start_pos, stop_pos, input_e, pNrgs->nrgEst,
+- pNrgs->nrgEst_e);
+-
+- /*
+- Calculate subband gains
+- */
+- {
+- UCHAR *table = pFreqBandTable[freq_res];
+- UCHAR *pUiNoise =
+- &pFreqBandTableNoise[1]; /*! Upper limit of the current noise floor
+- band. */
+-
+- FIXP_SGL *pNoiseLevels = noiseLevels;
+-
+- FIXP_DBL tmpNoise =
+- FX_SGL2FX_DBL((FIXP_SGL)((LONG)(*pNoiseLevels) & MASK_M));
+- SCHAR tmpNoise_e =
+- (UCHAR)((LONG)(*pNoiseLevels++) & MASK_E) - NOISE_EXP_OFFSET;
+-
+- int cc = 0;
+- c = 0;
+- if (pvc_mode > 0) {
+- for (j = 0; j < noSubFrameBands[freq_res]; j++) {
+- UCHAR sinePresentFlag = 0;
+- int li = table[j];
+- int ui = table[j + 1];
+-
+- for (k = li; k < ui; k++) {
+- sinePresentFlag |= (i >= sineMapped[cc]);
+- cc++;
+- }
+-
+- for (k = li; k < ui; k++) {
+- FIXP_DBL refNrg = pNrgs->nrgRef[k - lowSubband];
+- SCHAR refNrg_e = pNrgs->nrgRef_e[k - lowSubband];
+-
+- if (k >= *pUiNoise) {
+- tmpNoise =
+- FX_SGL2FX_DBL((FIXP_SGL)((LONG)(*pNoiseLevels) & MASK_M));
+- tmpNoise_e =
+- (SCHAR)((LONG)(*pNoiseLevels++) & MASK_E) - NOISE_EXP_OFFSET;
+-
+- pUiNoise++;
+- }
+-
+- FDK_ASSERT(k >= lowSubband);
+-
+- if (useLP) useAliasReduction[k - lowSubband] = !sinePresentFlag;
+-
+- pNrgs->nrgSine[c] = FL2FXCONST_DBL(0.0f);
+- pNrgs->nrgSine_e[c] = 0;
+-
+- calcSubbandGain(refNrg, refNrg_e, pNrgs, c, tmpNoise, tmpNoise_e,
+- sinePresentFlag, i >= sineMapped[c], noNoiseFlag);
+-
+- c++;
+- }
+- }
+- } else {
+- for (j = 0; j < noSubFrameBands[freq_res]; j++) {
+- FIXP_DBL refNrg = FX_SGL2FX_DBL((FIXP_SGL)((LONG)(*pIenv) & MASK_M));
+- SCHAR refNrg_e = (SCHAR)((LONG)(*pIenv) & MASK_E) - NRG_EXP_OFFSET;
+-
+- UCHAR sinePresentFlag = 0;
+- int li = table[j];
+- int ui = table[j + 1];
+-
+- for (k = li; k < ui; k++) {
+- sinePresentFlag |= (i >= sineMapped[cc]);
+- cc++;
+- }
+-
+- for (k = li; k < ui; k++) {
+- if (k >= *pUiNoise) {
+- tmpNoise =
+- FX_SGL2FX_DBL((FIXP_SGL)((LONG)(*pNoiseLevels) & MASK_M));
+- tmpNoise_e =
+- (SCHAR)((LONG)(*pNoiseLevels++) & MASK_E) - NOISE_EXP_OFFSET;
+-
+- pUiNoise++;
+- }
+-
+- FDK_ASSERT(k >= lowSubband);
+-
+- if (useLP) useAliasReduction[k - lowSubband] = !sinePresentFlag;
+-
+- pNrgs->nrgSine[c] = FL2FXCONST_DBL(0.0f);
+- pNrgs->nrgSine_e[c] = 0;
+-
+- calcSubbandGain(refNrg, refNrg_e, pNrgs, c, tmpNoise, tmpNoise_e,
+- sinePresentFlag, i >= sineMapped[c], noNoiseFlag);
+-
+- pNrgs->nrgRef[c] = refNrg;
+- pNrgs->nrgRef_e[c] = refNrg_e;
+-
+- c++;
+- }
+- pIenv++;
+- }
+- }
+- }
+-
+- /*
+- Noise limiting
+- */
+-
+- for (c = 0; c < hFreq->noLimiterBands; c++) {
+- FIXP_DBL sumRef, boostGain, maxGain;
+- FIXP_DBL accu = FL2FXCONST_DBL(0.0f);
+- SCHAR sumRef_e, boostGain_e, maxGain_e, accu_e = 0;
+- int maxGainLimGainSum_e = 0;
+-
+- calcAvgGain(pNrgs, hFreq->limiterBandTable[c],
+- hFreq->limiterBandTable[c + 1], &sumRef, &sumRef_e, &maxGain,
+- &maxGain_e);
+-
+- /* Multiply maxGain with limiterGain: */
+- maxGain = fMult(
+- maxGain,
+- FDK_sbrDecoder_sbr_limGains_m[hHeaderData->bs_data.limiterGains]);
+- /* maxGain_e +=
+- * FDK_sbrDecoder_sbr_limGains_e[hHeaderData->bs_data.limiterGains]; */
+- /* The addition of maxGain_e and FDK_sbrDecoder_sbr_limGains_e[3] might
+- yield values greater than 127 which doesn't fit into an SCHAR! In these
+- rare situations limit maxGain_e to 127.
+- */
+- maxGainLimGainSum_e =
+- maxGain_e +
+- FDK_sbrDecoder_sbr_limGains_e[hHeaderData->bs_data.limiterGains];
+- maxGain_e =
+- (maxGainLimGainSum_e > 127) ? (SCHAR)127 : (SCHAR)maxGainLimGainSum_e;
+-
+- /* Scale mantissa of MaxGain into range between 0.5 and 1: */
+- if (maxGain == FL2FXCONST_DBL(0.0f))
+- maxGain_e = -FRACT_BITS;
+- else {
+- SCHAR charTemp = CountLeadingBits(maxGain);
+- maxGain_e -= charTemp;
+- maxGain <<= (int)charTemp;
+- }
+-
+- if (maxGain_e >= maxGainLimit_e) { /* upper limit (e.g. 96 dB) */
+- maxGain = FL2FXCONST_DBL(0.5f);
+- maxGain_e = maxGainLimit_e;
+- }
+-
+- /* Every subband gain is compared to the scaled "average gain"
+- and limited if necessary: */
+- for (k = hFreq->limiterBandTable[c]; k < hFreq->limiterBandTable[c + 1];
+- k++) {
+- if ((pNrgs->nrgGain_e[k] > maxGain_e) ||
+- (pNrgs->nrgGain_e[k] == maxGain_e && pNrgs->nrgGain[k] > maxGain)) {
+- FIXP_DBL noiseAmp;
+- SCHAR noiseAmp_e;
+-
+- FDK_divide_MantExp(maxGain, maxGain_e, pNrgs->nrgGain[k],
+- pNrgs->nrgGain_e[k], &noiseAmp, &noiseAmp_e);
+- pNrgs->noiseLevel[k] = fMult(pNrgs->noiseLevel[k], noiseAmp);
+- pNrgs->noiseLevel_e[k] += noiseAmp_e;
+- pNrgs->nrgGain[k] = maxGain;
+- pNrgs->nrgGain_e[k] = maxGain_e;
+- }
+- }
+-
+- /* -- Boost gain
+- Calculate and apply boost factor for each limiter band:
+- 1. Check how much energy would be present when using the limited gain
+- 2. Calculate boost factor by comparison with reference energy
+- 3. Apply boost factor to compensate for the energy loss due to limiting
+- */
+- for (k = hFreq->limiterBandTable[c]; k < hFreq->limiterBandTable[c + 1];
+- k++) {
+- /* 1.a Add energy of adjusted signal (using preliminary gain) */
+- FIXP_DBL tmp = fMult(pNrgs->nrgGain[k], pNrgs->nrgEst[k]);
+- SCHAR tmp_e = pNrgs->nrgGain_e[k] + pNrgs->nrgEst_e[k];
+- FDK_add_MantExp(tmp, tmp_e, accu, accu_e, &accu, &accu_e);
+-
+- /* 1.b Add sine energy (if present) */
+- if (pNrgs->nrgSine[k] != FL2FXCONST_DBL(0.0f)) {
+- FDK_add_MantExp(pNrgs->nrgSine[k], pNrgs->nrgSine_e[k], accu, accu_e,
+- &accu, &accu_e);
+- } else {
+- /* 1.c Add noise energy (if present) */
+- if (noNoiseFlag == 0) {
+- FDK_add_MantExp(pNrgs->noiseLevel[k], pNrgs->noiseLevel_e[k], accu,
+- accu_e, &accu, &accu_e);
+- }
+- }
+- }
+-
+- /* 2.a Calculate ratio of wanted energy and accumulated energy */
+- if (accu == (FIXP_DBL)0) { /* If divisor is 0, limit quotient to +4 dB */
+- boostGain = FL2FXCONST_DBL(0.6279716f);
+- boostGain_e = 2;
+- } else {
+- INT div_e;
+- boostGain = fDivNorm(sumRef, accu, &div_e);
+- boostGain_e = sumRef_e - accu_e + div_e;
+- }
+-
+- /* 2.b Result too high? --> Limit the boost factor to +4 dB */
+- if ((boostGain_e > 3) ||
+- (boostGain_e == 2 && boostGain > FL2FXCONST_DBL(0.6279716f)) ||
+- (boostGain_e == 3 && boostGain > FL2FXCONST_DBL(0.3139858f))) {
+- boostGain = FL2FXCONST_DBL(0.6279716f);
+- boostGain_e = 2;
+- }
+- /* 3. Multiply all signal components with the boost factor */
+- for (k = hFreq->limiterBandTable[c]; k < hFreq->limiterBandTable[c + 1];
+- k++) {
+- pNrgs->nrgGain[k] = fMultDiv2(pNrgs->nrgGain[k], boostGain);
+- pNrgs->nrgGain_e[k] = pNrgs->nrgGain_e[k] + boostGain_e + 1;
+-
+- pNrgs->nrgSine[k] = fMultDiv2(pNrgs->nrgSine[k], boostGain);
+- pNrgs->nrgSine_e[k] = pNrgs->nrgSine_e[k] + boostGain_e + 1;
+-
+- pNrgs->noiseLevel[k] = fMultDiv2(pNrgs->noiseLevel[k], boostGain);
+- pNrgs->noiseLevel_e[k] = pNrgs->noiseLevel_e[k] + boostGain_e + 1;
+- }
+- }
+- /* End of noise limiting */
+-
+- if (useLP)
+- aliasingReduction(degreeAlias + lowSubband, pNrgs, useAliasReduction,
+- noSubbands);
+-
+- /* For the timeslots within the range for the output frame,
+- use the same scale for the noise levels.
+- Drawback: If the envelope exceeds the frame border, the noise levels
+- will have to be rescaled later to fit final_e of
+- the gain-values.
+- */
+- noise_e = (start_pos < no_cols) ? adj_e : final_e;
+-
+- /*
+- Convert energies to amplitude levels
+- */
+- for (k = 0; k < noSubbands; k++) {
+- FDK_sqrt_MantExp(&pNrgs->nrgSine[k], &pNrgs->nrgSine_e[k], &noise_e);
+- FDK_sqrt_MantExp(&pNrgs->nrgGain[k], &pNrgs->nrgGain_e[k],
+- &pNrgs->nrgGain_e[k]);
+- FDK_sqrt_MantExp(&pNrgs->noiseLevel[k], &pNrgs->noiseLevel_e[k],
+- &noise_e);
+- }
+-
+- /*
+- Apply calculated gains and adaptive noise
+- */
+-
+- /* assembleHfSignals() */
+- {
+- int scale_change, sc_change;
+- FIXP_SGL smooth_ratio;
+- int filtBufferNoiseShift = 0;
+-
+- /* Initialize smoothing buffers with the first valid values */
+- if (h_sbr_cal_env->startUp) {
+- if (!useLP) {
+- h_sbr_cal_env->filtBufferNoise_e = noise_e;
+-
+- FDKmemcpy(h_sbr_cal_env->filtBuffer_e, pNrgs->nrgGain_e,
+- noSubbands * sizeof(SCHAR));
+- FDKmemcpy(h_sbr_cal_env->filtBufferNoise, pNrgs->noiseLevel,
+- noSubbands * sizeof(FIXP_DBL));
+- FDKmemcpy(h_sbr_cal_env->filtBuffer, pNrgs->nrgGain,
+- noSubbands * sizeof(FIXP_DBL));
+- }
+- h_sbr_cal_env->startUp = 0;
+- }
+-
+- if (!useLP) {
+- equalizeFiltBufferExp(h_sbr_cal_env->filtBuffer, /* buffered */
+- h_sbr_cal_env->filtBuffer_e, /* buffered */
+- pNrgs->nrgGain, /* current */
+- pNrgs->nrgGain_e, /* current */
+- noSubbands);
+-
+- /* Adapt exponent of buffered noise levels to the current exponent
+- so they can easily be smoothed */
+- if ((h_sbr_cal_env->filtBufferNoise_e - noise_e) >= 0) {
+- int shift = fixMin(DFRACT_BITS - 1,
+- (int)(h_sbr_cal_env->filtBufferNoise_e - noise_e));
+- for (k = 0; k < noSubbands; k++)
+- h_sbr_cal_env->filtBufferNoise[k] <<= shift;
+- } else {
+- int shift =
+- fixMin(DFRACT_BITS - 1,
+- -(int)(h_sbr_cal_env->filtBufferNoise_e - noise_e));
+- for (k = 0; k < noSubbands; k++)
+- h_sbr_cal_env->filtBufferNoise[k] >>= shift;
+- }
+-
+- h_sbr_cal_env->filtBufferNoise_e = noise_e;
+- }
+-
+- /* find best scaling! */
+- scale_change = -(DFRACT_BITS - 1);
+- for (k = 0; k < noSubbands; k++) {
+- scale_change = fixMax(scale_change, (int)pNrgs->nrgGain_e[k]);
+- }
+- sc_change = (start_pos < no_cols) ? adj_e - input_e : final_e - input_e;
+-
+- if ((scale_change - sc_change + 1) < 0)
+- scale_change -= (scale_change - sc_change + 1);
+-
+- scale_change = (scale_change - sc_change) + 1;
+-
+- for (k = 0; k < noSubbands; k++) {
+- int sc = scale_change - pNrgs->nrgGain_e[k] + (sc_change - 1);
+- pNrgs->nrgGain[k] >>= sc;
+- pNrgs->nrgGain_e[k] += sc;
+- }
+-
+- if (!useLP) {
+- for (k = 0; k < noSubbands; k++) {
+- int sc =
+- scale_change - h_sbr_cal_env->filtBuffer_e[k] + (sc_change - 1);
+- h_sbr_cal_env->filtBuffer[k] >>= sc;
+- }
+- }
+-
+- for (j = start_pos; j < stop_pos; j++) {
+- /* This timeslot is located within the first part of the processing
+- buffer and will be fed into the QMF-synthesis for the current frame.
+- adj_e - input_e
+- This timeslot will not yet be fed into the QMF so we do not care
+- about the adj_e.
+- sc_change = final_e - input_e
+- */
+- if ((j == no_cols) && (start_pos < no_cols)) {
+- int shift = (int)(noise_e - final_e);
+- if (!useLP)
+- filtBufferNoiseShift = shift; /* shifting of
+- h_sbr_cal_env->filtBufferNoise[k]
+- will be applied in function
+- adjustTimeSlotHQ() */
+- if (shift >= 0) {
+- shift = fixMin(DFRACT_BITS - 1, shift);
+- for (k = 0; k < noSubbands; k++) {
+- pNrgs->nrgSine[k] <<= shift;
+- pNrgs->noiseLevel[k] <<= shift;
+- /*
+- if (!useLP)
+- h_sbr_cal_env->filtBufferNoise[k] <<= shift;
+- */
+- }
+- } else {
+- shift = fixMin(DFRACT_BITS - 1, -shift);
+- for (k = 0; k < noSubbands; k++) {
+- pNrgs->nrgSine[k] >>= shift;
+- pNrgs->noiseLevel[k] >>= shift;
+- /*
+- if (!useLP)
+- h_sbr_cal_env->filtBufferNoise[k] >>= shift;
+- */
+- }
+- }
+-
+- /* update noise scaling */
+- noise_e = final_e;
+- if (!useLP)
+- h_sbr_cal_env->filtBufferNoise_e =
+- noise_e; /* scaling value unused! */
+-
+- /* update gain buffer*/
+- sc_change -= (final_e - input_e);
+-
+- if (sc_change < 0) {
+- for (k = 0; k < noSubbands; k++) {
+- pNrgs->nrgGain[k] >>= -sc_change;
+- pNrgs->nrgGain_e[k] += -sc_change;
+- }
+- if (!useLP) {
+- for (k = 0; k < noSubbands; k++) {
+- h_sbr_cal_env->filtBuffer[k] >>= -sc_change;
+- }
+- }
+- } else {
+- scale_change += sc_change;
+- }
+-
+- } /* if */
+-
+- if (!useLP) {
+- /* Prevent the smoothing filter from running on constant levels */
+- if (j - start_pos < smooth_length)
+- smooth_ratio = FDK_sbrDecoder_sbr_smoothFilter[j - start_pos];
+- else
+- smooth_ratio = FL2FXCONST_SGL(0.0f);
+-
+- if (iTES_enable) {
+- /* adjustTimeSlotHQ() without adding of additional harmonics */
+- adjustTimeSlotHQ_GainAndNoise(
+- &analysBufferReal[j][lowSubband],
+- &analysBufferImag[j][lowSubband], h_sbr_cal_env, pNrgs,
+- lowSubband, noSubbands, fMin(scale_change, DFRACT_BITS - 1),
+- smooth_ratio, noNoiseFlag, filtBufferNoiseShift);
+- } else {
+- adjustTimeSlotHQ(&analysBufferReal[j][lowSubband],
+- &analysBufferImag[j][lowSubband], h_sbr_cal_env,
+- pNrgs, lowSubband, noSubbands,
+- fMin(scale_change, DFRACT_BITS - 1), smooth_ratio,
+- noNoiseFlag, filtBufferNoiseShift);
+- }
+- } else {
+- FDK_ASSERT(!iTES_enable); /* not supported */
+- if (flags & SBRDEC_ELD_GRID) {
+- /* FDKmemset(analysBufferReal[j], 0, 64 * sizeof(FIXP_DBL)); */
+- adjustTimeSlot_EldGrid(&analysBufferReal[j][lowSubband], pNrgs,
+- &h_sbr_cal_env->harmIndex, lowSubband,
+- noSubbands,
+- fMin(scale_change, DFRACT_BITS - 1),
+- noNoiseFlag, &h_sbr_cal_env->phaseIndex,
+- EXP2SCALE(adj_e) - sbrScaleFactor->lb_scale);
+- } else {
+- adjustTimeSlotLC(&analysBufferReal[j][lowSubband], pNrgs,
+- &h_sbr_cal_env->harmIndex, lowSubband, noSubbands,
+- fMin(scale_change, DFRACT_BITS - 1), noNoiseFlag,
+- &h_sbr_cal_env->phaseIndex);
+- }
+- }
+- /* In case the envelope spans accross the no_cols border both exponents
+- * are needed. */
+- /* nrgGain_e[0...(noSubbands-1)] are equalized by
+- * equalizeFiltBufferExp() */
+- pNrgs->exponent[(j < no_cols) ? 0 : 1] =
+- (SCHAR)((15 - sbrScaleFactor->hb_scale) + pNrgs->nrgGain_e[0] + 1 -
+- scale_change);
+- } /* for */
+-
+- if (iTES_enable) {
+- apply_inter_tes(
+- analysBufferReal, /* pABufR, */
+- analysBufferImag, /* pABufI, */
+- sbrScaleFactor, pNrgs->exponent, hHeaderData->timeStep, start_pos,
+- stop_pos, lowSubband, noSubbands,
+- hFrameData
+- ->interTempShapeMode[i] /* frameData->interTempShapeMode[env] */
+- );
+-
+- /* add additional harmonics */
+- for (j = start_pos; j < stop_pos; j++) {
+- /* match exponent of additional harmonics to scale change of QMF data
+- * caused by apply_inter_tes() */
+- scale_change = 0;
+-
+- if ((start_pos <= no_cols) && (stop_pos > no_cols)) {
+- /* Scaling of analysBuffers was potentially changed within this
+- envelope. The pNrgs->nrgSine_e match the second part of the
+- envelope. For (j<=no_cols) the exponent of the sine energies has
+- to be adapted. */
+- scale_change = pNrgs->exponent[1] - pNrgs->exponent[0];
+- }
+-
+- adjustTimeSlotHQ_AddHarmonics(
+- &analysBufferReal[j][lowSubband],
+- &analysBufferImag[j][lowSubband], h_sbr_cal_env, pNrgs,
+- lowSubband, noSubbands,
+- -iTES_scale_change + ((j < no_cols) ? scale_change : 0));
+- }
+- }
+-
+- if (!useLP) {
+- /* Update time-smoothing-buffers for gains and noise levels
+- The gains and the noise values of the current envelope are copied
+- into the buffer. This has to be done at the end of each envelope as
+- the values are required for a smooth transition to the next envelope.
+- */
+- FDKmemcpy(h_sbr_cal_env->filtBuffer, pNrgs->nrgGain,
+- noSubbands * sizeof(FIXP_DBL));
+- FDKmemcpy(h_sbr_cal_env->filtBuffer_e, pNrgs->nrgGain_e,
+- noSubbands * sizeof(SCHAR));
+- FDKmemcpy(h_sbr_cal_env->filtBufferNoise, pNrgs->noiseLevel,
+- noSubbands * sizeof(FIXP_DBL));
+- }
+- }
+- C_ALLOC_SCRATCH_END(pNrgs, ENV_CALC_NRGS, 1);
+- }
+-
+- /* adapt adj_e to the scale change caused by apply_inter_tes() */
+- adj_e += iTES_scale_change;
+-
+- /* Rescale output samples */
+- {
+- FIXP_DBL maxVal;
+- int ov_reserve, reserve;
+-
+- /* Determine headroom in old adjusted samples */
+- maxVal =
+- maxSubbandSample(analysBufferReal, (useLP) ? NULL : analysBufferImag,
+- lowSubband, ov_highSubband, 0, first_start);
+-
+- ov_reserve = fNorm(maxVal);
+-
+- /* Determine headroom in new adjusted samples */
+- maxVal =
+- maxSubbandSample(analysBufferReal, (useLP) ? NULL : analysBufferImag,
+- lowSubband, highSubband, first_start, no_cols);
+-
+- reserve = fNorm(maxVal);
+-
+- /* Determine common output exponent */
+- output_e = fMax(ov_adj_e - ov_reserve, adj_e - reserve);
+-
+- /* Rescale old samples */
+- rescaleSubbandSamples(analysBufferReal, (useLP) ? NULL : analysBufferImag,
+- lowSubband, ov_highSubband, 0, first_start,
+- ov_adj_e - output_e);
+-
+- /* Rescale new samples */
+- rescaleSubbandSamples(analysBufferReal, (useLP) ? NULL : analysBufferImag,
+- lowSubband, highSubband, first_start, no_cols,
+- adj_e - output_e);
+- }
+-
+- /* Update hb_scale */
+- sbrScaleFactor->hb_scale = EXP2SCALE(output_e);
+-
+- /* Save the current final exponent for the next frame: */
+- /* adapt final_e to the scale change caused by apply_inter_tes() */
+- sbrScaleFactor->ov_hb_scale = EXP2SCALE(final_e + iTES_scale_change);
+-
+- /* We need to remember to the next frame that the transient
+- will occur in the first envelope (if tranEnv == nEnvelopes). */
+- if (hFrameData->frameInfo.tranEnv == hFrameData->frameInfo.nEnvelopes)
+- h_sbr_cal_env->prevTranEnv = 0;
+- else
+- h_sbr_cal_env->prevTranEnv = -1;
+-
+- if (pvc_mode > 0) {
+- /* Not more than just the last noise envelope reaches into the next PVC
+- frame! This should be true because bs_noise_position is <= 15 */
+- FDK_ASSERT(hFrameData->frameInfo
+- .bordersNoise[hFrameData->frameInfo.nNoiseEnvelopes - 1] <
+- PVC_NTIMESLOT);
+- if (hFrameData->frameInfo
+- .bordersNoise[hFrameData->frameInfo.nNoiseEnvelopes] >
+- PVC_NTIMESLOT) {
+- FDK_ASSERT(noiseLevels ==
+- (hFrameData->sbrNoiseFloorLevel +
+- (hFrameData->frameInfo.nNoiseEnvelopes - 1) * noNoiseBands));
+- h_sbr_cal_env->prevNNfb = noNoiseBands;
+-
+- h_sbr_cal_env->prevNSfb[0] = noSubFrameBands[0];
+- h_sbr_cal_env->prevNSfb[1] = noSubFrameBands[1];
+-
+- h_sbr_cal_env->prevLoSubband = lowSubband;
+- h_sbr_cal_env->prevHiSubband = highSubband;
+- h_sbr_cal_env->prev_ov_highSubband = ov_highSubband;
+-
+- FDKmemcpy(h_sbr_cal_env->prevFreqBandTableLo, pFreqBandTable[0],
+- noSubFrameBands[0] + 1);
+- FDKmemcpy(h_sbr_cal_env->prevFreqBandTableHi, pFreqBandTable[1],
+- noSubFrameBands[1] + 1);
+- FDKmemcpy(h_sbr_cal_env->prevFreqBandTableNoise,
+- hFreq->freqBandTableNoise, sizeof(hFreq->freqBandTableNoise));
+-
+- FDKmemcpy(h_sbr_cal_env->prevSbrNoiseFloorLevel, noiseLevels,
+- MAX_NOISE_COEFFS * sizeof(FIXP_SGL));
+- }
+- }
+-
+- C_ALLOC_SCRATCH_END(useAliasReduction, UCHAR, 64)
+-}
+-
+-/*!
+- \brief Create envelope instance
+-
+- Must be called once for each channel before calculateSbrEnvelope() can be
+- used.
+-
+- \return errorCode, 0 if successful
+-*/
+-SBR_ERROR
+-createSbrEnvelopeCalc(
+- HANDLE_SBR_CALCULATE_ENVELOPE hs, /*!< pointer to envelope instance */
+- HANDLE_SBR_HEADER_DATA
+- hHeaderData, /*!< static SBR control data, initialized with defaults */
+- const int chan, /*!< Channel for which to assign buffers */
+- const UINT flags) {
+- SBR_ERROR err = SBRDEC_OK;
+- int i;
+-
+- /* Clear previous missing harmonics flags */
+- for (i = 0; i < ADD_HARMONICS_FLAGS_SIZE; i++) {
+- hs->harmFlagsPrev[i] = 0;
+- hs->harmFlagsPrevActive[i] = 0;
+- }
+- hs->harmIndex = 0;
+-
+- FDKmemclear(hs->prevSbrNoiseFloorLevel, sizeof(hs->prevSbrNoiseFloorLevel));
+- hs->prevNNfb = 0;
+- FDKmemclear(hs->prevFreqBandTableNoise, sizeof(hs->prevFreqBandTableNoise));
+- hs->sinusoidal_positionPrev = 0;
+-
+- /*
+- Setup pointers for time smoothing.
+- The buffer itself will be initialized later triggered by the startUp-flag.
+- */
+- hs->prevTranEnv = -1;
+-
+- /* initialization */
+- resetSbrEnvelopeCalc(hs);
+-
+- if (chan == 0) { /* do this only once */
+- err = resetFreqBandTables(hHeaderData, flags);
+- }
+-
+- return err;
+-}
+-
+-/*!
+- \brief Create envelope instance
+-
+- Must be called once for each channel before calculateSbrEnvelope() can be
+- used.
+-
+- \return errorCode, 0 if successful
+-*/
+-int deleteSbrEnvelopeCalc(HANDLE_SBR_CALCULATE_ENVELOPE hs) { return 0; }
+-
+-/*!
+- \brief Reset envelope instance
+-
+- This function must be called for each channel on a change of configuration.
+- Note that resetFreqBandTables should also be called in this case.
+-
+- \return errorCode, 0 if successful
+-*/
+-void resetSbrEnvelopeCalc(
+- HANDLE_SBR_CALCULATE_ENVELOPE hCalEnv) /*!< pointer to envelope instance */
+-{
+- hCalEnv->phaseIndex = 0;
+-
+- /* Noise exponent needs to be reset because the output exponent for the next
+- * frame depends on it */
+- hCalEnv->filtBufferNoise_e = 0;
+-
+- hCalEnv->startUp = 1;
+-}
+-
+-/*!
+- \brief Equalize exponents of the buffered gain values and the new ones
+-
+- After equalization of exponents, the FIR-filter addition for smoothing
+- can be performed.
+- This function is called once for each envelope before adjusting.
+-*/
+-static void equalizeFiltBufferExp(
+- FIXP_DBL *filtBuffer, /*!< bufferd gains */
+- SCHAR *filtBuffer_e, /*!< exponents of bufferd gains */
+- FIXP_DBL *nrgGain, /*!< gains for current envelope */
+- SCHAR *nrgGain_e, /*!< exponents of gains for current envelope */
+- int subbands) /*!< Number of QMF subbands */
+-{
+- int band;
+- int diff;
+-
+- for (band = 0; band < subbands; band++) {
+- diff = (int)(nrgGain_e[band] - filtBuffer_e[band]);
+- if (diff > 0) {
+- filtBuffer[band] >>=
+- diff; /* Compensate for the scale change by shifting the mantissa. */
+- filtBuffer_e[band] += diff; /* New gain is bigger, use its exponent */
+- } else if (diff < 0) {
+- /* The buffered gains seem to be larger, but maybe there
+- are some unused bits left in the mantissa */
+-
+- int reserve = CntLeadingZeros(fixp_abs(filtBuffer[band])) - 1;
+-
+- if ((-diff) <= reserve) {
+- /* There is enough space in the buffered mantissa so
+- that we can take the new exponent as common.
+- */
+- filtBuffer[band] <<= (-diff);
+- filtBuffer_e[band] += diff; /* becomes equal to *ptrNewExp */
+- } else {
+- filtBuffer[band] <<=
+- reserve; /* Shift the mantissa as far as possible: */
+- filtBuffer_e[band] -= reserve; /* Compensate in the exponent: */
+-
+- /* For the remaining difference, change the new gain value */
+- diff = fixMin(-(reserve + diff), DFRACT_BITS - 1);
+- nrgGain[band] >>= diff;
+- nrgGain_e[band] += diff;
+- }
+- }
+- }
+-}
+-
+-/*!
+- \brief Shift left the mantissas of all subband samples
+- in the giventime and frequency range by the specified number of bits.
+-
+- This function is used to rescale the audio data in the overlap buffer
+- which has already been envelope adjusted with the last frame.
+-*/
+-void rescaleSubbandSamples(
+- FIXP_DBL **re, /*!< Real part of input and output subband samples */
+- FIXP_DBL **im, /*!< Imaginary part of input and output subband samples */
+- int lowSubband, /*!< Begin of frequency range to process */
+- int highSubband, /*!< End of frequency range to process */
+- int start_pos, /*!< Begin of time rage (QMF-timeslot) */
+- int next_pos, /*!< End of time rage (QMF-timeslot) */
+- int shift) /*!< number of bits to shift */
+-{
+- int width = highSubband - lowSubband;
+-
+- if ((width > 0) && (shift != 0)) {
+- if (im != NULL) {
+- for (int l = start_pos; l < next_pos; l++) {
+- scaleValues(&re[l][lowSubband], width, shift);
+- scaleValues(&im[l][lowSubband], width, shift);
+- }
+- } else {
+- for (int l = start_pos; l < next_pos; l++) {
+- scaleValues(&re[l][lowSubband], width, shift);
+- }
+- }
+- }
+-}
+-
+-static inline FIXP_DBL FDK_get_maxval_real(FIXP_DBL maxVal, FIXP_DBL *reTmp,
+- INT width) {
+- maxVal = (FIXP_DBL)0;
+- while (width-- != 0) {
+- FIXP_DBL tmp = *(reTmp++);
+- maxVal |= (FIXP_DBL)((LONG)(tmp) ^ ((LONG)tmp >> (DFRACT_BITS - 1)));
+- }
+-
+- return maxVal;
+-}
+-
+-/*!
+- \brief Determine headroom for shifting
+-
+- Determine by how much the spectrum can be shifted left
+- for better accuracy in later processing.
+-
+- \return Number of free bits in the biggest spectral value
+-*/
+-
+-FIXP_DBL maxSubbandSample(
+- FIXP_DBL **re, /*!< Real part of input and output subband samples */
+- FIXP_DBL **im, /*!< Real part of input and output subband samples */
+- int lowSubband, /*!< Begin of frequency range to process */
+- int highSubband, /*!< Number of QMF bands to process */
+- int start_pos, /*!< Begin of time rage (QMF-timeslot) */
+- int next_pos /*!< End of time rage (QMF-timeslot) */
+-) {
+- FIXP_DBL maxVal = FL2FX_DBL(0.0f);
+- unsigned int width = highSubband - lowSubband;
+-
+- FDK_ASSERT(width <= (64));
+-
+- if (width > 0) {
+- if (im != NULL) {
+- for (int l = start_pos; l < next_pos; l++) {
+- int k = width;
+- FIXP_DBL *reTmp = &re[l][lowSubband];
+- FIXP_DBL *imTmp = &im[l][lowSubband];
+- do {
+- FIXP_DBL tmp1 = *(reTmp++);
+- FIXP_DBL tmp2 = *(imTmp++);
+- maxVal |=
+- (FIXP_DBL)((LONG)(tmp1) ^ ((LONG)tmp1 >> (DFRACT_BITS - 1)));
+- maxVal |=
+- (FIXP_DBL)((LONG)(tmp2) ^ ((LONG)tmp2 >> (DFRACT_BITS - 1)));
+- } while (--k != 0);
+- }
+- } else {
+- for (int l = start_pos; l < next_pos; l++) {
+- maxVal |= FDK_get_maxval_real(maxVal, &re[l][lowSubband], width);
+- }
+- }
+- }
+-
+- if (maxVal > (FIXP_DBL)0) {
+- /* For negative input values, maxVal is too small by 1. Add 1 only when
+- * necessary: if maxVal is a power of 2 */
+- FIXP_DBL lowerPow2 =
+- (FIXP_DBL)(1 << (DFRACT_BITS - 1 - CntLeadingZeros(maxVal)));
+- if (maxVal == lowerPow2) maxVal += (FIXP_DBL)1;
+- }
+-
+- return (maxVal);
+-}
+-
+-/* #define SHIFT_BEFORE_SQUARE (3) */ /* (7/2) */
+-/* Avoid assertion failures triggerd by overflows which occured in robustness
+- tests. Setting the SHIFT_BEFORE_SQUARE to 4 has negligible effect on (USAC)
+- conformance results. */
+-#define SHIFT_BEFORE_SQUARE (4) /* ((8 - 0) / 2) */
+-
+-/*!<
+- If the accumulator does not provide enough overflow bits or
+- does not provide a high dynamic range, the below energy calculation
+- requires an additional shift operation for each sample.
+- On the other hand, doing the shift allows using a single-precision
+- multiplication for the square (at least 16bit x 16bit).
+- For even values of OVRFLW_BITS (0, 2, 4, 6), saturated arithmetic
+- is required for the energy accumulation.
+- Theoretically, the sample-squares can sum up to a value of 76,
+- requiring 7 overflow bits. However since such situations are *very*
+- rare, accu can be limited to 64.
+- In case native saturated arithmetic is not available, overflows
+- can be prevented by replacing the above #define by
+- #define SHIFT_BEFORE_SQUARE ((8 - OVRFLW_BITS) / 2)
+- which will result in slightly reduced accuracy.
+-*/
+-
+-/*!
+- \brief Estimates the mean energy of each filter-bank channel for the
+- duration of the current envelope
+-
+- This function is used when interpolFreq is true.
+-*/
+-static void calcNrgPerSubband(
+- FIXP_DBL **analysBufferReal, /*!< Real part of subband samples */
+- FIXP_DBL **analysBufferImag, /*!< Imaginary part of subband samples */
+- int lowSubband, /*!< Begin of the SBR frequency range */
+- int highSubband, /*!< High end of the SBR frequency range */
+- int start_pos, /*!< First QMF-slot of current envelope */
+- int next_pos, /*!< Last QMF-slot of current envelope + 1 */
+- SCHAR frameExp, /*!< Common exponent for all input samples */
+- FIXP_DBL *nrgEst, /*!< resulting Energy (0..1) */
+- SCHAR *nrgEst_e) /*!< Exponent of resulting Energy */
+-{
+- FIXP_SGL invWidth;
+- SCHAR preShift;
+- SCHAR shift;
+- FIXP_DBL sum;
+- int k;
+-
+- /* Divide by width of envelope later: */
+- invWidth = FX_DBL2FX_SGL(GetInvInt(next_pos - start_pos));
+- /* The common exponent needs to be doubled because all mantissas are squared:
+- */
+- frameExp = frameExp << 1;
+-
+- for (k = lowSubband; k < highSubband; k++) {
+- FIXP_DBL bufferReal[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+- FIXP_DBL bufferImag[(((1024) / (32) * (4) / 2) + (3 * (4)))];
+- FIXP_DBL maxVal;
+-
+- if (analysBufferImag != NULL) {
+- int l;
+- maxVal = FL2FX_DBL(0.0f);
+- for (l = start_pos; l < next_pos; l++) {
+- bufferImag[l] = analysBufferImag[l][k];
+- maxVal |= (FIXP_DBL)((LONG)(bufferImag[l]) ^
+- ((LONG)bufferImag[l] >> (DFRACT_BITS - 1)));
+- bufferReal[l] = analysBufferReal[l][k];
+- maxVal |= (FIXP_DBL)((LONG)(bufferReal[l]) ^
+- ((LONG)bufferReal[l] >> (DFRACT_BITS - 1)));
+- }
+- } else {
+- int l;
+- maxVal = FL2FX_DBL(0.0f);
+- for (l = start_pos; l < next_pos; l++) {
+- bufferReal[l] = analysBufferReal[l][k];
+- maxVal |= (FIXP_DBL)((LONG)(bufferReal[l]) ^
+- ((LONG)bufferReal[l] >> (DFRACT_BITS - 1)));
+- }
+- }
+-
+- if (maxVal != FL2FXCONST_DBL(0.f)) {
+- /* If the accu does not provide enough overflow bits, we cannot
+- shift the samples up to the limit.
+- Instead, keep up to 3 free bits in each sample, i.e. up to
+- 6 bits after calculation of square.
+- Please note the comment on saturated arithmetic above!
+- */
+- FIXP_DBL accu;
+- preShift = CntLeadingZeros(maxVal) - 1;
+- preShift -= SHIFT_BEFORE_SQUARE;
+-
+- /* Limit preShift to a maximum value to prevent accumulator overflow in
+- exceptional situations where the signal in the analysis-buffer is very
+- small (small maxVal).
+- */
+- preShift = fMin(preShift, (SCHAR)25);
+-
+- accu = FL2FXCONST_DBL(0.0f);
+- if (preShift >= 0) {
+- int l;
+- if (analysBufferImag != NULL) {
+- for (l = start_pos; l < next_pos; l++) {
+- FIXP_DBL temp1 = bufferReal[l] << (int)preShift;
+- FIXP_DBL temp2 = bufferImag[l] << (int)preShift;
+- accu = fPow2AddDiv2(accu, temp1);
+- accu = fPow2AddDiv2(accu, temp2);
+- }
+- } else {
+- for (l = start_pos; l < next_pos; l++) {
+- FIXP_DBL temp = bufferReal[l] << (int)preShift;
+- accu = fPow2AddDiv2(accu, temp);
+- }
+- }
+- } else { /* if negative shift value */
+- int l;
+- int negpreShift = -preShift;
+- if (analysBufferImag != NULL) {
+- for (l = start_pos; l < next_pos; l++) {
+- FIXP_DBL temp1 = bufferReal[l] >> (int)negpreShift;
+- FIXP_DBL temp2 = bufferImag[l] >> (int)negpreShift;
+- accu = fPow2AddDiv2(accu, temp1);
+- accu = fPow2AddDiv2(accu, temp2);
+- }
+- } else {
+- for (l = start_pos; l < next_pos; l++) {
+- FIXP_DBL temp = bufferReal[l] >> (int)negpreShift;
+- accu = fPow2AddDiv2(accu, temp);
+- }
+- }
+- }
+- accu <<= 1;
+-
+- /* Convert double precision to Mantissa/Exponent: */
+- shift = fNorm(accu);
+- sum = accu << (int)shift;
+-
+- /* Divide by width of envelope and apply frame scale: */
+- *nrgEst++ = fMult(sum, invWidth);
+- shift += 2 * preShift;
+- if (analysBufferImag != NULL)
+- *nrgEst_e++ = frameExp - shift;
+- else
+- *nrgEst_e++ = frameExp - shift + 1; /* +1 due to missing imag. part */
+- } /* maxVal!=0 */
+- else {
+- /* Prevent a zero-mantissa-number from being misinterpreted
+- due to its exponent. */
+- *nrgEst++ = FL2FXCONST_DBL(0.0f);
+- *nrgEst_e++ = 0;
+- }
+- }
+-}
+-
+-/*!
+- \brief Estimates the mean energy of each Scale factor band for the
+- duration of the current envelope.
+-
+- This function is used when interpolFreq is false.
+-*/
+-static void calcNrgPerSfb(
+- FIXP_DBL **analysBufferReal, /*!< Real part of subband samples */
+- FIXP_DBL **analysBufferImag, /*!< Imaginary part of subband samples */
+- int nSfb, /*!< Number of scale factor bands */
+- UCHAR *freqBandTable, /*!< First Subband for each Sfb */
+- int start_pos, /*!< First QMF-slot of current envelope */
+- int next_pos, /*!< Last QMF-slot of current envelope + 1 */
+- SCHAR input_e, /*!< Common exponent for all input samples */
+- FIXP_DBL *nrgEst, /*!< resulting Energy (0..1) */
+- SCHAR *nrgEst_e) /*!< Exponent of resulting Energy */
+-{
+- FIXP_SGL invWidth;
+- FIXP_DBL temp;
+- SCHAR preShift;
+- SCHAR shift, sum_e;
+- FIXP_DBL sum;
+-
+- int j, k, l, li, ui;
+- FIXP_DBL sumAll, sumLine; /* Single precision would be sufficient,
+- but overflow bits are required for accumulation */
+-
+- /* Divide by width of envelope later: */
+- invWidth = FX_DBL2FX_SGL(GetInvInt(next_pos - start_pos));
+- /* The common exponent needs to be doubled because all mantissas are squared:
+- */
+- input_e = input_e << 1;
+-
+- for (j = 0; j < nSfb; j++) {
+- li = freqBandTable[j];
+- ui = freqBandTable[j + 1];
+-
+- FIXP_DBL maxVal = maxSubbandSample(analysBufferReal, analysBufferImag, li,
+- ui, start_pos, next_pos);
+-
+- if (maxVal != FL2FXCONST_DBL(0.f)) {
+- preShift = CntLeadingZeros(maxVal) - 1;
+-
+- /* If the accu does not provide enough overflow bits, we cannot
+- shift the samples up to the limit.
+- Instead, keep up to 3 free bits in each sample, i.e. up to
+- 6 bits after calculation of square.
+- Please note the comment on saturated arithmetic above!
+- */
+- preShift -= SHIFT_BEFORE_SQUARE;
+-
+- sumAll = FL2FXCONST_DBL(0.0f);
+-
+- for (k = li; k < ui; k++) {
+- sumLine = FL2FXCONST_DBL(0.0f);
+-
+- if (analysBufferImag != NULL) {
+- if (preShift >= 0) {
+- for (l = start_pos; l < next_pos; l++) {
+- temp = analysBufferReal[l][k] << (int)preShift;
+- sumLine += fPow2Div2(temp);
+- temp = analysBufferImag[l][k] << (int)preShift;
+- sumLine += fPow2Div2(temp);
+- }
+- } else {
+- for (l = start_pos; l < next_pos; l++) {
+- temp = analysBufferReal[l][k] >> -(int)preShift;
+- sumLine += fPow2Div2(temp);
+- temp = analysBufferImag[l][k] >> -(int)preShift;
+- sumLine += fPow2Div2(temp);
+- }
+- }
+- } else {
+- if (preShift >= 0) {
+- for (l = start_pos; l < next_pos; l++) {
+- temp = analysBufferReal[l][k] << (int)preShift;
+- sumLine += fPow2Div2(temp);
+- }
+- } else {
+- for (l = start_pos; l < next_pos; l++) {
+- temp = analysBufferReal[l][k] >> -(int)preShift;
+- sumLine += fPow2Div2(temp);
+- }
+- }
+- }
+-
+- /* The number of QMF-channels per SBR bands may be up to 15.
+- Shift right to avoid overflows in sum over all channels. */
+- sumLine = sumLine >> (4 - 1);
+- sumAll += sumLine;
+- }
+-
+- /* Convert double precision to Mantissa/Exponent: */
+- shift = fNorm(sumAll);
+- sum = sumAll << (int)shift;
+-
+- /* Divide by width of envelope: */
+- sum = fMult(sum, invWidth);
+-
+- /* Divide by width of Sfb: */
+- sum = fMult(sum, FX_DBL2FX_SGL(GetInvInt(ui - li)));
+-
+- /* Set all Subband energies in the Sfb to the average energy: */
+- if (analysBufferImag != NULL)
+- sum_e = input_e + 4 - shift; /* -4 to compensate right-shift */
+- else
+- sum_e = input_e + 4 + 1 -
+- shift; /* -4 to compensate right-shift; +1 due to missing
+- imag. part */
+-
+- sum_e -= 2 * preShift;
+- } /* maxVal!=0 */
+- else {
+- /* Prevent a zero-mantissa-number from being misinterpreted
+- due to its exponent. */
+- sum = FL2FXCONST_DBL(0.0f);
+- sum_e = 0;
+- }
+-
+- for (k = li; k < ui; k++) {
+- *nrgEst++ = sum;
+- *nrgEst_e++ = sum_e;
+- }
+- }
+-}
+-
+-/*!
+- \brief Calculate gain, noise, and additional sine level for one subband.
+-
+- The resulting energy gain is given by mantissa and exponent.
+-*/
+-static void calcSubbandGain(
+- FIXP_DBL nrgRef, /*!< Reference Energy according to envelope data */
+- SCHAR
+- nrgRef_e, /*!< Reference Energy according to envelope data (exponent) */
+- ENV_CALC_NRGS *nrgs, int i, FIXP_DBL tmpNoise, /*!< Relative noise level */
+- SCHAR tmpNoise_e, /*!< Relative noise level (exponent) */
+- UCHAR sinePresentFlag, /*!< Indicates if sine is present on band */
+- UCHAR sineMapped, /*!< Indicates if sine must be added */
+- int noNoiseFlag) /*!< Flag to suppress noise addition */
+-{
+- FIXP_DBL nrgEst = nrgs->nrgEst[i]; /*!< Energy in transposed signal */
+- SCHAR nrgEst_e =
+- nrgs->nrgEst_e[i]; /*!< Energy in transposed signal (exponent) */
+- FIXP_DBL *ptrNrgGain = &nrgs->nrgGain[i]; /*!< Resulting energy gain */
+- SCHAR *ptrNrgGain_e =
+- &nrgs->nrgGain_e[i]; /*!< Resulting energy gain (exponent) */
+- FIXP_DBL *ptrNoiseLevel =
+- &nrgs->noiseLevel[i]; /*!< Resulting absolute noise energy */
+- SCHAR *ptrNoiseLevel_e =
+- &nrgs->noiseLevel_e[i]; /*!< Resulting absolute noise energy (exponent) */
+- FIXP_DBL *ptrNrgSine = &nrgs->nrgSine[i]; /*!< Additional sine energy */
+- SCHAR *ptrNrgSine_e =
+- &nrgs->nrgSine_e[i]; /*!< Additional sine energy (exponent) */
+-
+- FIXP_DBL a, b, c;
+- SCHAR a_e, b_e, c_e;
+-
+- /*
+- This addition of 1 prevents divisions by zero in the reference code.
+- For very small energies in nrgEst, it prevents the gains from becoming
+- very high which could cause some trouble due to the smoothing.
+- */
+- b_e = (int)(nrgEst_e - 1);
+- if (b_e >= 0) {
+- nrgEst = (FL2FXCONST_DBL(0.5f) >> (INT)fixMin(b_e + 1, DFRACT_BITS - 1)) +
+- (nrgEst >> 1);
+- nrgEst_e += 1; /* shift by 1 bit to avoid overflow */
+-
+- } else {
+- nrgEst = (nrgEst >> (INT)(fixMin(-b_e + 1, DFRACT_BITS - 1))) +
+- (FL2FXCONST_DBL(0.5f) >> 1);
+- nrgEst_e = 2; /* shift by 1 bit to avoid overflow */
+- }
+-
+- /* A = NrgRef * TmpNoise */
+- a = fMult(nrgRef, tmpNoise);
+- a_e = nrgRef_e + tmpNoise_e;
+-
+- /* B = 1 + TmpNoise */
+- b_e = (int)(tmpNoise_e - 1);
+- if (b_e >= 0) {
+- b = (FL2FXCONST_DBL(0.5f) >> (INT)fixMin(b_e + 1, DFRACT_BITS - 1)) +
+- (tmpNoise >> 1);
+- b_e = tmpNoise_e + 1; /* shift by 1 bit to avoid overflow */
+- } else {
+- b = (tmpNoise >> (INT)(fixMin(-b_e + 1, DFRACT_BITS - 1))) +
+- (FL2FXCONST_DBL(0.5f) >> 1);
+- b_e = 2; /* shift by 1 bit to avoid overflow */
+- }
+-
+- /* noiseLevel = A / B = (NrgRef * TmpNoise) / (1 + TmpNoise) */
+- FDK_divide_MantExp(a, a_e, b, b_e, ptrNoiseLevel, ptrNoiseLevel_e);
+-
+- if (sinePresentFlag) {
+- /* C = (1 + TmpNoise) * NrgEst */
+- c = fMult(b, nrgEst);
+- c_e = b_e + nrgEst_e;
+-
+- /* gain = A / C = (NrgRef * TmpNoise) / (1 + TmpNoise) * NrgEst */
+- FDK_divide_MantExp(a, a_e, c, c_e, ptrNrgGain, ptrNrgGain_e);
+-
+- if (sineMapped) {
+- /* sineLevel = nrgRef/ (1 + TmpNoise) */
+- FDK_divide_MantExp(nrgRef, nrgRef_e, b, b_e, ptrNrgSine, ptrNrgSine_e);
+- }
+- } else {
+- if (noNoiseFlag) {
+- /* B = NrgEst */
+- b = nrgEst;
+- b_e = nrgEst_e;
+- } else {
+- /* B = NrgEst * (1 + TmpNoise) */
+- b = fMult(b, nrgEst);
+- b_e = b_e + nrgEst_e;
+- }
+-
+- /* gain = nrgRef / B */
+- FDK_divide_MantExp(nrgRef, nrgRef_e, b, b_e, ptrNrgGain, ptrNrgGain_e);
+- }
+-}
+-
+-/*!
+- \brief Calculate "average gain" for the specified subband range.
+-
+- This is rather a gain of the average magnitude than the average
+- of gains!
+- The result is used as a relative limit for all gains within the
+- current "limiter band" (a certain frequency range).
+-*/
+-static void calcAvgGain(
+- ENV_CALC_NRGS *nrgs, int lowSubband, /*!< Begin of the limiter band */
+- int highSubband, /*!< High end of the limiter band */
+- FIXP_DBL *ptrSumRef, SCHAR *ptrSumRef_e,
+- FIXP_DBL *ptrAvgGain, /*!< Resulting overall gain (mantissa) */
+- SCHAR *ptrAvgGain_e) /*!< Resulting overall gain (exponent) */
+-{
+- FIXP_DBL *nrgRef =
+- nrgs->nrgRef; /*!< Reference Energy according to envelope data */
+- SCHAR *nrgRef_e =
+- nrgs->nrgRef_e; /*!< Reference Energy according to envelope data
+- (exponent) */
+- FIXP_DBL *nrgEst = nrgs->nrgEst; /*!< Energy in transposed signal */
+- SCHAR *nrgEst_e =
+- nrgs->nrgEst_e; /*!< Energy in transposed signal (exponent) */
+-
+- FIXP_DBL sumRef = 1;
+- FIXP_DBL sumEst = 1;
+- SCHAR sumRef_e = -FRACT_BITS;
+- SCHAR sumEst_e = -FRACT_BITS;
+- int k;
+-
+- for (k = lowSubband; k < highSubband; k++) {
+- /* Add nrgRef[k] to sumRef: */
+- FDK_add_MantExp(sumRef, sumRef_e, nrgRef[k], nrgRef_e[k], &sumRef,
+- &sumRef_e);
+-
+- /* Add nrgEst[k] to sumEst: */
+- FDK_add_MantExp(sumEst, sumEst_e, nrgEst[k], nrgEst_e[k], &sumEst,
+- &sumEst_e);
+- }
+-
+- FDK_divide_MantExp(sumRef, sumRef_e, sumEst, sumEst_e, ptrAvgGain,
+- ptrAvgGain_e);
+-
+- *ptrSumRef = sumRef;
+- *ptrSumRef_e = sumRef_e;
+-}
+-
+-static void adjustTimeSlot_EldGrid(
+- FIXP_DBL *RESTRICT
+- ptrReal, /*!< Subband samples to be adjusted, real part */
+- ENV_CALC_NRGS *nrgs, UCHAR *ptrHarmIndex, /*!< Harmonic index */
+- int lowSubband, /*!< Lowest QMF-channel in the currently used SBR range. */
+- int noSubbands, /*!< Number of QMF subbands */
+- int scale_change, /*!< Number of bits to shift adjusted samples */
+- int noNoiseFlag, /*!< Flag to suppress noise addition */
+- int *ptrPhaseIndex, /*!< Start index to random number array */
+- int scale_diff_low) /*!< */
+-
+-{
+- int k;
+- FIXP_DBL signalReal, sbNoise;
+- int tone_count = 0;
+-
+- FIXP_DBL *pGain = nrgs->nrgGain; /*!< Gains of current envelope */
+- FIXP_DBL *RESTRICT pNoiseLevel =
+- nrgs->noiseLevel; /*!< Noise levels of current envelope */
+- FIXP_DBL *RESTRICT pSineLevel = nrgs->nrgSine; /*!< Sine levels */
+-
+- int phaseIndex = *ptrPhaseIndex;
+- UCHAR harmIndex = *ptrHarmIndex;
+-
+- static const INT harmonicPhase[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
+-
+- static const FIXP_DBL harmonicPhaseX[4][2] = {
+- {FL2FXCONST_DBL(2.0 * 1.245183154539139e-001),
+- FL2FXCONST_DBL(2.0 * 1.245183154539139e-001)},
+- {FL2FXCONST_DBL(2.0 * -1.123767859325028e-001),
+- FL2FXCONST_DBL(2.0 * 1.123767859325028e-001)},
+- {FL2FXCONST_DBL(2.0 * -1.245183154539139e-001),
+- FL2FXCONST_DBL(2.0 * -1.245183154539139e-001)},
+- {FL2FXCONST_DBL(2.0 * 1.123767859325028e-001),
+- FL2FXCONST_DBL(2.0 * -1.123767859325028e-001)}};
+-
+- const FIXP_DBL *p_harmonicPhaseX = &harmonicPhaseX[harmIndex][0];
+- const INT *p_harmonicPhase = &harmonicPhase[harmIndex][0];
+-
+- *(ptrReal - 1) = fAddSaturate(
+- *(ptrReal - 1),
+- SATURATE_SHIFT(fMultDiv2(p_harmonicPhaseX[lowSubband & 1], pSineLevel[0]),
+- scale_diff_low, DFRACT_BITS));
+- FIXP_DBL pSineLevel_prev = (FIXP_DBL)0;
+-
+- int idx_k = lowSubband & 1;
+-
+- for (k = 0; k < noSubbands; k++) {
+- FIXP_DBL sineLevel_curr = *pSineLevel++;
+- phaseIndex = (phaseIndex + 1) & (SBR_NF_NO_RANDOM_VAL - 1);
+-
+- signalReal = fMultDiv2(*ptrReal, *pGain++) << ((int)scale_change);
+- sbNoise = *pNoiseLevel++;
+- if (((INT)sineLevel_curr | noNoiseFlag) == 0) {
+- signalReal +=
+- (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[phaseIndex][0], sbNoise)
+- << 4);
+- }
+- signalReal += sineLevel_curr * p_harmonicPhase[0];
+- signalReal =
+- fMultAddDiv2(signalReal, pSineLevel_prev, p_harmonicPhaseX[idx_k]);
+- pSineLevel_prev = sineLevel_curr;
+- idx_k = !idx_k;
+- if (k < noSubbands - 1) {
+- signalReal =
+- fMultAddDiv2(signalReal, pSineLevel[0], p_harmonicPhaseX[idx_k]);
+- } else /* (k == noSubbands - 1) */
+- {
+- if (k + lowSubband + 1 < 63) {
+- *(ptrReal + 1) += fMultDiv2(pSineLevel_prev, p_harmonicPhaseX[idx_k]);
+- }
+- }
+- *ptrReal++ = signalReal;
+-
+- if (pSineLevel_prev != FL2FXCONST_DBL(0.0f)) {
+- if (++tone_count == 16) {
+- k++;
+- break;
+- }
+- }
+- }
+- /* Run again, if previous loop got breaked with tone_count = 16 */
+- for (; k < noSubbands; k++) {
+- FIXP_DBL sineLevel_curr = *pSineLevel++;
+- phaseIndex = (phaseIndex + 1) & (SBR_NF_NO_RANDOM_VAL - 1);
+-
+- signalReal = fMultDiv2(*ptrReal, *pGain++) << ((int)scale_change);
+- sbNoise = *pNoiseLevel++;
+- if (((INT)sineLevel_curr | noNoiseFlag) == 0) {
+- signalReal +=
+- (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[phaseIndex][0], sbNoise)
+- << 4);
+- }
+- signalReal += sineLevel_curr * p_harmonicPhase[0];
+- *ptrReal++ = signalReal;
+- }
+-
+- *ptrHarmIndex = (harmIndex + 1) & 3;
+- *ptrPhaseIndex = phaseIndex & (SBR_NF_NO_RANDOM_VAL - 1);
+-}
+-
+-/*!
+- \brief Amplify one timeslot of the signal with the calculated gains
+- and add the noisefloor.
+-*/
+-
+-static void adjustTimeSlotLC(
+- FIXP_DBL *ptrReal, /*!< Subband samples to be adjusted, real part */
+- ENV_CALC_NRGS *nrgs, UCHAR *ptrHarmIndex, /*!< Harmonic index */
+- int lowSubband, /*!< Lowest QMF-channel in the currently used SBR range. */
+- int noSubbands, /*!< Number of QMF subbands */
+- int scale_change, /*!< Number of bits to shift adjusted samples */
+- int noNoiseFlag, /*!< Flag to suppress noise addition */
+- int *ptrPhaseIndex) /*!< Start index to random number array */
+-{
+- FIXP_DBL *pGain = nrgs->nrgGain; /*!< Gains of current envelope */
+- FIXP_DBL *pNoiseLevel =
+- nrgs->noiseLevel; /*!< Noise levels of current envelope */
+- FIXP_DBL *pSineLevel = nrgs->nrgSine; /*!< Sine levels */
+-
+- int k;
+- int index = *ptrPhaseIndex;
+- UCHAR harmIndex = *ptrHarmIndex;
+- UCHAR freqInvFlag = (lowSubband & 1);
+- FIXP_DBL signalReal, sineLevel, sineLevelNext, sineLevelPrev;
+- int tone_count = 0;
+- int sineSign = 1;
+-
+-#define C1 ((FIXP_SGL)FL2FXCONST_SGL(2.f * 0.00815f))
+-#define C1_CLDFB ((FIXP_SGL)FL2FXCONST_SGL(2.f * 0.16773f))
+-
+- /*
+- First pass for k=0 pulled out of the loop:
+- */
+-
+- index = (index + 1) & (SBR_NF_NO_RANDOM_VAL - 1);
+-
+- /*
+- The next multiplication constitutes the actual envelope adjustment
+- of the signal and should be carried out with full accuracy
+- (supplying #FRACT_BITS valid bits).
+- */
+- signalReal = fMultDiv2(*ptrReal, *pGain++) << ((int)scale_change);
+- sineLevel = *pSineLevel++;
+- sineLevelNext = (noSubbands > 1) ? pSineLevel[0] : FL2FXCONST_DBL(0.0f);
+-
+- if (sineLevel != FL2FXCONST_DBL(0.0f))
+- tone_count++;
+- else if (!noNoiseFlag)
+- /* Add noisefloor to the amplified signal */
+- signalReal +=
+- (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], pNoiseLevel[0])
+- << 4);
+-
+- {
+- if (!(harmIndex & 0x1)) {
+- /* harmIndex 0,2 */
+- signalReal += (harmIndex & 0x2) ? -sineLevel : sineLevel;
+- *ptrReal++ = signalReal;
+- } else {
+- /* harmIndex 1,3 in combination with freqInvFlag */
+- int shift = (int)(scale_change + 1);
+- shift = (shift >= 0) ? fixMin(DFRACT_BITS - 1, shift)
+- : fixMax(-(DFRACT_BITS - 1), shift);
+-
+- FIXP_DBL tmp1 = (shift >= 0) ? (fMultDiv2(C1, sineLevel) >> shift)
+- : (fMultDiv2(C1, sineLevel) << (-shift));
+- FIXP_DBL tmp2 = fMultDiv2(C1, sineLevelNext);
+-
+- /* save switch and compare operations and reduce to XOR statement */
+- if (((harmIndex >> 1) & 0x1) ^ freqInvFlag) {
+- *(ptrReal - 1) += tmp1;
+- signalReal -= tmp2;
+- } else {
+- *(ptrReal - 1) -= tmp1;
+- signalReal += tmp2;
+- }
+- *ptrReal++ = signalReal;
+- freqInvFlag = !freqInvFlag;
+- }
+- }
+-
+- pNoiseLevel++;
+-
+- if (noSubbands > 2) {
+- if (!(harmIndex & 0x1)) {
+- /* harmIndex 0,2 */
+- if (!harmIndex) {
+- sineSign = 0;
+- }
+-
+- for (k = noSubbands - 2; k != 0; k--) {
+- FIXP_DBL sinelevel = *pSineLevel++;
+- index++;
+- if (((signalReal = (sineSign ? -sinelevel : sinelevel)) ==
+- FL2FXCONST_DBL(0.0f)) &&
+- !noNoiseFlag) {
+- /* Add noisefloor to the amplified signal */
+- index &= (SBR_NF_NO_RANDOM_VAL - 1);
+- signalReal += (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0],
+- pNoiseLevel[0])
+- << 4);
+- }
+-
+- /* The next multiplication constitutes the actual envelope adjustment of
+- * the signal. */
+- signalReal += fMultDiv2(*ptrReal, *pGain++) << ((int)scale_change);
+-
+- pNoiseLevel++;
+- *ptrReal++ = signalReal;
+- } /* for ... */
+- } else {
+- /* harmIndex 1,3 in combination with freqInvFlag */
+- if (harmIndex == 1) freqInvFlag = !freqInvFlag;
+-
+- for (k = noSubbands - 2; k != 0; k--) {
+- index++;
+- /* The next multiplication constitutes the actual envelope adjustment of
+- * the signal. */
+- signalReal = fMultDiv2(*ptrReal, *pGain++) << ((int)scale_change);
+-
+- if (*pSineLevel++ != FL2FXCONST_DBL(0.0f))
+- tone_count++;
+- else if (!noNoiseFlag) {
+- /* Add noisefloor to the amplified signal */
+- index &= (SBR_NF_NO_RANDOM_VAL - 1);
+- signalReal += (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0],
+- pNoiseLevel[0])
+- << 4);
+- }
+-
+- pNoiseLevel++;
+-
+- if (tone_count <= 16) {
+- FIXP_DBL addSine = fMultDiv2((pSineLevel[-2] - pSineLevel[0]), C1);
+- signalReal += (freqInvFlag) ? (-addSine) : (addSine);
+- }
+-
+- *ptrReal++ = signalReal;
+- freqInvFlag = !freqInvFlag;
+- } /* for ... */
+- }
+- }
+-
+- if (noSubbands > -1) {
+- index++;
+- /* The next multiplication constitutes the actual envelope adjustment of the
+- * signal. */
+- signalReal = fMultDiv2(*ptrReal, *pGain) << ((int)scale_change);
+- sineLevelPrev = fMultDiv2(pSineLevel[-1], FL2FX_SGL(0.0163f));
+- sineLevel = pSineLevel[0];
+-
+- if (pSineLevel[0] != FL2FXCONST_DBL(0.0f))
+- tone_count++;
+- else if (!noNoiseFlag) {
+- /* Add noisefloor to the amplified signal */
+- index &= (SBR_NF_NO_RANDOM_VAL - 1);
+- signalReal =
+- signalReal +
+- (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], pNoiseLevel[0])
+- << 4);
+- }
+-
+- if (!(harmIndex & 0x1)) {
+- /* harmIndex 0,2 */
+- *ptrReal = signalReal + ((sineSign) ? -sineLevel : sineLevel);
+- } else {
+- /* harmIndex 1,3 in combination with freqInvFlag */
+- if (tone_count <= 16) {
+- if (freqInvFlag) {
+- *ptrReal++ = signalReal - sineLevelPrev;
+- if (noSubbands + lowSubband < 63)
+- *ptrReal = *ptrReal + fMultDiv2(C1, sineLevel);
+- } else {
+- *ptrReal++ = signalReal + sineLevelPrev;
+- if (noSubbands + lowSubband < 63)
+- *ptrReal = *ptrReal - fMultDiv2(C1, sineLevel);
+- }
+- } else
+- *ptrReal = signalReal;
+- }
+- }
+- *ptrHarmIndex = (harmIndex + 1) & 3;
+- *ptrPhaseIndex = index & (SBR_NF_NO_RANDOM_VAL - 1);
+-}
+-
+-static void adjustTimeSlotHQ_GainAndNoise(
+- FIXP_DBL *RESTRICT
+- ptrReal, /*!< Subband samples to be adjusted, real part */
+- FIXP_DBL *RESTRICT
+- ptrImag, /*!< Subband samples to be adjusted, imag part */
+- HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env, ENV_CALC_NRGS *nrgs,
+- int lowSubband, /*!< Lowest QMF-channel in the currently used SBR range. */
+- int noSubbands, /*!< Number of QMF subbands */
+- int scale_change, /*!< Number of bits to shift adjusted samples */
+- FIXP_SGL smooth_ratio, /*!< Impact of last envelope */
+- int noNoiseFlag, /*!< Start index to random number array */
+- int filtBufferNoiseShift) /*!< Shift factor of filtBufferNoise */
+-{
+- FIXP_DBL *RESTRICT gain = nrgs->nrgGain; /*!< Gains of current envelope */
+- FIXP_DBL *RESTRICT noiseLevel =
+- nrgs->noiseLevel; /*!< Noise levels of current envelope */
+- FIXP_DBL *RESTRICT pSineLevel = nrgs->nrgSine; /*!< Sine levels */
+-
+- FIXP_DBL *RESTRICT filtBuffer =
+- h_sbr_cal_env->filtBuffer; /*!< Gains of last envelope */
+- FIXP_DBL *RESTRICT filtBufferNoise =
+- h_sbr_cal_env->filtBufferNoise; /*!< Noise levels of last envelope */
+- int *RESTRICT ptrPhaseIndex =
+- &h_sbr_cal_env->phaseIndex; /*!< Start index to random number array */
+-
+- int k;
+- FIXP_DBL signalReal, signalImag;
+- FIXP_DBL noiseReal, noiseImag;
+- FIXP_DBL smoothedGain, smoothedNoise;
+- FIXP_SGL direct_ratio =
+- /*FL2FXCONST_SGL(1.0f) */ (FIXP_SGL)MAXVAL_SGL - smooth_ratio;
+- int index = *ptrPhaseIndex;
+- int shift;
+-
+- *ptrPhaseIndex = (index + noSubbands) & (SBR_NF_NO_RANDOM_VAL - 1);
+-
+- filtBufferNoiseShift +=
+- 1; /* due to later use of fMultDiv2 instead of fMult */
+- if (filtBufferNoiseShift < 0) {
+- shift = fixMin(DFRACT_BITS - 1, -filtBufferNoiseShift);
+- } else {
+- shift = fixMin(DFRACT_BITS - 1, filtBufferNoiseShift);
+- }
+-
+- if (smooth_ratio > FL2FXCONST_SGL(0.0f)) {
+- for (k = 0; k < noSubbands; k++) {
+- /*
+- Smoothing: The old envelope has been bufferd and a certain ratio
+- of the old gains and noise levels is used.
+- */
+- smoothedGain =
+- fMult(smooth_ratio, filtBuffer[k]) + fMult(direct_ratio, gain[k]);
+-
+- if (filtBufferNoiseShift < 0) {
+- smoothedNoise = (fMultDiv2(smooth_ratio, filtBufferNoise[k]) >> shift) +
+- fMult(direct_ratio, noiseLevel[k]);
+- } else {
+- smoothedNoise = (fMultDiv2(smooth_ratio, filtBufferNoise[k]) << shift) +
+- fMult(direct_ratio, noiseLevel[k]);
+- }
+-
+- /*
+- The next 2 multiplications constitute the actual envelope adjustment
+- of the signal and should be carried out with full accuracy
+- (supplying #DFRACT_BITS valid bits).
+- */
+- signalReal = fMultDiv2(*ptrReal, smoothedGain) << ((int)scale_change);
+- signalImag = fMultDiv2(*ptrImag, smoothedGain) << ((int)scale_change);
+-
+- index++;
+-
+- if ((pSineLevel[k] != FL2FXCONST_DBL(0.0f)) || noNoiseFlag) {
+- /* Just the amplified signal is saved */
+- *ptrReal++ = signalReal;
+- *ptrImag++ = signalImag;
+- } else {
+- /* Add noisefloor to the amplified signal */
+- index &= (SBR_NF_NO_RANDOM_VAL - 1);
+- noiseReal =
+- fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise)
+- << 4;
+- noiseImag =
+- fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise)
+- << 4;
+- *ptrReal++ = (signalReal + noiseReal);
+- *ptrImag++ = (signalImag + noiseImag);
+- }
+- }
+- } else {
+- for (k = 0; k < noSubbands; k++) {
+- smoothedGain = gain[k];
+- signalReal = fMultDiv2(*ptrReal, smoothedGain) << scale_change;
+- signalImag = fMultDiv2(*ptrImag, smoothedGain) << scale_change;
+-
+- index++;
+-
+- if ((pSineLevel[k] == FL2FXCONST_DBL(0.0f)) && (noNoiseFlag == 0)) {
+- /* Add noisefloor to the amplified signal */
+- smoothedNoise = noiseLevel[k];
+- index &= (SBR_NF_NO_RANDOM_VAL - 1);
+- noiseReal =
+- fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise);
+- noiseImag =
+- fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise);
+-
+- /* FDK_sbrDecoder_sbr_randomPhase is downscaled by 2^3 */
+- signalReal += noiseReal << 4;
+- signalImag += noiseImag << 4;
+- }
+- *ptrReal++ = signalReal;
+- *ptrImag++ = signalImag;
+- }
+- }
+-}
+-
+-static void adjustTimeSlotHQ_AddHarmonics(
+- FIXP_DBL *RESTRICT
+- ptrReal, /*!< Subband samples to be adjusted, real part */
+- FIXP_DBL *RESTRICT
+- ptrImag, /*!< Subband samples to be adjusted, imag part */
+- HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env, ENV_CALC_NRGS *nrgs,
+- int lowSubband, /*!< Lowest QMF-channel in the currently used SBR range. */
+- int noSubbands, /*!< Number of QMF subbands */
+- int scale_change /*!< Scale mismatch between QMF input and sineLevel
+- exponent. */
+-) {
+- FIXP_DBL *RESTRICT pSineLevel = nrgs->nrgSine; /*!< Sine levels */
+- UCHAR *RESTRICT ptrHarmIndex =
+- &h_sbr_cal_env->harmIndex; /*!< Harmonic index */
+-
+- int k;
+- FIXP_DBL signalReal, signalImag;
+- UCHAR harmIndex = *ptrHarmIndex;
+- int freqInvFlag = (lowSubband & 1);
+- FIXP_DBL sineLevel;
+-
+- *ptrHarmIndex = (harmIndex + 1) & 3;
+-
+- for (k = 0; k < noSubbands; k++) {
+- sineLevel = pSineLevel[k];
+- freqInvFlag ^= 1;
+- if (sineLevel != FL2FXCONST_DBL(0.f)) {
+- signalReal = ptrReal[k];
+- signalImag = ptrImag[k];
+- sineLevel = scaleValue(sineLevel, scale_change);
+- if (harmIndex & 2) {
+- /* case 2,3 */
+- sineLevel = -sineLevel;
+- }
+- if (!(harmIndex & 1)) {
+- /* case 0,2: */
+- ptrReal[k] = signalReal + sineLevel;
+- } else {
+- /* case 1,3 */
+- if (!freqInvFlag) sineLevel = -sineLevel;
+- ptrImag[k] = signalImag + sineLevel;
+- }
+- }
+- }
+-}
+-
+-static void adjustTimeSlotHQ(
+- FIXP_DBL *RESTRICT
+- ptrReal, /*!< Subband samples to be adjusted, real part */
+- FIXP_DBL *RESTRICT
+- ptrImag, /*!< Subband samples to be adjusted, imag part */
+- HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env, ENV_CALC_NRGS *nrgs,
+- int lowSubband, /*!< Lowest QMF-channel in the currently used SBR range. */
+- int noSubbands, /*!< Number of QMF subbands */
+- int scale_change, /*!< Number of bits to shift adjusted samples */
+- FIXP_SGL smooth_ratio, /*!< Impact of last envelope */
+- int noNoiseFlag, /*!< Start index to random number array */
+- int filtBufferNoiseShift) /*!< Shift factor of filtBufferNoise */
+-{
+- FIXP_DBL *RESTRICT gain = nrgs->nrgGain; /*!< Gains of current envelope */
+- FIXP_DBL *RESTRICT noiseLevel =
+- nrgs->noiseLevel; /*!< Noise levels of current envelope */
+- FIXP_DBL *RESTRICT pSineLevel = nrgs->nrgSine; /*!< Sine levels */
+-
+- FIXP_DBL *RESTRICT filtBuffer =
+- h_sbr_cal_env->filtBuffer; /*!< Gains of last envelope */
+- FIXP_DBL *RESTRICT filtBufferNoise =
+- h_sbr_cal_env->filtBufferNoise; /*!< Noise levels of last envelope */
+- UCHAR *RESTRICT ptrHarmIndex =
+- &h_sbr_cal_env->harmIndex; /*!< Harmonic index */
+- int *RESTRICT ptrPhaseIndex =
+- &h_sbr_cal_env->phaseIndex; /*!< Start index to random number array */
+-
+- int k;
+- FIXP_DBL signalReal, signalImag;
+- FIXP_DBL noiseReal, noiseImag;
+- FIXP_DBL smoothedGain, smoothedNoise;
+- FIXP_SGL direct_ratio =
+- /*FL2FXCONST_SGL(1.0f) */ (FIXP_SGL)MAXVAL_SGL - smooth_ratio;
+- int index = *ptrPhaseIndex;
+- UCHAR harmIndex = *ptrHarmIndex;
+- int freqInvFlag = (lowSubband & 1);
+- FIXP_DBL sineLevel;
+- int shift;
+-
+- *ptrPhaseIndex = (index + noSubbands) & (SBR_NF_NO_RANDOM_VAL - 1);
+- *ptrHarmIndex = (harmIndex + 1) & 3;
+-
+- /*
+- Possible optimization:
+- smooth_ratio and harmIndex stay constant during the loop.
+- It might be faster to include a separate loop in each path.
+-
+- the check for smooth_ratio is now outside the loop and the workload
+- of the whole function decreased by about 20 %
+- */
+-
+- filtBufferNoiseShift +=
+- 1; /* due to later use of fMultDiv2 instead of fMult */
+- if (filtBufferNoiseShift < 0)
+- shift = fixMin(DFRACT_BITS - 1, -filtBufferNoiseShift);
+- else
+- shift = fixMin(DFRACT_BITS - 1, filtBufferNoiseShift);
+-
+- if (smooth_ratio > FL2FXCONST_SGL(0.0f)) {
+- for (k = 0; k < noSubbands; k++) {
+- /*
+- Smoothing: The old envelope has been bufferd and a certain ratio
+- of the old gains and noise levels is used.
+- */
+-
+- smoothedGain =
+- fMult(smooth_ratio, filtBuffer[k]) + fMult(direct_ratio, gain[k]);
+-
+- if (filtBufferNoiseShift < 0) {
+- smoothedNoise = (fMultDiv2(smooth_ratio, filtBufferNoise[k]) >> shift) +
+- fMult(direct_ratio, noiseLevel[k]);
+- } else {
+- smoothedNoise = (fMultDiv2(smooth_ratio, filtBufferNoise[k]) << shift) +
+- fMult(direct_ratio, noiseLevel[k]);
+- }
+-
+- /*
+- The next 2 multiplications constitute the actual envelope adjustment
+- of the signal and should be carried out with full accuracy
+- (supplying #DFRACT_BITS valid bits).
+- */
+- signalReal = fMultDiv2(*ptrReal, smoothedGain) << ((int)scale_change);
+- signalImag = fMultDiv2(*ptrImag, smoothedGain) << ((int)scale_change);
+-
+- index++;
+-
+- if (pSineLevel[k] != FL2FXCONST_DBL(0.0f)) {
+- sineLevel = pSineLevel[k];
+-
+- switch (harmIndex) {
+- case 0:
+- *ptrReal++ = (signalReal + sineLevel);
+- *ptrImag++ = (signalImag);
+- break;
+- case 2:
+- *ptrReal++ = (signalReal - sineLevel);
+- *ptrImag++ = (signalImag);
+- break;
+- case 1:
+- *ptrReal++ = (signalReal);
+- if (freqInvFlag)
+- *ptrImag++ = (signalImag - sineLevel);
+- else
+- *ptrImag++ = (signalImag + sineLevel);
+- break;
+- case 3:
+- *ptrReal++ = signalReal;
+- if (freqInvFlag)
+- *ptrImag++ = (signalImag + sineLevel);
+- else
+- *ptrImag++ = (signalImag - sineLevel);
+- break;
+- }
+- } else {
+- if (noNoiseFlag) {
+- /* Just the amplified signal is saved */
+- *ptrReal++ = (signalReal);
+- *ptrImag++ = (signalImag);
+- } else {
+- /* Add noisefloor to the amplified signal */
+- index &= (SBR_NF_NO_RANDOM_VAL - 1);
+- /* FDK_sbrDecoder_sbr_randomPhase is downscaled by 2^3 */
+- noiseReal =
+- fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise)
+- << 4;
+- noiseImag =
+- fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise)
+- << 4;
+- *ptrReal++ = (signalReal + noiseReal);
+- *ptrImag++ = (signalImag + noiseImag);
+- }
+- }
+- freqInvFlag ^= 1;
+- }
+-
+- } else {
+- for (k = 0; k < noSubbands; k++) {
+- smoothedGain = gain[k];
+- signalReal = fMultDiv2(*ptrReal, smoothedGain) << scale_change;
+- signalImag = fMultDiv2(*ptrImag, smoothedGain) << scale_change;
+-
+- index++;
+-
+- if ((sineLevel = pSineLevel[k]) != FL2FXCONST_DBL(0.0f)) {
+- switch (harmIndex) {
+- case 0:
+- signalReal += sineLevel;
+- break;
+- case 1:
+- if (freqInvFlag)
+- signalImag -= sineLevel;
+- else
+- signalImag += sineLevel;
+- break;
+- case 2:
+- signalReal -= sineLevel;
+- break;
+- case 3:
+- if (freqInvFlag)
+- signalImag += sineLevel;
+- else
+- signalImag -= sineLevel;
+- break;
+- }
+- } else {
+- if (noNoiseFlag == 0) {
+- /* Add noisefloor to the amplified signal */
+- smoothedNoise = noiseLevel[k];
+- index &= (SBR_NF_NO_RANDOM_VAL - 1);
+- noiseReal = fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0],
+- smoothedNoise);
+- noiseImag = fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][1],
+- smoothedNoise);
+-
+- /* FDK_sbrDecoder_sbr_randomPhase is downscaled by 2^3 */
+- signalReal += noiseReal << 4;
+- signalImag += noiseImag << 4;
+- }
+- }
+- *ptrReal++ = signalReal;
+- *ptrImag++ = signalImag;
+-
+- freqInvFlag ^= 1;
+- }
+- }
+-}
+-
+-/*!
+- \brief Reset limiter bands.
+-
+- Build frequency band table for the gain limiter dependent on
+- the previously generated transposer patch areas.
+-
+- \return SBRDEC_OK if ok, SBRDEC_UNSUPPORTED_CONFIG on error
+-*/
+-SBR_ERROR
+-ResetLimiterBands(
+- UCHAR *limiterBandTable, /*!< Resulting band borders in QMF channels */
+- UCHAR *noLimiterBands, /*!< Resulting number of limiter band */
+- UCHAR *freqBandTable, /*!< Table with possible band borders */
+- int noFreqBands, /*!< Number of bands in freqBandTable */
+- const PATCH_PARAM *patchParam, /*!< Transposer patch parameters */
+- int noPatches, /*!< Number of transposer patches */
+- int limiterBands, /*!< Selected 'band density' from bitstream */
+- UCHAR sbrPatchingMode, int xOverQmf[MAX_NUM_PATCHES], int b41Sbr) {
+- int i, k, isPatchBorder[2], loLimIndex, hiLimIndex, tempNoLim, nBands;
+- UCHAR workLimiterBandTable[MAX_FREQ_COEFFS / 2 + MAX_NUM_PATCHES + 1];
+- int patchBorders[MAX_NUM_PATCHES + 1];
+- int kx, k2;
+-
+- int lowSubband = freqBandTable[0];
+- int highSubband = freqBandTable[noFreqBands];
+-
+- /* 1 limiter band. */
+- if (limiterBands == 0) {
+- limiterBandTable[0] = 0;
+- limiterBandTable[1] = highSubband - lowSubband;
+- nBands = 1;
+- } else {
+- if (!sbrPatchingMode && xOverQmf != NULL) {
+- noPatches = 0;
+-
+- if (b41Sbr == 1) {
+- for (i = 1; i < MAX_NUM_PATCHES_HBE; i++)
+- if (xOverQmf[i] != 0) noPatches++;
+- } else {
+- for (i = 1; i < MAX_STRETCH_HBE; i++)
+- if (xOverQmf[i] != 0) noPatches++;
+- }
+- for (i = 0; i < noPatches; i++) {
+- patchBorders[i] = xOverQmf[i] - lowSubband;
+- }
+- } else {
+- for (i = 0; i < noPatches; i++) {
+- patchBorders[i] = patchParam[i].guardStartBand - lowSubband;
+- }
+- }
+- patchBorders[i] = highSubband - lowSubband;
+-
+- /* 1.2, 2, or 3 limiter bands/octave plus bandborders at patchborders. */
+- for (k = 0; k <= noFreqBands; k++) {
+- workLimiterBandTable[k] = freqBandTable[k] - lowSubband;
+- }
+- for (k = 1; k < noPatches; k++) {
+- workLimiterBandTable[noFreqBands + k] = patchBorders[k];
+- }
+-
+- tempNoLim = nBands = noFreqBands + noPatches - 1;
+- shellsort(workLimiterBandTable, tempNoLim + 1);
+-
+- loLimIndex = 0;
+- hiLimIndex = 1;
+-
+- while (hiLimIndex <= tempNoLim) {
+- FIXP_DBL div_m, oct_m, temp;
+- INT div_e = 0, oct_e = 0, temp_e = 0;
+-
+- k2 = workLimiterBandTable[hiLimIndex] + lowSubband;
+- kx = workLimiterBandTable[loLimIndex] + lowSubband;
+-
+- div_m = fDivNorm(k2, kx, &div_e);
+-
+- /* calculate number of octaves */
+- oct_m = fLog2(div_m, div_e, &oct_e);
+-
+- /* multiply with limiterbands per octave */
+- /* values 1, 1.2, 2, 3 -> scale factor of 2 */
+- temp = fMultNorm(
+- oct_m, FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4_DBL[limiterBands],
+- &temp_e);
+-
+- /* overall scale factor of temp ist addition of scalefactors from log2
+- calculation, limiter bands scalefactor (2) and limiter bands
+- multiplication */
+- temp_e += oct_e + 2;
+-
+- /* div can be a maximum of 64 (k2 = 64 and kx = 1)
+- -> oct can be a maximum of 6
+- -> temp can be a maximum of 18 (as limiterBandsPerOctoave is a maximum
+- factor of 3)
+- -> we need a scale factor of 5 for comparisson
+- */
+- if (temp >> (5 - temp_e) < FL2FXCONST_DBL(0.49f) >> 5) {
+- if (workLimiterBandTable[hiLimIndex] ==
+- workLimiterBandTable[loLimIndex]) {
+- workLimiterBandTable[hiLimIndex] = highSubband;
+- nBands--;
+- hiLimIndex++;
+- continue;
+- }
+- isPatchBorder[0] = isPatchBorder[1] = 0;
+- for (k = 0; k <= noPatches; k++) {
+- if (workLimiterBandTable[hiLimIndex] == patchBorders[k]) {
+- isPatchBorder[1] = 1;
+- break;
+- }
+- }
+- if (!isPatchBorder[1]) {
+- workLimiterBandTable[hiLimIndex] = highSubband;
+- nBands--;
+- hiLimIndex++;
+- continue;
+- }
+- for (k = 0; k <= noPatches; k++) {
+- if (workLimiterBandTable[loLimIndex] == patchBorders[k]) {
+- isPatchBorder[0] = 1;
+- break;
+- }
+- }
+- if (!isPatchBorder[0]) {
+- workLimiterBandTable[loLimIndex] = highSubband;
+- nBands--;
+- }
+- }
+- loLimIndex = hiLimIndex;
+- hiLimIndex++;
+- }
+- shellsort(workLimiterBandTable, tempNoLim + 1);
+-
+- /* Test if algorithm exceeded maximum allowed limiterbands */
+- if (nBands > MAX_NUM_LIMITERS || nBands <= 0) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- /* Copy limiterbands from working buffer into final destination */
+- for (k = 0; k <= nBands; k++) {
+- limiterBandTable[k] = workLimiterBandTable[k];
+- }
+- }
+- *noLimiterBands = nBands;
+-
+- return SBRDEC_OK;
+-}
+diff --git a/libSBRdec/src/env_calc.h b/libSBRdec/src/env_calc.h
+deleted file mode 100644
+index cff365d..0000000
+--- a/libSBRdec/src/env_calc.h
++++ /dev/null
+@@ -1,182 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Envelope calculation prototypes
+-*/
+-#ifndef ENV_CALC_H
+-#define ENV_CALC_H
+-
+-#include "sbrdecoder.h"
+-#include "env_extr.h" /* for HANDLE_SBR_HEADER_DATA */
+-
+-typedef struct {
+- FIXP_DBL filtBuffer[MAX_FREQ_COEFFS]; /*!< previous gains (required for
+- smoothing) */
+- FIXP_DBL filtBufferNoise[MAX_FREQ_COEFFS]; /*!< previous noise levels
+- (required for smoothing) */
+- SCHAR filtBuffer_e[MAX_FREQ_COEFFS]; /*!< Exponents of previous gains */
+- SCHAR filtBufferNoise_e; /*!< Common exponent of previous noise levels */
+-
+- int startUp; /*!< flag to signal initial conditions in buffers */
+- int phaseIndex; /*!< Index for randomPase array */
+- int prevTranEnv; /*!< The transient envelope of the previous frame. */
+-
+- ULONG harmFlagsPrev[ADD_HARMONICS_FLAGS_SIZE];
+- /*!< Words with 16 flags each indicating where a sine was added in the
+- * previous frame.*/
+- UCHAR harmIndex; /*!< Current phase of synthetic sine */
+- int sbrPatchingMode; /*!< Current patching mode */
+-
+- FIXP_SGL prevSbrNoiseFloorLevel[MAX_NOISE_COEFFS];
+- UCHAR prevNNfb;
+- UCHAR prevNSfb[2];
+- UCHAR prevLoSubband;
+- UCHAR prevHiSubband;
+- UCHAR prev_ov_highSubband;
+- UCHAR *prevFreqBandTable[2];
+- UCHAR prevFreqBandTableLo[MAX_FREQ_COEFFS / 2 + 1];
+- UCHAR prevFreqBandTableHi[MAX_FREQ_COEFFS + 1];
+- UCHAR prevFreqBandTableNoise[MAX_NOISE_COEFFS + 1];
+- SCHAR sinusoidal_positionPrev;
+- ULONG harmFlagsPrevActive[ADD_HARMONICS_FLAGS_SIZE];
+-} SBR_CALCULATE_ENVELOPE;
+-
+-typedef SBR_CALCULATE_ENVELOPE *HANDLE_SBR_CALCULATE_ENVELOPE;
+-
+-void calculateSbrEnvelope(
+- QMF_SCALE_FACTOR *sbrScaleFactor,
+- HANDLE_SBR_CALCULATE_ENVELOPE h_sbr_cal_env,
+- HANDLE_SBR_HEADER_DATA hHeaderData, HANDLE_SBR_FRAME_DATA hFrameData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData, FIXP_DBL **analysBufferReal,
+- FIXP_DBL *
+- *analysBufferImag, /*!< Imag part of subband samples to be processed */
+- const int useLP,
+- FIXP_DBL *degreeAlias, /*!< Estimated aliasing for each QMF channel */
+- const UINT flags, const int frameErrorFlag);
+-
+-SBR_ERROR
+-createSbrEnvelopeCalc(HANDLE_SBR_CALCULATE_ENVELOPE hSbrCalculateEnvelope,
+- HANDLE_SBR_HEADER_DATA hHeaderData, const int chan,
+- const UINT flags);
+-
+-int deleteSbrEnvelopeCalc(HANDLE_SBR_CALCULATE_ENVELOPE hSbrCalculateEnvelope);
+-
+-void resetSbrEnvelopeCalc(HANDLE_SBR_CALCULATE_ENVELOPE hCalEnv);
+-
+-SBR_ERROR
+-ResetLimiterBands(UCHAR *limiterBandTable, UCHAR *noLimiterBands,
+- UCHAR *freqBandTable, int noFreqBands,
+- const PATCH_PARAM *patchParam, int noPatches,
+- int limiterBands, UCHAR sbrPatchingMode,
+- int xOverQmf[MAX_NUM_PATCHES], int sbrRatio);
+-
+-void rescaleSubbandSamples(FIXP_DBL **re, FIXP_DBL **im, int lowSubband,
+- int noSubbands, int start_pos, int next_pos,
+- int shift);
+-
+-FIXP_DBL maxSubbandSample(FIXP_DBL **analysBufferReal_m,
+- FIXP_DBL **analysBufferImag_m, int lowSubband,
+- int highSubband, int start_pos, int stop_pos);
+-
+-#endif // ENV_CALC_H
+diff --git a/libSBRdec/src/env_dec.cpp b/libSBRdec/src/env_dec.cpp
+deleted file mode 100644
+index 95807c9..0000000
+--- a/libSBRdec/src/env_dec.cpp
++++ /dev/null
+@@ -1,873 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief envelope decoding
+- This module provides envelope decoding and error concealment algorithms. The
+- main entry point is decodeSbrData().
+-
+- \sa decodeSbrData(),\ref documentationOverview
+-*/
+-
+-#include "env_dec.h"
+-
+-#include "env_extr.h"
+-#include "transcendent.h"
+-
+-#include "genericStds.h"
+-
+-static void decodeEnvelope(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_sbr_data,
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data,
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data_otherChannel);
+-static void sbr_envelope_unmapping(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_data_left,
+- HANDLE_SBR_FRAME_DATA h_data_right);
+-static void requantizeEnvelopeData(HANDLE_SBR_FRAME_DATA h_sbr_data,
+- int ampResolution);
+-static void deltaToLinearPcmEnvelopeDecoding(
+- HANDLE_SBR_HEADER_DATA hHeaderData, HANDLE_SBR_FRAME_DATA h_sbr_data,
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data);
+-static void decodeNoiseFloorlevels(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_sbr_data,
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data);
+-static void timeCompensateFirstEnvelope(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_sbr_data,
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data);
+-static int checkEnvelopeData(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_sbr_data,
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data);
+-
+-#define SBR_ENERGY_PAN_OFFSET (12 << ENV_EXP_FRACT)
+-#define SBR_MAX_ENERGY (35 << ENV_EXP_FRACT)
+-
+-#define DECAY (1 << ENV_EXP_FRACT)
+-
+-#if ENV_EXP_FRACT
+-#define DECAY_COUPLING \
+- (1 << (ENV_EXP_FRACT - 1)) /*!< corresponds to a value of 0.5 */
+-#else
+-#define DECAY_COUPLING \
+- 1 /*!< If the energy data is not shifted, use 1 instead of 0.5 */
+-#endif
+-
+-/*!
+- \brief Convert table index
+-*/
+-static int indexLow2High(int offset, /*!< mapping factor */
+- int index, /*!< index to scalefactor band */
+- int res) /*!< frequency resolution */
+-{
+- if (res == 0) {
+- if (offset >= 0) {
+- if (index < offset)
+- return (index);
+- else
+- return (2 * index - offset);
+- } else {
+- offset = -offset;
+- if (index < offset)
+- return (2 * index + index);
+- else
+- return (2 * index + offset);
+- }
+- } else
+- return (index);
+-}
+-
+-/*!
+- \brief Update previous envelope value for delta-coding
+-
+- The current envelope values needs to be stored for delta-coding
+- in the next frame. The stored envelope is always represented with
+- the high frequency resolution. If the current envelope uses the
+- low frequency resolution, the energy value will be mapped to the
+- corresponding high-res bands.
+-*/
+-static void mapLowResEnergyVal(
+- FIXP_SGL currVal, /*!< current energy value */
+- FIXP_SGL *prevData, /*!< pointer to previous data vector */
+- int offset, /*!< mapping factor */
+- int index, /*!< index to scalefactor band */
+- int res) /*!< frequeny resolution */
+-{
+- if (res == 0) {
+- if (offset >= 0) {
+- if (index < offset)
+- prevData[index] = currVal;
+- else {
+- prevData[2 * index - offset] = currVal;
+- prevData[2 * index + 1 - offset] = currVal;
+- }
+- } else {
+- offset = -offset;
+- if (index < offset) {
+- prevData[3 * index] = currVal;
+- prevData[3 * index + 1] = currVal;
+- prevData[3 * index + 2] = currVal;
+- } else {
+- prevData[2 * index + offset] = currVal;
+- prevData[2 * index + 1 + offset] = currVal;
+- }
+- }
+- } else
+- prevData[index] = currVal;
+-}
+-
+-/*!
+- \brief Convert raw envelope and noisefloor data to energy levels
+-
+- This function is being called by sbrDecoder_ParseElement() and provides two
+- important algorithms:
+-
+- First the function decodes envelopes and noise floor levels as described in
+- requantizeEnvelopeData() and sbr_envelope_unmapping(). The function also
+- implements concealment algorithms in case there are errors within the sbr
+- data. For both operations fractional arithmetic is used. Therefore you might
+- encounter different output values on your target system compared to the
+- reference implementation.
+-*/
+-void decodeSbrData(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA
+- h_data_left, /*!< pointer to left channel frame data */
+- HANDLE_SBR_PREV_FRAME_DATA
+- h_prev_data_left, /*!< pointer to left channel previous frame data */
+- HANDLE_SBR_FRAME_DATA
+- h_data_right, /*!< pointer to right channel frame data */
+- HANDLE_SBR_PREV_FRAME_DATA
+- h_prev_data_right) /*!< pointer to right channel previous frame data */
+-{
+- FIXP_SGL tempSfbNrgPrev[MAX_FREQ_COEFFS];
+- int errLeft;
+-
+- /* Save previous energy values to be able to reuse them later for concealment.
+- */
+- FDKmemcpy(tempSfbNrgPrev, h_prev_data_left->sfb_nrg_prev,
+- MAX_FREQ_COEFFS * sizeof(FIXP_SGL));
+-
+- if (hHeaderData->frameErrorFlag || hHeaderData->bs_info.pvc_mode == 0) {
+- decodeEnvelope(hHeaderData, h_data_left, h_prev_data_left,
+- h_prev_data_right);
+- } else {
+- FDK_ASSERT(h_data_right == NULL);
+- }
+- decodeNoiseFloorlevels(hHeaderData, h_data_left, h_prev_data_left);
+-
+- if (h_data_right != NULL) {
+- errLeft = hHeaderData->frameErrorFlag;
+- decodeEnvelope(hHeaderData, h_data_right, h_prev_data_right,
+- h_prev_data_left);
+- decodeNoiseFloorlevels(hHeaderData, h_data_right, h_prev_data_right);
+-
+- if (!errLeft && hHeaderData->frameErrorFlag) {
+- /* If an error occurs in the right channel where the left channel seemed
+- ok, we apply concealment also on the left channel. This ensures that
+- the coupling modes of both channels match and that we have the same
+- number of envelopes in coupling mode. However, as the left channel has
+- already been processed before, the resulting energy levels are not the
+- same as if the left channel had been concealed during the first call of
+- decodeEnvelope().
+- */
+- /* Restore previous energy values for concealment, because the values have
+- been overwritten by the first call of decodeEnvelope(). */
+- FDKmemcpy(h_prev_data_left->sfb_nrg_prev, tempSfbNrgPrev,
+- MAX_FREQ_COEFFS * sizeof(FIXP_SGL));
+- /* Do concealment */
+- decodeEnvelope(hHeaderData, h_data_left, h_prev_data_left,
+- h_prev_data_right);
+- }
+-
+- if (h_data_left->coupling) {
+- sbr_envelope_unmapping(hHeaderData, h_data_left, h_data_right);
+- }
+- }
+-
+- /* Display the data for debugging: */
+-}
+-
+-/*!
+- \brief Convert from coupled channels to independent L/R data
+-*/
+-static void sbr_envelope_unmapping(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_data_left, /*!< pointer to left channel */
+- HANDLE_SBR_FRAME_DATA h_data_right) /*!< pointer to right channel */
+-{
+- int i;
+- FIXP_SGL tempL_m, tempR_m, tempRplus1_m, newL_m, newR_m;
+- SCHAR tempL_e, tempR_e, tempRplus1_e, newL_e, newR_e;
+-
+- /* 1. Unmap (already dequantized) coupled envelope energies */
+-
+- for (i = 0; i < h_data_left->nScaleFactors; i++) {
+- tempR_m = (FIXP_SGL)((LONG)h_data_right->iEnvelope[i] & MASK_M);
+- tempR_e = (SCHAR)((LONG)h_data_right->iEnvelope[i] & MASK_E);
+-
+- tempR_e -= (18 + NRG_EXP_OFFSET); /* -18 = ld(UNMAPPING_SCALE /
+- h_data_right->nChannels) */
+- tempL_m = (FIXP_SGL)((LONG)h_data_left->iEnvelope[i] & MASK_M);
+- tempL_e = (SCHAR)((LONG)h_data_left->iEnvelope[i] & MASK_E);
+-
+- tempL_e -= NRG_EXP_OFFSET;
+-
+- /* Calculate tempRight+1 */
+- FDK_add_MantExp(tempR_m, tempR_e, FL2FXCONST_SGL(0.5f), 1, /* 1.0 */
+- &tempRplus1_m, &tempRplus1_e);
+-
+- FDK_divide_MantExp(tempL_m, tempL_e + 1, /* 2 * tempLeft */
+- tempRplus1_m, tempRplus1_e, &newR_m, &newR_e);
+-
+- if (newR_m >= ((FIXP_SGL)MAXVAL_SGL - ROUNDING)) {
+- newR_m >>= 1;
+- newR_e += 1;
+- }
+-
+- newL_m = FX_DBL2FX_SGL(fMult(tempR_m, newR_m));
+- newL_e = tempR_e + newR_e;
+-
+- h_data_right->iEnvelope[i] =
+- ((FIXP_SGL)((SHORT)(FIXP_SGL)(newR_m + ROUNDING) & MASK_M)) +
+- (FIXP_SGL)((SHORT)(FIXP_SGL)(newR_e + NRG_EXP_OFFSET) & MASK_E);
+- h_data_left->iEnvelope[i] =
+- ((FIXP_SGL)((SHORT)(FIXP_SGL)(newL_m + ROUNDING) & MASK_M)) +
+- (FIXP_SGL)((SHORT)(FIXP_SGL)(newL_e + NRG_EXP_OFFSET) & MASK_E);
+- }
+-
+- /* 2. Dequantize and unmap coupled noise floor levels */
+-
+- for (i = 0; i < hHeaderData->freqBandData.nNfb *
+- h_data_left->frameInfo.nNoiseEnvelopes;
+- i++) {
+- tempL_e = (SCHAR)(6 - (LONG)h_data_left->sbrNoiseFloorLevel[i]);
+- tempR_e = (SCHAR)((LONG)h_data_right->sbrNoiseFloorLevel[i] -
+- 12) /*SBR_ENERGY_PAN_OFFSET*/;
+-
+- /* Calculate tempR+1 */
+- FDK_add_MantExp(FL2FXCONST_SGL(0.5f), 1 + tempR_e, /* tempR */
+- FL2FXCONST_SGL(0.5f), 1, /* 1.0 */
+- &tempRplus1_m, &tempRplus1_e);
+-
+- /* Calculate 2*tempLeft/(tempR+1) */
+- FDK_divide_MantExp(FL2FXCONST_SGL(0.5f), tempL_e + 2, /* 2 * tempLeft */
+- tempRplus1_m, tempRplus1_e, &newR_m, &newR_e);
+-
+- /* if (newR_m >= ((FIXP_SGL)MAXVAL_SGL - ROUNDING)) {
+- newR_m >>= 1;
+- newR_e += 1;
+- } */
+-
+- /* L = tempR * R */
+- newL_m = newR_m;
+- newL_e = newR_e + tempR_e;
+- h_data_right->sbrNoiseFloorLevel[i] =
+- ((FIXP_SGL)((SHORT)(FIXP_SGL)(newR_m + ROUNDING) & MASK_M)) +
+- (FIXP_SGL)((SHORT)(FIXP_SGL)(newR_e + NOISE_EXP_OFFSET) & MASK_E);
+- h_data_left->sbrNoiseFloorLevel[i] =
+- ((FIXP_SGL)((SHORT)(FIXP_SGL)(newL_m + ROUNDING) & MASK_M)) +
+- (FIXP_SGL)((SHORT)(FIXP_SGL)(newL_e + NOISE_EXP_OFFSET) & MASK_E);
+- }
+-}
+-
+-/*!
+- \brief Simple alternative to the real SBR concealment
+-
+- If the real frameInfo is not available due to a frame loss, a replacement will
+- be constructed with 1 envelope spanning the whole frame (FIX-FIX).
+- The delta-coded energies are set to negative values, resulting in a fade-down.
+- In case of coupling, the balance-channel will move towards the center.
+-*/
+-static void leanSbrConcealment(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_sbr_data, /*!< pointer to current data */
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data /*!< pointer to data of last frame */
+-) {
+- FIXP_SGL target; /* targeted level for sfb_nrg_prev during fade-down */
+- FIXP_SGL step; /* speed of fade */
+- int i;
+-
+- int currentStartPos =
+- fMax(0, h_prev_data->stopPos - hHeaderData->numberTimeSlots);
+- int currentStopPos = hHeaderData->numberTimeSlots;
+-
+- /* Use some settings of the previous frame */
+- h_sbr_data->ampResolutionCurrentFrame = h_prev_data->ampRes;
+- h_sbr_data->coupling = h_prev_data->coupling;
+- for (i = 0; i < MAX_INVF_BANDS; i++)
+- h_sbr_data->sbr_invf_mode[i] = h_prev_data->sbr_invf_mode[i];
+-
+- /* Generate concealing control data */
+-
+- h_sbr_data->frameInfo.nEnvelopes = 1;
+- h_sbr_data->frameInfo.borders[0] = currentStartPos;
+- h_sbr_data->frameInfo.borders[1] = currentStopPos;
+- h_sbr_data->frameInfo.freqRes[0] = 1;
+- h_sbr_data->frameInfo.tranEnv = -1; /* no transient */
+- h_sbr_data->frameInfo.nNoiseEnvelopes = 1;
+- h_sbr_data->frameInfo.bordersNoise[0] = currentStartPos;
+- h_sbr_data->frameInfo.bordersNoise[1] = currentStopPos;
+-
+- h_sbr_data->nScaleFactors = hHeaderData->freqBandData.nSfb[1];
+-
+- /* Generate fake envelope data */
+-
+- h_sbr_data->domain_vec[0] = 1;
+-
+- if (h_sbr_data->coupling == COUPLING_BAL) {
+- target = (FIXP_SGL)SBR_ENERGY_PAN_OFFSET;
+- step = (FIXP_SGL)DECAY_COUPLING;
+- } else {
+- target = FL2FXCONST_SGL(0.0f);
+- step = (FIXP_SGL)DECAY;
+- }
+- if (hHeaderData->bs_info.ampResolution == 0) {
+- target <<= 1;
+- step <<= 1;
+- }
+-
+- for (i = 0; i < h_sbr_data->nScaleFactors; i++) {
+- if (h_prev_data->sfb_nrg_prev[i] > target)
+- h_sbr_data->iEnvelope[i] = -step;
+- else
+- h_sbr_data->iEnvelope[i] = step;
+- }
+-
+- /* Noisefloor levels are always cleared ... */
+-
+- h_sbr_data->domain_vec_noise[0] = 1;
+- FDKmemclear(h_sbr_data->sbrNoiseFloorLevel,
+- sizeof(h_sbr_data->sbrNoiseFloorLevel));
+-
+- /* ... and so are the sines */
+- FDKmemclear(h_sbr_data->addHarmonics,
+- sizeof(ULONG) * ADD_HARMONICS_FLAGS_SIZE);
+-}
+-
+-/*!
+- \brief Build reference energies and noise levels from bitstream elements
+-*/
+-static void decodeEnvelope(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_sbr_data, /*!< pointer to current data */
+- HANDLE_SBR_PREV_FRAME_DATA
+- h_prev_data, /*!< pointer to data of last frame */
+- HANDLE_SBR_PREV_FRAME_DATA
+- otherChannel /*!< other channel's last frame data */
+-) {
+- int i;
+- int fFrameError = hHeaderData->frameErrorFlag;
+- FIXP_SGL tempSfbNrgPrev[MAX_FREQ_COEFFS];
+-
+- if (!fFrameError) {
+- /*
+- To avoid distortions after bad frames, set the error flag if delta coding
+- in time occurs. However, SBR can take a little longer to come up again.
+- */
+- if (h_prev_data->frameErrorFlag) {
+- if (h_sbr_data->domain_vec[0] != 0) {
+- fFrameError = 1;
+- }
+- } else {
+- /* Check that the previous stop position and the current start position
+- match. (Could be done in checkFrameInfo(), but the previous frame data
+- is not available there) */
+- if (h_sbr_data->frameInfo.borders[0] !=
+- h_prev_data->stopPos - hHeaderData->numberTimeSlots) {
+- /* Both the previous as well as the current frame are flagged to be ok,
+- * but they do not match! */
+- if (h_sbr_data->domain_vec[0] == 1) {
+- /* Prefer concealment over delta-time coding between the mismatching
+- * frames */
+- fFrameError = 1;
+- } else {
+- /* Close the gap in time by triggering timeCompensateFirstEnvelope()
+- */
+- fFrameError = 1;
+- }
+- }
+- }
+- }
+-
+- if (fFrameError) /* Error is detected */
+- {
+- leanSbrConcealment(hHeaderData, h_sbr_data, h_prev_data);
+-
+- /* decode the envelope data to linear PCM */
+- deltaToLinearPcmEnvelopeDecoding(hHeaderData, h_sbr_data, h_prev_data);
+- } else /*Do a temporary dummy decoding and check that the envelope values are
+- within limits */
+- {
+- if (h_prev_data->frameErrorFlag) {
+- timeCompensateFirstEnvelope(hHeaderData, h_sbr_data, h_prev_data);
+- if (h_sbr_data->coupling != h_prev_data->coupling) {
+- /*
+- Coupling mode has changed during concealment.
+- The stored energy levels need to be converted.
+- */
+- for (i = 0; i < hHeaderData->freqBandData.nSfb[1]; i++) {
+- /* Former Level-Channel will be used for both channels */
+- if (h_prev_data->coupling == COUPLING_BAL) {
+- h_prev_data->sfb_nrg_prev[i] =
+- (otherChannel != NULL) ? otherChannel->sfb_nrg_prev[i]
+- : (FIXP_SGL)SBR_ENERGY_PAN_OFFSET;
+- }
+- /* Former L/R will be combined as the new Level-Channel */
+- else if (h_sbr_data->coupling == COUPLING_LEVEL &&
+- otherChannel != NULL) {
+- h_prev_data->sfb_nrg_prev[i] = (h_prev_data->sfb_nrg_prev[i] +
+- otherChannel->sfb_nrg_prev[i]) >>
+- 1;
+- } else if (h_sbr_data->coupling == COUPLING_BAL) {
+- h_prev_data->sfb_nrg_prev[i] = (FIXP_SGL)SBR_ENERGY_PAN_OFFSET;
+- }
+- }
+- }
+- }
+- FDKmemcpy(tempSfbNrgPrev, h_prev_data->sfb_nrg_prev,
+- MAX_FREQ_COEFFS * sizeof(FIXP_SGL));
+-
+- deltaToLinearPcmEnvelopeDecoding(hHeaderData, h_sbr_data, h_prev_data);
+-
+- fFrameError = checkEnvelopeData(hHeaderData, h_sbr_data, h_prev_data);
+-
+- if (fFrameError) {
+- hHeaderData->frameErrorFlag = 1;
+- FDKmemcpy(h_prev_data->sfb_nrg_prev, tempSfbNrgPrev,
+- MAX_FREQ_COEFFS * sizeof(FIXP_SGL));
+- decodeEnvelope(hHeaderData, h_sbr_data, h_prev_data, otherChannel);
+- return;
+- }
+- }
+-
+- requantizeEnvelopeData(h_sbr_data, h_sbr_data->ampResolutionCurrentFrame);
+-
+- hHeaderData->frameErrorFlag = fFrameError;
+-}
+-
+-/*!
+- \brief Verify that envelope energies are within the allowed range
+- \return 0 if all is fine, 1 if an envelope value was too high
+-*/
+-static int checkEnvelopeData(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_sbr_data, /*!< pointer to current data */
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data /*!< pointer to data of last frame */
+-) {
+- FIXP_SGL *iEnvelope = h_sbr_data->iEnvelope;
+- FIXP_SGL *sfb_nrg_prev = h_prev_data->sfb_nrg_prev;
+- int i = 0, errorFlag = 0;
+- FIXP_SGL sbr_max_energy = (h_sbr_data->ampResolutionCurrentFrame == 1)
+- ? SBR_MAX_ENERGY
+- : (SBR_MAX_ENERGY << 1);
+-
+- /*
+- Range check for current energies
+- */
+- for (i = 0; i < h_sbr_data->nScaleFactors; i++) {
+- if (iEnvelope[i] > sbr_max_energy) {
+- errorFlag = 1;
+- }
+- if (iEnvelope[i] < FL2FXCONST_SGL(0.0f)) {
+- errorFlag = 1;
+- /* iEnvelope[i] = FL2FXCONST_SGL(0.0f); */
+- }
+- }
+-
+- /*
+- Range check for previous energies
+- */
+- for (i = 0; i < hHeaderData->freqBandData.nSfb[1]; i++) {
+- sfb_nrg_prev[i] = fixMax(sfb_nrg_prev[i], FL2FXCONST_SGL(0.0f));
+- sfb_nrg_prev[i] = fixMin(sfb_nrg_prev[i], sbr_max_energy);
+- }
+-
+- return (errorFlag);
+-}
+-
+-/*!
+- \brief Verify that the noise levels are within the allowed range
+-
+- The function is equivalent to checkEnvelopeData().
+- When the noise-levels are being decoded, it is already too late for
+- concealment. Therefore the noise levels are simply limited here.
+-*/
+-static void limitNoiseLevels(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_sbr_data) /*!< pointer to current data */
+-{
+- int i;
+- int nNfb = hHeaderData->freqBandData.nNfb;
+-
+-/*
+- Set range limits. The exact values depend on the coupling mode.
+- However this limitation is primarily intended to avoid unlimited
+- accumulation of the delta-coded noise levels.
+-*/
+-#define lowerLimit \
+- ((FIXP_SGL)0) /* lowerLimit actually refers to the _highest_ noise energy */
+-#define upperLimit \
+- ((FIXP_SGL)35) /* upperLimit actually refers to the _lowest_ noise energy */
+-
+- /*
+- Range check for current noise levels
+- */
+- for (i = 0; i < h_sbr_data->frameInfo.nNoiseEnvelopes * nNfb; i++) {
+- h_sbr_data->sbrNoiseFloorLevel[i] =
+- fixMin(h_sbr_data->sbrNoiseFloorLevel[i], upperLimit);
+- h_sbr_data->sbrNoiseFloorLevel[i] =
+- fixMax(h_sbr_data->sbrNoiseFloorLevel[i], lowerLimit);
+- }
+-}
+-
+-/*!
+- \brief Compensate for the wrong timing that might occur after a frame error.
+-*/
+-static void timeCompensateFirstEnvelope(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_sbr_data, /*!< pointer to actual data */
+- HANDLE_SBR_PREV_FRAME_DATA
+- h_prev_data) /*!< pointer to data of last frame */
+-{
+- int i, nScalefactors;
+- FRAME_INFO *pFrameInfo = &h_sbr_data->frameInfo;
+- UCHAR *nSfb = hHeaderData->freqBandData.nSfb;
+- int estimatedStartPos =
+- fMax(0, h_prev_data->stopPos - hHeaderData->numberTimeSlots);
+- int refLen, newLen, shift;
+- FIXP_SGL deltaExp;
+-
+- /* Original length of first envelope according to bitstream */
+- refLen = pFrameInfo->borders[1] - pFrameInfo->borders[0];
+- /* Corrected length of first envelope (concealing can make the first envelope
+- * longer) */
+- newLen = pFrameInfo->borders[1] - estimatedStartPos;
+-
+- if (newLen <= 0) {
+- /* An envelope length of <= 0 would not work, so we don't use it.
+- May occur if the previous frame was flagged bad due to a mismatch
+- of the old and new frame infos. */
+- newLen = refLen;
+- estimatedStartPos = pFrameInfo->borders[0];
+- }
+-
+- deltaExp = FDK_getNumOctavesDiv8(newLen, refLen);
+-
+- /* Shift by -3 to rescale ld-table, ampRes-1 to enable coarser steps */
+- shift = (FRACT_BITS - 1 - ENV_EXP_FRACT - 1 +
+- h_sbr_data->ampResolutionCurrentFrame - 3);
+- deltaExp = deltaExp >> shift;
+- pFrameInfo->borders[0] = estimatedStartPos;
+- pFrameInfo->bordersNoise[0] = estimatedStartPos;
+-
+- if (h_sbr_data->coupling != COUPLING_BAL) {
+- nScalefactors = (pFrameInfo->freqRes[0]) ? nSfb[1] : nSfb[0];
+-
+- for (i = 0; i < nScalefactors; i++)
+- h_sbr_data->iEnvelope[i] = h_sbr_data->iEnvelope[i] + deltaExp;
+- }
+-}
+-
+-/*!
+- \brief Convert each envelope value from logarithmic to linear domain
+-
+- Energy levels are transmitted in powers of 2, i.e. only the exponent
+- is extracted from the bitstream.
+- Therefore, normally only integer exponents can occur. However during
+- fading (in case of a corrupt bitstream), a fractional part can also
+- occur. The data in the array iEnvelope is shifted left by ENV_EXP_FRACT
+- compared to an integer representation so that numbers smaller than 1
+- can be represented.
+-
+- This function calculates a mantissa corresponding to the fractional
+- part of the exponent for each reference energy. The array iEnvelope
+- is converted in place to save memory. Input and output data must
+- be interpreted differently, as shown in the below figure:
+-
+- \image html EnvelopeData.png
+-
+- The data is then used in calculateSbrEnvelope().
+-*/
+-static void requantizeEnvelopeData(HANDLE_SBR_FRAME_DATA h_sbr_data,
+- int ampResolution) {
+- int i;
+- FIXP_SGL mantissa;
+- int ampShift = 1 - ampResolution;
+- int exponent;
+-
+- /* In case that ENV_EXP_FRACT is changed to something else but 0 or 8,
+- the initialization of this array has to be adapted!
+- */
+-#if ENV_EXP_FRACT
+- static const FIXP_SGL pow2[ENV_EXP_FRACT] = {
+- FL2FXCONST_SGL(0.5f * pow(2.0f, pow(0.5f, 1))), /* 0.7071 */
+- FL2FXCONST_SGL(0.5f * pow(2.0f, pow(0.5f, 2))), /* 0.5946 */
+- FL2FXCONST_SGL(0.5f * pow(2.0f, pow(0.5f, 3))),
+- FL2FXCONST_SGL(0.5f * pow(2.0f, pow(0.5f, 4))),
+- FL2FXCONST_SGL(0.5f * pow(2.0f, pow(0.5f, 5))),
+- FL2FXCONST_SGL(0.5f * pow(2.0f, pow(0.5f, 6))),
+- FL2FXCONST_SGL(0.5f * pow(2.0f, pow(0.5f, 7))),
+- FL2FXCONST_SGL(0.5f * pow(2.0f, pow(0.5f, 8))) /* 0.5013 */
+- };
+-
+- int bit, mask;
+-#endif
+-
+- for (i = 0; i < h_sbr_data->nScaleFactors; i++) {
+- exponent = (LONG)h_sbr_data->iEnvelope[i];
+-
+-#if ENV_EXP_FRACT
+-
+- exponent = exponent >> ampShift;
+- mantissa = 0.5f;
+-
+- /* Amplify mantissa according to the fractional part of the
+- exponent (result will be between 0.500000 and 0.999999)
+- */
+- mask = 1; /* begin with lowest bit of exponent */
+-
+- for (bit = ENV_EXP_FRACT - 1; bit >= 0; bit--) {
+- if (exponent & mask) {
+- /* The current bit of the exponent is set,
+- multiply mantissa with the corresponding factor: */
+- mantissa = (FIXP_SGL)((mantissa * pow2[bit]) << 1);
+- }
+- /* Advance to next bit */
+- mask = mask << 1;
+- }
+-
+- /* Make integer part of exponent right aligned */
+- exponent = exponent >> ENV_EXP_FRACT;
+-
+-#else
+- /* In case of the high amplitude resolution, 1 bit of the exponent gets lost
+- by the shift. This will be compensated by a mantissa of 0.5*sqrt(2)
+- instead of 0.5 if that bit is 1. */
+- mantissa = (exponent & ampShift) ? FL2FXCONST_SGL(0.707106781186548f)
+- : FL2FXCONST_SGL(0.5f);
+- exponent = exponent >> ampShift;
+-#endif
+-
+- /*
+- Mantissa was set to 0.5 (instead of 1.0, therefore increase exponent by
+- 1). Multiply by L=nChannels=64 by increasing exponent by another 6.
+- => Increase exponent by 7
+- */
+- exponent += 7 + NRG_EXP_OFFSET;
+-
+- /* Combine mantissa and exponent and write back the result */
+- h_sbr_data->iEnvelope[i] =
+- ((FIXP_SGL)((SHORT)(FIXP_SGL)mantissa & MASK_M)) +
+- (FIXP_SGL)((SHORT)(FIXP_SGL)exponent & MASK_E);
+- }
+-}
+-
+-/*!
+- \brief Build new reference energies from old ones and delta coded data
+-*/
+-static void deltaToLinearPcmEnvelopeDecoding(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_sbr_data, /*!< pointer to current data */
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data) /*!< pointer to previous data */
+-{
+- int i, domain, no_of_bands, band, freqRes;
+-
+- FIXP_SGL *sfb_nrg_prev = h_prev_data->sfb_nrg_prev;
+- FIXP_SGL *ptr_nrg = h_sbr_data->iEnvelope;
+-
+- int offset =
+- 2 * hHeaderData->freqBandData.nSfb[0] - hHeaderData->freqBandData.nSfb[1];
+-
+- for (i = 0; i < h_sbr_data->frameInfo.nEnvelopes; i++) {
+- domain = h_sbr_data->domain_vec[i];
+- freqRes = h_sbr_data->frameInfo.freqRes[i];
+-
+- FDK_ASSERT(freqRes >= 0 && freqRes <= 1);
+-
+- no_of_bands = hHeaderData->freqBandData.nSfb[freqRes];
+-
+- FDK_ASSERT(no_of_bands < (64));
+-
+- if (domain == 0) {
+- mapLowResEnergyVal(*ptr_nrg, sfb_nrg_prev, offset, 0, freqRes);
+- ptr_nrg++;
+- for (band = 1; band < no_of_bands; band++) {
+- *ptr_nrg = *ptr_nrg + *(ptr_nrg - 1);
+- mapLowResEnergyVal(*ptr_nrg, sfb_nrg_prev, offset, band, freqRes);
+- ptr_nrg++;
+- }
+- } else {
+- for (band = 0; band < no_of_bands; band++) {
+- *ptr_nrg =
+- *ptr_nrg + sfb_nrg_prev[indexLow2High(offset, band, freqRes)];
+- mapLowResEnergyVal(*ptr_nrg, sfb_nrg_prev, offset, band, freqRes);
+- ptr_nrg++;
+- }
+- }
+- }
+-}
+-
+-/*!
+- \brief Build new noise levels from old ones and delta coded data
+-*/
+-static void decodeNoiseFloorlevels(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_sbr_data, /*!< pointer to current data */
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data) /*!< pointer to previous data */
+-{
+- int i;
+- int nNfb = hHeaderData->freqBandData.nNfb;
+- int nNoiseFloorEnvelopes = h_sbr_data->frameInfo.nNoiseEnvelopes;
+-
+- /* Decode first noise envelope */
+-
+- if (h_sbr_data->domain_vec_noise[0] == 0) {
+- FIXP_SGL noiseLevel = h_sbr_data->sbrNoiseFloorLevel[0];
+- for (i = 1; i < nNfb; i++) {
+- noiseLevel += h_sbr_data->sbrNoiseFloorLevel[i];
+- h_sbr_data->sbrNoiseFloorLevel[i] = noiseLevel;
+- }
+- } else {
+- for (i = 0; i < nNfb; i++) {
+- h_sbr_data->sbrNoiseFloorLevel[i] += h_prev_data->prevNoiseLevel[i];
+- }
+- }
+-
+- /* If present, decode the second noise envelope
+- Note: nNoiseFloorEnvelopes can only be 1 or 2 */
+-
+- if (nNoiseFloorEnvelopes > 1) {
+- if (h_sbr_data->domain_vec_noise[1] == 0) {
+- FIXP_SGL noiseLevel = h_sbr_data->sbrNoiseFloorLevel[nNfb];
+- for (i = nNfb + 1; i < 2 * nNfb; i++) {
+- noiseLevel += h_sbr_data->sbrNoiseFloorLevel[i];
+- h_sbr_data->sbrNoiseFloorLevel[i] = noiseLevel;
+- }
+- } else {
+- for (i = 0; i < nNfb; i++) {
+- h_sbr_data->sbrNoiseFloorLevel[i + nNfb] +=
+- h_sbr_data->sbrNoiseFloorLevel[i];
+- }
+- }
+- }
+-
+- limitNoiseLevels(hHeaderData, h_sbr_data);
+-
+- /* Update prevNoiseLevel with the last noise envelope */
+- for (i = 0; i < nNfb; i++)
+- h_prev_data->prevNoiseLevel[i] =
+- h_sbr_data->sbrNoiseFloorLevel[i + nNfb * (nNoiseFloorEnvelopes - 1)];
+-
+- /* Requantize the noise floor levels in COUPLING_OFF-mode */
+- if (!h_sbr_data->coupling) {
+- int nf_e;
+-
+- for (i = 0; i < nNoiseFloorEnvelopes * nNfb; i++) {
+- nf_e = 6 - (LONG)h_sbr_data->sbrNoiseFloorLevel[i] + 1 + NOISE_EXP_OFFSET;
+- /* +1 to compensate for a mantissa of 0.5 instead of 1.0 */
+-
+- h_sbr_data->sbrNoiseFloorLevel[i] =
+- (FIXP_SGL)(((LONG)FL2FXCONST_SGL(0.5f)) + /* mantissa */
+- (nf_e & MASK_E)); /* exponent */
+- }
+- }
+-}
+diff --git a/libSBRdec/src/env_dec.h b/libSBRdec/src/env_dec.h
+deleted file mode 100644
+index 0b11ce1..0000000
+--- a/libSBRdec/src/env_dec.h
++++ /dev/null
+@@ -1,119 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Envelope decoding
+-*/
+-#ifndef ENV_DEC_H
+-#define ENV_DEC_H
+-
+-#include "sbrdecoder.h"
+-#include "env_extr.h"
+-
+-void decodeSbrData(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_data_left,
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data_left,
+- HANDLE_SBR_FRAME_DATA h_data_right,
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_data_right);
+-
+-#endif
+diff --git a/libSBRdec/src/env_extr.cpp b/libSBRdec/src/env_extr.cpp
+deleted file mode 100644
+index c72a7b6..0000000
+--- a/libSBRdec/src/env_extr.cpp
++++ /dev/null
+@@ -1,1728 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Envelope extraction
+- The functions provided by this module are mostly called by applySBR(). After
+- it is determined that there is valid SBR data, sbrGetHeaderData() might be
+- called if the current SBR data contains an \ref SBR_HEADER_ELEMENT as opposed
+- to a \ref SBR_STANDARD_ELEMENT. This function may return various error codes
+- as defined in #SBR_HEADER_STATUS . Most importantly it returns HEADER_RESET
+- when decoder settings need to be recalculated according to the SBR
+- specifications. In that case applySBR() will initiatite the required
+- re-configuration.
+-
+- The header data is stored in a #SBR_HEADER_DATA structure.
+-
+- The actual SBR data for the current frame is decoded into SBR_FRAME_DATA
+- stuctures by sbrGetChannelPairElement() [for stereo streams] and
+- sbrGetSingleChannelElement() [for mono streams]. There is no fractional
+- arithmetic involved.
+-
+- Once the information is extracted, the data needs to be further prepared
+- before the actual decoding process. This is done in decodeSbrData().
+-
+- \sa Description of buffer management in applySBR(). \ref documentationOverview
+-
+- <h1>About the SBR data format:</h1>
+-
+- Each frame includes SBR data (side chain information), and can be either the
+- \ref SBR_HEADER_ELEMENT or the \ref SBR_STANDARD_ELEMENT. Parts of the data
+- can be protected by a CRC checksum.
+-
+- \anchor SBR_HEADER_ELEMENT <h2>The SBR_HEADER_ELEMENT</h2>
+-
+- The SBR_HEADER_ELEMENT can be transmitted with every frame, however, it
+- typically is send every second or so. It contains fundamental information such
+- as SBR sampling frequency and frequency range as well as control signals that
+- do not require frequent changes. It also includes the \ref
+- SBR_STANDARD_ELEMENT.
+-
+- Depending on the changes between the information in a current
+- SBR_HEADER_ELEMENT and the previous SBR_HEADER_ELEMENT, the SBR decoder might
+- need to be reset and reconfigured (e.g. new tables need to be calculated).
+-
+- \anchor SBR_STANDARD_ELEMENT <h2>The SBR_STANDARD_ELEMENT</h2>
+-
+- This data can be subdivided into "side info" and "raw data", where side info
+- is defined as signals needed to decode the raw data and some decoder tuning
+- signals. Raw data is referred to as PCM and Huffman coded envelope and noise
+- floor estimates. The side info also includes information about the
+- time-frequency grid for the current frame.
+-
+- \sa \ref documentationOverview
+-*/
+-
+-#include "env_extr.h"
+-
+-#include "sbr_ram.h"
+-#include "sbr_rom.h"
+-#include "huff_dec.h"
+-
+-#include "psbitdec.h"
+-
+-#define DRM_PARAMETRIC_STEREO 0
+-#define EXTENSION_ID_PS_CODING 2
+-
+-static int extractPvcFrameInfo(
+- HANDLE_FDK_BITSTREAM hBs, /*!< bitbuffer handle */
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_frame_data, /*!< pointer to memory where the
+- frame-info will be stored */
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_frame_data, /*!< pointer to memory where
+- the previous frame-info
+- will be stored */
+- UCHAR pvc_mode_last, /**< PVC mode of last frame */
+- const UINT flags);
+-static int extractFrameInfo(HANDLE_FDK_BITSTREAM hBs,
+- HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_frame_data,
+- const UINT nrOfChannels, const UINT flags);
+-
+-static int sbrGetPvcEnvelope(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_frame_data,
+- HANDLE_FDK_BITSTREAM hBs, const UINT flags,
+- const UINT pvcMode);
+-static int sbrGetEnvelope(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_frame_data,
+- HANDLE_FDK_BITSTREAM hBs, const UINT flags);
+-
+-static void sbrGetDirectionControlData(HANDLE_SBR_FRAME_DATA hFrameData,
+- HANDLE_FDK_BITSTREAM hBs,
+- const UINT flags, const int bs_pvc_mode);
+-
+-static void sbrGetNoiseFloorData(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA h_frame_data,
+- HANDLE_FDK_BITSTREAM hBs);
+-
+-static int checkFrameInfo(FRAME_INFO *pFrameInfo, int numberOfTimeSlots,
+- int overlap, int timeStep);
+-
+-/* Mapping to std samplerate table according to 14496-3 (4.6.18.2.6) */
+-typedef struct SR_MAPPING {
+- UINT fsRangeLo; /* If fsRangeLo(n+1)>fs>=fsRangeLo(n), it will be mapped to...
+- */
+- UINT fsMapped; /* fsMapped. */
+-} SR_MAPPING;
+-
+-static const SR_MAPPING stdSampleRatesMapping[] = {
+- {0, 8000}, {9391, 11025}, {11502, 12000}, {13856, 16000},
+- {18783, 22050}, {23004, 24000}, {27713, 32000}, {37566, 44100},
+- {46009, 48000}, {55426, 64000}, {75132, 88200}, {92017, 96000}};
+-static const SR_MAPPING stdSampleRatesMappingUsac[] = {
+- {0, 16000}, {18783, 22050}, {23004, 24000}, {27713, 32000},
+- {35777, 40000}, {42000, 44100}, {46009, 48000}, {55426, 64000},
+- {75132, 88200}, {92017, 96000}};
+-
+-UINT sbrdec_mapToStdSampleRate(UINT fs,
+- UINT isUsac) /*!< Output sampling frequency */
+-{
+- UINT fsMapped = fs, tableSize = 0;
+- const SR_MAPPING *mappingTable;
+- int i;
+-
+- if (!isUsac) {
+- mappingTable = stdSampleRatesMapping;
+- tableSize = sizeof(stdSampleRatesMapping) / sizeof(SR_MAPPING);
+- } else {
+- mappingTable = stdSampleRatesMappingUsac;
+- tableSize = sizeof(stdSampleRatesMappingUsac) / sizeof(SR_MAPPING);
+- }
+-
+- for (i = tableSize - 1; i >= 0; i--) {
+- if (fs >= mappingTable[i].fsRangeLo) {
+- fsMapped = mappingTable[i].fsMapped;
+- break;
+- }
+- }
+-
+- return (fsMapped);
+-}
+-
+-SBR_ERROR
+-initHeaderData(HANDLE_SBR_HEADER_DATA hHeaderData, const int sampleRateIn,
+- const int sampleRateOut, const INT downscaleFactor,
+- const int samplesPerFrame, const UINT flags,
+- const int setDefaultHdr) {
+- HANDLE_FREQ_BAND_DATA hFreq = &hHeaderData->freqBandData;
+- SBR_ERROR sbrError = SBRDEC_OK;
+- int numAnalysisBands;
+- int sampleRateProc;
+-
+- if (!(flags & (SBRDEC_SYNTAX_USAC | SBRDEC_SYNTAX_RSVD50))) {
+- sampleRateProc =
+- sbrdec_mapToStdSampleRate(sampleRateOut * downscaleFactor, 0);
+- } else {
+- sampleRateProc = sampleRateOut * downscaleFactor;
+- }
+-
+- if (sampleRateIn == sampleRateOut) {
+- hHeaderData->sbrProcSmplRate = sampleRateProc << 1;
+- numAnalysisBands = 32;
+- } else {
+- hHeaderData->sbrProcSmplRate = sampleRateProc;
+- if ((sampleRateOut >> 1) == sampleRateIn) {
+- /* 1:2 */
+- numAnalysisBands = 32;
+- } else if ((sampleRateOut >> 2) == sampleRateIn) {
+- /* 1:4 */
+- numAnalysisBands = 16;
+- } else if ((sampleRateOut * 3) >> 3 == (sampleRateIn * 8) >> 3) {
+- /* 3:8, 3/4 core frame length */
+- numAnalysisBands = 24;
+- } else {
+- sbrError = SBRDEC_UNSUPPORTED_CONFIG;
+- goto bail;
+- }
+- }
+- numAnalysisBands /= downscaleFactor;
+-
+- if (setDefaultHdr) {
+- /* Fill in default values first */
+- hHeaderData->syncState = SBR_NOT_INITIALIZED;
+- hHeaderData->status = 0;
+- hHeaderData->frameErrorFlag = 0;
+-
+- hHeaderData->bs_info.ampResolution = 1;
+- hHeaderData->bs_info.xover_band = 0;
+- hHeaderData->bs_info.sbr_preprocessing = 0;
+- hHeaderData->bs_info.pvc_mode = 0;
+-
+- hHeaderData->bs_data.startFreq = 5;
+- hHeaderData->bs_data.stopFreq = 0;
+- hHeaderData->bs_data.freqScale =
+- 0; /* previously 2; for ELD reduced delay bitstreams
+- /samplerates initializing of the sbr decoder instance fails if
+- freqScale is set to 2 because no master table can be generated; in
+- ELD reduced delay bitstreams this value is always 0; gets overwritten
+- when header is read */
+- hHeaderData->bs_data.alterScale = 1;
+- hHeaderData->bs_data.noise_bands = 2;
+- hHeaderData->bs_data.limiterBands = 2;
+- hHeaderData->bs_data.limiterGains = 2;
+- hHeaderData->bs_data.interpolFreq = 1;
+- hHeaderData->bs_data.smoothingLength = 1;
+-
+- /* Patch some entries */
+- if (sampleRateOut * downscaleFactor >= 96000) {
+- hHeaderData->bs_data.startFreq =
+- 4; /* having read these frequency values from bit stream before. */
+- hHeaderData->bs_data.stopFreq = 3;
+- } else if (sampleRateOut * downscaleFactor >
+- 24000) { /* Trigger an error if SBR is going to be processed
+- without */
+- hHeaderData->bs_data.startFreq =
+- 7; /* having read these frequency values from bit stream before. */
+- hHeaderData->bs_data.stopFreq = 3;
+- }
+- }
+-
+- if ((sampleRateOut >> 2) == sampleRateIn) {
+- hHeaderData->timeStep = 4;
+- } else {
+- hHeaderData->timeStep = (flags & SBRDEC_ELD_GRID) ? 1 : 2;
+- }
+-
+- /* Setup pointers to frequency band tables */
+- hFreq->freqBandTable[0] = hFreq->freqBandTableLo;
+- hFreq->freqBandTable[1] = hFreq->freqBandTableHi;
+-
+- /* One SBR timeslot corresponds to the amount of samples equal to the amount
+- * of analysis bands, divided by the timestep. */
+- hHeaderData->numberTimeSlots =
+- (samplesPerFrame / numAnalysisBands) >> (hHeaderData->timeStep - 1);
+- if (hHeaderData->numberTimeSlots > (16)) {
+- sbrError = SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- hHeaderData->numberOfAnalysisBands = numAnalysisBands;
+- if ((sampleRateOut >> 2) == sampleRateIn) {
+- hHeaderData->numberTimeSlots <<= 1;
+- }
+-
+-bail:
+- return sbrError;
+-}
+-
+-/*!
+- \brief Initialize the SBR_PREV_FRAME_DATA struct
+-*/
+-void initSbrPrevFrameData(
+- HANDLE_SBR_PREV_FRAME_DATA
+- h_prev_data, /*!< handle to struct SBR_PREV_FRAME_DATA */
+- int timeSlots) /*!< Framelength in SBR-timeslots */
+-{
+- int i;
+-
+- /* Set previous energy and noise levels to 0 for the case
+- that decoding starts in the middle of a bitstream */
+- for (i = 0; i < MAX_FREQ_COEFFS; i++)
+- h_prev_data->sfb_nrg_prev[i] = (FIXP_DBL)0;
+- for (i = 0; i < MAX_NOISE_COEFFS; i++)
+- h_prev_data->prevNoiseLevel[i] = (FIXP_DBL)0;
+- for (i = 0; i < MAX_INVF_BANDS; i++) h_prev_data->sbr_invf_mode[i] = INVF_OFF;
+-
+- h_prev_data->stopPos = timeSlots;
+- h_prev_data->coupling = COUPLING_OFF;
+- h_prev_data->ampRes = 0;
+-
+- FDKmemclear(&h_prev_data->prevFrameInfo, sizeof(h_prev_data->prevFrameInfo));
+-}
+-
+-/*!
+- \brief Read header data from bitstream
+-
+- \return error status - 0 if ok
+-*/
+-SBR_HEADER_STATUS
+-sbrGetHeaderData(HANDLE_SBR_HEADER_DATA hHeaderData, HANDLE_FDK_BITSTREAM hBs,
+- const UINT flags, const int fIsSbrData,
+- const UCHAR configMode) {
+- SBR_HEADER_DATA_BS *pBsData;
+- SBR_HEADER_DATA_BS lastHeader;
+- SBR_HEADER_DATA_BS_INFO lastInfo;
+- int headerExtra1 = 0, headerExtra2 = 0;
+-
+- /* Read and discard new header in config change detection mode */
+- if (configMode & AC_CM_DET_CFG_CHANGE) {
+- if (!(flags & (SBRDEC_SYNTAX_RSVD50 | SBRDEC_SYNTAX_USAC))) {
+- /* ampResolution */
+- FDKreadBits(hBs, 1);
+- }
+- /* startFreq, stopFreq */
+- FDKpushFor(hBs, 8);
+- if (!(flags & (SBRDEC_SYNTAX_RSVD50 | SBRDEC_SYNTAX_USAC))) {
+- /* xover_band */
+- FDKreadBits(hBs, 3);
+- /* reserved bits */
+- FDKreadBits(hBs, 2);
+- }
+- headerExtra1 = FDKreadBit(hBs);
+- headerExtra2 = FDKreadBit(hBs);
+- FDKpushFor(hBs, 5 * headerExtra1 + 6 * headerExtra2);
+-
+- return HEADER_OK;
+- }
+-
+- /* Copy SBR bit stream header to temporary header */
+- lastHeader = hHeaderData->bs_data;
+- lastInfo = hHeaderData->bs_info;
+-
+- /* Read new header from bitstream */
+- if ((flags & (SBRDEC_SYNTAX_RSVD50 | SBRDEC_SYNTAX_USAC)) && !fIsSbrData) {
+- pBsData = &hHeaderData->bs_dflt;
+- } else {
+- pBsData = &hHeaderData->bs_data;
+- }
+-
+- if (!(flags & (SBRDEC_SYNTAX_RSVD50 | SBRDEC_SYNTAX_USAC))) {
+- hHeaderData->bs_info.ampResolution = FDKreadBits(hBs, 1);
+- }
+-
+- pBsData->startFreq = FDKreadBits(hBs, 4);
+- pBsData->stopFreq = FDKreadBits(hBs, 4);
+-
+- if (!(flags & (SBRDEC_SYNTAX_RSVD50 | SBRDEC_SYNTAX_USAC))) {
+- hHeaderData->bs_info.xover_band = FDKreadBits(hBs, 3);
+- FDKreadBits(hBs, 2);
+- }
+-
+- headerExtra1 = FDKreadBits(hBs, 1);
+- headerExtra2 = FDKreadBits(hBs, 1);
+-
+- /* Handle extra header information */
+- if (headerExtra1) {
+- pBsData->freqScale = FDKreadBits(hBs, 2);
+- pBsData->alterScale = FDKreadBits(hBs, 1);
+- pBsData->noise_bands = FDKreadBits(hBs, 2);
+- } else {
+- pBsData->freqScale = 2;
+- pBsData->alterScale = 1;
+- pBsData->noise_bands = 2;
+- }
+-
+- if (headerExtra2) {
+- pBsData->limiterBands = FDKreadBits(hBs, 2);
+- pBsData->limiterGains = FDKreadBits(hBs, 2);
+- pBsData->interpolFreq = FDKreadBits(hBs, 1);
+- pBsData->smoothingLength = FDKreadBits(hBs, 1);
+- } else {
+- pBsData->limiterBands = 2;
+- pBsData->limiterGains = 2;
+- pBsData->interpolFreq = 1;
+- pBsData->smoothingLength = 1;
+- }
+-
+- /* Look for new settings. IEC 14496-3, 4.6.18.3.1 */
+- if (hHeaderData->syncState < SBR_HEADER ||
+- lastHeader.startFreq != pBsData->startFreq ||
+- lastHeader.stopFreq != pBsData->stopFreq ||
+- lastHeader.freqScale != pBsData->freqScale ||
+- lastHeader.alterScale != pBsData->alterScale ||
+- lastHeader.noise_bands != pBsData->noise_bands ||
+- lastInfo.xover_band != hHeaderData->bs_info.xover_band) {
+- return HEADER_RESET; /* New settings */
+- }
+-
+- return HEADER_OK;
+-}
+-
+-/*!
+- \brief Get missing harmonics parameters (only used for AAC+SBR)
+-
+- \return error status - 0 if ok
+-*/
+-int sbrGetSyntheticCodedData(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA hFrameData,
+- HANDLE_FDK_BITSTREAM hBs, const UINT flags) {
+- int i, bitsRead = 0;
+-
+- int add_harmonic_flag = FDKreadBits(hBs, 1);
+- bitsRead++;
+-
+- if (add_harmonic_flag) {
+- int nSfb = hHeaderData->freqBandData.nSfb[1];
+- for (i = 0; i < ADD_HARMONICS_FLAGS_SIZE; i++) {
+- /* read maximum 32 bits and align them to the MSB */
+- int readBits = fMin(32, nSfb);
+- nSfb -= readBits;
+- if (readBits > 0) {
+- hFrameData->addHarmonics[i] = FDKreadBits(hBs, readBits)
+- << (32 - readBits);
+- } else {
+- hFrameData->addHarmonics[i] = 0;
+- }
+-
+- bitsRead += readBits;
+- }
+- /* bs_pvc_mode = 0 for Rsvd50 */
+- if (flags & SBRDEC_SYNTAX_USAC) {
+- if (hHeaderData->bs_info.pvc_mode) {
+- int bs_sinusoidal_position = 31;
+- if (FDKreadBit(hBs) /* bs_sinusoidal_position_flag */) {
+- bs_sinusoidal_position = FDKreadBits(hBs, 5);
+- }
+- hFrameData->sinusoidal_position = bs_sinusoidal_position;
+- }
+- }
+- } else {
+- for (i = 0; i < ADD_HARMONICS_FLAGS_SIZE; i++)
+- hFrameData->addHarmonics[i] = 0;
+- }
+-
+- return (bitsRead);
+-}
+-
+-/*!
+- \brief Reads extension data from the bitstream
+-
+- The bitstream format allows up to 4 kinds of extended data element.
+- Extended data may contain several elements, each identified by a 2-bit-ID.
+- So far, no extended data elements are defined hence the first 2 parameters
+- are unused. The data should be skipped in order to update the number
+- of read bits for the consistency check in applySBR().
+-*/
+-static int extractExtendedData(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< handle to SBR header */
+- HANDLE_FDK_BITSTREAM hBs /*!< Handle to the bit buffer */
+- ,
+- HANDLE_PS_DEC hParametricStereoDec /*!< Parametric Stereo Decoder */
+-) {
+- INT nBitsLeft;
+- int extended_data;
+- int i, frameOk = 1;
+-
+- extended_data = FDKreadBits(hBs, 1);
+-
+- if (extended_data) {
+- int cnt;
+- int bPsRead = 0;
+-
+- cnt = FDKreadBits(hBs, 4);
+- if (cnt == (1 << 4) - 1) cnt += FDKreadBits(hBs, 8);
+-
+- nBitsLeft = 8 * cnt;
+-
+- /* sanity check for cnt */
+- if (nBitsLeft > (INT)FDKgetValidBits(hBs)) {
+- /* limit nBitsLeft */
+- nBitsLeft = (INT)FDKgetValidBits(hBs);
+- /* set frame error */
+- frameOk = 0;
+- }
+-
+- while (nBitsLeft > 7) {
+- int extension_id = FDKreadBits(hBs, 2);
+- nBitsLeft -= 2;
+-
+- switch (extension_id) {
+- case EXTENSION_ID_PS_CODING:
+-
+- /* Read PS data from bitstream */
+-
+- if (hParametricStereoDec != NULL) {
+- if (bPsRead &&
+- !hParametricStereoDec->bsData[hParametricStereoDec->bsReadSlot]
+- .mpeg.bPsHeaderValid) {
+- cnt = nBitsLeft >> 3; /* number of remaining bytes */
+- for (i = 0; i < cnt; i++) FDKreadBits(hBs, 8);
+- nBitsLeft -= cnt * 8;
+- } else {
+- nBitsLeft -=
+- (INT)ReadPsData(hParametricStereoDec, hBs, nBitsLeft);
+- bPsRead = 1;
+- }
+- }
+-
+- /* parametric stereo detected, could set channelMode accordingly here
+- */
+- /* */
+- /* "The usage of this parametric stereo extension to HE-AAC is */
+- /* signalled implicitly in the bitstream. Hence, if an sbr_extension()
+- */
+- /* with bs_extension_id==EXTENSION_ID_PS is found in the SBR part of
+- */
+- /* the bitstream, a decoder supporting the combination of SBR and PS
+- */
+- /* shall operate the PS tool to generate a stereo output signal." */
+- /* source: ISO/IEC 14496-3:2001/FDAM 2:2004(E) */
+-
+- break;
+-
+- default:
+- cnt = nBitsLeft >> 3; /* number of remaining bytes */
+- for (i = 0; i < cnt; i++) FDKreadBits(hBs, 8);
+- nBitsLeft -= cnt * 8;
+- break;
+- }
+- }
+-
+- if (nBitsLeft < 0) {
+- frameOk = 0;
+- goto bail;
+- } else {
+- /* Read fill bits for byte alignment */
+- FDKreadBits(hBs, nBitsLeft);
+- }
+- }
+-
+-bail:
+- return (frameOk);
+-}
+-
+-/*!
+- \brief Read bitstream elements of a SBR channel element
+- \return SbrFrameOK
+-*/
+-int sbrGetChannelElement(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA hFrameDataLeft,
+- HANDLE_SBR_FRAME_DATA hFrameDataRight,
+- HANDLE_SBR_PREV_FRAME_DATA hFrameDataLeftPrev,
+- UCHAR pvc_mode_last, HANDLE_FDK_BITSTREAM hBs,
+- HANDLE_PS_DEC hParametricStereoDec, const UINT flags,
+- const int overlap) {
+- int i, bs_coupling = COUPLING_OFF;
+- const int nCh = (hFrameDataRight == NULL) ? 1 : 2;
+-
+- if (!(flags & (SBRDEC_SYNTAX_USAC | SBRDEC_SYNTAX_RSVD50))) {
+- /* Reserved bits */
+- if (FDKreadBits(hBs, 1)) { /* bs_data_extra */
+- FDKreadBits(hBs, 4);
+- if ((flags & SBRDEC_SYNTAX_SCAL) || (nCh == 2)) {
+- FDKreadBits(hBs, 4);
+- }
+- }
+- }
+-
+- if (nCh == 2) {
+- /* Read coupling flag */
+- bs_coupling = FDKreadBits(hBs, 1);
+- if (bs_coupling) {
+- hFrameDataLeft->coupling = COUPLING_LEVEL;
+- hFrameDataRight->coupling = COUPLING_BAL;
+- } else {
+- hFrameDataLeft->coupling = COUPLING_OFF;
+- hFrameDataRight->coupling = COUPLING_OFF;
+- }
+- } else {
+- if (flags & SBRDEC_SYNTAX_SCAL) {
+- FDKreadBits(hBs, 1); /* bs_coupling */
+- }
+- hFrameDataLeft->coupling = COUPLING_OFF;
+- }
+-
+- if (flags & (SBRDEC_SYNTAX_USAC | SBRDEC_SYNTAX_RSVD50)) {
+- if (flags & SBRDEC_USAC_HARMONICSBR) {
+- hFrameDataLeft->sbrPatchingMode = FDKreadBit(hBs);
+- if (hFrameDataLeft->sbrPatchingMode == 0) {
+- hFrameDataLeft->sbrOversamplingFlag = FDKreadBit(hBs);
+- if (FDKreadBit(hBs)) { /* sbrPitchInBinsFlag */
+- hFrameDataLeft->sbrPitchInBins = FDKreadBits(hBs, 7);
+- } else {
+- hFrameDataLeft->sbrPitchInBins = 0;
+- }
+- } else {
+- hFrameDataLeft->sbrOversamplingFlag = 0;
+- hFrameDataLeft->sbrPitchInBins = 0;
+- }
+-
+- if (nCh == 2) {
+- if (bs_coupling) {
+- hFrameDataRight->sbrPatchingMode = hFrameDataLeft->sbrPatchingMode;
+- hFrameDataRight->sbrOversamplingFlag =
+- hFrameDataLeft->sbrOversamplingFlag;
+- hFrameDataRight->sbrPitchInBins = hFrameDataLeft->sbrPitchInBins;
+- } else {
+- hFrameDataRight->sbrPatchingMode = FDKreadBit(hBs);
+- if (hFrameDataRight->sbrPatchingMode == 0) {
+- hFrameDataRight->sbrOversamplingFlag = FDKreadBit(hBs);
+- if (FDKreadBit(hBs)) { /* sbrPitchInBinsFlag */
+- hFrameDataRight->sbrPitchInBins = FDKreadBits(hBs, 7);
+- } else {
+- hFrameDataRight->sbrPitchInBins = 0;
+- }
+- } else {
+- hFrameDataRight->sbrOversamplingFlag = 0;
+- hFrameDataRight->sbrPitchInBins = 0;
+- }
+- }
+- }
+- } else {
+- if (nCh == 2) {
+- hFrameDataRight->sbrPatchingMode = 1;
+- hFrameDataRight->sbrOversamplingFlag = 0;
+- hFrameDataRight->sbrPitchInBins = 0;
+- }
+-
+- hFrameDataLeft->sbrPatchingMode = 1;
+- hFrameDataLeft->sbrOversamplingFlag = 0;
+- hFrameDataLeft->sbrPitchInBins = 0;
+- }
+- } else {
+- if (nCh == 2) {
+- hFrameDataRight->sbrPatchingMode = 1;
+- hFrameDataRight->sbrOversamplingFlag = 0;
+- hFrameDataRight->sbrPitchInBins = 0;
+- }
+-
+- hFrameDataLeft->sbrPatchingMode = 1;
+- hFrameDataLeft->sbrOversamplingFlag = 0;
+- hFrameDataLeft->sbrPitchInBins = 0;
+- }
+-
+- /*
+- sbr_grid(): Grid control
+- */
+- if (hHeaderData->bs_info.pvc_mode) {
+- FDK_ASSERT(nCh == 1); /* PVC not possible for CPE */
+- if (!extractPvcFrameInfo(hBs, hHeaderData, hFrameDataLeft,
+- hFrameDataLeftPrev, pvc_mode_last, flags))
+- return 0;
+-
+- if (!checkFrameInfo(&hFrameDataLeft->frameInfo,
+- hHeaderData->numberTimeSlots, overlap,
+- hHeaderData->timeStep))
+- return 0;
+- } else {
+- if (!extractFrameInfo(hBs, hHeaderData, hFrameDataLeft, 1, flags)) return 0;
+-
+- if (!checkFrameInfo(&hFrameDataLeft->frameInfo,
+- hHeaderData->numberTimeSlots, overlap,
+- hHeaderData->timeStep))
+- return 0;
+- }
+- if (nCh == 2) {
+- if (hFrameDataLeft->coupling) {
+- FDKmemcpy(&hFrameDataRight->frameInfo, &hFrameDataLeft->frameInfo,
+- sizeof(FRAME_INFO));
+- hFrameDataRight->ampResolutionCurrentFrame =
+- hFrameDataLeft->ampResolutionCurrentFrame;
+- } else {
+- if (!extractFrameInfo(hBs, hHeaderData, hFrameDataRight, 2, flags))
+- return 0;
+-
+- if (!checkFrameInfo(&hFrameDataRight->frameInfo,
+- hHeaderData->numberTimeSlots, overlap,
+- hHeaderData->timeStep))
+- return 0;
+- }
+- }
+-
+- /*
+- sbr_dtdf(): Fetch domain vectors (time or frequency direction for
+- delta-coding)
+- */
+- sbrGetDirectionControlData(hFrameDataLeft, hBs, flags,
+- hHeaderData->bs_info.pvc_mode);
+- if (nCh == 2) {
+- sbrGetDirectionControlData(hFrameDataRight, hBs, flags, 0);
+- }
+-
+- /* sbr_invf() */
+- for (i = 0; i < hHeaderData->freqBandData.nInvfBands; i++) {
+- hFrameDataLeft->sbr_invf_mode[i] = (INVF_MODE)FDKreadBits(hBs, 2);
+- }
+- if (nCh == 2) {
+- if (hFrameDataLeft->coupling) {
+- for (i = 0; i < hHeaderData->freqBandData.nInvfBands; i++) {
+- hFrameDataRight->sbr_invf_mode[i] = hFrameDataLeft->sbr_invf_mode[i];
+- }
+- } else {
+- for (i = 0; i < hHeaderData->freqBandData.nInvfBands; i++) {
+- hFrameDataRight->sbr_invf_mode[i] = (INVF_MODE)FDKreadBits(hBs, 2);
+- }
+- }
+- }
+-
+- if (nCh == 1) {
+- if (hHeaderData->bs_info.pvc_mode) {
+- if (!sbrGetPvcEnvelope(hHeaderData, hFrameDataLeft, hBs, flags,
+- hHeaderData->bs_info.pvc_mode))
+- return 0;
+- } else if (!sbrGetEnvelope(hHeaderData, hFrameDataLeft, hBs, flags))
+- return 0;
+-
+- sbrGetNoiseFloorData(hHeaderData, hFrameDataLeft, hBs);
+- } else if (hFrameDataLeft->coupling) {
+- if (!sbrGetEnvelope(hHeaderData, hFrameDataLeft, hBs, flags)) {
+- return 0;
+- }
+-
+- sbrGetNoiseFloorData(hHeaderData, hFrameDataLeft, hBs);
+-
+- if (!sbrGetEnvelope(hHeaderData, hFrameDataRight, hBs, flags)) {
+- return 0;
+- }
+- sbrGetNoiseFloorData(hHeaderData, hFrameDataRight, hBs);
+- } else { /* nCh == 2 && no coupling */
+-
+- if (!sbrGetEnvelope(hHeaderData, hFrameDataLeft, hBs, flags)) return 0;
+-
+- if (!sbrGetEnvelope(hHeaderData, hFrameDataRight, hBs, flags)) return 0;
+-
+- sbrGetNoiseFloorData(hHeaderData, hFrameDataLeft, hBs);
+-
+- sbrGetNoiseFloorData(hHeaderData, hFrameDataRight, hBs);
+- }
+-
+- sbrGetSyntheticCodedData(hHeaderData, hFrameDataLeft, hBs, flags);
+- if (nCh == 2) {
+- sbrGetSyntheticCodedData(hHeaderData, hFrameDataRight, hBs, flags);
+- }
+-
+- if (!(flags & (SBRDEC_SYNTAX_USAC | SBRDEC_SYNTAX_RSVD50))) {
+- if (!extractExtendedData(hHeaderData, hBs, hParametricStereoDec)) {
+- return 0;
+- }
+- }
+-
+- return 1;
+-}
+-
+-/*!
+- \brief Read direction control data from bitstream
+-*/
+-void sbrGetDirectionControlData(
+- HANDLE_SBR_FRAME_DATA h_frame_data, /*!< handle to struct SBR_FRAME_DATA */
+- HANDLE_FDK_BITSTREAM hBs, /*!< handle to struct BIT_BUF */
+- const UINT flags, const int bs_pvc_mode)
+-
+-{
+- int i;
+- int indepFlag = 0;
+-
+- if (flags & (SBRDEC_SYNTAX_USAC | SBRDEC_SYNTAX_RSVD50)) {
+- indepFlag = flags & SBRDEC_USAC_INDEP;
+- }
+-
+- if (bs_pvc_mode == 0) {
+- i = 0;
+- if (indepFlag) {
+- h_frame_data->domain_vec[i++] = 0;
+- }
+- for (; i < h_frame_data->frameInfo.nEnvelopes; i++) {
+- h_frame_data->domain_vec[i] = FDKreadBits(hBs, 1);
+- }
+- }
+-
+- i = 0;
+- if (indepFlag) {
+- h_frame_data->domain_vec_noise[i++] = 0;
+- }
+- for (; i < h_frame_data->frameInfo.nNoiseEnvelopes; i++) {
+- h_frame_data->domain_vec_noise[i] = FDKreadBits(hBs, 1);
+- }
+-}
+-
+-/*!
+- \brief Read noise-floor-level data from bitstream
+-*/
+-void sbrGetNoiseFloorData(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_frame_data, /*!< handle to struct SBR_FRAME_DATA */
+- HANDLE_FDK_BITSTREAM hBs) /*!< handle to struct BIT_BUF */
+-{
+- int i, j;
+- int delta;
+- COUPLING_MODE coupling;
+- int noNoiseBands = hHeaderData->freqBandData.nNfb;
+-
+- Huffman hcb_noiseF;
+- Huffman hcb_noise;
+- int envDataTableCompFactor;
+-
+- coupling = h_frame_data->coupling;
+-
+- /*
+- Select huffman codebook depending on coupling mode
+- */
+- if (coupling == COUPLING_BAL) {
+- hcb_noise = (Huffman)&FDK_sbrDecoder_sbr_huffBook_NoiseBalance11T;
+- hcb_noiseF =
+- (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvBalance11F; /* "sbr_huffBook_NoiseBalance11F"
+- */
+- envDataTableCompFactor = 1;
+- } else {
+- hcb_noise = (Huffman)&FDK_sbrDecoder_sbr_huffBook_NoiseLevel11T;
+- hcb_noiseF =
+- (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvLevel11F; /* "sbr_huffBook_NoiseLevel11F"
+- */
+- envDataTableCompFactor = 0;
+- }
+-
+- /*
+- Read raw noise-envelope data
+- */
+- for (i = 0; i < h_frame_data->frameInfo.nNoiseEnvelopes; i++) {
+- if (h_frame_data->domain_vec_noise[i] == 0) {
+- if (coupling == COUPLING_BAL) {
+- h_frame_data->sbrNoiseFloorLevel[i * noNoiseBands] =
+- (FIXP_SGL)(((int)FDKreadBits(hBs, 5)) << envDataTableCompFactor);
+- } else {
+- h_frame_data->sbrNoiseFloorLevel[i * noNoiseBands] =
+- (FIXP_SGL)(int)FDKreadBits(hBs, 5);
+- }
+-
+- for (j = 1; j < noNoiseBands; j++) {
+- delta = DecodeHuffmanCW(hcb_noiseF, hBs);
+- h_frame_data->sbrNoiseFloorLevel[i * noNoiseBands + j] =
+- (FIXP_SGL)(delta << envDataTableCompFactor);
+- }
+- } else {
+- for (j = 0; j < noNoiseBands; j++) {
+- delta = DecodeHuffmanCW(hcb_noise, hBs);
+- h_frame_data->sbrNoiseFloorLevel[i * noNoiseBands + j] =
+- (FIXP_SGL)(delta << envDataTableCompFactor);
+- }
+- }
+- }
+-}
+-
+-/* ns = mapNsMode2ns[pvcMode-1][nsMode] */
+-static const UCHAR mapNsMode2ns[2][2] = {
+- {16, 4}, /* pvcMode = 1 */
+- {12, 3} /* pvcMode = 2 */
+-};
+-
+-static int sbrGetPvcEnvelope(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_frame_data, /*!< handle to struct SBR_FRAME_DATA */
+- HANDLE_FDK_BITSTREAM hBs, /*!< handle to struct BIT_BUF */
+- const UINT flags, const UINT pvcMode) {
+- int divMode, nsMode;
+- int indepFlag = flags & SBRDEC_USAC_INDEP;
+- UCHAR *pvcID = h_frame_data->pvcID;
+-
+- divMode = FDKreadBits(hBs, PVC_DIVMODE_BITS);
+- nsMode = FDKreadBit(hBs);
+- FDK_ASSERT((pvcMode == 1) || (pvcMode == 2));
+- h_frame_data->ns = mapNsMode2ns[pvcMode - 1][nsMode];
+-
+- if (divMode <= 3) {
+- int i, k = 1, sum_length = 0, reuse_pcvID;
+-
+- /* special treatment for first time slot k=0 */
+- indepFlag ? (reuse_pcvID = 0) : (reuse_pcvID = FDKreadBit(hBs));
+- if (reuse_pcvID) {
+- pvcID[0] = hHeaderData->pvcIDprev;
+- } else {
+- pvcID[0] = FDKreadBits(hBs, PVC_PVCID_BITS);
+- }
+-
+- /* other time slots k>0 */
+- for (i = 0; i < divMode; i++) {
+- int length, numBits = 4;
+-
+- if (sum_length >= 13) {
+- numBits = 1;
+- } else if (sum_length >= 11) {
+- numBits = 2;
+- } else if (sum_length >= 7) {
+- numBits = 3;
+- }
+-
+- length = FDKreadBits(hBs, numBits);
+- sum_length += length + 1;
+- if (sum_length >= PVC_NTIMESLOT) {
+- return 0; /* parse error */
+- }
+- for (; length--; k++) {
+- pvcID[k] = pvcID[k - 1];
+- }
+- pvcID[k++] = FDKreadBits(hBs, PVC_PVCID_BITS);
+- }
+- for (; k < 16; k++) {
+- pvcID[k] = pvcID[k - 1];
+- }
+- } else { /* divMode >= 4 */
+- int num_grid_info, fixed_length, grid_info, j, k = 0;
+-
+- divMode -= 4;
+- num_grid_info = 2 << divMode;
+- fixed_length = 8 >> divMode;
+- FDK_ASSERT(num_grid_info * fixed_length == PVC_NTIMESLOT);
+-
+- /* special treatment for first time slot k=0 */
+- indepFlag ? (grid_info = 1) : (grid_info = FDKreadBit(hBs));
+- if (grid_info) {
+- pvcID[k++] = FDKreadBits(hBs, PVC_PVCID_BITS);
+- } else {
+- pvcID[k++] = hHeaderData->pvcIDprev;
+- }
+- j = fixed_length - 1;
+- for (; j--; k++) {
+- pvcID[k] = pvcID[k - 1];
+- }
+- num_grid_info--;
+-
+- /* other time slots k>0 */
+- for (; num_grid_info--;) {
+- j = fixed_length;
+- grid_info = FDKreadBit(hBs);
+- if (grid_info) {
+- pvcID[k++] = FDKreadBits(hBs, PVC_PVCID_BITS);
+- j--;
+- }
+- for (; j--; k++) {
+- pvcID[k] = pvcID[k - 1];
+- }
+- }
+- }
+-
+- hHeaderData->pvcIDprev = pvcID[PVC_NTIMESLOT - 1];
+-
+- /* usage of PVC excludes inter-TES tool */
+- h_frame_data->iTESactive = (UCHAR)0;
+-
+- return 1;
+-}
+-/*!
+- \brief Read envelope data from bitstream
+-*/
+-static int sbrGetEnvelope(
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_frame_data, /*!< handle to struct SBR_FRAME_DATA */
+- HANDLE_FDK_BITSTREAM hBs, /*!< handle to struct BIT_BUF */
+- const UINT flags) {
+- int i, j;
+- UCHAR no_band[MAX_ENVELOPES];
+- int delta = 0;
+- int offset = 0;
+- COUPLING_MODE coupling = h_frame_data->coupling;
+- int ampRes = hHeaderData->bs_info.ampResolution;
+- int nEnvelopes = h_frame_data->frameInfo.nEnvelopes;
+- int envDataTableCompFactor;
+- int start_bits, start_bits_balance;
+- Huffman hcb_t, hcb_f;
+-
+- h_frame_data->nScaleFactors = 0;
+-
+- if ((h_frame_data->frameInfo.frameClass == 0) && (nEnvelopes == 1)) {
+- if (flags & SBRDEC_ELD_GRID)
+- ampRes = h_frame_data->ampResolutionCurrentFrame;
+- else
+- ampRes = 0;
+- }
+- h_frame_data->ampResolutionCurrentFrame = ampRes;
+-
+- /*
+- Set number of bits for first value depending on amplitude resolution
+- */
+- if (ampRes == 1) {
+- start_bits = 6;
+- start_bits_balance = 5;
+- } else {
+- start_bits = 7;
+- start_bits_balance = 6;
+- }
+-
+- /*
+- Calculate number of values for each envelope and alltogether
+- */
+- for (i = 0; i < nEnvelopes; i++) {
+- no_band[i] =
+- hHeaderData->freqBandData.nSfb[h_frame_data->frameInfo.freqRes[i]];
+- h_frame_data->nScaleFactors += no_band[i];
+- }
+- if (h_frame_data->nScaleFactors > MAX_NUM_ENVELOPE_VALUES) return 0;
+-
+- /*
+- Select Huffman codebook depending on coupling mode and amplitude resolution
+- */
+- if (coupling == COUPLING_BAL) {
+- envDataTableCompFactor = 1;
+- if (ampRes == 0) {
+- hcb_t = (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvBalance10T;
+- hcb_f = (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvBalance10F;
+- } else {
+- hcb_t = (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvBalance11T;
+- hcb_f = (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvBalance11F;
+- }
+- } else {
+- envDataTableCompFactor = 0;
+- if (ampRes == 0) {
+- hcb_t = (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvLevel10T;
+- hcb_f = (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvLevel10F;
+- } else {
+- hcb_t = (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvLevel11T;
+- hcb_f = (Huffman)&FDK_sbrDecoder_sbr_huffBook_EnvLevel11F;
+- }
+- }
+-
+- h_frame_data->iTESactive = (UCHAR)0; /* disable inter-TES by default */
+- /*
+- Now read raw envelope data
+- */
+- for (j = 0, offset = 0; j < nEnvelopes; j++) {
+- if (h_frame_data->domain_vec[j] == 0) {
+- if (coupling == COUPLING_BAL) {
+- h_frame_data->iEnvelope[offset] =
+- (FIXP_SGL)(((int)FDKreadBits(hBs, start_bits_balance))
+- << envDataTableCompFactor);
+- } else {
+- h_frame_data->iEnvelope[offset] =
+- (FIXP_SGL)(int)FDKreadBits(hBs, start_bits);
+- }
+- }
+-
+- for (i = (1 - h_frame_data->domain_vec[j]); i < no_band[j]; i++) {
+- if (h_frame_data->domain_vec[j] == 0) {
+- delta = DecodeHuffmanCW(hcb_f, hBs);
+- } else {
+- delta = DecodeHuffmanCW(hcb_t, hBs);
+- }
+-
+- h_frame_data->iEnvelope[offset + i] =
+- (FIXP_SGL)(delta << envDataTableCompFactor);
+- }
+- if ((flags & SBRDEC_SYNTAX_USAC) && (flags & SBRDEC_USAC_ITES)) {
+- int bs_temp_shape = FDKreadBit(hBs);
+- FDK_ASSERT(j < 8);
+- h_frame_data->iTESactive |= (UCHAR)(bs_temp_shape << j);
+- if (bs_temp_shape) {
+- h_frame_data->interTempShapeMode[j] =
+- FDKread2Bits(hBs); /* bs_inter_temp_shape_mode */
+- } else {
+- h_frame_data->interTempShapeMode[j] = 0;
+- }
+- }
+- offset += no_band[j];
+- }
+-
+-#if ENV_EXP_FRACT
+- /* Convert from int to scaled fract (ENV_EXP_FRACT bits for the fractional
+- * part) */
+- for (i = 0; i < h_frame_data->nScaleFactors; i++) {
+- h_frame_data->iEnvelope[i] <<= ENV_EXP_FRACT;
+- }
+-#endif
+-
+- return 1;
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief Generates frame info for FIXFIXonly frame class used for low delay
+- version
+-
+- \return zero for error, one for correct.
+- ****************************************************************************/
+-static int generateFixFixOnly(FRAME_INFO *hSbrFrameInfo, int tranPosInternal,
+- int numberTimeSlots, const UINT flags) {
+- int nEnv, i, tranIdx;
+- const int *pTable;
+-
+- switch (numberTimeSlots) {
+- case 8:
+- pTable = FDK_sbrDecoder_envelopeTable_8[tranPosInternal];
+- break;
+- case 15:
+- pTable = FDK_sbrDecoder_envelopeTable_15[tranPosInternal];
+- break;
+- case 16:
+- pTable = FDK_sbrDecoder_envelopeTable_16[tranPosInternal];
+- break;
+- default:
+- return 0;
+- }
+-
+- /* look number of envelopes in table */
+- nEnv = pTable[0];
+- /* look up envelope distribution in table */
+- for (i = 1; i < nEnv; i++) hSbrFrameInfo->borders[i] = pTable[i + 2];
+- /* open and close frame border */
+- hSbrFrameInfo->borders[0] = 0;
+- hSbrFrameInfo->borders[nEnv] = numberTimeSlots;
+- hSbrFrameInfo->nEnvelopes = nEnv;
+-
+- /* transient idx */
+- tranIdx = hSbrFrameInfo->tranEnv = pTable[1];
+-
+- /* add noise floors */
+- hSbrFrameInfo->bordersNoise[0] = 0;
+- hSbrFrameInfo->bordersNoise[1] =
+- hSbrFrameInfo->borders[tranIdx ? tranIdx : 1];
+- hSbrFrameInfo->bordersNoise[2] = numberTimeSlots;
+- /* nEnv is always > 1, so nNoiseEnvelopes is always 2 (IEC 14496-3 4.6.19.3.2)
+- */
+- hSbrFrameInfo->nNoiseEnvelopes = 2;
+-
+- return 1;
+-}
+-
+-/*!
+- \brief Extracts LowDelaySBR control data from the bitstream.
+-
+- \return zero for bitstream error, one for correct.
+-*/
+-static int extractLowDelayGrid(
+- HANDLE_FDK_BITSTREAM hBitBuf, /*!< bitbuffer handle */
+- HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA
+- h_frame_data, /*!< contains the FRAME_INFO struct to be filled */
+- int timeSlots, const UINT flags) {
+- FRAME_INFO *pFrameInfo = &h_frame_data->frameInfo;
+- INT numberTimeSlots = hHeaderData->numberTimeSlots;
+- INT temp = 0, k;
+-
+- /* FIXFIXonly framing case */
+- h_frame_data->frameInfo.frameClass = 0;
+-
+- /* get the transient position from the bitstream */
+- switch (timeSlots) {
+- case 8:
+- /* 3bit transient position (temp={0;..;7}) */
+- temp = FDKreadBits(hBitBuf, 3);
+- break;
+-
+- case 16:
+- case 15:
+- /* 4bit transient position (temp={0;..;15}) */
+- temp = FDKreadBits(hBitBuf, 4);
+- break;
+-
+- default:
+- return 0;
+- }
+-
+- /* For "case 15" only*/
+- if (temp >= timeSlots) {
+- return 0;
+- }
+-
+- /* calculate borders according to the transient position */
+- if (!generateFixFixOnly(pFrameInfo, temp, numberTimeSlots, flags)) {
+- return 0;
+- }
+-
+- /* decode freq res: */
+- for (k = 0; k < pFrameInfo->nEnvelopes; k++) {
+- pFrameInfo->freqRes[k] =
+- (UCHAR)FDKreadBits(hBitBuf, 1); /* f = F [1 bits] */
+- }
+-
+- return 1;
+-}
+-
+-/*!
+- \brief Extract the PVC frame information (structure FRAME_INFO) from the
+- bitstream \return Zero for bitstream error, one for correct.
+-*/
+-int extractPvcFrameInfo(
+- HANDLE_FDK_BITSTREAM hBs, /*!< bitbuffer handle */
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_frame_data, /*!< pointer to memory where the
+- frame-info will be stored */
+- HANDLE_SBR_PREV_FRAME_DATA h_prev_frame_data, /*!< pointer to memory where
+- the previous frame-info
+- will be stored */
+- UCHAR pvc_mode_last, /**< PVC mode of last frame */
+- const UINT flags) {
+- FRAME_INFO *pFrameInfo = &h_frame_data->frameInfo;
+- FRAME_INFO *pPrevFrameInfo = &h_prev_frame_data->prevFrameInfo;
+- int bs_var_len_hf, bs_noise_position;
+- bs_noise_position = FDKreadBits(hBs, 4); /* SBR_PVC_NOISEPOSITION_BITS 4 */
+- bs_var_len_hf = FDKreadBit(hBs);
+- pFrameInfo->noisePosition = bs_noise_position;
+- pFrameInfo->tranEnv = -1;
+-
+- /* Init for bs_noise_position == 0 in case a parse error is found below. */
+- pFrameInfo->nEnvelopes = 1;
+- pFrameInfo->nNoiseEnvelopes = 1;
+- pFrameInfo->freqRes[0] = 0;
+-
+- if (bs_var_len_hf) { /* 1 or 3 Bits */
+- pFrameInfo->varLength = FDKreadBits(hBs, 2) + 1;
+- if (pFrameInfo->varLength > 3) {
+- pFrameInfo->varLength =
+- 0; /* assume bs_var_len_hf == 0 in case of error */
+- return 0; /* reserved value -> parse error */
+- }
+- } else {
+- pFrameInfo->varLength = 0;
+- }
+-
+- if (bs_noise_position) {
+- pFrameInfo->nEnvelopes = 2;
+- pFrameInfo->nNoiseEnvelopes = 2;
+- FDKmemclear(pFrameInfo->freqRes, sizeof(pFrameInfo->freqRes));
+- }
+-
+- /* frame border calculation */
+- if (hHeaderData->bs_info.pvc_mode > 0) {
+- /* See "7.5.1.4 HF adjustment of SBR envelope scalefactors" for reference.
+- */
+-
+- FDK_ASSERT((pFrameInfo->nEnvelopes == 1) || (pFrameInfo->nEnvelopes == 2));
+-
+- /* left timeborder-offset: use the timeborder of prev SBR frame */
+- if (pPrevFrameInfo->nEnvelopes > 0) {
+- pFrameInfo->borders[0] =
+- pPrevFrameInfo->borders[pPrevFrameInfo->nEnvelopes] - PVC_NTIMESLOT;
+- FDK_ASSERT(pFrameInfo->borders[0] <= 3);
+- } else {
+- pFrameInfo->borders[0] = 0;
+- }
+-
+- /* right timeborder-offset: */
+- pFrameInfo->borders[pFrameInfo->nEnvelopes] = 16 + pFrameInfo->varLength;
+-
+- if (pFrameInfo->nEnvelopes == 2) {
+- pFrameInfo->borders[1] = pFrameInfo->noisePosition;
+- }
+-
+- /* Calculation of PVC time borders t_EPVC */
+- if (pvc_mode_last == 0) {
+- /* there was a legacy SBR frame before this frame => use bs_var_len' for
+- * first PVC timeslot */
+- pFrameInfo->pvcBorders[0] = pFrameInfo->borders[0];
+- } else {
+- pFrameInfo->pvcBorders[0] = 0;
+- }
+- if (pFrameInfo->nEnvelopes == 2) {
+- pFrameInfo->pvcBorders[1] = pFrameInfo->borders[1];
+- }
+- pFrameInfo->pvcBorders[pFrameInfo->nEnvelopes] = 16;
+-
+- /* calculation of SBR noise-floor time-border vector: */
+- for (INT i = 0; i <= pFrameInfo->nNoiseEnvelopes; i++) {
+- pFrameInfo->bordersNoise[i] = pFrameInfo->borders[i];
+- }
+-
+- pFrameInfo->tranEnv = -1; /* tranEnv not used */
+- }
+- return 1;
+-}
+-
+-/*!
+- \brief Extract the frame information (structure FRAME_INFO) from the
+- bitstream \return Zero for bitstream error, one for correct.
+-*/
+-int extractFrameInfo(
+- HANDLE_FDK_BITSTREAM hBs, /*!< bitbuffer handle */
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA h_frame_data, /*!< pointer to memory where the
+- frame-info will be stored */
+- const UINT nrOfChannels, const UINT flags) {
+- FRAME_INFO *pFrameInfo = &h_frame_data->frameInfo;
+- int numberTimeSlots = hHeaderData->numberTimeSlots;
+- int pointer_bits = 0, nEnv = 0, b = 0, border, i, n = 0, k, p, aL, aR, nL, nR,
+- temp = 0, staticFreqRes;
+- UCHAR frameClass;
+-
+- if (flags & SBRDEC_ELD_GRID) {
+- /* CODEC_AACLD (LD+SBR) only uses the normal 0 Grid for non-transient Frames
+- * and the LowDelayGrid for transient Frames */
+- frameClass = FDKreadBits(hBs, 1); /* frameClass = [1 bit] */
+- if (frameClass == 1) {
+- /* if frameClass == 1, extract LowDelaySbrGrid, otherwise extract normal
+- * SBR-Grid for FIXIFX */
+- /* extract the AACLD-Sbr-Grid */
+- pFrameInfo->frameClass = frameClass;
+- int err = 1;
+- err = extractLowDelayGrid(hBs, hHeaderData, h_frame_data, numberTimeSlots,
+- flags);
+- return err;
+- }
+- } else {
+- frameClass = FDKreadBits(hBs, 2); /* frameClass = C [2 bits] */
+- }
+-
+- switch (frameClass) {
+- case 0:
+- temp = FDKreadBits(hBs, 2); /* E [2 bits ] */
+- nEnv = (int)(1 << temp); /* E -> e */
+-
+- if ((flags & SBRDEC_ELD_GRID) && (nEnv == 1))
+- h_frame_data->ampResolutionCurrentFrame =
+- FDKreadBits(hBs, 1); /* new ELD Syntax 07-11-09 */
+-
+- staticFreqRes = FDKreadBits(hBs, 1);
+-
+- if (flags & (SBRDEC_SYNTAX_USAC | SBRDEC_SYNTAX_RSVD50)) {
+- if (nEnv > MAX_ENVELOPES_USAC) return 0;
+- } else
+-
+- b = nEnv + 1;
+- switch (nEnv) {
+- case 1:
+- switch (numberTimeSlots) {
+- case 15:
+- FDKmemcpy(pFrameInfo, &FDK_sbrDecoder_sbr_frame_info1_15,
+- sizeof(FRAME_INFO));
+- break;
+- case 16:
+- FDKmemcpy(pFrameInfo, &FDK_sbrDecoder_sbr_frame_info1_16,
+- sizeof(FRAME_INFO));
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- break;
+- case 2:
+- switch (numberTimeSlots) {
+- case 15:
+- FDKmemcpy(pFrameInfo, &FDK_sbrDecoder_sbr_frame_info2_15,
+- sizeof(FRAME_INFO));
+- break;
+- case 16:
+- FDKmemcpy(pFrameInfo, &FDK_sbrDecoder_sbr_frame_info2_16,
+- sizeof(FRAME_INFO));
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- break;
+- case 4:
+- switch (numberTimeSlots) {
+- case 15:
+- FDKmemcpy(pFrameInfo, &FDK_sbrDecoder_sbr_frame_info4_15,
+- sizeof(FRAME_INFO));
+- break;
+- case 16:
+- FDKmemcpy(pFrameInfo, &FDK_sbrDecoder_sbr_frame_info4_16,
+- sizeof(FRAME_INFO));
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- break;
+- case 8:
+-#if (MAX_ENVELOPES >= 8)
+- switch (numberTimeSlots) {
+- case 15:
+- FDKmemcpy(pFrameInfo, &FDK_sbrDecoder_sbr_frame_info8_15,
+- sizeof(FRAME_INFO));
+- break;
+- case 16:
+- FDKmemcpy(pFrameInfo, &FDK_sbrDecoder_sbr_frame_info8_16,
+- sizeof(FRAME_INFO));
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- break;
+-#else
+- return 0;
+-#endif
+- }
+- /* Apply correct freqRes (High is default) */
+- if (!staticFreqRes) {
+- for (i = 0; i < nEnv; i++) pFrameInfo->freqRes[i] = 0;
+- }
+-
+- break;
+- case 1:
+- case 2:
+- temp = FDKreadBits(hBs, 2); /* A [2 bits] */
+-
+- n = FDKreadBits(hBs, 2); /* n = N [2 bits] */
+-
+- nEnv = n + 1; /* # envelopes */
+- b = nEnv + 1; /* # borders */
+-
+- break;
+- }
+-
+- switch (frameClass) {
+- case 1:
+- /* Decode borders: */
+- pFrameInfo->borders[0] = 0; /* first border */
+- border = temp + numberTimeSlots; /* A -> aR */
+- i = b - 1; /* frame info index for last border */
+- pFrameInfo->borders[i] = border; /* last border */
+-
+- for (k = 0; k < n; k++) {
+- temp = FDKreadBits(hBs, 2); /* R [2 bits] */
+- border -= (2 * temp + 2); /* R -> r */
+- pFrameInfo->borders[--i] = border;
+- }
+-
+- /* Decode pointer: */
+- pointer_bits = DFRACT_BITS - 1 - CountLeadingBits((FIXP_DBL)(n + 1));
+- p = FDKreadBits(hBs, pointer_bits); /* p = P [pointer_bits bits] */
+-
+- if (p > n + 1) return 0;
+-
+- pFrameInfo->tranEnv = p ? n + 2 - p : -1;
+-
+- /* Decode freq res: */
+- for (k = n; k >= 0; k--) {
+- pFrameInfo->freqRes[k] = FDKreadBits(hBs, 1); /* f = F [1 bits] */
+- }
+-
+- /* Calculate noise floor middle border: */
+- if (p == 0 || p == 1)
+- pFrameInfo->bordersNoise[1] = pFrameInfo->borders[n];
+- else
+- pFrameInfo->bordersNoise[1] = pFrameInfo->borders[pFrameInfo->tranEnv];
+-
+- break;
+-
+- case 2:
+- /* Decode borders: */
+- border = temp; /* A -> aL */
+- pFrameInfo->borders[0] = border; /* first border */
+-
+- for (k = 1; k <= n; k++) {
+- temp = FDKreadBits(hBs, 2); /* R [2 bits] */
+- border += (2 * temp + 2); /* R -> r */
+- pFrameInfo->borders[k] = border;
+- }
+- pFrameInfo->borders[k] = numberTimeSlots; /* last border */
+-
+- /* Decode pointer: */
+- pointer_bits = DFRACT_BITS - 1 - CountLeadingBits((FIXP_DBL)(n + 1));
+- p = FDKreadBits(hBs, pointer_bits); /* p = P [pointer_bits bits] */
+- if (p > n + 1) return 0;
+-
+- if (p == 0 || p == 1)
+- pFrameInfo->tranEnv = -1;
+- else
+- pFrameInfo->tranEnv = p - 1;
+-
+- /* Decode freq res: */
+- for (k = 0; k <= n; k++) {
+- pFrameInfo->freqRes[k] = FDKreadBits(hBs, 1); /* f = F [1 bits] */
+- }
+-
+- /* Calculate noise floor middle border: */
+- switch (p) {
+- case 0:
+- pFrameInfo->bordersNoise[1] = pFrameInfo->borders[1];
+- break;
+- case 1:
+- pFrameInfo->bordersNoise[1] = pFrameInfo->borders[n];
+- break;
+- default:
+- pFrameInfo->bordersNoise[1] =
+- pFrameInfo->borders[pFrameInfo->tranEnv];
+- break;
+- }
+-
+- break;
+-
+- case 3:
+- /* v_ctrlSignal = [frameClass,aL,aR,nL,nR,v_rL,v_rR,p,v_fLR]; */
+-
+- aL = FDKreadBits(hBs, 2); /* AL [2 bits], AL -> aL */
+-
+- aR = FDKreadBits(hBs, 2) + numberTimeSlots; /* AR [2 bits], AR -> aR */
+-
+- nL = FDKreadBits(hBs, 2); /* nL = NL [2 bits] */
+-
+- nR = FDKreadBits(hBs, 2); /* nR = NR [2 bits] */
+-
+- /*-------------------------------------------------------------------------
+- Calculate help variables
+- --------------------------------------------------------------------------*/
+-
+- /* general: */
+- nEnv = nL + nR + 1; /* # envelopes */
+- if (nEnv > MAX_ENVELOPES) return 0;
+- b = nEnv + 1; /* # borders */
+-
+- /*-------------------------------------------------------------------------
+- Decode envelopes
+- --------------------------------------------------------------------------*/
+-
+- /* L-borders: */
+- border = aL; /* first border */
+- pFrameInfo->borders[0] = border;
+-
+- for (k = 1; k <= nL; k++) {
+- temp = FDKreadBits(hBs, 2); /* R [2 bits] */
+- border += (2 * temp + 2); /* R -> r */
+- pFrameInfo->borders[k] = border;
+- }
+-
+- /* R-borders: */
+- border = aR; /* last border */
+- i = nEnv;
+-
+- pFrameInfo->borders[i] = border;
+-
+- for (k = 0; k < nR; k++) {
+- temp = FDKreadBits(hBs, 2); /* R [2 bits] */
+- border -= (2 * temp + 2); /* R -> r */
+- pFrameInfo->borders[--i] = border;
+- }
+-
+- /* decode pointer: */
+- pointer_bits =
+- DFRACT_BITS - 1 - CountLeadingBits((FIXP_DBL)(nL + nR + 1));
+- p = FDKreadBits(hBs, pointer_bits); /* p = P [pointer_bits bits] */
+-
+- if (p > nL + nR + 1) return 0;
+-
+- pFrameInfo->tranEnv = p ? b - p : -1;
+-
+- /* decode freq res: */
+- for (k = 0; k < nEnv; k++) {
+- pFrameInfo->freqRes[k] = FDKreadBits(hBs, 1); /* f = F [1 bits] */
+- }
+-
+- /*-------------------------------------------------------------------------
+- Decode noise floors
+- --------------------------------------------------------------------------*/
+- pFrameInfo->bordersNoise[0] = aL;
+-
+- if (nEnv == 1) {
+- /* 1 noise floor envelope: */
+- pFrameInfo->bordersNoise[1] = aR;
+- } else {
+- /* 2 noise floor envelopes */
+- if (p == 0 || p == 1)
+- pFrameInfo->bordersNoise[1] = pFrameInfo->borders[nEnv - 1];
+- else
+- pFrameInfo->bordersNoise[1] =
+- pFrameInfo->borders[pFrameInfo->tranEnv];
+- pFrameInfo->bordersNoise[2] = aR;
+- }
+- break;
+- }
+-
+- /*
+- Store number of envelopes, noise floor envelopes and frame class
+- */
+- pFrameInfo->nEnvelopes = nEnv;
+-
+- if (nEnv == 1)
+- pFrameInfo->nNoiseEnvelopes = 1;
+- else
+- pFrameInfo->nNoiseEnvelopes = 2;
+-
+- pFrameInfo->frameClass = frameClass;
+-
+- if (pFrameInfo->frameClass == 2 || pFrameInfo->frameClass == 1) {
+- /* calculate noise floor first and last borders: */
+- pFrameInfo->bordersNoise[0] = pFrameInfo->borders[0];
+- pFrameInfo->bordersNoise[pFrameInfo->nNoiseEnvelopes] =
+- pFrameInfo->borders[nEnv];
+- }
+-
+- return 1;
+-}
+-
+-/*!
+- \brief Check if the frameInfo vector has reasonable values.
+- \return Zero for error, one for correct
+-*/
+-static int checkFrameInfo(
+- FRAME_INFO *pFrameInfo, /*!< pointer to frameInfo */
+- int numberOfTimeSlots, /*!< QMF time slots per frame */
+- int overlap, /*!< Amount of overlap QMF time slots */
+- int timeStep) /*!< QMF slots to SBR slots step factor */
+-{
+- int maxPos, i, j;
+- int startPos;
+- int stopPos;
+- int tranEnv;
+- int startPosNoise;
+- int stopPosNoise;
+- int nEnvelopes = pFrameInfo->nEnvelopes;
+- int nNoiseEnvelopes = pFrameInfo->nNoiseEnvelopes;
+-
+- if (nEnvelopes < 1 || nEnvelopes > MAX_ENVELOPES) return 0;
+-
+- if (nNoiseEnvelopes > MAX_NOISE_ENVELOPES) return 0;
+-
+- startPos = pFrameInfo->borders[0];
+- stopPos = pFrameInfo->borders[nEnvelopes];
+- tranEnv = pFrameInfo->tranEnv;
+- startPosNoise = pFrameInfo->bordersNoise[0];
+- stopPosNoise = pFrameInfo->bordersNoise[nNoiseEnvelopes];
+-
+- if (overlap < 0 || overlap > (3 * (4))) {
+- return 0;
+- }
+- if (timeStep < 1 || timeStep > (4)) {
+- return 0;
+- }
+- maxPos = numberOfTimeSlots + (overlap / timeStep);
+-
+- /* Check that the start and stop positions of the frame are reasonable values.
+- */
+- if ((startPos < 0) || (startPos >= stopPos)) return 0;
+- if (startPos > maxPos - numberOfTimeSlots) /* First env. must start in or
+- directly after the overlap
+- buffer */
+- return 0;
+- if (stopPos < numberOfTimeSlots) /* One complete frame must be ready for
+- output after processing */
+- return 0;
+- if (stopPos > maxPos) return 0;
+-
+- /* Check that the start border for every envelope is strictly later in time
+- */
+- for (i = 0; i < nEnvelopes; i++) {
+- if (pFrameInfo->borders[i] >= pFrameInfo->borders[i + 1]) return 0;
+- }
+-
+- /* Check that the envelope to be shortened is actually among the envelopes */
+- if (tranEnv > nEnvelopes) return 0;
+-
+- /* Check the noise borders */
+- if (nEnvelopes == 1 && nNoiseEnvelopes > 1) return 0;
+-
+- if (startPos != startPosNoise || stopPos != stopPosNoise) return 0;
+-
+- /* Check that the start border for every noise-envelope is strictly later in
+- * time*/
+- for (i = 0; i < nNoiseEnvelopes; i++) {
+- if (pFrameInfo->bordersNoise[i] >= pFrameInfo->bordersNoise[i + 1])
+- return 0;
+- }
+-
+- /* Check that every noise border is the same as an envelope border*/
+- for (i = 0; i < nNoiseEnvelopes; i++) {
+- startPosNoise = pFrameInfo->bordersNoise[i];
+-
+- for (j = 0; j < nEnvelopes; j++) {
+- if (pFrameInfo->borders[j] == startPosNoise) break;
+- }
+- if (j == nEnvelopes) return 0;
+- }
+-
+- return 1;
+-}
+diff --git a/libSBRdec/src/env_extr.h b/libSBRdec/src/env_extr.h
+deleted file mode 100644
+index 38c04a3..0000000
+--- a/libSBRdec/src/env_extr.h
++++ /dev/null
+@@ -1,415 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Envelope extraction prototypes
+-*/
+-
+-#ifndef ENV_EXTR_H
+-#define ENV_EXTR_H
+-
+-#include "sbrdecoder.h"
+-
+-#include "FDK_bitstream.h"
+-#include "lpp_tran.h"
+-
+-#include "psdec.h"
+-#include "pvc_dec.h"
+-
+-#define ENV_EXP_FRACT 0
+-/*!< Shift raw envelope data to support fractional numbers.
+- Can be set to 8 instead of 0 to enhance accuracy during concealment.
+- This is not required for conformance and #requantizeEnvelopeData() will
+- become more expensive.
+-*/
+-
+-#define EXP_BITS 6
+-/*!< Size of exponent-part of a pseudo float envelope value (should be at least
+- 6). The remaining bits in each word are used for the mantissa (should be at
+- least 10). This format is used in the arrays iEnvelope[] and
+- sbrNoiseFloorLevel[] in the FRAME_DATA struct which must fit in a certain part
+- of the output buffer (See buffer management in sbr_dec.cpp). Exponents and
+- mantissas could also be stored in separate arrays. Accessing the exponent or
+- the mantissa would be simplified and the masks #MASK_E resp. #MASK_M would
+- no longer be required.
+-*/
+-
+-#define MASK_M \
+- (((1 << (FRACT_BITS - EXP_BITS)) - 1) \
+- << EXP_BITS) /*!< Mask for extracting the mantissa of a pseudo float \
+- envelope value */
+-#define MASK_E \
+- ((1 << EXP_BITS) - 1) /*!< Mask for extracting the exponent of a pseudo \
+- float envelope value */
+-
+-#define SIGN_EXT \
+- (((SCHAR)-1) ^ \
+- MASK_E) /*!< a CHAR-constant with all bits above our sign-bit set */
+-#define ROUNDING \
+- ((FIXP_SGL)( \
+- 1 << (EXP_BITS - 1))) /*!< 0.5-offset for rounding the mantissa of a \
+- pseudo-float envelope value */
+-#define NRG_EXP_OFFSET \
+- 16 /*!< Will be added to the reference energy's exponent to prevent negative \
+- numbers */
+-#define NOISE_EXP_OFFSET \
+- 38 /*!< Will be added to the noise level exponent to prevent negative \
+- numbers */
+-
+-#define ADD_HARMONICS_FLAGS_SIZE 2 /* ceil(MAX_FREQ_COEFFS/32) */
+-
+-typedef enum {
+- HEADER_NOT_PRESENT,
+- HEADER_ERROR,
+- HEADER_OK,
+- HEADER_RESET
+-} SBR_HEADER_STATUS;
+-
+-typedef enum {
+- SBR_NOT_INITIALIZED = 0,
+- UPSAMPLING = 1,
+- SBR_HEADER = 2,
+- SBR_ACTIVE = 3
+-} SBR_SYNC_STATE;
+-
+-typedef enum { COUPLING_OFF = 0, COUPLING_LEVEL, COUPLING_BAL } COUPLING_MODE;
+-
+-typedef struct {
+- UCHAR nSfb[2]; /*!< Number of SBR-bands for low and high freq-resolution */
+- UCHAR nNfb; /*!< Actual number of noise bands to read from the bitstream*/
+- UCHAR numMaster; /*!< Number of SBR-bands in v_k_master */
+- UCHAR lowSubband; /*!< QMF-band where SBR frequency range starts */
+- UCHAR highSubband; /*!< QMF-band where SBR frequency range ends */
+- UCHAR ov_highSubband; /*!< if headerchange applies this value holds the old
+- highband value -> highband value of overlap area;
+- required for overlap in usac when headerchange
+- occurs between XVAR and VARX frame */
+- UCHAR limiterBandTable[MAX_NUM_LIMITERS + 1]; /*!< Limiter band table. */
+- UCHAR noLimiterBands; /*!< Number of limiter bands. */
+- UCHAR nInvfBands; /*!< Number of bands for inverse filtering */
+- UCHAR
+- *freqBandTable[2]; /*!< Pointers to freqBandTableLo and freqBandTableHi */
+- UCHAR freqBandTableLo[MAX_FREQ_COEFFS / 2 + 1];
+- /*!< Mapping of SBR bands to QMF bands for low frequency resolution */
+- UCHAR freqBandTableHi[MAX_FREQ_COEFFS + 1];
+- /*!< Mapping of SBR bands to QMF bands for high frequency resolution */
+- UCHAR freqBandTableNoise[MAX_NOISE_COEFFS + 1];
+- /*!< Mapping of SBR noise bands to QMF bands */
+- UCHAR v_k_master[MAX_FREQ_COEFFS + 1];
+- /*!< Master BandTable which freqBandTable is derived from */
+-} FREQ_BAND_DATA;
+-
+-typedef FREQ_BAND_DATA *HANDLE_FREQ_BAND_DATA;
+-
+-#define SBRDEC_ELD_GRID 1
+-#define SBRDEC_SYNTAX_SCAL 2
+-#define SBRDEC_SYNTAX_USAC 4
+-#define SBRDEC_SYNTAX_RSVD50 8
+-#define SBRDEC_USAC_INDEP \
+- 16 /* Flag indicating that USAC global independency flag is active. */
+-#define SBRDEC_LOW_POWER \
+- 32 /* Flag indicating that Low Power QMF mode shall be used. */
+-#define SBRDEC_PS_DECODED \
+- 64 /* Flag indicating that PS was decoded and rendered. */
+-#define SBRDEC_QUAD_RATE \
+- 128 /* Flag indicating that USAC SBR 4:1 is active. \
+- */
+-#define SBRDEC_USAC_HARMONICSBR \
+- 256 /* Flag indicating that USAC HBE tool is active. */
+-#define SBRDEC_LD_MPS_QMF \
+- 512 /* Flag indicating that the LD-MPS QMF shall be used. */
+-#define SBRDEC_USAC_ITES \
+- 1024 /* Flag indicating that USAC inter TES tool is active. */
+-#define SBRDEC_SYNTAX_DRM \
+- 2048 /* Flag indicating that DRM30/DRM+ reverse syntax is being used. */
+-#define SBRDEC_ELD_DOWNSCALE \
+- 4096 /* Flag indicating that ELD downscaled mode decoding is used */
+-#define SBRDEC_DOWNSAMPLE \
+- 8192 /* Flag indicating that the downsampling mode is used. */
+-#define SBRDEC_FLUSH 16384 /* Flag is used to flush all elements in use. */
+-#define SBRDEC_FORCE_RESET \
+- 32768 /* Flag is used to force a reset of all elements in use. */
+-#define SBRDEC_SKIP_QMF_ANA \
+- (1 << 21) /* Flag indicating that the input data is provided in the QMF \
+- domain. */
+-#define SBRDEC_SKIP_QMF_SYN \
+- (1 << 22) /* Flag indicating that the output data is exported in the QMF \
+- domain. */
+-
+-#define SBRDEC_HDR_STAT_RESET 1
+-#define SBRDEC_HDR_STAT_UPDATE 2
+-
+-typedef struct {
+- UCHAR ampResolution; /*!< Amplitude resolution of envelope values (0: 1.5dB,
+- 1: 3dB) */
+- UCHAR
+- xover_band; /*!< Start index in #v_k_master[] used for dynamic crossover
+- frequency */
+- UCHAR sbr_preprocessing; /*!< SBR prewhitening flag. */
+- UCHAR pvc_mode; /*!< Predictive vector coding mode */
+-} SBR_HEADER_DATA_BS_INFO;
+-
+-typedef struct {
+- /* Changes in these variables causes a reset of the decoder */
+- UCHAR startFreq; /*!< Index for SBR start frequency */
+- UCHAR stopFreq; /*!< Index for SBR highest frequency */
+- UCHAR freqScale; /*!< 0: linear scale, 1-3 logarithmic scales */
+- UCHAR alterScale; /*!< Flag for coarser frequency resolution */
+- UCHAR noise_bands; /*!< Noise bands per octave, read from bitstream*/
+-
+- /* don't require reset */
+- UCHAR limiterBands; /*!< Index for number of limiter bands per octave */
+- UCHAR limiterGains; /*!< Index to select gain limit */
+- UCHAR interpolFreq; /*!< Select gain calculation method (1: per QMF channel,
+- 0: per SBR band) */
+- UCHAR smoothingLength; /*!< Smoothing of gains over time (0: on 1: off) */
+-
+-} SBR_HEADER_DATA_BS;
+-
+-typedef struct {
+- SBR_SYNC_STATE
+- syncState; /*!< The current initialization status of the header */
+-
+- UCHAR status; /*!< Flags field used for signaling a reset right before the
+- processing starts and an update from config (e.g. ASC). */
+- UCHAR
+- frameErrorFlag; /*!< Frame data valid flag. CAUTION: This variable will be
+- overwritten by the flag stored in the element
+- structure. This is necessary because of the frame
+- delay. There it might happen that different slots use
+- the same header. */
+- UCHAR numberTimeSlots; /*!< AAC: 16,15 */
+- UCHAR numberOfAnalysisBands; /*!< Number of QMF analysis bands */
+- UCHAR timeStep; /*!< Time resolution of SBR in QMF-slots */
+- UINT
+- sbrProcSmplRate; /*!< SBR processing sampling frequency (!=
+- OutputSamplingRate) (always: CoreSamplingRate *
+- UpSamplingFactor; even in single rate mode) */
+-
+- SBR_HEADER_DATA_BS bs_data; /*!< current SBR header. */
+- SBR_HEADER_DATA_BS bs_dflt; /*!< Default sbr header. */
+- SBR_HEADER_DATA_BS_INFO bs_info; /*!< SBR info. */
+-
+- FREQ_BAND_DATA freqBandData; /*!< Pointer to struct #FREQ_BAND_DATA */
+- UCHAR pvcIDprev;
+-} SBR_HEADER_DATA;
+-
+-typedef SBR_HEADER_DATA *HANDLE_SBR_HEADER_DATA;
+-
+-typedef struct {
+- UCHAR frameClass; /*!< Select grid type */
+- UCHAR nEnvelopes; /*!< Number of envelopes */
+- UCHAR borders[MAX_ENVELOPES + 1]; /*!< Envelope borders (in SBR-timeslots,
+- e.g. mp3PRO: 0..11) */
+- UCHAR freqRes[MAX_ENVELOPES]; /*!< Frequency resolution for each envelope
+- (0=low, 1=high) */
+- SCHAR tranEnv; /*!< Transient envelope, -1 if none */
+- UCHAR nNoiseEnvelopes; /*!< Number of noise envelopes */
+- UCHAR
+- bordersNoise[MAX_NOISE_ENVELOPES + 1]; /*!< borders of noise envelopes */
+- UCHAR pvcBorders[MAX_PVC_ENVELOPES + 1];
+- UCHAR noisePosition;
+- UCHAR varLength;
+-} FRAME_INFO;
+-
+-typedef struct {
+- FIXP_SGL sfb_nrg_prev[MAX_FREQ_COEFFS]; /*!< Previous envelope (required for
+- differential-coded values) */
+- FIXP_SGL
+- prevNoiseLevel[MAX_NOISE_COEFFS]; /*!< Previous noise envelope (required
+- for differential-coded values) */
+- COUPLING_MODE coupling; /*!< Stereo-mode of previous frame */
+- INVF_MODE sbr_invf_mode[MAX_INVF_BANDS]; /*!< Previous strength of filtering
+- in transposer */
+- UCHAR ampRes; /*!< Previous amplitude resolution (0: 1.5dB, 1: 3dB) */
+- UCHAR stopPos; /*!< Position in time where last envelope ended */
+- UCHAR frameErrorFlag; /*!< Previous frame status */
+- UCHAR prevSbrPitchInBins; /*!< Previous frame pitchInBins */
+- FRAME_INFO prevFrameInfo;
+-} SBR_PREV_FRAME_DATA;
+-
+-typedef SBR_PREV_FRAME_DATA *HANDLE_SBR_PREV_FRAME_DATA;
+-
+-typedef struct {
+- int nScaleFactors; /*!< total number of scalefactors in frame */
+-
+- FRAME_INFO frameInfo; /*!< time grid for current frame */
+- UCHAR domain_vec[MAX_ENVELOPES]; /*!< Bitfield containing direction of
+- delta-coding for each envelope
+- (0:frequency, 1:time) */
+- UCHAR domain_vec_noise
+- [MAX_NOISE_ENVELOPES]; /*!< Same as above, but for noise envelopes */
+-
+- INVF_MODE
+- sbr_invf_mode[MAX_INVF_BANDS]; /*!< Strength of filtering in transposer */
+- COUPLING_MODE coupling; /*!< Stereo-mode */
+- int ampResolutionCurrentFrame; /*!< Amplitude resolution of envelope values
+- (0: 1.5dB, 1: 3dB) */
+-
+- ULONG addHarmonics[ADD_HARMONICS_FLAGS_SIZE]; /*!< Flags for synthetic sine
+- addition (aligned to MSB) */
+-
+- FIXP_SGL iEnvelope[MAX_NUM_ENVELOPE_VALUES]; /*!< Envelope data */
+- FIXP_SGL sbrNoiseFloorLevel[MAX_NUM_NOISE_VALUES]; /*!< Noise envelope data */
+- UCHAR iTESactive; /*!< One flag for each envelope to enable USAC inter-TES */
+- UCHAR
+- interTempShapeMode[MAX_ENVELOPES]; /*!< USAC inter-TES:
+- bs_inter_temp_shape_mode[ch][env]
+- value */
+- UCHAR pvcID[PVC_NTIMESLOT]; /*!< One PVC ID value for each time slot */
+- UCHAR ns;
+- UCHAR sinusoidal_position;
+-
+- UCHAR sbrPatchingMode;
+- UCHAR sbrOversamplingFlag;
+- UCHAR sbrPitchInBins;
+-} SBR_FRAME_DATA;
+-
+-typedef SBR_FRAME_DATA *HANDLE_SBR_FRAME_DATA;
+-
+-/*!
+-\brief Maps sampling frequencies to frequencies for which setup tables are
+-available
+-
+-Maps arbitary sampling frequency to nearest neighbors for which setup tables
+-are available (e.g. 25600 -> 24000).
+-Used for startFreq calculation.
+-The mapping is defined in 14496-3 (4.6.18.2.6), fs(SBR), and table 4.82
+-
+-\return mapped sampling frequency
+-*/
+-UINT sbrdec_mapToStdSampleRate(UINT fs,
+- UINT isUsac); /*!< Output sampling frequency */
+-
+-void initSbrPrevFrameData(HANDLE_SBR_PREV_FRAME_DATA h_prev_data,
+- int timeSlots);
+-
+-int sbrGetChannelElement(HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_FRAME_DATA hFrameDataLeft,
+- HANDLE_SBR_FRAME_DATA hFrameDataRight,
+- HANDLE_SBR_PREV_FRAME_DATA hFrameDataLeftPrev,
+- UCHAR pvc_mode_last, HANDLE_FDK_BITSTREAM hBitBuf,
+- HANDLE_PS_DEC hParametricStereoDec, const UINT flags,
+- const int overlap);
+-
+-SBR_HEADER_STATUS
+-sbrGetHeaderData(HANDLE_SBR_HEADER_DATA headerData,
+- HANDLE_FDK_BITSTREAM hBitBuf, const UINT flags,
+- const int fIsSbrData, const UCHAR configMode);
+-
+-/*!
+- \brief Initialize SBR header data
+-
+- Copy default values to the header data struct and patch some entries
+- depending on the core codec.
+-*/
+-SBR_ERROR
+-initHeaderData(HANDLE_SBR_HEADER_DATA hHeaderData, const int sampleRateIn,
+- const int sampleRateOut, const INT downscaleFactor,
+- const int samplesPerFrame, const UINT flags,
+- const int setDefaultHdr);
+-#endif
+-
+-/* Convert headroom bits to exponent */
+-#define SCALE2EXP(s) (15 - (s))
+-#define EXP2SCALE(e) (15 - (e))
+diff --git a/libSBRdec/src/hbe.cpp b/libSBRdec/src/hbe.cpp
+deleted file mode 100644
+index 3310dcd..0000000
+--- a/libSBRdec/src/hbe.cpp
++++ /dev/null
+@@ -1,2202 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Fast FFT routines prototypes
+- \author Fabian Haussel
+-*/
+-
+-#include "hbe.h"
+-#include "qmf.h"
+-#include "env_extr.h"
+-
+-#define HBE_MAX_QMF_BANDS (40)
+-
+-#define HBE_MAX_OUT_SLOTS (11)
+-
+-#define QMF_WIN_LEN \
+- (12 + 6 - 4 - 1) /* 6 subband slots extra delay to align with HQ - 4 slots \
+- to compensate for critical sampling delay - 1 slot to \
+- align critical sampling exactly (w additional time \
+- domain delay)*/
+-
+-#ifndef PI
+-#define PI 3.14159265358979323846
+-#endif
+-
+-static const int xProducts[MAX_STRETCH_HBE - 1] = {
+- 1, 1, 1}; /* Cross products on(1)/off(0) for T=2,3,4. */
+-static const int startSubband2kL[33] = {
+- 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6,
+- 6, 8, 8, 8, 8, 8, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12};
+-
+-static const int pmin = 12;
+-
+-static const FIXP_DBL hintReal_F[4][3] = {
+- {FL2FXCONST_DBL(0.39840335f), FL2FXCONST_DBL(0.39840335f),
+- FL2FXCONST_DBL(-0.39840335f)},
+- {FL2FXCONST_DBL(0.39840335f), FL2FXCONST_DBL(-0.39840335f),
+- FL2FXCONST_DBL(-0.39840335f)},
+- {FL2FXCONST_DBL(-0.39840335f), FL2FXCONST_DBL(-0.39840335f),
+- FL2FXCONST_DBL(0.39840335f)},
+- {FL2FXCONST_DBL(-0.39840335f), FL2FXCONST_DBL(0.39840335f),
+- FL2FXCONST_DBL(0.39840335f)}};
+-
+-static const FIXP_DBL factors[4] = {
+- FL2FXCONST_DBL(0.39840335f), FL2FXCONST_DBL(-0.39840335f),
+- FL2FXCONST_DBL(-0.39840335f), FL2FXCONST_DBL(0.39840335f)};
+-
+-#define PSCALE 32
+-
+-static const FIXP_DBL p_F[128] = {FL2FXCONST_DBL(0.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(1.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(2.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(3.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(4.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(5.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(6.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(7.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(8.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(9.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(10.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(11.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(12.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(13.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(14.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(15.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(16.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(17.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(18.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(19.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(20.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(21.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(22.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(23.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(24.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(25.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(26.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(27.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(28.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(29.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(30.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(31.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(32.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(33.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(34.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(35.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(36.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(37.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(38.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(39.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(40.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(41.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(42.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(43.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(44.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(45.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(46.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(47.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(48.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(49.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(50.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(51.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(52.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(53.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(54.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(55.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(56.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(57.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(58.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(59.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(60.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(61.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(62.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(63.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(64.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(65.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(66.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(67.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(68.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(69.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(70.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(71.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(72.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(73.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(74.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(75.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(76.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(77.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(78.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(79.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(80.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(81.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(82.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(83.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(84.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(85.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(86.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(87.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(88.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(89.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(90.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(91.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(92.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(93.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(94.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(95.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(96.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(97.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(98.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(99.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(100.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(101.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(102.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(103.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(104.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(105.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(106.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(107.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(108.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(109.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(110.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(111.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(112.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(113.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(114.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(115.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(116.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(117.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(118.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(119.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(120.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(121.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(122.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(123.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(124.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(125.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(126.f / (PSCALE * 12.f)),
+- FL2FXCONST_DBL(127.f / (PSCALE * 12.f))};
+-
+-static const FIXP_DBL band_F[64] = {
+- FL2FXCONST_DBL((0.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((1.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((2.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((3.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((4.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((5.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((6.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((7.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((8.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((9.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((10.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((11.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((12.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((13.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((14.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((15.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((16.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((17.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((18.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((19.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((20.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((21.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((22.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((23.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((24.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((25.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((26.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((27.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((28.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((29.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((30.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((31.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((32.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((33.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((34.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((35.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((36.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((37.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((38.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((39.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((40.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((41.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((42.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((43.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((44.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((45.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((46.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((47.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((48.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((49.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((50.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((51.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((52.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((53.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((54.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((55.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((56.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((57.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((58.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((59.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((60.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((61.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((62.f * 2.f + 1) / (PSCALE << 2)),
+- FL2FXCONST_DBL((63.f * 2.f + 1) / (PSCALE << 2))};
+-
+-static const FIXP_DBL tr_str[3] = {FL2FXCONST_DBL(1.f / 4.f),
+- FL2FXCONST_DBL(2.f / 4.f),
+- FL2FXCONST_DBL(3.f / 4.f)};
+-
+-static const FIXP_DBL stretchfac[3] = {FL2FXCONST_DBL(1.f / 2.f),
+- FL2FXCONST_DBL(1.f / 3.f),
+- FL2FXCONST_DBL(1.f / 4.f)};
+-
+-static const FIXP_DBL cos_F[64] = {
+- 26353028, -79043208, 131685776, -184244944, 236697216, -289006912,
+- 341142496, -393072608, 444773984, -496191392, 547325824, -598114752,
+- 648559104, -698597248, 748230016, -797411904, 846083200, -894275136,
+- 941928192, -989013760, 1035474624, -1081340672, 1126555136, -1171063296,
+- 1214893696, -1257992192, 1300332544, -1341889408, 1382612736, -1422503808,
+- 1461586944, -1499741440, 1537039104, -1573364864, 1608743808, -1643196672,
+- 1676617344, -1709028992, 1740450560, -1770784896, 1800089472, -1828273536,
+- 1855357440, -1881356288, 1906190080, -1929876608, 1952428928, -1973777664,
+- 1993962880, -2012922240, 2030670208, -2047216000, 2062508288, -2076559488,
+- 2089376128, -2100932224, 2111196800, -2120214784, 2127953792, -2134394368,
+- 2139565056, -2143444864, 2146026624, -2147321856};
+-
+-static const FIXP_DBL twiddle[121] = {1073741824,
+- 1071442860,
+- 1064555814,
+- 1053110176,
+- 1037154959,
+- 1016758484,
+- 992008094,
+- 963009773,
+- 929887697,
+- 892783698,
+- 851856663,
+- 807281846,
+- 759250125,
+- 707967178,
+- 653652607,
+- 596538995,
+- 536870912,
+- 474903865,
+- 410903207,
+- 345142998,
+- 277904834,
+- 209476638,
+- 140151432,
+- 70226075,
+- 0,
+- -70226075,
+- -140151432,
+- -209476638,
+- -277904834,
+- -345142998,
+- -410903207,
+- -474903865,
+- -536870912,
+- -596538995,
+- -653652607,
+- -707967178,
+- -759250125,
+- -807281846,
+- -851856663,
+- -892783698,
+- -929887697,
+- -963009773,
+- -992008094,
+- -1016758484,
+- -1037154959,
+- -1053110176,
+- -1064555814,
+- -1071442860,
+- -1073741824,
+- -1071442860,
+- -1064555814,
+- -1053110176,
+- -1037154959,
+- -1016758484,
+- -992008094,
+- -963009773,
+- -929887697,
+- -892783698,
+- -851856663,
+- -807281846,
+- -759250125,
+- -707967178,
+- -653652607,
+- -596538995,
+- -536870912,
+- -474903865,
+- -410903207,
+- -345142998,
+- -277904834,
+- -209476638,
+- -140151432,
+- -70226075,
+- 0,
+- 70226075,
+- 140151432,
+- 209476638,
+- 277904834,
+- 345142998,
+- 410903207,
+- 474903865,
+- 536870912,
+- 596538995,
+- 653652607,
+- 707967178,
+- 759250125,
+- 807281846,
+- 851856663,
+- 892783698,
+- 929887697,
+- 963009773,
+- 992008094,
+- 1016758484,
+- 1037154959,
+- 1053110176,
+- 1064555814,
+- 1071442860,
+- 1073741824,
+- 1071442860,
+- 1064555814,
+- 1053110176,
+- 1037154959,
+- 1016758484,
+- 992008094,
+- 963009773,
+- 929887697,
+- 892783698,
+- 851856663,
+- 807281846,
+- 759250125,
+- 707967178,
+- 653652607,
+- 596538995,
+- 536870912,
+- 474903865,
+- 410903207,
+- 345142998,
+- 277904834,
+- 209476638,
+- 140151432,
+- 70226075,
+- 0};
+-
+-#if FIXP_QTW == FIXP_SGL
+-#define HTW(x) (x)
+-#else
+-#define HTW(x) FX_DBL2FX_QTW(FX_SGL2FX_DBL((const FIXP_SGL)x))
+-#endif
+-
+-static const FIXP_QTW post_twiddle_cos_8[8] = {
+- HTW(-1606), HTW(4756), HTW(-7723), HTW(10394),
+- HTW(-12665), HTW(14449), HTW(-15679), HTW(16305)};
+-
+-static const FIXP_QTW post_twiddle_cos_16[16] = {
+- HTW(-804), HTW(2404), HTW(-3981), HTW(5520), HTW(-7005), HTW(8423),
+- HTW(-9760), HTW(11003), HTW(-12140), HTW(13160), HTW(-14053), HTW(14811),
+- HTW(-15426), HTW(15893), HTW(-16207), HTW(16364)};
+-
+-static const FIXP_QTW post_twiddle_cos_24[24] = {
+- HTW(-536), HTW(1606), HTW(-2669), HTW(3720), HTW(-4756), HTW(5771),
+- HTW(-6762), HTW(7723), HTW(-8652), HTW(9543), HTW(-10394), HTW(11200),
+- HTW(-11958), HTW(12665), HTW(-13318), HTW(13913), HTW(-14449), HTW(14924),
+- HTW(-15334), HTW(15679), HTW(-15956), HTW(16165), HTW(-16305), HTW(16375)};
+-
+-static const FIXP_QTW post_twiddle_cos_32[32] = {
+- HTW(-402), HTW(1205), HTW(-2006), HTW(2801), HTW(-3590), HTW(4370),
+- HTW(-5139), HTW(5897), HTW(-6639), HTW(7366), HTW(-8076), HTW(8765),
+- HTW(-9434), HTW(10080), HTW(-10702), HTW(11297), HTW(-11866), HTW(12406),
+- HTW(-12916), HTW(13395), HTW(-13842), HTW(14256), HTW(-14635), HTW(14978),
+- HTW(-15286), HTW(15557), HTW(-15791), HTW(15986), HTW(-16143), HTW(16261),
+- HTW(-16340), HTW(16379)};
+-
+-static const FIXP_QTW post_twiddle_cos_40[40] = {
+- HTW(-322), HTW(965), HTW(-1606), HTW(2245), HTW(-2880), HTW(3511),
+- HTW(-4137), HTW(4756), HTW(-5368), HTW(5971), HTW(-6566), HTW(7150),
+- HTW(-7723), HTW(8285), HTW(-8833), HTW(9368), HTW(-9889), HTW(10394),
+- HTW(-10883), HTW(11356), HTW(-11810), HTW(12247), HTW(-12665), HTW(13063),
+- HTW(-13441), HTW(13799), HTW(-14135), HTW(14449), HTW(-14741), HTW(15011),
+- HTW(-15257), HTW(15480), HTW(-15679), HTW(15853), HTW(-16003), HTW(16129),
+- HTW(-16229), HTW(16305), HTW(-16356), HTW(16381)};
+-
+-static const FIXP_QTW post_twiddle_sin_8[8] = {
+- HTW(16305), HTW(-15679), HTW(14449), HTW(-12665),
+- HTW(10394), HTW(-7723), HTW(4756), HTW(-1606)};
+-
+-static const FIXP_QTW post_twiddle_sin_16[16] = {
+- HTW(16364), HTW(-16207), HTW(15893), HTW(-15426), HTW(14811), HTW(-14053),
+- HTW(13160), HTW(-12140), HTW(11003), HTW(-9760), HTW(8423), HTW(-7005),
+- HTW(5520), HTW(-3981), HTW(2404), HTW(-804)};
+-
+-static const FIXP_QTW post_twiddle_sin_24[24] = {
+- HTW(16375), HTW(-16305), HTW(16165), HTW(-15956), HTW(15679), HTW(-15334),
+- HTW(14924), HTW(-14449), HTW(13913), HTW(-13318), HTW(12665), HTW(-11958),
+- HTW(11200), HTW(-10394), HTW(9543), HTW(-8652), HTW(7723), HTW(-6762),
+- HTW(5771), HTW(-4756), HTW(3720), HTW(-2669), HTW(1606), HTW(-536)};
+-
+-static const FIXP_QTW post_twiddle_sin_32[32] = {
+- HTW(16379), HTW(-16340), HTW(16261), HTW(-16143), HTW(15986), HTW(-15791),
+- HTW(15557), HTW(-15286), HTW(14978), HTW(-14635), HTW(14256), HTW(-13842),
+- HTW(13395), HTW(-12916), HTW(12406), HTW(-11866), HTW(11297), HTW(-10702),
+- HTW(10080), HTW(-9434), HTW(8765), HTW(-8076), HTW(7366), HTW(-6639),
+- HTW(5897), HTW(-5139), HTW(4370), HTW(-3590), HTW(2801), HTW(-2006),
+- HTW(1205), HTW(-402)};
+-
+-static const FIXP_QTW post_twiddle_sin_40[40] = {
+- HTW(16381), HTW(-16356), HTW(16305), HTW(-16229), HTW(16129), HTW(-16003),
+- HTW(15853), HTW(-15679), HTW(15480), HTW(-15257), HTW(15011), HTW(-14741),
+- HTW(14449), HTW(-14135), HTW(13799), HTW(-13441), HTW(13063), HTW(-12665),
+- HTW(12247), HTW(-11810), HTW(11356), HTW(-10883), HTW(10394), HTW(-9889),
+- HTW(9368), HTW(-8833), HTW(8285), HTW(-7723), HTW(7150), HTW(-6566),
+- HTW(5971), HTW(-5368), HTW(4756), HTW(-4137), HTW(3511), HTW(-2880),
+- HTW(2245), HTW(-1606), HTW(965), HTW(-322)};
+-
+-static const FIXP_DBL preModCos[32] = {
+- -749875776, 786681536, 711263552, -821592064, -670937792, 854523392,
+- 628995648, -885396032, -585538240, 914135680, 540670208, -940673088,
+- -494499680, 964944384, 447137824, -986891008, -398698816, 1006460096,
+- 349299264, -1023604544, -299058240, 1038283072, 248096752, -1050460288,
+- -196537584, 1060106816, 144504928, -1067199488, -92124160, 1071721152,
+- 39521456, -1073660992};
+-
+-static const FIXP_DBL preModSin[32] = {
+- 768510144, 730789760, -804379072, -691308864, 838310208, 650162560,
+- -870221760, -607449920, 900036928, 563273856, -927683776, -517740896,
+- 953095808, 470960608, -976211712, -423045728, 996975808, 374111712,
+- -1015338112, -324276416, 1031254400, 273659904, -1044686336, -222384144,
+- 1055601472, 170572640, -1063973632, -118350192, 1069782528, 65842640,
+- -1073014208, -13176464};
+-
+-/* The cube root function */
+-/*****************************************************************************
+-
+- functionname: invCubeRootNorm2
+- description: delivers 1/cuberoot(op) in Q1.31 format and modified exponent
+-
+-*****************************************************************************/
+-#define CUBE_ROOT_BITS 7
+-#define CUBE_ROOT_VALUES (128 + 2)
+-#define CUBE_ROOT_BITS_MASK 0x7f
+-#define CUBE_ROOT_FRACT_BITS_MASK 0x007FFFFF
+-/* Inverse cube root table for operands running from 0.5 to 1.0 */
+-/* (INT) (1.0/cuberoot((op))); */
+-/* Implicit exponent is 1. */
+-
+-LNK_SECTION_CONSTDATA
+-static const FIXP_DBL invCubeRootTab[CUBE_ROOT_VALUES] = {
+- (0x50a28be6), (0x506d1172), (0x503823c4), (0x5003c05a), (0x4fcfe4c0),
+- (0x4f9c8e92), (0x4f69bb7d), (0x4f37693b), (0x4f059594), (0x4ed43e5f),
+- (0x4ea36181), (0x4e72fcea), (0x4e430e98), (0x4e139495), (0x4de48cf5),
+- (0x4db5f5db), (0x4d87cd73), (0x4d5a11f2), (0x4d2cc19c), (0x4cffdabb),
+- (0x4cd35ba4), (0x4ca742b7), (0x4c7b8e5c), (0x4c503d05), (0x4c254d2a),
+- (0x4bfabd50), (0x4bd08c00), (0x4ba6b7cd), (0x4b7d3f53), (0x4b542134),
+- (0x4b2b5c18), (0x4b02eeb1), (0x4adad7b8), (0x4ab315ea), (0x4a8ba80d),
+- (0x4a648cec), (0x4a3dc35b), (0x4a174a30), (0x49f1204a), (0x49cb448d),
+- (0x49a5b5e2), (0x49807339), (0x495b7b86), (0x4936cdc2), (0x491268ec),
+- (0x48ee4c08), (0x48ca761f), (0x48a6e63e), (0x48839b76), (0x486094de),
+- (0x483dd190), (0x481b50ad), (0x47f91156), (0x47d712b3), (0x47b553f0),
+- (0x4793d43c), (0x477292c9), (0x47518ece), (0x4730c785), (0x47103c2d),
+- (0x46efec06), (0x46cfd655), (0x46affa61), (0x46905777), (0x4670ece4),
+- (0x4651b9f9), (0x4632be0b), (0x4613f871), (0x45f56885), (0x45d70da5),
+- (0x45b8e72f), (0x459af487), (0x457d3511), (0x455fa835), (0x45424d5d),
+- (0x452523f6), (0x45082b6e), (0x44eb6337), (0x44cecac5), (0x44b2618d),
+- (0x44962708), (0x447a1ab1), (0x445e3c02), (0x44428a7c), (0x4427059e),
+- (0x440bacec), (0x43f07fe9), (0x43d57e1c), (0x43baa70e), (0x439ffa48),
+- (0x43857757), (0x436b1dc8), (0x4350ed2b), (0x4336e511), (0x431d050c),
+- (0x43034cb2), (0x42e9bb98), (0x42d05156), (0x42b70d85), (0x429defc0),
+- (0x4284f7a2), (0x426c24cb), (0x425376d8), (0x423aed6a), (0x42228823),
+- (0x420a46a6), (0x41f22898), (0x41da2d9f), (0x41c25561), (0x41aa9f86),
+- (0x41930bba), (0x417b99a5), (0x416448f5), (0x414d1956), (0x41360a76),
+- (0x411f1c06), (0x41084db5), (0x40f19f35), (0x40db1039), (0x40c4a074),
+- (0x40ae4f9b), (0x40981d64), (0x40820985), (0x406c13b6), (0x40563bb1),
+- (0x4040812e), (0x402ae3e7), (0x40156399), (0x40000000), (0x3FEAB8D9)};
+-/* n.a. */
+-static const FIXP_DBL invCubeRootCorrection[3] = {0x40000000, 0x50A28BE6,
+- 0x6597FA95};
+-
+-/*****************************************************************************
+- * \brief calculate 1.0/cube_root(op), op contains mantissa and exponent
+- * \param op_m: (i) mantissa of operand, must not be zero (0x0000.0000) or
+- * negative
+- * \param op_e: (i) pointer to the exponent of the operand (must be initialized)
+- * and .. (o) pointer to the exponent of the result
+- * \return: (o) mantissa of the result
+- * \description:
+- * This routine calculates the cube root of the input operand, that is
+- * given with its mantissa in Q31 format (FIXP_DBL) and its exponent (INT).
+- * The resulting mantissa is returned in format Q31. The exponent (*op_e)
+- * is modified accordingly. It is not assured, that the result is fully
+- * left-aligned but assumed to have not more than 2 bits headroom. There is one
+- * macro to activate the use of this algorithm: FUNCTION_invCubeRootNorm2 By
+- * means of activating the macro INVCUBEROOTNORM2_LINEAR_INTERPOLATE_HQ, a
+- * slightly higher precision is reachable (by default, not active). For DEBUG
+- * purpose only: a FDK_ASSERT macro validates, if the input mantissa is greater
+- * zero.
+- *
+- */
+-static
+-#ifdef __arm__
+- FIXP_DBL FDK_FORCEINLINE
+- invCubeRootNorm2(FIXP_DBL op_m, INT* op_e)
+-#else
+- FIXP_DBL
+- invCubeRootNorm2(FIXP_DBL op_m, INT* op_e)
+-#endif
+-{
+- FDK_ASSERT(op_m > FIXP_DBL(0));
+-
+- /* normalize input, calculate shift value */
+- INT exponent = (INT)fNormz(op_m) - 1;
+- op_m <<= exponent;
+-
+- INT index = (INT)(op_m >> (DFRACT_BITS - 1 - (CUBE_ROOT_BITS + 1))) &
+- CUBE_ROOT_BITS_MASK;
+- FIXP_DBL fract = (FIXP_DBL)(((INT)op_m & CUBE_ROOT_FRACT_BITS_MASK)
+- << (CUBE_ROOT_BITS + 1));
+- FIXP_DBL diff = invCubeRootTab[index + 1] - invCubeRootTab[index];
+- op_m = fMultAddDiv2(invCubeRootTab[index], diff << 1, fract);
+-#if defined(INVCUBEROOTNORM2_LINEAR_INTERPOLATE_HQ)
+- /* reg1 = t[i] + (t[i+1]-t[i])*fract ... already computed ... +
+- * (1-fract)fract*(t[i+2]-t[i+1])/2 */
+- if (fract != (FIXP_DBL)0) {
+- /* fract = fract * (1 - fract) */
+- fract = fMultDiv2(fract, (FIXP_DBL)((LONG)0x80000000 - (LONG)fract)) << 1;
+- diff = diff - (invCubeRootTab[index + 2] - invCubeRootTab[index + 1]);
+- op_m = fMultAddDiv2(op_m, fract, diff);
+- }
+-#endif /* INVCUBEROOTNORM2_LINEAR_INTERPOLATE_HQ */
+-
+- /* calculate the output exponent = input * exp/3 = cubicroot(m)*2^(exp/3)
+- * where 2^(exp/3) = 2^k'*2 or 2^k'*2^(1/3) or 2^k'*2^(2/3) */
+- exponent = exponent - *op_e + 3;
+- INT shift_tmp =
+- ((INT)fMultDiv2((FIXP_SGL)fAbs(exponent), (FIXP_SGL)0x5556)) >> 16;
+- if (exponent < 0) {
+- shift_tmp = -shift_tmp;
+- }
+- INT rem = exponent - 3 * shift_tmp;
+- if (rem < 0) {
+- rem += 3;
+- shift_tmp--;
+- }
+-
+- *op_e = shift_tmp;
+- op_m = fMultDiv2(op_m, invCubeRootCorrection[rem]) << 2;
+-
+- return (op_m);
+-}
+-
+- /*****************************************************************************
+-
+- functionname: invFourthRootNorm2
+- description: delivers 1/FourthRoot(op) in Q1.31 format and modified
+- exponent
+-
+- *****************************************************************************/
+-
+-#define FOURTHROOT_BITS 7
+-#define FOURTHROOT_VALUES (128 + 2)
+-#define FOURTHROOT_BITS_MASK 0x7f
+-#define FOURTHROOT_FRACT_BITS_MASK 0x007FFFFF
+-
+-LNK_SECTION_CONSTDATA
+-static const FIXP_DBL invFourthRootTab[FOURTHROOT_VALUES] = {
+- (0x4c1bf829), (0x4bf61977), (0x4bd09843), (0x4bab72ef), (0x4b86a7eb),
+- (0x4b6235ac), (0x4b3e1ab6), (0x4b1a5592), (0x4af6e4d4), (0x4ad3c718),
+- (0x4ab0fb03), (0x4a8e7f42), (0x4a6c5288), (0x4a4a7393), (0x4a28e126),
+- (0x4a079a0c), (0x49e69d16), (0x49c5e91f), (0x49a57d04), (0x498557ac),
+- (0x49657802), (0x4945dcf9), (0x49268588), (0x490770ac), (0x48e89d6a),
+- (0x48ca0ac9), (0x48abb7d6), (0x488da3a6), (0x486fcd4f), (0x485233ed),
+- (0x4834d6a3), (0x4817b496), (0x47faccf0), (0x47de1ee0), (0x47c1a999),
+- (0x47a56c51), (0x47896643), (0x476d96af), (0x4751fcd6), (0x473697ff),
+- (0x471b6773), (0x47006a81), (0x46e5a079), (0x46cb08ae), (0x46b0a279),
+- (0x46966d34), (0x467c683d), (0x466292f4), (0x4648ecbc), (0x462f74fe),
+- (0x46162b20), (0x45fd0e91), (0x45e41ebe), (0x45cb5b19), (0x45b2c315),
+- (0x459a562a), (0x458213cf), (0x4569fb81), (0x45520cbc), (0x453a4701),
+- (0x4522a9d1), (0x450b34b0), (0x44f3e726), (0x44dcc0ba), (0x44c5c0f7),
+- (0x44aee768), (0x4498339e), (0x4481a527), (0x446b3b96), (0x4454f67e),
+- (0x443ed576), (0x4428d815), (0x4412fdf3), (0x43fd46ad), (0x43e7b1de),
+- (0x43d23f23), (0x43bcee1e), (0x43a7be6f), (0x4392afb8), (0x437dc19d),
+- (0x4368f3c5), (0x435445d6), (0x433fb779), (0x432b4856), (0x4316f81a),
+- (0x4302c66f), (0x42eeb305), (0x42dabd8a), (0x42c6e5ad), (0x42b32b21),
+- (0x429f8d96), (0x428c0cc2), (0x4278a859), (0x42656010), (0x4252339e),
+- (0x423f22bc), (0x422c2d23), (0x4219528b), (0x420692b2), (0x41f3ed51),
+- (0x41e16228), (0x41cef0f2), (0x41bc9971), (0x41aa5b62), (0x41983687),
+- (0x41862aa2), (0x41743775), (0x41625cc3), (0x41509a50), (0x413eefe2),
+- (0x412d5d3e), (0x411be22b), (0x410a7e70), (0x40f931d5), (0x40e7fc23),
+- (0x40d6dd24), (0x40c5d4a2), (0x40b4e268), (0x40a40642), (0x40933ffc),
+- (0x40828f64), (0x4071f447), (0x40616e73), (0x4050fdb9), (0x4040a1e6),
+- (0x40305acc), (0x4020283c), (0x40100a08), (0x40000000), (0x3ff009f9),
+-};
+-
+-static const FIXP_DBL invFourthRootCorrection[4] = {0x40000000, 0x4C1BF829,
+- 0x5A82799A, 0x6BA27E65};
+-
+-/* The fourth root function */
+-/*****************************************************************************
+- * \brief calculate 1.0/fourth_root(op), op contains mantissa and exponent
+- * \param op_m: (i) mantissa of operand, must not be zero (0x0000.0000) or
+- * negative
+- * \param op_e: (i) pointer to the exponent of the operand (must be initialized)
+- * and .. (o) pointer to the exponent of the result
+- * \return: (o) mantissa of the result
+- * \description:
+- * This routine calculates the cube root of the input operand, that is
+- * given with its mantissa in Q31 format (FIXP_DBL) and its exponent (INT).
+- * The resulting mantissa is returned in format Q31. The exponent (*op_e)
+- * is modified accordingly. It is not assured, that the result is fully
+- * left-aligned but assumed to have not more than 2 bits headroom. There is one
+- * macro to activate the use of this algorithm: FUNCTION_invFourthRootNorm2 By
+- * means of activating the macro INVFOURTHROOTNORM2_LINEAR_INTERPOLATE_HQ, a
+- * slightly higher precision is reachable (by default, not active). For DEBUG
+- * purpose only: a FDK_ASSERT macro validates, if the input mantissa is greater
+- * zero.
+- *
+- */
+-
+-/* #define INVFOURTHROOTNORM2_LINEAR_INTERPOLATE_HQ */
+-
+-static
+-#ifdef __arm__
+- FIXP_DBL FDK_FORCEINLINE
+- invFourthRootNorm2(FIXP_DBL op_m, INT* op_e)
+-#else
+- FIXP_DBL
+- invFourthRootNorm2(FIXP_DBL op_m, INT* op_e)
+-#endif
+-{
+- FDK_ASSERT(op_m > FL2FXCONST_DBL(0.0));
+-
+- /* normalize input, calculate shift value */
+- INT exponent = (INT)fNormz(op_m) - 1;
+- op_m <<= exponent;
+-
+- INT index = (INT)(op_m >> (DFRACT_BITS - 1 - (FOURTHROOT_BITS + 1))) &
+- FOURTHROOT_BITS_MASK;
+- FIXP_DBL fract = (FIXP_DBL)(((INT)op_m & FOURTHROOT_FRACT_BITS_MASK)
+- << (FOURTHROOT_BITS + 1));
+- FIXP_DBL diff = invFourthRootTab[index + 1] - invFourthRootTab[index];
+- op_m = invFourthRootTab[index] + (fMultDiv2(diff, fract) << 1);
+-
+-#if defined(INVFOURTHROOTNORM2_LINEAR_INTERPOLATE_HQ)
+- /* reg1 = t[i] + (t[i+1]-t[i])*fract ... already computed ... +
+- * (1-fract)fract*(t[i+2]-t[i+1])/2 */
+- if (fract != (FIXP_DBL)0) {
+- /* fract = fract * (1 - fract) */
+- fract = fMultDiv2(fract, (FIXP_DBL)((LONG)0x80000000 - (LONG)fract)) << 1;
+- diff = diff - (invFourthRootTab[index + 2] - invFourthRootTab[index + 1]);
+- op_m = fMultAddDiv2(op_m, fract, diff);
+- }
+-#endif /* INVFOURTHROOTNORM2_LINEAR_INTERPOLATE_HQ */
+-
+- exponent = exponent - *op_e + 4;
+- INT rem = exponent & 0x00000003;
+- INT shift_tmp = (exponent >> 2);
+-
+- *op_e = shift_tmp;
+- op_m = fMultDiv2(op_m, invFourthRootCorrection[rem]) << 2;
+-
+- return (op_m);
+-}
+-
+-/*****************************************************************************
+-
+- functionname: inv3EigthRootNorm2
+- description: delivers 1/cubert(op) normalized to .5...1 and the shift value
+-of the OUTPUT
+-
+-*****************************************************************************/
+-#define THREEIGTHROOT_BITS 7
+-#define THREEIGTHROOT_VALUES (128 + 2)
+-#define THREEIGTHROOT_BITS_MASK 0x7f
+-#define THREEIGTHROOT_FRACT_BITS_MASK 0x007FFFFF
+-
+-LNK_SECTION_CONSTDATA
+-static const FIXP_DBL inv3EigthRootTab[THREEIGTHROOT_VALUES] = {
+- (0x45cae0f2), (0x45b981bf), (0x45a8492a), (0x45973691), (0x45864959),
+- (0x457580e6), (0x4564dca4), (0x45545c00), (0x4543fe6b), (0x4533c35a),
+- (0x4523aa44), (0x4513b2a4), (0x4503dbf7), (0x44f425be), (0x44e48f7b),
+- (0x44d518b6), (0x44c5c0f7), (0x44b687c8), (0x44a76cb8), (0x44986f58),
+- (0x44898f38), (0x447acbef), (0x446c2514), (0x445d9a3f), (0x444f2b0d),
+- (0x4440d71a), (0x44329e07), (0x44247f73), (0x44167b04), (0x4408905e),
+- (0x43fabf28), (0x43ed070b), (0x43df67b0), (0x43d1e0c5), (0x43c471f7),
+- (0x43b71af6), (0x43a9db71), (0x439cb31c), (0x438fa1ab), (0x4382a6d2),
+- (0x4375c248), (0x4368f3c5), (0x435c3b03), (0x434f97bc), (0x434309ac),
+- (0x43369091), (0x432a2c28), (0x431ddc30), (0x4311a06c), (0x4305789c),
+- (0x42f96483), (0x42ed63e5), (0x42e17688), (0x42d59c30), (0x42c9d4a6),
+- (0x42be1fb1), (0x42b27d1a), (0x42a6ecac), (0x429b6e2f), (0x42900172),
+- (0x4284a63f), (0x42795c64), (0x426e23b0), (0x4262fbf2), (0x4257e4f9),
+- (0x424cde96), (0x4241e89a), (0x423702d8), (0x422c2d23), (0x4221674d),
+- (0x4216b12c), (0x420c0a94), (0x4201735b), (0x41f6eb57), (0x41ec725f),
+- (0x41e2084b), (0x41d7acf3), (0x41cd6030), (0x41c321db), (0x41b8f1ce),
+- (0x41aecfe5), (0x41a4bbf8), (0x419ab5e6), (0x4190bd89), (0x4186d2bf),
+- (0x417cf565), (0x41732558), (0x41696277), (0x415faca1), (0x415603b4),
+- (0x414c6792), (0x4142d818), (0x4139552a), (0x412fdea6), (0x41267470),
+- (0x411d1668), (0x4113c472), (0x410a7e70), (0x41014445), (0x40f815d4),
+- (0x40eef302), (0x40e5dbb4), (0x40dccfcd), (0x40d3cf33), (0x40cad9cb),
+- (0x40c1ef7b), (0x40b9102a), (0x40b03bbd), (0x40a7721c), (0x409eb32e),
+- (0x4095feda), (0x408d5508), (0x4084b5a0), (0x407c208b), (0x407395b2),
+- (0x406b14fd), (0x40629e56), (0x405a31a6), (0x4051ced8), (0x404975d5),
+- (0x40412689), (0x4038e0dd), (0x4030a4bd), (0x40287215), (0x402048cf),
+- (0x401828d7), (0x4010121a), (0x40080483), (0x40000000), (0x3ff8047d),
+-};
+-
+-/* The last value is rounded in order to avoid any overflow due to the values
+- * range of the root table */
+-static const FIXP_DBL inv3EigthRootCorrection[8] = {
+- 0x40000000, 0x45CAE0F2, 0x4C1BF829, 0x52FF6B55,
+- 0x5A82799A, 0x62B39509, 0x6BA27E65, 0x75606373};
+-
+-/* The 3/8 root function */
+-/*****************************************************************************
+- * \brief calculate 1.0/3Eigth_root(op) = 1.0/(x)^(3/8), op contains mantissa
+- * and exponent
+- * \param op_m: (i) mantissa of operand, must not be zero (0x0000.0000) or
+- * negative
+- * \param op_e: (i) pointer to the exponent of the operand (must be initialized)
+- * and .. (o) pointer to the exponent of the result
+- * \return: (o) mantissa of the result
+- * \description:
+- * This routine calculates the cube root of the input operand, that is
+- * given with its mantissa in Q31 format (FIXP_DBL) and its exponent (INT).
+- * The resulting mantissa is returned in format Q31. The exponent (*op_e)
+- * is modified accordingly. It is not assured, that the result is fully
+- * left-aligned but assumed to have not more than 2 bits headroom. There is one
+- * macro to activate the use of this algorithm: FUNCTION_inv3EigthRootNorm2 By
+- * means of activating the macro INVTHREEIGTHROOTNORM2_LINEAR_INTERPOLATE_HQ, a
+- * slightly higher precision is reachable (by default, not active). For DEBUG
+- * purpose only: a FDK_ASSERT macro validates, if the input mantissa is greater
+- * zero.
+- *
+- */
+-
+-/* #define INVTHREEIGTHROOTNORM2_LINEAR_INTERPOLATE_HQ */
+-
+-static
+-#ifdef __arm__
+- FIXP_DBL FDK_FORCEINLINE
+- inv3EigthRootNorm2(FIXP_DBL op_m, INT* op_e)
+-#else
+- FIXP_DBL
+- inv3EigthRootNorm2(FIXP_DBL op_m, INT* op_e)
+-#endif
+-{
+- FDK_ASSERT(op_m > FL2FXCONST_DBL(0.0));
+-
+- /* normalize input, calculate shift op_mue */
+- INT exponent = (INT)fNormz(op_m) - 1;
+- op_m <<= exponent;
+-
+- INT index = (INT)(op_m >> (DFRACT_BITS - 1 - (THREEIGTHROOT_BITS + 1))) &
+- THREEIGTHROOT_BITS_MASK;
+- FIXP_DBL fract = (FIXP_DBL)(((INT)op_m & THREEIGTHROOT_FRACT_BITS_MASK)
+- << (THREEIGTHROOT_BITS + 1));
+- FIXP_DBL diff = inv3EigthRootTab[index + 1] - inv3EigthRootTab[index];
+- op_m = inv3EigthRootTab[index] + (fMultDiv2(diff, fract) << 1);
+-
+-#if defined(INVTHREEIGTHROOTNORM2_LINEAR_INTERPOLATE_HQ)
+- /* op_m = t[i] + (t[i+1]-t[i])*fract ... already computed ... +
+- * (1-fract)fract*(t[i+2]-t[i+1])/2 */
+- if (fract != (FIXP_DBL)0) {
+- /* fract = fract * (1 - fract) */
+- fract = fMultDiv2(fract, (FIXP_DBL)((LONG)0x80000000 - (LONG)fract)) << 1;
+- diff = diff - (inv3EigthRootTab[index + 2] - inv3EigthRootTab[index + 1]);
+- op_m = fMultAddDiv2(op_m, fract, diff);
+- }
+-#endif /* INVTHREEIGTHROOTNORM2_LINEAR_INTERPOLATE_HQ */
+-
+- exponent = exponent - *op_e + 8;
+- INT rem = exponent & 0x00000007;
+- INT shift_tmp = (exponent >> 3);
+-
+- *op_e = shift_tmp * 3;
+- op_m = fMultDiv2(op_m, inv3EigthRootCorrection[rem]) << 2;
+-
+- return (fMult(op_m, fMult(op_m, op_m)));
+-}
+-
+-SBR_ERROR
+-QmfTransposerCreate(HANDLE_HBE_TRANSPOSER* hQmfTransposer, const int frameSize,
+- int bDisableCrossProducts, int bSbr41) {
+- HANDLE_HBE_TRANSPOSER hQmfTran = NULL;
+-
+- int i;
+-
+- if (hQmfTransposer != NULL) {
+- /* Memory allocation */
+- /*--------------------------------------------------------------------------------------------*/
+- hQmfTran =
+- (HANDLE_HBE_TRANSPOSER)FDKcalloc(1, sizeof(struct hbeTransposer));
+- if (hQmfTran == NULL) {
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- for (i = 0; i < MAX_STRETCH_HBE - 1; i++) {
+- hQmfTran->bXProducts[i] = (bDisableCrossProducts ? 0 : xProducts[i]);
+- }
+-
+- hQmfTran->timeDomainWinLen = frameSize;
+- if (frameSize == 768) {
+- hQmfTran->noCols =
+- (8 * frameSize / 3) / QMF_SYNTH_CHANNELS; /* 32 for 24:64 */
+- } else {
+- hQmfTran->noCols =
+- (bSbr41 + 1) * 2 * frameSize /
+- QMF_SYNTH_CHANNELS; /* 32 for 32:64 and 64 for 16:64 -> identical to
+- sbrdec->no_cols */
+- }
+-
+- hQmfTran->noChannels = frameSize / hQmfTran->noCols;
+-
+- hQmfTran->qmfInBufSize = QMF_WIN_LEN;
+- hQmfTran->qmfOutBufSize = 2 * (hQmfTran->noCols / 2 + QMF_WIN_LEN - 1);
+-
+- hQmfTran->inBuf_F =
+- (INT_PCM*)FDKcalloc(QMF_SYNTH_CHANNELS + 20 + 1, sizeof(INT_PCM));
+- /* buffered time signal needs to be delayed by synthesis_size; max
+- * synthesis_size = 20; */
+- if (hQmfTran->inBuf_F == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- hQmfTran->qmfInBufReal_F =
+- (FIXP_DBL**)FDKcalloc(hQmfTran->qmfInBufSize, sizeof(FIXP_DBL*));
+- hQmfTran->qmfInBufImag_F =
+- (FIXP_DBL**)FDKcalloc(hQmfTran->qmfInBufSize, sizeof(FIXP_DBL*));
+-
+- if (hQmfTran->qmfInBufReal_F == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+- if (hQmfTran->qmfInBufImag_F == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- for (i = 0; i < hQmfTran->qmfInBufSize; i++) {
+- hQmfTran->qmfInBufReal_F[i] = (FIXP_DBL*)FDKaalloc(
+- QMF_SYNTH_CHANNELS * sizeof(FIXP_DBL), ALIGNMENT_DEFAULT);
+- hQmfTran->qmfInBufImag_F[i] = (FIXP_DBL*)FDKaalloc(
+- QMF_SYNTH_CHANNELS * sizeof(FIXP_DBL), ALIGNMENT_DEFAULT);
+- if (hQmfTran->qmfInBufReal_F[i] == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+- if (hQmfTran->qmfInBufImag_F[i] == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+- }
+-
+- hQmfTran->qmfHBEBufReal_F =
+- (FIXP_DBL**)FDKcalloc(HBE_MAX_OUT_SLOTS, sizeof(FIXP_DBL*));
+- hQmfTran->qmfHBEBufImag_F =
+- (FIXP_DBL**)FDKcalloc(HBE_MAX_OUT_SLOTS, sizeof(FIXP_DBL*));
+-
+- if (hQmfTran->qmfHBEBufReal_F == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+- if (hQmfTran->qmfHBEBufImag_F == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
+- hQmfTran->qmfHBEBufReal_F[i] =
+- (FIXP_DBL*)FDKcalloc(QMF_SYNTH_CHANNELS, sizeof(FIXP_DBL));
+- hQmfTran->qmfHBEBufImag_F[i] =
+- (FIXP_DBL*)FDKcalloc(QMF_SYNTH_CHANNELS, sizeof(FIXP_DBL));
+- if (hQmfTran->qmfHBEBufReal_F[i] == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+- if (hQmfTran->qmfHBEBufImag_F[i] == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+- }
+-
+- hQmfTran->qmfBufferCodecTempSlot_F =
+- (FIXP_DBL*)FDKcalloc(QMF_SYNTH_CHANNELS / 2, sizeof(FIXP_DBL));
+- if (hQmfTran->qmfBufferCodecTempSlot_F == NULL) {
+- QmfTransposerClose(hQmfTran);
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- hQmfTran->bSbr41 = bSbr41;
+-
+- hQmfTran->highband_exp[0] = 0;
+- hQmfTran->highband_exp[1] = 0;
+- hQmfTran->target_exp[0] = 0;
+- hQmfTran->target_exp[1] = 0;
+-
+- *hQmfTransposer = hQmfTran;
+- }
+-
+- return SBRDEC_OK;
+-}
+-
+-SBR_ERROR QmfTransposerReInit(HANDLE_HBE_TRANSPOSER hQmfTransposer,
+- UCHAR* FreqBandTable[2], UCHAR NSfb[2])
+-/* removed bSbr41 from parameterlist:
+- don't know where to get this value from
+- at call-side */
+-{
+- int L, sfb, patch, stopPatch, qmfErr;
+-
+- if (hQmfTransposer != NULL) {
+- const FIXP_QTW* tmp_t_cos;
+- const FIXP_QTW* tmp_t_sin;
+-
+- hQmfTransposer->startBand = FreqBandTable[0][0];
+- FDK_ASSERT((!hQmfTransposer->bSbr41 && hQmfTransposer->startBand <= 32) ||
+- (hQmfTransposer->bSbr41 &&
+- hQmfTransposer->startBand <=
+- 16)); /* is checked by resetFreqBandTables() */
+- hQmfTransposer->stopBand = FreqBandTable[0][NSfb[0]];
+-
+- hQmfTransposer->synthSize =
+- 4 * ((hQmfTransposer->startBand + 4) / 8 + 1); /* 8, 12, 16, 20 */
+- hQmfTransposer->kstart = startSubband2kL[hQmfTransposer->startBand];
+-
+- /* don't know where to take this information from */
+- /* hQmfTransposer->bSbr41 = bSbr41; */
+-
+- if (hQmfTransposer->bSbr41) {
+- if (hQmfTransposer->kstart + hQmfTransposer->synthSize > 16)
+- hQmfTransposer->kstart = 16 - hQmfTransposer->synthSize;
+- } else if (hQmfTransposer->timeDomainWinLen == 768) {
+- if (hQmfTransposer->kstart + hQmfTransposer->synthSize > 24)
+- hQmfTransposer->kstart = 24 - hQmfTransposer->synthSize;
+- }
+-
+- hQmfTransposer->synthesisQmfPreModCos_F =
+- &preModCos[hQmfTransposer->kstart];
+- hQmfTransposer->synthesisQmfPreModSin_F =
+- &preModSin[hQmfTransposer->kstart];
+-
+- L = 2 * hQmfTransposer->synthSize; /* 8, 16, 24, 32, 40 */
+- /* Change analysis post twiddles */
+-
+- switch (L) {
+- case 8:
+- tmp_t_cos = post_twiddle_cos_8;
+- tmp_t_sin = post_twiddle_sin_8;
+- break;
+- case 16:
+- tmp_t_cos = post_twiddle_cos_16;
+- tmp_t_sin = post_twiddle_sin_16;
+- break;
+- case 24:
+- tmp_t_cos = post_twiddle_cos_24;
+- tmp_t_sin = post_twiddle_sin_24;
+- break;
+- case 32:
+- tmp_t_cos = post_twiddle_cos_32;
+- tmp_t_sin = post_twiddle_sin_32;
+- break;
+- case 40:
+- tmp_t_cos = post_twiddle_cos_40;
+- tmp_t_sin = post_twiddle_sin_40;
+- break;
+- default:
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- qmfErr = qmfInitSynthesisFilterBank(
+- &hQmfTransposer->HBESynthesisQMF, hQmfTransposer->synQmfStates,
+- hQmfTransposer->noCols, 0, hQmfTransposer->synthSize,
+- hQmfTransposer->synthSize, 1);
+- if (qmfErr != 0) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- qmfErr = qmfInitAnalysisFilterBank(
+- &hQmfTransposer->HBEAnalysiscQMF, hQmfTransposer->anaQmfStates,
+- hQmfTransposer->noCols / 2, 0, 2 * hQmfTransposer->synthSize,
+- 2 * hQmfTransposer->synthSize, 0);
+-
+- if (qmfErr != 0) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- hQmfTransposer->HBEAnalysiscQMF.t_cos = tmp_t_cos;
+- hQmfTransposer->HBEAnalysiscQMF.t_sin = tmp_t_sin;
+-
+- FDKmemset(hQmfTransposer->xOverQmf, 0,
+- MAX_NUM_PATCHES * sizeof(int)); /* global */
+- sfb = 0;
+- if (hQmfTransposer->bSbr41) {
+- stopPatch = MAX_NUM_PATCHES;
+- hQmfTransposer->maxStretch = MAX_STRETCH_HBE;
+- } else {
+- stopPatch = MAX_STRETCH_HBE;
+- }
+-
+- for (patch = 1; patch <= stopPatch; patch++) {
+- while (sfb <= NSfb[0] &&
+- FreqBandTable[0][sfb] <= patch * hQmfTransposer->startBand)
+- sfb++;
+- if (sfb <= NSfb[0]) {
+- /* If the distance is larger than three QMF bands - try aligning to high
+- * resolution frequency bands instead. */
+- if ((patch * hQmfTransposer->startBand - FreqBandTable[0][sfb - 1]) <=
+- 3) {
+- hQmfTransposer->xOverQmf[patch - 1] = FreqBandTable[0][sfb - 1];
+- } else {
+- int sfb_tmp = 0;
+- while (sfb_tmp <= NSfb[1] &&
+- FreqBandTable[1][sfb_tmp] <= patch * hQmfTransposer->startBand)
+- sfb_tmp++;
+- hQmfTransposer->xOverQmf[patch - 1] = FreqBandTable[1][sfb_tmp - 1];
+- }
+- } else {
+- hQmfTransposer->xOverQmf[patch - 1] = hQmfTransposer->stopBand;
+- hQmfTransposer->maxStretch = fMin(patch, MAX_STRETCH_HBE);
+- break;
+- }
+- }
+-
+- hQmfTransposer->highband_exp[0] = 0;
+- hQmfTransposer->highband_exp[1] = 0;
+- hQmfTransposer->target_exp[0] = 0;
+- hQmfTransposer->target_exp[1] = 0;
+- }
+-
+- return SBRDEC_OK;
+-}
+-
+-void QmfTransposerClose(HANDLE_HBE_TRANSPOSER hQmfTransposer) {
+- int i;
+-
+- if (hQmfTransposer != NULL) {
+- if (hQmfTransposer->inBuf_F) FDKfree(hQmfTransposer->inBuf_F);
+-
+- if (hQmfTransposer->qmfInBufReal_F) {
+- for (i = 0; i < hQmfTransposer->qmfInBufSize; i++) {
+- FDKafree(hQmfTransposer->qmfInBufReal_F[i]);
+- }
+- FDKfree(hQmfTransposer->qmfInBufReal_F);
+- }
+-
+- if (hQmfTransposer->qmfInBufImag_F) {
+- for (i = 0; i < hQmfTransposer->qmfInBufSize; i++) {
+- FDKafree(hQmfTransposer->qmfInBufImag_F[i]);
+- }
+- FDKfree(hQmfTransposer->qmfInBufImag_F);
+- }
+-
+- if (hQmfTransposer->qmfHBEBufReal_F) {
+- for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
+- FDKfree(hQmfTransposer->qmfHBEBufReal_F[i]);
+- }
+- FDKfree(hQmfTransposer->qmfHBEBufReal_F);
+- }
+-
+- if (hQmfTransposer->qmfHBEBufImag_F) {
+- for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
+- FDKfree(hQmfTransposer->qmfHBEBufImag_F[i]);
+- }
+- FDKfree(hQmfTransposer->qmfHBEBufImag_F);
+- }
+-
+- FDKfree(hQmfTransposer->qmfBufferCodecTempSlot_F);
+-
+- FDKfree(hQmfTransposer);
+- }
+-}
+-
+-inline void scaleUp(FIXP_DBL* real_m, FIXP_DBL* imag_m, INT* _e) {
+- INT reserve;
+- /* shift gc_r and gc_i up if possible */
+- reserve = CntLeadingZeros((INT(*real_m) ^ INT((*real_m >> 31))) |
+- (INT(*imag_m) ^ INT((*imag_m >> 31)))) -
+- 1;
+- reserve = fMax(reserve - 1,
+- 0); /* Leave one bit headroom such that (real_m^2 + imag_m^2)
+- does not overflow later if both are 0x80000000. */
+- reserve = fMin(reserve, *_e);
+- FDK_ASSERT(reserve >= 0);
+- *real_m <<= reserve;
+- *imag_m <<= reserve;
+- *_e -= reserve;
+-}
+-
+-static void calculateCenterFIXP(FIXP_DBL gammaVecReal, FIXP_DBL gammaVecImag,
+- FIXP_DBL* centerReal, FIXP_DBL* centerImag,
+- INT* exponent, int stretch, int mult) {
+- scaleUp(&gammaVecReal, &gammaVecImag, exponent);
+- FIXP_DBL energy = fPow2Div2(gammaVecReal) + fPow2Div2(gammaVecImag);
+-
+- if (energy != FL2FXCONST_DBL(0.f)) {
+- FIXP_DBL gc_r_m, gc_i_m, factor_m = (FIXP_DBL)0;
+- INT factor_e, gc_e;
+- factor_e = 2 * (*exponent) + 1;
+-
+- switch (stretch) {
+- case 2:
+- factor_m = invFourthRootNorm2(energy, &factor_e);
+- break;
+- case 3:
+- factor_m = invCubeRootNorm2(energy, &factor_e);
+- break;
+- case 4:
+- factor_m = inv3EigthRootNorm2(energy, &factor_e);
+- break;
+- }
+-
+- gc_r_m = fMultDiv2(gammaVecReal,
+- factor_m); /* exponent = HBE_SCALE + factor_e + 1 */
+- gc_i_m = fMultDiv2(gammaVecImag,
+- factor_m); /* exponent = HBE_SCALE + factor_e + 1*/
+- gc_e = *exponent + factor_e + 1;
+-
+- scaleUp(&gc_r_m, &gc_i_m, &gc_e);
+-
+- switch (mult) {
+- case 0:
+- *centerReal = gc_r_m;
+- *centerImag = gc_i_m;
+- break;
+- case 1:
+- *centerReal = fPow2Div2(gc_r_m) - fPow2Div2(gc_i_m);
+- *centerImag = fMult(gc_r_m, gc_i_m);
+- gc_e = 2 * gc_e + 1;
+- break;
+- case 2:
+- FIXP_DBL tmp_r = gc_r_m;
+- FIXP_DBL tmp_i = gc_i_m;
+- gc_r_m = fPow2Div2(gc_r_m) - fPow2Div2(gc_i_m);
+- gc_i_m = fMult(tmp_r, gc_i_m);
+- gc_e = 3 * gc_e + 1 + 1;
+- cplxMultDiv2(¢erReal[0], ¢erImag[0], gc_r_m, gc_i_m, tmp_r,
+- tmp_i);
+- break;
+- }
+-
+- scaleUp(centerReal, centerImag, &gc_e);
+-
+- FDK_ASSERT(gc_e >= 0);
+- *exponent = gc_e;
+- } else {
+- *centerReal = energy; /* energy = 0 */
+- *centerImag = energy; /* energy = 0 */
+- *exponent = (INT)energy;
+- }
+-}
+-
+-static int getHBEScaleFactorFrame(const int bSbr41, const int maxStretch,
+- const int pitchInBins) {
+- if (pitchInBins >= pmin * (1 + bSbr41)) {
+- /* crossproducts enabled */
+- return 26;
+- } else {
+- return (maxStretch == 2) ? 24 : 25;
+- }
+-}
+-
+-static void addHighBandPart(FIXP_DBL g_r_m, FIXP_DBL g_i_m, INT g_e,
+- FIXP_DBL mult, FIXP_DBL gammaCenterReal_m,
+- FIXP_DBL gammaCenterImag_m, INT gammaCenter_e,
+- INT stretch, INT scale_factor_hbe,
+- FIXP_DBL* qmfHBEBufReal_F,
+- FIXP_DBL* qmfHBEBufImag_F) {
+- if ((g_r_m | g_i_m) != FL2FXCONST_DBL(0.f)) {
+- FIXP_DBL factor_m = (FIXP_DBL)0;
+- INT factor_e;
+- INT add = (stretch == 4) ? 1 : 0;
+- INT shift = (stretch == 4) ? 1 : 2;
+-
+- scaleUp(&g_r_m, &g_i_m, &g_e);
+- FIXP_DBL energy = fPow2AddDiv2(fPow2Div2(g_r_m), g_i_m);
+- factor_e = 2 * g_e + 1;
+-
+- switch (stretch) {
+- case 2:
+- factor_m = invFourthRootNorm2(energy, &factor_e);
+- break;
+- case 3:
+- factor_m = invCubeRootNorm2(energy, &factor_e);
+- break;
+- case 4:
+- factor_m = inv3EigthRootNorm2(energy, &factor_e);
+- break;
+- }
+-
+- factor_m = fMult(factor_m, mult);
+-
+- FIXP_DBL tmp_r, tmp_i;
+- cplxMultDiv2(&tmp_r, &tmp_i, g_r_m, g_i_m, gammaCenterReal_m,
+- gammaCenterImag_m);
+-
+- g_r_m = fMultDiv2(tmp_r, factor_m) << shift;
+- g_i_m = fMultDiv2(tmp_i, factor_m) << shift;
+- g_e = scale_factor_hbe - (g_e + factor_e + gammaCenter_e + add);
+- fMax((INT)0, g_e);
+- *qmfHBEBufReal_F += g_r_m >> g_e;
+- *qmfHBEBufImag_F += g_i_m >> g_e;
+- }
+-}
+-
+-void QmfTransposerApply(HANDLE_HBE_TRANSPOSER hQmfTransposer,
+- FIXP_DBL** qmfBufferCodecReal,
+- FIXP_DBL** qmfBufferCodecImag, int nColsIn,
+- FIXP_DBL** ppQmfBufferOutReal_F,
+- FIXP_DBL** ppQmfBufferOutImag_F,
+- FIXP_DBL lpcFilterStatesReal[2 + (3 * (4))][(64)],
+- FIXP_DBL lpcFilterStatesImag[2 + (3 * (4))][(64)],
+- int pitchInBins, int scale_lb, int scale_hbe,
+- int* scale_hb, int timeStep, int firstSlotOffsset,
+- int ov_len,
+- KEEP_STATES_SYNCED_MODE keepStatesSyncedMode) {
+- int i, j, stretch, band, sourceband, r, s;
+- int qmfVocoderColsIn = hQmfTransposer->noCols / 2;
+- int bSbr41 = hQmfTransposer->bSbr41;
+-
+- const int winLength[3] = {10, 8, 6};
+- const int slotOffset = 6; /* hQmfTransposer->winLen-6; */
+-
+- int qmfOffset = 2 * hQmfTransposer->kstart;
+- int scale_border = (nColsIn == 64) ? 32 : nColsIn;
+-
+- INT slot_stretch4[9] = {0, 0, 0, 0, 2, 4, 6, 8, 10};
+- INT slot_stretch2[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+- INT slot_stretch3[10] = {0, 0, 0, 1, 3, 4, 6, 7, 9, 10};
+- INT filt_stretch3[10] = {0, 0, 0, 1, 0, 1, 0, 1, 0, 1};
+- INT filt_dummy[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+- INT* pSlotStretch;
+- INT* pFilt;
+-
+- int offset = 0; /* where to take QmfTransposer data */
+-
+- int signPreMod =
+- (hQmfTransposer->synthesisQmfPreModCos_F[0] < FL2FXCONST_DBL(0.f)) ? 1
+- : -1;
+-
+- int scale_factor_hbe =
+- getHBEScaleFactorFrame(bSbr41, hQmfTransposer->maxStretch, pitchInBins);
+-
+- if (keepStatesSyncedMode != KEEP_STATES_SYNCED_OFF) {
+- offset = hQmfTransposer->noCols - ov_len - LPC_ORDER;
+- }
+-
+- hQmfTransposer->highband_exp[0] = hQmfTransposer->highband_exp[1];
+- hQmfTransposer->target_exp[0] = hQmfTransposer->target_exp[1];
+-
+- hQmfTransposer->highband_exp[1] = scale_factor_hbe;
+- hQmfTransposer->target_exp[1] =
+- fixMax(hQmfTransposer->highband_exp[1], hQmfTransposer->highband_exp[0]);
+-
+- scale_factor_hbe = hQmfTransposer->target_exp[1];
+-
+- int shift_ov = hQmfTransposer->target_exp[0] - hQmfTransposer->target_exp[1];
+-
+- if (shift_ov != 0) {
+- for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
+- for (band = 0; band < QMF_SYNTH_CHANNELS; band++) {
+- if (shift_ov >= 0) {
+- hQmfTransposer->qmfHBEBufReal_F[i][band] <<= shift_ov;
+- hQmfTransposer->qmfHBEBufImag_F[i][band] <<= shift_ov;
+- } else {
+- hQmfTransposer->qmfHBEBufReal_F[i][band] >>= (-shift_ov);
+- hQmfTransposer->qmfHBEBufImag_F[i][band] >>= (-shift_ov);
+- }
+- }
+- }
+- }
+-
+- if ((keepStatesSyncedMode == KEEP_STATES_SYNCED_OFF) && shift_ov != 0) {
+- for (i = timeStep * firstSlotOffsset; i < ov_len; i++) {
+- for (band = hQmfTransposer->startBand; band < hQmfTransposer->stopBand;
+- band++) {
+- if (shift_ov >= 0) {
+- ppQmfBufferOutReal_F[i][band] <<= shift_ov;
+- ppQmfBufferOutImag_F[i][band] <<= shift_ov;
+- } else {
+- ppQmfBufferOutReal_F[i][band] >>= (-shift_ov);
+- ppQmfBufferOutImag_F[i][band] >>= (-shift_ov);
+- }
+- }
+- }
+-
+- /* shift lpc filterstates */
+- for (i = 0; i < timeStep * firstSlotOffsset + LPC_ORDER; i++) {
+- for (band = 0; band < (64); band++) {
+- if (shift_ov >= 0) {
+- lpcFilterStatesReal[i][band] <<= shift_ov;
+- lpcFilterStatesImag[i][band] <<= shift_ov;
+- } else {
+- lpcFilterStatesReal[i][band] >>= (-shift_ov);
+- lpcFilterStatesImag[i][band] >>= (-shift_ov);
+- }
+- }
+- }
+- }
+-
+- FIXP_DBL twid_m_new[3][2]; /* [stretch][cos/sin] */
+- INT stepsize = 1 + !bSbr41, sine_offset = 24, mod = 96;
+- INT mult[3] = {1, 2, 3};
+-
+- for (s = 0; s <= MAX_STRETCH_HBE - 2; s++) {
+- twid_m_new[s][0] = twiddle[(mult[s] * (stepsize * pitchInBins)) % mod];
+- twid_m_new[s][1] =
+- twiddle[((mult[s] * (stepsize * pitchInBins)) + sine_offset) % mod];
+- }
+-
+- /* Time-stretch */
+- for (j = 0; j < qmfVocoderColsIn; j++) {
+- int sign = -1, k, z, addrshift, codecTemp_e;
+- /* update inbuf */
+- for (i = 0; i < hQmfTransposer->synthSize; i++) {
+- hQmfTransposer->inBuf_F[i] =
+- hQmfTransposer->inBuf_F[i + 2 * hQmfTransposer->synthSize];
+- }
+-
+- /* run synthesis for two sbr slots as transposer uses
+- half slots double bands representation */
+- for (z = 0; z < 2; z++) {
+- int scale_factor = ((nColsIn == 64) && ((2 * j + z) < scale_border))
+- ? scale_lb
+- : scale_hbe;
+- codecTemp_e = scale_factor - 1; /* -2 for Div2 and cos/sin scale of 1 */
+-
+- for (k = 0; k < hQmfTransposer->synthSize; k++) {
+- int ki = hQmfTransposer->kstart + k;
+- hQmfTransposer->qmfBufferCodecTempSlot_F[k] =
+- fMultDiv2(signPreMod * hQmfTransposer->synthesisQmfPreModCos_F[k],
+- qmfBufferCodecReal[2 * j + z][ki]);
+- hQmfTransposer->qmfBufferCodecTempSlot_F[k] +=
+- fMultDiv2(signPreMod * hQmfTransposer->synthesisQmfPreModSin_F[k],
+- qmfBufferCodecImag[2 * j + z][ki]);
+- }
+-
+- C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL, (HBE_MAX_QMF_BANDS << 1));
+-
+- qmfSynthesisFilteringSlot(
+- &hQmfTransposer->HBESynthesisQMF,
+- hQmfTransposer->qmfBufferCodecTempSlot_F, NULL, 0,
+- -7 - hQmfTransposer->HBESynthesisQMF.filterScale - codecTemp_e + 1,
+- hQmfTransposer->inBuf_F + hQmfTransposer->synthSize * (z + 1), 1,
+- pWorkBuffer);
+-
+- C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, (HBE_MAX_QMF_BANDS << 1));
+- }
+-
+- C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL, (HBE_MAX_QMF_BANDS << 1));
+-
+- qmfAnalysisFilteringSlot(&hQmfTransposer->HBEAnalysiscQMF,
+- hQmfTransposer->qmfInBufReal_F[QMF_WIN_LEN - 1],
+- hQmfTransposer->qmfInBufImag_F[QMF_WIN_LEN - 1],
+- hQmfTransposer->inBuf_F + 1, 1, pWorkBuffer);
+-
+- C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, (HBE_MAX_QMF_BANDS << 1));
+-
+- if ((keepStatesSyncedMode == KEEP_STATES_SYNCED_NORMAL) &&
+- j <= qmfVocoderColsIn - ((LPC_ORDER + ov_len + QMF_WIN_LEN - 1) >> 1)) {
+- /* update in buffer */
+- for (i = 0; i < QMF_WIN_LEN - 1; i++) {
+- FDKmemcpy(
+- hQmfTransposer->qmfInBufReal_F[i],
+- hQmfTransposer->qmfInBufReal_F[i + 1],
+- sizeof(FIXP_DBL) * hQmfTransposer->HBEAnalysiscQMF.no_channels);
+- FDKmemcpy(
+- hQmfTransposer->qmfInBufImag_F[i],
+- hQmfTransposer->qmfInBufImag_F[i + 1],
+- sizeof(FIXP_DBL) * hQmfTransposer->HBEAnalysiscQMF.no_channels);
+- }
+- continue;
+- }
+-
+- for (stretch = 2; stretch <= hQmfTransposer->maxStretch; stretch++) {
+- int start = slotOffset - winLength[stretch - 2] / 2;
+- int stop = slotOffset + winLength[stretch - 2] / 2;
+-
+- FIXP_DBL factor = FL2FXCONST_DBL(1.f / 3.f);
+-
+- for (band = hQmfTransposer->xOverQmf[stretch - 2];
+- band < hQmfTransposer->xOverQmf[stretch - 1]; band++) {
+- FIXP_DBL gammaCenterReal_m[2] = {(FIXP_DBL)0, (FIXP_DBL)0},
+- gammaCenterImag_m[2] = {(FIXP_DBL)0, (FIXP_DBL)0};
+- INT gammaCenter_e[2] = {0, 0};
+-
+- FIXP_DBL gammaVecReal_m[2] = {(FIXP_DBL)0, (FIXP_DBL)0},
+- gammaVecImag_m[2] = {(FIXP_DBL)0, (FIXP_DBL)0};
+- INT gammaVec_e[2] = {0, 0};
+-
+- FIXP_DBL wingain = (FIXP_DBL)0;
+-
+- gammaCenter_e[0] =
+- SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+- gammaCenter_e[1] =
+- SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+-
+- /* interpolation filters for 3rd order */
+- sourceband = 2 * band / stretch - qmfOffset;
+- FDK_ASSERT(sourceband >= 0);
+-
+- /* maximum gammaCenter_e == 20 */
+- calculateCenterFIXP(
+- hQmfTransposer->qmfInBufReal_F[slotOffset][sourceband],
+- hQmfTransposer->qmfInBufImag_F[slotOffset][sourceband],
+- &gammaCenterReal_m[0], &gammaCenterImag_m[0], &gammaCenter_e[0],
+- stretch, stretch - 2);
+-
+- if (stretch == 4) {
+- r = band - 2 * (band / 2);
+- sourceband += (r == 0) ? -1 : 1;
+- pSlotStretch = slot_stretch4;
+- factor = FL2FXCONST_DBL(2.f / 3.f);
+- pFilt = filt_dummy;
+- } else if (stretch == 2) {
+- r = 0;
+- sourceband = 2 * band / stretch - qmfOffset;
+- pSlotStretch = slot_stretch2;
+- factor = FL2FXCONST_DBL(1.f / 3.f);
+- pFilt = filt_dummy;
+- } else {
+- r = 2 * band - 3 * (2 * band / 3);
+- sourceband = 2 * band / stretch - qmfOffset;
+- pSlotStretch = slot_stretch3;
+- factor = FL2FXCONST_DBL(1.4142f / 3.0f);
+- pFilt = filt_stretch3;
+- }
+-
+- if (r == 2) {
+- calculateCenterFIXP(
+- hQmfTransposer->qmfInBufReal_F[slotOffset][sourceband + 1],
+- hQmfTransposer->qmfInBufImag_F[slotOffset][sourceband + 1],
+- &gammaCenterReal_m[1], &gammaCenterImag_m[1], &gammaCenter_e[1],
+- stretch, stretch - 2);
+-
+- factor = FL2FXCONST_DBL(1.4142f / 6.0f);
+- }
+-
+- if (r == 2) {
+- for (k = start; k < stop; k++) {
+- gammaVecReal_m[0] =
+- hQmfTransposer->qmfInBufReal_F[pSlotStretch[k]][sourceband];
+- gammaVecReal_m[1] =
+- hQmfTransposer->qmfInBufReal_F[pSlotStretch[k]][sourceband + 1];
+- gammaVecImag_m[0] =
+- hQmfTransposer->qmfInBufImag_F[pSlotStretch[k]][sourceband];
+- gammaVecImag_m[1] =
+- hQmfTransposer->qmfInBufImag_F[pSlotStretch[k]][sourceband + 1];
+- gammaVec_e[0] = gammaVec_e[1] =
+- SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+-
+- if (pFilt[k] == 1) {
+- FIXP_DBL tmpRealF = gammaVecReal_m[0], tmpImagF;
+- gammaVecReal_m[0] =
+- (fMult(gammaVecReal_m[0], hintReal_F[sourceband % 4][1]) -
+- fMult(gammaVecImag_m[0],
+- hintReal_F[(sourceband + 3) % 4][1])) >>
+- 1; /* sum should be <= 1 because of sin/cos multiplication */
+- gammaVecImag_m[0] =
+- (fMult(tmpRealF, hintReal_F[(sourceband + 3) % 4][1]) +
+- fMult(gammaVecImag_m[0], hintReal_F[sourceband % 4][1])) >>
+- 1; /* sum should be <= 1 because of sin/cos multiplication */
+-
+- tmpRealF = hQmfTransposer
+- ->qmfInBufReal_F[pSlotStretch[k] + 1][sourceband];
+- tmpImagF = hQmfTransposer
+- ->qmfInBufImag_F[pSlotStretch[k] + 1][sourceband];
+-
+- gammaVecReal_m[0] +=
+- (fMult(tmpRealF, hintReal_F[sourceband % 4][1]) -
+- fMult(tmpImagF, hintReal_F[(sourceband + 1) % 4][1])) >>
+- 1; /* sum should be <= 1 because of sin/cos multiplication */
+- gammaVecImag_m[0] +=
+- (fMult(tmpRealF, hintReal_F[(sourceband + 1) % 4][1]) +
+- fMult(tmpImagF, hintReal_F[sourceband % 4][1])) >>
+- 1; /* sum should be <= 1 because of sin/cos multiplication */
+- gammaVec_e[0]++;
+-
+- tmpRealF = gammaVecReal_m[1];
+-
+- gammaVecReal_m[1] =
+- (fMult(gammaVecReal_m[1], hintReal_F[sourceband % 4][2]) -
+- fMult(gammaVecImag_m[1],
+- hintReal_F[(sourceband + 3) % 4][2])) >>
+- 1;
+- gammaVecImag_m[1] =
+- (fMult(tmpRealF, hintReal_F[(sourceband + 3) % 4][2]) +
+- fMult(gammaVecImag_m[1], hintReal_F[sourceband % 4][2])) >>
+- 1;
+-
+- tmpRealF =
+- hQmfTransposer
+- ->qmfInBufReal_F[pSlotStretch[k] + 1][sourceband + 1];
+- tmpImagF =
+- hQmfTransposer
+- ->qmfInBufImag_F[pSlotStretch[k] + 1][sourceband + 1];
+-
+- gammaVecReal_m[1] +=
+- (fMult(tmpRealF, hintReal_F[sourceband % 4][2]) -
+- fMult(tmpImagF, hintReal_F[(sourceband + 1) % 4][2])) >>
+- 1;
+- gammaVecImag_m[1] +=
+- (fMult(tmpRealF, hintReal_F[(sourceband + 1) % 4][2]) +
+- fMult(tmpImagF, hintReal_F[sourceband % 4][2])) >>
+- 1;
+- gammaVec_e[1]++;
+- }
+-
+- addHighBandPart(gammaVecReal_m[1], gammaVecImag_m[1], gammaVec_e[1],
+- factor, gammaCenterReal_m[0], gammaCenterImag_m[0],
+- gammaCenter_e[0], stretch, scale_factor_hbe,
+- &hQmfTransposer->qmfHBEBufReal_F[k][band],
+- &hQmfTransposer->qmfHBEBufImag_F[k][band]);
+-
+- addHighBandPart(gammaVecReal_m[0], gammaVecImag_m[0], gammaVec_e[0],
+- factor, gammaCenterReal_m[1], gammaCenterImag_m[1],
+- gammaCenter_e[1], stretch, scale_factor_hbe,
+- &hQmfTransposer->qmfHBEBufReal_F[k][band],
+- &hQmfTransposer->qmfHBEBufImag_F[k][band]);
+- }
+- } else {
+- for (k = start; k < stop; k++) {
+- gammaVecReal_m[0] =
+- hQmfTransposer->qmfInBufReal_F[pSlotStretch[k]][sourceband];
+- gammaVecImag_m[0] =
+- hQmfTransposer->qmfInBufImag_F[pSlotStretch[k]][sourceband];
+- gammaVec_e[0] =
+- SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+-
+- if (pFilt[k] == 1) {
+- FIXP_DBL tmpRealF = gammaVecReal_m[0], tmpImagF;
+- gammaVecReal_m[0] =
+- (fMult(gammaVecReal_m[0], hintReal_F[sourceband % 4][1]) -
+- fMult(gammaVecImag_m[0],
+- hintReal_F[(sourceband + 3) % 4][1])) >>
+- 1; /* sum should be <= 1 because of sin/cos multiplication */
+- gammaVecImag_m[0] =
+- (fMult(tmpRealF, hintReal_F[(sourceband + 3) % 4][1]) +
+- fMult(gammaVecImag_m[0], hintReal_F[sourceband % 4][1])) >>
+- 1; /* sum should be <= 1 because of sin/cos multiplication */
+-
+- tmpRealF = hQmfTransposer
+- ->qmfInBufReal_F[pSlotStretch[k] + 1][sourceband];
+- tmpImagF = hQmfTransposer
+- ->qmfInBufImag_F[pSlotStretch[k] + 1][sourceband];
+-
+- gammaVecReal_m[0] +=
+- (fMult(tmpRealF, hintReal_F[sourceband % 4][1]) -
+- fMult(tmpImagF, hintReal_F[(sourceband + 1) % 4][1])) >>
+- 1; /* sum should be <= 1 because of sin/cos multiplication */
+- gammaVecImag_m[0] +=
+- (fMult(tmpRealF, hintReal_F[(sourceband + 1) % 4][1]) +
+- fMult(tmpImagF, hintReal_F[sourceband % 4][1])) >>
+- 1; /* sum should be <= 1 because of sin/cos multiplication */
+- gammaVec_e[0]++;
+- }
+-
+- addHighBandPart(gammaVecReal_m[0], gammaVecImag_m[0], gammaVec_e[0],
+- factor, gammaCenterReal_m[0], gammaCenterImag_m[0],
+- gammaCenter_e[0], stretch, scale_factor_hbe,
+- &hQmfTransposer->qmfHBEBufReal_F[k][band],
+- &hQmfTransposer->qmfHBEBufImag_F[k][band]);
+- }
+- }
+-
+- /* pitchInBins is given with the resolution of a 768 bins FFT and we
+- * need 64 QMF units so factor 768/64 = 12 */
+- if (pitchInBins >= pmin * (1 + bSbr41)) {
+- int tr, ti1, ti2, mTr = 0, ts1 = 0, ts2 = 0, mVal_e = 0, temp_e = 0;
+- int sqmag0_e =
+- SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+-
+- FIXP_DBL mVal_F = FL2FXCONST_DBL(0.f), sqmag0_F, sqmag1_F, sqmag2_F,
+- temp_F, f1_F; /* all equal exponent */
+- sign = -1;
+-
+- sourceband = 2 * band / stretch - qmfOffset; /* consistent with the
+- already computed for
+- stretch = 3,4. */
+- FDK_ASSERT(sourceband >= 0);
+-
+- FIXP_DBL sqmag0R_F =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][sourceband];
+- FIXP_DBL sqmag0I_F =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][sourceband];
+- scaleUp(&sqmag0R_F, &sqmag0I_F, &sqmag0_e);
+-
+- sqmag0_F = fPow2Div2(sqmag0R_F);
+- sqmag0_F += fPow2Div2(sqmag0I_F);
+- sqmag0_e = 2 * sqmag0_e + 1;
+-
+- for (tr = 1; tr < stretch; tr++) {
+- int sqmag1_e =
+- SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+- int sqmag2_e =
+- SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+-
+- FIXP_DBL tmp_band = band_F[band];
+- FIXP_DBL tr_p =
+- fMult(p_F[pitchInBins] >> bSbr41, tr_str[tr - 1]); /* scale 7 */
+- f1_F =
+- fMult(tmp_band - tr_p, stretchfac[stretch - 2]); /* scale 7 */
+- ti1 = (INT)(f1_F >> (DFRACT_BITS - 1 - 7)) - qmfOffset;
+- ti2 = (INT)(((f1_F) + ((p_F[pitchInBins] >> bSbr41) >> 2)) >>
+- (DFRACT_BITS - 1 - 7)) -
+- qmfOffset;
+-
+- if (ti1 >= 0 && ti2 < 2 * hQmfTransposer->synthSize) {
+- FIXP_DBL sqmag1R_F =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ti1];
+- FIXP_DBL sqmag1I_F =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ti1];
+- scaleUp(&sqmag1R_F, &sqmag1I_F, &sqmag1_e);
+- sqmag1_F = fPow2Div2(sqmag1R_F);
+- sqmag1_F += fPow2Div2(sqmag1I_F);
+- sqmag1_e = 2 * sqmag1_e + 1;
+-
+- FIXP_DBL sqmag2R_F =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ti2];
+- FIXP_DBL sqmag2I_F =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ti2];
+- scaleUp(&sqmag2R_F, &sqmag2I_F, &sqmag2_e);
+- sqmag2_F = fPow2Div2(sqmag2R_F);
+- sqmag2_F += fPow2Div2(sqmag2I_F);
+- sqmag2_e = 2 * sqmag2_e + 1;
+-
+- int shift1 = fMin(fMax(sqmag1_e, sqmag2_e) - sqmag1_e, 31);
+- int shift2 = fMin(fMax(sqmag1_e, sqmag2_e) - sqmag2_e, 31);
+-
+- temp_F = fMin((sqmag1_F >> shift1), (sqmag2_F >> shift2));
+- temp_e = fMax(sqmag1_e, sqmag2_e);
+-
+- int shift3 = fMin(fMax(temp_e, mVal_e) - temp_e, 31);
+- int shift4 = fMin(fMax(temp_e, mVal_e) - mVal_e, 31);
+-
+- if ((temp_F >> shift3) > (mVal_F >> shift4)) {
+- mVal_F = temp_F;
+- mVal_e = temp_e; /* equals sqmag2_e + shift2 */
+- mTr = tr;
+- ts1 = ti1;
+- ts2 = ti2;
+- }
+- }
+- }
+-
+- int shift1 = fMin(fMax(sqmag0_e, mVal_e) - sqmag0_e, 31);
+- int shift2 = fMin(fMax(sqmag0_e, mVal_e) - mVal_e, 31);
+-
+- if ((mVal_F >> shift2) > (sqmag0_F >> shift1) && ts1 >= 0 &&
+- ts2 < 2 * hQmfTransposer->synthSize) {
+- INT gammaOut_e[2];
+- FIXP_DBL gammaOutReal_m[2], gammaOutImag_m[2];
+- FIXP_DBL tmpReal_m = (FIXP_DBL)0, tmpImag_m = (FIXP_DBL)0;
+-
+- int Tcenter, Tvec;
+-
+- Tcenter = stretch - mTr; /* default phase power parameters */
+- Tvec = mTr;
+- switch (stretch) /* 2 tap block creation design depends on stretch
+- order */
+- {
+- case 2:
+- wingain =
+- FL2FXCONST_DBL(5.f / 12.f); /* sum of taps divided by two */
+-
+- if (hQmfTransposer->bXProducts[0]) {
+- gammaCenterReal_m[0] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
+- gammaCenterImag_m[0] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
+-
+- for (k = 0; k < 2; k++) {
+- gammaVecReal_m[k] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset - 1 + k][ts2];
+- gammaVecImag_m[k] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset - 1 + k][ts2];
+- }
+-
+- gammaCenter_e[0] = SCALE2EXP(
+- -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+- gammaVec_e[0] = gammaVec_e[1] = SCALE2EXP(
+- -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+- }
+- break;
+-
+- case 4:
+- wingain =
+- FL2FXCONST_DBL(6.f / 12.f); /* sum of taps divided by two */
+- if (hQmfTransposer->bXProducts[2]) {
+- if (mTr == 1) {
+- gammaCenterReal_m[0] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
+- gammaCenterImag_m[0] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
+-
+- for (k = 0; k < 2; k++) {
+- gammaVecReal_m[k] =
+- hQmfTransposer
+- ->qmfInBufReal_F[slotOffset + 2 * (k - 1)][ts2];
+- gammaVecImag_m[k] =
+- hQmfTransposer
+- ->qmfInBufImag_F[slotOffset + 2 * (k - 1)][ts2];
+- }
+- } else if (mTr == 2) {
+- gammaCenterReal_m[0] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
+- gammaCenterImag_m[0] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
+-
+- for (k = 0; k < 2; k++) {
+- gammaVecReal_m[k] =
+- hQmfTransposer
+- ->qmfInBufReal_F[slotOffset + (k - 1)][ts2];
+- gammaVecImag_m[k] =
+- hQmfTransposer
+- ->qmfInBufImag_F[slotOffset + (k - 1)][ts2];
+- }
+- } else /* (mTr == 3) */
+- {
+- sign = 1;
+- Tcenter = mTr; /* opposite phase power parameters as ts2 is
+- center */
+- Tvec = stretch - mTr;
+-
+- gammaCenterReal_m[0] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ts2];
+- gammaCenterImag_m[0] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ts2];
+-
+- for (k = 0; k < 2; k++) {
+- gammaVecReal_m[k] =
+- hQmfTransposer
+- ->qmfInBufReal_F[slotOffset + 2 * (k - 1)][ts1];
+- gammaVecImag_m[k] =
+- hQmfTransposer
+- ->qmfInBufImag_F[slotOffset + 2 * (k - 1)][ts1];
+- }
+- }
+-
+- gammaCenter_e[0] = SCALE2EXP(
+- -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+- gammaVec_e[0] = gammaVec_e[1] = SCALE2EXP(
+- -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+- }
+- break;
+-
+- case 3:
+- wingain = FL2FXCONST_DBL(5.6568f /
+- 12.f); /* sum of taps divided by two */
+-
+- if (hQmfTransposer->bXProducts[1]) {
+- FIXP_DBL tmpReal_F, tmpImag_F;
+- if (mTr == 1) {
+- gammaCenterReal_m[0] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
+- gammaCenterImag_m[0] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
+- gammaVecReal_m[1] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ts2];
+- gammaVecImag_m[1] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ts2];
+-
+- addrshift = -2;
+- tmpReal_F =
+- hQmfTransposer
+- ->qmfInBufReal_F[addrshift + slotOffset][ts2];
+- tmpImag_F =
+- hQmfTransposer
+- ->qmfInBufImag_F[addrshift + slotOffset][ts2];
+-
+- gammaVecReal_m[0] =
+- (fMult(factors[ts2 % 4], tmpReal_F) -
+- fMult(factors[(ts2 + 3) % 4], tmpImag_F)) >>
+- 1;
+- gammaVecImag_m[0] =
+- (fMult(factors[(ts2 + 3) % 4], tmpReal_F) +
+- fMult(factors[ts2 % 4], tmpImag_F)) >>
+- 1;
+-
+- tmpReal_F =
+- hQmfTransposer
+- ->qmfInBufReal_F[addrshift + 1 + slotOffset][ts2];
+- tmpImag_F =
+- hQmfTransposer
+- ->qmfInBufImag_F[addrshift + 1 + slotOffset][ts2];
+-
+- gammaVecReal_m[0] +=
+- (fMult(factors[ts2 % 4], tmpReal_F) -
+- fMult(factors[(ts2 + 1) % 4], tmpImag_F)) >>
+- 1;
+- gammaVecImag_m[0] +=
+- (fMult(factors[(ts2 + 1) % 4], tmpReal_F) +
+- fMult(factors[ts2 % 4], tmpImag_F)) >>
+- 1;
+-
+- } else /* (mTr == 2) */
+- {
+- sign = 1;
+- Tcenter = mTr; /* opposite phase power parameters as ts2 is
+- center */
+- Tvec = stretch - mTr;
+-
+- gammaCenterReal_m[0] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ts2];
+- gammaCenterImag_m[0] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ts2];
+- gammaVecReal_m[1] =
+- hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
+- gammaVecImag_m[1] =
+- hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
+-
+- addrshift = -2;
+- tmpReal_F =
+- hQmfTransposer
+- ->qmfInBufReal_F[addrshift + slotOffset][ts1];
+- tmpImag_F =
+- hQmfTransposer
+- ->qmfInBufImag_F[addrshift + slotOffset][ts1];
+-
+- gammaVecReal_m[0] =
+- (fMult(factors[ts1 % 4], tmpReal_F) -
+- fMult(factors[(ts1 + 3) % 4], tmpImag_F)) >>
+- 1;
+- gammaVecImag_m[0] =
+- (fMult(factors[(ts1 + 3) % 4], tmpReal_F) +
+- fMult(factors[ts1 % 4], tmpImag_F)) >>
+- 1;
+-
+- tmpReal_F =
+- hQmfTransposer
+- ->qmfInBufReal_F[addrshift + 1 + slotOffset][ts1];
+- tmpImag_F =
+- hQmfTransposer
+- ->qmfInBufImag_F[addrshift + 1 + slotOffset][ts1];
+-
+- gammaVecReal_m[0] +=
+- (fMult(factors[ts1 % 4], tmpReal_F) -
+- fMult(factors[(ts1 + 1) % 4], tmpImag_F)) >>
+- 1;
+- gammaVecImag_m[0] +=
+- (fMult(factors[(ts1 + 1) % 4], tmpReal_F) +
+- fMult(factors[ts1 % 4], tmpImag_F)) >>
+- 1;
+- }
+-
+- gammaCenter_e[0] = gammaVec_e[1] = SCALE2EXP(
+- -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
+- gammaVec_e[0] =
+- SCALE2EXP(
+- -hQmfTransposer->HBEAnalysiscQMF.outScalefactor) +
+- 1;
+- }
+- break;
+- default:
+- FDK_ASSERT(0);
+- break;
+- } /* stretch cases */
+-
+- /* parameter controlled phase modification parts */
+- /* maximum *_e == 20 */
+- calculateCenterFIXP(gammaCenterReal_m[0], gammaCenterImag_m[0],
+- &gammaCenterReal_m[0], &gammaCenterImag_m[0],
+- &gammaCenter_e[0], stretch, Tcenter - 1);
+- calculateCenterFIXP(gammaVecReal_m[0], gammaVecImag_m[0],
+- &gammaVecReal_m[0], &gammaVecImag_m[0],
+- &gammaVec_e[0], stretch, Tvec - 1);
+- calculateCenterFIXP(gammaVecReal_m[1], gammaVecImag_m[1],
+- &gammaVecReal_m[1], &gammaVecImag_m[1],
+- &gammaVec_e[1], stretch, Tvec - 1);
+-
+- /* Final multiplication of prepared parts */
+- for (k = 0; k < 2; k++) {
+- gammaOutReal_m[k] =
+- fMultDiv2(gammaVecReal_m[k], gammaCenterReal_m[0]) -
+- fMultDiv2(gammaVecImag_m[k], gammaCenterImag_m[0]);
+- gammaOutImag_m[k] =
+- fMultDiv2(gammaVecReal_m[k], gammaCenterImag_m[0]) +
+- fMultDiv2(gammaVecImag_m[k], gammaCenterReal_m[0]);
+- gammaOut_e[k] = gammaCenter_e[0] + gammaVec_e[k] + 1;
+- }
+-
+- scaleUp(&gammaOutReal_m[0], &gammaOutImag_m[0], &gammaOut_e[0]);
+- scaleUp(&gammaOutReal_m[1], &gammaOutImag_m[1], &gammaOut_e[1]);
+- FDK_ASSERT(gammaOut_e[0] >= 0);
+- FDK_ASSERT(gammaOut_e[0] < 32);
+-
+- tmpReal_m = gammaOutReal_m[0];
+- tmpImag_m = gammaOutImag_m[0];
+-
+- INT modstretch4 = ((stretch == 4) && (mTr == 2));
+-
+- FIXP_DBL cos_twid = twid_m_new[stretch - 2 - modstretch4][0];
+- FIXP_DBL sin_twid = sign * twid_m_new[stretch - 2 - modstretch4][1];
+-
+- gammaOutReal_m[0] =
+- fMult(tmpReal_m, cos_twid) -
+- fMult(tmpImag_m, sin_twid); /* sum should be <= 1 because of
+- sin/cos multiplication */
+- gammaOutImag_m[0] =
+- fMult(tmpImag_m, cos_twid) +
+- fMult(tmpReal_m, sin_twid); /* sum should be <= 1 because of
+- sin/cos multiplication */
+-
+- /* wingain */
+- for (k = 0; k < 2; k++) {
+- gammaOutReal_m[k] = (fMult(gammaOutReal_m[k], wingain) << 1);
+- gammaOutImag_m[k] = (fMult(gammaOutImag_m[k], wingain) << 1);
+- }
+-
+- gammaOutReal_m[1] >>= 1;
+- gammaOutImag_m[1] >>= 1;
+- gammaOut_e[0] += 2;
+- gammaOut_e[1] += 2;
+-
+- /* OLA including window scaling by wingain/3 */
+- for (k = 0; k < 2; k++) /* need k=1 to correspond to
+- grainModImag[slotOffset] -> out to
+- j*2+(slotOffset-offset) */
+- {
+- hQmfTransposer->qmfHBEBufReal_F[(k + slotOffset - 1)][band] +=
+- gammaOutReal_m[k] >> (scale_factor_hbe - gammaOut_e[k]);
+- hQmfTransposer->qmfHBEBufImag_F[(k + slotOffset - 1)][band] +=
+- gammaOutImag_m[k] >> (scale_factor_hbe - gammaOut_e[k]);
+- }
+- } /* mVal > qThrQMF * qThrQMF * sqmag0 && ts1 > 0 && ts2 < 64 */
+- } /* p >= pmin */
+- } /* for band */
+- } /* for stretch */
+-
+- for (i = 0; i < QMF_WIN_LEN - 1; i++) {
+- FDKmemcpy(hQmfTransposer->qmfInBufReal_F[i],
+- hQmfTransposer->qmfInBufReal_F[i + 1],
+- sizeof(FIXP_DBL) * hQmfTransposer->HBEAnalysiscQMF.no_channels);
+- FDKmemcpy(hQmfTransposer->qmfInBufImag_F[i],
+- hQmfTransposer->qmfInBufImag_F[i + 1],
+- sizeof(FIXP_DBL) * hQmfTransposer->HBEAnalysiscQMF.no_channels);
+- }
+-
+- if (keepStatesSyncedMode != KEEP_STATES_SYNCED_NOOUT) {
+- if (2 * j >= offset) {
+- /* copy first two slots of internal buffer to output */
+- if (keepStatesSyncedMode == KEEP_STATES_SYNCED_OUTDIFF) {
+- for (i = 0; i < 2; i++) {
+- FDKmemcpy(&ppQmfBufferOutReal_F[2 * j - offset + i]
+- [hQmfTransposer->xOverQmf[0]],
+- &hQmfTransposer
+- ->qmfHBEBufReal_F[i][hQmfTransposer->xOverQmf[0]],
+- (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
+- sizeof(FIXP_DBL));
+- FDKmemcpy(&ppQmfBufferOutImag_F[2 * j - offset + i]
+- [hQmfTransposer->xOverQmf[0]],
+- &hQmfTransposer
+- ->qmfHBEBufImag_F[i][hQmfTransposer->xOverQmf[0]],
+- (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
+- sizeof(FIXP_DBL));
+- }
+- } else {
+- for (i = 0; i < 2; i++) {
+- FDKmemcpy(&ppQmfBufferOutReal_F[2 * j + i + ov_len]
+- [hQmfTransposer->xOverQmf[0]],
+- &hQmfTransposer
+- ->qmfHBEBufReal_F[i][hQmfTransposer->xOverQmf[0]],
+- (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
+- sizeof(FIXP_DBL));
+- FDKmemcpy(&ppQmfBufferOutImag_F[2 * j + i + ov_len]
+- [hQmfTransposer->xOverQmf[0]],
+- &hQmfTransposer
+- ->qmfHBEBufImag_F[i][hQmfTransposer->xOverQmf[0]],
+- (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
+- sizeof(FIXP_DBL));
+- }
+- }
+- }
+- }
+-
+- /* move slots up */
+- for (i = 0; i < HBE_MAX_OUT_SLOTS - 2; i++) {
+- FDKmemcpy(
+- &hQmfTransposer->qmfHBEBufReal_F[i][hQmfTransposer->xOverQmf[0]],
+- &hQmfTransposer->qmfHBEBufReal_F[i + 2][hQmfTransposer->xOverQmf[0]],
+- (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
+- sizeof(FIXP_DBL));
+- FDKmemcpy(
+- &hQmfTransposer->qmfHBEBufImag_F[i][hQmfTransposer->xOverQmf[0]],
+- &hQmfTransposer->qmfHBEBufImag_F[i + 2][hQmfTransposer->xOverQmf[0]],
+- (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
+- sizeof(FIXP_DBL));
+- }
+-
+- /* finally set last two slot to zero */
+- for (i = 0; i < 2; i++) {
+- FDKmemset(&hQmfTransposer->qmfHBEBufReal_F[HBE_MAX_OUT_SLOTS - 1 - i]
+- [hQmfTransposer->xOverQmf[0]],
+- 0,
+- (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
+- sizeof(FIXP_DBL));
+- FDKmemset(&hQmfTransposer->qmfHBEBufImag_F[HBE_MAX_OUT_SLOTS - 1 - i]
+- [hQmfTransposer->xOverQmf[0]],
+- 0,
+- (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
+- sizeof(FIXP_DBL));
+- }
+- } /* qmfVocoderColsIn */
+-
+- if (keepStatesSyncedMode != KEEP_STATES_SYNCED_NOOUT) {
+- if (keepStatesSyncedMode == KEEP_STATES_SYNCED_OUTDIFF) {
+- for (i = 0; i < ov_len + LPC_ORDER; i++) {
+- for (band = hQmfTransposer->startBand; band < hQmfTransposer->stopBand;
+- band++) {
+- FIXP_DBL tmpR = ppQmfBufferOutReal_F[i][band];
+- FIXP_DBL tmpI = ppQmfBufferOutImag_F[i][band];
+-
+- ppQmfBufferOutReal_F[i][band] =
+- fMult(tmpR, cos_F[band]) -
+- fMult(tmpI, (-cos_F[64 - band - 1])); /* sum should be <= 1
+- because of sin/cos
+- multiplication */
+- ppQmfBufferOutImag_F[i][band] =
+- fMult(tmpR, (-cos_F[64 - band - 1])) +
+- fMult(tmpI, cos_F[band]); /* sum should by <= 1 because of sin/cos
+- multiplication */
+- }
+- }
+- } else {
+- for (i = offset; i < hQmfTransposer->noCols; i++) {
+- for (band = hQmfTransposer->startBand; band < hQmfTransposer->stopBand;
+- band++) {
+- FIXP_DBL tmpR = ppQmfBufferOutReal_F[i + ov_len][band];
+- FIXP_DBL tmpI = ppQmfBufferOutImag_F[i + ov_len][band];
+-
+- ppQmfBufferOutReal_F[i + ov_len][band] =
+- fMult(tmpR, cos_F[band]) -
+- fMult(tmpI, (-cos_F[64 - band - 1])); /* sum should be <= 1
+- because of sin/cos
+- multiplication */
+- ppQmfBufferOutImag_F[i + ov_len][band] =
+- fMult(tmpR, (-cos_F[64 - band - 1])) +
+- fMult(tmpI, cos_F[band]); /* sum should by <= 1 because of sin/cos
+- multiplication */
+- }
+- }
+- }
+- }
+-
+- *scale_hb = EXP2SCALE(scale_factor_hbe);
+-}
+-
+-int* GetxOverBandQmfTransposer(HANDLE_HBE_TRANSPOSER hQmfTransposer) {
+- if (hQmfTransposer)
+- return hQmfTransposer->xOverQmf;
+- else
+- return NULL;
+-}
+-
+-int Get41SbrQmfTransposer(HANDLE_HBE_TRANSPOSER hQmfTransposer) {
+- if (hQmfTransposer != NULL)
+- return hQmfTransposer->bSbr41;
+- else
+- return 0;
+-}
+diff --git a/libSBRdec/src/hbe.h b/libSBRdec/src/hbe.h
+deleted file mode 100644
+index fdffe1e..0000000
+--- a/libSBRdec/src/hbe.h
++++ /dev/null
+@@ -1,200 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#ifndef HBE_H
+-#define HBE_H
+-
+-#include "sbrdecoder.h"
+-
+-#ifndef QMF_SYNTH_CHANNELS
+-#define QMF_SYNTH_CHANNELS (64)
+-#endif
+-
+-#define HBE_QMF_FILTER_STATE_ANA_SIZE (400)
+-#define HBE_QMF_FILTER_STATE_SYN_SIZE (200)
+-
+-#ifndef MAX_NUM_PATCHES_HBE
+-#define MAX_NUM_PATCHES_HBE (6)
+-#endif
+-#define MAX_STRETCH_HBE (4)
+-
+-typedef enum {
+- KEEP_STATES_SYNCED_OFF = 0, /*!< normal QMF transposer behaviour */
+- KEEP_STATES_SYNCED_NORMAL = 1, /*!< QMF transposer called for syncing of
+- states the last 8/14 slots are calculated in
+- case next frame is HBE */
+- KEEP_STATES_SYNCED_OUTDIFF =
+- 2, /*!< QMF transposer behaviour as in normal case, but the calculated
+- slots are directly written to overlap area of buffer; only used in
+- resetSbrDec function */
+- KEEP_STATES_SYNCED_NOOUT =
+- 3 /*!< QMF transposer is called for syncing of states only, not output
+- is generated at all; only used in resetSbrDec function */
+-} KEEP_STATES_SYNCED_MODE;
+-
+-struct hbeTransposer {
+- int xOverQmf[MAX_NUM_PATCHES_HBE];
+-
+- int maxStretch;
+- int timeDomainWinLen;
+- int qmfInBufSize;
+- int qmfOutBufSize;
+- int noCols;
+- int noChannels;
+- int startBand;
+- int stopBand;
+- int bSbr41;
+-
+- INT_PCM *inBuf_F;
+- FIXP_DBL **qmfInBufReal_F;
+- FIXP_DBL **qmfInBufImag_F;
+-
+- FIXP_DBL *qmfBufferCodecTempSlot_F;
+-
+- QMF_FILTER_BANK HBEAnalysiscQMF;
+- QMF_FILTER_BANK HBESynthesisQMF;
+-
+- FIXP_DBL const *synthesisQmfPreModCos_F;
+- FIXP_DBL const *synthesisQmfPreModSin_F;
+-
+- FIXP_QAS anaQmfStates[HBE_QMF_FILTER_STATE_ANA_SIZE];
+- FIXP_QSS synQmfStates[HBE_QMF_FILTER_STATE_SYN_SIZE];
+-
+- FIXP_DBL **qmfHBEBufReal_F;
+- FIXP_DBL **qmfHBEBufImag_F;
+-
+- int bXProducts[MAX_STRETCH_HBE];
+-
+- int kstart;
+- int synthSize;
+-
+- int highband_exp[2];
+- int target_exp[2];
+-};
+-
+-typedef struct hbeTransposer *HANDLE_HBE_TRANSPOSER;
+-
+-SBR_ERROR QmfTransposerCreate(HANDLE_HBE_TRANSPOSER *hQmfTransposer,
+- const int frameSize, int bDisableCrossProducts,
+- int bSbr41);
+-
+-SBR_ERROR QmfTransposerReInit(HANDLE_HBE_TRANSPOSER hQmfTransposer,
+- UCHAR *FreqBandTable[2], UCHAR NSfb[2]);
+-
+-void QmfTransposerClose(HANDLE_HBE_TRANSPOSER hQmfTransposer);
+-
+-void QmfTransposerApply(HANDLE_HBE_TRANSPOSER hQmfTransposer,
+- FIXP_DBL **qmfBufferCodecReal,
+- FIXP_DBL **qmfBufferCodecImag, int nColsIn,
+- FIXP_DBL **ppQmfBufferOutReal_F,
+- FIXP_DBL **ppQmfBufferOutImag_F,
+- FIXP_DBL lpcFilterStatesReal[2 + (3 * (4))][(64)],
+- FIXP_DBL lpcFilterStatesImag[2 + (3 * (4))][(64)],
+- int pitchInBins, int scale_lb, int scale_hbe,
+- int *scale_hb, int timeStep, int firstSlotOffsset,
+- int ov_len,
+- KEEP_STATES_SYNCED_MODE keepStatesSyncedMode);
+-
+-int *GetxOverBandQmfTransposer(HANDLE_HBE_TRANSPOSER hQmfTransposer);
+-
+-int Get41SbrQmfTransposer(HANDLE_HBE_TRANSPOSER hQmfTransposer);
+-#endif /* HBE_H */
+diff --git a/libSBRdec/src/huff_dec.cpp b/libSBRdec/src/huff_dec.cpp
+deleted file mode 100644
+index 90c9541..0000000
+--- a/libSBRdec/src/huff_dec.cpp
++++ /dev/null
+@@ -1,137 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Huffman Decoder
+-*/
+-
+-#include "huff_dec.h"
+-
+-/***************************************************************************/
+-/*!
+- \brief Decodes one huffman code word
+-
+- Reads bits from the bitstream until a valid codeword is found.
+- The table entries are interpreted either as index to the next entry
+- or - if negative - as the codeword.
+-
+- \return decoded value
+-
+- \author
+-
+-****************************************************************************/
+-int DecodeHuffmanCW(Huffman h, /*!< pointer to huffman codebook table */
+- HANDLE_FDK_BITSTREAM hBs) /*!< Handle to Bitbuffer */
+-{
+- SCHAR index = 0;
+- int value, bit;
+-
+- while (index >= 0) {
+- bit = FDKreadBits(hBs, 1);
+- index = h[index][bit];
+- }
+-
+- value = index + 64; /* Add offset */
+-
+- return value;
+-}
+diff --git a/libSBRdec/src/huff_dec.h b/libSBRdec/src/huff_dec.h
+deleted file mode 100644
+index 9aa62b4..0000000
+--- a/libSBRdec/src/huff_dec.h
++++ /dev/null
+@@ -1,117 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Huffman Decoder
+-*/
+-#ifndef HUFF_DEC_H
+-#define HUFF_DEC_H
+-
+-#include "sbrdecoder.h"
+-#include "FDK_bitstream.h"
+-
+-typedef const SCHAR (*Huffman)[2];
+-
+-int DecodeHuffmanCW(Huffman h, HANDLE_FDK_BITSTREAM hBitBuf);
+-
+-#endif
+diff --git a/libSBRdec/src/lpp_tran.cpp b/libSBRdec/src/lpp_tran.cpp
+deleted file mode 100644
+index 2ef07eb..0000000
+--- a/libSBRdec/src/lpp_tran.cpp
++++ /dev/null
+@@ -1,1471 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Low Power Profile Transposer
+- This module provides the transposer. The main entry point is lppTransposer().
+- The function generates high frequency content by copying data from the low
+- band (provided by core codec) into the high band. This process is also
+- referred to as "patching". The function also implements spectral whitening by
+- means of inverse filtering based on LPC coefficients.
+-
+- Together with the QMF filterbank the transposer can be tested using a supplied
+- test program. See main_audio.cpp for details. This module does use fractional
+- arithmetic and the accuracy of the computations has an impact on the overall
+- sound quality. The module also needs to take into account the different
+- scaling of spectral data.
+-
+- \sa lppTransposer(), main_audio.cpp, sbr_scale.h, \ref documentationOverview
+-*/
+-
+-#ifdef __ANDROID__
+-#include "log/log.h"
+-#endif
+-
+-#include "lpp_tran.h"
+-
+-#include "sbr_ram.h"
+-#include "sbr_rom.h"
+-
+-#include "genericStds.h"
+-#include "autocorr2nd.h"
+-
+-#include "HFgen_preFlat.h"
+-
+-#if defined(__arm__)
+-#include "arm/lpp_tran_arm.cpp"
+-#endif
+-
+-#define LPC_SCALE_FACTOR 2
+-
+-/*!
+- *
+- * \brief Get bandwidth expansion factor from filtering level
+- *
+- * Returns a filter parameter (bandwidth expansion factor) depending on
+- * the desired filtering level signalled in the bitstream.
+- * When switching the filtering level from LOW to OFF, an additional
+- * level is being inserted to achieve a smooth transition.
+- */
+-
+-static FIXP_DBL mapInvfMode(INVF_MODE mode, INVF_MODE prevMode,
+- WHITENING_FACTORS whFactors) {
+- switch (mode) {
+- case INVF_LOW_LEVEL:
+- if (prevMode == INVF_OFF)
+- return whFactors.transitionLevel;
+- else
+- return whFactors.lowLevel;
+-
+- case INVF_MID_LEVEL:
+- return whFactors.midLevel;
+-
+- case INVF_HIGH_LEVEL:
+- return whFactors.highLevel;
+-
+- default:
+- if (prevMode == INVF_LOW_LEVEL)
+- return whFactors.transitionLevel;
+- else
+- return whFactors.off;
+- }
+-}
+-
+-/*!
+- *
+- * \brief Perform inverse filtering level emphasis
+- *
+- * Retrieve bandwidth expansion factor and apply smoothing for each filter band
+- *
+- */
+-
+-static void inverseFilteringLevelEmphasis(
+- HANDLE_SBR_LPP_TRANS hLppTrans, /*!< Handle of lpp transposer */
+- UCHAR nInvfBands, /*!< Number of bands for inverse filtering */
+- INVF_MODE *sbr_invf_mode, /*!< Current inverse filtering modes */
+- INVF_MODE *sbr_invf_mode_prev, /*!< Previous inverse filtering modes */
+- FIXP_DBL *bwVector /*!< Resulting filtering levels */
+-) {
+- for (int i = 0; i < nInvfBands; i++) {
+- FIXP_DBL accu;
+- FIXP_DBL bwTmp = mapInvfMode(sbr_invf_mode[i], sbr_invf_mode_prev[i],
+- hLppTrans->pSettings->whFactors);
+-
+- if (bwTmp < hLppTrans->bwVectorOld[i]) {
+- accu = fMultDiv2(FL2FXCONST_DBL(0.75f), bwTmp) +
+- fMultDiv2(FL2FXCONST_DBL(0.25f), hLppTrans->bwVectorOld[i]);
+- } else {
+- accu = fMultDiv2(FL2FXCONST_DBL(0.90625f), bwTmp) +
+- fMultDiv2(FL2FXCONST_DBL(0.09375f), hLppTrans->bwVectorOld[i]);
+- }
+-
+- if (accu<FL2FXCONST_DBL(0.015625f)>> 1) {
+- bwVector[i] = FL2FXCONST_DBL(0.0f);
+- } else {
+- bwVector[i] = fixMin(accu << 1, FL2FXCONST_DBL(0.99609375f));
+- }
+- }
+-}
+-
+-/* Resulting autocorrelation determinant exponent */
+-#define ACDET_EXP \
+- (2 * (DFRACT_BITS + sbrScaleFactor->lb_scale + 10 - ac.det_scale))
+-#define AC_EXP (-sbrScaleFactor->lb_scale + LPC_SCALE_FACTOR)
+-#define ALPHA_EXP (-sbrScaleFactor->lb_scale + LPC_SCALE_FACTOR + 1)
+-/* Resulting transposed QMF values exponent 16 bit normalized samplebits
+- * assumed. */
+-#define QMFOUT_EXP ((SAMPLE_BITS - 15) - sbrScaleFactor->lb_scale)
+-
+-static inline void calc_qmfBufferReal(FIXP_DBL **qmfBufferReal,
+- const FIXP_DBL *const lowBandReal,
+- const int startSample,
+- const int stopSample, const UCHAR hiBand,
+- const int dynamicScale, const int descale,
+- const FIXP_SGL a0r, const FIXP_SGL a1r) {
+- FIXP_DBL accu1, accu2;
+- int i;
+-
+- for (i = 0; i < stopSample - startSample; i++) {
+- accu1 = fMultDiv2(a1r, lowBandReal[i]);
+- accu1 = (fMultDiv2(a0r, lowBandReal[i + 1]) + accu1);
+- accu1 = accu1 >> dynamicScale;
+-
+- accu1 <<= 1;
+- accu2 = (lowBandReal[i + 2] >> descale);
+- qmfBufferReal[i + startSample][hiBand] = accu1 + accu2;
+- }
+-}
+-
+-/*!
+- *
+- * \brief Perform transposition by patching of subband samples.
+- * This function serves as the main entry point into the module. The function
+- * determines the areas for the patching process (these are the source range as
+- * well as the target range) and implements spectral whitening by means of
+- * inverse filtering. The function autoCorrelation2nd() is an auxiliary function
+- * for calculating the LPC coefficients for the filtering. The actual
+- * calculation of the LPC coefficients and the implementation of the filtering
+- * are done as part of lppTransposer().
+- *
+- * Note that the filtering is done on all available QMF subsamples, whereas the
+- * patching is only done on those QMF subsamples that will be used in the next
+- * QMF synthesis. The filtering is also implemented before the patching includes
+- * further dependencies on parameters from the SBR data.
+- *
+- */
+-
+-void lppTransposer(
+- HANDLE_SBR_LPP_TRANS hLppTrans, /*!< Handle of lpp transposer */
+- QMF_SCALE_FACTOR *sbrScaleFactor, /*!< Scaling factors */
+- FIXP_DBL **qmfBufferReal, /*!< Pointer to pointer to real part of subband
+- samples (source) */
+-
+- FIXP_DBL *degreeAlias, /*!< Vector for results of aliasing estimation */
+- FIXP_DBL **qmfBufferImag, /*!< Pointer to pointer to imaginary part of
+- subband samples (source) */
+- const int useLP, const int fPreWhitening, const int v_k_master0,
+- const int timeStep, /*!< Time step of envelope */
+- const int firstSlotOffs, /*!< Start position in time */
+- const int lastSlotOffs, /*!< Number of overlap-slots into next frame */
+- const int nInvfBands, /*!< Number of bands for inverse filtering */
+- INVF_MODE *sbr_invf_mode, /*!< Current inverse filtering modes */
+- INVF_MODE *sbr_invf_mode_prev /*!< Previous inverse filtering modes */
+-) {
+- INT bwIndex[MAX_NUM_PATCHES];
+- FIXP_DBL bwVector[MAX_NUM_PATCHES]; /*!< pole moving factors */
+- FIXP_DBL preWhiteningGains[(64) / 2];
+- int preWhiteningGains_exp[(64) / 2];
+-
+- int i;
+- int loBand, start, stop;
+- TRANSPOSER_SETTINGS *pSettings = hLppTrans->pSettings;
+- PATCH_PARAM *patchParam = pSettings->patchParam;
+- int patch;
+-
+- FIXP_SGL alphar[LPC_ORDER], a0r, a1r;
+- FIXP_SGL alphai[LPC_ORDER], a0i = 0, a1i = 0;
+- FIXP_SGL bw = FL2FXCONST_SGL(0.0f);
+-
+- int autoCorrLength;
+-
+- FIXP_DBL k1, k1_below = 0, k1_below2 = 0;
+-
+- ACORR_COEFS ac;
+- int startSample;
+- int stopSample;
+- int stopSampleClear;
+-
+- int comLowBandScale;
+- int ovLowBandShift;
+- int lowBandShift;
+- /* int ovHighBandShift;*/
+-
+- alphai[0] = FL2FXCONST_SGL(0.0f);
+- alphai[1] = FL2FXCONST_SGL(0.0f);
+-
+- startSample = firstSlotOffs * timeStep;
+- stopSample = pSettings->nCols + lastSlotOffs * timeStep;
+- FDK_ASSERT((lastSlotOffs * timeStep) <= pSettings->overlap);
+-
+- inverseFilteringLevelEmphasis(hLppTrans, nInvfBands, sbr_invf_mode,
+- sbr_invf_mode_prev, bwVector);
+-
+- stopSampleClear = stopSample;
+-
+- autoCorrLength = pSettings->nCols + pSettings->overlap;
+-
+- if (pSettings->noOfPatches > 0) {
+- /* Set upper subbands to zero:
+- This is required in case that the patches do not cover the complete
+- highband (because the last patch would be too short). Possible
+- optimization: Clearing bands up to usb would be sufficient here. */
+- int targetStopBand =
+- patchParam[pSettings->noOfPatches - 1].targetStartBand +
+- patchParam[pSettings->noOfPatches - 1].numBandsInPatch;
+-
+- int memSize = ((64) - targetStopBand) * sizeof(FIXP_DBL);
+-
+- if (!useLP) {
+- for (i = startSample; i < stopSampleClear; i++) {
+- FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
+- FDKmemclear(&qmfBufferImag[i][targetStopBand], memSize);
+- }
+- } else {
+- for (i = startSample; i < stopSampleClear; i++) {
+- FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
+- }
+- }
+- }
+-#ifdef __ANDROID__
+- else {
+- // Safetynet logging
+- android_errorWriteLog(0x534e4554, "112160868");
+- }
+-#endif
+-
+- /* init bwIndex for each patch */
+- FDKmemclear(bwIndex, sizeof(bwIndex));
+-
+- /*
+- Calc common low band scale factor
+- */
+- comLowBandScale =
+- fixMin(sbrScaleFactor->ov_lb_scale, sbrScaleFactor->lb_scale);
+-
+- ovLowBandShift = sbrScaleFactor->ov_lb_scale - comLowBandScale;
+- lowBandShift = sbrScaleFactor->lb_scale - comLowBandScale;
+- /* ovHighBandShift = firstSlotOffs == 0 ? ovLowBandShift:0;*/
+-
+- if (fPreWhitening) {
+- sbrDecoder_calculateGainVec(
+- qmfBufferReal, qmfBufferImag,
+- DFRACT_BITS - 1 - 16 -
+- sbrScaleFactor->ov_lb_scale, /* convert scale to exponent */
+- DFRACT_BITS - 1 - 16 -
+- sbrScaleFactor->lb_scale, /* convert scale to exponent */
+- pSettings->overlap, preWhiteningGains, preWhiteningGains_exp,
+- v_k_master0, startSample, stopSample);
+- }
+-
+- /* outer loop over bands to do analysis only once for each band */
+-
+- if (!useLP) {
+- start = pSettings->lbStartPatching;
+- stop = pSettings->lbStopPatching;
+- } else {
+- start = fixMax(1, pSettings->lbStartPatching - 2);
+- stop = patchParam[0].targetStartBand;
+- }
+-
+- for (loBand = start; loBand < stop; loBand++) {
+- FIXP_DBL lowBandReal[(((1024) / (32) * (4) / 2) + (3 * (4))) + LPC_ORDER];
+- FIXP_DBL *plowBandReal = lowBandReal;
+- FIXP_DBL **pqmfBufferReal =
+- qmfBufferReal + firstSlotOffs * timeStep /* + pSettings->overlap */;
+- FIXP_DBL lowBandImag[(((1024) / (32) * (4) / 2) + (3 * (4))) + LPC_ORDER];
+- FIXP_DBL *plowBandImag = lowBandImag;
+- FIXP_DBL **pqmfBufferImag =
+- qmfBufferImag + firstSlotOffs * timeStep /* + pSettings->overlap */;
+- int resetLPCCoeffs = 0;
+- int dynamicScale = DFRACT_BITS - 1 - LPC_SCALE_FACTOR;
+- int acDetScale = 0; /* scaling of autocorrelation determinant */
+-
+- for (i = 0;
+- i < LPC_ORDER + firstSlotOffs * timeStep /*+pSettings->overlap*/;
+- i++) {
+- *plowBandReal++ = hLppTrans->lpcFilterStatesRealLegSBR[i][loBand];
+- if (!useLP)
+- *plowBandImag++ = hLppTrans->lpcFilterStatesImagLegSBR[i][loBand];
+- }
+-
+- /*
+- Take old slope length qmf slot source values out of (overlap)qmf buffer
+- */
+- if (!useLP) {
+- for (i = 0;
+- i < pSettings->nCols + pSettings->overlap - firstSlotOffs * timeStep;
+- i++) {
+- *plowBandReal++ = (*pqmfBufferReal++)[loBand];
+- *plowBandImag++ = (*pqmfBufferImag++)[loBand];
+- }
+- } else {
+- /* pSettings->overlap is always even */
+- FDK_ASSERT((pSettings->overlap & 1) == 0);
+- for (i = 0; i < ((pSettings->nCols + pSettings->overlap -
+- firstSlotOffs * timeStep) >>
+- 1);
+- i++) {
+- *plowBandReal++ = (*pqmfBufferReal++)[loBand];
+- *plowBandReal++ = (*pqmfBufferReal++)[loBand];
+- }
+- if (pSettings->nCols & 1) {
+- *plowBandReal++ = (*pqmfBufferReal++)[loBand];
+- }
+- }
+-
+- /*
+- Determine dynamic scaling value.
+- */
+- dynamicScale =
+- fixMin(dynamicScale,
+- getScalefactor(lowBandReal, LPC_ORDER + pSettings->overlap) +
+- ovLowBandShift);
+- dynamicScale =
+- fixMin(dynamicScale,
+- getScalefactor(&lowBandReal[LPC_ORDER + pSettings->overlap],
+- pSettings->nCols) +
+- lowBandShift);
+- if (!useLP) {
+- dynamicScale =
+- fixMin(dynamicScale,
+- getScalefactor(lowBandImag, LPC_ORDER + pSettings->overlap) +
+- ovLowBandShift);
+- dynamicScale =
+- fixMin(dynamicScale,
+- getScalefactor(&lowBandImag[LPC_ORDER + pSettings->overlap],
+- pSettings->nCols) +
+- lowBandShift);
+- }
+- dynamicScale = fixMax(
+- 0, dynamicScale - 1); /* one additional bit headroom to prevent -1.0 */
+-
+- /*
+- Scale temporal QMF buffer.
+- */
+- scaleValues(&lowBandReal[0], LPC_ORDER + pSettings->overlap,
+- dynamicScale - ovLowBandShift);
+- scaleValues(&lowBandReal[LPC_ORDER + pSettings->overlap], pSettings->nCols,
+- dynamicScale - lowBandShift);
+-
+- if (!useLP) {
+- scaleValues(&lowBandImag[0], LPC_ORDER + pSettings->overlap,
+- dynamicScale - ovLowBandShift);
+- scaleValues(&lowBandImag[LPC_ORDER + pSettings->overlap],
+- pSettings->nCols, dynamicScale - lowBandShift);
+- }
+-
+- if (!useLP) {
+- acDetScale += autoCorr2nd_cplx(&ac, lowBandReal + LPC_ORDER,
+- lowBandImag + LPC_ORDER, autoCorrLength);
+- } else {
+- acDetScale +=
+- autoCorr2nd_real(&ac, lowBandReal + LPC_ORDER, autoCorrLength);
+- }
+-
+- /* Examine dynamic of determinant in autocorrelation. */
+- acDetScale += 2 * (comLowBandScale + dynamicScale);
+- acDetScale *= 2; /* two times reflection coefficent scaling */
+- acDetScale += ac.det_scale; /* ac scaling of determinant */
+-
+- /* In case of determinant < 10^-38, resetLPCCoeffs=1 has to be enforced. */
+- if (acDetScale > 126) {
+- resetLPCCoeffs = 1;
+- }
+-
+- alphar[1] = FL2FXCONST_SGL(0.0f);
+- if (!useLP) alphai[1] = FL2FXCONST_SGL(0.0f);
+-
+- if (ac.det != FL2FXCONST_DBL(0.0f)) {
+- FIXP_DBL tmp, absTmp, absDet;
+-
+- absDet = fixp_abs(ac.det);
+-
+- if (!useLP) {
+- tmp = (fMultDiv2(ac.r01r, ac.r12r) >> (LPC_SCALE_FACTOR - 1)) -
+- ((fMultDiv2(ac.r01i, ac.r12i) + fMultDiv2(ac.r02r, ac.r11r)) >>
+- (LPC_SCALE_FACTOR - 1));
+- } else {
+- tmp = (fMultDiv2(ac.r01r, ac.r12r) >> (LPC_SCALE_FACTOR - 1)) -
+- (fMultDiv2(ac.r02r, ac.r11r) >> (LPC_SCALE_FACTOR - 1));
+- }
+- absTmp = fixp_abs(tmp);
+-
+- /*
+- Quick check: is first filter coeff >= 1(4)
+- */
+- {
+- INT scale;
+- FIXP_DBL result = fDivNorm(absTmp, absDet, &scale);
+- scale = scale + ac.det_scale;
+-
+- if ((scale > 0) && (result >= (FIXP_DBL)MAXVAL_DBL >> scale)) {
+- resetLPCCoeffs = 1;
+- } else {
+- alphar[1] = FX_DBL2FX_SGL(scaleValue(result, scale));
+- if ((tmp < FL2FX_DBL(0.0f)) ^ (ac.det < FL2FX_DBL(0.0f))) {
+- alphar[1] = -alphar[1];
+- }
+- }
+- }
+-
+- if (!useLP) {
+- tmp = (fMultDiv2(ac.r01i, ac.r12r) >> (LPC_SCALE_FACTOR - 1)) +
+- ((fMultDiv2(ac.r01r, ac.r12i) -
+- (FIXP_DBL)fMultDiv2(ac.r02i, ac.r11r)) >>
+- (LPC_SCALE_FACTOR - 1));
+-
+- absTmp = fixp_abs(tmp);
+-
+- /*
+- Quick check: is second filter coeff >= 1(4)
+- */
+- {
+- INT scale;
+- FIXP_DBL result = fDivNorm(absTmp, absDet, &scale);
+- scale = scale + ac.det_scale;
+-
+- if ((scale > 0) &&
+- (result >= /*FL2FXCONST_DBL(1.f)*/ (FIXP_DBL)MAXVAL_DBL >>
+- scale)) {
+- resetLPCCoeffs = 1;
+- } else {
+- alphai[1] = FX_DBL2FX_SGL(scaleValue(result, scale));
+- if ((tmp < FL2FX_DBL(0.0f)) ^ (ac.det < FL2FX_DBL(0.0f))) {
+- alphai[1] = -alphai[1];
+- }
+- }
+- }
+- }
+- }
+-
+- alphar[0] = FL2FXCONST_SGL(0.0f);
+- if (!useLP) alphai[0] = FL2FXCONST_SGL(0.0f);
+-
+- if (ac.r11r != FL2FXCONST_DBL(0.0f)) {
+- /* ac.r11r is always >=0 */
+- FIXP_DBL tmp, absTmp;
+-
+- if (!useLP) {
+- tmp = (ac.r01r >> (LPC_SCALE_FACTOR + 1)) +
+- (fMultDiv2(alphar[1], ac.r12r) + fMultDiv2(alphai[1], ac.r12i));
+- } else {
+- if (ac.r01r >= FL2FXCONST_DBL(0.0f))
+- tmp = (ac.r01r >> (LPC_SCALE_FACTOR + 1)) +
+- fMultDiv2(alphar[1], ac.r12r);
+- else
+- tmp = -((-ac.r01r) >> (LPC_SCALE_FACTOR + 1)) +
+- fMultDiv2(alphar[1], ac.r12r);
+- }
+-
+- absTmp = fixp_abs(tmp);
+-
+- /*
+- Quick check: is first filter coeff >= 1(4)
+- */
+-
+- if (absTmp >= (ac.r11r >> 1)) {
+- resetLPCCoeffs = 1;
+- } else {
+- INT scale;
+- FIXP_DBL result = fDivNorm(absTmp, fixp_abs(ac.r11r), &scale);
+- alphar[0] = FX_DBL2FX_SGL(scaleValue(result, scale + 1));
+-
+- if ((tmp > FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f)))
+- alphar[0] = -alphar[0];
+- }
+-
+- if (!useLP) {
+- tmp = (ac.r01i >> (LPC_SCALE_FACTOR + 1)) +
+- (fMultDiv2(alphai[1], ac.r12r) - fMultDiv2(alphar[1], ac.r12i));
+-
+- absTmp = fixp_abs(tmp);
+-
+- /*
+- Quick check: is second filter coeff >= 1(4)
+- */
+- if (absTmp >= (ac.r11r >> 1)) {
+- resetLPCCoeffs = 1;
+- } else {
+- INT scale;
+- FIXP_DBL result = fDivNorm(absTmp, fixp_abs(ac.r11r), &scale);
+- alphai[0] = FX_DBL2FX_SGL(scaleValue(result, scale + 1));
+- if ((tmp > FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f)))
+- alphai[0] = -alphai[0];
+- }
+- }
+- }
+-
+- if (!useLP) {
+- /* Now check the quadratic criteria */
+- if ((fMultDiv2(alphar[0], alphar[0]) + fMultDiv2(alphai[0], alphai[0])) >=
+- FL2FXCONST_DBL(0.5f))
+- resetLPCCoeffs = 1;
+- if ((fMultDiv2(alphar[1], alphar[1]) + fMultDiv2(alphai[1], alphai[1])) >=
+- FL2FXCONST_DBL(0.5f))
+- resetLPCCoeffs = 1;
+- }
+-
+- if (resetLPCCoeffs) {
+- alphar[0] = FL2FXCONST_SGL(0.0f);
+- alphar[1] = FL2FXCONST_SGL(0.0f);
+- if (!useLP) {
+- alphai[0] = FL2FXCONST_SGL(0.0f);
+- alphai[1] = FL2FXCONST_SGL(0.0f);
+- }
+- }
+-
+- if (useLP) {
+- /* Aliasing detection */
+- if (ac.r11r == FL2FXCONST_DBL(0.0f)) {
+- k1 = FL2FXCONST_DBL(0.0f);
+- } else {
+- if (fixp_abs(ac.r01r) >= fixp_abs(ac.r11r)) {
+- if (fMultDiv2(ac.r01r, ac.r11r) < FL2FX_DBL(0.0f)) {
+- k1 = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_SGL(1.0f)*/;
+- } else {
+- /* Since this value is squared later, it must not ever become -1.0f.
+- */
+- k1 = (FIXP_DBL)(MINVAL_DBL + 1) /*FL2FXCONST_SGL(-1.0f)*/;
+- }
+- } else {
+- INT scale;
+- FIXP_DBL result =
+- fDivNorm(fixp_abs(ac.r01r), fixp_abs(ac.r11r), &scale);
+- k1 = scaleValue(result, scale);
+-
+- if (!((ac.r01r < FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f)))) {
+- k1 = -k1;
+- }
+- }
+- }
+- if ((loBand > 1) && (loBand < v_k_master0)) {
+- /* Check if the gain should be locked */
+- FIXP_DBL deg =
+- /*FL2FXCONST_DBL(1.0f)*/ (FIXP_DBL)MAXVAL_DBL - fPow2(k1_below);
+- degreeAlias[loBand] = FL2FXCONST_DBL(0.0f);
+- if (((loBand & 1) == 0) && (k1 < FL2FXCONST_DBL(0.0f))) {
+- if (k1_below < FL2FXCONST_DBL(0.0f)) { /* 2-Ch Aliasing Detection */
+- degreeAlias[loBand] = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/;
+- if (k1_below2 >
+- FL2FXCONST_DBL(0.0f)) { /* 3-Ch Aliasing Detection */
+- degreeAlias[loBand - 1] = deg;
+- }
+- } else if (k1_below2 >
+- FL2FXCONST_DBL(0.0f)) { /* 3-Ch Aliasing Detection */
+- degreeAlias[loBand] = deg;
+- }
+- }
+- if (((loBand & 1) == 1) && (k1 > FL2FXCONST_DBL(0.0f))) {
+- if (k1_below > FL2FXCONST_DBL(0.0f)) { /* 2-CH Aliasing Detection */
+- degreeAlias[loBand] = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/;
+- if (k1_below2 <
+- FL2FXCONST_DBL(0.0f)) { /* 3-CH Aliasing Detection */
+- degreeAlias[loBand - 1] = deg;
+- }
+- } else if (k1_below2 <
+- FL2FXCONST_DBL(0.0f)) { /* 3-CH Aliasing Detection */
+- degreeAlias[loBand] = deg;
+- }
+- }
+- }
+- /* remember k1 values of the 2 QMF channels below the current channel */
+- k1_below2 = k1_below;
+- k1_below = k1;
+- }
+-
+- patch = 0;
+-
+- while (patch < pSettings->noOfPatches) { /* inner loop over every patch */
+-
+- int hiBand = loBand + patchParam[patch].targetBandOffs;
+-
+- if (loBand < patchParam[patch].sourceStartBand ||
+- loBand >= patchParam[patch].sourceStopBand
+- //|| hiBand >= hLppTrans->pSettings->noChannels
+- ) {
+- /* Lowband not in current patch - proceed */
+- patch++;
+- continue;
+- }
+-
+- FDK_ASSERT(hiBand < (64));
+-
+- /* bwIndex[patch] is already initialized with value from previous band
+- * inside this patch */
+- while (hiBand >= pSettings->bwBorders[bwIndex[patch]] &&
+- bwIndex[patch] < MAX_NUM_PATCHES - 1) {
+- bwIndex[patch]++;
+- }
+-
+- /*
+- Filter Step 2: add the left slope with the current filter to the buffer
+- pure source values are already in there
+- */
+- bw = FX_DBL2FX_SGL(bwVector[bwIndex[patch]]);
+-
+- a0r = FX_DBL2FX_SGL(
+- fMult(bw, alphar[0])); /* Apply current bandwidth expansion factor */
+-
+- if (!useLP) a0i = FX_DBL2FX_SGL(fMult(bw, alphai[0]));
+- bw = FX_DBL2FX_SGL(fPow2(bw));
+- a1r = FX_DBL2FX_SGL(fMult(bw, alphar[1]));
+- if (!useLP) a1i = FX_DBL2FX_SGL(fMult(bw, alphai[1]));
+-
+- /*
+- Filter Step 3: insert the middle part which won't be windowed
+- */
+- if (bw <= FL2FXCONST_SGL(0.0f)) {
+- if (!useLP) {
+- int descale =
+- fixMin(DFRACT_BITS - 1, (LPC_SCALE_FACTOR + dynamicScale));
+- for (i = startSample; i < stopSample; i++) {
+- FIXP_DBL accu1, accu2;
+- accu1 = lowBandReal[LPC_ORDER + i] >> descale;
+- accu2 = lowBandImag[LPC_ORDER + i] >> descale;
+- if (fPreWhitening) {
+- accu1 = scaleValueSaturate(
+- fMultDiv2(accu1, preWhiteningGains[loBand]),
+- preWhiteningGains_exp[loBand] + 1);
+- accu2 = scaleValueSaturate(
+- fMultDiv2(accu2, preWhiteningGains[loBand]),
+- preWhiteningGains_exp[loBand] + 1);
+- }
+- qmfBufferReal[i][hiBand] = accu1;
+- qmfBufferImag[i][hiBand] = accu2;
+- }
+- } else {
+- int descale =
+- fixMin(DFRACT_BITS - 1, (LPC_SCALE_FACTOR + dynamicScale));
+- for (i = startSample; i < stopSample; i++) {
+- qmfBufferReal[i][hiBand] = lowBandReal[LPC_ORDER + i] >> descale;
+- }
+- }
+- } else { /* bw <= 0 */
+-
+- if (!useLP) {
+- int descale =
+- fixMin(DFRACT_BITS - 1, (LPC_SCALE_FACTOR + dynamicScale));
+-#ifdef FUNCTION_LPPTRANSPOSER_func1
+- lppTransposer_func1(
+- lowBandReal + LPC_ORDER + startSample,
+- lowBandImag + LPC_ORDER + startSample,
+- qmfBufferReal + startSample, qmfBufferImag + startSample,
+- stopSample - startSample, (int)hiBand, dynamicScale, descale, a0r,
+- a0i, a1r, a1i, fPreWhitening, preWhiteningGains[loBand],
+- preWhiteningGains_exp[loBand] + 1);
+-#else
+- for (i = startSample; i < stopSample; i++) {
+- FIXP_DBL accu1, accu2;
+-
+- accu1 = (fMultDiv2(a0r, lowBandReal[LPC_ORDER + i - 1]) -
+- fMultDiv2(a0i, lowBandImag[LPC_ORDER + i - 1]) +
+- fMultDiv2(a1r, lowBandReal[LPC_ORDER + i - 2]) -
+- fMultDiv2(a1i, lowBandImag[LPC_ORDER + i - 2])) >>
+- dynamicScale;
+- accu2 = (fMultDiv2(a0i, lowBandReal[LPC_ORDER + i - 1]) +
+- fMultDiv2(a0r, lowBandImag[LPC_ORDER + i - 1]) +
+- fMultDiv2(a1i, lowBandReal[LPC_ORDER + i - 2]) +
+- fMultDiv2(a1r, lowBandImag[LPC_ORDER + i - 2])) >>
+- dynamicScale;
+-
+- accu1 = (lowBandReal[LPC_ORDER + i] >> descale) + (accu1 << 1);
+- accu2 = (lowBandImag[LPC_ORDER + i] >> descale) + (accu2 << 1);
+- if (fPreWhitening) {
+- accu1 = scaleValueSaturate(
+- fMultDiv2(accu1, preWhiteningGains[loBand]),
+- preWhiteningGains_exp[loBand] + 1);
+- accu2 = scaleValueSaturate(
+- fMultDiv2(accu2, preWhiteningGains[loBand]),
+- preWhiteningGains_exp[loBand] + 1);
+- }
+- qmfBufferReal[i][hiBand] = accu1;
+- qmfBufferImag[i][hiBand] = accu2;
+- }
+-#endif
+- } else {
+- FDK_ASSERT(dynamicScale >= 0);
+- calc_qmfBufferReal(
+- qmfBufferReal, &(lowBandReal[LPC_ORDER + startSample - 2]),
+- startSample, stopSample, hiBand, dynamicScale,
+- fMin(DFRACT_BITS - 1, (LPC_SCALE_FACTOR + dynamicScale)), a0r,
+- a1r);
+- }
+- } /* bw <= 0 */
+-
+- patch++;
+-
+- } /* inner loop over patches */
+-
+- /*
+- * store the unmodified filter coefficients if there is
+- * an overlapping envelope
+- *****************************************************************/
+-
+- } /* outer loop over bands (loBand) */
+-
+- if (useLP) {
+- for (loBand = pSettings->lbStartPatching;
+- loBand < pSettings->lbStopPatching; loBand++) {
+- patch = 0;
+- while (patch < pSettings->noOfPatches) {
+- UCHAR hiBand = loBand + patchParam[patch].targetBandOffs;
+-
+- if (loBand < patchParam[patch].sourceStartBand ||
+- loBand >= patchParam[patch].sourceStopBand ||
+- hiBand >= (64) /* Highband out of range (biterror) */
+- ) {
+- /* Lowband not in current patch or highband out of range (might be
+- * caused by biterrors)- proceed */
+- patch++;
+- continue;
+- }
+-
+- if (hiBand != patchParam[patch].targetStartBand)
+- degreeAlias[hiBand] = degreeAlias[loBand];
+-
+- patch++;
+- }
+- } /* end for loop */
+- }
+-
+- for (i = 0; i < nInvfBands; i++) {
+- hLppTrans->bwVectorOld[i] = bwVector[i];
+- }
+-
+- /*
+- set high band scale factor
+- */
+- sbrScaleFactor->hb_scale = comLowBandScale - (LPC_SCALE_FACTOR);
+-}
+-
+-void lppTransposerHBE(
+- HANDLE_SBR_LPP_TRANS hLppTrans, /*!< Handle of lpp transposer */
+- HANDLE_HBE_TRANSPOSER hQmfTransposer,
+- QMF_SCALE_FACTOR *sbrScaleFactor, /*!< Scaling factors */
+- FIXP_DBL **qmfBufferReal, /*!< Pointer to pointer to real part of subband
+- samples (source) */
+- FIXP_DBL **qmfBufferImag, /*!< Pointer to pointer to imaginary part of
+- subband samples (source) */
+- const int timeStep, /*!< Time step of envelope */
+- const int firstSlotOffs, /*!< Start position in time */
+- const int lastSlotOffs, /*!< Number of overlap-slots into next frame */
+- const int nInvfBands, /*!< Number of bands for inverse filtering */
+- INVF_MODE *sbr_invf_mode, /*!< Current inverse filtering modes */
+- INVF_MODE *sbr_invf_mode_prev /*!< Previous inverse filtering modes */
+-) {
+- INT bwIndex;
+- FIXP_DBL bwVector[MAX_NUM_PATCHES_HBE]; /*!< pole moving factors */
+-
+- int i;
+- int loBand, start, stop;
+- TRANSPOSER_SETTINGS *pSettings = hLppTrans->pSettings;
+- PATCH_PARAM *patchParam = pSettings->patchParam;
+-
+- FIXP_SGL alphar[LPC_ORDER], a0r, a1r;
+- FIXP_SGL alphai[LPC_ORDER], a0i = 0, a1i = 0;
+- FIXP_SGL bw = FL2FXCONST_SGL(0.0f);
+-
+- int autoCorrLength;
+-
+- ACORR_COEFS ac;
+- int startSample;
+- int stopSample;
+- int stopSampleClear;
+-
+- int comBandScale;
+- int ovLowBandShift;
+- int lowBandShift;
+- /* int ovHighBandShift;*/
+-
+- alphai[0] = FL2FXCONST_SGL(0.0f);
+- alphai[1] = FL2FXCONST_SGL(0.0f);
+-
+- startSample = firstSlotOffs * timeStep;
+- stopSample = pSettings->nCols + lastSlotOffs * timeStep;
+-
+- inverseFilteringLevelEmphasis(hLppTrans, nInvfBands, sbr_invf_mode,
+- sbr_invf_mode_prev, bwVector);
+-
+- stopSampleClear = stopSample;
+-
+- autoCorrLength = pSettings->nCols + pSettings->overlap;
+-
+- if (pSettings->noOfPatches > 0) {
+- /* Set upper subbands to zero:
+- This is required in case that the patches do not cover the complete
+- highband (because the last patch would be too short). Possible
+- optimization: Clearing bands up to usb would be sufficient here. */
+- int targetStopBand =
+- patchParam[pSettings->noOfPatches - 1].targetStartBand +
+- patchParam[pSettings->noOfPatches - 1].numBandsInPatch;
+-
+- int memSize = ((64) - targetStopBand) * sizeof(FIXP_DBL);
+-
+- for (i = startSample; i < stopSampleClear; i++) {
+- FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
+- FDKmemclear(&qmfBufferImag[i][targetStopBand], memSize);
+- }
+- }
+-#ifdef __ANDROID__
+- else {
+- // Safetynet logging
+- android_errorWriteLog(0x534e4554, "112160868");
+- }
+-#endif
+-
+- /*
+- Calc common low band scale factor
+- */
+- comBandScale = sbrScaleFactor->hb_scale;
+-
+- ovLowBandShift = sbrScaleFactor->hb_scale - comBandScale;
+- lowBandShift = sbrScaleFactor->hb_scale - comBandScale;
+- /* ovHighBandShift = firstSlotOffs == 0 ? ovLowBandShift:0;*/
+-
+- /* outer loop over bands to do analysis only once for each band */
+-
+- start = hQmfTransposer->startBand;
+- stop = hQmfTransposer->stopBand;
+-
+- for (loBand = start; loBand < stop; loBand++) {
+- bwIndex = 0;
+-
+- FIXP_DBL lowBandReal[(((1024) / (32) * (4) / 2) + (3 * (4))) + LPC_ORDER];
+- FIXP_DBL lowBandImag[(((1024) / (32) * (4) / 2) + (3 * (4))) + LPC_ORDER];
+-
+- int resetLPCCoeffs = 0;
+- int dynamicScale = DFRACT_BITS - 1 - LPC_SCALE_FACTOR;
+- int acDetScale = 0; /* scaling of autocorrelation determinant */
+-
+- for (i = 0; i < LPC_ORDER; i++) {
+- lowBandReal[i] = hLppTrans->lpcFilterStatesRealHBE[i][loBand];
+- lowBandImag[i] = hLppTrans->lpcFilterStatesImagHBE[i][loBand];
+- }
+-
+- for (; i < LPC_ORDER + firstSlotOffs * timeStep; i++) {
+- lowBandReal[i] = hLppTrans->lpcFilterStatesRealHBE[i][loBand];
+- lowBandImag[i] = hLppTrans->lpcFilterStatesImagHBE[i][loBand];
+- }
+-
+- /*
+- Take old slope length qmf slot source values out of (overlap)qmf buffer
+- */
+- for (i = firstSlotOffs * timeStep;
+- i < pSettings->nCols + pSettings->overlap; i++) {
+- lowBandReal[i + LPC_ORDER] = qmfBufferReal[i][loBand];
+- lowBandImag[i + LPC_ORDER] = qmfBufferImag[i][loBand];
+- }
+-
+- /* store unmodified values to buffer */
+- for (i = 0; i < LPC_ORDER + pSettings->overlap; i++) {
+- hLppTrans->lpcFilterStatesRealHBE[i][loBand] =
+- qmfBufferReal[pSettings->nCols - LPC_ORDER + i][loBand];
+- hLppTrans->lpcFilterStatesImagHBE[i][loBand] =
+- qmfBufferImag[pSettings->nCols - LPC_ORDER + i][loBand];
+- }
+-
+- /*
+- Determine dynamic scaling value.
+- */
+- dynamicScale =
+- fixMin(dynamicScale,
+- getScalefactor(lowBandReal, LPC_ORDER + pSettings->overlap) +
+- ovLowBandShift);
+- dynamicScale =
+- fixMin(dynamicScale,
+- getScalefactor(&lowBandReal[LPC_ORDER + pSettings->overlap],
+- pSettings->nCols) +
+- lowBandShift);
+- dynamicScale =
+- fixMin(dynamicScale,
+- getScalefactor(lowBandImag, LPC_ORDER + pSettings->overlap) +
+- ovLowBandShift);
+- dynamicScale =
+- fixMin(dynamicScale,
+- getScalefactor(&lowBandImag[LPC_ORDER + pSettings->overlap],
+- pSettings->nCols) +
+- lowBandShift);
+-
+- dynamicScale = fixMax(
+- 0, dynamicScale - 1); /* one additional bit headroom to prevent -1.0 */
+-
+- /*
+- Scale temporal QMF buffer.
+- */
+- scaleValues(&lowBandReal[0], LPC_ORDER + pSettings->overlap,
+- dynamicScale - ovLowBandShift);
+- scaleValues(&lowBandReal[LPC_ORDER + pSettings->overlap], pSettings->nCols,
+- dynamicScale - lowBandShift);
+- scaleValues(&lowBandImag[0], LPC_ORDER + pSettings->overlap,
+- dynamicScale - ovLowBandShift);
+- scaleValues(&lowBandImag[LPC_ORDER + pSettings->overlap], pSettings->nCols,
+- dynamicScale - lowBandShift);
+-
+- acDetScale += autoCorr2nd_cplx(&ac, lowBandReal + LPC_ORDER,
+- lowBandImag + LPC_ORDER, autoCorrLength);
+-
+- /* Examine dynamic of determinant in autocorrelation. */
+- acDetScale += 2 * (comBandScale + dynamicScale);
+- acDetScale *= 2; /* two times reflection coefficent scaling */
+- acDetScale += ac.det_scale; /* ac scaling of determinant */
+-
+- /* In case of determinant < 10^-38, resetLPCCoeffs=1 has to be enforced. */
+- if (acDetScale > 126) {
+- resetLPCCoeffs = 1;
+- }
+-
+- alphar[1] = FL2FXCONST_SGL(0.0f);
+- alphai[1] = FL2FXCONST_SGL(0.0f);
+-
+- if (ac.det != FL2FXCONST_DBL(0.0f)) {
+- FIXP_DBL tmp, absTmp, absDet;
+-
+- absDet = fixp_abs(ac.det);
+-
+- tmp = (fMultDiv2(ac.r01r, ac.r12r) >> (LPC_SCALE_FACTOR - 1)) -
+- ((fMultDiv2(ac.r01i, ac.r12i) + fMultDiv2(ac.r02r, ac.r11r)) >>
+- (LPC_SCALE_FACTOR - 1));
+- absTmp = fixp_abs(tmp);
+-
+- /*
+- Quick check: is first filter coeff >= 1(4)
+- */
+- {
+- INT scale;
+- FIXP_DBL result = fDivNorm(absTmp, absDet, &scale);
+- scale = scale + ac.det_scale;
+-
+- if ((scale > 0) && (result >= (FIXP_DBL)MAXVAL_DBL >> scale)) {
+- resetLPCCoeffs = 1;
+- } else {
+- alphar[1] = FX_DBL2FX_SGL(scaleValue(result, scale));
+- if ((tmp < FL2FX_DBL(0.0f)) ^ (ac.det < FL2FX_DBL(0.0f))) {
+- alphar[1] = -alphar[1];
+- }
+- }
+- }
+-
+- tmp = (fMultDiv2(ac.r01i, ac.r12r) >> (LPC_SCALE_FACTOR - 1)) +
+- ((fMultDiv2(ac.r01r, ac.r12i) -
+- (FIXP_DBL)fMultDiv2(ac.r02i, ac.r11r)) >>
+- (LPC_SCALE_FACTOR - 1));
+-
+- absTmp = fixp_abs(tmp);
+-
+- /*
+- Quick check: is second filter coeff >= 1(4)
+- */
+- {
+- INT scale;
+- FIXP_DBL result = fDivNorm(absTmp, absDet, &scale);
+- scale = scale + ac.det_scale;
+-
+- if ((scale > 0) &&
+- (result >= /*FL2FXCONST_DBL(1.f)*/ (FIXP_DBL)MAXVAL_DBL >> scale)) {
+- resetLPCCoeffs = 1;
+- } else {
+- alphai[1] = FX_DBL2FX_SGL(scaleValue(result, scale));
+- if ((tmp < FL2FX_DBL(0.0f)) ^ (ac.det < FL2FX_DBL(0.0f))) {
+- alphai[1] = -alphai[1];
+- }
+- }
+- }
+- }
+-
+- alphar[0] = FL2FXCONST_SGL(0.0f);
+- alphai[0] = FL2FXCONST_SGL(0.0f);
+-
+- if (ac.r11r != FL2FXCONST_DBL(0.0f)) {
+- /* ac.r11r is always >=0 */
+- FIXP_DBL tmp, absTmp;
+-
+- tmp = (ac.r01r >> (LPC_SCALE_FACTOR + 1)) +
+- (fMultDiv2(alphar[1], ac.r12r) + fMultDiv2(alphai[1], ac.r12i));
+-
+- absTmp = fixp_abs(tmp);
+-
+- /*
+- Quick check: is first filter coeff >= 1(4)
+- */
+-
+- if (absTmp >= (ac.r11r >> 1)) {
+- resetLPCCoeffs = 1;
+- } else {
+- INT scale;
+- FIXP_DBL result = fDivNorm(absTmp, fixp_abs(ac.r11r), &scale);
+- alphar[0] = FX_DBL2FX_SGL(scaleValue(result, scale + 1));
+-
+- if ((tmp > FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f)))
+- alphar[0] = -alphar[0];
+- }
+-
+- tmp = (ac.r01i >> (LPC_SCALE_FACTOR + 1)) +
+- (fMultDiv2(alphai[1], ac.r12r) - fMultDiv2(alphar[1], ac.r12i));
+-
+- absTmp = fixp_abs(tmp);
+-
+- /*
+- Quick check: is second filter coeff >= 1(4)
+- */
+- if (absTmp >= (ac.r11r >> 1)) {
+- resetLPCCoeffs = 1;
+- } else {
+- INT scale;
+- FIXP_DBL result = fDivNorm(absTmp, fixp_abs(ac.r11r), &scale);
+- alphai[0] = FX_DBL2FX_SGL(scaleValue(result, scale + 1));
+- if ((tmp > FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f))) {
+- alphai[0] = -alphai[0];
+- }
+- }
+- }
+-
+- /* Now check the quadratic criteria */
+- if ((fMultDiv2(alphar[0], alphar[0]) + fMultDiv2(alphai[0], alphai[0])) >=
+- FL2FXCONST_DBL(0.5f)) {
+- resetLPCCoeffs = 1;
+- }
+- if ((fMultDiv2(alphar[1], alphar[1]) + fMultDiv2(alphai[1], alphai[1])) >=
+- FL2FXCONST_DBL(0.5f)) {
+- resetLPCCoeffs = 1;
+- }
+-
+- if (resetLPCCoeffs) {
+- alphar[0] = FL2FXCONST_SGL(0.0f);
+- alphar[1] = FL2FXCONST_SGL(0.0f);
+- alphai[0] = FL2FXCONST_SGL(0.0f);
+- alphai[1] = FL2FXCONST_SGL(0.0f);
+- }
+-
+- while (bwIndex < MAX_NUM_PATCHES - 1 &&
+- loBand >= pSettings->bwBorders[bwIndex]) {
+- bwIndex++;
+- }
+-
+- /*
+- Filter Step 2: add the left slope with the current filter to the buffer
+- pure source values are already in there
+- */
+- bw = FX_DBL2FX_SGL(bwVector[bwIndex]);
+-
+- a0r = FX_DBL2FX_SGL(
+- fMult(bw, alphar[0])); /* Apply current bandwidth expansion factor */
+- a0i = FX_DBL2FX_SGL(fMult(bw, alphai[0]));
+- bw = FX_DBL2FX_SGL(fPow2(bw));
+- a1r = FX_DBL2FX_SGL(fMult(bw, alphar[1]));
+- a1i = FX_DBL2FX_SGL(fMult(bw, alphai[1]));
+-
+- /*
+- Filter Step 3: insert the middle part which won't be windowed
+- */
+- if (bw <= FL2FXCONST_SGL(0.0f)) {
+- int descale = fixMin(DFRACT_BITS - 1, (LPC_SCALE_FACTOR + dynamicScale));
+- for (i = startSample; i < stopSample; i++) {
+- qmfBufferReal[i][loBand] = lowBandReal[LPC_ORDER + i] >> descale;
+- qmfBufferImag[i][loBand] = lowBandImag[LPC_ORDER + i] >> descale;
+- }
+- } else { /* bw <= 0 */
+-
+- int descale = fixMin(DFRACT_BITS - 1, (LPC_SCALE_FACTOR + dynamicScale));
+-
+- for (i = startSample; i < stopSample; i++) {
+- FIXP_DBL accu1, accu2;
+-
+- accu1 = (fMultDiv2(a0r, lowBandReal[LPC_ORDER + i - 1]) -
+- fMultDiv2(a0i, lowBandImag[LPC_ORDER + i - 1]) +
+- fMultDiv2(a1r, lowBandReal[LPC_ORDER + i - 2]) -
+- fMultDiv2(a1i, lowBandImag[LPC_ORDER + i - 2])) >>
+- dynamicScale;
+- accu2 = (fMultDiv2(a0i, lowBandReal[LPC_ORDER + i - 1]) +
+- fMultDiv2(a0r, lowBandImag[LPC_ORDER + i - 1]) +
+- fMultDiv2(a1i, lowBandReal[LPC_ORDER + i - 2]) +
+- fMultDiv2(a1r, lowBandImag[LPC_ORDER + i - 2])) >>
+- dynamicScale;
+-
+- qmfBufferReal[i][loBand] =
+- (lowBandReal[LPC_ORDER + i] >> descale) + (accu1 << 1);
+- qmfBufferImag[i][loBand] =
+- (lowBandImag[LPC_ORDER + i] >> descale) + (accu2 << 1);
+- }
+- } /* bw <= 0 */
+-
+- /*
+- * store the unmodified filter coefficients if there is
+- * an overlapping envelope
+- *****************************************************************/
+-
+- } /* outer loop over bands (loBand) */
+-
+- for (i = 0; i < nInvfBands; i++) {
+- hLppTrans->bwVectorOld[i] = bwVector[i];
+- }
+-
+- /*
+- set high band scale factor
+- */
+- sbrScaleFactor->hb_scale = comBandScale - (LPC_SCALE_FACTOR);
+-}
+-
+-/*!
+- *
+- * \brief Initialize one low power transposer instance
+- *
+- *
+- */
+-SBR_ERROR
+-createLppTransposer(
+- HANDLE_SBR_LPP_TRANS hs, /*!< Handle of low power transposer */
+- TRANSPOSER_SETTINGS *pSettings, /*!< Pointer to settings */
+- const int highBandStartSb, /*!< ? */
+- UCHAR *v_k_master, /*!< Master table */
+- const int numMaster, /*!< Valid entries in master table */
+- const int usb, /*!< Highband area stop subband */
+- const int timeSlots, /*!< Number of time slots */
+- const int nCols, /*!< Number of colums (codec qmf bank) */
+- UCHAR *noiseBandTable, /*!< Mapping of SBR noise bands to QMF bands */
+- const int noNoiseBands, /*!< Number of noise bands */
+- UINT fs, /*!< Sample Frequency */
+- const int chan, /*!< Channel number */
+- const int overlap) {
+- /* FB inverse filtering settings */
+- hs->pSettings = pSettings;
+-
+- pSettings->nCols = nCols;
+- pSettings->overlap = overlap;
+-
+- switch (timeSlots) {
+- case 15:
+- case 16:
+- break;
+-
+- default:
+- return SBRDEC_UNSUPPORTED_CONFIG; /* Unimplemented */
+- }
+-
+- if (chan == 0) {
+- /* Init common data only once */
+- hs->pSettings->nCols = nCols;
+-
+- return resetLppTransposer(hs, highBandStartSb, v_k_master, numMaster,
+- noiseBandTable, noNoiseBands, usb, fs);
+- }
+- return SBRDEC_OK;
+-}
+-
+-static int findClosestEntry(UCHAR goalSb, UCHAR *v_k_master, UCHAR numMaster,
+- UCHAR direction) {
+- int index;
+-
+- if (goalSb <= v_k_master[0]) return v_k_master[0];
+-
+- if (goalSb >= v_k_master[numMaster]) return v_k_master[numMaster];
+-
+- if (direction) {
+- index = 0;
+- while (v_k_master[index] < goalSb) {
+- index++;
+- }
+- } else {
+- index = numMaster;
+- while (v_k_master[index] > goalSb) {
+- index--;
+- }
+- }
+-
+- return v_k_master[index];
+-}
+-
+-/*!
+- *
+- * \brief Reset memory for one lpp transposer instance
+- *
+- * \return SBRDEC_OK on success, SBRDEC_UNSUPPORTED_CONFIG on error
+- */
+-SBR_ERROR
+-resetLppTransposer(
+- HANDLE_SBR_LPP_TRANS hLppTrans, /*!< Handle of lpp transposer */
+- UCHAR highBandStartSb, /*!< High band area: start subband */
+- UCHAR *v_k_master, /*!< Master table */
+- UCHAR numMaster, /*!< Valid entries in master table */
+- UCHAR *noiseBandTable, /*!< Mapping of SBR noise bands to QMF bands */
+- UCHAR noNoiseBands, /*!< Number of noise bands */
+- UCHAR usb, /*!< High band area: stop subband */
+- UINT fs /*!< SBR output sampling frequency */
+-) {
+- TRANSPOSER_SETTINGS *pSettings = hLppTrans->pSettings;
+- PATCH_PARAM *patchParam = pSettings->patchParam;
+-
+- int i, patch;
+- int targetStopBand;
+- int sourceStartBand;
+- int patchDistance;
+- int numBandsInPatch;
+-
+- int lsb = v_k_master[0]; /* Start subband expressed in "non-critical" sampling
+- terms*/
+- int xoverOffset = highBandStartSb -
+- lsb; /* Calculate distance in QMF bands between k0 and kx */
+- int startFreqHz;
+-
+- int desiredBorder;
+-
+- usb = fixMin(usb, v_k_master[numMaster]); /* Avoid endless loops (compare with
+- float code). */
+-
+- /*
+- * Plausibility check
+- */
+-
+- if (pSettings->nCols == 64) {
+- if (lsb < 4) {
+- /* 4:1 SBR Requirement k0 >= 4 missed! */
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+- } else if (lsb - SHIFT_START_SB < 4) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- /*
+- * Initialize the patching parameter
+- */
+- /* ISO/IEC 14496-3 (Figure 4.48): goalSb = round( 2.048e6 / fs ) */
+- desiredBorder = (((2048000 * 2) / fs) + 1) >> 1;
+-
+- desiredBorder = findClosestEntry(desiredBorder, v_k_master, numMaster,
+- 1); /* Adapt region to master-table */
+-
+- /* First patch */
+- sourceStartBand = SHIFT_START_SB + xoverOffset;
+- targetStopBand = lsb + xoverOffset; /* upperBand */
+-
+- /* Even (odd) numbered channel must be patched to even (odd) numbered channel
+- */
+- patch = 0;
+- while (targetStopBand < usb) {
+- /* Too many patches?
+- Allow MAX_NUM_PATCHES+1 patches here.
+- we need to check later again, since patch might be the highest patch
+- AND contain less than 3 bands => actual number of patches will be reduced
+- by 1.
+- */
+- if (patch > MAX_NUM_PATCHES) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- patchParam[patch].guardStartBand = targetStopBand;
+- patchParam[patch].targetStartBand = targetStopBand;
+-
+- numBandsInPatch =
+- desiredBorder - targetStopBand; /* Get the desired range of the patch */
+-
+- if (numBandsInPatch >= lsb - sourceStartBand) {
+- /* Desired number bands are not available -> patch whole source range */
+- patchDistance =
+- targetStopBand - sourceStartBand; /* Get the targetOffset */
+- patchDistance =
+- patchDistance & ~1; /* Rounding off odd numbers and make all even */
+- numBandsInPatch =
+- lsb - (targetStopBand -
+- patchDistance); /* Update number of bands to be patched */
+- numBandsInPatch = findClosestEntry(targetStopBand + numBandsInPatch,
+- v_k_master, numMaster, 0) -
+- targetStopBand; /* Adapt region to master-table */
+- }
+-
+- if (pSettings->nCols == 64) {
+- if (numBandsInPatch == 0 && sourceStartBand == SHIFT_START_SB) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+- }
+-
+- /* Desired number bands are available -> get the minimal even patching
+- * distance */
+- patchDistance =
+- numBandsInPatch + targetStopBand - lsb; /* Get minimal distance */
+- patchDistance = (patchDistance + 1) &
+- ~1; /* Rounding up odd numbers and make all even */
+-
+- if (numBandsInPatch > 0) {
+- patchParam[patch].sourceStartBand = targetStopBand - patchDistance;
+- patchParam[patch].targetBandOffs = patchDistance;
+- patchParam[patch].numBandsInPatch = numBandsInPatch;
+- patchParam[patch].sourceStopBand =
+- patchParam[patch].sourceStartBand + numBandsInPatch;
+-
+- targetStopBand += patchParam[patch].numBandsInPatch;
+- patch++;
+- }
+-
+- /* All patches but first */
+- sourceStartBand = SHIFT_START_SB;
+-
+- /* Check if we are close to desiredBorder */
+- if (desiredBorder - targetStopBand < 3) /* MPEG doc */
+- {
+- desiredBorder = usb;
+- }
+- }
+-
+- patch--;
+-
+- /* If highest patch contains less than three subband: skip it */
+- if ((patch > 0) && (patchParam[patch].numBandsInPatch < 3)) {
+- patch--;
+- targetStopBand =
+- patchParam[patch].targetStartBand + patchParam[patch].numBandsInPatch;
+- }
+-
+- /* now check if we don't have one too many */
+- if (patch >= MAX_NUM_PATCHES) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- pSettings->noOfPatches = patch + 1;
+-
+- /* Check lowest and highest source subband */
+- pSettings->lbStartPatching = targetStopBand;
+- pSettings->lbStopPatching = 0;
+- for (patch = 0; patch < pSettings->noOfPatches; patch++) {
+- pSettings->lbStartPatching =
+- fixMin(pSettings->lbStartPatching, patchParam[patch].sourceStartBand);
+- pSettings->lbStopPatching =
+- fixMax(pSettings->lbStopPatching, patchParam[patch].sourceStopBand);
+- }
+-
+- for (i = 0; i < noNoiseBands; i++) {
+- pSettings->bwBorders[i] = noiseBandTable[i + 1];
+- }
+- for (; i < MAX_NUM_NOISE_VALUES; i++) {
+- pSettings->bwBorders[i] = 255;
+- }
+-
+- /*
+- * Choose whitening factors
+- */
+-
+- startFreqHz =
+- ((lsb + xoverOffset) * fs) >> 7; /* Shift does a division by 2*(64) */
+-
+- for (i = 1; i < NUM_WHFACTOR_TABLE_ENTRIES; i++) {
+- if (startFreqHz < FDK_sbrDecoder_sbr_whFactorsIndex[i]) break;
+- }
+- i--;
+-
+- pSettings->whFactors.off = FDK_sbrDecoder_sbr_whFactorsTable[i][0];
+- pSettings->whFactors.transitionLevel =
+- FDK_sbrDecoder_sbr_whFactorsTable[i][1];
+- pSettings->whFactors.lowLevel = FDK_sbrDecoder_sbr_whFactorsTable[i][2];
+- pSettings->whFactors.midLevel = FDK_sbrDecoder_sbr_whFactorsTable[i][3];
+- pSettings->whFactors.highLevel = FDK_sbrDecoder_sbr_whFactorsTable[i][4];
+-
+- return SBRDEC_OK;
+-}
+diff --git a/libSBRdec/src/lpp_tran.h b/libSBRdec/src/lpp_tran.h
+deleted file mode 100644
+index 51b4395..0000000
+--- a/libSBRdec/src/lpp_tran.h
++++ /dev/null
+@@ -1,275 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Low Power Profile Transposer
+-*/
+-
+-#ifndef LPP_TRAN_H
+-#define LPP_TRAN_H
+-
+-#include "sbrdecoder.h"
+-#include "hbe.h"
+-#include "qmf.h"
+-
+-/*
+- Common
+-*/
+-#define QMF_OUT_SCALE 8
+-
+-/*
+- Frequency scales
+-*/
+-
+-/*
+- Env-Adjust
+-*/
+-#define MAX_NOISE_ENVELOPES 2
+-#define MAX_NOISE_COEFFS 5
+-#define MAX_NUM_NOISE_VALUES (MAX_NOISE_ENVELOPES * MAX_NOISE_COEFFS)
+-#define MAX_NUM_LIMITERS 12
+-
+-/* Set MAX_ENVELOPES to the largest value of all supported BSFORMATs
+- by overriding MAX_ENVELOPES in the correct order: */
+-#define MAX_ENVELOPES_LEGACY 5
+-#define MAX_ENVELOPES_USAC 8
+-#define MAX_ENVELOPES MAX_ENVELOPES_USAC
+-
+-#define MAX_FREQ_COEFFS_DUAL_RATE 48
+-#define MAX_FREQ_COEFFS_QUAD_RATE 56
+-#define MAX_FREQ_COEFFS MAX_FREQ_COEFFS_QUAD_RATE
+-
+-#define MAX_FREQ_COEFFS_FS44100 35
+-#define MAX_FREQ_COEFFS_FS48000 32
+-
+-#define MAX_NUM_ENVELOPE_VALUES (MAX_ENVELOPES * MAX_FREQ_COEFFS)
+-
+-#define MAX_GAIN_EXP 34
+-/* Maximum gain will be sqrt(0.5 * 2^MAX_GAIN_EXP)
+- example: 34=99dB */
+-#define MAX_GAIN_CONCEAL_EXP 1
+-/* Maximum gain will be sqrt(0.5 * 2^MAX_GAIN_CONCEAL_EXP) in concealment case
+- * (0dB) */
+-
+-/*
+- LPP Transposer
+-*/
+-#define LPC_ORDER 2
+-
+-#define MAX_INVF_BANDS MAX_NOISE_COEFFS
+-
+-#define MAX_NUM_PATCHES 6
+-#define SHIFT_START_SB 1 /*!< lowest subband of source range */
+-
+-typedef enum {
+- INVF_OFF = 0,
+- INVF_LOW_LEVEL,
+- INVF_MID_LEVEL,
+- INVF_HIGH_LEVEL,
+- INVF_SWITCHED /* not a real choice but used here to control behaviour */
+-} INVF_MODE;
+-
+-/** parameter set for one single patch */
+-typedef struct {
+- UCHAR sourceStartBand; /*!< first band in lowbands where to take the samples
+- from */
+- UCHAR
+- sourceStopBand; /*!< first band in lowbands which is not included in the
+- patch anymore */
+- UCHAR guardStartBand; /*!< first band in highbands to be filled with zeros in
+- order to reduce interferences between patches */
+- UCHAR
+- targetStartBand; /*!< first band in highbands to be filled with whitened
+- lowband signal */
+- UCHAR targetBandOffs; /*!< difference between 'startTargetBand' and
+- 'startSourceBand' */
+- UCHAR numBandsInPatch; /*!< number of consecutive bands in this one patch */
+-} PATCH_PARAM;
+-
+-/** whitening factors for different levels of whitening
+- need to be initialized corresponding to crossover frequency */
+-typedef struct {
+- FIXP_DBL off; /*!< bw factor for signal OFF */
+- FIXP_DBL transitionLevel;
+- FIXP_DBL lowLevel; /*!< bw factor for signal LOW_LEVEL */
+- FIXP_DBL midLevel; /*!< bw factor for signal MID_LEVEL */
+- FIXP_DBL highLevel; /*!< bw factor for signal HIGH_LEVEL */
+-} WHITENING_FACTORS;
+-
+-/*! The transposer settings are calculated on a header reset and are shared by
+- * both channels. */
+-typedef struct {
+- UCHAR nCols; /*!< number subsamples of a codec frame */
+- UCHAR noOfPatches; /*!< number of patches */
+- UCHAR lbStartPatching; /*!< first band of lowbands that will be patched */
+- UCHAR lbStopPatching; /*!< first band that won't be patched anymore*/
+- UCHAR bwBorders[MAX_NUM_NOISE_VALUES]; /*!< spectral bands with different
+- inverse filtering levels */
+-
+- PATCH_PARAM
+- patchParam[MAX_NUM_PATCHES]; /*!< new parameter set for patching */
+- WHITENING_FACTORS
+- whFactors; /*!< the pole moving factors for certain
+- whitening levels as indicated in the bitstream
+- depending on the crossover frequency */
+- UCHAR overlap; /*!< Overlap size */
+-} TRANSPOSER_SETTINGS;
+-
+-typedef struct {
+- TRANSPOSER_SETTINGS *pSettings; /*!< Common settings for both channels */
+- FIXP_DBL
+- bwVectorOld[MAX_NUM_PATCHES]; /*!< pole moving factors of past frame */
+- FIXP_DBL lpcFilterStatesRealLegSBR[LPC_ORDER + (3 * (4))][(
+- 32)]; /*!< pointer array to save filter states */
+-
+- FIXP_DBL lpcFilterStatesImagLegSBR[LPC_ORDER + (3 * (4))][(
+- 32)]; /*!< pointer array to save filter states */
+-
+- FIXP_DBL lpcFilterStatesRealHBE[LPC_ORDER + (3 * (4))][(
+- 64)]; /*!< pointer array to save filter states */
+- FIXP_DBL lpcFilterStatesImagHBE[LPC_ORDER + (3 * (4))][(
+- 64)]; /*!< pointer array to save filter states */
+-} SBR_LPP_TRANS;
+-
+-typedef SBR_LPP_TRANS *HANDLE_SBR_LPP_TRANS;
+-
+-void lppTransposer(HANDLE_SBR_LPP_TRANS hLppTrans,
+- QMF_SCALE_FACTOR *sbrScaleFactor, FIXP_DBL **qmfBufferReal,
+-
+- FIXP_DBL *degreeAlias, FIXP_DBL **qmfBufferImag,
+- const int useLP, const int fPreWhitening,
+- const int v_k_master0, const int timeStep,
+- const int firstSlotOffset, const int lastSlotOffset,
+- const int nInvfBands, INVF_MODE *sbr_invf_mode,
+- INVF_MODE *sbr_invf_mode_prev);
+-
+-void lppTransposerHBE(
+- HANDLE_SBR_LPP_TRANS hLppTrans, /*!< Handle of lpp transposer */
+- HANDLE_HBE_TRANSPOSER hQmfTransposer,
+- QMF_SCALE_FACTOR *sbrScaleFactor, /*!< Scaling factors */
+- FIXP_DBL **qmfBufferReal, /*!< Pointer to pointer to real part of subband
+- samples (source) */
+- FIXP_DBL **qmfBufferImag, /*!< Pointer to pointer to imaginary part of
+- subband samples (source) */
+- const int timeStep, /*!< Time step of envelope */
+- const int firstSlotOffs, /*!< Start position in time */
+- const int lastSlotOffs, /*!< Number of overlap-slots into next frame */
+- const int nInvfBands, /*!< Number of bands for inverse filtering */
+- INVF_MODE *sbr_invf_mode, /*!< Current inverse filtering modes */
+- INVF_MODE *sbr_invf_mode_prev /*!< Previous inverse filtering modes */
+-);
+-
+-SBR_ERROR
+-createLppTransposer(HANDLE_SBR_LPP_TRANS hLppTrans,
+- TRANSPOSER_SETTINGS *pSettings, const int highBandStartSb,
+- UCHAR *v_k_master, const int numMaster, const int usb,
+- const int timeSlots, const int nCols, UCHAR *noiseBandTable,
+- const int noNoiseBands, UINT fs, const int chan,
+- const int overlap);
+-
+-SBR_ERROR
+-resetLppTransposer(HANDLE_SBR_LPP_TRANS hLppTrans, UCHAR highBandStartSb,
+- UCHAR *v_k_master, UCHAR numMaster, UCHAR *noiseBandTable,
+- UCHAR noNoiseBands, UCHAR usb, UINT fs);
+-
+-#endif /* LPP_TRAN_H */
+diff --git a/libSBRdec/src/psbitdec.cpp b/libSBRdec/src/psbitdec.cpp
+deleted file mode 100644
+index 82bb65b..0000000
+--- a/libSBRdec/src/psbitdec.cpp
++++ /dev/null
+@@ -1,594 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "psbitdec.h"
+-
+-#include "sbr_rom.h"
+-#include "huff_dec.h"
+-
+-/* PS dec privat functions */
+-SBR_ERROR ResetPsDec(HANDLE_PS_DEC h_ps_d);
+-
+-/***************************************************************************/
+-/*!
+- \brief huffman decoding by codebook table
+-
+- \return index of huffman codebook table
+-
+-****************************************************************************/
+-static SCHAR decode_huff_cw(
+- Huffman h, /*!< pointer to huffman codebook table */
+- HANDLE_FDK_BITSTREAM hBitBuf, /*!< Handle to Bitbuffer */
+- int *length) /*!< length of huffman codeword (or NULL) */
+-{
+- UCHAR bit = 0;
+- SCHAR index = 0;
+- UCHAR bitCount = 0;
+-
+- while (index >= 0) {
+- bit = FDKreadBits(hBitBuf, 1);
+- bitCount++;
+- index = h[index][bit];
+- }
+- if (length) {
+- *length = bitCount;
+- }
+- return (index + 64); /* Add offset */
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief helper function - limiting of value to min/max values
+-
+- \return limited value
+-
+-****************************************************************************/
+-
+-static SCHAR limitMinMax(SCHAR i, SCHAR min, SCHAR max) {
+- if (i < min)
+- return min;
+- else if (i > max)
+- return max;
+- else
+- return i;
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief Decodes delta values in-place and updates
+- data buffers according to quantization classes.
+-
+- When delta coded in frequency the first element is deltacode from zero.
+- aIndex buffer is decoded from delta values to actual values.
+-
+- \return none
+-
+-****************************************************************************/
+-static void deltaDecodeArray(
+- SCHAR enable, SCHAR *aIndex, /*!< ICC/IID parameters */
+- SCHAR *aPrevFrameIndex, /*!< ICC/IID parameters of previous frame */
+- SCHAR DtDf, UCHAR nrElements, /*!< as conveyed in bitstream */
+- /*!< output array size: nrElements*stride */
+- UCHAR stride, /*!< 1=dflt, 2=half freq. resolution */
+- SCHAR minIdx, SCHAR maxIdx) {
+- int i;
+-
+- /* Delta decode */
+- if (enable == 1) {
+- if (DtDf == 0) { /* Delta coded in freq */
+- aIndex[0] = 0 + aIndex[0];
+- aIndex[0] = limitMinMax(aIndex[0], minIdx, maxIdx);
+- for (i = 1; i < nrElements; i++) {
+- aIndex[i] = aIndex[i - 1] + aIndex[i];
+- aIndex[i] = limitMinMax(aIndex[i], minIdx, maxIdx);
+- }
+- } else { /* Delta time */
+- for (i = 0; i < nrElements; i++) {
+- aIndex[i] = aPrevFrameIndex[i * stride] + aIndex[i];
+- aIndex[i] = limitMinMax(aIndex[i], minIdx, maxIdx);
+- }
+- }
+- } else { /* No data is sent, set index to zero */
+- for (i = 0; i < nrElements; i++) {
+- aIndex[i] = 0;
+- }
+- }
+- if (stride == 2) {
+- for (i = nrElements * stride - 1; i > 0; i--) {
+- aIndex[i] = aIndex[i >> 1];
+- }
+- }
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief Mapping of ICC/IID parameters to 20 stereo bands
+-
+- \return none
+-
+-****************************************************************************/
+-static void map34IndexTo20(SCHAR *aIndex, /*!< decoded ICC/IID parameters */
+- UCHAR noBins) /*!< number of stereo bands */
+-{
+- aIndex[0] = (2 * aIndex[0] + aIndex[1]) / 3;
+- aIndex[1] = (aIndex[1] + 2 * aIndex[2]) / 3;
+- aIndex[2] = (2 * aIndex[3] + aIndex[4]) / 3;
+- aIndex[3] = (aIndex[4] + 2 * aIndex[5]) / 3;
+- aIndex[4] = (aIndex[6] + aIndex[7]) / 2;
+- aIndex[5] = (aIndex[8] + aIndex[9]) / 2;
+- aIndex[6] = aIndex[10];
+- aIndex[7] = aIndex[11];
+- aIndex[8] = (aIndex[12] + aIndex[13]) / 2;
+- aIndex[9] = (aIndex[14] + aIndex[15]) / 2;
+- aIndex[10] = aIndex[16];
+- /* For IPD/OPD it stops here */
+-
+- if (noBins == NO_HI_RES_BINS) {
+- aIndex[11] = aIndex[17];
+- aIndex[12] = aIndex[18];
+- aIndex[13] = aIndex[19];
+- aIndex[14] = (aIndex[20] + aIndex[21]) / 2;
+- aIndex[15] = (aIndex[22] + aIndex[23]) / 2;
+- aIndex[16] = (aIndex[24] + aIndex[25]) / 2;
+- aIndex[17] = (aIndex[26] + aIndex[27]) / 2;
+- aIndex[18] = (aIndex[28] + aIndex[29] + aIndex[30] + aIndex[31]) / 4;
+- aIndex[19] = (aIndex[32] + aIndex[33]) / 2;
+- }
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief Decodes delta coded IID, ICC, IPD and OPD indices
+-
+- \return PS processing flag. If set to 1
+-
+-****************************************************************************/
+-int DecodePs(struct PS_DEC *h_ps_d, /*!< PS handle */
+- const UCHAR frameError, /*!< Flag telling that frame had errors */
+- PS_DEC_COEFFICIENTS *pScratch) {
+- MPEG_PS_BS_DATA *pBsData;
+- UCHAR gr, env;
+- int bPsHeaderValid, bPsDataAvail;
+-
+- /* Assign Scratch */
+- h_ps_d->specificTo.mpeg.pCoef = pScratch;
+-
+- /* Shortcuts to avoid deferencing and keep the code readable */
+- pBsData = &h_ps_d->bsData[h_ps_d->processSlot].mpeg;
+- bPsHeaderValid = pBsData->bPsHeaderValid;
+- bPsDataAvail =
+- (h_ps_d->bPsDataAvail[h_ps_d->processSlot] == ppt_mpeg) ? 1 : 0;
+-
+- /***************************************************************************************
+- * Decide whether to process or to conceal PS data or not. */
+-
+- if ((h_ps_d->psDecodedPrv && !frameError && !bPsDataAvail) ||
+- (!h_ps_d->psDecodedPrv &&
+- (frameError || !bPsDataAvail || !bPsHeaderValid))) {
+- /* Don't apply PS processing.
+- * Declare current PS header and bitstream data invalid. */
+- pBsData->bPsHeaderValid = 0;
+- h_ps_d->bPsDataAvail[h_ps_d->processSlot] = ppt_none;
+- return (0);
+- }
+-
+- if (frameError ||
+- !bPsHeaderValid) { /* no new PS data available (e.g. frame loss) */
+- /* => keep latest data constant (i.e. FIX with noEnv=0) */
+- pBsData->noEnv = 0;
+- }
+-
+- /***************************************************************************************
+- * Decode bitstream payload or prepare parameter for concealment:
+- */
+- for (env = 0; env < pBsData->noEnv; env++) {
+- SCHAR *aPrevIidIndex;
+- SCHAR *aPrevIccIndex;
+-
+- UCHAR noIidSteps = pBsData->bFineIidQ ? NO_IID_STEPS_FINE : NO_IID_STEPS;
+-
+- if (env == 0) {
+- aPrevIidIndex = h_ps_d->specificTo.mpeg.aIidPrevFrameIndex;
+- aPrevIccIndex = h_ps_d->specificTo.mpeg.aIccPrevFrameIndex;
+- } else {
+- aPrevIidIndex = pBsData->aaIidIndex[env - 1];
+- aPrevIccIndex = pBsData->aaIccIndex[env - 1];
+- }
+-
+- deltaDecodeArray(pBsData->bEnableIid, pBsData->aaIidIndex[env],
+- aPrevIidIndex, pBsData->abIidDtFlag[env],
+- FDK_sbrDecoder_aNoIidBins[pBsData->freqResIid],
+- (pBsData->freqResIid) ? 1 : 2, -noIidSteps, noIidSteps);
+-
+- deltaDecodeArray(pBsData->bEnableIcc, pBsData->aaIccIndex[env],
+- aPrevIccIndex, pBsData->abIccDtFlag[env],
+- FDK_sbrDecoder_aNoIccBins[pBsData->freqResIcc],
+- (pBsData->freqResIcc) ? 1 : 2, 0, NO_ICC_STEPS - 1);
+- } /* for (env=0; env<pBsData->noEnv; env++) */
+-
+- /* handling of FIX noEnv=0 */
+- if (pBsData->noEnv == 0) {
+- /* set noEnv=1, keep last parameters or force 0 if not enabled */
+- pBsData->noEnv = 1;
+-
+- if (pBsData->bEnableIid) {
+- pBsData->bFineIidQ = h_ps_d->specificTo.mpeg.bPrevFrameFineIidQ;
+- pBsData->freqResIid = h_ps_d->specificTo.mpeg.prevFreqResIid;
+- for (gr = 0; gr < NO_HI_RES_IID_BINS; gr++) {
+- pBsData->aaIidIndex[pBsData->noEnv - 1][gr] =
+- h_ps_d->specificTo.mpeg.aIidPrevFrameIndex[gr];
+- }
+- } else {
+- for (gr = 0; gr < NO_HI_RES_IID_BINS; gr++) {
+- pBsData->aaIidIndex[pBsData->noEnv - 1][gr] = 0;
+- }
+- }
+-
+- if (pBsData->bEnableIcc) {
+- pBsData->freqResIcc = h_ps_d->specificTo.mpeg.prevFreqResIcc;
+- for (gr = 0; gr < NO_HI_RES_ICC_BINS; gr++) {
+- pBsData->aaIccIndex[pBsData->noEnv - 1][gr] =
+- h_ps_d->specificTo.mpeg.aIccPrevFrameIndex[gr];
+- }
+- } else {
+- for (gr = 0; gr < NO_HI_RES_ICC_BINS; gr++) {
+- pBsData->aaIccIndex[pBsData->noEnv - 1][gr] = 0;
+- }
+- }
+- }
+-
+- /* Update previous frame Iid quantization */
+- h_ps_d->specificTo.mpeg.bPrevFrameFineIidQ = pBsData->bFineIidQ;
+-
+- /* Update previous frequency resolution for IID */
+- h_ps_d->specificTo.mpeg.prevFreqResIid = pBsData->freqResIid;
+-
+- /* Update previous frequency resolution for ICC */
+- h_ps_d->specificTo.mpeg.prevFreqResIcc = pBsData->freqResIcc;
+-
+- /* Update previous frame index buffers */
+- for (gr = 0; gr < NO_HI_RES_IID_BINS; gr++) {
+- h_ps_d->specificTo.mpeg.aIidPrevFrameIndex[gr] =
+- pBsData->aaIidIndex[pBsData->noEnv - 1][gr];
+- }
+- for (gr = 0; gr < NO_HI_RES_ICC_BINS; gr++) {
+- h_ps_d->specificTo.mpeg.aIccPrevFrameIndex[gr] =
+- pBsData->aaIccIndex[pBsData->noEnv - 1][gr];
+- }
+-
+- /* PS data from bitstream (if avail) was decoded now */
+- h_ps_d->bPsDataAvail[h_ps_d->processSlot] = ppt_none;
+-
+- /* handling of env borders for FIX & VAR */
+- if (pBsData->bFrameClass == 0) {
+- /* FIX_BORDERS NoEnv=0,1,2,4 */
+- pBsData->aEnvStartStop[0] = 0;
+- for (env = 1; env < pBsData->noEnv; env++) {
+- pBsData->aEnvStartStop[env] =
+- (env * h_ps_d->noSubSamples) / pBsData->noEnv;
+- }
+- pBsData->aEnvStartStop[pBsData->noEnv] = h_ps_d->noSubSamples;
+- /* 1024 (32 slots) env borders: 0, 8, 16, 24, 32 */
+- /* 960 (30 slots) env borders: 0, 7, 15, 22, 30 */
+- } else { /* if (h_ps_d->bFrameClass == 0) */
+- /* VAR_BORDERS NoEnv=1,2,3,4 */
+- pBsData->aEnvStartStop[0] = 0;
+-
+- /* handle case aEnvStartStop[noEnv]<noSubSample for VAR_BORDERS by
+- duplicating last PS parameters and incrementing noEnv */
+- if (pBsData->aEnvStartStop[pBsData->noEnv] < h_ps_d->noSubSamples) {
+- for (gr = 0; gr < NO_HI_RES_IID_BINS; gr++) {
+- pBsData->aaIidIndex[pBsData->noEnv][gr] =
+- pBsData->aaIidIndex[pBsData->noEnv - 1][gr];
+- }
+- for (gr = 0; gr < NO_HI_RES_ICC_BINS; gr++) {
+- pBsData->aaIccIndex[pBsData->noEnv][gr] =
+- pBsData->aaIccIndex[pBsData->noEnv - 1][gr];
+- }
+- pBsData->noEnv++;
+- pBsData->aEnvStartStop[pBsData->noEnv] = h_ps_d->noSubSamples;
+- }
+-
+- /* enforce strictly monotonic increasing borders */
+- for (env = 1; env < pBsData->noEnv; env++) {
+- UCHAR thr;
+- thr = (UCHAR)h_ps_d->noSubSamples - (pBsData->noEnv - env);
+- if (pBsData->aEnvStartStop[env] > thr) {
+- pBsData->aEnvStartStop[env] = thr;
+- } else {
+- thr = pBsData->aEnvStartStop[env - 1] + 1;
+- if (pBsData->aEnvStartStop[env] < thr) {
+- pBsData->aEnvStartStop[env] = thr;
+- }
+- }
+- }
+- } /* if (h_ps_d->bFrameClass == 0) ... else */
+-
+- /* copy data prior to possible 20<->34 in-place mapping */
+- for (env = 0; env < pBsData->noEnv; env++) {
+- UCHAR i;
+- for (i = 0; i < NO_HI_RES_IID_BINS; i++) {
+- h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][i] =
+- pBsData->aaIidIndex[env][i];
+- }
+- for (i = 0; i < NO_HI_RES_ICC_BINS; i++) {
+- h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][i] =
+- pBsData->aaIccIndex[env][i];
+- }
+- }
+-
+- /* MPEG baseline PS */
+- /* Baseline version of PS always uses the hybrid filter structure with 20
+- * stereo bands. */
+- /* If ICC/IID parameters for 34 stereo bands are decoded they have to be
+- * mapped to 20 */
+- /* stereo bands. */
+- /* Additionaly the IPD/OPD parameters won't be used. */
+-
+- for (env = 0; env < pBsData->noEnv; env++) {
+- if (pBsData->freqResIid == 2)
+- map34IndexTo20(h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env],
+- NO_HI_RES_IID_BINS);
+- if (pBsData->freqResIcc == 2)
+- map34IndexTo20(h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env],
+- NO_HI_RES_ICC_BINS);
+-
+- /* IPD/OPD is disabled in baseline version and thus was removed here */
+- }
+-
+- return (1);
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Reads parametric stereo data from bitstream
+-
+- \return
+-
+-****************************************************************************/
+-unsigned int ReadPsData(
+- HANDLE_PS_DEC h_ps_d, /*!< handle to struct PS_DEC */
+- HANDLE_FDK_BITSTREAM hBitBuf, /*!< handle to struct BIT_BUF */
+- int nBitsLeft /*!< max number of bits available */
+-) {
+- MPEG_PS_BS_DATA *pBsData;
+-
+- UCHAR gr, env;
+- SCHAR dtFlag;
+- INT startbits;
+- Huffman CurrentTable;
+- SCHAR bEnableHeader;
+-
+- if (!h_ps_d) return 0;
+-
+- pBsData = &h_ps_d->bsData[h_ps_d->bsReadSlot].mpeg;
+-
+- if (h_ps_d->bsReadSlot != h_ps_d->bsLastSlot) {
+- /* Copy last header data */
+- FDKmemcpy(pBsData, &h_ps_d->bsData[h_ps_d->bsLastSlot].mpeg,
+- sizeof(MPEG_PS_BS_DATA));
+- }
+-
+- startbits = (INT)FDKgetValidBits(hBitBuf);
+-
+- bEnableHeader = (SCHAR)FDKreadBits(hBitBuf, 1);
+-
+- /* Read header */
+- if (bEnableHeader) {
+- pBsData->bPsHeaderValid = 1;
+- pBsData->bEnableIid = (UCHAR)FDKreadBits(hBitBuf, 1);
+- if (pBsData->bEnableIid) {
+- pBsData->modeIid = (UCHAR)FDKreadBits(hBitBuf, 3);
+- }
+-
+- pBsData->bEnableIcc = (UCHAR)FDKreadBits(hBitBuf, 1);
+- if (pBsData->bEnableIcc) {
+- pBsData->modeIcc = (UCHAR)FDKreadBits(hBitBuf, 3);
+- }
+-
+- pBsData->bEnableExt = (UCHAR)FDKreadBits(hBitBuf, 1);
+- }
+-
+- pBsData->bFrameClass = (UCHAR)FDKreadBits(hBitBuf, 1);
+- if (pBsData->bFrameClass == 0) {
+- /* FIX_BORDERS NoEnv=0,1,2,4 */
+- pBsData->noEnv =
+- FDK_sbrDecoder_aFixNoEnvDecode[(UCHAR)FDKreadBits(hBitBuf, 2)];
+- /* all additional handling of env borders is now in DecodePs() */
+- } else {
+- /* VAR_BORDERS NoEnv=1,2,3,4 */
+- pBsData->noEnv = 1 + (UCHAR)FDKreadBits(hBitBuf, 2);
+- for (env = 1; env < pBsData->noEnv + 1; env++)
+- pBsData->aEnvStartStop[env] = ((UCHAR)FDKreadBits(hBitBuf, 5)) + 1;
+- /* all additional handling of env borders is now in DecodePs() */
+- }
+-
+- /* verify that IID & ICC modes (quant grid, freq res) are supported */
+- if ((pBsData->modeIid > 5) || (pBsData->modeIcc > 5)) {
+- /* no useful PS data could be read from bitstream */
+- h_ps_d->bPsDataAvail[h_ps_d->bsReadSlot] = ppt_none;
+- /* discard all remaining bits */
+- nBitsLeft -= startbits - (INT)FDKgetValidBits(hBitBuf);
+- while (nBitsLeft > 0) {
+- int i = nBitsLeft;
+- if (i > 8) {
+- i = 8;
+- }
+- FDKreadBits(hBitBuf, i);
+- nBitsLeft -= i;
+- }
+- return (UINT)(startbits - (INT)FDKgetValidBits(hBitBuf));
+- }
+-
+- if (pBsData->modeIid > 2) {
+- pBsData->freqResIid = pBsData->modeIid - 3;
+- pBsData->bFineIidQ = 1;
+- } else {
+- pBsData->freqResIid = pBsData->modeIid;
+- pBsData->bFineIidQ = 0;
+- }
+-
+- if (pBsData->modeIcc > 2) {
+- pBsData->freqResIcc = pBsData->modeIcc - 3;
+- } else {
+- pBsData->freqResIcc = pBsData->modeIcc;
+- }
+-
+- /* Extract IID data */
+- if (pBsData->bEnableIid) {
+- for (env = 0; env < pBsData->noEnv; env++) {
+- dtFlag = (SCHAR)FDKreadBits(hBitBuf, 1);
+- if (!dtFlag) {
+- if (pBsData->bFineIidQ)
+- CurrentTable = (Huffman)&aBookPsIidFineFreqDecode;
+- else
+- CurrentTable = (Huffman)&aBookPsIidFreqDecode;
+- } else {
+- if (pBsData->bFineIidQ)
+- CurrentTable = (Huffman)&aBookPsIidFineTimeDecode;
+- else
+- CurrentTable = (Huffman)&aBookPsIidTimeDecode;
+- }
+-
+- for (gr = 0; gr < FDK_sbrDecoder_aNoIidBins[pBsData->freqResIid]; gr++)
+- pBsData->aaIidIndex[env][gr] =
+- decode_huff_cw(CurrentTable, hBitBuf, NULL);
+- pBsData->abIidDtFlag[env] = dtFlag;
+- }
+- }
+-
+- /* Extract ICC data */
+- if (pBsData->bEnableIcc) {
+- for (env = 0; env < pBsData->noEnv; env++) {
+- dtFlag = (SCHAR)FDKreadBits(hBitBuf, 1);
+- if (!dtFlag)
+- CurrentTable = (Huffman)&aBookPsIccFreqDecode;
+- else
+- CurrentTable = (Huffman)&aBookPsIccTimeDecode;
+-
+- for (gr = 0; gr < FDK_sbrDecoder_aNoIccBins[pBsData->freqResIcc]; gr++)
+- pBsData->aaIccIndex[env][gr] =
+- decode_huff_cw(CurrentTable, hBitBuf, NULL);
+- pBsData->abIccDtFlag[env] = dtFlag;
+- }
+- }
+-
+- if (pBsData->bEnableExt) {
+- /*!
+- Decoders that support only the baseline version of the PS tool are allowed
+- to ignore the IPD/OPD data, but according header data has to be parsed.
+- ISO/IEC 14496-3 Subpart 8 Annex 4
+- */
+-
+- int cnt = FDKreadBits(hBitBuf, PS_EXTENSION_SIZE_BITS);
+- if (cnt == (1 << PS_EXTENSION_SIZE_BITS) - 1) {
+- cnt += FDKreadBits(hBitBuf, PS_EXTENSION_ESC_COUNT_BITS);
+- }
+- while (cnt--) FDKreadBits(hBitBuf, 8);
+- }
+-
+- /* new PS data was read from bitstream */
+- h_ps_d->bPsDataAvail[h_ps_d->bsReadSlot] = ppt_mpeg;
+-
+- return (startbits - (INT)FDKgetValidBits(hBitBuf));
+-}
+diff --git a/libSBRdec/src/psbitdec.h b/libSBRdec/src/psbitdec.h
+deleted file mode 100644
+index f0fc43a..0000000
+--- a/libSBRdec/src/psbitdec.h
++++ /dev/null
+@@ -1,116 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#ifndef PSBITDEC_H
+-#define PSBITDEC_H
+-
+-#include "sbrdecoder.h"
+-
+-#include "psdec.h"
+-
+-unsigned int ReadPsData(struct PS_DEC *h_ps_d, HANDLE_FDK_BITSTREAM hBs,
+- int nBitsLeft);
+-
+-int DecodePs(struct PS_DEC *h_ps_d, const UCHAR frameError,
+- PS_DEC_COEFFICIENTS *pCoef);
+-
+-#endif /* PSBITDEC_H */
+diff --git a/libSBRdec/src/psdec.cpp b/libSBRdec/src/psdec.cpp
+deleted file mode 100644
+index b31b310..0000000
+--- a/libSBRdec/src/psdec.cpp
++++ /dev/null
+@@ -1,722 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief parametric stereo decoder
+-*/
+-
+-#include "psdec.h"
+-
+-#include "FDK_bitbuffer.h"
+-
+-#include "sbr_rom.h"
+-#include "sbr_ram.h"
+-
+-#include "FDK_tools_rom.h"
+-
+-#include "genericStds.h"
+-
+-#include "FDK_trigFcts.h"
+-
+-/********************************************************************/
+-/* MLQUAL DEFINES */
+-/********************************************************************/
+-
+-#define FRACT_ZERO FRACT_BITS - 1
+-/********************************************************************/
+-
+-SBR_ERROR ResetPsDec(HANDLE_PS_DEC h_ps_d);
+-
+-/***** HELPERS *****/
+-
+-/***************************************************************************/
+-/*!
+- \brief Creates one instance of the PS_DEC struct
+-
+- \return Error info
+-
+-****************************************************************************/
+-int CreatePsDec(HANDLE_PS_DEC *h_PS_DEC, /*!< pointer to the module state */
+- int aacSamplesPerFrame) {
+- SBR_ERROR errorInfo = SBRDEC_OK;
+- HANDLE_PS_DEC h_ps_d;
+- int i;
+-
+- if (*h_PS_DEC == NULL) {
+- /* Get ps dec ram */
+- h_ps_d = GetRam_ps_dec();
+- if (h_ps_d == NULL) {
+- goto bail;
+- }
+- } else {
+- /* Reset an open instance */
+- h_ps_d = *h_PS_DEC;
+- }
+-
+- /*
+- * Create Analysis Hybrid filterbank.
+- */
+- FDKhybridAnalysisOpen(&h_ps_d->specificTo.mpeg.hybridAnalysis,
+- h_ps_d->specificTo.mpeg.pHybridAnaStatesLFdmx,
+- sizeof(h_ps_d->specificTo.mpeg.pHybridAnaStatesLFdmx),
+- NULL, 0);
+-
+- /* initialisation */
+- switch (aacSamplesPerFrame) {
+- case 960:
+- h_ps_d->noSubSamples = 30; /* col */
+- break;
+- case 1024:
+- h_ps_d->noSubSamples = 32; /* col */
+- break;
+- default:
+- h_ps_d->noSubSamples = -1;
+- break;
+- }
+-
+- if (h_ps_d->noSubSamples > MAX_NUM_COL || h_ps_d->noSubSamples <= 0) {
+- goto bail;
+- }
+- h_ps_d->noChannels = NO_QMF_CHANNELS; /* row */
+-
+- h_ps_d->psDecodedPrv = 0;
+- h_ps_d->procFrameBased = -1;
+- for (i = 0; i < (1) + 1; i++) {
+- h_ps_d->bPsDataAvail[i] = ppt_none;
+- }
+- {
+- int error;
+- error = FDKdecorrelateOpen(&(h_ps_d->specificTo.mpeg.apDecor),
+- h_ps_d->specificTo.mpeg.decorrBufferCplx,
+- (2 * ((825) + (373))));
+- if (error) goto bail;
+- }
+-
+- for (i = 0; i < (1) + 1; i++) {
+- FDKmemclear(&h_ps_d->bsData[i].mpeg, sizeof(MPEG_PS_BS_DATA));
+- }
+-
+- errorInfo = ResetPsDec(h_ps_d);
+-
+- if (errorInfo != SBRDEC_OK) goto bail;
+-
+- *h_PS_DEC = h_ps_d;
+-
+- return 0;
+-
+-bail:
+- if (h_ps_d != NULL) {
+- DeletePsDec(&h_ps_d);
+- }
+-
+- return -1;
+-} /*END CreatePsDec */
+-
+-/***************************************************************************/
+-/*!
+- \brief Delete one instance of the PS_DEC struct
+-
+- \return Error info
+-
+-****************************************************************************/
+-int DeletePsDec(HANDLE_PS_DEC *h_PS_DEC) /*!< pointer to the module state */
+-{
+- if (*h_PS_DEC == NULL) {
+- return -1;
+- }
+-
+- {
+- HANDLE_PS_DEC h_ps_d = *h_PS_DEC;
+- FDKdecorrelateClose(&(h_ps_d->specificTo.mpeg.apDecor));
+- }
+-
+- FreeRam_ps_dec(h_PS_DEC);
+-
+- return 0;
+-} /*END DeletePsDec */
+-
+-/***************************************************************************/
+-/*!
+- \brief resets some values of the PS handle to default states
+-
+- \return
+-
+-****************************************************************************/
+-SBR_ERROR ResetPsDec(HANDLE_PS_DEC h_ps_d) /*!< pointer to the module state */
+-{
+- SBR_ERROR errorInfo = SBRDEC_OK;
+- INT i;
+-
+- /* explicitly init state variables to safe values (until first ps header
+- * arrives) */
+-
+- h_ps_d->specificTo.mpeg.lastUsb = 0;
+-
+- /*
+- * Initialize Analysis Hybrid filterbank.
+- */
+- FDKhybridAnalysisInit(&h_ps_d->specificTo.mpeg.hybridAnalysis, THREE_TO_TEN,
+- NO_QMF_BANDS_HYBRID20, NO_QMF_BANDS_HYBRID20, 1);
+-
+- /*
+- * Initialize Synthesis Hybrid filterbank.
+- */
+- for (i = 0; i < 2; i++) {
+- FDKhybridSynthesisInit(&h_ps_d->specificTo.mpeg.hybridSynthesis[i],
+- THREE_TO_TEN, NO_QMF_CHANNELS, NO_QMF_CHANNELS);
+- }
+- {
+- INT error;
+- error = FDKdecorrelateInit(&h_ps_d->specificTo.mpeg.apDecor, 71, DECORR_PS,
+- DUCKER_AUTOMATIC, 0, 0, 0, 0, 1, /* isLegacyPS */
+- 1);
+- if (error) return SBRDEC_NOT_INITIALIZED;
+- }
+-
+- for (i = 0; i < NO_IID_GROUPS; i++) {
+- h_ps_d->specificTo.mpeg.h11rPrev[i] = FL2FXCONST_DBL(0.5f);
+- h_ps_d->specificTo.mpeg.h12rPrev[i] = FL2FXCONST_DBL(0.5f);
+- }
+-
+- FDKmemclear(h_ps_d->specificTo.mpeg.h21rPrev,
+- sizeof(h_ps_d->specificTo.mpeg.h21rPrev));
+- FDKmemclear(h_ps_d->specificTo.mpeg.h22rPrev,
+- sizeof(h_ps_d->specificTo.mpeg.h22rPrev));
+-
+- return errorInfo;
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief Feed delaylines when parametric stereo is switched on.
+- \return
+-****************************************************************************/
+-void PreparePsProcessing(HANDLE_PS_DEC h_ps_d,
+- const FIXP_DBL *const *const rIntBufferLeft,
+- const FIXP_DBL *const *const iIntBufferLeft,
+- const int scaleFactorLowBand) {
+- if (h_ps_d->procFrameBased ==
+- 1) /* If we have switched from frame to slot based processing */
+- { /* fill hybrid delay buffer. */
+- int i, j;
+-
+- for (i = 0; i < HYBRID_FILTER_DELAY; i++) {
+- FIXP_DBL qmfInputData[2][NO_QMF_BANDS_HYBRID20];
+- FIXP_DBL hybridOutputData[2][NO_SUB_QMF_CHANNELS];
+-
+- for (j = 0; j < NO_QMF_BANDS_HYBRID20; j++) {
+- qmfInputData[0][j] =
+- scaleValue(rIntBufferLeft[i][j], scaleFactorLowBand);
+- qmfInputData[1][j] =
+- scaleValue(iIntBufferLeft[i][j], scaleFactorLowBand);
+- }
+-
+- FDKhybridAnalysisApply(&h_ps_d->specificTo.mpeg.hybridAnalysis,
+- qmfInputData[0], qmfInputData[1],
+- hybridOutputData[0], hybridOutputData[1]);
+- }
+- h_ps_d->procFrameBased = 0; /* switch to slot based processing. */
+-
+- } /* procFrameBased==1 */
+-}
+-
+-void initSlotBasedRotation(
+- HANDLE_PS_DEC h_ps_d, /*!< pointer to the module state */
+- int env, int usb) {
+- INT group = 0;
+- INT bin = 0;
+- INT noIidSteps, noFactors;
+-
+- FIXP_SGL invL;
+- FIXP_DBL ScaleL, ScaleR;
+- FIXP_DBL Alpha, Beta, AlphasValue;
+- FIXP_DBL h11r, h12r, h21r, h22r;
+-
+- const FIXP_DBL *PScaleFactors;
+-
+- if (h_ps_d->bsData[h_ps_d->processSlot].mpeg.bFineIidQ) {
+- PScaleFactors = ScaleFactorsFine; /* values are shiftet right by one */
+- noIidSteps = NO_IID_STEPS_FINE;
+- noFactors = NO_IID_LEVELS_FINE;
+- } else {
+- PScaleFactors = ScaleFactors; /* values are shiftet right by one */
+- noIidSteps = NO_IID_STEPS;
+- noFactors = NO_IID_LEVELS;
+- }
+-
+- /* dequantize and decode */
+- for (group = 0; group < NO_IID_GROUPS; group++) {
+- bin = bins2groupMap20[group];
+-
+- /*!
+- <h3> type 'A' rotation </h3>
+- mixing procedure R_a, used in baseline version<br>
+-
+- Scale-factor vectors c1 and c2 are precalculated in initPsTables () and
+- stored in scaleFactors[] and scaleFactorsFine[] = pScaleFactors []. From the
+- linearized IID parameters (intensity differences), two scale factors are
+- calculated. They are used to obtain the coefficients h11... h22.
+- */
+-
+- /* ScaleR and ScaleL are scaled by 1 shift right */
+-
+- ScaleL = ScaleR = 0;
+- if (noIidSteps + h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] >= 0 && noIidSteps + h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] < noFactors)
+- ScaleR = PScaleFactors[noIidSteps + h_ps_d->specificTo.mpeg.pCoef
+- ->aaIidIndexMapped[env][bin]];
+- if (noIidSteps - h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] >= 0 && noIidSteps - h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] < noFactors)
+- ScaleL = PScaleFactors[noIidSteps - h_ps_d->specificTo.mpeg.pCoef
+- ->aaIidIndexMapped[env][bin]];
+-
+- AlphasValue = 0;
+- if (h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin] >= 0)
+- AlphasValue = Alphas[h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin]];
+- Beta = fMult(
+- fMult(AlphasValue,
+- (ScaleR - ScaleL)),
+- FIXP_SQRT05);
+- Alpha =
+- AlphasValue >> 1;
+-
+- /* Alpha and Beta are now both scaled by 2 shifts right */
+-
+- /* calculate the coefficients h11... h22 from scale-factors and ICC
+- * parameters */
+-
+- /* h values are scaled by 1 shift right */
+- {
+- FIXP_DBL trigData[4];
+-
+- inline_fixp_cos_sin(Beta + Alpha, Beta - Alpha, 2, trigData);
+- h11r = fMult(ScaleL, trigData[0]);
+- h12r = fMult(ScaleR, trigData[2]);
+- h21r = fMult(ScaleL, trigData[1]);
+- h22r = fMult(ScaleR, trigData[3]);
+- }
+- /*****************************************************************************************/
+- /* Interpolation of the matrices H11... H22: */
+- /* */
+- /* H11(k,n) = H11(k,n[e]) + (n-n[e]) * (H11(k,n[e+1] - H11(k,n[e])) /
+- * (n[e+1] - n[e]) */
+- /* ... */
+- /*****************************************************************************************/
+-
+- /* invL = 1/(length of envelope) */
+- invL = FX_DBL2FX_SGL(GetInvInt(
+- h_ps_d->bsData[h_ps_d->processSlot].mpeg.aEnvStartStop[env + 1] -
+- h_ps_d->bsData[h_ps_d->processSlot].mpeg.aEnvStartStop[env]));
+-
+- h_ps_d->specificTo.mpeg.pCoef->H11r[group] =
+- h_ps_d->specificTo.mpeg.h11rPrev[group];
+- h_ps_d->specificTo.mpeg.pCoef->H12r[group] =
+- h_ps_d->specificTo.mpeg.h12rPrev[group];
+- h_ps_d->specificTo.mpeg.pCoef->H21r[group] =
+- h_ps_d->specificTo.mpeg.h21rPrev[group];
+- h_ps_d->specificTo.mpeg.pCoef->H22r[group] =
+- h_ps_d->specificTo.mpeg.h22rPrev[group];
+-
+- h_ps_d->specificTo.mpeg.pCoef->DeltaH11r[group] =
+- fMult(h11r - h_ps_d->specificTo.mpeg.pCoef->H11r[group], invL);
+- h_ps_d->specificTo.mpeg.pCoef->DeltaH12r[group] =
+- fMult(h12r - h_ps_d->specificTo.mpeg.pCoef->H12r[group], invL);
+- h_ps_d->specificTo.mpeg.pCoef->DeltaH21r[group] =
+- fMult(h21r - h_ps_d->specificTo.mpeg.pCoef->H21r[group], invL);
+- h_ps_d->specificTo.mpeg.pCoef->DeltaH22r[group] =
+- fMult(h22r - h_ps_d->specificTo.mpeg.pCoef->H22r[group], invL);
+-
+- /* update prev coefficients for interpolation in next envelope */
+-
+- h_ps_d->specificTo.mpeg.h11rPrev[group] = h11r;
+- h_ps_d->specificTo.mpeg.h12rPrev[group] = h12r;
+- h_ps_d->specificTo.mpeg.h21rPrev[group] = h21r;
+- h_ps_d->specificTo.mpeg.h22rPrev[group] = h22r;
+-
+- } /* group loop */
+-}
+-
+-static const UCHAR groupTable[NO_IID_GROUPS + 1] = {
+- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+- 12, 13, 14, 15, 16, 18, 21, 25, 30, 42, 71};
+-
+-static void applySlotBasedRotation(
+- HANDLE_PS_DEC h_ps_d, /*!< pointer to the module state */
+-
+- FIXP_DBL *mHybridRealLeft, /*!< hybrid values real left */
+- FIXP_DBL *mHybridImagLeft, /*!< hybrid values imag left */
+-
+- FIXP_DBL *mHybridRealRight, /*!< hybrid values real right */
+- FIXP_DBL *mHybridImagRight /*!< hybrid values imag right */
+-) {
+- INT group;
+- INT subband;
+-
+- /**********************************************************************************************/
+- /*!
+- <h2> Mapping </h2>
+-
+- The number of stereo bands that is actually used depends on the number of
+- availble parameters for IID and ICC: <pre> nr. of IID para.| nr. of ICC para.
+- | nr. of Stereo bands
+- ----------------|------------------|-------------------
+- 10,20 | 10,20 | 20
+- 10,20 | 34 | 34
+- 34 | 10,20 | 34
+- 34 | 34 | 34
+- </pre>
+- In the case the number of parameters for IIS and ICC differs from the number
+- of stereo bands, a mapping from the lower number to the higher number of
+- parameters is applied. Index mapping of IID and ICC parameters is already done
+- in psbitdec.cpp. Further mapping is not needed here in baseline version.
+- **********************************************************************************************/
+-
+- /************************************************************************************************/
+- /*!
+- <h2> Mixing </h2>
+-
+- To generate the QMF subband signals for the subband samples n = n[e]+1 ,,,
+- n_[e+1] the parameters at position n[e] and n[e+1] are required as well as the
+- subband domain signals s_k(n) and d_k(n) for n = n[e]+1... n_[e+1]. n[e]
+- represents the start position for envelope e. The border positions n[e] are
+- handled in DecodePS().
+-
+- The stereo sub subband signals are constructed as:
+- <pre>
+- l_k(n) = H11(k,n) s_k(n) + H21(k,n) d_k(n)
+- r_k(n) = H21(k,n) s_k(n) + H22(k,n) d_k(n)
+- </pre>
+- In order to obtain the matrices H11(k,n)... H22 (k,n), the vectors h11(b)...
+- h22(b) need to be calculated first (b: parameter index). Depending on ICC mode
+- either mixing procedure R_a or R_b is used for that. For both procedures, the
+- parameters for parameter position n[e+1] is used.
+- ************************************************************************************************/
+-
+- /************************************************************************************************/
+- /*!
+- <h2>Phase parameters </h2>
+- With disabled phase parameters (which is the case in baseline version), the
+- H-matrices are just calculated by:
+-
+- <pre>
+- H11(k,n[e+1] = h11(b(k))
+- (...)
+- b(k): parameter index according to mapping table
+- </pre>
+-
+- <h2>Processing of the samples in the sub subbands </h2>
+- this loop includes the interpolation of the coefficients Hxx
+- ************************************************************************************************/
+-
+- /******************************************************/
+- /* construct stereo sub subband signals according to: */
+- /* */
+- /* l_k(n) = H11(k,n) s_k(n) + H21(k,n) d_k(n) */
+- /* r_k(n) = H12(k,n) s_k(n) + H22(k,n) d_k(n) */
+- /******************************************************/
+- PS_DEC_COEFFICIENTS *pCoef = h_ps_d->specificTo.mpeg.pCoef;
+-
+- for (group = 0; group < NO_IID_GROUPS; group++) {
+- pCoef->H11r[group] += pCoef->DeltaH11r[group];
+- pCoef->H12r[group] += pCoef->DeltaH12r[group];
+- pCoef->H21r[group] += pCoef->DeltaH21r[group];
+- pCoef->H22r[group] += pCoef->DeltaH22r[group];
+-
+- const int start = groupTable[group];
+- const int stop = groupTable[group + 1];
+- for (subband = start; subband < stop; subband++) {
+- FIXP_DBL tmpLeft =
+- fMultAdd(fMultDiv2(pCoef->H11r[group], mHybridRealLeft[subband]),
+- pCoef->H21r[group], mHybridRealRight[subband]);
+- FIXP_DBL tmpRight =
+- fMultAdd(fMultDiv2(pCoef->H12r[group], mHybridRealLeft[subband]),
+- pCoef->H22r[group], mHybridRealRight[subband]);
+- mHybridRealLeft[subband] = tmpLeft;
+- mHybridRealRight[subband] = tmpRight;
+-
+- tmpLeft =
+- fMultAdd(fMultDiv2(pCoef->H11r[group], mHybridImagLeft[subband]),
+- pCoef->H21r[group], mHybridImagRight[subband]);
+- tmpRight =
+- fMultAdd(fMultDiv2(pCoef->H12r[group], mHybridImagLeft[subband]),
+- pCoef->H22r[group], mHybridImagRight[subband]);
+- mHybridImagLeft[subband] = tmpLeft;
+- mHybridImagRight[subband] = tmpRight;
+- } /* subband */
+- }
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief Applies IID, ICC, IPD and OPD parameters to the current frame.
+-
+- \return none
+-
+-****************************************************************************/
+-void ApplyPsSlot(
+- HANDLE_PS_DEC h_ps_d, /*!< handle PS_DEC*/
+- FIXP_DBL **rIntBufferLeft, /*!< real bands left qmf channel (38x64) */
+- FIXP_DBL **iIntBufferLeft, /*!< imag bands left qmf channel (38x64) */
+- FIXP_DBL *rIntBufferRight, /*!< real bands right qmf channel (38x64) */
+- FIXP_DBL *iIntBufferRight, /*!< imag bands right qmf channel (38x64) */
+- const int scaleFactorLowBand_no_ov, const int scaleFactorLowBand,
+- const int scaleFactorHighBand, const int lsb, const int usb) {
+-/*!
+-The 64-band QMF representation of the monaural signal generated by the SBR tool
+-is used as input of the PS tool. After the PS processing, the outputs of the
+-left and right hybrid synthesis filterbanks are used to generate the stereo
+-output signal.
+-
+-<pre>
+-
+- ------------- ---------- -------------
+- | Hybrid | M_n[k,m] | | L_n[k,m] | Hybrid | l[n]
+- m[n] --->| analysis |--------->| |--------->| synthesis |----->
+- ------------- | Stereo | -------------
+- | | recon- |
+- | | stuction |
+- \|/ | |
+- ------------- | |
+- | De- | D_n[k,m] | |
+- | correlation |--------->| |
+- ------------- | | -------------
+- | | R_n[k,m] | Hybrid | r[n]
+- | |--------->| synthesis |----->
+- IID, ICC ------------------------>| | | filter bank |
+-(IPD, OPD) ---------- -------------
+-
+-m[n]: QMF represantation of the mono input
+-M_n[k,m]: (sub-)sub-band domain signals of the mono input
+-D_n[k,m]: decorrelated (sub-)sub-band domain signals
+-L_n[k,m]: (sub-)sub-band domain signals of the left output
+-R_n[k,m]: (sub-)sub-band domain signals of the right output
+-l[n],r[n]: left/right output signals
+-
+-</pre>
+-*/
+-#define NO_HYBRID_DATA_BANDS (71)
+-
+- int i;
+- FIXP_DBL qmfInputData[2][NO_QMF_BANDS_HYBRID20];
+- FIXP_DBL *hybridData[2][2];
+- C_ALLOC_SCRATCH_START(pHybridData, FIXP_DBL, 4 * NO_HYBRID_DATA_BANDS);
+-
+- hybridData[0][0] =
+- pHybridData + 0 * NO_HYBRID_DATA_BANDS; /* left real hybrid data */
+- hybridData[0][1] =
+- pHybridData + 1 * NO_HYBRID_DATA_BANDS; /* left imag hybrid data */
+- hybridData[1][0] =
+- pHybridData + 2 * NO_HYBRID_DATA_BANDS; /* right real hybrid data */
+- hybridData[1][1] =
+- pHybridData + 3 * NO_HYBRID_DATA_BANDS; /* right imag hybrid data */
+-
+- /*!
+- Hybrid analysis filterbank:
+- The lower 3 (5) of the 64 QMF subbands are further split to provide better
+- frequency resolution. for PS processing. For the 10 and 20 stereo bands
+- configuration, the QMF band H_0(w) is split up into 8 (sub-) sub-bands and the
+- QMF bands H_1(w) and H_2(w) are spit into 2 (sub-) 4th. (See figures 8.20
+- and 8.22 of ISO/IEC 14496-3:2001/FDAM 2:2004(E) )
+- */
+-
+- /*
+- * Hybrid analysis.
+- */
+-
+- /* Get qmf input data and apply descaling */
+- for (i = 0; i < NO_QMF_BANDS_HYBRID20; i++) {
+- qmfInputData[0][i] = scaleValue(rIntBufferLeft[HYBRID_FILTER_DELAY][i],
+- scaleFactorLowBand_no_ov);
+- qmfInputData[1][i] = scaleValue(iIntBufferLeft[HYBRID_FILTER_DELAY][i],
+- scaleFactorLowBand_no_ov);
+- }
+-
+- /* LF - part */
+- FDKhybridAnalysisApply(&h_ps_d->specificTo.mpeg.hybridAnalysis,
+- qmfInputData[0], qmfInputData[1], hybridData[0][0],
+- hybridData[0][1]);
+-
+- /* HF - part */
+- /* bands up to lsb */
+- scaleValues(&hybridData[0][0][NO_SUB_QMF_CHANNELS - 2],
+- &rIntBufferLeft[0][NO_QMF_BANDS_HYBRID20],
+- lsb - NO_QMF_BANDS_HYBRID20, scaleFactorLowBand);
+- scaleValues(&hybridData[0][1][NO_SUB_QMF_CHANNELS - 2],
+- &iIntBufferLeft[0][NO_QMF_BANDS_HYBRID20],
+- lsb - NO_QMF_BANDS_HYBRID20, scaleFactorLowBand);
+-
+- /* bands from lsb to usb */
+- scaleValues(&hybridData[0][0][lsb + (NO_SUB_QMF_CHANNELS - 2 -
+- NO_QMF_BANDS_HYBRID20)],
+- &rIntBufferLeft[0][lsb], usb - lsb, scaleFactorHighBand);
+- scaleValues(&hybridData[0][1][lsb + (NO_SUB_QMF_CHANNELS - 2 -
+- NO_QMF_BANDS_HYBRID20)],
+- &iIntBufferLeft[0][lsb], usb - lsb, scaleFactorHighBand);
+-
+- /* bands from usb to NO_SUB_QMF_CHANNELS which should be zero for non-overlap
+- slots but can be non-zero for overlap slots */
+- FDKmemcpy(
+- &hybridData[0][0]
+- [usb + (NO_SUB_QMF_CHANNELS - 2 - NO_QMF_BANDS_HYBRID20)],
+- &rIntBufferLeft[0][usb], sizeof(FIXP_DBL) * (NO_QMF_CHANNELS - usb));
+- FDKmemcpy(
+- &hybridData[0][1]
+- [usb + (NO_SUB_QMF_CHANNELS - 2 - NO_QMF_BANDS_HYBRID20)],
+- &iIntBufferLeft[0][usb], sizeof(FIXP_DBL) * (NO_QMF_CHANNELS - usb));
+-
+- /*!
+- Decorrelation:
+- By means of all-pass filtering and delaying, the (sub-)sub-band samples s_k(n)
+- are converted into de-correlated (sub-)sub-band samples d_k(n).
+- - k: frequency in hybrid spectrum
+- - n: time index
+- */
+-
+- FDKdecorrelateApply(&h_ps_d->specificTo.mpeg.apDecor,
+- &hybridData[0][0][0], /* left real hybrid data */
+- &hybridData[0][1][0], /* left imag hybrid data */
+- &hybridData[1][0][0], /* right real hybrid data */
+- &hybridData[1][1][0], /* right imag hybrid data */
+- 0 /* startHybBand */
+- );
+-
+- /*!
+- Stereo Processing:
+- The sets of (sub-)sub-band samples s_k(n) and d_k(n) are processed according
+- to the stereo cues which are defined per stereo band.
+- */
+-
+- applySlotBasedRotation(h_ps_d,
+- &hybridData[0][0][0], /* left real hybrid data */
+- &hybridData[0][1][0], /* left imag hybrid data */
+- &hybridData[1][0][0], /* right real hybrid data */
+- &hybridData[1][1][0] /* right imag hybrid data */
+- );
+-
+- /*!
+- Hybrid synthesis filterbank:
+- The stereo processed hybrid subband signals l_k(n) and r_k(n) are fed into the
+- hybrid synthesis filterbanks which are identical to the 64 complex synthesis
+- filterbank of the SBR tool. The input to the filterbank are slots of 64 QMF
+- samples. For each slot the filterbank outputs one block of 64 samples of one
+- reconstructed stereo channel. The hybrid synthesis filterbank is computed
+- seperatly for the left and right channel.
+- */
+-
+- /*
+- * Hybrid synthesis.
+- */
+- for (i = 0; i < 2; i++) {
+- FDKhybridSynthesisApply(
+- &h_ps_d->specificTo.mpeg.hybridSynthesis[i],
+- hybridData[i][0], /* real hybrid data */
+- hybridData[i][1], /* imag hybrid data */
+- (i == 0) ? rIntBufferLeft[0]
+- : rIntBufferRight, /* output real qmf buffer */
+- (i == 0) ? iIntBufferLeft[0]
+- : iIntBufferRight /* output imag qmf buffer */
+- );
+- }
+-
+- /* free temporary hybrid qmf values of one timeslot */
+- C_ALLOC_SCRATCH_END(pHybridData, FIXP_DBL, 4 * NO_HYBRID_DATA_BANDS);
+-
+-} /* END ApplyPsSlot */
+diff --git a/libSBRdec/src/psdec.h b/libSBRdec/src/psdec.h
+deleted file mode 100644
+index 029eac4..0000000
+--- a/libSBRdec/src/psdec.h
++++ /dev/null
+@@ -1,333 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Sbr decoder
+-*/
+-#ifndef PSDEC_H
+-#define PSDEC_H
+-
+-#include "sbrdecoder.h"
+-#include "FDK_hybrid.h"
+-
+-#include "FDK_decorrelate.h"
+-
+-/* This PS decoder implements the baseline version. So it always uses the */
+-/* hybrid filter structure for 20 stereo bands and does not implemet IPD/OPD */
+-/* synthesis. The baseline version has to support the complete PS bitstream */
+-/* syntax. But IPD/OPD data is ignored and set to 0. If 34 stereo band config */
+-/* is used in the bitstream for IIS/ICC the decoded parameters are mapped to */
+-/* 20 stereo bands. */
+-
+-#include "FDK_bitstream.h"
+-
+-#define SCAL_HEADROOM (2)
+-
+-#define PS_EXTENSION_SIZE_BITS (4)
+-#define PS_EXTENSION_ESC_COUNT_BITS (8)
+-
+-#define NO_QMF_CHANNELS (64)
+-#define MAX_NUM_COL (32)
+-
+-#define NO_QMF_BANDS_HYBRID20 (3)
+-#define NO_SUB_QMF_CHANNELS (12)
+-#define HYBRID_FILTER_DELAY (6)
+-
+-#define MAX_NO_PS_ENV (4 + 1) /* +1 needed for VAR_BORDER */
+-
+-#define NO_HI_RES_BINS (34)
+-#define NO_MID_RES_BINS (20)
+-#define NO_LOW_RES_BINS (10)
+-
+-#define NO_HI_RES_IID_BINS (NO_HI_RES_BINS)
+-#define NO_HI_RES_ICC_BINS (NO_HI_RES_BINS)
+-
+-#define NO_MID_RES_IID_BINS (NO_MID_RES_BINS)
+-#define NO_MID_RES_ICC_BINS (NO_MID_RES_BINS)
+-
+-#define NO_LOW_RES_IID_BINS (NO_LOW_RES_BINS)
+-#define NO_LOW_RES_ICC_BINS (NO_LOW_RES_BINS)
+-
+-#define SUBQMF_GROUPS (10)
+-#define QMF_GROUPS (12)
+-
+-//#define SUBQMF_GROUPS_HI_RES ( 32 )
+-//#define QMF_GROUPS_HI_RES ( 18 )
+-
+-#define NO_IID_GROUPS (SUBQMF_GROUPS + QMF_GROUPS)
+-//#define NO_IID_GROUPS_HI_RES ( SUBQMF_GROUPS_HI_RES +
+-// QMF_GROUPS_HI_RES )
+-
+-#define NO_IID_STEPS (7) /* 1 .. + 7 */
+-#define NO_IID_STEPS_FINE (15) /* 1 .. +15 */
+-#define NO_ICC_STEPS (8) /* 0 .. + 7 */
+-
+-#define NO_IID_LEVELS (2 * NO_IID_STEPS + 1) /* - 7 .. + 7 */
+-#define NO_IID_LEVELS_FINE (2 * NO_IID_STEPS_FINE + 1) /* -15 .. +15 */
+-#define NO_ICC_LEVELS (NO_ICC_STEPS) /* 0 .. + 7 */
+-
+-#define FIXP_SQRT05 ((FIXP_DBL)0x5a827980) /* 1/SQRT2 */
+-
+-struct PS_DEC_COEFFICIENTS {
+- FIXP_DBL H11r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
+- FIXP_DBL H12r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
+- FIXP_DBL H21r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
+- FIXP_DBL H22r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
+-
+- FIXP_DBL
+- DeltaH11r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
+- FIXP_DBL
+- DeltaH12r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
+- FIXP_DBL
+- DeltaH21r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
+- FIXP_DBL
+- DeltaH22r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
+-
+- SCHAR
+- aaIidIndexMapped[MAX_NO_PS_ENV]
+- [NO_HI_RES_IID_BINS]; /*!< The mapped IID index for all
+- envelopes and all IID bins */
+- SCHAR
+- aaIccIndexMapped[MAX_NO_PS_ENV]
+- [NO_HI_RES_ICC_BINS]; /*!< The mapped ICC index for all
+- envelopes and all ICC bins */
+-};
+-
+-typedef enum { ppt_none = 0, ppt_mpeg = 1, ppt_drm = 2 } PS_PAYLOAD_TYPE;
+-
+-typedef struct {
+- UCHAR bPsHeaderValid; /*!< set if new header is available from bitstream */
+-
+- UCHAR bEnableIid; /*!< One bit denoting the presence of IID parameters */
+- UCHAR bEnableIcc; /*!< One bit denoting the presence of ICC parameters */
+- UCHAR bEnableExt; /*!< The PS extension layer is enabled using the enable_ext
+- bit. If it is set to %1 the IPD and OPD parameters are
+- sent. If it is disabled, i.e. %0, the extension layer is
+- skipped. */
+-
+- UCHAR
+- modeIid; /*!< The configuration of IID parameters (number of bands and
+- quantisation grid, iid_quant) is determined by iid_mode. */
+- UCHAR modeIcc; /*!< The configuration of Inter-channel Coherence parameters
+- (number of bands and quantisation grid) is determined by
+- icc_mode. */
+-
+- UCHAR freqResIid; /*!< 0=low, 1=mid or 2=high frequency resolution for iid */
+- UCHAR freqResIcc; /*!< 0=low, 1=mid or 2=high frequency resolution for icc */
+-
+- UCHAR bFineIidQ; /*!< Use fine Iid quantisation. */
+-
+- UCHAR bFrameClass; /*!< The frame_class bit determines whether the parameter
+- positions of the current frame are uniformly spaced
+- accross the frame or they are defined using the
+- positions described by border_position.
+- */
+-
+- UCHAR noEnv; /*!< The number of envelopes per frame */
+- UCHAR aEnvStartStop[MAX_NO_PS_ENV + 1]; /*!< In case of variable parameter
+- spacing the parameter positions are
+- determined by border_position */
+-
+- SCHAR abIidDtFlag[MAX_NO_PS_ENV]; /*!< Deltacoding time/freq flag for IID, 0
+- => freq */
+- SCHAR abIccDtFlag[MAX_NO_PS_ENV]; /*!< Deltacoding time/freq flag for ICC, 0
+- => freq */
+-
+- SCHAR
+- aaIidIndex[MAX_NO_PS_ENV]
+- [NO_HI_RES_IID_BINS]; /*!< The IID index for all envelopes and
+- all IID bins */
+- SCHAR
+- aaIccIndex[MAX_NO_PS_ENV]
+- [NO_HI_RES_ICC_BINS]; /*!< The ICC index for all envelopes and
+- all ICC bins */
+-
+-} MPEG_PS_BS_DATA;
+-
+-struct PS_DEC {
+- SCHAR noSubSamples;
+- SCHAR noChannels;
+-
+- SCHAR procFrameBased; /*!< Helper to detected switching from frame based to
+- slot based processing
+- */
+-
+- PS_PAYLOAD_TYPE
+- bPsDataAvail[(1) + 1]; /*!< set if new data available from bitstream */
+- UCHAR psDecodedPrv; /*!< set if PS has been processed in the last frame */
+-
+- /* helpers for frame delay line */
+- UCHAR bsLastSlot; /*!< Index of last read slot. */
+- UCHAR bsReadSlot; /*!< Index of current read slot for additional delay. */
+- UCHAR processSlot; /*!< Index of current slot for processing (need for add.
+- delay). */
+-
+- union { /* Bitstream data */
+- MPEG_PS_BS_DATA
+- mpeg; /*!< Struct containing all MPEG specific PS data from bitstream.
+- */
+- } bsData[(1) + 1];
+-
+- shouldBeUnion { /* Static data */
+- struct {
+- SCHAR aIidPrevFrameIndex[NO_HI_RES_IID_BINS]; /*!< The IID index for
+- previous frame */
+- SCHAR aIccPrevFrameIndex[NO_HI_RES_ICC_BINS]; /*!< The ICC index for
+- previous frame */
+- UCHAR
+- bPrevFrameFineIidQ; /*!< The IID quantization of the previous frame */
+- UCHAR prevFreqResIid; /*!< Frequency resolution for IID of the previous
+- frame */
+- UCHAR prevFreqResIcc; /*!< Frequency resolution for ICC of the previous
+- frame */
+- UCHAR lastUsb; /*!< uppermost WMF delay band of last frame */
+-
+- FIXP_DBL pHybridAnaStatesLFdmx
+- [2 * 13 * NO_QMF_BANDS_HYBRID20]; /*!< Memory used in hybrid analysis
+- for filter states. */
+- FDK_ANA_HYB_FILTER hybridAnalysis;
+- FDK_SYN_HYB_FILTER hybridSynthesis[2];
+-
+- DECORR_DEC apDecor; /*!< Decorrelator instance. */
+- FIXP_DBL decorrBufferCplx[(2 * ((825) + (373)))];
+-
+- FIXP_DBL h11rPrev[NO_IID_GROUPS]; /*!< previous calculated h(xy)
+- coefficients */
+- FIXP_DBL h12rPrev[NO_IID_GROUPS]; /*!< previous calculated h(xy)
+- coefficients */
+- FIXP_DBL h21rPrev[NO_IID_GROUPS]; /*!< previous calculated h(xy)
+- coefficients */
+- FIXP_DBL h22rPrev[NO_IID_GROUPS]; /*!< previous calculated h(xy)
+- coefficients */
+-
+- PS_DEC_COEFFICIENTS
+- *pCoef; /*!< temporal coefficients are on reusable scratch memory */
+-
+- } mpeg;
+- }
+- specificTo;
+-};
+-
+-typedef struct PS_DEC *HANDLE_PS_DEC;
+-
+-int CreatePsDec(HANDLE_PS_DEC *h_PS_DEC, int aacSamplesPerFrame);
+-
+-int DeletePsDec(HANDLE_PS_DEC *h_PS_DEC);
+-
+-void PreparePsProcessing(HANDLE_PS_DEC h_ps_d,
+- const FIXP_DBL *const *const rIntBufferLeft,
+- const FIXP_DBL *const *const iIntBufferLeft,
+- const int scaleFactorLowBand);
+-
+-void initSlotBasedRotation(HANDLE_PS_DEC h_ps_d, int env, int usb);
+-
+-void ApplyPsSlot(
+- HANDLE_PS_DEC h_ps_d, /* parametric stereo decoder handle */
+- FIXP_DBL **rIntBufferLeft, /* real values of left qmf timeslot */
+- FIXP_DBL **iIntBufferLeft, /* imag values of left qmf timeslot */
+- FIXP_DBL *rIntBufferRight, /* real values of right qmf timeslot */
+- FIXP_DBL *iIntBufferRight, /* imag values of right qmf timeslot */
+- const int scaleFactorLowBand_no_ov, const int scaleFactorLowBand,
+- const int scaleFactorHighBand, const int lsb, const int usb);
+-
+-#endif /* PSDEC_H */
+diff --git a/libSBRdec/src/psdec_drm.cpp b/libSBRdec/src/psdec_drm.cpp
+deleted file mode 100644
+index 6971f53..0000000
+--- a/libSBRdec/src/psdec_drm.cpp
++++ /dev/null
+@@ -1,108 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief parametric stereo decoder for Digital radio mondial
+-*/
+-
+-#include "psdec_drm.h"
+diff --git a/libSBRdec/src/psdec_drm.h b/libSBRdec/src/psdec_drm.h
+deleted file mode 100644
+index 5e2575d..0000000
+--- a/libSBRdec/src/psdec_drm.h
++++ /dev/null
+@@ -1,113 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief parametric stereo decoder for digital radio mondial
+-*/
+-
+-#ifndef PSDEC_DRM_H
+-#define PSDEC_DRM_H
+-
+-#include "sbrdecoder.h"
+-
+-#endif /* PSDEC_DRM_H */
+diff --git a/libSBRdec/src/psdecrom_drm.cpp b/libSBRdec/src/psdecrom_drm.cpp
+deleted file mode 100644
+index 2033a83..0000000
+--- a/libSBRdec/src/psdecrom_drm.cpp
++++ /dev/null
+@@ -1,108 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief rom tables for Drm parametric stereo decoder
+-*/
+-
+-#include "psdec_drm.h"
+diff --git a/libSBRdec/src/pvc_dec.cpp b/libSBRdec/src/pvc_dec.cpp
+deleted file mode 100644
+index b477122..0000000
+--- a/libSBRdec/src/pvc_dec.cpp
++++ /dev/null
+@@ -1,683 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s): Matthias Hildenbrand
+-
+- Description: Decode Predictive Vector Coding Data
+-
+-*******************************************************************************/
+-
+-#include "pvc_dec.h"
+-
+-/* PVC interal definitions */
+-#define PVC_DIVMODE_BITS 3
+-#define PVC_NSMODE_BITS 1
+-#define PVC_REUSEPVCID_BITS 1
+-#define PVC_PVCID_BITS 7
+-#define PVC_GRIDINFO_BITS 1
+-#define PVC_NQMFBAND 64
+-#define PVC_NBLOW 3 /* max. number of grouped QMF subbands below SBR range */
+-
+-#define PVC_NTAB1 3
+-#define PVC_NTAB2 128
+-#define PVC_ID_NBIT 7
+-
+-/* Exponent of pPvcStaticData->Esg and predictedEsg in dB domain.
+- max(Esg) = 10*log10(2^15*2^15) = 90.30;
+- min(Esg) = 10*log10(0.1) = -10
+- max of predicted Esg seems to be higher than 90dB but 7 Bit should be enough.
+-*/
+-#define PVC_ESG_EXP 7
+-
+-#define LOG10FAC 0.752574989159953f /* == 10/log2(10) * 2^-2 */
+-#define LOG10FAC_INV 0.664385618977472f /* == log2(10)/10 * 2^1 */
+-
+-RAM_ALIGN
+-LNK_SECTION_CONSTDATA
+-static const FIXP_SGL pvc_SC_16[] = {
+- FX_DBL2FXCONST_SGL(0x14413695), FX_DBL2FXCONST_SGL(0x1434b6cb),
+- FX_DBL2FXCONST_SGL(0x140f27c7), FX_DBL2FXCONST_SGL(0x13d0591d),
+- FX_DBL2FXCONST_SGL(0x1377f502), FX_DBL2FXCONST_SGL(0x130577d6),
+- FX_DBL2FXCONST_SGL(0x12782266), FX_DBL2FXCONST_SGL(0x11cee459),
+- FX_DBL2FXCONST_SGL(0x11083a2a), FX_DBL2FXCONST_SGL(0x1021f5e9),
+- FX_DBL2FXCONST_SGL(0x0f18e17c), FX_DBL2FXCONST_SGL(0x0de814ca),
+- FX_DBL2FXCONST_SGL(0x0c87a568), FX_DBL2FXCONST_SGL(0x0ae9b167),
+- FX_DBL2FXCONST_SGL(0x08f24226), FX_DBL2FXCONST_SGL(0x06575ed5),
+-};
+-
+-RAM_ALIGN
+-LNK_SECTION_CONSTDATA
+-static const FIXP_SGL pvc_SC_12[] = {
+- FX_DBL2FXCONST_SGL(0x1aba6b3e), FX_DBL2FXCONST_SGL(0x1a9d164e),
+- FX_DBL2FXCONST_SGL(0x1a44d56d), FX_DBL2FXCONST_SGL(0x19b0d742),
+- FX_DBL2FXCONST_SGL(0x18df969a), FX_DBL2FXCONST_SGL(0x17ce91a0),
+- FX_DBL2FXCONST_SGL(0x1679c3fa), FX_DBL2FXCONST_SGL(0x14daabfc),
+- FX_DBL2FXCONST_SGL(0x12e65221), FX_DBL2FXCONST_SGL(0x1088d125),
+- FX_DBL2FXCONST_SGL(0x0d9907b3), FX_DBL2FXCONST_SGL(0x09a80e9d),
+-};
+-
+-RAM_ALIGN
+-LNK_SECTION_CONSTDATA
+-static const FIXP_SGL pvc_SC_4[] = {
+- FX_DBL2FXCONST_SGL(0x4ad6ab0f),
+- FX_DBL2FXCONST_SGL(0x47ef0dbe),
+- FX_DBL2FXCONST_SGL(0x3eee7496),
+- FX_DBL2FXCONST_SGL(0x2e4bd29d),
+-};
+-
+-RAM_ALIGN
+-LNK_SECTION_CONSTDATA
+-static const FIXP_SGL pvc_SC_3[] = {
+- FX_DBL2FXCONST_SGL(0x610dc761),
+- FX_DBL2FXCONST_SGL(0x5a519a3d),
+- FX_DBL2FXCONST_SGL(0x44a09e62),
+-};
+-
+-static const UCHAR g_3a_pvcTab1_mode1[PVC_NTAB1][PVC_NBLOW][PVC_NBHIGH_MODE1] =
+- {{{0x4F, 0x5B, 0x57, 0x52, 0x4D, 0x65, 0x45, 0x57},
+- {0xF3, 0x0F, 0x18, 0x20, 0x19, 0x4F, 0x3D, 0x23},
+- {0x78, 0x57, 0x55, 0x50, 0x50, 0x20, 0x36, 0x37}},
+- {{0x4C, 0x5F, 0x53, 0x37, 0x1E, 0xFD, 0x15, 0x0A},
+- {0x05, 0x0E, 0x28, 0x41, 0x48, 0x6E, 0x54, 0x5B},
+- {0x59, 0x47, 0x40, 0x40, 0x3D, 0x33, 0x3F, 0x39}},
+- {{0x47, 0x5F, 0x57, 0x34, 0x3C, 0x2E, 0x2E, 0x31},
+- {0xFA, 0x13, 0x23, 0x4E, 0x44, 0x7C, 0x34, 0x38},
+- {0x63, 0x43, 0x41, 0x3D, 0x35, 0x19, 0x3D, 0x33}}};
+-
+-static const UCHAR g_2a_pvcTab2_mode1[PVC_NTAB2][PVC_NBHIGH_MODE1] = {
+- {0xCB, 0xD1, 0xCC, 0xD2, 0xE2, 0xEB, 0xE7, 0xE8},
+- {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
+- {0x84, 0x8C, 0x88, 0x83, 0x90, 0x93, 0x86, 0x80},
+- {0xD7, 0xD8, 0xC0, 0xC7, 0xCF, 0xE5, 0xF1, 0xF6},
+- {0xA5, 0xA6, 0xAA, 0xA8, 0xB0, 0xB1, 0xB8, 0xB8},
+- {0xD7, 0xCB, 0xC1, 0xC3, 0xC5, 0xC9, 0xC9, 0xCE},
+- {0xCA, 0xB5, 0xB8, 0xB3, 0xAC, 0xB6, 0xBB, 0xB8},
+- {0xC1, 0xC4, 0xC3, 0xC5, 0xC6, 0xCA, 0xCA, 0xCB},
+- {0xE0, 0xE1, 0xD8, 0xCD, 0xCB, 0xCB, 0xCE, 0xCC},
+- {0xDB, 0xE1, 0xDF, 0xDB, 0xDC, 0xD9, 0xD9, 0xD6},
+- {0xE0, 0xDE, 0xDD, 0xDD, 0xE0, 0xE3, 0xE5, 0xE6},
+- {0xCA, 0xD2, 0xCD, 0xCE, 0xD5, 0xDB, 0xD9, 0xDB},
+- {0xD2, 0xE0, 0xDB, 0xD5, 0xDB, 0xDE, 0xE3, 0xE1},
+- {0xE5, 0xDB, 0xD0, 0xD2, 0xD8, 0xDD, 0xDB, 0xDD},
+- {0xC0, 0xB5, 0xBF, 0xDD, 0xE3, 0xDC, 0xDC, 0xE4},
+- {0xDB, 0xCE, 0xC6, 0xCF, 0xCF, 0xD1, 0xD3, 0xD4},
+- {0xC9, 0xD7, 0xDA, 0xE2, 0xE9, 0xE7, 0xDF, 0xDC},
+- {0x0A, 0x07, 0x0A, 0x08, 0x19, 0x24, 0x1F, 0x22},
+- {0x1E, 0x1F, 0x11, 0x0E, 0x22, 0x2D, 0x33, 0x32},
+- {0xF0, 0xDA, 0xDC, 0x18, 0x1F, 0x19, 0x0A, 0x1E},
+- {0x09, 0xF8, 0xE6, 0x05, 0x19, 0x11, 0x0E, 0x0B},
+- {0x09, 0x10, 0x0E, 0xE6, 0xF4, 0x20, 0x22, 0xFA},
+- {0xF2, 0xE5, 0xF8, 0x0E, 0x18, 0x15, 0x0D, 0x10},
+- {0x15, 0x13, 0x16, 0x0A, 0x0D, 0x1F, 0x1D, 0x1B},
+- {0xFA, 0xFF, 0xFE, 0xFF, 0x09, 0x11, 0x03, 0x0B},
+- {0xFE, 0xFA, 0xF2, 0xF8, 0x0C, 0x1E, 0x11, 0x12},
+- {0xFA, 0xF8, 0x0B, 0x17, 0x1D, 0x17, 0x0E, 0x16},
+- {0x00, 0xF3, 0xFD, 0x0A, 0x1C, 0x17, 0xFD, 0x08},
+- {0xEA, 0xEA, 0x03, 0x12, 0x1E, 0x14, 0x09, 0x04},
+- {0x02, 0xFE, 0x04, 0xFB, 0x0C, 0x0E, 0x07, 0x02},
+- {0xF6, 0x02, 0x07, 0x0B, 0x17, 0x17, 0x01, 0xFF},
+- {0xF5, 0xFB, 0xFE, 0x04, 0x12, 0x14, 0x0C, 0x0D},
+- {0x10, 0x10, 0x0E, 0x04, 0x07, 0x11, 0x0F, 0x13},
+- {0x0C, 0x0F, 0xFB, 0xF2, 0x0A, 0x12, 0x09, 0x0D},
+- {0x0D, 0x1D, 0xF1, 0xF4, 0x2A, 0x06, 0x3B, 0x32},
+- {0xFC, 0x08, 0x06, 0x02, 0x0E, 0x17, 0x08, 0x0E},
+- {0x07, 0x02, 0xEE, 0xEE, 0x2B, 0xF6, 0x23, 0x13},
+- {0x04, 0x02, 0x05, 0x08, 0x0B, 0x0E, 0xFB, 0xFB},
+- {0x00, 0x04, 0x10, 0x18, 0x22, 0x25, 0x1D, 0x1F},
+- {0xFB, 0x0D, 0x07, 0x00, 0x0C, 0x0F, 0xFC, 0x02},
+- {0x00, 0x00, 0x00, 0x01, 0x05, 0x07, 0x03, 0x05},
+- {0x04, 0x05, 0x08, 0x13, 0xFF, 0xEB, 0x0C, 0x06},
+- {0x05, 0x13, 0x0E, 0x0B, 0x12, 0x15, 0x09, 0x0A},
+- {0x09, 0x03, 0x09, 0x05, 0x12, 0x16, 0x11, 0x12},
+- {0x14, 0x1A, 0x06, 0x01, 0x10, 0x11, 0xFE, 0x02},
+- {0x01, 0x0B, 0x0B, 0x0C, 0x18, 0x21, 0x10, 0x13},
+- {0x12, 0x0D, 0x0A, 0x10, 0x1C, 0x1D, 0x0D, 0x10},
+- {0x03, 0x09, 0x14, 0x15, 0x1B, 0x1A, 0x01, 0xFF},
+- {0x08, 0x12, 0x13, 0x0E, 0x16, 0x1D, 0x14, 0x1B},
+- {0x07, 0x15, 0x1C, 0x1B, 0x20, 0x21, 0x11, 0x0E},
+- {0x12, 0x18, 0x19, 0x17, 0x20, 0x25, 0x1A, 0x1E},
+- {0x0C, 0x1A, 0x1D, 0x22, 0x2F, 0x33, 0x27, 0x28},
+- {0x0E, 0x1A, 0x17, 0x10, 0x0A, 0x0E, 0xFF, 0x06},
+- {0x1A, 0x1C, 0x18, 0x14, 0x1A, 0x16, 0x0A, 0x0E},
+- {0x1E, 0x27, 0x25, 0x26, 0x27, 0x2A, 0x21, 0x21},
+- {0xF1, 0x0A, 0x16, 0x1C, 0x28, 0x25, 0x15, 0x19},
+- {0x08, 0x12, 0x09, 0x08, 0x16, 0x17, 0xEF, 0xF6},
+- {0x0C, 0x0B, 0x00, 0xFC, 0x04, 0x09, 0xFC, 0x03},
+- {0xFB, 0xF1, 0xF8, 0x26, 0x24, 0x18, 0x1D, 0x20},
+- {0xF9, 0x01, 0x0C, 0x0F, 0x07, 0x08, 0x06, 0x07},
+- {0x07, 0x06, 0x08, 0x04, 0x07, 0x0D, 0x07, 0x09},
+- {0xFE, 0x01, 0x06, 0x05, 0x13, 0x1B, 0x14, 0x19},
+- {0x09, 0x0C, 0x0E, 0x01, 0x08, 0x05, 0xFB, 0xFD},
+- {0x07, 0x06, 0x03, 0x0A, 0x16, 0x12, 0x04, 0x07},
+- {0x04, 0x01, 0x00, 0x04, 0x1F, 0x20, 0x0E, 0x0A},
+- {0x03, 0xFF, 0xF6, 0xFB, 0x15, 0x1A, 0x00, 0x03},
+- {0xFC, 0x18, 0x0B, 0x2D, 0x35, 0x23, 0x12, 0x09},
+- {0x02, 0xFE, 0x01, 0xFF, 0x0C, 0x11, 0x0D, 0x0F},
+- {0xFA, 0xE9, 0xD9, 0xFF, 0x0D, 0x05, 0x0D, 0x10},
+- {0xF1, 0xE0, 0xF0, 0x01, 0x06, 0x06, 0x06, 0x10},
+- {0xE9, 0xD4, 0xD7, 0x0F, 0x14, 0x0B, 0x0D, 0x16},
+- {0x00, 0xFF, 0xEE, 0xE5, 0xFF, 0x08, 0x02, 0xF9},
+- {0xE0, 0xDA, 0xE5, 0xFE, 0x09, 0x02, 0xF9, 0x04},
+- {0xE0, 0xE2, 0xF4, 0x09, 0x13, 0x0C, 0x0D, 0x09},
+- {0xFC, 0x02, 0x04, 0xFF, 0x00, 0xFF, 0xF8, 0xF7},
+- {0xFE, 0xFB, 0xED, 0xF2, 0xFE, 0xFE, 0x08, 0x0C},
+- {0xF3, 0xEF, 0xD0, 0xE3, 0x05, 0x11, 0xFD, 0xFF},
+- {0xFA, 0xEF, 0xEA, 0xFE, 0x0D, 0x0E, 0xFE, 0x02},
+- {0xF7, 0xFB, 0xDB, 0xDF, 0x14, 0xDD, 0x07, 0xFE},
+- {0xFE, 0x08, 0x00, 0xDB, 0xE5, 0x1A, 0x13, 0xED},
+- {0xF9, 0xFE, 0xFF, 0xF4, 0xF3, 0x00, 0x05, 0x02},
+- {0xEF, 0xDE, 0xD8, 0xEB, 0xEA, 0xF5, 0x0E, 0x19},
+- {0xFB, 0xFC, 0xFA, 0xEC, 0xEB, 0xED, 0xEE, 0xE8},
+- {0xEE, 0xFC, 0xFD, 0x00, 0x04, 0xFC, 0xF0, 0xF5},
+- {0x00, 0xFA, 0xF4, 0xF1, 0xF5, 0xFA, 0xFB, 0xF9},
+- {0xEB, 0xF0, 0xDF, 0xE3, 0xEF, 0x07, 0x02, 0x05},
+- {0xF7, 0xF0, 0xE6, 0xE7, 0x06, 0x15, 0x06, 0x0C},
+- {0xF1, 0xE4, 0xD8, 0xEA, 0x06, 0xF2, 0x07, 0x09},
+- {0xFF, 0xFE, 0xFE, 0xF9, 0xFF, 0xFF, 0x02, 0xF9},
+- {0xDD, 0xF4, 0xF0, 0xF1, 0xFF, 0xFF, 0xEA, 0xF1},
+- {0xF0, 0xF1, 0xFD, 0x03, 0x03, 0xFE, 0x00, 0x05},
+- {0xF1, 0xF6, 0xE0, 0xDF, 0xF5, 0x01, 0xF4, 0xF8},
+- {0x02, 0x03, 0xE5, 0xDC, 0xE7, 0xFD, 0x02, 0x08},
+- {0xEC, 0xF1, 0xF5, 0xEC, 0xF2, 0xF8, 0xF6, 0xEE},
+- {0xF3, 0xF4, 0xF6, 0xF4, 0xF5, 0xF1, 0xE7, 0xEA},
+- {0xF7, 0xF3, 0xEC, 0xEA, 0xEF, 0xF0, 0xEE, 0xF1},
+- {0xEB, 0xF6, 0xFB, 0xFA, 0xEF, 0xF3, 0xF3, 0xF7},
+- {0x01, 0x03, 0xF1, 0xF6, 0x05, 0xF8, 0xE1, 0xEB},
+- {0xF5, 0xF6, 0xF6, 0xF4, 0xFB, 0xFB, 0xFF, 0x00},
+- {0xF8, 0x01, 0xFB, 0xFA, 0xFF, 0x03, 0xFE, 0x04},
+- {0x04, 0xFB, 0x03, 0xFD, 0xF5, 0xF7, 0xF6, 0xFB},
+- {0x06, 0x09, 0xFB, 0xF4, 0xF9, 0xFA, 0xFC, 0xFF},
+- {0xF5, 0xF6, 0xF1, 0xEE, 0xF5, 0xF8, 0xF5, 0xF9},
+- {0xF5, 0xF9, 0xFA, 0xFC, 0x07, 0x09, 0x01, 0xFB},
+- {0xD7, 0xE9, 0xE8, 0xEC, 0x00, 0x0C, 0xFE, 0xF1},
+- {0xEC, 0x04, 0xE9, 0xDF, 0x03, 0xE8, 0x00, 0xFA},
+- {0xE6, 0xE2, 0xFF, 0x0A, 0x13, 0x01, 0x00, 0xF7},
+- {0xF1, 0xFA, 0xF7, 0xF5, 0x01, 0x06, 0x05, 0x0A},
+- {0xF6, 0xF6, 0xFC, 0xF6, 0xE8, 0x11, 0xF2, 0xFE},
+- {0xFE, 0x08, 0x05, 0x12, 0xFD, 0xD0, 0x0E, 0x07},
+- {0xF1, 0xFE, 0xF7, 0xF2, 0xFB, 0x02, 0xFA, 0xF8},
+- {0xF4, 0xEA, 0xEC, 0xF3, 0xFE, 0x01, 0xF7, 0xF6},
+- {0xFF, 0xFA, 0xFB, 0xF9, 0xFF, 0x01, 0x04, 0x03},
+- {0x00, 0xF9, 0xF4, 0xFC, 0x05, 0xFC, 0xF7, 0xFB},
+- {0xF8, 0xFF, 0xEF, 0xEC, 0xFB, 0x04, 0xF8, 0x03},
+- {0xEB, 0xF1, 0xED, 0xF4, 0x02, 0x0E, 0x0B, 0x04},
+- {0xF7, 0x01, 0xF8, 0xF4, 0xF8, 0xEF, 0xF8, 0x04},
+- {0xEB, 0xF0, 0xF7, 0xFC, 0x10, 0x0D, 0xF8, 0xF8},
+- {0xE8, 0xFE, 0xEE, 0xE8, 0xED, 0xF7, 0xF5, 0xF8},
+- {0xED, 0xEB, 0xE9, 0xEA, 0xF2, 0xF5, 0xF4, 0xF9},
+- {0xEA, 0xF2, 0xEF, 0xEE, 0xF9, 0xFE, 0xFD, 0x02},
+- {0xFA, 0xFD, 0x02, 0x0D, 0xFA, 0xE4, 0x0F, 0x01},
+- {0xFF, 0x08, 0x05, 0xF6, 0xF7, 0xFB, 0xF1, 0xF1},
+- {0xF4, 0xEC, 0xEE, 0xF6, 0xEE, 0xEE, 0xF8, 0x06},
+- {0xE8, 0xFA, 0xF8, 0xE8, 0xF8, 0xE9, 0xEE, 0xF9},
+- {0xE5, 0xE9, 0xF0, 0x00, 0x00, 0xEF, 0xF3, 0xF8},
+- {0xF7, 0xFB, 0xFB, 0xF7, 0xF9, 0xF9, 0xF5, 0xF0},
+- {0xFD, 0xFF, 0xF2, 0xEE, 0xF2, 0xF5, 0xF1, 0xF3}};
+-
+-static const UCHAR g_3a_pvcTab1_mode2[PVC_NTAB1][PVC_NBLOW][PVC_NBHIGH_MODE2] =
+- {{{0x11, 0x27, 0x0F, 0xFD, 0x04, 0xFC},
+- {0x00, 0xBE, 0xE3, 0xF4, 0xDB, 0xF0},
+- {0x09, 0x1E, 0x18, 0x1A, 0x21, 0x1B}},
+- {{0x16, 0x28, 0x2B, 0x29, 0x25, 0x32},
+- {0xF2, 0xE9, 0xE4, 0xE5, 0xE2, 0xD4},
+- {0x0E, 0x0B, 0x0C, 0x0D, 0x0D, 0x0E}},
+- {{0x2E, 0x3C, 0x20, 0x16, 0x1B, 0x1A},
+- {0xE4, 0xC6, 0xE5, 0xF4, 0xDC, 0xDC},
+- {0x0F, 0x1B, 0x18, 0x14, 0x1E, 0x1A}}};
+-
+-static const UCHAR g_2a_pvcTab2_mode2[PVC_NTAB2][PVC_NBHIGH_MODE2] = {
+- {0x26, 0x25, 0x11, 0x0C, 0xFA, 0x15}, {0x1B, 0x18, 0x11, 0x0E, 0x0E, 0x0E},
+- {0x12, 0x10, 0x10, 0x10, 0x11, 0x10}, {0x1E, 0x24, 0x19, 0x15, 0x14, 0x12},
+- {0x24, 0x16, 0x12, 0x13, 0x15, 0x1C}, {0xEA, 0xED, 0xEB, 0xEA, 0xEC, 0xEB},
+- {0xFC, 0xFD, 0xFD, 0xFC, 0xFE, 0xFE}, {0x0F, 0x0C, 0x0B, 0x0A, 0x0B, 0x0B},
+- {0x22, 0x0B, 0x16, 0x18, 0x13, 0x19}, {0x1C, 0x14, 0x1D, 0x20, 0x19, 0x1A},
+- {0x10, 0x08, 0x00, 0xFF, 0x02, 0x05}, {0x06, 0x07, 0x05, 0x03, 0x05, 0x04},
+- {0x2A, 0x1F, 0x12, 0x12, 0x11, 0x18}, {0x19, 0x19, 0x02, 0x04, 0x00, 0x04},
+- {0x18, 0x17, 0x17, 0x15, 0x16, 0x15}, {0x21, 0x1E, 0x1B, 0x19, 0x1C, 0x1B},
+- {0x3C, 0x35, 0x20, 0x1D, 0x30, 0x34}, {0x3A, 0x1F, 0x37, 0x38, 0x33, 0x31},
+- {0x37, 0x34, 0x25, 0x27, 0x35, 0x34}, {0x34, 0x2E, 0x32, 0x31, 0x34, 0x31},
+- {0x36, 0x33, 0x2F, 0x2F, 0x32, 0x2F}, {0x35, 0x20, 0x2F, 0x32, 0x2F, 0x2C},
+- {0x2E, 0x2B, 0x2F, 0x34, 0x36, 0x30}, {0x3F, 0x39, 0x30, 0x28, 0x29, 0x29},
+- {0x3C, 0x30, 0x32, 0x37, 0x39, 0x36}, {0x37, 0x36, 0x30, 0x2B, 0x26, 0x24},
+- {0x44, 0x38, 0x2F, 0x2D, 0x2D, 0x2D}, {0x38, 0x2B, 0x2C, 0x2C, 0x30, 0x2D},
+- {0x37, 0x36, 0x2F, 0x23, 0x2D, 0x32}, {0x3C, 0x39, 0x29, 0x2E, 0x38, 0x37},
+- {0x3B, 0x3A, 0x35, 0x32, 0x31, 0x2D}, {0x32, 0x31, 0x2F, 0x2C, 0x2D, 0x28},
+- {0x2C, 0x31, 0x32, 0x30, 0x32, 0x2D}, {0x35, 0x34, 0x34, 0x34, 0x35, 0x33},
+- {0x34, 0x38, 0x3B, 0x3C, 0x3E, 0x3A}, {0x3E, 0x3C, 0x3B, 0x3A, 0x3C, 0x39},
+- {0x3D, 0x41, 0x46, 0x41, 0x3D, 0x38}, {0x44, 0x41, 0x40, 0x3E, 0x3F, 0x3A},
+- {0x47, 0x47, 0x47, 0x42, 0x44, 0x40}, {0x4C, 0x4A, 0x4A, 0x46, 0x49, 0x45},
+- {0x53, 0x52, 0x52, 0x4C, 0x4E, 0x49}, {0x41, 0x3D, 0x39, 0x2C, 0x2E, 0x2E},
+- {0x2D, 0x37, 0x36, 0x30, 0x28, 0x36}, {0x3B, 0x32, 0x2E, 0x2D, 0x2D, 0x29},
+- {0x40, 0x39, 0x36, 0x35, 0x36, 0x32}, {0x30, 0x2D, 0x2D, 0x2E, 0x31, 0x30},
+- {0x38, 0x3D, 0x3B, 0x37, 0x35, 0x34}, {0x44, 0x3D, 0x3C, 0x38, 0x37, 0x33},
+- {0x3A, 0x36, 0x37, 0x37, 0x39, 0x36}, {0x32, 0x36, 0x37, 0x30, 0x2E, 0x2A},
+- {0x3C, 0x33, 0x33, 0x31, 0x33, 0x30}, {0x30, 0x31, 0x36, 0x37, 0x38, 0x34},
+- {0x26, 0x27, 0x2E, 0x29, 0x1C, 0x16}, {0x14, 0x15, 0x1F, 0x17, 0x15, 0x1C},
+- {0x38, 0x2D, 0x18, 0x13, 0x1E, 0x2B}, {0x30, 0x22, 0x17, 0x1A, 0x26, 0x2B},
+- {0x24, 0x20, 0x1F, 0x10, 0x0C, 0x11}, {0x27, 0x1F, 0x13, 0x17, 0x24, 0x2A},
+- {0x2F, 0x13, 0x18, 0x13, 0x2A, 0x32}, {0x31, 0x1E, 0x1E, 0x1E, 0x21, 0x28},
+- {0x2A, 0x12, 0x19, 0x17, 0x16, 0x24}, {0x27, 0x0F, 0x16, 0x1D, 0x17, 0x1C},
+- {0x2F, 0x26, 0x25, 0x22, 0x20, 0x22}, {0x1E, 0x1B, 0x1E, 0x18, 0x1E, 0x24},
+- {0x31, 0x26, 0x0E, 0x15, 0x15, 0x25}, {0x2D, 0x22, 0x1E, 0x14, 0x10, 0x22},
+- {0x25, 0x1B, 0x18, 0x11, 0x13, 0x1F}, {0x2F, 0x1B, 0x13, 0x1B, 0x18, 0x22},
+- {0x21, 0x24, 0x1D, 0x1C, 0x1D, 0x1B}, {0x23, 0x1E, 0x28, 0x29, 0x27, 0x25},
+- {0x2E, 0x2A, 0x1D, 0x17, 0x26, 0x2D}, {0x31, 0x2C, 0x1A, 0x0E, 0x1A, 0x24},
+- {0x26, 0x16, 0x20, 0x1D, 0x14, 0x1E}, {0x29, 0x20, 0x1B, 0x1B, 0x17, 0x17},
+- {0x1D, 0x06, 0x1A, 0x1E, 0x1B, 0x1D}, {0x2B, 0x23, 0x1F, 0x1F, 0x1D, 0x1C},
+- {0x27, 0x1A, 0x0C, 0x0E, 0x0F, 0x1A}, {0x29, 0x1D, 0x1E, 0x22, 0x22, 0x24},
+- {0x20, 0x21, 0x1B, 0x18, 0x13, 0x21}, {0x27, 0x0E, 0x10, 0x14, 0x10, 0x1A},
+- {0x26, 0x24, 0x25, 0x25, 0x26, 0x28}, {0x1A, 0x24, 0x25, 0x29, 0x26, 0x24},
+- {0x1D, 0x1D, 0x15, 0x12, 0x0F, 0x18}, {0x1E, 0x14, 0x13, 0x12, 0x14, 0x18},
+- {0x16, 0x13, 0x13, 0x1A, 0x1B, 0x1D}, {0x20, 0x27, 0x22, 0x24, 0x1A, 0x19},
+- {0x1F, 0x17, 0x19, 0x18, 0x17, 0x18}, {0x20, 0x1B, 0x1C, 0x1C, 0x1B, 0x1A},
+- {0x23, 0x19, 0x1D, 0x1F, 0x1E, 0x21}, {0x26, 0x1F, 0x1D, 0x1B, 0x19, 0x1A},
+- {0x23, 0x1E, 0x1F, 0x20, 0x1F, 0x1E}, {0x29, 0x20, 0x22, 0x20, 0x20, 0x1F},
+- {0x26, 0x23, 0x21, 0x22, 0x23, 0x23}, {0x29, 0x1F, 0x24, 0x25, 0x26, 0x29},
+- {0x2B, 0x22, 0x25, 0x27, 0x23, 0x21}, {0x29, 0x21, 0x19, 0x0E, 0x22, 0x2D},
+- {0x32, 0x29, 0x1F, 0x1C, 0x1B, 0x21}, {0x1E, 0x1A, 0x1E, 0x24, 0x25, 0x25},
+- {0x24, 0x1D, 0x21, 0x22, 0x22, 0x25}, {0x2C, 0x25, 0x21, 0x22, 0x23, 0x25},
+- {0x24, 0x1E, 0x21, 0x26, 0x2B, 0x2C}, {0x28, 0x24, 0x1B, 0x1F, 0x28, 0x2D},
+- {0x23, 0x13, 0x16, 0x22, 0x22, 0x29}, {0x1B, 0x23, 0x1C, 0x20, 0x14, 0x0D},
+- {0x1E, 0x16, 0x1A, 0x1E, 0x1C, 0x1D}, {0x2B, 0x1C, 0x1D, 0x20, 0x1B, 0x1C},
+- {0x1C, 0x1B, 0x23, 0x1F, 0x19, 0x1E}, {0x21, 0x23, 0x26, 0x20, 0x20, 0x22},
+- {0x1D, 0x0B, 0x19, 0x1E, 0x11, 0x19}, {0x18, 0x17, 0x16, 0x17, 0x14, 0x16},
+- {0x16, 0x19, 0x1C, 0x20, 0x21, 0x22}, {0x30, 0x1E, 0x22, 0x24, 0x25, 0x26},
+- {0x1B, 0x1F, 0x17, 0x1D, 0x1E, 0x21}, {0x32, 0x2B, 0x27, 0x1F, 0x1B, 0x1A},
+- {0x28, 0x20, 0x1A, 0x1B, 0x1F, 0x23}, {0x32, 0x21, 0x20, 0x21, 0x1D, 0x1F},
+- {0x22, 0x18, 0x12, 0x15, 0x1B, 0x20}, {0x27, 0x27, 0x2A, 0x24, 0x21, 0x21},
+- {0x1E, 0x0F, 0x0D, 0x1A, 0x1D, 0x23}, {0x28, 0x25, 0x27, 0x21, 0x17, 0x25},
+- {0x2B, 0x27, 0x23, 0x19, 0x13, 0x14}, {0x25, 0x2B, 0x22, 0x22, 0x20, 0x21},
+- {0x27, 0x1B, 0x16, 0x17, 0x0F, 0x15}, {0x29, 0x26, 0x23, 0x15, 0x1E, 0x28},
+- {0x24, 0x1C, 0x19, 0x1A, 0x18, 0x19}, {0x2D, 0x15, 0x27, 0x2B, 0x24, 0x23},
+- {0x2C, 0x12, 0x1F, 0x23, 0x1F, 0x20}, {0x25, 0x0F, 0x22, 0x27, 0x1F, 0x21}};
+-
+-static const UCHAR g_a_pvcTab1_dp_mode1[PVC_NTAB1 - 1] = {17, 68};
+-static const UCHAR g_a_pvcTab1_dp_mode2[PVC_NTAB1 - 1] = {16, 52};
+-/* fractional exponent which corresponds to Q representation value */
+-static const SCHAR g_a_scalingCoef_mode1[PVC_NBLOW + 1] = {
+- -1, -1, 0, 6}; /* { 8, 8, 7, 1 }; Q scaling */
+-static const SCHAR g_a_scalingCoef_mode2[PVC_NBLOW + 1] = {
+- 0, 0, 1, 7}; /* { 7, 7, 6, 0 }; Q scaling */
+-
+-int pvcInitFrame(PVC_STATIC_DATA *pPvcStaticData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData, const UCHAR pvcMode,
+- const UCHAR ns, const int RATE, const int kx,
+- const int pvcBorder0, const UCHAR *pPvcID) {
+- int lbw, hbw, i, temp;
+- pPvcDynamicData->pvc_mode = pvcMode;
+- pPvcDynamicData->kx = kx;
+- pPvcDynamicData->RATE = RATE;
+-
+- switch (pvcMode) {
+- case 0:
+- /* legacy SBR, nothing to do */
+- return 0;
+- case 1:
+- pPvcDynamicData->nbHigh = 8;
+- pPvcDynamicData->pPVCTab1 = (const UCHAR *)g_3a_pvcTab1_mode1;
+- pPvcDynamicData->pPVCTab2 = (const UCHAR *)g_2a_pvcTab2_mode1;
+- pPvcDynamicData->pPVCTab1_dp = g_a_pvcTab1_dp_mode1;
+- pPvcDynamicData->pScalingCoef = g_a_scalingCoef_mode1;
+- hbw = 8 / RATE;
+- break;
+- case 2:
+- pPvcDynamicData->nbHigh = 6;
+- pPvcDynamicData->pPVCTab1 = (const UCHAR *)g_3a_pvcTab1_mode2;
+- pPvcDynamicData->pPVCTab2 = (const UCHAR *)g_2a_pvcTab2_mode2;
+- pPvcDynamicData->pPVCTab1_dp = g_a_pvcTab1_dp_mode2;
+- pPvcDynamicData->pScalingCoef = g_a_scalingCoef_mode2;
+- hbw = 12 / RATE;
+- break;
+- default:
+- /* invalid pvcMode */
+- return 1;
+- }
+-
+- pPvcDynamicData->pvcBorder0 = pvcBorder0;
+- UCHAR pvcBorder0_last = pPvcStaticData->pvcBorder0;
+- pPvcStaticData->pvcBorder0 = pvcBorder0;
+- pPvcDynamicData->pPvcID = pPvcID;
+-
+- pPvcDynamicData->ns = ns;
+- switch (ns) {
+- case 16:
+- pPvcDynamicData->pSCcoeffs = pvc_SC_16;
+- break;
+- case 12:
+- pPvcDynamicData->pSCcoeffs = pvc_SC_12;
+- break;
+- case 4:
+- pPvcDynamicData->pSCcoeffs = pvc_SC_4;
+- break;
+- case 3:
+- pPvcDynamicData->pSCcoeffs = pvc_SC_3;
+- break;
+- default:
+- return 1;
+- }
+-
+- /* in the lower part of Esg-array there are previous values of Esg (from last
+- call to this function In case of an previous legay-SBR frame, or if there
+- was a change in cross-over FQ the value of first PVC SBR timeslot is
+- propagated to prev-values in order to have reasonable values for
+- smooth-filtering
+- */
+- if ((pPvcStaticData->pvc_mode_last == 0) || (pPvcStaticData->kx_last != kx)) {
+- pPvcDynamicData->pastEsgSlotsAvail = 0;
+- } else {
+- pPvcDynamicData->pastEsgSlotsAvail = PVC_NS_MAX - pvcBorder0_last;
+- }
+-
+- lbw = 8 / RATE;
+-
+- temp = kx;
+- for (i = PVC_NBLOW; i >= 0; i--) {
+- pPvcDynamicData->sg_offset_low[i] = temp;
+- temp -= lbw;
+- }
+-
+- temp = 0;
+- for (i = 0; i <= pPvcDynamicData->nbHigh; i++) {
+- pPvcDynamicData->sg_offset_high_kx[i] = temp;
+- temp += hbw;
+- }
+-
+- return 0;
+-}
+-
+-/* call if pvcMode = 1,2 */
+-void pvcDecodeFrame(PVC_STATIC_DATA *pPvcStaticData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData, FIXP_DBL **qmfBufferReal,
+- FIXP_DBL **qmfBufferImag, const int overlap,
+- const int qmfExponentOverlap,
+- const int qmfExponentCurrent) {
+- int t;
+- FIXP_DBL *predictedEsgSlot;
+- int RATE = pPvcDynamicData->RATE;
+- int pvcBorder0 = pPvcDynamicData->pvcBorder0;
+-
+- for (t = pvcBorder0; t < PVC_NTIMESLOT; t++) {
+- int *pPredEsg_exp = &pPvcDynamicData->predEsg_exp[t];
+- predictedEsgSlot = pPvcDynamicData->predEsg[t];
+-
+- pvcDecodeTimeSlot(
+- pPvcStaticData, pPvcDynamicData, &qmfBufferReal[t * RATE],
+- &qmfBufferImag[t * RATE],
+- (t * RATE < overlap) ? qmfExponentOverlap : qmfExponentCurrent,
+- pvcBorder0, t, predictedEsgSlot, pPredEsg_exp);
+- }
+-
+- return;
+-}
+-
+-void pvcDecodeTimeSlot(PVC_STATIC_DATA *pPvcStaticData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData,
+- FIXP_DBL **qmfSlotReal, FIXP_DBL **qmfSlotImag,
+- const int qmfExponent, const int pvcBorder0,
+- const int timeSlotNumber, FIXP_DBL predictedEsgSlot[],
+- int *predictedEsg_exp) {
+- int i, band, ksg, ksg_start = 0;
+- int RATE = pPvcDynamicData->RATE;
+- int Esg_index = pPvcStaticData->Esg_slot_index;
+- const SCHAR *sg_borders = pPvcDynamicData->sg_offset_low;
+- FIXP_DBL *pEsg = pPvcStaticData->Esg[Esg_index];
+- FIXP_DBL E[PVC_NBLOW] = {0};
+-
+- /* Subband grouping in QMF subbands below SBR range */
+- /* Within one timeslot ( i = [0...(RATE-1)] QMF subsamples) calculate energy
+- E(ib,t) and group them to Esg(ksg,t). Then transfer values to logarithmical
+- domain and store them for time domain smoothing. (7.5.6.3 Subband grouping
+- in QMF subbands below SBR range)
+- */
+- for (ksg = 0; sg_borders[ksg] < 0; ksg++) {
+- pEsg[ksg] = FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)); /* 10*log10(0.1) */
+- ksg_start++;
+- }
+-
+- for (i = 0; i < RATE; i++) {
+- FIXP_DBL *qmfR, *qmfI;
+- qmfR = qmfSlotReal[i];
+- qmfI = qmfSlotImag[i];
+- for (ksg = ksg_start; ksg < PVC_NBLOW; ksg++) {
+- for (band = sg_borders[ksg]; band < sg_borders[ksg + 1]; band++) {
+- /* The division by 8 == (RATE*lbw) is required algorithmically */
+- E[ksg] += (fPow2Div2(qmfR[band]) + fPow2Div2(qmfI[band])) >> 2;
+- }
+- }
+- }
+- for (ksg = ksg_start; ksg < PVC_NBLOW; ksg++) {
+- if (E[ksg] > (FIXP_DBL)0) {
+- /* 10/log2(10) = 0.752574989159953 * 2^2 */
+- int exp_log;
+- FIXP_DBL nrg = CalcLog2(E[ksg], 2 * qmfExponent, &exp_log);
+- nrg = fMult(nrg, FL2FXCONST_SGL(LOG10FAC));
+- nrg = scaleValue(nrg, exp_log - PVC_ESG_EXP + 2);
+- pEsg[ksg] = fMax(nrg, FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)));
+- } else {
+- pEsg[ksg] =
+- FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)); /* 10*log10(0.1) */
+- }
+- }
+-
+- /* Time domain smoothing of subband-grouped energy */
+- {
+- int idx = pPvcStaticData->Esg_slot_index;
+- FIXP_DBL *pEsg_filt;
+- FIXP_SGL SCcoeff;
+-
+- E[0] = E[1] = E[2] = (FIXP_DBL)0;
+- for (i = 0; i < pPvcDynamicData->ns; i++) {
+- SCcoeff = pPvcDynamicData->pSCcoeffs[i];
+- pEsg_filt = pPvcStaticData->Esg[idx];
+- /* Div2 is compensated by scaling of coeff table */
+- E[0] = fMultAddDiv2(E[0], pEsg_filt[0], SCcoeff);
+- E[1] = fMultAddDiv2(E[1], pEsg_filt[1], SCcoeff);
+- E[2] = fMultAddDiv2(E[2], pEsg_filt[2], SCcoeff);
+- if (i >= pPvcDynamicData->pastEsgSlotsAvail) {
+- /* if past Esg values are not available use the ones from the last valid
+- * slot */
+- continue;
+- }
+- if (idx > 0) {
+- idx--;
+- } else {
+- idx += PVC_NS_MAX - 1;
+- }
+- }
+- }
+-
+- /* SBR envelope scalefactor prediction */
+- {
+- int E_high_exp[PVC_NBHIGH_MAX];
+- int E_high_exp_max = 0;
+- int pvcTab1ID;
+- int pvcTab2ID = (int)pPvcDynamicData->pPvcID[timeSlotNumber];
+- const UCHAR *pTab1, *pTab2;
+- if (pvcTab2ID < pPvcDynamicData->pPVCTab1_dp[0]) {
+- pvcTab1ID = 0;
+- } else if (pvcTab2ID < pPvcDynamicData->pPVCTab1_dp[1]) {
+- pvcTab1ID = 1;
+- } else {
+- pvcTab1ID = 2;
+- }
+- pTab1 = &(pPvcDynamicData
+- ->pPVCTab1[pvcTab1ID * PVC_NBLOW * pPvcDynamicData->nbHigh]);
+- pTab2 = &(pPvcDynamicData->pPVCTab2[pvcTab2ID * pPvcDynamicData->nbHigh]);
+- for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
+- FIXP_SGL predCoeff;
+- FIXP_DBL accu;
+- int predCoeff_exp, kb;
+- E_high_exp[ksg] = 0;
+-
+- /* residual part */
+- accu = ((LONG)(SCHAR)*pTab2++) << (DFRACT_BITS - 8 - PVC_ESG_EXP +
+- pPvcDynamicData->pScalingCoef[3]);
+-
+- /* linear combination of lower grouped energies part */
+- for (kb = 0; kb < PVC_NBLOW; kb++) {
+- predCoeff = (FIXP_SGL)(
+- (SHORT)(SCHAR)pTab1[kb * pPvcDynamicData->nbHigh + ksg] << 8);
+- predCoeff_exp = pPvcDynamicData->pScalingCoef[kb] +
+- 1; /* +1 to compensate for Div2 */
+- accu += fMultDiv2(E[kb], predCoeff) << predCoeff_exp;
+- }
+- /* convert back to linear domain */
+- accu = fMult(accu, FL2FXCONST_SGL(LOG10FAC_INV));
+- accu = f2Pow(
+- accu, PVC_ESG_EXP - 1,
+- &predCoeff_exp); /* -1 compensates for exponent of LOG10FAC_INV */
+- predictedEsgSlot[ksg] = accu;
+- E_high_exp[ksg] = predCoeff_exp;
+- if (predCoeff_exp > E_high_exp_max) {
+- E_high_exp_max = predCoeff_exp;
+- }
+- }
+-
+- /* rescale output vector according to largest exponent */
+- for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
+- int scale = E_high_exp[ksg] - E_high_exp_max;
+- predictedEsgSlot[ksg] = scaleValue(predictedEsgSlot[ksg], scale);
+- }
+- *predictedEsg_exp = E_high_exp_max;
+- }
+-
+- pPvcStaticData->Esg_slot_index =
+- (pPvcStaticData->Esg_slot_index + 1) & (PVC_NS_MAX - 1);
+- pPvcDynamicData->pastEsgSlotsAvail =
+- fMin(pPvcDynamicData->pastEsgSlotsAvail + 1, PVC_NS_MAX - 1);
+- return;
+-}
+-
+-/* call if pvcMode = 0,1,2 */
+-void pvcEndFrame(PVC_STATIC_DATA *pPvcStaticData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData) {
+- pPvcStaticData->pvc_mode_last = pPvcDynamicData->pvc_mode;
+- pPvcStaticData->kx_last = pPvcDynamicData->kx;
+-
+- if (pPvcDynamicData->pvc_mode == 0) return;
+-
+- {
+- int t, max = -100;
+- for (t = pPvcDynamicData->pvcBorder0; t < PVC_NTIMESLOT; t++) {
+- if (pPvcDynamicData->predEsg_exp[t] > max) {
+- max = pPvcDynamicData->predEsg_exp[t];
+- }
+- }
+- pPvcDynamicData->predEsg_expMax = max;
+- }
+- return;
+-}
+-
+-void expandPredEsg(const PVC_DYNAMIC_DATA *pPvcDynamicData, const int timeSlot,
+- const int lengthOutputVector, FIXP_DBL *pOutput,
+- SCHAR *pOutput_exp) {
+- int k = 0, ksg;
+- const FIXP_DBL *predEsg = pPvcDynamicData->predEsg[timeSlot];
+-
+- for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
+- for (; k < pPvcDynamicData->sg_offset_high_kx[ksg + 1]; k++) {
+- pOutput[k] = predEsg[ksg];
+- pOutput_exp[k] = (SCHAR)pPvcDynamicData->predEsg_exp[timeSlot];
+- }
+- }
+- ksg--;
+- for (; k < lengthOutputVector; k++) {
+- pOutput[k] = predEsg[ksg];
+- pOutput_exp[k] = (SCHAR)pPvcDynamicData->predEsg_exp[timeSlot];
+- }
+-
+- return;
+-}
+diff --git a/libSBRdec/src/pvc_dec.h b/libSBRdec/src/pvc_dec.h
+deleted file mode 100644
+index f5a467f..0000000
+--- a/libSBRdec/src/pvc_dec.h
++++ /dev/null
+@@ -1,238 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s): Matthias Hildenbrand
+-
+- Description: Decode Predictive Vector Coding Data
+-
+-*******************************************************************************/
+-
+-#ifndef PVC_DEC_H
+-#define PVC_DEC_H
+-
+-#include "common_fix.h"
+-
+-#define PVC_DIVMODE_BITS 3
+-#define PVC_REUSEPVCID_BITS 1
+-#define PVC_PVCID_BITS 7
+-#define PVC_GRIDINFO_BITS 1
+-
+-#define MAX_PVC_ENVELOPES 2
+-#define PVC_NTIMESLOT 16
+-#define PVC_NBLOW 3 /* max. number of grouped QMF subbands below SBR range */
+-
+-#define PVC_NBHIGH_MODE1 8
+-#define PVC_NBHIGH_MODE2 6
+-#define PVC_NBHIGH_MAX (PVC_NBHIGH_MODE1)
+-#define PVC_NS_MAX 16
+-
+-/** Data for each PVC instance which needs to be persistent accross SBR frames
+- */
+-typedef struct {
+- UCHAR kx_last; /**< Xover frequency of last frame */
+- UCHAR pvc_mode_last; /**< PVC mode of last frame */
+- UCHAR Esg_slot_index; /**< Ring buffer index to current Esg time slot */
+- UCHAR pvcBorder0; /**< Start SBR time slot of PVC frame */
+- FIXP_DBL Esg[PVC_NS_MAX][PVC_NBLOW]; /**< Esg(ksg,t) of current and 15
+- previous time slots (ring buffer) in
+- logarithmical domain */
+-} PVC_STATIC_DATA;
+-
+-/** Data for each PVC instance which is valid during one SBR frame */
+-typedef struct {
+- UCHAR pvc_mode; /**< PVC mode 1 or 2, 0 means legacy SBR */
+- UCHAR pvcBorder0; /**< Start SBR time slot of PVC frame */
+- UCHAR kx; /**< Index of the first QMF subband in the SBR range */
+- UCHAR RATE; /**< Number of QMF subband samples per time slot (2 or 4) */
+- UCHAR ns; /**< Number of time slots for time-domain smoothing of Esg(ksg,t) */
+- const UCHAR
+- *pPvcID; /**< Pointer to prediction coefficient matrix index table */
+- UCHAR pastEsgSlotsAvail; /**< Number of past Esg(ksg,t) which are available
+- for smoothing filter */
+- const FIXP_SGL *pSCcoeffs; /**< Pointer to smoothing window table */
+- SCHAR
+- sg_offset_low[PVC_NBLOW + 1]; /**< Offset table for PVC grouping of SBR
+- subbands below SBR range */
+- SCHAR sg_offset_high_kx[PVC_NBHIGH_MAX + 1]; /**< Offset table for PVC
+- grouping of SBR subbands in
+- SBR range (relativ to kx) */
+- UCHAR nbHigh; /**< Number of grouped QMF subbands in the SBR range */
+- const SCHAR *pScalingCoef; /**< Pointer to scaling coeff table */
+- const UCHAR *pPVCTab1; /**< PVC mode 1 table */
+- const UCHAR *pPVCTab2; /**< PVC mode 2 table */
+- const UCHAR *pPVCTab1_dp; /**< Mapping of pvcID to PVC mode 1 table */
+- FIXP_DBL predEsg[PVC_NTIMESLOT]
+- [PVC_NBHIGH_MAX]; /**< Predicted Energy in linear domain */
+- int predEsg_exp[PVC_NTIMESLOT]; /**< Exponent of predicted Energy in linear
+- domain */
+- int predEsg_expMax; /**< Maximum of predEsg_exp[] */
+-} PVC_DYNAMIC_DATA;
+-
+-/**
+- * \brief Initialize PVC data structures for current frame (call if pvcMode =
+- * 0,1,2)
+- * \param[in] pPvcStaticData Pointer to PVC persistent data
+- * \param[out] pPvcDynamicData Pointer to PVC dynamic data
+- * \param[in] pvcMode PVC mode 1 or 2, 0 means legacy SBR
+- * \param[in] ns Number of time slots for time-domain smoothing of Esg(ksg,t)
+- * \param[in] RATE Number of QMF subband samples per time slot (2 or 4)
+- * \param[in] kx Index of the first QMF subband in the SBR range
+- * \param[in] pvcBorder0 Start SBR time slot of PVC frame
+- * \param[in] pPvcID Pointer to array of PvcIDs read from bitstream
+- */
+-int pvcInitFrame(PVC_STATIC_DATA *pPvcStaticData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData, const UCHAR pvcMode,
+- const UCHAR ns, const int RATE, const int kx,
+- const int pvcBorder0, const UCHAR *pPvcID);
+-
+-/**
+- * \brief Wrapper function for pvcDecodeTimeSlot() to decode PVC data of one
+- * frame (call if pvcMode = 1,2)
+- * \param[in,out] pPvcStaticData Pointer to PVC persistent data
+- * \param[in,out] pPvcDynamicData Pointer to PVC dynamic data
+- * \param[in] qmfBufferReal Pointer to array with real QMF subbands
+- * \param[in] qmfBufferImag Pointer to array with imag QMF subbands
+- * \param[in] overlap Number of QMF overlap slots
+- * \param[in] qmfExponentOverlap Exponent of qmfBuffer (low part) of overlap
+- * slots
+- * \param[in] qmfExponentCurrent Exponent of qmfBuffer (low part)
+- */
+-void pvcDecodeFrame(PVC_STATIC_DATA *pPvcStaticData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData, FIXP_DBL **qmfBufferReal,
+- FIXP_DBL **qmfBufferImag, const int overlap,
+- const int qmfExponentOverlap, const int qmfExponentCurrent);
+-
+-/**
+- * \brief Decode PVC data for one SBR time slot (call if pvcMode = 1,2)
+- * \param[in,out] pPvcStaticData Pointer to PVC persistent data
+- * \param[in,out] pPvcDynamicData Pointer to PVC dynamic data
+- * \param[in] qmfBufferReal Pointer to array with real QMF subbands
+- * \param[in] qmfBufferImag Pointer to array with imag QMF subbands
+- * \param[in] qmfExponent Exponent of qmfBuffer of current time slot
+- * \param[in] pvcBorder0 Start SBR time slot of PVC frame
+- * \param[in] timeSlotNumber Number of current SBR time slot (0..15)
+- * \param[out] predictedEsgSlot Predicted Energy of current time slot
+- * \param[out] predictedEsg_exp Exponent of predicted Energy of current time
+- * slot
+- */
+-void pvcDecodeTimeSlot(PVC_STATIC_DATA *pPvcStaticData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData,
+- FIXP_DBL **qmfSlotReal, FIXP_DBL **qmfSlotImag,
+- const int qmfExponent, const int pvcBorder0,
+- const int timeSlotNumber, FIXP_DBL predictedEsgSlot[],
+- int *predictedEsg_exp);
+-
+-/**
+- * \brief Finish the current PVC frame (call if pvcMode = 0,1,2)
+- * \param[in,out] pPvcStaticData Pointer to PVC persistent data
+- * \param[in,out] pPvcDynamicData Pointer to PVC dynamic data
+- */
+-void pvcEndFrame(PVC_STATIC_DATA *pPvcStaticData,
+- PVC_DYNAMIC_DATA *pPvcDynamicData);
+-
+-/**
+- * \brief Expand predicted PVC grouped energies to full QMF subband resolution
+- * \param[in] pPvcDynamicData Pointer to PVC dynamic data
+- * \param[in] timeSlot Number of current SBR time slot (0..15)
+- * \param[in] lengthOutputVector Lenght of output vector
+- * \param[out] pOutput Output array for predicted energies
+- * \param[out] pOutput_exp Exponent of predicted energies
+- */
+-void expandPredEsg(const PVC_DYNAMIC_DATA *pPvcDynamicData, const int timeSlot,
+- const int lengthOutputVector, FIXP_DBL *pOutput,
+- SCHAR *pOutput_exp);
+-
+-#endif /* PVC_DEC_H*/
+diff --git a/libSBRdec/src/sbr_crc.cpp b/libSBRdec/src/sbr_crc.cpp
+deleted file mode 100644
+index ba0fd05..0000000
+--- a/libSBRdec/src/sbr_crc.cpp
++++ /dev/null
+@@ -1,192 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief CRC check coutines
+-*/
+-
+-#include "sbr_crc.h"
+-
+-#include "FDK_bitstream.h"
+-#include "transcendent.h"
+-
+-#define MAXCRCSTEP 16
+-#define MAXCRCSTEP_LD 4
+-
+-/*!
+- \brief crc calculation
+-*/
+-static ULONG calcCRC(HANDLE_CRC hCrcBuf, ULONG bValue, int nBits) {
+- int i;
+- ULONG bMask = (1UL << (nBits - 1));
+-
+- for (i = 0; i < nBits; i++, bMask >>= 1) {
+- USHORT flag = (hCrcBuf->crcState & hCrcBuf->crcMask) ? 1 : 0;
+- USHORT flag1 = (bMask & bValue) ? 1 : 0;
+-
+- flag ^= flag1;
+- hCrcBuf->crcState <<= 1;
+- if (flag) hCrcBuf->crcState ^= hCrcBuf->crcPoly;
+- }
+-
+- return (hCrcBuf->crcState);
+-}
+-
+-/*!
+- \brief crc
+-*/
+-static int getCrc(HANDLE_FDK_BITSTREAM hBs, ULONG NrBits) {
+- int i;
+- CRC_BUFFER CrcBuf;
+-
+- CrcBuf.crcState = SBR_CRC_START;
+- CrcBuf.crcPoly = SBR_CRC_POLY;
+- CrcBuf.crcMask = SBR_CRC_MASK;
+-
+- int CrcStep = NrBits >> MAXCRCSTEP_LD;
+-
+- int CrcNrBitsRest = (NrBits - CrcStep * MAXCRCSTEP);
+- ULONG bValue;
+-
+- for (i = 0; i < CrcStep; i++) {
+- bValue = FDKreadBits(hBs, MAXCRCSTEP);
+- calcCRC(&CrcBuf, bValue, MAXCRCSTEP);
+- }
+-
+- bValue = FDKreadBits(hBs, CrcNrBitsRest);
+- calcCRC(&CrcBuf, bValue, CrcNrBitsRest);
+-
+- return (CrcBuf.crcState & SBR_CRC_RANGE);
+-}
+-
+-/*!
+- \brief crc interface
+- \return 1: CRC OK, 0: CRC check failure
+-*/
+-int SbrCrcCheck(HANDLE_FDK_BITSTREAM hBs, /*!< handle to bit-buffer */
+- LONG NrBits) /*!< max. CRC length */
+-{
+- int crcResult = 1;
+- ULONG NrCrcBits;
+- ULONG crcCheckResult;
+- LONG NrBitsAvailable;
+- ULONG crcCheckSum;
+-
+- crcCheckSum = FDKreadBits(hBs, 10);
+-
+- NrBitsAvailable = FDKgetValidBits(hBs);
+- if (NrBitsAvailable <= 0) {
+- return 0;
+- }
+-
+- NrCrcBits = fixMin((INT)NrBits, (INT)NrBitsAvailable);
+-
+- crcCheckResult = getCrc(hBs, NrCrcBits);
+- FDKpushBack(hBs, (NrBitsAvailable - FDKgetValidBits(hBs)));
+-
+- if (crcCheckResult != crcCheckSum) {
+- crcResult = 0;
+- }
+-
+- return (crcResult);
+-}
+diff --git a/libSBRdec/src/sbr_crc.h b/libSBRdec/src/sbr_crc.h
+deleted file mode 100644
+index 9633717..0000000
+--- a/libSBRdec/src/sbr_crc.h
++++ /dev/null
+@@ -1,138 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief CRC checking routines
+-*/
+-#ifndef SBR_CRC_H
+-#define SBR_CRC_H
+-
+-#include "sbrdecoder.h"
+-
+-#include "FDK_bitstream.h"
+-
+-/* some useful crc polynoms:
+-
+-crc5: x^5+x^4+x^2+x^1+1
+-crc6: x^6+x^5+x^3+x^2+x+1
+-crc7: x^7+x^6+x^2+1
+-crc8: x^8+x^2+x+x+1
+-*/
+-
+-/* default SBR CRC */ /* G(x) = x^10 + x^9 + x^5 + x^4 + x + 1 */
+-#define SBR_CRC_POLY 0x0233
+-#define SBR_CRC_MASK 0x0200
+-#define SBR_CRC_START 0x0000
+-#define SBR_CRC_RANGE 0x03FF
+-
+-typedef struct {
+- USHORT crcState;
+- USHORT crcMask;
+- USHORT crcPoly;
+-} CRC_BUFFER;
+-
+-typedef CRC_BUFFER *HANDLE_CRC;
+-
+-int SbrCrcCheck(HANDLE_FDK_BITSTREAM hBitBuf, LONG NrCrcBits);
+-
+-#endif
+diff --git a/libSBRdec/src/sbr_deb.cpp b/libSBRdec/src/sbr_deb.cpp
+deleted file mode 100644
+index 13cd211..0000000
+--- a/libSBRdec/src/sbr_deb.cpp
++++ /dev/null
+@@ -1,108 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Print selected debug messages
+-*/
+-
+-#include "sbr_deb.h"
+diff --git a/libSBRdec/src/sbr_deb.h b/libSBRdec/src/sbr_deb.h
+deleted file mode 100644
+index 97d572a..0000000
+--- a/libSBRdec/src/sbr_deb.h
++++ /dev/null
+@@ -1,113 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Debugging aids
+-*/
+-
+-#ifndef SBR_DEB_H
+-#define SBR_DEB_H
+-
+-#include "sbrdecoder.h"
+-
+-#endif
+diff --git a/libSBRdec/src/sbr_dec.cpp b/libSBRdec/src/sbr_dec.cpp
+deleted file mode 100644
+index 30611e7..0000000
+--- a/libSBRdec/src/sbr_dec.cpp
++++ /dev/null
+@@ -1,1480 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Sbr decoder
+- This module provides the actual decoder implementation. The SBR data (side
+- information) is already decoded. Only three functions are provided:
+-
+- \li 1.) createSbrDec(): One time initialization
+- \li 2.) resetSbrDec(): Called by sbr_Apply() when the information contained in
+- an SBR_HEADER_ELEMENT requires a reset and recalculation of important SBR
+- structures. \li 3.) sbr_dec(): The actual decoder. Calls the different tools
+- such as filterbanks, lppTransposer(), and calculateSbrEnvelope() [the envelope
+- adjuster].
+-
+- \sa sbr_dec(), \ref documentationOverview
+-*/
+-
+-#include "sbr_dec.h"
+-
+-#include "sbr_ram.h"
+-#include "env_extr.h"
+-#include "env_calc.h"
+-#include "scale.h"
+-#include "FDK_matrixCalloc.h"
+-#include "hbe.h"
+-
+-#include "genericStds.h"
+-
+-#include "sbrdec_drc.h"
+-
+-static void copyHarmonicSpectrum(int *xOverQmf, FIXP_DBL **qmfReal,
+- FIXP_DBL **qmfImag, int noCols, int overlap,
+- KEEP_STATES_SYNCED_MODE keepStatesSynced) {
+- int patchBands;
+- int patch, band, col, target, sourceBands, i;
+- int numPatches = 0;
+- int slotOffset = 0;
+-
+- FIXP_DBL **ppqmfReal = qmfReal + overlap;
+- FIXP_DBL **ppqmfImag = qmfImag + overlap;
+-
+- if (keepStatesSynced == KEEP_STATES_SYNCED_NORMAL) {
+- slotOffset = noCols - overlap - LPC_ORDER;
+- }
+-
+- if (keepStatesSynced == KEEP_STATES_SYNCED_OUTDIFF) {
+- ppqmfReal = qmfReal;
+- ppqmfImag = qmfImag;
+- }
+-
+- for (i = 1; i < MAX_NUM_PATCHES; i++) {
+- if (xOverQmf[i] != 0) {
+- numPatches++;
+- }
+- }
+-
+- for (patch = (MAX_STRETCH_HBE - 1); patch < numPatches; patch++) {
+- patchBands = xOverQmf[patch + 1] - xOverQmf[patch];
+- target = xOverQmf[patch];
+- sourceBands = xOverQmf[MAX_STRETCH_HBE - 1] - xOverQmf[MAX_STRETCH_HBE - 2];
+-
+- while (patchBands > 0) {
+- int numBands = sourceBands;
+- int startBand = xOverQmf[MAX_STRETCH_HBE - 1] - 1;
+- if (target + numBands >= xOverQmf[patch + 1]) {
+- numBands = xOverQmf[patch + 1] - target;
+- }
+- if ((((target + numBands - 1) % 2) +
+- ((xOverQmf[MAX_STRETCH_HBE - 1] - 1) % 2)) %
+- 2) {
+- if (numBands == sourceBands) {
+- numBands--;
+- } else {
+- startBand--;
+- }
+- }
+- if (keepStatesSynced == KEEP_STATES_SYNCED_OUTDIFF) {
+- for (col = slotOffset; col < overlap + LPC_ORDER; col++) {
+- i = 0;
+- for (band = numBands; band > 0; band--) {
+- if ((target + band - 1 < 64) &&
+- (target + band - 1 < xOverQmf[patch + 1])) {
+- ppqmfReal[col][target + band - 1] = ppqmfReal[col][startBand - i];
+- ppqmfImag[col][target + band - 1] = ppqmfImag[col][startBand - i];
+- i++;
+- }
+- }
+- }
+- } else {
+- for (col = slotOffset; col < noCols; col++) {
+- i = 0;
+- for (band = numBands; band > 0; band--) {
+- if ((target + band - 1 < 64) &&
+- (target + band - 1 < xOverQmf[patch + 1])) {
+- ppqmfReal[col][target + band - 1] = ppqmfReal[col][startBand - i];
+- ppqmfImag[col][target + band - 1] = ppqmfImag[col][startBand - i];
+- i++;
+- }
+- }
+- }
+- }
+- target += numBands;
+- patchBands -= numBands;
+- }
+- }
+-}
+-
+-/*!
+- \brief SBR decoder core function for one channel
+-
+- \image html BufferMgmtDetailed-1632.png
+-
+- Besides the filter states of the QMF filter bank and the LPC-states of
+- the LPP-Transposer, processing is mainly based on four buffers:
+- #timeIn, #timeOut, #WorkBuffer2 and #OverlapBuffer. The #WorkBuffer2
+- is reused for all channels and might be used by the core decoder, a
+- static overlap buffer is required for each channel. Due to in-place
+- processing, #timeIn and #timeOut point to identical locations.
+-
+- The spectral data is organized in so-called slots. Each slot
+- contains 64 bands of complex data. The number of slots per frame
+- depends on the frame size. For mp3PRO, there are 18 slots per frame
+- and 6 slots per #OverlapBuffer. It is not necessary to have the slots
+- in located consecutive address ranges.
+-
+- To optimize memory usage and to minimize the number of memory
+- accesses, the memory management is organized as follows (slot numbers
+- based on mp3PRO):
+-
+- 1.) Input time domain signal is located in #timeIn. The last slots
+- (0..5) of the spectral data of the previous frame are located in the
+- #OverlapBuffer. In addition, #frameData of the current frame resides
+- in the upper part of #timeIn.
+-
+- 2.) During the cplxAnalysisQmfFiltering(), 32 samples from #timeIn are
+- transformed into a slot of up to 32 complex spectral low band values at a
+- time. The first spectral slot -- nr. 6 -- is written at slot number
+- zero of #WorkBuffer2. #WorkBuffer2 will be completely filled with
+- spectral data.
+-
+- 3.) LPP-Transposition in lppTransposer() is processed on 24 slots. During the
+- transposition, the high band part of the spectral data is replicated
+- based on the low band data.
+-
+- Envelope Adjustment is processed on the high band part of the spectral
+- data only by calculateSbrEnvelope().
+-
+- 4.) The cplxSynthesisQmfFiltering() creates 64 time domain samples out
+- of a slot of 64 complex spectral values at a time. The first 6 slots
+- in #timeOut are filled from the results of spectral slots 0..5 in the
+- #OverlapBuffer. The consecutive slots in timeOut are now filled with
+- the results of spectral slots 6..17.
+-
+- 5.) The preprocessed slots 18..23 have to be stored in the
+- #OverlapBuffer.
+-
+-*/
+-
+-void sbr_dec(
+- HANDLE_SBR_DEC hSbrDec, /*!< handle to Decoder channel */
+- INT_PCM *timeIn, /*!< pointer to input time signal */
+- INT_PCM *timeOut, /*!< pointer to output time signal */
+- HANDLE_SBR_DEC hSbrDecRight, /*!< handle to Decoder channel right */
+- INT_PCM *timeOutRight, /*!< pointer to output time signal */
+- const int strideOut, /*!< Time data traversal strideOut */
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA hFrameData, /*!< Control data of current frame */
+- HANDLE_SBR_PREV_FRAME_DATA
+- hPrevFrameData, /*!< Some control data of last frame */
+- const int applyProcessing, /*!< Flag for SBR operation */
+- HANDLE_PS_DEC h_ps_d, const UINT flags, const int codecFrameSize) {
+- int i, slot, reserve;
+- int saveLbScale;
+- int lastSlotOffs;
+- FIXP_DBL maxVal;
+-
+- /* temporary pointer / variable for QMF;
+- required as we want to use temporary buffer
+- creating one frame delay for HBE in LP mode */
+- INT_PCM *pTimeInQmf = timeIn;
+-
+- /* Number of QMF timeslots in the overlap buffer: */
+- int ov_len = hSbrDec->LppTrans.pSettings->overlap;
+-
+- /* Number of QMF slots per frame */
+- int noCols = hHeaderData->numberTimeSlots * hHeaderData->timeStep;
+-
+- /* create pointer array for data to use for HBE and legacy sbr */
+- FIXP_DBL *pLowBandReal[(3 * 4) + 2 * ((1024) / (32) * (4) / 2)];
+- FIXP_DBL *pLowBandImag[(3 * 4) + 2 * ((1024) / (32) * (4) / 2)];
+-
+- /* set pReal to where QMF analysis writes in case of legacy SBR */
+- FIXP_DBL **pReal = pLowBandReal + ov_len;
+- FIXP_DBL **pImag = pLowBandImag + ov_len;
+-
+- /* map QMF buffer to pointer array (Overlap + Frame)*/
+- for (i = 0; i < noCols + ov_len; i++) {
+- pLowBandReal[i] = hSbrDec->qmfDomainInCh->hQmfSlotsReal[i];
+- pLowBandImag[i] = hSbrDec->qmfDomainInCh->hQmfSlotsImag[i];
+- }
+-
+- if ((flags & SBRDEC_USAC_HARMONICSBR)) {
+- /* in case of harmonic SBR and no HBE_LP map additional buffer for
+- one more frame to pointer arry */
+- for (i = 0; i < noCols; i++) {
+- pLowBandReal[i + noCols + ov_len] = hSbrDec->hQmfHBESlotsReal[i];
+- pLowBandImag[i + noCols + ov_len] = hSbrDec->hQmfHBESlotsImag[i];
+- }
+-
+- /* shift scale values according to buffer */
+- hSbrDec->scale_ov = hSbrDec->scale_lb;
+- hSbrDec->scale_lb = hSbrDec->scale_hbe;
+-
+- /* set pReal to where QMF analysis writes in case of HBE */
+- pReal += noCols;
+- pImag += noCols;
+- if (flags & SBRDEC_SKIP_QMF_ANA) {
+- /* stereoCfgIndex3 with HBE */
+- FDK_QmfDomain_QmfData2HBE(hSbrDec->qmfDomainInCh,
+- hSbrDec->hQmfHBESlotsReal,
+- hSbrDec->hQmfHBESlotsImag);
+- } else {
+- /* We have to move old hbe frame data to lb area of buffer */
+- for (i = 0; i < noCols; i++) {
+- FDKmemcpy(pLowBandReal[ov_len + i], hSbrDec->hQmfHBESlotsReal[i],
+- hHeaderData->numberOfAnalysisBands * sizeof(FIXP_DBL));
+- FDKmemcpy(pLowBandImag[ov_len + i], hSbrDec->hQmfHBESlotsImag[i],
+- hHeaderData->numberOfAnalysisBands * sizeof(FIXP_DBL));
+- }
+- }
+- }
+-
+- /*
+- low band codec signal subband filtering
+- */
+-
+- if (flags & SBRDEC_SKIP_QMF_ANA) {
+- if (!(flags & SBRDEC_USAC_HARMONICSBR)) /* stereoCfgIndex3 w/o HBE */
+- FDK_QmfDomain_WorkBuffer2ProcChannel(hSbrDec->qmfDomainInCh);
+- } else {
+- C_AALLOC_SCRATCH_START(qmfTemp, FIXP_DBL, 2 * (64));
+- qmfAnalysisFiltering(&hSbrDec->qmfDomainInCh->fb, pReal, pImag,
+- &hSbrDec->qmfDomainInCh->scaling, pTimeInQmf, 0, 1,
+- qmfTemp);
+-
+- C_AALLOC_SCRATCH_END(qmfTemp, FIXP_DBL, 2 * (64));
+- }
+-
+- /*
+- Clear upper half of spectrum
+- */
+- if (!((flags & SBRDEC_USAC_HARMONICSBR) &&
+- (hFrameData->sbrPatchingMode == 0))) {
+- int nAnalysisBands = hHeaderData->numberOfAnalysisBands;
+-
+- if (!(flags & SBRDEC_LOW_POWER)) {
+- for (slot = ov_len; slot < noCols + ov_len; slot++) {
+- FDKmemclear(&pLowBandReal[slot][nAnalysisBands],
+- ((64) - nAnalysisBands) * sizeof(FIXP_DBL));
+- FDKmemclear(&pLowBandImag[slot][nAnalysisBands],
+- ((64) - nAnalysisBands) * sizeof(FIXP_DBL));
+- }
+- } else {
+- for (slot = ov_len; slot < noCols + ov_len; slot++) {
+- FDKmemclear(&pLowBandReal[slot][nAnalysisBands],
+- ((64) - nAnalysisBands) * sizeof(FIXP_DBL));
+- }
+- }
+- }
+-
+- /*
+- Shift spectral data left to gain accuracy in transposer and adjustor
+- */
+- /* Range was increased from lsb to no_channels because in some cases (e.g.
+- USAC conf eSbr_4_Pvc.mp4 and some HBE cases) it could be observed that the
+- signal between lsb and no_channels is used for the patching process.
+- */
+- maxVal = maxSubbandSample(pReal, (flags & SBRDEC_LOW_POWER) ? NULL : pImag, 0,
+- hSbrDec->qmfDomainInCh->fb.no_channels, 0, noCols);
+-
+- reserve = fixMax(0, CntLeadingZeros(maxVal) - 1);
+- reserve = fixMin(reserve,
+- DFRACT_BITS - 1 - hSbrDec->qmfDomainInCh->scaling.lb_scale);
+-
+- /* If all data is zero, lb_scale could become too large */
+- rescaleSubbandSamples(pReal, (flags & SBRDEC_LOW_POWER) ? NULL : pImag, 0,
+- hSbrDec->qmfDomainInCh->fb.no_channels, 0, noCols,
+- reserve);
+-
+- hSbrDec->qmfDomainInCh->scaling.lb_scale += reserve;
+-
+- if ((flags & SBRDEC_USAC_HARMONICSBR)) {
+- /* actually this is our hbe_scale */
+- hSbrDec->scale_hbe = hSbrDec->qmfDomainInCh->scaling.lb_scale;
+- /* the real lb_scale is stored in scale_lb from sbr */
+- hSbrDec->qmfDomainInCh->scaling.lb_scale = hSbrDec->scale_lb;
+- }
+- /*
+- save low band scale, wavecoding or parametric stereo may modify it
+- */
+- saveLbScale = hSbrDec->qmfDomainInCh->scaling.lb_scale;
+-
+- if (applyProcessing) {
+- UCHAR *borders = hFrameData->frameInfo.borders;
+- lastSlotOffs = borders[hFrameData->frameInfo.nEnvelopes] -
+- hHeaderData->numberTimeSlots;
+-
+- FIXP_DBL degreeAlias[(64)];
+- PVC_DYNAMIC_DATA pvcDynamicData;
+- pvcInitFrame(
+- &hSbrDec->PvcStaticData, &pvcDynamicData,
+- (hHeaderData->frameErrorFlag ? 0 : hHeaderData->bs_info.pvc_mode),
+- hFrameData->ns, hHeaderData->timeStep,
+- hHeaderData->freqBandData.lowSubband,
+- hFrameData->frameInfo.pvcBorders[0], hFrameData->pvcID);
+-
+- if (!hHeaderData->frameErrorFlag && (hHeaderData->bs_info.pvc_mode > 0)) {
+- pvcDecodeFrame(&hSbrDec->PvcStaticData, &pvcDynamicData, pLowBandReal,
+- pLowBandImag, ov_len,
+- SCALE2EXP(hSbrDec->qmfDomainInCh->scaling.ov_lb_scale),
+- SCALE2EXP(hSbrDec->qmfDomainInCh->scaling.lb_scale));
+- }
+- pvcEndFrame(&hSbrDec->PvcStaticData, &pvcDynamicData);
+-
+- /* The transposer will override most values in degreeAlias[].
+- The array needs to be cleared at least from lowSubband to highSubband
+- before. */
+- if (flags & SBRDEC_LOW_POWER)
+- FDKmemclear(°reeAlias[hHeaderData->freqBandData.lowSubband],
+- (hHeaderData->freqBandData.highSubband -
+- hHeaderData->freqBandData.lowSubband) *
+- sizeof(FIXP_DBL));
+-
+- /*
+- Inverse filtering of lowband and transposition into the SBR-frequency
+- range
+- */
+-
+- {
+- KEEP_STATES_SYNCED_MODE keepStatesSyncedMode =
+- ((flags & SBRDEC_USAC_HARMONICSBR) &&
+- (hFrameData->sbrPatchingMode != 0))
+- ? KEEP_STATES_SYNCED_NORMAL
+- : KEEP_STATES_SYNCED_OFF;
+-
+- if (flags & SBRDEC_USAC_HARMONICSBR) {
+- if (flags & SBRDEC_QUAD_RATE) {
+- pReal -= 32;
+- pImag -= 32;
+- }
+-
+- if ((hSbrDec->savedStates == 0) && (hFrameData->sbrPatchingMode == 1)) {
+- /* copy saved states from previous frame to legacy SBR lpc filterstate
+- * buffer */
+- for (i = 0; i < LPC_ORDER + ov_len; i++) {
+- FDKmemcpy(
+- hSbrDec->LppTrans.lpcFilterStatesRealLegSBR[i],
+- hSbrDec->codecQMFBufferReal[noCols - LPC_ORDER - ov_len + i],
+- hSbrDec->hHBE->noChannels * sizeof(FIXP_DBL));
+- FDKmemcpy(
+- hSbrDec->LppTrans.lpcFilterStatesImagLegSBR[i],
+- hSbrDec->codecQMFBufferImag[noCols - LPC_ORDER - ov_len + i],
+- hSbrDec->hHBE->noChannels * sizeof(FIXP_DBL));
+- }
+- }
+-
+- /* saving unmodified QMF states in case we are switching from legacy SBR
+- * to HBE */
+- for (i = 0; i < hSbrDec->hHBE->noCols; i++) {
+- FDKmemcpy(hSbrDec->codecQMFBufferReal[i], pLowBandReal[ov_len + i],
+- hSbrDec->hHBE->noChannels * sizeof(FIXP_DBL));
+- FDKmemcpy(hSbrDec->codecQMFBufferImag[i], pLowBandImag[ov_len + i],
+- hSbrDec->hHBE->noChannels * sizeof(FIXP_DBL));
+- }
+-
+- QmfTransposerApply(
+- hSbrDec->hHBE, pReal, pImag, noCols, pLowBandReal, pLowBandImag,
+- hSbrDec->LppTrans.lpcFilterStatesRealHBE,
+- hSbrDec->LppTrans.lpcFilterStatesImagHBE,
+- hFrameData->sbrPitchInBins, hSbrDec->scale_lb, hSbrDec->scale_hbe,
+- &hSbrDec->qmfDomainInCh->scaling.hb_scale, hHeaderData->timeStep,
+- borders[0], ov_len, keepStatesSyncedMode);
+-
+- if (flags & SBRDEC_QUAD_RATE) {
+- int *xOverQmf = GetxOverBandQmfTransposer(hSbrDec->hHBE);
+-
+- copyHarmonicSpectrum(xOverQmf, pLowBandReal, pLowBandImag, noCols,
+- ov_len, keepStatesSyncedMode);
+- }
+- }
+- }
+-
+- if ((flags & SBRDEC_USAC_HARMONICSBR) &&
+- (hFrameData->sbrPatchingMode == 0)) {
+- hSbrDec->prev_frame_lSbr = 0;
+- hSbrDec->prev_frame_hbeSbr = 1;
+-
+- lppTransposerHBE(
+- &hSbrDec->LppTrans, hSbrDec->hHBE, &hSbrDec->qmfDomainInCh->scaling,
+- pLowBandReal, pLowBandImag, hHeaderData->timeStep, borders[0],
+- lastSlotOffs, hHeaderData->freqBandData.nInvfBands,
+- hFrameData->sbr_invf_mode, hPrevFrameData->sbr_invf_mode);
+-
+- } else {
+- if (flags & SBRDEC_USAC_HARMONICSBR) {
+- for (i = 0; i < LPC_ORDER + hSbrDec->LppTrans.pSettings->overlap; i++) {
+- /*
+- Store the unmodified qmf Slots values for upper part of spectrum
+- (required for LPC filtering) required if next frame is a HBE frame
+- */
+- FDKmemcpy(hSbrDec->LppTrans.lpcFilterStatesRealHBE[i],
+- hSbrDec->qmfDomainInCh
+- ->hQmfSlotsReal[hSbrDec->hHBE->noCols - LPC_ORDER + i],
+- (64) * sizeof(FIXP_DBL));
+- FDKmemcpy(hSbrDec->LppTrans.lpcFilterStatesImagHBE[i],
+- hSbrDec->qmfDomainInCh
+- ->hQmfSlotsImag[hSbrDec->hHBE->noCols - LPC_ORDER + i],
+- (64) * sizeof(FIXP_DBL));
+- }
+- }
+- {
+- hSbrDec->prev_frame_lSbr = 1;
+- hSbrDec->prev_frame_hbeSbr = 0;
+- }
+-
+- lppTransposer(
+- &hSbrDec->LppTrans, &hSbrDec->qmfDomainInCh->scaling, pLowBandReal,
+- degreeAlias, // only used if useLP = 1
+- pLowBandImag, flags & SBRDEC_LOW_POWER,
+- hHeaderData->bs_info.sbr_preprocessing,
+- hHeaderData->freqBandData.v_k_master[0], hHeaderData->timeStep,
+- borders[0], lastSlotOffs, hHeaderData->freqBandData.nInvfBands,
+- hFrameData->sbr_invf_mode, hPrevFrameData->sbr_invf_mode);
+- }
+-
+- /*
+- Adjust envelope of current frame.
+- */
+-
+- if ((hFrameData->sbrPatchingMode !=
+- hSbrDec->SbrCalculateEnvelope.sbrPatchingMode)) {
+- ResetLimiterBands(hHeaderData->freqBandData.limiterBandTable,
+- &hHeaderData->freqBandData.noLimiterBands,
+- hHeaderData->freqBandData.freqBandTable[0],
+- hHeaderData->freqBandData.nSfb[0],
+- hSbrDec->LppTrans.pSettings->patchParam,
+- hSbrDec->LppTrans.pSettings->noOfPatches,
+- hHeaderData->bs_data.limiterBands,
+- hFrameData->sbrPatchingMode,
+- (flags & SBRDEC_USAC_HARMONICSBR) &&
+- (hFrameData->sbrPatchingMode == 0)
+- ? GetxOverBandQmfTransposer(hSbrDec->hHBE)
+- : NULL,
+- Get41SbrQmfTransposer(hSbrDec->hHBE));
+-
+- hSbrDec->SbrCalculateEnvelope.sbrPatchingMode =
+- hFrameData->sbrPatchingMode;
+- }
+-
+- calculateSbrEnvelope(
+- &hSbrDec->qmfDomainInCh->scaling, &hSbrDec->SbrCalculateEnvelope,
+- hHeaderData, hFrameData, &pvcDynamicData, pLowBandReal, pLowBandImag,
+- flags & SBRDEC_LOW_POWER,
+-
+- degreeAlias, flags,
+- (hHeaderData->frameErrorFlag || hPrevFrameData->frameErrorFlag));
+-
+-#if (SBRDEC_MAX_HB_FADE_FRAMES > 0)
+- /* Avoid hard onsets of high band */
+- if (hHeaderData->frameErrorFlag) {
+- if (hSbrDec->highBandFadeCnt < SBRDEC_MAX_HB_FADE_FRAMES) {
+- hSbrDec->highBandFadeCnt += 1;
+- }
+- } else {
+- if (hSbrDec->highBandFadeCnt >
+- 0) { /* Manipulate high band scale factor to get a smooth fade-in */
+- hSbrDec->qmfDomainInCh->scaling.hb_scale += hSbrDec->highBandFadeCnt;
+- hSbrDec->qmfDomainInCh->scaling.hb_scale =
+- fMin(hSbrDec->qmfDomainInCh->scaling.hb_scale, DFRACT_BITS - 1);
+- hSbrDec->highBandFadeCnt -= 1;
+- }
+- }
+-
+-#endif
+- /*
+- Update hPrevFrameData (to be used in the next frame)
+- */
+- for (i = 0; i < hHeaderData->freqBandData.nInvfBands; i++) {
+- hPrevFrameData->sbr_invf_mode[i] = hFrameData->sbr_invf_mode[i];
+- }
+- hPrevFrameData->coupling = hFrameData->coupling;
+- hPrevFrameData->stopPos = borders[hFrameData->frameInfo.nEnvelopes];
+- hPrevFrameData->ampRes = hFrameData->ampResolutionCurrentFrame;
+- hPrevFrameData->prevSbrPitchInBins = hFrameData->sbrPitchInBins;
+- /* could be done in extractFrameInfo_pvc() but hPrevFrameData is not
+- * available there */
+- FDKmemcpy(&hPrevFrameData->prevFrameInfo, &hFrameData->frameInfo,
+- sizeof(FRAME_INFO));
+- } else {
+- /* rescale from lsb to nAnalysisBands in order to compensate scaling with
+- * hb_scale in this area, done by synthesisFiltering*/
+- int rescale;
+- int lsb;
+- int length;
+-
+- /* Reset hb_scale if no highband is present, because hb_scale is considered
+- * in the QMF-synthesis */
+- hSbrDec->qmfDomainInCh->scaling.hb_scale = saveLbScale;
+-
+- rescale = hSbrDec->qmfDomainInCh->scaling.hb_scale -
+- hSbrDec->qmfDomainInCh->scaling.ov_lb_scale;
+- lsb = hSbrDec->qmfDomainOutCh->fb.lsb;
+- length = (hSbrDec->qmfDomainInCh->fb.no_channels - lsb);
+-
+- if ((rescale < 0) && (length > 0)) {
+- if (!(flags & SBRDEC_LOW_POWER)) {
+- for (i = 0; i < ov_len; i++) {
+- scaleValues(&pLowBandReal[i][lsb], length, rescale);
+- scaleValues(&pLowBandImag[i][lsb], length, rescale);
+- }
+- } else {
+- for (i = 0; i < ov_len; i++) {
+- scaleValues(&pLowBandReal[i][lsb], length, rescale);
+- }
+- }
+- }
+- }
+-
+- if (!(flags & SBRDEC_USAC_HARMONICSBR)) {
+- int length = hSbrDec->qmfDomainInCh->fb.lsb;
+- if (flags & SBRDEC_SYNTAX_USAC) {
+- length = hSbrDec->qmfDomainInCh->fb.no_channels;
+- }
+-
+- /* in case of legacy sbr saving of filter states here */
+- for (i = 0; i < LPC_ORDER + ov_len; i++) {
+- /*
+- Store the unmodified qmf Slots values (required for LPC filtering)
+- */
+- if (!(flags & SBRDEC_LOW_POWER)) {
+- FDKmemcpy(hSbrDec->LppTrans.lpcFilterStatesRealLegSBR[i],
+- pLowBandReal[noCols - LPC_ORDER + i],
+- length * sizeof(FIXP_DBL));
+- FDKmemcpy(hSbrDec->LppTrans.lpcFilterStatesImagLegSBR[i],
+- pLowBandImag[noCols - LPC_ORDER + i],
+- length * sizeof(FIXP_DBL));
+- } else
+- FDKmemcpy(hSbrDec->LppTrans.lpcFilterStatesRealLegSBR[i],
+- pLowBandReal[noCols - LPC_ORDER + i],
+- length * sizeof(FIXP_DBL));
+- }
+- }
+-
+- /*
+- Synthesis subband filtering.
+- */
+-
+- if (!(flags & SBRDEC_PS_DECODED)) {
+- if (!(flags & SBRDEC_SKIP_QMF_SYN)) {
+- int outScalefactor = 0;
+-
+- if (h_ps_d != NULL) {
+- h_ps_d->procFrameBased = 1; /* we here do frame based processing */
+- }
+-
+- sbrDecoder_drcApply(&hSbrDec->sbrDrcChannel, pLowBandReal,
+- (flags & SBRDEC_LOW_POWER) ? NULL : pLowBandImag,
+- hSbrDec->qmfDomainOutCh->fb.no_col, &outScalefactor);
+-
+- qmfChangeOutScalefactor(&hSbrDec->qmfDomainOutCh->fb, outScalefactor);
+-
+- {
+- HANDLE_FREQ_BAND_DATA hFreq = &hHeaderData->freqBandData;
+- int save_usb = hSbrDec->qmfDomainOutCh->fb.usb;
+-
+-#if (QMF_MAX_SYNTHESIS_BANDS <= 64)
+- C_AALLOC_SCRATCH_START(qmfTemp, FIXP_DBL, 2 * QMF_MAX_SYNTHESIS_BANDS);
+-#else
+- C_AALLOC_STACK_START(qmfTemp, FIXP_DBL, 2 * QMF_MAX_SYNTHESIS_BANDS);
+-#endif
+- if (hSbrDec->qmfDomainOutCh->fb.usb < hFreq->ov_highSubband) {
+- /* we need to patch usb for this frame as overlap may contain higher
+- frequency range if headerchange occured; fb. usb is always limited
+- to maximum fb.no_channels; In case of wrongly decoded headers it
+- might be that ov_highSubband is higher than the number of synthesis
+- channels (fb.no_channels), which is forbidden, therefore we need to
+- limit ov_highSubband with fMin function to avoid not allowed usb in
+- synthesis filterbank. */
+- hSbrDec->qmfDomainOutCh->fb.usb =
+- fMin((UINT)hFreq->ov_highSubband,
+- (UINT)hSbrDec->qmfDomainOutCh->fb.no_channels);
+- }
+- {
+- qmfSynthesisFiltering(
+- &hSbrDec->qmfDomainOutCh->fb, pLowBandReal,
+- (flags & SBRDEC_LOW_POWER) ? NULL : pLowBandImag,
+- &hSbrDec->qmfDomainInCh->scaling,
+- hSbrDec->LppTrans.pSettings->overlap, timeOut, strideOut,
+- qmfTemp);
+- }
+- /* restore saved value */
+- hSbrDec->qmfDomainOutCh->fb.usb = save_usb;
+- hFreq->ov_highSubband = save_usb;
+-#if (QMF_MAX_SYNTHESIS_BANDS <= 64)
+- C_AALLOC_SCRATCH_END(qmfTemp, FIXP_DBL, 2 * QMF_MAX_SYNTHESIS_BANDS);
+-#else
+- C_AALLOC_STACK_END(qmfTemp, FIXP_DBL, 2 * QMF_MAX_SYNTHESIS_BANDS);
+-#endif
+- }
+- }
+-
+- } else { /* (flags & SBRDEC_PS_DECODED) */
+- INT sdiff;
+- INT scaleFactorHighBand, scaleFactorLowBand_ov, scaleFactorLowBand_no_ov;
+-
+- HANDLE_QMF_FILTER_BANK synQmf = &hSbrDec->qmfDomainOutCh->fb;
+- HANDLE_QMF_FILTER_BANK synQmfRight = &hSbrDecRight->qmfDomainOutCh->fb;
+-
+- /* adapt scaling */
+- sdiff = hSbrDec->qmfDomainInCh->scaling.lb_scale -
+- reserve; /* Scaling difference */
+- scaleFactorHighBand = sdiff - hSbrDec->qmfDomainInCh->scaling.hb_scale;
+- scaleFactorLowBand_ov = sdiff - hSbrDec->qmfDomainInCh->scaling.ov_lb_scale;
+- scaleFactorLowBand_no_ov = sdiff - hSbrDec->qmfDomainInCh->scaling.lb_scale;
+-
+- /* Scale of low band overlapping QMF data */
+- scaleFactorLowBand_ov =
+- fMin(DFRACT_BITS - 1, fMax(-(DFRACT_BITS - 1), scaleFactorLowBand_ov));
+- /* Scale of low band current QMF data */
+- scaleFactorLowBand_no_ov = fMin(
+- DFRACT_BITS - 1, fMax(-(DFRACT_BITS - 1), scaleFactorLowBand_no_ov));
+- /* Scale of current high band */
+- scaleFactorHighBand =
+- fMin(DFRACT_BITS - 1, fMax(-(DFRACT_BITS - 1), scaleFactorHighBand));
+-
+- if (h_ps_d->procFrameBased == 1) /* If we have switched from frame to slot
+- based processing copy filter states */
+- { /* procFrameBased will be unset later */
+- /* copy filter states from left to right */
+- /* was ((640)-(64))*sizeof(FIXP_QSS)
+- flexible amount of synthesis bands needed for QMF based resampling
+- */
+- FDK_ASSERT(hSbrDec->qmfDomainInCh->pGlobalConf->nBandsSynthesis <=
+- QMF_MAX_SYNTHESIS_BANDS);
+- FDKmemcpy(synQmfRight->FilterStates, synQmf->FilterStates,
+- 9 * hSbrDec->qmfDomainInCh->pGlobalConf->nBandsSynthesis *
+- sizeof(FIXP_QSS));
+- }
+-
+- /* Feed delaylines when parametric stereo is switched on. */
+- PreparePsProcessing(h_ps_d, pLowBandReal, pLowBandImag,
+- scaleFactorLowBand_ov);
+-
+- /* use the same synthese qmf values for left and right channel */
+- synQmfRight->no_col = synQmf->no_col;
+- synQmfRight->lsb = synQmf->lsb;
+- synQmfRight->usb = synQmf->usb;
+-
+- int env = 0;
+-
+- {
+-#if (QMF_MAX_SYNTHESIS_BANDS <= 64)
+- C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL,
+- 2 * QMF_MAX_SYNTHESIS_BANDS);
+-#else
+- C_AALLOC_STACK_START(pWorkBuffer, FIXP_DBL, 2 * QMF_MAX_SYNTHESIS_BANDS);
+-#endif
+-
+- int maxShift = 0;
+-
+- if (hSbrDec->sbrDrcChannel.enable != 0) {
+- if (hSbrDec->sbrDrcChannel.prevFact_exp > maxShift) {
+- maxShift = hSbrDec->sbrDrcChannel.prevFact_exp;
+- }
+- if (hSbrDec->sbrDrcChannel.currFact_exp > maxShift) {
+- maxShift = hSbrDec->sbrDrcChannel.currFact_exp;
+- }
+- if (hSbrDec->sbrDrcChannel.nextFact_exp > maxShift) {
+- maxShift = hSbrDec->sbrDrcChannel.nextFact_exp;
+- }
+- }
+-
+- /* copy DRC data to right channel (with PS both channels use the same DRC
+- * gains) */
+- FDKmemcpy(&hSbrDecRight->sbrDrcChannel, &hSbrDec->sbrDrcChannel,
+- sizeof(SBRDEC_DRC_CHANNEL));
+-
+- for (i = 0; i < synQmf->no_col; i++) { /* ----- no_col loop ----- */
+-
+- INT outScalefactorR, outScalefactorL;
+-
+- /* qmf timeslot of right channel */
+- FIXP_DBL *rQmfReal = pWorkBuffer;
+- FIXP_DBL *rQmfImag = pWorkBuffer + synQmf->no_channels;
+-
+- {
+- if (i ==
+- h_ps_d->bsData[h_ps_d->processSlot].mpeg.aEnvStartStop[env]) {
+- initSlotBasedRotation(h_ps_d, env,
+- hHeaderData->freqBandData.highSubband);
+- env++;
+- }
+-
+- ApplyPsSlot(
+- h_ps_d, /* parametric stereo decoder handle */
+- (pLowBandReal + i), /* one timeslot of left/mono channel */
+- (pLowBandImag + i), /* one timeslot of left/mono channel */
+- rQmfReal, /* one timeslot or right channel */
+- rQmfImag, /* one timeslot or right channel */
+- scaleFactorLowBand_no_ov,
+- (i < hSbrDec->LppTrans.pSettings->overlap)
+- ? scaleFactorLowBand_ov
+- : scaleFactorLowBand_no_ov,
+- scaleFactorHighBand, synQmf->lsb, synQmf->usb);
+-
+- outScalefactorL = outScalefactorR = 1; /* psDiffScale! (MPEG-PS) */
+- }
+-
+- sbrDecoder_drcApplySlot(/* right channel */
+- &hSbrDecRight->sbrDrcChannel, rQmfReal,
+- rQmfImag, i, synQmfRight->no_col, maxShift);
+-
+- outScalefactorR += maxShift;
+-
+- sbrDecoder_drcApplySlot(/* left channel */
+- &hSbrDec->sbrDrcChannel, *(pLowBandReal + i),
+- *(pLowBandImag + i), i, synQmf->no_col,
+- maxShift);
+-
+- outScalefactorL += maxShift;
+-
+- if (!(flags & SBRDEC_SKIP_QMF_SYN)) {
+- qmfSynthesisFilteringSlot(
+- synQmfRight, rQmfReal, /* QMF real buffer */
+- rQmfImag, /* QMF imag buffer */
+- outScalefactorL, outScalefactorL,
+- timeOutRight + (i * synQmf->no_channels * strideOut), strideOut,
+- pWorkBuffer);
+-
+- qmfSynthesisFilteringSlot(
+- synQmf, *(pLowBandReal + i), /* QMF real buffer */
+- *(pLowBandImag + i), /* QMF imag buffer */
+- outScalefactorR, outScalefactorR,
+- timeOut + (i * synQmf->no_channels * strideOut), strideOut,
+- pWorkBuffer);
+- }
+- } /* no_col loop i */
+-#if (QMF_MAX_SYNTHESIS_BANDS <= 64)
+- C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, 2 * QMF_MAX_SYNTHESIS_BANDS);
+-#else
+- C_AALLOC_STACK_END(pWorkBuffer, FIXP_DBL, 2 * QMF_MAX_SYNTHESIS_BANDS);
+-#endif
+- }
+- }
+-
+- sbrDecoder_drcUpdateChannel(&hSbrDec->sbrDrcChannel);
+-
+- /*
+- Update overlap buffer
+- Even bands above usb are copied to avoid outdated spectral data in case
+- the stop frequency raises.
+- */
+-
+- if (!(flags & SBRDEC_SKIP_QMF_SYN)) {
+- {
+- FDK_QmfDomain_SaveOverlap(hSbrDec->qmfDomainInCh, 0);
+- FDK_ASSERT(hSbrDec->qmfDomainInCh->scaling.ov_lb_scale == saveLbScale);
+- }
+- }
+-
+- hSbrDec->savedStates = 0;
+-
+- /* Save current frame status */
+- hPrevFrameData->frameErrorFlag = hHeaderData->frameErrorFlag;
+- hSbrDec->applySbrProc_old = applyProcessing;
+-
+-} /* sbr_dec() */
+-
+-/*!
+- \brief Creates sbr decoder structure
+- \return errorCode, 0 if successful
+-*/
+-SBR_ERROR
+-createSbrDec(SBR_CHANNEL *hSbrChannel,
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- TRANSPOSER_SETTINGS *pSettings,
+- const int downsampleFac, /*!< Downsampling factor */
+- const UINT qmfFlags, /*!< flags -> 1: HQ/LP selector, 2: CLDFB */
+- const UINT flags, const int overlap,
+- int chan, /*!< Channel for which to assign buffers etc. */
+- int codecFrameSize)
+-
+-{
+- SBR_ERROR err = SBRDEC_OK;
+- int timeSlots =
+- hHeaderData->numberTimeSlots; /* Number of SBR slots per frame */
+- int noCols =
+- timeSlots * hHeaderData->timeStep; /* Number of QMF slots per frame */
+- HANDLE_SBR_DEC hs = &(hSbrChannel->SbrDec);
+-
+-#if (SBRDEC_MAX_HB_FADE_FRAMES > 0)
+- hs->highBandFadeCnt = SBRDEC_MAX_HB_FADE_FRAMES;
+-
+-#endif
+- hs->scale_hbe = 15;
+- hs->scale_lb = 15;
+- hs->scale_ov = 15;
+-
+- hs->prev_frame_lSbr = 0;
+- hs->prev_frame_hbeSbr = 0;
+-
+- hs->codecFrameSize = codecFrameSize;
+-
+- /*
+- create envelope calculator
+- */
+- err = createSbrEnvelopeCalc(&hs->SbrCalculateEnvelope, hHeaderData, chan,
+- flags);
+- if (err != SBRDEC_OK) {
+- return err;
+- }
+-
+- initSbrPrevFrameData(&hSbrChannel->prevFrameData, timeSlots);
+-
+- /*
+- create transposer
+- */
+- err = createLppTransposer(
+- &hs->LppTrans, pSettings, hHeaderData->freqBandData.lowSubband,
+- hHeaderData->freqBandData.v_k_master, hHeaderData->freqBandData.numMaster,
+- hHeaderData->freqBandData.highSubband, timeSlots, noCols,
+- hHeaderData->freqBandData.freqBandTableNoise,
+- hHeaderData->freqBandData.nNfb, hHeaderData->sbrProcSmplRate, chan,
+- overlap);
+- if (err != SBRDEC_OK) {
+- return err;
+- }
+-
+- if (flags & SBRDEC_USAC_HARMONICSBR) {
+- int noChannels, bSbr41 = flags & SBRDEC_QUAD_RATE ? 1 : 0;
+-
+- noChannels =
+- QMF_SYNTH_CHANNELS /
+- ((bSbr41 + 1) * 2); /* 32 for (32:64 and 24:64) and 16 for 16:64 */
+-
+- /* shared memory between hbeLightTimeDelayBuffer and hQmfHBESlotsReal if
+- * SBRDEC_HBE_ENABLE */
+- hSbrChannel->SbrDec.tmp_memory = (FIXP_DBL **)fdkCallocMatrix2D_aligned(
+- noCols, noChannels, sizeof(FIXP_DBL));
+- if (hSbrChannel->SbrDec.tmp_memory == NULL) {
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- hSbrChannel->SbrDec.hQmfHBESlotsReal = hSbrChannel->SbrDec.tmp_memory;
+- hSbrChannel->SbrDec.hQmfHBESlotsImag =
+- (FIXP_DBL **)fdkCallocMatrix2D_aligned(noCols, noChannels,
+- sizeof(FIXP_DBL));
+- if (hSbrChannel->SbrDec.hQmfHBESlotsImag == NULL) {
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- /* buffers containing unmodified qmf data; required when switching from
+- * legacy SBR to HBE */
+- /* buffer can be used as LPCFilterstates buffer because legacy SBR needs
+- * exactly these values for LPC filtering */
+- hSbrChannel->SbrDec.codecQMFBufferReal =
+- (FIXP_DBL **)fdkCallocMatrix2D_aligned(noCols, noChannels,
+- sizeof(FIXP_DBL));
+- if (hSbrChannel->SbrDec.codecQMFBufferReal == NULL) {
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- hSbrChannel->SbrDec.codecQMFBufferImag =
+- (FIXP_DBL **)fdkCallocMatrix2D_aligned(noCols, noChannels,
+- sizeof(FIXP_DBL));
+- if (hSbrChannel->SbrDec.codecQMFBufferImag == NULL) {
+- return SBRDEC_MEM_ALLOC_FAILED;
+- }
+-
+- err = QmfTransposerCreate(&hs->hHBE, codecFrameSize, 0, bSbr41);
+- if (err != SBRDEC_OK) {
+- return err;
+- }
+- }
+-
+- return err;
+-}
+-
+-/*!
+- \brief Delete sbr decoder structure
+- \return errorCode, 0 if successful
+-*/
+-int deleteSbrDec(SBR_CHANNEL *hSbrChannel) {
+- HANDLE_SBR_DEC hs = &hSbrChannel->SbrDec;
+-
+- deleteSbrEnvelopeCalc(&hs->SbrCalculateEnvelope);
+-
+- if (hs->tmp_memory != NULL) {
+- FDK_FREE_MEMORY_2D_ALIGNED(hs->tmp_memory);
+- }
+-
+- /* modify here */
+- FDK_FREE_MEMORY_2D_ALIGNED(hs->hQmfHBESlotsImag);
+-
+- if (hs->hHBE != NULL) QmfTransposerClose(hs->hHBE);
+-
+- if (hs->codecQMFBufferReal != NULL) {
+- FDK_FREE_MEMORY_2D_ALIGNED(hs->codecQMFBufferReal);
+- }
+-
+- if (hs->codecQMFBufferImag != NULL) {
+- FDK_FREE_MEMORY_2D_ALIGNED(hs->codecQMFBufferImag);
+- }
+-
+- return 0;
+-}
+-
+-/*!
+- \brief resets sbr decoder structure
+- \return errorCode, 0 if successful
+-*/
+-SBR_ERROR
+-resetSbrDec(HANDLE_SBR_DEC hSbrDec, HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_PREV_FRAME_DATA hPrevFrameData, const int downsampleFac,
+- const UINT flags, HANDLE_SBR_FRAME_DATA hFrameData) {
+- SBR_ERROR sbrError = SBRDEC_OK;
+- int i;
+- FIXP_DBL *pLowBandReal[128];
+- FIXP_DBL *pLowBandImag[128];
+- int useLP = flags & SBRDEC_LOW_POWER;
+-
+- int old_lsb = hSbrDec->qmfDomainInCh->fb.lsb;
+- int old_usb = hSbrDec->qmfDomainInCh->fb.usb;
+- int new_lsb = hHeaderData->freqBandData.lowSubband;
+- /* int new_usb = hHeaderData->freqBandData.highSubband; */
+- int l, startBand, stopBand, startSlot, size;
+-
+- FIXP_DBL **OverlapBufferReal = hSbrDec->qmfDomainInCh->hQmfSlotsReal;
+- FIXP_DBL **OverlapBufferImag = hSbrDec->qmfDomainInCh->hQmfSlotsImag;
+-
+- /* in case the previous frame was not active in terms of SBR processing, the
+- full band from 0 to no_channels was rescaled and not overwritten. Thats why
+- the scaling factor lb_scale can be seen as assigned to all bands from 0 to
+- no_channels in the previous frame. The same states for the current frame if
+- the current frame is not active in terms of SBR processing
+- */
+- int applySbrProc = (hHeaderData->syncState == SBR_ACTIVE ||
+- (hHeaderData->frameErrorFlag == 0 &&
+- hHeaderData->syncState == SBR_HEADER));
+- int applySbrProc_old = hSbrDec->applySbrProc_old;
+-
+- if (!applySbrProc) {
+- new_lsb = (hSbrDec->qmfDomainInCh->fb).no_channels;
+- }
+- if (!applySbrProc_old) {
+- old_lsb = (hSbrDec->qmfDomainInCh->fb).no_channels;
+- old_usb = old_lsb;
+- }
+-
+- resetSbrEnvelopeCalc(&hSbrDec->SbrCalculateEnvelope);
+-
+- /* Change lsb and usb */
+- /* Synthesis */
+- FDK_ASSERT(hSbrDec->qmfDomainOutCh != NULL);
+- hSbrDec->qmfDomainOutCh->fb.lsb =
+- fixMin((INT)hSbrDec->qmfDomainOutCh->fb.no_channels,
+- (INT)hHeaderData->freqBandData.lowSubband);
+- hSbrDec->qmfDomainOutCh->fb.usb =
+- fixMin((INT)hSbrDec->qmfDomainOutCh->fb.no_channels,
+- (INT)hHeaderData->freqBandData.highSubband);
+- /* Analysis */
+- FDK_ASSERT(hSbrDec->qmfDomainInCh != NULL);
+- hSbrDec->qmfDomainInCh->fb.lsb = hSbrDec->qmfDomainOutCh->fb.lsb;
+- hSbrDec->qmfDomainInCh->fb.usb = hSbrDec->qmfDomainOutCh->fb.usb;
+-
+- /*
+- The following initialization of spectral data in the overlap buffer
+- is required for dynamic x-over or a change of the start-freq for 2 reasons:
+-
+- 1. If the lowband gets _wider_, unadjusted data would remain
+-
+- 2. If the lowband becomes _smaller_, the highest bands of the old lowband
+- must be cleared because the whitening would be affected
+- */
+- startBand = old_lsb;
+- stopBand = new_lsb;
+- startSlot = fMax(0, hHeaderData->timeStep * (hPrevFrameData->stopPos -
+- hHeaderData->numberTimeSlots));
+- size = fMax(0, stopBand - startBand);
+-
+- /* in case of USAC we don't want to zero out the memory, as this can lead to
+- holes in the spectrum; fix shall only be applied for USAC not for MPEG-4
+- SBR, in this case setting zero remains */
+- if (!(flags & SBRDEC_SYNTAX_USAC)) {
+- /* keep already adjusted data in the x-over-area */
+- if (!useLP) {
+- for (l = startSlot; l < hSbrDec->LppTrans.pSettings->overlap; l++) {
+- FDKmemclear(&OverlapBufferReal[l][startBand], size * sizeof(FIXP_DBL));
+- FDKmemclear(&OverlapBufferImag[l][startBand], size * sizeof(FIXP_DBL));
+- }
+- } else {
+- for (l = startSlot; l < hSbrDec->LppTrans.pSettings->overlap; l++) {
+- FDKmemclear(&OverlapBufferReal[l][startBand], size * sizeof(FIXP_DBL));
+- }
+- }
+-
+- /*
+- reset LPC filter states
+- */
+- startBand = fixMin(old_lsb, new_lsb);
+- stopBand = fixMax(old_lsb, new_lsb);
+- size = fixMax(0, stopBand - startBand);
+-
+- FDKmemclear(&hSbrDec->LppTrans.lpcFilterStatesRealLegSBR[0][startBand],
+- size * sizeof(FIXP_DBL));
+- FDKmemclear(&hSbrDec->LppTrans.lpcFilterStatesRealLegSBR[1][startBand],
+- size * sizeof(FIXP_DBL));
+- if (!useLP) {
+- FDKmemclear(&hSbrDec->LppTrans.lpcFilterStatesImagLegSBR[0][startBand],
+- size * sizeof(FIXP_DBL));
+- FDKmemclear(&hSbrDec->LppTrans.lpcFilterStatesImagLegSBR[1][startBand],
+- size * sizeof(FIXP_DBL));
+- }
+- }
+-
+- if (startSlot != 0) {
+- int source_exp, target_exp, delta_exp, target_lsb, target_usb, reserve;
+- FIXP_DBL maxVal;
+-
+- /*
+- Rescale already processed spectral data between old and new x-over
+- frequency. This must be done because of the separate scalefactors for
+- lowband and highband.
+- */
+-
+- /* We have four relevant transitions to cover:
+- 1. old_usb is lower than new_lsb; old SBR area is completely below new SBR
+- area.
+- -> entire old area was highband and belongs to lowband now
+- and has to be rescaled.
+- 2. old_lsb is higher than new_usb; new SBR area is completely below old SBR
+- area.
+- -> old area between new_lsb and old_lsb was lowband and belongs to
+- highband now and has to be rescaled to match new highband scale.
+- 3. old_lsb is lower and old_usb is higher than new_lsb; old and new SBR
+- areas overlap.
+- -> old area between old_lsb and new_lsb was highband and belongs to
+- lowband now and has to be rescaled to match new lowband scale.
+- 4. new_lsb is lower and new_usb_is higher than old_lsb; old and new SBR
+- areas overlap.
+- -> old area between new_lsb and old_usb was lowband and belongs to
+- highband now and has to be rescaled to match new highband scale.
+- */
+-
+- if (new_lsb > old_lsb) {
+- /* case 1 and 3 */
+- source_exp = SCALE2EXP(hSbrDec->qmfDomainInCh->scaling.ov_hb_scale);
+- target_exp = SCALE2EXP(hSbrDec->qmfDomainInCh->scaling.ov_lb_scale);
+-
+- startBand = old_lsb;
+-
+- if (new_lsb >= old_usb) {
+- /* case 1 */
+- stopBand = old_usb;
+- } else {
+- /* case 3 */
+- stopBand = new_lsb;
+- }
+-
+- target_lsb = 0;
+- target_usb = old_lsb;
+- } else {
+- /* case 2 and 4 */
+- source_exp = SCALE2EXP(hSbrDec->qmfDomainInCh->scaling.ov_lb_scale);
+- target_exp = SCALE2EXP(hSbrDec->qmfDomainInCh->scaling.ov_hb_scale);
+-
+- startBand = new_lsb;
+- stopBand = old_lsb;
+-
+- target_lsb = old_lsb;
+- target_usb = old_usb;
+- }
+-
+- maxVal =
+- maxSubbandSample(OverlapBufferReal, (useLP) ? NULL : OverlapBufferImag,
+- startBand, stopBand, 0, startSlot);
+-
+- reserve = ((LONG)maxVal != 0 ? CntLeadingZeros(maxVal) - 1 : 0);
+- reserve = fixMin(
+- reserve,
+- DFRACT_BITS - 1 -
+- EXP2SCALE(
+- source_exp)); /* what is this line for, why do we need it? */
+-
+- /* process only if x-over-area is not dominant after rescale;
+- otherwise I'm not sure if all buffers are scaled correctly;
+- */
+- if (target_exp - (source_exp - reserve) >= 0) {
+- rescaleSubbandSamples(OverlapBufferReal,
+- (useLP) ? NULL : OverlapBufferImag, startBand,
+- stopBand, 0, startSlot, reserve);
+- source_exp -= reserve;
+- }
+-
+- delta_exp = target_exp - source_exp;
+-
+- if (delta_exp < 0) { /* x-over-area is dominant */
+- startBand = target_lsb;
+- stopBand = target_usb;
+- delta_exp = -delta_exp;
+-
+- if (new_lsb > old_lsb) {
+- /* The lowband has to be rescaled */
+- hSbrDec->qmfDomainInCh->scaling.ov_lb_scale = EXP2SCALE(source_exp);
+- } else {
+- /* The highband has to be rescaled */
+- hSbrDec->qmfDomainInCh->scaling.ov_hb_scale = EXP2SCALE(source_exp);
+- }
+- }
+-
+- FDK_ASSERT(startBand <= stopBand);
+-
+- if (!useLP) {
+- for (l = 0; l < startSlot; l++) {
+- scaleValues(OverlapBufferReal[l] + startBand, stopBand - startBand,
+- -delta_exp);
+- scaleValues(OverlapBufferImag[l] + startBand, stopBand - startBand,
+- -delta_exp);
+- }
+- } else
+- for (l = 0; l < startSlot; l++) {
+- scaleValues(OverlapBufferReal[l] + startBand, stopBand - startBand,
+- -delta_exp);
+- }
+- } /* startSlot != 0 */
+-
+- /*
+- Initialize transposer and limiter
+- */
+- sbrError = resetLppTransposer(
+- &hSbrDec->LppTrans, hHeaderData->freqBandData.lowSubband,
+- hHeaderData->freqBandData.v_k_master, hHeaderData->freqBandData.numMaster,
+- hHeaderData->freqBandData.freqBandTableNoise,
+- hHeaderData->freqBandData.nNfb, hHeaderData->freqBandData.highSubband,
+- hHeaderData->sbrProcSmplRate);
+- if (sbrError != SBRDEC_OK) return sbrError;
+-
+- hSbrDec->savedStates = 0;
+-
+- if ((flags & SBRDEC_USAC_HARMONICSBR) && applySbrProc) {
+- sbrError = QmfTransposerReInit(hSbrDec->hHBE,
+- hHeaderData->freqBandData.freqBandTable,
+- hHeaderData->freqBandData.nSfb);
+- if (sbrError != SBRDEC_OK) return sbrError;
+-
+- /* copy saved states from previous frame to legacy SBR lpc filterstate
+- * buffer */
+- for (i = 0; i < LPC_ORDER + hSbrDec->LppTrans.pSettings->overlap; i++) {
+- FDKmemcpy(
+- hSbrDec->LppTrans.lpcFilterStatesRealLegSBR[i],
+- hSbrDec->codecQMFBufferReal[hSbrDec->hHBE->noCols - LPC_ORDER -
+- hSbrDec->LppTrans.pSettings->overlap + i],
+- hSbrDec->hHBE->noChannels * sizeof(FIXP_DBL));
+- FDKmemcpy(
+- hSbrDec->LppTrans.lpcFilterStatesImagLegSBR[i],
+- hSbrDec->codecQMFBufferImag[hSbrDec->hHBE->noCols - LPC_ORDER -
+- hSbrDec->LppTrans.pSettings->overlap + i],
+- hSbrDec->hHBE->noChannels * sizeof(FIXP_DBL));
+- }
+- hSbrDec->savedStates = 1;
+-
+- {
+- /* map QMF buffer to pointer array (Overlap + Frame)*/
+- for (i = 0; i < hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER; i++) {
+- pLowBandReal[i] = hSbrDec->LppTrans.lpcFilterStatesRealHBE[i];
+- pLowBandImag[i] = hSbrDec->LppTrans.lpcFilterStatesImagHBE[i];
+- }
+-
+- /* map QMF buffer to pointer array (Overlap + Frame)*/
+- for (i = 0; i < hSbrDec->hHBE->noCols; i++) {
+- pLowBandReal[i + hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER] =
+- hSbrDec->codecQMFBufferReal[i];
+- pLowBandImag[i + hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER] =
+- hSbrDec->codecQMFBufferImag[i];
+- }
+-
+- if (flags & SBRDEC_QUAD_RATE) {
+- if (hFrameData->sbrPatchingMode == 0) {
+- int *xOverQmf = GetxOverBandQmfTransposer(hSbrDec->hHBE);
+-
+- /* in case of harmonic SBR and no HBE_LP map additional buffer for
+- one more frame to pointer arry */
+- for (i = 0; i < hSbrDec->hHBE->noCols / 2; i++) {
+- pLowBandReal[i + hSbrDec->hHBE->noCols +
+- hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER] =
+- hSbrDec->hQmfHBESlotsReal[i];
+- pLowBandImag[i + hSbrDec->hHBE->noCols +
+- hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER] =
+- hSbrDec->hQmfHBESlotsImag[i];
+- }
+-
+- QmfTransposerApply(
+- hSbrDec->hHBE,
+- pLowBandReal + hSbrDec->LppTrans.pSettings->overlap +
+- hSbrDec->hHBE->noCols / 2 + LPC_ORDER,
+- pLowBandImag + hSbrDec->LppTrans.pSettings->overlap +
+- hSbrDec->hHBE->noCols / 2 + LPC_ORDER,
+- hSbrDec->hHBE->noCols, pLowBandReal, pLowBandImag,
+- hSbrDec->LppTrans.lpcFilterStatesRealHBE,
+- hSbrDec->LppTrans.lpcFilterStatesImagHBE,
+- hPrevFrameData->prevSbrPitchInBins, hSbrDec->scale_lb,
+- hSbrDec->scale_hbe, &hSbrDec->qmfDomainInCh->scaling.hb_scale,
+- hHeaderData->timeStep, hFrameData->frameInfo.borders[0],
+- hSbrDec->LppTrans.pSettings->overlap, KEEP_STATES_SYNCED_OUTDIFF);
+-
+- copyHarmonicSpectrum(
+- xOverQmf, pLowBandReal, pLowBandImag, hSbrDec->hHBE->noCols,
+- hSbrDec->LppTrans.pSettings->overlap, KEEP_STATES_SYNCED_OUTDIFF);
+- }
+- } else {
+- /* in case of harmonic SBR and no HBE_LP map additional buffer for
+- one more frame to pointer arry */
+- for (i = 0; i < hSbrDec->hHBE->noCols; i++) {
+- pLowBandReal[i + hSbrDec->hHBE->noCols +
+- hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER] =
+- hSbrDec->hQmfHBESlotsReal[i];
+- pLowBandImag[i + hSbrDec->hHBE->noCols +
+- hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER] =
+- hSbrDec->hQmfHBESlotsImag[i];
+- }
+-
+- if (hFrameData->sbrPatchingMode == 0) {
+- QmfTransposerApply(
+- hSbrDec->hHBE,
+- pLowBandReal + hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER,
+- pLowBandImag + hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER,
+- hSbrDec->hHBE->noCols, pLowBandReal, pLowBandImag,
+- hSbrDec->LppTrans.lpcFilterStatesRealHBE,
+- hSbrDec->LppTrans.lpcFilterStatesImagHBE,
+- 0 /* not required for keeping states updated in this frame*/,
+- hSbrDec->scale_lb, hSbrDec->scale_lb,
+- &hSbrDec->qmfDomainInCh->scaling.hb_scale, hHeaderData->timeStep,
+- hFrameData->frameInfo.borders[0],
+- hSbrDec->LppTrans.pSettings->overlap, KEEP_STATES_SYNCED_NOOUT);
+- }
+-
+- QmfTransposerApply(
+- hSbrDec->hHBE,
+- pLowBandReal + hSbrDec->LppTrans.pSettings->overlap +
+- hSbrDec->hHBE->noCols + LPC_ORDER,
+- pLowBandImag + hSbrDec->LppTrans.pSettings->overlap +
+- hSbrDec->hHBE->noCols + LPC_ORDER,
+- hSbrDec->hHBE->noCols, pLowBandReal, pLowBandImag,
+- hSbrDec->LppTrans.lpcFilterStatesRealHBE,
+- hSbrDec->LppTrans.lpcFilterStatesImagHBE,
+- hPrevFrameData->prevSbrPitchInBins, hSbrDec->scale_lb,
+- hSbrDec->scale_hbe, &hSbrDec->qmfDomainInCh->scaling.hb_scale,
+- hHeaderData->timeStep, hFrameData->frameInfo.borders[0],
+- hSbrDec->LppTrans.pSettings->overlap, KEEP_STATES_SYNCED_OUTDIFF);
+- }
+-
+- if (hFrameData->sbrPatchingMode == 0) {
+- for (i = startSlot; i < hSbrDec->LppTrans.pSettings->overlap; i++) {
+- /*
+- Store the unmodified qmf Slots values for upper part of spectrum
+- (required for LPC filtering) required if next frame is a HBE frame
+- */
+- FDKmemcpy(hSbrDec->qmfDomainInCh->hQmfSlotsReal[i],
+- hSbrDec->LppTrans.lpcFilterStatesRealHBE[i + LPC_ORDER],
+- (64) * sizeof(FIXP_DBL));
+- FDKmemcpy(hSbrDec->qmfDomainInCh->hQmfSlotsImag[i],
+- hSbrDec->LppTrans.lpcFilterStatesImagHBE[i + LPC_ORDER],
+- (64) * sizeof(FIXP_DBL));
+- }
+-
+- for (i = startSlot; i < hSbrDec->LppTrans.pSettings->overlap; i++) {
+- /*
+- Store the unmodified qmf Slots values for upper part of spectrum
+- (required for LPC filtering) required if next frame is a HBE frame
+- */
+- FDKmemcpy(
+- hSbrDec->qmfDomainInCh->hQmfSlotsReal[i],
+- hSbrDec->codecQMFBufferReal[hSbrDec->hHBE->noCols -
+- hSbrDec->LppTrans.pSettings->overlap +
+- i],
+- new_lsb * sizeof(FIXP_DBL));
+- FDKmemcpy(
+- hSbrDec->qmfDomainInCh->hQmfSlotsImag[i],
+- hSbrDec->codecQMFBufferImag[hSbrDec->hHBE->noCols -
+- hSbrDec->LppTrans.pSettings->overlap +
+- i],
+- new_lsb * sizeof(FIXP_DBL));
+- }
+- }
+- }
+- }
+-
+- {
+- int adapt_lb = 0, diff = 0,
+- new_scale = hSbrDec->qmfDomainInCh->scaling.ov_lb_scale;
+-
+- if ((hSbrDec->qmfDomainInCh->scaling.ov_lb_scale !=
+- hSbrDec->qmfDomainInCh->scaling.lb_scale) &&
+- startSlot != 0) {
+- /* we need to adapt spectrum to have equal scale factor, always larger
+- * than zero */
+- diff = SCALE2EXP(hSbrDec->qmfDomainInCh->scaling.ov_lb_scale) -
+- SCALE2EXP(hSbrDec->qmfDomainInCh->scaling.lb_scale);
+-
+- if (diff > 0) {
+- adapt_lb = 1;
+- diff = -diff;
+- new_scale = hSbrDec->qmfDomainInCh->scaling.ov_lb_scale;
+- }
+-
+- stopBand = new_lsb;
+- }
+-
+- if (hFrameData->sbrPatchingMode == 1) {
+- /* scale states from LegSBR filterstates buffer */
+- for (i = 0; i < hSbrDec->LppTrans.pSettings->overlap + LPC_ORDER; i++) {
+- scaleValues(hSbrDec->LppTrans.lpcFilterStatesRealLegSBR[i], new_lsb,
+- diff);
+- if (!useLP) {
+- scaleValues(hSbrDec->LppTrans.lpcFilterStatesImagLegSBR[i], new_lsb,
+- diff);
+- }
+- }
+-
+- if (flags & SBRDEC_SYNTAX_USAC) {
+- /* get missing states between old and new x_over from LegSBR
+- * filterstates buffer */
+- /* in case of legacy SBR we leave these values zeroed out */
+- for (i = startSlot; i < hSbrDec->LppTrans.pSettings->overlap; i++) {
+- FDKmemcpy(&OverlapBufferReal[i][old_lsb],
+- &hSbrDec->LppTrans
+- .lpcFilterStatesRealLegSBR[LPC_ORDER + i][old_lsb],
+- fMax(new_lsb - old_lsb, 0) * sizeof(FIXP_DBL));
+- if (!useLP) {
+- FDKmemcpy(&OverlapBufferImag[i][old_lsb],
+- &hSbrDec->LppTrans
+- .lpcFilterStatesImagLegSBR[LPC_ORDER + i][old_lsb],
+- fMax(new_lsb - old_lsb, 0) * sizeof(FIXP_DBL));
+- }
+- }
+- }
+-
+- if (new_lsb > old_lsb) {
+- stopBand = old_lsb;
+- }
+- }
+- if ((adapt_lb == 1) && (stopBand > startBand)) {
+- for (l = startSlot; l < hSbrDec->LppTrans.pSettings->overlap; l++) {
+- scaleValues(OverlapBufferReal[l] + startBand, stopBand - startBand,
+- diff);
+- if (!useLP) {
+- scaleValues(OverlapBufferImag[l] + startBand, stopBand - startBand,
+- diff);
+- }
+- }
+- }
+- hSbrDec->qmfDomainInCh->scaling.ov_lb_scale = new_scale;
+- }
+-
+- sbrError = ResetLimiterBands(hHeaderData->freqBandData.limiterBandTable,
+- &hHeaderData->freqBandData.noLimiterBands,
+- hHeaderData->freqBandData.freqBandTable[0],
+- hHeaderData->freqBandData.nSfb[0],
+- hSbrDec->LppTrans.pSettings->patchParam,
+- hSbrDec->LppTrans.pSettings->noOfPatches,
+- hHeaderData->bs_data.limiterBands,
+- hFrameData->sbrPatchingMode,
+- GetxOverBandQmfTransposer(hSbrDec->hHBE),
+- Get41SbrQmfTransposer(hSbrDec->hHBE));
+-
+- hSbrDec->SbrCalculateEnvelope.sbrPatchingMode = hFrameData->sbrPatchingMode;
+-
+- return sbrError;
+-}
+diff --git a/libSBRdec/src/sbr_dec.h b/libSBRdec/src/sbr_dec.h
+deleted file mode 100644
+index 156da03..0000000
+--- a/libSBRdec/src/sbr_dec.h
++++ /dev/null
+@@ -1,204 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Sbr decoder
+-*/
+-#ifndef SBR_DEC_H
+-#define SBR_DEC_H
+-
+-#include "sbrdecoder.h"
+-
+-#include "lpp_tran.h"
+-#include "qmf.h"
+-#include "env_calc.h"
+-#include "FDK_audio.h"
+-
+-#include "sbrdec_drc.h"
+-
+-#include "pvc_dec.h"
+-
+-#include "hbe.h"
+-
+-enum SBRDEC_QMF_SKIP {
+- qmfSkipNothing = 0,
+- qmfSkipAnalysis = 1 << 0,
+- qmfSkipSynthesis = 1 << 1
+-};
+-
+-typedef struct {
+- SBR_CALCULATE_ENVELOPE SbrCalculateEnvelope;
+- SBR_LPP_TRANS LppTrans;
+- PVC_STATIC_DATA PvcStaticData;
+-
+- /* do scale handling in sbr an not in qmf */
+- SHORT scale_ov;
+- SHORT scale_lb;
+- SHORT scale_hbe;
+-
+- SHORT prev_frame_lSbr;
+- SHORT prev_frame_hbeSbr;
+-
+- int codecFrameSize;
+-
+- HANDLE_HBE_TRANSPOSER hHBE;
+-
+- HANDLE_FDK_QMF_DOMAIN_IN qmfDomainInCh;
+- HANDLE_FDK_QMF_DOMAIN_OUT qmfDomainOutCh;
+-
+- SBRDEC_DRC_CHANNEL sbrDrcChannel;
+-
+-#if (SBRDEC_MAX_HB_FADE_FRAMES > 0)
+- INT highBandFadeCnt; /* counter for fading in high-band signal smoothly */
+-
+-#endif
+- FIXP_DBL **tmp_memory; /* shared memory between hbeLightTimeDelayBuffer and
+- hQmfHBESlotsReal */
+-
+- FIXP_DBL **hQmfHBESlotsReal;
+- FIXP_DBL **hQmfHBESlotsImag;
+-
+- FIXP_DBL **codecQMFBufferReal;
+- FIXP_DBL **codecQMFBufferImag;
+- UCHAR savedStates;
+- int applySbrProc_old;
+-} SBR_DEC;
+-
+-typedef SBR_DEC *HANDLE_SBR_DEC;
+-
+-typedef struct {
+- SBR_FRAME_DATA frameData[(1) + 1];
+- SBR_PREV_FRAME_DATA prevFrameData;
+- SBR_DEC SbrDec;
+-} SBR_CHANNEL;
+-
+-typedef SBR_CHANNEL *HANDLE_SBR_CHANNEL;
+-
+-void sbr_dec(
+- HANDLE_SBR_DEC hSbrDec, /*!< handle to Decoder channel */
+- INT_PCM *timeIn, /*!< pointer to input time signal */
+- INT_PCM *timeOut, /*!< pointer to output time signal */
+- HANDLE_SBR_DEC hSbrDecRight, /*!< handle to Decoder channel right */
+- INT_PCM *timeOutRight, /*!< pointer to output time signal */
+- INT strideOut, /*!< Time data traversal strideOut */
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Static control data */
+- HANDLE_SBR_FRAME_DATA hFrameData, /*!< Control data of current frame */
+- HANDLE_SBR_PREV_FRAME_DATA
+- hPrevFrameData, /*!< Some control data of last frame */
+- const int applyProcessing, /*!< Flag for SBR operation */
+- HANDLE_PS_DEC h_ps_d, const UINT flags, const int codecFrameSize);
+-
+-SBR_ERROR
+-createSbrDec(SBR_CHANNEL *hSbrChannel, HANDLE_SBR_HEADER_DATA hHeaderData,
+- TRANSPOSER_SETTINGS *pSettings, const int downsampleFac,
+- const UINT qmfFlags, const UINT flags, const int overlap, int chan,
+- int codecFrameSize);
+-
+-int deleteSbrDec(SBR_CHANNEL *hSbrChannel);
+-
+-SBR_ERROR
+-resetSbrDec(HANDLE_SBR_DEC hSbrDec, HANDLE_SBR_HEADER_DATA hHeaderData,
+- HANDLE_SBR_PREV_FRAME_DATA hPrevFrameData, const int downsampleFac,
+- const UINT flags, HANDLE_SBR_FRAME_DATA hFrameData);
+-
+-#endif
+diff --git a/libSBRdec/src/sbr_ram.cpp b/libSBRdec/src/sbr_ram.cpp
+deleted file mode 100644
+index 8b35fd2..0000000
+--- a/libSBRdec/src/sbr_ram.cpp
++++ /dev/null
+@@ -1,191 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Memory layout
+-
+- This module declares all static and dynamic memory spaces
+-*/
+-
+-#include "sbr_ram.h"
+-
+-#define WORKBUFFER1_TAG 2
+-#define WORKBUFFER2_TAG 3
+-
+-/*!
+- \name StaticSbrData
+-
+- Static memory areas, must not be overwritten in other sections of the decoder
+-*/
+-/* @{ */
+-
+-/*! SBR Decoder main structure */
+-C_ALLOC_MEM(Ram_SbrDecoder, struct SBR_DECODER_INSTANCE, 1)
+-/*! SBR Decoder element data <br>
+- Dimension: (8) */
+-C_ALLOC_MEM2(Ram_SbrDecElement, SBR_DECODER_ELEMENT, 1, (8))
+-/*! SBR Decoder individual channel data <br>
+- Dimension: (8) */
+-C_ALLOC_MEM2(Ram_SbrDecChannel, SBR_CHANNEL, 1, (8) + 1)
+-
+-/*! Static Data of PS */
+-
+-C_ALLOC_MEM(Ram_ps_dec, struct PS_DEC, 1)
+-
+-/* @} */
+-
+-/*!
+- \name DynamicSbrData
+-
+- Dynamic memory areas, might be reused in other algorithm sections,
+- e.g. the core decoder
+- <br>
+- Depending on the mode set by DONT_USE_CORE_WORKBUFFER, workbuffers are
+- defined additionally to the CoreWorkbuffer.
+- <br>
+- The size of WorkBuffers is ((1024) / (32) * (4) / 2)*(64) = 2048.
+- <br>
+- WorkBuffer2 is a pointer to the CoreWorkBuffer wich is reused here in the SBR
+- part. In case of DONT_USE_CORE_WORKBUFFER, the CoreWorkbuffer is not used and
+- the according Workbuffer2 is defined locally in this file. <br> WorkBuffer1 is
+- reused in the AAC core (-> aacdecoder.cpp, aac_ram.cpp) <br>
+-
+- Use of WorkBuffers:
+- <pre>
+-
+- -------------------------------------------------------------
+- AAC core:
+-
+- CoreWorkbuffer: spectral coefficients
+- WorkBuffer1: CAacDecoderChannelInfo, CAacDecoderDynamicData
+-
+- -------------------------------------------------------------
+- SBR part:
+- ----------------------------------------------
+- Low Power Mode (useLP=1 or LOW_POWER_SBR_ONLY), see assignLcTimeSlots()
+-
+- SLOT_BASED_PROTOTYPE_SYN_FILTER
+-
+- WorkBuffer1 WorkBuffer2(=CoreWorkbuffer)
+- ________________ ________________
+- | RealLeft | | RealRight |
+- |________________| |________________|
+-
+- ----------------------------------------------
+- High Quality Mode (!LOW_POWER_SBR_ONLY and useLP=0), see
+- assignHqTimeSlots()
+-
+- SLOTBASED_PS
+-
+- WorkBuffer1 WorkBuffer2(=CoreWorkbuffer)
+- ________________ ________________
+- | Real/Imag | interleaved | Real/Imag |
+- interleaved
+- |________________| first half actual ch |________________| second
+- half actual ch
+-
+- -------------------------------------------------------------
+-
+- </pre>
+-
+-*/
+diff --git a/libSBRdec/src/sbr_ram.h b/libSBRdec/src/sbr_ram.h
+deleted file mode 100644
+index e00f8b5..0000000
+--- a/libSBRdec/src/sbr_ram.h
++++ /dev/null
+@@ -1,186 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+-\file
+-\brief Memory layout
+-*/
+-#ifndef SBR_RAM_H
+-#define SBR_RAM_H
+-
+-#include "sbrdecoder.h"
+-
+-#include "env_extr.h"
+-#include "sbr_dec.h"
+-
+-#define SBRDEC_MAX_CH_PER_ELEMENT (2)
+-
+-#define FRAME_OK (0)
+-#define FRAME_ERROR (1)
+-#define FRAME_ERROR_ALLSLOTS (2)
+-
+-typedef struct {
+- SBR_CHANNEL *pSbrChannel[SBRDEC_MAX_CH_PER_ELEMENT];
+- TRANSPOSER_SETTINGS
+- transposerSettings; /* Common transport settings for each individual
+- channel of an element */
+- HANDLE_FDK_BITSTREAM hBs;
+-
+- MP4_ELEMENT_ID
+- elementID; /* Element ID set during initialization. Can be used for
+- concealment */
+- int nChannels; /* Number of elements output channels (=2 in case of PS) */
+-
+- UCHAR frameErrorFlag[(1) + 1]; /* Frame error status (for every slot in the
+- delay line). Will be copied into header at
+- the very beginning of decodeElement()
+- routine. */
+-
+- UCHAR useFrameSlot; /* Index which defines which slot will be decoded/filled
+- next (used with additional delay) */
+- UCHAR useHeaderSlot[(1) + 1]; /* Index array that provides the link between
+- header and frame data (important when
+- processing with additional delay). */
+-} SBR_DECODER_ELEMENT;
+-
+-struct SBR_DECODER_INSTANCE {
+- SBR_DECODER_ELEMENT *pSbrElement[(8)];
+- SBR_HEADER_DATA sbrHeader[(
+- 8)][(1) + 1]; /* Sbr header for each individual channel of an element */
+-
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain;
+-
+- HANDLE_PS_DEC hParametricStereoDec;
+-
+- /* Global parameters */
+- AUDIO_OBJECT_TYPE coreCodec; /* AOT of core codec */
+- int numSbrElements;
+- int numSbrChannels;
+- INT sampleRateIn; /* SBR decoder input sampling rate; might be different than
+- the transposer input sampling rate. */
+- INT sampleRateOut; /* Sampling rate of the SBR decoder output audio samples.
+- */
+- USHORT codecFrameSize;
+- UCHAR synDownsampleFac;
+- INT downscaleFactor;
+- UCHAR numDelayFrames; /* The current number of additional delay frames used
+- for processing. */
+- UCHAR harmonicSBR;
+- UCHAR
+- numFlushedFrames; /* The variable counts the number of frames which are
+- flushed consecutively. */
+-
+- UINT flags;
+-};
+-
+-H_ALLOC_MEM(Ram_SbrDecElement, SBR_DECODER_ELEMENT)
+-H_ALLOC_MEM(Ram_SbrDecChannel, SBR_CHANNEL)
+-H_ALLOC_MEM(Ram_SbrDecoder, struct SBR_DECODER_INSTANCE)
+-
+-H_ALLOC_MEM(Ram_sbr_QmfStatesSynthesis, FIXP_QSS)
+-H_ALLOC_MEM(Ram_sbr_OverlapBuffer, FIXP_DBL)
+-
+-H_ALLOC_MEM(Ram_sbr_HBEOverlapBuffer, FIXP_DBL)
+-
+-H_ALLOC_MEM(Ram_ps_dec, PS_DEC)
+-
+-#endif /* SBR_RAM_H */
+diff --git a/libSBRdec/src/sbr_rom.cpp b/libSBRdec/src/sbr_rom.cpp
+deleted file mode 100644
+index 8a6688a..0000000
+--- a/libSBRdec/src/sbr_rom.cpp
++++ /dev/null
+@@ -1,1705 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Definition of constant tables
+-
+- This module contains most of the constant data that can be stored in ROM.
+-*/
+-
+-#include "sbr_rom.h"
+-
+-/*!
+- \name StartStopBands
+- \brief Start and stop subbands of the highband.
+-
+- k_o = startMin + offset[bs_start_freq];
+- startMin = {3000,4000,5000} * (128/FS_sbr) / FS_sbr < 32Khz, 32Khz <= FS_sbr <
+- 64KHz, 64KHz <= FS_sbr The stop subband can also be calculated to save memory
+- by defining #CALC_STOP_BAND.
+-*/
+-//@{
+-/* tables were created with ../addon/octave/sbr_start_freq_table.m */
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_16[][16] = {
+- {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
+- {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_22[][16] = {
+- {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 28, 30},
+- {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_24[][16] = {
+- {11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 27, 29, 32},
+- {3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 19, 21, 24}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_32[][16] = {
+- {10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 27, 29, 32},
+- {2, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 19, 21, 24}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_40[][16] = {
+- {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 28, 30, 32},
+- {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 19, 21, 23, 25}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_44[][16] = {
+- {8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 23, 25, 28, 32},
+- {2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 17, 19, 22, 26}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_48[][16] = {
+- {7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 27, 31},
+- {1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 21, 25}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_64[][16] = {
+- {6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 21, 23, 26, 30},
+- {1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 21, 25}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_88[][16] = {
+- {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 23, 27, 31},
+- {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 20, 24, 28}};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_192[16] = {
+- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 19, 23, 27};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_176[16] = {
+- 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 20, 24, 28};
+-const UCHAR FDK_sbrDecoder_sbr_start_freq_128[16] = {
+- 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 21, 25};
+-
+-//@}
+-
+-/*!
+- \name Whitening
+- \brief Coefficients for spectral whitening in the transposer
+-*/
+-//@{
+-/*! Assignment of whitening tuning depending on the crossover frequency */
+-const USHORT FDK_sbrDecoder_sbr_whFactorsIndex[NUM_WHFACTOR_TABLE_ENTRIES] = {
+- 0, 5000, 6000, 6500, 7000, 7500, 8000, 9000, 10000};
+-
+-/*!
+- \brief Whithening levels tuning table
+-
+- With the current tuning, there are some redundant entries:
+-
+- \li NUM_WHFACTOR_TABLE_ENTRIES can be reduced by 3,
+- \li the first coloumn can be eliminated.
+-
+-*/
+-const FIXP_DBL
+- FDK_sbrDecoder_sbr_whFactorsTable[NUM_WHFACTOR_TABLE_ENTRIES][6] = {
+- /* OFF_LEVEL, TRANSITION_LEVEL, LOW_LEVEL, MID_LEVEL, HIGH_LEVEL */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* < 5000 */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* 5000 < 6000 */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* 6000 < 6500 */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* 6500 < 7000 */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* 7000 < 7500 */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* 7500 < 8000 */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* 8000 < 9000 */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* 9000 < 10000 */
+- {FL2FXCONST_DBL(0.00f), FL2FXCONST_DBL(0.6f), FL2FXCONST_DBL(0.75f),
+- FL2FXCONST_DBL(0.90f), FL2FXCONST_DBL(0.98f)}, /* > 10000 */
+-};
+-
+-//@}
+-
+-/*!
+- \name EnvAdj
+- \brief Constants and tables used for envelope adjustment
+-*/
+-//@{
+-
+-/*! Mantissas of gain limits */
+-const FIXP_SGL FDK_sbrDecoder_sbr_limGains_m[4] = {
+- FL2FXCONST_SGL(0.5011932025f), /*!< -3 dB. Gain limit when limiterGains in
+- frameData is 0 */
+- FL2FXCONST_SGL(
+- 0.5f), /*!< 0 dB. Gain limit when limiterGains in frameData is 1 */
+- FL2FXCONST_SGL(0.9976346258f), /*!< +3 dB. Gain limit when limiterGains in
+- frameData is 2 */
+- FL2FXCONST_SGL(0.6776263578f) /*!< Inf. Gain limit when limiterGains in
+- frameData is 3 */
+-};
+-
+-/*! Exponents of gain limits */
+-const UCHAR FDK_sbrDecoder_sbr_limGains_e[4] = {0, 1, 1, 67};
+-
+-/*! Constants for calculating the number of limiter bands */
+-const FIXP_SGL FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4[4] = {
+- FL2FXCONST_SGL(1.0f / 4.0f), FL2FXCONST_SGL(1.2f / 4.0f),
+- FL2FXCONST_SGL(2.0f / 4.0f), FL2FXCONST_SGL(3.0f / 4.0f)};
+-
+-/*! Constants for calculating the number of limiter bands */
+-const FIXP_DBL FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4_DBL[4] = {
+- FL2FXCONST_DBL(1.0f / 4.0f), FL2FXCONST_DBL(1.2f / 4.0f),
+- FL2FXCONST_DBL(2.0f / 4.0f), FL2FXCONST_DBL(3.0f / 4.0f)};
+-
+-/*! Ratio of old gains and noise levels for the first 4 timeslots of an envelope
+- */
+-const FIXP_SGL FDK_sbrDecoder_sbr_smoothFilter[4] = {
+- FL2FXCONST_SGL(0.66666666666666f), FL2FXCONST_SGL(0.36516383427084f),
+- FL2FXCONST_SGL(0.14699433520835f), FL2FXCONST_SGL(0.03183050093751f)};
+-
+-/*! Real and imaginary part of random noise which will be modulated
+- to the desired level. An accuracy of 13 bits is sufficient for these
+- random numbers.
+-*/
+-const FIXP_SGL FDK_sbrDecoder_sbr_randomPhase[SBR_NF_NO_RANDOM_VAL][2] = {
+- {FL2FXCONST_SGL(-0.99948153278296f / 8.0),
+- FL2FXCONST_SGL(-0.59483417516607f / 8.0)},
+- {FL2FXCONST_SGL(0.97113454393991f / 8.0),
+- FL2FXCONST_SGL(-0.67528515225647f / 8.0)},
+- {FL2FXCONST_SGL(0.14130051758487f / 8.0),
+- FL2FXCONST_SGL(-0.95090983575689f / 8.0)},
+- {FL2FXCONST_SGL(-0.47005496701697f / 8.0),
+- FL2FXCONST_SGL(-0.37340549728647f / 8.0)},
+- {FL2FXCONST_SGL(0.80705063769351f / 8.0),
+- FL2FXCONST_SGL(0.29653668284408f / 8.0)},
+- {FL2FXCONST_SGL(-0.38981478896926f / 8.0),
+- FL2FXCONST_SGL(0.89572605717087f / 8.0)},
+- {FL2FXCONST_SGL(-0.01053049862020f / 8.0),
+- FL2FXCONST_SGL(-0.66959058036166f / 8.0)},
+- {FL2FXCONST_SGL(-0.91266367957293f / 8.0),
+- FL2FXCONST_SGL(-0.11522938140034f / 8.0)},
+- {FL2FXCONST_SGL(0.54840422910309f / 8.0),
+- FL2FXCONST_SGL(0.75221367176302f / 8.0)},
+- {FL2FXCONST_SGL(0.40009252867955f / 8.0),
+- FL2FXCONST_SGL(-0.98929400334421f / 8.0)},
+- {FL2FXCONST_SGL(-0.99867974711855f / 8.0),
+- FL2FXCONST_SGL(-0.88147068645358f / 8.0)},
+- {FL2FXCONST_SGL(-0.95531076805040f / 8.0),
+- FL2FXCONST_SGL(0.90908757154593f / 8.0)},
+- {FL2FXCONST_SGL(-0.45725933317144f / 8.0),
+- FL2FXCONST_SGL(-0.56716323646760f / 8.0)},
+- {FL2FXCONST_SGL(-0.72929675029275f / 8.0),
+- FL2FXCONST_SGL(-0.98008272727324f / 8.0)},
+- {FL2FXCONST_SGL(0.75622801399036f / 8.0),
+- FL2FXCONST_SGL(0.20950329995549f / 8.0)},
+- {FL2FXCONST_SGL(0.07069442601050f / 8.0),
+- FL2FXCONST_SGL(-0.78247898470706f / 8.0)},
+- {FL2FXCONST_SGL(0.74496252926055f / 8.0),
+- FL2FXCONST_SGL(-0.91169004445807f / 8.0)},
+- {FL2FXCONST_SGL(-0.96440182703856f / 8.0),
+- FL2FXCONST_SGL(-0.94739918296622f / 8.0)},
+- {FL2FXCONST_SGL(0.30424629369539f / 8.0),
+- FL2FXCONST_SGL(-0.49438267012479f / 8.0)},
+- {FL2FXCONST_SGL(0.66565033746925f / 8.0),
+- FL2FXCONST_SGL(0.64652935542491f / 8.0)},
+- {FL2FXCONST_SGL(0.91697008020594f / 8.0),
+- FL2FXCONST_SGL(0.17514097332009f / 8.0)},
+- {FL2FXCONST_SGL(-0.70774918760427f / 8.0),
+- FL2FXCONST_SGL(0.52548653416543f / 8.0)},
+- {FL2FXCONST_SGL(-0.70051415345560f / 8.0),
+- FL2FXCONST_SGL(-0.45340028808763f / 8.0)},
+- {FL2FXCONST_SGL(-0.99496513054797f / 8.0),
+- FL2FXCONST_SGL(-0.90071908066973f / 8.0)},
+- {FL2FXCONST_SGL(0.98164490790123f / 8.0),
+- FL2FXCONST_SGL(-0.77463155528697f / 8.0)},
+- {FL2FXCONST_SGL(-0.54671580548181f / 8.0),
+- FL2FXCONST_SGL(-0.02570928536004f / 8.0)},
+- {FL2FXCONST_SGL(-0.01689629065389f / 8.0),
+- FL2FXCONST_SGL(0.00287506445732f / 8.0)},
+- {FL2FXCONST_SGL(-0.86110349531986f / 8.0),
+- FL2FXCONST_SGL(0.42548583726477f / 8.0)},
+- {FL2FXCONST_SGL(-0.98892980586032f / 8.0),
+- FL2FXCONST_SGL(-0.87881132267556f / 8.0)},
+- {FL2FXCONST_SGL(0.51756627678691f / 8.0),
+- FL2FXCONST_SGL(0.66926784710139f / 8.0)},
+- {FL2FXCONST_SGL(-0.99635026409640f / 8.0),
+- FL2FXCONST_SGL(-0.58107730574765f / 8.0)},
+- {FL2FXCONST_SGL(-0.99969370862163f / 8.0),
+- FL2FXCONST_SGL(0.98369989360250f / 8.0)},
+- {FL2FXCONST_SGL(0.55266258627194f / 8.0),
+- FL2FXCONST_SGL(0.59449057465591f / 8.0)},
+- {FL2FXCONST_SGL(0.34581177741673f / 8.0),
+- FL2FXCONST_SGL(0.94879421061866f / 8.0)},
+- {FL2FXCONST_SGL(0.62664209577999f / 8.0),
+- FL2FXCONST_SGL(-0.74402970906471f / 8.0)},
+- {FL2FXCONST_SGL(-0.77149701404973f / 8.0),
+- FL2FXCONST_SGL(-0.33883658042801f / 8.0)},
+- {FL2FXCONST_SGL(-0.91592244254432f / 8.0),
+- FL2FXCONST_SGL(0.03687901376713f / 8.0)},
+- {FL2FXCONST_SGL(-0.76285492357887f / 8.0),
+- FL2FXCONST_SGL(-0.91371867919124f / 8.0)},
+- {FL2FXCONST_SGL(0.79788337195331f / 8.0),
+- FL2FXCONST_SGL(-0.93180971199849f / 8.0)},
+- {FL2FXCONST_SGL(0.54473080610200f / 8.0),
+- FL2FXCONST_SGL(-0.11919206037186f / 8.0)},
+- {FL2FXCONST_SGL(-0.85639281671058f / 8.0),
+- FL2FXCONST_SGL(0.42429854760451f / 8.0)},
+- {FL2FXCONST_SGL(-0.92882402971423f / 8.0),
+- FL2FXCONST_SGL(0.27871809078609f / 8.0)},
+- {FL2FXCONST_SGL(-0.11708371046774f / 8.0),
+- FL2FXCONST_SGL(-0.99800843444966f / 8.0)},
+- {FL2FXCONST_SGL(0.21356749817493f / 8.0),
+- FL2FXCONST_SGL(-0.90716295627033f / 8.0)},
+- {FL2FXCONST_SGL(-0.76191692573909f / 8.0),
+- FL2FXCONST_SGL(0.99768118356265f / 8.0)},
+- {FL2FXCONST_SGL(0.98111043100884f / 8.0),
+- FL2FXCONST_SGL(-0.95854459734407f / 8.0)},
+- {FL2FXCONST_SGL(-0.85913269895572f / 8.0),
+- FL2FXCONST_SGL(0.95766566168880f / 8.0)},
+- {FL2FXCONST_SGL(-0.93307242253692f / 8.0),
+- FL2FXCONST_SGL(0.49431757696466f / 8.0)},
+- {FL2FXCONST_SGL(0.30485754879632f / 8.0),
+- FL2FXCONST_SGL(-0.70540034357529f / 8.0)},
+- {FL2FXCONST_SGL(0.85289650925190f / 8.0),
+- FL2FXCONST_SGL(0.46766131791044f / 8.0)},
+- {FL2FXCONST_SGL(0.91328082618125f / 8.0),
+- FL2FXCONST_SGL(-0.99839597361769f / 8.0)},
+- {FL2FXCONST_SGL(-0.05890199924154f / 8.0),
+- FL2FXCONST_SGL(0.70741827819497f / 8.0)},
+- {FL2FXCONST_SGL(0.28398686150148f / 8.0),
+- FL2FXCONST_SGL(0.34633555702188f / 8.0)},
+- {FL2FXCONST_SGL(0.95258164539612f / 8.0),
+- FL2FXCONST_SGL(-0.54893416026939f / 8.0)},
+- {FL2FXCONST_SGL(-0.78566324168507f / 8.0),
+- FL2FXCONST_SGL(-0.75568541079691f / 8.0)},
+- {FL2FXCONST_SGL(-0.95789495447877f / 8.0),
+- FL2FXCONST_SGL(-0.20423194696966f / 8.0)},
+- {FL2FXCONST_SGL(0.82411158711197f / 8.0),
+- FL2FXCONST_SGL(0.96654618432562f / 8.0)},
+- {FL2FXCONST_SGL(-0.65185446735885f / 8.0),
+- FL2FXCONST_SGL(-0.88734990773289f / 8.0)},
+- {FL2FXCONST_SGL(-0.93643603134666f / 8.0),
+- FL2FXCONST_SGL(0.99870790442385f / 8.0)},
+- {FL2FXCONST_SGL(0.91427159529618f / 8.0),
+- FL2FXCONST_SGL(-0.98290505544444f / 8.0)},
+- {FL2FXCONST_SGL(-0.70395684036886f / 8.0),
+- FL2FXCONST_SGL(0.58796798221039f / 8.0)},
+- {FL2FXCONST_SGL(0.00563771969365f / 8.0),
+- FL2FXCONST_SGL(0.61768196727244f / 8.0)},
+- {FL2FXCONST_SGL(0.89065051931895f / 8.0),
+- FL2FXCONST_SGL(0.52783352697585f / 8.0)},
+- {FL2FXCONST_SGL(-0.68683707712762f / 8.0),
+- FL2FXCONST_SGL(0.80806944710339f / 8.0)},
+- {FL2FXCONST_SGL(0.72165342518718f / 8.0),
+- FL2FXCONST_SGL(-0.69259857349564f / 8.0)},
+- {FL2FXCONST_SGL(-0.62928247730667f / 8.0),
+- FL2FXCONST_SGL(0.13627037407335f / 8.0)},
+- {FL2FXCONST_SGL(0.29938434065514f / 8.0),
+- FL2FXCONST_SGL(-0.46051329682246f / 8.0)},
+- {FL2FXCONST_SGL(-0.91781958879280f / 8.0),
+- FL2FXCONST_SGL(-0.74012716684186f / 8.0)},
+- {FL2FXCONST_SGL(0.99298717043688f / 8.0),
+- FL2FXCONST_SGL(0.40816610075661f / 8.0)},
+- {FL2FXCONST_SGL(0.82368298622748f / 8.0),
+- FL2FXCONST_SGL(-0.74036047190173f / 8.0)},
+- {FL2FXCONST_SGL(-0.98512833386833f / 8.0),
+- FL2FXCONST_SGL(-0.99972330709594f / 8.0)},
+- {FL2FXCONST_SGL(-0.95915368242257f / 8.0),
+- FL2FXCONST_SGL(-0.99237800466040f / 8.0)},
+- {FL2FXCONST_SGL(-0.21411126572790f / 8.0),
+- FL2FXCONST_SGL(-0.93424819052545f / 8.0)},
+- {FL2FXCONST_SGL(-0.68821476106884f / 8.0),
+- FL2FXCONST_SGL(-0.26892306315457f / 8.0)},
+- {FL2FXCONST_SGL(0.91851997982317f / 8.0),
+- FL2FXCONST_SGL(0.09358228901785f / 8.0)},
+- {FL2FXCONST_SGL(-0.96062769559127f / 8.0),
+- FL2FXCONST_SGL(0.36099095133739f / 8.0)},
+- {FL2FXCONST_SGL(0.51646184922287f / 8.0),
+- FL2FXCONST_SGL(-0.71373332873917f / 8.0)},
+- {FL2FXCONST_SGL(0.61130721139669f / 8.0),
+- FL2FXCONST_SGL(0.46950141175917f / 8.0)},
+- {FL2FXCONST_SGL(0.47336129371299f / 8.0),
+- FL2FXCONST_SGL(-0.27333178296162f / 8.0)},
+- {FL2FXCONST_SGL(0.90998308703519f / 8.0),
+- FL2FXCONST_SGL(0.96715662938132f / 8.0)},
+- {FL2FXCONST_SGL(0.44844799194357f / 8.0),
+- FL2FXCONST_SGL(0.99211574628306f / 8.0)},
+- {FL2FXCONST_SGL(0.66614891079092f / 8.0),
+- FL2FXCONST_SGL(0.96590176169121f / 8.0)},
+- {FL2FXCONST_SGL(0.74922239129237f / 8.0),
+- FL2FXCONST_SGL(-0.89879858826087f / 8.0)},
+- {FL2FXCONST_SGL(-0.99571588506485f / 8.0),
+- FL2FXCONST_SGL(0.52785521494349f / 8.0)},
+- {FL2FXCONST_SGL(0.97401082477563f / 8.0),
+- FL2FXCONST_SGL(-0.16855870075190f / 8.0)},
+- {FL2FXCONST_SGL(0.72683747733879f / 8.0),
+- FL2FXCONST_SGL(-0.48060774432251f / 8.0)},
+- {FL2FXCONST_SGL(0.95432193457128f / 8.0),
+- FL2FXCONST_SGL(0.68849603408441f / 8.0)},
+- {FL2FXCONST_SGL(-0.72962208425191f / 8.0),
+- FL2FXCONST_SGL(-0.76608443420917f / 8.0)},
+- {FL2FXCONST_SGL(-0.85359479233537f / 8.0),
+- FL2FXCONST_SGL(0.88738125901579f / 8.0)},
+- {FL2FXCONST_SGL(-0.81412430338535f / 8.0),
+- FL2FXCONST_SGL(-0.97480768049637f / 8.0)},
+- {FL2FXCONST_SGL(-0.87930772356786f / 8.0),
+- FL2FXCONST_SGL(0.74748307690436f / 8.0)},
+- {FL2FXCONST_SGL(-0.71573331064977f / 8.0),
+- FL2FXCONST_SGL(-0.98570608178923f / 8.0)},
+- {FL2FXCONST_SGL(0.83524300028228f / 8.0),
+- FL2FXCONST_SGL(0.83702537075163f / 8.0)},
+- {FL2FXCONST_SGL(-0.48086065601423f / 8.0),
+- FL2FXCONST_SGL(-0.98848504923531f / 8.0)},
+- {FL2FXCONST_SGL(0.97139128574778f / 8.0),
+- FL2FXCONST_SGL(0.80093621198236f / 8.0)},
+- {FL2FXCONST_SGL(0.51992825347895f / 8.0),
+- FL2FXCONST_SGL(0.80247631400510f / 8.0)},
+- {FL2FXCONST_SGL(-0.00848591195325f / 8.0),
+- FL2FXCONST_SGL(-0.76670128000486f / 8.0)},
+- {FL2FXCONST_SGL(-0.70294374303036f / 8.0),
+- FL2FXCONST_SGL(0.55359910445577f / 8.0)},
+- {FL2FXCONST_SGL(-0.95894428168140f / 8.0),
+- FL2FXCONST_SGL(-0.43265504344783f / 8.0)},
+- {FL2FXCONST_SGL(0.97079252950321f / 8.0),
+- FL2FXCONST_SGL(0.09325857238682f / 8.0)},
+- {FL2FXCONST_SGL(-0.92404293670797f / 8.0),
+- FL2FXCONST_SGL(0.85507704027855f / 8.0)},
+- {FL2FXCONST_SGL(-0.69506469500450f / 8.0),
+- FL2FXCONST_SGL(0.98633412625459f / 8.0)},
+- {FL2FXCONST_SGL(0.26559203620024f / 8.0),
+- FL2FXCONST_SGL(0.73314307966524f / 8.0)},
+- {FL2FXCONST_SGL(0.28038443336943f / 8.0),
+- FL2FXCONST_SGL(0.14537913654427f / 8.0)},
+- {FL2FXCONST_SGL(-0.74138124825523f / 8.0),
+- FL2FXCONST_SGL(0.99310339807762f / 8.0)},
+- {FL2FXCONST_SGL(-0.01752795995444f / 8.0),
+- FL2FXCONST_SGL(-0.82616635284178f / 8.0)},
+- {FL2FXCONST_SGL(-0.55126773094930f / 8.0),
+- FL2FXCONST_SGL(-0.98898543862153f / 8.0)},
+- {FL2FXCONST_SGL(0.97960898850996f / 8.0),
+- FL2FXCONST_SGL(-0.94021446752851f / 8.0)},
+- {FL2FXCONST_SGL(-0.99196309146936f / 8.0),
+- FL2FXCONST_SGL(0.67019017358456f / 8.0)},
+- {FL2FXCONST_SGL(-0.67684928085260f / 8.0),
+- FL2FXCONST_SGL(0.12631491649378f / 8.0)},
+- {FL2FXCONST_SGL(0.09140039465500f / 8.0),
+- FL2FXCONST_SGL(-0.20537731453108f / 8.0)},
+- {FL2FXCONST_SGL(-0.71658965751996f / 8.0),
+- FL2FXCONST_SGL(-0.97788200391224f / 8.0)},
+- {FL2FXCONST_SGL(0.81014640078925f / 8.0),
+- FL2FXCONST_SGL(0.53722648362443f / 8.0)},
+- {FL2FXCONST_SGL(0.40616991671205f / 8.0),
+- FL2FXCONST_SGL(-0.26469008598449f / 8.0)},
+- {FL2FXCONST_SGL(-0.67680188682972f / 8.0),
+- FL2FXCONST_SGL(0.94502052337695f / 8.0)},
+- {FL2FXCONST_SGL(0.86849774348749f / 8.0),
+- FL2FXCONST_SGL(-0.18333598647899f / 8.0)},
+- {FL2FXCONST_SGL(-0.99500381284851f / 8.0),
+- FL2FXCONST_SGL(-0.02634122068550f / 8.0)},
+- {FL2FXCONST_SGL(0.84329189340667f / 8.0),
+- FL2FXCONST_SGL(0.10406957462213f / 8.0)},
+- {FL2FXCONST_SGL(-0.09215968531446f / 8.0),
+- FL2FXCONST_SGL(0.69540012101253f / 8.0)},
+- {FL2FXCONST_SGL(0.99956173327206f / 8.0),
+- FL2FXCONST_SGL(-0.12358542001404f / 8.0)},
+- {FL2FXCONST_SGL(-0.79732779473535f / 8.0),
+- FL2FXCONST_SGL(-0.91582524736159f / 8.0)},
+- {FL2FXCONST_SGL(0.96349973642406f / 8.0),
+- FL2FXCONST_SGL(0.96640458041000f / 8.0)},
+- {FL2FXCONST_SGL(-0.79942778496547f / 8.0),
+- FL2FXCONST_SGL(0.64323902822857f / 8.0)},
+- {FL2FXCONST_SGL(-0.11566039853896f / 8.0),
+- FL2FXCONST_SGL(0.28587846253726f / 8.0)},
+- {FL2FXCONST_SGL(-0.39922954514662f / 8.0),
+- FL2FXCONST_SGL(0.94129601616966f / 8.0)},
+- {FL2FXCONST_SGL(0.99089197565987f / 8.0),
+- FL2FXCONST_SGL(-0.92062625581587f / 8.0)},
+- {FL2FXCONST_SGL(0.28631285179909f / 8.0),
+- FL2FXCONST_SGL(-0.91035047143603f / 8.0)},
+- {FL2FXCONST_SGL(-0.83302725605608f / 8.0),
+- FL2FXCONST_SGL(-0.67330410892084f / 8.0)},
+- {FL2FXCONST_SGL(0.95404443402072f / 8.0),
+- FL2FXCONST_SGL(0.49162765398743f / 8.0)},
+- {FL2FXCONST_SGL(-0.06449863579434f / 8.0),
+- FL2FXCONST_SGL(0.03250560813135f / 8.0)},
+- {FL2FXCONST_SGL(-0.99575054486311f / 8.0),
+- FL2FXCONST_SGL(0.42389784469507f / 8.0)},
+- {FL2FXCONST_SGL(-0.65501142790847f / 8.0),
+- FL2FXCONST_SGL(0.82546114655624f / 8.0)},
+- {FL2FXCONST_SGL(-0.81254441908887f / 8.0),
+- FL2FXCONST_SGL(-0.51627234660629f / 8.0)},
+- {FL2FXCONST_SGL(-0.99646369485481f / 8.0),
+- FL2FXCONST_SGL(0.84490533520752f / 8.0)},
+- {FL2FXCONST_SGL(0.00287840603348f / 8.0),
+- FL2FXCONST_SGL(0.64768261158166f / 8.0)},
+- {FL2FXCONST_SGL(0.70176989408455f / 8.0),
+- FL2FXCONST_SGL(-0.20453028573322f / 8.0)},
+- {FL2FXCONST_SGL(0.96361882270190f / 8.0),
+- FL2FXCONST_SGL(0.40706967140989f / 8.0)},
+- {FL2FXCONST_SGL(-0.68883758192426f / 8.0),
+- FL2FXCONST_SGL(0.91338958840772f / 8.0)},
+- {FL2FXCONST_SGL(-0.34875585502238f / 8.0),
+- FL2FXCONST_SGL(0.71472290693300f / 8.0)},
+- {FL2FXCONST_SGL(0.91980081243087f / 8.0),
+- FL2FXCONST_SGL(0.66507455644919f / 8.0)},
+- {FL2FXCONST_SGL(-0.99009048343881f / 8.0),
+- FL2FXCONST_SGL(0.85868021604848f / 8.0)},
+- {FL2FXCONST_SGL(0.68865791458395f / 8.0),
+- FL2FXCONST_SGL(0.55660316809678f / 8.0)},
+- {FL2FXCONST_SGL(-0.99484402129368f / 8.0),
+- FL2FXCONST_SGL(-0.20052559254934f / 8.0)},
+- {FL2FXCONST_SGL(0.94214511408023f / 8.0),
+- FL2FXCONST_SGL(-0.99696425367461f / 8.0)},
+- {FL2FXCONST_SGL(-0.67414626793544f / 8.0),
+- FL2FXCONST_SGL(0.49548221180078f / 8.0)},
+- {FL2FXCONST_SGL(-0.47339353684664f / 8.0),
+- FL2FXCONST_SGL(-0.85904328834047f / 8.0)},
+- {FL2FXCONST_SGL(0.14323651387360f / 8.0),
+- FL2FXCONST_SGL(-0.94145598222488f / 8.0)},
+- {FL2FXCONST_SGL(-0.29268293575672f / 8.0),
+- FL2FXCONST_SGL(0.05759224927952f / 8.0)},
+- {FL2FXCONST_SGL(0.43793861458754f / 8.0),
+- FL2FXCONST_SGL(-0.78904969892724f / 8.0)},
+- {FL2FXCONST_SGL(-0.36345126374441f / 8.0),
+- FL2FXCONST_SGL(0.64874435357162f / 8.0)},
+- {FL2FXCONST_SGL(-0.08750604656825f / 8.0),
+- FL2FXCONST_SGL(0.97686944362527f / 8.0)},
+- {FL2FXCONST_SGL(-0.96495267812511f / 8.0),
+- FL2FXCONST_SGL(-0.53960305946511f / 8.0)},
+- {FL2FXCONST_SGL(0.55526940659947f / 8.0),
+- FL2FXCONST_SGL(0.78891523734774f / 8.0)},
+- {FL2FXCONST_SGL(0.73538215752630f / 8.0),
+- FL2FXCONST_SGL(0.96452072373404f / 8.0)},
+- {FL2FXCONST_SGL(-0.30889773919437f / 8.0),
+- FL2FXCONST_SGL(-0.80664389776860f / 8.0)},
+- {FL2FXCONST_SGL(0.03574995626194f / 8.0),
+- FL2FXCONST_SGL(-0.97325616900959f / 8.0)},
+- {FL2FXCONST_SGL(0.98720684660488f / 8.0),
+- FL2FXCONST_SGL(0.48409133691962f / 8.0)},
+- {FL2FXCONST_SGL(-0.81689296271203f / 8.0),
+- FL2FXCONST_SGL(-0.90827703628298f / 8.0)},
+- {FL2FXCONST_SGL(0.67866860118215f / 8.0),
+- FL2FXCONST_SGL(0.81284503870856f / 8.0)},
+- {FL2FXCONST_SGL(-0.15808569732583f / 8.0),
+- FL2FXCONST_SGL(0.85279555024382f / 8.0)},
+- {FL2FXCONST_SGL(0.80723395114371f / 8.0),
+- FL2FXCONST_SGL(-0.24717418514605f / 8.0)},
+- {FL2FXCONST_SGL(0.47788757329038f / 8.0),
+- FL2FXCONST_SGL(-0.46333147839295f / 8.0)},
+- {FL2FXCONST_SGL(0.96367554763201f / 8.0),
+- FL2FXCONST_SGL(0.38486749303242f / 8.0)},
+- {FL2FXCONST_SGL(-0.99143875716818f / 8.0),
+- FL2FXCONST_SGL(-0.24945277239809f / 8.0)},
+- {FL2FXCONST_SGL(0.83081876925833f / 8.0),
+- FL2FXCONST_SGL(-0.94780851414763f / 8.0)},
+- {FL2FXCONST_SGL(-0.58753191905341f / 8.0),
+- FL2FXCONST_SGL(0.01290772389163f / 8.0)},
+- {FL2FXCONST_SGL(0.95538108220960f / 8.0),
+- FL2FXCONST_SGL(-0.85557052096538f / 8.0)},
+- {FL2FXCONST_SGL(-0.96490920476211f / 8.0),
+- FL2FXCONST_SGL(-0.64020970923102f / 8.0)},
+- {FL2FXCONST_SGL(-0.97327101028521f / 8.0),
+- FL2FXCONST_SGL(0.12378128133110f / 8.0)},
+- {FL2FXCONST_SGL(0.91400366022124f / 8.0),
+- FL2FXCONST_SGL(0.57972471346930f / 8.0)},
+- {FL2FXCONST_SGL(-0.99925837363824f / 8.0),
+- FL2FXCONST_SGL(0.71084847864067f / 8.0)},
+- {FL2FXCONST_SGL(-0.86875903507313f / 8.0),
+- FL2FXCONST_SGL(-0.20291699203564f / 8.0)},
+- {FL2FXCONST_SGL(-0.26240034795124f / 8.0),
+- FL2FXCONST_SGL(-0.68264554369108f / 8.0)},
+- {FL2FXCONST_SGL(-0.24664412953388f / 8.0),
+- FL2FXCONST_SGL(-0.87642273115183f / 8.0)},
+- {FL2FXCONST_SGL(0.02416275806869f / 8.0),
+- FL2FXCONST_SGL(0.27192914288905f / 8.0)},
+- {FL2FXCONST_SGL(0.82068619590515f / 8.0),
+- FL2FXCONST_SGL(-0.85087787994476f / 8.0)},
+- {FL2FXCONST_SGL(0.88547373760759f / 8.0),
+- FL2FXCONST_SGL(-0.89636802901469f / 8.0)},
+- {FL2FXCONST_SGL(-0.18173078152226f / 8.0),
+- FL2FXCONST_SGL(-0.26152145156800f / 8.0)},
+- {FL2FXCONST_SGL(0.09355476558534f / 8.0),
+- FL2FXCONST_SGL(0.54845123045604f / 8.0)},
+- {FL2FXCONST_SGL(-0.54668414224090f / 8.0),
+- FL2FXCONST_SGL(0.95980774020221f / 8.0)},
+- {FL2FXCONST_SGL(0.37050990604091f / 8.0),
+- FL2FXCONST_SGL(-0.59910140383171f / 8.0)},
+- {FL2FXCONST_SGL(-0.70373594262891f / 8.0),
+- FL2FXCONST_SGL(0.91227665827081f / 8.0)},
+- {FL2FXCONST_SGL(-0.34600785879594f / 8.0),
+- FL2FXCONST_SGL(-0.99441426144200f / 8.0)},
+- {FL2FXCONST_SGL(-0.68774481731008f / 8.0),
+- FL2FXCONST_SGL(-0.30238837956299f / 8.0)},
+- {FL2FXCONST_SGL(-0.26843291251234f / 8.0),
+- FL2FXCONST_SGL(0.83115668004362f / 8.0)},
+- {FL2FXCONST_SGL(0.49072334613242f / 8.0),
+- FL2FXCONST_SGL(-0.45359708737775f / 8.0)},
+- {FL2FXCONST_SGL(0.38975993093975f / 8.0),
+- FL2FXCONST_SGL(0.95515358099121f / 8.0)},
+- {FL2FXCONST_SGL(-0.97757125224150f / 8.0),
+- FL2FXCONST_SGL(0.05305894580606f / 8.0)},
+- {FL2FXCONST_SGL(-0.17325552859616f / 8.0),
+- FL2FXCONST_SGL(-0.92770672250494f / 8.0)},
+- {FL2FXCONST_SGL(0.99948035025744f / 8.0),
+- FL2FXCONST_SGL(0.58285545563426f / 8.0)},
+- {FL2FXCONST_SGL(-0.64946246527458f / 8.0),
+- FL2FXCONST_SGL(0.68645507104960f / 8.0)},
+- {FL2FXCONST_SGL(-0.12016920576437f / 8.0),
+- FL2FXCONST_SGL(-0.57147322153312f / 8.0)},
+- {FL2FXCONST_SGL(-0.58947456517751f / 8.0),
+- FL2FXCONST_SGL(-0.34847132454388f / 8.0)},
+- {FL2FXCONST_SGL(-0.41815140454465f / 8.0),
+- FL2FXCONST_SGL(0.16276422358861f / 8.0)},
+- {FL2FXCONST_SGL(0.99885650204884f / 8.0),
+- FL2FXCONST_SGL(0.11136095490444f / 8.0)},
+- {FL2FXCONST_SGL(-0.56649614128386f / 8.0),
+- FL2FXCONST_SGL(-0.90494866361587f / 8.0)},
+- {FL2FXCONST_SGL(0.94138021032330f / 8.0),
+- FL2FXCONST_SGL(0.35281916733018f / 8.0)},
+- {FL2FXCONST_SGL(-0.75725076534641f / 8.0),
+- FL2FXCONST_SGL(0.53650549640587f / 8.0)},
+- {FL2FXCONST_SGL(0.20541973692630f / 8.0),
+- FL2FXCONST_SGL(-0.94435144369918f / 8.0)},
+- {FL2FXCONST_SGL(0.99980371023351f / 8.0),
+- FL2FXCONST_SGL(0.79835913565599f / 8.0)},
+- {FL2FXCONST_SGL(0.29078277605775f / 8.0),
+- FL2FXCONST_SGL(0.35393777921520f / 8.0)},
+- {FL2FXCONST_SGL(-0.62858772103030f / 8.0),
+- FL2FXCONST_SGL(0.38765693387102f / 8.0)},
+- {FL2FXCONST_SGL(0.43440904467688f / 8.0),
+- FL2FXCONST_SGL(-0.98546330463232f / 8.0)},
+- {FL2FXCONST_SGL(-0.98298583762390f / 8.0),
+- FL2FXCONST_SGL(0.21021524625209f / 8.0)},
+- {FL2FXCONST_SGL(0.19513029146934f / 8.0),
+- FL2FXCONST_SGL(-0.94239832251867f / 8.0)},
+- {FL2FXCONST_SGL(-0.95476662400101f / 8.0),
+- FL2FXCONST_SGL(0.98364554179143f / 8.0)},
+- {FL2FXCONST_SGL(0.93379635304810f / 8.0),
+- FL2FXCONST_SGL(-0.70881994583682f / 8.0)},
+- {FL2FXCONST_SGL(-0.85235410573336f / 8.0),
+- FL2FXCONST_SGL(-0.08342347966410f / 8.0)},
+- {FL2FXCONST_SGL(-0.86425093011245f / 8.0),
+- FL2FXCONST_SGL(-0.45795025029466f / 8.0)},
+- {FL2FXCONST_SGL(0.38879779059045f / 8.0),
+- FL2FXCONST_SGL(0.97274429344593f / 8.0)},
+- {FL2FXCONST_SGL(0.92045124735495f / 8.0),
+- FL2FXCONST_SGL(-0.62433652524220f / 8.0)},
+- {FL2FXCONST_SGL(0.89162532251878f / 8.0),
+- FL2FXCONST_SGL(0.54950955570563f / 8.0)},
+- {FL2FXCONST_SGL(-0.36834336949252f / 8.0),
+- FL2FXCONST_SGL(0.96458298020975f / 8.0)},
+- {FL2FXCONST_SGL(0.93891760988045f / 8.0),
+- FL2FXCONST_SGL(-0.89968353740388f / 8.0)},
+- {FL2FXCONST_SGL(0.99267657565094f / 8.0),
+- FL2FXCONST_SGL(-0.03757034316958f / 8.0)},
+- {FL2FXCONST_SGL(-0.94063471614176f / 8.0),
+- FL2FXCONST_SGL(0.41332338538963f / 8.0)},
+- {FL2FXCONST_SGL(0.99740224117019f / 8.0),
+- FL2FXCONST_SGL(-0.16830494996370f / 8.0)},
+- {FL2FXCONST_SGL(-0.35899413170555f / 8.0),
+- FL2FXCONST_SGL(-0.46633226649613f / 8.0)},
+- {FL2FXCONST_SGL(0.05237237274947f / 8.0),
+- FL2FXCONST_SGL(-0.25640361602661f / 8.0)},
+- {FL2FXCONST_SGL(0.36703583957424f / 8.0),
+- FL2FXCONST_SGL(-0.38653265641875f / 8.0)},
+- {FL2FXCONST_SGL(0.91653180367913f / 8.0),
+- FL2FXCONST_SGL(-0.30587628726597f / 8.0)},
+- {FL2FXCONST_SGL(0.69000803499316f / 8.0),
+- FL2FXCONST_SGL(0.90952171386132f / 8.0)},
+- {FL2FXCONST_SGL(-0.38658751133527f / 8.0),
+- FL2FXCONST_SGL(0.99501571208985f / 8.0)},
+- {FL2FXCONST_SGL(-0.29250814029851f / 8.0),
+- FL2FXCONST_SGL(0.37444994344615f / 8.0)},
+- {FL2FXCONST_SGL(-0.60182204677608f / 8.0),
+- FL2FXCONST_SGL(0.86779651036123f / 8.0)},
+- {FL2FXCONST_SGL(-0.97418588163217f / 8.0),
+- FL2FXCONST_SGL(0.96468523666475f / 8.0)},
+- {FL2FXCONST_SGL(0.88461574003963f / 8.0),
+- FL2FXCONST_SGL(0.57508405276414f / 8.0)},
+- {FL2FXCONST_SGL(0.05198933055162f / 8.0),
+- FL2FXCONST_SGL(0.21269661669964f / 8.0)},
+- {FL2FXCONST_SGL(-0.53499621979720f / 8.0),
+- FL2FXCONST_SGL(0.97241553731237f / 8.0)},
+- {FL2FXCONST_SGL(-0.49429560226497f / 8.0),
+- FL2FXCONST_SGL(0.98183865291903f / 8.0)},
+- {FL2FXCONST_SGL(-0.98935142339139f / 8.0),
+- FL2FXCONST_SGL(-0.40249159006933f / 8.0)},
+- {FL2FXCONST_SGL(-0.98081380091130f / 8.0),
+- FL2FXCONST_SGL(-0.72856895534041f / 8.0)},
+- {FL2FXCONST_SGL(-0.27338148835532f / 8.0),
+- FL2FXCONST_SGL(0.99950922447209f / 8.0)},
+- {FL2FXCONST_SGL(0.06310802338302f / 8.0),
+- FL2FXCONST_SGL(-0.54539587529618f / 8.0)},
+- {FL2FXCONST_SGL(-0.20461677199539f / 8.0),
+- FL2FXCONST_SGL(-0.14209977628489f / 8.0)},
+- {FL2FXCONST_SGL(0.66223843141647f / 8.0),
+- FL2FXCONST_SGL(0.72528579940326f / 8.0)},
+- {FL2FXCONST_SGL(-0.84764345483665f / 8.0),
+- FL2FXCONST_SGL(0.02372316801261f / 8.0)},
+- {FL2FXCONST_SGL(-0.89039863483811f / 8.0),
+- FL2FXCONST_SGL(0.88866581484602f / 8.0)},
+- {FL2FXCONST_SGL(0.95903308477986f / 8.0),
+- FL2FXCONST_SGL(0.76744927173873f / 8.0)},
+- {FL2FXCONST_SGL(0.73504123909879f / 8.0),
+- FL2FXCONST_SGL(-0.03747203173192f / 8.0)},
+- {FL2FXCONST_SGL(-0.31744434966056f / 8.0),
+- FL2FXCONST_SGL(-0.36834111883652f / 8.0)},
+- {FL2FXCONST_SGL(-0.34110827591623f / 8.0),
+- FL2FXCONST_SGL(0.40211222807691f / 8.0)},
+- {FL2FXCONST_SGL(0.47803883714199f / 8.0),
+- FL2FXCONST_SGL(-0.39423219786288f / 8.0)},
+- {FL2FXCONST_SGL(0.98299195879514f / 8.0),
+- FL2FXCONST_SGL(0.01989791390047f / 8.0)},
+- {FL2FXCONST_SGL(-0.30963073129751f / 8.0),
+- FL2FXCONST_SGL(-0.18076720599336f / 8.0)},
+- {FL2FXCONST_SGL(0.99992588229018f / 8.0),
+- FL2FXCONST_SGL(-0.26281872094289f / 8.0)},
+- {FL2FXCONST_SGL(-0.93149731080767f / 8.0),
+- FL2FXCONST_SGL(-0.98313162570490f / 8.0)},
+- {FL2FXCONST_SGL(0.99923472302773f / 8.0),
+- FL2FXCONST_SGL(-0.80142993767554f / 8.0)},
+- {FL2FXCONST_SGL(-0.26024169633417f / 8.0),
+- FL2FXCONST_SGL(-0.75999759855752f / 8.0)},
+- {FL2FXCONST_SGL(-0.35712514743563f / 8.0),
+- FL2FXCONST_SGL(0.19298963768574f / 8.0)},
+- {FL2FXCONST_SGL(-0.99899084509530f / 8.0),
+- FL2FXCONST_SGL(0.74645156992493f / 8.0)},
+- {FL2FXCONST_SGL(0.86557171579452f / 8.0),
+- FL2FXCONST_SGL(0.55593866696299f / 8.0)},
+- {FL2FXCONST_SGL(0.33408042438752f / 8.0),
+- FL2FXCONST_SGL(0.86185953874709f / 8.0)},
+- {FL2FXCONST_SGL(0.99010736374716f / 8.0),
+- FL2FXCONST_SGL(0.04602397576623f / 8.0)},
+- {FL2FXCONST_SGL(-0.66694269691195f / 8.0),
+- FL2FXCONST_SGL(-0.91643611810148f / 8.0)},
+- {FL2FXCONST_SGL(0.64016792079480f / 8.0),
+- FL2FXCONST_SGL(0.15649530836856f / 8.0)},
+- {FL2FXCONST_SGL(0.99570534804836f / 8.0),
+- FL2FXCONST_SGL(0.45844586038111f / 8.0)},
+- {FL2FXCONST_SGL(-0.63431466947340f / 8.0),
+- FL2FXCONST_SGL(0.21079116459234f / 8.0)},
+- {FL2FXCONST_SGL(-0.07706847005931f / 8.0),
+- FL2FXCONST_SGL(-0.89581437101329f / 8.0)},
+- {FL2FXCONST_SGL(0.98590090577724f / 8.0),
+- FL2FXCONST_SGL(0.88241721133981f / 8.0)},
+- {FL2FXCONST_SGL(0.80099335254678f / 8.0),
+- FL2FXCONST_SGL(-0.36851896710853f / 8.0)},
+- {FL2FXCONST_SGL(0.78368131392666f / 8.0),
+- FL2FXCONST_SGL(0.45506999802597f / 8.0)},
+- {FL2FXCONST_SGL(0.08707806671691f / 8.0),
+- FL2FXCONST_SGL(0.80938994918745f / 8.0)},
+- {FL2FXCONST_SGL(-0.86811883080712f / 8.0),
+- FL2FXCONST_SGL(0.39347308654705f / 8.0)},
+- {FL2FXCONST_SGL(-0.39466529740375f / 8.0),
+- FL2FXCONST_SGL(-0.66809432114456f / 8.0)},
+- {FL2FXCONST_SGL(0.97875325649683f / 8.0),
+- FL2FXCONST_SGL(-0.72467840967746f / 8.0)},
+- {FL2FXCONST_SGL(-0.95038560288864f / 8.0),
+- FL2FXCONST_SGL(0.89563219587625f / 8.0)},
+- {FL2FXCONST_SGL(0.17005239424212f / 8.0),
+- FL2FXCONST_SGL(0.54683053962658f / 8.0)},
+- {FL2FXCONST_SGL(-0.76910792026848f / 8.0),
+- FL2FXCONST_SGL(-0.96226617549298f / 8.0)},
+- {FL2FXCONST_SGL(0.99743281016846f / 8.0),
+- FL2FXCONST_SGL(0.42697157037567f / 8.0)},
+- {FL2FXCONST_SGL(0.95437383549973f / 8.0),
+- FL2FXCONST_SGL(0.97002324109952f / 8.0)},
+- {FL2FXCONST_SGL(0.99578905365569f / 8.0),
+- FL2FXCONST_SGL(-0.54106826257356f / 8.0)},
+- {FL2FXCONST_SGL(0.28058259829990f / 8.0),
+- FL2FXCONST_SGL(-0.85361420634036f / 8.0)},
+- {FL2FXCONST_SGL(0.85256524470573f / 8.0),
+- FL2FXCONST_SGL(-0.64567607735589f / 8.0)},
+- {FL2FXCONST_SGL(-0.50608540105128f / 8.0),
+- FL2FXCONST_SGL(-0.65846015480300f / 8.0)},
+- {FL2FXCONST_SGL(-0.97210735183243f / 8.0),
+- FL2FXCONST_SGL(-0.23095213067791f / 8.0)},
+- {FL2FXCONST_SGL(0.95424048234441f / 8.0),
+- FL2FXCONST_SGL(-0.99240147091219f / 8.0)},
+- {FL2FXCONST_SGL(-0.96926570524023f / 8.0),
+- FL2FXCONST_SGL(0.73775654896574f / 8.0)},
+- {FL2FXCONST_SGL(0.30872163214726f / 8.0),
+- FL2FXCONST_SGL(0.41514960556126f / 8.0)},
+- {FL2FXCONST_SGL(-0.24523839572639f / 8.0),
+- FL2FXCONST_SGL(0.63206633394807f / 8.0)},
+- {FL2FXCONST_SGL(-0.33813265086024f / 8.0),
+- FL2FXCONST_SGL(-0.38661779441897f / 8.0)},
+- {FL2FXCONST_SGL(-0.05826828420146f / 8.0),
+- FL2FXCONST_SGL(-0.06940774188029f / 8.0)},
+- {FL2FXCONST_SGL(-0.22898461455054f / 8.0),
+- FL2FXCONST_SGL(0.97054853316316f / 8.0)},
+- {FL2FXCONST_SGL(-0.18509915019881f / 8.0),
+- FL2FXCONST_SGL(0.47565762892084f / 8.0)},
+- {FL2FXCONST_SGL(-0.10488238045009f / 8.0),
+- FL2FXCONST_SGL(-0.87769947402394f / 8.0)},
+- {FL2FXCONST_SGL(-0.71886586182037f / 8.0),
+- FL2FXCONST_SGL(0.78030982480538f / 8.0)},
+- {FL2FXCONST_SGL(0.99793873738654f / 8.0),
+- FL2FXCONST_SGL(0.90041310491497f / 8.0)},
+- {FL2FXCONST_SGL(0.57563307626120f / 8.0),
+- FL2FXCONST_SGL(-0.91034337352097f / 8.0)},
+- {FL2FXCONST_SGL(0.28909646383717f / 8.0),
+- FL2FXCONST_SGL(0.96307783970534f / 8.0)},
+- {FL2FXCONST_SGL(0.42188998312520f / 8.0),
+- FL2FXCONST_SGL(0.48148651230437f / 8.0)},
+- {FL2FXCONST_SGL(0.93335049681047f / 8.0),
+- FL2FXCONST_SGL(-0.43537023883588f / 8.0)},
+- {FL2FXCONST_SGL(-0.97087374418267f / 8.0),
+- FL2FXCONST_SGL(0.86636445711364f / 8.0)},
+- {FL2FXCONST_SGL(0.36722871286923f / 8.0),
+- FL2FXCONST_SGL(0.65291654172961f / 8.0)},
+- {FL2FXCONST_SGL(-0.81093025665696f / 8.0),
+- FL2FXCONST_SGL(0.08778370229363f / 8.0)},
+- {FL2FXCONST_SGL(-0.26240603062237f / 8.0),
+- FL2FXCONST_SGL(-0.92774095379098f / 8.0)},
+- {FL2FXCONST_SGL(0.83996497984604f / 8.0),
+- FL2FXCONST_SGL(0.55839849139647f / 8.0)},
+- {FL2FXCONST_SGL(-0.99909615720225f / 8.0),
+- FL2FXCONST_SGL(-0.96024605713970f / 8.0)},
+- {FL2FXCONST_SGL(0.74649464155061f / 8.0),
+- FL2FXCONST_SGL(0.12144893606462f / 8.0)},
+- {FL2FXCONST_SGL(-0.74774595569805f / 8.0),
+- FL2FXCONST_SGL(-0.26898062008959f / 8.0)},
+- {FL2FXCONST_SGL(0.95781667469567f / 8.0),
+- FL2FXCONST_SGL(-0.79047927052628f / 8.0)},
+- {FL2FXCONST_SGL(0.95472308713099f / 8.0),
+- FL2FXCONST_SGL(-0.08588776019550f / 8.0)},
+- {FL2FXCONST_SGL(0.48708332746299f / 8.0),
+- FL2FXCONST_SGL(0.99999041579432f / 8.0)},
+- {FL2FXCONST_SGL(0.46332038247497f / 8.0),
+- FL2FXCONST_SGL(0.10964126185063f / 8.0)},
+- {FL2FXCONST_SGL(-0.76497004940162f / 8.0),
+- FL2FXCONST_SGL(0.89210929242238f / 8.0)},
+- {FL2FXCONST_SGL(0.57397389364339f / 8.0),
+- FL2FXCONST_SGL(0.35289703373760f / 8.0)},
+- {FL2FXCONST_SGL(0.75374316974495f / 8.0),
+- FL2FXCONST_SGL(0.96705214651335f / 8.0)},
+- {FL2FXCONST_SGL(-0.59174397685714f / 8.0),
+- FL2FXCONST_SGL(-0.89405370422752f / 8.0)},
+- {FL2FXCONST_SGL(0.75087906691890f / 8.0),
+- FL2FXCONST_SGL(-0.29612672982396f / 8.0)},
+- {FL2FXCONST_SGL(-0.98607857336230f / 8.0),
+- FL2FXCONST_SGL(0.25034911730023f / 8.0)},
+- {FL2FXCONST_SGL(-0.40761056640505f / 8.0),
+- FL2FXCONST_SGL(-0.90045573444695f / 8.0)},
+- {FL2FXCONST_SGL(0.66929266740477f / 8.0),
+- FL2FXCONST_SGL(0.98629493401748f / 8.0)},
+- {FL2FXCONST_SGL(-0.97463695257310f / 8.0),
+- FL2FXCONST_SGL(-0.00190223301301f / 8.0)},
+- {FL2FXCONST_SGL(0.90145509409859f / 8.0),
+- FL2FXCONST_SGL(0.99781390365446f / 8.0)},
+- {FL2FXCONST_SGL(-0.87259289048043f / 8.0),
+- FL2FXCONST_SGL(0.99233587353666f / 8.0)},
+- {FL2FXCONST_SGL(-0.91529461447692f / 8.0),
+- FL2FXCONST_SGL(-0.15698707534206f / 8.0)},
+- {FL2FXCONST_SGL(-0.03305738840705f / 8.0),
+- FL2FXCONST_SGL(-0.37205262859764f / 8.0)},
+- {FL2FXCONST_SGL(0.07223051368337f / 8.0),
+- FL2FXCONST_SGL(-0.88805001733626f / 8.0)},
+- {FL2FXCONST_SGL(0.99498012188353f / 8.0),
+- FL2FXCONST_SGL(0.97094358113387f / 8.0)},
+- {FL2FXCONST_SGL(-0.74904939500519f / 8.0),
+- FL2FXCONST_SGL(0.99985483641521f / 8.0)},
+- {FL2FXCONST_SGL(0.04585228574211f / 8.0),
+- FL2FXCONST_SGL(0.99812337444082f / 8.0)},
+- {FL2FXCONST_SGL(-0.89054954257993f / 8.0),
+- FL2FXCONST_SGL(-0.31791913188064f / 8.0)},
+- {FL2FXCONST_SGL(-0.83782144651251f / 8.0),
+- FL2FXCONST_SGL(0.97637632547466f / 8.0)},
+- {FL2FXCONST_SGL(0.33454804933804f / 8.0),
+- FL2FXCONST_SGL(-0.86231516800408f / 8.0)},
+- {FL2FXCONST_SGL(-0.99707579362824f / 8.0),
+- FL2FXCONST_SGL(0.93237990079441f / 8.0)},
+- {FL2FXCONST_SGL(-0.22827527843994f / 8.0),
+- FL2FXCONST_SGL(0.18874759397997f / 8.0)},
+- {FL2FXCONST_SGL(0.67248046289143f / 8.0),
+- FL2FXCONST_SGL(-0.03646211390569f / 8.0)},
+- {FL2FXCONST_SGL(-0.05146538187944f / 8.0),
+- FL2FXCONST_SGL(-0.92599700120679f / 8.0)},
+- {FL2FXCONST_SGL(0.99947295749905f / 8.0),
+- FL2FXCONST_SGL(0.93625229707912f / 8.0)},
+- {FL2FXCONST_SGL(0.66951124390363f / 8.0),
+- FL2FXCONST_SGL(0.98905825623893f / 8.0)},
+- {FL2FXCONST_SGL(-0.99602956559179f / 8.0),
+- FL2FXCONST_SGL(-0.44654715757688f / 8.0)},
+- {FL2FXCONST_SGL(0.82104905483590f / 8.0),
+- FL2FXCONST_SGL(0.99540741724928f / 8.0)},
+- {FL2FXCONST_SGL(0.99186510988782f / 8.0),
+- FL2FXCONST_SGL(0.72023001312947f / 8.0)},
+- {FL2FXCONST_SGL(-0.65284592392918f / 8.0),
+- FL2FXCONST_SGL(0.52186723253637f / 8.0)},
+- {FL2FXCONST_SGL(0.93885443798188f / 8.0),
+- FL2FXCONST_SGL(-0.74895312615259f / 8.0)},
+- {FL2FXCONST_SGL(0.96735248738388f / 8.0),
+- FL2FXCONST_SGL(0.90891816978629f / 8.0)},
+- {FL2FXCONST_SGL(-0.22225968841114f / 8.0),
+- FL2FXCONST_SGL(0.57124029781228f / 8.0)},
+- {FL2FXCONST_SGL(-0.44132783753414f / 8.0),
+- FL2FXCONST_SGL(-0.92688840659280f / 8.0)},
+- {FL2FXCONST_SGL(-0.85694974219574f / 8.0),
+- FL2FXCONST_SGL(0.88844532719844f / 8.0)},
+- {FL2FXCONST_SGL(0.91783042091762f / 8.0),
+- FL2FXCONST_SGL(-0.46356892383970f / 8.0)},
+- {FL2FXCONST_SGL(0.72556974415690f / 8.0),
+- FL2FXCONST_SGL(-0.99899555770747f / 8.0)},
+- {FL2FXCONST_SGL(-0.99711581834508f / 8.0),
+- FL2FXCONST_SGL(0.58211560180426f / 8.0)},
+- {FL2FXCONST_SGL(0.77638976371966f / 8.0),
+- FL2FXCONST_SGL(0.94321834873819f / 8.0)},
+- {FL2FXCONST_SGL(0.07717324253925f / 8.0),
+- FL2FXCONST_SGL(0.58638399856595f / 8.0)},
+- {FL2FXCONST_SGL(-0.56049829194163f / 8.0),
+- FL2FXCONST_SGL(0.82522301569036f / 8.0)},
+- {FL2FXCONST_SGL(0.98398893639988f / 8.0),
+- FL2FXCONST_SGL(0.39467440420569f / 8.0)},
+- {FL2FXCONST_SGL(0.47546946844938f / 8.0),
+- FL2FXCONST_SGL(0.68613044836811f / 8.0)},
+- {FL2FXCONST_SGL(0.65675089314631f / 8.0),
+- FL2FXCONST_SGL(0.18331637134880f / 8.0)},
+- {FL2FXCONST_SGL(0.03273375457980f / 8.0),
+- FL2FXCONST_SGL(-0.74933109564108f / 8.0)},
+- {FL2FXCONST_SGL(-0.38684144784738f / 8.0),
+- FL2FXCONST_SGL(0.51337349030406f / 8.0)},
+- {FL2FXCONST_SGL(-0.97346267944545f / 8.0),
+- FL2FXCONST_SGL(-0.96549364384098f / 8.0)},
+- {FL2FXCONST_SGL(-0.53282156061942f / 8.0),
+- FL2FXCONST_SGL(-0.91423265091354f / 8.0)},
+- {FL2FXCONST_SGL(0.99817310731176f / 8.0),
+- FL2FXCONST_SGL(0.61133572482148f / 8.0)},
+- {FL2FXCONST_SGL(-0.50254500772635f / 8.0),
+- FL2FXCONST_SGL(-0.88829338134294f / 8.0)},
+- {FL2FXCONST_SGL(0.01995873238855f / 8.0),
+- FL2FXCONST_SGL(0.85223515096765f / 8.0)},
+- {FL2FXCONST_SGL(0.99930381973804f / 8.0),
+- FL2FXCONST_SGL(0.94578896296649f / 8.0)},
+- {FL2FXCONST_SGL(0.82907767600783f / 8.0),
+- FL2FXCONST_SGL(-0.06323442598128f / 8.0)},
+- {FL2FXCONST_SGL(-0.58660709669728f / 8.0),
+- FL2FXCONST_SGL(0.96840773806582f / 8.0)},
+- {FL2FXCONST_SGL(-0.17573736667267f / 8.0),
+- FL2FXCONST_SGL(-0.48166920859485f / 8.0)},
+- {FL2FXCONST_SGL(0.83434292401346f / 8.0),
+- FL2FXCONST_SGL(-0.13023450646997f / 8.0)},
+- {FL2FXCONST_SGL(0.05946491307025f / 8.0),
+- FL2FXCONST_SGL(0.20511047074866f / 8.0)},
+- {FL2FXCONST_SGL(0.81505484574602f / 8.0),
+- FL2FXCONST_SGL(-0.94685947861369f / 8.0)},
+- {FL2FXCONST_SGL(-0.44976380954860f / 8.0),
+- FL2FXCONST_SGL(0.40894572671545f / 8.0)},
+- {FL2FXCONST_SGL(-0.89746474625671f / 8.0),
+- FL2FXCONST_SGL(0.99846578838537f / 8.0)},
+- {FL2FXCONST_SGL(0.39677256130792f / 8.0),
+- FL2FXCONST_SGL(-0.74854668609359f / 8.0)},
+- {FL2FXCONST_SGL(-0.07588948563079f / 8.0),
+- FL2FXCONST_SGL(0.74096214084170f / 8.0)},
+- {FL2FXCONST_SGL(0.76343198951445f / 8.0),
+- FL2FXCONST_SGL(0.41746629422634f / 8.0)},
+- {FL2FXCONST_SGL(-0.74490104699626f / 8.0),
+- FL2FXCONST_SGL(0.94725911744610f / 8.0)},
+- {FL2FXCONST_SGL(0.64880119792759f / 8.0),
+- FL2FXCONST_SGL(0.41336660830571f / 8.0)},
+- {FL2FXCONST_SGL(0.62319537462542f / 8.0),
+- FL2FXCONST_SGL(-0.93098313552599f / 8.0)},
+- {FL2FXCONST_SGL(0.42215817594807f / 8.0),
+- FL2FXCONST_SGL(-0.07712787385208f / 8.0)},
+- {FL2FXCONST_SGL(0.02704554141885f / 8.0),
+- FL2FXCONST_SGL(-0.05417518053666f / 8.0)},
+- {FL2FXCONST_SGL(0.80001773566818f / 8.0),
+- FL2FXCONST_SGL(0.91542195141039f / 8.0)},
+- {FL2FXCONST_SGL(-0.79351832348816f / 8.0),
+- FL2FXCONST_SGL(-0.36208897989136f / 8.0)},
+- {FL2FXCONST_SGL(0.63872359151636f / 8.0),
+- FL2FXCONST_SGL(0.08128252493444f / 8.0)},
+- {FL2FXCONST_SGL(0.52890520960295f / 8.0),
+- FL2FXCONST_SGL(0.60048872455592f / 8.0)},
+- {FL2FXCONST_SGL(0.74238552914587f / 8.0),
+- FL2FXCONST_SGL(0.04491915291044f / 8.0)},
+- {FL2FXCONST_SGL(0.99096131449250f / 8.0),
+- FL2FXCONST_SGL(-0.19451182854402f / 8.0)},
+- {FL2FXCONST_SGL(-0.80412329643109f / 8.0),
+- FL2FXCONST_SGL(-0.88513818199457f / 8.0)},
+- {FL2FXCONST_SGL(-0.64612616129736f / 8.0),
+- FL2FXCONST_SGL(0.72198674804544f / 8.0)},
+- {FL2FXCONST_SGL(0.11657770663191f / 8.0),
+- FL2FXCONST_SGL(-0.83662833815041f / 8.0)},
+- {FL2FXCONST_SGL(-0.95053182488101f / 8.0),
+- FL2FXCONST_SGL(-0.96939905138082f / 8.0)},
+- {FL2FXCONST_SGL(-0.62228872928622f / 8.0),
+- FL2FXCONST_SGL(0.82767262846661f / 8.0)},
+- {FL2FXCONST_SGL(0.03004475787316f / 8.0),
+- FL2FXCONST_SGL(-0.99738896333384f / 8.0)},
+- {FL2FXCONST_SGL(-0.97987214341034f / 8.0),
+- FL2FXCONST_SGL(0.36526129686425f / 8.0)},
+- {FL2FXCONST_SGL(-0.99986980746200f / 8.0),
+- FL2FXCONST_SGL(-0.36021610299715f / 8.0)},
+- {FL2FXCONST_SGL(0.89110648599879f / 8.0),
+- FL2FXCONST_SGL(-0.97894250343044f / 8.0)},
+- {FL2FXCONST_SGL(0.10407960510582f / 8.0),
+- FL2FXCONST_SGL(0.77357793811619f / 8.0)},
+- {FL2FXCONST_SGL(0.95964737821728f / 8.0),
+- FL2FXCONST_SGL(-0.35435818285502f / 8.0)},
+- {FL2FXCONST_SGL(0.50843233159162f / 8.0),
+- FL2FXCONST_SGL(0.96107691266205f / 8.0)},
+- {FL2FXCONST_SGL(0.17006334670615f / 8.0),
+- FL2FXCONST_SGL(-0.76854025314829f / 8.0)},
+- {FL2FXCONST_SGL(0.25872675063360f / 8.0),
+- FL2FXCONST_SGL(0.99893303933816f / 8.0)},
+- {FL2FXCONST_SGL(-0.01115998681937f / 8.0),
+- FL2FXCONST_SGL(0.98496019742444f / 8.0)},
+- {FL2FXCONST_SGL(-0.79598702973261f / 8.0),
+- FL2FXCONST_SGL(0.97138411318894f / 8.0)},
+- {FL2FXCONST_SGL(-0.99264708948101f / 8.0),
+- FL2FXCONST_SGL(-0.99542822402536f / 8.0)},
+- {FL2FXCONST_SGL(-0.99829663752818f / 8.0),
+- FL2FXCONST_SGL(0.01877138824311f / 8.0)},
+- {FL2FXCONST_SGL(-0.70801016548184f / 8.0),
+- FL2FXCONST_SGL(0.33680685948117f / 8.0)},
+- {FL2FXCONST_SGL(-0.70467057786826f / 8.0),
+- FL2FXCONST_SGL(0.93272777501857f / 8.0)},
+- {FL2FXCONST_SGL(0.99846021905254f / 8.0),
+- FL2FXCONST_SGL(-0.98725746254433f / 8.0)},
+- {FL2FXCONST_SGL(-0.63364968534650f / 8.0),
+- FL2FXCONST_SGL(-0.16473594423746f / 8.0)},
+- {FL2FXCONST_SGL(-0.16258217500792f / 8.0),
+- FL2FXCONST_SGL(-0.95939125400802f / 8.0)},
+- {FL2FXCONST_SGL(-0.43645594360633f / 8.0),
+- FL2FXCONST_SGL(-0.94805030113284f / 8.0)},
+- {FL2FXCONST_SGL(-0.99848471702976f / 8.0),
+- FL2FXCONST_SGL(0.96245166923809f / 8.0)},
+- {FL2FXCONST_SGL(-0.16796458968998f / 8.0),
+- FL2FXCONST_SGL(-0.98987511890470f / 8.0)},
+- {FL2FXCONST_SGL(-0.87979225745213f / 8.0),
+- FL2FXCONST_SGL(-0.71725725041680f / 8.0)},
+- {FL2FXCONST_SGL(0.44183099021786f / 8.0),
+- FL2FXCONST_SGL(-0.93568974498761f / 8.0)},
+- {FL2FXCONST_SGL(0.93310180125532f / 8.0),
+- FL2FXCONST_SGL(-0.99913308068246f / 8.0)},
+- {FL2FXCONST_SGL(-0.93941931782002f / 8.0),
+- FL2FXCONST_SGL(-0.56409379640356f / 8.0)},
+- {FL2FXCONST_SGL(-0.88590003188677f / 8.0),
+- FL2FXCONST_SGL(0.47624600491382f / 8.0)},
+- {FL2FXCONST_SGL(0.99971463703691f / 8.0),
+- FL2FXCONST_SGL(-0.83889954253462f / 8.0)},
+- {FL2FXCONST_SGL(-0.75376385639978f / 8.0),
+- FL2FXCONST_SGL(0.00814643438625f / 8.0)},
+- {FL2FXCONST_SGL(0.93887685615875f / 8.0),
+- FL2FXCONST_SGL(-0.11284528204636f / 8.0)},
+- {FL2FXCONST_SGL(0.85126435782309f / 8.0),
+- FL2FXCONST_SGL(0.52349251543547f / 8.0)},
+- {FL2FXCONST_SGL(0.39701421446381f / 8.0),
+- FL2FXCONST_SGL(0.81779634174316f / 8.0)},
+- {FL2FXCONST_SGL(-0.37024464187437f / 8.0),
+- FL2FXCONST_SGL(-0.87071656222959f / 8.0)},
+- {FL2FXCONST_SGL(-0.36024828242896f / 8.0),
+- FL2FXCONST_SGL(0.34655735648287f / 8.0)},
+- {FL2FXCONST_SGL(-0.93388812549209f / 8.0),
+- FL2FXCONST_SGL(-0.84476541096429f / 8.0)},
+- {FL2FXCONST_SGL(-0.65298804552119f / 8.0),
+- FL2FXCONST_SGL(-0.18439575450921f / 8.0)},
+- {FL2FXCONST_SGL(0.11960319006843f / 8.0),
+- FL2FXCONST_SGL(0.99899346780168f / 8.0)},
+- {FL2FXCONST_SGL(0.94292565553160f / 8.0),
+- FL2FXCONST_SGL(0.83163906518293f / 8.0)},
+- {FL2FXCONST_SGL(0.75081145286948f / 8.0),
+- FL2FXCONST_SGL(-0.35533223142265f / 8.0)},
+- {FL2FXCONST_SGL(0.56721979748394f / 8.0),
+- FL2FXCONST_SGL(-0.24076836414499f / 8.0)},
+- {FL2FXCONST_SGL(0.46857766746029f / 8.0),
+- FL2FXCONST_SGL(-0.30140233457198f / 8.0)},
+- {FL2FXCONST_SGL(0.97312313923635f / 8.0),
+- FL2FXCONST_SGL(-0.99548191630031f / 8.0)},
+- {FL2FXCONST_SGL(-0.38299976567017f / 8.0),
+- FL2FXCONST_SGL(0.98516909715427f / 8.0)},
+- {FL2FXCONST_SGL(0.41025800019463f / 8.0),
+- FL2FXCONST_SGL(0.02116736935734f / 8.0)},
+- {FL2FXCONST_SGL(0.09638062008048f / 8.0),
+- FL2FXCONST_SGL(0.04411984381457f / 8.0)},
+- {FL2FXCONST_SGL(-0.85283249275397f / 8.0),
+- FL2FXCONST_SGL(0.91475563922421f / 8.0)},
+- {FL2FXCONST_SGL(0.88866808958124f / 8.0),
+- FL2FXCONST_SGL(-0.99735267083226f / 8.0)},
+- {FL2FXCONST_SGL(-0.48202429536989f / 8.0),
+- FL2FXCONST_SGL(-0.96805608884164f / 8.0)},
+- {FL2FXCONST_SGL(0.27572582416567f / 8.0),
+- FL2FXCONST_SGL(0.58634753335832f / 8.0)},
+- {FL2FXCONST_SGL(-0.65889129659168f / 8.0),
+- FL2FXCONST_SGL(0.58835634138583f / 8.0)},
+- {FL2FXCONST_SGL(0.98838086953732f / 8.0),
+- FL2FXCONST_SGL(0.99994349600236f / 8.0)},
+- {FL2FXCONST_SGL(-0.20651349620689f / 8.0),
+- FL2FXCONST_SGL(0.54593044066355f / 8.0)},
+- {FL2FXCONST_SGL(-0.62126416356920f / 8.0),
+- FL2FXCONST_SGL(-0.59893681700392f / 8.0)},
+- {FL2FXCONST_SGL(0.20320105410437f / 8.0),
+- FL2FXCONST_SGL(-0.86879180355289f / 8.0)},
+- {FL2FXCONST_SGL(-0.97790548600584f / 8.0),
+- FL2FXCONST_SGL(0.96290806999242f / 8.0)},
+- {FL2FXCONST_SGL(0.11112534735126f / 8.0),
+- FL2FXCONST_SGL(0.21484763313301f / 8.0)},
+- {FL2FXCONST_SGL(-0.41368337314182f / 8.0),
+- FL2FXCONST_SGL(0.28216837680365f / 8.0)},
+- {FL2FXCONST_SGL(0.24133038992960f / 8.0),
+- FL2FXCONST_SGL(0.51294362630238f / 8.0)},
+- {FL2FXCONST_SGL(-0.66393410674885f / 8.0),
+- FL2FXCONST_SGL(-0.08249679629081f / 8.0)},
+- {FL2FXCONST_SGL(-0.53697829178752f / 8.0),
+- FL2FXCONST_SGL(-0.97649903936228f / 8.0)},
+- {FL2FXCONST_SGL(-0.97224737889348f / 8.0),
+- FL2FXCONST_SGL(0.22081333579837f / 8.0)},
+- {FL2FXCONST_SGL(0.87392477144549f / 8.0),
+- FL2FXCONST_SGL(-0.12796173740361f / 8.0)},
+- {FL2FXCONST_SGL(0.19050361015753f / 8.0),
+- FL2FXCONST_SGL(0.01602615387195f / 8.0)},
+- {FL2FXCONST_SGL(-0.46353441212724f / 8.0),
+- FL2FXCONST_SGL(-0.95249041539006f / 8.0)},
+- {FL2FXCONST_SGL(-0.07064096339021f / 8.0),
+- FL2FXCONST_SGL(-0.94479803205886f / 8.0)},
+- {FL2FXCONST_SGL(-0.92444085484466f / 8.0),
+- FL2FXCONST_SGL(-0.10457590187436f / 8.0)},
+- {FL2FXCONST_SGL(-0.83822593578728f / 8.0),
+- FL2FXCONST_SGL(-0.01695043208885f / 8.0)},
+- {FL2FXCONST_SGL(0.75214681811150f / 8.0),
+- FL2FXCONST_SGL(-0.99955681042665f / 8.0)},
+- {FL2FXCONST_SGL(-0.42102998829339f / 8.0),
+- FL2FXCONST_SGL(0.99720941999394f / 8.0)},
+- {FL2FXCONST_SGL(-0.72094786237696f / 8.0),
+- FL2FXCONST_SGL(-0.35008961934255f / 8.0)},
+- {FL2FXCONST_SGL(0.78843311019251f / 8.0),
+- FL2FXCONST_SGL(0.52851398958271f / 8.0)},
+- {FL2FXCONST_SGL(0.97394027897442f / 8.0),
+- FL2FXCONST_SGL(-0.26695944086561f / 8.0)},
+- {FL2FXCONST_SGL(0.99206463477946f / 8.0),
+- FL2FXCONST_SGL(-0.57010120849429f / 8.0)},
+- {FL2FXCONST_SGL(0.76789609461795f / 8.0),
+- FL2FXCONST_SGL(-0.76519356730966f / 8.0)},
+- {FL2FXCONST_SGL(-0.82002421836409f / 8.0),
+- FL2FXCONST_SGL(-0.73530179553767f / 8.0)},
+- {FL2FXCONST_SGL(0.81924990025724f / 8.0),
+- FL2FXCONST_SGL(0.99698425250579f / 8.0)},
+- {FL2FXCONST_SGL(-0.26719850873357f / 8.0),
+- FL2FXCONST_SGL(0.68903369776193f / 8.0)},
+- {FL2FXCONST_SGL(-0.43311260380975f / 8.0),
+- FL2FXCONST_SGL(0.85321815947490f / 8.0)},
+- {FL2FXCONST_SGL(0.99194979673836f / 8.0),
+- FL2FXCONST_SGL(0.91876249766422f / 8.0)},
+- {FL2FXCONST_SGL(-0.80692001248487f / 8.0),
+- FL2FXCONST_SGL(-0.32627540663214f / 8.0)},
+- {FL2FXCONST_SGL(0.43080003649976f / 8.0),
+- FL2FXCONST_SGL(-0.21919095636638f / 8.0)},
+- {FL2FXCONST_SGL(0.67709491937357f / 8.0),
+- FL2FXCONST_SGL(-0.95478075822906f / 8.0)},
+- {FL2FXCONST_SGL(0.56151770568316f / 8.0),
+- FL2FXCONST_SGL(-0.70693811747778f / 8.0)},
+- {FL2FXCONST_SGL(0.10831862810749f / 8.0),
+- FL2FXCONST_SGL(-0.08628837174592f / 8.0)},
+- {FL2FXCONST_SGL(0.91229417540436f / 8.0),
+- FL2FXCONST_SGL(-0.65987351408410f / 8.0)},
+- {FL2FXCONST_SGL(-0.48972893932274f / 8.0),
+- FL2FXCONST_SGL(0.56289246362686f / 8.0)},
+- {FL2FXCONST_SGL(-0.89033658689697f / 8.0),
+- FL2FXCONST_SGL(-0.71656563987082f / 8.0)},
+- {FL2FXCONST_SGL(0.65269447475094f / 8.0),
+- FL2FXCONST_SGL(0.65916004833932f / 8.0)},
+- {FL2FXCONST_SGL(0.67439478141121f / 8.0),
+- FL2FXCONST_SGL(-0.81684380846796f / 8.0)},
+- {FL2FXCONST_SGL(-0.47770832416973f / 8.0),
+- FL2FXCONST_SGL(-0.16789556203025f / 8.0)},
+- {FL2FXCONST_SGL(-0.99715979260878f / 8.0),
+- FL2FXCONST_SGL(-0.93565784007648f / 8.0)},
+- {FL2FXCONST_SGL(-0.90889593602546f / 8.0),
+- FL2FXCONST_SGL(0.62034397054380f / 8.0)},
+- {FL2FXCONST_SGL(-0.06618622548177f / 8.0),
+- FL2FXCONST_SGL(-0.23812217221359f / 8.0)},
+- {FL2FXCONST_SGL(0.99430266919728f / 8.0),
+- FL2FXCONST_SGL(0.18812555317553f / 8.0)},
+- {FL2FXCONST_SGL(0.97686402381843f / 8.0),
+- FL2FXCONST_SGL(-0.28664534366620f / 8.0)},
+- {FL2FXCONST_SGL(0.94813650221268f / 8.0),
+- FL2FXCONST_SGL(-0.97506640027128f / 8.0)},
+- {FL2FXCONST_SGL(-0.95434497492853f / 8.0),
+- FL2FXCONST_SGL(-0.79607978501983f / 8.0)},
+- {FL2FXCONST_SGL(-0.49104783137150f / 8.0),
+- FL2FXCONST_SGL(0.32895214359663f / 8.0)},
+- {FL2FXCONST_SGL(0.99881175120751f / 8.0),
+- FL2FXCONST_SGL(0.88993983831354f / 8.0)},
+- {FL2FXCONST_SGL(0.50449166760303f / 8.0),
+- FL2FXCONST_SGL(-0.85995072408434f / 8.0)},
+- {FL2FXCONST_SGL(0.47162891065108f / 8.0),
+- FL2FXCONST_SGL(-0.18680204049569f / 8.0)},
+- {FL2FXCONST_SGL(-0.62081581361840f / 8.0),
+- FL2FXCONST_SGL(0.75000676218956f / 8.0)},
+- {FL2FXCONST_SGL(-0.43867015250812f / 8.0),
+- FL2FXCONST_SGL(0.99998069244322f / 8.0)},
+- {FL2FXCONST_SGL(0.98630563232075f / 8.0),
+- FL2FXCONST_SGL(-0.53578899600662f / 8.0)},
+- {FL2FXCONST_SGL(-0.61510362277374f / 8.0),
+- FL2FXCONST_SGL(-0.89515019899997f / 8.0)},
+- {FL2FXCONST_SGL(-0.03841517601843f / 8.0),
+- FL2FXCONST_SGL(-0.69888815681179f / 8.0)},
+- {FL2FXCONST_SGL(-0.30102157304644f / 8.0),
+- FL2FXCONST_SGL(-0.07667808922205f / 8.0)},
+- {FL2FXCONST_SGL(0.41881284182683f / 8.0),
+- FL2FXCONST_SGL(0.02188098922282f / 8.0)},
+- {FL2FXCONST_SGL(-0.86135454941237f / 8.0),
+- FL2FXCONST_SGL(0.98947480909359f / 8.0)},
+- {FL2FXCONST_SGL(0.67226861393788f / 8.0),
+- FL2FXCONST_SGL(-0.13494389011014f / 8.0)},
+- {FL2FXCONST_SGL(-0.70737398842068f / 8.0),
+- FL2FXCONST_SGL(-0.76547349325992f / 8.0)},
+- {FL2FXCONST_SGL(0.94044946687963f / 8.0),
+- FL2FXCONST_SGL(0.09026201157416f / 8.0)},
+- {FL2FXCONST_SGL(-0.82386352534327f / 8.0),
+- FL2FXCONST_SGL(0.08924768823676f / 8.0)},
+- {FL2FXCONST_SGL(-0.32070666698656f / 8.0),
+- FL2FXCONST_SGL(0.50143421908753f / 8.0)},
+- {FL2FXCONST_SGL(0.57593163224487f / 8.0),
+- FL2FXCONST_SGL(-0.98966422921509f / 8.0)},
+- {FL2FXCONST_SGL(-0.36326018419965f / 8.0),
+- FL2FXCONST_SGL(0.07440243123228f / 8.0)},
+- {FL2FXCONST_SGL(0.99979044674350f / 8.0),
+- FL2FXCONST_SGL(-0.14130287347405f / 8.0)},
+- {FL2FXCONST_SGL(-0.92366023326932f / 8.0),
+- FL2FXCONST_SGL(-0.97979298068180f / 8.0)},
+- {FL2FXCONST_SGL(-0.44607178518598f / 8.0),
+- FL2FXCONST_SGL(-0.54233252016394f / 8.0)},
+- {FL2FXCONST_SGL(0.44226800932956f / 8.0),
+- FL2FXCONST_SGL(0.71326756742752f / 8.0)},
+- {FL2FXCONST_SGL(0.03671907158312f / 8.0),
+- FL2FXCONST_SGL(0.63606389366675f / 8.0)},
+- {FL2FXCONST_SGL(0.52175424682195f / 8.0),
+- FL2FXCONST_SGL(-0.85396826735705f / 8.0)},
+- {FL2FXCONST_SGL(-0.94701139690956f / 8.0),
+- FL2FXCONST_SGL(-0.01826348194255f / 8.0)},
+- {FL2FXCONST_SGL(-0.98759606946049f / 8.0),
+- FL2FXCONST_SGL(0.82288714303073f / 8.0)},
+- {FL2FXCONST_SGL(0.87434794743625f / 8.0),
+- FL2FXCONST_SGL(0.89399495655433f / 8.0)},
+- {FL2FXCONST_SGL(-0.93412041758744f / 8.0),
+- FL2FXCONST_SGL(0.41374052024363f / 8.0)},
+- {FL2FXCONST_SGL(0.96063943315511f / 8.0),
+- FL2FXCONST_SGL(0.93116709541280f / 8.0)},
+- {FL2FXCONST_SGL(0.97534253457837f / 8.0),
+- FL2FXCONST_SGL(0.86150930812689f / 8.0)},
+- {FL2FXCONST_SGL(0.99642466504163f / 8.0),
+- FL2FXCONST_SGL(0.70190043427512f / 8.0)},
+- {FL2FXCONST_SGL(-0.94705089665984f / 8.0),
+- FL2FXCONST_SGL(-0.29580042814306f / 8.0)},
+- {FL2FXCONST_SGL(0.91599807087376f / 8.0),
+- FL2FXCONST_SGL(-0.98147830385781f / 8.0)}};
+-//@}
+-
+-/*
+-static const FIXP_SGL harmonicPhase [2][4] = {
+- { 1.0, 0.0, -1.0, 0.0},
+- { 0.0, 1.0, 0.0, -1.0}
+-};
+-*/
+-
+-/* tables for SBR and AAC LD */
+-/* table for 8 time slot index */
+-const int FDK_sbrDecoder_envelopeTable_8[8][5] = {
+- /* transientIndex nEnv, tranIdx, shortEnv, border1, border2, ... */
+- /* borders from left to right side; -1 = not in use */
+- /*[|T-|------]*/ {2, 0, 0, 1, -1},
+- /*[|-T-|-----]*/ {2, 0, 0, 2, -1},
+- /*[--|T-|----]*/ {3, 1, 1, 2, 4},
+- /*[---|T-|---]*/ {3, 1, 1, 3, 5},
+- /*[----|T-|--]*/ {3, 1, 1, 4, 6},
+- /*[-----|T--|]*/ {2, 1, 1, 5, -1},
+- /*[------|T-|]*/ {2, 1, 1, 6, -1},
+- /*[-------|T|]*/ {2, 1, 1, 7, -1},
+-};
+-
+-/* table for 15 time slot index */
+-const int FDK_sbrDecoder_envelopeTable_15[15][6] = {
+- /* transientIndex nEnv, tranIdx, shortEnv, border1, border2, ... */
+- /* length from left to right side; -1 = not in use */
+- /*[|T---|------------]*/ {2, 0, 0, 4, -1, -1},
+- /*[|-T---|-----------]*/ {2, 0, 0, 5, -1, -1},
+- /*[|--|T---|---------]*/ {3, 1, 1, 2, 6, -1},
+- /*[|---|T---|--------]*/ {3, 1, 1, 3, 7, -1},
+- /*[|----|T---|-------]*/ {3, 1, 1, 4, 8, -1},
+- /*[|-----|T---|------]*/ {3, 1, 1, 5, 9, -1},
+- /*[|------|T---|-----]*/ {3, 1, 1, 6, 10, -1},
+- /*[|-------|T---|----]*/ {3, 1, 1, 7, 11, -1},
+- /*[|--------|T---|---]*/ {3, 1, 1, 8, 12, -1},
+- /*[|---------|T---|--]*/ {3, 1, 1, 9, 13, -1},
+- /*[|----------|T----|]*/ {2, 1, 1, 10, -1, -1},
+- /*[|-----------|T---|]*/ {2, 1, 1, 11, -1, -1},
+- /*[|------------|T--|]*/ {2, 1, 1, 12, -1, -1},
+- /*[|-------------|T-|]*/ {2, 1, 1, 13, -1, -1},
+- /*[|--------------|T|]*/ {2, 1, 1, 14, -1, -1},
+-};
+-
+-/* table for 16 time slot index */
+-const int FDK_sbrDecoder_envelopeTable_16[16][6] = {
+- /* transientIndex nEnv, tranIdx, shortEnv, border1, border2, ... */
+- /* length from left to right side; -1 = not in use */
+- /*[|T---|------------|]*/ {2, 0, 0, 4, -1, -1},
+- /*[|-T---|-----------|]*/ {2, 0, 0, 5, -1, -1},
+- /*[|--|T---|----------]*/ {3, 1, 1, 2, 6, -1},
+- /*[|---|T---|---------]*/ {3, 1, 1, 3, 7, -1},
+- /*[|----|T---|--------]*/ {3, 1, 1, 4, 8, -1},
+- /*[|-----|T---|-------]*/ {3, 1, 1, 5, 9, -1},
+- /*[|------|T---|------]*/ {3, 1, 1, 6, 10, -1},
+- /*[|-------|T---|-----]*/ {3, 1, 1, 7, 11, -1},
+- /*[|--------|T---|----]*/ {3, 1, 1, 8, 12, -1},
+- /*[|---------|T---|---]*/ {3, 1, 1, 9, 13, -1},
+- /*[|----------|T---|--]*/ {3, 1, 1, 10, 14, -1},
+- /*[|-----------|T----|]*/ {2, 1, 1, 11, -1, -1},
+- /*[|------------|T---|]*/ {2, 1, 1, 12, -1, -1},
+- /*[|-------------|T--|]*/ {2, 1, 1, 13, -1, -1},
+- /*[|--------------|T-|]*/ {2, 1, 1, 14, -1, -1},
+- /*[|---------------|T|]*/ {2, 1, 1, 15, -1, -1},
+-};
+-
+-/*!
+- \name FrameInfoDefaults
+-
+- Predefined envelope positions for the FIX-FIX case (static framing)
+-*/
+-//@{
+-const FRAME_INFO FDK_sbrDecoder_sbr_frame_info1_15 = {
+- 0, 1, {0, 15, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, -1, 1, {0, 15, 0}, {0, 0, 0},
+- 0, 0};
+-const FRAME_INFO FDK_sbrDecoder_sbr_frame_info2_15 = {
+- 0, 2, {0, 8, 15, 0, 0, 0}, {1, 1, 0, 0, 0}, -1, 2, {0, 8, 15}, {0, 0, 0},
+- 0, 0};
+-const FRAME_INFO FDK_sbrDecoder_sbr_frame_info4_15 = {
+- 0, 4, {0, 4, 8, 12, 15, 0}, {1, 1, 1, 1, 0}, -1, 2, {0, 8, 15}, {0, 0, 0},
+- 0, 0};
+-#if (MAX_ENVELOPES >= 8)
+-const FRAME_INFO FDK_sbrDecoder_sbr_frame_info8_15 = {
+- 0,
+- 8,
+- {0, 2, 4, 6, 8, 10, 12, 14, 15},
+- {1, 1, 1, 1, 1, 1, 1, 1},
+- -1,
+- 2,
+- {0, 8, 15},
+- {0, 0, 0},
+- 0,
+- 0};
+-#endif
+-
+-const FRAME_INFO FDK_sbrDecoder_sbr_frame_info1_16 = {
+- 0, 1, {0, 16, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, -1, 1, {0, 16, 0}, {0, 0, 0},
+- 0, 0};
+-const FRAME_INFO FDK_sbrDecoder_sbr_frame_info2_16 = {
+- 0, 2, {0, 8, 16, 0, 0, 0}, {1, 1, 0, 0, 0}, -1, 2, {0, 8, 16}, {0, 0, 0},
+- 0, 0};
+-const FRAME_INFO FDK_sbrDecoder_sbr_frame_info4_16 = {
+- 0, 4, {0, 4, 8, 12, 16, 0}, {1, 1, 1, 1, 0}, -1, 2, {0, 8, 16}, {0, 0, 0},
+- 0, 0};
+-
+-#if (MAX_ENVELOPES >= 8)
+-const FRAME_INFO FDK_sbrDecoder_sbr_frame_info8_16 = {
+- 0,
+- 8,
+- {0, 2, 4, 6, 8, 10, 12, 14, 16},
+- {1, 1, 1, 1, 1, 1, 1, 1},
+- -1,
+- 2,
+- {0, 8, 16},
+- {0, 0, 0},
+- 0,
+- 0};
+-#endif
+-
+-//@}
+-
+-/*!
+- \name SBR_HuffmanTables
+-
+- SBR Huffman Table Overview: \n
+- \n
+- o envelope level, 1.5 dB: \n
+- 1) sbr_huffBook_EnvLevel10T[120][2] \n
+- 2) sbr_huffBook_EnvLevel10F[120][2] \n
+- \n
+- o envelope balance, 1.5 dB: \n
+- 3) sbr_huffBook_EnvBalance10T[48][2] \n
+- 4) sbr_huffBook_EnvBalance10F[48][2] \n
+- \n
+- o envelope level, 3.0 dB: \n
+- 5) sbr_huffBook_EnvLevel11T[62][2] \n
+- 6) sbr_huffBook_EnvLevel11F[62][2] \n
+- \n
+- o envelope balance, 3.0 dB: \n
+- 7) sbr_huffBook_EnvBalance11T[24][2] \n
+- 8) sbr_huffBook_EnvBalance11F[24][2] \n
+- \n
+- o noise level, 3.0 dB: \n
+- 9) sbr_huffBook_NoiseLevel11T[62][2] \n
+- -) (sbr_huffBook_EnvLevel11F[62][2] is used for freq dir)\n
+- \n
+- o noise balance, 3.0 dB: \n
+- 10) sbr_huffBook_NoiseBalance11T[24][2]\n
+- -) (sbr_huffBook_EnvBalance11F[24][2] is used for freq dir)\n
+- \n
+- (1.5 dB is never used for noise)
+-
+-*/
+-//@{
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvLevel10T[120][2] = {
+- {1, 2}, {-64, -65}, {3, 4}, {-63, -66}, {5, 6},
+- {-62, -67}, {7, 8}, {-61, -68}, {9, 10}, {-60, -69},
+- {11, 12}, {-59, -70}, {13, 14}, {-58, -71}, {15, 16},
+- {-57, -72}, {17, 18}, {-73, -56}, {19, 21}, {-74, 20},
+- {-55, -75}, {22, 26}, {23, 24}, {-54, -76}, {-77, 25},
+- {-53, -78}, {27, 34}, {28, 29}, {-52, -79}, {30, 31},
+- {-80, -51}, {32, 33}, {-83, -82}, {-81, -50}, {35, 57},
+- {36, 40}, {37, 38}, {-88, -84}, {-48, 39}, {-90, -85},
+- {41, 46}, {42, 43}, {-49, -87}, {44, 45}, {-89, -86},
+- {-124, -123}, {47, 50}, {48, 49}, {-122, -121}, {-120, -119},
+- {51, 54}, {52, 53}, {-118, -117}, {-116, -115}, {55, 56},
+- {-114, -113}, {-112, -111}, {58, 89}, {59, 74}, {60, 67},
+- {61, 64}, {62, 63}, {-110, -109}, {-108, -107}, {65, 66},
+- {-106, -105}, {-104, -103}, {68, 71}, {69, 70}, {-102, -101},
+- {-100, -99}, {72, 73}, {-98, -97}, {-96, -95}, {75, 82},
+- {76, 79}, {77, 78}, {-94, -93}, {-92, -91}, {80, 81},
+- {-47, -46}, {-45, -44}, {83, 86}, {84, 85}, {-43, -42},
+- {-41, -40}, {87, 88}, {-39, -38}, {-37, -36}, {90, 105},
+- {91, 98}, {92, 95}, {93, 94}, {-35, -34}, {-33, -32},
+- {96, 97}, {-31, -30}, {-29, -28}, {99, 102}, {100, 101},
+- {-27, -26}, {-25, -24}, {103, 104}, {-23, -22}, {-21, -20},
+- {106, 113}, {107, 110}, {108, 109}, {-19, -18}, {-17, -16},
+- {111, 112}, {-15, -14}, {-13, -12}, {114, 117}, {115, 116},
+- {-11, -10}, {-9, -8}, {118, 119}, {-7, -6}, {-5, -4}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvLevel10F[120][2] = {
+- {1, 2}, {-64, -65}, {3, 4}, {-63, -66}, {5, 6},
+- {-67, -62}, {7, 8}, {-68, -61}, {9, 10}, {-69, -60},
+- {11, 13}, {-70, 12}, {-59, -71}, {14, 16}, {-58, 15},
+- {-72, -57}, {17, 19}, {-73, 18}, {-56, -74}, {20, 23},
+- {21, 22}, {-55, -75}, {-54, -53}, {24, 27}, {25, 26},
+- {-76, -52}, {-77, -51}, {28, 31}, {29, 30}, {-50, -78},
+- {-79, -49}, {32, 36}, {33, 34}, {-48, -47}, {-80, 35},
+- {-81, -82}, {37, 47}, {38, 41}, {39, 40}, {-83, -46},
+- {-45, -84}, {42, 44}, {-85, 43}, {-44, -43}, {45, 46},
+- {-88, -87}, {-86, -90}, {48, 66}, {49, 56}, {50, 53},
+- {51, 52}, {-92, -42}, {-41, -39}, {54, 55}, {-105, -89},
+- {-38, -37}, {57, 60}, {58, 59}, {-94, -91}, {-40, -36},
+- {61, 63}, {-20, 62}, {-115, -110}, {64, 65}, {-108, -107},
+- {-101, -97}, {67, 89}, {68, 75}, {69, 72}, {70, 71},
+- {-95, -93}, {-34, -27}, {73, 74}, {-22, -17}, {-16, -124},
+- {76, 82}, {77, 79}, {-123, 78}, {-122, -121}, {80, 81},
+- {-120, -119}, {-118, -117}, {83, 86}, {84, 85}, {-116, -114},
+- {-113, -112}, {87, 88}, {-111, -109}, {-106, -104}, {90, 105},
+- {91, 98}, {92, 95}, {93, 94}, {-103, -102}, {-100, -99},
+- {96, 97}, {-98, -96}, {-35, -33}, {99, 102}, {100, 101},
+- {-32, -31}, {-30, -29}, {103, 104}, {-28, -26}, {-25, -24},
+- {106, 113}, {107, 110}, {108, 109}, {-23, -21}, {-19, -18},
+- {111, 112}, {-15, -14}, {-13, -12}, {114, 117}, {115, 116},
+- {-11, -10}, {-9, -8}, {118, 119}, {-7, -6}, {-5, -4}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvBalance10T[48][2] = {
+- {-64, 1}, {-63, 2}, {-65, 3}, {-62, 4}, {-66, 5}, {-61, 6},
+- {-67, 7}, {-60, 8}, {-68, 9}, {10, 11}, {-69, -59}, {12, 13},
+- {-70, -58}, {14, 28}, {15, 21}, {16, 18}, {-57, 17}, {-71, -56},
+- {19, 20}, {-88, -87}, {-86, -85}, {22, 25}, {23, 24}, {-84, -83},
+- {-82, -81}, {26, 27}, {-80, -79}, {-78, -77}, {29, 36}, {30, 33},
+- {31, 32}, {-76, -75}, {-74, -73}, {34, 35}, {-72, -55}, {-54, -53},
+- {37, 41}, {38, 39}, {-52, -51}, {-50, 40}, {-49, -48}, {42, 45},
+- {43, 44}, {-47, -46}, {-45, -44}, {46, 47}, {-43, -42}, {-41, -40}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvBalance10F[48][2] = {
+- {-64, 1}, {-65, 2}, {-63, 3}, {-66, 4}, {-62, 5}, {-61, 6},
+- {-67, 7}, {-68, 8}, {-60, 9}, {10, 11}, {-69, -59}, {-70, 12},
+- {-58, 13}, {14, 17}, {-71, 15}, {-57, 16}, {-56, -73}, {18, 32},
+- {19, 25}, {20, 22}, {-72, 21}, {-88, -87}, {23, 24}, {-86, -85},
+- {-84, -83}, {26, 29}, {27, 28}, {-82, -81}, {-80, -79}, {30, 31},
+- {-78, -77}, {-76, -75}, {33, 40}, {34, 37}, {35, 36}, {-74, -55},
+- {-54, -53}, {38, 39}, {-52, -51}, {-50, -49}, {41, 44}, {42, 43},
+- {-48, -47}, {-46, -45}, {45, 46}, {-44, -43}, {-42, 47}, {-41, -40}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvLevel11T[62][2] = {
+- {-64, 1}, {-65, 2}, {-63, 3}, {-66, 4}, {-62, 5}, {-67, 6},
+- {-61, 7}, {-68, 8}, {-60, 9}, {10, 11}, {-69, -59}, {12, 14},
+- {-70, 13}, {-71, -58}, {15, 18}, {16, 17}, {-72, -57}, {-73, -74},
+- {19, 22}, {-56, 20}, {-55, 21}, {-54, -77}, {23, 31}, {24, 25},
+- {-75, -76}, {26, 27}, {-78, -53}, {28, 29}, {-52, -95}, {-94, 30},
+- {-93, -92}, {32, 47}, {33, 40}, {34, 37}, {35, 36}, {-91, -90},
+- {-89, -88}, {38, 39}, {-87, -86}, {-85, -84}, {41, 44}, {42, 43},
+- {-83, -82}, {-81, -80}, {45, 46}, {-79, -51}, {-50, -49}, {48, 55},
+- {49, 52}, {50, 51}, {-48, -47}, {-46, -45}, {53, 54}, {-44, -43},
+- {-42, -41}, {56, 59}, {57, 58}, {-40, -39}, {-38, -37}, {60, 61},
+- {-36, -35}, {-34, -33}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvLevel11F[62][2] = {
+- {-64, 1}, {-65, 2}, {-63, 3}, {-66, 4}, {-62, 5}, {-67, 6},
+- {7, 8}, {-61, -68}, {9, 10}, {-60, -69}, {11, 12}, {-59, -70},
+- {13, 14}, {-58, -71}, {15, 16}, {-57, -72}, {17, 19}, {-56, 18},
+- {-55, -73}, {20, 24}, {21, 22}, {-74, -54}, {-53, 23}, {-75, -76},
+- {25, 30}, {26, 27}, {-52, -51}, {28, 29}, {-77, -79}, {-50, -49},
+- {31, 39}, {32, 35}, {33, 34}, {-78, -46}, {-82, -88}, {36, 37},
+- {-83, -48}, {-47, 38}, {-86, -85}, {40, 47}, {41, 44}, {42, 43},
+- {-80, -44}, {-43, -42}, {45, 46}, {-39, -87}, {-84, -40}, {48, 55},
+- {49, 52}, {50, 51}, {-95, -94}, {-93, -92}, {53, 54}, {-91, -90},
+- {-89, -81}, {56, 59}, {57, 58}, {-45, -41}, {-38, -37}, {60, 61},
+- {-36, -35}, {-34, -33}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvBalance11T[24][2] = {
+- {-64, 1}, {-63, 2}, {-65, 3}, {-66, 4}, {-62, 5}, {-61, 6},
+- {-67, 7}, {-68, 8}, {-60, 9}, {10, 16}, {11, 13}, {-69, 12},
+- {-76, -75}, {14, 15}, {-74, -73}, {-72, -71}, {17, 20}, {18, 19},
+- {-70, -59}, {-58, -57}, {21, 22}, {-56, -55}, {-54, 23}, {-53, -52}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvBalance11F[24][2] = {
+- {-64, 1}, {-65, 2}, {-63, 3}, {-66, 4}, {-62, 5}, {-61, 6},
+- {-67, 7}, {-68, 8}, {-60, 9}, {10, 13}, {-69, 11}, {-59, 12},
+- {-58, -76}, {14, 17}, {15, 16}, {-75, -74}, {-73, -72}, {18, 21},
+- {19, 20}, {-71, -70}, {-57, -56}, {22, 23}, {-55, -54}, {-53, -52}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_NoiseLevel11T[62][2] = {
+- {-64, 1}, {-63, 2}, {-65, 3}, {-66, 4}, {-62, 5}, {-67, 6},
+- {7, 8}, {-61, -68}, {9, 30}, {10, 15}, {-60, 11}, {-69, 12},
+- {13, 14}, {-59, -53}, {-95, -94}, {16, 23}, {17, 20}, {18, 19},
+- {-93, -92}, {-91, -90}, {21, 22}, {-89, -88}, {-87, -86}, {24, 27},
+- {25, 26}, {-85, -84}, {-83, -82}, {28, 29}, {-81, -80}, {-79, -78},
+- {31, 46}, {32, 39}, {33, 36}, {34, 35}, {-77, -76}, {-75, -74},
+- {37, 38}, {-73, -72}, {-71, -70}, {40, 43}, {41, 42}, {-58, -57},
+- {-56, -55}, {44, 45}, {-54, -52}, {-51, -50}, {47, 54}, {48, 51},
+- {49, 50}, {-49, -48}, {-47, -46}, {52, 53}, {-45, -44}, {-43, -42},
+- {55, 58}, {56, 57}, {-41, -40}, {-39, -38}, {59, 60}, {-37, -36},
+- {-35, 61}, {-34, -33}};
+-
+-const SCHAR FDK_sbrDecoder_sbr_huffBook_NoiseBalance11T[24][2] = {
+- {-64, 1}, {-65, 2}, {-63, 3}, {4, 9}, {-66, 5}, {-62, 6},
+- {7, 8}, {-76, -75}, {-74, -73}, {10, 17}, {11, 14}, {12, 13},
+- {-72, -71}, {-70, -69}, {15, 16}, {-68, -67}, {-61, -60}, {18, 21},
+- {19, 20}, {-59, -58}, {-57, -56}, {22, 23}, {-55, -54}, {-53, -52}};
+-//@}
+-
+-/*!
+- \name parametric stereo
+- \brief constants used by the parametric stereo part of the decoder
+-
+-*/
+-
+-/* constants used in psbitdec.cpp */
+-
+-/* FIX_BORDER can have 0, 1, 2, 4 envelopes */
+-const UCHAR FDK_sbrDecoder_aFixNoEnvDecode[4] = {0, 1, 2, 4};
+-
+-/* IID & ICC Huffman codebooks */
+-const SCHAR aBookPsIidTimeDecode[28][2] = {
+- {-64, 1}, {-65, 2}, {-63, 3}, {-66, 4}, {-62, 5}, {-67, 6},
+- {-61, 7}, {-68, 8}, {-60, 9}, {-69, 10}, {-59, 11}, {-70, 12},
+- {-58, 13}, {-57, 14}, {-71, 15}, {16, 17}, {-56, -72}, {18, 21},
+- {19, 20}, {-55, -78}, {-77, -76}, {22, 25}, {23, 24}, {-75, -74},
+- {-73, -54}, {26, 27}, {-53, -52}, {-51, -50}};
+-
+-const SCHAR aBookPsIidFreqDecode[28][2] = {
+- {-64, 1}, {2, 3}, {-63, -65}, {4, 5}, {-62, -66}, {6, 7},
+- {-61, -67}, {8, 9}, {-68, -60}, {-59, 10}, {-69, 11}, {-58, 12},
+- {-70, 13}, {-71, 14}, {-57, 15}, {16, 17}, {-56, -72}, {18, 19},
+- {-55, -54}, {20, 21}, {-73, -53}, {22, 24}, {-74, 23}, {-75, -78},
+- {25, 26}, {-77, -76}, {-52, 27}, {-51, -50}};
+-
+-const SCHAR aBookPsIccTimeDecode[14][2] = {
+- {-64, 1}, {-63, 2}, {-65, 3}, {-62, 4}, {-66, 5}, {-61, 6}, {-67, 7},
+- {-60, 8}, {-68, 9}, {-59, 10}, {-69, 11}, {-58, 12}, {-70, 13}, {-71, -57}};
+-
+-const SCHAR aBookPsIccFreqDecode[14][2] = {
+- {-64, 1}, {-63, 2}, {-65, 3}, {-62, 4}, {-66, 5}, {-61, 6}, {-67, 7},
+- {-60, 8}, {-59, 9}, {-68, 10}, {-58, 11}, {-69, 12}, {-57, 13}, {-70, -71}};
+-
+-/* IID-fine Huffman codebooks */
+-
+-const SCHAR aBookPsIidFineTimeDecode[60][2] = {
+- {1, -64}, {-63, 2}, {3, -65}, {4, 59}, {5, 7}, {6, -67},
+- {-68, -60}, {-61, 8}, {9, 11}, {-59, 10}, {-70, -58}, {12, 41},
+- {13, 20}, {14, -71}, {-55, 15}, {-53, 16}, {17, -77}, {18, 19},
+- {-85, -84}, {-46, -45}, {-57, 21}, {22, 40}, {23, 29}, {-51, 24},
+- {25, 26}, {-83, -82}, {27, 28}, {-90, -38}, {-92, -91}, {30, 37},
+- {31, 34}, {32, 33}, {-35, -34}, {-37, -36}, {35, 36}, {-94, -93},
+- {-89, -39}, {38, -79}, {39, -81}, {-88, -40}, {-74, -54}, {42, -69},
+- {43, 44}, {-72, -56}, {45, 52}, {46, 50}, {47, -76}, {-49, 48},
+- {-47, 49}, {-87, -41}, {-52, 51}, {-78, -50}, {53, -73}, {54, -75},
+- {55, 57}, {56, -80}, {-86, -42}, {-48, 58}, {-44, -43}, {-66, -62}};
+-
+-const SCHAR aBookPsIidFineFreqDecode[60][2] = {
+- {1, -64}, {2, 4}, {3, -65}, {-66, -62}, {-63, 5}, {6, 7},
+- {-67, -61}, {8, 9}, {-68, -60}, {10, 11}, {-69, -59}, {12, 13},
+- {-70, -58}, {14, 18}, {-57, 15}, {16, -72}, {-54, 17}, {-75, -53},
+- {19, 37}, {-56, 20}, {21, -73}, {22, 29}, {23, -76}, {24, -78},
+- {25, 28}, {26, 27}, {-85, -43}, {-83, -45}, {-81, -47}, {-52, 30},
+- {-50, 31}, {32, -79}, {33, 34}, {-82, -46}, {35, 36}, {-90, -89},
+- {-92, -91}, {38, -71}, {-55, 39}, {40, -74}, {41, 50}, {42, -77},
+- {-49, 43}, {44, 47}, {45, 46}, {-86, -42}, {-88, -87}, {48, 49},
+- {-39, -38}, {-41, -40}, {-51, 51}, {52, 59}, {53, 56}, {54, 55},
+- {-35, -34}, {-37, -36}, {57, 58}, {-94, -93}, {-84, -44}, {-80, -48}};
+-
+-/* constants used in psdec.cpp */
+-
+-/* the values of the following 3 tables are shiftet right by 1 ! */
+-const FIXP_DBL ScaleFactors[NO_IID_LEVELS] = {
+-
+- 0x5a5ded00, 0x59cd0400, 0x58c29680, 0x564c2e80, 0x52a3d480,
+- 0x4c8be080, 0x46df3080, 0x40000000, 0x384ba5c0, 0x304c2980,
+- 0x24e9f640, 0x1b4a2940, 0x11b5c0a0, 0x0b4e2540, 0x0514ea90};
+-
+-const FIXP_DBL ScaleFactorsFine[NO_IID_LEVELS_FINE] = {
+-
+- 0x5a825c00, 0x5a821c00, 0x5a815100, 0x5a7ed000, 0x5a76e600, 0x5a5ded00,
+- 0x5a39b880, 0x59f1fd00, 0x5964d680, 0x5852ca00, 0x564c2e80, 0x54174480,
+- 0x50ea7500, 0x4c8be080, 0x46df3080, 0x40000000, 0x384ba5c0, 0x304c2980,
+- 0x288dd240, 0x217a2900, 0x1b4a2940, 0x13c5ece0, 0x0e2b0090, 0x0a178ef0,
+- 0x072ab798, 0x0514ea90, 0x02dc5944, 0x019bf87c, 0x00e7b173, 0x00824b8b,
+- 0x00494568};
+-const FIXP_DBL Alphas[NO_ICC_LEVELS] = {
+-
+- 0x00000000, 0x0b6b5be0, 0x12485f80, 0x1da2fa40,
+- 0x2637ebc0, 0x3243f6c0, 0x466b7480, 0x6487ed80};
+-
+-const UCHAR bins2groupMap20[NO_IID_GROUPS] = {
+- 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
+-
+-const UCHAR FDK_sbrDecoder_aNoIidBins[3] = {
+- NO_LOW_RES_IID_BINS, NO_MID_RES_IID_BINS, NO_HI_RES_IID_BINS};
+-
+-const UCHAR FDK_sbrDecoder_aNoIccBins[3] = {
+- NO_LOW_RES_ICC_BINS, NO_MID_RES_ICC_BINS, NO_HI_RES_ICC_BINS};
+-
+-/************************************************************************/
+-/*!
+- \brief Create lookup tables for some arithmetic functions
+-
+- The tables would normally be defined as const arrays,
+- but initialization at run time allows to specify their accuracy.
+-*/
+-/************************************************************************/
+-
+-/* 1/x-table: (example for INV_TABLE_BITS 8)
+-
+- The table covers an input range from 0.5 to 1.0 with a step size of 1/512,
+- starting at 0.5 + 1/512.
+- Each table entry corresponds to an input interval starting 1/1024 below the
+- exact value and ending 1/1024 above it.
+-
+- The table is actually a 0.5/x-table, so that the output range is again
+- 0.5...1.0 and the exponent of the result must be increased by 1.
+-
+- Input range Index in table result
+- -------------------------------------------------------------------
+- 0.500000...0.500976 - 0.5 / 0.500000 = 1.000000
+- 0.500976...0.502930 0 0.5 / 0.501953 = 0.996109
+- 0.502930...0.500488 1 0.5 / 0.503906 = 0.992248
+- ...
+- 0.999023...1.000000 255 0.5 / 1.000000 = 0.500000
+-
+- for (i=0; i<INV_TABLE_SIZE; i++) {
+- d = 0.5f / ( 0.5f+(double)(i+1)/(INV_TABLE_SIZE*2) ) ;
+- invTable[i] = FL2FX_SGL(d);
+- }
+-*/
+-const FIXP_SGL FDK_sbrDecoder_invTable[INV_TABLE_SIZE] = {
+- 0x7f80, 0x7f01, 0x7e83, 0x7e07, 0x7d8b, 0x7d11, 0x7c97, 0x7c1e, 0x7ba6,
+- 0x7b2f, 0x7ab9, 0x7a44, 0x79cf, 0x795c, 0x78e9, 0x7878, 0x7807, 0x7796,
+- 0x7727, 0x76b9, 0x764b, 0x75de, 0x7572, 0x7506, 0x749c, 0x7432, 0x73c9,
+- 0x7360, 0x72f9, 0x7292, 0x722c, 0x71c6, 0x7161, 0x70fd, 0x709a, 0x7037,
+- 0x6fd5, 0x6f74, 0x6f13, 0x6eb3, 0x6e54, 0x6df5, 0x6d97, 0x6d39, 0x6cdc,
+- 0x6c80, 0x6c24, 0x6bc9, 0x6b6f, 0x6b15, 0x6abc, 0x6a63, 0x6a0b, 0x69b3,
+- 0x695c, 0x6906, 0x68b0, 0x685a, 0x6806, 0x67b1, 0x675e, 0x670a, 0x66b8,
+- 0x6666, 0x6614, 0x65c3, 0x6572, 0x6522, 0x64d2, 0x6483, 0x6434, 0x63e6,
+- 0x6399, 0x634b, 0x62fe, 0x62b2, 0x6266, 0x621b, 0x61d0, 0x6185, 0x613b,
+- 0x60f2, 0x60a8, 0x6060, 0x6017, 0x5fcf, 0x5f88, 0x5f41, 0x5efa, 0x5eb4,
+- 0x5e6e, 0x5e28, 0x5de3, 0x5d9f, 0x5d5a, 0x5d17, 0x5cd3, 0x5c90, 0x5c4d,
+- 0x5c0b, 0x5bc9, 0x5b87, 0x5b46, 0x5b05, 0x5ac4, 0x5a84, 0x5a44, 0x5a05,
+- 0x59c6, 0x5987, 0x5949, 0x590a, 0x58cd, 0x588f, 0x5852, 0x5815, 0x57d9,
+- 0x579d, 0x5761, 0x5725, 0x56ea, 0x56af, 0x5675, 0x563b, 0x5601, 0x55c7,
+- 0x558e, 0x5555, 0x551c, 0x54e3, 0x54ab, 0x5473, 0x543c, 0x5405, 0x53ce,
+- 0x5397, 0x5360, 0x532a, 0x52f4, 0x52bf, 0x5289, 0x5254, 0x521f, 0x51eb,
+- 0x51b7, 0x5183, 0x514f, 0x511b, 0x50e8, 0x50b5, 0x5082, 0x5050, 0x501d,
+- 0x4feb, 0x4fba, 0x4f88, 0x4f57, 0x4f26, 0x4ef5, 0x4ec4, 0x4e94, 0x4e64,
+- 0x4e34, 0x4e04, 0x4dd5, 0x4da6, 0x4d77, 0x4d48, 0x4d19, 0x4ceb, 0x4cbd,
+- 0x4c8f, 0x4c61, 0x4c34, 0x4c07, 0x4bd9, 0x4bad, 0x4b80, 0x4b54, 0x4b27,
+- 0x4afb, 0x4acf, 0x4aa4, 0x4a78, 0x4a4d, 0x4a22, 0x49f7, 0x49cd, 0x49a2,
+- 0x4978, 0x494e, 0x4924, 0x48fa, 0x48d1, 0x48a7, 0x487e, 0x4855, 0x482d,
+- 0x4804, 0x47dc, 0x47b3, 0x478b, 0x4763, 0x473c, 0x4714, 0x46ed, 0x46c5,
+- 0x469e, 0x4677, 0x4651, 0x462a, 0x4604, 0x45de, 0x45b8, 0x4592, 0x456c,
+- 0x4546, 0x4521, 0x44fc, 0x44d7, 0x44b2, 0x448d, 0x4468, 0x4444, 0x441f,
+- 0x43fb, 0x43d7, 0x43b3, 0x4390, 0x436c, 0x4349, 0x4325, 0x4302, 0x42df,
+- 0x42bc, 0x4299, 0x4277, 0x4254, 0x4232, 0x4210, 0x41ee, 0x41cc, 0x41aa,
+- 0x4189, 0x4167, 0x4146, 0x4125, 0x4104, 0x40e3, 0x40c2, 0x40a1, 0x4081,
+- 0x4060, 0x4040, 0x4020, 0x4000};
+diff --git a/libSBRdec/src/sbr_rom.h b/libSBRdec/src/sbr_rom.h
+deleted file mode 100644
+index 039743c..0000000
+--- a/libSBRdec/src/sbr_rom.h
++++ /dev/null
+@@ -1,216 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+-\file
+-\brief Declaration of constant tables
+-*/
+-#ifndef SBR_ROM_H
+-#define SBR_ROM_H
+-
+-#include "sbrdecoder.h"
+-#include "env_extr.h"
+-#include "qmf.h"
+-
+-#define INV_INT_TABLE_SIZE 49
+-#define SBR_NF_NO_RANDOM_VAL \
+- 512 /*!< Size of random number array for noise floor */
+-
+-/*
+- Frequency scales
+-*/
+-
+-/* if defined(SBRDEC_RATIO_16_64_ENABLE) ((4) = 4) else ((4) = 2) */
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_16[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_22[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_24[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_32[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_40[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_44[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_48[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_64[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_88[(4) / 2][16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_192[16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_176[16];
+-extern const UCHAR FDK_sbrDecoder_sbr_start_freq_128[16];
+-
+-/*
+- Low-Power-Profile Transposer
+-*/
+-#define NUM_WHFACTOR_TABLE_ENTRIES 9
+-extern const USHORT
+- FDK_sbrDecoder_sbr_whFactorsIndex[NUM_WHFACTOR_TABLE_ENTRIES];
+-extern const FIXP_DBL
+- FDK_sbrDecoder_sbr_whFactorsTable[NUM_WHFACTOR_TABLE_ENTRIES][6];
+-
+-/*
+- Envelope Adjustor
+-*/
+-extern const FIXP_SGL FDK_sbrDecoder_sbr_limGains_m[4];
+-extern const UCHAR FDK_sbrDecoder_sbr_limGains_e[4];
+-extern const FIXP_SGL FDK_sbrDecoder_sbr_limGainsPvc_m[4];
+-extern const UCHAR FDK_sbrDecoder_sbr_limGainsPvc_e[4];
+-extern const FIXP_SGL FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4[4];
+-extern const FIXP_DBL FDK_sbrDecoder_sbr_limiterBandsPerOctaveDiv4_DBL[4];
+-extern const FIXP_SGL FDK_sbrDecoder_sbr_smoothFilter[4];
+-extern const FIXP_SGL FDK_sbrDecoder_sbr_randomPhase[SBR_NF_NO_RANDOM_VAL][2];
+-
+-/*
+- Envelope Extractor
+-*/
+-extern const int FDK_sbrDecoder_envelopeTable_8[8][5];
+-extern const int FDK_sbrDecoder_envelopeTable_15[15][6];
+-extern const int FDK_sbrDecoder_envelopeTable_16[16][6];
+-extern const FRAME_INFO FDK_sbrDecoder_sbr_frame_info1_15;
+-extern const FRAME_INFO FDK_sbrDecoder_sbr_frame_info2_15;
+-extern const FRAME_INFO FDK_sbrDecoder_sbr_frame_info4_15;
+-extern const FRAME_INFO FDK_sbrDecoder_sbr_frame_info8_15;
+-extern const FRAME_INFO FDK_sbrDecoder_sbr_frame_info1_16;
+-extern const FRAME_INFO FDK_sbrDecoder_sbr_frame_info2_16;
+-extern const FRAME_INFO FDK_sbrDecoder_sbr_frame_info4_16;
+-extern const FRAME_INFO FDK_sbrDecoder_sbr_frame_info8_16;
+-
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvLevel10T[120][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvLevel10F[120][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvBalance10T[48][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvBalance10F[48][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvLevel11T[62][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvLevel11F[62][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvBalance11T[24][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_EnvBalance11F[24][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_NoiseLevel11T[62][2];
+-extern const SCHAR FDK_sbrDecoder_sbr_huffBook_NoiseBalance11T[24][2];
+-
+-/*
+- Parametric stereo
+-*/
+-
+-/* FIX_BORDER can have 0, 1, 2, 4 envelops */
+-extern const UCHAR FDK_sbrDecoder_aFixNoEnvDecode[4];
+-
+-/* IID & ICC Huffman codebooks */
+-extern const SCHAR aBookPsIidTimeDecode[28][2];
+-extern const SCHAR aBookPsIidFreqDecode[28][2];
+-extern const SCHAR aBookPsIccTimeDecode[14][2];
+-extern const SCHAR aBookPsIccFreqDecode[14][2];
+-
+-/* IID-fine Huffman codebooks */
+-
+-extern const SCHAR aBookPsIidFineTimeDecode[60][2];
+-extern const SCHAR aBookPsIidFineFreqDecode[60][2];
+-
+-/* the values of the following 3 tables are shiftet right by 1 ! */
+-extern const FIXP_DBL ScaleFactors[NO_IID_LEVELS];
+-extern const FIXP_DBL ScaleFactorsFine[NO_IID_LEVELS_FINE];
+-extern const FIXP_DBL Alphas[NO_ICC_LEVELS];
+-
+-extern const UCHAR bins2groupMap20[NO_IID_GROUPS];
+-extern const UCHAR FDK_sbrDecoder_aNoIidBins[3];
+-extern const UCHAR FDK_sbrDecoder_aNoIccBins[3];
+-
+-/* Lookup tables for some arithmetic functions */
+-
+-#define INV_TABLE_BITS 8
+-#define INV_TABLE_SIZE (1 << INV_TABLE_BITS)
+-extern const FIXP_SGL FDK_sbrDecoder_invTable[INV_TABLE_SIZE];
+-
+-#endif // SBR_ROM_H
+diff --git a/libSBRdec/src/sbrdec_drc.cpp b/libSBRdec/src/sbrdec_drc.cpp
+deleted file mode 100644
+index 2d73f32..0000000
+--- a/libSBRdec/src/sbrdec_drc.cpp
++++ /dev/null
+@@ -1,528 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s): Christian Griebel
+-
+- Description: Dynamic range control (DRC) decoder tool for SBR
+-
+-*******************************************************************************/
+-
+-#include "sbrdec_drc.h"
+-
+-/* DRC - Offset table for QMF interpolation. Shifted by one index position.
+- The table defines the (short) window borders rounded to the nearest QMF
+- timeslot. It has the size 16 because it is accessed with the
+- drcInterpolationScheme that is read from the bitstream with 4 bit. */
+-static const UCHAR winBorderToColMappingTab[2][16] = {
+- /*-1, 0, 1, 2, 3, 4, 5, 6, 7, 8 */
+- {0, 0, 4, 8, 12, 16, 20, 24, 28, 32, 32, 32, 32, 32, 32,
+- 32}, /* 1024 framing */
+- {0, 0, 4, 8, 11, 15, 19, 23, 26, 30, 30, 30, 30, 30, 30,
+- 30} /* 960 framing */
+-};
+-
+-/*!
+- \brief Initialize DRC QMF factors
+-
+- \hDrcData Handle to DRC channel data.
+-
+- \return none
+-*/
+-void sbrDecoder_drcInitChannel(HANDLE_SBR_DRC_CHANNEL hDrcData) {
+- int band;
+-
+- if (hDrcData == NULL) {
+- return;
+- }
+-
+- for (band = 0; band < (64); band++) {
+- hDrcData->prevFact_mag[band] = FL2FXCONST_DBL(0.5f);
+- }
+-
+- for (band = 0; band < SBRDEC_MAX_DRC_BANDS; band++) {
+- hDrcData->currFact_mag[band] = FL2FXCONST_DBL(0.5f);
+- hDrcData->nextFact_mag[band] = FL2FXCONST_DBL(0.5f);
+- }
+-
+- hDrcData->prevFact_exp = 1;
+- hDrcData->currFact_exp = 1;
+- hDrcData->nextFact_exp = 1;
+-
+- hDrcData->numBandsCurr = 1;
+- hDrcData->numBandsNext = 1;
+-
+- hDrcData->winSequenceCurr = 0;
+- hDrcData->winSequenceNext = 0;
+-
+- hDrcData->drcInterpolationSchemeCurr = 0;
+- hDrcData->drcInterpolationSchemeNext = 0;
+-
+- hDrcData->enable = 0;
+-}
+-
+-/*!
+- \brief Swap DRC QMF scaling factors after they have been applied.
+-
+- \hDrcData Handle to DRC channel data.
+-
+- \return none
+-*/
+-void sbrDecoder_drcUpdateChannel(HANDLE_SBR_DRC_CHANNEL hDrcData) {
+- if (hDrcData == NULL) {
+- return;
+- }
+- if (hDrcData->enable != 1) {
+- return;
+- }
+-
+- /* swap previous data */
+- FDKmemcpy(hDrcData->currFact_mag, hDrcData->nextFact_mag,
+- SBRDEC_MAX_DRC_BANDS * sizeof(FIXP_DBL));
+-
+- hDrcData->currFact_exp = hDrcData->nextFact_exp;
+-
+- hDrcData->numBandsCurr = hDrcData->numBandsNext;
+-
+- FDKmemcpy(hDrcData->bandTopCurr, hDrcData->bandTopNext,
+- SBRDEC_MAX_DRC_BANDS * sizeof(USHORT));
+-
+- hDrcData->drcInterpolationSchemeCurr = hDrcData->drcInterpolationSchemeNext;
+-
+- hDrcData->winSequenceCurr = hDrcData->winSequenceNext;
+-}
+-
+-/*!
+- \brief Apply DRC factors slot based.
+-
+- \hDrcData Handle to DRC channel data.
+- \qmfRealSlot Pointer to real valued QMF data of one time slot.
+- \qmfImagSlot Pointer to the imaginary QMF data of one time slot.
+- \col Number of the time slot.
+- \numQmfSubSamples Total number of time slots for one frame.
+- \scaleFactor Pointer to the out scale factor of the time slot.
+-
+- \return None.
+-*/
+-void sbrDecoder_drcApplySlot(HANDLE_SBR_DRC_CHANNEL hDrcData,
+- FIXP_DBL *qmfRealSlot, FIXP_DBL *qmfImagSlot,
+- int col, int numQmfSubSamples, int maxShift) {
+- const UCHAR *winBorderToColMap;
+-
+- int band, bottomMdct, topMdct, bin, useLP;
+- int indx = numQmfSubSamples - (numQmfSubSamples >> 1) - 10; /* l_border */
+- int frameLenFlag = (numQmfSubSamples == 30) ? 1 : 0;
+- int frameSize = (frameLenFlag == 1) ? 960 : 1024;
+-
+- const FIXP_DBL *fact_mag = NULL;
+- INT fact_exp = 0;
+- UINT numBands = 0;
+- USHORT *bandTop = NULL;
+- int shortDrc = 0;
+-
+- FIXP_DBL alphaValue = FL2FXCONST_DBL(0.0f);
+-
+- if (hDrcData == NULL) {
+- return;
+- }
+- if (hDrcData->enable != 1) {
+- return;
+- }
+-
+- winBorderToColMap = winBorderToColMappingTab[frameLenFlag];
+-
+- useLP = (qmfImagSlot == NULL) ? 1 : 0;
+-
+- col += indx;
+- bottomMdct = 0;
+-
+- /* get respective data and calc interpolation factor */
+- if (col < (numQmfSubSamples >> 1)) { /* first half of current frame */
+- if (hDrcData->winSequenceCurr != 2) { /* long window */
+- int j = col + (numQmfSubSamples >> 1);
+-
+- if (hDrcData->drcInterpolationSchemeCurr == 0) {
+- INT k = (frameLenFlag) ? 0x4444445 : 0x4000000;
+-
+- alphaValue = (FIXP_DBL)(j * k);
+- } else {
+- if (j >= (int)winBorderToColMap[hDrcData->drcInterpolationSchemeCurr]) {
+- alphaValue = (FIXP_DBL)MAXVAL_DBL;
+- }
+- }
+- } else { /* short windows */
+- shortDrc = 1;
+- }
+-
+- fact_mag = hDrcData->currFact_mag;
+- fact_exp = hDrcData->currFact_exp;
+- numBands = hDrcData->numBandsCurr;
+- bandTop = hDrcData->bandTopCurr;
+- } else if (col < numQmfSubSamples) { /* second half of current frame */
+- if (hDrcData->winSequenceNext != 2) { /* next: long window */
+- int j = col - (numQmfSubSamples >> 1);
+-
+- if (hDrcData->drcInterpolationSchemeNext == 0) {
+- INT k = (frameLenFlag) ? 0x4444445 : 0x4000000;
+-
+- alphaValue = (FIXP_DBL)(j * k);
+- } else {
+- if (j >= (int)winBorderToColMap[hDrcData->drcInterpolationSchemeNext]) {
+- alphaValue = (FIXP_DBL)MAXVAL_DBL;
+- }
+- }
+-
+- fact_mag = hDrcData->nextFact_mag;
+- fact_exp = hDrcData->nextFact_exp;
+- numBands = hDrcData->numBandsNext;
+- bandTop = hDrcData->bandTopNext;
+- } else { /* next: short windows */
+- if (hDrcData->winSequenceCurr != 2) { /* current: long window */
+- alphaValue = (FIXP_DBL)0;
+-
+- fact_mag = hDrcData->nextFact_mag;
+- fact_exp = hDrcData->nextFact_exp;
+- numBands = hDrcData->numBandsNext;
+- bandTop = hDrcData->bandTopNext;
+- } else { /* current: short windows */
+- shortDrc = 1;
+-
+- fact_mag = hDrcData->currFact_mag;
+- fact_exp = hDrcData->currFact_exp;
+- numBands = hDrcData->numBandsCurr;
+- bandTop = hDrcData->bandTopCurr;
+- }
+- }
+- } else { /* first half of next frame */
+- if (hDrcData->winSequenceNext != 2) { /* long window */
+- int j = col - (numQmfSubSamples >> 1);
+-
+- if (hDrcData->drcInterpolationSchemeNext == 0) {
+- INT k = (frameLenFlag) ? 0x4444445 : 0x4000000;
+-
+- alphaValue = (FIXP_DBL)(j * k);
+- } else {
+- if (j >= (int)winBorderToColMap[hDrcData->drcInterpolationSchemeNext]) {
+- alphaValue = (FIXP_DBL)MAXVAL_DBL;
+- }
+- }
+- } else { /* short windows */
+- shortDrc = 1;
+- }
+-
+- fact_mag = hDrcData->nextFact_mag;
+- fact_exp = hDrcData->nextFact_exp;
+- numBands = hDrcData->numBandsNext;
+- bandTop = hDrcData->bandTopNext;
+-
+- col -= numQmfSubSamples;
+- }
+-
+- /* process bands */
+- for (band = 0; band < (int)numBands; band++) {
+- int bottomQmf, topQmf;
+-
+- FIXP_DBL drcFact_mag = (FIXP_DBL)MAXVAL_DBL;
+-
+- topMdct = (bandTop[band] + 1) << 2;
+-
+- if (!shortDrc) { /* long window */
+- if (frameLenFlag) {
+- /* 960 framing */
+- bottomQmf = fMultIfloor((FIXP_DBL)0x4444445, bottomMdct);
+- topQmf = fMultIfloor((FIXP_DBL)0x4444445, topMdct);
+-
+- topMdct = 30 * topQmf;
+- } else {
+- /* 1024 framing */
+- topMdct &= ~0x1f;
+-
+- bottomQmf = bottomMdct >> 5;
+- topQmf = topMdct >> 5;
+- }
+-
+- if (band == ((int)numBands - 1)) {
+- topQmf = (64);
+- }
+-
+- for (bin = bottomQmf; bin < topQmf; bin++) {
+- FIXP_DBL drcFact1_mag = hDrcData->prevFact_mag[bin];
+- FIXP_DBL drcFact2_mag = fact_mag[band];
+-
+- /* normalize scale factors */
+- if (hDrcData->prevFact_exp < maxShift) {
+- drcFact1_mag >>= maxShift - hDrcData->prevFact_exp;
+- }
+- if (fact_exp < maxShift) {
+- drcFact2_mag >>= maxShift - fact_exp;
+- }
+-
+- /* interpolate */
+- if (alphaValue == (FIXP_DBL)0) {
+- drcFact_mag = drcFact1_mag;
+- } else if (alphaValue == (FIXP_DBL)MAXVAL_DBL) {
+- drcFact_mag = drcFact2_mag;
+- } else {
+- drcFact_mag =
+- fMult(alphaValue, drcFact2_mag) +
+- fMult(((FIXP_DBL)MAXVAL_DBL - alphaValue), drcFact1_mag);
+- }
+-
+- /* apply scaling */
+- qmfRealSlot[bin] = fMult(qmfRealSlot[bin], drcFact_mag);
+- if (!useLP) {
+- qmfImagSlot[bin] = fMult(qmfImagSlot[bin], drcFact_mag);
+- }
+-
+- /* save previous factors */
+- if (col == (numQmfSubSamples >> 1) - 1) {
+- hDrcData->prevFact_mag[bin] = fact_mag[band];
+- }
+- }
+- } else { /* short windows */
+- unsigned startWinIdx, stopWinIdx;
+- int startCol, stopCol;
+- FIXP_DBL invFrameSizeDiv8 =
+- (frameLenFlag) ? (FIXP_DBL)0x1111112 : (FIXP_DBL)0x1000000;
+-
+- /* limit top at the frame borders */
+- if (topMdct < 0) {
+- topMdct = 0;
+- }
+- if (topMdct >= frameSize) {
+- topMdct = frameSize - 1;
+- }
+-
+- if (frameLenFlag) {
+- /* 960 framing */
+- topMdct = fMultIfloor((FIXP_DBL)0x78000000,
+- fMultIfloor((FIXP_DBL)0x22222223, topMdct) << 2);
+-
+- startWinIdx = fMultIfloor(invFrameSizeDiv8, bottomMdct) +
+- 1; /* winBorderToColMap table has offset of 1 */
+- stopWinIdx = fMultIceil(invFrameSizeDiv8 - (FIXP_DBL)1, topMdct) + 1;
+- } else {
+- /* 1024 framing */
+- topMdct &= ~0x03;
+-
+- startWinIdx = fMultIfloor(invFrameSizeDiv8, bottomMdct) + 1;
+- stopWinIdx = fMultIceil(invFrameSizeDiv8, topMdct) + 1;
+- }
+-
+- /* startCol is truncated to the nearest corresponding start subsample in
+- the QMF of the short window bottom is present in:*/
+- startCol = (int)winBorderToColMap[startWinIdx];
+-
+- /* stopCol is rounded upwards to the nearest corresponding stop subsample
+- in the QMF of the short window top is present in. */
+- stopCol = (int)winBorderToColMap[stopWinIdx];
+-
+- bottomQmf = fMultIfloor(invFrameSizeDiv8,
+- ((bottomMdct % (numQmfSubSamples << 2)) << 5));
+- topQmf = fMultIfloor(invFrameSizeDiv8,
+- ((topMdct % (numQmfSubSamples << 2)) << 5));
+-
+- /* extend last band */
+- if (band == ((int)numBands - 1)) {
+- topQmf = (64);
+- stopCol = numQmfSubSamples;
+- stopWinIdx = 10;
+- }
+-
+- if (topQmf == 0) {
+- if (frameLenFlag) {
+- FIXP_DBL rem = fMult(invFrameSizeDiv8,
+- (FIXP_DBL)(topMdct << (DFRACT_BITS - 12)));
+- if ((LONG)rem & (LONG)0x1F) {
+- stopWinIdx -= 1;
+- stopCol = (int)winBorderToColMap[stopWinIdx];
+- }
+- }
+- topQmf = (64);
+- }
+-
+- /* save previous factors */
+- if (stopCol == numQmfSubSamples) {
+- int tmpBottom = bottomQmf;
+-
+- if ((int)winBorderToColMap[8] > startCol) {
+- tmpBottom = 0; /* band starts in previous short window */
+- }
+-
+- for (bin = tmpBottom; bin < topQmf; bin++) {
+- hDrcData->prevFact_mag[bin] = fact_mag[band];
+- }
+- }
+-
+- /* apply */
+- if ((col >= startCol) && (col < stopCol)) {
+- if (col >= (int)winBorderToColMap[startWinIdx + 1]) {
+- bottomQmf = 0; /* band starts in previous short window */
+- }
+- if (col < (int)winBorderToColMap[stopWinIdx - 1]) {
+- topQmf = (64); /* band ends in next short window */
+- }
+-
+- drcFact_mag = fact_mag[band];
+-
+- /* normalize scale factor */
+- if (fact_exp < maxShift) {
+- drcFact_mag >>= maxShift - fact_exp;
+- }
+-
+- /* apply scaling */
+- for (bin = bottomQmf; bin < topQmf; bin++) {
+- qmfRealSlot[bin] = fMult(qmfRealSlot[bin], drcFact_mag);
+- if (!useLP) {
+- qmfImagSlot[bin] = fMult(qmfImagSlot[bin], drcFact_mag);
+- }
+- }
+- }
+- }
+-
+- bottomMdct = topMdct;
+- } /* end of bands loop */
+-
+- if (col == (numQmfSubSamples >> 1) - 1) {
+- hDrcData->prevFact_exp = fact_exp;
+- }
+-}
+-
+-/*!
+- \brief Apply DRC factors frame based.
+-
+- \hDrcData Handle to DRC channel data.
+- \qmfRealSlot Pointer to real valued QMF data of the whole frame.
+- \qmfImagSlot Pointer to the imaginary QMF data of the whole frame.
+- \numQmfSubSamples Total number of time slots for one frame.
+- \scaleFactor Pointer to the out scale factor of the frame.
+-
+- \return None.
+-*/
+-void sbrDecoder_drcApply(HANDLE_SBR_DRC_CHANNEL hDrcData,
+- FIXP_DBL **QmfBufferReal, FIXP_DBL **QmfBufferImag,
+- int numQmfSubSamples, int *scaleFactor) {
+- int col;
+- int maxShift = 0;
+-
+- if (hDrcData == NULL) {
+- return;
+- }
+- if (hDrcData->enable == 0) {
+- return; /* Avoid changing the scaleFactor even though the processing is
+- disabled. */
+- }
+-
+- /* get max scale factor */
+- if (hDrcData->prevFact_exp > maxShift) {
+- maxShift = hDrcData->prevFact_exp;
+- }
+- if (hDrcData->currFact_exp > maxShift) {
+- maxShift = hDrcData->currFact_exp;
+- }
+- if (hDrcData->nextFact_exp > maxShift) {
+- maxShift = hDrcData->nextFact_exp;
+- }
+-
+- for (col = 0; col < numQmfSubSamples; col++) {
+- FIXP_DBL *qmfSlotReal = QmfBufferReal[col];
+- FIXP_DBL *qmfSlotImag = (QmfBufferImag == NULL) ? NULL : QmfBufferImag[col];
+-
+- sbrDecoder_drcApplySlot(hDrcData, qmfSlotReal, qmfSlotImag, col,
+- numQmfSubSamples, maxShift);
+- }
+-
+- *scaleFactor += maxShift;
+-}
+diff --git a/libSBRdec/src/sbrdec_drc.h b/libSBRdec/src/sbrdec_drc.h
+deleted file mode 100644
+index 2eb0e20..0000000
+--- a/libSBRdec/src/sbrdec_drc.h
++++ /dev/null
+@@ -1,149 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s): Christian Griebel
+-
+- Description: Dynamic range control (DRC) decoder tool for SBR
+-
+-*******************************************************************************/
+-
+-#ifndef SBRDEC_DRC_H
+-#define SBRDEC_DRC_H
+-
+-#include "sbrdecoder.h"
+-
+-#define SBRDEC_MAX_DRC_CHANNELS (8)
+-#define SBRDEC_MAX_DRC_BANDS (16)
+-
+-typedef struct {
+- FIXP_DBL prevFact_mag[(64)];
+- INT prevFact_exp;
+-
+- FIXP_DBL currFact_mag[SBRDEC_MAX_DRC_BANDS];
+- FIXP_DBL nextFact_mag[SBRDEC_MAX_DRC_BANDS];
+- INT currFact_exp;
+- INT nextFact_exp;
+-
+- UINT numBandsCurr;
+- UINT numBandsNext;
+- USHORT bandTopCurr[SBRDEC_MAX_DRC_BANDS];
+- USHORT bandTopNext[SBRDEC_MAX_DRC_BANDS];
+-
+- SHORT drcInterpolationSchemeCurr;
+- SHORT drcInterpolationSchemeNext;
+-
+- SHORT enable;
+-
+- UCHAR winSequenceCurr;
+- UCHAR winSequenceNext;
+-
+-} SBRDEC_DRC_CHANNEL;
+-
+-typedef SBRDEC_DRC_CHANNEL *HANDLE_SBR_DRC_CHANNEL;
+-
+-void sbrDecoder_drcInitChannel(HANDLE_SBR_DRC_CHANNEL hDrcData);
+-
+-void sbrDecoder_drcUpdateChannel(HANDLE_SBR_DRC_CHANNEL hDrcData);
+-
+-void sbrDecoder_drcApplySlot(HANDLE_SBR_DRC_CHANNEL hDrcData,
+- FIXP_DBL *qmfRealSlot, FIXP_DBL *qmfImagSlot,
+- int col, int numQmfSubSamples, int maxShift);
+-
+-void sbrDecoder_drcApply(HANDLE_SBR_DRC_CHANNEL hDrcData,
+- FIXP_DBL **QmfBufferReal, FIXP_DBL **QmfBufferImag,
+- int numQmfSubSamples, int *scaleFactor);
+-
+-#endif /* SBRDEC_DRC_H */
+diff --git a/libSBRdec/src/sbrdec_freq_sca.cpp b/libSBRdec/src/sbrdec_freq_sca.cpp
+deleted file mode 100644
+index 165f94b..0000000
+--- a/libSBRdec/src/sbrdec_freq_sca.cpp
++++ /dev/null
+@@ -1,835 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Frequency scale calculation
+-*/
+-
+-#include "sbrdec_freq_sca.h"
+-
+-#include "transcendent.h"
+-#include "sbr_rom.h"
+-#include "env_extr.h"
+-
+-#include "genericStds.h" /* need log() for debug-code only */
+-
+-#define MAX_OCTAVE 29
+-#define MAX_SECOND_REGION 50
+-
+-static int numberOfBands(FIXP_SGL bpo_div16, int start, int stop, int warpFlag);
+-static void CalcBands(UCHAR *diff, UCHAR start, UCHAR stop, UCHAR num_bands);
+-static SBR_ERROR modifyBands(UCHAR max_band, UCHAR *diff, UCHAR length);
+-static void cumSum(UCHAR start_value, UCHAR *diff, UCHAR length,
+- UCHAR *start_adress);
+-
+-/*!
+- \brief Retrieve QMF-band where the SBR range starts
+-
+- Convert startFreq which was read from the bitstream into a
+- QMF-channel number.
+-
+- \return Number of start band
+-*/
+-static UCHAR getStartBand(
+- UINT fs, /*!< Output sampling frequency */
+- UCHAR startFreq, /*!< Index to table of possible start bands */
+- UINT headerDataFlags) /*!< Info to SBR mode */
+-{
+- INT band;
+- UINT fsMapped = fs;
+- SBR_RATE rate = DUAL;
+-
+- if (headerDataFlags & (SBRDEC_SYNTAX_USAC | SBRDEC_SYNTAX_RSVD50)) {
+- if (headerDataFlags & SBRDEC_QUAD_RATE) {
+- rate = QUAD;
+- }
+- fsMapped = sbrdec_mapToStdSampleRate(fs, 1);
+- }
+-
+- FDK_ASSERT(2 * (rate + 1) <= (4));
+-
+- switch (fsMapped) {
+- case 192000:
+- band = FDK_sbrDecoder_sbr_start_freq_192[startFreq];
+- break;
+- case 176400:
+- band = FDK_sbrDecoder_sbr_start_freq_176[startFreq];
+- break;
+- case 128000:
+- band = FDK_sbrDecoder_sbr_start_freq_128[startFreq];
+- break;
+- case 96000:
+- case 88200:
+- band = FDK_sbrDecoder_sbr_start_freq_88[rate][startFreq];
+- break;
+- case 64000:
+- band = FDK_sbrDecoder_sbr_start_freq_64[rate][startFreq];
+- break;
+- case 48000:
+- band = FDK_sbrDecoder_sbr_start_freq_48[rate][startFreq];
+- break;
+- case 44100:
+- band = FDK_sbrDecoder_sbr_start_freq_44[rate][startFreq];
+- break;
+- case 40000:
+- band = FDK_sbrDecoder_sbr_start_freq_40[rate][startFreq];
+- break;
+- case 32000:
+- band = FDK_sbrDecoder_sbr_start_freq_32[rate][startFreq];
+- break;
+- case 24000:
+- band = FDK_sbrDecoder_sbr_start_freq_24[rate][startFreq];
+- break;
+- case 22050:
+- band = FDK_sbrDecoder_sbr_start_freq_22[rate][startFreq];
+- break;
+- case 16000:
+- band = FDK_sbrDecoder_sbr_start_freq_16[rate][startFreq];
+- break;
+- default:
+- band = 255;
+- }
+-
+- return band;
+-}
+-
+-/*!
+- \brief Retrieve QMF-band where the SBR range starts
+-
+- Convert startFreq which was read from the bitstream into a
+- QMF-channel number.
+-
+- \return Number of start band
+-*/
+-static UCHAR getStopBand(
+- UINT fs, /*!< Output sampling frequency */
+- UCHAR stopFreq, /*!< Index to table of possible start bands */
+- UINT headerDataFlags, /*!< Info to SBR mode */
+- UCHAR k0) /*!< Start freq index */
+-{
+- UCHAR k2;
+-
+- if (stopFreq < 14) {
+- INT stopMin;
+- INT num = 2 * (64);
+- UCHAR diff_tot[MAX_OCTAVE + MAX_SECOND_REGION];
+- UCHAR *diff0 = diff_tot;
+- UCHAR *diff1 = diff_tot + MAX_OCTAVE;
+-
+- if (headerDataFlags & SBRDEC_QUAD_RATE) {
+- num >>= 1;
+- }
+-
+- if (fs < 32000) {
+- stopMin = (((2 * 6000 * num) / fs) + 1) >> 1;
+- } else {
+- if (fs < 64000) {
+- stopMin = (((2 * 8000 * num) / fs) + 1) >> 1;
+- } else {
+- stopMin = (((2 * 10000 * num) / fs) + 1) >> 1;
+- }
+- }
+-
+- /*
+- Choose a stop band between k1 and 64 depending on stopFreq (0..13),
+- based on a logarithmic scale.
+- The vectors diff0 and diff1 are used temporarily here.
+- */
+- CalcBands(diff0, stopMin, 64, 13);
+- shellsort(diff0, 13);
+- cumSum(stopMin, diff0, 13, diff1);
+- k2 = diff1[stopFreq];
+- } else if (stopFreq == 14)
+- k2 = 2 * k0;
+- else
+- k2 = 3 * k0;
+-
+- /* Limit to Nyquist */
+- if (k2 > (64)) k2 = (64);
+-
+- /* Range checks */
+- /* 1 <= difference <= 48; 1 <= fs <= 96000 */
+- {
+- UCHAR max_freq_coeffs = (headerDataFlags & SBRDEC_QUAD_RATE)
+- ? MAX_FREQ_COEFFS_QUAD_RATE
+- : MAX_FREQ_COEFFS;
+- if (((k2 - k0) > max_freq_coeffs) || (k2 <= k0)) {
+- return 255;
+- }
+- }
+-
+- if (headerDataFlags & SBRDEC_QUAD_RATE) {
+- return k2; /* skip other checks: (k2 - k0) must be <=
+- MAX_FREQ_COEFFS_QUAD_RATE for all fs */
+- }
+- if (headerDataFlags & (SBRDEC_SYNTAX_USAC | SBRDEC_SYNTAX_RSVD50)) {
+- /* 1 <= difference <= 35; 42000 <= fs <= 96000 */
+- if ((fs >= 42000) && ((k2 - k0) > MAX_FREQ_COEFFS_FS44100)) {
+- return 255;
+- }
+- /* 1 <= difference <= 32; 46009 <= fs <= 96000 */
+- if ((fs >= 46009) && ((k2 - k0) > MAX_FREQ_COEFFS_FS48000)) {
+- return 255;
+- }
+- } else {
+- /* 1 <= difference <= 35; fs == 44100 */
+- if ((fs == 44100) && ((k2 - k0) > MAX_FREQ_COEFFS_FS44100)) {
+- return 255;
+- }
+- /* 1 <= difference <= 32; 48000 <= fs <= 96000 */
+- if ((fs >= 48000) && ((k2 - k0) > MAX_FREQ_COEFFS_FS48000)) {
+- return 255;
+- }
+- }
+-
+- return k2;
+-}
+-
+-/*!
+- \brief Generates master frequency tables
+-
+- Frequency tables are calculated according to the selected domain
+- (linear/logarithmic) and granularity.
+- IEC 14496-3 4.6.18.3.2.1
+-
+- \return errorCode, 0 if successful
+-*/
+-SBR_ERROR
+-sbrdecUpdateFreqScale(
+- UCHAR *v_k_master, /*!< Master table to be created */
+- UCHAR *numMaster, /*!< Number of entries in master table */
+- UINT fs, /*!< SBR working sampling rate */
+- HANDLE_SBR_HEADER_DATA hHeaderData, /*!< Control data from bitstream */
+- UINT flags) {
+- FIXP_SGL bpo_div16; /* bands_per_octave divided by 16 */
+- INT dk = 0;
+-
+- /* Internal variables */
+- UCHAR k0, k2, i;
+- UCHAR num_bands0 = 0;
+- UCHAR num_bands1 = 0;
+- UCHAR diff_tot[MAX_OCTAVE + MAX_SECOND_REGION];
+- UCHAR *diff0 = diff_tot;
+- UCHAR *diff1 = diff_tot + MAX_OCTAVE;
+- INT k2_achived;
+- INT k2_diff;
+- INT incr = 0;
+-
+- /*
+- Determine start band
+- */
+- if (flags & SBRDEC_QUAD_RATE) {
+- fs >>= 1;
+- }
+-
+- k0 = getStartBand(fs, hHeaderData->bs_data.startFreq, flags);
+- if (k0 == 255) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- /*
+- Determine stop band
+- */
+- k2 = getStopBand(fs, hHeaderData->bs_data.stopFreq, flags, k0);
+- if (k2 == 255) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- if (hHeaderData->bs_data.freqScale > 0) { /* Bark */
+- INT k1;
+-
+- if (hHeaderData->bs_data.freqScale == 1) {
+- bpo_div16 = FL2FXCONST_SGL(12.0f / 16.0f);
+- } else if (hHeaderData->bs_data.freqScale == 2) {
+- bpo_div16 = FL2FXCONST_SGL(10.0f / 16.0f);
+- } else {
+- bpo_div16 = FL2FXCONST_SGL(8.0f / 16.0f);
+- }
+-
+- /* Ref: ISO/IEC 23003-3, Figure 12 - Flowchart calculation of fMaster for
+- * 4:1 system when bs_freq_scale > 0 */
+- if (flags & SBRDEC_QUAD_RATE) {
+- if ((SHORT)k0 < (SHORT)(bpo_div16 >> ((FRACT_BITS - 1) - 4))) {
+- bpo_div16 = (FIXP_SGL)(k0 & (UCHAR)0xfe)
+- << ((FRACT_BITS - 1) - 4); /* bpo_div16 = floor(k0/2)*2 */
+- }
+- }
+-
+- if (1000 * k2 > 2245 * k0) { /* Two or more regions */
+- k1 = 2 * k0;
+-
+- num_bands0 = numberOfBands(bpo_div16, k0, k1, 0);
+- num_bands1 =
+- numberOfBands(bpo_div16, k1, k2, hHeaderData->bs_data.alterScale);
+- if (num_bands0 < 1) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+- if (num_bands1 < 1) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- CalcBands(diff0, k0, k1, num_bands0);
+- shellsort(diff0, num_bands0);
+- if (diff0[0] == 0) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- cumSum(k0, diff0, num_bands0, v_k_master);
+-
+- CalcBands(diff1, k1, k2, num_bands1);
+- shellsort(diff1, num_bands1);
+- if (diff0[num_bands0 - 1] > diff1[0]) {
+- SBR_ERROR err;
+-
+- err = modifyBands(diff0[num_bands0 - 1], diff1, num_bands1);
+- if (err) return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- /* Add 2nd region */
+- cumSum(k1, diff1, num_bands1, &v_k_master[num_bands0]);
+- *numMaster = num_bands0 + num_bands1; /* Output nr of bands */
+-
+- } else { /* Only one region */
+- k1 = k2;
+-
+- num_bands0 = numberOfBands(bpo_div16, k0, k1, 0);
+- if (num_bands0 < 1) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+- CalcBands(diff0, k0, k1, num_bands0);
+- shellsort(diff0, num_bands0);
+- if (diff0[0] == 0) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- cumSum(k0, diff0, num_bands0, v_k_master);
+- *numMaster = num_bands0; /* Output nr of bands */
+- }
+- } else { /* Linear mode */
+- if (hHeaderData->bs_data.alterScale == 0) {
+- dk = 1;
+- /* FLOOR to get to few number of bands (next lower even number) */
+- num_bands0 = (k2 - k0) & 254;
+- } else {
+- dk = 2;
+- num_bands0 = (((k2 - k0) >> 1) + 1) & 254; /* ROUND to the closest fit */
+- }
+-
+- if (num_bands0 < 1) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- /* We must return already here because 'i' can become negative below. */
+- }
+-
+- k2_achived = k0 + num_bands0 * dk;
+- k2_diff = k2 - k2_achived;
+-
+- for (i = 0; i < num_bands0; i++) diff_tot[i] = dk;
+-
+- /* If linear scale wasn't achieved */
+- /* and we got too wide SBR area */
+- if (k2_diff < 0) {
+- incr = 1;
+- i = 0;
+- }
+-
+- /* If linear scale wasn't achieved */
+- /* and we got too small SBR area */
+- if (k2_diff > 0) {
+- incr = -1;
+- i = num_bands0 - 1;
+- }
+-
+- /* Adjust diff vector to get sepc. SBR range */
+- while (k2_diff != 0) {
+- diff_tot[i] = diff_tot[i] - incr;
+- i = i + incr;
+- k2_diff = k2_diff + incr;
+- }
+-
+- cumSum(k0, diff_tot, num_bands0, v_k_master); /* cumsum */
+- *numMaster = num_bands0; /* Output nr of bands */
+- }
+-
+- if (*numMaster < 1) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- /* Ref: ISO/IEC 23003-3 Cor.3, "In 7.5.5.2, add to the requirements:"*/
+- if (flags & SBRDEC_QUAD_RATE) {
+- int k;
+- for (k = 1; k < *numMaster; k++) {
+- if (!(v_k_master[k] - v_k_master[k - 1] <= k0 - 2)) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+- }
+- }
+-
+- /*
+- Print out the calculated table
+- */
+-
+- return SBRDEC_OK;
+-}
+-
+-/*!
+- \brief Calculate frequency ratio of one SBR band
+-
+- All SBR bands should span a constant frequency range in the logarithmic
+- domain. This function calculates the ratio of any SBR band's upper and lower
+- frequency.
+-
+- \return num_band-th root of k_start/k_stop
+-*/
+-static FIXP_SGL calcFactorPerBand(int k_start, int k_stop, int num_bands) {
+- /* Scaled bandfactor and step 1 bit right to avoid overflow
+- * use double data type */
+- FIXP_DBL bandfactor = FL2FXCONST_DBL(0.25f); /* Start value */
+- FIXP_DBL step = FL2FXCONST_DBL(0.125f); /* Initial increment for factor */
+-
+- int direction = 1;
+-
+- /* Because saturation can't be done in INT IIS,
+- * changed start and stop data type from FIXP_SGL to FIXP_DBL */
+- FIXP_DBL start = k_start << (DFRACT_BITS - 8);
+- FIXP_DBL stop = k_stop << (DFRACT_BITS - 8);
+-
+- FIXP_DBL temp;
+-
+- int j, i = 0;
+-
+- while (step > FL2FXCONST_DBL(0.0f)) {
+- i++;
+- temp = stop;
+-
+- /* Calculate temp^num_bands: */
+- for (j = 0; j < num_bands; j++)
+- // temp = fMult(temp,bandfactor);
+- temp = fMultDiv2(temp, bandfactor) << 2;
+-
+- if (temp < start) { /* Factor too strong, make it weaker */
+- if (direction == 0)
+- /* Halfen step. Right shift is not done as fract because otherwise the
+- lowest bit cannot be cleared due to rounding */
+- step = (FIXP_DBL)((LONG)step >> 1);
+- direction = 1;
+- bandfactor = bandfactor + step;
+- } else { /* Factor is too weak: make it stronger */
+- if (direction == 1) step = (FIXP_DBL)((LONG)step >> 1);
+- direction = 0;
+- bandfactor = bandfactor - step;
+- }
+-
+- if (i > 100) {
+- step = FL2FXCONST_DBL(0.0f);
+- }
+- }
+- return FX_DBL2FX_SGL(bandfactor << 1);
+-}
+-
+-/*!
+- \brief Calculate number of SBR bands between start and stop band
+-
+- Given the number of bands per octave, this function calculates how many
+- bands fit in the given frequency range.
+- When the warpFlag is set, the 'band density' is decreased by a factor
+- of 1/1.3
+-
+- \return number of bands
+-*/
+-static int numberOfBands(
+- FIXP_SGL bpo_div16, /*!< Input: number of bands per octave divided by 16 */
+- int start, /*!< First QMF band of SBR frequency range */
+- int stop, /*!< Last QMF band of SBR frequency range + 1 */
+- int warpFlag) /*!< Stretching flag */
+-{
+- FIXP_SGL num_bands_div128;
+- int num_bands;
+-
+- num_bands_div128 =
+- FX_DBL2FX_SGL(fMult(FDK_getNumOctavesDiv8(start, stop), bpo_div16));
+-
+- if (warpFlag) {
+- /* Apply the warp factor of 1.3 to get wider bands. We use a value
+- of 32768/25200 instead of the exact value to avoid critical cases
+- of rounding.
+- */
+- num_bands_div128 = FX_DBL2FX_SGL(
+- fMult(num_bands_div128, FL2FXCONST_SGL(25200.0 / 32768.0)));
+- }
+-
+- /* add scaled 1 for rounding to even numbers: */
+- num_bands_div128 = num_bands_div128 + FL2FXCONST_SGL(1.0f / 128.0f);
+- /* scale back to right aligned integer and double the value: */
+- num_bands = 2 * ((LONG)num_bands_div128 >> (FRACT_BITS - 7));
+-
+- return (num_bands);
+-}
+-
+-/*!
+- \brief Calculate width of SBR bands
+-
+- Given the desired number of bands within the SBR frequency range,
+- this function calculates the width of each SBR band in QMF channels.
+- The bands get wider from start to stop (bark scale).
+-*/
+-static void CalcBands(UCHAR *diff, /*!< Vector of widths to be calculated */
+- UCHAR start, /*!< Lower end of subband range */
+- UCHAR stop, /*!< Upper end of subband range */
+- UCHAR num_bands) /*!< Desired number of bands */
+-{
+- int i;
+- int previous;
+- int current;
+- FIXP_SGL exact, temp;
+- FIXP_SGL bandfactor = calcFactorPerBand(start, stop, num_bands);
+-
+- previous = stop; /* Start with highest QMF channel */
+- exact = (FIXP_SGL)(
+- stop << (FRACT_BITS - 8)); /* Shift left to gain some accuracy */
+-
+- for (i = num_bands - 1; i >= 0; i--) {
+- /* Calculate border of next lower sbr band */
+- exact = FX_DBL2FX_SGL(fMult(exact, bandfactor));
+-
+- /* Add scaled 0.5 for rounding:
+- We use a value 128/256 instead of 0.5 to avoid some critical cases of
+- rounding. */
+- temp = exact + FL2FXCONST_SGL(128.0 / 32768.0);
+-
+- /* scale back to right alinged integer: */
+- current = (LONG)temp >> (FRACT_BITS - 8);
+-
+- /* Save width of band i */
+- diff[i] = previous - current;
+- previous = current;
+- }
+-}
+-
+-/*!
+- \brief Calculate cumulated sum vector from delta vector
+-*/
+-static void cumSum(UCHAR start_value, UCHAR *diff, UCHAR length,
+- UCHAR *start_adress) {
+- int i;
+- start_adress[0] = start_value;
+- for (i = 1; i <= length; i++)
+- start_adress[i] = start_adress[i - 1] + diff[i - 1];
+-}
+-
+-/*!
+- \brief Adapt width of frequency bands in the second region
+-
+- If SBR spans more than 2 octaves, the upper part of a bark-frequency-scale
+- is calculated separately. This function tries to avoid that the second region
+- starts with a band smaller than the highest band of the first region.
+-*/
+-static SBR_ERROR modifyBands(UCHAR max_band_previous, UCHAR *diff,
+- UCHAR length) {
+- int change = max_band_previous - diff[0];
+-
+- /* Limit the change so that the last band cannot get narrower than the first
+- * one */
+- if (change > (diff[length - 1] - diff[0]) >> 1)
+- change = (diff[length - 1] - diff[0]) >> 1;
+-
+- diff[0] += change;
+- diff[length - 1] -= change;
+- shellsort(diff, length);
+-
+- return SBRDEC_OK;
+-}
+-
+-/*!
+- \brief Update high resolution frequency band table
+-*/
+-static void sbrdecUpdateHiRes(UCHAR *h_hires, UCHAR *num_hires,
+- UCHAR *v_k_master, UCHAR num_bands,
+- UCHAR xover_band) {
+- UCHAR i;
+-
+- *num_hires = num_bands - xover_band;
+-
+- for (i = xover_band; i <= num_bands; i++) {
+- h_hires[i - xover_band] = v_k_master[i];
+- }
+-}
+-
+-/*!
+- \brief Build low resolution table out of high resolution table
+-*/
+-static void sbrdecUpdateLoRes(UCHAR *h_lores, UCHAR *num_lores, UCHAR *h_hires,
+- UCHAR num_hires) {
+- UCHAR i;
+-
+- if ((num_hires & 1) == 0) {
+- /* If even number of hires bands */
+- *num_lores = num_hires >> 1;
+- /* Use every second lores=hires[0,2,4...] */
+- for (i = 0; i <= *num_lores; i++) h_lores[i] = h_hires[i * 2];
+- } else {
+- /* Odd number of hires, which means xover is odd */
+- *num_lores = (num_hires + 1) >> 1;
+- /* Use lores=hires[0,1,3,5 ...] */
+- h_lores[0] = h_hires[0];
+- for (i = 1; i <= *num_lores; i++) {
+- h_lores[i] = h_hires[i * 2 - 1];
+- }
+- }
+-}
+-
+-/*!
+- \brief Derive a low-resolution frequency-table from the master frequency
+- table
+-*/
+-void sbrdecDownSampleLoRes(UCHAR *v_result, UCHAR num_result,
+- UCHAR *freqBandTableRef, UCHAR num_Ref) {
+- int step;
+- int i, j;
+- int org_length, result_length;
+- int v_index[MAX_FREQ_COEFFS >> 1];
+-
+- /* init */
+- org_length = num_Ref;
+- result_length = num_result;
+-
+- v_index[0] = 0; /* Always use left border */
+- i = 0;
+- while (org_length > 0) {
+- /* Create downsample vector */
+- i++;
+- step = org_length / result_length;
+- org_length = org_length - step;
+- result_length--;
+- v_index[i] = v_index[i - 1] + step;
+- }
+-
+- for (j = 0; j <= i; j++) {
+- /* Use downsample vector to index LoResolution vector */
+- v_result[j] = freqBandTableRef[v_index[j]];
+- }
+-}
+-
+-/*!
+- \brief Sorting routine
+-*/
+-void shellsort(UCHAR *in, UCHAR n) {
+- int i, j, v, w;
+- int inc = 1;
+-
+- do
+- inc = 3 * inc + 1;
+- while (inc <= n);
+-
+- do {
+- inc = inc / 3;
+- for (i = inc; i < n; i++) {
+- v = in[i];
+- j = i;
+- while ((w = in[j - inc]) > v) {
+- in[j] = w;
+- j -= inc;
+- if (j < inc) break;
+- }
+- in[j] = v;
+- }
+- } while (inc > 1);
+-}
+-
+-/*!
+- \brief Reset frequency band tables
+- \return errorCode, 0 if successful
+-*/
+-SBR_ERROR
+-resetFreqBandTables(HANDLE_SBR_HEADER_DATA hHeaderData, const UINT flags) {
+- SBR_ERROR err = SBRDEC_OK;
+- int k2, kx, lsb, usb;
+- int intTemp;
+- UCHAR nBandsLo, nBandsHi;
+- HANDLE_FREQ_BAND_DATA hFreq = &hHeaderData->freqBandData;
+-
+- /* Calculate master frequency function */
+- err = sbrdecUpdateFreqScale(hFreq->v_k_master, &hFreq->numMaster,
+- hHeaderData->sbrProcSmplRate, hHeaderData, flags);
+-
+- if (err || (hHeaderData->bs_info.xover_band > hFreq->numMaster)) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- /* Derive Hiresolution from master frequency function */
+- sbrdecUpdateHiRes(hFreq->freqBandTable[1], &nBandsHi, hFreq->v_k_master,
+- hFreq->numMaster, hHeaderData->bs_info.xover_band);
+- /* Derive Loresolution from Hiresolution */
+- sbrdecUpdateLoRes(hFreq->freqBandTable[0], &nBandsLo, hFreq->freqBandTable[1],
+- nBandsHi);
+-
+- hFreq->nSfb[0] = nBandsLo;
+- hFreq->nSfb[1] = nBandsHi;
+-
+- /* Check index to freqBandTable[0] */
+- if (!(nBandsLo > 0) ||
+- (nBandsLo > (((hHeaderData->numberOfAnalysisBands == 16)
+- ? MAX_FREQ_COEFFS_QUAD_RATE
+- : MAX_FREQ_COEFFS_DUAL_RATE) >>
+- 1))) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- lsb = hFreq->freqBandTable[0][0];
+- usb = hFreq->freqBandTable[0][nBandsLo];
+-
+- /* Check for start frequency border k_x:
+- - ISO/IEC 14496-3 4.6.18.3.6 Requirements
+- - ISO/IEC 23003-3 7.5.5.2 Modifications and additions to the MPEG-4 SBR
+- tool
+- */
+- /* Note that lsb > as hHeaderData->numberOfAnalysisBands is a valid SBR config
+- * for 24 band QMF analysis. */
+- if ((lsb > ((flags & SBRDEC_QUAD_RATE) ? 16 : (32))) || (lsb >= usb)) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- /* Calculate number of noise bands */
+-
+- k2 = hFreq->freqBandTable[1][nBandsHi];
+- kx = hFreq->freqBandTable[1][0];
+-
+- if (hHeaderData->bs_data.noise_bands == 0) {
+- hFreq->nNfb = 1;
+- } else /* Calculate no of noise bands 1,2 or 3 bands/octave */
+- {
+- /* Fetch number of octaves divided by 32 */
+- intTemp = (LONG)FDK_getNumOctavesDiv8(kx, k2) >> 2;
+-
+- /* Integer-Multiplication with number of bands: */
+- intTemp = intTemp * hHeaderData->bs_data.noise_bands;
+-
+- /* Add scaled 0.5 for rounding: */
+- intTemp = intTemp + (LONG)FL2FXCONST_SGL(0.5f / 32.0f);
+-
+- /* Convert to right-aligned integer: */
+- intTemp = intTemp >> (FRACT_BITS - 1 /*sign*/ - 5 /* rescale */);
+-
+- if (intTemp == 0) intTemp = 1;
+-
+- hFreq->nNfb = intTemp;
+- }
+-
+- hFreq->nInvfBands = hFreq->nNfb;
+-
+- if (hFreq->nNfb > MAX_NOISE_COEFFS) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- /* Get noise bands */
+- sbrdecDownSampleLoRes(hFreq->freqBandTableNoise, hFreq->nNfb,
+- hFreq->freqBandTable[0], nBandsLo);
+-
+- /* save old highband; required for overlap in usac
+- when headerchange occurs at XVAR and VARX frame; */
+- hFreq->ov_highSubband = hFreq->highSubband;
+-
+- hFreq->lowSubband = lsb;
+- hFreq->highSubband = usb;
+-
+- return SBRDEC_OK;
+-}
+diff --git a/libSBRdec/src/sbrdec_freq_sca.h b/libSBRdec/src/sbrdec_freq_sca.h
+deleted file mode 100644
+index 7e6b8e8..0000000
+--- a/libSBRdec/src/sbrdec_freq_sca.h
++++ /dev/null
+@@ -1,127 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Frequency scale prototypes
+-*/
+-#ifndef SBRDEC_FREQ_SCA_H
+-#define SBRDEC_FREQ_SCA_H
+-
+-#include "sbrdecoder.h"
+-#include "env_extr.h"
+-
+-typedef enum { DUAL, QUAD } SBR_RATE;
+-
+-SBR_ERROR
+-sbrdecUpdateFreqScale(UCHAR *v_k_master, UCHAR *numMaster, UINT fs,
+- HANDLE_SBR_HEADER_DATA headerData, UINT flags);
+-
+-void sbrdecDownSampleLoRes(UCHAR *v_result, UCHAR num_result,
+- UCHAR *freqBandTableRef, UCHAR num_Ref);
+-
+-void shellsort(UCHAR *in, UCHAR n);
+-
+-SBR_ERROR
+-resetFreqBandTables(HANDLE_SBR_HEADER_DATA hHeaderData, const UINT flags);
+-
+-#endif
+diff --git a/libSBRdec/src/sbrdecoder.cpp b/libSBRdec/src/sbrdecoder.cpp
+deleted file mode 100644
+index 4bc6f69..0000000
+--- a/libSBRdec/src/sbrdecoder.cpp
++++ /dev/null
+@@ -1,2023 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief SBR decoder frontend
+- This module provides a frontend to the SBR decoder. The function openSBR() is
+- called for initialization. The function sbrDecoder_Apply() is called for each
+- frame. sbr_Apply() will call the required functions to decode the raw SBR data
+- (provided by env_extr.cpp), to decode the envelope data and noise floor levels
+- [decodeSbrData()], and to finally apply SBR to the current frame [sbr_dec()].
+-
+- \sa sbrDecoder_Apply(), \ref documentationOverview
+-*/
+-
+-/*!
+- \page documentationOverview Overview of important information resources and
+- source code documentation
+-
+- As part of this documentation you can find more extensive descriptions about
+- key concepts and algorithms at the following locations:
+-
+- <h2>Programming</h2>
+-
+- \li Buffer management: sbrDecoder_Apply() and sbr_dec()
+- \li Internal scale factors to maximize SNR on fixed point processors:
+- #QMF_SCALE_FACTOR \li Special mantissa-exponent format: Created in
+- requantizeEnvelopeData() and used in calculateSbrEnvelope()
+-
+- <h2>Algorithmic details</h2>
+- \li About the SBR data format: \ref SBR_HEADER_ELEMENT and \ref
+- SBR_STANDARD_ELEMENT \li Details about the bitstream decoder: env_extr.cpp \li
+- Details about the QMF filterbank and the provided polyphase implementation:
+- qmf_dec.cpp \li Details about the transposer: lpp_tran.cpp \li Details about
+- the envelope adjuster: env_calc.cpp
+-
+-*/
+-
+-#include "sbrdecoder.h"
+-
+-#include "FDK_bitstream.h"
+-
+-#include "sbrdec_freq_sca.h"
+-#include "env_extr.h"
+-#include "sbr_dec.h"
+-#include "env_dec.h"
+-#include "sbr_crc.h"
+-#include "sbr_ram.h"
+-#include "sbr_rom.h"
+-#include "lpp_tran.h"
+-#include "transcendent.h"
+-
+-#include "FDK_crc.h"
+-
+-#include "sbrdec_drc.h"
+-
+-#include "psbitdec.h"
+-
+-/* Decoder library info */
+-#define SBRDECODER_LIB_VL0 3
+-#define SBRDECODER_LIB_VL1 0
+-#define SBRDECODER_LIB_VL2 0
+-#define SBRDECODER_LIB_TITLE "SBR Decoder"
+-#ifdef __ANDROID__
+-#define SBRDECODER_LIB_BUILD_DATE ""
+-#define SBRDECODER_LIB_BUILD_TIME ""
+-#else
+-#define SBRDECODER_LIB_BUILD_DATE __DATE__
+-#define SBRDECODER_LIB_BUILD_TIME __TIME__
+-#endif
+-
+-static void setFrameErrorFlag(SBR_DECODER_ELEMENT *pSbrElement, UCHAR value) {
+- if (pSbrElement != NULL) {
+- switch (value) {
+- case FRAME_ERROR_ALLSLOTS:
+- FDKmemset(pSbrElement->frameErrorFlag, FRAME_ERROR,
+- sizeof(pSbrElement->frameErrorFlag));
+- break;
+- default:
+- pSbrElement->frameErrorFlag[pSbrElement->useFrameSlot] = value;
+- }
+- }
+-}
+-
+-static UCHAR getHeaderSlot(UCHAR currentSlot, UCHAR hdrSlotUsage[(1) + 1]) {
+- UINT occupied = 0;
+- int s;
+- UCHAR slot = hdrSlotUsage[currentSlot];
+-
+- FDK_ASSERT((1) + 1 < 32);
+-
+- for (s = 0; s < (1) + 1; s++) {
+- if ((hdrSlotUsage[s] == slot) && (s != slot)) {
+- occupied = 1;
+- break;
+- }
+- }
+-
+- if (occupied) {
+- occupied = 0;
+-
+- for (s = 0; s < (1) + 1; s++) {
+- occupied |= 1 << hdrSlotUsage[s];
+- }
+- for (s = 0; s < (1) + 1; s++) {
+- if (!(occupied & 0x1)) {
+- slot = s;
+- break;
+- }
+- occupied >>= 1;
+- }
+- }
+-
+- return slot;
+-}
+-
+-static void copySbrHeader(HANDLE_SBR_HEADER_DATA hDst,
+- const HANDLE_SBR_HEADER_DATA hSrc) {
+- /* copy the whole header memory (including pointers) */
+- FDKmemcpy(hDst, hSrc, sizeof(SBR_HEADER_DATA));
+-
+- /* update pointers */
+- hDst->freqBandData.freqBandTable[0] = hDst->freqBandData.freqBandTableLo;
+- hDst->freqBandData.freqBandTable[1] = hDst->freqBandData.freqBandTableHi;
+-}
+-
+-static int compareSbrHeader(const HANDLE_SBR_HEADER_DATA hHdr1,
+- const HANDLE_SBR_HEADER_DATA hHdr2) {
+- int result = 0;
+-
+- /* compare basic data */
+- result |= (hHdr1->syncState != hHdr2->syncState) ? 1 : 0;
+- result |= (hHdr1->status != hHdr2->status) ? 1 : 0;
+- result |= (hHdr1->frameErrorFlag != hHdr2->frameErrorFlag) ? 1 : 0;
+- result |= (hHdr1->numberTimeSlots != hHdr2->numberTimeSlots) ? 1 : 0;
+- result |=
+- (hHdr1->numberOfAnalysisBands != hHdr2->numberOfAnalysisBands) ? 1 : 0;
+- result |= (hHdr1->timeStep != hHdr2->timeStep) ? 1 : 0;
+- result |= (hHdr1->sbrProcSmplRate != hHdr2->sbrProcSmplRate) ? 1 : 0;
+-
+- /* compare bitstream data */
+- result |=
+- FDKmemcmp(&hHdr1->bs_data, &hHdr2->bs_data, sizeof(SBR_HEADER_DATA_BS));
+- result |=
+- FDKmemcmp(&hHdr1->bs_dflt, &hHdr2->bs_dflt, sizeof(SBR_HEADER_DATA_BS));
+- result |= FDKmemcmp(&hHdr1->bs_info, &hHdr2->bs_info,
+- sizeof(SBR_HEADER_DATA_BS_INFO));
+-
+- /* compare frequency band data */
+- result |= FDKmemcmp(&hHdr1->freqBandData, &hHdr2->freqBandData,
+- (8 + MAX_NUM_LIMITERS + 1) * sizeof(UCHAR));
+- result |= FDKmemcmp(hHdr1->freqBandData.freqBandTableLo,
+- hHdr2->freqBandData.freqBandTableLo,
+- (MAX_FREQ_COEFFS / 2 + 1) * sizeof(UCHAR));
+- result |= FDKmemcmp(hHdr1->freqBandData.freqBandTableHi,
+- hHdr2->freqBandData.freqBandTableHi,
+- (MAX_FREQ_COEFFS + 1) * sizeof(UCHAR));
+- result |= FDKmemcmp(hHdr1->freqBandData.freqBandTableNoise,
+- hHdr2->freqBandData.freqBandTableNoise,
+- (MAX_NOISE_COEFFS + 1) * sizeof(UCHAR));
+- result |=
+- FDKmemcmp(hHdr1->freqBandData.v_k_master, hHdr2->freqBandData.v_k_master,
+- (MAX_FREQ_COEFFS + 1) * sizeof(UCHAR));
+-
+- return result;
+-}
+-
+-/*!
+- \brief Reset SBR decoder.
+-
+- Reset should only be called if SBR has been sucessfully detected by
+- an appropriate checkForPayload() function.
+-
+- \return Error code.
+-*/
+-static SBR_ERROR sbrDecoder_ResetElement(HANDLE_SBRDECODER self,
+- int sampleRateIn, int sampleRateOut,
+- int samplesPerFrame,
+- const MP4_ELEMENT_ID elementID,
+- const int elementIndex,
+- const int overlap) {
+- SBR_ERROR sbrError = SBRDEC_OK;
+- HANDLE_SBR_HEADER_DATA hSbrHeader;
+- UINT qmfFlags = 0;
+-
+- int i, synDownsampleFac;
+-
+- /* USAC: assuming theoretical case 8 kHz output sample rate with 4:1 SBR */
+- const int sbr_min_sample_rate_in = IS_USAC(self->coreCodec) ? 2000 : 6400;
+-
+- /* Check in/out samplerates */
+- if (sampleRateIn < sbr_min_sample_rate_in || sampleRateIn > (96000)) {
+- sbrError = SBRDEC_UNSUPPORTED_CONFIG;
+- goto bail;
+- }
+-
+- if (sampleRateOut > (96000)) {
+- sbrError = SBRDEC_UNSUPPORTED_CONFIG;
+- goto bail;
+- }
+-
+- /* Set QMF mode flags */
+- if (self->flags & SBRDEC_LOW_POWER) qmfFlags |= QMF_FLAG_LP;
+-
+- if (self->coreCodec == AOT_ER_AAC_ELD) {
+- if (self->flags & SBRDEC_LD_MPS_QMF) {
+- qmfFlags |= QMF_FLAG_MPSLDFB;
+- } else {
+- qmfFlags |= QMF_FLAG_CLDFB;
+- }
+- }
+-
+- /* Set downsampling factor for synthesis filter bank */
+- if (sampleRateOut == 0) {
+- /* no single rate mode */
+- sampleRateOut =
+- sampleRateIn
+- << 1; /* In case of implicit signalling, assume dual rate SBR */
+- }
+-
+- if (sampleRateIn == sampleRateOut) {
+- synDownsampleFac = 2;
+- self->flags |= SBRDEC_DOWNSAMPLE;
+- } else {
+- synDownsampleFac = 1;
+- self->flags &= ~SBRDEC_DOWNSAMPLE;
+- }
+-
+- self->synDownsampleFac = synDownsampleFac;
+- self->sampleRateOut = sampleRateOut;
+-
+- {
+- for (i = 0; i < (1) + 1; i++) {
+- int setDflt;
+- hSbrHeader = &(self->sbrHeader[elementIndex][i]);
+- setDflt = ((hSbrHeader->syncState == SBR_NOT_INITIALIZED) ||
+- (self->flags & SBRDEC_FORCE_RESET))
+- ? 1
+- : 0;
+-
+- /* init a default header such that we can at least do upsampling later */
+- sbrError = initHeaderData(hSbrHeader, sampleRateIn, sampleRateOut,
+- self->downscaleFactor, samplesPerFrame,
+- self->flags, setDflt);
+-
+- /* Set synchState to UPSAMPLING in case it already is initialized */
+- hSbrHeader->syncState = hSbrHeader->syncState > UPSAMPLING
+- ? UPSAMPLING
+- : hSbrHeader->syncState;
+- }
+- }
+-
+- if (sbrError != SBRDEC_OK) {
+- goto bail;
+- }
+-
+- if (!self->pQmfDomain->globalConf.qmfDomainExplicitConfig) {
+- self->pQmfDomain->globalConf.flags_requested |= qmfFlags;
+- self->pQmfDomain->globalConf.nBandsAnalysis_requested =
+- self->sbrHeader[elementIndex][0].numberOfAnalysisBands;
+- self->pQmfDomain->globalConf.nBandsSynthesis_requested =
+- (synDownsampleFac == 1) ? 64 : 32; /* may be overwritten by MPS */
+- self->pQmfDomain->globalConf.nBandsSynthesis_requested /=
+- self->downscaleFactor;
+- self->pQmfDomain->globalConf.nQmfTimeSlots_requested =
+- self->sbrHeader[elementIndex][0].numberTimeSlots *
+- self->sbrHeader[elementIndex][0].timeStep;
+- self->pQmfDomain->globalConf.nQmfOvTimeSlots_requested = overlap;
+- self->pQmfDomain->globalConf.nQmfProcBands_requested = 64; /* always 64 */
+- self->pQmfDomain->globalConf.nQmfProcChannels_requested =
+- 1; /* may be overwritten by MPS */
+- }
+-
+- /* Init SBR channels going to be assigned to a SBR element */
+- {
+- int ch;
+- for (ch = 0; ch < self->pSbrElement[elementIndex]->nChannels; ch++) {
+- int headerIndex =
+- getHeaderSlot(self->pSbrElement[elementIndex]->useFrameSlot,
+- self->pSbrElement[elementIndex]->useHeaderSlot);
+-
+- /* and create sbrDec */
+- sbrError =
+- createSbrDec(self->pSbrElement[elementIndex]->pSbrChannel[ch],
+- &self->sbrHeader[elementIndex][headerIndex],
+- &self->pSbrElement[elementIndex]->transposerSettings,
+- synDownsampleFac, qmfFlags, self->flags, overlap, ch,
+- self->codecFrameSize);
+-
+- if (sbrError != SBRDEC_OK) {
+- goto bail;
+- }
+- }
+- }
+-
+- // FDKmemclear(sbr_OverlapBuffer, sizeof(sbr_OverlapBuffer));
+-
+- if (self->numSbrElements == 1) {
+- switch (self->coreCodec) {
+- case AOT_AAC_LC:
+- case AOT_SBR:
+- case AOT_PS:
+- case AOT_ER_AAC_SCAL:
+- case AOT_DRM_AAC:
+- case AOT_DRM_SURROUND:
+- if (CreatePsDec(&self->hParametricStereoDec, samplesPerFrame)) {
+- sbrError = SBRDEC_CREATE_ERROR;
+- goto bail;
+- }
+- break;
+- default:
+- break;
+- }
+- }
+-
+- /* Init frame delay slot handling */
+- self->pSbrElement[elementIndex]->useFrameSlot = 0;
+- for (i = 0; i < ((1) + 1); i++) {
+- self->pSbrElement[elementIndex]->useHeaderSlot[i] = i;
+- }
+-
+-bail:
+-
+- return sbrError;
+-}
+-
+-/*!
+- \brief Assign QMF domain provided QMF channels to SBR channels.
+-
+- \return void
+-*/
+-static void sbrDecoder_AssignQmfChannels2SbrChannels(HANDLE_SBRDECODER self) {
+- int ch, el, absCh_offset = 0;
+- for (el = 0; el < self->numSbrElements; el++) {
+- if (self->pSbrElement[el] != NULL) {
+- for (ch = 0; ch < self->pSbrElement[el]->nChannels; ch++) {
+- FDK_ASSERT(((absCh_offset + ch) < ((8) + (1))) &&
+- ((absCh_offset + ch) < ((8) + (1))));
+- self->pSbrElement[el]->pSbrChannel[ch]->SbrDec.qmfDomainInCh =
+- &self->pQmfDomain->QmfDomainIn[absCh_offset + ch];
+- self->pSbrElement[el]->pSbrChannel[ch]->SbrDec.qmfDomainOutCh =
+- &self->pQmfDomain->QmfDomainOut[absCh_offset + ch];
+- }
+- absCh_offset += self->pSbrElement[el]->nChannels;
+- }
+- }
+-}
+-
+-SBR_ERROR sbrDecoder_Open(HANDLE_SBRDECODER *pSelf,
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain) {
+- HANDLE_SBRDECODER self = NULL;
+- SBR_ERROR sbrError = SBRDEC_OK;
+- int elIdx;
+-
+- if ((pSelf == NULL) || (pQmfDomain == NULL)) {
+- return SBRDEC_INVALID_ARGUMENT;
+- }
+-
+- /* Get memory for this instance */
+- self = GetRam_SbrDecoder();
+- if (self == NULL) {
+- sbrError = SBRDEC_MEM_ALLOC_FAILED;
+- goto bail;
+- }
+-
+- self->pQmfDomain = pQmfDomain;
+-
+- /*
+- Already zero because of calloc
+- self->numSbrElements = 0;
+- self->numSbrChannels = 0;
+- self->codecFrameSize = 0;
+- */
+-
+- self->numDelayFrames = (1); /* set to the max value by default */
+-
+- /* Initialize header sync state */
+- for (elIdx = 0; elIdx < (8); elIdx += 1) {
+- int i;
+- for (i = 0; i < (1) + 1; i += 1) {
+- self->sbrHeader[elIdx][i].syncState = SBR_NOT_INITIALIZED;
+- }
+- }
+-
+- *pSelf = self;
+-
+-bail:
+- return sbrError;
+-}
+-
+-/**
+- * \brief determine if the given core codec AOT can be processed or not.
+- * \param coreCodec core codec audio object type.
+- * \return 1 if SBR can be processed, 0 if SBR cannot be processed/applied.
+- */
+-static int sbrDecoder_isCoreCodecValid(AUDIO_OBJECT_TYPE coreCodec) {
+- switch (coreCodec) {
+- case AOT_AAC_LC:
+- case AOT_SBR:
+- case AOT_PS:
+- case AOT_ER_AAC_SCAL:
+- case AOT_ER_AAC_ELD:
+- case AOT_DRM_AAC:
+- case AOT_DRM_SURROUND:
+- case AOT_USAC:
+- return 1;
+- default:
+- return 0;
+- }
+-}
+-
+-static void sbrDecoder_DestroyElement(HANDLE_SBRDECODER self,
+- const int elementIndex) {
+- if (self->pSbrElement[elementIndex] != NULL) {
+- int ch;
+-
+- for (ch = 0; ch < SBRDEC_MAX_CH_PER_ELEMENT; ch++) {
+- if (self->pSbrElement[elementIndex]->pSbrChannel[ch] != NULL) {
+- deleteSbrDec(self->pSbrElement[elementIndex]->pSbrChannel[ch]);
+- FreeRam_SbrDecChannel(
+- &self->pSbrElement[elementIndex]->pSbrChannel[ch]);
+- self->numSbrChannels -= 1;
+- }
+- }
+- FreeRam_SbrDecElement(&self->pSbrElement[elementIndex]);
+- self->numSbrElements -= 1;
+- }
+-}
+-
+-SBR_ERROR sbrDecoder_InitElement(
+- HANDLE_SBRDECODER self, const int sampleRateIn, const int sampleRateOut,
+- const int samplesPerFrame, const AUDIO_OBJECT_TYPE coreCodec,
+- const MP4_ELEMENT_ID elementID, const int elementIndex,
+- const UCHAR harmonicSBR, const UCHAR stereoConfigIndex,
+- const UCHAR configMode, UCHAR *configChanged, const INT downscaleFactor) {
+- SBR_ERROR sbrError = SBRDEC_OK;
+- int chCnt = 0;
+- int nSbrElementsStart;
+- int nSbrChannelsStart;
+- if (self == NULL) {
+- return SBRDEC_INVALID_ARGUMENT;
+- }
+-
+- nSbrElementsStart = self->numSbrElements;
+- nSbrChannelsStart = self->numSbrChannels;
+-
+- /* Check core codec AOT */
+- if (!sbrDecoder_isCoreCodecValid(coreCodec) || elementIndex >= (8)) {
+- sbrError = SBRDEC_UNSUPPORTED_CONFIG;
+- goto bail;
+- }
+-
+- if (elementID != ID_SCE && elementID != ID_CPE && elementID != ID_LFE) {
+- sbrError = SBRDEC_UNSUPPORTED_CONFIG;
+- goto bail;
+- }
+-
+- if (self->sampleRateIn == sampleRateIn &&
+- self->codecFrameSize == samplesPerFrame && self->coreCodec == coreCodec &&
+- self->pSbrElement[elementIndex] != NULL &&
+- self->pSbrElement[elementIndex]->elementID == elementID &&
+- !(self->flags & SBRDEC_FORCE_RESET) &&
+- ((sampleRateOut == 0) ? 1 : (self->sampleRateOut == sampleRateOut)) &&
+- ((harmonicSBR == 2) ? 1
+- : (self->harmonicSBR ==
+- harmonicSBR)) /* The value 2 signalizes that
+- harmonicSBR shall be ignored in
+- the config change detection */
+- ) {
+- /* Nothing to do */
+- return SBRDEC_OK;
+- } else {
+- if (configMode & AC_CM_DET_CFG_CHANGE) {
+- *configChanged = 1;
+- }
+- }
+-
+- /* reaching this point the SBR-decoder gets (re-)configured */
+-
+- /* The flags field is used for all elements! */
+- self->flags &=
+- (SBRDEC_FORCE_RESET | SBRDEC_FLUSH); /* Keep the global flags. They will
+- be reset after decoding. */
+- self->flags |= (downscaleFactor > 1) ? SBRDEC_ELD_DOWNSCALE : 0;
+- self->flags |= (coreCodec == AOT_ER_AAC_ELD) ? SBRDEC_ELD_GRID : 0;
+- self->flags |= (coreCodec == AOT_ER_AAC_SCAL) ? SBRDEC_SYNTAX_SCAL : 0;
+- self->flags |=
+- (coreCodec == AOT_DRM_AAC) ? SBRDEC_SYNTAX_SCAL | SBRDEC_SYNTAX_DRM : 0;
+- self->flags |= (coreCodec == AOT_DRM_SURROUND)
+- ? SBRDEC_SYNTAX_SCAL | SBRDEC_SYNTAX_DRM
+- : 0;
+- self->flags |= (coreCodec == AOT_USAC) ? SBRDEC_SYNTAX_USAC : 0;
+- /* Robustness: Take integer division rounding into consideration. E.g. 22050
+- * Hz with 4:1 SBR => 5512 Hz core sampling rate. */
+- self->flags |= (sampleRateIn == sampleRateOut / 4) ? SBRDEC_QUAD_RATE : 0;
+- self->flags |= (harmonicSBR == 1) ? SBRDEC_USAC_HARMONICSBR : 0;
+-
+- if (configMode & AC_CM_DET_CFG_CHANGE) {
+- return SBRDEC_OK;
+- }
+-
+- self->sampleRateIn = sampleRateIn;
+- self->codecFrameSize = samplesPerFrame;
+- self->coreCodec = coreCodec;
+- self->harmonicSBR = harmonicSBR;
+- self->downscaleFactor = downscaleFactor;
+-
+- /* Init SBR elements */
+- {
+- int elChannels, ch;
+-
+- if (self->pSbrElement[elementIndex] == NULL) {
+- self->pSbrElement[elementIndex] = GetRam_SbrDecElement(elementIndex);
+- if (self->pSbrElement[elementIndex] == NULL) {
+- sbrError = SBRDEC_MEM_ALLOC_FAILED;
+- goto bail;
+- }
+- self->numSbrElements++;
+- } else {
+- self->numSbrChannels -= self->pSbrElement[elementIndex]->nChannels;
+- }
+-
+- /* Save element ID for sanity checks and to have a fallback for concealment.
+- */
+- self->pSbrElement[elementIndex]->elementID = elementID;
+-
+- /* Determine amount of channels for this element */
+- switch (elementID) {
+- case ID_NONE:
+- case ID_CPE:
+- elChannels = 2;
+- break;
+- case ID_LFE:
+- case ID_SCE:
+- elChannels = 1;
+- break;
+- default:
+- elChannels = 0;
+- break;
+- }
+-
+- /* Handle case of Parametric Stereo */
+- if (elementIndex == 0 && elementID == ID_SCE) {
+- switch (coreCodec) {
+- case AOT_AAC_LC:
+- case AOT_SBR:
+- case AOT_PS:
+- case AOT_ER_AAC_SCAL:
+- case AOT_DRM_AAC:
+- case AOT_DRM_SURROUND:
+- elChannels = 2;
+- break;
+- default:
+- break;
+- }
+- }
+-
+- /* Sanity check to avoid memory leaks */
+- if (elChannels < self->pSbrElement[elementIndex]->nChannels) {
+- self->numSbrChannels += self->pSbrElement[elementIndex]->nChannels;
+- sbrError = SBRDEC_PARSE_ERROR;
+- goto bail;
+- }
+-
+- self->pSbrElement[elementIndex]->nChannels = elChannels;
+-
+- for (ch = 0; ch < elChannels; ch++) {
+- if (self->pSbrElement[elementIndex]->pSbrChannel[ch] == NULL) {
+- self->pSbrElement[elementIndex]->pSbrChannel[ch] =
+- GetRam_SbrDecChannel(chCnt);
+- if (self->pSbrElement[elementIndex]->pSbrChannel[ch] == NULL) {
+- sbrError = SBRDEC_MEM_ALLOC_FAILED;
+- goto bail;
+- }
+- }
+- self->numSbrChannels++;
+-
+- sbrDecoder_drcInitChannel(&self->pSbrElement[elementIndex]
+- ->pSbrChannel[ch]
+- ->SbrDec.sbrDrcChannel);
+-
+- chCnt++;
+- }
+- }
+-
+- if (!self->pQmfDomain->globalConf.qmfDomainExplicitConfig) {
+- self->pQmfDomain->globalConf.nInputChannels_requested =
+- self->numSbrChannels;
+- self->pQmfDomain->globalConf.nOutputChannels_requested =
+- fMax((INT)self->numSbrChannels,
+- (INT)self->pQmfDomain->globalConf.nOutputChannels_requested);
+- }
+-
+- /* Make sure each SBR channel has one QMF channel assigned even if
+- * numSbrChannels or element set-up has changed. */
+- sbrDecoder_AssignQmfChannels2SbrChannels(self);
+-
+- /* clear error flags for all delay slots */
+- FDKmemclear(self->pSbrElement[elementIndex]->frameErrorFlag,
+- ((1) + 1) * sizeof(UCHAR));
+-
+- {
+- int overlap;
+-
+- if (coreCodec == AOT_ER_AAC_ELD) {
+- overlap = 0;
+- } else if (self->flags & SBRDEC_QUAD_RATE) {
+- overlap = (3 * 4);
+- } else {
+- overlap = (3 * 2);
+- }
+- /* Initialize this instance */
+- sbrError = sbrDecoder_ResetElement(self, sampleRateIn, sampleRateOut,
+- samplesPerFrame, elementID, elementIndex,
+- overlap);
+- }
+-
+-bail:
+- if (sbrError != SBRDEC_OK) {
+- if ((nSbrElementsStart < self->numSbrElements) ||
+- (nSbrChannelsStart < self->numSbrChannels)) {
+- /* Free the memory allocated for this element */
+- sbrDecoder_DestroyElement(self, elementIndex);
+- } else if ((elementIndex < (8)) &&
+- (self->pSbrElement[elementIndex] !=
+- NULL)) { /* Set error flag to trigger concealment */
+- setFrameErrorFlag(self->pSbrElement[elementIndex], FRAME_ERROR);
+- }
+- }
+-
+- return sbrError;
+-}
+-
+-/**
+- * \brief Free config dependent SBR memory.
+- * \param self SBR decoder instance handle
+- */
+-SBR_ERROR sbrDecoder_FreeMem(HANDLE_SBRDECODER *self) {
+- int i;
+- int elIdx;
+-
+- if (self != NULL && *self != NULL) {
+- for (i = 0; i < (8); i++) {
+- sbrDecoder_DestroyElement(*self, i);
+- }
+-
+- for (elIdx = 0; elIdx < (8); elIdx += 1) {
+- for (i = 0; i < (1) + 1; i += 1) {
+- (*self)->sbrHeader[elIdx][i].syncState = SBR_NOT_INITIALIZED;
+- }
+- }
+- }
+-
+- return SBRDEC_OK;
+-}
+-
+-/**
+- * \brief Apply decoded SBR header for one element.
+- * \param self SBR decoder instance handle
+- * \param hSbrHeader SBR header handle to be processed.
+- * \param hSbrChannel pointer array to the SBR element channels corresponding to
+- * the SBR header.
+- * \param headerStatus header status value returned from SBR header parser.
+- * \param numElementChannels amount of channels for the SBR element whos header
+- * is to be processed.
+- */
+-static SBR_ERROR sbrDecoder_HeaderUpdate(HANDLE_SBRDECODER self,
+- HANDLE_SBR_HEADER_DATA hSbrHeader,
+- SBR_HEADER_STATUS headerStatus,
+- HANDLE_SBR_CHANNEL hSbrChannel[],
+- const int numElementChannels) {
+- SBR_ERROR errorStatus = SBRDEC_OK;
+-
+- /*
+- change of control data, reset decoder
+- */
+- errorStatus = resetFreqBandTables(hSbrHeader, self->flags);
+-
+- if (errorStatus == SBRDEC_OK) {
+- if (hSbrHeader->syncState == UPSAMPLING && headerStatus != HEADER_RESET) {
+-#if (SBRDEC_MAX_HB_FADE_FRAMES > 0)
+- int ch;
+- for (ch = 0; ch < numElementChannels; ch += 1) {
+- hSbrChannel[ch]->SbrDec.highBandFadeCnt = SBRDEC_MAX_HB_FADE_FRAMES;
+- }
+-
+-#endif
+- /* As the default header would limit the frequency range,
+- lowSubband and highSubband must be patched. */
+- hSbrHeader->freqBandData.lowSubband = hSbrHeader->numberOfAnalysisBands;
+- hSbrHeader->freqBandData.highSubband = hSbrHeader->numberOfAnalysisBands;
+- }
+-
+- /* Trigger a reset before processing this slot */
+- hSbrHeader->status |= SBRDEC_HDR_STAT_RESET;
+- }
+-
+- return errorStatus;
+-}
+-
+-INT sbrDecoder_Header(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
+- const INT sampleRateIn, const INT sampleRateOut,
+- const INT samplesPerFrame,
+- const AUDIO_OBJECT_TYPE coreCodec,
+- const MP4_ELEMENT_ID elementID, const INT elementIndex,
+- const UCHAR harmonicSBR, const UCHAR stereoConfigIndex,
+- const UCHAR configMode, UCHAR *configChanged,
+- const INT downscaleFactor) {
+- SBR_HEADER_STATUS headerStatus;
+- HANDLE_SBR_HEADER_DATA hSbrHeader;
+- SBR_ERROR sbrError = SBRDEC_OK;
+- int headerIndex;
+- UINT flagsSaved =
+- 0; /* flags should not be changed in AC_CM_DET_CFG_CHANGE - mode after
+- parsing */
+-
+- if (self == NULL || elementIndex >= (8)) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- if (!sbrDecoder_isCoreCodecValid(coreCodec)) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- if (configMode & AC_CM_DET_CFG_CHANGE) {
+- flagsSaved = self->flags; /* store */
+- }
+-
+- sbrError = sbrDecoder_InitElement(
+- self, sampleRateIn, sampleRateOut, samplesPerFrame, coreCodec, elementID,
+- elementIndex, harmonicSBR, stereoConfigIndex, configMode, configChanged,
+- downscaleFactor);
+-
+- if ((sbrError != SBRDEC_OK) || (elementID == ID_LFE)) {
+- goto bail;
+- }
+-
+- if (configMode & AC_CM_DET_CFG_CHANGE) {
+- hSbrHeader = NULL;
+- } else {
+- headerIndex = getHeaderSlot(self->pSbrElement[elementIndex]->useFrameSlot,
+- self->pSbrElement[elementIndex]->useHeaderSlot);
+-
+- hSbrHeader = &(self->sbrHeader[elementIndex][headerIndex]);
+- }
+-
+- headerStatus = sbrGetHeaderData(hSbrHeader, hBs, self->flags, 0, configMode);
+-
+- if (coreCodec == AOT_USAC) {
+- if (configMode & AC_CM_DET_CFG_CHANGE) {
+- self->flags = flagsSaved; /* restore */
+- }
+- return sbrError;
+- }
+-
+- if (configMode & AC_CM_ALLOC_MEM) {
+- SBR_DECODER_ELEMENT *pSbrElement;
+-
+- pSbrElement = self->pSbrElement[elementIndex];
+-
+- /* Sanity check */
+- if (pSbrElement != NULL) {
+- if ((elementID == ID_CPE && pSbrElement->nChannels != 2) ||
+- (elementID != ID_CPE && pSbrElement->nChannels != 1)) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+- if (headerStatus == HEADER_RESET) {
+- sbrError = sbrDecoder_HeaderUpdate(self, hSbrHeader, headerStatus,
+- pSbrElement->pSbrChannel,
+- pSbrElement->nChannels);
+-
+- if (sbrError == SBRDEC_OK) {
+- hSbrHeader->syncState = SBR_HEADER;
+- hSbrHeader->status |= SBRDEC_HDR_STAT_UPDATE;
+- }
+- /* else {
+- Since we already have overwritten the old SBR header the only way out
+- is UPSAMPLING! This will be prepared in the next step.
+- } */
+- }
+- }
+- }
+-bail:
+- if (configMode & AC_CM_DET_CFG_CHANGE) {
+- self->flags = flagsSaved; /* restore */
+- }
+- return sbrError;
+-}
+-
+-SBR_ERROR sbrDecoder_SetParam(HANDLE_SBRDECODER self, const SBRDEC_PARAM param,
+- const INT value) {
+- SBR_ERROR errorStatus = SBRDEC_OK;
+-
+- /* configure the subsystems */
+- switch (param) {
+- case SBR_SYSTEM_BITSTREAM_DELAY:
+- if (value < 0 || value > (1)) {
+- errorStatus = SBRDEC_SET_PARAM_FAIL;
+- break;
+- }
+- if (self == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- } else {
+- self->numDelayFrames = (UCHAR)value;
+- }
+- break;
+- case SBR_QMF_MODE:
+- if (self == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- } else {
+- if (value == 1) {
+- self->flags |= SBRDEC_LOW_POWER;
+- } else {
+- self->flags &= ~SBRDEC_LOW_POWER;
+- }
+- }
+- break;
+- case SBR_LD_QMF_TIME_ALIGN:
+- if (self == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- } else {
+- if (value == 1) {
+- self->flags |= SBRDEC_LD_MPS_QMF;
+- } else {
+- self->flags &= ~SBRDEC_LD_MPS_QMF;
+- }
+- }
+- break;
+- case SBR_FLUSH_DATA:
+- if (value != 0) {
+- if (self == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- } else {
+- self->flags |= SBRDEC_FLUSH;
+- }
+- }
+- break;
+- case SBR_CLEAR_HISTORY:
+- if (value != 0) {
+- if (self == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- } else {
+- self->flags |= SBRDEC_FORCE_RESET;
+- }
+- }
+- break;
+- case SBR_BS_INTERRUPTION: {
+- int elementIndex;
+-
+- if (self == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- break;
+- }
+-
+- /* Loop over SBR elements */
+- for (elementIndex = 0; elementIndex < self->numSbrElements;
+- elementIndex++) {
+- if (self->pSbrElement[elementIndex] != NULL) {
+- HANDLE_SBR_HEADER_DATA hSbrHeader;
+- int headerIndex =
+- getHeaderSlot(self->pSbrElement[elementIndex]->useFrameSlot,
+- self->pSbrElement[elementIndex]->useHeaderSlot);
+-
+- hSbrHeader = &(self->sbrHeader[elementIndex][headerIndex]);
+-
+- /* Set sync state UPSAMPLING for the corresponding slot.
+- This switches off bitstream parsing until a new header arrives. */
+- hSbrHeader->syncState = UPSAMPLING;
+- hSbrHeader->status |= SBRDEC_HDR_STAT_UPDATE;
+- }
+- }
+- } break;
+-
+- case SBR_SKIP_QMF:
+- if (self == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- } else {
+- if (value == 1) {
+- self->flags |= SBRDEC_SKIP_QMF_ANA;
+- } else {
+- self->flags &= ~SBRDEC_SKIP_QMF_ANA;
+- }
+- if (value == 2) {
+- self->flags |= SBRDEC_SKIP_QMF_SYN;
+- } else {
+- self->flags &= ~SBRDEC_SKIP_QMF_SYN;
+- }
+- }
+- break;
+- default:
+- errorStatus = SBRDEC_SET_PARAM_FAIL;
+- break;
+- } /* switch(param) */
+-
+- return (errorStatus);
+-}
+-
+-static SBRDEC_DRC_CHANNEL *sbrDecoder_drcGetChannel(
+- const HANDLE_SBRDECODER self, const INT channel) {
+- SBRDEC_DRC_CHANNEL *pSbrDrcChannelData = NULL;
+- int elementIndex, elChanIdx = 0, numCh = 0;
+-
+- for (elementIndex = 0; (elementIndex < (8)) && (numCh <= channel);
+- elementIndex++) {
+- SBR_DECODER_ELEMENT *pSbrElement = self->pSbrElement[elementIndex];
+- int c, elChannels;
+-
+- elChanIdx = 0;
+- if (pSbrElement == NULL) break;
+-
+- /* Determine amount of channels for this element */
+- switch (pSbrElement->elementID) {
+- case ID_CPE:
+- elChannels = 2;
+- break;
+- case ID_LFE:
+- case ID_SCE:
+- elChannels = 1;
+- break;
+- case ID_NONE:
+- default:
+- elChannels = 0;
+- break;
+- }
+-
+- /* Limit with actual allocated element channels */
+- elChannels = fMin(elChannels, pSbrElement->nChannels);
+-
+- for (c = 0; (c < elChannels) && (numCh <= channel); c++) {
+- if (pSbrElement->pSbrChannel[elChanIdx] != NULL) {
+- numCh++;
+- elChanIdx++;
+- }
+- }
+- }
+- elementIndex -= 1;
+- elChanIdx -= 1;
+-
+- if (elChanIdx < 0 || elementIndex < 0) {
+- return NULL;
+- }
+-
+- if (self->pSbrElement[elementIndex] != NULL) {
+- if (self->pSbrElement[elementIndex]->pSbrChannel[elChanIdx] != NULL) {
+- pSbrDrcChannelData = &self->pSbrElement[elementIndex]
+- ->pSbrChannel[elChanIdx]
+- ->SbrDec.sbrDrcChannel;
+- }
+- }
+-
+- return (pSbrDrcChannelData);
+-}
+-
+-SBR_ERROR sbrDecoder_drcFeedChannel(HANDLE_SBRDECODER self, INT ch,
+- UINT numBands, FIXP_DBL *pNextFact_mag,
+- INT nextFact_exp,
+- SHORT drcInterpolationScheme,
+- UCHAR winSequence, USHORT *pBandTop) {
+- SBRDEC_DRC_CHANNEL *pSbrDrcChannelData = NULL;
+- int band, isValidData = 0;
+-
+- if (self == NULL) {
+- return SBRDEC_NOT_INITIALIZED;
+- }
+- if (ch > (8) || pNextFact_mag == NULL) {
+- return SBRDEC_SET_PARAM_FAIL;
+- }
+-
+- /* Search for gain values different to 1.0f */
+- for (band = 0; band < (int)numBands; band += 1) {
+- if (!((pNextFact_mag[band] == FL2FXCONST_DBL(0.5)) &&
+- (nextFact_exp == 1)) &&
+- !((pNextFact_mag[band] == (FIXP_DBL)MAXVAL_DBL) &&
+- (nextFact_exp == 0))) {
+- isValidData = 1;
+- break;
+- }
+- }
+-
+- /* Find the right SBR channel */
+- pSbrDrcChannelData = sbrDecoder_drcGetChannel(self, ch);
+-
+- if (pSbrDrcChannelData != NULL) {
+- if (pSbrDrcChannelData->enable ||
+- isValidData) { /* Activate processing only with real and valid data */
+- int i;
+-
+- pSbrDrcChannelData->enable = 1;
+- pSbrDrcChannelData->numBandsNext = numBands;
+-
+- pSbrDrcChannelData->winSequenceNext = winSequence;
+- pSbrDrcChannelData->drcInterpolationSchemeNext = drcInterpolationScheme;
+- pSbrDrcChannelData->nextFact_exp = nextFact_exp;
+-
+- for (i = 0; i < (int)numBands; i++) {
+- pSbrDrcChannelData->bandTopNext[i] = pBandTop[i];
+- pSbrDrcChannelData->nextFact_mag[i] = pNextFact_mag[i];
+- }
+- }
+- }
+-
+- return SBRDEC_OK;
+-}
+-
+-void sbrDecoder_drcDisable(HANDLE_SBRDECODER self, INT ch) {
+- SBRDEC_DRC_CHANNEL *pSbrDrcChannelData = NULL;
+-
+- if ((self == NULL) || (ch > (8)) || (self->numSbrElements == 0) ||
+- (self->numSbrChannels == 0)) {
+- return;
+- }
+-
+- /* Find the right SBR channel */
+- pSbrDrcChannelData = sbrDecoder_drcGetChannel(self, ch);
+-
+- if (pSbrDrcChannelData != NULL) {
+- sbrDecoder_drcInitChannel(pSbrDrcChannelData);
+- }
+-}
+-
+-SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
+- UCHAR *pDrmBsBuffer, USHORT drmBsBufferSize,
+- int *count, int bsPayLen, int crcFlag,
+- MP4_ELEMENT_ID prevElement, int elementIndex,
+- UINT acFlags, UINT acElFlags[]) {
+- SBR_DECODER_ELEMENT *hSbrElement = NULL;
+- HANDLE_SBR_HEADER_DATA hSbrHeader = NULL;
+- HANDLE_SBR_CHANNEL *pSbrChannel;
+-
+- SBR_FRAME_DATA *hFrameDataLeft = NULL;
+- SBR_FRAME_DATA *hFrameDataRight = NULL;
+- SBR_FRAME_DATA frameDataLeftCopy;
+- SBR_FRAME_DATA frameDataRightCopy;
+-
+- SBR_ERROR errorStatus = SBRDEC_OK;
+- SBR_HEADER_STATUS headerStatus = HEADER_NOT_PRESENT;
+-
+- INT startPos = FDKgetValidBits(hBs);
+- INT CRCLen = 0;
+- HANDLE_FDK_BITSTREAM hBsOriginal = hBs;
+- FDK_BITSTREAM bsBwd;
+-
+- FDK_CRCINFO crcInfo;
+- INT crcReg = 0;
+- USHORT drmSbrCrc = 0;
+- const int fGlobalIndependencyFlag = acFlags & AC_INDEP;
+- const int bs_pvc = acElFlags[elementIndex] & AC_EL_USAC_PVC;
+- const int bs_interTes = acElFlags[elementIndex] & AC_EL_USAC_ITES;
+- int stereo;
+- int fDoDecodeSbrData = 1;
+-
+- int lastSlot, lastHdrSlot = 0, thisHdrSlot = 0;
+-
+- if (*count <= 0) {
+- setFrameErrorFlag(self->pSbrElement[elementIndex], FRAME_ERROR);
+- return SBRDEC_OK;
+- }
+-
+- /* SBR sanity checks */
+- if (self == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- goto bail;
+- }
+-
+- /* Reverse bits of DRM SBR payload */
+- if ((self->flags & SBRDEC_SYNTAX_DRM) && *count > 0) {
+- int dataBytes, dataBits;
+-
+- FDK_ASSERT(drmBsBufferSize >= (512));
+- dataBits = *count;
+-
+- if (dataBits > ((512) * 8)) {
+- /* do not flip more data than needed */
+- dataBits = (512) * 8;
+- }
+-
+- dataBytes = (dataBits + 7) >> 3;
+-
+- int j;
+-
+- if ((j = (int)FDKgetValidBits(hBs)) != 8) {
+- FDKpushBiDirectional(hBs, (j - 8));
+- }
+-
+- j = 0;
+- for (; dataBytes > 0; dataBytes--) {
+- int i;
+- UCHAR tmpByte;
+- UCHAR buffer = 0x00;
+-
+- tmpByte = (UCHAR)FDKreadBits(hBs, 8);
+- for (i = 0; i < 4; i++) {
+- int shift = 2 * i + 1;
+- buffer |= (tmpByte & (0x08 >> i)) << shift;
+- buffer |= (tmpByte & (0x10 << i)) >> shift;
+- }
+- pDrmBsBuffer[j++] = buffer;
+- FDKpushBack(hBs, 16);
+- }
+-
+- FDKinitBitStream(&bsBwd, pDrmBsBuffer, (512), dataBits, BS_READER);
+-
+- /* Use reversed data */
+- hBs = &bsBwd;
+- bsPayLen = *count;
+- }
+-
+- /* Remember start position of SBR element */
+- startPos = FDKgetValidBits(hBs);
+-
+- /* SBR sanity checks */
+- if (self->pSbrElement[elementIndex] == NULL) {
+- errorStatus = SBRDEC_NOT_INITIALIZED;
+- goto bail;
+- }
+- hSbrElement = self->pSbrElement[elementIndex];
+-
+- lastSlot = (hSbrElement->useFrameSlot > 0) ? hSbrElement->useFrameSlot - 1
+- : self->numDelayFrames;
+- lastHdrSlot = hSbrElement->useHeaderSlot[lastSlot];
+- thisHdrSlot = getHeaderSlot(
+- hSbrElement->useFrameSlot,
+- hSbrElement->useHeaderSlot); /* Get a free header slot not used by
+- frames not processed yet. */
+-
+- /* Assign the free slot to store a new header if there is one. */
+- hSbrHeader = &self->sbrHeader[elementIndex][thisHdrSlot];
+-
+- pSbrChannel = hSbrElement->pSbrChannel;
+- stereo = (hSbrElement->elementID == ID_CPE) ? 1 : 0;
+-
+- hFrameDataLeft = &self->pSbrElement[elementIndex]
+- ->pSbrChannel[0]
+- ->frameData[hSbrElement->useFrameSlot];
+- if (stereo) {
+- hFrameDataRight = &self->pSbrElement[elementIndex]
+- ->pSbrChannel[1]
+- ->frameData[hSbrElement->useFrameSlot];
+- }
+-
+- /* store frameData; new parsed frameData possibly corrupted */
+- FDKmemcpy(&frameDataLeftCopy, hFrameDataLeft, sizeof(SBR_FRAME_DATA));
+- if (stereo) {
+- FDKmemcpy(&frameDataRightCopy, hFrameDataRight, sizeof(SBR_FRAME_DATA));
+- }
+-
+- /* reset PS flag; will be set after PS was found */
+- self->flags &= ~SBRDEC_PS_DECODED;
+-
+- if (hSbrHeader->status & SBRDEC_HDR_STAT_UPDATE) {
+- /* Got a new header from extern (e.g. from an ASC) */
+- headerStatus = HEADER_OK;
+- hSbrHeader->status &= ~SBRDEC_HDR_STAT_UPDATE;
+- } else if (thisHdrSlot != lastHdrSlot) {
+- /* Copy the last header into this slot otherwise the
+- header compare will trigger more HEADER_RESETs than needed. */
+- copySbrHeader(hSbrHeader, &self->sbrHeader[elementIndex][lastHdrSlot]);
+- }
+-
+- /*
+- Check if bit stream data is valid and matches the element context
+- */
+- if (((prevElement != ID_SCE) && (prevElement != ID_CPE)) ||
+- prevElement != hSbrElement->elementID) {
+- /* In case of LFE we also land here, since there is no LFE SBR element (do
+- * upsampling only) */
+- fDoDecodeSbrData = 0;
+- }
+-
+- if (fDoDecodeSbrData) {
+- if ((INT)FDKgetValidBits(hBs) <= 0) {
+- fDoDecodeSbrData = 0;
+- }
+- }
+-
+- /*
+- SBR CRC-check
+- */
+- if (fDoDecodeSbrData) {
+- if (crcFlag) {
+- switch (self->coreCodec) {
+- case AOT_ER_AAC_ELD:
+- FDKpushFor(hBs, 10);
+- /* check sbrcrc later: we don't know the payload length now */
+- break;
+- case AOT_DRM_AAC:
+- case AOT_DRM_SURROUND:
+- drmSbrCrc = (USHORT)FDKreadBits(hBs, 8);
+- /* Setup CRC decoder */
+- FDKcrcInit(&crcInfo, 0x001d, 0xFFFF, 8);
+- /* Start CRC region */
+- crcReg = FDKcrcStartReg(&crcInfo, hBs, 0);
+- break;
+- default:
+- CRCLen = bsPayLen - 10; /* change: 0 => i */
+- if (CRCLen < 0) {
+- fDoDecodeSbrData = 0;
+- } else {
+- fDoDecodeSbrData = SbrCrcCheck(hBs, CRCLen);
+- }
+- break;
+- }
+- }
+- } /* if (fDoDecodeSbrData) */
+-
+- /*
+- Read in the header data and issue a reset if change occured
+- */
+- if (fDoDecodeSbrData) {
+- int sbrHeaderPresent;
+-
+- if (self->flags & (SBRDEC_SYNTAX_RSVD50 | SBRDEC_SYNTAX_USAC)) {
+- SBR_HEADER_DATA_BS_INFO newSbrInfo;
+- int sbrInfoPresent;
+-
+- if (bs_interTes) {
+- self->flags |= SBRDEC_USAC_ITES;
+- } else {
+- self->flags &= ~SBRDEC_USAC_ITES;
+- }
+-
+- if (fGlobalIndependencyFlag) {
+- self->flags |= SBRDEC_USAC_INDEP;
+- sbrInfoPresent = 1;
+- sbrHeaderPresent = 1;
+- } else {
+- self->flags &= ~SBRDEC_USAC_INDEP;
+- sbrInfoPresent = FDKreadBit(hBs);
+- if (sbrInfoPresent) {
+- sbrHeaderPresent = FDKreadBit(hBs);
+- } else {
+- sbrHeaderPresent = 0;
+- }
+- }
+-
+- if (sbrInfoPresent) {
+- newSbrInfo.ampResolution = FDKreadBit(hBs);
+- newSbrInfo.xover_band = FDKreadBits(hBs, 4);
+- newSbrInfo.sbr_preprocessing = FDKreadBit(hBs);
+- if (bs_pvc) {
+- newSbrInfo.pvc_mode = FDKreadBits(hBs, 2);
+- /* bs_pvc_mode: 0 -> no PVC, 1 -> PVC mode 1, 2 -> PVC mode 2, 3 ->
+- * reserved */
+- if (newSbrInfo.pvc_mode > 2) {
+- headerStatus = HEADER_ERROR;
+- }
+- if (stereo && newSbrInfo.pvc_mode > 0) {
+- /* bs_pvc is always transmitted but pvc_mode is set to zero in case
+- * of stereo SBR. The config might be wrong but we cannot tell for
+- * sure. */
+- newSbrInfo.pvc_mode = 0;
+- }
+- } else {
+- newSbrInfo.pvc_mode = 0;
+- }
+- if (headerStatus != HEADER_ERROR) {
+- if (FDKmemcmp(&hSbrHeader->bs_info, &newSbrInfo,
+- sizeof(SBR_HEADER_DATA_BS_INFO))) {
+- /* in case of ampResolution and preprocessing change no full reset
+- * required */
+- /* HEADER reset would trigger HBE transposer reset which breaks
+- * eSbr_3_Eaa.mp4 */
+- if ((hSbrHeader->bs_info.pvc_mode != newSbrInfo.pvc_mode) ||
+- (hSbrHeader->bs_info.xover_band != newSbrInfo.xover_band)) {
+- headerStatus = HEADER_RESET;
+- } else {
+- headerStatus = HEADER_OK;
+- }
+-
+- hSbrHeader->bs_info = newSbrInfo;
+- } else {
+- headerStatus = HEADER_OK;
+- }
+- }
+- }
+- if (headerStatus == HEADER_ERROR) {
+- /* Corrupt SBR info data, do not decode and switch to UPSAMPLING */
+- hSbrHeader->syncState = UPSAMPLING;
+- fDoDecodeSbrData = 0;
+- sbrHeaderPresent = 0;
+- }
+-
+- if (sbrHeaderPresent && fDoDecodeSbrData) {
+- int useDfltHeader;
+-
+- useDfltHeader = FDKreadBit(hBs);
+-
+- if (useDfltHeader) {
+- sbrHeaderPresent = 0;
+- if (FDKmemcmp(&hSbrHeader->bs_data, &hSbrHeader->bs_dflt,
+- sizeof(SBR_HEADER_DATA_BS)) ||
+- hSbrHeader->syncState != SBR_ACTIVE) {
+- hSbrHeader->bs_data = hSbrHeader->bs_dflt;
+- headerStatus = HEADER_RESET;
+- }
+- }
+- }
+- } else {
+- sbrHeaderPresent = FDKreadBit(hBs);
+- }
+-
+- if (sbrHeaderPresent) {
+- headerStatus = sbrGetHeaderData(hSbrHeader, hBs, self->flags, 1, 0);
+- }
+-
+- if (headerStatus == HEADER_RESET) {
+- errorStatus = sbrDecoder_HeaderUpdate(
+- self, hSbrHeader, headerStatus, pSbrChannel, hSbrElement->nChannels);
+-
+- if (errorStatus == SBRDEC_OK) {
+- hSbrHeader->syncState = SBR_HEADER;
+- } else {
+- hSbrHeader->syncState = SBR_NOT_INITIALIZED;
+- headerStatus = HEADER_ERROR;
+- }
+- }
+-
+- if (errorStatus != SBRDEC_OK) {
+- fDoDecodeSbrData = 0;
+- }
+- } /* if (fDoDecodeSbrData) */
+-
+- /*
+- Print debugging output only if state has changed
+- */
+-
+- /* read frame data */
+- if ((hSbrHeader->syncState >= SBR_HEADER) && fDoDecodeSbrData) {
+- int sbrFrameOk;
+- /* read the SBR element data */
+- if (!stereo && (self->hParametricStereoDec != NULL)) {
+- /* update slot index for PS bitstream parsing */
+- self->hParametricStereoDec->bsLastSlot =
+- self->hParametricStereoDec->bsReadSlot;
+- self->hParametricStereoDec->bsReadSlot = hSbrElement->useFrameSlot;
+- }
+- sbrFrameOk = sbrGetChannelElement(
+- hSbrHeader, hFrameDataLeft, (stereo) ? hFrameDataRight : NULL,
+- &pSbrChannel[0]->prevFrameData,
+- pSbrChannel[0]->SbrDec.PvcStaticData.pvc_mode_last, hBs,
+- (stereo) ? NULL : self->hParametricStereoDec, self->flags,
+- self->pSbrElement[elementIndex]->transposerSettings.overlap);
+-
+- if (!sbrFrameOk) {
+- fDoDecodeSbrData = 0;
+- } else {
+- INT valBits;
+-
+- if (bsPayLen > 0) {
+- valBits = bsPayLen - ((INT)startPos - (INT)FDKgetValidBits(hBs));
+- } else {
+- valBits = (INT)FDKgetValidBits(hBs);
+- }
+-
+- if (crcFlag) {
+- switch (self->coreCodec) {
+- case AOT_ER_AAC_ELD: {
+- /* late crc check for eld */
+- INT payloadbits =
+- (INT)startPos - (INT)FDKgetValidBits(hBs) - startPos;
+- INT crcLen = payloadbits - 10;
+- FDKpushBack(hBs, payloadbits);
+- fDoDecodeSbrData = SbrCrcCheck(hBs, crcLen);
+- FDKpushFor(hBs, crcLen);
+- } break;
+- case AOT_DRM_AAC:
+- case AOT_DRM_SURROUND:
+- /* End CRC region */
+- FDKcrcEndReg(&crcInfo, hBs, crcReg);
+- /* Check CRC */
+- if ((FDKcrcGetCRC(&crcInfo) ^ 0xFF) != drmSbrCrc) {
+- fDoDecodeSbrData = 0;
+- if (headerStatus != HEADER_NOT_PRESENT) {
+- headerStatus = HEADER_ERROR;
+- hSbrHeader->syncState = SBR_NOT_INITIALIZED;
+- }
+- }
+- break;
+- default:
+- break;
+- }
+- }
+-
+- /* sanity check of remaining bits */
+- if (valBits < 0) {
+- fDoDecodeSbrData = 0;
+- } else {
+- switch (self->coreCodec) {
+- case AOT_SBR:
+- case AOT_PS:
+- case AOT_AAC_LC: {
+- /* This sanity check is only meaningful with General Audio
+- * bitstreams */
+- int alignBits = valBits & 0x7;
+-
+- if (valBits > alignBits) {
+- fDoDecodeSbrData = 0;
+- }
+- } break;
+- default:
+- /* No sanity check available */
+- break;
+- }
+- }
+- }
+- } else {
+- /* The returned bit count will not be the actual payload size since we did
+- not parse the frame data. Return an error so that the caller can react
+- respectively. */
+- errorStatus = SBRDEC_PARSE_ERROR;
+- }
+-
+- if (!fDoDecodeSbrData) {
+- /* Set error flag for this slot to trigger concealment */
+- setFrameErrorFlag(self->pSbrElement[elementIndex], FRAME_ERROR);
+- /* restore old frameData for concealment */
+- FDKmemcpy(hFrameDataLeft, &frameDataLeftCopy, sizeof(SBR_FRAME_DATA));
+- if (stereo) {
+- FDKmemcpy(hFrameDataRight, &frameDataRightCopy, sizeof(SBR_FRAME_DATA));
+- }
+- errorStatus = SBRDEC_PARSE_ERROR;
+- } else {
+- /* Everything seems to be ok so clear the error flag */
+- setFrameErrorFlag(self->pSbrElement[elementIndex], FRAME_OK);
+- }
+-
+- if (!stereo) {
+- /* Turn coupling off explicitely to avoid access to absent right frame data
+- that might occur with corrupt bitstreams. */
+- hFrameDataLeft->coupling = COUPLING_OFF;
+- }
+-
+-bail:
+-
+- if (self != NULL) {
+- if (self->flags & SBRDEC_SYNTAX_DRM) {
+- hBs = hBsOriginal;
+- }
+-
+- if (errorStatus != SBRDEC_NOT_INITIALIZED) {
+- int useOldHdr =
+- ((headerStatus == HEADER_NOT_PRESENT) ||
+- (headerStatus == HEADER_ERROR) ||
+- (headerStatus == HEADER_RESET && errorStatus == SBRDEC_PARSE_ERROR))
+- ? 1
+- : 0;
+-
+- if (!useOldHdr && (thisHdrSlot != lastHdrSlot) && (hSbrHeader != NULL)) {
+- useOldHdr |=
+- (compareSbrHeader(hSbrHeader,
+- &self->sbrHeader[elementIndex][lastHdrSlot]) == 0)
+- ? 1
+- : 0;
+- }
+-
+- if (hSbrElement != NULL) {
+- if (useOldHdr != 0) {
+- /* Use the old header for this frame */
+- hSbrElement->useHeaderSlot[hSbrElement->useFrameSlot] = lastHdrSlot;
+- } else {
+- /* Use the new header for this frame */
+- hSbrElement->useHeaderSlot[hSbrElement->useFrameSlot] = thisHdrSlot;
+- }
+-
+- /* Move frame pointer to the next slot which is up to be decoded/applied
+- * next */
+- hSbrElement->useFrameSlot =
+- (hSbrElement->useFrameSlot + 1) % (self->numDelayFrames + 1);
+- }
+- }
+- }
+-
+- *count -= startPos - (INT)FDKgetValidBits(hBs);
+-
+- return errorStatus;
+-}
+-
+-/**
+- * \brief Render one SBR element into time domain signal.
+- * \param self SBR decoder handle
+- * \param timeData pointer to output buffer
+- * \param channelMapping pointer to UCHAR array where next 2 channel offsets are
+- * stored.
+- * \param elementIndex enumerating index of the SBR element to render.
+- * \param numInChannels number of channels from core coder.
+- * \param numOutChannels pointer to a location to return number of output
+- * channels.
+- * \param psPossible flag indicating if PS is possible or not.
+- * \return SBRDEC_OK if successfull, else error code
+- */
+-static SBR_ERROR sbrDecoder_DecodeElement(
+- HANDLE_SBRDECODER self, QDOM_PCM *input, INT_PCM *timeData,
+- const int timeDataSize, const FDK_channelMapDescr *const mapDescr,
+- const int mapIdx, int channelIndex, const int elementIndex,
+- const int numInChannels, int *numOutChannels, const int psPossible) {
+- SBR_DECODER_ELEMENT *hSbrElement = self->pSbrElement[elementIndex];
+- HANDLE_SBR_CHANNEL *pSbrChannel =
+- self->pSbrElement[elementIndex]->pSbrChannel;
+- HANDLE_SBR_HEADER_DATA hSbrHeader =
+- &self->sbrHeader[elementIndex]
+- [hSbrElement->useHeaderSlot[hSbrElement->useFrameSlot]];
+- HANDLE_PS_DEC h_ps_d = self->hParametricStereoDec;
+-
+- /* get memory for frame data from scratch */
+- SBR_FRAME_DATA *hFrameDataLeft = NULL;
+- SBR_FRAME_DATA *hFrameDataRight = NULL;
+-
+- SBR_ERROR errorStatus = SBRDEC_OK;
+-
+- INT strideOut, offset0 = 255, offset0_block = 0, offset1 = 255,
+- offset1_block = 0;
+- INT codecFrameSize = self->codecFrameSize;
+-
+- int stereo = (hSbrElement->elementID == ID_CPE) ? 1 : 0;
+- int numElementChannels =
+- hSbrElement
+- ->nChannels; /* Number of channels of the current SBR element */
+-
+- hFrameDataLeft =
+- &hSbrElement->pSbrChannel[0]->frameData[hSbrElement->useFrameSlot];
+- if (stereo) {
+- hFrameDataRight =
+- &hSbrElement->pSbrChannel[1]->frameData[hSbrElement->useFrameSlot];
+- }
+-
+- if (self->flags & SBRDEC_FLUSH) {
+- if (self->numFlushedFrames > self->numDelayFrames) {
+- int hdrIdx;
+- /* No valid SBR payload available, hence switch to upsampling (in all
+- * headers) */
+- for (hdrIdx = 0; hdrIdx < ((1) + 1); hdrIdx += 1) {
+- self->sbrHeader[elementIndex][hdrIdx].syncState = UPSAMPLING;
+- }
+- } else {
+- /* Move frame pointer to the next slot which is up to be decoded/applied
+- * next */
+- hSbrElement->useFrameSlot =
+- (hSbrElement->useFrameSlot + 1) % (self->numDelayFrames + 1);
+- /* Update header and frame data pointer because they have already been set
+- */
+- hSbrHeader =
+- &self->sbrHeader[elementIndex]
+- [hSbrElement
+- ->useHeaderSlot[hSbrElement->useFrameSlot]];
+- hFrameDataLeft =
+- &hSbrElement->pSbrChannel[0]->frameData[hSbrElement->useFrameSlot];
+- if (stereo) {
+- hFrameDataRight =
+- &hSbrElement->pSbrChannel[1]->frameData[hSbrElement->useFrameSlot];
+- }
+- }
+- }
+-
+- /* Update the header error flag */
+- hSbrHeader->frameErrorFlag =
+- hSbrElement->frameErrorFlag[hSbrElement->useFrameSlot];
+-
+- /*
+- Prepare filterbank for upsampling if no valid bit stream data is available.
+- */
+- if (hSbrHeader->syncState == SBR_NOT_INITIALIZED) {
+- errorStatus =
+- initHeaderData(hSbrHeader, self->sampleRateIn, self->sampleRateOut,
+- self->downscaleFactor, codecFrameSize, self->flags,
+- 1 /* SET_DEFAULT_HDR */
+- );
+-
+- if (errorStatus != SBRDEC_OK) {
+- return errorStatus;
+- }
+-
+- hSbrHeader->syncState = UPSAMPLING;
+-
+- errorStatus = sbrDecoder_HeaderUpdate(self, hSbrHeader, HEADER_NOT_PRESENT,
+- pSbrChannel, hSbrElement->nChannels);
+-
+- if (errorStatus != SBRDEC_OK) {
+- hSbrHeader->syncState = SBR_NOT_INITIALIZED;
+- return errorStatus;
+- }
+- }
+-
+- /* reset */
+- if (hSbrHeader->status & SBRDEC_HDR_STAT_RESET) {
+- int ch;
+- int applySbrProc = (hSbrHeader->syncState == SBR_ACTIVE ||
+- (hSbrHeader->frameErrorFlag == 0 &&
+- hSbrHeader->syncState == SBR_HEADER));
+- for (ch = 0; ch < numElementChannels; ch++) {
+- SBR_ERROR errorStatusTmp = SBRDEC_OK;
+-
+- errorStatusTmp = resetSbrDec(
+- &pSbrChannel[ch]->SbrDec, hSbrHeader, &pSbrChannel[ch]->prevFrameData,
+- self->synDownsampleFac, self->flags, pSbrChannel[ch]->frameData);
+-
+- if (errorStatusTmp != SBRDEC_OK) {
+- hSbrHeader->syncState = UPSAMPLING;
+- }
+- }
+- if (applySbrProc) {
+- hSbrHeader->status &= ~SBRDEC_HDR_STAT_RESET;
+- }
+- }
+-
+- /* decoding */
+- if ((hSbrHeader->syncState == SBR_ACTIVE) ||
+- ((hSbrHeader->syncState == SBR_HEADER) &&
+- (hSbrHeader->frameErrorFlag == 0))) {
+- errorStatus = SBRDEC_OK;
+-
+- decodeSbrData(hSbrHeader, hFrameDataLeft, &pSbrChannel[0]->prevFrameData,
+- (stereo) ? hFrameDataRight : NULL,
+- (stereo) ? &pSbrChannel[1]->prevFrameData : NULL);
+-
+- /* Now we have a full parameter set and can do parameter
+- based concealment instead of plain upsampling. */
+- hSbrHeader->syncState = SBR_ACTIVE;
+- }
+-
+- if (timeDataSize <
+- hSbrHeader->numberTimeSlots * hSbrHeader->timeStep *
+- self->pQmfDomain->globalConf.nBandsSynthesis *
+- (psPossible ? fMax(2, numInChannels) : numInChannels)) {
+- return SBRDEC_OUTPUT_BUFFER_TOO_SMALL;
+- }
+-
+- {
+- self->flags &= ~SBRDEC_PS_DECODED;
+- C_ALLOC_SCRATCH_START(pPsScratch, struct PS_DEC_COEFFICIENTS, 1)
+-
+- /* decode PS data if available */
+- if (h_ps_d != NULL && psPossible && (hSbrHeader->syncState == SBR_ACTIVE)) {
+- int applyPs = 1;
+-
+- /* define which frame delay line slot to process */
+- h_ps_d->processSlot = hSbrElement->useFrameSlot;
+-
+- applyPs = DecodePs(h_ps_d, hSbrHeader->frameErrorFlag, pPsScratch);
+- self->flags |= (applyPs) ? SBRDEC_PS_DECODED : 0;
+- }
+-
+- offset0 = FDK_chMapDescr_getMapValue(mapDescr, channelIndex, mapIdx);
+- offset0_block = offset0 * codecFrameSize;
+- if (stereo || psPossible) {
+- /* the value of offset1 only matters if the condition is true, however if
+- it is not true channelIndex+1 may exceed the channel map resutling in an
+- error, though the value of offset1 is actually meaningless. This is
+- prevented here. */
+- offset1 = FDK_chMapDescr_getMapValue(mapDescr, channelIndex + 1, mapIdx);
+- offset1_block = offset1 * codecFrameSize;
+- }
+- /* Set strides for reading and writing */
+- if (psPossible)
+- strideOut = (numInChannels < 2) ? 2 : numInChannels;
+- else
+- strideOut = numInChannels;
+-
+- /* use same buffers for left and right channel and apply PS per timeslot */
+- /* Process left channel */
+- sbr_dec(&pSbrChannel[0]->SbrDec, input + offset0_block, timeData + offset0,
+- (self->flags & SBRDEC_PS_DECODED) ? &pSbrChannel[1]->SbrDec : NULL,
+- timeData + offset1, strideOut, hSbrHeader, hFrameDataLeft,
+- &pSbrChannel[0]->prevFrameData,
+- (hSbrHeader->syncState == SBR_ACTIVE), h_ps_d, self->flags,
+- codecFrameSize);
+-
+- if (stereo) {
+- /* Process right channel */
+- sbr_dec(&pSbrChannel[1]->SbrDec, input + offset1_block,
+- timeData + offset1, NULL, NULL, strideOut, hSbrHeader,
+- hFrameDataRight, &pSbrChannel[1]->prevFrameData,
+- (hSbrHeader->syncState == SBR_ACTIVE), NULL, self->flags,
+- codecFrameSize);
+- }
+-
+- C_ALLOC_SCRATCH_END(pPsScratch, struct PS_DEC_COEFFICIENTS, 1)
+- }
+-
+- if (h_ps_d != NULL) {
+- /* save PS status for next run */
+- h_ps_d->psDecodedPrv = (self->flags & SBRDEC_PS_DECODED) ? 1 : 0;
+- }
+-
+- if (psPossible && !(self->flags & SBRDEC_SKIP_QMF_SYN)) {
+- FDK_ASSERT(strideOut > 1);
+- if (!(self->flags & SBRDEC_PS_DECODED)) {
+- /* A decoder which is able to decode PS has to produce a stereo output
+- * even if no PS data is available. */
+- /* So copy left channel to right channel. */
+- int copyFrameSize =
+- codecFrameSize * self->pQmfDomain->QmfDomainOut->fb.no_channels;
+- copyFrameSize /= self->pQmfDomain->QmfDomainIn->fb.no_channels;
+- INT_PCM *ptr;
+- INT i;
+- FDK_ASSERT(strideOut == 2);
+-
+- ptr = timeData;
+- for (i = copyFrameSize >> 1; i--;) {
+- INT_PCM tmp; /* This temporal variable is required because some
+- compilers can't do *ptr++ = *ptr++ correctly. */
+- tmp = *ptr++;
+- *ptr++ = tmp;
+- tmp = *ptr++;
+- *ptr++ = tmp;
+- }
+- }
+- *numOutChannels = 2; /* Output minimum two channels when PS is enabled. */
+- }
+-
+- return errorStatus;
+-}
+-
+-SBR_ERROR sbrDecoder_Apply(HANDLE_SBRDECODER self, INT_PCM *input,
+- INT_PCM *timeData, const int timeDataSize,
+- int *numChannels, int *sampleRate,
+- const FDK_channelMapDescr *const mapDescr,
+- const int mapIdx, const int coreDecodedOk,
+- UCHAR *psDecoded) {
+- SBR_ERROR errorStatus = SBRDEC_OK;
+-
+- int psPossible;
+- int sbrElementNum;
+- int numCoreChannels;
+- int numSbrChannels = 0;
+-
+- if ((self == NULL) || (timeData == NULL) || (numChannels == NULL) ||
+- (sampleRate == NULL) || (psDecoded == NULL) ||
+- !FDK_chMapDescr_isValid(mapDescr)) {
+- return SBRDEC_INVALID_ARGUMENT;
+- }
+-
+- psPossible = *psDecoded;
+- numCoreChannels = *numChannels;
+- if (numCoreChannels <= 0) {
+- return SBRDEC_INVALID_ARGUMENT;
+- }
+-
+- if (self->numSbrElements < 1) {
+- /* exit immediately to avoid access violations */
+- return SBRDEC_NOT_INITIALIZED;
+- }
+-
+- /* Sanity check of allocated SBR elements. */
+- for (sbrElementNum = 0; sbrElementNum < self->numSbrElements;
+- sbrElementNum++) {
+- if (self->pSbrElement[sbrElementNum] == NULL) {
+- return SBRDEC_NOT_INITIALIZED;
+- }
+- }
+-
+- if (self->numSbrElements != 1 || self->pSbrElement[0]->elementID != ID_SCE) {
+- psPossible = 0;
+- }
+-
+- /* Make sure that even if no SBR data was found/parsed *psDecoded is returned
+- * 1 if psPossible was 0. */
+- if (psPossible == 0) {
+- self->flags &= ~SBRDEC_PS_DECODED;
+- }
+-
+- /* replaces channel based reset inside sbr_dec() */
+- if (((self->flags & SBRDEC_LOW_POWER) ? 1 : 0) !=
+- ((self->pQmfDomain->globalConf.flags & QMF_FLAG_LP) ? 1 : 0)) {
+- if (self->flags & SBRDEC_LOW_POWER) {
+- self->pQmfDomain->globalConf.flags |= QMF_FLAG_LP;
+- self->pQmfDomain->globalConf.flags_requested |= QMF_FLAG_LP;
+- } else {
+- self->pQmfDomain->globalConf.flags &= ~QMF_FLAG_LP;
+- self->pQmfDomain->globalConf.flags_requested &= ~QMF_FLAG_LP;
+- }
+- if (FDK_QmfDomain_InitFilterBank(self->pQmfDomain, QMF_FLAG_KEEP_STATES)) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+- }
+- if (self->numSbrChannels > self->pQmfDomain->globalConf.nInputChannels) {
+- return SBRDEC_UNSUPPORTED_CONFIG;
+- }
+-
+- if (self->flags & SBRDEC_FLUSH) {
+- /* flushing is signalized, hence increment the flush frame counter */
+- self->numFlushedFrames++;
+- } else {
+- /* no flushing is signalized, hence reset the flush frame counter */
+- self->numFlushedFrames = 0;
+- }
+-
+- /* Loop over SBR elements */
+- for (sbrElementNum = 0; sbrElementNum < self->numSbrElements;
+- sbrElementNum++) {
+- int numElementChan;
+-
+- if (psPossible &&
+- self->pSbrElement[sbrElementNum]->pSbrChannel[1] == NULL) {
+- /* Disable PS and try decoding SBR mono. */
+- psPossible = 0;
+- }
+-
+- numElementChan =
+- (self->pSbrElement[sbrElementNum]->elementID == ID_CPE) ? 2 : 1;
+-
+- /* If core signal is bad then force upsampling */
+- if (!coreDecodedOk) {
+- setFrameErrorFlag(self->pSbrElement[sbrElementNum], FRAME_ERROR_ALLSLOTS);
+- }
+-
+- errorStatus = sbrDecoder_DecodeElement(
+- self, input, timeData, timeDataSize, mapDescr, mapIdx, numSbrChannels,
+- sbrElementNum,
+- numCoreChannels, /* is correct even for USC SCI==2 case */
+- &numElementChan, psPossible);
+-
+- if (errorStatus != SBRDEC_OK) {
+- goto bail;
+- }
+-
+- numSbrChannels += numElementChan;
+-
+- if (numSbrChannels >= numCoreChannels) {
+- break;
+- }
+- }
+-
+- /* Update numChannels and samplerate */
+- /* Do not mess with output channels in case of USAC. numSbrChannels !=
+- * numChannels for stereoConfigIndex == 2 */
+- if (!(self->flags & SBRDEC_SYNTAX_USAC)) {
+- *numChannels = numSbrChannels;
+- }
+- *sampleRate = self->sampleRateOut;
+- *psDecoded = (self->flags & SBRDEC_PS_DECODED) ? 1 : 0;
+-
+- /* Clear reset and flush flag because everything seems to be done
+- * successfully. */
+- self->flags &= ~SBRDEC_FORCE_RESET;
+- self->flags &= ~SBRDEC_FLUSH;
+-
+-bail:
+-
+- return errorStatus;
+-}
+-
+-SBR_ERROR sbrDecoder_Close(HANDLE_SBRDECODER *pSelf) {
+- HANDLE_SBRDECODER self = *pSelf;
+- int i;
+-
+- if (self != NULL) {
+- if (self->hParametricStereoDec != NULL) {
+- DeletePsDec(&self->hParametricStereoDec);
+- }
+-
+- for (i = 0; i < (8); i++) {
+- sbrDecoder_DestroyElement(self, i);
+- }
+-
+- FreeRam_SbrDecoder(pSelf);
+- }
+-
+- return SBRDEC_OK;
+-}
+-
+-INT sbrDecoder_GetLibInfo(LIB_INFO *info) {
+- int i;
+-
+- if (info == NULL) {
+- return -1;
+- }
+-
+- /* search for next free tab */
+- for (i = 0; i < FDK_MODULE_LAST; i++) {
+- if (info[i].module_id == FDK_NONE) break;
+- }
+- if (i == FDK_MODULE_LAST) return -1;
+- info += i;
+-
+- info->module_id = FDK_SBRDEC;
+- info->version =
+- LIB_VERSION(SBRDECODER_LIB_VL0, SBRDECODER_LIB_VL1, SBRDECODER_LIB_VL2);
+- LIB_VERSION_STRING(info);
+- info->build_date = SBRDECODER_LIB_BUILD_DATE;
+- info->build_time = SBRDECODER_LIB_BUILD_TIME;
+- info->title = SBRDECODER_LIB_TITLE;
+-
+- /* Set flags */
+- info->flags = 0 | CAPF_SBR_HQ | CAPF_SBR_LP | CAPF_SBR_PS_MPEG |
+- CAPF_SBR_DRM_BS | CAPF_SBR_CONCEALMENT | CAPF_SBR_DRC |
+- CAPF_SBR_ELD_DOWNSCALE | CAPF_SBR_HBEHQ;
+- /* End of flags */
+-
+- return 0;
+-}
+-
+-UINT sbrDecoder_GetDelay(const HANDLE_SBRDECODER self) {
+- UINT outputDelay = 0;
+-
+- if (self != NULL) {
+- UINT flags = self->flags;
+-
+- /* See chapter 1.6.7.2 of ISO/IEC 14496-3 for the GA-SBR figures below. */
+-
+- /* Are we initialized? */
+- if ((self->numSbrChannels > 0) && (self->numSbrElements > 0)) {
+- /* Add QMF synthesis delay */
+- if ((flags & SBRDEC_ELD_GRID) && IS_LOWDELAY(self->coreCodec)) {
+- /* Low delay SBR: */
+- if (!(flags & SBRDEC_SKIP_QMF_SYN)) {
+- outputDelay +=
+- (flags & SBRDEC_DOWNSAMPLE) ? 32 : 64; /* QMF synthesis */
+- if (flags & SBRDEC_LD_MPS_QMF) {
+- outputDelay += 32;
+- }
+- }
+- } else if (!IS_USAC(self->coreCodec)) {
+- /* By the method of elimination this is the GA (AAC-LC, HE-AAC, ...)
+- * branch: */
+- outputDelay += (flags & SBRDEC_DOWNSAMPLE) ? 481 : 962;
+- if (flags & SBRDEC_SKIP_QMF_SYN) {
+- outputDelay -= 257; /* QMF synthesis */
+- }
+- }
+- }
+- }
+-
+- return (outputDelay);
+-}
+diff --git a/libSBRdec/src/transcendent.h b/libSBRdec/src/transcendent.h
+deleted file mode 100644
+index 0e815c2..0000000
+--- a/libSBRdec/src/transcendent.h
++++ /dev/null
+@@ -1,372 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief FDK Fixed Point Arithmetic Library Interface
+-*/
+-
+-#ifndef TRANSCENDENT_H
+-#define TRANSCENDENT_H
+-
+-#include "sbrdecoder.h"
+-#include "sbr_rom.h"
+-
+-/************************************************************************/
+-/*!
+- \brief Get number of octaves between frequencies a and b
+-
+- The Result is scaled with 1/8.
+- The valid range for a and b is 1 to LOG_DUALIS_TABLE_SIZE.
+-
+- \return ld(a/b) / 8
+-*/
+-/************************************************************************/
+-static inline FIXP_SGL FDK_getNumOctavesDiv8(INT a, /*!< lower band */
+- INT b) /*!< upper band */
+-{
+- return ((SHORT)((LONG)(CalcLdInt(b) - CalcLdInt(a)) >> (FRACT_BITS - 3)));
+-}
+-
+-/************************************************************************/
+-/*!
+- \brief Add two values given by mantissa and exponent.
+-
+- Mantissas are in fract format with values between 0 and 1. <br>
+- The base for exponents is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$<br>
+-*/
+-/************************************************************************/
+-inline void FDK_add_MantExp(FIXP_SGL a_m, /*!< Mantissa of 1st operand a */
+- SCHAR a_e, /*!< Exponent of 1st operand a */
+- FIXP_SGL b_m, /*!< Mantissa of 2nd operand b */
+- SCHAR b_e, /*!< Exponent of 2nd operand b */
+- FIXP_SGL *ptrSum_m, /*!< Mantissa of result */
+- SCHAR *ptrSum_e) /*!< Exponent of result */
+-{
+- FIXP_DBL accu;
+- int shift;
+- int shiftAbs;
+-
+- FIXP_DBL shiftedMantissa;
+- FIXP_DBL otherMantissa;
+-
+- /* Equalize exponents of the summands.
+- For the smaller summand, the exponent is adapted and
+- for compensation, the mantissa is shifted right. */
+-
+- shift = (int)(a_e - b_e);
+-
+- shiftAbs = (shift > 0) ? shift : -shift;
+- shiftAbs = (shiftAbs < DFRACT_BITS - 1) ? shiftAbs : DFRACT_BITS - 1;
+- shiftedMantissa = (shift > 0) ? (FX_SGL2FX_DBL(b_m) >> shiftAbs)
+- : (FX_SGL2FX_DBL(a_m) >> shiftAbs);
+- otherMantissa = (shift > 0) ? FX_SGL2FX_DBL(a_m) : FX_SGL2FX_DBL(b_m);
+- *ptrSum_e = (shift > 0) ? a_e : b_e;
+-
+- accu = (shiftedMantissa >> 1) + (otherMantissa >> 1);
+- /* shift by 1 bit to avoid overflow */
+-
+- if ((accu >= (FL2FXCONST_DBL(0.5f) - (FIXP_DBL)1)) ||
+- (accu <= FL2FXCONST_DBL(-0.5f)))
+- *ptrSum_e += 1;
+- else
+- accu = (shiftedMantissa + otherMantissa);
+-
+- *ptrSum_m = FX_DBL2FX_SGL(accu);
+-}
+-
+-inline void FDK_add_MantExp(FIXP_DBL a, /*!< Mantissa of 1st operand a */
+- SCHAR a_e, /*!< Exponent of 1st operand a */
+- FIXP_DBL b, /*!< Mantissa of 2nd operand b */
+- SCHAR b_e, /*!< Exponent of 2nd operand b */
+- FIXP_DBL *ptrSum, /*!< Mantissa of result */
+- SCHAR *ptrSum_e) /*!< Exponent of result */
+-{
+- FIXP_DBL accu;
+- int shift;
+- int shiftAbs;
+-
+- FIXP_DBL shiftedMantissa;
+- FIXP_DBL otherMantissa;
+-
+- /* Equalize exponents of the summands.
+- For the smaller summand, the exponent is adapted and
+- for compensation, the mantissa is shifted right. */
+-
+- shift = (int)(a_e - b_e);
+-
+- shiftAbs = (shift > 0) ? shift : -shift;
+- shiftAbs = (shiftAbs < DFRACT_BITS - 1) ? shiftAbs : DFRACT_BITS - 1;
+- shiftedMantissa = (shift > 0) ? (b >> shiftAbs) : (a >> shiftAbs);
+- otherMantissa = (shift > 0) ? a : b;
+- *ptrSum_e = (shift > 0) ? a_e : b_e;
+-
+- accu = (shiftedMantissa >> 1) + (otherMantissa >> 1);
+- /* shift by 1 bit to avoid overflow */
+-
+- if ((accu >= (FL2FXCONST_DBL(0.5f) - (FIXP_DBL)1)) ||
+- (accu <= FL2FXCONST_DBL(-0.5f)))
+- *ptrSum_e += 1;
+- else
+- accu = (shiftedMantissa + otherMantissa);
+-
+- *ptrSum = accu;
+-}
+-
+-/************************************************************************/
+-/*!
+- \brief Divide two values given by mantissa and exponent.
+-
+- Mantissas are in fract format with values between 0 and 1. <br>
+- The base for exponents is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$<br>
+-
+- For performance reasons, the division is based on a table lookup
+- which limits accuracy.
+-*/
+-/************************************************************************/
+-static inline void FDK_divide_MantExp(
+- FIXP_SGL a_m, /*!< Mantissa of dividend a */
+- SCHAR a_e, /*!< Exponent of dividend a */
+- FIXP_SGL b_m, /*!< Mantissa of divisor b */
+- SCHAR b_e, /*!< Exponent of divisor b */
+- FIXP_SGL *ptrResult_m, /*!< Mantissa of quotient a/b */
+- SCHAR *ptrResult_e) /*!< Exponent of quotient a/b */
+-
+-{
+- int preShift, postShift, index, shift;
+- FIXP_DBL ratio_m;
+- FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
+-
+- preShift = CntLeadingZeros(FX_SGL2FX_DBL(b_m));
+-
+- /*
+- Shift b into the range from 0..INV_TABLE_SIZE-1,
+-
+- E.g. 10 bits must be skipped for INV_TABLE_BITS 8:
+- - leave 8 bits as index for table
+- - skip sign bit,
+- - skip first bit of mantissa, because this is always the same (>0.5)
+-
+- We are dealing with energies, so we need not care
+- about negative numbers
+- */
+-
+- /*
+- The first interval has half width so the lowest bit of the index is
+- needed for a doubled resolution.
+- */
+- shift = (FRACT_BITS - 2 - INV_TABLE_BITS - preShift);
+-
+- index = (shift < 0) ? (LONG)b_m << (-shift) : (LONG)b_m >> shift;
+-
+- /* The index has INV_TABLE_BITS +1 valid bits here. Clear the other bits. */
+- index &= (1 << (INV_TABLE_BITS + 1)) - 1;
+-
+- /* Remove offset of half an interval */
+- index--;
+-
+- /* Now the lowest bit is shifted out */
+- index = index >> 1;
+-
+- /* Fetch inversed mantissa from table: */
+- bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
+-
+- /* Multiply a with the inverse of b: */
+- ratio_m = (index < 0) ? FX_SGL2FX_DBL(a_m >> 1) : fMultDiv2(bInv_m, a_m);
+-
+- postShift = CntLeadingZeros(ratio_m) - 1;
+-
+- *ptrResult_m = FX_DBL2FX_SGL(ratio_m << postShift);
+- *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
+-}
+-
+-static inline void FDK_divide_MantExp(
+- FIXP_DBL a_m, /*!< Mantissa of dividend a */
+- SCHAR a_e, /*!< Exponent of dividend a */
+- FIXP_DBL b_m, /*!< Mantissa of divisor b */
+- SCHAR b_e, /*!< Exponent of divisor b */
+- FIXP_DBL *ptrResult_m, /*!< Mantissa of quotient a/b */
+- SCHAR *ptrResult_e) /*!< Exponent of quotient a/b */
+-
+-{
+- int preShift, postShift, index, shift;
+- FIXP_DBL ratio_m;
+- FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
+-
+- preShift = CntLeadingZeros(b_m);
+-
+- /*
+- Shift b into the range from 0..INV_TABLE_SIZE-1,
+-
+- E.g. 10 bits must be skipped for INV_TABLE_BITS 8:
+- - leave 8 bits as index for table
+- - skip sign bit,
+- - skip first bit of mantissa, because this is always the same (>0.5)
+-
+- We are dealing with energies, so we need not care
+- about negative numbers
+- */
+-
+- /*
+- The first interval has half width so the lowest bit of the index is
+- needed for a doubled resolution.
+- */
+- shift = (DFRACT_BITS - 2 - INV_TABLE_BITS - preShift);
+-
+- index = (shift < 0) ? (LONG)b_m << (-shift) : (LONG)b_m >> shift;
+-
+- /* The index has INV_TABLE_BITS +1 valid bits here. Clear the other bits. */
+- index &= (1 << (INV_TABLE_BITS + 1)) - 1;
+-
+- /* Remove offset of half an interval */
+- index--;
+-
+- /* Now the lowest bit is shifted out */
+- index = index >> 1;
+-
+- /* Fetch inversed mantissa from table: */
+- bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
+-
+- /* Multiply a with the inverse of b: */
+- ratio_m = (index < 0) ? (a_m >> 1) : fMultDiv2(bInv_m, a_m);
+-
+- postShift = CntLeadingZeros(ratio_m) - 1;
+-
+- *ptrResult_m = ratio_m << postShift;
+- *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
+-}
+-
+-/*!
+- \brief Calculate the squareroot of a number given by mantissa and exponent
+-
+- Mantissa is in fract format with values between 0 and 1. <br>
+- The base for the exponent is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$<br>
+- The operand is addressed via pointers and will be overwritten with the result.
+-
+- For performance reasons, the square root is based on a table lookup
+- which limits accuracy.
+-*/
+-static inline void FDK_sqrt_MantExp(
+- FIXP_DBL *mantissa, /*!< Pointer to mantissa */
+- SCHAR *exponent, const SCHAR *destScale) {
+- FIXP_DBL input_m = *mantissa;
+- int input_e = (int)*exponent;
+- FIXP_DBL result = FL2FXCONST_DBL(0.0f);
+- int result_e = -FRACT_BITS;
+-
+- /* Call lookup square root, which does internally normalization. */
+- result = sqrtFixp_lookup(input_m, &input_e);
+- result_e = input_e;
+-
+- /* Write result */
+- if (exponent == destScale) {
+- *mantissa = result;
+- *exponent = result_e;
+- } else {
+- int shift = result_e - *destScale;
+- *mantissa = (shift >= 0) ? result << (INT)fixMin(DFRACT_BITS - 1, shift)
+- : result >> (INT)fixMin(DFRACT_BITS - 1, -shift);
+- *exponent = *destScale;
+- }
+-}
+-
+-#endif
+diff --git a/libSBRenc/include/sbr_encoder.h b/libSBRenc/include/sbr_encoder.h
+deleted file mode 100644
+index d979ba6..0000000
+--- a/libSBRenc/include/sbr_encoder.h
++++ /dev/null
+@@ -1,483 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description: SBR encoder top level processing prototype
+-
+-*******************************************************************************/
+-
+-#ifndef SBR_ENCODER_H
+-#define SBR_ENCODER_H
+-
+-#include "common_fix.h"
+-#include "FDK_audio.h"
+-
+-#include "FDK_bitstream.h"
+-
+-/* core coder helpers */
+-#define MAX_TRANS_FAC 8
+-#define MAX_CODEC_FRAME_RATIO 2
+-#define MAX_PAYLOAD_SIZE 256
+-
+-typedef enum codecType {
+- CODEC_AAC = 0,
+- CODEC_AACLD = 1,
+- CODEC_UNSPECIFIED = 99
+-} CODEC_TYPE;
+-
+-typedef struct {
+- INT bitRate;
+- INT nChannels;
+- INT sampleFreq;
+- INT transFac;
+- INT standardBitrate;
+-} CODEC_PARAM;
+-
+-typedef enum {
+- SBR_MONO,
+- SBR_LEFT_RIGHT,
+- SBR_COUPLING,
+- SBR_SWITCH_LRC
+-} SBR_STEREO_MODE;
+-
+-/* bitstream syntax flags */
+-enum {
+- SBR_SYNTAX_LOW_DELAY = 0x0001,
+- SBR_SYNTAX_SCALABLE = 0x0002,
+- SBR_SYNTAX_CRC = 0x0004,
+- SBR_SYNTAX_DRM_CRC = 0x0008,
+- SBR_SYNTAX_ELD_REDUCED_DELAY = 0x0010
+-};
+-
+-typedef enum { FREQ_RES_LOW = 0, FREQ_RES_HIGH } FREQ_RES;
+-
+-typedef struct {
+- CODEC_TYPE coreCoder; /*!< LC or ELD */
+- UINT bitrateFrom; /*!< inclusive */
+- UINT bitrateTo; /*!< exclusive */
+-
+- UINT sampleRate; /*!< */
+- UCHAR numChannels; /*!< */
+-
+- UCHAR startFreq; /*!< bs_start_freq */
+- UCHAR startFreqSpeech; /*!< bs_start_freq for speech config flag */
+- UCHAR stopFreq; /*!< bs_stop_freq */
+- UCHAR stopFreqSpeech; /*!< bs_stop_freq for speech config flag */
+-
+- UCHAR numNoiseBands; /*!< */
+- UCHAR noiseFloorOffset; /*!< */
+- SCHAR noiseMaxLevel; /*!< */
+- SBR_STEREO_MODE stereoMode; /*!< */
+- UCHAR freqScale; /*!< */
+-} sbrTuningTable_t;
+-
+-typedef struct sbrConfiguration {
+- /*
+- core coder dependent configurations
+- */
+- CODEC_PARAM
+- codecSettings; /*!< Core coder settings. To be set from core coder. */
+- INT SendHeaderDataTime; /*!< SBR header send update frequency in ms. */
+- INT useWaveCoding; /*!< Flag: usage of wavecoding tool. */
+- INT crcSbr; /*!< Flag: usage of SBR-CRC. */
+- INT dynBwSupported; /*!< Flag: support for dynamic bandwidth in this
+- combination. */
+- INT parametricCoding; /*!< Flag: usage of parametric coding tool. */
+- INT downSampleFactor; /*!< Sampling rate relation between the SBR and the core
+- encoder. */
+- FREQ_RES freq_res_fixfix[2]; /*!< Frequency resolution of envelopes in frame
+- class FIXFIX, for non-split case and split
+- case */
+- UCHAR fResTransIsLow; /*!< Frequency resolution of envelopes in transient
+- frames: low (0) or variable (1) */
+-
+- /*
+- core coder dependent tuning parameters
+- */
+- INT tran_thr; /*!< SBR transient detector threshold (* 100). */
+- INT noiseFloorOffset; /*!< Noise floor offset. */
+- UINT useSpeechConfig; /*!< Flag: adapt tuning parameters according to speech.
+- */
+-
+- /*
+- core coder independent configurations
+- */
+- INT sbrFrameSize; /*!< SBR frame size in samples. Will be calculated from core
+- coder settings. */
+- INT sbr_data_extra; /*!< Flag usage of data extra. */
+- INT amp_res; /*!< Amplitude resolution. */
+- INT ana_max_level; /*!< Noise insertion maximum level. */
+- INT tran_fc; /*!< Transient detector start frequency. */
+- INT tran_det_mode; /*!< Transient detector mode. */
+- INT spread; /*!< Flag: usage of SBR spread. */
+- INT stat; /*!< Flag: usage of static framing. */
+- INT e; /*!< Number of envelopes when static framing is chosen. */
+- SBR_STEREO_MODE stereoMode; /*!< SBR stereo mode. */
+- INT deltaTAcrossFrames; /*!< Flag: allow time-delta coding. */
+- FIXP_DBL dF_edge_1stEnv; /*!< Extra fraction delta-F coding is allowed to be
+- more expensive. */
+- FIXP_DBL dF_edge_incr; /*!< Increment dF_edge_1stEnv this much if dT-coding
+- was used this frame. */
+- INT sbr_invf_mode; /*!< Inverse filtering mode. */
+- INT sbr_xpos_mode; /*!< Transposer mode. */
+- INT sbr_xpos_ctrl; /*!< Transposer control. */
+- INT sbr_xpos_level; /*!< Transposer 3rd order level. */
+- INT startFreq; /*!< The start frequency table index. */
+- INT stopFreq; /*!< The stop frequency table index. */
+- INT useSaPan; /*!< Flag: usage of SAPAN stereo. */
+- INT dynBwEnabled; /*!< Flag: usage of dynamic bandwidth. */
+- INT bParametricStereo; /*!< Flag: usage of parametric stereo coding tool. */
+-
+- /*
+- header_extra1 configuration
+- */
+- UCHAR freqScale; /*!< Frequency grouping. */
+- INT alterScale; /*!< Scale resolution. */
+- INT sbr_noise_bands; /*!< Number of noise bands. */
+-
+- /*
+- header_extra2 configuration
+- */
+- INT sbr_limiter_bands; /*!< Number of limiter bands. */
+- INT sbr_limiter_gains; /*!< Gain of limiter. */
+- INT sbr_interpol_freq; /*!< Flag: use interpolation in freq. direction. */
+- INT sbr_smoothing_length; /*!< Flag: choose length 4 or 0 (=on, off). */
+- UCHAR init_amp_res_FF;
+- FIXP_DBL threshold_AmpRes_FF_m;
+- SCHAR threshold_AmpRes_FF_e;
+-} sbrConfiguration, *sbrConfigurationPtr;
+-
+-typedef struct SBR_CONFIG_DATA {
+- UINT sbrSyntaxFlags; /**< SBR syntax flags derived from AOT. */
+- INT nChannels; /**< Number of channels. */
+-
+- INT nSfb[2]; /**< Number of SBR scalefactor bands for LO_RES and HI_RES (?) */
+- INT num_Master; /**< Number of elements in v_k_master. */
+- INT sampleFreq; /**< SBR sampling frequency. */
+- INT frameSize;
+- INT xOverFreq; /**< The SBR start frequency. */
+- INT dynXOverFreq; /**< Used crossover frequency when dynamic bandwidth is
+- enabled. */
+-
+- INT noQmfBands; /**< Number of QMF frequency bands. */
+- INT noQmfSlots; /**< Number of QMF slots. */
+-
+- UCHAR *freqBandTable[2]; /**< Frequency table for low and hires, only
+- MAX_FREQ_COEFFS/2 +1 coeffs actually needed for
+- lowres. */
+- UCHAR
+- *v_k_master; /**< Master BandTable where freqBandTable is derived from. */
+-
+- SBR_STEREO_MODE stereoMode;
+- INT noEnvChannels; /**< Number of envelope channels. */
+-
+- INT useWaveCoding; /**< Flag indicates whether to use wave coding at all. */
+- INT useParametricCoding; /**< Flag indicates whether to use para coding at
+- all. */
+- INT xposCtrlSwitch; /**< Flag indicates whether to switch xpos ctrl on the
+- fly. */
+- INT switchTransposers; /**< Flag indicates whether to switch xpos on the fly .
+- */
+- UCHAR initAmpResFF;
+- FIXP_DBL thresholdAmpResFF_m;
+- SCHAR thresholdAmpResFF_e;
+-} SBR_CONFIG_DATA, *HANDLE_SBR_CONFIG_DATA;
+-
+-typedef struct {
+- MP4_ELEMENT_ID elType;
+- INT bitRate;
+- int instanceTag;
+- UCHAR fParametricStereo;
+- UCHAR fDualMono; /**< This flags allows to disable coupling in sbr channel
+- pair element */
+- UCHAR nChannelsInEl;
+- UCHAR ChannelIndex[2];
+-} SBR_ELEMENT_INFO;
+-
+-#ifdef __cplusplus
+-extern "C" {
+-#endif
+-
+-typedef struct SBR_ENCODER *HANDLE_SBR_ENCODER;
+-
+-/**
+- * \brief Get the max required input buffer size including delay balancing
+- * space for N audio channels.
+- * \param noChannels Number of audio channels.
+- * \return Max required input buffer size in bytes.
+- */
+-INT sbrEncoder_GetInBufferSize(int noChannels);
+-
+-INT sbrEncoder_Open(HANDLE_SBR_ENCODER *phSbrEncoder, INT nElements,
+- INT nChannels, INT supportPS);
+-
+-/**
+- * \brief Get closest working bitrate to specified desired
+- * bitrate for a single SBR element.
+- * \param bitRate The desired target bit rate
+- * \param numChannels The amount of audio channels
+- * \param coreSampleRate The sample rate of the core coder
+- * \param aot The current Audio Object Type
+- * \return Closest working bit rate to bitRate value
+- */
+-UINT sbrEncoder_LimitBitRate(UINT bitRate, UINT numChannels,
+- UINT coreSampleRate, AUDIO_OBJECT_TYPE aot);
+-
+-/**
+- * \brief Check whether downsampled SBR single rate is possible
+- * with given audio object type.
+- * \param aot The Audio object type.
+- * \return 0 when downsampled SBR is not possible,
+- * 1 when downsampled SBR is possible.
+- */
+-UINT sbrEncoder_IsSingleRatePossible(AUDIO_OBJECT_TYPE aot);
+-
+-/**
+- * \brief Initialize SBR Encoder instance.
+- * \param phSbrEncoder Pointer to a SBR Encoder instance.
+- * \param elInfo Structure that describes the element/channel
+- * arrangement.
+- * \param noElements Amount of elements described in elInfo.
+- * \param inputBuffer Pointer to the encoder audio buffer
+- * \param inputBufferBufSize Buffer offset of one channel (frameSize + delay)
+- * \param bandwidth Returns the core audio encoder bandwidth (output)
+- * \param bufferOffset Returns the offset for the audio input data in order
+- * to do delay balancing.
+- * \param numChannels Input: Encoder input channels. output: core encoder
+- * channels.
+- * \param sampleRate Input: Encoder samplerate. output core encoder
+- * samplerate.
+- * \param downSampleFactor Input: Relation between SBR and core coder sampling
+- * rate;
+- * \param frameLength Input: Encoder frameLength. output core encoder
+- * frameLength.
+- * \param aot Input: AOT..
+- * \param delay Input: core encoder delay. Output: total delay
+- * because of SBR.
+- * \param transformFactor The core encoder transform factor (blockswitching).
+- * \param headerPeriod Repetition rate of the SBR header:
+- * - (-1) means intern configuration.
+- * - (1-10) corresponds to header repetition rate in
+- * frames.
+- * \return 0 on success, and non-zero if failed.
+- */
+-INT sbrEncoder_Init(HANDLE_SBR_ENCODER hSbrEncoder,
+- SBR_ELEMENT_INFO elInfo[(8)], int noElements,
+- INT_PCM *inputBuffer, UINT inputBufferBufSize,
+- INT *coreBandwidth, INT *inputBufferOffset,
+- INT *numChannels, const UINT syntaxFlags, INT *sampleRate,
+- UINT *downSampleFactor, INT *frameLength,
+- AUDIO_OBJECT_TYPE aot, int *delay, int transformFactor,
+- const int headerPeriod, ULONG statesInitFlag);
+-
+-/**
+- * \brief Do delay line buffers housekeeping. To be called after
+- * each encoded audio frame.
+- * \param hEnvEnc SBR Encoder handle.
+- * \param timeBuffer Pointer to the encoder audio buffer.
+- * \param timeBufferBufSIze buffer size for one channel
+- * \return 0 on success, and non-zero if failed.
+- */
+-INT sbrEncoder_UpdateBuffers(HANDLE_SBR_ENCODER hEnvEnc, INT_PCM *timeBuffer,
+- UINT timeBufferBufSIze);
+-
+-/**
+- * \brief Close SBR encoder instance.
+- * \param phEbrEncoder Handle of SBR encoder instance to be closed.
+- * \return void
+- */
+-void sbrEncoder_Close(HANDLE_SBR_ENCODER *phEbrEncoder);
+-
+-/**
+- * \brief Encode SBR data of one complete audio frame.
+- * \param hEnvEncoder Handle of SBR encoder instance.
+- * \param samples Time samples, not interleaved.
+- * \param timeInStride Channel offset of samples buffer.
+- * \param sbrDataBits Size of SBR payload in bits.
+- * \param sbrData SBR payload.
+- * \return 0 on success, and non-zero if failed.
+- */
+-INT sbrEncoder_EncodeFrame(HANDLE_SBR_ENCODER hEnvEncoder, INT_PCM *samples,
+- UINT samplesBufSize, UINT sbrDataBits[(8)],
+- UCHAR sbrData[(8)][MAX_PAYLOAD_SIZE]);
+-
+-/**
+- * \brief Write SBR headers of one SBR element.
+- * \param sbrEncoder Handle of the SBR encoder instance.
+- * \param hBs Handle of bit stream handle to write SBR header to.
+- * \param element_index Index of the SBR element which header should be written.
+- * \param fSendHeaders Flag indicating that the SBR encoder should send more
+- * headers in the SBR payload or not.
+- * \return void
+- */
+-void sbrEncoder_GetHeader(HANDLE_SBR_ENCODER sbrEncoder,
+- HANDLE_FDK_BITSTREAM hBs, INT element_index,
+- int fSendHeaders);
+-
+-/**
+- * \brief Request to write SBR header.
+- * \param hSbrEncoder SBR encoder handle.
+- * \return 0 on success, and non-zero if failed.
+- */
+-INT sbrEncoder_SendHeader(HANDLE_SBR_ENCODER hSbrEncoder);
+-
+-/**
+- * \brief Request if last sbr payload contains an SBR header.
+- * \param hSbrEncoder SBR encoder handle.
+- * \return 1 contains sbr header, 0 without sbr header.
+- */
+-INT sbrEncoder_ContainsHeader(HANDLE_SBR_ENCODER hSbrEncoder);
+-
+-/**
+- * \brief SBR header delay in frames.
+- * \param hSbrEncoder SBR encoder handle.
+- * \return Delay in frames, -1 on failure.
+- */
+-INT sbrEncoder_GetHeaderDelay(HANDLE_SBR_ENCODER hSbrEncoder);
+-
+-/**
+- * \brief Bitstrem delay in SBR frames.
+- * \param hSbrEncoder SBR encoder handle.
+- * \return Delay in frames, -1 on failure.
+- */
+-INT sbrEncoder_GetBsDelay(HANDLE_SBR_ENCODER hSbrEncoder);
+-
+-/**
+- * \brief Prepare SBR payload for SAP.
+- * \param hSbrEncoder SBR encoder handle.
+- * \return 0 on success, and non-zero if failed.
+- */
+-INT sbrEncoder_SAPPrepare(HANDLE_SBR_ENCODER hSbrEncoder);
+-
+-/**
+- * \brief SBR encoder bitrate estimation.
+- * \param hSbrEncoder SBR encoder handle.
+- * \return Estimated bitrate.
+- */
+-INT sbrEncoder_GetEstimateBitrate(HANDLE_SBR_ENCODER hSbrEncoder);
+-
+-/**
+- * \brief Delay between input data and downsampled output data.
+- * \param hSbrEncoder SBR encoder handle.
+- * \return Delay.
+- */
+-INT sbrEncoder_GetInputDataDelay(HANDLE_SBR_ENCODER hSbrEncoder);
+-
+-/**
+- * \brief Delay caused by the SBR decoder.
+- * \param hSbrEncoder SBR encoder handle.
+- * \return Delay.
+- */
+-INT sbrEncoder_GetSbrDecDelay(HANDLE_SBR_ENCODER hSbrEncoder);
+-
+-/**
+- * \brief Get decoder library version info.
+- * \param info Pointer to an allocated LIB_INFO struct, where library info is
+- * written to.
+- * \return 0 on sucess.
+- */
+-INT sbrEncoder_GetLibInfo(LIB_INFO *info);
+-
+-void sbrPrintRAM(void);
+-
+-void sbrPrintROM(void);
+-
+-#ifdef __cplusplus
+-}
+-#endif
+-
+-#endif /* ifndef __SBR_MAIN_H */
+diff --git a/libSBRenc/src/bit_sbr.cpp b/libSBRenc/src/bit_sbr.cpp
+deleted file mode 100644
+index 5a65e98..0000000
+--- a/libSBRenc/src/bit_sbr.cpp
++++ /dev/null
+@@ -1,1049 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief SBR bit writing routines $Revision: 93300 $
+-*/
+-
+-#include "bit_sbr.h"
+-
+-#include "code_env.h"
+-#include "cmondata.h"
+-#include "sbr.h"
+-
+-#include "ps_main.h"
+-
+-typedef enum { SBR_ID_SCE = 1, SBR_ID_CPE } SBR_ELEMENT_TYPE;
+-
+-static INT encodeSbrData(HANDLE_SBR_ENV_DATA sbrEnvDataLeft,
+- HANDLE_SBR_ENV_DATA sbrEnvDataRight,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_COMMON_DATA cmonData, SBR_ELEMENT_TYPE sbrElem,
+- INT coupling, UINT sbrSyntaxFlags);
+-
+-static INT encodeSbrHeader(HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData,
+- HANDLE_COMMON_DATA cmonData);
+-
+-static INT encodeSbrHeaderData(HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_FDK_BITSTREAM hBitStream);
+-
+-static INT encodeSbrSingleChannelElement(
+- HANDLE_SBR_ENV_DATA sbrEnvData, HANDLE_FDK_BITSTREAM hBitStream,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo, const UINT sbrSyntaxFlags);
+-
+-static INT encodeSbrChannelPairElement(
+- HANDLE_SBR_ENV_DATA sbrEnvDataLeft, HANDLE_SBR_ENV_DATA sbrEnvDataRight,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo, HANDLE_FDK_BITSTREAM hBitStream,
+- const INT coupling, const UINT sbrSyntaxFlags);
+-
+-static INT encodeSbrGrid(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream);
+-
+-static int encodeLowDelaySbrGrid(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream,
+- const int transmitFreqs,
+- const UINT sbrSyntaxFlags);
+-
+-static INT encodeSbrDtdf(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream);
+-
+-static INT writeNoiseLevelData(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream, INT coupling);
+-
+-static INT writeEnvelopeData(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream, INT coupling);
+-
+-static INT writeSyntheticCodingData(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream);
+-
+-static INT encodeExtendedData(HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_FDK_BITSTREAM hBitStream);
+-
+-static INT getSbrExtendedDataSize(HANDLE_PARAMETRIC_STEREO hParametricStereo);
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_WriteEnvSingleChannelElement
+- description: writes pure SBR single channel data element
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-INT FDKsbrEnc_WriteEnvSingleChannelElement(
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData, HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_COMMON_DATA cmonData, UINT sbrSyntaxFlags)
+-
+-{
+- INT payloadBits = 0;
+-
+- cmonData->sbrHdrBits = 0;
+- cmonData->sbrDataBits = 0;
+-
+- /* write pure sbr data */
+- if (sbrEnvData != NULL) {
+- /* write header */
+- payloadBits += encodeSbrHeader(sbrHeaderData, sbrBitstreamData, cmonData);
+-
+- /* write data */
+- payloadBits += encodeSbrData(sbrEnvData, NULL, hParametricStereo, cmonData,
+- SBR_ID_SCE, 0, sbrSyntaxFlags);
+- }
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_WriteEnvChannelPairElement
+- description: writes pure SBR channel pair data element
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-INT FDKsbrEnc_WriteEnvChannelPairElement(
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData,
+- HANDLE_SBR_ENV_DATA sbrEnvDataLeft, HANDLE_SBR_ENV_DATA sbrEnvDataRight,
+- HANDLE_COMMON_DATA cmonData, UINT sbrSyntaxFlags)
+-
+-{
+- INT payloadBits = 0;
+- cmonData->sbrHdrBits = 0;
+- cmonData->sbrDataBits = 0;
+-
+- /* write pure sbr data */
+- if ((sbrEnvDataLeft != NULL) && (sbrEnvDataRight != NULL)) {
+- /* write header */
+- payloadBits += encodeSbrHeader(sbrHeaderData, sbrBitstreamData, cmonData);
+-
+- /* write data */
+- payloadBits += encodeSbrData(sbrEnvDataLeft, sbrEnvDataRight,
+- hParametricStereo, cmonData, SBR_ID_CPE,
+- sbrHeaderData->coupling, sbrSyntaxFlags);
+- }
+- return payloadBits;
+-}
+-
+-INT FDKsbrEnc_CountSbrChannelPairElement(
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData,
+- HANDLE_SBR_ENV_DATA sbrEnvDataLeft, HANDLE_SBR_ENV_DATA sbrEnvDataRight,
+- HANDLE_COMMON_DATA cmonData, UINT sbrSyntaxFlags) {
+- INT payloadBits;
+- INT bitPos = FDKgetValidBits(&cmonData->sbrBitbuf);
+-
+- payloadBits = FDKsbrEnc_WriteEnvChannelPairElement(
+- sbrHeaderData, hParametricStereo, sbrBitstreamData, sbrEnvDataLeft,
+- sbrEnvDataRight, cmonData, sbrSyntaxFlags);
+-
+- FDKpushBack(&cmonData->sbrBitbuf,
+- (FDKgetValidBits(&cmonData->sbrBitbuf) - bitPos));
+-
+- return payloadBits;
+-}
+-
+-void sbrEncoder_GetHeader(SBR_ENCODER *sbrEncoder, HANDLE_FDK_BITSTREAM hBs,
+- INT element_index, int fSendHeaders) {
+- encodeSbrHeaderData(&sbrEncoder->sbrElement[element_index]->sbrHeaderData,
+- hBs);
+-
+- if (fSendHeaders == 0) {
+- /* Prevent header being embedded into the SBR payload. */
+- sbrEncoder->sbrElement[element_index]->sbrBitstreamData.NrSendHeaderData =
+- -1;
+- sbrEncoder->sbrElement[element_index]->sbrBitstreamData.HeaderActive = 0;
+- sbrEncoder->sbrElement[element_index]
+- ->sbrBitstreamData.CountSendHeaderData = -1;
+- }
+-}
+-
+-/*****************************************************************************
+-
+- functionname: encodeSbrHeader
+- description: encodes SBR Header information
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT encodeSbrHeader(HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData,
+- HANDLE_COMMON_DATA cmonData) {
+- INT payloadBits = 0;
+-
+- if (sbrBitstreamData->HeaderActive) {
+- payloadBits += FDKwriteBits(&cmonData->sbrBitbuf, 1, 1);
+- payloadBits += encodeSbrHeaderData(sbrHeaderData, &cmonData->sbrBitbuf);
+- } else {
+- payloadBits += FDKwriteBits(&cmonData->sbrBitbuf, 0, 1);
+- }
+-
+- cmonData->sbrHdrBits = payloadBits;
+-
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: encodeSbrHeaderData
+- description: writes sbr_header()
+- bs_protocol_version through bs_header_extra_2
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT encodeSbrHeaderData(HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_FDK_BITSTREAM hBitStream)
+-
+-{
+- INT payloadBits = 0;
+- if (sbrHeaderData != NULL) {
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->sbr_amp_res,
+- SI_SBR_AMP_RES_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->sbr_start_frequency,
+- SI_SBR_START_FREQ_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->sbr_stop_frequency,
+- SI_SBR_STOP_FREQ_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->sbr_xover_band,
+- SI_SBR_XOVER_BAND_BITS);
+-
+- payloadBits += FDKwriteBits(hBitStream, 0, SI_SBR_RESERVED_BITS);
+-
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->header_extra_1,
+- SI_SBR_HEADER_EXTRA_1_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->header_extra_2,
+- SI_SBR_HEADER_EXTRA_2_BITS);
+-
+- if (sbrHeaderData->header_extra_1) {
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->freqScale,
+- SI_SBR_FREQ_SCALE_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->alterScale,
+- SI_SBR_ALTER_SCALE_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->sbr_noise_bands,
+- SI_SBR_NOISE_BANDS_BITS);
+- } /* sbrHeaderData->header_extra_1 */
+-
+- if (sbrHeaderData->header_extra_2) {
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->sbr_limiter_bands,
+- SI_SBR_LIMITER_BANDS_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->sbr_limiter_gains,
+- SI_SBR_LIMITER_GAINS_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrHeaderData->sbr_interpol_freq,
+- SI_SBR_INTERPOL_FREQ_BITS);
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrHeaderData->sbr_smoothing_length,
+- SI_SBR_SMOOTHING_LENGTH_BITS);
+-
+- } /* sbrHeaderData->header_extra_2 */
+- } /* sbrHeaderData != NULL */
+-
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: encodeSbrData
+- description: encodes sbr Data information
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT encodeSbrData(HANDLE_SBR_ENV_DATA sbrEnvDataLeft,
+- HANDLE_SBR_ENV_DATA sbrEnvDataRight,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_COMMON_DATA cmonData, SBR_ELEMENT_TYPE sbrElem,
+- INT coupling, UINT sbrSyntaxFlags) {
+- INT payloadBits = 0;
+-
+- switch (sbrElem) {
+- case SBR_ID_SCE:
+- payloadBits +=
+- encodeSbrSingleChannelElement(sbrEnvDataLeft, &cmonData->sbrBitbuf,
+- hParametricStereo, sbrSyntaxFlags);
+- break;
+- case SBR_ID_CPE:
+- payloadBits += encodeSbrChannelPairElement(
+- sbrEnvDataLeft, sbrEnvDataRight, hParametricStereo,
+- &cmonData->sbrBitbuf, coupling, sbrSyntaxFlags);
+- break;
+- default:
+- /* we never should apply SBR to any other element type */
+- FDK_ASSERT(0);
+- }
+-
+- cmonData->sbrDataBits = payloadBits;
+-
+- return payloadBits;
+-}
+-
+-#define MODE_FREQ_TANS 1
+-#define MODE_NO_FREQ_TRAN 0
+-#define LD_TRANSMISSION MODE_FREQ_TANS
+-static int encodeFreqs(int mode) { return ((mode & MODE_FREQ_TANS) ? 1 : 0); }
+-
+-/*****************************************************************************
+-
+- functionname: encodeSbrSingleChannelElement
+- description: encodes sbr SCE information
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT encodeSbrSingleChannelElement(
+- HANDLE_SBR_ENV_DATA sbrEnvData, HANDLE_FDK_BITSTREAM hBitStream,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo, const UINT sbrSyntaxFlags) {
+- INT i, payloadBits = 0;
+-
+- payloadBits += FDKwriteBits(hBitStream, 0,
+- SI_SBR_DATA_EXTRA_BITS); /* no reserved bits */
+-
+- if (sbrEnvData->ldGrid) {
+- if (sbrEnvData->hSbrBSGrid->frameClass != FIXFIXonly) {
+- /* encode normal SbrGrid */
+- payloadBits += encodeSbrGrid(sbrEnvData, hBitStream);
+- } else {
+- /* use FIXFIXonly frame Grid */
+- payloadBits += encodeLowDelaySbrGrid(
+- sbrEnvData, hBitStream, encodeFreqs(LD_TRANSMISSION), sbrSyntaxFlags);
+- }
+- } else {
+- if (sbrSyntaxFlags & SBR_SYNTAX_SCALABLE) {
+- payloadBits += FDKwriteBits(hBitStream, 1, SI_SBR_COUPLING_BITS);
+- }
+- payloadBits += encodeSbrGrid(sbrEnvData, hBitStream);
+- }
+-
+- payloadBits += encodeSbrDtdf(sbrEnvData, hBitStream);
+-
+- for (i = 0; i < sbrEnvData->noOfnoisebands; i++) {
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->sbr_invf_mode_vec[i],
+- SI_SBR_INVF_MODE_BITS);
+- }
+-
+- payloadBits += writeEnvelopeData(sbrEnvData, hBitStream, 0);
+- payloadBits += writeNoiseLevelData(sbrEnvData, hBitStream, 0);
+-
+- payloadBits += writeSyntheticCodingData(sbrEnvData, hBitStream);
+-
+- payloadBits += encodeExtendedData(hParametricStereo, hBitStream);
+-
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: encodeSbrChannelPairElement
+- description: encodes sbr CPE information
+- returns:
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT encodeSbrChannelPairElement(
+- HANDLE_SBR_ENV_DATA sbrEnvDataLeft, HANDLE_SBR_ENV_DATA sbrEnvDataRight,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo, HANDLE_FDK_BITSTREAM hBitStream,
+- const INT coupling, const UINT sbrSyntaxFlags) {
+- INT payloadBits = 0;
+- INT i = 0;
+-
+- payloadBits += FDKwriteBits(hBitStream, 0,
+- SI_SBR_DATA_EXTRA_BITS); /* no reserved bits */
+-
+- payloadBits += FDKwriteBits(hBitStream, coupling, SI_SBR_COUPLING_BITS);
+-
+- if (coupling) {
+- if (sbrEnvDataLeft->ldGrid) {
+- if (sbrEnvDataLeft->hSbrBSGrid->frameClass != FIXFIXonly) {
+- /* normal SbrGrid */
+- payloadBits += encodeSbrGrid(sbrEnvDataLeft, hBitStream);
+-
+- } else {
+- /* FIXFIXonly frame Grid */
+- payloadBits +=
+- encodeLowDelaySbrGrid(sbrEnvDataLeft, hBitStream,
+- encodeFreqs(LD_TRANSMISSION), sbrSyntaxFlags);
+- }
+- } else
+- payloadBits += encodeSbrGrid(sbrEnvDataLeft, hBitStream);
+-
+- payloadBits += encodeSbrDtdf(sbrEnvDataLeft, hBitStream);
+- payloadBits += encodeSbrDtdf(sbrEnvDataRight, hBitStream);
+-
+- for (i = 0; i < sbrEnvDataLeft->noOfnoisebands; i++) {
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrEnvDataLeft->sbr_invf_mode_vec[i],
+- SI_SBR_INVF_MODE_BITS);
+- }
+-
+- payloadBits += writeEnvelopeData(sbrEnvDataLeft, hBitStream, 1);
+- payloadBits += writeNoiseLevelData(sbrEnvDataLeft, hBitStream, 1);
+- payloadBits += writeEnvelopeData(sbrEnvDataRight, hBitStream, 1);
+- payloadBits += writeNoiseLevelData(sbrEnvDataRight, hBitStream, 1);
+-
+- payloadBits += writeSyntheticCodingData(sbrEnvDataLeft, hBitStream);
+- payloadBits += writeSyntheticCodingData(sbrEnvDataRight, hBitStream);
+-
+- } else { /* no coupling */
+- FDK_ASSERT(sbrEnvDataLeft->ldGrid == sbrEnvDataRight->ldGrid);
+-
+- if (sbrEnvDataLeft->ldGrid || sbrEnvDataRight->ldGrid) {
+- /* sbrEnvDataLeft (left channel) */
+- if (sbrEnvDataLeft->hSbrBSGrid->frameClass != FIXFIXonly) {
+- /* no FIXFIXonly Frame so we dont need encodeLowDelaySbrGrid */
+- /* normal SbrGrid */
+- payloadBits += encodeSbrGrid(sbrEnvDataLeft, hBitStream);
+-
+- } else {
+- /* FIXFIXonly frame Grid */
+- payloadBits +=
+- encodeLowDelaySbrGrid(sbrEnvDataLeft, hBitStream,
+- encodeFreqs(LD_TRANSMISSION), sbrSyntaxFlags);
+- }
+-
+- /* sbrEnvDataRight (right channel) */
+- if (sbrEnvDataRight->hSbrBSGrid->frameClass != FIXFIXonly) {
+- /* no FIXFIXonly Frame so we dont need encodeLowDelaySbrGrid */
+- /* normal SbrGrid */
+- payloadBits += encodeSbrGrid(sbrEnvDataRight, hBitStream);
+-
+- } else {
+- /* FIXFIXonly frame Grid */
+- payloadBits +=
+- encodeLowDelaySbrGrid(sbrEnvDataRight, hBitStream,
+- encodeFreqs(LD_TRANSMISSION), sbrSyntaxFlags);
+- }
+- } else {
+- payloadBits += encodeSbrGrid(sbrEnvDataLeft, hBitStream);
+- payloadBits += encodeSbrGrid(sbrEnvDataRight, hBitStream);
+- }
+- payloadBits += encodeSbrDtdf(sbrEnvDataLeft, hBitStream);
+- payloadBits += encodeSbrDtdf(sbrEnvDataRight, hBitStream);
+-
+- for (i = 0; i < sbrEnvDataLeft->noOfnoisebands; i++) {
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrEnvDataLeft->sbr_invf_mode_vec[i],
+- SI_SBR_INVF_MODE_BITS);
+- }
+- for (i = 0; i < sbrEnvDataRight->noOfnoisebands; i++) {
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrEnvDataRight->sbr_invf_mode_vec[i],
+- SI_SBR_INVF_MODE_BITS);
+- }
+-
+- payloadBits += writeEnvelopeData(sbrEnvDataLeft, hBitStream, 0);
+- payloadBits += writeEnvelopeData(sbrEnvDataRight, hBitStream, 0);
+- payloadBits += writeNoiseLevelData(sbrEnvDataLeft, hBitStream, 0);
+- payloadBits += writeNoiseLevelData(sbrEnvDataRight, hBitStream, 0);
+-
+- payloadBits += writeSyntheticCodingData(sbrEnvDataLeft, hBitStream);
+- payloadBits += writeSyntheticCodingData(sbrEnvDataRight, hBitStream);
+-
+- } /* coupling */
+-
+- payloadBits += encodeExtendedData(hParametricStereo, hBitStream);
+-
+- return payloadBits;
+-}
+-
+-static INT ceil_ln2(INT x) {
+- INT tmp = -1;
+- while ((1 << ++tmp) < x)
+- ;
+- return (tmp);
+-}
+-
+-/*****************************************************************************
+-
+- functionname: encodeSbrGrid
+- description: if hBitStream != NULL writes bits that describes the
+- time/frequency grouping of a frame; else counts them only
+- returns: number of bits written or counted
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT encodeSbrGrid(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream) {
+- INT payloadBits = 0;
+- INT i, temp;
+- INT bufferFrameStart = sbrEnvData->hSbrBSGrid->bufferFrameStart;
+- INT numberTimeSlots = sbrEnvData->hSbrBSGrid->numberTimeSlots;
+-
+- if (sbrEnvData->ldGrid)
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->frameClass,
+- SBR_CLA_BITS_LD);
+- else
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->frameClass,
+- SBR_CLA_BITS);
+-
+- switch (sbrEnvData->hSbrBSGrid->frameClass) {
+- case FIXFIXonly:
+- FDK_ASSERT(0 /* Fatal error in encodeSbrGrid! */);
+- break;
+- case FIXFIX:
+- temp = ceil_ln2(sbrEnvData->hSbrBSGrid->bs_num_env);
+- payloadBits += FDKwriteBits(hBitStream, temp, SBR_ENV_BITS);
+- if ((sbrEnvData->ldGrid) && (sbrEnvData->hSbrBSGrid->bs_num_env == 1))
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->currentAmpResFF,
+- SI_SBR_AMP_RES_BITS);
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->v_f[0],
+- SBR_RES_BITS);
+-
+- break;
+-
+- case FIXVAR:
+- case VARFIX:
+- if (sbrEnvData->hSbrBSGrid->frameClass == FIXVAR)
+- temp = sbrEnvData->hSbrBSGrid->bs_abs_bord -
+- (bufferFrameStart + numberTimeSlots);
+- else
+- temp = sbrEnvData->hSbrBSGrid->bs_abs_bord - bufferFrameStart;
+-
+- payloadBits += FDKwriteBits(hBitStream, temp, SBR_ABS_BITS);
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->n, SBR_NUM_BITS);
+-
+- for (i = 0; i < sbrEnvData->hSbrBSGrid->n; i++) {
+- temp = (sbrEnvData->hSbrBSGrid->bs_rel_bord[i] - 2) >> 1;
+- payloadBits += FDKwriteBits(hBitStream, temp, SBR_REL_BITS);
+- }
+-
+- temp = ceil_ln2(sbrEnvData->hSbrBSGrid->n + 2);
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->p, temp);
+-
+- for (i = 0; i < sbrEnvData->hSbrBSGrid->n + 1; i++) {
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->v_f[i],
+- SBR_RES_BITS);
+- }
+- break;
+-
+- case VARVAR:
+- temp = sbrEnvData->hSbrBSGrid->bs_abs_bord_0 - bufferFrameStart;
+- payloadBits += FDKwriteBits(hBitStream, temp, SBR_ABS_BITS);
+- temp = sbrEnvData->hSbrBSGrid->bs_abs_bord_1 -
+- (bufferFrameStart + numberTimeSlots);
+- payloadBits += FDKwriteBits(hBitStream, temp, SBR_ABS_BITS);
+-
+- payloadBits += FDKwriteBits(
+- hBitStream, sbrEnvData->hSbrBSGrid->bs_num_rel_0, SBR_NUM_BITS);
+- payloadBits += FDKwriteBits(
+- hBitStream, sbrEnvData->hSbrBSGrid->bs_num_rel_1, SBR_NUM_BITS);
+-
+- for (i = 0; i < sbrEnvData->hSbrBSGrid->bs_num_rel_0; i++) {
+- temp = (sbrEnvData->hSbrBSGrid->bs_rel_bord_0[i] - 2) >> 1;
+- payloadBits += FDKwriteBits(hBitStream, temp, SBR_REL_BITS);
+- }
+-
+- for (i = 0; i < sbrEnvData->hSbrBSGrid->bs_num_rel_1; i++) {
+- temp = (sbrEnvData->hSbrBSGrid->bs_rel_bord_1[i] - 2) >> 1;
+- payloadBits += FDKwriteBits(hBitStream, temp, SBR_REL_BITS);
+- }
+-
+- temp = ceil_ln2(sbrEnvData->hSbrBSGrid->bs_num_rel_0 +
+- sbrEnvData->hSbrBSGrid->bs_num_rel_1 + 2);
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->p, temp);
+-
+- temp = sbrEnvData->hSbrBSGrid->bs_num_rel_0 +
+- sbrEnvData->hSbrBSGrid->bs_num_rel_1 + 1;
+-
+- for (i = 0; i < temp; i++) {
+- payloadBits += FDKwriteBits(
+- hBitStream, sbrEnvData->hSbrBSGrid->v_fLR[i], SBR_RES_BITS);
+- }
+- break;
+- }
+-
+- return payloadBits;
+-}
+-
+-#define SBR_CLA_BITS_LD 1
+-/*****************************************************************************
+-
+- functionname: encodeLowDelaySbrGrid
+- description: if hBitStream != NULL writes bits that describes the
+- time/frequency grouping of a frame;
+- else counts them only
+- (this function only write the FIXFIXonly Bitstream data)
+- returns: number of bits written or counted
+- input:
+- output:
+-
+-*****************************************************************************/
+-static int encodeLowDelaySbrGrid(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream,
+- const int transmitFreqs,
+- const UINT sbrSyntaxFlags) {
+- int payloadBits = 0;
+- int i;
+-
+- /* write FIXFIXonly Grid */
+- /* write frameClass [1 bit] for FIXFIXonly Grid */
+- payloadBits += FDKwriteBits(hBitStream, 1, SBR_CLA_BITS_LD);
+-
+- /* absolute Borders are fix: 0,X,X,X,nTimeSlots; so we dont have to transmit
+- * them */
+- /* only transmit the transient position! */
+- /* with this info (b1) we can reconstruct the Frame on Decoder side : */
+- /* border[0] = 0; border[1] = b1; border[2]=b1+2; border[3] = nrTimeSlots */
+-
+- /* use 3 or 4bits for transient border (border) */
+- if (sbrEnvData->hSbrBSGrid->numberTimeSlots == 8)
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->bs_abs_bord, 3);
+- else
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->bs_abs_bord, 4);
+-
+- if (transmitFreqs) {
+- /* write FreqRes grid */
+- for (i = 0; i < sbrEnvData->hSbrBSGrid->bs_num_env; i++) {
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->hSbrBSGrid->v_f[i],
+- SBR_RES_BITS);
+- }
+- }
+-
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: encodeSbrDtdf
+- description: writes bits that describes the direction of the envelopes of a
+-frame returns: number of bits written input: output:
+-
+-*****************************************************************************/
+-static INT encodeSbrDtdf(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream) {
+- INT i, payloadBits = 0, noOfNoiseEnvelopes;
+-
+- noOfNoiseEnvelopes = sbrEnvData->noOfEnvelopes > 1 ? 2 : 1;
+-
+- for (i = 0; i < sbrEnvData->noOfEnvelopes; ++i) {
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrEnvData->domain_vec[i], SBR_DIR_BITS);
+- }
+- for (i = 0; i < noOfNoiseEnvelopes; ++i) {
+- payloadBits +=
+- FDKwriteBits(hBitStream, sbrEnvData->domain_vec_noise[i], SBR_DIR_BITS);
+- }
+-
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: writeNoiseLevelData
+- description: writes bits corresponding to the noise-floor-level
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT writeNoiseLevelData(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream, INT coupling) {
+- INT j, i, payloadBits = 0;
+- INT nNoiseEnvelopes = sbrEnvData->noOfEnvelopes > 1 ? 2 : 1;
+-
+- for (i = 0; i < nNoiseEnvelopes; i++) {
+- switch (sbrEnvData->domain_vec_noise[i]) {
+- case FREQ:
+- if (coupling && sbrEnvData->balance) {
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData->sbr_noise_levels[i * sbrEnvData->noOfnoisebands],
+- sbrEnvData->si_sbr_start_noise_bits_balance);
+- } else {
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData->sbr_noise_levels[i * sbrEnvData->noOfnoisebands],
+- sbrEnvData->si_sbr_start_noise_bits);
+- }
+-
+- for (j = 1 + i * sbrEnvData->noOfnoisebands;
+- j < (sbrEnvData->noOfnoisebands * (1 + i)); j++) {
+- if (coupling) {
+- if (sbrEnvData->balance) {
+- /* coupling && balance */
+- payloadBits += FDKwriteBits(hBitStream,
+- sbrEnvData->hufftableNoiseBalanceFreqC
+- [sbrEnvData->sbr_noise_levels[j] +
+- CODE_BOOK_SCF_LAV_BALANCE11],
+- sbrEnvData->hufftableNoiseBalanceFreqL
+- [sbrEnvData->sbr_noise_levels[j] +
+- CODE_BOOK_SCF_LAV_BALANCE11]);
+- } else {
+- /* coupling && !balance */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData->hufftableNoiseLevelFreqC
+- [sbrEnvData->sbr_noise_levels[j] + CODE_BOOK_SCF_LAV11],
+- sbrEnvData->hufftableNoiseLevelFreqL
+- [sbrEnvData->sbr_noise_levels[j] + CODE_BOOK_SCF_LAV11]);
+- }
+- } else {
+- /* !coupling */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData
+- ->hufftableNoiseFreqC[sbrEnvData->sbr_noise_levels[j] +
+- CODE_BOOK_SCF_LAV11],
+- sbrEnvData
+- ->hufftableNoiseFreqL[sbrEnvData->sbr_noise_levels[j] +
+- CODE_BOOK_SCF_LAV11]);
+- }
+- }
+- break;
+-
+- case TIME:
+- for (j = i * sbrEnvData->noOfnoisebands;
+- j < (sbrEnvData->noOfnoisebands * (1 + i)); j++) {
+- if (coupling) {
+- if (sbrEnvData->balance) {
+- /* coupling && balance */
+- payloadBits += FDKwriteBits(hBitStream,
+- sbrEnvData->hufftableNoiseBalanceTimeC
+- [sbrEnvData->sbr_noise_levels[j] +
+- CODE_BOOK_SCF_LAV_BALANCE11],
+- sbrEnvData->hufftableNoiseBalanceTimeL
+- [sbrEnvData->sbr_noise_levels[j] +
+- CODE_BOOK_SCF_LAV_BALANCE11]);
+- } else {
+- /* coupling && !balance */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData->hufftableNoiseLevelTimeC
+- [sbrEnvData->sbr_noise_levels[j] + CODE_BOOK_SCF_LAV11],
+- sbrEnvData->hufftableNoiseLevelTimeL
+- [sbrEnvData->sbr_noise_levels[j] + CODE_BOOK_SCF_LAV11]);
+- }
+- } else {
+- /* !coupling */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData
+- ->hufftableNoiseLevelTimeC[sbrEnvData->sbr_noise_levels[j] +
+- CODE_BOOK_SCF_LAV11],
+- sbrEnvData
+- ->hufftableNoiseLevelTimeL[sbrEnvData->sbr_noise_levels[j] +
+- CODE_BOOK_SCF_LAV11]);
+- }
+- }
+- break;
+- }
+- }
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: writeEnvelopeData
+- description: writes bits corresponding to the envelope
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT writeEnvelopeData(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream, INT coupling) {
+- INT payloadBits = 0, j, i, delta;
+-
+- for (j = 0; j < sbrEnvData->noOfEnvelopes;
+- j++) { /* loop over all envelopes */
+- if (sbrEnvData->domain_vec[j] == FREQ) {
+- if (coupling && sbrEnvData->balance) {
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->ienvelope[j][0],
+- sbrEnvData->si_sbr_start_env_bits_balance);
+- } else {
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->ienvelope[j][0],
+- sbrEnvData->si_sbr_start_env_bits);
+- }
+- }
+-
+- for (i = 1 - sbrEnvData->domain_vec[j]; i < sbrEnvData->noScfBands[j];
+- i++) {
+- delta = sbrEnvData->ienvelope[j][i];
+- if (coupling && sbrEnvData->balance) {
+- FDK_ASSERT(fixp_abs(delta) <= sbrEnvData->codeBookScfLavBalance);
+- } else {
+- FDK_ASSERT(fixp_abs(delta) <= sbrEnvData->codeBookScfLav);
+- }
+- if (coupling) {
+- if (sbrEnvData->balance) {
+- if (sbrEnvData->domain_vec[j]) {
+- /* coupling && balance && TIME */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData
+- ->hufftableBalanceTimeC[delta +
+- sbrEnvData->codeBookScfLavBalance],
+- sbrEnvData
+- ->hufftableBalanceTimeL[delta +
+- sbrEnvData->codeBookScfLavBalance]);
+- } else {
+- /* coupling && balance && FREQ */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData
+- ->hufftableBalanceFreqC[delta +
+- sbrEnvData->codeBookScfLavBalance],
+- sbrEnvData
+- ->hufftableBalanceFreqL[delta +
+- sbrEnvData->codeBookScfLavBalance]);
+- }
+- } else {
+- if (sbrEnvData->domain_vec[j]) {
+- /* coupling && !balance && TIME */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData
+- ->hufftableLevelTimeC[delta + sbrEnvData->codeBookScfLav],
+- sbrEnvData
+- ->hufftableLevelTimeL[delta + sbrEnvData->codeBookScfLav]);
+- } else {
+- /* coupling && !balance && FREQ */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData
+- ->hufftableLevelFreqC[delta + sbrEnvData->codeBookScfLav],
+- sbrEnvData
+- ->hufftableLevelFreqL[delta + sbrEnvData->codeBookScfLav]);
+- }
+- }
+- } else {
+- if (sbrEnvData->domain_vec[j]) {
+- /* !coupling && TIME */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData->hufftableTimeC[delta + sbrEnvData->codeBookScfLav],
+- sbrEnvData->hufftableTimeL[delta + sbrEnvData->codeBookScfLav]);
+- } else {
+- /* !coupling && FREQ */
+- payloadBits += FDKwriteBits(
+- hBitStream,
+- sbrEnvData->hufftableFreqC[delta + sbrEnvData->codeBookScfLav],
+- sbrEnvData->hufftableFreqL[delta + sbrEnvData->codeBookScfLav]);
+- }
+- }
+- }
+- }
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: encodeExtendedData
+- description: writes bits corresponding to the extended data
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT encodeExtendedData(HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_FDK_BITSTREAM hBitStream) {
+- INT extDataSize;
+- INT payloadBits = 0;
+-
+- extDataSize = getSbrExtendedDataSize(hParametricStereo);
+-
+- if (extDataSize != 0) {
+- INT maxExtSize = (1 << SI_SBR_EXTENSION_SIZE_BITS) - 1;
+- INT writtenNoBits = 0; /* needed to byte align the extended data */
+-
+- payloadBits += FDKwriteBits(hBitStream, 1, SI_SBR_EXTENDED_DATA_BITS);
+- FDK_ASSERT(extDataSize <= SBR_EXTENDED_DATA_MAX_CNT);
+-
+- if (extDataSize < maxExtSize) {
+- payloadBits +=
+- FDKwriteBits(hBitStream, extDataSize, SI_SBR_EXTENSION_SIZE_BITS);
+- } else {
+- payloadBits +=
+- FDKwriteBits(hBitStream, maxExtSize, SI_SBR_EXTENSION_SIZE_BITS);
+- payloadBits += FDKwriteBits(hBitStream, extDataSize - maxExtSize,
+- SI_SBR_EXTENSION_ESC_COUNT_BITS);
+- }
+-
+- /* parametric coding signalled here? */
+- if (hParametricStereo) {
+- writtenNoBits += FDKwriteBits(hBitStream, EXTENSION_ID_PS_CODING,
+- SI_SBR_EXTENSION_ID_BITS);
+- writtenNoBits +=
+- FDKsbrEnc_PSEnc_WritePSData(hParametricStereo, hBitStream);
+- }
+-
+- payloadBits += writtenNoBits;
+-
+- /* byte alignment */
+- writtenNoBits = writtenNoBits % 8;
+- if (writtenNoBits)
+- payloadBits += FDKwriteBits(hBitStream, 0, (8 - writtenNoBits));
+- } else {
+- payloadBits += FDKwriteBits(hBitStream, 0, SI_SBR_EXTENDED_DATA_BITS);
+- }
+-
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: writeSyntheticCodingData
+- description: writes bits corresponding to the "synthetic-coding"-extension
+- returns: number of bits written
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT writeSyntheticCodingData(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_FDK_BITSTREAM hBitStream)
+-
+-{
+- INT i;
+- INT payloadBits = 0;
+-
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->addHarmonicFlag, 1);
+-
+- if (sbrEnvData->addHarmonicFlag) {
+- for (i = 0; i < sbrEnvData->noHarmonics; i++) {
+- payloadBits += FDKwriteBits(hBitStream, sbrEnvData->addHarmonic[i], 1);
+- }
+- }
+-
+- return payloadBits;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: getSbrExtendedDataSize
+- description: counts the number of bits needed for encoding the
+- extended data (including extension id)
+-
+- returns: number of bits needed for the extended data
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT getSbrExtendedDataSize(HANDLE_PARAMETRIC_STEREO hParametricStereo) {
+- INT extDataBits = 0;
+-
+- /* add your new extended data counting methods here */
+-
+- /*
+- no extended data
+- */
+-
+- if (hParametricStereo) {
+- /* PS extended data */
+- extDataBits += SI_SBR_EXTENSION_ID_BITS;
+- extDataBits += FDKsbrEnc_PSEnc_WritePSData(hParametricStereo, NULL);
+- }
+-
+- return (extDataBits + 7) >> 3;
+-}
+diff --git a/libSBRenc/src/bit_sbr.h b/libSBRenc/src/bit_sbr.h
+deleted file mode 100644
+index e90f52c..0000000
+--- a/libSBRenc/src/bit_sbr.h
++++ /dev/null
+@@ -1,267 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief SBR bit writing $Revision: 92790 $
+-*/
+-#ifndef BIT_SBR_H
+-#define BIT_SBR_H
+-
+-#include "sbr_def.h"
+-#include "cmondata.h"
+-#include "fram_gen.h"
+-
+-struct SBR_ENV_DATA;
+-
+-struct SBR_BITSTREAM_DATA {
+- INT TotalBits;
+- INT PayloadBits;
+- INT FillBits;
+- INT HeaderActive;
+- INT HeaderActiveDelay; /**< sbr payload and its header is delayed depending on
+- encoder configuration*/
+- INT NrSendHeaderData; /**< input from commandline */
+- INT CountSendHeaderData; /**< modulo count. If < 0 then no counting is done
+- (no SBR headers) */
+- INT rightBorderFIX; /**< force VARFIX or FIXFIX frames */
+-};
+-
+-typedef struct SBR_BITSTREAM_DATA *HANDLE_SBR_BITSTREAM_DATA;
+-
+-struct SBR_HEADER_DATA {
+- AMP_RES sbr_amp_res;
+- INT sbr_start_frequency;
+- INT sbr_stop_frequency;
+- INT sbr_xover_band;
+- INT sbr_noise_bands;
+- INT sbr_data_extra;
+- INT header_extra_1;
+- INT header_extra_2;
+- INT sbr_lc_stereo_mode;
+- INT sbr_limiter_bands;
+- INT sbr_limiter_gains;
+- INT sbr_interpol_freq;
+- INT sbr_smoothing_length;
+- INT alterScale;
+- INT freqScale;
+-
+- /*
+- element of channelpairelement
+- */
+- INT coupling;
+- INT prev_coupling;
+-
+- /*
+- element of singlechannelelement
+- */
+-};
+-typedef struct SBR_HEADER_DATA *HANDLE_SBR_HEADER_DATA;
+-
+-struct SBR_ENV_DATA {
+- INT sbr_xpos_ctrl;
+- FREQ_RES freq_res_fixfix[2];
+- UCHAR fResTransIsLow;
+-
+- INVF_MODE sbr_invf_mode;
+- INVF_MODE sbr_invf_mode_vec[MAX_NUM_NOISE_VALUES];
+-
+- XPOS_MODE sbr_xpos_mode;
+-
+- INT ienvelope[MAX_ENVELOPES][MAX_FREQ_COEFFS];
+-
+- INT codeBookScfLavBalance;
+- INT codeBookScfLav;
+- const INT *hufftableTimeC;
+- const INT *hufftableFreqC;
+- const UCHAR *hufftableTimeL;
+- const UCHAR *hufftableFreqL;
+-
+- const INT *hufftableLevelTimeC;
+- const INT *hufftableBalanceTimeC;
+- const INT *hufftableLevelFreqC;
+- const INT *hufftableBalanceFreqC;
+- const UCHAR *hufftableLevelTimeL;
+- const UCHAR *hufftableBalanceTimeL;
+- const UCHAR *hufftableLevelFreqL;
+- const UCHAR *hufftableBalanceFreqL;
+-
+- const UCHAR *hufftableNoiseTimeL;
+- const INT *hufftableNoiseTimeC;
+- const UCHAR *hufftableNoiseFreqL;
+- const INT *hufftableNoiseFreqC;
+-
+- const UCHAR *hufftableNoiseLevelTimeL;
+- const INT *hufftableNoiseLevelTimeC;
+- const UCHAR *hufftableNoiseBalanceTimeL;
+- const INT *hufftableNoiseBalanceTimeC;
+- const UCHAR *hufftableNoiseLevelFreqL;
+- const INT *hufftableNoiseLevelFreqC;
+- const UCHAR *hufftableNoiseBalanceFreqL;
+- const INT *hufftableNoiseBalanceFreqC;
+-
+- HANDLE_SBR_GRID hSbrBSGrid;
+-
+- INT noHarmonics;
+- INT addHarmonicFlag;
+- UCHAR addHarmonic[MAX_FREQ_COEFFS];
+-
+- /* calculated helper vars */
+- INT si_sbr_start_env_bits_balance;
+- INT si_sbr_start_env_bits;
+- INT si_sbr_start_noise_bits_balance;
+- INT si_sbr_start_noise_bits;
+-
+- INT noOfEnvelopes;
+- INT noScfBands[MAX_ENVELOPES];
+- INT domain_vec[MAX_ENVELOPES];
+- INT domain_vec_noise[MAX_ENVELOPES];
+- SCHAR sbr_noise_levels[MAX_FREQ_COEFFS];
+- INT noOfnoisebands;
+-
+- INT balance;
+- AMP_RES init_sbr_amp_res;
+- AMP_RES currentAmpResFF;
+- FIXP_DBL
+- ton_HF[SBR_GLOBAL_TONALITY_VALUES]; /* tonality is scaled by
+- 2^19/0.524288f (fract part of
+- RELAXATION) */
+- FIXP_DBL global_tonality;
+-
+- /* extended data */
+- INT extended_data;
+- INT extension_size;
+- INT extension_id;
+- UCHAR extended_data_buffer[SBR_EXTENDED_DATA_MAX_CNT];
+-
+- UCHAR ldGrid;
+-};
+-typedef struct SBR_ENV_DATA *HANDLE_SBR_ENV_DATA;
+-
+-INT FDKsbrEnc_WriteEnvSingleChannelElement(
+- struct SBR_HEADER_DATA *sbrHeaderData,
+- struct T_PARAMETRIC_STEREO *hParametricStereo,
+- struct SBR_BITSTREAM_DATA *sbrBitstreamData,
+- struct SBR_ENV_DATA *sbrEnvData, struct COMMON_DATA *cmonData,
+- UINT sbrSyntaxFlags);
+-
+-INT FDKsbrEnc_WriteEnvChannelPairElement(
+- struct SBR_HEADER_DATA *sbrHeaderData,
+- struct T_PARAMETRIC_STEREO *hParametricStereo,
+- struct SBR_BITSTREAM_DATA *sbrBitstreamData,
+- struct SBR_ENV_DATA *sbrEnvDataLeft, struct SBR_ENV_DATA *sbrEnvDataRight,
+- struct COMMON_DATA *cmonData, UINT sbrSyntaxFlags);
+-
+-INT FDKsbrEnc_CountSbrChannelPairElement(
+- struct SBR_HEADER_DATA *sbrHeaderData,
+- struct T_PARAMETRIC_STEREO *hParametricStereo,
+- struct SBR_BITSTREAM_DATA *sbrBitstreamData,
+- struct SBR_ENV_DATA *sbrEnvDataLeft, struct SBR_ENV_DATA *sbrEnvDataRight,
+- struct COMMON_DATA *cmonData, UINT sbrSyntaxFlags);
+-
+-/* debugging and tuning functions */
+-
+-/*#define SBR_ENV_STATISTICS */
+-
+-/*#define SBR_PAYLOAD_MONITOR*/
+-
+-#endif
+diff --git a/libSBRenc/src/cmondata.h b/libSBRenc/src/cmondata.h
+deleted file mode 100644
+index 0779b4d..0000000
+--- a/libSBRenc/src/cmondata.h
++++ /dev/null
+@@ -1,127 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Core Coder's and SBR's shared data structure definition $Revision:
+- 92790 $
+-*/
+-#ifndef CMONDATA_H
+-#define CMONDATA_H
+-
+-#include "FDK_bitstream.h"
+-
+-struct COMMON_DATA {
+- INT sbrHdrBits; /**< number of SBR header bits */
+- INT sbrDataBits; /**< number of SBR data bits */
+- INT sbrFillBits; /**< number of SBR fill bits */
+- FDK_BITSTREAM sbrBitbuf; /**< the SBR data bitbuffer */
+- FDK_BITSTREAM tmpWriteBitbuf; /**< helper var for writing header*/
+- INT xOverFreq; /**< the SBR crossover frequency */
+- INT dynBwEnabled; /**< indicates if dynamic bandwidth is enabled */
+- INT sbrNumChannels; /**< number of channels (meaning mono or stereo) */
+- INT dynXOverFreqEnc; /**< encoder dynamic crossover frequency */
+-};
+-
+-typedef struct COMMON_DATA *HANDLE_COMMON_DATA;
+-
+-#endif
+diff --git a/libSBRenc/src/code_env.cpp b/libSBRenc/src/code_env.cpp
+deleted file mode 100644
+index fb0f6a4..0000000
+--- a/libSBRenc/src/code_env.cpp
++++ /dev/null
+@@ -1,602 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "code_env.h"
+-#include "sbrenc_rom.h"
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_InitSbrHuffmanTables
+- description: initializes Huffman Tables dependent on chosen amp_res
+- returns: error handle
+- input:
+- output:
+-
+-*****************************************************************************/
+-INT FDKsbrEnc_InitSbrHuffmanTables(HANDLE_SBR_ENV_DATA sbrEnvData,
+- HANDLE_SBR_CODE_ENVELOPE henv,
+- HANDLE_SBR_CODE_ENVELOPE hnoise,
+- AMP_RES amp_res) {
+- if ((!henv) || (!hnoise) || (!sbrEnvData)) return (1); /* not init. */
+-
+- sbrEnvData->init_sbr_amp_res = amp_res;
+-
+- switch (amp_res) {
+- case SBR_AMP_RES_3_0:
+- /*envelope data*/
+-
+- /*Level/Pan - coding */
+- sbrEnvData->hufftableLevelTimeC = v_Huff_envelopeLevelC11T;
+- sbrEnvData->hufftableLevelTimeL = v_Huff_envelopeLevelL11T;
+- sbrEnvData->hufftableBalanceTimeC = bookSbrEnvBalanceC11T;
+- sbrEnvData->hufftableBalanceTimeL = bookSbrEnvBalanceL11T;
+-
+- sbrEnvData->hufftableLevelFreqC = v_Huff_envelopeLevelC11F;
+- sbrEnvData->hufftableLevelFreqL = v_Huff_envelopeLevelL11F;
+- sbrEnvData->hufftableBalanceFreqC = bookSbrEnvBalanceC11F;
+- sbrEnvData->hufftableBalanceFreqL = bookSbrEnvBalanceL11F;
+-
+- /*Right/Left - coding */
+- sbrEnvData->hufftableTimeC = v_Huff_envelopeLevelC11T;
+- sbrEnvData->hufftableTimeL = v_Huff_envelopeLevelL11T;
+- sbrEnvData->hufftableFreqC = v_Huff_envelopeLevelC11F;
+- sbrEnvData->hufftableFreqL = v_Huff_envelopeLevelL11F;
+-
+- sbrEnvData->codeBookScfLavBalance = CODE_BOOK_SCF_LAV_BALANCE11;
+- sbrEnvData->codeBookScfLav = CODE_BOOK_SCF_LAV11;
+-
+- sbrEnvData->si_sbr_start_env_bits = SI_SBR_START_ENV_BITS_AMP_RES_3_0;
+- sbrEnvData->si_sbr_start_env_bits_balance =
+- SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_3_0;
+- break;
+-
+- case SBR_AMP_RES_1_5:
+- /*envelope data*/
+-
+- /*Level/Pan - coding */
+- sbrEnvData->hufftableLevelTimeC = v_Huff_envelopeLevelC10T;
+- sbrEnvData->hufftableLevelTimeL = v_Huff_envelopeLevelL10T;
+- sbrEnvData->hufftableBalanceTimeC = bookSbrEnvBalanceC10T;
+- sbrEnvData->hufftableBalanceTimeL = bookSbrEnvBalanceL10T;
+-
+- sbrEnvData->hufftableLevelFreqC = v_Huff_envelopeLevelC10F;
+- sbrEnvData->hufftableLevelFreqL = v_Huff_envelopeLevelL10F;
+- sbrEnvData->hufftableBalanceFreqC = bookSbrEnvBalanceC10F;
+- sbrEnvData->hufftableBalanceFreqL = bookSbrEnvBalanceL10F;
+-
+- /*Right/Left - coding */
+- sbrEnvData->hufftableTimeC = v_Huff_envelopeLevelC10T;
+- sbrEnvData->hufftableTimeL = v_Huff_envelopeLevelL10T;
+- sbrEnvData->hufftableFreqC = v_Huff_envelopeLevelC10F;
+- sbrEnvData->hufftableFreqL = v_Huff_envelopeLevelL10F;
+-
+- sbrEnvData->codeBookScfLavBalance = CODE_BOOK_SCF_LAV_BALANCE10;
+- sbrEnvData->codeBookScfLav = CODE_BOOK_SCF_LAV10;
+-
+- sbrEnvData->si_sbr_start_env_bits = SI_SBR_START_ENV_BITS_AMP_RES_1_5;
+- sbrEnvData->si_sbr_start_env_bits_balance =
+- SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_1_5;
+- break;
+-
+- default:
+- return (1); /* undefined amp_res mode */
+- }
+-
+- /* these are common to both amp_res values */
+- /*Noise data*/
+-
+- /*Level/Pan - coding */
+- sbrEnvData->hufftableNoiseLevelTimeC = v_Huff_NoiseLevelC11T;
+- sbrEnvData->hufftableNoiseLevelTimeL = v_Huff_NoiseLevelL11T;
+- sbrEnvData->hufftableNoiseBalanceTimeC = bookSbrNoiseBalanceC11T;
+- sbrEnvData->hufftableNoiseBalanceTimeL = bookSbrNoiseBalanceL11T;
+-
+- sbrEnvData->hufftableNoiseLevelFreqC = v_Huff_envelopeLevelC11F;
+- sbrEnvData->hufftableNoiseLevelFreqL = v_Huff_envelopeLevelL11F;
+- sbrEnvData->hufftableNoiseBalanceFreqC = bookSbrEnvBalanceC11F;
+- sbrEnvData->hufftableNoiseBalanceFreqL = bookSbrEnvBalanceL11F;
+-
+- /*Right/Left - coding */
+- sbrEnvData->hufftableNoiseTimeC = v_Huff_NoiseLevelC11T;
+- sbrEnvData->hufftableNoiseTimeL = v_Huff_NoiseLevelL11T;
+- sbrEnvData->hufftableNoiseFreqC = v_Huff_envelopeLevelC11F;
+- sbrEnvData->hufftableNoiseFreqL = v_Huff_envelopeLevelL11F;
+-
+- sbrEnvData->si_sbr_start_noise_bits = SI_SBR_START_NOISE_BITS_AMP_RES_3_0;
+- sbrEnvData->si_sbr_start_noise_bits_balance =
+- SI_SBR_START_NOISE_BITS_BALANCE_AMP_RES_3_0;
+-
+- /* init envelope tables and codebooks */
+- henv->codeBookScfLavBalanceTime = sbrEnvData->codeBookScfLavBalance;
+- henv->codeBookScfLavBalanceFreq = sbrEnvData->codeBookScfLavBalance;
+- henv->codeBookScfLavLevelTime = sbrEnvData->codeBookScfLav;
+- henv->codeBookScfLavLevelFreq = sbrEnvData->codeBookScfLav;
+- henv->codeBookScfLavTime = sbrEnvData->codeBookScfLav;
+- henv->codeBookScfLavFreq = sbrEnvData->codeBookScfLav;
+-
+- henv->hufftableLevelTimeL = sbrEnvData->hufftableLevelTimeL;
+- henv->hufftableBalanceTimeL = sbrEnvData->hufftableBalanceTimeL;
+- henv->hufftableTimeL = sbrEnvData->hufftableTimeL;
+- henv->hufftableLevelFreqL = sbrEnvData->hufftableLevelFreqL;
+- henv->hufftableBalanceFreqL = sbrEnvData->hufftableBalanceFreqL;
+- henv->hufftableFreqL = sbrEnvData->hufftableFreqL;
+-
+- henv->codeBookScfLavFreq = sbrEnvData->codeBookScfLav;
+- henv->codeBookScfLavTime = sbrEnvData->codeBookScfLav;
+-
+- henv->start_bits = sbrEnvData->si_sbr_start_env_bits;
+- henv->start_bits_balance = sbrEnvData->si_sbr_start_env_bits_balance;
+-
+- /* init noise tables and codebooks */
+-
+- hnoise->codeBookScfLavBalanceTime = CODE_BOOK_SCF_LAV_BALANCE11;
+- hnoise->codeBookScfLavBalanceFreq = CODE_BOOK_SCF_LAV_BALANCE11;
+- hnoise->codeBookScfLavLevelTime = CODE_BOOK_SCF_LAV11;
+- hnoise->codeBookScfLavLevelFreq = CODE_BOOK_SCF_LAV11;
+- hnoise->codeBookScfLavTime = CODE_BOOK_SCF_LAV11;
+- hnoise->codeBookScfLavFreq = CODE_BOOK_SCF_LAV11;
+-
+- hnoise->hufftableLevelTimeL = sbrEnvData->hufftableNoiseLevelTimeL;
+- hnoise->hufftableBalanceTimeL = sbrEnvData->hufftableNoiseBalanceTimeL;
+- hnoise->hufftableTimeL = sbrEnvData->hufftableNoiseTimeL;
+- hnoise->hufftableLevelFreqL = sbrEnvData->hufftableNoiseLevelFreqL;
+- hnoise->hufftableBalanceFreqL = sbrEnvData->hufftableNoiseBalanceFreqL;
+- hnoise->hufftableFreqL = sbrEnvData->hufftableNoiseFreqL;
+-
+- hnoise->start_bits = sbrEnvData->si_sbr_start_noise_bits;
+- hnoise->start_bits_balance = sbrEnvData->si_sbr_start_noise_bits_balance;
+-
+- /* No delta coding in time from the previous frame due to 1.5dB FIx-FIX rule
+- */
+- henv->upDate = 0;
+- hnoise->upDate = 0;
+- return (0);
+-}
+-
+-/*******************************************************************************
+- Functionname: indexLow2High
+- *******************************************************************************
+-
+- Description: Nice small patch-functions in order to cope with non-factor-2
+- ratios between high-res and low-res
+-
+- Arguments: INT offset, INT index, FREQ_RES res
+-
+- Return: INT
+-
+-*******************************************************************************/
+-static INT indexLow2High(INT offset, INT index, FREQ_RES res) {
+- if (res == FREQ_RES_LOW) {
+- if (offset >= 0) {
+- if (index < offset)
+- return (index);
+- else
+- return (2 * index - offset);
+- } else {
+- offset = -offset;
+- if (index < offset)
+- return (2 * index + index);
+- else
+- return (2 * index + offset);
+- }
+- } else
+- return (index);
+-}
+-
+-/*******************************************************************************
+- Functionname: mapLowResEnergyVal
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: INT currVal,INT* prevData, INT offset, INT index, FREQ_RES res
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void mapLowResEnergyVal(SCHAR currVal, SCHAR *prevData, INT offset,
+- INT index, FREQ_RES res) {
+- if (res == FREQ_RES_LOW) {
+- if (offset >= 0) {
+- if (index < offset)
+- prevData[index] = currVal;
+- else {
+- prevData[2 * index - offset] = currVal;
+- prevData[2 * index + 1 - offset] = currVal;
+- }
+- } else {
+- offset = -offset;
+- if (index < offset) {
+- prevData[3 * index] = currVal;
+- prevData[3 * index + 1] = currVal;
+- prevData[3 * index + 2] = currVal;
+- } else {
+- prevData[2 * index + offset] = currVal;
+- prevData[2 * index + 1 + offset] = currVal;
+- }
+- }
+- } else
+- prevData[index] = currVal;
+-}
+-
+-/*******************************************************************************
+- Functionname: computeBits
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: INT delta,
+- INT codeBookScfLavLevel,
+- INT codeBookScfLavBalance,
+- const UCHAR * hufftableLevel,
+- const UCHAR * hufftableBalance, INT coupling, INT channel)
+-
+- Return: INT
+-
+-*******************************************************************************/
+-static INT computeBits(SCHAR *delta, INT codeBookScfLavLevel,
+- INT codeBookScfLavBalance, const UCHAR *hufftableLevel,
+- const UCHAR *hufftableBalance, INT coupling,
+- INT channel) {
+- INT index;
+- INT delta_bits = 0;
+-
+- if (coupling) {
+- if (channel == 1) {
+- if (*delta < 0)
+- index = fixMax(*delta, -codeBookScfLavBalance);
+- else
+- index = fixMin(*delta, codeBookScfLavBalance);
+-
+- if (index != *delta) {
+- *delta = index;
+- return (10000);
+- }
+-
+- delta_bits = hufftableBalance[index + codeBookScfLavBalance];
+- } else {
+- if (*delta < 0)
+- index = fixMax(*delta, -codeBookScfLavLevel);
+- else
+- index = fixMin(*delta, codeBookScfLavLevel);
+-
+- if (index != *delta) {
+- *delta = index;
+- return (10000);
+- }
+- delta_bits = hufftableLevel[index + codeBookScfLavLevel];
+- }
+- } else {
+- if (*delta < 0)
+- index = fixMax(*delta, -codeBookScfLavLevel);
+- else
+- index = fixMin(*delta, codeBookScfLavLevel);
+-
+- if (index != *delta) {
+- *delta = index;
+- return (10000);
+- }
+- delta_bits = hufftableLevel[index + codeBookScfLavLevel];
+- }
+-
+- return (delta_bits);
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_codeEnvelope
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: INT *sfb_nrg,
+- const FREQ_RES *freq_res,
+- SBR_CODE_ENVELOPE * h_sbrCodeEnvelope,
+- INT *directionVec, INT scalable, INT nEnvelopes, INT channel,
+- INT headerActive)
+-
+- Return: none
+- h_sbrCodeEnvelope->sfb_nrg_prev is modified !
+- sfb_nrg is modified
+- h_sbrCodeEnvelope->update is modfied !
+- *directionVec is modified
+-
+-*******************************************************************************/
+-void FDKsbrEnc_codeEnvelope(SCHAR *sfb_nrg, const FREQ_RES *freq_res,
+- SBR_CODE_ENVELOPE *h_sbrCodeEnvelope,
+- INT *directionVec, INT coupling, INT nEnvelopes,
+- INT channel, INT headerActive) {
+- INT i, no_of_bands, band;
+- FIXP_DBL tmp1, tmp2, tmp3, dF_edge_1stEnv;
+- SCHAR *ptr_nrg;
+-
+- INT codeBookScfLavLevelTime;
+- INT codeBookScfLavLevelFreq;
+- INT codeBookScfLavBalanceTime;
+- INT codeBookScfLavBalanceFreq;
+- const UCHAR *hufftableLevelTimeL;
+- const UCHAR *hufftableBalanceTimeL;
+- const UCHAR *hufftableLevelFreqL;
+- const UCHAR *hufftableBalanceFreqL;
+-
+- INT offset = h_sbrCodeEnvelope->offset;
+- INT envDataTableCompFactor;
+-
+- INT delta_F_bits = 0, delta_T_bits = 0;
+- INT use_dT;
+-
+- SCHAR delta_F[MAX_FREQ_COEFFS];
+- SCHAR delta_T[MAX_FREQ_COEFFS];
+- SCHAR last_nrg, curr_nrg;
+-
+- tmp1 = FL2FXCONST_DBL(0.5f) >> (DFRACT_BITS - 16 - 1);
+- tmp2 = h_sbrCodeEnvelope->dF_edge_1stEnv >> (DFRACT_BITS - 16);
+- tmp3 = (FIXP_DBL)fMult(h_sbrCodeEnvelope->dF_edge_incr,
+- ((FIXP_DBL)h_sbrCodeEnvelope->dF_edge_incr_fac) << 15);
+-
+- dF_edge_1stEnv = tmp1 + tmp2 + tmp3;
+-
+- if (coupling) {
+- codeBookScfLavLevelTime = h_sbrCodeEnvelope->codeBookScfLavLevelTime;
+- codeBookScfLavLevelFreq = h_sbrCodeEnvelope->codeBookScfLavLevelFreq;
+- codeBookScfLavBalanceTime = h_sbrCodeEnvelope->codeBookScfLavBalanceTime;
+- codeBookScfLavBalanceFreq = h_sbrCodeEnvelope->codeBookScfLavBalanceFreq;
+- hufftableLevelTimeL = h_sbrCodeEnvelope->hufftableLevelTimeL;
+- hufftableBalanceTimeL = h_sbrCodeEnvelope->hufftableBalanceTimeL;
+- hufftableLevelFreqL = h_sbrCodeEnvelope->hufftableLevelFreqL;
+- hufftableBalanceFreqL = h_sbrCodeEnvelope->hufftableBalanceFreqL;
+- } else {
+- codeBookScfLavLevelTime = h_sbrCodeEnvelope->codeBookScfLavTime;
+- codeBookScfLavLevelFreq = h_sbrCodeEnvelope->codeBookScfLavFreq;
+- codeBookScfLavBalanceTime = h_sbrCodeEnvelope->codeBookScfLavTime;
+- codeBookScfLavBalanceFreq = h_sbrCodeEnvelope->codeBookScfLavFreq;
+- hufftableLevelTimeL = h_sbrCodeEnvelope->hufftableTimeL;
+- hufftableBalanceTimeL = h_sbrCodeEnvelope->hufftableTimeL;
+- hufftableLevelFreqL = h_sbrCodeEnvelope->hufftableFreqL;
+- hufftableBalanceFreqL = h_sbrCodeEnvelope->hufftableFreqL;
+- }
+-
+- if (coupling == 1 && channel == 1)
+- envDataTableCompFactor =
+- 1; /*should be one when the new huffman-tables are ready*/
+- else
+- envDataTableCompFactor = 0;
+-
+- if (h_sbrCodeEnvelope->deltaTAcrossFrames == 0) h_sbrCodeEnvelope->upDate = 0;
+-
+- /* no delta coding in time in case of a header */
+- if (headerActive) h_sbrCodeEnvelope->upDate = 0;
+-
+- for (i = 0; i < nEnvelopes; i++) {
+- if (freq_res[i] == FREQ_RES_HIGH)
+- no_of_bands = h_sbrCodeEnvelope->nSfb[FREQ_RES_HIGH];
+- else
+- no_of_bands = h_sbrCodeEnvelope->nSfb[FREQ_RES_LOW];
+-
+- ptr_nrg = sfb_nrg;
+- curr_nrg = *ptr_nrg;
+-
+- delta_F[0] = curr_nrg >> envDataTableCompFactor;
+-
+- if (coupling && channel == 1)
+- delta_F_bits = h_sbrCodeEnvelope->start_bits_balance;
+- else
+- delta_F_bits = h_sbrCodeEnvelope->start_bits;
+-
+- if (h_sbrCodeEnvelope->upDate != 0) {
+- delta_T[0] = (curr_nrg - h_sbrCodeEnvelope->sfb_nrg_prev[0]) >>
+- envDataTableCompFactor;
+-
+- delta_T_bits = computeBits(&delta_T[0], codeBookScfLavLevelTime,
+- codeBookScfLavBalanceTime, hufftableLevelTimeL,
+- hufftableBalanceTimeL, coupling, channel);
+- }
+-
+- mapLowResEnergyVal(curr_nrg, h_sbrCodeEnvelope->sfb_nrg_prev, offset, 0,
+- freq_res[i]);
+-
+- /* ensure that nrg difference is not higher than codeBookScfLavXXXFreq */
+- if (coupling && channel == 1) {
+- for (band = no_of_bands - 1; band > 0; band--) {
+- if (ptr_nrg[band] - ptr_nrg[band - 1] > codeBookScfLavBalanceFreq) {
+- ptr_nrg[band - 1] = ptr_nrg[band] - codeBookScfLavBalanceFreq;
+- }
+- }
+- for (band = 1; band < no_of_bands; band++) {
+- if (ptr_nrg[band - 1] - ptr_nrg[band] > codeBookScfLavBalanceFreq) {
+- ptr_nrg[band] = ptr_nrg[band - 1] - codeBookScfLavBalanceFreq;
+- }
+- }
+- } else {
+- for (band = no_of_bands - 1; band > 0; band--) {
+- if (ptr_nrg[band] - ptr_nrg[band - 1] > codeBookScfLavLevelFreq) {
+- ptr_nrg[band - 1] = ptr_nrg[band] - codeBookScfLavLevelFreq;
+- }
+- }
+- for (band = 1; band < no_of_bands; band++) {
+- if (ptr_nrg[band - 1] - ptr_nrg[band] > codeBookScfLavLevelFreq) {
+- ptr_nrg[band] = ptr_nrg[band - 1] - codeBookScfLavLevelFreq;
+- }
+- }
+- }
+-
+- /* Coding loop*/
+- for (band = 1; band < no_of_bands; band++) {
+- last_nrg = (*ptr_nrg);
+- ptr_nrg++;
+- curr_nrg = (*ptr_nrg);
+-
+- delta_F[band] = (curr_nrg - last_nrg) >> envDataTableCompFactor;
+-
+- delta_F_bits += computeBits(
+- &delta_F[band], codeBookScfLavLevelFreq, codeBookScfLavBalanceFreq,
+- hufftableLevelFreqL, hufftableBalanceFreqL, coupling, channel);
+-
+- if (h_sbrCodeEnvelope->upDate != 0) {
+- delta_T[band] =
+- curr_nrg -
+- h_sbrCodeEnvelope
+- ->sfb_nrg_prev[indexLow2High(offset, band, freq_res[i])];
+- delta_T[band] = delta_T[band] >> envDataTableCompFactor;
+- }
+-
+- mapLowResEnergyVal(curr_nrg, h_sbrCodeEnvelope->sfb_nrg_prev, offset,
+- band, freq_res[i]);
+-
+- if (h_sbrCodeEnvelope->upDate != 0) {
+- delta_T_bits += computeBits(
+- &delta_T[band], codeBookScfLavLevelTime, codeBookScfLavBalanceTime,
+- hufftableLevelTimeL, hufftableBalanceTimeL, coupling, channel);
+- }
+- }
+-
+- /* Replace sfb_nrg with deltacoded samples and set flag */
+- if (i == 0) {
+- INT tmp_bits;
+- tmp_bits = (((delta_T_bits * dF_edge_1stEnv) >> (DFRACT_BITS - 18)) +
+- (FIXP_DBL)1) >>
+- 1;
+- use_dT = (h_sbrCodeEnvelope->upDate != 0 && (delta_F_bits > tmp_bits));
+- } else
+- use_dT = (delta_T_bits < delta_F_bits && h_sbrCodeEnvelope->upDate != 0);
+-
+- if (use_dT) {
+- directionVec[i] = TIME;
+- FDKmemcpy(sfb_nrg, delta_T, no_of_bands * sizeof(SCHAR));
+- } else {
+- h_sbrCodeEnvelope->upDate = 0;
+- directionVec[i] = FREQ;
+- FDKmemcpy(sfb_nrg, delta_F, no_of_bands * sizeof(SCHAR));
+- }
+- sfb_nrg += no_of_bands;
+- h_sbrCodeEnvelope->upDate = 1;
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_InitSbrCodeEnvelope
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-INT FDKsbrEnc_InitSbrCodeEnvelope(HANDLE_SBR_CODE_ENVELOPE h_sbrCodeEnvelope,
+- INT *nSfb, INT deltaTAcrossFrames,
+- FIXP_DBL dF_edge_1stEnv,
+- FIXP_DBL dF_edge_incr) {
+- FDKmemclear(h_sbrCodeEnvelope, sizeof(SBR_CODE_ENVELOPE));
+-
+- h_sbrCodeEnvelope->deltaTAcrossFrames = deltaTAcrossFrames;
+- h_sbrCodeEnvelope->dF_edge_1stEnv = dF_edge_1stEnv;
+- h_sbrCodeEnvelope->dF_edge_incr = dF_edge_incr;
+- h_sbrCodeEnvelope->dF_edge_incr_fac = 0;
+- h_sbrCodeEnvelope->upDate = 0;
+- h_sbrCodeEnvelope->nSfb[FREQ_RES_LOW] = nSfb[FREQ_RES_LOW];
+- h_sbrCodeEnvelope->nSfb[FREQ_RES_HIGH] = nSfb[FREQ_RES_HIGH];
+- h_sbrCodeEnvelope->offset = 2 * h_sbrCodeEnvelope->nSfb[FREQ_RES_LOW] -
+- h_sbrCodeEnvelope->nSfb[FREQ_RES_HIGH];
+-
+- return (0);
+-}
+diff --git a/libSBRenc/src/code_env.h b/libSBRenc/src/code_env.h
+deleted file mode 100644
+index 673a783..0000000
+--- a/libSBRenc/src/code_env.h
++++ /dev/null
+@@ -1,161 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief DPCM Envelope coding $Revision: 92790 $
+-*/
+-
+-#ifndef CODE_ENV_H
+-#define CODE_ENV_H
+-
+-#include "sbr_def.h"
+-#include "bit_sbr.h"
+-#include "fram_gen.h"
+-
+-typedef struct {
+- INT offset;
+- INT upDate;
+- INT nSfb[2];
+- SCHAR sfb_nrg_prev[MAX_FREQ_COEFFS];
+- INT deltaTAcrossFrames;
+- FIXP_DBL dF_edge_1stEnv;
+- FIXP_DBL dF_edge_incr;
+- INT dF_edge_incr_fac;
+-
+- INT codeBookScfLavTime;
+- INT codeBookScfLavFreq;
+-
+- INT codeBookScfLavLevelTime;
+- INT codeBookScfLavLevelFreq;
+- INT codeBookScfLavBalanceTime;
+- INT codeBookScfLavBalanceFreq;
+-
+- INT start_bits;
+- INT start_bits_balance;
+-
+- const UCHAR *hufftableTimeL;
+- const UCHAR *hufftableFreqL;
+-
+- const UCHAR *hufftableLevelTimeL;
+- const UCHAR *hufftableBalanceTimeL;
+- const UCHAR *hufftableLevelFreqL;
+- const UCHAR *hufftableBalanceFreqL;
+-} SBR_CODE_ENVELOPE;
+-typedef SBR_CODE_ENVELOPE *HANDLE_SBR_CODE_ENVELOPE;
+-
+-void FDKsbrEnc_codeEnvelope(SCHAR *sfb_nrg, const FREQ_RES *freq_res,
+- SBR_CODE_ENVELOPE *h_sbrCodeEnvelope,
+- INT *directionVec, INT coupling, INT nEnvelopes,
+- INT channel, INT headerActive);
+-
+-INT FDKsbrEnc_InitSbrCodeEnvelope(HANDLE_SBR_CODE_ENVELOPE h_sbrCodeEnvelope,
+- INT *nSfb, INT deltaTAcrossFrames,
+- FIXP_DBL dF_edge_1stEnv,
+- FIXP_DBL dF_edge_incr);
+-
+-INT FDKsbrEnc_InitSbrHuffmanTables(struct SBR_ENV_DATA *sbrEnvData,
+- HANDLE_SBR_CODE_ENVELOPE henv,
+- HANDLE_SBR_CODE_ENVELOPE hnoise,
+- AMP_RES amp_res);
+-
+-#endif
+diff --git a/libSBRenc/src/env_bit.cpp b/libSBRenc/src/env_bit.cpp
+deleted file mode 100644
+index 41812ac..0000000
+--- a/libSBRenc/src/env_bit.cpp
++++ /dev/null
+@@ -1,257 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Remaining SBR Bit Writing Routines
+-*/
+-
+-#include "env_bit.h"
+-#include "cmondata.h"
+-
+-#ifndef min
+-#define min(a, b) (a < b ? a : b)
+-#endif
+-
+-#ifndef max
+-#define max(a, b) (a > b ? a : b)
+-#endif
+-
+-/* ***************************** crcAdvance **********************************/
+-/**
+- * @fn
+- * @brief updates crc data register
+- * @return none
+- *
+- * This function updates the crc register
+- *
+- */
+-static void crcAdvance(USHORT crcPoly, USHORT crcMask, USHORT *crc,
+- ULONG bValue, INT bBits) {
+- INT i;
+- USHORT flag;
+-
+- for (i = bBits - 1; i >= 0; i--) {
+- flag = ((*crc) & crcMask) ? (1) : (0);
+- flag ^= (bValue & (1 << i)) ? (1) : (0);
+-
+- (*crc) <<= 1;
+- if (flag) (*crc) ^= crcPoly;
+- }
+-}
+-
+-/* ***************************** FDKsbrEnc_InitSbrBitstream
+- * **********************************/
+-/**
+- * @fn
+- * @brief Inittialisation of sbr bitstream, write of dummy header and CRC
+- * @return none
+- *
+- *
+- *
+- */
+-
+-INT FDKsbrEnc_InitSbrBitstream(
+- HANDLE_COMMON_DATA hCmonData,
+- UCHAR *memoryBase, /*!< Pointer to bitstream buffer */
+- INT memorySize, /*!< Length of bitstream buffer in bytes */
+- HANDLE_FDK_CRCINFO hCrcInfo, UINT sbrSyntaxFlags) /*!< SBR syntax flags */
+-{
+- INT crcRegion = 0;
+-
+- /* reset bit buffer */
+- FDKresetBitbuffer(&hCmonData->sbrBitbuf, BS_WRITER);
+-
+- FDKinitBitStream(&hCmonData->tmpWriteBitbuf, memoryBase, memorySize, 0,
+- BS_WRITER);
+-
+- if (sbrSyntaxFlags & SBR_SYNTAX_CRC) {
+- if (sbrSyntaxFlags & SBR_SYNTAX_DRM_CRC) { /* Init and start CRC region */
+- FDKwriteBits(&hCmonData->sbrBitbuf, 0x0, SI_SBR_DRM_CRC_BITS);
+- FDKcrcInit(hCrcInfo, 0x001d, 0xFFFF, SI_SBR_DRM_CRC_BITS);
+- crcRegion = FDKcrcStartReg(hCrcInfo, &hCmonData->sbrBitbuf, 0);
+- } else {
+- FDKwriteBits(&hCmonData->sbrBitbuf, 0x0, SI_SBR_CRC_BITS);
+- }
+- }
+-
+- return (crcRegion);
+-}
+-
+-/* ************************** FDKsbrEnc_AssembleSbrBitstream
+- * *******************************/
+-/**
+- * @fn
+- * @brief Formats the SBR payload
+- * @return nothing
+- *
+- * Also the CRC will be calculated here.
+- *
+- */
+-
+-void FDKsbrEnc_AssembleSbrBitstream(HANDLE_COMMON_DATA hCmonData,
+- HANDLE_FDK_CRCINFO hCrcInfo, INT crcRegion,
+- UINT sbrSyntaxFlags) {
+- USHORT crcReg = SBR_CRCINIT;
+- INT numCrcBits, i;
+-
+- /* check if SBR is present */
+- if (hCmonData == NULL) return;
+-
+- hCmonData->sbrFillBits = 0; /* Fill bits are written only for GA streams */
+-
+- if (sbrSyntaxFlags & SBR_SYNTAX_DRM_CRC) {
+- /*
+- * Calculate and write DRM CRC
+- */
+- FDKcrcEndReg(hCrcInfo, &hCmonData->sbrBitbuf, crcRegion);
+- FDKwriteBits(&hCmonData->tmpWriteBitbuf, FDKcrcGetCRC(hCrcInfo) ^ 0xFF,
+- SI_SBR_DRM_CRC_BITS);
+- } else {
+- if (!(sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)) {
+- /* Do alignment here, because its defined as part of the
+- * sbr_extension_data */
+- int sbrLoad = hCmonData->sbrHdrBits + hCmonData->sbrDataBits;
+-
+- if (sbrSyntaxFlags & SBR_SYNTAX_CRC) {
+- sbrLoad += SI_SBR_CRC_BITS;
+- }
+-
+- sbrLoad += 4; /* Do byte Align with 4 bit offset. ISO/IEC 14496-3:2005(E)
+- page 39. */
+-
+- hCmonData->sbrFillBits = (8 - (sbrLoad % 8)) % 8;
+-
+- /*
+- append fill bits
+- */
+- FDKwriteBits(&hCmonData->sbrBitbuf, 0, hCmonData->sbrFillBits);
+-
+- FDK_ASSERT(FDKgetValidBits(&hCmonData->sbrBitbuf) % 8 == 4);
+- }
+-
+- /*
+- calculate crc
+- */
+- if (sbrSyntaxFlags & SBR_SYNTAX_CRC) {
+- FDK_BITSTREAM tmpCRCBuf = hCmonData->sbrBitbuf;
+- FDKresetBitbuffer(&tmpCRCBuf, BS_READER);
+-
+- numCrcBits = hCmonData->sbrHdrBits + hCmonData->sbrDataBits +
+- hCmonData->sbrFillBits;
+-
+- for (i = 0; i < numCrcBits; i++) {
+- INT bit;
+- bit = FDKreadBits(&tmpCRCBuf, 1);
+- crcAdvance(SBR_CRC_POLY, SBR_CRC_MASK, &crcReg, bit, 1);
+- }
+- crcReg &= (SBR_CRC_RANGE);
+-
+- /*
+- * Write CRC data.
+- */
+- FDKwriteBits(&hCmonData->tmpWriteBitbuf, crcReg, SI_SBR_CRC_BITS);
+- }
+- }
+-
+- FDKsyncCache(&hCmonData->tmpWriteBitbuf);
+-}
+diff --git a/libSBRenc/src/env_bit.h b/libSBRenc/src/env_bit.h
+deleted file mode 100644
+index b91802c..0000000
+--- a/libSBRenc/src/env_bit.h
++++ /dev/null
+@@ -1,135 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Remaining SBR Bit Writing Routines
+-*/
+-
+-#ifndef ENV_BIT_H
+-#define ENV_BIT_H
+-
+-#include "sbr_encoder.h"
+-#include "FDK_crc.h"
+-
+-/* G(x) = x^10 + x^9 + x^5 + x^4 + x + 1 */
+-#define SBR_CRC_POLY (0x0233)
+-#define SBR_CRC_MASK (0x0200)
+-#define SBR_CRC_RANGE (0x03FF)
+-#define SBR_CRC_MAXREGS 1
+-#define SBR_CRCINIT (0x0)
+-
+-#define SI_SBR_CRC_ENABLE_BITS 0
+-#define SI_SBR_CRC_BITS 10
+-#define SI_SBR_DRM_CRC_BITS 8
+-
+-struct COMMON_DATA;
+-
+-INT FDKsbrEnc_InitSbrBitstream(struct COMMON_DATA *hCmonData, UCHAR *memoryBase,
+- INT memorySize, HANDLE_FDK_CRCINFO hCrcInfo,
+- UINT sbrSyntaxFlags);
+-
+-void FDKsbrEnc_AssembleSbrBitstream(struct COMMON_DATA *hCmonData,
+- HANDLE_FDK_CRCINFO hCrcInfo, INT crcRegion,
+- UINT sbrSyntaxFlags);
+-
+-#endif /* #ifndef ENV_BIT_H */
+diff --git a/libSBRenc/src/env_est.cpp b/libSBRenc/src/env_est.cpp
+deleted file mode 100644
+index 0eb8425..0000000
+--- a/libSBRenc/src/env_est.cpp
++++ /dev/null
+@@ -1,1985 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "env_est.h"
+-#include "tran_det.h"
+-
+-#include "qmf.h"
+-
+-#include "fram_gen.h"
+-#include "bit_sbr.h"
+-#include "cmondata.h"
+-#include "sbrenc_ram.h"
+-
+-#include "genericStds.h"
+-
+-#define QUANT_ERROR_THRES 200
+-#define Y_NRG_SCALE 5 /* noCols = 32 -> shift(5) */
+-#define MAX_NRG_SLOTS_LD 16
+-
+-static const UCHAR panTable[2][10] = {{0, 2, 4, 6, 8, 12, 16, 20, 24},
+- {0, 2, 4, 8, 12, 0, 0, 0, 0}};
+-static const UCHAR maxIndex[2] = {9, 5};
+-
+-/******************************************************************************
+- Functionname: FDKsbrEnc_GetTonality
+-******************************************************************************/
+-/***************************************************************************/
+-/*!
+-
+- \brief Calculates complete energy per band from the energy values
+- of the QMF subsamples.
+-
+- \brief quotaMatrix - calculated in FDKsbrEnc_CalculateTonalityQuotas()
+- \brief noEstPerFrame - number of estimations per frame
+- \brief startIndex - start index for the quota matrix
+- \brief Energies - energy matrix
+- \brief startBand - start band
+- \brief stopBand - number of QMF bands
+- \brief numberCols - number of QMF subsamples
+-
+- \return mean tonality of the 5 bands with the highest energy
+- scaled by 2^(RELAXATION_SHIFT+2)*RELAXATION_FRACT
+-
+-****************************************************************************/
+-static FIXP_DBL FDKsbrEnc_GetTonality(const FIXP_DBL *const *quotaMatrix,
+- const INT noEstPerFrame,
+- const INT startIndex,
+- const FIXP_DBL *const *Energies,
+- const UCHAR startBand, const INT stopBand,
+- const INT numberCols) {
+- UCHAR b, e, k;
+- INT no_enMaxBand[SBR_MAX_ENERGY_VALUES] = {-1, -1, -1, -1, -1};
+- FIXP_DBL energyMax[SBR_MAX_ENERGY_VALUES] = {
+- FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f),
+- FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f)};
+- FIXP_DBL energyMaxMin = MAXVAL_DBL; /* min. energy in energyMax array */
+- UCHAR posEnergyMaxMin = 0; /* min. energy in energyMax array position */
+- FIXP_DBL tonalityBand[SBR_MAX_ENERGY_VALUES] = {
+- FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f),
+- FL2FXCONST_DBL(0.0f), FL2FXCONST_DBL(0.0f)};
+- FIXP_DBL globalTonality = FL2FXCONST_DBL(0.0f);
+- FIXP_DBL energyBand[64];
+- INT maxNEnergyValues; /* max. number of max. energy values */
+-
+- /*** Sum up energies for each band ***/
+- FDK_ASSERT(numberCols == 15 || numberCols == 16);
+- /* numberCols is always 15 or 16 for ELD. In case of 16 bands, the
+- energyBands are initialized with the [15]th column.
+- The rest of the column energies are added in the next step. */
+- if (numberCols == 15) {
+- for (b = startBand; b < stopBand; b++) {
+- energyBand[b] = FL2FXCONST_DBL(0.0f);
+- }
+- } else {
+- for (b = startBand; b < stopBand; b++) {
+- energyBand[b] = Energies[15][b] >> 4;
+- }
+- }
+-
+- for (k = 0; k < 15; k++) {
+- for (b = startBand; b < stopBand; b++) {
+- energyBand[b] += Energies[k][b] >> 4;
+- }
+- }
+-
+- /*** Determine 5 highest band-energies ***/
+- maxNEnergyValues = fMin(SBR_MAX_ENERGY_VALUES, stopBand - startBand);
+-
+- /* Get min. value in energyMax array */
+- energyMaxMin = energyMax[0] = energyBand[startBand];
+- no_enMaxBand[0] = startBand;
+- posEnergyMaxMin = 0;
+- for (k = 1; k < maxNEnergyValues; k++) {
+- energyMax[k] = energyBand[startBand + k];
+- no_enMaxBand[k] = startBand + k;
+- if (energyMaxMin > energyMax[k]) {
+- energyMaxMin = energyMax[k];
+- posEnergyMaxMin = k;
+- }
+- }
+-
+- for (b = startBand + maxNEnergyValues; b < stopBand; b++) {
+- if (energyBand[b] > energyMaxMin) {
+- energyMax[posEnergyMaxMin] = energyBand[b];
+- no_enMaxBand[posEnergyMaxMin] = b;
+-
+- /* Again, get min. value in energyMax array */
+- energyMaxMin = energyMax[0];
+- posEnergyMaxMin = 0;
+- for (k = 1; k < maxNEnergyValues; k++) {
+- if (energyMaxMin > energyMax[k]) {
+- energyMaxMin = energyMax[k];
+- posEnergyMaxMin = k;
+- }
+- }
+- }
+- }
+- /*** End determine 5 highest band-energies ***/
+-
+- /* Get tonality values for 5 highest energies */
+- for (e = 0; e < maxNEnergyValues; e++) {
+- tonalityBand[e] = FL2FXCONST_DBL(0.0f);
+- for (k = 0; k < noEstPerFrame; k++) {
+- tonalityBand[e] += quotaMatrix[startIndex + k][no_enMaxBand[e]] >> 1;
+- }
+- globalTonality +=
+- tonalityBand[e] >> 2; /* headroom of 2+1 (max. 5 additions) */
+- }
+-
+- return globalTonality;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Calculates energy form real and imaginary part of
+- the QMF subsamples
+-
+- \return none
+-
+-****************************************************************************/
+-LNK_SECTION_CODE_L1
+-static void FDKsbrEnc_getEnergyFromCplxQmfData(
+- FIXP_DBL **RESTRICT energyValues, /*!< the result of the operation */
+- FIXP_DBL **RESTRICT realValues, /*!< the real part of the QMF subsamples */
+- FIXP_DBL **RESTRICT
+- imagValues, /*!< the imaginary part of the QMF subsamples */
+- INT numberBands, /*!< number of QMF bands */
+- INT numberCols, /*!< number of QMF subsamples */
+- INT *qmfScale, /*!< sclefactor of QMF subsamples */
+- INT *energyScale) /*!< scalefactor of energies */
+-{
+- int j, k;
+- int scale;
+- FIXP_DBL max_val = FL2FXCONST_DBL(0.0f);
+-
+- /* Get Scratch buffer */
+- C_ALLOC_SCRATCH_START(tmpNrg, FIXP_DBL, 32 * 64 / 2)
+-
+- /* Get max possible scaling of QMF data */
+- scale = DFRACT_BITS;
+- for (k = 0; k < numberCols; k++) {
+- scale = fixMin(scale, fixMin(getScalefactor(realValues[k], numberBands),
+- getScalefactor(imagValues[k], numberBands)));
+- }
+-
+- /* Tweak scaling stability for zero signal to non-zero signal transitions */
+- if (scale >= DFRACT_BITS - 1) {
+- scale = (FRACT_BITS - 1 - *qmfScale);
+- }
+- /* prevent scaling of QMF values to -1.f */
+- scale = fixMax(0, scale - 1);
+-
+- /* Update QMF scale */
+- *qmfScale += scale;
+-
+- /*
+- Calculate energy of each time slot pair, max energy
+- and shift QMF values as far as possible to the left.
+- */
+- {
+- FIXP_DBL *nrgValues = tmpNrg;
+- for (k = 0; k < numberCols; k += 2) {
+- /* Load band vector addresses of 2 consecutive timeslots */
+- FIXP_DBL *RESTRICT r0 = realValues[k];
+- FIXP_DBL *RESTRICT i0 = imagValues[k];
+- FIXP_DBL *RESTRICT r1 = realValues[k + 1];
+- FIXP_DBL *RESTRICT i1 = imagValues[k + 1];
+- for (j = 0; j < numberBands; j++) {
+- FIXP_DBL energy;
+- FIXP_DBL tr0, tr1, ti0, ti1;
+-
+- /* Read QMF values of 2 timeslots */
+- tr0 = r0[j];
+- tr1 = r1[j];
+- ti0 = i0[j];
+- ti1 = i1[j];
+-
+- /* Scale QMF Values and Calc Energy average of both timeslots */
+- tr0 <<= scale;
+- ti0 <<= scale;
+- energy = fPow2AddDiv2(fPow2Div2(tr0), ti0) >> 1;
+-
+- tr1 <<= scale;
+- ti1 <<= scale;
+- energy += fPow2AddDiv2(fPow2Div2(tr1), ti1) >> 1;
+-
+- /* Write timeslot pair energy to scratch */
+- *nrgValues++ = energy;
+- max_val = fixMax(max_val, energy);
+-
+- /* Write back scaled QMF values */
+- r0[j] = tr0;
+- r1[j] = tr1;
+- i0[j] = ti0;
+- i1[j] = ti1;
+- }
+- }
+- }
+- /* energyScale: scalefactor energies of current frame */
+- *energyScale =
+- 2 * (*qmfScale) -
+- 1; /* if qmfScale > 0: nr of right shifts otherwise nr of left shifts */
+-
+- /* Scale timeslot pair energies and write to output buffer */
+- scale = CountLeadingBits(max_val);
+- {
+- FIXP_DBL *nrgValues = tmpNrg;
+- for (k = 0; k<numberCols>> 1; k++) {
+- scaleValues(energyValues[k], nrgValues, numberBands, scale);
+- nrgValues += numberBands;
+- }
+- *energyScale += scale;
+- }
+-
+- /* Free Scratch buffer */
+- C_ALLOC_SCRATCH_END(tmpNrg, FIXP_DBL, 32 * 64 / 2)
+-}
+-
+-LNK_SECTION_CODE_L1
+-static void FDKsbrEnc_getEnergyFromCplxQmfDataFull(
+- FIXP_DBL **RESTRICT energyValues, /*!< the result of the operation */
+- FIXP_DBL **RESTRICT realValues, /*!< the real part of the QMF subsamples */
+- FIXP_DBL **RESTRICT
+- imagValues, /*!< the imaginary part of the QMF subsamples */
+- int numberBands, /*!< number of QMF bands */
+- int numberCols, /*!< number of QMF subsamples */
+- int *qmfScale, /*!< scalefactor of QMF subsamples */
+- int *energyScale) /*!< scalefactor of energies */
+-{
+- int j, k;
+- int scale;
+- FIXP_DBL max_val = FL2FXCONST_DBL(0.0f);
+-
+- /* Get Scratch buffer */
+- C_ALLOC_SCRATCH_START(tmpNrg, FIXP_DBL, MAX_NRG_SLOTS_LD * 64)
+-
+- FDK_ASSERT(numberCols <= MAX_NRG_SLOTS_LD);
+- FDK_ASSERT(numberBands <= 64);
+-
+- /* Get max possible scaling of QMF data */
+- scale = DFRACT_BITS;
+- for (k = 0; k < numberCols; k++) {
+- scale = fixMin(scale, fixMin(getScalefactor(realValues[k], numberBands),
+- getScalefactor(imagValues[k], numberBands)));
+- }
+-
+- /* Tweak scaling stability for zero signal to non-zero signal transitions */
+- if (scale >= DFRACT_BITS - 1) {
+- scale = (FRACT_BITS - 1 - *qmfScale);
+- }
+- /* prevent scaling of QFM values to -1.f */
+- scale = fixMax(0, scale - 1);
+-
+- /* Update QMF scale */
+- *qmfScale += scale;
+-
+- /*
+- Calculate energy of each time slot pair, max energy
+- and shift QMF values as far as possible to the left.
+- */
+- {
+- FIXP_DBL *nrgValues = tmpNrg;
+- for (k = 0; k < numberCols; k++) {
+- /* Load band vector addresses of 1 timeslot */
+- FIXP_DBL *RESTRICT r0 = realValues[k];
+- FIXP_DBL *RESTRICT i0 = imagValues[k];
+- for (j = 0; j < numberBands; j++) {
+- FIXP_DBL energy;
+- FIXP_DBL tr0, ti0;
+-
+- /* Read QMF values of 1 timeslot */
+- tr0 = r0[j];
+- ti0 = i0[j];
+-
+- /* Scale QMF Values and Calc Energy */
+- tr0 <<= scale;
+- ti0 <<= scale;
+- energy = fPow2AddDiv2(fPow2Div2(tr0), ti0);
+- *nrgValues++ = energy;
+-
+- max_val = fixMax(max_val, energy);
+-
+- /* Write back scaled QMF values */
+- r0[j] = tr0;
+- i0[j] = ti0;
+- }
+- }
+- }
+- /* energyScale: scalefactor energies of current frame */
+- *energyScale =
+- 2 * (*qmfScale) -
+- 1; /* if qmfScale > 0: nr of right shifts otherwise nr of left shifts */
+-
+- /* Scale timeslot pair energies and write to output buffer */
+- scale = CountLeadingBits(max_val);
+- {
+- FIXP_DBL *nrgValues = tmpNrg;
+- for (k = 0; k < numberCols; k++) {
+- scaleValues(energyValues[k], nrgValues, numberBands, scale);
+- nrgValues += numberBands;
+- }
+- *energyScale += scale;
+- }
+-
+- /* Free Scratch buffer */
+- C_ALLOC_SCRATCH_END(tmpNrg, FIXP_DBL, MAX_NRG_SLOTS_LD * 64)
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Quantisation of the panorama value (balance)
+-
+- \return the quantized pan value
+-
+-****************************************************************************/
+-static INT mapPanorama(INT nrgVal, /*! integer value of the energy */
+- INT ampRes, /*! amplitude resolution [1.5/3dB] */
+- INT *quantError /*! quantization error of energy val*/
+-) {
+- int i;
+- INT min_val, val;
+- UCHAR panIndex;
+- INT sign;
+-
+- sign = nrgVal > 0 ? 1 : -1;
+-
+- nrgVal *= sign;
+-
+- min_val = FDK_INT_MAX;
+- panIndex = 0;
+- for (i = 0; i < maxIndex[ampRes]; i++) {
+- val = fixp_abs((nrgVal - (INT)panTable[ampRes][i]));
+-
+- if (val < min_val) {
+- min_val = val;
+- panIndex = i;
+- }
+- }
+-
+- *quantError = min_val;
+-
+- return panTable[ampRes][maxIndex[ampRes] - 1] +
+- sign * panTable[ampRes][panIndex];
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Quantisation of the noise floor levels
+-
+- \return void
+-
+-****************************************************************************/
+-static void sbrNoiseFloorLevelsQuantisation(
+- SCHAR *RESTRICT iNoiseLevels, /*! quantized noise levels */
+- FIXP_DBL *RESTRICT
+- NoiseLevels, /*! the noise levels. Exponent = LD_DATA_SHIFT */
+- INT coupling /*! the coupling flag */
+-) {
+- INT i;
+- INT tmp, dummy;
+-
+- /* Quantisation, similar to sfb quant... */
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++) {
+- /* tmp = NoiseLevels[i] > (PFLOAT)30.0f ? 30: (INT) (NoiseLevels[i] +
+- * (PFLOAT)0.5); */
+- /* 30>>LD_DATA_SHIFT = 0.46875 */
+- if ((FIXP_DBL)NoiseLevels[i] > FL2FXCONST_DBL(0.46875f)) {
+- tmp = 30;
+- } else {
+- /* tmp = (INT)((FIXP_DBL)NoiseLevels[i] + (FL2FXCONST_DBL(0.5f)>>(*/
+- /* FRACT_BITS+ */ /* 6-1)));*/
+- /* tmp = tmp >> (DFRACT_BITS-1-LD_DATA_SHIFT); */ /* conversion to integer
+- happens here */
+- /* rounding is done by shifting one bit less than necessary to the right,
+- * adding '1' and then shifting the final bit */
+- tmp = ((((INT)NoiseLevels[i]) >>
+- (DFRACT_BITS - 1 - LD_DATA_SHIFT))); /* conversion to integer */
+- if (tmp != 0) tmp += 1;
+- }
+-
+- if (coupling) {
+- tmp = tmp < -30 ? -30 : tmp;
+- tmp = mapPanorama(tmp, 1, &dummy);
+- }
+- iNoiseLevels[i] = tmp;
+- }
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Calculation of noise floor for coupling
+-
+- \return void
+-
+-****************************************************************************/
+-static void coupleNoiseFloor(
+- FIXP_DBL *RESTRICT noise_level_left, /*! noise level left (modified)*/
+- FIXP_DBL *RESTRICT noise_level_right /*! noise level right (modified)*/
+-) {
+- FIXP_DBL cmpValLeft, cmpValRight;
+- INT i;
+- FIXP_DBL temp1, temp2;
+-
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++) {
+- /* Calculation of the power function using ld64:
+- z = x^y;
+- z' = CalcLd64(z) = y*CalcLd64(x)/64;
+- z = CalcInvLd64(z');
+- */
+- cmpValLeft = NOISE_FLOOR_OFFSET_64 - noise_level_left[i];
+- cmpValRight = NOISE_FLOOR_OFFSET_64 - noise_level_right[i];
+-
+- if (cmpValRight < FL2FXCONST_DBL(0.0f)) {
+- temp1 = CalcInvLdData(NOISE_FLOOR_OFFSET_64 - noise_level_right[i]);
+- } else {
+- temp1 = CalcInvLdData(NOISE_FLOOR_OFFSET_64 - noise_level_right[i]);
+- temp1 = temp1 << (DFRACT_BITS - 1 - LD_DATA_SHIFT -
+- 1); /* INT to fract conversion of result, if input of
+- CalcInvLdData is positiv */
+- }
+-
+- if (cmpValLeft < FL2FXCONST_DBL(0.0f)) {
+- temp2 = CalcInvLdData(NOISE_FLOOR_OFFSET_64 - noise_level_left[i]);
+- } else {
+- temp2 = CalcInvLdData(NOISE_FLOOR_OFFSET_64 - noise_level_left[i]);
+- temp2 = temp2 << (DFRACT_BITS - 1 - LD_DATA_SHIFT -
+- 1); /* INT to fract conversion of result, if input of
+- CalcInvLdData is positiv */
+- }
+-
+- if ((cmpValLeft < FL2FXCONST_DBL(0.0f)) &&
+- (cmpValRight < FL2FXCONST_DBL(0.0f))) {
+- noise_level_left[i] =
+- NOISE_FLOOR_OFFSET_64 -
+- (CalcLdData(
+- ((temp1 >> 1) +
+- (temp2 >> 1)))); /* no scaling needed! both values are dfract */
+- noise_level_right[i] = CalcLdData(temp2) - CalcLdData(temp1);
+- }
+-
+- if ((cmpValLeft >= FL2FXCONST_DBL(0.0f)) &&
+- (cmpValRight >= FL2FXCONST_DBL(0.0f))) {
+- noise_level_left[i] = NOISE_FLOOR_OFFSET_64 -
+- (CalcLdData(((temp1 >> 1) + (temp2 >> 1))) +
+- FL2FXCONST_DBL(0.109375f)); /* scaled with 7/64 */
+- noise_level_right[i] = CalcLdData(temp2) - CalcLdData(temp1);
+- }
+-
+- if ((cmpValLeft >= FL2FXCONST_DBL(0.0f)) &&
+- (cmpValRight < FL2FXCONST_DBL(0.0f))) {
+- noise_level_left[i] = NOISE_FLOOR_OFFSET_64 -
+- (CalcLdData(((temp1 >> (7 + 1)) + (temp2 >> 1))) +
+- FL2FXCONST_DBL(0.109375f)); /* scaled with 7/64 */
+- noise_level_right[i] =
+- (CalcLdData(temp2) + FL2FXCONST_DBL(0.109375f)) - CalcLdData(temp1);
+- }
+-
+- if ((cmpValLeft < FL2FXCONST_DBL(0.0f)) &&
+- (cmpValRight >= FL2FXCONST_DBL(0.0f))) {
+- noise_level_left[i] = NOISE_FLOOR_OFFSET_64 -
+- (CalcLdData(((temp1 >> 1) + (temp2 >> (7 + 1)))) +
+- FL2FXCONST_DBL(0.109375f)); /* scaled with 7/64 */
+- noise_level_right[i] = CalcLdData(temp2) -
+- (CalcLdData(temp1) +
+- FL2FXCONST_DBL(0.109375f)); /* scaled with 7/64 */
+- }
+- }
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Calculation of energy starting in lower band (li) up to upper band
+-(ui) over slots (start_pos) to (stop_pos)
+-
+- \return void
+-
+-****************************************************************************/
+-
+-static FIXP_DBL getEnvSfbEnergy(
+- INT li, /*! lower band */
+- INT ui, /*! upper band */
+- INT start_pos, /*! start slot */
+- INT stop_pos, /*! stop slot */
+- INT border_pos, /*! slots scaling border */
+- FIXP_DBL **YBuffer, /*! sfb energy buffer */
+- INT YBufferSzShift, /*! Energy buffer index scale */
+- INT scaleNrg0, /*! scaling of lower slots */
+- INT scaleNrg1) /*! scaling of upper slots */
+-{
+- /* use dynamic scaling for outer energy loop;
+- energies are critical and every bit is important */
+- int sc0, sc1, k, l;
+-
+- FIXP_DBL nrgSum, nrg1, nrg2, accu1, accu2;
+- INT dynScale, dynScale1, dynScale2;
+- if (ui - li == 0)
+- dynScale = DFRACT_BITS - 1;
+- else
+- dynScale = CalcLdInt(ui - li) >> (DFRACT_BITS - 1 - LD_DATA_SHIFT);
+-
+- sc0 = fixMin(scaleNrg0, Y_NRG_SCALE);
+- sc1 = fixMin(scaleNrg1, Y_NRG_SCALE);
+- /* dynScale{1,2} is set such that the right shift below is positive */
+- dynScale1 = fixMin((scaleNrg0 - sc0), dynScale);
+- dynScale2 = fixMin((scaleNrg1 - sc1), dynScale);
+- nrgSum = accu1 = accu2 = (FIXP_DBL)0;
+-
+- for (k = li; k < ui; k++) {
+- nrg1 = nrg2 = (FIXP_DBL)0;
+- for (l = start_pos; l < border_pos; l++) {
+- nrg1 += YBuffer[l >> YBufferSzShift][k] >> sc0;
+- }
+- for (; l < stop_pos; l++) {
+- nrg2 += YBuffer[l >> YBufferSzShift][k] >> sc1;
+- }
+- accu1 += (nrg1 >> dynScale1);
+- accu2 += (nrg2 >> dynScale2);
+- }
+- /* This shift factor is always positive. See comment above. */
+- nrgSum +=
+- (accu1 >> fixMin((scaleNrg0 - sc0 - dynScale1), (DFRACT_BITS - 1))) +
+- (accu2 >> fixMin((scaleNrg1 - sc1 - dynScale2), (DFRACT_BITS - 1)));
+-
+- return nrgSum;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Energy compensation in missing harmonic mode
+-
+- \return void
+-
+-****************************************************************************/
+-static FIXP_DBL mhLoweringEnergy(FIXP_DBL nrg, INT M) {
+- /*
+- Compensating for the fact that we in the decoder map the "average energy to
+- every QMF band, and use this when we calculate the boost-factor. Since the
+- mapped energy isn't the average energy but the maximum energy in case of
+- missing harmonic creation, we will in the boost function calculate that too
+- much limiting has been applied and hence we will boost the signal although
+- it isn't called for. Hence we need to compensate for this by lowering the
+- transmitted energy values for the sines so they will get the correct level
+- after the boost is applied.
+- */
+- if (M > 2) {
+- INT tmpScale;
+- tmpScale = CountLeadingBits(nrg);
+- nrg <<= tmpScale;
+- nrg = fMult(nrg, FL2FXCONST_DBL(0.398107267f)); /* The maximum boost
+- is 1.584893, so the
+- maximum attenuation
+- should be
+- square(1/1.584893) =
+- 0.398107267 */
+- nrg >>= tmpScale;
+- } else {
+- if (M > 1) {
+- nrg >>= 1;
+- }
+- }
+-
+- return nrg;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Energy compensation in none missing harmonic mode
+-
+- \return void
+-
+-****************************************************************************/
+-static FIXP_DBL nmhLoweringEnergy(FIXP_DBL nrg, const FIXP_DBL nrgSum,
+- const INT nrgSum_scale, const INT M) {
+- if (nrg > FL2FXCONST_DBL(0)) {
+- int sc = 0;
+- /* gain = nrgSum / (nrg*(M+1)) */
+- FIXP_DBL gain = fMult(fDivNorm(nrgSum, nrg, &sc), GetInvInt(M + 1));
+- sc += nrgSum_scale;
+-
+- /* reduce nrg if gain smaller 1.f */
+- if (!((sc >= 0) && (gain > ((FIXP_DBL)MAXVAL_DBL >> sc)))) {
+- nrg = fMult(scaleValue(gain, sc), nrg);
+- }
+- }
+- return nrg;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief calculates the envelope values from the energies, depending on
+- framing and stereo mode
+-
+- \return void
+-
+-****************************************************************************/
+-static void calculateSbrEnvelope(
+- FIXP_DBL **RESTRICT YBufferLeft, /*! energy buffer left */
+- FIXP_DBL **RESTRICT YBufferRight, /*! energy buffer right */
+- int *RESTRICT YBufferScaleLeft, /*! scale energy buffer left */
+- int *RESTRICT YBufferScaleRight, /*! scale energy buffer right */
+- const SBR_FRAME_INFO *frame_info, /*! frame info vector */
+- SCHAR *RESTRICT sfb_nrgLeft, /*! sfb energy buffer left */
+- SCHAR *RESTRICT sfb_nrgRight, /*! sfb energy buffer right */
+- HANDLE_SBR_CONFIG_DATA h_con, /*! handle to config data */
+- HANDLE_ENV_CHANNEL h_sbr, /*! envelope channel handle */
+- SBR_STEREO_MODE stereoMode, /*! stereo coding mode */
+- INT *maxQuantError, /*! maximum quantization error, for panorama. */
+- int YBufferSzShift) /*! Energy buffer index scale */
+-
+-{
+- int env, j, m = 0;
+- INT no_of_bands, start_pos, stop_pos, li, ui;
+- FREQ_RES freq_res;
+-
+- INT ca = 2 - h_sbr->encEnvData.init_sbr_amp_res;
+- INT oneBitLess = 0;
+- if (ca == 2)
+- oneBitLess =
+- 1; /* LD_DATA_SHIFT => ld64 scaling; one bit less for rounding */
+-
+- INT quantError;
+- INT nEnvelopes = frame_info->nEnvelopes;
+- INT short_env = frame_info->shortEnv - 1;
+- INT timeStep = h_sbr->sbrExtractEnvelope.time_step;
+- INT commonScale, scaleLeft0, scaleLeft1;
+- INT scaleRight0 = 0, scaleRight1 = 0;
+-
+- commonScale = fixMin(YBufferScaleLeft[0], YBufferScaleLeft[1]);
+-
+- if (stereoMode == SBR_COUPLING) {
+- commonScale = fixMin(commonScale, YBufferScaleRight[0]);
+- commonScale = fixMin(commonScale, YBufferScaleRight[1]);
+- }
+-
+- commonScale = commonScale - 7;
+-
+- scaleLeft0 = YBufferScaleLeft[0] - commonScale;
+- scaleLeft1 = YBufferScaleLeft[1] - commonScale;
+- FDK_ASSERT((scaleLeft0 >= 0) && (scaleLeft1 >= 0));
+-
+- if (stereoMode == SBR_COUPLING) {
+- scaleRight0 = YBufferScaleRight[0] - commonScale;
+- scaleRight1 = YBufferScaleRight[1] - commonScale;
+- FDK_ASSERT((scaleRight0 >= 0) && (scaleRight1 >= 0));
+- *maxQuantError = 0;
+- }
+-
+- for (env = 0; env < nEnvelopes; env++) {
+- FIXP_DBL pNrgLeft[32];
+- FIXP_DBL pNrgRight[32];
+- int envNrg_scale;
+- FIXP_DBL envNrgLeft = FL2FXCONST_DBL(0.0f);
+- FIXP_DBL envNrgRight = FL2FXCONST_DBL(0.0f);
+- int missingHarmonic[32];
+- int count[32];
+-
+- start_pos = timeStep * frame_info->borders[env];
+- stop_pos = timeStep * frame_info->borders[env + 1];
+- freq_res = frame_info->freqRes[env];
+- no_of_bands = h_con->nSfb[freq_res];
+- envNrg_scale = DFRACT_BITS - fNormz((FIXP_DBL)no_of_bands);
+- if (env == short_env) {
+- j = fMax(2, timeStep); /* consider at least 2 QMF slots less for short
+- envelopes (envelopes just before transients) */
+- if ((stop_pos - start_pos - j) > 0) {
+- stop_pos = stop_pos - j;
+- }
+- }
+- for (j = 0; j < no_of_bands; j++) {
+- FIXP_DBL nrgLeft = FL2FXCONST_DBL(0.0f);
+- FIXP_DBL nrgRight = FL2FXCONST_DBL(0.0f);
+-
+- li = h_con->freqBandTable[freq_res][j];
+- ui = h_con->freqBandTable[freq_res][j + 1];
+-
+- if (freq_res == FREQ_RES_HIGH) {
+- if (j == 0 && ui - li > 1) {
+- li++;
+- }
+- } else {
+- if (j == 0 && ui - li > 2) {
+- li++;
+- }
+- }
+-
+- /*
+- Find out whether a sine will be missing in the scale-factor
+- band that we're currently processing.
+- */
+- missingHarmonic[j] = 0;
+-
+- if (h_sbr->encEnvData.addHarmonicFlag) {
+- if (freq_res == FREQ_RES_HIGH) {
+- if (h_sbr->encEnvData
+- .addHarmonic[j]) { /*A missing sine in the current band*/
+- missingHarmonic[j] = 1;
+- }
+- } else {
+- INT i;
+- INT startBandHigh = 0;
+- INT stopBandHigh = 0;
+-
+- while (h_con->freqBandTable[FREQ_RES_HIGH][startBandHigh] <
+- h_con->freqBandTable[FREQ_RES_LOW][j])
+- startBandHigh++;
+- while (h_con->freqBandTable[FREQ_RES_HIGH][stopBandHigh] <
+- h_con->freqBandTable[FREQ_RES_LOW][j + 1])
+- stopBandHigh++;
+-
+- for (i = startBandHigh; i < stopBandHigh; i++) {
+- if (h_sbr->encEnvData.addHarmonic[i]) {
+- missingHarmonic[j] = 1;
+- }
+- }
+- }
+- }
+-
+- /*
+- If a sine is missing in a scalefactorband, with more than one qmf
+- channel use the nrg from the channel with the largest nrg rather than
+- the mean. Compensate for the boost calculation in the decdoder.
+- */
+- int border_pos =
+- fixMin(stop_pos, h_sbr->sbrExtractEnvelope.YBufferWriteOffset
+- << YBufferSzShift);
+-
+- if (missingHarmonic[j]) {
+- int k;
+- count[j] = stop_pos - start_pos;
+- nrgLeft = FL2FXCONST_DBL(0.0f);
+-
+- for (k = li; k < ui; k++) {
+- FIXP_DBL tmpNrg;
+- tmpNrg = getEnvSfbEnergy(k, k + 1, start_pos, stop_pos, border_pos,
+- YBufferLeft, YBufferSzShift, scaleLeft0,
+- scaleLeft1);
+-
+- nrgLeft = fixMax(nrgLeft, tmpNrg);
+- }
+-
+- /* Energy lowering compensation */
+- nrgLeft = mhLoweringEnergy(nrgLeft, ui - li);
+-
+- if (stereoMode == SBR_COUPLING) {
+- nrgRight = FL2FXCONST_DBL(0.0f);
+-
+- for (k = li; k < ui; k++) {
+- FIXP_DBL tmpNrg;
+- tmpNrg = getEnvSfbEnergy(k, k + 1, start_pos, stop_pos, border_pos,
+- YBufferRight, YBufferSzShift, scaleRight0,
+- scaleRight1);
+-
+- nrgRight = fixMax(nrgRight, tmpNrg);
+- }
+-
+- /* Energy lowering compensation */
+- nrgRight = mhLoweringEnergy(nrgRight, ui - li);
+- }
+- } /* end missingHarmonic */
+- else {
+- count[j] = (stop_pos - start_pos) * (ui - li);
+-
+- nrgLeft = getEnvSfbEnergy(li, ui, start_pos, stop_pos, border_pos,
+- YBufferLeft, YBufferSzShift, scaleLeft0,
+- scaleLeft1);
+-
+- if (stereoMode == SBR_COUPLING) {
+- nrgRight = getEnvSfbEnergy(li, ui, start_pos, stop_pos, border_pos,
+- YBufferRight, YBufferSzShift, scaleRight0,
+- scaleRight1);
+- }
+- } /* !missingHarmonic */
+-
+- /* save energies */
+- pNrgLeft[j] = nrgLeft;
+- pNrgRight[j] = nrgRight;
+- envNrgLeft += (nrgLeft >> envNrg_scale);
+- envNrgRight += (nrgRight >> envNrg_scale);
+- } /* j */
+-
+- for (j = 0; j < no_of_bands; j++) {
+- FIXP_DBL nrgLeft2 = FL2FXCONST_DBL(0.0f);
+- FIXP_DBL nrgLeft = pNrgLeft[j];
+- FIXP_DBL nrgRight = pNrgRight[j];
+-
+- /* None missing harmonic Energy lowering compensation */
+- if (!missingHarmonic[j] && h_sbr->fLevelProtect) {
+- /* in case of missing energy in base band,
+- reduce reference energy to prevent overflows in decoder output */
+- nrgLeft =
+- nmhLoweringEnergy(nrgLeft, envNrgLeft, envNrg_scale, no_of_bands);
+- if (stereoMode == SBR_COUPLING) {
+- nrgRight = nmhLoweringEnergy(nrgRight, envNrgRight, envNrg_scale,
+- no_of_bands);
+- }
+- }
+-
+- if (stereoMode == SBR_COUPLING) {
+- /* calc operation later with log */
+- nrgLeft2 = nrgLeft;
+- nrgLeft = (nrgRight + nrgLeft) >> 1;
+- }
+-
+- /* nrgLeft = f20_log2(nrgLeft / (PFLOAT)(count * 64))+(PFLOAT)44; */
+- /* If nrgLeft == 0 then the Log calculations below do fail. */
+- if (nrgLeft > FL2FXCONST_DBL(0.0f)) {
+- FIXP_DBL tmp0, tmp1, tmp2, tmp3;
+- INT tmpScale;
+-
+- tmpScale = CountLeadingBits(nrgLeft);
+- nrgLeft = nrgLeft << tmpScale;
+-
+- tmp0 = CalcLdData(nrgLeft); /* scaled by 1/64 */
+- tmp1 = ((FIXP_DBL)(commonScale + tmpScale))
+- << (DFRACT_BITS - 1 - LD_DATA_SHIFT - 1); /* scaled by 1/64 */
+- tmp2 = ((FIXP_DBL)(count[j] * 64)) << (DFRACT_BITS - 1 - 14 - 1);
+- tmp2 = CalcLdData(tmp2); /* scaled by 1/64 */
+- tmp3 = FL2FXCONST_DBL(0.6875f - 0.21875f - 0.015625f) >>
+- 1; /* scaled by 1/64 */
+-
+- nrgLeft = ((tmp0 - tmp2) >> 1) + (tmp3 - tmp1);
+- } else {
+- nrgLeft = FL2FXCONST_DBL(-1.0f);
+- }
+-
+- /* ld64 to integer conversion */
+- nrgLeft = fixMin(fixMax(nrgLeft, FL2FXCONST_DBL(0.0f)),
+- (FL2FXCONST_DBL(0.5f) >> oneBitLess));
+- nrgLeft = (FIXP_DBL)(LONG)nrgLeft >>
+- (DFRACT_BITS - 1 - LD_DATA_SHIFT - 1 - oneBitLess - 1);
+- sfb_nrgLeft[m] = ((INT)nrgLeft + 1) >> 1; /* rounding */
+-
+- if (stereoMode == SBR_COUPLING) {
+- FIXP_DBL scaleFract;
+- int sc0, sc1;
+-
+- nrgLeft2 = fixMax((FIXP_DBL)0x1, nrgLeft2);
+- nrgRight = fixMax((FIXP_DBL)0x1, nrgRight);
+-
+- sc0 = CountLeadingBits(nrgLeft2);
+- sc1 = CountLeadingBits(nrgRight);
+-
+- scaleFract =
+- ((FIXP_DBL)(sc0 - sc1))
+- << (DFRACT_BITS - 1 -
+- LD_DATA_SHIFT); /* scale value in ld64 representation */
+- nrgRight = CalcLdData(nrgLeft2 << sc0) - CalcLdData(nrgRight << sc1) -
+- scaleFract;
+-
+- /* ld64 to integer conversion */
+- nrgRight = (FIXP_DBL)(LONG)(nrgRight) >>
+- (DFRACT_BITS - 1 - LD_DATA_SHIFT - 1 - oneBitLess);
+- nrgRight = (nrgRight + (FIXP_DBL)1) >> 1; /* rounding */
+-
+- sfb_nrgRight[m] = mapPanorama(
+- nrgRight, h_sbr->encEnvData.init_sbr_amp_res, &quantError);
+-
+- *maxQuantError = fixMax(quantError, *maxQuantError);
+- }
+-
+- m++;
+- } /* j */
+-
+- /* Do energy compensation for sines that are present in two
+- QMF-bands in the original, but will only occur in one band in
+- the decoder due to the synthetic sine coding.*/
+- if (h_con->useParametricCoding) {
+- m -= no_of_bands;
+- for (j = 0; j < no_of_bands; j++) {
+- if (freq_res == FREQ_RES_HIGH &&
+- h_sbr->sbrExtractEnvelope.envelopeCompensation[j]) {
+- sfb_nrgLeft[m] -=
+- (ca *
+- fixp_abs(
+- (INT)h_sbr->sbrExtractEnvelope.envelopeCompensation[j]));
+- }
+- sfb_nrgLeft[m] = fixMax(0, sfb_nrgLeft[m]);
+- m++;
+- }
+- } /* useParametricCoding */
+-
+- } /* env loop */
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief calculates the noise floor and the envelope values from the
+- energies, depending on framing and stereo mode
+-
+- FDKsbrEnc_extractSbrEnvelope is the main function for encoding and writing the
+- envelope and the noise floor. The function includes the following processes:
+-
+- -Analysis subband filtering.
+- -Encoding SA and pan parameters (if enabled).
+- -Transient detection.
+-
+-****************************************************************************/
+-
+-LNK_SECTION_CODE_L1
+-void FDKsbrEnc_extractSbrEnvelope1(
+- HANDLE_SBR_CONFIG_DATA h_con, /*! handle to config data */
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData, HANDLE_ENV_CHANNEL hEnvChan,
+- HANDLE_COMMON_DATA hCmonData, SBR_ENV_TEMP_DATA *eData,
+- SBR_FRAME_TEMP_DATA *fData) {
+- HANDLE_SBR_EXTRACT_ENVELOPE sbrExtrEnv = &hEnvChan->sbrExtractEnvelope;
+-
+- if (sbrExtrEnv->YBufferSzShift == 0)
+- FDKsbrEnc_getEnergyFromCplxQmfDataFull(
+- &sbrExtrEnv->YBuffer[sbrExtrEnv->YBufferWriteOffset],
+- sbrExtrEnv->rBuffer + sbrExtrEnv->rBufferReadOffset,
+- sbrExtrEnv->iBuffer + sbrExtrEnv->rBufferReadOffset, h_con->noQmfBands,
+- sbrExtrEnv->no_cols, &hEnvChan->qmfScale, &sbrExtrEnv->YBufferScale[1]);
+- else
+- FDKsbrEnc_getEnergyFromCplxQmfData(
+- &sbrExtrEnv->YBuffer[sbrExtrEnv->YBufferWriteOffset],
+- sbrExtrEnv->rBuffer + sbrExtrEnv->rBufferReadOffset,
+- sbrExtrEnv->iBuffer + sbrExtrEnv->rBufferReadOffset, h_con->noQmfBands,
+- sbrExtrEnv->no_cols, &hEnvChan->qmfScale, &sbrExtrEnv->YBufferScale[1]);
+-
+- /* Energie values =
+- * sbrExtrEnv->YBuffer[sbrExtrEnv->YBufferWriteOffset][x].floatVal *
+- * (1<<2*7-sbrExtrEnv->YBufferScale[1]) */
+-
+- /*
+- Precalculation of Tonality Quotas COEFF Transform OK
+- */
+- FDKsbrEnc_CalculateTonalityQuotas(
+- &hEnvChan->TonCorr, sbrExtrEnv->rBuffer, sbrExtrEnv->iBuffer,
+- h_con->freqBandTable[HI][h_con->nSfb[HI]], hEnvChan->qmfScale);
+-
+- if (h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- FIXP_DBL tonality = FDKsbrEnc_GetTonality(
+- hEnvChan->TonCorr.quotaMatrix,
+- hEnvChan->TonCorr.numberOfEstimatesPerFrame,
+- hEnvChan->TonCorr.startIndexMatrix,
+- sbrExtrEnv->YBuffer + sbrExtrEnv->YBufferWriteOffset,
+- h_con->freqBandTable[HI][0] + 1, h_con->noQmfBands,
+- sbrExtrEnv->no_cols);
+-
+- hEnvChan->encEnvData.ton_HF[1] = hEnvChan->encEnvData.ton_HF[0];
+- hEnvChan->encEnvData.ton_HF[0] = tonality;
+-
+- /* tonality is scaled by 2^19/0.524288f (fract part of RELAXATION) */
+- hEnvChan->encEnvData.global_tonality =
+- (hEnvChan->encEnvData.ton_HF[0] >> 1) +
+- (hEnvChan->encEnvData.ton_HF[1] >> 1);
+- }
+-
+- /*
+- Transient detection COEFF Transform OK
+- */
+-
+- if (h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- FDKsbrEnc_fastTransientDetect(&hEnvChan->sbrFastTransientDetector,
+- sbrExtrEnv->YBuffer, sbrExtrEnv->YBufferScale,
+- sbrExtrEnv->YBufferWriteOffset,
+- eData->transient_info);
+-
+- } else {
+- FDKsbrEnc_transientDetect(
+- &hEnvChan->sbrTransientDetector, sbrExtrEnv->YBuffer,
+- sbrExtrEnv->YBufferScale, eData->transient_info,
+- sbrExtrEnv->YBufferWriteOffset, sbrExtrEnv->YBufferSzShift,
+- sbrExtrEnv->time_step, hEnvChan->SbrEnvFrame.frameMiddleSlot);
+- }
+-
+- /*
+- Generate flags for 2 env in a FIXFIX-frame.
+- Remove this function to get always 1 env per FIXFIX-frame.
+- */
+-
+- /*
+- frame Splitter COEFF Transform OK
+- */
+- FDKsbrEnc_frameSplitter(
+- sbrExtrEnv->YBuffer, sbrExtrEnv->YBufferScale,
+- &hEnvChan->sbrTransientDetector, h_con->freqBandTable[1],
+- eData->transient_info, sbrExtrEnv->YBufferWriteOffset,
+- sbrExtrEnv->YBufferSzShift, h_con->nSfb[1], sbrExtrEnv->time_step,
+- sbrExtrEnv->no_cols, &hEnvChan->encEnvData.global_tonality);
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief calculates the noise floor and the envelope values from the
+- energies, depending on framing and stereo mode
+-
+- FDKsbrEnc_extractSbrEnvelope is the main function for encoding and writing the
+- envelope and the noise floor. The function includes the following processes:
+-
+- -Determine time/frequency division of current granule.
+- -Sending transient info to bitstream.
+- -Set amp_res to 1.5 dB if the current frame contains only one envelope.
+- -Lock dynamic bandwidth frequency change if the next envelope not starts on a
+- frame boundary.
+- -MDCT transposer (needed to detect where harmonics will be missing).
+- -Spectrum Estimation (used for pulse train and missing harmonics detection).
+- -Pulse train detection.
+- -Inverse Filtering detection.
+- -Waveform Coding.
+- -Missing Harmonics detection.
+- -Extract envelope of current frame.
+- -Noise floor estimation.
+- -Noise floor quantisation and coding.
+- -Encode envelope of current frame.
+- -Send the encoded data to the bitstream.
+- -Write to bitstream.
+-
+-****************************************************************************/
+-
+-LNK_SECTION_CODE_L1
+-void FDKsbrEnc_extractSbrEnvelope2(
+- HANDLE_SBR_CONFIG_DATA h_con, /*! handle to config data */
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData, HANDLE_ENV_CHANNEL h_envChan0,
+- HANDLE_ENV_CHANNEL h_envChan1, HANDLE_COMMON_DATA hCmonData,
+- SBR_ENV_TEMP_DATA *eData, SBR_FRAME_TEMP_DATA *fData, int clearOutput) {
+- HANDLE_ENV_CHANNEL h_envChan[MAX_NUM_CHANNELS] = {h_envChan0, h_envChan1};
+- int ch, i, j, c, YSzShift = h_envChan[0]->sbrExtractEnvelope.YBufferSzShift;
+-
+- SBR_STEREO_MODE stereoMode = h_con->stereoMode;
+- int nChannels = h_con->nChannels;
+- const int *v_tuning;
+- static const int v_tuningHEAAC[6] = {0, 2, 4, 0, 0, 0};
+-
+- static const int v_tuningELD[6] = {0, 2, 3, 0, 0, 0};
+-
+- if (h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)
+- v_tuning = v_tuningELD;
+- else
+- v_tuning = v_tuningHEAAC;
+-
+- /*
+- Select stereo mode.
+- */
+- if (stereoMode == SBR_COUPLING) {
+- if (eData[0].transient_info[1] && eData[1].transient_info[1]) {
+- eData[0].transient_info[0] =
+- fixMin(eData[1].transient_info[0], eData[0].transient_info[0]);
+- eData[1].transient_info[0] = eData[0].transient_info[0];
+- } else {
+- if (eData[0].transient_info[1] && !eData[1].transient_info[1]) {
+- eData[1].transient_info[0] = eData[0].transient_info[0];
+- } else {
+- if (!eData[0].transient_info[1] && eData[1].transient_info[1])
+- eData[0].transient_info[0] = eData[1].transient_info[0];
+- else {
+- eData[0].transient_info[0] =
+- fixMax(eData[1].transient_info[0], eData[0].transient_info[0]);
+- eData[1].transient_info[0] = eData[0].transient_info[0];
+- }
+- }
+- }
+- }
+-
+- /*
+- Determine time/frequency division of current granule
+- */
+- eData[0].frame_info = FDKsbrEnc_frameInfoGenerator(
+- &h_envChan[0]->SbrEnvFrame, eData[0].transient_info,
+- sbrBitstreamData->rightBorderFIX,
+- h_envChan[0]->sbrExtractEnvelope.pre_transient_info,
+- h_envChan[0]->encEnvData.ldGrid, v_tuning);
+-
+- h_envChan[0]->encEnvData.hSbrBSGrid = &h_envChan[0]->SbrEnvFrame.SbrGrid;
+-
+- /* AAC LD patch for transient prediction */
+- if (h_envChan[0]->encEnvData.ldGrid && eData[0].transient_info[2]) {
+- /* if next frame will start with transient, set shortEnv to
+- * numEnvelopes(shortend Envelope = shortEnv-1)*/
+- h_envChan[0]->SbrEnvFrame.SbrFrameInfo.shortEnv =
+- h_envChan[0]->SbrEnvFrame.SbrFrameInfo.nEnvelopes;
+- }
+-
+- switch (stereoMode) {
+- case SBR_LEFT_RIGHT:
+- case SBR_SWITCH_LRC:
+- eData[1].frame_info = FDKsbrEnc_frameInfoGenerator(
+- &h_envChan[1]->SbrEnvFrame, eData[1].transient_info,
+- sbrBitstreamData->rightBorderFIX,
+- h_envChan[1]->sbrExtractEnvelope.pre_transient_info,
+- h_envChan[1]->encEnvData.ldGrid, v_tuning);
+-
+- h_envChan[1]->encEnvData.hSbrBSGrid = &h_envChan[1]->SbrEnvFrame.SbrGrid;
+-
+- if (h_envChan[1]->encEnvData.ldGrid && eData[1].transient_info[2]) {
+- /* if next frame will start with transient, set shortEnv to
+- * numEnvelopes(shortend Envelope = shortEnv-1)*/
+- h_envChan[1]->SbrEnvFrame.SbrFrameInfo.shortEnv =
+- h_envChan[1]->SbrEnvFrame.SbrFrameInfo.nEnvelopes;
+- }
+-
+- /* compare left and right frame_infos */
+- if (eData[0].frame_info->nEnvelopes != eData[1].frame_info->nEnvelopes) {
+- stereoMode = SBR_LEFT_RIGHT;
+- } else {
+- for (i = 0; i < eData[0].frame_info->nEnvelopes + 1; i++) {
+- if (eData[0].frame_info->borders[i] !=
+- eData[1].frame_info->borders[i]) {
+- stereoMode = SBR_LEFT_RIGHT;
+- break;
+- }
+- }
+- for (i = 0; i < eData[0].frame_info->nEnvelopes; i++) {
+- if (eData[0].frame_info->freqRes[i] !=
+- eData[1].frame_info->freqRes[i]) {
+- stereoMode = SBR_LEFT_RIGHT;
+- break;
+- }
+- }
+- if (eData[0].frame_info->shortEnv != eData[1].frame_info->shortEnv) {
+- stereoMode = SBR_LEFT_RIGHT;
+- }
+- }
+- break;
+- case SBR_COUPLING:
+- eData[1].frame_info = eData[0].frame_info;
+- h_envChan[1]->encEnvData.hSbrBSGrid = &h_envChan[0]->SbrEnvFrame.SbrGrid;
+- break;
+- case SBR_MONO:
+- /* nothing to do */
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+-
+- for (ch = 0; ch < nChannels; ch++) {
+- HANDLE_ENV_CHANNEL hEnvChan = h_envChan[ch];
+- HANDLE_SBR_EXTRACT_ENVELOPE sbrExtrEnv = &hEnvChan->sbrExtractEnvelope;
+- SBR_ENV_TEMP_DATA *ed = &eData[ch];
+-
+- /*
+- Send transient info to bitstream and store for next call
+- */
+- sbrExtrEnv->pre_transient_info[0] = ed->transient_info[0]; /* tran_pos */
+- sbrExtrEnv->pre_transient_info[1] = ed->transient_info[1]; /* tran_flag */
+- hEnvChan->encEnvData.noOfEnvelopes = ed->nEnvelopes =
+- ed->frame_info->nEnvelopes; /* number of envelopes of current frame */
+-
+- /*
+- Check if the current frame is divided into one envelope only. If so, set
+- the amplitude resolution to 1.5 dB, otherwise may set back to chosen value
+- */
+- if ((hEnvChan->encEnvData.hSbrBSGrid->frameClass == FIXFIX) &&
+- (ed->nEnvelopes == 1)) {
+- if (h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- /* Note: global_tonaliy_float_value ==
+- ((float)hEnvChan->encEnvData.global_tonality/((INT64)(1)<<(31-(19+2)))/0.524288*(2.0/3.0)));
+- threshold_float_value ==
+- ((float)h_con->thresholdAmpResFF_m/((INT64)(1)<<(31-(h_con->thresholdAmpResFF_e)))/0.524288*(2.0/3.0)));
+- */
+- /* decision of SBR_AMP_RES */
+- if (fIsLessThan(/* global_tonality > threshold ? */
+- h_con->thresholdAmpResFF_m, h_con->thresholdAmpResFF_e,
+- hEnvChan->encEnvData.global_tonality,
+- RELAXATION_SHIFT + 2)) {
+- hEnvChan->encEnvData.currentAmpResFF = SBR_AMP_RES_1_5;
+- } else {
+- hEnvChan->encEnvData.currentAmpResFF = SBR_AMP_RES_3_0;
+- }
+- } else
+- hEnvChan->encEnvData.currentAmpResFF = SBR_AMP_RES_1_5;
+-
+- if (hEnvChan->encEnvData.currentAmpResFF !=
+- hEnvChan->encEnvData.init_sbr_amp_res) {
+- FDKsbrEnc_InitSbrHuffmanTables(
+- &hEnvChan->encEnvData, &hEnvChan->sbrCodeEnvelope,
+- &hEnvChan->sbrCodeNoiseFloor, hEnvChan->encEnvData.currentAmpResFF);
+- }
+- } else {
+- if (sbrHeaderData->sbr_amp_res != hEnvChan->encEnvData.init_sbr_amp_res) {
+- FDKsbrEnc_InitSbrHuffmanTables(
+- &hEnvChan->encEnvData, &hEnvChan->sbrCodeEnvelope,
+- &hEnvChan->sbrCodeNoiseFloor, sbrHeaderData->sbr_amp_res);
+- }
+- }
+-
+- if (!clearOutput) {
+- /*
+- Tonality correction parameter extraction (inverse filtering level, noise
+- floor additional sines).
+- */
+- FDKsbrEnc_TonCorrParamExtr(
+- &hEnvChan->TonCorr, hEnvChan->encEnvData.sbr_invf_mode_vec,
+- ed->noiseFloor, &hEnvChan->encEnvData.addHarmonicFlag,
+- hEnvChan->encEnvData.addHarmonic, sbrExtrEnv->envelopeCompensation,
+- ed->frame_info, ed->transient_info, h_con->freqBandTable[HI],
+- h_con->nSfb[HI], hEnvChan->encEnvData.sbr_xpos_mode,
+- h_con->sbrSyntaxFlags);
+- }
+-
+- /* Low energy in low band fix */
+- if (hEnvChan->sbrTransientDetector.prevLowBandEnergy <
+- hEnvChan->sbrTransientDetector.prevHighBandEnergy &&
+- hEnvChan->sbrTransientDetector.prevHighBandEnergy > FL2FX_DBL(0.03)
+- /* The fix needs the non-fast transient detector running.
+- It sets prevLowBandEnergy and prevHighBandEnergy. */
+- && !(h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)) {
+- hEnvChan->fLevelProtect = 1;
+-
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++)
+- hEnvChan->encEnvData.sbr_invf_mode_vec[i] = INVF_HIGH_LEVEL;
+- } else {
+- hEnvChan->fLevelProtect = 0;
+- }
+-
+- hEnvChan->encEnvData.sbr_invf_mode =
+- hEnvChan->encEnvData.sbr_invf_mode_vec[0];
+-
+- hEnvChan->encEnvData.noOfnoisebands =
+- hEnvChan->TonCorr.sbrNoiseFloorEstimate.noNoiseBands;
+-
+- } /* ch */
+-
+- /*
+- Save number of scf bands per envelope
+- */
+- for (ch = 0; ch < nChannels; ch++) {
+- for (i = 0; i < eData[ch].nEnvelopes; i++) {
+- h_envChan[ch]->encEnvData.noScfBands[i] =
+- (eData[ch].frame_info->freqRes[i] == FREQ_RES_HIGH
+- ? h_con->nSfb[FREQ_RES_HIGH]
+- : h_con->nSfb[FREQ_RES_LOW]);
+- }
+- }
+-
+- /*
+- Extract envelope of current frame.
+- */
+- switch (stereoMode) {
+- case SBR_MONO:
+- calculateSbrEnvelope(h_envChan[0]->sbrExtractEnvelope.YBuffer, NULL,
+- h_envChan[0]->sbrExtractEnvelope.YBufferScale, NULL,
+- eData[0].frame_info, eData[0].sfb_nrg, NULL, h_con,
+- h_envChan[0], SBR_MONO, NULL, YSzShift);
+- break;
+- case SBR_LEFT_RIGHT:
+- calculateSbrEnvelope(h_envChan[0]->sbrExtractEnvelope.YBuffer, NULL,
+- h_envChan[0]->sbrExtractEnvelope.YBufferScale, NULL,
+- eData[0].frame_info, eData[0].sfb_nrg, NULL, h_con,
+- h_envChan[0], SBR_MONO, NULL, YSzShift);
+- calculateSbrEnvelope(h_envChan[1]->sbrExtractEnvelope.YBuffer, NULL,
+- h_envChan[1]->sbrExtractEnvelope.YBufferScale, NULL,
+- eData[1].frame_info, eData[1].sfb_nrg, NULL, h_con,
+- h_envChan[1], SBR_MONO, NULL, YSzShift);
+- break;
+- case SBR_COUPLING:
+- calculateSbrEnvelope(h_envChan[0]->sbrExtractEnvelope.YBuffer,
+- h_envChan[1]->sbrExtractEnvelope.YBuffer,
+- h_envChan[0]->sbrExtractEnvelope.YBufferScale,
+- h_envChan[1]->sbrExtractEnvelope.YBufferScale,
+- eData[0].frame_info, eData[0].sfb_nrg,
+- eData[1].sfb_nrg, h_con, h_envChan[0], SBR_COUPLING,
+- &fData->maxQuantError, YSzShift);
+- break;
+- case SBR_SWITCH_LRC:
+- calculateSbrEnvelope(h_envChan[0]->sbrExtractEnvelope.YBuffer, NULL,
+- h_envChan[0]->sbrExtractEnvelope.YBufferScale, NULL,
+- eData[0].frame_info, eData[0].sfb_nrg, NULL, h_con,
+- h_envChan[0], SBR_MONO, NULL, YSzShift);
+- calculateSbrEnvelope(h_envChan[1]->sbrExtractEnvelope.YBuffer, NULL,
+- h_envChan[1]->sbrExtractEnvelope.YBufferScale, NULL,
+- eData[1].frame_info, eData[1].sfb_nrg, NULL, h_con,
+- h_envChan[1], SBR_MONO, NULL, YSzShift);
+- calculateSbrEnvelope(h_envChan[0]->sbrExtractEnvelope.YBuffer,
+- h_envChan[1]->sbrExtractEnvelope.YBuffer,
+- h_envChan[0]->sbrExtractEnvelope.YBufferScale,
+- h_envChan[1]->sbrExtractEnvelope.YBufferScale,
+- eData[0].frame_info, eData[0].sfb_nrg_coupling,
+- eData[1].sfb_nrg_coupling, h_con, h_envChan[0],
+- SBR_COUPLING, &fData->maxQuantError, YSzShift);
+- break;
+- }
+-
+- /*
+- Noise floor quantisation and coding.
+- */
+-
+- switch (stereoMode) {
+- case SBR_MONO:
+- sbrNoiseFloorLevelsQuantisation(eData[0].noise_level, eData[0].noiseFloor,
+- 0);
+-
+- FDKsbrEnc_codeEnvelope(eData[0].noise_level, fData->res,
+- &h_envChan[0]->sbrCodeNoiseFloor,
+- h_envChan[0]->encEnvData.domain_vec_noise, 0,
+- (eData[0].frame_info->nEnvelopes > 1 ? 2 : 1), 0,
+- sbrBitstreamData->HeaderActive);
+-
+- break;
+- case SBR_LEFT_RIGHT:
+- sbrNoiseFloorLevelsQuantisation(eData[0].noise_level, eData[0].noiseFloor,
+- 0);
+-
+- FDKsbrEnc_codeEnvelope(eData[0].noise_level, fData->res,
+- &h_envChan[0]->sbrCodeNoiseFloor,
+- h_envChan[0]->encEnvData.domain_vec_noise, 0,
+- (eData[0].frame_info->nEnvelopes > 1 ? 2 : 1), 0,
+- sbrBitstreamData->HeaderActive);
+-
+- sbrNoiseFloorLevelsQuantisation(eData[1].noise_level, eData[1].noiseFloor,
+- 0);
+-
+- FDKsbrEnc_codeEnvelope(eData[1].noise_level, fData->res,
+- &h_envChan[1]->sbrCodeNoiseFloor,
+- h_envChan[1]->encEnvData.domain_vec_noise, 0,
+- (eData[1].frame_info->nEnvelopes > 1 ? 2 : 1), 0,
+- sbrBitstreamData->HeaderActive);
+-
+- break;
+-
+- case SBR_COUPLING:
+- coupleNoiseFloor(eData[0].noiseFloor, eData[1].noiseFloor);
+-
+- sbrNoiseFloorLevelsQuantisation(eData[0].noise_level, eData[0].noiseFloor,
+- 0);
+-
+- FDKsbrEnc_codeEnvelope(eData[0].noise_level, fData->res,
+- &h_envChan[0]->sbrCodeNoiseFloor,
+- h_envChan[0]->encEnvData.domain_vec_noise, 1,
+- (eData[0].frame_info->nEnvelopes > 1 ? 2 : 1), 0,
+- sbrBitstreamData->HeaderActive);
+-
+- sbrNoiseFloorLevelsQuantisation(eData[1].noise_level, eData[1].noiseFloor,
+- 1);
+-
+- FDKsbrEnc_codeEnvelope(eData[1].noise_level, fData->res,
+- &h_envChan[1]->sbrCodeNoiseFloor,
+- h_envChan[1]->encEnvData.domain_vec_noise, 1,
+- (eData[1].frame_info->nEnvelopes > 1 ? 2 : 1), 1,
+- sbrBitstreamData->HeaderActive);
+-
+- break;
+- case SBR_SWITCH_LRC:
+- sbrNoiseFloorLevelsQuantisation(eData[0].noise_level, eData[0].noiseFloor,
+- 0);
+- sbrNoiseFloorLevelsQuantisation(eData[1].noise_level, eData[1].noiseFloor,
+- 0);
+- coupleNoiseFloor(eData[0].noiseFloor, eData[1].noiseFloor);
+- sbrNoiseFloorLevelsQuantisation(eData[0].noise_level_coupling,
+- eData[0].noiseFloor, 0);
+- sbrNoiseFloorLevelsQuantisation(eData[1].noise_level_coupling,
+- eData[1].noiseFloor, 1);
+- break;
+- }
+-
+- /*
+- Encode envelope of current frame.
+- */
+- switch (stereoMode) {
+- case SBR_MONO:
+- sbrHeaderData->coupling = 0;
+- h_envChan[0]->encEnvData.balance = 0;
+- FDKsbrEnc_codeEnvelope(
+- eData[0].sfb_nrg, eData[0].frame_info->freqRes,
+- &h_envChan[0]->sbrCodeEnvelope, h_envChan[0]->encEnvData.domain_vec,
+- sbrHeaderData->coupling, eData[0].frame_info->nEnvelopes, 0,
+- sbrBitstreamData->HeaderActive);
+- break;
+- case SBR_LEFT_RIGHT:
+- sbrHeaderData->coupling = 0;
+-
+- h_envChan[0]->encEnvData.balance = 0;
+- h_envChan[1]->encEnvData.balance = 0;
+-
+- FDKsbrEnc_codeEnvelope(
+- eData[0].sfb_nrg, eData[0].frame_info->freqRes,
+- &h_envChan[0]->sbrCodeEnvelope, h_envChan[0]->encEnvData.domain_vec,
+- sbrHeaderData->coupling, eData[0].frame_info->nEnvelopes, 0,
+- sbrBitstreamData->HeaderActive);
+- FDKsbrEnc_codeEnvelope(
+- eData[1].sfb_nrg, eData[1].frame_info->freqRes,
+- &h_envChan[1]->sbrCodeEnvelope, h_envChan[1]->encEnvData.domain_vec,
+- sbrHeaderData->coupling, eData[1].frame_info->nEnvelopes, 0,
+- sbrBitstreamData->HeaderActive);
+- break;
+- case SBR_COUPLING:
+- sbrHeaderData->coupling = 1;
+- h_envChan[0]->encEnvData.balance = 0;
+- h_envChan[1]->encEnvData.balance = 1;
+-
+- FDKsbrEnc_codeEnvelope(
+- eData[0].sfb_nrg, eData[0].frame_info->freqRes,
+- &h_envChan[0]->sbrCodeEnvelope, h_envChan[0]->encEnvData.domain_vec,
+- sbrHeaderData->coupling, eData[0].frame_info->nEnvelopes, 0,
+- sbrBitstreamData->HeaderActive);
+- FDKsbrEnc_codeEnvelope(
+- eData[1].sfb_nrg, eData[1].frame_info->freqRes,
+- &h_envChan[1]->sbrCodeEnvelope, h_envChan[1]->encEnvData.domain_vec,
+- sbrHeaderData->coupling, eData[1].frame_info->nEnvelopes, 1,
+- sbrBitstreamData->HeaderActive);
+- break;
+- case SBR_SWITCH_LRC: {
+- INT payloadbitsLR;
+- INT payloadbitsCOUPLING;
+-
+- SCHAR sfbNrgPrevTemp[MAX_NUM_CHANNELS][MAX_FREQ_COEFFS];
+- SCHAR noisePrevTemp[MAX_NUM_CHANNELS][MAX_NUM_NOISE_COEFFS];
+- INT upDateNrgTemp[MAX_NUM_CHANNELS];
+- INT upDateNoiseTemp[MAX_NUM_CHANNELS];
+- INT domainVecTemp[MAX_NUM_CHANNELS][MAX_ENVELOPES];
+- INT domainVecNoiseTemp[MAX_NUM_CHANNELS][MAX_ENVELOPES];
+-
+- INT tempFlagRight = 0;
+- INT tempFlagLeft = 0;
+-
+- /*
+- Store previous values, in order to be able to "undo" what is being
+- done.
+- */
+-
+- for (ch = 0; ch < nChannels; ch++) {
+- FDKmemcpy(sfbNrgPrevTemp[ch],
+- h_envChan[ch]->sbrCodeEnvelope.sfb_nrg_prev,
+- MAX_FREQ_COEFFS * sizeof(SCHAR));
+-
+- FDKmemcpy(noisePrevTemp[ch],
+- h_envChan[ch]->sbrCodeNoiseFloor.sfb_nrg_prev,
+- MAX_NUM_NOISE_COEFFS * sizeof(SCHAR));
+-
+- upDateNrgTemp[ch] = h_envChan[ch]->sbrCodeEnvelope.upDate;
+- upDateNoiseTemp[ch] = h_envChan[ch]->sbrCodeNoiseFloor.upDate;
+-
+- /*
+- forbid time coding in the first envelope in case of a different
+- previous stereomode
+- */
+- if (sbrHeaderData->prev_coupling) {
+- h_envChan[ch]->sbrCodeEnvelope.upDate = 0;
+- h_envChan[ch]->sbrCodeNoiseFloor.upDate = 0;
+- }
+- } /* ch */
+-
+- /*
+- Code ordinary Left/Right stereo
+- */
+- FDKsbrEnc_codeEnvelope(eData[0].sfb_nrg, eData[0].frame_info->freqRes,
+- &h_envChan[0]->sbrCodeEnvelope,
+- h_envChan[0]->encEnvData.domain_vec, 0,
+- eData[0].frame_info->nEnvelopes, 0,
+- sbrBitstreamData->HeaderActive);
+- FDKsbrEnc_codeEnvelope(eData[1].sfb_nrg, eData[1].frame_info->freqRes,
+- &h_envChan[1]->sbrCodeEnvelope,
+- h_envChan[1]->encEnvData.domain_vec, 0,
+- eData[1].frame_info->nEnvelopes, 0,
+- sbrBitstreamData->HeaderActive);
+-
+- c = 0;
+- for (i = 0; i < eData[0].nEnvelopes; i++) {
+- for (j = 0; j < h_envChan[0]->encEnvData.noScfBands[i]; j++) {
+- h_envChan[0]->encEnvData.ienvelope[i][j] = eData[0].sfb_nrg[c];
+- h_envChan[1]->encEnvData.ienvelope[i][j] = eData[1].sfb_nrg[c];
+- c++;
+- }
+- }
+-
+- FDKsbrEnc_codeEnvelope(eData[0].noise_level, fData->res,
+- &h_envChan[0]->sbrCodeNoiseFloor,
+- h_envChan[0]->encEnvData.domain_vec_noise, 0,
+- (eData[0].frame_info->nEnvelopes > 1 ? 2 : 1), 0,
+- sbrBitstreamData->HeaderActive);
+-
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++)
+- h_envChan[0]->encEnvData.sbr_noise_levels[i] = eData[0].noise_level[i];
+-
+- FDKsbrEnc_codeEnvelope(eData[1].noise_level, fData->res,
+- &h_envChan[1]->sbrCodeNoiseFloor,
+- h_envChan[1]->encEnvData.domain_vec_noise, 0,
+- (eData[1].frame_info->nEnvelopes > 1 ? 2 : 1), 0,
+- sbrBitstreamData->HeaderActive);
+-
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++)
+- h_envChan[1]->encEnvData.sbr_noise_levels[i] = eData[1].noise_level[i];
+-
+- sbrHeaderData->coupling = 0;
+- h_envChan[0]->encEnvData.balance = 0;
+- h_envChan[1]->encEnvData.balance = 0;
+-
+- payloadbitsLR = FDKsbrEnc_CountSbrChannelPairElement(
+- sbrHeaderData, hParametricStereo, sbrBitstreamData,
+- &h_envChan[0]->encEnvData, &h_envChan[1]->encEnvData, hCmonData,
+- h_con->sbrSyntaxFlags);
+-
+- /*
+- swap saved stored with current values
+- */
+- for (ch = 0; ch < nChannels; ch++) {
+- INT itmp;
+- for (i = 0; i < MAX_FREQ_COEFFS; i++) {
+- /*
+- swap sfb energies
+- */
+- itmp = h_envChan[ch]->sbrCodeEnvelope.sfb_nrg_prev[i];
+- h_envChan[ch]->sbrCodeEnvelope.sfb_nrg_prev[i] =
+- sfbNrgPrevTemp[ch][i];
+- sfbNrgPrevTemp[ch][i] = itmp;
+- }
+- for (i = 0; i < MAX_NUM_NOISE_COEFFS; i++) {
+- /*
+- swap noise energies
+- */
+- itmp = h_envChan[ch]->sbrCodeNoiseFloor.sfb_nrg_prev[i];
+- h_envChan[ch]->sbrCodeNoiseFloor.sfb_nrg_prev[i] =
+- noisePrevTemp[ch][i];
+- noisePrevTemp[ch][i] = itmp;
+- }
+- /* swap update flags */
+- itmp = h_envChan[ch]->sbrCodeEnvelope.upDate;
+- h_envChan[ch]->sbrCodeEnvelope.upDate = upDateNrgTemp[ch];
+- upDateNrgTemp[ch] = itmp;
+-
+- itmp = h_envChan[ch]->sbrCodeNoiseFloor.upDate;
+- h_envChan[ch]->sbrCodeNoiseFloor.upDate = upDateNoiseTemp[ch];
+- upDateNoiseTemp[ch] = itmp;
+-
+- /*
+- save domain vecs
+- */
+- FDKmemcpy(domainVecTemp[ch], h_envChan[ch]->encEnvData.domain_vec,
+- sizeof(INT) * MAX_ENVELOPES);
+- FDKmemcpy(domainVecNoiseTemp[ch],
+- h_envChan[ch]->encEnvData.domain_vec_noise,
+- sizeof(INT) * MAX_ENVELOPES);
+-
+- /*
+- forbid time coding in the first envelope in case of a different
+- previous stereomode
+- */
+-
+- if (!sbrHeaderData->prev_coupling) {
+- h_envChan[ch]->sbrCodeEnvelope.upDate = 0;
+- h_envChan[ch]->sbrCodeNoiseFloor.upDate = 0;
+- }
+- } /* ch */
+-
+- /*
+- Coupling
+- */
+-
+- FDKsbrEnc_codeEnvelope(
+- eData[0].sfb_nrg_coupling, eData[0].frame_info->freqRes,
+- &h_envChan[0]->sbrCodeEnvelope, h_envChan[0]->encEnvData.domain_vec,
+- 1, eData[0].frame_info->nEnvelopes, 0,
+- sbrBitstreamData->HeaderActive);
+-
+- FDKsbrEnc_codeEnvelope(
+- eData[1].sfb_nrg_coupling, eData[1].frame_info->freqRes,
+- &h_envChan[1]->sbrCodeEnvelope, h_envChan[1]->encEnvData.domain_vec,
+- 1, eData[1].frame_info->nEnvelopes, 1,
+- sbrBitstreamData->HeaderActive);
+-
+- c = 0;
+- for (i = 0; i < eData[0].nEnvelopes; i++) {
+- for (j = 0; j < h_envChan[0]->encEnvData.noScfBands[i]; j++) {
+- h_envChan[0]->encEnvData.ienvelope[i][j] =
+- eData[0].sfb_nrg_coupling[c];
+- h_envChan[1]->encEnvData.ienvelope[i][j] =
+- eData[1].sfb_nrg_coupling[c];
+- c++;
+- }
+- }
+-
+- FDKsbrEnc_codeEnvelope(eData[0].noise_level_coupling, fData->res,
+- &h_envChan[0]->sbrCodeNoiseFloor,
+- h_envChan[0]->encEnvData.domain_vec_noise, 1,
+- (eData[0].frame_info->nEnvelopes > 1 ? 2 : 1), 0,
+- sbrBitstreamData->HeaderActive);
+-
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++)
+- h_envChan[0]->encEnvData.sbr_noise_levels[i] =
+- eData[0].noise_level_coupling[i];
+-
+- FDKsbrEnc_codeEnvelope(eData[1].noise_level_coupling, fData->res,
+- &h_envChan[1]->sbrCodeNoiseFloor,
+- h_envChan[1]->encEnvData.domain_vec_noise, 1,
+- (eData[1].frame_info->nEnvelopes > 1 ? 2 : 1), 1,
+- sbrBitstreamData->HeaderActive);
+-
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++)
+- h_envChan[1]->encEnvData.sbr_noise_levels[i] =
+- eData[1].noise_level_coupling[i];
+-
+- sbrHeaderData->coupling = 1;
+-
+- h_envChan[0]->encEnvData.balance = 0;
+- h_envChan[1]->encEnvData.balance = 1;
+-
+- tempFlagLeft = h_envChan[0]->encEnvData.addHarmonicFlag;
+- tempFlagRight = h_envChan[1]->encEnvData.addHarmonicFlag;
+-
+- payloadbitsCOUPLING = FDKsbrEnc_CountSbrChannelPairElement(
+- sbrHeaderData, hParametricStereo, sbrBitstreamData,
+- &h_envChan[0]->encEnvData, &h_envChan[1]->encEnvData, hCmonData,
+- h_con->sbrSyntaxFlags);
+-
+- h_envChan[0]->encEnvData.addHarmonicFlag = tempFlagLeft;
+- h_envChan[1]->encEnvData.addHarmonicFlag = tempFlagRight;
+-
+- if (payloadbitsCOUPLING < payloadbitsLR) {
+- /*
+- copy coded coupling envelope and noise data to l/r
+- */
+- for (ch = 0; ch < nChannels; ch++) {
+- SBR_ENV_TEMP_DATA *ed = &eData[ch];
+- FDKmemcpy(ed->sfb_nrg, ed->sfb_nrg_coupling,
+- MAX_NUM_ENVELOPE_VALUES * sizeof(SCHAR));
+- FDKmemcpy(ed->noise_level, ed->noise_level_coupling,
+- MAX_NUM_NOISE_VALUES * sizeof(SCHAR));
+- }
+-
+- sbrHeaderData->coupling = 1;
+- h_envChan[0]->encEnvData.balance = 0;
+- h_envChan[1]->encEnvData.balance = 1;
+- } else {
+- /*
+- restore saved l/r items
+- */
+- for (ch = 0; ch < nChannels; ch++) {
+- FDKmemcpy(h_envChan[ch]->sbrCodeEnvelope.sfb_nrg_prev,
+- sfbNrgPrevTemp[ch], MAX_FREQ_COEFFS * sizeof(SCHAR));
+-
+- h_envChan[ch]->sbrCodeEnvelope.upDate = upDateNrgTemp[ch];
+-
+- FDKmemcpy(h_envChan[ch]->sbrCodeNoiseFloor.sfb_nrg_prev,
+- noisePrevTemp[ch], MAX_NUM_NOISE_COEFFS * sizeof(SCHAR));
+-
+- FDKmemcpy(h_envChan[ch]->encEnvData.domain_vec, domainVecTemp[ch],
+- sizeof(INT) * MAX_ENVELOPES);
+- FDKmemcpy(h_envChan[ch]->encEnvData.domain_vec_noise,
+- domainVecNoiseTemp[ch], sizeof(INT) * MAX_ENVELOPES);
+-
+- h_envChan[ch]->sbrCodeNoiseFloor.upDate = upDateNoiseTemp[ch];
+- }
+-
+- sbrHeaderData->coupling = 0;
+- h_envChan[0]->encEnvData.balance = 0;
+- h_envChan[1]->encEnvData.balance = 0;
+- }
+- } break;
+- } /* switch */
+-
+- /* tell the envelope encoders how long it has been, since we last sent
+- a frame starting with a dF-coded envelope */
+- if (stereoMode == SBR_MONO) {
+- if (h_envChan[0]->encEnvData.domain_vec[0] == TIME)
+- h_envChan[0]->sbrCodeEnvelope.dF_edge_incr_fac++;
+- else
+- h_envChan[0]->sbrCodeEnvelope.dF_edge_incr_fac = 0;
+- } else {
+- if (h_envChan[0]->encEnvData.domain_vec[0] == TIME ||
+- h_envChan[1]->encEnvData.domain_vec[0] == TIME) {
+- h_envChan[0]->sbrCodeEnvelope.dF_edge_incr_fac++;
+- h_envChan[1]->sbrCodeEnvelope.dF_edge_incr_fac++;
+- } else {
+- h_envChan[0]->sbrCodeEnvelope.dF_edge_incr_fac = 0;
+- h_envChan[1]->sbrCodeEnvelope.dF_edge_incr_fac = 0;
+- }
+- }
+-
+- /*
+- Send the encoded data to the bitstream
+- */
+- for (ch = 0; ch < nChannels; ch++) {
+- SBR_ENV_TEMP_DATA *ed = &eData[ch];
+- c = 0;
+- for (i = 0; i < ed->nEnvelopes; i++) {
+- for (j = 0; j < h_envChan[ch]->encEnvData.noScfBands[i]; j++) {
+- h_envChan[ch]->encEnvData.ienvelope[i][j] = ed->sfb_nrg[c];
+-
+- c++;
+- }
+- }
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++) {
+- h_envChan[ch]->encEnvData.sbr_noise_levels[i] = ed->noise_level[i];
+- }
+- } /* ch */
+-
+- /*
+- Write bitstream
+- */
+- if (nChannels == 2) {
+- FDKsbrEnc_WriteEnvChannelPairElement(
+- sbrHeaderData, hParametricStereo, sbrBitstreamData,
+- &h_envChan[0]->encEnvData, &h_envChan[1]->encEnvData, hCmonData,
+- h_con->sbrSyntaxFlags);
+- } else {
+- FDKsbrEnc_WriteEnvSingleChannelElement(
+- sbrHeaderData, hParametricStereo, sbrBitstreamData,
+- &h_envChan[0]->encEnvData, hCmonData, h_con->sbrSyntaxFlags);
+- }
+-
+- /*
+- * Update buffers.
+- */
+- for (ch = 0; ch < nChannels; ch++) {
+- int YBufferLength = h_envChan[ch]->sbrExtractEnvelope.no_cols >>
+- h_envChan[ch]->sbrExtractEnvelope.YBufferSzShift;
+- for (i = 0; i < h_envChan[ch]->sbrExtractEnvelope.YBufferWriteOffset; i++) {
+- FDKmemcpy(h_envChan[ch]->sbrExtractEnvelope.YBuffer[i],
+- h_envChan[ch]->sbrExtractEnvelope.YBuffer[i + YBufferLength],
+- sizeof(FIXP_DBL) * 64);
+- }
+- h_envChan[ch]->sbrExtractEnvelope.YBufferScale[0] =
+- h_envChan[ch]->sbrExtractEnvelope.YBufferScale[1];
+- }
+-
+- sbrHeaderData->prev_coupling = sbrHeaderData->coupling;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief creates an envelope extractor handle
+-
+- \return error status
+-
+-****************************************************************************/
+-INT FDKsbrEnc_CreateExtractSbrEnvelope(HANDLE_SBR_EXTRACT_ENVELOPE hSbrCut,
+- INT channel, INT chInEl,
+- UCHAR *dynamic_RAM) {
+- INT i;
+- FIXP_DBL *rBuffer, *iBuffer;
+- INT n;
+- FIXP_DBL *YBufferDyn;
+-
+- FDKmemclear(hSbrCut, sizeof(SBR_EXTRACT_ENVELOPE));
+-
+- if (NULL == (hSbrCut->p_YBuffer = GetRam_Sbr_envYBuffer(channel))) {
+- goto bail;
+- }
+-
+- for (i = 0; i < (32 >> 1); i++) {
+- hSbrCut->YBuffer[i] = hSbrCut->p_YBuffer + (i * 64);
+- }
+- YBufferDyn = GetRam_Sbr_envYBuffer(chInEl, dynamic_RAM);
+- for (n = 0; i < 32; i++, n++) {
+- hSbrCut->YBuffer[i] = YBufferDyn + (n * 64);
+- }
+-
+- rBuffer = GetRam_Sbr_envRBuffer(0, dynamic_RAM);
+- iBuffer = GetRam_Sbr_envIBuffer(0, dynamic_RAM);
+-
+- for (i = 0; i < 32; i++) {
+- hSbrCut->rBuffer[i] = rBuffer + (i * 64);
+- hSbrCut->iBuffer[i] = iBuffer + (i * 64);
+- }
+-
+- return 0;
+-
+-bail:
+- FDKsbrEnc_deleteExtractSbrEnvelope(hSbrCut);
+-
+- return -1;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Initialize an envelope extractor instance.
+-
+- \return error status
+-
+-****************************************************************************/
+-INT FDKsbrEnc_InitExtractSbrEnvelope(HANDLE_SBR_EXTRACT_ENVELOPE hSbrCut,
+- int no_cols, int no_rows, int start_index,
+- int time_slots, int time_step,
+- int tran_off, ULONG statesInitFlag,
+- int chInEl, UCHAR *dynamic_RAM,
+- UINT sbrSyntaxFlags) {
+- int YBufferLength, rBufferLength;
+- int i;
+-
+- if (sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- int off = TRANSIENT_OFFSET_LD;
+- hSbrCut->YBufferWriteOffset = (no_cols >> 1) + off * time_step;
+- } else {
+- hSbrCut->YBufferWriteOffset = tran_off * time_step;
+- }
+- hSbrCut->rBufferReadOffset = 0;
+-
+- YBufferLength = hSbrCut->YBufferWriteOffset + no_cols;
+- rBufferLength = no_cols;
+-
+- hSbrCut->pre_transient_info[0] = 0;
+- hSbrCut->pre_transient_info[1] = 0;
+-
+- hSbrCut->no_cols = no_cols;
+- hSbrCut->no_rows = no_rows;
+- hSbrCut->start_index = start_index;
+-
+- hSbrCut->time_slots = time_slots;
+- hSbrCut->time_step = time_step;
+-
+- FDK_ASSERT(no_rows <= 64);
+-
+- /* Use half the Energy values if time step is 2 or greater */
+- if (time_step >= 2)
+- hSbrCut->YBufferSzShift = 1;
+- else
+- hSbrCut->YBufferSzShift = 0;
+-
+- YBufferLength >>= hSbrCut->YBufferSzShift;
+- hSbrCut->YBufferWriteOffset >>= hSbrCut->YBufferSzShift;
+-
+- FDK_ASSERT(YBufferLength <= 32);
+-
+- FIXP_DBL *YBufferDyn = GetRam_Sbr_envYBuffer(chInEl, dynamic_RAM);
+- INT n = 0;
+- for (i = (32 >> 1); i < 32; i++, n++) {
+- hSbrCut->YBuffer[i] = YBufferDyn + (n * 64);
+- }
+-
+- if (statesInitFlag) {
+- for (i = 0; i < YBufferLength; i++) {
+- FDKmemclear(hSbrCut->YBuffer[i], 64 * sizeof(FIXP_DBL));
+- }
+- }
+-
+- for (i = 0; i < rBufferLength; i++) {
+- FDKmemclear(hSbrCut->rBuffer[i], 64 * sizeof(FIXP_DBL));
+- FDKmemclear(hSbrCut->iBuffer[i], 64 * sizeof(FIXP_DBL));
+- }
+-
+- FDKmemclear(hSbrCut->envelopeCompensation, sizeof(UCHAR) * MAX_FREQ_COEFFS);
+-
+- if (statesInitFlag) {
+- hSbrCut->YBufferScale[0] = hSbrCut->YBufferScale[1] = FRACT_BITS - 1;
+- }
+-
+- return (0);
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief deinitializes an envelope extractor handle
+-
+- \return void
+-
+-****************************************************************************/
+-
+-void FDKsbrEnc_deleteExtractSbrEnvelope(HANDLE_SBR_EXTRACT_ENVELOPE hSbrCut) {
+- if (hSbrCut) {
+- FreeRam_Sbr_envYBuffer(&hSbrCut->p_YBuffer);
+- }
+-}
+-
+-INT FDKsbrEnc_GetEnvEstDelay(HANDLE_SBR_EXTRACT_ENVELOPE hSbr) {
+- return hSbr->no_rows *
+- ((hSbr->YBufferWriteOffset) *
+- 2 /* mult 2 because nrg's are grouped half */
+- - hSbr->rBufferReadOffset); /* in reference hold half spec and calc
+- nrg's on overlapped spec */
+-}
+diff --git a/libSBRenc/src/env_est.h b/libSBRenc/src/env_est.h
+deleted file mode 100644
+index 006f55b..0000000
+--- a/libSBRenc/src/env_est.h
++++ /dev/null
+@@ -1,223 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Envelope estimation structs and prototypes $Revision: 92790 $
+-*/
+-#ifndef ENV_EST_H
+-#define ENV_EST_H
+-
+-#include "sbr_def.h"
+-#include "sbr_encoder.h" /* SBR econfig structs */
+-#include "ps_main.h"
+-#include "bit_sbr.h"
+-#include "fram_gen.h"
+-#include "tran_det.h"
+-#include "code_env.h"
+-#include "ton_corr.h"
+-
+-typedef struct {
+- FIXP_DBL *rBuffer[32];
+- FIXP_DBL *iBuffer[32];
+-
+- FIXP_DBL *p_YBuffer;
+-
+- FIXP_DBL *YBuffer[32];
+- int YBufferScale[2];
+-
+- UCHAR envelopeCompensation[MAX_FREQ_COEFFS];
+- UCHAR pre_transient_info[2];
+-
+- int YBufferWriteOffset;
+- int YBufferSzShift;
+- int rBufferReadOffset;
+-
+- int no_cols;
+- int no_rows;
+- int start_index;
+-
+- int time_slots;
+- int time_step;
+-} SBR_EXTRACT_ENVELOPE;
+-typedef SBR_EXTRACT_ENVELOPE *HANDLE_SBR_EXTRACT_ENVELOPE;
+-
+-struct ENV_CHANNEL {
+- FAST_TRAN_DETECTOR sbrFastTransientDetector;
+- SBR_TRANSIENT_DETECTOR sbrTransientDetector;
+- SBR_CODE_ENVELOPE sbrCodeEnvelope;
+- SBR_CODE_ENVELOPE sbrCodeNoiseFloor;
+- SBR_EXTRACT_ENVELOPE sbrExtractEnvelope;
+-
+- SBR_ENVELOPE_FRAME SbrEnvFrame;
+- SBR_TON_CORR_EST TonCorr;
+-
+- struct SBR_ENV_DATA encEnvData;
+-
+- int qmfScale;
+- UCHAR fLevelProtect;
+-};
+-typedef struct ENV_CHANNEL *HANDLE_ENV_CHANNEL;
+-
+-/************ Function Declarations ***************/
+-
+-INT FDKsbrEnc_CreateExtractSbrEnvelope(HANDLE_SBR_EXTRACT_ENVELOPE hSbrCut,
+- INT channel, INT chInEl,
+- UCHAR *dynamic_RAM);
+-
+-INT FDKsbrEnc_InitExtractSbrEnvelope(HANDLE_SBR_EXTRACT_ENVELOPE hSbr,
+- int no_cols, int no_rows, int start_index,
+- int time_slots, int time_step,
+- int tran_off, ULONG statesInitFlag,
+- int chInEl, UCHAR *dynamic_RAM,
+- UINT sbrSyntaxFlags);
+-
+-void FDKsbrEnc_deleteExtractSbrEnvelope(HANDLE_SBR_EXTRACT_ENVELOPE hSbrCut);
+-
+-typedef struct {
+- FREQ_RES res[MAX_NUM_NOISE_VALUES];
+- int maxQuantError;
+-
+-} SBR_FRAME_TEMP_DATA;
+-
+-typedef struct {
+- const SBR_FRAME_INFO *frame_info;
+- FIXP_DBL noiseFloor[MAX_NUM_NOISE_VALUES];
+- SCHAR sfb_nrg_coupling
+- [MAX_NUM_ENVELOPE_VALUES]; /* only used if stereomode = SWITCH_L_R_C */
+- SCHAR sfb_nrg[MAX_NUM_ENVELOPE_VALUES];
+- SCHAR noise_level_coupling
+- [MAX_NUM_NOISE_VALUES]; /* only used if stereomode = SWITCH_L_R_C */
+- SCHAR noise_level[MAX_NUM_NOISE_VALUES];
+- UCHAR transient_info[3];
+- UCHAR nEnvelopes;
+-} SBR_ENV_TEMP_DATA;
+-
+-/*
+- * Extract features from QMF data. Afterwards, the QMF data is not required
+- * anymore.
+- */
+-void FDKsbrEnc_extractSbrEnvelope1(HANDLE_SBR_CONFIG_DATA h_con,
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData,
+- HANDLE_ENV_CHANNEL h_envChan,
+- HANDLE_COMMON_DATA cmonData,
+- SBR_ENV_TEMP_DATA *eData,
+- SBR_FRAME_TEMP_DATA *fData);
+-
+-/*
+- * Process the previously features extracted by FDKsbrEnc_extractSbrEnvelope1
+- * and create/encode SBR envelopes.
+- */
+-void FDKsbrEnc_extractSbrEnvelope2(HANDLE_SBR_CONFIG_DATA h_con,
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData,
+- HANDLE_ENV_CHANNEL sbrEnvChannel0,
+- HANDLE_ENV_CHANNEL sbrEnvChannel1,
+- HANDLE_COMMON_DATA cmonData,
+- SBR_ENV_TEMP_DATA *eData,
+- SBR_FRAME_TEMP_DATA *fData, int clearOutput);
+-
+-INT FDKsbrEnc_GetEnvEstDelay(HANDLE_SBR_EXTRACT_ENVELOPE hSbr);
+-
+-#endif
+diff --git a/libSBRenc/src/fram_gen.cpp b/libSBRenc/src/fram_gen.cpp
+deleted file mode 100644
+index 7ed6e79..0000000
+--- a/libSBRenc/src/fram_gen.cpp
++++ /dev/null
+@@ -1,1965 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "fram_gen.h"
+-#include "sbr_misc.h"
+-
+-#include "genericStds.h"
+-
+-static const SBR_FRAME_INFO frameInfo1_2048 = {1, {0, 16}, {FREQ_RES_HIGH},
+- 0, 1, {0, 16}};
+-
+-static const SBR_FRAME_INFO frameInfo2_2048 = {
+- 2, {0, 8, 16}, {FREQ_RES_HIGH, FREQ_RES_HIGH}, 0, 2, {0, 8, 16}};
+-
+-static const SBR_FRAME_INFO frameInfo4_2048 = {
+- 4,
+- {0, 4, 8, 12, 16},
+- {FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH},
+- 0,
+- 2,
+- {0, 8, 16}};
+-
+-static const SBR_FRAME_INFO frameInfo1_2304 = {1, {0, 18}, {FREQ_RES_HIGH},
+- 0, 1, {0, 18}};
+-
+-static const SBR_FRAME_INFO frameInfo2_2304 = {
+- 2, {0, 9, 18}, {FREQ_RES_HIGH, FREQ_RES_HIGH}, 0, 2, {0, 9, 18}};
+-
+-static const SBR_FRAME_INFO frameInfo4_2304 = {
+- 4,
+- {0, 5, 9, 14, 18},
+- {FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH},
+- 0,
+- 2,
+- {0, 9, 18}};
+-
+-static const SBR_FRAME_INFO frameInfo1_1920 = {1, {0, 15}, {FREQ_RES_HIGH},
+- 0, 1, {0, 15}};
+-
+-static const SBR_FRAME_INFO frameInfo2_1920 = {
+- 2, {0, 8, 15}, {FREQ_RES_HIGH, FREQ_RES_HIGH}, 0, 2, {0, 8, 15}};
+-
+-static const SBR_FRAME_INFO frameInfo4_1920 = {
+- 4,
+- {0, 4, 8, 12, 15},
+- {FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH},
+- 0,
+- 2,
+- {0, 8, 15}};
+-
+-static const SBR_FRAME_INFO frameInfo1_1152 = {1, {0, 9}, {FREQ_RES_HIGH},
+- 0, 1, {0, 9}};
+-
+-static const SBR_FRAME_INFO frameInfo2_1152 = {
+- 2, {0, 5, 9}, {FREQ_RES_HIGH, FREQ_RES_HIGH}, 0, 2, {0, 5, 9}};
+-
+-static const SBR_FRAME_INFO frameInfo4_1152 = {
+- 4,
+- {0, 2, 5, 7, 9},
+- {FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH},
+- 0,
+- 2,
+- {0, 5, 9}};
+-
+-/* AACLD frame info */
+-static const SBR_FRAME_INFO frameInfo1_512LD = {1, {0, 8}, {FREQ_RES_HIGH},
+- 0, 1, {0, 8}};
+-
+-static const SBR_FRAME_INFO frameInfo2_512LD = {
+- 2, {0, 4, 8}, {FREQ_RES_HIGH, FREQ_RES_HIGH}, 0, 2, {0, 4, 8}};
+-
+-static const SBR_FRAME_INFO frameInfo4_512LD = {
+- 4,
+- {0, 2, 4, 6, 8},
+- {FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH},
+- 0,
+- 2,
+- {0, 4, 8}};
+-
+-static int calcFillLengthMax(
+- int tranPos, /*!< input : transient position (ref: tran det) */
+- int numberTimeSlots /*!< input : number of timeslots */
+-);
+-
+-static void fillFrameTran(
+- const int *v_tuningSegm, /*!< tuning: desired segment lengths */
+- const int *v_tuningFreq, /*!< tuning: desired frequency resolutions */
+- int tran, /*!< input : position of transient */
+- int *v_bord, /*!< memNew: borders */
+- int *length_v_bord, /*!< memNew: # borders */
+- int *v_freq, /*!< memNew: frequency resolutions */
+- int *length_v_freq, /*!< memNew: # frequency resolutions */
+- int *bmin, /*!< hlpNew: first mandatory border */
+- int *bmax /*!< hlpNew: last mandatory border */
+-);
+-
+-static void fillFramePre(INT dmax, INT *v_bord, INT *length_v_bord, INT *v_freq,
+- INT *length_v_freq, INT bmin, INT rest);
+-
+-static void fillFramePost(INT *parts, INT *d, INT dmax, INT *v_bord,
+- INT *length_v_bord, INT *v_freq, INT *length_v_freq,
+- INT bmax, INT bufferFrameStart, INT numberTimeSlots,
+- INT fmax);
+-
+-static void fillFrameInter(INT *nL, const int *v_tuningSegm, INT *v_bord,
+- INT *length_v_bord, INT bmin, INT *v_freq,
+- INT *length_v_freq, INT *v_bordFollow,
+- INT *length_v_bordFollow, INT *v_freqFollow,
+- INT *length_v_freqFollow, INT i_fillFollow, INT dmin,
+- INT dmax, INT numberTimeSlots);
+-
+-static void calcFrameClass(FRAME_CLASS *frameClass, FRAME_CLASS *frameClassOld,
+- INT tranFlag, INT *spreadFlag);
+-
+-static void specialCase(INT *spreadFlag, INT allowSpread, INT *v_bord,
+- INT *length_v_bord, INT *v_freq, INT *length_v_freq,
+- INT *parts, INT d);
+-
+-static void calcCmonBorder(INT *i_cmon, INT *i_tran, INT *v_bord,
+- INT *length_v_bord, INT tran, INT bufferFrameStart,
+- INT numberTimeSlots);
+-
+-static void keepForFollowUp(INT *v_bordFollow, INT *length_v_bordFollow,
+- INT *v_freqFollow, INT *length_v_freqFollow,
+- INT *i_tranFollow, INT *i_fillFollow, INT *v_bord,
+- INT *length_v_bord, INT *v_freq, INT i_cmon,
+- INT i_tran, INT parts, INT numberTimeSlots);
+-
+-static void calcCtrlSignal(HANDLE_SBR_GRID hSbrGrid, FRAME_CLASS frameClass,
+- INT *v_bord, INT length_v_bord, INT *v_freq,
+- INT length_v_freq, INT i_cmon, INT i_tran,
+- INT spreadFlag, INT nL);
+-
+-static void ctrlSignal2FrameInfo(HANDLE_SBR_GRID hSbrGrid,
+- HANDLE_SBR_FRAME_INFO hFrameInfo,
+- FREQ_RES *freq_res_fixfix);
+-
+-/* table for 8 time slot index */
+-static const int envelopeTable_8[8][5] = {
+- /* transientIndex nEnv, tranIdx, shortEnv, border1, border2, ... */
+- /* borders from left to right side; -1 = not in use */
+- /*[|T-|------]*/ {2, 0, 0, 1, -1},
+- /*[|-T-|-----]*/ {2, 0, 0, 2, -1},
+- /*[--|T-|----]*/ {3, 1, 1, 2, 4},
+- /*[---|T-|---]*/ {3, 1, 1, 3, 5},
+- /*[----|T-|--]*/ {3, 1, 1, 4, 6},
+- /*[-----|T--|]*/ {2, 1, 1, 5, -1},
+- /*[------|T-|]*/ {2, 1, 1, 6, -1},
+- /*[-------|T|]*/ {2, 1, 1, 7, -1},
+-};
+-
+-/* table for 16 time slot index */
+-static const int envelopeTable_16[16][6] = {
+- /* transientIndex nEnv, tranIdx, shortEnv, border1, border2, ... */
+- /* length from left to right side; -1 = not in use */
+- /*[|T---|------------|]*/ {2, 0, 0, 4, -1, -1},
+- /*[|-T---|-----------|]*/ {2, 0, 0, 5, -1, -1},
+- /*[|--|T---|----------]*/ {3, 1, 1, 2, 6, -1},
+- /*[|---|T---|---------]*/ {3, 1, 1, 3, 7, -1},
+- /*[|----|T---|--------]*/ {3, 1, 1, 4, 8, -1},
+- /*[|-----|T---|-------]*/ {3, 1, 1, 5, 9, -1},
+- /*[|------|T---|------]*/ {3, 1, 1, 6, 10, -1},
+- /*[|-------|T---|-----]*/ {3, 1, 1, 7, 11, -1},
+- /*[|--------|T---|----]*/ {3, 1, 1, 8, 12, -1},
+- /*[|---------|T---|---]*/ {3, 1, 1, 9, 13, -1},
+- /*[|----------|T---|--]*/ {3, 1, 1, 10, 14, -1},
+- /*[|-----------|T----|]*/ {2, 1, 1, 11, -1, -1},
+- /*[|------------|T---|]*/ {2, 1, 1, 12, -1, -1},
+- /*[|-------------|T--|]*/ {2, 1, 1, 13, -1, -1},
+- /*[|--------------|T-|]*/ {2, 1, 1, 14, -1, -1},
+- /*[|---------------|T|]*/ {2, 1, 1, 15, -1, -1},
+-};
+-
+-/* table for 15 time slot index */
+-static const int envelopeTable_15[15][6] = {
+- /* transientIndex nEnv, tranIdx, shortEnv, border1, border2, ... */
+- /* length from left to right side; -1 = not in use */
+- /*[|T---|------------]*/ {2, 0, 0, 4, -1, -1},
+- /*[|-T---|-----------]*/ {2, 0, 0, 5, -1, -1},
+- /*[|--|T---|---------]*/ {3, 1, 1, 2, 6, -1},
+- /*[|---|T---|--------]*/ {3, 1, 1, 3, 7, -1},
+- /*[|----|T---|-------]*/ {3, 1, 1, 4, 8, -1},
+- /*[|-----|T---|------]*/ {3, 1, 1, 5, 9, -1},
+- /*[|------|T---|-----]*/ {3, 1, 1, 6, 10, -1},
+- /*[|-------|T---|----]*/ {3, 1, 1, 7, 11, -1},
+- /*[|--------|T---|---]*/ {3, 1, 1, 8, 12, -1},
+- /*[|---------|T---|--]*/ {3, 1, 1, 9, 13, -1},
+- /*[|----------|T----|]*/ {2, 1, 1, 10, -1, -1},
+- /*[|-----------|T---|]*/ {2, 1, 1, 11, -1, -1},
+- /*[|------------|T--|]*/ {2, 1, 1, 12, -1, -1},
+- /*[|-------------|T-|]*/ {2, 1, 1, 13, -1, -1},
+- /*[|--------------|T|]*/ {2, 1, 1, 14, -1, -1},
+-};
+-
+-static const int minFrameTranDistance = 4;
+-
+-static const FREQ_RES freqRes_table_8[] = {
+- FREQ_RES_LOW, FREQ_RES_LOW, FREQ_RES_LOW, FREQ_RES_LOW, FREQ_RES_LOW,
+- FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH, FREQ_RES_HIGH};
+-
+-static const FREQ_RES freqRes_table_16[16] = {
+- /* size of envelope */
+- /* 0-4 */ FREQ_RES_LOW,
+- FREQ_RES_LOW,
+- FREQ_RES_LOW,
+- FREQ_RES_LOW,
+- FREQ_RES_LOW,
+- /* 5-9 */ FREQ_RES_LOW,
+- FREQ_RES_HIGH,
+- FREQ_RES_HIGH,
+- FREQ_RES_HIGH,
+- FREQ_RES_HIGH,
+- /* 10-16 */ FREQ_RES_HIGH,
+- FREQ_RES_HIGH,
+- FREQ_RES_HIGH,
+- FREQ_RES_HIGH,
+- FREQ_RES_HIGH,
+- FREQ_RES_HIGH};
+-
+-static void generateFixFixOnly(HANDLE_SBR_FRAME_INFO hSbrFrameInfo,
+- HANDLE_SBR_GRID hSbrGrid, int tranPosInternal,
+- int numberTimeSlots, UCHAR fResTransIsLow);
+-
+-/*!
+- Functionname: FDKsbrEnc_frameInfoGenerator
+-
+- Description: produces the FRAME_INFO struct for the current frame
+-
+- Arguments: hSbrEnvFrame - pointer to sbr envelope handle
+- v_pre_transient_info - pointer to transient info vector
+- v_transient_info - pointer to previous transient info
+-vector v_tuning - pointer to tuning vector
+-
+- Return: frame_info - pointer to SBR_FRAME_INFO struct
+-
+-*******************************************************************************/
+-HANDLE_SBR_FRAME_INFO
+-FDKsbrEnc_frameInfoGenerator(HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame,
+- UCHAR *v_transient_info, const INT rightBorderFIX,
+- UCHAR *v_transient_info_pre, int ldGrid,
+- const int *v_tuning) {
+- INT numEnv, tranPosInternal = 0, bmin = 0, bmax = 0, parts, d, i_cmon = 0,
+- i_tran = 0, nL;
+- INT fmax = 0;
+-
+- INT *v_bord = hSbrEnvFrame->v_bord;
+- INT *v_freq = hSbrEnvFrame->v_freq;
+- INT *v_bordFollow = hSbrEnvFrame->v_bordFollow;
+- INT *v_freqFollow = hSbrEnvFrame->v_freqFollow;
+-
+- INT *length_v_bordFollow = &hSbrEnvFrame->length_v_bordFollow;
+- INT *length_v_freqFollow = &hSbrEnvFrame->length_v_freqFollow;
+- INT *length_v_bord = &hSbrEnvFrame->length_v_bord;
+- INT *length_v_freq = &hSbrEnvFrame->length_v_freq;
+- INT *spreadFlag = &hSbrEnvFrame->spreadFlag;
+- INT *i_tranFollow = &hSbrEnvFrame->i_tranFollow;
+- INT *i_fillFollow = &hSbrEnvFrame->i_fillFollow;
+- FRAME_CLASS *frameClassOld = &hSbrEnvFrame->frameClassOld;
+- FRAME_CLASS frameClass = FIXFIX;
+-
+- INT allowSpread = hSbrEnvFrame->allowSpread;
+- INT numEnvStatic = hSbrEnvFrame->numEnvStatic;
+- INT staticFraming = hSbrEnvFrame->staticFraming;
+- INT dmin = hSbrEnvFrame->dmin;
+- INT dmax = hSbrEnvFrame->dmax;
+-
+- INT bufferFrameStart = hSbrEnvFrame->SbrGrid.bufferFrameStart;
+- INT numberTimeSlots = hSbrEnvFrame->SbrGrid.numberTimeSlots;
+- INT frameMiddleSlot = hSbrEnvFrame->frameMiddleSlot;
+-
+- INT tranPos = v_transient_info[0];
+- INT tranFlag = v_transient_info[1];
+-
+- const int *v_tuningSegm = v_tuning;
+- const int *v_tuningFreq = v_tuning + 3;
+-
+- hSbrEnvFrame->v_tuningSegm = v_tuningSegm;
+-
+- if (ldGrid) {
+- /* in case there was a transient at the very end of the previous frame,
+- * start with a transient envelope */
+- if (!tranFlag && v_transient_info_pre[1] &&
+- (numberTimeSlots - v_transient_info_pre[0] < minFrameTranDistance)) {
+- tranFlag = 1;
+- tranPos = 0;
+- }
+- }
+-
+- /*
+- * Synopsis:
+- *
+- * The frame generator creates the time-/frequency-grid for one SBR frame.
+- * Input signals are provided by the transient detector and the frame
+- * splitter (transientDetectNew() & FrameSplitter() in tran_det.c). The
+- * framing is controlled by adjusting tuning parameters stored in
+- * FRAME_GEN_TUNING. The parameter values are dependent on frame lengths
+- * and bitrates, and may in the future be signal dependent.
+- *
+- * The envelope borders are stored for frame generator internal use in
+- * aBorders. The contents of aBorders represent positions along the time
+- * axis given in the figures in fram_gen.h (the "frame-generator" rows).
+- * The unit is "time slot". The figures in fram_gen.h also define the
+- * detection ranges for the transient detector. For every border in
+- * aBorders, there is a corresponding entry in aFreqRes, which defines the
+- * frequency resolution of the envelope following (delimited by) the
+- * border.
+- *
+- * When no transients are present, FIXFIX class frames are used. The
+- * frame splitter decides whether to use one or two envelopes in the
+- * FIXFIX frame. "Sparse transients" (separated by a few frames without
+- * transients) are handeled by [FIXVAR, VARFIX] pairs or (depending on
+- * tuning and transient position relative the nominal frame boundaries)
+- * by [FIXVAR, VARVAR, VARFIX] triples. "Tight transients" (in
+- * consecutive frames) are handeled by [..., VARVAR, VARVAR, ...]
+- * sequences.
+- *
+- * The generator assumes that transients are "sparse", and designs
+- * borders for [FIXVAR, VARFIX] pairs right away, where the first frame
+- * corresponds to the present frame. At the next call of the generator
+- * it is known whether the transient actually is "sparse" or not. If
+- * 'yes', the already calculated VARFIX borders are used. If 'no', new
+- * borders, meeting the requirements of the "tight" transient, are
+- * calculated.
+- *
+- * The generator produces two outputs: A "clear-text bitstream" stored in
+- * SBR_GRID, and a straight-forward representation of the grid stored in
+- * SBR_FRAME_INFO. The former is subsequently converted to the actual
+- * bitstream sbr_grid() (encodeSbrGrid() in bit_sbr.c). The latter is
+- * used by other encoder functions, such as the envelope estimator
+- * (calculateSbrEnvelope() in env_est.c) and the noise floor and missing
+- * harmonics detector (TonCorrParamExtr() in nf_est.c).
+- */
+-
+- if (staticFraming) {
+- /*--------------------------------------------------------------------------
+- Ignore transient detector
+- ---------------------------------------------------------------------------*/
+-
+- frameClass = FIXFIX;
+- numEnv = numEnvStatic; /* {1,2,4,8} */
+- *frameClassOld = FIXFIX; /* for change to dyn */
+- hSbrEnvFrame->SbrGrid.bs_num_env = numEnv;
+- hSbrEnvFrame->SbrGrid.frameClass = frameClass;
+- } else {
+- /*--------------------------------------------------------------------------
+- Calculate frame class to use
+- ---------------------------------------------------------------------------*/
+- if (rightBorderFIX) {
+- tranFlag = 0;
+- *spreadFlag = 0;
+- }
+- calcFrameClass(&frameClass, frameClassOld, tranFlag, spreadFlag);
+-
+- /* patch for new frame class FIXFIXonly for AAC LD */
+- if (tranFlag && ldGrid) {
+- frameClass = FIXFIXonly;
+- *frameClassOld = FIXFIX;
+- }
+-
+- /*
+- * every transient is processed below by inserting
+- *
+- * - one border at the onset of the transient
+- * - one or more "decay borders" (after the onset of the transient)
+- * - optionally one "attack border" (before the onset of the transient)
+- *
+- * those borders are referred to as "mandatory borders" and are
+- * defined by the 'segmentLength' array in FRAME_GEN_TUNING
+- *
+- * the frequency resolutions of the corresponding envelopes are
+- * defined by the 'segmentRes' array in FRAME_GEN_TUNING
+- */
+-
+- /*--------------------------------------------------------------------------
+- Design frame (or follow-up old design)
+- ---------------------------------------------------------------------------*/
+- if (tranFlag) {
+- /* Always for FixVar, often but not always for VarVar */
+-
+- /*--------------------------------------------------------------------------
+- Design part of T/F-grid around the new transient
+- ---------------------------------------------------------------------------*/
+-
+- tranPosInternal =
+- frameMiddleSlot + tranPos + bufferFrameStart; /* FH 00-06-26 */
+- /*
+- add mandatory borders around transient
+- */
+-
+- fillFrameTran(v_tuningSegm, v_tuningFreq, tranPosInternal, v_bord,
+- length_v_bord, v_freq, length_v_freq, &bmin, &bmax);
+-
+- /* make sure we stay within the maximum SBR frame overlap */
+- fmax = calcFillLengthMax(tranPos, numberTimeSlots);
+- }
+-
+- switch (frameClass) {
+- case FIXFIXonly:
+- FDK_ASSERT(ldGrid);
+- tranPosInternal = tranPos;
+- generateFixFixOnly(&(hSbrEnvFrame->SbrFrameInfo),
+- &(hSbrEnvFrame->SbrGrid), tranPosInternal,
+- numberTimeSlots, hSbrEnvFrame->fResTransIsLow);
+-
+- return &(hSbrEnvFrame->SbrFrameInfo);
+-
+- case FIXVAR:
+-
+- /*--------------------------------------------------------------------------
+- Design remaining parts of T/F-grid (assuming next frame is VarFix)
+- ---------------------------------------------------------------------------*/
+-
+- /*--------------------------------------------------------------------------
+- Fill region before new transient:
+- ---------------------------------------------------------------------------*/
+- fillFramePre(dmax, v_bord, length_v_bord, v_freq, length_v_freq, bmin,
+- bmin - bufferFrameStart); /* FH 00-06-26 */
+-
+- /*--------------------------------------------------------------------------
+- Fill region after new transient:
+- ---------------------------------------------------------------------------*/
+- fillFramePost(&parts, &d, dmax, v_bord, length_v_bord, v_freq,
+- length_v_freq, bmax, bufferFrameStart, numberTimeSlots,
+- fmax);
+-
+- /*--------------------------------------------------------------------------
+- Take care of special case:
+- ---------------------------------------------------------------------------*/
+- if (parts == 1 && d < dmin) /* no fill, short last envelope */
+- specialCase(spreadFlag, allowSpread, v_bord, length_v_bord, v_freq,
+- length_v_freq, &parts, d);
+-
+- /*--------------------------------------------------------------------------
+- Calculate common border (split-point)
+- ---------------------------------------------------------------------------*/
+- calcCmonBorder(&i_cmon, &i_tran, v_bord, length_v_bord, tranPosInternal,
+- bufferFrameStart, numberTimeSlots); /* FH 00-06-26 */
+-
+- /*--------------------------------------------------------------------------
+- Extract data for proper follow-up in next frame
+- ---------------------------------------------------------------------------*/
+- keepForFollowUp(v_bordFollow, length_v_bordFollow, v_freqFollow,
+- length_v_freqFollow, i_tranFollow, i_fillFollow, v_bord,
+- length_v_bord, v_freq, i_cmon, i_tran, parts,
+- numberTimeSlots); /* FH 00-06-26 */
+-
+- /*--------------------------------------------------------------------------
+- Calculate control signal
+- ---------------------------------------------------------------------------*/
+- calcCtrlSignal(&hSbrEnvFrame->SbrGrid, frameClass, v_bord,
+- *length_v_bord, v_freq, *length_v_freq, i_cmon, i_tran,
+- *spreadFlag, DC);
+- break;
+- case VARFIX:
+- /*--------------------------------------------------------------------------
+- Follow-up old transient - calculate control signal
+- ---------------------------------------------------------------------------*/
+- calcCtrlSignal(&hSbrEnvFrame->SbrGrid, frameClass, v_bordFollow,
+- *length_v_bordFollow, v_freqFollow, *length_v_freqFollow,
+- DC, *i_tranFollow, *spreadFlag, DC);
+- break;
+- case VARVAR:
+- if (*spreadFlag) { /* spread across three frames */
+- /*--------------------------------------------------------------------------
+- Follow-up old transient - calculate control signal
+- ---------------------------------------------------------------------------*/
+- calcCtrlSignal(&hSbrEnvFrame->SbrGrid, frameClass, v_bordFollow,
+- *length_v_bordFollow, v_freqFollow,
+- *length_v_freqFollow, DC, *i_tranFollow, *spreadFlag,
+- DC);
+-
+- *spreadFlag = 0;
+-
+- /*--------------------------------------------------------------------------
+- Extract data for proper follow-up in next frame
+- ---------------------------------------------------------------------------*/
+- v_bordFollow[0] = hSbrEnvFrame->SbrGrid.bs_abs_bord_1 -
+- numberTimeSlots; /* FH 00-06-26 */
+- v_freqFollow[0] = 1;
+- *length_v_bordFollow = 1;
+- *length_v_freqFollow = 1;
+-
+- *i_tranFollow = -DC;
+- *i_fillFollow = -DC;
+- } else {
+- /*--------------------------------------------------------------------------
+- Design remaining parts of T/F-grid (assuming next frame is VarFix)
+- adapt or fill region before new transient:
+- ---------------------------------------------------------------------------*/
+- fillFrameInter(&nL, v_tuningSegm, v_bord, length_v_bord, bmin, v_freq,
+- length_v_freq, v_bordFollow, length_v_bordFollow,
+- v_freqFollow, length_v_freqFollow, *i_fillFollow, dmin,
+- dmax, numberTimeSlots);
+-
+- /*--------------------------------------------------------------------------
+- Fill after transient:
+- ---------------------------------------------------------------------------*/
+- fillFramePost(&parts, &d, dmax, v_bord, length_v_bord, v_freq,
+- length_v_freq, bmax, bufferFrameStart, numberTimeSlots,
+- fmax);
+-
+- /*--------------------------------------------------------------------------
+- Take care of special case:
+- ---------------------------------------------------------------------------*/
+- if (parts == 1 && d < dmin) /*% no fill, short last envelope */
+- specialCase(spreadFlag, allowSpread, v_bord, length_v_bord, v_freq,
+- length_v_freq, &parts, d);
+-
+- /*--------------------------------------------------------------------------
+- Calculate common border (split-point)
+- ---------------------------------------------------------------------------*/
+- calcCmonBorder(&i_cmon, &i_tran, v_bord, length_v_bord,
+- tranPosInternal, bufferFrameStart, numberTimeSlots);
+-
+- /*--------------------------------------------------------------------------
+- Extract data for proper follow-up in next frame
+- ---------------------------------------------------------------------------*/
+- keepForFollowUp(v_bordFollow, length_v_bordFollow, v_freqFollow,
+- length_v_freqFollow, i_tranFollow, i_fillFollow,
+- v_bord, length_v_bord, v_freq, i_cmon, i_tran, parts,
+- numberTimeSlots);
+-
+- /*--------------------------------------------------------------------------
+- Calculate control signal
+- ---------------------------------------------------------------------------*/
+- calcCtrlSignal(&hSbrEnvFrame->SbrGrid, frameClass, v_bord,
+- *length_v_bord, v_freq, *length_v_freq, i_cmon, i_tran,
+- 0, nL);
+- }
+- break;
+- case FIXFIX:
+- if (tranPos == 0)
+- numEnv = 1;
+- else
+- numEnv = 2;
+-
+- hSbrEnvFrame->SbrGrid.bs_num_env = numEnv;
+- hSbrEnvFrame->SbrGrid.frameClass = frameClass;
+-
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- }
+-
+- /*-------------------------------------------------------------------------
+- Convert control signal to frame info struct
+- ---------------------------------------------------------------------------*/
+- ctrlSignal2FrameInfo(&hSbrEnvFrame->SbrGrid, &hSbrEnvFrame->SbrFrameInfo,
+- hSbrEnvFrame->freq_res_fixfix);
+-
+- return &hSbrEnvFrame->SbrFrameInfo;
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief Gnerates frame info for FIXFIXonly frame class used for low delay
+- version
+-
+- \return nothing
+- ****************************************************************************/
+-static void generateFixFixOnly(HANDLE_SBR_FRAME_INFO hSbrFrameInfo,
+- HANDLE_SBR_GRID hSbrGrid, int tranPosInternal,
+- int numberTimeSlots, UCHAR fResTransIsLow) {
+- int nEnv, i, k = 0, tranIdx;
+- const int *pTable = NULL;
+- const FREQ_RES *freqResTable = NULL;
+-
+- switch (numberTimeSlots) {
+- case 8: {
+- pTable = envelopeTable_8[tranPosInternal];
+- }
+- freqResTable = freqRes_table_8;
+- break;
+- case 15:
+- pTable = envelopeTable_15[tranPosInternal];
+- freqResTable = freqRes_table_16;
+- break;
+- case 16:
+- pTable = envelopeTable_16[tranPosInternal];
+- freqResTable = freqRes_table_16;
+- break;
+- }
+-
+- /* look number of envolpes in table */
+- nEnv = pTable[0];
+- /* look up envolpe distribution in table */
+- for (i = 1; i < nEnv; i++) hSbrFrameInfo->borders[i] = pTable[i + 2];
+-
+- /* open and close frame border */
+- hSbrFrameInfo->borders[0] = 0;
+- hSbrFrameInfo->borders[nEnv] = numberTimeSlots;
+-
+- /* adjust segment-frequency-resolution according to the segment-length */
+- for (i = 0; i < nEnv; i++) {
+- k = hSbrFrameInfo->borders[i + 1] - hSbrFrameInfo->borders[i];
+- if (!fResTransIsLow)
+- hSbrFrameInfo->freqRes[i] = freqResTable[k];
+- else
+- hSbrFrameInfo->freqRes[i] = FREQ_RES_LOW;
+-
+- hSbrGrid->v_f[i] = hSbrFrameInfo->freqRes[i];
+- }
+-
+- hSbrFrameInfo->nEnvelopes = nEnv;
+- hSbrFrameInfo->shortEnv = pTable[2];
+- /* transient idx */
+- tranIdx = pTable[1];
+-
+- /* add noise floors */
+- hSbrFrameInfo->bordersNoise[0] = 0;
+- hSbrFrameInfo->bordersNoise[1] =
+- hSbrFrameInfo->borders[tranIdx ? tranIdx : 1];
+- hSbrFrameInfo->bordersNoise[2] = numberTimeSlots;
+- hSbrFrameInfo->nNoiseEnvelopes = 2;
+-
+- hSbrGrid->frameClass = FIXFIXonly;
+- hSbrGrid->bs_abs_bord = tranPosInternal;
+- hSbrGrid->bs_num_env = nEnv;
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_initFrameInfoGenerator
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: hSbrEnvFrame - pointer to sbr envelope handle
+- allowSpread - commandline parameter
+- numEnvStatic - commandline parameter
+- staticFraming - commandline parameter
+-
+- Return: none
+-
+-*******************************************************************************/
+-void FDKsbrEnc_initFrameInfoGenerator(HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame,
+- INT allowSpread, INT numEnvStatic,
+- INT staticFraming, INT timeSlots,
+- const FREQ_RES *freq_res_fixfix,
+- UCHAR fResTransIsLow,
+- INT ldGrid) { /* FH 00-06-26 */
+-
+- FDKmemclear(hSbrEnvFrame, sizeof(SBR_ENVELOPE_FRAME));
+-
+- /* Initialisation */
+- hSbrEnvFrame->frameClassOld = FIXFIX;
+- hSbrEnvFrame->spreadFlag = 0;
+-
+- hSbrEnvFrame->allowSpread = allowSpread;
+- hSbrEnvFrame->numEnvStatic = numEnvStatic;
+- hSbrEnvFrame->staticFraming = staticFraming;
+- hSbrEnvFrame->freq_res_fixfix[0] = freq_res_fixfix[0];
+- hSbrEnvFrame->freq_res_fixfix[1] = freq_res_fixfix[1];
+- hSbrEnvFrame->fResTransIsLow = fResTransIsLow;
+-
+- hSbrEnvFrame->length_v_bord = 0;
+- hSbrEnvFrame->length_v_bordFollow = 0;
+-
+- hSbrEnvFrame->length_v_freq = 0;
+- hSbrEnvFrame->length_v_freqFollow = 0;
+-
+- hSbrEnvFrame->i_tranFollow = 0;
+- hSbrEnvFrame->i_fillFollow = 0;
+-
+- hSbrEnvFrame->SbrGrid.numberTimeSlots = timeSlots;
+-
+- if (ldGrid) {
+- /*case CODEC_AACLD:*/
+- hSbrEnvFrame->dmin = 2;
+- hSbrEnvFrame->dmax = 16;
+- hSbrEnvFrame->frameMiddleSlot = FRAME_MIDDLE_SLOT_512LD;
+- hSbrEnvFrame->SbrGrid.bufferFrameStart = 0;
+- } else
+- switch (timeSlots) {
+- case NUMBER_TIME_SLOTS_1920:
+- hSbrEnvFrame->dmin = 4;
+- hSbrEnvFrame->dmax = 12;
+- hSbrEnvFrame->SbrGrid.bufferFrameStart = 0;
+- hSbrEnvFrame->frameMiddleSlot = FRAME_MIDDLE_SLOT_1920;
+- break;
+- case NUMBER_TIME_SLOTS_2048:
+- hSbrEnvFrame->dmin = 4;
+- hSbrEnvFrame->dmax = 12;
+- hSbrEnvFrame->SbrGrid.bufferFrameStart = 0;
+- hSbrEnvFrame->frameMiddleSlot = FRAME_MIDDLE_SLOT_2048;
+- break;
+- case NUMBER_TIME_SLOTS_1152:
+- hSbrEnvFrame->dmin = 2;
+- hSbrEnvFrame->dmax = 8;
+- hSbrEnvFrame->SbrGrid.bufferFrameStart = 0;
+- hSbrEnvFrame->frameMiddleSlot = FRAME_MIDDLE_SLOT_1152;
+- break;
+- case NUMBER_TIME_SLOTS_2304:
+- hSbrEnvFrame->dmin = 4;
+- hSbrEnvFrame->dmax = 15;
+- hSbrEnvFrame->SbrGrid.bufferFrameStart = 0;
+- hSbrEnvFrame->frameMiddleSlot = FRAME_MIDDLE_SLOT_2304;
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: fillFrameTran
+- *******************************************************************************
+-
+- Description: Add mandatory borders, as described by the tuning vector
+- and the current transient position
+-
+- Arguments:
+- modified:
+- v_bord - int pointer to v_bord vector
+- length_v_bord - length of v_bord vector
+- v_freq - int pointer to v_freq vector
+- length_v_freq - length of v_freq vector
+- bmin - int pointer to bmin (call by reference)
+- bmax - int pointer to bmax (call by reference)
+- not modified:
+- tran - position of transient
+- v_tuningSegm - int pointer to v_tuningSegm vector
+- v_tuningFreq - int pointer to v_tuningFreq vector
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void fillFrameTran(
+- const int *v_tuningSegm, /*!< tuning: desired segment lengths */
+- const int *v_tuningFreq, /*!< tuning: desired frequency resolutions */
+- int tran, /*!< input : position of transient */
+- int *v_bord, /*!< memNew: borders */
+- int *length_v_bord, /*!< memNew: # borders */
+- int *v_freq, /*!< memNew: frequency resolutions */
+- int *length_v_freq, /*!< memNew: # frequency resolutions */
+- int *bmin, /*!< hlpNew: first mandatory border */
+- int *bmax /*!< hlpNew: last mandatory border */
+-) {
+- int bord, i;
+-
+- *length_v_bord = 0;
+- *length_v_freq = 0;
+-
+- /* add attack env leading border (optional) */
+- if (v_tuningSegm[0]) {
+- /* v_bord = [(Ba)] start of attack env */
+- FDKsbrEnc_AddRight(v_bord, length_v_bord, (tran - v_tuningSegm[0]));
+-
+- /* v_freq = [(Fa)] res of attack env */
+- FDKsbrEnc_AddRight(v_freq, length_v_freq, v_tuningFreq[0]);
+- }
+-
+- /* add attack env trailing border/first decay env leading border */
+- bord = tran;
+- FDKsbrEnc_AddRight(v_bord, length_v_bord, tran); /* v_bord = [(Ba),Bd1] */
+-
+- /* add first decay env trailing border/2:nd decay env leading border */
+- if (v_tuningSegm[1]) {
+- bord += v_tuningSegm[1];
+-
+- /* v_bord = [(Ba),Bd1,Bd2] */
+- FDKsbrEnc_AddRight(v_bord, length_v_bord, bord);
+-
+- /* v_freq = [(Fa),Fd1] */
+- FDKsbrEnc_AddRight(v_freq, length_v_freq, v_tuningFreq[1]);
+- }
+-
+- /* add 2:nd decay env trailing border (optional) */
+- if (v_tuningSegm[2] != 0) {
+- bord += v_tuningSegm[2];
+-
+- /* v_bord = [(Ba),Bd1, Bd2,(Bd3)] */
+- FDKsbrEnc_AddRight(v_bord, length_v_bord, bord);
+-
+- /* v_freq = [(Fa),Fd1,(Fd2)] */
+- FDKsbrEnc_AddRight(v_freq, length_v_freq, v_tuningFreq[2]);
+- }
+-
+- /* v_freq = [(Fa),Fd1,(Fd2),1] */
+- FDKsbrEnc_AddRight(v_freq, length_v_freq, 1);
+-
+- /* calc min and max values of mandatory borders */
+- *bmin = v_bord[0];
+- for (i = 0; i < *length_v_bord; i++)
+- if (v_bord[i] < *bmin) *bmin = v_bord[i];
+-
+- *bmax = v_bord[0];
+- for (i = 0; i < *length_v_bord; i++)
+- if (v_bord[i] > *bmax) *bmax = v_bord[i];
+-}
+-
+-/*******************************************************************************
+- Functionname: fillFramePre
+- *******************************************************************************
+-
+- Description: Add borders before mandatory borders, if needed
+-
+- Arguments:
+- modified:
+- v_bord - int pointer to v_bord vector
+- length_v_bord - length of v_bord vector
+- v_freq - int pointer to v_freq vector
+- length_v_freq - length of v_freq vector
+- not modified:
+- dmax - int value
+- bmin - int value
+- rest - int value
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void fillFramePre(INT dmax, INT *v_bord, INT *length_v_bord, INT *v_freq,
+- INT *length_v_freq, INT bmin, INT rest) {
+- /*
+- input state:
+- v_bord = [(Ba),Bd1, Bd2 ,(Bd3)]
+- v_freq = [(Fa),Fd1,(Fd2),1 ]
+- */
+-
+- INT parts, d, j, S, s = 0, segm, bord;
+-
+- /*
+- start with one envelope
+- */
+-
+- parts = 1;
+- d = rest;
+-
+- /*
+- calc # of additional envelopes and corresponding lengths
+- */
+-
+- while (d > dmax) {
+- parts++;
+-
+- segm = rest / parts;
+- S = (segm - 2) >> 1;
+- s = fixMin(8, 2 * S + 2);
+- d = rest - (parts - 1) * s;
+- }
+-
+- /*
+- add borders before mandatory borders
+- */
+-
+- bord = bmin;
+-
+- for (j = 0; j <= parts - 2; j++) {
+- bord = bord - s;
+-
+- /* v_bord = [...,(Bf),(Ba),Bd1, Bd2 ,(Bd3)] */
+- FDKsbrEnc_AddLeft(v_bord, length_v_bord, bord);
+-
+- /* v_freq = [...,(1 ),(Fa),Fd1,(Fd2), 1 ] */
+- FDKsbrEnc_AddLeft(v_freq, length_v_freq, 1);
+- }
+-}
+-
+-/***************************************************************************/
+-/*!
+- \brief Overlap control
+-
+- Calculate max length of trailing fill segments, such that we always get a
+- border within the frame overlap region
+-
+- \return void
+-
+-****************************************************************************/
+-static int calcFillLengthMax(
+- int tranPos, /*!< input : transient position (ref: tran det) */
+- int numberTimeSlots /*!< input : number of timeslots */
+-) {
+- int fmax;
+-
+- /*
+- calculate transient position within envelope buffer
+- */
+- switch (numberTimeSlots) {
+- case NUMBER_TIME_SLOTS_2048:
+- if (tranPos < 4)
+- fmax = 6;
+- else if (tranPos == 4 || tranPos == 5)
+- fmax = 4;
+- else
+- fmax = 8;
+- break;
+-
+- case NUMBER_TIME_SLOTS_1920:
+- if (tranPos < 4)
+- fmax = 5;
+- else if (tranPos == 4 || tranPos == 5)
+- fmax = 3;
+- else
+- fmax = 7;
+- break;
+-
+- default:
+- fmax = 8;
+- break;
+- }
+-
+- return fmax;
+-}
+-
+-/*******************************************************************************
+- Functionname: fillFramePost
+- *******************************************************************************
+-
+- Description: -Add borders after mandatory borders, if needed
+- Make a preliminary design of next frame,
+- assuming no transient is present there
+-
+- Arguments:
+- modified:
+- parts - int pointer to parts (call by reference)
+- d - int pointer to d (call by reference)
+- v_bord - int pointer to v_bord vector
+- length_v_bord - length of v_bord vector
+- v_freq - int pointer to v_freq vector
+- length_v_freq - length of v_freq vector
+- not modified:
+- bmax - int value
+- dmax - int value
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void fillFramePost(INT *parts, INT *d, INT dmax, INT *v_bord,
+- INT *length_v_bord, INT *v_freq, INT *length_v_freq,
+- INT bmax, INT bufferFrameStart, INT numberTimeSlots,
+- INT fmax) {
+- INT j, rest, segm, S, s = 0, bord;
+-
+- /*
+- input state:
+- v_bord = [...,(Bf),(Ba),Bd1, Bd2 ,(Bd3)]
+- v_freq = [...,(1 ),(Fa),Fd1,(Fd2),1 ]
+- */
+-
+- rest = bufferFrameStart + 2 * numberTimeSlots - bmax;
+- *d = rest;
+-
+- if (*d > 0) {
+- *parts = 1; /* start with one envelope */
+-
+- /* calc # of additional envelopes and corresponding lengths */
+-
+- while (*d > dmax) {
+- *parts = *parts + 1;
+-
+- segm = rest / (*parts);
+- S = (segm - 2) >> 1;
+- s = fixMin(fmax, 2 * S + 2);
+- *d = rest - (*parts - 1) * s;
+- }
+-
+- /* add borders after mandatory borders */
+-
+- bord = bmax;
+- for (j = 0; j <= *parts - 2; j++) {
+- bord += s;
+-
+- /* v_bord = [...,(Bf),(Ba),Bd1, Bd2 ,(Bd3),(Bf)] */
+- FDKsbrEnc_AddRight(v_bord, length_v_bord, bord);
+-
+- /* v_freq = [...,(1 ),(Fa),Fd1,(Fd2), 1 , 1! ,1] */
+- FDKsbrEnc_AddRight(v_freq, length_v_freq, 1);
+- }
+- } else {
+- *parts = 1;
+-
+- /* remove last element from v_bord and v_freq */
+-
+- *length_v_bord = *length_v_bord - 1;
+- *length_v_freq = *length_v_freq - 1;
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: fillFrameInter
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: nL -
+- v_tuningSegm -
+- v_bord -
+- length_v_bord -
+- bmin -
+- v_freq -
+- length_v_freq -
+- v_bordFollow -
+- length_v_bordFollow -
+- v_freqFollow -
+- length_v_freqFollow -
+- i_fillFollow -
+- dmin -
+- dmax -
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void fillFrameInter(INT *nL, const int *v_tuningSegm, INT *v_bord,
+- INT *length_v_bord, INT bmin, INT *v_freq,
+- INT *length_v_freq, INT *v_bordFollow,
+- INT *length_v_bordFollow, INT *v_freqFollow,
+- INT *length_v_freqFollow, INT i_fillFollow, INT dmin,
+- INT dmax, INT numberTimeSlots) {
+- INT middle, b_new, numBordFollow, bordMaxFollow, i;
+-
+- if (numberTimeSlots != NUMBER_TIME_SLOTS_1152) {
+- /* % remove fill borders: */
+- if (i_fillFollow >= 1) {
+- *length_v_bordFollow = i_fillFollow;
+- *length_v_freqFollow = i_fillFollow;
+- }
+-
+- numBordFollow = *length_v_bordFollow;
+- bordMaxFollow = v_bordFollow[numBordFollow - 1];
+-
+- /* remove even more borders if needed */
+- middle = bmin - bordMaxFollow;
+- while (middle < 0) {
+- numBordFollow--;
+- bordMaxFollow = v_bordFollow[numBordFollow - 1];
+- middle = bmin - bordMaxFollow;
+- }
+-
+- *length_v_bordFollow = numBordFollow;
+- *length_v_freqFollow = numBordFollow;
+- *nL = numBordFollow - 1;
+-
+- b_new = *length_v_bord;
+-
+- if (middle <= dmax) {
+- if (middle >= dmin) { /* concatenate */
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow);
+- FDKsbrEnc_AddVecLeft(v_freq, length_v_freq, v_freqFollow,
+- *length_v_freqFollow);
+- }
+-
+- else {
+- if (v_tuningSegm[0] != 0) { /* remove one new border and concatenate */
+- *length_v_bord = b_new - 1;
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow);
+-
+- *length_v_freq = b_new - 1;
+- FDKsbrEnc_AddVecLeft(v_freq + 1, length_v_freq, v_freqFollow,
+- *length_v_freqFollow);
+- } else {
+- if (*length_v_bordFollow >
+- 1) { /* remove one old border and concatenate */
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow - 1);
+- FDKsbrEnc_AddVecLeft(v_freq, length_v_freq, v_freqFollow,
+- *length_v_bordFollow - 1);
+-
+- *nL = *nL - 1;
+- } else { /* remove new "transient" border and concatenate */
+-
+- for (i = 0; i < *length_v_bord - 1; i++) v_bord[i] = v_bord[i + 1];
+-
+- for (i = 0; i < *length_v_freq - 1; i++) v_freq[i] = v_freq[i + 1];
+-
+- *length_v_bord = b_new - 1;
+- *length_v_freq = b_new - 1;
+-
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow);
+- FDKsbrEnc_AddVecLeft(v_freq, length_v_freq, v_freqFollow,
+- *length_v_freqFollow);
+- }
+- }
+- }
+- } else { /* middle > dmax */
+-
+- fillFramePre(dmax, v_bord, length_v_bord, v_freq, length_v_freq, bmin,
+- middle);
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow);
+- FDKsbrEnc_AddVecLeft(v_freq, length_v_freq, v_freqFollow,
+- *length_v_freqFollow);
+- }
+-
+- } else { /* numberTimeSlots==NUMBER_TIME_SLOTS_1152 */
+-
+- INT l, m;
+-
+- /*------------------------------------------------------------------------
+- remove fill borders
+- ------------------------------------------------------------------------*/
+- if (i_fillFollow >= 1) {
+- *length_v_bordFollow = i_fillFollow;
+- *length_v_freqFollow = i_fillFollow;
+- }
+-
+- numBordFollow = *length_v_bordFollow;
+- bordMaxFollow = v_bordFollow[numBordFollow - 1];
+-
+- /*------------------------------------------------------------------------
+- remove more borders if necessary to eliminate overlap
+- ------------------------------------------------------------------------*/
+-
+- /* check for overlap */
+- middle = bmin - bordMaxFollow;
+-
+- /* intervals:
+- i) middle < 0 : overlap, must remove borders
+- ii) 0 <= middle < dmin : no overlap but too tight, must remove
+- borders iii) dmin <= middle <= dmax : ok, just concatenate iv) dmax
+- <= middle : too wide, must add borders
+- */
+-
+- /* first remove old non-fill-borders... */
+- while (middle < 0) {
+- /* ...but don't remove all of them */
+- if (numBordFollow == 1) break;
+-
+- numBordFollow--;
+- bordMaxFollow = v_bordFollow[numBordFollow - 1];
+- middle = bmin - bordMaxFollow;
+- }
+-
+- /* if this isn't enough, remove new non-fill borders */
+- if (middle < 0) {
+- for (l = 0, m = 0; l < *length_v_bord; l++) {
+- if (v_bord[l] > bordMaxFollow) {
+- v_bord[m] = v_bord[l];
+- v_freq[m] = v_freq[l];
+- m++;
+- }
+- }
+-
+- *length_v_bord = l;
+- *length_v_freq = l;
+-
+- bmin = v_bord[0];
+- }
+-
+- /*------------------------------------------------------------------------
+- update modified follow-up data
+- ------------------------------------------------------------------------*/
+-
+- *length_v_bordFollow = numBordFollow;
+- *length_v_freqFollow = numBordFollow;
+-
+- /* left relative borders correspond to follow-up */
+- *nL = numBordFollow - 1;
+-
+- /*------------------------------------------------------------------------
+- take care of intervals ii through iv
+- ------------------------------------------------------------------------*/
+-
+- /* now middle should be >= 0 */
+- middle = bmin - bordMaxFollow;
+-
+- if (middle <= dmin) /* (ii) */
+- {
+- b_new = *length_v_bord;
+-
+- if (v_tuningSegm[0] != 0) {
+- /* remove new "luxury" border and concatenate */
+- *length_v_bord = b_new - 1;
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow);
+-
+- *length_v_freq = b_new - 1;
+- FDKsbrEnc_AddVecLeft(v_freq + 1, length_v_freq, v_freqFollow,
+- *length_v_freqFollow);
+-
+- } else if (*length_v_bordFollow > 1) {
+- /* remove old border and concatenate */
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow - 1);
+- FDKsbrEnc_AddVecLeft(v_freq, length_v_freq, v_freqFollow,
+- *length_v_bordFollow - 1);
+-
+- *nL = *nL - 1;
+- } else {
+- /* remove new border and concatenate */
+- for (i = 0; i < *length_v_bord - 1; i++) v_bord[i] = v_bord[i + 1];
+-
+- for (i = 0; i < *length_v_freq - 1; i++) v_freq[i] = v_freq[i + 1];
+-
+- *length_v_bord = b_new - 1;
+- *length_v_freq = b_new - 1;
+-
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow);
+- FDKsbrEnc_AddVecLeft(v_freq, length_v_freq, v_freqFollow,
+- *length_v_freqFollow);
+- }
+- } else if ((middle >= dmin) && (middle <= dmax)) /* (iii) */
+- {
+- /* concatenate */
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow);
+- FDKsbrEnc_AddVecLeft(v_freq, length_v_freq, v_freqFollow,
+- *length_v_freqFollow);
+-
+- } else /* (iv) */
+- {
+- fillFramePre(dmax, v_bord, length_v_bord, v_freq, length_v_freq, bmin,
+- middle);
+- FDKsbrEnc_AddVecLeft(v_bord, length_v_bord, v_bordFollow,
+- *length_v_bordFollow);
+- FDKsbrEnc_AddVecLeft(v_freq, length_v_freq, v_freqFollow,
+- *length_v_freqFollow);
+- }
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: calcFrameClass
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: INT* frameClass, INT* frameClassOld, INT tranFlag, INT* spreadFlag)
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void calcFrameClass(FRAME_CLASS *frameClass, FRAME_CLASS *frameClassOld,
+- INT tranFlag, INT *spreadFlag) {
+- switch (*frameClassOld) {
+- case FIXFIXonly:
+- case FIXFIX:
+- if (tranFlag)
+- *frameClass = FIXVAR;
+- else
+- *frameClass = FIXFIX;
+- break;
+- case FIXVAR:
+- if (tranFlag) {
+- *frameClass = VARVAR;
+- *spreadFlag = 0;
+- } else {
+- if (*spreadFlag)
+- *frameClass = VARVAR;
+- else
+- *frameClass = VARFIX;
+- }
+- break;
+- case VARFIX:
+- if (tranFlag)
+- *frameClass = FIXVAR;
+- else
+- *frameClass = FIXFIX;
+- break;
+- case VARVAR:
+- if (tranFlag) {
+- *frameClass = VARVAR;
+- *spreadFlag = 0;
+- } else {
+- if (*spreadFlag)
+- *frameClass = VARVAR;
+- else
+- *frameClass = VARFIX;
+- }
+- break;
+- };
+-
+- *frameClassOld = *frameClass;
+-}
+-
+-/*******************************************************************************
+- Functionname: specialCase
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: spreadFlag
+- allowSpread
+- v_bord
+- length_v_bord
+- v_freq
+- length_v_freq
+- parts
+- d
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void specialCase(INT *spreadFlag, INT allowSpread, INT *v_bord,
+- INT *length_v_bord, INT *v_freq, INT *length_v_freq,
+- INT *parts, INT d) {
+- INT L;
+-
+- L = *length_v_bord;
+-
+- if (allowSpread) { /* add one "step 8" */
+- *spreadFlag = 1;
+- FDKsbrEnc_AddRight(v_bord, length_v_bord, v_bord[L - 1] + 8);
+- FDKsbrEnc_AddRight(v_freq, length_v_freq, 1);
+- (*parts)++;
+- } else {
+- if (d == 1) { /* stretch one slot */
+- *length_v_bord = L - 1;
+- *length_v_freq = L - 1;
+- } else {
+- if ((v_bord[L - 1] - v_bord[L - 2]) > 2) { /* compress one quant step */
+- v_bord[L - 1] = v_bord[L - 1] - 2;
+- v_freq[*length_v_freq - 1] = 0; /* use low res for short segment */
+- }
+- }
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: calcCmonBorder
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: i_cmon
+- i_tran
+- v_bord
+- length_v_bord
+- tran
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void calcCmonBorder(INT *i_cmon, INT *i_tran, INT *v_bord,
+- INT *length_v_bord, INT tran, INT bufferFrameStart,
+- INT numberTimeSlots) { /* FH 00-06-26 */
+- INT i;
+-
+- for (i = 0; i < *length_v_bord; i++)
+- if (v_bord[i] >= bufferFrameStart + numberTimeSlots) { /* FH 00-06-26 */
+- *i_cmon = i;
+- break;
+- }
+-
+- /* keep track of transient: */
+- for (i = 0; i < *length_v_bord; i++)
+- if (v_bord[i] >= tran) {
+- *i_tran = i;
+- break;
+- } else
+- *i_tran = EMPTY;
+-}
+-
+-/*******************************************************************************
+- Functionname: keepForFollowUp
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: v_bordFollow
+- length_v_bordFollow
+- v_freqFollow
+- length_v_freqFollow
+- i_tranFollow
+- i_fillFollow
+- v_bord
+- length_v_bord
+- v_freq
+- i_cmon
+- i_tran
+- parts)
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void keepForFollowUp(INT *v_bordFollow, INT *length_v_bordFollow,
+- INT *v_freqFollow, INT *length_v_freqFollow,
+- INT *i_tranFollow, INT *i_fillFollow, INT *v_bord,
+- INT *length_v_bord, INT *v_freq, INT i_cmon,
+- INT i_tran, INT parts,
+- INT numberTimeSlots) { /* FH 00-06-26 */
+- INT L, i, j;
+-
+- L = *length_v_bord;
+-
+- (*length_v_bordFollow) = 0;
+- (*length_v_freqFollow) = 0;
+-
+- for (j = 0, i = i_cmon; i < L; i++, j++) {
+- v_bordFollow[j] = v_bord[i] - numberTimeSlots; /* FH 00-06-26 */
+- v_freqFollow[j] = v_freq[i];
+- (*length_v_bordFollow)++;
+- (*length_v_freqFollow)++;
+- }
+- if (i_tran != EMPTY)
+- *i_tranFollow = i_tran - i_cmon;
+- else
+- *i_tranFollow = EMPTY;
+- *i_fillFollow = L - (parts - 1) - i_cmon;
+-}
+-
+-/*******************************************************************************
+- Functionname: calcCtrlSignal
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: hSbrGrid
+- frameClass
+- v_bord
+- length_v_bord
+- v_freq
+- length_v_freq
+- i_cmon
+- i_tran
+- spreadFlag
+- nL
+-
+- Return: none
+-
+-*******************************************************************************/
+-static void calcCtrlSignal(HANDLE_SBR_GRID hSbrGrid, FRAME_CLASS frameClass,
+- INT *v_bord, INT length_v_bord, INT *v_freq,
+- INT length_v_freq, INT i_cmon, INT i_tran,
+- INT spreadFlag, INT nL) {
+- INT i, r, a, n, p, b, aL, aR, ntot, nmax, nR;
+-
+- INT *v_f = hSbrGrid->v_f;
+- INT *v_fLR = hSbrGrid->v_fLR;
+- INT *v_r = hSbrGrid->bs_rel_bord;
+- INT *v_rL = hSbrGrid->bs_rel_bord_0;
+- INT *v_rR = hSbrGrid->bs_rel_bord_1;
+-
+- INT length_v_r = 0;
+- INT length_v_rR = 0;
+- INT length_v_rL = 0;
+-
+- switch (frameClass) {
+- case FIXVAR:
+- /* absolute border: */
+-
+- a = v_bord[i_cmon];
+-
+- /* relative borders: */
+- length_v_r = 0;
+- i = i_cmon;
+-
+- while (i >= 1) {
+- r = v_bord[i] - v_bord[i - 1];
+- FDKsbrEnc_AddRight(v_r, &length_v_r, r);
+- i--;
+- }
+-
+- /* number of relative borders: */
+- n = length_v_r;
+-
+- /* freq res: */
+- for (i = 0; i < i_cmon; i++) v_f[i] = v_freq[i_cmon - 1 - i];
+- v_f[i_cmon] = 1;
+-
+- /* pointer: */
+- p = (i_cmon >= i_tran && i_tran != EMPTY) ? (i_cmon - i_tran + 1) : (0);
+-
+- hSbrGrid->frameClass = frameClass;
+- hSbrGrid->bs_abs_bord = a;
+- hSbrGrid->n = n;
+- hSbrGrid->p = p;
+-
+- break;
+- case VARFIX:
+- /* absolute border: */
+- a = v_bord[0];
+-
+- /* relative borders: */
+- length_v_r = 0;
+-
+- for (i = 1; i < length_v_bord; i++) {
+- r = v_bord[i] - v_bord[i - 1];
+- FDKsbrEnc_AddRight(v_r, &length_v_r, r);
+- }
+-
+- /* number of relative borders: */
+- n = length_v_r;
+-
+- /* freq res: */
+- FDKmemcpy(v_f, v_freq, length_v_freq * sizeof(INT));
+-
+- /* pointer: */
+- p = (i_tran >= 0 && i_tran != EMPTY) ? (i_tran + 1) : (0);
+-
+- hSbrGrid->frameClass = frameClass;
+- hSbrGrid->bs_abs_bord = a;
+- hSbrGrid->n = n;
+- hSbrGrid->p = p;
+-
+- break;
+- case VARVAR:
+- if (spreadFlag) {
+- /* absolute borders: */
+- b = length_v_bord;
+-
+- aL = v_bord[0];
+- aR = v_bord[b - 1];
+-
+- /* number of relative borders: */
+- ntot = b - 2;
+-
+- nmax = 2; /* n: {0,1,2} */
+- if (ntot > nmax) {
+- nL = nmax;
+- nR = ntot - nmax;
+- } else {
+- nL = ntot;
+- nR = 0;
+- }
+-
+- /* relative borders: */
+- length_v_rL = 0;
+- for (i = 1; i <= nL; i++) {
+- r = v_bord[i] - v_bord[i - 1];
+- FDKsbrEnc_AddRight(v_rL, &length_v_rL, r);
+- }
+-
+- length_v_rR = 0;
+- i = b - 1;
+- while (i >= b - nR) {
+- r = v_bord[i] - v_bord[i - 1];
+- FDKsbrEnc_AddRight(v_rR, &length_v_rR, r);
+- i--;
+- }
+-
+- /* pointer (only one due to constraint in frame info): */
+- p = (i_tran > 0 && i_tran != EMPTY) ? (b - i_tran) : (0);
+-
+- /* freq res: */
+-
+- for (i = 0; i < b - 1; i++) v_fLR[i] = v_freq[i];
+- } else {
+- length_v_bord = i_cmon + 1;
+-
+- /* absolute borders: */
+- b = length_v_bord;
+-
+- aL = v_bord[0];
+- aR = v_bord[b - 1];
+-
+- /* number of relative borders: */
+- ntot = b - 2;
+- nR = ntot - nL;
+-
+- /* relative borders: */
+- length_v_rL = 0;
+- for (i = 1; i <= nL; i++) {
+- r = v_bord[i] - v_bord[i - 1];
+- FDKsbrEnc_AddRight(v_rL, &length_v_rL, r);
+- }
+-
+- length_v_rR = 0;
+- i = b - 1;
+- while (i >= b - nR) {
+- r = v_bord[i] - v_bord[i - 1];
+- FDKsbrEnc_AddRight(v_rR, &length_v_rR, r);
+- i--;
+- }
+-
+- /* pointer (only one due to constraint in frame info): */
+- p = (i_cmon >= i_tran && i_tran != EMPTY) ? (i_cmon - i_tran + 1) : (0);
+-
+- /* freq res: */
+- for (i = 0; i < b - 1; i++) v_fLR[i] = v_freq[i];
+- }
+-
+- hSbrGrid->frameClass = frameClass;
+- hSbrGrid->bs_abs_bord_0 = aL;
+- hSbrGrid->bs_abs_bord_1 = aR;
+- hSbrGrid->bs_num_rel_0 = nL;
+- hSbrGrid->bs_num_rel_1 = nR;
+- hSbrGrid->p = p;
+-
+- break;
+-
+- default:
+- /* do nothing */
+- break;
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: createDefFrameInfo
+- *******************************************************************************
+-
+- Description: Copies the default (static) frameInfo structs to the frameInfo
+- passed by reference; only used for FIXFIX frames
+-
+- Arguments: hFrameInfo - HANLDE_SBR_FRAME_INFO
+- nEnv - INT
+- nTimeSlots - INT
+-
+- Return: none; hSbrFrameInfo contains a copy of the default frameInfo
+-
+- Written: Andreas Schneider
+- Revised:
+-*******************************************************************************/
+-static void createDefFrameInfo(HANDLE_SBR_FRAME_INFO hSbrFrameInfo, INT nEnv,
+- INT nTimeSlots) {
+- switch (nEnv) {
+- case 1:
+- switch (nTimeSlots) {
+- case NUMBER_TIME_SLOTS_1920:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo1_1920, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_2048:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo1_2048, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_1152:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo1_1152, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_2304:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo1_2304, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_512LD:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo1_512LD, sizeof(SBR_FRAME_INFO));
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- break;
+- case 2:
+- switch (nTimeSlots) {
+- case NUMBER_TIME_SLOTS_1920:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo2_1920, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_2048:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo2_2048, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_1152:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo2_1152, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_2304:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo2_2304, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_512LD:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo2_512LD, sizeof(SBR_FRAME_INFO));
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- break;
+- case 4:
+- switch (nTimeSlots) {
+- case NUMBER_TIME_SLOTS_1920:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo4_1920, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_2048:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo4_2048, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_1152:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo4_1152, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_2304:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo4_2304, sizeof(SBR_FRAME_INFO));
+- break;
+- case NUMBER_TIME_SLOTS_512LD:
+- FDKmemcpy(hSbrFrameInfo, &frameInfo4_512LD, sizeof(SBR_FRAME_INFO));
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: ctrlSignal2FrameInfo
+- *******************************************************************************
+-
+- Description: Convert "clear-text" sbr_grid() to "frame info" used by the
+- envelope and noise floor estimators.
+- This is basically (except for "low level" calculations) the
+- bitstream decoder defined in the MPEG-4 standard, sub clause
+- 4.6.18.3.3, Time / Frequency Grid. See inline comments for
+- explanation of the shorten and noise border algorithms.
+-
+- Arguments: hSbrGrid - source
+- hSbrFrameInfo - destination
+- freq_res_fixfix - frequency resolution for FIXFIX frames
+-
+- Return: void; hSbrFrameInfo contains the updated FRAME_INFO struct
+-
+-*******************************************************************************/
+-static void ctrlSignal2FrameInfo(
+- HANDLE_SBR_GRID hSbrGrid, /* input : the grid handle */
+- HANDLE_SBR_FRAME_INFO hSbrFrameInfo, /* output: the frame info handle */
+- FREQ_RES
+- *freq_res_fixfix /* in/out: frequency resolution for FIXFIX frames */
+-) {
+- INT frameSplit = 0;
+- INT nEnv = 0, border = 0, i, k, p /*?*/;
+- INT *v_r = hSbrGrid->bs_rel_bord;
+- INT *v_f = hSbrGrid->v_f;
+-
+- FRAME_CLASS frameClass = hSbrGrid->frameClass;
+- INT bufferFrameStart = hSbrGrid->bufferFrameStart;
+- INT numberTimeSlots = hSbrGrid->numberTimeSlots;
+-
+- switch (frameClass) {
+- case FIXFIX:
+- createDefFrameInfo(hSbrFrameInfo, hSbrGrid->bs_num_env, numberTimeSlots);
+-
+- frameSplit = (hSbrFrameInfo->nEnvelopes > 1);
+- for (i = 0; i < hSbrFrameInfo->nEnvelopes; i++) {
+- hSbrGrid->v_f[i] = hSbrFrameInfo->freqRes[i] =
+- freq_res_fixfix[frameSplit];
+- }
+- break;
+-
+- case FIXVAR:
+- case VARFIX:
+- nEnv = hSbrGrid->n + 1; /* read n [SBR_NUM_BITS bits] */ /*? snd*/
+- FDK_ASSERT(nEnv <= MAX_ENVELOPES_FIXVAR_VARFIX);
+-
+- hSbrFrameInfo->nEnvelopes = nEnv;
+-
+- border = hSbrGrid->bs_abs_bord; /* read the absolute border */
+-
+- if (nEnv == 1)
+- hSbrFrameInfo->nNoiseEnvelopes = 1;
+- else
+- hSbrFrameInfo->nNoiseEnvelopes = 2;
+-
+- break;
+-
+- default:
+- /* do nothing */
+- break;
+- }
+-
+- switch (frameClass) {
+- case FIXVAR:
+- hSbrFrameInfo->borders[0] =
+- bufferFrameStart; /* start-position of 1st envelope */
+-
+- hSbrFrameInfo->borders[nEnv] = border;
+-
+- for (k = 0, i = nEnv - 1; k < nEnv - 1; k++, i--) {
+- border -= v_r[k];
+- hSbrFrameInfo->borders[i] = border;
+- }
+-
+- /* make either envelope nr. nEnv + 1 - p short; or don't shorten if p == 0
+- */
+- p = hSbrGrid->p;
+- if (p == 0) {
+- hSbrFrameInfo->shortEnv = 0;
+- } else {
+- hSbrFrameInfo->shortEnv = nEnv + 1 - p;
+- }
+-
+- for (k = 0, i = nEnv - 1; k < nEnv; k++, i--) {
+- hSbrFrameInfo->freqRes[i] = (FREQ_RES)v_f[k];
+- }
+-
+- /* if either there is no short envelope or the last envelope is short...
+- */
+- if (p == 0 || p == 1) {
+- hSbrFrameInfo->bordersNoise[1] = hSbrFrameInfo->borders[nEnv - 1];
+- } else {
+- hSbrFrameInfo->bordersNoise[1] =
+- hSbrFrameInfo->borders[hSbrFrameInfo->shortEnv];
+- }
+-
+- break;
+-
+- case VARFIX:
+- /* in this case 'border' indicates the start of the 1st envelope */
+- hSbrFrameInfo->borders[0] = border;
+-
+- for (k = 0; k < nEnv - 1; k++) {
+- border += v_r[k];
+- hSbrFrameInfo->borders[k + 1] = border;
+- }
+-
+- hSbrFrameInfo->borders[nEnv] = bufferFrameStart + numberTimeSlots;
+-
+- p = hSbrGrid->p;
+- if (p == 0 || p == 1) {
+- hSbrFrameInfo->shortEnv = 0;
+- } else {
+- hSbrFrameInfo->shortEnv = p - 1;
+- }
+-
+- for (k = 0; k < nEnv; k++) {
+- hSbrFrameInfo->freqRes[k] = (FREQ_RES)v_f[k];
+- }
+-
+- switch (p) {
+- case 0:
+- hSbrFrameInfo->bordersNoise[1] = hSbrFrameInfo->borders[1];
+- break;
+- case 1:
+- hSbrFrameInfo->bordersNoise[1] = hSbrFrameInfo->borders[nEnv - 1];
+- break;
+- default:
+- hSbrFrameInfo->bordersNoise[1] =
+- hSbrFrameInfo->borders[hSbrFrameInfo->shortEnv];
+- break;
+- }
+- break;
+-
+- case VARVAR:
+- nEnv = hSbrGrid->bs_num_rel_0 + hSbrGrid->bs_num_rel_1 + 1;
+- FDK_ASSERT(nEnv <= MAX_ENVELOPES_VARVAR); /* just to be sure */
+- hSbrFrameInfo->nEnvelopes = nEnv;
+-
+- hSbrFrameInfo->borders[0] = border = hSbrGrid->bs_abs_bord_0;
+-
+- for (k = 0, i = 1; k < hSbrGrid->bs_num_rel_0; k++, i++) {
+- border += hSbrGrid->bs_rel_bord_0[k];
+- hSbrFrameInfo->borders[i] = border;
+- }
+-
+- border = hSbrGrid->bs_abs_bord_1;
+- hSbrFrameInfo->borders[nEnv] = border;
+-
+- for (k = 0, i = nEnv - 1; k < hSbrGrid->bs_num_rel_1; k++, i--) {
+- border -= hSbrGrid->bs_rel_bord_1[k];
+- hSbrFrameInfo->borders[i] = border;
+- }
+-
+- p = hSbrGrid->p;
+- if (p == 0) {
+- hSbrFrameInfo->shortEnv = 0;
+- } else {
+- hSbrFrameInfo->shortEnv = nEnv + 1 - p;
+- }
+-
+- for (k = 0; k < nEnv; k++) {
+- hSbrFrameInfo->freqRes[k] = (FREQ_RES)hSbrGrid->v_fLR[k];
+- }
+-
+- if (nEnv == 1) {
+- hSbrFrameInfo->nNoiseEnvelopes = 1;
+- hSbrFrameInfo->bordersNoise[0] = hSbrGrid->bs_abs_bord_0;
+- hSbrFrameInfo->bordersNoise[1] = hSbrGrid->bs_abs_bord_1;
+- } else {
+- hSbrFrameInfo->nNoiseEnvelopes = 2;
+- hSbrFrameInfo->bordersNoise[0] = hSbrGrid->bs_abs_bord_0;
+-
+- if (p == 0 || p == 1) {
+- hSbrFrameInfo->bordersNoise[1] = hSbrFrameInfo->borders[nEnv - 1];
+- } else {
+- hSbrFrameInfo->bordersNoise[1] =
+- hSbrFrameInfo->borders[hSbrFrameInfo->shortEnv];
+- }
+- hSbrFrameInfo->bordersNoise[2] = hSbrGrid->bs_abs_bord_1;
+- }
+- break;
+-
+- default:
+- /* do nothing */
+- break;
+- }
+-
+- if (frameClass == VARFIX || frameClass == FIXVAR) {
+- hSbrFrameInfo->bordersNoise[0] = hSbrFrameInfo->borders[0];
+- if (nEnv == 1) {
+- hSbrFrameInfo->bordersNoise[1] = hSbrFrameInfo->borders[nEnv];
+- } else {
+- hSbrFrameInfo->bordersNoise[2] = hSbrFrameInfo->borders[nEnv];
+- }
+- }
+-}
+diff --git a/libSBRenc/src/fram_gen.h b/libSBRenc/src/fram_gen.h
+deleted file mode 100644
+index 0c5edc3..0000000
+--- a/libSBRenc/src/fram_gen.h
++++ /dev/null
+@@ -1,343 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Framing generator prototypes and structs $Revision: 92790 $
+-*/
+-#ifndef FRAM_GEN_H
+-#define FRAM_GEN_H
+-
+-#include "sbr_def.h" /* for MAX_ENVELOPES and MAX_NOISE_ENVELOPES in struct FRAME_INFO and CODEC_TYPE */
+-#include "sbr_encoder.h" /* for FREQ_RES */
+-
+-#define MAX_ENVELOPES_VARVAR \
+- MAX_ENVELOPES /*!< worst case number of envelopes in a VARVAR frame */
+-#define MAX_ENVELOPES_FIXVAR_VARFIX \
+- 4 /*!< worst case number of envelopes in VARFIX and FIXVAR frames */
+-#define MAX_NUM_REL \
+- 3 /*!< maximum number of relative borders in any VAR frame */
+-
+-/* SBR frame class definitions */
+-typedef enum {
+- FIXFIX =
+- 0, /*!< bs_frame_class: leading and trailing frame borders are fixed */
+- FIXVAR, /*!< bs_frame_class: leading frame border is fixed, trailing frame
+- border is variable */
+- VARFIX, /*!< bs_frame_class: leading frame border is variable, trailing frame
+- border is fixed */
+- VARVAR /*!< bs_frame_class: leading and trailing frame borders are variable */
+- ,
+- FIXFIXonly /*!< bs_frame_class: leading border fixed (0), trailing border
+- fixed (nrTimeSlots) and encased borders are dynamically derived
+- from the tranPos */
+-} FRAME_CLASS;
+-
+-/* helper constants */
+-#define DC 4711 /*!< helper constant: don't care */
+-#define EMPTY (-99) /*!< helper constant: empty */
+-
+-/* system constants: AAC+SBR, DRM Frame-Length */
+-#define FRAME_MIDDLE_SLOT_1920 4
+-#define NUMBER_TIME_SLOTS_1920 15
+-
+-#define LD_PRETRAN_OFF 3
+-#define FRAME_MIDDLE_SLOT_512LD 4
+-#define NUMBER_TIME_SLOTS_512LD 8
+-#define TRANSIENT_OFFSET_LD 0
+-
+-/*
+-system constants: AAC+SBR or aacPRO (hybrid format), Standard Frame-Length,
+-Multi-Rate
+----------------------------------------------------------------------------
+-Number of slots (numberTimeSlots): 16 (NUMBER_TIME_SLOTS_2048)
+-Detector-offset (frameMiddleSlot): 4
+-Overlap : 3
+-Buffer-offset : 8 (BUFFER_FRAME_START_2048 = 0)
+-
+-
+- |<------------tranPos---------->|
+- |c|d|e|f|0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|
+- FixFix | |
+- FixVar | :<- ->:
+- VarFix :<- ->: |
+- VarVar :<- ->: :<- ->:
+- 0 1 2 3 4 5 6 7 8 9 a b c d e f 0 1 2 3
+-................................................................................
+-
+-|-|-|-|-|-|-|-|-B-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-B-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
+-
+-frame-generator:0 16 24 32
+-analysis-buffer:8 24 32 40
+-*/
+-#define FRAME_MIDDLE_SLOT_2048 4
+-#define NUMBER_TIME_SLOTS_2048 16
+-
+-/*
+-system constants: mp3PRO, Multi-Rate & Single-Rate
+---------------------------------------------------
+-Number of slots (numberTimeSlots): 9 (NUMBER_TIME_SLOTS_1152)
+-Detector-offset (frameMiddleSlot): 4 (FRAME_MIDDLE_SLOT_1152)
+-Overlap : 3
+-Buffer-offset : 4.5 (BUFFER_FRAME_START_1152 = 0)
+-
+-
+- |<----tranPos---->|
+- |5|6|7|8|0|1|2|3|4|5|6|7|8|
+- FixFix | |
+- FixVar | :<- ->:
+- VarFix :<- ->: |
+- VarVar :<- ->: :<- ->:
+- 0 1 2 3 4 5 6 7 8 0 1 2 3
+- .............................................
+-
+- -|-|-|-|-B-|-|-|-|-|-|-|-|-B-|-|-|-|-|-|-|-|-|
+-
+-frame-generator: 0 9 13 18
+-analysis-buffer: 4.5 13.5 22.5
+-*/
+-#define FRAME_MIDDLE_SLOT_1152 4
+-#define NUMBER_TIME_SLOTS_1152 9
+-
+-/* system constants: Layer2+SBR */
+-#define FRAME_MIDDLE_SLOT_2304 8
+-#define NUMBER_TIME_SLOTS_2304 18
+-
+-/*!
+- \struct SBR_GRID
+- \brief sbr_grid() signals to be converted to bitstream elements
+-
+- The variables hold the signals (e.g. lengths and numbers) in "clear text"
+-*/
+-
+-typedef struct {
+- /* system constants */
+- INT bufferFrameStart; /*!< frame generator vs analysis buffer time alignment
+- (currently set to 0, offset added elsewhere) */
+- INT numberTimeSlots; /*!< number of SBR timeslots per frame */
+-
+- /* will be adjusted for every frame */
+- FRAME_CLASS frameClass; /*!< SBR frame class */
+- INT bs_num_env; /*!< bs_num_env, number of envelopes for FIXFIX */
+- INT bs_abs_bord; /*!< bs_abs_bord, absolute border for VARFIX and FIXVAR */
+- INT n; /*!< number of relative borders for VARFIX and FIXVAR */
+- INT p; /*!< pointer-to-transient-border */
+- INT bs_rel_bord[MAX_NUM_REL]; /*!< bs_rel_bord, relative borders for all VAR
+- */
+- INT v_f[MAX_ENVELOPES_FIXVAR_VARFIX]; /*!< envelope frequency resolutions for
+- FIXVAR and VARFIX */
+-
+- INT bs_abs_bord_0; /*!< bs_abs_bord_0, leading absolute border for VARVAR */
+- INT bs_abs_bord_1; /*!< bs_abs_bord_1, trailing absolute border for VARVAR */
+- INT bs_num_rel_0; /*!< bs_num_rel_0, number of relative borders associated
+- with leading absolute border for VARVAR */
+- INT bs_num_rel_1; /*!< bs_num_rel_1, number of relative borders associated
+- with trailing absolute border for VARVAR */
+- INT bs_rel_bord_0[MAX_NUM_REL]; /*!< bs_rel_bord_0, relative borders
+- associated with leading absolute border
+- for VARVAR */
+- INT bs_rel_bord_1[MAX_NUM_REL]; /*!< bs_rel_bord_1, relative borders
+- associated with trailing absolute border
+- for VARVAR */
+- INT v_fLR[MAX_ENVELOPES_VARVAR]; /*!< envelope frequency resolutions for
+- VARVAR */
+-
+-} SBR_GRID;
+-typedef SBR_GRID *HANDLE_SBR_GRID;
+-
+-/*!
+- \struct SBR_FRAME_INFO
+- \brief time/frequency grid description for one frame
+-*/
+-typedef struct {
+- INT nEnvelopes; /*!< number of envelopes */
+- INT borders[MAX_ENVELOPES + 1]; /*!< envelope borders in SBR timeslots */
+- FREQ_RES freqRes[MAX_ENVELOPES]; /*!< frequency resolution of each envelope */
+- INT shortEnv; /*!< number of an envelope to be shortened (starting at 1) or 0
+- for no shortened envelope */
+- INT nNoiseEnvelopes; /*!< number of noise floors */
+- INT bordersNoise[MAX_NOISE_ENVELOPES +
+- 1]; /*!< noise floor borders in SBR timeslots */
+-} SBR_FRAME_INFO;
+-/* WARNING: When rearranging the elements of this struct keep in mind that the
+- * static initializations in the corresponding C-file have to be rearranged as
+- * well! snd 2002/01/23
+- */
+-typedef SBR_FRAME_INFO *HANDLE_SBR_FRAME_INFO;
+-
+-/*!
+- \struct SBR_ENVELOPE_FRAME
+- \brief frame generator main struct
+-
+- Contains tuning parameters, time/frequency grid description, sbr_grid()
+- bitstream elements, and generator internal signals
+-*/
+-typedef struct {
+- /* system constants */
+- INT frameMiddleSlot; /*!< transient detector offset in SBR timeslots */
+-
+- /* basic tuning parameters */
+- INT staticFraming; /*!< 1: run static framing in time, i.e. exclusive use of
+- bs_frame_class = FIXFIX */
+- INT numEnvStatic; /*!< number of envelopes per frame for static framing */
+- FREQ_RES
+- freq_res_fixfix[2]; /*!< envelope frequency resolution to use for
+- bs_frame_class = FIXFIX; single env and split */
+- UCHAR
+- fResTransIsLow; /*!< frequency resolution for transient frames - always
+- low (0) or according to table (1) */
+-
+- /* expert tuning parameters */
+- const int *v_tuningSegm; /*!< segment lengths to use around transient */
+- const int *v_tuningFreq; /*!< frequency resolutions to use around transient */
+- INT dmin; /*!< minimum length of dependent segments */
+- INT dmax; /*!< maximum length of dependent segments */
+- INT allowSpread; /*!< 1: allow isolated transient to influence grid of 3
+- consecutive frames */
+-
+- /* internally used signals */
+- FRAME_CLASS frameClassOld; /*!< frame class used for previous frame */
+- INT spreadFlag; /*!< 1: use VARVAR instead of VARFIX to follow up old
+- transient */
+-
+- INT v_bord[2 * MAX_ENVELOPES_VARVAR + 1]; /*!< borders for current frame and
+- preliminary borders for next
+- frame (fixed borders excluded) */
+- INT length_v_bord; /*!< helper variable: length of v_bord */
+- INT v_freq[2 * MAX_ENVELOPES_VARVAR + 1]; /*!< frequency resolutions for
+- current frame and preliminary
+- resolutions for next frame */
+- INT length_v_freq; /*!< helper variable: length of v_freq */
+-
+- INT v_bordFollow[MAX_ENVELOPES_VARVAR]; /*!< preliminary borders for current
+- frame (calculated during previous
+- frame) */
+- INT length_v_bordFollow; /*!< helper variable: length of v_bordFollow */
+- INT i_tranFollow; /*!< points to transient border in v_bordFollow (may be
+- negative, see keepForFollowUp()) */
+- INT i_fillFollow; /*!< points to first fill border in v_bordFollow */
+- INT v_freqFollow[MAX_ENVELOPES_VARVAR]; /*!< preliminary frequency resolutions
+- for current frame (calculated
+- during previous frame) */
+- INT length_v_freqFollow; /*!< helper variable: length of v_freqFollow */
+-
+- /* externally needed signals */
+- SBR_GRID
+- SbrGrid; /*!< sbr_grid() signals to be converted to bitstream elements */
+- SBR_FRAME_INFO
+- SbrFrameInfo; /*!< time/frequency grid description for one frame */
+-} SBR_ENVELOPE_FRAME;
+-typedef SBR_ENVELOPE_FRAME *HANDLE_SBR_ENVELOPE_FRAME;
+-
+-void FDKsbrEnc_initFrameInfoGenerator(HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame,
+- INT allowSpread, INT numEnvStatic,
+- INT staticFraming, INT timeSlots,
+- const FREQ_RES *freq_res_fixfix,
+- UCHAR fResTransIsLow, INT ldGrid);
+-
+-HANDLE_SBR_FRAME_INFO
+-FDKsbrEnc_frameInfoGenerator(HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame,
+- UCHAR *v_transient_info, const INT rightBorderFIX,
+- UCHAR *v_transient_info_pre, int ldGrid,
+- const int *v_tuning);
+-
+-#endif
+diff --git a/libSBRenc/src/invf_est.cpp b/libSBRenc/src/invf_est.cpp
+deleted file mode 100644
+index 53b47ac..0000000
+--- a/libSBRenc/src/invf_est.cpp
++++ /dev/null
+@@ -1,610 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "invf_est.h"
+-#include "sbr_misc.h"
+-
+-#include "genericStds.h"
+-
+-#define MAX_NUM_REGIONS 10
+-#define SCALE_FAC_QUO 512.0f
+-#define SCALE_FAC_NRG 256.0f
+-
+-#ifndef min
+-#define min(a, b) (a < b ? a : b)
+-#endif
+-
+-#ifndef max
+-#define max(a, b) (a > b ? a : b)
+-#endif
+-
+-static const FIXP_DBL quantStepsSbr[4] = {
+- 0x00400000, 0x02800000, 0x03800000,
+- 0x04c00000}; /* table scaled with SCALE_FAC_QUO */
+-static const FIXP_DBL quantStepsOrig[4] = {
+- 0x00000000, 0x00c00000, 0x01c00000,
+- 0x02800000}; /* table scaled with SCALE_FAC_QUO */
+-static const FIXP_DBL nrgBorders[4] = {
+- 0x0c800000, 0x0f000000, 0x11800000,
+- 0x14000000}; /* table scaled with SCALE_FAC_NRG */
+-
+-static const DETECTOR_PARAMETERS detectorParamsAAC = {
+- quantStepsSbr,
+- quantStepsOrig,
+- nrgBorders,
+- 4, /* Number of borders SBR. */
+- 4, /* Number of borders orig. */
+- 4, /* Number of borders Nrg. */
+- {
+- /* Region space. */
+- {INVF_MID_LEVEL, INVF_LOW_LEVEL, INVF_OFF, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_MID_LEVEL, INVF_LOW_LEVEL, INVF_OFF, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_LOW_LEVEL, INVF_OFF,
+- INVF_OFF}, /* regionSbr */
+- {INVF_HIGH_LEVEL, INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_HIGH_LEVEL, INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF} /* | */
+- }, /*------------------------ regionOrig ---------------------------------*/
+- {
+- /* Region space transient. */
+- {INVF_LOW_LEVEL, INVF_LOW_LEVEL, INVF_LOW_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_LOW_LEVEL, INVF_LOW_LEVEL, INVF_LOW_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF}, /* regionSbr */
+- {INVF_HIGH_LEVEL, INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_HIGH_LEVEL, INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF} /* | */
+- }, /*------------------------ regionOrig ---------------------------------*/
+- {-4, -3, -2, -1,
+- 0} /* Reduction factor of the inverse filtering for low energies.*/
+-};
+-
+-static const FIXP_DBL hysteresis =
+- 0x00400000; /* Delta value for hysteresis. scaled with SCALE_FAC_QUO */
+-
+-/*
+- * AAC+SBR PARAMETERS for Speech
+- *********************************/
+-static const DETECTOR_PARAMETERS detectorParamsAACSpeech = {
+- quantStepsSbr,
+- quantStepsOrig,
+- nrgBorders,
+- 4, /* Number of borders SBR. */
+- 4, /* Number of borders orig. */
+- 4, /* Number of borders Nrg. */
+- {
+- /* Region space. */
+- {INVF_MID_LEVEL, INVF_MID_LEVEL, INVF_LOW_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_MID_LEVEL, INVF_MID_LEVEL, INVF_LOW_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF}, /* regionSbr */
+- {INVF_HIGH_LEVEL, INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_HIGH_LEVEL, INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF} /* | */
+- }, /*------------------------ regionOrig ---------------------------------*/
+- {
+- /* Region space transient. */
+- {INVF_MID_LEVEL, INVF_MID_LEVEL, INVF_LOW_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_MID_LEVEL, INVF_MID_LEVEL, INVF_LOW_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF}, /* regionSbr */
+- {INVF_HIGH_LEVEL, INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF}, /* | */
+- {INVF_HIGH_LEVEL, INVF_HIGH_LEVEL, INVF_MID_LEVEL, INVF_OFF,
+- INVF_OFF} /* | */
+- }, /*------------------------ regionOrig ---------------------------------*/
+- {-4, -3, -2, -1,
+- 0} /* Reduction factor of the inverse filtering for low energies.*/
+-};
+-
+-/*
+- * Smoothing filters.
+- ************************/
+-typedef const FIXP_DBL FIR_FILTER[5];
+-
+-static const FIR_FILTER fir_0 = {0x7fffffff, 0x00000000, 0x00000000, 0x00000000,
+- 0x00000000};
+-static const FIR_FILTER fir_1 = {0x2aaaaa80, 0x555554ff, 0x00000000, 0x00000000,
+- 0x00000000};
+-static const FIR_FILTER fir_2 = {0x10000000, 0x30000000, 0x40000000, 0x00000000,
+- 0x00000000};
+-static const FIR_FILTER fir_3 = {0x077f80e8, 0x199999a0, 0x2bb3b240, 0x33333340,
+- 0x00000000};
+-static const FIR_FILTER fir_4 = {0x04130598, 0x0ebdb000, 0x1becfa60, 0x2697a4c0,
+- 0x2aaaaa80};
+-
+-static const FIR_FILTER *const fir_table[5] = {&fir_0, &fir_1, &fir_2, &fir_3,
+- &fir_4};
+-
+-/**************************************************************************/
+-/*!
+- \brief Calculates the values used for the detector.
+-
+-
+- \return none
+-
+-*/
+-/**************************************************************************/
+-static void calculateDetectorValues(
+- FIXP_DBL **quotaMatrixOrig, /*!< Matrix holding the tonality values of the
+- original. */
+- SCHAR *indexVector, /*!< Index vector to obtain the patched data. */
+- FIXP_DBL *nrgVector, /*!< Energy vector. */
+- DETECTOR_VALUES *detectorValues, /*!< pointer to DETECTOR_VALUES struct. */
+- INT startChannel, /*!< Start channel. */
+- INT stopChannel, /*!< Stop channel. */
+- INT startIndex, /*!< Start index. */
+- INT stopIndex, /*!< Stop index. */
+- INT numberOfStrongest /*!< The number of sorted tonal components to be
+- considered. */
+-) {
+- INT i, temp, j;
+-
+- const FIXP_DBL *filter = *fir_table[INVF_SMOOTHING_LENGTH];
+- FIXP_DBL origQuotaMeanStrongest, sbrQuotaMeanStrongest;
+- FIXP_DBL origQuota, sbrQuota;
+- FIXP_DBL invIndex, invChannel, invTemp;
+- FIXP_DBL quotaVecOrig[64], quotaVecSbr[64];
+-
+- FDKmemclear(quotaVecOrig, 64 * sizeof(FIXP_DBL));
+- FDKmemclear(quotaVecSbr, 64 * sizeof(FIXP_DBL));
+-
+- invIndex = GetInvInt(stopIndex - startIndex);
+- invChannel = GetInvInt(stopChannel - startChannel);
+-
+- /*
+- Calculate the mean value, over the current time segment, for the original,
+- the HFR and the difference, over all channels in the current frequency range.
+- NOTE: the averaging is done on the values quota/(1 - quota + RELAXATION).
+- */
+-
+- /* The original, the sbr signal and the total energy */
+- detectorValues->avgNrg = FL2FXCONST_DBL(0.0f);
+- for (j = startIndex; j < stopIndex; j++) {
+- for (i = startChannel; i < stopChannel; i++) {
+- quotaVecOrig[i] += fMult(quotaMatrixOrig[j][i], invIndex);
+-
+- if (indexVector[i] != -1)
+- quotaVecSbr[i] += fMult(quotaMatrixOrig[j][indexVector[i]], invIndex);
+- }
+- detectorValues->avgNrg += fMult(nrgVector[j], invIndex);
+- }
+-
+- /*
+- Calculate the mean value, over the current frequency range, for the original,
+- the HFR and the difference. Also calculate the same mean values for the three
+- vectors, but only includeing the x strongest copmponents.
+- */
+-
+- origQuota = FL2FXCONST_DBL(0.0f);
+- sbrQuota = FL2FXCONST_DBL(0.0f);
+- for (i = startChannel; i < stopChannel; i++) {
+- origQuota += fMultDiv2(quotaVecOrig[i], invChannel);
+- sbrQuota += fMultDiv2(quotaVecSbr[i], invChannel);
+- }
+-
+- /*
+- Calculate the mean value for the x strongest components
+- */
+- FDKsbrEnc_Shellsort_fract(quotaVecOrig + startChannel,
+- stopChannel - startChannel);
+- FDKsbrEnc_Shellsort_fract(quotaVecSbr + startChannel,
+- stopChannel - startChannel);
+-
+- origQuotaMeanStrongest = FL2FXCONST_DBL(0.0f);
+- sbrQuotaMeanStrongest = FL2FXCONST_DBL(0.0f);
+-
+- temp = min(stopChannel - startChannel, numberOfStrongest);
+- invTemp = GetInvInt(temp);
+-
+- for (i = 0; i < temp; i++) {
+- origQuotaMeanStrongest +=
+- fMultDiv2(quotaVecOrig[i + stopChannel - temp], invTemp);
+- sbrQuotaMeanStrongest +=
+- fMultDiv2(quotaVecSbr[i + stopChannel - temp], invTemp);
+- }
+-
+- /*
+- The value for the strongest component
+- */
+- detectorValues->origQuotaMax = quotaVecOrig[stopChannel - 1];
+- detectorValues->sbrQuotaMax = quotaVecSbr[stopChannel - 1];
+-
+- /*
+- Buffer values
+- */
+- FDKmemmove(detectorValues->origQuotaMean, detectorValues->origQuotaMean + 1,
+- INVF_SMOOTHING_LENGTH * sizeof(FIXP_DBL));
+- FDKmemmove(detectorValues->sbrQuotaMean, detectorValues->sbrQuotaMean + 1,
+- INVF_SMOOTHING_LENGTH * sizeof(FIXP_DBL));
+- FDKmemmove(detectorValues->origQuotaMeanStrongest,
+- detectorValues->origQuotaMeanStrongest + 1,
+- INVF_SMOOTHING_LENGTH * sizeof(FIXP_DBL));
+- FDKmemmove(detectorValues->sbrQuotaMeanStrongest,
+- detectorValues->sbrQuotaMeanStrongest + 1,
+- INVF_SMOOTHING_LENGTH * sizeof(FIXP_DBL));
+-
+- detectorValues->origQuotaMean[INVF_SMOOTHING_LENGTH] = origQuota << 1;
+- detectorValues->sbrQuotaMean[INVF_SMOOTHING_LENGTH] = sbrQuota << 1;
+- detectorValues->origQuotaMeanStrongest[INVF_SMOOTHING_LENGTH] =
+- origQuotaMeanStrongest << 1;
+- detectorValues->sbrQuotaMeanStrongest[INVF_SMOOTHING_LENGTH] =
+- sbrQuotaMeanStrongest << 1;
+-
+- /*
+- Filter values
+- */
+- detectorValues->origQuotaMeanFilt = FL2FXCONST_DBL(0.0f);
+- detectorValues->sbrQuotaMeanFilt = FL2FXCONST_DBL(0.0f);
+- detectorValues->origQuotaMeanStrongestFilt = FL2FXCONST_DBL(0.0f);
+- detectorValues->sbrQuotaMeanStrongestFilt = FL2FXCONST_DBL(0.0f);
+-
+- for (i = 0; i < INVF_SMOOTHING_LENGTH + 1; i++) {
+- detectorValues->origQuotaMeanFilt +=
+- fMult(detectorValues->origQuotaMean[i], filter[i]);
+- detectorValues->sbrQuotaMeanFilt +=
+- fMult(detectorValues->sbrQuotaMean[i], filter[i]);
+- detectorValues->origQuotaMeanStrongestFilt +=
+- fMult(detectorValues->origQuotaMeanStrongest[i], filter[i]);
+- detectorValues->sbrQuotaMeanStrongestFilt +=
+- fMult(detectorValues->sbrQuotaMeanStrongest[i], filter[i]);
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Returns the region in which the input value belongs.
+-
+-
+-
+- \return region.
+-
+-*/
+-/**************************************************************************/
+-static INT findRegion(
+- FIXP_DBL currVal, /*!< The current value. */
+- const FIXP_DBL *borders, /*!< The border of the regions. */
+- const INT numBorders /*!< The number of borders. */
+-) {
+- INT i;
+-
+- if (currVal < borders[0]) {
+- return 0;
+- }
+-
+- for (i = 1; i < numBorders; i++) {
+- if (currVal >= borders[i - 1] && currVal < borders[i]) {
+- return i;
+- }
+- }
+-
+- if (currVal >= borders[numBorders - 1]) {
+- return numBorders;
+- }
+-
+- return 0; /* We never get here, it's just to avoid compiler warnings.*/
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Makes a clever decision based on the quota vector.
+-
+-
+- \return decision on which invf mode to use
+-
+-*/
+-/**************************************************************************/
+-static INVF_MODE decisionAlgorithm(
+- const DETECTOR_PARAMETERS
+- *detectorParams, /*!< Struct with the detector parameters. */
+- DETECTOR_VALUES *detectorValues, /*!< Struct with the detector values. */
+- INT transientFlag, /*!< Flag indicating if there is a transient present.*/
+- INT *prevRegionSbr, /*!< The previous region in which the Sbr value was. */
+- INT *prevRegionOrig /*!< The previous region in which the Orig value was. */
+-) {
+- INT invFiltLevel, regionSbr, regionOrig, regionNrg;
+-
+- /*
+- Current thresholds.
+- */
+- const INT numRegionsSbr = detectorParams->numRegionsSbr;
+- const INT numRegionsOrig = detectorParams->numRegionsOrig;
+- const INT numRegionsNrg = detectorParams->numRegionsNrg;
+-
+- FIXP_DBL quantStepsSbrTmp[MAX_NUM_REGIONS];
+- FIXP_DBL quantStepsOrigTmp[MAX_NUM_REGIONS];
+-
+- /*
+- Current detector values.
+- */
+- FIXP_DBL origQuotaMeanFilt;
+- FIXP_DBL sbrQuotaMeanFilt;
+- FIXP_DBL nrg;
+-
+- /* 0.375 = 3.0 / 8.0; 0.31143075889 = log2(RELAXATION)/64.0; 0.625 =
+- * log(16)/64.0; 0.6875 = 44/64.0 */
+- origQuotaMeanFilt =
+- (fMultDiv2(FL2FXCONST_DBL(2.f * 0.375f),
+- (FIXP_DBL)(CalcLdData(max(detectorValues->origQuotaMeanFilt,
+- (FIXP_DBL)1)) +
+- FL2FXCONST_DBL(0.31143075889f))))
+- << 0; /* scaled by 1/2^9 */
+- sbrQuotaMeanFilt =
+- (fMultDiv2(FL2FXCONST_DBL(2.f * 0.375f),
+- (FIXP_DBL)(CalcLdData(max(detectorValues->sbrQuotaMeanFilt,
+- (FIXP_DBL)1)) +
+- FL2FXCONST_DBL(0.31143075889f))))
+- << 0; /* scaled by 1/2^9 */
+- /* If energy is zero then we will get different results for different word
+- * lengths. */
+- nrg =
+- (fMultDiv2(FL2FXCONST_DBL(2.f * 0.375f),
+- (FIXP_DBL)(CalcLdData(detectorValues->avgNrg + (FIXP_DBL)1) +
+- FL2FXCONST_DBL(0.0625f) + FL2FXCONST_DBL(0.6875f))))
+- << 0; /* scaled by 1/2^8; 2^44 -> qmf energy scale */
+-
+- FDKmemcpy(quantStepsSbrTmp, detectorParams->quantStepsSbr,
+- numRegionsSbr * sizeof(FIXP_DBL));
+- FDKmemcpy(quantStepsOrigTmp, detectorParams->quantStepsOrig,
+- numRegionsOrig * sizeof(FIXP_DBL));
+-
+- if (*prevRegionSbr < numRegionsSbr)
+- quantStepsSbrTmp[*prevRegionSbr] =
+- detectorParams->quantStepsSbr[*prevRegionSbr] + hysteresis;
+- if (*prevRegionSbr > 0)
+- quantStepsSbrTmp[*prevRegionSbr - 1] =
+- detectorParams->quantStepsSbr[*prevRegionSbr - 1] - hysteresis;
+-
+- if (*prevRegionOrig < numRegionsOrig)
+- quantStepsOrigTmp[*prevRegionOrig] =
+- detectorParams->quantStepsOrig[*prevRegionOrig] + hysteresis;
+- if (*prevRegionOrig > 0)
+- quantStepsOrigTmp[*prevRegionOrig - 1] =
+- detectorParams->quantStepsOrig[*prevRegionOrig - 1] - hysteresis;
+-
+- regionSbr = findRegion(sbrQuotaMeanFilt, quantStepsSbrTmp, numRegionsSbr);
+- regionOrig = findRegion(origQuotaMeanFilt, quantStepsOrigTmp, numRegionsOrig);
+- regionNrg = findRegion(nrg, detectorParams->nrgBorders, numRegionsNrg);
+-
+- *prevRegionSbr = regionSbr;
+- *prevRegionOrig = regionOrig;
+-
+- /* Use different settings if a transient is present*/
+- invFiltLevel =
+- (transientFlag == 1)
+- ? detectorParams->regionSpaceTransient[regionSbr][regionOrig]
+- : detectorParams->regionSpace[regionSbr][regionOrig];
+-
+- /* Compensate for low energy.*/
+- invFiltLevel =
+- max(invFiltLevel + detectorParams->EnergyCompFactor[regionNrg], 0);
+-
+- return (INVF_MODE)(invFiltLevel);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Estiamtion of the inverse filtering level required
+- in the decoder.
+-
+- A second order LPC is calculated for every filterbank channel, using
+- the covariance method. THe ratio between the energy of the predicted
+- signal and the energy of the non-predictable signal is calcualted.
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-void FDKsbrEnc_qmfInverseFilteringDetector(
+- HANDLE_SBR_INV_FILT_EST
+- hInvFilt, /*!< Handle to the SBR_INV_FILT_EST struct. */
+- FIXP_DBL **quotaMatrix, /*!< The matrix holding the tonality values of the
+- original. */
+- FIXP_DBL *nrgVector, /*!< The energy vector. */
+- SCHAR *indexVector, /*!< Index vector to obtain the patched data. */
+- INT startIndex, /*!< Start index. */
+- INT stopIndex, /*!< Stop index. */
+- INT transientFlag, /*!< Flag indicating if a transient is present or not.*/
+- INVF_MODE *infVec /*!< Vector holding the inverse filtering levels. */
+-) {
+- INT band;
+-
+- /*
+- * Do the inverse filtering level estimation.
+- *****************************************************/
+- for (band = 0; band < hInvFilt->noDetectorBands; band++) {
+- INT startChannel = hInvFilt->freqBandTableInvFilt[band];
+- INT stopChannel = hInvFilt->freqBandTableInvFilt[band + 1];
+-
+- calculateDetectorValues(quotaMatrix, indexVector, nrgVector,
+- &hInvFilt->detectorValues[band], startChannel,
+- stopChannel, startIndex, stopIndex,
+- hInvFilt->numberOfStrongest);
+-
+- infVec[band] = decisionAlgorithm(
+- hInvFilt->detectorParams, &hInvFilt->detectorValues[band],
+- transientFlag, &hInvFilt->prevRegionSbr[band],
+- &hInvFilt->prevRegionOrig[band]);
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Initialize an instance of the inverse filtering level estimator.
+-
+-
+- \return errorCode, noError if successful.
+-
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_initInvFiltDetector(
+- HANDLE_SBR_INV_FILT_EST
+- hInvFilt, /*!< Pointer to a handle to the SBR_INV_FILT_EST struct. */
+- INT *freqBandTableDetector, /*!< Frequency band table for the inverse
+- filtering. */
+- INT numDetectorBands, /*!< Number of inverse filtering bands. */
+- UINT
+- useSpeechConfig /*!< Flag: adapt tuning parameters according to speech*/
+-) {
+- INT i;
+-
+- FDKmemclear(hInvFilt, sizeof(SBR_INV_FILT_EST));
+-
+- hInvFilt->detectorParams =
+- (useSpeechConfig) ? &detectorParamsAACSpeech : &detectorParamsAAC;
+-
+- hInvFilt->noDetectorBandsMax = numDetectorBands;
+-
+- /*
+- Memory initialisation
+- */
+- for (i = 0; i < hInvFilt->noDetectorBandsMax; i++) {
+- FDKmemclear(&hInvFilt->detectorValues[i], sizeof(DETECTOR_VALUES));
+- hInvFilt->prevInvfMode[i] = INVF_OFF;
+- hInvFilt->prevRegionOrig[i] = 0;
+- hInvFilt->prevRegionSbr[i] = 0;
+- }
+-
+- /*
+- Reset the inverse fltering detector.
+- */
+- FDKsbrEnc_resetInvFiltDetector(hInvFilt, freqBandTableDetector,
+- hInvFilt->noDetectorBandsMax);
+-
+- return (0);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief resets sbr inverse filtering structure.
+-
+-
+-
+- \return errorCode, noError if successful.
+-
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_resetInvFiltDetector(
+- HANDLE_SBR_INV_FILT_EST
+- hInvFilt, /*!< Handle to the SBR_INV_FILT_EST struct. */
+- INT *freqBandTableDetector, /*!< Frequency band table for the inverse
+- filtering. */
+- INT numDetectorBands) /*!< Number of inverse filtering bands. */
+-{
+- hInvFilt->numberOfStrongest = 1;
+- FDKmemcpy(hInvFilt->freqBandTableInvFilt, freqBandTableDetector,
+- (numDetectorBands + 1) * sizeof(INT));
+- hInvFilt->noDetectorBands = numDetectorBands;
+-
+- return (0);
+-}
+diff --git a/libSBRenc/src/invf_est.h b/libSBRenc/src/invf_est.h
+deleted file mode 100644
+index 3ab6726..0000000
+--- a/libSBRenc/src/invf_est.h
++++ /dev/null
+@@ -1,181 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Inverse Filtering detection prototypes $Revision: 92790 $
+-*/
+-#ifndef INVF_EST_H
+-#define INVF_EST_H
+-
+-#include "sbr_encoder.h"
+-#include "sbr_def.h"
+-
+-#define INVF_SMOOTHING_LENGTH 2
+-
+-typedef struct {
+- const FIXP_DBL *quantStepsSbr;
+- const FIXP_DBL *quantStepsOrig;
+- const FIXP_DBL *nrgBorders;
+- INT numRegionsSbr;
+- INT numRegionsOrig;
+- INT numRegionsNrg;
+- INVF_MODE regionSpace[5][5];
+- INVF_MODE regionSpaceTransient[5][5];
+- INT EnergyCompFactor[5];
+-
+-} DETECTOR_PARAMETERS;
+-
+-typedef struct {
+- FIXP_DBL origQuotaMean[INVF_SMOOTHING_LENGTH + 1];
+- FIXP_DBL sbrQuotaMean[INVF_SMOOTHING_LENGTH + 1];
+- FIXP_DBL origQuotaMeanStrongest[INVF_SMOOTHING_LENGTH + 1];
+- FIXP_DBL sbrQuotaMeanStrongest[INVF_SMOOTHING_LENGTH + 1];
+-
+- FIXP_DBL origQuotaMeanFilt;
+- FIXP_DBL sbrQuotaMeanFilt;
+- FIXP_DBL origQuotaMeanStrongestFilt;
+- FIXP_DBL sbrQuotaMeanStrongestFilt;
+-
+- FIXP_DBL origQuotaMax;
+- FIXP_DBL sbrQuotaMax;
+-
+- FIXP_DBL avgNrg;
+-} DETECTOR_VALUES;
+-
+-typedef struct {
+- INT numberOfStrongest;
+-
+- INT prevRegionSbr[MAX_NUM_NOISE_VALUES];
+- INT prevRegionOrig[MAX_NUM_NOISE_VALUES];
+-
+- INT freqBandTableInvFilt[MAX_NUM_NOISE_VALUES];
+- INT noDetectorBands;
+- INT noDetectorBandsMax;
+-
+- const DETECTOR_PARAMETERS *detectorParams;
+-
+- INVF_MODE prevInvfMode[MAX_NUM_NOISE_VALUES];
+- DETECTOR_VALUES detectorValues[MAX_NUM_NOISE_VALUES];
+-
+- FIXP_DBL nrgAvg;
+- FIXP_DBL wmQmf[MAX_NUM_NOISE_VALUES];
+-} SBR_INV_FILT_EST;
+-
+-typedef SBR_INV_FILT_EST *HANDLE_SBR_INV_FILT_EST;
+-
+-void FDKsbrEnc_qmfInverseFilteringDetector(HANDLE_SBR_INV_FILT_EST hInvFilt,
+- FIXP_DBL **quotaMatrix,
+- FIXP_DBL *nrgVector,
+- SCHAR *indexVector, INT startIndex,
+- INT stopIndex, INT transientFlag,
+- INVF_MODE *infVec);
+-
+-INT FDKsbrEnc_initInvFiltDetector(HANDLE_SBR_INV_FILT_EST hInvFilt,
+- INT *freqBandTableDetector,
+- INT numDetectorBands, UINT useSpeechConfig);
+-
+-INT FDKsbrEnc_resetInvFiltDetector(HANDLE_SBR_INV_FILT_EST hInvFilt,
+- INT *freqBandTableDetector,
+- INT numDetectorBands);
+-
+-#endif /* _QMF_INV_FILT_H */
+diff --git a/libSBRenc/src/mh_det.cpp b/libSBRenc/src/mh_det.cpp
+deleted file mode 100644
+index 2f3b386..0000000
+--- a/libSBRenc/src/mh_det.cpp
++++ /dev/null
+@@ -1,1396 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "mh_det.h"
+-
+-#include "sbrenc_ram.h"
+-#include "sbr_misc.h"
+-
+-#include "genericStds.h"
+-
+-#define SFM_SHIFT 2 /* Attention: SFM_SCALE depends on SFM_SHIFT */
+-#define SFM_SCALE (MAXVAL_DBL >> SFM_SHIFT) /* 1.0 >> SFM_SHIFT */
+-
+-/*!< Detector Parameters for AAC core codec. */
+-static const DETECTOR_PARAMETERS_MH paramsAac = {
+- 9, /*!< deltaTime */
+- {
+- FL2FXCONST_DBL(20.0f * RELAXATION_FLOAT), /*!< thresHoldDiff */
+- FL2FXCONST_DBL(1.26f * RELAXATION_FLOAT), /*!< thresHoldDiffGuide */
+- FL2FXCONST_DBL(15.0f * RELAXATION_FLOAT), /*!< thresHoldTone */
+- FL2FXCONST_DBL((1.0f / 15.0f) *
+- RELAXATION_FLOAT), /*!< invThresHoldTone */
+- FL2FXCONST_DBL(1.26f * RELAXATION_FLOAT), /*!< thresHoldToneGuide */
+- FL2FXCONST_DBL(0.3f) >> SFM_SHIFT, /*!< sfmThresSbr */
+- FL2FXCONST_DBL(0.1f) >> SFM_SHIFT, /*!< sfmThresOrig */
+- FL2FXCONST_DBL(0.3f), /*!< decayGuideOrig */
+- FL2FXCONST_DBL(0.5f), /*!< decayGuideDiff */
+- FL2FXCONST_DBL(-0.000112993269),
+- /* LD64(FL2FXCONST_DBL(0.995f)) */ /*!< derivThresMaxLD64 */
+- FL2FXCONST_DBL(-0.000112993269),
+- /* LD64(FL2FXCONST_DBL(0.995f)) */ /*!< derivThresBelowLD64 */
+- FL2FXCONST_DBL(
+- -0.005030126483f) /* LD64(FL2FXCONST_DBL(0.8f)) */ /*!<
+- derivThresAboveLD64
+- */
+- },
+- 50 /*!< maxComp */
+-};
+-
+-/*!< Detector Parameters for AAC LD core codec. */
+-static const DETECTOR_PARAMETERS_MH paramsAacLd = {
+- 16, /*!< Delta time. */
+- {
+- FL2FXCONST_DBL(25.0f * RELAXATION_FLOAT), /*!< thresHoldDiff */
+- FL2FXCONST_DBL(1.26f * RELAXATION_FLOAT), /*!< tresHoldDiffGuide */
+- FL2FXCONST_DBL(15.0f * RELAXATION_FLOAT), /*!< thresHoldTone */
+- FL2FXCONST_DBL((1.0f / 15.0f) *
+- RELAXATION_FLOAT), /*!< invThresHoldTone */
+- FL2FXCONST_DBL(1.26f * RELAXATION_FLOAT), /*!< thresHoldToneGuide */
+- FL2FXCONST_DBL(0.3f) >> SFM_SHIFT, /*!< sfmThresSbr */
+- FL2FXCONST_DBL(0.1f) >> SFM_SHIFT, /*!< sfmThresOrig */
+- FL2FXCONST_DBL(0.3f), /*!< decayGuideOrig */
+- FL2FXCONST_DBL(0.2f), /*!< decayGuideDiff */
+- FL2FXCONST_DBL(-0.000112993269),
+- /* LD64(FL2FXCONST_DBL(0.995f)) */ /*!< derivThresMaxLD64 */
+- FL2FXCONST_DBL(-0.000112993269),
+- /* LD64(FL2FXCONST_DBL(0.995f)) */ /*!< derivThresBelowLD64 */
+- FL2FXCONST_DBL(
+- -0.005030126483f) /* LD64(FL2FXCONST_DBL(0.8f)) */ /*!<
+- derivThresAboveLD64
+- */
+- },
+- 50 /*!< maxComp */
+-};
+-
+-/**************************************************************************/
+-/*!
+- \brief Calculates the difference in tonality between original and SBR
+- for a given time and frequency region.
+-
+- The values for pDiffMapped2Scfb are scaled by RELAXATION
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-static void diff(FIXP_DBL *RESTRICT pTonalityOrig, FIXP_DBL *pDiffMapped2Scfb,
+- const UCHAR *RESTRICT pFreqBandTable, INT nScfb,
+- SCHAR *indexVector) {
+- UCHAR i, ll, lu, k;
+- FIXP_DBL maxValOrig, maxValSbr, tmp;
+- INT scale;
+-
+- for (i = 0; i < nScfb; i++) {
+- ll = pFreqBandTable[i];
+- lu = pFreqBandTable[i + 1];
+-
+- maxValOrig = FL2FXCONST_DBL(0.0f);
+- maxValSbr = FL2FXCONST_DBL(0.0f);
+-
+- for (k = ll; k < lu; k++) {
+- maxValOrig = fixMax(maxValOrig, pTonalityOrig[k]);
+- maxValSbr = fixMax(maxValSbr, pTonalityOrig[indexVector[k]]);
+- }
+-
+- if ((maxValSbr >= RELAXATION)) {
+- tmp = fDivNorm(maxValOrig, maxValSbr, &scale);
+- pDiffMapped2Scfb[i] =
+- scaleValue(fMult(tmp, RELAXATION_FRACT),
+- fixMax(-(DFRACT_BITS - 1), (scale - RELAXATION_SHIFT)));
+- } else {
+- pDiffMapped2Scfb[i] = maxValOrig;
+- }
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Calculates a flatness measure of the tonality measures.
+-
+- Calculation of the power function and using scalefactor for basis:
+- Using log2:
+- z = (2^k * x)^y;
+- z' = CalcLd(z) = y*CalcLd(x) + y*k;
+- z = CalcInvLd(z');
+-
+- Using ld64:
+- z = (2^k * x)^y;
+- z' = CalcLd64(z) = y*CalcLd64(x)/64 + y*k/64;
+- z = CalcInvLd64(z');
+-
+- The values pSfmOrigVec and pSfmSbrVec are scaled by the factor 1/4.0
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-static void calculateFlatnessMeasure(FIXP_DBL *pQuotaBuffer, SCHAR *indexVector,
+- FIXP_DBL *pSfmOrigVec,
+- FIXP_DBL *pSfmSbrVec,
+- const UCHAR *pFreqBandTable, INT nSfb) {
+- INT i, j;
+- FIXP_DBL invBands, tmp1, tmp2;
+- INT shiftFac0, shiftFacSum0;
+- INT shiftFac1, shiftFacSum1;
+- FIXP_DBL accu;
+-
+- for (i = 0; i < nSfb; i++) {
+- INT ll = pFreqBandTable[i];
+- INT lu = pFreqBandTable[i + 1];
+- pSfmOrigVec[i] = (FIXP_DBL)(MAXVAL_DBL >> 2);
+- pSfmSbrVec[i] = (FIXP_DBL)(MAXVAL_DBL >> 2);
+-
+- if (lu - ll > 1) {
+- FIXP_DBL amOrig, amTransp, gmOrig, gmTransp, sfmOrig, sfmTransp;
+- invBands = GetInvInt(lu - ll);
+- shiftFacSum0 = 0;
+- shiftFacSum1 = 0;
+- amOrig = amTransp = FL2FXCONST_DBL(0.0f);
+- gmOrig = gmTransp = (FIXP_DBL)MAXVAL_DBL;
+-
+- for (j = ll; j < lu; j++) {
+- sfmOrig = pQuotaBuffer[j];
+- sfmTransp = pQuotaBuffer[indexVector[j]];
+-
+- amOrig += fMult(sfmOrig, invBands);
+- amTransp += fMult(sfmTransp, invBands);
+-
+- shiftFac0 = CountLeadingBits(sfmOrig);
+- shiftFac1 = CountLeadingBits(sfmTransp);
+-
+- gmOrig = fMult(gmOrig, sfmOrig << shiftFac0);
+- gmTransp = fMult(gmTransp, sfmTransp << shiftFac1);
+-
+- shiftFacSum0 += shiftFac0;
+- shiftFacSum1 += shiftFac1;
+- }
+-
+- if (gmOrig > FL2FXCONST_DBL(0.0f)) {
+- tmp1 = CalcLdData(gmOrig); /* CalcLd64(x)/64 */
+- tmp1 = fMult(invBands, tmp1); /* y*CalcLd64(x)/64 */
+-
+- /* y*k/64 */
+- accu = (FIXP_DBL)-shiftFacSum0 << (DFRACT_BITS - 1 - 8);
+- tmp2 = fMultDiv2(invBands, accu) << (2 + 1);
+-
+- tmp2 = tmp1 + tmp2; /* y*CalcLd64(x)/64 + y*k/64 */
+- gmOrig = CalcInvLdData(tmp2); /* CalcInvLd64(z'); */
+- } else {
+- gmOrig = FL2FXCONST_DBL(0.0f);
+- }
+-
+- if (gmTransp > FL2FXCONST_DBL(0.0f)) {
+- tmp1 = CalcLdData(gmTransp); /* CalcLd64(x)/64 */
+- tmp1 = fMult(invBands, tmp1); /* y*CalcLd64(x)/64 */
+-
+- /* y*k/64 */
+- accu = (FIXP_DBL)-shiftFacSum1 << (DFRACT_BITS - 1 - 8);
+- tmp2 = fMultDiv2(invBands, accu) << (2 + 1);
+-
+- tmp2 = tmp1 + tmp2; /* y*CalcLd64(x)/64 + y*k/64 */
+- gmTransp = CalcInvLdData(tmp2); /* CalcInvLd64(z'); */
+- } else {
+- gmTransp = FL2FXCONST_DBL(0.0f);
+- }
+- if (amOrig != FL2FXCONST_DBL(0.0f))
+- pSfmOrigVec[i] =
+- FDKsbrEnc_LSI_divide_scale_fract(gmOrig, amOrig, SFM_SCALE);
+-
+- if (amTransp != FL2FXCONST_DBL(0.0f))
+- pSfmSbrVec[i] =
+- FDKsbrEnc_LSI_divide_scale_fract(gmTransp, amTransp, SFM_SCALE);
+- }
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Calculates the input to the missing harmonics detection.
+-
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-static void calculateDetectorInput(
+- FIXP_DBL **RESTRICT pQuotaBuffer, /*!< Pointer to tonality matrix. */
+- SCHAR *RESTRICT indexVector, FIXP_DBL **RESTRICT tonalityDiff,
+- FIXP_DBL **RESTRICT pSfmOrig, FIXP_DBL **RESTRICT pSfmSbr,
+- const UCHAR *freqBandTable, INT nSfb, INT noEstPerFrame, INT move) {
+- INT est;
+-
+- /*
+- New estimate.
+- */
+- for (est = 0; est < noEstPerFrame; est++) {
+- diff(pQuotaBuffer[est + move], tonalityDiff[est + move], freqBandTable,
+- nSfb, indexVector);
+-
+- calculateFlatnessMeasure(pQuotaBuffer[est + move], indexVector,
+- pSfmOrig[est + move], pSfmSbr[est + move],
+- freqBandTable, nSfb);
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Checks that the detection is not due to a LP filter
+-
+- This function determines if a newly detected missing harmonics is not
+- in fact just a low-pass filtere input signal. If so, the detection is
+- removed.
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-static void removeLowPassDetection(UCHAR *RESTRICT pAddHarmSfb,
+- UCHAR **RESTRICT pDetectionVectors,
+- INT start, INT stop, INT nSfb,
+- const UCHAR *RESTRICT pFreqBandTable,
+- FIXP_DBL *RESTRICT pNrgVector,
+- THRES_HOLDS mhThresh)
+-
+-{
+- INT i, est;
+- INT maxDerivPos = pFreqBandTable[nSfb];
+- INT numBands = pFreqBandTable[nSfb];
+- FIXP_DBL nrgLow, nrgHigh;
+- FIXP_DBL nrgLD64, nrgLowLD64, nrgHighLD64, nrgDiffLD64;
+- FIXP_DBL valLD64, maxValLD64, maxValAboveLD64;
+- INT bLPsignal = 0;
+-
+- maxValLD64 = FL2FXCONST_DBL(-1.0f);
+- for (i = numBands - 1 - 2; i > pFreqBandTable[0]; i--) {
+- nrgLow = pNrgVector[i];
+- nrgHigh = pNrgVector[i + 2];
+-
+- if (nrgLow != FL2FXCONST_DBL(0.0f) && nrgLow > nrgHigh) {
+- nrgLowLD64 = CalcLdData(nrgLow >> 1);
+- nrgDiffLD64 = CalcLdData((nrgLow >> 1) - (nrgHigh >> 1));
+- valLD64 = nrgDiffLD64 - nrgLowLD64;
+- if (valLD64 > maxValLD64) {
+- maxDerivPos = i;
+- maxValLD64 = valLD64;
+- }
+- if (maxValLD64 > mhThresh.derivThresMaxLD64) {
+- break;
+- }
+- }
+- }
+-
+- /* Find the largest "gradient" above. (should be relatively flat, hence we
+- expect a low value if the signal is LP.*/
+- maxValAboveLD64 = FL2FXCONST_DBL(-1.0f);
+- for (i = numBands - 1 - 2; i > maxDerivPos + 2; i--) {
+- nrgLow = pNrgVector[i];
+- nrgHigh = pNrgVector[i + 2];
+-
+- if (nrgLow != FL2FXCONST_DBL(0.0f) && nrgLow > nrgHigh) {
+- nrgLowLD64 = CalcLdData(nrgLow >> 1);
+- nrgDiffLD64 = CalcLdData((nrgLow >> 1) - (nrgHigh >> 1));
+- valLD64 = nrgDiffLD64 - nrgLowLD64;
+- if (valLD64 > maxValAboveLD64) {
+- maxValAboveLD64 = valLD64;
+- }
+- } else {
+- if (nrgHigh != FL2FXCONST_DBL(0.0f) && nrgHigh > nrgLow) {
+- nrgHighLD64 = CalcLdData(nrgHigh >> 1);
+- nrgDiffLD64 = CalcLdData((nrgHigh >> 1) - (nrgLow >> 1));
+- valLD64 = nrgDiffLD64 - nrgHighLD64;
+- if (valLD64 > maxValAboveLD64) {
+- maxValAboveLD64 = valLD64;
+- }
+- }
+- }
+- }
+-
+- if (maxValLD64 > mhThresh.derivThresMaxLD64 &&
+- maxValAboveLD64 < mhThresh.derivThresAboveLD64) {
+- bLPsignal = 1;
+-
+- for (i = maxDerivPos - 1; i > maxDerivPos - 5 && i >= 0; i--) {
+- if (pNrgVector[i] != FL2FXCONST_DBL(0.0f) &&
+- pNrgVector[i] > pNrgVector[maxDerivPos + 2]) {
+- nrgDiffLD64 = CalcLdData((pNrgVector[i] >> 1) -
+- (pNrgVector[maxDerivPos + 2] >> 1));
+- nrgLD64 = CalcLdData(pNrgVector[i] >> 1);
+- valLD64 = nrgDiffLD64 - nrgLD64;
+- if (valLD64 < mhThresh.derivThresBelowLD64) {
+- bLPsignal = 0;
+- break;
+- }
+- } else {
+- bLPsignal = 0;
+- break;
+- }
+- }
+- }
+-
+- if (bLPsignal) {
+- for (i = 0; i < nSfb; i++) {
+- if (maxDerivPos >= pFreqBandTable[i] &&
+- maxDerivPos < pFreqBandTable[i + 1])
+- break;
+- }
+-
+- if (pAddHarmSfb[i]) {
+- pAddHarmSfb[i] = 0;
+- for (est = start; est < stop; est++) {
+- pDetectionVectors[est][i] = 0;
+- }
+- }
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Checks if it is allowed to detect a missing tone, that wasn't
+- detected previously.
+-
+-
+- \return newDetectionAllowed flag.
+-
+-*/
+-/**************************************************************************/
+-static INT isDetectionOfNewToneAllowed(
+- const SBR_FRAME_INFO *pFrameInfo, INT *pDetectionStartPos,
+- INT noEstPerFrame, INT prevTransientFrame, INT prevTransientPos,
+- INT prevTransientFlag, INT transientPosOffset, INT transientFlag,
+- INT transientPos, INT deltaTime,
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR h_sbrMissingHarmonicsDetector) {
+- INT transientFrame, newDetectionAllowed;
+-
+- /* Determine if this is a frame where a transient starts...
+- * If the transient flag was set the previous frame but not the
+- * transient frame flag, the transient frame flag is set in the current frame.
+- *****************************************************************************/
+- transientFrame = 0;
+- if (transientFlag) {
+- if (transientPos + transientPosOffset <
+- pFrameInfo->borders[pFrameInfo->nEnvelopes]) {
+- transientFrame = 1;
+- if (noEstPerFrame > 1) {
+- if (transientPos + transientPosOffset >
+- h_sbrMissingHarmonicsDetector->timeSlots >> 1) {
+- *pDetectionStartPos = noEstPerFrame;
+- } else {
+- *pDetectionStartPos = noEstPerFrame >> 1;
+- }
+-
+- } else {
+- *pDetectionStartPos = noEstPerFrame;
+- }
+- }
+- } else {
+- if (prevTransientFlag && !prevTransientFrame) {
+- transientFrame = 1;
+- *pDetectionStartPos = 0;
+- }
+- }
+-
+- /*
+- * Determine if detection of new missing harmonics are allowed.
+- * If the frame contains a transient it's ok. If the previous
+- * frame contained a transient it needs to be sufficiently close
+- * to the start of the current frame.
+- ****************************************************************/
+- newDetectionAllowed = 0;
+- if (transientFrame) {
+- newDetectionAllowed = 1;
+- } else {
+- if (prevTransientFrame &&
+- fixp_abs(pFrameInfo->borders[0] -
+- (prevTransientPos + transientPosOffset -
+- h_sbrMissingHarmonicsDetector->timeSlots)) < deltaTime) {
+- newDetectionAllowed = 1;
+- *pDetectionStartPos = 0;
+- }
+- }
+-
+- h_sbrMissingHarmonicsDetector->previousTransientFlag = transientFlag;
+- h_sbrMissingHarmonicsDetector->previousTransientFrame = transientFrame;
+- h_sbrMissingHarmonicsDetector->previousTransientPos = transientPos;
+-
+- return (newDetectionAllowed);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Cleans up the detection after a transient.
+-
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-static void transientCleanUp(FIXP_DBL **quotaBuffer, INT nSfb,
+- UCHAR **detectionVectors, UCHAR *pAddHarmSfb,
+- UCHAR *pPrevAddHarmSfb, INT **signBuffer,
+- const UCHAR *pFreqBandTable, INT start, INT stop,
+- INT newDetectionAllowed, FIXP_DBL *pNrgVector,
+- THRES_HOLDS mhThresh) {
+- INT i, j, est;
+-
+- for (est = start; est < stop; est++) {
+- for (i = 0; i < nSfb; i++) {
+- pAddHarmSfb[i] = pAddHarmSfb[i] || detectionVectors[est][i];
+- }
+- }
+-
+- if (newDetectionAllowed == 1) {
+- /*
+- * Check for duplication of sines located
+- * on the border of two scf-bands.
+- *************************************************/
+- for (i = 0; i < nSfb - 1; i++) {
+- /* detection in adjacent channels.*/
+- if (pAddHarmSfb[i] && pAddHarmSfb[i + 1]) {
+- FIXP_DBL maxVal1, maxVal2;
+- INT maxPos1, maxPos2, maxPosTime1, maxPosTime2;
+-
+- INT li = pFreqBandTable[i];
+- INT ui = pFreqBandTable[i + 1];
+-
+- /* Find maximum tonality in the the two scf bands.*/
+- maxPosTime1 = start;
+- maxPos1 = li;
+- maxVal1 = quotaBuffer[start][li];
+- for (est = start; est < stop; est++) {
+- for (j = li; j < ui; j++) {
+- if (quotaBuffer[est][j] > maxVal1) {
+- maxVal1 = quotaBuffer[est][j];
+- maxPos1 = j;
+- maxPosTime1 = est;
+- }
+- }
+- }
+-
+- li = pFreqBandTable[i + 1];
+- ui = pFreqBandTable[i + 2];
+-
+- /* Find maximum tonality in the the two scf bands.*/
+- maxPosTime2 = start;
+- maxPos2 = li;
+- maxVal2 = quotaBuffer[start][li];
+- for (est = start; est < stop; est++) {
+- for (j = li; j < ui; j++) {
+- if (quotaBuffer[est][j] > maxVal2) {
+- maxVal2 = quotaBuffer[est][j];
+- maxPos2 = j;
+- maxPosTime2 = est;
+- }
+- }
+- }
+-
+- /* If the maximum values are in adjacent QMF-channels, we need to remove
+- the lowest of the two.*/
+- if (maxPos2 - maxPos1 < 2) {
+- if (pPrevAddHarmSfb[i] == 1 && pPrevAddHarmSfb[i + 1] == 0) {
+- /* Keep the lower, remove the upper.*/
+- pAddHarmSfb[i + 1] = 0;
+- for (est = start; est < stop; est++) {
+- detectionVectors[est][i + 1] = 0;
+- }
+- } else {
+- if (pPrevAddHarmSfb[i] == 0 && pPrevAddHarmSfb[i + 1] == 1) {
+- /* Keep the upper, remove the lower.*/
+- pAddHarmSfb[i] = 0;
+- for (est = start; est < stop; est++) {
+- detectionVectors[est][i] = 0;
+- }
+- } else {
+- /* If the maximum values are in adjacent QMF-channels, and if the
+- signs indicate that it is the same sine, we need to remove the
+- lowest of the two.*/
+- if (maxVal1 > maxVal2) {
+- if (signBuffer[maxPosTime1][maxPos2] < 0 &&
+- signBuffer[maxPosTime1][maxPos1] > 0) {
+- /* Keep the lower, remove the upper.*/
+- pAddHarmSfb[i + 1] = 0;
+- for (est = start; est < stop; est++) {
+- detectionVectors[est][i + 1] = 0;
+- }
+- }
+- } else {
+- if (signBuffer[maxPosTime2][maxPos2] < 0 &&
+- signBuffer[maxPosTime2][maxPos1] > 0) {
+- /* Keep the upper, remove the lower.*/
+- pAddHarmSfb[i] = 0;
+- for (est = start; est < stop; est++) {
+- detectionVectors[est][i] = 0;
+- }
+- }
+- }
+- }
+- }
+- }
+- }
+- }
+-
+- /* Make sure that the detection is not the cut-off of a low pass filter. */
+- removeLowPassDetection(pAddHarmSfb, detectionVectors, start, stop, nSfb,
+- pFreqBandTable, pNrgVector, mhThresh);
+- } else {
+- /*
+- * If a missing harmonic wasn't missing the previous frame
+- * the transient-flag needs to be set in order to be allowed to detect it.
+- *************************************************************************/
+- for (i = 0; i < nSfb; i++) {
+- if (pAddHarmSfb[i] - pPrevAddHarmSfb[i] > 0) pAddHarmSfb[i] = 0;
+- }
+- }
+-}
+-
+-/*****************************************************************************/
+-/*!
+- \brief Detection for one tonality estimate.
+-
+- This is the actual missing harmonics detection, using information from the
+- previous detection.
+-
+- If a missing harmonic was detected (in a previous frame) due to too high
+- tonality differences, but there was not enough tonality difference in the
+- current frame, the detection algorithm still continues to trace the strongest
+- tone in the scalefactor band (assuming that this is the tone that is going to
+- be replaced in the decoder). This is done to avoid abrupt endings of sines
+- fading out (e.g. in the glockenspiel).
+-
+- The function also tries to estimate where one sine is going to be replaced
+- with multiple sines (due to the patching). This is done by comparing the
+- tonality flatness measure of the original and the SBR signal.
+-
+- The function also tries to estimate (for the scalefactor bands only
+- containing one qmf subband) when a strong tone in the original will be
+- replaced by a strong tone in the adjacent QMF subband.
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-static void detection(FIXP_DBL *quotaBuffer, FIXP_DBL *pDiffVecScfb, INT nSfb,
+- UCHAR *pHarmVec, const UCHAR *pFreqBandTable,
+- FIXP_DBL *sfmOrig, FIXP_DBL *sfmSbr,
+- GUIDE_VECTORS guideVectors, GUIDE_VECTORS newGuideVectors,
+- THRES_HOLDS mhThresh) {
+- INT i, j, ll, lu;
+- FIXP_DBL thresTemp, thresOrig;
+-
+- /*
+- * Do detection on the difference vector, i.e. the difference between
+- * the original and the transposed.
+- *********************************************************************/
+- for (i = 0; i < nSfb; i++) {
+- thresTemp = (guideVectors.guideVectorDiff[i] != FL2FXCONST_DBL(0.0f))
+- ? fMax(fMult(mhThresh.decayGuideDiff,
+- guideVectors.guideVectorDiff[i]),
+- mhThresh.thresHoldDiffGuide)
+- : mhThresh.thresHoldDiff;
+-
+- thresTemp = fMin(thresTemp, mhThresh.thresHoldDiff);
+-
+- if (pDiffVecScfb[i] > thresTemp) {
+- pHarmVec[i] = 1;
+- newGuideVectors.guideVectorDiff[i] = pDiffVecScfb[i];
+- } else {
+- /* If the guide wasn't zero, but the current level is to low,
+- start tracking the decay on the tone in the original rather
+- than the difference.*/
+- if (guideVectors.guideVectorDiff[i] != FL2FXCONST_DBL(0.0f)) {
+- guideVectors.guideVectorOrig[i] = mhThresh.thresHoldToneGuide;
+- }
+- }
+- }
+-
+- /*
+- * Trace tones in the original signal that at one point
+- * have been detected because they will be replaced by
+- * multiple tones in the sbr signal.
+- ****************************************************/
+-
+- for (i = 0; i < nSfb; i++) {
+- ll = pFreqBandTable[i];
+- lu = pFreqBandTable[i + 1];
+-
+- thresOrig =
+- fixMax(fMult(guideVectors.guideVectorOrig[i], mhThresh.decayGuideOrig),
+- mhThresh.thresHoldToneGuide);
+- thresOrig = fixMin(thresOrig, mhThresh.thresHoldTone);
+-
+- if (guideVectors.guideVectorOrig[i] != FL2FXCONST_DBL(0.0f)) {
+- for (j = ll; j < lu; j++) {
+- if (quotaBuffer[j] > thresOrig) {
+- pHarmVec[i] = 1;
+- newGuideVectors.guideVectorOrig[i] = quotaBuffer[j];
+- }
+- }
+- }
+- }
+-
+- /*
+- * Check for multiple sines in the transposed signal,
+- * where there is only one in the original.
+- ****************************************************/
+- thresOrig = mhThresh.thresHoldTone;
+-
+- for (i = 0; i < nSfb; i++) {
+- ll = pFreqBandTable[i];
+- lu = pFreqBandTable[i + 1];
+-
+- if (pHarmVec[i] == 0) {
+- if (lu - ll > 1) {
+- for (j = ll; j < lu; j++) {
+- if (quotaBuffer[j] > thresOrig &&
+- (sfmSbr[i] > mhThresh.sfmThresSbr &&
+- sfmOrig[i] < mhThresh.sfmThresOrig)) {
+- pHarmVec[i] = 1;
+- newGuideVectors.guideVectorOrig[i] = quotaBuffer[j];
+- }
+- }
+- } else {
+- if (i < nSfb - 1) {
+- ll = pFreqBandTable[i];
+-
+- if (i > 0) {
+- if (quotaBuffer[ll] > mhThresh.thresHoldTone &&
+- (pDiffVecScfb[i + 1] < mhThresh.invThresHoldTone ||
+- pDiffVecScfb[i - 1] < mhThresh.invThresHoldTone)) {
+- pHarmVec[i] = 1;
+- newGuideVectors.guideVectorOrig[i] = quotaBuffer[ll];
+- }
+- } else {
+- if (quotaBuffer[ll] > mhThresh.thresHoldTone &&
+- pDiffVecScfb[i + 1] < mhThresh.invThresHoldTone) {
+- pHarmVec[i] = 1;
+- newGuideVectors.guideVectorOrig[i] = quotaBuffer[ll];
+- }
+- }
+- }
+- }
+- }
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Do detection for every tonality estimate, using forward prediction.
+-
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-static void detectionWithPrediction(
+- FIXP_DBL **quotaBuffer, FIXP_DBL **pDiffVecScfb, INT **signBuffer, INT nSfb,
+- const UCHAR *pFreqBandTable, FIXP_DBL **sfmOrig, FIXP_DBL **sfmSbr,
+- UCHAR **detectionVectors, UCHAR *pPrevAddHarmSfb,
+- GUIDE_VECTORS *guideVectors, INT noEstPerFrame, INT detectionStart,
+- INT totNoEst, INT newDetectionAllowed, INT *pAddHarmFlag,
+- UCHAR *pAddHarmSfb, FIXP_DBL *pNrgVector,
+- const DETECTOR_PARAMETERS_MH *mhParams) {
+- INT est = 0, i;
+- INT start;
+-
+- FDKmemclear(pAddHarmSfb, nSfb * sizeof(UCHAR));
+-
+- if (newDetectionAllowed) {
+- /* Since we don't want to use the transient region for detection (since the
+- tonality values tend to be a bit unreliable for this region) the
+- guide-values are copied to the current starting point. */
+- if (totNoEst > 1) {
+- start = detectionStart + 1;
+-
+- if (start != 0) {
+- FDKmemcpy(guideVectors[start].guideVectorDiff,
+- guideVectors[0].guideVectorDiff, nSfb * sizeof(FIXP_DBL));
+- FDKmemcpy(guideVectors[start].guideVectorOrig,
+- guideVectors[0].guideVectorOrig, nSfb * sizeof(FIXP_DBL));
+- FDKmemclear(guideVectors[start - 1].guideVectorDetected,
+- nSfb * sizeof(UCHAR));
+- }
+- } else {
+- start = 0;
+- }
+- } else {
+- start = 0;
+- }
+-
+- for (est = start; est < totNoEst; est++) {
+- /*
+- * Do detection on the current frame using
+- * guide-info from the previous.
+- *******************************************/
+- if (est > 0) {
+- FDKmemcpy(guideVectors[est].guideVectorDetected,
+- detectionVectors[est - 1], nSfb * sizeof(UCHAR));
+- }
+-
+- FDKmemclear(detectionVectors[est], nSfb * sizeof(UCHAR));
+-
+- if (est < totNoEst - 1) {
+- FDKmemclear(guideVectors[est + 1].guideVectorDiff,
+- nSfb * sizeof(FIXP_DBL));
+- FDKmemclear(guideVectors[est + 1].guideVectorOrig,
+- nSfb * sizeof(FIXP_DBL));
+- FDKmemclear(guideVectors[est + 1].guideVectorDetected,
+- nSfb * sizeof(UCHAR));
+-
+- detection(quotaBuffer[est], pDiffVecScfb[est], nSfb,
+- detectionVectors[est], pFreqBandTable, sfmOrig[est],
+- sfmSbr[est], guideVectors[est], guideVectors[est + 1],
+- mhParams->thresHolds);
+- } else {
+- FDKmemclear(guideVectors[est].guideVectorDiff, nSfb * sizeof(FIXP_DBL));
+- FDKmemclear(guideVectors[est].guideVectorOrig, nSfb * sizeof(FIXP_DBL));
+- FDKmemclear(guideVectors[est].guideVectorDetected, nSfb * sizeof(UCHAR));
+-
+- detection(quotaBuffer[est], pDiffVecScfb[est], nSfb,
+- detectionVectors[est], pFreqBandTable, sfmOrig[est],
+- sfmSbr[est], guideVectors[est], guideVectors[est],
+- mhParams->thresHolds);
+- }
+- }
+-
+- /* Clean up the detection.*/
+- transientCleanUp(quotaBuffer, nSfb, detectionVectors, pAddHarmSfb,
+- pPrevAddHarmSfb, signBuffer, pFreqBandTable, start, totNoEst,
+- newDetectionAllowed, pNrgVector, mhParams->thresHolds);
+-
+- /* Set flag... */
+- *pAddHarmFlag = 0;
+- for (i = 0; i < nSfb; i++) {
+- if (pAddHarmSfb[i]) {
+- *pAddHarmFlag = 1;
+- break;
+- }
+- }
+-
+- FDKmemcpy(pPrevAddHarmSfb, pAddHarmSfb, nSfb * sizeof(UCHAR));
+- FDKmemcpy(guideVectors[0].guideVectorDetected, pAddHarmSfb,
+- nSfb * sizeof(INT));
+-
+- for (i = 0; i < nSfb; i++) {
+- guideVectors[0].guideVectorDiff[i] = FL2FXCONST_DBL(0.0f);
+- guideVectors[0].guideVectorOrig[i] = FL2FXCONST_DBL(0.0f);
+-
+- if (pAddHarmSfb[i] == 1) {
+- /* If we had a detection use the guide-value in the next frame from the
+- last estimate were the detection was done.*/
+- for (est = start; est < totNoEst; est++) {
+- if (guideVectors[est].guideVectorDiff[i] != FL2FXCONST_DBL(0.0f)) {
+- guideVectors[0].guideVectorDiff[i] =
+- guideVectors[est].guideVectorDiff[i];
+- }
+- if (guideVectors[est].guideVectorOrig[i] != FL2FXCONST_DBL(0.0f)) {
+- guideVectors[0].guideVectorOrig[i] =
+- guideVectors[est].guideVectorOrig[i];
+- }
+- }
+- }
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Calculates a compensation vector for the energy data.
+-
+- This function calculates a compensation vector for the energy data (i.e.
+- envelope data) that is calculated elsewhere. This is since, one sine on
+- the border of two scalefactor bands, will be replace by one sine in the
+- middle of either scalefactor band. However, since the sine that is replaced
+- will influence the energy estimate in both scalefactor bands (in the envelops
+- calculation function) a compensation value is required in order to avoid
+- noise substitution in the decoder next to the synthetic sine.
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-static void calculateCompVector(UCHAR *pAddHarmSfb, FIXP_DBL **pTonalityMatrix,
+- INT **pSignMatrix, UCHAR *pEnvComp, INT nSfb,
+- const UCHAR *freqBandTable, INT totNoEst,
+- INT maxComp, UCHAR *pPrevEnvComp,
+- INT newDetectionAllowed) {
+- INT scfBand, est, l, ll, lu, maxPosF, maxPosT;
+- FIXP_DBL maxVal;
+- INT compValue;
+- FIXP_DBL tmp;
+-
+- FDKmemclear(pEnvComp, nSfb * sizeof(UCHAR));
+-
+- for (scfBand = 0; scfBand < nSfb; scfBand++) {
+- if (pAddHarmSfb[scfBand]) { /* A missing sine was detected */
+- ll = freqBandTable[scfBand];
+- lu = freqBandTable[scfBand + 1];
+-
+- maxPosF = 0; /* First find the maximum*/
+- maxPosT = 0;
+- maxVal = FL2FXCONST_DBL(0.0f);
+-
+- for (est = 0; est < totNoEst; est++) {
+- for (l = ll; l < lu; l++) {
+- if (pTonalityMatrix[est][l] > maxVal) {
+- maxVal = pTonalityMatrix[est][l];
+- maxPosF = l;
+- maxPosT = est;
+- }
+- }
+- }
+-
+- /*
+- * If the maximum tonality is at the lower border of the
+- * scalefactor band, we check the sign of the adjacent channels
+- * to see if this sine is shared by the lower channel. If so, the
+- * energy of the single sine will be present in two scalefactor bands
+- * in the SBR data, which will cause problems in the decoder, when we
+- * add a sine to just one of the channels.
+- *********************************************************************/
+- if (maxPosF == ll && scfBand) {
+- if (!pAddHarmSfb[scfBand - 1]) { /* No detection below*/
+- if (pSignMatrix[maxPosT][maxPosF - 1] > 0 &&
+- pSignMatrix[maxPosT][maxPosF] < 0) {
+- /* The comp value is calulated as the tonallity value, i.e we want
+- to reduce the envelope data for this channel with as much as the
+- tonality that is spread from the channel above. (ld64(RELAXATION)
+- = 0.31143075889) */
+- tmp = fixp_abs(
+- (FIXP_DBL)CalcLdData(pTonalityMatrix[maxPosT][maxPosF - 1]) +
+- RELAXATION_LD64);
+- tmp = (tmp >> (DFRACT_BITS - 1 - LD_DATA_SHIFT - 1)) +
+- (FIXP_DBL)1; /* shift one bit less for rounding */
+- compValue = ((INT)(LONG)tmp) >> 1;
+-
+- /* limit the comp-value*/
+- if (compValue > maxComp) compValue = maxComp;
+-
+- pEnvComp[scfBand - 1] = compValue;
+- }
+- }
+- }
+-
+- /*
+- * Same as above, but for the upper end of the scalefactor-band.
+- ***************************************************************/
+- if (maxPosF == lu - 1 && scfBand + 1 < nSfb) { /* Upper border*/
+- if (!pAddHarmSfb[scfBand + 1]) {
+- if (pSignMatrix[maxPosT][maxPosF] > 0 &&
+- pSignMatrix[maxPosT][maxPosF + 1] < 0) {
+- tmp = fixp_abs(
+- (FIXP_DBL)CalcLdData(pTonalityMatrix[maxPosT][maxPosF + 1]) +
+- RELAXATION_LD64);
+- tmp = (tmp >> (DFRACT_BITS - 1 - LD_DATA_SHIFT - 1)) +
+- (FIXP_DBL)1; /* shift one bit less for rounding */
+- compValue = ((INT)(LONG)tmp) >> 1;
+-
+- if (compValue > maxComp) compValue = maxComp;
+-
+- pEnvComp[scfBand + 1] = compValue;
+- }
+- }
+- }
+- }
+- }
+-
+- if (newDetectionAllowed == 0) {
+- for (scfBand = 0; scfBand < nSfb; scfBand++) {
+- if (pEnvComp[scfBand] != 0 && pPrevEnvComp[scfBand] == 0)
+- pEnvComp[scfBand] = 0;
+- }
+- }
+-
+- /* remember the value for the next frame.*/
+- FDKmemcpy(pPrevEnvComp, pEnvComp, nSfb * sizeof(UCHAR));
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Detects where strong tonal components will be missing after
+- HFR in the decoder.
+-
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-void FDKsbrEnc_SbrMissingHarmonicsDetectorQmf(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR h_sbrMHDet, FIXP_DBL **pQuotaBuffer,
+- INT **pSignBuffer, SCHAR *indexVector, const SBR_FRAME_INFO *pFrameInfo,
+- const UCHAR *pTranInfo, INT *pAddHarmonicsFlag,
+- UCHAR *pAddHarmonicsScaleFactorBands, const UCHAR *freqBandTable, INT nSfb,
+- UCHAR *envelopeCompensation, FIXP_DBL *pNrgVector) {
+- INT transientFlag = pTranInfo[1];
+- INT transientPos = pTranInfo[0];
+- INT newDetectionAllowed;
+- INT transientDetStart = 0;
+-
+- UCHAR **detectionVectors = h_sbrMHDet->detectionVectors;
+- INT move = h_sbrMHDet->move;
+- INT noEstPerFrame = h_sbrMHDet->noEstPerFrame;
+- INT totNoEst = h_sbrMHDet->totNoEst;
+- INT prevTransientFlag = h_sbrMHDet->previousTransientFlag;
+- INT prevTransientFrame = h_sbrMHDet->previousTransientFrame;
+- INT transientPosOffset = h_sbrMHDet->transientPosOffset;
+- INT prevTransientPos = h_sbrMHDet->previousTransientPos;
+- GUIDE_VECTORS *guideVectors = h_sbrMHDet->guideVectors;
+- INT deltaTime = h_sbrMHDet->mhParams->deltaTime;
+- INT maxComp = h_sbrMHDet->mhParams->maxComp;
+-
+- int est;
+-
+- /*
+- Buffer values.
+- */
+- FDK_ASSERT(move <= (MAX_NO_OF_ESTIMATES >> 1));
+- FDK_ASSERT(noEstPerFrame <= (MAX_NO_OF_ESTIMATES >> 1));
+-
+- FIXP_DBL *sfmSbr[MAX_NO_OF_ESTIMATES];
+- FIXP_DBL *sfmOrig[MAX_NO_OF_ESTIMATES];
+- FIXP_DBL *tonalityDiff[MAX_NO_OF_ESTIMATES];
+-
+- for (est = 0; est < MAX_NO_OF_ESTIMATES / 2; est++) {
+- sfmSbr[est] = h_sbrMHDet->sfmSbr[est];
+- sfmOrig[est] = h_sbrMHDet->sfmOrig[est];
+- tonalityDiff[est] = h_sbrMHDet->tonalityDiff[est];
+- }
+-
+- C_ALLOC_SCRATCH_START(_scratch, FIXP_DBL,
+- 3 * MAX_NO_OF_ESTIMATES / 2 * MAX_FREQ_COEFFS)
+- FIXP_DBL *scratch = _scratch;
+- for (; est < MAX_NO_OF_ESTIMATES; est++) {
+- sfmSbr[est] = scratch;
+- scratch += MAX_FREQ_COEFFS;
+- sfmOrig[est] = scratch;
+- scratch += MAX_FREQ_COEFFS;
+- tonalityDiff[est] = scratch;
+- scratch += MAX_FREQ_COEFFS;
+- }
+-
+- /* Determine if we're allowed to detect "missing harmonics" that wasn't
+- detected before. In order to be allowed to do new detection, there must be
+- a transient in the current frame, or a transient in the previous frame
+- sufficiently close to the current frame. */
+- newDetectionAllowed = isDetectionOfNewToneAllowed(
+- pFrameInfo, &transientDetStart, noEstPerFrame, prevTransientFrame,
+- prevTransientPos, prevTransientFlag, transientPosOffset, transientFlag,
+- transientPos, deltaTime, h_sbrMHDet);
+-
+- /* Calulate the variables that will be used subsequently for the actual
+- * detection */
+- calculateDetectorInput(pQuotaBuffer, indexVector, tonalityDiff, sfmOrig,
+- sfmSbr, freqBandTable, nSfb, noEstPerFrame, move);
+-
+- /* Do the actual detection using information from previous detections */
+- detectionWithPrediction(pQuotaBuffer, tonalityDiff, pSignBuffer, nSfb,
+- freqBandTable, sfmOrig, sfmSbr, detectionVectors,
+- h_sbrMHDet->guideScfb, guideVectors, noEstPerFrame,
+- transientDetStart, totNoEst, newDetectionAllowed,
+- pAddHarmonicsFlag, pAddHarmonicsScaleFactorBands,
+- pNrgVector, h_sbrMHDet->mhParams);
+-
+- /* Calculate the comp vector, so that the energy can be
+- compensated for a sine between two QMF-bands. */
+- calculateCompVector(pAddHarmonicsScaleFactorBands, pQuotaBuffer, pSignBuffer,
+- envelopeCompensation, nSfb, freqBandTable, totNoEst,
+- maxComp, h_sbrMHDet->prevEnvelopeCompensation,
+- newDetectionAllowed);
+-
+- for (est = 0; est < move; est++) {
+- FDKmemcpy(tonalityDiff[est], tonalityDiff[est + noEstPerFrame],
+- sizeof(FIXP_DBL) * MAX_FREQ_COEFFS);
+- FDKmemcpy(sfmOrig[est], sfmOrig[est + noEstPerFrame],
+- sizeof(FIXP_DBL) * MAX_FREQ_COEFFS);
+- FDKmemcpy(sfmSbr[est], sfmSbr[est + noEstPerFrame],
+- sizeof(FIXP_DBL) * MAX_FREQ_COEFFS);
+- }
+- C_ALLOC_SCRATCH_END(_scratch, FIXP_DBL,
+- 3 * MAX_NO_OF_ESTIMATES / 2 * MAX_FREQ_COEFFS)
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Initialize an instance of the missing harmonics detector.
+-
+-
+- \return errorCode, noError if OK.
+-
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_CreateSbrMissingHarmonicsDetector(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hSbrMHDet, INT chan) {
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hs = hSbrMHDet;
+- INT i;
+-
+- UCHAR *detectionVectors = GetRam_Sbr_detectionVectors(chan);
+- UCHAR *guideVectorDetected = GetRam_Sbr_guideVectorDetected(chan);
+- FIXP_DBL *guideVectorDiff = GetRam_Sbr_guideVectorDiff(chan);
+- FIXP_DBL *guideVectorOrig = GetRam_Sbr_guideVectorOrig(chan);
+-
+- FDKmemclear(hs, sizeof(SBR_MISSING_HARMONICS_DETECTOR));
+-
+- hs->prevEnvelopeCompensation = GetRam_Sbr_prevEnvelopeCompensation(chan);
+- hs->guideScfb = GetRam_Sbr_guideScfb(chan);
+-
+- if ((NULL == detectionVectors) || (NULL == guideVectorDetected) ||
+- (NULL == guideVectorDiff) || (NULL == guideVectorOrig) ||
+- (NULL == hs->prevEnvelopeCompensation) || (NULL == hs->guideScfb)) {
+- goto bail;
+- }
+-
+- for (i = 0; i < MAX_NO_OF_ESTIMATES; i++) {
+- hs->guideVectors[i].guideVectorDiff =
+- guideVectorDiff + (i * MAX_FREQ_COEFFS);
+- hs->guideVectors[i].guideVectorOrig =
+- guideVectorOrig + (i * MAX_FREQ_COEFFS);
+- hs->detectionVectors[i] = detectionVectors + (i * MAX_FREQ_COEFFS);
+- hs->guideVectors[i].guideVectorDetected =
+- guideVectorDetected + (i * MAX_FREQ_COEFFS);
+- }
+-
+- return 0;
+-
+-bail:
+- hs->guideVectors[0].guideVectorDiff = guideVectorDiff;
+- hs->guideVectors[0].guideVectorOrig = guideVectorOrig;
+- hs->detectionVectors[0] = detectionVectors;
+- hs->guideVectors[0].guideVectorDetected = guideVectorDetected;
+-
+- FDKsbrEnc_DeleteSbrMissingHarmonicsDetector(hs);
+- return -1;
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Initialize an instance of the missing harmonics detector.
+-
+-
+- \return errorCode, noError if OK.
+-
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_InitSbrMissingHarmonicsDetector(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hSbrMHDet, INT sampleFreq,
+- INT frameSize, INT nSfb, INT qmfNoChannels, INT totNoEst, INT move,
+- INT noEstPerFrame, UINT sbrSyntaxFlags) {
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hs = hSbrMHDet;
+- int i;
+-
+- FDK_ASSERT(totNoEst <= MAX_NO_OF_ESTIMATES);
+-
+- if (sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- switch (frameSize) {
+- case 1024:
+- case 512:
+- hs->transientPosOffset = FRAME_MIDDLE_SLOT_512LD;
+- hs->timeSlots = 16;
+- break;
+- case 960:
+- case 480:
+- hs->transientPosOffset = FRAME_MIDDLE_SLOT_512LD;
+- hs->timeSlots = 15;
+- break;
+- default:
+- return -1;
+- }
+- } else {
+- switch (frameSize) {
+- case 2048:
+- case 1024:
+- hs->transientPosOffset = FRAME_MIDDLE_SLOT_2048;
+- hs->timeSlots = NUMBER_TIME_SLOTS_2048;
+- break;
+- case 1920:
+- case 960:
+- hs->transientPosOffset = FRAME_MIDDLE_SLOT_1920;
+- hs->timeSlots = NUMBER_TIME_SLOTS_1920;
+- break;
+- default:
+- return -1;
+- }
+- }
+-
+- if (sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- hs->mhParams = ¶msAacLd;
+- } else
+- hs->mhParams = ¶msAac;
+-
+- hs->qmfNoChannels = qmfNoChannels;
+- hs->sampleFreq = sampleFreq;
+- hs->nSfb = nSfb;
+-
+- hs->totNoEst = totNoEst;
+- hs->move = move;
+- hs->noEstPerFrame = noEstPerFrame;
+-
+- for (i = 0; i < totNoEst; i++) {
+- FDKmemclear(hs->guideVectors[i].guideVectorDiff,
+- sizeof(FIXP_DBL) * MAX_FREQ_COEFFS);
+- FDKmemclear(hs->guideVectors[i].guideVectorOrig,
+- sizeof(FIXP_DBL) * MAX_FREQ_COEFFS);
+- FDKmemclear(hs->detectionVectors[i], sizeof(UCHAR) * MAX_FREQ_COEFFS);
+- FDKmemclear(hs->guideVectors[i].guideVectorDetected,
+- sizeof(UCHAR) * MAX_FREQ_COEFFS);
+- }
+-
+- // for(i=0; i<totNoEst/2; i++) {
+- for (i = 0; i < MAX_NO_OF_ESTIMATES / 2; i++) {
+- FDKmemclear(hs->tonalityDiff[i], sizeof(FIXP_DBL) * MAX_FREQ_COEFFS);
+- FDKmemclear(hs->sfmOrig[i], sizeof(FIXP_DBL) * MAX_FREQ_COEFFS);
+- FDKmemclear(hs->sfmSbr[i], sizeof(FIXP_DBL) * MAX_FREQ_COEFFS);
+- }
+-
+- FDKmemclear(hs->prevEnvelopeCompensation, sizeof(UCHAR) * MAX_FREQ_COEFFS);
+- FDKmemclear(hs->guideScfb, sizeof(UCHAR) * MAX_FREQ_COEFFS);
+-
+- hs->previousTransientFlag = 0;
+- hs->previousTransientFrame = 0;
+- hs->previousTransientPos = 0;
+-
+- return (0);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Deletes an instance of the missing harmonics detector.
+-
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-void FDKsbrEnc_DeleteSbrMissingHarmonicsDetector(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hSbrMHDet) {
+- if (hSbrMHDet) {
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hs = hSbrMHDet;
+-
+- FreeRam_Sbr_detectionVectors(&hs->detectionVectors[0]);
+- FreeRam_Sbr_guideVectorDetected(&hs->guideVectors[0].guideVectorDetected);
+- FreeRam_Sbr_guideVectorDiff(&hs->guideVectors[0].guideVectorDiff);
+- FreeRam_Sbr_guideVectorOrig(&hs->guideVectors[0].guideVectorOrig);
+- FreeRam_Sbr_prevEnvelopeCompensation(&hs->prevEnvelopeCompensation);
+- FreeRam_Sbr_guideScfb(&hs->guideScfb);
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Resets an instance of the missing harmonics detector.
+-
+-
+- \return error code, noError if OK.
+-
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_ResetSbrMissingHarmonicsDetector(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hSbrMissingHarmonicsDetector,
+- INT nSfb) {
+- int i;
+- FIXP_DBL tempGuide[MAX_FREQ_COEFFS];
+- UCHAR tempGuideInt[MAX_FREQ_COEFFS];
+- INT nSfbPrev;
+-
+- nSfbPrev = hSbrMissingHarmonicsDetector->nSfb;
+- hSbrMissingHarmonicsDetector->nSfb = nSfb;
+-
+- FDKmemcpy(tempGuideInt, hSbrMissingHarmonicsDetector->guideScfb,
+- nSfbPrev * sizeof(UCHAR));
+-
+- if (nSfb > nSfbPrev) {
+- for (i = 0; i < (nSfb - nSfbPrev); i++) {
+- hSbrMissingHarmonicsDetector->guideScfb[i] = 0;
+- }
+-
+- for (i = 0; i < nSfbPrev; i++) {
+- hSbrMissingHarmonicsDetector->guideScfb[i + (nSfb - nSfbPrev)] =
+- tempGuideInt[i];
+- }
+- } else {
+- for (i = 0; i < nSfb; i++) {
+- hSbrMissingHarmonicsDetector->guideScfb[i] =
+- tempGuideInt[i + (nSfbPrev - nSfb)];
+- }
+- }
+-
+- FDKmemcpy(tempGuide,
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorDiff,
+- nSfbPrev * sizeof(FIXP_DBL));
+-
+- if (nSfb > nSfbPrev) {
+- for (i = 0; i < (nSfb - nSfbPrev); i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorDiff[i] =
+- FL2FXCONST_DBL(0.0f);
+- }
+-
+- for (i = 0; i < nSfbPrev; i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0]
+- .guideVectorDiff[i + (nSfb - nSfbPrev)] = tempGuide[i];
+- }
+- } else {
+- for (i = 0; i < nSfb; i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorDiff[i] =
+- tempGuide[i + (nSfbPrev - nSfb)];
+- }
+- }
+-
+- FDKmemcpy(tempGuide,
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorOrig,
+- nSfbPrev * sizeof(FIXP_DBL));
+-
+- if (nSfb > nSfbPrev) {
+- for (i = 0; i < (nSfb - nSfbPrev); i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorOrig[i] =
+- FL2FXCONST_DBL(0.0f);
+- }
+-
+- for (i = 0; i < nSfbPrev; i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0]
+- .guideVectorOrig[i + (nSfb - nSfbPrev)] = tempGuide[i];
+- }
+- } else {
+- for (i = 0; i < nSfb; i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorOrig[i] =
+- tempGuide[i + (nSfbPrev - nSfb)];
+- }
+- }
+-
+- FDKmemcpy(tempGuideInt,
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorDetected,
+- nSfbPrev * sizeof(UCHAR));
+-
+- if (nSfb > nSfbPrev) {
+- for (i = 0; i < (nSfb - nSfbPrev); i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorDetected[i] = 0;
+- }
+-
+- for (i = 0; i < nSfbPrev; i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0]
+- .guideVectorDetected[i + (nSfb - nSfbPrev)] = tempGuideInt[i];
+- }
+- } else {
+- for (i = 0; i < nSfb; i++) {
+- hSbrMissingHarmonicsDetector->guideVectors[0].guideVectorDetected[i] =
+- tempGuideInt[i + (nSfbPrev - nSfb)];
+- }
+- }
+-
+- FDKmemcpy(tempGuideInt,
+- hSbrMissingHarmonicsDetector->prevEnvelopeCompensation,
+- nSfbPrev * sizeof(UCHAR));
+-
+- if (nSfb > nSfbPrev) {
+- for (i = 0; i < (nSfb - nSfbPrev); i++) {
+- hSbrMissingHarmonicsDetector->prevEnvelopeCompensation[i] = 0;
+- }
+-
+- for (i = 0; i < nSfbPrev; i++) {
+- hSbrMissingHarmonicsDetector
+- ->prevEnvelopeCompensation[i + (nSfb - nSfbPrev)] = tempGuideInt[i];
+- }
+- } else {
+- for (i = 0; i < nSfb; i++) {
+- hSbrMissingHarmonicsDetector->prevEnvelopeCompensation[i] =
+- tempGuideInt[i + (nSfbPrev - nSfb)];
+- }
+- }
+-
+- return 0;
+-}
+diff --git a/libSBRenc/src/mh_det.h b/libSBRenc/src/mh_det.h
+deleted file mode 100644
+index 89d81b5..0000000
+--- a/libSBRenc/src/mh_det.h
++++ /dev/null
+@@ -1,204 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief missing harmonics detection header file $Revision: 92790 $
+-*/
+-
+-#ifndef MH_DET_H
+-#define MH_DET_H
+-
+-#include "sbr_encoder.h"
+-#include "fram_gen.h"
+-
+-typedef struct {
+- FIXP_DBL thresHoldDiff; /*!< threshold for tonality difference */
+- FIXP_DBL thresHoldDiffGuide; /*!< threshold for tonality difference for the
+- guide */
+- FIXP_DBL thresHoldTone; /*!< threshold for tonality for a sine */
+- FIXP_DBL invThresHoldTone;
+- FIXP_DBL thresHoldToneGuide; /*!< threshold for tonality for a sine for the
+- guide */
+- FIXP_DBL sfmThresSbr; /*!< tonality flatness measure threshold for the SBR
+- signal.*/
+- FIXP_DBL sfmThresOrig; /*!< tonality flatness measure threshold for the
+- original signal.*/
+- FIXP_DBL decayGuideOrig; /*!< decay value of the tonality value of the guide
+- for the tone. */
+- FIXP_DBL decayGuideDiff; /*!< decay value of the tonality value of the guide
+- for the tonality difference. */
+- FIXP_DBL derivThresMaxLD64; /*!< threshold for detecting LP character in a
+- signal. */
+- FIXP_DBL derivThresBelowLD64; /*!< threshold for detecting LP character in a
+- signal. */
+- FIXP_DBL derivThresAboveLD64; /*!< threshold for detecting LP character in a
+- signal. */
+-} THRES_HOLDS;
+-
+-typedef struct {
+- INT deltaTime; /*!< maximum allowed transient distance (from frame border in
+- number of qmf subband sample) for a frame to be considered a
+- transient frame.*/
+- THRES_HOLDS thresHolds; /*!< the thresholds used for detection. */
+- INT maxComp; /*!< maximum alllowed compensation factor for the envelope data.
+- */
+-} DETECTOR_PARAMETERS_MH;
+-
+-typedef struct {
+- FIXP_DBL *guideVectorDiff;
+- FIXP_DBL *guideVectorOrig;
+- UCHAR *guideVectorDetected;
+-} GUIDE_VECTORS;
+-
+-typedef struct {
+- INT qmfNoChannels;
+- INT nSfb;
+- INT sampleFreq;
+- INT previousTransientFlag;
+- INT previousTransientFrame;
+- INT previousTransientPos;
+-
+- INT noVecPerFrame;
+- INT transientPosOffset;
+-
+- INT move;
+- INT totNoEst;
+- INT noEstPerFrame;
+- INT timeSlots;
+-
+- UCHAR *guideScfb;
+- UCHAR *prevEnvelopeCompensation;
+- UCHAR *detectionVectors[MAX_NO_OF_ESTIMATES];
+- FIXP_DBL tonalityDiff[MAX_NO_OF_ESTIMATES / 2][MAX_FREQ_COEFFS];
+- FIXP_DBL sfmOrig[MAX_NO_OF_ESTIMATES / 2][MAX_FREQ_COEFFS];
+- FIXP_DBL sfmSbr[MAX_NO_OF_ESTIMATES / 2][MAX_FREQ_COEFFS];
+- const DETECTOR_PARAMETERS_MH *mhParams;
+- GUIDE_VECTORS guideVectors[MAX_NO_OF_ESTIMATES];
+-} SBR_MISSING_HARMONICS_DETECTOR;
+-
+-typedef SBR_MISSING_HARMONICS_DETECTOR *HANDLE_SBR_MISSING_HARMONICS_DETECTOR;
+-
+-void FDKsbrEnc_SbrMissingHarmonicsDetectorQmf(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR h_sbrMissingHarmonicsDetector,
+- FIXP_DBL **pQuotaBuffer, INT **pSignBuffer, SCHAR *indexVector,
+- const SBR_FRAME_INFO *pFrameInfo, const UCHAR *pTranInfo,
+- INT *pAddHarmonicsFlag, UCHAR *pAddHarmonicsScaleFactorBands,
+- const UCHAR *freqBandTable, INT nSfb, UCHAR *envelopeCompensation,
+- FIXP_DBL *pNrgVector);
+-
+-INT FDKsbrEnc_CreateSbrMissingHarmonicsDetector(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hSbrMHDet, INT chan);
+-
+-INT FDKsbrEnc_InitSbrMissingHarmonicsDetector(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR h_sbrMissingHarmonicsDetector,
+- INT sampleFreq, INT frameSize, INT nSfb, INT qmfNoChannels, INT totNoEst,
+- INT move, INT noEstPerFrame, UINT sbrSyntaxFlags);
+-
+-void FDKsbrEnc_DeleteSbrMissingHarmonicsDetector(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR h_sbrMissingHarmonicsDetector);
+-
+-INT FDKsbrEnc_ResetSbrMissingHarmonicsDetector(
+- HANDLE_SBR_MISSING_HARMONICS_DETECTOR hSbrMissingHarmonicsDetector,
+- INT nSfb);
+-
+-#endif
+diff --git a/libSBRenc/src/nf_est.cpp b/libSBRenc/src/nf_est.cpp
+deleted file mode 100644
+index 290ec35..0000000
+--- a/libSBRenc/src/nf_est.cpp
++++ /dev/null
+@@ -1,612 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "nf_est.h"
+-
+-#include "sbr_misc.h"
+-
+-#include "genericStds.h"
+-
+-/* smoothFilter[4] = {0.05857864376269f, 0.2f, 0.34142135623731f, 0.4f}; */
+-static const FIXP_DBL smoothFilter[4] = {0x077f813d, 0x19999995, 0x2bb3b1f5,
+- 0x33333335};
+-
+-/* static const INT smoothFilterLength = 4; */
+-
+-static const FIXP_DBL QuantOffset = (INT)0xfc000000; /* ld64(0.25) */
+-
+-#ifndef min
+-#define min(a, b) (a < b ? a : b)
+-#endif
+-
+-#ifndef max
+-#define max(a, b) (a > b ? a : b)
+-#endif
+-
+-#define NOISE_FLOOR_OFFSET_SCALING (4)
+-
+-/**************************************************************************/
+-/*!
+- \brief The function applies smoothing to the noise levels.
+-
+-
+-
+- \return none
+-
+-*/
+-/**************************************************************************/
+-static void smoothingOfNoiseLevels(
+- FIXP_DBL *NoiseLevels, /*!< pointer to noise-floor levels.*/
+- INT nEnvelopes, /*!< Number of noise floor envelopes.*/
+- INT noNoiseBands, /*!< Number of noise bands for every noise floor envelope.
+- */
+- FIXP_DBL prevNoiseLevels[NF_SMOOTHING_LENGTH]
+- [MAX_NUM_NOISE_VALUES], /*!< Previous noise floor
+- envelopes. */
+- const FIXP_DBL *
+- pSmoothFilter, /*!< filter used for smoothing the noise floor levels. */
+- INT transientFlag) /*!< flag indicating if a transient is present*/
+-
+-{
+- INT i, band, env;
+- FIXP_DBL accu;
+-
+- for (env = 0; env < nEnvelopes; env++) {
+- if (transientFlag) {
+- for (i = 0; i < NF_SMOOTHING_LENGTH; i++) {
+- FDKmemcpy(prevNoiseLevels[i], NoiseLevels + env * noNoiseBands,
+- noNoiseBands * sizeof(FIXP_DBL));
+- }
+- } else {
+- for (i = 1; i < NF_SMOOTHING_LENGTH; i++) {
+- FDKmemcpy(prevNoiseLevels[i - 1], prevNoiseLevels[i],
+- noNoiseBands * sizeof(FIXP_DBL));
+- }
+- FDKmemcpy(prevNoiseLevels[NF_SMOOTHING_LENGTH - 1],
+- NoiseLevels + env * noNoiseBands,
+- noNoiseBands * sizeof(FIXP_DBL));
+- }
+-
+- for (band = 0; band < noNoiseBands; band++) {
+- accu = FL2FXCONST_DBL(0.0f);
+- for (i = 0; i < NF_SMOOTHING_LENGTH; i++) {
+- accu += fMultDiv2(pSmoothFilter[i], prevNoiseLevels[i][band]);
+- }
+- FDK_ASSERT((band + env * noNoiseBands) < MAX_NUM_NOISE_VALUES);
+- NoiseLevels[band + env * noNoiseBands] = accu << 1;
+- }
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Does the noise floor level estiamtion.
+-
+- The noiseLevel samples are scaled by the factor 0.25
+-
+- \return none
+-
+-*/
+-/**************************************************************************/
+-static void qmfBasedNoiseFloorDetection(
+- FIXP_DBL *noiseLevel, /*!< Pointer to vector to
+- store the noise levels
+- in.*/
+- FIXP_DBL **quotaMatrixOrig, /*!< Matrix holding the quota
+- values of the original. */
+- SCHAR *indexVector, /*!< Index vector to obtain the
+- patched data. */
+- INT startIndex, /*!< Start index. */
+- INT stopIndex, /*!< Stop index. */
+- INT startChannel, /*!< Start channel of the current
+- noise floor band.*/
+- INT stopChannel, /*!< Stop channel of the current
+- noise floor band. */
+- FIXP_DBL ana_max_level, /*!< Maximum level of the
+- adaptive noise.*/
+- FIXP_DBL noiseFloorOffset, /*!< Noise floor offset. */
+- INT missingHarmonicFlag, /*!< Flag indicating if a
+- strong tonal component
+- is missing.*/
+- FIXP_DBL weightFac, /*!< Weightening factor for the
+- difference between orig and sbr.
+- */
+- INVF_MODE diffThres, /*!< Threshold value to control the
+- inverse filtering decision.*/
+- INVF_MODE inverseFilteringLevel) /*!< Inverse filtering
+- level of the current
+- band.*/
+-{
+- INT scale, l, k;
+- FIXP_DBL meanOrig = FL2FXCONST_DBL(0.0f), meanSbr = FL2FXCONST_DBL(0.0f),
+- diff;
+- FIXP_DBL invIndex = GetInvInt(stopIndex - startIndex);
+- FIXP_DBL invChannel = GetInvInt(stopChannel - startChannel);
+- FIXP_DBL accu;
+-
+- /*
+- Calculate the mean value, over the current time segment, for the original, the
+- HFR and the difference, over all channels in the current frequency range.
+- */
+-
+- if (missingHarmonicFlag == 1) {
+- for (l = startChannel; l < stopChannel; l++) {
+- /* tonalityOrig */
+- accu = FL2FXCONST_DBL(0.0f);
+- for (k = startIndex; k < stopIndex; k++) {
+- accu += fMultDiv2(quotaMatrixOrig[k][l], invIndex);
+- }
+- meanOrig = fixMax(meanOrig, (accu << 1));
+-
+- /* tonalitySbr */
+- accu = FL2FXCONST_DBL(0.0f);
+- for (k = startIndex; k < stopIndex; k++) {
+- accu += fMultDiv2(quotaMatrixOrig[k][indexVector[l]], invIndex);
+- }
+- meanSbr = fixMax(meanSbr, (accu << 1));
+- }
+- } else {
+- for (l = startChannel; l < stopChannel; l++) {
+- /* tonalityOrig */
+- accu = FL2FXCONST_DBL(0.0f);
+- for (k = startIndex; k < stopIndex; k++) {
+- accu += fMultDiv2(quotaMatrixOrig[k][l], invIndex);
+- }
+- meanOrig += fMult((accu << 1), invChannel);
+-
+- /* tonalitySbr */
+- accu = FL2FXCONST_DBL(0.0f);
+- for (k = startIndex; k < stopIndex; k++) {
+- accu += fMultDiv2(quotaMatrixOrig[k][indexVector[l]], invIndex);
+- }
+- meanSbr += fMult((accu << 1), invChannel);
+- }
+- }
+-
+- /* Small fix to avoid noise during silent passages.*/
+- if (meanOrig <= FL2FXCONST_DBL(0.000976562f * RELAXATION_FLOAT) &&
+- meanSbr <= FL2FXCONST_DBL(0.000976562f * RELAXATION_FLOAT)) {
+- meanOrig = FL2FXCONST_DBL(101.5936673f * RELAXATION_FLOAT);
+- meanSbr = FL2FXCONST_DBL(101.5936673f * RELAXATION_FLOAT);
+- }
+-
+- meanOrig = fixMax(meanOrig, RELAXATION);
+- meanSbr = fixMax(meanSbr, RELAXATION);
+-
+- if (missingHarmonicFlag == 1 || inverseFilteringLevel == INVF_MID_LEVEL ||
+- inverseFilteringLevel == INVF_LOW_LEVEL ||
+- inverseFilteringLevel == INVF_OFF || inverseFilteringLevel <= diffThres) {
+- diff = RELAXATION;
+- } else {
+- accu = fDivNorm(meanSbr, meanOrig, &scale);
+-
+- diff = fixMax(RELAXATION, fMult(RELAXATION_FRACT, fMult(weightFac, accu)) >>
+- (RELAXATION_SHIFT - scale));
+- }
+-
+- /*
+- * noise Level is now a positive value, i.e.
+- * the more harmonic the signal is the higher noise level,
+- * this makes no sense so we change the sign.
+- *********************************************************/
+- accu = fDivNorm(diff, meanOrig, &scale);
+- scale -= 2;
+-
+- if ((scale > 0) && (accu > ((FIXP_DBL)MAXVAL_DBL) >> scale)) {
+- *noiseLevel = (FIXP_DBL)MAXVAL_DBL;
+- } else {
+- *noiseLevel = scaleValue(accu, scale);
+- }
+-
+- /*
+- * Add a noise floor offset to compensate for bias in the detector
+- *****************************************************************/
+- if (!missingHarmonicFlag) {
+- *noiseLevel = fixMin(fMult(*noiseLevel, noiseFloorOffset),
+- (FIXP_DBL)MAXVAL_DBL >> NOISE_FLOOR_OFFSET_SCALING)
+- << NOISE_FLOOR_OFFSET_SCALING;
+- }
+-
+- /*
+- * check to see that we don't exceed the maximum allowed level
+- **************************************************************/
+- *noiseLevel =
+- fixMin(*noiseLevel,
+- ana_max_level); /* ana_max_level is scaled with factor 0.25 */
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Does the noise floor level estiamtion.
+- The function calls the Noisefloor estimation function
+- for the time segments decided based upon the transient
+- information. The block is always divided into one or two segments.
+-
+-
+- \return none
+-
+-*/
+-/**************************************************************************/
+-void FDKsbrEnc_sbrNoiseFloorEstimateQmf(
+- HANDLE_SBR_NOISE_FLOOR_ESTIMATE
+- h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct
+- */
+- const SBR_FRAME_INFO
+- *frame_info, /*!< Time frequency grid of the current frame. */
+- FIXP_DBL
+- *noiseLevels, /*!< Pointer to vector to store the noise levels in.*/
+- FIXP_DBL **quotaMatrixOrig, /*!< Matrix holding the quota values of the
+- original. */
+- SCHAR *indexVector, /*!< Index vector to obtain the patched data. */
+- INT missingHarmonicsFlag, /*!< Flag indicating if a strong tonal component
+- will be missing. */
+- INT startIndex, /*!< Start index. */
+- UINT numberOfEstimatesPerFrame, /*!< The number of tonality estimates per
+- frame. */
+- int transientFrame, /*!< A flag indicating if a transient is present. */
+- INVF_MODE *pInvFiltLevels, /*!< Pointer to the vector holding the inverse
+- filtering levels. */
+- UINT sbrSyntaxFlags)
+-
+-{
+- INT nNoiseEnvelopes, startPos[2], stopPos[2], env, band;
+-
+- INT noNoiseBands = h_sbrNoiseFloorEstimate->noNoiseBands;
+- INT *freqBandTable = h_sbrNoiseFloorEstimate->freqBandTableQmf;
+-
+- nNoiseEnvelopes = frame_info->nNoiseEnvelopes;
+-
+- startPos[0] = startIndex;
+-
+- if (nNoiseEnvelopes == 1) {
+- stopPos[0] = startIndex + min(numberOfEstimatesPerFrame, 2);
+- } else {
+- stopPos[0] = startIndex + 1;
+- startPos[1] = startIndex + 1;
+- stopPos[1] = startIndex + min(numberOfEstimatesPerFrame, 2);
+- }
+-
+- /*
+- * Estimate the noise floor.
+- **************************************/
+- for (env = 0; env < nNoiseEnvelopes; env++) {
+- for (band = 0; band < noNoiseBands; band++) {
+- FDK_ASSERT((band + env * noNoiseBands) < MAX_NUM_NOISE_VALUES);
+- qmfBasedNoiseFloorDetection(
+- &noiseLevels[band + env * noNoiseBands], quotaMatrixOrig, indexVector,
+- startPos[env], stopPos[env], freqBandTable[band],
+- freqBandTable[band + 1], h_sbrNoiseFloorEstimate->ana_max_level,
+- h_sbrNoiseFloorEstimate->noiseFloorOffset[band], missingHarmonicsFlag,
+- h_sbrNoiseFloorEstimate->weightFac,
+- h_sbrNoiseFloorEstimate->diffThres, pInvFiltLevels[band]);
+- }
+- }
+-
+- /*
+- * Smoothing of the values.
+- **************************/
+- smoothingOfNoiseLevels(noiseLevels, nNoiseEnvelopes,
+- h_sbrNoiseFloorEstimate->noNoiseBands,
+- h_sbrNoiseFloorEstimate->prevNoiseLevels,
+- h_sbrNoiseFloorEstimate->smoothFilter, transientFrame);
+-
+- /* quantisation*/
+- for (env = 0; env < nNoiseEnvelopes; env++) {
+- for (band = 0; band < noNoiseBands; band++) {
+- FDK_ASSERT((band + env * noNoiseBands) < MAX_NUM_NOISE_VALUES);
+- noiseLevels[band + env * noNoiseBands] =
+- (FIXP_DBL)NOISE_FLOOR_OFFSET_64 -
+- (FIXP_DBL)CalcLdData(noiseLevels[band + env * noNoiseBands] +
+- (FIXP_DBL)1) +
+- QuantOffset;
+- }
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief
+-
+-
+- \return errorCode, noError if successful
+-
+-*/
+-/**************************************************************************/
+-static INT downSampleLoRes(INT *v_result, /*!< */
+- INT num_result, /*!< */
+- const UCHAR *freqBandTableRef, /*!< */
+- INT num_Ref) /*!< */
+-{
+- INT step;
+- INT i, j;
+- INT org_length, result_length;
+- INT v_index[MAX_FREQ_COEFFS / 2];
+-
+- /* init */
+- org_length = num_Ref;
+- result_length = num_result;
+-
+- v_index[0] = 0; /* Always use left border */
+- i = 0;
+- while (org_length > 0) /* Create downsample vector */
+- {
+- i++;
+- step = org_length / result_length; /* floor; */
+- org_length = org_length - step;
+- result_length--;
+- v_index[i] = v_index[i - 1] + step;
+- }
+-
+- if (i != num_result) /* Should never happen */
+- return (1); /* error downsampling */
+-
+- for (j = 0; j <= i;
+- j++) /* Use downsample vector to index LoResolution vector. */
+- {
+- v_result[j] = freqBandTableRef[v_index[j]];
+- }
+-
+- return (0);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Initialize an instance of the noise floor level estimation module.
+-
+-
+- \return errorCode, noError if successful
+-
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_InitSbrNoiseFloorEstimate(
+- HANDLE_SBR_NOISE_FLOOR_ESTIMATE
+- h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct
+- */
+- INT ana_max_level, /*!< Maximum level of the adaptive noise. */
+- const UCHAR *freqBandTable, /*!< Frequency band table. */
+- INT nSfb, /*!< Number of frequency bands. */
+- INT noiseBands, /*!< Number of noise bands per octave. */
+- INT noiseFloorOffset, /*!< Noise floor offset. */
+- INT timeSlots, /*!< Number of time slots in a frame. */
+- UINT useSpeechConfig /*!< Flag: adapt tuning parameters according to speech
+- */
+-) {
+- INT i, qexp, qtmp;
+- FIXP_DBL tmp, exp;
+-
+- FDKmemclear(h_sbrNoiseFloorEstimate, sizeof(SBR_NOISE_FLOOR_ESTIMATE));
+-
+- h_sbrNoiseFloorEstimate->smoothFilter = smoothFilter;
+- if (useSpeechConfig) {
+- h_sbrNoiseFloorEstimate->weightFac = (FIXP_DBL)MAXVAL_DBL;
+- h_sbrNoiseFloorEstimate->diffThres = INVF_LOW_LEVEL;
+- } else {
+- h_sbrNoiseFloorEstimate->weightFac = FL2FXCONST_DBL(0.25f);
+- h_sbrNoiseFloorEstimate->diffThres = INVF_MID_LEVEL;
+- }
+-
+- h_sbrNoiseFloorEstimate->timeSlots = timeSlots;
+- h_sbrNoiseFloorEstimate->noiseBands = noiseBands;
+-
+- /* h_sbrNoiseFloorEstimate->ana_max_level is scaled by 0.25 */
+- switch (ana_max_level) {
+- case 6:
+- h_sbrNoiseFloorEstimate->ana_max_level = (FIXP_DBL)MAXVAL_DBL;
+- break;
+- case 3:
+- h_sbrNoiseFloorEstimate->ana_max_level = FL2FXCONST_DBL(0.5);
+- break;
+- case -3:
+- h_sbrNoiseFloorEstimate->ana_max_level = FL2FXCONST_DBL(0.125);
+- break;
+- default:
+- /* Should not enter here */
+- h_sbrNoiseFloorEstimate->ana_max_level = (FIXP_DBL)MAXVAL_DBL;
+- break;
+- }
+-
+- /*
+- calculate number of noise bands and allocate
+- */
+- if (FDKsbrEnc_resetSbrNoiseFloorEstimate(h_sbrNoiseFloorEstimate,
+- freqBandTable, nSfb))
+- return (1);
+-
+- if (noiseFloorOffset == 0) {
+- tmp = ((FIXP_DBL)MAXVAL_DBL) >> NOISE_FLOOR_OFFSET_SCALING;
+- } else {
+- /* noiseFloorOffset has to be smaller than 12, because
+- the result of the calculation below must be smaller than 1:
+- (2^(noiseFloorOffset/3))*2^4<1 */
+- FDK_ASSERT(noiseFloorOffset < 12);
+-
+- /* Assumes the noise floor offset in tuning table are in q31 */
+- /* Change the qformat here when non-zero values would be filled */
+- exp = fDivNorm((FIXP_DBL)noiseFloorOffset, 3, &qexp);
+- tmp = fPow(2, DFRACT_BITS - 1, exp, qexp, &qtmp);
+- tmp = scaleValue(tmp, qtmp - NOISE_FLOOR_OFFSET_SCALING);
+- }
+-
+- for (i = 0; i < h_sbrNoiseFloorEstimate->noNoiseBands; i++) {
+- h_sbrNoiseFloorEstimate->noiseFloorOffset[i] = tmp;
+- }
+-
+- return (0);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Resets the current instance of the noise floor estiamtion
+- module.
+-
+-
+- \return errorCode, noError if successful
+-
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_resetSbrNoiseFloorEstimate(
+- HANDLE_SBR_NOISE_FLOOR_ESTIMATE
+- h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct
+- */
+- const UCHAR *freqBandTable, /*!< Frequency band table. */
+- INT nSfb /*!< Number of bands in the frequency band table. */
+-) {
+- INT k2, kx;
+-
+- /*
+- * Calculate number of noise bands
+- ***********************************/
+- k2 = freqBandTable[nSfb];
+- kx = freqBandTable[0];
+- if (h_sbrNoiseFloorEstimate->noiseBands == 0) {
+- h_sbrNoiseFloorEstimate->noNoiseBands = 1;
+- } else {
+- /*
+- * Calculate number of noise bands 1,2 or 3 bands/octave
+- ********************************************************/
+- FIXP_DBL tmp, ratio, lg2;
+- INT ratio_e, qlg2, nNoiseBands;
+-
+- ratio = fDivNorm(k2, kx, &ratio_e);
+- lg2 = fLog2(ratio, ratio_e, &qlg2);
+- tmp = fMult((FIXP_DBL)(h_sbrNoiseFloorEstimate->noiseBands << 24), lg2);
+- tmp = scaleValue(tmp, qlg2 - 23);
+-
+- nNoiseBands = (INT)((tmp + (FIXP_DBL)1) >> 1);
+-
+- if (nNoiseBands > MAX_NUM_NOISE_COEFFS) {
+- nNoiseBands = MAX_NUM_NOISE_COEFFS;
+- }
+-
+- if (nNoiseBands == 0) {
+- nNoiseBands = 1;
+- }
+-
+- h_sbrNoiseFloorEstimate->noNoiseBands = nNoiseBands;
+- }
+-
+- return (downSampleLoRes(h_sbrNoiseFloorEstimate->freqBandTableQmf,
+- h_sbrNoiseFloorEstimate->noNoiseBands, freqBandTable,
+- nSfb));
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Deletes the current instancce of the noise floor level
+- estimation module.
+-
+-
+- \return none
+-
+-*/
+-/**************************************************************************/
+-void FDKsbrEnc_deleteSbrNoiseFloorEstimate(
+- HANDLE_SBR_NOISE_FLOOR_ESTIMATE
+- h_sbrNoiseFloorEstimate) /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct
+- */
+-{
+- if (h_sbrNoiseFloorEstimate) {
+- /*
+- nothing to do
+- */
+- }
+-}
+diff --git a/libSBRenc/src/nf_est.h b/libSBRenc/src/nf_est.h
+deleted file mode 100644
+index c2f16e9..0000000
+--- a/libSBRenc/src/nf_est.h
++++ /dev/null
+@@ -1,185 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Noise floor estimation structs and prototypes $Revision: 92790 $
+-*/
+-
+-#ifndef NF_EST_H
+-#define NF_EST_H
+-
+-#include "sbr_encoder.h"
+-#include "fram_gen.h"
+-
+-#define NF_SMOOTHING_LENGTH 4 /*!< Smoothing length of the noise floors. */
+-
+-typedef struct {
+- FIXP_DBL
+- prevNoiseLevels[NF_SMOOTHING_LENGTH]
+- [MAX_NUM_NOISE_VALUES]; /*!< The previous noise levels. */
+- FIXP_DBL noiseFloorOffset
+- [MAX_NUM_NOISE_VALUES]; /*!< Noise floor offset, scaled with
+- NOISE_FLOOR_OFFSET_SCALING */
+- const FIXP_DBL *smoothFilter; /*!< Smoothing filter to use. */
+- FIXP_DBL ana_max_level; /*!< Max level allowed. */
+- FIXP_DBL weightFac; /*!< Weightening factor for the difference between orig
+- and sbr. */
+- INT freqBandTableQmf[MAX_NUM_NOISE_VALUES +
+- 1]; /*!< Frequncy band table for the noise floor bands.*/
+- INT noNoiseBands; /*!< Number of noisebands. */
+- INT noiseBands; /*!< NoiseBands switch 4 bit.*/
+- INT timeSlots; /*!< Number of timeslots in a frame. */
+- INVF_MODE diffThres; /*!< Threshold value to control the inverse filtering
+- decision */
+-} SBR_NOISE_FLOOR_ESTIMATE;
+-
+-typedef SBR_NOISE_FLOOR_ESTIMATE *HANDLE_SBR_NOISE_FLOOR_ESTIMATE;
+-
+-void FDKsbrEnc_sbrNoiseFloorEstimateQmf(
+- HANDLE_SBR_NOISE_FLOOR_ESTIMATE
+- h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct
+- */
+- const SBR_FRAME_INFO
+- *frame_info, /*!< Time frequency grid of the current frame. */
+- FIXP_DBL
+- *noiseLevels, /*!< Pointer to vector to store the noise levels in.*/
+- FIXP_DBL **quotaMatrixOrig, /*!< Matrix holding the quota values of the
+- original. */
+- SCHAR *indexVector, /*!< Index vector to obtain the patched data. */
+- INT missingHarmonicsFlag, /*!< Flag indicating if a strong tonal component
+- will be missing. */
+- INT startIndex, /*!< Start index. */
+- UINT numberOfEstimatesPerFrame, /*!< The number of tonality estimates per
+- frame. */
+- INT transientFrame, /*!< A flag indicating if a transient is present. */
+- INVF_MODE *pInvFiltLevels, /*!< Pointer to the vector holding the inverse
+- filtering levels. */
+- UINT sbrSyntaxFlags);
+-
+-INT FDKsbrEnc_InitSbrNoiseFloorEstimate(
+- HANDLE_SBR_NOISE_FLOOR_ESTIMATE
+- h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct
+- */
+- INT ana_max_level, /*!< Maximum level of the adaptive noise. */
+- const UCHAR *freqBandTable, /*!< Frequany band table. */
+- INT nSfb, /*!< Number of frequency bands. */
+- INT noiseBands, /*!< Number of noise bands per octave. */
+- INT noiseFloorOffset, /*!< Noise floor offset. */
+- INT timeSlots, /*!< Number of time slots in a frame. */
+- UINT useSpeechConfig /*!< Flag: adapt tuning parameters according to speech
+- */
+-);
+-
+-INT FDKsbrEnc_resetSbrNoiseFloorEstimate(
+- HANDLE_SBR_NOISE_FLOOR_ESTIMATE
+- h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct
+- */
+- const UCHAR *freqBandTable, /*!< Frequany band table. */
+- INT nSfb); /*!< Number of bands in the frequency band table. */
+-
+-void FDKsbrEnc_deleteSbrNoiseFloorEstimate(
+- HANDLE_SBR_NOISE_FLOOR_ESTIMATE
+- h_sbrNoiseFloorEstimate); /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct
+- */
+-
+-#endif
+diff --git a/libSBRenc/src/ps_bitenc.cpp b/libSBRenc/src/ps_bitenc.cpp
+deleted file mode 100644
+index e30af2a..0000000
+--- a/libSBRenc/src/ps_bitenc.cpp
++++ /dev/null
+@@ -1,624 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): N. Rettelbach
+-
+- Description: Parametric Stereo bitstream encoder
+-
+-*******************************************************************************/
+-
+-#include "ps_bitenc.h"
+-
+-#include "ps_main.h"
+-
+-static inline UCHAR FDKsbrEnc_WriteBits_ps(HANDLE_FDK_BITSTREAM hBitStream,
+- UINT value,
+- const UINT numberOfBits) {
+- /* hBitStream == NULL happens here intentionally */
+- if (hBitStream != NULL) {
+- FDKwriteBits(hBitStream, value, numberOfBits);
+- }
+- return numberOfBits;
+-}
+-
+-#define SI_SBR_EXTENSION_SIZE_BITS 4
+-#define SI_SBR_EXTENSION_ESC_COUNT_BITS 8
+-#define SI_SBR_EXTENSION_ID_BITS 2
+-#define EXTENSION_ID_PS_CODING 2
+-#define PS_EXT_ID_V0 0
+-
+-static const INT iidDeltaCoarse_Offset = 14;
+-static const INT iidDeltaCoarse_MaxVal = 28;
+-static const INT iidDeltaFine_Offset = 30;
+-static const INT iidDeltaFine_MaxVal = 60;
+-
+-/* PS Stereo Huffmantable: iidDeltaFreqCoarse */
+-static const UINT iidDeltaFreqCoarse_Length[] = {
+- 17, 17, 17, 17, 16, 15, 13, 10, 9, 7, 6, 5, 4, 3, 1,
+- 3, 4, 5, 6, 6, 8, 11, 13, 14, 14, 15, 17, 18, 18};
+-static const UINT iidDeltaFreqCoarse_Code[] = {
+- 0x0001fffb, 0x0001fffc, 0x0001fffd, 0x0001fffa, 0x0000fffc, 0x00007ffc,
+- 0x00001ffd, 0x000003fe, 0x000001fe, 0x0000007e, 0x0000003c, 0x0000001d,
+- 0x0000000d, 0x00000005, 0000000000, 0x00000004, 0x0000000c, 0x0000001c,
+- 0x0000003d, 0x0000003e, 0x000000fe, 0x000007fe, 0x00001ffc, 0x00003ffc,
+- 0x00003ffd, 0x00007ffd, 0x0001fffe, 0x0003fffe, 0x0003ffff};
+-
+-/* PS Stereo Huffmantable: iidDeltaFreqFine */
+-static const UINT iidDeltaFreqFine_Length[] = {
+- 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 16, 16, 15,
+- 14, 14, 13, 12, 12, 11, 10, 10, 8, 7, 6, 5, 4, 3, 1, 3,
+- 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16,
+- 17, 17, 18, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18};
+-static const UINT iidDeltaFreqFine_Code[] = {
+- 0x0001feb4, 0x0001feb5, 0x0001fd76, 0x0001fd77, 0x0001fd74, 0x0001fd75,
+- 0x0001fe8a, 0x0001fe8b, 0x0001fe88, 0x0000fe80, 0x0001feb6, 0x0000fe82,
+- 0x0000feb8, 0x00007f42, 0x00007fae, 0x00003faf, 0x00001fd1, 0x00001fe9,
+- 0x00000fe9, 0x000007ea, 0x000007fb, 0x000003fb, 0x000001fb, 0x000001ff,
+- 0x0000007c, 0x0000003c, 0x0000001c, 0x0000000c, 0000000000, 0x00000001,
+- 0x00000001, 0x00000002, 0x00000001, 0x0000000d, 0x0000001d, 0x0000003d,
+- 0x0000007d, 0x000000fc, 0x000001fc, 0x000003fc, 0x000003f4, 0x000007eb,
+- 0x00000fea, 0x00001fea, 0x00001fd6, 0x00003fd0, 0x00007faf, 0x00007f43,
+- 0x0000feb9, 0x0000fe83, 0x0001feb7, 0x0000fe81, 0x0001fe89, 0x0001fe8e,
+- 0x0001fe8f, 0x0001fe8c, 0x0001fe8d, 0x0001feb2, 0x0001feb3, 0x0001feb0,
+- 0x0001feb1};
+-
+-/* PS Stereo Huffmantable: iidDeltaTimeCoarse */
+-static const UINT iidDeltaTimeCoarse_Length[] = {
+- 19, 19, 19, 20, 20, 20, 17, 15, 12, 10, 8, 6, 4, 2, 1,
+- 3, 5, 7, 9, 11, 13, 14, 17, 19, 20, 20, 20, 20, 20};
+-static const UINT iidDeltaTimeCoarse_Code[] = {
+- 0x0007fff9, 0x0007fffa, 0x0007fffb, 0x000ffff8, 0x000ffff9, 0x000ffffa,
+- 0x0001fffd, 0x00007ffe, 0x00000ffe, 0x000003fe, 0x000000fe, 0x0000003e,
+- 0x0000000e, 0x00000002, 0000000000, 0x00000006, 0x0000001e, 0x0000007e,
+- 0x000001fe, 0x000007fe, 0x00001ffe, 0x00003ffe, 0x0001fffc, 0x0007fff8,
+- 0x000ffffb, 0x000ffffc, 0x000ffffd, 0x000ffffe, 0x000fffff};
+-
+-/* PS Stereo Huffmantable: iidDeltaTimeFine */
+-static const UINT iidDeltaTimeFine_Length[] = {
+- 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14,
+- 14, 13, 13, 13, 12, 12, 11, 10, 9, 9, 7, 6, 5, 3, 1, 2,
+- 5, 6, 7, 8, 9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15,
+- 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
+-static const UINT iidDeltaTimeFine_Code[] = {
+- 0x00004ed4, 0x00004ed5, 0x00004ece, 0x00004ecf, 0x00004ecc, 0x00004ed6,
+- 0x00004ed8, 0x00004f46, 0x00004f60, 0x00002718, 0x00002719, 0x00002764,
+- 0x00002765, 0x0000276d, 0x000027b1, 0x000013b7, 0x000013d6, 0x000009c7,
+- 0x000009e9, 0x000009ed, 0x000004ee, 0x000004f7, 0x00000278, 0x00000139,
+- 0x0000009a, 0x0000009f, 0x00000020, 0x00000011, 0x0000000a, 0x00000003,
+- 0x00000001, 0000000000, 0x0000000b, 0x00000012, 0x00000021, 0x0000004c,
+- 0x0000009b, 0x0000013a, 0x00000279, 0x00000270, 0x000004ef, 0x000004e2,
+- 0x000009ea, 0x000009d8, 0x000013d7, 0x000013d0, 0x000027b2, 0x000027a2,
+- 0x0000271a, 0x0000271b, 0x00004f66, 0x00004f67, 0x00004f61, 0x00004f47,
+- 0x00004ed9, 0x00004ed7, 0x00004ecd, 0x00004ed2, 0x00004ed3, 0x00004ed0,
+- 0x00004ed1};
+-
+-static const INT iccDelta_Offset = 7;
+-static const INT iccDelta_MaxVal = 14;
+-/* PS Stereo Huffmantable: iccDeltaFreq */
+-static const UINT iccDeltaFreq_Length[] = {14, 14, 12, 10, 7, 5, 3, 1,
+- 2, 4, 6, 8, 9, 11, 13};
+-static const UINT iccDeltaFreq_Code[] = {
+- 0x00003fff, 0x00003ffe, 0x00000ffe, 0x000003fe, 0x0000007e,
+- 0x0000001e, 0x00000006, 0000000000, 0x00000002, 0x0000000e,
+- 0x0000003e, 0x000000fe, 0x000001fe, 0x000007fe, 0x00001ffe};
+-
+-/* PS Stereo Huffmantable: iccDeltaTime */
+-static const UINT iccDeltaTime_Length[] = {14, 13, 11, 9, 7, 5, 3, 1,
+- 2, 4, 6, 8, 10, 12, 14};
+-static const UINT iccDeltaTime_Code[] = {
+- 0x00003ffe, 0x00001ffe, 0x000007fe, 0x000001fe, 0x0000007e,
+- 0x0000001e, 0x00000006, 0000000000, 0x00000002, 0x0000000e,
+- 0x0000003e, 0x000000fe, 0x000003fe, 0x00000ffe, 0x00003fff};
+-
+-static const INT ipdDelta_Offset = 0;
+-static const INT ipdDelta_MaxVal = 7;
+-/* PS Stereo Huffmantable: ipdDeltaFreq */
+-static const UINT ipdDeltaFreq_Length[] = {1, 3, 4, 4, 4, 4, 4, 4};
+-static const UINT ipdDeltaFreq_Code[] = {0x00000001, 0000000000, 0x00000006,
+- 0x00000004, 0x00000002, 0x00000003,
+- 0x00000005, 0x00000007};
+-
+-/* PS Stereo Huffmantable: ipdDeltaTime */
+-static const UINT ipdDeltaTime_Length[] = {1, 3, 4, 5, 5, 4, 4, 3};
+-static const UINT ipdDeltaTime_Code[] = {0x00000001, 0x00000002, 0x00000002,
+- 0x00000003, 0x00000002, 0000000000,
+- 0x00000003, 0x00000003};
+-
+-static const INT opdDelta_Offset = 0;
+-static const INT opdDelta_MaxVal = 7;
+-/* PS Stereo Huffmantable: opdDeltaFreq */
+-static const UINT opdDeltaFreq_Length[] = {1, 3, 4, 4, 5, 5, 4, 3};
+-static const UINT opdDeltaFreq_Code[] = {
+- 0x00000001, 0x00000001, 0x00000006, 0x00000004,
+- 0x0000000f, 0x0000000e, 0x00000005, 0000000000,
+-};
+-
+-/* PS Stereo Huffmantable: opdDeltaTime */
+-static const UINT opdDeltaTime_Length[] = {1, 3, 4, 5, 5, 4, 4, 3};
+-static const UINT opdDeltaTime_Code[] = {0x00000001, 0x00000002, 0x00000001,
+- 0x00000007, 0x00000006, 0000000000,
+- 0x00000002, 0x00000003};
+-
+-static INT getNoBands(const INT mode) {
+- INT noBands = 0;
+-
+- switch (mode) {
+- case 0:
+- case 3: /* coarse */
+- noBands = PS_BANDS_COARSE;
+- break;
+- case 1:
+- case 4: /* mid */
+- noBands = PS_BANDS_MID;
+- break;
+- case 2:
+- case 5: /* fine not supported */
+- default: /* coarse as default */
+- noBands = PS_BANDS_COARSE;
+- }
+-
+- return noBands;
+-}
+-
+-static INT getIIDRes(INT iidMode) {
+- if (iidMode < 3)
+- return PS_IID_RES_COARSE;
+- else
+- return PS_IID_RES_FINE;
+-}
+-
+-static INT encodeDeltaFreq(HANDLE_FDK_BITSTREAM hBitBuf, const INT *val,
+- const INT nBands, const UINT *codeTable,
+- const UINT *lengthTable, const INT tableOffset,
+- const INT maxVal, INT *error) {
+- INT bitCnt = 0;
+- INT lastVal = 0;
+- INT band;
+-
+- for (band = 0; band < nBands; band++) {
+- INT delta = (val[band] - lastVal) + tableOffset;
+- lastVal = val[band];
+- if ((delta > maxVal) || (delta < 0)) {
+- *error = 1;
+- delta = delta > 0 ? maxVal : 0;
+- }
+- bitCnt +=
+- FDKsbrEnc_WriteBits_ps(hBitBuf, codeTable[delta], lengthTable[delta]);
+- }
+-
+- return bitCnt;
+-}
+-
+-static INT encodeDeltaTime(HANDLE_FDK_BITSTREAM hBitBuf, const INT *val,
+- const INT *valLast, const INT nBands,
+- const UINT *codeTable, const UINT *lengthTable,
+- const INT tableOffset, const INT maxVal,
+- INT *error) {
+- INT bitCnt = 0;
+- INT band;
+-
+- for (band = 0; band < nBands; band++) {
+- INT delta = (val[band] - valLast[band]) + tableOffset;
+- if ((delta > maxVal) || (delta < 0)) {
+- *error = 1;
+- delta = delta > 0 ? maxVal : 0;
+- }
+- bitCnt +=
+- FDKsbrEnc_WriteBits_ps(hBitBuf, codeTable[delta], lengthTable[delta]);
+- }
+-
+- return bitCnt;
+-}
+-
+-INT FDKsbrEnc_EncodeIid(HANDLE_FDK_BITSTREAM hBitBuf, const INT *iidVal,
+- const INT *iidValLast, const INT nBands,
+- const PS_IID_RESOLUTION res, const PS_DELTA mode,
+- INT *error) {
+- const UINT *codeTable;
+- const UINT *lengthTable;
+- INT bitCnt = 0;
+-
+- bitCnt = 0;
+-
+- switch (mode) {
+- case PS_DELTA_FREQ:
+- switch (res) {
+- case PS_IID_RES_COARSE:
+- codeTable = iidDeltaFreqCoarse_Code;
+- lengthTable = iidDeltaFreqCoarse_Length;
+- bitCnt += encodeDeltaFreq(hBitBuf, iidVal, nBands, codeTable,
+- lengthTable, iidDeltaCoarse_Offset,
+- iidDeltaCoarse_MaxVal, error);
+- break;
+- case PS_IID_RES_FINE:
+- codeTable = iidDeltaFreqFine_Code;
+- lengthTable = iidDeltaFreqFine_Length;
+- bitCnt +=
+- encodeDeltaFreq(hBitBuf, iidVal, nBands, codeTable, lengthTable,
+- iidDeltaFine_Offset, iidDeltaFine_MaxVal, error);
+- break;
+- default:
+- *error = 1;
+- }
+- break;
+-
+- case PS_DELTA_TIME:
+- switch (res) {
+- case PS_IID_RES_COARSE:
+- codeTable = iidDeltaTimeCoarse_Code;
+- lengthTable = iidDeltaTimeCoarse_Length;
+- bitCnt += encodeDeltaTime(
+- hBitBuf, iidVal, iidValLast, nBands, codeTable, lengthTable,
+- iidDeltaCoarse_Offset, iidDeltaCoarse_MaxVal, error);
+- break;
+- case PS_IID_RES_FINE:
+- codeTable = iidDeltaTimeFine_Code;
+- lengthTable = iidDeltaTimeFine_Length;
+- bitCnt += encodeDeltaTime(hBitBuf, iidVal, iidValLast, nBands,
+- codeTable, lengthTable, iidDeltaFine_Offset,
+- iidDeltaFine_MaxVal, error);
+- break;
+- default:
+- *error = 1;
+- }
+- break;
+-
+- default:
+- *error = 1;
+- }
+-
+- return bitCnt;
+-}
+-
+-INT FDKsbrEnc_EncodeIcc(HANDLE_FDK_BITSTREAM hBitBuf, const INT *iccVal,
+- const INT *iccValLast, const INT nBands,
+- const PS_DELTA mode, INT *error) {
+- const UINT *codeTable;
+- const UINT *lengthTable;
+- INT bitCnt = 0;
+-
+- switch (mode) {
+- case PS_DELTA_FREQ:
+- codeTable = iccDeltaFreq_Code;
+- lengthTable = iccDeltaFreq_Length;
+- bitCnt += encodeDeltaFreq(hBitBuf, iccVal, nBands, codeTable, lengthTable,
+- iccDelta_Offset, iccDelta_MaxVal, error);
+- break;
+-
+- case PS_DELTA_TIME:
+- codeTable = iccDeltaTime_Code;
+- lengthTable = iccDeltaTime_Length;
+-
+- bitCnt +=
+- encodeDeltaTime(hBitBuf, iccVal, iccValLast, nBands, codeTable,
+- lengthTable, iccDelta_Offset, iccDelta_MaxVal, error);
+- break;
+-
+- default:
+- *error = 1;
+- }
+-
+- return bitCnt;
+-}
+-
+-INT FDKsbrEnc_EncodeIpd(HANDLE_FDK_BITSTREAM hBitBuf, const INT *ipdVal,
+- const INT *ipdValLast, const INT nBands,
+- const PS_DELTA mode, INT *error) {
+- const UINT *codeTable;
+- const UINT *lengthTable;
+- INT bitCnt = 0;
+-
+- switch (mode) {
+- case PS_DELTA_FREQ:
+- codeTable = ipdDeltaFreq_Code;
+- lengthTable = ipdDeltaFreq_Length;
+- bitCnt += encodeDeltaFreq(hBitBuf, ipdVal, nBands, codeTable, lengthTable,
+- ipdDelta_Offset, ipdDelta_MaxVal, error);
+- break;
+-
+- case PS_DELTA_TIME:
+- codeTable = ipdDeltaTime_Code;
+- lengthTable = ipdDeltaTime_Length;
+-
+- bitCnt +=
+- encodeDeltaTime(hBitBuf, ipdVal, ipdValLast, nBands, codeTable,
+- lengthTable, ipdDelta_Offset, ipdDelta_MaxVal, error);
+- break;
+-
+- default:
+- *error = 1;
+- }
+-
+- return bitCnt;
+-}
+-
+-INT FDKsbrEnc_EncodeOpd(HANDLE_FDK_BITSTREAM hBitBuf, const INT *opdVal,
+- const INT *opdValLast, const INT nBands,
+- const PS_DELTA mode, INT *error) {
+- const UINT *codeTable;
+- const UINT *lengthTable;
+- INT bitCnt = 0;
+-
+- switch (mode) {
+- case PS_DELTA_FREQ:
+- codeTable = opdDeltaFreq_Code;
+- lengthTable = opdDeltaFreq_Length;
+- bitCnt += encodeDeltaFreq(hBitBuf, opdVal, nBands, codeTable, lengthTable,
+- opdDelta_Offset, opdDelta_MaxVal, error);
+- break;
+-
+- case PS_DELTA_TIME:
+- codeTable = opdDeltaTime_Code;
+- lengthTable = opdDeltaTime_Length;
+-
+- bitCnt +=
+- encodeDeltaTime(hBitBuf, opdVal, opdValLast, nBands, codeTable,
+- lengthTable, opdDelta_Offset, opdDelta_MaxVal, error);
+- break;
+-
+- default:
+- *error = 1;
+- }
+-
+- return bitCnt;
+-}
+-
+-static INT encodeIpdOpd(HANDLE_PS_OUT psOut, HANDLE_FDK_BITSTREAM hBitBuf) {
+- INT bitCnt = 0;
+- INT error = 0;
+- INT env;
+-
+- FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->enableIpdOpd, 1);
+-
+- if (psOut->enableIpdOpd == 1) {
+- INT *ipdLast = psOut->ipdLast;
+- INT *opdLast = psOut->opdLast;
+-
+- for (env = 0; env < psOut->nEnvelopes; env++) {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->deltaIPD[env], 1);
+- bitCnt += FDKsbrEnc_EncodeIpd(hBitBuf, psOut->ipd[env], ipdLast,
+- getNoBands(psOut->iidMode),
+- psOut->deltaIPD[env], &error);
+-
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->deltaOPD[env], 1);
+- bitCnt += FDKsbrEnc_EncodeOpd(hBitBuf, psOut->opd[env], opdLast,
+- getNoBands(psOut->iidMode),
+- psOut->deltaOPD[env], &error);
+- }
+- /* reserved bit */
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, 0, 1);
+- }
+-
+- return bitCnt;
+-}
+-
+-static INT getEnvIdx(const INT nEnvelopes, const INT frameClass) {
+- INT envIdx = 0;
+-
+- switch (nEnvelopes) {
+- case 0:
+- envIdx = 0;
+- break;
+-
+- case 1:
+- if (frameClass == 0)
+- envIdx = 1;
+- else
+- envIdx = 0;
+- break;
+-
+- case 2:
+- if (frameClass == 0)
+- envIdx = 2;
+- else
+- envIdx = 1;
+- break;
+-
+- case 3:
+- envIdx = 2;
+- break;
+-
+- case 4:
+- envIdx = 3;
+- break;
+-
+- default:
+- /* unsupported number of envelopes */
+- envIdx = 0;
+- }
+-
+- return envIdx;
+-}
+-
+-static INT encodePSExtension(const HANDLE_PS_OUT psOut,
+- HANDLE_FDK_BITSTREAM hBitBuf) {
+- INT bitCnt = 0;
+-
+- if (psOut->enableIpdOpd == 1) {
+- INT ipdOpdBits = 0;
+- INT extSize = (2 + encodeIpdOpd(psOut, NULL) + 7) >> 3;
+-
+- if (extSize < 15) {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, extSize, 4);
+- } else {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, 15, 4);
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, (extSize - 15), 8);
+- }
+-
+- /* write ipd opd data */
+- ipdOpdBits += FDKsbrEnc_WriteBits_ps(hBitBuf, PS_EXT_ID_V0, 2);
+- ipdOpdBits += encodeIpdOpd(psOut, hBitBuf);
+-
+- /* byte align the ipd opd data */
+- if (ipdOpdBits % 8)
+- ipdOpdBits += FDKsbrEnc_WriteBits_ps(hBitBuf, 0, (8 - (ipdOpdBits % 8)));
+-
+- bitCnt += ipdOpdBits;
+- }
+-
+- return (bitCnt);
+-}
+-
+-INT FDKsbrEnc_WritePSBitstream(const HANDLE_PS_OUT psOut,
+- HANDLE_FDK_BITSTREAM hBitBuf) {
+- INT psExtEnable = 0;
+- INT bitCnt = 0;
+- INT error = 0;
+- INT env;
+-
+- if (psOut != NULL) {
+- /* PS HEADER */
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->enablePSHeader, 1);
+-
+- if (psOut->enablePSHeader) {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->enableIID, 1);
+- if (psOut->enableIID) {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->iidMode, 3);
+- }
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->enableICC, 1);
+- if (psOut->enableICC) {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->iccMode, 3);
+- }
+- if (psOut->enableIpdOpd) {
+- psExtEnable = 1;
+- }
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psExtEnable, 1);
+- }
+-
+- /* Frame class, number of envelopes */
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->frameClass, 1);
+- bitCnt += FDKsbrEnc_WriteBits_ps(
+- hBitBuf, getEnvIdx(psOut->nEnvelopes, psOut->frameClass), 2);
+-
+- if (psOut->frameClass == 1) {
+- for (env = 0; env < psOut->nEnvelopes; env++) {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->frameBorder[env], 5);
+- }
+- }
+-
+- if (psOut->enableIID == 1) {
+- INT *iidLast = psOut->iidLast;
+- for (env = 0; env < psOut->nEnvelopes; env++) {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->deltaIID[env], 1);
+- bitCnt += FDKsbrEnc_EncodeIid(
+- hBitBuf, psOut->iid[env], iidLast, getNoBands(psOut->iidMode),
+- (PS_IID_RESOLUTION)getIIDRes(psOut->iidMode), psOut->deltaIID[env],
+- &error);
+-
+- iidLast = psOut->iid[env];
+- }
+- }
+-
+- if (psOut->enableICC == 1) {
+- INT *iccLast = psOut->iccLast;
+- for (env = 0; env < psOut->nEnvelopes; env++) {
+- bitCnt += FDKsbrEnc_WriteBits_ps(hBitBuf, psOut->deltaICC[env], 1);
+- bitCnt += FDKsbrEnc_EncodeIcc(hBitBuf, psOut->icc[env], iccLast,
+- getNoBands(psOut->iccMode),
+- psOut->deltaICC[env], &error);
+-
+- iccLast = psOut->icc[env];
+- }
+- }
+-
+- if (psExtEnable != 0) {
+- bitCnt += encodePSExtension(psOut, hBitBuf);
+- }
+-
+- } /* if(psOut != NULL) */
+-
+- return bitCnt;
+-}
+diff --git a/libSBRenc/src/ps_bitenc.h b/libSBRenc/src/ps_bitenc.h
+deleted file mode 100644
+index 1d383e3..0000000
+--- a/libSBRenc/src/ps_bitenc.h
++++ /dev/null
+@@ -1,173 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): N. Rettelbach
+-
+- Description: Parametric Stereo bitstream encoder
+-
+-*******************************************************************************/
+-
+-#include "ps_main.h"
+-#include "ps_const.h"
+-#include "FDK_bitstream.h"
+-
+-#ifndef PS_BITENC_H
+-#define PS_BITENC_H
+-
+-typedef struct T_PS_OUT {
+- INT enablePSHeader;
+- INT enableIID;
+- INT iidMode;
+- INT enableICC;
+- INT iccMode;
+- INT enableIpdOpd;
+-
+- INT frameClass;
+- INT nEnvelopes;
+- /* ENV data */
+- INT frameBorder[PS_MAX_ENVELOPES];
+-
+- /* iid data */
+- PS_DELTA deltaIID[PS_MAX_ENVELOPES];
+- INT iid[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- INT iidLast[PS_MAX_BANDS];
+-
+- /* icc data */
+- PS_DELTA deltaICC[PS_MAX_ENVELOPES];
+- INT icc[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- INT iccLast[PS_MAX_BANDS];
+-
+- /* ipd data */
+- PS_DELTA deltaIPD[PS_MAX_ENVELOPES];
+- INT ipd[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- INT ipdLast[PS_MAX_BANDS];
+-
+- /* opd data */
+- PS_DELTA deltaOPD[PS_MAX_ENVELOPES];
+- INT opd[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- INT opdLast[PS_MAX_BANDS];
+-
+-} PS_OUT, *HANDLE_PS_OUT;
+-
+-#ifdef __cplusplus
+-extern "C" {
+-#endif /* __cplusplus */
+-
+-INT FDKsbrEnc_EncodeIid(HANDLE_FDK_BITSTREAM hBitBuf, const INT *iidVal,
+- const INT *iidValLast, const INT nBands,
+- const PS_IID_RESOLUTION res, const PS_DELTA mode,
+- INT *error);
+-
+-INT FDKsbrEnc_EncodeIcc(HANDLE_FDK_BITSTREAM hBitBuf, const INT *iccVal,
+- const INT *iccValLast, const INT nBands,
+- const PS_DELTA mode, INT *error);
+-
+-INT FDKsbrEnc_EncodeIpd(HANDLE_FDK_BITSTREAM hBitBuf, const INT *ipdVal,
+- const INT *ipdValLast, const INT nBands,
+- const PS_DELTA mode, INT *error);
+-
+-INT FDKsbrEnc_EncodeOpd(HANDLE_FDK_BITSTREAM hBitBuf, const INT *opdVal,
+- const INT *opdValLast, const INT nBands,
+- const PS_DELTA mode, INT *error);
+-
+-INT FDKsbrEnc_WritePSBitstream(const HANDLE_PS_OUT psOut,
+- HANDLE_FDK_BITSTREAM hBitBuf);
+-
+-#ifdef __cplusplus
+-}
+-#endif /* __cplusplus */
+-
+-#endif /* defined(PSENC_ENABLE) */
+diff --git a/libSBRenc/src/ps_const.h b/libSBRenc/src/ps_const.h
+deleted file mode 100644
+index b9a33f9..0000000
+--- a/libSBRenc/src/ps_const.h
++++ /dev/null
+@@ -1,150 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): N. Rettelbach
+-
+- Description: Parametric Stereo constants
+-
+-*******************************************************************************/
+-
+-#ifndef PS_CONST_H
+-#define PS_CONST_H
+-
+-#define MAX_PS_CHANNELS (2)
+-#define HYBRID_MAX_QMF_BANDS (3)
+-#define HYBRID_FILTER_LENGTH (13)
+-#define HYBRID_FILTER_DELAY ((HYBRID_FILTER_LENGTH - 1) / 2)
+-
+-#define HYBRID_FRAMESIZE (32)
+-#define HYBRID_READ_OFFSET (10)
+-
+-#define MAX_HYBRID_BANDS ((64 - HYBRID_MAX_QMF_BANDS + 10))
+-
+-typedef enum {
+- PS_RES_COARSE = 0,
+- PS_RES_MID = 1,
+- PS_RES_FINE = 2
+-} PS_RESOLUTION;
+-
+-typedef enum {
+- PS_BANDS_COARSE = 10,
+- PS_BANDS_MID = 20,
+- PS_MAX_BANDS = PS_BANDS_MID
+-} PS_BANDS;
+-
+-typedef enum { PS_IID_RES_COARSE = 0, PS_IID_RES_FINE } PS_IID_RESOLUTION;
+-
+-typedef enum { PS_ICC_ROT_A = 0, PS_ICC_ROT_B } PS_ICC_ROTATION_MODE;
+-
+-typedef enum { PS_DELTA_FREQ, PS_DELTA_TIME } PS_DELTA;
+-
+-typedef enum {
+- PS_MAX_ENVELOPES = 4
+-
+-} PS_CONSTS;
+-
+-typedef enum {
+- PSENC_OK = 0x0000, /*!< No error happened. All fine. */
+- PSENC_INVALID_HANDLE =
+- 0x0020, /*!< Handle passed to function call was invalid. */
+- PSENC_MEMORY_ERROR = 0x0021, /*!< Memory allocation failed. */
+- PSENC_INIT_ERROR = 0x0040, /*!< General initialization error. */
+- PSENC_ENCODE_ERROR = 0x0060 /*!< The encoding process was interrupted by an
+- unexpected error. */
+-
+-} FDK_PSENC_ERROR;
+-
+-#endif
+diff --git a/libSBRenc/src/ps_encode.cpp b/libSBRenc/src/ps_encode.cpp
+deleted file mode 100644
+index 88d3131..0000000
+--- a/libSBRenc/src/ps_encode.cpp
++++ /dev/null
+@@ -1,1031 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): M. Neuendorf, N. Rettelbach, M. Multrus
+-
+- Description: PS parameter extraction, encoding
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief PS parameter extraction, encoding functions $Revision: 96441 $
+-*/
+-
+-#include "ps_main.h"
+-#include "ps_encode.h"
+-#include "qmf.h"
+-#include "sbr_misc.h"
+-#include "sbrenc_ram.h"
+-
+-#include "genericStds.h"
+-
+-inline void FDKsbrEnc_addFIXP_DBL(const FIXP_DBL *X, const FIXP_DBL *Y,
+- FIXP_DBL *Z, INT n) {
+- for (INT i = 0; i < n; i++) Z[i] = (X[i] >> 1) + (Y[i] >> 1);
+-}
+-
+-#define LOG10_2_10 3.01029995664f /* 10.0f*log10(2.f) */
+-
+-static const INT
+- iidGroupBordersLoRes[QMF_GROUPS_LO_RES + SUBQMF_GROUPS_LO_RES + 1] = {
+- 0, 1, 2, 3, 4, 5, /* 6 subqmf subbands - 0th qmf subband */
+- 6, 7, /* 2 subqmf subbands - 1st qmf subband */
+- 8, 9, /* 2 subqmf subbands - 2nd qmf subband */
+- 10, 11, 12, 13, 14, 15, 16, 18, 21, 25, 30, 42, 71};
+-
+-static const UCHAR
+- iidGroupWidthLdLoRes[QMF_GROUPS_LO_RES + SUBQMF_GROUPS_LO_RES] = {
+- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 4, 5};
+-
+-static const INT subband2parameter20[QMF_GROUPS_LO_RES + SUBQMF_GROUPS_LO_RES] =
+- {1, 0, 0, 1, 2, 3, /* 6 subqmf subbands - 0th qmf subband */
+- 4, 5, /* 2 subqmf subbands - 1st qmf subband */
+- 6, 7, /* 2 subqmf subbands - 2nd qmf subband */
+- 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
+-
+-typedef enum {
+- MAX_TIME_DIFF_FRAMES = 20,
+- MAX_PS_NOHEADER_CNT = 10,
+- MAX_NOENV_CNT = 10,
+- DO_NOT_USE_THIS_MODE = 0x7FFFFF
+-} __PS_CONSTANTS;
+-
+-static const FIXP_DBL iidQuant_fx[15] = {
+- (FIXP_DBL)0xce000000, (FIXP_DBL)0xdc000000, (FIXP_DBL)0xe4000000,
+- (FIXP_DBL)0xec000000, (FIXP_DBL)0xf2000000, (FIXP_DBL)0xf8000000,
+- (FIXP_DBL)0xfc000000, (FIXP_DBL)0x00000000, (FIXP_DBL)0x04000000,
+- (FIXP_DBL)0x08000000, (FIXP_DBL)0x0e000000, (FIXP_DBL)0x14000000,
+- (FIXP_DBL)0x1c000000, (FIXP_DBL)0x24000000, (FIXP_DBL)0x32000000};
+-
+-static const FIXP_DBL iidQuantFine_fx[31] = {
+- (FIXP_DBL)0x9c000001, (FIXP_DBL)0xa6000001, (FIXP_DBL)0xb0000001,
+- (FIXP_DBL)0xba000001, (FIXP_DBL)0xc4000000, (FIXP_DBL)0xce000000,
+- (FIXP_DBL)0xd4000000, (FIXP_DBL)0xda000000, (FIXP_DBL)0xe0000000,
+- (FIXP_DBL)0xe6000000, (FIXP_DBL)0xec000000, (FIXP_DBL)0xf0000000,
+- (FIXP_DBL)0xf4000000, (FIXP_DBL)0xf8000000, (FIXP_DBL)0xfc000000,
+- (FIXP_DBL)0x00000000, (FIXP_DBL)0x04000000, (FIXP_DBL)0x08000000,
+- (FIXP_DBL)0x0c000000, (FIXP_DBL)0x10000000, (FIXP_DBL)0x14000000,
+- (FIXP_DBL)0x1a000000, (FIXP_DBL)0x20000000, (FIXP_DBL)0x26000000,
+- (FIXP_DBL)0x2c000000, (FIXP_DBL)0x32000000, (FIXP_DBL)0x3c000000,
+- (FIXP_DBL)0x45ffffff, (FIXP_DBL)0x4fffffff, (FIXP_DBL)0x59ffffff,
+- (FIXP_DBL)0x63ffffff};
+-
+-static const FIXP_DBL iccQuant[8] = {
+- (FIXP_DBL)0x7fffffff, (FIXP_DBL)0x77ef9d7f, (FIXP_DBL)0x6babc97f,
+- (FIXP_DBL)0x4ceaf27f, (FIXP_DBL)0x2f0ed3c0, (FIXP_DBL)0x00000000,
+- (FIXP_DBL)0xb49ba601, (FIXP_DBL)0x80000000};
+-
+-static FDK_PSENC_ERROR InitPSData(HANDLE_PS_DATA hPsData) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- if (hPsData == NULL) {
+- error = PSENC_INVALID_HANDLE;
+- } else {
+- int i, env;
+- FDKmemclear(hPsData, sizeof(PS_DATA));
+-
+- for (i = 0; i < PS_MAX_BANDS; i++) {
+- hPsData->iidIdxLast[i] = 0;
+- hPsData->iccIdxLast[i] = 0;
+- }
+-
+- hPsData->iidEnable = hPsData->iidEnableLast = 0;
+- hPsData->iccEnable = hPsData->iccEnableLast = 0;
+- hPsData->iidQuantMode = hPsData->iidQuantModeLast = PS_IID_RES_COARSE;
+- hPsData->iccQuantMode = hPsData->iccQuantModeLast = PS_ICC_ROT_A;
+-
+- for (env = 0; env < PS_MAX_ENVELOPES; env++) {
+- hPsData->iccDiffMode[env] = PS_DELTA_FREQ;
+- hPsData->iccDiffMode[env] = PS_DELTA_FREQ;
+-
+- for (i = 0; i < PS_MAX_BANDS; i++) {
+- hPsData->iidIdx[env][i] = 0;
+- hPsData->iccIdx[env][i] = 0;
+- }
+- }
+-
+- hPsData->nEnvelopesLast = 0;
+-
+- hPsData->headerCnt = MAX_PS_NOHEADER_CNT;
+- hPsData->iidTimeCnt = MAX_TIME_DIFF_FRAMES;
+- hPsData->iccTimeCnt = MAX_TIME_DIFF_FRAMES;
+- hPsData->noEnvCnt = MAX_NOENV_CNT;
+- }
+-
+- return error;
+-}
+-
+-static FIXP_DBL quantizeCoef(const FIXP_DBL *RESTRICT input, const INT nBands,
+- const FIXP_DBL *RESTRICT quantTable,
+- const INT idxOffset, const INT nQuantSteps,
+- INT *RESTRICT quantOut) {
+- INT idx, band;
+- FIXP_DBL quantErr = FL2FXCONST_DBL(0.f);
+-
+- for (band = 0; band < nBands; band++) {
+- for (idx = 0; idx < nQuantSteps - 1; idx++) {
+- if (fixp_abs((input[band] >> 1) - (quantTable[idx + 1] >> 1)) >
+- fixp_abs((input[band] >> 1) - (quantTable[idx] >> 1))) {
+- break;
+- }
+- }
+- quantErr += (fixp_abs(input[band] - quantTable[idx]) >>
+- PS_QUANT_SCALE); /* don't scale before subtraction; diff
+- smaller (64-25)/64 */
+- quantOut[band] = idx - idxOffset;
+- }
+-
+- return quantErr;
+-}
+-
+-static INT getICCMode(const INT nBands, const INT rotType) {
+- INT mode = 0;
+-
+- switch (nBands) {
+- case PS_BANDS_COARSE:
+- mode = PS_RES_COARSE;
+- break;
+- case PS_BANDS_MID:
+- mode = PS_RES_MID;
+- break;
+- default:
+- mode = 0;
+- }
+- if (rotType == PS_ICC_ROT_B) {
+- mode += 3;
+- }
+-
+- return mode;
+-}
+-
+-static INT getIIDMode(const INT nBands, const INT iidRes) {
+- INT mode = 0;
+-
+- switch (nBands) {
+- case PS_BANDS_COARSE:
+- mode = PS_RES_COARSE;
+- break;
+- case PS_BANDS_MID:
+- mode = PS_RES_MID;
+- break;
+- default:
+- mode = 0;
+- break;
+- }
+-
+- if (iidRes == PS_IID_RES_FINE) {
+- mode += 3;
+- }
+-
+- return mode;
+-}
+-
+-static INT envelopeReducible(FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- INT psBands, INT nEnvelopes) {
+-#define THRESH_SCALE 7
+-
+- INT reducible = 1; /* true */
+- INT e = 0, b = 0;
+- FIXP_DBL dIid = FL2FXCONST_DBL(0.f);
+- FIXP_DBL dIcc = FL2FXCONST_DBL(0.f);
+-
+- FIXP_DBL iidErrThreshold, iccErrThreshold;
+- FIXP_DBL iidMeanError, iccMeanError;
+-
+- /* square values to prevent sqrt,
+- multiply bands to prevent division; bands shifted DFRACT_BITS instead
+- (DFRACT_BITS-1) because fMultDiv2 used*/
+- iidErrThreshold =
+- fMultDiv2(FL2FXCONST_DBL(6.5f * 6.5f / (IID_SCALE_FT * IID_SCALE_FT)),
+- (FIXP_DBL)(psBands << ((DFRACT_BITS)-THRESH_SCALE)));
+- iccErrThreshold =
+- fMultDiv2(FL2FXCONST_DBL(0.75f * 0.75f),
+- (FIXP_DBL)(psBands << ((DFRACT_BITS)-THRESH_SCALE)));
+-
+- if (nEnvelopes <= 1) {
+- reducible = 0;
+- } else {
+- /* mean error criterion */
+- for (e = 0; (e < nEnvelopes / 2) && (reducible != 0); e++) {
+- iidMeanError = iccMeanError = FL2FXCONST_DBL(0.f);
+- for (b = 0; b < psBands; b++) {
+- dIid = (iid[2 * e][b] >> 1) -
+- (iid[2 * e + 1][b] >> 1); /* scale 1 bit; squared -> 2 bit */
+- dIcc = (icc[2 * e][b] >> 1) - (icc[2 * e + 1][b] >> 1);
+- iidMeanError += fPow2Div2(dIid) >> (5 - 1); /* + (bands=20) scale = 5 */
+- iccMeanError += fPow2Div2(dIcc) >> (5 - 1);
+- } /* --> scaling = 7 bit = THRESH_SCALE !! */
+-
+- /* instead sqrt values are squared!
+- instead of division, multiply threshold with psBands
+- scaling necessary!! */
+-
+- /* quit as soon as threshold is reached */
+- if ((iidMeanError > (iidErrThreshold)) ||
+- (iccMeanError > (iccErrThreshold))) {
+- reducible = 0;
+- }
+- }
+- } /* nEnvelopes != 1 */
+-
+- return reducible;
+-}
+-
+-static void processIidData(PS_DATA *psData,
+- FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- const INT psBands, const INT nEnvelopes,
+- const FIXP_DBL quantErrorThreshold) {
+- INT iidIdxFine[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- INT iidIdxCoarse[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+-
+- FIXP_DBL errIID = FL2FXCONST_DBL(0.f);
+- FIXP_DBL errIIDFine = FL2FXCONST_DBL(0.f);
+- INT bitsIidFreq = 0;
+- INT bitsIidTime = 0;
+- INT bitsFineTot = 0;
+- INT bitsCoarseTot = 0;
+- INT error = 0;
+- INT env, band;
+- INT diffMode[PS_MAX_ENVELOPES], diffModeFine[PS_MAX_ENVELOPES];
+- INT loudnDiff = 0;
+- INT iidTransmit = 0;
+-
+- /* Quantize IID coefficients */
+- for (env = 0; env < nEnvelopes; env++) {
+- errIID +=
+- quantizeCoef(iid[env], psBands, iidQuant_fx, 7, 15, iidIdxCoarse[env]);
+- errIIDFine += quantizeCoef(iid[env], psBands, iidQuantFine_fx, 15, 31,
+- iidIdxFine[env]);
+- }
+-
+- /* normalize error to number of envelopes, ps bands
+- errIID /= psBands*nEnvelopes;
+- errIIDFine /= psBands*nEnvelopes; */
+-
+- /* Check if IID coefficients should be used in this frame */
+- psData->iidEnable = 0;
+- for (env = 0; env < nEnvelopes; env++) {
+- for (band = 0; band < psBands; band++) {
+- loudnDiff += fixp_abs(iidIdxCoarse[env][band]);
+- iidTransmit++;
+- }
+- }
+-
+- if (loudnDiff >
+- fMultI(FL2FXCONST_DBL(0.7f), iidTransmit)) { /* 0.7f empiric value */
+- psData->iidEnable = 1;
+- }
+-
+- /* if iid not active -> RESET data */
+- if (psData->iidEnable == 0) {
+- psData->iidTimeCnt = MAX_TIME_DIFF_FRAMES;
+- for (env = 0; env < nEnvelopes; env++) {
+- psData->iidDiffMode[env] = PS_DELTA_FREQ;
+- FDKmemclear(psData->iidIdx[env], sizeof(INT) * psBands);
+- }
+- return;
+- }
+-
+- /* count COARSE quantization bits for first envelope*/
+- bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[0], NULL, psBands,
+- PS_IID_RES_COARSE, PS_DELTA_FREQ, &error);
+-
+- if ((psData->iidTimeCnt >= MAX_TIME_DIFF_FRAMES) ||
+- (psData->iidQuantModeLast == PS_IID_RES_FINE)) {
+- bitsIidTime = DO_NOT_USE_THIS_MODE;
+- } else {
+- bitsIidTime =
+- FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[0], psData->iidIdxLast, psBands,
+- PS_IID_RES_COARSE, PS_DELTA_TIME, &error);
+- }
+-
+- /* decision DELTA_FREQ vs DELTA_TIME */
+- if (bitsIidTime > bitsIidFreq) {
+- diffMode[0] = PS_DELTA_FREQ;
+- bitsCoarseTot = bitsIidFreq;
+- } else {
+- diffMode[0] = PS_DELTA_TIME;
+- bitsCoarseTot = bitsIidTime;
+- }
+-
+- /* count COARSE quantization bits for following envelopes*/
+- for (env = 1; env < nEnvelopes; env++) {
+- bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[env], NULL, psBands,
+- PS_IID_RES_COARSE, PS_DELTA_FREQ, &error);
+- bitsIidTime =
+- FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[env], iidIdxCoarse[env - 1],
+- psBands, PS_IID_RES_COARSE, PS_DELTA_TIME, &error);
+-
+- /* decision DELTA_FREQ vs DELTA_TIME */
+- if (bitsIidTime > bitsIidFreq) {
+- diffMode[env] = PS_DELTA_FREQ;
+- bitsCoarseTot += bitsIidFreq;
+- } else {
+- diffMode[env] = PS_DELTA_TIME;
+- bitsCoarseTot += bitsIidTime;
+- }
+- }
+-
+- /* count FINE quantization bits for first envelope*/
+- bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxFine[0], NULL, psBands,
+- PS_IID_RES_FINE, PS_DELTA_FREQ, &error);
+-
+- if ((psData->iidTimeCnt >= MAX_TIME_DIFF_FRAMES) ||
+- (psData->iidQuantModeLast == PS_IID_RES_COARSE)) {
+- bitsIidTime = DO_NOT_USE_THIS_MODE;
+- } else {
+- bitsIidTime =
+- FDKsbrEnc_EncodeIid(NULL, iidIdxFine[0], psData->iidIdxLast, psBands,
+- PS_IID_RES_FINE, PS_DELTA_TIME, &error);
+- }
+-
+- /* decision DELTA_FREQ vs DELTA_TIME */
+- if (bitsIidTime > bitsIidFreq) {
+- diffModeFine[0] = PS_DELTA_FREQ;
+- bitsFineTot = bitsIidFreq;
+- } else {
+- diffModeFine[0] = PS_DELTA_TIME;
+- bitsFineTot = bitsIidTime;
+- }
+-
+- /* count FINE quantization bits for following envelopes*/
+- for (env = 1; env < nEnvelopes; env++) {
+- bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxFine[env], NULL, psBands,
+- PS_IID_RES_FINE, PS_DELTA_FREQ, &error);
+- bitsIidTime =
+- FDKsbrEnc_EncodeIid(NULL, iidIdxFine[env], iidIdxFine[env - 1], psBands,
+- PS_IID_RES_FINE, PS_DELTA_TIME, &error);
+-
+- /* decision DELTA_FREQ vs DELTA_TIME */
+- if (bitsIidTime > bitsIidFreq) {
+- diffModeFine[env] = PS_DELTA_FREQ;
+- bitsFineTot += bitsIidFreq;
+- } else {
+- diffModeFine[env] = PS_DELTA_TIME;
+- bitsFineTot += bitsIidTime;
+- }
+- }
+-
+- if (bitsFineTot == bitsCoarseTot) {
+- /* if same number of bits is needed, use the quantization with lower error
+- */
+- if (errIIDFine < errIID) {
+- bitsCoarseTot = DO_NOT_USE_THIS_MODE;
+- } else {
+- bitsFineTot = DO_NOT_USE_THIS_MODE;
+- }
+- } else {
+- /* const FIXP_DBL minThreshold =
+- * FL2FXCONST_DBL(0.2f/(IID_SCALE_FT*PS_QUANT_SCALE_FT)*(psBands*nEnvelopes));
+- */
+- const FIXP_DBL minThreshold =
+- (FIXP_DBL)((LONG)0x00019999 * (psBands * nEnvelopes));
+-
+- /* decision RES_FINE vs RES_COARSE */
+- /* test if errIIDFine*quantErrorThreshold < errIID */
+- /* shiftVal 2 comes from scaling of quantErrorThreshold */
+- if (fixMax(((errIIDFine >> 1) + (minThreshold >> 1)) >> 1,
+- fMult(quantErrorThreshold, errIIDFine)) < (errIID >> 2)) {
+- bitsCoarseTot = DO_NOT_USE_THIS_MODE;
+- } else if (fixMax(((errIID >> 1) + (minThreshold >> 1)) >> 1,
+- fMult(quantErrorThreshold, errIID)) < (errIIDFine >> 2)) {
+- bitsFineTot = DO_NOT_USE_THIS_MODE;
+- }
+- }
+-
+- /* decision RES_FINE vs RES_COARSE */
+- if (bitsFineTot < bitsCoarseTot) {
+- psData->iidQuantMode = PS_IID_RES_FINE;
+- for (env = 0; env < nEnvelopes; env++) {
+- psData->iidDiffMode[env] = diffModeFine[env];
+- FDKmemcpy(psData->iidIdx[env], iidIdxFine[env], psBands * sizeof(INT));
+- }
+- } else {
+- psData->iidQuantMode = PS_IID_RES_COARSE;
+- for (env = 0; env < nEnvelopes; env++) {
+- psData->iidDiffMode[env] = diffMode[env];
+- FDKmemcpy(psData->iidIdx[env], iidIdxCoarse[env], psBands * sizeof(INT));
+- }
+- }
+-
+- /* Count DELTA_TIME encoding streaks */
+- for (env = 0; env < nEnvelopes; env++) {
+- if (psData->iidDiffMode[env] == PS_DELTA_TIME)
+- psData->iidTimeCnt++;
+- else
+- psData->iidTimeCnt = 0;
+- }
+-}
+-
+-static INT similarIid(PS_DATA *psData, const INT psBands,
+- const INT nEnvelopes) {
+- const INT diffThr = (psData->iidQuantMode == PS_IID_RES_COARSE) ? 2 : 3;
+- const INT sumDiffThr = diffThr * psBands / 4;
+- INT similar = 0;
+- INT diff = 0;
+- INT sumDiff = 0;
+- INT env = 0;
+- INT b = 0;
+- if ((nEnvelopes == psData->nEnvelopesLast) && (nEnvelopes == 1)) {
+- similar = 1;
+- for (env = 0; env < nEnvelopes; env++) {
+- sumDiff = 0;
+- b = 0;
+- do {
+- diff = fixp_abs(psData->iidIdx[env][b] - psData->iidIdxLast[b]);
+- sumDiff += diff;
+- if ((diff > diffThr) /* more than x quantization steps in any band */
+- || (sumDiff > sumDiffThr)) { /* more than x quantisations steps
+- overall difference */
+- similar = 0;
+- }
+- b++;
+- } while ((b < psBands) && (similar > 0));
+- }
+- } /* nEnvelopes==1 */
+-
+- return similar;
+-}
+-
+-static INT similarIcc(PS_DATA *psData, const INT psBands,
+- const INT nEnvelopes) {
+- const INT diffThr = 2;
+- const INT sumDiffThr = diffThr * psBands / 4;
+- INT similar = 0;
+- INT diff = 0;
+- INT sumDiff = 0;
+- INT env = 0;
+- INT b = 0;
+- if ((nEnvelopes == psData->nEnvelopesLast) && (nEnvelopes == 1)) {
+- similar = 1;
+- for (env = 0; env < nEnvelopes; env++) {
+- sumDiff = 0;
+- b = 0;
+- do {
+- diff = fixp_abs(psData->iccIdx[env][b] - psData->iccIdxLast[b]);
+- sumDiff += diff;
+- if ((diff > diffThr) /* more than x quantisation step in any band */
+- || (sumDiff > sumDiffThr)) { /* more than x quantisations steps
+- overall difference */
+- similar = 0;
+- }
+- b++;
+- } while ((b < psBands) && (similar > 0));
+- }
+- } /* nEnvelopes==1 */
+-
+- return similar;
+-}
+-
+-static void processIccData(
+- PS_DATA *psData,
+- FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS], /* const input values:
+- unable to declare as
+- const, since it does
+- not poINT to const
+- memory */
+- const INT psBands, const INT nEnvelopes) {
+- FIXP_DBL errICC = FL2FXCONST_DBL(0.f);
+- INT env, band;
+- INT bitsIccFreq, bitsIccTime;
+- INT error = 0;
+- INT inCoherence = 0, iccTransmit = 0;
+- INT *iccIdxLast;
+-
+- iccIdxLast = psData->iccIdxLast;
+-
+- /* Quantize ICC coefficients */
+- for (env = 0; env < nEnvelopes; env++) {
+- errICC +=
+- quantizeCoef(icc[env], psBands, iccQuant, 0, 8, psData->iccIdx[env]);
+- }
+-
+- /* Check if ICC coefficients should be used */
+- psData->iccEnable = 0;
+- for (env = 0; env < nEnvelopes; env++) {
+- for (band = 0; band < psBands; band++) {
+- inCoherence += psData->iccIdx[env][band];
+- iccTransmit++;
+- }
+- }
+- if (inCoherence >
+- fMultI(FL2FXCONST_DBL(0.5f), iccTransmit)) { /* 0.5f empiric value */
+- psData->iccEnable = 1;
+- }
+-
+- if (psData->iccEnable == 0) {
+- psData->iccTimeCnt = MAX_TIME_DIFF_FRAMES;
+- for (env = 0; env < nEnvelopes; env++) {
+- psData->iccDiffMode[env] = PS_DELTA_FREQ;
+- FDKmemclear(psData->iccIdx[env], sizeof(INT) * psBands);
+- }
+- return;
+- }
+-
+- for (env = 0; env < nEnvelopes; env++) {
+- bitsIccFreq = FDKsbrEnc_EncodeIcc(NULL, psData->iccIdx[env], NULL, psBands,
+- PS_DELTA_FREQ, &error);
+-
+- if (psData->iccTimeCnt < MAX_TIME_DIFF_FRAMES) {
+- bitsIccTime = FDKsbrEnc_EncodeIcc(NULL, psData->iccIdx[env], iccIdxLast,
+- psBands, PS_DELTA_TIME, &error);
+- } else {
+- bitsIccTime = DO_NOT_USE_THIS_MODE;
+- }
+-
+- if (bitsIccFreq > bitsIccTime) {
+- psData->iccDiffMode[env] = PS_DELTA_TIME;
+- psData->iccTimeCnt++;
+- } else {
+- psData->iccDiffMode[env] = PS_DELTA_FREQ;
+- psData->iccTimeCnt = 0;
+- }
+- iccIdxLast = psData->iccIdx[env];
+- }
+-}
+-
+-static void calculateIID(FIXP_DBL ldPwrL[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- FIXP_DBL ldPwrR[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- INT nEnvelopes, INT psBands) {
+- INT i = 0;
+- INT env = 0;
+- for (env = 0; env < nEnvelopes; env++) {
+- for (i = 0; i < psBands; i++) {
+- /* iid[env][i] = 10.0f*(float)log10(pwrL[env][i]/pwrR[env][i]);
+- */
+- FIXP_DBL IID = fMultDiv2(FL2FXCONST_DBL(LOG10_2_10 / IID_SCALE_FT),
+- (ldPwrL[env][i] - ldPwrR[env][i]));
+-
+- IID = fixMin(IID, (FIXP_DBL)(MAXVAL_DBL >> (LD_DATA_SHIFT + 1)));
+- IID = fixMax(IID, (FIXP_DBL)(MINVAL_DBL >> (LD_DATA_SHIFT + 1)));
+- iid[env][i] = IID << (LD_DATA_SHIFT + 1);
+- }
+- }
+-}
+-
+-static void calculateICC(FIXP_DBL pwrL[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- FIXP_DBL pwrR[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- FIXP_DBL pwrCr[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- FIXP_DBL pwrCi[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+- INT nEnvelopes, INT psBands) {
+- INT i = 0;
+- INT env = 0;
+- INT border = psBands;
+-
+- switch (psBands) {
+- case PS_BANDS_COARSE:
+- border = 5;
+- break;
+- case PS_BANDS_MID:
+- border = 11;
+- break;
+- default:
+- break;
+- }
+-
+- for (env = 0; env < nEnvelopes; env++) {
+- for (i = 0; i < border; i++) {
+- /* icc[env][i] = min( pwrCr[env][i] / (float) sqrt(pwrL[env][i] *
+- * pwrR[env][i]) , 1.f);
+- */
+- int scale;
+- FIXP_DBL invNrg = invSqrtNorm2(
+- fMax(fMult(pwrL[env][i], pwrR[env][i]), (FIXP_DBL)1), &scale);
+- icc[env][i] =
+- SATURATE_LEFT_SHIFT(fMult(pwrCr[env][i], invNrg), scale, DFRACT_BITS);
+- }
+-
+- for (; i < psBands; i++) {
+- int denom_e;
+- FIXP_DBL denom_m = fMultNorm(pwrL[env][i], pwrR[env][i], &denom_e);
+-
+- if (denom_m == (FIXP_DBL)0) {
+- icc[env][i] = (FIXP_DBL)MAXVAL_DBL;
+- } else {
+- int num_e, result_e;
+- FIXP_DBL num_m, result_m;
+-
+- num_e = CountLeadingBits(
+- fixMax(fixp_abs(pwrCr[env][i]), fixp_abs(pwrCi[env][i])));
+- num_m = fPow2Div2((pwrCr[env][i] << num_e)) +
+- fPow2Div2((pwrCi[env][i] << num_e));
+-
+- result_m = fDivNorm(num_m, denom_m, &result_e);
+- result_e += (-2 * num_e + 1) - denom_e;
+- icc[env][i] = scaleValueSaturate(sqrtFixp(result_m >> (result_e & 1)),
+- (result_e + (result_e & 1)) >> 1);
+- }
+- }
+- }
+-}
+-
+-void FDKsbrEnc_initPsBandNrgScale(HANDLE_PS_ENCODE hPsEncode) {
+- INT group, bin;
+- INT nIidGroups = hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups;
+-
+- FDKmemclear(hPsEncode->psBandNrgScale, PS_MAX_BANDS * sizeof(SCHAR));
+-
+- for (group = 0; group < nIidGroups; group++) {
+- /* Translate group to bin */
+- bin = hPsEncode->subband2parameterIndex[group];
+-
+- /* Translate from 20 bins to 10 bins */
+- if (hPsEncode->psEncMode == PS_BANDS_COARSE) {
+- bin = bin >> 1;
+- }
+-
+- hPsEncode->psBandNrgScale[bin] =
+- (hPsEncode->psBandNrgScale[bin] == 0)
+- ? (hPsEncode->iidGroupWidthLd[group] + 5)
+- : (fixMax(hPsEncode->iidGroupWidthLd[group],
+- hPsEncode->psBandNrgScale[bin]) +
+- 1);
+- }
+-}
+-
+-FDK_PSENC_ERROR FDKsbrEnc_CreatePSEncode(HANDLE_PS_ENCODE *phPsEncode) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- if (phPsEncode == NULL) {
+- error = PSENC_INVALID_HANDLE;
+- } else {
+- HANDLE_PS_ENCODE hPsEncode = NULL;
+- if (NULL == (hPsEncode = GetRam_PsEncode())) {
+- error = PSENC_MEMORY_ERROR;
+- goto bail;
+- }
+- FDKmemclear(hPsEncode, sizeof(PS_ENCODE));
+- *phPsEncode = hPsEncode; /* return allocated handle */
+- }
+-bail:
+- return error;
+-}
+-
+-FDK_PSENC_ERROR FDKsbrEnc_InitPSEncode(HANDLE_PS_ENCODE hPsEncode,
+- const PS_BANDS psEncMode,
+- const FIXP_DBL iidQuantErrorThreshold) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- if (NULL == hPsEncode) {
+- error = PSENC_INVALID_HANDLE;
+- } else {
+- if (PSENC_OK != (InitPSData(&hPsEncode->psData))) {
+- goto bail;
+- }
+-
+- switch (psEncMode) {
+- case PS_BANDS_COARSE:
+- case PS_BANDS_MID:
+- hPsEncode->nQmfIidGroups = QMF_GROUPS_LO_RES;
+- hPsEncode->nSubQmfIidGroups = SUBQMF_GROUPS_LO_RES;
+- FDKmemcpy(hPsEncode->iidGroupBorders, iidGroupBordersLoRes,
+- (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups + 1) *
+- sizeof(INT));
+- FDKmemcpy(hPsEncode->subband2parameterIndex, subband2parameter20,
+- (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups) *
+- sizeof(INT));
+- FDKmemcpy(hPsEncode->iidGroupWidthLd, iidGroupWidthLdLoRes,
+- (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups) *
+- sizeof(UCHAR));
+- break;
+- default:
+- error = PSENC_INIT_ERROR;
+- goto bail;
+- }
+-
+- hPsEncode->psEncMode = psEncMode;
+- hPsEncode->iidQuantErrorThreshold = iidQuantErrorThreshold;
+- FDKsbrEnc_initPsBandNrgScale(hPsEncode);
+- }
+-bail:
+- return error;
+-}
+-
+-FDK_PSENC_ERROR FDKsbrEnc_DestroyPSEncode(HANDLE_PS_ENCODE *phPsEncode) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- if (NULL != phPsEncode) {
+- FreeRam_PsEncode(phPsEncode);
+- }
+-
+- return error;
+-}
+-
+-typedef struct {
+- FIXP_DBL pwrL[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- FIXP_DBL pwrR[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- FIXP_DBL ldPwrL[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- FIXP_DBL ldPwrR[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- FIXP_DBL pwrCr[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- FIXP_DBL pwrCi[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+-
+-} PS_PWR_DATA;
+-
+-FDK_PSENC_ERROR FDKsbrEnc_PSEncode(
+- HANDLE_PS_ENCODE hPsEncode, HANDLE_PS_OUT hPsOut, UCHAR *dynBandScale,
+- UINT maxEnvelopes,
+- FIXP_DBL *hybridData[HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2],
+- const INT frameSize, const INT sendHeader) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- HANDLE_PS_DATA hPsData = &hPsEncode->psData;
+- FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- int envBorder[PS_MAX_ENVELOPES + 1];
+-
+- int group, bin, col, subband, band;
+- int i = 0;
+-
+- int env = 0;
+- int psBands = (int)hPsEncode->psEncMode;
+- int nIidGroups = hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups;
+- int nEnvelopes = fixMin(maxEnvelopes, (UINT)PS_MAX_ENVELOPES);
+-
+- C_ALLOC_SCRATCH_START(pwrData, PS_PWR_DATA, 1)
+-
+- for (env = 0; env < nEnvelopes + 1; env++) {
+- envBorder[env] = fMultI(GetInvInt(nEnvelopes), frameSize * env);
+- }
+-
+- for (env = 0; env < nEnvelopes; env++) {
+- /* clear energy array */
+- for (band = 0; band < psBands; band++) {
+- pwrData->pwrL[env][band] = pwrData->pwrR[env][band] =
+- pwrData->pwrCr[env][band] = pwrData->pwrCi[env][band] = FIXP_DBL(1);
+- }
+-
+- /**** calculate energies and correlation ****/
+-
+- /* start with hybrid data */
+- for (group = 0; group < nIidGroups; group++) {
+- /* Translate group to bin */
+- bin = hPsEncode->subband2parameterIndex[group];
+-
+- /* Translate from 20 bins to 10 bins */
+- if (hPsEncode->psEncMode == PS_BANDS_COARSE) {
+- bin >>= 1;
+- }
+-
+- /* determine group border */
+- int bScale = hPsEncode->psBandNrgScale[bin];
+-
+- FIXP_DBL pwrL_env_bin = pwrData->pwrL[env][bin];
+- FIXP_DBL pwrR_env_bin = pwrData->pwrR[env][bin];
+- FIXP_DBL pwrCr_env_bin = pwrData->pwrCr[env][bin];
+- FIXP_DBL pwrCi_env_bin = pwrData->pwrCi[env][bin];
+-
+- int scale = (int)dynBandScale[bin];
+- for (col = envBorder[env]; col < envBorder[env + 1]; col++) {
+- for (subband = hPsEncode->iidGroupBorders[group];
+- subband < hPsEncode->iidGroupBorders[group + 1]; subband++) {
+- FIXP_DBL l_real = (hybridData[col][0][0][subband]) << scale;
+- FIXP_DBL l_imag = (hybridData[col][0][1][subband]) << scale;
+- FIXP_DBL r_real = (hybridData[col][1][0][subband]) << scale;
+- FIXP_DBL r_imag = (hybridData[col][1][1][subband]) << scale;
+-
+- pwrL_env_bin += (fPow2Div2(l_real) + fPow2Div2(l_imag)) >> bScale;
+- pwrR_env_bin += (fPow2Div2(r_real) + fPow2Div2(r_imag)) >> bScale;
+- pwrCr_env_bin +=
+- (fMultDiv2(l_real, r_real) + fMultDiv2(l_imag, r_imag)) >> bScale;
+- pwrCi_env_bin +=
+- (fMultDiv2(r_real, l_imag) - fMultDiv2(l_real, r_imag)) >> bScale;
+- }
+- }
+- /* assure, nrg's of left and right channel are not negative; necessary on
+- * 16 bit multiply units */
+- pwrData->pwrL[env][bin] = fixMax((FIXP_DBL)0, pwrL_env_bin);
+- pwrData->pwrR[env][bin] = fixMax((FIXP_DBL)0, pwrR_env_bin);
+-
+- pwrData->pwrCr[env][bin] = pwrCr_env_bin;
+- pwrData->pwrCi[env][bin] = pwrCi_env_bin;
+-
+- } /* nIidGroups */
+-
+- /* calc logarithmic energy */
+- LdDataVector(pwrData->pwrL[env], pwrData->ldPwrL[env], psBands);
+- LdDataVector(pwrData->pwrR[env], pwrData->ldPwrR[env], psBands);
+-
+- } /* nEnvelopes */
+-
+- /* calculate iid and icc */
+- calculateIID(pwrData->ldPwrL, pwrData->ldPwrR, iid, nEnvelopes, psBands);
+- calculateICC(pwrData->pwrL, pwrData->pwrR, pwrData->pwrCr, pwrData->pwrCi,
+- icc, nEnvelopes, psBands);
+-
+- /*** Envelope Reduction ***/
+- while (envelopeReducible(iid, icc, psBands, nEnvelopes)) {
+- int e = 0;
+- /* sum energies of two neighboring envelopes */
+- nEnvelopes >>= 1;
+- for (e = 0; e < nEnvelopes; e++) {
+- FDKsbrEnc_addFIXP_DBL(pwrData->pwrL[2 * e], pwrData->pwrL[2 * e + 1],
+- pwrData->pwrL[e], psBands);
+- FDKsbrEnc_addFIXP_DBL(pwrData->pwrR[2 * e], pwrData->pwrR[2 * e + 1],
+- pwrData->pwrR[e], psBands);
+- FDKsbrEnc_addFIXP_DBL(pwrData->pwrCr[2 * e], pwrData->pwrCr[2 * e + 1],
+- pwrData->pwrCr[e], psBands);
+- FDKsbrEnc_addFIXP_DBL(pwrData->pwrCi[2 * e], pwrData->pwrCi[2 * e + 1],
+- pwrData->pwrCi[e], psBands);
+-
+- /* calc logarithmic energy */
+- LdDataVector(pwrData->pwrL[e], pwrData->ldPwrL[e], psBands);
+- LdDataVector(pwrData->pwrR[e], pwrData->ldPwrR[e], psBands);
+-
+- /* reduce number of envelopes and adjust borders */
+- envBorder[e] = envBorder[2 * e];
+- }
+- envBorder[nEnvelopes] = envBorder[2 * nEnvelopes];
+-
+- /* re-calculate iid and icc */
+- calculateIID(pwrData->ldPwrL, pwrData->ldPwrR, iid, nEnvelopes, psBands);
+- calculateICC(pwrData->pwrL, pwrData->pwrR, pwrData->pwrCr, pwrData->pwrCi,
+- icc, nEnvelopes, psBands);
+- }
+-
+- /* */
+- if (sendHeader) {
+- hPsData->headerCnt = MAX_PS_NOHEADER_CNT;
+- hPsData->iidTimeCnt = MAX_TIME_DIFF_FRAMES;
+- hPsData->iccTimeCnt = MAX_TIME_DIFF_FRAMES;
+- hPsData->noEnvCnt = MAX_NOENV_CNT;
+- }
+-
+- /*** Parameter processing, quantisation etc ***/
+- processIidData(hPsData, iid, psBands, nEnvelopes,
+- hPsEncode->iidQuantErrorThreshold);
+- processIccData(hPsData, icc, psBands, nEnvelopes);
+-
+- /*** Initialize output struct ***/
+-
+- /* PS Header on/off ? */
+- if ((hPsData->headerCnt < MAX_PS_NOHEADER_CNT) &&
+- ((hPsData->iidQuantMode == hPsData->iidQuantModeLast) &&
+- (hPsData->iccQuantMode == hPsData->iccQuantModeLast)) &&
+- ((hPsData->iidEnable == hPsData->iidEnableLast) &&
+- (hPsData->iccEnable == hPsData->iccEnableLast))) {
+- hPsOut->enablePSHeader = 0;
+- } else {
+- hPsOut->enablePSHeader = 1;
+- hPsData->headerCnt = 0;
+- }
+-
+- /* nEnvelopes = 0 ? */
+- if ((hPsData->noEnvCnt < MAX_NOENV_CNT) &&
+- (similarIid(hPsData, psBands, nEnvelopes)) &&
+- (similarIcc(hPsData, psBands, nEnvelopes))) {
+- hPsOut->nEnvelopes = nEnvelopes = 0;
+- hPsData->noEnvCnt++;
+- } else {
+- hPsData->noEnvCnt = 0;
+- }
+-
+- if (nEnvelopes > 0) {
+- hPsOut->enableIID = hPsData->iidEnable;
+- hPsOut->iidMode = getIIDMode(psBands, hPsData->iidQuantMode);
+-
+- hPsOut->enableICC = hPsData->iccEnable;
+- hPsOut->iccMode = getICCMode(psBands, hPsData->iccQuantMode);
+-
+- hPsOut->enableIpdOpd = 0;
+- hPsOut->frameClass = 0;
+- hPsOut->nEnvelopes = nEnvelopes;
+-
+- for (env = 0; env < nEnvelopes; env++) {
+- hPsOut->frameBorder[env] = envBorder[env + 1];
+- hPsOut->deltaIID[env] = (PS_DELTA)hPsData->iidDiffMode[env];
+- hPsOut->deltaICC[env] = (PS_DELTA)hPsData->iccDiffMode[env];
+- for (band = 0; band < psBands; band++) {
+- hPsOut->iid[env][band] = hPsData->iidIdx[env][band];
+- hPsOut->icc[env][band] = hPsData->iccIdx[env][band];
+- }
+- }
+-
+- /* IPD OPD not supported right now */
+- FDKmemclear(hPsOut->ipd,
+- PS_MAX_ENVELOPES * PS_MAX_BANDS * sizeof(PS_DELTA));
+- for (env = 0; env < PS_MAX_ENVELOPES; env++) {
+- hPsOut->deltaIPD[env] = PS_DELTA_FREQ;
+- hPsOut->deltaOPD[env] = PS_DELTA_FREQ;
+- }
+-
+- FDKmemclear(hPsOut->ipdLast, PS_MAX_BANDS * sizeof(INT));
+- FDKmemclear(hPsOut->opdLast, PS_MAX_BANDS * sizeof(INT));
+-
+- for (band = 0; band < PS_MAX_BANDS; band++) {
+- hPsOut->iidLast[band] = hPsData->iidIdxLast[band];
+- hPsOut->iccLast[band] = hPsData->iccIdxLast[band];
+- }
+-
+- /* save iids and iccs for differential time coding in the next frame */
+- hPsData->nEnvelopesLast = nEnvelopes;
+- hPsData->iidEnableLast = hPsData->iidEnable;
+- hPsData->iccEnableLast = hPsData->iccEnable;
+- hPsData->iidQuantModeLast = hPsData->iidQuantMode;
+- hPsData->iccQuantModeLast = hPsData->iccQuantMode;
+- for (i = 0; i < psBands; i++) {
+- hPsData->iidIdxLast[i] = hPsData->iidIdx[nEnvelopes - 1][i];
+- hPsData->iccIdxLast[i] = hPsData->iccIdx[nEnvelopes - 1][i];
+- }
+- } /* Envelope > 0 */
+-
+- C_ALLOC_SCRATCH_END(pwrData, PS_PWR_DATA, 1)
+-
+- return error;
+-}
+diff --git a/libSBRenc/src/ps_encode.h b/libSBRenc/src/ps_encode.h
+deleted file mode 100644
+index 4237a00..0000000
+--- a/libSBRenc/src/ps_encode.h
++++ /dev/null
+@@ -1,185 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): M. Neuendorf, N. Rettelbach, M. Multrus
+-
+- Description: PS Parameter extraction, encoding
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief PS parameter extraction, encoding functions $Revision: 92790 $
+-*/
+-
+-#ifndef PS_ENCODE_H
+-#define PS_ENCODE_H
+-
+-#include "ps_const.h"
+-#include "ps_bitenc.h"
+-
+-#define IID_SCALE_FT (64.f) /* maxVal in Quant tab is +/- 50 */
+-#define IID_SCALE 6 /* maxVal in Quant tab is +/- 50 */
+-#define IID_MAXVAL (1 << IID_SCALE)
+-
+-#define PS_QUANT_SCALE_FT \
+- (64.f) /* error smaller (64-25)/64 * 20 bands * 4 env -> QuantScale 64 */
+-#define PS_QUANT_SCALE \
+- 6 /* error smaller (64-25)/64 * 20 bands * 4 env -> QuantScale 6 bit */
+-
+-#define QMF_GROUPS_LO_RES 12
+-#define SUBQMF_GROUPS_LO_RES 10
+-#define QMF_GROUPS_HI_RES 18
+-#define SUBQMF_GROUPS_HI_RES 30
+-
+-typedef struct T_PS_DATA {
+- INT iidEnable;
+- INT iidEnableLast;
+- INT iidQuantMode;
+- INT iidQuantModeLast;
+- INT iidDiffMode[PS_MAX_ENVELOPES];
+- INT iidIdx[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- INT iidIdxLast[PS_MAX_BANDS];
+-
+- INT iccEnable;
+- INT iccEnableLast;
+- INT iccQuantMode;
+- INT iccQuantModeLast;
+- INT iccDiffMode[PS_MAX_ENVELOPES];
+- INT iccIdx[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+- INT iccIdxLast[PS_MAX_BANDS];
+-
+- INT nEnvelopesLast;
+-
+- INT headerCnt;
+- INT iidTimeCnt;
+- INT iccTimeCnt;
+- INT noEnvCnt;
+-
+-} PS_DATA, *HANDLE_PS_DATA;
+-
+-typedef struct T_PS_ENCODE {
+- PS_DATA psData;
+-
+- PS_BANDS psEncMode;
+- INT nQmfIidGroups;
+- INT nSubQmfIidGroups;
+- INT iidGroupBorders[QMF_GROUPS_HI_RES + SUBQMF_GROUPS_HI_RES + 1];
+- INT subband2parameterIndex[QMF_GROUPS_HI_RES + SUBQMF_GROUPS_HI_RES];
+- UCHAR iidGroupWidthLd[QMF_GROUPS_HI_RES + SUBQMF_GROUPS_HI_RES];
+- FIXP_DBL iidQuantErrorThreshold;
+-
+- UCHAR psBandNrgScale[PS_MAX_BANDS];
+-
+-} PS_ENCODE;
+-
+-typedef struct T_PS_ENCODE *HANDLE_PS_ENCODE;
+-
+-FDK_PSENC_ERROR FDKsbrEnc_CreatePSEncode(HANDLE_PS_ENCODE *phPsEncode);
+-
+-FDK_PSENC_ERROR FDKsbrEnc_InitPSEncode(HANDLE_PS_ENCODE hPsEncode,
+- const PS_BANDS psEncMode,
+- const FIXP_DBL iidQuantErrorThreshold);
+-
+-FDK_PSENC_ERROR FDKsbrEnc_DestroyPSEncode(HANDLE_PS_ENCODE *phPsEncode);
+-
+-FDK_PSENC_ERROR FDKsbrEnc_PSEncode(
+- HANDLE_PS_ENCODE hPsEncode, HANDLE_PS_OUT hPsOut, UCHAR *dynBandScale,
+- UINT maxEnvelopes,
+- FIXP_DBL *hybridData[HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2],
+- const INT frameSize, const INT sendHeader);
+-
+-#endif
+diff --git a/libSBRenc/src/ps_main.cpp b/libSBRenc/src/ps_main.cpp
+deleted file mode 100644
+index 4d7a7a5..0000000
+--- a/libSBRenc/src/ps_main.cpp
++++ /dev/null
+@@ -1,606 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): M. Multrus
+-
+- Description: PS Wrapper, Downmix
+-
+-*******************************************************************************/
+-
+-#include "ps_main.h"
+-
+-/* Includes ******************************************************************/
+-#include "ps_bitenc.h"
+-#include "sbrenc_ram.h"
+-
+-/*--------------- function declarations --------------------*/
+-static void psFindBestScaling(
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- FIXP_DBL *hybridData[HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2],
+- UCHAR *dynBandScale, FIXP_DBL *maxBandValue, SCHAR *dmxScale);
+-
+-/*------------- function definitions ----------------*/
+-FDK_PSENC_ERROR PSEnc_Create(HANDLE_PARAMETRIC_STEREO *phParametricStereo) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+- HANDLE_PARAMETRIC_STEREO hParametricStereo = NULL;
+-
+- if (phParametricStereo == NULL) {
+- error = PSENC_INVALID_HANDLE;
+- } else {
+- int i;
+-
+- if (NULL == (hParametricStereo = GetRam_ParamStereo())) {
+- error = PSENC_MEMORY_ERROR;
+- goto bail;
+- }
+- FDKmemclear(hParametricStereo, sizeof(PARAMETRIC_STEREO));
+-
+- if (PSENC_OK !=
+- (error = FDKsbrEnc_CreatePSEncode(&hParametricStereo->hPsEncode))) {
+- error = PSENC_MEMORY_ERROR;
+- goto bail;
+- }
+-
+- for (i = 0; i < MAX_PS_CHANNELS; i++) {
+- if (FDKhybridAnalysisOpen(
+- &hParametricStereo->fdkHybAnaFilter[i],
+- hParametricStereo->__staticHybAnaStatesLF[i],
+- sizeof(hParametricStereo->__staticHybAnaStatesLF[i]),
+- hParametricStereo->__staticHybAnaStatesHF[i],
+- sizeof(hParametricStereo->__staticHybAnaStatesHF[i])) != 0) {
+- error = PSENC_MEMORY_ERROR;
+- goto bail;
+- }
+- }
+- }
+-
+-bail:
+- if (phParametricStereo != NULL) {
+- *phParametricStereo = hParametricStereo; /* return allocated handle */
+- }
+-
+- if (error != PSENC_OK) {
+- PSEnc_Destroy(phParametricStereo);
+- }
+- return error;
+-}
+-
+-FDK_PSENC_ERROR PSEnc_Init(HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- const HANDLE_PSENC_CONFIG hPsEncConfig,
+- INT noQmfSlots, INT noQmfBands, UCHAR *dynamic_RAM) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- if ((NULL == hParametricStereo) || (NULL == hPsEncConfig)) {
+- error = PSENC_INVALID_HANDLE;
+- } else {
+- int ch, i;
+-
+- hParametricStereo->initPS = 1;
+- hParametricStereo->noQmfSlots = noQmfSlots;
+- hParametricStereo->noQmfBands = noQmfBands;
+-
+- /* clear delay lines */
+- FDKmemclear(hParametricStereo->qmfDelayLines,
+- sizeof(hParametricStereo->qmfDelayLines));
+-
+- hParametricStereo->qmfDelayScale = FRACT_BITS - 1;
+-
+- /* create configuration for hybrid filter bank */
+- for (ch = 0; ch < MAX_PS_CHANNELS; ch++) {
+- FDKhybridAnalysisInit(&hParametricStereo->fdkHybAnaFilter[ch],
+- THREE_TO_TEN, 64, 64, 1);
+- } /* ch */
+-
+- FDKhybridSynthesisInit(&hParametricStereo->fdkHybSynFilter, THREE_TO_TEN,
+- 64, 64);
+-
+- /* determine average delay */
+- hParametricStereo->psDelay =
+- (HYBRID_FILTER_DELAY * hParametricStereo->noQmfBands);
+-
+- if ((hPsEncConfig->maxEnvelopes < PSENC_NENV_1) ||
+- (hPsEncConfig->maxEnvelopes > PSENC_NENV_MAX)) {
+- hPsEncConfig->maxEnvelopes = PSENC_NENV_DEFAULT;
+- }
+- hParametricStereo->maxEnvelopes = hPsEncConfig->maxEnvelopes;
+-
+- if (PSENC_OK !=
+- (error = FDKsbrEnc_InitPSEncode(
+- hParametricStereo->hPsEncode, (PS_BANDS)hPsEncConfig->nStereoBands,
+- hPsEncConfig->iidQuantErrorThreshold))) {
+- goto bail;
+- }
+-
+- for (ch = 0; ch < MAX_PS_CHANNELS; ch++) {
+- FIXP_DBL *pDynReal = GetRam_Sbr_envRBuffer(ch, dynamic_RAM);
+- FIXP_DBL *pDynImag = GetRam_Sbr_envIBuffer(ch, dynamic_RAM);
+-
+- for (i = 0; i < HYBRID_FRAMESIZE; i++) {
+- hParametricStereo->pHybridData[i + HYBRID_READ_OFFSET][ch][0] =
+- &pDynReal[i * MAX_HYBRID_BANDS];
+- hParametricStereo->pHybridData[i + HYBRID_READ_OFFSET][ch][1] =
+- &pDynImag[i * MAX_HYBRID_BANDS];
+- ;
+- }
+-
+- for (i = 0; i < HYBRID_READ_OFFSET; i++) {
+- hParametricStereo->pHybridData[i][ch][0] =
+- hParametricStereo->__staticHybridData[i][ch][0];
+- hParametricStereo->pHybridData[i][ch][1] =
+- hParametricStereo->__staticHybridData[i][ch][1];
+- }
+- } /* ch */
+-
+- /* clear static hybrid buffer */
+- FDKmemclear(hParametricStereo->__staticHybridData,
+- sizeof(hParametricStereo->__staticHybridData));
+-
+- /* clear bs buffer */
+- FDKmemclear(hParametricStereo->psOut, sizeof(hParametricStereo->psOut));
+-
+- hParametricStereo->psOut[0].enablePSHeader =
+- 1; /* write ps header in first frame */
+-
+- /* clear scaling buffer */
+- FDKmemclear(hParametricStereo->dynBandScale, sizeof(UCHAR) * PS_MAX_BANDS);
+- FDKmemclear(hParametricStereo->maxBandValue,
+- sizeof(FIXP_DBL) * PS_MAX_BANDS);
+-
+- } /* valid handle */
+-bail:
+- return error;
+-}
+-
+-FDK_PSENC_ERROR PSEnc_Destroy(HANDLE_PARAMETRIC_STEREO *phParametricStereo) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- if (NULL != phParametricStereo) {
+- HANDLE_PARAMETRIC_STEREO hParametricStereo = *phParametricStereo;
+- if (hParametricStereo != NULL) {
+- FDKsbrEnc_DestroyPSEncode(&hParametricStereo->hPsEncode);
+- FreeRam_ParamStereo(phParametricStereo);
+- }
+- }
+-
+- return error;
+-}
+-
+-static FDK_PSENC_ERROR ExtractPSParameters(
+- HANDLE_PARAMETRIC_STEREO hParametricStereo, const int sendHeader,
+- FIXP_DBL *hybridData[HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2]) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- if (hParametricStereo == NULL) {
+- error = PSENC_INVALID_HANDLE;
+- } else {
+- /* call ps encode function */
+- if (hParametricStereo->initPS) {
+- hParametricStereo->psOut[1] = hParametricStereo->psOut[0];
+- }
+- hParametricStereo->psOut[0] = hParametricStereo->psOut[1];
+-
+- if (PSENC_OK !=
+- (error = FDKsbrEnc_PSEncode(
+- hParametricStereo->hPsEncode, &hParametricStereo->psOut[1],
+- hParametricStereo->dynBandScale, hParametricStereo->maxEnvelopes,
+- hybridData, hParametricStereo->noQmfSlots, sendHeader))) {
+- goto bail;
+- }
+-
+- if (hParametricStereo->initPS) {
+- hParametricStereo->psOut[0] = hParametricStereo->psOut[1];
+- hParametricStereo->initPS = 0;
+- }
+- }
+-bail:
+- return error;
+-}
+-
+-static FDK_PSENC_ERROR DownmixPSQmfData(
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_QMF_FILTER_BANK sbrSynthQmf, FIXP_DBL **RESTRICT mixRealQmfData,
+- FIXP_DBL **RESTRICT mixImagQmfData, INT_PCM *downsampledOutSignal,
+- const UINT downsampledOutSignalBufSize,
+- FIXP_DBL *hybridData[HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2],
+- const INT noQmfSlots, const INT psQmfScale[MAX_PS_CHANNELS],
+- SCHAR *qmfScale) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+-
+- if (hParametricStereo == NULL) {
+- error = PSENC_INVALID_HANDLE;
+- } else {
+- int n, k;
+- C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL, 2 * 64)
+-
+- /* define scalings */
+- int dynQmfScale = fixMax(
+- 0, hParametricStereo->dmxScale -
+- 1); /* scale one bit more for addition of left and right */
+- int downmixScale = psQmfScale[0] - dynQmfScale;
+- const FIXP_DBL maxStereoScaleFactor = MAXVAL_DBL; /* 2.f/2.f */
+-
+- for (n = 0; n < noQmfSlots; n++) {
+- FIXP_DBL tmpHybrid[2][MAX_HYBRID_BANDS];
+-
+- for (k = 0; k < 71; k++) {
+- int dynScale, sc; /* scaling */
+- FIXP_DBL tmpLeftReal, tmpRightReal, tmpLeftImag, tmpRightImag;
+- FIXP_DBL tmpScaleFactor, stereoScaleFactor;
+-
+- tmpLeftReal = hybridData[n][0][0][k];
+- tmpLeftImag = hybridData[n][0][1][k];
+- tmpRightReal = hybridData[n][1][0][k];
+- tmpRightImag = hybridData[n][1][1][k];
+-
+- sc = fixMax(
+- 0, CntLeadingZeros(fixMax(
+- fixMax(fixp_abs(tmpLeftReal), fixp_abs(tmpLeftImag)),
+- fixMax(fixp_abs(tmpRightReal), fixp_abs(tmpRightImag)))) -
+- 2);
+-
+- tmpLeftReal <<= sc;
+- tmpLeftImag <<= sc;
+- tmpRightReal <<= sc;
+- tmpRightImag <<= sc;
+- dynScale = fixMin(sc - dynQmfScale, DFRACT_BITS - 1);
+-
+- /* calc stereo scale factor to avoid loss of energy in bands */
+- /* stereo scale factor = min(2.0f, sqrt( (abs(l(k, n)^2 + abs(r(k, n)^2
+- * )))/(0.5f*abs(l(k, n) + r(k, n))) )) */
+- stereoScaleFactor = fPow2Div2(tmpLeftReal) + fPow2Div2(tmpLeftImag) +
+- fPow2Div2(tmpRightReal) + fPow2Div2(tmpRightImag);
+-
+- /* might be that tmpScaleFactor becomes negative, so fabs(.) */
+- tmpScaleFactor =
+- fixp_abs(stereoScaleFactor + fMult(tmpLeftReal, tmpRightReal) +
+- fMult(tmpLeftImag, tmpRightImag));
+-
+- /* min(2.0f, sqrt(stereoScaleFactor/(0.5f*tmpScaleFactor))) */
+- if ((stereoScaleFactor >> 1) <
+- fMult(maxStereoScaleFactor, tmpScaleFactor)) {
+- int sc_num = CountLeadingBits(stereoScaleFactor);
+- int sc_denum = CountLeadingBits(tmpScaleFactor);
+- sc = -(sc_num - sc_denum);
+-
+- tmpScaleFactor = schur_div((stereoScaleFactor << (sc_num)) >> 1,
+- tmpScaleFactor << sc_denum, 16);
+-
+- /* prevent odd scaling for next sqrt calculation */
+- if (sc & 0x1) {
+- sc++;
+- tmpScaleFactor >>= 1;
+- }
+- stereoScaleFactor = sqrtFixp(tmpScaleFactor);
+- stereoScaleFactor <<= (sc >> 1);
+- } else {
+- stereoScaleFactor = maxStereoScaleFactor;
+- }
+-
+- /* write data to hybrid output */
+- tmpHybrid[0][k] = fMultDiv2(stereoScaleFactor,
+- (FIXP_DBL)(tmpLeftReal + tmpRightReal)) >>
+- dynScale;
+- tmpHybrid[1][k] = fMultDiv2(stereoScaleFactor,
+- (FIXP_DBL)(tmpLeftImag + tmpRightImag)) >>
+- dynScale;
+-
+- } /* hybrid bands - k */
+-
+- FDKhybridSynthesisApply(&hParametricStereo->fdkHybSynFilter, tmpHybrid[0],
+- tmpHybrid[1], mixRealQmfData[n],
+- mixImagQmfData[n]);
+-
+- qmfSynthesisFilteringSlot(
+- sbrSynthQmf, mixRealQmfData[n], mixImagQmfData[n], downmixScale - 7,
+- downmixScale - 7,
+- downsampledOutSignal + (n * sbrSynthQmf->no_channels), 1,
+- pWorkBuffer);
+-
+- } /* slots */
+-
+- *qmfScale = -downmixScale + 7;
+-
+- C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, 2 * 64)
+-
+- {
+- const INT noQmfSlots2 = hParametricStereo->noQmfSlots >> 1;
+- const int noQmfBands = hParametricStereo->noQmfBands;
+-
+- INT scale, i, j, slotOffset;
+-
+- FIXP_DBL tmp[2][64];
+-
+- for (i = 0; i < noQmfSlots2; i++) {
+- FDKmemcpy(tmp[0], hParametricStereo->qmfDelayLines[0][i],
+- noQmfBands * sizeof(FIXP_DBL));
+- FDKmemcpy(tmp[1], hParametricStereo->qmfDelayLines[1][i],
+- noQmfBands * sizeof(FIXP_DBL));
+-
+- FDKmemcpy(hParametricStereo->qmfDelayLines[0][i],
+- mixRealQmfData[i + noQmfSlots2],
+- noQmfBands * sizeof(FIXP_DBL));
+- FDKmemcpy(hParametricStereo->qmfDelayLines[1][i],
+- mixImagQmfData[i + noQmfSlots2],
+- noQmfBands * sizeof(FIXP_DBL));
+-
+- FDKmemcpy(mixRealQmfData[i + noQmfSlots2], mixRealQmfData[i],
+- noQmfBands * sizeof(FIXP_DBL));
+- FDKmemcpy(mixImagQmfData[i + noQmfSlots2], mixImagQmfData[i],
+- noQmfBands * sizeof(FIXP_DBL));
+-
+- FDKmemcpy(mixRealQmfData[i], tmp[0], noQmfBands * sizeof(FIXP_DBL));
+- FDKmemcpy(mixImagQmfData[i], tmp[1], noQmfBands * sizeof(FIXP_DBL));
+- }
+-
+- if (hParametricStereo->qmfDelayScale > *qmfScale) {
+- scale = hParametricStereo->qmfDelayScale - *qmfScale;
+- slotOffset = 0;
+- } else {
+- scale = *qmfScale - hParametricStereo->qmfDelayScale;
+- slotOffset = noQmfSlots2;
+- }
+-
+- for (i = 0; i < noQmfSlots2; i++) {
+- for (j = 0; j < noQmfBands; j++) {
+- mixRealQmfData[i + slotOffset][j] >>= scale;
+- mixImagQmfData[i + slotOffset][j] >>= scale;
+- }
+- }
+-
+- scale = *qmfScale;
+- *qmfScale = fMin(*qmfScale, hParametricStereo->qmfDelayScale);
+- hParametricStereo->qmfDelayScale = scale;
+- }
+-
+- } /* valid handle */
+-
+- return error;
+-}
+-
+-INT FDKsbrEnc_PSEnc_WritePSData(HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_FDK_BITSTREAM hBitstream) {
+- return (
+- (hParametricStereo != NULL)
+- ? FDKsbrEnc_WritePSBitstream(&hParametricStereo->psOut[0], hBitstream)
+- : 0);
+-}
+-
+-FDK_PSENC_ERROR FDKsbrEnc_PSEnc_ParametricStereoProcessing(
+- HANDLE_PARAMETRIC_STEREO hParametricStereo, INT_PCM *samples[2],
+- UINT samplesBufSize, QMF_FILTER_BANK **hQmfAnalysis,
+- FIXP_DBL **RESTRICT downmixedRealQmfData,
+- FIXP_DBL **RESTRICT downmixedImagQmfData, INT_PCM *downsampledOutSignal,
+- HANDLE_QMF_FILTER_BANK sbrSynthQmf, SCHAR *qmfScale, const int sendHeader) {
+- FDK_PSENC_ERROR error = PSENC_OK;
+- INT psQmfScale[MAX_PS_CHANNELS] = {0};
+- int psCh, i;
+- C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL, 4 * 64)
+-
+- for (psCh = 0; psCh < MAX_PS_CHANNELS; psCh++) {
+- for (i = 0; i < hQmfAnalysis[psCh]->no_col; i++) {
+- qmfAnalysisFilteringSlot(
+- hQmfAnalysis[psCh], &pWorkBuffer[2 * 64], /* qmfReal[64] */
+- &pWorkBuffer[3 * 64], /* qmfImag[64] */
+- samples[psCh] + i * hQmfAnalysis[psCh]->no_channels, 1,
+- &pWorkBuffer[0 * 64] /* qmf workbuffer 2*64 */
+- );
+-
+- FDKhybridAnalysisApply(
+- &hParametricStereo->fdkHybAnaFilter[psCh],
+- &pWorkBuffer[2 * 64], /* qmfReal[64] */
+- &pWorkBuffer[3 * 64], /* qmfImag[64] */
+- hParametricStereo->pHybridData[i + HYBRID_READ_OFFSET][psCh][0],
+- hParametricStereo->pHybridData[i + HYBRID_READ_OFFSET][psCh][1]);
+-
+- } /* no_col loop i */
+-
+- psQmfScale[psCh] = hQmfAnalysis[psCh]->outScalefactor;
+-
+- } /* for psCh */
+-
+- C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, 4 * 64)
+-
+- /* find best scaling in new QMF and Hybrid data */
+- psFindBestScaling(
+- hParametricStereo, &hParametricStereo->pHybridData[HYBRID_READ_OFFSET],
+- hParametricStereo->dynBandScale, hParametricStereo->maxBandValue,
+- &hParametricStereo->dmxScale);
+-
+- /* extract the ps parameters */
+- if (PSENC_OK !=
+- (error = ExtractPSParameters(hParametricStereo, sendHeader,
+- &hParametricStereo->pHybridData[0]))) {
+- goto bail;
+- }
+-
+- /* save hybrid date for next frame */
+- for (i = 0; i < HYBRID_READ_OFFSET; i++) {
+- FDKmemcpy(
+- hParametricStereo->pHybridData[i][0][0],
+- hParametricStereo->pHybridData[hParametricStereo->noQmfSlots + i][0][0],
+- MAX_HYBRID_BANDS * sizeof(FIXP_DBL)); /* left, real */
+- FDKmemcpy(
+- hParametricStereo->pHybridData[i][0][1],
+- hParametricStereo->pHybridData[hParametricStereo->noQmfSlots + i][0][1],
+- MAX_HYBRID_BANDS * sizeof(FIXP_DBL)); /* left, imag */
+- FDKmemcpy(
+- hParametricStereo->pHybridData[i][1][0],
+- hParametricStereo->pHybridData[hParametricStereo->noQmfSlots + i][1][0],
+- MAX_HYBRID_BANDS * sizeof(FIXP_DBL)); /* right, real */
+- FDKmemcpy(
+- hParametricStereo->pHybridData[i][1][1],
+- hParametricStereo->pHybridData[hParametricStereo->noQmfSlots + i][1][1],
+- MAX_HYBRID_BANDS * sizeof(FIXP_DBL)); /* right, imag */
+- }
+-
+- /* downmix and hybrid synthesis */
+- if (PSENC_OK !=
+- (error = DownmixPSQmfData(
+- hParametricStereo, sbrSynthQmf, downmixedRealQmfData,
+- downmixedImagQmfData, downsampledOutSignal, samplesBufSize,
+- &hParametricStereo->pHybridData[HYBRID_READ_OFFSET],
+- hParametricStereo->noQmfSlots, psQmfScale, qmfScale))) {
+- goto bail;
+- }
+-
+-bail:
+-
+- return error;
+-}
+-
+-static void psFindBestScaling(
+- HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- FIXP_DBL *hybridData[HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2],
+- UCHAR *dynBandScale, FIXP_DBL *maxBandValue, SCHAR *dmxScale) {
+- HANDLE_PS_ENCODE hPsEncode = hParametricStereo->hPsEncode;
+-
+- INT group, bin, col, band;
+- const INT frameSize = hParametricStereo->noQmfSlots;
+- const INT psBands = (INT)hPsEncode->psEncMode;
+- const INT nIidGroups = hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups;
+-
+- /* group wise scaling */
+- FIXP_DBL maxVal[2][PS_MAX_BANDS];
+- FIXP_DBL maxValue = FL2FXCONST_DBL(0.f);
+-
+- FDKmemclear(maxVal, sizeof(maxVal));
+-
+- /* start with hybrid data */
+- for (group = 0; group < nIidGroups; group++) {
+- /* Translate group to bin */
+- bin = hPsEncode->subband2parameterIndex[group];
+-
+- /* Translate from 20 bins to 10 bins */
+- if (hPsEncode->psEncMode == PS_BANDS_COARSE) {
+- bin >>= 1;
+- }
+-
+- /* QMF downmix scaling */
+- for (col = 0; col < frameSize; col++) {
+- int i, section = (col < frameSize - HYBRID_READ_OFFSET) ? 0 : 1;
+- FIXP_DBL tmp = maxVal[section][bin];
+- for (i = hPsEncode->iidGroupBorders[group];
+- i < hPsEncode->iidGroupBorders[group + 1]; i++) {
+- tmp = fixMax(tmp, (FIXP_DBL)fixp_abs(hybridData[col][0][0][i]));
+- tmp = fixMax(tmp, (FIXP_DBL)fixp_abs(hybridData[col][0][1][i]));
+- tmp = fixMax(tmp, (FIXP_DBL)fixp_abs(hybridData[col][1][0][i]));
+- tmp = fixMax(tmp, (FIXP_DBL)fixp_abs(hybridData[col][1][1][i]));
+- }
+- maxVal[section][bin] = tmp;
+- }
+- } /* nIidGroups */
+-
+- /* convert maxSpec to maxScaling, find scaling space */
+- for (band = 0; band < psBands; band++) {
+-#ifndef MULT_16x16
+- dynBandScale[band] =
+- CountLeadingBits(fixMax(maxVal[0][band], maxBandValue[band]));
+-#else
+- dynBandScale[band] = fixMax(
+- 0, CountLeadingBits(fixMax(maxVal[0][band], maxBandValue[band])) -
+- FRACT_BITS);
+-#endif
+- maxValue = fixMax(maxValue, fixMax(maxVal[0][band], maxVal[1][band]));
+- maxBandValue[band] = fixMax(maxVal[0][band], maxVal[1][band]);
+- }
+-
+- /* calculate maximal scaling for QMF downmix */
+-#ifndef MULT_16x16
+- *dmxScale = fixMin(DFRACT_BITS, CountLeadingBits(maxValue));
+-#else
+- *dmxScale = fixMax(0, fixMin(FRACT_BITS, CountLeadingBits((maxValue))));
+-#endif
+-}
+diff --git a/libSBRenc/src/ps_main.h b/libSBRenc/src/ps_main.h
+deleted file mode 100644
+index 88b2993..0000000
+--- a/libSBRenc/src/ps_main.h
++++ /dev/null
+@@ -1,270 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): Markus Multrus
+-
+- Description: PS Wrapper, Downmix header file
+-
+-*******************************************************************************/
+-
+-#ifndef PS_MAIN_H
+-#define PS_MAIN_H
+-
+-/* Includes ******************************************************************/
+-
+-#include "sbr_def.h"
+-#include "qmf.h"
+-#include "ps_encode.h"
+-#include "FDK_bitstream.h"
+-#include "FDK_hybrid.h"
+-
+-/* Data Types ****************************************************************/
+-typedef enum {
+- PSENC_STEREO_BANDS_INVALID = 0,
+- PSENC_STEREO_BANDS_10 = 10,
+- PSENC_STEREO_BANDS_20 = 20
+-
+-} PSENC_STEREO_BANDS_CONFIG;
+-
+-typedef enum {
+- PSENC_NENV_1 = 1,
+- PSENC_NENV_2 = 2,
+- PSENC_NENV_4 = 4,
+- PSENC_NENV_DEFAULT = PSENC_NENV_2,
+- PSENC_NENV_MAX = PSENC_NENV_4
+-
+-} PSENC_NENV_CONFIG;
+-
+-typedef struct {
+- UINT bitrateFrom; /* inclusive */
+- UINT bitrateTo; /* exclusive */
+- PSENC_STEREO_BANDS_CONFIG nStereoBands;
+- PSENC_NENV_CONFIG nEnvelopes;
+- LONG iidQuantErrorThreshold; /* quantization threshold to switch between
+- coarse and fine iid quantization */
+-
+-} psTuningTable_t;
+-
+-/* Function / Class Declarations *********************************************/
+-
+-typedef struct T_PARAMETRIC_STEREO {
+- HANDLE_PS_ENCODE hPsEncode;
+- PS_OUT psOut[2];
+-
+- FIXP_DBL __staticHybridData[HYBRID_READ_OFFSET][MAX_PS_CHANNELS][2]
+- [MAX_HYBRID_BANDS];
+- FIXP_DBL
+- *pHybridData[HYBRID_READ_OFFSET + HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2];
+-
+- FIXP_DBL qmfDelayLines[2][32 >> 1][64];
+- int qmfDelayScale;
+-
+- INT psDelay;
+- UINT maxEnvelopes;
+- UCHAR dynBandScale[PS_MAX_BANDS];
+- FIXP_DBL maxBandValue[PS_MAX_BANDS];
+- SCHAR dmxScale;
+- INT initPS;
+- INT noQmfSlots;
+- INT noQmfBands;
+-
+- FIXP_DBL __staticHybAnaStatesLF[MAX_PS_CHANNELS][2 * HYBRID_FILTER_LENGTH *
+- HYBRID_MAX_QMF_BANDS];
+- FIXP_DBL __staticHybAnaStatesHF[MAX_PS_CHANNELS][2 * HYBRID_FILTER_DELAY *
+- (64 - HYBRID_MAX_QMF_BANDS)];
+- FDK_ANA_HYB_FILTER fdkHybAnaFilter[MAX_PS_CHANNELS];
+- FDK_SYN_HYB_FILTER fdkHybSynFilter;
+-
+-} PARAMETRIC_STEREO;
+-
+-typedef struct T_PSENC_CONFIG {
+- INT frameSize;
+- INT qmfFilterMode;
+- INT sbrPsDelay;
+- PSENC_STEREO_BANDS_CONFIG nStereoBands;
+- PSENC_NENV_CONFIG maxEnvelopes;
+- FIXP_DBL iidQuantErrorThreshold;
+-
+-} PSENC_CONFIG, *HANDLE_PSENC_CONFIG;
+-
+-typedef struct T_PARAMETRIC_STEREO *HANDLE_PARAMETRIC_STEREO;
+-
+-/**
+- * \brief Create a parametric stereo encoder instance.
+- *
+- * \param phParametricStereo A pointer to a parametric stereo handle to be
+- * allocated. Initialized on return.
+- *
+- * \return
+- * - PSENC_OK, on succes.
+- * - PSENC_INVALID_HANDLE, PSENC_MEMORY_ERROR, on failure.
+- */
+-FDK_PSENC_ERROR PSEnc_Create(HANDLE_PARAMETRIC_STEREO *phParametricStereo);
+-
+-/**
+- * \brief Initialize a parametric stereo encoder instance.
+- *
+- * \param hParametricStereo Meta Data handle.
+- * \param hPsEncConfig Filled parametric stereo configuration
+- * structure.
+- * \param noQmfSlots Number of slots within one audio frame.
+- * \param noQmfBands Number of QMF bands.
+- * \param dynamic_RAM Pointer to preallocated workbuffer.
+- *
+- * \return
+- * - PSENC_OK, on succes.
+- * - PSENC_INVALID_HANDLE, PSENC_INIT_ERROR, on failure.
+- */
+-FDK_PSENC_ERROR PSEnc_Init(HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- const HANDLE_PSENC_CONFIG hPsEncConfig,
+- INT noQmfSlots, INT noQmfBands, UCHAR *dynamic_RAM);
+-
+-/**
+- * \brief Destroy parametric stereo encoder instance.
+- *
+- * Deallocate instance and free whole memory.
+- *
+- * \param phParametricStereo Pointer to the parametric stereo handle to be
+- * deallocated.
+- *
+- * \return
+- * - PSENC_OK, on succes.
+- * - PSENC_INVALID_HANDLE, on failure.
+- */
+-FDK_PSENC_ERROR PSEnc_Destroy(HANDLE_PARAMETRIC_STEREO *phParametricStereo);
+-
+-/**
+- * \brief Apply parametric stereo processing.
+- *
+- * \param hParametricStereo Meta Data handle.
+- * \param samples Pointer to 2 channel audio input signal.
+- * \param timeInStride, Stride factor of input buffer.
+- * \param hQmfAnalysis, Pointer to QMF analysis filterbanks.
+- * \param downmixedRealQmfData Pointer to real QMF buffer to be written to.
+- * \param downmixedImagQmfData Pointer to imag QMF buffer to be written to.
+- * \param downsampledOutSignal Pointer to buffer where to write downmixed
+- * timesignal.
+- * \param sbrSynthQmf Pointer to QMF synthesis filterbank.
+- * \param qmfScale Return scaling factor of the qmf data.
+- * \param sendHeader Signal whether to write header data.
+- *
+- * \return
+- * - PSENC_OK, on succes.
+- * - PSENC_INVALID_HANDLE, PSENC_ENCODE_ERROR, on failure.
+- */
+-FDK_PSENC_ERROR FDKsbrEnc_PSEnc_ParametricStereoProcessing(
+- HANDLE_PARAMETRIC_STEREO hParametricStereo, INT_PCM *samples[2],
+- UINT timeInStride, QMF_FILTER_BANK **hQmfAnalysis,
+- FIXP_DBL **RESTRICT downmixedRealQmfData,
+- FIXP_DBL **RESTRICT downmixedImagQmfData, INT_PCM *downsampledOutSignal,
+- HANDLE_QMF_FILTER_BANK sbrSynthQmf, SCHAR *qmfScale, const int sendHeader);
+-
+-/**
+- * \brief Write parametric stereo bitstream.
+- *
+- * Write ps_data() element to bitstream and return number of written bits.
+- * Returns number of written bits only, if hBitstream == NULL.
+- *
+- * \param hParametricStereo Meta Data handle.
+- * \param hBitstream Bitstream buffer handle.
+- *
+- * \return
+- * - number of written bits.
+- */
+-INT FDKsbrEnc_PSEnc_WritePSData(HANDLE_PARAMETRIC_STEREO hParametricStereo,
+- HANDLE_FDK_BITSTREAM hBitstream);
+-
+-#endif /* PS_MAIN_H */
+diff --git a/libSBRenc/src/resampler.cpp b/libSBRenc/src/resampler.cpp
+deleted file mode 100644
+index b1781a7..0000000
+--- a/libSBRenc/src/resampler.cpp
++++ /dev/null
+@@ -1,444 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief FDK resampler tool box:$Revision: 91655 $
+- \author M. Werner
+-*/
+-
+-#include "resampler.h"
+-
+-#include "genericStds.h"
+-
+-/**************************************************************************/
+-/* BIQUAD Filter Specifications */
+-/**************************************************************************/
+-
+-#define B1 0
+-#define B2 1
+-#define A1 2
+-#define A2 3
+-
+-#define BQC(x) FL2FXCONST_SGL(x / 2)
+-
+-struct FILTER_PARAM {
+- const FIXP_SGL *coeffa; /*! SOS matrix One row/section. Scaled using BQC().
+- Order of coefficients: B1,B2,A1,A2. B0=A0=1.0 */
+- FIXP_DBL g; /*! overall gain */
+- int Wc; /*! normalized passband bandwidth at input samplerate * 1000 */
+- int noCoeffs; /*! number of filter coeffs */
+- int delay; /*! delay in samples at input samplerate */
+-};
+-
+-#define BIQUAD_COEFSTEP 4
+-
+-/**
+- *\brief Low Pass
+- Wc = 0,5, order 30, Stop Band -96dB. Wc criteria is "almost 0dB passband", not
+- the usual -3db gain point. [b,a]=cheby2(30,96,0.505) [sos,g]=tf2sos(b,a)
+- bandwidth 0.48
+- */
+-static const FIXP_SGL sos48[] = {
+- BQC(1.98941075681938), BQC(0.999999996890811),
+- BQC(0.863264527201963), BQC(0.189553799960663),
+- BQC(1.90733804822445), BQC(1.00000001736189),
+- BQC(0.836321575841691), BQC(0.203505809266564),
+- BQC(1.75616665495325), BQC(0.999999946079721),
+- BQC(0.784699225121588), BQC(0.230471265506986),
+- BQC(1.55727745512726), BQC(1.00000011737815),
+- BQC(0.712515423588351), BQC(0.268752723900498),
+- BQC(1.33407591943643), BQC(0.999999795953228),
+- BQC(0.625059117330989), BQC(0.316194685288965),
+- BQC(1.10689898412458), BQC(1.00000035057114),
+- BQC(0.52803514366398), BQC(0.370517843224669),
+- BQC(0.89060371078454), BQC(0.999999343962822),
+- BQC(0.426920462165257), BQC(0.429608200207746),
+- BQC(0.694438261209433), BQC(1.0000008629792),
+- BQC(0.326530699561716), BQC(0.491714450654174),
+- BQC(0.523237800935322), BQC(1.00000101349782),
+- BQC(0.230829556274851), BQC(0.555559034843281),
+- BQC(0.378631165929563), BQC(0.99998986482665),
+- BQC(0.142906422036095), BQC(0.620338874442411),
+- BQC(0.260786911308437), BQC(1.00003261460178),
+- BQC(0.0651008576256505), BQC(0.685759923926262),
+- BQC(0.168409429188098), BQC(0.999933049695828),
+- BQC(-0.000790067789975562), BQC(0.751905896602325),
+- BQC(0.100724533818628), BQC(1.00009472669872),
+- BQC(-0.0533772830257041), BQC(0.81930744384525),
+- BQC(0.0561434357867363), BQC(0.999911636304276),
+- BQC(-0.0913550299236405), BQC(0.88883625875915),
+- BQC(0.0341680678662057), BQC(1.00003667508676),
+- BQC(-0.113405185536697), BQC(0.961756638268446)};
+-
+-static const FIXP_DBL g48 =
+- FL2FXCONST_DBL(0.002712866530047) - (FIXP_DBL)0x8000;
+-
+-static const struct FILTER_PARAM param_set48 = {
+- sos48, g48, 480, 15, 4 /* LF 2 */
+-};
+-
+-/**
+- *\brief Low Pass
+- Wc = 0,5, order 24, Stop Band -96dB. Wc criteria is "almost 0dB passband", not
+- the usual -3db gain point. [b,a]=cheby2(24,96,0.5) [sos,g]=tf2sos(b,a)
+- bandwidth 0.45
+- */
+-static const FIXP_SGL sos45[] = {
+- BQC(1.982962601444), BQC(1.00000000007504), BQC(0.646113303737836),
+- BQC(0.10851149979981), BQC(1.85334094281111), BQC(0.999999999677192),
+- BQC(0.612073220102006), BQC(0.130022141698044), BQC(1.62541051415425),
+- BQC(1.00000000080398), BQC(0.547879702855959), BQC(0.171165825133192),
+- BQC(1.34554656923247), BQC(0.9999999980169), BQC(0.460373914508491),
+- BQC(0.228677463376354), BQC(1.05656568503116), BQC(1.00000000569363),
+- BQC(0.357891894038287), BQC(0.298676843912185), BQC(0.787967587877312),
+- BQC(0.999999984415017), BQC(0.248826893211877), BQC(0.377441803512978),
+- BQC(0.555480971120497), BQC(1.00000003583307), BQC(0.140614263345315),
+- BQC(0.461979302213679), BQC(0.364986207070964), BQC(0.999999932084303),
+- BQC(0.0392669446074516), BQC(0.55033451180825), BQC(0.216827267631558),
+- BQC(1.00000010534682), BQC(-0.0506232228865103), BQC(0.641691581560946),
+- BQC(0.108951672277119), BQC(0.999999871167516), BQC(-0.125584840183225),
+- BQC(0.736367748771803), BQC(0.0387988607229035), BQC(1.00000011205574),
+- BQC(-0.182814849097974), BQC(0.835802108714964), BQC(0.0042866175809225),
+- BQC(0.999999954830813), BQC(-0.21965740617151), BQC(0.942623047782363)};
+-
+-static const FIXP_DBL g45 =
+- FL2FXCONST_DBL(0.00242743980909524) - (FIXP_DBL)0x8000;
+-
+-static const struct FILTER_PARAM param_set45 = {
+- sos45, g45, 450, 12, 4 /* LF 2 */
+-};
+-
+-/*
+- Created by Octave 2.1.73, Mon Oct 13 17:31:32 2008 CEST
+- Wc = 0,5, order 16, Stop Band -96dB damping.
+- [b,a]=cheby2(16,96,0.5)
+- [sos,g]=tf2sos(b,a)
+- bandwidth = 0.41
+- */
+-
+-static const FIXP_SGL sos41[] = {
+- BQC(1.96193625292), BQC(0.999999999999964), BQC(0.169266178786789),
+- BQC(0.0128823300475907), BQC(1.68913437662092), BQC(1.00000000000053),
+- BQC(0.124751503206552), BQC(0.0537472273950989), BQC(1.27274692366017),
+- BQC(0.999999999995674), BQC(0.0433108625178357), BQC(0.131015753236317),
+- BQC(0.85214175088395), BQC(1.00000000001813), BQC(-0.0625658152550408),
+- BQC(0.237763778993806), BQC(0.503841579939009), BQC(0.999999999953223),
+- BQC(-0.179176128722865), BQC(0.367475236424474), BQC(0.249990711986162),
+- BQC(1.00000000007952), BQC(-0.294425165824676), BQC(0.516594857170212),
+- BQC(0.087971668680286), BQC(0.999999999915528), BQC(-0.398956566777928),
+- BQC(0.686417767801123), BQC(0.00965373325350294), BQC(1.00000000003744),
+- BQC(-0.48579173764817), BQC(0.884931534239068)};
+-
+-static const FIXP_DBL g41 = FL2FXCONST_DBL(0.00155956951169248);
+-
+-static const struct FILTER_PARAM param_set41 = {
+- sos41, g41, 410, 8, 5 /* LF 3 */
+-};
+-
+-/*
+- # Created by Octave 2.1.73, Mon Oct 13 17:55:33 2008 CEST
+- Wc = 0,5, order 12, Stop Band -96dB damping.
+- [b,a]=cheby2(12,96,0.5);
+- [sos,g]=tf2sos(b,a)
+-*/
+-static const FIXP_SGL sos35[] = {
+- BQC(1.93299325235762), BQC(0.999999999999985), BQC(-0.140733187246596),
+- BQC(0.0124139497836062), BQC(1.4890416764109), BQC(1.00000000000011),
+- BQC(-0.198215402588504), BQC(0.0746730616584138), BQC(0.918450161309795),
+- BQC(0.999999999999619), BQC(-0.30133912791941), BQC(0.192276468839529),
+- BQC(0.454877024246818), BQC(1.00000000000086), BQC(-0.432337328809815),
+- BQC(0.356852933642815), BQC(0.158017147118507), BQC(0.999999999998876),
+- BQC(-0.574817494249777), BQC(0.566380436970833), BQC(0.0171834649478749),
+- BQC(1.00000000000055), BQC(-0.718581178041165), BQC(0.83367484487889)};
+-
+-static const FIXP_DBL g35 = FL2FXCONST_DBL(0.00162580994125131);
+-
+-static const struct FILTER_PARAM param_set35 = {sos35, g35, 350, 6, 4};
+-
+-/*
+- # Created by Octave 2.1.73, Mon Oct 13 18:15:38 2008 CEST
+- Wc = 0,5, order 8, Stop Band -96dB damping.
+- [b,a]=cheby2(8,96,0.5);
+- [sos,g]=tf2sos(b,a)
+-*/
+-static const FIXP_SGL sos25[] = {
+- BQC(1.85334094301225), BQC(1.0),
+- BQC(-0.702127214212663), BQC(0.132452403998767),
+- BQC(1.056565682167), BQC(0.999999999999997),
+- BQC(-0.789503667880785), BQC(0.236328693569128),
+- BQC(0.364986307455489), BQC(0.999999999999996),
+- BQC(-0.955191189843375), BQC(0.442966457936379),
+- BQC(0.0387985751642125), BQC(1.0),
+- BQC(-1.19817786088084), BQC(0.770493895456328)};
+-
+-static const FIXP_DBL g25 = FL2FXCONST_DBL(0.000945182835294559);
+-
+-static const struct FILTER_PARAM param_set25 = {sos25, g25, 250, 4, 5};
+-
+-/* Must be sorted in descending order */
+-static const struct FILTER_PARAM *const filter_paramSet[] = {
+- ¶m_set48, ¶m_set45, ¶m_set41, ¶m_set35, ¶m_set25};
+-
+-/**************************************************************************/
+-/* Resampler Functions */
+-/**************************************************************************/
+-
+-/*!
+- \brief Reset downsampler instance and clear delay lines
+-
+- \return success of operation
+-*/
+-
+-INT FDKaacEnc_InitDownsampler(
+- DOWNSAMPLER *DownSampler, /*!< pointer to downsampler instance */
+- int Wc, /*!< normalized cutoff freq * 1000* */
+- int ratio) /*!< downsampler ratio */
+-
+-{
+- UINT i;
+- const struct FILTER_PARAM *currentSet = NULL;
+-
+- FDKmemclear(DownSampler->downFilter.states,
+- sizeof(DownSampler->downFilter.states));
+- DownSampler->downFilter.ptr = 0;
+-
+- /*
+- find applicable parameter set
+- */
+- currentSet = filter_paramSet[0];
+- for (i = 1; i < sizeof(filter_paramSet) / sizeof(struct FILTER_PARAM *);
+- i++) {
+- if (filter_paramSet[i]->Wc <= Wc) {
+- break;
+- }
+- currentSet = filter_paramSet[i];
+- }
+-
+- DownSampler->downFilter.coeffa = currentSet->coeffa;
+-
+- DownSampler->downFilter.gain = currentSet->g;
+- FDK_ASSERT(currentSet->noCoeffs <= MAXNR_SECTIONS * 2);
+-
+- DownSampler->downFilter.noCoeffs = currentSet->noCoeffs;
+- DownSampler->delay = currentSet->delay;
+- DownSampler->downFilter.Wc = currentSet->Wc;
+-
+- DownSampler->ratio = ratio;
+- DownSampler->pending = ratio - 1;
+- return (1);
+-}
+-
+-/*!
+- \brief faster simple folding operation
+- Filter:
+- H(z) = A(z)/B(z)
+- with
+- A(z) = a[0]*z^0 + a[1]*z^1 + a[2]*z^2 ... a[n]*z^n
+-
+- \return filtered value
+-*/
+-
+-static inline INT_PCM AdvanceFilter(
+- LP_FILTER *downFilter, /*!< pointer to iir filter instance */
+- INT_PCM *pInput, /*!< input of filter */
+- int downRatio) {
+- INT_PCM output;
+- int i, n;
+-
+-#define BIQUAD_SCALE 12
+-
+- FIXP_DBL y = FL2FXCONST_DBL(0.0f);
+- FIXP_DBL input;
+-
+- for (n = 0; n < downRatio; n++) {
+- FIXP_BQS(*states)[2] = downFilter->states;
+- const FIXP_SGL *coeff = downFilter->coeffa;
+- int s1, s2;
+-
+- s1 = downFilter->ptr;
+- s2 = s1 ^ 1;
+-
+-#if (SAMPLE_BITS == 16)
+- input = ((FIXP_DBL)pInput[n]) << (DFRACT_BITS - SAMPLE_BITS - BIQUAD_SCALE);
+-#elif (SAMPLE_BITS == 32)
+- input = pInput[n] >> BIQUAD_SCALE;
+-#else
+-#error NOT IMPLEMENTED
+-#endif
+-
+- FIXP_BQS state1, state2, state1b, state2b;
+-
+- state1 = states[0][s1];
+- state2 = states[0][s2];
+-
+- /* Loop over sections */
+- for (i = 0; i < downFilter->noCoeffs; i++) {
+- FIXP_DBL state0;
+-
+- /* Load merged states (from next section) */
+- state1b = states[i + 1][s1];
+- state2b = states[i + 1][s2];
+-
+- state0 = input + fMult(state1, coeff[B1]) + fMult(state2, coeff[B2]);
+- y = state0 - fMult(state1b, coeff[A1]) - fMult(state2b, coeff[A2]);
+-
+- /* Store new feed forward merge state */
+- states[i + 1][s2] = y << 1;
+- /* Store new feed backward state */
+- states[i][s2] = input << 1;
+-
+- /* Feedback output to next section. */
+- input = y;
+-
+- /* Transfer merged states */
+- state1 = state1b;
+- state2 = state2b;
+-
+- /* Step to next coef set */
+- coeff += BIQUAD_COEFSTEP;
+- }
+- downFilter->ptr ^= 1;
+- }
+- /* Apply global gain */
+- y = fMult(y, downFilter->gain);
+-
+- /* Apply final gain/scaling to output */
+-#if (SAMPLE_BITS == 16)
+- output = (INT_PCM)SATURATE_RIGHT_SHIFT(
+- y + (FIXP_DBL)(1 << (DFRACT_BITS - SAMPLE_BITS - BIQUAD_SCALE - 1)),
+- DFRACT_BITS - SAMPLE_BITS - BIQUAD_SCALE, SAMPLE_BITS);
+- // output = (INT_PCM) SATURATE_RIGHT_SHIFT(y,
+- // DFRACT_BITS-SAMPLE_BITS-BIQUAD_SCALE, SAMPLE_BITS);
+-#else
+- output = SATURATE_LEFT_SHIFT(y, BIQUAD_SCALE, SAMPLE_BITS);
+-#endif
+-
+- return output;
+-}
+-
+-/*!
+- \brief FDKaacEnc_Downsample numInSamples of type INT_PCM
+- Returns number of output samples in numOutSamples
+-
+- \return success of operation
+-*/
+-
+-INT FDKaacEnc_Downsample(
+- DOWNSAMPLER *DownSampler, /*!< pointer to downsampler instance */
+- INT_PCM *inSamples, /*!< pointer to input samples */
+- INT numInSamples, /*!< number of input samples */
+- INT_PCM *outSamples, /*!< pointer to output samples */
+- INT *numOutSamples /*!< pointer tp number of output samples */
+-) {
+- INT i;
+- *numOutSamples = 0;
+-
+- for (i = 0; i < numInSamples; i += DownSampler->ratio) {
+- *outSamples = AdvanceFilter(&(DownSampler->downFilter), &inSamples[i],
+- DownSampler->ratio);
+- outSamples++;
+- }
+- *numOutSamples = numInSamples / DownSampler->ratio;
+-
+- return 0;
+-}
+diff --git a/libSBRenc/src/resampler.h b/libSBRenc/src/resampler.h
+deleted file mode 100644
+index 7aa1cae..0000000
+--- a/libSBRenc/src/resampler.h
++++ /dev/null
+@@ -1,159 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#ifndef RESAMPLER_H
+-#define RESAMPLER_H
+-/*!
+- \file
+- \brief Fixed Point Resampler Tool Box $Revision: 92790 $
+-*/
+-
+-#include "common_fix.h"
+-
+-/**************************************************************************/
+-/* BIQUAD Filter Structure */
+-/**************************************************************************/
+-
+-#define MAXNR_SECTIONS (15)
+-
+-typedef FIXP_DBL FIXP_BQS;
+-
+-typedef struct {
+- FIXP_BQS states[MAXNR_SECTIONS + 1][2]; /*! state buffer */
+- const FIXP_SGL *coeffa; /*! pointer to filter coeffs */
+- FIXP_DBL gain; /*! overall gain factor */
+- int Wc; /*! normalized cutoff freq * 1000 */
+- int noCoeffs; /*! number of filter coeffs sets */
+- int ptr; /*! index to rinbuffers */
+-} LP_FILTER;
+-
+-/**************************************************************************/
+-/* Downsampler Structure */
+-/**************************************************************************/
+-
+-typedef struct {
+- LP_FILTER downFilter; /*! filter instance */
+- int ratio; /*! downsampling ration */
+- int delay; /*! downsampling delay (source fs) */
+- int pending; /*! number of pending output samples */
+-} DOWNSAMPLER;
+-
+-/**
+- * \brief Initialized a given downsampler structure.
+- */
+-INT FDKaacEnc_InitDownsampler(
+- DOWNSAMPLER *DownSampler, /*!< pointer to downsampler instance */
+- INT Wc, /*!< normalized cutoff freq * 1000 */
+- INT ratio); /*!< downsampler ratio */
+-
+-/**
+- * \brief Downsample a set of audio samples. numInSamples must be at least equal
+- * to the downsampler ratio.
+- */
+-INT FDKaacEnc_Downsample(
+- DOWNSAMPLER *DownSampler, /*!< pointer to downsampler instance */
+- INT_PCM *inSamples, /*!< pointer to input samples */
+- INT numInSamples, /*!< number of input samples */
+- INT_PCM *outSamples, /*!< pointer to output samples */
+- INT *numOutSamples); /*!< pointer tp number of output samples */
+-
+-#endif /* RESAMPLER_H */
+diff --git a/libSBRenc/src/sbr.h b/libSBRenc/src/sbr.h
+deleted file mode 100644
+index 341dcab..0000000
+--- a/libSBRenc/src/sbr.h
++++ /dev/null
+@@ -1,194 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Main SBR structs definitions $Revision: 92790 $
+-*/
+-
+-#ifndef SBR_H
+-#define SBR_H
+-
+-#include "fram_gen.h"
+-#include "bit_sbr.h"
+-#include "tran_det.h"
+-#include "code_env.h"
+-#include "env_est.h"
+-#include "cmondata.h"
+-
+-#include "qmf.h"
+-#include "resampler.h"
+-
+-#include "ton_corr.h"
+-
+-/* SBR bitstream delay */
+-#define MAX_DELAY_FRAMES 2
+-
+-/* sbr encoder downsampling type */
+-typedef enum { SBRENC_DS_NONE, SBRENC_DS_TIME, SBRENC_DS_QMF } SBRENC_DS_TYPE;
+-
+-typedef struct SBR_CHANNEL {
+- struct ENV_CHANNEL hEnvChannel;
+- // INT_PCM *pDSOutBuffer; /**< Pointer to
+- // downsampled audio output of SBR encoder */
+- DOWNSAMPLER downSampler;
+-
+-} SBR_CHANNEL;
+-typedef SBR_CHANNEL* HANDLE_SBR_CHANNEL;
+-
+-typedef struct SBR_ELEMENT {
+- HANDLE_SBR_CHANNEL sbrChannel[2];
+- QMF_FILTER_BANK* hQmfAnalysis[2];
+- SBR_CONFIG_DATA sbrConfigData;
+- SBR_HEADER_DATA sbrHeaderData;
+- SBR_BITSTREAM_DATA sbrBitstreamData;
+- COMMON_DATA CmonData;
+- INT dynXOverFreqDelay[5]; /**< to delay a frame (I don't like it that much
+- that way - hrc) */
+- SBR_ELEMENT_INFO elInfo;
+-
+- UCHAR payloadDelayLine[1 + MAX_DELAY_FRAMES][MAX_PAYLOAD_SIZE];
+- UINT payloadDelayLineSize[1 + MAX_DELAY_FRAMES]; /* Sizes in bits */
+-
+-} SBR_ELEMENT, *HANDLE_SBR_ELEMENT;
+-
+-typedef struct SBR_ENCODER {
+- HANDLE_SBR_ELEMENT sbrElement[(8)];
+- HANDLE_SBR_CHANNEL pSbrChannel[(8)];
+- QMF_FILTER_BANK QmfAnalysis[(8)];
+- DOWNSAMPLER lfeDownSampler;
+- int lfeChIdx; /* -1 default for no lfe, else assign channel index. */
+- int noElements; /* Number of elements. */
+- int nChannels; /* Total channel count across all elements. */
+- int frameSize; /* SBR framelength. */
+- int bufferOffset; /* Offset for SBR parameter extraction in time domain input
+- buffer. */
+- int downsampledOffset; /* Offset of downsampled/mixed output for core encoder.
+- */
+- int downmixSize; /* Size in samples of downsampled/mixed output for core
+- encoder. */
+- INT downSampleFactor; /* Sampling rate relation between the SBR and the core
+- encoder. */
+- SBRENC_DS_TYPE
+- downsamplingMethod; /* Method of downsmapling, time-domain, QMF or none.
+- */
+- int nBitstrDelay; /* Amount of SBR frames to be delayed in bitstream domain.
+- */
+- int sbrDecDelay; /* SBR decoder delay in samples */
+- INT estimateBitrate; /* Estimate bitrate of SBR encoder. */
+- INT inputDataDelay; /* Delay caused by downsampler, in/out buffer at
+- sbrEncoder_EncodeFrame. */
+-
+- UCHAR* dynamicRam;
+- UCHAR* pSBRdynamic_RAM;
+-
+- HANDLE_PARAMETRIC_STEREO hParametricStereo;
+- QMF_FILTER_BANK qmfSynthesisPS;
+-
+- /* parameters describing allocation volume of present instance */
+- INT maxElements;
+- INT maxChannels;
+- INT supportPS;
+-
+-} SBR_ENCODER;
+-
+-#endif /* SBR_H */
+diff --git a/libSBRenc/src/sbr_def.h b/libSBRenc/src/sbr_def.h
+deleted file mode 100644
+index 53eba71..0000000
+--- a/libSBRenc/src/sbr_def.h
++++ /dev/null
+@@ -1,276 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief SBR main definitions $Revision: 92790 $
+-*/
+-#ifndef SBR_DEF_H
+-#define SBR_DEF_H
+-
+-#include "common_fix.h"
+-
+-#define noError 0
+-#define HANDLE_ERROR_INFO INT
+-#define ERROR(a, b) 1
+-
+-/* #define SBR_ENV_STATISTICS_BITRATE */
+-#undef SBR_ENV_STATISTICS_BITRATE
+-
+-/* #define SBR_ENV_STATISTICS */
+-#undef SBR_ENV_STATISTICS
+-
+-/* #define SBR_PAYLOAD_MONITOR */
+-#undef SBR_PAYLOAD_MONITOR
+-
+-#define SWAP(a, b) tempr = a, a = b, b = tempr
+-#define TRUE 1
+-#define FALSE 0
+-
+-/* Constants */
+-#define EPS 1e-12
+-#define LOG2 0.69314718056f /* natural logarithm of 2 */
+-#define ILOG2 1.442695041f /* 1/LOG2 */
+-#define RELAXATION_FLOAT (1e-6f)
+-#define RELAXATION (FL2FXCONST_DBL(RELAXATION_FLOAT))
+-#define RELAXATION_FRACT \
+- (FL2FXCONST_DBL(0.524288f)) /* 0.524288f is fractional part of RELAXATION */
+-#define RELAXATION_SHIFT (19)
+-#define RELAXATION_LD64 \
+- (FL2FXCONST_DBL(0.31143075889f)) /* (ld64(RELAXATION) \
+- */
+-
+-/************ Definitions ***************/
+-#define SBR_COMP_MODE_DELTA 0
+-#define SBR_COMP_MODE_CTS 1
+-#define SBR_MAX_ENERGY_VALUES 5
+-#define SBR_GLOBAL_TONALITY_VALUES 2
+-
+-#define MAX_NUM_CHANNELS 2
+-
+-#define MAX_NOISE_ENVELOPES 2
+-#define MAX_NUM_NOISE_COEFFS 5
+-#define MAX_NUM_NOISE_VALUES (MAX_NUM_NOISE_COEFFS * MAX_NOISE_ENVELOPES)
+-
+-#define MAX_NUM_ENVELOPE_VALUES (MAX_ENVELOPES * MAX_FREQ_COEFFS)
+-#define MAX_ENVELOPES 5
+-#define MAX_FREQ_COEFFS 48
+-
+-#define MAX_FREQ_COEFFS_FS44100 35
+-#define MAX_FREQ_COEFFS_FS48000 32
+-
+-#define NO_OF_ESTIMATES_LC 4
+-#define NO_OF_ESTIMATES_LD 3
+-#define MAX_NO_OF_ESTIMATES 4
+-
+-#define NOISE_FLOOR_OFFSET 6
+-#define NOISE_FLOOR_OFFSET_64 (FL2FXCONST_DBL(0.09375f))
+-
+-#define LOW_RES 0
+-#define HIGH_RES 1
+-
+-#define LO 0
+-#define HI 1
+-
+-#define LENGTH_SBR_FRAME_INFO 35 /* 19 */
+-
+-#define SBR_NSFB_LOW_RES 9 /* 8 */
+-#define SBR_NSFB_HIGH_RES 18 /* 16 */
+-
+-#define SBR_XPOS_CTRL_DEFAULT 2
+-
+-#define SBR_FREQ_SCALE_DEFAULT 2
+-#define SBR_ALTER_SCALE_DEFAULT 1
+-#define SBR_NOISE_BANDS_DEFAULT 2
+-
+-#define SBR_LIMITER_BANDS_DEFAULT 2
+-#define SBR_LIMITER_GAINS_DEFAULT 2
+-#define SBR_LIMITER_GAINS_INFINITE 3
+-#define SBR_INTERPOL_FREQ_DEFAULT 1
+-#define SBR_SMOOTHING_LENGTH_DEFAULT 0
+-
+-/* sbr_header */
+-#define SI_SBR_AMP_RES_BITS 1
+-#define SI_SBR_COUPLING_BITS 1
+-#define SI_SBR_START_FREQ_BITS 4
+-#define SI_SBR_STOP_FREQ_BITS 4
+-#define SI_SBR_XOVER_BAND_BITS 3
+-#define SI_SBR_RESERVED_BITS 2
+-#define SI_SBR_DATA_EXTRA_BITS 1
+-#define SI_SBR_HEADER_EXTRA_1_BITS 1
+-#define SI_SBR_HEADER_EXTRA_2_BITS 1
+-
+-/* sbr_header extra 1 */
+-#define SI_SBR_FREQ_SCALE_BITS 2
+-#define SI_SBR_ALTER_SCALE_BITS 1
+-#define SI_SBR_NOISE_BANDS_BITS 2
+-
+-/* sbr_header extra 2 */
+-#define SI_SBR_LIMITER_BANDS_BITS 2
+-#define SI_SBR_LIMITER_GAINS_BITS 2
+-#define SI_SBR_INTERPOL_FREQ_BITS 1
+-#define SI_SBR_SMOOTHING_LENGTH_BITS 1
+-
+-/* sbr_grid */
+-#define SBR_CLA_BITS 2 /*!< size of bs_frame_class */
+-#define SBR_CLA_BITS_LD 1 /*!< size of bs_frame_class */
+-#define SBR_ENV_BITS 2 /*!< size of bs_num_env_raw */
+-#define SBR_ABS_BITS 2 /*!< size of bs_abs_bord_raw for HE-AAC */
+-#define SBR_NUM_BITS 2 /*!< size of bs_num_rel */
+-#define SBR_REL_BITS 2 /*!< size of bs_rel_bord_raw */
+-#define SBR_RES_BITS 1 /*!< size of bs_freq_res_flag */
+-#define SBR_DIR_BITS 1 /*!< size of bs_df_flag */
+-
+-/* sbr_data */
+-#define SI_SBR_INVF_MODE_BITS 2
+-
+-#define SI_SBR_START_ENV_BITS_AMP_RES_3_0 6
+-#define SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_3_0 5
+-#define SI_SBR_START_NOISE_BITS_AMP_RES_3_0 5
+-#define SI_SBR_START_NOISE_BITS_BALANCE_AMP_RES_3_0 5
+-
+-#define SI_SBR_START_ENV_BITS_AMP_RES_1_5 7
+-#define SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_1_5 6
+-
+-#define SI_SBR_EXTENDED_DATA_BITS 1
+-#define SI_SBR_EXTENSION_SIZE_BITS 4
+-#define SI_SBR_EXTENSION_ESC_COUNT_BITS 8
+-#define SI_SBR_EXTENSION_ID_BITS 2
+-
+-#define SBR_EXTENDED_DATA_MAX_CNT (15 + 255)
+-
+-#define EXTENSION_ID_PS_CODING 2
+-
+-/* Envelope coding constants */
+-#define FREQ 0
+-#define TIME 1
+-
+-/* qmf data scaling */
+-#define QMF_SCALE_OFFSET 7
+-
+-/* huffman tables */
+-#define CODE_BOOK_SCF_LAV00 60
+-#define CODE_BOOK_SCF_LAV01 31
+-#define CODE_BOOK_SCF_LAV10 60
+-#define CODE_BOOK_SCF_LAV11 31
+-#define CODE_BOOK_SCF_LAV_BALANCE11 12
+-#define CODE_BOOK_SCF_LAV_BALANCE10 24
+-
+-typedef enum { SBR_AMP_RES_1_5 = 0, SBR_AMP_RES_3_0 } AMP_RES;
+-
+-typedef enum {
+- XPOS_MDCT,
+- XPOS_MDCT_CROSS,
+- XPOS_LC,
+- XPOS_RESERVED,
+- XPOS_SWITCHED /* not a real choice but used here to control behaviour */
+-} XPOS_MODE;
+-
+-typedef enum {
+- INVF_OFF = 0,
+- INVF_LOW_LEVEL,
+- INVF_MID_LEVEL,
+- INVF_HIGH_LEVEL,
+- INVF_SWITCHED /* not a real choice but used here to control behaviour */
+-} INVF_MODE;
+-
+-#endif
+diff --git a/libSBRenc/src/sbr_encoder.cpp b/libSBRenc/src/sbr_encoder.cpp
+deleted file mode 100644
+index df9e996..0000000
+--- a/libSBRenc/src/sbr_encoder.cpp
++++ /dev/null
+@@ -1,2577 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): Andreas Ehret, Tobias Chalupka
+-
+- Description: SBR encoder top level processing.
+-
+-*******************************************************************************/
+-
+-#include "sbr_encoder.h"
+-
+-#include "sbrenc_ram.h"
+-#include "sbrenc_rom.h"
+-#include "sbrenc_freq_sca.h"
+-#include "env_bit.h"
+-#include "cmondata.h"
+-#include "sbr_misc.h"
+-#include "sbr.h"
+-#include "qmf.h"
+-
+-#include "ps_main.h"
+-
+-#define SBRENCODER_LIB_VL0 4
+-#define SBRENCODER_LIB_VL1 0
+-#define SBRENCODER_LIB_VL2 0
+-
+-/***************************************************************************/
+-/*
+- * SBR Delay balancing definitions.
+- */
+-
+-/*
+- input buffer (1ch)
+-
+- |------------ 1537 -------------|-----|---------- 2048 -------------|
+- (core2sbr delay ) ds (read, core and ds area)
+-*/
+-
+-#define SFB(dwnsmp) \
+- (32 << (dwnsmp - \
+- 1)) /* SBR Frequency bands: 64 for dual-rate, 32 for single-rate */
+-#define STS(fl) \
+- (((fl) == 1024) ? 32 \
+- : 30) /* SBR Time Slots: 32 for core frame length 1024, 30 \
+- for core frame length 960 */
+-
+-#define DELAY_QMF_ANA(dwnsmp) \
+- ((320 << ((dwnsmp)-1)) - (32 << ((dwnsmp)-1))) /* Full bandwidth */
+-#define DELAY_HYB_ANA (10 * 64) /* + 0.5 */ /* */
+-#define DELAY_HYB_SYN (6 * 64 - 32) /* */
+-#define DELAY_QMF_POSTPROC(dwnsmp) \
+- (32 * (dwnsmp)) /* QMF postprocessing delay */
+-#define DELAY_DEC_QMF(dwnsmp) (6 * SFB(dwnsmp)) /* Decoder QMF overlap */
+-#define DELAY_QMF_SYN(dwnsmp) \
+- (1 << (dwnsmp - \
+- 1)) /* QMF_NO_POLY/2=2.5, rounded down to 2, half for single-rate */
+-#define DELAY_QMF_DS (32) /* QMF synthesis for downsampled time signal */
+-
+-/* Delay in QMF paths */
+-#define DELAY_SBR(fl, dwnsmp) \
+- (DELAY_QMF_ANA(dwnsmp) + (SFB(dwnsmp) * STS(fl) - 1) + DELAY_QMF_SYN(dwnsmp))
+-#define DELAY_PS(fl, dwnsmp) \
+- (DELAY_QMF_ANA(dwnsmp) + DELAY_HYB_ANA + DELAY_DEC_QMF(dwnsmp) + \
+- (SFB(dwnsmp) * STS(fl) - 1) + DELAY_HYB_SYN + DELAY_QMF_SYN(dwnsmp))
+-#define DELAY_ELDSBR(fl, dwnsmp) \
+- ((((fl) / 2) * (dwnsmp)) - 1 + DELAY_QMF_POSTPROC(dwnsmp))
+-#define DELAY_ELDv2SBR(fl, dwnsmp) \
+- ((((fl) / 2) * (dwnsmp)) - 1 + 80 * (dwnsmp)) /* 80 is the delay caused \
+- by the sum of the CLD \
+- analysis and the MPSLD \
+- synthesis filterbank */
+-
+-/* Delay in core path (core and downsampler not taken into account) */
+-#define DELAY_COREPATH_SBR(fl, dwnsmp) \
+- ((DELAY_QMF_ANA(dwnsmp) + DELAY_DEC_QMF(dwnsmp) + DELAY_QMF_SYN(dwnsmp)))
+-#define DELAY_COREPATH_ELDSBR(fl, dwnsmp) ((DELAY_QMF_POSTPROC(dwnsmp)))
+-#define DELAY_COREPATH_ELDv2SBR(fl, dwnsmp) (128 * (dwnsmp)) /* 4 slots */
+-#define DELAY_COREPATH_PS(fl, dwnsmp) \
+- ((DELAY_QMF_ANA(dwnsmp) + DELAY_QMF_DS + \
+- /*(DELAY_AAC(fl)*2) + */ DELAY_QMF_ANA(dwnsmp) + DELAY_DEC_QMF(dwnsmp) + \
+- DELAY_HYB_SYN + DELAY_QMF_SYN(dwnsmp))) /* 2048 - 463*2 */
+-
+-/* Delay differences between SBR- and downsampled path for SBR and SBR+PS */
+-#define DELAY_AAC2SBR(fl, dwnsmp) \
+- ((DELAY_COREPATH_SBR(fl, dwnsmp)) - DELAY_SBR((fl), (dwnsmp)))
+-#define DELAY_ELD2SBR(fl, dwnsmp) \
+- ((DELAY_COREPATH_ELDSBR(fl, dwnsmp)) - DELAY_ELDSBR(fl, dwnsmp))
+-#define DELAY_AAC2PS(fl, dwnsmp) \
+- ((DELAY_COREPATH_PS(fl, dwnsmp)) - DELAY_PS(fl, dwnsmp)) /* 2048 - 463*2 */
+-
+-/* Assumption: The sample delay resulting of of DELAY_AAC2PS is always smaller
+- * than the sample delay implied by DELAY_AAC2SBR */
+-#define MAX_DS_FILTER_DELAY \
+- (5) /* the additional max downsampler filter delay (source fs) */
+-#define MAX_SAMPLE_DELAY \
+- (DELAY_AAC2SBR(1024, 2) + MAX_DS_FILTER_DELAY) /* maximum delay: frame \
+- length of 1024 and \
+- dual-rate sbr */
+-
+-/***************************************************************************/
+-
+-/*************** Delay parameters for sbrEncoder_Init_delay() **************/
+-typedef struct {
+- int dsDelay; /* the delay of the (time-domain) downsampler itself */
+- int delay; /* overall delay / samples */
+- int sbrDecDelay; /* SBR decoder's delay */
+- int corePathOffset; /* core path offset / samples; added by
+- sbrEncoder_Init_delay() */
+- int sbrPathOffset; /* SBR path offset / samples; added by
+- sbrEncoder_Init_delay() */
+- int bitstrDelay; /* bitstream delay / frames; added by sbrEncoder_Init_delay()
+- */
+- int delayInput2Core; /* delay of the input to the core / samples */
+-} DELAY_PARAM;
+-/***************************************************************************/
+-
+-#define INVALID_TABLE_IDX -1
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Selects the SBR tuning settings to use dependent on number of
+- channels, bitrate, sample rate and core coder
+-
+- \return Index to the appropriate table
+-
+-****************************************************************************/
+-#define DISTANCE_CEIL_VALUE 5000000
+-static INT getSbrTuningTableIndex(
+- UINT bitrate, /*! the total bitrate in bits/sec */
+- UINT numChannels, /*! the number of channels for the core coder */
+- UINT sampleRate, /*! the sampling rate of the core coder */
+- AUDIO_OBJECT_TYPE core, UINT *pBitRateClosest) {
+- int i, bitRateClosestLowerIndex = -1, bitRateClosestUpperIndex = -1,
+- found = 0;
+- UINT bitRateClosestUpper = 0, bitRateClosestLower = DISTANCE_CEIL_VALUE;
+-
+-#define isForThisCore(i) \
+- ((sbrTuningTable[i].coreCoder == CODEC_AACLD && core == AOT_ER_AAC_ELD) || \
+- (sbrTuningTable[i].coreCoder == CODEC_AAC && core != AOT_ER_AAC_ELD))
+-
+- for (i = 0; i < sbrTuningTableSize; i++) {
+- if (isForThisCore(i)) /* tuning table is for this core codec */
+- {
+- if (numChannels == sbrTuningTable[i].numChannels &&
+- sampleRate == sbrTuningTable[i].sampleRate) {
+- found = 1;
+- if ((bitrate >= sbrTuningTable[i].bitrateFrom) &&
+- (bitrate < sbrTuningTable[i].bitrateTo)) {
+- return i;
+- } else {
+- if (sbrTuningTable[i].bitrateFrom > bitrate) {
+- if (sbrTuningTable[i].bitrateFrom < bitRateClosestLower) {
+- bitRateClosestLower = sbrTuningTable[i].bitrateFrom;
+- bitRateClosestLowerIndex = i;
+- }
+- }
+- if (sbrTuningTable[i].bitrateTo <= bitrate) {
+- if (sbrTuningTable[i].bitrateTo > bitRateClosestUpper) {
+- bitRateClosestUpper = sbrTuningTable[i].bitrateTo - 1;
+- bitRateClosestUpperIndex = i;
+- }
+- }
+- }
+- }
+- }
+- }
+-
+- if (bitRateClosestUpperIndex >= 0) {
+- return bitRateClosestUpperIndex;
+- }
+-
+- if (pBitRateClosest != NULL) {
+- /* If there was at least one matching tuning entry pick the least distance
+- * bit rate */
+- if (found) {
+- int distanceUpper = DISTANCE_CEIL_VALUE,
+- distanceLower = DISTANCE_CEIL_VALUE;
+- if (bitRateClosestLowerIndex >= 0) {
+- distanceLower =
+- sbrTuningTable[bitRateClosestLowerIndex].bitrateFrom - bitrate;
+- }
+- if (bitRateClosestUpperIndex >= 0) {
+- distanceUpper =
+- bitrate - sbrTuningTable[bitRateClosestUpperIndex].bitrateTo;
+- }
+- if (distanceUpper < distanceLower) {
+- *pBitRateClosest = bitRateClosestUpper;
+- } else {
+- *pBitRateClosest = bitRateClosestLower;
+- }
+- } else {
+- *pBitRateClosest = 0;
+- }
+- }
+-
+- return INVALID_TABLE_IDX;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Selects the PS tuning settings to use dependent on bitrate
+- and core coder
+-
+- \return Index to the appropriate table
+-
+-****************************************************************************/
+-static INT getPsTuningTableIndex(UINT bitrate, UINT *pBitRateClosest) {
+- INT i, paramSets = sizeof(psTuningTable) / sizeof(psTuningTable[0]);
+- int bitRateClosestLowerIndex = -1, bitRateClosestUpperIndex = -1;
+- UINT bitRateClosestUpper = 0, bitRateClosestLower = DISTANCE_CEIL_VALUE;
+-
+- for (i = 0; i < paramSets; i++) {
+- if ((bitrate >= psTuningTable[i].bitrateFrom) &&
+- (bitrate < psTuningTable[i].bitrateTo)) {
+- return i;
+- } else {
+- if (psTuningTable[i].bitrateFrom > bitrate) {
+- if (psTuningTable[i].bitrateFrom < bitRateClosestLower) {
+- bitRateClosestLower = psTuningTable[i].bitrateFrom;
+- bitRateClosestLowerIndex = i;
+- }
+- }
+- if (psTuningTable[i].bitrateTo <= bitrate) {
+- if (psTuningTable[i].bitrateTo > bitRateClosestUpper) {
+- bitRateClosestUpper = psTuningTable[i].bitrateTo - 1;
+- bitRateClosestUpperIndex = i;
+- }
+- }
+- }
+- }
+-
+- if (bitRateClosestUpperIndex >= 0) {
+- return bitRateClosestUpperIndex;
+- }
+-
+- if (pBitRateClosest != NULL) {
+- int distanceUpper = DISTANCE_CEIL_VALUE,
+- distanceLower = DISTANCE_CEIL_VALUE;
+- if (bitRateClosestLowerIndex >= 0) {
+- distanceLower =
+- sbrTuningTable[bitRateClosestLowerIndex].bitrateFrom - bitrate;
+- }
+- if (bitRateClosestUpperIndex >= 0) {
+- distanceUpper =
+- bitrate - sbrTuningTable[bitRateClosestUpperIndex].bitrateTo;
+- }
+- if (distanceUpper < distanceLower) {
+- *pBitRateClosest = bitRateClosestUpper;
+- } else {
+- *pBitRateClosest = bitRateClosestLower;
+- }
+- }
+-
+- return INVALID_TABLE_IDX;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief In case of downsampled SBR we may need to lower the stop freq
+- of a tuning setting to fit into the lower half of the
+- spectrum ( which is sampleRate/4 )
+-
+- \return the adapted stop frequency index (-1 -> error)
+-
+- \ingroup SbrEncCfg
+-
+-****************************************************************************/
+-static INT FDKsbrEnc_GetDownsampledStopFreq(const INT sampleRateCore,
+- const INT startFreq, INT stopFreq,
+- const INT downSampleFactor) {
+- INT maxStopFreqRaw = sampleRateCore / 2;
+- INT startBand, stopBand;
+- HANDLE_ERROR_INFO err;
+-
+- while (stopFreq > 0 && FDKsbrEnc_getSbrStopFreqRAW(stopFreq, sampleRateCore) >
+- maxStopFreqRaw) {
+- stopFreq--;
+- }
+-
+- if (FDKsbrEnc_getSbrStopFreqRAW(stopFreq, sampleRateCore) > maxStopFreqRaw)
+- return -1;
+-
+- err = FDKsbrEnc_FindStartAndStopBand(
+- sampleRateCore << (downSampleFactor - 1), sampleRateCore,
+- 32 << (downSampleFactor - 1), startFreq, stopFreq, &startBand, &stopBand);
+- if (err) return -1;
+-
+- return stopFreq;
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief tells us, if for the given coreCoder, bitrate, number of channels
+- and input sampling rate an SBR setting is available. If yes, it
+- tells us also the core sampling rate we would need to run with
+-
+- \return a flag indicating success: yes (1) or no (0)
+-
+-****************************************************************************/
+-static UINT FDKsbrEnc_IsSbrSettingAvail(
+- UINT bitrate, /*! the total bitrate in bits/sec */
+- UINT vbrMode, /*! the vbr paramter, 0 means constant bitrate */
+- UINT numOutputChannels, /*! the number of channels for the core coder */
+- UINT sampleRateInput, /*! the input sample rate [in Hz] */
+- UINT sampleRateCore, /*! the core's sampling rate */
+- AUDIO_OBJECT_TYPE core) {
+- INT idx = INVALID_TABLE_IDX;
+-
+- if (sampleRateInput < 16000) return 0;
+-
+- if (bitrate == 0) {
+- /* map vbr quality to bitrate */
+- if (vbrMode < 30)
+- bitrate = 24000;
+- else if (vbrMode < 40)
+- bitrate = 28000;
+- else if (vbrMode < 60)
+- bitrate = 32000;
+- else if (vbrMode < 75)
+- bitrate = 40000;
+- else
+- bitrate = 48000;
+- bitrate *= numOutputChannels;
+- }
+-
+- idx = getSbrTuningTableIndex(bitrate, numOutputChannels, sampleRateCore, core,
+- NULL);
+-
+- return (idx == INVALID_TABLE_IDX ? 0 : 1);
+-}
+-
+-/***************************************************************************/
+-/*!
+-
+- \brief Adjusts the SBR settings according to the chosen core coder
+- settings which are accessible via config->codecSettings
+-
+- \return A flag indicating success: yes (1) or no (0)
+-
+-****************************************************************************/
+-static UINT FDKsbrEnc_AdjustSbrSettings(
+- const sbrConfigurationPtr config, /*! output, modified */
+- UINT bitRate, /*! the total bitrate in bits/sec */
+- UINT numChannels, /*! the core coder number of channels */
+- UINT sampleRateCore, /*! the core coder sampling rate in Hz */
+- UINT sampleRateSbr, /*! the sbr coder sampling rate in Hz */
+- UINT transFac, /*! the short block to long block ratio */
+- UINT standardBitrate, /*! the standard bitrate per channel in bits/sec */
+- UINT vbrMode, /*! the vbr paramter, 0 poor quality .. 100 high quality*/
+- UINT useSpeechConfig, /*!< adapt tuning parameters for speech ? */
+- UINT lcsMode, /*! the low complexity stereo mode */
+- UINT bParametricStereo, /*!< use parametric stereo */
+- AUDIO_OBJECT_TYPE core) /* Core audio codec object type */
+-{
+- INT idx = INVALID_TABLE_IDX;
+- /* set the core codec settings */
+- config->codecSettings.bitRate = bitRate;
+- config->codecSettings.nChannels = numChannels;
+- config->codecSettings.sampleFreq = sampleRateCore;
+- config->codecSettings.transFac = transFac;
+- config->codecSettings.standardBitrate = standardBitrate;
+-
+- if (bitRate < 28000) {
+- config->threshold_AmpRes_FF_m = (FIXP_DBL)MAXVAL_DBL;
+- config->threshold_AmpRes_FF_e = 7;
+- } else if (bitRate >= 28000 && bitRate <= 48000) {
+- /* The float threshold is 75
+- 0.524288f is fractional part of RELAXATION, the quotaMatrix and therefore
+- tonality are scaled by this 2/3 is because the original implementation
+- divides the tonality values by 3, here it's divided by 2 128 compensates
+- the necessary shiftfactor of 7 */
+- config->threshold_AmpRes_FF_m =
+- FL2FXCONST_DBL(75.0f * 0.524288f / (2.0f / 3.0f) / 128.0f);
+- config->threshold_AmpRes_FF_e = 7;
+- } else if (bitRate > 48000) {
+- config->threshold_AmpRes_FF_m = FL2FXCONST_DBL(0);
+- config->threshold_AmpRes_FF_e = 0;
+- }
+-
+- if (bitRate == 0) {
+- /* map vbr quality to bitrate */
+- if (vbrMode < 30)
+- bitRate = 24000;
+- else if (vbrMode < 40)
+- bitRate = 28000;
+- else if (vbrMode < 60)
+- bitRate = 32000;
+- else if (vbrMode < 75)
+- bitRate = 40000;
+- else
+- bitRate = 48000;
+- bitRate *= numChannels;
+- /* fix to enable mono vbrMode<40 @ 44.1 of 48kHz */
+- if (numChannels == 1) {
+- if (sampleRateSbr == 44100 || sampleRateSbr == 48000) {
+- if (vbrMode < 40) bitRate = 32000;
+- }
+- }
+- }
+-
+- idx =
+- getSbrTuningTableIndex(bitRate, numChannels, sampleRateCore, core, NULL);
+-
+- if (idx != INVALID_TABLE_IDX) {
+- config->startFreq = sbrTuningTable[idx].startFreq;
+- config->stopFreq = sbrTuningTable[idx].stopFreq;
+- if (useSpeechConfig) {
+- config->startFreq = sbrTuningTable[idx].startFreqSpeech;
+- config->stopFreq = sbrTuningTable[idx].stopFreqSpeech;
+- }
+-
+- /* Adapt stop frequency in case of downsampled SBR - only 32 bands then */
+- if (1 == config->downSampleFactor) {
+- INT dsStopFreq = FDKsbrEnc_GetDownsampledStopFreq(
+- sampleRateCore, config->startFreq, config->stopFreq,
+- config->downSampleFactor);
+- if (dsStopFreq < 0) {
+- return 0;
+- }
+-
+- config->stopFreq = dsStopFreq;
+- }
+-
+- config->sbr_noise_bands = sbrTuningTable[idx].numNoiseBands;
+- if (core == AOT_ER_AAC_ELD) config->init_amp_res_FF = SBR_AMP_RES_1_5;
+- config->noiseFloorOffset = sbrTuningTable[idx].noiseFloorOffset;
+-
+- config->ana_max_level = sbrTuningTable[idx].noiseMaxLevel;
+- config->stereoMode = sbrTuningTable[idx].stereoMode;
+- config->freqScale = sbrTuningTable[idx].freqScale;
+-
+- if (numChannels == 1) {
+- /* stereo case */
+- switch (core) {
+- case AOT_AAC_LC:
+- if (bitRate <= (useSpeechConfig ? 24000U : 20000U)) {
+- config->freq_res_fixfix[0] = FREQ_RES_LOW; /* set low frequency
+- resolution for
+- non-split frames */
+- config->freq_res_fixfix[1] = FREQ_RES_LOW; /* set low frequency
+- resolution for split
+- frames */
+- }
+- break;
+- case AOT_ER_AAC_ELD:
+- if (bitRate < 36000)
+- config->freq_res_fixfix[1] = FREQ_RES_LOW; /* set low frequency
+- resolution for split
+- frames */
+- if (bitRate < 26000) {
+- config->freq_res_fixfix[0] = FREQ_RES_LOW; /* set low frequency
+- resolution for
+- non-split frames */
+- config->fResTransIsLow =
+- 1; /* for transient frames, set low frequency resolution */
+- }
+- break;
+- default:
+- break;
+- }
+- } else {
+- /* stereo case */
+- switch (core) {
+- case AOT_AAC_LC:
+- if (bitRate <= 28000) {
+- config->freq_res_fixfix[0] = FREQ_RES_LOW; /* set low frequency
+- resolution for
+- non-split frames */
+- config->freq_res_fixfix[1] = FREQ_RES_LOW; /* set low frequency
+- resolution for split
+- frames */
+- }
+- break;
+- case AOT_ER_AAC_ELD:
+- if (bitRate < 72000) {
+- config->freq_res_fixfix[1] = FREQ_RES_LOW; /* set low frequency
+- resolution for split
+- frames */
+- }
+- if (bitRate < 52000) {
+- config->freq_res_fixfix[0] = FREQ_RES_LOW; /* set low frequency
+- resolution for
+- non-split frames */
+- config->fResTransIsLow =
+- 1; /* for transient frames, set low frequency resolution */
+- }
+- break;
+- default:
+- break;
+- }
+- if (bitRate <= 28000) {
+- /*
+- additionally restrict frequency resolution in FIXFIX frames
+- to further reduce SBR payload size */
+- config->freq_res_fixfix[0] = FREQ_RES_LOW;
+- config->freq_res_fixfix[1] = FREQ_RES_LOW;
+- }
+- }
+-
+- /* adjust usage of parametric coding dependent on bitrate and speech config
+- * flag */
+- if (useSpeechConfig) config->parametricCoding = 0;
+-
+- if (core == AOT_ER_AAC_ELD) {
+- if (bitRate < 28000) config->init_amp_res_FF = SBR_AMP_RES_3_0;
+- config->SendHeaderDataTime = -1;
+- }
+-
+- if (numChannels == 1) {
+- if (bitRate < 16000) {
+- config->parametricCoding = 0;
+- }
+- } else {
+- if (bitRate < 20000) {
+- config->parametricCoding = 0;
+- }
+- }
+-
+- config->useSpeechConfig = useSpeechConfig;
+-
+- /* PS settings */
+- config->bParametricStereo = bParametricStereo;
+-
+- return 1;
+- } else {
+- return 0;
+- }
+-}
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_InitializeSbrDefaults
+- description: initializes the SBR configuration
+- returns: error status
+- input: - core codec type,
+- - factor of SBR to core frame length,
+- - core frame length
+- output: initialized SBR configuration
+-
+-*****************************************************************************/
+-static UINT FDKsbrEnc_InitializeSbrDefaults(sbrConfigurationPtr config,
+- INT downSampleFactor,
+- UINT codecGranuleLen,
+- const INT isLowDelay) {
+- if ((downSampleFactor < 1 || downSampleFactor > 2) ||
+- (codecGranuleLen * downSampleFactor > 64 * 32))
+- return (0); /* error */
+-
+- config->SendHeaderDataTime = 1000;
+- config->useWaveCoding = 0;
+- config->crcSbr = 0;
+- config->dynBwSupported = 1;
+- if (isLowDelay)
+- config->tran_thr = 6000;
+- else
+- config->tran_thr = 13000;
+-
+- config->parametricCoding = 1;
+-
+- config->sbrFrameSize = codecGranuleLen * downSampleFactor;
+- config->downSampleFactor = downSampleFactor;
+-
+- /* sbr default parameters */
+- config->sbr_data_extra = 0;
+- config->amp_res = SBR_AMP_RES_3_0;
+- config->tran_fc = 0;
+- config->tran_det_mode = 1;
+- config->spread = 1;
+- config->stat = 0;
+- config->e = 1;
+- config->deltaTAcrossFrames = 1;
+- config->dF_edge_1stEnv = FL2FXCONST_DBL(0.3f);
+- config->dF_edge_incr = FL2FXCONST_DBL(0.3f);
+-
+- config->sbr_invf_mode = INVF_SWITCHED;
+- config->sbr_xpos_mode = XPOS_LC;
+- config->sbr_xpos_ctrl = SBR_XPOS_CTRL_DEFAULT;
+- config->sbr_xpos_level = 0;
+- config->useSaPan = 0;
+- config->dynBwEnabled = 0;
+-
+- /* the following parameters are overwritten by the
+- FDKsbrEnc_AdjustSbrSettings() function since they are included in the
+- tuning table */
+- config->stereoMode = SBR_SWITCH_LRC;
+- config->ana_max_level = 6;
+- config->noiseFloorOffset = 0;
+- config->startFreq = 5; /* 5.9 respectively 6.0 kHz at fs = 44.1/48 kHz */
+- config->stopFreq = 9; /* 16.2 respectively 16.8 kHz at fs = 44.1/48 kHz */
+- config->freq_res_fixfix[0] = FREQ_RES_HIGH; /* non-split case */
+- config->freq_res_fixfix[1] = FREQ_RES_HIGH; /* split case */
+- config->fResTransIsLow = 0; /* for transient frames, set variable frequency
+- resolution according to freqResTable */
+-
+- /* header_extra_1 */
+- config->freqScale = SBR_FREQ_SCALE_DEFAULT;
+- config->alterScale = SBR_ALTER_SCALE_DEFAULT;
+- config->sbr_noise_bands = SBR_NOISE_BANDS_DEFAULT;
+-
+- /* header_extra_2 */
+- config->sbr_limiter_bands = SBR_LIMITER_BANDS_DEFAULT;
+- config->sbr_limiter_gains = SBR_LIMITER_GAINS_DEFAULT;
+- config->sbr_interpol_freq = SBR_INTERPOL_FREQ_DEFAULT;
+- config->sbr_smoothing_length = SBR_SMOOTHING_LENGTH_DEFAULT;
+-
+- return 1;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: DeleteEnvChannel
+- description: frees memory of one SBR channel
+- returns: -
+- input: handle of channel
+- output: released handle
+-
+-*****************************************************************************/
+-static void deleteEnvChannel(HANDLE_ENV_CHANNEL hEnvCut) {
+- if (hEnvCut) {
+- FDKsbrEnc_DeleteTonCorrParamExtr(&hEnvCut->TonCorr);
+-
+- FDKsbrEnc_deleteExtractSbrEnvelope(&hEnvCut->sbrExtractEnvelope);
+- }
+-}
+-
+-/*****************************************************************************
+-
+- functionname: sbrEncoder_ChannelClose
+- description: close the channel coding handle
+- returns:
+- input: phSbrChannel
+- output:
+-
+-*****************************************************************************/
+-static void sbrEncoder_ChannelClose(HANDLE_SBR_CHANNEL hSbrChannel) {
+- if (hSbrChannel != NULL) {
+- deleteEnvChannel(&hSbrChannel->hEnvChannel);
+- }
+-}
+-
+-/*****************************************************************************
+-
+- functionname: sbrEncoder_ElementClose
+- description: close the channel coding handle
+- returns:
+- input: phSbrChannel
+- output:
+-
+-*****************************************************************************/
+-static void sbrEncoder_ElementClose(HANDLE_SBR_ELEMENT *phSbrElement) {
+- HANDLE_SBR_ELEMENT hSbrElement = *phSbrElement;
+-
+- if (hSbrElement != NULL) {
+- if (hSbrElement->sbrConfigData.v_k_master)
+- FreeRam_Sbr_v_k_master(&hSbrElement->sbrConfigData.v_k_master);
+- if (hSbrElement->sbrConfigData.freqBandTable[LO])
+- FreeRam_Sbr_freqBandTableLO(
+- &hSbrElement->sbrConfigData.freqBandTable[LO]);
+- if (hSbrElement->sbrConfigData.freqBandTable[HI])
+- FreeRam_Sbr_freqBandTableHI(
+- &hSbrElement->sbrConfigData.freqBandTable[HI]);
+-
+- FreeRam_SbrElement(phSbrElement);
+- }
+- return;
+-}
+-
+-void sbrEncoder_Close(HANDLE_SBR_ENCODER *phSbrEncoder) {
+- HANDLE_SBR_ENCODER hSbrEncoder = *phSbrEncoder;
+-
+- if (hSbrEncoder != NULL) {
+- int el, ch;
+-
+- for (el = 0; el < (8); el++) {
+- if (hSbrEncoder->sbrElement[el] != NULL) {
+- sbrEncoder_ElementClose(&hSbrEncoder->sbrElement[el]);
+- }
+- }
+-
+- /* Close sbr Channels */
+- for (ch = 0; ch < (8); ch++) {
+- if (hSbrEncoder->pSbrChannel[ch]) {
+- sbrEncoder_ChannelClose(hSbrEncoder->pSbrChannel[ch]);
+- FreeRam_SbrChannel(&hSbrEncoder->pSbrChannel[ch]);
+- }
+-
+- if (hSbrEncoder->QmfAnalysis[ch].FilterStates)
+- FreeRam_Sbr_QmfStatesAnalysis(
+- (FIXP_QAS **)&hSbrEncoder->QmfAnalysis[ch].FilterStates);
+- }
+-
+- if (hSbrEncoder->hParametricStereo)
+- PSEnc_Destroy(&hSbrEncoder->hParametricStereo);
+- if (hSbrEncoder->qmfSynthesisPS.FilterStates)
+- FreeRam_PsQmfStatesSynthesis(
+- (FIXP_DBL **)&hSbrEncoder->qmfSynthesisPS.FilterStates);
+-
+- /* Release Overlay */
+- if (hSbrEncoder->pSBRdynamic_RAM)
+- FreeRam_SbrDynamic_RAM((FIXP_DBL **)&hSbrEncoder->pSBRdynamic_RAM);
+-
+- FreeRam_SbrEncoder(phSbrEncoder);
+- }
+-}
+-
+-/*****************************************************************************
+-
+- functionname: updateFreqBandTable
+- description: updates vk_master
+- returns: -
+- input: config handle
+- output: error info
+-
+-*****************************************************************************/
+-static INT updateFreqBandTable(HANDLE_SBR_CONFIG_DATA sbrConfigData,
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- const INT downSampleFactor) {
+- INT k0, k2;
+-
+- if (FDKsbrEnc_FindStartAndStopBand(
+- sbrConfigData->sampleFreq,
+- sbrConfigData->sampleFreq >> (downSampleFactor - 1),
+- sbrConfigData->noQmfBands, sbrHeaderData->sbr_start_frequency,
+- sbrHeaderData->sbr_stop_frequency, &k0, &k2))
+- return (1);
+-
+- if (FDKsbrEnc_UpdateFreqScale(
+- sbrConfigData->v_k_master, &sbrConfigData->num_Master, k0, k2,
+- sbrHeaderData->freqScale, sbrHeaderData->alterScale))
+- return (1);
+-
+- sbrHeaderData->sbr_xover_band = 0;
+-
+- if (FDKsbrEnc_UpdateHiRes(sbrConfigData->freqBandTable[HI],
+- &sbrConfigData->nSfb[HI], sbrConfigData->v_k_master,
+- sbrConfigData->num_Master,
+- &sbrHeaderData->sbr_xover_band))
+- return (1);
+-
+- FDKsbrEnc_UpdateLoRes(
+- sbrConfigData->freqBandTable[LO], &sbrConfigData->nSfb[LO],
+- sbrConfigData->freqBandTable[HI], sbrConfigData->nSfb[HI]);
+-
+- sbrConfigData->xOverFreq =
+- (sbrConfigData->freqBandTable[LOW_RES][0] * sbrConfigData->sampleFreq /
+- sbrConfigData->noQmfBands +
+- 1) >>
+- 1;
+-
+- return (0);
+-}
+-
+-/*****************************************************************************
+-
+- functionname: resetEnvChannel
+- description: resets parameters and allocates memory
+- returns: error status
+- input:
+- output: hEnv
+-
+-*****************************************************************************/
+-static INT resetEnvChannel(HANDLE_SBR_CONFIG_DATA sbrConfigData,
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_ENV_CHANNEL hEnv) {
+- /* note !!! hEnv->encEnvData.noOfnoisebands will be updated later in function
+- * FDKsbrEnc_extractSbrEnvelope !!!*/
+- hEnv->TonCorr.sbrNoiseFloorEstimate.noiseBands =
+- sbrHeaderData->sbr_noise_bands;
+-
+- if (FDKsbrEnc_ResetTonCorrParamExtr(
+- &hEnv->TonCorr, sbrConfigData->xposCtrlSwitch,
+- sbrConfigData->freqBandTable[HI][0], sbrConfigData->v_k_master,
+- sbrConfigData->num_Master, sbrConfigData->sampleFreq,
+- sbrConfigData->freqBandTable, sbrConfigData->nSfb,
+- sbrConfigData->noQmfBands))
+- return (1);
+-
+- hEnv->sbrCodeNoiseFloor.nSfb[LO] =
+- hEnv->TonCorr.sbrNoiseFloorEstimate.noNoiseBands;
+- hEnv->sbrCodeNoiseFloor.nSfb[HI] =
+- hEnv->TonCorr.sbrNoiseFloorEstimate.noNoiseBands;
+-
+- hEnv->sbrCodeEnvelope.nSfb[LO] = sbrConfigData->nSfb[LO];
+- hEnv->sbrCodeEnvelope.nSfb[HI] = sbrConfigData->nSfb[HI];
+-
+- hEnv->encEnvData.noHarmonics = sbrConfigData->nSfb[HI];
+-
+- hEnv->sbrCodeEnvelope.upDate = 0;
+- hEnv->sbrCodeNoiseFloor.upDate = 0;
+-
+- return (0);
+-}
+-
+-/* ****************************** FDKsbrEnc_SbrGetXOverFreq
+- * ******************************/
+-/**
+- * @fn
+- * @brief calculates the closest possible crossover frequency
+- * @return the crossover frequency SBR accepts
+- *
+- */
+-static INT FDKsbrEnc_SbrGetXOverFreq(
+- HANDLE_SBR_ELEMENT hEnv, /*!< handle to SBR encoder instance */
+- INT xoverFreq) /*!< from core coder suggested crossover frequency */
+-{
+- INT band;
+- INT lastDiff, newDiff;
+- INT cutoffSb;
+-
+- UCHAR *RESTRICT pVKMaster = hEnv->sbrConfigData.v_k_master;
+-
+- /* Check if there is a matching cutoff frequency in the master table */
+- cutoffSb = (4 * xoverFreq * hEnv->sbrConfigData.noQmfBands /
+- hEnv->sbrConfigData.sampleFreq +
+- 1) >>
+- 1;
+- lastDiff = cutoffSb;
+- for (band = 0; band < hEnv->sbrConfigData.num_Master; band++) {
+- newDiff = fixp_abs((INT)pVKMaster[band] - cutoffSb);
+-
+- if (newDiff >= lastDiff) {
+- band--;
+- break;
+- }
+-
+- lastDiff = newDiff;
+- }
+-
+- return ((pVKMaster[band] * hEnv->sbrConfigData.sampleFreq /
+- hEnv->sbrConfigData.noQmfBands +
+- 1) >>
+- 1);
+-}
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_EnvEncodeFrame
+- description: performs the sbr envelope calculation for one element
+- returns:
+- input:
+- output:
+-
+-*****************************************************************************/
+-INT FDKsbrEnc_EnvEncodeFrame(
+- HANDLE_SBR_ENCODER hEnvEncoder, int iElement,
+- INT_PCM *samples, /*!< time samples, always deinterleaved */
+- UINT samplesBufSize, /*!< time buffer channel stride */
+- UINT *sbrDataBits, /*!< Size of SBR payload */
+- UCHAR *sbrData, /*!< SBR payload */
+- int clearOutput /*!< Do not consider any input signal */
+-) {
+- HANDLE_SBR_ELEMENT hSbrElement = NULL;
+- FDK_CRCINFO crcInfo;
+- INT crcReg;
+- INT ch;
+- INT band;
+- INT cutoffSb;
+- INT newXOver;
+-
+- if (hEnvEncoder == NULL) return -1;
+-
+- hSbrElement = hEnvEncoder->sbrElement[iElement];
+-
+- if (hSbrElement == NULL) return -1;
+-
+- /* header bitstream handling */
+- HANDLE_SBR_BITSTREAM_DATA sbrBitstreamData = &hSbrElement->sbrBitstreamData;
+-
+- INT psHeaderActive = 0;
+- sbrBitstreamData->HeaderActive = 0;
+-
+- /* Anticipate PS header because of internal PS bitstream delay in order to be
+- * in sync with SBR header. */
+- if (sbrBitstreamData->CountSendHeaderData ==
+- (sbrBitstreamData->NrSendHeaderData - 1)) {
+- psHeaderActive = 1;
+- }
+-
+- /* Signal SBR header to be written into bitstream */
+- if (sbrBitstreamData->CountSendHeaderData == 0) {
+- sbrBitstreamData->HeaderActive = 1;
+- }
+-
+- /* Increment header interval counter */
+- if (sbrBitstreamData->NrSendHeaderData == 0) {
+- sbrBitstreamData->CountSendHeaderData = 1;
+- } else {
+- if (sbrBitstreamData->CountSendHeaderData >= 0) {
+- sbrBitstreamData->CountSendHeaderData++;
+- sbrBitstreamData->CountSendHeaderData %=
+- sbrBitstreamData->NrSendHeaderData;
+- }
+- }
+-
+- if (hSbrElement->CmonData.dynBwEnabled) {
+- INT i;
+- for (i = 4; i > 0; i--)
+- hSbrElement->dynXOverFreqDelay[i] = hSbrElement->dynXOverFreqDelay[i - 1];
+-
+- hSbrElement->dynXOverFreqDelay[0] = hSbrElement->CmonData.dynXOverFreqEnc;
+- if (hSbrElement->dynXOverFreqDelay[1] > hSbrElement->dynXOverFreqDelay[2])
+- newXOver = hSbrElement->dynXOverFreqDelay[2];
+- else
+- newXOver = hSbrElement->dynXOverFreqDelay[1];
+-
+- /* has the crossover frequency changed? */
+- if (hSbrElement->sbrConfigData.dynXOverFreq != newXOver) {
+- /* get corresponding master band */
+- cutoffSb = ((4 * newXOver * hSbrElement->sbrConfigData.noQmfBands /
+- hSbrElement->sbrConfigData.sampleFreq) +
+- 1) >>
+- 1;
+-
+- for (band = 0; band < hSbrElement->sbrConfigData.num_Master; band++) {
+- if (cutoffSb == hSbrElement->sbrConfigData.v_k_master[band]) break;
+- }
+- FDK_ASSERT(band < hSbrElement->sbrConfigData.num_Master);
+-
+- hSbrElement->sbrConfigData.dynXOverFreq = newXOver;
+- hSbrElement->sbrHeaderData.sbr_xover_band = band;
+- hSbrElement->sbrBitstreamData.HeaderActive = 1;
+- psHeaderActive = 1; /* ps header is one frame delayed */
+-
+- /*
+- update vk_master table
+- */
+- if (updateFreqBandTable(&hSbrElement->sbrConfigData,
+- &hSbrElement->sbrHeaderData,
+- hEnvEncoder->downSampleFactor))
+- return (1);
+-
+- /* reset SBR channels */
+- INT nEnvCh = hSbrElement->sbrConfigData.nChannels;
+- for (ch = 0; ch < nEnvCh; ch++) {
+- if (resetEnvChannel(&hSbrElement->sbrConfigData,
+- &hSbrElement->sbrHeaderData,
+- &hSbrElement->sbrChannel[ch]->hEnvChannel))
+- return (1);
+- }
+- }
+- }
+-
+- /*
+- allocate space for dummy header and crc
+- */
+- crcReg = FDKsbrEnc_InitSbrBitstream(
+- &hSbrElement->CmonData,
+- hSbrElement->payloadDelayLine[hEnvEncoder->nBitstrDelay],
+- MAX_PAYLOAD_SIZE * sizeof(UCHAR), &crcInfo,
+- hSbrElement->sbrConfigData.sbrSyntaxFlags);
+-
+- /* Temporal Envelope Data */
+- SBR_FRAME_TEMP_DATA _fData;
+- SBR_FRAME_TEMP_DATA *fData = &_fData;
+- SBR_ENV_TEMP_DATA eData[MAX_NUM_CHANNELS];
+-
+- /* Init Temporal Envelope Data */
+- {
+- int i;
+-
+- FDKmemclear(&eData[0], sizeof(SBR_ENV_TEMP_DATA));
+- FDKmemclear(&eData[1], sizeof(SBR_ENV_TEMP_DATA));
+- FDKmemclear(fData, sizeof(SBR_FRAME_TEMP_DATA));
+-
+- for (i = 0; i < MAX_NUM_NOISE_VALUES; i++) fData->res[i] = FREQ_RES_HIGH;
+- }
+-
+- if (!clearOutput) {
+- /*
+- * Transform audio data into QMF domain
+- */
+- for (ch = 0; ch < hSbrElement->sbrConfigData.nChannels; ch++) {
+- HANDLE_ENV_CHANNEL h_envChan = &hSbrElement->sbrChannel[ch]->hEnvChannel;
+- HANDLE_SBR_EXTRACT_ENVELOPE sbrExtrEnv = &h_envChan->sbrExtractEnvelope;
+-
+- if (hSbrElement->elInfo.fParametricStereo == 0) {
+- QMF_SCALE_FACTOR tmpScale;
+- FIXP_DBL **pQmfReal, **pQmfImag;
+- C_AALLOC_SCRATCH_START(qmfWorkBuffer, FIXP_DBL, 64 * 2)
+-
+- /* Obtain pointers to QMF buffers. */
+- pQmfReal = sbrExtrEnv->rBuffer;
+- pQmfImag = sbrExtrEnv->iBuffer;
+-
+- qmfAnalysisFiltering(
+- hSbrElement->hQmfAnalysis[ch], pQmfReal, pQmfImag, &tmpScale,
+- samples + hSbrElement->elInfo.ChannelIndex[ch] * samplesBufSize, 0,
+- 1, qmfWorkBuffer);
+-
+- h_envChan->qmfScale = tmpScale.lb_scale + 7;
+-
+- C_AALLOC_SCRATCH_END(qmfWorkBuffer, FIXP_DBL, 64 * 2)
+-
+- } /* fParametricStereo == 0 */
+-
+- /*
+- Parametric Stereo processing
+- */
+- if (hSbrElement->elInfo.fParametricStereo) {
+- INT error = noError;
+-
+- /* Limit Parametric Stereo to one instance */
+- FDK_ASSERT(ch == 0);
+-
+- if (error == noError) {
+- /* parametric stereo processing:
+- - input:
+- o left and right time domain samples
+- - processing:
+- o stereo qmf analysis
+- o stereo hybrid analysis
+- o ps parameter extraction
+- o downmix + hybrid synthesis
+- - output:
+- o downmixed qmf data is written to sbrExtrEnv->rBuffer and
+- sbrExtrEnv->iBuffer
+- */
+- SCHAR qmfScale;
+- INT_PCM *pSamples[2] = {
+- samples + hSbrElement->elInfo.ChannelIndex[0] * samplesBufSize,
+- samples + hSbrElement->elInfo.ChannelIndex[1] * samplesBufSize};
+- error = FDKsbrEnc_PSEnc_ParametricStereoProcessing(
+- hEnvEncoder->hParametricStereo, pSamples, samplesBufSize,
+- hSbrElement->hQmfAnalysis, sbrExtrEnv->rBuffer,
+- sbrExtrEnv->iBuffer,
+- samples + hSbrElement->elInfo.ChannelIndex[ch] * samplesBufSize,
+- &hEnvEncoder->qmfSynthesisPS, &qmfScale, psHeaderActive);
+- h_envChan->qmfScale = (int)qmfScale;
+- }
+-
+- } /* if (hEnvEncoder->hParametricStereo) */
+-
+- /*
+-
+- Extract Envelope relevant things from QMF data
+-
+- */
+- FDKsbrEnc_extractSbrEnvelope1(&hSbrElement->sbrConfigData,
+- &hSbrElement->sbrHeaderData,
+- &hSbrElement->sbrBitstreamData, h_envChan,
+- &hSbrElement->CmonData, &eData[ch], fData);
+-
+- } /* hEnvEncoder->sbrConfigData.nChannels */
+- }
+-
+- /*
+- Process Envelope relevant things and calculate envelope data and write
+- payload
+- */
+- FDKsbrEnc_extractSbrEnvelope2(
+- &hSbrElement->sbrConfigData, &hSbrElement->sbrHeaderData,
+- (hSbrElement->elInfo.fParametricStereo) ? hEnvEncoder->hParametricStereo
+- : NULL,
+- &hSbrElement->sbrBitstreamData, &hSbrElement->sbrChannel[0]->hEnvChannel,
+- (hSbrElement->sbrConfigData.stereoMode != SBR_MONO)
+- ? &hSbrElement->sbrChannel[1]->hEnvChannel
+- : NULL,
+- &hSbrElement->CmonData, eData, fData, clearOutput);
+-
+- hSbrElement->sbrBitstreamData.rightBorderFIX = 0;
+-
+- /*
+- format payload, calculate crc
+- */
+- FDKsbrEnc_AssembleSbrBitstream(&hSbrElement->CmonData, &crcInfo, crcReg,
+- hSbrElement->sbrConfigData.sbrSyntaxFlags);
+-
+- /*
+- save new payload, set to zero length if greater than MAX_PAYLOAD_SIZE
+- */
+- hSbrElement->payloadDelayLineSize[hEnvEncoder->nBitstrDelay] =
+- FDKgetValidBits(&hSbrElement->CmonData.sbrBitbuf);
+-
+- if (hSbrElement->payloadDelayLineSize[hEnvEncoder->nBitstrDelay] >
+- (MAX_PAYLOAD_SIZE << 3))
+- hSbrElement->payloadDelayLineSize[hEnvEncoder->nBitstrDelay] = 0;
+-
+- /* While filling the Delay lines, sbrData is NULL */
+- if (sbrData) {
+- *sbrDataBits = hSbrElement->payloadDelayLineSize[0];
+- FDKmemcpy(sbrData, hSbrElement->payloadDelayLine[0],
+- (hSbrElement->payloadDelayLineSize[0] + 7) >> 3);
+- }
+-
+- /* delay header active flag */
+- if (hSbrElement->sbrBitstreamData.HeaderActive == 1) {
+- hSbrElement->sbrBitstreamData.HeaderActiveDelay =
+- 1 + hEnvEncoder->nBitstrDelay;
+- } else {
+- if (hSbrElement->sbrBitstreamData.HeaderActiveDelay > 0) {
+- hSbrElement->sbrBitstreamData.HeaderActiveDelay--;
+- }
+- }
+-
+- return (0);
+-}
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_Downsample
+- description: performs downsampling and delay compensation of the core path
+- returns:
+- input:
+- output:
+-
+-*****************************************************************************/
+-INT FDKsbrEnc_Downsample(
+- HANDLE_SBR_ENCODER hSbrEncoder,
+- INT_PCM *samples, /*!< time samples, always deinterleaved */
+- UINT samplesBufSize, /*!< time buffer size per channel */
+- UINT numChannels, /*!< number of channels */
+- UINT *sbrDataBits, /*!< Size of SBR payload */
+- UCHAR *sbrData, /*!< SBR payload */
+- int clearOutput /*!< Do not consider any input signal */
+-) {
+- HANDLE_SBR_ELEMENT hSbrElement = NULL;
+- INT nOutSamples;
+- int el;
+- if (hSbrEncoder->downSampleFactor > 1) {
+- /* Do downsampling */
+-
+- /* Loop over elements (LFE is handled later) */
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- hSbrElement = hSbrEncoder->sbrElement[el];
+- if (hSbrEncoder->sbrElement[el] != NULL) {
+- if (hSbrEncoder->downsamplingMethod == SBRENC_DS_TIME) {
+- int ch;
+- int nChannels = hSbrElement->sbrConfigData.nChannels;
+-
+- for (ch = 0; ch < nChannels; ch++) {
+- FDKaacEnc_Downsample(
+- &hSbrElement->sbrChannel[ch]->downSampler,
+- samples +
+- hSbrElement->elInfo.ChannelIndex[ch] * samplesBufSize +
+- hSbrEncoder->bufferOffset / numChannels,
+- hSbrElement->sbrConfigData.frameSize,
+- samples + hSbrElement->elInfo.ChannelIndex[ch] * samplesBufSize,
+- &nOutSamples);
+- }
+- }
+- }
+- }
+-
+- /* Handle LFE (if existing) */
+- if (hSbrEncoder->lfeChIdx != -1) { /* lfe downsampler */
+- FDKaacEnc_Downsample(&hSbrEncoder->lfeDownSampler,
+- samples + hSbrEncoder->lfeChIdx * samplesBufSize +
+- hSbrEncoder->bufferOffset / numChannels,
+- hSbrEncoder->frameSize,
+- samples + hSbrEncoder->lfeChIdx * samplesBufSize,
+- &nOutSamples);
+- }
+- } else {
+- /* No downsampling. Still, some buffer shifting for correct delay */
+- int samples2Copy = hSbrEncoder->frameSize;
+- if (hSbrEncoder->bufferOffset / (int)numChannels < samples2Copy) {
+- for (int c = 0; c < (int)numChannels; c++) {
+- /* Do memmove while taking care of overlapping memory areas. (memcpy
+- does not necessarily take care) Distinguish between oeverlapping and
+- non overlapping version due to reasons of complexity. */
+- FDKmemmove(samples + c * samplesBufSize,
+- samples + c * samplesBufSize +
+- hSbrEncoder->bufferOffset / numChannels,
+- samples2Copy * sizeof(INT_PCM));
+- }
+- } else {
+- for (int c = 0; c < (int)numChannels; c++) {
+- /* Simple memcpy since the memory areas are not overlapping */
+- FDKmemcpy(samples + c * samplesBufSize,
+- samples + c * samplesBufSize +
+- hSbrEncoder->bufferOffset / numChannels,
+- samples2Copy * sizeof(INT_PCM));
+- }
+- }
+- }
+-
+- return 0;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: createEnvChannel
+- description: initializes parameters and allocates memory
+- returns: error status
+- input:
+- output: hEnv
+-
+-*****************************************************************************/
+-
+-static INT createEnvChannel(HANDLE_ENV_CHANNEL hEnv, INT channel,
+- UCHAR *dynamic_RAM) {
+- FDKmemclear(hEnv, sizeof(struct ENV_CHANNEL));
+-
+- if (FDKsbrEnc_CreateTonCorrParamExtr(&hEnv->TonCorr, channel)) {
+- return (1);
+- }
+-
+- if (FDKsbrEnc_CreateExtractSbrEnvelope(&hEnv->sbrExtractEnvelope, channel,
+- /*chan*/ 0, dynamic_RAM)) {
+- return (1);
+- }
+-
+- return 0;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: initEnvChannel
+- description: initializes parameters
+- returns: error status
+- input:
+- output:
+-
+-*****************************************************************************/
+-static INT initEnvChannel(HANDLE_SBR_CONFIG_DATA sbrConfigData,
+- HANDLE_SBR_HEADER_DATA sbrHeaderData,
+- HANDLE_ENV_CHANNEL hEnv, sbrConfigurationPtr params,
+- ULONG statesInitFlag, INT chanInEl,
+- UCHAR *dynamic_RAM) {
+- int frameShift, tran_off = 0;
+- INT e;
+- INT tran_fc;
+- INT timeSlots, timeStep, startIndex;
+- INT noiseBands[2] = {3, 3};
+-
+- e = 1 << params->e;
+-
+- FDK_ASSERT(params->e >= 0);
+-
+- hEnv->encEnvData.freq_res_fixfix[0] = params->freq_res_fixfix[0];
+- hEnv->encEnvData.freq_res_fixfix[1] = params->freq_res_fixfix[1];
+- hEnv->encEnvData.fResTransIsLow = params->fResTransIsLow;
+-
+- hEnv->fLevelProtect = 0;
+-
+- hEnv->encEnvData.ldGrid =
+- (sbrConfigData->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) ? 1 : 0;
+-
+- hEnv->encEnvData.sbr_xpos_mode = (XPOS_MODE)params->sbr_xpos_mode;
+-
+- if (hEnv->encEnvData.sbr_xpos_mode == XPOS_SWITCHED) {
+- /*
+- no other type than XPOS_MDCT or XPOS_SPEECH allowed,
+- but enable switching
+- */
+- sbrConfigData->switchTransposers = TRUE;
+- hEnv->encEnvData.sbr_xpos_mode = XPOS_MDCT;
+- } else {
+- sbrConfigData->switchTransposers = FALSE;
+- }
+-
+- hEnv->encEnvData.sbr_xpos_ctrl = params->sbr_xpos_ctrl;
+-
+- /* extended data */
+- if (params->parametricCoding) {
+- hEnv->encEnvData.extended_data = 1;
+- } else {
+- hEnv->encEnvData.extended_data = 0;
+- }
+-
+- hEnv->encEnvData.extension_size = 0;
+-
+- startIndex = QMF_FILTER_PROTOTYPE_SIZE - sbrConfigData->noQmfBands;
+-
+- switch (params->sbrFrameSize) {
+- case 2304:
+- timeSlots = 18;
+- break;
+- case 2048:
+- case 1024:
+- case 512:
+- timeSlots = 16;
+- break;
+- case 1920:
+- case 960:
+- case 480:
+- timeSlots = 15;
+- break;
+- case 1152:
+- timeSlots = 9;
+- break;
+- default:
+- return (1); /* Illegal frame size */
+- }
+-
+- timeStep = sbrConfigData->noQmfSlots / timeSlots;
+-
+- if (FDKsbrEnc_InitTonCorrParamExtr(
+- params->sbrFrameSize, &hEnv->TonCorr, sbrConfigData, timeSlots,
+- params->sbr_xpos_ctrl, params->ana_max_level,
+- sbrHeaderData->sbr_noise_bands, params->noiseFloorOffset,
+- params->useSpeechConfig))
+- return (1);
+-
+- hEnv->encEnvData.noOfnoisebands =
+- hEnv->TonCorr.sbrNoiseFloorEstimate.noNoiseBands;
+-
+- noiseBands[0] = hEnv->encEnvData.noOfnoisebands;
+- noiseBands[1] = hEnv->encEnvData.noOfnoisebands;
+-
+- hEnv->encEnvData.sbr_invf_mode = (INVF_MODE)params->sbr_invf_mode;
+-
+- if (hEnv->encEnvData.sbr_invf_mode == INVF_SWITCHED) {
+- hEnv->encEnvData.sbr_invf_mode = INVF_MID_LEVEL;
+- hEnv->TonCorr.switchInverseFilt = TRUE;
+- } else {
+- hEnv->TonCorr.switchInverseFilt = FALSE;
+- }
+-
+- tran_fc = params->tran_fc;
+-
+- if (tran_fc == 0) {
+- tran_fc = fixMin(
+- 5000, FDKsbrEnc_getSbrStartFreqRAW(sbrHeaderData->sbr_start_frequency,
+- params->codecSettings.sampleFreq));
+- }
+-
+- tran_fc =
+- (tran_fc * 4 * sbrConfigData->noQmfBands / sbrConfigData->sampleFreq +
+- 1) >>
+- 1;
+-
+- if (sbrConfigData->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- frameShift = LD_PRETRAN_OFF;
+- tran_off = LD_PRETRAN_OFF + FRAME_MIDDLE_SLOT_512LD * timeStep;
+- } else {
+- frameShift = 0;
+- switch (timeSlots) {
+- /* The factor of 2 is by definition. */
+- case NUMBER_TIME_SLOTS_2048:
+- tran_off = 8 + FRAME_MIDDLE_SLOT_2048 * timeStep;
+- break;
+- case NUMBER_TIME_SLOTS_1920:
+- tran_off = 7 + FRAME_MIDDLE_SLOT_1920 * timeStep;
+- break;
+- default:
+- return 1;
+- }
+- }
+- if (FDKsbrEnc_InitExtractSbrEnvelope(
+- &hEnv->sbrExtractEnvelope, sbrConfigData->noQmfSlots,
+- sbrConfigData->noQmfBands, startIndex, timeSlots, timeStep, tran_off,
+- statesInitFlag, chanInEl, dynamic_RAM, sbrConfigData->sbrSyntaxFlags))
+- return (1);
+-
+- if (FDKsbrEnc_InitSbrCodeEnvelope(&hEnv->sbrCodeEnvelope, sbrConfigData->nSfb,
+- params->deltaTAcrossFrames,
+- params->dF_edge_1stEnv,
+- params->dF_edge_incr))
+- return (1);
+-
+- if (FDKsbrEnc_InitSbrCodeEnvelope(&hEnv->sbrCodeNoiseFloor, noiseBands,
+- params->deltaTAcrossFrames, 0, 0))
+- return (1);
+-
+- sbrConfigData->initAmpResFF = params->init_amp_res_FF;
+-
+- if (FDKsbrEnc_InitSbrHuffmanTables(&hEnv->encEnvData, &hEnv->sbrCodeEnvelope,
+- &hEnv->sbrCodeNoiseFloor,
+- sbrHeaderData->sbr_amp_res))
+- return (1);
+-
+- FDKsbrEnc_initFrameInfoGenerator(
+- &hEnv->SbrEnvFrame, params->spread, e, params->stat, timeSlots,
+- hEnv->encEnvData.freq_res_fixfix, hEnv->encEnvData.fResTransIsLow,
+- hEnv->encEnvData.ldGrid);
+-
+- if (sbrConfigData->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)
+-
+- {
+- INT bandwidth_qmf_slot =
+- (sbrConfigData->sampleFreq >> 1) / (sbrConfigData->noQmfBands);
+- if (FDKsbrEnc_InitSbrFastTransientDetector(
+- &hEnv->sbrFastTransientDetector, sbrConfigData->noQmfSlots,
+- bandwidth_qmf_slot, sbrConfigData->noQmfBands,
+- sbrConfigData->freqBandTable[0][0]))
+- return (1);
+- }
+-
+- /* The transient detector has to be initialized also if the fast transient
+- detector was active, because the values from the transient detector
+- structure are used. */
+- if (FDKsbrEnc_InitSbrTransientDetector(
+- &hEnv->sbrTransientDetector, sbrConfigData->sbrSyntaxFlags,
+- sbrConfigData->frameSize, sbrConfigData->sampleFreq, params, tran_fc,
+- sbrConfigData->noQmfSlots, sbrConfigData->noQmfBands,
+- hEnv->sbrExtractEnvelope.YBufferWriteOffset,
+- hEnv->sbrExtractEnvelope.YBufferSzShift, frameShift, tran_off))
+- return (1);
+-
+- sbrConfigData->xposCtrlSwitch = params->sbr_xpos_ctrl;
+-
+- hEnv->encEnvData.noHarmonics = sbrConfigData->nSfb[HI];
+- hEnv->encEnvData.addHarmonicFlag = 0;
+-
+- return (0);
+-}
+-
+-INT sbrEncoder_Open(HANDLE_SBR_ENCODER *phSbrEncoder, INT nElements,
+- INT nChannels, INT supportPS) {
+- INT i;
+- INT errorStatus = 1;
+- HANDLE_SBR_ENCODER hSbrEncoder = NULL;
+-
+- if (phSbrEncoder == NULL) {
+- goto bail;
+- }
+-
+- hSbrEncoder = GetRam_SbrEncoder();
+- if (hSbrEncoder == NULL) {
+- goto bail;
+- }
+- FDKmemclear(hSbrEncoder, sizeof(SBR_ENCODER));
+-
+- if (NULL ==
+- (hSbrEncoder->pSBRdynamic_RAM = (UCHAR *)GetRam_SbrDynamic_RAM())) {
+- goto bail;
+- }
+- hSbrEncoder->dynamicRam = hSbrEncoder->pSBRdynamic_RAM;
+-
+- /* Create SBR elements */
+- for (i = 0; i < nElements; i++) {
+- hSbrEncoder->sbrElement[i] = GetRam_SbrElement(i);
+- if (hSbrEncoder->sbrElement[i] == NULL) {
+- goto bail;
+- }
+- FDKmemclear(hSbrEncoder->sbrElement[i], sizeof(SBR_ELEMENT));
+- hSbrEncoder->sbrElement[i]->sbrConfigData.freqBandTable[LO] =
+- GetRam_Sbr_freqBandTableLO(i);
+- hSbrEncoder->sbrElement[i]->sbrConfigData.freqBandTable[HI] =
+- GetRam_Sbr_freqBandTableHI(i);
+- hSbrEncoder->sbrElement[i]->sbrConfigData.v_k_master =
+- GetRam_Sbr_v_k_master(i);
+- if ((hSbrEncoder->sbrElement[i]->sbrConfigData.freqBandTable[LO] == NULL) ||
+- (hSbrEncoder->sbrElement[i]->sbrConfigData.freqBandTable[HI] == NULL) ||
+- (hSbrEncoder->sbrElement[i]->sbrConfigData.v_k_master == NULL)) {
+- goto bail;
+- }
+- }
+-
+- /* Create SBR channels */
+- for (i = 0; i < nChannels; i++) {
+- hSbrEncoder->pSbrChannel[i] = GetRam_SbrChannel(i);
+- if (hSbrEncoder->pSbrChannel[i] == NULL) {
+- goto bail;
+- }
+-
+- if (createEnvChannel(&hSbrEncoder->pSbrChannel[i]->hEnvChannel, i,
+- hSbrEncoder->dynamicRam)) {
+- goto bail;
+- }
+- }
+-
+- /* Create QMF States */
+- for (i = 0; i < fixMax(nChannels, (supportPS) ? 2 : 0); i++) {
+- hSbrEncoder->QmfAnalysis[i].FilterStates = GetRam_Sbr_QmfStatesAnalysis(i);
+- if (hSbrEncoder->QmfAnalysis[i].FilterStates == NULL) {
+- goto bail;
+- }
+- }
+-
+- /* Create Parametric Stereo handle */
+- if (supportPS) {
+- if (PSEnc_Create(&hSbrEncoder->hParametricStereo)) {
+- goto bail;
+- }
+-
+- hSbrEncoder->qmfSynthesisPS.FilterStates = GetRam_PsQmfStatesSynthesis();
+- if (hSbrEncoder->qmfSynthesisPS.FilterStates == NULL) {
+- goto bail;
+- }
+- } /* supportPS */
+-
+- *phSbrEncoder = hSbrEncoder;
+-
+- errorStatus = 0;
+- return errorStatus;
+-
+-bail:
+- /* Close SBR encoder instance */
+- sbrEncoder_Close(&hSbrEncoder);
+- return errorStatus;
+-}
+-
+-static INT FDKsbrEnc_Reallocate(HANDLE_SBR_ENCODER hSbrEncoder,
+- SBR_ELEMENT_INFO elInfo[(8)],
+- const INT noElements) {
+- INT totalCh = 0;
+- INT totalQmf = 0;
+- INT coreEl;
+- INT el = -1;
+-
+- hSbrEncoder->lfeChIdx = -1; /* default value, until lfe found */
+-
+- for (coreEl = 0; coreEl < noElements; coreEl++) {
+- /* SBR only handles SCE and CPE's */
+- if (elInfo[coreEl].elType == ID_SCE || elInfo[coreEl].elType == ID_CPE) {
+- el++;
+- } else {
+- if (elInfo[coreEl].elType == ID_LFE) {
+- hSbrEncoder->lfeChIdx = elInfo[coreEl].ChannelIndex[0];
+- }
+- continue;
+- }
+-
+- SBR_ELEMENT_INFO *pelInfo = &elInfo[coreEl];
+- HANDLE_SBR_ELEMENT hSbrElement = hSbrEncoder->sbrElement[el];
+-
+- int ch;
+- for (ch = 0; ch < pelInfo->nChannelsInEl; ch++) {
+- hSbrElement->sbrChannel[ch] = hSbrEncoder->pSbrChannel[totalCh];
+- totalCh++;
+- }
+- /* analysis QMF */
+- for (ch = 0;
+- ch < ((pelInfo->fParametricStereo) ? 2 : pelInfo->nChannelsInEl);
+- ch++) {
+- hSbrElement->elInfo.ChannelIndex[ch] = pelInfo->ChannelIndex[ch];
+- hSbrElement->hQmfAnalysis[ch] = &hSbrEncoder->QmfAnalysis[totalQmf++];
+- }
+-
+- /* Copy Element info */
+- hSbrElement->elInfo.elType = pelInfo->elType;
+- hSbrElement->elInfo.instanceTag = pelInfo->instanceTag;
+- hSbrElement->elInfo.nChannelsInEl = pelInfo->nChannelsInEl;
+- hSbrElement->elInfo.fParametricStereo = pelInfo->fParametricStereo;
+- hSbrElement->elInfo.fDualMono = pelInfo->fDualMono;
+- } /* coreEl */
+-
+- return 0;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_bsBufInit
+- description: initializes bitstream buffer
+- returns: initialized bitstream buffer in env encoder
+- input:
+- output: hEnv
+-
+-*****************************************************************************/
+-static INT FDKsbrEnc_bsBufInit(HANDLE_SBR_ELEMENT hSbrElement,
+- int nBitstrDelay) {
+- UCHAR *bitstreamBuffer;
+-
+- /* initialize the bitstream buffer */
+- bitstreamBuffer = hSbrElement->payloadDelayLine[nBitstrDelay];
+- FDKinitBitStream(&hSbrElement->CmonData.sbrBitbuf, bitstreamBuffer,
+- MAX_PAYLOAD_SIZE * sizeof(UCHAR), 0, BS_WRITER);
+-
+- return (0);
+-}
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_EnvInit
+- description: initializes parameters
+- returns: error status
+- input:
+- output: hEnv
+-
+-*****************************************************************************/
+-static INT FDKsbrEnc_EnvInit(HANDLE_SBR_ELEMENT hSbrElement,
+- sbrConfigurationPtr params, INT *coreBandWith,
+- AUDIO_OBJECT_TYPE aot, int nElement,
+- const int headerPeriod, ULONG statesInitFlag,
+- const SBRENC_DS_TYPE downsamplingMethod,
+- UCHAR *dynamic_RAM) {
+- int ch, i;
+-
+- if ((params->codecSettings.nChannels < 1) ||
+- (params->codecSettings.nChannels > MAX_NUM_CHANNELS)) {
+- return (1);
+- }
+-
+- /* init and set syntax flags */
+- hSbrElement->sbrConfigData.sbrSyntaxFlags = 0;
+-
+- switch (aot) {
+- case AOT_ER_AAC_ELD:
+- hSbrElement->sbrConfigData.sbrSyntaxFlags |= SBR_SYNTAX_LOW_DELAY;
+- break;
+- default:
+- break;
+- }
+- if (params->crcSbr) {
+- hSbrElement->sbrConfigData.sbrSyntaxFlags |= SBR_SYNTAX_CRC;
+- }
+-
+- hSbrElement->sbrConfigData.noQmfBands = 64 >> (2 - params->downSampleFactor);
+- switch (hSbrElement->sbrConfigData.noQmfBands) {
+- case 64:
+- hSbrElement->sbrConfigData.noQmfSlots = params->sbrFrameSize >> 6;
+- break;
+- case 32:
+- hSbrElement->sbrConfigData.noQmfSlots = params->sbrFrameSize >> 5;
+- break;
+- default:
+- hSbrElement->sbrConfigData.noQmfSlots = params->sbrFrameSize >> 6;
+- return (2);
+- }
+-
+- /*
+- now initialize sbrConfigData, sbrHeaderData and sbrBitstreamData,
+- */
+- hSbrElement->sbrConfigData.nChannels = params->codecSettings.nChannels;
+-
+- if (params->codecSettings.nChannels == 2) {
+- if ((hSbrElement->elInfo.elType == ID_CPE) &&
+- ((hSbrElement->elInfo.fDualMono == 1))) {
+- hSbrElement->sbrConfigData.stereoMode = SBR_LEFT_RIGHT;
+- } else {
+- hSbrElement->sbrConfigData.stereoMode = params->stereoMode;
+- }
+- } else {
+- hSbrElement->sbrConfigData.stereoMode = SBR_MONO;
+- }
+-
+- hSbrElement->sbrConfigData.frameSize = params->sbrFrameSize;
+-
+- hSbrElement->sbrConfigData.sampleFreq =
+- params->downSampleFactor * params->codecSettings.sampleFreq;
+-
+- hSbrElement->sbrBitstreamData.CountSendHeaderData = 0;
+- if (params->SendHeaderDataTime > 0) {
+- if (headerPeriod == -1) {
+- hSbrElement->sbrBitstreamData.NrSendHeaderData = (INT)(
+- params->SendHeaderDataTime * hSbrElement->sbrConfigData.sampleFreq /
+- (1000 * hSbrElement->sbrConfigData.frameSize));
+- hSbrElement->sbrBitstreamData.NrSendHeaderData =
+- fixMax(hSbrElement->sbrBitstreamData.NrSendHeaderData, 1);
+- } else {
+- /* assure header period at least once per second */
+- hSbrElement->sbrBitstreamData.NrSendHeaderData = fixMin(
+- fixMax(headerPeriod, 1), (hSbrElement->sbrConfigData.sampleFreq /
+- hSbrElement->sbrConfigData.frameSize));
+- }
+- } else {
+- hSbrElement->sbrBitstreamData.NrSendHeaderData = 0;
+- }
+-
+- hSbrElement->sbrHeaderData.sbr_data_extra = params->sbr_data_extra;
+- hSbrElement->sbrBitstreamData.HeaderActive = 0;
+- hSbrElement->sbrBitstreamData.rightBorderFIX = 0;
+- hSbrElement->sbrHeaderData.sbr_start_frequency = params->startFreq;
+- hSbrElement->sbrHeaderData.sbr_stop_frequency = params->stopFreq;
+- hSbrElement->sbrHeaderData.sbr_xover_band = 0;
+- hSbrElement->sbrHeaderData.sbr_lc_stereo_mode = 0;
+-
+- /* data_extra */
+- if (params->sbr_xpos_ctrl != SBR_XPOS_CTRL_DEFAULT)
+- hSbrElement->sbrHeaderData.sbr_data_extra = 1;
+-
+- hSbrElement->sbrHeaderData.sbr_amp_res = (AMP_RES)params->amp_res;
+-
+- /* header_extra_1 */
+- hSbrElement->sbrHeaderData.freqScale = params->freqScale;
+- hSbrElement->sbrHeaderData.alterScale = params->alterScale;
+- hSbrElement->sbrHeaderData.sbr_noise_bands = params->sbr_noise_bands;
+- hSbrElement->sbrHeaderData.header_extra_1 = 0;
+-
+- if ((params->freqScale != SBR_FREQ_SCALE_DEFAULT) ||
+- (params->alterScale != SBR_ALTER_SCALE_DEFAULT) ||
+- (params->sbr_noise_bands != SBR_NOISE_BANDS_DEFAULT)) {
+- hSbrElement->sbrHeaderData.header_extra_1 = 1;
+- }
+-
+- /* header_extra_2 */
+- hSbrElement->sbrHeaderData.sbr_limiter_bands = params->sbr_limiter_bands;
+- hSbrElement->sbrHeaderData.sbr_limiter_gains = params->sbr_limiter_gains;
+-
+- if ((hSbrElement->sbrConfigData.sampleFreq > 48000) &&
+- (hSbrElement->sbrHeaderData.sbr_start_frequency >= 9)) {
+- hSbrElement->sbrHeaderData.sbr_limiter_gains = SBR_LIMITER_GAINS_INFINITE;
+- }
+-
+- hSbrElement->sbrHeaderData.sbr_interpol_freq = params->sbr_interpol_freq;
+- hSbrElement->sbrHeaderData.sbr_smoothing_length =
+- params->sbr_smoothing_length;
+- hSbrElement->sbrHeaderData.header_extra_2 = 0;
+-
+- if ((params->sbr_limiter_bands != SBR_LIMITER_BANDS_DEFAULT) ||
+- (params->sbr_limiter_gains != SBR_LIMITER_GAINS_DEFAULT) ||
+- (params->sbr_interpol_freq != SBR_INTERPOL_FREQ_DEFAULT) ||
+- (params->sbr_smoothing_length != SBR_SMOOTHING_LENGTH_DEFAULT)) {
+- hSbrElement->sbrHeaderData.header_extra_2 = 1;
+- }
+-
+- /* other switches */
+- hSbrElement->sbrConfigData.useWaveCoding = params->useWaveCoding;
+- hSbrElement->sbrConfigData.useParametricCoding = params->parametricCoding;
+- hSbrElement->sbrConfigData.thresholdAmpResFF_m =
+- params->threshold_AmpRes_FF_m;
+- hSbrElement->sbrConfigData.thresholdAmpResFF_e =
+- params->threshold_AmpRes_FF_e;
+-
+- /* init freq band table */
+- if (updateFreqBandTable(&hSbrElement->sbrConfigData,
+- &hSbrElement->sbrHeaderData,
+- params->downSampleFactor)) {
+- return (1);
+- }
+-
+- /* now create envelope ext and QMF for each available channel */
+- for (ch = 0; ch < hSbrElement->sbrConfigData.nChannels; ch++) {
+- if (initEnvChannel(&hSbrElement->sbrConfigData, &hSbrElement->sbrHeaderData,
+- &hSbrElement->sbrChannel[ch]->hEnvChannel, params,
+- statesInitFlag, ch, dynamic_RAM)) {
+- return (1);
+- }
+-
+- } /* nChannels */
+-
+- /* reset and intialize analysis qmf */
+- for (ch = 0; ch < ((hSbrElement->elInfo.fParametricStereo)
+- ? 2
+- : hSbrElement->sbrConfigData.nChannels);
+- ch++) {
+- int err;
+- UINT qmfFlags =
+- (hSbrElement->sbrConfigData.sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY)
+- ? QMF_FLAG_CLDFB
+- : 0;
+- if (statesInitFlag)
+- qmfFlags &= ~QMF_FLAG_KEEP_STATES;
+- else
+- qmfFlags |= QMF_FLAG_KEEP_STATES;
+-
+- err = qmfInitAnalysisFilterBank(
+- hSbrElement->hQmfAnalysis[ch],
+- (FIXP_QAS *)hSbrElement->hQmfAnalysis[ch]->FilterStates,
+- hSbrElement->sbrConfigData.noQmfSlots,
+- hSbrElement->sbrConfigData.noQmfBands,
+- hSbrElement->sbrConfigData.noQmfBands,
+- hSbrElement->sbrConfigData.noQmfBands, qmfFlags);
+- if (0 != err) {
+- return err;
+- }
+- }
+-
+- /* */
+- hSbrElement->CmonData.xOverFreq = hSbrElement->sbrConfigData.xOverFreq;
+- hSbrElement->CmonData.dynBwEnabled =
+- (params->dynBwSupported && params->dynBwEnabled);
+- hSbrElement->CmonData.dynXOverFreqEnc =
+- FDKsbrEnc_SbrGetXOverFreq(hSbrElement, hSbrElement->CmonData.xOverFreq);
+- for (i = 0; i < 5; i++)
+- hSbrElement->dynXOverFreqDelay[i] = hSbrElement->CmonData.dynXOverFreqEnc;
+- hSbrElement->CmonData.sbrNumChannels = hSbrElement->sbrConfigData.nChannels;
+- hSbrElement->sbrConfigData.dynXOverFreq = hSbrElement->CmonData.xOverFreq;
+-
+- /* Update Bandwith to be passed to the core encoder */
+- *coreBandWith = hSbrElement->CmonData.xOverFreq;
+-
+- return (0);
+-}
+-
+-INT sbrEncoder_GetInBufferSize(int noChannels) {
+- INT temp;
+-
+- temp = (2048);
+- temp += 1024 + MAX_SAMPLE_DELAY;
+- temp *= noChannels;
+- temp *= sizeof(INT_PCM);
+- return temp;
+-}
+-
+-/*
+- * Encode Dummy SBR payload frames to fill the delay lines.
+- */
+-static INT FDKsbrEnc_DelayCompensation(HANDLE_SBR_ENCODER hEnvEnc,
+- INT_PCM *timeBuffer,
+- UINT timeBufferBufSize) {
+- int n, el;
+-
+- for (n = hEnvEnc->nBitstrDelay; n > 0; n--) {
+- for (el = 0; el < hEnvEnc->noElements; el++) {
+- if (FDKsbrEnc_EnvEncodeFrame(
+- hEnvEnc, el,
+- timeBuffer + hEnvEnc->downsampledOffset / hEnvEnc->nChannels,
+- timeBufferBufSize, NULL, NULL, 1))
+- return -1;
+- }
+- sbrEncoder_UpdateBuffers(hEnvEnc, timeBuffer, timeBufferBufSize);
+- }
+- return 0;
+-}
+-
+-UINT sbrEncoder_LimitBitRate(UINT bitRate, UINT numChannels,
+- UINT coreSampleRate, AUDIO_OBJECT_TYPE aot) {
+- UINT newBitRate = bitRate;
+- INT index;
+-
+- FDK_ASSERT(numChannels > 0 && numChannels <= 2);
+- if (aot == AOT_PS) {
+- if (numChannels == 1) {
+- index = getPsTuningTableIndex(bitRate, &newBitRate);
+- if (index == INVALID_TABLE_IDX) {
+- bitRate = newBitRate;
+- }
+- } else {
+- return 0;
+- }
+- }
+- index = getSbrTuningTableIndex(bitRate, numChannels, coreSampleRate, aot,
+- &newBitRate);
+- if (index != INVALID_TABLE_IDX) {
+- newBitRate = bitRate;
+- }
+-
+- return newBitRate;
+-}
+-
+-UINT sbrEncoder_IsSingleRatePossible(AUDIO_OBJECT_TYPE aot) {
+- UINT isPossible = (AOT_PS == aot) ? 0 : 1;
+- return isPossible;
+-}
+-
+-/*****************************************************************************/
+-/* */
+-/*functionname: sbrEncoder_Init_delay */
+-/*description: Determine Delay balancing and new encoder delay */
+-/* */
+-/*returns: - error status */
+-/*input: - frame length of the core (i.e. e.g. AAC) */
+-/* - number of channels */
+-/* - downsample factor (1 for downsampled, 2 for dual-rate SBR) */
+-/* - low delay presence */
+-/* - ps presence */
+-/* - downsampling method: QMF-, time domain or no downsampling */
+-/* - various delay values (see DELAY_PARAM struct description) */
+-/* */
+-/*Example: Delay balancing for a HE-AACv1 encoder (time-domain downsampling) */
+-/*========================================================================== */
+-/* */
+-/* +--------+ +--------+ +--------+ +--------+ +--------+ */
+-/* |core | |ds 2:1 | |AAC | |QMF | |QMF | */
+-/* +-+path +------------+ +-+core +-+analysis+-+overlap +-+ */
+-/* | |offset | | | | | |32 bands| | | | */
+-/* | +--------+ +--------+ +--------+ +--------+ +--------+ | */
+-/* | core path +-------++ */
+-/* | |QMF | */
+-/*->+ +synth. +-> */
+-/* | |64 bands| */
+-/* | +-------++ */
+-/* | +--------+ +--------+ +--------+ +--------+ | */
+-/* | |SBR path| |QMF | |subband | |bs delay| | */
+-/* +-+offset +-+analysis+-+sample +-+(full +-----------------------+ */
+-/* | | |64 bands| |buffer | | frames)| */
+-/* +--------+ +--------+ +--------+ +--------+ */
+-/* SBR path */
+-/* */
+-/*****************************************************************************/
+-static INT sbrEncoder_Init_delay(
+- const int coreFrameLength, /* input */
+- const int numChannels, /* input */
+- const int downSampleFactor, /* input */
+- const int lowDelay, /* input */
+- const int usePs, /* input */
+- const int is212, /* input */
+- const SBRENC_DS_TYPE downsamplingMethod, /* input */
+- DELAY_PARAM *hDelayParam /* input/output */
+-) {
+- int delayCorePath = 0; /* delay in core path */
+- int delaySbrPath = 0; /* delay difference in QMF aka SBR path */
+- int delayInput2Core = 0; /* delay from the input to the core */
+- int delaySbrDec = 0; /* delay of the decoder's SBR module */
+-
+- int delayCore = hDelayParam->delay; /* delay of the core */
+-
+- /* Added delay by the SBR delay initialization */
+- int corePathOffset = 0; /* core path */
+- int sbrPathOffset = 0; /* sbr path */
+- int bitstreamDelay = 0; /* sbr path, framewise */
+-
+- int flCore = coreFrameLength; /* core frame length */
+-
+- int returnValue = 0; /* return value - 0 means: no error */
+-
+- /* 1) Calculate actual delay for core and SBR path */
+- if (is212) {
+- delayCorePath = DELAY_COREPATH_ELDv2SBR(flCore, downSampleFactor);
+- delaySbrPath = DELAY_ELDv2SBR(flCore, downSampleFactor);
+- delaySbrDec = ((flCore) / 2) * (downSampleFactor);
+- } else if (lowDelay) {
+- delayCorePath = DELAY_COREPATH_ELDSBR(flCore, downSampleFactor);
+- delaySbrPath = DELAY_ELDSBR(flCore, downSampleFactor);
+- delaySbrDec = DELAY_QMF_POSTPROC(downSampleFactor);
+- } else if (usePs) {
+- delayCorePath = DELAY_COREPATH_PS(flCore, downSampleFactor);
+- delaySbrPath = DELAY_PS(flCore, downSampleFactor);
+- delaySbrDec = DELAY_COREPATH_SBR(flCore, downSampleFactor);
+- } else {
+- delayCorePath = DELAY_COREPATH_SBR(flCore, downSampleFactor);
+- delaySbrPath = DELAY_SBR(flCore, downSampleFactor);
+- delaySbrDec = DELAY_COREPATH_SBR(flCore, downSampleFactor);
+- }
+- delayCorePath += delayCore * downSampleFactor;
+- delayCorePath +=
+- (downsamplingMethod == SBRENC_DS_TIME) ? hDelayParam->dsDelay : 0;
+-
+- /* 2) Manage coupling of paths */
+- if (downsamplingMethod == SBRENC_DS_QMF && delayCorePath > delaySbrPath) {
+- /* In case of QMF downsampling, both paths are coupled, i.e. the SBR path
+- offset would be added to both the SBR path and to the core path
+- as well, thus making it impossible to achieve delay balancing.
+- To overcome that problem, a framewise delay is added to the SBR path
+- first, until the overall delay of the core path is shorter than
+- the delay of the SBR path. When this is achieved, the missing delay
+- difference can be added as downsampled offset to the core path.
+- */
+- while (delayCorePath > delaySbrPath) {
+- /* Add one frame delay to SBR path */
+- delaySbrPath += flCore * downSampleFactor;
+- bitstreamDelay += 1;
+- }
+- }
+-
+- /* 3) Calculate necessary additional delay to balance the paths */
+- if (delayCorePath > delaySbrPath) {
+- /* Delay QMF input */
+- while (delayCorePath > delaySbrPath + (int)flCore * (int)downSampleFactor) {
+- /* Do bitstream frame-wise delay balancing if there are
+- more than SBR framelength samples delay difference */
+- delaySbrPath += flCore * downSampleFactor;
+- bitstreamDelay += 1;
+- }
+- /* Multiply input offset by input channels */
+- corePathOffset = 0;
+- sbrPathOffset = (delayCorePath - delaySbrPath) * numChannels;
+- } else {
+- /* Delay AAC data */
+- /* Multiply downsampled offset by AAC core channels. Divide by 2 because of
+- half samplerate of downsampled data. */
+- corePathOffset = ((delaySbrPath - delayCorePath) * numChannels) >>
+- (downSampleFactor - 1);
+- sbrPathOffset = 0;
+- }
+-
+- /* 4) Calculate delay from input to core */
+- if (usePs) {
+- delayInput2Core =
+- (DELAY_QMF_ANA(downSampleFactor) + DELAY_QMF_DS + DELAY_HYB_SYN) +
+- (downSampleFactor * corePathOffset) + 1;
+- } else if (downsamplingMethod == SBRENC_DS_TIME) {
+- delayInput2Core = corePathOffset + hDelayParam->dsDelay;
+- } else {
+- delayInput2Core = corePathOffset;
+- }
+-
+- /* 6) Set output parameters */
+- hDelayParam->delay = FDKmax(delayCorePath, delaySbrPath); /* overall delay */
+- hDelayParam->sbrDecDelay = delaySbrDec; /* SBR decoder delay */
+- hDelayParam->delayInput2Core = delayInput2Core; /* delay input - core */
+- hDelayParam->bitstrDelay = bitstreamDelay; /* bitstream delay, in frames */
+- hDelayParam->corePathOffset = corePathOffset; /* offset added to core path */
+- hDelayParam->sbrPathOffset = sbrPathOffset; /* offset added to SBR path */
+-
+- return returnValue;
+-}
+-
+-/*****************************************************************************
+-
+- functionname: sbrEncoder_Init
+- description: initializes the SBR encoder
+- returns: error status
+-
+-*****************************************************************************/
+-INT sbrEncoder_Init(HANDLE_SBR_ENCODER hSbrEncoder,
+- SBR_ELEMENT_INFO elInfo[(8)], int noElements,
+- INT_PCM *inputBuffer, UINT inputBufferBufSize,
+- INT *coreBandwidth, INT *inputBufferOffset,
+- INT *numChannels, const UINT syntaxFlags,
+- INT *coreSampleRate, UINT *downSampleFactor,
+- INT *frameLength, AUDIO_OBJECT_TYPE aot, int *delay,
+- int transformFactor, const int headerPeriod,
+- ULONG statesInitFlag) {
+- HANDLE_ERROR_INFO errorInfo = noError;
+- sbrConfiguration sbrConfig[(8)];
+- INT error = 0;
+- INT lowestBandwidth;
+- /* Save input parameters */
+- INT inputSampleRate = *coreSampleRate;
+- int coreFrameLength = *frameLength;
+- int inputBandWidth = *coreBandwidth;
+- int inputChannels = *numChannels;
+-
+- SBRENC_DS_TYPE downsamplingMethod = SBRENC_DS_NONE;
+- int highestSbrStartFreq, highestSbrStopFreq;
+- int lowDelay = 0;
+- int usePs = 0;
+- int is212 = 0;
+-
+- DELAY_PARAM delayParam;
+-
+- /* check whether SBR setting is available for the current encoder
+- * configuration (bitrate, samplerate) */
+- if (!sbrEncoder_IsSingleRatePossible(aot)) {
+- *downSampleFactor = 2;
+- }
+-
+- if (aot == AOT_PS) {
+- usePs = 1;
+- }
+- if (aot == AOT_ER_AAC_ELD) {
+- lowDelay = 1;
+- } else if (aot == AOT_ER_AAC_LD) {
+- error = 1;
+- goto bail;
+- }
+-
+- /* Parametric Stereo */
+- if (usePs) {
+- if (*numChannels == 2 && noElements == 1) {
+- /* Override Element type in case of Parametric stereo */
+- elInfo[0].elType = ID_SCE;
+- elInfo[0].fParametricStereo = 1;
+- elInfo[0].nChannelsInEl = 1;
+- /* core encoder gets downmixed mono signal */
+- *numChannels = 1;
+- } else {
+- error = 1;
+- goto bail;
+- }
+- } /* usePs */
+-
+- /* set the core's sample rate */
+- switch (*downSampleFactor) {
+- case 1:
+- *coreSampleRate = inputSampleRate;
+- downsamplingMethod = SBRENC_DS_NONE;
+- break;
+- case 2:
+- *coreSampleRate = inputSampleRate >> 1;
+- downsamplingMethod = usePs ? SBRENC_DS_QMF : SBRENC_DS_TIME;
+- break;
+- default:
+- *coreSampleRate = inputSampleRate >> 1;
+- return 0; /* return error */
+- }
+-
+- /* check whether SBR setting is available for the current encoder
+- * configuration (bitrate, coreSampleRate) */
+- {
+- int el, coreEl;
+-
+- /* Check if every element config is feasible */
+- for (coreEl = 0; coreEl < noElements; coreEl++) {
+- /* SBR only handles SCE and CPE's */
+- if (elInfo[coreEl].elType != ID_SCE && elInfo[coreEl].elType != ID_CPE) {
+- continue;
+- }
+- /* check if desired configuration is available */
+- if (!FDKsbrEnc_IsSbrSettingAvail(elInfo[coreEl].bitRate, 0,
+- elInfo[coreEl].nChannelsInEl,
+- inputSampleRate, *coreSampleRate, aot)) {
+- error = 1;
+- goto bail;
+- }
+- }
+-
+- hSbrEncoder->nChannels = *numChannels;
+- hSbrEncoder->frameSize = coreFrameLength * *downSampleFactor;
+- hSbrEncoder->downsamplingMethod = downsamplingMethod;
+- hSbrEncoder->downSampleFactor = *downSampleFactor;
+- hSbrEncoder->estimateBitrate = 0;
+- hSbrEncoder->inputDataDelay = 0;
+- is212 = ((aot == AOT_ER_AAC_ELD) && (syntaxFlags & AC_LD_MPS)) ? 1 : 0;
+-
+- /* Open SBR elements */
+- el = -1;
+- highestSbrStartFreq = highestSbrStopFreq = 0;
+- lowestBandwidth = 99999;
+-
+- /* Loop through each core encoder element and get a matching SBR element
+- * config */
+- for (coreEl = 0; coreEl < noElements; coreEl++) {
+- /* SBR only handles SCE and CPE's */
+- if (elInfo[coreEl].elType == ID_SCE || elInfo[coreEl].elType == ID_CPE) {
+- el++;
+- } else {
+- continue;
+- }
+-
+- /* Set parametric Stereo Flag. */
+- if (usePs) {
+- elInfo[coreEl].fParametricStereo = 1;
+- } else {
+- elInfo[coreEl].fParametricStereo = 0;
+- }
+-
+- /*
+- * Init sbrConfig structure
+- */
+- if (!FDKsbrEnc_InitializeSbrDefaults(&sbrConfig[el], *downSampleFactor,
+- coreFrameLength, IS_LOWDELAY(aot))) {
+- error = 1;
+- goto bail;
+- }
+-
+- /*
+- * Modify sbrConfig structure according to Element parameters
+- */
+- if (!FDKsbrEnc_AdjustSbrSettings(
+- &sbrConfig[el], elInfo[coreEl].bitRate,
+- elInfo[coreEl].nChannelsInEl, *coreSampleRate, inputSampleRate,
+- transformFactor, 24000, 0, 0, /* useSpeechConfig */
+- 0, /* lcsMode */
+- usePs, /* bParametricStereo */
+- aot)) {
+- error = 1;
+- goto bail;
+- }
+-
+- /* Find common frequency border for all SBR elements */
+- highestSbrStartFreq =
+- fixMax(highestSbrStartFreq, sbrConfig[el].startFreq);
+- highestSbrStopFreq = fixMax(highestSbrStopFreq, sbrConfig[el].stopFreq);
+-
+- } /* first element loop */
+-
+- /* Set element count (can be less than core encoder element count) */
+- hSbrEncoder->noElements = el + 1;
+-
+- FDKsbrEnc_Reallocate(hSbrEncoder, elInfo, noElements);
+-
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- int bandwidth = *coreBandwidth;
+-
+- /* Use lowest common bandwidth */
+- sbrConfig[el].startFreq = highestSbrStartFreq;
+- sbrConfig[el].stopFreq = highestSbrStopFreq;
+-
+- /* initialize SBR element, and get core bandwidth */
+- error = FDKsbrEnc_EnvInit(hSbrEncoder->sbrElement[el], &sbrConfig[el],
+- &bandwidth, aot, el, headerPeriod,
+- statesInitFlag, hSbrEncoder->downsamplingMethod,
+- hSbrEncoder->dynamicRam);
+-
+- if (error != 0) {
+- error = 2;
+- goto bail;
+- }
+-
+- /* Get lowest core encoder bandwidth to be returned later. */
+- lowestBandwidth = fixMin(lowestBandwidth, bandwidth);
+-
+- } /* second element loop */
+-
+- /* Initialize a downsampler for each channel in each SBR element */
+- if (hSbrEncoder->downsamplingMethod == SBRENC_DS_TIME) {
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- HANDLE_SBR_ELEMENT hSbrEl = hSbrEncoder->sbrElement[el];
+- INT Wc, ch;
+-
+- Wc = 500; /* Cutoff frequency with full bandwidth */
+-
+- for (ch = 0; ch < hSbrEl->elInfo.nChannelsInEl; ch++) {
+- FDKaacEnc_InitDownsampler(&hSbrEl->sbrChannel[ch]->downSampler, Wc,
+- *downSampleFactor);
+- FDK_ASSERT(hSbrEl->sbrChannel[ch]->downSampler.delay <=
+- MAX_DS_FILTER_DELAY);
+- }
+- } /* third element loop */
+-
+- /* lfe */
+- FDKaacEnc_InitDownsampler(&hSbrEncoder->lfeDownSampler, 0,
+- *downSampleFactor);
+- }
+-
+- /* Get delay information */
+- delayParam.dsDelay =
+- hSbrEncoder->sbrElement[0]->sbrChannel[0]->downSampler.delay;
+- delayParam.delay = *delay;
+-
+- error = sbrEncoder_Init_delay(coreFrameLength, *numChannels,
+- *downSampleFactor, lowDelay, usePs, is212,
+- downsamplingMethod, &delayParam);
+-
+- if (error != 0) {
+- error = 3;
+- goto bail;
+- }
+-
+- hSbrEncoder->nBitstrDelay = delayParam.bitstrDelay;
+- hSbrEncoder->sbrDecDelay = delayParam.sbrDecDelay;
+- hSbrEncoder->inputDataDelay = delayParam.delayInput2Core;
+-
+- /* Assign core encoder Bandwidth */
+- *coreBandwidth = lowestBandwidth;
+-
+- /* Estimate sbr bitrate, 2.5 kBit/s per sbr channel */
+- hSbrEncoder->estimateBitrate += 2500 * (*numChannels);
+-
+- /* Initialize bitstream buffer for each element */
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- FDKsbrEnc_bsBufInit(hSbrEncoder->sbrElement[el], delayParam.bitstrDelay);
+- }
+-
+- /* initialize parametric stereo */
+- if (usePs) {
+- PSENC_CONFIG psEncConfig;
+- FDK_ASSERT(hSbrEncoder->noElements == 1);
+- INT psTuningTableIdx = getPsTuningTableIndex(elInfo[0].bitRate, NULL);
+-
+- psEncConfig.frameSize = coreFrameLength; // sbrConfig.sbrFrameSize;
+- psEncConfig.qmfFilterMode = 0;
+- psEncConfig.sbrPsDelay = 0;
+-
+- /* tuning parameters */
+- if (psTuningTableIdx != INVALID_TABLE_IDX) {
+- psEncConfig.nStereoBands = psTuningTable[psTuningTableIdx].nStereoBands;
+- psEncConfig.maxEnvelopes = psTuningTable[psTuningTableIdx].nEnvelopes;
+- psEncConfig.iidQuantErrorThreshold =
+- (FIXP_DBL)psTuningTable[psTuningTableIdx].iidQuantErrorThreshold;
+-
+- /* calculation is not quite linear, increased number of envelopes causes
+- * more bits */
+- /* assume avg. 50 bits per frame for 10 stereo bands / 1 envelope
+- * configuration */
+- hSbrEncoder->estimateBitrate +=
+- ((((*coreSampleRate) * 5 * psEncConfig.nStereoBands *
+- psEncConfig.maxEnvelopes) /
+- hSbrEncoder->frameSize));
+-
+- } else {
+- error = ERROR(CDI, "Invalid ps tuning table index.");
+- goto bail;
+- }
+-
+- qmfInitSynthesisFilterBank(
+- &hSbrEncoder->qmfSynthesisPS,
+- (FIXP_DBL *)hSbrEncoder->qmfSynthesisPS.FilterStates,
+- hSbrEncoder->sbrElement[0]->sbrConfigData.noQmfSlots,
+- hSbrEncoder->sbrElement[0]->sbrConfigData.noQmfBands >> 1,
+- hSbrEncoder->sbrElement[0]->sbrConfigData.noQmfBands >> 1,
+- hSbrEncoder->sbrElement[0]->sbrConfigData.noQmfBands >> 1,
+- (statesInitFlag) ? 0 : QMF_FLAG_KEEP_STATES);
+-
+- if (errorInfo == noError) {
+- /* update delay */
+- psEncConfig.sbrPsDelay =
+- FDKsbrEnc_GetEnvEstDelay(&hSbrEncoder->sbrElement[0]
+- ->sbrChannel[0]
+- ->hEnvChannel.sbrExtractEnvelope);
+-
+- errorInfo =
+- PSEnc_Init(hSbrEncoder->hParametricStereo, &psEncConfig,
+- hSbrEncoder->sbrElement[0]->sbrConfigData.noQmfSlots,
+- hSbrEncoder->sbrElement[0]->sbrConfigData.noQmfBands,
+- hSbrEncoder->dynamicRam);
+- }
+- }
+-
+- hSbrEncoder->downsampledOffset = delayParam.corePathOffset;
+- hSbrEncoder->bufferOffset = delayParam.sbrPathOffset;
+- *delay = delayParam.delay;
+-
+- { hSbrEncoder->downmixSize = coreFrameLength * (*numChannels); }
+-
+- /* Delay Compensation: fill bitstream delay buffer with zero input signal */
+- if (hSbrEncoder->nBitstrDelay > 0) {
+- error = FDKsbrEnc_DelayCompensation(hSbrEncoder, inputBuffer,
+- inputBufferBufSize);
+- if (error != 0) goto bail;
+- }
+-
+- /* Set Output frame length */
+- *frameLength = coreFrameLength * *downSampleFactor;
+- /* Input buffer offset */
+- *inputBufferOffset =
+- fixMax(delayParam.sbrPathOffset, delayParam.corePathOffset);
+- }
+-
+- return error;
+-
+-bail:
+- /* Restore input settings */
+- *coreSampleRate = inputSampleRate;
+- *frameLength = coreFrameLength;
+- *numChannels = inputChannels;
+- *coreBandwidth = inputBandWidth;
+-
+- return error;
+-}
+-
+-INT sbrEncoder_EncodeFrame(HANDLE_SBR_ENCODER hSbrEncoder, INT_PCM *samples,
+- UINT samplesBufSize, UINT sbrDataBits[(8)],
+- UCHAR sbrData[(8)][MAX_PAYLOAD_SIZE]) {
+- INT error;
+- int el;
+-
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- if (hSbrEncoder->sbrElement[el] != NULL) {
+- error = FDKsbrEnc_EnvEncodeFrame(
+- hSbrEncoder, el,
+- samples + hSbrEncoder->downsampledOffset / hSbrEncoder->nChannels,
+- samplesBufSize, &sbrDataBits[el], sbrData[el], 0);
+- if (error) return error;
+- }
+- }
+-
+- error = FDKsbrEnc_Downsample(
+- hSbrEncoder,
+- samples + hSbrEncoder->downsampledOffset / hSbrEncoder->nChannels,
+- samplesBufSize, hSbrEncoder->nChannels, &sbrDataBits[el], sbrData[el], 0);
+- if (error) return error;
+-
+- return 0;
+-}
+-
+-INT sbrEncoder_UpdateBuffers(HANDLE_SBR_ENCODER hSbrEncoder,
+- INT_PCM *timeBuffer, UINT timeBufferBufSize) {
+- if (hSbrEncoder->downsampledOffset > 0) {
+- int c;
+- int nd = hSbrEncoder->downmixSize / hSbrEncoder->nChannels;
+-
+- for (c = 0; c < hSbrEncoder->nChannels; c++) {
+- /* Move delayed downsampled data */
+- FDKmemcpy(timeBuffer + timeBufferBufSize * c,
+- timeBuffer + timeBufferBufSize * c + nd,
+- sizeof(INT_PCM) *
+- (hSbrEncoder->downsampledOffset / hSbrEncoder->nChannels));
+- }
+- } else {
+- int c;
+-
+- for (c = 0; c < hSbrEncoder->nChannels; c++) {
+- /* Move delayed input data */
+- FDKmemcpy(
+- timeBuffer + timeBufferBufSize * c,
+- timeBuffer + timeBufferBufSize * c + hSbrEncoder->frameSize,
+- sizeof(INT_PCM) * hSbrEncoder->bufferOffset / hSbrEncoder->nChannels);
+- }
+- }
+- if (hSbrEncoder->nBitstrDelay > 0) {
+- int el;
+-
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- FDKmemmove(
+- hSbrEncoder->sbrElement[el]->payloadDelayLine[0],
+- hSbrEncoder->sbrElement[el]->payloadDelayLine[1],
+- sizeof(UCHAR) * (hSbrEncoder->nBitstrDelay * MAX_PAYLOAD_SIZE));
+-
+- FDKmemmove(&hSbrEncoder->sbrElement[el]->payloadDelayLineSize[0],
+- &hSbrEncoder->sbrElement[el]->payloadDelayLineSize[1],
+- sizeof(UINT) * (hSbrEncoder->nBitstrDelay));
+- }
+- }
+- return 0;
+-}
+-
+-INT sbrEncoder_SendHeader(HANDLE_SBR_ENCODER hSbrEncoder) {
+- INT error = -1;
+- if (hSbrEncoder) {
+- int el;
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- if ((hSbrEncoder->noElements == 1) &&
+- (hSbrEncoder->sbrElement[0]->elInfo.fParametricStereo == 1)) {
+- hSbrEncoder->sbrElement[el]->sbrBitstreamData.CountSendHeaderData =
+- hSbrEncoder->sbrElement[el]->sbrBitstreamData.NrSendHeaderData - 1;
+- } else {
+- hSbrEncoder->sbrElement[el]->sbrBitstreamData.CountSendHeaderData = 0;
+- }
+- }
+- error = 0;
+- }
+- return error;
+-}
+-
+-INT sbrEncoder_ContainsHeader(HANDLE_SBR_ENCODER hSbrEncoder) {
+- INT sbrHeader = 1;
+- if (hSbrEncoder) {
+- int el;
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- sbrHeader &=
+- (hSbrEncoder->sbrElement[el]->sbrBitstreamData.HeaderActiveDelay == 1)
+- ? 1
+- : 0;
+- }
+- }
+- return sbrHeader;
+-}
+-
+-INT sbrEncoder_GetHeaderDelay(HANDLE_SBR_ENCODER hSbrEncoder) {
+- INT delay = -1;
+-
+- if (hSbrEncoder) {
+- if ((hSbrEncoder->noElements == 1) &&
+- (hSbrEncoder->sbrElement[0]->elInfo.fParametricStereo == 1)) {
+- delay = hSbrEncoder->nBitstrDelay + 1;
+- } else {
+- delay = hSbrEncoder->nBitstrDelay;
+- }
+- }
+- return delay;
+-}
+-INT sbrEncoder_GetBsDelay(HANDLE_SBR_ENCODER hSbrEncoder) {
+- INT delay = -1;
+-
+- if (hSbrEncoder) {
+- delay = hSbrEncoder->nBitstrDelay;
+- }
+- return delay;
+-}
+-
+-INT sbrEncoder_SAPPrepare(HANDLE_SBR_ENCODER hSbrEncoder) {
+- INT error = -1;
+- if (hSbrEncoder) {
+- int el;
+- for (el = 0; el < hSbrEncoder->noElements; el++) {
+- hSbrEncoder->sbrElement[el]->sbrBitstreamData.rightBorderFIX = 1;
+- }
+- error = 0;
+- }
+- return error;
+-}
+-
+-INT sbrEncoder_GetEstimateBitrate(HANDLE_SBR_ENCODER hSbrEncoder) {
+- INT estimateBitrate = 0;
+-
+- if (hSbrEncoder) {
+- estimateBitrate += hSbrEncoder->estimateBitrate;
+- }
+-
+- return estimateBitrate;
+-}
+-
+-INT sbrEncoder_GetInputDataDelay(HANDLE_SBR_ENCODER hSbrEncoder) {
+- INT delay = -1;
+-
+- if (hSbrEncoder) {
+- delay = hSbrEncoder->inputDataDelay;
+- }
+- return delay;
+-}
+-
+-INT sbrEncoder_GetSbrDecDelay(HANDLE_SBR_ENCODER hSbrEncoder) {
+- INT delay = -1;
+-
+- if (hSbrEncoder) {
+- delay = hSbrEncoder->sbrDecDelay;
+- }
+- return delay;
+-}
+-
+-INT sbrEncoder_GetLibInfo(LIB_INFO *info) {
+- int i;
+-
+- if (info == NULL) {
+- return -1;
+- }
+- /* search for next free tab */
+- for (i = 0; i < FDK_MODULE_LAST; i++) {
+- if (info[i].module_id == FDK_NONE) break;
+- }
+- if (i == FDK_MODULE_LAST) {
+- return -1;
+- }
+- info += i;
+-
+- info->module_id = FDK_SBRENC;
+- info->version =
+- LIB_VERSION(SBRENCODER_LIB_VL0, SBRENCODER_LIB_VL1, SBRENCODER_LIB_VL2);
+- LIB_VERSION_STRING(info);
+-#ifdef __ANDROID__
+- info->build_date = "";
+- info->build_time = "";
+-#else
+- info->build_date = __DATE__;
+- info->build_time = __TIME__;
+-#endif
+- info->title = "SBR Encoder";
+-
+- /* Set flags */
+- info->flags = 0 | CAPF_SBR_HQ | CAPF_SBR_PS_MPEG;
+- /* End of flags */
+-
+- return 0;
+-}
+diff --git a/libSBRenc/src/sbr_misc.cpp b/libSBRenc/src/sbr_misc.cpp
+deleted file mode 100644
+index 83d7e36..0000000
+--- a/libSBRenc/src/sbr_misc.cpp
++++ /dev/null
+@@ -1,265 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Sbr miscellaneous helper functions $Revision: 36750 $
+-*/
+-#include "sbr_misc.h"
+-
+-void FDKsbrEnc_Shellsort_fract(FIXP_DBL *in, INT n) {
+- FIXP_DBL v;
+- INT i, j;
+- INT inc = 1;
+-
+- do
+- inc = 3 * inc + 1;
+- while (inc <= n);
+-
+- do {
+- inc = inc / 3;
+- for (i = inc + 1; i <= n; i++) {
+- v = in[i - 1];
+- j = i;
+- while (in[j - inc - 1] > v) {
+- in[j - 1] = in[j - inc - 1];
+- j -= inc;
+- if (j <= inc) break;
+- }
+- in[j - 1] = v;
+- }
+- } while (inc > 1);
+-}
+-
+-/* Sorting routine */
+-void FDKsbrEnc_Shellsort_int(INT *in, INT n) {
+- INT i, j, v;
+- INT inc = 1;
+-
+- do
+- inc = 3 * inc + 1;
+- while (inc <= n);
+-
+- do {
+- inc = inc / 3;
+- for (i = inc + 1; i <= n; i++) {
+- v = in[i - 1];
+- j = i;
+- while (in[j - inc - 1] > v) {
+- in[j - 1] = in[j - inc - 1];
+- j -= inc;
+- if (j <= inc) break;
+- }
+- in[j - 1] = v;
+- }
+- } while (inc > 1);
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_AddVecLeft
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: INT* dst, INT* length_dst, INT* src, INT length_src
+-
+- Return: none
+-
+-*******************************************************************************/
+-void FDKsbrEnc_AddVecLeft(INT *dst, INT *length_dst, INT *src, INT length_src) {
+- INT i;
+-
+- for (i = length_src - 1; i >= 0; i--)
+- FDKsbrEnc_AddLeft(dst, length_dst, src[i]);
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_AddLeft
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: INT* vector, INT* length_vector, INT value
+-
+- Return: none
+-
+-*******************************************************************************/
+-void FDKsbrEnc_AddLeft(INT *vector, INT *length_vector, INT value) {
+- INT i;
+-
+- for (i = *length_vector; i > 0; i--) vector[i] = vector[i - 1];
+- vector[0] = value;
+- (*length_vector)++;
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_AddRight
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: INT* vector, INT* length_vector, INT value
+-
+- Return: none
+-
+-*******************************************************************************/
+-void FDKsbrEnc_AddRight(INT *vector, INT *length_vector, INT value) {
+- vector[*length_vector] = value;
+- (*length_vector)++;
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_AddVecRight
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments: INT* dst, INT* length_dst, INT* src, INT length_src)
+-
+- Return: none
+-
+-*******************************************************************************/
+-void FDKsbrEnc_AddVecRight(INT *dst, INT *length_dst, INT *src,
+- INT length_src) {
+- INT i;
+- for (i = 0; i < length_src; i++) FDKsbrEnc_AddRight(dst, length_dst, src[i]);
+-}
+-
+-/*****************************************************************************
+-
+- functionname: FDKsbrEnc_LSI_divide_scale_fract
+-
+- description: Calculates division with best precision and scales the result.
+-
+- return: num*scale/denom
+-
+-*****************************************************************************/
+-FIXP_DBL FDKsbrEnc_LSI_divide_scale_fract(FIXP_DBL num, FIXP_DBL denom,
+- FIXP_DBL scale) {
+- FIXP_DBL tmp = FL2FXCONST_DBL(0.0f);
+- if (num != FL2FXCONST_DBL(0.0f)) {
+- INT shiftCommon;
+- INT shiftNum = CountLeadingBits(num);
+- INT shiftDenom = CountLeadingBits(denom);
+- INT shiftScale = CountLeadingBits(scale);
+-
+- num = num << shiftNum;
+- scale = scale << shiftScale;
+-
+- tmp = fMultDiv2(num, scale);
+-
+- if (denom > (tmp >> fixMin(shiftNum + shiftScale - 1, (DFRACT_BITS - 1)))) {
+- denom = denom << shiftDenom;
+- tmp = schur_div(tmp, denom, 15);
+- shiftCommon =
+- fixMin((shiftNum - shiftDenom + shiftScale - 1), (DFRACT_BITS - 1));
+- if (shiftCommon < 0)
+- tmp <<= -shiftCommon;
+- else
+- tmp >>= shiftCommon;
+- } else {
+- tmp = /*FL2FXCONST_DBL(1.0)*/ (FIXP_DBL)MAXVAL_DBL;
+- }
+- }
+-
+- return (tmp);
+-}
+diff --git a/libSBRenc/src/sbr_misc.h b/libSBRenc/src/sbr_misc.h
+deleted file mode 100644
+index fad853f..0000000
+--- a/libSBRenc/src/sbr_misc.h
++++ /dev/null
+@@ -1,127 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Sbr miscellaneous helper functions prototypes $Revision: 92790 $
+- \author
+-*/
+-
+-#ifndef SBR_MISC_H
+-#define SBR_MISC_H
+-
+-#include "sbr_encoder.h"
+-
+-/* Sorting routines */
+-void FDKsbrEnc_Shellsort_fract(FIXP_DBL *in, INT n);
+-void FDKsbrEnc_Shellsort_int(INT *in, INT n);
+-
+-void FDKsbrEnc_AddLeft(INT *vector, INT *length_vector, INT value);
+-void FDKsbrEnc_AddRight(INT *vector, INT *length_vector, INT value);
+-void FDKsbrEnc_AddVecLeft(INT *dst, INT *length_dst, INT *src, INT length_src);
+-void FDKsbrEnc_AddVecRight(INT *dst, INT *length_vector_dst, INT *src,
+- INT length_src);
+-
+-FIXP_DBL FDKsbrEnc_LSI_divide_scale_fract(FIXP_DBL num, FIXP_DBL denom,
+- FIXP_DBL scale);
+-
+-#endif
+diff --git a/libSBRenc/src/sbrenc_freq_sca.cpp b/libSBRenc/src/sbrenc_freq_sca.cpp
+deleted file mode 100644
+index c86e047..0000000
+--- a/libSBRenc/src/sbrenc_freq_sca.cpp
++++ /dev/null
+@@ -1,674 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief frequency scale $Revision: 95225 $
+-*/
+-
+-#include "sbrenc_freq_sca.h"
+-#include "sbr_misc.h"
+-
+-#include "genericStds.h"
+-
+-/* StartFreq */
+-static INT getStartFreq(INT fsCore, const INT start_freq);
+-
+-/* StopFreq */
+-static INT getStopFreq(INT fsCore, const INT stop_freq);
+-
+-static INT numberOfBands(INT b_p_o, INT start, INT stop, FIXP_DBL warp_factor);
+-static void CalcBands(INT *diff, INT start, INT stop, INT num_bands);
+-static INT modifyBands(INT max_band, INT *diff, INT length);
+-static void cumSum(INT start_value, INT *diff, INT length, UCHAR *start_adress);
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_getSbrStartFreqRAW
+- *******************************************************************************
+- Description:
+-
+- Arguments:
+-
+- Return:
+- *******************************************************************************/
+-
+-INT FDKsbrEnc_getSbrStartFreqRAW(INT startFreq, INT fsCore) {
+- INT result;
+-
+- if (startFreq < 0 || startFreq > 15) {
+- return -1;
+- }
+- /* Update startFreq struct */
+- result = getStartFreq(fsCore, startFreq);
+-
+- result =
+- (result * (fsCore >> 5) + 1) >> 1; /* (result*fsSBR/QMFbands+1)>>1; */
+-
+- return (result);
+-
+-} /* End FDKsbrEnc_getSbrStartFreqRAW */
+-
+-/*******************************************************************************
+- Functionname: getSbrStopFreq
+- *******************************************************************************
+- Description:
+-
+- Arguments:
+-
+- Return:
+- *******************************************************************************/
+-INT FDKsbrEnc_getSbrStopFreqRAW(INT stopFreq, INT fsCore) {
+- INT result;
+-
+- if (stopFreq < 0 || stopFreq > 13) return -1;
+-
+- /* Uppdate stopFreq struct */
+- result = getStopFreq(fsCore, stopFreq);
+- result =
+- (result * (fsCore >> 5) + 1) >> 1; /* (result*fsSBR/QMFbands+1)>>1; */
+-
+- return (result);
+-} /* End getSbrStopFreq */
+-
+-/*******************************************************************************
+- Functionname: getStartFreq
+- *******************************************************************************
+- Description:
+-
+- Arguments: fsCore - core sampling rate
+-
+-
+- Return:
+- *******************************************************************************/
+-static INT getStartFreq(INT fsCore, const INT start_freq) {
+- INT k0_min;
+-
+- switch (fsCore) {
+- case 8000:
+- k0_min = 24; /* (3000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 11025:
+- k0_min = 17; /* (3000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 12000:
+- k0_min = 16; /* (3000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 16000:
+- k0_min = 16; /* (4000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 22050:
+- k0_min = 12; /* (4000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 24000:
+- k0_min = 11; /* (4000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 32000:
+- k0_min = 10; /* (5000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 44100:
+- k0_min = 7; /* (5000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 48000:
+- k0_min = 7; /* (5000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- case 96000:
+- k0_min = 3; /* (5000 * nQmfChannels / fsSBR ) + 0.5 */
+- break;
+- default:
+- k0_min = 11; /* illegal fs */
+- }
+-
+- switch (fsCore) {
+- case 8000: {
+- INT v_offset[] = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7};
+- return (k0_min + v_offset[start_freq]);
+- }
+- case 11025: {
+- INT v_offset[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13};
+- return (k0_min + v_offset[start_freq]);
+- }
+- case 12000: {
+- INT v_offset[] = {-5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16};
+- return (k0_min + v_offset[start_freq]);
+- }
+- case 16000: {
+- INT v_offset[] = {-6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16};
+- return (k0_min + v_offset[start_freq]);
+- }
+- case 22050:
+- case 24000:
+- case 32000: {
+- INT v_offset[] = {-4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20};
+- return (k0_min + v_offset[start_freq]);
+- }
+- case 44100:
+- case 48000:
+- case 96000: {
+- INT v_offset[] = {-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24};
+- return (k0_min + v_offset[start_freq]);
+- }
+- default: {
+- INT v_offset[] = {0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24, 28, 33};
+- return (k0_min + v_offset[start_freq]);
+- }
+- }
+-} /* End getStartFreq */
+-
+-/*******************************************************************************
+- Functionname: getStopFreq
+- *******************************************************************************
+- Description:
+-
+- Arguments:
+-
+- Return:
+- *******************************************************************************/
+-static INT getStopFreq(INT fsCore, const INT stop_freq) {
+- INT result, i;
+- INT k1_min;
+- INT v_dstop[13];
+-
+- INT *v_stop_freq = NULL;
+- INT v_stop_freq_16[14] = {48, 49, 50, 51, 52, 54, 55,
+- 56, 57, 59, 60, 61, 63, 64};
+- INT v_stop_freq_22[14] = {35, 37, 38, 40, 42, 44, 46,
+- 48, 51, 53, 56, 58, 61, 64};
+- INT v_stop_freq_24[14] = {32, 34, 36, 38, 40, 42, 44,
+- 46, 49, 52, 55, 58, 61, 64};
+- INT v_stop_freq_32[14] = {32, 34, 36, 38, 40, 42, 44,
+- 46, 49, 52, 55, 58, 61, 64};
+- INT v_stop_freq_44[14] = {23, 25, 27, 29, 32, 34, 37,
+- 40, 43, 47, 51, 55, 59, 64};
+- INT v_stop_freq_48[14] = {21, 23, 25, 27, 30, 32, 35,
+- 38, 42, 45, 49, 54, 59, 64};
+- INT v_stop_freq_64[14] = {20, 22, 24, 26, 29, 31, 34,
+- 37, 41, 45, 49, 54, 59, 64};
+- INT v_stop_freq_88[14] = {15, 17, 19, 21, 23, 26, 29,
+- 33, 37, 41, 46, 51, 57, 64};
+- INT v_stop_freq_96[14] = {13, 15, 17, 19, 21, 24, 27,
+- 31, 35, 39, 44, 50, 57, 64};
+- INT v_stop_freq_192[14] = {7, 8, 10, 12, 14, 16, 19,
+- 23, 27, 32, 38, 46, 54, 64};
+-
+- switch (fsCore) {
+- case 8000:
+- k1_min = 48;
+- v_stop_freq = v_stop_freq_16;
+- break;
+- case 11025:
+- k1_min = 35;
+- v_stop_freq = v_stop_freq_22;
+- break;
+- case 12000:
+- k1_min = 32;
+- v_stop_freq = v_stop_freq_24;
+- break;
+- case 16000:
+- k1_min = 32;
+- v_stop_freq = v_stop_freq_32;
+- break;
+- case 22050:
+- k1_min = 23;
+- v_stop_freq = v_stop_freq_44;
+- break;
+- case 24000:
+- k1_min = 21;
+- v_stop_freq = v_stop_freq_48;
+- break;
+- case 32000:
+- k1_min = 20;
+- v_stop_freq = v_stop_freq_64;
+- break;
+- case 44100:
+- k1_min = 15;
+- v_stop_freq = v_stop_freq_88;
+- break;
+- case 48000:
+- k1_min = 13;
+- v_stop_freq = v_stop_freq_96;
+- break;
+- case 96000:
+- k1_min = 7;
+- v_stop_freq = v_stop_freq_192;
+- break;
+- default:
+- k1_min = 21; /* illegal fs */
+- }
+-
+- /* Ensure increasing bandwidth */
+- for (i = 0; i <= 12; i++) {
+- v_dstop[i] = v_stop_freq[i + 1] - v_stop_freq[i];
+- }
+-
+- FDKsbrEnc_Shellsort_int(v_dstop, 13); /* Sort bandwidth changes */
+-
+- result = k1_min;
+- for (i = 0; i < stop_freq; i++) {
+- result = result + v_dstop[i];
+- }
+-
+- return (result);
+-
+-} /* End getStopFreq */
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_FindStartAndStopBand
+- *******************************************************************************
+- Description:
+-
+- Arguments: srSbr SBR sampling freqency
+- srCore AAC core sampling freqency
+- noChannels Number of QMF channels
+- startFreq SBR start frequency in QMF bands
+- stopFreq SBR start frequency in QMF bands
+-
+- *k0 Output parameter
+- *k2 Output parameter
+-
+- Return: Error code (0 is OK)
+- *******************************************************************************/
+-INT FDKsbrEnc_FindStartAndStopBand(const INT srSbr, const INT srCore,
+- const INT noChannels, const INT startFreq,
+- const INT stopFreq, INT *k0, INT *k2) {
+- /* Update startFreq struct */
+- *k0 = getStartFreq(srCore, startFreq);
+-
+- /* Test if start freq is outside corecoder range */
+- if (srSbr * noChannels < *k0 * srCore) {
+- return (
+- 1); /* raise the cross-over frequency and/or lower the number
+- of target bands per octave (or lower the sampling frequency) */
+- }
+-
+- /*Update stopFreq struct */
+- if (stopFreq < 14) {
+- *k2 = getStopFreq(srCore, stopFreq);
+- } else if (stopFreq == 14) {
+- *k2 = 2 * *k0;
+- } else {
+- *k2 = 3 * *k0;
+- }
+-
+- /* limit to Nyqvist */
+- if (*k2 > noChannels) {
+- *k2 = noChannels;
+- }
+-
+- /* Test for invalid k0 k2 combinations */
+- if ((srCore == 22050) && ((*k2 - *k0) > MAX_FREQ_COEFFS_FS44100))
+- return (1); /* Number of bands exceeds valid range of MAX_FREQ_COEFFS for
+- fs=44.1kHz */
+-
+- if ((srCore >= 24000) && ((*k2 - *k0) > MAX_FREQ_COEFFS_FS48000))
+- return (1); /* Number of bands exceeds valid range of MAX_FREQ_COEFFS for
+- fs>=48kHz */
+-
+- if ((*k2 - *k0) > MAX_FREQ_COEFFS)
+- return (1); /*Number of bands exceeds valid range of MAX_FREQ_COEFFS */
+-
+- if ((*k2 - *k0) < 0) return (1); /* Number of bands is negative */
+-
+- return (0);
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_UpdateFreqScale
+- *******************************************************************************
+- Description:
+-
+- Arguments:
+-
+- Return:
+- *******************************************************************************/
+-INT FDKsbrEnc_UpdateFreqScale(UCHAR *v_k_master, INT *h_num_bands, const INT k0,
+- const INT k2, const INT freqScale,
+- const INT alterScale)
+-
+-{
+- INT b_p_o = 0; /* bands_per_octave */
+- FIXP_DBL warp = FL2FXCONST_DBL(0.0f);
+- INT dk = 0;
+-
+- /* Internal variables */
+- INT k1 = 0, i;
+- INT num_bands0;
+- INT num_bands1;
+- INT diff_tot[MAX_OCTAVE + MAX_SECOND_REGION];
+- INT *diff0 = diff_tot;
+- INT *diff1 = diff_tot + MAX_OCTAVE;
+- INT k2_achived;
+- INT k2_diff;
+- INT incr = 0;
+-
+- /* Init */
+- if (freqScale == 1) b_p_o = 12;
+- if (freqScale == 2) b_p_o = 10;
+- if (freqScale == 3) b_p_o = 8;
+-
+- if (freqScale > 0) /*Bark*/
+- {
+- if (alterScale == 0)
+- warp = FL2FXCONST_DBL(0.5f); /* 1.0/(1.0*2.0) */
+- else
+- warp = FL2FXCONST_DBL(1.0f / 2.6f); /* 1.0/(1.3*2.0); */
+-
+- if (4 * k2 >= 9 * k0) /*two or more regions (how many times the basis band
+- is copied)*/
+- {
+- k1 = 2 * k0;
+-
+- num_bands0 = numberOfBands(b_p_o, k0, k1, FL2FXCONST_DBL(0.5f));
+- num_bands1 = numberOfBands(b_p_o, k1, k2, warp);
+-
+- CalcBands(diff0, k0, k1, num_bands0); /*CalcBands1 => diff0 */
+- FDKsbrEnc_Shellsort_int(diff0, num_bands0); /*SortBands sort diff0 */
+-
+- if (diff0[0] == 0) /* too wide FB bands for target tuning */
+- {
+- return (1); /* raise the cross-over frequency and/or lower the number
+- of target bands per octave (or lower the sampling
+- frequency */
+- }
+-
+- cumSum(k0, diff0, num_bands0, v_k_master); /* cumsum */
+-
+- CalcBands(diff1, k1, k2, num_bands1); /* CalcBands2 => diff1 */
+- FDKsbrEnc_Shellsort_int(diff1, num_bands1); /* SortBands sort diff1 */
+- if (diff0[num_bands0 - 1] > diff1[0]) /* max(1) > min(2) */
+- {
+- if (modifyBands(diff0[num_bands0 - 1], diff1, num_bands1)) return (1);
+- }
+-
+- /* Add 2'nd region */
+- cumSum(k1, diff1, num_bands1, &v_k_master[num_bands0]);
+- *h_num_bands = num_bands0 + num_bands1; /* Output nr of bands */
+-
+- } else /* one region */
+- {
+- k1 = k2;
+-
+- num_bands0 = numberOfBands(b_p_o, k0, k1, FL2FXCONST_DBL(0.5f));
+- CalcBands(diff0, k0, k1, num_bands0); /* CalcBands1 => diff0 */
+- FDKsbrEnc_Shellsort_int(diff0, num_bands0); /* SortBands sort diff0 */
+-
+- if (diff0[0] == 0) /* too wide FB bands for target tuning */
+- {
+- return (1); /* raise the cross-over frequency and/or lower the number
+- of target bands per octave (or lower the sampling
+- frequency */
+- }
+-
+- cumSum(k0, diff0, num_bands0, v_k_master); /* cumsum */
+- *h_num_bands = num_bands0; /* Output nr of bands */
+- }
+- } else /* Linear mode */
+- {
+- if (alterScale == 0) {
+- dk = 1;
+- num_bands0 = 2 * ((k2 - k0) / 2); /* FLOOR to get to few number of bands*/
+- } else {
+- dk = 2;
+- num_bands0 =
+- 2 * (((k2 - k0) / dk + 1) / 2); /* ROUND to get closest fit */
+- }
+-
+- k2_achived = k0 + num_bands0 * dk;
+- k2_diff = k2 - k2_achived;
+-
+- for (i = 0; i < num_bands0; i++) diff_tot[i] = dk;
+-
+- /* If linear scale wasn't achived */
+- /* and we got wide SBR are */
+- if (k2_diff < 0) {
+- incr = 1;
+- i = 0;
+- }
+-
+- /* If linear scale wasn't achived */
+- /* and we got small SBR are */
+- if (k2_diff > 0) {
+- incr = -1;
+- i = num_bands0 - 1;
+- }
+-
+- /* Adjust diff vector to get sepc. SBR range */
+- while (k2_diff != 0) {
+- diff_tot[i] = diff_tot[i] - incr;
+- i = i + incr;
+- k2_diff = k2_diff + incr;
+- }
+-
+- cumSum(k0, diff_tot, num_bands0, v_k_master); /* cumsum */
+- *h_num_bands = num_bands0; /* Output nr of bands */
+- }
+-
+- if (*h_num_bands < 1) return (1); /*To small sbr area */
+-
+- return (0);
+-} /* End FDKsbrEnc_UpdateFreqScale */
+-
+-static INT numberOfBands(INT b_p_o, INT start, INT stop, FIXP_DBL warp_factor) {
+- INT result = 0;
+- /* result = 2* (INT) ( (double)b_p_o *
+- * (double)(FDKlog((double)stop/(double)start)/FDKlog((double)2)) *
+- * (double)FX_DBL2FL(warp_factor) + 0.5); */
+- result = ((b_p_o * fMult((CalcLdInt(stop) - CalcLdInt(start)), warp_factor) +
+- (FL2FX_DBL(0.5f) >> LD_DATA_SHIFT)) >>
+- ((DFRACT_BITS - 1) - LD_DATA_SHIFT))
+- << 1; /* do not optimize anymore (rounding!!) */
+-
+- return (result);
+-}
+-
+-static void CalcBands(INT *diff, INT start, INT stop, INT num_bands) {
+- INT i, qb, qe, qtmp;
+- INT previous;
+- INT current;
+- FIXP_DBL base, exp, tmp;
+-
+- previous = start;
+- for (i = 1; i <= num_bands; i++) {
+- base = fDivNorm((FIXP_DBL)stop, (FIXP_DBL)start, &qb);
+- exp = fDivNorm((FIXP_DBL)i, (FIXP_DBL)num_bands, &qe);
+- tmp = fPow(base, qb, exp, qe, &qtmp);
+- tmp = fMult(tmp, (FIXP_DBL)(start << 24));
+- current = (INT)scaleValue(tmp, qtmp - 23);
+- current = (current + 1) >> 1; /* rounding*/
+- diff[i - 1] = current - previous;
+- previous = current;
+- }
+-
+-} /* End CalcBands */
+-
+-static void cumSum(INT start_value, INT *diff, INT length,
+- UCHAR *start_adress) {
+- INT i;
+- start_adress[0] = start_value;
+- for (i = 1; i <= length; i++)
+- start_adress[i] = start_adress[i - 1] + diff[i - 1];
+-} /* End cumSum */
+-
+-static INT modifyBands(INT max_band_previous, INT *diff, INT length) {
+- INT change = max_band_previous - diff[0];
+-
+- /* Limit the change so that the last band cannot get narrower than the first
+- * one */
+- if (change > (diff[length - 1] - diff[0]) / 2)
+- change = (diff[length - 1] - diff[0]) / 2;
+-
+- diff[0] += change;
+- diff[length - 1] -= change;
+- FDKsbrEnc_Shellsort_int(diff, length);
+-
+- return (0);
+-} /* End modifyBands */
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_UpdateHiRes
+- *******************************************************************************
+- Description:
+-
+-
+- Arguments:
+-
+- Return:
+- *******************************************************************************/
+-INT FDKsbrEnc_UpdateHiRes(UCHAR *h_hires, INT *num_hires, UCHAR *v_k_master,
+- INT num_master, INT *xover_band) {
+- INT i;
+- INT max1, max2;
+-
+- if ((v_k_master[*xover_band] >
+- 32) || /* v_k_master[*xover_band] > noQMFChannels(dualRate)/divider */
+- (*xover_band > num_master)) {
+- /* xover_band error, too big for this startFreq. Will be clipped */
+-
+- /* Calculate maximum value for xover_band */
+- max1 = 0;
+- max2 = num_master;
+- while ((v_k_master[max1 + 1] < 32) && /* noQMFChannels(dualRate)/divider */
+- ((max1 + 1) < max2)) {
+- max1++;
+- }
+-
+- *xover_band = max1;
+- }
+-
+- *num_hires = num_master - *xover_band;
+- for (i = *xover_band; i <= num_master; i++) {
+- h_hires[i - *xover_band] = v_k_master[i];
+- }
+-
+- return (0);
+-} /* End FDKsbrEnc_UpdateHiRes */
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_UpdateLoRes
+- *******************************************************************************
+- Description:
+-
+- Arguments:
+-
+- Return:
+- *******************************************************************************/
+-void FDKsbrEnc_UpdateLoRes(UCHAR *h_lores, INT *num_lores, UCHAR *h_hires,
+- INT num_hires) {
+- INT i;
+-
+- if (num_hires % 2 == 0) /* if even number of hires bands */
+- {
+- *num_lores = num_hires / 2;
+- /* Use every second lores=hires[0,2,4...] */
+- for (i = 0; i <= *num_lores; i++) h_lores[i] = h_hires[i * 2];
+-
+- } else /* odd number of hires which means xover is odd */
+- {
+- *num_lores = (num_hires + 1) / 2;
+-
+- /* Use lores=hires[0,1,3,5 ...] */
+- h_lores[0] = h_hires[0];
+- for (i = 1; i <= *num_lores; i++) {
+- h_lores[i] = h_hires[i * 2 - 1];
+- }
+- }
+-
+-} /* End FDKsbrEnc_UpdateLoRes */
+diff --git a/libSBRenc/src/sbrenc_freq_sca.h b/libSBRenc/src/sbrenc_freq_sca.h
+deleted file mode 100644
+index 9b8d360..0000000
+--- a/libSBRenc/src/sbrenc_freq_sca.h
++++ /dev/null
+@@ -1,132 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief frequency scale prototypes $Revision: 92790 $
+-*/
+-#ifndef SBRENC_FREQ_SCA_H
+-#define SBRENC_FREQ_SCA_H
+-
+-#include "sbr_encoder.h"
+-#include "sbr_def.h"
+-
+-#define MAX_OCTAVE 29
+-#define MAX_SECOND_REGION 50
+-
+-INT FDKsbrEnc_UpdateFreqScale(UCHAR *v_k_master, INT *h_num_bands, const INT k0,
+- const INT k2, const INT freq_scale,
+- const INT alter_scale);
+-
+-INT FDKsbrEnc_UpdateHiRes(UCHAR *h_hires, INT *num_hires, UCHAR *v_k_master,
+- INT num_master, INT *xover_band);
+-
+-void FDKsbrEnc_UpdateLoRes(UCHAR *v_lores, INT *num_lores, UCHAR *v_hires,
+- INT num_hires);
+-
+-INT FDKsbrEnc_FindStartAndStopBand(const INT srSbr, const INT srCore,
+- const INT noChannels, const INT startFreq,
+- const INT stop_freq, INT *k0, INT *k2);
+-
+-INT FDKsbrEnc_getSbrStartFreqRAW(INT startFreq, INT fsCore);
+-INT FDKsbrEnc_getSbrStopFreqRAW(INT stopFreq, INT fsCore);
+-#endif
+diff --git a/libSBRenc/src/sbrenc_ram.cpp b/libSBRenc/src/sbrenc_ram.cpp
+deleted file mode 100644
+index fb30fa2..0000000
+--- a/libSBRenc/src/sbrenc_ram.cpp
++++ /dev/null
+@@ -1,249 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Memory layout
+- $Revision: 92864 $
+-
+- This module declares all static and dynamic memory spaces
+-*/
+-#include "sbrenc_ram.h"
+-
+-#include "sbr.h"
+-#include "genericStds.h"
+-
+-C_AALLOC_MEM(Ram_SbrDynamic_RAM, FIXP_DBL,
+- ((SBR_ENC_DYN_RAM_SIZE) / sizeof(FIXP_DBL)))
+-
+-/*!
+- \name StaticSbrData
+-
+- Static memory areas, must not be overwritten in other sections of the encoder
+-*/
+-/* @{ */
+-
+-/*! static sbr encoder instance for one encoder (2 channels)
+- all major static and dynamic memory areas are located
+- in module sbr_ram and sbr rom
+-*/
+-C_ALLOC_MEM(Ram_SbrEncoder, SBR_ENCODER, 1)
+-C_ALLOC_MEM2(Ram_SbrChannel, SBR_CHANNEL, 1, (8))
+-C_ALLOC_MEM2(Ram_SbrElement, SBR_ELEMENT, 1, (8))
+-
+-/*! Filter states for QMF-analysis. <br>
+- Dimension: #MAXNRSBRCHANNELS * #SBR_QMF_FILTER_LENGTH
+-*/
+-C_AALLOC_MEM2_L(Ram_Sbr_QmfStatesAnalysis, FIXP_QAS, 640, (8), SECT_DATA_L1)
+-
+-/*! Matrix holding the quota values for all estimates, all channels
+- Dimension #MAXNRSBRCHANNELS * +#SBR_QMF_CHANNELS* #MAX_NO_OF_ESTIMATES
+-*/
+-C_ALLOC_MEM2_L(Ram_Sbr_quotaMatrix, FIXP_DBL, (MAX_NO_OF_ESTIMATES * 64), (8),
+- SECT_DATA_L1)
+-
+-/*! Matrix holding the sign values for all estimates, all channels
+- Dimension #MAXNRSBRCHANNELS * +#SBR_QMF_CHANNELS* #MAX_NO_OF_ESTIMATES
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_signMatrix, INT, (MAX_NO_OF_ESTIMATES * 64), (8))
+-
+-/*! Frequency band table (low res) <br>
+- Dimension #MAX_FREQ_COEFFS/2+1
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_freqBandTableLO, UCHAR, (MAX_FREQ_COEFFS / 2 + 1), (8))
+-
+-/*! Frequency band table (high res) <br>
+- Dimension #MAX_FREQ_COEFFS +1
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_freqBandTableHI, UCHAR, (MAX_FREQ_COEFFS + 1), (8))
+-
+-/*! vk matser table <br>
+- Dimension #MAX_FREQ_COEFFS +1
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_v_k_master, UCHAR, (MAX_FREQ_COEFFS + 1), (8))
+-
+-/*
+- Missing harmonics detection
+-*/
+-
+-/*! sbr_detectionVectors <br>
+- Dimension #MAX_NUM_CHANNELS*#MAX_NO_OF_ESTIMATES*#MAX_FREQ_COEFFS]
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_detectionVectors, UCHAR,
+- (MAX_NO_OF_ESTIMATES * MAX_FREQ_COEFFS), (8))
+-
+-/*! sbr_prevCompVec[ <br>
+- Dimension #MAX_NUM_CHANNELS*#MAX_FREQ_COEFFS]
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_prevEnvelopeCompensation, UCHAR, MAX_FREQ_COEFFS, (8))
+-/*! sbr_guideScfb[ <br>
+- Dimension #MAX_NUM_CHANNELS*#MAX_FREQ_COEFFS]
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_guideScfb, UCHAR, MAX_FREQ_COEFFS, (8))
+-
+-/*! sbr_guideVectorDetected <br>
+- Dimension #MAX_NUM_CHANNELS*#MAX_NO_OF_ESTIMATES*#MAX_FREQ_COEFFS]
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_guideVectorDetected, UCHAR,
+- (MAX_NO_OF_ESTIMATES * MAX_FREQ_COEFFS), (8))
+-C_ALLOC_MEM2(Ram_Sbr_guideVectorDiff, FIXP_DBL,
+- (MAX_NO_OF_ESTIMATES * MAX_FREQ_COEFFS), (8))
+-C_ALLOC_MEM2(Ram_Sbr_guideVectorOrig, FIXP_DBL,
+- (MAX_NO_OF_ESTIMATES * MAX_FREQ_COEFFS), (8))
+-
+-/*
+- Static Parametric Stereo memory
+-*/
+-C_AALLOC_MEM_L(Ram_PsQmfStatesSynthesis, FIXP_DBL, 640 / 2, SECT_DATA_L1)
+-
+-C_ALLOC_MEM_L(Ram_PsEncode, PS_ENCODE, 1, SECT_DATA_L1)
+-C_ALLOC_MEM(Ram_ParamStereo, PARAMETRIC_STEREO, 1)
+-
+-/* @} */
+-
+-/*!
+- \name DynamicSbrData
+-
+- Dynamic memory areas, might be reused in other algorithm sections,
+- e.g. the core encoder.
+-*/
+-/* @{ */
+-
+-/*! Energy buffer for envelope extraction <br>
+- Dimension #MAXNRSBRCHANNELS * +#SBR_QMF_SLOTS * #SBR_QMF_CHANNELS
+-*/
+-C_ALLOC_MEM2(Ram_Sbr_envYBuffer, FIXP_DBL, (32 / 2 * 64), (8))
+-
+-FIXP_DBL* GetRam_Sbr_envYBuffer(int n, UCHAR* dynamic_RAM) {
+- FDK_ASSERT(dynamic_RAM != 0);
+- /* The reinterpret_cast is used to suppress a compiler warning. We know that
+- * (dynamic_RAM + OFFSET_NRG + (n*Y_2_BUF_BYTE)) is sufficiently aligned, so
+- * the cast is safe */
+- return reinterpret_cast<FIXP_DBL*>(
+- reinterpret_cast<void*>(dynamic_RAM + OFFSET_NRG + (n * Y_2_BUF_BYTE)));
+-}
+-
+-/*
+- * QMF data
+- */
+-/* The SBR encoder uses a single channel overlapping buffer set (always n=0),
+- * but PS does not. */
+-FIXP_DBL* GetRam_Sbr_envRBuffer(int n, UCHAR* dynamic_RAM) {
+- FDK_ASSERT(dynamic_RAM != 0);
+- /* The reinterpret_cast is used to suppress a compiler warning. We know that
+- * (dynamic_RAM + OFFSET_QMF + (n*(ENV_R_BUFF_BYTE+ENV_I_BUFF_BYTE))) is
+- * sufficiently aligned, so the cast is safe */
+- return reinterpret_cast<FIXP_DBL*>(reinterpret_cast<void*>(
+- dynamic_RAM + OFFSET_QMF + (n * (ENV_R_BUFF_BYTE + ENV_I_BUFF_BYTE))));
+-}
+-FIXP_DBL* GetRam_Sbr_envIBuffer(int n, UCHAR* dynamic_RAM) {
+- FDK_ASSERT(dynamic_RAM != 0);
+- /* The reinterpret_cast is used to suppress a compiler warning. We know that
+- * (dynamic_RAM + OFFSET_QMF + (ENV_R_BUFF_BYTE) +
+- * (n*(ENV_R_BUFF_BYTE+ENV_I_BUFF_BYTE))) is sufficiently aligned, so the cast
+- * is safe */
+- return reinterpret_cast<FIXP_DBL*>(
+- reinterpret_cast<void*>(dynamic_RAM + OFFSET_QMF + (ENV_R_BUFF_BYTE) +
+- (n * (ENV_R_BUFF_BYTE + ENV_I_BUFF_BYTE))));
+-}
+-
+-/* @} */
+diff --git a/libSBRenc/src/sbrenc_ram.h b/libSBRenc/src/sbrenc_ram.h
+deleted file mode 100644
+index cf23378..0000000
+--- a/libSBRenc/src/sbrenc_ram.h
++++ /dev/null
+@@ -1,199 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+-\file
+-\brief Memory layout
+-$Revision: 92790 $
+-*/
+-#ifndef SBRENC_RAM_H
+-#define SBRENC_RAM_H
+-
+-#include "sbr_def.h"
+-#include "env_est.h"
+-#include "sbr_encoder.h"
+-#include "sbr.h"
+-
+-#include "ps_main.h"
+-#include "ps_encode.h"
+-
+-#define ENV_TRANSIENTS_BYTE ((sizeof(FIXP_DBL) * (MAX_NUM_CHANNELS * 3 * 32)))
+-
+-#define ENV_R_BUFF_BYTE ((sizeof(FIXP_DBL) * ((32) * MAX_HYBRID_BANDS)))
+-#define ENV_I_BUFF_BYTE ((sizeof(FIXP_DBL) * ((32) * MAX_HYBRID_BANDS)))
+-#define Y_BUF_CH_BYTE \
+- ((2 * sizeof(FIXP_DBL) * (((32) - (32 / 2)) * MAX_HYBRID_BANDS)))
+-
+-#define ENV_R_BUF_PS_BYTE ((sizeof(FIXP_DBL) * 32 * 64 / 2))
+-#define ENV_I_BUF_PS_BYTE ((sizeof(FIXP_DBL) * 32 * 64 / 2))
+-
+-#define TON_BUF_CH_BYTE \
+- ((sizeof(FIXP_DBL) * (MAX_NO_OF_ESTIMATES * MAX_FREQ_COEFFS)))
+-
+-#define Y_2_BUF_BYTE (Y_BUF_CH_BYTE)
+-
+-/* Workbuffer RAM - Allocation */
+-/*
+- ++++++++++++++++++++++++++++++++++++++++++++++++++++
+- | OFFSET_QMF | OFFSET_NRG |
+- ++++++++++++++++++++++++++++++++++++++++++++++++++++
+- ------------------------- -------------------------
+- | | 0.5 * |
+- | sbr_envRBuffer | sbr_envYBuffer_size |
+- | sbr_envIBuffer | |
+- ------------------------- -------------------------
+-
+-*/
+-#define BUF_NRG_SIZE ((MAX_NUM_CHANNELS * Y_2_BUF_BYTE))
+-#define BUF_QMF_SIZE (ENV_R_BUFF_BYTE + ENV_I_BUFF_BYTE)
+-
+-/* Size of the shareable memory region than can be reused */
+-#define SBR_ENC_DYN_RAM_SIZE (BUF_QMF_SIZE + BUF_NRG_SIZE)
+-
+-#define OFFSET_QMF (0)
+-#define OFFSET_NRG (OFFSET_QMF + BUF_QMF_SIZE)
+-
+-/*
+- *****************************************************************************************************
+- */
+-
+-H_ALLOC_MEM(Ram_SbrDynamic_RAM, FIXP_DBL)
+-
+-H_ALLOC_MEM(Ram_SbrEncoder, SBR_ENCODER)
+-H_ALLOC_MEM(Ram_SbrChannel, SBR_CHANNEL)
+-H_ALLOC_MEM(Ram_SbrElement, SBR_ELEMENT)
+-
+-H_ALLOC_MEM(Ram_Sbr_quotaMatrix, FIXP_DBL)
+-H_ALLOC_MEM(Ram_Sbr_signMatrix, INT)
+-
+-H_ALLOC_MEM(Ram_Sbr_QmfStatesAnalysis, FIXP_QAS)
+-
+-H_ALLOC_MEM(Ram_Sbr_freqBandTableLO, UCHAR)
+-H_ALLOC_MEM(Ram_Sbr_freqBandTableHI, UCHAR)
+-H_ALLOC_MEM(Ram_Sbr_v_k_master, UCHAR)
+-
+-H_ALLOC_MEM(Ram_Sbr_detectionVectors, UCHAR)
+-H_ALLOC_MEM(Ram_Sbr_prevEnvelopeCompensation, UCHAR)
+-H_ALLOC_MEM(Ram_Sbr_guideScfb, UCHAR)
+-H_ALLOC_MEM(Ram_Sbr_guideVectorDetected, UCHAR)
+-
+-/* Dynamic Memory Allocation */
+-
+-H_ALLOC_MEM(Ram_Sbr_envYBuffer, FIXP_DBL)
+-FIXP_DBL* GetRam_Sbr_envYBuffer(int n, UCHAR* dynamic_RAM);
+-FIXP_DBL* GetRam_Sbr_envRBuffer(int n, UCHAR* dynamic_RAM);
+-FIXP_DBL* GetRam_Sbr_envIBuffer(int n, UCHAR* dynamic_RAM);
+-
+-H_ALLOC_MEM(Ram_Sbr_guideVectorDiff, FIXP_DBL)
+-H_ALLOC_MEM(Ram_Sbr_guideVectorOrig, FIXP_DBL)
+-
+-H_ALLOC_MEM(Ram_PsQmfStatesSynthesis, FIXP_DBL)
+-
+-H_ALLOC_MEM(Ram_PsEncode, PS_ENCODE)
+-
+-FIXP_DBL* FDKsbrEnc_SliceRam_PsRqmf(FIXP_DBL* rQmfData, UCHAR* dynamic_RAM,
+- int n, int i, int qmfSlots);
+-FIXP_DBL* FDKsbrEnc_SliceRam_PsIqmf(FIXP_DBL* iQmfData, UCHAR* dynamic_RAM,
+- int n, int i, int qmfSlots);
+-
+-H_ALLOC_MEM(Ram_ParamStereo, PARAMETRIC_STEREO)
+-#endif
+diff --git a/libSBRenc/src/sbrenc_rom.cpp b/libSBRenc/src/sbrenc_rom.cpp
+deleted file mode 100644
+index 737afaf..0000000
+--- a/libSBRenc/src/sbrenc_rom.cpp
++++ /dev/null
+@@ -1,910 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): Tobias Chalupka
+-
+- Description: Definition of constant tables
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Definition of constant tables
+- $Revision: 95404 $
+-
+- This module contains most of the constant data that can be stored in ROM.
+-*/
+-
+-#include "sbrenc_rom.h"
+-#include "genericStds.h"
+-
+-//@{
+-/*******************************************************************************
+-
+- Table Overview:
+-
+- o envelope level, 1.5 dB:
+- 1a) v_Huff_envelopeLevelC10T[121]
+- 1b) v_Huff_envelopeLevelL10T[121]
+- 2a) v_Huff_envelopeLevelC10F[121]
+- 2b) v_Huff_envelopeLevelL10F[121]
+-
+- o envelope balance, 1.5 dB:
+- 3a) bookSbrEnvBalanceC10T[49]
+- 3b) bookSbrEnvBalanceL10T[49]
+- 4a) bookSbrEnvBalanceC10F[49]
+- 4b) bookSbrEnvBalanceL10F[49]
+-
+- o envelope level, 3.0 dB:
+- 5a) v_Huff_envelopeLevelC11T[63]
+- 5b) v_Huff_envelopeLevelL11T[63]
+- 6a) v_Huff_envelopeLevelC11F[63]
+- 6b) v_Huff_envelopeLevelC11F[63]
+-
+- o envelope balance, 3.0 dB:
+- 7a) bookSbrEnvBalanceC11T[25]
+- 7b) bookSbrEnvBalanceL11T[25]
+- 8a) bookSbrEnvBalanceC11F[25]
+- 8b) bookSbrEnvBalanceL11F[25]
+-
+- o noise level, 3.0 dB:
+- 9a) v_Huff_NoiseLevelC11T[63]
+- 9b) v_Huff_NoiseLevelL11T[63]
+- - ) (v_Huff_envelopeLevelC11F[63] is used for freq dir)
+- - ) (v_Huff_envelopeLevelL11F[63] is used for freq dir)
+-
+- o noise balance, 3.0 dB:
+- 10a) bookSbrNoiseBalanceC11T[25]
+- 10b) bookSbrNoiseBalanceL11T[25]
+- - ) (bookSbrEnvBalanceC11F[25] is used for freq dir)
+- - ) (bookSbrEnvBalanceL11F[25] is used for freq dir)
+-
+-
+- (1.5 dB is never used for noise)
+-
+-********************************************************************************/
+-
+-/*******************************************************************************/
+-/* table : envelope level, 1.5 dB */
+-/* theor range : [-58,58], CODE_BOOK_SCF_LAV = 58 */
+-/* implem range: [-60,60], CODE_BOOK_SCF_LAV10 = 60 */
+-/* raw stats : envelopeLevel_00 (yes, wrong suffix in name) KK 01-03-09 */
+-/*******************************************************************************/
+-
+-/* direction: time
+- contents : codewords
+- raw table: HuffCode3C2FIX.m/envelopeLevel_00T_cF.mat/v_nChex_cF
+- built by : FH 01-07-05 */
+-
+-const INT v_Huff_envelopeLevelC10T[121] = {
+- 0x0003FFD6, 0x0003FFD7, 0x0003FFD8, 0x0003FFD9, 0x0003FFDA, 0x0003FFDB,
+- 0x0007FFB8, 0x0007FFB9, 0x0007FFBA, 0x0007FFBB, 0x0007FFBC, 0x0007FFBD,
+- 0x0007FFBE, 0x0007FFBF, 0x0007FFC0, 0x0007FFC1, 0x0007FFC2, 0x0007FFC3,
+- 0x0007FFC4, 0x0007FFC5, 0x0007FFC6, 0x0007FFC7, 0x0007FFC8, 0x0007FFC9,
+- 0x0007FFCA, 0x0007FFCB, 0x0007FFCC, 0x0007FFCD, 0x0007FFCE, 0x0007FFCF,
+- 0x0007FFD0, 0x0007FFD1, 0x0007FFD2, 0x0007FFD3, 0x0001FFE6, 0x0003FFD4,
+- 0x0000FFF0, 0x0001FFE9, 0x0003FFD5, 0x0001FFE7, 0x0000FFF1, 0x0000FFEC,
+- 0x0000FFED, 0x0000FFEE, 0x00007FF4, 0x00003FF9, 0x00003FF7, 0x00001FFA,
+- 0x00001FF9, 0x00000FFB, 0x000007FC, 0x000003FC, 0x000001FD, 0x000000FD,
+- 0x0000007D, 0x0000003D, 0x0000001D, 0x0000000D, 0x00000005, 0x00000001,
+- 0x00000000, 0x00000004, 0x0000000C, 0x0000001C, 0x0000003C, 0x0000007C,
+- 0x000000FC, 0x000001FC, 0x000003FD, 0x00000FFA, 0x00001FF8, 0x00003FF6,
+- 0x00003FF8, 0x00007FF5, 0x0000FFEF, 0x0001FFE8, 0x0000FFF2, 0x0007FFD4,
+- 0x0007FFD5, 0x0007FFD6, 0x0007FFD7, 0x0007FFD8, 0x0007FFD9, 0x0007FFDA,
+- 0x0007FFDB, 0x0007FFDC, 0x0007FFDD, 0x0007FFDE, 0x0007FFDF, 0x0007FFE0,
+- 0x0007FFE1, 0x0007FFE2, 0x0007FFE3, 0x0007FFE4, 0x0007FFE5, 0x0007FFE6,
+- 0x0007FFE7, 0x0007FFE8, 0x0007FFE9, 0x0007FFEA, 0x0007FFEB, 0x0007FFEC,
+- 0x0007FFED, 0x0007FFEE, 0x0007FFEF, 0x0007FFF0, 0x0007FFF1, 0x0007FFF2,
+- 0x0007FFF3, 0x0007FFF4, 0x0007FFF5, 0x0007FFF6, 0x0007FFF7, 0x0007FFF8,
+- 0x0007FFF9, 0x0007FFFA, 0x0007FFFB, 0x0007FFFC, 0x0007FFFD, 0x0007FFFE,
+- 0x0007FFFF};
+-
+-/* direction: time
+- contents : codeword lengths
+- raw table: HuffCode3C2FIX.m/envelopeLevel_00T_cF.mat/v_nLhex_cF
+- built by : FH 01-07-05 */
+-
+-const UCHAR v_Huff_envelopeLevelL10T[121] = {
+- 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13, 0x13,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+- 0x13, 0x11, 0x12, 0x10, 0x11, 0x12, 0x11, 0x10, 0x10, 0x10, 0x10,
+- 0x0F, 0x0E, 0x0E, 0x0D, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07,
+- 0x06, 0x05, 0x04, 0x03, 0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+- 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0E, 0x0F, 0x10, 0x11, 0x10,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13};
+-
+-/* direction: freq
+- contents : codewords
+- raw table: HuffCode3C2FIX.m/envelopeLevel_00F_cF.mat/v_nChex_cF
+- built by : FH 01-07-05 */
+-
+-const INT v_Huff_envelopeLevelC10F[121] = {
+- 0x0007FFE7, 0x0007FFE8, 0x000FFFD2, 0x000FFFD3, 0x000FFFD4, 0x000FFFD5,
+- 0x000FFFD6, 0x000FFFD7, 0x000FFFD8, 0x0007FFDA, 0x000FFFD9, 0x000FFFDA,
+- 0x000FFFDB, 0x000FFFDC, 0x0007FFDB, 0x000FFFDD, 0x0007FFDC, 0x0007FFDD,
+- 0x000FFFDE, 0x0003FFE4, 0x000FFFDF, 0x000FFFE0, 0x000FFFE1, 0x0007FFDE,
+- 0x000FFFE2, 0x000FFFE3, 0x000FFFE4, 0x0007FFDF, 0x000FFFE5, 0x0007FFE0,
+- 0x0003FFE8, 0x0007FFE1, 0x0003FFE0, 0x0003FFE9, 0x0001FFEF, 0x0003FFE5,
+- 0x0001FFEC, 0x0001FFED, 0x0001FFEE, 0x0000FFF4, 0x0000FFF3, 0x0000FFF0,
+- 0x00007FF7, 0x00007FF6, 0x00003FFA, 0x00001FFA, 0x00001FF9, 0x00000FFA,
+- 0x00000FF8, 0x000007F9, 0x000003FB, 0x000001FC, 0x000001FA, 0x000000FB,
+- 0x0000007C, 0x0000003C, 0x0000001C, 0x0000000C, 0x00000005, 0x00000001,
+- 0x00000000, 0x00000004, 0x0000000D, 0x0000001D, 0x0000003D, 0x000000FA,
+- 0x000000FC, 0x000001FB, 0x000003FA, 0x000007F8, 0x000007FA, 0x000007FB,
+- 0x00000FF9, 0x00000FFB, 0x00001FF8, 0x00001FFB, 0x00003FF8, 0x00003FF9,
+- 0x0000FFF1, 0x0000FFF2, 0x0001FFEA, 0x0001FFEB, 0x0003FFE1, 0x0003FFE2,
+- 0x0003FFEA, 0x0003FFE3, 0x0003FFE6, 0x0003FFE7, 0x0003FFEB, 0x000FFFE6,
+- 0x0007FFE2, 0x000FFFE7, 0x000FFFE8, 0x000FFFE9, 0x000FFFEA, 0x000FFFEB,
+- 0x000FFFEC, 0x0007FFE3, 0x000FFFED, 0x000FFFEE, 0x000FFFEF, 0x000FFFF0,
+- 0x0007FFE4, 0x000FFFF1, 0x0003FFEC, 0x000FFFF2, 0x000FFFF3, 0x0007FFE5,
+- 0x0007FFE6, 0x000FFFF4, 0x000FFFF5, 0x000FFFF6, 0x000FFFF7, 0x000FFFF8,
+- 0x000FFFF9, 0x000FFFFA, 0x000FFFFB, 0x000FFFFC, 0x000FFFFD, 0x000FFFFE,
+- 0x000FFFFF};
+-
+-/* direction: freq
+- contents : codeword lengths
+- raw table: HuffCode3C2FIX.m/envelopeLevel_00F_cF.mat/v_nLhex_cF
+- built by : FH 01-07-05 */
+-
+-const UCHAR v_Huff_envelopeLevelL10F[121] = {
+- 0x13, 0x13, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x13, 0x14,
+- 0x14, 0x14, 0x14, 0x13, 0x14, 0x13, 0x13, 0x14, 0x12, 0x14, 0x14,
+- 0x14, 0x13, 0x14, 0x14, 0x14, 0x13, 0x14, 0x13, 0x12, 0x13, 0x12,
+- 0x12, 0x11, 0x12, 0x11, 0x11, 0x11, 0x10, 0x10, 0x10, 0x0F, 0x0F,
+- 0x0E, 0x0D, 0x0D, 0x0C, 0x0C, 0x0B, 0x0A, 0x09, 0x09, 0x08, 0x07,
+- 0x06, 0x05, 0x04, 0x03, 0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08,
+- 0x08, 0x09, 0x0A, 0x0B, 0x0B, 0x0B, 0x0C, 0x0C, 0x0D, 0x0D, 0x0E,
+- 0x0E, 0x10, 0x10, 0x11, 0x11, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
+- 0x12, 0x14, 0x13, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x13, 0x14,
+- 0x14, 0x14, 0x14, 0x13, 0x14, 0x12, 0x14, 0x14, 0x13, 0x13, 0x14,
+- 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14};
+-
+-/*******************************************************************************/
+-/* table : envelope balance, 1.5 dB */
+-/* theor range : [-48,48], CODE_BOOK_SCF_LAV = 48 */
+-/* implem range: same but mapped to [-24,24], CODE_BOOK_SCF_LAV_BALANCE10 = 24
+- */
+-/* raw stats : envelopePan_00 (yes, wrong suffix in name) KK 01-03-09 */
+-/*******************************************************************************/
+-
+-/* direction: time
+- contents : codewords
+- raw table: HuffCode3C.m/envelopePan_00T.mat/v_nBhex
+- built by : FH 01-05-15 */
+-
+-const INT bookSbrEnvBalanceC10T[49] = {
+- 0x0000FFE4, 0x0000FFE5, 0x0000FFE6, 0x0000FFE7, 0x0000FFE8, 0x0000FFE9,
+- 0x0000FFEA, 0x0000FFEB, 0x0000FFEC, 0x0000FFED, 0x0000FFEE, 0x0000FFEF,
+- 0x0000FFF0, 0x0000FFF1, 0x0000FFF2, 0x0000FFF3, 0x0000FFF4, 0x0000FFE2,
+- 0x00000FFC, 0x000007FC, 0x000001FE, 0x0000007E, 0x0000001E, 0x00000006,
+- 0x00000000, 0x00000002, 0x0000000E, 0x0000003E, 0x000000FE, 0x000007FD,
+- 0x00000FFD, 0x00007FF0, 0x0000FFE3, 0x0000FFF5, 0x0000FFF6, 0x0000FFF7,
+- 0x0000FFF8, 0x0000FFF9, 0x0000FFFA, 0x0001FFF6, 0x0001FFF7, 0x0001FFF8,
+- 0x0001FFF9, 0x0001FFFA, 0x0001FFFB, 0x0001FFFC, 0x0001FFFD, 0x0001FFFE,
+- 0x0001FFFF};
+-
+-/* direction: time
+- contents : codeword lengths
+- raw table: HuffCode3C.m/envelopePan_00T.mat/v_nLhex
+- built by : FH 01-05-15 */
+-
+-const UCHAR bookSbrEnvBalanceL10T[49] = {
+- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0C, 0x0B,
+- 0x09, 0x07, 0x05, 0x03, 0x01, 0x02, 0x04, 0x06, 0x08, 0x0B,
+- 0x0C, 0x0F, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x11,
+- 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};
+-
+-/* direction: freq
+- contents : codewords
+- raw table: HuffCode3C.m/envelopePan_00F.mat/v_nBhex
+- built by : FH 01-05-15 */
+-
+-const INT bookSbrEnvBalanceC10F[49] = {
+- 0x0003FFE2, 0x0003FFE3, 0x0003FFE4, 0x0003FFE5, 0x0003FFE6, 0x0003FFE7,
+- 0x0003FFE8, 0x0003FFE9, 0x0003FFEA, 0x0003FFEB, 0x0003FFEC, 0x0003FFED,
+- 0x0003FFEE, 0x0003FFEF, 0x0003FFF0, 0x0000FFF7, 0x0001FFF0, 0x00003FFC,
+- 0x000007FE, 0x000007FC, 0x000000FE, 0x0000007E, 0x0000000E, 0x00000002,
+- 0x00000000, 0x00000006, 0x0000001E, 0x0000003E, 0x000001FE, 0x000007FD,
+- 0x00000FFE, 0x00007FFA, 0x0000FFF6, 0x0003FFF1, 0x0003FFF2, 0x0003FFF3,
+- 0x0003FFF4, 0x0003FFF5, 0x0003FFF6, 0x0003FFF7, 0x0003FFF8, 0x0003FFF9,
+- 0x0003FFFA, 0x0003FFFB, 0x0003FFFC, 0x0003FFFD, 0x0003FFFE, 0x0007FFFE,
+- 0x0007FFFF};
+-
+-/* direction: freq
+- contents : codeword lengths
+- raw table: HuffCode3C.m/envelopePan_00F.mat/v_nLhex
+- built by : FH 01-05-15 */
+-
+-const UCHAR bookSbrEnvBalanceL10F[49] = {
+- 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
+- 0x12, 0x12, 0x12, 0x12, 0x12, 0x10, 0x11, 0x0E, 0x0B, 0x0B,
+- 0x08, 0x07, 0x04, 0x02, 0x01, 0x03, 0x05, 0x06, 0x09, 0x0B,
+- 0x0C, 0x0F, 0x10, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
+- 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13};
+-
+-/*******************************************************************************/
+-/* table : envelope level, 3.0 dB */
+-/* theor range : [-29,29], CODE_BOOK_SCF_LAV = 29 */
+-/* implem range: [-31,31], CODE_BOOK_SCF_LAV11 = 31 */
+-/* raw stats : envelopeLevel_11 KK 00-02-03 */
+-/*******************************************************************************/
+-
+-/* direction: time
+- contents : codewords
+- raw table: HuffCode2.m
+- built by : FH 00-02-04 */
+-
+-const INT v_Huff_envelopeLevelC11T[63] = {
+- 0x0003FFED, 0x0003FFEE, 0x0007FFDE, 0x0007FFDF, 0x0007FFE0, 0x0007FFE1,
+- 0x0007FFE2, 0x0007FFE3, 0x0007FFE4, 0x0007FFE5, 0x0007FFE6, 0x0007FFE7,
+- 0x0007FFE8, 0x0007FFE9, 0x0007FFEA, 0x0007FFEB, 0x0007FFEC, 0x0001FFF4,
+- 0x0000FFF7, 0x0000FFF9, 0x0000FFF8, 0x00003FFB, 0x00003FFA, 0x00003FF8,
+- 0x00001FFA, 0x00000FFC, 0x000007FC, 0x000000FE, 0x0000003E, 0x0000000E,
+- 0x00000002, 0x00000000, 0x00000006, 0x0000001E, 0x0000007E, 0x000001FE,
+- 0x000007FD, 0x00001FFB, 0x00003FF9, 0x00003FFC, 0x00007FFA, 0x0000FFF6,
+- 0x0001FFF5, 0x0003FFEC, 0x0007FFED, 0x0007FFEE, 0x0007FFEF, 0x0007FFF0,
+- 0x0007FFF1, 0x0007FFF2, 0x0007FFF3, 0x0007FFF4, 0x0007FFF5, 0x0007FFF6,
+- 0x0007FFF7, 0x0007FFF8, 0x0007FFF9, 0x0007FFFA, 0x0007FFFB, 0x0007FFFC,
+- 0x0007FFFD, 0x0007FFFE, 0x0007FFFF};
+-
+-/* direction: time
+- contents : codeword lengths
+- raw table: HuffCode2.m
+- built by : FH 00-02-04 */
+-
+-const UCHAR v_Huff_envelopeLevelL11T[63] = {
+- 0x12, 0x12, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x11, 0x10, 0x10, 0x10, 0x0E,
+- 0x0E, 0x0E, 0x0D, 0x0C, 0x0B, 0x08, 0x06, 0x04, 0x02, 0x01, 0x03,
+- 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0E, 0x0E, 0x0F, 0x10, 0x11, 0x12,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13};
+-
+-/* direction: freq
+- contents : codewords
+- raw table: HuffCode2.m
+- built by : FH 00-02-04 */
+-
+-const INT v_Huff_envelopeLevelC11F[63] = {
+- 0x000FFFF0, 0x000FFFF1, 0x000FFFF2, 0x000FFFF3, 0x000FFFF4, 0x000FFFF5,
+- 0x000FFFF6, 0x0003FFF3, 0x0007FFF5, 0x0007FFEE, 0x0007FFEF, 0x0007FFF6,
+- 0x0003FFF4, 0x0003FFF2, 0x000FFFF7, 0x0007FFF0, 0x0001FFF5, 0x0003FFF0,
+- 0x0001FFF4, 0x0000FFF7, 0x0000FFF6, 0x00007FF8, 0x00003FFB, 0x00000FFD,
+- 0x000007FD, 0x000003FD, 0x000001FD, 0x000000FD, 0x0000003E, 0x0000000E,
+- 0x00000002, 0x00000000, 0x00000006, 0x0000001E, 0x000000FC, 0x000001FC,
+- 0x000003FC, 0x000007FC, 0x00000FFC, 0x00001FFC, 0x00003FFA, 0x00007FF9,
+- 0x00007FFA, 0x0000FFF8, 0x0000FFF9, 0x0001FFF6, 0x0001FFF7, 0x0003FFF5,
+- 0x0003FFF6, 0x0003FFF1, 0x000FFFF8, 0x0007FFF1, 0x0007FFF2, 0x0007FFF3,
+- 0x000FFFF9, 0x0007FFF7, 0x0007FFF4, 0x000FFFFA, 0x000FFFFB, 0x000FFFFC,
+- 0x000FFFFD, 0x000FFFFE, 0x000FFFFF};
+-
+-/* direction: freq
+- contents : codeword lengths
+- raw table: HuffCode2.m
+- built by : FH 00-02-04 */
+-
+-const UCHAR v_Huff_envelopeLevelL11F[63] = {
+- 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x12, 0x13, 0x13, 0x13,
+- 0x13, 0x12, 0x12, 0x14, 0x13, 0x11, 0x12, 0x11, 0x10, 0x10, 0x0F,
+- 0x0E, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01, 0x03,
+- 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x0F, 0x10,
+- 0x10, 0x11, 0x11, 0x12, 0x12, 0x12, 0x14, 0x13, 0x13, 0x13, 0x14,
+- 0x13, 0x13, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14};
+-
+-/*******************************************************************************/
+-/* table : envelope balance, 3.0 dB */
+-/* theor range : [-24,24], CODE_BOOK_SCF_LAV = 24 */
+-/* implem range: same but mapped to [-12,12], CODE_BOOK_SCF_LAV_BALANCE11 = 12
+- */
+-/* raw stats : envelopeBalance_11 KK 00-02-03 */
+-/*******************************************************************************/
+-
+-/* direction: time
+- contents : codewords
+- raw table: HuffCode3C.m/envelopeBalance_11T.mat/v_nBhex
+- built by : FH 01-05-15 */
+-
+-const INT bookSbrEnvBalanceC11T[25] = {
+- 0x00001FF2, 0x00001FF3, 0x00001FF4, 0x00001FF5, 0x00001FF6,
+- 0x00001FF7, 0x00001FF8, 0x00000FF8, 0x000000FE, 0x0000007E,
+- 0x0000000E, 0x00000006, 0x00000000, 0x00000002, 0x0000001E,
+- 0x0000003E, 0x000001FE, 0x00001FF9, 0x00001FFA, 0x00001FFB,
+- 0x00001FFC, 0x00001FFD, 0x00001FFE, 0x00003FFE, 0x00003FFF};
+-
+-/* direction: time
+- contents : codeword lengths
+- raw table: HuffCode3C.m/envelopeBalance_11T.mat/v_nLhex
+- built by : FH 01-05-15 */
+-
+-const UCHAR bookSbrEnvBalanceL11T[25] = {
+- 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0C, 0x08,
+- 0x07, 0x04, 0x03, 0x01, 0x02, 0x05, 0x06, 0x09, 0x0D,
+- 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0E, 0x0E};
+-
+-/* direction: freq
+- contents : codewords
+- raw table: HuffCode3C.m/envelopeBalance_11F.mat/v_nBhex
+- built by : FH 01-05-15 */
+-
+-const INT bookSbrEnvBalanceC11F[25] = {
+- 0x00001FF7, 0x00001FF8, 0x00001FF9, 0x00001FFA, 0x00001FFB,
+- 0x00003FF8, 0x00003FF9, 0x000007FC, 0x000000FE, 0x0000007E,
+- 0x0000000E, 0x00000002, 0x00000000, 0x00000006, 0x0000001E,
+- 0x0000003E, 0x000001FE, 0x00000FFA, 0x00001FF6, 0x00003FFA,
+- 0x00003FFB, 0x00003FFC, 0x00003FFD, 0x00003FFE, 0x00003FFF};
+-
+-/* direction: freq
+- contents : codeword lengths
+- raw table: HuffCode3C.m/envelopeBalance_11F.mat/v_nLhex
+- built by : FH 01-05-15 */
+-
+-const UCHAR bookSbrEnvBalanceL11F[25] = {
+- 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0E, 0x0E, 0x0B, 0x08,
+- 0x07, 0x04, 0x02, 0x01, 0x03, 0x05, 0x06, 0x09, 0x0C,
+- 0x0D, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E};
+-
+-/*******************************************************************************/
+-/* table : noise level, 3.0 dB */
+-/* theor range : [-29,29], CODE_BOOK_SCF_LAV = 29 */
+-/* implem range: [-31,31], CODE_BOOK_SCF_LAV11 = 31 */
+-/* raw stats : noiseLevel_11 KK 00-02-03 */
+-/*******************************************************************************/
+-
+-/* direction: time
+- contents : codewords
+- raw table: HuffCode2.m
+- built by : FH 00-02-04 */
+-
+-const INT v_Huff_NoiseLevelC11T[63] = {
+- 0x00001FCE, 0x00001FCF, 0x00001FD0, 0x00001FD1, 0x00001FD2, 0x00001FD3,
+- 0x00001FD4, 0x00001FD5, 0x00001FD6, 0x00001FD7, 0x00001FD8, 0x00001FD9,
+- 0x00001FDA, 0x00001FDB, 0x00001FDC, 0x00001FDD, 0x00001FDE, 0x00001FDF,
+- 0x00001FE0, 0x00001FE1, 0x00001FE2, 0x00001FE3, 0x00001FE4, 0x00001FE5,
+- 0x00001FE6, 0x00001FE7, 0x000007F2, 0x000000FD, 0x0000003E, 0x0000000E,
+- 0x00000006, 0x00000000, 0x00000002, 0x0000001E, 0x000000FC, 0x000003F8,
+- 0x00001FCC, 0x00001FE8, 0x00001FE9, 0x00001FEA, 0x00001FEB, 0x00001FEC,
+- 0x00001FCD, 0x00001FED, 0x00001FEE, 0x00001FEF, 0x00001FF0, 0x00001FF1,
+- 0x00001FF2, 0x00001FF3, 0x00001FF4, 0x00001FF5, 0x00001FF6, 0x00001FF7,
+- 0x00001FF8, 0x00001FF9, 0x00001FFA, 0x00001FFB, 0x00001FFC, 0x00001FFD,
+- 0x00001FFE, 0x00003FFE, 0x00003FFF};
+-
+-/* direction: time
+- contents : codeword lengths
+- raw table: HuffCode2.m
+- built by : FH 00-02-04 */
+-
+-const UCHAR v_Huff_NoiseLevelL11T[63] = {
+- 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D,
+- 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D,
+- 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D,
+- 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D,
+- 0x0000000D, 0x0000000D, 0x0000000B, 0x00000008, 0x00000006, 0x00000004,
+- 0x00000003, 0x00000001, 0x00000002, 0x00000005, 0x00000008, 0x0000000A,
+- 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D,
+- 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D,
+- 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D,
+- 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D, 0x0000000D,
+- 0x0000000D, 0x0000000E, 0x0000000E};
+-
+-/*******************************************************************************/
+-/* table : noise balance, 3.0 dB */
+-/* theor range : [-24,24], CODE_BOOK_SCF_LAV = 24 */
+-/* implem range: same but mapped to [-12,12], CODE_BOOK_SCF_LAV_BALANCE11 = 12
+- */
+-/* raw stats : noiseBalance_11 KK 00-02-03 */
+-/*******************************************************************************/
+-
+-/* direction: time
+- contents : codewords
+- raw table: HuffCode3C.m/noiseBalance_11.mat/v_nBhex
+- built by : FH 01-05-15 */
+-
+-const INT bookSbrNoiseBalanceC11T[25] = {
+- 0x000000EC, 0x000000ED, 0x000000EE, 0x000000EF, 0x000000F0,
+- 0x000000F1, 0x000000F2, 0x000000F3, 0x000000F4, 0x000000F5,
+- 0x0000001C, 0x00000002, 0x00000000, 0x00000006, 0x0000003A,
+- 0x000000F6, 0x000000F7, 0x000000F8, 0x000000F9, 0x000000FA,
+- 0x000000FB, 0x000000FC, 0x000000FD, 0x000000FE, 0x000000FF};
+-
+-/* direction: time
+- contents : codeword lengths
+- raw table: HuffCode3C.m/noiseBalance_11.mat/v_nLhex
+- built by : FH 01-05-15 */
+-
+-const UCHAR bookSbrNoiseBalanceL11T[25] = {
+- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
+- 0x08, 0x05, 0x02, 0x01, 0x03, 0x06, 0x08, 0x08, 0x08,
+- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08};
+-
+-/*
+- tuningTable
+-*/
+-const sbrTuningTable_t sbrTuningTable[] = {
+- /* Some of the low bitrates are commented out here, this is because the
+- encoder could lose frames at those bitrates and throw an error
+- because it has insufficient bits to encode for some test items.
+- */
+-
+- /*** HE-AAC section ***/
+- /* sf,sfsp,sf,sfsp,nnb,nfo,saml,SM,FS*/
+-
+- /*** mono ***/
+-
+- /* 8/16 kHz dual rate */
+- {CODEC_AAC, 8000, 10000, 8000, 1, 7, 6, 11, 10, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 10000, 12000, 8000, 1, 11, 7, 13, 12, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 12000, 16001, 8000, 1, 14, 10, 13, 13, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 16000, 24000, 8000, 1, 14, 10, 14, 14, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 24000, 32000, 8000, 1, 14, 10, 14, 14, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 32000, 48001, 8000, 1, 14, 11, 15, 15, 2, 0, 3, SBR_MONO, 2},
+-
+- /* 11/22 kHz dual rate */
+- {CODEC_AAC, 8000, 10000, 11025, 1, 5, 4, 6, 6, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 10000, 12000, 11025, 1, 8, 5, 12, 9, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 12000, 16000, 11025, 1, 12, 8, 13, 8, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 16000, 20000, 11025, 1, 12, 8, 13, 8, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 20000, 24001, 11025, 1, 13, 9, 13, 8, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 24000, 32000, 11025, 1, 14, 10, 14, 9, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 32000, 48000, 11025, 1, 15, 11, 15, 10, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 48000, 64001, 11025, 1, 15, 11, 15, 10, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 12/24 kHz dual rate */
+- {CODEC_AAC, 8000, 10000, 12000, 1, 4, 3, 6, 6, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 10000, 12000, 12000, 1, 7, 4, 11, 8, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 12000, 16000, 12000, 1, 11, 7, 12, 8, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 16000, 20000, 12000, 1, 11, 7, 12, 8, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 20000, 24001, 12000, 1, 12, 8, 12, 8, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 24000, 32000, 12000, 1, 13, 9, 13, 9, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 32000, 48000, 12000, 1, 14, 10, 14, 10, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 48000, 64001, 12000, 1, 14, 11, 15, 11, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 16/32 kHz dual rate */
+- {CODEC_AAC, 8000, 10000, 16000, 1, 1, 1, 0, 0, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 10000, 12000, 16000, 1, 2, 1, 6, 0, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 12000, 16000, 16000, 1, 4, 2, 6, 0, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 16000, 18000, 16000, 1, 4, 2, 8, 3, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 18000, 22000, 16000, 1, 6, 5, 11, 7, 2, 0, 6, SBR_MONO, 2},
+- {CODEC_AAC, 22000, 28000, 16000, 1, 10, 9, 12, 8, 2, 0, 6, SBR_MONO, 2},
+- {CODEC_AAC, 28000, 36000, 16000, 1, 12, 12, 13, 13, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 36000, 44000, 16000, 1, 14, 14, 13, 13, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 44000, 64001, 16000, 1, 14, 14, 13, 13, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 22.05/44.1 kHz dual rate */
+- /* { CODEC_AAC, 8000, 11369, 22050, 1, 1, 1, 1, 1, 1, 0, 6,
+- SBR_MONO, 3 }, */
+- {CODEC_AAC, 11369, 16000, 22050, 1, 3, 1, 4, 4, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 16000, 18000, 22050, 1, 3, 1, 5, 4, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 18000, 22000, 22050, 1, 4, 4, 8, 5, 2, 0, 6, SBR_MONO, 2},
+- {CODEC_AAC, 22000, 28000, 22050, 1, 7, 6, 8, 6, 2, 0, 6, SBR_MONO, 2},
+- {CODEC_AAC, 28000, 36000, 22050, 1, 10, 10, 9, 9, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 36000, 44000, 22050, 1, 11, 11, 10, 10, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 44000, 64001, 22050, 1, 13, 13, 12, 12, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 24/48 kHz dual rate */
+- /* { CODEC_AAC, 8000, 12000, 24000, 1, 1, 1, 1, 1, 1, 0, 6,
+- SBR_MONO, 3 }, */
+- {CODEC_AAC, 12000, 16000, 24000, 1, 3, 1, 4, 4, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 16000, 18000, 24000, 1, 3, 1, 5, 4, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AAC, 18000, 22000, 24000, 1, 4, 3, 8, 5, 2, 0, 6, SBR_MONO, 2},
+- {CODEC_AAC, 22000, 28000, 24000, 1, 7, 6, 8, 6, 2, 0, 6, SBR_MONO, 2},
+- {CODEC_AAC, 28000, 36000, 24000, 1, 10, 10, 9, 9, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 36000, 44000, 24000, 1, 11, 11, 10, 10, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 44000, 64001, 24000, 1, 13, 13, 11, 11, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 32/64 kHz dual rate */
+- {CODEC_AAC, 24000, 36000, 32000, 1, 4, 4, 4, 4, 2, 0, 3, SBR_MONO, 3},
+- {CODEC_AAC, 36000, 60000, 32000, 1, 7, 7, 6, 6, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 60000, 72000, 32000, 1, 9, 9, 8, 8, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 72000, 100000, 32000, 1, 11, 11, 10, 10, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 100000, 160001, 32000, 1, 13, 13, 11, 11, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 44.1/88.2 kHz dual rate */
+- {CODEC_AAC, 24000, 36000, 44100, 1, 4, 4, 4, 4, 2, 0, 3, SBR_MONO, 3},
+- {CODEC_AAC, 36000, 60000, 44100, 1, 7, 7, 6, 6, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 60000, 72000, 44100, 1, 9, 9, 8, 8, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 72000, 100000, 44100, 1, 11, 11, 10, 10, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 100000, 160001, 44100, 1, 13, 13, 11, 11, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 48/96 kHz dual rate */
+- {CODEC_AAC, 32000, 36000, 48000, 1, 4, 4, 9, 9, 2, 0, 3, SBR_MONO, 3},
+- {CODEC_AAC, 36000, 60000, 48000, 1, 7, 7, 10, 10, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AAC, 60000, 72000, 48000, 1, 9, 9, 10, 10, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 72000, 100000, 48000, 1, 11, 11, 11, 11, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AAC, 100000, 160001, 48000, 1, 13, 13, 11, 11, 2, 0, 3, SBR_MONO, 1},
+-
+- /*** stereo ***/
+- /* 08/16 kHz dual rate */
+- {CODEC_AAC, 16000, 24000, 8000, 2, 6, 6, 9, 7, 1, 0, -3, SBR_SWITCH_LRC, 3},
+- {CODEC_AAC, 24000, 28000, 8000, 2, 9, 9, 11, 9, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 28000, 36000, 8000, 2, 11, 9, 11, 9, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 36000, 44000, 8000, 2, 13, 11, 13, 11, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 44000, 52000, 8000, 2, 14, 12, 13, 12, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 52000, 60000, 8000, 2, 14, 14, 13, 13, 3, 0, -3, SBR_SWITCH_LRC,
+- 1},
+- {CODEC_AAC, 60000, 76000, 8000, 2, 14, 14, 13, 13, 3, 0, -3, SBR_LEFT_RIGHT,
+- 1},
+- {CODEC_AAC, 76000, 128001, 8000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 11/22 kHz dual rate */
+- {CODEC_AAC, 16000, 24000, 11025, 2, 7, 5, 9, 7, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 24000, 28000, 11025, 2, 10, 8, 10, 8, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 28000, 36000, 11025, 2, 12, 8, 12, 8, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 36000, 44000, 11025, 2, 13, 9, 13, 9, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 44000, 52000, 11025, 2, 14, 11, 13, 11, 2, 0, -3,
+- SBR_SWITCH_LRC, 2},
+- {CODEC_AAC, 52000, 60000, 11025, 2, 15, 15, 13, 13, 3, 0, -3,
+- SBR_SWITCH_LRC, 1},
+- {CODEC_AAC, 60000, 76000, 11025, 2, 15, 15, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AAC, 76000, 128001, 11025, 2, 15, 15, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 12/24 kHz dual rate */
+- {CODEC_AAC, 16000, 24000, 12000, 2, 6, 4, 9, 7, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 24000, 28000, 12000, 2, 9, 7, 10, 8, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 28000, 36000, 12000, 2, 11, 7, 12, 8, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 36000, 44000, 12000, 2, 12, 9, 12, 9, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 44000, 52000, 12000, 2, 13, 12, 13, 12, 2, 0, -3,
+- SBR_SWITCH_LRC, 2},
+- {CODEC_AAC, 52000, 60000, 12000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_SWITCH_LRC, 1},
+- {CODEC_AAC, 60000, 76000, 12000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AAC, 76000, 128001, 12000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 16/32 kHz dual rate */
+- {CODEC_AAC, 16000, 24000, 16000, 2, 4, 2, 1, 0, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 24000, 28000, 16000, 2, 8, 7, 10, 8, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 28000, 36000, 16000, 2, 10, 9, 12, 11, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 36000, 44000, 16000, 2, 13, 13, 13, 13, 2, 0, -3,
+- SBR_SWITCH_LRC, 2},
+- {CODEC_AAC, 44000, 52000, 16000, 2, 14, 14, 13, 13, 2, 0, -3,
+- SBR_SWITCH_LRC, 2},
+- {CODEC_AAC, 52000, 60000, 16000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_SWITCH_LRC, 1},
+- {CODEC_AAC, 60000, 76000, 16000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AAC, 76000, 128001, 16000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 22.05/44.1 kHz dual rate */
+- {CODEC_AAC, 16000, 24000, 22050, 2, 2, 1, 1, 0, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 24000, 28000, 22050, 2, 5, 4, 6, 5, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 28000, 32000, 22050, 2, 5, 4, 8, 7, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 32000, 36000, 22050, 2, 7, 6, 8, 7, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 36000, 44000, 22050, 2, 10, 10, 9, 9, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 44000, 52000, 22050, 2, 12, 12, 9, 9, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 52000, 60000, 22050, 2, 13, 13, 10, 10, 3, 0, -3,
+- SBR_SWITCH_LRC, 1},
+- {CODEC_AAC, 60000, 76000, 22050, 2, 14, 14, 12, 12, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AAC, 76000, 128001, 22050, 2, 14, 14, 12, 12, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 24/48 kHz dual rate */
+- {CODEC_AAC, 16000, 24000, 24000, 2, 2, 1, 1, 0, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 24000, 28000, 24000, 2, 5, 5, 6, 6, 1, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 28000, 36000, 24000, 2, 7, 6, 8, 7, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 36000, 44000, 24000, 2, 10, 10, 9, 9, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 44000, 52000, 24000, 2, 12, 12, 9, 9, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 52000, 60000, 24000, 2, 13, 13, 10, 10, 3, 0, -3,
+- SBR_SWITCH_LRC, 1},
+- {CODEC_AAC, 60000, 76000, 24000, 2, 14, 14, 12, 12, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AAC, 76000, 128001, 24000, 2, 14, 14, 12, 12, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 32/64 kHz dual rate */
+- {CODEC_AAC, 32000, 60000, 32000, 2, 4, 4, 4, 4, 2, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 60000, 80000, 32000, 2, 7, 7, 6, 6, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 80000, 112000, 32000, 2, 9, 9, 8, 8, 3, 0, -3, SBR_LEFT_RIGHT,
+- 1},
+- {CODEC_AAC, 112000, 144000, 32000, 2, 11, 11, 10, 10, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AAC, 144000, 256001, 32000, 2, 13, 13, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 44.1/88.2 kHz dual rate */
+- {CODEC_AAC, 32000, 60000, 44100, 2, 4, 4, 4, 4, 2, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 60000, 80000, 44100, 2, 7, 7, 6, 6, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 80000, 112000, 44100, 2, 9, 9, 8, 8, 3, 0, -3, SBR_LEFT_RIGHT,
+- 1},
+- {CODEC_AAC, 112000, 144000, 44100, 2, 11, 11, 10, 10, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AAC, 144000, 256001, 44100, 2, 13, 13, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 48/96 kHz dual rate */
+- {CODEC_AAC, 36000, 60000, 48000, 2, 4, 4, 9, 9, 2, 0, -3, SBR_SWITCH_LRC,
+- 3},
+- {CODEC_AAC, 60000, 80000, 48000, 2, 7, 7, 9, 9, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AAC, 80000, 112000, 48000, 2, 9, 9, 10, 10, 3, 0, -3, SBR_LEFT_RIGHT,
+- 1},
+- {CODEC_AAC, 112000, 144000, 48000, 2, 11, 11, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AAC, 144000, 256001, 48000, 2, 13, 13, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /** AAC LOW DELAY SECTION **/
+-
+- /* 24 kHz dual rate - 12kHz singlerate is not allowed (deactivated in
+- FDKsbrEnc_IsSbrSettingAvail()) */
+- {CODEC_AACLD, 8000, 32000, 12000, 1, 1, 1, 0, 0, 1, 0, 6, SBR_MONO, 3},
+-
+- /*** mono ***/
+- /* 16/32 kHz dual rate */
+- {CODEC_AACLD, 16000, 18000, 16000, 1, 4, 5, 9, 7, 1, 0, 6, SBR_MONO, 3},
+- {CODEC_AACLD, 18000, 22000, 16000, 1, 7, 7, 12, 12, 1, 6, 9, SBR_MONO, 3},
+- {CODEC_AACLD, 22000, 28000, 16000, 1, 6, 6, 9, 9, 2, 3, 6, SBR_MONO, 3},
+- {CODEC_AACLD, 28000, 36000, 16000, 1, 8, 8, 12, 7, 2, 9, 12, SBR_MONO, 3},
+- {CODEC_AACLD, 36000, 44000, 16000, 1, 10, 14, 12, 13, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AACLD, 44000, 64001, 16000, 1, 11, 14, 13, 13, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 22.05/44.1 kHz dual rate */
+- {CODEC_AACLD, 18000, 22000, 22050, 1, 4, 4, 5, 5, 2, 0, 6, SBR_MONO, 3},
+- {CODEC_AACLD, 22000, 28000, 22050, 1, 5, 5, 6, 6, 2, 0, 6, SBR_MONO, 2},
+- {CODEC_AACLD, 28000, 36000, 22050, 1, 7, 8, 8, 8, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AACLD, 36000, 44000, 22050, 1, 9, 9, 9, 9, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AACLD, 44000, 52000, 22050, 1, 12, 11, 11, 11, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AACLD, 52000, 64001, 22050, 1, 13, 11, 11, 10, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 24/48 kHz dual rate */
+- {CODEC_AACLD, 20000, 22000, 24000, 1, 3, 4, 8, 8, 2, 0, 6, SBR_MONO, 2},
+- {CODEC_AACLD, 22000, 28000, 24000, 1, 3, 8, 8, 7, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AACLD, 28000, 36000, 24000, 1, 4, 8, 8, 7, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AACLD, 36000, 56000, 24000, 1, 8, 9, 9, 8, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AACLD, 56000, 64001, 24000, 1, 13, 11, 11, 10, 2, 0, 3, SBR_MONO, 1},
+-
+- /* 32/64 kHz dual rate */
+- {CODEC_AACLD, 24000, 36000, 32000, 1, 4, 4, 4, 4, 2, 0, 3, SBR_MONO, 3},
+- {CODEC_AACLD, 36000, 60000, 32000, 1, 7, 7, 6, 6, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AACLD, 60000, 72000, 32000, 1, 9, 9, 8, 8, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AACLD, 72000, 100000, 32000, 1, 11, 11, 10, 10, 2, 0, 3, SBR_MONO,
+- 1},
+- {CODEC_AACLD, 100000, 160001, 32000, 1, 13, 13, 11, 11, 2, 0, 3, SBR_MONO,
+- 1},
+-
+- /* 44/88 kHz dual rate */
+- {CODEC_AACLD, 36000, 60000, 44100, 1, 8, 7, 6, 9, 2, 0, 3, SBR_MONO, 2},
+- {CODEC_AACLD, 60000, 72000, 44100, 1, 9, 9, 10, 10, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AACLD, 72000, 100000, 44100, 1, 11, 11, 11, 11, 2, 0, 3, SBR_MONO,
+- 1},
+- {CODEC_AACLD, 100000, 160001, 44100, 1, 13, 13, 11, 11, 2, 0, 3, SBR_MONO,
+- 1},
+-
+- /* 48/96 kHz dual rate */ /* 32 and 40kbps line tuned for dual-rate SBR
+- */
+- {CODEC_AACLD, 36000, 60000, 48000, 1, 4, 7, 4, 4, 2, 0, 3, SBR_MONO, 3},
+- {CODEC_AACLD, 60000, 72000, 48000, 1, 9, 9, 10, 10, 2, 0, 3, SBR_MONO, 1},
+- {CODEC_AACLD, 72000, 100000, 48000, 1, 11, 11, 11, 11, 2, 0, 3, SBR_MONO,
+- 1},
+- {CODEC_AACLD, 100000, 160001, 48000, 1, 13, 13, 11, 11, 2, 0, 3, SBR_MONO,
+- 1},
+-
+- /*** stereo ***/
+- /* 16/32 kHz dual rate */
+- {CODEC_AACLD, 32000, 36000, 16000, 2, 10, 9, 12, 11, 2, 0, -3,
+- SBR_SWITCH_LRC, 2},
+- {CODEC_AACLD, 36000, 44000, 16000, 2, 13, 13, 13, 13, 2, 0, -3,
+- SBR_SWITCH_LRC, 2},
+- {CODEC_AACLD, 44000, 52000, 16000, 2, 10, 9, 11, 9, 2, 0, -3,
+- SBR_SWITCH_LRC, 2},
+- {CODEC_AACLD, 52000, 60000, 16000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_SWITCH_LRC, 1},
+- {CODEC_AACLD, 60000, 76000, 16000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 76000, 128001, 16000, 2, 14, 14, 13, 13, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 22.05/44.1 kHz dual rate */
+- {CODEC_AACLD, 32000, 36000, 22050, 2, 5, 4, 7, 6, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AACLD, 36000, 44000, 22050, 2, 5, 8, 8, 8, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AACLD, 44000, 52000, 22050, 2, 7, 10, 8, 8, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AACLD, 52000, 60000, 22050, 2, 9, 11, 9, 9, 3, 0, -3, SBR_SWITCH_LRC,
+- 1},
+- {CODEC_AACLD, 60000, 76000, 22050, 2, 10, 12, 10, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 76000, 82000, 22050, 2, 12, 12, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 82000, 128001, 22050, 2, 13, 12, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 24/48 kHz dual rate */
+- {CODEC_AACLD, 32000, 36000, 24000, 2, 5, 4, 7, 6, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AACLD, 36000, 44000, 24000, 2, 4, 8, 8, 8, 2, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AACLD, 44000, 52000, 24000, 2, 6, 10, 8, 8, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AACLD, 52000, 60000, 24000, 2, 9, 11, 9, 9, 3, 0, -3, SBR_SWITCH_LRC,
+- 1},
+- {CODEC_AACLD, 60000, 76000, 24000, 2, 11, 12, 10, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 76000, 88000, 24000, 2, 12, 13, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 88000, 128001, 24000, 2, 13, 13, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 32/64 kHz dual rate */
+- {CODEC_AACLD, 60000, 80000, 32000, 2, 7, 7, 6, 6, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AACLD, 80000, 112000, 32000, 2, 9, 9, 8, 8, 3, 0, -3, SBR_LEFT_RIGHT,
+- 1},
+- {CODEC_AACLD, 112000, 144000, 32000, 2, 11, 11, 10, 10, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 144000, 256001, 32000, 2, 13, 13, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 44.1/88.2 kHz dual rate */
+- {CODEC_AACLD, 60000, 80000, 44100, 2, 7, 7, 6, 6, 3, 0, -3, SBR_SWITCH_LRC,
+- 2},
+- {CODEC_AACLD, 80000, 112000, 44100, 2, 10, 10, 8, 8, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 112000, 144000, 44100, 2, 12, 12, 10, 10, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 144000, 256001, 44100, 2, 13, 13, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+- /* 48/96 kHz dual rate */
+- {CODEC_AACLD, 60000, 80000, 48000, 2, 7, 7, 10, 10, 2, 0, -3,
+- SBR_SWITCH_LRC, 2},
+- {CODEC_AACLD, 80000, 112000, 48000, 2, 9, 9, 10, 10, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 112000, 144000, 48000, 2, 11, 11, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 144000, 176000, 48000, 2, 12, 12, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+- {CODEC_AACLD, 176000, 256001, 48000, 2, 13, 13, 11, 11, 3, 0, -3,
+- SBR_LEFT_RIGHT, 1},
+-
+-};
+-
+-const int sbrTuningTableSize =
+- sizeof(sbrTuningTable) / sizeof(sbrTuningTable[0]);
+-
+-const psTuningTable_t psTuningTable[4] = {
+- {8000, 22000, PSENC_STEREO_BANDS_10, PSENC_NENV_1,
+- FL2FXCONST_DBL(3.0f / 4.0f)},
+- {22000, 28000, PSENC_STEREO_BANDS_20, PSENC_NENV_1,
+- FL2FXCONST_DBL(2.0f / 4.0f)},
+- {28000, 36000, PSENC_STEREO_BANDS_20, PSENC_NENV_2,
+- FL2FXCONST_DBL(1.5f / 4.0f)},
+- {36000, 160001, PSENC_STEREO_BANDS_20, PSENC_NENV_4,
+- FL2FXCONST_DBL(1.1f / 4.0f)},
+-};
+-
+-//@}
+diff --git a/libSBRenc/src/sbrenc_rom.h b/libSBRenc/src/sbrenc_rom.h
+deleted file mode 100644
+index 18c1fb9..0000000
+--- a/libSBRenc/src/sbrenc_rom.h
++++ /dev/null
+@@ -1,145 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+-\file
+-\brief Declaration of constant tables
+-$Revision: 92790 $
+-*/
+-#ifndef SBRENC_ROM_H
+-#define SBRENC_ROM_H
+-
+-#include "sbr_def.h"
+-#include "sbr_encoder.h"
+-
+-#include "ps_main.h"
+-
+-/*
+- huffman tables
+-*/
+-extern const INT v_Huff_envelopeLevelC10T[121];
+-extern const UCHAR v_Huff_envelopeLevelL10T[121];
+-extern const INT v_Huff_envelopeLevelC10F[121];
+-extern const UCHAR v_Huff_envelopeLevelL10F[121];
+-extern const INT bookSbrEnvBalanceC10T[49];
+-extern const UCHAR bookSbrEnvBalanceL10T[49];
+-extern const INT bookSbrEnvBalanceC10F[49];
+-extern const UCHAR bookSbrEnvBalanceL10F[49];
+-extern const INT v_Huff_envelopeLevelC11T[63];
+-extern const UCHAR v_Huff_envelopeLevelL11T[63];
+-extern const INT v_Huff_envelopeLevelC11F[63];
+-extern const UCHAR v_Huff_envelopeLevelL11F[63];
+-extern const INT bookSbrEnvBalanceC11T[25];
+-extern const UCHAR bookSbrEnvBalanceL11T[25];
+-extern const INT bookSbrEnvBalanceC11F[25];
+-extern const UCHAR bookSbrEnvBalanceL11F[25];
+-extern const INT v_Huff_NoiseLevelC11T[63];
+-extern const UCHAR v_Huff_NoiseLevelL11T[63];
+-extern const INT bookSbrNoiseBalanceC11T[25];
+-extern const UCHAR bookSbrNoiseBalanceL11T[25];
+-
+-extern const sbrTuningTable_t sbrTuningTable[];
+-extern const int sbrTuningTableSize;
+-
+-extern const psTuningTable_t psTuningTable[4];
+-
+-#endif
+diff --git a/libSBRenc/src/ton_corr.cpp b/libSBRenc/src/ton_corr.cpp
+deleted file mode 100644
+index 1c050e2..0000000
+--- a/libSBRenc/src/ton_corr.cpp
++++ /dev/null
+@@ -1,891 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "ton_corr.h"
+-
+-#include "sbrenc_ram.h"
+-#include "sbr_misc.h"
+-#include "genericStds.h"
+-#include "autocorr2nd.h"
+-
+-#define BAND_V_SIZE 32
+-#define NUM_V_COMBINE \
+- 8 /* Must be a divisor of 64 and fulfill the ASSERTs below */
+-
+-/**************************************************************************/
+-/*!
+- \brief Calculates the tonal to noise ration for different frequency bands
+- and time segments.
+-
+- The ratio between the predicted energy (tonal energy A) and the total
+- energy (A + B) is calculated. This is converted to the ratio between
+- the predicted energy (tonal energy A) and the non-predictable energy
+- (noise energy B). Hence the quota-matrix contains A/B = q/(1-q).
+-
+- The samples in nrgVector are scaled by 1.0/16.0
+- The samples in pNrgVectorFreq are scaled by 1.0/2.0
+- The samples in quotaMatrix are scaled by RELAXATION
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-
+-void FDKsbrEnc_CalculateTonalityQuotas(
+- HANDLE_SBR_TON_CORR_EST hTonCorr, /*!< Handle to SBR_TON_CORR struct. */
+- FIXP_DBL **RESTRICT
+- sourceBufferReal, /*!< The real part of the QMF-matrix. */
+- FIXP_DBL **RESTRICT
+- sourceBufferImag, /*!< The imaginary part of the QMF-matrix. */
+- INT usb, /*!< upper side band, highest + 1 QMF band in the SBR range. */
+- INT qmfScale /*!< sclefactor of QMF subsamples */
+-) {
+- INT i, k, r, r2, timeIndex, autoCorrScaling;
+-
+- INT startIndexMatrix = hTonCorr->startIndexMatrix;
+- INT totNoEst = hTonCorr->numberOfEstimates;
+- INT noEstPerFrame = hTonCorr->numberOfEstimatesPerFrame;
+- INT move = hTonCorr->move;
+- INT noQmfChannels = hTonCorr->noQmfChannels; /* Number of Bands */
+- INT buffLen = hTonCorr->bufferLength; /* Number of Slots */
+- INT stepSize = hTonCorr->stepSize;
+- INT *pBlockLength = hTonCorr->lpcLength;
+- INT **RESTRICT signMatrix = hTonCorr->signMatrix;
+- FIXP_DBL *RESTRICT nrgVector = hTonCorr->nrgVector;
+- FIXP_DBL **RESTRICT quotaMatrix = hTonCorr->quotaMatrix;
+- FIXP_DBL *RESTRICT pNrgVectorFreq = hTonCorr->nrgVectorFreq;
+-
+- FIXP_DBL *realBuf;
+- FIXP_DBL *imagBuf;
+-
+- FIXP_DBL alphar[2], alphai[2], fac;
+-
+- C_ALLOC_SCRATCH_START(ac, ACORR_COEFS, 1)
+- C_ALLOC_SCRATCH_START(realBufRef, FIXP_DBL, 2 * BAND_V_SIZE * NUM_V_COMBINE)
+- realBuf = realBufRef;
+- imagBuf = realBuf + BAND_V_SIZE * NUM_V_COMBINE;
+-
+- FDK_ASSERT(buffLen <= BAND_V_SIZE);
+- FDK_ASSERT(sizeof(FIXP_DBL) * NUM_V_COMBINE * BAND_V_SIZE * 2 <
+- (1024 * sizeof(FIXP_DBL) - sizeof(ACORR_COEFS)));
+-
+- /*
+- * Buffering of the quotaMatrix and the quotaMatrixTransp.
+- *********************************************************/
+- for (i = 0; i < move; i++) {
+- FDKmemcpy(quotaMatrix[i], quotaMatrix[i + noEstPerFrame],
+- noQmfChannels * sizeof(FIXP_DBL));
+- FDKmemcpy(signMatrix[i], signMatrix[i + noEstPerFrame],
+- noQmfChannels * sizeof(INT));
+- }
+-
+- FDKmemmove(nrgVector, nrgVector + noEstPerFrame, move * sizeof(FIXP_DBL));
+- FDKmemclear(nrgVector + startIndexMatrix,
+- (totNoEst - startIndexMatrix) * sizeof(FIXP_DBL));
+- FDKmemclear(pNrgVectorFreq, noQmfChannels * sizeof(FIXP_DBL));
+-
+- /*
+- * Calculate the quotas for the current time steps.
+- **************************************************/
+-
+- for (r = 0; r < usb; r++) {
+- int blockLength;
+-
+- k = hTonCorr->nextSample; /* startSample */
+- timeIndex = startIndexMatrix;
+- /* Copy as many as possible Band across all Slots at once */
+- if (realBuf != realBufRef) {
+- realBuf -= BAND_V_SIZE;
+- imagBuf -= BAND_V_SIZE;
+- } else {
+- realBuf += BAND_V_SIZE * (NUM_V_COMBINE - 1);
+- imagBuf += BAND_V_SIZE * (NUM_V_COMBINE - 1);
+-
+- for (i = 0; i < buffLen; i++) {
+- int v;
+- FIXP_DBL *ptr;
+- ptr = realBuf + i;
+- for (v = 0; v < NUM_V_COMBINE; v++) {
+- ptr[0] = sourceBufferReal[i][r + v];
+- ptr[0 + BAND_V_SIZE * NUM_V_COMBINE] = sourceBufferImag[i][r + v];
+- ptr -= BAND_V_SIZE;
+- }
+- }
+- }
+-
+- blockLength = pBlockLength[0];
+-
+- while (k <= buffLen - blockLength) {
+- autoCorrScaling = fixMin(
+- getScalefactor(&realBuf[k - LPC_ORDER], LPC_ORDER + blockLength),
+- getScalefactor(&imagBuf[k - LPC_ORDER], LPC_ORDER + blockLength));
+- autoCorrScaling = fixMax(0, autoCorrScaling - 1);
+-
+- scaleValues(&realBuf[k - LPC_ORDER], LPC_ORDER + blockLength,
+- autoCorrScaling);
+- scaleValues(&imagBuf[k - LPC_ORDER], LPC_ORDER + blockLength,
+- autoCorrScaling);
+-
+- autoCorrScaling <<= 1; /* consider qmf buffer scaling twice */
+- autoCorrScaling +=
+- autoCorr2nd_cplx(ac, realBuf + k, imagBuf + k, blockLength);
+-
+- if (ac->det == FL2FXCONST_DBL(0.0f)) {
+- alphar[1] = alphai[1] = FL2FXCONST_DBL(0.0f);
+-
+- alphar[0] = (ac->r01r) >> 2;
+- alphai[0] = (ac->r01i) >> 2;
+-
+- fac = fMultDiv2(ac->r00r, ac->r11r) >> 1;
+- } else {
+- alphar[1] = (fMultDiv2(ac->r01r, ac->r12r) >> 1) -
+- (fMultDiv2(ac->r01i, ac->r12i) >> 1) -
+- (fMultDiv2(ac->r02r, ac->r11r) >> 1);
+- alphai[1] = (fMultDiv2(ac->r01i, ac->r12r) >> 1) +
+- (fMultDiv2(ac->r01r, ac->r12i) >> 1) -
+- (fMultDiv2(ac->r02i, ac->r11r) >> 1);
+-
+- alphar[0] = (fMultDiv2(ac->r01r, ac->det) >> (ac->det_scale + 1)) +
+- fMult(alphar[1], ac->r12r) + fMult(alphai[1], ac->r12i);
+- alphai[0] = (fMultDiv2(ac->r01i, ac->det) >> (ac->det_scale + 1)) +
+- fMult(alphai[1], ac->r12r) - fMult(alphar[1], ac->r12i);
+-
+- fac = fMultDiv2(ac->r00r, fMult(ac->det, ac->r11r)) >>
+- (ac->det_scale + 1);
+- }
+-
+- if (fac == FL2FXCONST_DBL(0.0f)) {
+- quotaMatrix[timeIndex][r] = FL2FXCONST_DBL(0.0f);
+- signMatrix[timeIndex][r] = 0;
+- } else {
+- /* quotaMatrix is scaled with the factor RELAXATION
+- parse RELAXATION in fractional part and shift factor: 1/(1/0.524288 *
+- 2^RELAXATION_SHIFT) */
+- FIXP_DBL tmp, num, denom;
+- INT numShift, denomShift, commonShift;
+- INT sign;
+-
+- num = fMultDiv2(alphar[0], ac->r01r) + fMultDiv2(alphai[0], ac->r01i) -
+- fMultDiv2(alphar[1], fMult(ac->r02r, ac->r11r)) -
+- fMultDiv2(alphai[1], fMult(ac->r02i, ac->r11r));
+- num = fixp_abs(num);
+-
+- denom = (fac >> 1) +
+- (fMultDiv2(fac, RELAXATION_FRACT) >> RELAXATION_SHIFT) - num;
+- denom = fixp_abs(denom);
+-
+- num = fMult(num, RELAXATION_FRACT);
+-
+- numShift = CountLeadingBits(num) - 2;
+- num = scaleValue(num, numShift);
+-
+- denomShift = CountLeadingBits(denom);
+- denom = (FIXP_DBL)denom << denomShift;
+-
+- if ((num > FL2FXCONST_DBL(0.0f)) && (denom != FL2FXCONST_DBL(0.0f))) {
+- commonShift =
+- fixMin(numShift - denomShift + RELAXATION_SHIFT, DFRACT_BITS - 1);
+- if (commonShift < 0) {
+- commonShift = -commonShift;
+- tmp = schur_div(num, denom, 16);
+- commonShift = fixMin(commonShift, CountLeadingBits(tmp));
+- quotaMatrix[timeIndex][r] = tmp << commonShift;
+- } else {
+- quotaMatrix[timeIndex][r] =
+- schur_div(num, denom, 16) >> commonShift;
+- }
+- } else {
+- quotaMatrix[timeIndex][r] = FL2FXCONST_DBL(0.0f);
+- }
+-
+- if (ac->r11r != FL2FXCONST_DBL(0.0f)) {
+- if (((ac->r01r >= FL2FXCONST_DBL(0.0f)) &&
+- (ac->r11r >= FL2FXCONST_DBL(0.0f))) ||
+- ((ac->r01r < FL2FXCONST_DBL(0.0f)) &&
+- (ac->r11r < FL2FXCONST_DBL(0.0f)))) {
+- sign = 1;
+- } else {
+- sign = -1;
+- }
+- } else {
+- sign = 1;
+- }
+-
+- if (sign < 0) {
+- r2 = r; /* (INT) pow(-1, band); */
+- } else {
+- r2 = r + 1; /* (INT) pow(-1, band+1); */
+- }
+- signMatrix[timeIndex][r] = 1 - 2 * (r2 & 0x1);
+- }
+-
+- nrgVector[timeIndex] +=
+- ((ac->r00r) >>
+- fixMin(DFRACT_BITS - 1,
+- (2 * qmfScale + autoCorrScaling + SCALE_NRGVEC)));
+- /* pNrgVectorFreq[r] finally has to be divided by noEstPerFrame, replaced
+- * division by shifting with one */
+- pNrgVectorFreq[r] =
+- pNrgVectorFreq[r] +
+- ((ac->r00r) >>
+- fixMin(DFRACT_BITS - 1,
+- (2 * qmfScale + autoCorrScaling + SCALE_NRGVEC)));
+-
+- blockLength = pBlockLength[1];
+- k += stepSize;
+- timeIndex++;
+- }
+- }
+-
+- C_ALLOC_SCRATCH_END(realBufRef, FIXP_DBL, 2 * BAND_V_SIZE * NUM_V_COMBINE)
+- C_ALLOC_SCRATCH_END(ac, ACORR_COEFS, 1)
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Extracts the parameters required in the decoder to obtain the
+- correct tonal to noise ratio after SBR.
+-
+- Estimates the tonal to noise ratio of the original signal (using LPC).
+- Predicts the tonal to noise ration of the SBR signal (in the decoder) by
+- patching the tonal to noise ratio values similar to the patching of the
+- lowband in the decoder. Given the tonal to noise ratio of the original
+- and the SBR signal, it estimates the required amount of inverse filtering,
+- additional noise as well as any additional sines.
+-
+- \return none.
+-
+-*/
+-/**************************************************************************/
+-void FDKsbrEnc_TonCorrParamExtr(
+- HANDLE_SBR_TON_CORR_EST hTonCorr, /*!< Handle to SBR_TON_CORR struct. */
+- INVF_MODE *infVec, /*!< Vector where the inverse filtering levels will be
+- stored. */
+- FIXP_DBL *noiseLevels, /*!< Vector where the noise levels will be stored. */
+- INT *missingHarmonicFlag, /*!< Flag set to one or zero, dependent on if any
+- strong sines are missing.*/
+- UCHAR *missingHarmonicsIndex, /*!< Vector indicating where sines are
+- missing. */
+- UCHAR *envelopeCompensation, /*!< Vector to store compensation values for
+- the energies in. */
+- const SBR_FRAME_INFO *frameInfo, /*!< Frame info struct, contains the time
+- and frequency grid of the current
+- frame.*/
+- UCHAR *transientInfo, /*!< Transient info.*/
+- UCHAR *freqBandTable, /*!< Frequency band tables for high-res.*/
+- INT nSfb, /*!< Number of scalefactor bands for high-res. */
+- XPOS_MODE xposType, /*!< Type of transposer used in the decoder.*/
+- UINT sbrSyntaxFlags) {
+- INT band;
+- INT transientFlag = transientInfo[1]; /*!< Flag indicating if a transient is
+- present in the current frame. */
+- INT transientPos = transientInfo[0]; /*!< Position of the transient.*/
+- INT transientFrame, transientFrameInvfEst;
+- INVF_MODE *infVecPtr;
+-
+- /* Determine if this is a frame where a transient starts...
+-
+- The detection of noise-floor, missing harmonics and invf_est, is not in sync
+- for the non-buf-opt decoder such as AAC. Hence we need to keep track on the
+- transient in the present frame as well as in the next.
+- */
+- transientFrame = 0;
+- if (hTonCorr->transientNextFrame) { /* The transient was detected in the
+- previous frame, but is actually */
+- transientFrame = 1;
+- hTonCorr->transientNextFrame = 0;
+-
+- if (transientFlag) {
+- if (transientPos + hTonCorr->transientPosOffset >=
+- frameInfo->borders[frameInfo->nEnvelopes]) {
+- hTonCorr->transientNextFrame = 1;
+- }
+- }
+- } else {
+- if (transientFlag) {
+- if (transientPos + hTonCorr->transientPosOffset <
+- frameInfo->borders[frameInfo->nEnvelopes]) {
+- transientFrame = 1;
+- hTonCorr->transientNextFrame = 0;
+- } else {
+- hTonCorr->transientNextFrame = 1;
+- }
+- }
+- }
+- transientFrameInvfEst = transientFrame;
+-
+- /*
+- Estimate the required invese filtereing level.
+- */
+- if (hTonCorr->switchInverseFilt)
+- FDKsbrEnc_qmfInverseFilteringDetector(
+- &hTonCorr->sbrInvFilt, hTonCorr->quotaMatrix, hTonCorr->nrgVector,
+- hTonCorr->indexVector, hTonCorr->frameStartIndexInvfEst,
+- hTonCorr->numberOfEstimatesPerFrame + hTonCorr->frameStartIndexInvfEst,
+- transientFrameInvfEst, infVec);
+-
+- /*
+- Detect what tones will be missing.
+- */
+- if (xposType == XPOS_LC) {
+- FDKsbrEnc_SbrMissingHarmonicsDetectorQmf(
+- &hTonCorr->sbrMissingHarmonicsDetector, hTonCorr->quotaMatrix,
+- hTonCorr->signMatrix, hTonCorr->indexVector, frameInfo, transientInfo,
+- missingHarmonicFlag, missingHarmonicsIndex, freqBandTable, nSfb,
+- envelopeCompensation, hTonCorr->nrgVectorFreq);
+- } else {
+- *missingHarmonicFlag = 0;
+- FDKmemclear(missingHarmonicsIndex, nSfb * sizeof(UCHAR));
+- }
+-
+- /*
+- Noise floor estimation
+- */
+-
+- infVecPtr = hTonCorr->sbrInvFilt.prevInvfMode;
+-
+- FDKsbrEnc_sbrNoiseFloorEstimateQmf(
+- &hTonCorr->sbrNoiseFloorEstimate, frameInfo, noiseLevels,
+- hTonCorr->quotaMatrix, hTonCorr->indexVector, *missingHarmonicFlag,
+- hTonCorr->frameStartIndex, hTonCorr->numberOfEstimatesPerFrame,
+- transientFrame, infVecPtr, sbrSyntaxFlags);
+-
+- /* Store the invfVec data for the next frame...*/
+- for (band = 0; band < hTonCorr->sbrInvFilt.noDetectorBands; band++) {
+- hTonCorr->sbrInvFilt.prevInvfMode[band] = infVec[band];
+- }
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Searches for the closest match in the frequency master table.
+-
+-
+-
+- \return closest entry.
+-
+-*/
+-/**************************************************************************/
+-static INT findClosestEntry(INT goalSb, UCHAR *v_k_master, INT numMaster,
+- INT direction) {
+- INT index;
+-
+- if (goalSb <= v_k_master[0]) return v_k_master[0];
+-
+- if (goalSb >= v_k_master[numMaster]) return v_k_master[numMaster];
+-
+- if (direction) {
+- index = 0;
+- while (v_k_master[index] < goalSb) {
+- index++;
+- }
+- } else {
+- index = numMaster;
+- while (v_k_master[index] > goalSb) {
+- index--;
+- }
+- }
+-
+- return v_k_master[index];
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief resets the patch
+-
+-
+-
+- \return errorCode, noError if successful.
+-
+-*/
+-/**************************************************************************/
+-static INT resetPatch(
+- HANDLE_SBR_TON_CORR_EST hTonCorr, /*!< Handle to SBR_TON_CORR struct. */
+- INT xposctrl, /*!< Different patch modes. */
+- INT highBandStartSb, /*!< Start band of the SBR range. */
+- UCHAR *v_k_master, /*!< Master frequency table from which all other table
+- are derived.*/
+- INT numMaster, /*!< Number of elements in the master table. */
+- INT fs, /*!< Sampling frequency. */
+- INT noChannels) /*!< Number of QMF-channels. */
+-{
+- INT patch, k, i;
+- INT targetStopBand;
+-
+- PATCH_PARAM *patchParam = hTonCorr->patchParam;
+-
+- INT sbGuard = hTonCorr->guard;
+- INT sourceStartBand;
+- INT patchDistance;
+- INT numBandsInPatch;
+-
+- INT lsb =
+- v_k_master[0]; /* Lowest subband related to the synthesis filterbank */
+- INT usb = v_k_master[numMaster]; /* Stop subband related to the synthesis
+- filterbank */
+- INT xoverOffset =
+- highBandStartSb -
+- v_k_master[0]; /* Calculate distance in subbands between k0 and kx */
+-
+- INT goalSb;
+-
+- /*
+- * Initialize the patching parameter
+- */
+-
+- if (xposctrl == 1) {
+- lsb += xoverOffset;
+- xoverOffset = 0;
+- }
+-
+- goalSb = (INT)((2 * noChannels * 16000 + (fs >> 1)) / fs); /* 16 kHz band */
+- goalSb = findClosestEntry(goalSb, v_k_master, numMaster,
+- 1); /* Adapt region to master-table */
+-
+- /* First patch */
+- sourceStartBand = hTonCorr->shiftStartSb + xoverOffset;
+- targetStopBand = lsb + xoverOffset;
+-
+- /* even (odd) numbered channel must be patched to even (odd) numbered channel
+- */
+- patch = 0;
+- while (targetStopBand < usb) {
+- /* To many patches */
+- if (patch >= MAX_NUM_PATCHES) return (1); /*Number of patches to high */
+-
+- patchParam[patch].guardStartBand = targetStopBand;
+- targetStopBand += sbGuard;
+- patchParam[patch].targetStartBand = targetStopBand;
+-
+- numBandsInPatch =
+- goalSb - targetStopBand; /* get the desired range of the patch */
+-
+- if (numBandsInPatch >= lsb - sourceStartBand) {
+- /* desired number bands are not available -> patch whole source range */
+- patchDistance =
+- targetStopBand - sourceStartBand; /* get the targetOffset */
+- patchDistance =
+- patchDistance & ~1; /* rounding off odd numbers and make all even */
+- numBandsInPatch = lsb - (targetStopBand - patchDistance);
+- numBandsInPatch = findClosestEntry(targetStopBand + numBandsInPatch,
+- v_k_master, numMaster, 0) -
+- targetStopBand; /* Adapt region to master-table */
+- }
+-
+- /* desired number bands are available -> get the minimal even patching
+- * distance */
+- patchDistance =
+- numBandsInPatch + targetStopBand - lsb; /* get minimal distance */
+- patchDistance = (patchDistance + 1) &
+- ~1; /* rounding up odd numbers and make all even */
+-
+- if (numBandsInPatch <= 0) {
+- patch--;
+- } else {
+- patchParam[patch].sourceStartBand = targetStopBand - patchDistance;
+- patchParam[patch].targetBandOffs = patchDistance;
+- patchParam[patch].numBandsInPatch = numBandsInPatch;
+- patchParam[patch].sourceStopBand =
+- patchParam[patch].sourceStartBand + numBandsInPatch;
+-
+- targetStopBand += patchParam[patch].numBandsInPatch;
+- }
+-
+- /* All patches but first */
+- sourceStartBand = hTonCorr->shiftStartSb;
+-
+- /* Check if we are close to goalSb */
+- if (fixp_abs(targetStopBand - goalSb) < 3) {
+- goalSb = usb;
+- }
+-
+- patch++;
+- }
+-
+- patch--;
+-
+- /* if highest patch contains less than three subband: skip it */
+- if (patchParam[patch].numBandsInPatch < 3 && patch > 0) {
+- patch--;
+- }
+-
+- hTonCorr->noOfPatches = patch + 1;
+-
+- /* Assign the index-vector, so we know where to look for the high-band.
+- -1 represents a guard-band. */
+- for (k = 0; k < hTonCorr->patchParam[0].guardStartBand; k++)
+- hTonCorr->indexVector[k] = k;
+-
+- for (i = 0; i < hTonCorr->noOfPatches; i++) {
+- INT sourceStart = hTonCorr->patchParam[i].sourceStartBand;
+- INT targetStart = hTonCorr->patchParam[i].targetStartBand;
+- INT numberOfBands = hTonCorr->patchParam[i].numBandsInPatch;
+- INT startGuardBand = hTonCorr->patchParam[i].guardStartBand;
+-
+- for (k = 0; k < (targetStart - startGuardBand); k++)
+- hTonCorr->indexVector[startGuardBand + k] = -1;
+-
+- for (k = 0; k < numberOfBands; k++)
+- hTonCorr->indexVector[targetStart + k] = sourceStart + k;
+- }
+-
+- return (0);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Creates an instance of the tonality correction parameter module.
+-
+- The module includes modules for inverse filtering level estimation,
+- missing harmonics detection and noise floor level estimation.
+-
+- \return errorCode, noError if successful.
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_CreateTonCorrParamExtr(
+- HANDLE_SBR_TON_CORR_EST
+- hTonCorr, /*!< Pointer to handle to SBR_TON_CORR struct. */
+- INT chan) /*!< Channel index, needed for mem allocation */
+-{
+- INT i;
+- FIXP_DBL *quotaMatrix = GetRam_Sbr_quotaMatrix(chan);
+- INT *signMatrix = GetRam_Sbr_signMatrix(chan);
+-
+- if ((NULL == quotaMatrix) || (NULL == signMatrix)) {
+- goto bail;
+- }
+-
+- FDKmemclear(hTonCorr, sizeof(SBR_TON_CORR_EST));
+-
+- for (i = 0; i < MAX_NO_OF_ESTIMATES; i++) {
+- hTonCorr->quotaMatrix[i] = quotaMatrix + (i * 64);
+- hTonCorr->signMatrix[i] = signMatrix + (i * 64);
+- }
+-
+- if (0 != FDKsbrEnc_CreateSbrMissingHarmonicsDetector(
+- &hTonCorr->sbrMissingHarmonicsDetector, chan)) {
+- goto bail;
+- }
+-
+- return 0;
+-
+-bail:
+- hTonCorr->quotaMatrix[0] = quotaMatrix;
+- hTonCorr->signMatrix[0] = signMatrix;
+-
+- FDKsbrEnc_DeleteTonCorrParamExtr(hTonCorr);
+-
+- return -1;
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Initialize an instance of the tonality correction parameter module.
+-
+- The module includes modules for inverse filtering level estimation,
+- missing harmonics detection and noise floor level estimation.
+-
+- \return errorCode, noError if successful.
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_InitTonCorrParamExtr(
+- INT frameSize, /*!< Current SBR frame size. */
+- HANDLE_SBR_TON_CORR_EST
+- hTonCorr, /*!< Pointer to handle to SBR_TON_CORR struct. */
+- HANDLE_SBR_CONFIG_DATA
+- sbrCfg, /*!< Pointer to SBR configuration parameters. */
+- INT timeSlots, /*!< Number of time-slots per frame */
+- INT xposCtrl, /*!< Different patch modes. */
+- INT ana_max_level, /*!< Maximum level of the adaptive noise. */
+- INT noiseBands, /*!< Number of noise bands per octave. */
+- INT noiseFloorOffset, /*!< Noise floor offset. */
+- UINT useSpeechConfig) /*!< Speech or music tuning. */
+-{
+- INT nCols = sbrCfg->noQmfSlots;
+- INT fs = sbrCfg->sampleFreq;
+- INT noQmfChannels = sbrCfg->noQmfBands;
+-
+- INT highBandStartSb = sbrCfg->freqBandTable[LOW_RES][0];
+- UCHAR *v_k_master = sbrCfg->v_k_master;
+- INT numMaster = sbrCfg->num_Master;
+-
+- UCHAR **freqBandTable = sbrCfg->freqBandTable;
+- INT *nSfb = sbrCfg->nSfb;
+-
+- INT i;
+-
+- /*
+- Reset the patching and allocate memory for the quota matrix.
+- Assuming parameters for the LPC analysis.
+- */
+- if (sbrCfg->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- switch (timeSlots) {
+- case NUMBER_TIME_SLOTS_1920:
+- hTonCorr->lpcLength[0] = 8 - LPC_ORDER;
+- hTonCorr->lpcLength[1] = 7 - LPC_ORDER;
+- hTonCorr->numberOfEstimates = NO_OF_ESTIMATES_LD;
+- hTonCorr->numberOfEstimatesPerFrame = 2; /* sbrCfg->noQmfSlots / 7 */
+- hTonCorr->frameStartIndexInvfEst = 0;
+- hTonCorr->transientPosOffset = FRAME_MIDDLE_SLOT_512LD;
+- break;
+- case NUMBER_TIME_SLOTS_2048:
+- hTonCorr->lpcLength[0] = 8 - LPC_ORDER;
+- hTonCorr->lpcLength[1] = 8 - LPC_ORDER;
+- hTonCorr->numberOfEstimates = NO_OF_ESTIMATES_LD;
+- hTonCorr->numberOfEstimatesPerFrame = 2; /* sbrCfg->noQmfSlots / 8 */
+- hTonCorr->frameStartIndexInvfEst = 0;
+- hTonCorr->transientPosOffset = FRAME_MIDDLE_SLOT_512LD;
+- break;
+- }
+- } else
+- switch (timeSlots) {
+- case NUMBER_TIME_SLOTS_2048:
+- hTonCorr->lpcLength[0] = 16 - LPC_ORDER; /* blockLength[0] */
+- hTonCorr->lpcLength[1] = 16 - LPC_ORDER; /* blockLength[0] */
+- hTonCorr->numberOfEstimates = NO_OF_ESTIMATES_LC;
+- hTonCorr->numberOfEstimatesPerFrame = sbrCfg->noQmfSlots / 16;
+- hTonCorr->frameStartIndexInvfEst = 0;
+- hTonCorr->transientPosOffset = FRAME_MIDDLE_SLOT_2048;
+- break;
+- case NUMBER_TIME_SLOTS_1920:
+- hTonCorr->lpcLength[0] = 15 - LPC_ORDER; /* blockLength[0] */
+- hTonCorr->lpcLength[1] = 15 - LPC_ORDER; /* blockLength[0] */
+- hTonCorr->numberOfEstimates = NO_OF_ESTIMATES_LC;
+- hTonCorr->numberOfEstimatesPerFrame = sbrCfg->noQmfSlots / 15;
+- hTonCorr->frameStartIndexInvfEst = 0;
+- hTonCorr->transientPosOffset = FRAME_MIDDLE_SLOT_1920;
+- break;
+- default:
+- return -1;
+- }
+-
+- hTonCorr->bufferLength = nCols;
+- hTonCorr->stepSize =
+- hTonCorr->lpcLength[0] + LPC_ORDER; /* stepSize[0] implicitly 0. */
+-
+- hTonCorr->nextSample = LPC_ORDER; /* firstSample */
+- hTonCorr->move = hTonCorr->numberOfEstimates -
+- hTonCorr->numberOfEstimatesPerFrame; /* Number of estimates
+- to move when
+- buffering.*/
+- if (hTonCorr->move < 0) {
+- return -1;
+- }
+- hTonCorr->startIndexMatrix =
+- hTonCorr->numberOfEstimates -
+- hTonCorr->numberOfEstimatesPerFrame; /* Where to store the latest
+- estimations in the tonality
+- Matrix.*/
+- hTonCorr->frameStartIndex = 0; /* Where in the tonality matrix the current
+- frame (to be sent to the decoder) starts. */
+- hTonCorr->prevTransientFlag = 0;
+- hTonCorr->transientNextFrame = 0;
+-
+- hTonCorr->noQmfChannels = noQmfChannels;
+-
+- for (i = 0; i < hTonCorr->numberOfEstimates; i++) {
+- FDKmemclear(hTonCorr->quotaMatrix[i], sizeof(FIXP_DBL) * noQmfChannels);
+- FDKmemclear(hTonCorr->signMatrix[i], sizeof(INT) * noQmfChannels);
+- }
+-
+- /* Reset the patch.*/
+- hTonCorr->guard = 0;
+- hTonCorr->shiftStartSb = 1;
+-
+- if (resetPatch(hTonCorr, xposCtrl, highBandStartSb, v_k_master, numMaster, fs,
+- noQmfChannels))
+- return (1);
+-
+- if (FDKsbrEnc_InitSbrNoiseFloorEstimate(
+- &hTonCorr->sbrNoiseFloorEstimate, ana_max_level, freqBandTable[LO],
+- nSfb[LO], noiseBands, noiseFloorOffset, timeSlots, useSpeechConfig))
+- return (1);
+-
+- if (FDKsbrEnc_initInvFiltDetector(
+- &hTonCorr->sbrInvFilt,
+- hTonCorr->sbrNoiseFloorEstimate.freqBandTableQmf,
+- hTonCorr->sbrNoiseFloorEstimate.noNoiseBands, useSpeechConfig))
+- return (1);
+-
+- if (FDKsbrEnc_InitSbrMissingHarmonicsDetector(
+- &hTonCorr->sbrMissingHarmonicsDetector, fs, frameSize, nSfb[HI],
+- noQmfChannels, hTonCorr->numberOfEstimates, hTonCorr->move,
+- hTonCorr->numberOfEstimatesPerFrame, sbrCfg->sbrSyntaxFlags))
+- return (1);
+-
+- return (0);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief resets tonality correction parameter module.
+-
+-
+-
+- \return errorCode, noError if successful.
+-
+-*/
+-/**************************************************************************/
+-INT FDKsbrEnc_ResetTonCorrParamExtr(
+- HANDLE_SBR_TON_CORR_EST hTonCorr, /*!< Handle to SBR_TON_CORR struct. */
+- INT xposctrl, /*!< Different patch modes. */
+- INT highBandStartSb, /*!< Start band of the SBR range. */
+- UCHAR *v_k_master, /*!< Master frequency table from which all other table
+- are derived.*/
+- INT numMaster, /*!< Number of elements in the master table. */
+- INT fs, /*!< Sampling frequency (of the SBR part). */
+- UCHAR *
+- *freqBandTable, /*!< Frequency band table for low-res and high-res. */
+- INT *nSfb, /*!< Number of frequency bands (hig-res and low-res). */
+- INT noQmfChannels /*!< Number of QMF channels. */
+-) {
+- /* Reset the patch.*/
+- hTonCorr->guard = 0;
+- hTonCorr->shiftStartSb = 1;
+-
+- if (resetPatch(hTonCorr, xposctrl, highBandStartSb, v_k_master, numMaster, fs,
+- noQmfChannels))
+- return (1);
+-
+- /* Reset the noise floor estimate.*/
+- if (FDKsbrEnc_resetSbrNoiseFloorEstimate(&hTonCorr->sbrNoiseFloorEstimate,
+- freqBandTable[LO], nSfb[LO]))
+- return (1);
+-
+- /*
+- Reset the inveerse filtereing detector.
+- */
+- if (FDKsbrEnc_resetInvFiltDetector(
+- &hTonCorr->sbrInvFilt,
+- hTonCorr->sbrNoiseFloorEstimate.freqBandTableQmf,
+- hTonCorr->sbrNoiseFloorEstimate.noNoiseBands))
+- return (1);
+- /* Reset the missing harmonics detector. */
+- if (FDKsbrEnc_ResetSbrMissingHarmonicsDetector(
+- &hTonCorr->sbrMissingHarmonicsDetector, nSfb[HI]))
+- return (1);
+-
+- return (0);
+-}
+-
+-/**************************************************************************/
+-/*!
+- \brief Deletes the tonality correction paramtere module.
+-
+-
+-
+- \return none
+-
+-*/
+-/**************************************************************************/
+-void FDKsbrEnc_DeleteTonCorrParamExtr(
+- HANDLE_SBR_TON_CORR_EST hTonCorr) /*!< Handle to SBR_TON_CORR struct. */
+-{
+- if (hTonCorr) {
+- FreeRam_Sbr_quotaMatrix(hTonCorr->quotaMatrix);
+-
+- FreeRam_Sbr_signMatrix(hTonCorr->signMatrix);
+-
+- FDKsbrEnc_DeleteSbrMissingHarmonicsDetector(
+- &hTonCorr->sbrMissingHarmonicsDetector);
+- }
+-}
+diff --git a/libSBRenc/src/ton_corr.h b/libSBRenc/src/ton_corr.h
+deleted file mode 100644
+index 91aa278..0000000
+--- a/libSBRenc/src/ton_corr.h
++++ /dev/null
+@@ -1,258 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief General tonality correction detector module.
+-*/
+-#ifndef TON_CORR_H
+-#define TON_CORR_H
+-
+-#include "sbr_encoder.h"
+-#include "mh_det.h"
+-#include "nf_est.h"
+-#include "invf_est.h"
+-
+-#define MAX_NUM_PATCHES 6
+-#define SCALE_NRGVEC 4
+-
+-/** parameter set for one single patch */
+-typedef struct {
+- INT sourceStartBand; /*!< first band in lowbands where to take the samples
+- from */
+- INT sourceStopBand; /*!< first band in lowbands which is not included in the
+- patch anymore */
+- INT guardStartBand; /*!< first band in highbands to be filled with zeros in
+- order to reduce interferences between patches */
+- INT targetStartBand; /*!< first band in highbands to be filled with whitened
+- lowband signal */
+- INT targetBandOffs; /*!< difference between 'startTargetBand' and
+- 'startSourceBand' */
+- INT numBandsInPatch; /*!< number of consecutive bands in this one patch */
+-} PATCH_PARAM;
+-
+-typedef struct {
+- INT switchInverseFilt; /*!< Flag to enable dynamic adaption of invf. detection
+- */
+- INT noQmfChannels;
+- INT bufferLength; /*!< Length of the r and i buffers. */
+- INT stepSize; /*!< Stride for the lpc estimate. */
+- INT numberOfEstimates; /*!< The total number of estiamtes, available in the
+- quotaMatrix.*/
+- UINT numberOfEstimatesPerFrame; /*!< The number of estimates per frame
+- available in the quotaMatrix.*/
+- INT lpcLength[2]; /*!< Segment length used for second order LPC analysis.*/
+- INT nextSample; /*!< Where to start the LPC analysis of the current frame.*/
+- INT move; /*!< How many estimates to move in the quotaMatrix, when buffering.
+- */
+- INT frameStartIndex; /*!< The start index for the current frame in the r and i
+- buffers. */
+- INT startIndexMatrix; /*!< The start index for the current frame in the
+- quotaMatrix. */
+- INT frameStartIndexInvfEst; /*!< The start index of the inverse filtering, not
+- the same as the others, dependent on what
+- decoder is used (buffer opt, or no buffer opt).
+- */
+- INT prevTransientFlag; /*!< The transisent flag (from the transient detector)
+- for the previous frame. */
+- INT transientNextFrame; /*!< Flag to indicate that the transient will show up
+- in the next frame. */
+- INT transientPosOffset; /*!< An offset value to match the transient pos as
+- calculated by the transient detector with the
+- actual position in the frame.*/
+-
+- INT* signMatrix[MAX_NO_OF_ESTIMATES]; /*!< Matrix holding the sign of each
+- channe, i.e. indicating in what part
+- of a QMF channel a possible sine is.
+- */
+-
+- FIXP_DBL* quotaMatrix[MAX_NO_OF_ESTIMATES]; /*!< Matrix holding the quota
+- values for all estimates, all
+- channels. */
+-
+- FIXP_DBL nrgVector[MAX_NO_OF_ESTIMATES]; /*!< Vector holding the averaged
+- energies for every QMF band. */
+- FIXP_DBL nrgVectorFreq[64]; /*!< Vector holding the averaged energies for
+- every QMF channel */
+-
+- SCHAR indexVector[64]; /*!< Index vector poINTing to the correct lowband
+- channel, when indexing a highband channel, -1
+- represents a guard band */
+- PATCH_PARAM
+- patchParam[MAX_NUM_PATCHES]; /*!< new parameter set for patching */
+- INT guard; /*!< number of guardbands between every patch */
+- INT shiftStartSb; /*!< lowest subband of source range to be included in the
+- patches */
+- INT noOfPatches; /*!< number of patches */
+-
+- SBR_MISSING_HARMONICS_DETECTOR
+- sbrMissingHarmonicsDetector; /*!< SBR_MISSING_HARMONICS_DETECTOR struct.
+- */
+- SBR_NOISE_FLOOR_ESTIMATE
+- sbrNoiseFloorEstimate; /*!< SBR_NOISE_FLOOR_ESTIMATE struct. */
+- SBR_INV_FILT_EST sbrInvFilt; /*!< SBR_INV_FILT_EST struct. */
+-} SBR_TON_CORR_EST;
+-
+-typedef SBR_TON_CORR_EST* HANDLE_SBR_TON_CORR_EST;
+-
+-void FDKsbrEnc_TonCorrParamExtr(
+- HANDLE_SBR_TON_CORR_EST hTonCorr, /*!< Handle to SBR_TON_CORR struct. */
+- INVF_MODE* infVec, /*!< Vector where the inverse filtering levels will be
+- stored. */
+- FIXP_DBL* noiseLevels, /*!< Vector where the noise levels will be stored. */
+- INT* missingHarmonicFlag, /*!< Flag set to one or zero, dependent on if any
+- strong sines are missing.*/
+- UCHAR* missingHarmonicsIndex, /*!< Vector indicating where sines are
+- missing. */
+- UCHAR* envelopeCompensation, /*!< Vector to store compensation values for
+- the energies in. */
+- const SBR_FRAME_INFO* frameInfo, /*!< Frame info struct, contains the time
+- and frequency grid of the current
+- frame.*/
+- UCHAR* transientInfo, /*!< Transient info.*/
+- UCHAR* freqBandTable, /*!< Frequency band tables for high-res.*/
+- INT nSfb, /*!< Number of scalefactor bands for high-res. */
+- XPOS_MODE xposType, /*!< Type of transposer used in the decoder.*/
+- UINT sbrSyntaxFlags);
+-
+-INT FDKsbrEnc_CreateTonCorrParamExtr(
+- HANDLE_SBR_TON_CORR_EST
+- hTonCorr, /*!< Pointer to handle to SBR_TON_CORR struct. */
+- INT chan); /*!< Channel index, needed for mem allocation */
+-
+-INT FDKsbrEnc_InitTonCorrParamExtr(
+- INT frameSize, /*!< Current SBR frame size. */
+- HANDLE_SBR_TON_CORR_EST
+- hTonCorr, /*!< Pointer to handle to SBR_TON_CORR struct. */
+- HANDLE_SBR_CONFIG_DATA
+- sbrCfg, /*!< Pointer to SBR configuration parameters. */
+- INT timeSlots, /*!< Number of time-slots per frame */
+- INT xposCtrl, /*!< Different patch modes. */
+- INT ana_max_level, /*!< Maximum level of the adaptive noise. */
+- INT noiseBands, /*!< Number of noise bands per octave. */
+- INT noiseFloorOffset, /*!< Noise floor offset. */
+- UINT useSpeechConfig /*!< Speech or music tuning. */
+-);
+-
+-void FDKsbrEnc_DeleteTonCorrParamExtr(
+- HANDLE_SBR_TON_CORR_EST hTonCorr); /*!< Handle to SBR_TON_CORR struct. */
+-
+-void FDKsbrEnc_CalculateTonalityQuotas(
+- HANDLE_SBR_TON_CORR_EST hTonCorr, FIXP_DBL** sourceBufferReal,
+- FIXP_DBL** sourceBufferImag, INT usb,
+- INT qmfScale /*!< sclefactor of QMF subsamples */
+-);
+-
+-INT FDKsbrEnc_ResetTonCorrParamExtr(
+- HANDLE_SBR_TON_CORR_EST hTonCorr, /*!< Handle to SBR_TON_CORR struct. */
+- INT xposctrl, /*!< Different patch modes. */
+- INT highBandStartSb, /*!< Start band of the SBR range. */
+- UCHAR* v_k_master, /*!< Master frequency table from which all other table
+- are derived.*/
+- INT numMaster, /*!< Number of elements in the master table. */
+- INT fs, /*!< Sampling frequency (of the SBR part). */
+- UCHAR**
+- freqBandTable, /*!< Frequency band table for low-res and high-res. */
+- INT* nSfb, /*!< Number of frequency bands (hig-res and low-res). */
+- INT noQmfChannels /*!< Number of QMF channels. */
+-);
+-#endif
+diff --git a/libSBRenc/src/tran_det.cpp b/libSBRenc/src/tran_det.cpp
+deleted file mode 100644
+index 3b6765a..0000000
+--- a/libSBRenc/src/tran_det.cpp
++++ /dev/null
+@@ -1,1092 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s): Tobias Chalupka
+-
+- Description: SBR encoder transient detector
+-
+-*******************************************************************************/
+-
+-#include "tran_det.h"
+-
+-#include "fram_gen.h"
+-#include "sbrenc_ram.h"
+-#include "sbr_misc.h"
+-
+-#include "genericStds.h"
+-
+-#define NORM_QMF_ENERGY 9.31322574615479E-10 /* 2^-30 */
+-
+-/* static FIXP_DBL ABS_THRES = fixMax( FL2FXCONST_DBL(1.28e5 *
+- * NORM_QMF_ENERGY), (FIXP_DBL)1) Minimum threshold for detecting changes */
+-#define ABS_THRES ((FIXP_DBL)16)
+-
+-/*******************************************************************************
+- Functionname: spectralChange
+- *******************************************************************************
+- \brief Calculates a measure for the spectral change within the frame
+-
+- The function says how good it would be to split the frame at the given border
+- position into 2 envelopes.
+-
+- The return value delta_sum is scaled with the factor 1/64
+-
+- \return calculated value
+-*******************************************************************************/
+-#define NRG_SHIFT 3 /* for energy summation */
+-
+-static FIXP_DBL spectralChange(
+- FIXP_DBL Energies[NUMBER_TIME_SLOTS_2304][MAX_FREQ_COEFFS],
+- INT *scaleEnergies, FIXP_DBL EnergyTotal, INT nSfb, INT start, INT border,
+- INT YBufferWriteOffset, INT stop, INT *result_e) {
+- INT i, j;
+- INT len1, len2;
+- SCHAR energies_e_diff[NUMBER_TIME_SLOTS_2304], energies_e, energyTotal_e = 19,
+- energies_e_add;
+- SCHAR prevEnergies_e_diff, newEnergies_e_diff;
+- FIXP_DBL tmp0, tmp1;
+- FIXP_DBL delta, delta_sum;
+- INT accu_e, tmp_e;
+-
+- delta_sum = FL2FXCONST_DBL(0.0f);
+- *result_e = 0;
+-
+- len1 = border - start;
+- len2 = stop - border;
+-
+- /* prefer borders near the middle of the frame */
+- FIXP_DBL pos_weight;
+- pos_weight = FL2FXCONST_DBL(0.5f) - (len1 * GetInvInt(len1 + len2));
+- pos_weight = /*FL2FXCONST_DBL(1.0)*/ (FIXP_DBL)MAXVAL_DBL -
+- (fMult(pos_weight, pos_weight) << 2);
+-
+- /*** Calc scaling for energies ***/
+- FDK_ASSERT(scaleEnergies[0] >= 0);
+- FDK_ASSERT(scaleEnergies[1] >= 0);
+-
+- energies_e = 19 - fMin(scaleEnergies[0], scaleEnergies[1]);
+-
+- /* limit shift for energy accumulation, energies_e can be -10 min. */
+- if (energies_e < -10) {
+- energies_e_add = -10 - energies_e;
+- energies_e = -10;
+- } else if (energies_e > 17) {
+- energies_e_add = energies_e - 17;
+- energies_e = 17;
+- } else {
+- energies_e_add = 0;
+- }
+-
+- /* compensate scaling differences between scaleEnergies[0] and
+- * scaleEnergies[1] */
+- prevEnergies_e_diff = scaleEnergies[0] -
+- fMin(scaleEnergies[0], scaleEnergies[1]) +
+- energies_e_add + NRG_SHIFT;
+- newEnergies_e_diff = scaleEnergies[1] -
+- fMin(scaleEnergies[0], scaleEnergies[1]) +
+- energies_e_add + NRG_SHIFT;
+-
+- prevEnergies_e_diff = fMin(prevEnergies_e_diff, DFRACT_BITS - 1);
+- newEnergies_e_diff = fMin(newEnergies_e_diff, DFRACT_BITS - 1);
+-
+- for (i = start; i < YBufferWriteOffset; i++) {
+- energies_e_diff[i] = prevEnergies_e_diff;
+- }
+- for (i = YBufferWriteOffset; i < stop; i++) {
+- energies_e_diff[i] = newEnergies_e_diff;
+- }
+-
+- /* Sum up energies of all QMF-timeslots for both halfs */
+- FDK_ASSERT(len1 <= 8); /* otherwise an overflow is possible */
+- FDK_ASSERT(len2 <= 8); /* otherwise an overflow is possible */
+-
+- for (j = 0; j < nSfb; j++) {
+- FIXP_DBL accu1 = FL2FXCONST_DBL(0.f);
+- FIXP_DBL accu2 = FL2FXCONST_DBL(0.f);
+- accu_e = energies_e + 3;
+-
+- /* Sum up energies in first half */
+- for (i = start; i < border; i++) {
+- accu1 += scaleValue(Energies[i][j], -energies_e_diff[i]);
+- }
+-
+- /* Sum up energies in second half */
+- for (i = border; i < stop; i++) {
+- accu2 += scaleValue(Energies[i][j], -energies_e_diff[i]);
+- }
+-
+- /* Ensure certain energy to prevent division by zero and to prevent
+- * splitting for very low levels */
+- accu1 = fMax(accu1, (FIXP_DBL)len1);
+- accu2 = fMax(accu2, (FIXP_DBL)len2);
+-
+-/* Energy change in current band */
+-#define LN2 FL2FXCONST_DBL(0.6931471806f) /* ln(2) */
+- tmp0 = fLog2(accu2, accu_e) - fLog2(accu1, accu_e);
+- tmp1 = fLog2((FIXP_DBL)len1, 31) - fLog2((FIXP_DBL)len2, 31);
+- delta = fMult(LN2, (tmp0 + tmp1));
+- delta = (FIXP_DBL)fAbs(delta);
+-
+- /* Weighting with amplitude ratio of this band */
+- accu_e++; /* scale at least one bit due to (accu1+accu2) */
+- accu1 >>= 1;
+- accu2 >>= 1;
+-
+- if (accu_e & 1) {
+- accu_e++; /* for a defined square result exponent, the exponent has to be
+- even */
+- accu1 >>= 1;
+- accu2 >>= 1;
+- }
+-
+- delta_sum += fMult(sqrtFixp(accu1 + accu2), delta);
+- *result_e = ((accu_e >> 1) + LD_DATA_SHIFT);
+- }
+-
+- if (energyTotal_e & 1) {
+- energyTotal_e += 1; /* for a defined square result exponent, the exponent
+- has to be even */
+- EnergyTotal >>= 1;
+- }
+-
+- delta_sum = fMult(delta_sum, invSqrtNorm2(EnergyTotal, &tmp_e));
+- *result_e = *result_e + (tmp_e - (energyTotal_e >> 1));
+-
+- return fMult(delta_sum, pos_weight);
+-}
+-
+-/*******************************************************************************
+- Functionname: addLowbandEnergies
+- *******************************************************************************
+- \brief Calculates total lowband energy
+-
+- The input values Energies[0] (low-band) are scaled by the factor
+- 2^(14-*scaleEnergies[0])
+- The input values Energies[1] (high-band) are scaled by the factor
+- 2^(14-*scaleEnergies[1])
+-
+- \return total energy in the lowband, scaled by the factor 2^19
+-*******************************************************************************/
+-static FIXP_DBL addLowbandEnergies(FIXP_DBL **Energies, int *scaleEnergies,
+- int YBufferWriteOffset, int nrgSzShift,
+- int tran_off, UCHAR *freqBandTable,
+- int slots) {
+- INT nrgTotal_e;
+- FIXP_DBL nrgTotal_m;
+- FIXP_DBL accu1 = FL2FXCONST_DBL(0.0f);
+- FIXP_DBL accu2 = FL2FXCONST_DBL(0.0f);
+- int tran_offdiv2 = tran_off >> nrgSzShift;
+- const int sc1 =
+- DFRACT_BITS -
+- fNormz((FIXP_DBL)fMax(
+- 1, (freqBandTable[0] * (YBufferWriteOffset - tran_offdiv2) - 1)));
+- const int sc2 =
+- DFRACT_BITS -
+- fNormz((FIXP_DBL)fMax(
+- 1, (freqBandTable[0] *
+- (tran_offdiv2 + (slots >> nrgSzShift) - YBufferWriteOffset) -
+- 1)));
+- int ts, k;
+-
+- /* Sum up lowband energy from one frame at offset tran_off */
+- /* freqBandTable[LORES] has MAX_FREQ_COEFFS/2 +1 coeefs max. */
+- for (ts = tran_offdiv2; ts < YBufferWriteOffset; ts++) {
+- for (k = 0; k < freqBandTable[0]; k++) {
+- accu1 += Energies[ts][k] >> sc1;
+- }
+- }
+- for (; ts < tran_offdiv2 + (slots >> nrgSzShift); ts++) {
+- for (k = 0; k < freqBandTable[0]; k++) {
+- accu2 += Energies[ts][k] >> sc2;
+- }
+- }
+-
+- nrgTotal_m = fAddNorm(accu1, (sc1 - 5) - scaleEnergies[0], accu2,
+- (sc2 - 5) - scaleEnergies[1], &nrgTotal_e);
+- nrgTotal_m = scaleValueSaturate(nrgTotal_m, nrgTotal_e);
+-
+- return (nrgTotal_m);
+-}
+-
+-/*******************************************************************************
+- Functionname: addHighbandEnergies
+- *******************************************************************************
+- \brief Add highband energies
+-
+- Highband energies are mapped to an array with smaller dimension:
+- Its time resolution is only 1 SBR-timeslot and its frequency resolution
+- is 1 SBR-band. Therefore the data to be fed into the spectralChange
+- function is reduced.
+-
+- The values EnergiesM are scaled by the factor (2^19-scaleEnergies[0]) for
+- slots<YBufferWriteOffset and by the factor (2^19-scaleEnergies[1]) for
+- slots>=YBufferWriteOffset.
+-
+- \return total energy in the highband, scaled by factor 2^19
+-*******************************************************************************/
+-
+-static FIXP_DBL addHighbandEnergies(
+- FIXP_DBL **RESTRICT Energies, /*!< input */
+- INT *scaleEnergies, INT YBufferWriteOffset,
+- FIXP_DBL EnergiesM[NUMBER_TIME_SLOTS_2304]
+- [MAX_FREQ_COEFFS], /*!< Combined output */
+- UCHAR *RESTRICT freqBandTable, INT nSfb, INT sbrSlots, INT timeStep) {
+- INT i, j, k, slotIn, slotOut, scale[2];
+- INT li, ui;
+- FIXP_DBL nrgTotal;
+- FIXP_DBL accu = FL2FXCONST_DBL(0.0f);
+-
+- /* Combine QMF-timeslots to SBR-timeslots,
+- combine QMF-bands to SBR-bands,
+- combine Left and Right channel */
+- for (slotOut = 0; slotOut < sbrSlots; slotOut++) {
+- /* Note: Below slotIn = slotOut and not slotIn = timeStep*slotOut
+- because the Energies[] time resolution is always the SBR slot resolution
+- regardless of the timeStep. */
+- slotIn = slotOut;
+-
+- for (j = 0; j < nSfb; j++) {
+- accu = FL2FXCONST_DBL(0.0f);
+-
+- li = freqBandTable[j];
+- ui = freqBandTable[j + 1];
+-
+- for (k = li; k < ui; k++) {
+- for (i = 0; i < timeStep; i++) {
+- accu += Energies[slotIn][k] >> 5;
+- }
+- }
+- EnergiesM[slotOut][j] = accu;
+- }
+- }
+-
+- /* scale energies down before add up */
+- scale[0] = fixMin(8, scaleEnergies[0]);
+- scale[1] = fixMin(8, scaleEnergies[1]);
+-
+- if ((scaleEnergies[0] - scale[0]) > (DFRACT_BITS - 1) ||
+- (scaleEnergies[1] - scale[1]) > (DFRACT_BITS - 1))
+- nrgTotal = FL2FXCONST_DBL(0.0f);
+- else {
+- /* Now add all energies */
+- accu = FL2FXCONST_DBL(0.0f);
+-
+- for (slotOut = 0; slotOut < YBufferWriteOffset; slotOut++) {
+- for (j = 0; j < nSfb; j++) {
+- accu += (EnergiesM[slotOut][j] >> scale[0]);
+- }
+- }
+- nrgTotal = accu >> (scaleEnergies[0] - scale[0]);
+-
+- for (slotOut = YBufferWriteOffset; slotOut < sbrSlots; slotOut++) {
+- for (j = 0; j < nSfb; j++) {
+- accu += (EnergiesM[slotOut][j] >> scale[0]);
+- }
+- }
+- nrgTotal = fAddSaturate(nrgTotal, accu >> (scaleEnergies[1] - scale[1]));
+- }
+-
+- return (nrgTotal);
+-}
+-
+-/*******************************************************************************
+- Functionname: FDKsbrEnc_frameSplitter
+- *******************************************************************************
+- \brief Decides if a FIXFIX-frame shall be splitted into 2 envelopes
+-
+- If no transient has been detected before, the frame can still be splitted
+- into 2 envelopes.
+-*******************************************************************************/
+-void FDKsbrEnc_frameSplitter(
+- FIXP_DBL **Energies, INT *scaleEnergies,
+- HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector, UCHAR *freqBandTable,
+- UCHAR *tran_vector, int YBufferWriteOffset, int YBufferSzShift, int nSfb,
+- int timeStep, int no_cols, FIXP_DBL *tonality) {
+- if (tran_vector[1] == 0) /* no transient was detected */
+- {
+- FIXP_DBL delta;
+- INT delta_e;
+- FIXP_DBL(*EnergiesM)[MAX_FREQ_COEFFS];
+- FIXP_DBL EnergyTotal, newLowbandEnergy, newHighbandEnergy;
+- INT border;
+- INT sbrSlots = fMultI(GetInvInt(timeStep), no_cols);
+- C_ALLOC_SCRATCH_START(_EnergiesM, FIXP_DBL,
+- NUMBER_TIME_SLOTS_2304 * MAX_FREQ_COEFFS)
+-
+- FDK_ASSERT(sbrSlots * timeStep == no_cols);
+-
+- EnergiesM = (FIXP_DBL(*)[MAX_FREQ_COEFFS])_EnergiesM;
+-
+- /*
+- Get Lowband-energy over a range of 2 frames (Look half a frame back and
+- ahead).
+- */
+- newLowbandEnergy = addLowbandEnergies(
+- Energies, scaleEnergies, YBufferWriteOffset, YBufferSzShift,
+- h_sbrTransientDetector->tran_off, freqBandTable, no_cols);
+-
+- newHighbandEnergy =
+- addHighbandEnergies(Energies, scaleEnergies, YBufferWriteOffset,
+- EnergiesM, freqBandTable, nSfb, sbrSlots, timeStep);
+-
+- {
+- /* prevLowBandEnergy: Corresponds to 1 frame, starting with half a frame
+- look-behind newLowbandEnergy: Corresponds to 1 frame, starting in the
+- middle of the current frame */
+- EnergyTotal = (newLowbandEnergy >> 1) +
+- (h_sbrTransientDetector->prevLowBandEnergy >>
+- 1); /* mean of new and prev LB NRG */
+- EnergyTotal =
+- fAddSaturate(EnergyTotal, newHighbandEnergy); /* Add HB NRG */
+- /* The below border should specify the same position as the middle border
+- of a FIXFIX-frame with 2 envelopes. */
+- border = (sbrSlots + 1) >> 1;
+-
+- if ((INT)EnergyTotal & 0xffffffe0 &&
+- (scaleEnergies[0] < 32 || scaleEnergies[1] < 32)) /* i.e. > 31 */ {
+- delta = spectralChange(EnergiesM, scaleEnergies, EnergyTotal, nSfb, 0,
+- border, YBufferWriteOffset, sbrSlots, &delta_e);
+- } else {
+- delta = FL2FXCONST_DBL(0.0f);
+- delta_e = 0;
+-
+- /* set tonality to 0 when energy is very low, since the amplitude
+- resolution should then be low as well */
+- *tonality = FL2FXCONST_DBL(0.0f);
+- }
+-
+- if (fIsLessThan(h_sbrTransientDetector->split_thr_m,
+- h_sbrTransientDetector->split_thr_e, delta, delta_e)) {
+- tran_vector[0] = 1; /* Set flag for splitting */
+- } else {
+- tran_vector[0] = 0;
+- }
+- }
+-
+- /* Update prevLowBandEnergy */
+- h_sbrTransientDetector->prevLowBandEnergy = newLowbandEnergy;
+- h_sbrTransientDetector->prevHighBandEnergy = newHighbandEnergy;
+- C_ALLOC_SCRATCH_END(_EnergiesM, FIXP_DBL,
+- NUMBER_TIME_SLOTS_2304 * MAX_FREQ_COEFFS)
+- }
+-}
+-
+-/*
+- * Calculate transient energy threshold for each QMF band
+- */
+-static void calculateThresholds(FIXP_DBL **RESTRICT Energies,
+- INT *RESTRICT scaleEnergies,
+- FIXP_DBL *RESTRICT thresholds,
+- int YBufferWriteOffset, int YBufferSzShift,
+- int noCols, int noRows, int tran_off) {
+- FIXP_DBL mean_val, std_val, temp;
+- FIXP_DBL i_noCols;
+- FIXP_DBL i_noCols1;
+- FIXP_DBL accu, accu0, accu1;
+- int scaleFactor0, scaleFactor1, commonScale;
+- int i, j;
+-
+- i_noCols = GetInvInt(noCols + tran_off) << YBufferSzShift;
+- i_noCols1 = GetInvInt(noCols + tran_off - 1) << YBufferSzShift;
+-
+- /* calc minimum scale of energies of previous and current frame */
+- commonScale = fixMin(scaleEnergies[0], scaleEnergies[1]);
+-
+- /* calc scalefactors to adapt energies to common scale */
+- scaleFactor0 = fixMin((scaleEnergies[0] - commonScale), (DFRACT_BITS - 1));
+- scaleFactor1 = fixMin((scaleEnergies[1] - commonScale), (DFRACT_BITS - 1));
+-
+- FDK_ASSERT((scaleFactor0 >= 0) && (scaleFactor1 >= 0));
+-
+- /* calculate standard deviation in every subband */
+- for (i = 0; i < noRows; i++) {
+- int startEnergy = (tran_off >> YBufferSzShift);
+- int endEnergy = ((noCols >> YBufferSzShift) + tran_off);
+- int shift;
+-
+- /* calculate mean value over decimated energy values (downsampled by 2). */
+- accu0 = accu1 = FL2FXCONST_DBL(0.0f);
+-
+- for (j = startEnergy; j < YBufferWriteOffset; j++)
+- accu0 = fMultAddDiv2(accu0, Energies[j][i], i_noCols);
+- for (; j < endEnergy; j++)
+- accu1 = fMultAddDiv2(accu1, Energies[j][i], i_noCols);
+-
+- mean_val = ((accu0 << 1) >> scaleFactor0) +
+- ((accu1 << 1) >> scaleFactor1); /* average */
+- shift = fixMax(
+- 0, CountLeadingBits(mean_val) -
+- 6); /* -6 to keep room for accumulating upto N = 24 values */
+-
+- /* calculate standard deviation */
+- accu = FL2FXCONST_DBL(0.0f);
+-
+- /* summe { ((mean_val-nrg)^2) * i_noCols1 } */
+- for (j = startEnergy; j < YBufferWriteOffset; j++) {
+- temp = ((FIXP_DBL)mean_val - ((FIXP_DBL)Energies[j][i] >> scaleFactor0))
+- << shift;
+- temp = fPow2Div2(temp);
+- accu = fMultAddDiv2(accu, temp, i_noCols1);
+- }
+- for (; j < endEnergy; j++) {
+- temp = ((FIXP_DBL)mean_val - ((FIXP_DBL)Energies[j][i] >> scaleFactor1))
+- << shift;
+- temp = fPow2Div2(temp);
+- accu = fMultAddDiv2(accu, temp, i_noCols1);
+- }
+- accu <<= 2;
+- std_val = sqrtFixp(accu) >> shift; /* standard deviation */
+-
+- /*
+- Take new threshold as average of calculated standard deviation ratio
+- and old threshold if greater than absolute threshold
+- */
+- temp = (commonScale <= (DFRACT_BITS - 1))
+- ? fMult(FL2FXCONST_DBL(0.66f), thresholds[i]) +
+- (fMult(FL2FXCONST_DBL(0.34f), std_val) >> commonScale)
+- : (FIXP_DBL)0;
+-
+- thresholds[i] = fixMax(ABS_THRES, temp);
+-
+- FDK_ASSERT(commonScale >= 0);
+- }
+-}
+-
+-/*
+- * Calculate transient levels for each QMF time slot.
+- */
+-static void extractTransientCandidates(
+- FIXP_DBL **RESTRICT Energies, INT *RESTRICT scaleEnergies,
+- FIXP_DBL *RESTRICT thresholds, FIXP_DBL *RESTRICT transients,
+- int YBufferWriteOffset, int YBufferSzShift, int noCols, int start_band,
+- int stop_band, int tran_off, int addPrevSamples) {
+- FIXP_DBL i_thres;
+- C_ALLOC_SCRATCH_START(EnergiesTemp, FIXP_DBL, 2 * 32)
+- int tmpScaleEnergies0, tmpScaleEnergies1;
+- int endCond;
+- int startEnerg, endEnerg;
+- int i, j, jIndex, jpBM;
+-
+- tmpScaleEnergies0 = scaleEnergies[0];
+- tmpScaleEnergies1 = scaleEnergies[1];
+-
+- /* Scale value for first energies, upto YBufferWriteOffset */
+- tmpScaleEnergies0 = fixMin(tmpScaleEnergies0, MAX_SHIFT_DBL);
+- /* Scale value for first energies, from YBufferWriteOffset upwards */
+- tmpScaleEnergies1 = fixMin(tmpScaleEnergies1, MAX_SHIFT_DBL);
+-
+- FDK_ASSERT((tmpScaleEnergies0 >= 0) && (tmpScaleEnergies1 >= 0));
+-
+- /* Keep addPrevSamples extra previous transient candidates. */
+- FDKmemmove(transients, transients + noCols - addPrevSamples,
+- (tran_off + addPrevSamples) * sizeof(FIXP_DBL));
+- FDKmemclear(transients + tran_off + addPrevSamples,
+- noCols * sizeof(FIXP_DBL));
+-
+- endCond = noCols; /* Amount of new transient values to be calculated. */
+- startEnerg = (tran_off - 3) >> YBufferSzShift; /* >>YBufferSzShift because of
+- amount of energy values. -3
+- because of neighbors being
+- watched. */
+- endEnerg =
+- ((noCols + (YBufferWriteOffset << YBufferSzShift)) - 1) >>
+- YBufferSzShift; /* YBufferSzShift shifts because of half energy values. */
+-
+- /* Compute differential values with two different weightings in every subband
+- */
+- for (i = start_band; i < stop_band; i++) {
+- FIXP_DBL thres = thresholds[i];
+-
+- if ((LONG)thresholds[i] >= 256)
+- i_thres = (LONG)((LONG)MAXVAL_DBL / ((((LONG)thresholds[i])) + 1))
+- << (32 - 24);
+- else
+- i_thres = (LONG)MAXVAL_DBL;
+-
+- /* Copy one timeslot and de-scale and de-squish */
+- if (YBufferSzShift == 1) {
+- for (j = startEnerg; j < YBufferWriteOffset; j++) {
+- FIXP_DBL tmp = Energies[j][i];
+- EnergiesTemp[(j << 1) + 1] = EnergiesTemp[j << 1] =
+- tmp >> tmpScaleEnergies0;
+- }
+- for (; j <= endEnerg; j++) {
+- FIXP_DBL tmp = Energies[j][i];
+- EnergiesTemp[(j << 1) + 1] = EnergiesTemp[j << 1] =
+- tmp >> tmpScaleEnergies1;
+- }
+- } else {
+- for (j = startEnerg; j < YBufferWriteOffset; j++) {
+- FIXP_DBL tmp = Energies[j][i];
+- EnergiesTemp[j] = tmp >> tmpScaleEnergies0;
+- }
+- for (; j <= endEnerg; j++) {
+- FIXP_DBL tmp = Energies[j][i];
+- EnergiesTemp[j] = tmp >> tmpScaleEnergies1;
+- }
+- }
+-
+- /* Detect peaks in energy values. */
+-
+- jIndex = tran_off;
+- jpBM = jIndex + addPrevSamples;
+-
+- for (j = endCond; j--; jIndex++, jpBM++) {
+- FIXP_DBL delta, tran;
+- int d;
+-
+- delta = (FIXP_DBL)0;
+- tran = (FIXP_DBL)0;
+-
+- for (d = 1; d < 4; d++) {
+- delta += EnergiesTemp[jIndex + d]; /* R */
+- delta -= EnergiesTemp[jIndex - d]; /* L */
+- delta -= thres;
+-
+- if (delta > (FIXP_DBL)0) {
+- tran = fMultAddDiv2(tran, i_thres, delta);
+- }
+- }
+- transients[jpBM] += (tran << 1);
+- }
+- }
+- C_ALLOC_SCRATCH_END(EnergiesTemp, FIXP_DBL, 2 * 32)
+-}
+-
+-void FDKsbrEnc_transientDetect(HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTran,
+- FIXP_DBL **Energies, INT *scaleEnergies,
+- UCHAR *transient_info, int YBufferWriteOffset,
+- int YBufferSzShift, int timeStep,
+- int frameMiddleBorder) {
+- int no_cols = h_sbrTran->no_cols;
+- int qmfStartSample;
+- int addPrevSamples;
+- int timeStepShift = 0;
+- int i, cond;
+-
+- /* Where to start looking for transients in the transient candidate buffer */
+- qmfStartSample = timeStep * frameMiddleBorder;
+- /* We need to look one value backwards in the transients, so we might need one
+- * more previous value. */
+- addPrevSamples = (qmfStartSample > 0) ? 0 : 1;
+-
+- switch (timeStep) {
+- case 1:
+- timeStepShift = 0;
+- break;
+- case 2:
+- timeStepShift = 1;
+- break;
+- case 4:
+- timeStepShift = 2;
+- break;
+- }
+-
+- calculateThresholds(Energies, scaleEnergies, h_sbrTran->thresholds,
+- YBufferWriteOffset, YBufferSzShift, h_sbrTran->no_cols,
+- h_sbrTran->no_rows, h_sbrTran->tran_off);
+-
+- extractTransientCandidates(
+- Energies, scaleEnergies, h_sbrTran->thresholds, h_sbrTran->transients,
+- YBufferWriteOffset, YBufferSzShift, h_sbrTran->no_cols, 0,
+- h_sbrTran->no_rows, h_sbrTran->tran_off, addPrevSamples);
+-
+- transient_info[0] = 0;
+- transient_info[1] = 0;
+- transient_info[2] = 0;
+-
+- /* Offset by the amount of additional previous transient candidates being
+- * kept. */
+- qmfStartSample += addPrevSamples;
+-
+- /* Check for transients in second granule (pick the last value of subsequent
+- * values) */
+- for (i = qmfStartSample; i < qmfStartSample + no_cols; i++) {
+- cond = (h_sbrTran->transients[i] <
+- fMult(FL2FXCONST_DBL(0.9f), h_sbrTran->transients[i - 1])) &&
+- (h_sbrTran->transients[i - 1] > h_sbrTran->tran_thr);
+-
+- if (cond) {
+- transient_info[0] = (i - qmfStartSample) >> timeStepShift;
+- transient_info[1] = 1;
+- break;
+- }
+- }
+-
+- if (h_sbrTran->frameShift != 0) {
+- /* transient prediction for LDSBR */
+- /* Check for transients in first <frameShift> qmf-slots of second frame */
+- for (i = qmfStartSample + no_cols;
+- i < qmfStartSample + no_cols + h_sbrTran->frameShift; i++) {
+- cond = (h_sbrTran->transients[i] <
+- fMult(FL2FXCONST_DBL(0.9f), h_sbrTran->transients[i - 1])) &&
+- (h_sbrTran->transients[i - 1] > h_sbrTran->tran_thr);
+-
+- if (cond) {
+- int pos = (int)((i - qmfStartSample - no_cols) >> timeStepShift);
+- if ((pos < 3) && (transient_info[1] == 0)) {
+- transient_info[2] = 1;
+- }
+- break;
+- }
+- }
+- }
+-}
+-
+-int FDKsbrEnc_InitSbrTransientDetector(
+- HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector,
+- UINT sbrSyntaxFlags, /* SBR syntax flags derived from AOT. */
+- INT frameSize, INT sampleFreq, sbrConfigurationPtr params, int tran_fc,
+- int no_cols, int no_rows, int YBufferWriteOffset, int YBufferSzShift,
+- int frameShift, int tran_off) {
+- INT totalBitrate =
+- params->codecSettings.standardBitrate * params->codecSettings.nChannels;
+- INT codecBitrate = params->codecSettings.bitRate;
+- FIXP_DBL bitrateFactor_m, framedur_fix;
+- INT bitrateFactor_e, tmp_e;
+-
+- FDKmemclear(h_sbrTransientDetector, sizeof(SBR_TRANSIENT_DETECTOR));
+-
+- h_sbrTransientDetector->frameShift = frameShift;
+- h_sbrTransientDetector->tran_off = tran_off;
+-
+- if (codecBitrate) {
+- bitrateFactor_m = fDivNorm((FIXP_DBL)totalBitrate,
+- (FIXP_DBL)(codecBitrate << 2), &bitrateFactor_e);
+- bitrateFactor_e += 2;
+- } else {
+- bitrateFactor_m = FL2FXCONST_DBL(1.0 / 4.0);
+- bitrateFactor_e = 2;
+- }
+-
+- framedur_fix = fDivNorm(frameSize, sampleFreq);
+-
+- /* The longer the frames, the more often should the FIXFIX-
+- case transmit 2 envelopes instead of 1.
+- Frame durations below 10 ms produce the highest threshold
+- so that practically always only 1 env is transmitted. */
+- FIXP_DBL tmp = framedur_fix - FL2FXCONST_DBL(0.010);
+-
+- tmp = fixMax(tmp, FL2FXCONST_DBL(0.0001));
+- tmp = fDivNorm(FL2FXCONST_DBL(0.000075), fPow2(tmp), &tmp_e);
+-
+- bitrateFactor_e = (tmp_e + bitrateFactor_e);
+-
+- if (sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
+- bitrateFactor_e--; /* divide by 2 */
+- }
+-
+- FDK_ASSERT(no_cols <= 32);
+- FDK_ASSERT(no_rows <= 64);
+-
+- h_sbrTransientDetector->no_cols = no_cols;
+- h_sbrTransientDetector->tran_thr =
+- (FIXP_DBL)((params->tran_thr << (32 - 24 - 1)) / no_rows);
+- h_sbrTransientDetector->tran_fc = tran_fc;
+- h_sbrTransientDetector->split_thr_m = fMult(tmp, bitrateFactor_m);
+- h_sbrTransientDetector->split_thr_e = bitrateFactor_e;
+- h_sbrTransientDetector->no_rows = no_rows;
+- h_sbrTransientDetector->mode = params->tran_det_mode;
+- h_sbrTransientDetector->prevLowBandEnergy = FL2FXCONST_DBL(0.0f);
+-
+- return (0);
+-}
+-
+-#define ENERGY_SCALING_SIZE 32
+-
+-INT FDKsbrEnc_InitSbrFastTransientDetector(
+- HANDLE_FAST_TRAN_DET h_sbrFastTransientDetector,
+- const INT time_slots_per_frame, const INT bandwidth_qmf_slot,
+- const INT no_qmf_channels, const INT sbr_qmf_1st_band) {
+- int i;
+- int buff_size;
+- FIXP_DBL myExp;
+- FIXP_DBL myExpSlot;
+-
+- h_sbrFastTransientDetector->lookahead = TRAN_DET_LOOKAHEAD;
+- h_sbrFastTransientDetector->nTimeSlots = time_slots_per_frame;
+-
+- buff_size = h_sbrFastTransientDetector->nTimeSlots +
+- h_sbrFastTransientDetector->lookahead;
+-
+- for (i = 0; i < buff_size; i++) {
+- h_sbrFastTransientDetector->delta_energy[i] = FL2FXCONST_DBL(0.0f);
+- h_sbrFastTransientDetector->energy_timeSlots[i] = FL2FXCONST_DBL(0.0f);
+- h_sbrFastTransientDetector->lowpass_energy[i] = FL2FXCONST_DBL(0.0f);
+- h_sbrFastTransientDetector->transientCandidates[i] = 0;
+- }
+-
+- FDK_ASSERT(bandwidth_qmf_slot > 0.f);
+- h_sbrFastTransientDetector->stopBand =
+- fMin(TRAN_DET_STOP_FREQ / bandwidth_qmf_slot, no_qmf_channels);
+- h_sbrFastTransientDetector->startBand =
+- fMin(sbr_qmf_1st_band,
+- h_sbrFastTransientDetector->stopBand - TRAN_DET_MIN_QMFBANDS);
+-
+- FDK_ASSERT(h_sbrFastTransientDetector->startBand < no_qmf_channels);
+- FDK_ASSERT(h_sbrFastTransientDetector->startBand <
+- h_sbrFastTransientDetector->stopBand);
+- FDK_ASSERT(h_sbrFastTransientDetector->startBand > 1);
+- FDK_ASSERT(h_sbrFastTransientDetector->stopBand > 1);
+-
+- /* the energy weighting and adding up has a headroom of 6 Bits,
+- so up to 64 bands can be added without potential overflow. */
+- FDK_ASSERT(h_sbrFastTransientDetector->stopBand -
+- h_sbrFastTransientDetector->startBand <=
+- 64);
+-
+-/* QMF_HP_dB_SLOPE_FIX says that we want a 20 dB per 16 kHz HP filter.
+- The following lines map this to the QMF bandwidth. */
+-#define EXP_E 7 /* 64 (=64) multiplications max, max. allowed sum is 0.5 */
+- myExp = fMultNorm(QMF_HP_dBd_SLOPE_FIX, 0, (FIXP_DBL)bandwidth_qmf_slot,
+- DFRACT_BITS - 1, EXP_E);
+- myExpSlot = myExp;
+-
+- for (i = 0; i < 64; i++) {
+- /* Calculate dBf over all qmf bands:
+- dBf = (10^(0.002266f/10*bw(slot)))^(band) =
+- = 2^(log2(10)*0.002266f/10*bw(slot)*band) =
+- = 2^(0.00075275f*bw(slot)*band) */
+-
+- FIXP_DBL dBf_m; /* dBf mantissa */
+- INT dBf_e; /* dBf exponent */
+- INT tmp;
+-
+- INT dBf_int; /* dBf integer part */
+- FIXP_DBL dBf_fract; /* dBf fractional part */
+-
+- /* myExp*(i+1) = myExp_int - myExp_fract
+- myExp*(i+1) is split up here for better accuracy of CalcInvLdData(),
+- for its result can be split up into an integer and a fractional part */
+-
+- /* Round up to next integer */
+- FIXP_DBL myExp_int =
+- (myExpSlot & (FIXP_DBL)0xfe000000) + (FIXP_DBL)0x02000000;
+-
+- /* This is the fractional part that needs to be substracted */
+- FIXP_DBL myExp_fract = myExp_int - myExpSlot;
+-
+- /* Calc integer part */
+- dBf_int = CalcInvLdData(myExp_int);
+- /* The result needs to be re-scaled. The ld(myExp_int) had been scaled by
+- EXP_E, the CalcInvLdData expects the operand to be scaled by
+- LD_DATA_SHIFT. Therefore, the correctly scaled result is
+- dBf_int^(2^(EXP_E-LD_DATA_SHIFT)), which is dBf_int^2 */
+-
+- if (dBf_int <=
+- 46340) { /* compare with maximum allowed value for signed integer
+- multiplication, 46340 =
+- (INT)floor(sqrt((double)(((UINT)1<<(DFRACT_BITS-1))-1))) */
+- dBf_int *= dBf_int;
+-
+- /* Calc fractional part */
+- dBf_fract = CalcInvLdData(-myExp_fract);
+- /* The result needs to be re-scaled. The ld(myExp_fract) had been scaled
+- by EXP_E, the CalcInvLdData expects the operand to be scaled by
+- LD_DATA_SHIFT. Therefore, the correctly scaled result is
+- dBf_fract^(2^(EXP_E-LD_DATA_SHIFT)), which is dBf_fract^2 */
+- dBf_fract = fMultNorm(dBf_fract, dBf_fract, &tmp);
+-
+- /* Get worst case scaling of multiplication result */
+- dBf_e = (DFRACT_BITS - 1 - tmp) - CountLeadingBits(dBf_int);
+-
+- /* Now multiply integer with fractional part of the result, thus resulting
+- in the overall accurate fractional result */
+- dBf_m = fMultNorm(dBf_int, DFRACT_BITS - 1, dBf_fract, tmp, dBf_e);
+-
+- myExpSlot += myExp;
+- } else {
+- dBf_m = (FIXP_DBL)0;
+- dBf_e = 0;
+- }
+-
+- /* Keep the results */
+- h_sbrFastTransientDetector->dBf_m[i] = dBf_m;
+- h_sbrFastTransientDetector->dBf_e[i] = dBf_e;
+- }
+-
+- /* Make sure that dBf is greater than 1.0 (because it should be a highpass) */
+- /* ... */
+-
+- return 0;
+-}
+-
+-void FDKsbrEnc_fastTransientDetect(
+- const HANDLE_FAST_TRAN_DET h_sbrFastTransientDetector,
+- const FIXP_DBL *const *Energies, const int *const scaleEnergies,
+- const INT YBufferWriteOffset, UCHAR *const tran_vector) {
+- int timeSlot, band;
+-
+- FIXP_DBL max_delta_energy; /* helper to store maximum energy ratio */
+- int max_delta_energy_scale; /* helper to store scale of maximum energy ratio
+- */
+- int ind_max = 0; /* helper to store index of maximum energy ratio */
+- int isTransientInFrame = 0;
+-
+- const int nTimeSlots = h_sbrFastTransientDetector->nTimeSlots;
+- const int lookahead = h_sbrFastTransientDetector->lookahead;
+- const int startBand = h_sbrFastTransientDetector->startBand;
+- const int stopBand = h_sbrFastTransientDetector->stopBand;
+-
+- int *transientCandidates = h_sbrFastTransientDetector->transientCandidates;
+-
+- FIXP_DBL *energy_timeSlots = h_sbrFastTransientDetector->energy_timeSlots;
+- int *energy_timeSlots_scale =
+- h_sbrFastTransientDetector->energy_timeSlots_scale;
+-
+- FIXP_DBL *delta_energy = h_sbrFastTransientDetector->delta_energy;
+- int *delta_energy_scale = h_sbrFastTransientDetector->delta_energy_scale;
+-
+- const FIXP_DBL thr = TRAN_DET_THRSHLD;
+- const INT thr_scale = TRAN_DET_THRSHLD_SCALE;
+-
+- /*reset transient info*/
+- tran_vector[2] = 0;
+-
+- /* reset transient candidates */
+- FDKmemclear(transientCandidates + lookahead, nTimeSlots * sizeof(int));
+-
+- for (timeSlot = lookahead; timeSlot < nTimeSlots + lookahead; timeSlot++) {
+- int i, norm;
+- FIXP_DBL tmpE = FL2FXCONST_DBL(0.0f);
+- int headroomEnSlot = DFRACT_BITS - 1;
+-
+- FIXP_DBL smallNRG = FL2FXCONST_DBL(1e-2f);
+- FIXP_DBL denominator;
+- INT denominator_scale;
+-
+- /* determine minimum headroom of energy values for this timeslot */
+- for (band = startBand; band < stopBand; band++) {
+- int tmp_headroom = fNormz(Energies[timeSlot][band]) - 1;
+- if (tmp_headroom < headroomEnSlot) {
+- headroomEnSlot = tmp_headroom;
+- }
+- }
+-
+- for (i = 0, band = startBand; band < stopBand; band++, i++) {
+- /* energy is weighted by weightingfactor stored in dBf_m array */
+- /* dBf_m index runs from 0 to stopBand-startband */
+- /* energy shifted by calculated headroom for maximum precision */
+- FIXP_DBL weightedEnergy =
+- fMult(Energies[timeSlot][band] << headroomEnSlot,
+- h_sbrFastTransientDetector->dBf_m[i]);
+-
+- /* energy is added up */
+- /* shift by 6 to have a headroom for maximum 64 additions */
+- /* shift by dBf_e to handle weighting factor dependent scale factors */
+- tmpE +=
+- weightedEnergy >> (6 + (10 - h_sbrFastTransientDetector->dBf_e[i]));
+- }
+-
+- /* store calculated energy for timeslot */
+- energy_timeSlots[timeSlot] = tmpE;
+-
+- /* calculate overall scale factor for energy of this timeslot */
+- /* = original scale factor of energies
+- * (-scaleEnergies[0]+2*QMF_SCALE_OFFSET or
+- * -scaleEnergies[1]+2*QMF_SCALE_OFFSET */
+- /* depending on YBufferWriteOffset) */
+- /* + weighting factor scale (10) */
+- /* + adding up scale factor ( 6) */
+- /* - headroom of energy value (headroomEnSlot) */
+- if (timeSlot < YBufferWriteOffset) {
+- energy_timeSlots_scale[timeSlot] =
+- (-scaleEnergies[0] + 2 * QMF_SCALE_OFFSET) + (10 + 6) -
+- headroomEnSlot;
+- } else {
+- energy_timeSlots_scale[timeSlot] =
+- (-scaleEnergies[1] + 2 * QMF_SCALE_OFFSET) + (10 + 6) -
+- headroomEnSlot;
+- }
+-
+- /* Add a small energy to the denominator, thus making the transient
+- detection energy-dependent. Loud transients are being detected,
+- silent ones not. */
+-
+- /* make sure that smallNRG does not overflow */
+- if (-energy_timeSlots_scale[timeSlot - 1] + 1 > 5) {
+- denominator = smallNRG;
+- denominator_scale = 0;
+- } else {
+- /* Leave an additional headroom of 1 bit for this addition. */
+- smallNRG =
+- scaleValue(smallNRG, -(energy_timeSlots_scale[timeSlot - 1] + 1));
+- denominator = (energy_timeSlots[timeSlot - 1] >> 1) + smallNRG;
+- denominator_scale = energy_timeSlots_scale[timeSlot - 1] + 1;
+- }
+-
+- delta_energy[timeSlot] =
+- fDivNorm(energy_timeSlots[timeSlot], denominator, &norm);
+- delta_energy_scale[timeSlot] =
+- energy_timeSlots_scale[timeSlot] - denominator_scale + norm;
+- }
+-
+- /*get transient candidates*/
+- /* For every timeslot, check if delta(E) exceeds the threshold. If it did,
+- it could potentially be marked as a transient candidate. However, the 2
+- slots before the current one must not be transients with an energy higher
+- than 1.4*E(current). If both aren't transients or if the energy of the
+- current timesolot is more than 1.4 times higher than the energy in the
+- last or the one before the last slot, it is marked as a transient.*/
+-
+- FDK_ASSERT(lookahead >= 2);
+- for (timeSlot = lookahead; timeSlot < nTimeSlots + lookahead; timeSlot++) {
+- FIXP_DBL energy_cur_slot_weighted =
+- fMult(energy_timeSlots[timeSlot], FL2FXCONST_DBL(1.0f / 1.4f));
+- if (!fIsLessThan(delta_energy[timeSlot], delta_energy_scale[timeSlot], thr,
+- thr_scale) &&
+- (((transientCandidates[timeSlot - 2] == 0) &&
+- (transientCandidates[timeSlot - 1] == 0)) ||
+- !fIsLessThan(energy_cur_slot_weighted,
+- energy_timeSlots_scale[timeSlot],
+- energy_timeSlots[timeSlot - 1],
+- energy_timeSlots_scale[timeSlot - 1]) ||
+- !fIsLessThan(energy_cur_slot_weighted,
+- energy_timeSlots_scale[timeSlot],
+- energy_timeSlots[timeSlot - 2],
+- energy_timeSlots_scale[timeSlot - 2]))) {
+- /* in case of strong transients, subsequent
+- * qmf slots might be recognized as transients. */
+- transientCandidates[timeSlot] = 1;
+- }
+- }
+-
+- /*get transient with max energy*/
+- max_delta_energy = FL2FXCONST_DBL(0.0f);
+- max_delta_energy_scale = 0;
+- ind_max = 0;
+- isTransientInFrame = 0;
+- for (timeSlot = 0; timeSlot < nTimeSlots; timeSlot++) {
+- int scale = fMax(delta_energy_scale[timeSlot], max_delta_energy_scale);
+- if (transientCandidates[timeSlot] &&
+- ((delta_energy[timeSlot] >> (scale - delta_energy_scale[timeSlot])) >
+- (max_delta_energy >> (scale - max_delta_energy_scale)))) {
+- max_delta_energy = delta_energy[timeSlot];
+- max_delta_energy_scale = scale;
+- ind_max = timeSlot;
+- isTransientInFrame = 1;
+- }
+- }
+-
+- /*from all transient candidates take the one with the biggest energy*/
+- if (isTransientInFrame) {
+- tran_vector[0] = ind_max;
+- tran_vector[1] = 1;
+- } else {
+- /*reset transient info*/
+- tran_vector[0] = tran_vector[1] = 0;
+- }
+-
+- /*check for transients in lookahead*/
+- for (timeSlot = nTimeSlots; timeSlot < nTimeSlots + lookahead; timeSlot++) {
+- if (transientCandidates[timeSlot]) {
+- tran_vector[2] = 1;
+- }
+- }
+-
+- /*update buffers*/
+- for (timeSlot = 0; timeSlot < lookahead; timeSlot++) {
+- transientCandidates[timeSlot] = transientCandidates[nTimeSlots + timeSlot];
+-
+- /* fixpoint stuff */
+- energy_timeSlots[timeSlot] = energy_timeSlots[nTimeSlots + timeSlot];
+- energy_timeSlots_scale[timeSlot] =
+- energy_timeSlots_scale[nTimeSlots + timeSlot];
+-
+- delta_energy[timeSlot] = delta_energy[nTimeSlots + timeSlot];
+- delta_energy_scale[timeSlot] = delta_energy_scale[nTimeSlots + timeSlot];
+- }
+-}
+diff --git a/libSBRenc/src/tran_det.h b/libSBRenc/src/tran_det.h
+deleted file mode 100644
+index d10a7db..0000000
+--- a/libSBRenc/src/tran_det.h
++++ /dev/null
+@@ -1,191 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** SBR encoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Transient detector prototypes $Revision: 95111 $
+-*/
+-#ifndef TRAN_DET_H
+-#define TRAN_DET_H
+-
+-#include "sbr_encoder.h"
+-#include "sbr_def.h"
+-
+-typedef struct {
+- FIXP_DBL transients[32 + (32 / 2)];
+- FIXP_DBL thresholds[64];
+- FIXP_DBL tran_thr; /* Master threshold for transient signals */
+- FIXP_DBL split_thr_m; /* Threshold for splitting FIXFIX-frames into 2 env */
+- INT split_thr_e; /* Scale for splitting threshold */
+- FIXP_DBL prevLowBandEnergy; /* Energy of low band */
+- FIXP_DBL prevHighBandEnergy; /* Energy of high band */
+- INT tran_fc; /* Number of lowband subbands to discard */
+- INT no_cols;
+- INT no_rows;
+- INT mode;
+-
+- int frameShift;
+- int tran_off; /* Offset for reading energy values. */
+-} SBR_TRANSIENT_DETECTOR;
+-
+-typedef SBR_TRANSIENT_DETECTOR *HANDLE_SBR_TRANSIENT_DETECTOR;
+-
+-#define TRAN_DET_LOOKAHEAD 2
+-#define TRAN_DET_START_FREQ 4500 /*start frequency for transient detection*/
+-#define TRAN_DET_STOP_FREQ 13500 /*stop frequency for transient detection*/
+-#define TRAN_DET_MIN_QMFBANDS \
+- 4 /* minimum qmf bands for transient detection \
+- */
+-#define QMF_HP_dBd_SLOPE_FIX \
+- FL2FXCONST_DBL(0.00075275f) /* 0.002266f/10 * log2(10) */
+-#define TRAN_DET_THRSHLD FL2FXCONST_DBL(5.0f / 8.0f)
+-#define TRAN_DET_THRSHLD_SCALE (3)
+-
+-typedef struct {
+- INT transientCandidates[32 + TRAN_DET_LOOKAHEAD];
+- INT nTimeSlots;
+- INT lookahead;
+- INT startBand;
+- INT stopBand;
+-
+- FIXP_DBL dBf_m[64];
+- INT dBf_e[64];
+-
+- FIXP_DBL energy_timeSlots[32 + TRAN_DET_LOOKAHEAD];
+- INT energy_timeSlots_scale[32 + TRAN_DET_LOOKAHEAD];
+-
+- FIXP_DBL delta_energy[32 + TRAN_DET_LOOKAHEAD];
+- INT delta_energy_scale[32 + TRAN_DET_LOOKAHEAD];
+-
+- FIXP_DBL lowpass_energy[32 + TRAN_DET_LOOKAHEAD];
+- INT lowpass_energy_scale[32 + TRAN_DET_LOOKAHEAD];
+-} FAST_TRAN_DETECTOR;
+-typedef FAST_TRAN_DETECTOR *HANDLE_FAST_TRAN_DET;
+-
+-INT FDKsbrEnc_InitSbrFastTransientDetector(
+- HANDLE_FAST_TRAN_DET h_sbrFastTransientDetector,
+- const INT time_slots_per_frame, const INT bandwidth_qmf_slot,
+- const INT no_qmf_channels, const INT sbr_qmf_1st_band);
+-
+-void FDKsbrEnc_fastTransientDetect(
+- const HANDLE_FAST_TRAN_DET h_sbrFastTransientDetector,
+- const FIXP_DBL *const *Energies, const int *const scaleEnergies,
+- const INT YBufferWriteOffset, UCHAR *const tran_vector);
+-
+-void FDKsbrEnc_transientDetect(
+- HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector, FIXP_DBL **Energies,
+- INT *scaleEnergies, UCHAR *tran_vector, int YBufferWriteOffset,
+- int YBufferSzShift, int timeStep, int frameMiddleBorder);
+-
+-int FDKsbrEnc_InitSbrTransientDetector(
+- HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector,
+- UINT sbrSyntaxFlags, /* SBR syntax flags derived from AOT. */
+- INT frameSize, INT sampleFreq, sbrConfigurationPtr params, int tran_fc,
+- int no_cols, int no_rows, int YBufferWriteOffset, int YBufferSzShift,
+- int frameShift, int tran_off);
+-
+-void FDKsbrEnc_frameSplitter(
+- FIXP_DBL **Energies, INT *scaleEnergies,
+- HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector, UCHAR *freqBandTable,
+- UCHAR *tran_vector, int YBufferWriteOffset, int YBufferSzShift, int nSfb,
+- int timeStep, int no_cols, FIXP_DBL *tonality);
+-#endif
+--
+cgit v1.1
+
--- /dev/null
+From 022f1b86ef2f992c1c5623719e403b9b28e1becc Mon Sep 17 00:00:00 2001
+From: Wim Taymans <wtaymans@redhat.com>
+Date: Mon, 24 Jun 2019 16:26:20 +0200
+Subject: Remove HCR, RVLC, error concealment
+
+---
+ Makefile.am | 7 -
+ Makefile.vc | 7 -
+ libAACdec/src/aac_ram.h | 3 -
+ libAACdec/src/aac_rom.cpp | 96 --
+ libAACdec/src/aac_rom.h | 4 +-
+ libAACdec/src/aacdec_hcr.cpp | 1498 ---------------------------
+ libAACdec/src/aacdec_hcr.h | 128 ---
+ libAACdec/src/aacdec_hcr_bit.cpp | 164 ---
+ libAACdec/src/aacdec_hcr_bit.h | 114 ---
+ libAACdec/src/aacdec_hcr_types.h | 432 --------
+ libAACdec/src/aacdec_hcrs.cpp | 1551 ----------------------------
+ libAACdec/src/aacdec_hcrs.h | 176 ----
+ libAACdec/src/aacdecoder.cpp | 91 +-
+ libAACdec/src/aacdecoder.h | 3 -
+ libAACdec/src/aacdecoder_lib.cpp | 73 +-
+ libAACdec/src/block.cpp | 59 +-
+ libAACdec/src/channel.cpp | 19 +-
+ libAACdec/src/channelinfo.h | 22 -
+ libAACdec/src/conceal.cpp | 2095 --------------------------------------
+ libAACdec/src/conceal.h | 152 ---
+ libAACdec/src/conceal_types.h | 203 ----
+ libAACdec/src/rvlc.cpp | 1217 ----------------------
+ libAACdec/src/rvlc.h | 153 ---
+ libAACdec/src/rvlc_info.h | 204 ----
+ libAACdec/src/rvlcbit.cpp | 148 ---
+ libAACdec/src/rvlcbit.h | 111 --
+ libAACdec/src/rvlcconceal.cpp | 787 --------------
+ libAACdec/src/rvlcconceal.h | 127 ---
+ libAACdec/src/usacdec_lpd.cpp | 20 +-
+ 29 files changed, 21 insertions(+), 9643 deletions(-)
+ delete mode 100644 libAACdec/src/aacdec_hcr.cpp
+ delete mode 100644 libAACdec/src/aacdec_hcr.h
+ delete mode 100644 libAACdec/src/aacdec_hcr_bit.cpp
+ delete mode 100644 libAACdec/src/aacdec_hcr_bit.h
+ delete mode 100644 libAACdec/src/aacdec_hcr_types.h
+ delete mode 100644 libAACdec/src/aacdec_hcrs.cpp
+ delete mode 100644 libAACdec/src/aacdec_hcrs.h
+ delete mode 100644 libAACdec/src/conceal.cpp
+ delete mode 100644 libAACdec/src/conceal.h
+ delete mode 100644 libAACdec/src/conceal_types.h
+ delete mode 100644 libAACdec/src/rvlc.cpp
+ delete mode 100644 libAACdec/src/rvlc.h
+ delete mode 100644 libAACdec/src/rvlc_info.h
+ delete mode 100644 libAACdec/src/rvlcbit.cpp
+ delete mode 100644 libAACdec/src/rvlcbit.h
+ delete mode 100644 libAACdec/src/rvlcconceal.cpp
+ delete mode 100644 libAACdec/src/rvlcconceal.h
+
+diff --git a/Makefile.am b/Makefile.am
+index 79e0677..16b21e1 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -50,9 +50,6 @@ AACDEC_SRC = \
+ libAACdec/src/aac_ram.cpp \
+ libAACdec/src/aac_rom.cpp \
+ libAACdec/src/aacdec_drc.cpp \
+- libAACdec/src/aacdec_hcr.cpp \
+- libAACdec/src/aacdec_hcr_bit.cpp \
+- libAACdec/src/aacdec_hcrs.cpp \
+ libAACdec/src/aacdec_pns.cpp \
+ libAACdec/src/aacdec_tns.cpp \
+ libAACdec/src/aacdecoder.cpp \
+@@ -60,12 +57,8 @@ AACDEC_SRC = \
+ libAACdec/src/block.cpp \
+ libAACdec/src/channel.cpp \
+ libAACdec/src/channelinfo.cpp \
+- libAACdec/src/conceal.cpp \
+ libAACdec/src/ldfiltbank.cpp \
+ libAACdec/src/pulsedata.cpp \
+- libAACdec/src/rvlc.cpp \
+- libAACdec/src/rvlcbit.cpp \
+- libAACdec/src/rvlcconceal.cpp \
+ libAACdec/src/stereo.cpp \
+ libAACdec/src/usacdec_ace_d4t64.cpp \
+ libAACdec/src/usacdec_ace_ltp.cpp \
+diff --git a/Makefile.vc b/Makefile.vc
+index ac3c097..97a0615 100644
+--- a/Makefile.vc
++++ b/Makefile.vc
+@@ -34,9 +34,6 @@ AACDEC_SRC = \
+ libAACdec/src/aac_ram.cpp \
+ libAACdec/src/aac_rom.cpp \
+ libAACdec/src/aacdec_drc.cpp \
+- libAACdec/src/aacdec_hcr.cpp \
+- libAACdec/src/aacdec_hcr_bit.cpp \
+- libAACdec/src/aacdec_hcrs.cpp \
+ libAACdec/src/aacdec_pns.cpp \
+ libAACdec/src/aacdec_tns.cpp \
+ libAACdec/src/aacdecoder.cpp \
+@@ -44,12 +41,8 @@ AACDEC_SRC = \
+ libAACdec/src/block.cpp \
+ libAACdec/src/channel.cpp \
+ libAACdec/src/channelinfo.cpp \
+- libAACdec/src/conceal.cpp \
+ libAACdec/src/ldfiltbank.cpp \
+ libAACdec/src/pulsedata.cpp \
+- libAACdec/src/rvlc.cpp \
+- libAACdec/src/rvlcbit.cpp \
+- libAACdec/src/rvlcconceal.cpp \
+ libAACdec/src/stereo.cpp \
+ libAACdec/src/usacdec_ace_d4t64.cpp \
+ libAACdec/src/usacdec_ace_ltp.cpp \
+diff --git a/libAACdec/src/aac_ram.h b/libAACdec/src/aac_ram.h
+index a861e25..7ee8d26 100644
+--- a/libAACdec/src/aac_ram.h
++++ b/libAACdec/src/aac_ram.h
+@@ -111,9 +111,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "ac_arith_coder.h"
+
+-#include "aacdec_hcr_types.h"
+-#include "aacdec_hcr.h"
+-
+ /* End of formal fix.h */
+
+ #define MAX_SYNCHS 10
+diff --git a/libAACdec/src/aac_rom.cpp b/libAACdec/src/aac_rom.cpp
+index cbdffc4..2c3c1b1 100644
+--- a/libAACdec/src/aac_rom.cpp
++++ b/libAACdec/src/aac_rom.cpp
+@@ -1583,102 +1583,6 @@ const SCHAR *aQuantTable[] = {
+ aValTab24, /* 30 6 */
+ aValTab24}; /* 31 6 */
+
+-/* arrays for HCR_TABLE_INFO structures */
+-/* maximum length of codeword in each codebook */
+-/* codebook: 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 */
+-const UCHAR aMaxCwLen[MAX_CB] = {0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14,
+- 49, 0, 0, 0, 0, 14, 17, 21, 21, 25, 25,
+- 29, 29, 29, 29, 33, 33, 33, 37, 37, 41};
+-
+-/* 11 13 15 17 19
+- * 21 23 25 27 39 31 */
+-/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20
+- * 22 24 26 28 30 */
+-const UCHAR aDimCb[MAX_CB] = {
+- 2, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2,
+- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; /* codebook dimension -
+- zero cb got a
+- dimension of 2 */
+-
+-/* 11 13 15 17 19
+- * 21 23 25 27 39 31 */
+-/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20
+- * 22 24 26 28 30 */
+-const UCHAR aDimCbShift[MAX_CB] = {
+- 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
+- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; /* codebook dimension */
+-
+-/* 1 -> decode sign bits */
+-/* 0 -> decode no sign bits 11 13 15 17 19 21
+- * 23 25 27 39 31 */
+-/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 22
+- * 24 26 28 30 */
+-const UCHAR aSignCb[MAX_CB] = {0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
+- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
+-
+-/* arrays for HCR_CB_PAIRS structures */
+-const UCHAR aMinOfCbPair[MAX_CB_PAIRS] = {0, 1, 3, 5, 7, 9, 16, 17,
+- 18, 19, 20, 21, 22, 23, 24, 25,
+- 26, 27, 28, 29, 30, 31, 11};
+-const UCHAR aMaxOfCbPair[MAX_CB_PAIRS] = {0, 2, 4, 6, 8, 10, 16, 17,
+- 18, 19, 20, 21, 22, 23, 24, 25,
+- 26, 27, 28, 29, 30, 31, 11};
+-
+-/* priorities of codebooks */
+-const UCHAR aCbPriority[MAX_CB] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
+- 22, 0, 0, 0, 0, 6, 7, 8, 9, 10, 11,
+- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
+-
+-const SCHAR aCodebook2StartInt[] = {STOP_THIS_STATE, /* cb 0 */
+- BODY_ONLY, /* cb 1 */
+- BODY_ONLY, /* cb 2 */
+- BODY_SIGN__BODY, /* cb 3 */
+- BODY_SIGN__BODY, /* cb 4 */
+- BODY_ONLY, /* cb 5 */
+- BODY_ONLY, /* cb 6 */
+- BODY_SIGN__BODY, /* cb 7 */
+- BODY_SIGN__BODY, /* cb 8 */
+- BODY_SIGN__BODY, /* cb 9 */
+- BODY_SIGN__BODY, /* cb 10 */
+- BODY_SIGN_ESC__BODY, /* cb 11 */
+- STOP_THIS_STATE, /* cb 12 */
+- STOP_THIS_STATE, /* cb 13 */
+- STOP_THIS_STATE, /* cb 14 */
+- STOP_THIS_STATE, /* cb 15 */
+- BODY_SIGN_ESC__BODY, /* cb 16 */
+- BODY_SIGN_ESC__BODY, /* cb 17 */
+- BODY_SIGN_ESC__BODY, /* cb 18 */
+- BODY_SIGN_ESC__BODY, /* cb 19 */
+- BODY_SIGN_ESC__BODY, /* cb 20 */
+- BODY_SIGN_ESC__BODY, /* cb 21 */
+- BODY_SIGN_ESC__BODY, /* cb 22 */
+- BODY_SIGN_ESC__BODY, /* cb 23 */
+- BODY_SIGN_ESC__BODY, /* cb 24 */
+- BODY_SIGN_ESC__BODY, /* cb 25 */
+- BODY_SIGN_ESC__BODY, /* cb 26 */
+- BODY_SIGN_ESC__BODY, /* cb 27 */
+- BODY_SIGN_ESC__BODY, /* cb 28 */
+- BODY_SIGN_ESC__BODY, /* cb 29 */
+- BODY_SIGN_ESC__BODY, /* cb 30 */
+- BODY_SIGN_ESC__BODY}; /* cb 31 */
+-
+-const STATEFUNC aStateConstant2State[] = {
+- NULL, /* 0 = STOP_THIS_STATE */
+- Hcr_State_BODY_ONLY, /* 1 = BODY_ONLY */
+- Hcr_State_BODY_SIGN__BODY, /* 2 = BODY_SIGN__BODY */
+- Hcr_State_BODY_SIGN__SIGN, /* 3 = BODY_SIGN__SIGN */
+- Hcr_State_BODY_SIGN_ESC__BODY, /* 4 = BODY_SIGN_ESC__BODY */
+- Hcr_State_BODY_SIGN_ESC__SIGN, /* 5 = BODY_SIGN_ESC__SIGN */
+- Hcr_State_BODY_SIGN_ESC__ESC_PREFIX, /* 6 = BODY_SIGN_ESC__ESC_PREFIX */
+- Hcr_State_BODY_SIGN_ESC__ESC_WORD}; /* 7 = BODY_SIGN_ESC__ESC_WORD */
+-
+-/* CB: 0 1 2 3 4 5 6 7 8 9 10 12
+- * 14 16 18 20 22 24 26 28 30 */
+-const USHORT aLargestAbsoluteValue[MAX_CB] = {
+- 0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12,
+- 8191, 0, 0, 0, 0, 15, 31, 47, 63, 95, 127,
+- 159, 191, 223, 255, 319, 383, 511, 767, 1023, 2047}; /* lav */
+ /* CB: 11 13
+ * 15 17 19 21 23 25 27 39 31 */
+
+diff --git a/libAACdec/src/aac_rom.h b/libAACdec/src/aac_rom.h
+index ffaf951..503e459 100644
+--- a/libAACdec/src/aac_rom.h
++++ b/libAACdec/src/aac_rom.h
+@@ -105,8 +105,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "common_fix.h"
+ #include "FDK_audio.h"
+-#include "aacdec_hcr_types.h"
+-#include "aacdec_hcrs.h"
+
+ #define PCM_DEC FIXP_DBL
+ #define MAXVAL_PCM_DEC MAXVAL_DBL
+@@ -165,7 +163,7 @@ typedef struct {
+ extern const CodeBookDescription AACcodeBookDescriptionTable[13];
+ extern const CodeBookDescription AACcodeBookDescriptionSCL;
+
+-extern const STATEFUNC aStateConstant2State[];
++#define MAX_CB 32 /* last used CB is cb #31 when VCB11 is used */
+
+ extern const SCHAR aCodebook2StartInt[];
+
+diff --git a/libAACdec/src/aacdec_hcr.cpp b/libAACdec/src/aacdec_hcr.cpp
+deleted file mode 100644
+index 6114756..0000000
+--- a/libAACdec/src/aacdec_hcr.cpp
++++ /dev/null
+@@ -1,1498 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Robert Weidner (DSP Solutions)
+-
+- Description: HCR Decoder: HCR initialization, preprocess HCR sideinfo,
+- decode priority codewords (PCWs)
+-
+-*******************************************************************************/
+-
+-#include "aacdec_hcr.h"
+-
+-#include "aacdec_hcr_types.h"
+-#include "aacdec_hcr_bit.h"
+-#include "aacdec_hcrs.h"
+-#include "aac_ram.h"
+-#include "aac_rom.h"
+-#include "channel.h"
+-#include "block.h"
+-
+-#include "aacdecoder.h" /* for ID_CPE, ID_SCE ... */
+-#include "FDK_bitstream.h"
+-
+-extern int mlFileChCurr;
+-
+-static void errDetectorInHcrSideinfoShrt(SCHAR cb, SHORT numLine,
+- UINT *errorWord);
+-
+-static void errDetectorInHcrLengths(SCHAR lengthOfLongestCodeword,
+- SHORT lengthOfReorderedSpectralData,
+- UINT *errorWord);
+-
+-static void HcrCalcNumCodeword(H_HCR_INFO pHcr);
+-static void HcrSortCodebookAndNumCodewordInSection(H_HCR_INFO pHcr);
+-static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr);
+-static void HcrExtendedSectionInfo(H_HCR_INFO pHcr);
+-
+-static void DeriveNumberOfExtendedSortedSectionsInSets(
+- UINT numSegment, USHORT *pNumExtendedSortedCodewordInSection,
+- int numExtendedSortedCodewordInSectionIdx,
+- USHORT *pNumExtendedSortedSectionsInSets,
+- int numExtendedSortedSectionsInSetsIdx);
+-
+-static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- INT quantSpecCoef, INT *pLeftStartOfSegment,
+- SCHAR *pRemainingBitsInSegment,
+- int *pNumDecodedBits);
+-
+-static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- UINT codebookDim, const SCHAR *pQuantVal,
+- FIXP_DBL *pQuantSpecCoef, int *quantSpecCoefIdx,
+- INT *pLeftStartOfSegment,
+- SCHAR *pRemainingBitsInSegment, int *pNumDecodedBits);
+-
+-static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- const UINT *pCurrentTree,
+- const SCHAR *pQuantValBase,
+- INT *pLeftStartOfSegment,
+- SCHAR *pRemainingBitsInSegment,
+- int *pNumDecodedBits);
+-
+-static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr);
+-
+-static void HcrReorderQuantizedSpectralCoefficients(
+- H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo);
+-
+-static UCHAR errDetectPcwSegmentation(SCHAR remainingBitsInSegment,
+- H_HCR_INFO pHcr, PCW_TYPE kind,
+- FIXP_DBL *qsc_base_of_cw,
+- UCHAR dimension);
+-
+-static void errDetectWithinSegmentationFinal(H_HCR_INFO pHcr);
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Check if codebook and numSect are within allowed range
+-(short only)
+---------------------------------------------------------------------------------------------
+-*/
+-static void errDetectorInHcrSideinfoShrt(SCHAR cb, SHORT numLine,
+- UINT *errorWord) {
+- if (cb < ZERO_HCB || cb >= MAX_CB_CHECK || cb == BOOKSCL) {
+- *errorWord |= CB_OUT_OF_RANGE_SHORT_BLOCK;
+- }
+- if (numLine < 0 || numLine > 1024) {
+- *errorWord |= LINE_IN_SECT_OUT_OF_RANGE_SHORT_BLOCK;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Check both HCR lengths
+---------------------------------------------------------------------------------------------
+-*/
+-static void errDetectorInHcrLengths(SCHAR lengthOfLongestCodeword,
+- SHORT lengthOfReorderedSpectralData,
+- UINT *errorWord) {
+- if (lengthOfReorderedSpectralData < lengthOfLongestCodeword) {
+- *errorWord |= HCR_SI_LENGTHS_FAILURE;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Decode (and adapt if necessary) the two HCR sideinfo
+-components: 'reordered_spectral_data_length' and 'longest_codeword_length'
+---------------------------------------------------------------------------------------------
+-*/
+-
+-void CHcr_Read(HANDLE_FDK_BITSTREAM bs,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const MP4_ELEMENT_ID globalHcrType) {
+- SHORT lengOfReorderedSpectralData;
+- SCHAR lengOfLongestCodeword;
+-
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfReorderedSpectralData =
+- 0;
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword = 0;
+-
+- /* ------- SI-Value No 1 ------- */
+- lengOfReorderedSpectralData = FDKreadBits(bs, 14) + ERROR_LORSD;
+- if (globalHcrType == ID_CPE) {
+- if ((lengOfReorderedSpectralData >= 0) &&
+- (lengOfReorderedSpectralData <= CPE_TOP_LENGTH)) {
+- pAacDecoderChannelInfo->pDynData->specificTo.aac
+- .lenOfReorderedSpectralData =
+- lengOfReorderedSpectralData; /* the decoded value is within range */
+- } else {
+- if (lengOfReorderedSpectralData > CPE_TOP_LENGTH) {
+- pAacDecoderChannelInfo->pDynData->specificTo.aac
+- .lenOfReorderedSpectralData =
+- CPE_TOP_LENGTH; /* use valid maximum */
+- }
+- }
+- } else if (globalHcrType == ID_SCE || globalHcrType == ID_LFE ||
+- globalHcrType == ID_CCE) {
+- if ((lengOfReorderedSpectralData >= 0) &&
+- (lengOfReorderedSpectralData <= SCE_TOP_LENGTH)) {
+- pAacDecoderChannelInfo->pDynData->specificTo.aac
+- .lenOfReorderedSpectralData =
+- lengOfReorderedSpectralData; /* the decoded value is within range */
+- } else {
+- if (lengOfReorderedSpectralData > SCE_TOP_LENGTH) {
+- pAacDecoderChannelInfo->pDynData->specificTo.aac
+- .lenOfReorderedSpectralData =
+- SCE_TOP_LENGTH; /* use valid maximum */
+- }
+- }
+- }
+-
+- /* ------- SI-Value No 2 ------- */
+- lengOfLongestCodeword = FDKreadBits(bs, 6) + ERROR_LOLC;
+- if ((lengOfLongestCodeword >= 0) &&
+- (lengOfLongestCodeword <= LEN_OF_LONGEST_CW_TOP_LENGTH)) {
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword =
+- lengOfLongestCodeword; /* the decoded value is within range */
+- } else {
+- if (lengOfLongestCodeword > LEN_OF_LONGEST_CW_TOP_LENGTH) {
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword =
+- LEN_OF_LONGEST_CW_TOP_LENGTH; /* use valid maximum */
+- }
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Set up HCR - must be called before every call to
+-HcrDecoder(). For short block a sorting algorithm is applied to get the SI in
+-the order that HCR could assemble the qsc's as if it is a long block.
+------------------------------------------------------------------------------------------------
+- return: error log
+---------------------------------------------------------------------------------------------
+-*/
+-
+-UINT HcrInit(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo,
+- HANDLE_FDK_BITSTREAM bs) {
+- CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
+- SHORT *pNumLinesInSec;
+- UCHAR *pCodeBk;
+- SHORT numSection;
+- SCHAR cb;
+- int numLine;
+- int i;
+-
+- pHcr->decInOut.lengthOfReorderedSpectralData =
+- pAacDecoderChannelInfo->pDynData->specificTo.aac
+- .lenOfReorderedSpectralData;
+- pHcr->decInOut.lengthOfLongestCodeword =
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword;
+- pHcr->decInOut.pQuantizedSpectralCoefficientsBase =
+- pAacDecoderChannelInfo->pSpectralCoefficient;
+- pHcr->decInOut.quantizedSpectralCoefficientsIdx = 0;
+- pHcr->decInOut.pCodebook =
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.aCodeBooks4Hcr;
+- pHcr->decInOut.pNumLineInSect =
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.aNumLineInSec4Hcr;
+- pHcr->decInOut.numSection =
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection;
+- pHcr->decInOut.errorLog = 0;
+- pHcr->nonPcwSideinfo.pResultBase =
+- SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
+-
+- FDKsyncCache(bs);
+- pHcr->decInOut.bitstreamAnchor = (INT)FDKgetValidBits(bs);
+-
+- if (!IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) /* short block */
+- {
+- SHORT band;
+- SHORT maxBand;
+- SCHAR group;
+- SCHAR winGroupLen;
+- SCHAR window;
+- SCHAR numUnitInBand;
+- SCHAR cntUnitInBand;
+- SCHAR groupWin;
+- SCHAR cb_prev;
+-
+- UCHAR *pCodeBook;
+- const SHORT *BandOffsets;
+- SCHAR numOfGroups;
+-
+- pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook; /* in */
+- pNumLinesInSec = pHcr->decInOut.pNumLineInSect; /* out */
+- pCodeBk = pHcr->decInOut.pCodebook; /* out */
+- BandOffsets =
+- GetScaleFactorBandOffsets(pIcsInfo, pSamplingRateInfo); /* aux */
+- numOfGroups = GetWindowGroups(pIcsInfo);
+-
+- numLine = 0;
+- numSection = 0;
+- cb = pCodeBook[0];
+- cb_prev = pCodeBook[0];
+-
+- /* convert HCR-sideinfo into a unitwise manner: When the cb changes, a new
+- * section starts */
+-
+- *pCodeBk++ = cb_prev;
+-
+- maxBand = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
+- for (band = 0; band < maxBand;
+- band++) { /* from low to high sfbs i.e. from low to high frequencies */
+- numUnitInBand =
+- ((BandOffsets[band + 1] - BandOffsets[band]) >>
+- FOUR_LOG_DIV_TWO_LOG); /* get the number of units in current sfb */
+- for (cntUnitInBand = numUnitInBand; cntUnitInBand != 0;
+- cntUnitInBand--) { /* for every unit in the band */
+- for (window = 0, group = 0; group < numOfGroups; group++) {
+- winGroupLen = (SCHAR)GetWindowGroupLength(
+- &pAacDecoderChannelInfo->icsInfo, group);
+- for (groupWin = winGroupLen; groupWin != 0; groupWin--, window++) {
+- cb = pCodeBook[group * 16 + band];
+- if (cb != cb_prev) {
+- errDetectorInHcrSideinfoShrt(cb, numLine,
+- &pHcr->decInOut.errorLog);
+- if (pHcr->decInOut.errorLog != 0) {
+- return (pHcr->decInOut.errorLog);
+- }
+- *pCodeBk++ = cb;
+- *pNumLinesInSec++ = numLine;
+- numSection++;
+-
+- cb_prev = cb;
+- numLine = LINES_PER_UNIT;
+- } else {
+- numLine += LINES_PER_UNIT;
+- }
+- }
+- }
+- }
+- }
+-
+- numSection++;
+-
+- errDetectorInHcrSideinfoShrt(cb, numLine, &pHcr->decInOut.errorLog);
+- if (numSection <= 0 || numSection > 1024 / 2) {
+- pHcr->decInOut.errorLog |= NUM_SECT_OUT_OF_RANGE_SHORT_BLOCK;
+- }
+- errDetectorInHcrLengths(pHcr->decInOut.lengthOfLongestCodeword,
+- pHcr->decInOut.lengthOfReorderedSpectralData,
+- &pHcr->decInOut.errorLog);
+- if (pHcr->decInOut.errorLog != 0) {
+- return (pHcr->decInOut.errorLog);
+- }
+-
+- *pCodeBk = cb;
+- *pNumLinesInSec = numLine;
+- pHcr->decInOut.numSection = numSection;
+-
+- } else /* end short block prepare SI */
+- { /* long block */
+- errDetectorInHcrLengths(pHcr->decInOut.lengthOfLongestCodeword,
+- pHcr->decInOut.lengthOfReorderedSpectralData,
+- &pHcr->decInOut.errorLog);
+- numSection = pHcr->decInOut.numSection;
+- pNumLinesInSec = pHcr->decInOut.pNumLineInSect;
+- pCodeBk = pHcr->decInOut.pCodebook;
+- if (numSection <= 0 || numSection > 64) {
+- pHcr->decInOut.errorLog |= NUM_SECT_OUT_OF_RANGE_LONG_BLOCK;
+- numSection = 0;
+- }
+-
+- for (i = numSection; i != 0; i--) {
+- cb = *pCodeBk++;
+-
+- if (cb < ZERO_HCB || cb >= MAX_CB_CHECK || cb == BOOKSCL) {
+- pHcr->decInOut.errorLog |= CB_OUT_OF_RANGE_LONG_BLOCK;
+- }
+-
+- numLine = *pNumLinesInSec++;
+- /* FDK_ASSERT(numLine > 0); */
+-
+- if ((numLine <= 0) || (numLine > 1024)) {
+- pHcr->decInOut.errorLog |= LINE_IN_SECT_OUT_OF_RANGE_LONG_BLOCK;
+- }
+- }
+- if (pHcr->decInOut.errorLog != 0) {
+- return (pHcr->decInOut.errorLog);
+- }
+- }
+-
+- pCodeBk = pHcr->decInOut.pCodebook;
+- for (i = 0; i < numSection; i++) {
+- if ((*pCodeBk == NOISE_HCB) || (*pCodeBk == INTENSITY_HCB2) ||
+- (*pCodeBk == INTENSITY_HCB)) {
+- *pCodeBk = 0;
+- }
+- pCodeBk++;
+- }
+-
+- /* HCR-sideinfo-input is complete and seems to be valid */
+-
+- return (pHcr->decInOut.errorLog);
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function decodes the codewords of the spectral
+-coefficients from the bitstream according to the HCR algorithm and stores the
+-quantized spectral coefficients in correct order in the output buffer.
+---------------------------------------------------------------------------------------------
+-*/
+-
+-UINT HcrDecoder(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo,
+- HANDLE_FDK_BITSTREAM bs) {
+- int pTmp1, pTmp2, pTmp3, pTmp4;
+- int pTmp5;
+-
+- INT bitCntOffst;
+- INT saveBitCnt = (INT)FDKgetValidBits(bs); /* save bitstream position */
+-
+- HcrCalcNumCodeword(pHcr);
+-
+- HcrSortCodebookAndNumCodewordInSection(pHcr);
+-
+- HcrPrepareSegmentationGrid(pHcr);
+-
+- HcrExtendedSectionInfo(pHcr);
+-
+- if ((pHcr->decInOut.errorLog & HCR_FATAL_PCW_ERROR_MASK) != 0) {
+- return (pHcr->decInOut.errorLog); /* sideinfo is massively corrupt, return
+- from HCR without having decoded
+- anything */
+- }
+-
+- DeriveNumberOfExtendedSortedSectionsInSets(
+- pHcr->segmentInfo.numSegment,
+- pHcr->sectionInfo.pNumExtendedSortedCodewordInSection,
+- pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx,
+- pHcr->sectionInfo.pNumExtendedSortedSectionsInSets,
+- pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx);
+-
+- /* store */
+- pTmp1 = pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
+- pTmp2 = pHcr->sectionInfo.extendedSortedCodebookIdx;
+- pTmp3 = pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
+- pTmp4 = pHcr->decInOut.quantizedSpectralCoefficientsIdx;
+- pTmp5 = pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx;
+-
+- /* ------- decode meaningful PCWs ------ */
+- DecodePCWs(bs, pHcr);
+-
+- if ((pHcr->decInOut.errorLog & HCR_FATAL_PCW_ERROR_MASK) == 0) {
+- /* ------ decode the non-PCWs -------- */
+- DecodeNonPCWs(bs, pHcr);
+- }
+-
+- errDetectWithinSegmentationFinal(pHcr);
+-
+- /* restore */
+- pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx = pTmp1;
+- pHcr->sectionInfo.extendedSortedCodebookIdx = pTmp2;
+- pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx = pTmp3;
+- pHcr->decInOut.quantizedSpectralCoefficientsIdx = pTmp4;
+- pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx = pTmp5;
+-
+- HcrReorderQuantizedSpectralCoefficients(pHcr, pAacDecoderChannelInfo,
+- pSamplingRateInfo);
+-
+- /* restore bitstream position */
+- bitCntOffst = (INT)FDKgetValidBits(bs) - saveBitCnt;
+- if (bitCntOffst) {
+- FDKpushBiDirectional(bs, bitCntOffst);
+- }
+-
+- return (pHcr->decInOut.errorLog);
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function reorders the quantized spectral coefficients
+-sectionwise for long- and short-blocks and compares to the LAV (Largest Absolute
+-Value of the current codebook) -- a counter is incremented if there is an error
+- detected.
+- Additional for short-blocks a unit-based-deinterleaving is
+-applied. Moreover (for short blocks) the scaling is derived (compare plain
+-huffman decoder).
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void HcrReorderQuantizedSpectralCoefficients(
+- H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo) {
+- INT qsc;
+- UINT abs_qsc;
+- UINT i, j;
+- USHORT numSpectralValuesInSection;
+- FIXP_DBL *pTeVa;
+- USHORT lavErrorCnt = 0;
+-
+- UINT numSection = pHcr->decInOut.numSection;
+- SPECTRAL_PTR pQuantizedSpectralCoefficientsBase =
+- pHcr->decInOut.pQuantizedSpectralCoefficientsBase;
+- FIXP_DBL *pQuantizedSpectralCoefficients =
+- SPEC_LONG(pHcr->decInOut.pQuantizedSpectralCoefficientsBase);
+- const UCHAR *pCbDimShift = aDimCbShift;
+- const USHORT *pLargestAbsVal = aLargestAbsoluteValue;
+- UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
+- USHORT *pNumSortedCodewordInSection =
+- pHcr->sectionInfo.pNumSortedCodewordInSection;
+- USHORT *pReorderOffset = pHcr->sectionInfo.pReorderOffset;
+- FIXP_DBL pTempValues[1024];
+- FIXP_DBL *pBak = pTempValues;
+-
+- FDKmemclear(pTempValues, 1024 * sizeof(FIXP_DBL));
+-
+- /* long and short: check if decoded huffman-values (quantized spectral
+- * coefficients) are within range */
+- for (i = numSection; i != 0; i--) {
+- numSpectralValuesInSection = *pNumSortedCodewordInSection++
+- << pCbDimShift[*pSortedCodebook];
+- pTeVa = &pTempValues[*pReorderOffset++];
+- for (j = numSpectralValuesInSection; j != 0; j--) {
+- qsc = *pQuantizedSpectralCoefficients++;
+- abs_qsc = fAbs(qsc);
+- if (abs_qsc <= pLargestAbsVal[*pSortedCodebook]) {
+- *pTeVa++ = (FIXP_DBL)qsc; /* the qsc value is within range */
+- } else { /* line is too high .. */
+- if (abs_qsc ==
+- Q_VALUE_INVALID) { /* .. because of previous marking --> dont set
+- LAV flag (would be confusing), just copy out
+- the already marked value */
+- *pTeVa++ = (FIXP_DBL)qsc;
+- } else { /* .. because a too high value was decoded for this cb --> set
+- LAV flag */
+- *pTeVa++ = (FIXP_DBL)Q_VALUE_INVALID;
+- lavErrorCnt += 1;
+- }
+- }
+- }
+- pSortedCodebook++;
+- }
+-
+- if (!IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) {
+- FIXP_DBL *pOut;
+- FIXP_DBL locMax;
+- FIXP_DBL tmp;
+- SCHAR groupoffset;
+- SCHAR group;
+- SCHAR band;
+- SCHAR groupwin;
+- SCHAR window;
+- SCHAR numWinGroup;
+- SHORT interm;
+- SCHAR numSfbTransm;
+- SCHAR winGroupLen;
+- SHORT index;
+- INT msb;
+- INT lsb;
+-
+- SHORT *pScaleFacHcr = pAacDecoderChannelInfo->pDynData->aScaleFactor;
+- SHORT *pSfbSclHcr = pAacDecoderChannelInfo->pDynData->aSfbScale;
+- const SHORT *BandOffsets = GetScaleFactorBandOffsets(
+- &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo);
+-
+- pBak = pTempValues;
+- /* deinterleave unitwise for short blocks */
+- for (window = 0; window < (8); window++) {
+- pOut = SPEC(pQuantizedSpectralCoefficientsBase, window,
+- pAacDecoderChannelInfo->granuleLength);
+- for (i = 0; i < (LINES_PER_UNIT_GROUP); i++) {
+- pTeVa = pBak + (window << FOUR_LOG_DIV_TWO_LOG) +
+- i * 32; /* distance of lines between unit groups has to be
+- constant for every framelength (32)! */
+- for (j = (LINES_PER_UNIT); j != 0; j--) {
+- *pOut++ = *pTeVa++;
+- }
+- }
+- }
+-
+- /* short blocks only */
+- /* derive global scaling-value for every sfb and every window (as it is done
+- * in plain-huffman-decoder at short blocks) */
+- groupoffset = 0;
+-
+- numWinGroup = GetWindowGroups(&pAacDecoderChannelInfo->icsInfo);
+- numSfbTransm =
+- GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
+-
+- for (group = 0; group < numWinGroup; group++) {
+- winGroupLen =
+- GetWindowGroupLength(&pAacDecoderChannelInfo->icsInfo, group);
+- for (band = 0; band < numSfbTransm; band++) {
+- interm = group * 16 + band;
+- msb = pScaleFacHcr[interm] >> 2;
+- lsb = pScaleFacHcr[interm] & 3;
+- for (groupwin = 0; groupwin < winGroupLen; groupwin++) {
+- window = groupoffset + groupwin;
+- pBak = SPEC(pQuantizedSpectralCoefficientsBase, window,
+- pAacDecoderChannelInfo->granuleLength);
+- locMax = FL2FXCONST_DBL(0.0f);
+- for (index = BandOffsets[band]; index < BandOffsets[band + 1];
+- index += LINES_PER_UNIT) {
+- pTeVa = &pBak[index];
+- for (i = LINES_PER_UNIT; i != 0; i--) {
+- tmp = (*pTeVa < FL2FXCONST_DBL(0.0f)) ? -*pTeVa++ : *pTeVa++;
+- locMax = fixMax(tmp, locMax);
+- }
+- }
+- if (fixp_abs(locMax) > (FIXP_DBL)MAX_QUANTIZED_VALUE) {
+- locMax = (FIXP_DBL)MAX_QUANTIZED_VALUE;
+- }
+- pSfbSclHcr[window * 16 + band] =
+- msb - GetScaleFromValue(
+- locMax, lsb); /* save global scale maxima in this sfb */
+- }
+- }
+- groupoffset +=
+- GetWindowGroupLength(&pAacDecoderChannelInfo->icsInfo, group);
+- }
+- } else {
+- /* copy straight for long-blocks */
+- pQuantizedSpectralCoefficients =
+- SPEC_LONG(pQuantizedSpectralCoefficientsBase);
+- for (i = 1024; i != 0; i--) {
+- *pQuantizedSpectralCoefficients++ = *pBak++;
+- }
+- }
+-
+- if (lavErrorCnt != 0) {
+- pHcr->decInOut.errorLog |= LAV_VIOLATION;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function calculates the number of codewords
+- for each section (numCodewordInSection) and the number of
+-codewords for all sections (numCodeword). For zero and intensity codebooks a
+-entry is also done in the variable numCodewordInSection. It is assumed that the
+-codebook is a two tuples codebook. This is needed later for the calculation of
+-the base addresses for the reordering of the quantize spectral coefficients at
+-the end of the hcr tool. The variable numCodeword contain the number of
+-codewords which are really in the bitstream. Zero or intensity codebooks does
+-not increase the variable numCodewords.
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void HcrCalcNumCodeword(H_HCR_INFO pHcr) {
+- int hcrSection;
+- UINT numCodeword;
+-
+- UINT numSection = pHcr->decInOut.numSection;
+- UCHAR *pCodebook = pHcr->decInOut.pCodebook;
+- SHORT *pNumLineInSection = pHcr->decInOut.pNumLineInSect;
+- const UCHAR *pCbDimShift = aDimCbShift;
+-
+- USHORT *pNumCodewordInSection = pHcr->sectionInfo.pNumCodewordInSection;
+-
+- numCodeword = 0;
+- for (hcrSection = numSection; hcrSection != 0; hcrSection--) {
+- *pNumCodewordInSection = *pNumLineInSection++ >> pCbDimShift[*pCodebook];
+- if (*pCodebook != 0) {
+- numCodeword += *pNumCodewordInSection;
+- }
+- pNumCodewordInSection++;
+- pCodebook++;
+- }
+- pHcr->sectionInfo.numCodeword = numCodeword;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function calculates the number
+- of sorted codebooks and sorts the codebooks and the
+-numCodewordInSection according to the priority.
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void HcrSortCodebookAndNumCodewordInSection(H_HCR_INFO pHcr) {
+- UINT i, j, k;
+- UCHAR temp;
+- UINT counter;
+- UINT startOffset;
+- UINT numZeroSection;
+- UCHAR *pDest;
+- UINT numSectionDec;
+-
+- UINT numSection = pHcr->decInOut.numSection;
+- UCHAR *pCodebook = pHcr->decInOut.pCodebook;
+- UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
+- USHORT *pNumCodewordInSection = pHcr->sectionInfo.pNumCodewordInSection;
+- USHORT *pNumSortedCodewordInSection =
+- pHcr->sectionInfo.pNumSortedCodewordInSection;
+- UCHAR *pCodebookSwitch = pHcr->sectionInfo.pCodebookSwitch;
+- USHORT *pReorderOffset = pHcr->sectionInfo.pReorderOffset;
+- const UCHAR *pCbPriority = aCbPriority;
+- const UCHAR *pMinOfCbPair = aMinOfCbPair;
+- const UCHAR *pMaxOfCbPair = aMaxOfCbPair;
+- const UCHAR *pCbDimShift = aDimCbShift;
+-
+- UINT searchStart = 0;
+-
+- /* calculate *pNumSortedSection and store the priorities in array
+- * pSortedCdebook */
+- pDest = pSortedCodebook;
+- numZeroSection = 0;
+- for (i = numSection; i != 0; i--) {
+- if (pCbPriority[*pCodebook] == 0) {
+- numZeroSection += 1;
+- }
+- *pDest++ = pCbPriority[*pCodebook++];
+- }
+- pHcr->sectionInfo.numSortedSection =
+- numSection - numZeroSection; /* numSortedSection contains no zero or
+- intensity section */
+- pCodebook = pHcr->decInOut.pCodebook;
+-
+- /* sort priorities of the codebooks in array pSortedCdebook[] */
+- numSectionDec = numSection - 1;
+- if (numSectionDec > 0) {
+- counter = numSectionDec;
+- for (j = numSectionDec; j != 0; j--) {
+- for (i = 0; i < counter; i++) {
+- /* swap priorities */
+- if (pSortedCodebook[i + 1] > pSortedCodebook[i]) {
+- temp = pSortedCodebook[i];
+- pSortedCodebook[i] = pSortedCodebook[i + 1];
+- pSortedCodebook[i + 1] = temp;
+- }
+- }
+- counter -= 1;
+- }
+- }
+-
+- /* clear codebookSwitch array */
+- for (i = numSection; i != 0; i--) {
+- *pCodebookSwitch++ = 0;
+- }
+- pCodebookSwitch = pHcr->sectionInfo.pCodebookSwitch;
+-
+- /* sort sectionCodebooks and numCodwordsInSection and calculate
+- * pReorderOffst[j] */
+- for (j = 0; j < numSection; j++) {
+- for (i = searchStart; i < numSection; i++) {
+- if (pCodebookSwitch[i] == 0 &&
+- (pMinOfCbPair[pSortedCodebook[j]] == pCodebook[i] ||
+- pMaxOfCbPair[pSortedCodebook[j]] == pCodebook[i])) {
+- pCodebookSwitch[i] = 1;
+- pSortedCodebook[j] = pCodebook[i]; /* sort codebook */
+- pNumSortedCodewordInSection[j] =
+- pNumCodewordInSection[i]; /* sort NumCodewordInSection */
+-
+- startOffset = 0;
+- for (k = 0; k < i; k++) { /* make entry in pReorderOffst */
+- startOffset += pNumCodewordInSection[k] << pCbDimShift[pCodebook[k]];
+- }
+- pReorderOffset[j] =
+- startOffset; /* offset for reordering the codewords */
+-
+- if (i == searchStart) {
+- k = i;
+- while (pCodebookSwitch[k++] == 1) searchStart++;
+- }
+- break;
+- }
+- }
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function calculates the segmentation, which includes
+-numSegment, leftStartOfSegment, rightStartOfSegment and remainingBitsInSegment.
+- The segmentation could be visualized a as kind of
+-'overlay-grid' for the bitstream-block holding the HCR-encoded
+-quantized-spectral-coefficients.
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr) {
+- USHORT i, j;
+- USHORT numSegment = 0;
+- INT segmentStart = 0;
+- UCHAR segmentWidth;
+- UCHAR lastSegmentWidth;
+- UCHAR sortedCodebook;
+- UCHAR endFlag = 0;
+- INT intermediateResult;
+-
+- SCHAR lengthOfLongestCodeword = pHcr->decInOut.lengthOfLongestCodeword;
+- SHORT lengthOfReorderedSpectralData =
+- pHcr->decInOut.lengthOfReorderedSpectralData;
+- UINT numSortedSection = pHcr->sectionInfo.numSortedSection;
+- UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
+- USHORT *pNumSortedCodewordInSection =
+- pHcr->sectionInfo.pNumSortedCodewordInSection;
+- INT *pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- INT *pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
+- SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- const UCHAR *pMaxCwLength = aMaxCwLen;
+-
+- for (i = numSortedSection; i != 0; i--) {
+- sortedCodebook = *pSortedCodebook++;
+- segmentWidth =
+- fMin((INT)pMaxCwLength[sortedCodebook], (INT)lengthOfLongestCodeword);
+-
+- for (j = *pNumSortedCodewordInSection; j != 0; j--) {
+- /* width allows a new segment */
+- intermediateResult = segmentStart;
+- if ((segmentStart + segmentWidth) <= lengthOfReorderedSpectralData) {
+- /* store segment start, segment length and increment the number of
+- * segments */
+- *pLeftStartOfSegment++ = intermediateResult;
+- *pRightStartOfSegment++ = intermediateResult + segmentWidth - 1;
+- *pRemainingBitsInSegment++ = segmentWidth;
+- segmentStart += segmentWidth;
+- numSegment += 1;
+- }
+- /* width does not allow a new segment */
+- else {
+- /* correct the last segment length */
+- pLeftStartOfSegment--;
+- pRightStartOfSegment--;
+- pRemainingBitsInSegment--;
+- segmentStart = *pLeftStartOfSegment;
+-
+- lastSegmentWidth = lengthOfReorderedSpectralData - segmentStart;
+- *pRemainingBitsInSegment = lastSegmentWidth;
+- *pRightStartOfSegment = segmentStart + lastSegmentWidth - 1;
+- endFlag = 1;
+- break;
+- }
+- }
+- pNumSortedCodewordInSection++;
+- if (endFlag != 0) {
+- break;
+- }
+- }
+- pHcr->segmentInfo.numSegment = numSegment;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function adapts the sorted section boundaries to the
+-boundaries of segmentation. If the section lengths does not fit completely into
+-the current segment, the section is spitted into two so called 'extended
+- sections'. The extended-section-info
+-(pNumExtendedSortedCodewordInSectin and pExtendedSortedCodebook) is updated in
+-this case.
+-
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void HcrExtendedSectionInfo(H_HCR_INFO pHcr) {
+- UINT srtSecCnt = 0; /* counter for sorted sections */
+- UINT xSrtScCnt = 0; /* counter for extended sorted sections */
+- UINT remainNumCwInSortSec;
+- UINT inSegmentRemainNumCW;
+-
+- UINT numSortedSection = pHcr->sectionInfo.numSortedSection;
+- UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
+- USHORT *pNumSortedCodewordInSection =
+- pHcr->sectionInfo.pNumSortedCodewordInSection;
+- UCHAR *pExtendedSortedCoBo = pHcr->sectionInfo.pExtendedSortedCodebook;
+- USHORT *pNumExtSortCwInSect =
+- pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
+- UINT numSegment = pHcr->segmentInfo.numSegment;
+- UCHAR *pMaxLenOfCbInExtSrtSec = pHcr->sectionInfo.pMaxLenOfCbInExtSrtSec;
+- SCHAR lengthOfLongestCodeword = pHcr->decInOut.lengthOfLongestCodeword;
+- const UCHAR *pMaxCwLength = aMaxCwLen;
+-
+- remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
+- inSegmentRemainNumCW = numSegment;
+-
+- while (srtSecCnt < numSortedSection) {
+- if (inSegmentRemainNumCW < remainNumCwInSortSec) {
+- pNumExtSortCwInSect[xSrtScCnt] = inSegmentRemainNumCW;
+- pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
+-
+- remainNumCwInSortSec -= inSegmentRemainNumCW;
+- inSegmentRemainNumCW = numSegment;
+- /* data of a sorted section was not integrated in extended sorted section
+- */
+- } else if (inSegmentRemainNumCW == remainNumCwInSortSec) {
+- pNumExtSortCwInSect[xSrtScCnt] = inSegmentRemainNumCW;
+- pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
+-
+- srtSecCnt++;
+- remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
+- inSegmentRemainNumCW = numSegment;
+- /* data of a sorted section was integrated in extended sorted section */
+- } else { /* inSegmentRemainNumCW > remainNumCwInSortSec */
+- pNumExtSortCwInSect[xSrtScCnt] = remainNumCwInSortSec;
+- pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
+-
+- inSegmentRemainNumCW -= remainNumCwInSortSec;
+- srtSecCnt++;
+- remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
+- /* data of a sorted section was integrated in extended sorted section */
+- }
+- pMaxLenOfCbInExtSrtSec[xSrtScCnt] =
+- fMin((INT)pMaxCwLength[pExtendedSortedCoBo[xSrtScCnt]],
+- (INT)lengthOfLongestCodeword);
+-
+- xSrtScCnt += 1;
+-
+- if (xSrtScCnt >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
+- pHcr->decInOut.errorLog |= EXTENDED_SORTED_COUNTER_OVERFLOW;
+- return;
+- }
+- }
+- pNumExtSortCwInSect[xSrtScCnt] = 0;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function calculates the number of extended sorted
+-sections which belong to the sets. Each set from set 0 (one and only set for the
+-PCWs) till to the last set gets a entry in the array to which
+- 'pNumExtendedSortedSectinsInSets' points to.
+-
+- Calculation: The entrys in
+-pNumExtendedSortedCodewordInSectin are added untill the value numSegment is
+-reached. Then the sum_variable is cleared and the calculation starts from the
+-beginning. As much extended sorted Sections are summed up to reach the value
+-numSegment, as much is the current entry in *pNumExtendedSortedCodewordInSectin.
+---------------------------------------------------------------------------------------------
+-*/
+-static void DeriveNumberOfExtendedSortedSectionsInSets(
+- UINT numSegment, USHORT *pNumExtendedSortedCodewordInSection,
+- int numExtendedSortedCodewordInSectionIdx,
+- USHORT *pNumExtendedSortedSectionsInSets,
+- int numExtendedSortedSectionsInSetsIdx) {
+- USHORT counter = 0;
+- UINT cwSum = 0;
+- USHORT *pNumExSortCwInSec = pNumExtendedSortedCodewordInSection;
+- USHORT *pNumExSortSecInSets = pNumExtendedSortedSectionsInSets;
+-
+- while (pNumExSortCwInSec[numExtendedSortedCodewordInSectionIdx] != 0) {
+- cwSum += pNumExSortCwInSec[numExtendedSortedCodewordInSectionIdx];
+- numExtendedSortedCodewordInSectionIdx++;
+- if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
+- return;
+- }
+- if (cwSum > numSegment) {
+- return;
+- }
+- counter++;
+- if (counter > 1024 / 4) {
+- return;
+- }
+- if (cwSum == numSegment) {
+- pNumExSortSecInSets[numExtendedSortedSectionsInSetsIdx] = counter;
+- numExtendedSortedSectionsInSetsIdx++;
+- if (numExtendedSortedSectionsInSetsIdx >= MAX_HCR_SETS) {
+- return;
+- }
+- counter = 0;
+- cwSum = 0;
+- }
+- }
+- pNumExSortSecInSets[numExtendedSortedSectionsInSetsIdx] =
+- counter; /* save last entry for the last - probably shorter - set */
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function decodes all priority codewords (PCWs) in a
+-spectrum (within set 0). The calculation of the PCWs is managed in two loops.
+-The loopcounter of the outer loop is set to the first value pointer
+- pNumExtendedSortedSectionsInSets points to. This value
+-represents the number of extended sorted sections within set 0. The loopcounter
+-of the inner loop is set to the first value pointer
+- pNumExtendedSortedCodewordInSectin points to. The value
+-represents the number of extended sorted codewords in sections (the original
+-sections have been splitted to go along with the borders of the sets). Each time
+-the number of the extended sorted codewords in sections are de- coded, the
+-pointer 'pNumExtendedSortedCodewordInSectin' is incremented by one.
+---------------------------------------------------------------------------------------------
+-*/
+-static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) {
+- UINT i;
+- USHORT extSortSec;
+- USHORT curExtSortCwInSec;
+- UCHAR codebook;
+- UCHAR dimension;
+- const UINT *pCurrentTree;
+- const SCHAR *pQuantValBase;
+- const SCHAR *pQuantVal;
+-
+- USHORT *pNumExtendedSortedCodewordInSection =
+- pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
+- int numExtendedSortedCodewordInSectionIdx =
+- pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
+- UCHAR *pExtendedSortedCodebook = pHcr->sectionInfo.pExtendedSortedCodebook;
+- int extendedSortedCodebookIdx = pHcr->sectionInfo.extendedSortedCodebookIdx;
+- USHORT *pNumExtendedSortedSectionsInSets =
+- pHcr->sectionInfo.pNumExtendedSortedSectionsInSets;
+- int numExtendedSortedSectionsInSetsIdx =
+- pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
+- FIXP_DBL *pQuantizedSpectralCoefficients =
+- SPEC_LONG(pHcr->decInOut.pQuantizedSpectralCoefficientsBase);
+- int quantizedSpectralCoefficientsIdx =
+- pHcr->decInOut.quantizedSpectralCoefficientsIdx;
+- INT *pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- UCHAR *pMaxLenOfCbInExtSrtSec = pHcr->sectionInfo.pMaxLenOfCbInExtSrtSec;
+- int maxLenOfCbInExtSrtSecIdx = pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx;
+- UCHAR maxAllowedCwLen;
+- int numDecodedBits;
+- const UCHAR *pCbDimension = aDimCb;
+- const UCHAR *pCbSign = aSignCb;
+-
+- /* clear result array */
+- FDKmemclear(pQuantizedSpectralCoefficients + quantizedSpectralCoefficientsIdx,
+- 1024 * sizeof(FIXP_DBL));
+-
+- /* decode all PCWs in the extended sorted section(s) belonging to set 0 */
+- for (extSortSec =
+- pNumExtendedSortedSectionsInSets[numExtendedSortedSectionsInSetsIdx];
+- extSortSec != 0; extSortSec--) {
+- codebook =
+- pExtendedSortedCodebook[extendedSortedCodebookIdx]; /* get codebook for
+- this extended
+- sorted section
+- and increment ptr
+- to cb of next
+- ext. sort sec */
+- extendedSortedCodebookIdx++;
+- if (extendedSortedCodebookIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
+- return;
+- }
+- dimension = pCbDimension[codebook]; /* get dimension of codebook of this
+- extended sort. sec. */
+- pCurrentTree =
+- aHuffTable[codebook]; /* convert codebook to pointer to QSCs */
+- pQuantValBase =
+- aQuantTable[codebook]; /* convert codebook to index to table of QSCs */
+- maxAllowedCwLen = pMaxLenOfCbInExtSrtSec[maxLenOfCbInExtSrtSecIdx];
+- maxLenOfCbInExtSrtSecIdx++;
+- if (maxLenOfCbInExtSrtSecIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
+- return;
+- }
+-
+- /* switch for decoding with different codebooks: */
+- if (pCbSign[codebook] ==
+- 0) { /* no sign bits follow after the codeword-body */
+- /* PCW_BodyONLY */
+- /*==============*/
+-
+- for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
+- [numExtendedSortedCodewordInSectionIdx];
+- curExtSortCwInSec != 0; curExtSortCwInSec--) {
+- numDecodedBits = 0;
+-
+- /* decode PCW_BODY */
+- pQuantVal = DecodePCW_Body(
+- bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
+- pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
+-
+- /* result is written out here because NO sign bits follow the body */
+- for (i = dimension; i != 0; i--) {
+- pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
+- (FIXP_DBL)*pQuantVal++; /* write quant. spec. coef. into
+- spectrum; sign is already valid */
+- quantizedSpectralCoefficientsIdx++;
+- if (quantizedSpectralCoefficientsIdx >= 1024) {
+- return;
+- }
+- }
+-
+- /* one more PCW should be decoded */
+-
+- if (maxAllowedCwLen < (numDecodedBits + ERROR_PCW_BODY_ONLY_TOO_LONG)) {
+- pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_BITS_DECODED;
+- }
+-
+- if (1 == errDetectPcwSegmentation(
+- *pRemainingBitsInSegment - ERROR_PCW_BODY, pHcr, PCW_BODY,
+- pQuantizedSpectralCoefficients +
+- quantizedSpectralCoefficientsIdx - dimension,
+- dimension)) {
+- return;
+- }
+- pLeftStartOfSegment++; /* update pointer for decoding the next PCW */
+- pRemainingBitsInSegment++; /* update pointer for decoding the next PCW
+- */
+- }
+- } else if ((codebook < 11) && (pCbSign[codebook] ==
+- 1)) { /* possibly there follow 1,2,3 or 4
+- sign bits after the codeword-body */
+- /* PCW_Body and PCW_Sign */
+- /*=======================*/
+-
+- for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
+- [numExtendedSortedCodewordInSectionIdx];
+- curExtSortCwInSec != 0; curExtSortCwInSec--) {
+- int err;
+- numDecodedBits = 0;
+-
+- pQuantVal = DecodePCW_Body(
+- bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
+- pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
+-
+- err = DecodePCW_Sign(
+- bs, pHcr->decInOut.bitstreamAnchor, dimension, pQuantVal,
+- pQuantizedSpectralCoefficients, &quantizedSpectralCoefficientsIdx,
+- pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
+- if (err != 0) {
+- return;
+- }
+- /* one more PCW should be decoded */
+-
+- if (maxAllowedCwLen < (numDecodedBits + ERROR_PCW_BODY_SIGN_TOO_LONG)) {
+- pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_SIGN_BITS_DECODED;
+- }
+-
+- if (1 == errDetectPcwSegmentation(
+- *pRemainingBitsInSegment - ERROR_PCW_BODY_SIGN, pHcr,
+- PCW_BODY_SIGN,
+- pQuantizedSpectralCoefficients +
+- quantizedSpectralCoefficientsIdx - dimension,
+- dimension)) {
+- return;
+- }
+- pLeftStartOfSegment++;
+- pRemainingBitsInSegment++;
+- }
+- } else if ((pCbSign[codebook] == 1) &&
+- (codebook >= 11)) { /* possibly there follow some sign bits and
+- maybe one or two escape sequences after
+- the cw-body */
+- /* PCW_Body, PCW_Sign and maybe PCW_Escape */
+- /*=========================================*/
+-
+- for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
+- [numExtendedSortedCodewordInSectionIdx];
+- curExtSortCwInSec != 0; curExtSortCwInSec--) {
+- int err;
+- numDecodedBits = 0;
+-
+- /* decode PCW_BODY */
+- pQuantVal = DecodePCW_Body(
+- bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
+- pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
+-
+- err = DecodePCW_Sign(
+- bs, pHcr->decInOut.bitstreamAnchor, dimension, pQuantVal,
+- pQuantizedSpectralCoefficients, &quantizedSpectralCoefficientsIdx,
+- pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
+- if (err != 0) {
+- return;
+- }
+-
+- /* decode PCW_ESCAPE if present */
+- quantizedSpectralCoefficientsIdx -= DIMENSION_OF_ESCAPE_CODEBOOK;
+-
+- if (fixp_abs(pQuantizedSpectralCoefficients
+- [quantizedSpectralCoefficientsIdx]) ==
+- (FIXP_DBL)ESCAPE_VALUE) {
+- pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
+- (FIXP_DBL)DecodeEscapeSequence(
+- bs, pHcr->decInOut.bitstreamAnchor,
+- pQuantizedSpectralCoefficients
+- [quantizedSpectralCoefficientsIdx],
+- pLeftStartOfSegment, pRemainingBitsInSegment,
+- &numDecodedBits);
+- }
+- quantizedSpectralCoefficientsIdx++;
+- if (quantizedSpectralCoefficientsIdx >= 1024) {
+- return;
+- }
+-
+- if (fixp_abs(pQuantizedSpectralCoefficients
+- [quantizedSpectralCoefficientsIdx]) ==
+- (FIXP_DBL)ESCAPE_VALUE) {
+- pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
+- (FIXP_DBL)DecodeEscapeSequence(
+- bs, pHcr->decInOut.bitstreamAnchor,
+- pQuantizedSpectralCoefficients
+- [quantizedSpectralCoefficientsIdx],
+- pLeftStartOfSegment, pRemainingBitsInSegment,
+- &numDecodedBits);
+- }
+- quantizedSpectralCoefficientsIdx++;
+- if (quantizedSpectralCoefficientsIdx >= 1024) {
+- return;
+- }
+-
+- /* one more PCW should be decoded */
+-
+- if (maxAllowedCwLen <
+- (numDecodedBits + ERROR_PCW_BODY_SIGN_ESC_TOO_LONG)) {
+- pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_SIGN_ESC_BITS_DECODED;
+- }
+-
+- if (1 == errDetectPcwSegmentation(
+- *pRemainingBitsInSegment - ERROR_PCW_BODY_SIGN_ESC, pHcr,
+- PCW_BODY_SIGN_ESC,
+- pQuantizedSpectralCoefficients +
+- quantizedSpectralCoefficientsIdx -
+- DIMENSION_OF_ESCAPE_CODEBOOK,
+- DIMENSION_OF_ESCAPE_CODEBOOK)) {
+- return;
+- }
+- pLeftStartOfSegment++;
+- pRemainingBitsInSegment++;
+- }
+- }
+-
+- /* all PCWs belonging to this extended section should be decoded */
+- numExtendedSortedCodewordInSectionIdx++;
+- if (numExtendedSortedCodewordInSectionIdx >= MAX_SFB_HCR + MAX_HCR_SETS) {
+- return;
+- }
+- }
+- /* all PCWs should be decoded */
+-
+- numExtendedSortedSectionsInSetsIdx++;
+- if (numExtendedSortedSectionsInSetsIdx >= MAX_HCR_SETS) {
+- return;
+- }
+-
+- /* Write back indexes into structure */
+- pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
+- numExtendedSortedCodewordInSectionIdx;
+- pHcr->sectionInfo.extendedSortedCodebookIdx = extendedSortedCodebookIdx;
+- pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx =
+- numExtendedSortedSectionsInSetsIdx;
+- pHcr->decInOut.quantizedSpectralCoefficientsIdx =
+- quantizedSpectralCoefficientsIdx;
+- pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx = maxLenOfCbInExtSrtSecIdx;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function checks immediately after every decoded PCW,
+-whether out of the current segment too many bits have been read or not. If an
+-error occurrs, probably the sideinfo or the HCR-bitstream block holding the
+-huffman encoded quantized spectral coefficients is distorted. In this case the
+-two or four quantized spectral coefficients belonging to the current codeword
+- are marked (for being detected by concealment later).
+---------------------------------------------------------------------------------------------
+-*/
+-static UCHAR errDetectPcwSegmentation(SCHAR remainingBitsInSegment,
+- H_HCR_INFO pHcr, PCW_TYPE kind,
+- FIXP_DBL *qsc_base_of_cw,
+- UCHAR dimension) {
+- SCHAR i;
+- if (remainingBitsInSegment < 0) {
+- /* log the error */
+- switch (kind) {
+- case PCW_BODY:
+- pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY;
+- break;
+- case PCW_BODY_SIGN:
+- pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN;
+- break;
+- case PCW_BODY_SIGN_ESC:
+- pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN_ESC;
+- break;
+- }
+- /* mark the erred lines */
+- for (i = dimension; i != 0; i--) {
+- *qsc_base_of_cw++ = (FIXP_DBL)Q_VALUE_INVALID;
+- }
+- return 1;
+- }
+- return 0;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function checks if all segments are empty after
+-decoding. There are _no lines markded_ as invalid because it could not be traced
+-back where from the remaining bits are.
+---------------------------------------------------------------------------------------------
+-*/
+-static void errDetectWithinSegmentationFinal(H_HCR_INFO pHcr) {
+- UCHAR segmentationErrorFlag = 0;
+- USHORT i;
+- SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- UINT numSegment = pHcr->segmentInfo.numSegment;
+-
+- for (i = numSegment; i != 0; i--) {
+- if (*pRemainingBitsInSegment++ != 0) {
+- segmentationErrorFlag = 1;
+- }
+- }
+- if (segmentationErrorFlag == 1) {
+- pHcr->decInOut.errorLog |= BIT_IN_SEGMENTATION_ERROR;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function walks one step within the decoding tree. Which
+-branch is taken depends on the decoded carryBit input parameter.
+---------------------------------------------------------------------------------------------
+-*/
+-void CarryBitToBranchValue(UCHAR carryBit, UINT treeNode, UINT *branchValue,
+- UINT *branchNode) {
+- if (carryBit == 0) {
+- *branchNode =
+- (treeNode & MASK_LEFT) >> LEFT_OFFSET; /* MASK_LEFT: 00FFF000 */
+- } else {
+- *branchNode = treeNode & MASK_RIGHT; /* MASK_RIGHT: 00000FFF */
+- }
+-
+- *branchValue = *branchNode & CLR_BIT_10; /* clear bit 10 (if set) */
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Decodes the body of a priority codeword (PCW)
+------------------------------------------------------------------------------------------------
+- return: - return value is pointer to first of two or four quantized
+-spectral coefficients
+---------------------------------------------------------------------------------------------
+-*/
+-static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- const UINT *pCurrentTree,
+- const SCHAR *pQuantValBase,
+- INT *pLeftStartOfSegment,
+- SCHAR *pRemainingBitsInSegment,
+- int *pNumDecodedBits) {
+- UCHAR carryBit;
+- UINT branchNode;
+- UINT treeNode;
+- UINT branchValue;
+- const SCHAR *pQuantVal;
+-
+- /* decode PCW_BODY */
+- treeNode = *pCurrentTree; /* get first node of current tree belonging to
+- current codebook */
+-
+- /* decode whole PCW-codeword-body */
+- while (1) {
+- carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
+- pLeftStartOfSegment, /* dummy */
+- FROM_LEFT_TO_RIGHT);
+- *pRemainingBitsInSegment -= 1;
+- *pNumDecodedBits += 1;
+-
+- CarryBitToBranchValue(carryBit, treeNode, &branchValue, &branchNode);
+-
+- if ((branchNode & TEST_BIT_10) ==
+- TEST_BIT_10) { /* test bit 10 ; if set --> codeword-body is complete */
+- break; /* end of branch in tree reached i.e. a whole PCW-Body is decoded
+- */
+- } else {
+- treeNode = *(
+- pCurrentTree +
+- branchValue); /* update treeNode for further step in decoding tree */
+- }
+- }
+-
+- pQuantVal =
+- pQuantValBase + branchValue; /* update pointer to valid first of 2 or 4
+- quantized values */
+-
+- return pQuantVal;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function decodes one escape sequence. In case of a
+-escape codebook and in case of the absolute value of the quantized spectral
+-value == 16, a escapeSequence is decoded in two steps:
+- 1. escape prefix
+- 2. escape word
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- INT quantSpecCoef, INT *pLeftStartOfSegment,
+- SCHAR *pRemainingBitsInSegment,
+- int *pNumDecodedBits) {
+- UINT i;
+- INT sign;
+- UINT escapeOnesCounter = 0;
+- UINT carryBit;
+- INT escape_word = 0;
+-
+- /* decode escape prefix */
+- while (1) {
+- carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
+- pLeftStartOfSegment, /* dummy */
+- FROM_LEFT_TO_RIGHT);
+- *pRemainingBitsInSegment -= 1;
+- *pNumDecodedBits += 1;
+-
+- if (carryBit != 0) {
+- escapeOnesCounter += 1;
+- } else {
+- escapeOnesCounter += 4;
+- break;
+- }
+- }
+-
+- /* decode escape word */
+- for (i = escapeOnesCounter; i != 0; i--) {
+- carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
+- pLeftStartOfSegment, /* dummy */
+- FROM_LEFT_TO_RIGHT);
+- *pRemainingBitsInSegment -= 1;
+- *pNumDecodedBits += 1;
+-
+- escape_word <<= 1;
+- escape_word = escape_word | carryBit;
+- }
+-
+- sign = (quantSpecCoef >= 0) ? 1 : -1;
+-
+- quantSpecCoef = sign * (((INT)1 << escapeOnesCounter) + escape_word);
+-
+- return quantSpecCoef;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Decodes the Signbits of a priority codeword (PCW) and writes
+-out the resulting quantized spectral values into unsorted sections
+------------------------------------------------------------------------------------------------
+- output: - two or four lines at position in corresponding section
+-(which are not located at the desired position, i.e. they must be reordered in
+-the last of eight function of HCR)
+------------------------------------------------------------------------------------------------
+- return: - updated pQuantSpecCoef pointer (to next empty storage for a
+-line)
+---------------------------------------------------------------------------------------------
+-*/
+-static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- UINT codebookDim, const SCHAR *pQuantVal,
+- FIXP_DBL *pQuantSpecCoef, int *quantSpecCoefIdx,
+- INT *pLeftStartOfSegment,
+- SCHAR *pRemainingBitsInSegment,
+- int *pNumDecodedBits) {
+- UINT i;
+- UINT carryBit;
+- INT quantSpecCoef;
+-
+- for (i = codebookDim; i != 0; i--) {
+- quantSpecCoef = *pQuantVal++;
+- if (quantSpecCoef != 0) {
+- carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
+- pLeftStartOfSegment, /* dummy */
+- FROM_LEFT_TO_RIGHT);
+- *pRemainingBitsInSegment -= 1;
+- *pNumDecodedBits += 1;
+- if (*pRemainingBitsInSegment < 0 || *pNumDecodedBits >= (1024 >> 1)) {
+- return -1;
+- }
+-
+- /* adapt sign of values according to the decoded sign bit */
+- if (carryBit != 0) {
+- pQuantSpecCoef[*quantSpecCoefIdx] = -(FIXP_DBL)quantSpecCoef;
+- } else {
+- pQuantSpecCoef[*quantSpecCoefIdx] = (FIXP_DBL)quantSpecCoef;
+- }
+- } else {
+- pQuantSpecCoef[*quantSpecCoefIdx] = FL2FXCONST_DBL(0.0f);
+- }
+- *quantSpecCoefIdx += 1;
+- if (*quantSpecCoefIdx >= 1024) {
+- return -1;
+- }
+- }
+- return 0;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Mutes spectral lines which have been marked as erroneous
+-(Q_VALUE_INVALID)
+---------------------------------------------------------------------------------------------
+-*/
+-void HcrMuteErroneousLines(H_HCR_INFO hHcr) {
+- int c;
+- FIXP_DBL *RESTRICT pLong =
+- SPEC_LONG(hHcr->decInOut.pQuantizedSpectralCoefficientsBase);
+-
+- /* if there is a line with value Q_VALUE_INVALID mute it */
+- for (c = 0; c < 1024; c++) {
+- if (pLong[c] == (FIXP_DBL)Q_VALUE_INVALID) {
+- pLong[c] = FL2FXCONST_DBL(0.0f); /* muting */
+- }
+- }
+-}
+diff --git a/libAACdec/src/aacdec_hcr.h b/libAACdec/src/aacdec_hcr.h
+deleted file mode 100644
+index be21144..0000000
+--- a/libAACdec/src/aacdec_hcr.h
++++ /dev/null
+@@ -1,128 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Robert Weidner (DSP Solutions)
+-
+- Description: HCR Decoder: Interface function declaration; common defines
+- and structures; defines for switching error-generator,
+- -detector, and -concealment
+-
+-*******************************************************************************/
+-
+-#ifndef AACDEC_HCR_H
+-#define AACDEC_HCR_H
+-
+-#include "channelinfo.h"
+-#include "FDK_bitstream.h"
+-
+-UINT HcrInit(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo,
+- HANDLE_FDK_BITSTREAM bs);
+-UINT HcrDecoder(H_HCR_INFO hHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo,
+- HANDLE_FDK_BITSTREAM bs);
+-void CarryBitToBranchValue(UCHAR carryBit, UINT treeNode, UINT *branchValue,
+- UINT *branchNode);
+-
+-void CHcr_Read(HANDLE_FDK_BITSTREAM bs,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const MP4_ELEMENT_ID globalHcrType);
+-void HcrMuteErroneousLines(H_HCR_INFO hHcr);
+-
+-void setHcrType(H_HCR_INFO hHcr, MP4_ELEMENT_ID type);
+-INT getHcrType(H_HCR_INFO hHcr);
+-
+-#endif /* AACDEC_HCR_H */
+diff --git a/libAACdec/src/aacdec_hcr_bit.cpp b/libAACdec/src/aacdec_hcr_bit.cpp
+deleted file mode 100644
+index 0198659..0000000
+--- a/libAACdec/src/aacdec_hcr_bit.cpp
++++ /dev/null
+@@ -1,164 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Robert Weidner (DSP Solutions)
+-
+- Description: HCR Decoder: Bitstream reading
+-
+-*******************************************************************************/
+-
+-#include "aacdec_hcr_bit.h"
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function toggles the read direction.
+------------------------------------------------------------------------------------------------
+- input: current read direction
+------------------------------------------------------------------------------------------------
+- return: new read direction
+---------------------------------------------------------------------------------------------
+-*/
+-UCHAR ToggleReadDirection(UCHAR readDirection) {
+- if (readDirection == FROM_LEFT_TO_RIGHT) {
+- return FROM_RIGHT_TO_LEFT;
+- } else {
+- return FROM_LEFT_TO_RIGHT;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function returns a bit from the bitstream according to
+-read direction. It is called very often, therefore it makes sense to inline it
+-(runtime).
+------------------------------------------------------------------------------------------------
+- input: - handle to FDK bitstream
+- - reference value marking start of bitfield
+- - pLeftStartOfSegment
+- - pRightStartOfSegment
+- - readDirection
+------------------------------------------------------------------------------------------------
+- return: - bit from bitstream
+---------------------------------------------------------------------------------------------
+-*/
+-UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- INT *pLeftStartOfSegment,
+- INT *pRightStartOfSegment, UCHAR readDirection) {
+- UINT bit;
+- INT readBitOffset;
+-
+- if (readDirection == FROM_LEFT_TO_RIGHT) {
+- readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pLeftStartOfSegment;
+- if (readBitOffset) {
+- FDKpushBiDirectional(bs, readBitOffset);
+- }
+-
+- bit = FDKreadBits(bs, 1);
+-
+- *pLeftStartOfSegment += 1;
+- } else {
+- readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pRightStartOfSegment;
+- if (readBitOffset) {
+- FDKpushBiDirectional(bs, readBitOffset);
+- }
+-
+- /* to be replaced with a brother function of FDKreadBits() */
+- bit = FDKreadBits(bs, 1);
+- FDKpushBack(bs, 2);
+-
+- *pRightStartOfSegment -= 1;
+- }
+-
+- return (bit);
+-}
+diff --git a/libAACdec/src/aacdec_hcr_bit.h b/libAACdec/src/aacdec_hcr_bit.h
+deleted file mode 100644
+index 77242ac..0000000
+--- a/libAACdec/src/aacdec_hcr_bit.h
++++ /dev/null
+@@ -1,114 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Robert Weidner (DSP Solutions)
+-
+- Description: HCR Decoder: Bitstream reading prototypes
+-
+-*******************************************************************************/
+-
+-#ifndef AACDEC_HCR_BIT_H
+-#define AACDEC_HCR_BIT_H
+-
+-#include "aacdec_hcr.h"
+-
+-UCHAR ToggleReadDirection(UCHAR readDirection);
+-
+-UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- INT *pLeftStartOfSegment,
+- INT *pRightStartOfSegment, UCHAR readDirection);
+-
+-#endif /* AACDEC_HCR_BIT_H */
+diff --git a/libAACdec/src/aacdec_hcr_types.h b/libAACdec/src/aacdec_hcr_types.h
+deleted file mode 100644
+index 1cc3cb0..0000000
+--- a/libAACdec/src/aacdec_hcr_types.h
++++ /dev/null
+@@ -1,432 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Robert Weidner (DSP Solutions)
+-
+- Description: HCR Decoder: Common defines and structures; defines for
+- switching error-generator, -detector, and -concealment;
+-
+-*******************************************************************************/
+-
+-#ifndef AACDEC_HCR_TYPES_H
+-#define AACDEC_HCR_TYPES_H
+-
+-#include "FDK_bitstream.h"
+-#include "overlapadd.h"
+-
+-/* ------------------------------------------------ */
+-/* ------------------------------------------------ */
+-
+-#define LINES_PER_UNIT 4
+-
+-/* ------------------------------------------------ */
+-/* ------------------------------------------------ */
+-/* ----------- basic HCR configuration ------------ */
+-
+-#define MAX_SFB_HCR \
+- (((1024 / 8) / LINES_PER_UNIT) * 8) /* (8 * 16) is not enough because sfbs \
+- are split in units for blocktype \
+- short */
+-#define NUMBER_OF_UNIT_GROUPS (LINES_PER_UNIT * 8)
+-#define LINES_PER_UNIT_GROUP (1024 / NUMBER_OF_UNIT_GROUPS) /* 15 16 30 32 */
+-
+-/* ------------------------------------------------ */
+-/* ------------------------------------------------ */
+-/* ------------------------------------------------ */
+-
+-#define FROM_LEFT_TO_RIGHT 0
+-#define FROM_RIGHT_TO_LEFT 1
+-
+-#define MAX_CB_PAIRS 23
+-#define MAX_HCR_SETS 14
+-
+-#define ESCAPE_VALUE 16
+-#define POSITION_OF_FLAG_A 21
+-#define POSITION_OF_FLAG_B 20
+-
+-#define MAX_CB 32 /* last used CB is cb #31 when VCB11 is used */
+-
+-#define MAX_CB_CHECK \
+- 32 /* support for VCB11 available -- is more general, could therefore used \
+- in both cases */
+-
+-#define NUMBER_OF_BIT_IN_WORD 32
+-
+-/* log */
+-#define THIRTYTWO_LOG_DIV_TWO_LOG 5
+-#define EIGHT_LOG_DIV_TWO_LOG 3
+-#define FOUR_LOG_DIV_TWO_LOG 2
+-
+-/* borders */
+-#define CPE_TOP_LENGTH 12288
+-#define SCE_TOP_LENGTH 6144
+-#define LEN_OF_LONGEST_CW_TOP_LENGTH 49
+-
+-/* qsc's of high level */
+-#define Q_VALUE_INVALID \
+- 8192 /* mark a invalid line with this value (to be concealed later on) */
+-#define HCR_DIRAC 500 /* a line of high level */
+-
+-/* masks */
+-#define MASK_LEFT 0xFFF000
+-#define MASK_RIGHT 0xFFF
+-#define CLR_BIT_10 0x3FF
+-#define TEST_BIT_10 0x400
+-
+-#define LEFT_OFFSET 12
+-
+-/* when set HCR is replaced by a dummy-module which just fills the outputbuffer
+- * with a dirac sequence */
+-/* use this if HCR is suspected to write in other modules -- if error is stell
+- * there, HCR is innocent */
+-
+-/* ------------------------------ */
+-/* - insert HCR errors - */
+-/* ------------------------------ */
+-
+-/* modify input lengths -- high protected */
+-#define ERROR_LORSD 0 /* offset: error if different from zero */
+-#define ERROR_LOLC 0 /* offset: error if different from zero */
+-
+-/* segments are earlier empty as expected when decoding PCWs */
+-#define ERROR_PCW_BODY \
+- 0 /* set a positive values to trigger the error (make segments earlyer \
+- appear to be empty) */
+-#define ERROR_PCW_BODY_SIGN \
+- 0 /* set a positive values to trigger the error (make segments earlyer \
+- appear to be empty) */
+-#define ERROR_PCW_BODY_SIGN_ESC \
+- 0 /* set a positive values to trigger the error (make segments earlyer \
+- appear to be empty) */
+-
+-/* pretend there are too many bits decoded (enlarge length of codeword) at PCWs
+- * -- use a positive value */
+-#define ERROR_PCW_BODY_ONLY_TOO_LONG \
+- 0 /* set a positive values to trigger the error */
+-#define ERROR_PCW_BODY_SIGN_TOO_LONG \
+- 0 /* set a positive values to trigger the error */
+-#define ERROR_PCW_BODY_SIGN_ESC_TOO_LONG \
+- 0 /* set a positive values to trigger the error */
+-
+-/* modify HCR bitstream block */
+-
+-#define MODULO_DIVISOR_HCR 30
+-
+-/* ------------------------------ */
+-/* - detect HCR errors - */
+-/* ------------------------------ */
+-/* check input data */
+-
+-/* during decoding */
+-
+-/* all the segments are checked -- therefore -- if this check passes, its a kind
+- of evidence that the decoded PCWs and non-PCWs are fine */
+-
+-/* if a codeword is decoded there exists a border for the number of bits, which
+- are allowed to read for this codeword. This border is the minimum of the
+- length of the longest codeword (for the currently used codebook) and the
+- separately transmitted 'lengthOfLongestCodeword' in this frame and channel.
+- The number of decoded bits is counted (for PCWs only -- there it makes really
+- sense in my opinion). If this number exceeds the border (derived as minimum
+- -- see above), a error is detected. */
+-
+-/* -----------------------------------------------------------------------------------------------------
+- This error check could be set to zero because due to a test within
+- RVLC-Escape-huffman-Decoder a too long codeword could not be detected -- it
+- seems that for RVLC-Escape-Codeword the coderoom is used to 100%. Therefore I
+- assume that the coderoom is used to 100% also for the codebooks 1..11 used at
+- HCR Therefore this test is deactivated pending further notice
+- -----------------------------------------------------------------------------------------------------
+- */
+-
+-/* test if the number of remaining bits in a segment is _below_ zero. If there
+- are no errors the lowest allowed value for remainingBitsInSegment is zero.
+- This check also could be set to zero (save runtime) */
+-
+-/* other */
+-/* when set to '1', avoid setting the LAV-Flag in errorLog due to a
+- previous-line-marking (at PCW decoder). A little more runtime is needed then
+- when writing values out into output-buffer. */
+-
+-/* ------------------------------ */
+-/* - conceal HCR errors - */
+-/* ------------------------------ */
+-
+-#define HCR_ERROR_CONCEALMENT \
+- 1 /* if set to '1', HCR _mutes_ the erred quantized spectral coefficients */
+-
+-// ------------------------------------------------------------------------------------------------------------------
+-// errorLog: A word of 32 bits used for
+-// logging possible errors within HCR
+-// in case of distorted
+-// bitstreams. Table of all
+-// known errors:
+-// ------------------------------------------------------------------------------------------------------------------------
+-// bit fatal location meaning
+-// ----+-----+-----------+--------------------------------------
+-#define SEGMENT_OVERRIDE_ERR_PCW_BODY \
+- 0x80000000 // 31 no PCW-Dec During PCW decoding it is checked after
+- // every PCW if there are too many bits decoded (immediate
+- // check).
+-#define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN \
+- 0x40000000 // 30 no PCW-Dec During PCW decoding it is checked after
+- // every PCW if there are too many bits decoded (immediate
+- // check).
+-#define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN_ESC \
+- 0x20000000 // 29 no PCW-Dec During PCW decoding it is checked after
+- // every PCW if there are too many bits decoded (immediate
+- // check).
+-#define EXTENDED_SORTED_COUNTER_OVERFLOW \
+- 0x10000000 // 28 yes Init-Dec Error during extending sideinfo
+- // (neither a PCW nor a nonPCW was decoded so far)
+- // 0x08000000 // 27 reserved
+- // 0x04000000 // 26 reserved
+- // 0x02000000 // 25 reserved
+- // 0x01000000 // 24 reserved
+- // 0x00800000 // 23 reserved
+- // 0x00400000 // 22 reserved
+- // 0x00200000 // 21 reserved
+- // 0x00100000 // 20 reserved
+-
+-/* special errors */
+-#define TOO_MANY_PCW_BODY_BITS_DECODED \
+- 0x00080000 // 19 yes PCW-Dec During PCW-body-decoding too many bits
+- // have been read from bitstream -- advice: skip non-PCW decoding
+-#define TOO_MANY_PCW_BODY_SIGN_BITS_DECODED \
+- 0x00040000 // 18 yes PCW-Dec During PCW-body-sign-decoding too many
+- // bits have been read from bitstream -- advice: skip non-PCW
+- // decoding
+-#define TOO_MANY_PCW_BODY_SIGN_ESC_BITS_DECODED \
+- 0x00020000 // 17 yes PCW-Dec During PCW-body-sign-esc-decoding too
+- // many bits have been read from bitstream -- advice: skip
+- // non-PCW decoding
+-
+-// 0x00010000 // 16 reserved
+-#define STATE_ERROR_BODY_ONLY \
+- 0x00008000 // 15 no NonPCW-Dec State machine returned with error
+-#define STATE_ERROR_BODY_SIGN__BODY \
+- 0x00004000 // 14 no NonPCW-Dec State machine returned with error
+-#define STATE_ERROR_BODY_SIGN__SIGN \
+- 0x00002000 // 13 no NonPCW-Dec State machine returned with error
+-#define STATE_ERROR_BODY_SIGN_ESC__BODY \
+- 0x00001000 // 12 no NonPCW-Dec State machine returned with error
+-#define STATE_ERROR_BODY_SIGN_ESC__SIGN \
+- 0x00000800 // 11 no NonPCW-Dec State machine returned with error
+-#define STATE_ERROR_BODY_SIGN_ESC__ESC_PREFIX \
+- 0x00000400 // 10 no NonPCW-Dec State machine returned with error
+-#define STATE_ERROR_BODY_SIGN_ESC__ESC_WORD \
+- 0x00000200 // 9 no NonPCW-Dec State machine returned with error
+-#define HCR_SI_LENGTHS_FAILURE \
+- 0x00000100 // 8 yes Init-Dec LengthOfLongestCodeword must not be
+- // less than lenghtOfReorderedSpectralData
+-#define NUM_SECT_OUT_OF_RANGE_SHORT_BLOCK \
+- 0x00000080 // 7 yes Init-Dec The number of sections is not within
+- // the allowed range (short block)
+-#define NUM_SECT_OUT_OF_RANGE_LONG_BLOCK \
+- 0x00000040 // 6 yes Init-Dec The number of sections is not within
+- // the allowed range (long block)
+-#define LINE_IN_SECT_OUT_OF_RANGE_SHORT_BLOCK \
+- 0x00000020 // 5 yes Init-Dec The number of lines per section is not
+- // within the allowed range (short block)
+-#define CB_OUT_OF_RANGE_SHORT_BLOCK \
+- 0x00000010 // 4 yes Init-Dec The codebook is not within the allowed
+- // range (short block)
+-#define LINE_IN_SECT_OUT_OF_RANGE_LONG_BLOCK \
+- 0x00000008 // 3 yes Init-Dec The number of lines per section is not
+- // within the allowed range (long block)
+-#define CB_OUT_OF_RANGE_LONG_BLOCK \
+- 0x00000004 // 2 yes Init-Dec The codebook is not within the allowed
+- // range (long block)
+-#define LAV_VIOLATION \
+- 0x00000002 // 1 no Final The absolute value of at least one
+- // decoded line was too high for the according codebook.
+-#define BIT_IN_SEGMENTATION_ERROR \
+- 0x00000001 // 0 no Final After PCW and non-PWC-decoding at least
+- // one segment is not zero (global check).
+-
+-/*----------*/
+-#define HCR_FATAL_PCW_ERROR_MASK 0x100E01FC
+-
+-typedef enum { PCW_BODY, PCW_BODY_SIGN, PCW_BODY_SIGN_ESC } PCW_TYPE;
+-
+-/* interface Decoder <---> HCR */
+-typedef struct {
+- UINT errorLog;
+- SPECTRAL_PTR pQuantizedSpectralCoefficientsBase;
+- int quantizedSpectralCoefficientsIdx;
+- SHORT lengthOfReorderedSpectralData;
+- SHORT numSection;
+- SHORT *pNumLineInSect;
+- INT bitstreamAnchor;
+- SCHAR lengthOfLongestCodeword;
+- UCHAR *pCodebook;
+-} HCR_INPUT_OUTPUT;
+-
+-typedef struct {
+- const UCHAR *pMinOfCbPair;
+- const UCHAR *pMaxOfCbPair;
+-} HCR_CB_PAIRS;
+-
+-typedef struct {
+- const USHORT *pLargestAbsVal;
+- const UCHAR *pMaxCwLength;
+- const UCHAR *pCbDimension;
+- const UCHAR *pCbDimShift;
+- const UCHAR *pCbSign;
+- const UCHAR *pCbPriority;
+-} HCR_TABLE_INFO;
+-
+-typedef struct {
+- UINT numSegment;
+- UINT pSegmentBitfield[((1024 >> 1) / NUMBER_OF_BIT_IN_WORD + 1)];
+- UINT pCodewordBitfield[((1024 >> 1) / NUMBER_OF_BIT_IN_WORD + 1)];
+- UINT segmentOffset;
+- INT pLeftStartOfSegment[1024 >> 1];
+- INT pRightStartOfSegment[1024 >> 1];
+- SCHAR pRemainingBitsInSegment[1024 >> 1];
+- UCHAR readDirection;
+- UCHAR numWordForBitfield;
+- USHORT pNumBitValidInLastWord;
+-} HCR_SEGMENT_INFO;
+-
+-typedef struct {
+- UINT numCodeword;
+- UINT numSortedSection;
+- USHORT pNumCodewordInSection[MAX_SFB_HCR];
+- USHORT pNumSortedCodewordInSection[MAX_SFB_HCR];
+- USHORT pNumExtendedSortedCodewordInSection[MAX_SFB_HCR + MAX_HCR_SETS];
+- int numExtendedSortedCodewordInSectionIdx;
+- USHORT pNumExtendedSortedSectionsInSets[MAX_HCR_SETS];
+- int numExtendedSortedSectionsInSetsIdx;
+- USHORT pReorderOffset[MAX_SFB_HCR];
+- UCHAR pSortedCodebook[MAX_SFB_HCR];
+-
+- UCHAR pExtendedSortedCodebook[MAX_SFB_HCR + MAX_HCR_SETS];
+- int extendedSortedCodebookIdx;
+- UCHAR pMaxLenOfCbInExtSrtSec[MAX_SFB_HCR + MAX_HCR_SETS];
+- int maxLenOfCbInExtSrtSecIdx;
+- UCHAR pCodebookSwitch[MAX_SFB_HCR];
+-} HCR_SECTION_INFO;
+-
+-typedef UINT (*STATEFUNC)(HANDLE_FDK_BITSTREAM, void *);
+-
+-typedef struct {
+- /* worst-case and 1024/4 non-PCWs exist in worst-case */
+- FIXP_DBL
+- *pResultBase; /* Base address for spectral data output target buffer */
+- UINT iNode[1024 >> 2]; /* Helper indices for code books */
+- USHORT
+- iResultPointer[1024 >> 2]; /* Helper indices for accessing pResultBase */
+- UINT pEscapeSequenceInfo[1024 >> 2];
+- UINT codewordOffset;
+- STATEFUNC pState;
+- UCHAR pCodebook[1024 >> 2];
+- UCHAR pCntSign[1024 >> 2];
+- /* this array holds the states coded as integer values within the range
+- * [0,1,..,7] */
+- SCHAR pSta[1024 >> 2];
+-} HCR_NON_PCW_SIDEINFO;
+-
+-typedef struct {
+- HCR_INPUT_OUTPUT decInOut;
+- HCR_SEGMENT_INFO segmentInfo;
+- HCR_SECTION_INFO sectionInfo;
+- HCR_NON_PCW_SIDEINFO nonPcwSideinfo;
+-} CErHcrInfo;
+-
+-typedef CErHcrInfo *H_HCR_INFO;
+-
+-#endif /* AACDEC_HCR_TYPES_H */
+diff --git a/libAACdec/src/aacdec_hcrs.cpp b/libAACdec/src/aacdec_hcrs.cpp
+deleted file mode 100644
+index d2bc867..0000000
+--- a/libAACdec/src/aacdec_hcrs.cpp
++++ /dev/null
+@@ -1,1551 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Robert Weidner (DSP Solutions)
+-
+- Description: HCR Decoder: Prepare decoding of non-PCWs, segmentation- and
+- bitfield-handling, HCR-Statemachine
+-
+-*******************************************************************************/
+-
+-#include "aacdec_hcrs.h"
+-
+-#include "aacdec_hcr.h"
+-
+-#include "aacdec_hcr_bit.h"
+-#include "aac_rom.h"
+-#include "aac_ram.h"
+-
+-static UINT InitSegmentBitfield(UINT *pNumSegment,
+- SCHAR *pRemainingBitsInSegment,
+- UINT *pSegmentBitfield,
+- UCHAR *pNumWordForBitfield,
+- USHORT *pNumBitValidInLastWord);
+-
+-static void InitNonPCWSideInformationForCurrentSet(H_HCR_INFO pHcr);
+-
+-static INT ModuloValue(INT input, INT bufferlength);
+-
+-static void ClearBitFromBitfield(STATEFUNC *ptrState, UINT offset,
+- UINT *pBitfield);
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function decodes all non-priority codewords (non-PCWs) by
+-using a state-machine.
+---------------------------------------------------------------------------------------------
+-*/
+-void DecodeNonPCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) {
+- UINT numValidSegment;
+- INT segmentOffset;
+- INT codewordOffsetBase;
+- INT codewordOffset;
+- UINT trial;
+-
+- UINT *pNumSegment;
+- SCHAR *pRemainingBitsInSegment;
+- UINT *pSegmentBitfield;
+- UCHAR *pNumWordForBitfield;
+- USHORT *pNumBitValidInLastWord;
+- UINT *pCodewordBitfield;
+- INT bitfieldWord;
+- INT bitInWord;
+- UINT tempWord;
+- UINT interMediateWord;
+- INT tempBit;
+- INT carry;
+-
+- UINT numCodeword;
+- UCHAR numSet;
+- UCHAR currentSet;
+- UINT codewordInSet;
+- UINT remainingCodewordsInSet;
+- SCHAR *pSta;
+- UINT ret;
+-
+- pNumSegment = &(pHcr->segmentInfo.numSegment);
+- pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
+- pNumWordForBitfield = &(pHcr->segmentInfo.numWordForBitfield);
+- pNumBitValidInLastWord = &(pHcr->segmentInfo.pNumBitValidInLastWord);
+- pSta = pHcr->nonPcwSideinfo.pSta;
+-
+- numValidSegment = InitSegmentBitfield(pNumSegment, pRemainingBitsInSegment,
+- pSegmentBitfield, pNumWordForBitfield,
+- pNumBitValidInLastWord);
+-
+- if (numValidSegment != 0) {
+- numCodeword = pHcr->sectionInfo.numCodeword;
+- numSet = ((numCodeword - 1) / *pNumSegment) + 1;
+-
+- pHcr->segmentInfo.readDirection = FROM_RIGHT_TO_LEFT;
+-
+- /* Process sets subsequently */
+- for (currentSet = 1; currentSet < numSet; currentSet++) {
+- /* step 1 */
+- numCodeword -=
+- *pNumSegment; /* number of remaining non PCWs [for all sets] */
+- if (numCodeword < *pNumSegment) {
+- codewordInSet = numCodeword; /* for last set */
+- } else {
+- codewordInSet = *pNumSegment; /* for all sets except last set */
+- }
+-
+- /* step 2 */
+- /* prepare array 'CodewordBitfield'; as much ones are written from left in
+- * all words, as much decodedCodewordInSetCounter nonPCWs exist in this
+- * set */
+- tempWord = 0xFFFFFFFF;
+- pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
+-
+- for (bitfieldWord = *pNumWordForBitfield; bitfieldWord != 0;
+- bitfieldWord--) { /* loop over all used words */
+- if (codewordInSet > NUMBER_OF_BIT_IN_WORD) { /* more codewords than
+- number of bits => fill
+- ones */
+- /* fill a whole word with ones */
+- *pCodewordBitfield++ = tempWord;
+- codewordInSet -= NUMBER_OF_BIT_IN_WORD; /* subtract number of bits */
+- } else {
+- /* prepare last tempWord */
+- for (remainingCodewordsInSet = codewordInSet;
+- remainingCodewordsInSet < NUMBER_OF_BIT_IN_WORD;
+- remainingCodewordsInSet++) {
+- tempWord =
+- tempWord &
+- ~(1
+- << (NUMBER_OF_BIT_IN_WORD - 1 -
+- remainingCodewordsInSet)); /* set a zero at bit number
+- (NUMBER_OF_BIT_IN_WORD-1-i)
+- in tempWord */
+- }
+- *pCodewordBitfield++ = tempWord;
+- tempWord = 0x00000000;
+- }
+- }
+- pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
+-
+- /* step 3 */
+- /* build non-PCW sideinfo for each non-PCW of the current set */
+- InitNonPCWSideInformationForCurrentSet(pHcr);
+-
+- /* step 4 */
+- /* decode all non-PCWs belonging to this set */
+-
+- /* loop over trials */
+- codewordOffsetBase = 0;
+- for (trial = *pNumSegment; trial > 0; trial--) {
+- /* loop over number of words in bitfields */
+- segmentOffset = 0; /* start at zero in every segment */
+- pHcr->segmentInfo.segmentOffset =
+- segmentOffset; /* store in structure for states */
+- codewordOffset = codewordOffsetBase;
+- pHcr->nonPcwSideinfo.codewordOffset =
+- codewordOffset; /* store in structure for states */
+-
+- for (bitfieldWord = 0; bitfieldWord < *pNumWordForBitfield;
+- bitfieldWord++) {
+- /* derive tempWord with bitwise and */
+- tempWord =
+- pSegmentBitfield[bitfieldWord] & pCodewordBitfield[bitfieldWord];
+-
+- /* if tempWord is not zero, decode something */
+- if (tempWord != 0) {
+- /* loop over all bits in tempWord; start state machine if & is true
+- */
+- for (bitInWord = NUMBER_OF_BIT_IN_WORD; bitInWord > 0;
+- bitInWord--) {
+- interMediateWord = ((UINT)1 << (bitInWord - 1));
+- if ((tempWord & interMediateWord) == interMediateWord) {
+- /* get state and start state machine */
+- pHcr->nonPcwSideinfo.pState =
+- aStateConstant2State[pSta[codewordOffset]];
+-
+- while (pHcr->nonPcwSideinfo.pState) {
+- ret = ((STATEFUNC)pHcr->nonPcwSideinfo.pState)(bs, pHcr);
+- if (ret != 0) {
+- return;
+- }
+- }
+- }
+-
+- /* update both offsets */
+- segmentOffset += 1; /* add NUMBER_OF_BIT_IN_WORD times one */
+- pHcr->segmentInfo.segmentOffset = segmentOffset;
+- codewordOffset += 1; /* add NUMBER_OF_BIT_IN_WORD times one */
+- codewordOffset =
+- ModuloValue(codewordOffset,
+- *pNumSegment); /* index of the current codeword
+- lies within modulo range */
+- pHcr->nonPcwSideinfo.codewordOffset = codewordOffset;
+- }
+- } else {
+- segmentOffset +=
+- NUMBER_OF_BIT_IN_WORD; /* add NUMBER_OF_BIT_IN_WORD at once */
+- pHcr->segmentInfo.segmentOffset = segmentOffset;
+- codewordOffset +=
+- NUMBER_OF_BIT_IN_WORD; /* add NUMBER_OF_BIT_IN_WORD at once */
+- codewordOffset = ModuloValue(
+- codewordOffset,
+- *pNumSegment); /* index of the current codeword lies within
+- modulo range */
+- pHcr->nonPcwSideinfo.codewordOffset = codewordOffset;
+- }
+- } /* end of bitfield word loop */
+-
+- /* decrement codeword - pointer */
+- codewordOffsetBase -= 1;
+- codewordOffsetBase =
+- ModuloValue(codewordOffsetBase, *pNumSegment); /* index of the
+- current codeword
+- base lies within
+- modulo range */
+-
+- /* rotate numSegment bits in codewordBitfield */
+- /* rotation of *numSegment bits in bitfield of codewords
+- * (circle-rotation) */
+- /* get last valid bit */
+- tempBit = pCodewordBitfield[*pNumWordForBitfield - 1] &
+- (1 << (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord));
+- tempBit = tempBit >> (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord);
+-
+- /* write zero into place where tempBit was fetched from */
+- pCodewordBitfield[*pNumWordForBitfield - 1] =
+- pCodewordBitfield[*pNumWordForBitfield - 1] &
+- ~(1 << (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord));
+-
+- /* rotate last valid word */
+- pCodewordBitfield[*pNumWordForBitfield - 1] =
+- pCodewordBitfield[*pNumWordForBitfield - 1] >> 1;
+-
+- /* transfare carry bit 0 from current word into bitposition 31 from next
+- * word and rotate current word */
+- for (bitfieldWord = *pNumWordForBitfield - 2; bitfieldWord > -1;
+- bitfieldWord--) {
+- /* get carry (=bit at position 0) from current word */
+- carry = pCodewordBitfield[bitfieldWord] & 1;
+-
+- /* put the carry bit at position 31 into word right from current word
+- */
+- pCodewordBitfield[bitfieldWord + 1] =
+- pCodewordBitfield[bitfieldWord + 1] |
+- (carry << (NUMBER_OF_BIT_IN_WORD - 1));
+-
+- /* shift current word */
+- pCodewordBitfield[bitfieldWord] =
+- pCodewordBitfield[bitfieldWord] >> 1;
+- }
+-
+- /* put tempBit into free bit-position 31 from first word */
+- pCodewordBitfield[0] =
+- pCodewordBitfield[0] | (tempBit << (NUMBER_OF_BIT_IN_WORD - 1));
+-
+- } /* end of trial loop */
+-
+- /* toggle read direction */
+- pHcr->segmentInfo.readDirection =
+- ToggleReadDirection(pHcr->segmentInfo.readDirection);
+- }
+- /* end of set loop */
+-
+- /* all non-PCWs of this spectrum are decoded */
+- }
+-
+- /* all PCWs and all non PCWs are decoded. They are unbacksorted in output
+- * buffer. Here is the Interface with comparing QSCs to asm decoding */
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function prepares the bitfield used for the
+- segments. The list is set up once to be used in all
+-following sets. If a segment is decoded empty, the according bit from the
+-Bitfield is removed.
+------------------------------------------------------------------------------------------------
+- return: numValidSegment = the number of valid segments
+---------------------------------------------------------------------------------------------
+-*/
+-static UINT InitSegmentBitfield(UINT *pNumSegment,
+- SCHAR *pRemainingBitsInSegment,
+- UINT *pSegmentBitfield,
+- UCHAR *pNumWordForBitfield,
+- USHORT *pNumBitValidInLastWord) {
+- SHORT i;
+- USHORT r;
+- UCHAR bitfieldWord;
+- UINT tempWord;
+- USHORT numValidSegment;
+-
+- *pNumWordForBitfield =
+- (*pNumSegment == 0)
+- ? 0
+- : ((*pNumSegment - 1) >> THIRTYTWO_LOG_DIV_TWO_LOG) + 1;
+-
+- /* loop over all words, which are completely used or only partial */
+- /* bit in pSegmentBitfield is zero if segment is empty; bit in
+- * pSegmentBitfield is one if segment is not empty */
+- numValidSegment = 0;
+- *pNumBitValidInLastWord = *pNumSegment;
+-
+- /* loop over words */
+- for (bitfieldWord = 0; bitfieldWord < *pNumWordForBitfield - 1;
+- bitfieldWord++) {
+- tempWord = 0xFFFFFFFF; /* set ones */
+- r = bitfieldWord << THIRTYTWO_LOG_DIV_TWO_LOG;
+- for (i = 0; i < NUMBER_OF_BIT_IN_WORD; i++) {
+- if (pRemainingBitsInSegment[r + i] == 0) {
+- tempWord = tempWord & ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 -
+- i)); /* set a zero at bit number
+- (NUMBER_OF_BIT_IN_WORD-1-i) in
+- tempWord */
+- } else {
+- numValidSegment += 1; /* count segments which are not empty */
+- }
+- }
+- pSegmentBitfield[bitfieldWord] = tempWord; /* store result */
+- *pNumBitValidInLastWord -= NUMBER_OF_BIT_IN_WORD; /* calculate number of
+- zeros on LSB side in
+- the last word */
+- }
+-
+- /* calculate last word: prepare special tempWord */
+- tempWord = 0xFFFFFFFF;
+- for (i = 0; i < (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord); i++) {
+- tempWord = tempWord & ~(1 << i); /* clear bit i in tempWord */
+- }
+-
+- /* calculate last word */
+- r = bitfieldWord << THIRTYTWO_LOG_DIV_TWO_LOG;
+- for (i = 0; i < *pNumBitValidInLastWord; i++) {
+- if (pRemainingBitsInSegment[r + i] == 0) {
+- tempWord = tempWord & ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 -
+- i)); /* set a zero at bit number
+- (NUMBER_OF_BIT_IN_WORD-1-i) in
+- tempWord */
+- } else {
+- numValidSegment += 1; /* count segments which are not empty */
+- }
+- }
+- pSegmentBitfield[bitfieldWord] = tempWord; /* store result */
+-
+- return numValidSegment;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function sets up sideinfo for the non-PCW decoder (for the
+-current set).
+----------------------------------------------------------------------------------------------*/
+-static void InitNonPCWSideInformationForCurrentSet(H_HCR_INFO pHcr) {
+- USHORT i, k;
+- UCHAR codebookDim;
+- UINT startNode;
+-
+- UCHAR *pCodebook = pHcr->nonPcwSideinfo.pCodebook;
+- UINT *iNode = pHcr->nonPcwSideinfo.iNode;
+- UCHAR *pCntSign = pHcr->nonPcwSideinfo.pCntSign;
+- USHORT *iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
+- UINT *pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
+- SCHAR *pSta = pHcr->nonPcwSideinfo.pSta;
+- USHORT *pNumExtendedSortedCodewordInSection =
+- pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
+- int numExtendedSortedCodewordInSectionIdx =
+- pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
+- UCHAR *pExtendedSortedCodebook = pHcr->sectionInfo.pExtendedSortedCodebook;
+- int extendedSortedCodebookIdx = pHcr->sectionInfo.extendedSortedCodebookIdx;
+- USHORT *pNumExtendedSortedSectionsInSets =
+- pHcr->sectionInfo.pNumExtendedSortedSectionsInSets;
+- int numExtendedSortedSectionsInSetsIdx =
+- pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
+- int quantizedSpectralCoefficientsIdx =
+- pHcr->decInOut.quantizedSpectralCoefficientsIdx;
+- const UCHAR *pCbDimension = aDimCb;
+- int iterationCounter = 0;
+-
+- /* loop over number of extended sorted sections in the current set so all
+- * codewords sideinfo variables within this set can be prepared for decoding
+- */
+- for (i = pNumExtendedSortedSectionsInSets[numExtendedSortedSectionsInSetsIdx];
+- i != 0; i--) {
+- codebookDim =
+- pCbDimension[pExtendedSortedCodebook[extendedSortedCodebookIdx]];
+- startNode = *aHuffTable[pExtendedSortedCodebook[extendedSortedCodebookIdx]];
+-
+- for (k = pNumExtendedSortedCodewordInSection
+- [numExtendedSortedCodewordInSectionIdx];
+- k != 0; k--) {
+- iterationCounter++;
+- if (iterationCounter > (1024 >> 2)) {
+- return;
+- }
+- *pSta++ = aCodebook2StartInt
+- [pExtendedSortedCodebook[extendedSortedCodebookIdx]];
+- *pCodebook++ = pExtendedSortedCodebook[extendedSortedCodebookIdx];
+- *iNode++ = startNode;
+- *pCntSign++ = 0;
+- *iResultPointer++ = quantizedSpectralCoefficientsIdx;
+- *pEscapeSequenceInfo++ = 0;
+- quantizedSpectralCoefficientsIdx +=
+- codebookDim; /* update pointer by codebookDim --> point to next
+- starting value for writing out */
+- if (quantizedSpectralCoefficientsIdx >= 1024) {
+- return;
+- }
+- }
+- numExtendedSortedCodewordInSectionIdx++; /* inc ptr for next ext sort sec in
+- current set */
+- extendedSortedCodebookIdx++; /* inc ptr for next ext sort sec in current set
+- */
+- if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS) ||
+- extendedSortedCodebookIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
+- return;
+- }
+- }
+- numExtendedSortedSectionsInSetsIdx++; /* inc ptr for next set of non-PCWs */
+- if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
+- return;
+- }
+-
+- /* Write back indexes */
+- pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
+- numExtendedSortedCodewordInSectionIdx;
+- pHcr->sectionInfo.extendedSortedCodebookIdx = extendedSortedCodebookIdx;
+- pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx =
+- numExtendedSortedSectionsInSetsIdx;
+- pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
+- numExtendedSortedCodewordInSectionIdx;
+- pHcr->decInOut.quantizedSpectralCoefficientsIdx =
+- quantizedSpectralCoefficientsIdx;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function returns the input value if the value is in the
+- range of bufferlength. If <input> is smaller, one bufferlength
+-is added, if <input> is bigger one bufferlength is subtracted.
+------------------------------------------------------------------------------------------------
+- return: modulo result
+---------------------------------------------------------------------------------------------
+-*/
+-static INT ModuloValue(INT input, INT bufferlength) {
+- if (input > (bufferlength - 1)) {
+- return (input - bufferlength);
+- }
+- if (input < 0) {
+- return (input + bufferlength);
+- }
+- return input;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This function clears a bit from current bitfield and
+- switches off the statemachine.
+-
+- A bit is cleared in two cases:
+- a) a codeword is decoded, then a bit is cleared in codeword
+-bitfield b) a segment is decoded empty, then a bit is cleared in segment
+-bitfield
+---------------------------------------------------------------------------------------------
+-*/
+-static void ClearBitFromBitfield(STATEFUNC *ptrState, UINT offset,
+- UINT *pBitfield) {
+- UINT numBitfieldWord;
+- UINT numBitfieldBit;
+-
+- /* get both values needed for clearing the bit */
+- numBitfieldWord = offset >> THIRTYTWO_LOG_DIV_TWO_LOG; /* int = wordNr */
+- numBitfieldBit = offset - (numBitfieldWord
+- << THIRTYTWO_LOG_DIV_TWO_LOG); /* fract = bitNr */
+-
+- /* clear a bit in bitfield */
+- pBitfield[numBitfieldWord] =
+- pBitfield[numBitfieldWord] &
+- ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 - numBitfieldBit));
+-
+- /* switch off state machine because codeword is decoded and/or because segment
+- * is empty */
+- *ptrState = NULL;
+-}
+-
+-/* =========================================================================================
+- the states of the statemachine
+- =========================================================================================
+- */
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Decodes the body of a codeword. This State is used for
+-codebooks 1,2,5 and 6. No sign bits are decoded, because the table of the
+-quantized spectral values has got a valid sign at the quantized spectral lines.
+------------------------------------------------------------------------------------------------
+- output: Two or four quantizes spectral values written at position
+-where pResultPointr points to
+------------------------------------------------------------------------------------------------
+- return: 0
+---------------------------------------------------------------------------------------------
+-*/
+-UINT Hcr_State_BODY_ONLY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
+- H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
+- UINT *pSegmentBitfield;
+- UINT *pCodewordBitfield;
+- UINT segmentOffset;
+- FIXP_DBL *pResultBase;
+- UINT *iNode;
+- USHORT *iResultPointer;
+- UINT codewordOffset;
+- UINT branchNode;
+- UINT branchValue;
+- UINT iQSC;
+- UINT treeNode;
+- UCHAR carryBit;
+- INT *pLeftStartOfSegment;
+- INT *pRightStartOfSegment;
+- SCHAR *pRemainingBitsInSegment;
+- UCHAR readDirection;
+- UCHAR *pCodebook;
+- UCHAR dimCntr;
+- const UINT *pCurrentTree;
+- const UCHAR *pCbDimension;
+- const SCHAR *pQuantVal;
+- const SCHAR *pQuantValBase;
+-
+- pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
+- readDirection = pHcr->segmentInfo.readDirection;
+- pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
+- pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
+- segmentOffset = pHcr->segmentInfo.segmentOffset;
+-
+- pCodebook = pHcr->nonPcwSideinfo.pCodebook;
+- iNode = pHcr->nonPcwSideinfo.iNode;
+- pResultBase = pHcr->nonPcwSideinfo.pResultBase;
+- iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
+- codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
+-
+- pCbDimension = aDimCb;
+-
+- treeNode = iNode[codewordOffset];
+- pCurrentTree = aHuffTable[pCodebook[codewordOffset]];
+-
+- for (; pRemainingBitsInSegment[segmentOffset] > 0;
+- pRemainingBitsInSegment[segmentOffset] -= 1) {
+- carryBit = HcrGetABitFromBitstream(
+- bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
+- &pRightStartOfSegment[segmentOffset], readDirection);
+-
+- CarryBitToBranchValue(carryBit, /* make a step in decoding tree */
+- treeNode, &branchValue, &branchNode);
+-
+- /* if end of branch reached write out lines and count bits needed for sign,
+- * otherwise store node in codeword sideinfo */
+- if ((branchNode & TEST_BIT_10) ==
+- TEST_BIT_10) { /* test bit 10 ; ==> body is complete */
+- pQuantValBase = aQuantTable[pCodebook[codewordOffset]]; /* get base
+- address of
+- quantized
+- values
+- belonging to
+- current
+- codebook */
+- pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
+- line [of 2 or 4 quantized
+- values] */
+-
+- iQSC = iResultPointer[codewordOffset]; /* get position of first line for
+- writing out result */
+-
+- for (dimCntr = pCbDimension[pCodebook[codewordOffset]]; dimCntr != 0;
+- dimCntr--) {
+- pResultBase[iQSC++] =
+- (FIXP_DBL)*pQuantVal++; /* write out 2 or 4 lines into
+- spectrum; no Sign bits
+- available in this state */
+- }
+-
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pCodewordBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+- pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
+- for loop counter (see
+- above) is done here */
+- break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
+- decoded */
+- } else { /* body is not decoded completely: */
+- treeNode = *(
+- pCurrentTree +
+- branchValue); /* update treeNode for further step in decoding tree */
+- }
+- }
+- iNode[codewordOffset] = treeNode; /* store updated treeNode because maybe
+- decoding of codeword body not finished
+- yet */
+-
+- if (pRemainingBitsInSegment[segmentOffset] <= 0) {
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pSegmentBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+-
+- if (pRemainingBitsInSegment[segmentOffset] < 0) {
+- pHcr->decInOut.errorLog |= STATE_ERROR_BODY_ONLY;
+- return BODY_ONLY;
+- }
+- }
+-
+- return STOP_THIS_STATE;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Decodes the codeword body, writes out result and counts the
+-number of quantized spectral values, which are different form zero. For those
+-values sign bits are needed.
+-
+- If sign bit counter cntSign is different from zero, switch to
+-next state to decode sign Bits there. If sign bit counter cntSign is zero, no
+-sign bits are needed and codeword is decoded.
+------------------------------------------------------------------------------------------------
+- output: Two or four written quantizes spectral values written at
+-position where pResultPointr points to. The signs of those lines may be wrong.
+-If the signs [on just one signle sign] is wrong, the next state will correct it.
+------------------------------------------------------------------------------------------------
+- return: 0
+---------------------------------------------------------------------------------------------
+-*/
+-UINT Hcr_State_BODY_SIGN__BODY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
+- H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
+- SCHAR *pRemainingBitsInSegment;
+- INT *pLeftStartOfSegment;
+- INT *pRightStartOfSegment;
+- UCHAR readDirection;
+- UINT *pSegmentBitfield;
+- UINT *pCodewordBitfield;
+- UINT segmentOffset;
+-
+- UCHAR *pCodebook;
+- UINT *iNode;
+- UCHAR *pCntSign;
+- FIXP_DBL *pResultBase;
+- USHORT *iResultPointer;
+- UINT codewordOffset;
+-
+- UINT iQSC;
+- UINT cntSign;
+- UCHAR dimCntr;
+- UCHAR carryBit;
+- SCHAR *pSta;
+- UINT treeNode;
+- UINT branchValue;
+- UINT branchNode;
+- const UCHAR *pCbDimension;
+- const UINT *pCurrentTree;
+- const SCHAR *pQuantValBase;
+- const SCHAR *pQuantVal;
+-
+- pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
+- readDirection = pHcr->segmentInfo.readDirection;
+- pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
+- pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
+- segmentOffset = pHcr->segmentInfo.segmentOffset;
+-
+- pCodebook = pHcr->nonPcwSideinfo.pCodebook;
+- iNode = pHcr->nonPcwSideinfo.iNode;
+- pCntSign = pHcr->nonPcwSideinfo.pCntSign;
+- pResultBase = pHcr->nonPcwSideinfo.pResultBase;
+- iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
+- codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
+- pSta = pHcr->nonPcwSideinfo.pSta;
+-
+- pCbDimension = aDimCb;
+-
+- treeNode = iNode[codewordOffset];
+- pCurrentTree = aHuffTable[pCodebook[codewordOffset]];
+-
+- for (; pRemainingBitsInSegment[segmentOffset] > 0;
+- pRemainingBitsInSegment[segmentOffset] -= 1) {
+- carryBit = HcrGetABitFromBitstream(
+- bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
+- &pRightStartOfSegment[segmentOffset], readDirection);
+-
+- CarryBitToBranchValue(carryBit, /* make a step in decoding tree */
+- treeNode, &branchValue, &branchNode);
+-
+- /* if end of branch reached write out lines and count bits needed for sign,
+- * otherwise store node in codeword sideinfo */
+- if ((branchNode & TEST_BIT_10) ==
+- TEST_BIT_10) { /* test bit 10 ; if set body complete */
+- /* body completely decoded; branchValue is valid, set pQuantVal to first
+- * (of two or four) quantized spectral coefficients */
+- pQuantValBase = aQuantTable[pCodebook[codewordOffset]]; /* get base
+- address of
+- quantized
+- values
+- belonging to
+- current
+- codebook */
+- pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
+- line [of 2 or 4 quantized
+- values] */
+-
+- iQSC = iResultPointer[codewordOffset]; /* get position of first line for
+- writing result */
+-
+- /* codeword decoding result is written out here: Write out 2 or 4
+- * quantized spectral values with probably */
+- /* wrong sign and count number of values which are different from zero for
+- * sign bit decoding [which happens in next state] */
+- cntSign = 0;
+- for (dimCntr = pCbDimension[pCodebook[codewordOffset]]; dimCntr != 0;
+- dimCntr--) {
+- pResultBase[iQSC++] =
+- (FIXP_DBL)*pQuantVal; /* write quant. spec. coef. into spectrum */
+- if (*pQuantVal++ != 0) {
+- cntSign += 1;
+- }
+- }
+-
+- if (cntSign == 0) {
+- ClearBitFromBitfield(
+- &(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pCodewordBitfield); /* clear a bit in bitfield and switch off
+- statemachine */
+- } else {
+- pCntSign[codewordOffset] = cntSign; /* write sign count result into
+- codewordsideinfo of current
+- codeword */
+- pSta[codewordOffset] = BODY_SIGN__SIGN; /* change state */
+- pHcr->nonPcwSideinfo.pState =
+- aStateConstant2State[pSta[codewordOffset]]; /* get state from
+- separate array of
+- cw-sideinfo */
+- }
+- pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
+- for loop counter (see
+- above) is done here */
+- break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
+- decoded */
+- } else { /* body is not decoded completely: */
+- treeNode = *(
+- pCurrentTree +
+- branchValue); /* update treeNode for further step in decoding tree */
+- }
+- }
+- iNode[codewordOffset] = treeNode; /* store updated treeNode because maybe
+- decoding of codeword body not finished
+- yet */
+-
+- if (pRemainingBitsInSegment[segmentOffset] <= 0) {
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pSegmentBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+-
+- if (pRemainingBitsInSegment[segmentOffset] < 0) {
+- pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN__BODY;
+- return BODY_SIGN__BODY;
+- }
+- }
+-
+- return STOP_THIS_STATE;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This state decodes the sign bits belonging to a codeword. The
+-state is called as often in different "trials" until pCntSgn[codewordOffset] is
+-zero.
+------------------------------------------------------------------------------------------------
+- output: The two or four quantizes spectral values (written in previous
+-state) have now the correct sign.
+------------------------------------------------------------------------------------------------
+- return: 0
+---------------------------------------------------------------------------------------------
+-*/
+-UINT Hcr_State_BODY_SIGN__SIGN(HANDLE_FDK_BITSTREAM bs, void *ptr) {
+- H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
+- SCHAR *pRemainingBitsInSegment;
+- INT *pLeftStartOfSegment;
+- INT *pRightStartOfSegment;
+- UCHAR readDirection;
+- UINT *pSegmentBitfield;
+- UINT *pCodewordBitfield;
+- UINT segmentOffset;
+-
+- UCHAR *pCntSign;
+- FIXP_DBL *pResultBase;
+- USHORT *iResultPointer;
+- UINT codewordOffset;
+-
+- UCHAR carryBit;
+- UINT iQSC;
+- UCHAR cntSign;
+-
+- pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
+- readDirection = pHcr->segmentInfo.readDirection;
+- pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
+- pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
+- segmentOffset = pHcr->segmentInfo.segmentOffset;
+-
+- /*pCodebook = */
+- pCntSign = pHcr->nonPcwSideinfo.pCntSign;
+- pResultBase = pHcr->nonPcwSideinfo.pResultBase;
+- iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
+- codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
+-
+- iQSC = iResultPointer[codewordOffset];
+- cntSign = pCntSign[codewordOffset];
+-
+- /* loop for sign bit decoding */
+- for (; pRemainingBitsInSegment[segmentOffset] > 0;
+- pRemainingBitsInSegment[segmentOffset] -= 1) {
+- carryBit = HcrGetABitFromBitstream(
+- bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
+- &pRightStartOfSegment[segmentOffset], readDirection);
+- cntSign -=
+- 1; /* decrement sign counter because one sign bit has been read */
+-
+- /* search for a line (which was decoded in previous state) which is not
+- * zero. [This value will get a sign] */
+- while (pResultBase[iQSC] == (FIXP_DBL)0) {
+- if (++iQSC >= 1024) { /* points to current value different from zero */
+- return BODY_SIGN__SIGN;
+- }
+- }
+-
+- /* put sign together with line; if carryBit is zero, the sign is ok already;
+- * no write operation necessary in this case */
+- if (carryBit != 0) {
+- pResultBase[iQSC] = -pResultBase[iQSC]; /* carryBit = 1 --> minus */
+- }
+-
+- iQSC++; /* update pointer to next (maybe valid) value */
+-
+- if (cntSign == 0) { /* if (cntSign==0) ==> set state CODEWORD_DECODED */
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pCodewordBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+- pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
+- for loop counter (see
+- above) is done here */
+- break; /* whole nonPCW-Body and according sign bits are decoded */
+- }
+- }
+- pCntSign[codewordOffset] = cntSign;
+- iResultPointer[codewordOffset] = iQSC; /* store updated pResultPointer */
+-
+- if (pRemainingBitsInSegment[segmentOffset] <= 0) {
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pSegmentBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+-
+- if (pRemainingBitsInSegment[segmentOffset] < 0) {
+- pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN__SIGN;
+- return BODY_SIGN__SIGN;
+- }
+- }
+-
+- return STOP_THIS_STATE;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Decodes the codeword body in case of codebook is 11. Writes
+-out resulting two or four lines [with probably wrong sign] and counts the number
+-of lines, which are different form zero. This information is needed in next
+- state where sign bits will be decoded, if necessary.
+- If sign bit counter cntSign is zero, no sign bits are needed
+-and codeword is decoded completely.
+------------------------------------------------------------------------------------------------
+- output: Two lines (quantizes spectral coefficients) which are probably
+-wrong. The sign may be wrong and if one or two values is/are 16, the following
+-states will decode the escape sequence to correct the values which are wirtten
+-here.
+------------------------------------------------------------------------------------------------
+- return: 0
+---------------------------------------------------------------------------------------------
+-*/
+-UINT Hcr_State_BODY_SIGN_ESC__BODY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
+- H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
+- SCHAR *pRemainingBitsInSegment;
+- INT *pLeftStartOfSegment;
+- INT *pRightStartOfSegment;
+- UCHAR readDirection;
+- UINT *pSegmentBitfield;
+- UINT *pCodewordBitfield;
+- UINT segmentOffset;
+-
+- UINT *iNode;
+- UCHAR *pCntSign;
+- FIXP_DBL *pResultBase;
+- USHORT *iResultPointer;
+- UINT codewordOffset;
+-
+- UCHAR carryBit;
+- UINT iQSC;
+- UINT cntSign;
+- UINT dimCntr;
+- UINT treeNode;
+- SCHAR *pSta;
+- UINT branchNode;
+- UINT branchValue;
+- const UINT *pCurrentTree;
+- const SCHAR *pQuantValBase;
+- const SCHAR *pQuantVal;
+-
+- pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
+- readDirection = pHcr->segmentInfo.readDirection;
+- pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
+- pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
+- segmentOffset = pHcr->segmentInfo.segmentOffset;
+-
+- iNode = pHcr->nonPcwSideinfo.iNode;
+- pCntSign = pHcr->nonPcwSideinfo.pCntSign;
+- pResultBase = pHcr->nonPcwSideinfo.pResultBase;
+- iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
+- codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
+- pSta = pHcr->nonPcwSideinfo.pSta;
+-
+- treeNode = iNode[codewordOffset];
+- pCurrentTree = aHuffTable[ESCAPE_CODEBOOK];
+-
+- for (; pRemainingBitsInSegment[segmentOffset] > 0;
+- pRemainingBitsInSegment[segmentOffset] -= 1) {
+- carryBit = HcrGetABitFromBitstream(
+- bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
+- &pRightStartOfSegment[segmentOffset], readDirection);
+-
+- /* make a step in tree */
+- CarryBitToBranchValue(carryBit, treeNode, &branchValue, &branchNode);
+-
+- /* if end of branch reached write out lines and count bits needed for sign,
+- * otherwise store node in codeword sideinfo */
+- if ((branchNode & TEST_BIT_10) ==
+- TEST_BIT_10) { /* test bit 10 ; if set body complete */
+-
+- /* body completely decoded; branchValue is valid */
+- /* set pQuantVol to first (of two or four) quantized spectral coefficients
+- */
+- pQuantValBase = aQuantTable[ESCAPE_CODEBOOK]; /* get base address of
+- quantized values
+- belonging to current
+- codebook */
+- pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
+- line [of 2 or 4 quantized
+- values] */
+-
+- /* make backup from original resultPointer in node storage for state
+- * BODY_SIGN_ESC__SIGN */
+- iNode[codewordOffset] = iResultPointer[codewordOffset];
+-
+- /* get position of first line for writing result */
+- iQSC = iResultPointer[codewordOffset];
+-
+- /* codeword decoding result is written out here: Write out 2 or 4
+- * quantized spectral values with probably */
+- /* wrong sign and count number of values which are different from zero for
+- * sign bit decoding [which happens in next state] */
+- cntSign = 0;
+-
+- for (dimCntr = DIMENSION_OF_ESCAPE_CODEBOOK; dimCntr != 0; dimCntr--) {
+- pResultBase[iQSC++] =
+- (FIXP_DBL)*pQuantVal; /* write quant. spec. coef. into spectrum */
+- if (*pQuantVal++ != 0) {
+- cntSign += 1;
+- }
+- }
+-
+- if (cntSign == 0) {
+- ClearBitFromBitfield(
+- &(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pCodewordBitfield); /* clear a bit in bitfield and switch off
+- statemachine */
+- /* codeword decoded */
+- } else {
+- /* write sign count result into codewordsideinfo of current codeword */
+- pCntSign[codewordOffset] = cntSign;
+- pSta[codewordOffset] = BODY_SIGN_ESC__SIGN; /* change state */
+- pHcr->nonPcwSideinfo.pState =
+- aStateConstant2State[pSta[codewordOffset]]; /* get state from
+- separate array of
+- cw-sideinfo */
+- }
+- pRemainingBitsInSegment[segmentOffset] -= 1; /* the last reinitialzation
+- of for loop counter (see
+- above) is done here */
+- break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
+- decoded */
+- } else { /* body is not decoded completely: */
+- /* update treeNode for further step in decoding tree and store updated
+- * treeNode because maybe no more bits left in segment */
+- treeNode = *(pCurrentTree + branchValue);
+- iNode[codewordOffset] = treeNode;
+- }
+- }
+-
+- if (pRemainingBitsInSegment[segmentOffset] <= 0) {
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pSegmentBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+-
+- if (pRemainingBitsInSegment[segmentOffset] < 0) {
+- pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__BODY;
+- return BODY_SIGN_ESC__BODY;
+- }
+- }
+-
+- return STOP_THIS_STATE;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: This state decodes the sign bits, if a codeword of codebook 11
+-needs some. A flag named 'flagB' in codeword sideinfo is set, if the second line
+-of quantized spectral values is 16. The 'flagB' is used in case of decoding of a
+-escape sequence is necessary as far as the second line is concerned.
+-
+- If only the first line needs an escape sequence, the flagB is
+-cleared. If only the second line needs an escape sequence, the flagB is not
+-used.
+-
+- For storing sideinfo in case of escape sequence decoding one
+-single word can be used for both escape sequences because they are decoded not
+-at the same time:
+-
+-
+- bit 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5
+-4 3 2 1 0
+- ===== == == =========== ===========
+-=================================== ^ ^ ^ ^ ^
+-^ | | | | | | res. flagA flagB
+-escapePrefixUp escapePrefixDown escapeWord
+-
+------------------------------------------------------------------------------------------------
+- output: Two lines with correct sign. If one or two values is/are 16,
+-the lines are not valid, otherwise they are.
+------------------------------------------------------------------------------------------------
+- return: 0
+---------------------------------------------------------------------------------------------
+-*/
+-UINT Hcr_State_BODY_SIGN_ESC__SIGN(HANDLE_FDK_BITSTREAM bs, void *ptr) {
+- H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
+- SCHAR *pRemainingBitsInSegment;
+- INT *pLeftStartOfSegment;
+- INT *pRightStartOfSegment;
+- UCHAR readDirection;
+- UINT *pSegmentBitfield;
+- UINT *pCodewordBitfield;
+- UINT segmentOffset;
+-
+- UINT *iNode;
+- UCHAR *pCntSign;
+- FIXP_DBL *pResultBase;
+- USHORT *iResultPointer;
+- UINT *pEscapeSequenceInfo;
+- UINT codewordOffset;
+-
+- UINT iQSC;
+- UCHAR cntSign;
+- UINT flagA;
+- UINT flagB;
+- UINT flags;
+- UCHAR carryBit;
+- SCHAR *pSta;
+-
+- pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
+- readDirection = pHcr->segmentInfo.readDirection;
+- pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
+- pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
+- segmentOffset = pHcr->segmentInfo.segmentOffset;
+-
+- iNode = pHcr->nonPcwSideinfo.iNode;
+- pCntSign = pHcr->nonPcwSideinfo.pCntSign;
+- pResultBase = pHcr->nonPcwSideinfo.pResultBase;
+- iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
+- pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
+- codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
+- pSta = pHcr->nonPcwSideinfo.pSta;
+-
+- iQSC = iResultPointer[codewordOffset];
+- cntSign = pCntSign[codewordOffset];
+-
+- /* loop for sign bit decoding */
+- for (; pRemainingBitsInSegment[segmentOffset] > 0;
+- pRemainingBitsInSegment[segmentOffset] -= 1) {
+- carryBit = HcrGetABitFromBitstream(
+- bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
+- &pRightStartOfSegment[segmentOffset], readDirection);
+-
+- /* decrement sign counter because one sign bit has been read */
+- cntSign -= 1;
+- pCntSign[codewordOffset] = cntSign;
+-
+- /* get a quantized spectral value (which was decoded in previous state)
+- * which is not zero. [This value will get a sign] */
+- while (pResultBase[iQSC] == (FIXP_DBL)0) {
+- if (++iQSC >= 1024) {
+- return BODY_SIGN_ESC__SIGN;
+- }
+- }
+- iResultPointer[codewordOffset] = iQSC;
+-
+- /* put negative sign together with quantized spectral value; if carryBit is
+- * zero, the sign is ok already; no write operation necessary in this case
+- */
+- if (carryBit != 0) {
+- pResultBase[iQSC] = -pResultBase[iQSC]; /* carryBit = 1 --> minus */
+- }
+- iQSC++; /* update index to next (maybe valid) value */
+- iResultPointer[codewordOffset] = iQSC;
+-
+- if (cntSign == 0) {
+- /* all sign bits are decoded now */
+- pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
+- for loop counter (see
+- above) is done here */
+-
+- /* check decoded values if codeword is decoded: Check if one or two escape
+- * sequences 16 follow */
+-
+- /* step 0 */
+- /* restore pointer to first decoded quantized value [ = original
+- * pResultPointr] from index iNode prepared in State_BODY_SIGN_ESC__BODY
+- */
+- iQSC = iNode[codewordOffset];
+-
+- /* step 1 */
+- /* test first value if escape sequence follows */
+- flagA = 0; /* for first possible escape sequence */
+- if (fixp_abs(pResultBase[iQSC++]) == (FIXP_DBL)ESCAPE_VALUE) {
+- flagA = 1;
+- }
+-
+- /* step 2 */
+- /* test second value if escape sequence follows */
+- flagB = 0; /* for second possible escape sequence */
+- if (fixp_abs(pResultBase[iQSC]) == (FIXP_DBL)ESCAPE_VALUE) {
+- flagB = 1;
+- }
+-
+- /* step 3 */
+- /* evaluate flag result and go on if necessary */
+- if (!flagA && !flagB) {
+- ClearBitFromBitfield(
+- &(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pCodewordBitfield); /* clear a bit in bitfield and switch off
+- statemachine */
+- } else {
+- /* at least one of two lines is 16 */
+- /* store both flags at correct positions in non PCW codeword sideinfo
+- * pEscapeSequenceInfo[codewordOffset] */
+- flags = flagA << POSITION_OF_FLAG_A;
+- flags |= (flagB << POSITION_OF_FLAG_B);
+- pEscapeSequenceInfo[codewordOffset] = flags;
+-
+- /* set next state */
+- pSta[codewordOffset] = BODY_SIGN_ESC__ESC_PREFIX;
+- pHcr->nonPcwSideinfo.pState =
+- aStateConstant2State[pSta[codewordOffset]]; /* get state from
+- separate array of
+- cw-sideinfo */
+-
+- /* set result pointer to the first line of the two decoded lines */
+- iResultPointer[codewordOffset] = iNode[codewordOffset];
+-
+- if (!flagA && flagB) {
+- /* update pResultPointr ==> state Stat_BODY_SIGN_ESC__ESC_WORD writes
+- * to correct position. Second value is the one and only escape value
+- */
+- iQSC = iResultPointer[codewordOffset];
+- iQSC++;
+- iResultPointer[codewordOffset] = iQSC;
+- }
+-
+- } /* at least one of two lines is 16 */
+- break; /* nonPCW-Body at cb 11 and according sign bits are decoded */
+-
+- } /* if ( cntSign == 0 ) */
+- } /* loop over remaining Bits in segment */
+-
+- if (pRemainingBitsInSegment[segmentOffset] <= 0) {
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pSegmentBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+-
+- if (pRemainingBitsInSegment[segmentOffset] < 0) {
+- pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__SIGN;
+- return BODY_SIGN_ESC__SIGN;
+- }
+- }
+- return STOP_THIS_STATE;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Decode escape prefix of first or second escape sequence. The
+-escape prefix consists of ones. The following zero is also decoded here.
+------------------------------------------------------------------------------------------------
+- output: If the single separator-zero which follows the
+-escape-prefix-ones is not yet decoded: The value 'escapePrefixUp' in word
+-pEscapeSequenceInfo[codewordOffset] is updated.
+-
+- If the single separator-zero which follows the
+-escape-prefix-ones is decoded: Two updated values 'escapePrefixUp' and
+-'escapePrefixDown' in word pEscapeSequenceInfo[codewordOffset]. This State is
+-finished. Switch to next state.
+------------------------------------------------------------------------------------------------
+- return: 0
+---------------------------------------------------------------------------------------------
+-*/
+-UINT Hcr_State_BODY_SIGN_ESC__ESC_PREFIX(HANDLE_FDK_BITSTREAM bs, void *ptr) {
+- H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
+- SCHAR *pRemainingBitsInSegment;
+- INT *pLeftStartOfSegment;
+- INT *pRightStartOfSegment;
+- UCHAR readDirection;
+- UINT *pSegmentBitfield;
+- UINT segmentOffset;
+- UINT *pEscapeSequenceInfo;
+- UINT codewordOffset;
+- UCHAR carryBit;
+- UINT escapePrefixUp;
+- SCHAR *pSta;
+-
+- pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
+- readDirection = pHcr->segmentInfo.readDirection;
+- pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
+- segmentOffset = pHcr->segmentInfo.segmentOffset;
+- pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
+- codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
+- pSta = pHcr->nonPcwSideinfo.pSta;
+-
+- escapePrefixUp =
+- (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_UP) >>
+- LSB_ESCAPE_PREFIX_UP;
+-
+- /* decode escape prefix */
+- for (; pRemainingBitsInSegment[segmentOffset] > 0;
+- pRemainingBitsInSegment[segmentOffset] -= 1) {
+- carryBit = HcrGetABitFromBitstream(
+- bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
+- &pRightStartOfSegment[segmentOffset], readDirection);
+-
+- /* count ones and store sum in escapePrefixUp */
+- if (carryBit == 1) {
+- escapePrefixUp += 1; /* update conter for ones */
+-
+- /* store updated counter in sideinfo of current codeword */
+- pEscapeSequenceInfo[codewordOffset] &=
+- ~MASK_ESCAPE_PREFIX_UP; /* delete old escapePrefixUp */
+- escapePrefixUp <<= LSB_ESCAPE_PREFIX_UP; /* shift to correct position */
+- pEscapeSequenceInfo[codewordOffset] |=
+- escapePrefixUp; /* insert new escapePrefixUp */
+- escapePrefixUp >>= LSB_ESCAPE_PREFIX_UP; /* shift back down */
+- } else { /* separator [zero] reached */
+- pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
+- for loop counter (see
+- above) is done here */
+- escapePrefixUp +=
+- 4; /* if escape_separator '0' appears, add 4 and ==> break */
+-
+- /* store escapePrefixUp in pEscapeSequenceInfo[codewordOffset] at bit
+- * position escapePrefixUp */
+- pEscapeSequenceInfo[codewordOffset] &=
+- ~MASK_ESCAPE_PREFIX_UP; /* delete old escapePrefixUp */
+- escapePrefixUp <<= LSB_ESCAPE_PREFIX_UP; /* shift to correct position */
+- pEscapeSequenceInfo[codewordOffset] |=
+- escapePrefixUp; /* insert new escapePrefixUp */
+- escapePrefixUp >>= LSB_ESCAPE_PREFIX_UP; /* shift back down */
+-
+- /* store escapePrefixUp in pEscapeSequenceInfo[codewordOffset] at bit
+- * position escapePrefixDown */
+- pEscapeSequenceInfo[codewordOffset] &=
+- ~MASK_ESCAPE_PREFIX_DOWN; /* delete old escapePrefixDown */
+- escapePrefixUp <<= LSB_ESCAPE_PREFIX_DOWN; /* shift to correct position */
+- pEscapeSequenceInfo[codewordOffset] |=
+- escapePrefixUp; /* insert new escapePrefixDown */
+-
+- pSta[codewordOffset] = BODY_SIGN_ESC__ESC_WORD; /* set next state */
+- pHcr->nonPcwSideinfo.pState =
+- aStateConstant2State[pSta[codewordOffset]]; /* get state from separate
+- array of cw-sideinfo */
+- break;
+- }
+- }
+-
+- if (pRemainingBitsInSegment[segmentOffset] <= 0) {
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pSegmentBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+-
+- if (pRemainingBitsInSegment[segmentOffset] < 0) {
+- pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__ESC_PREFIX;
+- return BODY_SIGN_ESC__ESC_PREFIX;
+- }
+- }
+-
+- return STOP_THIS_STATE;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Decode escapeWord of escape sequence. If the escape sequence
+-is decoded completely, assemble quantized-spectral-escape-coefficient and
+-replace the previous decoded 16 by the new value. Test flagB. If flagB is set,
+-the second escape sequence must be decoded. If flagB is not set, the codeword is
+-decoded and the state machine is switched off.
+------------------------------------------------------------------------------------------------
+- output: Two lines with valid sign. At least one of both lines has got
+-the correct value.
+------------------------------------------------------------------------------------------------
+- return: 0
+---------------------------------------------------------------------------------------------
+-*/
+-UINT Hcr_State_BODY_SIGN_ESC__ESC_WORD(HANDLE_FDK_BITSTREAM bs, void *ptr) {
+- H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
+- SCHAR *pRemainingBitsInSegment;
+- INT *pLeftStartOfSegment;
+- INT *pRightStartOfSegment;
+- UCHAR readDirection;
+- UINT *pSegmentBitfield;
+- UINT *pCodewordBitfield;
+- UINT segmentOffset;
+-
+- FIXP_DBL *pResultBase;
+- USHORT *iResultPointer;
+- UINT *pEscapeSequenceInfo;
+- UINT codewordOffset;
+-
+- UINT escapeWord;
+- UINT escapePrefixDown;
+- UINT escapePrefixUp;
+- UCHAR carryBit;
+- UINT iQSC;
+- INT sign;
+- UINT flagA;
+- UINT flagB;
+- SCHAR *pSta;
+-
+- pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
+- pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
+- pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
+- readDirection = pHcr->segmentInfo.readDirection;
+- pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
+- pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
+- segmentOffset = pHcr->segmentInfo.segmentOffset;
+-
+- pResultBase = pHcr->nonPcwSideinfo.pResultBase;
+- iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
+- pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
+- codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
+- pSta = pHcr->nonPcwSideinfo.pSta;
+-
+- escapeWord = pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_WORD;
+- escapePrefixDown =
+- (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_DOWN) >>
+- LSB_ESCAPE_PREFIX_DOWN;
+-
+- /* decode escape word */
+- for (; pRemainingBitsInSegment[segmentOffset] > 0;
+- pRemainingBitsInSegment[segmentOffset] -= 1) {
+- carryBit = HcrGetABitFromBitstream(
+- bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
+- &pRightStartOfSegment[segmentOffset], readDirection);
+-
+- /* build escape word */
+- escapeWord <<=
+- 1; /* left shift previous decoded part of escapeWord by on bit */
+- escapeWord = escapeWord | carryBit; /* assemble escape word by bitwise or */
+-
+- /* decrement counter for length of escape word because one more bit was
+- * decoded */
+- escapePrefixDown -= 1;
+-
+- /* store updated escapePrefixDown */
+- pEscapeSequenceInfo[codewordOffset] &=
+- ~MASK_ESCAPE_PREFIX_DOWN; /* delete old escapePrefixDown */
+- escapePrefixDown <<= LSB_ESCAPE_PREFIX_DOWN; /* shift to correct position */
+- pEscapeSequenceInfo[codewordOffset] |=
+- escapePrefixDown; /* insert new escapePrefixDown */
+- escapePrefixDown >>= LSB_ESCAPE_PREFIX_DOWN; /* shift back */
+-
+- /* store updated escapeWord */
+- pEscapeSequenceInfo[codewordOffset] &=
+- ~MASK_ESCAPE_WORD; /* delete old escapeWord */
+- pEscapeSequenceInfo[codewordOffset] |=
+- escapeWord; /* insert new escapeWord */
+-
+- if (escapePrefixDown == 0) {
+- pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
+- for loop counter (see
+- above) is done here */
+-
+- /* escape sequence decoded. Assemble escape-line and replace original line
+- */
+-
+- /* step 0 */
+- /* derive sign */
+- iQSC = iResultPointer[codewordOffset];
+- sign = (pResultBase[iQSC] >= (FIXP_DBL)0)
+- ? 1
+- : -1; /* get sign of escape value 16 */
+-
+- /* step 1 */
+- /* get escapePrefixUp */
+- escapePrefixUp =
+- (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_UP) >>
+- LSB_ESCAPE_PREFIX_UP;
+-
+- /* step 2 */
+- /* calculate escape value */
+- pResultBase[iQSC] =
+- (FIXP_DBL)(sign * (((INT)1 << escapePrefixUp) + (INT)escapeWord));
+-
+- /* get both flags from sideinfo (flags are not shifted to the
+- * lsb-position) */
+- flagA = pEscapeSequenceInfo[codewordOffset] & MASK_FLAG_A;
+- flagB = pEscapeSequenceInfo[codewordOffset] & MASK_FLAG_B;
+-
+- /* step 3 */
+- /* clear the whole escape sideinfo word */
+- pEscapeSequenceInfo[codewordOffset] = 0;
+-
+- /* change state in dependence of flag flagB */
+- if (flagA != 0) {
+- /* first escape sequence decoded; previous decoded 16 has been replaced
+- * by valid line */
+-
+- /* clear flagA in sideinfo word because this escape sequence has already
+- * beed decoded */
+- pEscapeSequenceInfo[codewordOffset] &= ~MASK_FLAG_A;
+-
+- if (flagB == 0) {
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pCodewordBitfield); /* clear a bit in bitfield
+- and switch off
+- statemachine */
+- } else {
+- /* updated pointer to next and last 16 */
+- iQSC++;
+- iResultPointer[codewordOffset] = iQSC;
+-
+- /* change state */
+- pSta[codewordOffset] = BODY_SIGN_ESC__ESC_PREFIX;
+- pHcr->nonPcwSideinfo.pState =
+- aStateConstant2State[pSta[codewordOffset]]; /* get state from
+- separate array of
+- cw-sideinfo */
+- }
+- } else {
+- ClearBitFromBitfield(
+- &(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pCodewordBitfield); /* clear a bit in bitfield and switch off
+- statemachine */
+- }
+- break;
+- }
+- }
+-
+- if (pRemainingBitsInSegment[segmentOffset] <= 0) {
+- ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
+- pSegmentBitfield); /* clear a bit in bitfield and
+- switch off statemachine */
+-
+- if (pRemainingBitsInSegment[segmentOffset] < 0) {
+- pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__ESC_WORD;
+- return BODY_SIGN_ESC__ESC_WORD;
+- }
+- }
+-
+- return STOP_THIS_STATE;
+-}
+diff --git a/libAACdec/src/aacdec_hcrs.h b/libAACdec/src/aacdec_hcrs.h
+deleted file mode 100644
+index acb2f40..0000000
+--- a/libAACdec/src/aacdec_hcrs.h
++++ /dev/null
+@@ -1,176 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Robert Weidner (DSP Solutions)
+-
+- Description: HCR Decoder: Defines of state-constants, masks and
+- state-prototypes
+-
+-*******************************************************************************/
+-
+-#ifndef AACDEC_HCRS_H
+-#define AACDEC_HCRS_H
+-
+-#include "FDK_bitstream.h"
+-#include "aacdec_hcr_types.h"
+-/* The four different kinds of types of states are: */
+-/* different states are defined as constants */ /* start middle=self next
+- stop */
+-#define STOP_THIS_STATE \
+- 0 /* */
+-#define BODY_ONLY \
+- 1 /* X X X */
+-#define BODY_SIGN__BODY \
+- 2 /* X X X X [stop if no sign] */
+-#define BODY_SIGN__SIGN \
+- 3 /* X X [stop if sign bits decoded] */
+-#define BODY_SIGN_ESC__BODY \
+- 4 /* X X X X [stop if no sign] */
+-#define BODY_SIGN_ESC__SIGN \
+- 5 /* X X X [stop if no escape sequence] */
+-#define BODY_SIGN_ESC__ESC_PREFIX \
+- 6 /* X X */
+-#define BODY_SIGN_ESC__ESC_WORD \
+- 7 /* X X X [stop if abs(second qsc) != 16] */
+-
+-/* examples: */
+-
+-/* BODY_ONLY means only the codeword body will be decoded; no
+- * sign bits will follow and no escapesequence will follow */
+-
+-/* BODY_SIGN__BODY means that the codeword consists of two parts;
+- * body and sign part. The part '__BODY' after the two underscores shows */
+-/* that the bits which are currently decoded belong
+- * to the '__BODY' of the codeword and not to the sign part. */
+-
+-/* BODY_SIGN_ESC__ESC_PB means that the codeword consists of three parts;
+- * body, sign and (here: two) escape sequences; */
+-/* P = Prefix = ones */
+-/* W = Escape Word */
+-/* A = first possible (of two) Escape sequeces */
+-/* B = second possible (of two) Escape sequeces */
+-/* The part after the two underscores shows that
+- * the current bits which are decoded belong to the '__ESC_PB' - part of the */
+-/* codeword. That means the body and the sign bits
+- * are decoded completely and the bits which are decoded now belong to */
+-/* the escape sequence [P = prefix; B=second
+- * possible escape sequence] */
+-
+-#define MSB_31_MASK 0x80000000 /* masks MSB (= Bit 31) in a 32 bit word */
+-#define DIMENSION_OF_ESCAPE_CODEBOOK 2 /* for cb >= 11 is dimension 2 */
+-#define ESCAPE_CODEBOOK 11
+-
+-#define MASK_ESCAPE_PREFIX_UP 0x000F0000
+-#define LSB_ESCAPE_PREFIX_UP 16
+-
+-#define MASK_ESCAPE_PREFIX_DOWN 0x0000F000
+-#define LSB_ESCAPE_PREFIX_DOWN 12
+-
+-#define MASK_ESCAPE_WORD 0x00000FFF
+-#define MASK_FLAG_A 0x00200000
+-#define MASK_FLAG_B 0x00100000
+-
+-extern void DecodeNonPCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO hHcr);
+-
+-UINT Hcr_State_BODY_ONLY(HANDLE_FDK_BITSTREAM, void*);
+-UINT Hcr_State_BODY_SIGN__BODY(HANDLE_FDK_BITSTREAM, void*);
+-UINT Hcr_State_BODY_SIGN__SIGN(HANDLE_FDK_BITSTREAM, void*);
+-UINT Hcr_State_BODY_SIGN_ESC__BODY(HANDLE_FDK_BITSTREAM, void*);
+-UINT Hcr_State_BODY_SIGN_ESC__SIGN(HANDLE_FDK_BITSTREAM, void*);
+-UINT Hcr_State_BODY_SIGN_ESC__ESC_PREFIX(HANDLE_FDK_BITSTREAM, void*);
+-UINT Hcr_State_BODY_SIGN_ESC__ESC_WORD(HANDLE_FDK_BITSTREAM, void*);
+-
+-#endif /* AACDEC_HCRS_H */
+diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp
+index 2419ecc..6c03567 100644
+--- a/libAACdec/src/aacdecoder.cpp
++++ b/libAACdec/src/aacdecoder.cpp
+@@ -163,17 +163,12 @@ amm-info@iis.fraunhofer.de
+
+ #include "sac_dec_lib.h"
+
+-#include "aacdec_hcr.h"
+-#include "rvlc.h"
+-
+ #include "usacdec_lpd.h"
+
+ #include "ac_arith_coder.h"
+
+ #include "tpdec_lib.h"
+
+-#include "conceal.h"
+-
+ #include "FDK_crc.h"
+ #define PS_IS_EXPLICITLY_DISABLED(aot, flags) \
+ (((aot) == AOT_DRM_AAC) && !(flags & AC_PS_PRESENT))
+@@ -1191,10 +1186,6 @@ LINKSPEC_CPP HANDLE_AACDECODER CAacDecoder_Open(
+ /* initialize progam config */
+ CProgramConfig_Init(&self->pce);
+
+- /* initialize error concealment common data */
+- CConcealment_InitCommonData(&self->concealCommonData);
+- self->concealMethodUser = ConcealMethodNone; /* undefined -> auto mode */
+-
+ self->hDrcInfo = GetDrcInfo();
+ if (self->hDrcInfo == NULL) {
+ goto bail;
+@@ -1202,8 +1193,7 @@ LINKSPEC_CPP HANDLE_AACDECODER CAacDecoder_Open(
+ /* Init common DRC structure */
+ aacDecoder_drcInit(self->hDrcInfo);
+ /* Set default frame delay */
+- aacDecoder_drcSetParam(self->hDrcInfo, DRC_BS_DELAY,
+- CConcealment_GetDelay(&self->concealCommonData));
++ aacDecoder_drcSetParam(self->hDrcInfo, DRC_BS_DELAY, 0);
+
+ self->workBufferCore2 = GetWorkBufferCore2();
+ if (self->workBufferCore2 == NULL) goto bail;
+@@ -2085,15 +2075,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ if (self->pAacDecoderStaticChannelInfo[ch]->pCpeStaticData !=
+ NULL) {
+ self->pAacDecoderStaticChannelInfo[ch]
+- ->pCpeStaticData->jointStereoPersistentData
+- .spectralCoeffs[ch2] =
+- self->pAacDecoderStaticChannelInfo[ch]
+- ->concealmentInfo.spectralCoefficient;
+- self->pAacDecoderStaticChannelInfo[ch]
+- ->pCpeStaticData->jointStereoPersistentData.specScale[ch2] =
+- self->pAacDecoderStaticChannelInfo[ch]
+- ->concealmentInfo.specScale;
+- self->pAacDecoderStaticChannelInfo[ch]
+ ->pCpeStaticData->jointStereoPersistentData.scratchBuffer =
+ (FIXP_DBL *)self->pTimeData2;
+ }
+@@ -2193,12 +2174,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ /* Delete mixdown metadata from the past */
+ pcmDmx_Reset(self->hPcmUtils, PCMDMX_RESET_BS_DATA);
+
+- /* Reset concealment only if ASC changed. Otherwise it will be done with
+- any config callback. E.g. every time the LATM SMC is present. */
+- CConcealment_InitChannelData(
+- &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
+- &self->concealCommonData, initRenderMode,
+- self->streamInfo.aacSamplesPerFrame);
+ ch++;
+ chIdx++;
+ }
+@@ -2336,12 +2311,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ int ch;
+ /* Clear history */
+ for (ch = 0; ch < self->aacChannels; ch++) {
+- /* Reset concealment */
+- CConcealment_InitChannelData(
+- &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
+- &self->concealCommonData,
+- self->pAacDecoderChannelInfo[0]->renderMode,
+- self->streamInfo.aacSamplesPerFrame);
+ /* Clear overlap-add buffers to avoid clicks. */
+ FDKmemclear(self->pAacDecoderStaticChannelInfo[ch]->pOverlapBuffer,
+ OverlapBufferSize * sizeof(FIXP_DBL));
+@@ -2403,15 +2372,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ if (ch >= self->aacChannels) {
+ return AAC_DEC_UNKNOWN;
+ }
+-
+- /* if last frame was broken and this frame is no independent frame,
+- * correct decoding is impossible we need to trigger concealment */
+- if ((CConcealment_GetLastFrameOk(
+- &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
+- 1) == 0) &&
+- !(self->flags[streamIndex] & AC_INDEP)) {
+- self->frameOK = 0;
+- }
+ ch++;
+ }
+ }
+@@ -3081,13 +3041,8 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ * following concealment method, mark the frame as erroneous */
+ {
+ CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
+- CConcealmentInfo *hConcealmentInfo =
+- &pAacDecoderStaticChannelInfo->concealmentInfo;
+ const int mute_release_active =
+- (self->frameOK && !(flags & AACDEC_CONCEAL)) &&
+- ((hConcealmentInfo->concealState >= ConcealState_Mute) &&
+- (hConcealmentInfo->cntValidFrames + 1 <=
+- hConcealmentInfo->pConcealParams->numMuteReleaseFrames));
++ (self->frameOK && !(flags & AACDEC_CONCEAL));
+ const int icsIsInvalid = (GetScaleFactorBandsTransmitted(pIcsInfo) >
+ GetScaleFactorBandsTotal(pIcsInfo));
+ const int icsInfoUsedinFadeOut =
+@@ -3098,29 +3053,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ }
+ }
+
+- /*
+- Conceal defective spectral data
+- */
+- {
+- CAacDecoderChannelInfo **ppAacDecoderChannelInfo =
+- &pAacDecoderChannelInfo;
+- CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo =
+- &pAacDecoderStaticChannelInfo;
+- {
+- concealApplyReturnCode = CConcealment_Apply(
+- &(*ppAacDecoderStaticChannelInfo)->concealmentInfo,
+- *ppAacDecoderChannelInfo, *ppAacDecoderStaticChannelInfo,
+- &self->samplingRateInfo[streamIndex],
+- self->streamInfo.aacSamplesPerFrame,
+- pAacDecoderStaticChannelInfo->last_lpd_mode,
+- (self->frameOK && !(flags & AACDEC_CONCEAL)),
+- self->flags[streamIndex]);
+- }
+- }
+- if (concealApplyReturnCode == -1) {
+- frameOk_butConceal = 1;
+- }
+-
+ if (flags & (AACDEC_INTR)) {
+ /* Reset DRC control data for this channel */
+ aacDecoder_drcInitChannelData(&pAacDecoderStaticChannelInfo->drcData);
+@@ -3191,20 +3123,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ ErrorStatus = AAC_DEC_UNKNOWN;
+ break;
+ }
+- /* TimeDomainFading */
+- if (!CConceal_TDFading_Applied[c]) {
+- CConceal_TDFading_Applied[c] = CConcealment_TDFading(
+- self->streamInfo.aacSamplesPerFrame,
+- &self->pAacDecoderStaticChannelInfo[c], pTimeData + offset, 0);
+- if (c + 1 < (8) && c < aacChannels - 1) {
+- /* update next TDNoise Seed to avoid muting in case of Parametric
+- * Stereo */
+- self->pAacDecoderStaticChannelInfo[c + 1]
+- ->concealmentInfo.TDNoiseSeed =
+- self->pAacDecoderStaticChannelInfo[c]
+- ->concealmentInfo.TDNoiseSeed;
+- }
+- }
+ }
+ }
+
+@@ -3249,11 +3167,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ }
+ }
+
+- /* Add additional concealment delay */
+- self->streamInfo.outputDelay +=
+- CConcealment_GetDelay(&self->concealCommonData) *
+- self->streamInfo.aacSamplesPerFrame;
+-
+ /* Map DRC data to StreamInfo structure */
+ aacDecoder_drcGetInfo(self->hDrcInfo, &self->streamInfo.drcPresMode,
+ &self->streamInfo.drcProgRefLev);
+diff --git a/libAACdec/src/aacdecoder.h b/libAACdec/src/aacdecoder.h
+index 0711160..3750389 100644
+--- a/libAACdec/src/aacdecoder.h
++++ b/libAACdec/src/aacdecoder.h
+@@ -236,9 +236,6 @@ struct AAC_DECODER_INSTANCE {
+ 1)]; /*!< Pointer to persistent data shared by both channels of a CPE.
+ This structure is allocated once for each CPE. */
+
+- CConcealParams concealCommonData;
+- CConcealmentMethod concealMethodUser;
+-
+ CUsacCoreExtensions usacCoreExt; /*!< Data and handles to extend USAC FD/LPD
+ core decoder (SBR, MPS, ...) */
+ UINT numUsacElements[(1 * 1)];
+diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp
+index bde978e..1fc6ea0 100644
+--- a/libAACdec/src/aacdecoder_lib.cpp
++++ b/libAACdec/src/aacdecoder_lib.cpp
+@@ -107,8 +107,6 @@ amm-info@iis.fraunhofer.de
+ #include "tpdec_lib.h"
+ #include "FDK_core.h" /* FDK_tools version info */
+
+-#include "conceal.h"
+-
+ #include "aacdec_drc.h"
+
+ #include "sac_dec_lib.h"
+@@ -280,26 +278,6 @@ static INT aacDecoder_ConfigCallback(void *handle,
+ { err = aacDecoder_Config(self, pAscStruct, configMode, configChanged); }
+ }
+ if (err == AAC_DEC_OK) {
+- /*
+- revert concealment method if either
+- - Interpolation concealment might not be meaningful
+- - Interpolation concealment is not implemented
+- */
+- if ((self->flags[0] & (AC_LD | AC_ELD) &&
+- (self->concealMethodUser == ConcealMethodNone) &&
+- CConcealment_GetDelay(&self->concealCommonData) >
+- 0) /* might not be meaningful but allow if user has set it
+- expicitly */
+- || (self->flags[0] & (AC_USAC | AC_RSVD50 | AC_RSV603DA) &&
+- CConcealment_GetDelay(&self->concealCommonData) >
+- 0) /* not implemented */
+- ) {
+- /* Revert to error concealment method Noise Substitution.
+- Because interpolation is not implemented for USAC or
+- the additional delay is unwanted for low delay codecs. */
+- setConcealMethod(self, 1);
+- }
+- aacDecoder_setMetadataExpiry(self, self->metadataExpiry);
+ errTp = TRANSPORTDEC_OK;
+ } else {
+ if (err == AAC_DEC_NEED_TO_RESTART) {
+@@ -529,17 +507,12 @@ static AAC_DECODER_ERROR setConcealMethod(
+ const HANDLE_AACDECODER self, /*!< Handle of the decoder instance */
+ const INT method) {
+ AAC_DECODER_ERROR errorStatus = AAC_DEC_OK;
+- CConcealParams *pConcealData = NULL;
+ int method_revert = 0;
+ HANDLE_AAC_DRC hDrcInfo = NULL;
+ HANDLE_PCM_DOWNMIX hPcmDmx = NULL;
+- CConcealmentMethod backupMethod = ConcealMethodNone;
+- int backupDelay = 0;
+- int bsDelay = 0;
+
+ /* check decoder handle */
+ if (self != NULL) {
+- pConcealData = &self->concealCommonData;
+ hDrcInfo = self->hDrcInfo;
+ hPcmDmx = self->hPcmUtils;
+ if (self->flags[0] & (AC_USAC | AC_RSVD50 | AC_RSV603DA) && method >= 2) {
+@@ -555,33 +528,13 @@ static AAC_DECODER_ERROR setConcealMethod(
+ }
+ }
+
+- /* Get current method/delay */
+- backupMethod = CConcealment_GetMethod(pConcealData);
+- backupDelay = CConcealment_GetDelay(pConcealData);
+-
+- /* Be sure to set AAC and SBR concealment method simultaneously! */
+- errorStatus = CConcealment_SetParams(
+- pConcealData,
+- (method_revert == 0) ? (int)method : (int)1, // concealMethod
+- AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealFadeOutSlope
+- AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealFadeInSlope
+- AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealMuteRelease
+- AACDEC_CONCEAL_PARAM_NOT_SPECIFIED // concealComfNoiseLevel
+- );
+- if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
+- goto bail;
+- }
+-
+- /* Get new delay */
+- bsDelay = CConcealment_GetDelay(pConcealData);
+-
+- errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, bsDelay);
++ errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, 0);
+ if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
+ goto bail;
+ }
+
+ if (errorStatus == AAC_DEC_OK) {
+- PCMDMX_ERROR err = pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, bsDelay);
++ PCMDMX_ERROR err = pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, 0);
+ switch (err) {
+ case PCMDMX_INVALID_HANDLE:
+ errorStatus = AAC_DEC_INVALID_HANDLE;
+@@ -596,15 +549,10 @@ static AAC_DECODER_ERROR setConcealMethod(
+
+ bail:
+ if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
+- /* Revert to the initial state */
+- CConcealment_SetParams(
+- pConcealData, (int)backupMethod, AACDEC_CONCEAL_PARAM_NOT_SPECIFIED,
+- AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, AACDEC_CONCEAL_PARAM_NOT_SPECIFIED,
+- AACDEC_CONCEAL_PARAM_NOT_SPECIFIED);
+ /* Revert DRC bitstream delay */
+- aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, backupDelay);
++ aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, 0);
+ /* Revert PCM mixdown bitstream delay */
+- pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, backupDelay);
++ pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, 0);
+ }
+
+ return errorStatus;
+@@ -834,9 +782,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_SetParam(
+ packed into a helper function which keeps all modules and libs in a
+ consistent state even in the case an error occures. */
+ errorStatus = setConcealMethod(self, value);
+- if (errorStatus == AAC_DEC_OK) {
+- self->concealMethodUser = (CConcealmentMethod)value;
+- }
+ break;
+
+ default:
+@@ -966,8 +911,7 @@ LINKSPEC_CPP HANDLE_AACDECODER aacDecoder_Open(TRANSPORT_TYPE transportFmt,
+ aacDec->limiterEnableCurr = 0;
+
+ /* Assure that all modules have same delay */
+- if (setConcealMethod(aacDec,
+- CConcealment_GetMethod(&aacDec->concealCommonData))) {
++ if (setConcealMethod(aacDec, 0)) {
+ err = -1;
+ goto bail;
+ }
+@@ -1359,9 +1303,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ break;
+ }
+
+- if ((ErrorStatus != AAC_DEC_OK) || (flags & AACDEC_CONCEAL) ||
+- self->pAacDecoderStaticChannelInfo[0]->concealmentInfo.concealState >
+- ConcealState_FadeIn) {
++ if ((ErrorStatus != AAC_DEC_OK) || (flags & AACDEC_CONCEAL)) {
+ self->frameOK = 0; /* if an error has occured do concealment in the SBR
+ decoder too */
+ }
+@@ -1457,9 +1399,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ domain signal before the QMF synthesis. Therefore the DRC gains
+ need to be delayed by the QMF synthesis delay. */
+ if (self->mpsEnableCurr) drcDelay = 257;
+- /* Take into account concealment delay */
+- drcDelay += CConcealment_GetDelay(&self->concealCommonData) *
+- self->streamInfo.frameSize;
+
+ for (ch = 0; ch < self->streamInfo.numChannels; ch++) {
+ UCHAR mapValue = FDK_chMapDescr_getMapValue(
+diff --git a/libAACdec/src/block.cpp b/libAACdec/src/block.cpp
+index b3d09a6..a394cd7 100644
+--- a/libAACdec/src/block.cpp
++++ b/libAACdec/src/block.cpp
+@@ -114,9 +114,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "ac_arith_coder.h"
+
+-#include "aacdec_hcr.h"
+-#include "rvlc.h"
+-
+ #if defined(__arm__)
+ #include "arm/block_arm.cpp"
+ #endif
+@@ -331,12 +328,7 @@ AAC_DECODER_ERROR CBlock_ReadSectionData(
+ int group;
+ UCHAR sect_cb;
+ UCHAR *pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook;
+- /* HCR input (long) */
+- SHORT *pNumLinesInSec =
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.aNumLineInSec4Hcr;
+ int numLinesInSecIdx = 0;
+- UCHAR *pHcrCodeBook =
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.aCodeBooks4Hcr;
+ const SHORT *BandOffsets = GetScaleFactorBandOffsets(
+ &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo);
+ pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection = 0;
+@@ -376,22 +368,8 @@ AAC_DECODER_ERROR CBlock_ReadSectionData(
+ top = band + sect_len;
+
+ if (flags & AC_ER_HCR) {
+- /* HCR input (long) -- collecting sideinfo (for HCR-_long_ only) */
+- if (numLinesInSecIdx >= MAX_SFB_HCR) {
+- return AAC_DEC_PARSE_ERROR;
+- }
+- if (top > (int)GetNumberOfScaleFactorBands(
+- &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo)) {
+- return AAC_DEC_PARSE_ERROR;
+- }
+- pNumLinesInSec[numLinesInSecIdx] = BandOffsets[top] - BandOffsets[band];
+- numLinesInSecIdx++;
+- if (sect_cb == BOOKSCL) {
+- return AAC_DEC_INVALID_CODE_BOOK;
+- } else {
+- *pHcrCodeBook++ = sect_cb;
+- }
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection++;
++ /* HCR disabled */
++ return AAC_DEC_PARSE_ERROR;
+ }
+
+ /* Check spectral line limits */
+@@ -718,41 +696,12 @@ AAC_DECODER_ERROR CBlock_ReadSpectralData(
+ /* plain huffman decoding (short) finished */
+ }
+
+- /* HCR - Huffman Codeword Reordering short */
+ else /* if ( flags & AC_ER_HCR ) */
+
+ {
+- H_HCR_INFO hHcr = &pAacDecoderChannelInfo->pComData->overlay.aac.erHcrInfo;
+-
+- int hcrStatus = 0;
+-
+- /* advanced Huffman decoding starts here (HCR decoding :) */
+- if (pAacDecoderChannelInfo->pDynData->specificTo.aac
+- .lenOfReorderedSpectralData != 0) {
+- /* HCR initialization short */
+- hcrStatus = HcrInit(hHcr, pAacDecoderChannelInfo, pSamplingRateInfo, bs);
+-
+- if (hcrStatus != 0) {
+- return AAC_DEC_DECODE_FRAME_ERROR;
+- }
+-
+- /* HCR decoding short */
+- hcrStatus =
+- HcrDecoder(hHcr, pAacDecoderChannelInfo, pSamplingRateInfo, bs);
+-
+- if (hcrStatus != 0) {
+-#if HCR_ERROR_CONCEALMENT
+- HcrMuteErroneousLines(hHcr);
+-#else
+- return AAC_DEC_DECODE_FRAME_ERROR;
+-#endif /* HCR_ERROR_CONCEALMENT */
+- }
+-
+- FDKpushFor(bs, pAacDecoderChannelInfo->pDynData->specificTo.aac
+- .lenOfReorderedSpectralData);
+- }
++ /* HCR - Huffman Codeword Reordering disabled */
++ return AAC_DEC_DECODE_FRAME_ERROR;
+ }
+- /* HCR - Huffman Codeword Reordering short finished */
+
+ if (IsLongBlock(&pAacDecoderChannelInfo->icsInfo) &&
+ !(flags & (AC_ELD | AC_SCALABLE))) {
+diff --git a/libAACdec/src/channel.cpp b/libAACdec/src/channel.cpp
+index a020034..e17ccf4 100644
+--- a/libAACdec/src/channel.cpp
++++ b/libAACdec/src/channel.cpp
+@@ -106,12 +106,6 @@ amm-info@iis.fraunhofer.de
+ #include "aacdec_tns.h"
+ #include "FDK_bitstream.h"
+
+-#include "conceal.h"
+-
+-#include "rvlc.h"
+-
+-#include "aacdec_hcr.h"
+-
+ #include "usacdec_lpd.h"
+ #include "usacdec_fac.h"
+
+@@ -376,9 +370,6 @@ void CChannelElement_Decode(
+ ->pCpeStaticData->jointStereoPersistentData.clearSpectralCoeffs = 0;
+ }
+ }
+-
+- CRvlc_ElementCheck(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo,
+- flags, el_channels);
+ }
+
+ void CChannel_CodebookTableInit(
+@@ -596,8 +587,8 @@ AAC_DECODER_ERROR CChannelElement_Read(
+
+ case scale_factor_data:
+ if (flags & AC_ER_RVLC) {
+- /* read RVLC data from bitstream (error sens. cat. 1) */
+- CRvlc_Read(pAacDecoderChannelInfo[ch], hBs);
++ /* RVLC not supported */
++ error = AAC_DEC_DECODE_FRAME_ERROR;
+ } else {
+ error = CBlock_ReadScaleFactorData(pAacDecoderChannelInfo[ch], hBs,
+ flags);
+@@ -730,15 +721,13 @@ AAC_DECODER_ERROR CChannelElement_Read(
+ } break;
+ case esc2_rvlc:
+ if (flags & AC_ER_RVLC) {
+- CRvlc_Decode(pAacDecoderChannelInfo[ch],
+- pAacDecoderStaticChannelInfo[ch], hBs);
++ error = AAC_DEC_UNSUPPORTED_FORMAT;
+ }
+ break;
+
+ case esc1_hcr:
+ if (flags & AC_ER_HCR) {
+- CHcr_Read(hBs, pAacDecoderChannelInfo[ch],
+- numberOfChannels == 2 ? ID_CPE : ID_SCE);
++ error = AAC_DEC_UNSUPPORTED_FORMAT;
+ }
+ break;
+
+diff --git a/libAACdec/src/channelinfo.h b/libAACdec/src/channelinfo.h
+index 4523400..04f0012 100644
+--- a/libAACdec/src/channelinfo.h
++++ b/libAACdec/src/channelinfo.h
+@@ -117,17 +117,12 @@ amm-info@iis.fraunhofer.de
+
+ #include "aacdec_pns.h"
+
+-#include "aacdec_hcr_types.h"
+-#include "rvlc_info.h"
+-
+ #include "usacdec_acelp.h"
+ #include "usacdec_const.h"
+ #include "usacdec_rom.h"
+
+ #include "ac_arith_coder.h"
+
+-#include "conceal_types.h"
+-
+ #include "aacdec_drc_types.h"
+
+ #define WB_SECTION_SIZE (1024 * 2)
+@@ -257,7 +252,6 @@ typedef struct {
+ ULONG nfRandomSeed; /* seed value for USAC noise filling random generator */
+
+ CDrcChannelData drcData;
+- CConcealmentInfo concealmentInfo;
+
+ CpePersistentData *pCpeStaticData;
+
+@@ -280,11 +274,6 @@ typedef struct {
+ shouldBeUnion {
+ struct {
+ CPulseData PulseData;
+- SHORT aNumLineInSec4Hcr[MAX_SFB_HCR]; /* needed once for all channels
+- except for Drm syntax */
+- UCHAR
+- aCodeBooks4Hcr[MAX_SFB_HCR]; /* needed once for all channels except for
+- Drm syntax. Same as "aCodeBook" ? */
+ SHORT lenOfReorderedSpectralData;
+ SCHAR lenOfLongestCodeword;
+ SCHAR numberSection;
+@@ -325,17 +314,6 @@ typedef struct {
+
+ CJointStereoData jointStereoData; /* One for one element */
+
+- shouldBeUnion {
+- struct {
+- CErHcrInfo erHcrInfo;
+- CErRvlcInfo erRvlcInfo;
+- SHORT aRvlcScfEsc[RVLC_MAX_SFB]; /* needed once for all channels */
+- SHORT aRvlcScfFwd[RVLC_MAX_SFB]; /* needed once for all channels */
+- SHORT aRvlcScfBwd[RVLC_MAX_SFB]; /* needed once for all channels */
+- } aac;
+- }
+- overlay;
+-
+ } CAacDecoderCommonData;
+
+ typedef struct {
+diff --git a/libAACdec/src/conceal.cpp b/libAACdec/src/conceal.cpp
+deleted file mode 100644
+index 5895cb8..0000000
+--- a/libAACdec/src/conceal.cpp
++++ /dev/null
+@@ -1,2095 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Josef Hoepfl
+-
+- Description: independent channel concealment
+-
+-*******************************************************************************/
+-
+-/*!
+- \page concealment AAC core concealment
+-
+- This AAC core implementation includes a concealment function, which can be
+- enabled using the several defines during compilation.
+-
+- There are various tests inside the core, starting with simple CRC tests and
+- ending in a variety of plausibility checks. If such a check indicates an
+- invalid bitstream, then concealment is applied.
+-
+- Concealment is also applied when the calling main program indicates a
+- distorted or missing data frame using the frameOK flag. This is used for error
+- detection on the transport layer. (See below)
+-
+- There are three concealment-modes:
+-
+- 1) Muting: The spectral data is simply set to zero in case of an detected
+- error.
+-
+- 2) Noise substitution: In case of an detected error, concealment copies the
+- last frame and adds attenuates the spectral data. For this mode you have to
+- set the #CONCEAL_NOISE define. Noise substitution adds no additional delay.
+-
+- 3) Interpolation: The interpolation routine swaps the spectral data from the
+- previous and the current frame just before the final frequency to time
+- conversion. In case a single frame is corrupted, concealmant interpolates
+- between the last good and the first good frame to create the spectral data for
+- the missing frame. If multiple frames are corrupted, concealment implements
+- first a fade out based on slightly modified spectral values from the last good
+- frame. As soon as good frames are available, concealmant fades in the new
+- spectral data. For this mode you have to set the #CONCEAL_INTER define. Note
+- that in this case, you also need to set #SBR_BS_DELAY_ENABLE, which basically
+- adds approriate delay in the SBR decoder. Note that the
+- Interpolating-Concealment increases the delay of your decoder by one frame and
+- that it does require additional resources such as memory and computational
+- complexity.
+-
+- <h2>How concealment can be used with errors on the transport layer</h2>
+-
+- Many errors can or have to be detected on the transport layer. For example in
+- IP based systems packet loss can occur. The transport protocol used should
+- indicate such packet loss by inserting an empty frame with frameOK=0.
+-*/
+-
+-#include "conceal.h"
+-
+-#include "aac_rom.h"
+-#include "genericStds.h"
+-
+-/* PNS (of block) */
+-#include "aacdec_pns.h"
+-#include "block.h"
+-
+-#define CONCEAL_DFLT_COMF_NOISE_LEVEL (0x100000)
+-
+-#define CONCEAL_NOT_DEFINED ((UCHAR)-1)
+-
+-/* default settings */
+-#define CONCEAL_DFLT_FADEOUT_FRAMES (6)
+-#define CONCEAL_DFLT_FADEIN_FRAMES (5)
+-#define CONCEAL_DFLT_MUTE_RELEASE_FRAMES (0)
+-
+-#define CONCEAL_DFLT_FADE_FACTOR (0.707106781186548f) /* 1/sqrt(2) */
+-
+-/* some often used constants: */
+-#define FIXP_ZERO FL2FXCONST_DBL(0.0f)
+-#define FIXP_ONE FL2FXCONST_DBL(1.0f)
+-#define FIXP_FL_CORRECTION FL2FXCONST_DBL(0.53333333333333333f)
+-
+-/* For parameter conversion */
+-#define CONCEAL_PARAMETER_BITS (8)
+-#define CONCEAL_MAX_QUANT_FACTOR ((1 << CONCEAL_PARAMETER_BITS) - 1)
+-/*#define CONCEAL_MIN_ATTENUATION_FACTOR_025 ( FL2FXCONST_DBL(0.971627951577106174) )*/ /* -0.25 dB */
+-#define CONCEAL_MIN_ATTENUATION_FACTOR_025_LD \
+- FL2FXCONST_DBL(-0.041524101186092029596853445212299)
+-/*#define CONCEAL_MIN_ATTENUATION_FACTOR_050 ( FL2FXCONST_DBL(0.944060876285923380) )*/ /* -0.50 dB */
+-#define CONCEAL_MIN_ATTENUATION_FACTOR_050_LD \
+- FL2FXCONST_DBL(-0.083048202372184059253597008145293)
+-
+-typedef enum {
+- CConcealment_NoExpand,
+- CConcealment_Expand,
+- CConcealment_Compress
+-} CConcealmentExpandType;
+-
+-static const FIXP_SGL facMod4Table[4] = {
+- FL2FXCONST_SGL(0.500000000f), /* FIXP_SGL(0x4000), 2^-(1-0,00) */
+- FL2FXCONST_SGL(0.594603558f), /* FIXP_SGL(0x4c1b), 2^-(1-0,25) */
+- FL2FXCONST_SGL(0.707106781f), /* FIXP_SGL(0x5a82), 2^-(1-0,50) */
+- FL2FXCONST_SGL(0.840896415f) /* FIXP_SGL(0x6ba2) 2^-(1-0,75) */
+-};
+-
+-static void CConcealment_CalcBandEnergy(
+- FIXP_DBL *spectrum, const SamplingRateInfo *pSamplingRateInfo,
+- const int blockType, CConcealmentExpandType ex, int *sfbEnergy);
+-
+-static void CConcealment_InterpolateBuffer(FIXP_DBL *spectrum,
+- SHORT *pSpecScalePrev,
+- SHORT *pSpecScaleAct,
+- SHORT *pSpecScaleOut, int *enPrv,
+- int *enAct, int sfbCnt,
+- const SHORT *pSfbOffset);
+-
+-static int CConcealment_ApplyInter(
+- CConcealmentInfo *pConcealmentInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
+- const int improveTonal, const int frameOk, const int mute_release_active);
+-
+-static int CConcealment_ApplyNoise(
+- CConcealmentInfo *pConcealmentInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
+- const UINT flags);
+-
+-static void CConcealment_UpdateState(
+- CConcealmentInfo *pConcealmentInfo, int frameOk,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo);
+-
+-static void CConcealment_ApplyRandomSign(int iRandomPhase, FIXP_DBL *spec,
+- int samplesPerFrame);
+-
+-/* TimeDomainFading */
+-static void CConcealment_TDFadePcmAtt(int start, int len, FIXP_DBL fadeStart,
+- FIXP_DBL fadeStop, FIXP_PCM *pcmdata);
+-static void CConcealment_TDFadeFillFadingStations(FIXP_DBL *fadingStations,
+- int *fadingSteps,
+- FIXP_DBL fadeStop,
+- FIXP_DBL fadeStart,
+- TDfadingType fadingType);
+-static void CConcealment_TDFading_doLinearFadingSteps(int *fadingSteps);
+-
+-/* Streamline the state machine */
+-static int CConcealment_ApplyFadeOut(
+- int mode, CConcealmentInfo *pConcealmentInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo);
+-
+-static int CConcealment_TDNoise_Random(ULONG *seed);
+-static void CConcealment_TDNoise_Apply(CConcealmentInfo *const pConcealmentInfo,
+- const int len, FIXP_PCM *const pcmdata);
+-
+-static BLOCK_TYPE CConcealment_GetWinSeq(int prevWinSeq) {
+- BLOCK_TYPE newWinSeq = BLOCK_LONG;
+-
+- /* Try to have only long blocks */
+- if (prevWinSeq == BLOCK_START || prevWinSeq == BLOCK_SHORT) {
+- newWinSeq = BLOCK_STOP;
+- }
+-
+- return (newWinSeq);
+-}
+-
+-/*!
+- \brief Init common concealment information data
+-
+- \param pConcealCommonData Pointer to the concealment common data structure.
+-*/
+-void CConcealment_InitCommonData(CConcealParams *pConcealCommonData) {
+- if (pConcealCommonData != NULL) {
+- int i;
+-
+- /* Set default error concealment technique */
+- pConcealCommonData->method = ConcealMethodInter;
+-
+- pConcealCommonData->numFadeOutFrames = CONCEAL_DFLT_FADEOUT_FRAMES;
+- pConcealCommonData->numFadeInFrames = CONCEAL_DFLT_FADEIN_FRAMES;
+- pConcealCommonData->numMuteReleaseFrames = CONCEAL_DFLT_MUTE_RELEASE_FRAMES;
+-
+- pConcealCommonData->comfortNoiseLevel =
+- (FIXP_DBL)CONCEAL_DFLT_COMF_NOISE_LEVEL;
+-
+- /* Init fade factors (symetric) */
+- pConcealCommonData->fadeOutFactor[0] =
+- FL2FXCONST_SGL(CONCEAL_DFLT_FADE_FACTOR);
+- pConcealCommonData->fadeInFactor[0] = pConcealCommonData->fadeOutFactor[0];
+-
+- for (i = 1; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
+- pConcealCommonData->fadeOutFactor[i] =
+- FX_DBL2FX_SGL(fMult(pConcealCommonData->fadeOutFactor[i - 1],
+- FL2FXCONST_SGL(CONCEAL_DFLT_FADE_FACTOR)));
+- pConcealCommonData->fadeInFactor[i] =
+- pConcealCommonData->fadeOutFactor[i];
+- }
+- }
+-}
+-
+-/*!
+- \brief Get current concealment method.
+-
+- \param pConcealCommonData Pointer to common concealment data (for all
+- channels)
+-*/
+-CConcealmentMethod CConcealment_GetMethod(CConcealParams *pConcealCommonData) {
+- CConcealmentMethod method = ConcealMethodNone;
+-
+- if (pConcealCommonData != NULL) {
+- method = pConcealCommonData->method;
+- }
+-
+- return (method);
+-}
+-
+-/*!
+- \brief Init concealment information for each channel
+-
+- \param pConcealChannelInfo Pointer to the channel related concealment info
+- structure to be initialized. \param pConcealCommonData Pointer to common
+- concealment data (for all channels) \param initRenderMode Initial render
+- mode to be set for the current channel. \param samplesPerFrame The number
+- of samples per frame.
+-*/
+-void CConcealment_InitChannelData(CConcealmentInfo *pConcealChannelInfo,
+- CConcealParams *pConcealCommonData,
+- AACDEC_RENDER_MODE initRenderMode,
+- int samplesPerFrame) {
+- int i;
+- pConcealChannelInfo->TDNoiseSeed = 0;
+- FDKmemclear(pConcealChannelInfo->TDNoiseStates,
+- sizeof(pConcealChannelInfo->TDNoiseStates));
+- pConcealChannelInfo->TDNoiseCoef[0] = FL2FXCONST_SGL(0.05f);
+- pConcealChannelInfo->TDNoiseCoef[1] = FL2FXCONST_SGL(0.5f);
+- pConcealChannelInfo->TDNoiseCoef[2] = FL2FXCONST_SGL(0.45f);
+-
+- pConcealChannelInfo->pConcealParams = pConcealCommonData;
+-
+- pConcealChannelInfo->lastRenderMode = initRenderMode;
+-
+- pConcealChannelInfo->windowShape = CONCEAL_NOT_DEFINED;
+- pConcealChannelInfo->windowSequence = BLOCK_LONG; /* default type */
+- pConcealChannelInfo->lastWinGrpLen = 1;
+-
+- pConcealChannelInfo->concealState = ConcealState_Ok;
+-
+- FDKmemclear(pConcealChannelInfo->spectralCoefficient,
+- 1024 * sizeof(FIXP_CNCL));
+-
+- for (i = 0; i < 8; i++) {
+- pConcealChannelInfo->specScale[i] = 0;
+- }
+-
+- pConcealChannelInfo->iRandomPhase = 0;
+-
+- pConcealChannelInfo->prevFrameOk[0] = 1;
+- pConcealChannelInfo->prevFrameOk[1] = 1;
+-
+- pConcealChannelInfo->cntFadeFrames = 0;
+- pConcealChannelInfo->cntValidFrames = 0;
+- pConcealChannelInfo->fade_old = (FIXP_DBL)MAXVAL_DBL;
+- pConcealChannelInfo->winGrpOffset[0] = 0;
+- pConcealChannelInfo->winGrpOffset[1] = 0;
+- pConcealChannelInfo->attGrpOffset[0] = 0;
+- pConcealChannelInfo->attGrpOffset[1] = 0;
+-}
+-
+-/*!
+- \brief Set error concealment parameters
+-
+- \param concealParams
+- \param method
+- \param fadeOutSlope
+- \param fadeInSlope
+- \param muteRelease
+- \param comfNoiseLevel
+-*/
+-AAC_DECODER_ERROR
+-CConcealment_SetParams(CConcealParams *concealParams, int method,
+- int fadeOutSlope, int fadeInSlope, int muteRelease,
+- FIXP_DBL comfNoiseLevel) {
+- /* set concealment technique */
+- if (method != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
+- switch ((CConcealmentMethod)method) {
+- case ConcealMethodMute:
+- case ConcealMethodNoise:
+- case ConcealMethodInter:
+- /* Be sure to enable delay adjustment of SBR decoder! */
+- if (concealParams == NULL) {
+- return AAC_DEC_INVALID_HANDLE;
+- } else {
+- /* set param */
+- concealParams->method = (CConcealmentMethod)method;
+- }
+- break;
+-
+- default:
+- return AAC_DEC_SET_PARAM_FAIL;
+- }
+- }
+-
+- /* set number of frames for fade-out slope */
+- if (fadeOutSlope != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
+- if ((fadeOutSlope < CONCEAL_MAX_NUM_FADE_FACTORS) && (fadeOutSlope >= 0)) {
+- if (concealParams == NULL) {
+- return AAC_DEC_INVALID_HANDLE;
+- } else {
+- /* set param */
+- concealParams->numFadeOutFrames = fadeOutSlope;
+- }
+- } else {
+- return AAC_DEC_SET_PARAM_FAIL;
+- }
+- }
+-
+- /* set number of frames for fade-in slope */
+- if (fadeInSlope != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
+- if ((fadeInSlope < CONCEAL_MAX_NUM_FADE_FACTORS) && (fadeInSlope >= 0)) {
+- if (concealParams == NULL) {
+- return AAC_DEC_INVALID_HANDLE;
+- } else {
+- /* set param */
+- concealParams->numFadeInFrames = fadeInSlope;
+- }
+- } else {
+- return AAC_DEC_SET_PARAM_FAIL;
+- }
+- }
+-
+- /* set number of error-free frames after which the muting will be released */
+- if (muteRelease != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
+- if ((muteRelease < (CONCEAL_MAX_NUM_FADE_FACTORS << 1)) &&
+- (muteRelease >= 0)) {
+- if (concealParams == NULL) {
+- return AAC_DEC_INVALID_HANDLE;
+- } else {
+- /* set param */
+- concealParams->numMuteReleaseFrames = muteRelease;
+- }
+- } else {
+- return AAC_DEC_SET_PARAM_FAIL;
+- }
+- }
+-
+- /* set confort noise level which will be inserted while in state 'muting' */
+- if (comfNoiseLevel != (FIXP_DBL)AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
+- if ((comfNoiseLevel < (FIXP_DBL)0) ||
+- (comfNoiseLevel > (FIXP_DBL)MAXVAL_DBL)) {
+- return AAC_DEC_SET_PARAM_FAIL;
+- }
+- if (concealParams == NULL) {
+- return AAC_DEC_INVALID_HANDLE;
+- } else {
+- concealParams->comfortNoiseLevel = (FIXP_DBL)comfNoiseLevel;
+- }
+- }
+-
+- return (AAC_DEC_OK);
+-}
+-
+-/*!
+- \brief Set fade-out/in attenuation factor vectors
+-
+- \param concealParams
+- \param fadeOutAttenuationVector
+- \param fadeInAttenuationVector
+-
+- \return 0 if OK all other values indicate errors
+-*/
+-AAC_DECODER_ERROR
+-CConcealment_SetAttenuation(CConcealParams *concealParams,
+- const SHORT *fadeOutAttenuationVector,
+- const SHORT *fadeInAttenuationVector) {
+- if ((fadeOutAttenuationVector == NULL) && (fadeInAttenuationVector == NULL)) {
+- return AAC_DEC_SET_PARAM_FAIL;
+- }
+-
+- /* Fade-out factors */
+- if (fadeOutAttenuationVector != NULL) {
+- int i;
+-
+- /* check quantized factors first */
+- for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
+- if ((fadeOutAttenuationVector[i] < 0) ||
+- (fadeOutAttenuationVector[i] > CONCEAL_MAX_QUANT_FACTOR)) {
+- return AAC_DEC_SET_PARAM_FAIL;
+- }
+- }
+- if (concealParams == NULL) {
+- return AAC_DEC_INVALID_HANDLE;
+- }
+-
+- /* now dequantize factors */
+- for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
+- concealParams->fadeOutFactor[i] =
+- FX_DBL2FX_SGL(fLdPow(CONCEAL_MIN_ATTENUATION_FACTOR_025_LD, 0,
+- (FIXP_DBL)((INT)(FL2FXCONST_DBL(1.0 / 2.0) >>
+- (CONCEAL_PARAMETER_BITS - 1)) *
+- (INT)fadeOutAttenuationVector[i]),
+- CONCEAL_PARAMETER_BITS));
+- }
+- }
+-
+- /* Fade-in factors */
+- if (fadeInAttenuationVector != NULL) {
+- int i;
+-
+- /* check quantized factors first */
+- for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
+- if ((fadeInAttenuationVector[i] < 0) ||
+- (fadeInAttenuationVector[i] > CONCEAL_MAX_QUANT_FACTOR)) {
+- return AAC_DEC_SET_PARAM_FAIL;
+- }
+- }
+- if (concealParams == NULL) {
+- return AAC_DEC_INVALID_HANDLE;
+- }
+-
+- /* now dequantize factors */
+- for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
+- concealParams->fadeInFactor[i] = FX_DBL2FX_SGL(
+- fLdPow(CONCEAL_MIN_ATTENUATION_FACTOR_025_LD, 0,
+- (FIXP_DBL)((INT)(FIXP_ONE >> CONCEAL_PARAMETER_BITS) *
+- (INT)fadeInAttenuationVector[i]),
+- CONCEAL_PARAMETER_BITS));
+- }
+- }
+-
+- return (AAC_DEC_OK);
+-}
+-
+-/*!
+- \brief Get state of concealment module.
+-
+- \param pConcealChannelInfo
+-
+- \return Concealment state.
+-*/
+-CConcealmentState CConcealment_GetState(CConcealmentInfo *pConcealChannelInfo) {
+- CConcealmentState state = ConcealState_Ok;
+-
+- if (pConcealChannelInfo != NULL) {
+- state = pConcealChannelInfo->concealState;
+- }
+-
+- return (state);
+-}
+-
+-/*!
+- \brief Store data for concealment techniques applied later
+-
+- Interface function to store data for different concealment strategies
+- */
+-void CConcealment_Store(
+- CConcealmentInfo *hConcealmentInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
+- UCHAR nbDiv = NB_DIV;
+-
+- if (!(pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD &&
+- pAacDecoderChannelInfo->data.usac.mod[nbDiv - 1] == 0))
+-
+- {
+- FIXP_DBL *pSpectralCoefficient =
+- SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
+- SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
+- CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
+-
+- SHORT tSpecScale[8];
+- UCHAR tWindowShape;
+- BLOCK_TYPE tWindowSequence;
+-
+- /* store old window infos for swapping */
+- tWindowSequence = hConcealmentInfo->windowSequence;
+- tWindowShape = hConcealmentInfo->windowShape;
+-
+- /* store old scale factors for swapping */
+- FDKmemcpy(tSpecScale, hConcealmentInfo->specScale, 8 * sizeof(SHORT));
+-
+- /* store new window infos */
+- hConcealmentInfo->windowSequence = GetWindowSequence(pIcsInfo);
+- hConcealmentInfo->windowShape = GetWindowShape(pIcsInfo);
+- hConcealmentInfo->lastWinGrpLen =
+- *(GetWindowGroupLengthTable(pIcsInfo) + GetWindowGroups(pIcsInfo) - 1);
+-
+- /* store new scale factors */
+- FDKmemcpy(hConcealmentInfo->specScale, pSpecScale, 8 * sizeof(SHORT));
+-
+- if (hConcealmentInfo->pConcealParams->method < ConcealMethodInter) {
+- /* store new spectral bins */
+-#if (CNCL_FRACT_BITS == DFRACT_BITS)
+- FDKmemcpy(hConcealmentInfo->spectralCoefficient, pSpectralCoefficient,
+- 1024 * sizeof(FIXP_CNCL));
+-#else
+- FIXP_CNCL *RESTRICT pCncl =
+- &hConcealmentInfo->spectralCoefficient[1024 - 1];
+- FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
+- int i;
+- for (i = 1024; i != 0; i--) {
+- *pCncl-- = FX_DBL2FX_CNCL(*pSpec--);
+- }
+-#endif
+- } else {
+- /* swap spectral data */
+-#if (FIXP_CNCL == FIXP_DBL)
+- C_ALLOC_SCRATCH_START(pSpecTmp, FIXP_DBL, 1024);
+- FDKmemcpy(pSpecTmp, pSpectralCoefficient, 1024 * sizeof(FIXP_DBL));
+- FDKmemcpy(pSpectralCoefficient, hConcealmentInfo->spectralCoefficient,
+- 1024 * sizeof(FIXP_DBL));
+- FDKmemcpy(hConcealmentInfo->spectralCoefficient, pSpecTmp,
+- 1024 * sizeof(FIXP_DBL));
+- C_ALLOC_SCRATCH_END(pSpecTmp, FIXP_DBL, 1024);
+-#else
+- FIXP_CNCL *RESTRICT pCncl =
+- &hConcealmentInfo->spectralCoefficient[1024 - 1];
+- FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
+- FIXP_DBL tSpec;
+-
+- for (int i = 1024; i != 0; i--) {
+- tSpec = *pSpec;
+- *pSpec-- = FX_CNCL2FX_DBL(*pCncl);
+- *pCncl-- = FX_DBL2FX_CNCL(tSpec);
+- }
+-#endif
+-
+- /* complete swapping of window infos */
+- pIcsInfo->WindowSequence = tWindowSequence;
+- pIcsInfo->WindowShape = tWindowShape;
+-
+- /* complete swapping of scale factors */
+- FDKmemcpy(pSpecScale, tSpecScale, 8 * sizeof(SHORT));
+- }
+- }
+-
+- if (pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD) {
+- /* Store LSF4 */
+- FDKmemcpy(hConcealmentInfo->lsf4, pAacDecoderStaticChannelInfo->lpc4_lsf,
+- sizeof(hConcealmentInfo->lsf4));
+- /* Store TCX gain */
+- hConcealmentInfo->last_tcx_gain =
+- pAacDecoderStaticChannelInfo->last_tcx_gain;
+- hConcealmentInfo->last_tcx_gain_e =
+- pAacDecoderStaticChannelInfo->last_tcx_gain_e;
+- }
+-}
+-
+-/*!
+- \brief Apply concealment
+-
+- Interface function to different concealment strategies
+- */
+-int CConcealment_Apply(
+- CConcealmentInfo *hConcealmentInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
+- const UCHAR lastLpdMode, const int frameOk, const UINT flags) {
+- int appliedProcessing = 0;
+- const int mute_release_active =
+- frameOk && (hConcealmentInfo->concealState >= ConcealState_Mute) &&
+- (hConcealmentInfo->cntValidFrames + 1 <=
+- hConcealmentInfo->pConcealParams->numMuteReleaseFrames);
+-
+- if (hConcealmentInfo->windowShape == CONCEAL_NOT_DEFINED) {
+- /* Initialize window_shape with same value as in the current (parsed) frame.
+- Because section 4.6.11.3.2 (Windowing and block switching) of ISO/IEC
+- 14496-3:2009 says: For the first raw_data_block() to be decoded the
+- window_shape of the left and right half of the window are identical. */
+- hConcealmentInfo->windowShape = pAacDecoderChannelInfo->icsInfo.WindowShape;
+- }
+-
+- if (frameOk && !mute_release_active) {
+- /* Update render mode if frameOk except for ongoing mute release state. */
+- hConcealmentInfo->lastRenderMode =
+- (SCHAR)pAacDecoderChannelInfo->renderMode;
+-
+- /* Rescue current data for concealment in future frames */
+- CConcealment_Store(hConcealmentInfo, pAacDecoderChannelInfo,
+- pAacDecoderStaticChannelInfo);
+- /* Reset index to random sign vector to make sign calculation frame agnostic
+- (only depends on number of subsequently concealed spectral blocks) */
+- hConcealmentInfo->iRandomPhase = 0;
+- } else {
+- if (hConcealmentInfo->lastRenderMode == AACDEC_RENDER_INVALID) {
+- hConcealmentInfo->lastRenderMode = AACDEC_RENDER_IMDCT;
+- }
+- pAacDecoderChannelInfo->renderMode =
+- (AACDEC_RENDER_MODE)hConcealmentInfo->lastRenderMode;
+- }
+-
+- /* hand current frame status to the state machine */
+- CConcealment_UpdateState(hConcealmentInfo, frameOk,
+- pAacDecoderStaticChannelInfo, samplesPerFrame,
+- pAacDecoderChannelInfo);
+-
+- {
+- if (!frameOk && pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_IMDCT) {
+- /* LPC extrapolation */
+- CLpc_Conceal(pAacDecoderChannelInfo->data.usac.lsp_coeff,
+- pAacDecoderStaticChannelInfo->lpc4_lsf,
+- pAacDecoderStaticChannelInfo->lsf_adaptive_mean,
+- hConcealmentInfo->lastRenderMode == AACDEC_RENDER_IMDCT);
+- FDKmemcpy(hConcealmentInfo->lsf4, pAacDecoderStaticChannelInfo->lpc4_lsf,
+- sizeof(pAacDecoderStaticChannelInfo->lpc4_lsf));
+- }
+-
+- /* Create data for signal rendering according to the selected concealment
+- * method and decoder operating mode. */
+-
+- if ((!frameOk || mute_release_active) &&
+- (pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD)) {
+- /* Restore old LSF4 */
+- FDKmemcpy(pAacDecoderStaticChannelInfo->lpc4_lsf, hConcealmentInfo->lsf4,
+- sizeof(pAacDecoderStaticChannelInfo->lpc4_lsf));
+- /* Restore old TCX gain */
+- pAacDecoderStaticChannelInfo->last_tcx_gain =
+- hConcealmentInfo->last_tcx_gain;
+- pAacDecoderStaticChannelInfo->last_tcx_gain_e =
+- hConcealmentInfo->last_tcx_gain_e;
+- }
+-
+- if (!(pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD &&
+- pAacDecoderStaticChannelInfo->last_lpd_mode == 0)) {
+- switch (hConcealmentInfo->pConcealParams->method) {
+- default:
+- case ConcealMethodMute:
+- if (!frameOk) {
+- /* Mute spectral data in case of errors */
+- FDKmemclear(pAacDecoderChannelInfo->pSpectralCoefficient,
+- samplesPerFrame * sizeof(FIXP_DBL));
+- /* Set last window shape */
+- pAacDecoderChannelInfo->icsInfo.WindowShape =
+- hConcealmentInfo->windowShape;
+- appliedProcessing = 1;
+- }
+- break;
+-
+- case ConcealMethodNoise:
+- /* Noise substitution error concealment technique */
+- appliedProcessing = CConcealment_ApplyNoise(
+- hConcealmentInfo, pAacDecoderChannelInfo,
+- pAacDecoderStaticChannelInfo, pSamplingRateInfo, samplesPerFrame,
+- flags);
+- break;
+-
+- case ConcealMethodInter:
+- /* Energy interpolation concealment based on 3GPP */
+- appliedProcessing = CConcealment_ApplyInter(
+- hConcealmentInfo, pAacDecoderChannelInfo, pSamplingRateInfo,
+- samplesPerFrame, 0, /* don't use tonal improvement */
+- frameOk, mute_release_active);
+- break;
+- }
+- } else if (!frameOk || mute_release_active) {
+- /* simply restore the buffer */
+- FIXP_DBL *pSpectralCoefficient =
+- SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
+- SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
+- CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
+-#if (CNCL_FRACT_BITS != DFRACT_BITS)
+- FIXP_CNCL *RESTRICT pCncl =
+- &hConcealmentInfo->spectralCoefficient[1024 - 1];
+- FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
+- int i;
+-#endif
+-
+- /* restore window infos (gri) do we need that? */
+- pIcsInfo->WindowSequence = hConcealmentInfo->windowSequence;
+- pIcsInfo->WindowShape = hConcealmentInfo->windowShape;
+-
+- if (hConcealmentInfo->concealState != ConcealState_Mute) {
+- /* restore scale factors */
+- FDKmemcpy(pSpecScale, hConcealmentInfo->specScale, 8 * sizeof(SHORT));
+-
+- /* restore spectral bins */
+-#if (CNCL_FRACT_BITS == DFRACT_BITS)
+- FDKmemcpy(pSpectralCoefficient, hConcealmentInfo->spectralCoefficient,
+- 1024 * sizeof(FIXP_DBL));
+-#else
+- for (i = 1024; i != 0; i--) {
+- *pSpec-- = FX_CNCL2FX_DBL(*pCncl--);
+- }
+-#endif
+- } else {
+- /* clear scale factors */
+- FDKmemclear(pSpecScale, 8 * sizeof(SHORT));
+-
+- /* clear buffer */
+- FDKmemclear(pSpectralCoefficient, 1024 * sizeof(FIXP_CNCL));
+- }
+- }
+- }
+- /* update history */
+- hConcealmentInfo->prevFrameOk[0] = hConcealmentInfo->prevFrameOk[1];
+- hConcealmentInfo->prevFrameOk[1] = frameOk;
+-
+- return mute_release_active ? -1 : appliedProcessing;
+-}
+-
+-/*!
+-\brief Apply concealment noise substitution
+-
+- In case of frame lost this function produces a noisy frame with respect to the
+- energies values of past frame.
+- */
+-static int CConcealment_ApplyNoise(
+- CConcealmentInfo *pConcealmentInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
+- const UINT flags) {
+- FIXP_DBL *pSpectralCoefficient =
+- SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
+- CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
+-
+- int appliedProcessing = 0;
+-
+- FDK_ASSERT(pConcealmentInfo != NULL);
+- FDK_ASSERT((samplesPerFrame >= 120) && (samplesPerFrame <= 1024));
+-
+- switch (pConcealmentInfo->concealState) {
+- case ConcealState_Ok:
+- /* Nothing to do here! */
+- break;
+-
+- case ConcealState_Single:
+- case ConcealState_FadeOut:
+- appliedProcessing = CConcealment_ApplyFadeOut(
+- /*mode =*/1, pConcealmentInfo, pAacDecoderStaticChannelInfo,
+- samplesPerFrame, pAacDecoderChannelInfo);
+- break;
+-
+- case ConcealState_Mute: {
+- /* set dummy window parameters */
+- pIcsInfo->Valid = 0; /* Trigger the generation of a consitent IcsInfo */
+- pIcsInfo->WindowShape =
+- pConcealmentInfo->windowShape; /* Prevent an invalid WindowShape
+- (required for F/T transform) */
+- pIcsInfo->WindowSequence =
+- CConcealment_GetWinSeq(pConcealmentInfo->windowSequence);
+- pConcealmentInfo->windowSequence =
+- pIcsInfo->WindowSequence; /* Store for next frame
+- (spectrum in concealment
+- buffer can't be used at
+- all) */
+-
+- /* mute spectral data */
+- FDKmemclear(pSpectralCoefficient, samplesPerFrame * sizeof(FIXP_DBL));
+- FDKmemclear(pConcealmentInfo->spectralCoefficient,
+- samplesPerFrame * sizeof(FIXP_DBL));
+-
+- appliedProcessing = 1;
+- } break;
+-
+- case ConcealState_FadeIn: {
+- /* TimeDomainFading: */
+- /* Attenuation of signal is done in CConcealment_TDFading() */
+-
+- appliedProcessing = 1;
+- } break;
+-
+- default:
+- /* we shouldn't come here anyway */
+- FDK_ASSERT(0);
+- break;
+- }
+-
+- return appliedProcessing;
+-}
+-
+-/*!
+- \brief Apply concealment interpolation
+-
+- The function swaps the data from the current and the previous frame. If an
+- error has occured, frame interpolation is performed to restore the missing
+- frame. In case of multiple faulty frames, fade-in and fade-out is applied.
+-*/
+-static int CConcealment_ApplyInter(
+- CConcealmentInfo *pConcealmentInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
+- const int improveTonal, const int frameOk, const int mute_release_active) {
+-#if defined(FDK_ASSERT_ENABLE)
+- CConcealParams *pConcealCommonData = pConcealmentInfo->pConcealParams;
+-#endif
+-
+- FIXP_DBL *pSpectralCoefficient =
+- SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
+- CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
+- SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
+-
+- int sfbEnergyPrev[64];
+- int sfbEnergyAct[64];
+-
+- int i, appliedProcessing = 0;
+-
+- /* clear/init */
+- FDKmemclear(sfbEnergyPrev, 64 * sizeof(int));
+- FDKmemclear(sfbEnergyAct, 64 * sizeof(int));
+-
+- if (!frameOk || mute_release_active) {
+- /* Restore last frame from concealment buffer */
+- pIcsInfo->WindowShape = pConcealmentInfo->windowShape;
+- pIcsInfo->WindowSequence = pConcealmentInfo->windowSequence;
+-
+- /* Restore spectral data */
+- for (i = 0; i < samplesPerFrame; i++) {
+- pSpectralCoefficient[i] =
+- FX_CNCL2FX_DBL(pConcealmentInfo->spectralCoefficient[i]);
+- }
+-
+- /* Restore scale factors */
+- FDKmemcpy(pSpecScale, pConcealmentInfo->specScale, 8 * sizeof(SHORT));
+- }
+-
+- /* if previous frame was not ok */
+- if (!pConcealmentInfo->prevFrameOk[1] || mute_release_active) {
+- /* if current frame (f_n) is ok and the last but one frame (f_(n-2))
+- was ok, too, then interpolate both frames in order to generate
+- the current output frame (f_(n-1)). Otherwise, use the last stored
+- frame (f_(n-2) or f_(n-3) or ...). */
+- if (frameOk && pConcealmentInfo->prevFrameOk[0] && !mute_release_active) {
+- appliedProcessing = 1;
+-
+- /* Interpolate both frames in order to generate the current output frame
+- * (f_(n-1)). */
+- if (pIcsInfo->WindowSequence == BLOCK_SHORT) {
+- /* f_(n-2) == BLOCK_SHORT */
+- /* short--??????--short, short--??????--long interpolation */
+- /* short--short---short, short---long---long interpolation */
+-
+- int wnd;
+-
+- if (pConcealmentInfo->windowSequence ==
+- BLOCK_SHORT) { /* f_n == BLOCK_SHORT */
+- /* short--short---short interpolation */
+-
+- int scaleFactorBandsTotal =
+- pSamplingRateInfo->NumberOfScaleFactorBands_Short;
+- const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
+- pIcsInfo->WindowShape = (samplesPerFrame <= 512) ? 2 : 1;
+- pIcsInfo->WindowSequence = BLOCK_SHORT;
+-
+- for (wnd = 0; wnd < 8; wnd++) {
+- CConcealment_CalcBandEnergy(
+- &pSpectralCoefficient[wnd *
+- (samplesPerFrame / 8)], /* spec_(n-2) */
+- pSamplingRateInfo, BLOCK_SHORT, CConcealment_NoExpand,
+- sfbEnergyPrev);
+-
+- CConcealment_CalcBandEnergy(
+- &pConcealmentInfo->spectralCoefficient[wnd * (samplesPerFrame /
+- 8)], /* spec_n */
+- pSamplingRateInfo, BLOCK_SHORT, CConcealment_NoExpand,
+- sfbEnergyAct);
+-
+- CConcealment_InterpolateBuffer(
+- &pSpectralCoefficient[wnd *
+- (samplesPerFrame / 8)], /* spec_(n-1) */
+- &pSpecScale[wnd], &pConcealmentInfo->specScale[wnd],
+- &pSpecScale[wnd], sfbEnergyPrev, sfbEnergyAct,
+- scaleFactorBandsTotal, pSfbOffset);
+- }
+- } else { /* f_n != BLOCK_SHORT */
+- /* short---long---long interpolation */
+-
+- int scaleFactorBandsTotal =
+- pSamplingRateInfo->NumberOfScaleFactorBands_Long;
+- const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
+- SHORT specScaleOut;
+-
+- CConcealment_CalcBandEnergy(
+- &pSpectralCoefficient[samplesPerFrame -
+- (samplesPerFrame /
+- 8)], /* [wnd] spec_(n-2) */
+- pSamplingRateInfo, BLOCK_SHORT, CConcealment_Expand,
+- sfbEnergyAct);
+-
+- CConcealment_CalcBandEnergy(
+- pConcealmentInfo->spectralCoefficient, /* spec_n */
+- pSamplingRateInfo, BLOCK_LONG, CConcealment_NoExpand,
+- sfbEnergyPrev);
+-
+- pIcsInfo->WindowShape = 0;
+- pIcsInfo->WindowSequence = BLOCK_STOP;
+-
+- for (i = 0; i < samplesPerFrame; i++) {
+- pSpectralCoefficient[i] =
+- pConcealmentInfo->spectralCoefficient[i]; /* spec_n */
+- }
+-
+- for (i = 0; i < 8; i++) { /* search for max(specScale) */
+- if (pSpecScale[i] > pSpecScale[0]) {
+- pSpecScale[0] = pSpecScale[i];
+- }
+- }
+-
+- CConcealment_InterpolateBuffer(
+- pSpectralCoefficient, /* spec_(n-1) */
+- &pConcealmentInfo->specScale[0], &pSpecScale[0], &specScaleOut,
+- sfbEnergyPrev, sfbEnergyAct, scaleFactorBandsTotal, pSfbOffset);
+-
+- pSpecScale[0] = specScaleOut;
+- }
+- } else {
+- /* long--??????--short, long--??????--long interpolation */
+- /* long---long---short, long---long---long interpolation */
+-
+- int scaleFactorBandsTotal =
+- pSamplingRateInfo->NumberOfScaleFactorBands_Long;
+- const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
+- SHORT specScaleAct = pConcealmentInfo->specScale[0];
+-
+- CConcealment_CalcBandEnergy(pSpectralCoefficient, /* spec_(n-2) */
+- pSamplingRateInfo, BLOCK_LONG,
+- CConcealment_NoExpand, sfbEnergyPrev);
+-
+- if (pConcealmentInfo->windowSequence ==
+- BLOCK_SHORT) { /* f_n == BLOCK_SHORT */
+- /* long---long---short interpolation */
+-
+- pIcsInfo->WindowShape = (samplesPerFrame <= 512) ? 2 : 1;
+- pIcsInfo->WindowSequence = BLOCK_START;
+-
+- for (i = 1; i < 8; i++) { /* search for max(specScale) */
+- if (pConcealmentInfo->specScale[i] > specScaleAct) {
+- specScaleAct = pConcealmentInfo->specScale[i];
+- }
+- }
+-
+- /* Expand first short spectrum */
+- CConcealment_CalcBandEnergy(
+- pConcealmentInfo->spectralCoefficient, /* spec_n */
+- pSamplingRateInfo, BLOCK_SHORT, CConcealment_Expand, /* !!! */
+- sfbEnergyAct);
+- } else {
+- /* long---long---long interpolation */
+-
+- pIcsInfo->WindowShape = 0;
+- pIcsInfo->WindowSequence = BLOCK_LONG;
+-
+- CConcealment_CalcBandEnergy(
+- pConcealmentInfo->spectralCoefficient, /* spec_n */
+- pSamplingRateInfo, BLOCK_LONG, CConcealment_NoExpand,
+- sfbEnergyAct);
+- }
+-
+- CConcealment_InterpolateBuffer(
+- pSpectralCoefficient, /* spec_(n-1) */
+- &pSpecScale[0], &specScaleAct, &pSpecScale[0], sfbEnergyPrev,
+- sfbEnergyAct, scaleFactorBandsTotal, pSfbOffset);
+- }
+- }
+-
+- /* Noise substitution of sign of the output spectral coefficients */
+- CConcealment_ApplyRandomSign(pConcealmentInfo->iRandomPhase,
+- pSpectralCoefficient, samplesPerFrame);
+- /* Increment random phase index to avoid repetition artifacts. */
+- pConcealmentInfo->iRandomPhase =
+- (pConcealmentInfo->iRandomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
+- }
+-
+- /* scale spectrum according to concealment state */
+- switch (pConcealmentInfo->concealState) {
+- case ConcealState_Single:
+- appliedProcessing = 1;
+- break;
+-
+- case ConcealState_FadeOut: {
+- FDK_ASSERT(pConcealmentInfo->cntFadeFrames >= 0);
+- FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
+- CONCEAL_MAX_NUM_FADE_FACTORS);
+- FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
+- pConcealCommonData->numFadeOutFrames);
+-
+- /* TimeDomainFading: */
+- /* Attenuation of signal is done in CConcealment_TDFading() */
+-
+- appliedProcessing = 1;
+- } break;
+-
+- case ConcealState_FadeIn: {
+- FDK_ASSERT(pConcealmentInfo->cntFadeFrames >= 0);
+- FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
+- CONCEAL_MAX_NUM_FADE_FACTORS);
+- FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
+- pConcealCommonData->numFadeInFrames);
+-
+- /* TimeDomainFading: */
+- /* Attenuation of signal is done in CConcealment_TDFading() */
+-
+- appliedProcessing = 1;
+- } break;
+-
+- case ConcealState_Mute: {
+- /* set dummy window parameters */
+- pIcsInfo->Valid = 0; /* Trigger the generation of a consitent IcsInfo */
+- pIcsInfo->WindowShape =
+- pConcealmentInfo->windowShape; /* Prevent an invalid WindowShape
+- (required for F/T transform) */
+- pIcsInfo->WindowSequence =
+- CConcealment_GetWinSeq(pConcealmentInfo->windowSequence);
+- pConcealmentInfo->windowSequence =
+- pIcsInfo->WindowSequence; /* Store for next frame
+- (spectrum in concealment
+- buffer can't be used at
+- all) */
+-
+- /* mute spectral data */
+- FDKmemclear(pSpectralCoefficient, samplesPerFrame * sizeof(FIXP_DBL));
+-
+- appliedProcessing = 1;
+- } break;
+-
+- default:
+- /* nothing to do here */
+- break;
+- }
+-
+- return appliedProcessing;
+-}
+-
+-/*!
+- \brief Calculate the spectral energy
+-
+- The function calculates band-wise the spectral energy. This is used for
+- frame interpolation.
+-*/
+-static void CConcealment_CalcBandEnergy(
+- FIXP_DBL *spectrum, const SamplingRateInfo *pSamplingRateInfo,
+- const int blockType, CConcealmentExpandType expandType, int *sfbEnergy) {
+- const SHORT *pSfbOffset;
+- int line, sfb, scaleFactorBandsTotal = 0;
+-
+- /* In the following calculations, enAccu is initialized with LSB-value in
+- * order to avoid zero energy-level */
+-
+- line = 0;
+-
+- switch (blockType) {
+- case BLOCK_LONG:
+- case BLOCK_START:
+- case BLOCK_STOP:
+-
+- if (expandType == CConcealment_NoExpand) {
+- /* standard long calculation */
+- scaleFactorBandsTotal =
+- pSamplingRateInfo->NumberOfScaleFactorBands_Long;
+- pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
+-
+- for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
+- FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
+- int sfbScale =
+- (sizeof(LONG) << 3) -
+- CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
+- /* scaling depends on sfb width. */
+- for (; line < pSfbOffset[sfb + 1]; line++) {
+- enAccu += fPow2Div2(*(spectrum + line)) >> sfbScale;
+- }
+- *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
+- }
+- } else {
+- /* compress long to short */
+- scaleFactorBandsTotal =
+- pSamplingRateInfo->NumberOfScaleFactorBands_Short;
+- pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
+-
+- for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
+- FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
+- int sfbScale =
+- (sizeof(LONG) << 3) -
+- CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
+- /* scaling depends on sfb width. */
+- for (; line < pSfbOffset[sfb + 1] << 3; line++) {
+- enAccu +=
+- (enAccu + (fPow2Div2(*(spectrum + line)) >> sfbScale)) >> 3;
+- }
+- *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
+- }
+- }
+- break;
+-
+- case BLOCK_SHORT:
+-
+- if (expandType == CConcealment_NoExpand) {
+- /* standard short calculation */
+- scaleFactorBandsTotal =
+- pSamplingRateInfo->NumberOfScaleFactorBands_Short;
+- pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
+-
+- for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
+- FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
+- int sfbScale =
+- (sizeof(LONG) << 3) -
+- CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
+- /* scaling depends on sfb width. */
+- for (; line < pSfbOffset[sfb + 1]; line++) {
+- enAccu += fPow2Div2(*(spectrum + line)) >> sfbScale;
+- }
+- *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
+- }
+- } else {
+- /* expand short to long spectrum */
+- scaleFactorBandsTotal =
+- pSamplingRateInfo->NumberOfScaleFactorBands_Long;
+- pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
+-
+- for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
+- FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
+- int sfbScale =
+- (sizeof(LONG) << 3) -
+- CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
+- /* scaling depends on sfb width. */
+- for (; line < pSfbOffset[sfb + 1]; line++) {
+- enAccu += fPow2Div2(*(spectrum + (line >> 3))) >> sfbScale;
+- }
+- *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
+- }
+- }
+- break;
+- }
+-}
+-
+-/*!
+- \brief Interpolate buffer
+-
+- The function creates the interpolated spectral data according to the
+- energy of the last good frame and the current (good) frame.
+-*/
+-static void CConcealment_InterpolateBuffer(FIXP_DBL *spectrum,
+- SHORT *pSpecScalePrv,
+- SHORT *pSpecScaleAct,
+- SHORT *pSpecScaleOut, int *enPrv,
+- int *enAct, int sfbCnt,
+- const SHORT *pSfbOffset) {
+- int sfb, line = 0;
+- int fac_shift;
+- int fac_mod;
+- FIXP_DBL accu;
+-
+- for (sfb = 0; sfb < sfbCnt; sfb++) {
+- fac_shift =
+- enPrv[sfb] - enAct[sfb] + ((*pSpecScaleAct - *pSpecScalePrv) << 1);
+- fac_mod = fac_shift & 3;
+- fac_shift = (fac_shift >> 2) + 1;
+- fac_shift += *pSpecScalePrv - fixMax(*pSpecScalePrv, *pSpecScaleAct);
+-
+- for (; line < pSfbOffset[sfb + 1]; line++) {
+- accu = fMult(*(spectrum + line), facMod4Table[fac_mod]);
+- if (fac_shift < 0) {
+- accu >>= -fac_shift;
+- } else {
+- accu <<= fac_shift;
+- }
+- *(spectrum + line) = accu;
+- }
+- }
+- *pSpecScaleOut = fixMax(*pSpecScalePrv, *pSpecScaleAct);
+-}
+-
+-/*!
+- \brief Find next fading frame in case of changing fading direction
+-
+- \param pConcealCommonData Pointer to the concealment common data structure.
+- \param actFadeIndex Last index used for fading
+- \param direction Direction of change: 0 : change from FADE-OUT to FADE-IN, 1
+- : change from FADE-IN to FADE-OUT
+-
+- This function determines the next fading index to be used for the fading
+- direction to be changed to.
+-*/
+-
+-static INT findEquiFadeFrame(CConcealParams *pConcealCommonData,
+- INT actFadeIndex, int direction) {
+- FIXP_SGL *pFactor;
+- FIXP_SGL referenceVal;
+- FIXP_SGL minDiff = (FIXP_SGL)MAXVAL_SGL;
+-
+- INT nextFadeIndex = 0;
+-
+- int i;
+-
+- /* init depending on direction */
+- if (direction == 0) { /* FADE-OUT => FADE-IN */
+- if (actFadeIndex < 0) {
+- referenceVal = (FIXP_SGL)MAXVAL_SGL;
+- } else {
+- referenceVal = pConcealCommonData->fadeOutFactor[actFadeIndex] >> 1;
+- }
+- pFactor = pConcealCommonData->fadeInFactor;
+- } else { /* FADE-IN => FADE-OUT */
+- if (actFadeIndex < 0) {
+- referenceVal = (FIXP_SGL)MAXVAL_SGL;
+- } else {
+- referenceVal = pConcealCommonData->fadeInFactor[actFadeIndex] >> 1;
+- }
+- pFactor = pConcealCommonData->fadeOutFactor;
+- }
+-
+- /* search for minimum difference */
+- for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
+- FIXP_SGL diff = fixp_abs((pFactor[i] >> 1) - referenceVal);
+- if (diff < minDiff) {
+- minDiff = diff;
+- nextFadeIndex = i;
+- }
+- }
+-
+- /* check and adjust depending on direction */
+- if (direction == 0) { /* FADE-OUT => FADE-IN */
+- if (nextFadeIndex > pConcealCommonData->numFadeInFrames) {
+- nextFadeIndex = fMax(pConcealCommonData->numFadeInFrames - 1, 0);
+- }
+- if (((pFactor[nextFadeIndex] >> 1) <= referenceVal) &&
+- (nextFadeIndex > 0)) {
+- nextFadeIndex -= 1;
+- }
+- } else { /* FADE-IN => FADE-OUT */
+- if (((pFactor[nextFadeIndex] >> 1) >= referenceVal) &&
+- (nextFadeIndex < CONCEAL_MAX_NUM_FADE_FACTORS - 1)) {
+- nextFadeIndex += 1;
+- }
+- }
+-
+- return (nextFadeIndex);
+-}
+-
+-/*!
+- \brief Update the concealment state
+-
+- The function updates the state of the concealment state-machine. The
+- states are: mute, fade-in, fade-out, interpolate and frame-ok.
+-*/
+-static void CConcealment_UpdateState(
+- CConcealmentInfo *pConcealmentInfo, int frameOk,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
+- CConcealParams *pConcealCommonData = pConcealmentInfo->pConcealParams;
+-
+- switch (pConcealCommonData->method) {
+- case ConcealMethodNoise: {
+- if (pConcealmentInfo->concealState != ConcealState_Ok) {
+- /* count the valid frames during concealment process */
+- if (frameOk) {
+- pConcealmentInfo->cntValidFrames += 1;
+- } else {
+- pConcealmentInfo->cntValidFrames = 0;
+- }
+- }
+-
+- /* -- STATE MACHINE for Noise Substitution -- */
+- switch (pConcealmentInfo->concealState) {
+- case ConcealState_Ok:
+- if (!frameOk) {
+- pConcealmentInfo->cntFadeFrames = 0;
+- pConcealmentInfo->cntValidFrames = 0;
+- pConcealmentInfo->attGrpOffset[0] = 0;
+- pConcealmentInfo->attGrpOffset[1] = 0;
+- pConcealmentInfo->winGrpOffset[0] = 0;
+- pConcealmentInfo->winGrpOffset[1] = 0;
+- if (pConcealCommonData->numFadeOutFrames > 0) {
+- /* change to state SINGLE-FRAME-LOSS */
+- pConcealmentInfo->concealState = ConcealState_Single;
+- /* mode 0 just updates the Fading counter */
+- CConcealment_ApplyFadeOut(
+- /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
+- samplesPerFrame, pAacDecoderChannelInfo);
+-
+- } else {
+- /* change to state MUTE */
+- pConcealmentInfo->concealState = ConcealState_Mute;
+- }
+- }
+- break;
+-
+- case ConcealState_Single: /* Just a pre-stage before fade-out begins.
+- Stay here only one frame! */
+- if (frameOk) {
+- /* change to state OK */
+- pConcealmentInfo->concealState = ConcealState_Ok;
+- } else {
+- if (pConcealmentInfo->cntFadeFrames >=
+- pConcealCommonData->numFadeOutFrames) {
+- /* change to state MUTE */
+- pConcealmentInfo->concealState = ConcealState_Mute;
+- } else {
+- /* change to state FADE-OUT */
+- pConcealmentInfo->concealState = ConcealState_FadeOut;
+- /* mode 0 just updates the Fading counter */
+- CConcealment_ApplyFadeOut(
+- /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
+- samplesPerFrame, pAacDecoderChannelInfo);
+- }
+- }
+- break;
+-
+- case ConcealState_FadeOut:
+- if (pConcealmentInfo->cntValidFrames >
+- pConcealCommonData->numMuteReleaseFrames) {
+- if (pConcealCommonData->numFadeInFrames > 0) {
+- /* change to state FADE-IN */
+- pConcealmentInfo->concealState = ConcealState_FadeIn;
+- pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
+- pConcealCommonData, pConcealmentInfo->cntFadeFrames,
+- 0 /* FadeOut -> FadeIn */);
+- } else {
+- /* change to state OK */
+- pConcealmentInfo->concealState = ConcealState_Ok;
+- }
+- } else {
+- if (frameOk) {
+- /* we have good frame information but stay fully in concealment -
+- * reset winGrpOffset/attGrpOffset */
+- pConcealmentInfo->winGrpOffset[0] = 0;
+- pConcealmentInfo->winGrpOffset[1] = 0;
+- pConcealmentInfo->attGrpOffset[0] = 0;
+- pConcealmentInfo->attGrpOffset[1] = 0;
+- }
+- if (pConcealmentInfo->cntFadeFrames >=
+- pConcealCommonData->numFadeOutFrames) {
+- /* change to state MUTE */
+- pConcealmentInfo->concealState = ConcealState_Mute;
+- } else /* Stay in FADE-OUT */
+- {
+- /* mode 0 just updates the Fading counter */
+- CConcealment_ApplyFadeOut(
+- /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
+- samplesPerFrame, pAacDecoderChannelInfo);
+- }
+- }
+- break;
+-
+- case ConcealState_Mute:
+- if (pConcealmentInfo->cntValidFrames >
+- pConcealCommonData->numMuteReleaseFrames) {
+- if (pConcealCommonData->numFadeInFrames > 0) {
+- /* change to state FADE-IN */
+- pConcealmentInfo->concealState = ConcealState_FadeIn;
+- pConcealmentInfo->cntFadeFrames =
+- pConcealCommonData->numFadeInFrames - 1;
+- } else {
+- /* change to state OK */
+- pConcealmentInfo->concealState = ConcealState_Ok;
+- }
+- } else {
+- if (frameOk) {
+- /* we have good frame information but stay fully in concealment -
+- * reset winGrpOffset/attGrpOffset */
+- pConcealmentInfo->winGrpOffset[0] = 0;
+- pConcealmentInfo->winGrpOffset[1] = 0;
+- pConcealmentInfo->attGrpOffset[0] = 0;
+- pConcealmentInfo->attGrpOffset[1] = 0;
+- }
+- }
+- break;
+-
+- case ConcealState_FadeIn:
+- pConcealmentInfo->cntFadeFrames -= 1;
+- if (frameOk) {
+- if (pConcealmentInfo->cntFadeFrames < 0) {
+- /* change to state OK */
+- pConcealmentInfo->concealState = ConcealState_Ok;
+- }
+- } else {
+- if (pConcealCommonData->numFadeOutFrames > 0) {
+- /* change to state FADE-OUT */
+- pConcealmentInfo->concealState = ConcealState_FadeOut;
+- pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
+- pConcealCommonData, pConcealmentInfo->cntFadeFrames + 1,
+- 1 /* FadeIn -> FadeOut */);
+- pConcealmentInfo->winGrpOffset[0] = 0;
+- pConcealmentInfo->winGrpOffset[1] = 0;
+- pConcealmentInfo->attGrpOffset[0] = 0;
+- pConcealmentInfo->attGrpOffset[1] = 0;
+-
+- pConcealmentInfo
+- ->cntFadeFrames--; /* decrease because
+- CConcealment_ApplyFadeOut() will
+- increase, accordingly */
+- /* mode 0 just updates the Fading counter */
+- CConcealment_ApplyFadeOut(
+- /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
+- samplesPerFrame, pAacDecoderChannelInfo);
+- } else {
+- /* change to state MUTE */
+- pConcealmentInfo->concealState = ConcealState_Mute;
+- }
+- }
+- break;
+-
+- default:
+- FDK_ASSERT(0);
+- break;
+- }
+- } break;
+-
+- case ConcealMethodInter:
+- case ConcealMethodTonal: {
+- if (pConcealmentInfo->concealState != ConcealState_Ok) {
+- /* count the valid frames during concealment process */
+- if (pConcealmentInfo->prevFrameOk[1] ||
+- (pConcealmentInfo->prevFrameOk[0] &&
+- !pConcealmentInfo->prevFrameOk[1] && frameOk)) {
+- /* The frame is OK even if it can be estimated by the energy
+- * interpolation algorithm */
+- pConcealmentInfo->cntValidFrames += 1;
+- } else {
+- pConcealmentInfo->cntValidFrames = 0;
+- }
+- }
+-
+- /* -- STATE MACHINE for energy interpolation -- */
+- switch (pConcealmentInfo->concealState) {
+- case ConcealState_Ok:
+- if (!(pConcealmentInfo->prevFrameOk[1] ||
+- (pConcealmentInfo->prevFrameOk[0] &&
+- !pConcealmentInfo->prevFrameOk[1] && frameOk))) {
+- if (pConcealCommonData->numFadeOutFrames > 0) {
+- /* Fade out only if the energy interpolation algorithm can not be
+- * applied! */
+- pConcealmentInfo->concealState = ConcealState_FadeOut;
+- } else {
+- /* change to state MUTE */
+- pConcealmentInfo->concealState = ConcealState_Mute;
+- }
+- pConcealmentInfo->cntFadeFrames = 0;
+- pConcealmentInfo->cntValidFrames = 0;
+- }
+- break;
+-
+- case ConcealState_Single:
+- pConcealmentInfo->concealState = ConcealState_Ok;
+- break;
+-
+- case ConcealState_FadeOut:
+- pConcealmentInfo->cntFadeFrames += 1;
+-
+- if (pConcealmentInfo->cntValidFrames >
+- pConcealCommonData->numMuteReleaseFrames) {
+- if (pConcealCommonData->numFadeInFrames > 0) {
+- /* change to state FADE-IN */
+- pConcealmentInfo->concealState = ConcealState_FadeIn;
+- pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
+- pConcealCommonData, pConcealmentInfo->cntFadeFrames - 1,
+- 0 /* FadeOut -> FadeIn */);
+- } else {
+- /* change to state OK */
+- pConcealmentInfo->concealState = ConcealState_Ok;
+- }
+- } else {
+- if (pConcealmentInfo->cntFadeFrames >=
+- pConcealCommonData->numFadeOutFrames) {
+- /* change to state MUTE */
+- pConcealmentInfo->concealState = ConcealState_Mute;
+- }
+- }
+- break;
+-
+- case ConcealState_Mute:
+- if (pConcealmentInfo->cntValidFrames >
+- pConcealCommonData->numMuteReleaseFrames) {
+- if (pConcealCommonData->numFadeInFrames > 0) {
+- /* change to state FADE-IN */
+- pConcealmentInfo->concealState = ConcealState_FadeIn;
+- pConcealmentInfo->cntFadeFrames =
+- pConcealCommonData->numFadeInFrames - 1;
+- } else {
+- /* change to state OK */
+- pConcealmentInfo->concealState = ConcealState_Ok;
+- }
+- }
+- break;
+-
+- case ConcealState_FadeIn:
+- pConcealmentInfo->cntFadeFrames -=
+- 1; /* used to address the fade-in factors */
+-
+- if (frameOk || pConcealmentInfo->prevFrameOk[1]) {
+- if (pConcealmentInfo->cntFadeFrames < 0) {
+- /* change to state OK */
+- pConcealmentInfo->concealState = ConcealState_Ok;
+- }
+- } else {
+- if (pConcealCommonData->numFadeOutFrames > 0) {
+- /* change to state FADE-OUT */
+- pConcealmentInfo->concealState = ConcealState_FadeOut;
+- pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
+- pConcealCommonData, pConcealmentInfo->cntFadeFrames + 1,
+- 1 /* FadeIn -> FadeOut */);
+- } else {
+- /* change to state MUTE */
+- pConcealmentInfo->concealState = ConcealState_Mute;
+- }
+- }
+- break;
+- } /* End switch(pConcealmentInfo->concealState) */
+- } break;
+-
+- default:
+- /* Don't need a state machine for other concealment methods. */
+- break;
+- }
+-}
+-
+-/*!
+-\brief Randomizes the sign of the spectral data
+-
+- The function toggles the sign of the spectral data randomly. This is
+- useful to ensure the quality of the concealed frames.
+- */
+-static void CConcealment_ApplyRandomSign(int randomPhase, FIXP_DBL *spec,
+- int samplesPerFrame) {
+- int i;
+- USHORT packedSign = 0;
+-
+- /* random table 512x16bit has been reduced to 512 packed sign bits = 32x16 bit
+- */
+-
+- /* read current packed sign word */
+- packedSign = AacDec_randomSign[randomPhase >> 4];
+- packedSign >>= (randomPhase & 0xf);
+-
+- for (i = 0; i < samplesPerFrame; i++) {
+- if ((randomPhase & 0xf) == 0) {
+- packedSign = AacDec_randomSign[randomPhase >> 4];
+- }
+-
+- if (packedSign & 0x1) {
+- spec[i] = -spec[i];
+- }
+- packedSign >>= 1;
+-
+- randomPhase = (randomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
+- }
+-}
+-
+-/*!
+- \brief Get fadeing factor for current concealment state.
+-
+- The function returns the state (ok or not) of the previous frame.
+- If called before the function CConcealment_Apply() set the fBeforeApply
+- flag to get the correct value.
+-
+- \return Frame OK flag of previous frame.
+- */
+-int CConcealment_GetLastFrameOk(CConcealmentInfo *hConcealmentInfo,
+- const int fBeforeApply) {
+- int prevFrameOk = 1;
+-
+- if (hConcealmentInfo != NULL) {
+- prevFrameOk = hConcealmentInfo->prevFrameOk[fBeforeApply & 0x1];
+- }
+-
+- return prevFrameOk;
+-}
+-
+-/*!
+- \brief Get the number of delay frames introduced by concealment technique.
+-
+- \return Number of delay frames.
+- */
+-UINT CConcealment_GetDelay(CConcealParams *pConcealCommonData) {
+- UINT frameDelay = 0;
+-
+- if (pConcealCommonData != NULL) {
+- switch (pConcealCommonData->method) {
+- case ConcealMethodTonal:
+- case ConcealMethodInter:
+- frameDelay = 1;
+- break;
+- default:
+- break;
+- }
+- }
+-
+- return frameDelay;
+-}
+-
+-static int CConcealment_ApplyFadeOut(
+- int mode, CConcealmentInfo *pConcealmentInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
+- /* mode 1 = apply RandomSign and mute spectral coefficients if necessary, *
+- * mode 0 = Update cntFadeFrames */
+-
+- /* restore frequency coefficients from buffer with a specific muting */
+- int srcWin, dstWin, numWindows = 1;
+- int windowLen = samplesPerFrame;
+- int srcGrpStart = 0;
+- int winIdxStride = 1;
+- int numWinGrpPerFac, attIdx, attIdxStride;
+- int i;
+- int appliedProcessing = 0;
+-
+- CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
+- FIXP_DBL *pSpectralCoefficient =
+- SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
+- SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
+-
+- /* set old window parameters */
+- if (pConcealmentInfo->lastRenderMode == AACDEC_RENDER_LPD) {
+- switch (pAacDecoderStaticChannelInfo->last_lpd_mode) {
+- case 1:
+- numWindows = 4;
+- srcGrpStart = 3;
+- windowLen = samplesPerFrame >> 2;
+- break;
+- case 2:
+- numWindows = 2;
+- srcGrpStart = 1;
+- windowLen = samplesPerFrame >> 1;
+- winIdxStride = 2;
+- break;
+- case 3:
+- numWindows = 1;
+- srcGrpStart = 0;
+- windowLen = samplesPerFrame;
+- winIdxStride = 4;
+- break;
+- }
+- pConcealmentInfo->lastWinGrpLen = 1;
+- } else {
+- pIcsInfo->WindowShape = pConcealmentInfo->windowShape;
+- pIcsInfo->WindowSequence = pConcealmentInfo->windowSequence;
+-
+- if (pConcealmentInfo->windowSequence == BLOCK_SHORT) {
+- /* short block handling */
+- numWindows = 8;
+- windowLen = samplesPerFrame >> 3;
+- srcGrpStart = numWindows - pConcealmentInfo->lastWinGrpLen;
+- }
+- }
+-
+- attIdxStride =
+- fMax(1, (int)(numWindows / (pConcealmentInfo->lastWinGrpLen + 1)));
+-
+- /* load last state */
+- attIdx = pConcealmentInfo->cntFadeFrames;
+- numWinGrpPerFac = pConcealmentInfo->attGrpOffset[mode];
+- srcWin = srcGrpStart + pConcealmentInfo->winGrpOffset[mode];
+-
+- FDK_ASSERT((srcGrpStart * windowLen + windowLen) <= samplesPerFrame);
+- FDK_ASSERT((srcWin * windowLen + windowLen) <= 1024);
+-
+- for (dstWin = 0; dstWin < numWindows; dstWin += 1) {
+- FIXP_CNCL *pCncl =
+- pConcealmentInfo->spectralCoefficient + (srcWin * windowLen);
+- FIXP_DBL *pOut = pSpectralCoefficient + (dstWin * windowLen);
+-
+- if (mode == 1) {
+- /* mute if attIdx gets large enaugh */
+- if (attIdx > pConcealmentInfo->pConcealParams->numFadeOutFrames) {
+- FDKmemclear(pCncl, sizeof(FIXP_DBL) * windowLen);
+- }
+-
+- /* restore frequency coefficients from buffer - attenuation is done later
+- */
+- for (i = 0; i < windowLen; i++) {
+- pOut[i] = pCncl[i];
+- }
+-
+- /* apply random change of sign for spectral coefficients */
+- CConcealment_ApplyRandomSign(pConcealmentInfo->iRandomPhase, pOut,
+- windowLen);
+-
+- /* Increment random phase index to avoid repetition artifacts. */
+- pConcealmentInfo->iRandomPhase =
+- (pConcealmentInfo->iRandomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
+-
+- /* set old scale factors */
+- pSpecScale[dstWin * winIdxStride] =
+- pConcealmentInfo->specScale[srcWin * winIdxStride];
+- }
+-
+- srcWin += 1;
+-
+- if (srcWin >= numWindows) {
+- /* end of sequence -> rewind to first window of group */
+- srcWin = srcGrpStart;
+- numWinGrpPerFac += 1;
+- if (numWinGrpPerFac >= attIdxStride) {
+- numWinGrpPerFac = 0;
+- attIdx += 1;
+- }
+- }
+- }
+-
+- /* store current state */
+-
+- pConcealmentInfo->winGrpOffset[mode] = srcWin - srcGrpStart;
+- FDK_ASSERT((pConcealmentInfo->winGrpOffset[mode] >= 0) &&
+- (pConcealmentInfo->winGrpOffset[mode] < 8));
+- pConcealmentInfo->attGrpOffset[mode] = numWinGrpPerFac;
+- FDK_ASSERT((pConcealmentInfo->attGrpOffset[mode] >= 0) &&
+- (pConcealmentInfo->attGrpOffset[mode] < attIdxStride));
+-
+- if (mode == 0) {
+- pConcealmentInfo->cntFadeFrames = attIdx;
+- }
+-
+- appliedProcessing = 1;
+-
+- return appliedProcessing;
+-}
+-
+-/*!
+- \brief Do Time domain fading (TDFading) in concealment case
+-
+- In case of concealment, this function takes care of the fading, after time
+-domain signal has been rendered by the respective signal rendering functions.
+- The fading out in case of ACELP decoding is not done by this function but by
+-the ACELP decoder for the first concealed frame if CONCEAL_CORE_IGNORANT_FADE is
+-not set.
+-
+- TimeDomain fading never creates jumps in energy / discontinuities, it always
+-does a continuous fading. To achieve this, fading is always done from a starting
+-point to a target point, while the starting point is always determined to be the
+-last target point. By varying the target point of a fading, the fading slope can
+-be controlled.
+-
+- This principle is applied to the fading within a frame and the fading from
+-frame to frame.
+-
+- One frame is divided into 8 subframes to obtain 8 parts of fading slopes
+-within a frame, each maybe with its own gradient.
+-
+- Workflow:
+- 1.) Determine Fading behavior and end-of-frame target fading level, based on
+-concealmentState (determined by CConcealment_UpdateState()) and the core mode.
+- - By _DEFAULT_,
+- The target fading level is determined by fadeOutFactor[cntFadeFrames]
+-in case of fadeOut, or fadeInFactor[cntFadeFrames] in case of fadeIn.
+- --> fading type is FADE_TIMEDOMAIN in this case. Target fading level
+-is determined by fading index cntFadeFrames.
+-
+- - If concealmentState is signalling a _MUTED SIGNAL_,
+- TDFading decays to 0 within 1/8th of a frame if numFadeOutFrames == 0.
+- --> fading type is FADE_TIMEDOMAIN_TOSPECTRALMUTE in this case.
+-
+- - If concealmentState is signalling the _END OF MUTING_,
+- TDFading fades to target fading level within 1/8th of a frame if
+-numFadeInFrames == 0.
+- --> fading type is FADE_TIMEDOMAIN_FROMSPECTRALMUTE in this case.
+-Target fading level is determined by fading index cntFadeFrames.
+-
+-#ifndef CONCEAL_CORE_IGNORANT_FADE
+- - In case of an _ACELP FADEOUT_,
+- TDFading leaves fading control to ACELP decoder for 1/2 frame.
+- --> fading type is FADE_ACELPDOMAIN in this case.
+-#endif
+-
+- 2.) Render fading levels within current frame and do the final fading:
+- Map Fading slopes to fading levels and apply to time domain signal.
+-
+-
+-*/
+-
+-INT CConcealment_TDFading(
+- int len, CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo,
+- FIXP_PCM *pcmdata, FIXP_PCM *pcmdata_1) {
+- /*
+- Do the fading in Time domain based on concealment states and core mode
+- */
+- FIXP_DBL fadeStop, attMute = (FIXP_DBL)0;
+- int idx = 0, ii;
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo =
+- *ppAacDecoderStaticChannelInfo;
+- CConcealmentInfo *pConcealmentInfo =
+- &pAacDecoderStaticChannelInfo->concealmentInfo;
+- CConcealParams *pConcealParams = pConcealmentInfo->pConcealParams;
+- const CConcealmentState concealState = pConcealmentInfo->concealState;
+- TDfadingType fadingType;
+- FIXP_DBL fadingStations[9] = {0};
+- int fadingSteps[8] = {0};
+- const FIXP_DBL fadeStart =
+- pConcealmentInfo
+- ->fade_old; /* start fading at last end-of-frame attenuation */
+- FIXP_SGL *fadeFactor = pConcealParams->fadeOutFactor;
+- const INT cntFadeFrames = pConcealmentInfo->cntFadeFrames;
+- int TDFadeOutStopBeforeMute = 1;
+- int TDFadeInStopBeforeFullLevel = 1;
+-
+- /*
+- determine Fading behaviour (end-of-frame attenuation and fading type) (1.)
+- */
+-
+- switch (concealState) {
+- case ConcealState_Single:
+- case ConcealState_Mute:
+- case ConcealState_FadeOut:
+- idx = (pConcealParams->method == ConcealMethodNoise) ? cntFadeFrames - 1
+- : cntFadeFrames;
+- fadingType = FADE_TIMEDOMAIN;
+-
+- if (concealState == ConcealState_Mute ||
+- (cntFadeFrames + TDFadeOutStopBeforeMute) >
+- pConcealmentInfo->pConcealParams->numFadeOutFrames) {
+- fadingType = FADE_TIMEDOMAIN_TOSPECTRALMUTE;
+- }
+-
+- break;
+- case ConcealState_FadeIn:
+- idx = cntFadeFrames;
+- idx -= TDFadeInStopBeforeFullLevel;
+- FDK_FALLTHROUGH;
+- case ConcealState_Ok:
+- fadeFactor = pConcealParams->fadeInFactor;
+- idx = (concealState == ConcealState_Ok) ? -1 : idx;
+- fadingType = (pConcealmentInfo->concealState_old == ConcealState_Mute)
+- ? FADE_TIMEDOMAIN_FROMSPECTRALMUTE
+- : FADE_TIMEDOMAIN;
+- break;
+- default:
+- FDK_ASSERT(0);
+- fadingType = FADE_TIMEDOMAIN_TOSPECTRALMUTE;
+- break;
+- }
+-
+- /* determine Target end-of-frame fading level and fading slope */
+- switch (fadingType) {
+- case FADE_TIMEDOMAIN_FROMSPECTRALMUTE:
+- fadeStop =
+- (idx < 0) ? (FIXP_DBL)MAXVAL_DBL : FX_SGL2FX_DBL(fadeFactor[idx]);
+- if (pConcealmentInfo->pConcealParams->numFadeInFrames == 0) {
+- /* do step as fast as possible */
+- fadingSteps[0] = 1;
+- break;
+- }
+- CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
+- break;
+- case FADE_TIMEDOMAIN:
+- fadeStop =
+- (idx < 0) ? (FIXP_DBL)MAXVAL_DBL : FX_SGL2FX_DBL(fadeFactor[idx]);
+- CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
+- break;
+- case FADE_TIMEDOMAIN_TOSPECTRALMUTE:
+- fadeStop = attMute;
+- if (pConcealmentInfo->pConcealParams->numFadeOutFrames == 0) {
+- /* do step as fast as possible */
+- fadingSteps[0] = 1;
+- break;
+- }
+- CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
+- break;
+- }
+-
+- /*
+- Render fading levels within current frame and do the final fading (2.)
+- */
+-
+- len >>= 3;
+- CConcealment_TDFadeFillFadingStations(fadingStations, fadingSteps, fadeStop,
+- fadeStart, fadingType);
+-
+- if ((fadingStations[8] != (FIXP_DBL)MAXVAL_DBL) ||
+- (fadingStations[7] != (FIXP_DBL)MAXVAL_DBL) ||
+- (fadingStations[6] != (FIXP_DBL)MAXVAL_DBL) ||
+- (fadingStations[5] != (FIXP_DBL)MAXVAL_DBL) ||
+- (fadingStations[4] != (FIXP_DBL)MAXVAL_DBL) ||
+- (fadingStations[3] != (FIXP_DBL)MAXVAL_DBL) ||
+- (fadingStations[2] != (FIXP_DBL)MAXVAL_DBL) ||
+- (fadingStations[1] != (FIXP_DBL)MAXVAL_DBL) ||
+- (fadingStations[0] !=
+- (FIXP_DBL)MAXVAL_DBL)) /* if there's something to fade */
+- {
+- int start = 0;
+- for (ii = 0; ii < 8; ii++) {
+- CConcealment_TDFadePcmAtt(start, len, fadingStations[ii],
+- fadingStations[ii + 1], pcmdata);
+- start += len;
+- }
+- }
+- CConcealment_TDNoise_Apply(pConcealmentInfo, len, pcmdata);
+-
+- /* Save end-of-frame attenuation and fading type */
+- pConcealmentInfo->lastFadingType = fadingType;
+- pConcealmentInfo->fade_old = fadeStop;
+- pConcealmentInfo->concealState_old = concealState;
+-
+- return 1;
+-}
+-
+-/* attenuate pcmdata in Time Domain Fading process */
+-static void CConcealment_TDFadePcmAtt(int start, int len, FIXP_DBL fadeStart,
+- FIXP_DBL fadeStop, FIXP_PCM *pcmdata) {
+- int i;
+- FIXP_DBL dStep;
+- FIXP_DBL dGain;
+- FIXP_DBL dGain_apply;
+- int bitshift = (DFRACT_BITS - SAMPLE_BITS);
+-
+- /* set start energy */
+- dGain = fadeStart;
+- /* determine energy steps from sample to sample */
+- dStep = (FIXP_DBL)((int)((fadeStart >> 1) - (fadeStop >> 1)) / len) << 1;
+-
+- for (i = start; i < (start + len); i++) {
+- dGain -= dStep;
+- /* prevent gain from getting negative due to possible fixpoint inaccuracies
+- */
+- dGain_apply = fMax((FIXP_DBL)0, dGain);
+- /* finally, attenuate samples */
+- pcmdata[i] = (FIXP_PCM)((fMult(pcmdata[i], (dGain_apply))) >> bitshift);
+- }
+-}
+-
+-/*
+-\brief Fill FadingStations
+-
+-The fadingstations are the attenuation factors, being applied to its dedicated
+-portions of pcm data. They are calculated using the fadingsteps. One fadingstep
+-is the weighted contribution to the fading slope within its dedicated portion of
+-pcm data.
+-
+-*Fadingsteps : 0 0 0 1 0 1 2 0
+-
+- |<- 1 Frame pcm data ->|
+- fadeStart-->|__________ |
+- ^ ^ ^ ^ \____ |
+- Attenuation : | | | | ^ ^\__ |
+- | | | | | | ^\ |
+- | | | | | | | \___|<-- fadeStop
+- | | | | | | | ^ ^
+- | | | | | | | | |
+-Fadingstations: [0][1][2][3][4][5][6][7][8]
+-
+-(Fadingstations "[0]" is "[8] from previous frame", therefore its not meaningful
+-to be edited)
+-
+-*/
+-static void CConcealment_TDFadeFillFadingStations(FIXP_DBL *fadingStations,
+- int *fadingSteps,
+- FIXP_DBL fadeStop,
+- FIXP_DBL fadeStart,
+- TDfadingType fadingType) {
+- int i;
+- INT fadingSteps_sum = 0;
+- INT fadeDiff;
+-
+- fadingSteps_sum = fadingSteps[0] + fadingSteps[1] + fadingSteps[2] +
+- fadingSteps[3] + fadingSteps[4] + fadingSteps[5] +
+- fadingSteps[6] + fadingSteps[7];
+- fadeDiff = ((INT)(fadeStop - fadeStart) / fMax(fadingSteps_sum, (INT)1));
+- fadingStations[0] = fadeStart;
+- for (i = 1; i < 8; i++) {
+- fadingStations[i] =
+- fadingStations[i - 1] + (FIXP_DBL)(fadeDiff * fadingSteps[i - 1]);
+- }
+- fadingStations[8] = fadeStop;
+-}
+-
+-static void CConcealment_TDFading_doLinearFadingSteps(int *fadingSteps) {
+- fadingSteps[0] = fadingSteps[1] = fadingSteps[2] = fadingSteps[3] =
+- fadingSteps[4] = fadingSteps[5] = fadingSteps[6] = fadingSteps[7] = 1;
+-}
+-
+-/* end of TimeDomainFading functions */
+-
+-/* derived from int UsacRandomSign() */
+-static int CConcealment_TDNoise_Random(ULONG *seed) {
+- *seed = (ULONG)(((UINT64)(*seed) * 69069) + 5);
+- return (int)(*seed);
+-}
+-
+-static void CConcealment_TDNoise_Apply(CConcealmentInfo *const pConcealmentInfo,
+- const int len, FIXP_PCM *const pcmdata) {
+- FIXP_PCM *states = pConcealmentInfo->TDNoiseStates;
+- FIXP_PCM noiseVal;
+- FIXP_DBL noiseValLong;
+- FIXP_SGL *coef = pConcealmentInfo->TDNoiseCoef;
+- FIXP_DBL TDNoiseAtt;
+- ULONG seed = pConcealmentInfo->TDNoiseSeed =
+- (ULONG)CConcealment_TDNoise_Random(&pConcealmentInfo->TDNoiseSeed) + 1;
+-
+- TDNoiseAtt = pConcealmentInfo->pConcealParams->comfortNoiseLevel;
+-
+- int ii;
+-
+- if ((pConcealmentInfo->concealState != ConcealState_Ok ||
+- pConcealmentInfo->concealState_old != ConcealState_Ok) &&
+- TDNoiseAtt != (FIXP_DBL)0) {
+- for (ii = 0; ii < (len << 3); ii++) {
+- /* create filtered noise */
+- states[2] = states[1];
+- states[1] = states[0];
+- states[0] = ((FIXP_PCM)CConcealment_TDNoise_Random(&seed));
+- noiseValLong = fMult(states[0], coef[0]) + fMult(states[1], coef[1]) +
+- fMult(states[2], coef[2]);
+- noiseVal = FX_DBL2FX_PCM(fMult(noiseValLong, TDNoiseAtt));
+-
+- /* add filtered noise - check for clipping, before */
+- if (noiseVal > (FIXP_PCM)0 &&
+- pcmdata[ii] > (FIXP_PCM)MAXVAL_FIXP_PCM - noiseVal) {
+- noiseVal = noiseVal * (FIXP_PCM)-1;
+- } else if (noiseVal < (FIXP_PCM)0 &&
+- pcmdata[ii] < (FIXP_PCM)MINVAL_FIXP_PCM - noiseVal) {
+- noiseVal = noiseVal * (FIXP_PCM)-1;
+- }
+-
+- pcmdata[ii] += noiseVal;
+- }
+- }
+-}
+diff --git a/libAACdec/src/conceal.h b/libAACdec/src/conceal.h
+deleted file mode 100644
+index e01a796..0000000
+--- a/libAACdec/src/conceal.h
++++ /dev/null
+@@ -1,152 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Josef Hoepfl
+-
+- Description: independent channel concealment
+-
+-*******************************************************************************/
+-
+-#ifndef CONCEAL_H
+-#define CONCEAL_H
+-
+-#include "channelinfo.h"
+-
+-#define AACDEC_CONCEAL_PARAM_NOT_SPECIFIED (0xFFFE)
+-
+-void CConcealment_InitCommonData(CConcealParams *pConcealCommonData);
+-
+-void CConcealment_InitChannelData(CConcealmentInfo *hConcealmentInfo,
+- CConcealParams *pConcealCommonData,
+- AACDEC_RENDER_MODE initRenderMode,
+- int samplesPerFrame);
+-
+-CConcealmentMethod CConcealment_GetMethod(CConcealParams *pConcealCommonData);
+-
+-UINT CConcealment_GetDelay(CConcealParams *pConcealCommonData);
+-
+-AAC_DECODER_ERROR
+-CConcealment_SetParams(CConcealParams *concealParams, int method,
+- int fadeOutSlope, int fadeInSlope, int muteRelease,
+- FIXP_DBL comfNoiseLevel);
+-
+-CConcealmentState CConcealment_GetState(CConcealmentInfo *hConcealmentInfo);
+-
+-AAC_DECODER_ERROR
+-CConcealment_SetAttenuation(CConcealParams *concealParams,
+- const SHORT *fadeOutAttenuationVector,
+- const SHORT *fadeInAttenuationVector);
+-
+-void CConcealment_Store(
+- CConcealmentInfo *hConcealmentInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
+-
+-int CConcealment_Apply(
+- CConcealmentInfo *hConcealmentInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
+- const UCHAR lastLpdMode, const int FrameOk, const UINT flags);
+-
+-int CConcealment_GetLastFrameOk(CConcealmentInfo *hConcealmentInfo,
+- const int fBeforeApply);
+-
+-INT CConcealment_TDFading(
+- int len, CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo,
+- FIXP_PCM *pcmdata, FIXP_PCM *pcmdata_1);
+-
+-#endif /* #ifndef CONCEAL_H */
+diff --git a/libAACdec/src/conceal_types.h b/libAACdec/src/conceal_types.h
+deleted file mode 100644
+index d90374e..0000000
+--- a/libAACdec/src/conceal_types.h
++++ /dev/null
+@@ -1,203 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Christian Griebel
+-
+- Description: Error concealment structs and types
+-
+-*******************************************************************************/
+-
+-#ifndef CONCEAL_TYPES_H
+-#define CONCEAL_TYPES_H
+-
+-#include "machine_type.h"
+-#include "common_fix.h"
+-
+-#include "rvlc_info.h"
+-
+-#include "usacdec_lpc.h"
+-
+-#define CONCEAL_MAX_NUM_FADE_FACTORS (32)
+-
+-#define FIXP_CNCL FIXP_DBL
+-#define FL2FXCONST_CNCL FL2FXCONST_DBL
+-#define FX_DBL2FX_CNCL
+-#define FX_CNCL2FX_DBL
+-#define CNCL_FRACT_BITS DFRACT_BITS
+-
+-/* Warning: Do not ever change these values. */
+-typedef enum {
+- ConcealMethodNone = -1,
+- ConcealMethodMute = 0,
+- ConcealMethodNoise = 1,
+- ConcealMethodInter = 2,
+- ConcealMethodTonal = 3
+-
+-} CConcealmentMethod;
+-
+-typedef enum {
+- ConcealState_Ok,
+- ConcealState_Single,
+- ConcealState_FadeIn,
+- ConcealState_Mute,
+- ConcealState_FadeOut
+-
+-} CConcealmentState;
+-
+-typedef struct {
+- FIXP_SGL fadeOutFactor[CONCEAL_MAX_NUM_FADE_FACTORS];
+- FIXP_SGL fadeInFactor[CONCEAL_MAX_NUM_FADE_FACTORS];
+-
+- CConcealmentMethod method;
+-
+- int numFadeOutFrames;
+- int numFadeInFrames;
+- int numMuteReleaseFrames;
+- FIXP_DBL comfortNoiseLevel;
+-
+-} CConcealParams;
+-
+-typedef enum {
+- FADE_TIMEDOMAIN_TOSPECTRALMUTE = 1,
+- FADE_TIMEDOMAIN_FROMSPECTRALMUTE,
+- FADE_TIMEDOMAIN
+-} TDfadingType;
+-
+-typedef struct {
+- CConcealParams *pConcealParams;
+-
+- FIXP_CNCL spectralCoefficient[1024];
+- SHORT specScale[8];
+-
+- INT iRandomPhase;
+- INT prevFrameOk[2];
+- INT cntValidFrames;
+- INT cntFadeFrames; /* State for signal fade-in/out */
+- /* States for signal fade-out of frames with more than one window/subframe -
+- [0] used by Update CntFadeFrames mode of CConcealment_ApplyFadeOut, [1] used
+- by FadeOut mode */
+- int winGrpOffset[2]; /* State for signal fade-out of frames with more than one
+- window/subframe */
+- int attGrpOffset[2]; /* State for faster signal fade-out of frames with
+- transient signal parts */
+-
+- SCHAR lastRenderMode;
+-
+- UCHAR windowShape;
+- BLOCK_TYPE windowSequence;
+- UCHAR lastWinGrpLen;
+-
+- CConcealmentState concealState;
+- CConcealmentState concealState_old;
+- FIXP_DBL fade_old; /* last fading factor */
+- TDfadingType lastFadingType; /* last fading type */
+-
+- SHORT aRvlcPreviousScaleFactor[RVLC_MAX_SFB]; /* needed once per channel */
+- UCHAR aRvlcPreviousCodebook[RVLC_MAX_SFB]; /* needed once per channel */
+- SCHAR rvlcPreviousScaleFactorOK;
+- SCHAR rvlcPreviousBlockType;
+-
+- FIXP_LPC lsf4[M_LP_FILTER_ORDER];
+- FIXP_DBL last_tcx_gain;
+- INT last_tcx_gain_e;
+- ULONG TDNoiseSeed;
+- FIXP_PCM TDNoiseStates[3];
+- FIXP_SGL TDNoiseCoef[3];
+- FIXP_SGL TDNoiseAtt;
+-
+-} CConcealmentInfo;
+-
+-#endif /* #ifndef CONCEAL_TYPES_H */
+diff --git a/libAACdec/src/rvlc.cpp b/libAACdec/src/rvlc.cpp
+deleted file mode 100644
+index b7a9be1..0000000
+--- a/libAACdec/src/rvlc.cpp
++++ /dev/null
+@@ -1,1217 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief RVLC Decoder
+- \author Robert Weidner
+-*/
+-
+-#include "rvlc.h"
+-
+-#include "block.h"
+-
+-#include "aac_rom.h"
+-#include "rvlcbit.h"
+-#include "rvlcconceal.h"
+-#include "aacdec_hcr.h"
+-
+-/*---------------------------------------------------------------------------------------------
+- function: rvlcInit
+-
+- description: init RVLC by data from channelinfo, which was decoded
+-previously and set up pointers
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+- - pointer channel info structure
+- - pointer bitstream structure
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void rvlcInit(CErRvlcInfo *pRvlc,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- HANDLE_FDK_BITSTREAM bs) {
+- /* RVLC common initialization part 2 of 2 */
+- SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
+- SHORT *pScfFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd;
+- SHORT *pScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd;
+- SHORT *pScaleFactor = pAacDecoderChannelInfo->pDynData->aScaleFactor;
+- int bnds;
+-
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcIntensityUsed = 0;
+-
+- pRvlc->numDecodedEscapeWordsEsc = 0;
+- pRvlc->numDecodedEscapeWordsFwd = 0;
+- pRvlc->numDecodedEscapeWordsBwd = 0;
+-
+- pRvlc->intensity_used = 0;
+- pRvlc->errorLogRvlc = 0;
+-
+- pRvlc->conceal_max = CONCEAL_MAX_INIT;
+- pRvlc->conceal_min = CONCEAL_MIN_INIT;
+-
+- pRvlc->conceal_max_esc = CONCEAL_MAX_INIT;
+- pRvlc->conceal_min_esc = CONCEAL_MIN_INIT;
+-
+- pRvlc->pHuffTreeRvlcEscape = aHuffTreeRvlcEscape;
+- pRvlc->pHuffTreeRvlCodewds = aHuffTreeRvlCodewds;
+-
+- /* init scf arrays (for savety (in case of there are only zero codebooks)) */
+- for (bnds = 0; bnds < RVLC_MAX_SFB; bnds++) {
+- pScfFwd[bnds] = 0;
+- pScfBwd[bnds] = 0;
+- pScfEsc[bnds] = 0;
+- pScaleFactor[bnds] = 0;
+- }
+-
+- /* set base bitstream ptr to the RVL-coded part (start of RVLC data (ESC 2))
+- */
+- FDKsyncCache(bs);
+- pRvlc->bsAnchor = (INT)FDKgetValidBits(bs);
+-
+- pRvlc->bitstreamIndexRvlFwd =
+- 0; /* first bit within RVL coded block as start address for forward
+- decoding */
+- pRvlc->bitstreamIndexRvlBwd =
+- pRvlc->length_of_rvlc_sf - 1; /* last bit within RVL coded block as start
+- address for backward decoding */
+-
+- /* skip RVLC-bitstream-part -- pointing now to escapes (if present) or to TNS
+- * data (if present) */
+- FDKpushFor(bs, pRvlc->length_of_rvlc_sf);
+-
+- if (pRvlc->sf_escapes_present != 0) {
+- /* locate internal bitstream ptr at escapes (which is the second part) */
+- FDKsyncCache(bs);
+- pRvlc->bitstreamIndexEsc = pRvlc->bsAnchor - (INT)FDKgetValidBits(bs);
+-
+- /* skip escapeRVLC-bitstream-part -- pointing to TNS data (if present) to
+- * make decoder continue */
+- /* decoding of RVLC should work despite this second pushFor during
+- * initialization because */
+- /* bitstream initialization is valid for both ESC2 data parts (RVL-coded
+- * values and ESC-coded values) */
+- FDKpushFor(bs, pRvlc->length_of_rvlc_escapes);
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: rvlcCheckIntensityCb
+-
+- description: Check if a intensity codebook is used in the current channel.
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+- - pointer channel info structure
+------------------------------------------------------------------------------------------------
+- output: - intensity_used: 0 no intensity codebook is used
+- 1 intensity codebook is used
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void rvlcCheckIntensityCb(
+- CErRvlcInfo *pRvlc, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
+- int group, band, bnds;
+-
+- pRvlc->intensity_used = 0;
+-
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- if ((pAacDecoderChannelInfo->pDynData->aCodeBook[bnds] ==
+- INTENSITY_HCB) ||
+- (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds] ==
+- INTENSITY_HCB2)) {
+- pRvlc->intensity_used = 1;
+- break;
+- }
+- }
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: rvlcDecodeEscapeWord
+-
+- description: Decode a huffman coded RVLC Escape-word. This value is part
+-of a DPCM coded scalefactor.
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+------------------------------------------------------------------------------------------------
+- return: - a single RVLC-Escape value which had to be applied to a
+-DPCM value (which has a absolute value of 7)
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static SCHAR rvlcDecodeEscapeWord(CErRvlcInfo *pRvlc, HANDLE_FDK_BITSTREAM bs) {
+- int i;
+- SCHAR value;
+- UCHAR carryBit;
+- UINT treeNode;
+- UINT branchValue;
+- UINT branchNode;
+-
+- INT *pBitstreamIndexEsc;
+- const UINT *pEscTree;
+-
+- pEscTree = pRvlc->pHuffTreeRvlcEscape;
+- pBitstreamIndexEsc = &(pRvlc->bitstreamIndexEsc);
+- treeNode = *pEscTree; /* init at starting node */
+-
+- for (i = MAX_LEN_RVLC_ESCAPE_WORD - 1; i >= 0; i--) {
+- carryBit =
+- rvlcReadBitFromBitstream(bs, /* get next bit */
+- pRvlc->bsAnchor, pBitstreamIndexEsc, FWD);
+-
+- CarryBitToBranchValue(carryBit, /* huffman decoding, do a single step in
+- huffman decoding tree */
+- treeNode, &branchValue, &branchNode);
+-
+- if ((branchNode & TEST_BIT_10) ==
+- TEST_BIT_10) { /* test bit 10 ; if set --> a RVLC-escape-word is
+- completely decoded */
+- value = (SCHAR)branchNode & CLR_BIT_10;
+- pRvlc->length_of_rvlc_escapes -= (MAX_LEN_RVLC_ESCAPE_WORD - i);
+-
+- if (pRvlc->length_of_rvlc_escapes < 0) {
+- pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
+- value = -1;
+- }
+-
+- return value;
+- } else {
+- treeNode = *(
+- pEscTree +
+- branchValue); /* update treeNode for further step in decoding tree */
+- }
+- }
+-
+- pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
+-
+- return -1; /* should not be reached */
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: rvlcDecodeEscapes
+-
+- description: Decodes all huffman coded RVLC Escape Words.
+- Here a difference to the pseudo-code-implementation from
+-standard can be found. A while loop (and not two nested for loops) is used for
+-two reasons:
+-
+- 1. The plain huffman encoded escapes are decoded before the
+-RVL-coded scalefactors. Therefore the escapes are present in the second step
+- when decoding the RVL-coded-scalefactor values in forward
+-and backward direction.
+-
+- When the RVL-coded scalefactors are decoded and there a
+-escape is needed, then it is just taken out of the array in ascending order.
+-
+- 2. It's faster.
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+- - handle to FDK bitstream
+------------------------------------------------------------------------------------------------
+- return: - 0 ok the decoded escapes seem to be valid
+- - 1 error there was a error detected during decoding escapes
+- --> all escapes are invalid
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void rvlcDecodeEscapes(CErRvlcInfo *pRvlc, SHORT *pEsc,
+- HANDLE_FDK_BITSTREAM bs) {
+- SCHAR escWord;
+- SCHAR escCnt = 0;
+- SHORT *pEscBitCntSum;
+-
+- pEscBitCntSum = &(pRvlc->length_of_rvlc_escapes);
+-
+- /* Decode all RVLC-Escape words with a plain Huffman-Decoder */
+- while (*pEscBitCntSum > 0) {
+- escWord = rvlcDecodeEscapeWord(pRvlc, bs);
+-
+- if (escWord >= 0) {
+- pEsc[escCnt] = escWord;
+- escCnt++;
+- } else {
+- pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
+- pRvlc->numDecodedEscapeWordsEsc = escCnt;
+-
+- return;
+- }
+- } /* all RVLC escapes decoded */
+-
+- pRvlc->numDecodedEscapeWordsEsc = escCnt;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: decodeRVLCodeword
+-
+- description: Decodes a RVL-coded dpcm-word (-part).
+------------------------------------------------------------------------------------------------
+- input: - FDK bitstream handle
+- - pointer rvlc structure
+------------------------------------------------------------------------------------------------
+- return: - a dpcm value which is within range [0,1,..,14] in case of
+-no errors. The offset of 7 must be subtracted to get a valid dpcm scalefactor
+-value. In case of errors a forbidden codeword is detected --> returning -1
+---------------------------------------------------------------------------------------------
+-*/
+-
+-SCHAR decodeRVLCodeword(HANDLE_FDK_BITSTREAM bs, CErRvlcInfo *pRvlc) {
+- int i;
+- SCHAR value;
+- UCHAR carryBit;
+- UINT branchValue;
+- UINT branchNode;
+-
+- const UINT *pRvlCodeTree = pRvlc->pHuffTreeRvlCodewds;
+- UCHAR direction = pRvlc->direction;
+- INT *pBitstrIndxRvl = pRvlc->pBitstrIndxRvl_RVL;
+- UINT treeNode = *pRvlCodeTree;
+-
+- for (i = MAX_LEN_RVLC_CODE_WORD - 1; i >= 0; i--) {
+- carryBit =
+- rvlcReadBitFromBitstream(bs, /* get next bit */
+- pRvlc->bsAnchor, pBitstrIndxRvl, direction);
+-
+- CarryBitToBranchValue(carryBit, /* huffman decoding, do a single step in
+- huffman decoding tree */
+- treeNode, &branchValue, &branchNode);
+-
+- if ((branchNode & TEST_BIT_10) ==
+- TEST_BIT_10) { /* test bit 10 ; if set --> a
+- RVLC-codeword is completely decoded
+- */
+- value = (SCHAR)(branchNode & CLR_BIT_10);
+- *pRvlc->pRvlBitCnt_RVL -= (MAX_LEN_RVLC_CODE_WORD - i);
+-
+- /* check available bits for decoding */
+- if (*pRvlc->pRvlBitCnt_RVL < 0) {
+- if (direction == FWD) {
+- pRvlc->errorLogRvlc |= RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_FWD;
+- } else {
+- pRvlc->errorLogRvlc |= RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_BWD;
+- }
+- value = -1; /* signalize an error in return value, because too many bits
+- was decoded */
+- }
+-
+- /* check max value of dpcm value */
+- if (value > MAX_ALLOWED_DPCM_INDEX) {
+- if (direction == FWD) {
+- pRvlc->errorLogRvlc |= RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD;
+- } else {
+- pRvlc->errorLogRvlc |= RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD;
+- }
+- value = -1; /* signalize an error in return value, because a forbidden
+- cw was detected*/
+- }
+-
+- return value; /* return a dpcm value with offset +7 or an error status */
+- } else {
+- treeNode = *(
+- pRvlCodeTree +
+- branchValue); /* update treeNode for further step in decoding tree */
+- }
+- }
+-
+- return -1;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: rvlcDecodeForward
+-
+- description: Decode RVL-coded codewords in forward direction.
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+- - pointer channel info structure
+- - handle to FDK bitstream
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void rvlcDecodeForward(CErRvlcInfo *pRvlc,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- HANDLE_FDK_BITSTREAM bs) {
+- int band = 0;
+- int group = 0;
+- int bnds = 0;
+-
+- SHORT dpcm;
+-
+- SHORT factor =
+- pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
+- SHORT position = -SF_OFFSET;
+- SHORT noisenrg = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
+- SF_OFFSET - 90 - 256;
+-
+- SHORT *pScfFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd;
+- SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
+- UCHAR *pEscFwdCnt = &(pRvlc->numDecodedEscapeWordsFwd);
+-
+- pRvlc->pRvlBitCnt_RVL = &(pRvlc->length_of_rvlc_sf_fwd);
+- pRvlc->pBitstrIndxRvl_RVL = &(pRvlc->bitstreamIndexRvlFwd);
+-
+- *pEscFwdCnt = 0;
+- pRvlc->direction = FWD;
+- pRvlc->noise_used = 0;
+- pRvlc->sf_used = 0;
+- pRvlc->lastScf = 0;
+- pRvlc->lastNrg = 0;
+- pRvlc->lastIs = 0;
+-
+- rvlcCheckIntensityCb(pRvlc, pAacDecoderChannelInfo);
+-
+- /* main loop fwd long */
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+-
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- pScfFwd[bnds] = 0;
+- break;
+-
+- case INTENSITY_HCB2:
+- case INTENSITY_HCB:
+- /* store dpcm_is_position */
+- dpcm = decodeRVLCodeword(bs, pRvlc);
+- if (dpcm < 0) {
+- pRvlc->conceal_max = bnds;
+- return;
+- }
+- dpcm -= TABLE_OFFSET;
+- if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
+- if (pRvlc->length_of_rvlc_escapes) {
+- pRvlc->conceal_max = bnds;
+- return;
+- } else {
+- if (dpcm == MIN_RVL) {
+- dpcm -= *pScfEsc++;
+- } else {
+- dpcm += *pScfEsc++;
+- }
+- (*pEscFwdCnt)++;
+- if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
+- pRvlc->conceal_max_esc = bnds;
+- }
+- }
+- }
+- position += dpcm;
+- pScfFwd[bnds] = position;
+- pRvlc->lastIs = position;
+- break;
+-
+- case NOISE_HCB:
+- if (pRvlc->noise_used == 0) {
+- pRvlc->noise_used = 1;
+- pRvlc->first_noise_band = bnds;
+- noisenrg += pRvlc->dpcm_noise_nrg;
+- pScfFwd[bnds] = 100 + noisenrg;
+- pRvlc->lastNrg = noisenrg;
+- } else {
+- dpcm = decodeRVLCodeword(bs, pRvlc);
+- if (dpcm < 0) {
+- pRvlc->conceal_max = bnds;
+- return;
+- }
+- dpcm -= TABLE_OFFSET;
+- if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
+- if (pRvlc->length_of_rvlc_escapes) {
+- pRvlc->conceal_max = bnds;
+- return;
+- } else {
+- if (dpcm == MIN_RVL) {
+- dpcm -= *pScfEsc++;
+- } else {
+- dpcm += *pScfEsc++;
+- }
+- (*pEscFwdCnt)++;
+- if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
+- pRvlc->conceal_max_esc = bnds;
+- }
+- }
+- }
+- noisenrg += dpcm;
+- pScfFwd[bnds] = 100 + noisenrg;
+- pRvlc->lastNrg = noisenrg;
+- }
+- pAacDecoderChannelInfo->data.aac.PnsData.pnsUsed[bnds] = 1;
+- break;
+-
+- default:
+- pRvlc->sf_used = 1;
+- dpcm = decodeRVLCodeword(bs, pRvlc);
+- if (dpcm < 0) {
+- pRvlc->conceal_max = bnds;
+- return;
+- }
+- dpcm -= TABLE_OFFSET;
+- if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
+- if (pRvlc->length_of_rvlc_escapes) {
+- pRvlc->conceal_max = bnds;
+- return;
+- } else {
+- if (dpcm == MIN_RVL) {
+- dpcm -= *pScfEsc++;
+- } else {
+- dpcm += *pScfEsc++;
+- }
+- (*pEscFwdCnt)++;
+- if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
+- pRvlc->conceal_max_esc = bnds;
+- }
+- }
+- }
+- factor += dpcm;
+- pScfFwd[bnds] = factor;
+- pRvlc->lastScf = factor;
+- break;
+- }
+- }
+- }
+-
+- /* postfetch fwd long */
+- if (pRvlc->intensity_used) {
+- dpcm = decodeRVLCodeword(bs, pRvlc); /* dpcm_is_last_position */
+- if (dpcm < 0) {
+- pRvlc->conceal_max = bnds;
+- return;
+- }
+- dpcm -= TABLE_OFFSET;
+- if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
+- if (pRvlc->length_of_rvlc_escapes) {
+- pRvlc->conceal_max = bnds;
+- return;
+- } else {
+- if (dpcm == MIN_RVL) {
+- dpcm -= *pScfEsc++;
+- } else {
+- dpcm += *pScfEsc++;
+- }
+- (*pEscFwdCnt)++;
+- if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
+- pRvlc->conceal_max_esc = bnds;
+- }
+- }
+- }
+- pRvlc->dpcm_is_last_position = dpcm;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: rvlcDecodeBackward
+-
+- description: Decode RVL-coded codewords in backward direction.
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+- - pointer channel info structure
+- - handle FDK bitstream
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- HANDLE_FDK_BITSTREAM bs) {
+- SHORT band, group, dpcm, offset;
+- SHORT bnds = pRvlc->maxSfbTransmitted - 1;
+-
+- SHORT factor = pRvlc->rev_global_gain - SF_OFFSET;
+- SHORT position = pRvlc->dpcm_is_last_position - SF_OFFSET;
+- SHORT noisenrg = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position -
+- SF_OFFSET - 90 - 256;
+-
+- SHORT *pScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd;
+- SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
+- UCHAR *pEscEscCnt = &(pRvlc->numDecodedEscapeWordsEsc);
+- UCHAR *pEscBwdCnt = &(pRvlc->numDecodedEscapeWordsBwd);
+-
+- pRvlc->pRvlBitCnt_RVL = &(pRvlc->length_of_rvlc_sf_bwd);
+- pRvlc->pBitstrIndxRvl_RVL = &(pRvlc->bitstreamIndexRvlBwd);
+-
+- *pEscBwdCnt = 0;
+- pRvlc->direction = BWD;
+- pScfEsc += *pEscEscCnt - 1; /* set pScfEsc to last entry */
+- pRvlc->firstScf = 0;
+- pRvlc->firstNrg = 0;
+- pRvlc->firstIs = 0;
+-
+- /* prefetch long BWD */
+- if (pRvlc->intensity_used) {
+- dpcm = decodeRVLCodeword(bs, pRvlc); /* dpcm_is_last_position */
+- if (dpcm < 0) {
+- pRvlc->dpcm_is_last_position = 0;
+- pRvlc->conceal_min = bnds;
+- return;
+- }
+- dpcm -= TABLE_OFFSET;
+- if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
+- if (pRvlc->length_of_rvlc_escapes) {
+- pRvlc->conceal_min = bnds;
+- return;
+- } else {
+- if (dpcm == MIN_RVL) {
+- dpcm -= *pScfEsc--;
+- } else {
+- dpcm += *pScfEsc--;
+- }
+- (*pEscBwdCnt)++;
+- if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
+- pRvlc->conceal_min_esc = bnds;
+- }
+- }
+- }
+- pRvlc->dpcm_is_last_position = dpcm;
+- }
+-
+- /* main loop long BWD */
+- for (group = pRvlc->numWindowGroups - 1; group >= 0; group--) {
+- for (band = pRvlc->maxSfbTransmitted - 1; band >= 0; band--) {
+- bnds = 16 * group + band;
+- if ((band == 0) && (pRvlc->numWindowGroups != 1))
+- offset = 16 - pRvlc->maxSfbTransmitted + 1;
+- else
+- offset = 1;
+-
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- pScfBwd[bnds] = 0;
+- break;
+-
+- case INTENSITY_HCB2:
+- case INTENSITY_HCB:
+- /* store dpcm_is_position */
+- dpcm = decodeRVLCodeword(bs, pRvlc);
+- if (dpcm < 0) {
+- pScfBwd[bnds] = position;
+- pRvlc->conceal_min = fMax(0, bnds - offset);
+- return;
+- }
+- dpcm -= TABLE_OFFSET;
+- if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
+- if (pRvlc->length_of_rvlc_escapes) {
+- pScfBwd[bnds] = position;
+- pRvlc->conceal_min = fMax(0, bnds - offset);
+- return;
+- } else {
+- if (dpcm == MIN_RVL) {
+- dpcm -= *pScfEsc--;
+- } else {
+- dpcm += *pScfEsc--;
+- }
+- (*pEscBwdCnt)++;
+- if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
+- pRvlc->conceal_min_esc = fMax(0, bnds - offset);
+- }
+- }
+- }
+- pScfBwd[bnds] = position;
+- position -= dpcm;
+- pRvlc->firstIs = position;
+- break;
+-
+- case NOISE_HCB:
+- if (bnds == pRvlc->first_noise_band) {
+- pScfBwd[bnds] =
+- pRvlc->dpcm_noise_nrg +
+- pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
+- SF_OFFSET - 90 - 256;
+- pRvlc->firstNrg = pScfBwd[bnds];
+- } else {
+- dpcm = decodeRVLCodeword(bs, pRvlc);
+- if (dpcm < 0) {
+- pScfBwd[bnds] = noisenrg;
+- pRvlc->conceal_min = fMax(0, bnds - offset);
+- return;
+- }
+- dpcm -= TABLE_OFFSET;
+- if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
+- if (pRvlc->length_of_rvlc_escapes) {
+- pScfBwd[bnds] = noisenrg;
+- pRvlc->conceal_min = fMax(0, bnds - offset);
+- return;
+- } else {
+- if (dpcm == MIN_RVL) {
+- dpcm -= *pScfEsc--;
+- } else {
+- dpcm += *pScfEsc--;
+- }
+- (*pEscBwdCnt)++;
+- if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
+- pRvlc->conceal_min_esc = fMax(0, bnds - offset);
+- }
+- }
+- }
+- pScfBwd[bnds] = noisenrg;
+- noisenrg -= dpcm;
+- pRvlc->firstNrg = noisenrg;
+- }
+- break;
+-
+- default:
+- dpcm = decodeRVLCodeword(bs, pRvlc);
+- if (dpcm < 0) {
+- pScfBwd[bnds] = factor;
+- pRvlc->conceal_min = fMax(0, bnds - offset);
+- return;
+- }
+- dpcm -= TABLE_OFFSET;
+- if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
+- if (pRvlc->length_of_rvlc_escapes) {
+- pScfBwd[bnds] = factor;
+- pRvlc->conceal_min = fMax(0, bnds - offset);
+- return;
+- } else {
+- if (dpcm == MIN_RVL) {
+- dpcm -= *pScfEsc--;
+- } else {
+- dpcm += *pScfEsc--;
+- }
+- (*pEscBwdCnt)++;
+- if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
+- pRvlc->conceal_min_esc = fMax(0, bnds - offset);
+- }
+- }
+- }
+- pScfBwd[bnds] = factor;
+- factor -= dpcm;
+- pRvlc->firstScf = factor;
+- break;
+- }
+- }
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: rvlcFinalErrorDetection
+-
+- description: Call RVLC concealment if error was detected in decoding
+-process
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+- - pointer channel info structure
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void rvlcFinalErrorDetection(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
+- CErRvlcInfo *pRvlc =
+- &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
+- UCHAR ErrorStatusComplete = 0;
+- UCHAR ErrorStatusLengthFwd = 0;
+- UCHAR ErrorStatusLengthBwd = 0;
+- UCHAR ErrorStatusLengthEscapes = 0;
+- UCHAR ErrorStatusFirstScf = 0;
+- UCHAR ErrorStatusLastScf = 0;
+- UCHAR ErrorStatusFirstNrg = 0;
+- UCHAR ErrorStatusLastNrg = 0;
+- UCHAR ErrorStatusFirstIs = 0;
+- UCHAR ErrorStatusLastIs = 0;
+- UCHAR ErrorStatusForbiddenCwFwd = 0;
+- UCHAR ErrorStatusForbiddenCwBwd = 0;
+- UCHAR ErrorStatusNumEscapesFwd = 0;
+- UCHAR ErrorStatusNumEscapesBwd = 0;
+- UCHAR ConcealStatus = 1;
+- UCHAR currentBlockType; /* short: 0, not short: 1*/
+-
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 1;
+-
+- /* invalid escape words, bit counter unequal zero, forbidden codeword detected
+- */
+- if (pRvlc->errorLogRvlc & RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD)
+- ErrorStatusForbiddenCwFwd = 1;
+-
+- if (pRvlc->errorLogRvlc & RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD)
+- ErrorStatusForbiddenCwBwd = 1;
+-
+- /* bit counter forward unequal zero */
+- if (pRvlc->length_of_rvlc_sf_fwd) ErrorStatusLengthFwd = 1;
+-
+- /* bit counter backward unequal zero */
+- if (pRvlc->length_of_rvlc_sf_bwd) ErrorStatusLengthBwd = 1;
+-
+- /* bit counter escape sequences unequal zero */
+- if (pRvlc->sf_escapes_present)
+- if (pRvlc->length_of_rvlc_escapes) ErrorStatusLengthEscapes = 1;
+-
+- if (pRvlc->sf_used) {
+- /* first decoded scf does not match to global gain in backward direction */
+- if (pRvlc->firstScf !=
+- (pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET))
+- ErrorStatusFirstScf = 1;
+-
+- /* last decoded scf does not match to rev global gain in forward direction
+- */
+- if (pRvlc->lastScf != (pRvlc->rev_global_gain - SF_OFFSET))
+- ErrorStatusLastScf = 1;
+- }
+-
+- if (pRvlc->noise_used) {
+- /* first decoded nrg does not match to dpcm_noise_nrg in backward direction
+- */
+- if (pRvlc->firstNrg !=
+- (pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain +
+- pRvlc->dpcm_noise_nrg - SF_OFFSET - 90 - 256))
+- ErrorStatusFirstNrg = 1;
+-
+- /* last decoded nrg does not match to dpcm_noise_last_position in forward
+- * direction */
+- if (pRvlc->lastNrg !=
+- (pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position - SF_OFFSET -
+- 90 - 256))
+- ErrorStatusLastNrg = 1;
+- }
+-
+- if (pRvlc->intensity_used) {
+- /* first decoded is position does not match in backward direction */
+- if (pRvlc->firstIs != (-SF_OFFSET)) ErrorStatusFirstIs = 1;
+-
+- /* last decoded is position does not match in forward direction */
+- if (pRvlc->lastIs != (pRvlc->dpcm_is_last_position - SF_OFFSET))
+- ErrorStatusLastIs = 1;
+- }
+-
+- /* decoded escapes and used escapes in forward direction do not fit */
+- if ((pRvlc->numDecodedEscapeWordsFwd != pRvlc->numDecodedEscapeWordsEsc) &&
+- (pRvlc->conceal_max == CONCEAL_MAX_INIT)) {
+- ErrorStatusNumEscapesFwd = 1;
+- }
+-
+- /* decoded escapes and used escapes in backward direction do not fit */
+- if ((pRvlc->numDecodedEscapeWordsBwd != pRvlc->numDecodedEscapeWordsEsc) &&
+- (pRvlc->conceal_min == CONCEAL_MIN_INIT)) {
+- ErrorStatusNumEscapesBwd = 1;
+- }
+-
+- if (ErrorStatusLengthEscapes ||
+- (((pRvlc->conceal_max == CONCEAL_MAX_INIT) &&
+- (pRvlc->numDecodedEscapeWordsFwd != pRvlc->numDecodedEscapeWordsEsc) &&
+- (ErrorStatusLastScf || ErrorStatusLastNrg || ErrorStatusLastIs))
+-
+- &&
+-
+- ((pRvlc->conceal_min == CONCEAL_MIN_INIT) &&
+- (pRvlc->numDecodedEscapeWordsBwd != pRvlc->numDecodedEscapeWordsEsc) &&
+- (ErrorStatusFirstScf || ErrorStatusFirstNrg || ErrorStatusFirstIs))) ||
+- ((pRvlc->conceal_max == CONCEAL_MAX_INIT) &&
+- ((pRvlc->rev_global_gain - SF_OFFSET - pRvlc->lastScf) < -15)) ||
+- ((pRvlc->conceal_min == CONCEAL_MIN_INIT) &&
+- ((pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET -
+- pRvlc->firstScf) < -15))) {
+- if ((pRvlc->conceal_max == CONCEAL_MAX_INIT) ||
+- (pRvlc->conceal_min == CONCEAL_MIN_INIT)) {
+- pRvlc->conceal_max = 0;
+- pRvlc->conceal_min = fMax(
+- 0, (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1);
+- } else {
+- pRvlc->conceal_max = fMin(pRvlc->conceal_max, pRvlc->conceal_max_esc);
+- pRvlc->conceal_min = fMax(pRvlc->conceal_min, pRvlc->conceal_min_esc);
+- }
+- }
+-
+- ErrorStatusComplete = ErrorStatusLastScf || ErrorStatusFirstScf ||
+- ErrorStatusLastNrg || ErrorStatusFirstNrg ||
+- ErrorStatusLastIs || ErrorStatusFirstIs ||
+- ErrorStatusForbiddenCwFwd ||
+- ErrorStatusForbiddenCwBwd || ErrorStatusLengthFwd ||
+- ErrorStatusLengthBwd || ErrorStatusLengthEscapes ||
+- ErrorStatusNumEscapesFwd || ErrorStatusNumEscapesBwd;
+-
+- currentBlockType =
+- (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) ? 0
+- : 1;
+-
+- if (!ErrorStatusComplete) {
+- int band;
+- int group;
+- int bnds;
+- int lastSfbIndex;
+-
+- lastSfbIndex = (pRvlc->numWindowGroups > 1) ? 16 : 64;
+-
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- }
+- }
+-
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] =
+- pAacDecoderChannelInfo->pDynData->aCodeBook[bnds];
+- }
+- for (; band < lastSfbIndex; band++) {
+- bnds = 16 * group + band;
+- FDK_ASSERT(bnds >= 0 && bnds < RVLC_MAX_SFB);
+- pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] = ZERO_HCB;
+- }
+- }
+- } else {
+- int band;
+- int group;
+-
+- /* A single bit error was detected in decoding of dpcm values. It also could
+- be an error with more bits in decoding of escapes and dpcm values whereby
+- an illegal codeword followed not directly after the corrupted bits but
+- just after decoding some more (wrong) scalefactors. Use the smaller
+- scalefactor from forward decoding, backward decoding and previous frame.
+- */
+- if (((pRvlc->conceal_min != CONCEAL_MIN_INIT) ||
+- (pRvlc->conceal_max != CONCEAL_MAX_INIT)) &&
+- (pRvlc->conceal_min <= pRvlc->conceal_max) &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo.rvlcPreviousBlockType ==
+- currentBlockType) &&
+- pAacDecoderStaticChannelInfo->concealmentInfo
+- .rvlcPreviousScaleFactorOK &&
+- pRvlc->sf_concealment && ConcealStatus) {
+- BidirectionalEstimation_UseScfOfPrevFrameAsReference(
+- pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo);
+- ConcealStatus = 0;
+- }
+-
+- /* A single bit error was detected in decoding of dpcm values. It also could
+- be an error with more bits in decoding of escapes and dpcm values whereby
+- an illegal codeword followed not directly after the corrupted bits but
+- just after decoding some more (wrong) scalefactors. Use the smaller
+- scalefactor from forward and backward decoding. */
+- if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
+- ((pRvlc->conceal_min != CONCEAL_MIN_INIT) ||
+- (pRvlc->conceal_max != CONCEAL_MAX_INIT)) &&
+- !(pAacDecoderStaticChannelInfo->concealmentInfo
+- .rvlcPreviousScaleFactorOK &&
+- pRvlc->sf_concealment &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .rvlcPreviousBlockType == currentBlockType)) &&
+- ConcealStatus) {
+- BidirectionalEstimation_UseLowerScfOfCurrentFrame(pAacDecoderChannelInfo);
+- ConcealStatus = 0;
+- }
+-
+- /* No errors were detected in decoding of escapes and dpcm values however
+- the first and last value of a group (is,nrg,sf) is incorrect */
+- if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
+- ((ErrorStatusLastScf && ErrorStatusFirstScf) ||
+- (ErrorStatusLastNrg && ErrorStatusFirstNrg) ||
+- (ErrorStatusLastIs && ErrorStatusFirstIs)) &&
+- !(ErrorStatusForbiddenCwFwd || ErrorStatusForbiddenCwBwd ||
+- ErrorStatusLengthEscapes) &&
+- ConcealStatus) {
+- StatisticalEstimation(pAacDecoderChannelInfo);
+- ConcealStatus = 0;
+- }
+-
+- /* A error with more bits in decoding of escapes and dpcm values was
+- detected. Use the smaller scalefactor from forward decoding, backward
+- decoding and previous frame. */
+- if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
+- pAacDecoderStaticChannelInfo->concealmentInfo
+- .rvlcPreviousScaleFactorOK &&
+- pRvlc->sf_concealment &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo.rvlcPreviousBlockType ==
+- currentBlockType) &&
+- ConcealStatus) {
+- PredictiveInterpolation(pAacDecoderChannelInfo,
+- pAacDecoderStaticChannelInfo);
+- ConcealStatus = 0;
+- }
+-
+- /* Call frame concealment, because no better strategy was found. Setting the
+- scalefactors to zero is done for debugging purposes */
+- if (ConcealStatus) {
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[16 * group + band] = 0;
+- }
+- }
+- pAacDecoderChannelInfo->pDynData->specificTo.aac
+- .rvlcCurrentScaleFactorOK = 0;
+- }
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: CRvlc_Read
+-
+- description: Read RVLC ESC1 data (side info) from bitstream.
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+- - pointer channel info structure
+- - pointer bitstream structure
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-void CRvlc_Read(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- HANDLE_FDK_BITSTREAM bs) {
+- CErRvlcInfo *pRvlc =
+- &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
+-
+- int group, band;
+-
+- /* RVLC long specific initialization Init part 1 of 2 */
+- pRvlc->numWindowGroups = GetWindowGroups(&pAacDecoderChannelInfo->icsInfo);
+- pRvlc->maxSfbTransmitted =
+- GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
+- pRvlc->noise_used = 0; /* noise detection */
+- pRvlc->dpcm_noise_nrg = 0; /* only for debugging */
+- pRvlc->dpcm_noise_last_position = 0; /* only for debugging */
+- pRvlc->length_of_rvlc_escapes =
+- -1; /* default value is used for error detection and concealment */
+-
+- /* read only error sensitivity class 1 data (ESC 1 - data) */
+- pRvlc->sf_concealment = FDKreadBits(bs, 1); /* #1 */
+- pRvlc->rev_global_gain = FDKreadBits(bs, 8); /* #2 */
+-
+- if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
+- pRvlc->length_of_rvlc_sf = FDKreadBits(bs, 11); /* #3 */
+- } else {
+- pRvlc->length_of_rvlc_sf = FDKreadBits(bs, 9); /* #3 */
+- }
+-
+- /* check if noise codebook is used */
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- if (pAacDecoderChannelInfo->pDynData->aCodeBook[16 * group + band] ==
+- NOISE_HCB) {
+- pRvlc->noise_used = 1;
+- break;
+- }
+- }
+- }
+-
+- if (pRvlc->noise_used)
+- pRvlc->dpcm_noise_nrg = FDKreadBits(bs, 9); /* #4 PNS */
+-
+- pRvlc->sf_escapes_present = FDKreadBits(bs, 1); /* #5 */
+-
+- if (pRvlc->sf_escapes_present) {
+- pRvlc->length_of_rvlc_escapes = FDKreadBits(bs, 8); /* #6 */
+- }
+-
+- if (pRvlc->noise_used) {
+- pRvlc->dpcm_noise_last_position = FDKreadBits(bs, 9); /* #7 PNS */
+- pRvlc->length_of_rvlc_sf -= 9;
+- }
+-
+- pRvlc->length_of_rvlc_sf_fwd = pRvlc->length_of_rvlc_sf;
+- pRvlc->length_of_rvlc_sf_bwd = pRvlc->length_of_rvlc_sf;
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: CRvlc_Decode
+-
+- description: Decode rvlc data
+- The function reads both the escape sequences and the
+-scalefactors in forward and backward direction. If an error occured during
+-decoding process which can not be concealed with the rvlc concealment frame
+-concealment will be initiated. Then the element "rvlcCurrentScaleFactorOK" in
+-the decoder channel info is set to 0 otherwise it is set to 1.
+------------------------------------------------------------------------------------------------
+- input: - pointer rvlc structure
+- - pointer channel info structure
+- - pointer to persistent channel info structure
+- - pointer bitstream structure
+------------------------------------------------------------------------------------------------
+- return: ErrorStatus = AAC_DEC_OK
+---------------------------------------------------------------------------------------------
+-*/
+-
+-void CRvlc_Decode(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- HANDLE_FDK_BITSTREAM bs) {
+- CErRvlcInfo *pRvlc =
+- &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
+- INT bitCntOffst;
+- INT saveBitCnt;
+-
+- rvlcInit(pRvlc, pAacDecoderChannelInfo, bs);
+-
+- /* save bitstream position */
+- saveBitCnt = (INT)FDKgetValidBits(bs);
+-
+- if (pRvlc->sf_escapes_present)
+- rvlcDecodeEscapes(
+- pRvlc, pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc, bs);
+-
+- rvlcDecodeForward(pRvlc, pAacDecoderChannelInfo, bs);
+- rvlcDecodeBackward(pRvlc, pAacDecoderChannelInfo, bs);
+- rvlcFinalErrorDetection(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo);
+-
+- pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcIntensityUsed =
+- pRvlc->intensity_used;
+- pAacDecoderChannelInfo->data.aac.PnsData.PnsActive = pRvlc->noise_used;
+-
+- /* restore bitstream position */
+- bitCntOffst = (INT)FDKgetValidBits(bs) - saveBitCnt;
+- if (bitCntOffst) {
+- FDKpushBiDirectional(bs, bitCntOffst);
+- }
+-}
+-
+-void CRvlc_ElementCheck(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo[],
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[],
+- const UINT flags, const INT elChannels) {
+- int ch;
+-
+- /* Required for MPS residuals. */
+- if (pAacDecoderStaticChannelInfo == NULL) {
+- return;
+- }
+-
+- /* RVLC specific sanity checks */
+- if ((flags & AC_ER_RVLC) && (elChannels == 2)) { /* to be reviewed */
+- if (((pAacDecoderChannelInfo[0]
+- ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0) ||
+- (pAacDecoderChannelInfo[1]
+- ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0)) &&
+- pAacDecoderChannelInfo[0]->pComData->jointStereoData.MsMaskPresent) {
+- pAacDecoderChannelInfo[0]
+- ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
+- pAacDecoderChannelInfo[1]
+- ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
+- }
+-
+- if ((pAacDecoderChannelInfo[0]
+- ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0) &&
+- (pAacDecoderChannelInfo[1]
+- ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 1) &&
+- (pAacDecoderChannelInfo[1]
+- ->pDynData->specificTo.aac.rvlcIntensityUsed == 1)) {
+- pAacDecoderChannelInfo[1]
+- ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
+- }
+- }
+-
+- for (ch = 0; ch < elChannels; ch++) {
+- pAacDecoderStaticChannelInfo[ch]->concealmentInfo.rvlcPreviousBlockType =
+- (GetWindowSequence(&pAacDecoderChannelInfo[ch]->icsInfo) == BLOCK_SHORT)
+- ? 0
+- : 1;
+- if (flags & AC_ER_RVLC) {
+- pAacDecoderStaticChannelInfo[ch]
+- ->concealmentInfo.rvlcPreviousScaleFactorOK =
+- pAacDecoderChannelInfo[ch]
+- ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK;
+- } else {
+- pAacDecoderStaticChannelInfo[ch]
+- ->concealmentInfo.rvlcPreviousScaleFactorOK = 0;
+- }
+- }
+-}
+diff --git a/libAACdec/src/rvlc.h b/libAACdec/src/rvlc.h
+deleted file mode 100644
+index 9c60d51..0000000
+--- a/libAACdec/src/rvlc.h
++++ /dev/null
+@@ -1,153 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Defines structures and prototypes for RVLC
+- \author Robert Weidner
+-*/
+-
+-#ifndef RVLC_H
+-#define RVLC_H
+-
+-#include "aacdecoder.h"
+-#include "channel.h"
+-#include "rvlc_info.h"
+-
+-/* ------------------------------------------------------------------- */
+-/* errorLogRvlc: A word of 32 bits used for logging possible errors */
+-/* within RVLC in case of distorted bitstreams. */
+-/* ------------------------------------------------------------------- */
+-#define RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID \
+- 0x80000000 /* ESC-Dec During RVLC-Escape-decoding there have been more \
+- bits decoded as there are available */
+-#define RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_FWD \
+- 0x40000000 /* RVL-Dec negative sum-bitcounter during RVL-fwd-decoding \
+- (long+shrt) */
+-#define RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_BWD \
+- 0x20000000 /* RVL-Dec negative sum-bitcounter during RVL-fwd-decoding \
+- (long+shrt) */
+-#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD \
+- 0x08000000 /* RVL-Dec forbidden codeword detected fwd (long+shrt) */
+-#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD \
+- 0x04000000 /* RVL-Dec forbidden codeword detected bwd (long+shrt) */
+-
+-void CRvlc_Read(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- HANDLE_FDK_BITSTREAM bs);
+-
+-void CRvlc_Decode(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- HANDLE_FDK_BITSTREAM bs);
+-
+-/**
+- * \brief performe sanity checks to the channel data corresponding to one
+- * channel element.
+- * \param pAacDecoderChannelInfo
+- * \param pAacDecoderStaticChannelInfo
+- * \param elChannels amount of channels of the channel element.
+- */
+-void CRvlc_ElementCheck(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo[],
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[],
+- const UINT flags, const INT elChannels);
+-
+-#endif /* RVLC_H */
+diff --git a/libAACdec/src/rvlc_info.h b/libAACdec/src/rvlc_info.h
+deleted file mode 100644
+index e7b3b99..0000000
+--- a/libAACdec/src/rvlc_info.h
++++ /dev/null
+@@ -1,204 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Defines structures for RVLC
+- \author Robert Weidner
+-*/
+-#ifndef RVLC_INFO_H
+-#define RVLC_INFO_H
+-
+-#define FWD 0 /* bitstream decoding direction forward (RVL coded part) */
+-#define BWD 1 /* bitstream decoding direction backward (RVL coded part) */
+-
+-#define MAX_RVL 7 /* positive RVLC escape */
+-#define MIN_RVL -7 /* negative RVLC escape */
+-#define MAX_ALLOWED_DPCM_INDEX \
+- 14 /* the maximum allowed index of a decoded dpcm value (offset \
+- 'TABLE_OFFSET' incl --> must be subtracted) */
+-#define TABLE_OFFSET \
+- 7 /* dpcm offset of valid output values of rvl table decoding, the rvl table \
+- ouly returns positive values, therefore the offset */
+-#define MAX_LEN_RVLC_CODE_WORD 9 /* max length of a RVL codeword in bits */
+-#define MAX_LEN_RVLC_ESCAPE_WORD \
+- 20 /* max length of huffman coded RVLC escape word in bits */
+-
+-#define DPCM_NOISE_NRG_BITS 9
+-#define SF_OFFSET 100 /* offset for correcting scf value */
+-
+-#define CONCEAL_MAX_INIT 1311 /* arbitrary value */
+-#define CONCEAL_MIN_INIT -1311 /* arbitrary value */
+-
+-#define RVLC_MAX_SFB ((8) * (16))
+-
+-/* sideinfo of RVLC */
+-typedef struct {
+- /* ------- ESC 1 Data: --------- */ /* order of RVLC-bitstream components in
+- bitstream (RVLC-initialization), every
+- component appears only once in
+- bitstream */
+- INT sf_concealment; /* 1 */
+- INT rev_global_gain; /* 2 */
+- SHORT length_of_rvlc_sf; /* 3 */ /* original value, gets modified
+- (subtract 9) in case of noise
+- (PNS); is kept for later use */
+- INT dpcm_noise_nrg; /* 4 optional */
+- INT sf_escapes_present; /* 5 */
+- SHORT length_of_rvlc_escapes; /* 6 optional */
+- INT dpcm_noise_last_position; /* 7 optional */
+-
+- INT dpcm_is_last_position;
+-
+- SHORT length_of_rvlc_sf_fwd; /* length_of_rvlc_sf used for forward decoding */
+- SHORT
+- length_of_rvlc_sf_bwd; /* length_of_rvlc_sf used for backward decoding */
+-
+- /* for RVL-Codeword decoder to distinguish between fwd and bwd decoding */
+- SHORT *pRvlBitCnt_RVL;
+- INT *pBitstrIndxRvl_RVL;
+-
+- UCHAR numWindowGroups;
+- UCHAR maxSfbTransmitted;
+- UCHAR first_noise_group;
+- UCHAR first_noise_band;
+- UCHAR direction;
+-
+- /* bitstream indices */
+- INT bsAnchor; /* hcr bit buffer reference index */
+- INT bitstreamIndexRvlFwd; /* base address of RVL-coded-scalefactor data (ESC
+- 2) for forward decoding */
+- INT bitstreamIndexRvlBwd; /* base address of RVL-coded-scalefactor data (ESC
+- 2) for backward decoding */
+- INT bitstreamIndexEsc; /* base address where RVLC-escapes start (ESC 2) */
+-
+- /* decoding trees */
+- const UINT *pHuffTreeRvlCodewds;
+- const UINT *pHuffTreeRvlcEscape;
+-
+- /* escape counters */
+- UCHAR numDecodedEscapeWordsFwd; /* when decoding RVL-codes forward */
+- UCHAR numDecodedEscapeWordsBwd; /* when decoding RVL-codes backward */
+- UCHAR numDecodedEscapeWordsEsc; /* when decoding the escape-Words */
+-
+- SCHAR noise_used;
+- SCHAR intensity_used;
+- SCHAR sf_used;
+-
+- SHORT firstScf;
+- SHORT lastScf;
+- SHORT firstNrg;
+- SHORT lastNrg;
+- SHORT firstIs;
+- SHORT lastIs;
+-
+- /* ------ RVLC error detection ------ */
+- UINT errorLogRvlc; /* store RVLC errors */
+- SHORT conceal_min; /* is set at backward decoding */
+- SHORT conceal_max; /* is set at forward decoding */
+- SHORT conceal_min_esc; /* is set at backward decoding */
+- SHORT conceal_max_esc; /* is set at forward decoding */
+-} CErRvlcInfo;
+-
+-typedef CErRvlcInfo RVLC_INFO; /* temp */
+-
+-#endif /* RVLC_INFO_H */
+diff --git a/libAACdec/src/rvlcbit.cpp b/libAACdec/src/rvlcbit.cpp
+deleted file mode 100644
+index b0c4596..0000000
+--- a/libAACdec/src/rvlcbit.cpp
++++ /dev/null
+@@ -1,148 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief RVLC bitstream reading
+- \author Robert Weidner
+-*/
+-
+-#include "rvlcbit.h"
+-
+-/*---------------------------------------------------------------------------------------------
+- function: rvlcReadBitFromBitstream
+-
+- description: This function returns a bit from the bitstream according to
+-read direction. It is called very often, therefore it makes sense to inline it
+-(runtime).
+------------------------------------------------------------------------------------------------
+- input: - bitstream
+- - pPosition
+- - readDirection
+------------------------------------------------------------------------------------------------
+- return: - bit from bitstream
+---------------------------------------------------------------------------------------------
+-*/
+-
+-UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- INT *pPosition, UCHAR readDirection) {
+- UINT bit;
+- INT readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pPosition;
+-
+- if (readBitOffset) {
+- FDKpushBiDirectional(bs, readBitOffset);
+- }
+-
+- if (readDirection == FWD) {
+- bit = FDKreadBits(bs, 1);
+-
+- *pPosition += 1;
+- } else {
+- /* to be replaced with a brother function of FDKreadBits() */
+- bit = FDKreadBits(bs, 1);
+- FDKpushBack(bs, 2);
+-
+- *pPosition -= 1;
+- }
+-
+- return (bit);
+-}
+diff --git a/libAACdec/src/rvlcbit.h b/libAACdec/src/rvlcbit.h
+deleted file mode 100644
+index 2578453..0000000
+--- a/libAACdec/src/rvlcbit.h
++++ /dev/null
+@@ -1,111 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Robert Weidner (DSP Solutions)
+-
+- Description: RVLC Decoder: Bitstream reading
+-
+-*******************************************************************************/
+-
+-#ifndef RVLCBIT_H
+-#define RVLCBIT_H
+-
+-#include "rvlc.h"
+-
+-UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
+- INT *pPosition, UCHAR readDirection);
+-
+-#endif /* RVLCBIT_H */
+diff --git a/libAACdec/src/rvlcconceal.cpp b/libAACdec/src/rvlcconceal.cpp
+deleted file mode 100644
+index 77fda68..0000000
+--- a/libAACdec/src/rvlcconceal.cpp
++++ /dev/null
+@@ -1,787 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief rvlc concealment
+- \author Josef Hoepfl
+-*/
+-
+-#include "rvlcconceal.h"
+-
+-#include "block.h"
+-#include "rvlc.h"
+-
+-/*---------------------------------------------------------------------------------------------
+- function: calcRefValFwd
+-
+- description: The function determines the scalefactor which is closed to the
+-scalefactorband conceal_min. The same is done for intensity data and noise
+-energies.
+------------------------------------------------------------------------------------------------
+- output: - reference value scf
+- - reference value internsity data
+- - reference value noise energy
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void calcRefValFwd(CErRvlcInfo *pRvlc,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- int *refIsFwd, int *refNrgFwd, int *refScfFwd) {
+- int band, bnds, group, startBand;
+- int idIs, idNrg, idScf;
+- int conceal_min, conceal_group_min;
+- int MaximumScaleFactorBands;
+-
+- if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
+- MaximumScaleFactorBands = 16;
+- else
+- MaximumScaleFactorBands = 64;
+-
+- conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
+- conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
+-
+- /* calculate first reference value for approach in forward direction */
+- idIs = idNrg = idScf = 1;
+-
+- /* set reference values */
+- *refIsFwd = -SF_OFFSET;
+- *refNrgFwd = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
+- SF_OFFSET - 90 - 256;
+- *refScfFwd =
+- pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
+-
+- startBand = conceal_min - 1;
+- for (group = conceal_group_min; group >= 0; group--) {
+- for (band = startBand; band >= 0; band--) {
+- bnds = 16 * group + band;
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- break;
+- case INTENSITY_HCB:
+- case INTENSITY_HCB2:
+- if (idIs) {
+- *refIsFwd =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- idIs = 0; /* reference value has been set */
+- }
+- break;
+- case NOISE_HCB:
+- if (idNrg) {
+- *refNrgFwd =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- idNrg = 0; /* reference value has been set */
+- }
+- break;
+- default:
+- if (idScf) {
+- *refScfFwd =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- idScf = 0; /* reference value has been set */
+- }
+- break;
+- }
+- }
+- startBand = pRvlc->maxSfbTransmitted - 1;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: calcRefValBwd
+-
+- description: The function determines the scalefactor which is closed to the
+-scalefactorband conceal_max. The same is done for intensity data and noise
+-energies.
+------------------------------------------------------------------------------------------------
+- output: - reference value scf
+- - reference value internsity data
+- - reference value noise energy
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-static void calcRefValBwd(CErRvlcInfo *pRvlc,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- int *refIsBwd, int *refNrgBwd, int *refScfBwd) {
+- int band, bnds, group, startBand;
+- int idIs, idNrg, idScf;
+- int conceal_max, conceal_group_max;
+- int MaximumScaleFactorBands;
+-
+- if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
+- MaximumScaleFactorBands = 16;
+- else
+- MaximumScaleFactorBands = 64;
+-
+- conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
+- conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
+-
+- /* calculate first reference value for approach in backward direction */
+- idIs = idNrg = idScf = 1;
+-
+- /* set reference values */
+- *refIsBwd = pRvlc->dpcm_is_last_position - SF_OFFSET;
+- *refNrgBwd = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position -
+- SF_OFFSET - 90 - 256 + pRvlc->dpcm_noise_nrg;
+- *refScfBwd = pRvlc->rev_global_gain - SF_OFFSET;
+-
+- startBand = conceal_max + 1;
+-
+- /* if needed, re-set reference values */
+- for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
+- for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- break;
+- case INTENSITY_HCB:
+- case INTENSITY_HCB2:
+- if (idIs) {
+- *refIsBwd =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- idIs = 0; /* reference value has been set */
+- }
+- break;
+- case NOISE_HCB:
+- if (idNrg) {
+- *refNrgBwd =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- idNrg = 0; /* reference value has been set */
+- }
+- break;
+- default:
+- if (idScf) {
+- *refScfBwd =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- idScf = 0; /* reference value has been set */
+- }
+- break;
+- }
+- }
+- startBand = 0;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: BidirectionalEstimation_UseLowerScfOfCurrentFrame
+-
+- description: This approach by means of bidirectional estimation is generally
+-performed when a single bit error has been detected, the bit error can be
+-isolated between 'conceal_min' and 'conceal_max' and the 'sf_concealment' flag
+-is not set. The sets of scalefactors decoded in forward and backward direction
+-are compared with each other. The smaller scalefactor will be considered as the
+-correct one respectively. The reconstruction of the scalefactors with this
+-approach archieve good results in audio quality. The strategy must be applied to
+-scalefactors, intensity data and noise energy seperately.
+------------------------------------------------------------------------------------------------
+- output: Concealed scalefactor, noise energy and intensity data between
+-conceal_min and conceal_max
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-void BidirectionalEstimation_UseLowerScfOfCurrentFrame(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
+- CErRvlcInfo *pRvlc =
+- &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
+- int band, bnds, startBand, endBand, group;
+- int conceal_min, conceal_max;
+- int conceal_group_min, conceal_group_max;
+- int MaximumScaleFactorBands;
+-
+- if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
+- MaximumScaleFactorBands = 16;
+- } else {
+- MaximumScaleFactorBands = 64;
+- }
+-
+- /* If an error was detected just in forward or backward direction, set the
+- corresponding border for concealment to a appropriate scalefactor band. The
+- border is set to first or last sfb respectively, because the error will
+- possibly not follow directly after the corrupt bit but just after decoding
+- some more (wrong) scalefactors. */
+- if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
+-
+- if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
+- pRvlc->conceal_max =
+- (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
+-
+- conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
+- conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
+- conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
+- conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
+-
+- if (pRvlc->conceal_min == pRvlc->conceal_max) {
+- int refIsFwd, refNrgFwd, refScfFwd;
+- int refIsBwd, refNrgBwd, refScfBwd;
+-
+- bnds = pRvlc->conceal_min;
+- calcRefValFwd(pRvlc, pAacDecoderChannelInfo, &refIsFwd, &refNrgFwd,
+- &refScfFwd);
+- calcRefValBwd(pRvlc, pAacDecoderChannelInfo, &refIsBwd, &refNrgBwd,
+- &refScfBwd);
+-
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- break;
+- case INTENSITY_HCB:
+- case INTENSITY_HCB2:
+- if (refIsFwd < refIsBwd)
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsFwd;
+- else
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsBwd;
+- break;
+- case NOISE_HCB:
+- if (refNrgFwd < refNrgBwd)
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgFwd;
+- else
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgBwd;
+- break;
+- default:
+- if (refScfFwd < refScfBwd)
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfFwd;
+- else
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfBwd;
+- break;
+- }
+- } else {
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfFwd[pRvlc->conceal_max] =
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[pRvlc->conceal_max];
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[pRvlc->conceal_min] =
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfFwd[pRvlc->conceal_min];
+-
+- /* consider the smaller of the forward and backward decoded value as the
+- * correct one */
+- startBand = conceal_min;
+- if (conceal_group_min == conceal_group_max)
+- endBand = conceal_max;
+- else
+- endBand = pRvlc->maxSfbTransmitted - 1;
+-
+- for (group = conceal_group_min; group <= conceal_group_max; group++) {
+- for (band = startBand; band <= endBand; band++) {
+- bnds = 16 * group + band;
+- if (pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds] <
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds])
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- else
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- }
+- startBand = 0;
+- if ((group + 1) == conceal_group_max) endBand = conceal_max;
+- }
+- }
+-
+- /* now copy all data to the output buffer which needs not to be concealed */
+- if (conceal_group_min == 0)
+- endBand = conceal_min;
+- else
+- endBand = pRvlc->maxSfbTransmitted;
+- for (group = 0; group <= conceal_group_min; group++) {
+- for (band = 0; band < endBand; band++) {
+- bnds = 16 * group + band;
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- }
+- if ((group + 1) == conceal_group_min) endBand = conceal_min;
+- }
+-
+- startBand = conceal_max + 1;
+- for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
+- for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- }
+- startBand = 0;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: BidirectionalEstimation_UseScfOfPrevFrameAsReference
+-
+- description: This approach by means of bidirectional estimation is generally
+-performed when a single bit error has been detected, the bit error can be
+-isolated between 'conceal_min' and 'conceal_max', the 'sf_concealment' flag is
+-set and the previous frame has the same block type as the current frame. The
+-scalefactor decoded in forward and backward direction and the scalefactor of the
+-previous frame are compared with each other. The smaller scalefactor will be
+-considered as the correct one. At this the codebook of the previous and current
+-frame must be of the same set (scf, nrg, is) in each scalefactorband. Otherwise
+-the scalefactor of the previous frame is not considered in the minimum
+-calculation. The reconstruction of the scalefactors with this approach archieve
+-good results in audio quality. The strategy must be applied to scalefactors,
+-intensity data and noise energy seperately.
+------------------------------------------------------------------------------------------------
+- output: Concealed scalefactor, noise energy and intensity data between
+-conceal_min and conceal_max
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-void BidirectionalEstimation_UseScfOfPrevFrameAsReference(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
+- CErRvlcInfo *pRvlc =
+- &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
+- int band, bnds, startBand, endBand, group;
+- int conceal_min, conceal_max;
+- int conceal_group_min, conceal_group_max;
+- int MaximumScaleFactorBands;
+- SHORT commonMin;
+-
+- if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
+- MaximumScaleFactorBands = 16;
+- } else {
+- MaximumScaleFactorBands = 64;
+- }
+-
+- /* If an error was detected just in forward or backward direction, set the
+- corresponding border for concealment to a appropriate scalefactor band. The
+- border is set to first or last sfb respectively, because the error will
+- possibly not follow directly after the corrupt bit but just after decoding
+- some more (wrong) scalefactors. */
+- if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
+-
+- if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
+- pRvlc->conceal_max =
+- (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
+-
+- conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
+- conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
+- conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
+- conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
+-
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfFwd[pRvlc->conceal_max] =
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[pRvlc->conceal_max];
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[pRvlc->conceal_min] =
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfFwd[pRvlc->conceal_min];
+-
+- /* consider the smaller of the forward and backward decoded value as the
+- * correct one */
+- startBand = conceal_min;
+- if (conceal_group_min == conceal_group_max)
+- endBand = conceal_max;
+- else
+- endBand = pRvlc->maxSfbTransmitted - 1;
+-
+- for (group = conceal_group_min; group <= conceal_group_max; group++) {
+- for (band = startBand; band <= endBand; band++) {
+- bnds = 16 * group + band;
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
+- break;
+-
+- case INTENSITY_HCB:
+- case INTENSITY_HCB2:
+- if ((pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
+- commonMin = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousScaleFactor[bnds]);
+- } else {
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- }
+- break;
+-
+- case NOISE_HCB:
+- if (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
+- commonMin = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousScaleFactor[bnds]);
+- } else {
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- }
+- break;
+-
+- default:
+- if ((pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
+- commonMin = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousScaleFactor[bnds]);
+- } else {
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- }
+- break;
+- }
+- }
+- startBand = 0;
+- if ((group + 1) == conceal_group_max) endBand = conceal_max;
+- }
+-
+- /* now copy all data to the output buffer which needs not to be concealed */
+- if (conceal_group_min == 0)
+- endBand = conceal_min;
+- else
+- endBand = pRvlc->maxSfbTransmitted;
+- for (group = 0; group <= conceal_group_min; group++) {
+- for (band = 0; band < endBand; band++) {
+- bnds = 16 * group + band;
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- }
+- if ((group + 1) == conceal_group_min) endBand = conceal_min;
+- }
+-
+- startBand = conceal_max + 1;
+- for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
+- for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- }
+- startBand = 0;
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- function: StatisticalEstimation
+-
+- description: This approach by means of statistical estimation is generally
+-performed when both the start value and the end value are different and no
+-further errors have been detected. Considering the forward and backward decoded
+-scalefactors, the set with the lower scalefactors in sum will be considered as
+-the correct one. The scalefactors are differentially encoded. Normally it would
+-reach to compare one pair of the forward and backward decoded scalefactors to
+-specify the lower set. But having detected no further errors does not
+-necessarily mean the absence of errors. Therefore all scalefactors decoded in
+-forward and backward direction are summed up seperately. The set with the lower
+-sum will be used. The strategy must be applied to scalefactors, intensity data
+-and noise energy seperately.
+------------------------------------------------------------------------------------------------
+- output: Concealed scalefactor, noise energy and intensity data
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-void StatisticalEstimation(CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
+- CErRvlcInfo *pRvlc =
+- &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
+- int band, bnds, group;
+- int sumIsFwd, sumIsBwd; /* sum of intensity data forward/backward */
+- int sumNrgFwd, sumNrgBwd; /* sum of noise energy data forward/backward */
+- int sumScfFwd, sumScfBwd; /* sum of scalefactor data forward/backward */
+- int useIsFwd, useNrgFwd, useScfFwd; /* the flags signals the elements which
+- are used for the final result */
+-
+- sumIsFwd = sumIsBwd = sumNrgFwd = sumNrgBwd = sumScfFwd = sumScfBwd = 0;
+- useIsFwd = useNrgFwd = useScfFwd = 0;
+-
+- /* calculate sum of each group (scf,nrg,is) of forward and backward direction
+- */
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- break;
+-
+- case INTENSITY_HCB:
+- case INTENSITY_HCB2:
+- sumIsFwd +=
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- sumIsBwd +=
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- break;
+-
+- case NOISE_HCB:
+- sumNrgFwd +=
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- sumNrgBwd +=
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- break;
+-
+- default:
+- sumScfFwd +=
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- sumScfBwd +=
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- break;
+- }
+- }
+- }
+-
+- /* find for each group (scf,nrg,is) the correct direction */
+- if (sumIsFwd < sumIsBwd) useIsFwd = 1;
+-
+- if (sumNrgFwd < sumNrgBwd) useNrgFwd = 1;
+-
+- if (sumScfFwd < sumScfBwd) useScfFwd = 1;
+-
+- /* conceal each group (scf,nrg,is) */
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- break;
+-
+- case INTENSITY_HCB:
+- case INTENSITY_HCB2:
+- if (useIsFwd)
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- else
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- break;
+-
+- case NOISE_HCB:
+- if (useNrgFwd)
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- else
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- break;
+-
+- default:
+- if (useScfFwd)
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
+- else
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
+- break;
+- }
+- }
+- }
+-}
+-
+-/*---------------------------------------------------------------------------------------------
+- description: Approach by means of predictive interpolation
+- This approach by means of predictive estimation is generally
+-performed when the error cannot be isolated between 'conceal_min' and
+-'conceal_max', the 'sf_concealment' flag is set and the previous frame has the
+-same block type as the current frame. Check for each scalefactorband if the same
+-type of data (scalefactor, internsity data, noise energies) is transmitted. If
+-so use the scalefactor (intensity data, noise energy) in the current frame.
+-Otherwise set the scalefactor (intensity data, noise energy) for this
+-scalefactorband to zero.
+------------------------------------------------------------------------------------------------
+- output: Concealed scalefactor, noise energy and intensity data
+------------------------------------------------------------------------------------------------
+- return: -
+---------------------------------------------------------------------------------------------
+-*/
+-
+-void PredictiveInterpolation(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
+- CErRvlcInfo *pRvlc =
+- &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
+- int band, bnds, group;
+- SHORT commonMin;
+-
+- for (group = 0; group < pRvlc->numWindowGroups; group++) {
+- for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
+- bnds = 16 * group + band;
+- switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
+- case ZERO_HCB:
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
+- break;
+-
+- case INTENSITY_HCB:
+- case INTENSITY_HCB2:
+- if ((pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
+- commonMin = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousScaleFactor[bnds]);
+- } else {
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
+- }
+- break;
+-
+- case NOISE_HCB:
+- if (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
+- commonMin = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousScaleFactor[bnds]);
+- } else {
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
+- }
+- break;
+-
+- default:
+- if ((pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
+- (pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
+- commonMin = fMin(
+- pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
+- pAacDecoderChannelInfo->pComData->overlay.aac
+- .aRvlcScfBwd[bnds]);
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
+- fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
+- .aRvlcPreviousScaleFactor[bnds]);
+- } else {
+- pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
+- }
+- break;
+- }
+- }
+- }
+-}
+diff --git a/libAACdec/src/rvlcconceal.h b/libAACdec/src/rvlcconceal.h
+deleted file mode 100644
+index 8e2062e..0000000
+--- a/libAACdec/src/rvlcconceal.h
++++ /dev/null
+@@ -1,127 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s):
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief rvlc concealment
+- \author Josef Hoepfl
+-*/
+-
+-#ifndef RVLCCONCEAL_H
+-#define RVLCCONCEAL_H
+-
+-#include "rvlc.h"
+-
+-void BidirectionalEstimation_UseLowerScfOfCurrentFrame(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo);
+-
+-void BidirectionalEstimation_UseScfOfPrevFrameAsReference(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
+-
+-void StatisticalEstimation(CAacDecoderChannelInfo *pAacDecoderChannelInfo);
+-
+-void PredictiveInterpolation(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
+-
+-#endif /* RVLCCONCEAL_H */
+diff --git a/libAACdec/src/usacdec_lpd.cpp b/libAACdec/src/usacdec_lpd.cpp
+index 2110172..fcf7a76 100644
+--- a/libAACdec/src/usacdec_lpd.cpp
++++ b/libAACdec/src/usacdec_lpd.cpp
+@@ -111,8 +111,6 @@ amm-info@iis.fraunhofer.de
+ #include "usacdec_acelp.h"
+ #include "overlapadd.h"
+
+-#include "conceal.h"
+-
+ #include "block.h"
+
+ #define SF_PITCH_TRACK 6
+@@ -1210,8 +1208,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read(
+ : &lg_table_ccfl[1][lg_table_offset];
+ int last_lpc_lost = pAacDecoderStaticChannelInfo->last_lpc_lost;
+
+- int last_frame_ok = CConcealment_GetLastFrameOk(
+- &pAacDecoderStaticChannelInfo->concealmentInfo, 1);
++ int last_frame_ok = 1;
+
+ INT i_offset;
+ UINT samplingRate;
+@@ -1392,13 +1389,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read(
+ }
+ }
+
+- if (!CConcealment_GetLastFrameOk(
+- &pAacDecoderStaticChannelInfo->concealmentInfo, 1)) {
+- E_LPC_f_lsp_a_conversion(
+- pAacDecoderChannelInfo->data.usac.lsp_coeff[0],
+- pAacDecoderChannelInfo->data.usac.lp_coeff[0],
+- &pAacDecoderChannelInfo->data.usac.lp_coeff_exp[0]);
+- } else if (pAacDecoderStaticChannelInfo->last_lpd_mode != 0) {
++ if (pAacDecoderStaticChannelInfo->last_lpd_mode != 0) {
+ if (pAacDecoderStaticChannelInfo->last_lpd_mode == 255) {
+ /* We need it for TCX decoding or ACELP excitation update */
+ E_LPC_f_lsp_a_conversion(
+@@ -1426,9 +1417,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read(
+ FD_SHORT;
+ pAacDecoderChannelInfo->data.usac.lpd_mode_last = 255;
+
+- if ((pAacDecoderStaticChannelInfo->last_core_mode != FD_SHORT) &&
+- CConcealment_GetLastFrameOk(
+- &pAacDecoderStaticChannelInfo->concealmentInfo, 1)) {
++ if ((pAacDecoderStaticChannelInfo->last_core_mode != FD_SHORT)) {
+ /* USAC Conformance document:
+ short_fac_flag shall be encoded with a value of 1 if the
+ window_sequence of the previous frame was 2 (EIGHT_SHORT_SEQUENCE).
+@@ -1604,8 +1593,7 @@ AAC_DECODER_ERROR CLpd_RenderTimeSignal(
+ return AAC_DEC_UNKNOWN;
+ }
+
+- last_frame_lost = !CConcealment_GetLastFrameOk(
+- &pAacDecoderStaticChannelInfo->concealmentInfo, 0);
++ last_frame_lost = 0;
+
+ /* Maintain LPD mode from previous frame */
+ if ((pAacDecoderStaticChannelInfo->last_core_mode == FD_LONG) ||
+--
+cgit v1.1
+
--- /dev/null
+From b13485d2c310d339e4f55359741ae6b0d6912bbd Mon Sep 17 00:00:00 2001
+From: Wim Taymans <wtaymans@redhat.com>
+Date: Tue, 25 Jun 2019 12:31:47 +0200
+Subject: Remove MPS surround sound encoder
+
+---
+ Makefile.am | 37 -
+ Makefile.vc | 35 -
+ libAACdec/src/aacdecoder.cpp | 160 +--
+ libAACdec/src/aacdecoder.h | 11 -
+ libAACdec/src/aacdecoder_lib.cpp | 206 +--
+ libAACenc/src/aacenc_lib.cpp | 95 +-
+ libAACenc/src/mps_main.cpp | 529 --------
+ libAACenc/src/mps_main.h | 270 ----
+ libSACdec/include/sac_dec_errorcodes.h | 157 ---
+ libSACdec/include/sac_dec_lib.h | 477 -------
+ libSACdec/src/sac_bitdec.cpp | 2167 ------------------------------
+ libSACdec/src/sac_bitdec.h | 161 ---
+ libSACdec/src/sac_calcM1andM2.cpp | 848 ------------
+ libSACdec/src/sac_calcM1andM2.h | 129 --
+ libSACdec/src/sac_dec.cpp | 1509 ---------------------
+ libSACdec/src/sac_dec.h | 539 --------
+ libSACdec/src/sac_dec_conceal.cpp | 392 ------
+ libSACdec/src/sac_dec_conceal.h | 187 ---
+ libSACdec/src/sac_dec_interface.h | 335 -----
+ libSACdec/src/sac_dec_lib.cpp | 1995 ---------------------------
+ libSACdec/src/sac_dec_ssc_struct.h | 283 ----
+ libSACdec/src/sac_process.cpp | 1066 ---------------
+ libSACdec/src/sac_process.h | 297 ----
+ libSACdec/src/sac_qmf.cpp | 156 ---
+ libSACdec/src/sac_qmf.h | 143 --
+ libSACdec/src/sac_reshapeBBEnv.cpp | 680 ----------
+ libSACdec/src/sac_reshapeBBEnv.h | 114 --
+ libSACdec/src/sac_rom.cpp | 709 ----------
+ libSACdec/src/sac_rom.h | 230 ----
+ libSACdec/src/sac_smoothing.cpp | 295 ----
+ libSACdec/src/sac_smoothing.h | 114 --
+ libSACdec/src/sac_stp.cpp | 548 --------
+ libSACdec/src/sac_stp.h | 115 --
+ libSACdec/src/sac_tsd.cpp | 353 -----
+ libSACdec/src/sac_tsd.h | 167 ---
+ libSACenc/include/sacenc_lib.h | 405 ------
+ libSACenc/src/sacenc_bitstream.cpp | 826 ------------
+ libSACenc/src/sacenc_bitstream.h | 296 ----
+ libSACenc/src/sacenc_const.h | 126 --
+ libSACenc/src/sacenc_delay.cpp | 472 -------
+ libSACenc/src/sacenc_delay.h | 175 ---
+ libSACenc/src/sacenc_dmx_tdom_enh.cpp | 639 ---------
+ libSACenc/src/sacenc_dmx_tdom_enh.h | 134 --
+ libSACenc/src/sacenc_filter.cpp | 207 ---
+ libSACenc/src/sacenc_filter.h | 133 --
+ libSACenc/src/sacenc_framewindowing.cpp | 568 --------
+ libSACenc/src/sacenc_framewindowing.h | 181 ---
+ libSACenc/src/sacenc_huff_tab.cpp | 997 --------------
+ libSACenc/src/sacenc_huff_tab.h | 222 ---
+ libSACenc/src/sacenc_lib.cpp | 2042 ----------------------------
+ libSACenc/src/sacenc_nlc_enc.cpp | 1442 --------------------
+ libSACenc/src/sacenc_nlc_enc.h | 141 --
+ libSACenc/src/sacenc_onsetdetect.cpp | 381 ------
+ libSACenc/src/sacenc_onsetdetect.h | 154 ---
+ libSACenc/src/sacenc_paramextract.cpp | 725 ----------
+ libSACenc/src/sacenc_paramextract.h | 214 ---
+ libSACenc/src/sacenc_staticgain.cpp | 446 ------
+ libSACenc/src/sacenc_staticgain.h | 177 ---
+ libSACenc/src/sacenc_tree.cpp | 488 -------
+ libSACenc/src/sacenc_tree.h | 168 ---
+ libSACenc/src/sacenc_vectorfunctions.cpp | 450 -------
+ libSACenc/src/sacenc_vectorfunctions.h | 488 -------
+ 62 files changed, 9 insertions(+), 28197 deletions(-)
+ delete mode 100644 libAACenc/src/mps_main.cpp
+ delete mode 100644 libAACenc/src/mps_main.h
+ delete mode 100644 libSACdec/include/sac_dec_errorcodes.h
+ delete mode 100644 libSACdec/include/sac_dec_lib.h
+ delete mode 100644 libSACdec/src/sac_bitdec.cpp
+ delete mode 100644 libSACdec/src/sac_bitdec.h
+ delete mode 100644 libSACdec/src/sac_calcM1andM2.cpp
+ delete mode 100644 libSACdec/src/sac_calcM1andM2.h
+ delete mode 100644 libSACdec/src/sac_dec.cpp
+ delete mode 100644 libSACdec/src/sac_dec.h
+ delete mode 100644 libSACdec/src/sac_dec_conceal.cpp
+ delete mode 100644 libSACdec/src/sac_dec_conceal.h
+ delete mode 100644 libSACdec/src/sac_dec_interface.h
+ delete mode 100644 libSACdec/src/sac_dec_lib.cpp
+ delete mode 100644 libSACdec/src/sac_dec_ssc_struct.h
+ delete mode 100644 libSACdec/src/sac_process.cpp
+ delete mode 100644 libSACdec/src/sac_process.h
+ delete mode 100644 libSACdec/src/sac_qmf.cpp
+ delete mode 100644 libSACdec/src/sac_qmf.h
+ delete mode 100644 libSACdec/src/sac_reshapeBBEnv.cpp
+ delete mode 100644 libSACdec/src/sac_reshapeBBEnv.h
+ delete mode 100644 libSACdec/src/sac_rom.cpp
+ delete mode 100644 libSACdec/src/sac_rom.h
+ delete mode 100644 libSACdec/src/sac_smoothing.cpp
+ delete mode 100644 libSACdec/src/sac_smoothing.h
+ delete mode 100644 libSACdec/src/sac_stp.cpp
+ delete mode 100644 libSACdec/src/sac_stp.h
+ delete mode 100644 libSACdec/src/sac_tsd.cpp
+ delete mode 100644 libSACdec/src/sac_tsd.h
+ delete mode 100644 libSACenc/include/sacenc_lib.h
+ delete mode 100644 libSACenc/src/sacenc_bitstream.cpp
+ delete mode 100644 libSACenc/src/sacenc_bitstream.h
+ delete mode 100644 libSACenc/src/sacenc_const.h
+ delete mode 100644 libSACenc/src/sacenc_delay.cpp
+ delete mode 100644 libSACenc/src/sacenc_delay.h
+ delete mode 100644 libSACenc/src/sacenc_dmx_tdom_enh.cpp
+ delete mode 100644 libSACenc/src/sacenc_dmx_tdom_enh.h
+ delete mode 100644 libSACenc/src/sacenc_filter.cpp
+ delete mode 100644 libSACenc/src/sacenc_filter.h
+ delete mode 100644 libSACenc/src/sacenc_framewindowing.cpp
+ delete mode 100644 libSACenc/src/sacenc_framewindowing.h
+ delete mode 100644 libSACenc/src/sacenc_huff_tab.cpp
+ delete mode 100644 libSACenc/src/sacenc_huff_tab.h
+ delete mode 100644 libSACenc/src/sacenc_lib.cpp
+ delete mode 100644 libSACenc/src/sacenc_nlc_enc.cpp
+ delete mode 100644 libSACenc/src/sacenc_nlc_enc.h
+ delete mode 100644 libSACenc/src/sacenc_onsetdetect.cpp
+ delete mode 100644 libSACenc/src/sacenc_onsetdetect.h
+ delete mode 100644 libSACenc/src/sacenc_paramextract.cpp
+ delete mode 100644 libSACenc/src/sacenc_paramextract.h
+ delete mode 100644 libSACenc/src/sacenc_staticgain.cpp
+ delete mode 100644 libSACenc/src/sacenc_staticgain.h
+ delete mode 100644 libSACenc/src/sacenc_tree.cpp
+ delete mode 100644 libSACenc/src/sacenc_tree.h
+ delete mode 100644 libSACenc/src/sacenc_vectorfunctions.cpp
+ delete mode 100644 libSACenc/src/sacenc_vectorfunctions.h
+
+diff --git a/Makefile.am b/Makefile.am
+index 16b21e1..1550d95 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -6,8 +6,6 @@ AM_CPPFLAGS = \
+ -I$(top_srcdir)/libAACenc/include \
+ -I$(top_srcdir)/libArithCoding/include \
+ -I$(top_srcdir)/libDRCdec/include \
+- -I$(top_srcdir)/libSACdec/include \
+- -I$(top_srcdir)/libSACenc/include \
+ -I$(top_srcdir)/libMpegTPDec/include \
+ -I$(top_srcdir)/libMpegTPEnc/include \
+ -I$(top_srcdir)/libSYS/include \
+@@ -89,7 +87,6 @@ AACENC_SRC = \
+ libAACenc/src/line_pe.cpp \
+ libAACenc/src/metadata_compressor.cpp \
+ libAACenc/src/metadata_main.cpp \
+- libAACenc/src/mps_main.cpp \
+ libAACenc/src/ms_stereo.cpp \
+ libAACenc/src/noisedet.cpp \
+ libAACenc/src/pnsparam.cpp \
+@@ -159,35 +156,6 @@ PCMUTILS_SRC = \
+ libPCMutils/src/pcm_utils.cpp \
+ libPCMutils/src/pcmdmx_lib.cpp
+
+-SACDEC_SRC = \
+- libSACdec/src/sac_bitdec.cpp \
+- libSACdec/src/sac_calcM1andM2.cpp \
+- libSACdec/src/sac_dec.cpp \
+- libSACdec/src/sac_dec_conceal.cpp \
+- libSACdec/src/sac_dec_lib.cpp \
+- libSACdec/src/sac_process.cpp \
+- libSACdec/src/sac_qmf.cpp \
+- libSACdec/src/sac_reshapeBBEnv.cpp \
+- libSACdec/src/sac_rom.cpp \
+- libSACdec/src/sac_smoothing.cpp \
+- libSACdec/src/sac_stp.cpp \
+- libSACdec/src/sac_tsd.cpp
+-
+-SACENC_SRC = \
+- libSACenc/src/sacenc_bitstream.cpp \
+- libSACenc/src/sacenc_delay.cpp \
+- libSACenc/src/sacenc_dmx_tdom_enh.cpp \
+- libSACenc/src/sacenc_filter.cpp \
+- libSACenc/src/sacenc_framewindowing.cpp \
+- libSACenc/src/sacenc_huff_tab.cpp \
+- libSACenc/src/sacenc_lib.cpp \
+- libSACenc/src/sacenc_nlc_enc.cpp \
+- libSACenc/src/sacenc_onsetdetect.cpp \
+- libSACenc/src/sacenc_paramextract.cpp \
+- libSACenc/src/sacenc_staticgain.cpp \
+- libSACenc/src/sacenc_tree.cpp \
+- libSACenc/src/sacenc_vectorfunctions.cpp
+-
+ SYS_SRC = \
+ libSYS/src/genericStds.cpp \
+ libSYS/src/syslib_channelMapDescr.cpp
+@@ -197,7 +165,6 @@ libfdk_aac_la_SOURCES = \
+ $(ARITHCODING_SRC) \
+ $(DRCDEC_SRC) \
+ $(MPEGTPDEC_SRC) $(MPEGTPENC_SRC) \
+- $(SACDEC_SRC) $(SACENC_SRC) \
+ $(PCMUTILS_SRC) $(FDK_SRC) $(SYS_SRC)
+
+ EXTRA_DIST = \
+@@ -217,10 +184,6 @@ EXTRA_DIST = \
+ $(top_srcdir)/libArithCoding/include/*.h \
+ $(top_srcdir)/libDRCdec/include/*.h \
+ $(top_srcdir)/libDRCdec/src/*.h \
+- $(top_srcdir)/libSACdec/include/*.h \
+- $(top_srcdir)/libSACdec/src/*.h \
+- $(top_srcdir)/libSACenc/include/*.h \
+- $(top_srcdir)/libSACenc/src/*.h \
+ $(top_srcdir)/libSYS/include/*.h \
+ $(top_srcdir)/libPCMutils/include/*.h \
+ $(top_srcdir)/libPCMutils/src/*.h \
+diff --git a/Makefile.vc b/Makefile.vc
+index 97a0615..54f3744 100644
+--- a/Makefile.vc
++++ b/Makefile.vc
+@@ -21,8 +21,6 @@ AM_CPPFLAGS = \
+ -IlibAACenc/include \
+ -IlibArithCoding/include \
+ -IlibDRCdec/include \
+- -IlibSACdec/include \
+- -IlibSACenc/include \
+ -IlibMpegTPDec/include \
+ -IlibMpegTPEnc/include \
+ -IlibSYS/include \
+@@ -73,7 +71,6 @@ AACENC_SRC = \
+ libAACenc/src/line_pe.cpp \
+ libAACenc/src/metadata_compressor.cpp \
+ libAACenc/src/metadata_main.cpp \
+- libAACenc/src/mps_main.cpp \
+ libAACenc/src/ms_stereo.cpp \
+ libAACenc/src/noisedet.cpp \
+ libAACenc/src/pnsparam.cpp \
+@@ -143,35 +140,6 @@ PCMUTILS_SRC = \
+ libPCMutils/src/pcm_utils.cpp \
+ libPCMutils/src/pcmdmx_lib.cpp
+
+-SACDEC_SRC = \
+- libSACdec/src/sac_bitdec.cpp \
+- libSACdec/src/sac_calcM1andM2.cpp \
+- libSACdec/src/sac_dec.cpp \
+- libSACdec/src/sac_dec_conceal.cpp \
+- libSACdec/src/sac_dec_lib.cpp \
+- libSACdec/src/sac_process.cpp \
+- libSACdec/src/sac_qmf.cpp \
+- libSACdec/src/sac_reshapeBBEnv.cpp \
+- libSACdec/src/sac_rom.cpp \
+- libSACdec/src/sac_smoothing.cpp \
+- libSACdec/src/sac_stp.cpp \
+- libSACdec/src/sac_tsd.cpp
+-
+-SACENC_SRC = \
+- libSACenc/src/sacenc_bitstream.cpp \
+- libSACenc/src/sacenc_delay.cpp \
+- libSACenc/src/sacenc_dmx_tdom_enh.cpp \
+- libSACenc/src/sacenc_filter.cpp \
+- libSACenc/src/sacenc_framewindowing.cpp \
+- libSACenc/src/sacenc_huff_tab.cpp \
+- libSACenc/src/sacenc_lib.cpp \
+- libSACenc/src/sacenc_nlc_enc.cpp \
+- libSACenc/src/sacenc_onsetdetect.cpp \
+- libSACenc/src/sacenc_paramextract.cpp \
+- libSACenc/src/sacenc_staticgain.cpp \
+- libSACenc/src/sacenc_tree.cpp \
+- libSACenc/src/sacenc_vectorfunctions.cpp
+-
+ SYS_SRC = \
+ libSYS/src/genericStds.cpp \
+ libSYS/src/syslib_channelMapDescr.cpp
+@@ -181,7 +149,6 @@ libfdk_aac_SOURCES = \
+ $(ARITHCODING_SRC) \
+ $(DRCDEC_SRC) \
+ $(MPEGTPDEC_SRC) $(MPEGTPENC_SRC) \
+- $(SACDEC_SRC) $(SACENC_SRC) \
+ $(PCMUTILS_SRC) $(FDK_SRC) $(SYS_SRC)
+
+
+@@ -227,8 +194,6 @@ clean:
+ del /f libMpegTPDec\src\*.obj 2>NUL
+ del /f libMpegTPEnc\src\*.obj 2>NUL
+ del /f libPCMutils\src\*.obj 2>NUL
+- del /f libSACdec\src\*.obj 2>NUL
+- del /f libSACenc\src\*.obj 2>NUL
+ del /f libSYS\src\*.obj 2>NUL
+
+ install: $(INST_DIRS)
+diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp
+index 6c03567..cc3e245 100644
+--- a/libAACdec/src/aacdecoder.cpp
++++ b/libAACdec/src/aacdecoder.cpp
+@@ -161,8 +161,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "aacdec_pns.h"
+
+-#include "sac_dec_lib.h"
+-
+ #include "usacdec_lpd.h"
+
+ #include "ac_arith_coder.h"
+@@ -201,47 +199,6 @@ void CAacDecoder_SyncQmfMode(HANDLE_AACDECODER self) {
+ }
+ }
+
+- if (self->mpsEnableCurr) {
+- if (IS_LOWDELAY(self->streamInfo.aot) &&
+- (self->qmfModeCurr == MODE_LP)) { /* Overrule user requested QMF mode */
+- self->qmfModeCurr = MODE_HQ;
+- }
+- /* Set and check if MPS decoder allows the current mode */
+- switch (mpegSurroundDecoder_SetParam(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder,
+- SACDEC_PARTIALLY_COMPLEX, self->qmfModeCurr == MODE_LP)) {
+- case MPS_OK:
+- break;
+- case MPS_INVALID_PARAMETER: { /* Only one mode supported. Find out which
+- one: */
+- LIB_INFO libInfo[FDK_MODULE_LAST];
+- UINT mpsCaps;
+-
+- FDKinitLibInfo(libInfo);
+- mpegSurroundDecoder_GetLibInfo(libInfo);
+- mpsCaps = FDKlibInfo_getCapabilities(libInfo, FDK_MPSDEC);
+-
+- if (((mpsCaps & CAPF_MPS_LP) && (self->qmfModeCurr == MODE_LP)) ||
+- ((mpsCaps & CAPF_MPS_HQ) &&
+- (self->qmfModeCurr ==
+- MODE_HQ))) { /* MPS decoder does support the requested mode. */
+- break;
+- }
+- }
+- FDK_FALLTHROUGH;
+- default:
+- if (self->qmfModeUser == NOT_DEFINED) {
+- /* Revert in case mpegSurroundDecoder_SetParam() fails. */
+- self->qmfModeCurr =
+- (self->qmfModeCurr == MODE_LP) ? MODE_HQ : MODE_LP;
+- } else {
+- /* in case specific mode was requested we disable MPS and playout the
+- * downmix */
+- self->mpsEnableCurr = 0;
+- }
+- }
+- }
+-
+ self->psPossible =
+ ((CAN_DO_PS(self->streamInfo.aot) &&
+ !PS_IS_EXPLICITLY_DISABLED(self->streamInfo.aot, self->flags[0]) &&
+@@ -876,45 +833,6 @@ static AAC_DECODER_ERROR CAacDecoder_ExtPayloadParse(
+ goto bail;
+ }
+
+- /* Handle SBR dual rate case */
+- if (self->streamInfo.extSamplingRate != 0) {
+- mpsSampleRate = self->streamInfo.extSamplingRate;
+- mpsFrameSize = self->streamInfo.aacSamplesPerFrame *
+- (self->streamInfo.extSamplingRate /
+- self->streamInfo.aacSampleRate);
+- } else {
+- mpsSampleRate = self->streamInfo.aacSampleRate;
+- mpsFrameSize = self->streamInfo.aacSamplesPerFrame;
+- }
+- /* Setting of internal MPS state; may be reset in
+- CAacDecoder_SyncQmfMode if decoder is unable to decode with user
+- defined qmfMode */
+- if (!(self->flags[0] & (AC_USAC | AC_RSVD50 | AC_ELD))) {
+- self->mpsEnableCurr = self->mpsEnableUser;
+- }
+- if (self->mpsEnableCurr) {
+- if (!self->qmfDomain.globalConf.qmfDomainExplicitConfig) {
+- /* if not done yet, allocate full MPEG Surround decoder instance */
+- if (mpegSurroundDecoder_IsFullMpegSurroundDecoderInstanceAvailable(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder) ==
+- SAC_INSTANCE_NOT_FULL_AVAILABLE) {
+- if (mpegSurroundDecoder_Open(
+- (CMpegSurroundDecoder **)&self->pMpegSurroundDecoder, -1,
+- &self->qmfDomain)) {
+- return AAC_DEC_OUT_OF_MEMORY;
+- }
+- }
+- }
+- err = mpegSurroundDecoder_Parse(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder, hBs, count,
+- self->streamInfo.aot, mpsSampleRate, mpsFrameSize,
+- self->flags[0] & AC_INDEP);
+- if (err == MPS_OK) {
+- self->flags[0] |= AC_MPS_PRESENT;
+- } else {
+- error = AAC_DEC_PARSE_ERROR;
+- }
+- }
+ /* Skip any trailing bytes */
+ FDKpushFor(hBs, *count);
+ *count = 0;
+@@ -1080,15 +998,8 @@ static AAC_DECODER_ERROR aacDecoder_ParseExplicitMpsAndSbr(
+ if ((bitCnt > 0) && (self->flags[0] & (AC_USAC | AC_RSVD50))) {
+ if ((self->flags[0] & AC_MPS_PRESENT) ||
+ (self->elFlags[element_index] & AC_EL_USAC_MPS212)) {
+- int err;
+-
+- err = mpegSurroundDecoder_ParseNoHeader(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder, bs, &bitCnt,
+- self->flags[0] & AC_INDEP);
+- if (err != MPS_OK) {
+- self->frameOK = 0;
+- ErrorStatus = AAC_DEC_PARSE_ERROR;
+- }
++ self->frameOK = 0;
++ ErrorStatus = AAC_DEC_PARSE_ERROR;
+ }
+ }
+
+@@ -1581,58 +1492,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ asc->m_sc.m_usacConfig.m_usacNumElements;
+ }
+
+- self->mpsEnableCurr = 0;
+- for (int _el = 0;
+- _el < (int)self->pUsacConfig[streamIndex]->m_usacNumElements;
+- _el++) {
+- int el = _el + elementOffset;
+- if (self->elements[el] !=
+- self->pUsacConfig[streamIndex]->element[_el].usacElementType) {
+- ascChanged = 1;
+- }
+- if (self->usacStereoConfigIndex[el] !=
+- asc->m_sc.m_usacConfig.element[_el].m_stereoConfigIndex) {
+- ascChanged = 1;
+- }
+- if (configMode & AC_CM_ALLOC_MEM) {
+- self->elements[el] =
+- self->pUsacConfig[streamIndex]->element[_el].usacElementType;
+- /* for Unified Stereo Coding */
+- self->usacStereoConfigIndex[el] =
+- asc->m_sc.m_usacConfig.element[_el].m_stereoConfigIndex;
+- if (self->elements[el] == ID_USAC_CPE) {
+- self->mpsEnableCurr |= self->usacStereoConfigIndex[el] ? 1 : 0;
+- }
+- }
+-
+- self->elFlags[el] |=
+- (asc->m_sc.m_usacConfig.element[_el].m_noiseFilling)
+- ? AC_EL_USAC_NOISE
+- : 0;
+- self->elFlags[el] |=
+- (asc->m_sc.m_usacConfig.element[_el].m_stereoConfigIndex > 0)
+- ? AC_EL_USAC_MPS212
+- : 0;
+- self->elFlags[el] |= (asc->m_sc.m_usacConfig.element[_el].m_interTes)
+- ? AC_EL_USAC_ITES
+- : 0;
+- self->elFlags[el] |=
+- (asc->m_sc.m_usacConfig.element[_el].m_pvc) ? AC_EL_USAC_PVC : 0;
+- self->elFlags[el] |=
+- (asc->m_sc.m_usacConfig.element[_el].usacElementType == ID_USAC_LFE)
+- ? AC_EL_USAC_LFE
+- : 0;
+- self->elFlags[el] |=
+- (asc->m_sc.m_usacConfig.element[_el].usacElementType == ID_USAC_LFE)
+- ? AC_EL_LFE
+- : 0;
+- if ((asc->m_sc.m_usacConfig.element[_el].usacElementType ==
+- ID_USAC_CPE) &&
+- ((self->usacStereoConfigIndex[el] == 0))) {
+- self->elFlags[el] |= AC_EL_USAC_CP_POSSIBLE;
+- }
+- }
+-
+ self->hasAudioPreRoll = 0;
+ if (self->pUsacConfig[streamIndex]->m_usacNumElements) {
+ self->hasAudioPreRoll = asc->m_sc.m_usacConfig.element[0]
+@@ -1764,7 +1623,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ self->flags[streamIndex] |= (asc->m_hcrFlag) ? AC_ER_HCR : 0;
+
+ if (asc->m_aot == AOT_ER_AAC_ELD) {
+- self->mpsEnableCurr = 0;
+ self->flags[streamIndex] |= AC_ELD;
+ self->flags[streamIndex] |=
+ (asc->m_sbrPresentFlag)
+@@ -1776,9 +1634,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ self->flags[streamIndex] |=
+ (asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign) ? AC_MPS_PRESENT
+ : 0;
+- if (self->mpsApplicable) {
+- self->mpsEnableCurr = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign;
+- }
++
+ }
+ self->flags[streamIndex] |= (asc->m_aot == AOT_ER_AAC_LD) ? AC_LD : 0;
+ self->flags[streamIndex] |= (asc->m_epConfig >= 0) ? AC_ER : 0;
+@@ -1867,14 +1723,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ case AOT_USAC:
+ break;
+ case AOT_ER_AAC_ELD:
+- if (self->mpsEnableCurr &&
+- asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign) {
+- SAC_INPUT_CONFIG sac_interface = SAC_INTERFACE_TIME;
+- mpegSurroundDecoder_ConfigureQmfDomain(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder, sac_interface,
+- (UINT)self->streamInfo.aacSampleRate, asc->m_aot);
+- self->qmfDomain.globalConf.qmfDomainExplicitConfig = 1;
+- }
+ break;
+ default:
+ self->qmfDomain.globalConf.qmfDomainExplicitConfig =
+@@ -3128,8 +2976,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+
+ if (self->flags[streamIndex] & AC_USAC) {
+ int bsPseudoLr = 0;
+- mpegSurroundDecoder_IsPseudoLR(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder, &bsPseudoLr);
+ /* ISO/IEC 23003-3, 7.11.2.6 Modification of core decoder output (pseudo
+ * LR) */
+ if ((aacChannels == 2) && bsPseudoLr) {
+diff --git a/libAACdec/src/aacdecoder.h b/libAACdec/src/aacdecoder.h
+index 3750389..a57b0bb 100644
+--- a/libAACdec/src/aacdecoder.h
++++ b/libAACdec/src/aacdecoder.h
+@@ -276,17 +276,6 @@ This structure is allocated once for each CPE. */
+ HANDLE_AAC_DRC hDrcInfo; /*!< handle to DRC data structure */
+ INT metadataExpiry; /*!< Metadata expiry time in milli-seconds. */
+
+- void *pMpegSurroundDecoder; /*!< pointer to mpeg surround decoder structure */
+- UCHAR mpsEnableUser; /*!< MPS enable user flag */
+- UCHAR mpsEnableCurr; /*!< MPS enable decoder state */
+- UCHAR mpsApplicable; /*!< MPS applicable */
+- SCHAR mpsOutputMode; /*!< setting: normal = 0, binaural = 1, stereo = 2, 5.1ch
+- = 3 */
+- INT mpsOutChannelsLast; /*!< The amount of channels returned by the last
+- successful MPS decoder call. */
+- INT mpsFrameSizeLast; /*!< The frame length returned by the last successful
+- MPS decoder call. */
+-
+ CAncData ancData; /*!< structure to handle ancillary data */
+
+ HANDLE_PCM_DOWNMIX hPcmUtils; /*!< privat data for the PCM utils. */
+diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp
+index 1fc6ea0..e49d502 100644
+--- a/libAACdec/src/aacdecoder_lib.cpp
++++ b/libAACdec/src/aacdecoder_lib.cpp
+@@ -109,8 +109,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "aacdec_drc.h"
+
+-#include "sac_dec_lib.h"
+-
+ #include "pcm_utils.h"
+
+ /* Decoder library info */
+@@ -306,14 +304,6 @@ static INT aacDecoder_FreeMemCallback(void *handle,
+ errTp = TRANSPORTDEC_UNKOWN_ERROR;
+ }
+
+- /* free pSpatialDec and mpsData */
+- if (self->pMpegSurroundDecoder != NULL) {
+- if (mpegSurroundDecoder_FreeMem(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder) != MPS_OK) {
+- errTp = TRANSPORTDEC_UNKOWN_ERROR;
+- }
+- }
+-
+ /* free persistent qmf domain buffer, QmfWorkBufferCore3, QmfWorkBufferCore4,
+ * QmfWorkBufferCore5 and configuration variables */
+ FDK_QmfDomain_FreeMem(&self->qmfDomain);
+@@ -344,44 +334,9 @@ static INT aacDecoder_SscCallback(void *handle, HANDLE_FDK_BITSTREAM hBs,
+ const INT coreSbrFrameLengthIndex,
+ const INT configBytes, const UCHAR configMode,
+ UCHAR *configChanged) {
+- SACDEC_ERROR err;
+ TRANSPORTDEC_ERROR errTp;
+ HANDLE_AACDECODER hAacDecoder = (HANDLE_AACDECODER)handle;
+-
+- err = mpegSurroundDecoder_Config(
+- (CMpegSurroundDecoder *)hAacDecoder->pMpegSurroundDecoder, hBs, coreCodec,
+- samplingRate, frameSize, stereoConfigIndex, coreSbrFrameLengthIndex,
+- configBytes, configMode, configChanged);
+-
+- switch (err) {
+- case MPS_UNSUPPORTED_CONFIG:
+- /* MPS found but invalid or not decodable by this instance */
+- /* We switch off MPS and keep going */
+- hAacDecoder->mpsEnableCurr = 0;
+- hAacDecoder->mpsApplicable = 0;
+- errTp = TRANSPORTDEC_OK;
+- break;
+- case MPS_PARSE_ERROR:
+- /* MPS found but invalid or not decodable by this instance */
+- hAacDecoder->mpsEnableCurr = 0;
+- hAacDecoder->mpsApplicable = 0;
+- if ((coreCodec == AOT_USAC) || (coreCodec == AOT_DRM_USAC) ||
+- IS_LOWDELAY(coreCodec)) {
+- errTp = TRANSPORTDEC_PARSE_ERROR;
+- } else {
+- errTp = TRANSPORTDEC_OK;
+- }
+- break;
+- case MPS_OK:
+- hAacDecoder->mpsApplicable = 1;
+- errTp = TRANSPORTDEC_OK;
+- break;
+- default:
+- /* especially Parsing error is critical for transport layer */
+- hAacDecoder->mpsApplicable = 0;
+- errTp = TRANSPORTDEC_UNKOWN_ERROR;
+- }
+-
++ errTp = TRANSPORTDEC_UNKOWN_ERROR;
+ return (INT)errTp;
+ }
+
+@@ -451,8 +406,6 @@ static int isSupportedMpsConfig(AUDIO_OBJECT_TYPE aot,
+
+ FDKinitLibInfo(libInfo);
+
+- mpegSurroundDecoder_GetLibInfo(libInfo);
+-
+ mpsCaps = FDKlibInfo_getCapabilities(libInfo, FDK_MPSDEC);
+
+ if (!(mpsCaps & CAPF_MPS_LD) && IS_LOWDELAY(aot)) {
+@@ -869,19 +822,6 @@ LINKSPEC_CPP HANDLE_AACDECODER aacDecoder_Open(TRANSPORT_TYPE transportFmt,
+ FDKmemclear(&aacDec->qmfDomain, sizeof(FDK_QMF_DOMAIN));
+ aacDec->qmfModeUser = NOT_DEFINED;
+
+- if (mpegSurroundDecoder_Open(
+- (CMpegSurroundDecoder **)&aacDec->pMpegSurroundDecoder,
+- stereoConfigIndex, &aacDec->qmfDomain)) {
+- err = -1;
+- goto bail;
+- }
+- /* Set MPEG Surround defaults */
+- aacDec->mpsEnableUser = 0;
+- aacDec->mpsEnableCurr = 0;
+- aacDec->mpsApplicable = 0;
+- aacDec->mpsOutputMode = (SCHAR)SACDEC_OUT_MODE_NORMAL;
+- transportDec_RegisterSscCallback(pIn, aacDecoder_SscCallback, (void *)aacDec);
+-
+ {
+ if (FDK_drcDec_Open(&(aacDec->hUniDrcDecoder), DRC_DEC_ALL) != 0) {
+ err = -1;
+@@ -952,12 +892,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_Fill(HANDLE_AACDECODER self,
+
+ static void aacDecoder_SignalInterruption(HANDLE_AACDECODER self) {
+ CAacDecoder_SignalInterruption(self);
+-
+- if (self->mpsEnableUser) {
+- mpegSurroundDecoder_SetParam(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder,
+- SACDEC_BS_INTERRUPTION, 1);
+- }
+ }
+
+ static void aacDecoder_UpdateBitStreamCounters(CStreamInfo *pSi,
+@@ -1157,9 +1091,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ Tell other modules to clear states if required. */
+ if (flags & AACDEC_CLRHIST) {
+ if (!(self->flags[0] & AC_USAC)) {
+- mpegSurroundDecoder_SetParam(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder,
+- SACDEC_CLEAR_HISTORY, 1);
+ if (FDK_QmfDomain_ClearPersistentMemory(&self->qmfDomain) != 0) {
+ ErrorStatus = AAC_DEC_UNKNOWN;
+ goto bail;
+@@ -1247,48 +1178,8 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ self->streamInfo.frameSize, 0);
+ }
+
+- /* Setting of internal MPS state; may be reset in CAacDecoder_SyncQmfMode
+- if decoder is unable to decode with user defined qmfMode */
+- if (!(self->flags[0] & (AC_USAC | AC_RSVD50 | AC_RSV603DA | AC_ELD))) {
+- self->mpsEnableCurr =
+- (self->mpsEnableUser &&
+- isSupportedMpsConfig(self->streamInfo.aot,
+- self->streamInfo.numChannels,
+- (self->flags[0] & AC_MPS_PRESENT) ? 1 : 0));
+- }
+-
+- if (!self->qmfDomain.globalConf.qmfDomainExplicitConfig &&
+- self->mpsEnableCurr) {
+- /* if not done yet, allocate full MPEG Surround decoder instance */
+- if (mpegSurroundDecoder_IsFullMpegSurroundDecoderInstanceAvailable(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder) ==
+- SAC_INSTANCE_NOT_FULL_AVAILABLE) {
+- if (mpegSurroundDecoder_Open(
+- (CMpegSurroundDecoder **)&self->pMpegSurroundDecoder, -1,
+- &self->qmfDomain)) {
+- return AAC_DEC_OUT_OF_MEMORY;
+- }
+- }
+- }
+-
+ CAacDecoder_SyncQmfMode(self);
+
+- if (!self->qmfDomain.globalConf.qmfDomainExplicitConfig &&
+- self->mpsEnableCurr) {
+- SAC_INPUT_CONFIG sac_interface = SAC_INTERFACE_TIME;
+- /* needs to be done before first SBR apply. */
+- mpegSurroundDecoder_ConfigureQmfDomain(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder, sac_interface,
+- (UINT)self->streamInfo.aacSampleRate, self->streamInfo.aot);
+- if (self->qmfDomain.globalConf.nBandsAnalysis_requested > 0) {
+- self->qmfDomain.globalConf.nQmfTimeSlots_requested =
+- self->streamInfo.aacSamplesPerFrame /
+- self->qmfDomain.globalConf.nBandsAnalysis_requested;
+- } else {
+- self->qmfDomain.globalConf.nQmfTimeSlots_requested = 0;
+- }
+- }
+-
+ self->qmfDomain.globalConf.TDinput = pTimeData;
+
+ switch (FDK_QmfDomain_Configure(&self->qmfDomain)) {
+@@ -1308,61 +1199,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ decoder too */
+ }
+
+- if (self->mpsEnableCurr) {
+- int err, sac_interface, nChannels, frameSize;
+-
+- nChannels = self->streamInfo.numChannels;
+- frameSize = self->streamInfo.frameSize;
+- sac_interface = SAC_INTERFACE_TIME;
+-
+- if (self->streamInfo.aot == AOT_USAC) {
+- if (self->flags[0] & AC_USAC_SCFGI3) {
+- sac_interface = SAC_INTERFACE_TIME;
+- }
+- }
+- err = mpegSurroundDecoder_SetParam(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder,
+- SACDEC_INTERFACE, sac_interface);
+-
+- if (err == 0) {
+- err = mpegSurroundDecoder_Apply(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder,
+- (INT_PCM *)self->workBufferCore2, pTimeData, timeDataSize,
+- self->streamInfo.aacSamplesPerFrame, &nChannels, &frameSize,
+- self->streamInfo.sampleRate, self->streamInfo.aot,
+- self->channelType, self->channelIndices, &self->mapDescr);
+- }
+-
+- if (err == MPS_OUTPUT_BUFFER_TOO_SMALL) {
+- ErrorStatus = AAC_DEC_OUTPUT_BUFFER_TOO_SMALL;
+- goto bail;
+- }
+- if (err == 0) {
+- /* Update output parameter */
+- self->streamInfo.numChannels = nChannels;
+- self->streamInfo.frameSize = frameSize;
+- self->streamInfo.outputDelay += mpegSurroundDecoder_GetDelay(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder);
+- /* Save current parameter for possible concealment of next frame */
+- self->mpsOutChannelsLast = nChannels;
+- self->mpsFrameSizeLast = frameSize;
+- } else if ((self->mpsOutChannelsLast > 0) &&
+- (self->mpsFrameSizeLast > 0)) {
+- /* Restore parameters of last frame ... */
+- self->streamInfo.numChannels = self->mpsOutChannelsLast;
+- self->streamInfo.frameSize = self->mpsFrameSizeLast;
+- /* ... and clear output buffer so that potentially corrupted data does
+- * not reach the framework. */
+- FDKmemclear(pTimeData, self->mpsOutChannelsLast *
+- self->mpsFrameSizeLast * sizeof(INT_PCM));
+- /* Additionally proclaim that this frame had errors during decoding.
+- */
+- ErrorStatus = AAC_DEC_DECODE_FRAME_ERROR;
+- } else {
+- ErrorStatus = AAC_DEC_UNKNOWN; /* no output */
+- }
+- }
+-
+ /* Use dedicated memory for PCM postprocessing */
+ pTimeDataPcmPost = self->pTimeData2;
+ timeDataPcmPostSize = self->timeData2Size;
+@@ -1395,11 +1231,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ reverseOutChannelMap[ch] = ch;
+ }
+
+- /* If SBR and/or MPS is active, the DRC gains are aligned to the QMF
+- domain signal before the QMF synthesis. Therefore the DRC gains
+- need to be delayed by the QMF synthesis delay. */
+- if (self->mpsEnableCurr) drcDelay = 257;
+-
+ for (ch = 0; ch < self->streamInfo.numChannels; ch++) {
+ UCHAR mapValue = FDK_chMapDescr_getMapValue(
+ &self->mapDescr, (UCHAR)ch, self->chMapIndex);
+@@ -1411,27 +1242,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ if (mapValue < (8)) reverseOutChannelMap[mapValue] = ch;
+ }
+
+- /* The output of SBR and MPS is interleaved. Deinterleaving may be
+- * necessary for FDK_drcDec_ProcessTime, which accepts deinterleaved
+- * audio only. */
+- if ((self->streamInfo.numChannels > 1) &&
+- (0 || (self->mpsEnableCurr))) {
+- /* interleaving/deinterleaving is performed on upper part of
+- * pTimeDataPcmPost. Check if this buffer is large enough. */
+- if (timeDataPcmPostSize <
+- (INT)(2 * self->streamInfo.numChannels *
+- self->streamInfo.frameSize * sizeof(PCM_DEC))) {
+- ErrorStatus = AAC_DEC_UNKNOWN;
+- goto bail;
+- }
+- needsDeinterleaving = 1;
+- drcWorkBuffer =
+- (FIXP_DBL *)pTimeDataPcmPost +
+- self->streamInfo.numChannels * self->streamInfo.frameSize;
+- FDK_deinterleave(
+- pTimeDataPcmPost, drcWorkBuffer, self->streamInfo.numChannels,
+- self->streamInfo.frameSize, self->streamInfo.frameSize);
+- } else {
++ {
+ drcWorkBuffer = (FIXP_DBL *)pTimeDataPcmPost;
+ }
+
+@@ -1488,7 +1299,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ }
+
+ INT interleaved = 0;
+- interleaved |= (self->mpsEnableCurr) ? 1 : 0;
+
+ /* do PCM post processing */
+ dmxErr = pcmDmx_ApplyFrame(
+@@ -1525,8 +1335,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ pcmLimiter_SetSampleRate(self->hLimiter, self->streamInfo.sampleRate);
+ pcmLimiterScale += PCM_OUT_HEADROOM;
+
+- if ((self->streamInfo.numChannels == 1) ||
+- (self->mpsEnableCurr)) {
++ if ((self->streamInfo.numChannels == 1)) {
+ pInterleaveBuffer = (PCM_LIM *)pTimeDataPcmPost;
+ } else {
+ pInterleaveBuffer = (PCM_LIM *)pTimeData;
+@@ -1549,8 +1358,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
+ /* If numChannels = 1 we do not need interleaving. The same applies if
+ SBR or MPS are used, since their output is interleaved already
+ (resampled or not) */
+- if ((self->streamInfo.numChannels == 1) ||
+- (self->mpsEnableCurr)) {
++ if ((self->streamInfo.numChannels == 1)) {
+ scaleValuesSaturate(
+ pTimeData, pTimeDataPcmPost,
+ self->streamInfo.frameSize * self->streamInfo.numChannels,
+@@ -1688,11 +1496,6 @@ LINKSPEC_CPP void aacDecoder_Close(HANDLE_AACDECODER self) {
+
+ FDK_drcDec_Close(&self->hUniDrcDecoder);
+
+- if (self->pMpegSurroundDecoder != NULL) {
+- mpegSurroundDecoder_Close(
+- (CMpegSurroundDecoder *)self->pMpegSurroundDecoder);
+- }
+-
+ if (self->hInput != NULL) {
+ transportDec_Close(&self->hInput);
+ }
+@@ -1711,7 +1514,6 @@ LINKSPEC_CPP INT aacDecoder_GetLibInfo(LIB_INFO *info) {
+ return -1;
+ }
+
+- mpegSurroundDecoder_GetLibInfo(info);
+ transportDec_GetLibInfo(info);
+ FDK_toolsGetLibInfo(info);
+ pcmDmx_GetLibInfo(info);
+diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp
+index 51f3f49..7382106 100644
+--- a/libAACenc/src/aacenc_lib.cpp
++++ b/libAACenc/src/aacenc_lib.cpp
+@@ -130,8 +130,6 @@ amm-info@iis.fraunhofer.de
+ #include "tpenc_lib.h"
+
+ #include "metadata_main.h"
+-#include "mps_main.h"
+-#include "sacenc_lib.h"
+
+ #define SBL(fl) \
+ (fl / \
+@@ -223,8 +221,6 @@ struct AACENCODER {
+ Necessary for delay compensation. Metadata mode is a
+ separate parameter. */
+
+- HANDLE_MPS_ENCODER hMpsEnc;
+-
+ /* Transport */
+ HANDLE_TRANSPORTENC hTpEnc;
+
+@@ -541,14 +537,6 @@ static INT aacEncoder_LimitBitrate(const HANDLE_TRANSPORTENC hTpEnc,
+ nChannels, cm.nChannelsEff, bitRate, -1,
+ NULL, AACENC_BR_MODE_INVALID, nSubFrames);
+
+- /* Limit bit rate in respect to available MPS modes if active */
+- if ((aot == AOT_ER_AAC_ELD) && (syntaxFlags & AC_LD_MPS) &&
+- (channelMode == MODE_1)) {
+- bitRate = FDK_MpegsEnc_GetClosestBitRate(
+- aot, MODE_212, samplingRate, 0,
+- bitRate);
+- }
+-
+ return bitRate;
+ }
+
+@@ -863,17 +851,6 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
+ return err;
+ }
+
+-INT aacenc_SscCallback(void *self, HANDLE_FDK_BITSTREAM hBs,
+- const AUDIO_OBJECT_TYPE coreCodec,
+- const INT samplingRate, const INT frameSize,
+- const INT stereoConfigIndex,
+- const INT coreSbrFrameLengthIndex, const INT configBytes,
+- const UCHAR configMode, UCHAR *configChanged) {
+- HANDLE_AACENCODER hAacEncoder = (HANDLE_AACENCODER)self;
+-
+- return (FDK_MpegsEnc_WriteSpatialSpecificConfig(hAacEncoder->hMpsEnc, hBs));
+-}
+-
+ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+ USER_PARAM *config) {
+ AACENC_ERROR err = AACENC_OK;
+@@ -918,23 +895,6 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+ hAacConfig->ancDataBitRate = 0;
+ }
+
+- if ((hAacEncoder->hMpsEnc != NULL) && (hAacConfig->syntaxFlags & AC_LD_MPS)) {
+- int coreCoderDelay = DELAY_AACELD(hAacConfig->framelength);
+-
+- if (MPS_ENCODER_OK !=
+- FDK_MpegsEnc_Init(hAacEncoder->hMpsEnc, hAacConfig->audioObjectType,
+- config->userSamplerate, hAacConfig->bitRate,
+- 0,
+- frameLength, /* for dual rate sbr this value is
+- already multiplied by 2 */
+- hAacEncoder->inputBufferSizePerChannel,
+- coreCoderDelay)) {
+- return AACENC_INIT_MPS_ERROR;
+- }
+- }
+- hAacEncoder->nDelay =
+- fMax(FDK_MpegsEnc_GetDelay(hAacEncoder->hMpsEnc), hAacEncoder->nDelay);
+-
+ /*
+ * Initialize Transport - Module.
+ */
+@@ -994,13 +954,7 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, ULONG InitFlags,
+ hAacEncoder->nDelay += FDK_MetadataEnc_GetDelay(hAacEncoder->hMetadataEnc);
+ }
+
+- /* Get custom delay, i.e. the codec delay w/o the decoder's SBR- or MPS delay
+- */
+- if ((hAacEncoder->hMpsEnc != NULL) && (hAacConfig->syntaxFlags & AC_LD_MPS)) {
+- hAacEncoder->nDelayCore =
+- hAacEncoder->nDelay -
+- fMax(0, FDK_MpegsEnc_GetDecDelay(hAacEncoder->hMpsEnc));
+- } else {
++ {
+ hAacEncoder->nDelayCore = hAacEncoder->nDelay;
+ }
+
+@@ -1120,14 +1074,6 @@ AACENC_ERROR aacEncOpen(HANDLE_AACENCODER *phAacEncoder, const UINT encModules,
+ }
+ } /* (encoder_modis&ENC_MODE_FLAG_META) */
+
+- /* Open MPEG Surround Encoder */
+- if (hAacEncoder->encoder_modis & ENC_MODE_FLAG_SAC) {
+- if (MPS_ENCODER_OK != FDK_MpegsEnc_Open(&hAacEncoder->hMpsEnc)) {
+- err = AACENC_MEMORY_ERROR;
+- goto bail;
+- }
+- } /* (hAacEncoder->encoder_modis&ENC_MODE_FLAG_SAC) */
+-
+ /* Open Transport Encoder */
+ if (transportEnc_Open(&hAacEncoder->hTpEnc) != 0) {
+ err = AACENC_MEMORY_ERROR;
+@@ -1146,11 +1092,6 @@ AACENC_ERROR aacEncOpen(HANDLE_AACENCODER *phAacEncoder, const UINT encModules,
+
+ C_ALLOC_SCRATCH_END(_pLibInfo, LIB_INFO, FDK_MODULE_LAST)
+ }
+- if (transportEnc_RegisterSscCallback(hAacEncoder->hTpEnc, aacenc_SscCallback,
+- hAacEncoder) != 0) {
+- err = AACENC_INIT_TP_ERROR;
+- goto bail;
+- }
+
+ /* Initialize encoder instance with default parameters. */
+ aacEncDefaultConfig(&hAacEncoder->aacConfig, &hAacEncoder->extParam);
+@@ -1202,9 +1143,6 @@ AACENC_ERROR aacEncClose(HANDLE_AACENCODER *phAacEncoder) {
+ if (hAacEncoder->hMetadataEnc) {
+ FDK_MetadataEnc_Close(&hAacEncoder->hMetadataEnc);
+ }
+- if (hAacEncoder->hMpsEnc) {
+- FDK_MpegsEnc_Close(&hAacEncoder->hMpsEnc);
+- }
+
+ Free_AacEncoder(phAacEncoder);
+ }
+@@ -1399,30 +1337,6 @@ AACENC_ERROR aacEncEncode(const HANDLE_AACENCODER hAacEncoder,
+ }
+ }
+
+- /*
+- * Encode MPS data.
+- */
+- if ((hAacEncoder->hMpsEnc != NULL) &&
+- (hAacEncoder->aacConfig.syntaxFlags & AC_LD_MPS)) {
+- AACENC_EXT_PAYLOAD mpsExtensionPayload;
+- FDKmemclear(&mpsExtensionPayload, sizeof(AACENC_EXT_PAYLOAD));
+-
+- if (MPS_ENCODER_OK !=
+- FDK_MpegsEnc_Process(
+- hAacEncoder->hMpsEnc,
+- hAacEncoder->inputBuffer + hAacEncoder->inputBufferOffset /
+- hAacEncoder->coderConfig.noChannels,
+- hAacEncoder->nSamplesRead, &mpsExtensionPayload)) {
+- err = AACENC_ENCODE_ERROR;
+- goto bail;
+- }
+-
+- if ((mpsExtensionPayload.pData != NULL) &&
+- ((mpsExtensionPayload.dataSize != 0))) {
+- hAacEncoder->extPayload[nExtensions++] = mpsExtensionPayload;
+- }
+- }
+-
+ if ((inargs->numAncBytes > 0) &&
+ (getBufDescIdx(inBufDesc, IN_ANCILLRY_DATA) != -1)) {
+ INT idx = getBufDescIdx(inBufDesc, IN_ANCILLRY_DATA);
+@@ -1528,7 +1442,6 @@ AACENC_ERROR aacEncGetLibInfo(LIB_INFO *info) {
+
+ FDK_toolsGetLibInfo(info);
+ transportEnc_GetLibInfo(info);
+- FDK_MpegsEnc_GetLibInfo(info);
+
+ /* search for next free tab */
+ for (i = 0; i < FDK_MODULE_LAST; i++) {
+@@ -1645,11 +1558,7 @@ AACENC_ERROR aacEncoder_SetParam(const HANDLE_AACENCODER hAacEncoder,
+ break;
+ case AACENC_CHANNELMODE:
+ if (settings->userChannelMode != (CHANNEL_MODE)value) {
+- if (((CHANNEL_MODE)value == MODE_212) &&
+- (NULL != hAacEncoder->hMpsEnc)) {
+- settings->userChannelMode = (CHANNEL_MODE)value;
+- settings->nChannels = 2;
+- } else {
++ {
+ const CHANNEL_MODE_CONFIG_TAB *pConfig =
+ FDKaacEnc_GetChannelModeConfiguration((CHANNEL_MODE)value);
+ if (pConfig == NULL) {
+diff --git a/libAACenc/src/mps_main.cpp b/libAACenc/src/mps_main.cpp
+deleted file mode 100644
+index 1048228..0000000
+--- a/libAACenc/src/mps_main.cpp
++++ /dev/null
+@@ -1,529 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC encoder library ******************************
+-
+- Author(s): Markus Lohwasser
+-
+- Description: Mpeg Surround library interface functions
+-
+-*******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "mps_main.h"
+-#include "sacenc_lib.h"
+-
+-/* Data Types ****************************************************************/
+-struct MPS_ENCODER {
+- HANDLE_MP4SPACE_ENCODER hSacEncoder;
+-
+- AUDIO_OBJECT_TYPE audioObjectType;
+-
+- FDK_bufDescr inBufDesc;
+- FDK_bufDescr outBufDesc;
+- SACENC_InArgs inargs;
+- SACENC_OutArgs outargs;
+-
+- void *pInBuffer[1];
+- UINT pInBufferSize[1];
+- UINT pInBufferElSize[1];
+- UINT pInBufferType[1];
+-
+- void *pOutBuffer[2];
+- UINT pOutBufferSize[2];
+- UINT pOutBufferElSize[2];
+- UINT pOutBufferType[2];
+-
+- UCHAR sacOutBuffer[1024]; /* Worst case memory consumption for ELDv2: 768
+- bytes => 6144 bits (Core + SBR + MPS) */
+-};
+-
+-struct MPS_CONFIG_TAB {
+- AUDIO_OBJECT_TYPE audio_object_type;
+- CHANNEL_MODE channel_mode;
+- ULONG sbr_ratio;
+- ULONG sampling_rate;
+- ULONG bitrate_min;
+- ULONG bitrate_max;
+-};
+-
+-/* Constants *****************************************************************/
+-static const MPS_CONFIG_TAB mpsConfigTab[] = {
+- {AOT_ER_AAC_ELD, MODE_212, 0, 16000, 16000, 39999},
+- {AOT_ER_AAC_ELD, MODE_212, 0, 22050, 16000, 49999},
+- {AOT_ER_AAC_ELD, MODE_212, 0, 24000, 16000, 61999},
+- {AOT_ER_AAC_ELD, MODE_212, 0, 32000, 20000, 84999},
+- {AOT_ER_AAC_ELD, MODE_212, 0, 44100, 50000, 192000},
+- {AOT_ER_AAC_ELD, MODE_212, 0, 48000, 62000, 192000},
+-
+- {AOT_ER_AAC_ELD, MODE_212, 1, 16000, 18000, 31999},
+- {AOT_ER_AAC_ELD, MODE_212, 1, 22050, 18000, 31999},
+- {AOT_ER_AAC_ELD, MODE_212, 1, 24000, 20000, 64000},
+-
+- {AOT_ER_AAC_ELD, MODE_212, 2, 32000, 18000, 64000},
+- {AOT_ER_AAC_ELD, MODE_212, 2, 44100, 21000, 64000},
+- {AOT_ER_AAC_ELD, MODE_212, 2, 48000, 26000, 64000}
+-
+-};
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-static INT FDK_MpegsEnc_WriteFrameHeader(HANDLE_MPS_ENCODER hMpsEnc,
+- UCHAR *const pOutputBuffer,
+- const int outputBufferSize);
+-
+-MPS_ENCODER_ERROR FDK_MpegsEnc_Open(HANDLE_MPS_ENCODER *phMpsEnc) {
+- MPS_ENCODER_ERROR error = MPS_ENCODER_OK;
+- HANDLE_MPS_ENCODER hMpsEnc = NULL;
+-
+- if (phMpsEnc == NULL) {
+- error = MPS_ENCODER_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- if (NULL ==
+- (hMpsEnc = (HANDLE_MPS_ENCODER)FDKcalloc(1, sizeof(MPS_ENCODER)))) {
+- error = MPS_ENCODER_MEMORY_ERROR;
+- goto bail;
+- }
+- FDKmemclear(hMpsEnc, sizeof(MPS_ENCODER));
+-
+- if (SACENC_OK != FDK_sacenc_open(&hMpsEnc->hSacEncoder)) {
+- error = MPS_ENCODER_MEMORY_ERROR;
+- goto bail;
+- }
+-
+- /* Return mps encoder instance */
+- *phMpsEnc = hMpsEnc;
+-
+-bail:
+- if (error != MPS_ENCODER_OK) {
+- FDK_MpegsEnc_Close(&hMpsEnc);
+- }
+- return error;
+-}
+-
+-MPS_ENCODER_ERROR FDK_MpegsEnc_Close(HANDLE_MPS_ENCODER *phMpsEnc) {
+- MPS_ENCODER_ERROR error = MPS_ENCODER_OK;
+-
+- if (phMpsEnc == NULL) {
+- error = MPS_ENCODER_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- if (*phMpsEnc != NULL) {
+- FDK_sacenc_close(&(*phMpsEnc)->hSacEncoder);
+- FDKfree(*phMpsEnc);
+- *phMpsEnc = NULL;
+- }
+-bail:
+- return error;
+-}
+-
+-MPS_ENCODER_ERROR FDK_MpegsEnc_Init(HANDLE_MPS_ENCODER hMpsEnc,
+- const AUDIO_OBJECT_TYPE audioObjectType,
+- const UINT samplingrate, const UINT bitrate,
+- const UINT sbrRatio, const UINT framelength,
+- const UINT inputBufferSizePerChannel,
+- const UINT coreCoderDelay) {
+- MPS_ENCODER_ERROR error = MPS_ENCODER_OK;
+- const UINT fs_low = 27713; /* low MPS sampling frequencies */
+- const UINT fs_high = 55426; /* high MPS sampling frequencies */
+- UINT nTimeSlots = 0, nQmfBandsLd = 0;
+-
+- if (hMpsEnc == NULL) {
+- error = MPS_ENCODER_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- /* Combine MPS with SBR only if the number of QMF band fits together.*/
+- switch (sbrRatio) {
+- case 1: /* downsampled sbr - 32 QMF bands required */
+- if (!(samplingrate < fs_low)) {
+- error = MPS_ENCODER_INIT_ERROR;
+- goto bail;
+- }
+- break;
+- case 2: /* dualrate - 64 QMF bands required */
+- if (!((samplingrate >= fs_low) && (samplingrate < fs_high))) {
+- error = MPS_ENCODER_INIT_ERROR;
+- goto bail;
+- }
+- break;
+- case 0:
+- default:; /* time interface - no samplingrate restriction */
+- }
+-
+- /* 32 QMF-Bands ( fs < 27713 )
+- * 64 QMF-Bands ( 27713 >= fs <= 55426 )
+- * 128 QMF-Bands ( fs > 55426 )
+- */
+- nQmfBandsLd =
+- (samplingrate < fs_low) ? 5 : ((samplingrate > fs_high) ? 7 : 6);
+- nTimeSlots = framelength >> nQmfBandsLd;
+-
+- /* check if number of qmf bands is usable for given framelength */
+- if (framelength != (nTimeSlots << nQmfBandsLd)) {
+- error = MPS_ENCODER_INIT_ERROR;
+- goto bail;
+- }
+-
+- /* is given bitrate intended to be supported */
+- if ((INT)bitrate != FDK_MpegsEnc_GetClosestBitRate(audioObjectType, MODE_212,
+- samplingrate, sbrRatio,
+- bitrate)) {
+- error = MPS_ENCODER_INIT_ERROR;
+- goto bail;
+- }
+-
+- /* init SAC library */
+- switch (audioObjectType) {
+- case AOT_ER_AAC_ELD: {
+- const UINT noInterFrameCoding = 0;
+-
+- if ((SACENC_OK !=
+- FDK_sacenc_setParam(hMpsEnc->hSacEncoder, SACENC_LOWDELAY,
+- (noInterFrameCoding == 1) ? 1 : 2)) ||
+- (SACENC_OK != FDK_sacenc_setParam(hMpsEnc->hSacEncoder,
+- SACENC_ENC_MODE, SACENC_212)) ||
+- (SACENC_OK != FDK_sacenc_setParam(hMpsEnc->hSacEncoder,
+- SACENC_SAMPLERATE, samplingrate)) ||
+- (SACENC_OK != FDK_sacenc_setParam(hMpsEnc->hSacEncoder,
+- SACENC_FRAME_TIME_SLOTS,
+- nTimeSlots)) ||
+- (SACENC_OK != FDK_sacenc_setParam(hMpsEnc->hSacEncoder,
+- SACENC_PARAM_BANDS,
+- SACENC_BANDS_15)) ||
+- (SACENC_OK !=
+- FDK_sacenc_setParam(hMpsEnc->hSacEncoder, SACENC_TIME_DOM_DMX, 2)) ||
+- (SACENC_OK !=
+- FDK_sacenc_setParam(hMpsEnc->hSacEncoder, SACENC_COARSE_QUANT, 0)) ||
+- (SACENC_OK != FDK_sacenc_setParam(hMpsEnc->hSacEncoder,
+- SACENC_QUANT_MODE,
+- SACENC_QUANTMODE_FINE)) ||
+- (SACENC_OK != FDK_sacenc_setParam(hMpsEnc->hSacEncoder,
+- SACENC_TIME_ALIGNMENT, 0)) ||
+- (SACENC_OK != FDK_sacenc_setParam(hMpsEnc->hSacEncoder,
+- SACENC_INDEPENDENCY_FACTOR, 20))) {
+- error = MPS_ENCODER_INIT_ERROR;
+- goto bail;
+- }
+- break;
+- }
+- default:
+- error = MPS_ENCODER_INIT_ERROR;
+- goto bail;
+- }
+-
+- if (SACENC_OK != FDK_sacenc_init(hMpsEnc->hSacEncoder, coreCoderDelay)) {
+- error = MPS_ENCODER_INIT_ERROR;
+- }
+-
+- hMpsEnc->audioObjectType = audioObjectType;
+-
+- hMpsEnc->inBufDesc.ppBase = (void **)&hMpsEnc->pInBuffer;
+- hMpsEnc->inBufDesc.pBufSize = hMpsEnc->pInBufferSize;
+- hMpsEnc->inBufDesc.pEleSize = hMpsEnc->pInBufferElSize;
+- hMpsEnc->inBufDesc.pBufType = hMpsEnc->pInBufferType;
+- hMpsEnc->inBufDesc.numBufs = 1;
+-
+- hMpsEnc->outBufDesc.ppBase = (void **)&hMpsEnc->pOutBuffer;
+- hMpsEnc->outBufDesc.pBufSize = hMpsEnc->pOutBufferSize;
+- hMpsEnc->outBufDesc.pEleSize = hMpsEnc->pOutBufferElSize;
+- hMpsEnc->outBufDesc.pBufType = hMpsEnc->pOutBufferType;
+- hMpsEnc->outBufDesc.numBufs = 2;
+-
+- hMpsEnc->pInBuffer[0] = NULL;
+- hMpsEnc->pInBufferSize[0] = 0;
+- hMpsEnc->pInBufferElSize[0] = sizeof(INT_PCM);
+- hMpsEnc->pInBufferType[0] = (FDK_BUF_TYPE_INPUT | FDK_BUF_TYPE_PCM_DATA);
+-
+- hMpsEnc->pOutBuffer[0] = NULL;
+- hMpsEnc->pOutBufferSize[0] = 0;
+- hMpsEnc->pOutBufferElSize[0] = sizeof(INT_PCM);
+- hMpsEnc->pOutBufferType[0] = (FDK_BUF_TYPE_OUTPUT | FDK_BUF_TYPE_PCM_DATA);
+-
+- hMpsEnc->pOutBuffer[1] = NULL;
+- hMpsEnc->pOutBufferSize[1] = 0;
+- hMpsEnc->pOutBufferElSize[1] = sizeof(UCHAR);
+- hMpsEnc->pOutBufferType[1] = (FDK_BUF_TYPE_OUTPUT | FDK_BUF_TYPE_BS_DATA);
+-
+- hMpsEnc->inargs.isInputInterleaved = 0;
+- hMpsEnc->inargs.inputBufferSizePerChannel = inputBufferSizePerChannel;
+-
+-bail:
+- return error;
+-}
+-
+-MPS_ENCODER_ERROR FDK_MpegsEnc_Process(HANDLE_MPS_ENCODER hMpsEnc,
+- INT_PCM *const pAudioSamples,
+- const INT nAudioSamples,
+- AACENC_EXT_PAYLOAD *pMpsExtPayload) {
+- MPS_ENCODER_ERROR error = MPS_ENCODER_OK;
+-
+- if (hMpsEnc == NULL) {
+- error = MPS_ENCODER_INVALID_HANDLE;
+- } else {
+- int sacHeaderFlag = 1;
+- int sacOutBufferOffset = 0;
+-
+- /* In case of eld the ssc is explicit and doesn't need to be inband */
+- if (hMpsEnc->audioObjectType == AOT_ER_AAC_ELD) {
+- sacHeaderFlag = 0;
+- }
+-
+- /* 4 bits nibble after extension type */
+- hMpsEnc->sacOutBuffer[0] = (sacHeaderFlag == 0) ? 0x3 : 0x7;
+- sacOutBufferOffset += 1;
+-
+- if (sacHeaderFlag) {
+- sacOutBufferOffset += FDK_MpegsEnc_WriteFrameHeader(
+- hMpsEnc, &hMpsEnc->sacOutBuffer[sacOutBufferOffset],
+- sizeof(hMpsEnc->sacOutBuffer) - sacOutBufferOffset);
+- }
+-
+- /* Register input and output buffer. */
+- hMpsEnc->pInBuffer[0] = (void *)pAudioSamples;
+- hMpsEnc->inargs.nInputSamples = nAudioSamples;
+-
+- hMpsEnc->pOutBuffer[0] = (void *)pAudioSamples;
+- hMpsEnc->pOutBufferSize[0] = sizeof(INT_PCM) * nAudioSamples / 2;
+-
+- hMpsEnc->pOutBuffer[1] = (void *)&hMpsEnc->sacOutBuffer[sacOutBufferOffset];
+- hMpsEnc->pOutBufferSize[1] =
+- sizeof(hMpsEnc->sacOutBuffer) - sacOutBufferOffset;
+-
+- /* encode SAC frame */
+- if (SACENC_OK != FDK_sacenc_encode(hMpsEnc->hSacEncoder,
+- &hMpsEnc->inBufDesc,
+- &hMpsEnc->outBufDesc, &hMpsEnc->inargs,
+- &hMpsEnc->outargs)) {
+- error = MPS_ENCODER_ENCODE_ERROR;
+- goto bail;
+- }
+-
+- /* export MPS payload */
+- pMpsExtPayload->pData = (UCHAR *)hMpsEnc->sacOutBuffer;
+- pMpsExtPayload->dataSize =
+- hMpsEnc->outargs.nOutputBits + 8 * (sacOutBufferOffset - 1);
+- pMpsExtPayload->dataType = EXT_LDSAC_DATA;
+- pMpsExtPayload->associatedChElement = -1;
+- }
+-
+-bail:
+- return error;
+-}
+-
+-INT FDK_MpegsEnc_WriteSpatialSpecificConfig(HANDLE_MPS_ENCODER hMpsEnc,
+- HANDLE_FDK_BITSTREAM hBs) {
+- INT sscBits = 0;
+-
+- if (NULL != hMpsEnc) {
+- MP4SPACEENC_INFO mp4SpaceEncoderInfo;
+- FDK_sacenc_getInfo(hMpsEnc->hSacEncoder, &mp4SpaceEncoderInfo);
+-
+- if (hBs != NULL) {
+- int i;
+- int writtenBits = 0;
+- for (i = 0; i<mp4SpaceEncoderInfo.pSscBuf->nSscSizeBits>> 3; i++) {
+- FDKwriteBits(hBs, mp4SpaceEncoderInfo.pSscBuf->pSsc[i], 8);
+- writtenBits += 8;
+- }
+- FDKwriteBits(hBs, mp4SpaceEncoderInfo.pSscBuf->pSsc[i],
+- mp4SpaceEncoderInfo.pSscBuf->nSscSizeBits - writtenBits);
+- } /* hBS */
+-
+- sscBits = mp4SpaceEncoderInfo.pSscBuf->nSscSizeBits;
+-
+- } /* valid hMpsEnc */
+-
+- return sscBits;
+-}
+-
+-static INT FDK_MpegsEnc_WriteFrameHeader(HANDLE_MPS_ENCODER hMpsEnc,
+- UCHAR *const pOutputBuffer,
+- const int outputBufferSize) {
+- const int sacTimeAlignFlag = 0;
+-
+- /* Initialize variables */
+- int numBits = 0;
+-
+- if ((NULL != hMpsEnc) && (NULL != pOutputBuffer)) {
+- UINT alignAnchor, cnt;
+- FDK_BITSTREAM Bs;
+- FDKinitBitStream(&Bs, pOutputBuffer, outputBufferSize, 0, BS_WRITER);
+-
+- /* Calculate SSC length information */
+- cnt = (FDK_MpegsEnc_WriteSpatialSpecificConfig(hMpsEnc, NULL) + 7) >> 3;
+-
+- /* Write SSC */
+- FDKwriteBits(&Bs, sacTimeAlignFlag, 1);
+-
+- if (cnt < 127) {
+- FDKwriteBits(&Bs, cnt, 7);
+- } else {
+- FDKwriteBits(&Bs, 127, 7);
+- FDKwriteBits(&Bs, cnt - 127, 16);
+- }
+-
+- alignAnchor = FDKgetValidBits(&Bs);
+- FDK_MpegsEnc_WriteSpatialSpecificConfig(hMpsEnc, &Bs);
+- FDKbyteAlign(&Bs, alignAnchor); /* bsFillBits */
+-
+- if (sacTimeAlignFlag) {
+- FDK_ASSERT(1); /* time alignment not supported */
+- }
+-
+- numBits = FDKgetValidBits(&Bs);
+- } /* valid handle */
+-
+- return ((numBits + 7) >> 3);
+-}
+-
+-INT FDK_MpegsEnc_GetClosestBitRate(const AUDIO_OBJECT_TYPE audioObjectType,
+- const CHANNEL_MODE channelMode,
+- const UINT samplingrate, const UINT sbrRatio,
+- const UINT bitrate) {
+- unsigned int i;
+- int targetBitrate = -1;
+-
+- for (i = 0; i < sizeof(mpsConfigTab) / sizeof(MPS_CONFIG_TAB); i++) {
+- if ((mpsConfigTab[i].audio_object_type == audioObjectType) &&
+- (mpsConfigTab[i].channel_mode == channelMode) &&
+- (mpsConfigTab[i].sbr_ratio == sbrRatio) &&
+- (mpsConfigTab[i].sampling_rate == samplingrate)) {
+- targetBitrate = fMin(fMax(bitrate, mpsConfigTab[i].bitrate_min),
+- mpsConfigTab[i].bitrate_max);
+- }
+- }
+-
+- return targetBitrate;
+-}
+-
+-INT FDK_MpegsEnc_GetDelay(HANDLE_MPS_ENCODER hMpsEnc) {
+- INT delay = 0;
+-
+- if (NULL != hMpsEnc) {
+- MP4SPACEENC_INFO mp4SpaceEncoderInfo;
+- FDK_sacenc_getInfo(hMpsEnc->hSacEncoder, &mp4SpaceEncoderInfo);
+- delay = mp4SpaceEncoderInfo.nCodecDelay;
+- }
+-
+- return delay;
+-}
+-
+-INT FDK_MpegsEnc_GetDecDelay(HANDLE_MPS_ENCODER hMpsEnc) {
+- INT delay = 0;
+-
+- if (NULL != hMpsEnc) {
+- MP4SPACEENC_INFO mp4SpaceEncoderInfo;
+- FDK_sacenc_getInfo(hMpsEnc->hSacEncoder, &mp4SpaceEncoderInfo);
+- delay = mp4SpaceEncoderInfo.nDecoderDelay;
+- }
+-
+- return delay;
+-}
+-
+-MPS_ENCODER_ERROR FDK_MpegsEnc_GetLibInfo(LIB_INFO *info) {
+- MPS_ENCODER_ERROR error = MPS_ENCODER_OK;
+-
+- if (NULL == info) {
+- error = MPS_ENCODER_INVALID_HANDLE;
+- } else if (SACENC_OK != FDK_sacenc_getLibInfo(info)) {
+- error = MPS_ENCODER_INIT_ERROR;
+- }
+-
+- return error;
+-}
+diff --git a/libAACenc/src/mps_main.h b/libAACenc/src/mps_main.h
+deleted file mode 100644
+index f56678a..0000000
+--- a/libAACenc/src/mps_main.h
++++ /dev/null
+@@ -1,270 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC encoder library ******************************
+-
+- Author(s): Markus Lohwasser
+-
+- Description: Mpeg Surround library interface functions
+-
+-*******************************************************************************/
+-
+-#ifndef MPS_MAIN_H
+-#define MPS_MAIN_H
+-
+-/* Includes ******************************************************************/
+-#include "aacenc.h"
+-#include "FDK_audio.h"
+-#include "machine_type.h"
+-
+-/* Defines *******************************************************************/
+-typedef enum {
+- MPS_ENCODER_OK = 0x0000, /*!< No error happened. All fine. */
+- MPS_ENCODER_INVALID_HANDLE =
+- 0x0020, /*!< Handle passed to function call was invalid. */
+- MPS_ENCODER_MEMORY_ERROR = 0x0021, /*!< Memory allocation failed. */
+- MPS_ENCODER_INIT_ERROR = 0x0040, /*!< General initialization error. */
+- MPS_ENCODER_ENCODE_ERROR =
+- 0x0060 /*!< The encoding process was interrupted by an unexpected error.
+- */
+-
+-} MPS_ENCODER_ERROR;
+-
+-/* Data Types ****************************************************************/
+-
+-/**
+- * MPEG Surround Encoder interface handle.
+- */
+-typedef struct MPS_ENCODER MPS_ENCODER, *HANDLE_MPS_ENCODER;
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/**
+- * \brief Open a Mpeg Surround Encoder instance.
+- *
+- * \phMpsEnc A pointer to a MPS handle to be allocated.
+- * Initialized on return.
+- *
+- * \return
+- * - MPS_ENCODER_OK, on succes.
+- * - MPS_ENCODER_INVALID_HANDLE, MPS_ENCODER_MEMORY_ERROR, on failure.
+- */
+-MPS_ENCODER_ERROR FDK_MpegsEnc_Open(HANDLE_MPS_ENCODER *phMpsEnc);
+-
+-/**
+- * \brief Close the Mpeg Surround Encoder instance.
+- *
+- * Deallocate instance and free whole memory.
+- *
+- * \param phMpsEnc Pointer to the MPS handle to be deallocated.
+- *
+- * \return
+- * - MPS_ENCODER_OK, on succes.
+- * - MPS_ENCODER_INVALID_HANDLE, on failure.
+- */
+-MPS_ENCODER_ERROR FDK_MpegsEnc_Close(HANDLE_MPS_ENCODER *phMpsEnc);
+-
+-/**
+- * \brief Initialize a Mpeg Surround Encoder instance.
+- *
+- * \param hMpsEnc MPS Encoder handle.
+- * \param audioObjectType Audio object type.
+- * \param samplingrate Sampling rate in Hz of audio input signal.
+- * \param bitrate Encder target bitrate.
+- * \param sbrRatio SBR sampling rate ratio.
+- * \param framelength Number of samples to be processes within one
+- * frame.
+- * \param inputBufferSizePerChannel Size of input buffer per channel.
+- * \param coreCoderDelay Core coder delay.
+- *
+- * \return
+- * - MPS_ENCODER_OK, on succes.
+- * - MPS_ENCODER_INVALID_HANDLE, MPS_ENCODER_ENCODE_ERROR, on failure.
+- */
+-MPS_ENCODER_ERROR FDK_MpegsEnc_Init(HANDLE_MPS_ENCODER hMpsEnc,
+- const AUDIO_OBJECT_TYPE audioObjectType,
+- const UINT samplingrate, const UINT bitrate,
+- const UINT sbrRatio, const UINT framelength,
+- const UINT inputBufferSizePerChannel,
+- const UINT coreCoderDelay);
+-
+-/**
+- * \brief Calculate Mpeg Surround processing.
+- *
+- * This fuction applies the MPS processing. The MPS side info will be written to
+- * extension payload. The input audio data will be overwritten by the calculated
+- * downmix.
+- *
+- * \param hMpsEnc MPS Encoder handle.
+- * \param pAudioSamples Pointer to audio input/output data.
+- * \param nAudioSamples Number of input audio samples to be prcessed.
+- * \param pMpsExtPayload Pointer to extension payload to be filled on
+- * return.
+- *
+- * \return
+- * - MPS_ENCODER_OK, on succes.
+- * - MPS_ENCODER_INVALID_HANDLE, MPS_ENCODER_ENCODE_ERROR, on failure.
+- */
+-MPS_ENCODER_ERROR FDK_MpegsEnc_Process(HANDLE_MPS_ENCODER hMpsEnc,
+- INT_PCM *const pAudioSamples,
+- const INT nAudioSamples,
+- AACENC_EXT_PAYLOAD *pMpsExtPayload);
+-
+-/**
+- * \brief Write Spatial Specific Config.
+- *
+- * This function can be called via call back from the transport library to write
+- * the Spatial Specific Config to given bitstream buffer.
+- *
+- * \param hMpsEnc MPS Encoder handle.
+- * \param hBs Bitstream buffer handle.
+- *
+- * \return Number of written bits.
+- */
+-INT FDK_MpegsEnc_WriteSpatialSpecificConfig(HANDLE_MPS_ENCODER hMpsEnc,
+- HANDLE_FDK_BITSTREAM hBs);
+-
+-/**
+- * \brief Get closest valid bitrate supported by given config.
+- *
+- * \param audioObjectType Audio object type.
+- * \param channelMode Encoder channel mode.
+- * \param samplingrate Sampling rate in Hz of audio input signal.
+- * \param sbrRatio SBR sampling rate ratio.
+- * \param bitrate The desired target bitrate.
+- *
+- * \return Closest valid bitrate to given bitrate..
+- */
+-INT FDK_MpegsEnc_GetClosestBitRate(const AUDIO_OBJECT_TYPE audioObjectType,
+- const CHANNEL_MODE channelMode,
+- const UINT samplingrate, const UINT sbrRatio,
+- const UINT bitrate);
+-
+-/**
+- * \brief Get codec delay.
+- *
+- * This function returns delay of the whole en-/decoded signal, including
+- * corecoder delay.
+- *
+- * \param hMpsEnc MPS Encoder handle.
+- *
+- * \return Codec delay in samples.
+- */
+-INT FDK_MpegsEnc_GetDelay(HANDLE_MPS_ENCODER hMpsEnc);
+-
+-/**
+- * \brief Get Mpeg Surround Decoder delay.
+- *
+- * This function returns delay of the Mpeg Surround decoder.
+- *
+- * \param hMpsEnc MPS Encoder handle.
+- *
+- * \return Mpeg Surround Decoder delay in samples.
+- */
+-INT FDK_MpegsEnc_GetDecDelay(HANDLE_MPS_ENCODER hMpsEnc);
+-
+-/**
+- * \brief Get information about encoder library build.
+- *
+- * Fill a given LIB_INFO structure with library version information.
+- *
+- * \param info Pointer to an allocated LIB_INFO struct.
+- *
+- * \return
+- * - MPS_ENCODER_OK, on succes.
+- * - MPS_ENCODER_INVALID_HANDLE, MPS_ENCODER_INIT_ERROR, on failure.
+- */
+-MPS_ENCODER_ERROR FDK_MpegsEnc_GetLibInfo(LIB_INFO *info);
+-
+-#endif /* MPS_MAIN_H */
+diff --git a/libSACdec/include/sac_dec_errorcodes.h b/libSACdec/include/sac_dec_errorcodes.h
+deleted file mode 100644
+index ee8b9f8..0000000
+--- a/libSACdec/include/sac_dec_errorcodes.h
++++ /dev/null
+@@ -1,157 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: error codes for mpeg surround decoder
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_DEC_ERRORCODES_H
+-#define SAC_DEC_ERRORCODES_H
+-
+-typedef enum {
+-
+- __mps_error_start = -1000,
+-
+- MPS_OK = 0,
+-
+- /* generic/init errors */
+- MPS_NOTOK = __mps_error_start,
+-
+- MPS_OUTOFMEMORY,
+- MPS_INVALID_HANDLE,
+- MPS_INVALID_PARAMETER, /* SetParam not successfull */
+- MPS_UNSUPPORTED_HRTFMODEL, /* SetHRTFModel() not successfull */
+- MPS_UNSUPPORTED_HRTFFREQ, /* SetHRTFModel() not successfull */
+-
+- MPS_UNSUPPORTED_UPMIX_TYPE, /* CheckLevelTreeUpmixType() */
+- MPS_UNSUPPORTED_FORMAT, /* various functions; unknown aot or no_channels in
+- filterbank */
+- MPS_OUTPUT_BUFFER_TOO_SMALL, /* Size of provided output time buffer is too
+- small */
+-
+- /* ssc errors */
+- MPS_INVALID_PARAMETERBANDS, /* unsupported numParameterBands in
+- SpatialDecDecodeHeader() */
+- MPS_INVALID_TREECONFIG,
+- MPS_INVALID_HRTFSET, /* SpatialDecDecodeHeader() */
+- MPS_INVALID_TTT, /* SpatialDecDecodeHeader() */
+- MPS_INVALID_BOXIDX, /* ecDataDec() */
+- MPS_INVALID_SETIDX, /* ecDataDec() */
+- MPS_INVALID_QUANTMODE, /* SpatialDecParseSpecificConfig() */
+- MPS_UNEQUAL_SSC, /* FDK_SpatialDecCompareSpatialSpecificConfigHeader() */
+- MPS_UNSUPPORTED_CONFIG, /* number of core channels; 3DStereoInversion; */
+-
+- /* parse errors */
+- MPS_PARSE_ERROR,
+- MPS_INVALID_TEMPSHAPE, /* SpatialDecParseFrameData() */
+-
+- /* render errors */
+- MPS_WRONG_PARAMETERSETS,
+- MPS_WRONG_PARAMETERBANDS, /* decodeAndMapFrameSmg() */
+- MPS_WRONG_TREECONFIG,
+- MPS_WRONG_BLINDCONFIG,
+- MPS_WRONG_OTT,
+- MPS_WRONG_QUANTMODE,
+- MPS_RESDEC_ERROR,
+- MPS_APPLY_M2_ERROR, /* error in applyM2x()selection */
+-
+- __mps_error_end
+-
+-} SACDEC_ERROR;
+-
+-#endif
+diff --git a/libSACdec/include/sac_dec_lib.h b/libSACdec/include/sac_dec_lib.h
+deleted file mode 100644
+index 9913279..0000000
+--- a/libSACdec/include/sac_dec_lib.h
++++ /dev/null
+@@ -1,477 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: Space Decoder
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_DEC_LIB_H
+-#define SAC_DEC_LIB_H
+-
+-#include "common_fix.h"
+-#include "FDK_audio.h"
+-#include "sac_dec_errorcodes.h"
+-#include "FDK_bitstream.h"
+-#include "FDK_qmf_domain.h"
+-
+-#ifdef __cplusplus
+-extern "C" {
+-#endif /* __cplusplus */
+-
+-/**
+- * \brief MPEG Surround input data interface mode.
+- **/
+-typedef enum {
+- SAC_INTERFACE_QMF =
+- 0, /*!< Use QMF domain interface for the input downmix audio. */
+- SAC_INTERFACE_TIME, /*!< Use time domain interface for the input downmix
+- audio. */
+- SAC_INTERFACE_AUTO /*!< */
+-} SAC_INPUT_CONFIG;
+-
+-/**
+- * \brief MPEG Surround output mode.
+- **/
+-typedef enum {
+- SACDEC_OUT_MODE_NORMAL =
+- 0, /*!< Normal multi channel processing without output restrictions. */
+- SACDEC_OUT_MODE_BINAURAL, /*!< Two channel output with binaural processsing.
+- */
+- SACDEC_OUT_MODE_STEREO, /*!< Always two channel output mode. */
+- SACDEC_OUT_MODE_6CHANNEL /*!< Always process with 5.1 channel output. */
+-} SAC_DEC_OUTPUT_MODE;
+-
+-/**
+- * \brief MPEG Surround binaural HRTF model.
+- * HRTF will be applied only in combination with upmixtype
+- *SAC_UPMIX_TYPE_BINAURAL.
+- **/
+-typedef enum {
+- SAC_BINAURAL_HRTF_KEMAR = 0,
+- SAC_BINAURAL_HRTF_VAST,
+- SAC_BINAURAL_HRTF_MPSVT,
+- SAC_BINAURAL_SINGLE_HRTFS
+-} SAC_BINAURAL_HRTF_MODEL;
+-
+-/**
+- * \brief MPEG Surround decoder instance available.
+- **/
+-typedef enum {
+- SAC_INSTANCE_NOT_FULL_AVAILABLE =
+- 0, /*!< MPEG Surround decoder instance not full available. */
+- SAC_INSTANCE_FULL_AVAILABLE /*!< MPEG Surround decoder instance full
+- available. */
+-} SAC_INSTANCE_AVAIL;
+-
+-/**
+- * \brief MPEG Surround decoder dynamic parameters.
+- *
+- * Use mpegSurroundDecoder_SetParam() function to configure internal status of
+- * following parameters.
+- */
+-typedef enum {
+- SACDEC_OUTPUT_MODE = 0x0001, /*!< Set MPEG Surround decoder output mode. See
+- SAC_DEC_OUTPUT_MODE. */
+- SACDEC_BLIND_ENABLE =
+- 0x0002, /*!< Multi channel output without MPEG Surround side info. */
+- SACDEC_PARTIALLY_COMPLEX =
+- 0x0003, /*!< Set partially complex flag for MPEG Surround.
+- 0: Use complex valued QMF data.
+- 1: Use real valued QMF data (low power mode) */
+- SACDEC_INTERFACE =
+- 0x0004, /*!< Select signal input interface for MPEG Surround.
+- Switch time interface off: 0
+- Switch time interface on: 1 */
+- SACDEC_BS_DELAY = 0x0005, /*!< Select bit stream delay for MPEG Surround.
+- Switch bit stream delay off: 0
+- Switch bit stream delay on: 1 */
+- SACDEC_BINAURAL_QUALITY =
+- 0x0102, /*!< Set binaural quality for MPEG Surround binaural mode.
+- 0: Low Complexity,
+- 1: High Quality */
+- SACDEC_BINAURAL_DISTANCE = 0x0103, /*!< Set perceived distance for binaural
+- playback (binaural mode only). The valid
+- values range from 0 to 100. Where 100
+- corresponds to the farthest perceived
+- distance. */
+- SACDEC_BINAURAL_DIALOG_CLARITY =
+- 0x0104, /*!< Set dialog clarity (for binaural playback).
+- The valid values range from 0 to 100. */
+- SACDEC_BINAURAL_FRONT_ANGLE = 0x0105, /*!< Set angle between the virtual front
+- speaker pair (binaural mode only).
+- The valid range is from 0 to 180
+- angular degrees. */
+- SACDEC_BINAURAL_BACK_ANGLE = 0x0106, /*!< Set angle between the virtual back
+- speaker pair (binaural mode only). The
+- valid range is from 0 to 180 angular
+- degrees. */
+- SACDEC_BINAURAL_PRESET = 0x0107, /*!< Set a virtual speaker setup preset for
+- binaural playback (binaural mode only).
+- This meta-parameter implicitly modifies
+- the following parameters:
+- SACDEC_BINAURAL_DISTANCE,
+- SACDEC_BINAURAL_DIALOG_CLARITY,
+- SACDEC_BINAURAL_FRONT_ANGLE and
+- SACDEC_BINAURAL_BACK_ANGLE.
+- The following presets are available:
+- 1: Dry room
+- 2: Living room (default)
+- 3: Cinema */
+-
+- SACDEC_BS_INTERRUPTION =
+- 0x0200, /*!< If the given value is unequal to 0 hint the MPEG Surround
+- decoder that the next input data is discontinuous, because of
+- frame loss, seeking, etc. Announce the decoder that the
+- bitstream data was interrupted (fSync = 0). This will cause the
+- surround decoder not to parse any new bitstream data until a
+- new header with a valid Spatial Specific Config and a
+- independently decodable frame is found. Specially important
+- when the MPEG Surround data is split accross several frames
+- (for example in the case of AAC-LC downmix with 1024
+- framelength and 2048 surround frame length) and a discontinuity
+- in the bitstream data occurs. If fSync is 1, assume that MPEG
+- Surround data is in sync (out of band config for example). */
+- SACDEC_CLEAR_HISTORY = 0x0201, /*!< If the given value is unequal to 0 clear
+- all internal states (delay lines, QMF
+- states, ...) of the MPEG Surround decoder.
+- This will cause a discontinuity in the audio
+- output signal. */
+-
+- SACDEC_CONCEAL_NUM_KEEP_FRAMES =
+- 0x0301, /*!< Error concealment: The Number of frames the module keeps the
+- last spatial image before fading to the particular spatial
+- scenario starts. The default is 10 frames. */
+- SACDEC_CONCEAL_FADE_OUT_SLOPE_LENGTH =
+- 0x0302, /*!< Error concealment: Length of the slope (in frames) the module
+- creates to fade from the last spatial scenario to the
+- particular default scenario (downmix) in case of consecutive
+- errors. Default is 5. */
+- SACDEC_CONCEAL_FADE_IN_SLOPE_LENGTH =
+- 0x0303, /*!< Error concealment: Length of the slope (in frames) the module
+- creates to fade from the default spatial scenario (downmix) to
+- the current scenario after fade-out. Default parameter value
+- is 5. */
+- SACDEC_CONCEAL_NUM_RELEASE_FRAMES =
+- 0x0304 /*!< Error concealment: The number of error free frames before the
+- module starts fading from default to the current spatial
+- scenario. Default parameter value is 3 frames. */
+-} SACDEC_PARAM;
+-
+-#define PCM_MPS INT_PCM
+-
+-/**
+- * \brief MPEG Surround decoder handle.
+- */
+-typedef struct MpegSurroundDecoder CMpegSurroundDecoder;
+-
+-/**
+- * \brief Check if the full MPEG Surround decoder instance is allocated.
+- *
+- * Check if the full MPEG Surround decoder instance is allocated.
+- *
+- * \param pMpegSurroundDecoder A pointer to a decoder stucture.
+- *
+- * \return SACDEC_ERROR error code
+- */
+-SAC_INSTANCE_AVAIL
+-mpegSurroundDecoder_IsFullMpegSurroundDecoderInstanceAvailable(
+- CMpegSurroundDecoder *pMpegSurroundDecoder);
+-
+-/**
+- * \brief Open one instance of the MPEG Surround decoder.
+- *
+- * Allocate one instance of decoder and input buffers.
+- * - Allocate decoder structure
+- * - Allocate input buffers (QMF/time/MPS data)
+- *
+- * \param pMpegSurroundDecoder A pointer to a decoder handle; filled on
+- * return.
+- * \param splitMemoryAllocation Allocate only outer layer of MPS decoder. Core
+- * part is reallocated later if needed.
+- * \param stereoConfigIndex USAC: Save memory by opening the MPS decoder
+- * for a specific stereoConfigIndex. (Needs optimization macros enabled.)
+- * \param pQmfDomain Pointer to QMF domain data structure.
+- *
+- * \return SACDEC_ERROR error code
+- */
+-SACDEC_ERROR mpegSurroundDecoder_Open(
+- CMpegSurroundDecoder **pMpegSurroundDecoder, int stereoConfigIndex,
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain);
+-
+-/**
+- * \brief Init one instance of the MPEG Surround decoder.
+- *
+- * Init one instance of the MPEG Surround decoder
+- *
+- * \param pMpegSurroundDecoder A pointer to a decoder handle;
+- *
+- * \return SACDEC_ERROR error code
+- */
+-SACDEC_ERROR mpegSurroundDecoder_Init(
+- CMpegSurroundDecoder *pMpegSurroundDecoder);
+-
+-/**
+- * \brief Read and parse SpatialSpecificConfig.
+- *
+- * \param pMpegSurroundDecoder A pointer to a decoder handle.
+- * \param hBs bitstream handle config parsing data source.
+- *
+- * \return SACDEC_ERROR error code
+- */
+-SACDEC_ERROR mpegSurroundDecoder_Config(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, HANDLE_FDK_BITSTREAM hBs,
+- AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT frameSize,
+- INT stereoConfigIndex, INT coreSbrFrameLengthIndex, INT configBytes,
+- const UCHAR configMode, UCHAR *configChanged);
+-
+-SACDEC_ERROR
+-mpegSurroundDecoder_ConfigureQmfDomain(
+- CMpegSurroundDecoder *pMpegSurroundDecoder,
+- SAC_INPUT_CONFIG sac_dec_interface, UINT coreSamplingRate,
+- AUDIO_OBJECT_TYPE coreCodec);
+-
+-/**
+- * \brief Parse MPEG Surround data without header
+- *
+- * \param pMpegSurroundDecoder A MPEG Surrround decoder handle.
+- * \param hBs Bit stream handle data input source
+- * \param pMpsDataBits Pointer to number of valid bits in extension
+- * payload. Function updates mpsDataBits while parsing bitstream.
+- * \param fGlobalIndependencyFlag Global independency flag of current frame.
+- *
+- * \return Error code.
+- */
+-int mpegSurroundDecoder_ParseNoHeader(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, HANDLE_FDK_BITSTREAM hBs,
+- int *pMpsDataBits, int fGlobalIndependencyFlag);
+-
+-/* #ifdef SACDEC_MPS_ENABLE */
+-/**
+- * \brief Parse MPEG Surround data with header. Header is ancType, ancStart,
+- ancStop (4 bits total). Body is ancDataSegmentByte[i].
+- *
+- * \param pMpegSurroundDecoder A MPEG Surrround decoder handle.
+- * \param hBs Bit stream handle data input source
+- * \param pMpsDataBits Pointer to number of valid bits in extension
+- payload. Function updates mpsDataBits while parsing bitstream. Needs to be a
+- multiple of 8 + 4 (4 bits header).
+- * \param coreCodec The audio object type of the core codec handling
+- the downmix input signal.
+- * \param sampleRate Samplerate of input downmix data.
+- * \param nChannels Amount of input channels.
+- * \param frameSize Amount of input samples.
+- * \param fGlobalIndependencyFlag Global independency flag of current frame.
+- *
+- * \return Error code.
+- */
+-int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder,
+- HANDLE_FDK_BITSTREAM hBs, int *pMpsDataBits,
+- AUDIO_OBJECT_TYPE coreCodec, int sampleRate,
+- int frameSize, int fGlobalIndependencyFlag);
+-/* #endif */
+-
+-/**
+- * \brief Apply MPEG Surround upmix.
+- *
+- * Process one downmix audio frame and decode one surround frame if it applies.
+- * Downmix framing can be different from surround framing, so depending on the
+- * frame size of the downmix audio data and the framing being used by the MPEG
+- * Surround decoder, it could be that only every second call, for example, of
+- * this function actually surround data was decoded. The returned value of
+- * frameSize will be zero, if no surround data was decoded.
+- *
+- * Decoding one MPEG Surround frame. Depending on interface configuration
+- * mpegSurroundDecoder_SetParam(self, SACDEC_INTERFACE, value), the QMF or time
+- * interface will be applied. External access to QMF buffer interface can be
+- * achieved by mpegSurroundDecoder_GetQmfBuffer() call before decode frame.
+- * While using time interface, pTimeData buffer will be shared as input and
+- * output buffer.
+- *
+- * \param pMpegSurroundDecoder A MPEG Surrround decoder handle.
+- * \param pTimeData Pointer to time buffer. Depending on interface
+- * configuration, the content of pTimeData is ignored, and the internal QMF
+- * buffer will be used as input data source.
+- * Otherwise, the MPEG Surround processing is applied to the timesignal
+- * pTimeData. For both variants, the resulting MPEG
+- * Surround signal is written into pTimeData.
+- * \param timeDataSize Size of pTimeData (available buffer size).
+- * \param timeDataFrameSize Frame size of input timedata
+- * \param nChannels Pointer where the amount of input channels is
+- * given and amount of output channels is returned.
+- * \param frameSize Pointer where the amount of output samples is
+- * returned into.
+- * \param channelType Array were the corresponding channel type for
+- * each output audio channel is stored into.
+- * \param channelIndices Array were the corresponding channel type index
+- * for each output audio channel is stored into.
+- * \param mapDescr Channep map descriptor for output channel mapping
+- * to be used (From MPEG PCE ordering to whatever is required).
+- *
+- * \return Error code.
+- */
+-int mpegSurroundDecoder_Apply(CMpegSurroundDecoder *pMpegSurroundDecoder,
+- INT_PCM *input, PCM_MPS *pTimeData,
+- const int timeDataSize, int timeDataFrameSize,
+- int *nChannels, int *frameSize, int sampleRate,
+- AUDIO_OBJECT_TYPE coreCodec,
+- AUDIO_CHANNEL_TYPE channelType[],
+- UCHAR channelIndices[],
+- const FDK_channelMapDescr *const mapDescr);
+-
+-/**
+- * \brief Deallocate a MPEG Surround decoder instance.
+- * \param pMpegSurroundDecoder A decoder handle.
+- * \return No return value.
+- */
+-void mpegSurroundDecoder_Close(CMpegSurroundDecoder *pMpegSurroundDecoder);
+-
+-/**
+- * \brief Free config dependent MPEG Surround memory.
+- * \param pMpegSurroundDecoder A decoder handle.
+- * \return error.
+- */
+-SACDEC_ERROR mpegSurroundDecoder_FreeMem(
+- CMpegSurroundDecoder *pMpegSurroundDecoder);
+-
+-/**
+- * \brief Set one single MPEG Surround decoder parameter.
+- *
+- * \param pMpegSurroundDecoder A MPEG Surrround decoder handle. Must not be
+- * NULL pointer.
+- * \param param Parameter to be set. See SACDEC_PARAM.
+- * \param value Parameter value. See SACDEC_PARAM.
+- *
+- * \return 0 on sucess, and non-zero on failure.
+- */
+-SACDEC_ERROR mpegSurroundDecoder_SetParam(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, const SACDEC_PARAM param,
+- const INT value);
+-
+-/**
+- * \brief Retrieve MPEG Surround decoder library info and fill info list with all depending library infos.
+- * \param libInfo Pointer to library info list to be filled.
+- * \return 0 on sucess, and non-zero on failure.
+- **/
+-int mpegSurroundDecoder_GetLibInfo(LIB_INFO *libInfo);
+-
+-/**
+- * \brief Set one single MPEG Surround decoder parameter.
+- *
+- * \param pMpegSurroundDecoder A valid MPEG Surrround decoder handle.
+- *
+- * \return The additional signal delay caused by the module.
+- */
+-UINT mpegSurroundDecoder_GetDelay(const CMpegSurroundDecoder *self);
+-
+-/**
+- * \brief Get info on whether the USAC pseudo LR feature is active.
+- *
+- * \param pMpegSurroundDecoder A valid MPEG Surrround decoder handle.
+- * \param bsPseudoLr Pointer to return wether pseudo LR USAC feature
+- * is used.
+- *
+- * \return 0 on sucess, and non-zero on failure.
+- */
+-SACDEC_ERROR mpegSurroundDecoder_IsPseudoLR(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, int *bsPseudoLr);
+-
+-#ifdef __cplusplus
+-}
+-#endif /* __cplusplus */
+-
+-#endif /* #ifndef SAC_DEC_LIB_H */
+diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp
+deleted file mode 100644
+index 883e1e8..0000000
+--- a/libSACdec/src/sac_bitdec.cpp
++++ /dev/null
+@@ -1,2167 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec bitstream decoder
+-
+-*******************************************************************************/
+-
+-#include "sac_bitdec.h"
+-
+-#include "sac_dec_errorcodes.h"
+-#include "nlc_dec.h"
+-#include "sac_rom.h"
+-#include "FDK_matrixCalloc.h"
+-#include "sac_tsd.h"
+-
+-enum {
+- ottVsTotInactiv = 0,
+- ottVsTotDb1Activ = 1,
+- ottVsTotDb2Activ = 2,
+- ottVsTotDb1Db2Activ = 3
+-};
+-
+-static SACDEC_ERROR SpatialDecDecodeHelperInfo(
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig, UPMIXTYPE upmixType) {
+- int i;
+- UINT syntaxFlags;
+-
+- /* Determine bit stream syntax */
+- syntaxFlags = 0;
+- switch (pSpatialSpecificConfig->coreCodec) {
+- case AOT_ER_AAC_ELD:
+- case AOT_ER_AAC_LD:
+- syntaxFlags |= SACDEC_SYNTAX_LD;
+- break;
+- case AOT_USAC:
+- syntaxFlags |= SACDEC_SYNTAX_USAC;
+- break;
+- case AOT_NONE:
+- default:
+- return MPS_UNSUPPORTED_FORMAT;
+- }
+-
+- pSpatialSpecificConfig->syntaxFlags = syntaxFlags;
+-
+- switch (pSpatialSpecificConfig->treeConfig) {
+- case TREE_212: {
+- pSpatialSpecificConfig->ottCLDdefault[0] = 0;
+- } break;
+- default:
+- return MPS_INVALID_TREECONFIG;
+- }
+-
+- if (syntaxFlags & SACDEC_SYNTAX_USAC) {
+- if (pSpatialSpecificConfig->bsOttBandsPhasePresent) {
+- pSpatialSpecificConfig->numOttBandsIPD =
+- pSpatialSpecificConfig->bsOttBandsPhase;
+- } else {
+- int numParameterBands;
+-
+- numParameterBands = pSpatialSpecificConfig->freqRes;
+- switch (numParameterBands) {
+- case 4:
+- case 5:
+- pSpatialSpecificConfig->numOttBandsIPD = 2;
+- break;
+- case 7:
+- pSpatialSpecificConfig->numOttBandsIPD = 3;
+- break;
+- case 10:
+- pSpatialSpecificConfig->numOttBandsIPD = 5;
+- break;
+- case 14:
+- pSpatialSpecificConfig->numOttBandsIPD = 7;
+- break;
+- case 20:
+- case 28:
+- pSpatialSpecificConfig->numOttBandsIPD = 10;
+- break;
+- default:
+- return MPS_INVALID_PARAMETERBANDS;
+- }
+- }
+- } else {
+- pSpatialSpecificConfig->numOttBandsIPD = 0;
+- }
+- for (i = 0; i < pSpatialSpecificConfig->nOttBoxes; i++) {
+- {
+- pSpatialSpecificConfig->bitstreamOttBands[i] =
+- pSpatialSpecificConfig->freqRes;
+- }
+- {
+- pSpatialSpecificConfig->numOttBands[i] =
+- pSpatialSpecificConfig->bitstreamOttBands[i];
+- if (syntaxFlags & SACDEC_SYNTAX_USAC &&
+- !pSpatialSpecificConfig->bsOttBandsPhasePresent) {
+- if (pSpatialSpecificConfig->bResidualCoding &&
+- pSpatialSpecificConfig->ResidualConfig[i].bResidualPresent &&
+- (pSpatialSpecificConfig->numOttBandsIPD <
+- pSpatialSpecificConfig->ResidualConfig[i].nResidualBands)) {
+- pSpatialSpecificConfig->numOttBandsIPD =
+- pSpatialSpecificConfig->ResidualConfig[i].nResidualBands;
+- }
+- }
+- }
+- } /* i */
+-
+- return MPS_OK;
+-}
+-
+-/*******************************************************************************
+- Functionname: SpatialDecParseExtensionConfig
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-
+-static SACDEC_ERROR SpatialDecParseExtensionConfig(
+- HANDLE_FDK_BITSTREAM bitstream, SPATIAL_SPECIFIC_CONFIG *config,
+- int numOttBoxes, int numTttBoxes, int numOutChan, int bitsAvailable) {
+- SACDEC_ERROR err = MPS_OK;
+- INT ba = bitsAvailable;
+-
+- config->sacExtCnt = 0;
+- config->bResidualCoding = 0;
+-
+- ba = fMin((int)FDKgetValidBits(bitstream), ba);
+-
+- while ((ba >= 8) && (config->sacExtCnt < MAX_NUM_EXT_TYPES)) {
+- int bitsRead, nFillBits;
+- INT tmp;
+- UINT sacExtLen;
+-
+- config->sacExtType[config->sacExtCnt] = FDKreadBits(bitstream, 4);
+- ba -= 4;
+-
+- sacExtLen = FDKreadBits(bitstream, 4);
+- ba -= 4;
+-
+- if (sacExtLen == 15) {
+- sacExtLen += FDKreadBits(bitstream, 8);
+- ba -= 8;
+- if (sacExtLen == 15 + 255) {
+- sacExtLen += FDKreadBits(bitstream, 16);
+- ba -= 16;
+- }
+- }
+-
+- tmp = (INT)FDKgetValidBits(
+- bitstream); /* Extension config payload start anchor. */
+- if ((tmp <= 0) || (tmp < (INT)sacExtLen * 8) || (ba < (INT)sacExtLen * 8)) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+-
+- switch (config->sacExtType[config->sacExtCnt]) {
+- default:; /* unknown extension data => do nothing */
+- }
+-
+- /* skip remaining extension data */
+- bitsRead = tmp - FDKgetValidBits(bitstream);
+- nFillBits = 8 * sacExtLen - bitsRead;
+-
+- if (nFillBits < 0) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- } else {
+- /* Skip fill bits or an unkown extension. */
+- FDKpushFor(bitstream, nFillBits);
+- }
+-
+- ba -= 8 * sacExtLen;
+- config->sacExtCnt++;
+- }
+-
+-bail:
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecParseSpecificConfigHeader(
+- HANDLE_FDK_BITSTREAM bitstream,
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig,
+- AUDIO_OBJECT_TYPE coreCodec, SPATIAL_DEC_UPMIX_TYPE upmixType) {
+- SACDEC_ERROR err = MPS_OK;
+- INT numFillBits;
+- int sacHeaderLen = 0;
+- int sacTimeAlignFlag = 0;
+-
+- sacTimeAlignFlag = FDKreadBits(bitstream, 1);
+- sacHeaderLen = FDKreadBits(bitstream, 7);
+-
+- if (sacHeaderLen == 127) {
+- sacHeaderLen += FDKreadBits(bitstream, 16);
+- }
+- numFillBits = (INT)FDKgetValidBits(bitstream);
+-
+- err = SpatialDecParseSpecificConfig(bitstream, pSpatialSpecificConfig,
+- sacHeaderLen, coreCodec);
+-
+- numFillBits -=
+- (INT)FDKgetValidBits(bitstream); /* the number of read bits (tmpBits) */
+- numFillBits = (8 * sacHeaderLen) - numFillBits;
+- if (numFillBits < 0) {
+- /* Parsing went wrong */
+- err = MPS_PARSE_ERROR;
+- }
+- /* Move to the very end of the SSC */
+- FDKpushBiDirectional(bitstream, numFillBits);
+-
+- if ((err == MPS_OK) && sacTimeAlignFlag) {
+- /* not supported */
+- FDKreadBits(bitstream, 16);
+- err = MPS_UNSUPPORTED_CONFIG;
+- }
+-
+- /* Derive additional helper variables */
+- SpatialDecDecodeHelperInfo(pSpatialSpecificConfig, (UPMIXTYPE)upmixType);
+-
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecParseMps212Config(
+- HANDLE_FDK_BITSTREAM bitstream,
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig, int samplingRate,
+- AUDIO_OBJECT_TYPE coreCodec, INT stereoConfigIndex,
+- INT coreSbrFrameLengthIndex) {
+- int i;
+-
+- FDKmemclear(pSpatialSpecificConfig, sizeof(SPATIAL_SPECIFIC_CONFIG));
+-
+- pSpatialSpecificConfig->stereoConfigIndex = stereoConfigIndex;
+- pSpatialSpecificConfig->coreSbrFrameLengthIndex = coreSbrFrameLengthIndex;
+- pSpatialSpecificConfig->freqRes =
+- (SPATIALDEC_FREQ_RES)freqResTable[FDKreadBits(bitstream, 3)];
+- if (pSpatialSpecificConfig->freqRes == 0) {
+- return MPS_PARSE_ERROR; /* reserved value */
+- }
+-
+- switch (coreCodec) {
+- case AOT_DRM_USAC:
+- pSpatialSpecificConfig->bsFixedGainDMX =
+- (SPATIALDEC_FIXED_GAINS)FDKreadBits(bitstream, 3);
+- /* tempShapeConfig = (bsTempShapeConfigDrm == 1) ? 3 : 0 */
+- pSpatialSpecificConfig->tempShapeConfig =
+- (SPATIALDEC_TS_CONF)(FDKreadBits(bitstream, 1) * 3);
+- pSpatialSpecificConfig->decorrConfig = (SPATIALDEC_DECORR_CONF)0;
+- pSpatialSpecificConfig->bsDecorrType = 0;
+- break;
+- case AOT_USAC:
+- pSpatialSpecificConfig->bsFixedGainDMX =
+- (SPATIALDEC_FIXED_GAINS)FDKreadBits(bitstream, 3);
+- pSpatialSpecificConfig->tempShapeConfig =
+- (SPATIALDEC_TS_CONF)FDKreadBits(bitstream, 2);
+- pSpatialSpecificConfig->decorrConfig =
+- (SPATIALDEC_DECORR_CONF)FDKreadBits(bitstream, 2);
+- if (pSpatialSpecificConfig->decorrConfig > 2) {
+- return MPS_PARSE_ERROR; /* reserved value */
+- }
+- pSpatialSpecificConfig->bsDecorrType = 0;
+- break;
+- default:
+- return MPS_UNSUPPORTED_FORMAT;
+- }
+- pSpatialSpecificConfig->nTimeSlots = (coreSbrFrameLengthIndex == 4) ? 64 : 32;
+- pSpatialSpecificConfig->bsHighRateMode = (UCHAR)FDKreadBits(bitstream, 1);
+-
+- {
+- pSpatialSpecificConfig->bsPhaseCoding = (UCHAR)FDKreadBits(bitstream, 1);
+- pSpatialSpecificConfig->bsOttBandsPhasePresent =
+- (UCHAR)FDKreadBits(bitstream, 1);
+- if (pSpatialSpecificConfig->bsOttBandsPhasePresent) {
+- if (MAX_PARAMETER_BANDS < (pSpatialSpecificConfig->bsOttBandsPhase =
+- FDKreadBits(bitstream, 5))) {
+- return MPS_PARSE_ERROR;
+- }
+- } else {
+- pSpatialSpecificConfig->bsOttBandsPhase = 0;
+- }
+- }
+-
+- if (stereoConfigIndex > 1) { /* do residual coding */
+- pSpatialSpecificConfig->bResidualCoding = 1;
+- pSpatialSpecificConfig->ResidualConfig->bResidualPresent = 1;
+- if (pSpatialSpecificConfig->freqRes <
+- (pSpatialSpecificConfig->ResidualConfig->nResidualBands =
+- FDKreadBits(bitstream, 5))) {
+- return MPS_PARSE_ERROR;
+- }
+- pSpatialSpecificConfig->bsOttBandsPhase =
+- fMax(pSpatialSpecificConfig->bsOttBandsPhase,
+- pSpatialSpecificConfig->ResidualConfig->nResidualBands);
+- pSpatialSpecificConfig->bsPseudoLr = (UCHAR)FDKreadBits(bitstream, 1);
+-
+- if (pSpatialSpecificConfig->bsPhaseCoding) {
+- pSpatialSpecificConfig->bsPhaseCoding = 3;
+- }
+- } else {
+- pSpatialSpecificConfig->bResidualCoding = 0;
+- pSpatialSpecificConfig->ResidualConfig->bResidualPresent = 0;
+- }
+-
+- if (pSpatialSpecificConfig->tempShapeConfig == 2) {
+- switch (coreCodec) {
+- case AOT_USAC:
+- pSpatialSpecificConfig->envQuantMode = FDKreadBits(bitstream, 1);
+- break;
+- default: /* added to avoid compiler warning */
+- break; /* added to avoid compiler warning */
+- }
+- }
+-
+- /* Static parameters */
+-
+- pSpatialSpecificConfig->samplingFreq =
+- samplingRate; /* wrong for stereoConfigIndex == 3 but value is unused */
+- pSpatialSpecificConfig->treeConfig = SPATIALDEC_MODE_RSVD7;
+- pSpatialSpecificConfig->nOttBoxes =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numOttBoxes;
+- pSpatialSpecificConfig->nInputChannels =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numInputChannels;
+- pSpatialSpecificConfig->nOutputChannels =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numOutputChannels;
+-
+- pSpatialSpecificConfig->bArbitraryDownmix = 0;
+-
+- for (i = 0; i < pSpatialSpecificConfig->nOttBoxes; i++) {
+- pSpatialSpecificConfig->OttConfig[i].nOttBands = 0;
+- }
+-
+- if (coreCodec == AOT_DRM_USAC) {
+- /* MPS payload is MPEG conform -> no need for pseudo DRM AOT */
+- coreCodec = AOT_USAC;
+- }
+- pSpatialSpecificConfig->coreCodec = coreCodec;
+-
+- /* Derive additional helper variables */
+- SpatialDecDecodeHelperInfo(pSpatialSpecificConfig, UPMIXTYPE_NORMAL);
+-
+- return MPS_OK;
+-}
+-
+-SACDEC_ERROR SpatialDecParseSpecificConfig(
+- HANDLE_FDK_BITSTREAM bitstream,
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig, int sacHeaderLen,
+- AUDIO_OBJECT_TYPE coreCodec) {
+- SACDEC_ERROR err = MPS_OK;
+- int i;
+- int bsSamplingFreqIndex;
+- int bsFreqRes, b3DaudioMode = 0;
+- int numHeaderBits;
+- int cfgStartPos, bitsAvailable;
+-
+- FDKmemclear(pSpatialSpecificConfig, sizeof(SPATIAL_SPECIFIC_CONFIG));
+-
+- cfgStartPos = FDKgetValidBits(bitstream);
+- /* It might be that we do not know the SSC length beforehand. */
+- if (sacHeaderLen == 0) {
+- bitsAvailable = cfgStartPos;
+- } else {
+- bitsAvailable = 8 * sacHeaderLen;
+- if (bitsAvailable > cfgStartPos) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+- }
+-
+- bsSamplingFreqIndex = FDKreadBits(bitstream, 4);
+-
+- if (bsSamplingFreqIndex == 15) {
+- pSpatialSpecificConfig->samplingFreq = FDKreadBits(bitstream, 24);
+- } else {
+- pSpatialSpecificConfig->samplingFreq =
+- samplingFreqTable[bsSamplingFreqIndex];
+- if (pSpatialSpecificConfig->samplingFreq == 0) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+- }
+-
+- pSpatialSpecificConfig->nTimeSlots = FDKreadBits(bitstream, 5) + 1;
+- if ((pSpatialSpecificConfig->nTimeSlots < 1) ||
+- (pSpatialSpecificConfig->nTimeSlots > MAX_TIME_SLOTS)) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+-
+- bsFreqRes = FDKreadBits(bitstream, 3);
+-
+- pSpatialSpecificConfig->freqRes =
+- (SPATIALDEC_FREQ_RES)freqResTable_LD[bsFreqRes];
+-
+- pSpatialSpecificConfig->treeConfig =
+- (SPATIALDEC_TREE_CONFIG)FDKreadBits(bitstream, 4);
+-
+- if (pSpatialSpecificConfig->treeConfig != SPATIALDEC_MODE_RSVD7) {
+- err = MPS_UNSUPPORTED_CONFIG;
+- goto bail;
+- }
+-
+- {
+- pSpatialSpecificConfig->nOttBoxes =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numOttBoxes;
+- pSpatialSpecificConfig->nTttBoxes =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numTttBoxes;
+- pSpatialSpecificConfig->nInputChannels =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numInputChannels;
+- pSpatialSpecificConfig->nOutputChannels =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numOutputChannels;
+- }
+-
+- pSpatialSpecificConfig->quantMode =
+- (SPATIALDEC_QUANT_MODE)FDKreadBits(bitstream, 2);
+-
+- pSpatialSpecificConfig->bArbitraryDownmix = FDKreadBits(bitstream, 1);
+-
+- pSpatialSpecificConfig->bsFixedGainDMX =
+- (SPATIALDEC_FIXED_GAINS)FDKreadBits(bitstream, 3);
+-
+- pSpatialSpecificConfig->tempShapeConfig =
+- (SPATIALDEC_TS_CONF)FDKreadBits(bitstream, 2);
+- if (pSpatialSpecificConfig->tempShapeConfig > 2) {
+- return MPS_PARSE_ERROR; /* reserved value */
+- }
+-
+- pSpatialSpecificConfig->decorrConfig =
+- (SPATIALDEC_DECORR_CONF)FDKreadBits(bitstream, 2);
+- if (pSpatialSpecificConfig->decorrConfig > 2) {
+- return MPS_PARSE_ERROR; /* reserved value */
+- }
+-
+- for (i = 0; i < pSpatialSpecificConfig->nOttBoxes; i++) {
+- pSpatialSpecificConfig->OttConfig[i].nOttBands = 0;
+- }
+-
+- for (i = 0; i < pSpatialSpecificConfig->nTttBoxes; i++) {
+- int bTttDualMode = FDKreadBits(bitstream, 1);
+- FDKreadBits(bitstream, 3); /* not supported */
+-
+- if (bTttDualMode) {
+- FDKreadBits(bitstream, 8); /* not supported */
+- }
+- }
+-
+- if (pSpatialSpecificConfig->tempShapeConfig == 2) {
+- pSpatialSpecificConfig->envQuantMode = FDKreadBits(bitstream, 1);
+- }
+-
+- if (b3DaudioMode) {
+- if (FDKreadBits(bitstream, 2) == 0) { /* b3DaudioHRTFset ? */
+- int hc;
+- int HRTFnumBand;
+- int HRTFfreqRes = FDKreadBits(bitstream, 3);
+- int HRTFnumChan = FDKreadBits(bitstream, 4);
+- int HRTFasymmetric = FDKreadBits(bitstream, 1);
+-
+- HRTFnumBand = freqResTable_LD[HRTFfreqRes];
+-
+- for (hc = 0; hc < HRTFnumChan; hc++) {
+- FDKpushFor(bitstream, HRTFnumBand * 6); /* HRTFlevelLeft[hc][hb] */
+- if (HRTFasymmetric) {
+- FDKpushFor(bitstream, HRTFnumBand * 6); /* HRTFlevelRight[hc][hb] */
+- }
+- if (FDKreadBits(bitstream, 1)) { /* HRTFphase[hc] ? */
+- FDKpushFor(bitstream, HRTFnumBand * 6); /* HRTFphaseLR[hc][hb] */
+- }
+- if (FDKreadBits(bitstream, 1)) { /* HRTFicc[hc] ? */
+- FDKpushFor(bitstream, HRTFnumBand * 6); /* HRTFiccLR[hc][hb] */
+- }
+- }
+- }
+- }
+-
+- FDKbyteAlign(bitstream,
+- cfgStartPos); /* ISO/IEC FDIS 23003-1: 5.2. ... byte alignment
+- with respect to the beginning of the syntactic
+- element in which ByteAlign() occurs. */
+-
+- numHeaderBits = cfgStartPos - (INT)FDKgetValidBits(bitstream);
+- bitsAvailable -= numHeaderBits;
+- if (bitsAvailable < 0) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+-
+- pSpatialSpecificConfig->sacExtCnt = 0;
+- pSpatialSpecificConfig->bResidualCoding = 0;
+-
+- err = SpatialDecParseExtensionConfig(
+- bitstream, pSpatialSpecificConfig, pSpatialSpecificConfig->nOttBoxes,
+- pSpatialSpecificConfig->nTttBoxes,
+- pSpatialSpecificConfig->nOutputChannels, bitsAvailable);
+-
+- FDKbyteAlign(
+- bitstream,
+- cfgStartPos); /* Same alignment anchor as above because
+- SpatialExtensionConfig() always reads full bytes */
+-
+- pSpatialSpecificConfig->coreCodec = coreCodec;
+-
+- SpatialDecDecodeHelperInfo(pSpatialSpecificConfig, UPMIXTYPE_NORMAL);
+-
+-bail:
+- if (sacHeaderLen > 0) {
+- /* If the config is of known length then assure that the
+- bitbuffer is exactly at its end when leaving the function. */
+- FDKpushBiDirectional(
+- bitstream,
+- (sacHeaderLen * 8) - (cfgStartPos - (INT)FDKgetValidBits(bitstream)));
+- }
+-
+- return err;
+-}
+-
+-int SpatialDecDefaultSpecificConfig(
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig,
+- AUDIO_OBJECT_TYPE coreCodec, int samplingFreq, int nTimeSlots,
+- int sacDecoderLevel, int isBlind, int numCoreChannels)
+-
+-{
+- int err = MPS_OK;
+- int i;
+-
+- FDK_ASSERT(coreCodec != AOT_NONE);
+- FDK_ASSERT(nTimeSlots > 0);
+- FDK_ASSERT(samplingFreq > 0);
+-
+- pSpatialSpecificConfig->coreCodec = coreCodec;
+- pSpatialSpecificConfig->samplingFreq = samplingFreq;
+- pSpatialSpecificConfig->nTimeSlots = nTimeSlots;
+- if ((pSpatialSpecificConfig->coreCodec == AOT_ER_AAC_ELD) ||
+- (pSpatialSpecificConfig->coreCodec == AOT_ER_AAC_LD))
+- pSpatialSpecificConfig->freqRes = SPATIALDEC_FREQ_RES_23;
+- else
+- pSpatialSpecificConfig->freqRes = SPATIALDEC_FREQ_RES_28;
+-
+- {
+- pSpatialSpecificConfig->treeConfig =
+- SPATIALDEC_MODE_RSVD7; /* 212 configuration */
+- }
+-
+- {
+- pSpatialSpecificConfig->nOttBoxes =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numOttBoxes;
+- pSpatialSpecificConfig->nInputChannels =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numInputChannels;
+- pSpatialSpecificConfig->nOutputChannels =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig].numOutputChannels;
+- }
+-
+- pSpatialSpecificConfig->quantMode = SPATIALDEC_QUANT_FINE_DEF;
+- pSpatialSpecificConfig->bArbitraryDownmix = 0;
+- pSpatialSpecificConfig->bResidualCoding = 0;
+- if ((pSpatialSpecificConfig->coreCodec == AOT_ER_AAC_ELD) ||
+- (pSpatialSpecificConfig->coreCodec == AOT_ER_AAC_LD))
+- pSpatialSpecificConfig->bsFixedGainDMX = SPATIALDEC_GAIN_RSVD2;
+- else
+- pSpatialSpecificConfig->bsFixedGainDMX = SPATIALDEC_GAIN_MODE0;
+-
+- pSpatialSpecificConfig->tempShapeConfig = SPATIALDEC_TS_TPNOWHITE;
+- pSpatialSpecificConfig->decorrConfig = SPATIALDEC_DECORR_MODE0;
+-
+- for (i = 0; i < pSpatialSpecificConfig->nOttBoxes; i++) {
+- pSpatialSpecificConfig->OttConfig[i].nOttBands = 0;
+- }
+-
+- return err;
+-}
+-
+-/*******************************************************************************
+- Functionname: coarse2fine
+- *******************************************************************************
+-
+- Description:
+- Parameter index mapping from coarse to fine quantization
+-
+- Arguments:
+-
+-Input:
+-
+-Output:
+-
+-*******************************************************************************/
+-static void coarse2fine(SCHAR *data, DATA_TYPE dataType, int startBand,
+- int numBands) {
+- int i;
+-
+- for (i = startBand; i < startBand + numBands; i++) {
+- data[i] <<= 1;
+- }
+-
+- if (dataType == t_CLD) {
+- for (i = startBand; i < startBand + numBands; i++) {
+- if (data[i] == -14)
+- data[i] = -15;
+- else if (data[i] == 14)
+- data[i] = 15;
+- }
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: fine2coarse
+- *******************************************************************************
+-
+- Description:
+- Parameter index mapping from fine to coarse quantization
+-
+- Arguments:
+-
+-Input:
+-
+-Output:
+-
+-*******************************************************************************/
+-static void fine2coarse(SCHAR *data, DATA_TYPE dataType, int startBand,
+- int numBands) {
+- int i;
+-
+- for (i = startBand; i < startBand + numBands; i++) {
+- /* Note: the if cases below actually make a difference (negative values) */
+- if (dataType == t_CLD)
+- data[i] /= 2;
+- else
+- data[i] >>= 1;
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: getStrideMap
+- *******************************************************************************
+-
+- Description:
+- Index Mapping accroding to pbStrides
+-
+- Arguments:
+-
+-Input:
+-
+-Output:
+-
+-*******************************************************************************/
+-static int getStrideMap(int freqResStride, int startBand, int stopBand,
+- int *aStrides) {
+- int i, pb, pbStride, dataBands, strOffset;
+-
+- pbStride = pbStrideTable[freqResStride];
+- dataBands = (stopBand - startBand - 1) / pbStride + 1;
+-
+- aStrides[0] = startBand;
+- for (pb = 1; pb <= dataBands; pb++) {
+- aStrides[pb] = aStrides[pb - 1] + pbStride;
+- }
+- strOffset = 0;
+- while (aStrides[dataBands] > stopBand) {
+- if (strOffset < dataBands) strOffset++;
+- for (i = strOffset; i <= dataBands; i++) {
+- aStrides[i]--;
+- }
+- }
+-
+- return dataBands;
+-}
+-
+-/*******************************************************************************
+- Functionname: ecDataDec
+- *******************************************************************************
+-
+- Description:
+- Do delta decoding and dequantization
+-
+- Arguments:
+-
+-Input:
+-
+-Output:
+-
+-
+-*******************************************************************************/
+-
+-static SACDEC_ERROR ecDataDec(
+- const SPATIAL_BS_FRAME *frame, UINT syntaxFlags,
+- HANDLE_FDK_BITSTREAM bitstream, LOSSLESSDATA *const llData,
+- SCHAR (*data)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS], SCHAR **lastdata,
+- int datatype, int boxIdx, int startBand, int stopBand, SCHAR defaultValue) {
+- SACDEC_ERROR err = MPS_OK;
+- int i, j, pb, dataSets, setIdx, bsDataPair, dataBands, oldQuantCoarseXXX;
+- INT aStrides[MAX_PARAMETER_BANDS + 1] = {0};
+-
+- dataSets = 0;
+- for (i = 0; i < frame->numParameterSets; i++) {
+- llData->bsXXXDataMode[i] = (SCHAR)FDKreadBits(bitstream, 2);
+-
+- if ((frame->bsIndependencyFlag == 1) && (i == 0) &&
+- (llData->bsXXXDataMode[i] == 1 ||
+- llData->bsXXXDataMode[i] == 2)) { /* This check catches bitstreams
+- generated by older encoder that
+- cause trouble */
+- return MPS_PARSE_ERROR;
+- }
+- if ((i >= frame->numParameterSets - 1) &&
+- (llData->bsXXXDataMode[i] ==
+- 2)) { /* The interpolation mode must not be active for the last
+- parameter set */
+- return MPS_PARSE_ERROR;
+- }
+-
+- if (llData->bsXXXDataMode[i] == 3) {
+- dataSets++;
+- }
+- }
+-
+- setIdx = 0;
+- bsDataPair = 0;
+- oldQuantCoarseXXX = llData->state->bsQuantCoarseXXXprevParse;
+-
+- for (i = 0; i < frame->numParameterSets; i++) {
+- if (llData->bsXXXDataMode[i] == 0) {
+- for (pb = startBand; pb < stopBand; pb++) {
+- lastdata[boxIdx][pb] = defaultValue;
+- }
+-
+- oldQuantCoarseXXX = 0;
+- }
+-
+- if (llData->bsXXXDataMode[i] == 3) {
+- if (bsDataPair) {
+- bsDataPair = 0;
+- } else {
+- bsDataPair = FDKreadBits(bitstream, 1);
+- llData->bsQuantCoarseXXX[setIdx] = (UCHAR)FDKreadBits(bitstream, 1);
+- llData->bsFreqResStrideXXX[setIdx] = (UCHAR)FDKreadBits(bitstream, 2);
+-
+- if (llData->bsQuantCoarseXXX[setIdx] != oldQuantCoarseXXX) {
+- if (oldQuantCoarseXXX) {
+- coarse2fine(lastdata[boxIdx], (DATA_TYPE)datatype, startBand,
+- stopBand - startBand);
+- } else {
+- fine2coarse(lastdata[boxIdx], (DATA_TYPE)datatype, startBand,
+- stopBand - startBand);
+- }
+- }
+-
+- dataBands = getStrideMap(llData->bsFreqResStrideXXX[setIdx], startBand,
+- stopBand, aStrides);
+-
+- for (pb = 0; pb < dataBands; pb++) {
+- lastdata[boxIdx][startBand + pb] = lastdata[boxIdx][aStrides[pb]];
+- }
+-
+- if (boxIdx > MAX_NUM_OTT) return MPS_INVALID_BOXIDX;
+- if ((setIdx + bsDataPair) > MAX_PARAMETER_SETS)
+- return MPS_INVALID_SETIDX;
+-
+- /* DECODER_TYPE defined in FDK_tools */
+- DECODER_TYPE this_decoder_type = SAC_DECODER;
+- if (syntaxFlags & (SACDEC_SYNTAX_USAC | SACDEC_SYNTAX_RSVD50)) {
+- this_decoder_type = USAC_DECODER;
+- } else if (syntaxFlags & SACDEC_SYNTAX_LD) {
+- this_decoder_type = SAOC_DECODER;
+- }
+-
+- err = (SACDEC_ERROR)EcDataPairDec(
+- this_decoder_type, bitstream, data[boxIdx][setIdx + 0],
+- data[boxIdx][setIdx + 1], lastdata[boxIdx], (DATA_TYPE)datatype,
+- startBand, dataBands, bsDataPair, llData->bsQuantCoarseXXX[setIdx],
+- !(frame->bsIndependencyFlag && (i == 0)) || (setIdx > 0));
+- if (err != MPS_OK) goto bail;
+-
+- if (datatype == t_IPD) {
+- const SCHAR mask = (llData->bsQuantCoarseXXX[setIdx]) ? 7 : 15;
+- for (pb = 0; pb < dataBands; pb++) {
+- for (j = aStrides[pb]; j < aStrides[pb + 1]; j++) {
+- lastdata[boxIdx][j] =
+- data[boxIdx][setIdx + bsDataPair][startBand + pb] & mask;
+- }
+- }
+- } else {
+- for (pb = 0; pb < dataBands; pb++) {
+- for (j = aStrides[pb]; j < aStrides[pb + 1]; j++) {
+- lastdata[boxIdx][j] =
+- data[boxIdx][setIdx + bsDataPair][startBand + pb];
+- }
+- }
+- }
+-
+- oldQuantCoarseXXX = llData->bsQuantCoarseXXX[setIdx];
+-
+- if (bsDataPair) {
+- llData->bsQuantCoarseXXX[setIdx + 1] =
+- llData->bsQuantCoarseXXX[setIdx];
+- llData->bsFreqResStrideXXX[setIdx + 1] =
+- llData->bsFreqResStrideXXX[setIdx];
+- }
+- setIdx += bsDataPair + 1;
+- } /* !bsDataPair */
+- } /* llData->bsXXXDataMode[i] == 3 */
+- }
+-
+- llData->state->bsQuantCoarseXXXprevParse = oldQuantCoarseXXX;
+-
+-bail:
+- return err;
+-}
+-
+-/*******************************************************************************
+- Functionname: parseArbitraryDownmixData
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static SACDEC_ERROR parseArbitraryDownmixData(
+- spatialDec *self, const SPATIAL_SPECIFIC_CONFIG *pSSC,
+- const UINT syntaxFlags, const SPATIAL_BS_FRAME *frame,
+- HANDLE_FDK_BITSTREAM bitstream) {
+- SACDEC_ERROR err = MPS_OK;
+- int ch;
+- int offset = pSSC->nOttBoxes;
+-
+- /* CLD (arbitrary down-mix gains) */
+- for (ch = 0; ch < pSSC->nInputChannels; ch++) {
+- err = ecDataDec(frame, syntaxFlags, bitstream,
+- &frame->CLDLosslessData[offset + ch],
+- frame->cmpArbdmxGainIdx, self->cmpArbdmxGainIdxPrev, t_CLD,
+- ch, 0, pSSC->freqRes, arbdmxGainDefault);
+- if (err != MPS_OK) return err;
+- }
+-
+- return err;
+-
+-} /* parseArbitraryDownmixData */
+-
+-/*******************************************************************************
+- Functionname: SpatialDecParseFrame
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Input:
+-
+- Output:
+-
+-*******************************************************************************/
+-
+-static int nBitsParamSlot(int i) {
+- int bitsParamSlot;
+-
+- bitsParamSlot = fMax(0, DFRACT_BITS - 1 - fNormz((FIXP_DBL)i));
+- if ((1 << bitsParamSlot) < i) {
+- bitsParamSlot++;
+- }
+- FDK_ASSERT((bitsParamSlot >= 0) && (bitsParamSlot <= 32));
+-
+- return bitsParamSlot;
+-}
+-
+-SACDEC_ERROR SpatialDecParseFrameData(
+- spatialDec_struct *self, SPATIAL_BS_FRAME *frame,
+- HANDLE_FDK_BITSTREAM bitstream,
+- const SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig, UPMIXTYPE upmixType,
+- int fGlobalIndependencyFlag) {
+- SACDEC_ERROR err = MPS_OK;
+- int bsFramingType, dataBands, ps, pg, i;
+- int pb;
+- int numTempShapeChan = 0;
+- int bsNumOutputChannels =
+- treePropertyTable[pSpatialSpecificConfig->treeConfig]
+- .numOutputChannels; /* CAUTION: Maybe different to
+- pSpatialSpecificConfig->treeConfig in some
+- modes! */
+- int paramSetErr = 0;
+- UINT alignAnchor = FDKgetValidBits(
+- bitstream); /* Anchor for ByteAlign() function. See comment below. */
+- UINT syntaxFlags;
+-
+- syntaxFlags = pSpatialSpecificConfig->syntaxFlags;
+-
+- if ((syntaxFlags & (SACDEC_SYNTAX_USAC | SACDEC_SYNTAX_RSVD50)) &&
+- pSpatialSpecificConfig->bsHighRateMode == 0) {
+- bsFramingType = 0; /* fixed framing */
+- frame->numParameterSets = 1;
+- } else {
+- bsFramingType = FDKreadBits(bitstream, 1);
+- if (syntaxFlags & SACDEC_SYNTAX_LD)
+- frame->numParameterSets = FDKreadBits(bitstream, 1) + 1;
+- else
+- frame->numParameterSets = FDKreadBits(bitstream, 3) + 1;
+- }
+-
+- /* Any error after this line shall trigger parameter invalidation at bail
+- * label. */
+- paramSetErr = 1;
+-
+- if (frame->numParameterSets >= MAX_PARAMETER_SETS) {
+- goto bail;
+- }
+-
+- /* Basic config check. */
+- if (pSpatialSpecificConfig->nInputChannels <= 0 ||
+- pSpatialSpecificConfig->nOutputChannels <= 0) {
+- err = MPS_UNSUPPORTED_CONFIG;
+- goto bail;
+- }
+-
+- if (bsFramingType) {
+- int prevParamSlot = -1;
+- int bitsParamSlot;
+-
+- {
+- bitsParamSlot = nBitsParamSlot(pSpatialSpecificConfig->nTimeSlots);
+-
+- for (i = 0; i < frame->numParameterSets; i++) {
+- frame->paramSlot[i] = FDKreadBits(bitstream, bitsParamSlot);
+- /* Sanity check */
+- if ((frame->paramSlot[i] <= prevParamSlot) ||
+- (frame->paramSlot[i] >= pSpatialSpecificConfig->nTimeSlots)) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+- prevParamSlot = frame->paramSlot[i];
+- }
+- }
+- } else {
+- for (i = 0; i < frame->numParameterSets; i++) {
+- frame->paramSlot[i] = ((pSpatialSpecificConfig->nTimeSlots * (i + 1)) /
+- frame->numParameterSets) -
+- 1;
+- }
+- }
+-
+- if ((syntaxFlags & (SACDEC_SYNTAX_USAC | SACDEC_SYNTAX_RSVD50)) &&
+- fGlobalIndependencyFlag) {
+- frame->bsIndependencyFlag = 1;
+- } else {
+- frame->bsIndependencyFlag = (UCHAR)FDKreadBits(bitstream, 1);
+- }
+-
+- /*
+- * OttData()
+- */
+- for (i = 0; i < pSpatialSpecificConfig->nOttBoxes; i++) {
+- err = ecDataDec(frame, syntaxFlags, bitstream, &frame->CLDLosslessData[i],
+- frame->cmpOttCLDidx, self->cmpOttCLDidxPrev, t_CLD, i, 0,
+- pSpatialSpecificConfig->bitstreamOttBands[i],
+- pSpatialSpecificConfig->ottCLDdefault[i]);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- } /* i < numOttBoxes */
+-
+- {
+- for (i = 0; i < pSpatialSpecificConfig->nOttBoxes; i++) {
+- err = ecDataDec(frame, syntaxFlags, bitstream, &frame->ICCLosslessData[i],
+- frame->cmpOttICCidx, self->cmpOttICCidxPrev, t_ICC, i, 0,
+- pSpatialSpecificConfig->bitstreamOttBands[i], ICCdefault);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- } /* i < numOttBoxes */
+- } /* !oneICC */
+-
+- if ((pSpatialSpecificConfig->treeConfig == SPATIALDEC_MODE_RSVD7) &&
+- (pSpatialSpecificConfig->bsPhaseCoding)) {
+- frame->phaseMode = FDKreadBits(bitstream, 1);
+-
+- if (frame->phaseMode == 0) {
+- for (pb = 0; pb < pSpatialSpecificConfig->numOttBandsIPD; pb++) {
+- self->cmpOttIPDidxPrev[0][pb] = 0;
+- for (i = 0; i < frame->numParameterSets; i++) {
+- frame->cmpOttIPDidx[0][i][pb] = 0;
+- // frame->ottIPDidx[0][i][pb] = 0;
+- }
+- /* self->ottIPDidxPrev[0][pb] = 0; */
+- }
+- frame->OpdSmoothingMode = 0;
+- } else {
+- frame->OpdSmoothingMode = FDKreadBits(bitstream, 1);
+- err = ecDataDec(frame, syntaxFlags, bitstream, &frame->IPDLosslessData[0],
+- frame->cmpOttIPDidx, self->cmpOttIPDidxPrev, t_IPD, 0, 0,
+- pSpatialSpecificConfig->numOttBandsIPD, IPDdefault);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- }
+- }
+-
+- /*
+- * SmgData()
+- */
+-
+- {
+- if (!pSpatialSpecificConfig->bsHighRateMode &&
+- (syntaxFlags & SACDEC_SYNTAX_USAC)) {
+- for (ps = 0; ps < frame->numParameterSets; ps++) {
+- frame->bsSmoothMode[ps] = 0;
+- }
+- } else {
+- for (ps = 0; ps < frame->numParameterSets; ps++) {
+- frame->bsSmoothMode[ps] = (UCHAR)FDKreadBits(bitstream, 2);
+- if (frame->bsSmoothMode[ps] >= 2) {
+- frame->bsSmoothTime[ps] = (UCHAR)FDKreadBits(bitstream, 2);
+- }
+- if (frame->bsSmoothMode[ps] == 3) {
+- frame->bsFreqResStrideSmg[ps] = (UCHAR)FDKreadBits(bitstream, 2);
+- dataBands = (pSpatialSpecificConfig->freqRes - 1) /
+- pbStrideTable[frame->bsFreqResStrideSmg[ps]] +
+- 1;
+- for (pg = 0; pg < dataBands; pg++) {
+- frame->bsSmgData[ps][pg] = (UCHAR)FDKreadBits(bitstream, 1);
+- }
+- }
+- } /* ps < numParameterSets */
+- }
+- }
+-
+- /*
+- * TempShapeData()
+- */
+- if ((pSpatialSpecificConfig->tempShapeConfig == 3) &&
+- (syntaxFlags & SACDEC_SYNTAX_USAC)) {
+- int TsdErr;
+- TsdErr = TsdRead(bitstream, pSpatialSpecificConfig->nTimeSlots,
+- &frame->TsdData[0]);
+- if (TsdErr) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+- } else {
+- frame->TsdData[0].bsTsdEnable = 0;
+- }
+-
+- for (i = 0; i < bsNumOutputChannels; i++) {
+- frame->tempShapeEnableChannelSTP[i] = 0;
+- frame->tempShapeEnableChannelGES[i] = 0;
+- }
+-
+- if ((pSpatialSpecificConfig->tempShapeConfig == 1) ||
+- (pSpatialSpecificConfig->tempShapeConfig == 2)) {
+- int bsTempShapeEnable = FDKreadBits(bitstream, 1);
+- if (bsTempShapeEnable) {
+- numTempShapeChan =
+- tempShapeChanTable[pSpatialSpecificConfig->tempShapeConfig - 1]
+- [pSpatialSpecificConfig->treeConfig];
+- switch (pSpatialSpecificConfig->tempShapeConfig) {
+- case 1: /* STP */
+- for (i = 0; i < numTempShapeChan; i++) {
+- int stpEnable = FDKreadBits(bitstream, 1);
+- frame->tempShapeEnableChannelSTP[i] = stpEnable;
+- }
+- break;
+- case 2: /* GES */
+- {
+- UCHAR gesChannelEnable[MAX_OUTPUT_CHANNELS];
+-
+- for (i = 0; i < numTempShapeChan; i++) {
+- gesChannelEnable[i] = (UCHAR)FDKreadBits(bitstream, 1);
+- frame->tempShapeEnableChannelGES[i] = gesChannelEnable[i];
+- }
+- for (i = 0; i < numTempShapeChan; i++) {
+- if (gesChannelEnable[i]) {
+- int envShapeData_tmp[MAX_TIME_SLOTS];
+- if (huff_dec_reshape(bitstream, envShapeData_tmp,
+- pSpatialSpecificConfig->nTimeSlots) != 0) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+- for (int ts = 0; ts < pSpatialSpecificConfig->nTimeSlots; ts++) {
+- if (!(envShapeData_tmp[ts] >= 0) &&
+- (envShapeData_tmp[ts] <= 4)) {
+- err = MPS_PARSE_ERROR;
+- goto bail;
+- }
+- frame->bsEnvShapeData[i][ts] = (UCHAR)envShapeData_tmp[ts];
+- }
+- }
+- }
+- } break;
+- default:
+- err = MPS_INVALID_TEMPSHAPE;
+- goto bail;
+- }
+- } /* bsTempShapeEnable */
+- } /* pSpatialSpecificConfig->tempShapeConfig != 0 */
+-
+- if (pSpatialSpecificConfig->bArbitraryDownmix != 0) {
+- err = parseArbitraryDownmixData(self, pSpatialSpecificConfig, syntaxFlags,
+- frame, bitstream);
+- if (err != MPS_OK) goto bail;
+- }
+-
+- if (1 && (!(syntaxFlags & (SACDEC_SYNTAX_USAC)))) {
+- FDKbyteAlign(bitstream,
+- alignAnchor); /* ISO/IEC FDIS 23003-1: 5.2. ... byte alignment
+- with respect to the beginning of the syntactic
+- element in which ByteAlign() occurs. */
+- }
+-
+-bail:
+- if (err != MPS_OK && paramSetErr != 0) {
+- /* Since the parameter set data has already been written to the instance we
+- * need to ... */
+- frame->numParameterSets = 0; /* ... signal that it is corrupt ... */
+- }
+-
+- return err;
+-
+-} /* SpatialDecParseFrame */
+-
+-/*******************************************************************************
+- Functionname: createMapping
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static void createMapping(int aMap[MAX_PARAMETER_BANDS + 1], int startBand,
+- int stopBand, int stride) {
+- int inBands, outBands, bandsAchived, bandsDiff, incr, k, i;
+- int vDk[MAX_PARAMETER_BANDS + 1];
+- inBands = stopBand - startBand;
+- outBands = (inBands - 1) / stride + 1;
+-
+- if (outBands < 1) {
+- outBands = 1;
+- }
+-
+- bandsAchived = outBands * stride;
+- bandsDiff = inBands - bandsAchived;
+- for (i = 0; i < outBands; i++) {
+- vDk[i] = stride;
+- }
+-
+- if (bandsDiff > 0) {
+- incr = -1;
+- k = outBands - 1;
+- } else {
+- incr = 1;
+- k = 0;
+- }
+-
+- while (bandsDiff != 0) {
+- vDk[k] = vDk[k] - incr;
+- k = k + incr;
+- bandsDiff = bandsDiff + incr;
+- if (k >= outBands) {
+- if (bandsDiff > 0) {
+- k = outBands - 1;
+- } else if (bandsDiff < 0) {
+- k = 0;
+- }
+- }
+- }
+- aMap[0] = startBand;
+- for (i = 0; i < outBands; i++) {
+- aMap[i + 1] = aMap[i] + vDk[i];
+- }
+-} /* createMapping */
+-
+-/*******************************************************************************
+- Functionname: mapFrequency
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static void mapFrequency(const SCHAR *pInput, /* Input */
+- SCHAR *pOutput, /* Output */
+- int *pMap, /* Mapping function */
+- int dataBands) /* Number of data Bands */
+-{
+- int i, j;
+- int startBand0 = pMap[0];
+-
+- for (i = 0; i < dataBands; i++) {
+- int startBand, stopBand, value;
+-
+- value = pInput[i + startBand0];
+-
+- startBand = pMap[i];
+- stopBand = pMap[i + 1];
+- for (j = startBand; j < stopBand; j++) {
+- pOutput[j] = value;
+- }
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: deq
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static int deqIdx(int value, int paramType) {
+- int idx = -1;
+-
+- switch (paramType) {
+- case t_CLD:
+- if (((value + 15) >= 0) && ((value + 15) < 31)) {
+- idx = (value + 15);
+- }
+- break;
+-
+- case t_ICC:
+- if ((value >= 0) && (value < 8)) {
+- idx = value;
+- }
+- break;
+-
+- case t_IPD:
+- /* (+/-)15 * MAX_PARAMETER_BANDS for differential coding in frequency
+- * domain (according to rbl) */
+- if ((value >= -420) && (value <= 420)) {
+- idx = (value & 0xf);
+- }
+- break;
+-
+- default:
+- FDK_ASSERT(0);
+- }
+-
+- return idx;
+-}
+-
+- /*******************************************************************************
+- Functionname: factorFunct
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+- *******************************************************************************/
+-
+-#define SF_IDX (7)
+-#define SF_FACTOR (3)
+-#define SCALE_FACTOR (1 << SF_FACTOR)
+-#define SCALE_CLD_C1C2 (1 << SF_CLD_C1C2)
+-
+-static FIXP_DBL factorFunct(FIXP_DBL ottVsTotDb, INT quantMode) {
+- FIXP_DBL factor;
+-
+- if (ottVsTotDb > FL2FXCONST_DBL(0.0)) {
+- ottVsTotDb = FL2FXCONST_DBL(0.0);
+- }
+-
+- ottVsTotDb = -ottVsTotDb;
+-
+- switch (quantMode) {
+- case 0:
+- factor = FL2FXCONST_DBL(1.0f / SCALE_FACTOR);
+- break;
+- case 1:
+- if (ottVsTotDb >= FL2FXCONST_DBL(21.0f / SCALE_CLD_C1C2))
+- factor = FL2FXCONST_DBL(5.0f / SCALE_FACTOR);
+- else if (ottVsTotDb <= FL2FXCONST_DBL(1.0f / SCALE_CLD_C1C2))
+- factor = FL2FXCONST_DBL(1.0f / SCALE_FACTOR);
+- else
+- factor = (fMult(FL2FXCONST_DBL(0.2f), ottVsTotDb) +
+- FL2FXCONST_DBL(0.8f / SCALE_CLD_C1C2))
+- << (SF_CLD_C1C2 - SF_FACTOR);
+- break;
+- case 2:
+- if (ottVsTotDb >= FL2FXCONST_DBL(25.0f / SCALE_CLD_C1C2)) {
+- FDK_ASSERT(SF_FACTOR == 3);
+- factor = (FIXP_DBL)
+- MAXVAL_DBL; /* avoid warning: FL2FXCONST_DBL(8.0f/SCALE_FACTOR) */
+- } else if (ottVsTotDb <= FL2FXCONST_DBL(1.0f / SCALE_CLD_C1C2))
+- factor = FL2FXCONST_DBL(1.0f / SCALE_FACTOR);
+- else
+- factor = (fMult(FL2FXCONST_DBL(7.0f / 24.0f), ottVsTotDb) +
+- FL2FXCONST_DBL((17.0f / 24.0f) / SCALE_CLD_C1C2))
+- << (SF_CLD_C1C2 - SF_FACTOR);
+- break;
+- default:
+- factor = FL2FXCONST_DBL(0.0f);
+- }
+-
+- return (factor);
+-}
+-
+-/*******************************************************************************
+- Functionname: factorCLD
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static void factorCLD(SCHAR *idx, FIXP_DBL ottVsTotDb, FIXP_DBL *ottVsTotDb1,
+- FIXP_DBL *ottVsTotDb2, SCHAR ottVsTotDbMode,
+- INT quantMode) {
+- FIXP_DBL factor;
+- FIXP_DBL cldIdxFract;
+- INT cldIdx;
+-
+- factor = factorFunct(ottVsTotDb, quantMode);
+-
+- cldIdxFract =
+- fMult((FIXP_DBL)((*idx) << ((DFRACT_BITS - 1) - SF_IDX)), factor);
+- cldIdxFract += FL2FXCONST_DBL(15.5f / (1 << (SF_FACTOR + SF_IDX)));
+- cldIdx = fixp_truncateToInt(cldIdxFract, SF_FACTOR + SF_IDX);
+-
+- cldIdx = fMin(cldIdx, 30);
+- cldIdx = fMax(cldIdx, 0);
+-
+- *idx = cldIdx - 15;
+-
+- if (ottVsTotDbMode & ottVsTotDb1Activ)
+- (*ottVsTotDb1) = ottVsTotDb + dequantCLD_c1[cldIdx];
+-
+- if (ottVsTotDbMode & ottVsTotDb2Activ)
+- (*ottVsTotDb2) = ottVsTotDb + dequantCLD_c1[30 - cldIdx];
+-}
+-
+-/*******************************************************************************
+- Functionname: mapIndexData
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static SACDEC_ERROR mapIndexData(
+- LOSSLESSDATA *llData, SCHAR ***outputDataIdx, SCHAR ***outputIdxData,
+- const SCHAR (*cmpIdxData)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
+- SCHAR ***diffIdxData, SCHAR xttIdx, SCHAR **idxPrev, int paramIdx,
+- int paramType, int startBand, int stopBand, SCHAR defaultValue,
+- int numParameterSets, const int *paramSlot, int extendFrame, int quantMode,
+- SpatialDecConcealmentInfo *concealmentInfo, SCHAR ottVsTotDbMode,
+- FIXP_DBL (*pOttVsTotDbIn)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
+- FIXP_DBL (*pOttVsTotDb1)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
+- FIXP_DBL (*pOttVsTotDb2)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS]) {
+- int aParamSlots[MAX_PARAMETER_SETS];
+- int aInterpolate[MAX_PARAMETER_SETS];
+-
+- int dataSets;
+- int aMap[MAX_PARAMETER_BANDS + 1];
+-
+- int setIdx, i, band, parmSlot;
+- int dataBands;
+- int ps, pb;
+- int i1;
+-
+- if (numParameterSets > MAX_PARAMETER_SETS) return MPS_WRONG_PARAMETERSETS;
+-
+- dataSets = 0;
+- for (i = 0; i < numParameterSets; i++) {
+- if (llData->bsXXXDataMode[i] == 3) {
+- aParamSlots[dataSets] = i;
+- dataSets++;
+- }
+- }
+-
+- setIdx = 0;
+-
+- /* Main concealment stage is here: */
+- SpatialDecConcealment_Apply(
+- concealmentInfo, cmpIdxData[xttIdx],
+- (diffIdxData != NULL) ? diffIdxData[xttIdx] : NULL, idxPrev[xttIdx],
+- llData->bsXXXDataMode, startBand, stopBand, defaultValue, paramType,
+- numParameterSets);
+-
+- /* Prepare data */
+- for (i = 0; i < numParameterSets; i++) {
+- if (llData->bsXXXDataMode[i] == 0) {
+- llData->nocmpQuantCoarseXXX[i] = 0;
+- for (band = startBand; band < stopBand; band++) {
+- outputIdxData[xttIdx][i][band] = defaultValue;
+- }
+- for (band = startBand; band < stopBand; band++) {
+- idxPrev[xttIdx][band] = outputIdxData[xttIdx][i][band];
+- }
+- /* Because the idxPrev are also set to the defaultValue -> signalize fine
+- */
+- llData->state->bsQuantCoarseXXXprev = 0;
+- }
+-
+- if (llData->bsXXXDataMode[i] == 1) {
+- for (band = startBand; band < stopBand; band++) {
+- outputIdxData[xttIdx][i][band] = idxPrev[xttIdx][band];
+- }
+- llData->nocmpQuantCoarseXXX[i] = llData->state->bsQuantCoarseXXXprev;
+- }
+-
+- if (llData->bsXXXDataMode[i] == 2) {
+- for (band = startBand; band < stopBand; band++) {
+- outputIdxData[xttIdx][i][band] = idxPrev[xttIdx][band];
+- }
+- llData->nocmpQuantCoarseXXX[i] = llData->state->bsQuantCoarseXXXprev;
+- aInterpolate[i] = 1;
+- } else {
+- aInterpolate[i] = 0;
+- }
+-
+- if (llData->bsXXXDataMode[i] == 3) {
+- int stride;
+-
+- parmSlot = aParamSlots[setIdx];
+- stride = pbStrideTable[llData->bsFreqResStrideXXX[setIdx]];
+- dataBands = (stopBand - startBand - 1) / stride + 1;
+- createMapping(aMap, startBand, stopBand, stride);
+- mapFrequency(&cmpIdxData[xttIdx][setIdx][0],
+- &outputIdxData[xttIdx][parmSlot][0], aMap, dataBands);
+- for (band = startBand; band < stopBand; band++) {
+- idxPrev[xttIdx][band] = outputIdxData[xttIdx][parmSlot][band];
+- }
+- llData->state->bsQuantCoarseXXXprev = llData->bsQuantCoarseXXX[setIdx];
+- llData->nocmpQuantCoarseXXX[i] = llData->bsQuantCoarseXXX[setIdx];
+-
+- setIdx++;
+- }
+- if (diffIdxData != NULL) {
+- for (band = startBand; band < stopBand; band++) {
+- outputIdxData[xttIdx][i][band] += diffIdxData[xttIdx][i][band];
+- }
+- }
+- } /* for( i = 0 ; i < numParameterSets; i++ ) */
+-
+- /* Map all coarse data to fine */
+- for (i = 0; i < numParameterSets; i++) {
+- if (llData->nocmpQuantCoarseXXX[i] == 1) {
+- coarse2fine(outputIdxData[xttIdx][i], (DATA_TYPE)paramType, startBand,
+- stopBand - startBand);
+- llData->nocmpQuantCoarseXXX[i] = 0;
+- }
+- }
+-
+- /* Interpolate */
+- i1 = 0;
+- for (i = 0; i < numParameterSets; i++) {
+- int xi, i2, x1, x2;
+-
+- if (aInterpolate[i] != 1) {
+- i1 = i;
+- }
+- i2 = i;
+- while (aInterpolate[i2] == 1) {
+- i2++;
+- }
+- x1 = paramSlot[i1];
+- xi = paramSlot[i];
+- x2 = paramSlot[i2];
+-
+- if (aInterpolate[i] == 1) {
+- if (i2 >= numParameterSets) return MPS_WRONG_PARAMETERSETS;
+- for (band = startBand; band < stopBand; band++) {
+- int yi, y1, y2;
+- y1 = outputIdxData[xttIdx][i1][band];
+- y2 = outputIdxData[xttIdx][i2][band];
+- if (x1 != x2) {
+- yi = y1 + (xi - x1) * (y2 - y1) / (x2 - x1);
+- } else {
+- yi = y1 /*+ (xi-x1)*(y2-y1)/1e-12*/;
+- }
+- outputIdxData[xttIdx][i][band] = yi;
+- }
+- }
+- } /* for( i = 0 ; i < numParameterSets; i++ ) */
+-
+- /* Dequantize data and apply factorCLD if necessary */
+- for (ps = 0; ps < numParameterSets; ps++) {
+- if (quantMode && (paramType == t_CLD)) {
+- if (pOttVsTotDbIn == 0) return MPS_WRONG_OTT;
+- if ((pOttVsTotDb1 == 0) && (ottVsTotDbMode == ottVsTotDb1Activ))
+- return MPS_WRONG_OTT;
+- if ((pOttVsTotDb2 == 0) && (ottVsTotDbMode == ottVsTotDb2Activ))
+- return MPS_WRONG_OTT;
+-
+- for (pb = startBand; pb < stopBand; pb++) {
+- factorCLD(&(outputIdxData[xttIdx][ps][pb]), (*pOttVsTotDbIn)[ps][pb],
+- (pOttVsTotDb1 != NULL) ? &((*pOttVsTotDb1)[ps][pb]) : NULL,
+- (pOttVsTotDb2 != NULL) ? &((*pOttVsTotDb2)[ps][pb]) : NULL,
+- ottVsTotDbMode, quantMode);
+- }
+- }
+-
+- /* Dequantize data */
+- for (band = startBand; band < stopBand; band++) {
+- outputDataIdx[xttIdx][ps][band] =
+- deqIdx(outputIdxData[xttIdx][ps][band], paramType);
+- if (outputDataIdx[xttIdx][ps][band] == -1) {
+- outputDataIdx[xttIdx][ps][band] = defaultValue;
+- }
+- }
+- } /* for( i = 0 ; i < numParameterSets; i++ ) */
+-
+- if (extendFrame) {
+- for (band = startBand; band < stopBand; band++) {
+- outputDataIdx[xttIdx][numParameterSets][band] =
+- outputDataIdx[xttIdx][numParameterSets - 1][band];
+- }
+- }
+-
+- return MPS_OK;
+-}
+-
+-/*******************************************************************************
+- Functionname: decodeAndMapFrameOtt
+- *******************************************************************************
+-
+- Description:
+- Do delta decoding and dequantization
+-
+- Arguments:
+-
+-Input:
+-
+-Output:
+-
+-*******************************************************************************/
+-static SACDEC_ERROR decodeAndMapFrameOtt(HANDLE_SPATIAL_DEC self,
+- SPATIAL_BS_FRAME *pCurBs) {
+- int i, ottIdx;
+- int numOttBoxes;
+-
+- SACDEC_ERROR err = MPS_OK;
+-
+- numOttBoxes = self->numOttBoxes;
+-
+- switch (self->treeConfig) {
+- default: {
+- if (self->quantMode != 0) {
+- goto bail;
+- }
+- }
+- for (i = 0; i < numOttBoxes; i++) {
+- err = mapIndexData(
+- &pCurBs->CLDLosslessData[i], /* LOSSLESSDATA *llData,*/
+- self->ottCLD__FDK, self->outIdxData,
+- pCurBs
+- ->cmpOttCLDidx, /* int
+- cmpIdxData[MAX_NUM_OTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
+- */
+- NULL, /* no differential data */
+- i, /* int xttIdx, Which ott/ttt index to use for input and
+- output buffers */
+- self->ottCLDidxPrev, /* int
+- idxPrev[MAX_NUM_OTT][MAX_PARAMETER_BANDS],
+- */
+- i, t_CLD, 0, /* int startBand, */
+- self->pConfigCurrent->bitstreamOttBands[i], /* int stopBand, */
+- self->pConfigCurrent->ottCLDdefault[i], /* int defaultValue, */
+- pCurBs->numParameterSets, /* int numParameterSets) */
+- pCurBs->paramSlot, self->extendFrame, self->quantMode,
+- &(self->concealInfo), ottVsTotInactiv, NULL, NULL, NULL);
+- if (err != MPS_OK) goto bail;
+-
+- } /* for(i = 0; i < numOttBoxes ; i++ ) */
+- break;
+- } /* case */
+-
+- for (ottIdx = 0; ottIdx < numOttBoxes; ottIdx++) {
+- /* Read ICC */
+- err = mapIndexData(
+- &pCurBs->ICCLosslessData[ottIdx], /* LOSSLESSDATA *llData,*/
+- self->ottICC__FDK, self->outIdxData,
+- pCurBs
+- ->cmpOttICCidx, /* int
+- cmpIdxData[MAX_NUM_OTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
+- */
+- self->ottICCdiffidx, /* differential data */
+- ottIdx, /* int xttIdx, Which ott/ttt index to use for input and
+- output buffers */
+- self->ottICCidxPrev, /* int idxPrev[MAX_NUM_OTT][MAX_PARAMETER_BANDS],
+- */
+- ottIdx, t_ICC, 0, /* int startBand, */
+- self->pConfigCurrent->bitstreamOttBands[ottIdx], /* int stopBand, */
+- ICCdefault, /* int defaultValue, */
+- pCurBs->numParameterSets, /* int numParameterSets) */
+- pCurBs->paramSlot, self->extendFrame, self->quantMode,
+- &(self->concealInfo), ottVsTotInactiv, NULL, NULL, NULL);
+- if (err != MPS_OK) goto bail;
+- } /* ottIdx */
+-
+- if ((self->treeConfig == TREE_212) && (self->phaseCoding)) {
+- if (pCurBs->phaseMode == 0) {
+- for (int pb = 0; pb < self->pConfigCurrent->numOttBandsIPD; pb++) {
+- self->ottIPDidxPrev[0][pb] = 0;
+- }
+- }
+- for (ottIdx = 0; ottIdx < numOttBoxes; ottIdx++) {
+- err = mapIndexData(
+- &pCurBs->IPDLosslessData[ottIdx], self->ottIPD__FDK, self->outIdxData,
+- pCurBs->cmpOttIPDidx, NULL, ottIdx, self->ottIPDidxPrev, ottIdx,
+- t_IPD, 0, self->numOttBandsIPD, IPDdefault, pCurBs->numParameterSets,
+- pCurBs->paramSlot, self->extendFrame, self->quantMode,
+- &(self->concealInfo), ottVsTotInactiv, NULL, NULL, NULL);
+- }
+- }
+-
+-bail:
+-
+- return MPS_OK;
+-
+-} /* decodeAndMapFrameOtt */
+-
+-/*******************************************************************************
+- Functionname: decodeAndMapFrameSmg
+- *******************************************************************************
+-
+- Description:
+- Decode smoothing flags
+-
+- Arguments:
+-
+-Input:
+-
+-Output:
+-
+-
+-*******************************************************************************/
+-static SACDEC_ERROR decodeAndMapFrameSmg(HANDLE_SPATIAL_DEC self,
+- const SPATIAL_BS_FRAME *frame) {
+- int ps, pb, pg, pbStride, dataBands, pbStart, pbStop,
+- aGroupToBand[MAX_PARAMETER_BANDS + 1];
+-
+- if (frame->numParameterSets > MAX_PARAMETER_SETS)
+- return MPS_WRONG_PARAMETERSETS;
+- if (self->bitstreamParameterBands > MAX_PARAMETER_BANDS)
+- return MPS_WRONG_PARAMETERBANDS;
+-
+- for (ps = 0; ps < frame->numParameterSets; ps++) {
+- switch (frame->bsSmoothMode[ps]) {
+- case 0:
+- self->smgTime[ps] = 256;
+- FDKmemclear(self->smgData[ps],
+- self->bitstreamParameterBands * sizeof(UCHAR));
+- break;
+-
+- case 1:
+- if (ps > 0) {
+- self->smgTime[ps] = self->smgTime[ps - 1];
+- FDKmemcpy(self->smgData[ps], self->smgData[ps - 1],
+- self->bitstreamParameterBands * sizeof(UCHAR));
+- } else {
+- self->smgTime[ps] = self->smoothState->prevSmgTime;
+- FDKmemcpy(self->smgData[ps], self->smoothState->prevSmgData,
+- self->bitstreamParameterBands * sizeof(UCHAR));
+- }
+- break;
+-
+- case 2:
+- self->smgTime[ps] = smgTimeTable[frame->bsSmoothTime[ps]];
+- for (pb = 0; pb < self->bitstreamParameterBands; pb++) {
+- self->smgData[ps][pb] = 1;
+- }
+- break;
+-
+- case 3:
+- self->smgTime[ps] = smgTimeTable[frame->bsSmoothTime[ps]];
+- pbStride = pbStrideTable[frame->bsFreqResStrideSmg[ps]];
+- dataBands = (self->bitstreamParameterBands - 1) / pbStride + 1;
+- createMapping(aGroupToBand, 0, self->bitstreamParameterBands, pbStride);
+- for (pg = 0; pg < dataBands; pg++) {
+- pbStart = aGroupToBand[pg];
+- pbStop = aGroupToBand[pg + 1];
+- for (pb = pbStart; pb < pbStop; pb++) {
+- self->smgData[ps][pb] = frame->bsSmgData[ps][pg];
+- }
+- }
+- break;
+- }
+- }
+-
+- self->smoothState->prevSmgTime = self->smgTime[frame->numParameterSets - 1];
+- FDKmemcpy(self->smoothState->prevSmgData,
+- self->smgData[frame->numParameterSets - 1],
+- self->bitstreamParameterBands * sizeof(UCHAR));
+-
+- if (self->extendFrame) {
+- self->smgTime[frame->numParameterSets] =
+- self->smgTime[frame->numParameterSets - 1];
+- FDKmemcpy(self->smgData[frame->numParameterSets],
+- self->smgData[frame->numParameterSets - 1],
+- self->bitstreamParameterBands * sizeof(UCHAR));
+- }
+-
+- return MPS_OK;
+-}
+-
+-/*******************************************************************************
+- Functionname: decodeAndMapFrameArbdmx
+- *******************************************************************************
+-
+- Description:
+- Do delta decoding and dequantization
+-
+- Arguments:
+-
+-Input:
+-
+-Output:
+-
+-*******************************************************************************/
+-static SACDEC_ERROR decodeAndMapFrameArbdmx(HANDLE_SPATIAL_DEC self,
+- const SPATIAL_BS_FRAME *frame) {
+- SACDEC_ERROR err = MPS_OK;
+- int ch;
+- int offset = self->numOttBoxes;
+-
+- for (ch = 0; ch < self->numInputChannels; ch++) {
+- err = mapIndexData(&frame->CLDLosslessData[offset + ch],
+- self->arbdmxGain__FDK, self->outIdxData,
+- frame->cmpArbdmxGainIdx, NULL, /* no differential data */
+- ch, self->arbdmxGainIdxPrev, offset + ch, t_CLD, 0,
+- self->bitstreamParameterBands,
+- 0 /*self->arbdmxGainDefault*/, frame->numParameterSets,
+- frame->paramSlot, self->extendFrame, 0,
+- &(self->concealInfo), ottVsTotInactiv, NULL, NULL, NULL);
+- if (err != MPS_OK) goto bail;
+- }
+-
+-bail:
+- return err;
+-} /* decodeAndMapFrameArbdmx */
+-
+-/*******************************************************************************
+- Functionname: SpatialDecDecodeFrame
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-SACDEC_ERROR SpatialDecDecodeFrame(spatialDec *self, SPATIAL_BS_FRAME *frame) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- self->extendFrame = 0;
+- if (frame->paramSlot[frame->numParameterSets - 1] != self->timeSlots - 1) {
+- self->extendFrame = 1;
+- }
+-
+- self->TsdTs = 0;
+-
+- /****** DTDF and MAP DATA ********/
+- if ((err = decodeAndMapFrameOtt(self, frame)) != MPS_OK) goto bail;
+-
+- if ((err = decodeAndMapFrameSmg(self, frame)) != MPS_OK) goto bail;
+-
+- if (self->arbitraryDownmix != 0) {
+- if ((err = decodeAndMapFrameArbdmx(self, frame)) != MPS_OK) goto bail;
+- }
+-
+- if (self->extendFrame) {
+- frame->numParameterSets =
+- fixMin(MAX_PARAMETER_SETS, frame->numParameterSets + 1);
+- frame->paramSlot[frame->numParameterSets - 1] = self->timeSlots - 1;
+-
+- for (int p = 0; p < frame->numParameterSets; p++) {
+- if (frame->paramSlot[p] > self->timeSlots - 1) {
+- frame->paramSlot[p] = self->timeSlots - 1;
+- err = MPS_PARSE_ERROR;
+- }
+- }
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- }
+-
+-bail:
+- return err;
+-} /* SpatialDecDecodeFrame() */
+-
+-/*******************************************************************************
+- Functionname: SpatialDecodeHeader
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-
+-SACDEC_ERROR SpatialDecDecodeHeader(
+- spatialDec *self, SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig) {
+- SACDEC_ERROR err = MPS_OK;
+- int i;
+-
+- self->samplingFreq = pSpatialSpecificConfig->samplingFreq;
+- self->timeSlots = pSpatialSpecificConfig->nTimeSlots;
+- self->frameLength = self->timeSlots * self->qmfBands;
+- self->bitstreamParameterBands = pSpatialSpecificConfig->freqRes;
+-
+- if (self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_LD)
+- self->hybridBands = self->qmfBands;
+- else
+- self->hybridBands = SacGetHybridSubbands(self->qmfBands);
+- self->tp_hybBandBorder = 12;
+-
+- self->numParameterBands = self->bitstreamParameterBands;
+-
+- if (self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_LD) {
+- switch (self->numParameterBands) {
+- case 4:
+- self->kernels = kernels_4_to_64;
+- break;
+- case 5:
+- self->kernels = kernels_5_to_64;
+- break;
+- case 7:
+- self->kernels = kernels_7_to_64;
+- break;
+- case 9:
+- self->kernels = kernels_9_to_64;
+- break;
+- case 12:
+- self->kernels = kernels_12_to_64;
+- break;
+- case 15:
+- self->kernels = kernels_15_to_64;
+- break;
+- case 23:
+- self->kernels = kernels_23_to_64;
+- break;
+- default:
+- return MPS_INVALID_PARAMETERBANDS; /* unsupported numParameterBands */
+- }
+- } else {
+- switch (self->numParameterBands) {
+- case 4:
+- self->kernels = kernels_4_to_71;
+- break;
+- case 5:
+- self->kernels = kernels_5_to_71;
+- break;
+- case 7:
+- self->kernels = kernels_7_to_71;
+- break;
+- case 10:
+- self->kernels = kernels_10_to_71;
+- break;
+- case 14:
+- self->kernels = kernels_14_to_71;
+- break;
+- case 20:
+- self->kernels = kernels_20_to_71;
+- break;
+- case 28:
+- self->kernels = kernels_28_to_71;
+- break;
+- default:
+- return MPS_INVALID_PARAMETERBANDS; /* unsupported numParameterBands */
+- }
+- }
+-
+- /* create param to hyb band table */
+- FDKmemclear(self->param2hyb, (MAX_PARAMETER_BANDS + 1) * sizeof(int));
+- for (i = 0; i < self->hybridBands; i++) {
+- self->param2hyb[self->kernels[i] + 1] = i + 1;
+- }
+- {
+- int pb = self->kernels[i - 1] + 2;
+- for (; pb < (MAX_PARAMETER_BANDS + 1); pb++) {
+- self->param2hyb[pb] = i;
+- }
+- for (pb = 0; pb < MAX_PARAMETER_BANDS; pb += 1) {
+- self->kernels_width[pb] = self->param2hyb[pb + 1] - self->param2hyb[pb];
+- }
+- }
+-
+- self->treeConfig = pSpatialSpecificConfig->treeConfig;
+-
+- self->numOttBoxes = pSpatialSpecificConfig->nOttBoxes;
+-
+- self->numInputChannels = pSpatialSpecificConfig->nInputChannels;
+-
+- self->numOutputChannels = pSpatialSpecificConfig->nOutputChannels;
+-
+- self->quantMode = pSpatialSpecificConfig->quantMode;
+-
+- self->arbitraryDownmix = pSpatialSpecificConfig->bArbitraryDownmix;
+-
+- self->numM2rows = self->numOutputChannels;
+-
+- {
+- self->residualCoding = 0;
+- if (self->arbitraryDownmix == 2)
+- self->arbitraryDownmix = 1; /* no arbitrary downmix residuals */
+- }
+- if ((self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_USAC)) {
+- self->residualCoding = pSpatialSpecificConfig->bResidualCoding;
+- }
+-
+- self->clipProtectGain__FDK =
+- FX_CFG2FX_DBL(clipGainTable__FDK[pSpatialSpecificConfig->bsFixedGainDMX]);
+- self->clipProtectGainSF__FDK =
+- clipGainSFTable__FDK[pSpatialSpecificConfig->bsFixedGainDMX];
+-
+- self->tempShapeConfig = pSpatialSpecificConfig->tempShapeConfig;
+-
+- self->decorrConfig = pSpatialSpecificConfig->decorrConfig;
+-
+- if (self->upmixType == UPMIXTYPE_BYPASS) {
+- self->numOutputChannels = self->numInputChannels;
+- }
+-
+- self->numOutputChannelsAT = self->numOutputChannels;
+-
+- self->numOttBandsIPD = pSpatialSpecificConfig->numOttBandsIPD;
+- self->phaseCoding = pSpatialSpecificConfig->bsPhaseCoding;
+- for (i = 0; i < self->numOttBoxes; i++) {
+- {
+- self->pConfigCurrent->bitstreamOttBands[i] =
+- self->bitstreamParameterBands;
+- }
+- self->numOttBands[i] = self->pConfigCurrent->bitstreamOttBands[i];
+- } /* i */
+-
+- if (self->residualCoding) {
+- int numBoxes = self->numOttBoxes;
+- for (i = 0; i < numBoxes; i++) {
+- self->residualPresent[i] =
+- pSpatialSpecificConfig->ResidualConfig[i].bResidualPresent;
+-
+- if (self->residualPresent[i]) {
+- self->residualBands[i] =
+- pSpatialSpecificConfig->ResidualConfig[i].nResidualBands;
+- /* conversion from hybrid bands to qmf bands */
+- self->residualQMFBands[i] =
+- fMax(self->param2hyb[self->residualBands[i]] + 3 - 10,
+- 3); /* simplification for the lowest 10 hybrid bands */
+- } else {
+- self->residualBands[i] = 0;
+- self->residualQMFBands[i] = 0;
+- }
+- }
+- } /* self->residualCoding */
+- else {
+- int boxes = self->numOttBoxes;
+- for (i = 0; i < boxes; i += 1) {
+- self->residualPresent[i] = 0;
+- self->residualBands[i] = 0;
+- }
+- }
+-
+- switch (self->treeConfig) {
+- case TREE_212:
+- self->numDirektSignals = 1;
+- self->numDecorSignals = 1;
+- self->numXChannels = 1;
+- if (self->arbitraryDownmix == 2) {
+- self->numXChannels += 1;
+- }
+- self->numVChannels = self->numDirektSignals + self->numDecorSignals;
+- break;
+- default:
+- return MPS_INVALID_TREECONFIG;
+- }
+-
+- self->highRateMode = pSpatialSpecificConfig->bsHighRateMode;
+- self->decorrType = pSpatialSpecificConfig->bsDecorrType;
+-
+- SpatialDecDecodeHelperInfo(pSpatialSpecificConfig, UPMIXTYPE_NORMAL);
+-
+- return err;
+-}
+-
+-/*******************************************************************************
+- Functionname: SpatialDecCreateBsFrame
+- *******************************************************************************
+-
+- Description: Create spatial bitstream structure
+-
+- Arguments: spatialDec* self
+- const SPATIAL_BS_FRAME **bsFrame
+-
+- Return: -
+-
+-*******************************************************************************/
+-SACDEC_ERROR SpatialDecCreateBsFrame(SPATIAL_BS_FRAME *bsFrame,
+- BS_LL_STATE *llState) {
+- SPATIAL_BS_FRAME *pBs = bsFrame;
+-
+- const int maxNumOtt = MAX_NUM_OTT;
+- const int maxNumInputChannels = MAX_INPUT_CHANNELS;
+-
+- FDK_ALLOCATE_MEMORY_1D_P(
+- pBs->cmpOttIPDidx, maxNumOtt * MAX_PARAMETER_SETS * MAX_PARAMETER_BANDS,
+- SCHAR, SCHAR(*)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS])
+-
+- /* Arbitrary Downmix */
+- FDK_ALLOCATE_MEMORY_1D_P(
+- pBs->cmpArbdmxGainIdx,
+- maxNumInputChannels * MAX_PARAMETER_SETS * MAX_PARAMETER_BANDS, SCHAR,
+- SCHAR(*)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS])
+-
+- /* Lossless control */
+- FDK_ALLOCATE_MEMORY_1D(pBs->CLDLosslessData, MAX_NUM_PARAMETERS, LOSSLESSDATA)
+- FDK_ALLOCATE_MEMORY_1D(pBs->ICCLosslessData, MAX_NUM_PARAMETERS, LOSSLESSDATA)
+-
+- FDK_ALLOCATE_MEMORY_1D(pBs->IPDLosslessData, MAX_NUM_PARAMETERS, LOSSLESSDATA)
+-
+- pBs->newBsData = 0;
+- pBs->numParameterSets = 1;
+-
+- /* Link lossless states */
+- for (int x = 0; x < MAX_NUM_PARAMETERS; x++) {
+- pBs->CLDLosslessData[x].state = &llState->CLDLosslessState[x];
+- pBs->ICCLosslessData[x].state = &llState->ICCLosslessState[x];
+-
+- pBs->IPDLosslessData[x].state = &llState->IPDLosslessState[x];
+- }
+-
+- return MPS_OK;
+-
+-bail:
+- return MPS_OUTOFMEMORY;
+-}
+-
+-/*******************************************************************************
+- Functionname: SpatialDecCloseBsFrame
+- *******************************************************************************
+-
+- Description: Close spatial bitstream structure
+-
+- Arguments: spatialDec* self
+-
+- Return: -
+-
+-*******************************************************************************/
+-void SpatialDecCloseBsFrame(SPATIAL_BS_FRAME *pBs) {
+- if (pBs != NULL) {
+- /* These arrays contain the compact indices, only one value per pbstride,
+- * only paramsets actually containing data. */
+-
+- FDK_FREE_MEMORY_1D(pBs->cmpOttIPDidx);
+-
+- /* Arbitrary Downmix */
+- FDK_FREE_MEMORY_1D(pBs->cmpArbdmxGainIdx);
+-
+- /* Lossless control */
+- FDK_FREE_MEMORY_1D(pBs->IPDLosslessData);
+- FDK_FREE_MEMORY_1D(pBs->CLDLosslessData);
+- FDK_FREE_MEMORY_1D(pBs->ICCLosslessData);
+- }
+-}
+diff --git a/libSACdec/src/sac_bitdec.h b/libSACdec/src/sac_bitdec.h
+deleted file mode 100644
+index cb0c7d2..0000000
+--- a/libSACdec/src/sac_bitdec.h
++++ /dev/null
+@@ -1,161 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec bitstream decoder
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Spatial Audio bitstream decoder
+-*/
+-
+-#ifndef SAC_BITDEC_H
+-#define SAC_BITDEC_H
+-
+-#include "sac_dec.h"
+-
+-typedef struct {
+- SCHAR numInputChannels;
+- SCHAR numOutputChannels;
+- SCHAR numOttBoxes;
+- SCHAR numTttBoxes;
+- SCHAR ottModeLfe[MAX_NUM_OTT];
+-} TREEPROPERTIES;
+-
+-enum { TREE_212 = 7, TREE_DUMMY = 255 };
+-
+-enum { QUANT_FINE = 0, QUANT_EBQ1 = 1, QUANT_EBQ2 = 2 };
+-
+-SACDEC_ERROR SpatialDecParseSpecificConfigHeader(
+- HANDLE_FDK_BITSTREAM bitstream,
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig,
+- AUDIO_OBJECT_TYPE coreCodec, SPATIAL_DEC_UPMIX_TYPE upmixType);
+-
+-SACDEC_ERROR SpatialDecParseMps212Config(
+- HANDLE_FDK_BITSTREAM bitstream,
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig, int samplingRate,
+- AUDIO_OBJECT_TYPE coreCodec, INT stereoConfigIndex,
+- INT coreSbrFrameLengthIndex);
+-
+-SACDEC_ERROR SpatialDecParseSpecificConfig(
+- HANDLE_FDK_BITSTREAM bitstream,
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig, int sacHeaderLen,
+- AUDIO_OBJECT_TYPE coreCodec);
+-
+-int SpatialDecDefaultSpecificConfig(
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig,
+- AUDIO_OBJECT_TYPE coreCodec, int samplingFreq, int nTimeSlots,
+- int sacDecoderLevel, int isBlind, int coreChannels);
+-
+-SACDEC_ERROR SpatialDecCreateBsFrame(SPATIAL_BS_FRAME *bsFrame,
+- BS_LL_STATE *llState);
+-
+-void SpatialDecCloseBsFrame(SPATIAL_BS_FRAME *bsFrame);
+-
+-SACDEC_ERROR SpatialDecParseFrameData(
+- spatialDec *self, SPATIAL_BS_FRAME *frame, HANDLE_FDK_BITSTREAM bitstream,
+- const SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig, UPMIXTYPE upmixType,
+- int fGlobalIndependencyFlag);
+-
+-SACDEC_ERROR SpatialDecDecodeFrame(spatialDec *self, SPATIAL_BS_FRAME *frame);
+-
+-SACDEC_ERROR SpatialDecDecodeHeader(
+- spatialDec *self, SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig);
+-
+-#endif
+diff --git a/libSACdec/src/sac_calcM1andM2.cpp b/libSACdec/src/sac_calcM1andM2.cpp
+deleted file mode 100644
+index 6e5a145..0000000
+--- a/libSACdec/src/sac_calcM1andM2.cpp
++++ /dev/null
+@@ -1,848 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec M1 and M2 calculation
+-
+-*******************************************************************************/
+-
+-#include "sac_calcM1andM2.h"
+-#include "sac_bitdec.h"
+-#include "sac_process.h"
+-#include "sac_rom.h"
+-#include "sac_smoothing.h"
+-#include "FDK_trigFcts.h"
+-
+-/* assorted definitions and constants */
+-
+-#define ABS_THR2 1.0e-9
+-#define SQRT2_FDK \
+- ((FIXP_DBL)FL2FXCONST_DBL(0.70710678118f)) /* FDKsqrt(2.0) scaled by 0.5 */
+-
+-static void param2UMX_PS__FDK(spatialDec* self,
+- FIXP_DBL H11[MAX_PARAMETER_BANDS],
+- FIXP_DBL H12[MAX_PARAMETER_BANDS],
+- FIXP_DBL H21[MAX_PARAMETER_BANDS],
+- FIXP_DBL H22[MAX_PARAMETER_BANDS],
+- FIXP_DBL c_l[MAX_PARAMETER_BANDS],
+- FIXP_DBL c_r[MAX_PARAMETER_BANDS], int ottBoxIndx,
+- int parameterSetIndx, int resBands);
+-
+-static void param2UMX_PS_Core__FDK(
+- const SCHAR cld[MAX_PARAMETER_BANDS], const SCHAR icc[MAX_PARAMETER_BANDS],
+- const int numOttBands, const int resBands,
+- FIXP_DBL H11[MAX_PARAMETER_BANDS], FIXP_DBL H12[MAX_PARAMETER_BANDS],
+- FIXP_DBL H21[MAX_PARAMETER_BANDS], FIXP_DBL H22[MAX_PARAMETER_BANDS],
+- FIXP_DBL c_l[MAX_PARAMETER_BANDS], FIXP_DBL c_r[MAX_PARAMETER_BANDS]);
+-
+-static void param2UMX_PS_IPD_OPD__FDK(
+- spatialDec* self, const SPATIAL_BS_FRAME* frame,
+- FIXP_DBL H11re[MAX_PARAMETER_BANDS], FIXP_DBL H12re[MAX_PARAMETER_BANDS],
+- FIXP_DBL H21re[MAX_PARAMETER_BANDS], FIXP_DBL H22re[MAX_PARAMETER_BANDS],
+- FIXP_DBL c_l[MAX_PARAMETER_BANDS], FIXP_DBL c_r[MAX_PARAMETER_BANDS],
+- int ottBoxIndx, int parameterSetIndx, int residualBands);
+-
+-static void param2UMX_Prediction__FDK(
+- spatialDec* self, FIXP_DBL H11re[MAX_PARAMETER_BANDS],
+- FIXP_DBL H11im[MAX_PARAMETER_BANDS], FIXP_DBL H12re[MAX_PARAMETER_BANDS],
+- FIXP_DBL H12im[MAX_PARAMETER_BANDS], FIXP_DBL H21re[MAX_PARAMETER_BANDS],
+- FIXP_DBL H21im[MAX_PARAMETER_BANDS], FIXP_DBL H22re[MAX_PARAMETER_BANDS],
+- FIXP_DBL H22im[MAX_PARAMETER_BANDS], int ottBoxIndx, int parameterSetIndx,
+- int resBands);
+-
+-/* static void SpatialDecCalculateM0(spatialDec* self,int ps); */
+-static SACDEC_ERROR SpatialDecCalculateM1andM2_212(
+- spatialDec* self, int ps, const SPATIAL_BS_FRAME* frame);
+-
+-/*******************************************************************************
+- Functionname: SpatialDecGetResidualIndex
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Input:
+-
+- Output:
+-
+-*******************************************************************************/
+-int SpatialDecGetResidualIndex(spatialDec* self, int row) {
+- return row2residual[self->treeConfig][row];
+-}
+-
+-/*******************************************************************************
+- Functionname: UpdateAlpha
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Input:
+-
+- Output:
+-
+-*******************************************************************************/
+-static void updateAlpha(spatialDec* self) {
+- int nChIn = self->numInputChannels;
+- int ch;
+-
+- for (ch = 0; ch < nChIn; ch++) {
+- FIXP_DBL alpha = /* FL2FXCONST_DBL(1.0f) */ (FIXP_DBL)MAXVAL_DBL;
+-
+- self->arbdmxAlphaPrev__FDK[ch] = self->arbdmxAlpha__FDK[ch];
+-
+- self->arbdmxAlpha__FDK[ch] = alpha;
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: SpatialDecCalculateM1andM2
+- *******************************************************************************
+- Description:
+- Arguments:
+-*******************************************************************************/
+-SACDEC_ERROR SpatialDecCalculateM1andM2(spatialDec* self, int ps,
+- const SPATIAL_BS_FRAME* frame) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- if ((self->arbitraryDownmix != 0) && (ps == 0)) {
+- updateAlpha(self);
+- }
+-
+- self->pActivM2ParamBands = NULL;
+-
+- switch (self->upmixType) {
+- case UPMIXTYPE_BYPASS:
+- case UPMIXTYPE_NORMAL:
+- switch (self->treeConfig) {
+- case TREE_212:
+- err = SpatialDecCalculateM1andM2_212(self, ps, frame);
+- break;
+- default:
+- err = MPS_WRONG_TREECONFIG;
+- };
+- break;
+-
+- default:
+- err = MPS_WRONG_TREECONFIG;
+- }
+-
+- if (err != MPS_OK) {
+- goto bail;
+- }
+-
+-bail:
+- return err;
+-}
+-
+-/*******************************************************************************
+- Functionname: SpatialDecCalculateM1andM2_212
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static SACDEC_ERROR SpatialDecCalculateM1andM2_212(
+- spatialDec* self, int ps, const SPATIAL_BS_FRAME* frame) {
+- SACDEC_ERROR err = MPS_OK;
+- int pb;
+-
+- FIXP_DBL H11re[MAX_PARAMETER_BANDS] = {FL2FXCONST_DBL(0.0f)};
+- FIXP_DBL H12re[MAX_PARAMETER_BANDS] = {FL2FXCONST_DBL(0.0f)};
+- FIXP_DBL H21re[MAX_PARAMETER_BANDS] = {FL2FXCONST_DBL(0.0f)};
+- FIXP_DBL H22re[MAX_PARAMETER_BANDS] = {FL2FXCONST_DBL(0.0f)};
+- FIXP_DBL H11im[MAX_PARAMETER_BANDS] = {FL2FXCONST_DBL(0.0f)};
+- FIXP_DBL H21im[MAX_PARAMETER_BANDS] = {FL2FXCONST_DBL(0.0f)};
+-
+- INT phaseCoding = self->phaseCoding;
+-
+- switch (phaseCoding) {
+- case 1:
+- /* phase coding: yes; residuals: no */
+- param2UMX_PS_IPD_OPD__FDK(self, frame, H11re, H12re, H21re, H22re, NULL,
+- NULL, 0, ps, self->residualBands[0]);
+- break;
+- case 3:
+- /* phase coding: yes; residuals: yes */
+- param2UMX_Prediction__FDK(self, H11re, H11im, H12re, NULL, H21re, H21im,
+- H22re, NULL, 0, ps, self->residualBands[0]);
+- break;
+- default:
+- if (self->residualCoding) {
+- /* phase coding: no; residuals: yes */
+- param2UMX_Prediction__FDK(self, H11re, NULL, H12re, NULL, H21re, NULL,
+- H22re, NULL, 0, ps, self->residualBands[0]);
+- } else {
+- /* phase coding: no; residuals: no */
+- param2UMX_PS__FDK(self, H11re, H12re, H21re, H22re, NULL, NULL, 0, ps,
+- 0);
+- }
+- break;
+- }
+-
+- for (pb = 0; pb < self->numParameterBands; pb++) {
+- self->M2Real__FDK[0][0][pb] = (H11re[pb]);
+- self->M2Real__FDK[0][1][pb] = (H12re[pb]);
+-
+- self->M2Real__FDK[1][0][pb] = (H21re[pb]);
+- self->M2Real__FDK[1][1][pb] = (H22re[pb]);
+- }
+- if (phaseCoding == 3) {
+- for (pb = 0; pb < self->numParameterBands; pb++) {
+- self->M2Imag__FDK[0][0][pb] = (H11im[pb]);
+- self->M2Imag__FDK[1][0][pb] = (H21im[pb]);
+- self->M2Imag__FDK[0][1][pb] = (FIXP_DBL)0; // H12im[pb];
+- self->M2Imag__FDK[1][1][pb] = (FIXP_DBL)0; // H22im[pb];
+- }
+- }
+-
+- if (self->phaseCoding == 1) {
+- SpatialDecSmoothOPD(
+- self, frame,
+- ps); /* INPUT: PhaseLeft, PhaseRight, (opdLeftState, opdRightState) */
+- }
+-
+- return err;
+-}
+-
+-/*******************************************************************************
+- Functionname: param2UMX_PS_Core
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static void param2UMX_PS_Core__FDK(
+- const SCHAR cld[MAX_PARAMETER_BANDS], const SCHAR icc[MAX_PARAMETER_BANDS],
+- const int numOttBands, const int resBands,
+- FIXP_DBL H11[MAX_PARAMETER_BANDS], FIXP_DBL H12[MAX_PARAMETER_BANDS],
+- FIXP_DBL H21[MAX_PARAMETER_BANDS], FIXP_DBL H22[MAX_PARAMETER_BANDS],
+- FIXP_DBL c_l[MAX_PARAMETER_BANDS], FIXP_DBL c_r[MAX_PARAMETER_BANDS]) {
+- int band;
+-
+- if ((c_l != NULL) && (c_r != NULL)) {
+- for (band = 0; band < numOttBands; band++) {
+- SpatialDequantGetCLDValues(cld[band], &c_l[band], &c_r[band]);
+- }
+- }
+-
+- band = 0;
+- FDK_ASSERT(resBands == 0);
+- for (; band < numOttBands; band++) {
+- /* compute mixing variables: */
+- const int idx1 = cld[band];
+- const int idx2 = icc[band];
+- H11[band] = FX_CFG2FX_DBL(H11_nc[idx1][idx2]);
+- H21[band] = FX_CFG2FX_DBL(H11_nc[30 - idx1][idx2]);
+- H12[band] = FX_CFG2FX_DBL(H12_nc[idx1][idx2]);
+- H22[band] = FX_CFG2FX_DBL(-H12_nc[30 - idx1][idx2]);
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: param2UMX_PS
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static void param2UMX_PS__FDK(spatialDec* self,
+- FIXP_DBL H11[MAX_PARAMETER_BANDS],
+- FIXP_DBL H12[MAX_PARAMETER_BANDS],
+- FIXP_DBL H21[MAX_PARAMETER_BANDS],
+- FIXP_DBL H22[MAX_PARAMETER_BANDS],
+- FIXP_DBL c_l[MAX_PARAMETER_BANDS],
+- FIXP_DBL c_r[MAX_PARAMETER_BANDS], int ottBoxIndx,
+- int parameterSetIndx, int residualBands) {
+- int band;
+- param2UMX_PS_Core__FDK(self->ottCLD__FDK[ottBoxIndx][parameterSetIndx],
+- self->ottICC__FDK[ottBoxIndx][parameterSetIndx],
+- self->numOttBands[ottBoxIndx], residualBands, H11, H12,
+- H21, H22, c_l, c_r);
+-
+- for (band = self->numOttBands[ottBoxIndx]; band < self->numParameterBands;
+- band++) {
+- H11[band] = H21[band] = H12[band] = H22[band] = FL2FXCONST_DBL(0.f);
+- }
+-}
+-
+-#define N_CLD (31)
+-#define N_IPD (16)
+-
+-static const FIXP_DBL sinIpd_tab[N_IPD] = {
+- FIXP_DBL(0x00000000), FIXP_DBL(0x30fbc54e), FIXP_DBL(0x5a827999),
+- FIXP_DBL(0x7641af3d), FIXP_DBL(0x7fffffff), FIXP_DBL(0x7641af3d),
+- FIXP_DBL(0x5a82799a), FIXP_DBL(0x30fbc54d), FIXP_DBL(0xffffffff),
+- FIXP_DBL(0xcf043ab3), FIXP_DBL(0xa57d8666), FIXP_DBL(0x89be50c3),
+- FIXP_DBL(0x80000000), FIXP_DBL(0x89be50c3), FIXP_DBL(0xa57d8666),
+- FIXP_DBL(0xcf043ab2),
+-};
+-
+-/* cosIpd[i] = sinIpd[(i+4)&15] */
+-#define SIN_IPD(a) (sinIpd_tab[(a)])
+-#define COS_IPD(a) (sinIpd_tab[((a) + 4) & 15]) //(cosIpd_tab[(a)])
+-
+-static const FIXP_SGL sqrt_one_minus_ICC2[8] = {
+- FL2FXCONST_SGL(0.0f),
+- FL2FXCONST_SGL(0.349329357483736f),
+- FL2FXCONST_SGL(0.540755219669676f),
+- FL2FXCONST_SGL(0.799309172723546f),
+- FL2FXCONST_SGL(0.929968187843004f),
+- FX_DBL2FXCONST_SGL(MAXVAL_DBL),
+- FL2FXCONST_SGL(0.80813303360276f),
+- FL2FXCONST_SGL(0.141067359796659f),
+-};
+-
+-/* exponent of sqrt(CLD) */
+-static const SCHAR sqrt_CLD_e[N_CLD] = {
+- -24, -7, -6, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 0, 1,
+- 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 25};
+-
+-static const FIXP_DBL sqrt_CLD_m[N_CLD] = {
+- FL2FXCONST_DBL(0.530542153566195f),
+- FL2FXCONST_DBL(0.719796896243647f),
+- FL2FXCONST_DBL(0.64f),
+- FL2FXCONST_DBL(0.569049411212455f),
+- FL2FXCONST_DBL(0.505964425626941f),
+- FL2FXCONST_DBL(0.899746120304559f),
+- FL2FXCONST_DBL(0.635462587779425f),
+- FL2FXCONST_DBL(0.897614763441571f),
+- FL2FXCONST_DBL(0.633957276984445f),
+- FL2FXCONST_DBL(0.895488455427336f),
+- FL2FXCONST_DBL(0.632455532033676f),
+- FL2FXCONST_DBL(0.796214341106995f),
+- FL2FXCONST_DBL(0.501187233627272f),
+- FL2FXCONST_DBL(0.630957344480193f),
+- FL2FXCONST_DBL(0.794328234724281f),
+- FL2FXCONST_DBL(0.5f),
+- FL2FXCONST_DBL(0.629462705897084f),
+- FL2FXCONST_DBL(0.792446596230557f),
+- FL2FXCONST_DBL(0.99763115748444f),
+- FL2FXCONST_DBL(0.627971607877395f),
+- FL2FXCONST_DBL(0.790569415042095f),
+- FL2FXCONST_DBL(0.558354490188704f),
+- FL2FXCONST_DBL(0.788696680600242f),
+- FL2FXCONST_DBL(0.557031836333591f),
+- FL2FXCONST_DBL(0.786828382371355f),
+- FL2FXCONST_DBL(0.555712315637163f),
+- FL2FXCONST_DBL(0.988211768802619f),
+- FL2FXCONST_DBL(0.87865832060992f),
+- FL2FXCONST_DBL(0.78125f),
+- FL2FXCONST_DBL(0.694640394546454f),
+- FL2FXCONST_DBL(0.942432183077448f),
+-};
+-
+-static const FIXP_DBL CLD_m[N_CLD] = {
+- FL2FXCONST_DBL(0.281474976710656f),
+- FL2FXCONST_DBL(0.518107571841987f),
+- FL2FXCONST_DBL(0.4096f),
+- FL2FXCONST_DBL(0.323817232401242f),
+- FL2FXCONST_DBL(0.256f),
+- FL2FXCONST_DBL(0.809543081003105f),
+- FL2FXCONST_DBL(0.403812700467324f),
+- FL2FXCONST_DBL(0.805712263548267f),
+- FL2FXCONST_DBL(0.401901829041533f),
+- FL2FXCONST_DBL(0.801899573803636f),
+- FL2FXCONST_DBL(0.4f),
+- FL2FXCONST_DBL(0.633957276984445f),
+- FL2FXCONST_DBL(0.251188643150958f),
+- FL2FXCONST_DBL(0.398107170553497f),
+- FL2FXCONST_DBL(0.630957344480193f),
+- FL2FXCONST_DBL(0.25f),
+- FL2FXCONST_DBL(0.396223298115278f),
+- FL2FXCONST_DBL(0.627971607877395f),
+- FL2FXCONST_DBL(0.995267926383743f),
+- FL2FXCONST_DBL(0.394348340300121f),
+- FL2FXCONST_DBL(0.625f),
+- FL2FXCONST_DBL(0.311759736713887f),
+- FL2FXCONST_DBL(0.62204245398984f),
+- FL2FXCONST_DBL(0.310284466689172f),
+- FL2FXCONST_DBL(0.619098903305123f),
+- FL2FXCONST_DBL(0.308816177750818f),
+- FL2FXCONST_DBL(0.9765625f),
+- FL2FXCONST_DBL(0.772040444377046f),
+- FL2FXCONST_DBL(0.6103515625f),
+- FL2FXCONST_DBL(0.482525277735654f),
+- FL2FXCONST_DBL(0.888178419700125),
+-};
+-
+-static FIXP_DBL dequantIPD_CLD_ICC_splitAngle__FDK_Function(INT ipdIdx,
+- INT cldIdx,
+- INT iccIdx) {
+- FIXP_DBL cld;
+- SpatialDequantGetCLD2Values(cldIdx, &cld);
+-
+- /*const FIXP_DBL one_m = (FIXP_DBL)MAXVAL_DBL;
+- const int one_e = 0;*/
+- const FIXP_DBL one_m = FL2FXCONST_DBL(0.5f);
+- const int one_e = 1;
+- /* iidLin = sqrt(cld); */
+- FIXP_DBL iidLin_m = sqrt_CLD_m[cldIdx];
+- int iidLin_e = sqrt_CLD_e[cldIdx];
+- /* iidLin2 = cld; */
+- FIXP_DBL iidLin2_m = CLD_m[cldIdx];
+- int iidLin2_e = sqrt_CLD_e[cldIdx] << 1;
+- /* iidLin21 = iidLin2 + 1.0f; */
+- int iidLin21_e;
+- FIXP_DBL iidLin21_m =
+- fAddNorm(iidLin2_m, iidLin2_e, one_m, one_e, &iidLin21_e);
+- /* iidIcc2 = iidLin * icc * 2.0f; */
+- FIXP_CFG icc = dequantICC__FDK[iccIdx];
+- FIXP_DBL temp1_m, temp1c_m;
+- int temp1_e, temp1c_e;
+- temp1_m = fMult(iidLin_m, icc);
+- temp1_e = iidLin_e + 1;
+-
+- FIXP_DBL cosIpd, sinIpd;
+- cosIpd = COS_IPD(ipdIdx);
+- sinIpd = SIN_IPD(ipdIdx);
+-
+- temp1c_m = fMult(temp1_m, cosIpd);
+- temp1c_e = temp1_e; //+cosIpd_e;
+-
+- int temp2_e, temp3_e, inv_temp3_e, ratio_e;
+- FIXP_DBL temp2_m =
+- fAddNorm(iidLin21_m, iidLin21_e, temp1c_m, temp1c_e, &temp2_e);
+- FIXP_DBL temp3_m =
+- fAddNorm(iidLin21_m, iidLin21_e, temp1_m, temp1_e, &temp3_e);
+- /* calculate 1/temp3 needed later */
+- inv_temp3_e = temp3_e;
+- FIXP_DBL inv_temp3_m = invFixp(temp3_m, &inv_temp3_e);
+- FIXP_DBL ratio_m =
+- fAddNorm(fMult(inv_temp3_m, temp2_m), (inv_temp3_e + temp2_e),
+- FL2FXCONST_DBL(1e-9f), 0, &ratio_e);
+-
+- int weight2_e, tempb_atan2_e;
+- FIXP_DBL weight2_m =
+- fPow(ratio_m, ratio_e, FL2FXCONST_DBL(0.5f), -1, &weight2_e);
+- /* atan2(w2*sinIpd, w1*iidLin + w2*cosIpd) = atan2(w2*sinIpd, (2 - w2)*iidLin
+- * + w2*cosIpd) = atan2(w2*sinIpd, 2*iidLin + w2*(cosIpd - iidLin)); */
+- /* tmpa_atan2 = w2*sinIpd; tmpb_atan2 = 2*iidLin + w2*(cosIpd - iidLin); */
+- FIXP_DBL tempb_atan2_m = iidLin_m;
+- tempb_atan2_e = iidLin_e + 1;
+- int add_tmp1_e = 0;
+- FIXP_DBL add_tmp1_m = fAddNorm(cosIpd, 0, -iidLin_m, iidLin_e, &add_tmp1_e);
+- FIXP_DBL add_tmp2_m = fMult(add_tmp1_m, weight2_m);
+- int add_tmp2_e = add_tmp1_e + weight2_e;
+- tempb_atan2_m = fAddNorm(tempb_atan2_m, tempb_atan2_e, add_tmp2_m, add_tmp2_e,
+- &tempb_atan2_e);
+-
+- FIXP_DBL tempa_atan2_m = fMult(weight2_m, sinIpd);
+- int tempa_atan2_e = weight2_e; // + sinIpd_e;
+-
+- if (tempa_atan2_e > tempb_atan2_e) {
+- tempb_atan2_m = (tempb_atan2_m >> (tempa_atan2_e - tempb_atan2_e));
+- tempb_atan2_e = tempa_atan2_e;
+- } else if (tempb_atan2_e > tempa_atan2_e) {
+- tempa_atan2_m = (tempa_atan2_m >> (tempb_atan2_e - tempa_atan2_e));
+- }
+-
+- return fixp_atan2(tempa_atan2_m, tempb_atan2_m);
+-}
+-
+-static void calculateOpd(spatialDec* self, INT ottBoxIndx, INT parameterSetIndx,
+- FIXP_DBL opd[MAX_PARAMETER_BANDS]) {
+- INT band;
+-
+- for (band = 0; band < self->numOttBandsIPD; band++) {
+- INT idxCld = self->ottCLD__FDK[ottBoxIndx][parameterSetIndx][band];
+- INT idxIpd = self->ottIPD__FDK[ottBoxIndx][parameterSetIndx][band];
+- INT idxIcc = self->ottICC__FDK[ottBoxIndx][parameterSetIndx][band];
+- FIXP_DBL cld, ipd;
+-
+- ipd = FX_CFG2FX_DBL(dequantIPD__FDK[idxIpd]);
+-
+- SpatialDequantGetCLD2Values(idxCld, &cld);
+-
+- /* ipd(idxIpd==8) == PI */
+- if ((cld == FL2FXCONST_DBL(0.0f)) && (idxIpd == 8)) {
+- opd[2 * band] = FL2FXCONST_DBL(0.0f);
+- } else {
+- opd[2 * band] = (dequantIPD_CLD_ICC_splitAngle__FDK_Function(
+- idxIpd, idxCld, idxIcc) >>
+- (IPD_SCALE - AT2O_SF));
+- }
+- opd[2 * band + 1] = opd[2 * band] - ipd;
+- }
+-}
+-
+-/* wrap phase in rad to the range of 0 <= x < 2*pi */
+-static FIXP_DBL wrapPhase(FIXP_DBL phase) {
+- while (phase < (FIXP_DBL)0) phase += PIx2__IPD;
+- while (phase >= PIx2__IPD) phase -= PIx2__IPD;
+- FDK_ASSERT((phase >= (FIXP_DBL)0) && (phase < PIx2__IPD));
+-
+- return phase;
+-}
+-
+-/*******************************************************************************
+- Functionname: param2UMX_PS_IPD
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static void param2UMX_PS_IPD_OPD__FDK(
+- spatialDec* self, const SPATIAL_BS_FRAME* frame,
+- FIXP_DBL H11[MAX_PARAMETER_BANDS], FIXP_DBL H12[MAX_PARAMETER_BANDS],
+- FIXP_DBL H21[MAX_PARAMETER_BANDS], FIXP_DBL H22[MAX_PARAMETER_BANDS],
+- FIXP_DBL c_l[MAX_PARAMETER_BANDS], FIXP_DBL c_r[MAX_PARAMETER_BANDS],
+- int ottBoxIndx, int parameterSetIndx, int residualBands) {
+- INT band;
+- FIXP_DBL opd[2 * MAX_PARAMETER_BANDS];
+- INT numOttBands = self->numOttBands[ottBoxIndx];
+- INT numIpdBands;
+-
+- numIpdBands = frame->phaseMode ? self->numOttBandsIPD : 0;
+-
+- FDK_ASSERT(self->residualCoding == 0);
+-
+- param2UMX_PS_Core__FDK(self->ottCLD__FDK[ottBoxIndx][parameterSetIndx],
+- self->ottICC__FDK[ottBoxIndx][parameterSetIndx],
+- self->numOttBands[ottBoxIndx], residualBands, H11, H12,
+- H21, H22, c_l, c_r);
+-
+- for (band = self->numOttBands[ottBoxIndx]; band < self->numParameterBands;
+- band++) {
+- H11[band] = H21[band] = H12[band] = H22[band] = FL2FXCONST_DBL(0.f);
+- }
+-
+- if (frame->phaseMode) {
+- calculateOpd(self, ottBoxIndx, parameterSetIndx, opd);
+-
+- for (band = 0; band < numIpdBands; band++) {
+- self->PhaseLeft__FDK[band] = wrapPhase(opd[2 * band]);
+- self->PhaseRight__FDK[band] = wrapPhase(opd[2 * band + 1]);
+- }
+- }
+-
+- for (band = numIpdBands; band < numOttBands; band++) {
+- self->PhaseLeft__FDK[band] = FL2FXCONST_DBL(0.0f);
+- self->PhaseRight__FDK[band] = FL2FXCONST_DBL(0.0f);
+- }
+-}
+-
+-FDK_INLINE void param2UMX_Prediction_Core__FDK(
+- FIXP_DBL* H11re, FIXP_DBL* H11im, FIXP_DBL* H12re, FIXP_DBL* H12im,
+- FIXP_DBL* H21re, FIXP_DBL* H21im, FIXP_DBL* H22re, FIXP_DBL* H22im,
+- int cldIdx, int iccIdx, int ipdIdx, int band, int numOttBandsIPD,
+- int resBands) {
+-#define MAX_WEIGHT (1.2f)
+- FDK_ASSERT((H12im == NULL) && (H22im == NULL)); /* always == 0 */
+-
+- if ((band < numOttBandsIPD) && (cldIdx == 15) && (iccIdx == 0) &&
+- (ipdIdx == 8)) {
+- const FIXP_DBL gain =
+- FL2FXCONST_DBL(0.5f / MAX_WEIGHT) >> SCALE_PARAM_M2_212_PRED;
+-
+- *H11re = gain;
+- if (band < resBands) {
+- *H21re = gain;
+- *H12re = gain;
+- *H22re = -gain;
+- } else {
+- *H21re = -gain;
+- *H12re = (FIXP_DBL)0;
+- *H22re = (FIXP_DBL)0;
+- }
+- if ((H11im != NULL) &&
+- (H21im != NULL) /*&& (H12im!=NULL) && (H22im!=NULL)*/) {
+- *H11im = (FIXP_DBL)0;
+- *H21im = (FIXP_DBL)0;
+- /* *H12im = (FIXP_DBL)0; */
+- /* *H22im = (FIXP_DBL)0; */
+- }
+- } else {
+- const FIXP_DBL one_m = (FIXP_DBL)MAXVAL_DBL;
+- const int one_e = 0;
+- /* iidLin = sqrt(cld); */
+- FIXP_DBL iidLin_m = sqrt_CLD_m[cldIdx];
+- int iidLin_e = sqrt_CLD_e[cldIdx];
+- /* iidLin2 = cld; */
+- FIXP_DBL iidLin2_m = CLD_m[cldIdx];
+- int iidLin2_e = sqrt_CLD_e[cldIdx] << 1;
+- /* iidLin21 = iidLin2 + 1.0f; */
+- int iidLin21_e;
+- FIXP_DBL iidLin21_m =
+- fAddNorm(iidLin2_m, iidLin2_e, one_m, one_e, &iidLin21_e);
+- /* iidIcc2 = iidLin * icc * 2.0f; */
+- FIXP_CFG icc = dequantICC__FDK[iccIdx];
+- int iidIcc2_e = iidLin_e + 1;
+- FIXP_DBL iidIcc2_m = fMult(iidLin_m, icc);
+- FIXP_DBL temp_m, sqrt_temp_m, inv_temp_m, weight_m;
+- int temp_e, sqrt_temp_e, inv_temp_e, weight_e, scale;
+- FIXP_DBL cosIpd, sinIpd;
+-
+- cosIpd = COS_IPD((band < numOttBandsIPD) ? ipdIdx : 0);
+- sinIpd = SIN_IPD((band < numOttBandsIPD) ? ipdIdx : 0);
+-
+- /* temp = iidLin21 + iidIcc2 * cosIpd; */
+- temp_m = fAddNorm(iidLin21_m, iidLin21_e, fMult(iidIcc2_m, cosIpd),
+- iidIcc2_e, &temp_e);
+-
+- /* calculate 1/temp needed later */
+- inv_temp_e = temp_e;
+- inv_temp_m = invFixp(temp_m, &inv_temp_e);
+-
+- /* 1/weight = sqrt(temp) * 1/sqrt(iidLin21) */
+- if (temp_e & 1) {
+- sqrt_temp_m = temp_m >> 1;
+- sqrt_temp_e = (temp_e + 1) >> 1;
+- } else {
+- sqrt_temp_m = temp_m;
+- sqrt_temp_e = temp_e >> 1;
+- }
+- sqrt_temp_m = sqrtFixp(sqrt_temp_m);
+- if (iidLin21_e & 1) {
+- iidLin21_e += 1;
+- iidLin21_m >>= 1;
+- }
+- /* weight_[m,e] is actually 1/weight in the next few lines */
+- weight_m = invSqrtNorm2(iidLin21_m, &weight_e);
+- weight_e -= iidLin21_e >> 1;
+- weight_m = fMult(sqrt_temp_m, weight_m);
+- weight_e += sqrt_temp_e;
+- scale = fNorm(weight_m);
+- weight_m = scaleValue(weight_m, scale);
+- weight_e -= scale;
+- /* weight = 0.5 * max(1/weight, 1/maxWeight) */
+- if ((weight_e < 0) ||
+- ((weight_e == 0) && (weight_m < FL2FXCONST_DBL(1.f / MAX_WEIGHT)))) {
+- weight_m = FL2FXCONST_DBL(1.f / MAX_WEIGHT);
+- weight_e = 0;
+- }
+- weight_e -= 1;
+-
+- {
+- FIXP_DBL alphaRe_m, alphaIm_m, accu_m;
+- int alphaRe_e, alphaIm_e, accu_e;
+- /* alphaRe = (1.0f - iidLin2) / temp; */
+- alphaRe_m = fAddNorm(one_m, one_e, -iidLin2_m, iidLin2_e, &alphaRe_e);
+- alphaRe_m = fMult(alphaRe_m, inv_temp_m);
+- alphaRe_e += inv_temp_e;
+-
+- /* H11re = weight - alphaRe * weight; */
+- /* H21re = weight + alphaRe * weight; */
+- accu_m = fMult(alphaRe_m, weight_m);
+- accu_e = alphaRe_e + weight_e;
+- {
+- int accu2_e;
+- FIXP_DBL accu2_m;
+- accu2_m = fAddNorm(weight_m, weight_e, -accu_m, accu_e, &accu2_e);
+- *H11re = scaleValue(accu2_m, accu2_e - SCALE_PARAM_M2_212_PRED);
+- accu2_m = fAddNorm(weight_m, weight_e, accu_m, accu_e, &accu2_e);
+- *H21re = scaleValue(accu2_m, accu2_e - SCALE_PARAM_M2_212_PRED);
+- }
+-
+- if ((H11im != NULL) &&
+- (H21im != NULL) /*&& (H12im != NULL) && (H22im != NULL)*/) {
+- /* alphaIm = -iidIcc2 * sinIpd / temp; */
+- alphaIm_m = fMult(-iidIcc2_m, sinIpd);
+- alphaIm_m = fMult(alphaIm_m, inv_temp_m);
+- alphaIm_e = iidIcc2_e + inv_temp_e;
+- /* H11im = -alphaIm * weight; */
+- /* H21im = alphaIm * weight; */
+- accu_m = fMult(alphaIm_m, weight_m);
+- accu_e = alphaIm_e + weight_e;
+- accu_m = scaleValue(accu_m, accu_e - SCALE_PARAM_M2_212_PRED);
+- *H11im = -accu_m;
+- *H21im = accu_m;
+-
+- /* *H12im = (FIXP_DBL)0; */
+- /* *H22im = (FIXP_DBL)0; */
+- }
+- }
+- if (band < resBands) {
+- FIXP_DBL weight =
+- scaleValue(weight_m, weight_e - SCALE_PARAM_M2_212_PRED);
+- *H12re = weight;
+- *H22re = -weight;
+- } else {
+- /* beta = 2.0f * iidLin * (float) sqrt(1.0f - icc * icc) * weight / temp;
+- */
+- FIXP_DBL beta_m;
+- int beta_e;
+- beta_m = FX_SGL2FX_DBL(sqrt_one_minus_ICC2[iccIdx]);
+- beta_e = 1; /* multipication with 2.0f */
+- beta_m = fMult(beta_m, weight_m);
+- beta_e += weight_e;
+- beta_m = fMult(beta_m, iidLin_m);
+- beta_e += iidLin_e;
+- beta_m = fMult(beta_m, inv_temp_m);
+- beta_e += inv_temp_e;
+-
+- beta_m = scaleValue(beta_m, beta_e - SCALE_PARAM_M2_212_PRED);
+- *H12re = beta_m;
+- *H22re = -beta_m;
+- }
+- }
+-}
+-
+-static void param2UMX_Prediction__FDK(spatialDec* self, FIXP_DBL* H11re,
+- FIXP_DBL* H11im, FIXP_DBL* H12re,
+- FIXP_DBL* H12im, FIXP_DBL* H21re,
+- FIXP_DBL* H21im, FIXP_DBL* H22re,
+- FIXP_DBL* H22im, int ottBoxIndx,
+- int parameterSetIndx, int resBands) {
+- int band;
+- FDK_ASSERT((H12im == NULL) && (H22im == NULL)); /* always == 0 */
+-
+- for (band = 0; band < self->numParameterBands; band++) {
+- int cldIdx = self->ottCLD__FDK[ottBoxIndx][parameterSetIndx][band];
+- int iccIdx = self->ottICC__FDK[ottBoxIndx][parameterSetIndx][band];
+- int ipdIdx = self->ottIPD__FDK[ottBoxIndx][parameterSetIndx][band];
+-
+- param2UMX_Prediction_Core__FDK(
+- &H11re[band], (H11im ? &H11im[band] : NULL), &H12re[band], NULL,
+- &H21re[band], (H21im ? &H21im[band] : NULL), &H22re[band], NULL, cldIdx,
+- iccIdx, ipdIdx, band, self->numOttBandsIPD, resBands);
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: initM1andM2
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-
+-SACDEC_ERROR initM1andM2(spatialDec* self, int initStatesFlag,
+- int configChanged) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- self->bOverwriteM1M2prev = (configChanged && !initStatesFlag) ? 1 : 0;
+-
+- { self->numM2rows = self->numOutputChannels; }
+-
+- if (initStatesFlag) {
+- int i, j, k;
+-
+- for (i = 0; i < self->numM2rows; i++) {
+- for (j = 0; j < self->numVChannels; j++) {
+- for (k = 0; k < MAX_PARAMETER_BANDS; k++) {
+- self->M2Real__FDK[i][j][k] = FL2FXCONST_DBL(0);
+- self->M2RealPrev__FDK[i][j][k] = FL2FXCONST_DBL(0);
+- }
+- }
+- }
+- }
+-
+- return err;
+-}
+diff --git a/libSACdec/src/sac_calcM1andM2.h b/libSACdec/src/sac_calcM1andM2.h
+deleted file mode 100644
+index 996238d..0000000
+--- a/libSACdec/src/sac_calcM1andM2.h
++++ /dev/null
+@@ -1,129 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec M1 and M2 calculation
+-
+-*******************************************************************************/
+-
+-/* sa_calcM1andM2.h */
+-
+-#ifndef SAC_CALCM1ANDM2_H
+-#define SAC_CALCM1ANDM2_H
+-
+-#include "sac_dec.h"
+-
+-#define SCALE_PARAM_M1 3
+-
+-/* Scaling of M2 matrix, but only for binaural upmix type. */
+-#define SCALE_PARAM_CALC_M2 (3)
+-#define SCALE_PARAM_M2_515X (3)
+-#define SCALE_PARAM_M2_525 (SCALE_PARAM_M1 + HRG_SF + 1 - SCALE_PARAM_CALC_M2)
+-#define SCALE_PARAM_M2_212_PRED (3)
+-/* Scaling of spectral data after applying M2 matrix, but only for binaural
+- upmix type Scaling is compensated later in synthesis qmf filterbank */
+-#define SCALE_DATA_APPLY_M2 (1)
+-
+-SACDEC_ERROR initM1andM2(spatialDec* self, int initStatesFlag,
+- int configChanged);
+-
+-int SpatialDecGetResidualIndex(spatialDec* self, int row);
+-
+-SACDEC_ERROR SpatialDecCalculateM1andM2(spatialDec* self, int ps,
+- const SPATIAL_BS_FRAME* frame);
+-
+-#endif /* SAC_CALCM1ANDM2_H */
+diff --git a/libSACdec/src/sac_dec.cpp b/libSACdec/src/sac_dec.cpp
+deleted file mode 100644
+index 4537d6e..0000000
+--- a/libSACdec/src/sac_dec.cpp
++++ /dev/null
+@@ -1,1509 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Decoder Library
+-
+-*******************************************************************************/
+-
+-#include "sac_dec_errorcodes.h"
+-#include "sac_dec.h"
+-
+-#include "sac_process.h"
+-#include "sac_bitdec.h"
+-#include "sac_smoothing.h"
+-#include "sac_calcM1andM2.h"
+-#include "sac_reshapeBBEnv.h"
+-#include "sac_stp.h"
+-#include "sac_rom.h"
+-
+-#include "FDK_decorrelate.h"
+-
+-#include "FDK_trigFcts.h"
+-#include "FDK_matrixCalloc.h"
+-
+-/* static int pbStrideTable[] = {1, 2, 5, 28}; see sac_rom.cpp */
+-
+-enum {
+- APPLY_M2_NONE = 0, /* init value */
+- APPLY_M2 = 1, /* apply m2 fallback implementation */
+- APPLY_M2_MODE212 = 2, /* apply m2 for 212 mode */
+- APPLY_M2_MODE212_Res_PhaseCoding =
+- 3 /* apply m2 for 212 mode with residuals and phase coding */
+-};
+-
+-/******************************************************************************************/
+-/* function: FDK_SpatialDecInitDefaultSpatialSpecificConfig */
+-/* output: struct of type SPATIAL_SPECIFIC_CONFIG */
+-/* input: core coder audio object type */
+-/* input: nr of core channels */
+-/* input: sampling rate */
+-/* input: nr of time slots */
+-/* input: decoder level */
+-/* input: flag indicating upmix type blind */
+-/* */
+-/* returns: error code */
+-/******************************************************************************************/
+-int FDK_SpatialDecInitDefaultSpatialSpecificConfig(
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig,
+- AUDIO_OBJECT_TYPE coreCodec, int coreChannels, int samplingFreq,
+- int nTimeSlots, int decoderLevel, int isBlind) {
+- return SpatialDecDefaultSpecificConfig(pSpatialSpecificConfig, coreCodec,
+- samplingFreq, nTimeSlots, decoderLevel,
+- isBlind, coreChannels);
+-}
+-
+-/******************************************************************************************/
+-/* function: FDK_SpatialDecCompareSpatialSpecificConfigHeader */
+-/* input: 2 pointers to a ssc */
+-/* */
+-/* output: - */
+-/* returns: error code (0 = equal, <>0 unequal) */
+-/******************************************************************************************/
+-int FDK_SpatialDecCompareSpatialSpecificConfigHeader(
+- SPATIAL_SPECIFIC_CONFIG *pSsc1, SPATIAL_SPECIFIC_CONFIG *pSsc2) {
+- int result = MPS_OK;
+-
+- /* we assume: every bit must be equal */
+- if (FDKmemcmp(pSsc1, pSsc2, sizeof(SPATIAL_SPECIFIC_CONFIG)) != 0) {
+- result = MPS_UNEQUAL_SSC;
+- }
+- return result;
+-}
+-
+-/*******************************************************************************
+- Functionname: SpatialDecClearFrameData
+- *******************************************************************************
+-
+- Description: Clear/Fake frame data to avoid misconfiguration and allow proper
+- error concealment.
+- Arguments:
+- Input: self (frame data)
+- Output: No return value.
+-
+-*******************************************************************************/
+-static void SpatialDecClearFrameData(
+- spatialDec *self, /* Shall be removed */
+- SPATIAL_BS_FRAME *bsFrame, const SACDEC_CREATION_PARAMS *const setup) {
+- int i;
+-
+- FDK_ASSERT(self != NULL);
+- FDK_ASSERT(bsFrame != NULL);
+- FDK_ASSERT(setup != NULL);
+-
+- /* do not apply shaping tools (GES or STP) */
+- for (i = 0; i < setup->maxNumOutputChannels;
+- i += 1) { /* MAX_OUTPUT_CHANNELS */
+- bsFrame->tempShapeEnableChannelSTP[i] = 0;
+- bsFrame->tempShapeEnableChannelGES[i] = 0;
+- }
+-
+- bsFrame->TsdData->bsTsdEnable = 0;
+-
+- /* use only 1 parameter set at the end of the frame */
+- bsFrame->numParameterSets = 1;
+- bsFrame->paramSlot[0] = self->timeSlots - 1;
+-
+- /* parameter smoothing tool set to off */
+- bsFrame->bsSmoothMode[0] = 0;
+-
+- /* reset residual data */
+- {
+- int resQmfBands, resTimeSlots = (1);
+-
+- resQmfBands = setup->maxNumQmfBands;
+-
+- for (i = 0; i < setup->bProcResidual
+- ? fMin(setup->maxNumResChannels,
+- setup->maxNumOttBoxes + setup->maxNumInputChannels)
+- : 0;
+- i += 1) {
+- for (int j = 0; j < resTimeSlots; j += 1) {
+- for (int k = 0; k < resQmfBands; k += 1) {
+- self->qmfResidualReal__FDK[i][j][k] = FL2FXCONST_DBL(0.0f);
+- self->qmfResidualImag__FDK[i][j][k] = FL2FXCONST_DBL(0.0f);
+- }
+- }
+- }
+- }
+-
+- return;
+-}
+-
+-/*******************************************************************************
+- Functionname: FDK_SpatialDecOpen
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-spatialDec *FDK_SpatialDecOpen(const SPATIAL_DEC_CONFIG *config,
+- int stereoConfigIndex) {
+- int i;
+- int lfSize, hfSize;
+- spatialDec *self = NULL;
+- SACDEC_CREATION_PARAMS setup;
+-
+- switch (config->decoderLevel) {
+- case DECODER_LEVEL_0: /* 212 maxNumOutputChannels== 2 */
+- setup.maxNumInputChannels = 1;
+- setup.maxNumOutputChannels = 2;
+- setup.maxNumQmfBands = 64;
+- setup.maxNumXChannels = 2;
+- setup.maxNumVChannels = 2;
+- setup.maxNumDecorChannels = 1;
+- setup.bProcResidual = 1;
+- setup.maxNumResidualChannels = 0;
+- setup.maxNumOttBoxes = 1;
+- setup.maxNumParams = setup.maxNumInputChannels + setup.maxNumOttBoxes;
+- break;
+- default:
+- return NULL;
+- }
+-
+- setup.maxNumResChannels = 1;
+-
+- {
+- switch (config->maxNumOutputChannels) {
+- case OUTPUT_CHANNELS_2_0:
+- setup.maxNumOutputChannels = fMin(setup.maxNumOutputChannels, 2);
+- break;
+- case OUTPUT_CHANNELS_DEFAULT:
+- default:
+- break;
+- }
+- }
+-
+- setup.maxNumHybridBands = SacGetHybridSubbands(setup.maxNumQmfBands);
+-
+- switch (config->decoderMode) {
+- case EXT_HQ_ONLY:
+- setup.maxNumCmplxQmfBands = setup.maxNumQmfBands;
+- setup.maxNumCmplxHybBands = setup.maxNumHybridBands;
+- break;
+- default:
+- setup.maxNumCmplxQmfBands = fixMax(PC_NUM_BANDS, setup.maxNumQmfBands);
+- setup.maxNumCmplxHybBands =
+- fixMax(PC_NUM_HYB_BANDS, setup.maxNumHybridBands);
+- break;
+- } /* switch config->decoderMode */
+-
+- FDK_ALLOCATE_MEMORY_1D_INT(self, 1, spatialDec, SECT_DATA_L2)
+-
+- self->createParams = setup;
+-
+- FDK_ALLOCATE_MEMORY_1D(self->param2hyb, MAX_PARAMETER_BANDS + 1, int)
+-
+- FDK_ALLOCATE_MEMORY_1D(self->numOttBands, setup.maxNumOttBoxes, int)
+-
+- /* allocate arrays */
+-
+- FDK_ALLOCATE_MEMORY_1D(self->smgTime, MAX_PARAMETER_SETS, int)
+- FDK_ALLOCATE_MEMORY_2D(self->smgData, MAX_PARAMETER_SETS, MAX_PARAMETER_BANDS,
+- UCHAR)
+-
+- FDK_ALLOCATE_MEMORY_3D(self->ottCLD__FDK, setup.maxNumOttBoxes,
+- MAX_PARAMETER_SETS, MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_3D(self->ottICC__FDK, setup.maxNumOttBoxes,
+- MAX_PARAMETER_SETS, MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_3D(self->ottIPD__FDK, setup.maxNumOttBoxes,
+- MAX_PARAMETER_SETS, MAX_PARAMETER_BANDS, SCHAR)
+-
+- /* Last parameters from prev frame */
+- FDK_ALLOCATE_MEMORY_2D(self->ottCLDidxPrev, setup.maxNumOttBoxes,
+- MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_2D(self->ottICCidxPrev, setup.maxNumOttBoxes,
+- MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_3D(self->ottICCdiffidx, setup.maxNumOttBoxes,
+- MAX_PARAMETER_SETS, MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_2D(self->ottIPDidxPrev, setup.maxNumOttBoxes,
+- MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_2D(self->arbdmxGainIdxPrev, setup.maxNumInputChannels,
+- MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_2D(self->cmpOttCLDidxPrev, setup.maxNumOttBoxes,
+- MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_2D(self->cmpOttICCidxPrev, setup.maxNumOttBoxes,
+- MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_3D(self->outIdxData, setup.maxNumOttBoxes,
+- MAX_PARAMETER_SETS, MAX_PARAMETER_BANDS, SCHAR)
+-
+- FDK_ALLOCATE_MEMORY_3D(self->arbdmxGain__FDK, setup.maxNumInputChannels,
+- MAX_PARAMETER_SETS, MAX_PARAMETER_BANDS, SCHAR)
+- FDK_ALLOCATE_MEMORY_1D(self->arbdmxAlpha__FDK, setup.maxNumInputChannels,
+- FIXP_DBL)
+- FDK_ALLOCATE_MEMORY_1D(self->arbdmxAlphaPrev__FDK, setup.maxNumInputChannels,
+- FIXP_DBL)
+- FDK_ALLOCATE_MEMORY_2D(self->cmpArbdmxGainIdxPrev, setup.maxNumInputChannels,
+- MAX_PARAMETER_BANDS, SCHAR)
+-
+- FDK_ALLOCATE_MEMORY_2D(self->cmpOttIPDidxPrev, setup.maxNumOttBoxes,
+- MAX_PARAMETER_BANDS, SCHAR)
+-
+- FDK_ALLOCATE_MEMORY_3D_INT(self->M2Real__FDK, setup.maxNumOutputChannels,
+- setup.maxNumVChannels, MAX_PARAMETER_BANDS,
+- FIXP_DBL, SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_3D(self->M2Imag__FDK, setup.maxNumOutputChannels,
+- setup.maxNumVChannels, MAX_PARAMETER_BANDS, FIXP_DBL)
+-
+- FDK_ALLOCATE_MEMORY_3D_INT(self->M2RealPrev__FDK, setup.maxNumOutputChannels,
+- setup.maxNumVChannels, MAX_PARAMETER_BANDS,
+- FIXP_DBL, SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_3D(self->M2ImagPrev__FDK, setup.maxNumOutputChannels,
+- setup.maxNumVChannels, MAX_PARAMETER_BANDS, FIXP_DBL)
+-
+- FDK_ALLOCATE_MEMORY_2D_INT_ALIGNED(
+- self->qmfInputReal__FDK, setup.maxNumInputChannels, setup.maxNumQmfBands,
+- FIXP_DBL, SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_2D_INT_ALIGNED(
+- self->qmfInputImag__FDK, setup.maxNumInputChannels,
+- setup.maxNumCmplxQmfBands, FIXP_DBL, SECT_DATA_L2)
+-
+- FDK_ALLOCATE_MEMORY_2D_INT(self->hybInputReal__FDK, setup.maxNumInputChannels,
+- setup.maxNumHybridBands, FIXP_DBL, SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_2D_INT(self->hybInputImag__FDK, setup.maxNumInputChannels,
+- setup.maxNumCmplxHybBands, FIXP_DBL, SECT_DATA_L2)
+-
+- if (setup.bProcResidual) {
+- FDK_ALLOCATE_MEMORY_1D(self->qmfResidualReal__FDK, setup.maxNumResChannels,
+- FIXP_DBL **)
+- FDK_ALLOCATE_MEMORY_1D(self->qmfResidualImag__FDK, setup.maxNumResChannels,
+- FIXP_DBL **)
+-
+- FDK_ALLOCATE_MEMORY_1D(self->hybResidualReal__FDK, setup.maxNumResChannels,
+- FIXP_DBL *)
+- FDK_ALLOCATE_MEMORY_1D(self->hybResidualImag__FDK, setup.maxNumResChannels,
+- FIXP_DBL *)
+-
+- for (i = 0; i < setup.maxNumResChannels; i++) {
+- int resQmfBands = (config->decoderMode == EXT_LP_ONLY)
+- ? PC_NUM_BANDS
+- : setup.maxNumQmfBands;
+- int resHybBands = (config->decoderMode == EXT_LP_ONLY)
+- ? PC_NUM_HYB_BANDS
+- : setup.maxNumHybridBands;
+- /* Alignment is needed for USAC residuals because QMF analysis directly
+- * writes to this buffer. */
+- FDK_ALLOCATE_MEMORY_2D_INT_ALIGNED(self->qmfResidualReal__FDK[i], (1),
+- resQmfBands, FIXP_DBL, SECT_DATA_L1)
+- FDK_ALLOCATE_MEMORY_2D_INT_ALIGNED(self->qmfResidualImag__FDK[i], (1),
+- resQmfBands, FIXP_DBL, SECT_DATA_L1)
+-
+- FDK_ALLOCATE_MEMORY_1D(self->hybResidualReal__FDK[i],
+- setup.maxNumHybridBands, FIXP_DBL)
+- FDK_ALLOCATE_MEMORY_1D(self->hybResidualImag__FDK[i], resHybBands,
+- FIXP_DBL)
+- }
+- } /* if (setup.bProcResidual) */
+-
+- FDK_ALLOCATE_MEMORY_2D_INT(self->wReal__FDK, setup.maxNumVChannels,
+- setup.maxNumHybridBands, FIXP_DBL, SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_2D_INT(self->wImag__FDK, setup.maxNumVChannels,
+- setup.maxNumCmplxHybBands, FIXP_DBL, SECT_DATA_L2)
+-
+- FDK_ALLOCATE_MEMORY_2D_INT(self->hybOutputRealDry__FDK,
+- setup.maxNumOutputChannels,
+- setup.maxNumHybridBands, FIXP_DBL, SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_2D_INT(self->hybOutputImagDry__FDK,
+- setup.maxNumOutputChannels,
+- setup.maxNumCmplxHybBands, FIXP_DBL, SECT_DATA_L2)
+-
+- FDK_ALLOCATE_MEMORY_2D_INT(self->hybOutputRealWet__FDK,
+- setup.maxNumOutputChannels,
+- setup.maxNumHybridBands, FIXP_DBL, SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_2D_INT(self->hybOutputImagWet__FDK,
+- setup.maxNumOutputChannels,
+- setup.maxNumCmplxHybBands, FIXP_DBL, SECT_DATA_L2)
+-
+- FDK_ALLOCATE_MEMORY_1D(self->hybridSynthesis, setup.maxNumOutputChannels,
+- FDK_SYN_HYB_FILTER)
+-
+- FDK_ALLOCATE_MEMORY_1D(
+- self->hybridAnalysis,
+- setup.bProcResidual ? setup.maxNumInputChannels + setup.maxNumResChannels
+- : setup.maxNumInputChannels,
+- FDK_ANA_HYB_FILTER)
+-
+- lfSize = 2 * BUFFER_LEN_LF * MAX_QMF_BANDS_TO_HYBRID;
+- {
+- hfSize =
+- BUFFER_LEN_HF * ((setup.maxNumQmfBands - MAX_QMF_BANDS_TO_HYBRID) +
+- (setup.maxNumCmplxQmfBands - MAX_QMF_BANDS_TO_HYBRID));
+- }
+-
+- FDK_ALLOCATE_MEMORY_2D_INT(self->pHybridAnaStatesLFdmx,
+- setup.maxNumInputChannels, lfSize, FIXP_DBL,
+- SECT_DATA_L2) {
+- FDK_ALLOCATE_MEMORY_2D(self->pHybridAnaStatesHFdmx,
+- setup.maxNumInputChannels, hfSize, FIXP_DBL)
+- }
+-
+- for (i = 0; i < setup.maxNumInputChannels; i++) {
+- FIXP_DBL *pHybridAnaStatesHFdmx;
+-
+- pHybridAnaStatesHFdmx = self->pHybridAnaStatesHFdmx[i];
+-
+- FDKhybridAnalysisOpen(&self->hybridAnalysis[i],
+- self->pHybridAnaStatesLFdmx[i],
+- lfSize * sizeof(FIXP_DBL), pHybridAnaStatesHFdmx,
+- hfSize * sizeof(FIXP_DBL));
+- }
+- if (setup.bProcResidual) {
+- lfSize = 2 * BUFFER_LEN_LF * MAX_QMF_BANDS_TO_HYBRID;
+- hfSize = BUFFER_LEN_HF *
+- ((((config->decoderMode == EXT_LP_ONLY) ? PC_NUM_BANDS
+- : setup.maxNumQmfBands) -
+- MAX_QMF_BANDS_TO_HYBRID) +
+- (setup.maxNumCmplxQmfBands - MAX_QMF_BANDS_TO_HYBRID));
+-
+- FDK_ALLOCATE_MEMORY_2D_INT(self->pHybridAnaStatesLFres,
+- setup.maxNumResChannels, lfSize, FIXP_DBL,
+- SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_2D(self->pHybridAnaStatesHFres, setup.maxNumResChannels,
+- hfSize, FIXP_DBL)
+-
+- for (i = setup.maxNumInputChannels;
+- i < (setup.maxNumInputChannels + setup.maxNumResChannels); i++) {
+- FDKhybridAnalysisOpen(
+- &self->hybridAnalysis[i],
+- self->pHybridAnaStatesLFres[i - setup.maxNumInputChannels],
+- lfSize * sizeof(FIXP_DBL),
+- self->pHybridAnaStatesHFres[i - setup.maxNumInputChannels],
+- hfSize * sizeof(FIXP_DBL));
+- }
+- }
+-
+- FDK_ALLOCATE_MEMORY_1D(self->smoothState, 1, SMOOTHING_STATE)
+- FDK_ALLOCATE_MEMORY_1D(self->reshapeBBEnvState, 1, RESHAPE_BBENV_STATE)
+-
+- FDK_ALLOCATE_MEMORY_1D(self->apDecor, setup.maxNumDecorChannels, DECORR_DEC)
+- FDK_ALLOCATE_MEMORY_2D_INT(self->pDecorBufferCplx, setup.maxNumDecorChannels,
+- (2 * ((825) + (373))), FIXP_DBL, SECT_DATA_L2)
+-
+- for (i = 0; i < setup.maxNumDecorChannels; i++) {
+- if (FDKdecorrelateOpen(&self->apDecor[i], self->pDecorBufferCplx[i],
+- (2 * ((825) + (373))))) {
+- goto bail;
+- }
+- }
+-
+- if (subbandTPCreate(&self->hStpDec) != MPS_OK) {
+- goto bail;
+- }
+-
+- /* save general decoder configuration */
+- self->decoderLevel = config->decoderLevel;
+- self->decoderMode = config->decoderMode;
+- self->binauralMode = config->binauralMode;
+-
+- /* preinitialize configuration */
+- self->partiallyComplex = (config->decoderMode != EXT_HQ_ONLY) ? 1 : 0;
+-
+- /* Set to default state */
+- SpatialDecConcealment_Init(&self->concealInfo, MPEGS_CONCEAL_RESET_ALL);
+-
+- /* Everything is fine so return the handle */
+- return self;
+-
+-bail:
+- /* Collector for all errors.
+- Deallocate all memory and return a invalid handle. */
+- FDK_SpatialDecClose(self);
+-
+- return NULL;
+-}
+-
+-/*******************************************************************************
+- Functionname: isValidConfig
+- *******************************************************************************
+-
+- Description: Validate if configuration is supported in present instance
+-
+- Arguments:
+-
+- Return: 1: all okay
+- 0: configuration not supported
+-*******************************************************************************/
+-static int isValidConfig(spatialDec const *const self,
+- const SPATIAL_DEC_UPMIX_TYPE upmixType,
+- SPATIALDEC_PARAM const *const pUserParams,
+- const AUDIO_OBJECT_TYPE coreAot) {
+- UPMIXTYPE nUpmixType;
+-
+- FDK_ASSERT(self != NULL);
+- FDK_ASSERT(pUserParams != NULL);
+-
+- nUpmixType = (UPMIXTYPE)upmixType;
+-
+- switch (nUpmixType) {
+- case UPMIXTYPE_BYPASS: /* UPMIX_TYPE_BYPASS */
+- break;
+- case UPMIXTYPE_NORMAL: /* UPMIX_TYPE_NORMAL */
+- break;
+- default:
+- return 0; /* unsupported upmixType */
+- }
+-
+- return 1; /* upmixType supported */
+-}
+-
+-static SACDEC_ERROR CheckLevelTreeUpmixType(
+- const SACDEC_CREATION_PARAMS *const pCreateParams,
+- const SPATIAL_SPECIFIC_CONFIG *const pSsc, const int decoderLevel,
+- const UPMIXTYPE upmixType) {
+- SACDEC_ERROR err = MPS_OK;
+- int nOutputChannels, treeConfig;
+-
+- FDK_ASSERT(pCreateParams != NULL);
+- FDK_ASSERT(pSsc != NULL);
+-
+- treeConfig = pSsc->treeConfig;
+-
+- switch (decoderLevel) {
+- case 0: {
+- if (treeConfig != SPATIALDEC_MODE_RSVD7) {
+- err = MPS_INVALID_TREECONFIG;
+- goto bail;
+- }
+- break;
+- }
+- default:
+- err = MPS_INVALID_PARAMETER /* MPS_UNIMPLEMENTED */;
+- goto bail;
+- }
+-
+- switch (upmixType) {
+- case UPMIXTYPE_BYPASS:
+- nOutputChannels = pSsc->nInputChannels;
+- break;
+- default:
+- nOutputChannels = pSsc->nOutputChannels;
+- break;
+- }
+-
+- /* Is sufficient memory allocated. */
+- if ((pSsc->nInputChannels > pCreateParams->maxNumInputChannels) ||
+- (nOutputChannels > pCreateParams->maxNumOutputChannels) ||
+- (pSsc->nOttBoxes > pCreateParams->maxNumOttBoxes)) {
+- err = MPS_INVALID_PARAMETER;
+- }
+-
+-bail:
+- return err;
+-}
+-
+-void SpatialDecInitParserContext(spatialDec *self) {
+- int i, j;
+-
+- for (i = 0; i < self->createParams.maxNumOttBoxes; i += 1) {
+- for (j = 0; j < MAX_PARAMETER_BANDS; j++) {
+- self->ottCLDidxPrev[i][j] = 0;
+- self->ottICCidxPrev[i][j] = 0;
+- self->cmpOttCLDidxPrev[i][j] = 0;
+- self->cmpOttICCidxPrev[i][j] = 0;
+- }
+- }
+- for (i = 0; i < self->createParams.maxNumInputChannels; i++) {
+- for (j = 0; j < MAX_PARAMETER_BANDS; j++) {
+- self->arbdmxGainIdxPrev[i][j] = 0;
+- self->cmpArbdmxGainIdxPrev[i][j] = 0;
+- }
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: FDK_SpatialDecInit
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-
+-SACDEC_ERROR FDK_SpatialDecInit(spatialDec *self, SPATIAL_BS_FRAME *frame,
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig,
+- int nQmfBands,
+- SPATIAL_DEC_UPMIX_TYPE const upmixType,
+- SPATIALDEC_PARAM *pUserParams, UINT initFlags) {
+- SACDEC_ERROR err = MPS_OK;
+- int nCh, i, j, k;
+- int maxQmfBands;
+- int bypassMode = 0;
+-
+- self->useFDreverb = 0;
+-
+- /* check configuration parameter */
+- if (!isValidConfig(self, upmixType, pUserParams,
+- pSpatialSpecificConfig->coreCodec)) {
+- return MPS_INVALID_PARAMETER;
+- }
+-
+- /* check tree configuration */
+- err = CheckLevelTreeUpmixType(&self->createParams, pSpatialSpecificConfig,
+- self->decoderLevel, (UPMIXTYPE)upmixType);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+-
+- /* Store and update instance after all checks passed successfully: */
+- self->upmixType = (UPMIXTYPE)upmixType;
+-
+- if (initFlags & MPEGS_INIT_PARAMS_ERROR_CONCEALMENT) { /* At least one error
+- concealment
+- parameter changed */
+- err = SpatialDecConcealment_SetParam(
+- &self->concealInfo, SAC_DEC_CONCEAL_METHOD, pUserParams->concealMethod);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- err = SpatialDecConcealment_SetParam(&self->concealInfo,
+- SAC_DEC_CONCEAL_NUM_KEEP_FRAMES,
+- pUserParams->concealNumKeepFrames);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- err = SpatialDecConcealment_SetParam(
+- &self->concealInfo, SAC_DEC_CONCEAL_FADE_OUT_SLOPE_LENGTH,
+- pUserParams->concealFadeOutSlopeLength);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- err = SpatialDecConcealment_SetParam(&self->concealInfo,
+- SAC_DEC_CONCEAL_FADE_IN_SLOPE_LENGTH,
+- pUserParams->concealFadeInSlopeLength);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- err = SpatialDecConcealment_SetParam(&self->concealInfo,
+- SAC_DEC_CONCEAL_NUM_RELEASE_FRAMES,
+- pUserParams->concealNumReleaseFrames);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- }
+-
+- if (initFlags &
+- MPEGS_INIT_STATES_ERROR_CONCEALMENT) { /* Set to default state */
+- SpatialDecConcealment_Init(&self->concealInfo, MPEGS_CONCEAL_RESET_STATE);
+- }
+-
+- /* determine bypass mode */
+- bypassMode |= pUserParams->bypassMode;
+- bypassMode |= ((self->upmixType == UPMIXTYPE_BYPASS) ? 1 : 0);
+-
+- /* static decoder scale depends on number of qmf bands */
+- switch (nQmfBands) {
+- case 16:
+- case 24:
+- case 32:
+- self->staticDecScale = 21;
+- break;
+- case 64:
+- self->staticDecScale = 22;
+- break;
+- default:
+- return MPS_INVALID_PARAMETER;
+- }
+-
+- self->numParameterSetsPrev = 1;
+-
+- self->qmfBands = nQmfBands;
+- /* self->hybridBands will be updated in SpatialDecDecodeHeader() below. */
+-
+- self->bShareDelayWithSBR = 0;
+-
+- err = SpatialDecDecodeHeader(self, pSpatialSpecificConfig);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+-
+- self->stereoConfigIndex = pSpatialSpecificConfig->stereoConfigIndex;
+-
+- if (initFlags & MPEGS_INIT_STATES_ANA_QMF_FILTER) {
+- self->qmfInputDelayBufPos = 0;
+- self->pc_filterdelay = 1; /* Division by 0 not possible */
+- }
+-
+- maxQmfBands = self->qmfBands;
+-
+- /* init residual decoder */
+-
+- /* init tonality smoothing */
+- if (initFlags & MPEGS_INIT_STATES_PARAM) {
+- initParameterSmoothing(self);
+- }
+-
+- /* init GES */
+- initBBEnv(self, (initFlags & MPEGS_INIT_STATES_GES) ? 1 : 0);
+-
+- /* Clip protection is applied only for normal processing. */
+- if (!isTwoChMode(self->upmixType) && !bypassMode) {
+- self->staticDecScale += self->clipProtectGainSF__FDK;
+- }
+-
+- {
+- UINT flags = 0;
+- INT initStatesFlag = (initFlags & MPEGS_INIT_STATES_ANA_QMF_FILTER) ? 1 : 0;
+- INT useLdFilter =
+- (self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_LD) ? 1 : 0;
+-
+- flags = self->pQmfDomain->globalConf.flags_requested;
+- flags &= (~(UINT)QMF_FLAG_LP);
+-
+- if (initStatesFlag)
+- flags &= ~QMF_FLAG_KEEP_STATES;
+- else
+- flags |= QMF_FLAG_KEEP_STATES;
+-
+- if (useLdFilter)
+- flags |= QMF_FLAG_MPSLDFB;
+- else
+- flags &= ~QMF_FLAG_MPSLDFB;
+-
+- self->pQmfDomain->globalConf.flags_requested = flags;
+- FDK_QmfDomain_Configure(self->pQmfDomain);
+-
+- /* output scaling */
+- for (nCh = 0; nCh < self->numOutputChannelsAT; nCh++) {
+- int outputScale = 0, outputGain_e = 0, scale = 0;
+- FIXP_DBL outputGain_m = getChGain(self, nCh, &outputGain_e);
+-
+- if (!isTwoChMode(self->upmixType) && !bypassMode) {
+- outputScale +=
+- self->clipProtectGainSF__FDK; /* consider clip protection scaling at
+- synthesis qmf */
+- }
+-
+- scale = outputScale;
+-
+- qmfChangeOutScalefactor(&self->pQmfDomain->QmfDomainOut[nCh].fb, scale);
+- qmfChangeOutGain(&self->pQmfDomain->QmfDomainOut[nCh].fb, outputGain_m,
+- outputGain_e);
+- }
+- }
+-
+- for (nCh = 0; nCh < self->numOutputChannelsAT; nCh++) {
+- FDKhybridSynthesisInit(&self->hybridSynthesis[nCh], THREE_TO_TEN,
+- self->qmfBands, maxQmfBands);
+- }
+-
+- /* for input, residual channels and arbitrary down-mix residual channels */
+- for (nCh = 0; nCh < self->createParams.maxNumInputChannels; nCh++) {
+- FDKhybridAnalysisInit(
+- &self->hybridAnalysis[nCh], THREE_TO_TEN, self->qmfBands, maxQmfBands,
+- (initFlags & MPEGS_INIT_STATES_ANA_HYB_FILTER) ? 1 : 0);
+- }
+- for (; nCh < (self->createParams.bProcResidual
+- ? (self->createParams.maxNumInputChannels +
+- self->createParams.maxNumResChannels)
+- : self->createParams.maxNumInputChannels);
+- nCh++) {
+- FDKhybridAnalysisInit(&self->hybridAnalysis[nCh], THREE_TO_TEN, maxQmfBands,
+- maxQmfBands, 0);
+- }
+-
+- {
+- for (k = 0; k < self->numDecorSignals; k++) {
+- int errCode, idec;
+- FDK_DECORR_TYPE decorrType = DECORR_PS;
+- decorrType = DECORR_LD;
+- if (self->pConfigCurrent->syntaxFlags &
+- (SACDEC_SYNTAX_USAC | SACDEC_SYNTAX_RSVD50)) {
+- decorrType =
+- ((self->treeConfig == TREE_212) && (self->decorrType == DECORR_PS))
+- ? DECORR_PS
+- : DECORR_USAC;
+- }
+- {
+- idec = k;
+- if (self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_LD) {
+- if (self->treeConfig == TREE_212 && k == 0) {
+- idec = 2;
+- }
+- }
+- }
+- errCode = FDKdecorrelateInit(
+- &self->apDecor[k], self->hybridBands, decorrType, DUCKER_AUTOMATIC,
+- self->decorrConfig, idec, 0, /* self->partiallyComplex */
+- 0, 0, /* isLegacyPS */
+- (initFlags & MPEGS_INIT_STATES_DECORRELATOR) ? 1 : 0);
+- if (errCode) return MPS_NOTOK;
+- }
+- } /* !self->partiallyComplex */
+-
+- err = initM1andM2(self, (initFlags & MPEGS_INIT_STATES_M1M2) ? 1 : 0,
+- (initFlags & MPEGS_INIT_CONFIG) ? 1 : 0);
+- if (err != MPS_OK) return err;
+-
+- /* Initialization of previous frame data */
+- if (initFlags & MPEGS_INIT_STATES_PARAM) {
+- for (i = 0; i < self->createParams.maxNumOttBoxes; i += 1) {
+- /* reset icc diff data */
+- for (k = 0; k < MAX_PARAMETER_SETS; k += 1) {
+- for (j = 0; j < MAX_PARAMETER_BANDS; j += 1) {
+- self->ottICCdiffidx[i][k][j] = 0;
+- }
+- }
+- }
+- /* Parameter Smoothing */
+- /* robustness: init with one of the values of smgTimeTable[] = {64, 128,
+- 256, 512} to avoid division by zero in calcFilterCoeff__FDK() */
+- self->smoothState->prevSmgTime = smgTimeTable[2]; /* == 256 */
+- FDKmemclear(self->smoothState->prevSmgData,
+- MAX_PARAMETER_BANDS * sizeof(UCHAR));
+- FDKmemclear(self->smoothState->opdLeftState__FDK,
+- MAX_PARAMETER_BANDS * sizeof(FIXP_DBL));
+- FDKmemclear(self->smoothState->opdRightState__FDK,
+- MAX_PARAMETER_BANDS * sizeof(FIXP_DBL));
+- }
+-
+- self->prevTimeSlot = -1;
+- self->curTimeSlot =
+- MAX_TIME_SLOTS + 1; /* Initialize with a invalid value to trigger
+- concealment if first frame has no valid data. */
+- self->curPs = 0;
+-
+- subbandTPInit(self->hStpDec);
+-
+-bail:
+- return err;
+-}
+-
+-void SpatialDecChannelProperties(spatialDec *self,
+- AUDIO_CHANNEL_TYPE channelType[],
+- UCHAR channelIndices[],
+- const FDK_channelMapDescr *const mapDescr) {
+- if ((self == NULL) || (channelType == NULL) || (channelIndices == NULL) ||
+- (mapDescr == NULL)) {
+- return; /* no extern buffer to be filled */
+- }
+-
+- if (self->numOutputChannelsAT !=
+- treePropertyTable[self->treeConfig].numOutputChannels) {
+- int ch;
+- /* Declare all channels to be front channels: */
+- for (ch = 0; ch < self->numOutputChannelsAT; ch += 1) {
+- channelType[ch] = ACT_FRONT;
+- channelIndices[ch] = ch;
+- }
+- } else {
+- /* ISO/IEC FDIS 23003-1:2006(E), page 46, Table 40 bsTreeConfig */
+- switch (self->treeConfig) {
+- case TREE_212:
+- channelType[0] = ACT_FRONT;
+- channelIndices[0] = 0;
+- channelType[1] = ACT_FRONT;
+- channelIndices[1] = 1;
+- break;
+- default:;
+- }
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: FDK_SpatialDecClose
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-
+-void FDK_SpatialDecClose(spatialDec *self) {
+- if (self) {
+- int k;
+-
+- if (self->apDecor != NULL) {
+- for (k = 0; k < self->createParams.maxNumDecorChannels; k++) {
+- FDKdecorrelateClose(&(self->apDecor[k]));
+- }
+- FDK_FREE_MEMORY_1D(self->apDecor);
+- }
+- if (self->pDecorBufferCplx != NULL) {
+- FDK_FREE_MEMORY_2D(self->pDecorBufferCplx);
+- }
+-
+- subbandTPDestroy(&self->hStpDec);
+-
+- FDK_FREE_MEMORY_1D(self->reshapeBBEnvState);
+- FDK_FREE_MEMORY_1D(self->smoothState);
+-
+- FDK_FREE_MEMORY_2D(self->pHybridAnaStatesLFdmx);
+- FDK_FREE_MEMORY_2D(self->pHybridAnaStatesHFdmx);
+- FDK_FREE_MEMORY_2D(self->pHybridAnaStatesLFres);
+- FDK_FREE_MEMORY_2D(self->pHybridAnaStatesHFres);
+- FDK_FREE_MEMORY_1D(self->hybridAnalysis);
+-
+- FDK_FREE_MEMORY_1D(self->hybridSynthesis);
+-
+- /* The time buffer is passed to the decoder from outside to avoid copying
+- * (zero copy). */
+- /* FDK_FREE_MEMORY_2D(self->timeOut__FDK); */
+-
+- FDK_FREE_MEMORY_2D(self->hybOutputImagWet__FDK);
+- FDK_FREE_MEMORY_2D(self->hybOutputRealWet__FDK);
+-
+- FDK_FREE_MEMORY_2D(self->hybOutputImagDry__FDK);
+- FDK_FREE_MEMORY_2D(self->hybOutputRealDry__FDK);
+-
+- FDK_FREE_MEMORY_2D(self->wImag__FDK);
+- FDK_FREE_MEMORY_2D(self->wReal__FDK);
+-
+- if (self->createParams.bProcResidual) {
+- int i;
+-
+- for (i = 0; i < self->createParams.maxNumResChannels; i++) {
+- if (self->hybResidualImag__FDK != NULL)
+- FDK_FREE_MEMORY_1D(self->hybResidualImag__FDK[i]);
+- if (self->hybResidualReal__FDK != NULL)
+- FDK_FREE_MEMORY_1D(self->hybResidualReal__FDK[i]);
+- if (self->qmfResidualImag__FDK != NULL)
+- FDK_FREE_MEMORY_2D_ALIGNED(self->qmfResidualImag__FDK[i]);
+- if (self->qmfResidualReal__FDK != NULL)
+- FDK_FREE_MEMORY_2D_ALIGNED(self->qmfResidualReal__FDK[i]);
+- }
+-
+- FDK_FREE_MEMORY_1D(self->hybResidualImag__FDK);
+- FDK_FREE_MEMORY_1D(self->hybResidualReal__FDK);
+-
+- FDK_FREE_MEMORY_1D(self->qmfResidualImag__FDK);
+- FDK_FREE_MEMORY_1D(self->qmfResidualReal__FDK);
+-
+- } /* self->createParams.bProcResidual */
+-
+- FDK_FREE_MEMORY_2D(self->hybInputImag__FDK);
+- FDK_FREE_MEMORY_2D(self->hybInputReal__FDK);
+-
+- FDK_FREE_MEMORY_2D_ALIGNED(self->qmfInputImag__FDK);
+- FDK_FREE_MEMORY_2D_ALIGNED(self->qmfInputReal__FDK);
+-
+- FDK_FREE_MEMORY_3D(self->M2ImagPrev__FDK);
+-
+- FDK_FREE_MEMORY_3D(self->M2RealPrev__FDK);
+-
+- FDK_FREE_MEMORY_3D(self->M2Imag__FDK);
+-
+- FDK_FREE_MEMORY_3D(self->M2Real__FDK);
+-
+- FDK_FREE_MEMORY_1D(self->arbdmxAlphaPrev__FDK);
+- FDK_FREE_MEMORY_1D(self->arbdmxAlpha__FDK);
+-
+- FDK_FREE_MEMORY_3D(self->arbdmxGain__FDK);
+-
+- FDK_FREE_MEMORY_3D(self->ottIPD__FDK);
+- FDK_FREE_MEMORY_3D(self->ottICC__FDK);
+- FDK_FREE_MEMORY_3D(self->ottCLD__FDK);
+-
+- /* Last parameters from prev frame */
+- FDK_FREE_MEMORY_2D(self->ottCLDidxPrev);
+- FDK_FREE_MEMORY_2D(self->ottICCidxPrev);
+- FDK_FREE_MEMORY_3D(self->ottICCdiffidx);
+- FDK_FREE_MEMORY_2D(self->ottIPDidxPrev);
+- FDK_FREE_MEMORY_2D(self->arbdmxGainIdxPrev);
+-
+- FDK_FREE_MEMORY_2D(self->cmpOttCLDidxPrev);
+- FDK_FREE_MEMORY_2D(self->cmpOttICCidxPrev);
+- FDK_FREE_MEMORY_3D(self->outIdxData);
+- FDK_FREE_MEMORY_2D(self->cmpOttIPDidxPrev);
+- FDK_FREE_MEMORY_2D(self->cmpArbdmxGainIdxPrev);
+-
+- FDK_FREE_MEMORY_2D(self->smgData);
+- FDK_FREE_MEMORY_1D(self->smgTime);
+-
+- FDK_FREE_MEMORY_1D(self->numOttBands);
+-
+- FDK_FREE_MEMORY_1D(self->param2hyb);
+-
+- FDK_FREE_MEMORY_1D(self);
+- }
+-
+- return;
+-}
+-
+-/**
+- * \brief Apply Surround bypass buffer copies
+- * \param self spatialDec handle
+- * \param hybInputReal
+- * \param hybInputImag
+- * \param hybOutputReal
+- * \param hybOutputImag
+- * \param numInputChannels amount if input channels available in hybInputReal
+- * and hybInputImag, which may differ from self->numInputChannels.
+- */
+-static void SpatialDecApplyBypass(spatialDec *self, FIXP_DBL **hybInputReal,
+- FIXP_DBL **hybInputImag,
+- FIXP_DBL **hybOutputReal,
+- FIXP_DBL **hybOutputImag,
+- const int numInputChannels) {
+- int complexHybBands;
+-
+- complexHybBands = self->hybridBands;
+-
+- {
+- int ch;
+- int rf = -1, lf = -1, cf = -1; /* Right Front, Left Front, Center Front */
+-
+- /* Determine output channel indices according to tree config */
+- switch (self->treeConfig) {
+- case TREE_212: /* 212 */
+- lf = 0;
+- rf = 1;
+- break;
+- default:;
+- }
+-
+- /* Note: numInputChannels might not match the tree config ! */
+- switch (numInputChannels) {
+- case 1:
+- if (cf > 0) {
+- FDKmemcpy(hybOutputReal[cf], hybInputReal[0],
+- self->hybridBands * sizeof(FIXP_DBL));
+- FDKmemcpy(hybOutputImag[cf], hybInputImag[0],
+- complexHybBands * sizeof(FIXP_DBL));
+- } else {
+- FDKmemcpy(hybOutputReal[lf], hybInputReal[0],
+- self->hybridBands * sizeof(FIXP_DBL));
+- FDKmemcpy(hybOutputReal[rf], hybInputReal[0],
+- self->hybridBands * sizeof(FIXP_DBL));
+- FDKmemcpy(hybOutputImag[lf], hybInputImag[0],
+- complexHybBands * sizeof(FIXP_DBL));
+- FDKmemcpy(hybOutputImag[rf], hybInputImag[0],
+- complexHybBands * sizeof(FIXP_DBL));
+- }
+- break;
+- case 2:
+- FDK_ASSERT(lf != -1);
+- FDK_ASSERT(rf != -1);
+- FDKmemcpy(hybOutputReal[lf], hybInputReal[0],
+- self->hybridBands * sizeof(FIXP_DBL));
+- FDKmemcpy(hybOutputReal[rf], hybInputReal[1],
+- self->hybridBands * sizeof(FIXP_DBL));
+- FDKmemcpy(hybOutputImag[lf], hybInputImag[0],
+- complexHybBands * sizeof(FIXP_DBL));
+- FDKmemcpy(hybOutputImag[rf], hybInputImag[1],
+- complexHybBands * sizeof(FIXP_DBL));
+- break;
+- }
+- for (ch = 0; ch < self->numOutputChannelsAT; ch++) {
+- if (ch == lf || ch == rf || ch == cf) {
+- continue; /* Skip bypassed channels */
+- }
+- FDKmemclear(hybOutputReal[ch], self->hybridBands * sizeof(FIXP_DBL));
+- FDKmemclear(hybOutputImag[ch], complexHybBands * sizeof(FIXP_DBL));
+- }
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: SpatialDecApplyParameterSets
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Return:
+-
+-*******************************************************************************/
+-static SACDEC_ERROR SpatialDecApplyParameterSets(
+- spatialDec *self, const SPATIAL_BS_FRAME *frame, SPATIALDEC_INPUT_MODE mode,
+- PCM_MPS *inData, /* Time domain input */
+- FIXP_DBL **qmfInDataReal, /* QMF domain data l/r */
+- FIXP_DBL **qmfInDataImag, /* QMF domain data l/r */
+- UINT nSamples, UINT controlFlags, int numInputChannels,
+- const FDK_channelMapDescr *const mapDescr) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- FIXP_SGL alpha;
+-
+- int ts;
+- int ch;
+- int hyb;
+-
+- int prevSlot = self->prevTimeSlot;
+- int ps = self->curPs;
+- int ts_io = 0; /* i/o dependent slot */
+- int bypassMode = (controlFlags & MPEGS_BYPASSMODE) ? 1 : 0;
+-
+- /* Bypass can be triggered by the upmixType, too. */
+- bypassMode |= ((self->upmixType == UPMIXTYPE_BYPASS) ? 1 : 0);
+-
+- /*
+- * Decode available slots
+- */
+- for (ts = self->curTimeSlot;
+- ts <= fixMin(self->curTimeSlot + (int)nSamples / self->qmfBands - 1,
+- self->timeSlots - 1);
+- ts++, ts_io++) {
+- int currSlot = frame->paramSlot[ps];
+-
+- /*
+- * Get new parameter set
+- */
+- if (ts == prevSlot + 1) {
+- err = SpatialDecCalculateM1andM2(self, ps,
+- frame); /* input: ottCLD, ottICC, ... */
+- /* output: M1param(Real/Imag), M2(Real/Imag) */
+- if (err != MPS_OK) {
+- bypassMode = 1;
+- if (self->errInt == MPS_OK) {
+- /* store internal error befor it gets overwritten */
+- self->errInt = err;
+- }
+- err = MPS_OK;
+- }
+-
+- if ((ps == 0) && (self->bOverwriteM1M2prev != 0)) {
+- /* copy matrix entries of M1/M2 of the first parameter set to the
+- previous matrices (of the last frame). This avoids the interpolation
+- of incompatible values. E.g. for residual bands the coefficients are
+- calculated differently compared to non-residual bands.
+- */
+- SpatialDecBufferMatrices(self); /* input: M(1/2)param(Real/Imag) */
+- /* output: M(1/2)param(Real/Imag)Prev */
+- self->bOverwriteM1M2prev = 0;
+- }
+-
+- SpatialDecSmoothM1andM2(
+- self, frame,
+- ps); /* input: M1param(Real/Imag)(Prev), M2(Real/Imag)(Prev) */
+- /* output: M1param(Real/Imag), M2(Real/Imag) */
+- }
+-
+- alpha = FX_DBL2FX_SGL(fDivNorm(ts - prevSlot, currSlot - prevSlot));
+-
+- switch (mode) {
+- case INPUTMODE_QMF_SBR:
+- if (self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_LD)
+- self->bShareDelayWithSBR = 0; /* We got no hybrid delay */
+- else
+- self->bShareDelayWithSBR = 1;
+- SpatialDecFeedQMF(self, qmfInDataReal, qmfInDataImag, ts_io, bypassMode,
+- self->qmfInputReal__FDK, self->qmfInputImag__FDK,
+- self->numInputChannels);
+- break;
+- case INPUTMODE_TIME:
+- self->bShareDelayWithSBR = 0;
+- SpatialDecQMFAnalysis(self, inData, ts_io, bypassMode,
+- self->qmfInputReal__FDK, self->qmfInputImag__FDK,
+- self->numInputChannels);
+- break;
+- default:
+- break;
+- }
+-
+- if ((self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_USAC) &&
+- self->residualCoding) {
+- int offset;
+- ch = 1;
+-
+- offset = self->pQmfDomain->globalConf.nBandsSynthesis *
+- self->pQmfDomain->globalConf.nQmfTimeSlots;
+-
+- {
+- const PCM_MPS *inSamples =
+- &inData[ts * self->pQmfDomain->globalConf.nBandsAnalysis];
+-
+- CalculateSpaceAnalysisQmf(
+- &self->pQmfDomain->QmfDomainIn[ch].fb, inSamples + (ch * offset),
+- self->qmfResidualReal__FDK[0][0], self->qmfResidualImag__FDK[0][0]);
+-
+- if (!isTwoChMode(self->upmixType) && !bypassMode) {
+- int i;
+- FIXP_DBL *RESTRICT self_qmfResidualReal__FDK_0_0 =
+- &self->qmfResidualReal__FDK[0][0][0];
+- FIXP_DBL *RESTRICT self_qmfResidualImag__FDK_0_0 =
+- &self->qmfResidualImag__FDK[0][0][0];
+-
+- if ((self->pQmfDomain->globalConf.nBandsAnalysis == 24) &&
+- !(self->stereoConfigIndex == 3)) {
+- for (i = 0; i < self->qmfBands; i++) {
+- self_qmfResidualReal__FDK_0_0[i] =
+- fMult(self_qmfResidualReal__FDK_0_0[i] << 1,
+- self->clipProtectGain__FDK);
+- self_qmfResidualImag__FDK_0_0[i] =
+- fMult(self_qmfResidualImag__FDK_0_0[i] << 1,
+- self->clipProtectGain__FDK);
+- }
+- } else {
+- for (i = 0; i < self->qmfBands; i++) {
+- self_qmfResidualReal__FDK_0_0[i] = fMult(
+- self_qmfResidualReal__FDK_0_0[i], self->clipProtectGain__FDK);
+- self_qmfResidualImag__FDK_0_0[i] = fMult(
+- self_qmfResidualImag__FDK_0_0[i], self->clipProtectGain__FDK);
+- }
+- }
+- }
+- }
+- }
+-
+- SpatialDecHybridAnalysis(
+- self, /* input: qmfInput(Real/Imag), qmfResidual(Real/Imag) */
+- self->qmfInputReal__FDK, self->qmfInputImag__FDK,
+- self->hybInputReal__FDK, self->hybInputImag__FDK, ts, numInputChannels);
+-
+- if (bypassMode) {
+- SpatialDecApplyBypass(
+- self, self->hybInputReal__FDK, /* input: hybInput(Real/Imag) */
+- self->hybInputImag__FDK,
+- self->hybOutputRealDry__FDK, /* output: hybOutput(Real/Imag)Dry */
+- self->hybOutputImagDry__FDK, numInputChannels);
+- } else /* !bypassMode */
+- {
+- FIXP_DBL *pxReal[MAX_NUM_XCHANNELS] = {NULL};
+- FIXP_DBL *pxImag[MAX_NUM_XCHANNELS] = {NULL};
+-
+- SpatialDecCreateX(self,
+- self->hybInputReal__FDK, /* input: hybInput(Real/Imag),
+- hybResidual(Real/Imag) */
+- self->hybInputImag__FDK, pxReal, pxImag);
+-
+- {
+- SpatialDecApplyM1_CreateW_Mode212(
+- self, frame, pxReal, pxImag,
+- self->wReal__FDK, /* output: w(Real/Imag) */
+- self->wImag__FDK);
+- }
+- if (err != MPS_OK) goto bail;
+-
+- int applyM2Config = APPLY_M2_NONE;
+-
+- applyM2Config = APPLY_M2;
+- if ((self->pConfigCurrent->syntaxFlags &
+- (SACDEC_SYNTAX_USAC | SACDEC_SYNTAX_RSVD50)) &&
+- (self->tempShapeConfig != 1) && (self->tempShapeConfig != 2)) {
+- if (self->phaseCoding == 3)
+- applyM2Config = APPLY_M2_MODE212_Res_PhaseCoding;
+- else
+- applyM2Config = APPLY_M2_MODE212;
+- }
+-
+- switch (applyM2Config) {
+- case APPLY_M2_MODE212: {
+- err = SpatialDecApplyM2_Mode212(
+- self, ps, alpha, self->wReal__FDK, self->wImag__FDK,
+- self->hybOutputRealDry__FDK, self->hybOutputImagDry__FDK);
+- } break;
+- case APPLY_M2_MODE212_Res_PhaseCoding:
+- err = SpatialDecApplyM2_Mode212_ResidualsPlusPhaseCoding(
+- self, ps, alpha, self->wReal__FDK, self->wImag__FDK,
+- self->hybOutputRealDry__FDK, self->hybOutputImagDry__FDK);
+- break;
+- case APPLY_M2:
+- err = SpatialDecApplyM2(
+- self, ps, alpha, self->wReal__FDK, self->wImag__FDK,
+- self->hybOutputRealDry__FDK, self->hybOutputImagDry__FDK,
+- self->hybOutputRealWet__FDK, self->hybOutputImagWet__FDK);
+- break;
+- default:
+- err = MPS_APPLY_M2_ERROR;
+- goto bail;
+- }
+-
+- if (err != MPS_OK) goto bail;
+-
+- if ((self->tempShapeConfig == 2) && (!isTwoChMode(self->upmixType))) {
+- SpatialDecReshapeBBEnv(self, frame,
+- ts); /* input: reshapeBBEnvState,
+- hybOutput(Real/Imag)(Dry/Wet),
+- hybInput(Real/Imag) */
+- } /* output: hybOutput(Real/Imag)Dry */
+-
+- /* Merge parts of the dry and wet QMF buffers. */
+- if ((self->tempShapeConfig == 1) && (!isTwoChMode(self->upmixType))) {
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- for (hyb = 0; hyb < self->tp_hybBandBorder; hyb++) {
+- self->hybOutputRealDry__FDK[ch][hyb] +=
+- self->hybOutputRealWet__FDK[ch][hyb];
+- self->hybOutputImagDry__FDK[ch][hyb] +=
+- self->hybOutputImagWet__FDK[ch][hyb];
+- } /* loop hyb */
+- } /* loop ch */
+- err = subbandTPApply(
+- self, frame); /* input: hStpDec, hybOutput(Real/Imag)Dry/Wet */
+- /* output: hStpDec, hybOutput(Real/Imag)Dry */
+- if (err != MPS_OK) goto bail;
+- } /* (self->tempShapeConfig == 1) */
+- else {
+- /* The wet signal is added to the dry signal in applyM2 if GES and STP
+- * are disabled */
+- if ((self->tempShapeConfig == 1) || (self->tempShapeConfig == 2)) {
+- int nHybBands;
+- nHybBands = self->hybridBands;
+-
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- FIXP_DBL *RESTRICT pRealDry = self->hybOutputRealDry__FDK[ch];
+- FIXP_DBL *RESTRICT pImagDry = self->hybOutputImagDry__FDK[ch];
+- FIXP_DBL *RESTRICT pRealWet = self->hybOutputRealWet__FDK[ch];
+- FIXP_DBL *RESTRICT pImagWet = self->hybOutputImagWet__FDK[ch];
+- for (hyb = 0; hyb < nHybBands; hyb++) {
+- pRealDry[hyb] += pRealWet[hyb];
+- pImagDry[hyb] += pImagWet[hyb];
+- } /* loop hyb */
+- for (; hyb < self->hybridBands; hyb++) {
+- pRealDry[hyb] += pRealWet[hyb];
+- } /* loop hyb */
+- } /* loop ch */
+- } /* ( self->tempShapeConfig == 1 ) || ( self->tempShapeConfig == 2 ) */
+- } /* !self->tempShapeConfig == 1 */
+- } /* !bypassMode */
+-
+- if (self->phaseCoding == 1) {
+- /* only if bsPhaseCoding == 1 and bsResidualCoding == 0 */
+-
+- SpatialDecApplyPhase(
+- self, alpha, (ts == currSlot) /* signal the last slot of the set */
+- );
+- }
+-
+- /*
+- * Synthesis Filtering
+- */
+-
+- err = SpatialDecSynthesis(
+- self, ts_io,
+- self->hybOutputRealDry__FDK, /* input: hybOutput(Real/Imag)Dry */
+- self->hybOutputImagDry__FDK, self->timeOut__FDK, /* output: timeOut */
+- numInputChannels, mapDescr);
+-
+- if (err != MPS_OK) goto bail;
+-
+- /*
+- * Update parameter buffer
+- */
+- if (ts == currSlot) {
+- SpatialDecBufferMatrices(self); /* input: M(1/2)param(Real/Imag) */
+- /* output: M(1/2)param(Real/Imag)Prev */
+-
+- prevSlot = currSlot;
+- ps++;
+- } /* if (ts==currSlot) */
+-
+- } /* ts loop */
+-
+- /*
+- * Save parameter states
+- */
+- self->prevTimeSlot = prevSlot;
+- self->curTimeSlot = ts;
+- self->curPs = ps;
+-
+-bail:
+-
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecApplyFrame(
+- spatialDec *self,
+- SPATIAL_BS_FRAME *frame, /* parsed frame data to be applied */
+- SPATIALDEC_INPUT_MODE inputMode, PCM_MPS *inData, /* Time domain input */
+- FIXP_DBL **qmfInDataReal, /* QMF domain data l/r */
+- FIXP_DBL **qmfInDataImag, /* QMF domain data l/r */
+- PCM_MPS *pcmOutBuf, /* MAX_OUTPUT_CHANNELS*MAX_TIME_SLOTS*NUM_QMF_BANDS] */
+- UINT nSamples, UINT *pControlFlags, int numInputChannels,
+- const FDK_channelMapDescr *const mapDescr) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- int fDecAndMapFrameData;
+- int controlFlags;
+-
+- FDK_ASSERT(self != NULL);
+- FDK_ASSERT(pControlFlags != NULL);
+- FDK_ASSERT(pcmOutBuf != NULL);
+-
+- self->errInt = err; /* Init internal error */
+-
+- controlFlags = *pControlFlags;
+-
+- if ((self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_USAC) &&
+- (self->stereoConfigIndex > 1)) {
+- numInputChannels =
+- 1; /* Do not count residual channel as input channel. It is handled
+- seperately. */
+- }
+-
+- /* Check if input amount of channels is consistent */
+- if (numInputChannels != self->numInputChannels) {
+- controlFlags |= MPEGS_CONCEAL;
+- if (numInputChannels > self->createParams.maxNumInputChannels) {
+- return MPS_INVALID_PARAMETER;
+- }
+- }
+-
+- self->timeOut__FDK = pcmOutBuf;
+-
+- /* Determine local function control flags */
+- fDecAndMapFrameData = frame->newBsData;
+-
+- if (((fDecAndMapFrameData ==
+- 0) /* assures that conceal flag will not be set for blind mode */
+- && (self->curTimeSlot + (int)nSamples / self->qmfBands >
+- self->timeSlots)) ||
+- (frame->numParameterSets ==
+- 0)) { /* New input samples but missing side info */
+- fDecAndMapFrameData = 1;
+- controlFlags |= MPEGS_CONCEAL;
+- }
+-
+- if ((fDecAndMapFrameData == 0) &&
+- (frame->paramSlot[fMax(0, frame->numParameterSets - 1)] !=
+- (self->timeSlots - 1) ||
+- self->curTimeSlot >
+- frame->paramSlot[self->curPs])) { /* Detected faulty parameter slot
+- data. */
+- fDecAndMapFrameData = 1;
+- controlFlags |= MPEGS_CONCEAL;
+- }
+-
+- /* Update concealment state machine */
+- SpatialDecConcealment_UpdateState(
+- &self->concealInfo,
+- (controlFlags & MPEGS_CONCEAL)
+- ? 0
+- : 1); /* convert from conceal flag to frame ok flag */
+-
+- if (fDecAndMapFrameData) {
+- /* Reset spatial framing control vars */
+- frame->newBsData = 0;
+- self->prevTimeSlot = -1;
+- self->curTimeSlot = 0;
+- self->curPs = 0;
+-
+- if (controlFlags & MPEGS_CONCEAL) {
+- /* Reset frame data to avoid misconfiguration. */
+- SpatialDecClearFrameData(self, frame, &self->createParams);
+- }
+-
+- {
+- err = SpatialDecDecodeFrame(self, frame); /* input: ... */
+- /* output: decodeAndMapFrameDATA */
+- }
+-
+- if (err != MPS_OK) {
+- /* Rescue strategy is to apply bypass mode in order
+- to keep at least the downmix channels continuous. */
+- controlFlags |= MPEGS_CONCEAL;
+- if (self->errInt == MPS_OK) {
+- /* store internal error befor it gets overwritten */
+- self->errInt = err;
+- }
+- }
+- }
+-
+- err = SpatialDecApplyParameterSets(
+- self, frame, inputMode, inData, qmfInDataReal, qmfInDataImag, nSamples,
+- controlFlags | ((err == MPS_OK) ? 0 : MPEGS_BYPASSMODE), numInputChannels,
+- mapDescr);
+- if (err != MPS_OK) {
+- goto bail;
+- }
+-
+-bail:
+-
+- *pControlFlags = controlFlags;
+-
+- return err;
+-}
+diff --git a/libSACdec/src/sac_dec.h b/libSACdec/src/sac_dec.h
+deleted file mode 100644
+index 992acad..0000000
+--- a/libSACdec/src/sac_dec.h
++++ /dev/null
+@@ -1,539 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Decoder Library structures
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_DEC_H
+-#define SAC_DEC_H
+-
+-#include "common_fix.h"
+-
+-#include "sac_dec_interface.h" /* library interface in ../include */
+-
+-#include "FDK_qmf_domain.h"
+-#include "sac_qmf.h"
+-#include "FDK_bitstream.h" /* mp4 bitbuffer */
+-#include "sac_calcM1andM2.h"
+-#include "FDK_hybrid.h"
+-#include "FDK_decorrelate.h"
+-#include "sac_reshapeBBEnv.h"
+-
+-#include "sac_dec_conceal.h"
+-
+-#include "sac_tsd.h"
+-
+-#ifndef MAX
+-#define MAX(a, b) ((a) > (b) ? (a) : (b))
+-#endif
+-
+-#define ICCdefault 0
+-#define IPDdefault 0
+-#define arbdmxGainDefault 0
+-#define CPCdefault 10
+-#define tttCLD1default 15
+-#define tttCLD2default 0
+-
+-#define IS_HQ_ONLY(aot) \
+- ((aot) == AOT_ER_AAC_LD || (aot) == AOT_ER_AAC_ELD || (aot) == AOT_USAC || \
+- (aot) == AOT_RSVD50)
+-
+-#define SCONST(x) FL2FXCONST_DBL(x)
+-
+-#define PC_NUM_BANDS (8)
+-#define PC_NUM_HYB_BANDS (PC_NUM_BANDS - 3 + 10)
+-#define ABS_THR (1e-9f * 32768 * 32768)
+-
+-#define MAX_HYBRID_BANDS (MAX_NUM_QMF_BANDS - 3 + 10)
+-#define HYBRID_FILTER_DELAY (6)
+-
+-#define MAX_RESIDUAL_FRAMES (4)
+-#define MAX_RESIDUAL_BISTREAM \
+- (836) /* 48000 bps * 3 res / (8 * 44100 / 2048 ) */
+-#define MAX_MDCT_COEFFS (1024)
+-#define SACDEC_RESIDUAL_BS_BUF_SIZE \
+- (1024) /* used to setup and check residual bitstream buffer */
+-
+-#define MAX_NUM_PARAMS (MAX_NUM_OTT + 4 * MAX_NUM_TTT + MAX_INPUT_CHANNELS)
+-#define MAX_NUM_PARAMETERS (MAX(MAX_NUM_PARAMS, MAX_NUM_OTT))
+-
+-#define MAX_PARAMETER_SETS (9)
+-
+-#define MAX_M2_INPUT (MAX_OUTPUT_CHANNELS) /* 3 direct + 5 diffuse */
+-
+-#define MAX_QMF_BANDS_TO_HYBRID \
+- (3) /* 3 bands are filtered again in "40 bands" case */
+-#define PROTO_LEN (13)
+-#define BUFFER_LEN_LF (PROTO_LEN)
+-#define BUFFER_LEN_HF ((PROTO_LEN - 1) / 2)
+-
+-#define MAX_NO_DECORR_CHANNELS (MAX_OUTPUT_CHANNELS)
+-#define HRTF_AZIMUTHS (5)
+-
+-#define MAX_NUM_OTT_AT 0
+-
+-/* left out */
+-
+-typedef enum {
+- UPMIXTYPE_BYPASS = -1, /*just bypass the input channels without processing*/
+- UPMIXTYPE_NORMAL = 0 /*multichannel loudspeaker upmix with spatial data*/
+-} UPMIXTYPE;
+-
+-static inline int isTwoChMode(UPMIXTYPE upmixType) {
+- int retval = 0;
+- return retval;
+-}
+-
+- /* left out end */
+-
+-#define MPEGS_BYPASSMODE (0x00000001)
+-#define MPEGS_CONCEAL (0x00000002)
+-
+-typedef struct STP_DEC *HANDLE_STP_DEC;
+-
+-typedef struct {
+- SCHAR bsQuantCoarseXXXprev;
+- SCHAR bsQuantCoarseXXXprevParse;
+-} LOSSLESSSTATE;
+-
+-typedef struct {
+- SCHAR bsXXXDataMode[MAX_PARAMETER_SETS];
+- SCHAR bsQuantCoarseXXX[MAX_PARAMETER_SETS];
+- SCHAR bsFreqResStrideXXX[MAX_PARAMETER_SETS];
+- SCHAR nocmpQuantCoarseXXX[MAX_PARAMETER_SETS];
+- LOSSLESSSTATE *state; /* Link to persistent state information */
+-} LOSSLESSDATA;
+-
+-struct SPATIAL_BS_FRAME_struct {
+- UCHAR bsIndependencyFlag;
+- UCHAR newBsData;
+- UCHAR numParameterSets;
+-
+- /*
+- If bsFramingType == 0, then the paramSlot[ps] for 0 <= ps < numParamSets is
+- calculated as follows: paramSlot[ps] = ceil(numSlots*(ps+1)/numParamSets) - 1
+- Otherwise, it is
+- paramSlot[ps] = bsParamSlot[ps]
+- */
+- INT paramSlot[MAX_PARAMETER_SETS];
+-
+- /* These arrays contain the compact indices, only one value per pbstride, only
+- * paramsets actually containing data. */
+- /* These values are written from the parser in ecDataDec() and read during
+- * decode in mapIndexData() */
+- SCHAR cmpOttCLDidx[MAX_NUM_OTT + MAX_NUM_OTT_AT][MAX_PARAMETER_SETS]
+- [MAX_PARAMETER_BANDS];
+- SCHAR cmpOttICCidx[MAX_NUM_OTT][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
+-
+- /* Smoothing */
+- UCHAR bsSmoothMode[MAX_PARAMETER_SETS];
+- UCHAR bsSmoothTime[MAX_PARAMETER_SETS];
+- UCHAR bsFreqResStrideSmg[MAX_PARAMETER_SETS];
+- UCHAR bsSmgData[MAX_PARAMETER_SETS]
+- [MAX_PARAMETER_BANDS]; /* smoothing flags, one if band is
+- smoothed, otherwise zero */
+-
+- /* Arbitrary Downmix */
+- SCHAR (*cmpArbdmxGainIdx)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
+-
+- /* Lossless control */
+- LOSSLESSDATA *CLDLosslessData;
+- LOSSLESSDATA *ICCLosslessData;
+- /* LOSSLESSDATA *ADGLosslessData; -> is stored in CLDLosslessData[offset] */
+-
+- LOSSLESSDATA *IPDLosslessData;
+- SCHAR (*cmpOttIPDidx)[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
+- int phaseMode;
+- int OpdSmoothingMode;
+-
+- UCHAR tempShapeEnableChannelGES[MAX_OUTPUT_CHANNELS]; /*!< GES side info. */
+- UCHAR bsEnvShapeData[MAX_OUTPUT_CHANNELS]
+- [MAX_TIME_SLOTS]; /*!< GES side info (quantized). */
+-
+- UCHAR tempShapeEnableChannelSTP[MAX_OUTPUT_CHANNELS]; /*!< STP side info. */
+-
+- TSD_DATA TsdData[1]; /*!< TSD data structure. */
+-};
+-
+-typedef struct {
+- /* Lossless state */
+- LOSSLESSSTATE CLDLosslessState[MAX_NUM_PARAMETERS];
+- LOSSLESSSTATE ICCLosslessState[MAX_NUM_PARAMETERS];
+- LOSSLESSSTATE IPDLosslessState[MAX_NUM_PARAMETERS];
+-} BS_LL_STATE;
+-
+-typedef struct {
+- int prevParamSlot;
+- int prevSmgTime;
+- UCHAR prevSmgData[MAX_PARAMETER_BANDS];
+-
+- FIXP_DBL opdLeftState__FDK[MAX_PARAMETER_BANDS];
+- FIXP_DBL opdRightState__FDK[MAX_PARAMETER_BANDS];
+-
+-} SMOOTHING_STATE;
+-
+-typedef struct {
+- FIXP_DBL alpha__FDK;
+- FIXP_DBL beta__FDK;
+- FIXP_DBL partNrgPrev__FDK[2 * MAX_OUTPUT_CHANNELS + MAX_INPUT_CHANNELS]
+- [BB_ENV_SIZE];
+- FIXP_DBL normNrgPrev__FDK[2 * MAX_OUTPUT_CHANNELS + MAX_INPUT_CHANNELS];
+- FIXP_DBL frameNrgPrev__FDK[2 * MAX_OUTPUT_CHANNELS + MAX_INPUT_CHANNELS];
+- INT partNrgPrevSF[2 * MAX_OUTPUT_CHANNELS + MAX_INPUT_CHANNELS];
+- INT partNrgPrev2SF[2 * MAX_OUTPUT_CHANNELS + MAX_INPUT_CHANNELS];
+- INT normNrgPrevSF[2 * MAX_OUTPUT_CHANNELS + MAX_INPUT_CHANNELS];
+- INT frameNrgPrevSF[2 * MAX_OUTPUT_CHANNELS + MAX_INPUT_CHANNELS];
+-} RESHAPE_BBENV_STATE;
+-
+-typedef struct {
+- int maxNumInputChannels;
+- int maxNumOutputChannels;
+- int maxNumQmfBands;
+- int maxNumHybridBands;
+- int maxNumXChannels;
+- int maxNumVChannels;
+- int maxNumDecorChannels;
+- int maxNumCmplxQmfBands;
+- int maxNumCmplxHybBands;
+- int maxNumResChannels;
+- int bProcResidual; /* process residual */
+- int maxNumResidualChannels;
+- int maxNumOttBoxes;
+- int maxNumParams;
+-
+-} SACDEC_CREATION_PARAMS;
+-
+-struct spatialDec_struct {
+- SACDEC_ERROR
+- errInt; /* Field to store internal errors.
+- Will be clear at the very beginning of each process call. */
+- int staticDecScale; /* static scale of decoder */
+-
+- /* GENERAL */
+- int samplingFreq; /* [Hz] */
+- CFG_LEVEL decoderLevel; /* 0..5 */
+- CFG_EXTENT decoderMode;
+- CFG_BINAURAL binauralMode;
+-
+- SACDEC_CREATION_PARAMS createParams;
+-
+- int numComplexProcessingBands;
+-
+- int treeConfig; /* TREE_5151 = 5151, TREE_5152 = 5152, TREE_525 = 525, defined
+- in sac_bitdec.h */
+-
+- int numInputChannels; /* 1 (M) or 2 (L,R) */
+- int numOutputChannels; /* 6 for 3/2.1 (FL,FR,FC,LF,BL,BR) */
+- int numOttBoxes; /* number of ott boxes */
+- int numM2rows;
+-
+- int numOutputChannelsAT; /* Number of output channels after arbitrary tree
+- processing */
+-
+- int quantMode; /* QUANT_FINE, QUANT_EBQ1, QUANT_EBQ2, defined in sac_bitdec.h
+- */
+- int arbitraryDownmix; /* (arbitraryDownmix != 0) 1 arbitrary downmix data
+- present, 2 arbitrary downmix residual data present*/
+- int residualCoding; /* (residualCoding != 0) => residual coding data present
+- */
+- UCHAR nrResidualFrame;
+- UCHAR nrArbDownmixResidualFrame;
+- FDK_BITSTREAM **hResidualBitstreams;
+- int tempShapeConfig; /* */
+- int decorrType; /* Indicates to use PS or none PS decorrelator. */
+- int decorrConfig; /* chosen decorrelator */
+- int envQuantMode; /* quantization mode of envelope reshaping data */
+-
+- FIXP_DBL clipProtectGain__FDK; /* global gain for upmix */
+- char clipProtectGainSF__FDK; /* global gain for upmix */
+-
+- /* Currently ignoring center decorr
+- numVChannels = numDirektSignals + numDecorSignals */
+- int numDirektSignals; /* needed for W, Number of direkt signals 515 -> 1 525
+- -> 3 */
+- int wStartResidualIdx; /* Where to start read residuals for W, = 0 for 515, =
+- 1 for 525 since one residual is used in V */
+- int numDecorSignals; /* needed for W, Number of residual and decorrelated
+- signals, = 2, 3 for center deccorelation*/
+- int numVChannels; /* direct signals + decorelator signals */
+- int numXChannels; /* direct input signals + TTT-residuals */
+-
+- int timeSlots; /* length of spatial frame in QMF samples */
+- int curTimeSlot; /* pointer to the current time slot used for hyperframing */
+- int prevTimeSlot; /* */
+- int curPs;
+- int frameLength; /* number of output waveform samples/channel/frame */
+- UPMIXTYPE upmixType;
+- int partiallyComplex;
+- int useFDreverb;
+-
+- int bShareDelayWithSBR;
+-
+- int tp_hybBandBorder; /* Hybrid band indicating the HP filter cut-off. */
+-
+- /* FREQUENCY MAPPING */
+- int qmfBands;
+- int hybridBands;
+- const SCHAR *kernels; /* Mapping hybrid band to parameter band. */
+-
+- int TsdTs; /**< TSD QMF slot counter 0<= ts < numSlots */
+-
+- int *param2hyb; /* Mapping parameter bands to hybrid bands */
+- int kernels_width[MAX_PARAMETER_BANDS]; /* Mapping parmeter band to hybrid
+- band offsets. */
+-
+- /* Residual coding */
+- int residualSamplingFreq;
+- UCHAR residualPresent[MAX_NUM_OTT + MAX_NUM_TTT];
+- UCHAR residualBands[MAX_NUM_OTT + MAX_NUM_TTT]; /* 0, if no residual data
+- present for this box */
+- UCHAR residualQMFBands[MAX_NUM_OTT + MAX_NUM_TTT]; /* needed for optimized
+- mdct2qmf calculation */
+- SPATIAL_SPECIFIC_CONFIG *pConfigCurrent;
+-
+- int arbdmxFramesPerSpatialFrame;
+- int arbdmxUpdQMF;
+-
+- int numParameterBands; /* Number of parameter bands 40, 28, 20, 14, 10, ...
+- .*/
+- int bitstreamParameterBands;
+- int *numOttBands; /* number of bands for each ott, is != numParameterBands for
+- LFEs */
+-
+- /* 1 MAPPING */
+- UCHAR extendFrame;
+- UCHAR numParameterSetsPrev;
+-
+- int *smgTime;
+- UCHAR **smgData;
+-
+- /* PARAMETER DATA decoded and dequantized */
+-
+- /* Last parameters from prev frame required during decode in mapIndexData()
+- * and not touched during parse */
+- SCHAR **ottCLDidxPrev;
+- SCHAR **ottICCidxPrev;
+- SCHAR **arbdmxGainIdxPrev;
+- SCHAR **ottIPDidxPrev;
+- SCHAR ***outIdxData; /* is this really persistent memory ? */
+-
+- /* State mem required during parse in SpatialDecParseFrameData() */
+- SCHAR **cmpOttCLDidxPrev;
+- SCHAR **cmpOttICCidxPrev;
+- SCHAR ***ottICCdiffidx;
+- SCHAR **cmpOttIPDidxPrev;
+-
+- /* State mem required in parseArbitraryDownmixData */
+- SCHAR **cmpArbdmxGainIdxPrev;
+-
+- SCHAR ***ottCLD__FDK;
+- SCHAR ***ottICC__FDK;
+-
+- SCHAR ***arbdmxGain__FDK; /* Holds the artistic downmix correction index.*/
+-
+- FIXP_DBL *arbdmxAlpha__FDK;
+- FIXP_DBL *arbdmxAlphaPrev__FDK;
+-
+- UCHAR stereoConfigIndex;
+- int highRateMode;
+-
+- int phaseCoding;
+-
+- SCHAR ***ottIPD__FDK;
+-
+- FIXP_DBL PhaseLeft__FDK[MAX_PARAMETER_BANDS];
+- FIXP_DBL PhaseRight__FDK[MAX_PARAMETER_BANDS];
+- FIXP_DBL PhasePrevLeft__FDK[MAX_PARAMETER_BANDS];
+- FIXP_DBL PhasePrevRight__FDK[MAX_PARAMETER_BANDS];
+- int numOttBandsIPD;
+-
+- /* GAIN MATRICIES FOR CURRENT and PREVIOUS PARMATER SET(s)*/
+- FIXP_DBL ***M2Real__FDK;
+- FIXP_DBL ***M2Imag__FDK;
+- FIXP_DBL ***M2RealPrev__FDK;
+- FIXP_DBL ***M2ImagPrev__FDK;
+-
+- /* INPUT SIGNALS */
+- FIXP_DBL ***qmfInputRealDelayBuffer__FDK;
+- FIXP_DBL ***qmfInputImagDelayBuffer__FDK;
+-
+- int pc_filterdelay; /* additional delay to align HQ with LP before hybird
+- analysis */
+- int qmfInputDelayBufPos;
+- FIXP_DBL **qmfInputReal__FDK;
+- FIXP_DBL **qmfInputImag__FDK;
+-
+- FIXP_DBL **hybInputReal__FDK;
+- FIXP_DBL **hybInputImag__FDK;
+-
+- FIXP_DBL **binInputReverb;
+-
+- FIXP_DBL binGain, reverbGain;
+- FIXP_DBL binCenterGain, reverbCenterGain;
+-
+- /* RESIDUAL SIGNALS */
+-
+- FIXP_DBL ***qmfResidualReal__FDK;
+- FIXP_DBL ***qmfResidualImag__FDK;
+-
+- FIXP_DBL **hybResidualReal__FDK;
+- FIXP_DBL **hybResidualImag__FDK;
+-
+- int qmfOutputRealDryDelayBufPos;
+- FIXP_DBL ***qmfOutputRealDryDelayBuffer__FDK;
+- FIXP_DBL ***qmfOutputImagDryFilterBuffer__FDK;
+- FIXP_DBL *qmfOutputImagDryFilterBufferBase__FDK;
+-
+- /* TEMPORARY SIGNALS */
+-
+- FIXP_DBL **wReal__FDK;
+- FIXP_DBL **wImag__FDK;
+-
+- /* OUTPUT SIGNALS */
+- FIXP_DBL **hybOutputRealDry__FDK;
+- FIXP_DBL **hybOutputImagDry__FDK;
+- FIXP_DBL **hybOutputRealWet__FDK;
+- FIXP_DBL **hybOutputImagWet__FDK;
+- PCM_MPS *timeOut__FDK;
+-
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain;
+-
+- FDK_ANA_HYB_FILTER
+- *hybridAnalysis; /*!< pointer Analysis hybrid filterbank array. */
+- FDK_SYN_HYB_FILTER
+- *hybridSynthesis; /*!< pointer Synthesis hybrid filterbank array. */
+- FIXP_DBL **
+- pHybridAnaStatesLFdmx; /*!< pointer to analysis hybrid filter states LF */
+- FIXP_DBL **
+- pHybridAnaStatesHFdmx; /*!< pointer to analysis hybrid filter states HF */
+- FIXP_DBL **
+- pHybridAnaStatesLFres; /*!< pointer to analysis hybrid filter states LF */
+- FIXP_DBL **
+- pHybridAnaStatesHFres; /*!< pointer to analysis hybrid filter states HF */
+-
+- DECORR_DEC *apDecor; /*!< pointer decorrelator array. */
+- FIXP_DBL **pDecorBufferCplx;
+-
+- SMOOTHING_STATE *smoothState; /*!< Pointer to smoothing states. */
+-
+- RESHAPE_BBENV_STATE *reshapeBBEnvState; /*!< GES handle. */
+- SCHAR row2channelDmxGES[MAX_OUTPUT_CHANNELS];
+-
+- HANDLE_STP_DEC hStpDec; /*!< STP handle. */
+-
+- const UCHAR *pActivM2ParamBands;
+-
+- int bOverwriteM1M2prev; /* Overwrite previous M2/M2 params with first set of
+- new frame after SSC change (aka
+- decodeAfterConfigHasChangedFlag). */
+- SpatialDecConcealmentInfo concealInfo;
+-};
+-
+-#define SACDEC_SYNTAX_MPS 1
+-#define SACDEC_SYNTAX_USAC 2
+-#define SACDEC_SYNTAX_RSVD50 4
+-#define SACDEC_SYNTAX_L2 8
+-#define SACDEC_SYNTAX_L3 16
+-#define SACDEC_SYNTAX_LD 32
+-
+-static inline int GetProcBand(spatialDec_struct *self, int qs) {
+- return self->kernels[qs];
+-}
+-
+-#endif /* SAC_DEC_H */
+diff --git a/libSACdec/src/sac_dec_conceal.cpp b/libSACdec/src/sac_dec_conceal.cpp
+deleted file mode 100644
+index dfeef7b..0000000
+--- a/libSACdec/src/sac_dec_conceal.cpp
++++ /dev/null
+@@ -1,392 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s): Christian Ertel, Christian Griebel
+-
+- Description: SAC Dec error concealment
+-
+-*******************************************************************************/
+-
+-#include "sac_dec_conceal.h"
+-
+-void SpatialDecConcealment_Init(SpatialDecConcealmentInfo *info,
+- const UINT resetFlags) {
+- FDK_ASSERT(info != NULL);
+-
+- if (resetFlags & MPEGS_CONCEAL_RESET_STATE) {
+- info->concealState = SpatialDecConcealState_Init;
+- /* Frame counters will be initialized implicitely in function
+- * SpatialDecConcealment_UpdateState(). */
+- }
+-
+- if (resetFlags & MPEGS_CONCEAL_RESET_PARAMETER) {
+- /* Set default params */
+- info->concealParams.method = MPEGS_CONCEAL_DEFAULT_METHOD;
+- info->concealParams.numKeepFrames = MPEGS_CONCEAL_DEFAULT_NUM_KEEP_FRAMES;
+- info->concealParams.numFadeOutFrames =
+- MPEGS_CONCEAL_DEFAULT_FADE_OUT_SLOPE_LENGTH;
+- info->concealParams.numFadeInFrames =
+- MPEGS_CONCEAL_DEFAULT_FADE_IN_SLOPE_LENGTH;
+- info->concealParams.numReleaseFrames =
+- MPEGS_CONCEAL_DEFAULT_NUM_RELEASE_FRAMES;
+- }
+-
+- return;
+-}
+-
+-int SpatialDecConcealment_Apply(
+- SpatialDecConcealmentInfo *info,
+- const SCHAR (*cmpIdxData)[MAX_PARAMETER_BANDS], SCHAR **diffIdxData,
+- SCHAR *
+- idxPrev, /* char
+- idxPrev[SPATIALDEC_MAX_NUM_OTT][SPATIALDEC_MAX_PARAMETER_BANDS],
+- */
+- SCHAR *bsXXXDataMode, const int startBand, const int stopBand,
+- const SCHAR defaultValue, const int paramType, const int numParamSets) {
+- int appliedProcessing = 0;
+- int band, dataMode = -1;
+-
+- FDK_ASSERT(info != NULL);
+- FDK_ASSERT(cmpIdxData != NULL);
+- FDK_ASSERT(idxPrev != NULL);
+- FDK_ASSERT(bsXXXDataMode != NULL);
+-
+- /* Processing depends only on the internal state */
+- switch (info->concealState) {
+- case SpatialDecConcealState_Init:
+- dataMode = 0; /* default */
+- break;
+-
+- case SpatialDecConcealState_Ok:
+- /* Nothing to do */
+- break;
+-
+- case SpatialDecConcealState_Keep:
+- dataMode = 1; /* keep */
+- break;
+-
+- case SpatialDecConcealState_FadeToDefault: {
+- /* Start simple fade out */
+- FIXP_DBL fac = fDivNorm(info->cntStateFrames + 1,
+- info->concealParams.numFadeOutFrames + 1);
+-
+- for (band = startBand; band < stopBand; band += 1) {
+- /* idxPrev = fac * defaultValue + (1-fac) * idxPrev; */
+- idxPrev[band] =
+- fMultI(fac, defaultValue - idxPrev[band]) + idxPrev[band];
+- }
+- dataMode = 1; /* keep */
+- appliedProcessing = 1;
+- } break;
+-
+- case SpatialDecConcealState_Default:
+- for (band = startBand; band < stopBand; band += 1) {
+- idxPrev[band] = defaultValue;
+- }
+- dataMode = 1; /* keep */
+- appliedProcessing = 1;
+- break;
+-
+- case SpatialDecConcealState_FadeFromDefault: {
+- FIXP_DBL fac = fDivNorm(info->cntValidFrames + 1,
+- info->concealParams.numFadeInFrames + 1);
+-
+- for (band = startBand; band < stopBand; band += 1) {
+- /* idxPrev = fac * cmpIdxData + (1-fac) * defaultValue; */
+- idxPrev[band] =
+- fMultI(fac, cmpIdxData[numParamSets - 1][band] - defaultValue) +
+- defaultValue;
+- }
+- dataMode = 1; /* keep */
+- appliedProcessing = 1;
+- } break;
+-
+- default:
+- FDK_ASSERT(0); /* All valid states shall be handled above. */
+- break;
+- }
+-
+- if (dataMode >= 0) {
+- int i;
+- for (i = 0; i < numParamSets; i += 1) {
+- bsXXXDataMode[i] = dataMode;
+- if (diffIdxData != NULL) {
+- for (band = startBand; band < stopBand; band += 1) {
+- diffIdxData[i][band] = 0;
+- }
+- }
+- }
+- }
+-
+- return appliedProcessing;
+-}
+-
+-void SpatialDecConcealment_UpdateState(SpatialDecConcealmentInfo *info,
+- const int frameOk) {
+- FDK_ASSERT(info != NULL);
+-
+- if (frameOk) {
+- info->cntValidFrames += 1;
+- } else {
+- info->cntValidFrames = 0;
+- }
+-
+- switch (info->concealState) {
+- case SpatialDecConcealState_Init:
+- if (frameOk) {
+- /* NEXT STATE: Ok */
+- info->concealState = SpatialDecConcealState_Ok;
+- info->cntStateFrames = 0;
+- }
+- break;
+-
+- case SpatialDecConcealState_Ok:
+- if (!frameOk) {
+- /* NEXT STATE: Keep */
+- info->concealState = SpatialDecConcealState_Keep;
+- info->cntStateFrames = 0;
+- }
+- break;
+-
+- case SpatialDecConcealState_Keep:
+- info->cntStateFrames += 1;
+- if (frameOk) {
+- /* NEXT STATE: Ok */
+- info->concealState = SpatialDecConcealState_Ok;
+- } else {
+- if (info->cntStateFrames >= info->concealParams.numKeepFrames) {
+- if (info->concealParams.numFadeOutFrames == 0) {
+- /* NEXT STATE: Default */
+- info->concealState = SpatialDecConcealState_Default;
+- } else {
+- /* NEXT STATE: Fade to default */
+- info->concealState = SpatialDecConcealState_FadeToDefault;
+- info->cntStateFrames = 0;
+- }
+- }
+- }
+- break;
+-
+- case SpatialDecConcealState_FadeToDefault:
+- info->cntStateFrames += 1;
+- if (info->cntValidFrames > 0) {
+- /* NEXT STATE: Fade in from default */
+- info->concealState = SpatialDecConcealState_FadeFromDefault;
+- info->cntStateFrames = 0;
+- } else {
+- if (info->cntStateFrames >= info->concealParams.numFadeOutFrames) {
+- /* NEXT STATE: Default */
+- info->concealState = SpatialDecConcealState_Default;
+- }
+- }
+- break;
+-
+- case SpatialDecConcealState_Default:
+- if (info->cntValidFrames > 0) {
+- if (info->concealParams.numFadeInFrames == 0) {
+- /* NEXT STATE: Ok */
+- info->concealState = SpatialDecConcealState_Ok;
+- } else {
+- /* NEXT STATE: Fade in from default */
+- info->concealState = SpatialDecConcealState_FadeFromDefault;
+- info->cntValidFrames = 0;
+- }
+- }
+- break;
+-
+- case SpatialDecConcealState_FadeFromDefault:
+- info->cntValidFrames += 1;
+- if (frameOk) {
+- if (info->cntValidFrames >= info->concealParams.numFadeInFrames) {
+- /* NEXT STATE: Ok */
+- info->concealState = SpatialDecConcealState_Ok;
+- }
+- } else {
+- /* NEXT STATE: Fade to default */
+- info->concealState = SpatialDecConcealState_FadeToDefault;
+- info->cntStateFrames = 0;
+- }
+- break;
+-
+- default:
+- FDK_ASSERT(0); /* All valid states should be handled above! */
+- break;
+- }
+-}
+-
+-SACDEC_ERROR SpatialDecConcealment_SetParam(SpatialDecConcealmentInfo *self,
+- const SAC_DEC_CONCEAL_PARAM param,
+- const INT value) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- switch (param) {
+- case SAC_DEC_CONCEAL_METHOD:
+- switch ((SpatialDecConcealmentMethod)value) {
+- case SAC_DEC_CONCEAL_WITH_ZERO_VALUED_OUTPUT:
+- case SAC_DEC_CONCEAL_BY_FADING_PARAMETERS:
+- break;
+- default:
+- err = MPS_INVALID_PARAMETER;
+- goto bail;
+- }
+- if (self != NULL) {
+- /* store parameter value */
+- self->concealParams.method = (SpatialDecConcealmentMethod)value;
+- } else {
+- err = MPS_INVALID_HANDLE;
+- goto bail;
+- }
+- break;
+- case SAC_DEC_CONCEAL_NUM_KEEP_FRAMES:
+- if (value < 0) {
+- err = MPS_INVALID_PARAMETER;
+- goto bail;
+- }
+- if (self != NULL) {
+- /* store parameter value */
+- self->concealParams.numKeepFrames = (UINT)value;
+- } else {
+- err = MPS_INVALID_HANDLE;
+- goto bail;
+- }
+- break;
+- case SAC_DEC_CONCEAL_FADE_OUT_SLOPE_LENGTH:
+- if (value < 0) {
+- err = MPS_INVALID_PARAMETER;
+- goto bail;
+- }
+- if (self != NULL) {
+- /* store parameter value */
+- self->concealParams.numFadeOutFrames = (UINT)value;
+- } else {
+- err = MPS_INVALID_HANDLE;
+- goto bail;
+- }
+- break;
+- case SAC_DEC_CONCEAL_FADE_IN_SLOPE_LENGTH:
+- if (value < 0) {
+- err = MPS_INVALID_PARAMETER;
+- goto bail;
+- }
+- if (self != NULL) {
+- /* store parameter value */
+- self->concealParams.numFadeInFrames = (UINT)value;
+- } else {
+- err = MPS_INVALID_HANDLE;
+- goto bail;
+- }
+- break;
+- case SAC_DEC_CONCEAL_NUM_RELEASE_FRAMES:
+- if (value < 0) {
+- err = MPS_INVALID_PARAMETER;
+- goto bail;
+- }
+- if (self != NULL) {
+- /* store parameter value */
+- self->concealParams.numReleaseFrames = (UINT)value;
+- } else {
+- err = MPS_INVALID_HANDLE;
+- goto bail;
+- }
+- break;
+- default:
+- err = MPS_INVALID_PARAMETER;
+- goto bail;
+- }
+-
+-bail:
+- return err;
+-}
+diff --git a/libSACdec/src/sac_dec_conceal.h b/libSACdec/src/sac_dec_conceal.h
+deleted file mode 100644
+index 27f5249..0000000
+--- a/libSACdec/src/sac_dec_conceal.h
++++ /dev/null
+@@ -1,187 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s): Christian Ertel, Christian Griebel
+-
+- Description: SAC Dec error concealment
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_DEC_CONCEAL_H
+-#define SAC_DEC_CONCEAL_H
+-
+-#include "sac_dec_interface.h"
+-
+-/* Modules dynamic parameters: */
+-typedef enum {
+- SAC_DEC_CONCEAL_METHOD = 0,
+- SAC_DEC_CONCEAL_NUM_KEEP_FRAMES,
+- SAC_DEC_CONCEAL_FADE_OUT_SLOPE_LENGTH,
+- SAC_DEC_CONCEAL_FADE_IN_SLOPE_LENGTH,
+- SAC_DEC_CONCEAL_NUM_RELEASE_FRAMES
+-
+-} SAC_DEC_CONCEAL_PARAM;
+-
+-/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
+-/* sac_dec_interface.h */
+-/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
+-typedef enum {
+- SAC_DEC_CONCEAL_WITH_ZERO_VALUED_OUTPUT = 0,
+- SAC_DEC_CONCEAL_BY_FADING_PARAMETERS = 1
+-
+-} SpatialDecConcealmentMethod;
+-/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
+-
+-/* Default dynamic parameter values: */
+-#define MPEGS_CONCEAL_DEFAULT_METHOD SAC_DEC_CONCEAL_BY_FADING_PARAMETERS
+-#define MPEGS_CONCEAL_DEFAULT_NUM_KEEP_FRAMES (10)
+-#define MPEGS_CONCEAL_DEFAULT_FADE_OUT_SLOPE_LENGTH (5)
+-#define MPEGS_CONCEAL_DEFAULT_FADE_IN_SLOPE_LENGTH (5)
+-#define MPEGS_CONCEAL_DEFAULT_NUM_RELEASE_FRAMES (3)
+-
+-typedef enum {
+- SpatialDecConcealState_Init = 0,
+- SpatialDecConcealState_Ok,
+- SpatialDecConcealState_Keep,
+- SpatialDecConcealState_FadeToDefault,
+- SpatialDecConcealState_Default,
+- SpatialDecConcealState_FadeFromDefault
+-
+-} SpatialDecConcealmentState;
+-
+-typedef struct {
+- SpatialDecConcealmentMethod method;
+-
+- UINT numKeepFrames;
+- UINT numFadeOutFrames;
+- UINT numFadeInFrames;
+- UINT numReleaseFrames;
+-
+-} SpatialDecConcealmentParams;
+-
+-typedef struct {
+- SpatialDecConcealmentParams concealParams; /* User set params */
+- SpatialDecConcealmentState
+- concealState; /* State of internal state machine (fade-in/out etc) */
+-
+- UINT cntStateFrames; /* Counter for fade-in/out handling */
+- UINT cntValidFrames; /* Counter for the number of consecutive good frames*/
+-
+-} SpatialDecConcealmentInfo;
+-
+-/* Module reset flags */
+-#define MPEGS_CONCEAL_RESET_STATE (0x01)
+-#define MPEGS_CONCEAL_RESET_PARAMETER (0x02)
+-#define MPEGS_CONCEAL_RESET_ALL (0xFF)
+-
+-void SpatialDecConcealment_Init(SpatialDecConcealmentInfo *info,
+- const UINT resetFlags);
+-
+-int SpatialDecConcealment_Apply(SpatialDecConcealmentInfo *info,
+- const SCHAR (*cmpIdxData)[MAX_PARAMETER_BANDS],
+- SCHAR **diffIdxData, SCHAR *idxPrev,
+- SCHAR *bsXXXDataMode, const int startBand,
+- const int stopBand, const SCHAR defaultValue,
+- const int paramType, const int numParamSets);
+-
+-void SpatialDecConcealment_UpdateState(SpatialDecConcealmentInfo *info,
+- const int frameOk);
+-
+-SACDEC_ERROR SpatialDecConcealment_SetParam(SpatialDecConcealmentInfo *info,
+- const SAC_DEC_CONCEAL_PARAM param,
+- const INT value);
+-
+-#endif /* SAC_DEC_CONCEAL_H */
+diff --git a/libSACdec/src/sac_dec_interface.h b/libSACdec/src/sac_dec_interface.h
+deleted file mode 100644
+index a2eea92..0000000
+--- a/libSACdec/src/sac_dec_interface.h
++++ /dev/null
+@@ -1,335 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Decoder Library Interface
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_DEC_INTERFACE_H
+-#define SAC_DEC_INTERFACE_H
+-
+-#include "common_fix.h"
+-#include "FDK_audio.h"
+-
+-#ifdef __cplusplus
+-extern "C" {
+-#endif
+-
+-#include "sac_dec_errorcodes.h"
+-#include "sac_dec_ssc_struct.h"
+-
+-/**
+- * \brief Baseline MPEG-Surround profile Level 1-5.
+- */
+-typedef enum {
+- DECODER_LEVEL_0 = 0, /*!< Level 0: dummy level; 212 only */
+- DECODER_LEVEL_6 = 6 /*!< Level 6: no support */
+-} CFG_LEVEL;
+-
+-/*
+- * \brief Number of output channels restriction.
+- */
+-typedef enum {
+- OUTPUT_CHANNELS_DEFAULT, /*!< Default configuration depending on Decoder Level
+- */
+- OUTPUT_CHANNELS_2_0, /*!< Limitation to stereo output */
+- OUTPUT_CHANNELS_5_1 /*!< Limitation to 5.1 output */
+-} CFG_RESTRICTION;
+-
+-/*
+- * \brief Supported decoder mode.
+- */
+-typedef enum {
+- EXT_HQ_ONLY = 0, /*!< High Quality processing only */
+- EXT_LP_ONLY = 1, /*!< Low Power procesing only */
+- EXT_HQ_AND_LP = 2 /*!< Support both HQ and LP processing */
+-} CFG_EXTENT;
+-
+-/*
+- * \brief Supported binaural mode.
+- */
+-typedef enum {
+- BINAURAL_NONE = -1 /*!< No binaural procesing supported */
+-} CFG_BINAURAL;
+-
+-/**
+- * \brief Decoder configuration structure.
+- *
+- * These structure contains all parameters necessary for decoder open function.
+- * The configuration specifies the functional range of the decoder instance.
+- */
+-typedef struct {
+- CFG_LEVEL decoderLevel;
+- CFG_EXTENT decoderMode;
+- CFG_RESTRICTION maxNumOutputChannels;
+- CFG_BINAURAL binauralMode;
+-
+-} SPATIAL_DEC_CONFIG;
+-
+-typedef enum {
+- INPUTMODE_QMF = 1000,
+- INPUTMODE_QMF_SBR = 1001,
+- INPUTMODE_TIME = 1002
+-} SPATIALDEC_INPUT_MODE;
+-
+-/**
+- * \brief MPEG Surround upmix type mode.
+- **/
+-typedef enum {
+- UPMIX_TYPE_BYPASS =
+- -1, /*!< Bypass the downmix channels from the core decoder. */
+- UPMIX_TYPE_NORMAL = 0 /*!< Multi channel output. */
+-
+-} SPATIAL_DEC_UPMIX_TYPE;
+-
+-/**
+- * \brief Dynamic decoder parameters.
+- */
+-typedef struct {
+- /* Basics */
+- UCHAR outputMode;
+- UCHAR blindEnable;
+- UCHAR bypassMode;
+-
+- /* Error concealment */
+- UCHAR concealMethod;
+- UINT concealNumKeepFrames;
+- UINT concealFadeOutSlopeLength;
+- UINT concealFadeInSlopeLength;
+- UINT concealNumReleaseFrames;
+-
+-} SPATIALDEC_PARAM;
+-
+-/**
+- * \brief Flags which control the initialization
+- **/
+-typedef enum {
+- MPEGS_INIT_NONE = 0x00000000, /*!< Indicates no initialization */
+-
+- MPEGS_INIT_CONFIG = 0x00000010, /*!< Indicates a configuration change due to
+- SSC value changes */
+-
+- MPEGS_INIT_STATES_ANA_QMF_FILTER =
+- 0x00000100, /*!< Controls the initialization of the analysis qmf filter
+- states */
+- MPEGS_INIT_STATES_SYN_QMF_FILTER =
+- 0x00000200, /*!< Controls the initialization of the synthesis qmf filter
+- states */
+- MPEGS_INIT_STATES_ANA_HYB_FILTER = 0x00000400, /*!< Controls the
+- initialization of the
+- analysis hybrid filter
+- states */
+- MPEGS_INIT_STATES_DECORRELATOR =
+- 0x00000800, /*!< Controls the initialization of the decorrelator states */
+- MPEGS_INIT_STATES_M1M2 = 0x00002000, /*!< Controls the initialization of the
+- history in m1 and m2 parameter
+- calculation */
+- MPEGS_INIT_STATES_GES = 0x00004000, /*!< Controls the initialization of the
+- history in the ges calculation */
+- MPEGS_INIT_STATES_REVERB =
+- 0x00008000, /*!< Controls the initialization of the reverb states */
+- MPEGS_INIT_STATES_PARAM =
+- 0x00020000, /*!< Controls the initialization of the history of all other
+- parameter */
+- MPEGS_INIT_STATES_ERROR_CONCEALMENT =
+- 0x00080000, /*!< Controls the initialization of the error concealment
+- module state */
+- MPEGS_INIT_PARAMS_ERROR_CONCEALMENT = 0x00200000 /*!< Controls the
+- initialization of the
+- whole error concealment
+- parameter set */
+-
+-} MPEGS_INIT_CTRL_FLAGS;
+-
+-#define MASK_MPEGS_INIT_ALL_STATES (0x000FFF00)
+-#define MASK_MPEGS_INIT_ALL_PARAMS (0x00F00000)
+-
+-typedef struct spatialDec_struct spatialDec, *HANDLE_SPATIAL_DEC;
+-
+-typedef struct SPATIAL_BS_FRAME_struct SPATIAL_BS_FRAME;
+-
+-typedef struct {
+- UINT sizePersistent; /* persistent memory */
+- UINT sizeFastPersistent; /* fast persistent memory */
+-
+-} MEM_REQUIREMENTS;
+-
+-#define PCM_MPS INT_PCM
+-#define PCM_MPSF FIXP_PCM
+-
+-#define FIXP_DBL2PCM_MPS(x) ((INT_PCM)FX_DBL2FX_PCM(x))
+-
+-/* exposed functions (library interface) */
+-
+-int FDK_SpatialDecCompareSpatialSpecificConfigHeader(
+- SPATIAL_SPECIFIC_CONFIG *pSsc1, SPATIAL_SPECIFIC_CONFIG *pSsc2);
+-
+-int FDK_SpatialDecInitDefaultSpatialSpecificConfig(
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig,
+- AUDIO_OBJECT_TYPE coreCodec, int coreChannels, int samplingFreq,
+- int nTimeSlots, int decoderLevel, int isBlind);
+-
+-spatialDec *FDK_SpatialDecOpen(const SPATIAL_DEC_CONFIG *config,
+- int stereoConfigIndex);
+-
+-/**
+- * \brief Initialize state variables of the MPS parser
+- */
+-void SpatialDecInitParserContext(spatialDec *self);
+-
+-/**
+- * \brief Initialize state of MPS decoder. This may happen after the first parse
+- * operation.
+- */
+-SACDEC_ERROR FDK_SpatialDecInit(spatialDec *self, SPATIAL_BS_FRAME *frame,
+- SPATIAL_SPECIFIC_CONFIG *pSpatialSpecificConfig,
+- int nQmfBands,
+- SPATIAL_DEC_UPMIX_TYPE const upmixType,
+- SPATIALDEC_PARAM *pUserParams,
+- UINT initFlags /* MPEGS_INIT_CTRL_FLAGS */
+-);
+-
+-/**
+- * \brief Apply decoded MPEG Surround parameters to time domain or QMF down mix
+- * data.
+- * \param self spatial decoder handle.
+- * \param inData Pointer to time domain input down mix data if any.
+- * \param qmfInDataReal Pointer array of QMF domain down mix input data (real
+- * part).
+- * \param qmfInDataImag Pointer array of QMF domain down mix input data
+- * (imaginary part).
+- * \param pcmOutBuf Pointer to a time domain buffer were the upmixed output data
+- * will be stored into.
+- * \param nSamples Amount of audio samples per channel of down mix input data
+- * (frame length).
+- * \param pControlFlags pointer to control flags field; input/output.
+- * \param numInputChannels amount of down mix input channels. Might not match
+- * the current tree config, useful for internal sanity checks and bypass mode.
+- * \param channelMapping array containing the desired output channel ordering to
+- * transform MPEG PCE style ordering to any other channel ordering. First
+- * dimension is the total channel count.
+- */
+-SACDEC_ERROR SpatialDecApplyFrame(
+- spatialDec *self, SPATIAL_BS_FRAME *frame, SPATIALDEC_INPUT_MODE inputMode,
+- PCM_MPS *inData, /* Time domain input */
+- FIXP_DBL **qmfInDataReal, /* interleaved l/r */
+- FIXP_DBL **qmfInDataImag, /* interleaved l/r */
+- PCM_MPS *pcmOutBuf, /* MAX_OUTPUT_CHANNELS*MAX_TIME_SLOTS*NUM_QMF_BANDS] */
+- UINT nSamples, UINT *pControlFlags, int numInputChannels,
+- const FDK_channelMapDescr *const mapDescr);
+-
+-/**
+- * \brief Fill given arrays with audio channel types and indices.
+- * \param self spatial decoder handle.
+- * \param channelType array where corresponding channel types fr each output
+- * channels are stored into.
+- * \param channelIndices array where corresponding channel type indices fr each
+- * output channels are stored into.
+- */
+-void SpatialDecChannelProperties(spatialDec *self,
+- AUDIO_CHANNEL_TYPE channelType[],
+- UCHAR channelIndices[],
+- const FDK_channelMapDescr *const mapDescr);
+-
+-void FDK_SpatialDecClose(spatialDec *self);
+-
+-#ifdef __cplusplus
+-}
+-#endif
+-
+-#endif /* SAC_DEC_INTERFACE_H */
+diff --git a/libSACdec/src/sac_dec_lib.cpp b/libSACdec/src/sac_dec_lib.cpp
+deleted file mode 100644
+index bf6dedf..0000000
+--- a/libSACdec/src/sac_dec_lib.cpp
++++ /dev/null
+@@ -1,1995 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Decoder Library Interface
+-
+-*******************************************************************************/
+-
+-#include "sac_dec_lib.h"
+-#include "sac_dec_interface.h"
+-#include "sac_dec.h"
+-#include "sac_bitdec.h"
+-#include "FDK_matrixCalloc.h"
+-
+-#define MPS_DATA_BUFFER_SIZE (2048)
+-
+-/**
+- * \brief MPEG Surround data indication.
+- **/
+-typedef enum {
+- MPEGS_ANCTYPE_FRAME = 0, /*!< MPEG Surround frame, see ISO/IEC 23003-1 */
+- MPEGS_ANCTYPE_HEADER_AND_FRAME = 1, /*!< MPEG Surround header and MPEG
+- Surround frame, see ISO/IEC 23003-1 */
+- MPEGS_ANCTYPE_RESERVED_1 = 2, /*!< reserved, see ISO/IEC 23003-1 */
+- MPEGS_ANCTYPE_RESERVED_2 = 3 /*!< reserved, see ISO/IEC 23003-1*/
+-} MPEGS_ANCTYPE;
+-
+-/**
+- * \brief MPEG Surround data segment indication.
+- **/
+-typedef enum {
+- MPEGS_CONTINUE = 0, /*!< Indicates if data segment continues a data block. */
+- MPEGS_STOP = 1, /*!< Indicates if data segment ends a data block. */
+- MPEGS_START = 2, /*!< Indicates if data segment begins a data block. */
+- MPEGS_START_STOP =
+- 3 /*!< Indicates if data segment begins and ends a data block. */
+-} MPEGS_ANCSTARTSTOP;
+-
+-/**
+- * \brief MPEG Surround synchronizaiton state.
+- *
+- * CAUTION: Changing the enumeration values can break the sync mechanism
+- *because it is based on comparing the state values.
+- **/
+-typedef enum {
+- MPEGS_SYNC_LOST =
+- 0, /*!< Indicates lost sync because of current discontinuity. */
+- MPEGS_SYNC_FOUND = 1, /*!< Parsed a valid header and (re)intialization was
+- successfully completed. */
+- MPEGS_SYNC_COMPLETE = 2 /*!< In sync and continuous. Found an independent
+- frame in addition to MPEGS_SYNC_FOUND.
+- Precondition: MPEGS_SYNC_FOUND. */
+-} MPEGS_SYNCSTATE;
+-
+-/**
+- * \brief MPEG Surround operation mode.
+- **/
+-typedef enum {
+- MPEGS_OPMODE_EMM = 0, /*!< Mode: Enhanced Matrix Mode (Blind) */
+- MPEGS_OPMODE_MPS_PAYLOAD = 1, /*!< Mode: Normal, Stereo or Binaural */
+- MPEGS_OPMODE_NO_MPS_PAYLOAD = 2 /*!< Mode: no MPEG Surround payload */
+-} MPEGS_OPMODE;
+-
+-/**
+- * \brief MPEG Surround init flags.
+- **/
+-typedef enum {
+- MPEGS_INIT_OK = 0x00000000, /*!< indicate correct initialization */
+- MPEGS_INIT_ENFORCE_REINIT =
+- 0x00000001, /*!< indicate complete initialization */
+-
+- MPEGS_INIT_CHANGE_OUTPUT_MODE =
+- 0x00000010, /*!< indicate change of the output mode */
+- MPEGS_INIT_CHANGE_PARTIALLY_COMPLEX =
+- 0x00000020, /*!< indicate change of low power/high quality */
+- MPEGS_INIT_CHANGE_TIME_FREQ_INTERFACE =
+- 0x00000040, /*!< indicate change of qmf/time interface */
+- MPEGS_INIT_CHANGE_HEADER = 0x00000080, /*!< indicate change of header */
+-
+- MPEGS_INIT_ERROR_PAYLOAD =
+- 0x00000100, /*!< indicate payload/ancType/ancStartStop error */
+-
+- MPEGS_INIT_BS_INTERRUPTION =
+- 0x00001000, /*!< indicate bitstream interruption */
+- MPEGS_INIT_CLEAR_HISTORY =
+- 0x00002000, /*!< indicate that all states shall be cleared */
+-
+- /* Re-initialization of submodules */
+-
+- MPEGS_INIT_CHANGE_CONCEAL_PARAMS = 0x00100000, /*!< indicate a change of at
+- least one error concealment
+- param */
+-
+- /* No re-initialization needed, currently not used */
+- MPEGS_INIT_CHANGE_BYPASS_MODE =
+- 0x01000000, /*!< indicate change of bypass mode */
+-
+- /* Re-initialization needed, currently not used */
+- MPEGS_INIT_ERROR_ANC_TYPE = 0x10000000, /*!< indicate ancType error*/
+- MPEGS_INIT_ERROR_ANC_STARTSTOP =
+- 0x20000000 /*!< indicate ancStartStop error */
+-} MPEGS_INIT_FLAGS;
+-
+-struct MpegSurroundDecoder {
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain;
+- UCHAR mpsData[MPS_DATA_BUFFER_SIZE]; /* Buffer for MPS payload accross more
+- than one segment */
+- INT mpsDataBits; /* Amount of bits in mpsData */
+- /* MPEG Surround decoder */
+- SPATIAL_SPECIFIC_CONFIG spatialSpecificConfig[1]; /* SSC delay line which is
+- used during decoding */
+- spatialDec *pSpatialDec;
+- SPATIAL_SPECIFIC_CONFIG
+- spatialSpecificConfigBackup; /* SSC used while parsing */
+-
+- /* Creation parameter */
+- UCHAR mpegSurroundDecoderLevel;
+- /* Run-time parameter */
+- UCHAR mpegSurroundSscIsGlobalCfg; /* Flag telling that the SSC
+- (::spatialSpecificConfig) is a
+- out-of-band configuration. */
+- UCHAR mpegSurroundUseTimeInterface;
+-
+- SPATIAL_BS_FRAME
+- bsFrames[1]; /* Bitstream Structs that contain data read from the
+- SpatialFrame() bitstream element */
+- BS_LL_STATE llState; /* Bit stream parser state memory */
+- UCHAR bsFrameParse; /* Current parse frame context index */
+- UCHAR bsFrameDecode; /* Current decode/apply frame context index */
+- UCHAR bsFrameDelay; /* Amount of frames delay between parsing and processing.
+- Required i.e. for interpolation error concealment. */
+-
+- /* User prameters */
+- SPATIALDEC_PARAM mpegSurroundUserParams;
+-
+- /* Internal flags */
+- SPATIAL_DEC_UPMIX_TYPE upmixType;
+- int initFlags[1];
+- MPEGS_ANCSTARTSTOP ancStartStopPrev;
+- MPEGS_SYNCSTATE fOnSync[1];
+-
+- /* Inital decoder configuration */
+- SPATIAL_DEC_CONFIG decConfig;
+-};
+-
+-SACDEC_ERROR
+-static sscCheckOutOfBand(const SPATIAL_SPECIFIC_CONFIG *pSsc,
+- const INT coreCodec, const INT sampleRate,
+- const INT frameSize);
+-
+-static SACDEC_ERROR sscParseCheck(const SPATIAL_SPECIFIC_CONFIG *pSsc);
+-
+-/**
+- * \brief Get the number of QMF bands from the sampling frequency (in Hz)
+- **/
+-static int mpegSurroundDecoder_GetNrOfQmfBands(
+- const SPATIAL_SPECIFIC_CONFIG *pSsc, UINT sampleRate) {
+- UINT samplingFrequency = sampleRate;
+- int qmfBands = 64;
+-
+- if (pSsc != NULL) {
+- switch (pSsc->coreCodec) {
+- case AOT_USAC:
+- if ((pSsc->stereoConfigIndex == 3)) {
+- static const UCHAR mapIdx2QmfBands[3] = {24, 32, 16};
+- FDK_ASSERT((pSsc->coreSbrFrameLengthIndex >= 2) &&
+- (pSsc->coreSbrFrameLengthIndex <= 4));
+- qmfBands = mapIdx2QmfBands[pSsc->coreSbrFrameLengthIndex - 2];
+- }
+- return qmfBands;
+- default:
+- samplingFrequency = pSsc->samplingFreq;
+- break;
+- }
+- }
+-
+- /* number of QMF bands depend on sampling frequency, see FDIS 23003-1:2006
+- * Chapter 6.3.3 */
+- if (samplingFrequency < 27713) {
+- qmfBands = 32;
+- }
+- if (samplingFrequency > 55426) {
+- qmfBands = 128;
+- }
+-
+- return qmfBands;
+-}
+-
+-/**
+- * \brief Analyse init flags
+- **/
+-static int mpegSurroundDecoder_CalcInitFlags(SPATIAL_SPECIFIC_CONFIG *pSsc1,
+- SPATIAL_SPECIFIC_CONFIG *pSsc2,
+- int upmixTypeFlag,
+- int binauralQualityFlag,
+- int partiallyComplexFlag,
+- int *ctrlFlags) {
+- /* Analyse core coder */
+- if (pSsc1->coreCodec != pSsc2->coreCodec) {
+- *ctrlFlags |= MASK_MPEGS_INIT_ALL_STATES;
+- *ctrlFlags |= MASK_MPEGS_INIT_ALL_PARAMS;
+- } else {
+- /* Analyse elements for initialization of space analysis qmf filterbank */
+- if ((partiallyComplexFlag) || (pSsc1->treeConfig != pSsc2->treeConfig) ||
+- (pSsc1->samplingFreq != pSsc2->samplingFreq)) {
+- *ctrlFlags |= MPEGS_INIT_STATES_ANA_QMF_FILTER;
+- *ctrlFlags |= MPEGS_INIT_STATES_ANA_HYB_FILTER;
+- }
+-
+- /* Analyse elements for initialization of space synthesis qmf filterbank */
+- if ((upmixTypeFlag) || (partiallyComplexFlag) ||
+- (pSsc1->treeConfig != pSsc2->treeConfig) ||
+- (pSsc1->samplingFreq != pSsc2->samplingFreq) ||
+- (pSsc1->bsFixedGainDMX != pSsc2->bsFixedGainDMX)) {
+- *ctrlFlags |= MPEGS_INIT_STATES_SYN_QMF_FILTER;
+- }
+-
+- /* Analyse elements for initialization of decorrelator */
+- if ((upmixTypeFlag) || (partiallyComplexFlag) ||
+- (pSsc1->treeConfig != pSsc2->treeConfig) ||
+- (pSsc1->samplingFreq != pSsc2->samplingFreq) ||
+- (pSsc1->decorrConfig != pSsc2->decorrConfig)) {
+- *ctrlFlags |= MPEGS_INIT_STATES_DECORRELATOR;
+- }
+-
+- /* Analyse elements for initialization of m1 and m2 calculation */
+- if ((upmixTypeFlag) || (binauralQualityFlag) ||
+- (pSsc1->treeConfig != pSsc2->treeConfig) ||
+- (pSsc1->samplingFreq != pSsc2->samplingFreq))
+-
+- {
+- *ctrlFlags |= MPEGS_INIT_STATES_M1M2;
+- }
+-
+- /* Analyse elements for initialization of GES */
+- if ((upmixTypeFlag) || (pSsc1->treeConfig != pSsc2->treeConfig) ||
+- (pSsc1->tempShapeConfig != pSsc2->tempShapeConfig)) {
+- *ctrlFlags |= MPEGS_INIT_STATES_GES;
+- }
+-
+- /* Analyse elements for initialization of FDreverb */
+- if ((upmixTypeFlag) || (binauralQualityFlag) || (partiallyComplexFlag) ||
+- (pSsc1->samplingFreq != pSsc2->samplingFreq) ||
+- (pSsc1->nTimeSlots != pSsc2->nTimeSlots)) {
+- *ctrlFlags |= MPEGS_INIT_STATES_REVERB;
+- }
+-
+- /* Reset previous frame data whenever the config changes */
+- if (*ctrlFlags & MPEGS_INIT_CONFIG) {
+- *ctrlFlags |= MPEGS_INIT_STATES_PARAM;
+- }
+- }
+-
+- return MPS_OK;
+-}
+-
+-/**
+- * \brief Reset MPEG Surround status info
+- **/
+-static void updateMpegSurroundDecoderStatus(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, int initFlags,
+- MPEGS_SYNCSTATE fOnSync, MPEGS_ANCSTARTSTOP ancStartStopPrev) {
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] |=
+- initFlags;
+- if ((pMpegSurroundDecoder->mpegSurroundSscIsGlobalCfg != 0) &&
+- (pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameDecode] >=
+- MPEGS_SYNC_FOUND) &&
+- (fOnSync < MPEGS_SYNC_FOUND)) {
+- pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameDecode] =
+- MPEGS_SYNC_FOUND;
+- } else {
+- pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameDecode] =
+- fOnSync;
+- }
+- pMpegSurroundDecoder->ancStartStopPrev = ancStartStopPrev;
+-}
+-
+-static SACDEC_ERROR mpegSurroundDecoder_Create(
+- CMpegSurroundDecoder **pMpegSurroundDecoder, int stereoConfigIndex,
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain);
+-
+-SAC_INSTANCE_AVAIL
+-mpegSurroundDecoder_IsFullMpegSurroundDecoderInstanceAvailable(
+- CMpegSurroundDecoder *pMpegSurroundDecoder) {
+- SAC_INSTANCE_AVAIL instanceAvailable = SAC_INSTANCE_NOT_FULL_AVAILABLE;
+-
+- if (pMpegSurroundDecoder->pSpatialDec != NULL) {
+- instanceAvailable = SAC_INSTANCE_FULL_AVAILABLE;
+- }
+-
+- return instanceAvailable;
+-}
+-
+-SACDEC_ERROR mpegSurroundDecoder_Open(
+- CMpegSurroundDecoder **pMpegSurroundDecoder, int stereoConfigIndex,
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain) {
+- SACDEC_ERROR error;
+-
+- error = mpegSurroundDecoder_Create(pMpegSurroundDecoder, stereoConfigIndex,
+- pQmfDomain);
+-
+- return error;
+-}
+-
+-/**
+- * \brief Renamed function from getUpmixType to check_UParam_Build_DecConfig.
+- * This function checks if user params, decoder config and SSC are valid
+- * and if the decoder build can handle all this settings.
+- * The upmix type may be modified by this function.
+- * It is called in initMpegSurroundDecoder() after the ssc parse check,
+- * to have all checks in one place and to ensure these checks are always
+- * performed if config changes (inband and out-of-band).
+- *
+- * \param pUserParams User data handle.
+- * \param pDecConfig decoder config handle.
+- * \param pSsc spatial specific config handle.
+- * \param pUpmixType upmix type which is set by this function
+- *
+- * \return MPS_OK on sucess, and else on failure.
+- */
+-static SACDEC_ERROR check_UParam_Build_DecConfig(
+- SPATIALDEC_PARAM const *pUserParams, SPATIAL_DEC_CONFIG const *pDecConfig,
+- const SPATIAL_SPECIFIC_CONFIG *pSsc, SPATIAL_DEC_UPMIX_TYPE *pUpmixType) {
+- int dmxChannels, outChannels, maxNumOutChannels;
+-
+- FDK_ASSERT(pUserParams != NULL);
+- FDK_ASSERT(pUpmixType != NULL);
+-
+- /* checks if implementation can handle the Ssc */
+-
+- switch (pSsc->treeConfig) {
+- case SPATIALDEC_MODE_RSVD7: /* 212 */
+- dmxChannels = 1;
+- outChannels = 2;
+- break;
+- default:
+- return MPS_UNSUPPORTED_CONFIG;
+- }
+-
+- /* ------------------------------------------- */
+-
+- /* Analyse pDecConfig params */
+- switch (pDecConfig->binauralMode) {
+- case BINAURAL_NONE:
+- break;
+- default:
+- return MPS_UNSUPPORTED_CONFIG;
+- }
+-
+- switch (pDecConfig->decoderMode) {
+- case EXT_HQ_ONLY:
+- break;
+- default:
+- return MPS_UNSUPPORTED_CONFIG;
+- }
+-
+- switch (pDecConfig->maxNumOutputChannels) {
+- case OUTPUT_CHANNELS_DEFAULT:
+- /* No special restrictions -> Get the level restriction: */
+- switch (pDecConfig->decoderLevel) {
+- case DECODER_LEVEL_0:
+- maxNumOutChannels = 2;
+- break;
+- default:
+- return MPS_UNSUPPORTED_CONFIG;
+- }
+- break;
+- case OUTPUT_CHANNELS_2_0:
+- maxNumOutChannels = 2;
+- break;
+- default:
+- return MPS_UNSUPPORTED_CONFIG;
+- }
+- /* ------------------------- */
+-
+- /* check if we can handle user params */
+- if (pUserParams->blindEnable == 1) {
+- return MPS_UNSUPPORTED_CONFIG;
+- }
+- {
+- switch ((SAC_DEC_OUTPUT_MODE)pUserParams->outputMode) {
+- case SACDEC_OUT_MODE_NORMAL:
+- if (maxNumOutChannels >= outChannels) {
+- *pUpmixType = UPMIX_TYPE_NORMAL;
+- } else {
+- { *pUpmixType = UPMIX_TYPE_BYPASS; }
+- }
+- break;
+- case SACDEC_OUT_MODE_STEREO:
+- if (dmxChannels == 1) {
+- if (outChannels == 2) {
+- *pUpmixType = UPMIX_TYPE_NORMAL;
+- }
+- } else {
+- *pUpmixType = UPMIX_TYPE_BYPASS;
+- }
+- break;
+- case SACDEC_OUT_MODE_6CHANNEL:
+- if (outChannels > 6) {
+- { *pUpmixType = UPMIX_TYPE_BYPASS; }
+- } else {
+- *pUpmixType = UPMIX_TYPE_NORMAL;
+- }
+- break;
+- default:
+- return MPS_UNSUPPORTED_CONFIG;
+- }
+- }
+-
+- return MPS_OK;
+-}
+-
+-/**
+- * \brief Init MPEG Surround decoder.
+- **/
+-static SACDEC_ERROR initMpegSurroundDecoder(
+- CMpegSurroundDecoder *pMpegSurroundDecoder) {
+- SACDEC_ERROR err;
+- int initFlags = MPEGS_INIT_NONE, initFlagsDec;
+- int upmixTypeCurr = pMpegSurroundDecoder->upmixType;
+-
+- FDK_ASSERT(pMpegSurroundDecoder != NULL);
+-
+- SPATIAL_SPECIFIC_CONFIG *const pSSCinput =
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup;
+- SPATIAL_SPECIFIC_CONFIG *const pSSCtarget =
+- &pMpegSurroundDecoder
+- ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameDecode];
+- initFlagsDec =
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode];
+-
+- if (pSSCinput->coreCodec != AOT_USAC) {
+- /* here we check if we have a valid Ssc */
+- err = sscParseCheck(pSSCinput);
+- if (err != MPS_OK) goto bail;
+- }
+-
+- /* here we check if Ssc matches build; also check UParams and DecConfig */
+- /* if desired upmixType is changes */
+- err = check_UParam_Build_DecConfig(
+- &pMpegSurroundDecoder->mpegSurroundUserParams,
+- &pMpegSurroundDecoder->decConfig, pSSCinput,
+- &pMpegSurroundDecoder->upmixType);
+- if (err != MPS_OK) goto bail;
+-
+- /* init config */
+- if (initFlagsDec & MPEGS_INIT_CHANGE_HEADER) {
+- initFlags |= MPEGS_INIT_CONFIG;
+- }
+- /* init all states */
+- if (initFlagsDec & MPEGS_INIT_CLEAR_HISTORY) {
+- initFlags |= MASK_MPEGS_INIT_ALL_STATES;
+- }
+- if (initFlagsDec & MPEGS_INIT_CHANGE_CONCEAL_PARAMS) {
+- initFlags |= MPEGS_INIT_PARAMS_ERROR_CONCEALMENT;
+- }
+-
+- if (initFlagsDec & MPEGS_INIT_ENFORCE_REINIT) {
+- /* init all states */
+- initFlags |= MASK_MPEGS_INIT_ALL_STATES;
+- initFlags |= MASK_MPEGS_INIT_ALL_PARAMS;
+- } else {
+- /* analyse states which have to be initialized */
+- mpegSurroundDecoder_CalcInitFlags(
+- pSSCtarget, pSSCinput,
+- (upmixTypeCurr !=
+- pMpegSurroundDecoder->upmixType), /* upmixType changed */
+- 0, (initFlagsDec & MPEGS_INIT_CHANGE_PARTIALLY_COMPLEX) ? 1 : 0,
+- &initFlags);
+- }
+-
+- {
+- int nrOfQmfBands;
+- FDKmemcpy(pSSCtarget, pSSCinput, sizeof(SPATIAL_SPECIFIC_CONFIG));
+-
+- nrOfQmfBands = mpegSurroundDecoder_GetNrOfQmfBands(
+- pSSCtarget, pSSCtarget->samplingFreq);
+- err = FDK_SpatialDecInit(
+- pMpegSurroundDecoder->pSpatialDec,
+- &pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameDecode],
+- pSSCtarget, nrOfQmfBands, pMpegSurroundDecoder->upmixType,
+- &pMpegSurroundDecoder->mpegSurroundUserParams, initFlags);
+-
+- if (err != MPS_OK) goto bail;
+-
+- /* Signal that we got a header and can go on decoding */
+- if (err == MPS_OK) {
+- initFlagsDec = MPEGS_INIT_OK;
+- {
+- pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameDecode] =
+- MPEGS_SYNC_FOUND;
+- }
+- }
+- }
+-
+-bail:
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] =
+- initFlagsDec;
+- return err;
+-}
+-
+-/**
+- * \brief Init MPEG Surround decoder.
+- **/
+-SACDEC_ERROR mpegSurroundDecoder_Init(
+- CMpegSurroundDecoder *pMpegSurroundDecoder) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- if (pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode]) {
+- err = initMpegSurroundDecoder(pMpegSurroundDecoder);
+- }
+- return err;
+-}
+-
+-/**
+- * \brief Open MPEG Surround decoder.
+- **/
+-static SACDEC_ERROR mpegSurroundDecoder_Create(
+- CMpegSurroundDecoder **pMpegSurroundDecoder, int stereoConfigIndex,
+- HANDLE_FDK_QMF_DOMAIN pQmfDomain) {
+- SACDEC_ERROR err = MPS_OK;
+- CMpegSurroundDecoder *sacDec = NULL;
+- spatialDec *self = NULL;
+-
+- /* decoderLevel decoderMode maxNumOutputChannels binauralMode */
+- static const SPATIAL_DEC_CONFIG decConfig = {
+- (CFG_LEVEL)(0), EXT_HQ_ONLY, OUTPUT_CHANNELS_DEFAULT, BINAURAL_NONE};
+-
+- if (*pMpegSurroundDecoder == NULL) {
+- FDK_ALLOCATE_MEMORY_1D(*pMpegSurroundDecoder, 1, CMpegSurroundDecoder)
+-
+- for (int i = 0; i < 1; i++) {
+- err = SpatialDecCreateBsFrame(&(*pMpegSurroundDecoder)->bsFrames[i],
+- &(*pMpegSurroundDecoder)->llState);
+- if (err != MPS_OK) {
+- sacDec = *pMpegSurroundDecoder;
+- goto bail;
+- }
+- }
+- (*pMpegSurroundDecoder)->pQmfDomain = pQmfDomain;
+-
+- (*pMpegSurroundDecoder)->bsFrameDelay = 1;
+- (*pMpegSurroundDecoder)->bsFrameParse = 0;
+- (*pMpegSurroundDecoder)->bsFrameDecode = 0;
+-
+- return err;
+- } else {
+- sacDec = *pMpegSurroundDecoder;
+- }
+-
+- if (sacDec->pSpatialDec == NULL) {
+- if ((self = FDK_SpatialDecOpen(&decConfig, stereoConfigIndex)) == NULL) {
+- err = MPS_OUTOFMEMORY;
+- goto bail;
+- }
+- } else {
+- self = sacDec->pSpatialDec;
+- }
+-
+- self->pQmfDomain = sacDec->pQmfDomain;
+-
+- sacDec->pSpatialDec = self;
+-
+- /* default parameter set */
+- sacDec->mpegSurroundUserParams.outputMode = SACDEC_OUT_MODE_NORMAL;
+- sacDec->mpegSurroundUserParams.blindEnable = 0;
+- sacDec->mpegSurroundUserParams.bypassMode = 0;
+- sacDec->mpegSurroundUserParams.concealMethod = 1;
+- sacDec->mpegSurroundUserParams.concealNumKeepFrames = 10;
+- sacDec->mpegSurroundUserParams.concealFadeOutSlopeLength = 5;
+- sacDec->mpegSurroundUserParams.concealFadeInSlopeLength = 5;
+- sacDec->mpegSurroundUserParams.concealNumReleaseFrames = 3;
+- sacDec->mpegSurroundSscIsGlobalCfg = 0;
+- sacDec->mpegSurroundUseTimeInterface = 1;
+- sacDec->mpegSurroundDecoderLevel = decConfig.decoderLevel;
+-
+- sacDec->upmixType = UPMIX_TYPE_NORMAL;
+-
+- /* signalize spatial decoder re-initalization */
+- updateMpegSurroundDecoderStatus(sacDec, MPEGS_INIT_ENFORCE_REINIT,
+- MPEGS_SYNC_LOST, MPEGS_STOP);
+-
+- /* return decoder instance */
+- *pMpegSurroundDecoder = sacDec;
+- sacDec->decConfig = decConfig;
+-
+- SpatialDecInitParserContext(sacDec->pSpatialDec);
+-
+- return err;
+-
+-bail:
+- if (sacDec != NULL) {
+- mpegSurroundDecoder_Close(sacDec);
+- }
+- *pMpegSurroundDecoder = NULL;
+- if (err == MPS_OK) {
+- return MPS_OUTOFMEMORY;
+- } else {
+- return err;
+- }
+-}
+-
+-/**
+- * \brief Config MPEG Surround decoder.
+- **/
+-SACDEC_ERROR mpegSurroundDecoder_Config(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, HANDLE_FDK_BITSTREAM hBs,
+- AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT frameSize,
+- INT stereoConfigIndex, INT coreSbrFrameLengthIndex, INT configBytes,
+- const UCHAR configMode, UCHAR *configChanged) {
+- SACDEC_ERROR err = MPS_OK;
+- SPATIAL_SPECIFIC_CONFIG spatialSpecificConfig;
+- SPATIAL_SPECIFIC_CONFIG *pSsc =
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup;
+-
+- switch (coreCodec) {
+- case AOT_DRM_USAC:
+- case AOT_USAC:
+- if (configMode == AC_CM_DET_CFG_CHANGE) {
+- /* In config detection mode write spatial specific config parameters
+- * into temporarily allocated structure */
+- err = SpatialDecParseMps212Config(
+- hBs, &spatialSpecificConfig, samplingRate, coreCodec,
+- stereoConfigIndex, coreSbrFrameLengthIndex);
+- pSsc = &spatialSpecificConfig;
+- } else {
+- err = SpatialDecParseMps212Config(
+- hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup,
+- samplingRate, coreCodec, stereoConfigIndex,
+- coreSbrFrameLengthIndex);
+- }
+- break;
+- case AOT_ER_AAC_ELD:
+- case AOT_ER_AAC_LD:
+- if (configMode == AC_CM_DET_CFG_CHANGE) {
+- /* In config detection mode write spatial specific config parameters
+- * into temporarily allocated structure */
+- err = SpatialDecParseSpecificConfig(hBs, &spatialSpecificConfig,
+- configBytes, coreCodec);
+- pSsc = &spatialSpecificConfig;
+- } else {
+- err = SpatialDecParseSpecificConfig(
+- hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup,
+- configBytes, coreCodec);
+- }
+- break;
+- default:
+- err = MPS_UNSUPPORTED_FORMAT;
+- break;
+- }
+-
+- if (err != MPS_OK) {
+- goto bail;
+- }
+-
+- err = sscCheckOutOfBand(pSsc, coreCodec, samplingRate, frameSize);
+-
+- if (err != MPS_OK) {
+- goto bail;
+- }
+-
+- if (configMode & AC_CM_DET_CFG_CHANGE) {
+- return err;
+- }
+-
+- if (configMode & AC_CM_ALLOC_MEM) {
+- if (*configChanged) {
+- err = mpegSurroundDecoder_Open(&pMpegSurroundDecoder, stereoConfigIndex,
+- NULL);
+- if (err) {
+- return err;
+- }
+- }
+- }
+-
+- {
+- SPATIAL_SPECIFIC_CONFIG *sscParse =
+- &pMpegSurroundDecoder
+- ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameParse];
+-
+- if (FDK_SpatialDecCompareSpatialSpecificConfigHeader(
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup, sscParse)) {
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameParse] |=
+- MPEGS_INIT_CHANGE_HEADER;
+- /* Error resilience code */
+- if (pMpegSurroundDecoder->pSpatialDec == NULL) {
+- err = MPS_NOTOK;
+- goto bail;
+- }
+- SpatialDecInitParserContext(pMpegSurroundDecoder->pSpatialDec);
+- pMpegSurroundDecoder->pSpatialDec->pConfigCurrent =
+- &pMpegSurroundDecoder
+- ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameDecode];
+- }
+- }
+-
+- if (err == MPS_OK) {
+- /* We got a valid out-of-band configuration so label it accordingly. */
+- pMpegSurroundDecoder->mpegSurroundSscIsGlobalCfg = 1;
+- }
+-
+-bail:
+- return err;
+-}
+-
+-/**
+- * \brief Determine MPEG Surround operation mode.
+- **/
+-static MPEGS_OPMODE mpegSurroundOperationMode(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, int mpsDataBits) {
+- MPEGS_OPMODE mode;
+-
+- {
+- if ((mpsDataBits > 0) &&
+- (pMpegSurroundDecoder->mpegSurroundUserParams.blindEnable == 0)) {
+- mode = MPEGS_OPMODE_MPS_PAYLOAD; /* Mode: Normal, Stereo or Binaural */
+- } else {
+- mode = MPEGS_OPMODE_NO_MPS_PAYLOAD; /* Mode: No MPEG Surround Payload */
+- updateMpegSurroundDecoderStatus(pMpegSurroundDecoder,
+- MPEGS_INIT_ERROR_PAYLOAD, MPEGS_SYNC_LOST,
+- MPEGS_STOP);
+- }
+- }
+-
+- return (mode);
+-}
+-
+-/**
+- * \brief Check ssc for parse errors.
+- * This one is called in initMpegSurroundDecoder()
+- * to ensure checking of inband and out-of-band mps configs.
+- * Only parse errors checked here! Check for valid config is done
+- * in check_UParam_Build_DecConfig()!
+- *
+- * \param pSsc spatial specific config handle.
+- *
+- * \return MPS_OK on sucess, and else on parse error.
+- */
+-static SACDEC_ERROR sscParseCheck(const SPATIAL_SPECIFIC_CONFIG *pSsc) {
+- if (pSsc->samplingFreq > 96000) return MPS_PARSE_ERROR;
+- if (pSsc->samplingFreq < 8000) return MPS_PARSE_ERROR;
+-
+- if ((pSsc->treeConfig < 0) || (pSsc->treeConfig > 7)) {
+- return MPS_PARSE_ERROR;
+- }
+-
+- if ((pSsc->quantMode < 0) || (pSsc->quantMode > 2)) {
+- return MPS_PARSE_ERROR;
+- }
+-
+- /* now we are sure there were no parsing errors */
+-
+- return MPS_OK;
+-}
+-
+-/**
+- * \brief Check number of time slots
+- *
+- * Basically the mps frame length must be a multiple of the core coder frame
+- * length. The below table shows all valid configurations in detail. See ISO/IEC
+- * 23003-1: "Table 4A - Allowed values for bsFrameLength in the Baseline MPEG
+- * Surround Profile"
+- *
+- * Downmix Coder Downmix Code Allowed values for bsFrameLength
+- * Allowed frame sizes for normal, downsampled and upsampled MPS Framelength
+- * (QMF Samples)
+- *
+- * AAC 1024 16 15, 31, 47, 63 1024 2048 3072 4096
+- * downsampled MPS 32 31, 63 1024 2048 upsampled MPS
+- * 8 7, 15, 23, 31, 39, 47, 55, 63, 71 1024 2048 3072 4096
+- * 5120 6144 7168 8192 9216
+- *
+- * AAC 960 15 14, 29, 44, 59 960 1920 2880 3840
+- * downsampled MPS 30 29, 59 960 1920 upsampled MPS
+- * 7,5 14, 29, 44, 59 1920 3840 5760 7680
+- *
+- * HE-AAC 1024/2048 32 31, 63 2048 4096 downsampled MPS
+- * 64 63 2048 upsampled MPS
+- * 16 15, 31, 47, 63 2048 4096 6144 8192
+- *
+- * HE-AAC 960/1920 30 29, 59 1920 3840 downsampled MPS
+- * 60 59 1920 upsampled MPS
+- * 15 14, 29, 44, 59 1920 3840 5760 7680
+- *
+- * BSAC 16 15, 31, 47, 63 1024 2048 3072 4096
+- * downsampled MPS 32 31, 63 1024 2048 upsampled MPS
+- * 8 7, 15, 23, 31, 39, 47, 55, 63, 71 1024 2048 3072 4096
+- * 5120 6144 7168 8192 9216
+- *
+- * BSAC with SBR 32 31, 63 2048 4096 downsampled MPS
+- * 64 63 2048 upsampled MPS
+- * 16 15, 31, 47, 63 2048 4096 6144 8192
+- *
+- * AAC LD 512 8 7, 15, 23, 31, 39, 47, 55, 63, 71
+- * 512 1024 1536 2048 2560 3072 3584 4096 4608 downsampled MPS
+- * 16 15, 31, 47, 63 512 1024 1536 2048
+- *
+- * AAC ELD 512 8 7, 15, 23, 31, 39, 47, 55, 63, 71
+- * 512 1024 1536 2048 2560 3072 3584 4096 4608 downsampled MPS
+- * 16 15, 31, 47, 63 512 1024 1536 2048
+- *
+- * AAC ELD with SBR 512/1024 16 15, 31, 47, 63 1024 2048 3072 4096
+- * downsampled MPS 32 31, 63 1024 2048 upsampled MPS
+- * 8 7, 15, 23, 31, 39, 47, 55, 63, 71 1024 2048 3072 4096
+- * 5120 6144 7168 8192 9216
+- *
+- * MPEG1/2 Layer II 18 17, 35, 53, 71 1152 2304 3456 4608
+- * downsampled MPS 36 35, 71 1152 2304
+- *
+- * MPEG1/2 Layer III 18 17, 35, 53, 71 1152 2304 3456 4608
+- * downsampled MPS 36 35, 71 1152 2304
+- *
+- * \param frameLength
+- * \param qmfBands
+- * \param timeSlots
+- *
+- * \return error code
+- */
+-SACDEC_ERROR checkTimeSlots(int frameLength, int qmfBands, int timeSlots) {
+- int len;
+- int maxFrameLength;
+-
+- if (qmfBands == 64) {
+- /* normal MPEG Surround */
+- switch (frameLength) {
+- case 960:
+- case 1920:
+- maxFrameLength = 3840;
+- break;
+- case 1024:
+- case 2048:
+- maxFrameLength = 4096;
+- break;
+- case 512:
+- case 1152:
+- maxFrameLength = 4608;
+- break;
+- default:
+- return MPS_PARSE_ERROR;
+- }
+- } else if (qmfBands == 32) {
+- /* downsampled MPEG Surround */
+- switch (frameLength) {
+- case 960:
+- case 1920:
+- maxFrameLength = 1920;
+- break;
+- case 512:
+- case 1024:
+- case 2048:
+- maxFrameLength = 2048;
+- break;
+- case 1152:
+- maxFrameLength = 2304;
+- break;
+- default:
+- return MPS_PARSE_ERROR;
+- }
+- } else if (qmfBands == 128) {
+- /* upsampled MPEG Surround */
+- switch (frameLength) {
+- case 1920:
+- maxFrameLength = 7680;
+- break;
+- case 1024:
+- maxFrameLength = 9216;
+- break;
+- case 2048:
+- maxFrameLength = 8192;
+- break;
+- case 512:
+- case 960:
+- case 1152:
+- /* no break, no support for upsampled MPEG Surround */
+- default:
+- return MPS_PARSE_ERROR;
+- }
+- } else {
+- return MPS_PARSE_ERROR;
+- }
+-
+- len = frameLength;
+-
+- while (len <= maxFrameLength) {
+- if (len == timeSlots * qmfBands) {
+- return MPS_OK;
+- }
+- len += frameLength;
+- }
+- return MPS_PARSE_ERROR;
+-}
+-
+-/**
+- * \brief Check ssc for consistency (e.g. bit errors could cause trouble)
+- * First of currently two ssc-checks.
+- * This (old) one is called in mpegSurroundDecoder_Apply()
+- * only if inband mps config is contained in stream.
+- *
+- * New ssc check is split in two functions sscParseCheck() and
+- * check_UParam_Build_DecConfig(). sscParseCheck() checks only for correct
+- * parsing. check_UParam_Build_DecConfig() is used to check if we have a
+- * valid config. Both are called in initMpegSurroundDecoder() to ensure
+- * checking of inband and out-of-band mps configs.
+- *
+- * If this function can be integrated into the new functions.
+- * We can remove this one.
+- *
+- * \param pSsc spatial specific config handle.
+- * \param frameLength
+- * \param sampleRate
+- *
+- * \return MPS_OK on sucess, and else on failure.
+- */
+-static SACDEC_ERROR sscCheckInBand(SPATIAL_SPECIFIC_CONFIG *pSsc,
+- int frameLength, int sampleRate) {
+- SACDEC_ERROR err = MPS_OK;
+- int qmfBands;
+-
+- FDK_ASSERT(pSsc != NULL);
+-
+- /* check ssc for parse errors */
+- if (sscParseCheck(pSsc) != MPS_OK) {
+- err = MPS_PARSE_ERROR;
+- }
+-
+- /* core fs and mps fs must match */
+- if (pSsc->samplingFreq != sampleRate) {
+- err = MPS_PARSE_ERROR /* MPEGSDEC_SSC_PARSE_ERROR */;
+- }
+-
+- qmfBands = mpegSurroundDecoder_GetNrOfQmfBands(pSsc, pSsc->samplingFreq);
+-
+- if (checkTimeSlots(frameLength, qmfBands, pSsc->nTimeSlots) != MPS_OK) {
+- err = MPS_PARSE_ERROR;
+- }
+-
+- return err;
+-}
+-
+-SACDEC_ERROR
+-mpegSurroundDecoder_ConfigureQmfDomain(
+- CMpegSurroundDecoder *pMpegSurroundDecoder,
+- SAC_INPUT_CONFIG sac_dec_interface, UINT coreSamplingRate,
+- AUDIO_OBJECT_TYPE coreCodec) {
+- SACDEC_ERROR err = MPS_OK;
+- FDK_QMF_DOMAIN_GC *pGC = NULL;
+-
+- if (pMpegSurroundDecoder == NULL) {
+- return MPS_INVALID_HANDLE;
+- }
+-
+- FDK_ASSERT(pMpegSurroundDecoder->pSpatialDec);
+-
+- pGC = &pMpegSurroundDecoder->pQmfDomain->globalConf;
+- if (pMpegSurroundDecoder->mpegSurroundSscIsGlobalCfg) {
+- SPATIAL_SPECIFIC_CONFIG *pSSC =
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup;
+- if (sac_dec_interface == SAC_INTERFACE_TIME) {
+- /* For SAC_INTERFACE_QMF these parameters are set by SBR. */
+- pGC->nBandsAnalysis_requested = mpegSurroundDecoder_GetNrOfQmfBands(
+- pSSC, coreSamplingRate); /* coreSamplingRate == outputSamplingRate for
+- SAC_INTERFACE_TIME */
+- pGC->nBandsSynthesis_requested = pGC->nBandsAnalysis_requested;
+- pGC->nInputChannels_requested =
+- fMax((UINT)pSSC->nInputChannels, (UINT)pGC->nInputChannels_requested);
+- }
+- pGC->nOutputChannels_requested =
+- fMax((UINT)pSSC->nOutputChannels, (UINT)pGC->nOutputChannels_requested);
+- } else {
+- if (sac_dec_interface == SAC_INTERFACE_TIME) {
+- /* For SAC_INTERFACE_QMF these parameters are set by SBR. */
+- pGC->nBandsAnalysis_requested = mpegSurroundDecoder_GetNrOfQmfBands(
+- NULL, coreSamplingRate); /* coreSamplingRate == outputSamplingRate for
+- SAC_INTERFACE_TIME */
+- pGC->nBandsSynthesis_requested = pGC->nBandsAnalysis_requested;
+- pGC->nInputChannels_requested =
+- pMpegSurroundDecoder->pSpatialDec->createParams.maxNumInputChannels;
+- }
+- pGC->nOutputChannels_requested =
+- pMpegSurroundDecoder->pSpatialDec->createParams.maxNumOutputChannels;
+- }
+- pGC->nQmfProcBands_requested = 64;
+- pGC->nQmfProcChannels_requested =
+- fMin((INT)pGC->nInputChannels_requested,
+- pMpegSurroundDecoder->pSpatialDec->createParams.maxNumInputChannels);
+-
+- if (coreCodec == AOT_ER_AAC_ELD) {
+- pGC->flags_requested |= QMF_FLAG_MPSLDFB;
+- pGC->flags_requested &= ~QMF_FLAG_CLDFB;
+- }
+-
+- return err;
+-}
+-
+-/**
+- * \brief Check out-of-band config
+- *
+- * \param pSsc spatial specific config handle.
+- * \param coreCodec core codec.
+- * \param sampleRate sampling frequency.
+- *
+- * \return errorStatus
+- */
+-SACDEC_ERROR
+-sscCheckOutOfBand(const SPATIAL_SPECIFIC_CONFIG *pSsc, const INT coreCodec,
+- const INT sampleRate, const INT frameSize) {
+- FDK_ASSERT(pSsc != NULL);
+- int qmfBands = 0;
+-
+- /* check ssc for parse errors */
+- if (sscParseCheck(pSsc) != MPS_OK) {
+- return MPS_PARSE_ERROR;
+- }
+-
+- switch (coreCodec) {
+- case AOT_USAC:
+- case AOT_DRM_USAC:
+- /* ISO/IEC 23003-1:2007(E), Chapter 6.3.3, Support for lower and higher
+- * sampling frequencies */
+- if (pSsc->samplingFreq >= 55426) {
+- return MPS_PARSE_ERROR;
+- }
+- break;
+- case AOT_ER_AAC_LD:
+- case AOT_ER_AAC_ELD:
+- /* core fs and mps fs must match */
+- if (pSsc->samplingFreq != sampleRate) {
+- return MPS_PARSE_ERROR;
+- }
+-
+- /* ISO/IEC 14496-3:2009 FDAM 3: Chapter 1.5.2.3, Levels for the Low Delay
+- * AAC v2 profile */
+- if (pSsc->samplingFreq > 48000) {
+- return MPS_PARSE_ERROR;
+- }
+-
+- qmfBands = mpegSurroundDecoder_GetNrOfQmfBands(pSsc, pSsc->samplingFreq);
+- switch (frameSize) {
+- case 480:
+- if (!((qmfBands == 32) && (pSsc->nTimeSlots == 15))) {
+- return MPS_PARSE_ERROR;
+- }
+- break;
+- case 960:
+- if (!((qmfBands == 64) && (pSsc->nTimeSlots == 15))) {
+- return MPS_PARSE_ERROR;
+- }
+- break;
+- case 512:
+- if (!(((qmfBands == 32) && (pSsc->nTimeSlots == 16)) ||
+- ((qmfBands == 64) && (pSsc->nTimeSlots == 8)))) {
+- return MPS_PARSE_ERROR;
+- }
+- break;
+- case 1024:
+- if (!((qmfBands == 64) && (pSsc->nTimeSlots == 16))) {
+- return MPS_PARSE_ERROR;
+- }
+- break;
+- default:
+- return MPS_PARSE_ERROR;
+- }
+- break;
+- default:
+- return MPS_PARSE_ERROR;
+- break;
+- }
+-
+- return MPS_OK;
+-}
+-
+-/**
+- * \brief Decode MPEG Surround frame.
+- **/
+-int mpegSurroundDecoder_ParseNoHeader(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, HANDLE_FDK_BITSTREAM hBs,
+- int *pMpsDataBits, int fGlobalIndependencyFlag) {
+- SACDEC_ERROR err = MPS_OK;
+- SPATIAL_SPECIFIC_CONFIG *sscParse;
+- int bitsAvail, numSacBits;
+-
+- if (pMpegSurroundDecoder == NULL || hBs == NULL) {
+- return MPS_INVALID_HANDLE;
+- }
+-
+- sscParse = &pMpegSurroundDecoder
+- ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameParse];
+-
+- bitsAvail = FDKgetValidBits(hBs);
+-
+- /* First spatial specific config is parsed into spatialSpecificConfigBackup,
+- * second spatialSpecificConfigBackup is copied into
+- * spatialSpecificConfig[bsFrameDecode] */
+- if (pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameParse]) {
+- FDKmemcpy(sscParse, &pMpegSurroundDecoder->spatialSpecificConfigBackup,
+- sizeof(SPATIAL_SPECIFIC_CONFIG));
+- pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameParse] =
+- MPEGS_SYNC_FOUND;
+- }
+-
+- if (bitsAvail <= 0) {
+- err = MPS_PARSE_ERROR;
+- } else {
+- err = SpatialDecParseFrameData(
+- pMpegSurroundDecoder->pSpatialDec,
+- &pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameParse],
+- hBs, sscParse, (UPMIXTYPE)pMpegSurroundDecoder->upmixType,
+- fGlobalIndependencyFlag);
+- if (err == MPS_OK) {
+- pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameParse]
+- .newBsData = 1;
+- }
+- }
+-
+- numSacBits = bitsAvail - (INT)FDKgetValidBits(hBs);
+-
+- if (numSacBits > bitsAvail) {
+- pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameParse]
+- .newBsData = 0;
+- err = MPS_PARSE_ERROR;
+- }
+-
+- *pMpsDataBits -= numSacBits;
+-
+- return err;
+-}
+-
+-/**
+- * \brief Check, if ancType is valid.
+- **/
+-static int isValidAncType(CMpegSurroundDecoder *pMpegSurroundDecoder,
+- int ancType) {
+- int ret = 1;
+-
+- if ((ancType != MPEGS_ANCTYPE_HEADER_AND_FRAME) &&
+- (ancType != MPEGS_ANCTYPE_FRAME)) {
+- ret = 0;
+- }
+-
+- if (ret == 0) {
+- updateMpegSurroundDecoderStatus(pMpegSurroundDecoder,
+- MPEGS_INIT_ERROR_PAYLOAD, MPEGS_SYNC_LOST,
+- MPEGS_STOP);
+- }
+-
+- return (ret);
+-}
+-
+-/**
+- * \brief Check, if ancStartStop is valid.
+- **/
+-static int isValidAncStartStop(CMpegSurroundDecoder *pMpegSurroundDecoder,
+- int ancStartStop) {
+- int ret = 1;
+-
+- switch (ancStartStop) {
+- case MPEGS_START:
+- /* Sequence start - start and continue - start not allowed */
+- if ((pMpegSurroundDecoder->ancStartStopPrev == MPEGS_START) ||
+- (pMpegSurroundDecoder->ancStartStopPrev == MPEGS_CONTINUE)) {
+- ret = 0;
+- }
+- break;
+-
+- case MPEGS_STOP:
+- /* MPS payload of the previous frame must be valid if current type is stop
+- Sequence startstop - stop and stop - stop not allowed
+- Sequence startstop - continue and stop - continue are allowed */
+- if ((pMpegSurroundDecoder->ancStartStopPrev == MPEGS_STOP) ||
+- (pMpegSurroundDecoder->ancStartStopPrev == MPEGS_START_STOP)) {
+- ret = 0;
+- }
+- break;
+-
+- case MPEGS_CONTINUE:
+- case MPEGS_START_STOP:
+- /* No error detection possible for this states */
+- break;
+- }
+-
+- if (ret == 0) {
+- updateMpegSurroundDecoderStatus(pMpegSurroundDecoder,
+- MPEGS_INIT_ERROR_PAYLOAD, MPEGS_SYNC_LOST,
+- MPEGS_STOP);
+- } else {
+- pMpegSurroundDecoder->ancStartStopPrev = (MPEGS_ANCSTARTSTOP)ancStartStop;
+- }
+-
+- return (ret);
+-}
+-
+-int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder,
+- HANDLE_FDK_BITSTREAM hBs, int *pMpsDataBits,
+- AUDIO_OBJECT_TYPE coreCodec, int sampleRate,
+- int frameSize, int fGlobalIndependencyFlag) {
+- SACDEC_ERROR err = MPS_OK;
+- SPATIAL_SPECIFIC_CONFIG *sscParse;
+- SPATIAL_BS_FRAME *bsFrame;
+- HANDLE_FDK_BITSTREAM hMpsBsData = NULL;
+- FDK_BITSTREAM mpsBsData;
+- int mpsDataBits = *pMpsDataBits;
+- int mpsBsBits;
+- MPEGS_ANCTYPE ancType;
+- MPEGS_ANCSTARTSTOP ancStartStop;
+-
+- if (pMpegSurroundDecoder == NULL) {
+- return MPS_INVALID_HANDLE;
+- }
+-
+- FDK_ASSERT(pMpegSurroundDecoder->pSpatialDec);
+-
+- mpsBsBits = (INT)FDKgetValidBits(hBs);
+-
+- sscParse = &pMpegSurroundDecoder
+- ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameParse];
+- bsFrame = &pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameParse];
+-
+- /*
+- Find operation mode of mpeg surround decoder:
+- - MPEGS_OPMODE_EMM: Mode: Enhanced Matrix Mode (Blind)
+- - MPEGS_OPMODE_MPS_PAYLOAD: Mode: Normal, Stereo or Binaural
+- - MPEGS_OPMODE_NO_MPS_PAYLOAD: Mode: No MpegSurround Payload
+- */
+- {
+- /* Parse ancType and ancStartStop */
+- ancType = (MPEGS_ANCTYPE)FDKreadBits(hBs, 2);
+- ancStartStop = (MPEGS_ANCSTARTSTOP)FDKreadBits(hBs, 2);
+- mpsDataBits -= 4;
+-
+- /* Set valid anc type flag, if ancType signals a payload with either header
+- * and frame or frame */
+- if (isValidAncType(pMpegSurroundDecoder, ancType)) {
+- /* Set valid anc startstop flag, if transmitted sequence is not illegal */
+- if (isValidAncStartStop(pMpegSurroundDecoder, ancStartStop)) {
+- switch (ancStartStop) {
+- case MPEGS_START:
+- /* Assuming that core coder frame size (AAC) is smaller than MPS
+- coder frame size. Save audio data for next frame. */
+- if (mpsDataBits > MPS_DATA_BUFFER_SIZE * 8) {
+- err = MPS_NOTOK;
+- goto bail;
+- }
+- for (int i = 0; i < mpsDataBits / 8; i++) {
+- pMpegSurroundDecoder->mpsData[i] = FDKreadBits(hBs, 8);
+- }
+- pMpegSurroundDecoder->mpsDataBits = mpsDataBits;
+- break;
+-
+- case MPEGS_CONTINUE:
+- case MPEGS_STOP:
+- /* Assuming that core coder frame size (AAC) is smaller than MPS
+- coder frame size. Save audio data for next frame. */
+- if ((pMpegSurroundDecoder->mpsDataBits + mpsDataBits) >
+- MPS_DATA_BUFFER_SIZE * 8) {
+- err = MPS_NOTOK;
+- goto bail;
+- }
+- for (int i = 0; i < mpsDataBits / 8; i++) {
+- pMpegSurroundDecoder
+- ->mpsData[(pMpegSurroundDecoder->mpsDataBits / 8) + i] =
+- FDKreadBits(hBs, 8);
+- }
+- pMpegSurroundDecoder->mpsDataBits += mpsDataBits;
+- FDKinitBitStream(&mpsBsData, pMpegSurroundDecoder->mpsData,
+- MAX_BUFSIZE_BYTES,
+- pMpegSurroundDecoder->mpsDataBits, BS_READER);
+- hMpsBsData = &mpsBsData;
+- break;
+-
+- case MPEGS_START_STOP:
+- pMpegSurroundDecoder->mpsDataBits = mpsDataBits;
+- hMpsBsData = hBs;
+- break;
+-
+- default:
+- FDK_ASSERT(0);
+- }
+-
+- if ((ancStartStop == MPEGS_STOP) ||
+- (ancStartStop == MPEGS_START_STOP)) {
+- switch (ancType) {
+- case MPEGS_ANCTYPE_HEADER_AND_FRAME: {
+- int parseResult, bitsRead;
+- SPATIAL_SPECIFIC_CONFIG spatialSpecificConfigTmp =
+- pMpegSurroundDecoder->spatialSpecificConfigBackup;
+-
+- /* Parse spatial specific config */
+- bitsRead = (INT)FDKgetValidBits(hMpsBsData);
+-
+- err = SpatialDecParseSpecificConfigHeader(
+- hMpsBsData,
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup, coreCodec,
+- pMpegSurroundDecoder->upmixType);
+-
+- bitsRead = (bitsRead - (INT)FDKgetValidBits(hMpsBsData));
+- parseResult = ((err == MPS_OK) ? bitsRead : -bitsRead);
+-
+- if (parseResult < 0) {
+- parseResult = -parseResult;
+- err = MPS_PARSE_ERROR;
+- } else if (err == MPS_OK) {
+- /* Check SSC for consistency (e.g. bit errors could cause
+- * trouble) */
+- err = sscCheckInBand(
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup,
+- frameSize, sampleRate);
+- }
+- if (err != MPS_OK) {
+- pMpegSurroundDecoder->spatialSpecificConfigBackup =
+- spatialSpecificConfigTmp;
+- break;
+- }
+-
+- pMpegSurroundDecoder->mpsDataBits -= parseResult;
+-
+- /* Initiate re-initialization, if header has changed */
+- if (FDK_SpatialDecCompareSpatialSpecificConfigHeader(
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup,
+- sscParse) == MPS_UNEQUAL_SSC) {
+- pMpegSurroundDecoder
+- ->initFlags[pMpegSurroundDecoder->bsFrameParse] |=
+- MPEGS_INIT_CHANGE_HEADER;
+- SpatialDecInitParserContext(pMpegSurroundDecoder->pSpatialDec);
+- /* We found a valid in-band configuration. Therefore any
+- * previous config is invalid now. */
+- pMpegSurroundDecoder->mpegSurroundSscIsGlobalCfg = 0;
+- }
+- }
+- FDK_FALLTHROUGH;
+- case MPEGS_ANCTYPE_FRAME:
+-
+- if (pMpegSurroundDecoder
+- ->initFlags[pMpegSurroundDecoder->bsFrameParse] &
+- MPEGS_INIT_ERROR_PAYLOAD) {
+- err = MPS_PARSE_ERROR;
+- break;
+- }
+-
+- /* First spatial specific config is parsed into
+- * spatialSpecificConfigBackup, second spatialSpecificConfigBackup
+- * is copied into spatialSpecificConfig[bsFrameDecode] */
+- if (pMpegSurroundDecoder
+- ->initFlags[pMpegSurroundDecoder->bsFrameParse]) {
+- FDKmemcpy(sscParse,
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup,
+- sizeof(SPATIAL_SPECIFIC_CONFIG));
+- pMpegSurroundDecoder
+- ->fOnSync[pMpegSurroundDecoder->bsFrameParse] =
+- MPEGS_SYNC_FOUND;
+- }
+-
+- if (pMpegSurroundDecoder
+- ->fOnSync[pMpegSurroundDecoder->bsFrameParse] >=
+- MPEGS_SYNC_FOUND) {
+- int nbits = 0, bitsAvail;
+-
+- if (err != MPS_OK) {
+- break;
+- }
+-
+- bitsAvail = FDKgetValidBits(hMpsBsData);
+-
+- if (bitsAvail <= 0) {
+- err = MPS_PARSE_ERROR;
+- } else {
+- err = SpatialDecParseFrameData(
+- pMpegSurroundDecoder->pSpatialDec, bsFrame, hMpsBsData,
+- sscParse, (UPMIXTYPE)pMpegSurroundDecoder->upmixType,
+- fGlobalIndependencyFlag);
+- if (err == MPS_OK) {
+- bsFrame->newBsData = 1;
+- }
+- }
+-
+- nbits = bitsAvail - (INT)FDKgetValidBits(hMpsBsData);
+-
+- if ((nbits > bitsAvail) ||
+- (nbits > pMpegSurroundDecoder->mpsDataBits) ||
+- (pMpegSurroundDecoder->mpsDataBits > nbits + 7 &&
+- !IS_LOWDELAY(coreCodec))) {
+- bsFrame->newBsData = 0;
+- err = MPS_PARSE_ERROR;
+- break;
+- }
+- pMpegSurroundDecoder->mpsDataBits -= nbits;
+- }
+- break;
+-
+- default: /* added to avoid compiler warning */
+- err = MPS_NOTOK;
+- break; /* added to avoid compiler warning */
+- } /* switch (ancType) */
+-
+- if (err == MPS_OK) {
+- pMpegSurroundDecoder->ancStartStopPrev = ancStartStop;
+- } else {
+- updateMpegSurroundDecoderStatus(pMpegSurroundDecoder,
+- MPEGS_INIT_ERROR_PAYLOAD,
+- MPEGS_SYNC_LOST, MPEGS_STOP);
+- pMpegSurroundDecoder->mpsDataBits = 0;
+- }
+- } /* (ancStartStop == MPEGS_STOP) || (ancStartStop == MPEGS_START_STOP)
+- */
+- } /* validAncStartStop */
+- } /* validAncType */
+- }
+-
+-bail:
+-
+- *pMpsDataBits -= (mpsBsBits - (INT)FDKgetValidBits(hBs));
+-
+- return err;
+-}
+-
+-int mpegSurroundDecoder_Apply(CMpegSurroundDecoder *pMpegSurroundDecoder,
+- INT_PCM *input, PCM_MPS *pTimeData,
+- const int timeDataSize, int timeDataFrameSize,
+- int *nChannels, int *frameSize, int sampleRate,
+- AUDIO_OBJECT_TYPE coreCodec,
+- AUDIO_CHANNEL_TYPE channelType[],
+- UCHAR channelIndices[],
+- const FDK_channelMapDescr *const mapDescr) {
+- SACDEC_ERROR err = MPS_OK;
+- PCM_MPS *pTimeOut = pTimeData;
+- UINT initControlFlags = 0, controlFlags = 0;
+- int timeDataRequiredSize = 0;
+- int newData;
+-
+- if (pMpegSurroundDecoder == NULL) {
+- return MPS_INVALID_HANDLE;
+- }
+-
+- FDK_ASSERT(pMpegSurroundDecoder->pSpatialDec);
+-
+- if (!FDK_chMapDescr_isValid(mapDescr)) {
+- return MPS_INVALID_HANDLE;
+- }
+-
+- if ((*nChannels <= 0) || (*nChannels > 2)) {
+- return MPS_NOTOK;
+- }
+-
+- pMpegSurroundDecoder->pSpatialDec->pConfigCurrent =
+- &pMpegSurroundDecoder
+- ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameDecode];
+- newData = pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameParse]
+- .newBsData;
+-
+- switch (mpegSurroundOperationMode(pMpegSurroundDecoder, 1000)) {
+- case MPEGS_OPMODE_MPS_PAYLOAD:
+- if (pMpegSurroundDecoder
+- ->initFlags[pMpegSurroundDecoder->bsFrameDecode]) {
+- err = initMpegSurroundDecoder(pMpegSurroundDecoder);
+- }
+-
+- if (err == MPS_OK) {
+- if ((pMpegSurroundDecoder
+- ->fOnSync[pMpegSurroundDecoder->bsFrameDecode] !=
+- MPEGS_SYNC_COMPLETE) &&
+- (pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameDecode]
+- .bsIndependencyFlag == 1)) {
+- /* We got a valid header and independently decodeable frame data.
+- -> Go to the next sync level and start processing. */
+- pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameDecode] =
+- MPEGS_SYNC_COMPLETE;
+- }
+- } else {
+- /* We got a valid config header but found an error while parsing the
+- bitstream. Wait for the next independent frame and apply error
+- conealment in the meantime. */
+- pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameDecode] =
+- MPEGS_SYNC_FOUND;
+- controlFlags |= MPEGS_CONCEAL;
+- err = MPS_OK;
+- }
+- /*
+- Concealment:
+- - Bitstream is available, no sync found during bitstream processing
+- - Bitstream is available, sync lost due to corrupted bitstream
+- - Bitstream is available, sync found but no independent frame
+- */
+- if (pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameDecode] !=
+- MPEGS_SYNC_COMPLETE) {
+- controlFlags |= MPEGS_CONCEAL;
+- }
+- break;
+-
+- case MPEGS_OPMODE_NO_MPS_PAYLOAD:
+- /* Concealment: No bitstream is available */
+- controlFlags |= MPEGS_CONCEAL;
+- break;
+-
+- default:
+- err = MPS_NOTOK;
+- }
+-
+- if (err != MPS_OK) {
+- goto bail;
+- }
+-
+- /*
+- * Force BypassMode if choosen by user
+- */
+- if (pMpegSurroundDecoder->mpegSurroundUserParams.bypassMode) {
+- controlFlags |= MPEGS_BYPASSMODE;
+- }
+-
+- if (pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode]) {
+- int startWithDfltCfg = 0;
+- /*
+- * Init with a default configuration if we came here and are still not
+- * initialized.
+- */
+- if (pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] &
+- MPEGS_INIT_ENFORCE_REINIT) {
+- /* Get default spatial specific config */
+- if (FDK_SpatialDecInitDefaultSpatialSpecificConfig(
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup, coreCodec,
+- *nChannels, sampleRate,
+- *frameSize /
+- mpegSurroundDecoder_GetNrOfQmfBands(NULL, sampleRate),
+- pMpegSurroundDecoder->mpegSurroundDecoderLevel,
+- pMpegSurroundDecoder->mpegSurroundUserParams.blindEnable)) {
+- err = MPS_NOTOK;
+- goto bail;
+- }
+-
+- /* Initiate re-initialization, if header has changed */
+- if (FDK_SpatialDecCompareSpatialSpecificConfigHeader(
+- &pMpegSurroundDecoder->spatialSpecificConfigBackup,
+- &pMpegSurroundDecoder->spatialSpecificConfig
+- [pMpegSurroundDecoder->bsFrameDecode]) == MPS_UNEQUAL_SSC) {
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] |=
+- MPEGS_INIT_CHANGE_HEADER;
+- SpatialDecInitParserContext(pMpegSurroundDecoder->pSpatialDec);
+- }
+-
+- startWithDfltCfg = 1;
+- }
+-
+- /* First spatial specific config is parsed into spatialSpecificConfigBackup,
+- * second spatialSpecificConfigBackup is copied into spatialSpecificConfig
+- */
+- err = initMpegSurroundDecoder(pMpegSurroundDecoder);
+-
+- if (startWithDfltCfg) {
+- /* initialized with default config, but no sync found */
+- /* maybe use updateMpegSurroundDecoderStatus later on */
+- pMpegSurroundDecoder->fOnSync[pMpegSurroundDecoder->bsFrameDecode] =
+- MPEGS_SYNC_LOST;
+- }
+-
+- /* Since we do not have state MPEGS_SYNC_COMPLETE apply concealment */
+- controlFlags |= MPEGS_CONCEAL;
+-
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- }
+-
+- /*
+- * Process MPEG Surround Audio
+- */
+- initControlFlags = controlFlags;
+-
+- /* Check that provided output buffer is large enough. */
+- if (pMpegSurroundDecoder->pQmfDomain->globalConf.nBandsAnalysis == 0) {
+- err = MPS_UNSUPPORTED_FORMAT;
+- goto bail;
+- }
+- timeDataRequiredSize =
+- (timeDataFrameSize *
+- pMpegSurroundDecoder->pSpatialDec->numOutputChannelsAT *
+- pMpegSurroundDecoder->pQmfDomain->globalConf.nBandsSynthesis) /
+- pMpegSurroundDecoder->pQmfDomain->globalConf.nBandsAnalysis;
+- if (timeDataSize < timeDataRequiredSize) {
+- err = MPS_OUTPUT_BUFFER_TOO_SMALL;
+- goto bail;
+- }
+-
+- if ((pMpegSurroundDecoder->pSpatialDec->pConfigCurrent->syntaxFlags &
+- SACDEC_SYNTAX_USAC) &&
+- (pMpegSurroundDecoder->pSpatialDec->stereoConfigIndex > 1)) {
+- FDK_ASSERT(timeDataRequiredSize >= timeDataFrameSize * *nChannels);
+- /* Place samples comprising QMF time slots spaced at QMF output Band raster
+- * to allow slot wise processing */
+- int timeDataFrameSizeOut =
+- (timeDataFrameSize *
+- pMpegSurroundDecoder->pQmfDomain->globalConf.nBandsSynthesis) /
+- pMpegSurroundDecoder->pQmfDomain->globalConf.nBandsAnalysis;
+- pMpegSurroundDecoder->pQmfDomain->globalConf.TDinput =
+- pTimeData + timeDataFrameSizeOut - timeDataFrameSize;
+- for (int i = *nChannels - 1; i >= 0; i--) {
+- FDKmemmove(pTimeData + (i + 1) * timeDataFrameSizeOut - timeDataFrameSize,
+- pTimeData + timeDataFrameSize * i,
+- sizeof(PCM_MPS) * timeDataFrameSize);
+- FDKmemclear(pTimeData + i * timeDataFrameSizeOut,
+- sizeof(PCM_MPS) * (timeDataFrameSizeOut - timeDataFrameSize));
+- }
+- } else {
+- if (pMpegSurroundDecoder->mpegSurroundUseTimeInterface) {
+- FDKmemcpy(input, pTimeData,
+- sizeof(INT_PCM) * (*nChannels) * (*frameSize));
+- pMpegSurroundDecoder->pQmfDomain->globalConf.TDinput = input;
+- }
+- }
+-
+- /*
+- * Process MPEG Surround Audio
+- */
+- err = SpatialDecApplyFrame(
+- pMpegSurroundDecoder->pSpatialDec,
+- &pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameDecode],
+- pMpegSurroundDecoder->mpegSurroundUseTimeInterface ? INPUTMODE_TIME
+- : INPUTMODE_QMF_SBR,
+- pMpegSurroundDecoder->pQmfDomain->globalConf.TDinput, NULL, NULL,
+- pTimeOut, *frameSize, &controlFlags, *nChannels, mapDescr);
+- *nChannels = pMpegSurroundDecoder->pSpatialDec->numOutputChannelsAT;
+-
+- if (err !=
+- MPS_OK) { /* A fatal error occured. Go back to start and try again: */
+- updateMpegSurroundDecoderStatus(pMpegSurroundDecoder,
+- MPEGS_INIT_ENFORCE_REINIT, MPEGS_SYNC_LOST,
+- MPEGS_STOP);
+- *frameSize =
+- 0; /* Declare that framework can not use the data in pTimeOut. */
+- } else {
+- if (((controlFlags & MPEGS_CONCEAL) &&
+- !(initControlFlags & MPEGS_CONCEAL)) ||
+- (pMpegSurroundDecoder->pSpatialDec->errInt !=
+- MPS_OK)) { /* Account for errors that occured in
+- SpatialDecApplyFrame(): */
+- updateMpegSurroundDecoderStatus(pMpegSurroundDecoder,
+- MPEGS_INIT_ERROR_PAYLOAD, MPEGS_SYNC_LOST,
+- MPEGS_STOP);
+- }
+- }
+-
+- if ((err == MPS_OK) && !(controlFlags & MPEGS_BYPASSMODE) &&
+- !(pMpegSurroundDecoder->upmixType == UPMIX_TYPE_BYPASS)) {
+- SpatialDecChannelProperties(pMpegSurroundDecoder->pSpatialDec, channelType,
+- channelIndices, mapDescr);
+- }
+-
+-bail:
+-
+- if (newData) {
+- /* numParameterSetsPrev shall only be read in the decode process, because of
+- that we can update this state variable here */
+- pMpegSurroundDecoder->pSpatialDec->numParameterSetsPrev =
+- pMpegSurroundDecoder->bsFrames[pMpegSurroundDecoder->bsFrameDecode]
+- .numParameterSets;
+- }
+-
+- return (err);
+-}
+-
+-/**
+- * \brief Free config dependent MPEG Surround memory.
+- **/
+-SACDEC_ERROR mpegSurroundDecoder_FreeMem(
+- CMpegSurroundDecoder *pMpegSurroundDecoder) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- if (pMpegSurroundDecoder != NULL) {
+- FDK_SpatialDecClose(pMpegSurroundDecoder->pSpatialDec);
+- pMpegSurroundDecoder->pSpatialDec = NULL;
+- }
+-
+- return err;
+-}
+-
+-/**
+- * \brief Close MPEG Surround decoder.
+- **/
+-void mpegSurroundDecoder_Close(CMpegSurroundDecoder *pMpegSurroundDecoder) {
+- if (pMpegSurroundDecoder != NULL) {
+- FDK_SpatialDecClose(pMpegSurroundDecoder->pSpatialDec);
+- pMpegSurroundDecoder->pSpatialDec = NULL;
+-
+- for (int i = 0; i < 1; i++) {
+- SpatialDecCloseBsFrame(&pMpegSurroundDecoder->bsFrames[i]);
+- }
+-
+- FDK_FREE_MEMORY_1D(pMpegSurroundDecoder);
+- }
+-}
+-
+-#define SACDEC_VL0 2
+-#define SACDEC_VL1 0
+-#define SACDEC_VL2 0
+-
+-int mpegSurroundDecoder_GetLibInfo(LIB_INFO *info) {
+- int i;
+-
+- if (info == NULL) {
+- return -1;
+- }
+-
+- /* search for next free tab */
+- for (i = 0; i < FDK_MODULE_LAST; i++) {
+- if (info[i].module_id == FDK_NONE) break;
+- }
+- if (i == FDK_MODULE_LAST) return -1;
+-
+- info += i;
+-
+- info->module_id = FDK_MPSDEC;
+-#ifdef __ANDROID__
+- info->build_date = "";
+- info->build_time = "";
+-#else
+- info->build_date = __DATE__;
+- info->build_time = __TIME__;
+-#endif
+- info->title = "MPEG Surround Decoder";
+- info->version = LIB_VERSION(SACDEC_VL0, SACDEC_VL1, SACDEC_VL2);
+- LIB_VERSION_STRING(info);
+- info->flags = 0 | CAPF_MPS_LD | CAPF_MPS_USAC | CAPF_MPS_HQ |
+- CAPF_MPS_1CH_IN | CAPF_MPS_2CH_OUT; /* end flags */
+-
+- return 0;
+-}
+-
+-SACDEC_ERROR mpegSurroundDecoder_SetParam(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, const SACDEC_PARAM param,
+- const INT value) {
+- SACDEC_ERROR err = MPS_OK;
+- SPATIALDEC_PARAM *pUserParams = NULL;
+-
+- /* check decoder handle */
+- if (pMpegSurroundDecoder != NULL) {
+- /* init local shortcuts */
+- pUserParams = &pMpegSurroundDecoder->mpegSurroundUserParams;
+- } else {
+- err = MPS_INVALID_HANDLE;
+- /* check the parameter values before exiting. */
+- }
+-
+- /* apply param value */
+- switch (param) {
+- case SACDEC_OUTPUT_MODE:
+- switch ((SAC_DEC_OUTPUT_MODE)value) {
+- case SACDEC_OUT_MODE_NORMAL:
+- case SACDEC_OUT_MODE_STEREO:
+- break;
+- default:
+- err = MPS_INVALID_PARAMETER;
+- }
+- if (err == MPS_OK) {
+- if (0) {
+- err = MPS_INVALID_PARAMETER;
+- } else if (pUserParams->outputMode != (UCHAR)value) {
+- pUserParams->outputMode = (UCHAR)value;
+- pMpegSurroundDecoder
+- ->initFlags[pMpegSurroundDecoder->bsFrameDecode] |=
+- MPEGS_INIT_CHANGE_OUTPUT_MODE;
+- }
+- }
+- break;
+-
+- case SACDEC_INTERFACE:
+- if (value < 0 || value > 1) {
+- err = MPS_INVALID_PARAMETER;
+- }
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- if (pMpegSurroundDecoder->mpegSurroundUseTimeInterface != (UCHAR)value) {
+- pMpegSurroundDecoder->mpegSurroundUseTimeInterface = (UCHAR)value;
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] |=
+- MPEGS_INIT_CHANGE_TIME_FREQ_INTERFACE;
+- }
+- break;
+-
+- case SACDEC_BS_INTERRUPTION:
+- if ((err == MPS_OK) && (value != 0)) {
+- updateMpegSurroundDecoderStatus(pMpegSurroundDecoder,
+- MPEGS_INIT_BS_INTERRUPTION,
+- MPEGS_SYNC_LOST, MPEGS_STOP);
+- }
+- break;
+-
+- case SACDEC_CLEAR_HISTORY:
+- if ((err == MPS_OK) && (value != 0)) {
+- /* Just reset the states and go on. */
+- updateMpegSurroundDecoderStatus(pMpegSurroundDecoder,
+- MPEGS_INIT_CLEAR_HISTORY,
+- MPEGS_SYNC_LOST, MPEGS_STOP);
+- }
+- break;
+-
+- case SACDEC_CONCEAL_NUM_KEEP_FRAMES:
+- if (value < 0) { /* Check valid value range */
+- err = MPS_INVALID_PARAMETER;
+- }
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- if (pUserParams->concealNumKeepFrames != (UINT)value) {
+- pUserParams->concealNumKeepFrames = (UINT)value;
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] |=
+- MPEGS_INIT_CHANGE_CONCEAL_PARAMS;
+- }
+- break;
+-
+- case SACDEC_CONCEAL_FADE_OUT_SLOPE_LENGTH:
+- if (value < 0) { /* Check valid value range */
+- err = MPS_INVALID_PARAMETER;
+- }
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- if (pUserParams->concealFadeOutSlopeLength != (UINT)value) {
+- pUserParams->concealFadeOutSlopeLength = (UINT)value;
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] |=
+- MPEGS_INIT_CHANGE_CONCEAL_PARAMS;
+- }
+- break;
+-
+- case SACDEC_CONCEAL_FADE_IN_SLOPE_LENGTH:
+- if (value < 0) { /* Check valid value range */
+- err = MPS_INVALID_PARAMETER;
+- }
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- if (pUserParams->concealFadeInSlopeLength != (UINT)value) {
+- pUserParams->concealFadeInSlopeLength = (UINT)value;
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] |=
+- MPEGS_INIT_CHANGE_CONCEAL_PARAMS;
+- }
+- break;
+-
+- case SACDEC_CONCEAL_NUM_RELEASE_FRAMES:
+- if (value < 0) { /* Check valid value range */
+- err = MPS_INVALID_PARAMETER;
+- }
+- if (err != MPS_OK) {
+- goto bail;
+- }
+- if (pUserParams->concealNumReleaseFrames != (UINT)value) {
+- pUserParams->concealNumReleaseFrames = (UINT)value;
+- pMpegSurroundDecoder->initFlags[pMpegSurroundDecoder->bsFrameDecode] |=
+- MPEGS_INIT_CHANGE_CONCEAL_PARAMS;
+- }
+- break;
+-
+- default:
+- err = MPS_INVALID_PARAMETER;
+- break;
+- } /* switch(param) */
+-
+-bail:
+- return err;
+-}
+-
+-SACDEC_ERROR mpegSurroundDecoder_IsPseudoLR(
+- CMpegSurroundDecoder *pMpegSurroundDecoder, int *bsPseudoLr) {
+- if (pMpegSurroundDecoder != NULL) {
+- const SPATIAL_SPECIFIC_CONFIG *sscDecode =
+- &pMpegSurroundDecoder
+- ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameDecode];
+- *bsPseudoLr = (int)sscDecode->bsPseudoLr;
+- return MPS_OK;
+- } else
+- return MPS_INVALID_HANDLE;
+-}
+-
+-/**
+- * \brief Get the signal delay caused by the MPEG Surround decoder module.
+- **/
+-UINT mpegSurroundDecoder_GetDelay(const CMpegSurroundDecoder *self) {
+- INT outputDelay = 0;
+-
+- if (self != NULL) {
+- const SPATIAL_SPECIFIC_CONFIG *sscDecode =
+- &self->spatialSpecificConfig[self->bsFrameDecode];
+- AUDIO_OBJECT_TYPE coreCodec = sscDecode->coreCodec;
+-
+- /* See chapter 4.5 (delay and synchronization) of ISO/IEC FDIS 23003-1 and
+- chapter 5.4.3 of ISO/IEC FDIS 23003-2 for details on the following
+- figures. */
+-
+- if (coreCodec > AOT_NULL_OBJECT) {
+- if (IS_LOWDELAY(coreCodec)) {
+- /* All low delay variants (ER-AAC-(E)LD): */
+- outputDelay += 256;
+- } else if (!IS_USAC(coreCodec)) {
+- /* By the method of elimination this is the GA (AAC-LC, HE-AAC, ...)
+- * branch: */
+- outputDelay += 320 + 257; /* cos to exp delay + QMF synthesis */
+- if (self->mpegSurroundUseTimeInterface) {
+- outputDelay += 320 + 384; /* QMF and hybrid analysis */
+- }
+- }
+- }
+- }
+-
+- return (outputDelay);
+-}
+diff --git a/libSACdec/src/sac_dec_ssc_struct.h b/libSACdec/src/sac_dec_ssc_struct.h
+deleted file mode 100644
+index b67b465..0000000
+--- a/libSACdec/src/sac_dec_ssc_struct.h
++++ /dev/null
+@@ -1,283 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: interface - spatial specific config struct
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_DEC_SSC_STRUCT_H
+-#define SAC_DEC_SSC_STRUCT_H
+-
+-#include "FDK_audio.h"
+-
+-#define MAX_NUM_QMF_BANDS (128)
+-#define MAX_TIME_SLOTS 64
+-#define MAX_INPUT_CHANNELS 1
+-#define MAX_OUTPUT_CHANNELS \
+- 2 /* CAUTION: This does NOT restrict the number of \
+- output channels exclusively! In addition it \
+- affects the max number of bitstream and residual channels! */
+-#define MAX_NUM_OTT (5)
+-#define MAX_NUM_TTT (0)
+-#define MAX_NUM_EXT_TYPES (8)
+-#define MAX_PARAMETER_BANDS (28)
+-#define MAX_PARAMETER_BANDS_LD (23)
+-
+-#define MAX_NUM_XCHANNELS (6)
+-
+-#define MAX_ARBITRARY_TREE_LEVELS (0)
+-
+-typedef enum {
+- /* CAUTION: Do not change enum values! */
+- SPATIALDEC_FREQ_RES_40 = 40,
+- SPATIALDEC_FREQ_RES_28 = 28,
+- SPATIALDEC_FREQ_RES_23 = 23,
+- SPATIALDEC_FREQ_RES_20 = 20,
+- SPATIALDEC_FREQ_RES_15 = 15,
+- SPATIALDEC_FREQ_RES_14 = 14,
+- SPATIALDEC_FREQ_RES_12 = 12,
+- SPATIALDEC_FREQ_RES_10 = 10,
+- SPATIALDEC_FREQ_RES_9 = 9,
+- SPATIALDEC_FREQ_RES_7 = 7,
+- SPATIALDEC_FREQ_RES_5 = 5,
+- SPATIALDEC_FREQ_RES_4 = 4
+-
+-} SPATIALDEC_FREQ_RES;
+-
+-typedef enum {
+-
+- SPATIALDEC_QUANT_FINE_DEF = 0,
+- SPATIALDEC_QUANT_EDQ1 = 1,
+- SPATIALDEC_QUANT_EDQ2 = 2,
+- SPATIALDEC_QUANT_RSVD3 = 3,
+- SPATIALDEC_QUANT_RSVD4 = 4,
+- SPATIALDEC_QUANT_RSVD5 = 5,
+- SPATIALDEC_QUANT_RSVD6 = 6,
+- SPATIALDEC_QUANT_RSVD7 = 7
+-
+-} SPATIALDEC_QUANT_MODE;
+-
+-typedef enum { SPATIALDEC_MODE_RSVD7 = 7 } SPATIALDEC_TREE_CONFIG;
+-
+-typedef enum {
+-
+- SPATIALDEC_GAIN_MODE0 = 0,
+- SPATIALDEC_GAIN_RSVD1 = 1,
+- SPATIALDEC_GAIN_RSVD2 = 2,
+- SPATIALDEC_GAIN_RSVD3 = 3,
+- SPATIALDEC_GAIN_RSVD4 = 4,
+- SPATIALDEC_GAIN_RSVD5 = 5,
+- SPATIALDEC_GAIN_RSVD6 = 6,
+- SPATIALDEC_GAIN_RSVD7 = 7,
+- SPATIALDEC_GAIN_RSVD8 = 8,
+- SPATIALDEC_GAIN_RSVD9 = 9,
+- SPATIALDEC_GAIN_RSVD10 = 10,
+- SPATIALDEC_GAIN_RSVD11 = 11,
+- SPATIALDEC_GAIN_RSVD12 = 12,
+- SPATIALDEC_GAIN_RSVD13 = 13,
+- SPATIALDEC_GAIN_RSVD14 = 14,
+- SPATIALDEC_GAIN_RSVD15 = 15
+-
+-} SPATIALDEC_FIXED_GAINS;
+-
+-typedef enum {
+-
+- SPATIALDEC_TS_TPNOWHITE = 0,
+- SPATIALDEC_TS_TPWHITE = 1,
+- SPATIALDEC_TS_TES = 2,
+- SPATIALDEC_TS_NOTS = 3,
+- SPATIALDEC_TS_RSVD4 = 4,
+- SPATIALDEC_TS_RSVD5 = 5,
+- SPATIALDEC_TS_RSVD6 = 6,
+- SPATIALDEC_TS_RSVD7 = 7,
+- SPATIALDEC_TS_RSVD8 = 8,
+- SPATIALDEC_TS_RSVD9 = 9,
+- SPATIALDEC_TS_RSVD10 = 10,
+- SPATIALDEC_TS_RSVD11 = 11,
+- SPATIALDEC_TS_RSVD12 = 12,
+- SPATIALDEC_TS_RSVD13 = 13,
+- SPATIALDEC_TS_RSVD14 = 14,
+- SPATIALDEC_TS_RSVD15 = 15
+-
+-} SPATIALDEC_TS_CONF;
+-
+-typedef enum {
+-
+- SPATIALDEC_DECORR_MODE0 = 0,
+- SPATIALDEC_DECORR_MODE1 = 1,
+- SPATIALDEC_DECORR_MODE2 = 2,
+- SPATIALDEC_DECORR_RSVD3 = 3,
+- SPATIALDEC_DECORR_RSVD4 = 4,
+- SPATIALDEC_DECORR_RSVD5 = 5,
+- SPATIALDEC_DECORR_RSVD6 = 6,
+- SPATIALDEC_DECORR_RSVD7 = 7,
+- SPATIALDEC_DECORR_RSVD8 = 8,
+- SPATIALDEC_DECORR_RSVD9 = 9,
+- SPATIALDEC_DECORR_RSVD10 = 10,
+- SPATIALDEC_DECORR_RSVD11 = 11,
+- SPATIALDEC_DECORR_RSVD12 = 12,
+- SPATIALDEC_DECORR_RSVD13 = 13,
+- SPATIALDEC_DECORR_RSVD14 = 14,
+- SPATIALDEC_DECORR_RSVD15 = 15
+-
+-} SPATIALDEC_DECORR_CONF;
+-
+-typedef struct T_SPATIALDEC_OTT_CONF {
+- int nOttBands;
+-
+-} SPATIALDEC_OTT_CONF;
+-
+-typedef struct T_SPATIALDEC_RESIDUAL_CONF {
+- int bResidualPresent;
+- int nResidualBands;
+-
+-} SPATIALDEC_RESIDUAL_CONF;
+-
+-typedef struct T_SPATIAL_SPECIFIC_CONFIG {
+- UINT syntaxFlags;
+- int samplingFreq;
+- int nTimeSlots;
+- SPATIALDEC_FREQ_RES freqRes;
+- SPATIALDEC_TREE_CONFIG treeConfig;
+- SPATIALDEC_QUANT_MODE quantMode;
+- int bArbitraryDownmix;
+-
+- int bResidualCoding;
+- SPATIALDEC_FIXED_GAINS bsFixedGainDMX;
+-
+- SPATIALDEC_TS_CONF tempShapeConfig;
+- SPATIALDEC_DECORR_CONF decorrConfig;
+-
+- int nInputChannels; /* derived from treeConfig */
+- int nOutputChannels; /* derived from treeConfig */
+-
+- /* ott config */
+- int nOttBoxes; /* derived from treeConfig */
+- SPATIALDEC_OTT_CONF OttConfig[MAX_NUM_OTT]; /* dimension nOttBoxes */
+-
+- /* ttt config */
+- int nTttBoxes; /* derived from treeConfig */
+-
+- /* residual config */
+- SPATIALDEC_RESIDUAL_CONF
+- ResidualConfig[MAX_NUM_OTT +
+- MAX_NUM_TTT]; /* dimension (nOttBoxes + nTttBoxes) */
+-
+- int sacExtCnt;
+- int sacExtType[MAX_NUM_EXT_TYPES];
+- int envQuantMode;
+-
+- AUDIO_OBJECT_TYPE coreCodec;
+-
+- UCHAR stereoConfigIndex;
+- UCHAR coreSbrFrameLengthIndex; /* Table 70 in ISO/IEC FDIS 23003-3:2011 */
+- UCHAR bsHighRateMode;
+- UCHAR bsDecorrType;
+- UCHAR bsPseudoLr;
+- UCHAR bsPhaseCoding;
+- UCHAR bsOttBandsPhasePresent;
+- int bsOttBandsPhase;
+-
+- SCHAR ottCLDdefault[MAX_NUM_OTT];
+- UCHAR numOttBandsIPD;
+- UCHAR bitstreamOttBands[MAX_NUM_OTT];
+- UCHAR numOttBands[MAX_NUM_OTT];
+-
+-} SPATIAL_SPECIFIC_CONFIG;
+-
+-#endif
+diff --git a/libSACdec/src/sac_process.cpp b/libSACdec/src/sac_process.cpp
+deleted file mode 100644
+index 56c72ad..0000000
+--- a/libSACdec/src/sac_process.cpp
++++ /dev/null
+@@ -1,1066 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Processing
+-
+-*******************************************************************************/
+-
+-/* data structures and interfaces for spatial audio reference software */
+-#include "sac_process.h"
+-
+-#include "sac_bitdec.h"
+-#include "sac_calcM1andM2.h"
+-#include "sac_smoothing.h"
+-#include "sac_rom.h"
+-
+-#include "sac_dec_errorcodes.h"
+-
+-#include "FDK_trigFcts.h"
+-#include "FDK_decorrelate.h"
+-
+-/**
+- * \brief Linear interpolation between two parameter values.
+- * a*alpha + b*(1-alpha)
+- * = a*alpha + b - b*alpha
+- *
+- * \param alpha Weighting factor.
+- * \param a Parameter a.
+- * \param b Parameter b.
+- *
+- * \return Interpolated parameter value.
+- */
+-FDK_INLINE FIXP_DBL interpolateParameter(const FIXP_SGL alpha, const FIXP_DBL a,
+- const FIXP_DBL b) {
+- return (b - fMult(alpha, b) + fMult(alpha, a));
+-}
+-
+-/**
+- * \brief Map MPEG Surround channel indices to MPEG 4 PCE like channel indices.
+- * \param self Spatial decoder handle.
+- * \param ch MPEG Surround channel index.
+- * \return MPEG 4 PCE style channel index, corresponding to the given MPEG
+- * Surround channel index.
+- */
+-static UINT mapChannel(spatialDec *self, UINT ch) {
+- static const UCHAR chanelIdx[][8] = {
+- {0, 1, 2, 3, 4, 5, 6, 7}, /* binaural, TREE_212, arbitrary tree */
+- };
+-
+- int idx = 0;
+-
+- return (chanelIdx[idx][ch]);
+-}
+-
+-FIXP_DBL getChGain(spatialDec *self, UINT ch, INT *scale) {
+- /* init no gain modifier */
+- FIXP_DBL gain = 0x80000000;
+- *scale = 0;
+-
+- if ((!isTwoChMode(self->upmixType)) &&
+- (self->upmixType != UPMIXTYPE_BYPASS)) {
+- if ((ch == 0) || (ch == 1) || (ch == 2)) {
+- /* no modifier */
+- }
+- }
+-
+- return gain;
+-}
+-
+-SACDEC_ERROR SpatialDecQMFAnalysis(spatialDec *self, const PCM_MPS *inData,
+- const INT ts, const INT bypassMode,
+- FIXP_DBL **qmfReal, FIXP_DBL **qmfImag,
+- const int numInputChannels) {
+- SACDEC_ERROR err = MPS_OK;
+- int ch, offset;
+-
+- offset = self->pQmfDomain->globalConf.nBandsSynthesis *
+- self->pQmfDomain->globalConf.nQmfTimeSlots;
+-
+- {
+- for (ch = 0; ch < numInputChannels; ch++) {
+- const PCM_MPS *inSamples =
+- &inData[ts * self->pQmfDomain->globalConf.nBandsAnalysis];
+- FIXP_DBL *pQmfRealAnalysis = qmfReal[ch]; /* no delay in blind mode */
+- FIXP_DBL *pQmfImagAnalysis = qmfImag[ch];
+-
+- CalculateSpaceAnalysisQmf(&self->pQmfDomain->QmfDomainIn[ch].fb,
+- inSamples + (ch * offset), pQmfRealAnalysis,
+- pQmfImagAnalysis);
+-
+- if (!isTwoChMode(self->upmixType) && !bypassMode) {
+- int i;
+- for (i = 0; i < self->qmfBands; i++) {
+- qmfReal[ch][i] = fMult(qmfReal[ch][i], self->clipProtectGain__FDK);
+- qmfImag[ch][i] = fMult(qmfImag[ch][i], self->clipProtectGain__FDK);
+- }
+- }
+- }
+- }
+-
+- self->qmfInputDelayBufPos =
+- (self->qmfInputDelayBufPos + 1) % self->pc_filterdelay;
+-
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecFeedQMF(spatialDec *self, FIXP_DBL **qmfInDataReal,
+- FIXP_DBL **qmfInDataImag, const INT ts,
+- const INT bypassMode, FIXP_DBL **qmfReal__FDK,
+- FIXP_DBL **qmfImag__FDK,
+- const INT numInputChannels) {
+- SACDEC_ERROR err = MPS_OK;
+- int ch;
+-
+- {
+- for (ch = 0; ch < numInputChannels; ch++) {
+- FIXP_DBL *pQmfRealAnalysis =
+- qmfReal__FDK[ch]; /* no delay in blind mode */
+- FIXP_DBL *pQmfImagAnalysis = qmfImag__FDK[ch];
+-
+- /* Write Input data to pQmfRealAnalysis. */
+- if (self->bShareDelayWithSBR) {
+- FDK_QmfDomain_GetSlot(
+- &self->pQmfDomain->QmfDomainIn[ch], ts + HYBRID_FILTER_DELAY, 0,
+- MAX_QMF_BANDS_TO_HYBRID, pQmfRealAnalysis, pQmfImagAnalysis, 15);
+- FDK_QmfDomain_GetSlot(&self->pQmfDomain->QmfDomainIn[ch], ts,
+- MAX_QMF_BANDS_TO_HYBRID, self->qmfBands,
+- pQmfRealAnalysis, pQmfImagAnalysis, 15);
+- } else {
+- FDK_QmfDomain_GetSlot(&self->pQmfDomain->QmfDomainIn[ch], ts, 0,
+- self->qmfBands, pQmfRealAnalysis,
+- pQmfImagAnalysis, 15);
+- }
+- if (ts == self->pQmfDomain->globalConf.nQmfTimeSlots - 1) {
+- /* Is currently also needed in case we dont have any overlap. We need to
+- * save lb_scale to ov_lb_scale */
+- FDK_QmfDomain_SaveOverlap(&self->pQmfDomain->QmfDomainIn[ch], 0);
+- }
+-
+- /* Apply clip protection to output. */
+- if (!isTwoChMode(self->upmixType) && !bypassMode) {
+- int i;
+- for (i = 0; i < self->qmfBands; i++) {
+- qmfReal__FDK[ch][i] =
+- fMult(qmfReal__FDK[ch][i], self->clipProtectGain__FDK);
+- qmfImag__FDK[ch][i] =
+- fMult(qmfImag__FDK[ch][i], self->clipProtectGain__FDK);
+- }
+- }
+-
+- } /* End of loop over numInputChannels */
+- }
+-
+- self->qmfInputDelayBufPos =
+- (self->qmfInputDelayBufPos + 1) % self->pc_filterdelay;
+-
+- return err;
+-}
+-
+-/*******************************************************************************
+- Functionname: SpatialDecHybridAnalysis
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Input:
+- float** pointers[4] leftReal, leftIm, rightReal, rightIm
+-
+- Output:
+- float self->qmfInputReal[MAX_INPUT_CHANNELS][MAX_TIME_SLOTS][MAX_QMF_BANDS];
+- float self->qmfInputImag[MAX_INPUT_CHANNELS][MAX_TIME_SLOTS][MAX_QMF_BANDS];
+-
+- float
+-self->hybInputReal[MAX_INPUT_CHANNELS][MAX_TIME_SLOTS][MAX_HYBRID_BANDS]; float
+-self->hybInputImag[MAX_INPUT_CHANNELS][MAX_TIME_SLOTS][MAX_HYBRID_BANDS];
+-
+-
+-*******************************************************************************/
+-SACDEC_ERROR SpatialDecHybridAnalysis(spatialDec *self, FIXP_DBL **qmfInputReal,
+- FIXP_DBL **qmfInputImag,
+- FIXP_DBL **hybOutputReal,
+- FIXP_DBL **hybOutputImag, const INT ts,
+- const INT numInputChannels) {
+- SACDEC_ERROR err = MPS_OK;
+- int ch;
+-
+- for (ch = 0; ch < numInputChannels;
+- ch++) /* hybrid filtering for down-mix signals */
+- {
+- if (self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_LD) {
+- int k;
+- /* No hybrid filtering. Just copy the QMF data. */
+- for (k = 0; k < self->hybridBands; k += 1) {
+- hybOutputReal[ch][k] = qmfInputReal[ch][k];
+- hybOutputImag[ch][k] = qmfInputImag[ch][k];
+- }
+- } else {
+- self->hybridAnalysis[ch].hfMode = self->bShareDelayWithSBR;
+-
+- if (self->stereoConfigIndex == 3)
+- FDK_ASSERT(self->hybridAnalysis[ch].hfMode == 0);
+- FDKhybridAnalysisApply(&self->hybridAnalysis[ch], qmfInputReal[ch],
+- qmfInputImag[ch], hybOutputReal[ch],
+- hybOutputImag[ch]);
+- }
+- }
+-
+- if ((self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_USAC) &&
+- self->residualCoding) {
+- self->hybridAnalysis[numInputChannels].hfMode = 0;
+- FDKhybridAnalysisApply(
+- &self->hybridAnalysis[numInputChannels],
+- self->qmfResidualReal__FDK[0][0], self->qmfResidualImag__FDK[0][0],
+- self->hybResidualReal__FDK[0], self->hybResidualImag__FDK[0]);
+- }
+-
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecCreateX(spatialDec *self, FIXP_DBL **hybInputReal,
+- FIXP_DBL **hybInputImag, FIXP_DBL **pxReal,
+- FIXP_DBL **pxImag) {
+- SACDEC_ERROR err = MPS_OK;
+- int row;
+-
+- /* Creating wDry */
+- for (row = 0; row < self->numInputChannels; row++) {
+- /* pointer to direct signals */
+- pxReal[row] = hybInputReal[row];
+- pxImag[row] = hybInputImag[row];
+- }
+-
+- return err;
+-}
+-
+-static void M2ParamToKernelMult(FIXP_SGL *RESTRICT pKernel,
+- FIXP_DBL *RESTRICT Mparam,
+- FIXP_DBL *RESTRICT MparamPrev,
+- int *RESTRICT pWidth, FIXP_SGL alpha__FDK,
+- int nBands) {
+- int pb;
+-
+- for (pb = 0; pb < nBands; pb++) {
+- FIXP_SGL tmp = FX_DBL2FX_SGL(
+- interpolateParameter(alpha__FDK, Mparam[pb], MparamPrev[pb]));
+-
+- int i = pWidth[pb];
+- if (i & 1) *pKernel++ = tmp;
+- if (i & 2) {
+- *pKernel++ = tmp;
+- *pKernel++ = tmp;
+- }
+- for (i >>= 2; i--;) {
+- *pKernel++ = tmp;
+- *pKernel++ = tmp;
+- *pKernel++ = tmp;
+- *pKernel++ = tmp;
+- }
+- }
+-}
+-
+-SACDEC_ERROR SpatialDecApplyM1_CreateW_Mode212(
+- spatialDec *self, const SPATIAL_BS_FRAME *frame, FIXP_DBL **xReal,
+- FIXP_DBL **xImag, FIXP_DBL **vReal, FIXP_DBL **vImag) {
+- SACDEC_ERROR err = MPS_OK;
+- int res;
+- FIXP_DBL *decorrInReal = vReal[0];
+- FIXP_DBL *decorrInImag = vImag[0];
+-
+- /* M1 does not do anything in 212 mode, so use simplified processing */
+- FDK_ASSERT(self->numVChannels == 2);
+- FDK_ASSERT(self->numDirektSignals == 1);
+- FDK_ASSERT(self->numDecorSignals == 1);
+- FDKmemcpy(vReal[0], xReal[0], self->hybridBands * sizeof(FIXP_DBL));
+- FDKmemcpy(vImag[0], xImag[0], self->hybridBands * sizeof(FIXP_DBL));
+-
+- if (isTsdActive(frame->TsdData)) {
+- /* Generate v_{x,nonTr} as input for allpass based decorrelator */
+- TsdGenerateNonTr(self->hybridBands, frame->TsdData, self->TsdTs, vReal[0],
+- vImag[0], vReal[1], vImag[1], &decorrInReal,
+- &decorrInImag);
+- }
+- /* - Decorrelate */
+- res = SpatialDecGetResidualIndex(self, 1);
+- if (FDKdecorrelateApply(&self->apDecor[0], decorrInReal, decorrInImag,
+- vReal[1], vImag[1],
+- self->param2hyb[self->residualBands[res]])) {
+- return MPS_NOTOK;
+- }
+- if (isTsdActive(frame->TsdData)) {
+- /* Generate v_{x,Tr}, apply transient decorrelator and add to allpass based
+- * decorrelator output */
+- TsdApply(self->hybridBands, frame->TsdData, &self->TsdTs,
+- vReal[0], /* input: v_x */
+- vImag[0],
+- vReal[1], /* input: d_{x,nonTr}; output: d_{x,nonTr} + d_{x,Tr} */
+- vImag[1]);
+- }
+-
+- /* Write residual signal in approriate parameter bands */
+- if (self->residualBands[res] > 0) {
+- int stopBand = self->param2hyb[self->residualBands[res]];
+- FDKmemcpy(vReal[1], self->hybResidualReal__FDK[res],
+- fixMin(stopBand, self->hybridBands) * sizeof(FIXP_DBL));
+- FDKmemcpy(vImag[1], self->hybResidualImag__FDK[res],
+- fixMin(stopBand, self->hybridBands) * sizeof(FIXP_DBL));
+- } /* (self->residualBands[res]>0) */
+-
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecApplyM2_Mode212(spatialDec *self, INT ps,
+- const FIXP_SGL alpha, FIXP_DBL **wReal,
+- FIXP_DBL **wImag,
+- FIXP_DBL **hybOutputRealDry,
+- FIXP_DBL **hybOutputImagDry) {
+- SACDEC_ERROR err = MPS_OK;
+- INT row;
+-
+- INT *pWidth = self->kernels_width;
+- /* for stereoConfigIndex == 3 case hybridBands is < 71 */
+- INT pb_max = self->kernels[self->hybridBands - 1] + 1;
+- INT max_row = self->numOutputChannels;
+-
+- INT M2_exp = 0;
+- if (self->residualCoding) M2_exp = 3;
+-
+- for (row = 0; row < max_row; row++) // 2 times
+- {
+- FIXP_DBL *Mparam0 = self->M2Real__FDK[row][0];
+- FIXP_DBL *Mparam1 = self->M2Real__FDK[row][1];
+- FIXP_DBL *MparamPrev0 = self->M2RealPrev__FDK[row][0];
+- FIXP_DBL *MparamPrev1 = self->M2RealPrev__FDK[row][1];
+-
+- FIXP_DBL *RESTRICT pHybOutRealDry = hybOutputRealDry[row];
+- FIXP_DBL *RESTRICT pHybOutImagDry = hybOutputImagDry[row];
+-
+- FIXP_DBL *RESTRICT pWReal0 = wReal[0];
+- FIXP_DBL *RESTRICT pWReal1 = wReal[1];
+- FIXP_DBL *RESTRICT pWImag0 = wImag[0];
+- FIXP_DBL *RESTRICT pWImag1 = wImag[1];
+- for (INT pb = 0; pb < pb_max; pb++) {
+- FIXP_DBL tmp0, tmp1;
+-
+- tmp0 = interpolateParameter(alpha, Mparam0[pb], MparamPrev0[pb]);
+- tmp1 = interpolateParameter(alpha, Mparam1[pb], MparamPrev1[pb]);
+-
+- INT i = pWidth[pb];
+-
+- do // about 3-4 times
+- {
+- FIXP_DBL var0, var1, real, imag;
+-
+- var0 = *pWReal0++;
+- var1 = *pWReal1++;
+- real = fMultDiv2(var0, tmp0);
+- var0 = *pWImag0++;
+- real = fMultAddDiv2(real, var1, tmp1);
+- var1 = *pWImag1++;
+- imag = fMultDiv2(var0, tmp0);
+- *pHybOutRealDry++ = real << (1 + M2_exp);
+- imag = fMultAddDiv2(imag, var1, tmp1);
+- *pHybOutImagDry++ = imag << (1 + M2_exp);
+- } while (--i != 0);
+- }
+- }
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecApplyM2_Mode212_ResidualsPlusPhaseCoding(
+- spatialDec *self, INT ps, const FIXP_SGL alpha, FIXP_DBL **wReal,
+- FIXP_DBL **wImag, FIXP_DBL **hybOutputRealDry,
+- FIXP_DBL **hybOutputImagDry) {
+- SACDEC_ERROR err = MPS_OK;
+- INT row;
+- INT scale_param_m2;
+- INT *pWidth = self->kernels_width;
+- INT pb_max = self->kernels[self->hybridBands - 1] + 1;
+-
+- scale_param_m2 = SCALE_PARAM_M2_212_PRED + SCALE_DATA_APPLY_M2;
+-
+- for (row = 0; row < self->numM2rows; row++) {
+- INT qs, pb;
+-
+- FIXP_DBL *RESTRICT pWReal0 = wReal[0];
+- FIXP_DBL *RESTRICT pWImag0 = wImag[0];
+- FIXP_DBL *RESTRICT pWReal1 = wReal[1];
+- FIXP_DBL *RESTRICT pWImag1 = wImag[1];
+-
+- FIXP_DBL *MReal0 = self->M2Real__FDK[row][0];
+- FIXP_DBL *MImag0 = self->M2Imag__FDK[row][0];
+- FIXP_DBL *MReal1 = self->M2Real__FDK[row][1];
+- FIXP_DBL *MRealPrev0 = self->M2RealPrev__FDK[row][0];
+- FIXP_DBL *MImagPrev0 = self->M2ImagPrev__FDK[row][0];
+- FIXP_DBL *MRealPrev1 = self->M2RealPrev__FDK[row][1];
+-
+- FIXP_DBL *RESTRICT pHybOutRealDry = hybOutputRealDry[row];
+- FIXP_DBL *RESTRICT pHybOutImagDry = hybOutputImagDry[row];
+-
+- FDK_ASSERT(!(self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_LD));
+- FDK_ASSERT((pWidth[0] + pWidth[1]) >= 3);
+-
+- for (pb = 0, qs = 3; pb < 2; pb++) {
+- INT s;
+- FIXP_DBL maxVal;
+- FIXP_SGL mReal1;
+- FIXP_SGL mReal0, mImag0;
+- FIXP_DBL iReal0, iImag0, iReal1;
+-
+- iReal0 = interpolateParameter(alpha, MReal0[pb], MRealPrev0[pb]);
+- iImag0 = -interpolateParameter(alpha, MImag0[pb], MImagPrev0[pb]);
+- iReal1 = interpolateParameter(alpha, MReal1[pb], MRealPrev1[pb]);
+-
+- maxVal = fAbs(iReal0) | fAbs(iImag0);
+- maxVal |= fAbs(iReal1);
+-
+- s = fMax(CntLeadingZeros(maxVal) - 1, 0);
+- s = fMin(s, scale_param_m2);
+-
+- mReal0 = FX_DBL2FX_SGL(iReal0 << s);
+- mImag0 = FX_DBL2FX_SGL(iImag0 << s);
+- mReal1 = FX_DBL2FX_SGL(iReal1 << s);
+-
+- s = scale_param_m2 - s;
+-
+- INT i = pWidth[pb];
+-
+- do {
+- FIXP_DBL real, imag, wReal0, wImag0, wReal1, wImag1;
+-
+- wReal0 = *pWReal0++;
+- wImag0 = *pWImag0++;
+- wReal1 = *pWReal1++;
+- wImag1 = *pWImag1++;
+-
+- cplxMultDiv2(&real, &imag, wReal0, wImag0, mReal0, mImag0);
+-
+- *pHybOutRealDry++ = fMultAddDiv2(real, wReal1, mReal1) << s;
+- *pHybOutImagDry++ = fMultAddDiv2(imag, wImag1, mReal1) << s;
+-
+- if (qs > 0) {
+- mImag0 = -mImag0;
+- qs--;
+- }
+- } while (--i != 0);
+- }
+-
+- for (; pb < pb_max; pb++) {
+- INT s;
+- FIXP_DBL maxVal;
+- FIXP_SGL mReal1;
+- FIXP_SGL mReal0, mImag0;
+- FIXP_DBL iReal0, iImag0, iReal1;
+-
+- iReal0 = interpolateParameter(alpha, MReal0[pb], MRealPrev0[pb]);
+- iImag0 = interpolateParameter(alpha, MImag0[pb], MImagPrev0[pb]);
+- iReal1 = interpolateParameter(alpha, MReal1[pb], MRealPrev1[pb]);
+-
+- maxVal = fAbs(iReal0) | fAbs(iImag0);
+- maxVal |= fAbs(iReal1);
+-
+- s = fMax(CntLeadingZeros(maxVal) - 1, 0);
+- s = fMin(s, scale_param_m2);
+-
+- mReal0 = FX_DBL2FX_SGL(iReal0 << s);
+- mImag0 = FX_DBL2FX_SGL(iImag0 << s);
+- mReal1 = FX_DBL2FX_SGL(iReal1 << s);
+-
+- s = scale_param_m2 - s;
+-
+- INT i = pWidth[pb];
+-
+- do {
+- FIXP_DBL real, imag, wReal0, wImag0, wReal1, wImag1;
+-
+- wReal0 = *pWReal0++;
+- wImag0 = *pWImag0++;
+- wReal1 = *pWReal1++;
+- wImag1 = *pWImag1++;
+-
+- cplxMultDiv2(&real, &imag, wReal0, wImag0, mReal0, mImag0);
+-
+- *pHybOutRealDry++ = fMultAddDiv2(real, wReal1, mReal1) << s;
+- *pHybOutImagDry++ = fMultAddDiv2(imag, wImag1, mReal1) << s;
+- } while (--i != 0);
+- }
+- }
+-
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecApplyM2(spatialDec *self, INT ps, const FIXP_SGL alpha,
+- FIXP_DBL **wReal, FIXP_DBL **wImag,
+- FIXP_DBL **hybOutputRealDry,
+- FIXP_DBL **hybOutputImagDry,
+- FIXP_DBL **hybOutputRealWet,
+- FIXP_DBL **hybOutputImagWet) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- {
+- int qs, row, col;
+- int complexHybBands;
+- int complexParBands;
+- int scale_param_m2 = 0;
+- int toolsDisabled;
+-
+- UCHAR activParamBands;
+- FIXP_DBL *RESTRICT pWReal, *RESTRICT pWImag, *RESTRICT pHybOutRealDry,
+- *RESTRICT pHybOutImagDry, *RESTRICT pHybOutRealWet,
+- *RESTRICT pHybOutImagWet;
+- C_ALLOC_SCRATCH_START(pKernel, FIXP_SGL, MAX_HYBRID_BANDS);
+-
+- /* The wet signal is added to the dry signal directly in applyM2 if GES and
+- * STP are disabled */
+- toolsDisabled =
+- ((self->tempShapeConfig == 1) || (self->tempShapeConfig == 2)) ? 0 : 1;
+-
+- {
+- complexHybBands = self->hybridBands;
+- complexParBands = self->numParameterBands;
+- }
+-
+- FDKmemclear(hybOutputImagDry[0],
+- self->createParams.maxNumOutputChannels *
+- self->createParams.maxNumCmplxHybBands * sizeof(FIXP_DBL));
+- FDKmemclear(hybOutputRealDry[0], self->createParams.maxNumOutputChannels *
+- self->createParams.maxNumHybridBands *
+- sizeof(FIXP_DBL));
+-
+- if (!toolsDisabled) {
+- FDKmemclear(hybOutputRealWet[0],
+- self->createParams.maxNumOutputChannels *
+- self->createParams.maxNumHybridBands * sizeof(FIXP_DBL));
+- FDKmemclear(hybOutputImagWet[0],
+- self->createParams.maxNumOutputChannels *
+- self->createParams.maxNumCmplxHybBands *
+- sizeof(FIXP_DBL));
+- }
+-
+- if (self->phaseCoding == 3) {
+- /* + SCALE_DATA_APPLY_M2 to compensate for Div2 below ?! */
+- scale_param_m2 = SCALE_PARAM_M2_212_PRED + SCALE_DATA_APPLY_M2;
+- }
+-
+- for (row = 0; row < self->numM2rows; row++) {
+- pHybOutRealDry = hybOutputRealDry[row];
+- pHybOutImagDry = hybOutputImagDry[row];
+-
+- if (toolsDisabled) {
+- pHybOutRealWet = hybOutputRealDry[row];
+- pHybOutImagWet = hybOutputImagDry[row];
+- } else {
+- pHybOutRealWet = hybOutputRealWet[row];
+- pHybOutImagWet = hybOutputImagWet[row];
+- }
+-
+- for (col = 0; col < self->numDirektSignals; col++) {
+- if (self->pActivM2ParamBands ==
+- 0) { /* default setting, calculate all rows and columns */
+- activParamBands = 1;
+- } else {
+- if (self->pActivM2ParamBands[MAX_M2_INPUT * row +
+- col]) /* table with activ and inactiv
+- bands exists for current
+- configuration */
+- activParamBands = 1;
+- else
+- activParamBands = 0;
+- }
+- if (activParamBands) {
+- pWReal = wReal[col];
+- pWImag = wImag[col];
+-
+- M2ParamToKernelMult(pKernel, self->M2Real__FDK[row][col],
+- self->M2RealPrev__FDK[row][col],
+- self->kernels_width, alpha,
+- self->numParameterBands);
+-
+- if (1 && (self->phaseCoding != 3)) {
+- /* direct signals */
+- {
+- /* only one sample will be assigned to each row, hence
+- * accumulation is not neccessary; that is valid for all
+- * configurations */
+- for (qs = 0; qs < complexHybBands; qs++) {
+- pHybOutRealDry[qs] = fMult(pWReal[qs], pKernel[qs]);
+- pHybOutImagDry[qs] = fMult(pWImag[qs], pKernel[qs]);
+- }
+- }
+- } else { /* isBinauralMode(self->upmixType) */
+-
+- for (qs = 0; qs < complexHybBands; qs++) {
+- pHybOutRealDry[qs] += fMultDiv2(pWReal[qs], pKernel[qs])
+- << (scale_param_m2);
+- pHybOutImagDry[qs] += fMultDiv2(pWImag[qs], pKernel[qs])
+- << (scale_param_m2);
+- }
+-
+- M2ParamToKernelMult(pKernel, self->M2Imag__FDK[row][col],
+- self->M2ImagPrev__FDK[row][col],
+- self->kernels_width, alpha, complexParBands);
+-
+- /* direct signals sign is -1 for qs = 0,2 */
+- pHybOutRealDry[0] += fMultDiv2(pWImag[0], pKernel[0])
+- << (scale_param_m2);
+- pHybOutImagDry[0] -= fMultDiv2(pWReal[0], pKernel[0])
+- << (scale_param_m2);
+-
+- pHybOutRealDry[2] += fMultDiv2(pWImag[2], pKernel[2])
+- << (scale_param_m2);
+- pHybOutImagDry[2] -= fMultDiv2(pWReal[2], pKernel[2])
+- << (scale_param_m2);
+-
+- /* direct signals sign is +1 for qs = 1,3,4,5,...,complexHybBands */
+- pHybOutRealDry[1] -= fMultDiv2(pWImag[1], pKernel[1])
+- << (scale_param_m2);
+- pHybOutImagDry[1] += fMultDiv2(pWReal[1], pKernel[1])
+- << (scale_param_m2);
+-
+- for (qs = 3; qs < complexHybBands; qs++) {
+- pHybOutRealDry[qs] -= fMultDiv2(pWImag[qs], pKernel[qs])
+- << (scale_param_m2);
+- pHybOutImagDry[qs] += fMultDiv2(pWReal[qs], pKernel[qs])
+- << (scale_param_m2);
+- }
+- } /* self->upmixType */
+- } /* if (activParamBands) */
+- } /* self->numDirektSignals */
+-
+- for (; col < self->numVChannels; col++) {
+- if (self->pActivM2ParamBands ==
+- 0) { /* default setting, calculate all rows and columns */
+- activParamBands = 1;
+- } else {
+- if (self->pActivM2ParamBands[MAX_M2_INPUT * row +
+- col]) /* table with activ and inactiv
+- bands exists for current
+- configuration */
+- activParamBands = 1;
+- else
+- activParamBands = 0;
+- }
+-
+- if (activParamBands) {
+- int resBandIndex;
+- int resHybIndex;
+-
+- resBandIndex =
+- self->residualBands[SpatialDecGetResidualIndex(self, col)];
+- resHybIndex = self->param2hyb[resBandIndex];
+-
+- pWReal = wReal[col];
+- pWImag = wImag[col];
+-
+- M2ParamToKernelMult(pKernel, self->M2Real__FDK[row][col],
+- self->M2RealPrev__FDK[row][col],
+- self->kernels_width, alpha,
+- self->numParameterBands);
+-
+- if (1 && (self->phaseCoding != 3)) {
+- /* residual signals */
+- for (qs = 0; qs < resHybIndex; qs++) {
+- pHybOutRealDry[qs] += fMult(pWReal[qs], pKernel[qs]);
+- pHybOutImagDry[qs] += fMult(pWImag[qs], pKernel[qs]);
+- }
+- /* decor signals */
+- for (; qs < complexHybBands; qs++) {
+- pHybOutRealWet[qs] += fMult(pWReal[qs], pKernel[qs]);
+- pHybOutImagWet[qs] += fMult(pWImag[qs], pKernel[qs]);
+- }
+- } else { /* self->upmixType */
+- /* residual signals */
+- FIXP_DBL *RESTRICT pHybOutReal;
+- FIXP_DBL *RESTRICT pHybOutImag;
+-
+- for (qs = 0; qs < resHybIndex; qs++) {
+- pHybOutRealDry[qs] += fMultDiv2(pWReal[qs], pKernel[qs])
+- << (scale_param_m2);
+- pHybOutImagDry[qs] += fMultDiv2(pWImag[qs], pKernel[qs])
+- << (scale_param_m2);
+- }
+- /* decor signals */
+- for (; qs < complexHybBands; qs++) {
+- pHybOutRealWet[qs] += fMultDiv2(pWReal[qs], pKernel[qs])
+- << (scale_param_m2);
+- pHybOutImagWet[qs] += fMultDiv2(pWImag[qs], pKernel[qs])
+- << (scale_param_m2);
+- }
+-
+- M2ParamToKernelMult(pKernel, self->M2Imag__FDK[row][col],
+- self->M2ImagPrev__FDK[row][col],
+- self->kernels_width, alpha, complexParBands);
+-
+- /* direct signals sign is -1 for qs = 0,2 */
+- /* direct signals sign is +1 for qs = 1,3.. */
+- if (toolsDisabled) {
+- pHybOutRealDry[0] += fMultDiv2(pWImag[0], pKernel[0])
+- << (scale_param_m2);
+- pHybOutImagDry[0] -= fMultDiv2(pWReal[0], pKernel[0])
+- << (scale_param_m2);
+-
+- pHybOutRealDry[1] -= fMultDiv2(pWImag[1], pKernel[1])
+- << (scale_param_m2);
+- pHybOutImagDry[1] += fMultDiv2(pWReal[1], pKernel[1])
+- << (scale_param_m2);
+-
+- pHybOutRealDry[2] += fMultDiv2(pWImag[2], pKernel[2])
+- << (scale_param_m2);
+- pHybOutImagDry[2] -= fMultDiv2(pWReal[2], pKernel[2])
+- << (scale_param_m2);
+- } else {
+- pHybOutReal = &pHybOutRealDry[0];
+- pHybOutImag = &pHybOutImagDry[0];
+- if (0 == resHybIndex) {
+- pHybOutReal = &pHybOutRealWet[0];
+- pHybOutImag = &pHybOutImagWet[0];
+- }
+- pHybOutReal[0] += fMultDiv2(pWImag[0], pKernel[0])
+- << (scale_param_m2);
+- pHybOutImag[0] -= fMultDiv2(pWReal[0], pKernel[0])
+- << (scale_param_m2);
+-
+- if (1 == resHybIndex) {
+- pHybOutReal = &pHybOutRealWet[0];
+- pHybOutImag = &pHybOutImagWet[0];
+- }
+- pHybOutReal[1] -= fMultDiv2(pWImag[1], pKernel[1])
+- << (scale_param_m2);
+- pHybOutImag[1] += fMultDiv2(pWReal[1], pKernel[1])
+- << (scale_param_m2);
+-
+- if (2 == resHybIndex) {
+- pHybOutReal = &pHybOutRealWet[0];
+- pHybOutImag = &pHybOutImagWet[0];
+- }
+- pHybOutReal[2] += fMultDiv2(pWImag[2], pKernel[2])
+- << (scale_param_m2);
+- pHybOutImag[2] -= fMultDiv2(pWReal[2], pKernel[2])
+- << (scale_param_m2);
+- }
+-
+- for (qs = 3; qs < resHybIndex; qs++) {
+- pHybOutRealDry[qs] -= fMultDiv2(pWImag[qs], pKernel[qs])
+- << (scale_param_m2);
+- pHybOutImagDry[qs] += fMultDiv2(pWReal[qs], pKernel[qs])
+- << (scale_param_m2);
+- }
+- /* decor signals */
+- for (; qs < complexHybBands; qs++) {
+- pHybOutRealWet[qs] -= fMultDiv2(pWImag[qs], pKernel[qs])
+- << (scale_param_m2);
+- pHybOutImagWet[qs] += fMultDiv2(pWReal[qs], pKernel[qs])
+- << (scale_param_m2);
+- }
+- } /* self->upmixType */
+- } /* if (activParamBands) { */
+- } /* self->numVChannels */
+- }
+-
+- C_ALLOC_SCRATCH_END(pKernel, FIXP_SGL, MAX_HYBRID_BANDS);
+- }
+-
+- return err;
+-}
+-
+-SACDEC_ERROR SpatialDecSynthesis(spatialDec *self, const INT ts,
+- FIXP_DBL **hybOutputReal,
+- FIXP_DBL **hybOutputImag, PCM_MPS *timeOut,
+- const INT numInputChannels,
+- const FDK_channelMapDescr *const mapDescr) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- int ch;
+- int stride, offset;
+-
+- stride = self->numOutputChannelsAT;
+- offset = 1;
+-
+- PCM_MPS *pTimeOut__FDK =
+- &timeOut[stride * self->pQmfDomain->globalConf.nBandsSynthesis * ts];
+- C_ALLOC_SCRATCH_START(pQmfReal, FIXP_DBL, QMF_MAX_SYNTHESIS_BANDS);
+- C_ALLOC_SCRATCH_START(pQmfImag, FIXP_DBL, QMF_MAX_SYNTHESIS_BANDS);
+-
+- for (ch = 0; ch < self->numOutputChannelsAT; ch++) {
+- if (self->pConfigCurrent->syntaxFlags & SACDEC_SYNTAX_LD) {
+- int k;
+- /* No hybrid filtering. Just copy the QMF data. */
+- for (k = 0; k < self->hybridBands; k += 1) {
+- pQmfReal[k] = hybOutputReal[ch][k];
+- pQmfImag[k] = hybOutputImag[ch][k];
+- }
+- } else {
+- FDKhybridSynthesisApply(&self->hybridSynthesis[ch], hybOutputReal[ch],
+- hybOutputImag[ch], pQmfReal, pQmfImag);
+- }
+-
+- /* Map channel indices from MPEG Surround -> PCE style -> channelMapping[]
+- */
+- FDK_ASSERT(self->numOutputChannelsAT <= 6);
+- int outCh = FDK_chMapDescr_getMapValue(mapDescr, mapChannel(self, ch),
+- self->numOutputChannelsAT);
+-
+- {
+- if (self->stereoConfigIndex == 3) {
+- /* MPS -> SBR */
+- int i;
+- FIXP_DBL *pWorkBufReal, *pWorkBufImag;
+- FDK_ASSERT((self->pQmfDomain->QmfDomainOut[outCh].fb.outGain_m ==
+- (FIXP_DBL)0x80000000) &&
+- (self->pQmfDomain->QmfDomainOut[outCh].fb.outGain_e == 0));
+- FDK_QmfDomain_GetWorkBuffer(&self->pQmfDomain->QmfDomainIn[outCh], ts,
+- &pWorkBufReal, &pWorkBufImag);
+- FDK_ASSERT(self->qmfBands <=
+- self->pQmfDomain->QmfDomainIn[outCh].workBuf_nBands);
+- for (i = 0; i < self->qmfBands; i++) {
+- pWorkBufReal[i] = pQmfReal[i];
+- pWorkBufImag[i] = pQmfImag[i];
+- }
+- self->pQmfDomain->QmfDomainIn[outCh].scaling.lb_scale =
+- -7; /*-ALGORITHMIC_SCALING_IN_ANALYSIS_FILTERBANK;*/
+- self->pQmfDomain->QmfDomainIn[outCh].scaling.lb_scale -=
+- self->pQmfDomain->QmfDomainIn[outCh].fb.filterScale;
+- self->pQmfDomain->QmfDomainIn[outCh].scaling.lb_scale -=
+- self->clipProtectGainSF__FDK;
+-
+- } else {
+- /* Call the QMF synthesis for dry. */
+- err = CalculateSpaceSynthesisQmf(&self->pQmfDomain->QmfDomainOut[outCh],
+- pQmfReal, pQmfImag, stride,
+- pTimeOut__FDK + (offset * outCh));
+- }
+- if (err != MPS_OK) goto bail;
+- }
+- } /* ch loop */
+-
+-bail:
+- C_ALLOC_SCRATCH_END(pQmfImag, FIXP_DBL, QMF_MAX_SYNTHESIS_BANDS);
+- C_ALLOC_SCRATCH_END(pQmfReal, FIXP_DBL, QMF_MAX_SYNTHESIS_BANDS);
+-
+- return err;
+-}
+-
+-void SpatialDecBufferMatrices(spatialDec *self) {
+- int row, col;
+- int complexParBands;
+- complexParBands = self->numParameterBands;
+-
+- /*
+- buffer matrices M2
+- */
+- for (row = 0; row < self->numM2rows; row++) {
+- for (col = 0; col < self->numVChannels; col++) {
+- FDKmemcpy(self->M2RealPrev__FDK[row][col], self->M2Real__FDK[row][col],
+- self->numParameterBands * sizeof(FIXP_DBL));
+- if (0 || (self->phaseCoding == 3)) {
+- FDKmemcpy(self->M2ImagPrev__FDK[row][col], self->M2Imag__FDK[row][col],
+- complexParBands * sizeof(FIXP_DBL));
+- }
+- }
+- }
+-
+- /* buffer phase */
+- FDKmemcpy(self->PhasePrevLeft__FDK, self->PhaseLeft__FDK,
+- self->numParameterBands * sizeof(FIXP_DBL));
+- FDKmemcpy(self->PhasePrevRight__FDK, self->PhaseRight__FDK,
+- self->numParameterBands * sizeof(FIXP_DBL));
+-}
+-
+-#define PHASE_SCALE 2
+-
+-#ifndef P_PI
+-#define P_PI 3.1415926535897932
+-#endif
+-
+-/* For better precision, PI (pi_x2) is already doubled */
+-static FIXP_DBL interp_angle__FDK(FIXP_DBL angle1, FIXP_DBL angle2,
+- FIXP_SGL alpha, FIXP_DBL pi_x2) {
+- if (angle2 - angle1 > (pi_x2 >> 1)) angle2 -= pi_x2;
+-
+- if (angle1 - angle2 > (pi_x2 >> 1)) angle1 -= pi_x2;
+-
+- return interpolateParameter(alpha, angle2, angle1);
+-}
+-
+-/*
+- *
+- */
+-void SpatialDecApplyPhase(spatialDec *self, FIXP_SGL alpha__FDK,
+- int lastSlotOfParamSet) {
+- int pb, qs;
+- FIXP_DBL ppb[MAX_PARAMETER_BANDS *
+- 4]; /* left real, imag - right real, imag interleaved */
+-
+- const FIXP_DBL pi_x2 = PIx2__IPD;
+- for (pb = 0; pb < self->numParameterBands; pb++) {
+- FIXP_DBL pl, pr;
+-
+- pl = interp_angle__FDK(self->PhasePrevLeft__FDK[pb],
+- self->PhaseLeft__FDK[pb], alpha__FDK, pi_x2);
+- pr = interp_angle__FDK(self->PhasePrevRight__FDK[pb],
+- self->PhaseRight__FDK[pb], alpha__FDK, pi_x2);
+-
+- inline_fixp_cos_sin(pl, pr, IPD_SCALE, &ppb[4 * pb]);
+- }
+-
+- /* sign is -1 for qs = 0,2 and +1 for qs = 1 */
+-
+- const SCHAR *kernels = &self->kernels[0];
+-
+- FIXP_DBL *Dry_real0 = &self->hybOutputRealDry__FDK[0][0];
+- FIXP_DBL *Dry_imag0 = &self->hybOutputImagDry__FDK[0][0];
+- FIXP_DBL *Dry_real1 = &self->hybOutputRealDry__FDK[1][0];
+- FIXP_DBL *Dry_imag1 = &self->hybOutputImagDry__FDK[1][0];
+-
+- for (qs = 2; qs >= 0; qs--) {
+- FIXP_DBL out_re, out_im;
+-
+- pb = *kernels++;
+- if (qs == 1) /* sign[qs] >= 0 */
+- {
+- cplxMultDiv2(&out_re, &out_im, *Dry_real0, *Dry_imag0, ppb[4 * pb + 0],
+- ppb[4 * pb + 1]);
+- out_re <<= PHASE_SCALE - 1;
+- out_im <<= PHASE_SCALE - 1;
+- *Dry_real0++ = out_re;
+- *Dry_imag0++ = out_im;
+-
+- cplxMultDiv2(&out_re, &out_im, *Dry_real1, *Dry_imag1, ppb[4 * pb + 2],
+- ppb[4 * pb + 3]);
+- out_re <<= PHASE_SCALE - 1;
+- out_im <<= PHASE_SCALE - 1;
+- *Dry_real1++ = out_re;
+- *Dry_imag1++ = out_im;
+- } else {
+- cplxMultDiv2(&out_re, &out_im, *Dry_real0, *Dry_imag0, ppb[4 * pb + 0],
+- -ppb[4 * pb + 1]);
+- out_re <<= PHASE_SCALE - 1;
+- out_im <<= PHASE_SCALE - 1;
+- *Dry_real0++ = out_re;
+- *Dry_imag0++ = out_im;
+-
+- cplxMultDiv2(&out_re, &out_im, *Dry_real1, *Dry_imag1, ppb[4 * pb + 2],
+- -ppb[4 * pb + 3]);
+- out_re <<= PHASE_SCALE - 1;
+- out_im <<= PHASE_SCALE - 1;
+- *Dry_real1++ = out_re;
+- *Dry_imag1++ = out_im;
+- }
+- }
+-
+- /* sign is +1 for qs >=3 */
+- for (qs = self->hybridBands - 3; qs--;) {
+- FIXP_DBL out_re, out_im;
+-
+- pb = *kernels++;
+- cplxMultDiv2(&out_re, &out_im, *Dry_real0, *Dry_imag0, ppb[4 * pb + 0],
+- ppb[4 * pb + 1]);
+- out_re <<= PHASE_SCALE - 1;
+- out_im <<= PHASE_SCALE - 1;
+- *Dry_real0++ = out_re;
+- *Dry_imag0++ = out_im;
+-
+- cplxMultDiv2(&out_re, &out_im, *Dry_real1, *Dry_imag1, ppb[4 * pb + 2],
+- ppb[4 * pb + 3]);
+- out_re <<= PHASE_SCALE - 1;
+- out_im <<= PHASE_SCALE - 1;
+- *Dry_real1++ = out_re;
+- *Dry_imag1++ = out_im;
+- }
+-}
+diff --git a/libSACdec/src/sac_process.h b/libSACdec/src/sac_process.h
+deleted file mode 100644
+index ee2f2fe..0000000
+--- a/libSACdec/src/sac_process.h
++++ /dev/null
+@@ -1,297 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Processing
+-
+-*******************************************************************************/
+-
+-/*!
+- \file
+- \brief Polyphase Filterbank
+-*/
+-
+-#ifndef SAC_PROCESS_H
+-#define SAC_PROCESS_H
+-
+-#include "sac_dec.h"
+-
+-void SpatialDecApplyPhase(spatialDec *self, FIXP_SGL alpha,
+- int lastSlotOfParamSet);
+-
+-/**
+- * \brief Apply QMF Analysis Filterbank.
+- *
+- * Calculates qmf data on downmix input time data.
+- * Delaylines will be applied if necessaray.
+- *
+- * \param self A spatial decoder handle.
+- * \param inData Downmix channel time data as input.
+- * \param ts Signals time slot offset for input buffer.
+- * \param qmfReal Downmix channel qmf output data.
+- * \param qmfImag Downmix channel qmf output data.
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR SpatialDecQMFAnalysis(spatialDec *self, const PCM_MPS *inData,
+- const INT ts, const INT bypassMode,
+- FIXP_DBL **qmfReal, FIXP_DBL **qmfImag,
+- const int numInputChannels);
+-
+-/**
+- * \brief Feed spatial decoder with external qmf data.
+- *
+- * \param self A spatial decoder handle.
+- * \param qmfInDataReal External qmf downmix data as input.
+- * \param qmfInDataImag External qmf downmix data as input.
+- * \param ts Signals time slot in input buffer to process.
+- * \param qmfReal Downmix channel qmf output data.
+- * \param qmfImag Downmix channel qmf output data.
+- * \param numInputChannels Number of input channels. Might differ from
+- * self->numInputChannels.
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR SpatialDecFeedQMF(spatialDec *self, FIXP_DBL **qmfInDataReal,
+- FIXP_DBL **qmfInDataImag, const INT ts,
+- const INT bypassMode, FIXP_DBL **qmfReal,
+- FIXP_DBL **qmfImag, const INT numInputChannels);
+-
+-/**
+- * \brief Apply Hybrdid Analysis Filterbank.
+- *
+- * Calculates hybrid data on downmix input data.
+- * Residual hybrid signals will also be calculated on current slot if available.
+- *
+- * \param self A spatial decoder handle.
+- * \param qmfInputReal Downmix channel qmf data as input.
+- * \param qmfInputImag Downmix channel qmf data as input.
+- * \param hybOutputReal Downmix channel hybrid output data.
+- * \param hybOutputImag Downmix channel hybrid output data.
+- * \param ts Signals time slot in spatial frame to process.
+- * \param numInputChannels Number of input channels. Might differ from
+- * self->numInputChannels.
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR SpatialDecHybridAnalysis(spatialDec *self, FIXP_DBL **qmfInputReal,
+- FIXP_DBL **qmfInputImag,
+- FIXP_DBL **hybOutputReal,
+- FIXP_DBL **hybOutputImag, const INT ts,
+- const INT numInputChannels);
+-
+-/**
+- * \brief Create X data.
+- *
+- * Returns a pointer list over Xchannels pointing to downmix input channels
+- * and to residual channels when provided.
+- *
+- * \param self A spatial decoder handle.
+- * \param hybInputReal Downmix channel hybrid data as input.
+- * \param hybInputImag Downmix channel hybrid data as input.
+- * \param pxReal Pointer to hybrid and residual data as output.
+- * \param pxImag Pointer to hybrid and residual data as output.
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR SpatialDecCreateX(spatialDec *self, FIXP_DBL **hybInputReal,
+- FIXP_DBL **hybInputImag, FIXP_DBL **pxReal,
+- FIXP_DBL **pxImag);
+-
+-/**
+- * \brief MPS212 combined version of apply M1 parameters and create wet signal
+- *
+- * \param self A spatial decoder handle.
+- * \param xReal Downmix and residual X data as input.
+- * \param xImag Downmix and residual X data as input.
+- * \param vReal output data: [0] direct signal (V); [1] wet signal
+- * (W).
+- * \param vImag output data: [0] direct signal (V); [1] wet signal
+- * (W).
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR SpatialDecApplyM1_CreateW_Mode212(
+- spatialDec *self, const SPATIAL_BS_FRAME *frame, FIXP_DBL **xReal,
+- FIXP_DBL **xImag, FIXP_DBL **vReal, FIXP_DBL **vImag);
+-
+-/**
+- * \brief Apply M2 parameters.
+- *
+- * \param self A spatial decoder handle.
+- * \param ps Signals parameter band from where M2 parameter to
+- * use.
+- * \param alpha Smoothing factor between current and previous
+- * parameter band. Rangeability between 0.f and 1.f.
+- * \param wReal Wet input data.
+- * \param wImag Wet input data.
+- * \param hybOutputRealDry Dry output data.
+- * \param hybOutputImagDry Dry output data.
+- * \param hybOutputRealWet Wet output data.
+- * \param hybOutputImagWet Wet output data.
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR SpatialDecApplyM2(spatialDec *self, INT ps, const FIXP_SGL alpha,
+- FIXP_DBL **wReal, FIXP_DBL **wImag,
+- FIXP_DBL **hybOutputRealDry,
+- FIXP_DBL **hybOutputImagDry,
+- FIXP_DBL **hybOutputRealWet,
+- FIXP_DBL **hybOutputImagWet);
+-
+-/**
+- * \brief Apply M2 parameter for 212 mode with residualCoding and phaseCoding.
+- *
+- * \param self [i] A spatial decoder handle.
+- * \param ps [i] Signals parameter band from where M2 parameter
+- * to use.
+- * \param alpha [i] Smoothing factor between current and previous
+- * parameter band. Rangeability between 0.f and 1.f.
+- * \param wReal [i] Wet input data.
+- * \param wImag [i] Wet input data.
+- * \param hybOutputRealDry [o] Dry output data.
+- * \param hybOutputImagDry [o] Dry output data.
+- *
+- * \return error
+- */
+-SACDEC_ERROR SpatialDecApplyM2_Mode212_ResidualsPlusPhaseCoding(
+- spatialDec *self, INT ps, const FIXP_SGL alpha, FIXP_DBL **wReal,
+- FIXP_DBL **wImag, FIXP_DBL **hybOutputRealDry, FIXP_DBL **hybOutputImagDry);
+-
+-/**
+- * \brief Apply M2 parameter for 212 mode, upmix from mono to stereo.
+- *
+- * \param self [i] A spatial decoder handle.
+- * \param ps [i] Signals parameter band from where M2 parameter
+- * to use.
+- * \param alpha [i] Smoothing factor between current and previous
+- * parameter band. Rangeability between 0.f and 1.f.
+- * \param wReal [i] Wet input data.
+- * \param wImag [i] Wet input data.
+- * \param hybOutputRealDry [o] Dry output data.
+- * \param hybOutputImagDry [o] Dry output data.
+- *
+- * \return error
+- */
+-SACDEC_ERROR SpatialDecApplyM2_Mode212(spatialDec *self, INT ps,
+- const FIXP_SGL alpha, FIXP_DBL **wReal,
+- FIXP_DBL **wImag,
+- FIXP_DBL **hybOutputRealDry,
+- FIXP_DBL **hybOutputImagDry);
+-
+-/**
+- * \brief Convert Hybrid input to output audio data.
+- *
+- * \param hSpaceSynthesisQmf A spatial decoder handle.
+- * \param ts Signals time slot in spatial frame to process.
+- * \param hybOutputReal Hybrid data as input.
+- * \param hybOutputImag Hybrid data as input.
+- * \param timeOut audio output data.
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR SpatialDecSynthesis(spatialDec *self, const INT ts,
+- FIXP_DBL **hybOutputReal,
+- FIXP_DBL **hybOutputImag, PCM_MPS *timeOut,
+- const INT numInputChannels,
+- const FDK_channelMapDescr *const mapDescr);
+-
+-void SpatialDecBufferMatrices(spatialDec *self);
+-
+-FIXP_DBL getChGain(spatialDec *self, UINT ch, INT *scale);
+-
+-#endif
+diff --git a/libSACdec/src/sac_qmf.cpp b/libSACdec/src/sac_qmf.cpp
+deleted file mode 100644
+index a075490..0000000
+--- a/libSACdec/src/sac_qmf.cpp
++++ /dev/null
+@@ -1,156 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec QMF processing
+-
+-*******************************************************************************/
+-
+-#include "sac_qmf.h"
+-
+-#include "FDK_matrixCalloc.h"
+-#include "sac_dec_interface.h"
+-#include "sac_rom.h"
+-
+-#include "qmf.h"
+-
+-SACDEC_ERROR CalculateSpaceSynthesisQmf(
+- const HANDLE_FDK_QMF_DOMAIN_OUT hQmfDomainOutCh, const FIXP_DBL *Sr,
+- const FIXP_DBL *Si, const INT stride, INT_PCM *timeSig) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- if (hQmfDomainOutCh == NULL) {
+- err = MPS_INVALID_HANDLE;
+- } else {
+- HANDLE_SPACE_SYNTHESIS_QMF hSpaceSynthesisQmf = &hQmfDomainOutCh->fb;
+-#if (QMF_MAX_SYNTHESIS_BANDS <= 64)
+- C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL,
+- (QMF_MAX_SYNTHESIS_BANDS << 1));
+-#else
+- C_AALLOC_STACK_START(pWorkBuffer, FIXP_DBL, (QMF_MAX_SYNTHESIS_BANDS << 1));
+-#endif
+-
+- qmfSynthesisFilteringSlot(hSpaceSynthesisQmf, Sr, Si, 0, 0, timeSig, stride,
+- pWorkBuffer);
+-
+-#if (QMF_MAX_SYNTHESIS_BANDS <= 64)
+- C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, (QMF_MAX_SYNTHESIS_BANDS << 1));
+-#else
+- C_AALLOC_STACK_END(pWorkBuffer, FIXP_DBL, (QMF_MAX_SYNTHESIS_BANDS << 1));
+-#endif
+- }
+-
+- return err;
+-}
+-
+-SACDEC_ERROR CalculateSpaceAnalysisQmf(
+- HANDLE_SPACE_ANALYSIS_QMF hSpaceAnalysisQmf, const PCM_MPS *timeSig,
+- FIXP_DBL *Sr, FIXP_DBL *Si) {
+- SACDEC_ERROR err = MPS_OK;
+-
+- if (hSpaceAnalysisQmf == NULL) {
+- err = MPS_INVALID_HANDLE;
+- } else {
+- C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL, (64 << 1));
+-
+- qmfAnalysisFilteringSlot(hSpaceAnalysisQmf, Sr, Si, timeSig, 1,
+- pWorkBuffer);
+- C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, (64 << 1));
+- }
+-
+- return err;
+-}
+diff --git a/libSACdec/src/sac_qmf.h b/libSACdec/src/sac_qmf.h
+deleted file mode 100644
+index d1dc837..0000000
+--- a/libSACdec/src/sac_qmf.h
++++ /dev/null
+@@ -1,143 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec QMF processing
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_QMF_H
+-#define SAC_QMF_H
+-
+-#include "common_fix.h"
+-
+-#include "sac_dec_interface.h"
+-
+-#include "FDK_qmf_domain.h"
+-#define HANDLE_SPACE_ANALYSIS_QMF HANDLE_QMF_FILTER_BANK
+-#define HANDLE_SPACE_SYNTHESIS_QMF HANDLE_QMF_FILTER_BANK
+-
+-/**
+- * \brief Convert Qmf input to output audio data.
+- *
+- * \param hSpaceSynthesisQmf A Qmf Synthesis Filterbank handle.
+- * \param Sr Pointer to Qmf input buffer.
+- * \param Si Pointer to Qmf input buffer.
+- * \param stride Stride factor for output data, 1 if none.
+- * \param timeSig (None-)Interleaved audio output data.
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR CalculateSpaceSynthesisQmf(
+- const HANDLE_FDK_QMF_DOMAIN_OUT hQmfDomainOutCh, const FIXP_DBL *Sr,
+- const FIXP_DBL *Si, const INT stride, INT_PCM *timeSig);
+-
+-/**
+- * \brief Convert audio input data to qmf representation.
+- *
+- * \param hSpaceAnalysisQmf A Qmf Analysis Filterbank handle.
+- * \param timeSig (None-)Interleavd audio input data.
+- * \param Sr Pointer to Qmf output buffer.
+- * \param Si Pointer to Qmf output buffer.
+- *
+- * \return Error status.
+- */
+-SACDEC_ERROR CalculateSpaceAnalysisQmf(
+- HANDLE_SPACE_ANALYSIS_QMF hSpaceAnalysisQmf, const PCM_MPS *timeSig,
+- FIXP_DBL *Sr, FIXP_DBL *Si);
+-
+-#endif /* SAC_QMF_H */
+diff --git a/libSACdec/src/sac_reshapeBBEnv.cpp b/libSACdec/src/sac_reshapeBBEnv.cpp
+deleted file mode 100644
+index 87c0ac6..0000000
+--- a/libSACdec/src/sac_reshapeBBEnv.cpp
++++ /dev/null
+@@ -1,680 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec guided envelope shaping
+-
+-*******************************************************************************/
+-
+-#include "sac_reshapeBBEnv.h"
+-
+-#include "sac_dec.h"
+-#include "sac_bitdec.h"
+-#include "sac_calcM1andM2.h"
+-#include "sac_reshapeBBEnv.h"
+-#include "sac_rom.h"
+-
+-#define INP_DRY_WET 0
+-#define INP_DMX 1
+-
+-#define SF_SHAPE 1
+-#define SF_DIV32 6
+-#define SF_FACTOR_SLOT 5
+-
+-#define START_BB_ENV 0 /* 10 */
+-#define END_BB_ENV 9 /* 18 */
+-
+-#define SF_ALPHA1 8
+-#define SF_BETA1 4
+-
+-void initBBEnv(spatialDec *self, int initStatesFlag) {
+- INT ch, k;
+-
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- k = row2channelGES[self->treeConfig][ch];
+- self->row2channelDmxGES[ch] = k;
+- if (k == -1) continue;
+-
+- switch (self->treeConfig) {
+- case TREE_212:
+- self->row2channelDmxGES[ch] = 0;
+- break;
+- default:;
+- }
+- }
+-
+- if (initStatesFlag) {
+- for (k = 0; k < 2 * MAX_OUTPUT_CHANNELS + MAX_INPUT_CHANNELS; k++) {
+- self->reshapeBBEnvState->normNrgPrev__FDK[k] =
+- FL2FXCONST_DBL(0.5f); /* 32768.f*32768.f */
+- self->reshapeBBEnvState->normNrgPrevSF[k] = DFRACT_BITS - 1;
+- self->reshapeBBEnvState->partNrgPrevSF[k] = 0;
+- self->reshapeBBEnvState->partNrgPrev2SF[k] = 0;
+- self->reshapeBBEnvState->frameNrgPrevSF[k] = 0;
+- }
+- }
+-
+- self->reshapeBBEnvState->alpha__FDK =
+- FL2FXCONST_DBL(0.99637845575f); /* FDKexp(-64 / (0.4f * 44100)) */
+- self->reshapeBBEnvState->beta__FDK =
+- FL2FXCONST_DBL(0.96436909488f); /* FDKexp(-64 / (0.04f * 44100)) */
+-}
+-
+-static inline void getSlotNrgHQ(FIXP_DBL *RESTRICT pReal,
+- FIXP_DBL *RESTRICT pImag,
+- FIXP_DBL *RESTRICT slotNrg, INT maxValSF,
+- INT hybBands) {
+- INT qs;
+- FIXP_DBL nrg;
+-
+- /* qs = 12, 13, 14 */
+- slotNrg[0] = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- slotNrg[1] = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- slotNrg[2] = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- /* qs = 15 */
+- slotNrg[3] = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- /* qs = 16, 17 */
+- nrg = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- slotNrg[4] = nrg + ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- /* qs = 18, 19, 20 */
+- nrg = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- nrg += ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- slotNrg[5] = nrg + ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- /* qs = 21, 22 */
+- nrg = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- slotNrg[6] = nrg + ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- /* qs = 23, 24 */
+- if (hybBands > 23) {
+- slotNrg[6] += ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- slotNrg[6] += ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- /* qs = 25, 26, 29, 28, 29 */
+- nrg = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- nrg += ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- nrg += ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- nrg += ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- slotNrg[7] = nrg + ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- /* qs = 30 ... min(41,hybBands-1) */
+- nrg = ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- for (qs = 31; qs < hybBands; qs++) {
+- nrg += ((fPow2Div2((*pReal++) << maxValSF) +
+- fPow2Div2((*pImag++) << maxValSF)) >>
+- (SF_FACTOR_SLOT - 1));
+- }
+- slotNrg[8] = nrg;
+- } else {
+- slotNrg[7] = (FIXP_DBL)0;
+- slotNrg[8] = (FIXP_DBL)0;
+- }
+-}
+-
+-static inline INT getMaxValDmx(FIXP_DBL *RESTRICT pReal,
+- FIXP_DBL *RESTRICT pImag, INT cplxBands,
+- INT hybBands) {
+- INT qs, clz;
+- FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f);
+-
+- for (qs = 12; qs < cplxBands; qs++) {
+- maxVal |= fAbs(pReal[qs]);
+- maxVal |= fAbs(pImag[qs]);
+- }
+- for (; qs < hybBands; qs++) {
+- maxVal |= fAbs(pReal[qs]);
+- }
+-
+- clz = fixMax(0, CntLeadingZeros(maxVal) - 1);
+-
+- return (clz);
+-}
+-
+-static inline INT getMaxValDryWet(FIXP_DBL *RESTRICT pReal,
+- FIXP_DBL *RESTRICT pImag,
+- FIXP_DBL *RESTRICT pHybOutputRealDry,
+- FIXP_DBL *RESTRICT pHybOutputImagDry,
+- FIXP_DBL *RESTRICT pHybOutputRealWet,
+- FIXP_DBL *RESTRICT pHybOutputImagWet,
+- INT cplxBands, INT hybBands) {
+- INT qs, clz;
+- FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f);
+-
+- for (qs = 12; qs < cplxBands; qs++) {
+- pReal[qs] = pHybOutputRealDry[qs] + pHybOutputRealWet[qs];
+- maxVal |= fAbs(pReal[qs]);
+- pImag[qs] = pHybOutputImagDry[qs] + pHybOutputImagWet[qs];
+- maxVal |= fAbs(pImag[qs]);
+- }
+- for (; qs < hybBands; qs++) {
+- pReal[qs] = pHybOutputRealDry[qs] + pHybOutputRealWet[qs];
+- maxVal |= fAbs(pReal[qs]);
+- }
+-
+- clz = fixMax(0, CntLeadingZeros(maxVal) - 1);
+-
+- return (clz);
+-}
+-
+-static inline void slotAmp(FIXP_DBL *RESTRICT slotAmp_dry,
+- FIXP_DBL *RESTRICT slotAmp_wet,
+- FIXP_DBL *RESTRICT pHybOutputRealDry,
+- FIXP_DBL *RESTRICT pHybOutputImagDry,
+- FIXP_DBL *RESTRICT pHybOutputRealWet,
+- FIXP_DBL *RESTRICT pHybOutputImagWet, INT cplxBands,
+- INT hybBands) {
+- INT qs;
+- FIXP_DBL dry, wet;
+-
+- dry = wet = FL2FXCONST_DBL(0.0f);
+- for (qs = 0; qs < cplxBands; qs++) {
+- dry = fAddSaturate(dry, fPow2Div2(pHybOutputRealDry[qs]) +
+- fPow2Div2(pHybOutputImagDry[qs]));
+- wet = fAddSaturate(wet, fPow2Div2(pHybOutputRealWet[qs]) +
+- fPow2Div2(pHybOutputImagWet[qs]));
+- }
+- for (; qs < hybBands; qs++) {
+- dry = fAddSaturate(dry, fPow2Div2(pHybOutputRealDry[qs]));
+- wet = fAddSaturate(wet, fPow2Div2(pHybOutputRealWet[qs]));
+- }
+- *slotAmp_dry = dry;
+- *slotAmp_wet = wet;
+-}
+-
+-#if defined(__aarch64__)
+-__attribute__((noinline))
+-#endif
+-static void
+-shapeBBEnv(FIXP_DBL *pHybOutputRealDry, FIXP_DBL *pHybOutputImagDry,
+- FIXP_DBL dryFac, INT scale, INT cplxBands, INT hybBands) {
+- INT qs;
+-
+- if (scale == 0) {
+- for (qs = 0; qs < cplxBands; qs++) {
+- pHybOutputRealDry[qs] = fMultDiv2(pHybOutputRealDry[qs], dryFac);
+- pHybOutputImagDry[qs] = fMultDiv2(pHybOutputImagDry[qs], dryFac);
+- }
+- for (; qs < hybBands; qs++) {
+- pHybOutputRealDry[qs] = fMultDiv2(pHybOutputRealDry[qs], dryFac);
+- }
+- } else {
+- for (qs = 0; qs < cplxBands; qs++) {
+- pHybOutputRealDry[qs] = fMultDiv2(pHybOutputRealDry[qs], dryFac) << scale;
+- pHybOutputImagDry[qs] = fMultDiv2(pHybOutputImagDry[qs], dryFac) << scale;
+- }
+- for (; qs < hybBands; qs++) {
+- pHybOutputRealDry[qs] = fMultDiv2(pHybOutputRealDry[qs], dryFac) << scale;
+- }
+- }
+-}
+-
+-static void extractBBEnv(spatialDec *self, INT inp, INT start, INT channels,
+- FIXP_DBL *pEnv, const SPATIAL_BS_FRAME *frame) {
+- INT ch, pb, prevChOffs;
+- INT clz, scale, scale_min, envSF;
+- INT scaleCur, scalePrev, commonScale;
+- INT slotNrgSF, partNrgSF, frameNrgSF;
+- INT *pPartNrgPrevSF, *pFrameNrgPrevSF;
+- INT *pNormNrgPrevSF, *pPartNrgPrev2SF;
+-
+- FIXP_DBL maxVal, env, frameNrg, normNrg;
+- FIXP_DBL *pReal, *pImag;
+- FIXP_DBL *partNrg, *partNrgPrev;
+-
+- C_ALLOC_SCRATCH_START(pScratchBuffer, FIXP_DBL,
+- (2 * 42 + MAX_PARAMETER_BANDS));
+- C_ALLOC_SCRATCH_START(resPb, FIXP_DBL, (END_BB_ENV - START_BB_ENV));
+- C_ALLOC_SCRATCH_START(resPbSF, INT, (END_BB_ENV - START_BB_ENV));
+-
+- FIXP_DBL *slotNrg = pScratchBuffer + (2 * 42);
+-
+- RESHAPE_BBENV_STATE *pBBEnvState = self->reshapeBBEnvState;
+-
+- FIXP_DBL alpha = pBBEnvState->alpha__FDK;
+- /*FIXP_DBL alpha1 = (FL2FXCONST_DBL(1.0f) - alpha) << SF_ALPHA1;*/
+- FIXP_DBL alpha1 = ((FIXP_DBL)MAXVAL_DBL - alpha) << SF_ALPHA1;
+- FIXP_DBL beta = pBBEnvState->beta__FDK;
+- /*FIXP_DBL beta1 = (FL2FXCONST_DBL(1.0f) - beta) << SF_BETA1;*/
+- FIXP_DBL beta1 = ((FIXP_DBL)MAXVAL_DBL - beta) << SF_BETA1;
+-
+- INT shapeActiv = 1;
+- INT hybBands = fixMin(42, self->hybridBands);
+- INT staticScale = self->staticDecScale;
+- INT cplxBands;
+- cplxBands = fixMin(42, self->hybridBands);
+-
+- for (ch = start; ch < channels; ch++) {
+- if (inp == INP_DRY_WET) {
+- INT ch2 = row2channelGES[self->treeConfig][ch];
+- if (ch2 == -1) {
+- continue;
+- } else {
+- if (frame->tempShapeEnableChannelGES[ch2]) {
+- shapeActiv = 1;
+- } else {
+- shapeActiv = 0;
+- }
+- }
+- prevChOffs = ch;
+- pReal = pScratchBuffer;
+- pImag = pScratchBuffer + 42;
+- clz = getMaxValDryWet(
+- pReal, pImag, self->hybOutputRealDry__FDK[ch],
+- self->hybOutputImagDry__FDK[ch], self->hybOutputRealWet__FDK[ch],
+- self->hybOutputImagWet__FDK[ch], cplxBands, hybBands);
+- } else {
+- prevChOffs = ch + self->numOutputChannels;
+- pReal = self->hybInputReal__FDK[ch];
+- pImag = self->hybInputImag__FDK[ch];
+- clz = getMaxValDmx(pReal, pImag, cplxBands, hybBands);
+- }
+-
+- partNrg = partNrgPrev = pBBEnvState->partNrgPrev__FDK[prevChOffs];
+- pPartNrgPrevSF = &pBBEnvState->partNrgPrevSF[prevChOffs];
+- pFrameNrgPrevSF = &pBBEnvState->frameNrgPrevSF[prevChOffs];
+- pNormNrgPrevSF = &pBBEnvState->normNrgPrevSF[prevChOffs];
+- pPartNrgPrev2SF = &pBBEnvState->partNrgPrev2SF[prevChOffs];
+-
+- /* calculate slot energy */
+- {
+- getSlotNrgHQ(&pReal[12], &pImag[12], slotNrg, clz,
+- fixMin(42, self->hybridBands)); /* scale slotNrg:
+- 2*(staticScale-clz) +
+- SF_FACTOR_SLOT */
+- }
+-
+- slotNrgSF = 2 * (staticScale - clz) + SF_FACTOR_SLOT;
+- frameNrgSF = 2 * (staticScale - clz) + SF_FACTOR_SLOT;
+-
+- partNrgSF = fixMax(slotNrgSF - SF_ALPHA1 + 1,
+- pPartNrgPrevSF[0] - pPartNrgPrev2SF[0] + 1);
+- scalePrev = fixMax(fixMin(partNrgSF - pPartNrgPrevSF[0], DFRACT_BITS - 1),
+- -(DFRACT_BITS - 1));
+- scaleCur =
+- fixMax(fixMin(partNrgSF - slotNrgSF + SF_ALPHA1, DFRACT_BITS - 1),
+- -(DFRACT_BITS - 1));
+-
+- maxVal = FL2FXCONST_DBL(0.0f);
+- frameNrg = FL2FXCONST_DBL(0.0f);
+- if ((scaleCur < 0) && (scalePrev < 0)) {
+- scaleCur = -scaleCur;
+- scalePrev = -scalePrev;
+- for (pb = START_BB_ENV; pb < END_BB_ENV; pb++) {
+- partNrg[pb] = ((fMultDiv2(alpha1, slotNrg[pb]) << scaleCur) +
+- (fMultDiv2(alpha, partNrgPrev[pb]) << scalePrev))
+- << 1;
+- maxVal |= partNrg[pb];
+- frameNrg += slotNrg[pb] >> 3;
+- }
+- } else if ((scaleCur >= 0) && (scalePrev >= 0)) {
+- for (pb = START_BB_ENV; pb < END_BB_ENV; pb++) {
+- partNrg[pb] = ((fMultDiv2(alpha1, slotNrg[pb]) >> scaleCur) +
+- (fMultDiv2(alpha, partNrgPrev[pb]) >> scalePrev))
+- << 1;
+- maxVal |= partNrg[pb];
+- frameNrg += slotNrg[pb] >> 3;
+- }
+- } else if ((scaleCur < 0) && (scalePrev >= 0)) {
+- scaleCur = -scaleCur;
+- for (pb = START_BB_ENV; pb < END_BB_ENV; pb++) {
+- partNrg[pb] = ((fMultDiv2(alpha1, slotNrg[pb]) << scaleCur) +
+- (fMultDiv2(alpha, partNrgPrev[pb]) >> scalePrev))
+- << 1;
+- maxVal |= partNrg[pb];
+- frameNrg += slotNrg[pb] >> 3;
+- }
+- } else { /* if ( (scaleCur >= 0) && (scalePrev < 0) ) */
+- scalePrev = -scalePrev;
+- for (pb = START_BB_ENV; pb < END_BB_ENV; pb++) {
+- partNrg[pb] = ((fMultDiv2(alpha1, slotNrg[pb]) >> scaleCur) +
+- (fMultDiv2(alpha, partNrgPrev[pb]) << scalePrev))
+- << 1;
+- maxVal |= partNrg[pb];
+- frameNrg += slotNrg[pb] >> 3;
+- }
+- }
+-
+- /* frameNrg /= (END_BB_ENV - START_BB_ENV); 0.88888888888f =
+- * (1/(END_BB_ENV-START_BB_ENV)<<3; shift with 3 is compensated in loop
+- * above */
+- frameNrg = fMult(frameNrg, FL2FXCONST_DBL(0.88888888888f));
+-
+- /* store scalefactor and headroom for part nrg prev */
+- pPartNrgPrevSF[0] = partNrgSF;
+- pPartNrgPrev2SF[0] = fixMax(0, CntLeadingZeros(maxVal) - 1);
+-
+- commonScale = fixMax(frameNrgSF - SF_ALPHA1 + 1, pFrameNrgPrevSF[0] + 1);
+- scalePrev = fixMin(commonScale - pFrameNrgPrevSF[0], DFRACT_BITS - 1);
+- scaleCur = fixMin(commonScale - frameNrgSF + SF_ALPHA1, DFRACT_BITS - 1);
+- frameNrgSF = commonScale;
+-
+- frameNrg = ((fMultDiv2(alpha1, frameNrg) >> scaleCur) +
+- (fMultDiv2(alpha, pBBEnvState->frameNrgPrev__FDK[prevChOffs]) >>
+- scalePrev))
+- << 1;
+-
+- clz = fixMax(0, CntLeadingZeros(frameNrg) - 1);
+- pBBEnvState->frameNrgPrev__FDK[prevChOffs] = frameNrg << clz;
+- pFrameNrgPrevSF[0] = frameNrgSF - clz;
+-
+- env = FL2FXCONST_DBL(0.0f);
+- scale = clz + partNrgSF - frameNrgSF;
+- scale_min = DFRACT_BITS - 1;
+- for (pb = START_BB_ENV; pb < END_BB_ENV; pb++) {
+- if ((partNrg[pb] | slotNrg[pb]) != FL2FXCONST_DBL(0.0f)) {
+- INT s;
+- INT sc = 0;
+- INT sn = fixMax(0, CntLeadingZeros(slotNrg[pb]) - 1);
+- FIXP_DBL inv_sqrt = invSqrtNorm2(partNrg[pb], &sc);
+- FIXP_DBL res = fMult(slotNrg[pb] << sn, fPow2(inv_sqrt));
+-
+- s = fixMax(0, CntLeadingZeros(res) - 1);
+- res = res << s;
+-
+- sc = scale - (2 * sc - sn - s);
+- scale_min = fixMin(scale_min, sc);
+-
+- resPb[pb] = res;
+- resPbSF[pb] = sc;
+- } else {
+- resPb[pb] = (FIXP_DBL)0;
+- resPbSF[pb] = 0;
+- }
+- }
+-
+- scale_min = 4 - scale_min;
+-
+- for (pb = START_BB_ENV; pb < END_BB_ENV; pb++) {
+- INT sc = fixMax(fixMin(resPbSF[pb] + scale_min, DFRACT_BITS - 1),
+- -(DFRACT_BITS - 1));
+-
+- if (sc < 0) {
+- env += resPb[pb] << (-sc);
+- } else {
+- env += resPb[pb] >> (sc);
+- }
+- }
+-
+- env = fMultDiv2(env, pBBEnvState->frameNrgPrev__FDK[prevChOffs]);
+- envSF = slotNrgSF + scale_min + 1;
+-
+- commonScale = fixMax(envSF - SF_BETA1 + 1, pNormNrgPrevSF[0] + 1);
+- scalePrev = fixMin(commonScale - pNormNrgPrevSF[0], DFRACT_BITS - 1);
+- scaleCur = fixMin(commonScale - envSF + SF_BETA1, DFRACT_BITS - 1);
+-
+- normNrg = ((fMultDiv2(beta1, env) >> scaleCur) +
+- (fMultDiv2(beta, pBBEnvState->normNrgPrev__FDK[prevChOffs]) >>
+- scalePrev))
+- << 1;
+-
+- clz = fixMax(0, CntLeadingZeros(normNrg) - 1);
+- pBBEnvState->normNrgPrev__FDK[prevChOffs] = normNrg << clz;
+- pNormNrgPrevSF[0] = commonScale - clz;
+-
+- if (shapeActiv) {
+- if ((env | normNrg) != FL2FXCONST_DBL(0.0f)) {
+- INT sc, se, sn;
+- se = fixMax(0, CntLeadingZeros(env) - 1);
+- sc = commonScale + SF_DIV32 - envSF + se;
+- env = fMult(sqrtFixp((env << se) >> (sc & 0x1)),
+- invSqrtNorm2(normNrg, &sn));
+-
+- sc = fixMin((sc >> 1) - sn, DFRACT_BITS - 1);
+- if (sc < 0) {
+- env <<= (-sc);
+- } else {
+- env >>= (sc);
+- }
+- }
+- /* env is scaled by SF_DIV32/2 bits */
+- }
+- pEnv[ch] = env;
+- }
+-
+- C_ALLOC_SCRATCH_END(resPbSF, INT, (END_BB_ENV - START_BB_ENV));
+- C_ALLOC_SCRATCH_END(resPb, FIXP_DBL, (END_BB_ENV - START_BB_ENV));
+- C_ALLOC_SCRATCH_END(pScratchBuffer, FIXP_DBL, (2 * 42 + MAX_PARAMETER_BANDS));
+-}
+-
+-void SpatialDecReshapeBBEnv(spatialDec *self, const SPATIAL_BS_FRAME *frame,
+- INT ts) {
+- INT ch, scale;
+- INT dryFacSF, slotAmpSF;
+- FIXP_DBL tmp, dryFac, envShape;
+- FIXP_DBL slotAmp_dry, slotAmp_wet, slotAmp_ratio;
+- FIXP_DBL envDry[MAX_OUTPUT_CHANNELS], envDmx[2];
+-
+- INT cplxBands;
+- INT hybBands = self->hybridBands - 6;
+-
+- cplxBands = self->hybridBands - 6;
+-
+- /* extract downmix envelope(s) */
+- switch (self->treeConfig) {
+- default:
+- extractBBEnv(self, INP_DMX, 0, fMin(self->numInputChannels, 2), envDmx,
+- frame);
+- }
+-
+- /* extract dry and wet envelopes */
+- extractBBEnv(self, INP_DRY_WET, 0, self->numOutputChannels, envDry, frame);
+-
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- INT ch2;
+-
+- ch2 = row2channelGES[self->treeConfig][ch];
+-
+- if (ch2 == -1) continue;
+-
+- if (frame->tempShapeEnableChannelGES[ch2]) {
+- INT sc;
+-
+- /* reshape dry and wet signals according to transmitted envelope */
+-
+- /* De-quantize GES data */
+- FDK_ASSERT((frame->bsEnvShapeData[ch2][ts] >= 0) &&
+- (frame->bsEnvShapeData[ch2][ts] <= 4));
+- FDK_ASSERT((self->envQuantMode == 0) || (self->envQuantMode == 1));
+- envShape =
+- FX_CFG2FX_DBL(envShapeDataTable__FDK[frame->bsEnvShapeData[ch2][ts]]
+- [self->envQuantMode]);
+-
+- /* get downmix channel */
+- ch2 = self->row2channelDmxGES[ch];
+-
+- /* multiply ratio with dmx envelope; tmp is scaled by SF_DIV32/2+SF_SHAPE
+- * bits */
+- if (ch2 == 2) {
+- tmp = fMultDiv2(envShape, envDmx[0]) + fMultDiv2(envShape, envDmx[1]);
+- } else {
+- tmp = fMult(envShape, envDmx[ch2]);
+- }
+-
+- /* weighting factors */
+- dryFacSF = slotAmpSF = 0;
+- dryFac = slotAmp_ratio = FL2FXCONST_DBL(0.0f);
+-
+- /* dryFac will be scaled by dryFacSF bits */
+- if (envDry[ch] != FL2FXCONST_DBL(0.0f)) {
+- envDry[ch] = invSqrtNorm2(envDry[ch], &dryFacSF);
+- dryFac = fMultDiv2(tmp, fPow2Div2(envDry[ch])) << 2;
+- dryFacSF = SF_SHAPE + 2 * dryFacSF;
+- }
+-
+- /* calculate slotAmp_dry and slotAmp_wet */
+- slotAmp(&slotAmp_dry, &slotAmp_wet, &self->hybOutputRealDry__FDK[ch][6],
+- &self->hybOutputImagDry__FDK[ch][6],
+- &self->hybOutputRealWet__FDK[ch][6],
+- &self->hybOutputImagWet__FDK[ch][6], cplxBands, hybBands);
+-
+- /* slotAmp_ratio will be scaled by slotAmpSF bits */
+- if (slotAmp_dry != FL2FXCONST_DBL(0.0f)) {
+- sc = fixMax(0, CntLeadingZeros(slotAmp_wet) - 1);
+- sc = sc - (sc & 1);
+-
+- slotAmp_wet = sqrtFixp(slotAmp_wet << sc);
+- slotAmp_dry = invSqrtNorm2(slotAmp_dry, &slotAmpSF);
+-
+- slotAmp_ratio = fMult(slotAmp_wet, slotAmp_dry);
+- slotAmpSF = slotAmpSF - (sc >> 1);
+- }
+-
+- /* calculate common scale factor */
+- scale =
+- fixMax(3, fixMax(dryFacSF, slotAmpSF)); /* scale is at least with 3
+- bits to avoid overflows
+- when calculating dryFac */
+- dryFac = dryFac >> (scale - dryFacSF);
+- slotAmp_ratio = slotAmp_ratio >> (scale - slotAmpSF);
+-
+- /* limit dryFac */
+- dryFac = fixMax(
+- FL2FXCONST_DBL(0.25f) >> (INT)fixMin(2 * scale, DFRACT_BITS - 1),
+- fMult(dryFac, slotAmp_ratio) - (slotAmp_ratio >> scale) +
+- (dryFac >> scale));
+- dryFac = fixMin(
+- FL2FXCONST_DBL(0.50f) >> (INT)fixMin(2 * scale - 3, DFRACT_BITS - 1),
+- dryFac); /* reduce shift bits by 3, because upper
+- limit 4.0 is scaled with 3 bits */
+- scale = 2 * scale + 1;
+-
+- /* improve precision for dryFac */
+- sc = fixMax(0, CntLeadingZeros(dryFac) - 1);
+- dryFac = dryFac << (INT)fixMin(scale, sc);
+- scale = scale - fixMin(scale, sc);
+-
+- /* shaping */
+- shapeBBEnv(&self->hybOutputRealDry__FDK[ch][6],
+- &self->hybOutputImagDry__FDK[ch][6], dryFac, scale, cplxBands,
+- hybBands);
+- }
+- }
+-}
+diff --git a/libSACdec/src/sac_reshapeBBEnv.h b/libSACdec/src/sac_reshapeBBEnv.h
+deleted file mode 100644
+index 1658530..0000000
+--- a/libSACdec/src/sac_reshapeBBEnv.h
++++ /dev/null
+@@ -1,114 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec guided envelope shaping
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_RESHAPEBBENV_H
+-#define SAC_RESHAPEBBENV_H
+-
+-#include "sac_dec_interface.h"
+-
+-#define BB_ENV_SIZE 9 /* END_BB_ENV - START_BB_ENV */
+-
+-void initBBEnv(spatialDec *self, int initStatesFlag);
+-void SpatialDecReshapeBBEnv(spatialDec *self, const SPATIAL_BS_FRAME *frame,
+- int ts);
+-
+-#endif
+diff --git a/libSACdec/src/sac_rom.cpp b/libSACdec/src/sac_rom.cpp
+deleted file mode 100644
+index 4285b65..0000000
+--- a/libSACdec/src/sac_rom.cpp
++++ /dev/null
+@@ -1,709 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec tables
+-
+-*******************************************************************************/
+-
+-#include "sac_rom.h"
+-#include "sac_calcM1andM2.h"
+-
+-#define SCALE_CPC(a) (FL2FXCONST_CFG(a / (float)(1 << SCALE_PARAM_M1)))
+-const FIXP_CFG dequantCPC__FDK[] = {
+- SCALE_CPC(-2.0f), SCALE_CPC(-1.9f), SCALE_CPC(-1.8f), SCALE_CPC(-1.7f),
+- SCALE_CPC(-1.6f), SCALE_CPC(-1.5f), SCALE_CPC(-1.4f), SCALE_CPC(-1.3f),
+- SCALE_CPC(-1.2f), SCALE_CPC(-1.1f), SCALE_CPC(-1.0f), SCALE_CPC(-0.9f),
+- SCALE_CPC(-0.8f), SCALE_CPC(-0.7f), SCALE_CPC(-0.6f), SCALE_CPC(-0.5f),
+- SCALE_CPC(-0.4f), SCALE_CPC(-0.3f), SCALE_CPC(-0.2f), SCALE_CPC(-0.1f),
+- SCALE_CPC(0.0f), SCALE_CPC(0.1f), SCALE_CPC(0.2f), SCALE_CPC(0.3f),
+- SCALE_CPC(0.4f), SCALE_CPC(0.5f), SCALE_CPC(0.6f), SCALE_CPC(0.7f),
+- SCALE_CPC(0.8f), SCALE_CPC(0.9f), SCALE_CPC(1.0f), SCALE_CPC(1.1f),
+- SCALE_CPC(1.2f), SCALE_CPC(1.3f), SCALE_CPC(1.4f), SCALE_CPC(1.5f),
+- SCALE_CPC(1.6f), SCALE_CPC(1.7f), SCALE_CPC(1.8f), SCALE_CPC(1.9f),
+- SCALE_CPC(2.0f), SCALE_CPC(2.1f), SCALE_CPC(2.2f), SCALE_CPC(2.3f),
+- SCALE_CPC(2.4f), SCALE_CPC(2.5f), SCALE_CPC(2.6f), SCALE_CPC(2.7f),
+- SCALE_CPC(2.8f), SCALE_CPC(2.9f), SCALE_CPC(3.0f)};
+-
+-#define SCALE_ICC(a) (FL2FXCONST_CFG(a))
+-const FIXP_CFG dequantICC__FDK[8] = {
+- /*SCALE_ICC(1.00000f)*/ FX_DBL2FX_CFG(MAXVAL_DBL),
+- SCALE_ICC(0.9370f),
+- SCALE_ICC(0.84118f),
+- SCALE_ICC(0.60092f),
+- SCALE_ICC(0.36764f),
+- SCALE_ICC(0.0000f),
+- SCALE_ICC(-0.58900f),
+- SCALE_ICC(-0.9900f)};
+-
+-#define SCALE_CLD2(a) (FL2FXCONST_CFG(a / (float)(1 << 8)))
+-const FIXP_CFG dequantCLD__FDK[31] = {
+- SCALE_CLD2(-150.0f), SCALE_CLD2(-45.0f), SCALE_CLD2(-40.0f),
+- SCALE_CLD2(-35.0f), SCALE_CLD2(-30.0f), SCALE_CLD2(-25.0f),
+- SCALE_CLD2(-22.0f), SCALE_CLD2(-19.0f), SCALE_CLD2(-16.0f),
+- SCALE_CLD2(-13.0f), SCALE_CLD2(-10.0f), SCALE_CLD2(-8.0f),
+- SCALE_CLD2(-6.0f), SCALE_CLD2(-4.0f), SCALE_CLD2(-2.0f),
+- SCALE_CLD2(0.0f), SCALE_CLD2(2.0f), SCALE_CLD2(4.0f),
+- SCALE_CLD2(6.0f), SCALE_CLD2(8.0f), SCALE_CLD2(10.0f),
+- SCALE_CLD2(13.0f), SCALE_CLD2(16.0f), SCALE_CLD2(19.0f),
+- SCALE_CLD2(22.0f), SCALE_CLD2(25.0f), SCALE_CLD2(30.0f),
+- SCALE_CLD2(35.0f), SCALE_CLD2(40.0f), SCALE_CLD2(45.0f),
+- SCALE_CLD2(150.0f)};
+-
+-#define SCALE_IPD(a) (FL2FXCONST_CFG(a / (float)(1 << IPD_SCALE)))
+-const FIXP_CFG dequantIPD__FDK[16] = {
+- /* SCALE_IPD(0.000000000f), SCALE_IPD(0.392699082f),
+- SCALE_IPD(0.785398163f), SCALE_IPD(1.178097245f),
+- SCALE_IPD(1.570796327f), SCALE_IPD(1.963495408f),
+- SCALE_IPD(2.356194490f), SCALE_IPD(2.748893572f),
+- SCALE_IPD(3.141592654f), SCALE_IPD(3.534291735f),
+- SCALE_IPD(3.926990817f), SCALE_IPD(4.319689899f),
+- SCALE_IPD(4.712388980f), SCALE_IPD(5.105088062f),
+- SCALE_IPD(5.497787144f), SCALE_IPD(5.890486225f) */
+- SCALE_IPD(0.00000000000000f), SCALE_IPD(0.392699082f),
+- SCALE_IPD(0.78539816339745f), SCALE_IPD(1.178097245f),
+- SCALE_IPD(1.57079632679490f), SCALE_IPD(1.963495408f),
+- SCALE_IPD(2.35619449019234f), SCALE_IPD(2.748893572f),
+- SCALE_IPD(3.14159265358979f), SCALE_IPD(3.534291735f),
+- SCALE_IPD(3.92699081698724f), SCALE_IPD(4.319689899f),
+- SCALE_IPD(4.71238898038469f), SCALE_IPD(5.105088062f),
+- SCALE_IPD(5.49778714378214f), SCALE_IPD(5.890486225f)};
+-
+-#define SCALE_SPLIT_ANGLE(a) (FL2FXCONST_CFG(a / (float)(1 << IPD_SCALE)))
+-/*
+- Generate table dequantIPD_CLD_ICC_splitAngle__FDK[16][31][8]:
+-
+- #define ABS_THR ( 1e-9f * 32768 * 32768 )
+-
+- float dequantICC[] =
+- {1.0000f,0.9370f,0.84118f,0.60092f,0.36764f,0.0f,-0.5890f,-0.9900f}; float
+- dequantCLD[] =
+- {-150.0,-45.0,-40.0,-35.0,-30.0,-25.0,-22.0,-19.0,-16.0,-13.0,-10.0, -8.0,
+- -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 8.0,
+- 10.0, 13.0, 16.0, 19.0, 22.0, 25.0, 30.0, 35.0, 40.0, 45.0, 150.0 }; float
+- dequantIPD[] =
+- {0.f,0.392699082f,0.785398163f,1.178097245f,1.570796327f,1.963495408f,
+- 2.35619449f,2.748893572f,3.141592654f,3.534291735f,3.926990817f,
+- 4.319689899f,4.71238898f,5.105088062f,5.497787144f,5.890486225f};
+-
+- for (ipdIdx=0; ipdIdx<16; ipdIdx++)
+- for (cldIdx=0; cldIdx<31; cldIdx++)
+- for (iccIdx=0; iccIdx<8; iccIdx++) {
+- ipd = dequantIPD[ipdIdx];
+- cld = dequantCLD[cldIdx];
+- icc = dequantICC[iccIdx];
+- iidLin = (float) pow(10.0f, cld / 20.0f);
+- iidLin2 = iidLin * iidLin;
+- iidLin21 = iidLin2 + 1.0f;
+- sinIpd = (float) sin(ipd);
+- cosIpd = (float) cos(ipd);
+- temp1 = 2.0f * icc * iidLin;
+- temp1c = temp1 * cosIpd;
+- ratio = (iidLin21 + temp1c) / (iidLin21 + temp1) + ABS_THR;
+- w2 = (float) pow(ratio, 0.25f);
+- w1 = 2.0f - w2;
+- dequantIPD_CLD_ICC_splitAngle__FDK[ipdIdx][cldIdx][iccIdx] = (float)
+- atan2(w2 * sinIpd, w1 * iidLin + w2 * cosIpd);
+- }
+-*/
+-
+-#define SCALE_CLD(a) (FL2FXCONST_CFG(a))
+-
+-const FIXP_CFG dequantCLD_c_l[31] = {
+- SCALE_CLD(0.0000000316f),
+- SCALE_CLD(0.0056233243f),
+- SCALE_CLD(0.0099994997f),
+- SCALE_CLD(0.0177799836f),
+- SCALE_CLD(0.0316069759f),
+- SCALE_CLD(0.0561454296f),
+- SCALE_CLD(0.0791834071f),
+- SCALE_CLD(0.1115021780f),
+- SCALE_CLD(0.1565355062f),
+- SCALE_CLD(0.2184644639f),
+- SCALE_CLD(0.3015113473f),
+- SCALE_CLD(0.3698741496f),
+- SCALE_CLD(0.4480624795f),
+- SCALE_CLD(0.5336171389f),
+- SCALE_CLD(0.6219832301f),
+- SCALE_CLD(0.7071067691f),
+- SCALE_CLD(0.7830305696f),
+- SCALE_CLD(0.8457261920f),
+- SCALE_CLD(0.8940021992f),
+- SCALE_CLD(0.9290818572f),
+- SCALE_CLD(0.9534626007f),
+- SCALE_CLD(0.9758449197f),
+- SCALE_CLD(0.9876723289f),
+- SCALE_CLD(0.9937641621f),
+- SCALE_CLD(0.9968600869f),
+- SCALE_CLD(0.9984226227f),
+- SCALE_CLD(0.9995003939f),
+- SCALE_CLD(0.9998419285f),
+- SCALE_CLD(0.9999499917f),
+- SCALE_CLD(0.9999842048f),
+- /*SCALE_CLD(1.0000000000f)*/ FX_DBL2FX_CFG(MAXVAL_DBL)};
+-
+-#define SC_H(a) (FL2FXCONST_CFG(a))
+-#define DATA_TYPE_H FIXP_CFG
+-
+-/* not correlated tables */
+-const DATA_TYPE_H H11_nc[31][8] = {
+- {SC_H(0.0000000316f), SC_H(0.0000000296f), SC_H(0.0000000266f),
+- SC_H(0.0000000190f), SC_H(0.0000000116f), SC_H(0.0000000000f),
+- SC_H(-0.0000000186f), SC_H(-0.0000000313f)},
+- {SC_H(0.0056233243f), SC_H(0.0052728835f), SC_H(0.0047394098f),
+- SC_H(0.0033992692f), SC_H(0.0020946222f), SC_H(0.0000316215f),
+- SC_H(-0.0032913829f), SC_H(-0.0055664564f)},
+- {SC_H(0.0099994997f), SC_H(0.0093815643f), SC_H(0.0084402543f),
+- SC_H(0.0060722125f), SC_H(0.0037622179f), SC_H(0.0000999898f),
+- SC_H(-0.0058238208f), SC_H(-0.0098974844f)},
+- {SC_H(0.0177799836f), SC_H(0.0166974831f), SC_H(0.0150465844f),
+- SC_H(0.0108831404f), SC_H(0.0068073822f), SC_H(0.0003161267f),
+- SC_H(-0.0102626514f), SC_H(-0.0175957214f)},
+- {SC_H(0.0316069759f), SC_H(0.0297324844f), SC_H(0.0268681273f),
+- SC_H(0.0196138974f), SC_H(0.0124691967f), SC_H(0.0009989988f),
+- SC_H(-0.0179452803f), SC_H(-0.0312700421f)},
+- {SC_H(0.0561454296f), SC_H(0.0529650487f), SC_H(0.0480896905f),
+- SC_H(0.0356564634f), SC_H(0.0232860073f), SC_H(0.0031523081f),
+- SC_H(-0.0309029408f), SC_H(-0.0555154830f)},
+- {SC_H(0.0791834071f), SC_H(0.0748842582f), SC_H(0.0682762116f),
+- SC_H(0.0513241664f), SC_H(0.0343080349f), SC_H(0.0062700072f),
+- SC_H(-0.0422340371f), SC_H(-0.0782499388f)},
+- {SC_H(0.1115021780f), SC_H(0.1057924852f), SC_H(0.0969873071f),
+- SC_H(0.0742305145f), SC_H(0.0511277616f), SC_H(0.0124327289f),
+- SC_H(-0.0566596612f), SC_H(-0.1100896299f)},
+- {SC_H(0.1565355062f), SC_H(0.1491366178f), SC_H(0.1376826316f),
+- SC_H(0.1078186408f), SC_H(0.0770794004f), SC_H(0.0245033558f),
+- SC_H(-0.0735980421f), SC_H(-0.1543303132f)},
+- {SC_H(0.2184644639f), SC_H(0.2091979682f), SC_H(0.1947948188f),
+- SC_H(0.1568822265f), SC_H(0.1172478944f), SC_H(0.0477267131f),
+- SC_H(-0.0899507254f), SC_H(-0.2148526460f)},
+- {SC_H(0.3015113473f), SC_H(0.2904391289f), SC_H(0.2731673419f),
+- SC_H(0.2273024023f), SC_H(0.1786239147f), SC_H(0.0909090787f),
+- SC_H(-0.0964255333f), SC_H(-0.2951124907f)},
+- {SC_H(0.3698741496f), SC_H(0.3578284085f), SC_H(0.3390066922f),
+- SC_H(0.2888108492f), SC_H(0.2351117432f), SC_H(0.1368068755f),
+- SC_H(-0.0850296095f), SC_H(-0.3597966135f)},
+- {SC_H(0.4480624795f), SC_H(0.4354025424f), SC_H(0.4156077504f),
+- SC_H(0.3627120256f), SC_H(0.3058823943f), SC_H(0.2007599771f),
+- SC_H(-0.0484020934f), SC_H(-0.4304940701f)},
+- {SC_H(0.5336171389f), SC_H(0.5208471417f), SC_H(0.5008935928f),
+- SC_H(0.4476420581f), SC_H(0.3905044496f), SC_H(0.2847472429f),
+- SC_H(0.0276676007f), SC_H(-0.4966579080f)},
+- {SC_H(0.6219832301f), SC_H(0.6096963882f), SC_H(0.5905415416f),
+- SC_H(0.5396950245f), SC_H(0.4856070578f), SC_H(0.3868631124f),
+- SC_H(0.1531652957f), SC_H(-0.5045361519f)},
+- {SC_H(0.7071067691f), SC_H(0.6958807111f), SC_H(0.6784504056f),
+- SC_H(0.6326373219f), SC_H(0.5847306848f), SC_H(0.4999999702f),
+- SC_H(0.3205464482f), SC_H(0.0500000045f)},
+- {SC_H(0.7830305696f), SC_H(0.7733067870f), SC_H(0.7582961321f),
+- SC_H(0.7194055915f), SC_H(0.6797705293f), SC_H(0.6131368876f),
+- SC_H(0.4997332692f), SC_H(0.6934193969f)},
+- {SC_H(0.8457261920f), SC_H(0.8377274871f), SC_H(0.8254694939f),
+- SC_H(0.7942851782f), SC_H(0.7635439038f), SC_H(0.7152527571f),
+- SC_H(0.6567122936f), SC_H(0.8229061961f)},
+- {SC_H(0.8940021992f), SC_H(0.8877248168f), SC_H(0.8781855106f),
+- SC_H(0.8544237614f), SC_H(0.8318918347f), SC_H(0.7992399335f),
+- SC_H(0.7751275301f), SC_H(0.8853276968f)},
+- {SC_H(0.9290818572f), SC_H(0.9243524075f), SC_H(0.9172304869f),
+- SC_H(0.8998877406f), SC_H(0.8841174841f), SC_H(0.8631930947f),
+- SC_H(0.8565139771f), SC_H(0.9251161218f)},
+- {SC_H(0.9534626007f), SC_H(0.9500193000f), SC_H(0.9448821545f),
+- SC_H(0.9326565266f), SC_H(0.9220023751f), SC_H(0.9090909362f),
+- SC_H(0.9096591473f), SC_H(0.9514584541f)},
+- {SC_H(0.9758449197f), SC_H(0.9738122821f), SC_H(0.9708200693f),
+- SC_H(0.9639287591f), SC_H(0.9582763910f), SC_H(0.9522733092f),
+- SC_H(0.9553207159f), SC_H(0.9750427008f)},
+- {SC_H(0.9876723289f), SC_H(0.9865267277f), SC_H(0.9848603010f),
+- SC_H(0.9811310172f), SC_H(0.9782302976f), SC_H(0.9754966497f),
+- SC_H(0.9779621363f), SC_H(0.9873252511f)},
+- {SC_H(0.9937641621f), SC_H(0.9931397438f), SC_H(0.9922404289f),
+- SC_H(0.9902750254f), SC_H(0.9888116717f), SC_H(0.9875672460f),
+- SC_H(0.9891131520f), SC_H(0.9936066866f)},
+- {SC_H(0.9968600869f), SC_H(0.9965277910f), SC_H(0.9960530400f),
+- SC_H(0.9950347543f), SC_H(0.9943022728f), SC_H(0.9937300086f),
+- SC_H(0.9946073294f), SC_H(0.9967863560f)},
+- {SC_H(0.9984226227f), SC_H(0.9982488155f), SC_H(0.9980020523f),
+- SC_H(0.9974802136f), SC_H(0.9971146584f), SC_H(0.9968476892f),
+- SC_H(0.9973216057f), SC_H(0.9983873963f)},
+- {SC_H(0.9995003939f), SC_H(0.9994428754f), SC_H(0.9993617535f),
+- SC_H(0.9991930723f), SC_H(0.9990783334f), SC_H(0.9990010262f),
+- SC_H(0.9991616607f), SC_H(0.9994897842f)},
+- {SC_H(0.9998419285f), SC_H(0.9998232722f), SC_H(0.9997970462f),
+- SC_H(0.9997430444f), SC_H(0.9997069836f), SC_H(0.9996838570f),
+- SC_H(0.9997364879f), SC_H(0.9998386502f)},
+- {SC_H(0.9999499917f), SC_H(0.9999440312f), SC_H(0.9999356270f),
+- SC_H(0.9999184012f), SC_H(0.9999070764f), SC_H(0.9998999834f),
+- SC_H(0.9999169707f), SC_H(0.9999489784f)},
+- {SC_H(0.9999842048f), SC_H(0.9999822974f), SC_H(0.9999796152f),
+- SC_H(0.9999741912f), SC_H(0.9999706149f), SC_H(0.9999684095f),
+- SC_H(0.9999738336f), SC_H(0.9999839067f)},
+- /* { SC_H( 1.0000000000f), SC_H( 1.0000000000f), SC_H( 1.0000000000f),
+- SC_H( 1.0000000000f), SC_H( 1.0000000000f), SC_H( 1.0000000000f),
+- SC_H( 1.0000000000f), SC_H( 1.0000000000f)} */
+- {FX_DBL2FX_CFG(MAXVAL_DBL), FX_DBL2FX_CFG(MAXVAL_DBL),
+- FX_DBL2FX_CFG(MAXVAL_DBL), FX_DBL2FX_CFG(MAXVAL_DBL),
+- FX_DBL2FX_CFG(MAXVAL_DBL), FX_DBL2FX_CFG(MAXVAL_DBL),
+- FX_DBL2FX_CFG(MAXVAL_DBL), FX_DBL2FX_CFG(MAXVAL_DBL)}};
+-const DATA_TYPE_H H12_nc[31][8] = {
+- {SC_H(0.0000000000f), SC_H(0.0000000110f), SC_H(0.0000000171f),
+- SC_H(0.0000000253f), SC_H(0.0000000294f), SC_H(0.0000000316f),
+- SC_H(0.0000000256f), SC_H(0.0000000045f)},
+- {SC_H(0.0000000000f), SC_H(0.0019540924f), SC_H(0.0030265113f),
+- SC_H(0.0044795922f), SC_H(0.0052186525f), SC_H(0.0056232354f),
+- SC_H(0.0045594489f), SC_H(0.0007977085f)},
+- {SC_H(0.0000000000f), SC_H(0.0034606720f), SC_H(0.0053620986f),
+- SC_H(0.0079446984f), SC_H(0.0092647560f), SC_H(0.0099989995f),
+- SC_H(0.0081285369f), SC_H(0.0014247064f)},
+- {SC_H(0.0000000000f), SC_H(0.0061091618f), SC_H(0.0094724922f),
+- SC_H(0.0140600521f), SC_H(0.0164252054f), SC_H(0.0177771728f),
+- SC_H(0.0145191532f), SC_H(0.0025531140f)},
+- {SC_H(0.0000000000f), SC_H(0.0107228858f), SC_H(0.0166464616f),
+- SC_H(0.0247849934f), SC_H(0.0290434174f), SC_H(0.0315911844f),
+- SC_H(0.0260186065f), SC_H(0.0046027615f)},
+- {SC_H(0.0000000000f), SC_H(0.0186282862f), SC_H(0.0289774220f),
+- SC_H(0.0433696397f), SC_H(0.0510888547f), SC_H(0.0560568646f),
+- SC_H(0.0468755551f), SC_H(0.0083869267f)},
+- {SC_H(0.0000000000f), SC_H(0.0257363543f), SC_H(0.0401044972f),
+- SC_H(0.0602979437f), SC_H(0.0713650510f), SC_H(0.0789347738f),
+- SC_H(0.0669798329f), SC_H(0.0121226767f)},
+- {SC_H(0.0000000000f), SC_H(0.0352233723f), SC_H(0.0550108925f),
+- SC_H(0.0832019597f), SC_H(0.0990892947f), SC_H(0.1108068749f),
+- SC_H(0.0960334241f), SC_H(0.0176920593f)},
+- {SC_H(0.0000000000f), SC_H(0.0475566536f), SC_H(0.0744772255f),
+- SC_H(0.1134835035f), SC_H(0.1362429112f), SC_H(0.1546057910f),
+- SC_H(0.1381545961f), SC_H(0.0261824392f)},
+- {SC_H(0.0000000000f), SC_H(0.0629518181f), SC_H(0.0989024863f),
+- SC_H(0.1520351619f), SC_H(0.1843357086f), SC_H(0.2131874412f),
+- SC_H(0.1990868896f), SC_H(0.0395608991f)},
+- {SC_H(0.0000000000f), SC_H(0.0809580907f), SC_H(0.1276271492f),
+- SC_H(0.1980977356f), SC_H(0.2429044843f), SC_H(0.2874797881f),
+- SC_H(0.2856767476f), SC_H(0.0617875643f)},
+- {SC_H(0.0000000000f), SC_H(0.0936254337f), SC_H(0.1479234397f),
+- SC_H(0.2310739607f), SC_H(0.2855334580f), SC_H(0.3436433673f),
+- SC_H(0.3599678576f), SC_H(0.0857512727f)},
+- {SC_H(0.0000000000f), SC_H(0.1057573780f), SC_H(0.1674221754f),
+- SC_H(0.2630588412f), SC_H(0.3274079263f), SC_H(0.4005688727f),
+- SC_H(0.4454404712f), SC_H(0.1242370531f)},
+- {SC_H(0.0000000000f), SC_H(0.1160409302f), SC_H(0.1839915067f),
+- SC_H(0.2904545665f), SC_H(0.3636667728f), SC_H(0.4512939751f),
+- SC_H(0.5328993797f), SC_H(0.1951362640f)},
+- {SC_H(0.0000000000f), SC_H(0.1230182052f), SC_H(0.1952532977f),
+- SC_H(0.3091802597f), SC_H(0.3886501491f), SC_H(0.4870318770f),
+- SC_H(0.6028295755f), SC_H(0.3637395203f)},
+- {SC_H(0.0000000000f), SC_H(0.1254990250f), SC_H(0.1992611140f),
+- SC_H(0.3158638775f), SC_H(0.3976053298f), SC_H(0.5000000000f),
+- SC_H(0.6302776933f), SC_H(0.7053368092f)},
+- {SC_H(0.0000000000f), SC_H(0.1230182052f), SC_H(0.1952533126f),
+- SC_H(0.3091802597f), SC_H(0.3886501491f), SC_H(0.4870319068f),
+- SC_H(0.6028295755f), SC_H(0.3637394905f)},
+- {SC_H(0.0000000000f), SC_H(0.1160409302f), SC_H(0.1839915216f),
+- SC_H(0.2904545665f), SC_H(0.3636668026f), SC_H(0.4512939751f),
+- SC_H(0.5328993797f), SC_H(0.1951362044f)},
+- {SC_H(0.0000000000f), SC_H(0.1057573855f), SC_H(0.1674221754f),
+- SC_H(0.2630588710f), SC_H(0.3274079263f), SC_H(0.4005688727f),
+- SC_H(0.4454405010f), SC_H(0.1242370382f)},
+- {SC_H(0.0000000000f), SC_H(0.0936254337f), SC_H(0.1479234397f),
+- SC_H(0.2310739607f), SC_H(0.2855334580f), SC_H(0.3436433673f),
+- SC_H(0.3599678576f), SC_H(0.0857512653f)},
+- {SC_H(0.0000000000f), SC_H(0.0809580907f), SC_H(0.1276271492f),
+- SC_H(0.1980977207f), SC_H(0.2429044843f), SC_H(0.2874797881f),
+- SC_H(0.2856767476f), SC_H(0.0617875606f)},
+- {SC_H(0.0000000000f), SC_H(0.0629518107f), SC_H(0.0989024863f),
+- SC_H(0.1520351619f), SC_H(0.1843357235f), SC_H(0.2131874412f),
+- SC_H(0.1990868896f), SC_H(0.0395609401f)},
+- {SC_H(0.0000000000f), SC_H(0.0475566462f), SC_H(0.0744772255f),
+- SC_H(0.1134835184f), SC_H(0.1362429112f), SC_H(0.1546057761f),
+- SC_H(0.1381545961f), SC_H(0.0261824802f)},
+- {SC_H(0.0000000000f), SC_H(0.0352233797f), SC_H(0.0550108962f),
+- SC_H(0.0832019448f), SC_H(0.0990892798f), SC_H(0.1108068526f),
+- SC_H(0.0960334465f), SC_H(0.0176920686f)},
+- {SC_H(0.0000000000f), SC_H(0.0257363524f), SC_H(0.0401044935f),
+- SC_H(0.0602979474f), SC_H(0.0713650808f), SC_H(0.0789347589f),
+- SC_H(0.0669797957f), SC_H(0.0121226516f)},
+- {SC_H(0.0000000000f), SC_H(0.0186282881f), SC_H(0.0289774258f),
+- SC_H(0.0433696248f), SC_H(0.0510888547f), SC_H(0.0560568906f),
+- SC_H(0.0468755886f), SC_H(0.0083869714f)},
+- {SC_H(0.0000000000f), SC_H(0.0107228830f), SC_H(0.0166464727f),
+- SC_H(0.0247849822f), SC_H(0.0290434249f), SC_H(0.0315911621f),
+- SC_H(0.0260186475f), SC_H(0.0046027377f)},
+- {SC_H(0.0000000000f), SC_H(0.0061091576f), SC_H(0.0094724894f),
+- SC_H(0.0140600465f), SC_H(0.0164251942f), SC_H(0.0177771524f),
+- SC_H(0.0145191504f), SC_H(0.0025530567f)},
+- {SC_H(0.0000000000f), SC_H(0.0034606743f), SC_H(0.0053620976f),
+- SC_H(0.0079446994f), SC_H(0.0092647672f), SC_H(0.0099990256f),
+- SC_H(0.0081285043f), SC_H(0.0014247177f)},
+- {SC_H(0.0000000000f), SC_H(0.0019540912f), SC_H(0.0030265225f),
+- SC_H(0.0044795908f), SC_H(0.0052186381f), SC_H(0.0056232223f),
+- SC_H(0.0045594289f), SC_H(0.0007977359f)},
+- {SC_H(0.0000000000f), SC_H(0.0000000149f), SC_H(0.0000000298f),
+- SC_H(0.0000000298f), SC_H(0.0000000000f), SC_H(0.0000000596f),
+- SC_H(0.0000000000f), SC_H(0.0000000000f)}};
+-
+-/*
+- for (i=0; i<31; i++) {
+- cld = dequantCLD[i];
+- val = (float)(FDKexp(cld/dbe)/(1+FDKexp(cld/dbe)));
+- val = (float)(dbe*FDKlog(val));
+- }
+-*/
+-#define SCALE_CLD_C1C2(a) (FL2FXCONST_DBL(a / (float)(1 << SF_CLD_C1C2)))
+-const FIXP_DBL dequantCLD_c1[31] = {SCALE_CLD_C1C2(-1.5000000000000000e+002f),
+- SCALE_CLD_C1C2(-4.5000137329101563e+001f),
+- SCALE_CLD_C1C2(-4.0000434875488281e+001f),
+- SCALE_CLD_C1C2(-3.5001373291015625e+001f),
+- SCALE_CLD_C1C2(-3.0004341125488281e+001f),
+- SCALE_CLD_C1C2(-2.5013711929321289e+001f),
+- SCALE_CLD_C1C2(-2.2027315139770508e+001f),
+- SCALE_CLD_C1C2(-1.9054332733154297e+001f),
+- SCALE_CLD_C1C2(-1.6107742309570313e+001f),
+- SCALE_CLD_C1C2(-1.3212384223937988e+001f),
+- SCALE_CLD_C1C2(-1.0413927078247070e+001f),
+- SCALE_CLD_C1C2(-8.6389207839965820e+000f),
+- SCALE_CLD_C1C2(-6.9732279777526855e+000f),
+- SCALE_CLD_C1C2(-5.4554042816162109e+000f),
+- SCALE_CLD_C1C2(-4.1244258880615234e+000f),
+- SCALE_CLD_C1C2(-3.0102999210357666e+000f),
+- SCALE_CLD_C1C2(-2.1244258880615234e+000f),
+- SCALE_CLD_C1C2(-1.4554045200347900e+000f),
+- SCALE_CLD_C1C2(-9.7322785854339600e-001f),
+- SCALE_CLD_C1C2(-6.3892036676406860e-001f),
+- SCALE_CLD_C1C2(-4.1392669081687927e-001f),
+- SCALE_CLD_C1C2(-2.1238386631011963e-001f),
+- SCALE_CLD_C1C2(-1.0774217545986176e-001f),
+- SCALE_CLD_C1C2(-5.4333221167325974e-002f),
+- SCALE_CLD_C1C2(-2.7315950021147728e-002f),
+- SCALE_CLD_C1C2(-1.3711934909224510e-002f),
+- SCALE_CLD_C1C2(-4.3406565673649311e-003f),
+- SCALE_CLD_C1C2(-1.3732088264077902e-003f),
+- SCALE_CLD_C1C2(-4.3438826105557382e-004f),
+- SCALE_CLD_C1C2(-1.3745666365139186e-004f),
+- SCALE_CLD_C1C2(0.0000000000000000e+000f)};
+-
+-/* sac_stp */
+-/* none scaled */
+-const FIXP_CFG BP__FDK[] = {FL2FXCONST_CFG(0.73919999599457),
+- FL2FXCONST_CFG(0.97909998893738),
+- FL2FXCONST_CFG(0.99930000305176)};
+-
+-/* scaled with 26 bits */
+-const FIXP_CFG BP_GF__FDK[] = {
+- FL2FXCONST_CFG(0.00000000643330), FL2FXCONST_CFG(0.00004396850232),
+- FL2FXCONST_CFG(0.00087456948552), FL2FXCONST_CFG(0.00474648220243),
+- FL2FXCONST_CFG(0.01717987244800), FL2FXCONST_CFG(0.04906742491073),
+- FL2FXCONST_CFG(0.10569518656729), FL2FXCONST_CFG(0.21165767592653),
+- FL2FXCONST_CFG(0.36036762478024), FL2FXCONST_CFG(0.59894182766948),
+- FL2FXCONST_CFG(0.81641678929129), FL2FXCONST_CFG(0.97418481133397),
+- FL2FXCONST_CFG(0.99575411610845), FL2FXCONST_CFG(0.88842666281361),
+- FL2FXCONST_CFG(0.79222317063736), FL2FXCONST_CFG(0.70828604318604),
+- FL2FXCONST_CFG(0.66395054816338), FL2FXCONST_CFG(0.64633739516952),
+- FL2FXCONST_CFG(0.66098278185255)};
+-
+-/* sac_bitdec */
+-const INT samplingFreqTable[16] = {96000, 88200, 64000, 48000, 44100, 32000,
+- 24000, 22050, 16000, 12000, 11025, 8000,
+- 7350, 0, 0, 0};
+-
+-const UCHAR freqResTable[] = {0, 28, 20, 14, 10, 7, 5, 4};
+-
+-const UCHAR freqResTable_LD[] = {0, 23, 15, 12, 9, 7, 5, 4};
+-
+-const UCHAR tempShapeChanTable[][8] = {{5, 5, 4, 6, 6, 4, 4, 2},
+- {5, 5, 5, 7, 7, 4, 4, 2}};
+-
+-const TREEPROPERTIES treePropertyTable[] = {
+- {1, 6, 5, 0, {0, 0, 0, 0, 1}}, {1, 6, 5, 0, {0, 0, 1, 0, 0}},
+- {2, 6, 3, 1, {1, 0, 0, 0, 0}}, {2, 8, 5, 1, {1, 0, 0, 0, 0}},
+- {2, 8, 5, 1, {1, 0, 0, 0, 0}}, {6, 8, 2, 0, {0, 0, 0, 0, 0}},
+- {6, 8, 2, 0, {0, 0, 0, 0, 0}}, {1, 2, 1, 0, {0, 0, 0, 0, 0}}};
+-
+-const SCHAR kernels_4_to_71[MAX_HYBRID_BANDS] = {
+- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 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,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
+-
+-const SCHAR kernels_5_to_71[MAX_HYBRID_BANDS] = {
+- 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 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,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
+-
+-const SCHAR kernels_7_to_71[MAX_HYBRID_BANDS] = {
+- 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5,
+- 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
+-
+-const SCHAR kernels_10_to_71[MAX_HYBRID_BANDS] = {
+- 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8, 8,
+- 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
+-
+-const SCHAR kernels_14_to_71[MAX_HYBRID_BANDS] = {
+- 0, 0, 0, 0, 1, 1, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8,
+- 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12,
+- 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13};
+-
+-const SCHAR kernels_20_to_71[MAX_HYBRID_BANDS] = {
+- 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+- 14, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18,
+- 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19};
+-
+-const SCHAR kernels_28_to_71[MAX_HYBRID_BANDS] = {
+- 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+- 15, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 22, 22, 23,
+- 23, 23, 23, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 26, 26, 26,
+- 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+- 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+- 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+- 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+- 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27};
+-
+-const SCHAR kernels_4_to_64[MAX_HYBRID_BANDS] = {
+- 0, 0, 1, 1, 1, 1, 2, 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, 3, 3, 3, 3, 3,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
+-
+-const SCHAR kernels_5_to_64[MAX_HYBRID_BANDS] = {
+- 0, 1, 1, 2, 2, 2, 2, 2, 2, 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, 4, 4, 4, 4, 4,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
+-
+-const SCHAR kernels_7_to_64[MAX_HYBRID_BANDS] = {
+- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
+- 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
+-
+-const SCHAR kernels_9_to_64[MAX_HYBRID_BANDS] = {
+- 0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
+- 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8};
+-
+-const SCHAR kernels_12_to_64[MAX_HYBRID_BANDS] = {
+- 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9,
+- 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11,
+- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11};
+-
+-const SCHAR kernels_15_to_64[MAX_HYBRID_BANDS] = {
+- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12,
+- 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14,
+- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14};
+-
+-const SCHAR kernels_23_to_64[MAX_HYBRID_BANDS] = {
+- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 13, 13, 14, 14, 15,
+- 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 19, 20, 20, 20,
+- 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22};
+-
+-const UCHAR mapping_15_to_23[MAX_PARAMETER_BANDS_LD] = {
+- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10,
+- 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14};
+-
+-const UCHAR mapping_12_to_23[MAX_PARAMETER_BANDS_LD] = {
+- 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11};
+-
+-const UCHAR mapping_9_to_23[MAX_PARAMETER_BANDS_LD] = {
+- 0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8};
+-
+-const UCHAR mapping_7_to_23[MAX_PARAMETER_BANDS_LD] = {
+- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6};
+-
+-const UCHAR mapping_5_to_23[MAX_PARAMETER_BANDS_LD] = {
+- 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4};
+-
+-const UCHAR mapping_4_to_23[MAX_PARAMETER_BANDS_LD] = {
+- 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3};
+-
+-const FIXP_CFG clipGainTable__FDK[] = {
+- /*CLIP_PROTECT_GAIN_0(1.000000f)*/ FX_DBL2FX_CFG(MAXVAL_DBL),
+- CLIP_PROTECT_GAIN_1(1.189207f),
+- CLIP_PROTECT_GAIN_1(1.414213f),
+- CLIP_PROTECT_GAIN_1(1.681792f),
+- /*CLIP_PROTECT_GAIN_1(2.000000f)*/ FX_DBL2FX_CFG(MAXVAL_DBL),
+- CLIP_PROTECT_GAIN_2(2.378414f),
+- CLIP_PROTECT_GAIN_2(2.828427f),
+- /*CLIP_PROTECT_GAIN_2(4.000000f)*/ FX_DBL2FX_CFG(MAXVAL_DBL)};
+-
+-const UCHAR clipGainSFTable__FDK[] = {0, 1, 1, 1, 1, 2, 2, 2};
+-
+-const UCHAR pbStrideTable[] = {1, 2, 5, 28};
+-
+-const int smgTimeTable[] = {64, 128, 256, 512};
+-
+-/* table is scaled by factor 0.5 */
+-const FIXP_CFG envShapeDataTable__FDK[5][2] = {
+- {FL2FXCONST_CFG(0.25000000000000f), FL2FXCONST_CFG(0.25000000000000f)},
+- {FL2FXCONST_CFG(0.35355339059327f), FL2FXCONST_CFG(0.31498026247372f)},
+- {FL2FXCONST_CFG(0.50000000000000f), FL2FXCONST_CFG(0.39685026299205f)},
+- {FL2FXCONST_CFG(0.70710678118655f), FL2FXCONST_CFG(0.50000000000000f)},
+- {/*FL2FXCONST_CFG( 1.00000000000000f)*/ FX_DBL2FX_CFG(MAXVAL_DBL),
+- FL2FXCONST_CFG(0.62996052494744f)}};
+-
+-/* sac_calcM1andM2 */
+-const SCHAR row2channelSTP[][MAX_M2_INPUT] = {{0, 1}, {0, 3}, {0, 2}, {0, 4},
+- {0, 4}, {0, 2}, {-1, 2}, {0, 1}};
+-
+-const SCHAR row2channelGES[][MAX_M2_INPUT] = {{0, 1}, {0, 3}, {0, 3}, {0, 5},
+- {0, 5}, {0, 2}, {-1, 2}, {0, 1}};
+-
+-const SCHAR row2residual[][MAX_M2_INPUT] = {{-1, 0}, {-1, 0}, {-1, -1},
+- {-1, -1}, {-1, -1}, {-1, -1},
+- {-1, -1}, {-1, 0}};
+-
+-/*******************************************************************************
+- Functionname: sac_getCLDValues
+- *******************************************************************************
+-
+- Description: Get CLD values from table index.
+-
+- Arguments:
+- index: Table index
+- *cu, *cl : Pointer to locations where resulting values will be written to.
+-
+- Return: nothing
+-
+-*******************************************************************************/
+-void SpatialDequantGetCLDValues(int index, FIXP_DBL* cu, FIXP_DBL* cl) {
+- *cu = FX_CFG2FX_DBL(dequantCLD_c_l[index]);
+- *cl = FX_CFG2FX_DBL(dequantCLD_c_l[31 - 1 - index]);
+-}
+-
+-void SpatialDequantGetCLD2Values(int idx, FIXP_DBL* x) {
+- *x = FX_CFG2FX_DBL(dequantCLD__FDK[idx]);
+-}
+diff --git a/libSACdec/src/sac_rom.h b/libSACdec/src/sac_rom.h
+deleted file mode 100644
+index d366fb6..0000000
+--- a/libSACdec/src/sac_rom.h
++++ /dev/null
+@@ -1,230 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec tables
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_ROM_H
+-#define SAC_ROM_H
+-
+-#include "FDK_archdef.h"
+-#include "sac_dec_interface.h"
+-
+-#include "huff_nodes.h"
+-#include "sac_bitdec.h"
+-#include "machine_type.h"
+-
+-/* Global ROM table data type: */
+-#ifndef ARCH_PREFER_MULT_32x32
+-#define FIXP_CFG FIXP_SGL
+-#define FX_CFG2FX_DBL FX_SGL2FX_DBL
+-#define FX_CFG2FX_SGL
+-#define CFG(a) (FX_DBL2FXCONST_SGL(a))
+-#define FL2FXCONST_CFG FL2FXCONST_SGL
+-#define FX_DBL2FX_CFG(x) FX_DBL2FX_SGL((FIXP_DBL)(x))
+-#else
+-#define FIXP_CFG FIXP_DBL
+-#define FX_CFG2FX_DBL
+-#define FX_CFG2FX_SGL FX_DBL2FX_SGL
+-#define CFG(a) FIXP_DBL(a)
+-#define FL2FXCONST_CFG FL2FXCONST_DBL
+-#define FX_DBL2FX_CFG(x) ((FIXP_DBL)(x))
+-#endif
+-
+-/* others */
+-#define SCALE_INV_ICC (2)
+-#define G_dd_SCALE (2)
+-
+-#define QCC_SCALE 1
+-#define M1M2_DATA FIXP_DBL
+-#ifndef ARCH_PREFER_MULT_32x32
+-#define M1M2_CDATA FIXP_SGL
+-#define M1M2_CDATA2FX_DBL(a) FX_SGL2FX_DBL(a)
+-#define FX_DBL2M1M2_CDATA(a) FX_DBL2FX_SGL(a)
+-#else
+-#define M1M2_CDATA FIXP_DBL
+-#define M1M2_CDATA2FX_DBL(a) (a)
+-#define FX_DBL2M1M2_CDATA(a) (a)
+-#endif
+-
+-#define CLIP_PROTECT_GAIN_0(x) FL2FXCONST_CFG(((x) / (float)(1 << 0)))
+-#define CLIP_PROTECT_GAIN_1(x) FL2FXCONST_CFG(((x) / (float)(1 << 1)))
+-#define CLIP_PROTECT_GAIN_2(x) FL2FXCONST_CFG(((x) / (float)(1 << 2)))
+-
+-#define SF_CLD_C1C2 (8)
+-
+-extern const FIXP_CFG dequantCPC__FDK[];
+-extern const FIXP_CFG dequantICC__FDK[8];
+-extern const FIXP_CFG dequantCLD__FDK[31];
+-
+-#define IPD_SCALE (5)
+-#define PI__IPD (FL2FXCONST_DBL(3.1415926535897932f / (float)(1 << IPD_SCALE)))
+-/* Define for PI*2 for better precision in SpatialDecApplyPhase() */
+-#define PIx2__IPD \
+- (FL2FXCONST_DBL(3.1415926535897932f / (float)(1 << (IPD_SCALE - 1))))
+-
+-extern const FIXP_CFG dequantIPD__FDK[16];
+-
+-extern const FIXP_CFG H11_nc[31][8];
+-extern const FIXP_CFG H12_nc[31][8];
+-
+-extern const FIXP_DBL dequantCLD_c1[31];
+-
+-extern const FIXP_CFG BP__FDK[];
+-extern const FIXP_CFG BP_GF__FDK[];
+-extern const SCHAR row2channelSTP[][MAX_M2_INPUT];
+-
+-/* sac_bitdec */
+-extern const INT samplingFreqTable[16];
+-extern const UCHAR freqResTable[];
+-extern const UCHAR freqResTable_LD[];
+-extern const UCHAR tempShapeChanTable[2][8];
+-extern const TREEPROPERTIES treePropertyTable[];
+-
+-extern const SCHAR kernels_4_to_71[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_5_to_71[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_7_to_71[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_10_to_71[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_14_to_71[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_20_to_71[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_28_to_71[MAX_HYBRID_BANDS];
+-
+-extern const UCHAR mapping_4_to_28[MAX_PARAMETER_BANDS];
+-extern const UCHAR mapping_5_to_28[MAX_PARAMETER_BANDS];
+-extern const UCHAR mapping_7_to_28[MAX_PARAMETER_BANDS];
+-extern const UCHAR mapping_10_to_28[MAX_PARAMETER_BANDS];
+-extern const UCHAR mapping_14_to_28[MAX_PARAMETER_BANDS];
+-extern const UCHAR mapping_20_to_28[MAX_PARAMETER_BANDS];
+-extern const SCHAR kernels_4_to_64[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_5_to_64[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_7_to_64[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_9_to_64[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_12_to_64[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_15_to_64[MAX_HYBRID_BANDS];
+-extern const SCHAR kernels_23_to_64[MAX_HYBRID_BANDS];
+-
+-extern const UCHAR mapping_15_to_23[MAX_PARAMETER_BANDS_LD];
+-extern const UCHAR mapping_12_to_23[MAX_PARAMETER_BANDS_LD];
+-extern const UCHAR mapping_9_to_23[MAX_PARAMETER_BANDS_LD];
+-extern const UCHAR mapping_7_to_23[MAX_PARAMETER_BANDS_LD];
+-extern const UCHAR mapping_5_to_23[MAX_PARAMETER_BANDS_LD];
+-extern const UCHAR mapping_4_to_23[MAX_PARAMETER_BANDS_LD];
+-
+-extern const FIXP_CFG clipGainTable__FDK[];
+-extern const UCHAR clipGainSFTable__FDK[];
+-
+-extern const UCHAR pbStrideTable[];
+-extern const int smgTimeTable[];
+-
+-extern const FIXP_CFG envShapeDataTable__FDK[5][2];
+-extern const SCHAR row2channelGES[][MAX_M2_INPUT];
+-
+-/* sac_calcM1andM2 */
+-extern const SCHAR row2residual[][MAX_M2_INPUT];
+-
+-void SpatialDequantGetCLDValues(int index, FIXP_DBL* cu, FIXP_DBL* cl);
+-
+-void SpatialDequantGetCLD2Values(int index, FIXP_DBL* x);
+-
+-/* External helper functions */
+-static inline int SacGetHybridSubbands(int qmfSubbands) {
+- return qmfSubbands - MAX_QMF_BANDS_TO_HYBRID + 10;
+-}
+-
+-#endif /* SAC_ROM_H */
+diff --git a/libSACdec/src/sac_smoothing.cpp b/libSACdec/src/sac_smoothing.cpp
+deleted file mode 100644
+index bee6551..0000000
+--- a/libSACdec/src/sac_smoothing.cpp
++++ /dev/null
+@@ -1,295 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec parameter smoothing
+-
+-*******************************************************************************/
+-
+-#include "sac_dec.h"
+-#include "sac_bitdec.h"
+-#include "sac_smoothing.h"
+-#include "sac_rom.h"
+-
+-/*******************************************************************************
+- Functionname: calcFilterCoeff
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Input:
+-
+- Output:
+-
+-
+-*******************************************************************************/
+-static FIXP_DBL calcFilterCoeff__FDK(spatialDec *self, int ps,
+- const SPATIAL_BS_FRAME *frame) {
+- int dSlots;
+- FIXP_DBL delta;
+-
+- dSlots = frame->paramSlot[ps] - self->smoothState->prevParamSlot;
+-
+- if (dSlots <= 0) {
+- dSlots += self->timeSlots;
+- }
+-
+- delta = fDivNorm(dSlots, self->smgTime[ps]);
+-
+- return delta;
+-}
+-
+-/*******************************************************************************
+- Functionname: getSmoothOnOff
+- *******************************************************************************
+-
+- Description:
+-
+- Arguments:
+-
+- Input:
+-
+- Output:
+-
+-
+-*******************************************************************************/
+-static int getSmoothOnOff(spatialDec *self, int ps, int pb) {
+- int smoothBand = 0;
+-
+- smoothBand = self->smgData[ps][pb];
+-
+- return smoothBand;
+-}
+-
+-void SpatialDecSmoothM1andM2(spatialDec *self, const SPATIAL_BS_FRAME *frame,
+- int ps) {
+- FIXP_DBL delta__FDK;
+- FIXP_DBL one_minus_delta__FDK;
+-
+- int pb, row, col;
+- int residualBands = 0;
+-
+- if (self->residualCoding) {
+- int i;
+- int boxes = self->numOttBoxes;
+- for (i = 0; i < boxes; i++) {
+- if (self->residualBands[i] > residualBands) {
+- residualBands = self->residualBands[i];
+- }
+- }
+- }
+-
+- delta__FDK = calcFilterCoeff__FDK(self, ps, frame);
+- if (delta__FDK == /*FL2FXCONST_DBL(1.0f)*/ (FIXP_DBL)MAXVAL_DBL)
+- one_minus_delta__FDK = FL2FXCONST_DBL(0.0f);
+- else if (delta__FDK == FL2FXCONST_DBL(0.0f))
+- one_minus_delta__FDK = /*FL2FXCONST_DBL(1.0f)*/ (FIXP_DBL)MAXVAL_DBL;
+- else
+- one_minus_delta__FDK = (FL2FXCONST_DBL(0.5f) - (delta__FDK >> 1)) << 1;
+-
+- for (pb = 0; pb < self->numParameterBands; pb++) {
+- int smoothBand;
+-
+- smoothBand = getSmoothOnOff(self, ps, pb);
+-
+- if (smoothBand && (pb >= residualBands)) {
+- for (row = 0; row < self->numM2rows; row++) {
+- for (col = 0; col < self->numVChannels; col++) {
+- self->M2Real__FDK[row][col][pb] =
+- ((fMultDiv2(delta__FDK, self->M2Real__FDK[row][col][pb]) +
+- fMultDiv2(one_minus_delta__FDK,
+- self->M2RealPrev__FDK[row][col][pb]))
+- << 1);
+- if (0 || (self->phaseCoding == 3)) {
+- self->M2Imag__FDK[row][col][pb] =
+- ((fMultDiv2(delta__FDK, self->M2Imag__FDK[row][col][pb]) +
+- fMultDiv2(one_minus_delta__FDK,
+- self->M2ImagPrev__FDK[row][col][pb]))
+- << 1);
+- }
+- }
+- }
+- }
+- }
+- self->smoothState->prevParamSlot = frame->paramSlot[ps];
+-}
+-
+-/* init states */
+-void initParameterSmoothing(spatialDec *self) {
+- self->smoothState->prevParamSlot = 0;
+-}
+-
+-void SpatialDecSmoothOPD(spatialDec *self, const SPATIAL_BS_FRAME *frame,
+- int ps) {
+- int pb;
+- int dSlots;
+- FIXP_DBL delta__FDK;
+- FIXP_DBL one_minus_delta__FDK;
+- FIXP_DBL *phaseLeftSmooth__FDK = self->smoothState->opdLeftState__FDK;
+- FIXP_DBL *phaseRightSmooth__FDK = self->smoothState->opdRightState__FDK;
+- int quantCoarse;
+-
+- quantCoarse = frame->IPDLosslessData[0].bsQuantCoarseXXX[ps];
+-
+- if (frame->OpdSmoothingMode == 0) {
+- FDKmemcpy(phaseLeftSmooth__FDK, self->PhaseLeft__FDK,
+- self->numParameterBands * sizeof(FIXP_DBL));
+- FDKmemcpy(phaseRightSmooth__FDK, self->PhaseRight__FDK,
+- self->numParameterBands * sizeof(FIXP_DBL));
+- } else {
+- if (ps == 0) {
+- dSlots = frame->paramSlot[ps] + 1;
+- } else {
+- dSlots = frame->paramSlot[ps] - frame->paramSlot[ps - 1];
+- }
+-
+- delta__FDK = (FIXP_DBL)((INT)(FL2FXCONST_DBL(0.0078125f)) * dSlots);
+-
+- if (delta__FDK == (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/)
+- one_minus_delta__FDK = FL2FXCONST_DBL(0.0f);
+- else if (delta__FDK == FL2FXCONST_DBL(0.0f))
+- one_minus_delta__FDK = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/;
+- else
+- one_minus_delta__FDK = (FL2FXCONST_DBL(0.5f) - (delta__FDK >> 1)) << 1;
+-
+- for (pb = 0; pb < self->numParameterBands; pb++) {
+- FIXP_DBL tmpL, tmpR, tmp;
+-
+- tmpL = self->PhaseLeft__FDK[pb];
+- tmpR = self->PhaseRight__FDK[pb];
+-
+- while (tmpL > phaseLeftSmooth__FDK[pb] + PI__IPD) tmpL -= PI__IPD << 1;
+- while (tmpL < phaseLeftSmooth__FDK[pb] - PI__IPD) tmpL += PI__IPD << 1;
+- while (tmpR > phaseRightSmooth__FDK[pb] + PI__IPD) tmpR -= PI__IPD << 1;
+- while (tmpR < phaseRightSmooth__FDK[pb] - PI__IPD) tmpR += PI__IPD << 1;
+-
+- phaseLeftSmooth__FDK[pb] =
+- fMult(delta__FDK, tmpL) +
+- fMult(one_minus_delta__FDK, phaseLeftSmooth__FDK[pb]);
+- phaseRightSmooth__FDK[pb] =
+- fMult(delta__FDK, tmpR) +
+- fMult(one_minus_delta__FDK, phaseRightSmooth__FDK[pb]);
+-
+- tmp = (((tmpL >> 1) - (tmpR >> 1)) - ((phaseLeftSmooth__FDK[pb] >> 1) -
+- (phaseRightSmooth__FDK[pb] >> 1)))
+- << 1;
+- while (tmp > PI__IPD) tmp -= PI__IPD << 1;
+- while (tmp < -PI__IPD) tmp += PI__IPD << 1;
+- if (fixp_abs(tmp) > fMult((quantCoarse ? FL2FXCONST_DBL(50.f / 180.f)
+- : FL2FXCONST_DBL(25.f / 180.f)),
+- PI__IPD)) {
+- phaseLeftSmooth__FDK[pb] = tmpL;
+- phaseRightSmooth__FDK[pb] = tmpR;
+- }
+-
+- while (phaseLeftSmooth__FDK[pb] > PI__IPD << 1)
+- phaseLeftSmooth__FDK[pb] -= PI__IPD << 1;
+- while (phaseLeftSmooth__FDK[pb] < (FIXP_DBL)0)
+- phaseLeftSmooth__FDK[pb] += PI__IPD << 1;
+- while (phaseRightSmooth__FDK[pb] > PI__IPD << 1)
+- phaseRightSmooth__FDK[pb] -= PI__IPD << 1;
+- while (phaseRightSmooth__FDK[pb] < (FIXP_DBL)0)
+- phaseRightSmooth__FDK[pb] += PI__IPD << 1;
+-
+- self->PhaseLeft__FDK[pb] = phaseLeftSmooth__FDK[pb];
+- self->PhaseRight__FDK[pb] = phaseRightSmooth__FDK[pb];
+- }
+- }
+- return;
+-}
+diff --git a/libSACdec/src/sac_smoothing.h b/libSACdec/src/sac_smoothing.h
+deleted file mode 100644
+index fdf3f5b..0000000
+--- a/libSACdec/src/sac_smoothing.h
++++ /dev/null
+@@ -1,114 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec parameter smoothing
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_SMOOTHING_H
+-#define SAC_SMOOTHING_H
+-
+-#include "sac_dec.h"
+-
+-void initParameterSmoothing(spatialDec *self);
+-void SpatialDecSmoothM1andM2(spatialDec *self, const SPATIAL_BS_FRAME *frame,
+- int ps);
+-void SpatialDecSmoothOPD(spatialDec *self, const SPATIAL_BS_FRAME *frame,
+- int ps);
+-
+-#endif
+diff --git a/libSACdec/src/sac_stp.cpp b/libSACdec/src/sac_stp.cpp
+deleted file mode 100644
+index 818e9df..0000000
+--- a/libSACdec/src/sac_stp.cpp
++++ /dev/null
+@@ -1,548 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec subband processing
+-
+-*******************************************************************************/
+-
+-#include "sac_stp.h"
+-#include "sac_calcM1andM2.h"
+-#include "sac_bitdec.h"
+-#include "FDK_matrixCalloc.h"
+-#include "sac_rom.h"
+-
+-#define BP_GF_START 6
+-#define BP_GF_SIZE 25
+-#define HP_SIZE 9
+-#define STP_UPDATE_ENERGY_RATE 32
+-
+-#define SF_WET 5
+-#define SF_DRY \
+- 3 /* SF_DRY == 2 would produce good conformance test results as well */
+-#define SF_PRODUCT_BP_GF 13
+-#define SF_PRODUCT_BP_GF_GF 26
+-#define SF_SCALE 2
+-
+-#define SF_SCALE_LD64 FL2FXCONST_DBL(0.03125) /* LD64((1<<SF_SCALE))*/
+-#define STP_LPF_COEFF1__FDK FL2FXCONST_DBL(0.950f) /* 0.95 */
+-#define ONE_MINUS_STP_LPF_COEFF1__FDK FL2FXCONST_DBL(0.05f) /* 1.0 - 0.95 */
+-#define STP_LPF_COEFF2__FDK FL2FXCONST_DBL(0.450f) /* 0.45 */
+-#define ONE_MINUS_STP_LPF_COEFF2__FDK \
+- FL2FXCONST_DBL(1.0f - 0.450f) /* 1.0 - 0.45 */
+-#define STP_SCALE_LIMIT__FDK \
+- FL2FXCONST_DBL(2.82f / (float)(1 << SF_SCALE)) /* scaled by SF_SCALE */
+-#define ONE_DIV_STP_SCALE_LIMIT__FDK \
+- FL2FXCONST_DBL(1.0f / 2.82f / (float)(1 << SF_SCALE)) /* scaled by SF_SCALE \
+- */
+-#define ABS_THR__FDK \
+- FL2FXCONST_DBL(ABS_THR / \
+- ((float)(1 << (22 + 22 - 26)))) /* scaled by 18 bits */
+-#define ABS_THR2__FDK \
+- FL2FXCONST_DBL(ABS_THR * 32.0f * 32.0f / \
+- ((float)(1 << (22 + 22 - 26)))) /* scaled by 10 bits */
+-#define STP_SCALE_LIMIT_HI \
+- FL2FXCONST_DBL(3.02222222222 / (1 << SF_SCALE)) /* see 4. below */
+-#define STP_SCALE_LIMIT_LO \
+- FL2FXCONST_DBL(0.28289992119 / (1 << SF_SCALE)) /* see 4. below */
+-#define STP_SCALE_LIMIT_HI_LD64 \
+- FL2FXCONST_DBL(0.04986280452) /* see 4. below \
+- */
+-#define STP_SCALE_LIMIT_LO_LD64 \
+- FL2FXCONST_DBL(0.05692613500) /* see 4. below \
+- */
+-
+-/* Scale factor calculation for the diffuse signal needs adapted thresholds
+- for STP_SCALE_LIMIT and 1/STP_SCALE_LIMIT:
+-
+- 1. scale = sqrt(DryNrg/WetNrg)
+-
+- 2. Damping of scale factor
+- scale2 = 0.1 + 0.9 * scale
+-
+- 3. Limiting of scale factor
+- STP_SCALE_LIMIT >= scale2 >= 1/STP_SCALE_LIMIT
+- => STP_SCALE_LIMIT >= (0.1 + 0.9 * scale) >= 1/STP_SCALE_LIMIT
+- => (STP_SCALE_LIMIT-0.1)/0.9 >= scale >=
+- (1/STP_SCALE_LIMIT-0.1)/0.9
+-
+- 3. Limiting of scale factor before sqrt calculation
+- ((STP_SCALE_LIMIT-0.1)/0.9)^2 >= (scale^2) >=
+- ((1/STP_SCALE_LIMIT-0.1)/0.9)^2 (STP_SCALE_LIMIT_HI)^2 >= (scale^2) >=
+- (STP_SCALE_LIMIT_LO)^2
+-
+- 4. Thresholds for limiting of scale factor
+- STP_SCALE_LIMIT_HI = ((2.82-0.1)/0.9)
+- STP_SCALE_LIMIT_LO = (((1.0/2.82)-0.1)/0.9)
+- STP_SCALE_LIMIT_HI_LD64 = LD64(STP_SCALE_LIMIT_HI*STP_SCALE_LIMIT_HI)
+- STP_SCALE_LIMIT_LO_LD64 = LD64(STP_SCALE_LIMIT_LO*STP_SCALE_LIMIT_LO)
+-*/
+-
+-#define DRY_ENER_WEIGHT(DryEner) DryEner = DryEner >> dry_scale_dmx
+-
+-#define WET_ENER_WEIGHT(WetEner) WetEner = WetEner << wet_scale_dmx
+-
+-#define DRY_ENER_SUM_REAL(DryEner, dmxReal, n) \
+- DryEner += \
+- fMultDiv2(fPow2Div2(dmxReal << SF_DRY), pBP[n]) >> ((2 * SF_DRY) - 2)
+-
+-#define DRY_ENER_SUM_CPLX(DryEner, dmxReal, dmxImag, n) \
+- DryEner += fMultDiv2( \
+- fPow2Div2(dmxReal << SF_DRY) + fPow2Div2(dmxImag << SF_DRY), pBP[n])
+-
+-#define CALC_WET_SCALE(dryIdx, wetIdx) \
+- if ((DryEnerLD64[dryIdx] - STP_SCALE_LIMIT_HI_LD64) > WetEnerLD64[wetIdx]) { \
+- scale[wetIdx] = STP_SCALE_LIMIT_HI; \
+- } else if (DryEnerLD64[dryIdx] < \
+- (WetEnerLD64[wetIdx] - STP_SCALE_LIMIT_LO_LD64)) { \
+- scale[wetIdx] = STP_SCALE_LIMIT_LO; \
+- } else { \
+- tmp = ((DryEnerLD64[dryIdx] - WetEnerLD64[wetIdx]) >> 1) - SF_SCALE_LD64; \
+- scale[wetIdx] = CalcInvLdData(tmp); \
+- }
+-
+-struct STP_DEC {
+- FIXP_DBL runDryEner[MAX_INPUT_CHANNELS];
+- FIXP_DBL runWetEner[MAX_OUTPUT_CHANNELS];
+- FIXP_DBL oldDryEnerLD64[MAX_INPUT_CHANNELS];
+- FIXP_DBL oldWetEnerLD64[MAX_OUTPUT_CHANNELS];
+- FIXP_DBL prev_tp_scale[MAX_OUTPUT_CHANNELS];
+- const FIXP_CFG *BP;
+- const FIXP_CFG *BP_GF;
+- int update_old_ener;
+-};
+-
+-inline void combineSignalReal(FIXP_DBL *hybOutputRealDry,
+- FIXP_DBL *hybOutputRealWet, int bands) {
+- int n;
+-
+- for (n = bands - 1; n >= 0; n--) {
+- *hybOutputRealDry = *hybOutputRealDry + *hybOutputRealWet;
+- hybOutputRealDry++, hybOutputRealWet++;
+- }
+-}
+-
+-inline void combineSignalRealScale1(FIXP_DBL *hybOutputRealDry,
+- FIXP_DBL *hybOutputRealWet, FIXP_DBL scaleX,
+- int bands) {
+- int n;
+-
+- for (n = bands - 1; n >= 0; n--) {
+- *hybOutputRealDry =
+- *hybOutputRealDry +
+- (fMultDiv2(*hybOutputRealWet, scaleX) << (SF_SCALE + 1));
+- hybOutputRealDry++, hybOutputRealWet++;
+- }
+-}
+-
+-inline void combineSignalCplx(FIXP_DBL *hybOutputRealDry,
+- FIXP_DBL *hybOutputImagDry,
+- FIXP_DBL *hybOutputRealWet,
+- FIXP_DBL *hybOutputImagWet, int bands) {
+- int n;
+-
+- for (n = bands - 1; n >= 0; n--) {
+- *hybOutputRealDry = *hybOutputRealDry + *hybOutputRealWet;
+- *hybOutputImagDry = *hybOutputImagDry + *hybOutputImagWet;
+- hybOutputRealDry++, hybOutputRealWet++;
+- hybOutputImagDry++, hybOutputImagWet++;
+- }
+-}
+-
+-inline void combineSignalCplxScale1(FIXP_DBL *hybOutputRealDry,
+- FIXP_DBL *hybOutputImagDry,
+- FIXP_DBL *hybOutputRealWet,
+- FIXP_DBL *hybOutputImagWet,
+- const FIXP_CFG *pBP, FIXP_DBL scaleX,
+- int bands) {
+- int n;
+- FIXP_DBL scaleY;
+- for (n = bands - 1; n >= 0; n--) {
+- scaleY = fMultDiv2(scaleX, *pBP);
+- *hybOutputRealDry =
+- *hybOutputRealDry +
+- (fMultDiv2(*hybOutputRealWet, scaleY) << (SF_SCALE + 2));
+- *hybOutputImagDry =
+- *hybOutputImagDry +
+- (fMultDiv2(*hybOutputImagWet, scaleY) << (SF_SCALE + 2));
+- hybOutputRealDry++, hybOutputRealWet++;
+- hybOutputImagDry++, hybOutputImagWet++;
+- pBP++;
+- }
+-}
+-
+-inline void combineSignalCplxScale2(FIXP_DBL *hybOutputRealDry,
+- FIXP_DBL *hybOutputImagDry,
+- FIXP_DBL *hybOutputRealWet,
+- FIXP_DBL *hybOutputImagWet, FIXP_DBL scaleX,
+- int bands) {
+- int n;
+-
+- for (n = bands - 1; n >= 0; n--) {
+- *hybOutputRealDry =
+- *hybOutputRealDry +
+- (fMultDiv2(*hybOutputRealWet, scaleX) << (SF_SCALE + 1));
+- *hybOutputImagDry =
+- *hybOutputImagDry +
+- (fMultDiv2(*hybOutputImagWet, scaleX) << (SF_SCALE + 1));
+- hybOutputRealDry++, hybOutputRealWet++;
+- hybOutputImagDry++, hybOutputImagWet++;
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: subbandTPCreate
+- ******************************************************************************/
+-SACDEC_ERROR subbandTPCreate(HANDLE_STP_DEC *hStpDec) {
+- HANDLE_STP_DEC self = NULL;
+- FDK_ALLOCATE_MEMORY_1D(self, 1, struct STP_DEC)
+- if (hStpDec != NULL) {
+- *hStpDec = self;
+- }
+-
+- return MPS_OK;
+-bail:
+- return MPS_OUTOFMEMORY;
+-}
+-
+-SACDEC_ERROR subbandTPInit(HANDLE_STP_DEC self) {
+- SACDEC_ERROR err = MPS_OK;
+- int ch;
+-
+- for (ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) {
+- self->prev_tp_scale[ch] = FL2FXCONST_DBL(1.0f / (1 << SF_SCALE));
+- self->oldWetEnerLD64[ch] =
+- FL2FXCONST_DBL(0.34375f); /* 32768.0*32768.0/2^(44-26-10) */
+- }
+- for (ch = 0; ch < MAX_INPUT_CHANNELS; ch++) {
+- self->oldDryEnerLD64[ch] =
+- FL2FXCONST_DBL(0.1875f); /* 32768.0*32768.0/2^(44-26) */
+- }
+-
+- self->BP = BP__FDK;
+- self->BP_GF = BP_GF__FDK;
+-
+- self->update_old_ener = 0;
+-
+- return err;
+-}
+-
+-/*******************************************************************************
+- Functionname: subbandTPDestroy
+- ******************************************************************************/
+-void subbandTPDestroy(HANDLE_STP_DEC *hStpDec) {
+- if (hStpDec != NULL) {
+- FDK_FREE_MEMORY_1D(*hStpDec);
+- }
+-}
+-
+-/*******************************************************************************
+- Functionname: subbandTPApply
+- ******************************************************************************/
+-SACDEC_ERROR subbandTPApply(spatialDec *self, const SPATIAL_BS_FRAME *frame) {
+- FIXP_DBL *qmfOutputRealDry[MAX_OUTPUT_CHANNELS];
+- FIXP_DBL *qmfOutputImagDry[MAX_OUTPUT_CHANNELS];
+- FIXP_DBL *qmfOutputRealWet[MAX_OUTPUT_CHANNELS];
+- FIXP_DBL *qmfOutputImagWet[MAX_OUTPUT_CHANNELS];
+-
+- FIXP_DBL DryEner[MAX_INPUT_CHANNELS];
+- FIXP_DBL scale[MAX_OUTPUT_CHANNELS];
+-
+- FIXP_DBL DryEnerLD64[MAX_INPUT_CHANNELS];
+- FIXP_DBL WetEnerLD64[MAX_OUTPUT_CHANNELS];
+-
+- FIXP_DBL DryEner0 = FL2FXCONST_DBL(0.0f);
+- FIXP_DBL WetEnerX, damp, tmp;
+- FIXP_DBL dmxReal0, dmxImag0;
+- int skipChannels[MAX_OUTPUT_CHANNELS];
+- int n, ch, cplxBands, cplxHybBands;
+- int dry_scale_dmx, wet_scale_dmx;
+- int i_LF, i_RF;
+- HANDLE_STP_DEC hStpDec;
+- const FIXP_CFG *pBP;
+-
+- int nrgScale = (2 * self->clipProtectGainSF__FDK);
+-
+- hStpDec = self->hStpDec;
+-
+- /* set scalefactor and loop counter */
+- FDK_ASSERT(SF_DRY >= 1);
+- {
+- cplxBands = BP_GF_SIZE;
+- cplxHybBands = self->hybridBands;
+- dry_scale_dmx = (2 * SF_DRY) - 2;
+- wet_scale_dmx = 2;
+- }
+-
+- /* setup pointer for forming the direct downmix signal */
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- qmfOutputRealDry[ch] = &self->hybOutputRealDry__FDK[ch][7];
+- qmfOutputRealWet[ch] = &self->hybOutputRealWet__FDK[ch][7];
+- qmfOutputImagDry[ch] = &self->hybOutputImagDry__FDK[ch][7];
+- qmfOutputImagWet[ch] = &self->hybOutputImagWet__FDK[ch][7];
+- }
+-
+- /* clear skipping flag for all output channels */
+- FDKmemset(skipChannels, 0, self->numOutputChannels * sizeof(int));
+-
+- /* set scale values to zero */
+- FDKmemset(scale, 0, self->numOutputChannels * sizeof(FIXP_DBL));
+-
+- /* update normalisation energy with latest smoothed energy */
+- if (hStpDec->update_old_ener == STP_UPDATE_ENERGY_RATE) {
+- hStpDec->update_old_ener = 1;
+- for (ch = 0; ch < self->numInputChannels; ch++) {
+- hStpDec->oldDryEnerLD64[ch] =
+- CalcLdData(hStpDec->runDryEner[ch] + ABS_THR__FDK);
+- }
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- hStpDec->oldWetEnerLD64[ch] =
+- CalcLdData(hStpDec->runWetEner[ch] + ABS_THR2__FDK);
+- }
+- } else {
+- hStpDec->update_old_ener++;
+- }
+-
+- /* get channel configuration */
+- switch (self->treeConfig) {
+- case TREE_212:
+- i_LF = 0;
+- i_RF = 1;
+- break;
+- default:
+- return MPS_WRONG_TREECONFIG;
+- }
+-
+- /* form the 'direct' downmix signal */
+- pBP = hStpDec->BP_GF - BP_GF_START;
+- switch (self->treeConfig) {
+- case TREE_212:
+- for (n = BP_GF_START; n < cplxBands; n++) {
+- dmxReal0 = qmfOutputRealDry[i_LF][n] + qmfOutputRealDry[i_RF][n];
+- dmxImag0 = qmfOutputImagDry[i_LF][n] + qmfOutputImagDry[i_RF][n];
+- DRY_ENER_SUM_CPLX(DryEner0, dmxReal0, dmxImag0, n);
+- }
+- DRY_ENER_WEIGHT(DryEner0);
+- break;
+- default:;
+- }
+- DryEner[0] = DryEner0;
+-
+- /* normalise the 'direct' signals */
+- for (ch = 0; ch < self->numInputChannels; ch++) {
+- DryEner[ch] = DryEner[ch] << (nrgScale);
+- hStpDec->runDryEner[ch] =
+- fMult(STP_LPF_COEFF1__FDK, hStpDec->runDryEner[ch]) +
+- fMult(ONE_MINUS_STP_LPF_COEFF1__FDK, DryEner[ch]);
+- if (DryEner[ch] != FL2FXCONST_DBL(0.0f)) {
+- DryEnerLD64[ch] =
+- fixMax((CalcLdData(DryEner[ch]) - hStpDec->oldDryEnerLD64[ch]),
+- FL2FXCONST_DBL(-0.484375f));
+- } else {
+- DryEnerLD64[ch] = FL2FXCONST_DBL(-0.484375f);
+- }
+- }
+- if (self->treeConfig == TREE_212) {
+- for (; ch < MAX_INPUT_CHANNELS; ch++) {
+- DryEnerLD64[ch] = FL2FXCONST_DBL(-0.484375f);
+- }
+- }
+-
+- /* normalise the 'diffuse' signals */
+- pBP = hStpDec->BP_GF - BP_GF_START;
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- if (skipChannels[ch]) {
+- continue;
+- }
+-
+- WetEnerX = FL2FXCONST_DBL(0.0f);
+- for (n = BP_GF_START; n < cplxBands; n++) {
+- tmp = fPow2Div2(qmfOutputRealWet[ch][n] << SF_WET);
+- tmp += fPow2Div2(qmfOutputImagWet[ch][n] << SF_WET);
+- WetEnerX += fMultDiv2(tmp, pBP[n]);
+- }
+- WET_ENER_WEIGHT(WetEnerX);
+-
+- WetEnerX = WetEnerX << (nrgScale);
+- hStpDec->runWetEner[ch] =
+- fMult(STP_LPF_COEFF1__FDK, hStpDec->runWetEner[ch]) +
+- fMult(ONE_MINUS_STP_LPF_COEFF1__FDK, WetEnerX);
+-
+- if (WetEnerX == FL2FXCONST_DBL(0.0f)) {
+- WetEnerLD64[ch] = FL2FXCONST_DBL(-0.484375f);
+- } else {
+- WetEnerLD64[ch] =
+- fixMax((CalcLdData(WetEnerX) - hStpDec->oldWetEnerLD64[ch]),
+- FL2FXCONST_DBL(-0.484375f));
+- }
+- }
+-
+- /* compute scale factor for the 'diffuse' signals */
+- switch (self->treeConfig) {
+- case TREE_212:
+- if (DryEner[0] != FL2FXCONST_DBL(0.0f)) {
+- CALC_WET_SCALE(0, i_LF);
+- CALC_WET_SCALE(0, i_RF);
+- }
+- break;
+- default:;
+- }
+-
+- damp = FL2FXCONST_DBL(0.1f / (1 << SF_SCALE));
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- /* damp the scaling factor */
+- scale[ch] = damp + fMult(FL2FXCONST_DBL(0.9f), scale[ch]);
+-
+- /* limiting the scale factor */
+- if (scale[ch] > STP_SCALE_LIMIT__FDK) {
+- scale[ch] = STP_SCALE_LIMIT__FDK;
+- }
+- if (scale[ch] < ONE_DIV_STP_SCALE_LIMIT__FDK) {
+- scale[ch] = ONE_DIV_STP_SCALE_LIMIT__FDK;
+- }
+-
+- /* low pass filter the scaling factor */
+- scale[ch] =
+- fMult(STP_LPF_COEFF2__FDK, scale[ch]) +
+- fMult(ONE_MINUS_STP_LPF_COEFF2__FDK, hStpDec->prev_tp_scale[ch]);
+- hStpDec->prev_tp_scale[ch] = scale[ch];
+- }
+-
+- /* combine 'direct' and scaled 'diffuse' signal */
+- FDK_ASSERT((HP_SIZE - 3 + 10 - 1) == PC_NUM_HYB_BANDS);
+- const SCHAR *channlIndex = row2channelSTP[self->treeConfig];
+-
+- for (ch = 0; ch < self->numOutputChannels; ch++) {
+- int no_scaling;
+-
+- no_scaling = !frame->tempShapeEnableChannelSTP[channlIndex[ch]];
+- if (no_scaling) {
+- combineSignalCplx(
+- &self->hybOutputRealDry__FDK[ch][self->tp_hybBandBorder],
+- &self->hybOutputImagDry__FDK[ch][self->tp_hybBandBorder],
+- &self->hybOutputRealWet__FDK[ch][self->tp_hybBandBorder],
+- &self->hybOutputImagWet__FDK[ch][self->tp_hybBandBorder],
+- cplxHybBands - self->tp_hybBandBorder);
+-
+- } else {
+- FIXP_DBL scaleX;
+- scaleX = scale[ch];
+- pBP = hStpDec->BP - self->tp_hybBandBorder;
+- /* Band[HP_SIZE-3+10-1] needs not to be processed in
+- combineSignalCplxScale1(), because pB[HP_SIZE-3+10-1] would be 1.0 */
+- combineSignalCplxScale1(
+- &self->hybOutputRealDry__FDK[ch][self->tp_hybBandBorder],
+- &self->hybOutputImagDry__FDK[ch][self->tp_hybBandBorder],
+- &self->hybOutputRealWet__FDK[ch][self->tp_hybBandBorder],
+- &self->hybOutputImagWet__FDK[ch][self->tp_hybBandBorder],
+- &pBP[self->tp_hybBandBorder], scaleX,
+- (HP_SIZE - 3 + 10 - 1) - self->tp_hybBandBorder);
+-
+- {
+- combineSignalCplxScale2(
+- &self->hybOutputRealDry__FDK[ch][HP_SIZE - 3 + 10 - 1],
+- &self->hybOutputImagDry__FDK[ch][HP_SIZE - 3 + 10 - 1],
+- &self->hybOutputRealWet__FDK[ch][HP_SIZE - 3 + 10 - 1],
+- &self->hybOutputImagWet__FDK[ch][HP_SIZE - 3 + 10 - 1], scaleX,
+- cplxHybBands - (HP_SIZE - 3 + 10 - 1));
+- }
+- }
+- }
+-
+- return (SACDEC_ERROR)MPS_OK;
+- ;
+-}
+diff --git a/libSACdec/src/sac_stp.h b/libSACdec/src/sac_stp.h
+deleted file mode 100644
+index 18471bd..0000000
+--- a/libSACdec/src/sac_stp.h
++++ /dev/null
+@@ -1,115 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s):
+-
+- Description: SAC Dec subband processing
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_STP_H
+-#define SAC_STP_H
+-
+-#include "sac_dec.h"
+-
+-SACDEC_ERROR subbandTPCreate(HANDLE_STP_DEC *hStpDec);
+-
+-SACDEC_ERROR subbandTPInit(HANDLE_STP_DEC self);
+-
+-SACDEC_ERROR subbandTPApply(spatialDec *self, const SPATIAL_BS_FRAME *frame);
+-void subbandTPDestroy(HANDLE_STP_DEC *hStpDec);
+-
+-#endif
+diff --git a/libSACdec/src/sac_tsd.cpp b/libSACdec/src/sac_tsd.cpp
+deleted file mode 100644
+index 30acca8..0000000
+--- a/libSACdec/src/sac_tsd.cpp
++++ /dev/null
+@@ -1,353 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s): Matthias Hildenbrand
+-
+- Description: USAC MPS212 Transient Steering Decorrelator (TSD)
+-
+-*******************************************************************************/
+-
+-#include "sac_tsd.h"
+-
+-#define TSD_START_BAND (7)
+-#define SIZE_S (4)
+-#define SIZE_C (5)
+-
+-/*** Tables ***/
+-RAM_ALIGN
+-LNK_SECTION_CONSTDATA
+-static const UCHAR nBitsTsdCW_32slots[32] = {
+- 5, 9, 13, 16, 18, 20, 22, 24, 25, 26, 27, 28, 29, 29, 30, 30,
+- 30, 29, 29, 28, 27, 26, 25, 24, 22, 20, 18, 16, 13, 9, 5, 0};
+-
+-RAM_ALIGN
+-LNK_SECTION_CONSTDATA
+-static const UCHAR nBitsTsdCW_64slots[64] = {
+- 6, 11, 16, 20, 23, 27, 30, 33, 35, 38, 40, 42, 44, 46, 48, 49,
+- 51, 52, 53, 55, 56, 57, 58, 58, 59, 60, 60, 60, 61, 61, 61, 61,
+- 61, 61, 61, 60, 60, 60, 59, 58, 58, 57, 56, 55, 53, 52, 51, 49,
+- 48, 46, 44, 42, 40, 38, 35, 33, 30, 27, 23, 20, 16, 11, 6, 0};
+-
+-RAM_ALIGN
+-LNK_SECTION_CONSTDATA
+-static const FIXP_STP phiTsd[8] = {
+- STCP(0x7fffffff, 0x00000000), STCP(0x5a82799a, 0x5a82799a),
+- STCP(0x00000000, 0x7fffffff), STCP(0xa57d8666, 0x5a82799a),
+- STCP(0x80000000, 0x00000000), STCP(0xa57d8666, 0xa57d8666),
+- STCP(0x00000000, 0x80000000), STCP(0x5a82799a, 0xa57d8666),
+-};
+-
+-/*** Static Functions ***/
+-static void longmult1(USHORT a[], USHORT b, USHORT d[], int len) {
+- int k;
+- ULONG tmp;
+- ULONG b0 = (ULONG)b;
+-
+- tmp = ((ULONG)a[0]) * b0;
+- d[0] = (USHORT)tmp;
+-
+- for (k = 1; k < len; k++) {
+- tmp = (tmp >> 16) + ((ULONG)a[k]) * b0;
+- d[k] = (USHORT)tmp;
+- }
+-}
+-
+-static void longdiv(USHORT b[], USHORT a, USHORT d[], USHORT *pr, int len) {
+- ULONG r;
+- ULONG tmp;
+- int k;
+-
+- FDK_ASSERT(a != 0);
+-
+- r = 0;
+-
+- for (k = len - 1; k >= 0; k--) {
+- tmp = ((ULONG)b[k]) + (r << 16);
+-
+- if (tmp) {
+- d[k] = (USHORT)(tmp / a);
+- r = tmp - d[k] * a;
+- } else {
+- d[k] = 0;
+- }
+- }
+- *pr = (USHORT)r;
+-}
+-
+-static void longsub(USHORT a[], USHORT b[], int lena, int lenb) {
+- int h;
+- LONG carry = 0;
+-
+- FDK_ASSERT(lena >= lenb);
+- for (h = 0; h < lenb; h++) {
+- carry += ((LONG)a[h]) - ((LONG)b[h]);
+- a[h] = (USHORT)carry;
+- carry = carry >> 16;
+- }
+-
+- for (; h < lena; h++) {
+- carry = ((LONG)a[h]) + carry;
+- a[h] = (USHORT)carry;
+- carry = carry >> 16;
+- }
+-
+- FDK_ASSERT(carry ==
+- 0); /* carry != 0 indicates subtraction underflow, e.g. b > a */
+- return;
+-}
+-
+-static int longcompare(USHORT a[], USHORT b[], int len) {
+- int i;
+-
+- for (i = len - 1; i > 0; i--) {
+- if (a[i] != b[i]) break;
+- }
+- return (a[i] >= b[i]) ? 1 : 0;
+-}
+-
+-FDK_INLINE int isTrSlot(const TSD_DATA *pTsdData, const int ts) {
+- return (pTsdData->bsTsdTrPhaseData[ts] >= 0);
+-}
+-
+-/*** Public Functions ***/
+-int TsdRead(HANDLE_FDK_BITSTREAM hBs, const int numSlots, TSD_DATA *pTsdData) {
+- int nBitsTrSlots = 0;
+- int bsTsdNumTrSlots;
+- const UCHAR *nBitsTsdCW_tab = NULL;
+-
+- switch (numSlots) {
+- case 32:
+- nBitsTrSlots = 4;
+- nBitsTsdCW_tab = nBitsTsdCW_32slots;
+- break;
+- case 64:
+- nBitsTrSlots = 5;
+- nBitsTsdCW_tab = nBitsTsdCW_64slots;
+- break;
+- default:
+- return 1;
+- }
+-
+- /*** Read TempShapeData for bsTempShapeConfig == 3 ***/
+- pTsdData->bsTsdEnable = FDKreadBit(hBs);
+- if (!pTsdData->bsTsdEnable) {
+- return 0;
+- }
+-
+- /*** Parse/Decode TsdData() ***/
+- pTsdData->numSlots = numSlots;
+-
+- bsTsdNumTrSlots = FDKreadBits(hBs, nBitsTrSlots);
+-
+- /* Decode transient slot positions */
+- {
+- int nBitsTsdCW = (int)nBitsTsdCW_tab[bsTsdNumTrSlots];
+- SCHAR *phaseData = pTsdData->bsTsdTrPhaseData;
+- int p = bsTsdNumTrSlots + 1;
+- int k, h;
+- USHORT s[SIZE_S] = {0};
+- USHORT c[SIZE_C] = {0};
+- USHORT r[1];
+-
+- /* Init with TsdSepData[k] = 0 */
+- for (k = 0; k < numSlots; k++) {
+- phaseData[k] = -1; /* means TsdSepData[] = 0 */
+- }
+-
+- for (h = (SIZE_S - 1); h >= 0; h--) {
+- if (nBitsTsdCW > h * 16) {
+- s[h] = (USHORT)FDKreadBits(hBs, nBitsTsdCW - h * 16);
+- nBitsTsdCW = h * 16;
+- }
+- }
+-
+- /* c = prod_{h=1}^{p} (k-p+h)/h */
+- k = numSlots - 1;
+- c[0] = k - p + 1;
+- for (h = 2; h <= p; h++) {
+- longmult1(c, (k - p + h), c, 5); /* c *= k - p + h; */
+- longdiv(c, h, c, r, 5); /* c /= h; */
+- FDK_ASSERT(*r == 0);
+- }
+-
+- /* go through all slots */
+- for (; k >= 0; k--) {
+- if (p > k) {
+- for (; k >= 0; k--) {
+- phaseData[k] = 1; /* means TsdSepData[] = 1 */
+- }
+- break;
+- }
+- if (longcompare(s, c, 4)) { /* (s >= c) */
+- longsub(s, c, 4, 4); /* s -= c; */
+- phaseData[k] = 1; /* means TsdSepData[] = 1 */
+- if (p == 1) {
+- break;
+- }
+- /* Update c for next iteration: c_new = c_old * p / k */
+- longmult1(c, p, c, 5);
+- p--;
+- } else {
+- /* Update c for next iteration: c_new = c_old * (k-p) / k */
+- longmult1(c, (k - p), c, 5);
+- }
+- longdiv(c, k, c, r, 5);
+- FDK_ASSERT(*r == 0);
+- }
+-
+- /* Read phase data */
+- for (k = 0; k < numSlots; k++) {
+- if (phaseData[k] == 1) {
+- phaseData[k] = FDKreadBits(hBs, 3);
+- }
+- }
+- }
+-
+- return 0;
+-}
+-
+-void TsdGenerateNonTr(const int numHybridBands, const TSD_DATA *pTsdData,
+- const int ts, FIXP_DBL *pVdirectReal,
+- FIXP_DBL *pVdirectImag, FIXP_DBL *pVnonTrReal,
+- FIXP_DBL *pVnonTrImag, FIXP_DBL **ppDecorrInReal,
+- FIXP_DBL **ppDecorrInImag) {
+- int k = 0;
+-
+- if (!isTrSlot(pTsdData, ts)) {
+- /* Let allpass based decorrelator read from direct input. */
+- *ppDecorrInReal = pVdirectReal;
+- *ppDecorrInImag = pVdirectImag;
+- return;
+- }
+-
+- /* Generate nonTr input signal for allpass based decorrelator */
+- for (; k < TSD_START_BAND; k++) {
+- pVnonTrReal[k] = pVdirectReal[k];
+- pVnonTrImag[k] = pVdirectImag[k];
+- }
+- for (; k < numHybridBands; k++) {
+- pVnonTrReal[k] = (FIXP_DBL)0;
+- pVnonTrImag[k] = (FIXP_DBL)0;
+- }
+- *ppDecorrInReal = pVnonTrReal;
+- *ppDecorrInImag = pVnonTrImag;
+-}
+-
+-void TsdApply(const int numHybridBands, const TSD_DATA *pTsdData, int *pTsdTs,
+- const FIXP_DBL *pVdirectReal, const FIXP_DBL *pVdirectImag,
+- FIXP_DBL *pDnonTrReal, FIXP_DBL *pDnonTrImag) {
+- const int ts = *pTsdTs;
+-
+- if (isTrSlot(pTsdData, ts)) {
+- int k;
+- const FIXP_STP *phi = &phiTsd[pTsdData->bsTsdTrPhaseData[ts]];
+- FDK_ASSERT((pTsdData->bsTsdTrPhaseData[ts] >= 0) &&
+- (pTsdData->bsTsdTrPhaseData[ts] < 8));
+-
+- /* d = d_nonTr + v_direct * exp(j * bsTsdTrPhaseData[ts]/4 * pi ) */
+- for (k = TSD_START_BAND; k < numHybridBands; k++) {
+- FIXP_DBL tempReal, tempImag;
+- cplxMult(&tempReal, &tempImag, pVdirectReal[k], pVdirectImag[k], *phi);
+- pDnonTrReal[k] += tempReal;
+- pDnonTrImag[k] += tempImag;
+- }
+- }
+-
+- /* The modulo MAX_TSD_TIME_SLOTS operation is to avoid illegal memory accesses
+- * in case of errors. */
+- *pTsdTs = (ts + 1) & (MAX_TSD_TIME_SLOTS - 1);
+- return;
+-}
+diff --git a/libSACdec/src/sac_tsd.h b/libSACdec/src/sac_tsd.h
+deleted file mode 100644
+index 2521e27..0000000
+--- a/libSACdec/src/sac_tsd.h
++++ /dev/null
+@@ -1,167 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround decoder library *************************
+-
+- Author(s): Matthias Hildenbrand
+-
+- Description: USAC MPS212 Transient Steering Decorrelator (TSD)
+-
+-*******************************************************************************/
+-
+-#ifndef SAC_TSD_H
+-#define SAC_TSD_H
+-
+-#include "FDK_bitstream.h"
+-#include "common_fix.h"
+-
+-#define MAX_TSD_TIME_SLOTS (64)
+-
+-/** Structure which holds the data needed to apply TSD to current frame. */
+-typedef struct {
+- UCHAR bsTsdEnable; /**< for current frame TSD is (0:disabled, 1:enabled) */
+- UCHAR numSlots; /**< total number of QMF slots per frame */
+- SCHAR
+- bsTsdTrPhaseData[MAX_TSD_TIME_SLOTS]; /**< -1 => TsdSepData[ts]=0; 0-7:
+- values of bsTsdTrPhaseData[ts]
+- and TsdSepData[ts]=1 */
+-} TSD_DATA;
+-
+-FDK_INLINE int isTsdActive(const TSD_DATA *pTsdData) {
+- return (int)pTsdData->bsTsdEnable;
+-}
+-
+-/**
+- * \brief Parse and Decode TSD data.
+- * \param[in] hBs bitstream handle to read data from.
+- * \param[in] numSlots number of QMF slots per frame.
+- * \param[out] pTsdData pointer to TSD data structure.
+- * \return 0 on succes, 1 on error.
+- */
+-int TsdRead(HANDLE_FDK_BITSTREAM hBs, const int numSlots, TSD_DATA *pTsdData);
+-
+-/**
+- * \brief Perform transient seperation (v_{x,nonTr} signal).
+- * \param[in] numHybridBands number of hybrid bands.
+- * \param[in] pTsdData pointer to TSD data structure.
+- * \param[in] pVdirectReal pointer to array with direct signal.
+- * \param[in] pVdirectImag pointer to array with direct signal.
+- * \param[out] pVnonTrReal pointer to array with nonTr signal.
+- * \param[out] pVnonTrImag pointer to array with nonTr signal.
+- * \param[out] ppDecorrInReal handle to array where allpass based decorrelator
+- * should read from (modified by this function).
+- * \param[out] ppDecorrInImag handle to array where allpass based decorrelator
+- * should read from (modified by this function).
+- */
+-void TsdGenerateNonTr(const int numHybridBands, const TSD_DATA *pTsdData,
+- const int ts, FIXP_DBL *pVdirectReal,
+- FIXP_DBL *pVdirectImag, FIXP_DBL *pVnonTrReal,
+- FIXP_DBL *pVnonTrImag, FIXP_DBL **ppDecorrInReal,
+- FIXP_DBL **ppDecorrInImag);
+-
+-/**
+- * \brief Generate d_{x,Tr} signal and add to d_{x,nonTr} signal
+- * \param[in] numHybridBands
+- * \param[in,out] pTsdData
+- * \param pTsdTs pointer to persistent time slot counter
+- * \param[in] pVdirectReal
+- * \param[in] pVdirectImag
+- * \param[out] pDnonTrReal
+- * \param[out] pDnonTrImag
+- */
+-void TsdApply(const int numHybridBands, const TSD_DATA *pTsdData, int *pTsdTs,
+- const FIXP_DBL *pVdirectReal, const FIXP_DBL *pVdirectImag,
+- FIXP_DBL *pDnonTrReal, FIXP_DBL *pDnonTrImag);
+-
+-#endif /* #ifndef SAC_TSD_H */
+diff --git a/libSACenc/include/sacenc_lib.h b/libSACenc/include/sacenc_lib.h
+deleted file mode 100644
+index 758cc0f..0000000
+--- a/libSACenc/include/sacenc_lib.h
++++ /dev/null
+@@ -1,405 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Max Neuendorf
+-
+- Description: Encoder Library Interface
+- Encoder API
+-
+-*******************************************************************************/
+-
+-/**************************************************************************/ /**
+- \file
+- ******************************************************************************/
+-
+-#ifndef SACENC_LIB_H
+-#define SACENC_LIB_H
+-
+-/* Includes ******************************************************************/
+-#include "machine_type.h"
+-#include "FDK_audio.h"
+-
+-#ifdef __cplusplus
+-extern "C" {
+-#endif
+-/* Defines *******************************************************************/
+-
+-/* Data Types ****************************************************************/
+-
+-/**
+- * Space encoder error codes.
+- */
+-typedef enum {
+- SACENC_OK = 0x00000000, /*!< No error happened. All fine. */
+- SACENC_INVALID_HANDLE =
+- 0x00000080, /*!< Handle passed to function call was invalid. */
+- SACENC_MEMORY_ERROR = 0x00000800, /*!< Memory allocation failed. */
+- SACENC_INIT_ERROR = 0x00008000, /*!< General initialization error. */
+- SACENC_ENCODE_ERROR =
+- 0x00080000, /*!< The encoding process was interrupted by an unexpected
+- error. */
+- SACENC_PARAM_ERROR = 0x00800000, /*!< Invalid runtime parameter. */
+- SACENC_UNSUPPORTED_PARAMETER = 0x00800001, /*!< Parameter not available. */
+- SACENC_INVALID_CONFIG = 0x00800002, /*!< Configuration not provided. */
+- SACENC_UNKNOWN_ERROR = 0x08000000 /*!< Unknown error. */
+-
+-} FDK_SACENC_ERROR;
+-
+-typedef enum {
+- SACENC_INVALID_MODE = 0,
+- SACENC_212 = 8,
+- SACENC_ESCAPE = 15
+-
+-} MP4SPACEENC_MODE;
+-
+-typedef enum {
+- SACENC_BANDS_INVALID = 0,
+- SACENC_BANDS_4 = 4,
+- SACENC_BANDS_5 = 5,
+- SACENC_BANDS_7 = 7,
+- SACENC_BANDS_9 = 9,
+- SACENC_BANDS_12 = 12,
+- SACENC_BANDS_15 = 15,
+- SACENC_BANDS_23 = 23
+-
+-} MP4SPACEENC_BANDS_CONFIG;
+-
+-typedef enum {
+- SACENC_QUANTMODE_INVALID = -1,
+- SACENC_QUANTMODE_FINE = 0,
+- SACENC_QUANTMODE_EBQ1 = 1,
+- SACENC_QUANTMODE_EBQ2 = 2,
+- SACENC_QUANTMODE_RSVD3 = 3
+-
+-} MP4SPACEENC_QUANTMODE;
+-
+-typedef enum {
+- SACENC_DMXGAIN_INVALID = -1,
+- SACENC_DMXGAIN_0_dB = 0,
+- SACENC_DMXGAIN_1_5_dB = 1,
+- SACENC_DMXGAIN_3_dB = 2,
+- SACENC_DMXGAIN_4_5_dB = 3,
+- SACENC_DMXGAIN_6_dB = 4,
+- SACENC_DMXGAIN_7_5_dB = 5,
+- SACENC_DMXGAIN_9_dB = 6,
+- SACENC_DMXGAIN_12_dB = 7
+-
+-} MP4SPACEENC_DMX_GAIN;
+-
+-/**
+- * \brief Space Encoder setting parameters.
+- *
+- * Use FDK_sacenc_setParam() function to configure the internal status of the
+- * following parameters.
+- */
+-typedef enum {
+- SACENC_LOWDELAY, /*!< Configure lowdelay MPEG Surround.
+- - 0: Disable Lowdelay. (default)
+- - 1: Enable Lowdelay.
+- - 2: Enable Lowdelay including keep frame. */
+-
+- SACENC_ENC_MODE, /*!< Configure encoder tree mode. See ::MP4SPACEENC_MODE for
+- available values. */
+-
+- SACENC_SAMPLERATE, /*!< Configure encoder sampling rate. */
+-
+- SACENC_FRAME_TIME_SLOTS, /*!< Configure number of slots per spatial frame. */
+-
+- SACENC_PARAM_BANDS, /*!< Configure number of parameter bands. See
+- ::MP4SPACEENC_BANDS_CONFIG for available values. */
+-
+- SACENC_TIME_DOM_DMX, /*!< Configure time domain downmix.
+- - 0: No time domain downmix. (default)
+- - 1: Static time domain downmix.
+- - 2: Enhanced time domain downmix, stereo to mono
+- only. */
+-
+- SACENC_DMX_GAIN, /*!< Configure downmix gain. See ::MP4SPACEENC_DMX_GAIN for
+- available values. */
+-
+- SACENC_COARSE_QUANT, /*!< Use coarse parameter quantization.
+- - 0: No (default)
+- - 1: Yes */
+-
+- SACENC_QUANT_MODE, /*!< Configure quanitzation mode. See
+- ::MP4SPACEENC_QUANTMODE for available values. */
+-
+- SACENC_TIME_ALIGNMENT, /*!< Configure time alignment in samples. */
+-
+- SACENC_INDEPENDENCY_COUNT, /*!< Configure the independency count. (count == 0
+- means independencyFlag == 1) */
+-
+- SACENC_INDEPENDENCY_FACTOR, /*!< How often should we set the independency flag
+- */
+-
+- SACENC_NONE /*!< ------ */
+-
+-} SPACEENC_PARAM;
+-
+-/**
+- * Describes Spatial Specific Config.
+- */
+-typedef struct {
+- INT nSscSizeBits; /*!< Number of valid bits in pSsc buffer. */
+- UCHAR *pSsc; /*!< SpatialSpecificConfig buffer in binary format. */
+-
+-} MPEG4SPACEENC_SSCBUF;
+-
+-/**
+- * Provides some info about the encoder configuration.
+- */
+-typedef struct {
+- INT nSampleRate; /*!< Configured sampling rate.*/
+- INT nSamplesFrame; /*!< Frame length in samples. */
+- INT nTotalInputChannels; /*!< Number of expected audio input channels. */
+- INT nDmxDelay; /*!< Delay of the downmixed signal. */
+- INT nCodecDelay; /*!< Delay of the whole en-/decoded signal, including
+- core-coder delay. */
+- INT nDecoderDelay; /*!< Delay added by the MP4SPACE decoder. */
+- INT nPayloadDelay; /*!< Delay of the payload. */
+- INT nDiscardOutFrames; /*!< Number of dmx frames to discard for alignment with
+- bitstream. */
+-
+- MPEG4SPACEENC_SSCBUF
+- *pSscBuf; /*!< Pointer to Spatial Specific Config structure. */
+-
+-} MP4SPACEENC_INFO;
+-
+-/**
+- * MPEG Surround encoder handle.
+- */
+-typedef struct MP4SPACE_ENCODER *HANDLE_MP4SPACE_ENCODER;
+-
+-/**
+- * Defines the input arguments for a FDK_sacenc_encode() call.
+- */
+-typedef struct {
+- INT nInputSamples; /*!< Number of valid input audio samples (multiple of input
+- channels). */
+- UINT inputBufferSizePerChannel; /*!< Size of input buffer (input audio
+- samples) per channel. */
+- UINT isInputInterleaved; /*!< Indicates if input audio samples are represented
+- in blocks or interleaved:
+- - 0 : in blocks.
+- - 1 : interleaved. */
+-
+-} SACENC_InArgs;
+-
+-/**
+- * Defines the output arguments for a FDK_sacenc_encode() call.
+- */
+-typedef struct {
+- INT nOutputBits; /*!< Number of valid payload bits generated during
+- FDK_sacenc_encode(). */
+- INT nOutputSamples; /*!< Number of valid output audio samples generated during
+- FDK_sacenc_encode(). */
+- UINT nSamplesConsumed; /*!< Number of input audio samples consumed in
+- FDK_sacenc_encode(). */
+-
+-} SACENC_OutArgs;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/**
+- * \brief Opens a new instace of the MPEG Surround encoder.
+- *
+- * \param phMp4SpaceEnc Pointer to the encoder handle to be deallocated.
+- *
+- * \return
+- * - SACENC_OK, on success.
+- * - SACENC_INVALID_HANDLE, SACENC_MEMORY_ERROR, on failure.
+- */
+-FDK_SACENC_ERROR FDK_sacenc_open(HANDLE_MP4SPACE_ENCODER *phMp4SpaceEnc);
+-
+-/**
+- * \brief Finalizes opening process of MPEG Surround encoder.
+- *
+- * Shows, how many samples are needed as input
+- *
+- * \param hMp4SpaceEnc A valid MPEG Surround encoder handle.
+- * \param dmxDelay Downmix delay.
+- *
+- * \return
+- * - SACENC_OK, on success.
+- * - SACENC_INVALID_HANDLE, SACENC_INIT_ERROR, SACENC_INVALID_CONFIG,
+- * on failure.
+- */
+-FDK_SACENC_ERROR FDK_sacenc_init(HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc,
+- const INT dmxDelay);
+-
+-/**
+- * \brief Close the MPEG Surround encoder instance.
+- *
+- * Deallocate encoder instance and free whole memory.
+- *
+- * \param phMp4SpaceEnc Pointer to the encoder handle to be deallocated.
+- *
+- * \return
+- * - SACENC_OK, on success.
+- * - SACENC_INVALID_HANDLE, on failure.
+- */
+-FDK_SACENC_ERROR FDK_sacenc_close(HANDLE_MP4SPACE_ENCODER *phMp4SpaceEnc);
+-
+-/**
+- * \brief MPEG surround parameter extraction, framwise.
+- *
+- * \param hMp4SpaceEnc A valid MPEG Surround encoder handle.
+- *
+- * \return
+- * - SACENC_OK, on success.
+- * - SACENC_INVALID_HANDLE, on failure.
+- */
+-FDK_SACENC_ERROR FDK_sacenc_encode(const HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc,
+- const FDK_bufDescr *inBufDesc,
+- const FDK_bufDescr *outBufDesc,
+- const SACENC_InArgs *inargs,
+- SACENC_OutArgs *outargs);
+-
+-/**
+- * \brief Provides information on produced bitstream.
+- *
+- * \param hMp4SpaceEnc A valid MPEG Surround encoder handle.
+- * \param pInfo Pointer to an encoder info struct, filled on
+- * return.
+- *
+- * \return
+- * - SACENC_OK, on success.
+- * - SACENC_INVALID_HANDLE, on failure.
+- */
+-FDK_SACENC_ERROR FDK_sacenc_getInfo(const HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc,
+- MP4SPACEENC_INFO *const pInfo);
+-
+-/**
+- * \brief Set one single MPEG Surround encoder parameter.
+- *
+- * This function allows configuration of all encoder parameters specified in
+- * ::SPACEENC_PARAM. Each parameter must be set with a separate function call.
+- * An internal validation of the configuration value range will be done.
+- *
+- * \param hMp4SpaceEnc A valid MPEG Surround encoder handle.
+- * \param param Parameter to be set. See ::SPACEENC_PARAM.
+- * \param value Parameter value. See parameter description in
+- * ::SPACEENC_PARAM.
+- *
+- * \return
+- * - SACENC_OK, on success.
+- * - SACENC_INVALID_HANDLE, SACENC_UNSUPPORTED_PARAMETER,
+- * SACENC_INVALID_CONFIG, on failure.
+- */
+-FDK_SACENC_ERROR FDK_sacenc_setParam(HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc,
+- const SPACEENC_PARAM param,
+- const UINT value);
+-
+-/**
+- * \brief Get information about MPEG Surround encoder library build.
+- *
+- * Fill a given LIB_INFO structure with library version information.
+- *
+- * \param info Pointer to an allocated LIB_INFO struct.
+- *
+- * \return
+- * - SACENC_OK, on success.
+- * - SACENC_INVALID_HANDLE, SACENC_INIT_ERROR, on failure.
+- */
+-FDK_SACENC_ERROR FDK_sacenc_getLibInfo(LIB_INFO *info);
+-
+-#ifdef __cplusplus
+-}
+-#endif
+-
+-#endif /* SACENC_LIB_H */
+diff --git a/libSACenc/src/sacenc_bitstream.cpp b/libSACenc/src/sacenc_bitstream.cpp
+deleted file mode 100644
+index dacfc27..0000000
+--- a/libSACenc/src/sacenc_bitstream.cpp
++++ /dev/null
+@@ -1,826 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s):
+-
+- Description: Encoder Library Interface
+- Bitstream Writer
+-
+-*******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_bitstream.h"
+-#include "sacenc_const.h"
+-
+-#include "genericStds.h"
+-#include "common_fix.h"
+-
+-#include "FDK_matrixCalloc.h"
+-#include "sacenc_nlc_enc.h"
+-
+-/* Defines *******************************************************************/
+-#define MAX_FREQ_RES_INDEX 8
+-#define MAX_SAMPLING_FREQUENCY_INDEX 13
+-#define SAMPLING_FREQUENCY_INDEX_ESCAPE 15
+-
+-/* Data Types ****************************************************************/
+-typedef struct {
+- SCHAR cld_old[SACENC_MAX_NUM_BOXES][MAX_NUM_BINS];
+- SCHAR icc_old[SACENC_MAX_NUM_BOXES][MAX_NUM_BINS];
+- UCHAR quantCoarseCldPrev[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAMS];
+- UCHAR quantCoarseIccPrev[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAMS];
+-
+-} PREV_OTTDATA;
+-
+-typedef struct {
+- PREV_OTTDATA prevOttData;
+-
+-} STATIC_SPATIALFRAME;
+-
+-typedef struct BSF_INSTANCE {
+- SPATIALSPECIFICCONFIG spatialSpecificConfig;
+- SPATIALFRAME frame;
+- STATIC_SPATIALFRAME prevFrameData;
+-
+-} BSF_INSTANCE;
+-
+-/* Constants *****************************************************************/
+-static const INT SampleRateTable[MAX_SAMPLING_FREQUENCY_INDEX] = {
+- 96000, 88200, 64000, 48000, 44100, 32000, 24000,
+- 22050, 16000, 12000, 11025, 8000, 7350};
+-
+-static const UCHAR FreqResBinTable_LD[MAX_FREQ_RES_INDEX] = {0, 23, 15, 12,
+- 9, 7, 5, 4};
+-static const UCHAR FreqResStrideTable_LD[] = {1, 2, 5, 23};
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-static FDK_SACENC_ERROR DuplicateLosslessData(
+- const INT startBox, const INT stopBox,
+- const LOSSLESSDATA *const hLosslessDataFrom, const INT setFrom,
+- LOSSLESSDATA *const hLosslessDataTo, const INT setTo) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((NULL == hLosslessDataFrom) || (NULL == hLosslessDataTo)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i;
+-
+- for (i = startBox; i < stopBox; i++) {
+- hLosslessDataTo->bsXXXDataMode[i][setTo] =
+- hLosslessDataFrom->bsXXXDataMode[i][setFrom];
+- hLosslessDataTo->bsDataPair[i][setTo] =
+- hLosslessDataFrom->bsDataPair[i][setFrom];
+- hLosslessDataTo->bsQuantCoarseXXX[i][setTo] =
+- hLosslessDataFrom->bsQuantCoarseXXX[i][setFrom];
+- hLosslessDataTo->bsFreqResStrideXXX[i][setTo] =
+- hLosslessDataFrom->bsFreqResStrideXXX[i][setFrom];
+- }
+- }
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_duplicateParameterSet(
+- const SPATIALFRAME *const hFrom, const INT setFrom, SPATIALFRAME *const hTo,
+- const INT setTo) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((NULL == hFrom) || (NULL == hTo)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int box;
+- /* Only Copy Parameter Set selective stuff */
+-
+- /* OTT-Data */
+- for (box = 0; box < SACENC_MAX_NUM_BOXES; box++) {
+- FDKmemcpy(hTo->ottData.cld[box][setTo], hFrom->ottData.cld[box][setFrom],
+- sizeof(hFrom->ottData.cld[0][0]));
+- FDKmemcpy(hTo->ottData.icc[box][setTo], hFrom->ottData.icc[box][setFrom],
+- sizeof(hFrom->ottData.icc[0][0]));
+- }
+-
+- /* LOSSLESSDATA */
+- DuplicateLosslessData(0, SACENC_MAX_NUM_BOXES, &hFrom->CLDLosslessData,
+- setFrom, &hTo->CLDLosslessData, setTo);
+- DuplicateLosslessData(0, SACENC_MAX_NUM_BOXES, &hFrom->ICCLosslessData,
+- setFrom, &hTo->ICCLosslessData, setTo);
+-
+- } /* valid handle */
+-
+- return error;
+-}
+-
+-/* set frame defaults */
+-static void clearFrame(SPATIALFRAME *const pFrame) {
+- FDKmemclear(pFrame, sizeof(SPATIALFRAME));
+-
+- pFrame->bsIndependencyFlag = 1;
+- pFrame->framingInfo.numParamSets = 1;
+-}
+-
+-static void fine2coarse(SCHAR *const data, const DATA_TYPE dataType,
+- const INT startBand, const INT numBands) {
+- int i;
+- if (dataType == t_CLD) {
+- for (i = startBand; i < startBand + numBands; i++) {
+- data[i] /= 2;
+- }
+- } else {
+- for (i = startBand; i < startBand + numBands; i++) {
+- data[i] >>= 1;
+- }
+- }
+-}
+-
+-static void coarse2fine(SCHAR *const data, const DATA_TYPE dataType,
+- const INT startBand, const INT numBands) {
+- int i;
+-
+- for (i = startBand; i < startBand + numBands; i++) {
+- data[i] <<= 1;
+- }
+-
+- if (dataType == t_CLD) {
+- for (i = startBand; i < startBand + numBands; i++) {
+- if (data[i] == -14) {
+- data[i] = -15;
+- } else if (data[i] == 14) {
+- data[i] = 15;
+- }
+- }
+- } /* (dataType == t_CLD) */
+-}
+-
+-static UCHAR getBsFreqResStride(const INT index) {
+- const UCHAR *pFreqResStrideTable = NULL;
+- int freqResStrideTableSize = 0;
+-
+- pFreqResStrideTable = FreqResStrideTable_LD;
+- freqResStrideTableSize =
+- sizeof(FreqResStrideTable_LD) / sizeof(*FreqResStrideTable_LD);
+-
+- return (((NULL != pFreqResStrideTable) && (index >= 0) &&
+- (index < freqResStrideTableSize))
+- ? pFreqResStrideTable[index]
+- : 1);
+-}
+-
+-/* write data to bitstream */
+-static void ecData(HANDLE_FDK_BITSTREAM bitstream,
+- SCHAR data[MAX_NUM_PARAMS][MAX_NUM_BINS],
+- SCHAR oldData[MAX_NUM_BINS],
+- UCHAR quantCoarseXXXprev[MAX_NUM_PARAMS],
+- LOSSLESSDATA *const losslessData, const DATA_TYPE dataType,
+- const INT paramIdx, const INT numParamSets,
+- const INT independencyFlag, const INT startBand,
+- const INT stopBand, const INT defaultValue) {
+- int ps, pb, strOffset, pbStride, dataBands, i;
+- int aStrides[MAX_NUM_BINS + 1] = {0};
+- SHORT cmpIdxData[2][MAX_NUM_BINS] = {{0}};
+- SHORT cmpOldData[MAX_NUM_BINS] = {0};
+-
+- /* bsXXXDataMode */
+- if (independencyFlag || (losslessData->bsQuantCoarseXXX[paramIdx][0] !=
+- quantCoarseXXXprev[paramIdx])) {
+- losslessData->bsXXXDataMode[paramIdx][0] = FINECOARSE;
+- } else {
+- losslessData->bsXXXDataMode[paramIdx][0] = KEEP;
+- for (i = startBand; i < stopBand; i++) {
+- if (data[0][i] != oldData[i]) {
+- losslessData->bsXXXDataMode[paramIdx][0] = FINECOARSE;
+- break;
+- }
+- }
+- }
+-
+- FDKwriteBits(bitstream, losslessData->bsXXXDataMode[paramIdx][0], 2);
+-
+- for (ps = 1; ps < numParamSets; ps++) {
+- if (losslessData->bsQuantCoarseXXX[paramIdx][ps] !=
+- losslessData->bsQuantCoarseXXX[paramIdx][ps - 1]) {
+- losslessData->bsXXXDataMode[paramIdx][ps] = FINECOARSE;
+- } else {
+- losslessData->bsXXXDataMode[paramIdx][ps] = KEEP;
+- for (i = startBand; i < stopBand; i++) {
+- if (data[ps][i] != data[ps - 1][i]) {
+- losslessData->bsXXXDataMode[paramIdx][ps] = FINECOARSE;
+- break;
+- }
+- }
+- }
+-
+- FDKwriteBits(bitstream, losslessData->bsXXXDataMode[paramIdx][ps], 2);
+- } /* for ps */
+-
+- /* Create data pairs if possible */
+- for (ps = 0; ps < (numParamSets - 1); ps++) {
+- if (losslessData->bsXXXDataMode[paramIdx][ps] == FINECOARSE) {
+- /* Check if next parameter set is FINCOARSE */
+- if (losslessData->bsXXXDataMode[paramIdx][ps + 1] == FINECOARSE) {
+- /* We have to check if ps and ps+1 use the same bsXXXQuantMode */
+- /* and also have the same stride */
+- if ((losslessData->bsQuantCoarseXXX[paramIdx][ps + 1] ==
+- losslessData->bsQuantCoarseXXX[paramIdx][ps]) &&
+- (losslessData->bsFreqResStrideXXX[paramIdx][ps + 1] ==
+- losslessData->bsFreqResStrideXXX[paramIdx][ps])) {
+- losslessData->bsDataPair[paramIdx][ps] = 1;
+- losslessData->bsDataPair[paramIdx][ps + 1] = 1;
+-
+- /* We have a data pair -> Jump to the ps after next ps*/
+- ps++;
+- continue;
+- }
+- }
+- /* dataMode of next ps is not FINECOARSE or does not use the same
+- * bsXXXQuantMode/stride */
+- /* -> no dataPair possible */
+- losslessData->bsDataPair[paramIdx][ps] = 0;
+-
+- /* Initialize ps after next ps to Zero (only important for the last
+- * parameter set) */
+- losslessData->bsDataPair[paramIdx][ps + 1] = 0;
+- } else {
+- /* No FINECOARSE -> no data pair possible */
+- losslessData->bsDataPair[paramIdx][ps] = 0;
+-
+- /* Initialize ps after next ps to Zero (only important for the last
+- * parameter set) */
+- losslessData->bsDataPair[paramIdx][ps + 1] = 0;
+- }
+- } /* for ps */
+-
+- for (ps = 0; ps < numParamSets; ps++) {
+- if (losslessData->bsXXXDataMode[paramIdx][ps] == DEFAULT) {
+- /* Prepare old data */
+- for (i = startBand; i < stopBand; i++) {
+- oldData[i] = defaultValue;
+- }
+- quantCoarseXXXprev[paramIdx] = 0; /* Default data are always fine */
+- }
+-
+- if (losslessData->bsXXXDataMode[paramIdx][ps] == FINECOARSE) {
+- FDKwriteBits(bitstream, losslessData->bsDataPair[paramIdx][ps], 1);
+- FDKwriteBits(bitstream, losslessData->bsQuantCoarseXXX[paramIdx][ps], 1);
+- FDKwriteBits(bitstream, losslessData->bsFreqResStrideXXX[paramIdx][ps],
+- 2);
+-
+- if (losslessData->bsQuantCoarseXXX[paramIdx][ps] !=
+- quantCoarseXXXprev[paramIdx]) {
+- if (quantCoarseXXXprev[paramIdx]) {
+- coarse2fine(oldData, dataType, startBand, stopBand - startBand);
+- } else {
+- fine2coarse(oldData, dataType, startBand, stopBand - startBand);
+- }
+- }
+-
+- /* Handle strides */
+- pbStride =
+- getBsFreqResStride(losslessData->bsFreqResStrideXXX[paramIdx][ps]);
+- dataBands = (stopBand - startBand - 1) / pbStride + 1;
+-
+- aStrides[0] = startBand;
+- for (pb = 1; pb <= dataBands; pb++) {
+- aStrides[pb] = aStrides[pb - 1] + pbStride;
+- }
+-
+- strOffset = 0;
+- while (aStrides[dataBands] > stopBand) {
+- if (strOffset < dataBands) {
+- strOffset++;
+- }
+- for (i = strOffset; i <= dataBands; i++) {
+- aStrides[i]--;
+- }
+- } /* while */
+-
+- for (pb = 0; pb < dataBands; pb++) {
+- cmpOldData[startBand + pb] = oldData[aStrides[pb]];
+- cmpIdxData[0][startBand + pb] = data[ps][aStrides[pb]];
+-
+- if (losslessData->bsDataPair[paramIdx][ps]) {
+- cmpIdxData[1][startBand + pb] = data[ps + 1][aStrides[pb]];
+- }
+- } /* for pb*/
+-
+- /* Finally encode */
+- if (losslessData->bsDataPair[paramIdx][ps]) {
+- fdk_sacenc_ecDataPairEnc(bitstream, cmpIdxData, cmpOldData, dataType, 0,
+- startBand, dataBands,
+- losslessData->bsQuantCoarseXXX[paramIdx][ps],
+- independencyFlag && (ps == 0));
+- } else {
+- fdk_sacenc_ecDataSingleEnc(bitstream, cmpIdxData, cmpOldData, dataType,
+- 0, startBand, dataBands,
+- losslessData->bsQuantCoarseXXX[paramIdx][ps],
+- independencyFlag && (ps == 0));
+- }
+-
+- /* Overwrite old data */
+- for (i = startBand; i < stopBand; i++) {
+- if (losslessData->bsDataPair[paramIdx][ps]) {
+- oldData[i] = data[ps + 1][i];
+- } else {
+- oldData[i] = data[ps][i];
+- }
+- }
+-
+- quantCoarseXXXprev[paramIdx] =
+- losslessData->bsQuantCoarseXXX[paramIdx][ps];
+-
+- /* Jump forward if we have encoded a data pair */
+- if (losslessData->bsDataPair[paramIdx][ps]) {
+- ps++;
+- }
+-
+- } /* if (losslessData->bsXXXDataMode[paramIdx][ps] == FINECOARSE ) */
+- } /* for ps */
+-}
+-
+-/****************************************************************************/
+-/* Bitstream formatter interface functions */
+-/****************************************************************************/
+-static FDK_SACENC_ERROR getBsFreqResIndex(const INT numBands,
+- INT *const pbsFreqResIndex) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == pbsFreqResIndex) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- const UCHAR *pFreqResBinTable = FreqResBinTable_LD;
+- int i;
+- *pbsFreqResIndex = -1;
+-
+- for (i = 0; i < MAX_FREQ_RES_INDEX; i++) {
+- if (numBands == pFreqResBinTable[i]) {
+- *pbsFreqResIndex = i;
+- break;
+- }
+- }
+- if (*pbsFreqResIndex < 0 || *pbsFreqResIndex >= MAX_FREQ_RES_INDEX) {
+- error = SACENC_INVALID_CONFIG;
+- }
+- }
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR getSamplingFrequencyIndex(
+- const INT bsSamplingFrequency, INT *const pbsSamplingFrequencyIndex) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == pbsSamplingFrequencyIndex) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i;
+- *pbsSamplingFrequencyIndex = SAMPLING_FREQUENCY_INDEX_ESCAPE;
+-
+- for (i = 0; i < MAX_SAMPLING_FREQUENCY_INDEX; i++) {
+- if (bsSamplingFrequency == SampleRateTable[i]) { /*spatial sampling rate*/
+- *pbsSamplingFrequencyIndex = i;
+- break;
+- }
+- }
+- }
+- return error;
+-}
+-
+-/* destroy encoder instance */
+-FDK_SACENC_ERROR fdk_sacenc_destroySpatialBitstreamEncoder(
+- HANDLE_BSF_INSTANCE *selfPtr) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((selfPtr == NULL) || (*selfPtr == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- if (*selfPtr != NULL) {
+- FDK_FREE_MEMORY_1D(*selfPtr);
+- }
+- }
+- return error;
+-}
+-
+-/* create encoder instance */
+-FDK_SACENC_ERROR fdk_sacenc_createSpatialBitstreamEncoder(
+- HANDLE_BSF_INSTANCE *selfPtr) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == selfPtr) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* allocate encoder struct */
+- FDK_ALLOCATE_MEMORY_1D(*selfPtr, 1, BSF_INSTANCE);
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_destroySpatialBitstreamEncoder(selfPtr);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-/* init encoder instance */
+-FDK_SACENC_ERROR fdk_sacenc_initSpatialBitstreamEncoder(
+- HANDLE_BSF_INSTANCE selfPtr) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (selfPtr == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* init/clear */
+- clearFrame(&selfPtr->frame);
+-
+- } /* valid handle */
+- return error;
+-}
+-
+-/* get SpatialSpecificConfig struct */
+-SPATIALSPECIFICCONFIG *fdk_sacenc_getSpatialSpecificConfig(
+- HANDLE_BSF_INSTANCE selfPtr) {
+- return ((selfPtr == NULL) ? NULL : &(selfPtr->spatialSpecificConfig));
+-}
+-
+-/* write SpatialSpecificConfig to stream */
+-FDK_SACENC_ERROR fdk_sacenc_writeSpatialSpecificConfig(
+- SPATIALSPECIFICCONFIG *const spatialSpecificConfig,
+- UCHAR *const pOutputBuffer, const INT outputBufferSize,
+- INT *const pnOutputBits) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+- INT bsSamplingFrequencyIndex = 0;
+- INT bsFreqRes = 0;
+-
+- if ((spatialSpecificConfig == NULL) || (pOutputBuffer == NULL) ||
+- (pnOutputBits == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDK_BITSTREAM bitstream;
+-
+- /* Find FreqRes */
+- if (SACENC_OK != (error = getBsFreqResIndex(spatialSpecificConfig->numBands,
+- &bsFreqRes)))
+- goto bail;
+-
+- /* Find SamplingFrequencyIndex */
+- if (SACENC_OK != (error = getSamplingFrequencyIndex(
+- spatialSpecificConfig->bsSamplingFrequency,
+- &bsSamplingFrequencyIndex)))
+- goto bail;
+-
+- /* bind extern buffer to bitstream handle */
+- FDKinitBitStream(&bitstream, pOutputBuffer, outputBufferSize, 0, BS_WRITER);
+-
+- /****************************************************************************/
+- /* write to bitstream */
+-
+- FDKwriteBits(&bitstream, bsSamplingFrequencyIndex, 4);
+-
+- if (bsSamplingFrequencyIndex == 15) {
+- FDKwriteBits(&bitstream, spatialSpecificConfig->bsSamplingFrequency, 24);
+- }
+-
+- FDKwriteBits(&bitstream, spatialSpecificConfig->bsFrameLength, 5);
+-
+- FDKwriteBits(&bitstream, bsFreqRes, 3);
+- FDKwriteBits(&bitstream, spatialSpecificConfig->bsTreeConfig, 4);
+- FDKwriteBits(&bitstream, spatialSpecificConfig->bsQuantMode, 2);
+-
+- FDKwriteBits(&bitstream, 0, 1); /* bsArbitraryDownmix */
+-
+- FDKwriteBits(&bitstream, spatialSpecificConfig->bsFixedGainDMX, 3);
+-
+- FDKwriteBits(&bitstream, TEMPSHAPE_OFF, 2);
+- FDKwriteBits(&bitstream, spatialSpecificConfig->bsDecorrConfig, 2);
+-
+- FDKbyteAlign(&bitstream, 0); /* byte alignment */
+-
+- /* return number of valid bits in bitstream */
+- if ((*pnOutputBits = FDKgetValidBits(&bitstream)) >
+- (outputBufferSize * 8)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- /* terminate buffer with alignment */
+- FDKbyteAlign(&bitstream, 0);
+-
+- } /* valid handle */
+-
+-bail:
+- return error;
+-}
+-
+-/* get SpatialFrame struct */
+-SPATIALFRAME *fdk_sacenc_getSpatialFrame(HANDLE_BSF_INSTANCE selfPtr,
+- const SPATIALFRAME_TYPE frameType) {
+- int idx = -1;
+-
+- switch (frameType) {
+- case READ_SPATIALFRAME:
+- case WRITE_SPATIALFRAME:
+- idx = 0;
+- break;
+- default:
+- idx = -1; /* invalid configuration */
+- } /* switch frameType */
+-
+- return (((selfPtr == NULL) || (idx == -1)) ? NULL : &selfPtr->frame);
+-}
+-
+-static FDK_SACENC_ERROR writeFramingInfo(HANDLE_FDK_BITSTREAM hBitstream,
+- const FRAMINGINFO *const pFramingInfo,
+- const INT frameLength) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hBitstream == NULL) || (pFramingInfo == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDKwriteBits(hBitstream, pFramingInfo->bsFramingType, 1);
+- FDKwriteBits(hBitstream, pFramingInfo->numParamSets - 1, 1);
+-
+- if (pFramingInfo->bsFramingType) {
+- int ps = 0;
+- int numParamSets = pFramingInfo->numParamSets;
+-
+- {
+- for (ps = 0; ps < numParamSets; ps++) {
+- int bitsParamSlot = 0;
+- while ((1 << bitsParamSlot) < (frameLength + 1)) bitsParamSlot++;
+- if (bitsParamSlot > 0)
+- FDKwriteBits(hBitstream, pFramingInfo->bsParamSlots[ps],
+- bitsParamSlot);
+- }
+- }
+- } /* pFramingInfo->bsFramingType */
+- } /* valid handle */
+-
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR writeSmgData(HANDLE_FDK_BITSTREAM hBitstream,
+- const SMGDATA *const pSmgData,
+- const INT numParamSets,
+- const INT dataBands) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hBitstream == NULL) || (pSmgData == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i, j;
+-
+- for (i = 0; i < numParamSets; i++) {
+- FDKwriteBits(hBitstream, pSmgData->bsSmoothMode[i], 2);
+-
+- if (pSmgData->bsSmoothMode[i] >= 2) {
+- FDKwriteBits(hBitstream, pSmgData->bsSmoothTime[i], 2);
+- }
+- if (pSmgData->bsSmoothMode[i] == 3) {
+- const int stride = getBsFreqResStride(pSmgData->bsFreqResStride[i]);
+- FDKwriteBits(hBitstream, pSmgData->bsFreqResStride[i], 2);
+- for (j = 0; j < dataBands; j += stride) {
+- FDKwriteBits(hBitstream, pSmgData->bsSmgData[i][j], 1);
+- }
+- }
+- } /* for i */
+- } /* valid handle */
+-
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR writeOttData(
+- HANDLE_FDK_BITSTREAM hBitstream, PREV_OTTDATA *const pPrevOttData,
+- OTTDATA *const pOttData, const OTTCONFIG ottConfig[SACENC_MAX_NUM_BOXES],
+- LOSSLESSDATA *const pCLDLosslessData, LOSSLESSDATA *const pICCLosslessData,
+- const INT numOttBoxes, const INT numBands, const INT numParamSets,
+- const INT bsIndependencyFlag) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hBitstream == NULL) || (pPrevOttData == NULL) || (pOttData == NULL) ||
+- (ottConfig == NULL) || (pCLDLosslessData == NULL) ||
+- (pICCLosslessData == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i;
+- for (i = 0; i < numOttBoxes; i++) {
+- ecData(hBitstream, pOttData->cld[i], pPrevOttData->cld_old[i],
+- pPrevOttData->quantCoarseCldPrev[i], pCLDLosslessData, t_CLD, i,
+- numParamSets, bsIndependencyFlag, 0, ottConfig[i].bsOttBands, 15);
+- }
+- {
+- for (i = 0; i < numOttBoxes; i++) {
+- {
+- ecData(hBitstream, pOttData->icc[i], pPrevOttData->icc_old[i],
+- pPrevOttData->quantCoarseIccPrev[i], pICCLosslessData, t_ICC,
+- i, numParamSets, bsIndependencyFlag, 0, numBands, 0);
+- }
+- } /* for i */
+- }
+- } /* valid handle */
+-
+- return error;
+-}
+-
+-/* write extension frame data to stream */
+-static FDK_SACENC_ERROR WriteSpatialExtensionFrame(
+- HANDLE_FDK_BITSTREAM bitstream, HANDLE_BSF_INSTANCE self) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((bitstream == NULL) || (self == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDKbyteAlign(bitstream, 0);
+- } /* valid handle */
+-
+- return error;
+-}
+-
+-/* write frame data to stream */
+-FDK_SACENC_ERROR fdk_sacenc_writeSpatialFrame(UCHAR *const pOutputBuffer,
+- const INT outputBufferSize,
+- INT *const pnOutputBits,
+- HANDLE_BSF_INSTANCE selfPtr) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((pOutputBuffer == NULL) || (pnOutputBits == NULL) || (selfPtr == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- SPATIALFRAME *frame = NULL;
+- SPATIALSPECIFICCONFIG *config = NULL;
+- FDK_BITSTREAM bitstream;
+-
+- int i, j, numParamSets, numOttBoxes;
+-
+- if ((NULL ==
+- (frame = fdk_sacenc_getSpatialFrame(selfPtr, READ_SPATIALFRAME))) ||
+- (NULL == (config = &(selfPtr->spatialSpecificConfig)))) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- numOttBoxes = selfPtr->spatialSpecificConfig.treeDescription.numOttBoxes;
+-
+- numParamSets = frame->framingInfo.numParamSets;
+-
+- if (frame->bUseBBCues) {
+- for (i = 0; i < SACENC_MAX_NUM_BOXES; i++) {
+- /* If a transient was detected, force only the second ps broad band */
+- if (numParamSets == 1) {
+- frame->CLDLosslessData.bsFreqResStrideXXX[i][0] = 3;
+- frame->ICCLosslessData.bsFreqResStrideXXX[i][0] = 3;
+- } else {
+- for (j = 1; j < MAX_NUM_PARAMS; j++) {
+- frame->CLDLosslessData.bsFreqResStrideXXX[i][j] = 3;
+- frame->ICCLosslessData.bsFreqResStrideXXX[i][j] = 3;
+- }
+- }
+- }
+- } /* frame->bUseBBCues */
+-
+- /* bind extern buffer to bitstream handle */
+- FDKinitBitStream(&bitstream, pOutputBuffer, outputBufferSize, 0, BS_WRITER);
+-
+- if (SACENC_OK != (error = writeFramingInfo(
+- &bitstream, &(frame->framingInfo),
+- selfPtr->spatialSpecificConfig.bsFrameLength))) {
+- goto bail;
+- }
+-
+- /* write bsIndependencyFlag */
+- FDKwriteBits(&bitstream, frame->bsIndependencyFlag, 1);
+-
+- /* write spatial data to bitstream */
+- if (SACENC_OK !=
+- (error = writeOttData(&bitstream, &selfPtr->prevFrameData.prevOttData,
+- &frame->ottData, config->ottConfig,
+- &frame->CLDLosslessData, &frame->ICCLosslessData,
+- numOttBoxes, config->numBands, numParamSets,
+- frame->bsIndependencyFlag))) {
+- goto bail;
+- }
+- if (SACENC_OK != (error = writeSmgData(&bitstream, &frame->smgData,
+- numParamSets, config->numBands))) {
+- goto bail;
+- }
+-
+- /* byte alignment */
+- FDKbyteAlign(&bitstream, 0);
+-
+- /* Write SpatialExtensionFrame */
+- if (SACENC_OK !=
+- (error = WriteSpatialExtensionFrame(&bitstream, selfPtr))) {
+- goto bail;
+- }
+-
+- if (NULL ==
+- (frame = fdk_sacenc_getSpatialFrame(selfPtr, WRITE_SPATIALFRAME))) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- clearFrame(frame);
+-
+- /* return number of valid bits in bitstream */
+- if ((*pnOutputBits = FDKgetValidBits(&bitstream)) >
+- (outputBufferSize * 8)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- /* terminate buffer with alignment */
+- FDKbyteAlign(&bitstream, 0);
+-
+- } /* valid handle */
+-
+-bail:
+- return error;
+-}
+diff --git a/libSACenc/src/sacenc_bitstream.h b/libSACenc/src/sacenc_bitstream.h
+deleted file mode 100644
+index 67b7b5a..0000000
+--- a/libSACenc/src/sacenc_bitstream.h
++++ /dev/null
+@@ -1,296 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s):
+-
+- Description: Encoder Library Interface
+- Bitstream Writer
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_BITSTREAM_H
+-#define SACENC_BITSTREAM_H
+-
+-/* Includes ******************************************************************/
+-#include "FDK_bitstream.h"
+-#include "FDK_matrixCalloc.h"
+-#include "sacenc_lib.h"
+-#include "sacenc_const.h"
+-
+-/* Defines *******************************************************************/
+-#define MAX_NUM_BINS 23
+-#define MAX_NUM_PARAMS 2
+-#define MAX_NUM_OUTPUTCHANNELS SACENC_MAX_OUTPUT_CHANNELS
+-#define MAX_TIME_SLOTS 32
+-
+-typedef enum {
+- TREE_212 = 7,
+- TREE_ESCAPE = 15
+-
+-} TREECONFIG;
+-
+-typedef enum {
+- FREQ_RES_40 = 0,
+- FREQ_RES_20 = 1,
+- FREQ_RES_10 = 2,
+- FREQ_RES_5 = 3
+-
+-} FREQ;
+-
+-typedef enum {
+- QUANTMODE_INVALID = -1,
+- QUANTMODE_FINE = 0,
+- QUANTMODE_EBQ1 = 1,
+- QUANTMODE_EBQ2 = 2
+-
+-} QUANTMODE;
+-
+-typedef enum {
+- TEMPSHAPE_OFF = 0
+-
+-} TEMPSHAPECONFIG;
+-
+-typedef enum {
+- FIXEDGAINDMX_INVALID = -1,
+- FIXEDGAINDMX_0 = 0,
+- FIXEDGAINDMX_1 = 1,
+- FIXEDGAINDMX_2 = 2,
+- FIXEDGAINDMX_3 = 3,
+- FIXEDGAINDMX_4 = 4,
+- FIXEDGAINDMX_5 = 5,
+- FIXEDGAINDMX_6 = 6,
+- FIXEDGAINDMX_7 = 7
+-
+-} FIXEDGAINDMXCONFIG;
+-
+-typedef enum {
+- DECORR_INVALID = -1,
+- DECORR_QMFSPLIT0 = 0, /* QMF splitfreq: 3, 15, 24, 65 */
+- DECORR_QMFSPLIT1 = 1, /* QMF splitfreq: 3, 50, 65, 65 */
+- DECORR_QMFSPLIT2 = 2 /* QMF splitfreq: 0, 15, 65, 65 */
+-
+-} DECORRCONFIG;
+-
+-typedef enum {
+- DEFAULT = 0,
+- KEEP = 1,
+- INTERPOLATE = 2,
+- FINECOARSE = 3
+-
+-} DATA_MODE;
+-
+-typedef enum {
+- READ_SPATIALFRAME = 0,
+- WRITE_SPATIALFRAME = 1
+-
+-} SPATIALFRAME_TYPE;
+-
+-/* Data Types ****************************************************************/
+-typedef struct {
+- INT numOttBoxes;
+- INT numInChan;
+- INT numOutChan;
+-
+-} TREEDESCRIPTION;
+-
+-typedef struct {
+- INT bsOttBands;
+-
+-} OTTCONFIG;
+-
+-typedef struct {
+- INT bsSamplingFrequency; /* for bsSamplingFrequencyIndex */
+- INT bsFrameLength;
+- INT numBands; /* for bsFreqRes */
+- TREECONFIG bsTreeConfig;
+- QUANTMODE bsQuantMode;
+- FIXEDGAINDMXCONFIG bsFixedGainDMX;
+- int bsEnvQuantMode;
+- DECORRCONFIG bsDecorrConfig;
+- TREEDESCRIPTION treeDescription;
+- OTTCONFIG ottConfig[SACENC_MAX_NUM_BOXES];
+-
+-} SPATIALSPECIFICCONFIG;
+-
+-typedef struct {
+- UCHAR bsFramingType;
+- UCHAR numParamSets;
+- UCHAR bsParamSlots[MAX_NUM_PARAMS];
+-
+-} FRAMINGINFO;
+-
+-typedef struct {
+- SCHAR cld[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAMS][MAX_NUM_BINS];
+- SCHAR icc[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAMS][MAX_NUM_BINS];
+-
+-} OTTDATA;
+-
+-typedef struct {
+- UCHAR bsSmoothMode[MAX_NUM_PARAMS];
+- UCHAR bsSmoothTime[MAX_NUM_PARAMS];
+- UCHAR bsFreqResStride[MAX_NUM_PARAMS];
+- UCHAR bsSmgData[MAX_NUM_PARAMS][MAX_NUM_BINS];
+-
+-} SMGDATA;
+-
+-typedef struct {
+- UCHAR bsEnvShapeChannel[MAX_NUM_OUTPUTCHANNELS];
+- UCHAR bsEnvShapeData[MAX_NUM_OUTPUTCHANNELS][MAX_TIME_SLOTS];
+-
+-} TEMPSHAPEDATA;
+-
+-typedef struct {
+- UCHAR bsXXXDataMode[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAMS];
+- UCHAR bsDataPair[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAMS];
+- UCHAR bsQuantCoarseXXX[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAMS];
+- UCHAR bsFreqResStrideXXX[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAMS];
+-
+-} LOSSLESSDATA;
+-
+-typedef struct {
+- FRAMINGINFO framingInfo;
+- UCHAR bsIndependencyFlag;
+- OTTDATA ottData;
+- SMGDATA smgData;
+- TEMPSHAPEDATA tempShapeData;
+- LOSSLESSDATA CLDLosslessData;
+- LOSSLESSDATA ICCLosslessData;
+- UCHAR bUseBBCues;
+-
+-} SPATIALFRAME;
+-
+-typedef struct BSF_INSTANCE *HANDLE_BSF_INSTANCE;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-/* destroy encoder instance */
+-FDK_SACENC_ERROR fdk_sacenc_destroySpatialBitstreamEncoder(
+- HANDLE_BSF_INSTANCE *selfPtr);
+-
+-/* create encoder instance */
+-FDK_SACENC_ERROR fdk_sacenc_createSpatialBitstreamEncoder(
+- HANDLE_BSF_INSTANCE *selfPtr);
+-
+-FDK_SACENC_ERROR fdk_sacenc_initSpatialBitstreamEncoder(
+- HANDLE_BSF_INSTANCE selfPtr);
+-
+-/* get SpatialSpecificConfig struct */
+-SPATIALSPECIFICCONFIG *fdk_sacenc_getSpatialSpecificConfig(
+- HANDLE_BSF_INSTANCE selfPtr);
+-
+-/* write SpatialSpecificConfig to stream */
+-FDK_SACENC_ERROR fdk_sacenc_writeSpatialSpecificConfig(
+- SPATIALSPECIFICCONFIG *const spatialSpecificConfig,
+- UCHAR *const pOutputBuffer, const INT outputBufferSize,
+- INT *const pnOutputBits);
+-
+-/* get SpatialFrame struct */
+-SPATIALFRAME *fdk_sacenc_getSpatialFrame(HANDLE_BSF_INSTANCE selfPtr,
+- const SPATIALFRAME_TYPE frameType);
+-
+-/* write frame data to stream */
+-FDK_SACENC_ERROR fdk_sacenc_writeSpatialFrame(UCHAR *const pOutputBuffer,
+- const INT outputBufferSize,
+- INT *const pnOutputBits,
+- HANDLE_BSF_INSTANCE selfPtr);
+-
+-/* Copy/Save spatial frame data for one parameter set */
+-FDK_SACENC_ERROR fdk_sacenc_duplicateParameterSet(
+- const SPATIALFRAME *const hFrom, const INT setFrom, SPATIALFRAME *const hTo,
+- const INT setTo);
+-
+-#endif /* SACENC_BITSTREAM_H */
+diff --git a/libSACenc/src/sacenc_const.h b/libSACenc/src/sacenc_const.h
+deleted file mode 100644
+index c86e765..0000000
+--- a/libSACenc/src/sacenc_const.h
++++ /dev/null
+@@ -1,126 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Markus Multrus
+-
+- Description: Encoder Library Interface
+- constants to MPEG-4 spatial encoder lib
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_CONST_H
+-#define SACENC_CONST_H
+-
+-/* Includes ******************************************************************/
+-#include "machine_type.h"
+-
+-/* Defines *******************************************************************/
+-#define NUM_QMF_BANDS 64
+-#define MAX_QMF_BANDS 128
+-
+-#define SACENC_MAX_NUM_BOXES 1
+-#define SACENC_MAX_INPUT_CHANNELS 2
+-#define SACENC_MAX_OUTPUT_CHANNELS 1
+-
+-#define SACENC_FLOAT_EPSILON (1e-9f)
+-
+-/* Data Types ****************************************************************/
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-#endif /* SACENC_CONST_H */
+diff --git a/libSACenc/src/sacenc_delay.cpp b/libSACenc/src/sacenc_delay.cpp
+deleted file mode 100644
+index f2ed6b0..0000000
+--- a/libSACenc/src/sacenc_delay.cpp
++++ /dev/null
+@@ -1,472 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Christian Goettlinger
+-
+- Description: Encoder Library Interface
+- delay management of the encoder
+-
+-*******************************************************************************/
+-
+-/**************************************************************************/ /**
+- \file
+- This file contains all delay infrastructure
+- ******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_delay.h"
+-#include "sacenc_const.h"
+-#include "FDK_matrixCalloc.h"
+-
+-/* Defines *******************************************************************/
+-
+-/* Data Types ****************************************************************/
+-struct DELAY {
+- struct DELAY_CONFIG {
+- /* Routing Config Switches*/
+- INT bDmxAlign;
+- INT bTimeDomDmx;
+- INT bMinimizeDelay;
+- INT bSacTimeAlignmentDynamicOut;
+-
+- /* Needed Input Variables*/
+- INT nQmfLen;
+- INT nFrameLen;
+- INT nSurroundDelay;
+- INT nArbDmxDelay;
+- INT nLimiterDelay;
+- INT nCoreCoderDelay;
+- INT nSacStreamMuxDelay;
+- INT nSacTimeAlignment; /* Overwritten, if bSacTimeAlignmentDynamicOut */
+- } config;
+-
+- /* Variable Delaybuffers -> Delays */
+- INT nDmxAlignBuffer;
+- INT nSurroundAnalysisBuffer;
+- INT nArbDmxAnalysisBuffer;
+- INT nOutputAudioBuffer;
+- INT nBitstreamFrameBuffer;
+- INT nOutputAudioQmfFrameBuffer;
+- INT nDiscardOutFrames;
+-
+- /* Variable Delaybuffers Computation Variables */
+- INT nBitstreamFrameBufferSize;
+-
+- /* Output: Infos */
+- INT nInfoDmxDelay; /* Delay of the downmixed signal after the space encoder */
+- INT nInfoCodecDelay; /* Delay of the whole en-/decoder including CoreCoder */
+- INT nInfoDecoderDelay; /* Delay of the Mpeg Surround decoder */
+-};
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_delay_Open()
+-description: initializes Delays
+-returns: noError on success, an apropriate error code else
+------------------------------------------------------------------------------*/
+-FDK_SACENC_ERROR fdk_sacenc_delay_Open(HANDLE_DELAY *phDelay) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == phDelay) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDK_ALLOCATE_MEMORY_1D(*phDelay, 1, struct DELAY);
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_delay_Close(phDelay);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_delay_Close()
+-description: destructs Delay
+-returns: noError on success, an apropriate error code else
+------------------------------------------------------------------------------*/
+-FDK_SACENC_ERROR fdk_sacenc_delay_Close(HANDLE_DELAY *phDelay) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == phDelay) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- if (NULL != *phDelay) {
+- FDK_FREE_MEMORY_1D(*phDelay);
+- }
+- }
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_Init(HANDLE_DELAY hDelay, const INT nQmfLen,
+- const INT nFrameLen,
+- const INT nCoreCoderDelay,
+- const INT nSacStreamMuxDelay) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hDelay) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* Fill structure before calculation */
+- FDKmemclear(&hDelay->config, sizeof(hDelay->config));
+-
+- hDelay->config.nQmfLen = nQmfLen;
+- hDelay->config.nFrameLen = nFrameLen;
+- hDelay->config.nCoreCoderDelay = nCoreCoderDelay;
+- hDelay->config.nSacStreamMuxDelay = nSacStreamMuxDelay;
+- }
+- return error;
+-}
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_delay_SubCalulateBufferDelays()
+-description: Calculates the Delays of the buffers
+-returns: Error Code
+------------------------------------------------------------------------------*/
+-FDK_SACENC_ERROR fdk_sacenc_delay_SubCalulateBufferDelays(HANDLE_DELAY hDel) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hDel) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int nEncoderAnDelay, nEncoderSynDelay, nEncoderWinDelay, nDecoderAnDelay,
+- nDecoderSynDelay, nResidualCoderFrameDelay,
+- nArbDmxResidualCoderFrameDelay;
+-
+- if (hDel->config.bSacTimeAlignmentDynamicOut > 0) {
+- hDel->config.nSacTimeAlignment = 0;
+- }
+-
+- {
+- nEncoderAnDelay =
+- 2 * hDel->config.nQmfLen +
+- hDel->config.nQmfLen / 2; /* Only Ld-QMF Delay, no hybrid */
+- nEncoderSynDelay = 1 * hDel->config.nQmfLen + hDel->config.nQmfLen / 2;
+- nDecoderAnDelay = 2 * hDel->config.nQmfLen + hDel->config.nQmfLen / 2;
+- nDecoderSynDelay = 1 * hDel->config.nQmfLen + hDel->config.nQmfLen / 2;
+- nEncoderWinDelay =
+- hDel->config.nFrameLen / 2; /* WindowLookahead is just half a frame */
+- }
+-
+- { nResidualCoderFrameDelay = 0; }
+-
+- { nArbDmxResidualCoderFrameDelay = 0; }
+-
+- /* Calculate variable Buffer-Delays */
+- if (hDel->config.bTimeDomDmx == 0) {
+- /* ArbitraryDmx and TdDmx off */
+- int tempDelay;
+-
+- hDel->nSurroundAnalysisBuffer = 0;
+- hDel->nArbDmxAnalysisBuffer = 0;
+- tempDelay = nEncoderSynDelay + hDel->config.nLimiterDelay +
+- hDel->config.nCoreCoderDelay +
+- hDel->config.nSacTimeAlignment + nDecoderAnDelay;
+- tempDelay = (nResidualCoderFrameDelay * hDel->config.nFrameLen) +
+- hDel->config.nSacStreamMuxDelay - tempDelay;
+-
+- if (tempDelay > 0) {
+- hDel->nBitstreamFrameBuffer = 0;
+- hDel->nOutputAudioBuffer = tempDelay;
+- } else {
+- tempDelay = -tempDelay;
+- hDel->nBitstreamFrameBuffer =
+- (tempDelay + hDel->config.nFrameLen - 1) / hDel->config.nFrameLen;
+- hDel->nOutputAudioBuffer =
+- (hDel->nBitstreamFrameBuffer * hDel->config.nFrameLen) - tempDelay;
+- }
+-
+- hDel->nOutputAudioQmfFrameBuffer =
+- (hDel->nOutputAudioBuffer + (hDel->config.nQmfLen / 2) - 1) /
+- hDel->config.nQmfLen;
+-
+- if (hDel->config.bDmxAlign > 0) {
+- tempDelay = nEncoderWinDelay + nEncoderAnDelay + nEncoderSynDelay +
+- hDel->nOutputAudioBuffer + hDel->config.nLimiterDelay +
+- hDel->config.nCoreCoderDelay;
+- hDel->nDiscardOutFrames =
+- (tempDelay + hDel->config.nFrameLen - 1) / hDel->config.nFrameLen;
+- hDel->nDmxAlignBuffer =
+- hDel->nDiscardOutFrames * hDel->config.nFrameLen - tempDelay;
+- } else {
+- hDel->nDiscardOutFrames = 0;
+- hDel->nDmxAlignBuffer = 0;
+- }
+-
+- /* Output: Info-Variables */
+- hDel->nInfoDmxDelay = hDel->nSurroundAnalysisBuffer + nEncoderAnDelay +
+- nEncoderWinDelay + nEncoderSynDelay +
+- hDel->nOutputAudioBuffer +
+- hDel->config.nLimiterDelay;
+- hDel->nInfoCodecDelay =
+- hDel->nInfoDmxDelay + hDel->config.nCoreCoderDelay +
+- hDel->config.nSacTimeAlignment + nDecoderAnDelay + nDecoderSynDelay;
+-
+- } else {
+- /* ArbitraryDmx or TdDmx on */
+- int tempDelay1, tempDelay2, tempDelay12, tempDelay3;
+-
+- tempDelay1 = hDel->config.nArbDmxDelay - hDel->config.nSurroundDelay;
+-
+- if (tempDelay1 >= 0) {
+- hDel->nSurroundAnalysisBuffer = tempDelay1;
+- hDel->nArbDmxAnalysisBuffer = 0;
+- } else {
+- hDel->nSurroundAnalysisBuffer = 0;
+- hDel->nArbDmxAnalysisBuffer = -tempDelay1;
+- }
+-
+- tempDelay1 = nEncoderWinDelay + hDel->config.nSurroundDelay +
+- hDel->nSurroundAnalysisBuffer +
+- nEncoderAnDelay; /*Surround Path*/
+- tempDelay2 = nEncoderWinDelay + hDel->config.nArbDmxDelay +
+- hDel->nArbDmxAnalysisBuffer +
+- nEncoderAnDelay; /* ArbDmx Compare Path */
+- tempDelay3 = hDel->config.nArbDmxDelay + hDel->config.nLimiterDelay +
+- hDel->config.nCoreCoderDelay +
+- hDel->config.nSacTimeAlignment +
+- nDecoderAnDelay; /* ArbDmx Passthrough*/
+-
+- tempDelay12 =
+- FDKmax(nResidualCoderFrameDelay, nArbDmxResidualCoderFrameDelay) *
+- hDel->config.nFrameLen;
+- tempDelay12 += hDel->config.nSacStreamMuxDelay;
+-
+- if (tempDelay1 > tempDelay2) {
+- tempDelay12 += tempDelay1;
+- } else {
+- tempDelay12 += tempDelay2;
+- }
+-
+- if (tempDelay3 > tempDelay12) {
+- if (hDel->config.bMinimizeDelay > 0) {
+- hDel->nBitstreamFrameBuffer =
+- (tempDelay3 - tempDelay12) / hDel->config.nFrameLen; /*floor*/
+- hDel->nOutputAudioBuffer = 0;
+- hDel->nSurroundAnalysisBuffer +=
+- (tempDelay3 - tempDelay12 -
+- (hDel->nBitstreamFrameBuffer * hDel->config.nFrameLen));
+- hDel->nArbDmxAnalysisBuffer +=
+- (tempDelay3 - tempDelay12 -
+- (hDel->nBitstreamFrameBuffer * hDel->config.nFrameLen));
+- } else {
+- hDel->nBitstreamFrameBuffer =
+- ((tempDelay3 - tempDelay12) + hDel->config.nFrameLen - 1) /
+- hDel->config.nFrameLen;
+- hDel->nOutputAudioBuffer =
+- hDel->nBitstreamFrameBuffer * hDel->config.nFrameLen +
+- tempDelay12 - tempDelay3;
+- }
+- } else {
+- hDel->nBitstreamFrameBuffer = 0;
+- hDel->nOutputAudioBuffer = tempDelay12 - tempDelay3;
+- }
+-
+- if (hDel->config.bDmxAlign > 0) {
+- int tempDelay = hDel->config.nArbDmxDelay + hDel->nOutputAudioBuffer +
+- hDel->config.nLimiterDelay +
+- hDel->config.nCoreCoderDelay;
+- hDel->nDiscardOutFrames =
+- (tempDelay + hDel->config.nFrameLen - 1) / hDel->config.nFrameLen;
+- hDel->nDmxAlignBuffer =
+- hDel->nDiscardOutFrames * hDel->config.nFrameLen - tempDelay;
+- } else {
+- hDel->nDiscardOutFrames = 0;
+- hDel->nDmxAlignBuffer = 0;
+- }
+-
+- /* Output: Info-Variables */
+- hDel->nInfoDmxDelay = hDel->config.nArbDmxDelay +
+- hDel->nOutputAudioBuffer +
+- hDel->config.nLimiterDelay;
+- hDel->nInfoCodecDelay =
+- hDel->nInfoDmxDelay + hDel->config.nCoreCoderDelay +
+- hDel->config.nSacTimeAlignment + nDecoderAnDelay + nDecoderSynDelay;
+- hDel->nInfoDecoderDelay = nDecoderAnDelay + nDecoderSynDelay;
+-
+- } /* ArbitraryDmx or TdDmx on */
+-
+- /* Additonal Variables needed for Computation Issues */
+- hDel->nBitstreamFrameBufferSize = hDel->nBitstreamFrameBuffer + 1;
+- }
+-
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR assignParameterInRange(
+- const INT startRange, /* including startRange */
+- const INT stopRange, /* including stopRange */
+- const INT value, /* value to write*/
+- INT *const ptr /* destination pointer*/
+-) {
+- FDK_SACENC_ERROR error = SACENC_INVALID_CONFIG;
+-
+- if ((startRange <= value) && (value <= stopRange)) {
+- *ptr = value;
+- error = SACENC_OK;
+- }
+-
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetDmxAlign(HANDLE_DELAY hDelay,
+- const INT bDmxAlignIn) {
+- return (assignParameterInRange(0, 1, bDmxAlignIn, &hDelay->config.bDmxAlign));
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetTimeDomDmx(HANDLE_DELAY hDelay,
+- const INT bTimeDomDmxIn) {
+- return (
+- assignParameterInRange(0, 1, bTimeDomDmxIn, &hDelay->config.bTimeDomDmx));
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetSacTimeAlignmentDynamicOut(
+- HANDLE_DELAY hDelay, const INT bSacTimeAlignmentDynamicOutIn) {
+- return (assignParameterInRange(0, 1, bSacTimeAlignmentDynamicOutIn,
+- &hDelay->config.bSacTimeAlignmentDynamicOut));
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetNSacTimeAlignment(
+- HANDLE_DELAY hDelay, const INT nSacTimeAlignmentIn) {
+- return (assignParameterInRange(-32768, 32767, nSacTimeAlignmentIn,
+- &hDelay->config.nSacTimeAlignment));
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetMinimizeDelay(HANDLE_DELAY hDelay,
+- const INT bMinimizeDelay) {
+- return (assignParameterInRange(0, 1, bMinimizeDelay,
+- &hDelay->config.bMinimizeDelay));
+-}
+-
+-INT fdk_sacenc_delay_GetOutputAudioBufferDelay(HANDLE_DELAY hDelay) {
+- return (hDelay->nOutputAudioBuffer);
+-}
+-
+-INT fdk_sacenc_delay_GetSurroundAnalysisBufferDelay(HANDLE_DELAY hDelay) {
+- return (hDelay->nSurroundAnalysisBuffer);
+-}
+-
+-INT fdk_sacenc_delay_GetArbDmxAnalysisBufferDelay(HANDLE_DELAY hDelay) {
+- return (hDelay->nArbDmxAnalysisBuffer);
+-}
+-
+-INT fdk_sacenc_delay_GetBitstreamFrameBufferSize(HANDLE_DELAY hDelay) {
+- return (hDelay->nBitstreamFrameBufferSize);
+-}
+-
+-INT fdk_sacenc_delay_GetDmxAlignBufferDelay(HANDLE_DELAY hDelay) {
+- return (hDelay->nDmxAlignBuffer);
+-}
+-
+-INT fdk_sacenc_delay_GetDiscardOutFrames(HANDLE_DELAY hDelay) {
+- return (hDelay->nDiscardOutFrames);
+-}
+-
+-INT fdk_sacenc_delay_GetInfoDmxDelay(HANDLE_DELAY hDelay) {
+- return (hDelay->nInfoDmxDelay);
+-}
+-
+-INT fdk_sacenc_delay_GetInfoCodecDelay(HANDLE_DELAY hDelay) {
+- return (hDelay->nInfoCodecDelay);
+-}
+-
+-INT fdk_sacenc_delay_GetInfoDecoderDelay(HANDLE_DELAY hDelay) {
+- return (hDelay->nInfoDecoderDelay);
+-}
+diff --git a/libSACenc/src/sacenc_delay.h b/libSACenc/src/sacenc_delay.h
+deleted file mode 100644
+index 38bfbc5..0000000
+--- a/libSACenc/src/sacenc_delay.h
++++ /dev/null
+@@ -1,175 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Christian Goettlinger
+-
+- Description: Encoder Library Interface
+- delay management of the encoder
+-
+-*******************************************************************************/
+-
+-/**************************************************************************/ /**
+- \file
+- ******************************************************************************/
+-#ifndef SACENC_DELAY_H
+-#define SACENC_DELAY_H
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_lib.h"
+-#include "machine_type.h"
+-#include "FDK_matrixCalloc.h"
+-
+-/* Defines *******************************************************************/
+-#define MAX_DELAY_INPUT 1024
+-#define MAX_DELAY_OUTPUT 4096
+-/* bumped from 0 to 5. this should be equal or larger to the dualrate sbr
+- * resampler filter length */
+-#define MAX_DELAY_SURROUND_ANALYSIS 5
+-#define MAX_BITSTREAM_DELAY 1
+-
+-/* Data Types ****************************************************************/
+-typedef struct DELAY *HANDLE_DELAY;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_delay_Open(HANDLE_DELAY *phDelay);
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_Close(HANDLE_DELAY *phDelay);
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_Init(HANDLE_DELAY hDelay, const INT nQmfLen,
+- const INT nFrameLen,
+- const INT nCoreCoderDelay,
+- const INT nSacStreamMuxDelay);
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SubCalulateBufferDelays(HANDLE_DELAY hDel);
+-
+-/* Set Expert Config Parameters */
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetDmxAlign(HANDLE_DELAY hDelay,
+- const INT bDmxAlignIn);
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetTimeDomDmx(HANDLE_DELAY hDelay,
+- const INT bTimeDomDmxIn);
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetSacTimeAlignmentDynamicOut(
+- HANDLE_DELAY hDelay, const INT bSacTimeAlignmentDynamicOutIn);
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetNSacTimeAlignment(
+- HANDLE_DELAY hDelay, const INT nSacTimeAlignmentIn);
+-
+-FDK_SACENC_ERROR fdk_sacenc_delay_SetMinimizeDelay(HANDLE_DELAY hDelay,
+- const INT bMinimizeDelay);
+-
+-/* Get Internal Variables */
+-INT fdk_sacenc_delay_GetOutputAudioBufferDelay(HANDLE_DELAY hDelay);
+-
+-INT fdk_sacenc_delay_GetSurroundAnalysisBufferDelay(HANDLE_DELAY hDelay);
+-
+-INT fdk_sacenc_delay_GetArbDmxAnalysisBufferDelay(HANDLE_DELAY hDelay);
+-
+-INT fdk_sacenc_delay_GetBitstreamFrameBufferSize(HANDLE_DELAY hDelay);
+-
+-INT fdk_sacenc_delay_GetDmxAlignBufferDelay(HANDLE_DELAY hDelay);
+-
+-INT fdk_sacenc_delay_GetDiscardOutFrames(HANDLE_DELAY hDelay);
+-
+-INT fdk_sacenc_delay_GetInfoDmxDelay(HANDLE_DELAY hDelay);
+-
+-INT fdk_sacenc_delay_GetInfoCodecDelay(HANDLE_DELAY hDelay);
+-
+-INT fdk_sacenc_delay_GetInfoDecoderDelay(HANDLE_DELAY hDelay);
+-
+-#endif /* SACENC_DELAY_H */
+diff --git a/libSACenc/src/sacenc_dmx_tdom_enh.cpp b/libSACenc/src/sacenc_dmx_tdom_enh.cpp
+deleted file mode 100644
+index be66c83..0000000
+--- a/libSACenc/src/sacenc_dmx_tdom_enh.cpp
++++ /dev/null
+@@ -1,639 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): M. Luis Valero
+-
+- Description: Enhanced Time Domain Downmix
+-
+-*******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_dmx_tdom_enh.h"
+-
+-#include "FDK_matrixCalloc.h"
+-#include "FDK_trigFcts.h"
+-#include "fixpoint_math.h"
+-
+-/* Defines *******************************************************************/
+-#define PI_FLT 3.1415926535897931f
+-#define ALPHA_FLT 0.0001f
+-
+-#define PI_E (2)
+-#define PI_M (FL2FXCONST_DBL(PI_FLT / (1 << PI_E)))
+-
+-#define ALPHA_E (13)
+-#define ALPHA_M (FL2FXCONST_DBL(ALPHA_FLT * (1 << ALPHA_E)))
+-
+-enum { L = 0, R = 1 };
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_ENHANCED_TIME_DOMAIN_DMX {
+- int maxFramelength;
+-
+- int framelength;
+-
+- FIXP_DBL prev_gain_m[2];
+- INT prev_gain_e;
+- FIXP_DBL prev_H1_m[2];
+- INT prev_H1_e;
+-
+- FIXP_DBL *sinusWindow_m;
+- SCHAR sinusWindow_e;
+-
+- FIXP_DBL prev_Left_m;
+- INT prev_Left_e;
+- FIXP_DBL prev_Right_m;
+- INT prev_Right_e;
+- FIXP_DBL prev_XNrg_m;
+- INT prev_XNrg_e;
+-
+- FIXP_DBL lin_bbCld_weight_m;
+- INT lin_bbCld_weight_e;
+- FIXP_DBL gain_weight_m[2];
+- INT gain_weight_e;
+-
+-} ENHANCED_TIME_DOMAIN_DMX;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-static void calculateRatio(const FIXP_DBL sqrt_linCld_m,
+- const INT sqrt_linCld_e, const FIXP_DBL lin_Cld_m,
+- const INT lin_Cld_e, const FIXP_DBL Icc_m,
+- const INT Icc_e, FIXP_DBL G_m[2], INT *G_e);
+-
+-static void calculateDmxGains(const FIXP_DBL lin_Cld_m, const INT lin_Cld_e,
+- const FIXP_DBL lin_Cld2_m, const INT lin_Cld2_e,
+- const FIXP_DBL Icc_m, const INT Icc_e,
+- const FIXP_DBL G_m[2], const INT G_e,
+- FIXP_DBL H1_m[2], INT *pH1_e);
+-
+-/* Function / Class Definition ***********************************************/
+-static FIXP_DBL invSqrtNorm2(const FIXP_DBL op_m, const INT op_e,
+- INT *const result_e) {
+- FIXP_DBL src_m = op_m;
+- int src_e = op_e;
+-
+- if (src_e & 1) {
+- src_m >>= 1;
+- src_e += 1;
+- }
+-
+- src_m = invSqrtNorm2(src_m, result_e);
+- *result_e = (*result_e) - (src_e >> 1);
+-
+- return src_m;
+-}
+-
+-static FIXP_DBL sqrtFixp(const FIXP_DBL op_m, const INT op_e,
+- INT *const result_e) {
+- FIXP_DBL src_m = op_m;
+- int src_e = op_e;
+-
+- if (src_e & 1) {
+- src_m >>= 1;
+- src_e += 1;
+- }
+-
+- *result_e = (src_e >> 1);
+- return sqrtFixp(src_m);
+-}
+-
+-static FIXP_DBL fixpAdd(const FIXP_DBL src1_m, const INT src1_e,
+- const FIXP_DBL src2_m, const INT src2_e,
+- INT *const dst_e) {
+- FIXP_DBL dst_m;
+-
+- if (src1_m == FL2FXCONST_DBL(0.f)) {
+- *dst_e = src2_e;
+- dst_m = src2_m;
+- } else if (src2_m == FL2FXCONST_DBL(0.f)) {
+- *dst_e = src1_e;
+- dst_m = src1_m;
+- } else {
+- *dst_e = fixMax(src1_e, src2_e) + 1;
+- dst_m =
+- scaleValue(src1_m, fixMax((src1_e - (*dst_e)), -(DFRACT_BITS - 1))) +
+- scaleValue(src2_m, fixMax((src2_e - (*dst_e)), -(DFRACT_BITS - 1)));
+- }
+- return dst_m;
+-}
+-
+-/**
+- * \brief Sum up fixpoint values with best possible accuracy.
+- *
+- * \param value1 First input value.
+- * \param q1 Scaling factor of first input value.
+- * \param pValue2 Pointer to second input value, will be modified on
+- * return.
+- * \param pQ2 Pointer to second scaling factor, will be modified on
+- * return.
+- *
+- * \return void
+- */
+-static void fixpAddNorm(const FIXP_DBL value1, const INT q1,
+- FIXP_DBL *const pValue2, INT *const pQ2) {
+- const int headroom1 = fNormz(fixp_abs(value1)) - 1;
+- const int headroom2 = fNormz(fixp_abs(*pValue2)) - 1;
+- int resultScale = fixMax(q1 - headroom1, (*pQ2) - headroom2);
+-
+- if ((value1 != FL2FXCONST_DBL(0.f)) && (*pValue2 != FL2FXCONST_DBL(0.f))) {
+- resultScale++;
+- }
+-
+- *pValue2 =
+- scaleValue(value1, q1 - resultScale) +
+- scaleValue(*pValue2, fixMax(-(DFRACT_BITS - 1), ((*pQ2) - resultScale)));
+- *pQ2 = (*pValue2 != (FIXP_DBL)0) ? resultScale : DFRACT_BITS - 1;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_open_enhancedTimeDomainDmx(
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX *phEnhancedTimeDmx, const INT framelength) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX hEnhancedTimeDmx = NULL;
+-
+- if (NULL == phEnhancedTimeDmx) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDK_ALLOCATE_MEMORY_1D(hEnhancedTimeDmx, 1, ENHANCED_TIME_DOMAIN_DMX);
+- FDK_ALLOCATE_MEMORY_1D(hEnhancedTimeDmx->sinusWindow_m, 1 + framelength,
+- FIXP_DBL);
+- hEnhancedTimeDmx->maxFramelength = framelength;
+- *phEnhancedTimeDmx = hEnhancedTimeDmx;
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_close_enhancedTimeDomainDmx(&hEnhancedTimeDmx);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_init_enhancedTimeDomainDmx(
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX hEnhancedTimeDmx,
+- const FIXP_DBL *const pInputGain_m, const INT inputGain_e,
+- const FIXP_DBL outputGain_m, const INT outputGain_e,
+- const INT framelength) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (hEnhancedTimeDmx == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int smp;
+- if (framelength > hEnhancedTimeDmx->maxFramelength) {
+- error = SACENC_INIT_ERROR;
+- goto bail;
+- }
+-
+- hEnhancedTimeDmx->framelength = framelength;
+-
+- INT deltax_e;
+- FIXP_DBL deltax_m;
+-
+- deltax_m = fDivNormHighPrec(
+- PI_M, (FIXP_DBL)(2 * hEnhancedTimeDmx->framelength), &deltax_e);
+- deltax_m = scaleValue(deltax_m, PI_E + deltax_e - (DFRACT_BITS - 1) - 1);
+- deltax_e = 1;
+-
+- for (smp = 0; smp < hEnhancedTimeDmx->framelength + 1; smp++) {
+- hEnhancedTimeDmx->sinusWindow_m[smp] =
+- fMult(ALPHA_M, fPow2(fixp_sin(smp * deltax_m, deltax_e)));
+- }
+- hEnhancedTimeDmx->sinusWindow_e = -ALPHA_E;
+-
+- hEnhancedTimeDmx->prev_Left_m = hEnhancedTimeDmx->prev_Right_m =
+- hEnhancedTimeDmx->prev_XNrg_m = FL2FXCONST_DBL(0.f);
+- hEnhancedTimeDmx->prev_Left_e = hEnhancedTimeDmx->prev_Right_e =
+- hEnhancedTimeDmx->prev_XNrg_e = DFRACT_BITS - 1;
+-
+- hEnhancedTimeDmx->lin_bbCld_weight_m =
+- fDivNormHighPrec(fPow2(pInputGain_m[L]), fPow2(pInputGain_m[R]),
+- &hEnhancedTimeDmx->lin_bbCld_weight_e);
+-
+- hEnhancedTimeDmx->gain_weight_m[L] = fMult(pInputGain_m[L], outputGain_m);
+- hEnhancedTimeDmx->gain_weight_m[R] = fMult(pInputGain_m[R], outputGain_m);
+- hEnhancedTimeDmx->gain_weight_e =
+- -fNorm(fixMax(hEnhancedTimeDmx->gain_weight_m[L],
+- hEnhancedTimeDmx->gain_weight_m[R]));
+-
+- hEnhancedTimeDmx->gain_weight_m[L] = scaleValue(
+- hEnhancedTimeDmx->gain_weight_m[L], -hEnhancedTimeDmx->gain_weight_e);
+- hEnhancedTimeDmx->gain_weight_m[R] = scaleValue(
+- hEnhancedTimeDmx->gain_weight_m[R], -hEnhancedTimeDmx->gain_weight_e);
+- hEnhancedTimeDmx->gain_weight_e += inputGain_e + outputGain_e;
+-
+- hEnhancedTimeDmx->prev_gain_m[L] = hEnhancedTimeDmx->gain_weight_m[L] >> 1;
+- hEnhancedTimeDmx->prev_gain_m[R] = hEnhancedTimeDmx->gain_weight_m[R] >> 1;
+- hEnhancedTimeDmx->prev_gain_e = hEnhancedTimeDmx->gain_weight_e + 1;
+-
+- hEnhancedTimeDmx->prev_H1_m[L] =
+- scaleValue(hEnhancedTimeDmx->gain_weight_m[L], -4);
+- hEnhancedTimeDmx->prev_H1_m[R] =
+- scaleValue(hEnhancedTimeDmx->gain_weight_m[R], -4);
+- hEnhancedTimeDmx->prev_H1_e = 2 + 2 + hEnhancedTimeDmx->gain_weight_e;
+- }
+-bail:
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_apply_enhancedTimeDomainDmx(
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX hEnhancedTimeDmx,
+- const INT_PCM *const *const inputTime, INT_PCM *const outputTimeDmx,
+- const INT InputDelay) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((NULL == hEnhancedTimeDmx) || (NULL == inputTime) ||
+- (NULL == inputTime[L]) || (NULL == inputTime[R]) ||
+- (NULL == outputTimeDmx)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int smp;
+- FIXP_DBL lin_bbCld_m, lin_Cld_m, bbCorr_m, sqrt_linCld_m, G_m[2], H1_m[2],
+- gainLeft_m, gainRight_m;
+- FIXP_DBL bbNrgLeft_m, bbNrgRight_m, bbXNrg_m, nrgLeft_m, nrgRight_m, nrgX_m;
+- INT lin_bbCld_e, lin_Cld_e, bbCorr_e, sqrt_linCld_e, G_e, H1_e;
+- INT bbNrgLeft_e, bbNrgRight_e, bbXNrg_e, nrgLeft_e, nrgRight_e, nrgX_e;
+-
+- /* Increase energy time resolution with shorter processing blocks. 128 is an
+- * empiric value. */
+- const int granuleLength = fixMin(128, hEnhancedTimeDmx->framelength);
+- int granuleShift =
+- (granuleLength > 1)
+- ? ((DFRACT_BITS - 1) - fNorm((FIXP_DBL)(granuleLength - 1)))
+- : 0;
+- granuleShift = fixMax(
+- 3, granuleShift +
+- 1); /* one bit more headroom for worst case accumulation */
+-
+- smp = 0;
+-
+- /* Prevent division by zero. */
+- bbNrgLeft_m = bbNrgRight_m = bbXNrg_m = (FIXP_DBL)(1);
+- bbNrgLeft_e = bbNrgRight_e = bbXNrg_e = 0;
+-
+- do {
+- const int offset = smp;
+- FIXP_DBL partialL, partialR, partialX;
+- partialL = partialR = partialX = FL2FXCONST_DBL(0.f);
+-
+- int in_margin = FDKmin(
+- getScalefactorPCM(
+- &inputTime[L][offset],
+- fixMin(offset + granuleLength, hEnhancedTimeDmx->framelength) -
+- offset,
+- 1),
+- getScalefactorPCM(
+- &inputTime[R][offset],
+- fixMin(offset + granuleLength, hEnhancedTimeDmx->framelength) -
+- offset,
+- 1));
+-
+- /* partial energy */
+- for (smp = offset;
+- smp < fixMin(offset + granuleLength, hEnhancedTimeDmx->framelength);
+- smp++) {
+- FIXP_PCM inputL =
+- scaleValue((FIXP_PCM)inputTime[L][smp], in_margin - 1);
+- FIXP_PCM inputR =
+- scaleValue((FIXP_PCM)inputTime[R][smp], in_margin - 1);
+-
+- partialL += fPow2Div2(inputL) >> (granuleShift - 3);
+- partialR += fPow2Div2(inputR) >> (granuleShift - 3);
+- partialX += fMultDiv2(inputL, inputR) >> (granuleShift - 3);
+- }
+-
+- fixpAddNorm(partialL, granuleShift - 2 * in_margin, &bbNrgLeft_m,
+- &bbNrgLeft_e);
+- fixpAddNorm(partialR, granuleShift - 2 * in_margin, &bbNrgRight_m,
+- &bbNrgRight_e);
+- fixpAddNorm(partialX, granuleShift - 2 * in_margin, &bbXNrg_m, &bbXNrg_e);
+- } while (smp < hEnhancedTimeDmx->framelength);
+-
+- nrgLeft_m =
+- fixpAdd(hEnhancedTimeDmx->prev_Left_m, hEnhancedTimeDmx->prev_Left_e,
+- bbNrgLeft_m, bbNrgLeft_e, &nrgLeft_e);
+- nrgRight_m =
+- fixpAdd(hEnhancedTimeDmx->prev_Right_m, hEnhancedTimeDmx->prev_Right_e,
+- bbNrgRight_m, bbNrgRight_e, &nrgRight_e);
+- nrgX_m =
+- fixpAdd(hEnhancedTimeDmx->prev_XNrg_m, hEnhancedTimeDmx->prev_XNrg_e,
+- bbXNrg_m, bbXNrg_e, &nrgX_e);
+-
+- lin_bbCld_m = fMult(hEnhancedTimeDmx->lin_bbCld_weight_m,
+- fDivNorm(nrgLeft_m, nrgRight_m, &lin_bbCld_e));
+- lin_bbCld_e +=
+- hEnhancedTimeDmx->lin_bbCld_weight_e + nrgLeft_e - nrgRight_e;
+-
+- bbCorr_m = fMult(nrgX_m, invSqrtNorm2(fMult(nrgLeft_m, nrgRight_m),
+- nrgLeft_e + nrgRight_e, &bbCorr_e));
+- bbCorr_e += nrgX_e;
+-
+- hEnhancedTimeDmx->prev_Left_m = bbNrgLeft_m;
+- hEnhancedTimeDmx->prev_Left_e = bbNrgLeft_e;
+- hEnhancedTimeDmx->prev_Right_m = bbNrgRight_m;
+- hEnhancedTimeDmx->prev_Right_e = bbNrgRight_e;
+- hEnhancedTimeDmx->prev_XNrg_m = bbXNrg_m;
+- hEnhancedTimeDmx->prev_XNrg_e = bbXNrg_e;
+-
+- /*
+- bbCld = 10.f*log10(lin_bbCld)
+-
+- lin_Cld = pow(10,bbCld/20)
+- = pow(10,10.f*log10(lin_bbCld)/20.f)
+- = sqrt(lin_bbCld)
+-
+- lin_Cld2 = lin_Cld*lin_Cld
+- = sqrt(lin_bbCld)*sqrt(lin_bbCld)
+- = lin_bbCld
+- */
+- lin_Cld_m = sqrtFixp(lin_bbCld_m, lin_bbCld_e, &lin_Cld_e);
+- sqrt_linCld_m = sqrtFixp(lin_Cld_m, lin_Cld_e, &sqrt_linCld_e);
+-
+- /*calculate how much right and how much left signal, to avoid signal
+- * cancellations*/
+- calculateRatio(sqrt_linCld_m, sqrt_linCld_e, lin_Cld_m, lin_Cld_e, bbCorr_m,
+- bbCorr_e, G_m, &G_e);
+-
+- /*calculate downmix gains*/
+- calculateDmxGains(lin_Cld_m, lin_Cld_e, lin_bbCld_m, lin_bbCld_e, bbCorr_m,
+- bbCorr_e, G_m, G_e, H1_m, &H1_e);
+-
+- /*adapt output gains*/
+- H1_m[L] = fMult(H1_m[L], hEnhancedTimeDmx->gain_weight_m[L]);
+- H1_m[R] = fMult(H1_m[R], hEnhancedTimeDmx->gain_weight_m[R]);
+- H1_e += hEnhancedTimeDmx->gain_weight_e;
+-
+- gainLeft_m = hEnhancedTimeDmx->prev_gain_m[L];
+- gainRight_m = hEnhancedTimeDmx->prev_gain_m[R];
+-
+- INT intermediate_gain_e =
+- +hEnhancedTimeDmx->sinusWindow_e + H1_e - hEnhancedTimeDmx->prev_gain_e;
+-
+- for (smp = 0; smp < hEnhancedTimeDmx->framelength; smp++) {
+- const INT N = hEnhancedTimeDmx->framelength;
+- FIXP_DBL intermediate_gainLeft_m, intermediate_gainRight_m, tmp;
+-
+- intermediate_gainLeft_m =
+- scaleValue((fMult(hEnhancedTimeDmx->sinusWindow_m[smp], H1_m[L]) +
+- fMult(hEnhancedTimeDmx->sinusWindow_m[N - smp],
+- hEnhancedTimeDmx->prev_H1_m[L])),
+- intermediate_gain_e);
+- intermediate_gainRight_m =
+- scaleValue((fMult(hEnhancedTimeDmx->sinusWindow_m[smp], H1_m[R]) +
+- fMult(hEnhancedTimeDmx->sinusWindow_m[N - smp],
+- hEnhancedTimeDmx->prev_H1_m[R])),
+- intermediate_gain_e);
+-
+- gainLeft_m = intermediate_gainLeft_m +
+- fMult(FL2FXCONST_DBL(1.f - ALPHA_FLT), gainLeft_m);
+- gainRight_m = intermediate_gainRight_m +
+- fMult(FL2FXCONST_DBL(1.f - ALPHA_FLT), gainRight_m);
+-
+- tmp = fMultDiv2(gainLeft_m, (FIXP_PCM)inputTime[L][smp + InputDelay]) +
+- fMultDiv2(gainRight_m, (FIXP_PCM)inputTime[R][smp + InputDelay]);
+- outputTimeDmx[smp] = (INT_PCM)SATURATE_SHIFT(
+- tmp,
+- -(hEnhancedTimeDmx->prev_gain_e + 1 - (DFRACT_BITS - SAMPLE_BITS)),
+- SAMPLE_BITS);
+- }
+-
+- hEnhancedTimeDmx->prev_gain_m[L] = gainLeft_m;
+- hEnhancedTimeDmx->prev_gain_m[R] = gainRight_m;
+-
+- hEnhancedTimeDmx->prev_H1_m[L] = H1_m[L];
+- hEnhancedTimeDmx->prev_H1_m[R] = H1_m[R];
+- hEnhancedTimeDmx->prev_H1_e = H1_e;
+- }
+-
+- return error;
+-}
+-
+-static void calculateRatio(const FIXP_DBL sqrt_linCld_m,
+- const INT sqrt_linCld_e, const FIXP_DBL lin_Cld_m,
+- const INT lin_Cld_e, const FIXP_DBL Icc_m,
+- const INT Icc_e, FIXP_DBL G_m[2], INT *G_e) {
+-#define G_SCALE_FACTOR (2)
+-
+- if (Icc_m >= FL2FXCONST_DBL(0.f)) {
+- G_m[0] = G_m[1] = FL2FXCONST_DBL(1.f / (float)(1 << G_SCALE_FACTOR));
+- G_e[0] = G_SCALE_FACTOR;
+- } else {
+- const FIXP_DBL max_gain_factor =
+- FL2FXCONST_DBL(2.f / (float)(1 << G_SCALE_FACTOR));
+- FIXP_DBL tmp1_m, tmp2_m, numerator_m, denominator_m, r_m, r4_m, q;
+- INT tmp1_e, tmp2_e, numerator_e, denominator_e, r_e, r4_e;
+-
+- /* r = (lin_Cld + 1 + 2*Icc*sqrt_linCld) / (lin_Cld + 1 -
+- * 2*Icc*sqrt_linCld) = (tmp1 + tmp2) / (tmp1 - tmp2)
+- */
+- tmp1_m =
+- fixpAdd(lin_Cld_m, lin_Cld_e, FL2FXCONST_DBL(1.f / 2.f), 1, &tmp1_e);
+-
+- tmp2_m = fMult(Icc_m, sqrt_linCld_m);
+- tmp2_e = 1 + Icc_e + sqrt_linCld_e;
+- numerator_m = fixpAdd(tmp1_m, tmp1_e, tmp2_m, tmp2_e, &numerator_e);
+- denominator_m = fixpAdd(tmp1_m, tmp1_e, -tmp2_m, tmp2_e, &denominator_e);
+-
+- if ((numerator_m > FL2FXCONST_DBL(0.f)) &&
+- (denominator_m > FL2FXCONST_DBL(0.f))) {
+- r_m = fDivNorm(numerator_m, denominator_m, &r_e);
+- r_e += numerator_e - denominator_e;
+-
+- /* r_4 = sqrt( sqrt( r ) ) */
+- r4_m = sqrtFixp(r_m, r_e, &r4_e);
+- r4_m = sqrtFixp(r4_m, r4_e, &r4_e);
+-
+- r4_e -= G_SCALE_FACTOR;
+-
+- /* q = min(r4_m, max_gain_factor) */
+- q = ((r4_e >= 0) && (r4_m >= (max_gain_factor >> r4_e)))
+- ? max_gain_factor
+- : scaleValue(r4_m, r4_e);
+- } else {
+- q = FL2FXCONST_DBL(0.f);
+- }
+-
+- G_m[0] = max_gain_factor - q;
+- G_m[1] = q;
+-
+- *G_e = G_SCALE_FACTOR;
+- }
+-}
+-
+-static void calculateDmxGains(const FIXP_DBL lin_Cld_m, const INT lin_Cld_e,
+- const FIXP_DBL lin_Cld2_m, const INT lin_Cld2_e,
+- const FIXP_DBL Icc_m, const INT Icc_e,
+- const FIXP_DBL G_m[2], const INT G_e,
+- FIXP_DBL H1_m[2], INT *pH1_e) {
+-#define H1_SCALE_FACTOR (2)
+- const FIXP_DBL max_gain_factor =
+- FL2FXCONST_DBL(2.f / (float)(1 << H1_SCALE_FACTOR));
+-
+- FIXP_DBL nrgRight_m, nrgLeft_m, crossNrg_m, inv_weight_num_m,
+- inv_weight_denom_m, inverse_weight_m, inverse_weight_limited;
+- INT nrgRight_e, nrgLeft_e, crossNrg_e, inv_weight_num_e, inv_weight_denom_e,
+- inverse_weight_e;
+-
+- /* nrgRight = sqrt(1/(lin_Cld2 + 1) */
+- nrgRight_m = fixpAdd(lin_Cld2_m, lin_Cld2_e, FL2FXCONST_DBL(1.f / 2.f), 1,
+- &nrgRight_e);
+- nrgRight_m = invSqrtNorm2(nrgRight_m, nrgRight_e, &nrgRight_e);
+-
+- /* nrgLeft = lin_Cld * nrgRight */
+- nrgLeft_m = fMult(lin_Cld_m, nrgRight_m);
+- nrgLeft_e = lin_Cld_e + nrgRight_e;
+-
+- /* crossNrg = sqrt(nrgLeft*nrgRight) */
+- crossNrg_m = sqrtFixp(fMult(nrgLeft_m, nrgRight_m), nrgLeft_e + nrgRight_e,
+- &crossNrg_e);
+-
+- /* inverse_weight = sqrt((nrgLeft + nrgRight) / ( (G[0]*G[0]*nrgLeft) +
+- * (G[1]*G[1]*nrgRight) + 2*G[0]*G[1]*Icc*crossNrg)) = sqrt(inv_weight_num /
+- * inv_weight_denom)
+- */
+- inv_weight_num_m =
+- fixpAdd(nrgRight_m, nrgRight_e, nrgLeft_m, nrgLeft_e, &inv_weight_num_e);
+-
+- inv_weight_denom_m =
+- fixpAdd(fMult(fPow2(G_m[0]), nrgLeft_m), 2 * G_e + nrgLeft_e,
+- fMult(fPow2(G_m[1]), nrgRight_m), 2 * G_e + nrgRight_e,
+- &inv_weight_denom_e);
+-
+- inv_weight_denom_m =
+- fixpAdd(fMult(fMult(fMult(G_m[0], G_m[1]), crossNrg_m), Icc_m),
+- 1 + 2 * G_e + crossNrg_e + Icc_e, inv_weight_denom_m,
+- inv_weight_denom_e, &inv_weight_denom_e);
+-
+- if (inv_weight_denom_m > FL2FXCONST_DBL(0.f)) {
+- inverse_weight_m =
+- fDivNorm(inv_weight_num_m, inv_weight_denom_m, &inverse_weight_e);
+- inverse_weight_m =
+- sqrtFixp(inverse_weight_m,
+- inverse_weight_e + inv_weight_num_e - inv_weight_denom_e,
+- &inverse_weight_e);
+- inverse_weight_e -= H1_SCALE_FACTOR;
+-
+- /* inverse_weight_limited = min(max_gain_factor, inverse_weight) */
+- inverse_weight_limited =
+- ((inverse_weight_e >= 0) &&
+- (inverse_weight_m >= (max_gain_factor >> inverse_weight_e)))
+- ? max_gain_factor
+- : scaleValue(inverse_weight_m, inverse_weight_e);
+- } else {
+- inverse_weight_limited = max_gain_factor;
+- }
+-
+- H1_m[0] = fMult(G_m[0], inverse_weight_limited);
+- H1_m[1] = fMult(G_m[1], inverse_weight_limited);
+-
+- *pH1_e = G_e + H1_SCALE_FACTOR;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_close_enhancedTimeDomainDmx(
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX *phEnhancedTimeDmx) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (phEnhancedTimeDmx == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- if (*phEnhancedTimeDmx != NULL) {
+- if ((*phEnhancedTimeDmx)->sinusWindow_m != NULL) {
+- FDK_FREE_MEMORY_1D((*phEnhancedTimeDmx)->sinusWindow_m);
+- }
+- FDK_FREE_MEMORY_1D(*phEnhancedTimeDmx);
+- }
+- }
+- return error;
+-}
+diff --git a/libSACenc/src/sacenc_dmx_tdom_enh.h b/libSACenc/src/sacenc_dmx_tdom_enh.h
+deleted file mode 100644
+index 0b39911..0000000
+--- a/libSACenc/src/sacenc_dmx_tdom_enh.h
++++ /dev/null
+@@ -1,134 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): M. Luis Valero
+-
+- Description: Enhanced Time Domain Downmix
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_DMX_TDOM_ENH_H
+-#define SACENC_DMX_TDOM_ENH_H
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_lib.h"
+-#include "common_fix.h"
+-
+-/* Defines *******************************************************************/
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_ENHANCED_TIME_DOMAIN_DMX *HANDLE_ENHANCED_TIME_DOMAIN_DMX;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_open_enhancedTimeDomainDmx(
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX *hEnhancedTimeDmx, const INT framelength);
+-
+-FDK_SACENC_ERROR fdk_sacenc_init_enhancedTimeDomainDmx(
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX hEnhancedTimeDmx,
+- const FIXP_DBL *const pInputGain_m, const INT inputGain_e,
+- const FIXP_DBL outputGain_m, const INT outputGain_e, const INT framelength);
+-
+-FDK_SACENC_ERROR fdk_sacenc_apply_enhancedTimeDomainDmx(
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX hEnhancedTimeDmx,
+- const INT_PCM *const *const inputTime, INT_PCM *const outputTimeDmx,
+- const INT InputDelay);
+-
+-FDK_SACENC_ERROR fdk_sacenc_close_enhancedTimeDomainDmx(
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX *hEnhancedTimeDmx);
+-
+-#endif /* SACENC_DMX_TDOM_ENH_H */
+diff --git a/libSACenc/src/sacenc_filter.cpp b/libSACenc/src/sacenc_filter.cpp
+deleted file mode 100644
+index 79f0797..0000000
+--- a/libSACenc/src/sacenc_filter.cpp
++++ /dev/null
+@@ -1,207 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): M. Multrus
+-
+- Description: Encoder Library
+- Filter functions
+-
+-*******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_filter.h"
+-
+-/* Defines *******************************************************************/
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_DC_FILTER {
+- FIXP_DBL c__FDK;
+- FIXP_DBL state__FDK;
+-
+-} DC_FILTER;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_createDCFilter(HANDLE_DC_FILTER *hDCFilter) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hDCFilter) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDK_ALLOCATE_MEMORY_1D(*hDCFilter, 1, DC_FILTER);
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_destroyDCFilter(hDCFilter);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_initDCFilter(HANDLE_DC_FILTER hDCFilter,
+- const UINT sampleRate) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- FIXP_DBL expC;
+- int s;
+-
+- /* Conversion for use of CalcInvLdData: e^x = 2^(x*log10(e)/log10(2) =
+- CalcInvLdData(x*log10(e)/log10(2)/64.0) 1.44269504089 = log10(e)/log10(2)
+- 0.5 = scale constant value with 1 Bits
+- */
+- expC = fDivNormHighPrec((FIXP_DBL)20, (FIXP_DBL)sampleRate, &s);
+- expC = fMultDiv2(FL2FXCONST_DBL(-1.44269504089 * 0.5), expC) >>
+- (LD_DATA_SHIFT - 1 - 1);
+-
+- if (s < 0)
+- expC = expC >> (-s);
+- else
+- expC = expC << (s);
+-
+- expC = CalcInvLdData(expC);
+-
+- hDCFilter->c__FDK = expC;
+- hDCFilter->state__FDK = FL2FXCONST_DBL(0.0f);
+-
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_destroyDCFilter(HANDLE_DC_FILTER *hDCFilter) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hDCFilter != NULL) && (*hDCFilter != NULL)) {
+- FDKfree(*hDCFilter);
+-
+- *hDCFilter = NULL;
+- }
+-
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_applyDCFilter(HANDLE_DC_FILTER hDCFilter,
+- const INT_PCM *const signalIn,
+- INT_PCM *const signalOut,
+- const INT signalLength) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hDCFilter == NULL) || (signalIn == NULL) || (signalOut == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- const INT_PCM *const x = signalIn;
+- INT_PCM *const y = signalOut;
+- const FIXP_DBL c = hDCFilter->c__FDK;
+- FIXP_DBL *const state = &hDCFilter->state__FDK;
+- int i;
+- FIXP_DBL x0, x1, y1;
+-
+- x1 = x0 = FX_PCM2FX_DBL(x[0]) >> DC_FILTER_SF;
+- y1 = x0 + (*state);
+-
+- for (i = 1; i < signalLength; i++) {
+- x0 = FX_PCM2FX_DBL(x[i]) >> DC_FILTER_SF;
+- y[i - 1] = FX_DBL2FX_PCM(y1);
+- y1 = x0 - x1 + fMult(c, y1);
+- x1 = x0;
+- }
+-
+- *state = fMult(c, y1) - x1;
+- y[i - 1] = FX_DBL2FX_PCM(y1);
+- }
+-
+- return error;
+-}
+diff --git a/libSACenc/src/sacenc_filter.h b/libSACenc/src/sacenc_filter.h
+deleted file mode 100644
+index 10e3abd..0000000
+--- a/libSACenc/src/sacenc_filter.h
++++ /dev/null
+@@ -1,133 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): M. Multrus
+-
+- Description: Encoder Library Interface
+- Filter functions
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_FILTER_H
+-#define SACENC_FILTER_H
+-
+-/* Includes ******************************************************************/
+-#include "common_fix.h"
+-#include "sacenc_lib.h"
+-#include "FDK_matrixCalloc.h"
+-
+-/* Defines *******************************************************************/
+-#define DC_FILTER_SF 1
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_DC_FILTER *HANDLE_DC_FILTER;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_createDCFilter(HANDLE_DC_FILTER *hDCFilter);
+-
+-FDK_SACENC_ERROR fdk_sacenc_initDCFilter(HANDLE_DC_FILTER hDCFilter,
+- const UINT sampleRate);
+-
+-FDK_SACENC_ERROR fdk_sacenc_destroyDCFilter(HANDLE_DC_FILTER *hDCFilter);
+-
+-FDK_SACENC_ERROR fdk_sacenc_applyDCFilter(HANDLE_DC_FILTER hDCFilter,
+- const INT_PCM *const signalIn,
+- INT_PCM *const signalOut,
+- const INT signalLength);
+-
+-#endif /* SACENC_FILTER_H */
+diff --git a/libSACenc/src/sacenc_framewindowing.cpp b/libSACenc/src/sacenc_framewindowing.cpp
+deleted file mode 100644
+index 15f0f0a..0000000
+--- a/libSACenc/src/sacenc_framewindowing.cpp
++++ /dev/null
+@@ -1,568 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Max Neuendorf
+-
+- Description: Encoder Library Interface
+- Get windows for framing
+-
+-*******************************************************************************/
+-
+-/**************************************************************************/ /**
+- \file
+- Description of file contents
+- ******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_framewindowing.h"
+-#include "sacenc_vectorfunctions.h"
+-
+-/* Defines *******************************************************************/
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_FRAMEWINDOW {
+- INT nTimeSlotsMax;
+- INT bFrameKeep;
+- INT startSlope;
+- INT stopSlope;
+- INT startRect;
+- INT stopRect;
+-
+- INT taperAnaLen;
+- INT taperSynLen;
+- FIXP_WIN pTaperAna__FDK[MAX_TIME_SLOTS];
+- FIXP_WIN pTaperSyn__FDK[MAX_TIME_SLOTS];
+-
+-} FRAMEWINDOW;
+-
+-typedef enum {
+- FIX_INVALID = -1,
+- FIX_RECT_SMOOTH = 0,
+- FIX_SMOOTH_RECT = 1,
+- FIX_LARGE_SMOOTH = 2,
+- FIX_RECT_TRIANG = 3
+-
+-} FIX_TYPE;
+-
+-typedef enum {
+- VAR_INVALID = -1,
+- VAR_HOLD = 0,
+- VAR_ISOLATE = 1
+-
+-} VAR_TYPE;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-static void calcTaperWin(FIXP_WIN *pTaperWin, INT timeSlots) {
+- FIXP_DBL x;
+- int i, scale;
+-
+- for (i = 0; i < timeSlots; i++) {
+- x = fDivNormHighPrec((FIXP_DBL)i, (FIXP_DBL)timeSlots, &scale);
+-
+- if (scale < 0) {
+- pTaperWin[i] = FX_DBL2FX_WIN(x >> (-scale));
+- } else {
+- pTaperWin[i] = FX_DBL2FX_WIN(x << (scale));
+- }
+- }
+- pTaperWin[timeSlots] = FX_DBL2FX_WIN((FIXP_DBL)MAXVAL_DBL);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_frameWindow_Create(
+- HANDLE_FRAMEWINDOW *phFrameWindow) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == phFrameWindow) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* Memory Allocation */
+- FDK_ALLOCATE_MEMORY_1D(*phFrameWindow, 1, FRAMEWINDOW);
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_frameWindow_Destroy(phFrameWindow);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_frameWindow_Init(
+- HANDLE_FRAMEWINDOW hFrameWindow,
+- const FRAMEWINDOW_CONFIG *const pFrameWindowConfig) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hFrameWindow == NULL) || (pFrameWindowConfig == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else if (pFrameWindowConfig->nTimeSlotsMax < 0) {
+- error = SACENC_INIT_ERROR;
+- } else {
+- int ts;
+- hFrameWindow->bFrameKeep = pFrameWindowConfig->bFrameKeep;
+- hFrameWindow->nTimeSlotsMax = pFrameWindowConfig->nTimeSlotsMax;
+-
+- FIXP_WIN winMaxVal = FX_DBL2FX_WIN((FIXP_DBL)MAXVAL_DBL);
+- int timeSlots = pFrameWindowConfig->nTimeSlotsMax;
+- {
+- hFrameWindow->startSlope = 0;
+- hFrameWindow->stopSlope = ((3 * timeSlots) >> 1) - 1;
+- hFrameWindow->startRect = timeSlots >> 1;
+- hFrameWindow->stopRect = timeSlots;
+- calcTaperWin(hFrameWindow->pTaperSyn__FDK, timeSlots >> 1);
+- hFrameWindow->taperSynLen = timeSlots >> 1;
+- }
+-
+- /* Calculate Taper for non-rect. ana. windows */
+- hFrameWindow->taperAnaLen =
+- hFrameWindow->startRect - hFrameWindow->startSlope;
+- for (ts = 0; ts < hFrameWindow->taperAnaLen; ts++) {
+- { hFrameWindow->pTaperAna__FDK[ts] = winMaxVal; }
+- }
+- }
+-
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_frameWindow_Destroy(
+- HANDLE_FRAMEWINDOW *phFrameWindow) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((NULL != phFrameWindow) && (NULL != *phFrameWindow)) {
+- FDKfree(*phFrameWindow);
+- *phFrameWindow = NULL;
+- }
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR FrameWinList_Reset(FRAMEWIN_LIST *const pFrameWinList) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == pFrameWinList) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int k = 0;
+- for (k = 0; k < MAX_NUM_PARAMS; k++) {
+- pFrameWinList->dat[k].slot = -1;
+- pFrameWinList->dat[k].hold = FW_INTP;
+- }
+- pFrameWinList->n = 0;
+- }
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR FrameWindowList_Add(FRAMEWIN_LIST *const pFrameWinList,
+- const INT slot,
+- const FW_SLOTTYPE hold) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == pFrameWinList) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- if (pFrameWinList->n >= MAX_NUM_PARAMS) { /* Place left in List ?*/
+- error = SACENC_PARAM_ERROR;
+- } else if (pFrameWinList->n > 0 &&
+- pFrameWinList->dat[pFrameWinList->n - 1].slot - slot > 0) {
+- error = SACENC_PARAM_ERROR;
+- } else {
+- pFrameWinList->dat[pFrameWinList->n].slot = slot;
+- pFrameWinList->dat[pFrameWinList->n].hold = hold;
+- pFrameWinList->n++;
+- }
+- }
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR FrameWindowList_Remove(
+- FRAMEWIN_LIST *const pFrameWinList, const INT idx) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == pFrameWinList) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int k = 0;
+- if (idx < 0 || idx >= MAX_NUM_PARAMS) {
+- error = SACENC_PARAM_ERROR;
+- } else if (pFrameWinList->n > 0) {
+- if (idx == MAX_NUM_PARAMS - 1) {
+- pFrameWinList->dat[idx].slot = -1;
+- pFrameWinList->dat[idx].hold = FW_INTP;
+- } else {
+- for (k = idx; k < MAX_NUM_PARAMS - 1; k++) {
+- pFrameWinList->dat[k] = pFrameWinList->dat[k + 1];
+- }
+- }
+- pFrameWinList->n--;
+- }
+- }
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR FrameWindowList_Limit(
+- FRAMEWIN_LIST *const pFrameWinList, const INT ll /*lower limit*/,
+- const INT ul /*upper limit*/
+-) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == pFrameWinList) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int k = 0;
+- for (k = 0; k < pFrameWinList->n; k++) {
+- if (pFrameWinList->dat[k].slot < ll || pFrameWinList->dat[k].slot > ul) {
+- FrameWindowList_Remove(pFrameWinList, k);
+- --k;
+- }
+- }
+- }
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_frameWindow_GetWindow(
+- HANDLE_FRAMEWINDOW hFrameWindow, INT tr_pos[MAX_NUM_PARAMS],
+- const INT timeSlots, FRAMINGINFO *const pFramingInfo,
+- FIXP_WIN *pWindowAna__FDK[MAX_NUM_PARAMS],
+- FRAMEWIN_LIST *const pFrameWinList, const INT avoid_keep) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hFrameWindow == NULL) || (tr_pos == NULL) || (pFramingInfo == NULL) ||
+- (pFrameWinList == NULL) || (pWindowAna__FDK == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- const VAR_TYPE varType = VAR_HOLD;
+- const int tranL = 4;
+- int winCnt = 0;
+- int w, ps;
+-
+- int startSlope = hFrameWindow->startSlope;
+- int stopSlope = hFrameWindow->stopSlope;
+- int startRect = hFrameWindow->startRect;
+- int stopRect = hFrameWindow->stopRect;
+- int taperAnaLen = hFrameWindow->taperAnaLen;
+-
+- FIXP_WIN winMaxVal = FX_DBL2FX_WIN((FIXP_DBL)MAXVAL_DBL);
+- FIXP_WIN applyRightWindowGain__FDK[MAX_NUM_PARAMS];
+- FIXP_WIN *pTaperAna__FDK = hFrameWindow->pTaperAna__FDK;
+-
+- /* sanity check */
+- for (ps = 0; ps < MAX_NUM_PARAMS; ps++) {
+- if (pWindowAna__FDK[ps] == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+- }
+-
+- if ((timeSlots > hFrameWindow->nTimeSlotsMax) || (timeSlots < 0)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- /* Reset */
+- if (SACENC_OK != (error = FrameWinList_Reset(pFrameWinList))) goto bail;
+-
+- FDKmemclear(applyRightWindowGain__FDK, sizeof(applyRightWindowGain__FDK));
+-
+- if (tr_pos[0] > -1) { /* Transients in first (left) half? */
+- int p_l = tr_pos[0];
+- winCnt = 0;
+-
+- /* Create Parameter Positions */
+- switch (varType) {
+- case VAR_HOLD:
+- if (SACENC_OK !=
+- (error = FrameWindowList_Add(pFrameWinList, p_l - 1, FW_HOLD)))
+- goto bail;
+- if (SACENC_OK !=
+- (error = FrameWindowList_Add(pFrameWinList, p_l, FW_INTP)))
+- goto bail;
+- break;
+- case VAR_ISOLATE:
+- if (SACENC_OK !=
+- (error = FrameWindowList_Add(pFrameWinList, p_l - 1, FW_HOLD)))
+- goto bail;
+- if (SACENC_OK !=
+- (error = FrameWindowList_Add(pFrameWinList, p_l, FW_INTP)))
+- goto bail;
+- if (SACENC_OK != (error = FrameWindowList_Add(pFrameWinList,
+- p_l + tranL, FW_HOLD)))
+- goto bail;
+- if (SACENC_OK != (error = FrameWindowList_Add(
+- pFrameWinList, p_l + tranL + 1, FW_INTP)))
+- goto bail;
+- break;
+- default:
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+-
+- /* Outside of frame? => Kick Out */
+- if (SACENC_OK !=
+- (error = FrameWindowList_Limit(pFrameWinList, 0, timeSlots - 1)))
+- goto bail;
+-
+- /* Add timeSlots as temporary border for window creation */
+- if (SACENC_OK !=
+- (error = FrameWindowList_Add(pFrameWinList, timeSlots - 1, FW_HOLD)))
+- goto bail;
+-
+- /* Create Windows */
+- for (ps = 0; ps < pFrameWinList->n - 1; ps++) {
+- if (FW_HOLD != pFrameWinList->dat[ps].hold) {
+- int const start = pFrameWinList->dat[ps].slot;
+- int const stop = pFrameWinList->dat[ps + 1].slot;
+-
+- /* Analysis Window */
+- FDKmemset_flex(pWindowAna__FDK[winCnt], FX_DBL2FX_WIN((FIXP_DBL)0),
+- start);
+- FDKmemset_flex(&pWindowAna__FDK[winCnt][start], winMaxVal,
+- stop - start + 1);
+- FDKmemset_flex(&pWindowAna__FDK[winCnt][stop + 1],
+- FX_DBL2FX_WIN((FIXP_DBL)0), timeSlots - stop - 1);
+-
+- applyRightWindowGain__FDK[winCnt] =
+- pWindowAna__FDK[winCnt][timeSlots - 1];
+- winCnt++;
+- }
+- } /* ps */
+-
+- /* Pop temporary frame border */
+- if (SACENC_OK !=
+- (error = FrameWindowList_Remove(pFrameWinList, pFrameWinList->n - 1)))
+- goto bail;
+- } else { /* No transient in left half of ana. window */
+- winCnt = 0;
+-
+- /* Add paramter set at end of frame */
+- if (SACENC_OK !=
+- (error = FrameWindowList_Add(pFrameWinList, timeSlots - 1, FW_INTP)))
+- goto bail;
+- /* Analysis Window */
+- FDKmemset_flex(pWindowAna__FDK[winCnt], FX_DBL2FX_WIN((FIXP_DBL)0),
+- startSlope);
+- FDKmemcpy_flex(&pWindowAna__FDK[winCnt][startSlope], 1, pTaperAna__FDK, 1,
+- taperAnaLen);
+- FDKmemset_flex(&pWindowAna__FDK[winCnt][startRect], winMaxVal,
+- timeSlots - startRect);
+-
+- applyRightWindowGain__FDK[winCnt] = winMaxVal;
+- winCnt++;
+- } /* if (tr_pos[0] > -1) */
+-
+- for (w = 0; w < winCnt; w++) {
+- if (applyRightWindowGain__FDK[w] > (FIXP_WIN)0) {
+- if (tr_pos[1] > -1) { /* Transients in second (right) half? */
+- int p_r = tr_pos[1];
+-
+- /* Analysis Window */
+- FDKmemset_flex(&pWindowAna__FDK[w][timeSlots], winMaxVal,
+- p_r - timeSlots);
+- FDKmemset_flex(&pWindowAna__FDK[w][p_r], FX_DBL2FX_WIN((FIXP_DBL)0),
+- 2 * timeSlots - p_r);
+-
+- } else { /* No transient in right half of ana. window */
+- /* Analysis Window */
+- FDKmemset_flex(&pWindowAna__FDK[w][timeSlots], winMaxVal,
+- stopRect - timeSlots + 1);
+- FDKmemcpy_flex(&pWindowAna__FDK[w][stopRect], 1,
+- &pTaperAna__FDK[taperAnaLen - 1], -1, taperAnaLen);
+- FDKmemset_flex(&pWindowAna__FDK[w][stopSlope + 1],
+- FX_DBL2FX_WIN((FIXP_DBL)0),
+- 2 * timeSlots - stopSlope - 1);
+-
+- } /* if (tr_pos[1] > -1) */
+-
+- /* Weight */
+- if (applyRightWindowGain__FDK[w] < winMaxVal) {
+- int ts;
+- for (ts = 0; ts < timeSlots; ts++) {
+- pWindowAna__FDK[w][timeSlots + ts] =
+- FX_DBL2FX_WIN(fMult(pWindowAna__FDK[w][timeSlots + ts],
+- applyRightWindowGain__FDK[w]));
+- }
+- }
+- } /* if (applyRightWindowGain[w] > 0.0f) */
+- else {
+- /* All Zero */
+- FDKmemset_flex(&pWindowAna__FDK[w][timeSlots],
+- FX_DBL2FX_WIN((FIXP_DBL)0), timeSlots);
+- }
+- } /* loop over windows */
+-
+- if (hFrameWindow->bFrameKeep == 1) {
+- FDKmemcpy_flex(&pWindowAna__FDK[0][2 * timeSlots], 1,
+- &pWindowAna__FDK[0][timeSlots], 1, timeSlots);
+- FDKmemcpy_flex(&pWindowAna__FDK[0][timeSlots], 1, pWindowAna__FDK[0], 1,
+- timeSlots);
+-
+- if (avoid_keep != 0) {
+- FDKmemset_flex(pWindowAna__FDK[0], FX_DBL2FX_WIN((FIXP_DBL)0),
+- timeSlots);
+- } else {
+- FDKmemset_flex(pWindowAna__FDK[0], winMaxVal, timeSlots);
+- }
+- } /* if (hFrameWindow->bFrameKeep==1) */
+-
+- /* Feed Info to Bitstream Formatter */
+- pFramingInfo->numParamSets = pFrameWinList->n;
+- pFramingInfo->bsFramingType = 1; /* variable framing */
+- for (ps = 0; ps < pFramingInfo->numParamSets; ps++) {
+- pFramingInfo->bsParamSlots[ps] = pFrameWinList->dat[ps].slot;
+- }
+-
+- /* if there is just one param set at last slot,
+- use fixed framing to save some bits */
+- if ((pFramingInfo->numParamSets == 1) &&
+- (pFramingInfo->bsParamSlots[0] == timeSlots - 1)) {
+- pFramingInfo->bsFramingType = 0;
+- }
+-
+- } /* valid handle */
+-
+-bail:
+-
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_analysisWindowing(
+- const INT nTimeSlots, const INT startTimeSlot,
+- FIXP_WIN *pFrameWindowAna__FDK, const FIXP_DPK *const *const ppDataIn__FDK,
+- FIXP_DPK *const *const ppDataOut__FDK, const INT nHybridBands,
+- const INT dim) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((pFrameWindowAna__FDK == NULL) || (ppDataIn__FDK == NULL) ||
+- (ppDataOut__FDK == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i, ts;
+- FIXP_WIN maxVal = FX_DBL2FX_WIN((FIXP_DBL)MAXVAL_DBL);
+-
+- if (dim == FW_CHANGE_DIM) {
+- for (ts = startTimeSlot; ts < nTimeSlots; ts++) {
+- FIXP_WIN win = pFrameWindowAna__FDK[ts];
+- if (win == maxVal) {
+- for (i = 0; i < nHybridBands; i++) {
+- ppDataOut__FDK[i][ts].v.re = ppDataIn__FDK[ts][i].v.re;
+- ppDataOut__FDK[i][ts].v.im = ppDataIn__FDK[ts][i].v.im;
+- }
+- } else {
+- for (i = 0; i < nHybridBands; i++) {
+- ppDataOut__FDK[i][ts].v.re = fMult(win, ppDataIn__FDK[ts][i].v.re);
+- ppDataOut__FDK[i][ts].v.im = fMult(win, ppDataIn__FDK[ts][i].v.im);
+- }
+- }
+- } /* ts */
+- } else {
+- for (ts = startTimeSlot; ts < nTimeSlots; ts++) {
+- FIXP_WIN win = pFrameWindowAna__FDK[ts];
+- if (win == maxVal) {
+- for (i = 0; i < nHybridBands; i++) {
+- ppDataOut__FDK[ts][i].v.re = ppDataIn__FDK[ts][i].v.re;
+- ppDataOut__FDK[ts][i].v.im = ppDataIn__FDK[ts][i].v.im;
+- }
+- } else {
+- for (i = 0; i < nHybridBands; i++) {
+- ppDataOut__FDK[ts][i].v.re = fMult(win, ppDataIn__FDK[ts][i].v.re);
+- ppDataOut__FDK[ts][i].v.im = fMult(win, ppDataIn__FDK[ts][i].v.im);
+- }
+- }
+- } /* ts */
+- }
+- }
+-
+- return error;
+-}
+diff --git a/libSACenc/src/sacenc_framewindowing.h b/libSACenc/src/sacenc_framewindowing.h
+deleted file mode 100644
+index 6b22dc9..0000000
+--- a/libSACenc/src/sacenc_framewindowing.h
++++ /dev/null
+@@ -1,181 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Max Neuendorf
+-
+- Description: Encoder Library Interface
+- Get windows for framing
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_FRAMEWINDOWING_H
+-#define SACENC_FRAMEWINDOWING_H
+-
+-/**************************************************************************/ /**
+- \file
+- Description of file contents
+- ******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "genericStds.h"
+-#include "common_fix.h"
+-#include "sacenc_lib.h"
+-#include "sacenc_bitstream.h"
+-
+-/* Defines *******************************************************************/
+-#define FIXP_WIN FIXP_DBL
+-#define FX_DBL2FX_WIN(x) (x)
+-#define DALDATATYPE_WIN DALDATATYPE_DFRACT
+-
+-typedef enum {
+- FW_INTP = 0,
+- FW_HOLD = 1
+-
+-} FW_SLOTTYPE;
+-
+-typedef enum {
+- FW_LEAVE_DIM = 0,
+- FW_CHANGE_DIM = 1
+-
+-} FW_DIMENSION;
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_FRAMEWINDOW *HANDLE_FRAMEWINDOW;
+-
+-typedef struct T_FRAMEWINDOW_CONFIG {
+- INT nTimeSlotsMax;
+- INT bFrameKeep;
+-
+-} FRAMEWINDOW_CONFIG;
+-
+-typedef struct {
+- INT slot;
+- FW_SLOTTYPE hold;
+-
+-} FRAMEWIN_DATA;
+-
+-typedef struct {
+- FRAMEWIN_DATA dat[MAX_NUM_PARAMS];
+- INT n;
+-
+-} FRAMEWIN_LIST;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_frameWindow_Create(
+- HANDLE_FRAMEWINDOW *phFrameWindow);
+-
+-FDK_SACENC_ERROR fdk_sacenc_frameWindow_Init(
+- HANDLE_FRAMEWINDOW hFrameWindow,
+- const FRAMEWINDOW_CONFIG *const pFrameWindowConfig);
+-
+-FDK_SACENC_ERROR fdk_sacenc_frameWindow_Destroy(
+- HANDLE_FRAMEWINDOW *phFrameWindow);
+-
+-FDK_SACENC_ERROR fdk_sacenc_frameWindow_GetWindow(
+- HANDLE_FRAMEWINDOW hFrameWindow, INT tr_pos[MAX_NUM_PARAMS],
+- const INT timeSlots, FRAMINGINFO *const pFramingInfo,
+- FIXP_WIN *pWindowAna__FDK[MAX_NUM_PARAMS],
+- FRAMEWIN_LIST *const pFrameWinList, const INT avoid_keep);
+-
+-FDK_SACENC_ERROR fdk_sacenc_analysisWindowing(
+- const INT nTimeSlots, const INT startTimeSlot,
+- FIXP_WIN *pFrameWindowAna__FDK, const FIXP_DPK *const *const ppDataIn__FDK,
+- FIXP_DPK *const *const ppDataOut__FDK, const INT nHybridBands,
+- const INT dim);
+-
+-#endif /* SACENC_FRAMEWINDOWING_H */
+diff --git a/libSACenc/src/sacenc_huff_tab.cpp b/libSACenc/src/sacenc_huff_tab.cpp
+deleted file mode 100644
+index 7b28ecd..0000000
+--- a/libSACenc/src/sacenc_huff_tab.cpp
++++ /dev/null
+@@ -1,997 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Markus Lohwasser
+-
+- Description: SAC-Encoder constant huffman tables
+-
+-*******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_huff_tab.h"
+-
+-/* Defines *******************************************************************/
+-
+-/* Data Types ****************************************************************/
+-
+-/* Constants *****************************************************************/
+-const HUFF_CLD_TABLE fdk_sacenc_huffCLDTab = {
+- {/* h1D[2][31] */
+- {HUFF_PACK(0x00000000, 1), HUFF_PACK(0x00000002, 2),
+- HUFF_PACK(0x00000006, 3), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000003e, 6),
+- HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x000000fe, 8),
+- HUFF_PACK(0x000001fe, 9), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x000007fe, 11), HUFF_PACK(0x00000ffe, 12),
+- HUFF_PACK(0x00001ffe, 13), HUFF_PACK(0x00007ffe, 15),
+- HUFF_PACK(0x00007ffc, 15), HUFF_PACK(0x0000fffe, 16),
+- HUFF_PACK(0x0000fffa, 16), HUFF_PACK(0x0001fffe, 17),
+- HUFF_PACK(0x0001fff6, 17), HUFF_PACK(0x0003fffe, 18),
+- HUFF_PACK(0x0003ffff, 18), HUFF_PACK(0x0007ffde, 19),
+- HUFF_PACK(0x0003ffee, 18), HUFF_PACK(0x000fffbe, 20),
+- HUFF_PACK(0x001fff7e, 21), HUFF_PACK(0x00fffbfc, 24),
+- HUFF_PACK(0x00fffbfd, 24), HUFF_PACK(0x00fffbfe, 24),
+- HUFF_PACK(0x00fffbff, 24), HUFF_PACK(0x007ffdfc, 23),
+- HUFF_PACK(0x007ffdfd, 23)},
+- {HUFF_PACK(0x00000000, 1), HUFF_PACK(0x00000002, 2),
+- HUFF_PACK(0x00000006, 3), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000003e, 6),
+- HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x000001fe, 9),
+- HUFF_PACK(0x000001fc, 9), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x000003fa, 10), HUFF_PACK(0x000007fe, 11),
+- HUFF_PACK(0x000007f6, 11), HUFF_PACK(0x00000ffe, 12),
+- HUFF_PACK(0x00000fee, 12), HUFF_PACK(0x00001ffe, 13),
+- HUFF_PACK(0x00001fde, 13), HUFF_PACK(0x00003ffe, 14),
+- HUFF_PACK(0x00003fbe, 14), HUFF_PACK(0x00003fbf, 14),
+- HUFF_PACK(0x00007ffe, 15), HUFF_PACK(0x0000fffe, 16),
+- HUFF_PACK(0x0001fffe, 17), HUFF_PACK(0x0007fffe, 19),
+- HUFF_PACK(0x0007fffc, 19), HUFF_PACK(0x000ffffa, 20),
+- HUFF_PACK(0x001ffffc, 21), HUFF_PACK(0x001ffffd, 21),
+- HUFF_PACK(0x001ffffe, 21), HUFF_PACK(0x001fffff, 21),
+- HUFF_PACK(0x000ffffb, 20)}},
+- { /* HUFF_CLD_TAB_2D */
+- { /* HUFF_CLD_TAB_2D[0][] */
+- {/* HUFF_CLD_TAB_2D[0][0] */
+- {
+- /* LAV3_2D */
+- {{HUFF_PACK(0x00000002, 2), HUFF_PACK(0x00000002, 3),
+- HUFF_PACK(0x00000004, 5), HUFF_PACK(0x0000003e, 8)},
+- {HUFF_PACK(0x00000006, 4), HUFF_PACK(0x00000007, 4),
+- HUFF_PACK(0x0000000e, 6), HUFF_PACK(0x000000fe, 10)},
+- {HUFF_PACK(0x0000007e, 9), HUFF_PACK(0x0000001e, 7),
+- HUFF_PACK(0x0000000c, 6), HUFF_PACK(0x00000005, 5)},
+- {HUFF_PACK(0x000000ff, 10), HUFF_PACK(0x0000000d, 6),
+- HUFF_PACK(0x00000000, 3), HUFF_PACK(0x00000003, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV5_2D */
+- {{HUFF_PACK(0x00000002, 3), HUFF_PACK(0x00000003, 3),
+- HUFF_PACK(0x00000010, 5), HUFF_PACK(0x0000007c, 7),
+- HUFF_PACK(0x000000d6, 8), HUFF_PACK(0x000003ee, 10)},
+- {HUFF_PACK(0x0000000a, 4), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x00000016, 5), HUFF_PACK(0x00000034, 6),
+- HUFF_PACK(0x000000fe, 8), HUFF_PACK(0x00001f7e, 13)},
+- {HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x00000036, 6),
+- HUFF_PACK(0x00000026, 6), HUFF_PACK(0x00000046, 7),
+- HUFF_PACK(0x0000011e, 9), HUFF_PACK(0x000001f6, 9)},
+- {HUFF_PACK(0x0000011f, 9), HUFF_PACK(0x000000d7, 8),
+- HUFF_PACK(0x0000008e, 8), HUFF_PACK(0x000000ff, 8),
+- HUFF_PACK(0x0000006a, 7), HUFF_PACK(0x0000004e, 7)},
+- {HUFF_PACK(0x00000fbe, 12), HUFF_PACK(0x000007de, 11),
+- HUFF_PACK(0x0000004f, 7), HUFF_PACK(0x00000037, 6),
+- HUFF_PACK(0x00000017, 5), HUFF_PACK(0x0000001e, 5)},
+- {HUFF_PACK(0x00001f7f, 13), HUFF_PACK(0x000000fa, 8),
+- HUFF_PACK(0x00000022, 6), HUFF_PACK(0x00000012, 5),
+- HUFF_PACK(0x0000000e, 4), HUFF_PACK(0x00000000, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV7_2D */
+- {{HUFF_PACK(0x0000000e, 4), HUFF_PACK(0x0000000a, 4),
+- HUFF_PACK(0x0000000a, 5), HUFF_PACK(0x0000007c, 7),
+- HUFF_PACK(0x000000be, 8), HUFF_PACK(0x0000017a, 9),
+- HUFF_PACK(0x000000ee, 9), HUFF_PACK(0x000007b6, 11)},
+- {HUFF_PACK(0x00000006, 4), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x00000016, 5), HUFF_PACK(0x00000026, 6),
+- HUFF_PACK(0x0000003e, 7), HUFF_PACK(0x0000002e, 7),
+- HUFF_PACK(0x000001ec, 9), HUFF_PACK(0x000047ce, 15)},
+- {HUFF_PACK(0x00000016, 6), HUFF_PACK(0x0000003c, 6),
+- HUFF_PACK(0x00000022, 6), HUFF_PACK(0x0000004e, 7),
+- HUFF_PACK(0x0000003f, 7), HUFF_PACK(0x0000005e, 8),
+- HUFF_PACK(0x000008fa, 12), HUFF_PACK(0x000008fb, 12)},
+- {HUFF_PACK(0x0000005f, 8), HUFF_PACK(0x000000fa, 8),
+- HUFF_PACK(0x000000bf, 8), HUFF_PACK(0x0000003a, 7),
+- HUFF_PACK(0x000001f6, 9), HUFF_PACK(0x000001de, 10),
+- HUFF_PACK(0x000003da, 10), HUFF_PACK(0x000007b7, 11)},
+- {HUFF_PACK(0x000001df, 10), HUFF_PACK(0x000003ee, 10),
+- HUFF_PACK(0x0000017b, 9), HUFF_PACK(0x000003ef, 10),
+- HUFF_PACK(0x000001ee, 9), HUFF_PACK(0x0000008e, 8),
+- HUFF_PACK(0x000001ef, 9), HUFF_PACK(0x000001fe, 9)},
+- {HUFF_PACK(0x000008f8, 12), HUFF_PACK(0x0000047e, 11),
+- HUFF_PACK(0x0000047f, 11), HUFF_PACK(0x00000076, 8),
+- HUFF_PACK(0x0000003c, 7), HUFF_PACK(0x00000046, 7),
+- HUFF_PACK(0x0000007a, 7), HUFF_PACK(0x0000007e, 7)},
+- {HUFF_PACK(0x000023e6, 14), HUFF_PACK(0x000011f2, 13),
+- HUFF_PACK(0x000001ff, 9), HUFF_PACK(0x0000003d, 7),
+- HUFF_PACK(0x0000004f, 7), HUFF_PACK(0x0000002e, 6),
+- HUFF_PACK(0x00000012, 5), HUFF_PACK(0x00000004, 4)},
+- {HUFF_PACK(0x000047cf, 15), HUFF_PACK(0x0000011e, 9),
+- HUFF_PACK(0x000000bc, 8), HUFF_PACK(0x000000fe, 8),
+- HUFF_PACK(0x0000001c, 6), HUFF_PACK(0x00000010, 5),
+- HUFF_PACK(0x0000000d, 4), HUFF_PACK(0x00000000, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV9_2D */
+- {{HUFF_PACK(0x00000006, 4), HUFF_PACK(0x00000007, 4),
+- HUFF_PACK(0x00000006, 5), HUFF_PACK(0x0000007e, 7),
+- HUFF_PACK(0x0000000a, 7), HUFF_PACK(0x0000001e, 8),
+- HUFF_PACK(0x0000008a, 9), HUFF_PACK(0x0000004e, 10),
+- HUFF_PACK(0x00000276, 10), HUFF_PACK(0x000002e2, 11)},
+- {HUFF_PACK(0x00000000, 4), HUFF_PACK(0x0000000a, 4),
+- HUFF_PACK(0x00000016, 5), HUFF_PACK(0x00000026, 6),
+- HUFF_PACK(0x00000076, 7), HUFF_PACK(0x000000f2, 8),
+- HUFF_PACK(0x00000012, 8), HUFF_PACK(0x0000005e, 8),
+- HUFF_PACK(0x0000008b, 9), HUFF_PACK(0x00002e76, 15)},
+- {HUFF_PACK(0x00000012, 6), HUFF_PACK(0x00000007, 5),
+- HUFF_PACK(0x00000038, 6), HUFF_PACK(0x0000007c, 7),
+- HUFF_PACK(0x00000008, 7), HUFF_PACK(0x00000046, 8),
+- HUFF_PACK(0x000000f6, 8), HUFF_PACK(0x000001ca, 9),
+- HUFF_PACK(0x0000173a, 14), HUFF_PACK(0x00001738, 14)},
+- {HUFF_PACK(0x0000009e, 8), HUFF_PACK(0x0000004a, 7),
+- HUFF_PACK(0x00000026, 7), HUFF_PACK(0x0000000c, 7),
+- HUFF_PACK(0x0000004e, 8), HUFF_PACK(0x000000f7, 8),
+- HUFF_PACK(0x0000013a, 9), HUFF_PACK(0x0000009e, 11),
+- HUFF_PACK(0x000009fe, 12), HUFF_PACK(0x0000013e, 12)},
+- {HUFF_PACK(0x00000026, 9), HUFF_PACK(0x0000001a, 8),
+- HUFF_PACK(0x000001e6, 9), HUFF_PACK(0x000001e2, 9),
+- HUFF_PACK(0x000000ee, 8), HUFF_PACK(0x000001ce, 9),
+- HUFF_PACK(0x00000277, 10), HUFF_PACK(0x000003ce, 10),
+- HUFF_PACK(0x000002e6, 11), HUFF_PACK(0x000004fc, 11)},
+- {HUFF_PACK(0x000002e3, 11), HUFF_PACK(0x00000170, 10),
+- HUFF_PACK(0x00000172, 10), HUFF_PACK(0x000000ba, 9),
+- HUFF_PACK(0x0000003e, 9), HUFF_PACK(0x000001e3, 9),
+- HUFF_PACK(0x0000001b, 8), HUFF_PACK(0x0000003f, 9),
+- HUFF_PACK(0x0000009e, 9), HUFF_PACK(0x0000009f, 9)},
+- {HUFF_PACK(0x00000b9e, 13), HUFF_PACK(0x000009ff, 12),
+- HUFF_PACK(0x000004fd, 11), HUFF_PACK(0x000004fe, 11),
+- HUFF_PACK(0x000001cf, 9), HUFF_PACK(0x000000ef, 8),
+- HUFF_PACK(0x00000044, 8), HUFF_PACK(0x0000005f, 8),
+- HUFF_PACK(0x000000e4, 8), HUFF_PACK(0x000000f0, 8)},
+- {HUFF_PACK(0x00002e72, 15), HUFF_PACK(0x0000013f, 12),
+- HUFF_PACK(0x00000b9f, 13), HUFF_PACK(0x0000013e, 9),
+- HUFF_PACK(0x000000fe, 8), HUFF_PACK(0x00000047, 8),
+- HUFF_PACK(0x0000000e, 7), HUFF_PACK(0x0000007d, 7),
+- HUFF_PACK(0x00000010, 6), HUFF_PACK(0x00000024, 6)},
+- {HUFF_PACK(0x00002e77, 15), HUFF_PACK(0x00005ce6, 16),
+- HUFF_PACK(0x000000bb, 9), HUFF_PACK(0x000000e6, 8),
+- HUFF_PACK(0x00000016, 8), HUFF_PACK(0x000000ff, 8),
+- HUFF_PACK(0x0000007a, 7), HUFF_PACK(0x0000003a, 6),
+- HUFF_PACK(0x00000017, 5), HUFF_PACK(0x00000002, 4)},
+- {HUFF_PACK(0x00005ce7, 16), HUFF_PACK(0x000003cf, 10),
+- HUFF_PACK(0x00000017, 8), HUFF_PACK(0x000001cb, 9),
+- HUFF_PACK(0x0000009c, 8), HUFF_PACK(0x0000004b, 7),
+- HUFF_PACK(0x00000016, 6), HUFF_PACK(0x0000000a, 5),
+- HUFF_PACK(0x00000008, 4), HUFF_PACK(0x00000006, 3)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- }},
+- {/* HUFF_CLD_TAB_2D[0][1] */
+- {
+- /* LAV3_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x0000003e, 6),
+- HUFF_PACK(0x0000076e, 11), HUFF_PACK(0x00000ede, 12)},
+- {HUFF_PACK(0x00000006, 3), HUFF_PACK(0x0000003f, 6),
+- HUFF_PACK(0x000003b6, 10), HUFF_PACK(0x0000003a, 6)},
+- {HUFF_PACK(0x0000001c, 5), HUFF_PACK(0x000000ee, 8),
+- HUFF_PACK(0x000001da, 9), HUFF_PACK(0x0000001e, 5)},
+- {HUFF_PACK(0x000000ef, 8), HUFF_PACK(0x00000edf, 12),
+- HUFF_PACK(0x000000ec, 8), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV5_2D */
+- {{HUFF_PACK(0x00000006, 3), HUFF_PACK(0x0000001c, 5),
+- HUFF_PACK(0x0000007e, 8), HUFF_PACK(0x00000efc, 12),
+- HUFF_PACK(0x0000effe, 16), HUFF_PACK(0x0001dffe, 17)},
+- {HUFF_PACK(0x00000004, 3), HUFF_PACK(0x0000000a, 4),
+- HUFF_PACK(0x0000003e, 7), HUFF_PACK(0x00000efe, 12),
+- HUFF_PACK(0x000077fe, 15), HUFF_PACK(0x00000076, 7)},
+- {HUFF_PACK(0x00000006, 4), HUFF_PACK(0x00000016, 5),
+- HUFF_PACK(0x000000be, 8), HUFF_PACK(0x00000efd, 12),
+- HUFF_PACK(0x000000ee, 8), HUFF_PACK(0x0000000e, 5)},
+- {HUFF_PACK(0x0000003e, 6), HUFF_PACK(0x0000002e, 6),
+- HUFF_PACK(0x000001de, 9), HUFF_PACK(0x000003be, 10),
+- HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x0000001e, 5)},
+- {HUFF_PACK(0x0000007f, 7), HUFF_PACK(0x0000005e, 7),
+- HUFF_PACK(0x00003bfe, 14), HUFF_PACK(0x000000fe, 9),
+- HUFF_PACK(0x0000001e, 6), HUFF_PACK(0x00000002, 3)},
+- {HUFF_PACK(0x000000bf, 8), HUFF_PACK(0x0001dfff, 17),
+- HUFF_PACK(0x00001dfe, 13), HUFF_PACK(0x000000ff, 9),
+- HUFF_PACK(0x0000003a, 6), HUFF_PACK(0x00000000, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV7_2D */
+- {{HUFF_PACK(0x00000002, 3), HUFF_PACK(0x0000001c, 5),
+- HUFF_PACK(0x000000bc, 8), HUFF_PACK(0x000005fc, 11),
+- HUFF_PACK(0x00005ffe, 15), HUFF_PACK(0x0002ffde, 18),
+- HUFF_PACK(0x000bff7e, 20), HUFF_PACK(0x0017feff, 21)},
+- {HUFF_PACK(0x00000004, 3), HUFF_PACK(0x0000000a, 4),
+- HUFF_PACK(0x0000000e, 7), HUFF_PACK(0x000002fa, 10),
+- HUFF_PACK(0x000001fe, 13), HUFF_PACK(0x0000bff2, 16),
+- HUFF_PACK(0x0005ffbe, 19), HUFF_PACK(0x000000ee, 8)},
+- {HUFF_PACK(0x00000002, 4), HUFF_PACK(0x00000016, 5),
+- HUFF_PACK(0x000000f6, 8), HUFF_PACK(0x000005fe, 11),
+- HUFF_PACK(0x000001ff, 13), HUFF_PACK(0x0000bff6, 16),
+- HUFF_PACK(0x000001de, 9), HUFF_PACK(0x0000007e, 7)},
+- {HUFF_PACK(0x00000000, 5), HUFF_PACK(0x0000003c, 6),
+- HUFF_PACK(0x0000000e, 8), HUFF_PACK(0x0000003e, 10),
+- HUFF_PACK(0x00002ffe, 14), HUFF_PACK(0x000002fb, 10),
+- HUFF_PACK(0x000000f7, 8), HUFF_PACK(0x0000002e, 6)},
+- {HUFF_PACK(0x00000006, 6), HUFF_PACK(0x0000007a, 7),
+- HUFF_PACK(0x0000000a, 8), HUFF_PACK(0x0000007e, 11),
+- HUFF_PACK(0x000000fe, 12), HUFF_PACK(0x00000016, 9),
+- HUFF_PACK(0x00000006, 7), HUFF_PACK(0x00000002, 5)},
+- {HUFF_PACK(0x0000000f, 7), HUFF_PACK(0x00000076, 7),
+- HUFF_PACK(0x00000017, 9), HUFF_PACK(0x00005ff8, 15),
+- HUFF_PACK(0x00000bfe, 12), HUFF_PACK(0x0000001e, 9),
+- HUFF_PACK(0x0000007f, 7), HUFF_PACK(0x00000003, 4)},
+- {HUFF_PACK(0x00000004, 7), HUFF_PACK(0x000000bd, 8),
+- HUFF_PACK(0x0000bff3, 16), HUFF_PACK(0x00005fff, 15),
+- HUFF_PACK(0x00000bfa, 12), HUFF_PACK(0x0000017c, 9),
+- HUFF_PACK(0x0000003a, 6), HUFF_PACK(0x00000003, 3)},
+- {HUFF_PACK(0x0000017e, 9), HUFF_PACK(0x0017fefe, 21),
+- HUFF_PACK(0x00017fee, 17), HUFF_PACK(0x00005ffa, 15),
+- HUFF_PACK(0x00000bfb, 12), HUFF_PACK(0x000001df, 9),
+- HUFF_PACK(0x0000003e, 6), HUFF_PACK(0x00000006, 3)}},
+- HUFF_PACK(0x0017feff, 21) /* escape */
+- },
+- {
+- /* LAV9_2D */
+- {{HUFF_PACK(0x0000000e, 4), HUFF_PACK(0x00000014, 5),
+- HUFF_PACK(0x0000008e, 8), HUFF_PACK(0x000004fe, 11),
+- HUFF_PACK(0x000023fe, 14), HUFF_PACK(0x00008ffe, 16),
+- HUFF_PACK(0x0005ffbc, 19), HUFF_PACK(0x0017fef7, 21),
+- HUFF_PACK(0x0017fef7, 21), HUFF_PACK(0x0017fef7, 21)},
+- {HUFF_PACK(0x00000002, 3), HUFF_PACK(0x00000002, 4),
+- HUFF_PACK(0x00000044, 7), HUFF_PACK(0x0000027e, 10),
+- HUFF_PACK(0x000017fc, 13), HUFF_PACK(0x0000bff6, 16),
+- HUFF_PACK(0x0005ffbe, 19), HUFF_PACK(0x00011ff8, 17),
+- HUFF_PACK(0x000bff7a, 20), HUFF_PACK(0x000000bc, 8)},
+- {HUFF_PACK(0x00000006, 4), HUFF_PACK(0x00000016, 5),
+- HUFF_PACK(0x0000001a, 7), HUFF_PACK(0x000000fe, 10),
+- HUFF_PACK(0x000011f6, 13), HUFF_PACK(0x0000bffe, 16),
+- HUFF_PACK(0x00011ff9, 17), HUFF_PACK(0x0017fef6, 21),
+- HUFF_PACK(0x0000011e, 9), HUFF_PACK(0x00000056, 7)},
+- {HUFF_PACK(0x00000010, 5), HUFF_PACK(0x0000003e, 6),
+- HUFF_PACK(0x0000009e, 8), HUFF_PACK(0x000007fe, 11),
+- HUFF_PACK(0x000011f7, 13), HUFF_PACK(0x00005ff8, 15),
+- HUFF_PACK(0x00017fee, 17), HUFF_PACK(0x000007ff, 11),
+- HUFF_PACK(0x000000ae, 8), HUFF_PACK(0x0000001e, 7)},
+- {HUFF_PACK(0x00000026, 6), HUFF_PACK(0x0000000e, 6),
+- HUFF_PACK(0x000001ee, 9), HUFF_PACK(0x0000047e, 11),
+- HUFF_PACK(0x00000bfc, 12), HUFF_PACK(0x0000bfff, 16),
+- HUFF_PACK(0x000008fa, 12), HUFF_PACK(0x0000006e, 9),
+- HUFF_PACK(0x000001ef, 9), HUFF_PACK(0x0000007e, 7)},
+- {HUFF_PACK(0x0000007a, 7), HUFF_PACK(0x0000004e, 7),
+- HUFF_PACK(0x0000007e, 9), HUFF_PACK(0x000000de, 10),
+- HUFF_PACK(0x000011fe, 13), HUFF_PACK(0x00002ffe, 14),
+- HUFF_PACK(0x000004ff, 11), HUFF_PACK(0x000000ff, 10),
+- HUFF_PACK(0x000000bd, 8), HUFF_PACK(0x0000002e, 6)},
+- {HUFF_PACK(0x000000fe, 8), HUFF_PACK(0x000000af, 8),
+- HUFF_PACK(0x000001ec, 9), HUFF_PACK(0x000001be, 11),
+- HUFF_PACK(0x00011ffe, 17), HUFF_PACK(0x00002ffa, 14),
+- HUFF_PACK(0x000008fe, 12), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x00000046, 7), HUFF_PACK(0x00000012, 5)},
+- {HUFF_PACK(0x0000003e, 8), HUFF_PACK(0x00000045, 7),
+- HUFF_PACK(0x000002fe, 10), HUFF_PACK(0x000bff7e, 20),
+- HUFF_PACK(0x00005ff9, 15), HUFF_PACK(0x00005ffa, 15),
+- HUFF_PACK(0x00000bfd, 12), HUFF_PACK(0x0000013e, 9),
+- HUFF_PACK(0x0000000c, 6), HUFF_PACK(0x00000007, 4)},
+- {HUFF_PACK(0x000000be, 8), HUFF_PACK(0x00000036, 8),
+- HUFF_PACK(0x000bff7f, 20), HUFF_PACK(0x00023ffe, 18),
+- HUFF_PACK(0x00011ffa, 17), HUFF_PACK(0x00005ffe, 15),
+- HUFF_PACK(0x000001bf, 11), HUFF_PACK(0x000001ed, 9),
+- HUFF_PACK(0x0000002a, 6), HUFF_PACK(0x00000000, 3)},
+- {HUFF_PACK(0x0000017e, 9), HUFF_PACK(0x0017fef7, 21),
+- HUFF_PACK(0x00047ffe, 19), HUFF_PACK(0x00047fff, 19),
+- HUFF_PACK(0x00011ffb, 17), HUFF_PACK(0x00002ffb, 14),
+- HUFF_PACK(0x0000047c, 11), HUFF_PACK(0x000001fe, 9),
+- HUFF_PACK(0x0000003c, 6), HUFF_PACK(0x00000006, 3)}},
+- HUFF_PACK(0x0017fef7, 21) /* escape */
+- }}},
+- { /* HUFF_CLD_TAB_2D[1][] */
+- {/* HUFF_CLD_TAB_2D[1][0] */
+- {
+- /* LAV3_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x0000001e, 5),
+- HUFF_PACK(0x000003be, 10), HUFF_PACK(0x00000efe, 12)},
+- {HUFF_PACK(0x00000006, 3), HUFF_PACK(0x0000001c, 5),
+- HUFF_PACK(0x000001de, 9), HUFF_PACK(0x000000ea, 8)},
+- {HUFF_PACK(0x00000074, 7), HUFF_PACK(0x000000ee, 8),
+- HUFF_PACK(0x000000eb, 8), HUFF_PACK(0x0000001f, 5)},
+- {HUFF_PACK(0x0000077e, 11), HUFF_PACK(0x00000eff, 12),
+- HUFF_PACK(0x00000076, 7), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV5_2D */
+- {{HUFF_PACK(0x00000000, 2), HUFF_PACK(0x00000006, 4),
+- HUFF_PACK(0x00000024, 7), HUFF_PACK(0x0000025e, 11),
+- HUFF_PACK(0x00003cfe, 14), HUFF_PACK(0x000079fe, 15)},
+- {HUFF_PACK(0x00000006, 3), HUFF_PACK(0x00000007, 4),
+- HUFF_PACK(0x00000078, 7), HUFF_PACK(0x000003ce, 10),
+- HUFF_PACK(0x00001e7e, 13), HUFF_PACK(0x000000be, 9)},
+- {HUFF_PACK(0x00000008, 5), HUFF_PACK(0x0000003e, 6),
+- HUFF_PACK(0x00000026, 7), HUFF_PACK(0x0000012e, 10),
+- HUFF_PACK(0x000000bf, 9), HUFF_PACK(0x0000002e, 7)},
+- {HUFF_PACK(0x00000027, 7), HUFF_PACK(0x0000007a, 7),
+- HUFF_PACK(0x000001e4, 9), HUFF_PACK(0x00000096, 9),
+- HUFF_PACK(0x0000007b, 7), HUFF_PACK(0x0000003f, 6)},
+- {HUFF_PACK(0x000001e6, 9), HUFF_PACK(0x000001e5, 9),
+- HUFF_PACK(0x00000f3e, 12), HUFF_PACK(0x0000005e, 8),
+- HUFF_PACK(0x00000016, 6), HUFF_PACK(0x0000000e, 4)},
+- {HUFF_PACK(0x0000079e, 11), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x0000025f, 11), HUFF_PACK(0x0000004a, 8),
+- HUFF_PACK(0x0000000a, 5), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV7_2D */
+- {{HUFF_PACK(0x00000000, 2), HUFF_PACK(0x00000006, 4),
+- HUFF_PACK(0x000000de, 8), HUFF_PACK(0x0000069e, 11),
+- HUFF_PACK(0x000034fe, 14), HUFF_PACK(0x0001a7fe, 17),
+- HUFF_PACK(0x00069ff6, 19), HUFF_PACK(0x00069ff7, 19)},
+- {HUFF_PACK(0x00000002, 3), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x0000006a, 7), HUFF_PACK(0x0000034e, 10),
+- HUFF_PACK(0x00001fde, 13), HUFF_PACK(0x000069fe, 15),
+- HUFF_PACK(0x0001a7fc, 17), HUFF_PACK(0x00000372, 10)},
+- {HUFF_PACK(0x0000003e, 6), HUFF_PACK(0x0000003c, 6),
+- HUFF_PACK(0x000000df, 8), HUFF_PACK(0x000001ee, 10),
+- HUFF_PACK(0x00000dde, 12), HUFF_PACK(0x000069fa, 15),
+- HUFF_PACK(0x00000373, 10), HUFF_PACK(0x0000007a, 8)},
+- {HUFF_PACK(0x0000003e, 7), HUFF_PACK(0x00000068, 7),
+- HUFF_PACK(0x000001ba, 9), HUFF_PACK(0x000003f6, 10),
+- HUFF_PACK(0x00000d3e, 12), HUFF_PACK(0x0000034c, 10),
+- HUFF_PACK(0x000001fa, 9), HUFF_PACK(0x000000d2, 8)},
+- {HUFF_PACK(0x0000007e, 8), HUFF_PACK(0x0000007f, 8),
+- HUFF_PACK(0x000001f8, 9), HUFF_PACK(0x000006ee, 11),
+- HUFF_PACK(0x000003de, 11), HUFF_PACK(0x000001b8, 9),
+- HUFF_PACK(0x000001fc, 9), HUFF_PACK(0x0000006b, 7)},
+- {HUFF_PACK(0x000000f6, 9), HUFF_PACK(0x000001fe, 9),
+- HUFF_PACK(0x0000034d, 10), HUFF_PACK(0x00003fbe, 14),
+- HUFF_PACK(0x000007f6, 11), HUFF_PACK(0x000003fa, 10),
+- HUFF_PACK(0x0000003c, 7), HUFF_PACK(0x0000003d, 6)},
+- {HUFF_PACK(0x000003f7, 10), HUFF_PACK(0x00000376, 10),
+- HUFF_PACK(0x0001a7ff, 17), HUFF_PACK(0x00003fbf, 14),
+- HUFF_PACK(0x00000ddf, 12), HUFF_PACK(0x000001f9, 9),
+- HUFF_PACK(0x00000036, 6), HUFF_PACK(0x0000000e, 4)},
+- {HUFF_PACK(0x000003df, 11), HUFF_PACK(0x00034ffa, 18),
+- HUFF_PACK(0x000069fb, 15), HUFF_PACK(0x000034fc, 14),
+- HUFF_PACK(0x00000fee, 12), HUFF_PACK(0x000001ff, 9),
+- HUFF_PACK(0x0000000e, 5), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV9_2D */
+- {{HUFF_PACK(0x00000006, 3), HUFF_PACK(0x00000004, 4),
+- HUFF_PACK(0x00000012, 7), HUFF_PACK(0x000007fe, 11),
+- HUFF_PACK(0x00001f7e, 13), HUFF_PACK(0x0000fbfe, 16),
+- HUFF_PACK(0x0001f7fe, 17), HUFF_PACK(0x000b7dfe, 21),
+- HUFF_PACK(0x000b7dff, 21), HUFF_PACK(0x000b7dff, 21)},
+- {HUFF_PACK(0x00000000, 3), HUFF_PACK(0x00000006, 4),
+- HUFF_PACK(0x0000007c, 7), HUFF_PACK(0x00000046, 9),
+- HUFF_PACK(0x000007d0, 12), HUFF_PACK(0x00001f4e, 14),
+- HUFF_PACK(0x0000b7fe, 17), HUFF_PACK(0x00005bee, 16),
+- HUFF_PACK(0x00016fbe, 18), HUFF_PACK(0x000003ee, 10)},
+- {HUFF_PACK(0x00000006, 5), HUFF_PACK(0x0000000a, 5),
+- HUFF_PACK(0x0000002e, 7), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x000007d2, 12), HUFF_PACK(0x00001f4f, 14),
+- HUFF_PACK(0x00002dfe, 15), HUFF_PACK(0x0000b7de, 17),
+- HUFF_PACK(0x000001fe, 10), HUFF_PACK(0x0000002e, 8)},
+- {HUFF_PACK(0x0000007a, 7), HUFF_PACK(0x0000007e, 7),
+- HUFF_PACK(0x0000007a, 8), HUFF_PACK(0x000001fa, 10),
+- HUFF_PACK(0x000007fe, 12), HUFF_PACK(0x00001f7c, 13),
+- HUFF_PACK(0x000016fa, 14), HUFF_PACK(0x0000009e, 10),
+- HUFF_PACK(0x00000020, 8), HUFF_PACK(0x00000021, 8)},
+- {HUFF_PACK(0x000000fe, 8), HUFF_PACK(0x00000016, 7),
+- HUFF_PACK(0x000000fe, 9), HUFF_PACK(0x0000016e, 10),
+- HUFF_PACK(0x0000009f, 10), HUFF_PACK(0x00000b7c, 13),
+- HUFF_PACK(0x000003de, 11), HUFF_PACK(0x000000b6, 9),
+- HUFF_PACK(0x000000be, 9), HUFF_PACK(0x0000007c, 8)},
+- {HUFF_PACK(0x0000005a, 8), HUFF_PACK(0x00000078, 8),
+- HUFF_PACK(0x00000047, 9), HUFF_PACK(0x00000044, 9),
+- HUFF_PACK(0x000007ff, 12), HUFF_PACK(0x000007d1, 12),
+- HUFF_PACK(0x000001f6, 10), HUFF_PACK(0x000001f7, 10),
+- HUFF_PACK(0x0000002f, 8), HUFF_PACK(0x0000002c, 7)},
+- {HUFF_PACK(0x000000fc, 9), HUFF_PACK(0x000001f6, 9),
+- HUFF_PACK(0x000000f6, 9), HUFF_PACK(0x000007ff, 11),
+- HUFF_PACK(0x000016fe, 14), HUFF_PACK(0x000002de, 11),
+- HUFF_PACK(0x000003ea, 11), HUFF_PACK(0x000000bf, 9),
+- HUFF_PACK(0x000000fa, 8), HUFF_PACK(0x0000000a, 6)},
+- {HUFF_PACK(0x0000004e, 9), HUFF_PACK(0x00000026, 8),
+- HUFF_PACK(0x000001ee, 10), HUFF_PACK(0x00005bfe, 16),
+- HUFF_PACK(0x00003efe, 14), HUFF_PACK(0x00000b7e, 13),
+- HUFF_PACK(0x000003eb, 11), HUFF_PACK(0x000001fe, 9),
+- HUFF_PACK(0x0000007b, 7), HUFF_PACK(0x00000007, 5)},
+- {HUFF_PACK(0x000001fb, 10), HUFF_PACK(0x00000045, 9),
+- HUFF_PACK(0x00016ffe, 18), HUFF_PACK(0x0001f7ff, 17),
+- HUFF_PACK(0x00002df6, 15), HUFF_PACK(0x00001f7d, 13),
+- HUFF_PACK(0x000003fe, 11), HUFF_PACK(0x0000005e, 8),
+- HUFF_PACK(0x0000003c, 6), HUFF_PACK(0x0000000e, 4)},
+- {HUFF_PACK(0x000003df, 11), HUFF_PACK(0x0005befe, 20),
+- HUFF_PACK(0x0002df7e, 19), HUFF_PACK(0x00016fff, 18),
+- HUFF_PACK(0x00007dfe, 15), HUFF_PACK(0x00000fa6, 13),
+- HUFF_PACK(0x000007de, 11), HUFF_PACK(0x00000079, 8),
+- HUFF_PACK(0x0000000e, 5), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x000b7dff, 21) /* escape */
+- }},
+- {/* HUFF_CLD_TAB_2D[1][1] */
+- {
+- /* LAV3_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x000000fa, 8), HUFF_PACK(0x000007de, 11)},
+- {HUFF_PACK(0x0000000c, 4), HUFF_PACK(0x0000001e, 5),
+- HUFF_PACK(0x000000fe, 8), HUFF_PACK(0x000001f6, 9)},
+- {HUFF_PACK(0x000000ff, 8), HUFF_PACK(0x0000007c, 7),
+- HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x0000001a, 5)},
+- {HUFF_PACK(0x000007df, 11), HUFF_PACK(0x000003ee, 10),
+- HUFF_PACK(0x0000001b, 5), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV5_2D */
+- {{HUFF_PACK(0x00000006, 3), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000007c, 7), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x00000fbe, 12), HUFF_PACK(0x00003efe, 14)},
+- {HUFF_PACK(0x00000000, 3), HUFF_PACK(0x00000001, 3),
+- HUFF_PACK(0x0000003c, 6), HUFF_PACK(0x0000005e, 8),
+- HUFF_PACK(0x000007de, 11), HUFF_PACK(0x000007be, 11)},
+- {HUFF_PACK(0x0000001e, 6), HUFF_PACK(0x0000000a, 5),
+- HUFF_PACK(0x0000001f, 6), HUFF_PACK(0x0000005f, 8),
+- HUFF_PACK(0x000001ee, 9), HUFF_PACK(0x000001f6, 9)},
+- {HUFF_PACK(0x000001fe, 9), HUFF_PACK(0x000000fe, 8),
+- HUFF_PACK(0x000000f6, 8), HUFF_PACK(0x000000fa, 8),
+- HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x00000016, 6)},
+- {HUFF_PACK(0x000007bf, 11), HUFF_PACK(0x000003de, 10),
+- HUFF_PACK(0x000003ee, 10), HUFF_PACK(0x0000007a, 7),
+- HUFF_PACK(0x0000000e, 5), HUFF_PACK(0x00000006, 4)},
+- {HUFF_PACK(0x00003eff, 14), HUFF_PACK(0x00001f7e, 13),
+- HUFF_PACK(0x000003ff, 10), HUFF_PACK(0x0000002e, 7),
+- HUFF_PACK(0x00000004, 4), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV7_2D */
+- {{HUFF_PACK(0x00000002, 3), HUFF_PACK(0x0000000a, 4),
+- HUFF_PACK(0x0000001a, 6), HUFF_PACK(0x000001be, 9),
+- HUFF_PACK(0x000006e6, 11), HUFF_PACK(0x0000067a, 12),
+- HUFF_PACK(0x00000cf2, 13), HUFF_PACK(0x000033de, 15)},
+- {HUFF_PACK(0x0000000c, 4), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000000e, 5), HUFF_PACK(0x000000de, 8),
+- HUFF_PACK(0x00000372, 10), HUFF_PACK(0x000003d6, 11),
+- HUFF_PACK(0x00000678, 12), HUFF_PACK(0x00000cf6, 13)},
+- {HUFF_PACK(0x00000036, 6), HUFF_PACK(0x00000012, 5),
+- HUFF_PACK(0x0000003e, 6), HUFF_PACK(0x0000003c, 7),
+- HUFF_PACK(0x000001b8, 9), HUFF_PACK(0x000003d4, 11),
+- HUFF_PACK(0x0000033e, 11), HUFF_PACK(0x0000033f, 11)},
+- {HUFF_PACK(0x0000007e, 8), HUFF_PACK(0x0000006a, 7),
+- HUFF_PACK(0x0000004e, 7), HUFF_PACK(0x0000007e, 7),
+- HUFF_PACK(0x000001ba, 9), HUFF_PACK(0x000000ce, 9),
+- HUFF_PACK(0x000000f6, 9), HUFF_PACK(0x000001ee, 10)},
+- {HUFF_PACK(0x000001ef, 10), HUFF_PACK(0x0000013e, 9),
+- HUFF_PACK(0x0000007f, 8), HUFF_PACK(0x00000066, 8),
+- HUFF_PACK(0x000000d6, 8), HUFF_PACK(0x0000003e, 7),
+- HUFF_PACK(0x000000d7, 8), HUFF_PACK(0x0000009e, 8)},
+- {HUFF_PACK(0x000007ae, 12), HUFF_PACK(0x000001e8, 10),
+- HUFF_PACK(0x000001e9, 10), HUFF_PACK(0x0000027e, 10),
+- HUFF_PACK(0x00000032, 7), HUFF_PACK(0x00000018, 6),
+- HUFF_PACK(0x00000026, 6), HUFF_PACK(0x00000034, 6)},
+- {HUFF_PACK(0x00000cf3, 13), HUFF_PACK(0x000007aa, 12),
+- HUFF_PACK(0x000007ab, 12), HUFF_PACK(0x0000027f, 10),
+- HUFF_PACK(0x000001bf, 9), HUFF_PACK(0x0000001b, 6),
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000000b, 4)},
+- {HUFF_PACK(0x000033df, 15), HUFF_PACK(0x000019ee, 14),
+- HUFF_PACK(0x000007af, 12), HUFF_PACK(0x000006e7, 11),
+- HUFF_PACK(0x000001bb, 9), HUFF_PACK(0x0000007f, 7),
+- HUFF_PACK(0x00000008, 4), HUFF_PACK(0x00000000, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV9_2D */
+- {{HUFF_PACK(0x0000000e, 4), HUFF_PACK(0x00000008, 4),
+- HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x000001fe, 9),
+- HUFF_PACK(0x000001ba, 10), HUFF_PACK(0x00000dbe, 12),
+- HUFF_PACK(0x00000d7e, 13), HUFF_PACK(0x00001af6, 14),
+- HUFF_PACK(0x00007fec, 15), HUFF_PACK(0x0001ffb6, 17)},
+- {HUFF_PACK(0x0000000a, 4), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x0000000c, 5), HUFF_PACK(0x00000036, 7),
+- HUFF_PACK(0x000000de, 9), HUFF_PACK(0x000005fe, 11),
+- HUFF_PACK(0x000006be, 12), HUFF_PACK(0x00001b7e, 13),
+- HUFF_PACK(0x00007fee, 15), HUFF_PACK(0x00006dfe, 15)},
+- {HUFF_PACK(0x0000001e, 6), HUFF_PACK(0x0000000e, 5),
+- HUFF_PACK(0x0000000a, 5), HUFF_PACK(0x0000006a, 7),
+- HUFF_PACK(0x000001ae, 9), HUFF_PACK(0x000006fe, 11),
+- HUFF_PACK(0x00000376, 11), HUFF_PACK(0x00000dfe, 13),
+- HUFF_PACK(0x00000dff, 13), HUFF_PACK(0x00000d7f, 13)},
+- {HUFF_PACK(0x000000b6, 8), HUFF_PACK(0x0000005e, 7),
+- HUFF_PACK(0x0000007c, 7), HUFF_PACK(0x0000006e, 7),
+- HUFF_PACK(0x0000006a, 8), HUFF_PACK(0x0000016a, 9),
+- HUFF_PACK(0x00000ffe, 12), HUFF_PACK(0x00000dfe, 12),
+- HUFF_PACK(0x00000ffc, 12), HUFF_PACK(0x00001bfe, 13)},
+- {HUFF_PACK(0x0000035e, 10), HUFF_PACK(0x000001b6, 9),
+- HUFF_PACK(0x0000005e, 8), HUFF_PACK(0x000000b4, 8),
+- HUFF_PACK(0x0000006c, 7), HUFF_PACK(0x0000017e, 9),
+- HUFF_PACK(0x0000036e, 10), HUFF_PACK(0x000003ee, 10),
+- HUFF_PACK(0x0000037e, 11), HUFF_PACK(0x00000377, 11)},
+- {HUFF_PACK(0x00000fff, 12), HUFF_PACK(0x000001ae, 10),
+- HUFF_PACK(0x000001be, 10), HUFF_PACK(0x000001f6, 9),
+- HUFF_PACK(0x000001be, 9), HUFF_PACK(0x000000da, 8),
+- HUFF_PACK(0x000000fe, 8), HUFF_PACK(0x0000016b, 9),
+- HUFF_PACK(0x000000d6, 9), HUFF_PACK(0x0000037e, 10)},
+- {HUFF_PACK(0x000017fe, 13), HUFF_PACK(0x00000bfe, 12),
+- HUFF_PACK(0x000007de, 11), HUFF_PACK(0x000006de, 11),
+- HUFF_PACK(0x000001b8, 10), HUFF_PACK(0x000000d6, 8),
+- HUFF_PACK(0x0000002e, 7), HUFF_PACK(0x00000034, 7),
+- HUFF_PACK(0x000000de, 8), HUFF_PACK(0x000000be, 8)},
+- {HUFF_PACK(0x00007fef, 15), HUFF_PACK(0x000006bc, 12),
+- HUFF_PACK(0x00001bff, 13), HUFF_PACK(0x00001ffa, 13),
+- HUFF_PACK(0x000001b9, 10), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x000000fa, 8), HUFF_PACK(0x0000002e, 6),
+- HUFF_PACK(0x00000034, 6), HUFF_PACK(0x0000001f, 6)},
+- {HUFF_PACK(0x00006dff, 15), HUFF_PACK(0x00001af7, 14),
+- HUFF_PACK(0x000036fe, 14), HUFF_PACK(0x000006fe, 12),
+- HUFF_PACK(0x00000fbe, 12), HUFF_PACK(0x0000035f, 10),
+- HUFF_PACK(0x000000b7, 8), HUFF_PACK(0x0000002c, 6),
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x00000009, 4)},
+- {HUFF_PACK(0x0001ffb7, 17), HUFF_PACK(0x0000ffda, 16),
+- HUFF_PACK(0x00000d7a, 13), HUFF_PACK(0x000017ff, 13),
+- HUFF_PACK(0x00000fbf, 12), HUFF_PACK(0x000002fe, 10),
+- HUFF_PACK(0x0000005f, 8), HUFF_PACK(0x00000016, 6),
+- HUFF_PACK(0x00000004, 4), HUFF_PACK(0x00000000, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- }}}}};
+-
+-const HUFF_ICC_TABLE fdk_sacenc_huffICCTab = {
+- {/* h1D[2][8] */
+- {HUFF_PACK(0x00000000, 1), HUFF_PACK(0x00000002, 2),
+- HUFF_PACK(0x00000006, 3), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000003e, 6),
+- HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x0000007f, 7)},
+- {HUFF_PACK(0x00000000, 1), HUFF_PACK(0x00000002, 2),
+- HUFF_PACK(0x00000006, 3), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000003e, 6),
+- HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x0000007f, 7)}},
+- { /* HUFF_ICC_TAB_2D */
+- { /* HUFF_ICC_TAB_2D[0][] */
+- {/* HUFF_ICC_TAB_2D[0][0] */
+- {
+- /* LAV1_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x00000006, 3)},
+- {HUFF_PACK(0x00000007, 3), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV3_2D */
+- {{HUFF_PACK(0x00000002, 2), HUFF_PACK(0x00000000, 2),
+- HUFF_PACK(0x0000000a, 5), HUFF_PACK(0x0000007e, 8)},
+- {HUFF_PACK(0x0000000e, 5), HUFF_PACK(0x00000004, 4),
+- HUFF_PACK(0x00000016, 6), HUFF_PACK(0x000003fe, 11)},
+- {HUFF_PACK(0x000001fe, 10), HUFF_PACK(0x000000fe, 9),
+- HUFF_PACK(0x0000003e, 7), HUFF_PACK(0x0000001e, 6)},
+- {HUFF_PACK(0x000003ff, 11), HUFF_PACK(0x00000017, 6),
+- HUFF_PACK(0x00000006, 4), HUFF_PACK(0x00000003, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV5_2D */
+- {{HUFF_PACK(0x00000000, 2), HUFF_PACK(0x00000002, 3),
+- HUFF_PACK(0x0000000c, 5), HUFF_PACK(0x0000006a, 7),
+- HUFF_PACK(0x000000dc, 8), HUFF_PACK(0x000006ee, 11)},
+- {HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x0000000d, 5), HUFF_PACK(0x0000001e, 6),
+- HUFF_PACK(0x000001ae, 9), HUFF_PACK(0x0000ddff, 16)},
+- {HUFF_PACK(0x000000de, 8), HUFF_PACK(0x0000007e, 7),
+- HUFF_PACK(0x0000001f, 6), HUFF_PACK(0x000001be, 9),
+- HUFF_PACK(0x00006efe, 15), HUFF_PACK(0x0000ddfe, 16)},
+- {HUFF_PACK(0x0000377e, 14), HUFF_PACK(0x00001bbe, 13),
+- HUFF_PACK(0x00000dde, 12), HUFF_PACK(0x000001bf, 9),
+- HUFF_PACK(0x000000d6, 8), HUFF_PACK(0x00000376, 10)},
+- {HUFF_PACK(0x0000ddff, 16), HUFF_PACK(0x0000ddff, 16),
+- HUFF_PACK(0x000001ba, 9), HUFF_PACK(0x00000034, 6),
+- HUFF_PACK(0x0000003e, 6), HUFF_PACK(0x0000000e, 5)},
+- {HUFF_PACK(0x0000ddff, 16), HUFF_PACK(0x000001af, 9),
+- HUFF_PACK(0x0000007f, 7), HUFF_PACK(0x00000036, 6),
+- HUFF_PACK(0x0000000e, 4), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x0000ddff, 16) /* escape */
+- },
+- {
+- /* LAV7_2D */
+- {{HUFF_PACK(0x00000000, 2), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x0000002e, 6), HUFF_PACK(0x00000044, 7),
+- HUFF_PACK(0x00000086, 8), HUFF_PACK(0x0000069e, 11),
+- HUFF_PACK(0x0000043e, 11), HUFF_PACK(0x0000087a, 12)},
+- {HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000002a, 6), HUFF_PACK(0x00000046, 7),
+- HUFF_PACK(0x0000015e, 9), HUFF_PACK(0x00000047, 7),
+- HUFF_PACK(0x0000034a, 10), HUFF_PACK(0x0000087b, 12)},
+- {HUFF_PACK(0x000000d6, 8), HUFF_PACK(0x00000026, 6),
+- HUFF_PACK(0x0000002f, 6), HUFF_PACK(0x000000d7, 8),
+- HUFF_PACK(0x0000006a, 7), HUFF_PACK(0x0000034e, 10),
+- HUFF_PACK(0x0000087b, 12), HUFF_PACK(0x0000087b, 12)},
+- {HUFF_PACK(0x000002be, 10), HUFF_PACK(0x000001a6, 9),
+- HUFF_PACK(0x000001be, 9), HUFF_PACK(0x00000012, 5),
+- HUFF_PACK(0x000001bf, 9), HUFF_PACK(0x0000087b, 12),
+- HUFF_PACK(0x0000087b, 12), HUFF_PACK(0x0000087b, 12)},
+- {HUFF_PACK(0x0000087b, 12), HUFF_PACK(0x0000087b, 12),
+- HUFF_PACK(0x0000087b, 12), HUFF_PACK(0x0000087b, 12),
+- HUFF_PACK(0x00000036, 6), HUFF_PACK(0x000000d0, 8),
+- HUFF_PACK(0x0000043c, 11), HUFF_PACK(0x0000043f, 11)},
+- {HUFF_PACK(0x0000087b, 12), HUFF_PACK(0x0000087b, 12),
+- HUFF_PACK(0x0000087b, 12), HUFF_PACK(0x0000034b, 10),
+- HUFF_PACK(0x00000027, 6), HUFF_PACK(0x00000020, 6),
+- HUFF_PACK(0x00000042, 7), HUFF_PACK(0x000000d1, 8)},
+- {HUFF_PACK(0x0000087b, 12), HUFF_PACK(0x0000087b, 12),
+- HUFF_PACK(0x000002bf, 10), HUFF_PACK(0x000000de, 8),
+- HUFF_PACK(0x000000ae, 8), HUFF_PACK(0x00000056, 7),
+- HUFF_PACK(0x00000016, 5), HUFF_PACK(0x00000014, 5)},
+- {HUFF_PACK(0x0000087b, 12), HUFF_PACK(0x0000069f, 11),
+- HUFF_PACK(0x000001a4, 9), HUFF_PACK(0x0000010e, 9),
+- HUFF_PACK(0x00000045, 7), HUFF_PACK(0x0000006e, 7),
+- HUFF_PACK(0x0000001f, 5), HUFF_PACK(0x00000001, 2)}},
+- HUFF_PACK(0x0000087b, 12) /* escape */
+- }},
+- {/* HUFF_ICC_TAB_2D[0][1] */
+- {
+- /* LAV1_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x00000006, 3)},
+- {HUFF_PACK(0x00000007, 3), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV3_2D */
+- {{HUFF_PACK(0x00000002, 2), HUFF_PACK(0x00000004, 4),
+- HUFF_PACK(0x0000017e, 10), HUFF_PACK(0x000002fe, 11)},
+- {HUFF_PACK(0x00000000, 2), HUFF_PACK(0x0000000e, 5),
+- HUFF_PACK(0x000000be, 9), HUFF_PACK(0x00000016, 6)},
+- {HUFF_PACK(0x0000000f, 5), HUFF_PACK(0x00000014, 6),
+- HUFF_PACK(0x0000005e, 8), HUFF_PACK(0x00000006, 4)},
+- {HUFF_PACK(0x0000002e, 7), HUFF_PACK(0x000002ff, 11),
+- HUFF_PACK(0x00000015, 6), HUFF_PACK(0x00000003, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV5_2D */
+- {{HUFF_PACK(0x00000000, 2), HUFF_PACK(0x0000001e, 5),
+- HUFF_PACK(0x000003fc, 10), HUFF_PACK(0x0000fffa, 16),
+- HUFF_PACK(0x000fff9e, 20), HUFF_PACK(0x000fff9f, 20)},
+- {HUFF_PACK(0x00000006, 3), HUFF_PACK(0x00000004, 4),
+- HUFF_PACK(0x000000be, 9), HUFF_PACK(0x00007ffe, 15),
+- HUFF_PACK(0x0007ffce, 19), HUFF_PACK(0x000000fe, 8)},
+- {HUFF_PACK(0x00000006, 4), HUFF_PACK(0x0000001e, 6),
+- HUFF_PACK(0x000003fd, 10), HUFF_PACK(0x0000fffb, 16),
+- HUFF_PACK(0x00000ffe, 12), HUFF_PACK(0x0000003e, 6)},
+- {HUFF_PACK(0x0000000a, 5), HUFF_PACK(0x0000007e, 7),
+- HUFF_PACK(0x00001ffe, 13), HUFF_PACK(0x00007fff, 15),
+- HUFF_PACK(0x0000005e, 8), HUFF_PACK(0x0000000e, 5)},
+- {HUFF_PACK(0x0000001f, 6), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x0001fff2, 17), HUFF_PACK(0x00000ffc, 12),
+- HUFF_PACK(0x0000002e, 7), HUFF_PACK(0x0000000e, 4)},
+- {HUFF_PACK(0x000000bf, 9), HUFF_PACK(0x0003ffe6, 18),
+- HUFF_PACK(0x0000fff8, 16), HUFF_PACK(0x00000ffd, 12),
+- HUFF_PACK(0x00000016, 6), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV7_2D */
+- {{HUFF_PACK(0x00000002, 2), HUFF_PACK(0x0000001e, 6),
+- HUFF_PACK(0x00000ffe, 12), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x0000fffe, 16), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x0000ffff, 16), HUFF_PACK(0x0000ffff, 16)},
+- {HUFF_PACK(0x00000006, 3), HUFF_PACK(0x00000008, 5),
+- HUFF_PACK(0x000007fe, 11), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x0000ffff, 16), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x0000ffff, 16), HUFF_PACK(0x0000005a, 8)},
+- {HUFF_PACK(0x00000006, 4), HUFF_PACK(0x0000007a, 7),
+- HUFF_PACK(0x00000164, 10), HUFF_PACK(0x00007ffa, 15),
+- HUFF_PACK(0x0000ffff, 16), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x00001fee, 13), HUFF_PACK(0x0000003c, 6)},
+- {HUFF_PACK(0x0000000e, 5), HUFF_PACK(0x000000fe, 8),
+- HUFF_PACK(0x000002ce, 11), HUFF_PACK(0x000002cf, 11),
+- HUFF_PACK(0x00007ffb, 15), HUFF_PACK(0x00001fec, 13),
+- HUFF_PACK(0x000000b0, 9), HUFF_PACK(0x0000002e, 7)},
+- {HUFF_PACK(0x0000003e, 6), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x00000165, 10), HUFF_PACK(0x00007ffc, 15),
+- HUFF_PACK(0x00001fef, 13), HUFF_PACK(0x000007fa, 11),
+- HUFF_PACK(0x000007f8, 11), HUFF_PACK(0x0000001f, 6)},
+- {HUFF_PACK(0x0000002f, 7), HUFF_PACK(0x000000f6, 8),
+- HUFF_PACK(0x00001fed, 13), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x00007ffd, 15), HUFF_PACK(0x00000ff2, 12),
+- HUFF_PACK(0x000000b1, 9), HUFF_PACK(0x0000000a, 5)},
+- {HUFF_PACK(0x00000009, 5), HUFF_PACK(0x00000166, 10),
+- HUFF_PACK(0x0000ffff, 16), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x00007ffe, 15), HUFF_PACK(0x00003ffc, 14),
+- HUFF_PACK(0x0000005b, 8), HUFF_PACK(0x0000000e, 4)},
+- {HUFF_PACK(0x0000007e, 7), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x0000ffff, 16), HUFF_PACK(0x0000ffff, 16),
+- HUFF_PACK(0x0000ffff, 16), HUFF_PACK(0x00000ff3, 12),
+- HUFF_PACK(0x000000f7, 8), HUFF_PACK(0x00000000, 2)}},
+- HUFF_PACK(0x0000ffff, 16) /* escape */
+- }}},
+- { /* HUFF_ICC_TAB_2D[1][] */
+- {/* HUFF_ICC_TAB_2D[1][0] */
+- {
+- /* LAV1_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x00000006, 3)},
+- {HUFF_PACK(0x00000007, 3), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV3_2D */
+- {{HUFF_PACK(0x00000002, 2), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000037e, 10), HUFF_PACK(0x00000dfe, 12)},
+- {HUFF_PACK(0x0000000f, 4), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x000001ba, 9), HUFF_PACK(0x000001bb, 9)},
+- {HUFF_PACK(0x000000de, 8), HUFF_PACK(0x000000dc, 8),
+- HUFF_PACK(0x000001be, 9), HUFF_PACK(0x0000001a, 5)},
+- {HUFF_PACK(0x000006fe, 11), HUFF_PACK(0x00000dff, 12),
+- HUFF_PACK(0x00000036, 6), HUFF_PACK(0x00000000, 1)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV5_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x000001b6, 9), HUFF_PACK(0x00001b7c, 13),
+- HUFF_PACK(0x0000dbfe, 16), HUFF_PACK(0x00036fff, 18)},
+- {HUFF_PACK(0x0000000e, 4), HUFF_PACK(0x0000001e, 5),
+- HUFF_PACK(0x000001be, 9), HUFF_PACK(0x00000dfe, 12),
+- HUFF_PACK(0x00036ffe, 18), HUFF_PACK(0x0000036e, 10)},
+- {HUFF_PACK(0x0000006e, 7), HUFF_PACK(0x000000fe, 8),
+- HUFF_PACK(0x000000d8, 8), HUFF_PACK(0x000036fe, 14),
+- HUFF_PACK(0x000006de, 11), HUFF_PACK(0x000000de, 8)},
+- {HUFF_PACK(0x000001fa, 9), HUFF_PACK(0x000000da, 8),
+- HUFF_PACK(0x00000dff, 12), HUFF_PACK(0x00001b7e, 13),
+- HUFF_PACK(0x000000d9, 8), HUFF_PACK(0x000000ff, 8)},
+- {HUFF_PACK(0x000003f6, 10), HUFF_PACK(0x000006fe, 11),
+- HUFF_PACK(0x00006dfe, 15), HUFF_PACK(0x0000037e, 10),
+- HUFF_PACK(0x000000fc, 8), HUFF_PACK(0x0000001a, 5)},
+- {HUFF_PACK(0x000007ee, 11), HUFF_PACK(0x0001b7fe, 17),
+- HUFF_PACK(0x00001b7d, 13), HUFF_PACK(0x000007ef, 11),
+- HUFF_PACK(0x0000003e, 6), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00036fff, 18) /* escape */
+- },
+- {
+- /* LAV7_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x0000000c, 4),
+- HUFF_PACK(0x000007ee, 11), HUFF_PACK(0x00001e7e, 13),
+- HUFF_PACK(0x00003cfe, 14), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x000079ff, 15), HUFF_PACK(0x000079ff, 15)},
+- {HUFF_PACK(0x0000000e, 4), HUFF_PACK(0x0000001a, 5),
+- HUFF_PACK(0x000001e6, 9), HUFF_PACK(0x00001fbe, 13),
+- HUFF_PACK(0x000079fe, 15), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x000079ff, 15), HUFF_PACK(0x000006fc, 11)},
+- {HUFF_PACK(0x0000006c, 7), HUFF_PACK(0x000000f6, 8),
+- HUFF_PACK(0x000001ba, 9), HUFF_PACK(0x00000dfc, 12),
+- HUFF_PACK(0x00000dfd, 12), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x00000f3e, 12), HUFF_PACK(0x000001bb, 9)},
+- {HUFF_PACK(0x000000dc, 8), HUFF_PACK(0x000001fe, 9),
+- HUFF_PACK(0x0000036e, 10), HUFF_PACK(0x000003fe, 10),
+- HUFF_PACK(0x000079ff, 15), HUFF_PACK(0x00000fde, 12),
+- HUFF_PACK(0x000001ee, 9), HUFF_PACK(0x000000f2, 8)},
+- {HUFF_PACK(0x000001fa, 9), HUFF_PACK(0x000003f6, 10),
+- HUFF_PACK(0x000001be, 9), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x00001fbf, 13), HUFF_PACK(0x000003ce, 10),
+- HUFF_PACK(0x000003ff, 10), HUFF_PACK(0x000000de, 8)},
+- {HUFF_PACK(0x00000078, 7), HUFF_PACK(0x000000da, 8),
+- HUFF_PACK(0x000079ff, 15), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x000006fd, 11), HUFF_PACK(0x0000036c, 10),
+- HUFF_PACK(0x000001ef, 9), HUFF_PACK(0x000000fe, 8)},
+- {HUFF_PACK(0x0000036f, 10), HUFF_PACK(0x00000dfe, 12),
+- HUFF_PACK(0x000079ff, 15), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x000079ff, 15), HUFF_PACK(0x0000036d, 10),
+- HUFF_PACK(0x000000fc, 8), HUFF_PACK(0x0000003e, 6)},
+- {HUFF_PACK(0x00000dff, 12), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x000079ff, 15), HUFF_PACK(0x000079ff, 15),
+- HUFF_PACK(0x000079ff, 15), HUFF_PACK(0x0000079e, 11),
+- HUFF_PACK(0x0000007a, 7), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x000079ff, 15) /* escape */
+- }},
+- {/* HUFF_ICC_TAB_2D[1][1] */
+- {
+- /* LAV1_2D */
+- {{HUFF_PACK(0x00000000, 1), HUFF_PACK(0x00000006, 3)},
+- {HUFF_PACK(0x00000007, 3), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV3_2D */
+- {{HUFF_PACK(0x00000002, 2), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x000000fc, 8), HUFF_PACK(0x00000fde, 12)},
+- {HUFF_PACK(0x0000000c, 4), HUFF_PACK(0x0000000d, 4),
+- HUFF_PACK(0x000001fe, 9), HUFF_PACK(0x000007ee, 11)},
+- {HUFF_PACK(0x000001fa, 9), HUFF_PACK(0x000001ff, 9),
+- HUFF_PACK(0x000000fe, 8), HUFF_PACK(0x0000003e, 6)},
+- {HUFF_PACK(0x00000fdf, 12), HUFF_PACK(0x000003f6, 10),
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x00000000, 1)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV5_2D */
+- {{HUFF_PACK(0x00000000, 2), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000003a, 7), HUFF_PACK(0x00000676, 11),
+- HUFF_PACK(0x000019fe, 13), HUFF_PACK(0x0000cebe, 16)},
+- {HUFF_PACK(0x0000000f, 4), HUFF_PACK(0x00000002, 3),
+- HUFF_PACK(0x0000001e, 6), HUFF_PACK(0x000000fe, 9),
+- HUFF_PACK(0x000019d6, 13), HUFF_PACK(0x0000675e, 15)},
+- {HUFF_PACK(0x0000003e, 7), HUFF_PACK(0x00000032, 6),
+- HUFF_PACK(0x00000018, 5), HUFF_PACK(0x0000033e, 10),
+- HUFF_PACK(0x00000cfe, 12), HUFF_PACK(0x00000677, 11)},
+- {HUFF_PACK(0x00000674, 11), HUFF_PACK(0x0000019c, 9),
+- HUFF_PACK(0x000000ff, 9), HUFF_PACK(0x0000003b, 7),
+- HUFF_PACK(0x0000001c, 6), HUFF_PACK(0x0000007e, 8)},
+- {HUFF_PACK(0x000033fe, 14), HUFF_PACK(0x000033ff, 14),
+- HUFF_PACK(0x00000cea, 12), HUFF_PACK(0x00000066, 7),
+- HUFF_PACK(0x0000001a, 5), HUFF_PACK(0x00000006, 4)},
+- {HUFF_PACK(0x0000cebf, 16), HUFF_PACK(0x000033ae, 14),
+- HUFF_PACK(0x0000067e, 11), HUFF_PACK(0x0000019e, 9),
+- HUFF_PACK(0x0000001b, 5), HUFF_PACK(0x00000002, 2)}},
+- HUFF_PACK(0x00000000, 0) /* escape */
+- },
+- {
+- /* LAV7_2D */
+- {{HUFF_PACK(0x00000002, 2), HUFF_PACK(0x00000002, 4),
+- HUFF_PACK(0x000000fe, 9), HUFF_PACK(0x000007be, 12),
+- HUFF_PACK(0x00000ffc, 13), HUFF_PACK(0x00000ffd, 13),
+- HUFF_PACK(0x00001efe, 15), HUFF_PACK(0x00003dfe, 16)},
+- {HUFF_PACK(0x00000004, 4), HUFF_PACK(0x00000000, 3),
+- HUFF_PACK(0x0000003c, 7), HUFF_PACK(0x000000f6, 10),
+- HUFF_PACK(0x000001da, 11), HUFF_PACK(0x000003fe, 12),
+- HUFF_PACK(0x00003dfe, 15), HUFF_PACK(0x00003dff, 16)},
+- {HUFF_PACK(0x0000003c, 8), HUFF_PACK(0x0000003e, 7),
+- HUFF_PACK(0x0000000a, 5), HUFF_PACK(0x0000003a, 8),
+- HUFF_PACK(0x000003de, 11), HUFF_PACK(0x000007be, 13),
+- HUFF_PACK(0x00000f7e, 14), HUFF_PACK(0x00001efe, 14)},
+- {HUFF_PACK(0x000001de, 11), HUFF_PACK(0x000000ec, 10),
+- HUFF_PACK(0x0000007e, 9), HUFF_PACK(0x0000000c, 5),
+- HUFF_PACK(0x000001ee, 10), HUFF_PACK(0x00000f7e, 13),
+- HUFF_PACK(0x000007fc, 12), HUFF_PACK(0x00003dff, 15)},
+- {HUFF_PACK(0x00007ffe, 16), HUFF_PACK(0x000003be, 12),
+- HUFF_PACK(0x000000fe, 10), HUFF_PACK(0x000001fe, 10),
+- HUFF_PACK(0x0000001a, 6), HUFF_PACK(0x0000001c, 7),
+- HUFF_PACK(0x000007fd, 12), HUFF_PACK(0x00000ffe, 13)},
+- {HUFF_PACK(0x00003dff, 16), HUFF_PACK(0x000003bf, 12),
+- HUFF_PACK(0x00001ffe, 14), HUFF_PACK(0x000003ff, 12),
+- HUFF_PACK(0x0000003e, 8), HUFF_PACK(0x0000001b, 6),
+- HUFF_PACK(0x0000007e, 8), HUFF_PACK(0x000000f6, 9)},
+- {HUFF_PACK(0x00007fff, 16), HUFF_PACK(0x00003dff, 16),
+- HUFF_PACK(0x00003ffe, 15), HUFF_PACK(0x000001db, 11),
+- HUFF_PACK(0x000000ee, 10), HUFF_PACK(0x0000007a, 8),
+- HUFF_PACK(0x0000000e, 5), HUFF_PACK(0x0000000b, 5)},
+- {HUFF_PACK(0x00003dff, 16), HUFF_PACK(0x00003dff, 16),
+- HUFF_PACK(0x000003de, 12), HUFF_PACK(0x000001fe, 11),
+- HUFF_PACK(0x000001ee, 11), HUFF_PACK(0x0000007a, 9),
+- HUFF_PACK(0x00000006, 5), HUFF_PACK(0x00000003, 2)}},
+- HUFF_PACK(0x00003dff, 16) /* escape */
+- }}}}};
+-
+-const HUFF_PT0_TABLE fdk_sacenc_huffPart0Tab = {
+- {/* CLD */
+- HUFF_PACK(0x00000052, 8), HUFF_PACK(0x000000ae, 9),
+- HUFF_PACK(0x000000af, 9), HUFF_PACK(0x00000028, 7),
+- HUFF_PACK(0x0000006e, 7), HUFF_PACK(0x00000036, 6),
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x0000000c, 4), HUFF_PACK(0x0000000a, 4),
+- HUFF_PACK(0x00000002, 4), HUFF_PACK(0x00000016, 5),
+- HUFF_PACK(0x00000012, 5), HUFF_PACK(0x00000017, 5),
+- HUFF_PACK(0x00000000, 4), HUFF_PACK(0x00000004, 4),
+- HUFF_PACK(0x00000006, 4), HUFF_PACK(0x00000008, 4),
+- HUFF_PACK(0x00000007, 4), HUFF_PACK(0x00000003, 4),
+- HUFF_PACK(0x00000001, 4), HUFF_PACK(0x0000001a, 5),
+- HUFF_PACK(0x00000013, 5), HUFF_PACK(0x0000003e, 6),
+- HUFF_PACK(0x00000016, 6), HUFF_PACK(0x00000017, 6),
+- HUFF_PACK(0x0000006f, 7), HUFF_PACK(0x0000002a, 7),
+- HUFF_PACK(0x00000056, 8), HUFF_PACK(0x00000053, 8),
+- HUFF_PACK(0x0000003f, 6)},
+- {/* ICC */
+- HUFF_PACK(0x0000001e, 5), HUFF_PACK(0x0000000e, 4),
+- HUFF_PACK(0x00000006, 3), HUFF_PACK(0x00000000, 2),
+- HUFF_PACK(0x00000002, 2), HUFF_PACK(0x00000001, 2),
+- HUFF_PACK(0x0000003e, 6), HUFF_PACK(0x0000003f, 6)}};
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+diff --git a/libSACenc/src/sacenc_huff_tab.h b/libSACenc/src/sacenc_huff_tab.h
+deleted file mode 100644
+index 7d6c331..0000000
+--- a/libSACenc/src/sacenc_huff_tab.h
++++ /dev/null
+@@ -1,222 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Markus Lohwasser
+-
+- Description: SAC-Encoder constant huffman tables
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_HUFF_TAB_H
+-#define SACENC_HUFF_TAB_H
+-
+-/* Includes ******************************************************************/
+-#include "machine_type.h"
+-
+-/* Defines *******************************************************************/
+-#define HUFF_PACK(a, b) \
+- { \
+- ((((ULONG)a) & 0x00FFFFFF) << 8) | (((ULONG)b) & 0xFF) \
+- } /*!< Pack huffman value and length information. */
+-#define HUFF_VALUE(a) \
+- (((a.packed >> 8) & 0x00FFFFFF)) /*!< Return value from packed table entry. \
+- */
+-#define HUFF_LENGTH(a) \
+- ((a.packed & 0xFF)) /*!< Return length from packed table entry. */
+-
+-/* Data Types ****************************************************************/
+-/**
+- * \brief This struct contains packed huffman entries.
+- *
+- * The packed entry consist of hffman value and length information.
+- *
+- * |---------------------------------|
+- * | value | length |
+- * |---------------------------------|
+- * |<------- 31...8 ------->|< 7..0 >|
+- */
+-typedef struct {
+- ULONG packed; /*! Packed huffman entry:
+- - lower 8 bit are reservoed for length information
+- - upper 24 bit contains huffman value */
+-} HUFF_ENTRY;
+-
+-typedef struct {
+- HUFF_ENTRY entry[2][2];
+- HUFF_ENTRY escape;
+-
+-} LAV1_2D;
+-
+-typedef struct {
+- HUFF_ENTRY entry[4][4];
+- HUFF_ENTRY escape;
+-
+-} LAV3_2D;
+-
+-typedef struct {
+- HUFF_ENTRY entry[6][6];
+- HUFF_ENTRY escape;
+-
+-} LAV5_2D;
+-
+-typedef struct {
+- HUFF_ENTRY entry[7][7];
+- HUFF_ENTRY escape;
+-
+-} LAV6_2D;
+-
+-typedef struct {
+- HUFF_ENTRY entry[8][8];
+- HUFF_ENTRY escape;
+-
+-} LAV7_2D;
+-
+-typedef struct {
+- HUFF_ENTRY entry[10][10];
+- HUFF_ENTRY escape;
+-
+-} LAV9_2D;
+-
+-typedef struct {
+- HUFF_ENTRY entry[13][13];
+- HUFF_ENTRY escape;
+-
+-} LAV12_2D;
+-
+-typedef struct {
+- LAV3_2D lav3;
+- LAV5_2D lav5;
+- LAV7_2D lav7;
+- LAV9_2D lav9;
+-
+-} HUFF_CLD_TAB_2D;
+-
+-typedef struct {
+- LAV1_2D lav1;
+- LAV3_2D lav3;
+- LAV5_2D lav5;
+- LAV7_2D lav7;
+-
+-} HUFF_ICC_TAB_2D;
+-
+-typedef struct {
+- HUFF_ENTRY h1D[2][31];
+- HUFF_CLD_TAB_2D h2D[2][2];
+-
+-} HUFF_CLD_TABLE;
+-
+-typedef struct {
+- HUFF_ENTRY h1D[2][8];
+- HUFF_ICC_TAB_2D h2D[2][2];
+-
+-} HUFF_ICC_TABLE;
+-
+-typedef struct {
+- HUFF_ENTRY cld[31];
+- HUFF_ENTRY icc[8];
+-
+-} HUFF_PT0_TABLE;
+-
+-typedef HUFF_ENTRY HUFF_RES_TABLE[5][8];
+-
+-/* Constants *****************************************************************/
+-extern const HUFF_CLD_TABLE fdk_sacenc_huffCLDTab;
+-extern const HUFF_ICC_TABLE fdk_sacenc_huffICCTab;
+-extern const HUFF_PT0_TABLE fdk_sacenc_huffPart0Tab;
+-
+-/* Function / Class Declarations *********************************************/
+-
+-#endif /* SACENC_HUFF_TAB_H */
+diff --git a/libSACenc/src/sacenc_lib.cpp b/libSACenc/src/sacenc_lib.cpp
+deleted file mode 100644
+index d6a1658..0000000
+--- a/libSACenc/src/sacenc_lib.cpp
++++ /dev/null
+@@ -1,2042 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Max Neuendorf
+-
+- Description: Encoder Library Interface
+- Interface to Spacial Audio Coding Encoder lib
+-
+-*******************************************************************************/
+-
+-/****************************************************************************
+-\file
+-Description of file contents
+-******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_lib.h"
+-#include "sacenc_const.h"
+-#include "genericStds.h"
+-#include "FDK_core.h"
+-#include "sacenc_tree.h"
+-#include "sacenc_bitstream.h"
+-#include "sacenc_onsetdetect.h"
+-#include "sacenc_framewindowing.h"
+-#include "sacenc_filter.h"
+-#include "sacenc_paramextract.h"
+-#include "sacenc_staticgain.h"
+-#include "sacenc_delay.h"
+-#include "sacenc_dmx_tdom_enh.h"
+-#include "sacenc_vectorfunctions.h"
+-#include "qmf.h"
+-
+-/* Defines *******************************************************************/
+-
+-/* Encoder library info */
+-#define SACENC_LIB_VL0 2
+-#define SACENC_LIB_VL1 0
+-#define SACENC_LIB_VL2 0
+-#define SACENC_LIB_TITLE "MPEG Surround Encoder"
+-#ifdef __ANDROID__
+-#define SACENC_LIB_BUILD_DATE ""
+-#define SACENC_LIB_BUILD_TIME ""
+-#else
+-#define SACENC_LIB_BUILD_DATE __DATE__
+-#define SACENC_LIB_BUILD_TIME __TIME__
+-#endif
+-
+-#define MAX_MPEGS_BYTES (1 << 14)
+-#define MAX_SSC_BYTES (1 << 6)
+-
+-#define MAX_SPACE_TREE_CHANNELS 2
+-#define NUM_KEEP_WINDOWS 3
+-
+-/* Data Types ****************************************************************/
+-typedef struct {
+- MP4SPACEENC_MODE encMode;
+- MP4SPACEENC_BANDS_CONFIG nParamBands;
+- MP4SPACEENC_QUANTMODE quantMode;
+- UCHAR bUseCoarseQuant;
+- UCHAR bLdMode;
+- UCHAR bTimeDomainDmx;
+- UINT sampleRate;
+- UINT frameTimeSlots; /* e.g. 32 when used with HE-AAC */
+- UINT independencyFactor; /* how often should we set the independency flag */
+- INT timeAlignment; /* additional delay for downmix */
+-
+-} MP4SPACEENC_SETUP, *HANDLE_MP4SPACEENC_SETUP;
+-
+-struct ENC_CONFIG_SETUP {
+- UCHAR bEncMode_212;
+- UCHAR maxHybridInStaticSlots;
+- LONG maxSamplingrate;
+- INT maxAnalysisLengthTimeSlots;
+- INT maxHybridBands;
+- INT maxQmfBands;
+- INT maxChIn;
+- INT maxFrameTimeSlots;
+- INT maxFrameLength;
+- INT maxChOut;
+- INT maxChTotOut;
+-};
+-
+-struct MP4SPACE_ENCODER {
+- MP4SPACEENC_SETUP user;
+-
+- ENC_CONFIG_SETUP setup; /* describe allocated instance */
+-
+- HANDLE_FRAMEWINDOW
+- hFrameWindow; /* Windowing, only created+updated, but not used */
+- INT nSamplesValid; /* Input Buffer Handling */
+-
+- /* Routing Sensible Switches/Variables */
+- MP4SPACEENC_BANDS_CONFIG nParamBands;
+- UCHAR useTimeDomDownmix;
+-
+- /* not Routing Sensible Switches/Varibles - must be contained in Check */
+- MP4SPACEENC_MODE encMode;
+- UCHAR bEncMode_212_only;
+-
+- /* not Routing Sensible Switches/Varibles + lower Classes */
+- UCHAR useFrameKeep;
+- UINT independencyFactor;
+- UINT nSampleRate;
+- UCHAR nInputChannels;
+- UCHAR nOutputChannels;
+- UCHAR nFrameTimeSlots; /* e.g. 32 when used with HE-AAC */
+- UCHAR nQmfBands;
+- UCHAR nHybridBands;
+- UINT nFrameLength; /* number of output waveform samples/channel/frame */
+-
+- /* not Routing Sensible Switches/Varibles + lower Classes, secondary computed
+- */
+- INT nSamplesNext;
+- INT nAnalysisLengthTimeSlots;
+- INT nAnalysisLookaheadTimeSlots;
+- INT nUpdateHybridPositionTimeSlots;
+- INT *pnOutputBits;
+- INT nInputDelay;
+- INT nOutputBufferDelay;
+- INT nSurroundAnalysisBufferDelay;
+- INT nBitstreamDelayBuffer;
+- INT nBitstreamBufferRead;
+- INT nBitstreamBufferWrite;
+- INT nDiscardOutFrames;
+- INT avoid_keep;
+-
+- /* not Routing Sensible Switches/Varibles -> moved to lower Classes */
+- UCHAR useCoarseQuantCld; /* Only Used in SpaceTreeSetup */
+- UCHAR useCoarseQuantIcc; /* Only Used in SpaceTreeSetup */
+- UCHAR useCoarseQuantCpc; /* Only Used in SpaceTreeSetup */
+- UCHAR useCoarseQuantArbDmx; /* ArbitraryDmx,... not available yet */
+- MP4SPACEENC_QUANTMODE
+- quantMode; /* Used for quanitzation and in bitstream writer */
+- INT coreCoderDelay; /* Used in delay compensation */
+- INT timeAlignment; /* Used in delay compensation */
+-
+- /* Local Processing Variables */
+- INT independencyCount;
+- INT independencyFlag;
+- INT **ppTrCurrPos; /* belongs somehow to Onset Detection */
+- INT trPrevPos[2 * MAX_NUM_TRANS]; /* belongs somehow to Onset Detection */
+-
+- FRAMEWIN_LIST frameWinList;
+- SPATIALFRAME saveFrame;
+-
+- /* Module-Handles */
+- SPACE_TREE_SETUP spaceTreeSetup;
+- MPEG4SPACEENC_SSCBUF sscBuf;
+- FIXP_WIN *pFrameWindowAna__FDK[MAX_NUM_PARAMS];
+- HANDLE_QMF_FILTER_BANK *phQmfFiltIn__FDK;
+- HANDLE_DC_FILTER phDCFilterSigIn[SACENC_MAX_INPUT_CHANNELS];
+- HANDLE_ONSET_DETECT phOnset[SACENC_MAX_INPUT_CHANNELS];
+- HANDLE_SPACE_TREE hSpaceTree;
+- HANDLE_BSF_INSTANCE hBitstreamFormatter;
+- HANDLE_STATIC_GAIN_CONFIG hStaticGainConfig;
+- HANDLE_STATIC_GAIN hStaticGain;
+- HANDLE_DELAY hDelay;
+-
+- /* enhanced time domain downmix (for stereo input) */
+- HANDLE_ENHANCED_TIME_DOMAIN_DMX hEnhancedTimeDmx;
+-
+- /* Data Buffers */
+- INT_PCM **ppTimeSigIn__FDK;
+- INT_PCM **ppTimeSigDelayIn__FDK;
+- INT_PCM **ppTimeSigOut__FDK;
+- FIXP_DPK ***pppHybridIn__FDK;
+- FIXP_DPK ***pppHybridInStatic__FDK;
+- FIXP_DPK ***pppProcDataIn__FDK;
+- INT_PCM *pOutputDelayBuffer__FDK;
+-
+- UCHAR **ppBitstreamDelayBuffer;
+-
+- UCHAR *pParameterBand2HybridBandOffset;
+- INT staticGainScale;
+-
+- INT *pEncoderInputChScale;
+- INT *staticTimeDomainDmxInScale;
+-};
+-
+-/* Constants *****************************************************************/
+-static const UCHAR pValidBands_Ld[8] = {4, 5, 7, 9, 12, 15, 23, 40};
+-
+-static const UCHAR qmf2qmf[] = /* Bypass the HybridAnylyis/Synthesis*/
+- {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, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+- 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
+- 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
+- 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
+- 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
+- 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
+- 120, 121, 122, 123, 124, 125, 126, 127};
+-
+-/* Function / Class Declarations *********************************************/
+-static FDK_SACENC_ERROR mp4SpaceEnc_create(
+- HANDLE_MP4SPACE_ENCODER *phMp4SpaceEnc);
+-
+-static FDK_SACENC_ERROR FillSpatialSpecificConfig(
+- const HANDLE_MP4SPACE_ENCODER hEnc, SPATIALSPECIFICCONFIG *const hSsc);
+-
+-static FDK_SACENC_ERROR mp4SpaceEnc_FillSpaceTreeSetup(
+- const HANDLE_MP4SPACE_ENCODER hEnc,
+- SPACE_TREE_SETUP *const hSpaceTreeSetup);
+-
+-static FDK_SACENC_ERROR mp4SpaceEnc_InitDelayCompensation(
+- HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc, const INT coreCoderDelay);
+-
+-static FDK_SACENC_ERROR mp4SpaceEnc_InitDefault(
+- HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc);
+-
+-static DECORRCONFIG mp4SpaceEnc_GetDecorrConfig(const MP4SPACEENC_MODE encMode);
+-
+-static FDK_SACENC_ERROR mp4SpaceEnc_InitNumParamBands(
+- HANDLE_MP4SPACE_ENCODER hEnc, const MP4SPACEENC_BANDS_CONFIG nParamBands);
+-
+-/* Function / Class Definition ***********************************************/
+-static UINT mp4SpaceEnc_GetNumQmfBands(const UINT nSampleRate) {
+- UINT nQmfBands = 0;
+-
+- if (nSampleRate < 27713)
+- nQmfBands = 32;
+- else if (nSampleRate < 55426)
+- nQmfBands = 64;
+-
+- return nQmfBands;
+-}
+-
+-static UINT updateQmfFlags(const UINT flags, const INT keepStates) {
+- UINT qmfFlags = flags;
+-
+- qmfFlags = (qmfFlags & (~(UINT)QMF_FLAG_LP));
+- qmfFlags = (qmfFlags | QMF_FLAG_MPSLDFB);
+- qmfFlags = (keepStates) ? (qmfFlags | QMF_FLAG_KEEP_STATES)
+- : (qmfFlags & (~(UINT)QMF_FLAG_KEEP_STATES));
+-
+- return qmfFlags;
+-}
+-
+-static INT freq2HybridBand(const UINT nFrequency, const UINT nSampleRate,
+- const UINT nQmfBands) {
+- /*
+- nQmfSlotWidth = (nSampleRate/2) / nQmfBands;
+- nQmfBand = nFrequency / nQmfSlotWidth;
+- */
+- int nHybridBand = -1;
+- int scale = 0;
+- const FIXP_DBL temp = fDivNorm((FIXP_DBL)(2 * nFrequency * nQmfBands),
+- (FIXP_DBL)nSampleRate, &scale);
+- const int nQmfBand = scaleValue(temp, scale - (DFRACT_BITS - 1));
+-
+- if ((nQmfBand > -1) && (nQmfBand < (int)nQmfBands)) {
+- nHybridBand = qmf2qmf[nQmfBand];
+- }
+-
+- return nHybridBand;
+-}
+-
+-/*
+- * Examine buffer descriptor regarding choosen type.
+- *
+- * \param pBufDesc Pointer to buffer descriptor
+- * \param type Buffer type to look for.
+-
+- * \return - Buffer descriptor index.
+- * -1, if there is no entry available.
+- */
+-static INT getBufDescIdx(const FDK_bufDescr *pBufDesc, const UINT type) {
+- INT i, idx = -1;
+-
+- for (i = 0; i < (int)pBufDesc->numBufs; i++) {
+- if (pBufDesc->pBufType[i] == type) {
+- idx = i;
+- break;
+- }
+- }
+- return idx;
+-}
+-
+-FDK_SACENC_ERROR FDK_sacenc_open(HANDLE_MP4SPACE_ENCODER *phMp4SpaceEnc) {
+- return mp4SpaceEnc_create(phMp4SpaceEnc);
+-}
+-
+-static FDK_SACENC_ERROR mp4SpaceEnc_create(
+- HANDLE_MP4SPACE_ENCODER *phMp4SpaceEnc) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+- HANDLE_MP4SPACE_ENCODER hEnc = NULL;
+- ENC_CONFIG_SETUP setup;
+-
+- if (NULL == phMp4SpaceEnc) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i, ch;
+- FDKmemclear(&setup, sizeof(ENC_CONFIG_SETUP));
+-
+- /* Allocate Encoder Instance */
+- FDK_ALLOCATE_MEMORY_1D(hEnc, 1, struct MP4SPACE_ENCODER);
+-
+- /* Clear everything, also pointers. */
+- if (NULL != hEnc) {
+- FDKmemclear(hEnc, sizeof(struct MP4SPACE_ENCODER));
+- }
+-
+- setup.maxSamplingrate = 48000;
+- setup.maxFrameTimeSlots = 16;
+-
+- setup.maxAnalysisLengthTimeSlots = 3 * setup.maxFrameTimeSlots;
+- setup.maxQmfBands = mp4SpaceEnc_GetNumQmfBands(setup.maxSamplingrate);
+- ;
+- setup.maxHybridBands = setup.maxQmfBands;
+- setup.maxFrameLength = setup.maxQmfBands * setup.maxFrameTimeSlots;
+-
+- setup.maxChIn = 2;
+- setup.maxChOut = 1;
+- setup.maxChTotOut = setup.maxChOut;
+- setup.bEncMode_212 = 1;
+- setup.maxHybridInStaticSlots = 24;
+-
+- /* Open Static Gain*/
+- if (SACENC_OK !=
+- (error = fdk_sacenc_staticGain_OpenConfig(&hEnc->hStaticGainConfig))) {
+- goto bail;
+- }
+-
+- /* enhanced time domain downmix (for stereo input) */
+- if (SACENC_OK != (error = fdk_sacenc_open_enhancedTimeDomainDmx(
+- &hEnc->hEnhancedTimeDmx, setup.maxFrameLength))) {
+- goto bail;
+- }
+-
+- FDK_ALLOCATE_MEMORY_1D(hEnc->pParameterBand2HybridBandOffset,
+- MAX_NUM_PARAM_BANDS, UCHAR);
+-
+- /* Create Space Tree first, to get number of in-/output channels */
+- if (SACENC_OK != (error = fdk_sacenc_spaceTree_Open(&hEnc->hSpaceTree))) {
+- goto bail;
+- }
+-
+- FDK_ALLOCATE_MEMORY_1D(hEnc->pEncoderInputChScale, setup.maxChIn, INT);
+- FDK_ALLOCATE_MEMORY_1D(hEnc->staticTimeDomainDmxInScale, setup.maxChIn,
+- INT);
+-
+- FDK_ALLOCATE_MEMORY_1D(hEnc->phQmfFiltIn__FDK, setup.maxChIn,
+- HANDLE_QMF_FILTER_BANK);
+-
+- /* Allocate Analysis Filterbank Structs */
+- for (ch = 0; ch < setup.maxChIn; ch++) {
+- FDK_ALLOCATE_MEMORY_1D_INT(hEnc->phQmfFiltIn__FDK[ch], 1,
+- struct QMF_FILTER_BANK, SECT_DATA_L2)
+- FDK_ALLOCATE_MEMORY_1D_INT(hEnc->phQmfFiltIn__FDK[ch]->FilterStates,
+- 2 * 5 * setup.maxQmfBands, FIXP_QAS,
+- SECT_DATA_L2)
+- }
+-
+- /* Allocate Synthesis Filterbank Structs for arbitrary downmix */
+-
+- /* Allocate DC Filter Struct for normal signal input */
+- for (ch = 0; ch < setup.maxChIn; ch++) {
+- if (SACENC_OK !=
+- (error = fdk_sacenc_createDCFilter(&hEnc->phDCFilterSigIn[ch]))) {
+- goto bail;
+- }
+- }
+-
+- /* Open Onset Detection */
+- for (ch = 0; ch < setup.maxChIn; ch++) {
+- if (SACENC_OK != (error = fdk_sacenc_onsetDetect_Open(
+- &hEnc->phOnset[ch], setup.maxFrameTimeSlots))) {
+- goto bail;
+- }
+- }
+-
+- FDK_ALLOCATE_MEMORY_2D(hEnc->ppTrCurrPos, setup.maxChIn, MAX_NUM_TRANS,
+- INT);
+-
+- /* Create Windowing */
+- if (SACENC_OK !=
+- (error = fdk_sacenc_frameWindow_Create(&hEnc->hFrameWindow))) {
+- goto bail;
+- }
+-
+- /* Open static gain */
+- if (SACENC_OK != (error = fdk_sacenc_staticGain_Open(&hEnc->hStaticGain))) {
+- goto bail;
+- }
+-
+- /* create bitstream encoder */
+- if (SACENC_OK != (error = fdk_sacenc_createSpatialBitstreamEncoder(
+- &hEnc->hBitstreamFormatter))) {
+- goto bail;
+- }
+-
+- FDK_ALLOCATE_MEMORY_1D(hEnc->sscBuf.pSsc, MAX_SSC_BYTES, UCHAR);
+-
+- {
+- FDK_ALLOCATE_MEMORY_2D(hEnc->ppTimeSigIn__FDK, setup.maxChIn,
+- setup.maxFrameLength + MAX_DELAY_SURROUND_ANALYSIS,
+- INT_PCM);
+- }
+- FDK_ALLOCATE_MEMORY_2D(hEnc->ppTimeSigDelayIn__FDK, setup.maxChIn,
+- MAX_DELAY_SURROUND_ANALYSIS, INT_PCM);
+-
+- /* Create new buffers for several signals (including arbitrary downmix) */
+- if (setup.bEncMode_212 == 0) {
+- /* pOutputDelayBuffer__FDK buffer is not needed for SACENC_212 mode */
+- FDK_ALLOCATE_MEMORY_1D(
+- hEnc->pOutputDelayBuffer__FDK,
+- (setup.maxFrameLength + MAX_DELAY_OUTPUT) * setup.maxChOut, INT_PCM);
+- }
+-
+- /* allocate buffers */
+- if (setup.bEncMode_212 == 0) {
+- /* ppTimeSigOut__FDK buffer is not needed for SACENC_212 mode */
+- FDK_ALLOCATE_MEMORY_2D(hEnc->ppTimeSigOut__FDK, setup.maxChTotOut,
+- setup.maxFrameLength, INT_PCM);
+- }
+-
+- if (setup.bEncMode_212 == 1) {
+- /* pppHybridIn__FDK buffer can be reduced by maxFrameTimeSlots/2 slots for
+- * SACENC_212 mode */
+- FDK_ALLOCATE_MEMORY_3D(
+- hEnc->pppHybridIn__FDK, setup.maxChIn,
+- setup.maxAnalysisLengthTimeSlots - (setup.maxFrameTimeSlots >> 1),
+- setup.maxHybridBands, FIXP_DPK);
+- FDK_ALLOCATE_MEMORY_3D(hEnc->pppHybridInStatic__FDK, setup.maxChIn,
+- setup.maxHybridInStaticSlots, setup.maxHybridBands,
+- FIXP_DPK);
+- } else {
+- FDK_ALLOCATE_MEMORY_3D(hEnc->pppHybridIn__FDK, setup.maxChIn,
+- setup.maxAnalysisLengthTimeSlots,
+- setup.maxHybridBands, FIXP_DPK);
+- }
+-
+- if (setup.bEncMode_212 == 0) {
+- /* pppProcDataIn__FDK buffer is not needed for SACENC_212 mode */
+- FDK_ALLOCATE_MEMORY_3D(hEnc->pppProcDataIn__FDK, MAX_SPACE_TREE_CHANNELS,
+- setup.maxAnalysisLengthTimeSlots,
+- setup.maxHybridBands, FIXP_DPK);
+- }
+- for (i = 0; i < MAX_NUM_PARAMS; i++) {
+- FDK_ALLOCATE_MEMORY_1D(hEnc->pFrameWindowAna__FDK[i],
+- setup.maxAnalysisLengthTimeSlots, FIXP_WIN);
+- } /* for i */
+-
+- if (SACENC_OK != (error = fdk_sacenc_delay_Open(&hEnc->hDelay))) {
+- goto bail;
+- }
+-
+- if (setup.bEncMode_212 == 0) {
+- /* ppBitstreamDelayBuffer buffer is not needed for SACENC_212 mode */
+- FDK_ALLOCATE_MEMORY_2D(hEnc->ppBitstreamDelayBuffer, MAX_BITSTREAM_DELAY,
+- MAX_MPEGS_BYTES, UCHAR);
+- }
+- FDK_ALLOCATE_MEMORY_1D(hEnc->pnOutputBits, MAX_BITSTREAM_DELAY, INT);
+-
+- hEnc->setup = setup; /* save configuration used while encoder allocation. */
+- mp4SpaceEnc_InitDefault(hEnc);
+-
+- if (NULL != phMp4SpaceEnc) {
+- *phMp4SpaceEnc = hEnc; /* return encoder handle */
+- }
+-
+- } /* valid handle */
+-
+- return error;
+-
+-bail:
+- if (NULL != hEnc) {
+- hEnc->setup = setup;
+- FDK_sacenc_close(&hEnc);
+- }
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-static FDK_SACENC_ERROR mp4SpaceEnc_InitDefault(HANDLE_MP4SPACE_ENCODER hEnc) {
+- FDK_SACENC_ERROR err = SACENC_OK;
+-
+- /* Get default static gain configuration. */
+- if (SACENC_OK != (err = fdk_sacenc_staticGain_InitDefaultConfig(
+- hEnc->hStaticGainConfig))) {
+- goto bail;
+- }
+-
+-bail:
+- return err;
+-}
+-
+-static FDK_SACENC_ERROR FDK_sacenc_configure(
+- HANDLE_MP4SPACE_ENCODER hEnc, const HANDLE_MP4SPACEENC_SETUP hSetup) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- hEnc->nSampleRate = hSetup->sampleRate;
+- hEnc->encMode = hSetup->encMode;
+- hEnc->nQmfBands = mp4SpaceEnc_GetNumQmfBands(hEnc->nSampleRate);
+-
+- /* Make sure that we have set time domain downmix for 212 */
+- if (hSetup->encMode == SACENC_212 && hSetup->bTimeDomainDmx == 0) {
+- error = SACENC_INVALID_CONFIG;
+- } else {
+- hEnc->useTimeDomDownmix = hSetup->bTimeDomainDmx;
+- }
+-
+- hEnc->timeAlignment = hSetup->timeAlignment;
+- hEnc->quantMode = hSetup->quantMode;
+-
+- hEnc->useCoarseQuantCld = hSetup->bUseCoarseQuant;
+- hEnc->useCoarseQuantCpc = hSetup->bUseCoarseQuant;
+- hEnc->useFrameKeep = (hSetup->bLdMode == 2);
+- hEnc->useCoarseQuantIcc = 0; /* not available */
+- hEnc->useCoarseQuantArbDmx = 0; /* not available for user right now */
+- hEnc->independencyFactor = hSetup->independencyFactor;
+- hEnc->independencyCount = 0;
+- hEnc->independencyFlag = 1;
+-
+- /* set number of Hybrid bands */
+- hEnc->nHybridBands = hEnc->nQmfBands;
+- hEnc->nFrameTimeSlots = hSetup->frameTimeSlots;
+- mp4SpaceEnc_InitNumParamBands(hEnc, hSetup->nParamBands);
+-
+- return error;
+-}
+-
+-FDK_SACENC_ERROR FDK_sacenc_init(HANDLE_MP4SPACE_ENCODER hEnc,
+- const INT dmxDelay) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- /* Sanity Checks */
+- if (NULL == hEnc) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- const int initStatesFlag = 1;
+-
+- int ch; /* loop counter */
+- int nChInArbDmx;
+-
+- if (SACENC_OK != (error = FDK_sacenc_configure(hEnc, &hEnc->user))) {
+- goto bail;
+- }
+-
+- hEnc->bEncMode_212_only = hEnc->setup.bEncMode_212;
+-
+- /* Slots per Frame and Frame Length */
+- if (hEnc->nFrameTimeSlots < 1) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+- hEnc->nFrameLength = hEnc->nQmfBands * hEnc->nFrameTimeSlots;
+-
+- if (hEnc->useFrameKeep == 1) {
+- hEnc->nAnalysisLengthTimeSlots = 3 * hEnc->nFrameTimeSlots;
+- hEnc->nUpdateHybridPositionTimeSlots = hEnc->nFrameTimeSlots;
+- } else {
+- hEnc->nAnalysisLengthTimeSlots = 2 * hEnc->nFrameTimeSlots;
+- hEnc->nUpdateHybridPositionTimeSlots = 0;
+- }
+-
+- {
+- hEnc->nAnalysisLookaheadTimeSlots =
+- hEnc->nAnalysisLengthTimeSlots - 3 * hEnc->nFrameTimeSlots / 2;
+- }
+-
+- /* init parameterBand2hybridBandOffset table */
+- fdk_sacenc_calcParameterBand2HybridBandOffset(
+- (BOX_SUBBAND_CONFIG)hEnc->nParamBands, hEnc->nHybridBands,
+- hEnc->pParameterBand2HybridBandOffset);
+-
+- /* Fill Setup structure for Space Tree */
+- if (SACENC_OK !=
+- (error = mp4SpaceEnc_FillSpaceTreeSetup(hEnc, &hEnc->spaceTreeSetup))) {
+- goto bail;
+- }
+-
+- /* Init space tree configuration */
+- if (SACENC_OK !=
+- (error = fdk_sacenc_spaceTree_Init(
+- hEnc->hSpaceTree, &hEnc->spaceTreeSetup,
+- hEnc->pParameterBand2HybridBandOffset, hEnc->useFrameKeep))) {
+- goto bail;
+- }
+-
+- /* Get space tree description and resulting number of input/output channels
+- */
+- {
+- SPACE_TREE_DESCRIPTION spaceTreeDescription;
+-
+- if (SACENC_OK != (error = fdk_sacenc_spaceTree_GetDescription(
+- hEnc->hSpaceTree, &spaceTreeDescription))) {
+- goto bail;
+- }
+-
+- hEnc->nInputChannels =
+- spaceTreeDescription.nOutChannels; /* space tree description
+- describes decoder
+- configuration */
+- hEnc->nOutputChannels =
+- spaceTreeDescription.nInChannels; /* space tree description
+- describes decoder
+- configuration */
+- }
+-
+- nChInArbDmx = 0;
+-
+- /* INITIALIZATION */
+- for (ch = 0; ch < hEnc->nInputChannels; ch++) {
+- /* scaling in analysis qmf filterbank (7) */
+- hEnc->pEncoderInputChScale[ch] = 7;
+-
+- {
+- /* additional scaling in qmf prototype filter for low delay */
+- hEnc->pEncoderInputChScale[ch] += 1;
+- }
+-
+- { hEnc->pEncoderInputChScale[ch] += DC_FILTER_SF; }
+- } /* nInputChannels */
+-
+- /* Init analysis filterbank */
+- for (ch = 0; ch < hEnc->nInputChannels; ch++) {
+- hEnc->phQmfFiltIn__FDK[ch]->flags =
+- updateQmfFlags(hEnc->phQmfFiltIn__FDK[ch]->flags, !initStatesFlag);
+-
+- if (0 != qmfInitAnalysisFilterBank(
+- hEnc->phQmfFiltIn__FDK[ch],
+- (FIXP_QAS *)hEnc->phQmfFiltIn__FDK[ch]->FilterStates, 1,
+- hEnc->nQmfBands, hEnc->nQmfBands, hEnc->nQmfBands,
+- hEnc->phQmfFiltIn__FDK[ch]->flags)) {
+- error = SACENC_INIT_ERROR;
+- goto bail;
+- }
+- }
+-
+- /* Initialize DC Filter. */
+- {
+- for (ch = 0; ch < hEnc->nInputChannels; ch++) {
+- if (SACENC_OK != (error = fdk_sacenc_initDCFilter(
+- hEnc->phDCFilterSigIn[ch], hEnc->nSampleRate))) {
+- goto bail;
+- }
+- }
+- }
+-
+- /* Init onset detect. */
+- {
+- /* init onset detect configuration struct */
+- ONSET_DETECT_CONFIG onsetDetectConfig;
+- onsetDetectConfig.maxTimeSlots = hEnc->nFrameTimeSlots;
+- onsetDetectConfig.lowerBoundOnsetDetection =
+- freq2HybridBand(1725, hEnc->nSampleRate, hEnc->nQmfBands);
+- onsetDetectConfig.upperBoundOnsetDetection = hEnc->nHybridBands;
+-
+- for (ch = 0; ch < hEnc->nInputChannels; ch++) {
+- if (SACENC_OK != (error = fdk_sacenc_onsetDetect_Init(
+- hEnc->phOnset[ch], &onsetDetectConfig, 1))) {
+- goto bail;
+- }
+- }
+- }
+-
+- {
+- /* init windowing */
+- FRAMEWINDOW_CONFIG framewindowConfig;
+- framewindowConfig.nTimeSlotsMax = hEnc->nFrameTimeSlots;
+- framewindowConfig.bFrameKeep = hEnc->useFrameKeep;
+-
+- if (SACENC_OK != (error = fdk_sacenc_frameWindow_Init(
+- hEnc->hFrameWindow, &framewindowConfig))) {
+- goto bail;
+- }
+- }
+-
+- /* Set encoder mode for static gain initialization. */
+- if (SACENC_OK != (error = fdk_sacenc_staticGain_SetEncMode(
+- hEnc->hStaticGainConfig, hEnc->encMode))) {
+- goto bail;
+- }
+-
+- /* Init static gain. */
+- if (SACENC_OK != (error = fdk_sacenc_staticGain_Init(
+- hEnc->hStaticGain, hEnc->hStaticGainConfig,
+- &(hEnc->staticGainScale)))) {
+- goto bail;
+- }
+-
+- for (ch = 0; ch < hEnc->nInputChannels; ch++) {
+- hEnc->pEncoderInputChScale[ch] += hEnc->staticGainScale;
+- }
+-
+- /* enhanced downmix for stereo input*/
+- if (hEnc->useTimeDomDownmix != 0) {
+- if (SACENC_OK != (error = fdk_sacenc_init_enhancedTimeDomainDmx(
+- hEnc->hEnhancedTimeDmx,
+- fdk_sacenc_getPreGainPtrFDK(hEnc->hStaticGain),
+- hEnc->staticGainScale,
+- fdk_sacenc_getPostGainFDK(hEnc->hStaticGain),
+- hEnc->staticGainScale, hEnc->nFrameLength))) {
+- goto bail;
+- }
+- }
+-
+- /* Create config structure for bitstream formatter including arbitrary
+- * downmix residual */
+- if (SACENC_OK != (error = fdk_sacenc_initSpatialBitstreamEncoder(
+- hEnc->hBitstreamFormatter))) {
+- goto bail;
+- }
+-
+- if (SACENC_OK != (error = FillSpatialSpecificConfig(
+- hEnc, fdk_sacenc_getSpatialSpecificConfig(
+- hEnc->hBitstreamFormatter)))) {
+- goto bail;
+- }
+-
+- if (SACENC_OK !=
+- (error = fdk_sacenc_writeSpatialSpecificConfig(
+- fdk_sacenc_getSpatialSpecificConfig(hEnc->hBitstreamFormatter),
+- hEnc->sscBuf.pSsc, MAX_SSC_BYTES, &hEnc->sscBuf.nSscSizeBits))) {
+- goto bail;
+- }
+-
+- /* init delay compensation with dmx core coder delay; if no core coder is
+- * used, many other buffers are initialized nevertheless */
+- if (SACENC_OK !=
+- (error = mp4SpaceEnc_InitDelayCompensation(hEnc, dmxDelay))) {
+- goto bail;
+- }
+-
+- /* How much input do we need? */
+- hEnc->nSamplesNext =
+- hEnc->nFrameLength * (hEnc->nInputChannels + nChInArbDmx);
+- hEnc->nSamplesValid = 0;
+- } /* valid handle */
+-
+-bail:
+- return error;
+-}
+-
+-static INT getAnalysisLengthTimeSlots(FIXP_WIN *pFrameWindowAna,
+- INT nTimeSlots) {
+- int i;
+- for (i = nTimeSlots - 1; i >= 0; i--) {
+- if (pFrameWindowAna[i] != (FIXP_WIN)0) {
+- break;
+- }
+- }
+- nTimeSlots = i + 1;
+- return nTimeSlots;
+-}
+-
+-static INT getAnalysisStartTimeSlot(FIXP_WIN *pFrameWindowAna, INT nTimeSlots) {
+- int startTimeSlot = 0;
+- int i;
+- for (i = 0; i < nTimeSlots; i++) {
+- if (pFrameWindowAna[i] != (FIXP_WIN)0) {
+- break;
+- }
+- }
+- startTimeSlot = i;
+- return startTimeSlot;
+-}
+-
+-static FDK_SACENC_ERROR __FeedDeinterPreScale(
+- HANDLE_MP4SPACE_ENCODER hEnc, INT_PCM const *const pSamples,
+- INT_PCM *const pOutputSamples, INT const nSamples,
+- UINT const isInputInterleaved, UINT const inputBufferSizePerChannel,
+- UINT *const pnSamplesFed) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hEnc == NULL) || (pSamples == NULL) || (pnSamplesFed == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else if (nSamples == 0) {
+- error = SACENC_INVALID_CONFIG; /* Flushing not implemented */
+- } else {
+- int ch;
+- const INT nChIn = hEnc->nInputChannels;
+- const INT nChInWithDmx = nChIn;
+- const INT samplesToFeed =
+- FDKmin(nSamples, hEnc->nSamplesNext - hEnc->nSamplesValid);
+- const INT nSamplesPerChannel = samplesToFeed / nChInWithDmx;
+-
+- if ((samplesToFeed < 0) || (samplesToFeed % nChInWithDmx != 0) ||
+- (samplesToFeed > nChInWithDmx * (INT)hEnc->nFrameLength)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+- int i;
+-
+- const INT_PCM *pInput__FDK;
+- const INT_PCM *pInput2__FDK;
+-
+- { /* no dmx align = default*/
+- pInput__FDK = pSamples;
+- pInput2__FDK = pSamples + (hEnc->nInputDelay * nChInWithDmx);
+- }
+-
+- for (i = 0; i < hEnc->nInputChannels; i++) {
+- hEnc->staticTimeDomainDmxInScale[i] = hEnc->staticGainScale;
+- }
+-
+- /***** N-channel-input *****/
+- for (ch = 0; ch < nChIn; ch++) {
+- /* Write delayed time signal into time signal buffer */
+- FDKmemcpy(&(hEnc->ppTimeSigIn__FDK[ch][0]),
+- &(hEnc->ppTimeSigDelayIn__FDK[ch][0]),
+- hEnc->nSurroundAnalysisBufferDelay * sizeof(INT_PCM));
+-
+- if (isInputInterleaved) {
+- /* Add the new frame de-interleaved. Apply nSurroundAnalysisBufferDelay.
+- */
+- FDKmemcpy_flex(
+- &(hEnc->ppTimeSigIn__FDK[ch][hEnc->nSurroundAnalysisBufferDelay]),
+- 1, pInput__FDK + ch, nChInWithDmx, hEnc->nInputDelay);
+- FDKmemcpy_flex(
+- &(hEnc->ppTimeSigIn__FDK[ch][hEnc->nSurroundAnalysisBufferDelay +
+- hEnc->nInputDelay]),
+- 1, pInput2__FDK + ch, nChInWithDmx,
+- nSamplesPerChannel - hEnc->nInputDelay);
+- } else {
+- /* Input is already deinterleaved, just copy */
+- FDKmemcpy(
+- &(hEnc->ppTimeSigIn__FDK[ch][hEnc->nSurroundAnalysisBufferDelay]),
+- pInput__FDK + ch * inputBufferSizePerChannel,
+- hEnc->nInputDelay * sizeof(INT_PCM));
+- FDKmemcpy(
+- &(hEnc->ppTimeSigIn__FDK[ch][hEnc->nSurroundAnalysisBufferDelay +
+- hEnc->nInputDelay]),
+- pInput2__FDK + ch * inputBufferSizePerChannel,
+- (nSamplesPerChannel - hEnc->nInputDelay) * sizeof(INT_PCM));
+- }
+-
+- /* Update time signal delay buffer */
+- FDKmemcpy(&(hEnc->ppTimeSigDelayIn__FDK[ch][0]),
+- &(hEnc->ppTimeSigIn__FDK[ch][hEnc->nFrameLength]),
+- hEnc->nSurroundAnalysisBufferDelay * sizeof(INT_PCM));
+- } /* for ch */
+-
+- /***** No Arbitrary Downmix *****/
+- /* "Crude TD Dmx": Time DomainDownmix + NO Arbitrary Downmix, Delay Added at
+- * pOutputBuffer */
+- if ((hEnc->useTimeDomDownmix > 0)) {
+- if ((hEnc->useTimeDomDownmix == 1) || (hEnc->nInputChannels != 2)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- } else {
+- /* enhanced time domain downmix (for stereo input) */
+- if (hEnc->encMode == SACENC_212) {
+- if (pOutputSamples == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- fdk_sacenc_apply_enhancedTimeDomainDmx(
+- hEnc->hEnhancedTimeDmx, hEnc->ppTimeSigIn__FDK, pOutputSamples,
+- hEnc->nSurroundAnalysisBufferDelay);
+- } else {
+- if (&hEnc->ppTimeSigOut__FDK[0][0] == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- fdk_sacenc_apply_enhancedTimeDomainDmx(
+- hEnc->hEnhancedTimeDmx, hEnc->ppTimeSigIn__FDK,
+- &hEnc->ppTimeSigOut__FDK[0][0],
+- hEnc->nSurroundAnalysisBufferDelay);
+- }
+- }
+- }
+-
+- /* update number of samples still to process */
+- hEnc->nSamplesValid += samplesToFeed;
+-
+- /*return number of fed samples */
+- *pnSamplesFed = samplesToFeed;
+- }
+-bail:
+- return error;
+-}
+-
+-FDK_SACENC_ERROR FDK_sacenc_encode(const HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc,
+- const FDK_bufDescr *inBufDesc,
+- const FDK_bufDescr *outBufDesc,
+- const SACENC_InArgs *inargs,
+- SACENC_OutArgs *outargs) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- const INT_PCM *pInputSamples =
+- (const INT_PCM *)inBufDesc->ppBase[getBufDescIdx(
+- inBufDesc, (FDK_BUF_TYPE_INPUT | FDK_BUF_TYPE_PCM_DATA))];
+-
+- INT_PCM *const pOutputSamples = (INT_PCM *)outBufDesc->ppBase[getBufDescIdx(
+- outBufDesc, (FDK_BUF_TYPE_OUTPUT | FDK_BUF_TYPE_PCM_DATA))];
+-
+- const int nOutputSamplesBufferSize =
+- outBufDesc->pBufSize[getBufDescIdx(
+- outBufDesc, (FDK_BUF_TYPE_OUTPUT | FDK_BUF_TYPE_PCM_DATA))] /
+- outBufDesc->pEleSize[getBufDescIdx(
+- outBufDesc, (FDK_BUF_TYPE_OUTPUT | FDK_BUF_TYPE_PCM_DATA))];
+-
+- if ((hMp4SpaceEnc == NULL) || (pInputSamples == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int nOutputSamples;
+- int i, ch, ps, winCnt, ts, slot;
+- INT currTransPos = -1;
+- SPATIALFRAME *pFrameData = NULL;
+-
+- /* Improve Code Readability */
+- const int nChIn = hMp4SpaceEnc->nInputChannels;
+- const int nChInWithDmx = nChIn;
+- const int nChOut = hMp4SpaceEnc->nOutputChannels;
+- const int nSamplesPerChannel = inargs->nInputSamples / nChInWithDmx;
+- const int nOutputSamplesMax = nSamplesPerChannel * nChOut;
+- const int nFrameTimeSlots = hMp4SpaceEnc->nFrameTimeSlots;
+-
+- INT encoderInputChScale[SACENC_MAX_INPUT_CHANNELS];
+- INT nFrameTimeSlotsReduction = 0;
+-
+- if (hMp4SpaceEnc->encMode == SACENC_212) {
+- nFrameTimeSlotsReduction = hMp4SpaceEnc->nFrameTimeSlots >> 1;
+- }
+-
+- for (i = 0; i < nChIn; i++)
+- encoderInputChScale[i] = hMp4SpaceEnc->pEncoderInputChScale[i];
+-
+- /* Sanity Check */
+- if ((0 != inargs->nInputSamples % nChInWithDmx)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- /*
+- * Get Frame Data Handle.
+- */
+-
+- /* get bitstream handle (for storage of cld's, icc's and so on)
+- * get spatialframe 2 frames in the future; NOTE: this is necessary to
+- * synchronise spatial data and audio data */
+- if (NULL == (pFrameData = fdk_sacenc_getSpatialFrame(
+- hMp4SpaceEnc->hBitstreamFormatter, WRITE_SPATIALFRAME))) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- /* Independent Frames Counters*/
+- if (hMp4SpaceEnc->nDiscardOutFrames >
+- 0) { /* Independent Frames if they should be discarded, Reset Counter*/
+- hMp4SpaceEnc->independencyCount =
+- 0; /* Reset the counter, first valid frame is an independent one*/
+- hMp4SpaceEnc->independencyFlag = 1;
+- } else { /*hMp4SpaceEnc->nDiscardOutFrames == 0*/
+- hMp4SpaceEnc->independencyFlag =
+- (hMp4SpaceEnc->independencyCount == 0) ? 1 : 0;
+- if (hMp4SpaceEnc->independencyFactor > 0) {
+- hMp4SpaceEnc->independencyCount++;
+- hMp4SpaceEnc->independencyCount =
+- hMp4SpaceEnc->independencyCount %
+- ((int)hMp4SpaceEnc->independencyFactor);
+- } else { /* independencyFactor == 0 */
+- hMp4SpaceEnc->independencyCount = -1;
+- }
+- }
+-
+- /*
+- * Time signal preprocessing:
+- * - Feed input buffer
+- * - Prescale time signal
+- * - Apply DC filter on input signal
+- */
+-
+- /* Feed, Deinterleave, Pre-Scale the input time signals */
+- if (SACENC_OK !=
+- (error = __FeedDeinterPreScale(
+- hMp4SpaceEnc, pInputSamples, pOutputSamples, inargs->nInputSamples,
+- inargs->isInputInterleaved, inargs->inputBufferSizePerChannel,
+- &outargs->nSamplesConsumed))) {
+- goto bail;
+- }
+-
+- if (hMp4SpaceEnc->nSamplesNext != hMp4SpaceEnc->nSamplesValid) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- if (hMp4SpaceEnc->encMode == SACENC_212 &&
+- hMp4SpaceEnc->bEncMode_212_only) {
+- for (ch = 0; ch < nChIn; ch++) {
+- for (slot = 0; slot < nFrameTimeSlots; slot++) {
+- setCplxVec(
+- hMp4SpaceEnc->pppHybridIn__FDK
+- [ch][hMp4SpaceEnc->nUpdateHybridPositionTimeSlots +
+- nFrameTimeSlots - nFrameTimeSlotsReduction + slot],
+- (FIXP_DBL)0, hMp4SpaceEnc->nHybridBands);
+- }
+- }
+- }
+-
+- /*
+- * Time / Frequency:
+- * - T/F audio input channels
+- * - T/F arbitrary downmix input channels
+- */
+- for (ch = 0; ch < nChIn; ch++) {
+- C_AALLOC_SCRATCH_START(pQmfInReal, FIXP_DBL, MAX_QMF_BANDS)
+- C_AALLOC_SCRATCH_START(pQmfInImag, FIXP_DBL, MAX_QMF_BANDS)
+- FIXP_GAIN *pPreGain =
+- fdk_sacenc_getPreGainPtrFDK(hMp4SpaceEnc->hStaticGain);
+-
+- for (ts = 0; ts < nFrameTimeSlots; ts++) {
+- FIXP_DBL *pSpecReal;
+- FIXP_DBL *pSpecImag;
+-
+- INT_PCM *pTimeIn =
+- &hMp4SpaceEnc->ppTimeSigIn__FDK[ch][(ts * hMp4SpaceEnc->nQmfBands)];
+-
+- {
+- /* Apply DC filter on input channels */
+- if (SACENC_OK != (error = fdk_sacenc_applyDCFilter(
+- hMp4SpaceEnc->phDCFilterSigIn[ch], pTimeIn,
+- pTimeIn, hMp4SpaceEnc->nQmfBands))) {
+- goto bail;
+- }
+- }
+-
+- /* QMF filterbank */
+- C_ALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL, (MAX_QMF_BANDS << 1));
+-
+- qmfAnalysisFilteringSlot(hMp4SpaceEnc->phQmfFiltIn__FDK[ch], pQmfInReal,
+- pQmfInImag, pTimeIn, 1, pWorkBuffer);
+-
+- C_ALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, (MAX_QMF_BANDS << 1));
+-
+- pSpecReal = pQmfInReal;
+- pSpecImag = pQmfInImag;
+-
+- /* Apply pre-scale after filterbank */
+- if (MAXVAL_GAIN != pPreGain[ch]) {
+- for (i = 0; i < hMp4SpaceEnc->nHybridBands; i++) {
+- hMp4SpaceEnc
+- ->pppHybridIn__FDK[ch]
+- [hMp4SpaceEnc->nAnalysisLookaheadTimeSlots +
+- ts][i]
+- .v.re = fMult(pSpecReal[i], pPreGain[ch]);
+- hMp4SpaceEnc
+- ->pppHybridIn__FDK[ch]
+- [hMp4SpaceEnc->nAnalysisLookaheadTimeSlots +
+- ts][i]
+- .v.im = fMult(pSpecImag[i], pPreGain[ch]);
+- }
+- } else {
+- for (i = 0; i < hMp4SpaceEnc->nHybridBands; i++) {
+- hMp4SpaceEnc
+- ->pppHybridIn__FDK[ch]
+- [hMp4SpaceEnc->nAnalysisLookaheadTimeSlots +
+- ts][i]
+- .v.re = pSpecReal[i];
+- hMp4SpaceEnc
+- ->pppHybridIn__FDK[ch]
+- [hMp4SpaceEnc->nAnalysisLookaheadTimeSlots +
+- ts][i]
+- .v.im = pSpecImag[i];
+- }
+- }
+- } /* ts */
+- C_AALLOC_SCRATCH_END(pQmfInImag, FIXP_DBL, MAX_QMF_BANDS)
+- C_AALLOC_SCRATCH_END(pQmfInReal, FIXP_DBL, MAX_QMF_BANDS)
+-
+- if (SACENC_OK != error) {
+- goto bail;
+- }
+- } /* ch */
+-
+- if (hMp4SpaceEnc->encMode == SACENC_212 &&
+- hMp4SpaceEnc->bEncMode_212_only) {
+- for (ch = 0; ch < nChIn; ch++) {
+- for (slot = 0;
+- slot < (int)(hMp4SpaceEnc->nUpdateHybridPositionTimeSlots +
+- nFrameTimeSlots - nFrameTimeSlotsReduction);
+- slot++) {
+- copyCplxVec(hMp4SpaceEnc->pppHybridIn__FDK[ch][slot],
+- hMp4SpaceEnc->pppHybridInStatic__FDK[ch][slot],
+- hMp4SpaceEnc->nHybridBands);
+- }
+- }
+- for (ch = 0; ch < nChIn; ch++) {
+- for (slot = 0;
+- slot < (int)(hMp4SpaceEnc->nUpdateHybridPositionTimeSlots +
+- nFrameTimeSlots - nFrameTimeSlotsReduction);
+- slot++) {
+- copyCplxVec(
+- hMp4SpaceEnc->pppHybridInStatic__FDK[ch][slot],
+- hMp4SpaceEnc->pppHybridIn__FDK[ch][nFrameTimeSlots + slot],
+- hMp4SpaceEnc->nHybridBands);
+- }
+- }
+- }
+-
+- /*
+- * Onset Detection:
+- * - detection of transients
+- * - build framing
+- */
+- for (ch = 0; ch < nChIn; ch++) {
+- if (ch != 3) { /* !LFE */
+- if (SACENC_OK !=
+- (error = fdk_sacenc_onsetDetect_Apply(
+- hMp4SpaceEnc->phOnset[ch], nFrameTimeSlots,
+- hMp4SpaceEnc->nHybridBands,
+- &hMp4SpaceEnc->pppHybridIn__FDK
+- [ch][hMp4SpaceEnc->nAnalysisLookaheadTimeSlots],
+- encoderInputChScale[ch],
+- hMp4SpaceEnc->trPrevPos[1], /* contains previous Transient */
+- hMp4SpaceEnc->ppTrCurrPos[ch]))) {
+- goto bail;
+- }
+-
+- if ((1) && (hMp4SpaceEnc->useFrameKeep == 0)) {
+- hMp4SpaceEnc->ppTrCurrPos[ch][0] = -1;
+- }
+-
+- /* Find first Transient Position */
+- if ((hMp4SpaceEnc->ppTrCurrPos[ch][0] >= 0) &&
+- ((currTransPos < 0) ||
+- (hMp4SpaceEnc->ppTrCurrPos[ch][0] < currTransPos))) {
+- currTransPos = hMp4SpaceEnc->ppTrCurrPos[ch][0];
+- }
+- } /* !LFE */
+- } /* ch */
+-
+- if (hMp4SpaceEnc->useFrameKeep == 1) {
+- if ((currTransPos != -1) || (hMp4SpaceEnc->independencyFlag == 1)) {
+- hMp4SpaceEnc->avoid_keep = NUM_KEEP_WINDOWS;
+- currTransPos = -1;
+- }
+- }
+-
+- /* Save previous Transient Position */
+- hMp4SpaceEnc->trPrevPos[0] =
+- FDKmax(-1, hMp4SpaceEnc->trPrevPos[1] - (INT)nFrameTimeSlots);
+- hMp4SpaceEnc->trPrevPos[1] = currTransPos;
+-
+- /* Update Onset Detection Energy Buffer */
+- for (ch = 0; ch < nChIn; ch++) {
+- if (SACENC_OK != (error = fdk_sacenc_onsetDetect_Update(
+- hMp4SpaceEnc->phOnset[ch], nFrameTimeSlots))) {
+- goto bail;
+- }
+- }
+-
+- /* Framing */
+- if (SACENC_OK !=
+- (error = fdk_sacenc_frameWindow_GetWindow(
+- hMp4SpaceEnc->hFrameWindow, hMp4SpaceEnc->trPrevPos,
+- nFrameTimeSlots, &pFrameData->framingInfo,
+- hMp4SpaceEnc->pFrameWindowAna__FDK, &hMp4SpaceEnc->frameWinList,
+- hMp4SpaceEnc->avoid_keep))) {
+- goto bail;
+- }
+-
+- /*
+- * MPS Processing:
+- */
+- for (ps = 0, winCnt = 0; ps < hMp4SpaceEnc->frameWinList.n; ++ps) {
+- /* Analysis Windowing */
+- if (hMp4SpaceEnc->frameWinList.dat[ps].hold == FW_HOLD) {
+- /* ************************************** */
+- /* ONLY COPY AND HOLD PREVIOUS PARAMETERS */
+- if (SACENC_OK != (error = fdk_sacenc_duplicateParameterSet(
+- &hMp4SpaceEnc->saveFrame, 0, pFrameData, ps))) {
+- goto bail;
+- }
+-
+- } else { /* !FW_HOLD */
+- /* ************************************** */
+- /* NEW WINDOW */
+-
+- INT nAnalysisLengthTimeSlots, analysisStartTimeSlot;
+-
+- nAnalysisLengthTimeSlots = getAnalysisLengthTimeSlots(
+- hMp4SpaceEnc->pFrameWindowAna__FDK[winCnt],
+- hMp4SpaceEnc->nAnalysisLengthTimeSlots);
+-
+- analysisStartTimeSlot =
+- getAnalysisStartTimeSlot(hMp4SpaceEnc->pFrameWindowAna__FDK[winCnt],
+- hMp4SpaceEnc->nAnalysisLengthTimeSlots);
+-
+- /* perform main signal analysis windowing in
+- * fdk_sacenc_spaceTree_Apply() */
+- FIXP_WIN *pFrameWindowAna__FDK =
+- hMp4SpaceEnc->pFrameWindowAna__FDK[winCnt];
+- FIXP_DPK ***pppHybridIn__FDK = hMp4SpaceEnc->pppHybridIn__FDK;
+- FIXP_DPK ***pppProcDataIn__FDK = hMp4SpaceEnc->pppProcDataIn__FDK;
+-
+- if (hMp4SpaceEnc->encMode == SACENC_212 &&
+- hMp4SpaceEnc->bEncMode_212_only) {
+- pppProcDataIn__FDK = pppHybridIn__FDK;
+- }
+-
+- if (SACENC_OK !=
+- (error = fdk_sacenc_spaceTree_Apply(
+- hMp4SpaceEnc->hSpaceTree, ps, nChIn, nAnalysisLengthTimeSlots,
+- analysisStartTimeSlot, hMp4SpaceEnc->nHybridBands,
+- pFrameWindowAna__FDK, pppHybridIn__FDK,
+- pppProcDataIn__FDK, /* multi-channel input */
+- pFrameData, hMp4SpaceEnc->avoid_keep, encoderInputChScale))) {
+- goto bail;
+- }
+-
+- /* Save spatial frame for potential hold parameter set */
+- if (SACENC_OK != (error = fdk_sacenc_duplicateParameterSet(
+- pFrameData, ps, &hMp4SpaceEnc->saveFrame, 0))) {
+- goto bail;
+- }
+-
+- ++winCnt;
+- }
+- if (hMp4SpaceEnc->avoid_keep > 0) {
+- hMp4SpaceEnc->avoid_keep--;
+- }
+- } /* Loop over Parameter Sets */
+- /* ---- End of Processing Loop ---- */
+-
+- /*
+- * Update hybridInReal/Imag buffer and do the same for arbDmx
+- * this means to move the hybrid data of the current frame to the beginning
+- * of the 2*nFrameLength-long buffer
+- */
+- if (!(hMp4SpaceEnc->encMode == SACENC_212 &&
+- hMp4SpaceEnc->bEncMode_212_only)) {
+- for (ch = 0; ch < nChIn; ch++) { /* for automatic downmix */
+- for (slot = 0;
+- slot < (int)(hMp4SpaceEnc->nUpdateHybridPositionTimeSlots +
+- nFrameTimeSlots - nFrameTimeSlotsReduction);
+- slot++) {
+- copyCplxVec(
+- hMp4SpaceEnc->pppHybridIn__FDK[ch][slot],
+- hMp4SpaceEnc->pppHybridIn__FDK[ch][nFrameTimeSlots + slot],
+- hMp4SpaceEnc->nHybridBands);
+- }
+- for (slot = 0; slot < nFrameTimeSlots; slot++) {
+- setCplxVec(
+- hMp4SpaceEnc->pppHybridIn__FDK
+- [ch][hMp4SpaceEnc->nUpdateHybridPositionTimeSlots +
+- nFrameTimeSlots - nFrameTimeSlotsReduction + slot],
+- (FIXP_DBL)0, hMp4SpaceEnc->nHybridBands);
+- }
+- }
+- }
+- /*
+- * Spatial Tonality:
+- */
+- {
+- /* Smooth config off. */
+- FDKmemclear(&pFrameData->smgData, sizeof(pFrameData->smgData));
+- }
+-
+- /*
+- * Create bitstream
+- * - control independecy flag
+- * - write spatial frame
+- * - return bitstream
+- */
+- UCHAR *pBitstreamDelayBuffer;
+-
+- if (hMp4SpaceEnc->encMode == SACENC_212) {
+- /* no bitstream delay buffer for SACENC_212 mode, write bitstream directly
+- * into the sacOutBuffer buffer which is provided by the core routine */
+- pBitstreamDelayBuffer = (UCHAR *)outBufDesc->ppBase[1];
+- } else {
+- /* bitstream delay is handled in ppBitstreamDelayBuffer buffer */
+- pBitstreamDelayBuffer =
+- hMp4SpaceEnc
+- ->ppBitstreamDelayBuffer[hMp4SpaceEnc->nBitstreamBufferWrite];
+- }
+- if (pBitstreamDelayBuffer == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- pFrameData->bsIndependencyFlag = hMp4SpaceEnc->independencyFlag;
+-
+- if (SACENC_OK !=
+- (error = fdk_sacenc_writeSpatialFrame(
+- pBitstreamDelayBuffer, MAX_MPEGS_BYTES,
+- &hMp4SpaceEnc->pnOutputBits[hMp4SpaceEnc->nBitstreamBufferWrite],
+- hMp4SpaceEnc->hBitstreamFormatter))) {
+- goto bail;
+- }
+-
+- /* return bitstream info */
+- if ((hMp4SpaceEnc->nDiscardOutFrames == 0) &&
+- (getBufDescIdx(outBufDesc,
+- (FDK_BUF_TYPE_OUTPUT | FDK_BUF_TYPE_BS_DATA)) != -1)) {
+- const INT idx = getBufDescIdx(
+- outBufDesc, (FDK_BUF_TYPE_OUTPUT | FDK_BUF_TYPE_BS_DATA));
+- const INT outBits =
+- hMp4SpaceEnc->pnOutputBits[hMp4SpaceEnc->nBitstreamBufferRead];
+-
+- if (((outBits + 7) / 8) >
+- (INT)(outBufDesc->pBufSize[idx] / outBufDesc->pEleSize[idx])) {
+- outargs->nOutputBits = 0;
+- error = SACENC_ENCODE_ERROR;
+- goto bail;
+- }
+-
+- /* return bitstream buffer, copy delayed bitstream for all configurations
+- * except for the SACENC_212 mode */
+- if (hMp4SpaceEnc->encMode != SACENC_212) {
+- FDKmemcpy(
+- outBufDesc->ppBase[idx],
+- hMp4SpaceEnc
+- ->ppBitstreamDelayBuffer[hMp4SpaceEnc->nBitstreamBufferRead],
+- (outBits + 7) / 8);
+- }
+-
+- /* return number of valid bits */
+- outargs->nOutputBits = outBits;
+- } else { /* No spatial data should be returned if the current frame is to be
+- discarded. */
+- outargs->nOutputBits = 0;
+- }
+-
+- /* update pointers */
+- hMp4SpaceEnc->nBitstreamBufferRead =
+- (hMp4SpaceEnc->nBitstreamBufferRead + 1) %
+- hMp4SpaceEnc->nBitstreamDelayBuffer;
+- hMp4SpaceEnc->nBitstreamBufferWrite =
+- (hMp4SpaceEnc->nBitstreamBufferWrite + 1) %
+- hMp4SpaceEnc->nBitstreamDelayBuffer;
+-
+- /* Set Output Parameters */
+- nOutputSamples =
+- (hMp4SpaceEnc->nDiscardOutFrames == 0)
+- ? (nOutputSamplesMax)
+- : 0; /* don't output samples in case frames to be discarded */
+- if (nOutputSamples > nOutputSamplesBufferSize) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+- outargs->nOutputSamples = nOutputSamples;
+-
+- { /* !bQmfOutput */
+-
+- if (hMp4SpaceEnc->encMode != SACENC_212) {
+- /* delay output samples and interleave them */
+- /* note: in case of arbitrary downmix this will always be processed,
+- * because nOutputSamples != 0, even if bDMXAlign is switched on */
+- /* always run copy-func, so nOutputSamplesMax instead of nOutputSamples
+- */
+- for (ch = 0; ch < nChOut; ch++) {
+- FDKmemcpy_flex(
+- &hMp4SpaceEnc->pOutputDelayBuffer__FDK
+- [ch + (hMp4SpaceEnc->nOutputBufferDelay) * nChOut],
+- nChOut, hMp4SpaceEnc->ppTimeSigOut__FDK[ch], 1,
+- nOutputSamplesMax / nChOut);
+- }
+-
+- /* write delayed data in output pcm stream */
+- /* always calculate, limiter must have a lookahead!!! */
+- FDKmemcpy(pOutputSamples, hMp4SpaceEnc->pOutputDelayBuffer__FDK,
+- nOutputSamplesMax * sizeof(INT_PCM));
+-
+- /* update delay buffer (move back end to the beginning of the buffer) */
+- FDKmemmove(
+- hMp4SpaceEnc->pOutputDelayBuffer__FDK,
+- &hMp4SpaceEnc->pOutputDelayBuffer__FDK[nOutputSamplesMax],
+- nChOut * (hMp4SpaceEnc->nOutputBufferDelay) * sizeof(INT_PCM));
+- }
+-
+- if (hMp4SpaceEnc->useTimeDomDownmix <= 0) {
+- if (SACENC_OK != (error = fdk_sacenc_staticPostGain_ApplyFDK(
+- hMp4SpaceEnc->hStaticGain, pOutputSamples,
+- nOutputSamplesMax, 0))) {
+- goto bail;
+- }
+- }
+-
+- } /* !bQmfOutput */
+-
+- if (hMp4SpaceEnc->nDiscardOutFrames > 0) {
+- hMp4SpaceEnc->nDiscardOutFrames--;
+- }
+-
+- /* Invalidate Input Buffer */
+- hMp4SpaceEnc->nSamplesValid = 0;
+-
+- } /* valid handle */
+-bail:
+- return error;
+-}
+-
+-FDK_SACENC_ERROR FDK_sacenc_close(HANDLE_MP4SPACE_ENCODER *phMp4SpaceEnc) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL != phMp4SpaceEnc) {
+- if (NULL != *phMp4SpaceEnc) {
+- int ch, i;
+- HANDLE_MP4SPACE_ENCODER const hEnc = *phMp4SpaceEnc;
+-
+- if (hEnc->pParameterBand2HybridBandOffset != NULL) {
+- FDK_FREE_MEMORY_1D(hEnc->pParameterBand2HybridBandOffset);
+- }
+- /* Free Analysis Filterbank Structs */
+- if (hEnc->pEncoderInputChScale != NULL) {
+- FDK_FREE_MEMORY_1D(hEnc->pEncoderInputChScale);
+- }
+- if (hEnc->staticTimeDomainDmxInScale != NULL) {
+- FDK_FREE_MEMORY_1D(hEnc->staticTimeDomainDmxInScale);
+- }
+- if (hEnc->phQmfFiltIn__FDK != NULL) {
+- for (ch = 0; ch < hEnc->setup.maxChIn; ch++) {
+- if (hEnc->phQmfFiltIn__FDK[ch] != NULL) {
+- if (hEnc->phQmfFiltIn__FDK[ch]->FilterStates != NULL) {
+- FDK_FREE_MEMORY_1D(hEnc->phQmfFiltIn__FDK[ch]->FilterStates);
+- }
+- FDK_FREE_MEMORY_1D(hEnc->phQmfFiltIn__FDK[ch]);
+- }
+- }
+- FDK_FREE_MEMORY_1D(hEnc->phQmfFiltIn__FDK);
+- }
+- for (ch = 0; ch < hEnc->setup.maxChIn; ch++) {
+- if (NULL != hEnc->phDCFilterSigIn[ch]) {
+- fdk_sacenc_destroyDCFilter(&hEnc->phDCFilterSigIn[ch]);
+- }
+- }
+- /* Close Onset Detection */
+- for (ch = 0; ch < hEnc->setup.maxChIn; ch++) {
+- if (NULL != hEnc->phOnset[ch]) {
+- fdk_sacenc_onsetDetect_Close(&hEnc->phOnset[ch]);
+- }
+- }
+- if (hEnc->ppTrCurrPos) {
+- FDK_FREE_MEMORY_2D(hEnc->ppTrCurrPos);
+- }
+- if (hEnc->hFrameWindow) {
+- fdk_sacenc_frameWindow_Destroy(&hEnc->hFrameWindow);
+- }
+- /* Close Space Tree */
+- if (NULL != hEnc->hSpaceTree) {
+- fdk_sacenc_spaceTree_Close(&hEnc->hSpaceTree);
+- }
+- if (NULL != hEnc->hEnhancedTimeDmx) {
+- fdk_sacenc_close_enhancedTimeDomainDmx(&hEnc->hEnhancedTimeDmx);
+- }
+- /* Close Static Gain */
+- if (NULL != hEnc->hStaticGain) {
+- fdk_sacenc_staticGain_Close(&hEnc->hStaticGain);
+- }
+- if (NULL != hEnc->hStaticGainConfig) {
+- fdk_sacenc_staticGain_CloseConfig(&hEnc->hStaticGainConfig);
+- }
+- /* Close Delay*/
+- if (NULL != hEnc->hDelay) {
+- fdk_sacenc_delay_Close(&hEnc->hDelay);
+- }
+- /* Delete Bitstream Stuff */
+- if (NULL != hEnc->hBitstreamFormatter) {
+- fdk_sacenc_destroySpatialBitstreamEncoder(&(hEnc->hBitstreamFormatter));
+- }
+- if (hEnc->pppHybridIn__FDK != NULL) {
+- if (hEnc->setup.bEncMode_212 == 1) {
+- FDK_FREE_MEMORY_3D(hEnc->pppHybridIn__FDK);
+- FDK_FREE_MEMORY_3D(hEnc->pppHybridInStatic__FDK);
+- } else {
+- FDK_FREE_MEMORY_3D(hEnc->pppHybridIn__FDK);
+- }
+- }
+- if (hEnc->pppProcDataIn__FDK != NULL) {
+- FDK_FREE_MEMORY_3D(hEnc->pppProcDataIn__FDK);
+- }
+- if (hEnc->pOutputDelayBuffer__FDK != NULL) {
+- FDK_FREE_MEMORY_1D(hEnc->pOutputDelayBuffer__FDK);
+- }
+- if (hEnc->ppTimeSigIn__FDK != NULL) {
+- { FDK_FREE_MEMORY_2D(hEnc->ppTimeSigIn__FDK); }
+- }
+- if (hEnc->ppTimeSigDelayIn__FDK != NULL) {
+- FDK_FREE_MEMORY_2D(hEnc->ppTimeSigDelayIn__FDK);
+- }
+- if (hEnc->ppTimeSigOut__FDK != NULL) {
+- FDK_FREE_MEMORY_2D(hEnc->ppTimeSigOut__FDK);
+- }
+- for (i = 0; i < MAX_NUM_PARAMS; i++) {
+- if (hEnc->pFrameWindowAna__FDK[i] != NULL) {
+- FDK_FREE_MEMORY_1D(hEnc->pFrameWindowAna__FDK[i]);
+- }
+- }
+- if (hEnc->pnOutputBits != NULL) {
+- FDK_FREE_MEMORY_1D(hEnc->pnOutputBits);
+- }
+- if (hEnc->ppBitstreamDelayBuffer != NULL) {
+- FDK_FREE_MEMORY_2D(hEnc->ppBitstreamDelayBuffer);
+- }
+- if (hEnc->sscBuf.pSsc != NULL) {
+- FDK_FREE_MEMORY_1D(hEnc->sscBuf.pSsc);
+- }
+- FDK_FREE_MEMORY_1D(*phMp4SpaceEnc);
+- }
+- }
+-
+- return error;
+-}
+-
+-/*-----------------------------------------------------------------------------
+- functionname: mp4SpaceEnc_InitDelayCompensation()
+- description: initialzes delay compensation
+- returns: noError on success, an apropriate error code else
+- -----------------------------------------------------------------------------*/
+-static FDK_SACENC_ERROR mp4SpaceEnc_InitDelayCompensation(
+- HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc, const INT coreCoderDelay) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- /* Sanity Check */
+- if (hMp4SpaceEnc == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- hMp4SpaceEnc->coreCoderDelay = coreCoderDelay;
+-
+- if (SACENC_OK != (error = fdk_sacenc_delay_Init(
+- hMp4SpaceEnc->hDelay, hMp4SpaceEnc->nQmfBands,
+- hMp4SpaceEnc->nFrameLength, coreCoderDelay,
+- hMp4SpaceEnc->timeAlignment))) {
+- goto bail;
+- }
+-
+- fdk_sacenc_delay_SetDmxAlign(hMp4SpaceEnc->hDelay, 0);
+- fdk_sacenc_delay_SetTimeDomDmx(
+- hMp4SpaceEnc->hDelay, (hMp4SpaceEnc->useTimeDomDownmix >= 1) ? 1 : 0);
+- fdk_sacenc_delay_SetMinimizeDelay(hMp4SpaceEnc->hDelay, 1);
+-
+- if (SACENC_OK != (error = fdk_sacenc_delay_SubCalulateBufferDelays(
+- hMp4SpaceEnc->hDelay))) {
+- goto bail;
+- }
+-
+- /* init output delay compensation */
+- hMp4SpaceEnc->nBitstreamDelayBuffer =
+- fdk_sacenc_delay_GetBitstreamFrameBufferSize(hMp4SpaceEnc->hDelay);
+- hMp4SpaceEnc->nOutputBufferDelay =
+- fdk_sacenc_delay_GetOutputAudioBufferDelay(hMp4SpaceEnc->hDelay);
+- hMp4SpaceEnc->nSurroundAnalysisBufferDelay =
+- fdk_sacenc_delay_GetSurroundAnalysisBufferDelay(hMp4SpaceEnc->hDelay);
+- hMp4SpaceEnc->nBitstreamBufferRead = 0;
+- hMp4SpaceEnc->nBitstreamBufferWrite =
+- hMp4SpaceEnc->nBitstreamDelayBuffer - 1;
+-
+- if (hMp4SpaceEnc->encMode == SACENC_212) {
+- /* mode 212 expects no bitstream delay */
+- if (hMp4SpaceEnc->nBitstreamBufferWrite !=
+- hMp4SpaceEnc->nBitstreamBufferRead) {
+- error = SACENC_PARAM_ERROR;
+- goto bail;
+- }
+-
+- /* mode 212 expects no output buffer delay */
+- if (hMp4SpaceEnc->nOutputBufferDelay != 0) {
+- error = SACENC_PARAM_ERROR;
+- goto bail;
+- }
+- }
+-
+- /*** Input delay to obtain a net encoder delay that is a multiple
+- of the used framelength to ensure synchronization of framing
+- in artistic down-mix with the corresponding spatial data. ***/
+- hMp4SpaceEnc->nDiscardOutFrames =
+- fdk_sacenc_delay_GetDiscardOutFrames(hMp4SpaceEnc->hDelay);
+- hMp4SpaceEnc->nInputDelay =
+- fdk_sacenc_delay_GetDmxAlignBufferDelay(hMp4SpaceEnc->hDelay);
+-
+- /* reset independency Flag counter */
+- hMp4SpaceEnc->independencyCount = 0;
+- hMp4SpaceEnc->independencyFlag = 1;
+-
+- int i;
+-
+- /* write some parameters to bitstream */
+- for (i = 0; i < hMp4SpaceEnc->nBitstreamDelayBuffer - 1; i++) {
+- SPATIALFRAME *pFrameData = NULL;
+-
+- if (NULL == (pFrameData = fdk_sacenc_getSpatialFrame(
+- hMp4SpaceEnc->hBitstreamFormatter, READ_SPATIALFRAME))) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- pFrameData->bsIndependencyFlag = 1;
+- pFrameData->framingInfo.numParamSets = 1;
+- pFrameData->framingInfo.bsFramingType = 0;
+-
+- fdk_sacenc_writeSpatialFrame(
+- hMp4SpaceEnc->ppBitstreamDelayBuffer[i], MAX_MPEGS_BYTES,
+- &hMp4SpaceEnc->pnOutputBits[i], hMp4SpaceEnc->hBitstreamFormatter);
+- }
+-
+- if ((hMp4SpaceEnc->nInputDelay > MAX_DELAY_INPUT) ||
+- (hMp4SpaceEnc->nOutputBufferDelay > MAX_DELAY_OUTPUT) ||
+- (hMp4SpaceEnc->nSurroundAnalysisBufferDelay >
+- MAX_DELAY_SURROUND_ANALYSIS) ||
+- (hMp4SpaceEnc->nBitstreamDelayBuffer > MAX_BITSTREAM_DELAY)) {
+- error = SACENC_INIT_ERROR;
+- goto bail;
+- }
+- }
+-
+-bail:
+-
+- return error;
+-}
+-
+-static QUANTMODE __mapQuantMode(const MP4SPACEENC_QUANTMODE quantMode) {
+- QUANTMODE bsQuantMode = QUANTMODE_INVALID;
+-
+- switch (quantMode) {
+- case SACENC_QUANTMODE_FINE:
+- bsQuantMode = QUANTMODE_FINE;
+- break;
+- case SACENC_QUANTMODE_EBQ1:
+- bsQuantMode = QUANTMODE_EBQ1;
+- break;
+- case SACENC_QUANTMODE_EBQ2:
+- bsQuantMode = QUANTMODE_EBQ2;
+- break;
+- case SACENC_QUANTMODE_RSVD3:
+- case SACENC_QUANTMODE_INVALID:
+- default:
+- bsQuantMode = QUANTMODE_INVALID;
+- } /* switch hEnc->quantMode */
+-
+- return bsQuantMode;
+-}
+-
+-static FDK_SACENC_ERROR FillSpatialSpecificConfig(
+- const HANDLE_MP4SPACE_ENCODER hEnc, SPATIALSPECIFICCONFIG *const hSsc) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((NULL == hEnc) || (NULL == hSsc)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- SPACE_TREE_DESCRIPTION spaceTreeDescription;
+- int i;
+-
+- /* Get tree description */
+- if (SACENC_OK != (error = fdk_sacenc_spaceTree_GetDescription(
+- hEnc->hSpaceTree, &spaceTreeDescription))) {
+- goto bail;
+- }
+-
+- /* Fill SSC */
+- FDKmemclear(hSsc, sizeof(SPATIALSPECIFICCONFIG)); /* reset */
+-
+- hSsc->numBands = hEnc->spaceTreeSetup.nParamBands; /* for bsFreqRes */
+-
+- /* Fill tree configuration */
+- hSsc->treeDescription.numOttBoxes = spaceTreeDescription.nOttBoxes;
+- hSsc->treeDescription.numInChan = spaceTreeDescription.nInChannels;
+- hSsc->treeDescription.numOutChan = spaceTreeDescription.nOutChannels;
+-
+- for (i = 0; i < SACENC_MAX_NUM_BOXES; i++) {
+- hSsc->ottConfig[i].bsOttBands = hSsc->numBands;
+- }
+-
+- switch (hEnc->encMode) {
+- case SACENC_212:
+- hSsc->bsTreeConfig = TREE_212;
+- break;
+- case SACENC_INVALID_MODE:
+- default:
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- hSsc->bsSamplingFrequency =
+- hEnc->nSampleRate; /* for bsSamplingFrequencyIndex */
+- hSsc->bsFrameLength = hEnc->nFrameTimeSlots - 1;
+-
+- /* map decorr type */
+- if (DECORR_INVALID ==
+- (hSsc->bsDecorrConfig = mp4SpaceEnc_GetDecorrConfig(hEnc->encMode))) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- /* map quantMode */
+- if (QUANTMODE_INVALID ==
+- (hSsc->bsQuantMode = __mapQuantMode(hEnc->quantMode))) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- /* Configure Gains*/
+- hSsc->bsFixedGainDMX = fdk_sacenc_staticGain_GetDmxGain(hEnc->hStaticGain);
+- hSsc->bsEnvQuantMode = 0;
+-
+- } /* valid handle */
+-
+-bail:
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR mp4SpaceEnc_FillSpaceTreeSetup(
+- const HANDLE_MP4SPACE_ENCODER hEnc,
+- SPACE_TREE_SETUP *const hSpaceTreeSetup) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- /* Sanity Check */
+- if (NULL == hEnc || NULL == hSpaceTreeSetup) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- QUANTMODE tmpQuantmode = QUANTMODE_INVALID;
+-
+- /* map quantMode */
+- if (QUANTMODE_INVALID == (tmpQuantmode = __mapQuantMode(hEnc->quantMode))) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- hSpaceTreeSetup->nParamBands = hEnc->nParamBands;
+- hSpaceTreeSetup->bUseCoarseQuantTtoCld = hEnc->useCoarseQuantCld;
+- hSpaceTreeSetup->bUseCoarseQuantTtoIcc = hEnc->useCoarseQuantIcc;
+- hSpaceTreeSetup->quantMode = tmpQuantmode;
+- hSpaceTreeSetup->nHybridBandsMax = hEnc->nHybridBands;
+-
+- switch (hEnc->encMode) {
+- case SACENC_212:
+- hSpaceTreeSetup->mode = SPACETREE_212;
+- hSpaceTreeSetup->nChannelsInMax = 2;
+- break;
+- case SACENC_INVALID_MODE:
+- default:
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- } /* switch hEnc->encMode */
+-
+- } /* valid handle */
+-bail:
+- return error;
+-}
+-
+-FDK_SACENC_ERROR FDK_sacenc_getInfo(const HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc,
+- MP4SPACEENC_INFO *const pInfo) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((NULL == hMp4SpaceEnc) || (NULL == pInfo)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- pInfo->nSampleRate = hMp4SpaceEnc->nSampleRate;
+- pInfo->nSamplesFrame = hMp4SpaceEnc->nFrameLength;
+- pInfo->nTotalInputChannels = hMp4SpaceEnc->nInputChannels;
+- pInfo->nDmxDelay = fdk_sacenc_delay_GetInfoDmxDelay(hMp4SpaceEnc->hDelay);
+- pInfo->nCodecDelay =
+- fdk_sacenc_delay_GetInfoCodecDelay(hMp4SpaceEnc->hDelay);
+- pInfo->nDecoderDelay =
+- fdk_sacenc_delay_GetInfoDecoderDelay(hMp4SpaceEnc->hDelay);
+- pInfo->nPayloadDelay =
+- fdk_sacenc_delay_GetBitstreamFrameBufferSize(hMp4SpaceEnc->hDelay) - 1;
+- pInfo->nDiscardOutFrames = hMp4SpaceEnc->nDiscardOutFrames;
+-
+- pInfo->pSscBuf = &hMp4SpaceEnc->sscBuf;
+- }
+- return error;
+-}
+-
+-FDK_SACENC_ERROR FDK_sacenc_setParam(HANDLE_MP4SPACE_ENCODER hMp4SpaceEnc,
+- const SPACEENC_PARAM param,
+- const UINT value) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- /* check encoder handle */
+- if (hMp4SpaceEnc == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- /* apply param value */
+- switch (param) {
+- case SACENC_LOWDELAY:
+- if (!((value == 0) || (value == 1) || (value == 2))) {
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+- hMp4SpaceEnc->user.bLdMode = value;
+- break;
+-
+- case SACENC_ENC_MODE:
+- switch ((MP4SPACEENC_MODE)value) {
+- case SACENC_212:
+- hMp4SpaceEnc->user.encMode = (MP4SPACEENC_MODE)value;
+- break;
+- default:
+- error = SACENC_INVALID_CONFIG;
+- }
+- break;
+-
+- case SACENC_SAMPLERATE:
+- if (((int)value < 0) ||
+- ((int)value > hMp4SpaceEnc->setup.maxSamplingrate)) {
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+- hMp4SpaceEnc->user.sampleRate = value;
+- break;
+-
+- case SACENC_FRAME_TIME_SLOTS:
+- if (((int)value < 0) ||
+- ((int)value > hMp4SpaceEnc->setup.maxFrameTimeSlots)) {
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+- hMp4SpaceEnc->user.frameTimeSlots = value;
+- break;
+-
+- case SACENC_PARAM_BANDS:
+- switch ((MP4SPACEENC_BANDS_CONFIG)value) {
+- case SACENC_BANDS_4:
+- case SACENC_BANDS_5:
+- case SACENC_BANDS_7:
+- case SACENC_BANDS_9:
+- case SACENC_BANDS_12:
+- case SACENC_BANDS_15:
+- case SACENC_BANDS_23:
+- hMp4SpaceEnc->user.nParamBands = (MP4SPACEENC_BANDS_CONFIG)value;
+- break;
+- default:
+- error = SACENC_INVALID_CONFIG;
+- }
+- break;
+-
+- case SACENC_TIME_DOM_DMX:
+- if (!((value == 0) || (value == 2))) {
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+- hMp4SpaceEnc->user.bTimeDomainDmx = value;
+- break;
+-
+- case SACENC_DMX_GAIN:
+- if (!((value == 0) || (value == 1) || (value == 2) || (value == 3) ||
+- (value == 4) || (value == 5) || (value == 6) || (value == 7))) {
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+- error = fdk_sacenc_staticGain_SetDmxGain(hMp4SpaceEnc->hStaticGainConfig,
+- (MP4SPACEENC_DMX_GAIN)value);
+- break;
+-
+- case SACENC_COARSE_QUANT:
+- if (!((value == 0) || (value == 1))) {
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+- hMp4SpaceEnc->user.bUseCoarseQuant = value;
+- break;
+-
+- case SACENC_QUANT_MODE:
+- switch ((MP4SPACEENC_QUANTMODE)value) {
+- case SACENC_QUANTMODE_FINE:
+- case SACENC_QUANTMODE_EBQ1:
+- case SACENC_QUANTMODE_EBQ2:
+- hMp4SpaceEnc->user.quantMode = (MP4SPACEENC_QUANTMODE)value;
+- break;
+- default:
+- error = SACENC_INVALID_CONFIG;
+- }
+- break;
+-
+- case SACENC_TIME_ALIGNMENT:
+- if ((INT)value < -32768 || (INT)value > 32767) {
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+- hMp4SpaceEnc->user.timeAlignment = value;
+- break;
+-
+- case SACENC_INDEPENDENCY_COUNT:
+- hMp4SpaceEnc->independencyCount = value;
+- break;
+-
+- case SACENC_INDEPENDENCY_FACTOR:
+- hMp4SpaceEnc->user.independencyFactor = value;
+- break;
+-
+- default:
+- error = SACENC_UNSUPPORTED_PARAMETER;
+- break;
+- } /* switch(param) */
+-bail:
+- return error;
+-}
+-
+-FDK_SACENC_ERROR FDK_sacenc_getLibInfo(LIB_INFO *info) {
+- int i = 0;
+-
+- if (info == NULL) {
+- return SACENC_INVALID_HANDLE;
+- }
+-
+- FDK_toolsGetLibInfo(info);
+-
+- /* search for next free tab */
+- for (i = 0; i < FDK_MODULE_LAST; i++) {
+- if (info[i].module_id == FDK_NONE) break;
+- }
+- if (i == FDK_MODULE_LAST) {
+- return SACENC_INIT_ERROR;
+- }
+-
+- info[i].module_id = FDK_MPSENC;
+- info[i].build_date = SACENC_LIB_BUILD_DATE;
+- info[i].build_time = SACENC_LIB_BUILD_TIME;
+- info[i].title = SACENC_LIB_TITLE;
+- info[i].version = LIB_VERSION(SACENC_LIB_VL0, SACENC_LIB_VL1, SACENC_LIB_VL2);
+- LIB_VERSION_STRING(&info[i]);
+-
+- /* Capability flags */
+- info[i].flags = 0;
+- /* End of flags */
+-
+- return SACENC_OK;
+-}
+-
+-static DECORRCONFIG mp4SpaceEnc_GetDecorrConfig(
+- const MP4SPACEENC_MODE encMode) {
+- DECORRCONFIG decorrConfig = DECORR_INVALID;
+-
+- /* set decorrConfig dependent on tree mode */
+- switch (encMode) {
+- case SACENC_212:
+- decorrConfig = DECORR_QMFSPLIT0;
+- break;
+- case SACENC_INVALID_MODE:
+- default:
+- decorrConfig = DECORR_INVALID;
+- }
+- return decorrConfig;
+-}
+-
+-static FDK_SACENC_ERROR mp4SpaceEnc_InitNumParamBands(
+- HANDLE_MP4SPACE_ENCODER hEnc, const MP4SPACEENC_BANDS_CONFIG nParamBands) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- /* Set/Check nParamBands */
+- int k = 0;
+- const int n = sizeof(pValidBands_Ld) / sizeof(UCHAR);
+- const UCHAR *pBands = pValidBands_Ld;
+-
+- while (k < n && pBands[k] != (UCHAR)nParamBands) ++k;
+- if (k == n) {
+- hEnc->nParamBands = SACENC_BANDS_INVALID;
+- } else {
+- hEnc->nParamBands = nParamBands;
+- }
+- return error;
+-}
+diff --git a/libSACenc/src/sacenc_nlc_enc.cpp b/libSACenc/src/sacenc_nlc_enc.cpp
+deleted file mode 100644
+index 0ba6cc9..0000000
+--- a/libSACenc/src/sacenc_nlc_enc.cpp
++++ /dev/null
+@@ -1,1442 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Karsten Linzmeier
+-
+- Description: Noiseless Coding
+- Huffman encoder
+-
+-*******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_nlc_enc.h"
+-
+-#include "genericStds.h"
+-#include "fixpoint_math.h"
+-
+-#include "sacenc_const.h"
+-#include "sacenc_huff_tab.h"
+-#include "sacenc_paramextract.h"
+-
+-/* Defines *******************************************************************/
+-#define PAIR_SHIFT 4
+-#define PAIR_MASK 0xf
+-
+-#define PBC_MIN_BANDS 5
+-
+-typedef enum {
+- BACKWARDS = 0x0,
+- FORWARDS = 0x1
+-
+-} DIRECTION;
+-
+-typedef enum {
+- DIFF_FREQ = 0x0,
+- DIFF_TIME = 0x1
+-
+-} DIFF_TYPE;
+-
+-typedef enum {
+- HUFF_1D = 0x0,
+- HUFF_2D = 0x1
+-
+-} CODING_SCHEME;
+-
+-typedef enum {
+- FREQ_PAIR = 0x0,
+- TIME_PAIR = 0x1
+-
+-} PAIRING;
+-
+-/* Data Types ****************************************************************/
+-
+-/* Constants *****************************************************************/
+-static const UCHAR lavHuffVal[4] = {0, 2, 6, 7};
+-static const UCHAR lavHuffLen[4] = {1, 2, 3, 3};
+-
+-static const UCHAR lav_step_CLD[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3};
+-static const UCHAR lav_step_ICC[] = {0, 0, 1, 1, 2, 2, 3, 3};
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-static void split_lsb(const SHORT *const in_data, SHORT offset,
+- const INT num_val, SHORT *const out_data_lsb,
+- SHORT *const out_data_msb) {
+- int i;
+-
+- for (i = 0; i < num_val; i++) {
+- SHORT val = in_data[i] + offset;
+- if (out_data_lsb != NULL) out_data_lsb[i] = val & 0x0001;
+- if (out_data_msb != NULL) out_data_msb[i] = val >> 1;
+- }
+-}
+-
+-static void apply_lsb_coding(HANDLE_FDK_BITSTREAM strm,
+- const SHORT *const in_data_lsb, const UINT num_lsb,
+- const INT num_val) {
+- int i;
+-
+- for (i = 0; i < num_val; i++) {
+- FDKwriteBits(strm, in_data_lsb[i], num_lsb);
+- }
+-}
+-
+-static void calc_diff_freq(const SHORT *const in_data, SHORT *const out_data,
+- const INT num_val) {
+- int i;
+- out_data[0] = in_data[0];
+-
+- for (i = 1; i < num_val; i++) {
+- out_data[i] = in_data[i] - in_data[i - 1];
+- }
+-}
+-
+-static void calc_diff_time(const SHORT *const in_data,
+- const SHORT *const prev_data, SHORT *const out_data,
+- const INT num_val) {
+- int i;
+- out_data[0] = in_data[0];
+- out_data[1] = prev_data[0];
+-
+- for (i = 0; i < num_val; i++) {
+- out_data[i + 2] = in_data[i] - prev_data[i];
+- }
+-}
+-
+-static INT sym_check(SHORT data[2], const INT lav, SHORT *const pSym_bits) {
+- UCHAR symBits = 0;
+- int sum_val = data[0] + data[1];
+- int diff_val = data[0] - data[1];
+- int num_sbits = 0;
+-
+- if (sum_val != 0) {
+- int sum_neg = (sum_val < 0) ? 1 : 0;
+- if (sum_neg) {
+- sum_val = -sum_val;
+- diff_val = -diff_val;
+- }
+- symBits = (symBits << 1) | sum_neg;
+- num_sbits++;
+- }
+-
+- if (diff_val != 0) {
+- int diff_neg = (diff_val < 0) ? 1 : 0;
+- if (diff_neg) {
+- diff_val = -diff_val;
+- }
+- symBits = (symBits << 1) | diff_neg;
+- num_sbits++;
+- }
+-
+- if (pSym_bits != NULL) {
+- *pSym_bits = symBits;
+- }
+-
+- if (sum_val % 2) {
+- data[0] = lav - sum_val / 2;
+- data[1] = lav - diff_val / 2;
+- } else {
+- data[0] = sum_val / 2;
+- data[1] = diff_val / 2;
+- }
+-
+- return num_sbits;
+-}
+-
+-static INT ilog2(UINT i) {
+- int l = 0;
+-
+- if (i) i--;
+- while (i > 0) {
+- i >>= 1;
+- l++;
+- }
+-
+- return l;
+-}
+-
+-static SHORT calc_pcm_bits(const SHORT num_val, const SHORT num_levels) {
+- SHORT num_complete_chunks = 0, rest_chunk_size = 0;
+- SHORT max_grp_len = 0, bits_pcm = 0;
+- int chunk_levels, i;
+-
+- switch (num_levels) {
+- case 3:
+- max_grp_len = 5;
+- break;
+- case 6:
+- max_grp_len = 5;
+- break;
+- case 7:
+- max_grp_len = 6;
+- break;
+- case 11:
+- max_grp_len = 2;
+- break;
+- case 13:
+- max_grp_len = 4;
+- break;
+- case 19:
+- max_grp_len = 4;
+- break;
+- case 25:
+- max_grp_len = 3;
+- break;
+- case 51:
+- max_grp_len = 4;
+- break;
+- default:
+- max_grp_len = 1;
+- }
+-
+- num_complete_chunks = num_val / max_grp_len;
+- rest_chunk_size = num_val % max_grp_len;
+-
+- chunk_levels = 1;
+- for (i = 1; i <= max_grp_len; i++) {
+- chunk_levels *= num_levels;
+- }
+-
+- bits_pcm = (SHORT)(ilog2(chunk_levels) * num_complete_chunks);
+- bits_pcm += (SHORT)(ilog2(num_levels) * rest_chunk_size);
+-
+- return bits_pcm;
+-}
+-
+-static void apply_pcm_coding(HANDLE_FDK_BITSTREAM strm,
+- const SHORT *const in_data_1,
+- const SHORT *const in_data_2, const SHORT offset,
+- const SHORT num_val, const SHORT num_levels) {
+- SHORT i = 0, j = 0, idx = 0;
+- SHORT max_grp_len = 0, grp_len = 0, next_val = 0;
+- int grp_val = 0, chunk_levels = 0;
+-
+- SHORT pcm_chunk_size[7] = {0};
+-
+- switch (num_levels) {
+- case 3:
+- max_grp_len = 5;
+- break;
+- case 5:
+- max_grp_len = 3;
+- break;
+- case 6:
+- max_grp_len = 5;
+- break;
+- case 7:
+- max_grp_len = 6;
+- break;
+- case 9:
+- max_grp_len = 5;
+- break;
+- case 11:
+- max_grp_len = 2;
+- break;
+- case 13:
+- max_grp_len = 4;
+- break;
+- case 19:
+- max_grp_len = 4;
+- break;
+- case 25:
+- max_grp_len = 3;
+- break;
+- case 51:
+- max_grp_len = 4;
+- break;
+- default:
+- max_grp_len = 1;
+- }
+-
+- chunk_levels = 1;
+- for (i = 1; i <= max_grp_len; i++) {
+- chunk_levels *= num_levels;
+- pcm_chunk_size[i] = ilog2(chunk_levels);
+- }
+-
+- for (i = 0; i < num_val; i += max_grp_len) {
+- grp_len = FDKmin(max_grp_len, num_val - i);
+- grp_val = 0;
+- for (j = 0; j < grp_len; j++) {
+- idx = i + j;
+- if (in_data_2 == NULL) {
+- next_val = in_data_1[idx];
+- } else if (in_data_1 == NULL) {
+- next_val = in_data_2[idx];
+- } else {
+- next_val = ((idx % 2) ? in_data_2[idx / 2] : in_data_1[idx / 2]);
+- }
+- next_val += offset;
+- grp_val = grp_val * num_levels + next_val;
+- }
+-
+- FDKwriteBits(strm, grp_val, pcm_chunk_size[grp_len]);
+- }
+-}
+-
+-static UINT huff_enc_1D(HANDLE_FDK_BITSTREAM strm, const DATA_TYPE data_type,
+- const INT dim1, SHORT *const in_data,
+- const SHORT num_val, const SHORT p0_flag) {
+- int i, offset = 0;
+- UINT huffBits = 0;
+-
+- HUFF_ENTRY part0 = {0};
+- const HUFF_ENTRY *pHuffTab = NULL;
+-
+- switch (data_type) {
+- case t_CLD:
+- pHuffTab = fdk_sacenc_huffCLDTab.h1D[dim1];
+- break;
+- case t_ICC:
+- pHuffTab = fdk_sacenc_huffICCTab.h1D[dim1];
+- break;
+- }
+-
+- if (p0_flag) {
+- switch (data_type) {
+- case t_CLD:
+- part0 = fdk_sacenc_huffPart0Tab.cld[in_data[0]];
+- break;
+- case t_ICC:
+- part0 = fdk_sacenc_huffPart0Tab.icc[in_data[0]];
+- break;
+- }
+- huffBits += FDKwriteBits(strm, HUFF_VALUE(part0), HUFF_LENGTH(part0));
+- offset = 1;
+- }
+-
+- for (i = offset; i < num_val; i++) {
+- int id_sign = 0;
+- int id = in_data[i];
+-
+- if (id != 0) {
+- id_sign = 0;
+- if (id < 0) {
+- id = -id;
+- id_sign = 1;
+- }
+- }
+-
+- huffBits +=
+- FDKwriteBits(strm, HUFF_VALUE(pHuffTab[id]), HUFF_LENGTH(pHuffTab[id]));
+-
+- if (id != 0) {
+- huffBits += FDKwriteBits(strm, id_sign, 1);
+- }
+- } /* for i */
+-
+- return huffBits;
+-}
+-
+-static void getHuffEntry(const INT lav, const DATA_TYPE data_type, const INT i,
+- const SHORT tab_idx_2D[2], const SHORT in_data[][2],
+- HUFF_ENTRY *const pEntry, HUFF_ENTRY *const pEscape) {
+- const HUFF_CLD_TAB_2D *pCLD2dTab =
+- &fdk_sacenc_huffCLDTab.h2D[tab_idx_2D[0]][tab_idx_2D[1]];
+- const HUFF_ICC_TAB_2D *pICC2dTab =
+- &fdk_sacenc_huffICCTab.h2D[tab_idx_2D[0]][tab_idx_2D[1]];
+-
+- switch (lav) {
+- case 1: {
+- const LAV1_2D *pLav1 = NULL;
+- switch (data_type) {
+- case t_CLD:
+- pLav1 = NULL;
+- break;
+- case t_ICC:
+- pLav1 = &pICC2dTab->lav1;
+- break;
+- }
+- if (pLav1 != NULL) {
+- *pEntry = pLav1->entry[in_data[i][0]][in_data[i][1]];
+- *pEscape = pLav1->escape;
+- }
+- } break;
+- case 3: {
+- const LAV3_2D *pLav3 = NULL;
+- switch (data_type) {
+- case t_CLD:
+- pLav3 = &pCLD2dTab->lav3;
+- break;
+- case t_ICC:
+- pLav3 = &pICC2dTab->lav3;
+- break;
+- }
+- if (pLav3 != NULL) {
+- *pEntry = pLav3->entry[in_data[i][0]][in_data[i][1]];
+- *pEscape = pLav3->escape;
+- }
+- } break;
+- case 5: {
+- const LAV5_2D *pLav5 = NULL;
+- switch (data_type) {
+- case t_CLD:
+- pLav5 = &pCLD2dTab->lav5;
+- break;
+- case t_ICC:
+- pLav5 = &pICC2dTab->lav5;
+- break;
+- }
+- if (pLav5 != NULL) {
+- *pEntry = pLav5->entry[in_data[i][0]][in_data[i][1]];
+- *pEscape = pLav5->escape;
+- }
+- } break;
+- case 7: {
+- const LAV7_2D *pLav7 = NULL;
+- switch (data_type) {
+- case t_CLD:
+- pLav7 = &pCLD2dTab->lav7;
+- break;
+- case t_ICC:
+- pLav7 = &pICC2dTab->lav7;
+- break;
+- }
+- if (pLav7 != NULL) {
+- *pEntry = pLav7->entry[in_data[i][0]][in_data[i][1]];
+- *pEscape = pLav7->escape;
+- }
+- } break;
+- case 9: {
+- const LAV9_2D *pLav9 = NULL;
+- switch (data_type) {
+- case t_CLD:
+- pLav9 = &pCLD2dTab->lav9;
+- break;
+- case t_ICC:
+- pLav9 = NULL;
+- break;
+- }
+- if (pLav9 != NULL) {
+- *pEntry = pLav9->entry[in_data[i][0]][in_data[i][1]];
+- *pEscape = pLav9->escape;
+- }
+- } break;
+- }
+-}
+-
+-static UINT huff_enc_2D(HANDLE_FDK_BITSTREAM strm, const DATA_TYPE data_type,
+- SHORT tab_idx_2D[2], SHORT lav_idx, SHORT in_data[][2],
+- SHORT num_val, SHORT stride, SHORT *p0_data[2]) {
+- SHORT i = 0, lav = 0, num_sbits = 0, sym_bits = 0, escIdx = 0;
+- SHORT esc_data[2][MAXBANDS] = {{0}};
+-
+- UINT huffBits = 0;
+-
+- const HUFF_ENTRY *pHuffEntry = NULL;
+-
+- switch (data_type) {
+- case t_CLD:
+- lav = 2 * lav_idx + 3; /* LAV */
+- pHuffEntry = fdk_sacenc_huffPart0Tab.cld;
+- break;
+- case t_ICC:
+- lav = 2 * lav_idx + 1; /* LAV */
+- pHuffEntry = fdk_sacenc_huffPart0Tab.icc;
+- break;
+- }
+-
+- /* Partition 0 */
+- if (p0_data[0] != NULL) {
+- HUFF_ENTRY entry = pHuffEntry[*p0_data[0]];
+- huffBits += FDKwriteBits(strm, HUFF_VALUE(entry), HUFF_LENGTH(entry));
+- }
+- if (p0_data[1] != NULL) {
+- HUFF_ENTRY entry = pHuffEntry[*p0_data[1]];
+- huffBits += FDKwriteBits(strm, HUFF_VALUE(entry), HUFF_LENGTH(entry));
+- }
+-
+- for (i = 0; i < num_val; i += stride) {
+- HUFF_ENTRY entry = {0};
+- HUFF_ENTRY escape = {0};
+-
+- esc_data[0][escIdx] = in_data[i][0] + lav;
+- esc_data[1][escIdx] = in_data[i][1] + lav;
+-
+- num_sbits = sym_check(in_data[i], lav, &sym_bits);
+-
+- getHuffEntry(lav, data_type, i, tab_idx_2D, in_data, &entry, &escape);
+-
+- huffBits += FDKwriteBits(strm, HUFF_VALUE(entry), HUFF_LENGTH(entry));
+-
+- if ((HUFF_VALUE(entry) == HUFF_VALUE(escape)) &&
+- (HUFF_LENGTH(entry) == HUFF_LENGTH(escape))) {
+- escIdx++;
+- } else {
+- huffBits += FDKwriteBits(strm, sym_bits, num_sbits);
+- }
+- } /* for i */
+-
+- if (escIdx > 0) {
+- huffBits += calc_pcm_bits(2 * escIdx, (2 * lav + 1));
+- if (strm != NULL) {
+- apply_pcm_coding(strm, esc_data[0], esc_data[1], 0 /*offset*/, 2 * escIdx,
+- (2 * lav + 1));
+- }
+- }
+-
+- return huffBits;
+-}
+-
+-static SCHAR get_next_lav_step(const INT lav, const DATA_TYPE data_type) {
+- SCHAR lav_step = 0;
+-
+- switch (data_type) {
+- case t_CLD:
+- lav_step = (lav > 9) ? -1 : lav_step_CLD[lav];
+- break;
+- case t_ICC:
+- lav_step = (lav > 7) ? -1 : lav_step_ICC[lav];
+- break;
+- }
+-
+- return lav_step;
+-}
+-
+-static INT diff_type_offset(const DIFF_TYPE diff_type) {
+- int offset = 0;
+- switch (diff_type) {
+- case DIFF_FREQ:
+- offset = 0;
+- break;
+- case DIFF_TIME:
+- offset = 2;
+- break;
+- }
+- return offset;
+-}
+-
+-static SHORT calc_huff_bits(SHORT *in_data_1, SHORT *in_data_2,
+- const DATA_TYPE data_type,
+- const DIFF_TYPE diff_type_1,
+- const DIFF_TYPE diff_type_2, const SHORT num_val,
+- SHORT *const lav_idx, SHORT *const cdg_scheme) {
+- SHORT tab_idx_2D[2][2] = {{0}};
+- SHORT tab_idx_1D[2] = {0};
+- SHORT df_rest_flag[2] = {0};
+- SHORT p0_flag[2] = {0};
+-
+- SHORT pair_vec[MAXBANDS][2] = {{0}};
+-
+- SHORT *p0_data_1[2] = {NULL};
+- SHORT *p0_data_2[2] = {NULL};
+-
+- SHORT i = 0;
+- SHORT lav_fp[2] = {0};
+-
+- SHORT bit_count_1D = 0;
+- SHORT bit_count_2D_freq = 0;
+- SHORT bit_count_min = 0;
+-
+- SHORT num_val_1_short = 0;
+- SHORT num_val_2_short = 0;
+-
+- SHORT *in_data_1_short = NULL;
+- SHORT *in_data_2_short = NULL;
+-
+- /* 1D Huffman coding */
+- bit_count_1D = 1; /* HUFF_1D */
+-
+- num_val_1_short = num_val;
+- num_val_2_short = num_val;
+-
+- if (in_data_1 != NULL) {
+- in_data_1_short = in_data_1 + diff_type_offset(diff_type_1);
+- }
+- if (in_data_2 != NULL) {
+- in_data_2_short = in_data_2 + diff_type_offset(diff_type_2);
+- }
+-
+- p0_flag[0] = (diff_type_1 == DIFF_FREQ);
+- p0_flag[1] = (diff_type_2 == DIFF_FREQ);
+-
+- tab_idx_1D[0] = (diff_type_1 == DIFF_FREQ) ? 0 : 1;
+- tab_idx_1D[1] = (diff_type_2 == DIFF_FREQ) ? 0 : 1;
+-
+- if (in_data_1 != NULL) {
+- bit_count_1D += huff_enc_1D(NULL, data_type, tab_idx_1D[0], in_data_1_short,
+- num_val_1_short, p0_flag[0]);
+- }
+- if (in_data_2 != NULL) {
+- bit_count_1D += huff_enc_1D(NULL, data_type, tab_idx_1D[1], in_data_2_short,
+- num_val_2_short, p0_flag[1]);
+- }
+-
+- bit_count_min = bit_count_1D;
+- *cdg_scheme = HUFF_1D << PAIR_SHIFT;
+- lav_idx[0] = lav_idx[1] = -1;
+-
+- /* Huffman 2D frequency pairs */
+- bit_count_2D_freq = 1; /* HUFF_2D */
+-
+- num_val_1_short = num_val;
+- num_val_2_short = num_val;
+-
+- if (in_data_1 != NULL) {
+- in_data_1_short = in_data_1 + diff_type_offset(diff_type_1);
+- }
+- if (in_data_2 != NULL) {
+- in_data_2_short = in_data_2 + diff_type_offset(diff_type_2);
+- }
+-
+- lav_fp[0] = lav_fp[1] = 0;
+-
+- p0_data_1[0] = NULL;
+- p0_data_1[1] = NULL;
+- p0_data_2[0] = NULL;
+- p0_data_2[1] = NULL;
+-
+- if (in_data_1 != NULL) {
+- if (diff_type_1 == DIFF_FREQ) {
+- p0_data_1[0] = &in_data_1[0];
+- p0_data_1[1] = NULL;
+-
+- num_val_1_short -= 1;
+- in_data_1_short += 1;
+- }
+-
+- df_rest_flag[0] = num_val_1_short % 2;
+-
+- if (df_rest_flag[0]) num_val_1_short -= 1;
+-
+- for (i = 0; i < num_val_1_short - 1; i += 2) {
+- pair_vec[i][0] = in_data_1_short[i];
+- pair_vec[i][1] = in_data_1_short[i + 1];
+-
+- lav_fp[0] = FDKmax(lav_fp[0], fAbs(pair_vec[i][0]));
+- lav_fp[0] = FDKmax(lav_fp[0], fAbs(pair_vec[i][1]));
+- }
+-
+- tab_idx_2D[0][0] = (diff_type_1 == DIFF_TIME) ? 1 : 0;
+- tab_idx_2D[0][1] = 0;
+-
+- tab_idx_1D[0] = (diff_type_1 == DIFF_FREQ) ? 0 : 1;
+-
+- lav_fp[0] = get_next_lav_step(lav_fp[0], data_type);
+-
+- if (lav_fp[0] != -1) bit_count_2D_freq += lavHuffLen[lav_fp[0]];
+- }
+-
+- if (in_data_2 != NULL) {
+- if (diff_type_2 == DIFF_FREQ) {
+- p0_data_2[0] = NULL;
+- p0_data_2[1] = &in_data_2[0];
+-
+- num_val_2_short -= 1;
+- in_data_2_short += 1;
+- }
+-
+- df_rest_flag[1] = num_val_2_short % 2;
+-
+- if (df_rest_flag[1]) num_val_2_short -= 1;
+-
+- for (i = 0; i < num_val_2_short - 1; i += 2) {
+- pair_vec[i + 1][0] = in_data_2_short[i];
+- pair_vec[i + 1][1] = in_data_2_short[i + 1];
+-
+- lav_fp[1] = FDKmax(lav_fp[1], fAbs(pair_vec[i + 1][0]));
+- lav_fp[1] = FDKmax(lav_fp[1], fAbs(pair_vec[i + 1][1]));
+- }
+-
+- tab_idx_2D[1][0] = (diff_type_2 == DIFF_TIME) ? 1 : 0;
+- tab_idx_2D[1][1] = 0;
+-
+- tab_idx_1D[1] = (diff_type_2 == DIFF_FREQ) ? 0 : 1;
+-
+- lav_fp[1] = get_next_lav_step(lav_fp[1], data_type);
+-
+- if (lav_fp[1] != -1) bit_count_2D_freq += lavHuffLen[lav_fp[1]];
+- }
+-
+- if ((lav_fp[0] != -1) && (lav_fp[1] != -1)) {
+- if (in_data_1 != NULL) {
+- bit_count_2D_freq +=
+- huff_enc_2D(NULL, data_type, tab_idx_2D[0], lav_fp[0], pair_vec,
+- num_val_1_short, 2, p0_data_1);
+- }
+- if (in_data_2 != NULL) {
+- bit_count_2D_freq +=
+- huff_enc_2D(NULL, data_type, tab_idx_2D[1], lav_fp[1], pair_vec + 1,
+- num_val_2_short, 2, p0_data_2);
+- }
+- if (in_data_1 != NULL) {
+- if (df_rest_flag[0])
+- bit_count_2D_freq +=
+- huff_enc_1D(NULL, data_type, tab_idx_1D[0],
+- in_data_1_short + num_val_1_short, 1, 0);
+- }
+- if (in_data_2 != NULL) {
+- if (df_rest_flag[1])
+- bit_count_2D_freq +=
+- huff_enc_1D(NULL, data_type, tab_idx_1D[1],
+- in_data_2_short + num_val_2_short, 1, 0);
+- }
+-
+- if (bit_count_2D_freq < bit_count_min) {
+- bit_count_min = bit_count_2D_freq;
+- *cdg_scheme = HUFF_2D << PAIR_SHIFT | FREQ_PAIR;
+- lav_idx[0] = lav_fp[0];
+- lav_idx[1] = lav_fp[1];
+- }
+- }
+-
+- return bit_count_min;
+-}
+-
+-static void apply_huff_coding(HANDLE_FDK_BITSTREAM strm, SHORT *const in_data_1,
+- SHORT *const in_data_2, const DATA_TYPE data_type,
+- const DIFF_TYPE diff_type_1,
+- const DIFF_TYPE diff_type_2, const SHORT num_val,
+- const SHORT *const lav_idx,
+- const SHORT cdg_scheme) {
+- SHORT tab_idx_2D[2][2] = {{0}};
+- SHORT tab_idx_1D[2] = {0};
+- SHORT df_rest_flag[2] = {0};
+- SHORT p0_flag[2] = {0};
+-
+- SHORT pair_vec[MAXBANDS][2] = {{0}};
+-
+- SHORT *p0_data_1[2] = {NULL};
+- SHORT *p0_data_2[2] = {NULL};
+-
+- SHORT i = 0;
+-
+- SHORT num_val_1_short = num_val;
+- SHORT num_val_2_short = num_val;
+-
+- SHORT *in_data_1_short = NULL;
+- SHORT *in_data_2_short = NULL;
+-
+- /* Offset */
+- if (in_data_1 != NULL) {
+- in_data_1_short = in_data_1 + diff_type_offset(diff_type_1);
+- }
+- if (in_data_2 != NULL) {
+- in_data_2_short = in_data_2 + diff_type_offset(diff_type_2);
+- }
+-
+- /* Signalize coding scheme */
+- FDKwriteBits(strm, cdg_scheme >> PAIR_SHIFT, 1);
+-
+- switch (cdg_scheme >> PAIR_SHIFT) {
+- case HUFF_1D:
+-
+- p0_flag[0] = (diff_type_1 == DIFF_FREQ);
+- p0_flag[1] = (diff_type_2 == DIFF_FREQ);
+-
+- tab_idx_1D[0] = (diff_type_1 == DIFF_FREQ) ? 0 : 1;
+- tab_idx_1D[1] = (diff_type_2 == DIFF_FREQ) ? 0 : 1;
+-
+- if (in_data_1 != NULL) {
+- huff_enc_1D(strm, data_type, tab_idx_1D[0], in_data_1_short,
+- num_val_1_short, p0_flag[0]);
+- }
+- if (in_data_2 != NULL) {
+- huff_enc_1D(strm, data_type, tab_idx_1D[1], in_data_2_short,
+- num_val_2_short, p0_flag[1]);
+- }
+- break; /* HUFF_1D */
+-
+- case HUFF_2D:
+-
+- switch (cdg_scheme & PAIR_MASK) {
+- case FREQ_PAIR:
+-
+- if (in_data_1 != NULL) {
+- if (diff_type_1 == DIFF_FREQ) {
+- p0_data_1[0] = &in_data_1[0];
+- p0_data_1[1] = NULL;
+-
+- num_val_1_short -= 1;
+- in_data_1_short += 1;
+- }
+-
+- df_rest_flag[0] = num_val_1_short % 2;
+-
+- if (df_rest_flag[0]) num_val_1_short -= 1;
+-
+- for (i = 0; i < num_val_1_short - 1; i += 2) {
+- pair_vec[i][0] = in_data_1_short[i];
+- pair_vec[i][1] = in_data_1_short[i + 1];
+- }
+-
+- tab_idx_2D[0][0] = (diff_type_1 == DIFF_TIME) ? 1 : 0;
+- tab_idx_2D[0][1] = 0;
+-
+- tab_idx_1D[0] = (diff_type_1 == DIFF_FREQ) ? 0 : 1;
+- } /* if( in_data_1 != NULL ) */
+-
+- if (in_data_2 != NULL) {
+- if (diff_type_2 == DIFF_FREQ) {
+- p0_data_2[0] = NULL;
+- p0_data_2[1] = &in_data_2[0];
+-
+- num_val_2_short -= 1;
+- in_data_2_short += 1;
+- }
+-
+- df_rest_flag[1] = num_val_2_short % 2;
+-
+- if (df_rest_flag[1]) num_val_2_short -= 1;
+-
+- for (i = 0; i < num_val_2_short - 1; i += 2) {
+- pair_vec[i + 1][0] = in_data_2_short[i];
+- pair_vec[i + 1][1] = in_data_2_short[i + 1];
+- }
+-
+- tab_idx_2D[1][0] = (diff_type_2 == DIFF_TIME) ? 1 : 0;
+- tab_idx_2D[1][1] = 0;
+-
+- tab_idx_1D[1] = (diff_type_2 == DIFF_FREQ) ? 0 : 1;
+- } /* if( in_data_2 != NULL ) */
+-
+- if (in_data_1 != NULL) {
+- FDKwriteBits(strm, lavHuffVal[lav_idx[0]], lavHuffLen[lav_idx[0]]);
+- huff_enc_2D(strm, data_type, tab_idx_2D[0], lav_idx[0], pair_vec,
+- num_val_1_short, 2, p0_data_1);
+- if (df_rest_flag[0]) {
+- huff_enc_1D(strm, data_type, tab_idx_1D[0],
+- in_data_1_short + num_val_1_short, 1, 0);
+- }
+- }
+- if (in_data_2 != NULL) {
+- FDKwriteBits(strm, lavHuffVal[lav_idx[1]], lavHuffLen[lav_idx[1]]);
+- huff_enc_2D(strm, data_type, tab_idx_2D[1], lav_idx[1],
+- pair_vec + 1, num_val_2_short, 2, p0_data_2);
+- if (df_rest_flag[1]) {
+- huff_enc_1D(strm, data_type, tab_idx_1D[1],
+- in_data_2_short + num_val_2_short, 1, 0);
+- }
+- }
+- break; /* FREQ_PAIR */
+-
+- case TIME_PAIR:
+-
+- if ((diff_type_1 == DIFF_FREQ) || (diff_type_2 == DIFF_FREQ)) {
+- p0_data_1[0] = &in_data_1[0];
+- p0_data_1[1] = &in_data_2[0];
+-
+- in_data_1_short += 1;
+- in_data_2_short += 1;
+-
+- num_val_1_short -= 1;
+- }
+-
+- for (i = 0; i < num_val_1_short; i++) {
+- pair_vec[i][0] = in_data_1_short[i];
+- pair_vec[i][1] = in_data_2_short[i];
+- }
+-
+- tab_idx_2D[0][0] =
+- ((diff_type_1 == DIFF_TIME) || (diff_type_2 == DIFF_TIME)) ? 1
+- : 0;
+- tab_idx_2D[0][1] = 1;
+-
+- FDKwriteBits(strm, lavHuffVal[lav_idx[0]], lavHuffLen[lav_idx[0]]);
+-
+- huff_enc_2D(strm, data_type, tab_idx_2D[0], lav_idx[0], pair_vec,
+- num_val_1_short, 1, p0_data_1);
+-
+- break; /* TIME_PAIR */
+- } /* switch( cdg_scheme & PAIR_MASK ) */
+-
+- break; /* HUFF_2D */
+-
+- default:
+- break;
+- } /* switch( cdg_scheme >> PAIR_SHIFT ) */
+-}
+-
+-INT fdk_sacenc_ecDataPairEnc(HANDLE_FDK_BITSTREAM strm,
+- SHORT aaInData[][MAXBANDS],
+- SHORT aHistory[MAXBANDS],
+- const DATA_TYPE data_type, const INT setIdx,
+- const INT startBand, const INT dataBands,
+- const INT coarse_flag,
+- const INT independency_flag) {
+- SHORT reset = 0, pb = 0;
+- SHORT quant_levels = 0, quant_offset = 0, num_pcm_val = 0;
+-
+- SHORT splitLsb_flag = 0;
+- SHORT pcmCoding_flag = 0;
+-
+- SHORT allowDiffTimeBack_flag = !independency_flag || (setIdx > 0);
+-
+- SHORT num_lsb_bits = -1;
+- SHORT num_pcm_bits = -1;
+-
+- SHORT quant_data_lsb[2][MAXBANDS];
+- SHORT quant_data_msb[2][MAXBANDS];
+-
+- SHORT quant_data_hist_lsb[MAXBANDS];
+- SHORT quant_data_hist_msb[MAXBANDS];
+-
+- SHORT data_diff_freq[2][MAXBANDS];
+- SHORT data_diff_time[2][MAXBANDS + 2];
+-
+- SHORT *p_quant_data_msb[2];
+- SHORT *p_quant_data_hist_msb = NULL;
+-
+- SHORT min_bits_all = 0;
+- SHORT min_found = 0;
+-
+- SHORT min_bits_df_df = -1;
+- SHORT min_bits_df_dt = -1;
+- SHORT min_bits_dtbw_df = -1;
+- SHORT min_bits_dt_dt = -1;
+-
+- SHORT lav_df_df[2] = {-1, -1};
+- SHORT lav_df_dt[2] = {-1, -1};
+- SHORT lav_dtbw_df[2] = {-1, -1};
+- SHORT lav_dt_dt[2] = {-1, -1};
+-
+- SHORT coding_scheme_df_df = 0;
+- SHORT coding_scheme_df_dt = 0;
+- SHORT coding_scheme_dtbw_df = 0;
+- SHORT coding_scheme_dt_dt = 0;
+-
+- switch (data_type) {
+- case t_CLD:
+- if (coarse_flag) {
+- splitLsb_flag = 0;
+- quant_levels = 15;
+- quant_offset = 7;
+- } else {
+- splitLsb_flag = 0;
+- quant_levels = 31;
+- quant_offset = 15;
+- }
+- break;
+- case t_ICC:
+- if (coarse_flag) {
+- splitLsb_flag = 0;
+- quant_levels = 4;
+- quant_offset = 0;
+- } else {
+- splitLsb_flag = 0;
+- quant_levels = 8;
+- quant_offset = 0;
+- }
+- break;
+- } /* switch( data_type ) */
+-
+- /* Split off LSB */
+- if (splitLsb_flag) {
+- split_lsb(aaInData[setIdx] + startBand, quant_offset, dataBands,
+- quant_data_lsb[0], quant_data_msb[0]);
+-
+- split_lsb(aaInData[setIdx + 1] + startBand, quant_offset, dataBands,
+- quant_data_lsb[1], quant_data_msb[1]);
+-
+- p_quant_data_msb[0] = quant_data_msb[0];
+- p_quant_data_msb[1] = quant_data_msb[1];
+-
+- num_lsb_bits = 2 * dataBands;
+- } else if (quant_offset != 0) {
+- for (pb = 0; pb < dataBands; pb++) {
+- quant_data_msb[0][pb] = aaInData[setIdx][startBand + pb] + quant_offset;
+- quant_data_msb[1][pb] =
+- aaInData[setIdx + 1][startBand + pb] + quant_offset;
+- }
+-
+- p_quant_data_msb[0] = quant_data_msb[0];
+- p_quant_data_msb[1] = quant_data_msb[1];
+-
+- num_lsb_bits = 0;
+- } else {
+- p_quant_data_msb[0] = aaInData[setIdx] + startBand;
+- p_quant_data_msb[1] = aaInData[setIdx + 1] + startBand;
+-
+- num_lsb_bits = 0;
+- }
+-
+- if (allowDiffTimeBack_flag) {
+- if (splitLsb_flag) {
+- split_lsb(aHistory + startBand, quant_offset, dataBands,
+- quant_data_hist_lsb, quant_data_hist_msb);
+-
+- p_quant_data_hist_msb = quant_data_hist_msb;
+- } else if (quant_offset != 0) {
+- for (pb = 0; pb < dataBands; pb++) {
+- quant_data_hist_msb[pb] = aHistory[startBand + pb] + quant_offset;
+- }
+- p_quant_data_hist_msb = quant_data_hist_msb;
+- } else {
+- p_quant_data_hist_msb = aHistory + startBand;
+- }
+- }
+-
+- /* Calculate frequency differences */
+- calc_diff_freq(p_quant_data_msb[0], data_diff_freq[0], dataBands);
+-
+- calc_diff_freq(p_quant_data_msb[1], data_diff_freq[1], dataBands);
+-
+- /* Calculate time differences */
+- if (allowDiffTimeBack_flag) {
+- calc_diff_time(p_quant_data_msb[0], p_quant_data_hist_msb,
+- data_diff_time[0], dataBands);
+- }
+-
+- calc_diff_time(p_quant_data_msb[1], p_quant_data_msb[0], data_diff_time[1],
+- dataBands);
+-
+- /* Calculate coding scheme with minumum bit consumption */
+-
+- /**********************************************************/
+- num_pcm_bits = calc_pcm_bits(2 * dataBands, quant_levels);
+- num_pcm_val = 2 * dataBands;
+-
+- /**********************************************************/
+-
+- min_bits_all = num_pcm_bits;
+-
+- /**********************************************************/
+- /**********************************************************/
+-
+- /**********************************************************/
+- min_bits_df_df =
+- calc_huff_bits(data_diff_freq[0], data_diff_freq[1], data_type, DIFF_FREQ,
+- DIFF_FREQ, dataBands, lav_df_df, &coding_scheme_df_df);
+-
+- min_bits_df_df += 2;
+-
+- min_bits_df_df += num_lsb_bits;
+-
+- if (min_bits_df_df < min_bits_all) {
+- min_bits_all = min_bits_df_df;
+- }
+- /**********************************************************/
+-
+- /**********************************************************/
+- min_bits_df_dt =
+- calc_huff_bits(data_diff_freq[0], data_diff_time[1], data_type, DIFF_FREQ,
+- DIFF_TIME, dataBands, lav_df_dt, &coding_scheme_df_dt);
+-
+- min_bits_df_dt += 2;
+-
+- min_bits_df_dt += num_lsb_bits;
+-
+- if (min_bits_df_dt < min_bits_all) {
+- min_bits_all = min_bits_df_dt;
+- }
+- /**********************************************************/
+-
+- /**********************************************************/
+- /**********************************************************/
+-
+- if (allowDiffTimeBack_flag) {
+- /**********************************************************/
+- min_bits_dtbw_df = calc_huff_bits(
+- data_diff_time[0], data_diff_freq[1], data_type, DIFF_TIME, DIFF_FREQ,
+- dataBands, lav_dtbw_df, &coding_scheme_dtbw_df);
+-
+- min_bits_dtbw_df += 2;
+-
+- min_bits_dtbw_df += num_lsb_bits;
+-
+- if (min_bits_dtbw_df < min_bits_all) {
+- min_bits_all = min_bits_dtbw_df;
+- }
+- /**********************************************************/
+-
+- /**********************************************************/
+- min_bits_dt_dt = calc_huff_bits(data_diff_time[0], data_diff_time[1],
+- data_type, DIFF_TIME, DIFF_TIME, dataBands,
+- lav_dt_dt, &coding_scheme_dt_dt);
+-
+- min_bits_dt_dt += 2;
+-
+- min_bits_dt_dt += num_lsb_bits;
+-
+- if (min_bits_dt_dt < min_bits_all) {
+- min_bits_all = min_bits_dt_dt;
+- }
+- /**********************************************************/
+-
+- } /* if( allowDiffTimeBack_flag ) */
+-
+- /***************************/
+- /* Start actual coding now */
+- /***************************/
+-
+- /* PCM or Diff/Huff Coding? */
+- pcmCoding_flag = (min_bits_all == num_pcm_bits);
+-
+- FDKwriteBits(strm, pcmCoding_flag, 1);
+-
+- if (pcmCoding_flag) {
+- /* Grouped PCM Coding */
+- apply_pcm_coding(strm, aaInData[setIdx] + startBand,
+- aaInData[setIdx + 1] + startBand, quant_offset,
+- num_pcm_val, quant_levels);
+- } else {
+- /* Diff/Huff Coding */
+-
+- min_found = 0;
+-
+- /*******************************************/
+- if (min_bits_all == min_bits_df_df) {
+- FDKwriteBits(strm, DIFF_FREQ, 1);
+- FDKwriteBits(strm, DIFF_FREQ, 1);
+-
+- apply_huff_coding(strm, data_diff_freq[0], data_diff_freq[1], data_type,
+- DIFF_FREQ, DIFF_FREQ, dataBands, lav_df_df,
+- coding_scheme_df_df);
+-
+- min_found = 1;
+- }
+- /*******************************************/
+-
+- /*******************************************/
+- if (!min_found && (min_bits_all == min_bits_df_dt)) {
+- FDKwriteBits(strm, DIFF_FREQ, 1);
+- FDKwriteBits(strm, DIFF_TIME, 1);
+-
+- apply_huff_coding(strm, data_diff_freq[0], data_diff_time[1], data_type,
+- DIFF_FREQ, DIFF_TIME, dataBands, lav_df_dt,
+- coding_scheme_df_dt);
+-
+- min_found = 1;
+- }
+- /*******************************************/
+-
+- /*******************************************/
+- /*******************************************/
+-
+- if (allowDiffTimeBack_flag) {
+- /*******************************************/
+- if (!min_found && (min_bits_all == min_bits_dtbw_df)) {
+- FDKwriteBits(strm, DIFF_TIME, 1);
+- FDKwriteBits(strm, DIFF_FREQ, 1);
+-
+- apply_huff_coding(strm, data_diff_time[0], data_diff_freq[1], data_type,
+- DIFF_TIME, DIFF_FREQ, dataBands, lav_dtbw_df,
+- coding_scheme_dtbw_df);
+-
+- min_found = 1;
+- }
+- /*******************************************/
+-
+- /*******************************************/
+- if (!min_found && (min_bits_all == min_bits_dt_dt)) {
+- FDKwriteBits(strm, DIFF_TIME, 1);
+- FDKwriteBits(strm, DIFF_TIME, 1);
+-
+- apply_huff_coding(strm, data_diff_time[0], data_diff_time[1], data_type,
+- DIFF_TIME, DIFF_TIME, dataBands, lav_dt_dt,
+- coding_scheme_dt_dt);
+- }
+- /*******************************************/
+-
+- } /* if( allowDiffTimeBack_flag ) */
+-
+- /* LSB coding */
+- if (splitLsb_flag) {
+- apply_lsb_coding(strm, quant_data_lsb[0], 1, dataBands);
+-
+- apply_lsb_coding(strm, quant_data_lsb[1], 1, dataBands);
+- }
+-
+- } /* Diff/Huff/LSB coding */
+-
+- return reset;
+-}
+-
+-INT fdk_sacenc_ecDataSingleEnc(HANDLE_FDK_BITSTREAM strm,
+- SHORT aaInData[][MAXBANDS],
+- SHORT aHistory[MAXBANDS],
+- const DATA_TYPE data_type, const INT setIdx,
+- const INT startBand, const INT dataBands,
+- const INT coarse_flag,
+- const INT independency_flag) {
+- SHORT reset = 0, pb = 0;
+- SHORT quant_levels = 0, quant_offset = 0, num_pcm_val = 0;
+-
+- SHORT splitLsb_flag = 0;
+- SHORT pcmCoding_flag = 0;
+-
+- SHORT allowDiffTimeBack_flag = !independency_flag || (setIdx > 0);
+-
+- SHORT num_lsb_bits = -1;
+- SHORT num_pcm_bits = -1;
+-
+- SHORT quant_data_lsb[MAXBANDS];
+- SHORT quant_data_msb[MAXBANDS];
+-
+- SHORT quant_data_hist_lsb[MAXBANDS];
+- SHORT quant_data_hist_msb[MAXBANDS];
+-
+- SHORT data_diff_freq[MAXBANDS];
+- SHORT data_diff_time[MAXBANDS + 2];
+-
+- SHORT *p_quant_data_msb;
+- SHORT *p_quant_data_hist_msb = NULL;
+-
+- SHORT min_bits_all = 0;
+- SHORT min_found = 0;
+-
+- SHORT min_bits_df = -1;
+- SHORT min_bits_dt = -1;
+-
+- SHORT lav_df[2] = {-1, -1};
+- SHORT lav_dt[2] = {-1, -1};
+-
+- SHORT coding_scheme_df = 0;
+- SHORT coding_scheme_dt = 0;
+-
+- switch (data_type) {
+- case t_CLD:
+- if (coarse_flag) {
+- splitLsb_flag = 0;
+- quant_levels = 15;
+- quant_offset = 7;
+- } else {
+- splitLsb_flag = 0;
+- quant_levels = 31;
+- quant_offset = 15;
+- }
+- break;
+- case t_ICC:
+- if (coarse_flag) {
+- splitLsb_flag = 0;
+- quant_levels = 4;
+- quant_offset = 0;
+- } else {
+- splitLsb_flag = 0;
+- quant_levels = 8;
+- quant_offset = 0;
+- }
+- break;
+- } /* switch( data_type ) */
+-
+- /* Split off LSB */
+- if (splitLsb_flag) {
+- split_lsb(aaInData[setIdx] + startBand, quant_offset, dataBands,
+- quant_data_lsb, quant_data_msb);
+-
+- p_quant_data_msb = quant_data_msb;
+- num_lsb_bits = dataBands;
+- } else if (quant_offset != 0) {
+- for (pb = 0; pb < dataBands; pb++) {
+- quant_data_msb[pb] = aaInData[setIdx][startBand + pb] + quant_offset;
+- }
+-
+- p_quant_data_msb = quant_data_msb;
+- num_lsb_bits = 0;
+- } else {
+- p_quant_data_msb = aaInData[setIdx] + startBand;
+- num_lsb_bits = 0;
+- }
+-
+- if (allowDiffTimeBack_flag) {
+- if (splitLsb_flag) {
+- split_lsb(aHistory + startBand, quant_offset, dataBands,
+- quant_data_hist_lsb, quant_data_hist_msb);
+-
+- p_quant_data_hist_msb = quant_data_hist_msb;
+- } else if (quant_offset != 0) {
+- for (pb = 0; pb < dataBands; pb++) {
+- quant_data_hist_msb[pb] = aHistory[startBand + pb] + quant_offset;
+- }
+- p_quant_data_hist_msb = quant_data_hist_msb;
+- } else {
+- p_quant_data_hist_msb = aHistory + startBand;
+- }
+- }
+-
+- /* Calculate frequency differences */
+- calc_diff_freq(p_quant_data_msb, data_diff_freq, dataBands);
+-
+- /* Calculate time differences */
+- if (allowDiffTimeBack_flag) {
+- calc_diff_time(p_quant_data_msb, p_quant_data_hist_msb, data_diff_time,
+- dataBands);
+- }
+-
+- /* Calculate coding scheme with minumum bit consumption */
+-
+- /**********************************************************/
+- num_pcm_bits = calc_pcm_bits(dataBands, quant_levels);
+- num_pcm_val = dataBands;
+-
+- /**********************************************************/
+-
+- min_bits_all = num_pcm_bits;
+-
+- /**********************************************************/
+- /**********************************************************/
+-
+- /**********************************************************/
+- min_bits_df = calc_huff_bits(data_diff_freq, NULL, data_type, DIFF_FREQ,
+- DIFF_FREQ, dataBands, lav_df, &coding_scheme_df);
+-
+- if (allowDiffTimeBack_flag) min_bits_df += 1;
+-
+- min_bits_df += num_lsb_bits;
+-
+- if (min_bits_df < min_bits_all) {
+- min_bits_all = min_bits_df;
+- }
+- /**********************************************************/
+-
+- /**********************************************************/
+- if (allowDiffTimeBack_flag) {
+- min_bits_dt =
+- calc_huff_bits(data_diff_time, NULL, data_type, DIFF_TIME, DIFF_TIME,
+- dataBands, lav_dt, &coding_scheme_dt);
+-
+- min_bits_dt += 1;
+- min_bits_dt += num_lsb_bits;
+-
+- if (min_bits_dt < min_bits_all) {
+- min_bits_all = min_bits_dt;
+- }
+- } /* if( allowDiffTimeBack_flag ) */
+-
+- /***************************/
+- /* Start actual coding now */
+- /***************************/
+-
+- /* PCM or Diff/Huff Coding? */
+- pcmCoding_flag = (min_bits_all == num_pcm_bits);
+-
+- FDKwriteBits(strm, pcmCoding_flag, 1);
+-
+- if (pcmCoding_flag) {
+- /* Grouped PCM Coding */
+- apply_pcm_coding(strm, aaInData[setIdx] + startBand, NULL, quant_offset,
+- num_pcm_val, quant_levels);
+- } else {
+- /* Diff/Huff Coding */
+-
+- min_found = 0;
+-
+- /*******************************************/
+- if (min_bits_all == min_bits_df) {
+- if (allowDiffTimeBack_flag) {
+- FDKwriteBits(strm, DIFF_FREQ, 1);
+- }
+-
+- apply_huff_coding(strm, data_diff_freq, NULL, data_type, DIFF_FREQ,
+- DIFF_FREQ, dataBands, lav_df, coding_scheme_df);
+-
+- min_found = 1;
+- } /* if( min_bits_all == min_bits_df ) */
+- /*******************************************/
+-
+- /*******************************************/
+- if (allowDiffTimeBack_flag) {
+- /*******************************************/
+- if (!min_found && (min_bits_all == min_bits_dt)) {
+- FDKwriteBits(strm, DIFF_TIME, 1);
+-
+- apply_huff_coding(strm, data_diff_time, NULL, data_type, DIFF_TIME,
+- DIFF_TIME, dataBands, lav_dt, coding_scheme_dt);
+- }
+- /*******************************************/
+-
+- } /* if( allowDiffTimeBack_flag ) */
+-
+- /* LSB coding */
+- if (splitLsb_flag) {
+- apply_lsb_coding(strm, quant_data_lsb, 1, dataBands);
+- }
+-
+- } /* Diff/Huff/LSB coding */
+-
+- return reset;
+-}
+diff --git a/libSACenc/src/sacenc_nlc_enc.h b/libSACenc/src/sacenc_nlc_enc.h
+deleted file mode 100644
+index 506b308..0000000
+--- a/libSACenc/src/sacenc_nlc_enc.h
++++ /dev/null
+@@ -1,141 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Karsten Linzmeier
+-
+- Description: Noiseless Coding
+- Huffman encoder
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_NLC_ENC_H
+-#define SACENC_NLC_ENC_H
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_const.h"
+-#include "FDK_bitstream.h"
+-#include "sacenc_bitstream.h"
+-
+-/* Defines *******************************************************************/
+-#define MAXBANDS MAX_NUM_BINS /* maximum number of frequency bands */
+-
+-/* Data Types ****************************************************************/
+-typedef enum {
+- t_CLD,
+- t_ICC
+-
+-} DATA_TYPE;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-INT fdk_sacenc_ecDataPairEnc(HANDLE_FDK_BITSTREAM strm,
+- SHORT aaInData[][MAXBANDS],
+- SHORT aHistory[MAXBANDS],
+- const DATA_TYPE data_type, const INT setIdx,
+- const INT startBand, const INT dataBands,
+- const INT coarse_flag,
+- const INT independency_flag);
+-
+-INT fdk_sacenc_ecDataSingleEnc(HANDLE_FDK_BITSTREAM strm,
+- SHORT aaInData[][MAXBANDS],
+- SHORT aHistory[MAXBANDS],
+- const DATA_TYPE data_type, const INT setIdx,
+- const INT startBand, const INT dataBands,
+- const INT coarse_flag,
+- const INT independency_flag);
+-
+-#endif /* SACENC_NLC_ENC_H */
+diff --git a/libSACenc/src/sacenc_onsetdetect.cpp b/libSACenc/src/sacenc_onsetdetect.cpp
+deleted file mode 100644
+index 7e9aee1..0000000
+--- a/libSACenc/src/sacenc_onsetdetect.cpp
++++ /dev/null
+@@ -1,381 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Max Neuendorf
+-
+- Description: Encoder Library Interface
+- Detect Onset in current frame
+-
+-*******************************************************************************/
+-
+-/**************************************************************************/ /**
+- \file
+- Description of file contents
+- ******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_onsetdetect.h"
+-#include "genericStds.h"
+-#include "sacenc_vectorfunctions.h"
+-
+-/* Defines *******************************************************************/
+-#define SPACE_ONSET_THRESHOLD (3.0)
+-#define SPACE_ONSET_THRESHOLD_SF (3)
+-#define SPACE_ONSET_THRESHOLD_SQUARE \
+- (FL2FXCONST_DBL((1.0 / (SPACE_ONSET_THRESHOLD * SPACE_ONSET_THRESHOLD)) * \
+- (float)(1 << SPACE_ONSET_THRESHOLD_SF)))
+-
+-/* Data Types ****************************************************************/
+-struct ONSET_DETECT {
+- INT maxTimeSlots;
+- INT minTransientDistance;
+- INT avgEnergyDistance;
+- INT lowerBoundOnsetDetection;
+- INT upperBoundOnsetDetection;
+- FIXP_DBL *pEnergyHist__FDK;
+- SCHAR *pEnergyHistScale;
+- SCHAR avgEnergyDistanceScale;
+-};
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Open(HANDLE_ONSET_DETECT *phOnset,
+- const UINT maxTimeSlots) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+- HANDLE_ONSET_DETECT hOnset = NULL;
+-
+- if (NULL == phOnset) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* Memory Allocation */
+- FDK_ALLOCATE_MEMORY_1D(hOnset, 1, struct ONSET_DETECT);
+- FDK_ALLOCATE_MEMORY_1D(hOnset->pEnergyHist__FDK, 16 + maxTimeSlots,
+- FIXP_DBL);
+- FDK_ALLOCATE_MEMORY_1D(hOnset->pEnergyHistScale, 16 + maxTimeSlots, SCHAR);
+-
+- hOnset->maxTimeSlots = maxTimeSlots;
+- hOnset->minTransientDistance =
+- 8; /* minimum distance between detected transients */
+- hOnset->avgEnergyDistance = 16; /* average energy distance */
+-
+- hOnset->avgEnergyDistanceScale = 4;
+- *phOnset = hOnset;
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_onsetDetect_Close(&hOnset);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Init(
+- HANDLE_ONSET_DETECT hOnset,
+- const ONSET_DETECT_CONFIG *const pOnsetDetectConfig, const UINT initFlags) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((NULL == hOnset) || (pOnsetDetectConfig == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- if ((pOnsetDetectConfig->maxTimeSlots > hOnset->maxTimeSlots) ||
+- (pOnsetDetectConfig->upperBoundOnsetDetection <
+- hOnset->lowerBoundOnsetDetection)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- hOnset->maxTimeSlots = pOnsetDetectConfig->maxTimeSlots;
+- hOnset->lowerBoundOnsetDetection =
+- pOnsetDetectConfig->lowerBoundOnsetDetection;
+- hOnset->upperBoundOnsetDetection =
+- pOnsetDetectConfig->upperBoundOnsetDetection;
+-
+- hOnset->minTransientDistance =
+- 8; /* minimum distance between detected transients */
+- hOnset->avgEnergyDistance = 16; /* average energy distance */
+-
+- hOnset->avgEnergyDistanceScale = 4;
+-
+- /* Init / Reset */
+- if (initFlags) {
+- int i;
+- for (i = 0; i < hOnset->avgEnergyDistance + hOnset->maxTimeSlots; i++)
+- hOnset->pEnergyHistScale[i] = -(DFRACT_BITS - 3);
+-
+- FDKmemset_flex(
+- hOnset->pEnergyHist__FDK,
+- FL2FXCONST_DBL(SACENC_FLOAT_EPSILON * (1 << (DFRACT_BITS - 3))),
+- hOnset->avgEnergyDistance + hOnset->maxTimeSlots);
+- }
+- }
+-
+-bail:
+- return error;
+-}
+-
+-/**************************************************************************/
+-
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Close(HANDLE_ONSET_DETECT *phOnset) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((NULL != phOnset) && (NULL != *phOnset)) {
+- if (NULL != (*phOnset)->pEnergyHist__FDK) {
+- FDKfree((*phOnset)->pEnergyHist__FDK);
+- }
+- (*phOnset)->pEnergyHist__FDK = NULL;
+-
+- if (NULL != (*phOnset)->pEnergyHistScale) {
+- FDKfree((*phOnset)->pEnergyHistScale);
+- }
+- (*phOnset)->pEnergyHistScale = NULL;
+- FDKfree(*phOnset);
+- *phOnset = NULL;
+- }
+- return error;
+-}
+-
+-/**************************************************************************/
+-
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Update(HANDLE_ONSET_DETECT hOnset,
+- const INT timeSlots) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hOnset) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- if (timeSlots > hOnset->maxTimeSlots) {
+- error = SACENC_INVALID_CONFIG;
+- } else {
+- int i;
+- /* Shift old data */
+- for (i = 0; i < hOnset->avgEnergyDistance; i++) {
+- hOnset->pEnergyHist__FDK[i] = hOnset->pEnergyHist__FDK[i + timeSlots];
+- hOnset->pEnergyHistScale[i] = hOnset->pEnergyHistScale[i + timeSlots];
+- }
+-
+- /* Clear for new data */
+- FDKmemset_flex(&hOnset->pEnergyHist__FDK[hOnset->avgEnergyDistance],
+- FL2FXCONST_DBL(SACENC_FLOAT_EPSILON), timeSlots);
+- }
+- }
+- return error;
+-}
+-
+-/**************************************************************************/
+-
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Apply(
+- HANDLE_ONSET_DETECT hOnset, const INT nTimeSlots, const INT nHybridBands,
+- FIXP_DPK *const *const ppHybridData__FDK, const INT hybridDataScale,
+- const INT prevPos, INT pTransientPos[MAX_NUM_TRANS]) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- C_ALLOC_SCRATCH_START(envs, FIXP_DBL, (16 + MAX_TIME_SLOTS))
+- FDKmemclear(envs, (16 + MAX_TIME_SLOTS) * sizeof(FIXP_DBL));
+-
+- if ((hOnset == NULL) || (pTransientPos == NULL) ||
+- (ppHybridData__FDK == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i, ts, trCnt, currPos;
+-
+- if ((nTimeSlots < 0) || (nTimeSlots > hOnset->maxTimeSlots) ||
+- (hOnset->lowerBoundOnsetDetection < -1) ||
+- (hOnset->upperBoundOnsetDetection > nHybridBands)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- const int lowerBoundOnsetDetection = hOnset->lowerBoundOnsetDetection;
+- const int upperBoundOnsetDetection = hOnset->upperBoundOnsetDetection;
+- const int M = hOnset->avgEnergyDistance;
+-
+- {
+- SCHAR *envScale = hOnset->pEnergyHistScale;
+- FIXP_DBL *env = hOnset->pEnergyHist__FDK;
+- const FIXP_DBL threshold_square = SPACE_ONSET_THRESHOLD_SQUARE;
+-
+- trCnt = 0;
+-
+- /* reset transient array */
+- FDKmemset_flex(pTransientPos, -1, MAX_NUM_TRANS);
+-
+- /* minimum transient distance of minTransDist QMF samples */
+- if (prevPos > 0) {
+- currPos = FDKmax(nTimeSlots,
+- prevPos - nTimeSlots + hOnset->minTransientDistance);
+- } else {
+- currPos = nTimeSlots;
+- }
+-
+- /* get energy and scalefactor for each time slot */
+- int outScale;
+- int inScale = 3; /* scale factor determined empirically */
+- for (ts = 0; ts < nTimeSlots; ts++) {
+- env[M + ts] = sumUpCplxPow2(
+- &ppHybridData__FDK[ts][lowerBoundOnsetDetection + 1],
+- SUM_UP_DYNAMIC_SCALE, inScale, &outScale,
+- upperBoundOnsetDetection - lowerBoundOnsetDetection - 1);
+- envScale[M + ts] = outScale + (hybridDataScale << 1);
+- }
+-
+- /* calculate common scale for all time slots */
+- SCHAR maxScale = -(DFRACT_BITS - 1);
+- for (i = 0; i < (nTimeSlots + M); i++) {
+- maxScale = fixMax(maxScale, envScale[i]);
+- }
+-
+- /* apply common scale and store energy in temporary buffer */
+- for (i = 0; i < (nTimeSlots + M); i++) {
+- envs[i] = env[i] >> fixMin((maxScale - envScale[i]), (DFRACT_BITS - 1));
+- }
+-
+- FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f);
+- for (i = 0; i < (nTimeSlots + M); i++) {
+- maxVal |= fAbs(envs[i]);
+- }
+-
+- int s = fixMax(0, CntLeadingZeros(maxVal) - 1);
+-
+- for (i = 0; i < (nTimeSlots + M); i++) {
+- envs[i] = envs[i] << s;
+- }
+-
+- int currPosPrev = currPos;
+- FIXP_DBL p1, p2;
+- p2 = FL2FXCONST_DBL(0.0f);
+- for (; (currPos < (nTimeSlots << 1)) && (trCnt < MAX_NUM_TRANS);
+- currPos++) {
+- p1 = fMultDiv2(envs[currPos - nTimeSlots + M], threshold_square) >>
+- (SPACE_ONSET_THRESHOLD_SF - 1);
+-
+- /* Calculate average of past M energy values */
+- if (currPosPrev == (currPos - 1)) {
+- /* remove last and add new element */
+- p2 -= (envs[currPosPrev - nTimeSlots] >>
+- (int)hOnset->avgEnergyDistanceScale);
+- p2 += (envs[currPos - nTimeSlots + M - 1] >>
+- (int)hOnset->avgEnergyDistanceScale);
+- } else {
+- /* calculate complete vector */
+- p2 = FL2FXCONST_DBL(0.0f);
+- for (ts = 0; ts < M; ts++) {
+- p2 += (envs[currPos - nTimeSlots + ts] >>
+- (int)hOnset->avgEnergyDistanceScale);
+- }
+- }
+- currPosPrev = currPos;
+-
+- {
+- /* save position if transient found */
+- if (p1 > p2) {
+- pTransientPos[trCnt++] = currPos;
+- currPos += hOnset->minTransientDistance;
+- }
+- }
+- } /* for currPos */
+- }
+-
+- } /* valid handle*/
+-bail:
+-
+- C_ALLOC_SCRATCH_END(envs, FIXP_DBL, (16 + MAX_TIME_SLOTS))
+-
+- return error;
+-}
+-
+-/**************************************************************************/
+diff --git a/libSACenc/src/sacenc_onsetdetect.h b/libSACenc/src/sacenc_onsetdetect.h
+deleted file mode 100644
+index 5f3f0bd..0000000
+--- a/libSACenc/src/sacenc_onsetdetect.h
++++ /dev/null
+@@ -1,154 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Max Neuendorf
+-
+- Description: Encoder Library Interface
+- Determine TES flags
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_ONSETDETECT_H
+-#define SACENC_ONSETDETECT_H
+-
+-/**************************************************************************/ /**
+- \file
+- Description of file contents
+- ******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "common_fix.h"
+-#include "FDK_matrixCalloc.h"
+-#include "sacenc_lib.h"
+-#include "sacenc_bitstream.h" /* for def. of MAX_NUM_PARAMS */
+-
+-/* Defines *******************************************************************/
+-#define MAX_NUM_TRANS (MAX_NUM_PARAMS / 2)
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_ONSET_DETECT_CONFIG {
+- INT maxTimeSlots;
+-
+- /* calc transien detection in ]lowerBoundOnsetDetection;
+- * upperBoundOnsetDetection[ */
+- INT lowerBoundOnsetDetection;
+- INT upperBoundOnsetDetection;
+-
+-} ONSET_DETECT_CONFIG;
+-
+-typedef struct ONSET_DETECT *HANDLE_ONSET_DETECT;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Open(HANDLE_ONSET_DETECT *phOnset,
+- const UINT maxTimeSlots);
+-
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Init(
+- HANDLE_ONSET_DETECT hOnset,
+- const ONSET_DETECT_CONFIG *const pOnsetDetectConfig, const UINT initFlags);
+-
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Close(HANDLE_ONSET_DETECT *phOnset);
+-
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Update(HANDLE_ONSET_DETECT hOnset,
+- const INT timeSlots);
+-
+-FDK_SACENC_ERROR fdk_sacenc_onsetDetect_Apply(
+- HANDLE_ONSET_DETECT hOnset, const INT nTimeSlots, const INT nHybridBands,
+- FIXP_DPK *const *const ppHybridData__FDK, const INT hybridDataScale,
+- const INT prevPos, INT pTransientPos[MAX_NUM_TRANS]);
+-
+-#endif /* SACENC_ONSETDETECT_H */
+diff --git a/libSACenc/src/sacenc_paramextract.cpp b/libSACenc/src/sacenc_paramextract.cpp
+deleted file mode 100644
+index dcbce1e..0000000
+--- a/libSACenc/src/sacenc_paramextract.cpp
++++ /dev/null
+@@ -1,725 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): M. Multrus
+-
+- Description: Parameter Extraction
+-
+-*******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_paramextract.h"
+-#include "sacenc_tree.h"
+-#include "sacenc_vectorfunctions.h"
+-
+-/* Defines *******************************************************************/
+-#define LOG10_2_10 (3.01029995664f) /* 10.0f*log10(2.f) */
+-#define SCALE_CLDE_SF (7) /* maxVal in Quant tab is +/- 50 */
+-#define SCALE_CLDD_SF (8) /* maxVal in Quant tab is +/- 150 */
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_TTO_BOX {
+- FIXP_DBL pCld__FDK[MAX_NUM_PARAM_BANDS];
+- FIXP_DBL pIcc__FDK[MAX_NUM_PARAM_BANDS];
+- FIXP_DBL pCldQuant__FDK[MAX_NUM_PARAM_BANDS];
+-
+- const FIXP_DBL *pIccQuantTable__FDK;
+- const FIXP_DBL *pCldQuantTableDec__FDK;
+- const FIXP_DBL *pCldQuantTableEnc__FDK;
+-
+- SCHAR pCldEbQIdx[MAX_NUM_PARAM_BANDS];
+- SCHAR pIccDownmixIdx[MAX_NUM_PARAM_BANDS];
+-
+- UCHAR *pParameterBand2HybridBandOffset;
+- const INT *pSubbandImagSign;
+- UCHAR nHybridBandsMax;
+- UCHAR nParameterBands;
+- UCHAR bFrameKeep;
+-
+- UCHAR iccCorrelationCoherenceBorder;
+- BOX_QUANTMODE boxQuantMode;
+-
+- UCHAR nIccQuantSteps;
+- UCHAR nIccQuantOffset;
+-
+- UCHAR nCldQuantSteps;
+- UCHAR nCldQuantOffset;
+-
+- UCHAR bUseCoarseQuantCld;
+- UCHAR bUseCoarseQuantIcc;
+-
+-} TTO_BOX;
+-
+-struct BOX_SUBBAND_SETUP {
+- BOX_SUBBAND_CONFIG subbandConfig;
+- UCHAR nParameterBands;
+- const UCHAR *pSubband2ParameterIndexLd;
+- UCHAR iccCorrelationCoherenceBorder;
+-};
+-
+-/* Constants *****************************************************************/
+-static const UCHAR subband2Parameter4_Ld[NUM_QMF_BANDS] = {
+- 0, 0, 1, 1, 1, 1, 2, 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, 3, 3, 3, 3, 3,
+- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
+-
+-static const UCHAR subband2Parameter5_Ld[NUM_QMF_BANDS] = {
+- 0, 1, 1, 2, 2, 2, 2, 2, 2, 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, 4, 4, 4, 4, 4,
+- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
+-
+-static const UCHAR subband2Parameter7_Ld[NUM_QMF_BANDS] = {
+- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
+- 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
+-
+-static const UCHAR subband2Parameter9_Ld[NUM_QMF_BANDS] = {
+- 0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
+- 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8};
+-
+-static const UCHAR subband2Parameter12_Ld[NUM_QMF_BANDS] = {
+- 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8,
+- 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+- 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11};
+-
+-static const UCHAR subband2Parameter15_Ld[NUM_QMF_BANDS] = {
+- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11,
+- 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+- 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14};
+-
+-static const UCHAR subband2Parameter23_Ld[NUM_QMF_BANDS] = {
+- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 13, 13,
+- 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 18, 19, 19,
+- 19, 19, 19, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21,
+- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22};
+-
+-static const INT subbandImagSign_Ld[NUM_QMF_BANDS] = {
+- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+-};
+-
+-#define SCALE_CLDE(a) (FL2FXCONST_DBL(a / (float)(1 << SCALE_CLDE_SF)))
+-static const FIXP_DBL cldQuantTableFineEnc__FDK[MAX_CLD_QUANT_FINE] = {
+- SCALE_CLDE(-50.0), SCALE_CLDE(-45.0), SCALE_CLDE(-40.0), SCALE_CLDE(-35.0),
+- SCALE_CLDE(-30.0), SCALE_CLDE(-25.0), SCALE_CLDE(-22.0), SCALE_CLDE(-19.0),
+- SCALE_CLDE(-16.0), SCALE_CLDE(-13.0), SCALE_CLDE(-10.0), SCALE_CLDE(-8.0),
+- SCALE_CLDE(-6.0), SCALE_CLDE(-4.0), SCALE_CLDE(-2.0), SCALE_CLDE(0.0),
+- SCALE_CLDE(2.0), SCALE_CLDE(4.0), SCALE_CLDE(6.0), SCALE_CLDE(8.0),
+- SCALE_CLDE(10.0), SCALE_CLDE(13.0), SCALE_CLDE(16.0), SCALE_CLDE(19.0),
+- SCALE_CLDE(22.0), SCALE_CLDE(25.0), SCALE_CLDE(30.0), SCALE_CLDE(35.0),
+- SCALE_CLDE(40.0), SCALE_CLDE(45.0), SCALE_CLDE(50.0)};
+-
+-static const FIXP_DBL cldQuantTableCoarseEnc__FDK[MAX_CLD_QUANT_COARSE] = {
+- SCALE_CLDE(-50.0), SCALE_CLDE(-35.0), SCALE_CLDE(-25.0), SCALE_CLDE(-19.0),
+- SCALE_CLDE(-13.0), SCALE_CLDE(-8.0), SCALE_CLDE(-4.0), SCALE_CLDE(0.0),
+- SCALE_CLDE(4.0), SCALE_CLDE(8.0), SCALE_CLDE(13.0), SCALE_CLDE(19.0),
+- SCALE_CLDE(25.0), SCALE_CLDE(35.0), SCALE_CLDE(50.0)};
+-
+-#define SCALE_CLDD(a) (FL2FXCONST_DBL(a / (float)(1 << SCALE_CLDD_SF)))
+-static const FIXP_DBL cldQuantTableFineDec__FDK[MAX_CLD_QUANT_FINE] = {
+- SCALE_CLDD(-150.0), SCALE_CLDD(-45.0), SCALE_CLDD(-40.0), SCALE_CLDD(-35.0),
+- SCALE_CLDD(-30.0), SCALE_CLDD(-25.0), SCALE_CLDD(-22.0), SCALE_CLDD(-19.0),
+- SCALE_CLDD(-16.0), SCALE_CLDD(-13.0), SCALE_CLDD(-10.0), SCALE_CLDD(-8.0),
+- SCALE_CLDD(-6.0), SCALE_CLDD(-4.0), SCALE_CLDD(-2.0), SCALE_CLDD(0.0),
+- SCALE_CLDD(2.0), SCALE_CLDD(4.0), SCALE_CLDD(6.0), SCALE_CLDD(8.0),
+- SCALE_CLDD(10.0), SCALE_CLDD(13.0), SCALE_CLDD(16.0), SCALE_CLDD(19.0),
+- SCALE_CLDD(22.0), SCALE_CLDD(25.0), SCALE_CLDD(30.0), SCALE_CLDD(35.0),
+- SCALE_CLDD(40.0), SCALE_CLDD(45.0), SCALE_CLDD(150.0)};
+-
+-static const FIXP_DBL cldQuantTableCoarseDec__FDK[MAX_CLD_QUANT_COARSE] = {
+- SCALE_CLDD(-150.0), SCALE_CLDD(-35.0), SCALE_CLDD(-25.0), SCALE_CLDD(-19.0),
+- SCALE_CLDD(-13.0), SCALE_CLDD(-8.0), SCALE_CLDD(-4.0), SCALE_CLDD(0.0),
+- SCALE_CLDD(4.0), SCALE_CLDD(8.0), SCALE_CLDD(13.0), SCALE_CLDD(19.0),
+- SCALE_CLDD(25.0), SCALE_CLDD(35.0), SCALE_CLDD(150.0)};
+-
+-#define SCALE_ICC(a) (FL2FXCONST_DBL(a))
+-static const FIXP_DBL iccQuantTableFine__FDK[MAX_ICC_QUANT_FINE] = {
+- SCALE_ICC(0.99999999953), SCALE_ICC(0.937f), SCALE_ICC(0.84118f),
+- SCALE_ICC(0.60092f), SCALE_ICC(0.36764f), SCALE_ICC(0.0f),
+- SCALE_ICC(-0.589f), SCALE_ICC(-0.99f)};
+-
+-static const FIXP_DBL iccQuantTableCoarse__FDK[MAX_ICC_QUANT_COARSE] = {
+- SCALE_ICC(0.99999999953), SCALE_ICC(0.84118f), SCALE_ICC(0.36764f),
+- SCALE_ICC(-0.5890f)};
+-
+-static const BOX_SUBBAND_SETUP boxSubbandSetup[] = {
+- {BOX_SUBBANDS_4, 4, subband2Parameter4_Ld, 1},
+- {BOX_SUBBANDS_5, 5, subband2Parameter5_Ld, 2},
+- {BOX_SUBBANDS_7, 7, subband2Parameter7_Ld, 3},
+- {BOX_SUBBANDS_9, 9, subband2Parameter9_Ld, 4},
+- {BOX_SUBBANDS_12, 12, subband2Parameter12_Ld, 4},
+- {BOX_SUBBANDS_15, 15, subband2Parameter15_Ld, 5},
+- {BOX_SUBBANDS_23, 23, subband2Parameter23_Ld, 8}};
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-static const BOX_SUBBAND_SETUP *getBoxSubbandSetup(
+- const BOX_SUBBAND_CONFIG subbandConfig) {
+- int i;
+- const BOX_SUBBAND_SETUP *setup = NULL;
+-
+- for (i = 0; i < (int)(sizeof(boxSubbandSetup) / sizeof(BOX_SUBBAND_SETUP));
+- i++) {
+- if (boxSubbandSetup[i].subbandConfig == subbandConfig) {
+- setup = &boxSubbandSetup[i];
+- break;
+- }
+- }
+- return setup;
+-}
+-
+-static inline void ApplyBBCuesFDK(FIXP_DBL *const pData,
+- const INT nParamBands) {
+- int i, s;
+- FIXP_DBL tmp, invParamBands;
+-
+- invParamBands = fDivNormHighPrec((FIXP_DBL)1, (FIXP_DBL)nParamBands, &s);
+- s = -s;
+-
+- tmp = fMult(pData[0], invParamBands) >> s;
+- for (i = 1; i < nParamBands; i++) {
+- tmp += fMult(pData[i], invParamBands) >> s;
+- }
+-
+- for (i = 0; i < nParamBands; i++) {
+- pData[i] = tmp;
+- }
+-}
+-
+-static INT getNumberParameterBands(const BOX_SUBBAND_CONFIG subbandConfig) {
+- const BOX_SUBBAND_SETUP *setup = getBoxSubbandSetup(subbandConfig);
+- return ((setup == NULL) ? 0 : setup->nParameterBands);
+-}
+-
+-static const UCHAR *getSubband2ParameterIndex(
+- const BOX_SUBBAND_CONFIG subbandConfig) {
+- const BOX_SUBBAND_SETUP *setup = getBoxSubbandSetup(subbandConfig);
+-
+- return ((setup == NULL) ? NULL : (setup->pSubband2ParameterIndexLd));
+-}
+-
+-void fdk_sacenc_calcParameterBand2HybridBandOffset(
+- const BOX_SUBBAND_CONFIG subbandConfig, const INT nHybridBands,
+- UCHAR *pParameterBand2HybridBandOffset) {
+- const BOX_SUBBAND_SETUP *setup = getBoxSubbandSetup(subbandConfig);
+- const UCHAR *pSubband2ParameterIndex;
+-
+- int i, pb;
+-
+- pSubband2ParameterIndex = setup->pSubband2ParameterIndexLd;
+-
+- for (pb = 0, i = 0; i < nHybridBands - 1; i++) {
+- if (pSubband2ParameterIndex[i + 1] - pSubband2ParameterIndex[i]) {
+- pParameterBand2HybridBandOffset[pb++] = (i + 1);
+- }
+- }
+- pParameterBand2HybridBandOffset[pb++] = (i + 1);
+-}
+-
+-const INT *fdk_sacenc_getSubbandImagSign() {
+- const INT *pImagSign = NULL;
+-
+- pImagSign = subbandImagSign_Ld;
+-
+- return (pImagSign);
+-}
+-
+-static INT getIccCorrelationCoherenceBorder(
+- const BOX_SUBBAND_CONFIG subbandConfig, const INT bUseCoherenceOnly) {
+- const BOX_SUBBAND_SETUP *setup = getBoxSubbandSetup(subbandConfig);
+- return (
+- (setup == NULL)
+- ? 0
+- : ((bUseCoherenceOnly) ? 0 : setup->iccCorrelationCoherenceBorder));
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_createTtoBox(HANDLE_TTO_BOX *hTtoBox) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hTtoBox) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDK_ALLOCATE_MEMORY_1D(*hTtoBox, 1, TTO_BOX);
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_destroyTtoBox(hTtoBox);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_initTtoBox(HANDLE_TTO_BOX hTtoBox,
+- const TTO_BOX_CONFIG *const ttoBoxConfig,
+- UCHAR *pParameterBand2HybridBandOffset) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hTtoBox == NULL) || (ttoBoxConfig == NULL) ||
+- (pParameterBand2HybridBandOffset == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDKmemclear(hTtoBox, sizeof(TTO_BOX));
+-
+- hTtoBox->bUseCoarseQuantCld = ttoBoxConfig->bUseCoarseQuantCld;
+- hTtoBox->bUseCoarseQuantIcc = ttoBoxConfig->bUseCoarseQuantIcc;
+- hTtoBox->boxQuantMode = ttoBoxConfig->boxQuantMode;
+- hTtoBox->iccCorrelationCoherenceBorder = getIccCorrelationCoherenceBorder(
+- ttoBoxConfig->subbandConfig, ttoBoxConfig->bUseCoherenceIccOnly);
+- hTtoBox->nHybridBandsMax = ttoBoxConfig->nHybridBandsMax;
+- hTtoBox->nParameterBands =
+- getNumberParameterBands(ttoBoxConfig->subbandConfig);
+- hTtoBox->bFrameKeep = ttoBoxConfig->bFrameKeep;
+-
+- hTtoBox->nIccQuantSteps =
+- fdk_sacenc_getNumberIccQuantLevels(hTtoBox->bUseCoarseQuantIcc);
+- hTtoBox->nIccQuantOffset =
+- fdk_sacenc_getIccQuantOffset(hTtoBox->bUseCoarseQuantIcc);
+-
+- hTtoBox->pIccQuantTable__FDK = hTtoBox->bUseCoarseQuantIcc
+- ? iccQuantTableCoarse__FDK
+- : iccQuantTableFine__FDK;
+- hTtoBox->pCldQuantTableDec__FDK = hTtoBox->bUseCoarseQuantCld
+- ? cldQuantTableCoarseDec__FDK
+- : cldQuantTableFineDec__FDK;
+- hTtoBox->pCldQuantTableEnc__FDK = hTtoBox->bUseCoarseQuantCld
+- ? cldQuantTableCoarseEnc__FDK
+- : cldQuantTableFineEnc__FDK;
+-
+- hTtoBox->nCldQuantSteps =
+- fdk_sacenc_getNumberCldQuantLevels(hTtoBox->bUseCoarseQuantCld);
+- hTtoBox->nCldQuantOffset =
+- fdk_sacenc_getCldQuantOffset(hTtoBox->bUseCoarseQuantCld);
+-
+- /* sanity */
+- if (NULL == (hTtoBox->pParameterBand2HybridBandOffset =
+- pParameterBand2HybridBandOffset)) {
+- error = SACENC_INIT_ERROR;
+- goto bail;
+- }
+-
+- if (NULL == (hTtoBox->pSubbandImagSign = fdk_sacenc_getSubbandImagSign())) {
+- error = SACENC_INIT_ERROR;
+- }
+-
+- if ((hTtoBox->boxQuantMode != BOX_QUANTMODE_FINE) &&
+- (hTtoBox->boxQuantMode != BOX_QUANTMODE_EBQ1) &&
+- (hTtoBox->boxQuantMode != BOX_QUANTMODE_EBQ2)) {
+- error = SACENC_INIT_ERROR;
+- goto bail;
+- }
+- }
+-bail:
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_destroyTtoBox(HANDLE_TTO_BOX *hTtoBox) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (*hTtoBox != NULL) {
+- FDKfree(*hTtoBox);
+- *hTtoBox = NULL;
+- }
+-
+- return error;
+-}
+-
+-static FDK_SACENC_ERROR calculateIccFDK(const INT nParamBand,
+- const INT correlationCoherenceBorder,
+- const FIXP_DBL *const pPwr1,
+- const FIXP_DBL *const pPwr2,
+- const FIXP_DBL *const pProdReal,
+- FIXP_DBL const *const pProdImag,
+- FIXP_DBL *const pIcc) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((pPwr1 == NULL) || (pPwr2 == NULL) || (pProdReal == NULL) ||
+- (pProdImag == NULL) || (pIcc == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* sanity check border */
+- if (correlationCoherenceBorder > nParamBand) {
+- error = SACENC_INVALID_CONFIG;
+- } else {
+- /* correlation */
+- FDKcalcCorrelationVec(pIcc, pProdReal, pPwr1, pPwr2,
+- correlationCoherenceBorder);
+-
+- /* coherence */
+- calcCoherenceVec(&pIcc[correlationCoherenceBorder],
+- &pProdReal[correlationCoherenceBorder],
+- &pProdImag[correlationCoherenceBorder],
+- &pPwr1[correlationCoherenceBorder],
+- &pPwr2[correlationCoherenceBorder], 0, 0,
+- nParamBand - correlationCoherenceBorder);
+-
+- } /* valid configuration */
+- } /* valid handle */
+-
+- return error;
+-}
+-
+-static void QuantizeCoefFDK(const FIXP_DBL *const input, const INT nBands,
+- const FIXP_DBL *const quantTable,
+- const INT idxOffset, const INT nQuantSteps,
+- SCHAR *const quantOut) {
+- int band;
+- const int reverse = (quantTable[0] > quantTable[1]);
+-
+- for (band = 0; band < nBands; band++) {
+- FIXP_DBL qVal;
+- FIXP_DBL curVal = input[band];
+-
+- int lower = 0;
+- int upper = nQuantSteps - 1;
+-
+- if (reverse) {
+- while (upper - lower > 1) {
+- int idx = (lower + upper) >> 1;
+- qVal = quantTable[idx];
+- if (curVal >= qVal) {
+- upper = idx;
+- } else {
+- lower = idx;
+- }
+- } /* while */
+-
+- if ((curVal - quantTable[lower]) >= (quantTable[upper] - curVal)) {
+- quantOut[band] = lower - idxOffset;
+- } else {
+- quantOut[band] = upper - idxOffset;
+- }
+- } /* if reverse */
+- else {
+- while (upper - lower > 1) {
+- int idx = (lower + upper) >> 1;
+- qVal = quantTable[idx];
+- if (curVal <= qVal) {
+- upper = idx;
+- } else {
+- lower = idx;
+- }
+- } /* while */
+-
+- if ((curVal - quantTable[lower]) <= (quantTable[upper] - curVal)) {
+- quantOut[band] = lower - idxOffset;
+- } else {
+- quantOut[band] = upper - idxOffset;
+- }
+- } /* else reverse */
+- } /* for band */
+-}
+-
+-static void deQuantizeCoefFDK(const SCHAR *const input, const INT nBands,
+- const FIXP_DBL *const quantTable,
+- const INT idxOffset, FIXP_DBL *const dequantOut) {
+- int band;
+-
+- for (band = 0; band < nBands; band++) {
+- dequantOut[band] = quantTable[input[band] + idxOffset];
+- }
+-}
+-
+-static void CalculateCldFDK(FIXP_DBL *const pCld, const FIXP_DBL *const pPwr1,
+- const FIXP_DBL *const pPwr2, const INT scaleCh1,
+- const INT *const pbScaleCh1, const INT scaleCh2,
+- const INT *const pbScaleCh2, const int nParamBand) {
+- INT i;
+- FIXP_DBL ldPwr1, ldPwr2, cld;
+- FIXP_DBL maxPwr = FL2FXCONST_DBL(
+- 30.0f /
+- (1 << (LD_DATA_SHIFT +
+- 1))); /* consider SACENC_FLOAT_EPSILON in power calculation */
+-
+- for (i = 0; i < nParamBand; i++) {
+- ldPwr1 =
+- (CalcLdData(pPwr1[i]) >> 1) + ((FIXP_DBL)(scaleCh1 + pbScaleCh1[i])
+- << (DFRACT_BITS - 1 - LD_DATA_SHIFT));
+- ldPwr2 =
+- (CalcLdData(pPwr2[i]) >> 1) + ((FIXP_DBL)(scaleCh2 + pbScaleCh2[i])
+- << (DFRACT_BITS - 1 - LD_DATA_SHIFT));
+-
+- ldPwr1 = fixMax(fixMin(ldPwr1, maxPwr), -maxPwr);
+- ldPwr2 = fixMax(fixMin(ldPwr2, maxPwr), -maxPwr);
+-
+- /* ldPwr1 and ldPwr2 are scaled by LD_DATA_SHIFT and additional 1 bit; 1 bit
+- * scale by fMultDiv2() */
+- cld = fMultDiv2(FL2FXCONST_DBL(LOG10_2_10 / (1 << SCALE_CLDE_SF)),
+- ldPwr1 - ldPwr2);
+-
+- cld =
+- fixMin(cld, (FIXP_DBL)(((FIXP_DBL)MAXVAL_DBL) >> (LD_DATA_SHIFT + 2)));
+- cld =
+- fixMax(cld, (FIXP_DBL)(((FIXP_DBL)MINVAL_DBL) >> (LD_DATA_SHIFT + 2)));
+- pCld[i] = cld << (LD_DATA_SHIFT + 2);
+- }
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_applyTtoBox(
+- HANDLE_TTO_BOX hTtoBox, const INT nTimeSlots, const INT startTimeSlot,
+- const INT nHybridBands, const FIXP_DPK *const *const ppHybridData1__FDK,
+- const FIXP_DPK *const *const ppHybridData2__FDK, SCHAR *const pIccIdx,
+- UCHAR *const pbIccQuantCoarse, SCHAR *const pCldIdx,
+- UCHAR *const pbCldQuantCoarse, const INT bUseBBCues, INT *scaleCh1,
+- INT *scaleCh2) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- C_ALLOC_SCRATCH_START(powerHybridData1__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_START(powerHybridData2__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_START(prodHybridDataReal__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_START(prodHybridDataImag__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+-
+- C_ALLOC_SCRATCH_START(IccDownmix__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_START(IccDownmixQuant__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_START(pbScaleCh1, INT, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_START(pbScaleCh2, INT, MAX_NUM_PARAM_BANDS)
+-
+- if ((hTtoBox == NULL) || (pCldIdx == NULL) || (pbCldQuantCoarse == NULL) ||
+- (ppHybridData1__FDK == NULL) || (ppHybridData2__FDK == NULL) ||
+- (pIccIdx == NULL) || (pbIccQuantCoarse == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int j, pb;
+- const int nParamBands = hTtoBox->nParameterBands;
+- const int bUseEbQ = (hTtoBox->boxQuantMode == BOX_QUANTMODE_EBQ1) ||
+- (hTtoBox->boxQuantMode == BOX_QUANTMODE_EBQ2);
+-
+- /* sanity check */
+- if ((nHybridBands < 0) || (nHybridBands > hTtoBox->nHybridBandsMax)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- int outScale; /* scalefactor will not be evaluated */
+- int inScale = 5; /* scale factor determined empirically */
+-
+- /* calculate the headroom of the hybrid data for each parameter band */
+- FDKcalcPbScaleFactor(ppHybridData1__FDK,
+- hTtoBox->pParameterBand2HybridBandOffset, pbScaleCh1,
+- startTimeSlot, nTimeSlots, nParamBands);
+- FDKcalcPbScaleFactor(ppHybridData2__FDK,
+- hTtoBox->pParameterBand2HybridBandOffset, pbScaleCh2,
+- startTimeSlot, nTimeSlots, nParamBands);
+-
+- for (j = 0, pb = 0; pb < nParamBands; pb++) {
+- FIXP_DBL data1, data2;
+- data1 = data2 = (FIXP_DBL)0;
+- for (; j < hTtoBox->pParameterBand2HybridBandOffset[pb]; j++) {
+- data1 += sumUpCplxPow2Dim2(ppHybridData1__FDK, SUM_UP_STATIC_SCALE,
+- inScale + pbScaleCh1[pb], &outScale,
+- startTimeSlot, nTimeSlots, j, j + 1);
+- data2 += sumUpCplxPow2Dim2(ppHybridData2__FDK, SUM_UP_STATIC_SCALE,
+- inScale + pbScaleCh2[pb], &outScale,
+- startTimeSlot, nTimeSlots, j, j + 1);
+- } /* for j */
+- powerHybridData1__FDK[pb] = data1;
+- powerHybridData2__FDK[pb] = data2;
+- } /* pb */
+-
+- {
+- for (j = 0, pb = 0; pb < nParamBands; pb++) {
+- FIXP_DBL dataReal, dataImag;
+- dataReal = dataImag = (FIXP_DBL)0;
+- for (; j < hTtoBox->pParameterBand2HybridBandOffset[pb]; j++) {
+- FIXP_DPK scalarProd;
+- cplx_cplxScalarProduct(&scalarProd, ppHybridData1__FDK,
+- ppHybridData2__FDK, inScale + pbScaleCh1[pb],
+- inScale + pbScaleCh2[pb], &outScale,
+- startTimeSlot, nTimeSlots, j, j + 1);
+- dataReal += scalarProd.v.re;
+- if (hTtoBox->pSubbandImagSign[j] < 0) {
+- dataImag -= scalarProd.v.im;
+- } else {
+- dataImag += scalarProd.v.im;
+- }
+- } /* for j */
+- prodHybridDataReal__FDK[pb] = dataReal;
+- prodHybridDataImag__FDK[pb] = dataImag;
+- } /* pb */
+-
+- if (SACENC_OK != (error = calculateIccFDK(
+- nParamBands, hTtoBox->iccCorrelationCoherenceBorder,
+- powerHybridData1__FDK, powerHybridData2__FDK,
+- prodHybridDataReal__FDK, prodHybridDataImag__FDK,
+- hTtoBox->pIcc__FDK))) {
+- goto bail;
+- }
+-
+- /* calculate correlation based Icc for downmix */
+- if (SACENC_OK != (error = calculateIccFDK(
+- nParamBands, nParamBands, powerHybridData1__FDK,
+- powerHybridData2__FDK, prodHybridDataReal__FDK,
+- prodHybridDataImag__FDK, IccDownmix__FDK))) {
+- goto bail;
+- }
+- }
+-
+- if (!bUseEbQ) {
+- CalculateCldFDK(hTtoBox->pCld__FDK, powerHybridData1__FDK,
+- powerHybridData2__FDK, *scaleCh1 + inScale + 1,
+- pbScaleCh1, *scaleCh2 + inScale + 1, pbScaleCh2,
+- nParamBands);
+- }
+-
+- if (bUseBBCues) {
+- ApplyBBCuesFDK(&hTtoBox->pCld__FDK[0], nParamBands);
+-
+- { ApplyBBCuesFDK(&hTtoBox->pIcc__FDK[0], nParamBands); }
+-
+- } /* bUseBBCues */
+-
+- /* quantize/de-quantize icc */
+- {
+- QuantizeCoefFDK(hTtoBox->pIcc__FDK, nParamBands,
+- hTtoBox->pIccQuantTable__FDK, hTtoBox->nIccQuantOffset,
+- hTtoBox->nIccQuantSteps, pIccIdx);
+- QuantizeCoefFDK(IccDownmix__FDK, nParamBands,
+- hTtoBox->pIccQuantTable__FDK, hTtoBox->nIccQuantOffset,
+- hTtoBox->nIccQuantSteps, hTtoBox->pIccDownmixIdx);
+- deQuantizeCoefFDK(hTtoBox->pIccDownmixIdx, nParamBands,
+- hTtoBox->pIccQuantTable__FDK, hTtoBox->nIccQuantOffset,
+- IccDownmixQuant__FDK);
+-
+- *pbIccQuantCoarse = hTtoBox->bUseCoarseQuantIcc;
+- }
+-
+- /* quantize/de-quantize cld */
+- if (!bUseEbQ) {
+- QuantizeCoefFDK(hTtoBox->pCld__FDK, nParamBands,
+- hTtoBox->pCldQuantTableEnc__FDK, hTtoBox->nCldQuantOffset,
+- hTtoBox->nCldQuantSteps, pCldIdx);
+- deQuantizeCoefFDK(pCldIdx, nParamBands, hTtoBox->pCldQuantTableDec__FDK,
+- hTtoBox->nCldQuantOffset, hTtoBox->pCldQuant__FDK);
+- } else {
+- FDKmemcpy(pCldIdx, hTtoBox->pCldEbQIdx, nParamBands * sizeof(SCHAR));
+- }
+- *pbCldQuantCoarse = hTtoBox->bUseCoarseQuantCld;
+-
+- } /* valid handle */
+-
+-bail:
+- C_ALLOC_SCRATCH_END(pbScaleCh2, INT, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_END(pbScaleCh1, INT, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_END(IccDownmixQuant__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_END(IccDownmix__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+-
+- C_ALLOC_SCRATCH_END(prodHybridDataImag__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_END(prodHybridDataReal__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_END(powerHybridData2__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+- C_ALLOC_SCRATCH_END(powerHybridData1__FDK, FIXP_DBL, MAX_NUM_PARAM_BANDS)
+-
+- return error;
+-}
+-
+-INT fdk_sacenc_subband2ParamBand(const BOX_SUBBAND_CONFIG boxSubbandConfig,
+- const INT nSubband) {
+- INT nParamBand = -1;
+- const UCHAR *pSubband2ParameterIndex =
+- getSubband2ParameterIndex(boxSubbandConfig);
+-
+- if (pSubband2ParameterIndex != NULL) {
+- const int hybrid_resolution = 64;
+-
+- if ((nSubband > -1) && (nSubband < hybrid_resolution)) {
+- nParamBand = pSubband2ParameterIndex[nSubband];
+- }
+- }
+-
+- return nParamBand;
+-}
+diff --git a/libSACenc/src/sacenc_paramextract.h b/libSACenc/src/sacenc_paramextract.h
+deleted file mode 100644
+index 9ebb902..0000000
+--- a/libSACenc/src/sacenc_paramextract.h
++++ /dev/null
+@@ -1,214 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): M. Multrus
+-
+- Description: Parameter Extraction
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_PARAMEXTRACT_H
+-#define SACENC_PARAMEXTRACT_H
+-
+-/* Includes ******************************************************************/
+-#include "common_fix.h"
+-#include "sacenc_lib.h"
+-#include "sacenc_const.h"
+-#include "sacenc_bitstream.h"
+-
+-/* Defines *******************************************************************/
+-#define MAX_CLD_QUANT_FINE (31)
+-#define MAX_CLD_QUANT_COARSE (15)
+-#define OFFSET_CLD_QUANT_COARSE (7)
+-#define OFFSET_CLD_QUANT_FINE (15)
+-
+-#define MAX_ICC_QUANT_COARSE (4)
+-#define MAX_ICC_QUANT_FINE (8)
+-#define OFFSET_ICC_QUANT_COARSE (0)
+-#define OFFSET_ICC_QUANT_FINE (0)
+-
+-#define MAX_NUM_PARAM_BANDS (28)
+-
+-#define NUM_MAPPED_HYBRID_BANDS (16)
+-
+-/* Data Types ****************************************************************/
+-typedef struct T_TTO_BOX *HANDLE_TTO_BOX;
+-
+-typedef enum {
+- BOX_SUBBANDS_INVALID = 0,
+- BOX_SUBBANDS_4 = 4,
+- BOX_SUBBANDS_5 = 5,
+- BOX_SUBBANDS_7 = 7,
+- BOX_SUBBANDS_9 = 9,
+- BOX_SUBBANDS_12 = 12,
+- BOX_SUBBANDS_15 = 15,
+- BOX_SUBBANDS_23 = 23
+-
+-} BOX_SUBBAND_CONFIG;
+-
+-typedef enum {
+- BOX_QUANTMODE_INVALID = -1,
+- BOX_QUANTMODE_FINE = 0,
+- BOX_QUANTMODE_EBQ1 = 1,
+- BOX_QUANTMODE_EBQ2 = 2,
+- BOX_QUANTMODE_RESERVED3 = 3,
+- BOX_QUANTMODE_RESERVED4 = 4,
+- BOX_QUANTMODE_RESERVED5 = 5,
+- BOX_QUANTMODE_RESERVED6 = 6,
+- BOX_QUANTMODE_RESERVED7 = 7
+-
+-} BOX_QUANTMODE;
+-
+-typedef struct T_TTO_BOX_CONFIG {
+- UCHAR bUseCoarseQuantCld;
+- UCHAR bUseCoarseQuantIcc;
+- UCHAR bUseCoherenceIccOnly;
+-
+- BOX_SUBBAND_CONFIG subbandConfig;
+- BOX_QUANTMODE boxQuantMode;
+-
+- UCHAR nHybridBandsMax;
+-
+- UCHAR bFrameKeep;
+-
+-} TTO_BOX_CONFIG;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_createTtoBox(HANDLE_TTO_BOX *hTtoBox);
+-
+-FDK_SACENC_ERROR fdk_sacenc_initTtoBox(HANDLE_TTO_BOX hTtoBox,
+- const TTO_BOX_CONFIG *const ttoBoxConfig,
+- UCHAR *pParameterBand2HybridBandOffset);
+-
+-FDK_SACENC_ERROR fdk_sacenc_destroyTtoBox(HANDLE_TTO_BOX *hTtoBox);
+-
+-FDK_SACENC_ERROR fdk_sacenc_applyTtoBox(
+- HANDLE_TTO_BOX hTtoBox, const INT nTimeSlots, const INT startTimeSlot,
+- const INT nHybridBands, const FIXP_DPK *const *const ppHybridData1__FDK,
+- const FIXP_DPK *const *const ppHybridData2__FDK, SCHAR *const pIccIdx,
+- UCHAR *const pbIccQuantCoarse, SCHAR *const pCldIdx,
+- UCHAR *const pbCldQuantCoarse, const INT bUseBBCues, INT *scaleCh0,
+- INT *scaleCh1);
+-
+-INT fdk_sacenc_subband2ParamBand(const BOX_SUBBAND_CONFIG boxSubbandConfig,
+- const INT nSubband);
+-
+-const INT *fdk_sacenc_getSubbandImagSign();
+-
+-void fdk_sacenc_calcParameterBand2HybridBandOffset(
+- const BOX_SUBBAND_CONFIG subbandConfig, const INT nHybridBands,
+- UCHAR *pParameterBand2HybridBandOffset);
+-
+-/* Function / Class Definition ***********************************************/
+-static inline UCHAR fdk_sacenc_getCldQuantOffset(const INT bUseCoarseQuant) {
+- return ((bUseCoarseQuant) ? OFFSET_CLD_QUANT_COARSE : OFFSET_CLD_QUANT_FINE);
+-}
+-static inline UCHAR fdk_sacenc_getIccQuantOffset(const INT bUseCoarseQuant) {
+- return ((bUseCoarseQuant) ? OFFSET_ICC_QUANT_COARSE : OFFSET_ICC_QUANT_FINE);
+-}
+-
+-static inline UCHAR fdk_sacenc_getNumberCldQuantLevels(
+- const INT bUseCoarseQuant) {
+- return ((bUseCoarseQuant) ? MAX_CLD_QUANT_COARSE : MAX_CLD_QUANT_FINE);
+-}
+-static inline UCHAR fdk_sacenc_getNumberIccQuantLevels(
+- const INT bUseCoarseQuant) {
+- return ((bUseCoarseQuant) ? MAX_ICC_QUANT_COARSE : MAX_ICC_QUANT_FINE);
+-}
+-
+-#endif /* SACENC_PARAMEXTRACT_H */
+diff --git a/libSACenc/src/sacenc_staticgain.cpp b/libSACenc/src/sacenc_staticgain.cpp
+deleted file mode 100644
+index fef9f8d..0000000
+--- a/libSACenc/src/sacenc_staticgain.cpp
++++ /dev/null
+@@ -1,446 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Christian Goettlinger
+-
+- Description: Encoder Library Interface
+- gain management of the encoder
+-
+-*******************************************************************************/
+-
+-/*****************************************************************************
+-\file
+-This file contains all static gain infrastructure
+-******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_staticgain.h"
+-
+-/* Defines *******************************************************************/
+-#define MP4SPACEENC_DMX_GAIN_DEFAULT SACENC_DMXGAIN_3_dB
+-#define GAINCF_SF (4)
+-#define GAINCT1(x) FL2FXCONST_DBL(x)
+-#define GAINCF(x) FL2FXCONST_DBL(x)
+-
+-#define GAINCT2(x) FL2FXCONST_DBL(x)
+-#define FX_DBL2FX_GAIN(x) (x)
+-
+-/* Data Types ****************************************************************/
+-struct STATIC_GAIN {
+- /* External Config Values */
+- MP4SPACEENC_MODE encMode;
+- MP4SPACEENC_DMX_GAIN fixedGainDMX;
+- INT preGainFactorDb;
+-
+- /* Internal Values */
+- FIXP_GAIN PostGain__FDK;
+- FIXP_GAIN pPreGain__FDK[SACENC_MAX_INPUT_CHANNELS];
+-};
+-
+-/* Constants *****************************************************************/
+-/*
+- preGainFactorTable:
+-
+- pre calculation: (float)pow(10.f,(((float) x)/20.f))/(float)(1<<GAINCF_SF), x
+- = -20 ... +20
+-*/
+-static const FIXP_DBL preGainFactorTable__FDK[41] = {
+- GAINCF(6.2500000931e-003), GAINCF(7.0126154460e-003),
+- GAINCF(7.8682834283e-003), GAINCF(8.8283596560e-003),
+- GAINCF(9.9055822939e-003), GAINCF(1.1114246212e-002),
+- GAINCF(1.2470389716e-002), GAINCF(1.3992006890e-002),
+- GAINCF(1.5699289739e-002), GAINCF(1.7614893615e-002),
+- GAINCF(1.9764235243e-002), GAINCF(2.2175837308e-002),
+- GAINCF(2.4881698191e-002), GAINCF(2.7917724103e-002),
+- GAINCF(3.1324200332e-002), GAINCF(3.5146333277e-002),
+- GAINCF(3.9434835315e-002), GAINCF(4.4246610254e-002),
+- GAINCF(4.9645513296e-002), GAINCF(5.5703181773e-002),
+- GAINCF(6.2500000000e-002), GAINCF(7.0126153529e-002),
+- GAINCF(7.8682839870e-002), GAINCF(8.8283598423e-002),
+- GAINCF(9.9055826664e-002), GAINCF(1.1114246398e-001),
+- GAINCF(1.2470389158e-001), GAINCF(1.3992007077e-001),
+- GAINCF(1.5699289739e-001), GAINCF(1.7614893615e-001),
+- GAINCF(1.9764235616e-001), GAINCF(2.2175836563e-001),
+- GAINCF(2.4881698191e-001), GAINCF(2.7917724848e-001),
+- GAINCF(3.1324201822e-001), GAINCF(3.5146331787e-001),
+- GAINCF(3.9434835315e-001), GAINCF(4.4246610999e-001),
+- GAINCF(4.9645513296e-001), GAINCF(5.5703181028e-001),
+- GAINCF(6.2500000000e-001)};
+-
+-static const FIXP_GAIN dmxGainTable__FDK[] = {
+- /* GAINCT2(1.0), */ GAINCT2(0.84089650f),
+- GAINCT2(0.70710706f),
+- GAINCT2(0.59460385f),
+- GAINCT2(0.50000000f),
+- GAINCT2(0.42044825f),
+- GAINCT2(0.35355341f),
+- GAINCT2(0.25000000f)};
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_staticGain_OpenConfig()
+-description: opens and sets ConfigStruct to Default Values
+-returns: noError on success, an apropriate error code else
+------------------------------------------------------------------------------*/
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_OpenConfig(
+- HANDLE_STATIC_GAIN_CONFIG *phStaticGainConfig) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == phStaticGainConfig) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* Allocate Instance */
+- FDK_ALLOCATE_MEMORY_1D(*phStaticGainConfig, 1, struct STATIC_GAIN_CONFIG);
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_staticGain_CloseConfig(phStaticGainConfig);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_InitDefaultConfig(
+- HANDLE_STATIC_GAIN_CONFIG hStaticGainConfig) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hStaticGainConfig) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* Necessary Input Variables */
+- hStaticGainConfig->encMode = SACENC_INVALID_MODE;
+-
+- /* Optional Configs Set to Default Values */
+- hStaticGainConfig->fixedGainDMX = MP4SPACEENC_DMX_GAIN_DEFAULT;
+- hStaticGainConfig->preGainFactorDb = 0;
+- }
+- return error;
+-}
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_staticGain_CloseConfig()
+-description: destructs Static Gain Config Structure
+-returns: noError on success, an apropriate error code else
+------------------------------------------------------------------------------*/
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_CloseConfig(
+- HANDLE_STATIC_GAIN_CONFIG *phStaticGainConfig) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((phStaticGainConfig == NULL) || (*phStaticGainConfig == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDKfree(*phStaticGainConfig);
+- *phStaticGainConfig = NULL;
+- }
+- return error;
+-}
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_staticGain_Open()
+-description: initializes Static Gains
+-returns: noError on success, an apropriate error code else
+------------------------------------------------------------------------------*/
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_Open(HANDLE_STATIC_GAIN *phStaticGain) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == phStaticGain) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- /* Allocate Instance */
+- FDK_ALLOCATE_MEMORY_1D(*phStaticGain, 1, struct STATIC_GAIN);
+- }
+- return error;
+-
+-bail:
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_Init(
+- HANDLE_STATIC_GAIN hStaticGain,
+- const HANDLE_STATIC_GAIN_CONFIG hStaticGainConfig, INT *const scale) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hStaticGain == NULL) || (hStaticGainConfig == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- hStaticGain->encMode = hStaticGainConfig->encMode;
+- hStaticGain->fixedGainDMX = hStaticGainConfig->fixedGainDMX;
+- hStaticGain->preGainFactorDb = hStaticGainConfig->preGainFactorDb;
+-
+- if ((hStaticGain->preGainFactorDb < -20) ||
+- (hStaticGain->preGainFactorDb > 20)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- FIXP_DBL fPreGainFactor__FDK;
+-
+- if (hStaticGain->preGainFactorDb == 0) {
+- fPreGainFactor__FDK = (FIXP_DBL)MAXVAL_DBL;
+- *scale = 0;
+- } else {
+- int s;
+- fPreGainFactor__FDK =
+- preGainFactorTable__FDK[hStaticGain->preGainFactorDb + 20];
+- s = fixMax(0, CntLeadingZeros(fPreGainFactor__FDK) - 1);
+- fPreGainFactor__FDK = fPreGainFactor__FDK << (s);
+- *scale = GAINCF_SF - s;
+- }
+-
+- if (hStaticGain->fixedGainDMX == 0)
+- hStaticGain->PostGain__FDK = MAXVAL_GAIN;
+- else
+- hStaticGain->PostGain__FDK =
+- dmxGainTable__FDK[hStaticGain->fixedGainDMX - 1];
+-
+- FDKmemclear(
+- hStaticGain->pPreGain__FDK,
+- sizeof(hStaticGain->pPreGain__FDK)); /* zero all input channels */
+-
+- /* Configure PreGain-Vector */
+- if (hStaticGain->encMode == SACENC_212) {
+- hStaticGain->pPreGain__FDK[0] =
+- FX_DBL2FX_GAIN(fPreGainFactor__FDK); /* L */
+- hStaticGain->pPreGain__FDK[1] =
+- FX_DBL2FX_GAIN(fPreGainFactor__FDK); /* R */
+- } else {
+- error = SACENC_INVALID_CONFIG;
+- }
+-
+- } /* valid handle */
+-
+-bail:
+-
+- return error;
+-}
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_staticGain_Close()
+-description: destructs Static Gains
+-returns: noError on success, an apropriate error code else
+------------------------------------------------------------------------------*/
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_Close(HANDLE_STATIC_GAIN *phStaticGain) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((phStaticGain == NULL) || (*phStaticGain == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- FDKfree(*phStaticGain);
+- *phStaticGain = NULL;
+- }
+- return error;
+-}
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_staticPostGain_Apply
+-description: multiply the Output samples with the PostGain
+-returns: noError on success, an apropriate error code else
+------------------------------------------------------------------------------*/
+-FDK_SACENC_ERROR fdk_sacenc_staticPostGain_ApplyFDK(
+- const HANDLE_STATIC_GAIN hStaticGain, INT_PCM *const pOutputSamples,
+- const INT nOutputSamples, const INT scale) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hStaticGain) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i;
+- FIXP_GAIN postGain = hStaticGain->PostGain__FDK;
+-
+- if (scale < 0) {
+- if (postGain == MAXVAL_GAIN) {
+- for (i = 0; i < nOutputSamples; i++) {
+- pOutputSamples[i] = pOutputSamples[i] >> (-scale);
+- }
+- } else {
+- for (i = 0; i < nOutputSamples; i++) {
+- pOutputSamples[i] = FX_DBL2FX_PCM(
+- fMult(postGain, FX_PCM2FX_DBL(pOutputSamples[i])) >> (-scale));
+- }
+- }
+- } else {
+- if (postGain == MAXVAL_GAIN) {
+- for (i = 0; i < nOutputSamples; i++) {
+- pOutputSamples[i] = FX_DBL2FX_PCM(SATURATE_LEFT_SHIFT(
+- FX_PCM2FX_DBL(pOutputSamples[i]), scale, DFRACT_BITS));
+- }
+- } else {
+- for (i = 0; i < nOutputSamples; i++) {
+- pOutputSamples[i] = FX_DBL2FX_PCM(SATURATE_LEFT_SHIFT(
+- fMult(postGain, FX_PCM2FX_DBL(pOutputSamples[i])), scale,
+- DFRACT_BITS));
+- }
+- }
+- }
+- }
+- return error;
+-}
+-
+-/*-----------------------------------------------------------------------------
+-functionname: fdk_sacenc_getPreGainPtr()/ fdk_sacenc_getPostGain()
+-description: get Gain-Pointers from struct
+-returns: Pointer to PreGain or postGain
+------------------------------------------------------------------------------*/
+-FIXP_GAIN *fdk_sacenc_getPreGainPtrFDK(HANDLE_STATIC_GAIN hStaticGain) {
+- return ((hStaticGain == NULL) ? NULL : hStaticGain->pPreGain__FDK);
+-}
+-
+-FIXP_GAIN fdk_sacenc_getPostGainFDK(HANDLE_STATIC_GAIN hStaticGain) {
+- return (hStaticGain->PostGain__FDK);
+-}
+-
+-/* get fixed downmix gain and map it to bitstream enum */
+-FIXEDGAINDMXCONFIG fdk_sacenc_staticGain_GetDmxGain(
+- const HANDLE_STATIC_GAIN hStaticGain) {
+- FIXEDGAINDMXCONFIG dmxGain = FIXEDGAINDMX_INVALID;
+-
+- switch (hStaticGain->fixedGainDMX) {
+- case 0:
+- dmxGain = FIXEDGAINDMX_0;
+- break;
+- case 1:
+- dmxGain = FIXEDGAINDMX_1;
+- break;
+- case 2:
+- dmxGain = FIXEDGAINDMX_2;
+- break;
+- case 3:
+- dmxGain = FIXEDGAINDMX_3;
+- break;
+- case 4:
+- dmxGain = FIXEDGAINDMX_4;
+- break;
+- case 5:
+- dmxGain = FIXEDGAINDMX_5;
+- break;
+- case 6:
+- dmxGain = FIXEDGAINDMX_6;
+- break;
+- case 7:
+- dmxGain = FIXEDGAINDMX_7;
+- break;
+- default:
+- dmxGain = FIXEDGAINDMX_INVALID;
+- }
+- return dmxGain;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_SetDmxGain(
+- HANDLE_STATIC_GAIN_CONFIG hStaticGainCfg,
+- const MP4SPACEENC_DMX_GAIN dmxGain) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hStaticGainCfg) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- hStaticGainCfg->fixedGainDMX = dmxGain;
+- }
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_SetEncMode(
+- HANDLE_STATIC_GAIN_CONFIG hStaticGainCfg, const MP4SPACEENC_MODE encMode) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if (NULL == hStaticGainCfg) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- hStaticGainCfg->encMode = encMode;
+- }
+- return error;
+-}
+diff --git a/libSACenc/src/sacenc_staticgain.h b/libSACenc/src/sacenc_staticgain.h
+deleted file mode 100644
+index 5db3bec..0000000
+--- a/libSACenc/src/sacenc_staticgain.h
++++ /dev/null
+@@ -1,177 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Christian Goettlinger
+-
+- Description: Encoder Library Interfac
+- gain management of the encoder
+-
+-*******************************************************************************/
+-
+-/**************************************************************************/ /**
+- \file
+- ******************************************************************************/
+-
+-#ifndef SACENC_STATICGAIN_H
+-#define SACENC_STATICGAIN_H
+-
+-/* Includes ******************************************************************/
+-#include "common_fix.h"
+-#include "sacenc_lib.h"
+-#include "sacenc_const.h"
+-#include "sacenc_bitstream.h"
+-
+-/* Defines *******************************************************************/
+-#define FIXP_GAIN FIXP_DBL
+-#define MAXVAL_GAIN ((FIXP_DBL)MAXVAL_DBL)
+-
+-/* Data Types ****************************************************************/
+-struct STATIC_GAIN_CONFIG {
+- MP4SPACEENC_MODE encMode;
+- MP4SPACEENC_DMX_GAIN fixedGainDMX;
+- INT preGainFactorDb;
+-};
+-
+-typedef struct STATIC_GAIN_CONFIG *HANDLE_STATIC_GAIN_CONFIG;
+-typedef struct STATIC_GAIN *HANDLE_STATIC_GAIN;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Initializes Static Gain Computation Config */
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_OpenConfig(
+- HANDLE_STATIC_GAIN_CONFIG *phStaticGainConfig);
+-
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_InitDefaultConfig(
+- HANDLE_STATIC_GAIN_CONFIG hStaticGainConfig);
+-
+-/* Deletes Static Gain Computation Config ~Destructor */
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_CloseConfig(
+- HANDLE_STATIC_GAIN_CONFIG *phStaticGainConfig);
+-
+-/* Initializes Static Gain Computation ~Constructor */
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_Open(HANDLE_STATIC_GAIN *phStaticGain);
+-
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_Init(
+- HANDLE_STATIC_GAIN hStaticGain,
+- const HANDLE_STATIC_GAIN_CONFIG hStaticGainConfig, INT *const scale);
+-
+-/* Deletes Static Gain Computation Infrastucture ~Destructor */
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_Close(HANDLE_STATIC_GAIN *phStaticGain);
+-
+-/* Apply PostGain to the output PCM Downmix-Signal */
+-FDK_SACENC_ERROR fdk_sacenc_staticPostGain_ApplyFDK(
+- const HANDLE_STATIC_GAIN hStaticGain, INT_PCM *const pOutputSamples,
+- const INT nOutputSamples, const INT scale);
+-
+-/* Get Pointer to PreGain-vector */
+-FIXP_GAIN *fdk_sacenc_getPreGainPtrFDK(HANDLE_STATIC_GAIN hStaticGain);
+-
+-/* Get Pointer to PostGain-coef */
+-FIXP_GAIN fdk_sacenc_getPostGainFDK(HANDLE_STATIC_GAIN hStaticGain);
+-
+-FIXEDGAINDMXCONFIG fdk_sacenc_staticGain_GetDmxGain(
+- const HANDLE_STATIC_GAIN hStaticGain);
+-
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_SetDmxGain(
+- HANDLE_STATIC_GAIN_CONFIG hStaticGainCfg,
+- const MP4SPACEENC_DMX_GAIN dmxGain);
+-
+-FDK_SACENC_ERROR fdk_sacenc_staticGain_SetEncMode(
+- HANDLE_STATIC_GAIN_CONFIG hStaticGainCfg, const MP4SPACEENC_MODE encMode);
+-
+-#endif /* SACENC_STATICGAIN_H */
+diff --git a/libSACenc/src/sacenc_tree.cpp b/libSACenc/src/sacenc_tree.cpp
+deleted file mode 100644
+index c7d3128..0000000
+--- a/libSACenc/src/sacenc_tree.cpp
++++ /dev/null
+@@ -1,488 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Max Neuendorf
+-
+- Description: Encoder Library Interface
+- Tree Structure for Space Encoder
+-
+-*******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_tree.h"
+-#include "genericStds.h"
+-#include "sacenc_const.h"
+-#include "sacenc_paramextract.h"
+-#include "sacenc_framewindowing.h"
+-#include "FDK_matrixCalloc.h"
+-
+-/* Defines *******************************************************************/
+-enum { BOX_0 = 0, BOX_1 = 1 };
+-
+-enum { CH_L = 0, CH_R = 1 };
+-
+-enum { TTO_CH_0 = 0, TTO_CH_1 = 1 };
+-
+-enum { WIN_INACTIV = 0, WIN_ACTIV = 1 };
+-
+-enum { MAX_KEEP_FRAMECOUNT = 100 };
+-
+-/* Data Types ****************************************************************/
+-struct SPACE_TREE {
+- SPACETREE_MODE mode;
+- SPACE_TREE_DESCRIPTION descr;
+- HANDLE_TTO_BOX ttoBox[SACENC_MAX_NUM_BOXES];
+- UCHAR nParamBands;
+- UCHAR bUseCoarseQuantTtoIcc;
+- UCHAR bUseCoarseQuantTtoCld;
+- QUANTMODE quantMode;
+- INT frameCount;
+- UCHAR bFrameKeep;
+-
+- /* Intermediate buffers */
+- UCHAR pCld_prev[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAM_BANDS];
+- UCHAR pIcc_prev[SACENC_MAX_NUM_BOXES][MAX_NUM_PARAM_BANDS];
+-
+- UCHAR nChannelsInMax;
+- UCHAR nHybridBandsMax;
+-};
+-
+-typedef struct {
+- UCHAR boxId;
+- UCHAR inCh1;
+- UCHAR inCh2;
+- UCHAR inCh3;
+- UCHAR inCh4;
+- UCHAR wCh1;
+- UCHAR wCh2;
+-
+-} TTO_DESCRIPTOR;
+-
+-typedef struct {
+- SPACETREE_MODE mode;
+- SPACE_TREE_DESCRIPTION treeDescription;
+-
+-} TREE_CONFIG;
+-
+-typedef struct {
+- SPACETREE_MODE mode;
+- UCHAR nChannelsIn;
+- UCHAR nChannelsOut;
+- UCHAR nTtoBoxes;
+- TTO_DESCRIPTOR tto_descriptor[1];
+-
+-} TREE_SETUP;
+-
+-/* Constants *****************************************************************/
+-static const TREE_CONFIG treeConfigTable[] = {
+- {SPACETREE_INVALID_MODE, {0, 0, 0}}, {SPACETREE_212, {1, 1, 2}}};
+-
+-static const TREE_SETUP treeSetupTable[] = {
+- {SPACETREE_INVALID_MODE, 0, 0, 0, {{0, 0, 0, 0, 0, 0, 0}}},
+- {SPACETREE_212,
+- 2,
+- 1,
+- 1,
+- {{BOX_0, CH_L, CH_R, TTO_CH_0, TTO_CH_1, WIN_ACTIV, WIN_ACTIV}}}};
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-static FDK_SACENC_ERROR getTreeConfig(
+- const SPACETREE_MODE mode, SPACE_TREE_DESCRIPTION *pTreeDescription) {
+- FDK_SACENC_ERROR error = SACENC_INIT_ERROR;
+-
+- if (pTreeDescription == NULL) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int i;
+- for (i = 0; i < (int)(sizeof(treeConfigTable) / sizeof(TREE_CONFIG)); i++) {
+- if (treeConfigTable[i].mode == mode) {
+- *pTreeDescription = treeConfigTable[i].treeDescription;
+- error = SACENC_OK;
+- break;
+- }
+- }
+- } /* valid handle */
+- return error;
+-}
+-
+-static const TREE_SETUP *getTreeSetup(const SPACETREE_MODE mode) {
+- int i;
+- const TREE_SETUP *setup = NULL;
+-
+- for (i = 0; i < (int)(sizeof(treeSetupTable) / sizeof(TREE_SETUP)); i++) {
+- if (treeSetupTable[i].mode == mode) {
+- setup = &treeSetupTable[i];
+- break;
+- }
+- }
+- return setup;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_Open(HANDLE_SPACE_TREE *phSpaceTree) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+- HANDLE_SPACE_TREE hSpaceTree = NULL;
+-
+- if (NULL == phSpaceTree) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int box;
+-
+- FDK_ALLOCATE_MEMORY_1D(hSpaceTree, 1, struct SPACE_TREE);
+-
+- for (box = 0; box < SACENC_MAX_NUM_BOXES; box++) {
+- HANDLE_TTO_BOX ttoBox = NULL;
+- if (SACENC_OK != (error = fdk_sacenc_createTtoBox(&ttoBox))) {
+- goto bail;
+- }
+- if (NULL != hSpaceTree) {
+- hSpaceTree->ttoBox[box] = ttoBox;
+- }
+- }
+- *phSpaceTree = hSpaceTree;
+- }
+- return error;
+-
+-bail:
+- fdk_sacenc_spaceTree_Close(&hSpaceTree);
+- return ((SACENC_OK == error) ? SACENC_MEMORY_ERROR : error);
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_Init(
+- HANDLE_SPACE_TREE hST, const SPACE_TREE_SETUP *const hSetup,
+- UCHAR *pParameterBand2HybridBandOffset, const INT bFrameKeep) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hST == NULL) || (hSetup == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int bTtoBoxFrontBackCombin[SACENC_MAX_NUM_BOXES] = {0};
+- int box = 0;
+-
+- hST->frameCount = 0;
+- hST->bFrameKeep = bFrameKeep;
+-
+- /* Init */
+- hST->mode = hSetup->mode;
+- hST->nParamBands = hSetup->nParamBands;
+- hST->bUseCoarseQuantTtoIcc = hSetup->bUseCoarseQuantTtoIcc;
+- hST->bUseCoarseQuantTtoCld = hSetup->bUseCoarseQuantTtoCld;
+- hST->quantMode = hSetup->quantMode;
+- hST->nChannelsInMax = hSetup->nChannelsInMax;
+- hST->nHybridBandsMax = hSetup->nHybridBandsMax;
+-
+- if (SACENC_OK != (error = getTreeConfig(hST->mode, &hST->descr))) {
+- goto bail;
+- }
+-
+- switch (hST->mode) {
+- case SPACETREE_212:
+- bTtoBoxFrontBackCombin[BOX_0] = 0;
+- break;
+- case SPACETREE_INVALID_MODE:
+- default:
+- error = SACENC_INIT_ERROR;
+- goto bail;
+- } /* switch (hST->mode) */
+-
+- if (hST->descr.nOttBoxes > SACENC_MAX_NUM_BOXES) {
+- error = SACENC_INIT_ERROR;
+- goto bail;
+- }
+-
+- for (box = 0; box < hST->descr.nOttBoxes; box++) {
+- TTO_BOX_CONFIG boxConfig;
+- boxConfig.subbandConfig = (BOX_SUBBAND_CONFIG)hST->nParamBands;
+- boxConfig.bUseCoarseQuantCld = hST->bUseCoarseQuantTtoCld;
+- boxConfig.bUseCoarseQuantIcc = hST->bUseCoarseQuantTtoIcc;
+- boxConfig.bUseCoherenceIccOnly = bTtoBoxFrontBackCombin[box];
+- boxConfig.boxQuantMode = (BOX_QUANTMODE)hST->quantMode;
+- boxConfig.nHybridBandsMax = hST->nHybridBandsMax;
+- boxConfig.bFrameKeep = hST->bFrameKeep;
+-
+- if (SACENC_OK !=
+- (error = fdk_sacenc_initTtoBox(hST->ttoBox[box], &boxConfig,
+- pParameterBand2HybridBandOffset))) {
+- goto bail;
+- }
+- } /* for box */
+-
+- } /* valid handle */
+-
+-bail:
+- return error;
+-}
+-
+-static void SpaceTree_FrameKeep212(const HANDLE_SPACE_TREE hST,
+- SPATIALFRAME *const hSTOut,
+- const INT avoid_keep) {
+- int pb;
+-
+- if (avoid_keep == 0) {
+- if (hST->frameCount % 2 == 0) {
+- for (pb = 0; pb < hST->nParamBands; pb++) {
+- hST->pIcc_prev[BOX_0][pb] = hSTOut->ottData.icc[BOX_0][0][pb];
+- hSTOut->ottData.cld[BOX_0][0][pb] = hST->pCld_prev[BOX_0][pb];
+- }
+- } else {
+- for (pb = 0; pb < hST->nParamBands; pb++) {
+- hSTOut->ottData.icc[BOX_0][0][pb] = hST->pIcc_prev[BOX_0][pb];
+- hST->pCld_prev[BOX_0][pb] = hSTOut->ottData.cld[BOX_0][0][pb];
+- }
+- }
+- } else {
+- for (pb = 0; pb < hST->nParamBands; pb++) {
+- hST->pIcc_prev[BOX_0][pb] = hSTOut->ottData.icc[BOX_0][0][pb];
+- hST->pCld_prev[BOX_0][pb] = hSTOut->ottData.cld[BOX_0][0][pb];
+- }
+- }
+- hST->frameCount++;
+- if (hST->frameCount == MAX_KEEP_FRAMECOUNT) {
+- hST->frameCount = 0;
+- }
+-}
+-
+-static FDK_SACENC_ERROR SpaceTree_FrameKeep(const HANDLE_SPACE_TREE hST,
+- SPATIALFRAME *const hSTOut,
+- const INT avoid_keep) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- switch (hST->mode) {
+- case SPACETREE_212:
+- SpaceTree_FrameKeep212(hST, hSTOut, avoid_keep);
+- break;
+- case SPACETREE_INVALID_MODE:
+- default:
+- error = SACENC_INVALID_CONFIG;
+- break;
+- }
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_Apply(
+- HANDLE_SPACE_TREE hST, const INT paramSet, const INT nChannelsIn,
+- const INT nTimeSlots, const INT startTimeSlot, const INT nHybridBands,
+- FIXP_WIN *pFrameWindowAna__FDK,
+- FIXP_DPK *const *const *const pppHybrid__FDK,
+- FIXP_DPK *const *const *const pppHybridIn__FDK, SPATIALFRAME *const hSTOut,
+- const INT avoid_keep, INT *pEncoderInputChScale) {
+- /** \verbatim
+- =============================================================================================================================
+- TREE_212
+- =============================================================================================================================
+- _______
+- L -- TTO_CH_0 --| |
+- | TTO_0 |-- TTO_CH_0
+- R -- TTO_CH_1 --|_______|
+-
+- \endverbatim */
+-
+- FDK_SACENC_ERROR error = SACENC_OK;
+- int k;
+- const TREE_SETUP *treeSetup = NULL;
+-
+- if ((hST == NULL) || (hSTOut == NULL) || (pppHybrid__FDK == NULL) ||
+- (pppHybridIn__FDK == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- goto bail;
+- }
+-
+- if ((treeSetup = getTreeSetup(hST->mode)) == NULL) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- /* Sanity Checks */
+- if ((nChannelsIn != treeSetup->nChannelsIn) ||
+- (nChannelsIn > hST->nChannelsInMax) ||
+- (nHybridBands > hST->nHybridBandsMax)) {
+- error = SACENC_INVALID_CONFIG;
+- goto bail;
+- }
+-
+- /* Apply all TTO boxes. */
+- for (k = 0; k < treeSetup->nTtoBoxes; k++) {
+- const TTO_DESCRIPTOR *pTTO = &treeSetup->tto_descriptor[k];
+-
+- int i, inCh[2], outCh[2], win[2];
+-
+- inCh[0] = pTTO->inCh1;
+- outCh[0] = pTTO->inCh3;
+- win[0] = pTTO->wCh1;
+- inCh[1] = pTTO->inCh2;
+- outCh[1] = pTTO->inCh4;
+- win[1] = pTTO->wCh2;
+-
+- for (i = 0; i < 2; i++) {
+- if (win[i] == WIN_ACTIV) {
+- fdk_sacenc_analysisWindowing(
+- nTimeSlots, startTimeSlot, pFrameWindowAna__FDK,
+- pppHybrid__FDK[inCh[i]], pppHybridIn__FDK[outCh[i]], nHybridBands,
+- FW_LEAVE_DIM);
+- }
+- }
+-
+- /* Calculate output downmix within last TTO box, if no TTT box is applied.
+- */
+- if (SACENC_OK !=
+- (error = fdk_sacenc_applyTtoBox(
+- hST->ttoBox[pTTO->boxId], nTimeSlots, startTimeSlot, nHybridBands,
+- pppHybridIn__FDK[pTTO->inCh3], pppHybridIn__FDK[pTTO->inCh4],
+- hSTOut->ottData.icc[pTTO->boxId][paramSet],
+- &(hSTOut->ICCLosslessData.bsQuantCoarseXXX[pTTO->boxId][paramSet]),
+- hSTOut->ottData.cld[pTTO->boxId][paramSet],
+- &(hSTOut->CLDLosslessData.bsQuantCoarseXXX[pTTO->boxId][paramSet]),
+- hSTOut->bUseBBCues, &pEncoderInputChScale[inCh[0]],
+- &pEncoderInputChScale[inCh[1]]))) {
+- goto bail;
+- }
+- }
+-
+- if (hST->bFrameKeep == 1) {
+- if (SACENC_OK != (error = SpaceTree_FrameKeep(hST, hSTOut, avoid_keep))) {
+- goto bail;
+- }
+- }
+-
+-bail:
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_Close(HANDLE_SPACE_TREE *phSpaceTree) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((phSpaceTree == NULL) || (*phSpaceTree == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- int box;
+- HANDLE_SPACE_TREE const hST = *phSpaceTree;
+-
+- /* for (box = 0; box < hST->descr.nOttBoxes; ++box) { */
+- for (box = 0; box < SACENC_MAX_NUM_BOXES; ++box) {
+- if (SACENC_OK != (error = fdk_sacenc_destroyTtoBox(&hST->ttoBox[box]))) {
+- goto bail;
+- }
+- }
+-
+- FDKfree(*phSpaceTree);
+- *phSpaceTree = NULL;
+- }
+-bail:
+- return error;
+-}
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_GetDescription(
+- const HANDLE_SPACE_TREE hSpaceTree,
+- SPACE_TREE_DESCRIPTION *pSpaceTreeDescription) {
+- FDK_SACENC_ERROR error = SACENC_OK;
+-
+- if ((hSpaceTree == NULL) || (pSpaceTreeDescription == NULL)) {
+- error = SACENC_INVALID_HANDLE;
+- } else {
+- *pSpaceTreeDescription = hSpaceTree->descr;
+- }
+- return error;
+-}
+-
+-INT fdk_sacenc_spaceTree_Hybrid2ParamBand(const INT nParamBands,
+- const INT nHybridBand) {
+- return fdk_sacenc_subband2ParamBand((BOX_SUBBAND_CONFIG)nParamBands,
+- nHybridBand);
+-}
+-
+-/*****************************************************************************
+-******************************************************************************/
+diff --git a/libSACenc/src/sacenc_tree.h b/libSACenc/src/sacenc_tree.h
+deleted file mode 100644
+index 09f5b2b..0000000
+--- a/libSACenc/src/sacenc_tree.h
++++ /dev/null
+@@ -1,168 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Max Neuendorf
+-
+- Description: Encoder Library Interface
+- Tree Structure for Space Encoder
+-
+-*******************************************************************************/
+-
+-#ifndef SACENC_TREE_H
+-#define SACENC_TREE_H
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_framewindowing.h"
+-#include "sacenc_lib.h"
+-#include "sacenc_bitstream.h"
+-
+-/* Defines *******************************************************************/
+-
+-/* Data Types ****************************************************************/
+-typedef enum {
+- SPACETREE_INVALID_MODE = 0,
+- SPACETREE_212 = 8
+-
+-} SPACETREE_MODE;
+-
+-typedef struct SPACE_TREE *HANDLE_SPACE_TREE;
+-
+-typedef struct {
+- UCHAR nParamBands;
+- UCHAR bUseCoarseQuantTtoCld;
+- UCHAR bUseCoarseQuantTtoIcc;
+- QUANTMODE quantMode;
+- SPACETREE_MODE mode;
+-
+- UCHAR nChannelsInMax;
+- UCHAR nHybridBandsMax;
+-
+-} SPACE_TREE_SETUP;
+-
+-typedef struct {
+- UCHAR nOttBoxes;
+- UCHAR nInChannels;
+- UCHAR nOutChannels;
+-
+-} SPACE_TREE_DESCRIPTION;
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_Open(HANDLE_SPACE_TREE *phSpaceTree);
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_Init(
+- HANDLE_SPACE_TREE hST, const SPACE_TREE_SETUP *const hSetup,
+- UCHAR *pParameterBand2HybridBandOffset, const INT bFrameKeep);
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_Apply(
+- HANDLE_SPACE_TREE hST, const INT paramSet, const INT nChannelsIn,
+- const INT nTimeSlots, const INT startTimeSlot, const INT nHybridBands,
+- FIXP_WIN *pFrameWindowAna__FDK,
+- FIXP_DPK *const *const *const pppHybrid__FDK,
+- FIXP_DPK *const *const *const pppHybridIn__FDK, SPATIALFRAME *const hSTOut,
+- const INT avoid_keep, INT *pEncoderInputChScale);
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_Close(HANDLE_SPACE_TREE *phSpaceTree);
+-
+-FDK_SACENC_ERROR fdk_sacenc_spaceTree_GetDescription(
+- const HANDLE_SPACE_TREE hSpaceTree,
+- SPACE_TREE_DESCRIPTION *pSpaceTreeDescription);
+-
+-INT fdk_sacenc_spaceTree_Hybrid2ParamBand(const INT nParamBands,
+- const INT nHybridBand);
+-
+-#endif /* SACENC_TREE_H */
+diff --git a/libSACenc/src/sacenc_vectorfunctions.cpp b/libSACenc/src/sacenc_vectorfunctions.cpp
+deleted file mode 100644
+index c1e24b7..0000000
+--- a/libSACenc/src/sacenc_vectorfunctions.cpp
++++ /dev/null
+@@ -1,450 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Josef Hoepfl
+-
+- Description: Encoder Library Interface
+- vector functions
+-
+-*******************************************************************************/
+-
+-/*****************************************************************************
+-\file
+-This file contains vector functions
+-******************************************************************************/
+-
+-/* Includes ******************************************************************/
+-#include "sacenc_vectorfunctions.h"
+-
+-/* Defines *******************************************************************/
+-
+-/* Data Types ****************************************************************/
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/* Function / Class Definition ***********************************************/
+-
+-FIXP_DBL sumUpCplxPow2(const FIXP_DPK *const x, const INT scaleMode,
+- const INT inScaleFactor, INT *const outScaleFactor,
+- const INT n) {
+- int i, cs;
+-
+- if (scaleMode == SUM_UP_DYNAMIC_SCALE) {
+- /* calculate headroom */
+- FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f);
+- for (i = 0; i < n; i++) {
+- maxVal |= fAbs(x[i].v.re);
+- maxVal |= fAbs(x[i].v.im);
+- }
+- cs = inScaleFactor - fixMax(0, CntLeadingZeros(maxVal) - 1);
+- } else {
+- cs = inScaleFactor;
+- }
+-
+- /* consider scaling of energy and scaling in fPow2Div2 and addition */
+- *outScaleFactor = 2 * cs + 2;
+-
+- /* make sure that the scalefactor is in the range of -(DFRACT_BITS-1), ... ,
+- * (DFRACT_BITS-1) */
+- cs = fixMax(fixMin(cs, DFRACT_BITS - 1), -(DFRACT_BITS - 1));
+-
+- /* sum up complex energy samples */
+- FIXP_DBL re, im, sum;
+-
+- re = im = sum = FL2FXCONST_DBL(0.0);
+- if (cs < 0) {
+- cs = -cs;
+- for (i = 0; i < n; i++) {
+- re += fPow2Div2(x[i].v.re << cs);
+- im += fPow2Div2(x[i].v.im << cs);
+- }
+- } else {
+- cs = 2 * cs;
+- for (i = 0; i < n; i++) {
+- re += fPow2Div2(x[i].v.re) >> cs;
+- im += fPow2Div2(x[i].v.im) >> cs;
+- }
+- }
+-
+- sum = (re >> 1) + (im >> 1);
+-
+- return (sum);
+-}
+-
+-FIXP_DBL sumUpCplxPow2Dim2(const FIXP_DPK *const *const x, const INT scaleMode,
+- const INT inScaleFactor, INT *const outScaleFactor,
+- const INT sDim1, const INT nDim1, const INT sDim2,
+- const INT nDim2) {
+- int i, j, cs;
+-
+- if (scaleMode == SUM_UP_DYNAMIC_SCALE) {
+- /* calculate headroom */
+- FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f);
+- for (i = sDim1; i < nDim1; i++) {
+- for (j = sDim2; j < nDim2; j++) {
+- maxVal |= fAbs(x[i][j].v.re);
+- maxVal |= fAbs(x[i][j].v.im);
+- }
+- }
+- cs = inScaleFactor - fixMax(0, CntLeadingZeros(maxVal) - 1);
+- } else {
+- cs = inScaleFactor;
+- }
+-
+- /* consider scaling of energy and scaling in fPow2Div2 and addition */
+- *outScaleFactor = 2 * cs + 2;
+-
+- /* make sure that the scalefactor is in the range of -(DFRACT_BITS-1), ... ,
+- * (DFRACT_BITS-1) */
+- cs = fixMax(fixMin(cs, DFRACT_BITS - 1), -(DFRACT_BITS - 1));
+-
+- /* sum up complex energy samples */
+- FIXP_DBL re, im, sum;
+-
+- re = im = sum = FL2FXCONST_DBL(0.0);
+- if (cs < 0) {
+- cs = -cs;
+- for (i = sDim1; i < nDim1; i++) {
+- for (j = sDim2; j < nDim2; j++) {
+- re += fPow2Div2(x[i][j].v.re << cs);
+- im += fPow2Div2(x[i][j].v.im << cs);
+- }
+- }
+- } else {
+- cs = 2 * cs;
+- for (i = sDim1; i < nDim1; i++) {
+- for (j = sDim2; j < nDim2; j++) {
+- re += fPow2Div2(x[i][j].v.re) >> cs;
+- im += fPow2Div2(x[i][j].v.im) >> cs;
+- }
+- }
+- }
+-
+- sum = (re >> 1) + (im >> 1);
+-
+- return (sum);
+-}
+-
+-void copyCplxVec(FIXP_DPK *const Z, const FIXP_DPK *const X, const INT n) {
+- FDKmemmove(Z, X, sizeof(FIXP_DPK) * n);
+-}
+-
+-void setCplxVec(FIXP_DPK *const Z, const FIXP_DBL a, const INT n) {
+- int i;
+-
+- for (i = 0; i < n; i++) {
+- Z[i].v.re = a;
+- Z[i].v.im = a;
+- }
+-}
+-
+-void cplx_cplxScalarProduct(FIXP_DPK *const Z, const FIXP_DPK *const *const X,
+- const FIXP_DPK *const *const Y, const INT scaleX,
+- const INT scaleY, INT *const scaleZ,
+- const INT sDim1, const INT nDim1, const INT sDim2,
+- const INT nDim2) {
+- int i, j, sx, sy;
+- FIXP_DBL xre, yre, xim, yim, re, im;
+-
+- /* make sure that the scalefactor is in the range of -(DFRACT_BITS-1), ... ,
+- * (DFRACT_BITS-1) */
+- sx = fixMax(fixMin(scaleX, DFRACT_BITS - 1), -(DFRACT_BITS - 1));
+- sy = fixMax(fixMin(scaleY, DFRACT_BITS - 1), -(DFRACT_BITS - 1));
+-
+- /* consider scaling of energy and scaling in fMultDiv2 and shift of result
+- * values */
+- *scaleZ = sx + sy + 2;
+-
+- re = (FIXP_DBL)0;
+- im = (FIXP_DBL)0;
+- if ((sx < 0) && (sy < 0)) {
+- sx = -sx;
+- sy = -sy;
+- for (i = sDim1; i < nDim1; i++) {
+- for (j = sDim2; j < nDim2; j++) {
+- xre = X[i][j].v.re << sx;
+- xim = X[i][j].v.im << sx;
+- yre = Y[i][j].v.re << sy;
+- yim = Y[i][j].v.im << sy;
+- re += fMultDiv2(xre, yre) + fMultDiv2(xim, yim);
+- im += fMultDiv2(xim, yre) - fMultDiv2(xre, yim);
+- }
+- }
+- } else if ((sx >= 0) && (sy >= 0)) {
+- for (i = sDim1; i < nDim1; i++) {
+- for (j = sDim2; j < nDim2; j++) {
+- xre = X[i][j].v.re;
+- xim = X[i][j].v.im;
+- yre = Y[i][j].v.re;
+- yim = Y[i][j].v.im;
+- re += (fMultDiv2(xre, yre) + fMultDiv2(xim, yim)) >> (sx + sy);
+- im += (fMultDiv2(xim, yre) - fMultDiv2(xre, yim)) >> (sx + sy);
+- }
+- }
+- } else if ((sx < 0) && (sy >= 0)) {
+- sx = -sx;
+- for (i = sDim1; i < nDim1; i++) {
+- for (j = sDim2; j < nDim2; j++) {
+- xre = X[i][j].v.re << sx;
+- xim = X[i][j].v.im << sx;
+- yre = Y[i][j].v.re;
+- yim = Y[i][j].v.im;
+- re += (fMultDiv2(xre, yre) + fMultDiv2(xim, yim)) >> sy;
+- im += (fMultDiv2(xim, yre) - fMultDiv2(xre, yim)) >> sy;
+- }
+- }
+- } else {
+- sy = -sy;
+- for (i = sDim1; i < nDim1; i++) {
+- for (j = sDim2; j < nDim2; j++) {
+- xre = X[i][j].v.re;
+- xim = X[i][j].v.im;
+- yre = Y[i][j].v.re << sy;
+- yim = Y[i][j].v.im << sy;
+- re += (fMultDiv2(xre, yre) + fMultDiv2(xim, yim)) >> sx;
+- im += (fMultDiv2(xim, yre) - fMultDiv2(xre, yim)) >> sx;
+- }
+- }
+- }
+-
+- Z->v.re = re >> 1;
+- Z->v.im = im >> 1;
+-}
+-
+-void FDKcalcCorrelationVec(FIXP_DBL *const z, const FIXP_DBL *const pr12,
+- const FIXP_DBL *const p1, const FIXP_DBL *const p2,
+- const INT n) {
+- int i, s;
+- FIXP_DBL p12, cor;
+-
+- /* correlation */
+- for (i = 0; i < n; i++) {
+- p12 = fMult(p1[i], p2[i]);
+- if (p12 > FL2FXCONST_DBL(0.0f)) {
+- p12 = invSqrtNorm2(p12, &s);
+- cor = fMult(pr12[i], p12);
+- z[i] = SATURATE_LEFT_SHIFT(cor, s, DFRACT_BITS);
+- } else {
+- z[i] = (FIXP_DBL)MAXVAL_DBL;
+- }
+- }
+-}
+-
+-void calcCoherenceVec(FIXP_DBL *const z, const FIXP_DBL *const p12r,
+- const FIXP_DBL *const p12i, const FIXP_DBL *const p1,
+- const FIXP_DBL *const p2, const INT scaleP12,
+- const INT scaleP, const INT n) {
+- int i, s, s1, s2;
+- FIXP_DBL coh, p12, p12ri;
+-
+- for (i = 0; i < n; i++) {
+- s2 = fixMin(fixMax(0, CountLeadingBits(p12r[i]) - 1),
+- fixMax(0, CountLeadingBits(p12i[i]) - 1));
+- p12ri = sqrtFixp(fPow2Div2(p12r[i] << s2) + fPow2Div2(p12i[i] << s2));
+- s1 = fixMin(fixMax(0, CountLeadingBits(p1[i]) - 1),
+- fixMax(0, CountLeadingBits(p2[i]) - 1));
+- p12 = fMultDiv2(p1[i] << s1, p2[i] << s1);
+-
+- if (p12 > FL2FXCONST_DBL(0.0f)) {
+- p12 = invSqrtNorm2(p12, &s);
+- coh = fMult(p12ri, p12);
+- s = fixMax(fixMin((scaleP12 - scaleP + s + s1 - s2), DFRACT_BITS - 1),
+- -(DFRACT_BITS - 1));
+- if (s < 0) {
+- z[i] = coh >> (-s);
+- } else {
+- z[i] = SATURATE_LEFT_SHIFT(coh, s, DFRACT_BITS);
+- }
+- } else {
+- z[i] = (FIXP_DBL)MAXVAL_DBL;
+- }
+- }
+-}
+-
+-void addWeightedCplxVec(FIXP_DPK *const *const Z, const FIXP_DBL *const a,
+- const FIXP_DPK *const *const X, const FIXP_DBL *const b,
+- const FIXP_DPK *const *const Y, const INT scale,
+- INT *const scaleCh1, const INT scaleCh2,
+- const UCHAR *const pParameterBand2HybridBandOffset,
+- const INT nParameterBands, const INT nTimeSlots,
+- const INT startTimeSlot) {
+- int pb, j, i;
+- int cs, s1, s2;
+-
+- /* determine maximum scale of both channels */
+- cs = fixMax(*scaleCh1, scaleCh2);
+- s1 = cs - (*scaleCh1);
+- s2 = cs - scaleCh2;
+-
+- /* scalefactor 1 is updated with common scale of channel 1 and channel2 */
+- *scaleCh1 = cs;
+-
+- /* scale of a and b; additional scale for fMultDiv2() */
+- for (j = 0, pb = 0; pb < nParameterBands; pb++) {
+- FIXP_DBL aPb, bPb;
+- aPb = a[pb], bPb = b[pb];
+- for (; j < pParameterBand2HybridBandOffset[pb]; j++) {
+- for (i = startTimeSlot; i < nTimeSlots; i++) {
+- Z[j][i].v.re = ((fMultDiv2(aPb, X[j][i].v.re) >> s1) +
+- (fMultDiv2(bPb, Y[j][i].v.re) >> s2))
+- << (scale + 1);
+- Z[j][i].v.im = ((fMultDiv2(aPb, X[j][i].v.im) >> s1) +
+- (fMultDiv2(bPb, Y[j][i].v.im) >> s2))
+- << (scale + 1);
+- }
+- }
+- }
+-}
+-
+-void FDKcalcPbScaleFactor(const FIXP_DPK *const *const x,
+- const UCHAR *const pParameterBand2HybridBandOffset,
+- INT *const outScaleFactor, const INT startTimeSlot,
+- const INT nTimeSlots, const INT nParamBands) {
+- int i, j, pb;
+-
+- /* calculate headroom */
+- for (j = 0, pb = 0; pb < nParamBands; pb++) {
+- FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f);
+- for (; j < pParameterBand2HybridBandOffset[pb]; j++) {
+- for (i = startTimeSlot; i < nTimeSlots; i++) {
+- maxVal |= fAbs(x[i][j].v.re);
+- maxVal |= fAbs(x[i][j].v.im);
+- }
+- }
+- outScaleFactor[pb] = -fixMax(0, CntLeadingZeros(maxVal) - 1);
+- }
+-}
+-
+-INT FDKcalcScaleFactor(const FIXP_DBL *const x, const FIXP_DBL *const y,
+- const INT n) {
+- int i;
+-
+- /* calculate headroom */
+- FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f);
+- if (x != NULL) {
+- for (i = 0; i < n; i++) {
+- maxVal |= fAbs(x[i]);
+- }
+- }
+-
+- if (y != NULL) {
+- for (i = 0; i < n; i++) {
+- maxVal |= fAbs(y[i]);
+- }
+- }
+-
+- if (maxVal == (FIXP_DBL)0)
+- return (-(DFRACT_BITS - 1));
+- else
+- return (-CountLeadingBits(maxVal));
+-}
+-
+-INT FDKcalcScaleFactorDPK(const FIXP_DPK *RESTRICT x, const INT startBand,
+- const INT bands) {
+- INT qs, clz;
+- FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f);
+-
+- for (qs = startBand; qs < bands; qs++) {
+- maxVal |= fAbs(x[qs].v.re);
+- maxVal |= fAbs(x[qs].v.im);
+- }
+-
+- clz = -fixMax(0, CntLeadingZeros(maxVal) - 1);
+-
+- return (clz);
+-}
+diff --git a/libSACenc/src/sacenc_vectorfunctions.h b/libSACenc/src/sacenc_vectorfunctions.h
+deleted file mode 100644
+index e9c4abd..0000000
+--- a/libSACenc/src/sacenc_vectorfunctions.h
++++ /dev/null
+@@ -1,488 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/*********************** MPEG surround encoder library *************************
+-
+- Author(s): Josef Hoepfl
+-
+- Description: Encoder Library Interface
+- vector functions
+-
+-*******************************************************************************/
+-
+-/*****************************************************************************
+-\file
+-This file contains vector functions
+-******************************************************************************/
+-
+-#ifndef SACENC_VECTORFUNCTIONS_H
+-#define SACENC_VECTORFUNCTIONS_H
+-
+-/* Includes ******************************************************************/
+-#include "common_fix.h"
+-
+-/* Defines *******************************************************************/
+-#define SUM_UP_STATIC_SCALE 0
+-#define SUM_UP_DYNAMIC_SCALE 1
+-
+-/* Data Types ****************************************************************/
+-
+-/* Constants *****************************************************************/
+-
+-/* Function / Class Declarations *********************************************/
+-
+-/**
+- * \brief Vector function : Sum up complex power
+- *
+- * Description : ret = sum( re{X[i]} * re{X[i]} + im{X[i]} *
+- * im{X[i]} ), i=0,...,n-1 ret is scaled by outScaleFactor
+- *
+- * \param const FIXP_DPK x[]
+- * Input: complex vector of the length n
+- *
+- * \param int scaleMode
+- * Input: choose static or dynamic scaling
+- * (SUM_UP_DYNAMIC_SCALE/SUM_UP_STATIC_SCALE)
+- *
+- * \param int inScaleFactor
+- * Input: determine headroom bits for the complex input vector
+- *
+- * \param int outScaleFactor
+- * Output: complete scaling in energy calculation
+- *
+- * \return FIXP_DBL ret
+- */
+-FIXP_DBL sumUpCplxPow2(const FIXP_DPK *const x, const INT scaleMode,
+- const INT inScaleFactor, INT *const outScaleFactor,
+- const INT n);
+-
+-/**
+- * \brief Vector function : Sum up complex power
+- *
+- * Description : ret = sum( re{X[i][j]} * re{X[i][]} +
+- * im{X[i][]} * im{X[i][]} ), i=sDim1,...,nDim1-1 i=sDim2,...,nDim2-1 ret is
+- * scaled by outScaleFactor
+- *
+- * \param const FIXP_DPK x[]
+- * Input: complex vector of the length n
+- *
+- * \param int scaleMode
+- * Input: choose static or dynamic scaling
+- * (SUM_UP_DYNAMIC_SCALE/SUM_UP_STATIC_SCALE)
+- *
+- * \param int inScaleFactor
+- * Input: determine headroom bits for the complex input vector
+- *
+- * \param int outScaleFactor
+- * Output: complete scaling in energy calculation
+- *
+- * \param int sDim1
+- * Input: start index for loop counter in dimension 1
+- *
+- * \param int nDim1
+- * Input: loop counter in dimension 1
+- *
+- * \param int sDim2
+- * Input: start index for loop counter in dimension 2
+- *
+- * \param int nDim2
+- * Input: loop counter in dimension 2
+- *
+- * \return FIXP_DBL ret
+- */
+-FIXP_DBL sumUpCplxPow2Dim2(const FIXP_DPK *const *const x, const INT scaleMode,
+- const INT inScaleFactor, INT *const outScaleFactor,
+- const INT sDim1, const INT nDim1, const INT sDim2,
+- const INT nDim2);
+-
+-/**
+- * \brief Vector function : Z[i] = X[i], i=0,...,n-1
+- *
+- * Description : re{Z[i]} = re{X[i]}, i=0,...,n-1
+- * im{Z[i]} = im{X[i]}, i=0,...,n-1
+- *
+- * Copy complex vector X[] to complex vector Z[].
+- * It is allowed to overlay X[] with Z[].
+- *
+- * \param FIXP_DPK Z[]
+- * Output: vector of the length n
+- *
+- * \param const FIXP_DPK X[]
+- * Input: vector of the length n
+- *
+- * \param int n
+- * Input: length of vector Z[] and X[]
+- *
+- * \return void
+- */
+-void copyCplxVec(FIXP_DPK *const Z, const FIXP_DPK *const X, const INT n);
+-
+-/**
+- * \brief Vector function : Z[i] = a, i=0,...,n-1
+- *
+- * Description : re{Z[i]} = a, i=0,...,n-1
+- * im{Z[i]} = a, i=0,...,n-1
+- *
+- * Set real and imaginary part of the complex value Z to a.
+- *
+- * \param FIPX_DPK Z[]
+- * Output: vector of the length n
+- *
+- * \param const FIXP_DBL a
+- * Input: constant value
+- *
+- * \param int n
+- * Input: length of vector Z[]
+- *
+- * \return void
+- */
+-void setCplxVec(FIXP_DPK *const Z, const FIXP_DBL a, const INT n);
+-
+-/**
+- * \brief Vector function : Calculate complex-valued result of complex
+- * scalar product
+- *
+- * Description : re{Z} = sum( re{X[i]} * re{Y[i]} + im{X[i]} *
+- * im{Y[i]}, i=0,...,n-1 ) im{Z} = sum( im{X[i]} * re{Y[i]} - re{X[i]} *
+- * im{Y[i]}, i=0,...,n-1 )
+- *
+- * The function returns the complex-valued result of the complex
+- * scalar product at the address of Z. The result is scaled by scaleZ.
+- *
+- * \param FIXP_DPK *Z
+- * Output: pointer to Z
+- *
+- * \param const FIXP_DPK *const *const X
+- * Input: vector of the length n
+- *
+- * \param const FIXP_DPK *const *const Y
+- * Input: vector of the length n
+- *
+- * \param int scaleX
+- * Input: scalefactor of vector X[]
+- *
+- * \param int scaleY
+- * Input: scalefactor of vector Y[]
+- *
+- * \param int scaleZ
+- * Output: scalefactor of vector Z[]
+- *
+- * \param int sDim1
+- * Input: start index for loop counter in dimension 1
+- *
+- * \param int nDim1
+- * Input: loop counter in dimension 1
+- *
+- * \param int sDim2
+- * Input: start index for loop counter in dimension 2
+- *
+- * \param int nDim2
+- * Input: loop counter in dimension 2
+- *
+- * \return void
+- */
+-void cplx_cplxScalarProduct(FIXP_DPK *const Z, const FIXP_DPK *const *const X,
+- const FIXP_DPK *const *const Y, const INT scaleX,
+- const INT scaleY, INT *const scaleZ,
+- const INT sDim1, const INT nDim1, const INT sDim2,
+- const INT nDim2);
+-
+-/**
+- * \brief Vector function : Calculate correlation
+- *
+- * Description : z[i] = pr12[i] / sqrt(p1[i]*p2[i]) ,
+- * i=0,...,n-1
+- *
+- * \param FIXP_DBL z[]
+- * Output: vector of length n
+- *
+- * \param const FIXP_DBL pr12[]
+- * Input: vector of the length n
+- *
+- * \param const FIXP_DBL p1[]
+- * Input: vector of the length n
+- *
+- * \param const FIXP_DBL p2[]
+- * Input: vector of the length n
+- *
+- * \param int n
+- * Input: length of vector pr12[], p1[] and p2[]
+- *
+- * \return void
+- */
+-void FDKcalcCorrelationVec(FIXP_DBL *const z, const FIXP_DBL *const pr12,
+- const FIXP_DBL *const p1, const FIXP_DBL *const p2,
+- const INT n);
+-
+-/**
+- * \brief Vector function : Calculate coherence
+- *
+- * Description : z[i] = sqrt( (p12r[i]*p12r[i] +
+- * p12i[i]*p12i[i]) / (p1[i]*p2[i]) ), i=0,...,n-1
+- *
+- * \param FIXP_DBL z[]
+- * Output: vector of length n
+- *
+- * \param const FIXP_DBL p12r[]
+- * Input: vector of the length n
+- *
+- * \param const FIXP_DBL p12i[]
+- * Input: vector of the length n
+- *
+- * \param const FIXP_DBL p1[]
+- * Input: vector of the length n
+- *
+- * \param const FIXP_DBL p2[]
+- * Input: vector of the length n
+- *
+- * \param int scaleP12[]
+- * Input: scalefactor of p12r and p12i
+- *
+- * \param int scaleP
+- * Input: scalefactor of p1 and p2
+- *
+- * \param int n
+- * Input: length of vector p12r[], p12i[], p1[] and p2[]
+- *
+- * \return void
+- */
+-void calcCoherenceVec(FIXP_DBL *const z, const FIXP_DBL *const p12r,
+- const FIXP_DBL *const p12i, const FIXP_DBL *const p1,
+- const FIXP_DBL *const p2, const INT scaleP12,
+- const INT scaleP, const INT n);
+-
+-/**
+- * \brief Vector function : Z[j][i] = a[pb] * X[j][i] + b[pb] *
+- * Y[j][i], j=0,...,nHybridBands-1; i=startTimeSlot,...,nTimeSlots-1;
+- * pb=0,...,nParameterBands-1
+- *
+- * Description : re{Z[j][i]} = a[pb] * re{X[j][i]} + b[pb] *
+- * re{Y[j][i]}, j=0,...,nHybridBands-1; i=startTimeSlot,...,nTimeSlots-1;
+- * pb=0,...,nParameterBands-1 im{Z[j][i]} = a[pb] * im{X[j][i]} + b[pb] *
+- * im{Y[j][i]}, j=0,...,nHybridBands-1;
+- * i=startTimeSlot,...,nTimeSlots-1; pb=0,...,nParameterBands-1
+- *
+- * It is allowed to overlay X[] or Y[] with Z[]. The scalefactor
+- * of channel 1 is updated with the common scalefactor of channel 1 and
+- * channel 2.
+- *
+- * \param FIXP_DPK **Z
+- * Output: vector of the length nHybridBands*nTimeSlots
+- *
+- * \param const FIXP_DBL *a
+- * Input: vector of length nParameterBands
+- *
+- * \param const FIXP_DPK **X
+- * Input: vector of the length nHybridBands*nTimeSlots
+- *
+- * \param const FIXP_DBL *b
+- * Input: vector of length nParameterBands
+- *
+- * \param const FIXP_DPK **Y
+- * Input: vector of the length nHybridBands*nTimeSlots
+- *
+- * \param int scale
+- * Input: scale of vector a and b
+- *
+- * \param int *scaleCh1
+- * Input: scale of ch1
+- *
+- * \param int scaleCh2
+- * Input: scale of ch2
+- *
+- * \param UCHAR *pParameterBand2HybridBandOffset
+- * Input: vector of length nParameterBands
+- *
+- * \param int nTimeSlots
+- * Input: number of time slots
+- *
+- * \param int startTimeSlot
+- * Input: start time slot
+- *
+- * \return void
+- */
+-void addWeightedCplxVec(FIXP_DPK *const *const Z, const FIXP_DBL *const a,
+- const FIXP_DPK *const *const X, const FIXP_DBL *const b,
+- const FIXP_DPK *const *const Y, const INT scale,
+- INT *const scaleCh1, const INT scaleCh2,
+- const UCHAR *const pParameterBand2HybridBandOffset,
+- const INT nParameterBands, const INT nTimeSlots,
+- const INT startTimeSlot);
+-
+-/**
+- * \brief Vector function : Calculate the headroom of a complex vector
+- * in a parameter band grid
+- *
+- * \param FIXP_DPK **x
+- * Input: pointer to complex input vector
+- *
+- * \param UCHAR *pParameterBand2HybridBandOffset
+- * Input: pointer to hybrid band offsets
+- *
+- * \param int *outScaleFactor
+- * Input: pointer to ouput scalefactor
+- *
+- * \param int startTimeSlot
+- * Input: start time slot
+- *
+- * \param int nTimeSlots
+- * Input: number of time slot
+- *
+- * \param int nParamBands
+- * Input: number of parameter bands
+- *
+- * \return void
+- */
+-void FDKcalcPbScaleFactor(const FIXP_DPK *const *const x,
+- const UCHAR *const pParameterBand2HybridBandOffset,
+- INT *const outScaleFactor, const INT startTimeSlot,
+- const INT nTimeSlots, const INT nParamBands);
+-
+-/**
+- * \brief Vector function : Calculate the common headroom of two
+- * sparate vectors
+- *
+- * \param FIXP_DBL *x
+- * Input: pointer to first input vector
+- *
+- * \param FIXP_DBL *y
+- * Input: pointer to second input vector
+- *
+- * \param int n
+- * Input: number of samples
+- *
+- * \return int headromm in bits
+- */
+-INT FDKcalcScaleFactor(const FIXP_DBL *const x, const FIXP_DBL *const y,
+- const INT n);
+-
+-/**
+- * \brief Vector function : Calculate the headroom of a complex vector
+- *
+- * \param FIXP_DPK *x
+- * Input: pointer to complex input vector
+- *
+- * \param INT startBand
+- * Input: start band
+- *
+- * \param INT bands
+- * Input: number of bands
+- *
+- * \return int headromm in bits
+- */
+-INT FDKcalcScaleFactorDPK(const FIXP_DPK *RESTRICT x, const INT startBand,
+- const INT bands);
+-
+-/* Function / Class Definition ***********************************************/
+-template <class T>
+-inline void FDKmemcpy_flex(T *const dst, const INT dstStride,
+- const T *const src, const INT srcStride,
+- const INT nSamples) {
+- int i;
+-
+- for (i = 0; i < nSamples; i++) {
+- dst[i * dstStride] = src[i * srcStride];
+- }
+-}
+-
+-template <class T>
+-inline void FDKmemset_flex(T *const x, const T c, const INT nSamples) {
+- int i;
+-
+- for (i = 0; i < nSamples; i++) {
+- x[i] = c;
+- }
+-}
+-
+-#endif /* SACENC_VECTORFUNCTIONS_H */
+--
+cgit v1.1
+
--- /dev/null
+From 0fc0e0e0b89de3becd5f099eae725f13eeecc0d1 Mon Sep 17 00:00:00 2001
+From: Wim Taymans <wtaymans@redhat.com>
+Date: Tue, 25 Jun 2019 11:43:16 +0200
+Subject: Remove USAC
+
+---
+ Makefile.am | 9 +-
+ Makefile.vc | 9 +-
+ libAACdec/src/aacdecoder.cpp | 34 +-
+ libAACdec/src/block.cpp | 163 ---
+ libAACdec/src/channel.cpp | 70 +-
+ libAACdec/src/channelinfo.h | 91 --
+ libAACdec/src/usacdec_ace_d4t64.cpp | 439 --------
+ libAACdec/src/usacdec_ace_d4t64.h | 117 --
+ libAACdec/src/usacdec_ace_ltp.cpp | 229 ----
+ libAACdec/src/usacdec_ace_ltp.h | 128 ---
+ libAACdec/src/usacdec_acelp.cpp | 1296 ----------------------
+ libAACdec/src/usacdec_acelp.h | 281 -----
+ libAACdec/src/usacdec_const.h | 203 ----
+ libAACdec/src/usacdec_fac.cpp | 745 -------------
+ libAACdec/src/usacdec_fac.h | 191 ----
+ libAACdec/src/usacdec_lpc.cpp | 1194 ---------------------
+ libAACdec/src/usacdec_lpc.h | 190 ----
+ libAACdec/src/usacdec_lpd.cpp | 2017 -----------------------------------
+ libAACdec/src/usacdec_lpd.h | 198 ----
+ libAACdec/src/usacdec_rom.cpp | 1504 --------------------------
+ libAACdec/src/usacdec_rom.h | 154 ---
+ 22 files changed, 6 insertions(+), 9258 deletions(-)
+ delete mode 100644 libAACdec/src/usacdec_ace_d4t64.cpp
+ delete mode 100644 libAACdec/src/usacdec_ace_d4t64.h
+ delete mode 100644 libAACdec/src/usacdec_ace_ltp.cpp
+ delete mode 100644 libAACdec/src/usacdec_ace_ltp.h
+ delete mode 100644 libAACdec/src/usacdec_acelp.cpp
+ delete mode 100644 libAACdec/src/usacdec_acelp.h
+ delete mode 100644 libAACdec/src/usacdec_const.h
+ delete mode 100644 libAACdec/src/usacdec_fac.cpp
+ delete mode 100644 libAACdec/src/usacdec_fac.h
+ delete mode 100644 libAACdec/src/usacdec_lpc.cpp
+ delete mode 100644 libAACdec/src/usacdec_lpc.h
+ delete mode 100644 libAACdec/src/usacdec_lpd.cpp
+ delete mode 100644 libAACdec/src/usacdec_lpd.h
+ delete mode 100644 libAACdec/src/usacdec_rom.cpp
+ delete mode 100644 libAACdec/src/usacdec_rom.h
+
+diff --git a/Makefile.am b/Makefile.am
+index 1550d95..d5fd180 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -57,14 +57,7 @@ AACDEC_SRC = \
+ libAACdec/src/channelinfo.cpp \
+ libAACdec/src/ldfiltbank.cpp \
+ libAACdec/src/pulsedata.cpp \
+- libAACdec/src/stereo.cpp \
+- libAACdec/src/usacdec_ace_d4t64.cpp \
+- libAACdec/src/usacdec_ace_ltp.cpp \
+- libAACdec/src/usacdec_acelp.cpp \
+- libAACdec/src/usacdec_fac.cpp \
+- libAACdec/src/usacdec_lpc.cpp \
+- libAACdec/src/usacdec_lpd.cpp \
+- libAACdec/src/usacdec_rom.cpp
++ libAACdec/src/stereo.cpp
+
+ AACENC_SRC = \
+ libAACenc/src/aacEnc_ram.cpp \
+diff --git a/Makefile.vc b/Makefile.vc
+index 54f3744..c236c15 100644
+--- a/Makefile.vc
++++ b/Makefile.vc
+@@ -41,14 +41,7 @@ AACDEC_SRC = \
+ libAACdec/src/channelinfo.cpp \
+ libAACdec/src/ldfiltbank.cpp \
+ libAACdec/src/pulsedata.cpp \
+- libAACdec/src/stereo.cpp \
+- libAACdec/src/usacdec_ace_d4t64.cpp \
+- libAACdec/src/usacdec_ace_ltp.cpp \
+- libAACdec/src/usacdec_acelp.cpp \
+- libAACdec/src/usacdec_fac.cpp \
+- libAACdec/src/usacdec_lpc.cpp \
+- libAACdec/src/usacdec_lpd.cpp \
+- libAACdec/src/usacdec_rom.cpp
++ libAACdec/src/stereo.cpp
+
+ AACENC_SRC = \
+ libAACenc/src/aacEnc_ram.cpp \
+diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp
+index cc3e245..cd57500 100644
+--- a/libAACdec/src/aacdecoder.cpp
++++ b/libAACdec/src/aacdecoder.cpp
+@@ -161,8 +161,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "aacdec_pns.h"
+
+-#include "usacdec_lpd.h"
+-
+ #include "ac_arith_coder.h"
+
+ #include "tpdec_lib.h"
+@@ -1942,17 +1940,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ goto bail;
+ }
+ }
+- if (elCh > 0) {
+- self->pAacDecoderStaticChannelInfo[ch - elCh]->nfRandomSeed =
+- (ULONG)0x3039;
+- if (self->elements[el2] == ID_USAC_CPE) {
+- if (asc->m_sc.m_usacConfig.element[el2].m_stereoConfigIndex !=
+- 1) {
+- self->pAacDecoderStaticChannelInfo[ch - elCh + 1]
+- ->nfRandomSeed = (ULONG)0x10932;
+- }
+- }
+- }
+ } /* for each element */
+ }
+
+@@ -2010,11 +1997,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
+ self->pAacDecoderStaticChannelInfo[ch]->pOverlapBuffer,
+ OverlapBufferSize);
+
+- self->pAacDecoderStaticChannelInfo[ch]->last_core_mode = FD_LONG;
+- self->pAacDecoderStaticChannelInfo[ch]->last_lpd_mode = 255;
+-
+- self->pAacDecoderStaticChannelInfo[ch]->last_tcx_pitch = L_DIV;
+-
+ /* Reset DRC control data for this channel */
+ aacDecoder_drcInitChannelData(
+ &self->pAacDecoderStaticChannelInfo[ch]->drcData);
+@@ -2893,10 +2875,7 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ (self->frameOK && !(flags & AACDEC_CONCEAL));
+ const int icsIsInvalid = (GetScaleFactorBandsTransmitted(pIcsInfo) >
+ GetScaleFactorBandsTotal(pIcsInfo));
+- const int icsInfoUsedinFadeOut =
+- !(pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD &&
+- pAacDecoderStaticChannelInfo->last_lpd_mode == 0);
+- if (icsInfoUsedinFadeOut && icsIsInvalid && !mute_release_active) {
++ if (icsIsInvalid && !mute_release_active) {
+ self->frameOK = 0;
+ }
+ }
+@@ -2956,16 +2935,7 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
+ 2;
+ } break;
+ case AACDEC_RENDER_LPD:
+-
+- CLpd_RenderTimeSignal(
+- pAacDecoderStaticChannelInfo, pAacDecoderChannelInfo,
+- pTimeData + offset, self->streamInfo.aacSamplesPerFrame,
+- &self->samplingRateInfo[streamIndex],
+- (self->frameOK && !(flags & AACDEC_CONCEAL) &&
+- !frameOk_butConceal),
+- flags, self->flags[streamIndex]);
+-
+- self->extGainDelay = self->streamInfo.aacSamplesPerFrame;
++ ErrorStatus = AAC_DEC_UNKNOWN;
+ break;
+ default:
+ ErrorStatus = AAC_DEC_UNKNOWN;
+diff --git a/libAACdec/src/block.cpp b/libAACdec/src/block.cpp
+index a394cd7..b8ca877 100644
+--- a/libAACdec/src/block.cpp
++++ b/libAACdec/src/block.cpp
+@@ -107,9 +107,6 @@ amm-info@iis.fraunhofer.de
+ #include "scale.h"
+ #include "FDK_tools_rom.h"
+
+-#include "usacdec_fac.h"
+-#include "usacdec_lpd.h"
+-#include "usacdec_lpc.h"
+ #include "FDK_trigFcts.h"
+
+ #include "ac_arith_coder.h"
+@@ -1010,162 +1007,7 @@ void CBlock_FrequencyToTime(
+ nSpec = 8;
+ break;
+ }
+-
+ {
+- int last_frame_lost = pAacDecoderStaticChannelInfo->last_lpc_lost;
+-
+- if (pAacDecoderStaticChannelInfo->last_core_mode == LPD) {
+- INT fac_FB = 1;
+- if (elFlags & AC_EL_FULLBANDLPD) {
+- fac_FB = 2;
+- }
+-
+- FIXP_DBL *synth;
+-
+- /* Keep some free space at the beginning of the buffer. To be used for
+- * past data */
+- if (!(elFlags & AC_EL_LPDSTEREOIDX)) {
+- synth = pWorkBuffer1 + ((PIT_MAX_MAX - (1 * L_SUBFR)) * fac_FB);
+- } else {
+- synth = pWorkBuffer1 + PIT_MAX_MAX * fac_FB;
+- }
+-
+- int fac_length =
+- (pAacDecoderChannelInfo->icsInfo.WindowSequence == BLOCK_SHORT)
+- ? (frameLen >> 4)
+- : (frameLen >> 3);
+-
+- INT pitch[NB_SUBFR_SUPERFR + SYN_SFD];
+- FIXP_DBL pit_gain[NB_SUBFR_SUPERFR + SYN_SFD];
+-
+- int nbDiv = (elFlags & AC_EL_FULLBANDLPD) ? 2 : 4;
+- int lFrame = (elFlags & AC_EL_FULLBANDLPD) ? frameLen / 2 : frameLen;
+- int nbSubfr =
+- lFrame / (nbDiv * L_SUBFR); /* number of subframes per division */
+- int LpdSfd = (nbDiv * nbSubfr) >> 1;
+- int SynSfd = LpdSfd - BPF_SFD;
+-
+- FDKmemclear(
+- pitch,
+- sizeof(
+- pitch)); // added to prevent ferret errors in bass_pf_1sf_delay
+- FDKmemclear(pit_gain, sizeof(pit_gain));
+-
+- /* FAC case */
+- if (pAacDecoderStaticChannelInfo->last_lpd_mode == 0 ||
+- pAacDecoderStaticChannelInfo->last_lpd_mode == 4) {
+- FIXP_DBL fac_buf[LFAC];
+- FIXP_LPC *A = pAacDecoderChannelInfo->data.usac.lp_coeff[0];
+-
+- if (!frameOk || last_frame_lost ||
+- (pAacDecoderChannelInfo->data.usac.fac_data[0] == NULL)) {
+- FDKmemclear(fac_buf,
+- pAacDecoderChannelInfo->granuleLength * sizeof(FIXP_DBL));
+- pAacDecoderChannelInfo->data.usac.fac_data[0] = fac_buf;
+- pAacDecoderChannelInfo->data.usac.fac_data_e[0] = 0;
+- }
+-
+- INT A_exp; /* linear prediction coefficients exponent */
+- {
+- for (int i = 0; i < M_LP_FILTER_ORDER; i++) {
+- A[i] = FX_DBL2FX_LPC(fixp_cos(
+- fMult(pAacDecoderStaticChannelInfo->lpc4_lsf[i],
+- FL2FXCONST_SGL((1 << LSPARG_SCALE) * M_PI / 6400.0)),
+- LSF_SCALE - LSPARG_SCALE));
+- }
+-
+- E_LPC_f_lsp_a_conversion(A, A, &A_exp);
+- }
+-
+-#if defined(FDK_ASSERT_ENABLE)
+- nSamples =
+-#endif
+- CLpd_FAC_Acelp2Mdct(
+- &pAacDecoderStaticChannelInfo->IMdct, synth,
+- SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient),
+- pAacDecoderChannelInfo->specScale, nSpec,
+- pAacDecoderChannelInfo->data.usac.fac_data[0],
+- pAacDecoderChannelInfo->data.usac.fac_data_e[0], fac_length,
+- frameLen, tl,
+- FDKgetWindowSlope(
+- fr, GetWindowShape(&pAacDecoderChannelInfo->icsInfo)),
+- fr, A, A_exp, &pAacDecoderStaticChannelInfo->acelp,
+- (FIXP_DBL)0, /* FAC gain has already been applied. */
+- (last_frame_lost || !frameOk), 1,
+- pAacDecoderStaticChannelInfo->last_lpd_mode, 0,
+- pAacDecoderChannelInfo->currAliasingSymmetry);
+-
+- } else {
+-#if defined(FDK_ASSERT_ENABLE)
+- nSamples =
+-#endif
+- imlt_block(
+- &pAacDecoderStaticChannelInfo->IMdct, synth,
+- SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient),
+- pAacDecoderChannelInfo->specScale, nSpec, frameLen, tl,
+- FDKgetWindowSlope(
+- fl, GetWindowShape(&pAacDecoderChannelInfo->icsInfo)),
+- fl,
+- FDKgetWindowSlope(
+- fr, GetWindowShape(&pAacDecoderChannelInfo->icsInfo)),
+- fr, (FIXP_DBL)0,
+- pAacDecoderChannelInfo->currAliasingSymmetry
+- ? MLT_FLAG_CURR_ALIAS_SYMMETRY
+- : 0);
+- }
+- FDK_ASSERT(nSamples == frameLen);
+-
+- /* The "if" clause is entered both for fullbandLpd mono and
+- * non-fullbandLpd*. The "else"-> just for fullbandLpd stereo*/
+- if (!(elFlags & AC_EL_LPDSTEREOIDX)) {
+- FDKmemcpy(pitch, pAacDecoderStaticChannelInfo->old_T_pf,
+- SynSfd * sizeof(INT));
+- FDKmemcpy(pit_gain, pAacDecoderStaticChannelInfo->old_gain_pf,
+- SynSfd * sizeof(FIXP_DBL));
+-
+- for (int i = SynSfd; i < LpdSfd + 3; i++) {
+- pitch[i] = L_SUBFR;
+- pit_gain[i] = (FIXP_DBL)0;
+- }
+-
+- if (pAacDecoderStaticChannelInfo->last_lpd_mode == 0) {
+- pitch[SynSfd] = pitch[SynSfd - 1];
+- pit_gain[SynSfd] = pit_gain[SynSfd - 1];
+- if (IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) {
+- pitch[SynSfd + 1] = pitch[SynSfd];
+- pit_gain[SynSfd + 1] = pit_gain[SynSfd];
+- }
+- }
+-
+- /* Copy old data to the beginning of the buffer */
+- {
+- FDKmemcpy(
+- pWorkBuffer1, pAacDecoderStaticChannelInfo->old_synth,
+- ((PIT_MAX_MAX - (1 * L_SUBFR)) * fac_FB) * sizeof(FIXP_DBL));
+- }
+-
+- FIXP_DBL *p2_synth = pWorkBuffer1 + (PIT_MAX_MAX * fac_FB);
+-
+- /* recalculate pitch gain to allow postfilering on FAC area */
+- for (int i = 0; i < SynSfd + 2; i++) {
+- int T = pitch[i];
+- FIXP_DBL gain = pit_gain[i];
+-
+- if (gain > (FIXP_DBL)0) {
+- gain = get_gain(&p2_synth[i * L_SUBFR * fac_FB],
+- &p2_synth[(i * L_SUBFR * fac_FB) - fac_FB * T],
+- L_SUBFR * fac_FB);
+- pit_gain[i] = gain;
+- }
+- }
+-
+- bass_pf_1sf_delay(p2_synth, pitch, pit_gain, frameLen,
+- (LpdSfd + 2) * L_SUBFR + BPF_SFD * L_SUBFR,
+- frameLen - (LpdSfd + 4) * L_SUBFR, outSamples,
+- pAacDecoderStaticChannelInfo->mem_bpf);
+- }
+-
+- } else /* last_core_mode was not LPD */
+ {
+ FIXP_DBL *tmp =
+ pAacDecoderChannelInfo->pComStaticData->pWorkBufferCore1->mdctOutTemp;
+@@ -1190,11 +1032,6 @@ void CBlock_FrequencyToTime(
+ }
+
+ FDK_ASSERT(nSamples == frameLen);
+-
+- pAacDecoderStaticChannelInfo->last_core_mode =
+- (pAacDecoderChannelInfo->icsInfo.WindowSequence == BLOCK_SHORT) ? FD_SHORT
+- : FD_LONG;
+- pAacDecoderStaticChannelInfo->last_lpd_mode = 255;
+ }
+
+ #include "ldfiltbank.h"
+diff --git a/libAACdec/src/channel.cpp b/libAACdec/src/channel.cpp
+index e17ccf4..fe63756 100644
+--- a/libAACdec/src/channel.cpp
++++ b/libAACdec/src/channel.cpp
+@@ -106,9 +106,6 @@ amm-info@iis.fraunhofer.de
+ #include "aacdec_tns.h"
+ #include "FDK_bitstream.h"
+
+-#include "usacdec_lpd.h"
+-#include "usacdec_fac.h"
+-
+ static void MapMidSideMaskToPnsCorrelation(
+ CAacDecoderChannelInfo *pAacDecoderChannelInfo[2]) {
+ int group;
+@@ -164,13 +161,6 @@ void CChannelElement_Decode(
+ int maxSfBandsL = 0, maxSfBandsR = 0;
+ int maybe_jstereo = (el_channels > 1);
+
+- if (flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA) && el_channels == 2) {
+- if (pAacDecoderChannelInfo[L]->data.usac.core_mode ||
+- pAacDecoderChannelInfo[R]->data.usac.core_mode) {
+- maybe_jstereo = 0;
+- }
+- }
+-
+ if (maybe_jstereo) {
+ maxSfBandsL =
+ GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo);
+@@ -236,9 +226,6 @@ void CChannelElement_Decode(
+
+ for (ch = 0; ch < el_channels; ch++) {
+ if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_LPD) {
+- /* Decode LPD data */
+- CLpdChannelStream_Decode(pAacDecoderChannelInfo[ch],
+- pAacDecoderStaticChannelInfo[ch], flags);
+ } else {
+ UCHAR noSfbs =
+ GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[ch]->icsInfo);
+@@ -651,13 +638,6 @@ AAC_DECODER_ERROR CChannelElement_Read(
+ break;
+ case core_mode:
+ decision_bit = FDKreadBits(hBs, 1);
+- pAacDecoderChannelInfo[ch]->data.usac.core_mode = decision_bit;
+- if ((ch == 1) && (pAacDecoderChannelInfo[0]->data.usac.core_mode !=
+- pAacDecoderChannelInfo[1]->data.usac.core_mode)) {
+- /* StereoCoreToolInfo(core_mode[ch] ) */
+- pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 0;
+- pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = 0;
+- }
+ break;
+ case tns_active:
+ pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active =
+@@ -671,53 +651,12 @@ AAC_DECODER_ERROR CChannelElement_Read(
+ }
+ break;
+ case lpd_channel_stream:
+-
+- {
+- error = CLpdChannelStream_Read(/* = lpd_channel_stream() */
+- hBs, pAacDecoderChannelInfo[ch],
+- pAacDecoderStaticChannelInfo[ch],
+- pSamplingRateInfo, flags);
+- }
+-
+ pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_LPD;
+ break;
+ case fac_data: {
+ int fFacDatPresent = FDKreadBit(hBs);
+
+- /* Wee need a valid fac_data[0] even if no FAC data is present (as
+- * temporal buffer) */
+- pAacDecoderChannelInfo[ch]->data.usac.fac_data[0] =
+- pAacDecoderChannelInfo[ch]->data.usac.fac_data0;
+-
+- if (fFacDatPresent) {
+- if (elFlags & AC_EL_LFE) {
+- error = AAC_DEC_PARSE_ERROR;
+- break;
+- }
+- /* FAC data present, this frame is FD, so the last mode had to be
+- * ACELP. */
+- if (pAacDecoderStaticChannelInfo[ch]->last_core_mode != LPD ||
+- pAacDecoderStaticChannelInfo[ch]->last_lpd_mode != 0) {
+- pAacDecoderChannelInfo[ch]->data.usac.core_mode_last = LPD;
+- pAacDecoderChannelInfo[ch]->data.usac.lpd_mode_last = 0;
+- /* We can't change the past! So look to the future and go ahead! */
+- }
+- CLpd_FAC_Read(hBs, pAacDecoderChannelInfo[ch]->data.usac.fac_data[0],
+- pAacDecoderChannelInfo[ch]->data.usac.fac_data_e,
+- CLpd_FAC_getLength(
+- IsLongBlock(&pAacDecoderChannelInfo[ch]->icsInfo),
+- pAacDecoderChannelInfo[ch]->granuleLength),
+- 1, 0);
+- } else {
+- if (pAacDecoderStaticChannelInfo[ch]->last_core_mode == LPD &&
+- pAacDecoderStaticChannelInfo[ch]->last_lpd_mode == 0) {
+- /* ACELP to FD transitons without FAC are possible. That is why we
+- zero it out (i.e FAC will not be considered in the subsequent
+- calculations */
+- FDKmemclear(pAacDecoderChannelInfo[ch]->data.usac.fac_data0,
+- LFAC * sizeof(FIXP_DBL));
+- }
+- }
++ error = AAC_DEC_PARSE_ERROR;
+ } break;
+ case esc2_rvlc:
+ if (flags & AC_ER_RVLC) {
+@@ -887,13 +826,6 @@ AAC_DECODER_ERROR CChannelElement_Read(
+ if (error != AAC_DEC_OK) {
+ return error;
+ }
+-
+- if (elFlags & AC_EL_USAC_NOISE) {
+- CBlock_ApplyNoise(pAacDecoderChannelInfo[ch], pSamplingRateInfo,
+- &pAacDecoderStaticChannelInfo[ch]->nfRandomSeed,
+- band_is_noise);
+-
+- } /* if (elFlags & AC_EL_USAC_NOISE) */
+ }
+ }
+
+diff --git a/libAACdec/src/channelinfo.h b/libAACdec/src/channelinfo.h
+index 04f0012..42c8298 100644
+--- a/libAACdec/src/channelinfo.h
++++ b/libAACdec/src/channelinfo.h
+@@ -117,10 +117,6 @@ amm-info@iis.fraunhofer.de
+
+ #include "aacdec_pns.h"
+
+-#include "usacdec_acelp.h"
+-#include "usacdec_const.h"
+-#include "usacdec_rom.h"
+-
+ #include "ac_arith_coder.h"
+
+ #include "aacdec_drc_types.h"
+@@ -202,55 +198,6 @@ typedef struct {
+
+ INT pnsCurrentSeed;
+
+- /* LPD memory */
+- FIXP_DBL old_synth[PIT_MAX_MAX - L_SUBFR];
+- INT old_T_pf[SYN_SFD];
+- FIXP_DBL old_gain_pf[SYN_SFD];
+- FIXP_DBL mem_bpf[L_FILT + L_SUBFR];
+- UCHAR
+- old_bpf_control_info; /* (1: enable, 0: disable) bpf for past superframe
+- */
+-
+- USAC_COREMODE last_core_mode; /* core mode used by the decoder in previous
+- frame. (not signalled by the bitstream, see
+- CAacDecoderChannelInfo::core_mode_last !! )
+- */
+- UCHAR last_lpd_mode; /* LPD mode used by the decoder in last LPD subframe
+- (not signalled by the bitstream, see
+- CAacDecoderChannelInfo::lpd_mode_last !! ) */
+- UCHAR last_last_lpd_mode; /* LPD mode used in second last LPD subframe
+- (not signalled by the bitstream) */
+- UCHAR last_lpc_lost; /* Flag indicating that the previous LPC is lost */
+-
+- FIXP_LPC
+- lpc4_lsf[M_LP_FILTER_ORDER]; /* Last LPC4 coefficients in LSF domain. */
+- FIXP_LPC lsf_adaptive_mean[M_LP_FILTER_ORDER]; /* Adaptive mean of LPC
+- coefficients in LSF domain
+- for concealment. */
+- FIXP_LPC lp_coeff_old[2][M_LP_FILTER_ORDER]; /* Last LPC coefficients in LP
+- domain. lp_coeff_old[0] is lpc4 (coeffs for
+- right folding point of last tcx frame),
+- lp_coeff_old[1] are coeffs for left folding
+- point of last tcx frame */
+- INT lp_coeff_old_exp[2];
+-
+- FIXP_SGL
+- oldStability; /* LPC coeff stability value from last frame (required for
+- TCX concealment). */
+- UINT numLostLpdFrames; /* Number of consecutive lost subframes. */
+-
+- /* TCX memory */
+- FIXP_DBL last_tcx_gain;
+- INT last_tcx_gain_e;
+- FIXP_DBL last_alfd_gains[32]; /* Scaled by one bit. */
+- SHORT last_tcx_pitch;
+- UCHAR last_tcx_noise_factor;
+-
+- /* ACELP memory */
+- CAcelpStaticMem acelp;
+-
+- ULONG nfRandomSeed; /* seed value for USAC noise filling random generator */
+-
+ CDrcChannelData drcData;
+
+ CpePersistentData *pCpeStaticData;
+@@ -299,8 +246,6 @@ typedef shouldBeUnion {
+ * used anymore. */
+ FIXP_DBL mdctOutTemp[1024];
+
+- FIXP_DBL synth_buf[(PIT_MAX_MAX + SYN_DELAY + L_FRAME_PLUS)];
+-
+ FIXP_DBL workBuffer[WB_SECTION_SIZE];
+ }
+ CWorkBufferCore1;
+@@ -335,42 +280,6 @@ typedef struct {
+ */
+ typedef struct {
+ shouldBeUnion {
+- struct {
+- FIXP_DBL fac_data0[LFAC];
+- SCHAR fac_data_e[4];
+- FIXP_DBL
+- *fac_data[4]; /* Pointers to unused parts of pSpectralCoefficient */
+-
+- UCHAR core_mode; /* current core mode */
+- USAC_COREMODE
+- core_mode_last; /* previous core mode, signalled in the bitstream
+- (not done by the decoder, see
+- CAacDecoderStaticChannelInfo::last_core_mode !!)*/
+- UCHAR lpd_mode_last; /* previous LPD mode, signalled in the bitstream
+- (not done by the decoder, see
+- CAacDecoderStaticChannelInfo::last_core_mode !!)*/
+- UCHAR mod[4];
+- UCHAR bpf_control_info; /* (1: enable, 0: disable) bpf for current
+- superframe */
+-
+- FIXP_LPC lsp_coeff[5][M_LP_FILTER_ORDER]; /* linear prediction
+- coefficients in LSP domain */
+- FIXP_LPC
+- lp_coeff[5][M_LP_FILTER_ORDER]; /* linear prediction coefficients in
+- LP domain */
+- INT lp_coeff_exp[5];
+- FIXP_LPC lsf_adaptive_mean_cand
+- [M_LP_FILTER_ORDER]; /* concealment: is copied to
+- CAacDecoderStaticChannelInfo->lsf_adaptive_mean once frame is
+- assumed to be correct*/
+- FIXP_SGL aStability[4]; /* LPC coeff stability values required for ACELP
+- and TCX (concealment) */
+-
+- CAcelpChannelData acelp[4];
+-
+- FIXP_DBL tcx_gain[4];
+- SCHAR tcx_gain_e[4];
+- } usac;
+
+ struct {
+ CPnsData PnsData; /* Not required for USAC */
+diff --git a/libAACdec/src/usacdec_ace_d4t64.cpp b/libAACdec/src/usacdec_ace_d4t64.cpp
+deleted file mode 100644
+index 43e06cd..0000000
+--- a/libAACdec/src/usacdec_ace_d4t64.cpp
++++ /dev/null
+@@ -1,439 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s):
+-
+- Description: ACELP
+-
+-*******************************************************************************/
+-
+-#include "usacdec_ace_d4t64.h"
+-
+-#define L_SUBFR 64 /* Subframe size */
+-
+-/*
+- * D_ACELP_add_pulse
+- *
+- * Parameters:
+- * pos I: position of pulse
+- * nb_pulse I: number of pulses
+- * track I: track
+- * code O: fixed codebook
+- *
+- * Function:
+- * Add pulses to fixed codebook
+- *
+- * Returns:
+- * void
+- */
+-static void D_ACELP_add_pulse(SHORT pos[], SHORT nb_pulse, SHORT track,
+- FIXP_COD code[]) {
+- SHORT i, k;
+- for (k = 0; k < nb_pulse; k++) {
+- /* i = ((pos[k] & (16-1))*NB_TRACK) + track; */
+- i = ((pos[k] & (16 - 1)) << 2) + track;
+- if ((pos[k] & 16) == 0) {
+- code[i] = code[i] + (FIXP_COD)(512 << (COD_BITS - FRACT_BITS));
+- } else {
+- code[i] = code[i] - (FIXP_COD)(512 << (COD_BITS - FRACT_BITS));
+- }
+- }
+- return;
+-}
+-/*
+- * D_ACELP_decode_1p_N1
+- *
+- * Parameters:
+- * index I: pulse index
+- * N I: number of bits for position
+- * offset I: offset
+- * pos O: position of the pulse
+- *
+- * Function:
+- * Decode 1 pulse with N+1 bits
+- *
+- * Returns:
+- * void
+- */
+-static void D_ACELP_decode_1p_N1(LONG index, SHORT N, SHORT offset,
+- SHORT pos[]) {
+- SHORT pos1;
+- LONG i, mask;
+-
+- mask = ((1 << N) - 1);
+- /*
+- * Decode 1 pulse with N+1 bits
+- */
+- pos1 = (SHORT)((index & mask) + offset);
+- i = ((index >> N) & 1);
+- if (i == 1) {
+- pos1 += 16;
+- }
+- pos[0] = pos1;
+- return;
+-}
+-/*
+- * D_ACELP_decode_2p_2N1
+- *
+- * Parameters:
+- * index I: pulse index
+- * N I: number of bits for position
+- * offset I: offset
+- * pos O: position of the pulse
+- *
+- * Function:
+- * Decode 2 pulses with 2*N+1 bits
+- *
+- * Returns:
+- * void
+- */
+-static void D_ACELP_decode_2p_2N1(LONG index, SHORT N, SHORT offset,
+- SHORT pos[]) {
+- SHORT pos1, pos2;
+- LONG mask, i;
+- mask = ((1 << N) - 1);
+- /*
+- * Decode 2 pulses with 2*N+1 bits
+- */
+- pos1 = (SHORT)(((index >> N) & mask) + offset);
+- i = (index >> (2 * N)) & 1;
+- pos2 = (SHORT)((index & mask) + offset);
+- if ((pos2 - pos1) < 0) {
+- if (i == 1) {
+- pos1 += 16;
+- } else {
+- pos2 += 16;
+- }
+- } else {
+- if (i == 1) {
+- pos1 += 16;
+- pos2 += 16;
+- }
+- }
+- pos[0] = pos1;
+- pos[1] = pos2;
+- return;
+-}
+-/*
+- * D_ACELP_decode_3p_3N1
+- *
+- * Parameters:
+- * index I: pulse index
+- * N I: number of bits for position
+- * offset I: offset
+- * pos O: position of the pulse
+- *
+- * Function:
+- * Decode 3 pulses with 3*N+1 bits
+- *
+- * Returns:
+- * void
+- */
+-static void D_ACELP_decode_3p_3N1(LONG index, SHORT N, SHORT offset,
+- SHORT pos[]) {
+- SHORT j;
+- LONG mask, idx;
+-
+- /*
+- * Decode 3 pulses with 3*N+1 bits
+- */
+- mask = ((1 << ((2 * N) - 1)) - 1);
+- idx = index & mask;
+- j = offset;
+- if (((index >> ((2 * N) - 1)) & 1) == 1) {
+- j += (1 << (N - 1));
+- }
+- D_ACELP_decode_2p_2N1(idx, N - 1, j, pos);
+- mask = ((1 << (N + 1)) - 1);
+- idx = (index >> (2 * N)) & mask;
+- D_ACELP_decode_1p_N1(idx, N, offset, pos + 2);
+- return;
+-}
+-/*
+- * D_ACELP_decode_4p_4N1
+- *
+- * Parameters:
+- * index I: pulse index
+- * N I: number of bits for position
+- * offset I: offset
+- * pos O: position of the pulse
+- *
+- * Function:
+- * Decode 4 pulses with 4*N+1 bits
+- *
+- * Returns:
+- * void
+- */
+-static void D_ACELP_decode_4p_4N1(LONG index, SHORT N, SHORT offset,
+- SHORT pos[]) {
+- SHORT j;
+- LONG mask, idx;
+- /*
+- * Decode 4 pulses with 4*N+1 bits
+- */
+- mask = ((1 << ((2 * N) - 1)) - 1);
+- idx = index & mask;
+- j = offset;
+- if (((index >> ((2 * N) - 1)) & 1) == 1) {
+- j += (1 << (N - 1));
+- }
+- D_ACELP_decode_2p_2N1(idx, N - 1, j, pos);
+- mask = ((1 << ((2 * N) + 1)) - 1);
+- idx = (index >> (2 * N)) & mask;
+- D_ACELP_decode_2p_2N1(idx, N, offset, pos + 2);
+- return;
+-}
+-/*
+- * D_ACELP_decode_4p_4N
+- *
+- * Parameters:
+- * index I: pulse index
+- * N I: number of bits for position
+- * offset I: offset
+- * pos O: position of the pulse
+- *
+- * Function:
+- * Decode 4 pulses with 4*N bits
+- *
+- * Returns:
+- * void
+- */
+-static void D_ACELP_decode_4p_4N(LONG index, SHORT N, SHORT offset,
+- SHORT pos[]) {
+- SHORT j, n_1;
+- /*
+- * Decode 4 pulses with 4*N bits
+- */
+- n_1 = N - 1;
+- j = offset + (1 << n_1);
+- switch ((index >> ((4 * N) - 2)) & 3) {
+- case 0:
+- if (((index >> ((4 * n_1) + 1)) & 1) == 0) {
+- D_ACELP_decode_4p_4N1(index, n_1, offset, pos);
+- } else {
+- D_ACELP_decode_4p_4N1(index, n_1, j, pos);
+- }
+- break;
+- case 1:
+- D_ACELP_decode_1p_N1((index >> ((3 * n_1) + 1)), n_1, offset, pos);
+- D_ACELP_decode_3p_3N1(index, n_1, j, pos + 1);
+- break;
+- case 2:
+- D_ACELP_decode_2p_2N1((index >> ((2 * n_1) + 1)), n_1, offset, pos);
+- D_ACELP_decode_2p_2N1(index, n_1, j, pos + 2);
+- break;
+- case 3:
+- D_ACELP_decode_3p_3N1((index >> (n_1 + 1)), n_1, offset, pos);
+- D_ACELP_decode_1p_N1(index, n_1, j, pos + 3);
+- break;
+- }
+- return;
+-}
+-
+-/*
+- * D_ACELP_decode_4t
+- *
+- * Parameters:
+- * index I: index
+- * mode I: speech mode
+- * code I: (Q9) algebraic (fixed) codebook excitation
+- *
+- * Function:
+- * 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook.
+- * 4 tracks x 16 positions per track = 64 samples.
+- *
+- * 20 bits 5+5+5+5 --> 4 pulses in a frame of 64 samples.
+- * 36 bits 9+9+9+9 --> 8 pulses in a frame of 64 samples.
+- * 44 bits 13+9+13+9 --> 10 pulses in a frame of 64 samples.
+- * 52 bits 13+13+13+13 --> 12 pulses in a frame of 64 samples.
+- * 64 bits 2+2+2+2+14+14+14+14 --> 16 pulses in a frame of 64 samples.
+- * 72 bits 10+2+10+2+10+14+10+14 --> 18 pulses in a frame of 64 samples.
+- * 88 bits 11+11+11+11+11+11+11+11 --> 24 pulses in a frame of 64 samples.
+- *
+- * All pulses can have two (2) possible amplitudes: +1 or -1.
+- * Each pulse can sixteen (16) possible positions.
+- *
+- * codevector length 64
+- * number of track 4
+- * number of position 16
+- *
+- * Returns:
+- * void
+- */
+-void D_ACELP_decode_4t64(SHORT index[], int nbits, FIXP_COD code[]) {
+- LONG L_index;
+- SHORT k, pos[6];
+-
+- FDKmemclear(code, L_SUBFR * sizeof(FIXP_COD));
+-
+- /* decode the positions and signs of pulses and build the codeword */
+- switch (nbits) {
+- case 12:
+- for (k = 0; k < 4; k += 2) {
+- L_index = index[2 * (k / 2) + 1];
+- D_ACELP_decode_1p_N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 1, 2 * (index[2 * (k / 2)]) + k / 2, code);
+- }
+- break;
+- case 16: {
+- int i = 0;
+- int offset = index[i++];
+- offset = (offset == 0) ? 1 : 3;
+- for (k = 0; k < 4; k++) {
+- if (k != offset) {
+- L_index = index[i++];
+- D_ACELP_decode_1p_N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 1, k, code);
+- }
+- }
+- } break;
+- case 20:
+- for (k = 0; k < 4; k++) {
+- L_index = (LONG)index[k];
+- D_ACELP_decode_1p_N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 1, k, code);
+- }
+- break;
+- case 28:
+- for (k = 0; k < 4 - 2; k++) {
+- L_index = (LONG)index[k];
+- D_ACELP_decode_2p_2N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 2, k, code);
+- }
+- for (k = 2; k < 4; k++) {
+- L_index = (LONG)index[k];
+- D_ACELP_decode_1p_N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 1, k, code);
+- }
+- break;
+- case 36:
+- for (k = 0; k < 4; k++) {
+- L_index = (LONG)index[k];
+- D_ACELP_decode_2p_2N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 2, k, code);
+- }
+- break;
+- case 44:
+- for (k = 0; k < 4 - 2; k++) {
+- L_index = (LONG)index[k];
+- D_ACELP_decode_3p_3N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 3, k, code);
+- }
+- for (k = 2; k < 4; k++) {
+- L_index = (LONG)index[k];
+- D_ACELP_decode_2p_2N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 2, k, code);
+- }
+- break;
+- case 52:
+- for (k = 0; k < 4; k++) {
+- L_index = (LONG)index[k];
+- D_ACELP_decode_3p_3N1(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 3, k, code);
+- }
+- break;
+- case 64:
+- for (k = 0; k < 4; k++) {
+- L_index = (((LONG)index[k] << 14) + (LONG)index[k + 4]);
+- D_ACELP_decode_4p_4N(L_index, 4, 0, pos);
+- D_ACELP_add_pulse(pos, 4, k, code);
+- }
+- break;
+- default:
+- FDK_ASSERT(0);
+- }
+- return;
+-}
+diff --git a/libAACdec/src/usacdec_ace_d4t64.h b/libAACdec/src/usacdec_ace_d4t64.h
+deleted file mode 100644
+index 76bc3d9..0000000
+--- a/libAACdec/src/usacdec_ace_d4t64.h
++++ /dev/null
+@@ -1,117 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s):
+-
+- Description: ACELP
+-
+-*******************************************************************************/
+-
+-#ifndef USACDEC_ACE_D4T64_H
+-#define USACDEC_ACE_D4T64_H
+-
+-#include "common_fix.h"
+-
+-/* Data type definition for the fixed codebook vector */
+-#define FIXP_COD FIXP_SGL
+-#define FX_COD2FX_DBL(x) (FX_SGL2FX_DBL(x))
+-#define FX_DBL2FX_COD(x) FX_DBL2FX_SGL((x) + (FIXP_DBL)0x8000)
+-#define FX_SGL2FX_COD(x) (x)
+-#define COD_BITS FRACT_BITS
+-
+-void D_ACELP_decode_4t64(SHORT index[], int nbits, FIXP_COD code[]);
+-
+-#endif /* USACDEC_ACE_D4T64_H */
+diff --git a/libAACdec/src/usacdec_ace_ltp.cpp b/libAACdec/src/usacdec_ace_ltp.cpp
+deleted file mode 100644
+index 5964b49..0000000
+--- a/libAACdec/src/usacdec_ace_ltp.cpp
++++ /dev/null
+@@ -1,229 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Matthias Hildenbrand
+-
+- Description: USAC ACELP LTP filter
+-
+-*******************************************************************************/
+-
+-#include "usacdec_ace_ltp.h"
+-
+-#include "genericStds.h"
+-#include "common_fix.h"
+-
+-#define UP_SAMP 4
+-#define L_INTERPOL2 16
+-#define L_SUBFR 64
+-
+-#define A2 FL2FX_SGL(2 * 0.18f)
+-#define B FL2FX_SGL(0.64f)
+-
+-static const LONG Pred_lt4_inter4_2[UP_SAMP][L_INTERPOL2] = {
+- {(LONG)0x0000FFFC, (LONG)0x0008FFFC, (LONG)0xFFEB004C, (LONG)0xFF50014A,
+- (LONG)0xFDD90351, (LONG)0xFB2A06CD, (LONG)0xF6920D46, (LONG)0xEBB42B35,
+- (LONG)0x6D9EEF39, (LONG)0x0618FE0F, (LONG)0xFFE00131, (LONG)0xFE5501C5,
+- (LONG)0xFE5E015D, (LONG)0xFEF700B6, (LONG)0xFF920037, (LONG)0xFFEC0003},
+- {(LONG)0x0002FFF2, (LONG)0x0026FFBD, (LONG)0x005DFF98, (LONG)0x0055FFEF,
+- (LONG)0xFF89015F, (LONG)0xFD3A04E5, (LONG)0xF7D90DAA, (LONG)0xE67A50EE,
+- (LONG)0x50EEE67A, (LONG)0x0DAAF7D9, (LONG)0x04E5FD3A, (LONG)0x015FFF89,
+- (LONG)0xFFEF0055, (LONG)0xFF98005D, (LONG)0xFFBD0026, (LONG)0xFFF20002},
+- {(LONG)0x0003FFEC, (LONG)0x0037FF92, (LONG)0x00B6FEF7, (LONG)0x015DFE5E,
+- (LONG)0x01C5FE55, (LONG)0x0131FFE0, (LONG)0xFE0F0618, (LONG)0xEF396D9E,
+- (LONG)0x2B35EBB4, (LONG)0x0D46F692, (LONG)0x06CDFB2A, (LONG)0x0351FDD9,
+- (LONG)0x014AFF50, (LONG)0x004CFFEB, (LONG)0xFFFC0008, (LONG)0xFFFC0000},
+- {(LONG)0x0002FFF2, (LONG)0x002BFF9E, (LONG)0x00B9FECE, (LONG)0x01CFFD75,
+- (LONG)0x035EFBC1, (LONG)0x0521FA0C, (LONG)0x06AAF8C9, (LONG)0x07907852,
+- (LONG)0x0790F8C9, (LONG)0x06AAFA0C, (LONG)0x0521FBC1, (LONG)0x035EFD75,
+- (LONG)0x01CFFECE, (LONG)0x00B9FF9E, (LONG)0x002BFFF2, (LONG)0x00020000}};
+-
+-void Pred_lt4(FIXP_DBL exc[], /* in/out: excitation buffer */
+- int T0, /* input : integer pitch lag */
+- int frac /* input : fraction of lag in range 0..3 */
+-) {
+- int j;
+- FIXP_DBL *x;
+- const LONG *interpol;
+- FIXP_DBL L_sumb, L_sumt;
+-
+- x = &exc[-T0 - L_INTERPOL2 + 1];
+-
+- /* remap frac and x:
+- 0 -> 3 x (unchanged)
+- 1 -> 0 x--
+- 2 -> 1 x--
+- 3 -> 2 x--
+- */
+-
+- if (--frac < 0)
+- frac += UP_SAMP;
+- else
+- x--;
+-
+- j = L_SUBFR + 1;
+- do {
+- LONG filt;
+- FIXP_DBL x0, x1;
+- FIXP_DBL *xi = x++;
+- interpol = Pred_lt4_inter4_2[frac];
+- int i = 3;
+-
+- filt = *interpol++;
+- x0 = *xi++;
+- x1 = *xi++;
+- L_sumt = fMultDiv2(x0, (FIXP_SGL)((SHORT)(filt >> 16)));
+- L_sumb = fMultDiv2(x1, (FIXP_SGL)((SHORT)filt));
+- do {
+- filt = *interpol++;
+- x0 = *xi++;
+- x1 = *xi++;
+- L_sumt = fMultAddDiv2(L_sumt, x0, (FIXP_SGL)((SHORT)(filt >> 16)));
+- L_sumb = fMultAddDiv2(L_sumb, x1, (FIXP_SGL)((SHORT)filt));
+-
+- filt = *interpol++;
+- x0 = *xi++;
+- x1 = *xi++;
+- L_sumt = fMultAddDiv2(L_sumt, x0, (FIXP_SGL)((SHORT)(filt >> 16)));
+- L_sumb = fMultAddDiv2(L_sumb, x1, (FIXP_SGL)((SHORT)filt));
+-
+- filt = *interpol++;
+- x0 = *xi++;
+- x1 = *xi++;
+- L_sumt = fMultAddDiv2(L_sumt, x0, (FIXP_SGL)((SHORT)(filt >> 16)));
+- L_sumb = fMultAddDiv2(L_sumb, x1, (FIXP_SGL)((SHORT)filt));
+-
+- filt = *interpol++;
+- x0 = *xi++;
+- x1 = *xi++;
+- L_sumt = fMultAddDiv2(L_sumt, x0, (FIXP_SGL)((SHORT)(filt >> 16)));
+- L_sumb = fMultAddDiv2(L_sumb, x1, (FIXP_SGL)((SHORT)filt));
+-
+- filt = *interpol++;
+- x0 = *xi++;
+- x1 = *xi++;
+- L_sumt = fMultAddDiv2(L_sumt, x0, (FIXP_SGL)((SHORT)(filt >> 16)));
+- L_sumb = fMultAddDiv2(L_sumb, x1, (FIXP_SGL)((SHORT)filt));
+- } while (--i != 0);
+-
+- L_sumb <<= 1;
+- L_sumb = fAddSaturate(L_sumt << 1, L_sumb);
+- *exc++ = L_sumb;
+- } while (--j != 0);
+- return;
+-}
+-
+-void Pred_lt4_postfilter(FIXP_DBL exc[] /* in/out: excitation buffer */
+-) {
+- /*
+- exc[i] = A*exc[i-1] + B*exc[i] + A*exc[i+1]
+- exc[i+1] = A*exc[i] + B*exc[i+1] + A*exc[i+2] ; i = 0:2:62
+- */
+- int i;
+- FIXP_DBL sum0, sum1, a_exc0, a_exc1;
+- a_exc0 = fMultDiv2(A2, exc[-1]);
+- a_exc1 = fMultDiv2(A2, exc[0]);
+-
+- /* ARM926: 22 cycles/iteration */
+- for (i = 0; i < L_SUBFR; i += 2) {
+- sum0 = a_exc0 + fMult(B, exc[i]);
+- sum1 = a_exc1 + fMult(B, exc[i + 1]);
+- a_exc0 = fMultDiv2(A2, exc[i + 1]);
+- a_exc1 = fMultDiv2(A2, exc[i + 2]);
+- exc[i] = sum0 + a_exc0;
+- exc[i + 1] = sum1 + a_exc1;
+- }
+- return;
+-}
+diff --git a/libAACdec/src/usacdec_ace_ltp.h b/libAACdec/src/usacdec_ace_ltp.h
+deleted file mode 100644
+index 5128acd..0000000
+--- a/libAACdec/src/usacdec_ace_ltp.h
++++ /dev/null
+@@ -1,128 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Matthias Hildenbrand
+-
+- Description: USAC ACELP LTP filter
+-
+-*******************************************************************************/
+-
+-#ifndef USACDEC_ACE_LTP_H
+-#define USACDEC_ACE_LTP_H
+-
+-#include "common_fix.h"
+-
+-/**
+- * \brief Compute the initial adaptive codebook excitation v'(n) by
+- * interpolating the past excitation vector u'(n).
+- * \param exc points to adaptive codebook of current subframe (input/output)
+- * \param T0 integer part of decoded pitch lag (input)
+- * \param frac fractional part of decoded pitch lag (0..3) (input)
+- */
+-void Pred_lt4(FIXP_DBL exc[], /* in/out: excitation buffer */
+- int T0, /* input : integer pitch lag */
+- int frac /* input : fraction of lag */
+-);
+-
+-/**
+- * \brief Compute the adaptive codebook excitation v(n) in case of
+- * ltp_filtering_flag == 0.
+- * \param exc points to adaptive codebook of current subframe (input/output)
+- */
+-void Pred_lt4_postfilter(FIXP_DBL exc[] /* in/out: excitation buffer */
+-);
+-
+-#endif /* USACDEC_ACE_LTP_H */
+diff --git a/libAACdec/src/usacdec_acelp.cpp b/libAACdec/src/usacdec_acelp.cpp
+deleted file mode 100644
+index a606459..0000000
+--- a/libAACdec/src/usacdec_acelp.cpp
++++ /dev/null
+@@ -1,1296 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Matthias Hildenbrand
+-
+- Description: USAC ACELP frame decoder
+-
+-*******************************************************************************/
+-
+-#include "usacdec_acelp.h"
+-
+-#include "usacdec_ace_d4t64.h"
+-#include "usacdec_ace_ltp.h"
+-#include "usacdec_rom.h"
+-#include "usacdec_lpc.h"
+-#include "genericStds.h"
+-
+-#define PIT_FR2_12k8 128 /* Minimum pitch lag with resolution 1/2 */
+-#define PIT_FR1_12k8 160 /* Minimum pitch lag with resolution 1 */
+-#define TILT_CODE2 \
+- FL2FXCONST_SGL(0.3f * 2.0f) /* ACELP code pre-emphasis factor ( *2 ) */
+-#define PIT_SHARP \
+- FL2FXCONST_SGL(0.85f) /* pitch sharpening factor */
+-#define PREEMPH_FAC \
+- FL2FXCONST_SGL(0.68f) /* ACELP synth pre-emphasis factor */
+-
+-#define ACELP_HEADROOM 1
+-#define ACELP_OUTSCALE (MDCT_OUT_HEADROOM - ACELP_HEADROOM)
+-
+-/**
+- * \brief Calculate pre-emphasis (1 - mu z^-1) on input signal.
+- * \param[in] in pointer to input signal; in[-1] is also needed.
+- * \param[out] out pointer to output signal.
+- * \param[in] L length of filtering.
+- */
+-/* static */
+-void E_UTIL_preemph(const FIXP_DBL *in, FIXP_DBL *out, INT L) {
+- int i;
+-
+- for (i = 0; i < L; i++) {
+- out[i] = in[i] - fMult(PREEMPH_FAC, in[i - 1]);
+- }
+-
+- return;
+-}
+-
+-/**
+- * \brief Calculate de-emphasis 1/(1 - TILT_CODE z^-1) on innovative codebook
+- * vector.
+- * \param[in,out] x innovative codebook vector.
+- */
+-static void Preemph_code(
+- FIXP_COD x[] /* (i/o) : input signal overwritten by the output */
+-) {
+- int i;
+- FIXP_DBL L_tmp;
+-
+- /* ARM926: 12 cycles per sample */
+- for (i = L_SUBFR - 1; i > 0; i--) {
+- L_tmp = FX_COD2FX_DBL(x[i]);
+- L_tmp -= fMultDiv2(x[i - 1], TILT_CODE2);
+- x[i] = FX_DBL2FX_COD(L_tmp);
+- }
+-}
+-
+-/**
+- * \brief Apply pitch sharpener to the innovative codebook vector.
+- * \param[in,out] x innovative codebook vector.
+- * \param[in] pit_lag decoded pitch lag.
+- */
+-static void Pit_shrp(
+- FIXP_COD x[], /* in/out: impulse response (or algebraic code) */
+- int pit_lag /* input : pitch lag */
+-) {
+- int i;
+- FIXP_DBL L_tmp;
+-
+- for (i = pit_lag; i < L_SUBFR; i++) {
+- L_tmp = FX_COD2FX_DBL(x[i]);
+- L_tmp += fMult(x[i - pit_lag], PIT_SHARP);
+- x[i] = FX_DBL2FX_COD(L_tmp);
+- }
+-
+- return;
+-}
+-
+- /**
+- * \brief Calculate Quantized codebook gain, Quantized pitch gain and unbiased
+- * Innovative code vector energy.
+- * \param[in] index index of quantizer.
+- * \param[in] code innovative code vector with exponent = SF_CODE.
+- * \param[out] gain_pit Quantized pitch gain g_p with exponent = SF_GAIN_P.
+- * \param[out] gain_code Quantized codebook gain g_c.
+- * \param[in] mean_ener mean_ener defined in open-loop (2 bits), exponent = 7.
+- * \param[out] E_code unbiased innovative code vector energy.
+- * \param[out] E_code_e exponent of unbiased innovative code vector energy.
+- */
+-
+-#define SF_MEAN_ENER_LG10 9
+-
+-/* pow(10.0, {18, 30, 42, 54}/20.0) /(float)(1<<SF_MEAN_ENER_LG10) */
+-static const FIXP_DBL pow_10_mean_energy[4] = {0x01fc5ebd, 0x07e7db92,
+- 0x1f791f65, 0x7d4bfba3};
+-
+-static void D_gain2_plus(int index, FIXP_COD code[], FIXP_SGL *gain_pit,
+- FIXP_DBL *gain_code, int mean_ener_bits, int bfi,
+- FIXP_SGL *past_gpit, FIXP_DBL *past_gcode,
+- FIXP_DBL *pEner_code, int *pEner_code_e) {
+- FIXP_DBL Ltmp;
+- FIXP_DBL gcode0, gcode_inov;
+- INT gcode0_e, gcode_inov_e;
+- int i;
+-
+- FIXP_DBL ener_code;
+- INT ener_code_e;
+-
+- /* ener_code = sum(code[]^2) */
+- ener_code = FIXP_DBL(0);
+- for (i = 0; i < L_SUBFR; i++) {
+- ener_code += fPow2Div2(code[i]);
+- }
+-
+- ener_code_e = fMax(fNorm(ener_code) - 1, 0);
+- ener_code <<= ener_code_e;
+- ener_code_e = 2 * SF_CODE + 1 - ener_code_e;
+-
+- /* export energy of code for calc_period_factor() */
+- *pEner_code = ener_code;
+- *pEner_code_e = ener_code_e;
+-
+- ener_code += scaleValue(FL2FXCONST_DBL(0.01f), -ener_code_e);
+-
+- /* ener_code *= 1/L_SUBFR, and make exponent even (because of square root
+- * below). */
+- if (ener_code_e & 1) {
+- ener_code_e -= 5;
+- ener_code >>= 1;
+- } else {
+- ener_code_e -= 6;
+- }
+- gcode_inov = invSqrtNorm2(ener_code, &gcode0_e);
+- gcode_inov_e = gcode0_e - (ener_code_e >> 1);
+-
+- if (bfi) {
+- FIXP_DBL tgcode;
+- FIXP_SGL tgpit;
+-
+- tgpit = *past_gpit;
+-
+- if (tgpit > FL2FXCONST_SGL(0.95f / (1 << SF_GAIN_P))) {
+- tgpit = FL2FXCONST_SGL(0.95f / (1 << SF_GAIN_P));
+- } else if (tgpit < FL2FXCONST_SGL(0.5f / (1 << SF_GAIN_P))) {
+- tgpit = FL2FXCONST_SGL(0.5f / (1 << SF_GAIN_P));
+- }
+- *gain_pit = tgpit;
+- tgpit = FX_DBL2FX_SGL(fMult(tgpit, FL2FXCONST_DBL(0.95f)));
+- *past_gpit = tgpit;
+-
+- tgpit = FL2FXCONST_SGL(1.4f / (1 << SF_GAIN_P)) - tgpit;
+- tgcode = fMult(*past_gcode, tgpit) << SF_GAIN_P;
+- *gain_code = scaleValue(fMult(tgcode, gcode_inov), gcode_inov_e);
+- *past_gcode = tgcode;
+-
+- return;
+- }
+-
+- /*-------------- Decode gains ---------------*/
+- /*
+- gcode0 = pow(10.0, (float)mean_ener/20.0);
+- gcode0 = gcode0 / sqrt(ener_code/L_SUBFR);
+- */
+- gcode0 = pow_10_mean_energy[mean_ener_bits];
+- gcode0 = fMultDiv2(gcode0, gcode_inov);
+- gcode0_e = gcode0_e + SF_MEAN_ENER_LG10 - (ener_code_e >> 1) + 1;
+-
+- i = index << 1;
+- *gain_pit = fdk_t_qua_gain7b[i]; /* adaptive codebook gain */
+- /* t_qua_gain[ind2p1] : fixed codebook gain correction factor */
+- Ltmp = fMult(fdk_t_qua_gain7b[i + 1], gcode0);
+- *gain_code = scaleValue(Ltmp, gcode0_e - SF_GAIN_C + SF_QUA_GAIN7B);
+-
+- /* update bad frame handler */
+- *past_gpit = *gain_pit;
+-
+- /*--------------------------------------------------------
+- past_gcode = gain_code/gcode_inov
+- --------------------------------------------------------*/
+- {
+- FIXP_DBL gcode_m;
+- INT gcode_e;
+-
+- gcode_m = fDivNormHighPrec(Ltmp, gcode_inov, &gcode_e);
+- gcode_e += (gcode0_e - SF_GAIN_C + SF_QUA_GAIN7B) - (gcode_inov_e);
+- *past_gcode = scaleValue(gcode_m, gcode_e);
+- }
+-}
+-
+-/**
+- * \brief Calculate period/voicing factor r_v
+- * \param[in] exc pitch excitation.
+- * \param[in] gain_pit gain of pitch g_p.
+- * \param[in] gain_code gain of code g_c.
+- * \param[in] gain_code_e exponent of gain of code.
+- * \param[in] ener_code unbiased innovative code vector energy.
+- * \param[in] ener_code_e exponent of unbiased innovative code vector energy.
+- * \return period/voice factor r_v (-1=unvoiced to 1=voiced), exponent SF_PFAC.
+- */
+-static FIXP_DBL calc_period_factor(FIXP_DBL exc[], FIXP_SGL gain_pit,
+- FIXP_DBL gain_code, FIXP_DBL ener_code,
+- int ener_code_e) {
+- int ener_exc_e, L_tmp_e, s = 0;
+- FIXP_DBL ener_exc, L_tmp;
+- FIXP_DBL period_fac;
+-
+- /* energy of pitch excitation */
+- ener_exc = (FIXP_DBL)0;
+- for (int i = 0; i < L_SUBFR; i++) {
+- ener_exc += fPow2Div2(exc[i]) >> s;
+- if (ener_exc >= FL2FXCONST_DBL(0.5f)) {
+- ener_exc >>= 1;
+- s++;
+- }
+- }
+-
+- ener_exc_e = fNorm(ener_exc);
+- ener_exc = fMult(ener_exc << ener_exc_e, fPow2(gain_pit));
+- if (ener_exc != (FIXP_DBL)0) {
+- ener_exc_e = 2 * SF_EXC + 1 + 2 * SF_GAIN_P - ener_exc_e + s;
+- } else {
+- ener_exc_e = 0;
+- }
+-
+- /* energy of innovative code excitation */
+- /* L_tmp = ener_code * gain_code*gain_code; */
+- L_tmp_e = fNorm(gain_code);
+- L_tmp = fPow2(gain_code << L_tmp_e);
+- L_tmp = fMult(ener_code, L_tmp);
+- L_tmp_e = 2 * SF_GAIN_C + ener_code_e - 2 * L_tmp_e;
+-
+- /* Find common exponent */
+- {
+- FIXP_DBL num, den;
+- int exp_diff;
+-
+- exp_diff = ener_exc_e - L_tmp_e;
+- if (exp_diff >= 0) {
+- ener_exc >>= 1;
+- if (exp_diff <= DFRACT_BITS - 2) {
+- L_tmp >>= exp_diff + 1;
+- } else {
+- L_tmp = (FIXP_DBL)0;
+- }
+- den = ener_exc + L_tmp;
+- if (ener_exc_e < DFRACT_BITS - 1) {
+- den += scaleValue(FL2FXCONST_DBL(0.01f), -ener_exc_e - 1);
+- }
+- } else {
+- if (exp_diff >= -(DFRACT_BITS - 2)) {
+- ener_exc >>= 1 - exp_diff;
+- } else {
+- ener_exc = (FIXP_DBL)0;
+- }
+- L_tmp >>= 1;
+- den = ener_exc + L_tmp;
+- if (L_tmp_e < DFRACT_BITS - 1) {
+- den += scaleValue(FL2FXCONST_DBL(0.01f), -L_tmp_e - 1);
+- }
+- }
+- num = (ener_exc - L_tmp);
+- num >>= SF_PFAC;
+-
+- if (den > (FIXP_DBL)0) {
+- if (ener_exc > L_tmp) {
+- period_fac = schur_div(num, den, 16);
+- } else {
+- period_fac = -schur_div(-num, den, 16);
+- }
+- } else {
+- period_fac = (FIXP_DBL)MAXVAL_DBL;
+- }
+- }
+-
+- /* exponent = SF_PFAC */
+- return period_fac;
+-}
+-
+-/*------------------------------------------------------------*
+- * noise enhancer *
+- * ~~~~~~~~~~~~~~ *
+- * - Enhance excitation on noise. (modify gain of code) *
+- * If signal is noisy and LPC filter is stable, move gain *
+- * of code 1.5 dB toward gain of code threshold. *
+- * This decrease by 3 dB noise energy variation. *
+- *------------------------------------------------------------*/
+-/**
+- * \brief Enhance excitation on noise. (modify gain of code)
+- * \param[in] gain_code Quantized codebook gain g_c, exponent = SF_GAIN_C.
+- * \param[in] period_fac periodicity factor, exponent = SF_PFAC.
+- * \param[in] stab_fac stability factor, exponent = SF_STAB.
+- * \param[in,out] p_gc_threshold modified gain of previous subframe.
+- * \return gain_code smoothed gain of code g_sc, exponent = SF_GAIN_C.
+- */
+-static FIXP_DBL
+-noise_enhancer(/* (o) : smoothed gain g_sc SF_GAIN_C */
+- FIXP_DBL gain_code, /* (i) : Quantized codebook gain SF_GAIN_C */
+- FIXP_DBL period_fac, /* (i) : periodicity factor (-1=unvoiced to
+- 1=voiced), SF_PFAC */
+- FIXP_SGL stab_fac, /* (i) : stability factor (0 <= ... < 1.0)
+- SF_STAB */
+- FIXP_DBL
+- *p_gc_threshold) /* (io): gain of code threshold SF_GAIN_C */
+-{
+- FIXP_DBL fac, L_tmp, gc_thres;
+-
+- gc_thres = *p_gc_threshold;
+-
+- L_tmp = gain_code;
+- if (L_tmp < gc_thres) {
+- L_tmp += fMultDiv2(gain_code,
+- FL2FXCONST_SGL(2.0 * 0.19f)); /* +1.5dB => *(1.0+0.19) */
+- if (L_tmp > gc_thres) {
+- L_tmp = gc_thres;
+- }
+- } else {
+- L_tmp = fMult(gain_code,
+- FL2FXCONST_SGL(1.0f / 1.19f)); /* -1.5dB => *10^(-1.5/20) */
+- if (L_tmp < gc_thres) {
+- L_tmp = gc_thres;
+- }
+- }
+- *p_gc_threshold = L_tmp;
+-
+- /* voicing factor lambda = 0.5*(1-period_fac) */
+- /* gain smoothing factor S_m = lambda*stab_fac (=fac)
+- = 0.5(stab_fac - stab_fac * period_fac) */
+- fac = (FX_SGL2FX_DBL(stab_fac) >> (SF_PFAC + 1)) -
+- fMultDiv2(stab_fac, period_fac);
+- /* fac_e = SF_PFAC + SF_STAB */
+- FDK_ASSERT(fac >= (FIXP_DBL)0);
+-
+- /* gain_code = (float)((fac*tmp) + ((1.0-fac)*gain_code)); */
+- gain_code = fMult(fac, L_tmp) -
+- fMult(FL2FXCONST_DBL(-1.0f / (1 << (SF_PFAC + SF_STAB))) + fac,
+- gain_code);
+- gain_code <<= (SF_PFAC + SF_STAB);
+-
+- return gain_code;
+-}
+-
+-/**
+- * \brief Update adaptive codebook u'(n) (exc)
+- * Enhance pitch of c(n) and build post-processed excitation u(n) (exc2)
+- * \param[in] code innovative codevector c(n), exponent = SF_CODE.
+- * \param[in,out] exc filtered adaptive codebook v(n), exponent = SF_EXC.
+- * \param[in] gain_pit adaptive codebook gain, exponent = SF_GAIN_P.
+- * \param[in] gain_code innovative codebook gain g_c, exponent = SF_GAIN_C.
+- * \param[in] gain_code_smoothed smoothed innov. codebook gain g_sc, exponent =
+- * SF_GAIN_C.
+- * \param[in] period_fac periodicity factor r_v, exponent = SF_PFAC.
+- * \param[out] exc2 post-processed excitation u(n), exponent = SF_EXC.
+- */
+-void BuildAdaptiveExcitation(
+- FIXP_COD code[], /* (i) : algebraic codevector c(n) Q9 */
+- FIXP_DBL exc[], /* (io): filtered adaptive codebook v(n) Q15 */
+- FIXP_SGL gain_pit, /* (i) : adaptive codebook gain g_p Q14 */
+- FIXP_DBL gain_code, /* (i) : innovative codebook gain g_c Q16 */
+- FIXP_DBL gain_code_smoothed, /* (i) : smoothed innov. codebook gain g_sc
+- Q16 */
+- FIXP_DBL period_fac, /* (i) : periodicity factor r_v Q15 */
+- FIXP_DBL exc2[] /* (o) : post-processed excitation u(n) Q15 */
+-) {
+-/* Note: code[L_SUBFR] and exc2[L_SUBFR] share the same memory!
+- If exc2[i] is written, code[i] will be destroyed!
+-*/
+-#define SF (SF_CODE + SF_GAIN_C + 1 - SF_EXC)
+-
+- int i;
+- FIXP_DBL tmp, cpe, code_smooth_prev, code_smooth;
+-
+- FIXP_COD code_i;
+- FIXP_DBL cpe_code_smooth, cpe_code_smooth_prev;
+-
+- /* cpe = (1+r_v)/8 * 2 ; ( SF = -1) */
+- cpe = (period_fac >> (2 - SF_PFAC)) + FL2FXCONST_DBL(0.25f);
+-
+- /* u'(n) */
+- tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P + 1); /* v(0)*g_p */
+- *exc++ = tmp + (fMultDiv2(code[0], gain_code) << SF);
+-
+- /* u(n) */
+- code_smooth_prev = fMultDiv2(*code++, gain_code_smoothed)
+- << SF; /* c(0) * g_sc */
+- code_i = *code++;
+- code_smooth = fMultDiv2(code_i, gain_code_smoothed) << SF; /* c(1) * g_sc */
+- tmp += code_smooth_prev; /* tmp = v(0)*g_p + c(0)*g_sc */
+- cpe_code_smooth = fMultDiv2(cpe, code_smooth);
+- *exc2++ = tmp - cpe_code_smooth;
+- cpe_code_smooth_prev = fMultDiv2(cpe, code_smooth_prev);
+-
+- i = L_SUBFR - 2;
+- do /* ARM926: 22 cycles per iteration */
+- {
+- /* u'(n) */
+- tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P + 1);
+- *exc++ = tmp + (fMultDiv2(code_i, gain_code) << SF);
+- /* u(n) */
+- tmp += code_smooth; /* += g_sc * c(i) */
+- tmp -= cpe_code_smooth_prev;
+- cpe_code_smooth_prev = cpe_code_smooth;
+- code_i = *code++;
+- code_smooth = fMultDiv2(code_i, gain_code_smoothed) << SF;
+- cpe_code_smooth = fMultDiv2(cpe, code_smooth);
+- *exc2++ = tmp - cpe_code_smooth; /* tmp - c_pe * g_sc * c(i+1) */
+- } while (--i != 0);
+-
+- /* u'(n) */
+- tmp = fMultDiv2(*exc, gain_pit) << (SF_GAIN_P + 1);
+- *exc = tmp + (fMultDiv2(code_i, gain_code) << SF);
+- /* u(n) */
+- tmp += code_smooth;
+- tmp -= cpe_code_smooth_prev;
+- *exc2++ = tmp;
+-
+- return;
+-}
+-
+-/**
+- * \brief Interpolate LPC vector in LSP domain for current subframe and convert
+- * to LP domain
+- * \param[in] lsp_old LPC vector (LSP domain) corresponding to the beginning of
+- * current ACELP frame.
+- * \param[in] lsp_new LPC vector (LSP domain) corresponding to the end of
+- * current ACELP frame.
+- * \param[in] subfr_nr number of current ACELP subframe 0..3.
+- * \param[in] nb_subfr total number of ACELP subframes in this frame.
+- * \param[out] A LP filter coefficients for current ACELP subframe, exponent =
+- * SF_A_COEFFS.
+- */
+-/* static */
+-void int_lpc_acelp(
+- const FIXP_LPC lsp_old[], /* input : LSPs from past frame */
+- const FIXP_LPC lsp_new[], /* input : LSPs from present frame */
+- int subfr_nr, int nb_subfr,
+- FIXP_LPC
+- A[], /* output: interpolated LP coefficients for current subframe */
+- INT *A_exp) {
+- int i;
+- FIXP_LPC lsp_interpol[M_LP_FILTER_ORDER];
+- FIXP_SGL fac_old, fac_new;
+-
+- FDK_ASSERT((nb_subfr == 3) || (nb_subfr == 4));
+-
+- fac_old = lsp_interpol_factor[nb_subfr & 0x1][(nb_subfr - 1) - subfr_nr];
+- fac_new = lsp_interpol_factor[nb_subfr & 0x1][subfr_nr];
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp_interpol[i] = FX_DBL2FX_LPC(
+- (fMultDiv2(lsp_old[i], fac_old) + fMultDiv2(lsp_new[i], fac_new)) << 1);
+- }
+-
+- E_LPC_f_lsp_a_conversion(lsp_interpol, A, A_exp);
+-
+- return;
+-}
+-
+-/**
+- * \brief Perform LP synthesis by filtering the post-processed excitation u(n)
+- * through the LP synthesis filter 1/A(z)
+- * \param[in] a LP filter coefficients, exponent = SF_A_COEFFS.
+- * \param[in] length length of input/output signal.
+- * \param[in] x post-processed excitation u(n).
+- * \param[in,out] y LP synthesis signal and filter memory
+- * y[-M_LP_FILTER_ORDER..-1].
+- */
+-
+-/* static */
+-void Syn_filt(const FIXP_LPC a[], /* (i) : a[m] prediction coefficients Q12 */
+- const INT a_exp,
+- INT length, /* (i) : length of input/output signal (64|128) */
+- FIXP_DBL x[], /* (i) : input signal Qx */
+- FIXP_DBL y[] /* (i/o) : filter states / output signal Qx-s*/
+-) {
+- int i, j;
+- FIXP_DBL L_tmp;
+-
+- for (i = 0; i < length; i++) {
+- L_tmp = (FIXP_DBL)0;
+-
+- for (j = 0; j < M_LP_FILTER_ORDER; j++) {
+- L_tmp -= fMultDiv2(a[j], y[i - (j + 1)]) >> (LP_FILTER_SCALE - 1);
+- }
+-
+- L_tmp = scaleValue(L_tmp, a_exp + LP_FILTER_SCALE);
+- y[i] = fAddSaturate(L_tmp, x[i]);
+- }
+-
+- return;
+-}
+-
+-/**
+- * \brief Calculate de-emphasis 1/(1 - mu z^-1) on input signal.
+- * \param[in] x input signal.
+- * \param[out] y output signal.
+- * \param[in] L length of signal.
+- * \param[in,out] mem memory (signal[-1]).
+- */
+-/* static */
+-void Deemph(FIXP_DBL *x, FIXP_DBL *y, int L, FIXP_DBL *mem) {
+- int i;
+- FIXP_DBL yi = *mem;
+-
+- for (i = 0; i < L; i++) {
+- FIXP_DBL xi = x[i] >> 1;
+- xi = fMultAddDiv2(xi, PREEMPH_FAC, yi);
+- yi = SATURATE_LEFT_SHIFT(xi, 1, 32);
+- y[i] = yi;
+- }
+- *mem = yi;
+- return;
+-}
+-
+-/**
+- * \brief Compute the LP residual by filtering the input speech through the
+- * analysis filter A(z).
+- * \param[in] a LP filter coefficients, exponent = SF_A_COEFFS
+- * \param[in] x input signal (note that values x[-m..-1] are needed), exponent =
+- * SF_SYNTH
+- * \param[out] y output signal (residual), exponent = SF_EXC
+- * \param[in] l length of filtering
+- */
+-/* static */
+-void E_UTIL_residu(const FIXP_LPC *a, const INT a_exp, FIXP_DBL *x, FIXP_DBL *y,
+- INT l) {
+- FIXP_DBL s;
+- INT i, j;
+-
+- /* (note that values x[-m..-1] are needed) */
+- for (i = 0; i < l; i++) {
+- s = (FIXP_DBL)0;
+-
+- for (j = 0; j < M_LP_FILTER_ORDER; j++) {
+- s += fMultDiv2(a[j], x[i - j - 1]) >> (LP_FILTER_SCALE - 1);
+- }
+-
+- s = scaleValue(s, a_exp + LP_FILTER_SCALE);
+- y[i] = fAddSaturate(s, x[i]);
+- }
+-
+- return;
+-}
+-
+-/* use to map subfr number to number of bits used for acb_index */
+-static const UCHAR num_acb_idx_bits_table[2][NB_SUBFR] = {
+- {9, 6, 9, 6}, /* coreCoderFrameLength == 1024 */
+- {9, 6, 6, 0} /* coreCoderFrameLength == 768 */
+-};
+-
+-static int DecodePitchLag(HANDLE_FDK_BITSTREAM hBs,
+- const UCHAR num_acb_idx_bits,
+- const int PIT_MIN, /* TMIN */
+- const int PIT_FR2, /* TFR2 */
+- const int PIT_FR1, /* TFR1 */
+- const int PIT_MAX, /* TMAX */
+- int *pT0, int *pT0_frac, int *pT0_min, int *pT0_max) {
+- int acb_idx;
+- int error = 0;
+- int T0, T0_frac;
+-
+- FDK_ASSERT((num_acb_idx_bits == 9) || (num_acb_idx_bits == 6));
+-
+- acb_idx = FDKreadBits(hBs, num_acb_idx_bits);
+-
+- if (num_acb_idx_bits == 6) {
+- /* When the pitch value is encoded on 6 bits, a pitch resolution of 1/4 is
+- always used in the range [T1-8, T1+7.75], where T1 is nearest integer to
+- the fractional pitch lag of the previous subframe.
+- */
+- T0 = *pT0_min + acb_idx / 4;
+- T0_frac = acb_idx & 0x3;
+- } else { /* num_acb_idx_bits == 9 */
+- /* When the pitch value is encoded on 9 bits, a fractional pitch delay is
+- used with resolutions 0.25 in the range [TMIN, TFR2-0.25], resolutions
+- 0.5 in the range [TFR2, TFR1-0.5], and integers only in the range [TFR1,
+- TMAX]. NOTE: for small sampling rates TMAX can get smaller than TFR1.
+- */
+- int T0_min, T0_max;
+-
+- if (acb_idx < (PIT_FR2 - PIT_MIN) * 4) {
+- /* first interval with 0.25 pitch resolution */
+- T0 = PIT_MIN + (acb_idx / 4);
+- T0_frac = acb_idx & 0x3;
+- } else if (acb_idx < ((PIT_FR2 - PIT_MIN) * 4 + (PIT_FR1 - PIT_FR2) * 2)) {
+- /* second interval with 0.5 pitch resolution */
+- acb_idx -= (PIT_FR2 - PIT_MIN) * 4;
+- T0 = PIT_FR2 + (acb_idx / 2);
+- T0_frac = (acb_idx & 0x1) * 2;
+- } else {
+- /* third interval with 1.0 pitch resolution */
+- T0 = acb_idx + PIT_FR1 - ((PIT_FR2 - PIT_MIN) * 4) -
+- ((PIT_FR1 - PIT_FR2) * 2);
+- T0_frac = 0;
+- }
+- /* find T0_min and T0_max for subframe 1 or 3 */
+- T0_min = T0 - 8;
+- if (T0_min < PIT_MIN) {
+- T0_min = PIT_MIN;
+- }
+- T0_max = T0_min + 15;
+- if (T0_max > PIT_MAX) {
+- T0_max = PIT_MAX;
+- T0_min = T0_max - 15;
+- }
+- *pT0_min = T0_min;
+- *pT0_max = T0_max;
+- }
+- *pT0 = T0;
+- *pT0_frac = T0_frac;
+-
+- return error;
+-}
+-static void ConcealPitchLag(CAcelpStaticMem *acelp_mem, const int PIT_MAX,
+- int *pT0, int *pT0_frac) {
+- USHORT *pold_T0 = &acelp_mem->old_T0;
+- UCHAR *pold_T0_frac = &acelp_mem->old_T0_frac;
+-
+- if ((int)*pold_T0 >= PIT_MAX) {
+- *pold_T0 = (UCHAR)(PIT_MAX - 5);
+- }
+- *pT0 = (int)*pold_T0;
+- *pT0_frac = (int)*pold_T0_frac;
+-}
+-
+-static UCHAR tab_coremode2nbits[8] = {20, 28, 36, 44, 52, 64, 12, 16};
+-
+-static int MapCoreMode2NBits(int core_mode) {
+- return (int)tab_coremode2nbits[core_mode];
+-}
+-
+-void CLpd_AcelpDecode(CAcelpStaticMem *acelp_mem, INT i_offset,
+- const FIXP_LPC lsp_old[M_LP_FILTER_ORDER],
+- const FIXP_LPC lsp_new[M_LP_FILTER_ORDER],
+- FIXP_SGL stab_fac, CAcelpChannelData *pAcelpData,
+- INT numLostSubframes, int lastLpcLost, int frameCnt,
+- FIXP_DBL synth[], int pT[], FIXP_DBL *pit_gain,
+- INT coreCoderFrameLength) {
+- int i_subfr, subfr_nr, l_div, T;
+- int T0 = -1, T0_frac = -1; /* mark invalid */
+-
+- int pit_gain_index = 0;
+-
+- const int PIT_MAX = PIT_MAX_12k8 + (6 * i_offset); /* maximum pitch lag */
+-
+- FIXP_COD *code;
+- FIXP_DBL *exc2;
+- FIXP_DBL *syn;
+- FIXP_DBL *exc;
+- FIXP_LPC A[M_LP_FILTER_ORDER];
+- INT A_exp;
+-
+- FIXP_DBL period_fac;
+- FIXP_SGL gain_pit;
+- FIXP_DBL gain_code, gain_code_smooth, Ener_code;
+- int Ener_code_e;
+- int n;
+- int bfi = (numLostSubframes > 0) ? 1 : 0;
+-
+- C_ALLOC_SCRATCH_START(
+- exc_buf, FIXP_DBL,
+- PIT_MAX_MAX + L_INTERPOL + L_DIV + 1); /* 411 + 17 + 256 + 1 = 685 */
+- C_ALLOC_SCRATCH_START(syn_buf, FIXP_DBL,
+- M_LP_FILTER_ORDER + L_DIV); /* 16 + 256 = 272 */
+- /* use same memory for code[L_SUBFR] and exc2[L_SUBFR] */
+- C_ALLOC_SCRATCH_START(tmp_buf, FIXP_DBL, L_SUBFR); /* 64 */
+- /* make sure they don't overlap if they are accessed alternatingly in
+- * BuildAdaptiveExcitation() */
+-#if (COD_BITS == FRACT_BITS)
+- code = (FIXP_COD *)(tmp_buf + L_SUBFR / 2);
+-#elif (COD_BITS == DFRACT_BITS)
+- code = (FIXP_COD *)tmp_buf;
+-#endif
+- exc2 = (FIXP_DBL *)tmp_buf;
+-
+- syn = syn_buf + M_LP_FILTER_ORDER;
+- exc = exc_buf + PIT_MAX_MAX + L_INTERPOL;
+-
+- FDKmemcpy(syn_buf, acelp_mem->old_syn_mem,
+- M_LP_FILTER_ORDER * sizeof(FIXP_DBL));
+- FDKmemcpy(exc_buf, acelp_mem->old_exc_mem,
+- (PIT_MAX_MAX + L_INTERPOL) * sizeof(FIXP_DBL));
+-
+- FDKmemclear(exc_buf + (PIT_MAX_MAX + L_INTERPOL),
+- (L_DIV + 1) * sizeof(FIXP_DBL));
+-
+- l_div = coreCoderFrameLength / NB_DIV;
+-
+- for (i_subfr = 0, subfr_nr = 0; i_subfr < l_div;
+- i_subfr += L_SUBFR, subfr_nr++) {
+- /*-------------------------------------------------*
+- * - Decode pitch lag (T0 and T0_frac) *
+- *-------------------------------------------------*/
+- if (bfi) {
+- ConcealPitchLag(acelp_mem, PIT_MAX, &T0, &T0_frac);
+- } else {
+- T0 = (int)pAcelpData->T0[subfr_nr];
+- T0_frac = (int)pAcelpData->T0_frac[subfr_nr];
+- }
+-
+- /*-------------------------------------------------*
+- * - Find the pitch gain, the interpolation filter *
+- * and the adaptive codebook vector. *
+- *-------------------------------------------------*/
+- Pred_lt4(&exc[i_subfr], T0, T0_frac);
+-
+- if ((!bfi && pAcelpData->ltp_filtering_flag[subfr_nr] == 0) ||
+- (bfi && numLostSubframes == 1 && stab_fac < FL2FXCONST_SGL(0.25f))) {
+- /* find pitch excitation with lp filter: v'(n) => v(n) */
+- Pred_lt4_postfilter(&exc[i_subfr]);
+- }
+-
+- /*-------------------------------------------------------*
+- * - Decode innovative codebook. *
+- * - Add the fixed-gain pitch contribution to code[]. *
+- *-------------------------------------------------------*/
+- if (bfi) {
+- for (n = 0; n < L_SUBFR; n++) {
+- code[n] =
+- FX_SGL2FX_COD((FIXP_SGL)E_UTIL_random(&acelp_mem->seed_ace)) >> 4;
+- }
+- } else {
+- int nbits = MapCoreMode2NBits((int)pAcelpData->acelp_core_mode);
+- D_ACELP_decode_4t64(pAcelpData->icb_index[subfr_nr], nbits, &code[0]);
+- }
+-
+- T = T0;
+- if (T0_frac > 2) {
+- T += 1;
+- }
+-
+- Preemph_code(code);
+- Pit_shrp(code, T);
+-
+- /* Output pitch lag for bass post-filter */
+- if (T > PIT_MAX) {
+- pT[subfr_nr] = PIT_MAX;
+- } else {
+- pT[subfr_nr] = T;
+- }
+- D_gain2_plus(
+- pAcelpData->gains[subfr_nr],
+- code, /* (i) : Innovative code vector, exponent = SF_CODE */
+- &gain_pit, /* (o) : Quantized pitch gain, exponent = SF_GAIN_P */
+- &gain_code, /* (o) : Quantized codebook gain */
+- pAcelpData
+- ->mean_energy, /* (i) : mean_ener defined in open-loop (2 bits) */
+- bfi, &acelp_mem->past_gpit, &acelp_mem->past_gcode,
+- &Ener_code, /* (o) : Innovative code vector energy */
+- &Ener_code_e); /* (o) : Innovative code vector energy exponent */
+-
+- pit_gain[pit_gain_index++] = FX_SGL2FX_DBL(gain_pit);
+-
+- /* calc periodicity factor r_v */
+- period_fac =
+- calc_period_factor(/* (o) : factor (-1=unvoiced to 1=voiced) */
+- &exc[i_subfr], /* (i) : pitch excitation, exponent =
+- SF_EXC */
+- gain_pit, /* (i) : gain of pitch, exponent =
+- SF_GAIN_P */
+- gain_code, /* (i) : gain of code */
+- Ener_code, /* (i) : Energy of code[] */
+- Ener_code_e); /* (i) : Exponent of energy of code[]
+- */
+-
+- if (lastLpcLost && frameCnt == 0) {
+- if (gain_pit > FL2FXCONST_SGL(1.0f / (1 << SF_GAIN_P))) {
+- gain_pit = FL2FXCONST_SGL(1.0f / (1 << SF_GAIN_P));
+- }
+- }
+-
+- gain_code_smooth =
+- noise_enhancer(/* (o) : smoothed gain g_sc exponent = SF_GAIN_C */
+- gain_code, /* (i) : Quantized codebook gain */
+- period_fac, /* (i) : periodicity factor (-1=unvoiced to
+- 1=voiced) */
+- stab_fac, /* (i) : stability factor (0 <= ... < 1),
+- exponent = 1 */
+- &acelp_mem->gc_threshold);
+-
+- /* Compute adaptive codebook update u'(n), pitch enhancement c'(n) and
+- * post-processed excitation u(n). */
+- BuildAdaptiveExcitation(code, exc + i_subfr, gain_pit, gain_code,
+- gain_code_smooth, period_fac, exc2);
+-
+- /* Interpolate filter coeffs for current subframe in lsp domain and convert
+- * to LP domain */
+- int_lpc_acelp(lsp_old, /* input : LSPs from past frame */
+- lsp_new, /* input : LSPs from present frame */
+- subfr_nr, /* input : ACELP subframe index */
+- coreCoderFrameLength / L_DIV,
+- A, /* output: LP coefficients of this subframe */
+- &A_exp);
+-
+- Syn_filt(A, /* (i) : a[m] prediction coefficients */
+- A_exp, L_SUBFR, /* (i) : length */
+- exc2, /* (i) : input signal */
+- &syn[i_subfr] /* (i/o) : filter states / output signal */
+- );
+-
+- } /* end of subframe loop */
+-
+- /* update pitch value for bfi procedure */
+- acelp_mem->old_T0_frac = T0_frac;
+- acelp_mem->old_T0 = T0;
+-
+- /* save old excitation and old synthesis memory for next ACELP frame */
+- FDKmemcpy(acelp_mem->old_exc_mem, exc + l_div - (PIT_MAX_MAX + L_INTERPOL),
+- sizeof(FIXP_DBL) * (PIT_MAX_MAX + L_INTERPOL));
+- FDKmemcpy(acelp_mem->old_syn_mem, syn_buf + l_div,
+- sizeof(FIXP_DBL) * M_LP_FILTER_ORDER);
+-
+- Deemph(syn, synth, l_div,
+- &acelp_mem->de_emph_mem); /* ref soft: mem = synth[-1] */
+-
+- scaleValues(synth, l_div, -ACELP_OUTSCALE);
+- acelp_mem->deemph_mem_wsyn = acelp_mem->de_emph_mem;
+-
+- C_ALLOC_SCRATCH_END(tmp_buf, FIXP_DBL, L_SUBFR);
+- C_ALLOC_SCRATCH_END(syn_buf, FIXP_DBL, M_LP_FILTER_ORDER + L_DIV);
+- C_ALLOC_SCRATCH_END(exc_buf, FIXP_DBL, PIT_MAX_MAX + L_INTERPOL + L_DIV + 1);
+- return;
+-}
+-
+-void CLpd_AcelpReset(CAcelpStaticMem *acelp) {
+- acelp->gc_threshold = (FIXP_DBL)0;
+-
+- acelp->past_gpit = (FIXP_SGL)0;
+- acelp->past_gcode = (FIXP_DBL)0;
+- acelp->old_T0 = 64;
+- acelp->old_T0_frac = 0;
+- acelp->deemph_mem_wsyn = (FIXP_DBL)0;
+- acelp->wsyn_rms = (FIXP_DBL)0;
+- acelp->seed_ace = 0;
+-}
+-
+-/* TCX time domain concealment */
+-/* Compare to figure 13a on page 54 in 3GPP TS 26.290 */
+-void CLpd_TcxTDConceal(CAcelpStaticMem *acelp_mem, SHORT *pitch,
+- const FIXP_LPC lsp_old[M_LP_FILTER_ORDER],
+- const FIXP_LPC lsp_new[M_LP_FILTER_ORDER],
+- const FIXP_SGL stab_fac, INT nLostSf, FIXP_DBL synth[],
+- INT coreCoderFrameLength, UCHAR last_tcx_noise_factor) {
+- /* repeat past excitation with pitch from previous decoded TCX frame */
+- C_ALLOC_SCRATCH_START(
+- exc_buf, FIXP_DBL,
+- PIT_MAX_MAX + L_INTERPOL + L_DIV); /* 411 + 17 + 256 + 1 = */
+- C_ALLOC_SCRATCH_START(syn_buf, FIXP_DBL,
+- M_LP_FILTER_ORDER + L_DIV); /* 256 + 16 = */
+- /* += */
+- FIXP_DBL ns_buf[L_DIV + 1];
+- FIXP_DBL *syn = syn_buf + M_LP_FILTER_ORDER;
+- FIXP_DBL *exc = exc_buf + PIT_MAX_MAX + L_INTERPOL;
+- FIXP_DBL *ns = ns_buf + 1;
+- FIXP_DBL tmp, fact_exc;
+- INT T = fMin(*pitch, (SHORT)PIT_MAX_MAX);
+- int i, i_subfr, subfr_nr;
+- int lDiv = coreCoderFrameLength / NB_DIV;
+-
+- FDKmemcpy(syn_buf, acelp_mem->old_syn_mem,
+- M_LP_FILTER_ORDER * sizeof(FIXP_DBL));
+- FDKmemcpy(exc_buf, acelp_mem->old_exc_mem,
+- (PIT_MAX_MAX + L_INTERPOL) * sizeof(FIXP_DBL));
+-
+- /* if we lost all packets (i.e. 1 packet of TCX-20 ms, 2 packets of
+- the TCX-40 ms or 4 packets of the TCX-80ms), we lost the whole
+- coded frame extrapolation strategy: repeat lost excitation and
+- use extrapolated LSFs */
+-
+- /* AMR-WB+ like TCX TD concealment */
+-
+- /* number of lost frame cmpt */
+- if (nLostSf < 2) {
+- fact_exc = FL2FXCONST_DBL(0.8f);
+- } else {
+- fact_exc = FL2FXCONST_DBL(0.4f);
+- }
+-
+- /* repeat past excitation */
+- for (i = 0; i < lDiv; i++) {
+- exc[i] = fMult(fact_exc, exc[i - T]);
+- }
+-
+- tmp = fMult(fact_exc, acelp_mem->wsyn_rms);
+- acelp_mem->wsyn_rms = tmp;
+-
+- /* init deemph_mem_wsyn */
+- acelp_mem->deemph_mem_wsyn = exc[-1];
+-
+- ns[-1] = acelp_mem->deemph_mem_wsyn;
+-
+- for (i_subfr = 0, subfr_nr = 0; i_subfr < lDiv;
+- i_subfr += L_SUBFR, subfr_nr++) {
+- FIXP_DBL tRes[L_SUBFR];
+- FIXP_LPC A[M_LP_FILTER_ORDER];
+- INT A_exp;
+-
+- /* interpolate LPC coefficients */
+- int_lpc_acelp(lsp_old, lsp_new, subfr_nr, lDiv / L_SUBFR, A, &A_exp);
+-
+- Syn_filt(A, /* (i) : a[m] prediction coefficients */
+- A_exp, L_SUBFR, /* (i) : length */
+- &exc[i_subfr], /* (i) : input signal */
+- &syn[i_subfr] /* (i/o) : filter states / output signal */
+- );
+-
+- E_LPC_a_weight(
+- A, A,
+- M_LP_FILTER_ORDER); /* overwrite A as it is not needed any longer */
+-
+- E_UTIL_residu(A, A_exp, &syn[i_subfr], tRes, L_SUBFR);
+-
+- Deemph(tRes, &ns[i_subfr], L_SUBFR, &acelp_mem->deemph_mem_wsyn);
+-
+- /* Amplitude limiter (saturate at wsyn_rms) */
+- for (i = i_subfr; i < i_subfr + L_SUBFR; i++) {
+- if (ns[i] > tmp) {
+- ns[i] = tmp;
+- } else {
+- if (ns[i] < -tmp) {
+- ns[i] = -tmp;
+- }
+- }
+- }
+-
+- E_UTIL_preemph(&ns[i_subfr], tRes, L_SUBFR);
+-
+- Syn_filt(A, /* (i) : a[m] prediction coefficients */
+- A_exp, L_SUBFR, /* (i) : length */
+- tRes, /* (i) : input signal */
+- &syn[i_subfr] /* (i/o) : filter states / output signal */
+- );
+-
+- FDKmemmove(&synth[i_subfr], &syn[i_subfr], L_SUBFR * sizeof(FIXP_DBL));
+- }
+-
+- /* save old excitation and old synthesis memory for next ACELP frame */
+- FDKmemcpy(acelp_mem->old_exc_mem, exc + lDiv - (PIT_MAX_MAX + L_INTERPOL),
+- sizeof(FIXP_DBL) * (PIT_MAX_MAX + L_INTERPOL));
+- FDKmemcpy(acelp_mem->old_syn_mem, syn_buf + lDiv,
+- sizeof(FIXP_DBL) * M_LP_FILTER_ORDER);
+- acelp_mem->de_emph_mem = acelp_mem->deemph_mem_wsyn;
+-
+- C_ALLOC_SCRATCH_END(syn_buf, FIXP_DBL, M_LP_FILTER_ORDER + L_DIV);
+- C_ALLOC_SCRATCH_END(exc_buf, FIXP_DBL, PIT_MAX_MAX + L_INTERPOL + L_DIV);
+-}
+-
+-void Acelp_PreProcessing(FIXP_DBL *synth_buf, FIXP_DBL *old_synth, INT *pitch,
+- INT *old_T_pf, FIXP_DBL *pit_gain,
+- FIXP_DBL *old_gain_pf, INT samplingRate, INT *i_offset,
+- INT coreCoderFrameLength, INT synSfd,
+- INT nbSubfrSuperfr) {
+- int n;
+-
+- /* init beginning of synth_buf with old synthesis from previous frame */
+- FDKmemcpy(synth_buf, old_synth, sizeof(FIXP_DBL) * (PIT_MAX_MAX - BPF_DELAY));
+-
+- /* calculate pitch lag offset for ACELP decoder */
+- *i_offset =
+- (samplingRate * PIT_MIN_12k8 + (FSCALE_DENOM / 2)) / FSCALE_DENOM -
+- PIT_MIN_12k8;
+-
+- /* for bass postfilter */
+- for (n = 0; n < synSfd; n++) {
+- pitch[n] = old_T_pf[n];
+- pit_gain[n] = old_gain_pf[n];
+- }
+- for (n = 0; n < nbSubfrSuperfr; n++) {
+- pitch[n + synSfd] = L_SUBFR;
+- pit_gain[n + synSfd] = (FIXP_DBL)0;
+- }
+-}
+-
+-void Acelp_PostProcessing(FIXP_DBL *synth_buf, FIXP_DBL *old_synth, INT *pitch,
+- INT *old_T_pf, INT coreCoderFrameLength, INT synSfd,
+- INT nbSubfrSuperfr) {
+- int n;
+-
+- /* store last part of synth_buf (which is not handled by the IMDCT overlap)
+- * for next frame */
+- FDKmemcpy(old_synth, synth_buf + coreCoderFrameLength,
+- sizeof(FIXP_DBL) * (PIT_MAX_MAX - BPF_DELAY));
+-
+- /* for bass postfilter */
+- for (n = 0; n < synSfd; n++) {
+- old_T_pf[n] = pitch[nbSubfrSuperfr + n];
+- }
+-}
+-
+-#define L_FAC_ZIR (LFAC)
+-
+-void CLpd_Acelp_Zir(const FIXP_LPC A[], const INT A_exp,
+- CAcelpStaticMem *acelp_mem, const INT length,
+- FIXP_DBL zir[], int doDeemph) {
+- C_ALLOC_SCRATCH_START(tmp_buf, FIXP_DBL, L_FAC_ZIR + M_LP_FILTER_ORDER);
+- FDK_ASSERT(length <= L_FAC_ZIR);
+-
+- FDKmemcpy(tmp_buf, acelp_mem->old_syn_mem,
+- M_LP_FILTER_ORDER * sizeof(FIXP_DBL));
+- FDKmemset(tmp_buf + M_LP_FILTER_ORDER, 0, L_FAC_ZIR * sizeof(FIXP_DBL));
+-
+- Syn_filt(A, A_exp, length, &tmp_buf[M_LP_FILTER_ORDER],
+- &tmp_buf[M_LP_FILTER_ORDER]);
+- if (!doDeemph) {
+- /* if last lpd mode was TD concealment, then bypass deemph */
+- FDKmemcpy(zir, tmp_buf, length * sizeof(*zir));
+- } else {
+- Deemph(&tmp_buf[M_LP_FILTER_ORDER], &zir[0], length,
+- &acelp_mem->de_emph_mem);
+- scaleValues(zir, length, -ACELP_OUTSCALE);
+- }
+- C_ALLOC_SCRATCH_END(tmp_buf, FIXP_DBL, L_FAC_ZIR + M_LP_FILTER_ORDER);
+-}
+-
+-void CLpd_AcelpPrepareInternalMem(const FIXP_DBL *synth, UCHAR last_lpd_mode,
+- UCHAR last_last_lpd_mode,
+- const FIXP_LPC *A_new, const INT A_new_exp,
+- const FIXP_LPC *A_old, const INT A_old_exp,
+- CAcelpStaticMem *acelp_mem,
+- INT coreCoderFrameLength, INT clearOldExc,
+- UCHAR lpd_mode) {
+- int l_div =
+- coreCoderFrameLength / NB_DIV; /* length of one ACELP/TCX20 frame */
+- int l_div_partial;
+- FIXP_DBL *syn, *old_exc_mem;
+-
+- C_ALLOC_SCRATCH_START(synth_buf, FIXP_DBL,
+- PIT_MAX_MAX + L_INTERPOL + M_LP_FILTER_ORDER);
+- syn = &synth_buf[M_LP_FILTER_ORDER];
+-
+- l_div_partial = PIT_MAX_MAX + L_INTERPOL - l_div;
+- old_exc_mem = acelp_mem->old_exc_mem;
+-
+- if (lpd_mode == 4) {
+- /* Bypass Domain conversion. TCXTD Concealment does no deemphasis in the
+- * end. */
+- FDKmemcpy(
+- synth_buf, &synth[-(PIT_MAX_MAX + L_INTERPOL + M_LP_FILTER_ORDER)],
+- (PIT_MAX_MAX + L_INTERPOL + M_LP_FILTER_ORDER) * sizeof(FIXP_DBL));
+- /* Set deemphasis memory state for TD concealment */
+- acelp_mem->deemph_mem_wsyn = scaleValueSaturate(synth[-1], ACELP_OUTSCALE);
+- } else {
+- /* convert past [PIT_MAX_MAX+L_INTERPOL+M_LP_FILTER_ORDER] synthesis to
+- * preemph domain */
+- E_UTIL_preemph(&synth[-(PIT_MAX_MAX + L_INTERPOL + M_LP_FILTER_ORDER)],
+- synth_buf, PIT_MAX_MAX + L_INTERPOL + M_LP_FILTER_ORDER);
+- scaleValuesSaturate(synth_buf, PIT_MAX_MAX + L_INTERPOL + M_LP_FILTER_ORDER,
+- ACELP_OUTSCALE);
+- }
+-
+- /* Set deemphasis memory state */
+- acelp_mem->de_emph_mem = scaleValueSaturate(synth[-1], ACELP_OUTSCALE);
+-
+- /* update acelp synth filter memory */
+- FDKmemcpy(acelp_mem->old_syn_mem,
+- &syn[PIT_MAX_MAX + L_INTERPOL - M_LP_FILTER_ORDER],
+- M_LP_FILTER_ORDER * sizeof(FIXP_DBL));
+-
+- if (clearOldExc) {
+- FDKmemclear(old_exc_mem, (PIT_MAX_MAX + L_INTERPOL) * sizeof(FIXP_DBL));
+- C_ALLOC_SCRATCH_END(synth_buf, FIXP_DBL,
+- PIT_MAX_MAX + L_INTERPOL + M_LP_FILTER_ORDER);
+- return;
+- }
+-
+- /* update past [PIT_MAX_MAX+L_INTERPOL] samples of exc memory */
+- if (last_lpd_mode == 1) { /* last frame was TCX20 */
+- if (last_last_lpd_mode == 0) { /* ACELP -> TCX20 -> ACELP transition */
+- /* Delay valid part of excitation buffer (from previous ACELP frame) by
+- * l_div samples */
+- FDKmemmove(old_exc_mem, old_exc_mem + l_div,
+- sizeof(FIXP_DBL) * l_div_partial);
+- } else if (last_last_lpd_mode > 0) { /* TCX -> TCX20 -> ACELP transition */
+- E_UTIL_residu(A_old, A_old_exp, syn, old_exc_mem, l_div_partial);
+- }
+- E_UTIL_residu(A_new, A_new_exp, syn + l_div_partial,
+- old_exc_mem + l_div_partial, l_div);
+- } else { /* prev frame was FD, TCX40 or TCX80 */
+- int exc_A_new_length = (coreCoderFrameLength / 2 > PIT_MAX_MAX + L_INTERPOL)
+- ? PIT_MAX_MAX + L_INTERPOL
+- : coreCoderFrameLength / 2;
+- int exc_A_old_length = PIT_MAX_MAX + L_INTERPOL - exc_A_new_length;
+- E_UTIL_residu(A_old, A_old_exp, syn, old_exc_mem, exc_A_old_length);
+- E_UTIL_residu(A_new, A_new_exp, &syn[exc_A_old_length],
+- &old_exc_mem[exc_A_old_length], exc_A_new_length);
+- }
+- C_ALLOC_SCRATCH_END(synth_buf, FIXP_DBL,
+- PIT_MAX_MAX + L_INTERPOL + M_LP_FILTER_ORDER);
+-
+- return;
+-}
+-
+-FIXP_DBL *CLpd_ACELP_GetFreeExcMem(CAcelpStaticMem *acelp_mem, INT length) {
+- FDK_ASSERT(length <= PIT_MAX_MAX + L_INTERPOL);
+- return acelp_mem->old_exc_mem;
+-}
+-
+-INT CLpd_AcelpRead(HANDLE_FDK_BITSTREAM hBs, CAcelpChannelData *acelp,
+- INT acelp_core_mode, INT coreCoderFrameLength,
+- INT i_offset) {
+- int nb_subfr = coreCoderFrameLength / L_DIV;
+- const UCHAR *num_acb_index_bits =
+- (nb_subfr == 4) ? num_acb_idx_bits_table[0] : num_acb_idx_bits_table[1];
+- int nbits;
+- int error = 0;
+-
+- const int PIT_MIN = PIT_MIN_12k8 + i_offset;
+- const int PIT_FR2 = PIT_FR2_12k8 - i_offset;
+- const int PIT_FR1 = PIT_FR1_12k8;
+- const int PIT_MAX = PIT_MAX_12k8 + (6 * i_offset);
+- int T0, T0_frac, T0_min = 0, T0_max;
+-
+- if (PIT_MAX > PIT_MAX_MAX) {
+- error = AAC_DEC_DECODE_FRAME_ERROR;
+- goto bail;
+- }
+-
+- acelp->acelp_core_mode = acelp_core_mode;
+-
+- nbits = MapCoreMode2NBits(acelp_core_mode);
+-
+- /* decode mean energy with 2 bits : 18, 30, 42 or 54 dB */
+- acelp->mean_energy = FDKreadBits(hBs, 2);
+-
+- for (int sfr = 0; sfr < nb_subfr; sfr++) {
+- /* read ACB index and store T0 and T0_frac for each ACELP subframe. */
+- error = DecodePitchLag(hBs, num_acb_index_bits[sfr], PIT_MIN, PIT_FR2,
+- PIT_FR1, PIT_MAX, &T0, &T0_frac, &T0_min, &T0_max);
+- if (error) {
+- goto bail;
+- }
+- acelp->T0[sfr] = (USHORT)T0;
+- acelp->T0_frac[sfr] = (UCHAR)T0_frac;
+- acelp->ltp_filtering_flag[sfr] = FDKreadBits(hBs, 1);
+- switch (nbits) {
+- case 12: /* 12 bits AMR-WB codebook is used */
+- acelp->icb_index[sfr][0] = FDKreadBits(hBs, 1);
+- acelp->icb_index[sfr][1] = FDKreadBits(hBs, 5);
+- acelp->icb_index[sfr][2] = FDKreadBits(hBs, 1);
+- acelp->icb_index[sfr][3] = FDKreadBits(hBs, 5);
+- break;
+- case 16: /* 16 bits AMR-WB codebook is used */
+- acelp->icb_index[sfr][0] = FDKreadBits(hBs, 1);
+- acelp->icb_index[sfr][1] = FDKreadBits(hBs, 5);
+- acelp->icb_index[sfr][2] = FDKreadBits(hBs, 5);
+- acelp->icb_index[sfr][3] = FDKreadBits(hBs, 5);
+- break;
+- case 20: /* 20 bits AMR-WB codebook is used */
+- acelp->icb_index[sfr][0] = FDKreadBits(hBs, 5);
+- acelp->icb_index[sfr][1] = FDKreadBits(hBs, 5);
+- acelp->icb_index[sfr][2] = FDKreadBits(hBs, 5);
+- acelp->icb_index[sfr][3] = FDKreadBits(hBs, 5);
+- break;
+- case 28: /* 28 bits AMR-WB codebook is used */
+- acelp->icb_index[sfr][0] = FDKreadBits(hBs, 9);
+- acelp->icb_index[sfr][1] = FDKreadBits(hBs, 9);
+- acelp->icb_index[sfr][2] = FDKreadBits(hBs, 5);
+- acelp->icb_index[sfr][3] = FDKreadBits(hBs, 5);
+- break;
+- case 36: /* 36 bits AMR-WB codebook is used */
+- acelp->icb_index[sfr][0] = FDKreadBits(hBs, 9);
+- acelp->icb_index[sfr][1] = FDKreadBits(hBs, 9);
+- acelp->icb_index[sfr][2] = FDKreadBits(hBs, 9);
+- acelp->icb_index[sfr][3] = FDKreadBits(hBs, 9);
+- break;
+- case 44: /* 44 bits AMR-WB codebook is used */
+- acelp->icb_index[sfr][0] = FDKreadBits(hBs, 13);
+- acelp->icb_index[sfr][1] = FDKreadBits(hBs, 13);
+- acelp->icb_index[sfr][2] = FDKreadBits(hBs, 9);
+- acelp->icb_index[sfr][3] = FDKreadBits(hBs, 9);
+- break;
+- case 52: /* 52 bits AMR-WB codebook is used */
+- acelp->icb_index[sfr][0] = FDKreadBits(hBs, 13);
+- acelp->icb_index[sfr][1] = FDKreadBits(hBs, 13);
+- acelp->icb_index[sfr][2] = FDKreadBits(hBs, 13);
+- acelp->icb_index[sfr][3] = FDKreadBits(hBs, 13);
+- break;
+- case 64: /* 64 bits AMR-WB codebook is used */
+- acelp->icb_index[sfr][0] = FDKreadBits(hBs, 2);
+- acelp->icb_index[sfr][1] = FDKreadBits(hBs, 2);
+- acelp->icb_index[sfr][2] = FDKreadBits(hBs, 2);
+- acelp->icb_index[sfr][3] = FDKreadBits(hBs, 2);
+- acelp->icb_index[sfr][4] = FDKreadBits(hBs, 14);
+- acelp->icb_index[sfr][5] = FDKreadBits(hBs, 14);
+- acelp->icb_index[sfr][6] = FDKreadBits(hBs, 14);
+- acelp->icb_index[sfr][7] = FDKreadBits(hBs, 14);
+- break;
+- default:
+- FDK_ASSERT(0);
+- break;
+- }
+- acelp->gains[sfr] = FDKreadBits(hBs, 7);
+- }
+-
+-bail:
+- return error;
+-}
+diff --git a/libAACdec/src/usacdec_acelp.h b/libAACdec/src/usacdec_acelp.h
+deleted file mode 100644
+index 9de41ff..0000000
+--- a/libAACdec/src/usacdec_acelp.h
++++ /dev/null
+@@ -1,281 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Matthias Hildenbrand
+-
+- Description: USAC ACELP frame decoder
+-
+-*******************************************************************************/
+-
+-#ifndef USACDEC_ACELP_H
+-#define USACDEC_ACELP_H
+-
+-#include "common_fix.h"
+-#include "FDK_bitstream.h"
+-#include "usacdec_const.h"
+-#include "usacdec_rom.h"
+-
+-//#define ENHANCED_TCX_TD_CONCEAL_ENABLE
+-
+-/** Structure which holds the ACELP internal persistent memory */
+-typedef struct {
+- FIXP_DBL old_exc_mem[PIT_MAX_MAX + L_INTERPOL];
+- FIXP_DBL old_syn_mem[M_LP_FILTER_ORDER]; /* synthesis filter states */
+- FIXP_SGL A[M_LP_FILTER_ORDER];
+- INT A_exp;
+- FIXP_DBL gc_threshold;
+- FIXP_DBL de_emph_mem;
+- FIXP_SGL past_gpit;
+- FIXP_DBL past_gcode;
+- USHORT old_T0;
+- UCHAR old_T0_frac;
+- FIXP_DBL deemph_mem_wsyn;
+- FIXP_DBL wsyn_rms;
+- SHORT seed_ace;
+-} CAcelpStaticMem;
+-
+-/** Structure which holds the parameter data needed to decode one ACELP frame.
+- */
+-typedef struct {
+- UCHAR
+- acelp_core_mode; /**< mean excitation energy index for whole ACELP frame
+- */
+- UCHAR mean_energy; /**< acelp core mode for whole ACELP frame */
+- USHORT T0[NB_SUBFR];
+- UCHAR T0_frac[NB_SUBFR];
+- UCHAR ltp_filtering_flag[NB_SUBFR]; /**< controlls whether LTP postfilter is
+- active for each ACELP subframe */
+- SHORT icb_index[NB_SUBFR]
+- [8]; /**< innovative codebook index for each ACELP subframe */
+- UCHAR gains[NB_SUBFR]; /**< gain index for each ACELP subframe */
+-} CAcelpChannelData;
+-
+-/**
+- * \brief Read the acelp_coding() bitstream part.
+- * \param[in] hBs bitstream handle to read data from.
+- * \param[out] acelpData pointer to structure to store the parsed data of one
+- * ACELP frame.
+- * \param[in] acelp_core_mode the ACELP core mode index.
+- * \param[in] coreCoderFrameLength length of core coder frame (1024|768)
+- */
+-INT CLpd_AcelpRead(HANDLE_FDK_BITSTREAM hBs, CAcelpChannelData *acelpData,
+- INT acelp_core_mode, INT i_offset, INT coreCoderFrameLength);
+-/**
+- * \brief Initialization of memory before one LPD frame is decoded
+- * \param[out] synth_buf synthesis buffer to be initialized, exponent = SF_SYNTH
+- * \param[in] old_synth past synthesis of previous LPD frame, exponent =
+- * SF_SYNTH
+- * \param[out] synth_buf_fb fullband synthesis buffer to be initialized,
+- * exponent = SF_SYNTH
+- * \param[in] old_synth_fb past fullband synthesis of previous LPD frame,
+- * exponent = SF_SYNTH
+- * \param[out] pitch vector where decoded pitch lag values are stored
+- * \param[in] old_T_pf past pitch lag values of previous LPD frame
+- * \param[in] samplingRate sampling rate for pitch lag offset calculation
+- * \param[out] i_offset pitch lag offset for the decoding of the pitch lag
+- * \param[in] coreCoderFrameLength length of core coder frame (1024|768)
+- */
+-void Acelp_PreProcessing(FIXP_DBL *synth_buf, FIXP_DBL *old_synth, INT *pitch,
+- INT *old_T_pf, FIXP_DBL *pit_gain,
+- FIXP_DBL *old_gain_pf, INT samplingRate, INT *i_offset,
+- INT coreCoderFrameLength, INT synSfd,
+- INT nbSubfrSuperfr);
+-
+-/**
+- * \brief Save tail of buffers for the initialization of the next LPD frame
+- * \param[in] synth_buf synthesis of current LPD frame, exponent = SF_SYNTH
+- * \param[out] old_synth memory where tail of fullband synth_buf is stored,
+- * exponent = SF_SYNTH
+- * \param[in] synth_buf_fb fullband synthesis of current LPD frame, exponent =
+- * SF_SYNTH
+- * \param[out] old_synth_fb memory where tail of fullband synth_buf is stored,
+- * exponent = SF_SYNTH
+- * \param[in] pitch decoded pitch lag values of current LPD frame
+- * \param[out] old_T_pf memory where last SYN_SFD pitch lag values are stored
+- */
+-void Acelp_PostProcessing(FIXP_DBL *synth_buf, FIXP_DBL *old_synth, INT *pitch,
+- INT *old_T_pf, INT coreCoderFrameLength, INT synSfd,
+- INT nbSubfrSuperfr);
+-
+-/**
+- * \brief Decode one ACELP frame (three or four ACELP subframes with 64 samples
+- * each)
+- * \param[in,out] acelp_mem pointer to ACELP memory structure
+- * \param[in] i_offset pitch lag offset
+- * \param[in] lsp_old LPC filter in LSP domain corresponding to previous frame
+- * \param[in] lsp_new LPC filter in LSP domain corresponding to current frame
+- * \param[in] stab_fac stability factor constrained by 0<=stab_fac<=1.0,
+- * exponent = SF_STAB
+- * \param[in] acelpData pointer to struct with data which is needed for decoding
+- * one ACELP frame
+- * \param[out] synth ACELP output signal
+- * \param[out] pT four decoded pitch lag values
+- * \param[in] coreCoderFrameLength length of core coder frame (1024|768)
+- */
+-void CLpd_AcelpDecode(CAcelpStaticMem *acelp_mem, INT i_offset,
+- const FIXP_LPC lsp_old[M_LP_FILTER_ORDER],
+- const FIXP_LPC lsp_new[M_LP_FILTER_ORDER],
+- FIXP_SGL stab_fac, CAcelpChannelData *acelpData,
+- INT numLostSubframes, int lastLpcLost, int frameCnt,
+- FIXP_DBL synth[], int pT[], FIXP_DBL *pit_gain,
+- INT coreCoderFrameLength);
+-
+-/**
+- * \brief Reset ACELP internal memory.
+- * \param[out] acelp_mem pointer to ACELP memory structure
+- */
+-void CLpd_AcelpReset(CAcelpStaticMem *acelp_mem);
+-
+-/**
+- * \brief Initialize ACELP internal memory in case of FAC before ACELP decoder
+- * is called
+- * \param[in] synth points to end+1 of past valid synthesis signal, exponent =
+- * SF_SYNTH
+- * \param[in] last_lpd_mode last lpd mode
+- * \param[in] last_last_lpd_mode lpd mode before last_lpd_mode
+- * \param[in] A_new LP synthesis filter coeffs corresponding to last frame,
+- * exponent = SF_A_COEFFS
+- * \param[in] A_old LP synthesis filter coeffs corresponding to the frame before
+- * last frame, exponent = SF_A_COEFFS
+- * \param[in,out] acelp_mem pointer to ACELP memory structure
+- * \param[in] coreCoderFrameLength length of core coder frame (1024|768)
+- */
+-void CLpd_AcelpPrepareInternalMem(const FIXP_DBL *synth, UCHAR last_lpd_mode,
+- UCHAR last_last_lpd_mode,
+- const FIXP_LPC *A_new, const INT A_new_exp,
+- const FIXP_LPC *A_old, const INT A_old_exp,
+- CAcelpStaticMem *acelp_mem,
+- INT coreCoderFrameLength, INT clearOldExc,
+- UCHAR lpd_mode);
+-
+-/**
+- * \brief Calculate zero input response (zir) of the acelp synthesis filter
+- * \param[in] A LP synthesis filter coefficients, exponent = SF_A_COEFFS
+- * \param[in,out] acelp_mem pointer to ACELP memory structure
+- * \param[in] length length of zir
+- * \param[out] zir pointer to zir output buffer, exponent = SF_SYNTH
+- */
+-void CLpd_Acelp_Zir(const FIXP_LPC A[], const INT A_exp,
+- CAcelpStaticMem *acelp_mem, const INT length,
+- FIXP_DBL zir[], int doDeemph);
+-
+-/**
+- * \brief Borrow static excitation memory from ACELP decoder
+- * \param[in] acelp_mem pointer to ACELP memory structure
+- * \param[in] length number of requested FIXP_DBL values
+- * \return pointer to requested memory
+- *
+- * The caller has to take care not to overwrite valid memory areas.
+- * During TCX/FAC calculations and before CLpd_AcelpPrepareInternalMem() is
+- * called, the following memory size is available:
+- * - 256 samples in case of ACELP -> TCX20 -> ACELP transition
+- * - PIT_MAX_MAX+L_INTERPOL samples in all other cases
+- */
+-FIXP_DBL *CLpd_ACELP_GetFreeExcMem(CAcelpStaticMem *acelp_mem, INT length);
+-
+-void CLpd_TcxTDConceal(CAcelpStaticMem *acelp_mem, SHORT *pitch,
+- const FIXP_LPC lsp_old[M_LP_FILTER_ORDER],
+- const FIXP_LPC lsp_new[M_LP_FILTER_ORDER],
+- const FIXP_SGL stab_fac, INT numLostSubframes,
+- FIXP_DBL synth[], INT coreCoderFrameLength,
+- UCHAR last_tcx_noise_factor);
+-
+-inline SHORT E_UTIL_random(SHORT *seed) {
+- *seed = (SHORT)((((LONG)*seed * (LONG)31821) >> 1) + (LONG)13849);
+- return (*seed);
+-}
+-
+-#endif /* USACDEC_ACELP_H */
+diff --git a/libAACdec/src/usacdec_const.h b/libAACdec/src/usacdec_const.h
+deleted file mode 100644
+index f68e808..0000000
+--- a/libAACdec/src/usacdec_const.h
++++ /dev/null
+@@ -1,203 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Manuel Jander
+-
+- Description: USAC related constants
+-
+-*******************************************************************************/
+-
+-#ifndef USACDEC_CONST_H
+-#define USACDEC_CONST_H
+-
+-/* scale factors */
+-#define SF_CODE 6 /* exponent of code[], fixed codebook vector */
+-#define SF_GAIN_C 16 /* exponent of gain code and smoothed gain code */
+-#define SF_EXC 16 /* exponent of exc[] and exc2[], excitation buffer */
+-#define SF_GAIN_P 1 /* exponent of gain_pit */
+-#define SF_PFAC 0 /* exponent of period/voicing factor */
+-#define SF_SYNTH SF_EXC /* exponent of synthesis buffer */
+-#define SF_A_COEFFS 3 /* exponent of LP domain synthesis filter coefficient */
+-#define SF_STAB 1 /* exponent of stability factor */
+-
+-/* definitions which are independent of coreCoderFrameLength */
+-#define M_LP_FILTER_ORDER 16 /* LP filter order */
+-#define LP_FILTER_SCALE 4 /* LP filter scale */
+-
+-#define PIT_MIN_12k8 34 /* Minimum pitch lag with resolution 1/4 */
+-#define PIT_MAX_12k8 231 /* Maximum pitch lag for fs=12.8kHz */
+-#define FSCALE_DENOM 12800 /* Frequency scale denominator */
+-#define FAC_FSCALE_MIN \
+- 6000 /* Minimum allowed frequency scale for acelp decoder */
+-
+-#if !defined(LPD_MAX_CORE_SR)
+-#define LPD_MAX_CORE_SR 24000 /* Default value from ref soft */
+-#endif
+-#define FAC_FSCALE_MAX \
+- LPD_MAX_CORE_SR /* Maximum allowed frequency scale for acelp decoder */
+-
+-/* Maximum pitch lag (= 411 for fs_max = 24000) */
+-#define PIT_MAX_TMP \
+- (PIT_MAX_12k8 + \
+- (6 * \
+- ((((FAC_FSCALE_MAX * PIT_MIN_12k8) + (FSCALE_DENOM / 2)) / FSCALE_DENOM) - \
+- PIT_MIN_12k8)))
+-#if (PIT_MAX_TMP < \
+- 256) /* cannot be smaller because of tcx time domain concealment */
+-#define PIT_MAX_MAX 256
+-#else
+-#define PIT_MAX_MAX PIT_MAX_TMP
+-#endif
+-
+-#define NB_DIV 4 /* number of division (20ms) per 80ms frame */
+-#define L_SUBFR 64 /* subframe size (5ms) */
+-#define BPF_SFD 1 /* bass postfilter delay (subframe) */
+-#define BPF_DELAY (BPF_SFD * L_SUBFR) /* bass postfilter delay (samples) */
+-
+-#define L_FILT 12 /* Delay of up-sampling filter (bass post-filter) */
+-#define L_EXTRA 96 /* for bass post-filter */
+-#define L_INTERPOL \
+- (16 + 1) /* Length of filter for interpolation (acelp decoder) */
+-
+-/* definitions for coreCoderFrameLength = 1024 */
+-#define L_FRAME_PLUS_1024 1024 /* length of one 80ms superframe */
+-#define L_DIV_1024 \
+- (L_FRAME_PLUS_1024 / NB_DIV) /* length of one acelp or tcx20 frame */
+-#define NB_SUBFR_1024 \
+- (L_DIV_1024 / L_SUBFR) /* number of 5ms subframe per division */
+-#define NB_SUBFR_SUPERFR_1024 \
+- (L_FRAME_PLUS_1024 / L_SUBFR) /* number of 5ms subframe per 80ms frame */
+-#define AAC_SFD_1024 (NB_SUBFR_SUPERFR_1024 / 2) /* AAC delay (subframe) */
+-#define AAC_DELAY_1024 (AAC_SFD_1024 * L_SUBFR) /* AAC delay (samples) */
+-#define SYN_SFD_1024 (AAC_SFD_1024 - BPF_SFD) /* synthesis delay (subframe) */
+-#define SYN_DELAY_1024 \
+- (SYN_SFD_1024 * L_SUBFR) /* synthesis delay (samples) \
+- */
+-#define LFAC_1024 (L_DIV_1024 / 2) /* FAC frame length */
+-#define LFAC_SHORT_1024 \
+- (L_DIV_1024 / 4) /* for transitions EIGHT_SHORT FD->LPD and vv. */
+-#define FDNS_NPTS_1024 64 /* FD noise shaping resolution (64=100Hz/point) */
+-
+-/* definitions for coreCoderFrameLength = 768 */
+-#define L_FRAME_PLUS_768 768
+-#define L_DIV_768 \
+- (L_FRAME_PLUS_768 / NB_DIV) /* length of one acelp or tcx20 frame */
+-#define NB_SUBFR_768 \
+- (L_DIV_768 / L_SUBFR) /* number of 5ms subframe per division */
+-#define NB_SUBFR_SUPERFR_768 \
+- (L_FRAME_PLUS_768 / L_SUBFR) /* number of 5ms subframe per 80ms frame */
+-#define AAC_SFD_768 (NB_SUBFR_SUPERFR_768 / 2) /* AAC delay (subframe) */
+-#define AAC_DELAY_768 (AAC_SFD_768 * L_SUBFR) /* AAC delay (samples) */
+-#define SYN_SFD_768 (AAC_SFD_768 - BPF_SFD) /* synthesis delay (subframe) */
+-#define SYN_DELAY_768 (SYN_SFD_768 * L_SUBFR) /* synthesis delay (samples) */
+-#define LFAC_768 (L_DIV_768 / 2) /* FAC frame length */
+-#define LFAC_SHORT_768 \
+- (L_DIV_768 / 4) /* for transitions EIGHT_SHORT FD->LPD and vv. */
+-
+-/* maximum (used for memory allocation) */
+-#define L_FRAME_PLUS L_FRAME_PLUS_1024
+-#define L_DIV L_DIV_1024
+-#define NB_SUBFR NB_SUBFR_1024
+-#define NB_SUBFR_SUPERFR NB_SUBFR_SUPERFR_1024
+-#define AAC_SFD AAC_SFD_1024
+-#define AAC_DELAY AAC_DELAY_1024
+-#define SYN_SFD SYN_SFD_1024
+-#define SYN_DELAY SYN_DELAY_1024
+-#define LFAC LFAC_1024
+-#define LFAC_SHORT LFAC_SHORT_1024
+-#define FDNS_NPTS FDNS_NPTS_1024
+-
+-#endif /* USACDEC_CONST_H */
+diff --git a/libAACdec/src/usacdec_fac.cpp b/libAACdec/src/usacdec_fac.cpp
+deleted file mode 100644
+index 0d3d844..0000000
+--- a/libAACdec/src/usacdec_fac.cpp
++++ /dev/null
+@@ -1,745 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Manuel Jander
+-
+- Description: USAC FAC
+-
+-*******************************************************************************/
+-
+-#include "usacdec_fac.h"
+-
+-#include "usacdec_const.h"
+-#include "usacdec_lpc.h"
+-#include "usacdec_acelp.h"
+-#include "usacdec_rom.h"
+-#include "dct.h"
+-#include "FDK_tools_rom.h"
+-#include "mdct.h"
+-
+-#define SPEC_FAC(ptr, i, gl) ((ptr) + ((i) * (gl)))
+-
+-FIXP_DBL *CLpd_FAC_GetMemory(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- UCHAR mod[NB_DIV], int *pState) {
+- FIXP_DBL *ptr;
+- int i;
+- int k = 0;
+- int max_windows = 8;
+-
+- FDK_ASSERT(*pState >= 0 && *pState < max_windows);
+-
+- /* Look for free space to store FAC data. 2 FAC data blocks fit into each TCX
+- * spectral data block. */
+- for (i = *pState; i < max_windows; i++) {
+- if (mod[i >> 1] == 0) {
+- break;
+- }
+- }
+-
+- *pState = i + 1;
+-
+- if (i == max_windows) {
+- ptr = pAacDecoderChannelInfo->data.usac.fac_data0;
+- } else {
+- FDK_ASSERT(mod[(i >> 1)] == 0);
+- ptr = SPEC_FAC(pAacDecoderChannelInfo->pSpectralCoefficient, i,
+- pAacDecoderChannelInfo->granuleLength << k);
+- }
+-
+- return ptr;
+-}
+-
+-int CLpd_FAC_Read(HANDLE_FDK_BITSTREAM hBs, FIXP_DBL *pFac, SCHAR *pFacScale,
+- int length, int use_gain, int frame) {
+- FIXP_DBL fac_gain;
+- int fac_gain_e = 0;
+-
+- if (use_gain) {
+- CLpd_DecodeGain(&fac_gain, &fac_gain_e, FDKreadBits(hBs, 7));
+- }
+-
+- if (CLpc_DecodeAVQ(hBs, pFac, 1, 1, length) != 0) {
+- return -1;
+- }
+-
+- {
+- int scale;
+-
+- scale = getScalefactor(pFac, length);
+- scaleValues(pFac, length, scale);
+- pFacScale[frame] = DFRACT_BITS - 1 - scale;
+- }
+-
+- if (use_gain) {
+- int i;
+-
+- pFacScale[frame] += fac_gain_e;
+-
+- for (i = 0; i < length; i++) {
+- pFac[i] = fMult(pFac[i], fac_gain);
+- }
+- }
+- return 0;
+-}
+-
+-/**
+- * \brief Apply synthesis filter with zero input to x. The overall filter gain
+- * is 1.0.
+- * \param a LPC filter coefficients.
+- * \param length length of the input/output data vector x.
+- * \param x input/output vector, where the synthesis filter is applied in place.
+- */
+-static void Syn_filt_zero(const FIXP_LPC a[], const INT a_exp, INT length,
+- FIXP_DBL x[]) {
+- int i, j;
+- FIXP_DBL L_tmp;
+-
+- for (i = 0; i < length; i++) {
+- L_tmp = (FIXP_DBL)0;
+-
+- for (j = 0; j < fMin(i, M_LP_FILTER_ORDER); j++) {
+- L_tmp -= fMultDiv2(a[j], x[i - (j + 1)]) >> (LP_FILTER_SCALE - 1);
+- }
+-
+- L_tmp = scaleValue(L_tmp, a_exp + LP_FILTER_SCALE);
+- x[i] = fAddSaturate(x[i], L_tmp);
+- }
+-}
+-
+-/* Table is also correct for coreCoderFrameLength = 768. Factor 3/4 is canceled
+- out: gainFac = 0.5 * sqrt(fac_length/lFrame)
+-*/
+-static const FIXP_DBL gainFac[4] = {0x40000000, 0x2d413ccd, 0x20000000,
+- 0x16a09e66};
+-
+-void CFac_ApplyGains(FIXP_DBL fac_data[LFAC], const INT fac_length,
+- const FIXP_DBL tcx_gain, const FIXP_DBL alfd_gains[],
+- const INT mod) {
+- FIXP_DBL facFactor;
+- int i;
+-
+- FDK_ASSERT((fac_length == 128) || (fac_length == 96));
+-
+- /* 2) Apply gain factor to FAC data */
+- facFactor = fMult(gainFac[mod], tcx_gain);
+- for (i = 0; i < fac_length; i++) {
+- fac_data[i] = fMult(fac_data[i], facFactor);
+- }
+-
+- /* 3) Apply spectrum deshaping using alfd_gains */
+- for (i = 0; i < fac_length / 4; i++) {
+- int k;
+-
+- k = i >> (3 - mod);
+- fac_data[i] = fMult(fac_data[i], alfd_gains[k])
+- << 1; /* alfd_gains is scaled by one bit. */
+- }
+-}
+-
+-static void CFac_CalcFacSignal(FIXP_DBL *pOut, FIXP_DBL *pFac,
+- const int fac_scale, const int fac_length,
+- const FIXP_LPC A[M_LP_FILTER_ORDER],
+- const INT A_exp, const int fAddZir,
+- const int isFdFac) {
+- FIXP_LPC wA[M_LP_FILTER_ORDER];
+- FIXP_DBL tf_gain = (FIXP_DBL)0;
+- int wlength;
+- int scale = fac_scale;
+-
+- /* obtain tranform gain. */
+- imdct_gain(&tf_gain, &scale, isFdFac ? 0 : fac_length);
+-
+- /* 4) Compute inverse DCT-IV of FAC data. Output scale of DCT IV is 16 bits.
+- */
+- dct_IV(pFac, fac_length, &scale);
+- /* dct_IV scale = log2(fac_length). "- 7" is a factor of 2/128 */
+- if (tf_gain != (FIXP_DBL)0) { /* non-radix 2 transform gain */
+- int i;
+-
+- for (i = 0; i < fac_length; i++) {
+- pFac[i] = fMult(tf_gain, pFac[i]);
+- }
+- }
+- scaleValuesSaturate(pOut, pFac, fac_length,
+- scale); /* Avoid overflow issues and saturate. */
+-
+- E_LPC_a_weight(wA, A, M_LP_FILTER_ORDER);
+-
+- /* We need the output of the IIR filter to be longer than "fac_length".
+- For this reason we run it with zero input appended to the end of the input
+- sequence, i.e. we generate its ZIR and extend the output signal.*/
+- FDKmemclear(pOut + fac_length, fac_length * sizeof(FIXP_DBL));
+- wlength = 2 * fac_length;
+-
+- /* 5) Apply weighted synthesis filter to FAC data, including optional Zir (5.
+- * item 4). */
+- Syn_filt_zero(wA, A_exp, wlength, pOut);
+-}
+-
+-INT CLpd_FAC_Mdct2Acelp(H_MDCT hMdct, FIXP_DBL *output, FIXP_DBL *pFac,
+- const int fac_scale, FIXP_LPC *A, INT A_exp,
+- INT nrOutSamples, const INT fac_length,
+- const INT isFdFac, UCHAR prevWindowShape) {
+- FIXP_DBL *pOvl;
+- FIXP_DBL *pOut0;
+- const FIXP_WTP *pWindow;
+- int i, fl, nrSamples = 0;
+-
+- FDK_ASSERT(fac_length <= 1024 / (4 * 2));
+-
+- fl = fac_length * 2;
+-
+- pWindow = FDKgetWindowSlope(fl, prevWindowShape);
+-
+- /* Adapt window slope length in case of frame loss. */
+- if (hMdct->prev_fr != fl) {
+- int nl = 0;
+- imdct_adapt_parameters(hMdct, &fl, &nl, fac_length, pWindow, nrOutSamples);
+- FDK_ASSERT(nl == 0);
+- }
+-
+- if (nrSamples < nrOutSamples) {
+- pOut0 = output;
+- nrSamples += hMdct->ov_offset;
+- /* Purge buffered output. */
+- FDKmemcpy(pOut0, hMdct->overlap.time, hMdct->ov_offset * sizeof(pOut0[0]));
+- hMdct->ov_offset = 0;
+- }
+-
+- pOvl = hMdct->overlap.freq + hMdct->ov_size - 1;
+-
+- if (nrSamples >= nrOutSamples) {
+- pOut0 = hMdct->overlap.time + hMdct->ov_offset;
+- hMdct->ov_offset += hMdct->prev_nr + fl / 2;
+- } else {
+- pOut0 = output + nrSamples;
+- nrSamples += hMdct->prev_nr + fl / 2;
+- }
+- if (hMdct->prevPrevAliasSymmetry == 0) {
+- for (i = 0; i < hMdct->prev_nr; i++) {
+- FIXP_DBL x = -(*pOvl--);
+- *pOut0 = IMDCT_SCALE_DBL(x);
+- pOut0++;
+- }
+- } else {
+- for (i = 0; i < hMdct->prev_nr; i++) {
+- FIXP_DBL x = (*pOvl--);
+- *pOut0 = IMDCT_SCALE_DBL(x);
+- pOut0++;
+- }
+- }
+- hMdct->prev_nr = 0;
+-
+- {
+- if (pFac != NULL) {
+- /* Note: The FAC gain might have been applied directly after bit stream
+- * parse in this case. */
+- CFac_CalcFacSignal(pOut0, pFac, fac_scale, fac_length, A, A_exp, 0,
+- isFdFac);
+- } else {
+- /* Clear buffer because of the overlap and ADD! */
+- FDKmemclear(pOut0, fac_length * sizeof(FIXP_DBL));
+- }
+- }
+-
+- i = 0;
+-
+- if (hMdct->prevPrevAliasSymmetry == 0) {
+- for (; i < fl / 2; i++) {
+- FIXP_DBL x0;
+-
+- /* Overlap Add */
+- x0 = -fMult(*pOvl--, pWindow[i].v.re);
+-
+- *pOut0 += IMDCT_SCALE_DBL(x0);
+- pOut0++;
+- }
+- } else {
+- for (; i < fl / 2; i++) {
+- FIXP_DBL x0;
+-
+- /* Overlap Add */
+- x0 = fMult(*pOvl--, pWindow[i].v.re);
+-
+- *pOut0 += IMDCT_SCALE_DBL(x0);
+- pOut0++;
+- }
+- }
+- if (hMdct->pFacZir !=
+- 0) { /* this should only happen for ACELP -> TCX20 -> ACELP transition */
+- FIXP_DBL *pOut = pOut0 - fl / 2; /* fl/2 == fac_length */
+- for (i = 0; i < fl / 2; i++) {
+- pOut[i] += IMDCT_SCALE_DBL(hMdct->pFacZir[i]);
+- }
+- hMdct->pFacZir = NULL;
+- }
+-
+- hMdct->prev_fr = 0;
+- hMdct->prev_nr = 0;
+- hMdct->prev_tl = 0;
+- hMdct->prevPrevAliasSymmetry = hMdct->prevAliasSymmetry;
+-
+- return nrSamples;
+-}
+-
+-INT CLpd_FAC_Acelp2Mdct(H_MDCT hMdct, FIXP_DBL *output, FIXP_DBL *_pSpec,
+- const SHORT spec_scale[], const int nSpec,
+- FIXP_DBL *pFac, const int fac_scale,
+- const INT fac_length, INT noOutSamples, const INT tl,
+- const FIXP_WTP *wrs, const INT fr, FIXP_LPC A[16],
+- INT A_exp, CAcelpStaticMem *acelp_mem,
+- const FIXP_DBL gain, const int last_frame_lost,
+- const int isFdFac, const UCHAR last_lpd_mode,
+- const int k, int currAliasingSymmetry) {
+- FIXP_DBL *pCurr, *pOvl, *pSpec;
+- const FIXP_WTP *pWindow;
+- const FIXP_WTB *FacWindowZir_conceal;
+- UCHAR doFacZirConceal = 0;
+- int doDeemph = 1;
+- const FIXP_WTB *FacWindowZir, *FacWindowSynth;
+- FIXP_DBL *pOut0 = output, *pOut1;
+- int w, i, fl, nl, nr, f_len, nrSamples = 0, s = 0, scale, total_gain_e;
+- FIXP_DBL *pF, *pFAC_and_FAC_ZIR = NULL;
+- FIXP_DBL total_gain = gain;
+-
+- FDK_ASSERT(fac_length <= 1024 / (4 * 2));
+- switch (fac_length) {
+- /* coreCoderFrameLength = 1024 */
+- case 128:
+- pWindow = SineWindow256;
+- FacWindowZir = FacWindowZir128;
+- FacWindowSynth = FacWindowSynth128;
+- break;
+- case 64:
+- pWindow = SineWindow128;
+- FacWindowZir = FacWindowZir64;
+- FacWindowSynth = FacWindowSynth64;
+- break;
+- case 32:
+- pWindow = SineWindow64;
+- FacWindowZir = FacWindowZir32;
+- FacWindowSynth = FacWindowSynth32;
+- break;
+- /* coreCoderFrameLength = 768 */
+- case 96:
+- pWindow = SineWindow192;
+- FacWindowZir = FacWindowZir96;
+- FacWindowSynth = FacWindowSynth96;
+- break;
+- case 48:
+- pWindow = SineWindow96;
+- FacWindowZir = FacWindowZir48;
+- FacWindowSynth = FacWindowSynth48;
+- break;
+- default:
+- FDK_ASSERT(0);
+- return 0;
+- }
+-
+- FacWindowZir_conceal = FacWindowSynth;
+- /* Derive NR and NL */
+- fl = fac_length * 2;
+- nl = (tl - fl) >> 1;
+- nr = (tl - fr) >> 1;
+-
+- if (noOutSamples > nrSamples) {
+- /* Purge buffered output. */
+- FDKmemcpy(pOut0, hMdct->overlap.time, hMdct->ov_offset * sizeof(pOut0[0]));
+- nrSamples = hMdct->ov_offset;
+- hMdct->ov_offset = 0;
+- }
+-
+- if (nrSamples >= noOutSamples) {
+- pOut1 = hMdct->overlap.time + hMdct->ov_offset;
+- if (hMdct->ov_offset < fac_length) {
+- pOut0 = output + nrSamples;
+- } else {
+- pOut0 = pOut1;
+- }
+- hMdct->ov_offset += fac_length + nl;
+- } else {
+- pOut1 = output + nrSamples;
+- pOut0 = output + nrSamples;
+- }
+-
+- {
+- pFAC_and_FAC_ZIR = CLpd_ACELP_GetFreeExcMem(acelp_mem, 2 * fac_length);
+- {
+- const FIXP_DBL *pTmp1, *pTmp2;
+-
+- doFacZirConceal |= ((last_frame_lost != 0) && (k == 0));
+- doDeemph &= (last_lpd_mode != 4);
+- if (doFacZirConceal) {
+- /* ACELP contribution in concealment case:
+- Use ZIR with a modified ZIR window to preserve some more energy.
+- Dont use FAC, which contains wrong information for concealed frame
+- Dont use last ACELP samples, but double ZIR, instead (afterwards) */
+- FDKmemclear(pFAC_and_FAC_ZIR, 2 * fac_length * sizeof(FIXP_DBL));
+- FacWindowSynth = (FIXP_WTB *)pFAC_and_FAC_ZIR;
+- FacWindowZir = FacWindowZir_conceal;
+- } else {
+- CFac_CalcFacSignal(pFAC_and_FAC_ZIR, pFac, fac_scale + s, fac_length, A,
+- A_exp, 1, isFdFac);
+- }
+- /* 6) Get windowed past ACELP samples and ACELP ZIR signal */
+-
+- /*
+- * Get ACELP ZIR (pFac[]) and ACELP past samples (pOut0[]) and add them
+- * to the FAC synth signal contribution on pOut1[].
+- */
+- {
+- {
+- CLpd_Acelp_Zir(A, A_exp, acelp_mem, fac_length, pFac, doDeemph);
+-
+- pTmp1 = pOut0;
+- pTmp2 = pFac;
+- }
+-
+- for (i = 0, w = 0; i < fac_length; i++) {
+- FIXP_DBL x;
+- /* Div2 is compensated by table scaling */
+- x = fMultDiv2(pTmp2[i], FacWindowZir[w]);
+- x += fMultDiv2(pTmp1[-i - 1], FacWindowSynth[w]);
+- x += pFAC_and_FAC_ZIR[i];
+- pOut1[i] = x;
+-
+- w++;
+- }
+- }
+-
+- if (doFacZirConceal) {
+- /* ZIR is the only ACELP contribution, so double it */
+- scaleValues(pOut1, fac_length, 1);
+- }
+- }
+- }
+-
+- if (nrSamples < noOutSamples) {
+- nrSamples += fac_length + nl;
+- }
+-
+- /* Obtain transform gain */
+- total_gain = gain;
+- total_gain_e = 0;
+- imdct_gain(&total_gain, &total_gain_e, tl);
+-
+- /* IMDCT overlap add */
+- scale = total_gain_e;
+- pSpec = _pSpec;
+-
+- /* Note:when comming from an LPD frame (TCX/ACELP) the previous alisaing
+- * symmetry must always be 0 */
+- if (currAliasingSymmetry == 0) {
+- dct_IV(pSpec, tl, &scale);
+- } else {
+- FIXP_DBL _tmp[1024 + ALIGNMENT_DEFAULT / sizeof(FIXP_DBL)];
+- FIXP_DBL *tmp = (FIXP_DBL *)ALIGN_PTR(_tmp);
+- C_ALLOC_ALIGNED_REGISTER(tmp, sizeof(_tmp));
+- dst_III(pSpec, tmp, tl, &scale);
+- C_ALLOC_ALIGNED_UNREGISTER(tmp);
+- }
+-
+- /* Optional scaling of time domain - no yet windowed - of current spectrum */
+- if (total_gain != (FIXP_DBL)0) {
+- for (i = 0; i < tl; i++) {
+- pSpec[i] = fMult(pSpec[i], total_gain);
+- }
+- }
+- int loc_scale = fixmin_I(spec_scale[0] + scale, (INT)DFRACT_BITS - 1);
+- scaleValuesSaturate(pSpec, tl, loc_scale);
+-
+- pOut1 += fl / 2 - 1;
+- pCurr = pSpec + tl - fl / 2;
+-
+- for (i = 0; i < fl / 2; i++) {
+- FIXP_DBL x1;
+-
+- /* FAC signal is already on pOut1, because of that the += operator. */
+- x1 = fMult(*pCurr++, pWindow[i].v.re);
+- FDK_ASSERT((pOut1 >= hMdct->overlap.time &&
+- pOut1 < hMdct->overlap.time + hMdct->ov_size) ||
+- (pOut1 >= output && pOut1 < output + 1024));
+- *pOut1 += IMDCT_SCALE_DBL(-x1);
+- pOut1--;
+- }
+-
+- /* NL output samples TL/2+FL/2..TL. - current[FL/2..0] */
+- pOut1 += (fl / 2) + 1;
+-
+- pFAC_and_FAC_ZIR += fac_length; /* set pointer to beginning of FAC ZIR */
+-
+- if (nl == 0) {
+- /* save pointer to write FAC ZIR data later */
+- hMdct->pFacZir = pFAC_and_FAC_ZIR;
+- } else {
+- FDK_ASSERT(nl >= fac_length);
+- /* FAC ZIR will be added now ... */
+- hMdct->pFacZir = NULL;
+- }
+-
+- pF = pFAC_and_FAC_ZIR;
+- f_len = fac_length;
+-
+- pCurr = pSpec + tl - fl / 2 - 1;
+- for (i = 0; i < nl; i++) {
+- FIXP_DBL x = -(*pCurr--);
+- /* 5) (item 4) Synthesis filter Zir component, FAC ZIR (another one). */
+- if (i < f_len) {
+- x += *pF++;
+- }
+-
+- FDK_ASSERT((pOut1 >= hMdct->overlap.time &&
+- pOut1 < hMdct->overlap.time + hMdct->ov_size) ||
+- (pOut1 >= output && pOut1 < output + 1024));
+- *pOut1 = IMDCT_SCALE_DBL(x);
+- pOut1++;
+- }
+-
+- hMdct->prev_nr = nr;
+- hMdct->prev_fr = fr;
+- hMdct->prev_wrs = wrs;
+- hMdct->prev_tl = tl;
+- hMdct->prevPrevAliasSymmetry = hMdct->prevAliasSymmetry;
+- hMdct->prevAliasSymmetry = currAliasingSymmetry;
+- fl = fr;
+- nl = nr;
+-
+- pOvl = pSpec + tl / 2 - 1;
+- pOut0 = pOut1;
+-
+- for (w = 1; w < nSpec; w++) /* for ACELP -> FD short */
+- {
+- const FIXP_WTP *pWindow_prev;
+-
+- /* Setup window pointers */
+- pWindow_prev = hMdct->prev_wrs;
+-
+- /* Current spectrum */
+- pSpec = _pSpec + w * tl;
+-
+- scale = total_gain_e;
+-
+- /* For the second, third, etc. short frames the alisaing symmetry is equal,
+- * either (0,0) or (1,1) */
+- if (currAliasingSymmetry == 0) {
+- /* DCT IV of current spectrum */
+- dct_IV(pSpec, tl, &scale);
+- } else {
+- dst_IV(pSpec, tl, &scale);
+- }
+-
+- /* Optional scaling of time domain - no yet windowed - of current spectrum
+- */
+- /* and de-scale current spectrum signal (time domain, no yet windowed) */
+- if (total_gain != (FIXP_DBL)0) {
+- for (i = 0; i < tl; i++) {
+- pSpec[i] = fMult(pSpec[i], total_gain);
+- }
+- }
+- loc_scale = fixmin_I(spec_scale[w] + scale, (INT)DFRACT_BITS - 1);
+- scaleValuesSaturate(pSpec, tl, loc_scale);
+-
+- if (noOutSamples <= nrSamples) {
+- /* Divert output first half to overlap buffer if we already got enough
+- * output samples. */
+- pOut0 = hMdct->overlap.time + hMdct->ov_offset;
+- hMdct->ov_offset += hMdct->prev_nr + fl / 2;
+- } else {
+- /* Account output samples */
+- nrSamples += hMdct->prev_nr + fl / 2;
+- }
+-
+- /* NR output samples 0 .. NR. -overlap[TL/2..TL/2-NR] */
+- for (i = 0; i < hMdct->prev_nr; i++) {
+- FIXP_DBL x = -(*pOvl--);
+- *pOut0 = IMDCT_SCALE_DBL(x);
+- pOut0++;
+- }
+-
+- if (noOutSamples <= nrSamples) {
+- /* Divert output second half to overlap buffer if we already got enough
+- * output samples. */
+- pOut1 = hMdct->overlap.time + hMdct->ov_offset + fl / 2 - 1;
+- hMdct->ov_offset += fl / 2 + nl;
+- } else {
+- pOut1 = pOut0 + (fl - 1);
+- nrSamples += fl / 2 + nl;
+- }
+-
+- /* output samples before window crossing point NR .. TL/2.
+- * -overlap[TL/2-NR..TL/2-NR-FL/2] + current[NR..TL/2] */
+- /* output samples after window crossing point TL/2 .. TL/2+FL/2.
+- * -overlap[0..FL/2] - current[TL/2..FL/2] */
+- pCurr = pSpec + tl - fl / 2;
+- if (currAliasingSymmetry == 0) {
+- for (i = 0; i < fl / 2; i++) {
+- FIXP_DBL x0, x1;
+-
+- cplxMult(&x1, &x0, *pCurr++, -*pOvl--, pWindow_prev[i]);
+- *pOut0 = IMDCT_SCALE_DBL(x0);
+- *pOut1 = IMDCT_SCALE_DBL(-x1);
+- pOut0++;
+- pOut1--;
+- }
+- } else {
+- if (hMdct->prevPrevAliasSymmetry == 0) {
+- /* Jump DST II -> DST IV for the second window */
+- for (i = 0; i < fl / 2; i++) {
+- FIXP_DBL x0, x1;
+-
+- cplxMult(&x1, &x0, *pCurr++, -*pOvl--, pWindow_prev[i]);
+- *pOut0 = IMDCT_SCALE_DBL(x0);
+- *pOut1 = IMDCT_SCALE_DBL(x1);
+- pOut0++;
+- pOut1--;
+- }
+- } else {
+- /* Jump DST IV -> DST IV from the second window on */
+- for (i = 0; i < fl / 2; i++) {
+- FIXP_DBL x0, x1;
+-
+- cplxMult(&x1, &x0, *pCurr++, *pOvl--, pWindow_prev[i]);
+- *pOut0 = IMDCT_SCALE_DBL(x0);
+- *pOut1 = IMDCT_SCALE_DBL(x1);
+- pOut0++;
+- pOut1--;
+- }
+- }
+- }
+-
+- if (hMdct->pFacZir != 0) {
+- /* add FAC ZIR of previous ACELP -> mdct transition */
+- FIXP_DBL *pOut = pOut0 - fl / 2;
+- FDK_ASSERT(fl / 2 <= 128);
+- for (i = 0; i < fl / 2; i++) {
+- pOut[i] += IMDCT_SCALE_DBL(hMdct->pFacZir[i]);
+- }
+- hMdct->pFacZir = NULL;
+- }
+- pOut0 += (fl / 2);
+-
+- /* NL output samples TL/2+FL/2..TL. - current[FL/2..0] */
+- pOut1 += (fl / 2) + 1;
+- pCurr = pSpec + tl - fl / 2 - 1;
+- for (i = 0; i < nl; i++) {
+- FIXP_DBL x = -(*pCurr--);
+- *pOut1 = IMDCT_SCALE_DBL(x);
+- pOut1++;
+- }
+-
+- /* Set overlap source pointer for next window pOvl = pSpec + tl/2 - 1; */
+- pOvl = pSpec + tl / 2 - 1;
+-
+- /* Previous window values. */
+- hMdct->prev_nr = nr;
+- hMdct->prev_fr = fr;
+- hMdct->prev_tl = tl;
+- hMdct->prev_wrs = pWindow_prev;
+- hMdct->prevPrevAliasSymmetry = hMdct->prevAliasSymmetry;
+- hMdct->prevAliasSymmetry = currAliasingSymmetry;
+- }
+-
+- /* Save overlap */
+-
+- pOvl = hMdct->overlap.freq + hMdct->ov_size - tl / 2;
+- FDK_ASSERT(pOvl >= hMdct->overlap.time + hMdct->ov_offset);
+- FDK_ASSERT(tl / 2 <= hMdct->ov_size);
+- for (i = 0; i < tl / 2; i++) {
+- pOvl[i] = _pSpec[i + (w - 1) * tl];
+- }
+-
+- return nrSamples;
+-}
+diff --git a/libAACdec/src/usacdec_fac.h b/libAACdec/src/usacdec_fac.h
+deleted file mode 100644
+index 100a6fa..0000000
+--- a/libAACdec/src/usacdec_fac.h
++++ /dev/null
+@@ -1,191 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Manuel Jander
+-
+- Description: USAC FAC
+-
+-*******************************************************************************/
+-
+-#ifndef USACDEC_FAC_H
+-#define USACDEC_FAC_H
+-
+-#include "channelinfo.h"
+-#include "FDK_bitstream.h"
+-
+-/**
+- * \brief Get the address of a memory area of the spectral data memory were the
+- * FAC data can be stored into.
+- * \param spec SPECTRAL_PTR pointing to the current spectral data.
+- * \param mod the current LPD mod array.
+- * \param pState pointer to a private state variable which must be 0 for the
+- * first call and not changed externally.
+- * \param isFullbandLPD is 1 if fullband LPD mode is on, otherwise it is 0.
+- */
+-FIXP_DBL *CLpd_FAC_GetMemory(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- UCHAR mod[NB_SUBFR], int *pState);
+-
+-/**
+- * \brief read a fac bitstream data block.
+- * \param hBs a bit stream handle, where the fac bitstream data is located.
+- * \param pFac pointer to were the FAC data will be stored into.
+- * \param pFacScale pointer to were the FAC data scale value will be stored
+- * into.
+- * \param tcx_gain value to be used as FAC gain. If zero, read fac_gain from
+- * bitstream.
+- * \param tcx_gain_e exponen value of tcx_gain.
+- * \param frame the subframe to be considered from the current superframe.
+- * Always 0 for FD case.
+- * \return 0 on success, -1 on error.
+- */
+-int CLpd_FAC_Read(HANDLE_FDK_BITSTREAM hBs, FIXP_DBL *pFac, SCHAR *pFacScale,
+- int length, int use_gain, int frame);
+-
+-/**
+- * \brief Apply TCX and ALFD gains to FAC data.
+- * \param fac_data pointer to FAC data.
+- * \param fac_length FAC length (128 or 96).
+- * \param tcx_gain TCX gain
+- * \param alfd_gains pointer to alfd gains.
+- * \param mod mod value (1,2,3) of TCX frame where the FAC signal needs to be
+- * applied.
+- */
+-void CFac_ApplyGains(FIXP_DBL fac_data[LFAC], const INT fac_length,
+- const FIXP_DBL tcx_gain, const FIXP_DBL alfd_gains[],
+- const INT mod);
+-
+-/**
+- * \brief Do FAC transition from frequency domain to ACELP domain.
+- */
+-INT CLpd_FAC_Mdct2Acelp(H_MDCT hMdct, FIXP_DBL *output, FIXP_DBL *pFac_data,
+- const int fac_data_e, FIXP_LPC *A, INT A_exp,
+- INT nrOutSamples, const INT fac_length,
+- const INT isFdFac, UCHAR prevWindowShape);
+-
+-/**
+- * \brief Do FAC transition from ACELP domain to frequency domain.
+- * \param hMdct MDCT context.
+- * \param output pointer for time domain output.
+- * \param pSpec pointer to MDCT spectrum input.
+- * \param spec_scale MDCT spectrum exponents.
+- * \param nSpec amount of contiguos MDCT spectra.
+- * \param pFac pointer to FAC MDCT domain data.
+- * \param fac_scale exponent of FAC data.
+- * \param fac_length length of FAC data.
+- * \param nrSamples room in samples in output buffer.
+- * \param tl MDCT transform length of pSpec.
+- * \param wrs right MDCT window slope.
+- * \param fr right MDCT window slope length.
+- * \param A LP domain filter coefficients.
+- * \param deemph_mem deemphasis filter state.
+- * \param gain gain to be applied to FAC data before overlap add.
+- * \param old_syn_mem Synthesis filter state.
+- * \param isFdFac indicates fac processing from or to FD.
+- * \param pFacData fac data stored for fullband LPD.
+- * \param elFlags element specific parser guidance flags.
+- * \param isFacForFullband indicates that fac is processed for fullband LPD.
+- */
+-INT CLpd_FAC_Acelp2Mdct(H_MDCT hMdct, FIXP_DBL *output, FIXP_DBL *pSpec,
+- const SHORT spec_scale[], const int nSpec,
+- FIXP_DBL *pFac_data, const int fac_data_e,
+- const INT fac_length, INT nrSamples, const INT tl,
+- const FIXP_WTP *wrs, const INT fr, FIXP_LPC A[16],
+- INT A_exp, CAcelpStaticMem *acelp_mem,
+- const FIXP_DBL gain, const int last_frame_lost,
+- const int isFdFac, const UCHAR last_lpd, const int k,
+- int currAliasingSymmetry);
+-
+-#endif /* USACDEC_FAC_H */
+diff --git a/libAACdec/src/usacdec_lpc.cpp b/libAACdec/src/usacdec_lpc.cpp
+deleted file mode 100644
+index 271463f..0000000
+--- a/libAACdec/src/usacdec_lpc.cpp
++++ /dev/null
+@@ -1,1194 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Matthias Hildenbrand, Manuel Jander
+-
+- Description: USAC LPC/AVQ decode
+-
+-*******************************************************************************/
+-
+-#include "usacdec_lpc.h"
+-
+-#include "usacdec_rom.h"
+-#include "FDK_trigFcts.h"
+-
+-#define NQ_MAX 36
+-
+-/*
+- * Helper functions.
+- */
+-
+-/**
+- * \brief Read unary code.
+- * \param hBs bitstream handle as data source.
+- * \return decoded value.
+- */
+-static int get_vlclbf(HANDLE_FDK_BITSTREAM hBs) {
+- int result = 0;
+-
+- while (FDKreadBits(hBs, 1) && result <= NQ_MAX) {
+- result++;
+- }
+- return result;
+-}
+-
+-/**
+- * \brief Read bit count limited unary code.
+- * \param hBs bitstream handle as data source
+- * \param n max amount of bits to be read.
+- * \return decoded value.
+- */
+-static int get_vlclbf_n(HANDLE_FDK_BITSTREAM hBs, int n) {
+- int result = 0;
+-
+- while (FDKreadBits(hBs, 1)) {
+- result++;
+- n--;
+- if (n <= 0) {
+- break;
+- }
+- }
+-
+- return result;
+-}
+-
+-/*
+- * Algebraic Vector Quantizer
+- */
+-
+-/* ZF_SCALE must be greater than (number of FIXP_ZF)/2
+- because the loss of precision caused by fPow2Div2 in RE8_PPV() */
+-//#define ZF_SCALE ((NQ_MAX-3)>>1)
+-#define ZF_SCALE ((DFRACT_BITS / 2))
+-#define FIXP_ZF FIXP_DBL
+-#define INT2ZF(x, s) (FIXP_ZF)((x) << (ZF_SCALE - (s)))
+-#define ZF2INT(x) (INT)((x) >> ZF_SCALE)
+-
+-/* 1.0 in ZF format format */
+-#define ONEZF ((FIXP_ZF)INT2ZF(1, 0))
+-
+-/* static */
+-void nearest_neighbor_2D8(FIXP_ZF x[8], int y[8]) {
+- FIXP_ZF s, em, e[8];
+- int i, j, sum;
+-
+- /* round x into 2Z^8 i.e. compute y=(y1,...,y8) such that yi = 2[xi/2]
+- where [.] is the nearest integer operator
+- in the mean time, compute sum = y1+...+y8
+- */
+- sum = 0;
+- for (i = 0; i < 8; i++) {
+- FIXP_ZF tmp;
+- /* round to ..., -2, 0, 2, ... ([-1..1[ --> 0) */
+- if (x[i] < (FIXP_ZF)0) {
+- tmp = ONEZF - x[i];
+- y[i] = -2 * ((ZF2INT(tmp)) >> 1);
+- } else {
+- tmp = ONEZF + x[i];
+- y[i] = 2 * ((ZF2INT(tmp)) >> 1);
+- }
+- sum += y[i];
+- }
+- /* check if y1+...+y8 is a multiple of 4
+- if not, y is not round xj in the wrong way where j is defined by
+- j = arg max_i | xi -yi|
+- (this is called the Wagner rule)
+- */
+- if (sum % 4) {
+- /* find j = arg max_i | xi -yi| */
+- em = (FIXP_SGL)0;
+- j = 0;
+- for (i = 0; i < 8; i++) {
+- /* compute ei = xi-yi */
+- e[i] = x[i] - INT2ZF(y[i], 0);
+- }
+- for (i = 0; i < 8; i++) {
+- /* compute |ei| = | xi-yi | */
+- if (e[i] < (FIXP_ZF)0) {
+- s = -e[i];
+- } else {
+- s = e[i];
+- }
+- /* check if |ei| is maximal, if so, set j=i */
+- if (em < s) {
+- em = s;
+- j = i;
+- }
+- }
+- /* round xj in the "wrong way" */
+- if (e[j] < (FIXP_ZF)0) {
+- y[j] -= 2;
+- } else {
+- y[j] += 2;
+- }
+- }
+-}
+-
+-/*--------------------------------------------------------------
+- RE8_PPV(x,y)
+- NEAREST NEIGHBOR SEARCH IN INFINITE LATTICE RE8
+- the algorithm is based on the definition of RE8 as
+- RE8 = (2D8) U (2D8+[1,1,1,1,1,1,1,1])
+- it applies the coset decoding of Sloane and Conway
+- (i) x: point in R^8 in 32-ZF_SCALE.ZF_SCALE format
+- (o) y: point in RE8 (8-dimensional integer vector)
+- --------------------------------------------------------------
+-*/
+-/* static */
+-void RE8_PPV(FIXP_ZF x[], SHORT y[], int r) {
+- int i, y0[8], y1[8];
+- FIXP_ZF x1[8], tmp;
+- FIXP_DBL e;
+-
+- /* find the nearest neighbor y0 of x in 2D8 */
+- nearest_neighbor_2D8(x, y0);
+- /* find the nearest neighbor y1 of x in 2D8+(1,...,1) (by coset decoding) */
+- for (i = 0; i < 8; i++) {
+- x1[i] = x[i] - ONEZF;
+- }
+- nearest_neighbor_2D8(x1, y1);
+- for (i = 0; i < 8; i++) {
+- y1[i] += 1;
+- }
+-
+- /* compute e0=||x-y0||^2 and e1=||x-y1||^2 */
+- e = (FIXP_DBL)0;
+- for (i = 0; i < 8; i++) {
+- tmp = x[i] - INT2ZF(y0[i], 0);
+- e += fPow2Div2(
+- tmp << r); /* shift left to ensure that no fract part bits get lost. */
+- tmp = x[i] - INT2ZF(y1[i], 0);
+- e -= fPow2Div2(tmp << r);
+- }
+- /* select best candidate y0 or y1 to minimize distortion */
+- if (e < (FIXP_DBL)0) {
+- for (i = 0; i < 8; i++) {
+- y[i] = y0[i];
+- }
+- } else {
+- for (i = 0; i < 8; i++) {
+- y[i] = y1[i];
+- }
+- }
+-}
+-
+-/* table look-up of unsigned value: find i where index >= table[i]
+- Note: range must be >= 2, index must be >= table[0] */
+-static int table_lookup(const USHORT *table, unsigned int index, int range) {
+- int i;
+-
+- for (i = 4; i < range; i += 4) {
+- if (index < table[i]) {
+- break;
+- }
+- }
+- if (i > range) {
+- i = range;
+- }
+-
+- if (index < table[i - 2]) {
+- i -= 2;
+- }
+- if (index < table[i - 1]) {
+- i--;
+- }
+- i--;
+-
+- return (i); /* index >= table[i] */
+-}
+-
+-/*--------------------------------------------------------------------------
+- re8_decode_rank_of_permutation(rank, xs, x)
+- DECODING OF THE RANK OF THE PERMUTATION OF xs
+- (i) rank: index (rank) of a permutation
+- (i) xs: signed leader in RE8 (8-dimensional integer vector)
+- (o) x: point in RE8 (8-dimensional integer vector)
+- --------------------------------------------------------------------------
+- */
+-static void re8_decode_rank_of_permutation(int rank, int *xs, SHORT x[8]) {
+- INT a[8], w[8], B, fac, fac_B, target;
+- int i, j;
+-
+- /* --- pre-processing based on the signed leader xs ---
+- - compute the alphabet a=[a[0] ... a[q-1]] of x (q elements)
+- such that a[0]!=...!=a[q-1]
+- it is assumed that xs is sorted in the form of a signed leader
+- which can be summarized in 2 requirements:
+- a) |xs[0]| >= |xs[1]| >= |xs[2]| >= ... >= |xs[7]|
+- b) if |xs[i]|=|xs[i-1]|, xs[i]>=xs[i+1]
+- where |.| indicates the absolute value operator
+- - compute q (the number of symbols in the alphabet)
+- - compute w[0..q-1] where w[j] counts the number of occurences of
+- the symbol a[j] in xs
+- - compute B = prod_j=0..q-1 (w[j]!) where .! is the factorial */
+- /* xs[i], xs[i-1] and ptr_w/a*/
+- j = 0;
+- w[j] = 1;
+- a[j] = xs[0];
+- B = 1;
+- for (i = 1; i < 8; i++) {
+- if (xs[i] != xs[i - 1]) {
+- j++;
+- w[j] = 1;
+- a[j] = xs[i];
+- } else {
+- w[j]++;
+- B *= w[j];
+- }
+- }
+-
+- /* --- actual rank decoding ---
+- the rank of x (where x is a permutation of xs) is based on
+- Schalkwijk's formula
+- it is given by rank=sum_{k=0..7} (A_k * fac_k/B_k)
+- the decoding of this rank is sequential and reconstructs x[0..7]
+- element by element from x[0] to x[7]
+- [the tricky part is the inference of A_k for each k...]
+- */
+-
+- if (w[0] == 8) {
+- for (i = 0; i < 8; i++) {
+- x[i] = a[0]; /* avoid fac of 40320 */
+- }
+- } else {
+- target = rank * B;
+- fac_B = 1;
+- /* decode x element by element */
+- for (i = 0; i < 8; i++) {
+- fac = fac_B * fdk_dec_tab_factorial[i]; /* fac = 1..5040 */
+- j = -1;
+- do {
+- target -= w[++j] * fac;
+- } while (target >= 0); /* max of 30 tests / SV */
+- x[i] = a[j];
+- /* update rank, denominator B (B_k) and counter w[j] */
+- target += w[j] * fac; /* target = fac_B*B*rank */
+- fac_B *= w[j];
+- w[j]--;
+- }
+- }
+-}
+-
+-/*--------------------------------------------------------------------------
+- re8_decode_base_index(n, I, y)
+- DECODING OF AN INDEX IN Qn (n=0,2,3 or 4)
+- (i) n: codebook number (*n is an integer defined in {0,2,3,4})
+- (i) I: index of c (pointer to unsigned 16-bit word)
+- (o) y: point in RE8 (8-dimensional integer vector)
+- note: the index I is defined as a 32-bit word, but only
+- 16 bits are required (long can be replaced by unsigned integer)
+- --------------------------------------------------------------------------
+- */
+-static void re8_decode_base_index(int *n, UINT index, SHORT y[8]) {
+- int i, im, t, sign_code, ka, ks, rank, leader[8];
+-
+- if (*n < 2) {
+- for (i = 0; i < 8; i++) {
+- y[i] = 0;
+- }
+- } else {
+- // index = (unsigned int)*I;
+- /* search for the identifier ka of the absolute leader (table-lookup)
+- Q2 is a subset of Q3 - the two cases are considered in the same branch
+- */
+- switch (*n) {
+- case 2:
+- case 3:
+- i = table_lookup(fdk_dec_I3, index, NB_LDQ3);
+- ka = fdk_dec_A3[i];
+- break;
+- case 4:
+- i = table_lookup(fdk_dec_I4, index, NB_LDQ4);
+- ka = fdk_dec_A4[i];
+- break;
+- default:
+- FDK_ASSERT(0);
+- return;
+- }
+- /* reconstruct the absolute leader */
+- for (i = 0; i < 8; i++) {
+- leader[i] = fdk_dec_Da[ka][i];
+- }
+- /* search for the identifier ks of the signed leader (table look-up)
+- (this search is focused based on the identifier ka of the absolute
+- leader)*/
+- t = fdk_dec_Ia[ka];
+- im = fdk_dec_Ns[ka];
+- ks = table_lookup(fdk_dec_Is + t, index, im);
+-
+- /* reconstruct the signed leader from its sign code */
+- sign_code = 2 * fdk_dec_Ds[t + ks];
+- for (i = 7; i >= 0; i--) {
+- leader[i] *= (1 - (sign_code & 2));
+- sign_code >>= 1;
+- }
+-
+- /* compute and decode the rank of the permutation */
+- rank = index - fdk_dec_Is[t + ks]; /* rank = index - cardinality offset */
+-
+- re8_decode_rank_of_permutation(rank, leader, y);
+- }
+- return;
+-}
+-
+-/* re8_y2k(y,m,k)
+- VORONOI INDEXING (INDEX DECODING) k -> y
+- (i) k: Voronoi index k[0..7]
+- (i) m: Voronoi modulo (m = 2^r = 1<<r, where r is integer >=2)
+- (i) r: Voronoi order (m = 2^r = 1<<r, where r is integer >=2)
+- (o) y: 8-dimensional point y[0..7] in RE8
+- */
+-static void re8_k2y(int *k, int r, SHORT *y) {
+- int i, tmp, sum;
+- SHORT v[8];
+- FIXP_ZF zf[8];
+-
+- FDK_ASSERT(r <= ZF_SCALE);
+-
+- /* compute y = k M and z=(y-a)/m, where
+- M = [4 ]
+- [2 2 ]
+- [| \ ]
+- [2 2 ]
+- [1 1 _ 1 1]
+- a=(2,0,...,0)
+- m = 1<<r
+- */
+- for (i = 0; i < 8; i++) {
+- y[i] = k[7];
+- }
+- zf[7] = INT2ZF(y[7], r);
+- sum = 0;
+- for (i = 6; i >= 1; i--) {
+- tmp = 2 * k[i];
+- sum += tmp;
+- y[i] += tmp;
+- zf[i] = INT2ZF(y[i], r);
+- }
+- y[0] += (4 * k[0] + sum);
+- zf[0] = INT2ZF(y[0] - 2, r);
+- /* find nearest neighbor v of z in infinite RE8 */
+- RE8_PPV(zf, v, r);
+- /* compute y -= m v */
+- for (i = 0; i < 8; i++) {
+- y[i] -= (SHORT)(v[i] << r);
+- }
+-}
+-
+-/*--------------------------------------------------------------------------
+- RE8_dec(n, I, k, y)
+- MULTI-RATE INDEXING OF A POINT y in THE LATTICE RE8 (INDEX DECODING)
+- (i) n: codebook number (*n is an integer defined in {0,2,3,4,..,n_max}). n_max
+- = 36 (i) I: index of c (pointer to unsigned 16-bit word) (i) k: index of v
+- (8-dimensional vector of binary indices) = Voronoi index (o) y: point in RE8
+- (8-dimensional integer vector) note: the index I is defined as a 32-bit word,
+- but only 16 bits are required (long can be replaced by unsigned integer)
+-
+- return 0 on success, -1 on error.
+- --------------------------------------------------------------------------
+- */
+-static int RE8_dec(int n, int I, int *k, FIXP_DBL *y) {
+- SHORT v[8];
+- SHORT _y[8];
+- UINT r;
+- int i;
+-
+- /* Check bound of codebook qn */
+- if (n > NQ_MAX) {
+- return -1;
+- }
+-
+- /* decode the sub-indices I and kv[] according to the codebook number n:
+- if n=0,2,3,4, decode I (no Voronoi extension)
+- if n>4, Voronoi extension is used, decode I and kv[] */
+- if (n <= 4) {
+- re8_decode_base_index(&n, I, _y);
+- for (i = 0; i < 8; i++) {
+- y[i] = (LONG)_y[i];
+- }
+- } else {
+- /* compute the Voronoi modulo m = 2^r where r is extension order */
+- r = ((n - 3) >> 1);
+-
+- while (n > 4) {
+- n -= 2;
+- }
+- /* decode base codebook index I into c (c is an element of Q3 or Q4)
+- [here c is stored in y to save memory] */
+- re8_decode_base_index(&n, I, _y);
+- /* decode Voronoi index k[] into v */
+- re8_k2y(k, r, v);
+- /* reconstruct y as y = m c + v (with m=2^r, r integer >=1) */
+- for (i = 0; i < 8; i++) {
+- y[i] = (LONG)((_y[i] << r) + v[i]);
+- }
+- }
+- return 0;
+-}
+-
+-/**************************/
+-/* start LPC decode stuff */
+-/**************************/
+-//#define M 16
+-#define FREQ_MAX 6400.0f
+-#define FREQ_DIV 400.0f
+-#define LSF_GAP 50.0f
+-
+-/**
+- * \brief calculate inverse weighting factor and add non-weighted residual
+- * LSF vector to first stage LSF approximation
+- * \param lsfq first stage LSF approximation values.
+- * \param xq weighted residual LSF vector
+- * \param nk_mode code book number coding mode.
+- */
+-static void lsf_weight_2st(FIXP_LPC *lsfq, FIXP_DBL *xq, int nk_mode) {
+- FIXP_LPC d[M_LP_FILTER_ORDER + 1];
+- FIXP_SGL factor;
+- LONG w; /* inverse weight factor */
+- int i;
+-
+- /* compute lsf distance */
+- d[0] = lsfq[0];
+- d[M_LP_FILTER_ORDER] =
+- FL2FXCONST_LPC(FREQ_MAX / (1 << LSF_SCALE)) - lsfq[M_LP_FILTER_ORDER - 1];
+- for (i = 1; i < M_LP_FILTER_ORDER; i++) {
+- d[i] = lsfq[i] - lsfq[i - 1];
+- }
+-
+- switch (nk_mode) {
+- case 0:
+- factor = FL2FXCONST_SGL(2.0f * 60.0f / FREQ_DIV);
+- break; /* abs */
+- case 1:
+- factor = FL2FXCONST_SGL(2.0f * 65.0f / FREQ_DIV);
+- break; /* mid */
+- case 2:
+- factor = FL2FXCONST_SGL(2.0f * 64.0f / FREQ_DIV);
+- break; /* rel1 */
+- default:
+- factor = FL2FXCONST_SGL(2.0f * 63.0f / FREQ_DIV);
+- break; /* rel2 */
+- }
+- /* add non-weighted residual LSF vector to LSF1st */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- w = (LONG)fMultDiv2(factor, sqrtFixp(fMult(d[i], d[i + 1])));
+- lsfq[i] = fAddSaturate(lsfq[i], FX_DBL2FX_LPC((FIXP_DBL)(w * (LONG)xq[i])));
+- }
+-
+- return;
+-}
+-
+-/**
+- * \brief decode nqn amount of code book numbers. These values determine the
+- * amount of following bits for nqn AVQ RE8 vectors.
+- * \param nk_mode quantization mode.
+- * \param nqn amount code book number to read.
+- * \param qn pointer to output buffer to hold decoded code book numbers qn.
+- */
+-static void decode_qn(HANDLE_FDK_BITSTREAM hBs, int nk_mode, int nqn,
+- int qn[]) {
+- int n;
+-
+- if (nk_mode == 1) { /* nk mode 1 */
+- /* Unary code for mid LPC1/LPC3 */
+- /* Q0=0, Q2=10, Q3=110, ... */
+- for (n = 0; n < nqn; n++) {
+- qn[n] = get_vlclbf(hBs);
+- if (qn[n] > 0) {
+- qn[n]++;
+- }
+- }
+- } else { /* nk_mode 0, 3 and 2 */
+- /* 2 bits to specify Q2,Q3,Q4,ext */
+- for (n = 0; n < nqn; n++) {
+- qn[n] = 2 + FDKreadBits(hBs, 2);
+- }
+- if (nk_mode == 2) {
+- /* Unary code for rel LPC1/LPC3 */
+- /* Q0 = 0, Q5=10, Q6=110, ... */
+- for (n = 0; n < nqn; n++) {
+- if (qn[n] > 4) {
+- qn[n] = get_vlclbf(hBs);
+- if (qn[n] > 0) qn[n] += 4;
+- }
+- }
+- } else { /* nk_mode == (0 and 3) */
+- /* Unary code for abs and rel LPC0/LPC2 */
+- /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */
+- for (n = 0; n < nqn; n++) {
+- if (qn[n] > 4) {
+- qn[n] = get_vlclbf(hBs);
+- switch (qn[n]) {
+- case 0:
+- qn[n] = 5;
+- break;
+- case 1:
+- qn[n] = 6;
+- break;
+- case 2:
+- qn[n] = 0;
+- break;
+- default:
+- qn[n] += 4;
+- break;
+- }
+- }
+- }
+- }
+- }
+-}
+-
+-/**
+- * \brief reorder LSF coefficients to minimum distance.
+- * \param lsf pointer to buffer containing LSF coefficients and where reordered
+- * LSF coefficients will be stored into, scaled by LSF_SCALE.
+- * \param min_dist min distance scaled by LSF_SCALE
+- * \param n number of LSF/LSP coefficients.
+- */
+-static void reorder_lsf(FIXP_LPC *lsf, FIXP_LPC min_dist, int n) {
+- FIXP_LPC lsf_min;
+- int i;
+-
+- lsf_min = min_dist;
+- for (i = 0; i < n; i++) {
+- if (lsf[i] < lsf_min) {
+- lsf[i] = lsf_min;
+- }
+- lsf_min = fAddSaturate(lsf[i], min_dist);
+- }
+-
+- /* reverse */
+- lsf_min = FL2FXCONST_LPC(FREQ_MAX / (1 << LSF_SCALE)) - min_dist;
+- for (i = n - 1; i >= 0; i--) {
+- if (lsf[i] > lsf_min) {
+- lsf[i] = lsf_min;
+- }
+-
+- lsf_min = lsf[i] - min_dist;
+- }
+-}
+-
+-/**
+- * \brief First stage approximation
+- * \param hBs bitstream handle as data source
+- * \param lsfq pointer to output buffer to hold LPC coefficients scaled by
+- * LSF_SCALE.
+- */
+-static void vlpc_1st_dec(
+- HANDLE_FDK_BITSTREAM hBs, /* input: codebook index */
+- FIXP_LPC *lsfq /* i/o: i:prediction o:quantized lsf */
+-) {
+- const FIXP_LPC *p_dico;
+- int i, index;
+-
+- index = FDKreadBits(hBs, 8);
+- p_dico = &fdk_dec_dico_lsf_abs_8b[index * M_LP_FILTER_ORDER];
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsfq[i] = p_dico[i];
+- }
+-}
+-
+-/**
+- * \brief Do first stage approximation weighting and multiply with AVQ
+- * refinement.
+- * \param hBs bitstream handle data ssource.
+- * \param lsfq buffer holding 1st stage approx, 2nd stage approx is added to
+- * this values.
+- * \param nk_mode quantization mode.
+- * \return 0 on success, -1 on error.
+- */
+-static int vlpc_2st_dec(
+- HANDLE_FDK_BITSTREAM hBs,
+- FIXP_LPC *lsfq, /* i/o: i:1st stage o:1st+2nd stage */
+- int nk_mode /* input: 0=abs, >0=rel */
+-) {
+- int err;
+- FIXP_DBL xq[M_LP_FILTER_ORDER]; /* weighted residual LSF vector */
+-
+- /* Decode AVQ refinement */
+- { err = CLpc_DecodeAVQ(hBs, xq, nk_mode, 2, 8); }
+- if (err != 0) {
+- return -1;
+- }
+-
+- /* add non-weighted residual LSF vector to LSF1st */
+- lsf_weight_2st(lsfq, xq, nk_mode);
+-
+- /* reorder */
+- reorder_lsf(lsfq, FL2FXCONST_LPC(LSF_GAP / (1 << LSF_SCALE)),
+- M_LP_FILTER_ORDER);
+-
+- return 0;
+-}
+-
+-/*
+- * Externally visible functions
+- */
+-
+-int CLpc_DecodeAVQ(HANDLE_FDK_BITSTREAM hBs, FIXP_DBL *pOutput, int nk_mode,
+- int no_qn, int length) {
+- int i, l;
+-
+- for (i = 0; i < length; i += 8 * no_qn) {
+- int qn[2], nk, n, I;
+- int kv[8] = {0};
+-
+- decode_qn(hBs, nk_mode, no_qn, qn);
+-
+- for (l = 0; l < no_qn; l++) {
+- if (qn[l] == 0) {
+- FDKmemclear(&pOutput[i + l * 8], 8 * sizeof(FIXP_DBL));
+- }
+-
+- /* Voronoi extension order ( nk ) */
+- nk = 0;
+- n = qn[l];
+- if (qn[l] > 4) {
+- nk = (qn[l] - 3) >> 1;
+- n = qn[l] - nk * 2;
+- }
+-
+- /* Base codebook index, in reverse bit group order (!) */
+- I = FDKreadBits(hBs, 4 * n);
+-
+- if (nk > 0) {
+- int j;
+-
+- for (j = 0; j < 8; j++) {
+- kv[j] = FDKreadBits(hBs, nk);
+- }
+- }
+-
+- if (RE8_dec(qn[l], I, kv, &pOutput[i + l * 8]) != 0) {
+- return -1;
+- }
+- }
+- }
+- return 0;
+-}
+-
+-int CLpc_Read(HANDLE_FDK_BITSTREAM hBs, FIXP_LPC lsp[][M_LP_FILTER_ORDER],
+- FIXP_LPC lpc4_lsf[M_LP_FILTER_ORDER],
+- FIXP_LPC lsf_adaptive_mean_cand[M_LP_FILTER_ORDER],
+- FIXP_SGL pStability[], UCHAR *mod, int first_lpd_flag,
+- int last_lpc_lost, int last_frame_ok) {
+- int i, k, err;
+- int mode_lpc_bin = 0; /* mode_lpc bitstream representation */
+- int lpc_present[5] = {0, 0, 0, 0, 0};
+- int lpc0_available = 1;
+- int s = 0;
+- int l = 3;
+- const int nbDiv = NB_DIV;
+-
+- lpc_present[4 >> s] = 1; /* LPC4 */
+-
+- /* Decode LPC filters in the following order: LPC 4,0,2,1,3 */
+-
+- /*** Decode LPC4 ***/
+- vlpc_1st_dec(hBs, lsp[4 >> s]);
+- err = vlpc_2st_dec(hBs, lsp[4 >> s], 0); /* nk_mode = 0 */
+- if (err != 0) {
+- return err;
+- }
+-
+- /*** Decode LPC0 and LPC2 ***/
+- k = 0;
+- if (!first_lpd_flag) {
+- lpc_present[0] = 1;
+- lpc0_available = !last_lpc_lost;
+- /* old LPC4 is new LPC0 */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[0][i] = lpc4_lsf[i];
+- }
+- /* skip LPC0 and continue with LPC2 */
+- k = 2;
+- }
+-
+- for (; k < l; k += 2) {
+- int nk_mode = 0;
+-
+- if ((k == 2) && (mod[0] == 3)) {
+- break; /* skip LPC2 */
+- }
+-
+- lpc_present[k >> s] = 1;
+-
+- mode_lpc_bin = FDKreadBit(hBs);
+-
+- if (mode_lpc_bin == 0) {
+- /* LPC0/LPC2: Abs */
+- vlpc_1st_dec(hBs, lsp[k >> s]);
+- } else {
+- /* LPC0/LPC2: RelR */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[k >> s][i] = lsp[4 >> s][i];
+- }
+- nk_mode = 3;
+- }
+-
+- err = vlpc_2st_dec(hBs, lsp[k >> s], nk_mode);
+- if (err != 0) {
+- return err;
+- }
+- }
+-
+- /*** Decode LPC1 ***/
+- if (mod[0] < 2) { /* else: skip LPC1 */
+- lpc_present[1] = 1;
+- mode_lpc_bin = get_vlclbf_n(hBs, 2);
+-
+- switch (mode_lpc_bin) {
+- case 1:
+- /* LPC1: abs */
+- vlpc_1st_dec(hBs, lsp[1]);
+- err = vlpc_2st_dec(hBs, lsp[1], 0);
+- if (err != 0) {
+- return err;
+- }
+- break;
+- case 2:
+- /* LPC1: mid0 (no second stage AVQ quantizer in this case) */
+- if (lpc0_available) { /* LPC0/lsf[0] might be zero some times */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[1][i] = (lsp[0][i] >> 1) + (lsp[2][i] >> 1);
+- }
+- } else {
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[1][i] = lsp[2][i];
+- }
+- }
+- break;
+- case 0:
+- /* LPC1: RelR */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[1][i] = lsp[2][i];
+- }
+- err = vlpc_2st_dec(hBs, lsp[1], 2 << s);
+- if (err != 0) {
+- return err;
+- }
+- break;
+- }
+- }
+-
+- /*** Decode LPC3 ***/
+- if ((mod[2] < 2)) { /* else: skip LPC3 */
+- int nk_mode = 0;
+- lpc_present[3] = 1;
+-
+- mode_lpc_bin = get_vlclbf_n(hBs, 3);
+-
+- switch (mode_lpc_bin) {
+- case 1:
+- /* LPC3: abs */
+- vlpc_1st_dec(hBs, lsp[3]);
+- break;
+- case 0:
+- /* LPC3: mid */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[3][i] = (lsp[2][i] >> 1) + (lsp[4][i] >> 1);
+- }
+- nk_mode = 1;
+- break;
+- case 2:
+- /* LPC3: relL */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[3][i] = lsp[2][i];
+- }
+- nk_mode = 2;
+- break;
+- case 3:
+- /* LPC3: relR */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[3][i] = lsp[4][i];
+- }
+- nk_mode = 2;
+- break;
+- }
+- err = vlpc_2st_dec(hBs, lsp[3], nk_mode);
+- if (err != 0) {
+- return err;
+- }
+- }
+-
+- if (!lpc0_available && !last_frame_ok) {
+- /* LPC(0) was lost. Use next available LPC(k) instead */
+- for (k = 1; k < (nbDiv + 1); k++) {
+- if (lpc_present[k]) {
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+-#define LSF_INIT_TILT (0.25f)
+- if (mod[0] > 0) {
+- lsp[0][i] = FX_DBL2FX_LPC(
+- fMult(lsp[k][i], FL2FXCONST_SGL(1.0f - LSF_INIT_TILT)) +
+- fMult(fdk_dec_lsf_init[i], FL2FXCONST_SGL(LSF_INIT_TILT)));
+- } else {
+- lsp[0][i] = lsp[k][i];
+- }
+- }
+- break;
+- }
+- }
+- }
+-
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lpc4_lsf[i] = lsp[4 >> s][i];
+- }
+-
+- {
+- FIXP_DBL divFac;
+- int last, numLpc = 0;
+-
+- i = nbDiv;
+- do {
+- numLpc += lpc_present[i--];
+- } while (i >= 0 && numLpc < 3);
+-
+- last = i;
+-
+- switch (numLpc) {
+- case 3:
+- divFac = FL2FXCONST_DBL(1.0f / 3.0f);
+- break;
+- case 2:
+- divFac = FL2FXCONST_DBL(1.0f / 2.0f);
+- break;
+- default:
+- divFac = FL2FXCONST_DBL(1.0f);
+- break;
+- }
+-
+- /* get the adaptive mean for the next (bad) frame */
+- for (k = 0; k < M_LP_FILTER_ORDER; k++) {
+- FIXP_DBL tmp = (FIXP_DBL)0;
+- for (i = nbDiv; i > last; i--) {
+- if (lpc_present[i]) {
+- tmp = fMultAdd(tmp >> 1, lsp[i][k], divFac);
+- }
+- }
+- lsf_adaptive_mean_cand[k] = FX_DBL2FX_LPC(tmp);
+- }
+- }
+-
+- /* calculate stability factor Theta. Needed for ACELP decoder and concealment
+- */
+- {
+- FIXP_LPC *lsf_prev, *lsf_curr;
+- k = 0;
+-
+- FDK_ASSERT(lpc_present[0] == 1 && lpc_present[4 >> s] == 1);
+- lsf_prev = lsp[0];
+- for (i = 1; i < (nbDiv + 1); i++) {
+- if (lpc_present[i]) {
+- FIXP_DBL tmp = (FIXP_DBL)0;
+- int j;
+- lsf_curr = lsp[i];
+-
+- /* sum = tmp * 2^(LSF_SCALE*2 + 4) */
+- for (j = 0; j < M_LP_FILTER_ORDER; j++) {
+- tmp += fPow2Div2((FIXP_SGL)(lsf_curr[j] - lsf_prev[j])) >> 3;
+- }
+-
+- /* tmp = (float)(FL2FXCONST_DBL(1.25f) - fMult(tmp,
+- * FL2FXCONST_DBL(1/400000.0f))); */
+- tmp = FL2FXCONST_DBL(1.25f / (1 << LSF_SCALE)) -
+- fMult(tmp, FL2FXCONST_DBL((1 << (LSF_SCALE + 4)) / 400000.0f));
+- if (tmp >= FL2FXCONST_DBL(1.0f / (1 << LSF_SCALE))) {
+- pStability[k] = FL2FXCONST_SGL(1.0f / 2.0f);
+- } else if (tmp < FL2FXCONST_DBL(0.0f)) {
+- pStability[k] = FL2FXCONST_SGL(0.0f);
+- } else {
+- pStability[k] = FX_DBL2FX_SGL(tmp << (LSF_SCALE - 1));
+- }
+-
+- lsf_prev = lsf_curr;
+- k = i;
+- } else {
+- /* Mark stability value as undefined. */
+- pStability[i] = (FIXP_SGL)-1;
+- }
+- }
+- }
+-
+- /* convert into LSP domain */
+- for (i = 0; i < (nbDiv + 1); i++) {
+- if (lpc_present[i]) {
+- for (k = 0; k < M_LP_FILTER_ORDER; k++) {
+- lsp[i][k] = FX_DBL2FX_LPC(
+- fixp_cos(fMult(lsp[i][k],
+- FL2FXCONST_SGL((1 << LSPARG_SCALE) * M_PI / 6400.0)),
+- LSF_SCALE - LSPARG_SCALE));
+- }
+- }
+- }
+-
+- return 0;
+-}
+-
+-void CLpc_Conceal(FIXP_LPC lsp[][M_LP_FILTER_ORDER],
+- FIXP_LPC lpc4_lsf[M_LP_FILTER_ORDER],
+- FIXP_LPC lsf_adaptive_mean[M_LP_FILTER_ORDER],
+- const int first_lpd_flag) {
+- int i, j;
+-
+-#define BETA (FL2FXCONST_SGL(0.25f))
+-#define ONE_BETA (FL2FXCONST_SGL(0.75f))
+-#define BFI_FAC (FL2FXCONST_SGL(0.90f))
+-#define ONE_BFI_FAC (FL2FXCONST_SGL(0.10f))
+-
+- /* Frame loss concealment (could be improved) */
+-
+- if (first_lpd_flag) {
+- /* Reset past LSF values */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[0][i] = lpc4_lsf[i] = fdk_dec_lsf_init[i];
+- }
+- } else {
+- /* old LPC4 is new LPC0 */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[0][i] = lpc4_lsf[i];
+- }
+- }
+-
+- /* LPC1 */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- FIXP_LPC lsf_mean = FX_DBL2FX_LPC(fMult(BETA, fdk_dec_lsf_init[i]) +
+- fMult(ONE_BETA, lsf_adaptive_mean[i]));
+-
+- lsp[1][i] = FX_DBL2FX_LPC(fMult(BFI_FAC, lpc4_lsf[i]) +
+- fMult(ONE_BFI_FAC, lsf_mean));
+- }
+-
+- /* LPC2 - LPC4 */
+- for (j = 2; j <= 4; j++) {
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- /* lsf_mean[i] = FX_DBL2FX_LPC(fMult((FIXP_LPC)(BETA + j *
+- FL2FXCONST_LPC(0.1f)), fdk_dec_lsf_init[i])
+- + fMult((FIXP_LPC)(ONE_BETA - j *
+- FL2FXCONST_LPC(0.1f)), lsf_adaptive_mean[i])); */
+-
+- FIXP_LPC lsf_mean = FX_DBL2FX_LPC(
+- fMult((FIXP_SGL)(BETA + (FIXP_SGL)(j * (INT)FL2FXCONST_SGL(0.1f))),
+- (FIXP_SGL)fdk_dec_lsf_init[i]) +
+- fMult(
+- (FIXP_SGL)(ONE_BETA - (FIXP_SGL)(j * (INT)FL2FXCONST_SGL(0.1f))),
+- lsf_adaptive_mean[i]));
+-
+- lsp[j][i] = FX_DBL2FX_LPC(fMult(BFI_FAC, lsp[j - 1][i]) +
+- fMult(ONE_BFI_FAC, lsf_mean));
+- }
+- }
+-
+- /* Update past values for the future */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lpc4_lsf[i] = lsp[4][i];
+- }
+-
+- /* convert into LSP domain */
+- for (j = 0; j < 5; j++) {
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- lsp[j][i] = FX_DBL2FX_LPC(fixp_cos(
+- fMult(lsp[j][i], FL2FXCONST_SGL((1 << LSPARG_SCALE) * M_PI / 6400.0)),
+- LSF_SCALE - LSPARG_SCALE));
+- }
+- }
+-}
+-
+-void E_LPC_a_weight(FIXP_LPC *wA, const FIXP_LPC *A, int m) {
+- FIXP_DBL f;
+- int i;
+-
+- f = FL2FXCONST_DBL(0.92f);
+- for (i = 0; i < m; i++) {
+- wA[i] = FX_DBL2FX_LPC(fMult(A[i], f));
+- f = fMult(f, FL2FXCONST_DBL(0.92f));
+- }
+-}
+-
+-void CLpd_DecodeGain(FIXP_DBL *gain, INT *gain_e, int gain_code) {
+- /* gain * 2^(gain_e) = 10^(gain_code/28) */
+- *gain = fLdPow(
+- FL2FXCONST_DBL(3.3219280948873623478703194294894 / 4.0), /* log2(10)*/
+- 2,
+- fMultDiv2((FIXP_DBL)gain_code << (DFRACT_BITS - 1 - 7),
+- FL2FXCONST_DBL(2.0f / 28.0f)),
+- 7, gain_e);
+-}
+-
+- /**
+- * \brief * Find the polynomial F1(z) or F2(z) from the LSPs.
+- * This is performed by expanding the product polynomials:
+- *
+- * F1(z) = product ( 1 - 2 LSP_i z^-1 + z^-2 )
+- * i=0,2,4,6,8
+- * F2(z) = product ( 1 - 2 LSP_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
+- * \param lsp input, line spectral freq. (cosine domain)
+- * \param f output, the coefficients of F1 or F2, scaled by 8 bits
+- * \param n no of coefficients (m/2)
+- * \param flag 1 : F1(z) ; 2 : F2(z)
+- */
+-
+-#define SF_F 8
+-
+-static void get_lsppol(FIXP_LPC lsp[], FIXP_DBL f[], int n, int flag) {
+- FIXP_DBL b;
+- FIXP_LPC *plsp;
+- int i, j;
+-
+- plsp = lsp + flag - 1;
+- f[0] = FL2FXCONST_DBL(1.0f / (1 << SF_F));
+- b = -FX_LPC2FX_DBL(*plsp);
+- f[1] = b >> (SF_F - 1);
+- for (i = 2; i <= n; i++) {
+- plsp += 2;
+- b = -FX_LPC2FX_DBL(*plsp);
+- f[i] = ((fMultDiv2(b, f[i - 1]) << 1) + (f[i - 2])) << 1;
+- for (j = i - 1; j > 1; j--) {
+- f[j] = f[j] + (fMultDiv2(b, f[j - 1]) << 2) + f[j - 2];
+- }
+- f[1] = f[1] + (b >> (SF_F - 1));
+- }
+- return;
+-}
+-
+-#define NC M_LP_FILTER_ORDER / 2
+-
+-/**
+- * \brief lsp input LSP vector
+- * \brief a output LP filter coefficient vector scaled by SF_A_COEFFS.
+- */
+-void E_LPC_f_lsp_a_conversion(FIXP_LPC *lsp, FIXP_LPC *a, INT *a_exp) {
+- FIXP_DBL f1[NC + 1], f2[NC + 1];
+- int i, k;
+-
+- /*-----------------------------------------------------*
+- * 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) *
+- *-----------------------------------------------------*/
+- for (i = NC; i > 0; i--) {
+- f1[i] += f1[i - 1];
+- f2[i] -= f2[i - 1];
+- }
+-
+- FIXP_DBL aDBL[M_LP_FILTER_ORDER];
+-
+- for (i = 1, k = M_LP_FILTER_ORDER - 1; i <= NC; i++, k--) {
+- FIXP_DBL tmp1, tmp2;
+-
+- tmp1 = f1[i] >> 1;
+- tmp2 = f2[i] >> 1;
+-
+- aDBL[i - 1] = (tmp1 + tmp2);
+- aDBL[k] = (tmp1 - tmp2);
+- }
+-
+- int headroom_a = getScalefactor(aDBL, M_LP_FILTER_ORDER);
+-
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- a[i] = FX_DBL2FX_LPC(aDBL[i] << headroom_a);
+- }
+-
+- *a_exp = 8 - headroom_a;
+-}
+diff --git a/libAACdec/src/usacdec_lpc.h b/libAACdec/src/usacdec_lpc.h
+deleted file mode 100644
+index a6713c1..0000000
+--- a/libAACdec/src/usacdec_lpc.h
++++ /dev/null
+@@ -1,190 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Matthias Hildenbrand, Manuel Jander
+-
+- Description: USAC LPC/AVQ decode
+-
+-*******************************************************************************/
+-
+-#ifndef USACDEC_LPC_H
+-#define USACDEC_LPC_H
+-
+-#include "channelinfo.h"
+-#include "common_fix.h"
+-#include "FDK_bitstream.h"
+-#include "usacdec_rom.h"
+-
+-#define LSPARG_SCALE 10
+-
+-/**
+- * \brief AVQ (refinement) decode
+- * \param hBs bitstream handle
+- * \param lsfq buffer for AVQ decode output.
+- * \param nk_mode quantization mode.
+- * \param nqn amount of split/interleaved RE8 vectors.
+- * \param total amount of individual data values to decode.
+- * \return 0 on success, -1 on error.
+- */
+-int CLpc_DecodeAVQ(HANDLE_FDK_BITSTREAM hBs, FIXP_DBL *lsfq, int nk_mode,
+- int nqn, int length);
+-
+-/**
+- * \brief Read and decode LPC coeficient sets. First stage approximation + AVQ
+- * decode.
+- * \param[in] hBs bitstream handle to read data from.
+- * \param[out] lsp buffer into which the decoded LSP coefficients will be stored
+- * into.
+- * \param[in,out] lpc4_lsf buffer into which the decoded LCP4 LSF coefficients
+- * will be stored into (persistent).
+- * \param[out] lsf_adaptive_mean_cand lsf adaptive mean vector needed for
+- * concealment.
+- * \param[out] pStability array with stability values for the ACELP decoder (and
+- * concealment).
+- * \param[in] mod array which defines modes (ACELP, TCX20|40|80) are used in
+- * the current superframe.
+- * \param[in] first_lpd_flag indicates the presence of LPC0
+- * \param[in] last_lpc_lost indicate that LPC4 of previous frame was lost.
+- * \param[in] last_frame_ok indicate that the last frame was ok.
+- * \return 0 on success, -1 on error.
+- */
+-int CLpc_Read(HANDLE_FDK_BITSTREAM hBs, FIXP_LPC lsp[][M_LP_FILTER_ORDER],
+- FIXP_LPC lpc4_lsf[M_LP_FILTER_ORDER],
+- FIXP_LPC lsf_adaptive_mean_cand[M_LP_FILTER_ORDER],
+- FIXP_SGL pStability[], UCHAR *mod, int first_lpd_flag,
+- int last_lpc_lost, int last_frame_ok);
+-
+-/**
+- * \brief Generate LPC coefficient sets in case frame loss.
+- * \param lsp buffer into which the decoded LSP coefficients will be stored
+- * into.
+- * \param lpc4_lsf buffer into which the decoded LCP4 LSF coefficients will be
+- * stored into (persistent).
+- * \param isf_adaptive_mean
+- * \param first_lpd_flag indicates the previous LSF4 coefficients lpc4_lsf[] are
+- * not valid.
+- */
+-void CLpc_Conceal(FIXP_LPC lsp[][M_LP_FILTER_ORDER],
+- FIXP_LPC lpc4_lsf[M_LP_FILTER_ORDER],
+- FIXP_LPC isf_adaptive_mean[M_LP_FILTER_ORDER],
+- const int first_lpd_flag);
+-
+-/**
+- * \brief apply absolute weighting
+- * \param A weighted LPC coefficient vector output. The first coeffcient is
+- * implicitly 1.0
+- * \param A LPC coefficient vector. The first coeffcient is implicitly 1.0
+- * \param m length of vector A
+- */
+-/* static */
+-void E_LPC_a_weight(FIXP_LPC *wA, const FIXP_LPC *A, const int m);
+-
+-/**
+- * \brief decode TCX/FAC gain. In case of TCX the lg/sqrt(rms) part
+- * must still be applied to obtain the gain value.
+- * \param gain (o) pointer were the gain mantissa is stored into.
+- * \param gain_e (o) pointer were the gain exponent is stored into.
+- * \param gain_code (i) the 7 bit binary word from the bitstream
+- * representing the gain.
+- */
+-void CLpd_DecodeGain(FIXP_DBL *gain, INT *gain_e, int gain_code);
+-
+-/**
+- * \brief convert LSP coefficients into LP domain.
+- */
+-void E_LPC_f_lsp_a_conversion(FIXP_LPC *lsp, FIXP_LPC *a, INT *a_exp);
+-
+-#endif /* USACDEC_LPC_H */
+diff --git a/libAACdec/src/usacdec_lpd.cpp b/libAACdec/src/usacdec_lpd.cpp
+deleted file mode 100644
+index fcf7a76..0000000
+--- a/libAACdec/src/usacdec_lpd.cpp
++++ /dev/null
+@@ -1,2017 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Manuel Jander
+-
+- Description: USAC Linear Prediction Domain coding
+-
+-*******************************************************************************/
+-
+-#include "usacdec_lpd.h"
+-
+-#include "usacdec_rom.h"
+-#include "usacdec_fac.h"
+-#include "usacdec_lpc.h"
+-#include "FDK_tools_rom.h"
+-#include "fft.h"
+-#include "mdct.h"
+-#include "usacdec_acelp.h"
+-#include "overlapadd.h"
+-
+-#include "block.h"
+-
+-#define SF_PITCH_TRACK 6
+-#define SF_GAIN 3
+-#define MIN_VAL FL2FXCONST_DBL(0.0f)
+-#define MAX_VAL (FIXP_DBL) MAXVAL_DBL
+-
+-#include "ac_arith_coder.h"
+-
+-void filtLP(const FIXP_DBL *syn, FIXP_PCM *syn_out, FIXP_DBL *noise,
+- const FIXP_SGL *filt, INT stop, int len) {
+- INT i, j;
+- FIXP_DBL tmp;
+-
+- for (i = 0; i < stop; i++) {
+- tmp = fMultDiv2(noise[i], filt[0]); // Filt in Q-1.16
+- for (j = 1; j <= len; j++) {
+- tmp += fMultDiv2((noise[i - j] + noise[i + j]), filt[j]);
+- }
+- syn_out[i] = (FIXP_PCM)(IMDCT_SCALE(syn[i] - tmp));
+- }
+-}
+-
+-void bass_pf_1sf_delay(
+- FIXP_DBL *syn, /* (i) : 12.8kHz synthesis to postfilter */
+- const INT *T_sf, /* (i) : Pitch period for all subframes (T_sf[16]) */
+- FIXP_DBL *pit_gain,
+- const int frame_length, /* (i) : frame length (should be 768|1024) */
+- const INT l_frame,
+- const INT l_next, /* (i) : look ahead for symmetric filtering */
+- FIXP_PCM *synth_out, /* (o) : filtered synthesis (with delay of 1 subfr) */
+- FIXP_DBL mem_bpf[]) /* i/o : memory state [L_FILT+L_SUBFR] */
+-{
+- INT i, sf, i_subfr, T, T2, lg;
+-
+- FIXP_DBL tmp, ener, corr, gain;
+- FIXP_DBL *noise, *noise_in;
+- FIXP_DBL
+- noise_buf[L_FILT + (2 * L_SUBFR)]; // L_FILT = 12, L_SUBFR = 64 => 140
+- const FIXP_DBL *x, *y;
+-
+- {
+- noise = noise_buf + L_FILT; // L_FILT = 12 delay of upsampling filter
+- noise_in = noise_buf + L_FILT + L_SUBFR;
+- /* Input scaling of the BPF memory */
+- scaleValues(mem_bpf, (L_FILT + L_SUBFR), 1);
+- }
+-
+- int gain_exp = 17;
+-
+- sf = 0;
+- for (i_subfr = 0; i_subfr < l_frame; i_subfr += L_SUBFR, sf++) {
+- T = T_sf[sf];
+- gain = pit_gain[sf];
+-
+- /* Gain is in Q17.14 */
+- /* If gain > 1 set to 1 */
+- if (gain > (FIXP_DBL)(1 << 14)) gain = (FIXP_DBL)(1 << 14);
+-
+- /* If gain < 0 set to 0 */
+- if (gain < (FIXP_DBL)0) gain = (FIXP_DBL)0;
+-
+- if (gain > (FIXP_DBL)0) {
+- /* pitch tracker: test pitch/2 to avoid continuous pitch doubling */
+- /* Note: pitch is limited to PIT_MIN (34 = 376Hz) at the encoder */
+- T2 = T >> 1;
+- x = &syn[i_subfr - L_EXTRA];
+- y = &syn[i_subfr - T2 - L_EXTRA];
+-
+- ener = (FIXP_DBL)0;
+- corr = (FIXP_DBL)0;
+- tmp = (FIXP_DBL)0;
+-
+- int headroom_x = getScalefactor(x, L_SUBFR + L_EXTRA);
+- int headroom_y = getScalefactor(y, L_SUBFR + L_EXTRA);
+-
+- int width_shift = 7;
+-
+- for (i = 0; i < (L_SUBFR + L_EXTRA); i++) {
+- ener += fPow2Div2((x[i] << headroom_x)) >> width_shift;
+- corr += fMultDiv2((x[i] << headroom_x), (y[i] << headroom_y)) >>
+- width_shift;
+- tmp += fPow2Div2((y[i] << headroom_y)) >> width_shift;
+- }
+-
+- int exp_ener = ((17 - headroom_x) << 1) + width_shift + 1;
+- int exp_corr = (17 - headroom_x) + (17 - headroom_y) + width_shift + 1;
+- int exp_tmp = ((17 - headroom_y) << 1) + width_shift + 1;
+-
+- /* Add 0.01 to "ener". Adjust exponents */
+- FIXP_DBL point_zero_one = (FIXP_DBL)0x51eb851f; /* In Q-6.37 */
+- int diff;
+- ener = fAddNorm(ener, exp_ener, point_zero_one, -6, &exp_ener);
+- corr = fAddNorm(corr, exp_corr, point_zero_one, -6, &exp_corr);
+- tmp = fAddNorm(tmp, exp_tmp, point_zero_one, -6, &exp_tmp);
+-
+- /* use T2 if normalized correlation > 0.95 */
+- INT s1, s2;
+- s1 = CntLeadingZeros(ener) - 1;
+- s2 = CntLeadingZeros(tmp) - 1;
+-
+- FIXP_DBL ener_by_tmp = fMultDiv2(ener << s1, tmp << s2);
+- int ener_by_tmp_exp = (exp_ener - s1) + (exp_tmp - s2) + 1;
+-
+- if (ener_by_tmp_exp & 1) {
+- ener_by_tmp <<= 1;
+- ener_by_tmp_exp -= 1;
+- }
+-
+- int temp_exp = 0;
+-
+- FIXP_DBL temp1 = invSqrtNorm2(ener_by_tmp, &temp_exp);
+-
+- int temp1_exp = temp_exp - (ener_by_tmp_exp >> 1);
+-
+- FIXP_DBL tmp_result = fMult(corr, temp1);
+-
+- int tmp_result_exp = exp_corr + temp1_exp;
+-
+- diff = tmp_result_exp - 0;
+- FIXP_DBL point95 = FL2FXCONST_DBL(0.95f);
+- if (diff >= 0) {
+- diff = fMin(diff, 31);
+- point95 = FL2FXCONST_DBL(0.95f) >> diff;
+- } else {
+- diff = fMax(diff, -31);
+- tmp_result >>= (-diff);
+- }
+-
+- if (tmp_result > point95) T = T2;
+-
+- /* prevent that noise calculation below reaches into not defined signal
+- parts at the end of the synth_buf or in other words restrict the below
+- used index (i+i_subfr+T) < l_frame + l_next
+- */
+- lg = l_frame + l_next - T - i_subfr;
+-
+- if (lg > L_SUBFR)
+- lg = L_SUBFR;
+- else if (lg < 0)
+- lg = 0;
+-
+- /* limit gain to avoid problem on burst */
+- if (lg > 0) {
+- FIXP_DBL tmp1;
+-
+- /* max(lg) = 64 => scale with 6 bits minus 1 (fPow2Div2) */
+-
+- s1 = getScalefactor(&syn[i_subfr], lg);
+- s2 = getScalefactor(&syn[i_subfr + T], lg);
+- INT s = fixMin(s1, s2);
+-
+- tmp = (FIXP_DBL)0;
+- ener = (FIXP_DBL)0;
+- for (i = 0; i < lg; i++) {
+- tmp += fPow2Div2(syn[i + i_subfr] << s1) >> (SF_PITCH_TRACK);
+- ener += fPow2Div2(syn[i + i_subfr + T] << s2) >> (SF_PITCH_TRACK);
+- }
+- tmp = tmp >> fMin(DFRACT_BITS - 1, (2 * (s1 - s)));
+- ener = ener >> fMin(DFRACT_BITS - 1, (2 * (s2 - s)));
+-
+- /* error robustness: for the specific case syn[...] == -1.0f for all 64
+- samples ener or tmp might overflow and become negative. For all sane
+- cases we have enough headroom.
+- */
+- if (ener <= (FIXP_DBL)0) {
+- ener = (FIXP_DBL)1;
+- }
+- if (tmp <= (FIXP_DBL)0) {
+- tmp = (FIXP_DBL)1;
+- }
+- FDK_ASSERT(ener > (FIXP_DBL)0);
+-
+- /* tmp = sqrt(tmp/ener) */
+- int result_e = 0;
+- tmp1 = fDivNorm(tmp, ener, &result_e);
+- if (result_e & 1) {
+- tmp1 >>= 1;
+- result_e += 1;
+- }
+- tmp = sqrtFixp(tmp1);
+- result_e >>= 1;
+-
+- gain_exp = 17;
+-
+- diff = result_e - gain_exp;
+-
+- FIXP_DBL gain1 = gain;
+-
+- if (diff >= 0) {
+- diff = fMin(diff, 31);
+- gain1 >>= diff;
+- } else {
+- result_e += (-diff);
+- diff = fMax(diff, -31);
+- tmp >>= (-diff);
+- }
+-
+- if (tmp < gain1) {
+- gain = tmp;
+- gain_exp = result_e;
+- }
+- }
+-
+- /* calculate noise based on voiced pitch */
+- /* fMultDiv2() replaces weighting of gain with 0.5 */
+- diff = gain_exp - 17;
+- if (diff >= 0) {
+- gain <<= diff;
+- } else {
+- gain >>= (-diff);
+- }
+-
+- s1 = CntLeadingZeros(gain) - 1;
+- s1 -= 16; /* Leading bits for SGL */
+-
+- FIXP_SGL gainSGL = FX_DBL2FX_SGL(gain << 16);
+-
+- gainSGL = gainSGL << s1;
+-
+- {
+- for (i = 0; i < lg; i++) {
+- /* scaled with SF_SYNTH + gain_sf + 1 */
+- noise_in[i] =
+- (fMult(gainSGL, syn[i + i_subfr] - (syn[i + i_subfr - T] >> 1) -
+- (syn[i + i_subfr + T] >> 1))) >>
+- s1;
+- }
+-
+- for (i = lg; i < L_SUBFR; i++) {
+- /* scaled with SF_SYNTH + gain_sf + 1 */
+- noise_in[i] =
+- (fMult(gainSGL, syn[i + i_subfr] - syn[i + i_subfr - T])) >> s1;
+- }
+- }
+- } else {
+- FDKmemset(noise_in, (FIXP_DBL)0, L_SUBFR * sizeof(FIXP_DBL));
+- }
+-
+- {
+- FDKmemcpy(noise_buf, mem_bpf, (L_FILT + L_SUBFR) * sizeof(FIXP_DBL));
+-
+- FDKmemcpy(mem_bpf, noise_buf + L_SUBFR,
+- (L_FILT + L_SUBFR) * sizeof(FIXP_DBL));
+- }
+-
+- /* substract from voiced speech low-pass filtered noise */
+- /* filter coefficients are scaled with factor SF_FILT_LP (1) */
+-
+- {
+- filtLP(&syn[i_subfr - L_SUBFR], &synth_out[i_subfr], noise,
+- fdk_dec_filt_lp, L_SUBFR, L_FILT);
+- }
+- }
+-
+- {
+-
+- }
+-
+- // To be determined (info from Ben)
+- {
+- /* Output scaling of the BPF memory */
+- scaleValues(mem_bpf, (L_FILT + L_SUBFR), -1);
+- /* Copy the rest of the signal (after the fac) */
+- scaleValuesSaturate((FIXP_PCM *)&synth_out[l_frame],
+- (FIXP_DBL *)&syn[l_frame - L_SUBFR],
+- (frame_length - l_frame), MDCT_OUT_HEADROOM);
+- }
+-
+- return;
+-}
+-
+-/*
+- * Frequency Domain Noise Shaping
+- */
+-
+-/**
+- * \brief Adaptive Low Frequencies Deemphasis of spectral coefficients.
+- *
+- * Ensure quantization of low frequencies in case where the
+- * signal dynamic is higher than the LPC noise shaping.
+- * This is the inverse operation of adap_low_freq_emph().
+- * Output gain of all blocks.
+- *
+- * \param x pointer to the spectral coefficients, requires 1 bit headroom.
+- * \param lg length of x.
+- * \param bUseNewAlfe if set, apply ALFD for fullband lpd.
+- * \param gainLpc1 pointer to gain based on old input LPC coefficients.
+- * \param gainLpc2 pointer to gain based on new input LPC coefficients.
+- * \param alfd_gains pointer to output gains.
+- * \param s current scale shift factor of x.
+- */
+-#define ALFDPOW2_SCALE 3
+-/*static*/
+-void CLpd_AdaptLowFreqDeemph(FIXP_DBL x[], int lg, FIXP_DBL alfd_gains[],
+- INT s) {
+- {
+- int i, j, k, i_max;
+- FIXP_DBL max, fac;
+- /* Note: This stack array saves temporary accumulation results to be used in
+- * a second run */
+- /* The size should be limited to (1024/4)/8=32 */
+- FIXP_DBL tmp_pow2[32];
+-
+- s = s * 2 + ALFDPOW2_SCALE;
+- s = fMin(31, s);
+-
+- k = 8;
+- i_max = lg / 4; /* ALFD range = 1600Hz (lg = 6400Hz) */
+-
+- /* find spectral peak */
+- max = FL2FX_DBL(0.01f) >> s;
+- for (i = 0; i < i_max; i += k) {
+- FIXP_DBL tmp;
+-
+- tmp = FIXP_DBL(0);
+- FIXP_DBL *pX = &x[i];
+-
+- j = 8;
+- do {
+- FIXP_DBL x0 = *pX++;
+- FIXP_DBL x1 = *pX++;
+- x0 = fPow2Div2(x0);
+- x1 = fPow2Div2(x1);
+- tmp = tmp + (x0 >> (ALFDPOW2_SCALE - 1));
+- tmp = tmp + (x1 >> (ALFDPOW2_SCALE - 1));
+- } while ((j = j - 2) != 0);
+- tmp = fMax(tmp, (FL2FX_DBL(0.01f) >> s));
+- tmp_pow2[i >> 3] = tmp;
+- if (tmp > max) {
+- max = tmp;
+- }
+- }
+-
+- /* deemphasis of all blocks below the peak */
+- fac = FL2FX_DBL(0.1f) >> 1;
+- for (i = 0; i < i_max; i += k) {
+- FIXP_DBL tmp;
+- INT shifti;
+-
+- tmp = tmp_pow2[i >> 3];
+-
+- /* tmp = (float)sqrt(tmp/max); */
+-
+- /* value of tmp is between 8/2*max^2 and max^2 / 2. */
+- /* required shift factor of division can grow up to 27
+- (grows exponentially for values toward zero)
+- thus using normalized division to assure valid result. */
+- {
+- INT sd;
+-
+- if (tmp != (FIXP_DBL)0) {
+- tmp = fDivNorm(max, tmp, &sd);
+- if (sd & 1) {
+- sd++;
+- tmp >>= 1;
+- }
+- } else {
+- tmp = (FIXP_DBL)MAXVAL_DBL;
+- sd = 0;
+- }
+- tmp = invSqrtNorm2(tmp, &shifti);
+- tmp = scaleValue(tmp, shifti - 1 - (sd / 2));
+- }
+- if (tmp > fac) {
+- fac = tmp;
+- }
+- FIXP_DBL *pX = &x[i];
+-
+- j = 8;
+- do {
+- FIXP_DBL x0 = pX[0];
+- FIXP_DBL x1 = pX[1];
+- x0 = fMultDiv2(x0, fac);
+- x1 = fMultDiv2(x1, fac);
+- x0 = x0 << 2;
+- x1 = x1 << 2;
+- *pX++ = x0;
+- *pX++ = x1;
+-
+- } while ((j = j - 2) != 0);
+- /* Store gains for FAC */
+- *alfd_gains++ = fac;
+- }
+- }
+-}
+-
+-/**
+- * \brief Interpolated Noise Shaping for mdct coefficients.
+- * This algorithm shapes temporally the spectral noise between
+- * the two spectral noise represention (FDNS_NPTS of resolution).
+- * The noise is shaped monotonically between the two points
+- * using a curved shape to favor the lower gain in mid-frame.
+- * ODFT and amplitud calculation are applied to the 2 LPC coefficients first.
+- *
+- * \param r pointer to spectrum data.
+- * \param rms RMS of output spectrum.
+- * \param lg length of r.
+- * \param A1 pointer to old input LPC coefficients of length M_LP_FILTER_ORDER
+- * scaled by SF_A_COEFFS.
+- * \param A2 pointer to new input LPC coefficients of length M_LP_FILTER_ORDER
+- * scaled by SF_A_COEFFS.
+- * \param bLpc2Mdct flags control lpc2mdct conversion and noise shaping.
+- * \param gainLpc1 pointer to gain based on old input LPC coefficients.
+- * \param gainLpc2 pointer to gain based on new input LPC coefficients.
+- * \param gLpc_e pointer to exponent of gainLpc1 and gainLpc2.
+- */
+-/* static */
+-#define NSHAPE_SCALE (4)
+-
+-#define LPC2MDCT_CALC (1)
+-#define LPC2MDCT_GAIN_LOAD (2)
+-#define LPC2MDCT_GAIN_SAVE (4)
+-#define LPC2MDCT_APPLY_NSHAPE (8)
+-
+-void lpc2mdctAndNoiseShaping(FIXP_DBL *r, SHORT *pScale, const INT lg,
+- const INT fdns_npts, const FIXP_LPC *A1,
+- const INT A1_exp, const FIXP_LPC *A2,
+- const INT A2_exp) {
+- FIXP_DBL *tmp2 = NULL;
+- FIXP_DBL rr_minus_one;
+- int i, k, s, step;
+-
+- C_AALLOC_SCRATCH_START(tmp1, FIXP_DBL, FDNS_NPTS * 8)
+-
+- {
+- tmp2 = tmp1 + fdns_npts * 4;
+-
+- /* lpc2mdct() */
+-
+- /* ODFT. E_LPC_a_weight() for A1 and A2 vectors is included into the loop
+- * below. */
+- FIXP_DBL f = FL2FXCONST_DBL(0.92f);
+-
+- const FIXP_STP *SinTab;
+- int k_step;
+- /* needed values: sin(phi), cos(phi); phi = i*PI/(2*fdns_npts), i = 0 ...
+- * M_LP_FILTER_ORDER */
+- switch (fdns_npts) {
+- case 64:
+- SinTab = SineTable512;
+- k_step = (512 / 64);
+- FDK_ASSERT(512 >= 64);
+- break;
+- case 48:
+- SinTab = SineTable384;
+- k_step = 384 / 48;
+- FDK_ASSERT(384 >= 48);
+- break;
+- default:
+- FDK_ASSERT(0);
+- return;
+- }
+-
+- for (i = 0, k = k_step; i < M_LP_FILTER_ORDER; i++, k += k_step) {
+- FIXP_STP cs = SinTab[k];
+- FIXP_DBL wA1, wA2;
+-
+- wA1 = fMult(A1[i], f);
+- wA2 = fMult(A2[i], f);
+-
+- /* r[i] = A[i]*cos() */
+- tmp1[2 + i * 2] = fMult(wA1, cs.v.re);
+- tmp2[2 + i * 2] = fMult(wA2, cs.v.re);
+- /* i[i] = A[i]*sin() */
+- tmp1[3 + i * 2] = -fMult(wA1, cs.v.im);
+- tmp2[3 + i * 2] = -fMult(wA2, cs.v.im);
+-
+- f = fMult(f, FL2FXCONST_DBL(0.92f));
+- }
+-
+- /* Guarantee at least 2 bits of headroom for the FFT */
+- /* "3" stands for 1.0 with 2 bits of headroom; (A1_exp + 2) guarantess 2
+- * bits of headroom if A1_exp > 1 */
+- int A1_exp_fix = fMax(3, A1_exp + 2);
+- int A2_exp_fix = fMax(3, A2_exp + 2);
+-
+- /* Set 1.0 in the proper format */
+- tmp1[0] = (FIXP_DBL)(INT)((ULONG)0x80000000 >> A1_exp_fix);
+- tmp2[0] = (FIXP_DBL)(INT)((ULONG)0x80000000 >> A2_exp_fix);
+-
+- tmp1[1] = tmp2[1] = (FIXP_DBL)0;
+-
+- /* Clear the resto of the array */
+- FDKmemclear(
+- tmp1 + 2 * (M_LP_FILTER_ORDER + 1),
+- 2 * (fdns_npts * 2 - (M_LP_FILTER_ORDER + 1)) * sizeof(FIXP_DBL));
+- FDKmemclear(
+- tmp2 + 2 * (M_LP_FILTER_ORDER + 1),
+- 2 * (fdns_npts * 2 - (M_LP_FILTER_ORDER + 1)) * sizeof(FIXP_DBL));
+-
+- /* Guarantee 2 bits of headroom for FFT */
+- scaleValues(&tmp1[2], (2 * M_LP_FILTER_ORDER), (A1_exp - A1_exp_fix));
+- scaleValues(&tmp2[2], (2 * M_LP_FILTER_ORDER), (A2_exp - A2_exp_fix));
+-
+- INT s2;
+- s = A1_exp_fix;
+- s2 = A2_exp_fix;
+-
+- fft(2 * fdns_npts, tmp1, &s);
+- fft(2 * fdns_npts, tmp2, &s2);
+-
+- /* Adjust the exponents of both fft outputs if necessary*/
+- if (s > s2) {
+- scaleValues(tmp2, 2 * fdns_npts, s2 - s);
+- s2 = s;
+- } else if (s < s2) {
+- scaleValues(tmp1, 2 * fdns_npts, s - s2);
+- s = s2;
+- }
+-
+- FDK_ASSERT(s == s2);
+- }
+-
+- /* Get amplitude and apply gains */
+- step = lg / fdns_npts;
+- rr_minus_one = (FIXP_DBL)0;
+-
+- for (k = 0; k < fdns_npts; k++) {
+- FIXP_DBL g1, g2, inv_g1_g2, a, b;
+- INT inv_g1_g2_e;
+- int g_e, shift;
+-
+- {
+- FIXP_DBL real, imag;
+- int si1, si2, sInput;
+-
+- real = tmp1[k * 2];
+- imag = tmp1[k * 2 + 1];
+- sInput = fMax(fMin(fNorm(real), fNorm(imag)) - 1, 0);
+- real <<= sInput;
+- imag <<= sInput;
+- /* g1_e = si1 - 2*s/2 */
+- g1 = invSqrtNorm2(fPow2(real) + fPow2(imag), &si1);
+- si1 += sInput;
+-
+- real = tmp2[k * 2];
+- imag = tmp2[k * 2 + 1];
+- sInput = fMax(fMin(fNorm(real), fNorm(imag)) - 1, 0);
+- real <<= sInput;
+- imag <<= sInput;
+- /* g2_e = si2 - 2*s/2 */
+- g2 = invSqrtNorm2(fPow2(real) + fPow2(imag), &si2);
+- si2 += sInput;
+-
+- /* Pick a common scale factor for g1 and g2 */
+- if (si1 > si2) {
+- g2 >>= si1 - si2;
+- g_e = si1 - s;
+- } else {
+- g1 >>= si2 - si1;
+- g_e = si2 - s;
+- }
+- }
+-
+- /* end of lpc2mdct() */
+-
+- FDK_ASSERT(g1 >= (FIXP_DBL)0);
+- FDK_ASSERT(g2 >= (FIXP_DBL)0);
+-
+- /* mdct_IntNoiseShaping() */
+- {
+- /* inv_g1_g2 * 2^inv_g1_g2_e = 1/(g1+g2) */
+- inv_g1_g2 = (g1 >> 1) + (g2 >> 1);
+- if (inv_g1_g2 != (FIXP_DBL)0) {
+- inv_g1_g2 = fDivNorm(FL2FXCONST_DBL(0.5f), inv_g1_g2, &inv_g1_g2_e);
+- inv_g1_g2_e = inv_g1_g2_e - g_e;
+- } else {
+- inv_g1_g2 = (FIXP_DBL)MAXVAL_DBL;
+- inv_g1_g2_e = 0;
+- }
+-
+- if (g_e < 0) {
+- /* a_e = g_e + inv_g1_g2_e + 1 */
+- a = scaleValue(fMult(fMult(g1, g2), inv_g1_g2), g_e);
+- /* b_e = g_e + inv_g1_g2_e */
+- b = fMult(g2 - g1, inv_g1_g2);
+- shift = g_e + inv_g1_g2_e + 1 - NSHAPE_SCALE;
+- } else {
+- /* a_e = (g_e+g_e) + inv_g1_g2_e + 1 */
+- a = fMult(fMult(g1, g2), inv_g1_g2);
+- /* b_e = (g_e+g_e) + inv_g1_g2_e */
+- b = scaleValue(fMult(g2 - g1, inv_g1_g2), -g_e);
+- shift = (g_e + g_e) + inv_g1_g2_e + 1 - NSHAPE_SCALE;
+- }
+-
+- for (i = k * step; i < (k + 1) * step; i++) {
+- FIXP_DBL tmp;
+-
+- /* rr[i] = 2*a*r[i] + b*rr[i-1] */
+- tmp = fMult(a, r[i]);
+- tmp += scaleValue(fMultDiv2(b, rr_minus_one), NSHAPE_SCALE);
+- tmp = scaleValueSaturate(tmp, shift);
+- rr_minus_one = tmp;
+- r[i] = tmp;
+- }
+- }
+- }
+-
+- /* end of mdct_IntNoiseShaping() */
+- { *pScale += NSHAPE_SCALE; }
+-
+- C_AALLOC_SCRATCH_END(tmp1, FIXP_DBL, FDNS_NPTS * 8)
+-}
+-
+-/**
+- * \brief Calculates the energy.
+- * \param r pointer to spectrum.
+- * \param rs scale factor of spectrum r.
+- * \param lg frame length in audio samples.
+- * \param rms_e pointer to exponent of energy value.
+- * \return mantissa of energy value.
+- */
+-static FIXP_DBL calcEnergy(const FIXP_DBL *r, const SHORT rs, const INT lg,
+- INT *rms_e) {
+- int headroom = getScalefactor(r, lg);
+-
+- FIXP_DBL rms_m = 0;
+-
+- /* Calculate number of growth bits due to addition */
+- INT shift = (INT)(fNormz((FIXP_DBL)lg));
+- shift = 31 - shift;
+-
+- /* Generate 1e-2 in Q-6.37 */
+- const FIXP_DBL value0_01 = 0x51eb851e;
+- const INT value0_01_exp = -6;
+-
+- /* Find the exponent of the resulting energy value */
+- *rms_e = ((rs - headroom) << 1) + shift + 1;
+-
+- INT delta = *rms_e - value0_01_exp;
+- if (delta > 0) {
+- /* Limit shift_to 31*/
+- delta = fMin(31, delta);
+- rms_m = value0_01 >> delta;
+- } else {
+- rms_m = value0_01;
+- *rms_e = value0_01_exp;
+- shift = shift - delta;
+- /* Limit shift_to 31*/
+- shift = fMin(31, shift);
+- }
+-
+- for (int i = 0; i < lg; i++) {
+- rms_m += fPow2Div2(r[i] << headroom) >> shift;
+- }
+-
+- return rms_m;
+-}
+-
+-/**
+- * \brief TCX gain calculation.
+- * \param pAacDecoderChannelInfo channel context data.
+- * \param r output spectrum.
+- * \param rms_e pointer to mantissa of energy value.
+- * \param rms_e pointer to exponent of energy value.
+- * \param frame the frame index of the LPD super frame.
+- * \param lg the frame length in audio samples.
+- * \param gain_m pointer to mantissa of TCX gain.
+- * \param gain_e pointer to exponent of TCX gain.
+- * \param elFlags element specific parser guidance flags.
+- * \param lg_fb the fullband frame length in audio samples.
+- * \param IGF_bgn the IGF start index.
+- */
+-static void calcTCXGain(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- FIXP_DBL *r, FIXP_DBL rms_m, INT rms_e, const INT frame,
+- const INT lg) {
+- if ((rms_m != (FIXP_DBL)0)) {
+- FIXP_DBL tcx_gain_m;
+- INT tcx_gain_e;
+-
+- CLpd_DecodeGain(&tcx_gain_m, &tcx_gain_e,
+- pAacDecoderChannelInfo->pDynData->specificTo.usac
+- .tcx_global_gain[frame]);
+-
+- /* rms * 2^rms_e = lg/sqrt(sum(spec^2)) */
+- if (rms_e & 1) {
+- rms_m >>= 1;
+- rms_e++;
+- }
+-
+- {
+- FIXP_DBL fx_lg;
+- INT fx_lg_e, s;
+- INT inv_e;
+-
+- /* lg = fx_lg * 2^fx_lg_e */
+- s = fNorm((FIXP_DBL)lg);
+- fx_lg = (FIXP_DBL)lg << s;
+- fx_lg_e = DFRACT_BITS - 1 - s;
+- /* 1/sqrt(rms) */
+- rms_m = invSqrtNorm2(rms_m, &inv_e);
+- rms_m = fMult(rms_m, fx_lg);
+- rms_e = inv_e - (rms_e >> 1) + fx_lg_e;
+- }
+-
+- {
+- int s = fNorm(tcx_gain_m);
+- tcx_gain_m = tcx_gain_m << s;
+- tcx_gain_e -= s;
+- }
+-
+- tcx_gain_m = fMultDiv2(tcx_gain_m, rms_m);
+- tcx_gain_e = tcx_gain_e + rms_e;
+-
+- /* global_gain * 2^(global_gain_e+rms_e) = (10^(global_gain/28)) * rms *
+- * 2^rms_e */
+- {
+- { tcx_gain_e += 1; }
+- }
+-
+- pAacDecoderChannelInfo->data.usac.tcx_gain[frame] = tcx_gain_m;
+- pAacDecoderChannelInfo->data.usac.tcx_gain_e[frame] = tcx_gain_e;
+-
+- pAacDecoderChannelInfo->specScale[frame] += tcx_gain_e;
+- }
+-}
+-
+-/**
+- * \brief FDNS decoding.
+- * \param pAacDecoderChannelInfo channel context data.
+- * \param pAacDecoderStaticChannelInfo channel context static data.
+- * \param r output spectrum.
+- * \param lg the frame length in audio samples.
+- * \param frame the frame index of the LPD super frame.
+- * \param pScale pointer to current scale shift factor of r[].
+- * \param A1 old input LPC coefficients of length M_LP_FILTER_ORDER.
+- * \param A2 new input LPC coefficients of length M_LP_FILTER_ORDER.
+- * \param pAlfdGains pointer for ALFD gains output scaled by 1.
+- * \param fdns_npts number of lines (FDNS_NPTS).
+- * \param inf_mask pointer to noise mask.
+- * \param IGF_win_mode IGF window mode (LONG, SHORT, TCX10, TCX20).
+- * \param frameType (IGF_FRAME_DIVISION_AAC_OR_TCX_LONG or
+- * IGF_FRAME_DIVISION_TCX_SHORT_1).
+- * \param elFlags element specific parser guidance flags.
+- * \param lg_fb the fullband frame length in audio samples.
+- * \param IGF_bgn the IGF start index.
+- * \param rms_m mantisse of energy.
+- * \param rms_e exponent of energy.
+- */
+-/* static */
+-void CLpd_FdnsDecode(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- FIXP_DBL r[], const INT lg, const INT frame, SHORT *pScale,
+- const FIXP_LPC A1[M_LP_FILTER_ORDER], const INT A1_exp,
+- const FIXP_LPC A2[M_LP_FILTER_ORDER], const INT A2_exp,
+- FIXP_DBL pAlfdGains[LFAC / 4], const INT fdns_npts) {
+- /* Weight LPC coefficients using Rm values */
+- CLpd_AdaptLowFreqDeemph(r, lg, pAlfdGains, *pScale);
+-
+- FIXP_DBL rms_m = (FIXP_DBL)0;
+- INT rms_e = 0;
+- {
+- /* Calculate Energy */
+- rms_m = calcEnergy(r, *pScale, lg, &rms_e);
+- }
+-
+- calcTCXGain(pAacDecoderChannelInfo, r, rms_m, rms_e, frame, lg);
+-
+- /* Apply ODFT and Noise Shaping. LP coefficient (A1, A2) weighting is done
+- * inside on the fly. */
+-
+- lpc2mdctAndNoiseShaping(r, pScale, lg, fdns_npts, A1, A1_exp, A2, A2_exp);
+-}
+-
+-/**
+- * find pitch for TCX20 (time domain) concealment.
+- */
+-static int find_mpitch(FIXP_DBL xri[], int lg) {
+- FIXP_DBL max, pitch;
+- INT pitch_e;
+- int i, n;
+-
+- max = (FIXP_DBL)0;
+- n = 2;
+-
+- /* find maximum below 400Hz */
+- for (i = 2; i < (lg >> 4); i += 2) {
+- FIXP_DBL tmp = fPow2Div2(xri[i]) + fPow2Div2(xri[i + 1]);
+- if (tmp > max) {
+- max = tmp;
+- n = i;
+- }
+- }
+-
+- // pitch = ((float)lg<<1)/(float)n;
+- pitch = fDivNorm((FIXP_DBL)lg << 1, (FIXP_DBL)n, &pitch_e);
+- pitch >>= fixMax(0, DFRACT_BITS - 1 - pitch_e - 16);
+-
+- /* find pitch multiple under 20ms */
+- if (pitch >= (FIXP_DBL)((256 << 16) - 1)) { /*231.0f*/
+- n = 256;
+- } else {
+- FIXP_DBL mpitch = pitch;
+- while (mpitch < (FIXP_DBL)(255 << 16)) {
+- mpitch += pitch;
+- }
+- n = (int)(mpitch - pitch) >> 16;
+- }
+-
+- return (n);
+-}
+-
+-/**
+- * number of spectral coefficients / time domain samples using frame mode as
+- * index.
+- */
+-static const int lg_table_ccfl[2][4] = {
+- {256, 256, 512, 1024}, /* coreCoderFrameLength = 1024 */
+- {192, 192, 384, 768} /* coreCoderFrameLength = 768 */
+-};
+-
+-/**
+- * \brief Decode and render one MDCT-TCX frame.
+- * \param pAacDecoderChannelInfo channel context data.
+- * \param lg the frame length in audio samples.
+- * \param frame the frame index of the LPD super frame.
+- */
+-static void CLpd_TcxDecode(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo, UINT flags,
+- int mod, int last_mod, int frame, int frameOk) {
+- FIXP_DBL *pAlfd_gains = pAacDecoderStaticChannelInfo->last_alfd_gains;
+- ULONG *pSeed = &pAacDecoderStaticChannelInfo->nfRandomSeed;
+- int lg = (pAacDecoderChannelInfo->granuleLength == 128)
+- ? lg_table_ccfl[0][mod + 0]
+- : lg_table_ccfl[1][mod + 0];
+- int next_frame = frame + (1 << (mod - 1));
+- int isFullBandLpd = 0;
+-
+- /* Obtain r[] vector by combining the quant[] and noise[] vectors */
+- {
+- FIXP_DBL noise_level;
+- FIXP_DBL *coeffs =
+- SPEC_TCX(pAacDecoderChannelInfo->pSpectralCoefficient, frame,
+- pAacDecoderChannelInfo->granuleLength, isFullBandLpd);
+- int scale = pAacDecoderChannelInfo->specScale[frame];
+- int i, nfBgn, nfEnd;
+- UCHAR tcx_noise_factor = pAacDecoderChannelInfo->pDynData->specificTo.usac
+- .tcx_noise_factor[frame];
+-
+- /* find pitch for bfi case */
+- pAacDecoderStaticChannelInfo->last_tcx_pitch = find_mpitch(coeffs, lg);
+-
+- if (frameOk) {
+- /* store for concealment */
+- pAacDecoderStaticChannelInfo->last_tcx_noise_factor = tcx_noise_factor;
+- } else {
+- /* restore last frames value */
+- tcx_noise_factor = pAacDecoderStaticChannelInfo->last_tcx_noise_factor;
+- }
+-
+- noise_level =
+- (FIXP_DBL)((LONG)FL2FXCONST_DBL(0.0625f) * (8 - tcx_noise_factor));
+- noise_level = scaleValue(noise_level, -scale);
+-
+- const FIXP_DBL neg_noise_level = -noise_level;
+-
+- {
+- nfBgn = lg / 6;
+- nfEnd = lg;
+- }
+-
+- for (i = nfBgn; i < nfEnd - 7; i += 8) {
+- LONG tmp;
+-
+- /* Fill all 8 consecutive zero coeffs with noise */
+- tmp = coeffs[i + 0] | coeffs[i + 1] | coeffs[i + 2] | coeffs[i + 3] |
+- coeffs[i + 4] | coeffs[i + 5] | coeffs[i + 6] | coeffs[i + 7];
+-
+- if (tmp == 0) {
+- for (int k = i; k < i + 8; k++) {
+- UsacRandomSign(pSeed) ? (coeffs[k] = neg_noise_level)
+- : (coeffs[k] = noise_level);
+- }
+- }
+- }
+- if ((nfEnd - i) >
+- 0) { /* noise filling for last "band" with less than 8 bins */
+- LONG tmp = (LONG)coeffs[i];
+- int k;
+-
+- FDK_ASSERT((nfEnd - i) < 8);
+- for (k = 1; k < (nfEnd - i); k++) {
+- tmp |= (LONG)coeffs[i + k];
+- }
+- if (tmp == 0) {
+- for (k = i; k < nfEnd; k++) {
+- UsacRandomSign(pSeed) ? (coeffs[k] = neg_noise_level)
+- : (coeffs[k] = noise_level);
+- }
+- }
+- }
+- }
+-
+- {
+- /* Convert LPC to LP domain */
+- if (last_mod == 0) {
+- /* Note: The case where last_mod == 255 is handled by other means
+- * in CLpdChannelStream_Read() */
+- E_LPC_f_lsp_a_conversion(
+- pAacDecoderChannelInfo->data.usac.lsp_coeff[frame],
+- pAacDecoderChannelInfo->data.usac.lp_coeff[frame],
+- &pAacDecoderChannelInfo->data.usac.lp_coeff_exp[frame]);
+- }
+-
+- E_LPC_f_lsp_a_conversion(
+- pAacDecoderChannelInfo->data.usac.lsp_coeff[next_frame],
+- pAacDecoderChannelInfo->data.usac.lp_coeff[next_frame],
+- &pAacDecoderChannelInfo->data.usac.lp_coeff_exp[next_frame]);
+-
+- /* FDNS decoding */
+- CLpd_FdnsDecode(
+- pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo,
+- SPEC_TCX(pAacDecoderChannelInfo->pSpectralCoefficient, frame,
+- pAacDecoderChannelInfo->granuleLength, isFullBandLpd),
+- lg, frame, pAacDecoderChannelInfo->specScale + frame,
+- pAacDecoderChannelInfo->data.usac.lp_coeff[frame],
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[frame],
+- pAacDecoderChannelInfo->data.usac.lp_coeff[next_frame],
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[next_frame], pAlfd_gains,
+- pAacDecoderChannelInfo->granuleLength / 2 /* == FDNS_NPTS(ccfl) */
+- );
+- }
+-}
+-
+-/**
+- * \brief Read the tcx_coding bitstream part
+- * \param hBs bitstream handle to read from.
+- * \param pAacDecoderChannelInfo channel context info to store data into.
+- * \param lg the frame length in audio samples.
+- * \param first_tcx_flag flag indicating that this is the first TCX frame.
+- * \param frame the frame index of the LPD super frame.
+- */
+-static AAC_DECODER_ERROR CLpd_TCX_Read(
+- HANDLE_FDK_BITSTREAM hBs, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo, int lg,
+- int first_tcx_flag, int frame, UINT flags) {
+- AAC_DECODER_ERROR errorAAC = AAC_DEC_OK;
+- ARITH_CODING_ERROR error = ARITH_CODER_OK;
+- FIXP_DBL *pSpec;
+- int arith_reset_flag = 0;
+- int isFullBandLpd = 0;
+-
+- pSpec = SPEC_TCX(pAacDecoderChannelInfo->pSpectralCoefficient, frame,
+- pAacDecoderChannelInfo->granuleLength, isFullBandLpd);
+-
+- /* TCX noise level */
+- {
+- pAacDecoderChannelInfo->pDynData->specificTo.usac.tcx_noise_factor[frame] =
+- FDKreadBits(hBs, 3);
+- }
+- /* TCX global gain */
+- pAacDecoderChannelInfo->pDynData->specificTo.usac.tcx_global_gain[frame] =
+- FDKreadBits(hBs, 7);
+-
+- /* Arithmetic coded residual/spectrum */
+- if (first_tcx_flag) {
+- if (flags & AC_INDEP) {
+- arith_reset_flag = 1;
+- } else {
+- arith_reset_flag = FDKreadBits(hBs, 1);
+- }
+- }
+-
+- /* CArco_DecodeArithData() output scale of "pSpec" is DFRACT_BITS-1 */
+- error = CArco_DecodeArithData(pAacDecoderStaticChannelInfo->hArCo, hBs, pSpec,
+- lg, lg, arith_reset_flag);
+-
+- /* Rescale residual/spectrum */
+- {
+- int scale = getScalefactor(pSpec, lg) - 2; /* Leave 2 bits headroom */
+-
+- /* Exponent of CArco_DecodeArithData() output is DFRACT_BITS; integer
+- * values. */
+- scaleValues(pSpec, lg, scale);
+- scale = DFRACT_BITS - 1 - scale;
+-
+- pAacDecoderChannelInfo->specScale[frame] = scale;
+- }
+-
+- if (error == ARITH_CODER_ERROR) errorAAC = AAC_DEC_UNKNOWN;
+-
+- return errorAAC;
+-}
+-
+-/**
+- * \brief translate lpd_mode into the mod[] array which describes the mode of
+- * each each LPD frame
+- * \param mod[] the array that will be filled with the mode indexes of the
+- * inidividual frames.
+- * \param lpd_mode the lpd_mode field read from the lpd_channel_stream
+- */
+-static AAC_DECODER_ERROR CLpd_ReadAndMapLpdModeToModArray(
+- UCHAR mod[4], HANDLE_FDK_BITSTREAM hBs, UINT elFlags) {
+- int lpd_mode;
+-
+- {
+- lpd_mode = FDKreadBits(hBs, 5);
+-
+- if (lpd_mode > 25 || lpd_mode < 0) {
+- return AAC_DEC_PARSE_ERROR;
+- }
+-
+- switch (lpd_mode) {
+- case 25:
+- /* 1 80MS frame */
+- mod[0] = mod[1] = mod[2] = mod[3] = 3;
+- break;
+- case 24:
+- /* 2 40MS frames */
+- mod[0] = mod[1] = mod[2] = mod[3] = 2;
+- break;
+- default:
+- switch (lpd_mode >> 2) {
+- case 4:
+- /* lpd_mode 19 - 16 => 1 40MS and 2 20MS frames */
+- mod[0] = mod[1] = 2;
+- mod[2] = (lpd_mode & 1) ? 1 : 0;
+- mod[3] = (lpd_mode & 2) ? 1 : 0;
+- break;
+- case 5:
+- /* lpd_mode 23 - 20 => 2 20MS and 1 40MS frames */
+- mod[2] = mod[3] = 2;
+- mod[0] = (lpd_mode & 1) ? 1 : 0;
+- mod[1] = (lpd_mode & 2) ? 1 : 0;
+- break;
+- default:
+- /* lpd_mode < 16 => 4 20MS frames */
+- mod[0] = (lpd_mode & 1) ? 1 : 0;
+- mod[1] = (lpd_mode & 2) ? 1 : 0;
+- mod[2] = (lpd_mode & 4) ? 1 : 0;
+- mod[3] = (lpd_mode & 8) ? 1 : 0;
+- break;
+- }
+- break;
+- }
+- }
+- return AAC_DEC_OK;
+-}
+-
+-static void CLpd_Reset(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- int keep_past_signal) {
+- int i;
+-
+- /* Reset TCX / ACELP common memory */
+- if (!keep_past_signal) {
+- FDKmemclear(pAacDecoderStaticChannelInfo->old_synth,
+- sizeof(pAacDecoderStaticChannelInfo->old_synth));
+- }
+-
+- /* Initialize the LSFs */
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- pAacDecoderStaticChannelInfo->lpc4_lsf[i] = fdk_dec_lsf_init[i];
+- }
+-
+- /* Reset memory needed by bass post-filter */
+- FDKmemclear(pAacDecoderStaticChannelInfo->mem_bpf,
+- sizeof(pAacDecoderStaticChannelInfo->mem_bpf));
+-
+- pAacDecoderStaticChannelInfo->old_bpf_control_info = 0;
+- for (i = 0; i < SYN_SFD; i++) {
+- pAacDecoderStaticChannelInfo->old_T_pf[i] = 64;
+- pAacDecoderStaticChannelInfo->old_gain_pf[i] = (FIXP_DBL)0;
+- }
+-
+- /* Reset ACELP memory */
+- CLpd_AcelpReset(&pAacDecoderStaticChannelInfo->acelp);
+-
+- pAacDecoderStaticChannelInfo->last_lpc_lost = 0; /* prev_lpc_lost */
+- pAacDecoderStaticChannelInfo->last_tcx_pitch = L_DIV; /* pitch_tcx */
+- pAacDecoderStaticChannelInfo->numLostLpdFrames = 0; /* nbLostCmpt */
+-}
+-
+-/*
+- * Externally visible functions
+- */
+-
+-AAC_DECODER_ERROR CLpdChannelStream_Read(
+- HANDLE_FDK_BITSTREAM hBs, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo, UINT flags) {
+- AAC_DECODER_ERROR error = AAC_DEC_OK;
+- int first_tcx_flag;
+- int k, nbDiv, fFacDataPresent, first_lpd_flag, acelp_core_mode,
+- facGetMemState = 0;
+- UCHAR *mod = pAacDecoderChannelInfo->data.usac.mod;
+- int lpd_mode_last, prev_frame_was_lpd;
+- USAC_COREMODE core_mode_last;
+- const int lg_table_offset = 0;
+- const int *lg_table = (pAacDecoderChannelInfo->granuleLength == 128)
+- ? &lg_table_ccfl[0][lg_table_offset]
+- : &lg_table_ccfl[1][lg_table_offset];
+- int last_lpc_lost = pAacDecoderStaticChannelInfo->last_lpc_lost;
+-
+- int last_frame_ok = 1;
+-
+- INT i_offset;
+- UINT samplingRate;
+-
+- samplingRate = pSamplingRateInfo->samplingRate;
+-
+- i_offset =
+- (INT)(samplingRate * PIT_MIN_12k8 + (FSCALE_DENOM / 2)) / FSCALE_DENOM -
+- (INT)PIT_MIN_12k8;
+-
+- if ((samplingRate < FAC_FSCALE_MIN) || (samplingRate > FAC_FSCALE_MAX)) {
+- error = AAC_DEC_PARSE_ERROR;
+- goto bail;
+- }
+-
+- acelp_core_mode = FDKreadBits(hBs, 3);
+-
+- /* lpd_mode */
+- error = CLpd_ReadAndMapLpdModeToModArray(mod, hBs, 0);
+- if (error != AAC_DEC_OK) {
+- goto bail;
+- }
+-
+- /* bpf_control_info */
+- pAacDecoderChannelInfo->data.usac.bpf_control_info = FDKreadBit(hBs);
+-
+- /* last_core_mode */
+- prev_frame_was_lpd = FDKreadBit(hBs);
+- /* fac_data_present */
+- fFacDataPresent = FDKreadBit(hBs);
+-
+- /* Set valid values from
+- * pAacDecoderStaticChannelInfo->{last_core_mode,last_lpd_mode} */
+- pAacDecoderChannelInfo->data.usac.core_mode_last =
+- pAacDecoderStaticChannelInfo->last_core_mode;
+- lpd_mode_last = pAacDecoderChannelInfo->data.usac.lpd_mode_last =
+- pAacDecoderStaticChannelInfo->last_lpd_mode;
+-
+- if (prev_frame_was_lpd == 0) {
+- /* Last frame was FD */
+- pAacDecoderChannelInfo->data.usac.core_mode_last = FD_LONG;
+- pAacDecoderChannelInfo->data.usac.lpd_mode_last = 255;
+- } else {
+- /* Last frame was LPD */
+- pAacDecoderChannelInfo->data.usac.core_mode_last = LPD;
+- if (((mod[0] == 0) && fFacDataPresent) ||
+- ((mod[0] != 0) && !fFacDataPresent)) {
+- /* Currend mod is ACELP, fac data present -> TCX, current mod TCX, no fac
+- * data -> TCX */
+- if (lpd_mode_last == 0) {
+- /* Bit stream interruption detected. Assume last TCX mode as TCX20. */
+- pAacDecoderChannelInfo->data.usac.lpd_mode_last = 1;
+- }
+- /* Else assume that remembered TCX mode is correct. */
+- } else {
+- pAacDecoderChannelInfo->data.usac.lpd_mode_last = 0;
+- }
+- }
+-
+- first_lpd_flag = (pAacDecoderChannelInfo->data.usac.core_mode_last !=
+- LPD); /* Depends on bitstream configuration */
+- first_tcx_flag = 1;
+-
+- if (pAacDecoderStaticChannelInfo->last_core_mode !=
+- LPD) { /* ATTENTION: Reset depends on what we rendered before! */
+- CLpd_Reset(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, 0);
+-
+- if (!last_frame_ok) {
+- /* If last rendered frame was not LPD and first lpd flag is not set, this
+- * must be an error - set last_lpc_lost flag */
+- last_lpc_lost |= (first_lpd_flag) ? 0 : 1;
+- }
+- }
+-
+- core_mode_last = pAacDecoderChannelInfo->data.usac.core_mode_last;
+- lpd_mode_last = pAacDecoderChannelInfo->data.usac.lpd_mode_last;
+-
+- nbDiv = NB_DIV;
+-
+- /* k is the frame index. If a frame is of size 40MS or 80MS,
+- this frame index is incremented 2 or 4 instead of 1 respectively. */
+-
+- k = 0;
+- while (k < nbDiv) {
+- /* Reset FAC data pointers in order to avoid applying old random FAC data.
+- */
+- pAacDecoderChannelInfo->data.usac.fac_data[k] = NULL;
+-
+- if ((k == 0 && core_mode_last == LPD && fFacDataPresent) ||
+- (lpd_mode_last == 0 && mod[k] > 0) ||
+- ((lpd_mode_last != 255) && lpd_mode_last > 0 && mod[k] == 0)) {
+- int err;
+-
+- /* Assign FAC memory */
+- pAacDecoderChannelInfo->data.usac.fac_data[k] =
+- CLpd_FAC_GetMemory(pAacDecoderChannelInfo, mod, &facGetMemState);
+-
+- /* FAC for (ACELP -> TCX) or (TCX -> ACELP) */
+- err = CLpd_FAC_Read(
+- hBs, pAacDecoderChannelInfo->data.usac.fac_data[k],
+- pAacDecoderChannelInfo->data.usac.fac_data_e,
+- pAacDecoderChannelInfo->granuleLength, /* == fac_length */
+- 0, k);
+- if (err != 0) {
+- error = AAC_DEC_PARSE_ERROR;
+- goto bail;
+- }
+- }
+-
+- if (mod[k] == 0) /* acelp-mode */
+- {
+- int err;
+- err = CLpd_AcelpRead(
+- hBs, &pAacDecoderChannelInfo->data.usac.acelp[k], acelp_core_mode,
+- pAacDecoderChannelInfo->granuleLength * 8 /* coreCoderFrameLength */,
+- i_offset);
+- if (err != 0) {
+- error = AAC_DEC_PARSE_ERROR;
+- goto bail;
+- }
+-
+- lpd_mode_last = 0;
+- k++;
+- } else /* mode != 0 => TCX */
+- {
+- error = CLpd_TCX_Read(hBs, pAacDecoderChannelInfo,
+- pAacDecoderStaticChannelInfo, lg_table[mod[k]],
+- first_tcx_flag, k, flags);
+-
+- lpd_mode_last = mod[k];
+- first_tcx_flag = 0;
+- k += 1 << (mod[k] - 1);
+- }
+- if (error != AAC_DEC_OK) {
+- error = AAC_DEC_PARSE_ERROR;
+- goto bail;
+- }
+- }
+-
+- {
+- int err;
+-
+- /* Read LPC coefficients */
+- err = CLpc_Read(
+- hBs, pAacDecoderChannelInfo->data.usac.lsp_coeff,
+- pAacDecoderStaticChannelInfo->lpc4_lsf,
+- pAacDecoderChannelInfo->data.usac.lsf_adaptive_mean_cand,
+- pAacDecoderChannelInfo->data.usac.aStability, mod, first_lpd_flag,
+- /* if last lpc4 is available from concealment do not extrapolate lpc0
+- from lpc2 */
+- (mod[0] & 0x3) ? 0
+- : (last_lpc_lost &&
+- pAacDecoderStaticChannelInfo->last_core_mode != LPD),
+- last_frame_ok);
+- if (err != 0) {
+- error = AAC_DEC_PARSE_ERROR;
+- goto bail;
+- }
+- }
+-
+- /* adjust old lsp[] following to a bad frame (to avoid overshoot) (ref:
+- * dec_LPD.c) */
+- if (last_lpc_lost && !last_frame_ok) {
+- int k_next;
+- k = 0;
+- while (k < nbDiv) {
+- int i;
+- k_next = k + (((mod[k] & 0x3) == 0) ? 1 : (1 << (mod[k] - 1)));
+- FIXP_LPC *lsp_old = pAacDecoderChannelInfo->data.usac.lsp_coeff[k];
+- FIXP_LPC *lsp_new = pAacDecoderChannelInfo->data.usac.lsp_coeff[k_next];
+-
+- for (i = 0; i < M_LP_FILTER_ORDER; i++) {
+- if (lsp_new[i] < lsp_old[i]) {
+- lsp_old[i] = lsp_new[i];
+- }
+- }
+- k = k_next;
+- }
+- }
+-
+- if (pAacDecoderStaticChannelInfo->last_lpd_mode != 0) {
+- if (pAacDecoderStaticChannelInfo->last_lpd_mode == 255) {
+- /* We need it for TCX decoding or ACELP excitation update */
+- E_LPC_f_lsp_a_conversion(
+- pAacDecoderChannelInfo->data.usac.lsp_coeff[0],
+- pAacDecoderChannelInfo->data.usac.lp_coeff[0],
+- &pAacDecoderChannelInfo->data.usac.lp_coeff_exp[0]);
+- } else { /* last_lpd_mode was TCX */
+- /* Copy old LPC4 LP domain coefficients to LPC0 LP domain buffer (to avoid
+- * converting LSP coefficients again). */
+- FDKmemcpy(pAacDecoderChannelInfo->data.usac.lp_coeff[0],
+- pAacDecoderStaticChannelInfo->lp_coeff_old[0],
+- M_LP_FILTER_ORDER * sizeof(FIXP_LPC));
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[0] =
+- pAacDecoderStaticChannelInfo->lp_coeff_old_exp[0];
+- }
+- } /* case last_lpd_mode was ACELP is handled by CLpd_TcxDecode() */
+-
+- if (fFacDataPresent && (core_mode_last != LPD)) {
+- int prev_frame_was_short;
+-
+- prev_frame_was_short = FDKreadBit(hBs);
+-
+- if (prev_frame_was_short) {
+- core_mode_last = pAacDecoderChannelInfo->data.usac.core_mode_last =
+- FD_SHORT;
+- pAacDecoderChannelInfo->data.usac.lpd_mode_last = 255;
+-
+- if ((pAacDecoderStaticChannelInfo->last_core_mode != FD_SHORT)) {
+- /* USAC Conformance document:
+- short_fac_flag shall be encoded with a value of 1 if the
+- window_sequence of the previous frame was 2 (EIGHT_SHORT_SEQUENCE).
+- Otherwise short_fac_flag shall be encoded with a
+- value of 0. */
+- error = AAC_DEC_PARSE_ERROR;
+- goto bail;
+- }
+- }
+-
+- /* Assign memory */
+- pAacDecoderChannelInfo->data.usac.fac_data[0] =
+- CLpd_FAC_GetMemory(pAacDecoderChannelInfo, mod, &facGetMemState);
+-
+- {
+- int err;
+-
+- /* FAC for FD -> ACELP */
+- err = CLpd_FAC_Read(
+- hBs, pAacDecoderChannelInfo->data.usac.fac_data[0],
+- pAacDecoderChannelInfo->data.usac.fac_data_e,
+- CLpd_FAC_getLength(core_mode_last != FD_SHORT,
+- pAacDecoderChannelInfo->granuleLength),
+- 1, 0);
+- if (err != 0) {
+- error = AAC_DEC_PARSE_ERROR;
+- goto bail;
+- }
+- }
+- }
+-
+-bail:
+- if (error == AAC_DEC_OK) {
+- /* check consitency of last core/lpd mode values */
+- if ((pAacDecoderChannelInfo->data.usac.core_mode_last !=
+- pAacDecoderStaticChannelInfo->last_core_mode) &&
+- (pAacDecoderStaticChannelInfo->last_lpc_lost == 0)) {
+- /* Something got wrong! */
+- /* error = AAC_DEC_PARSE_ERROR; */ /* Throwing errors does not help */
+- } else if ((pAacDecoderChannelInfo->data.usac.core_mode_last == LPD) &&
+- (pAacDecoderChannelInfo->data.usac.lpd_mode_last !=
+- pAacDecoderStaticChannelInfo->last_lpd_mode) &&
+- (pAacDecoderStaticChannelInfo->last_lpc_lost == 0)) {
+- /* Something got wrong! */
+- /* error = AAC_DEC_PARSE_ERROR; */ /* Throwing errors does not help */
+- }
+- }
+-
+- return error;
+-}
+-
+-void CLpdChannelStream_Decode(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo, UINT flags) {
+- UCHAR *mod = pAacDecoderChannelInfo->data.usac.mod;
+- int k;
+- UCHAR last_lpd_mode;
+- int nbDiv = NB_DIV;
+-
+- /* k is the frame index. If a frame is of size 40MS or 80MS,
+- this frame index is incremented 2 or 4 instead of 1 respectively. */
+- k = 0;
+- last_lpd_mode =
+- pAacDecoderChannelInfo->data.usac
+- .lpd_mode_last; /* could be different to what has been rendered */
+- while (k < nbDiv) {
+- if (mod[k] == 0) {
+- /* ACELP */
+-
+- /* If FAC (fac_data[k] != NULL), and previous frame was TCX, apply (TCX)
+- * gains to FAC data */
+- if (last_lpd_mode > 0 && last_lpd_mode != 255 &&
+- pAacDecoderChannelInfo->data.usac.fac_data[k]) {
+- CFac_ApplyGains(pAacDecoderChannelInfo->data.usac.fac_data[k],
+- pAacDecoderChannelInfo->granuleLength,
+- pAacDecoderStaticChannelInfo->last_tcx_gain,
+- pAacDecoderStaticChannelInfo->last_alfd_gains,
+- (last_lpd_mode < 4) ? last_lpd_mode : 3);
+-
+- pAacDecoderChannelInfo->data.usac.fac_data_e[k] +=
+- pAacDecoderStaticChannelInfo->last_tcx_gain_e;
+- }
+- } else {
+- /* TCX */
+- CLpd_TcxDecode(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo,
+- flags, mod[k], last_lpd_mode, k, 1 /* frameOk == 1 */
+- );
+-
+- /* Store TCX gain scale for next possible FAC transition. */
+- pAacDecoderStaticChannelInfo->last_tcx_gain =
+- pAacDecoderChannelInfo->data.usac.tcx_gain[k];
+- pAacDecoderStaticChannelInfo->last_tcx_gain_e =
+- pAacDecoderChannelInfo->data.usac.tcx_gain_e[k];
+-
+- /* If FAC (fac_data[k] != NULL), apply gains */
+- if (last_lpd_mode == 0 && pAacDecoderChannelInfo->data.usac.fac_data[k]) {
+- CFac_ApplyGains(
+- pAacDecoderChannelInfo->data.usac.fac_data[k],
+- pAacDecoderChannelInfo->granuleLength /* == fac_length */,
+- pAacDecoderChannelInfo->data.usac.tcx_gain[k],
+- pAacDecoderStaticChannelInfo->last_alfd_gains, mod[k]);
+-
+- pAacDecoderChannelInfo->data.usac.fac_data_e[k] +=
+- pAacDecoderChannelInfo->data.usac.tcx_gain_e[k];
+- }
+- }
+-
+- /* remember previous mode */
+- last_lpd_mode = mod[k];
+-
+- /* Increase k to next frame */
+- k += (mod[k] == 0) ? 1 : (1 << (mod[k] - 1));
+- }
+-}
+-
+-AAC_DECODER_ERROR CLpd_RenderTimeSignal(
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo, FIXP_PCM *pTimeData,
+- INT lFrame, SamplingRateInfo *pSamplingRateInfo, UINT frameOk, UINT flags,
+- UINT strmFlags) {
+- UCHAR *mod = pAacDecoderChannelInfo->data.usac.mod;
+- AAC_DECODER_ERROR error = AAC_DEC_OK;
+- int k, i_offset;
+- int last_k;
+- int nrSamples = 0;
+- int facFB = 1;
+- int nbDiv = NB_DIV;
+- int lDiv = lFrame / nbDiv; /* length of division (acelp or tcx20 frame)*/
+- int lFac = lDiv / 2;
+- int nbSubfr =
+- lFrame / (nbDiv * L_SUBFR); /* number of subframes per division */
+- int nbSubfrSuperfr = nbDiv * nbSubfr;
+- int synSfd = (nbSubfrSuperfr / 2) - BPF_SFD;
+- int SynDelay = synSfd * L_SUBFR;
+- int aacDelay = lFrame / 2;
+-
+- /*
+- In respect to the reference software, the synth pointer here is lagging by
+- aacDelay ( == SYN_DELAY + BPF_DELAY ) samples. The corresponding old
+- synthesis samples are handled by the IMDCT overlap.
+- */
+-
+- FIXP_DBL *synth_buf =
+- pAacDecoderChannelInfo->pComStaticData->pWorkBufferCore1->synth_buf;
+- FIXP_DBL *synth = synth_buf + PIT_MAX_MAX - BPF_DELAY;
+- UCHAR last_lpd_mode, last_last_lpd_mode, last_lpc_lost, last_frame_lost;
+-
+- INT pitch[NB_SUBFR_SUPERFR + SYN_SFD];
+- FIXP_DBL pit_gain[NB_SUBFR_SUPERFR + SYN_SFD];
+-
+- const int *lg_table;
+- int lg_table_offset = 0;
+-
+- UINT samplingRate = pSamplingRateInfo->samplingRate;
+-
+- FDKmemclear(pitch, (NB_SUBFR_SUPERFR + SYN_SFD) * sizeof(INT));
+-
+- if (flags & AACDEC_FLUSH) {
+- CLpd_Reset(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo,
+- flags & AACDEC_FLUSH);
+- frameOk = 0;
+- }
+-
+- switch (lFrame) {
+- case 1024:
+- lg_table = &lg_table_ccfl[0][lg_table_offset];
+- break;
+- case 768:
+- lg_table = &lg_table_ccfl[1][lg_table_offset];
+- break;
+- default:
+- FDK_ASSERT(0);
+- return AAC_DEC_UNKNOWN;
+- }
+-
+- last_frame_lost = 0;
+-
+- /* Maintain LPD mode from previous frame */
+- if ((pAacDecoderStaticChannelInfo->last_core_mode == FD_LONG) ||
+- (pAacDecoderStaticChannelInfo->last_core_mode == FD_SHORT)) {
+- pAacDecoderStaticChannelInfo->last_lpd_mode = 255;
+- }
+-
+- if (!frameOk) {
+- FIXP_DBL old_tcx_gain;
+- FIXP_SGL old_stab;
+- SCHAR old_tcx_gain_e;
+- int nLostSf;
+-
+- last_lpd_mode = pAacDecoderStaticChannelInfo->last_lpd_mode;
+- old_tcx_gain = pAacDecoderStaticChannelInfo->last_tcx_gain;
+- old_tcx_gain_e = pAacDecoderStaticChannelInfo->last_tcx_gain_e;
+- old_stab = pAacDecoderStaticChannelInfo->oldStability;
+- nLostSf = pAacDecoderStaticChannelInfo->numLostLpdFrames;
+-
+- /* patch the last LPD mode */
+- pAacDecoderChannelInfo->data.usac.lpd_mode_last = last_lpd_mode;
+-
+- /* Do mode extrapolation and repeat the previous mode:
+- if previous mode = ACELP -> ACELP
+- if previous mode = TCX-20/40 -> TCX-20
+- if previous mode = TCX-80 -> TCX-80
+- notes:
+- - ACELP is not allowed after TCX (no pitch information to reuse)
+- - TCX-40 is not allowed in the mode repetition to keep the logic simple
+- */
+- switch (last_lpd_mode) {
+- case 0:
+- mod[0] = mod[1] = mod[2] = mod[3] = 0; /* -> ACELP concealment */
+- break;
+- case 3:
+- mod[0] = mod[1] = mod[2] = mod[3] = 3; /* -> TCX FD concealment */
+- break;
+- case 2:
+- mod[0] = mod[1] = mod[2] = mod[3] = 2; /* -> TCX FD concealment */
+- break;
+- case 1:
+- default:
+- mod[0] = mod[1] = mod[2] = mod[3] = 4; /* -> TCX TD concealment */
+- break;
+- }
+-
+- /* LPC extrapolation */
+- CLpc_Conceal(pAacDecoderChannelInfo->data.usac.lsp_coeff,
+- pAacDecoderStaticChannelInfo->lpc4_lsf,
+- pAacDecoderStaticChannelInfo->lsf_adaptive_mean,
+- /*(pAacDecoderStaticChannelInfo->numLostLpdFrames == 0) ||*/
+- (last_lpd_mode == 255));
+-
+- if ((last_lpd_mode > 0) && (last_lpd_mode < 255)) {
+- /* Copy old LPC4 LP domain coefficients to LPC0 LP domain buffer (to avoid
+- * converting LSP coefficients again). */
+- FDKmemcpy(pAacDecoderChannelInfo->data.usac.lp_coeff[0],
+- pAacDecoderStaticChannelInfo->lp_coeff_old[0],
+- M_LP_FILTER_ORDER * sizeof(FIXP_LPC));
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[0] =
+- pAacDecoderStaticChannelInfo->lp_coeff_old_exp[0];
+- } /* case last_lpd_mode was ACELP is handled by CLpd_TcxDecode() */
+- /* case last_lpd_mode was Time domain TCX concealment is handled after this
+- * "if (!frameOk)"-block */
+-
+- /* k is the frame index. If a frame is of size 40MS or 80MS,
+- this frame index is incremented 2 or 4 instead of 1 respectively. */
+- k = 0;
+- while (k < nbDiv) {
+- pAacDecoderChannelInfo->data.usac.tcx_gain[k] = old_tcx_gain;
+- pAacDecoderChannelInfo->data.usac.tcx_gain_e[k] = old_tcx_gain_e;
+-
+- /* restore stability value from last frame */
+- pAacDecoderChannelInfo->data.usac.aStability[k] = old_stab;
+-
+- /* Increase k to next frame */
+- k += ((mod[k] & 0x3) == 0) ? 1 : (1 << ((mod[k] & 0x3) - 1));
+-
+- nLostSf++;
+- }
+- } else {
+- if ((pAacDecoderStaticChannelInfo->last_lpd_mode == 4) && (mod[0] > 0)) {
+- /* Copy old LPC4 LP domain coefficients to LPC0 LP domain buffer (to avoid
+- * converting LSP coefficients again). */
+- FDKmemcpy(pAacDecoderChannelInfo->data.usac.lp_coeff[0],
+- pAacDecoderStaticChannelInfo->lp_coeff_old[0],
+- M_LP_FILTER_ORDER * sizeof(FIXP_LPC));
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[0] =
+- pAacDecoderStaticChannelInfo->lp_coeff_old_exp[0];
+- }
+- }
+-
+- Acelp_PreProcessing(synth_buf, pAacDecoderStaticChannelInfo->old_synth, pitch,
+- pAacDecoderStaticChannelInfo->old_T_pf, pit_gain,
+- pAacDecoderStaticChannelInfo->old_gain_pf, samplingRate,
+- &i_offset, lFrame, synSfd, nbSubfrSuperfr);
+-
+- /* k is the frame index. If a frame is of size 40MS or 80MS,
+- this frame index is incremented 2 or 4 instead of 1 respectively. */
+- k = 0;
+- last_k = -1; /* mark invalid */
+- last_lpd_mode = pAacDecoderStaticChannelInfo->last_lpd_mode;
+- last_last_lpd_mode = pAacDecoderStaticChannelInfo->last_last_lpd_mode;
+- last_lpc_lost = pAacDecoderStaticChannelInfo->last_lpc_lost | last_frame_lost;
+-
+- /* This buffer must be avalable for the case of FD->ACELP transition. The
+- beginning of the buffer is used after the BPF to overwrite the output signal.
+- Only the FAC area must be affected by the BPF */
+-
+- while (k < nbDiv) {
+- if (frameOk == 0) {
+- pAacDecoderStaticChannelInfo->numLostLpdFrames++;
+- } else {
+- last_frame_lost |=
+- (pAacDecoderStaticChannelInfo->numLostLpdFrames > 0) ? 1 : 0;
+- pAacDecoderStaticChannelInfo->numLostLpdFrames = 0;
+- }
+- if (mod[k] == 0 || mod[k] == 4) {
+- /* ACELP or TCX time domain concealment */
+- FIXP_DBL *acelp_out;
+-
+- /* FAC management */
+- if ((last_lpd_mode != 0) && (last_lpd_mode != 4)) /* TCX TD concealment */
+- {
+- FIXP_DBL *pFacData = NULL;
+-
+- if (frameOk && !last_frame_lost) {
+- pFacData = pAacDecoderChannelInfo->data.usac.fac_data[k];
+- }
+-
+- nrSamples += CLpd_FAC_Mdct2Acelp(
+- &pAacDecoderStaticChannelInfo->IMdct, synth + nrSamples, pFacData,
+- pAacDecoderChannelInfo->data.usac.fac_data_e[k],
+- pAacDecoderChannelInfo->data.usac.lp_coeff[k],
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[k],
+- lFrame - nrSamples,
+- CLpd_FAC_getLength(
+- (pAacDecoderStaticChannelInfo->last_core_mode != FD_SHORT) ||
+- (k > 0),
+- lFac),
+- (pAacDecoderStaticChannelInfo->last_core_mode != LPD) && (k == 0),
+- 0);
+-
+- FDKmemcpy(
+- synth + nrSamples, pAacDecoderStaticChannelInfo->IMdct.overlap.time,
+- pAacDecoderStaticChannelInfo->IMdct.ov_offset * sizeof(FIXP_DBL));
+- {
+- FIXP_LPC *lp_prev =
+- pAacDecoderChannelInfo->data.usac
+- .lp_coeff[0]; /* init value does not real matter */
+- INT lp_prev_exp = pAacDecoderChannelInfo->data.usac.lp_coeff_exp[0];
+-
+- if (last_lpd_mode != 255) { /* last mode was tcx */
+- last_k = k - (1 << (last_lpd_mode - 1));
+- if (last_k < 0) {
+- lp_prev = pAacDecoderStaticChannelInfo->lp_coeff_old[1];
+- lp_prev_exp = pAacDecoderStaticChannelInfo->lp_coeff_old_exp[1];
+- } else {
+- lp_prev = pAacDecoderChannelInfo->data.usac.lp_coeff[last_k];
+- lp_prev_exp =
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[last_k];
+- }
+- }
+-
+- CLpd_AcelpPrepareInternalMem(
+- synth + aacDelay + k * lDiv, last_lpd_mode,
+- (last_last_lpd_mode == 4) ? 0 : last_last_lpd_mode,
+- pAacDecoderChannelInfo->data.usac.lp_coeff[k],
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[k], lp_prev,
+- lp_prev_exp, &pAacDecoderStaticChannelInfo->acelp, lFrame,
+- (last_frame_lost && k < 2), mod[k]);
+- }
+- } else {
+- if (k == 0 && pAacDecoderStaticChannelInfo->IMdct.ov_offset !=
+- lFrame / facFB / 2) {
+- pAacDecoderStaticChannelInfo->IMdct.ov_offset = lFrame / facFB / 2;
+- }
+- nrSamples += imdct_drain(&pAacDecoderStaticChannelInfo->IMdct,
+- synth + nrSamples, lFrame / facFB - nrSamples);
+- }
+-
+- if (nrSamples >= lFrame / facFB) {
+- /* Write ACELP time domain samples into IMDCT overlap buffer at
+- * pAacDecoderStaticChannelInfo->IMdct.overlap.time +
+- * pAacDecoderStaticChannelInfo->IMdct.ov_offset
+- */
+- acelp_out = pAacDecoderStaticChannelInfo->IMdct.overlap.time +
+- pAacDecoderStaticChannelInfo->IMdct.ov_offset;
+-
+- /* Account ACELP time domain output samples to overlap buffer */
+- pAacDecoderStaticChannelInfo->IMdct.ov_offset += lDiv;
+- } else {
+- /* Write ACELP time domain samples into output buffer at pTimeData +
+- * nrSamples */
+- acelp_out = synth + nrSamples;
+-
+- /* Account ACELP time domain output samples to output buffer */
+- nrSamples += lDiv;
+- }
+-
+- if (mod[k] == 4) {
+- pAacDecoderStaticChannelInfo->acelp.wsyn_rms = scaleValue(
+- pAacDecoderChannelInfo->data.usac.tcx_gain[k],
+- fixMin(0,
+- pAacDecoderChannelInfo->data.usac.tcx_gain_e[k] - SF_EXC));
+- CLpd_TcxTDConceal(&pAacDecoderStaticChannelInfo->acelp,
+- &pAacDecoderStaticChannelInfo->last_tcx_pitch,
+- pAacDecoderChannelInfo->data.usac.lsp_coeff[k],
+- pAacDecoderChannelInfo->data.usac.lsp_coeff[k + 1],
+- pAacDecoderChannelInfo->data.usac.aStability[k],
+- pAacDecoderStaticChannelInfo->numLostLpdFrames,
+- acelp_out, lFrame,
+- pAacDecoderStaticChannelInfo->last_tcx_noise_factor);
+-
+- } else {
+- FDK_ASSERT(pAacDecoderChannelInfo->data.usac.aStability[k] >=
+- (FIXP_SGL)0);
+- CLpd_AcelpDecode(&pAacDecoderStaticChannelInfo->acelp, i_offset,
+- pAacDecoderChannelInfo->data.usac.lsp_coeff[k],
+- pAacDecoderChannelInfo->data.usac.lsp_coeff[k + 1],
+- pAacDecoderChannelInfo->data.usac.aStability[k],
+- &pAacDecoderChannelInfo->data.usac.acelp[k],
+- pAacDecoderStaticChannelInfo->numLostLpdFrames,
+- last_lpc_lost, k, acelp_out,
+- &pitch[(k * nbSubfr) + synSfd],
+- &pit_gain[(k * nbSubfr) + synSfd], lFrame);
+- }
+-
+- if (mod[k] != 4) {
+- if (last_lpd_mode != 0 &&
+- pAacDecoderChannelInfo->data.usac
+- .bpf_control_info) { /* FD/TCX -> ACELP transition */
+- /* bass post-filter past FAC area (past two (one for FD short)
+- * subframes) */
+- int currentSf = synSfd + k * nbSubfr;
+-
+- if ((k > 0) || (pAacDecoderStaticChannelInfo->last_core_mode !=
+- FD_SHORT)) { /* TCX or FD long -> ACELP */
+- pitch[currentSf - 2] = pitch[currentSf - 1] = pitch[currentSf];
+- pit_gain[currentSf - 2] = pit_gain[currentSf - 1] =
+- pit_gain[currentSf];
+- } else { /* FD short -> ACELP */
+- pitch[currentSf - 1] = pitch[currentSf];
+- pit_gain[currentSf - 1] = pit_gain[currentSf];
+- }
+- }
+- }
+- } else { /* TCX */
+- int lg = lg_table[mod[k]];
+- int isFullBandLpd = 0;
+-
+- /* FAC management */
+- if ((last_lpd_mode == 0) || (last_lpd_mode == 4)) /* TCX TD concealment */
+- {
+- C_AALLOC_SCRATCH_START(fac_buf, FIXP_DBL, 1024 / 8);
+-
+- /* pAacDecoderChannelInfo->data.usac.fac_data[k] == NULL means no FAC
+- * data available. */
+- if (last_frame_lost == 1 ||
+- pAacDecoderChannelInfo->data.usac.fac_data[k] == NULL) {
+- FDKmemclear(fac_buf, 1024 / 8 * sizeof(FIXP_DBL));
+- pAacDecoderChannelInfo->data.usac.fac_data[k] = fac_buf;
+- pAacDecoderChannelInfo->data.usac.fac_data_e[k] = 0;
+- }
+-
+- nrSamples += CLpd_FAC_Acelp2Mdct(
+- &pAacDecoderStaticChannelInfo->IMdct, synth + nrSamples,
+- SPEC_TCX(pAacDecoderChannelInfo->pSpectralCoefficient, k,
+- pAacDecoderChannelInfo->granuleLength, isFullBandLpd),
+- pAacDecoderChannelInfo->specScale + k, 1,
+- pAacDecoderChannelInfo->data.usac.fac_data[k],
+- pAacDecoderChannelInfo->data.usac.fac_data_e[k],
+- pAacDecoderChannelInfo->granuleLength /* == fac_length */,
+- lFrame - nrSamples, lg,
+- FDKgetWindowSlope(lDiv,
+- GetWindowShape(&pAacDecoderChannelInfo->icsInfo)),
+- lDiv, pAacDecoderChannelInfo->data.usac.lp_coeff[k],
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[k],
+- &pAacDecoderStaticChannelInfo->acelp,
+- pAacDecoderChannelInfo->data.usac.tcx_gain[k],
+- (last_frame_lost || !frameOk), 0 /* is not FD FAC */
+- ,
+- last_lpd_mode, k,
+- pAacDecoderChannelInfo
+- ->currAliasingSymmetry /* Note: The current aliasing
+- symmetry for a TCX (i.e. LPD)
+- frame must always be 0 */
+- );
+-
+- pitch[(k * nbSubfr) + synSfd + 1] = pitch[(k * nbSubfr) + synSfd] =
+- pitch[(k * nbSubfr) + synSfd - 1];
+- pit_gain[(k * nbSubfr) + synSfd + 1] =
+- pit_gain[(k * nbSubfr) + synSfd] =
+- pit_gain[(k * nbSubfr) + synSfd - 1];
+-
+- C_AALLOC_SCRATCH_END(fac_buf, FIXP_DBL, 1024 / 8);
+- } else {
+- int tl = lg;
+- int fl = lDiv;
+- int fr = lDiv;
+-
+- nrSamples += imlt_block(
+- &pAacDecoderStaticChannelInfo->IMdct, synth + nrSamples,
+- SPEC_TCX(pAacDecoderChannelInfo->pSpectralCoefficient, k,
+- pAacDecoderChannelInfo->granuleLength, isFullBandLpd),
+- pAacDecoderChannelInfo->specScale + k, 1, lFrame - nrSamples, tl,
+- FDKgetWindowSlope(fl,
+- GetWindowShape(&pAacDecoderChannelInfo->icsInfo)),
+- fl,
+- FDKgetWindowSlope(fr,
+- GetWindowShape(&pAacDecoderChannelInfo->icsInfo)),
+- fr, pAacDecoderChannelInfo->data.usac.tcx_gain[k],
+- pAacDecoderChannelInfo->currAliasingSymmetry
+- ? MLT_FLAG_CURR_ALIAS_SYMMETRY
+- : 0);
+- }
+- }
+- /* remember previous mode */
+- last_last_lpd_mode = last_lpd_mode;
+- last_lpd_mode = mod[k];
+- last_lpc_lost = (frameOk == 0) ? 1 : 0;
+-
+- /* Increase k to next frame */
+- last_k = k;
+- k += ((mod[k] & 0x3) == 0) ? 1 : (1 << (mod[k] - 1));
+- }
+-
+- if (frameOk) {
+- /* assume data was ok => store for concealment */
+- FDK_ASSERT(pAacDecoderChannelInfo->data.usac.aStability[last_k] >=
+- (FIXP_SGL)0);
+- pAacDecoderStaticChannelInfo->oldStability =
+- pAacDecoderChannelInfo->data.usac.aStability[last_k];
+- FDKmemcpy(pAacDecoderStaticChannelInfo->lsf_adaptive_mean,
+- pAacDecoderChannelInfo->data.usac.lsf_adaptive_mean_cand,
+- M_LP_FILTER_ORDER * sizeof(FIXP_LPC));
+- }
+-
+- /* store past lp coeffs for next superframe (they are only valid and needed if
+- * last_lpd_mode was tcx) */
+- if (last_lpd_mode > 0) {
+- FDKmemcpy(pAacDecoderStaticChannelInfo->lp_coeff_old[0],
+- pAacDecoderChannelInfo->data.usac.lp_coeff[nbDiv],
+- M_LP_FILTER_ORDER * sizeof(FIXP_LPC));
+- pAacDecoderStaticChannelInfo->lp_coeff_old_exp[0] =
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[nbDiv];
+- FDKmemcpy(pAacDecoderStaticChannelInfo->lp_coeff_old[1],
+- pAacDecoderChannelInfo->data.usac.lp_coeff[last_k],
+- M_LP_FILTER_ORDER * sizeof(FIXP_LPC));
+- pAacDecoderStaticChannelInfo->lp_coeff_old_exp[1] =
+- pAacDecoderChannelInfo->data.usac.lp_coeff_exp[last_k];
+- }
+-
+- FDK_ASSERT(nrSamples == lFrame);
+-
+- /* check whether usage of bass postfilter was de-activated in the bitstream;
+- if yes, set pitch gain to 0 */
+- if (!(pAacDecoderChannelInfo->data.usac.bpf_control_info)) {
+- if (mod[0] != 0 && (pAacDecoderStaticChannelInfo->old_bpf_control_info)) {
+- for (int i = 2; i < nbSubfrSuperfr; i++)
+- pit_gain[synSfd + i] = (FIXP_DBL)0;
+- } else {
+- for (int i = 0; i < nbSubfrSuperfr; i++)
+- pit_gain[synSfd + i] = (FIXP_DBL)0;
+- }
+- }
+-
+- /* for bass postfilter */
+- for (int n = 0; n < synSfd; n++) {
+- pAacDecoderStaticChannelInfo->old_T_pf[n] = pitch[nbSubfrSuperfr + n];
+- pAacDecoderStaticChannelInfo->old_gain_pf[n] = pit_gain[nbSubfrSuperfr + n];
+- }
+-
+- pAacDecoderStaticChannelInfo->old_bpf_control_info =
+- pAacDecoderChannelInfo->data.usac.bpf_control_info;
+-
+- {
+- INT lookahead = -BPF_DELAY;
+- int copySamp = (mod[nbDiv - 1] == 0) ? (aacDelay) : (aacDelay - lFac);
+-
+- /* Copy enough time domain samples from MDCT to synthesis buffer as needed
+- * by the bass postfilter */
+-
+- lookahead += imdct_copy_ov_and_nr(&pAacDecoderStaticChannelInfo->IMdct,
+- synth + nrSamples, copySamp);
+-
+- FDK_ASSERT(lookahead == copySamp - BPF_DELAY);
+-
+- FIXP_DBL *p2_synth = synth + BPF_DELAY;
+-
+- /* recalculate pitch gain to allow postfilering on FAC area */
+- for (int i = 0; i < nbSubfrSuperfr; i++) {
+- int T = pitch[i];
+- FIXP_DBL gain = pit_gain[i];
+-
+- if (gain > (FIXP_DBL)0) {
+- gain = get_gain(&p2_synth[i * L_SUBFR], &p2_synth[(i * L_SUBFR) - T],
+- L_SUBFR);
+- pit_gain[i] = gain;
+- }
+- }
+-
+- {
+- bass_pf_1sf_delay(p2_synth, pitch, pit_gain, lFrame, lFrame / facFB,
+- mod[nbDiv - 1] ? (SynDelay - (lDiv / 2)) : SynDelay,
+- pTimeData, pAacDecoderStaticChannelInfo->mem_bpf);
+- }
+- }
+-
+- Acelp_PostProcessing(synth_buf, pAacDecoderStaticChannelInfo->old_synth,
+- pitch, pAacDecoderStaticChannelInfo->old_T_pf, lFrame,
+- synSfd, nbSubfrSuperfr);
+-
+- /* Store last mode for next super frame */
+- { pAacDecoderStaticChannelInfo->last_core_mode = LPD; }
+- pAacDecoderStaticChannelInfo->last_lpd_mode = last_lpd_mode;
+- pAacDecoderStaticChannelInfo->last_last_lpd_mode = last_last_lpd_mode;
+- pAacDecoderStaticChannelInfo->last_lpc_lost = last_lpc_lost;
+-
+- return error;
+-}
+diff --git a/libAACdec/src/usacdec_lpd.h b/libAACdec/src/usacdec_lpd.h
+deleted file mode 100644
+index 3e7938d..0000000
+--- a/libAACdec/src/usacdec_lpd.h
++++ /dev/null
+@@ -1,198 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): Manuel Jander
+-
+- Description: USAC Linear Prediction Domain coding
+-
+-*******************************************************************************/
+-
+-#ifndef USACDEC_LPD_H
+-#define USACDEC_LPD_H
+-
+-#include "channelinfo.h"
+-
+-#define OPTIMIZE_AVG_PERFORMANCE
+-
+-/**
+- * \brief read a lpd_channel_stream.
+- * \param hBs a bit stream handle, where the lpd_channel_stream is located.
+- * \param pAacDecoderChannelInfo the channel context structure for storing read
+- * data.
+- * \param flags bit stream syntax flags.
+- * \return AAC_DECODER_ERROR error code.
+- */
+-AAC_DECODER_ERROR CLpdChannelStream_Read(
+- HANDLE_FDK_BITSTREAM hBs, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- const SamplingRateInfo *pSamplingRateInfo, UINT flags);
+-
+-/**
+- * \brief decode one lpd_channel_stream and render the audio output.
+- * \param pAacDecoderChannelInfo struct holding the channel information to be
+- * rendered.
+- * \param pAacDecoderStaticChannelInfo struct holding the persistent channel
+- * information to be rendered.
+- * \param pSamplingRateInfo holds the sampling rate information
+- * \param elFlags holds the internal decoder flags
+- */
+-void CLpdChannelStream_Decode(
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo,
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo, UINT flags);
+-
+-/**
+- * \brief generate time domain output signal for LPD channel streams
+- * \param pAacDecoderStaticChannelInfo
+- * \param pAacDecoderChannelInfo
+- * \param pTimeData pointer to output buffer
+- * \param samplesPerFrame amount of output samples
+- * \param pSamplingRateInfo holds the sampling rate information
+- * \param pWorkBuffer1 pointer to work buffer for temporal data
+- */
+-AAC_DECODER_ERROR CLpd_RenderTimeSignal(
+- CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
+- CAacDecoderChannelInfo *pAacDecoderChannelInfo, FIXP_PCM *pTimeData,
+- INT samplesPerFrame, SamplingRateInfo *pSamplingRateInfo, UINT frameOk,
+- UINT flags, UINT strmFlags);
+-
+-static inline INT CLpd_FAC_getLength(int fNotShortBlock, int fac_length_long) {
+- if (fNotShortBlock) {
+- return (fac_length_long);
+- } else {
+- return fac_length_long / 2;
+- }
+-}
+-
+-void filtLP(const FIXP_DBL *syn, FIXP_PCM *syn_out, FIXP_DBL *noise,
+- const FIXP_SGL *filt, INT stop, int len);
+-
+-/**
+- * \brief perform a low-frequency pitch enhancement on time domain signal
+- * \param[in] syn pointer to time domain input signal
+- * \param[in] synFB pointer to time domain input signal
+- * \param[in] upsampling factor
+- * \param[in] T_sf array with past decoded pitch period values for each subframe
+- * \param[in] non_zero_gain_flags indicates whether pitch gains of past
+- * subframes are zero or not, msb -> [1 BPF_DELAY subfr][7 SYN_DELAY subfr][16
+- * new subfr] <- lsb
+- * \param[in] l_frame length of filtering, must be multiple of L_SUBFR
+- * \param[in] l_next length of allowed look ahead on syn[i], i < l_frame+l_next
+- * \param[out] synth_out pointer to time domain output signal
+- * \param[in,out] mem_bpf pointer to filter memory (L_FILT+L_SUBFR)
+- */
+-
+-void bass_pf_1sf_delay(FIXP_DBL syn[], const INT T_sf[], FIXP_DBL *pit_gain,
+- const int frame_length, const INT l_frame,
+- const INT l_next, FIXP_PCM *synth_out,
+- FIXP_DBL mem_bpf[]);
+-
+-/**
+- * \brief random sign generator for FD and TCX noise filling
+- * \param[in,out] seed pointer to random seed
+- * \return if return value is zero use positive sign
+- * \Note: This code is also implemented as a copy in block.cpp, grep for
+- * "UsacRandomSign"
+- */
+-FDK_INLINE
+-int UsacRandomSign(ULONG *seed) {
+- *seed = (ULONG)((UINT64)(*seed) * 69069 + 5);
+-
+- return (int)((*seed) & 0x10000);
+-}
+-
+-void CFdp_Reset(CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
+-
+-#endif /* USACDEC_LPD_H */
+diff --git a/libAACdec/src/usacdec_rom.cpp b/libAACdec/src/usacdec_rom.cpp
+deleted file mode 100644
+index ca3009e..0000000
+--- a/libAACdec/src/usacdec_rom.cpp
++++ /dev/null
+@@ -1,1504 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): M. Jander
+-
+- Description:
+-
+-*******************************************************************************/
+-
+-#include "usacdec_rom.h"
+-
+-#define NB_SPHERE 32
+-#define NB_LEADER 37
+-#define NB_LDSIGN 226
+-#define NB_LDQ3 9
+-#define NB_LDQ4 28
+-
+-/* For bass post filter */
+-#define FL2FXCONST_SGL_FILT(a) FL2FXCONST_SGL(a*(1 << SF_FILT_LP))
+-#define SF_FILT_LP 1
+-
+-/* table of factorial */
+-const UINT fdk_dec_tab_factorial[8] = {5040, 720, 120, 24, 6, 2, 1, 1};
+-
+-/* Da - Absolute leaders */
+-const UCHAR fdk_dec_Da[NB_LEADER][8] = {
+- {1, 1, 1, 1, 1, 1, 1, 1}, {2, 2, 0, 0, 0, 0, 0, 0},
+- {2, 2, 2, 2, 0, 0, 0, 0}, {3, 1, 1, 1, 1, 1, 1, 1},
+- {4, 0, 0, 0, 0, 0, 0, 0}, {2, 2, 2, 2, 2, 2, 0, 0},
+- {3, 3, 1, 1, 1, 1, 1, 1}, {4, 2, 2, 0, 0, 0, 0, 0},
+- {2, 2, 2, 2, 2, 2, 2, 2}, {3, 3, 3, 1, 1, 1, 1, 1},
+- {4, 2, 2, 2, 2, 0, 0, 0}, {4, 4, 0, 0, 0, 0, 0, 0},
+- {5, 1, 1, 1, 1, 1, 1, 1}, {3, 3, 3, 3, 1, 1, 1, 1},
+- {4, 2, 2, 2, 2, 2, 2, 0}, {4, 4, 2, 2, 0, 0, 0, 0},
+- {5, 3, 1, 1, 1, 1, 1, 1}, {6, 2, 0, 0, 0, 0, 0, 0},
+- {4, 4, 4, 0, 0, 0, 0, 0}, {6, 2, 2, 2, 0, 0, 0, 0},
+- {6, 4, 2, 0, 0, 0, 0, 0}, {7, 1, 1, 1, 1, 1, 1, 1},
+- {8, 0, 0, 0, 0, 0, 0, 0}, {6, 6, 0, 0, 0, 0, 0, 0},
+- {8, 2, 2, 0, 0, 0, 0, 0}, {8, 4, 0, 0, 0, 0, 0, 0},
+- {9, 1, 1, 1, 1, 1, 1, 1}, {10, 2, 0, 0, 0, 0, 0, 0},
+- {8, 8, 0, 0, 0, 0, 0, 0}, {10, 6, 0, 0, 0, 0, 0, 0},
+- {12, 0, 0, 0, 0, 0, 0, 0}, {12, 4, 0, 0, 0, 0, 0, 0},
+- {10, 10, 0, 0, 0, 0, 0, 0}, {14, 2, 0, 0, 0, 0, 0, 0},
+- {12, 8, 0, 0, 0, 0, 0, 0}, {16, 0, 0, 0, 0, 0, 0, 0},
+- {20, 0, 0, 0, 0, 0, 0, 0}};
+-
+-/* Ds - Sign codes of all signed leaders */
+-const UCHAR fdk_dec_Ds[NB_LDSIGN] = {
+- 0, 3, 15, 63, 255, 0, 64, 192, 0, 16, 48, 112, 240, 1, 7,
+- 31, 127, 128, 131, 143, 191, 0, 128, 0, 4, 12, 28, 60, 124, 252,
+- 0, 3, 15, 63, 65, 71, 95, 192, 195, 207, 255, 0, 32, 96, 128,
+- 160, 224, 0, 1, 3, 7, 15, 31, 63, 127, 255, 1, 7, 31, 32,
+- 35, 47, 97, 103, 127, 224, 227, 239, 0, 8, 24, 56, 120, 128, 136,
+- 152, 184, 248, 0, 64, 192, 0, 3, 15, 63, 129, 135, 159, 255, 0,
+- 3, 15, 17, 23, 48, 51, 63, 113, 119, 240, 243, 255, 0, 2, 6,
+- 14, 30, 62, 126, 128, 130, 134, 142, 158, 190, 254, 0, 16, 48, 64,
+- 80, 112, 192, 208, 240, 1, 7, 31, 64, 67, 79, 127, 128, 131, 143,
+- 191, 193, 199, 223, 0, 64, 128, 192, 0, 32, 96, 224, 0, 16, 48,
+- 112, 128, 144, 176, 240, 0, 32, 64, 96, 128, 160, 192, 224, 1, 7,
+- 31, 127, 128, 131, 143, 191, 0, 128, 0, 64, 192, 0, 32, 96, 128,
+- 160, 224, 0, 64, 128, 192, 0, 3, 15, 63, 129, 135, 159, 255, 0,
+- 64, 128, 192, 0, 64, 192, 0, 64, 128, 192, 0, 128, 0, 64, 128,
+- 192, 0, 64, 192, 0, 64, 128, 192, 0, 64, 128, 192, 0, 128, 0,
+- 128};
+-
+-/* Ns - Number of signed leader associated to a given absolute leader */
+-const UCHAR fdk_dec_Ns[NB_LEADER] = {
+- 5, 3, 5, 8, 2, 7, 11, 6, 9, 12, 10, 3, 8, 13, 14, 9, 14, 4, 4,
+- 8, 8, 8, 2, 3, 6, 4, 8, 4, 3, 4, 2, 4, 3, 4, 4, 2, 2};
+-
+-/* Ia - Position of the first signed leader associated to an absolute leader */
+-const UCHAR fdk_dec_Ia[NB_LEADER] = {
+- 0, 5, 8, 13, 21, 23, 30, 41, 47, 56, 68, 78, 81,
+- 89, 102, 116, 125, 139, 143, 147, 155, 163, 171, 173, 176, 182,
+- 186, 194, 198, 201, 205, 207, 211, 214, 218, 222, 224};
+-
+-/* Is - Cardinalite offset of signed leaders */
+-const USHORT fdk_dec_Is[NB_LDSIGN] = {
+- 0, 1, 29, 99, 127, 128, 156, 212, 256, 326, 606,
+- 1026, 1306, 1376, 1432, 1712, 1880, 1888, 1896, 2064, 2344, 240,
+- 248, 0, 28, 196, 616, 1176, 1596, 1764, 1792, 1820, 2240,
+- 2660, 2688, 3024, 4144, 4480, 4508, 4928, 5348, 2400, 2568, 2904,
+- 3072, 3240, 3576, 5376, 5377, 5385, 5413, 5469, 5539, 5595, 5623,
+- 5631, 5632, 5912, 6472, 6528, 6696, 8376, 9216, 10056, 11736, 11904,
+- 11960, 12520, 12800, 13080, 14200, 15880, 17000, 17280, 17560, 18680, 20360,
+- 21480, 3744, 3772, 3828, 21760, 21768, 21936, 22216, 22272, 22328, 22608,
+- 22776, 22784, 22854, 23274, 23344, 24464, 25584, 26004, 28524, 28944, 30064,
+- 31184, 31254, 31674, 31744, 31800, 32136, 32976, 34096, 34936, 35272, 35328,
+- 35384, 35720, 36560, 37680, 38520, 38856, 38912, 39332, 40172, 40592, 41432,
+- 43112, 43952, 44372, 45212, 45632, 45968, 47088, 47424, 47480, 48320, 49160,
+- 49216, 49272, 50112, 50952, 51008, 51344, 52464, 3856, 3912, 3968, 4024,
+- 52800, 52856, 53024, 53192, 53248, 53528, 54368, 55208, 55488, 55768, 56608,
+- 57448, 57728, 58064, 58400, 58736, 59072, 59408, 59744, 60080, 60416, 60472,
+- 60752, 60920, 60928, 60936, 61104, 61384, 4080, 4088, 61440, 61468, 61524,
+- 61552, 61720, 62056, 62224, 62392, 62728, 62896, 62952, 63008, 63064, 63120,
+- 63128, 63296, 63576, 63632, 63688, 63968, 64136, 64144, 64200, 64256, 64312,
+- 64368, 64396, 64452, 64480, 64536, 64592, 64648, 64704, 64712, 64720, 64776,
+- 64832, 64888, 64944, 64972, 65028, 65056, 65112, 65168, 65224, 65280, 65336,
+- 65392, 65448, 65504, 65512, 65520, 65528};
+-
+-/* A3 - Number of the absolute leaders in codebooks Q2 and Q3 */
+-const UCHAR fdk_dec_A3[NB_LDQ3] = {0, 1, 4, 2, 3, 7, 11, 17, 22};
+-
+-/* A4 - Number of the absolute leaders in codebook Q4 */
+-const UCHAR fdk_dec_A4[NB_LDQ4] = {5, 6, 8, 9, 10, 12, 13, 14, 15, 16,
+- 18, 19, 20, 21, 23, 24, 25, 26, 27, 28,
+- 29, 30, 31, 32, 33, 34, 35, 36};
+-
+-/* I3 - Cardinality offsets for absolute leaders in Q3 */
+-const USHORT fdk_dec_I3[NB_LDQ3] = {0, 128, 240, 256, 1376,
+- 2400, 3744, 3856, 4080};
+-
+-/* I4 - Cardinality offset for absolute leaders in Q4 */
+-const USHORT fdk_dec_I4[NB_LDQ4] = {
+- 0, 1792, 5376, 5632, 12800, 21760, 22784, 31744, 38912, 45632,
+- 52800, 53248, 57728, 60416, 61440, 61552, 62896, 63120, 64144, 64368,
+- 64480, 64704, 64720, 64944, 65056, 65280, 65504, 65520};
+-
+-/* Initial ISF memory for concealment case */
+-#define LSFI(x) ((x) << (FRACT_BITS - LSF_SCALE - 1))
+-
+-const FIXP_LPC fdk_dec_lsf_init[16] = {1506, 3012, 4518, 6024, 7529, 9035,
+- 10541, 12047, 13553, 15059, 16565, 18071,
+- 19576, 21082, 22588, 24094};
+-
+-/* dico_lsf_abs_8b is scaled by 1/(1<<13) */
+-#define DICO(x) FX_DBL2FXCONST_LPC(x >> (LSF_SCALE - 13))
+-
+-const FIXP_LPC fdk_dec_dico_lsf_abs_8b[] = {
+- DICO(0x05e57fe8), DICO(0x0ac00810), DICO(0x11ed8500), DICO(0x16d42ce0),
+- DICO(0x1beb1e20), DICO(0x217eaf40), DICO(0x2768c740), DICO(0x2d26f600),
+- DICO(0x32fe68c0), DICO(0x38b1d980), DICO(0x3e95bd80), DICO(0x446dab00),
+- DICO(0x4abfd280), DICO(0x5094b380), DICO(0x56ccb800), DICO(0x5c9aba00),
+- DICO(0x09660ca0), DICO(0x10ab4c00), DICO(0x15a16f20), DICO(0x19d3c780),
+- DICO(0x1ee99060), DICO(0x241d1200), DICO(0x29c83700), DICO(0x2f098f00),
+- DICO(0x34803fc0), DICO(0x3a37bc00), DICO(0x3ff55580), DICO(0x45da9280),
+- DICO(0x4bec6700), DICO(0x5169e300), DICO(0x57797c80), DICO(0x5d09ae80),
+- DICO(0x08a203b0), DICO(0x0d6ed1a0), DICO(0x152ccf20), DICO(0x19639dc0),
+- DICO(0x1d7e3e60), DICO(0x21f4a7c0), DICO(0x27b2f8c0), DICO(0x2dbb4480),
+- DICO(0x33ecde80), DICO(0x3982e100), DICO(0x3ea16100), DICO(0x43ab6080),
+- DICO(0x49534a80), DICO(0x4ea7e100), DICO(0x550d6300), DICO(0x5bcdcc80),
+- DICO(0x072dd048), DICO(0x0c654690), DICO(0x1436e940), DICO(0x19459680),
+- DICO(0x1e0041c0), DICO(0x2240dc80), DICO(0x26de4040), DICO(0x2b509b00),
+- DICO(0x309d8780), DICO(0x36151180), DICO(0x3c6c1200), DICO(0x42df6b80),
+- DICO(0x4a144400), DICO(0x50541280), DICO(0x56c34b80), DICO(0x5cb6c600),
+- DICO(0x051fef00), DICO(0x06b9fb48), DICO(0x0b4f9cc0), DICO(0x17e27800),
+- DICO(0x1b8c7340), DICO(0x1f772ca0), DICO(0x2478dc80), DICO(0x28242240),
+- DICO(0x2f27c640), DICO(0x33b03e80), DICO(0x381f20c0), DICO(0x3c662c00),
+- DICO(0x49565080), DICO(0x529b0f00), DICO(0x583ed080), DICO(0x5d8cec00),
+- DICO(0x071c4d18), DICO(0x097853b0), DICO(0x0f0f0690), DICO(0x157bf980),
+- DICO(0x1801f580), DICO(0x1deb0c20), DICO(0x2523da40), DICO(0x28534600),
+- DICO(0x2eb499c0), DICO(0x32eb5ac0), DICO(0x36749580), DICO(0x3a748200),
+- DICO(0x4325f700), DICO(0x515d8300), DICO(0x58a18700), DICO(0x5d722100),
+- DICO(0x06cbcd88), DICO(0x08bb6740), DICO(0x0dead310), DICO(0x152f0cc0),
+- DICO(0x18427640), DICO(0x1d9f2f20), DICO(0x22ba3b40), DICO(0x271a6e80),
+- DICO(0x2c677ec0), DICO(0x31061b00), DICO(0x349eef40), DICO(0x3c531b80),
+- DICO(0x4aed0580), DICO(0x4f8bbf80), DICO(0x54b74980), DICO(0x5bc9b700),
+- DICO(0x046410c8), DICO(0x06522ab0), DICO(0x0b6528c0), DICO(0x0f94bd90),
+- DICO(0x1a8f8b80), DICO(0x1ea57820), DICO(0x233ee180), DICO(0x27b3acc0),
+- DICO(0x2bd1d240), DICO(0x2fc4bcc0), DICO(0x3a98ea40), DICO(0x43d3f500),
+- DICO(0x49b37580), DICO(0x4e2afd00), DICO(0x55953300), DICO(0x5d36f600),
+- DICO(0x05d0f6c8), DICO(0x07e56d90), DICO(0x0be98080), DICO(0x0f956f30),
+- DICO(0x1259b3c0), DICO(0x1f08b240), DICO(0x25008c00), DICO(0x2900b180),
+- DICO(0x31ea6f00), DICO(0x352d1e00), DICO(0x3c970c80), DICO(0x45271200),
+- DICO(0x4b632280), DICO(0x5098a480), DICO(0x5672fc80), DICO(0x5c163180),
+- DICO(0x05bd81a0), DICO(0x07d4b8f0), DICO(0x0ce224b0), DICO(0x110abe20),
+- DICO(0x13dfeac0), DICO(0x17dedae0), DICO(0x2535c0c0), DICO(0x2a19da80),
+- DICO(0x2e5224c0), DICO(0x38ddeec0), DICO(0x3da99d80), DICO(0x42799100),
+- DICO(0x48973b00), DICO(0x4ea62880), DICO(0x53f77e80), DICO(0x5bd9c100),
+- DICO(0x0395cd50), DICO(0x058244b8), DICO(0x0af45520), DICO(0x1329cea0),
+- DICO(0x1a3970c0), DICO(0x1d9f2e00), DICO(0x21704400), DICO(0x277a34c0),
+- DICO(0x30215b40), DICO(0x33875040), DICO(0x3c159840), DICO(0x452fea00),
+- DICO(0x4981d200), DICO(0x4e15a980), DICO(0x54e84780), DICO(0x5c79ea00),
+- DICO(0x05413b98), DICO(0x08132a80), DICO(0x0dc7f050), DICO(0x13e25460),
+- DICO(0x1784bf80), DICO(0x1d630200), DICO(0x238bc880), DICO(0x28cc0880),
+- DICO(0x30da1a40), DICO(0x391e2200), DICO(0x415d8d00), DICO(0x48f13280),
+- DICO(0x4e300300), DICO(0x52e56580), DICO(0x5849fe80), DICO(0x5cdef400),
+- DICO(0x04a058c8), DICO(0x07569b88), DICO(0x0ef26610), DICO(0x13208140),
+- DICO(0x168c0500), DICO(0x1afec080), DICO(0x22a0abc0), DICO(0x2a057880),
+- DICO(0x2fd1c840), DICO(0x3703c680), DICO(0x3d326b80), DICO(0x43df2e80),
+- DICO(0x4a6f9000), DICO(0x50900d80), DICO(0x56c73f00), DICO(0x5cc3da80),
+- DICO(0x065c99e8), DICO(0x09060c50), DICO(0x0d1ef1c0), DICO(0x16bd9020),
+- DICO(0x1a04dae0), DICO(0x1e3c0580), DICO(0x25783700), DICO(0x29710ac0),
+- DICO(0x309cbb80), DICO(0x36c66280), DICO(0x3adb0580), DICO(0x41b37e00),
+- DICO(0x496ca700), DICO(0x4dab7600), DICO(0x52be6280), DICO(0x58fec480),
+- DICO(0x04640880), DICO(0x05a75ab8), DICO(0x0edba410), DICO(0x16e076a0),
+- DICO(0x198acec0), DICO(0x1eb5fae0), DICO(0x228c9000), DICO(0x29986c00),
+- DICO(0x2c780c80), DICO(0x38078dc0), DICO(0x3f42dc00), DICO(0x441ba900),
+- DICO(0x492f8080), DICO(0x4ed85d00), DICO(0x54605800), DICO(0x5d106a80),
+- DICO(0x045cb970), DICO(0x0627a828), DICO(0x0db35290), DICO(0x1778f780),
+- DICO(0x1a243c60), DICO(0x23c2dd40), DICO(0x27c57840), DICO(0x2f53cd80),
+- DICO(0x36f65600), DICO(0x3bc1b2c0), DICO(0x40c36500), DICO(0x46074180),
+- DICO(0x4b551b80), DICO(0x50a99700), DICO(0x569b6c80), DICO(0x5ca25780),
+- DICO(0x05ef2828), DICO(0x07d3adf8), DICO(0x0b5416d0), DICO(0x0f9adb70),
+- DICO(0x126e7360), DICO(0x1baff460), DICO(0x2b5decc0), DICO(0x31036200),
+- DICO(0x34ca7500), DICO(0x39681340), DICO(0x3da97100), DICO(0x4161ee00),
+- DICO(0x46a62e80), DICO(0x4d1b9380), DICO(0x530e0300), DICO(0x59ff0480),
+- DICO(0x04f5bc50), DICO(0x06e90d18), DICO(0x0c2af480), DICO(0x123f7400),
+- DICO(0x1530a160), DICO(0x18aa3dc0), DICO(0x1cc0a240), DICO(0x2cdb02c0),
+- DICO(0x32909a00), DICO(0x36bae640), DICO(0x3c917a80), DICO(0x40121900),
+- DICO(0x48a90d80), DICO(0x51ccc180), DICO(0x5884ea00), DICO(0x5dbc4280),
+- DICO(0x05791410), DICO(0x07b0dd80), DICO(0x0bec4190), DICO(0x13c30520),
+- DICO(0x17ac1900), DICO(0x1b6f1d00), DICO(0x26e54f40), DICO(0x2d4a8040),
+- DICO(0x311c6840), DICO(0x38ec4180), DICO(0x3f0c4340), DICO(0x427c5b00),
+- DICO(0x4886e480), DICO(0x504a0b00), DICO(0x56d48700), DICO(0x5c80f600),
+- DICO(0x04b58880), DICO(0x0743f0d8), DICO(0x0be95e20), DICO(0x0fd0d9b0),
+- DICO(0x1c2e11a0), DICO(0x2241af80), DICO(0x296e83c0), DICO(0x2f16adc0),
+- DICO(0x32cd6fc0), DICO(0x374ddec0), DICO(0x3da95f80), DICO(0x45d56c80),
+- DICO(0x4c6afa80), DICO(0x5141f380), DICO(0x5616b380), DICO(0x5c58f580),
+- DICO(0x03f4b368), DICO(0x05939890), DICO(0x09d95480), DICO(0x122cac60),
+- DICO(0x17e27e00), DICO(0x1f9dc680), DICO(0x26e26680), DICO(0x2ae64040),
+- DICO(0x2dd6cf40), DICO(0x3295c400), DICO(0x3e23b400), DICO(0x44fd0380),
+- DICO(0x4ad7a700), DICO(0x51295e80), DICO(0x594a9400), DICO(0x5e41aa00),
+- DICO(0x0424b9d8), DICO(0x05b30508), DICO(0x09380f20), DICO(0x0c9509c0),
+- DICO(0x18730860), DICO(0x219a9d40), DICO(0x24f699c0), DICO(0x289b2680),
+- DICO(0x2cb62240), DICO(0x36e88180), DICO(0x3e968800), DICO(0x48053c80),
+- DICO(0x4d6dca80), DICO(0x51d9a580), DICO(0x563e5a80), DICO(0x5c0b2b80),
+- DICO(0x03456ae8), DICO(0x04e49948), DICO(0x07dd0e88), DICO(0x0ed5cd30),
+- DICO(0x1b06e980), DICO(0x1de2b9c0), DICO(0x21160540), DICO(0x270a8240),
+- DICO(0x3352a280), DICO(0x3b8b6c00), DICO(0x40241400), DICO(0x43f60f80),
+- DICO(0x4a897900), DICO(0x51692a00), DICO(0x57449d00), DICO(0x5d497480),
+- DICO(0x04b94290), DICO(0x067e99d0), DICO(0x0ab06840), DICO(0x0e697070),
+- DICO(0x1745c460), DICO(0x22ee8040), DICO(0x2647e8c0), DICO(0x2bc2c680),
+- DICO(0x2fd57d00), DICO(0x37186680), DICO(0x3d074500), DICO(0x412b2800),
+- DICO(0x4579af00), DICO(0x4caff980), DICO(0x557add00), DICO(0x5c6ae780),
+- DICO(0x0423a090), DICO(0x05b9bca0), DICO(0x091b45d0), DICO(0x0c5b6d60),
+- DICO(0x194dd1c0), DICO(0x1fc85020), DICO(0x2486b080), DICO(0x2920af80),
+- DICO(0x2dd4f140), DICO(0x3598be40), DICO(0x3b9c1440), DICO(0x42d19280),
+- DICO(0x4a314280), DICO(0x50b00a00), DICO(0x56c55400), DICO(0x5d5ba300),
+- DICO(0x03e68b28), DICO(0x05a7b190), DICO(0x0917f000), DICO(0x0d247050),
+- DICO(0x19e637a0), DICO(0x2221a540), DICO(0x2777e540), DICO(0x2c103380),
+- DICO(0x30c2e040), DICO(0x389f1240), DICO(0x3f4a2c80), DICO(0x454a4c00),
+- DICO(0x4b0ab680), DICO(0x50cf6000), DICO(0x571c0700), DICO(0x5d2ef600),
+- DICO(0x04886f18), DICO(0x065103e8), DICO(0x0a607d40), DICO(0x0db91960),
+- DICO(0x13546f20), DICO(0x22f5e200), DICO(0x27064240), DICO(0x2e371d40),
+- DICO(0x33659240), DICO(0x38aa1c40), DICO(0x417bb280), DICO(0x47ca9480),
+- DICO(0x4dd6fb80), DICO(0x528e3480), DICO(0x57c49d80), DICO(0x5cc98100),
+- DICO(0x02db2370), DICO(0x04398848), DICO(0x07a8da38), DICO(0x10b90280),
+- DICO(0x1a2a4a20), DICO(0x20b1f640), DICO(0x277096c0), DICO(0x2dc568c0),
+- DICO(0x341b33c0), DICO(0x3a000640), DICO(0x40152880), DICO(0x45eeee00),
+- DICO(0x4c08c480), DICO(0x51bf0600), DICO(0x5799a180), DICO(0x5d23db80),
+- DICO(0x047b1498), DICO(0x06089848), DICO(0x0905af20), DICO(0x0bf13c20),
+- DICO(0x11fcf620), DICO(0x1f79cd00), DICO(0x257f6b40), DICO(0x2cfc2600),
+- DICO(0x31610040), DICO(0x35ea8280), DICO(0x3c774bc0), DICO(0x44417280),
+- DICO(0x4b432500), DICO(0x510e9480), DICO(0x56f2e480), DICO(0x5d282780),
+- DICO(0x02cfd0b0), DICO(0x042845d8), DICO(0x0a1fa610), DICO(0x15911fc0),
+- DICO(0x1bc07f00), DICO(0x2281d640), DICO(0x287abcc0), DICO(0x2ec6b400),
+- DICO(0x34a0d040), DICO(0x3aa4dcc0), DICO(0x4074d980), DICO(0x46726b80),
+- DICO(0x4c3bf900), DICO(0x52055100), DICO(0x57b20500), DICO(0x5d34da80),
+- DICO(0x04d4f768), DICO(0x06cad828), DICO(0x0b52a540), DICO(0x0ea224e0),
+- DICO(0x13c3f460), DICO(0x23808900), DICO(0x27d1cec0), DICO(0x2d6051c0),
+- DICO(0x33c5ff00), DICO(0x37ef2440), DICO(0x3d2a5300), DICO(0x43266000),
+- DICO(0x4a53a100), DICO(0x50acce80), DICO(0x57612100), DICO(0x5cdee380),
+- DICO(0x04039a88), DICO(0x0626dcb0), DICO(0x0c059620), DICO(0x12c3db20),
+- DICO(0x1bb9eb40), DICO(0x240fda00), DICO(0x2baab840), DICO(0x3177c5c0),
+- DICO(0x36cf2e40), DICO(0x3c025100), DICO(0x40bb8d00), DICO(0x45960800),
+- DICO(0x4adaca00), DICO(0x505a7300), DICO(0x566a6400), DICO(0x5c8ce000),
+- DICO(0x062891e8), DICO(0x09680810), DICO(0x0e9a11b0), DICO(0x1523e320),
+- DICO(0x1c57db00), DICO(0x21f22c80), DICO(0x28aeeb00), DICO(0x2e4fd600),
+- DICO(0x341cf000), DICO(0x3a5034c0), DICO(0x40600f80), DICO(0x461fde00),
+- DICO(0x4c368480), DICO(0x51dbbc00), DICO(0x57709780), DICO(0x5cce9880),
+- DICO(0x05d41f70), DICO(0x0a65bb30), DICO(0x132ddfa0), DICO(0x17d26820),
+- DICO(0x1e6d8380), DICO(0x24e68dc0), DICO(0x2b68c4c0), DICO(0x30fa2880),
+- DICO(0x361998c0), DICO(0x3aa1d640), DICO(0x3f942400), DICO(0x44d11680),
+- DICO(0x4ab8e580), DICO(0x50643b80), DICO(0x5697fe00), DICO(0x5cb3a780),
+- DICO(0x0707fa10), DICO(0x0cb8beb0), DICO(0x15011d20), DICO(0x1a4ad300),
+- DICO(0x20997080), DICO(0x26dbe240), DICO(0x2d907880), DICO(0x3307a3c0),
+- DICO(0x38819740), DICO(0x3d3e89c0), DICO(0x41ea2300), DICO(0x469ce200),
+- DICO(0x4be61680), DICO(0x51261b80), DICO(0x5716ef80), DICO(0x5cba2900),
+- DICO(0x084dc830), DICO(0x0f16f610), DICO(0x16ca2420), DICO(0x1bb58380),
+- DICO(0x22f00f00), DICO(0x296ba4c0), DICO(0x306d2600), DICO(0x362ca080),
+- DICO(0x3b86d280), DICO(0x3ffa96c0), DICO(0x446a5300), DICO(0x48d0fd00),
+- DICO(0x4d8a0800), DICO(0x525bf200), DICO(0x57f5aa00), DICO(0x5d569480),
+- DICO(0x08d664f0), DICO(0x110c8520), DICO(0x1865fa40), DICO(0x1efe3160),
+- DICO(0x26f38740), DICO(0x2d4608c0), DICO(0x32862500), DICO(0x374f8840),
+- DICO(0x3bfa9900), DICO(0x3ff5c8c0), DICO(0x4450c500), DICO(0x4918e680),
+- DICO(0x4e1d0f00), DICO(0x53342600), DICO(0x58a38e00), DICO(0x5dbbff00),
+- DICO(0x09143fd0), DICO(0x0f401c30), DICO(0x169c1ee0), DICO(0x1bcfb280),
+- DICO(0x2190dd00), DICO(0x27bf56c0), DICO(0x2e8e0640), DICO(0x34b67080),
+- DICO(0x3b534dc0), DICO(0x41134c00), DICO(0x467a3280), DICO(0x4bd63600),
+- DICO(0x50de8700), DICO(0x55657580), DICO(0x5a0cef00), DICO(0x5e8aa200),
+- DICO(0x06b5d860), DICO(0x0c8a5000), DICO(0x13343620), DICO(0x17a2abe0),
+- DICO(0x1caf7340), DICO(0x22a3f740), DICO(0x29059980), DICO(0x2ecff880),
+- DICO(0x34ce0f00), DICO(0x3ad32280), DICO(0x40f08d80), DICO(0x46d1d400),
+- DICO(0x4ca9df00), DICO(0x523b9580), DICO(0x57ea9b80), DICO(0x5d4a9a00),
+- DICO(0x03822fec), DICO(0x0522c670), DICO(0x099f89a0), DICO(0x12ddc9c0),
+- DICO(0x17c3d380), DICO(0x1d27ec20), DICO(0x2219e480), DICO(0x25fdf580),
+- DICO(0x329d6500), DICO(0x368ba040), DICO(0x3afedb00), DICO(0x430db980),
+- DICO(0x4a105380), DICO(0x51205080), DICO(0x5673b880), DICO(0x5ca2e500),
+- DICO(0x04e07408), DICO(0x06a13dc0), DICO(0x0b31c780), DICO(0x0e67fcd0),
+- DICO(0x13723240), DICO(0x1f87a840), DICO(0x2321ab00), DICO(0x2c604680),
+- DICO(0x310bc180), DICO(0x351eea40), DICO(0x3a2d6440), DICO(0x3e7ebac0),
+- DICO(0x4798ef80), DICO(0x50721100), DICO(0x57ff9880), DICO(0x5dc2e080),
+- DICO(0x05d626b8), DICO(0x07eaf140), DICO(0x0c5675b0), DICO(0x0eba7b00),
+- DICO(0x1a7f36c0), DICO(0x1f969200), DICO(0x244d8c00), DICO(0x29666440),
+- DICO(0x2c94b100), DICO(0x31865380), DICO(0x3713c000), DICO(0x3c228f40),
+- DICO(0x4296ed80), DICO(0x4dcbde00), DICO(0x56059a00), DICO(0x5c932d00),
+- DICO(0x07dceb20), DICO(0x0b533fe0), DICO(0x0eb18880), DICO(0x13124220),
+- DICO(0x167f74e0), DICO(0x1afbee40), DICO(0x229e2f80), DICO(0x26b05ec0),
+- DICO(0x2c7b4040), DICO(0x32806140), DICO(0x38da6540), DICO(0x3e495540),
+- DICO(0x444d3880), DICO(0x4e784400), DICO(0x5865f580), DICO(0x5e616180),
+- DICO(0x06395790), DICO(0x084b8f20), DICO(0x0d0e26a0), DICO(0x10897ac0),
+- DICO(0x14bcd080), DICO(0x1c5babe0), DICO(0x2108f9c0), DICO(0x274f8e80),
+- DICO(0x2b0ba180), DICO(0x305b8480), DICO(0x383ad300), DICO(0x3e34f440),
+- DICO(0x47f7aa00), DICO(0x4fdb5880), DICO(0x56b8c280), DICO(0x5d07d700),
+- DICO(0x051f0880), DICO(0x071b8fa8), DICO(0x0ce79c90), DICO(0x1005bd60),
+- DICO(0x14a4a080), DICO(0x183def40), DICO(0x1ee8d0a0), DICO(0x2c5b9bc0),
+- DICO(0x309f9dc0), DICO(0x35659380), DICO(0x3c0439c0), DICO(0x49603800),
+- DICO(0x5018a800), DICO(0x54862380), DICO(0x593edd80), DICO(0x5d415b80),
+- DICO(0x051c8108), DICO(0x06bd97d8), DICO(0x0b47d030), DICO(0x0d9c81a0),
+- DICO(0x178f0be0), DICO(0x1cdf7c80), DICO(0x2183db40), DICO(0x26ec7180),
+- DICO(0x2a3856c0), DICO(0x366c9b40), DICO(0x3d3611c0), DICO(0x42788100),
+- DICO(0x4981f200), DICO(0x4dd68380), DICO(0x55286a00), DICO(0x5cc72500),
+- DICO(0x06ee58c8), DICO(0x098b1310), DICO(0x0ccbd880), DICO(0x0f9d68f0),
+- DICO(0x1277ac40), DICO(0x1d71faa0), DICO(0x230d9480), DICO(0x276b8c00),
+- DICO(0x2ec77000), DICO(0x31f2a700), DICO(0x3bee0200), DICO(0x42250700),
+- DICO(0x466b7100), DICO(0x4de41980), DICO(0x56a08d80), DICO(0x5d700880),
+- DICO(0x062f1d80), DICO(0x091bcd30), DICO(0x0cd875e0), DICO(0x0fd42e60),
+- DICO(0x1322b980), DICO(0x1f11b480), DICO(0x2651e5c0), DICO(0x29f9b480),
+- DICO(0x2e238840), DICO(0x30fc58c0), DICO(0x37aa3040), DICO(0x3e9ac580),
+- DICO(0x44c6fd00), DICO(0x4eba4300), DICO(0x56fdad00), DICO(0x5d885700),
+- DICO(0x04213a78), DICO(0x05d028c0), DICO(0x09a1f9e0), DICO(0x0d28ae90),
+- DICO(0x151819a0), DICO(0x1c78c860), DICO(0x21d78f00), DICO(0x29992cc0),
+- DICO(0x2fbdc180), DICO(0x36bab700), DICO(0x3d4db1c0), DICO(0x4402a280),
+- DICO(0x4a920700), DICO(0x50988600), DICO(0x5717c100), DICO(0x5d52c200),
+- DICO(0x036af4bc), DICO(0x0514cf40), DICO(0x09ec2d30), DICO(0x113de160),
+- DICO(0x1991b700), DICO(0x20590bc0), DICO(0x23892a00), DICO(0x2654cd00),
+- DICO(0x2ff5c0c0), DICO(0x387ed380), DICO(0x3e305300), DICO(0x46137700),
+- DICO(0x4bc29100), DICO(0x4f96dd80), DICO(0x564aca00), DICO(0x5c4d9e80),
+- DICO(0x041051a0), DICO(0x0734dad8), DICO(0x1064e780), DICO(0x14d8bf00),
+- DICO(0x19727e40), DICO(0x1f7bede0), DICO(0x25b5ebc0), DICO(0x2c71fd40),
+- DICO(0x32813740), DICO(0x39340c80), DICO(0x3f974f40), DICO(0x45ca1580),
+- DICO(0x4be69f00), DICO(0x51c9c900), DICO(0x57a1ce80), DICO(0x5d0b2b00),
+- DICO(0x04b73008), DICO(0x06598b60), DICO(0x0b0aee00), DICO(0x15ac7ba0),
+- DICO(0x18b5e340), DICO(0x1f5308c0), DICO(0x23cfc4c0), DICO(0x27d3fdc0),
+- DICO(0x30138080), DICO(0x343c85c0), DICO(0x389cb540), DICO(0x42def900),
+- DICO(0x4aa6a000), DICO(0x4f719580), DICO(0x5585d080), DICO(0x5bc03f00),
+- DICO(0x05601b88), DICO(0x07616b88), DICO(0x0c22ba40), DICO(0x16bc8200),
+- DICO(0x192ebf80), DICO(0x1f71c120), DICO(0x25c59d00), DICO(0x28f76d00),
+- DICO(0x33dbdd80), DICO(0x39f40d80), DICO(0x3da0c880), DICO(0x432c1e00),
+- DICO(0x4aa19d80), DICO(0x51006f80), DICO(0x56a62e80), DICO(0x5c67d000),
+- DICO(0x053095d0), DICO(0x06c43fc8), DICO(0x0f80a460), DICO(0x139b4960),
+- DICO(0x1769ed80), DICO(0x1c828b00), DICO(0x21195980), DICO(0x26329800),
+- DICO(0x29f35900), DICO(0x2dc9df80), DICO(0x3795f0c0), DICO(0x43139b00),
+- DICO(0x4acae680), DICO(0x5048de00), DICO(0x57c11880), DICO(0x5db35900),
+- DICO(0x0466e180), DICO(0x05d31550), DICO(0x10cad200), DICO(0x168c2be0),
+- DICO(0x1a5e9580), DICO(0x1ef2d480), DICO(0x238db240), DICO(0x2920ce80),
+- DICO(0x2c80b4c0), DICO(0x30bb2700), DICO(0x38b257c0), DICO(0x46abd580),
+- DICO(0x4c30dd80), DICO(0x50e51880), DICO(0x5782ab80), DICO(0x5d23da80),
+- DICO(0x06700f78), DICO(0x085ec0a0), DICO(0x0c037280), DICO(0x16d90a60),
+- DICO(0x1bf46c00), DICO(0x1e6f4740), DICO(0x22c2c180), DICO(0x263fa2c0),
+- DICO(0x2c4a74c0), DICO(0x3642b040), DICO(0x3a476900), DICO(0x3ea12840),
+- DICO(0x46b6e880), DICO(0x4b5bad80), DICO(0x5152a500), DICO(0x5c1c6080),
+- DICO(0x041f8108), DICO(0x05ef1d98), DICO(0x0ce43300), DICO(0x11647cc0),
+- DICO(0x16e77fe0), DICO(0x1cdafc40), DICO(0x218832c0), DICO(0x26dd1b40),
+- DICO(0x2c776100), DICO(0x34f1eb80), DICO(0x3caf6100), DICO(0x45630a80),
+- DICO(0x4c0c5380), DICO(0x517ae980), DICO(0x567f4280), DICO(0x5c4bf900),
+- DICO(0x06673f18), DICO(0x091ee510), DICO(0x0d6ccb10), DICO(0x12503240),
+- DICO(0x158696e0), DICO(0x1f035420), DICO(0x24e6eac0), DICO(0x2a03bf40),
+- DICO(0x329aa000), DICO(0x375aafc0), DICO(0x3da133c0), DICO(0x45645600),
+- DICO(0x4c447c00), DICO(0x51a26b00), DICO(0x57917c00), DICO(0x5c557680),
+- DICO(0x04f84c18), DICO(0x06db4c30), DICO(0x0d53a940), DICO(0x1095cd20),
+- DICO(0x142b0b20), DICO(0x184229c0), DICO(0x20147280), DICO(0x25152740),
+- DICO(0x2db89fc0), DICO(0x35f3d200), DICO(0x400aa680), DICO(0x47a51c00),
+- DICO(0x4d9c5c00), DICO(0x525d1680), DICO(0x5832af00), DICO(0x5d27d580),
+- DICO(0x05c973d0), DICO(0x07c25810), DICO(0x0e928e50), DICO(0x12f5ad00),
+- DICO(0x16b2a800), DICO(0x1c2c9ce0), DICO(0x20b0f100), DICO(0x28be1940),
+- DICO(0x2d0f3c00), DICO(0x30a06f40), DICO(0x399e4340), DICO(0x46b48280),
+- DICO(0x4bbbc300), DICO(0x50283700), DICO(0x54a1a800), DICO(0x5ab20c80),
+- DICO(0x03df9390), DICO(0x055ff1e0), DICO(0x0bbeb640), DICO(0x17d906c0),
+- DICO(0x1ac20140), DICO(0x1fd84440), DICO(0x24502600), DICO(0x2a9fe640),
+- DICO(0x2ef79700), DICO(0x34cbed40), DICO(0x3c48cd00), DICO(0x43ccce80),
+- DICO(0x49b1d500), DICO(0x50145e00), DICO(0x56f16f80), DICO(0x5d46dd80),
+- DICO(0x04a69ef0), DICO(0x06470480), DICO(0x0defbd00), DICO(0x1590e900),
+- DICO(0x18114000), DICO(0x1bda6c60), DICO(0x1f64d160), DICO(0x28d8d640),
+- DICO(0x2d4e2880), DICO(0x34cfe380), DICO(0x3b7077c0), DICO(0x42f36a80),
+- DICO(0x49615580), DICO(0x4ff9d200), DICO(0x5657ef80), DICO(0x5cb91300),
+- DICO(0x038893dc), DICO(0x0535cdf0), DICO(0x0aabff80), DICO(0x146daaa0),
+- DICO(0x1848c700), DICO(0x1ce578c0), DICO(0x21116000), DICO(0x2b116d40),
+- DICO(0x32113500), DICO(0x3751a480), DICO(0x3e88c200), DICO(0x44cb1800),
+- DICO(0x4af1c200), DICO(0x5122b980), DICO(0x5782bc80), DICO(0x5d20be00),
+- DICO(0x03118434), DICO(0x04afe2e8), DICO(0x08f144f0), DICO(0x12c787c0),
+- DICO(0x1c32e4e0), DICO(0x1f701180), DICO(0x2362f740), DICO(0x2b995cc0),
+- DICO(0x3322c540), DICO(0x3951f200), DICO(0x3f7c2c80), DICO(0x4569c480),
+- DICO(0x4b2a6200), DICO(0x50905e80), DICO(0x56236680), DICO(0x5c32fa00),
+- DICO(0x0460c3b0), DICO(0x061e1378), DICO(0x0b07f610), DICO(0x166e0680),
+- DICO(0x18d0f020), DICO(0x21120340), DICO(0x24d4c000), DICO(0x29bafc00),
+- DICO(0x338c0740), DICO(0x36cfbc00), DICO(0x3f313900), DICO(0x47bf9c00),
+- DICO(0x4dd5d480), DICO(0x52848200), DICO(0x585add00), DICO(0x5cf7b480),
+- DICO(0x041a4bc8), DICO(0x05ca0920), DICO(0x0a3ae5b0), DICO(0x13fbb840),
+- DICO(0x1cdd3d00), DICO(0x209d5b80), DICO(0x27e78e80), DICO(0x2d1f4ec0),
+- DICO(0x32d84c80), DICO(0x3b8aa680), DICO(0x4289c180), DICO(0x46c33580),
+- DICO(0x4c23e580), DICO(0x51583180), DICO(0x56f52680), DICO(0x5c7a3d00),
+- DICO(0x03067404), DICO(0x05914038), DICO(0x10d33e60), DICO(0x17377180),
+- DICO(0x1d7f32a0), DICO(0x23848880), DICO(0x29d32200), DICO(0x2fb167c0),
+- DICO(0x356c8480), DICO(0x3b420280), DICO(0x4106d080), DICO(0x46d29280),
+- DICO(0x4c8a1200), DICO(0x52383300), DICO(0x57db8f80), DICO(0x5d61f200),
+- DICO(0x04baf368), DICO(0x06670a08), DICO(0x0e0cbd90), DICO(0x126299c0),
+- DICO(0x17ed7220), DICO(0x1e369900), DICO(0x22d7d300), DICO(0x2c0f9300),
+- DICO(0x2f5e7fc0), DICO(0x3b7c0d40), DICO(0x405aff80), DICO(0x44f2ef80),
+- DICO(0x4982b400), DICO(0x4e501380), DICO(0x539daa00), DICO(0x5c114b00),
+- DICO(0x0694c170), DICO(0x092d6890), DICO(0x0d0faee0), DICO(0x13800d00),
+- DICO(0x170f8d80), DICO(0x1bcd8240), DICO(0x246a8480), DICO(0x28bab640),
+- DICO(0x2f482ac0), DICO(0x36e736c0), DICO(0x3aaa68c0), DICO(0x3fc43500),
+- DICO(0x46e16000), DICO(0x4b3fbc00), DICO(0x4ff68e80), DICO(0x5aabf600),
+- DICO(0x05e849a0), DICO(0x0b485a80), DICO(0x14be52c0), DICO(0x1a079380),
+- DICO(0x1e8b1ce0), DICO(0x22fbca00), DICO(0x28c36a40), DICO(0x2e3b2a00),
+- DICO(0x34360b80), DICO(0x3a24cf00), DICO(0x3fff6200), DICO(0x45a6bf00),
+- DICO(0x4baf7800), DICO(0x51720e80), DICO(0x57560c80), DICO(0x5ce57e00),
+- DICO(0x0751da38), DICO(0x0f0949f0), DICO(0x18141860), DICO(0x1dfcb2c0),
+- DICO(0x24adbf00), DICO(0x296af240), DICO(0x2dbe60c0), DICO(0x3179ae40),
+- DICO(0x35ec4400), DICO(0x3ab76400), DICO(0x4034f400), DICO(0x45cfc700),
+- DICO(0x4bea6b00), DICO(0x516f5f00), DICO(0x57655300), DICO(0x5cfc0e00),
+- DICO(0x069900d0), DICO(0x0d379520), DICO(0x175d0560), DICO(0x1c4d92c0),
+- DICO(0x21407680), DICO(0x250d0340), DICO(0x29804940), DICO(0x2dfb9ac0),
+- DICO(0x337a1f80), DICO(0x39105fc0), DICO(0x3efd0380), DICO(0x44bce380),
+- DICO(0x4b07cc80), DICO(0x50ad7d00), DICO(0x56ddce80), DICO(0x5cb9a000),
+- DICO(0x069c6948), DICO(0x0a56ea10), DICO(0x0f7cca20), DICO(0x12d18680),
+- DICO(0x17036d00), DICO(0x1f4c1e80), DICO(0x262e5540), DICO(0x2b951e40),
+- DICO(0x3468ad40), DICO(0x3a2b2100), DICO(0x3f02f0c0), DICO(0x4383e400),
+- DICO(0x48374180), DICO(0x4d8eec80), DICO(0x54d74800), DICO(0x5c309600),
+- DICO(0x05a50158), DICO(0x0797e350), DICO(0x0cf1f230), DICO(0x14f3fb20),
+- DICO(0x17676400), DICO(0x20636780), DICO(0x2617ef80), DICO(0x29cbf700),
+- DICO(0x32ed57c0), DICO(0x374c3080), DICO(0x3b348e40), DICO(0x3fde0180),
+- DICO(0x44d38c00), DICO(0x4a8c6100), DICO(0x55f0e400), DICO(0x5dfed100),
+- DICO(0x04b74228), DICO(0x0623d3e0), DICO(0x0ab4c670), DICO(0x1bde7fa0),
+- DICO(0x1fcb6ac0), DICO(0x2344a540), DICO(0x275f7c40), DICO(0x2b7a8300),
+- DICO(0x31407440), DICO(0x35237700), DICO(0x38798540), DICO(0x3d0af340),
+- DICO(0x4224c980), DICO(0x49a17900), DICO(0x57702880), DICO(0x5dba4c00),
+- DICO(0x03c83c84), DICO(0x05cc52d8), DICO(0x0b644c10), DICO(0x129ab9a0),
+- DICO(0x1cee46c0), DICO(0x2152b080), DICO(0x247b1c00), DICO(0x27697180),
+- DICO(0x304f7500), DICO(0x3895d880), DICO(0x3c3a1740), DICO(0x413ace80),
+- DICO(0x462b0100), DICO(0x4ab07e00), DICO(0x50967580), DICO(0x5ba5e700),
+- DICO(0x06bcfda8), DICO(0x08c8b920), DICO(0x0de21530), DICO(0x1028d320),
+- DICO(0x168cfe00), DICO(0x20f78a40), DICO(0x248493c0), DICO(0x2c34bf80),
+- DICO(0x2ff88540), DICO(0x32d28c40), DICO(0x36d99640), DICO(0x4438e500),
+- DICO(0x4bacdb00), DICO(0x50343700), DICO(0x56b79080), DICO(0x5b694d00),
+- DICO(0x069109a0), DICO(0x0a73bc50), DICO(0x0e3c8330), DICO(0x13082620),
+- DICO(0x1c3a3760), DICO(0x200b5e80), DICO(0x256a4880), DICO(0x2b256ac0),
+- DICO(0x2f34afc0), DICO(0x35580200), DICO(0x3e0bd9c0), DICO(0x43d92900),
+- DICO(0x494e6e00), DICO(0x4f1a2780), DICO(0x5532a980), DICO(0x5a835a80),
+- DICO(0x04053450), DICO(0x05cb8fe0), DICO(0x097387b0), DICO(0x1121af00),
+- DICO(0x1abf62c0), DICO(0x1e39bbe0), DICO(0x243de300), DICO(0x2b440ec0),
+- DICO(0x2f2c1480), DICO(0x34697d80), DICO(0x405f8600), DICO(0x440b6f80),
+- DICO(0x47373100), DICO(0x4c764f80), DICO(0x55293780), DICO(0x5c59a780),
+- DICO(0x03c5b4a4), DICO(0x056fb380), DICO(0x09b8f910), DICO(0x13833fa0),
+- DICO(0x185eed60), DICO(0x1ce33d40), DICO(0x242e4100), DICO(0x282e5b80),
+- DICO(0x2cfe4d40), DICO(0x38a06d80), DICO(0x3e002240), DICO(0x423be400),
+- DICO(0x49a5e600), DICO(0x5092b780), DICO(0x57023d00), DICO(0x5d5f7c80),
+- DICO(0x077ada38), DICO(0x09d5ac70), DICO(0x0e58be30), DICO(0x14fb2040),
+- DICO(0x17fc9dc0), DICO(0x1c2c31e0), DICO(0x26cf1b00), DICO(0x2a91ba80),
+- DICO(0x2ed880c0), DICO(0x38cbf900), DICO(0x3d2fc700), DICO(0x405d2280),
+- DICO(0x439c1d00), DICO(0x4dd16800), DICO(0x5672c080), DICO(0x5d313880),
+- DICO(0x04272090), DICO(0x05d76e18), DICO(0x0b4d8080), DICO(0x12883f60),
+- DICO(0x17952180), DICO(0x2040d480), DICO(0x23e8cc00), DICO(0x2819c200),
+- DICO(0x2b871040), DICO(0x357c8f00), DICO(0x3caf9ac0), DICO(0x40a39380),
+- DICO(0x45bc2780), DICO(0x4e4aa300), DICO(0x568c2280), DICO(0x5cadc400),
+- DICO(0x0375b03c), DICO(0x056f0b40), DICO(0x0b0dc930), DICO(0x128c51e0),
+- DICO(0x189fa360), DICO(0x1c8197e0), DICO(0x1eed52a0), DICO(0x23ed4500),
+- DICO(0x2e5eb840), DICO(0x36415a40), DICO(0x3dcf6340), DICO(0x43126e80),
+- DICO(0x4aeb7f80), DICO(0x501e1280), DICO(0x5852b100), DICO(0x5d040d80),
+- DICO(0x06351b88), DICO(0x07f90ac0), DICO(0x0bab4ea0), DICO(0x18d04b40),
+- DICO(0x1f1e1480), DICO(0x219abcc0), DICO(0x261c31c0), DICO(0x2a611a00),
+- DICO(0x2e725480), DICO(0x36b511c0), DICO(0x3d362f00), DICO(0x40be6d80),
+- DICO(0x456dc400), DICO(0x4b74c580), DICO(0x55c82680), DICO(0x5e318480),
+- DICO(0x046212d8), DICO(0x05ca95e8), DICO(0x0a02d910), DICO(0x1ae58f40),
+- DICO(0x1e73ec20), DICO(0x2197d640), DICO(0x2581df00), DICO(0x29c83780),
+- DICO(0x31294300), DICO(0x356f8a40), DICO(0x3b97d240), DICO(0x4505cc80),
+- DICO(0x4b497600), DICO(0x504e8780), DICO(0x55644480), DICO(0x5bdedf80),
+- DICO(0x0514f798), DICO(0x06bd0d00), DICO(0x0fc31550), DICO(0x13dfb1a0),
+- DICO(0x17dda900), DICO(0x204a8c40), DICO(0x23095300), DICO(0x2d0da040),
+- DICO(0x31b2a540), DICO(0x34620180), DICO(0x3ab3e000), DICO(0x448ac300),
+- DICO(0x4be6a600), DICO(0x5114e280), DICO(0x562b0780), DICO(0x5b833c00),
+- DICO(0x070f5ef0), DICO(0x0919c2b0), DICO(0x0e778740), DICO(0x154db320),
+- DICO(0x177cfbe0), DICO(0x1ea66040), DICO(0x23666680), DICO(0x2839c400),
+- DICO(0x30cc4ec0), DICO(0x3444a280), DICO(0x38c93580), DICO(0x42a80e00),
+- DICO(0x4c433880), DICO(0x519e4f80), DICO(0x56ff8f80), DICO(0x5be18200),
+- DICO(0x066c5968), DICO(0x08a589f0), DICO(0x0ca4d7a0), DICO(0x0ffdefb0),
+- DICO(0x12943f40), DICO(0x1be84ee0), DICO(0x21276540), DICO(0x265a9540),
+- DICO(0x2e0de140), DICO(0x325148c0), DICO(0x3bd05d40), DICO(0x41e81780),
+- DICO(0x4b7cf400), DICO(0x53289400), DICO(0x597d9000), DICO(0x5e458e00),
+- DICO(0x04da3e40), DICO(0x06e8e1b0), DICO(0x0b9b1a20), DICO(0x11264bc0),
+- DICO(0x14f3d7e0), DICO(0x1cf9c100), DICO(0x23568f40), DICO(0x292b5380),
+- DICO(0x33878d40), DICO(0x38dac840), DICO(0x3d578200), DICO(0x4223a880),
+- DICO(0x473fb700), DICO(0x4c765500), DICO(0x546c6480), DICO(0x5c76d280),
+- DICO(0x05e63bb0), DICO(0x07a1a428), DICO(0x0ec4ff10), DICO(0x1348a100),
+- DICO(0x16204f40), DICO(0x1a0a6440), DICO(0x1e33f6c0), DICO(0x2ae8ccc0),
+- DICO(0x2ed5e6c0), DICO(0x32427600), DICO(0x379d9980), DICO(0x3c0f4080),
+- DICO(0x441ea680), DICO(0x4e592b00), DICO(0x56e27700), DICO(0x5da2e280),
+- DICO(0x0474de80), DICO(0x06167248), DICO(0x0ce650e0), DICO(0x135b4aa0),
+- DICO(0x16cea2a0), DICO(0x1d138ac0), DICO(0x220a84c0), DICO(0x275ca380),
+- DICO(0x2c300340), DICO(0x333b3d80), DICO(0x37a35080), DICO(0x40b83880),
+- DICO(0x494c4780), DICO(0x4ff71c80), DICO(0x56db2d80), DICO(0x5d0aac00),
+- DICO(0x0746cd00), DICO(0x09deff10), DICO(0x0e4a3560), DICO(0x14f005e0),
+- DICO(0x186a4de0), DICO(0x1cd0b240), DICO(0x22287bc0), DICO(0x26ced500),
+- DICO(0x2d57c440), DICO(0x31d943c0), DICO(0x364b0f80), DICO(0x3c85a040),
+- DICO(0x4240ca00), DICO(0x4a648080), DICO(0x54d12200), DICO(0x5d1a1c00),
+- DICO(0x05522eb0), DICO(0x0704efb8), DICO(0x0c66cd50), DICO(0x15aefca0),
+- DICO(0x184f7b00), DICO(0x1e4b26a0), DICO(0x22667640), DICO(0x284e4e00),
+- DICO(0x2d8be3c0), DICO(0x31376f00), DICO(0x39cd9800), DICO(0x3e46b740),
+- DICO(0x43af0380), DICO(0x4e1dec00), DICO(0x562ac500), DICO(0x5d45f580),
+- DICO(0x062f5708), DICO(0x08d079a0), DICO(0x0c1b4920), DICO(0x13f147c0),
+- DICO(0x1ae77c80), DICO(0x1d200ea0), DICO(0x236e4740), DICO(0x2b98d000),
+- DICO(0x2eefc600), DICO(0x34c674c0), DICO(0x3d36f540), DICO(0x411d8c00),
+- DICO(0x45c50300), DICO(0x4d207480), DICO(0x55603100), DICO(0x5c442d80),
+- DICO(0x0510bcd0), DICO(0x06ec00a0), DICO(0x0b639550), DICO(0x15daa2c0),
+- DICO(0x18c0ba60), DICO(0x1e0f7d60), DICO(0x24b05c80), DICO(0x280638c0),
+- DICO(0x314a6580), DICO(0x35e4b2c0), DICO(0x3aef2bc0), DICO(0x4158c280),
+- DICO(0x4d245100), DICO(0x53c69a80), DICO(0x597f1000), DICO(0x5dcb0080),
+- DICO(0x042cb748), DICO(0x05d710b0), DICO(0x0afe6130), DICO(0x1256cdc0),
+- DICO(0x15b8cd00), DICO(0x1dc72d20), DICO(0x2205fc00), DICO(0x2a3d0d00),
+- DICO(0x2f3ba600), DICO(0x33b3d840), DICO(0x3b5a5440), DICO(0x416c9d00),
+- DICO(0x497cdd80), DICO(0x50405e00), DICO(0x570ca980), DICO(0x5d3aa180),
+- DICO(0x0443b7b8), DICO(0x063d8588), DICO(0x0c76ef20), DICO(0x12709b40),
+- DICO(0x1649f0a0), DICO(0x20c522c0), DICO(0x24cde400), DICO(0x2ba78280),
+- DICO(0x3104c340), DICO(0x360b1740), DICO(0x3cd6a6c0), DICO(0x42573800),
+- DICO(0x48b18480), DICO(0x4fca1e00), DICO(0x5700c100), DICO(0x5cf14480),
+- DICO(0x05123628), DICO(0x06bf10b0), DICO(0x0bde7570), DICO(0x175b7ee0),
+- DICO(0x1a134460), DICO(0x20fa4100), DICO(0x25eda440), DICO(0x29c3b540),
+- DICO(0x318a1b40), DICO(0x35e0d500), DICO(0x3a147f00), DICO(0x3f08e980),
+- DICO(0x445d7580), DICO(0x4ec48c80), DICO(0x588bce80), DICO(0x5dfae300),
+- DICO(0x04c9e750), DICO(0x065224f8), DICO(0x0c6f1e30), DICO(0x1a2ffca0),
+- DICO(0x1cac6140), DICO(0x21c2a640), DICO(0x25fb8ac0), DICO(0x2ab90f00),
+- DICO(0x33189200), DICO(0x38088ac0), DICO(0x3bb7de40), DICO(0x40180800),
+- DICO(0x4453c300), DICO(0x4cdba880), DICO(0x54902680), DICO(0x5bb21700),
+- DICO(0x06958570), DICO(0x097f32b0), DICO(0x0cb418b0), DICO(0x141b6900),
+- DICO(0x1c8cfb00), DICO(0x1fab7920), DICO(0x2477c800), DICO(0x2aabed40),
+- DICO(0x2eb1a080), DICO(0x339f67c0), DICO(0x3abcc240), DICO(0x3f661b00),
+- DICO(0x45663280), DICO(0x4c680800), DICO(0x51703000), DICO(0x58a0e000),
+- DICO(0x069f6c88), DICO(0x095e1490), DICO(0x0cf442b0), DICO(0x10ea8d60),
+- DICO(0x1377b580), DICO(0x195ed480), DICO(0x26542b00), DICO(0x2c9ea700),
+- DICO(0x318d8ac0), DICO(0x364e5a40), DICO(0x3a0db000), DICO(0x3e1087c0),
+- DICO(0x450ca380), DICO(0x4c781d00), DICO(0x53cf7a00), DICO(0x5c7d1280),
+- DICO(0x06e51d98), DICO(0x09eb8d30), DICO(0x0e6683d0), DICO(0x129418a0),
+- DICO(0x1562fc80), DICO(0x1f708660), DICO(0x253f1000), DICO(0x293a16c0),
+- DICO(0x2e7c1d80), DICO(0x316e75c0), DICO(0x35a7fbc0), DICO(0x3bfbf780),
+- DICO(0x416a9200), DICO(0x4be36400), DICO(0x56dc7a80), DICO(0x5d64ea80),
+- DICO(0x0574d0c8), DICO(0x0748efd0), DICO(0x0b510860), DICO(0x0e219e00),
+- DICO(0x1299cc00), DICO(0x1ef706a0), DICO(0x22ca38c0), DICO(0x28820a00),
+- DICO(0x2cc635c0), DICO(0x31ef4740), DICO(0x3a5e89c0), DICO(0x42acaa00),
+- DICO(0x4b2bf500), DICO(0x515e0980), DICO(0x57949400), DICO(0x5d002500),
+- DICO(0x07c715d0), DICO(0x0b3fa110), DICO(0x0e745370), DICO(0x11e93560),
+- DICO(0x14bad680), DICO(0x189a0400), DICO(0x240b1240), DICO(0x2a6b3580),
+- DICO(0x2e5e1380), DICO(0x352072c0), DICO(0x3a5037c0), DICO(0x3e3726c0),
+- DICO(0x4725ed80), DICO(0x4f885900), DICO(0x54c8d580), DICO(0x5b261680),
+- DICO(0x075f02a8), DICO(0x0a214900), DICO(0x0e189de0), DICO(0x1376d5a0),
+- DICO(0x163d5c80), DICO(0x1a94b3e0), DICO(0x21376980), DICO(0x259c3140),
+- DICO(0x2e663bc0), DICO(0x337884c0), DICO(0x3a035c00), DICO(0x40b32c00),
+- DICO(0x4b21de00), DICO(0x53298f00), DICO(0x58788080), DICO(0x5cfa7c00),
+- DICO(0x05658988), DICO(0x0797f470), DICO(0x0d250810), DICO(0x102fc2a0),
+- DICO(0x13738fe0), DICO(0x1740bbc0), DICO(0x2491b380), DICO(0x28bc5800),
+- DICO(0x2c75a940), DICO(0x325cb500), DICO(0x37944740), DICO(0x405f2d80),
+- DICO(0x48eb8f00), DICO(0x50676f80), DICO(0x56f70380), DICO(0x5d62c000),
+- DICO(0x0531b540), DICO(0x06ae64c0), DICO(0x0cf7ad30), DICO(0x11c83000),
+- DICO(0x14edc980), DICO(0x18d436c0), DICO(0x1e184080), DICO(0x2603bb80),
+- DICO(0x2a2f2f80), DICO(0x33bdbe00), DICO(0x3a1066c0), DICO(0x42b9ff00),
+- DICO(0x4a617580), DICO(0x51619480), DICO(0x57ccd500), DICO(0x5d4d1600),
+- DICO(0x03e40bac), DICO(0x05f53158), DICO(0x0e76d3b0), DICO(0x17c157a0),
+- DICO(0x1ccb5bc0), DICO(0x250129c0), DICO(0x2b7d9d00), DICO(0x33224d80),
+- DICO(0x3966f600), DICO(0x3f399480), DICO(0x4449fc80), DICO(0x49401b80),
+- DICO(0x4e2ab580), DICO(0x53117000), DICO(0x5848e080), DICO(0x5d66a280),
+- DICO(0x041d4f60), DICO(0x070e8080), DICO(0x1390ec40), DICO(0x177c42c0),
+- DICO(0x1beb1400), DICO(0x208b0580), DICO(0x264cbb40), DICO(0x2bd30940),
+- DICO(0x30b30880), DICO(0x36978e80), DICO(0x3cb2a140), DICO(0x43f6b080),
+- DICO(0x4a881000), DICO(0x505ca780), DICO(0x569a5d80), DICO(0x5cae3580),
+- DICO(0x03f3c760), DICO(0x05564e08), DICO(0x09e310d0), DICO(0x1b9b3d00),
+- DICO(0x20909ac0), DICO(0x2382eec0), DICO(0x278c6700), DICO(0x2b34d500),
+- DICO(0x30fa2ac0), DICO(0x34d27d40), DICO(0x38e334c0), DICO(0x3d732440),
+- DICO(0x46d07800), DICO(0x51f4d400), DICO(0x57744f80), DICO(0x5d56bb80),
+- DICO(0x03abfdd8), DICO(0x0512b140), DICO(0x135f7500), DICO(0x19fcc4c0),
+- DICO(0x1d0b1b80), DICO(0x21eca540), DICO(0x258f8700), DICO(0x29e292c0),
+- DICO(0x2c51fe80), DICO(0x31e2a180), DICO(0x3c638640), DICO(0x44873a00),
+- DICO(0x4bb7e800), DICO(0x5078f700), DICO(0x57fc9b80), DICO(0x5def1c00),
+- DICO(0x04721ef0), DICO(0x06688158), DICO(0x0f65a5d0), DICO(0x14499840),
+- DICO(0x1bf5b8c0), DICO(0x1f33b700), DICO(0x264b6900), DICO(0x2c3e6780),
+- DICO(0x2ec8d440), DICO(0x323885c0), DICO(0x37143300), DICO(0x3bafa800),
+- DICO(0x49030480), DICO(0x54c16b00), DICO(0x58ec4b00), DICO(0x5d713d00),
+- DICO(0x03d114e4), DICO(0x067e5b40), DICO(0x10393420), DICO(0x14961300),
+- DICO(0x1a59cfa0), DICO(0x20854240), DICO(0x26b3f300), DICO(0x2e3e2840),
+- DICO(0x323bd300), DICO(0x37c49280), DICO(0x3d79e500), DICO(0x4352d880),
+- DICO(0x49e17980), DICO(0x4fc72f80), DICO(0x55c0c680), DICO(0x5c53c700),
+- DICO(0x053f5de8), DICO(0x075162b8), DICO(0x0fae8050), DICO(0x13ec0ee0),
+- DICO(0x17f92440), DICO(0x1f054440), DICO(0x24b15d40), DICO(0x2add4480),
+- DICO(0x2e306300), DICO(0x35420680), DICO(0x3c6b6e00), DICO(0x42fc0380),
+- DICO(0x4732e380), DICO(0x4ceb2200), DICO(0x522efe00), DICO(0x5aa12680),
+- DICO(0x06111728), DICO(0x08183c80), DICO(0x0d026650), DICO(0x14b41940),
+- DICO(0x17e37320), DICO(0x1c40b160), DICO(0x219c5400), DICO(0x26d88840),
+- DICO(0x2bfdfe00), DICO(0x315a2800), DICO(0x38cd7140), DICO(0x3de22740),
+- DICO(0x48ff1300), DICO(0x53ef4180), DICO(0x5a479380), DICO(0x5ea1e380),
+- DICO(0x07ea0fa8), DICO(0x0a844ef0), DICO(0x0e1023c0), DICO(0x1208d980),
+- DICO(0x15891360), DICO(0x1bebc380), DICO(0x2087da40), DICO(0x257ac940),
+- DICO(0x2caefa00), DICO(0x300defc0), DICO(0x376aa000), DICO(0x438aad80),
+- DICO(0x49f00500), DICO(0x4e023780), DICO(0x524e5800), DICO(0x5abcb980),
+- DICO(0x079cfc88), DICO(0x0a367240), DICO(0x0f224330), DICO(0x15b51540),
+- DICO(0x19065420), DICO(0x1ddbe0a0), DICO(0x23a99d80), DICO(0x28c2d340),
+- DICO(0x2f627e40), DICO(0x3487e080), DICO(0x38b76bc0), DICO(0x3d135580),
+- DICO(0x43799a80), DICO(0x489a5000), DICO(0x4ece6280), DICO(0x5a82f500),
+- DICO(0x06c37e40), DICO(0x093f0540), DICO(0x0e0d0c30), DICO(0x17487860),
+- DICO(0x1bf78020), DICO(0x20318000), DICO(0x260b8300), DICO(0x2c615980),
+- DICO(0x30c88440), DICO(0x36433b40), DICO(0x3bdb8c40), DICO(0x40050c80),
+- DICO(0x44062f80), DICO(0x48a8d480), DICO(0x4dd64d00), DICO(0x55abd380),
+- DICO(0x05e9e828), DICO(0x07f24330), DICO(0x0c8b4fe0), DICO(0x0ecd2820),
+- DICO(0x17f05c00), DICO(0x1fdb4560), DICO(0x24b4c940), DICO(0x2968d0c0),
+- DICO(0x2cbf3500), DICO(0x381eadc0), DICO(0x3d3baf40), DICO(0x42828080),
+- DICO(0x47f36300), DICO(0x4c8c6600), DICO(0x51d66f00), DICO(0x5a7e0300),
+- DICO(0x065c5cf8), DICO(0x08882540), DICO(0x0d887c70), DICO(0x112ac560),
+- DICO(0x150ccdc0), DICO(0x19e49c20), DICO(0x1eb65680), DICO(0x2a76e040),
+- DICO(0x2f65fc00), DICO(0x36d79cc0), DICO(0x3c85a900), DICO(0x408dc680),
+- DICO(0x44964700), DICO(0x4a98eb00), DICO(0x5528b500), DICO(0x5d660f80),
+- DICO(0x06b56230), DICO(0x08e340f0), DICO(0x0e1e4380), DICO(0x112d2d40),
+- DICO(0x158dfde0), DICO(0x227e6040), DICO(0x26bff7c0), DICO(0x2b73a100),
+- DICO(0x32199580), DICO(0x3585a240), DICO(0x398a5d40), DICO(0x3db8c6c0),
+- DICO(0x43905600), DICO(0x4945f800), DICO(0x4f310380), DICO(0x5a6d2400),
+- DICO(0x05cfc6f8), DICO(0x0832e650), DICO(0x0de82f80), DICO(0x1a1afe80),
+- DICO(0x1e9a1f80), DICO(0x221acd80), DICO(0x27fa00c0), DICO(0x2c4df980),
+- DICO(0x31e04bc0), DICO(0x38c9ed40), DICO(0x3db86080), DICO(0x428ec800),
+- DICO(0x48500500), DICO(0x4e1ca580), DICO(0x53d3f500), DICO(0x5aa6be00),
+- DICO(0x050cc4d0), DICO(0x070c2180), DICO(0x0c4ca980), DICO(0x0fce9f40),
+- DICO(0x14af4160), DICO(0x2206a780), DICO(0x25848e80), DICO(0x2c2b84c0),
+- DICO(0x35a39980), DICO(0x3914bd80), DICO(0x3caff580), DICO(0x3fcb0600),
+- DICO(0x4426b380), DICO(0x486c9700), DICO(0x4f730480), DICO(0x5afd3980),
+- DICO(0x05e40640), DICO(0x0830df50), DICO(0x0b9e83e0), DICO(0x158bacc0),
+- DICO(0x1d0692e0), DICO(0x2021e0c0), DICO(0x26572e00), DICO(0x2d58cc40),
+- DICO(0x30dd0f80), DICO(0x361d68c0), DICO(0x3e3086c0), DICO(0x42450800),
+- DICO(0x46c25800), DICO(0x4c45cf00), DICO(0x51dd4200), DICO(0x57326500),
+- DICO(0x04d32fa0), DICO(0x064ed2c0), DICO(0x0b07cd70), DICO(0x1c7f6da0),
+- DICO(0x213bc140), DICO(0x25051fc0), DICO(0x295cd1c0), DICO(0x2c9f4f80),
+- DICO(0x32271540), DICO(0x36a8ec80), DICO(0x3a8e6b40), DICO(0x3e137580),
+- DICO(0x42795480), DICO(0x4779b780), DICO(0x4f7d9600), DICO(0x5c09b000),
+- DICO(0x044b0748), DICO(0x05fee680), DICO(0x08f66960), DICO(0x11db5940),
+- DICO(0x219ede80), DICO(0x27fb96c0), DICO(0x2affc980), DICO(0x2eadc3c0),
+- DICO(0x32895700), DICO(0x37180d00), DICO(0x3d4bf880), DICO(0x41741980),
+- DICO(0x460d8280), DICO(0x4c34be80), DICO(0x54531e80), DICO(0x5c874000),
+- DICO(0x03e25dcc), DICO(0x069e8170), DICO(0x13b3d9c0), DICO(0x1a803260),
+- DICO(0x1ed3a4a0), DICO(0x23ea6380), DICO(0x2883b900), DICO(0x2e0ceac0),
+- DICO(0x3308e400), DICO(0x38796dc0), DICO(0x3e318e80), DICO(0x441da080),
+- DICO(0x4a892300), DICO(0x509b9f80), DICO(0x56caa380), DICO(0x5cc39e00),
+- DICO(0x05023038), DICO(0x06b6b4d8), DICO(0x0a449370), DICO(0x15b86ea0),
+- DICO(0x224a9200), DICO(0x272e6f40), DICO(0x2a617700), DICO(0x2e915d00),
+- DICO(0x3240ac40), DICO(0x37636300), DICO(0x3dd3ea80), DICO(0x420e1f80),
+- DICO(0x45bf0680), DICO(0x4a26d980), DICO(0x4f82a900), DICO(0x56576800),
+- DICO(0x03d630f4), DICO(0x082140a0), DICO(0x12644700), DICO(0x16b80cc0),
+- DICO(0x1ba90c40), DICO(0x21c38300), DICO(0x27dd1480), DICO(0x2e18ee00),
+- DICO(0x33fb72c0), DICO(0x39f9d980), DICO(0x40219300), DICO(0x4607fd00),
+- DICO(0x4c07e500), DICO(0x51ba8f00), DICO(0x57a24280), DICO(0x5d367700),
+- DICO(0x080a5880), DICO(0x0ef3f570), DICO(0x141fd6c0), DICO(0x17c163a0),
+- DICO(0x1c2840a0), DICO(0x2111fe00), DICO(0x27376bc0), DICO(0x2cc7edc0),
+- DICO(0x329b0100), DICO(0x386d3e40), DICO(0x3ec1bdc0), DICO(0x453f6200),
+- DICO(0x4bf16080), DICO(0x51bded00), DICO(0x57ba6800), DICO(0x5d2ffd80),
+- DICO(0x08643590), DICO(0x0e911f00), DICO(0x15911380), DICO(0x1ab5e180),
+- DICO(0x207ff600), DICO(0x26399b00), DICO(0x2cadae80), DICO(0x3276ca40),
+- DICO(0x389d9cc0), DICO(0x3eb22180), DICO(0x44570700), DICO(0x49d15800),
+- DICO(0x4f591300), DICO(0x54566a80), DICO(0x5967db00), DICO(0x5e307780),
+- DICO(0x07120fa8), DICO(0x0c791c60), DICO(0x112d3b60), DICO(0x149452a0),
+- DICO(0x19d2c100), DICO(0x202f1540), DICO(0x269c10c0), DICO(0x2be22880),
+- DICO(0x312a07c0), DICO(0x36984fc0), DICO(0x3c7ac3c0), DICO(0x435b5000),
+- DICO(0x4aa60280), DICO(0x50f50c00), DICO(0x5719f700), DICO(0x5cb98680),
+- DICO(0x05517c88), DICO(0x06ba0a70), DICO(0x0da167c0), DICO(0x19918440),
+- DICO(0x1bb37220), DICO(0x20681080), DICO(0x23dc6740), DICO(0x2a1403c0),
+- DICO(0x31a71580), DICO(0x34ff0600), DICO(0x395b7cc0), DICO(0x42019200),
+- DICO(0x4c818d00), DICO(0x513ff400), DICO(0x5731ce00), DICO(0x5c5f1180),
+- DICO(0x04f74ec0), DICO(0x067b4628), DICO(0x0dc4c9c0), DICO(0x19e9fa40),
+- DICO(0x1cf00a00), DICO(0x21602a80), DICO(0x25334a80), DICO(0x29b3a800),
+- DICO(0x2f9b3600), DICO(0x338c0540), DICO(0x370c3cc0), DICO(0x3abbc3c0),
+- DICO(0x4053a000), DICO(0x4f14d980), DICO(0x57e0b600), DICO(0x5d95e780),
+- DICO(0x05d844b8), DICO(0x07a05608), DICO(0x0b7837f0), DICO(0x161fb460),
+- DICO(0x19c31d00), DICO(0x1cf36280), DICO(0x20ccc200), DICO(0x24ae3980),
+- DICO(0x2e2b5800), DICO(0x3316af80), DICO(0x37432b00), DICO(0x4050b280),
+- DICO(0x4605be00), DICO(0x4cc78900), DICO(0x556d2080), DICO(0x5c578300),
+- DICO(0x0551b768), DICO(0x07024f60), DICO(0x1045fde0), DICO(0x16480120),
+- DICO(0x19974420), DICO(0x1ec2b280), DICO(0x228b30c0), DICO(0x295e0ec0),
+- DICO(0x2d8775c0), DICO(0x30ef1440), DICO(0x35978080), DICO(0x3a2ab480),
+- DICO(0x40229780), DICO(0x4da40980), DICO(0x5718e480), DICO(0x5d68d400),
+- DICO(0x03f903e4), DICO(0x06731580), DICO(0x0ecf4850), DICO(0x12e57920),
+- DICO(0x1a69ece0), DICO(0x1fe32700), DICO(0x2585b9c0), DICO(0x2aa006c0),
+- DICO(0x2f20ea80), DICO(0x37298bc0), DICO(0x3df2a000), DICO(0x44a6c600),
+- DICO(0x4b10de00), DICO(0x510fb880), DICO(0x5749c280), DICO(0x5d0b9480),
+- DICO(0x03c418fc), DICO(0x056c4cd0), DICO(0x0d0cf070), DICO(0x1907a2c0),
+- DICO(0x1be9bc00), DICO(0x21599480), DICO(0x25700e40), DICO(0x2c83e280),
+- DICO(0x329fa7c0), DICO(0x389f4cc0), DICO(0x3ef60900), DICO(0x44c19300),
+- DICO(0x4af56d00), DICO(0x512eec80), DICO(0x5772ad00), DICO(0x5d37f380),
+- DICO(0x04d57920), DICO(0x0716b5e0), DICO(0x0cb3bcc0), DICO(0x1197f740),
+- DICO(0x163e5fc0), DICO(0x2194e400), DICO(0x274bb600), DICO(0x2f5d7080),
+- DICO(0x361ee340), DICO(0x3b3b22c0), DICO(0x3f800400), DICO(0x4327ef80),
+- DICO(0x48b5d200), DICO(0x5116d300), DICO(0x59652e80), DICO(0x5e444d00),
+- DICO(0x0755b6b0), DICO(0x0b68c2c0), DICO(0x0f3441d0), DICO(0x124a01a0),
+- DICO(0x18910600), DICO(0x20911b80), DICO(0x281f7100), DICO(0x2e4dd640),
+- DICO(0x335bd8c0), DICO(0x37f14a80), DICO(0x3cab7b80), DICO(0x43be3180),
+- DICO(0x4beee100), DICO(0x52292180), DICO(0x57efea00), DICO(0x5d177300),
+- DICO(0x071a7748), DICO(0x0c6cf1b0), DICO(0x10db1500), DICO(0x143bca00),
+- DICO(0x1b86a900), DICO(0x22ed1d80), DICO(0x2a1f61c0), DICO(0x305f1400),
+- DICO(0x3645f580), DICO(0x3be45b00), DICO(0x4166ea80), DICO(0x46c3f200),
+- DICO(0x4c740400), DICO(0x51e30d00), DICO(0x57a37000), DICO(0x5cfc4980),
+- DICO(0x08cdd5b0), DICO(0x0daf9840), DICO(0x11cc02a0), DICO(0x1588ed40),
+- DICO(0x1cfef5e0), DICO(0x239f12c0), DICO(0x296d3b40), DICO(0x2e61c240),
+- DICO(0x333dc800), DICO(0x385d0000), DICO(0x3e1e5180), DICO(0x44196e00),
+- DICO(0x4a833000), DICO(0x503d7b80), DICO(0x56556680), DICO(0x5c410c00),
+- DICO(0x07372408), DICO(0x0d5c41f0), DICO(0x155dc140), DICO(0x1a9a3cc0),
+- DICO(0x21740980), DICO(0x27139f40), DICO(0x2c977040), DICO(0x30cfe5c0),
+- DICO(0x35381240), DICO(0x39b83140), DICO(0x3ef3fe80), DICO(0x44547200),
+- DICO(0x4a812800), DICO(0x5046c200), DICO(0x56957d00), DICO(0x5c85cd80),
+- DICO(0x06da6990), DICO(0x0bc41250), DICO(0x13d54800), DICO(0x1979c220),
+- DICO(0x1fad2f00), DICO(0x24bbe0c0), DICO(0x29c08f00), DICO(0x2e34b940),
+- DICO(0x32c89e40), DICO(0x376a2040), DICO(0x3cd81080), DICO(0x4267bd00),
+- DICO(0x48e8e800), DICO(0x4f150280), DICO(0x55cb1980), DICO(0x5c428b80),
+- DICO(0x087d45d0), DICO(0x0cf1ef20), DICO(0x135cba20), DICO(0x16fc7420),
+- DICO(0x1b2772e0), DICO(0x1fd4fe60), DICO(0x260a0b80), DICO(0x2bc54c00),
+- DICO(0x31694cc0), DICO(0x36d08080), DICO(0x3c245c80), DICO(0x41170900),
+- DICO(0x47b18600), DICO(0x4e706180), DICO(0x558d2000), DICO(0x5c428d00),
+- DICO(0x081e6490), DICO(0x0d16a7d0), DICO(0x124ccd20), DICO(0x154c20c0),
+- DICO(0x1945d8c0), DICO(0x1ee0b700), DICO(0x26a01f00), DICO(0x2d554e40),
+- DICO(0x3432eb80), DICO(0x3a605500), DICO(0x401d8980), DICO(0x45737680),
+- DICO(0x4b03cb00), DICO(0x50666780), DICO(0x56a0cd00), DICO(0x5cb46480),
+- DICO(0x06c58278), DICO(0x091b10b0), DICO(0x0e0e74f0), DICO(0x11faf980),
+- DICO(0x14a48600), DICO(0x1e6f7500), DICO(0x27f77100), DICO(0x2ab49940),
+- DICO(0x32a1f680), DICO(0x38cb2a80), DICO(0x3c3ff140), DICO(0x3f681cc0),
+- DICO(0x44310700), DICO(0x4fa21700), DICO(0x586c6180), DICO(0x5df74200),
+- DICO(0x06a3e478), DICO(0x09714400), DICO(0x0d90b7a0), DICO(0x12df2720),
+- DICO(0x1618f320), DICO(0x1ac52840), DICO(0x27612900), DICO(0x2e438e00),
+- DICO(0x322b6ac0), DICO(0x38022940), DICO(0x3d2a5180), DICO(0x40d76b80),
+- DICO(0x46671500), DICO(0x4c5bd480), DICO(0x517a2500), DICO(0x57775b00),
+- DICO(0x056c2230), DICO(0x07b8f9d8), DICO(0x0bc6e060), DICO(0x16ac2c80),
+- DICO(0x1a92fc00), DICO(0x1e15f000), DICO(0x28b73200), DICO(0x2cd9e5c0),
+- DICO(0x3196ecc0), DICO(0x3abae340), DICO(0x4040c580), DICO(0x44c18d80),
+- DICO(0x4c086800), DICO(0x50b78500), DICO(0x54e42600), DICO(0x5a549a80),
+- DICO(0x04f9fa10), DICO(0x07419358), DICO(0x0c3e15f0), DICO(0x174c1800),
+- DICO(0x1ab1fe60), DICO(0x23a12680), DICO(0x27955780), DICO(0x2d14b1c0),
+- DICO(0x35cefb00), DICO(0x39576700), DICO(0x3e82b780), DICO(0x42b6a680),
+- DICO(0x476d1880), DICO(0x4b6cdd00), DICO(0x52758680), DICO(0x5b69e500),
+- DICO(0x060b7ab0), DICO(0x081c05c0), DICO(0x0b540300), DICO(0x0f564270),
+- DICO(0x1210aa80), DICO(0x1771e060), DICO(0x25d73280), DICO(0x2e49e380),
+- DICO(0x319c1100), DICO(0x3771e700), DICO(0x3c532f40), DICO(0x40c9a900),
+- DICO(0x48cbf580), DICO(0x4f819980), DICO(0x566f9400), DICO(0x5cfdd980),
+- DICO(0x04efb7b8), DICO(0x0b8a3710), DICO(0x124fd520), DICO(0x1846dde0),
+- DICO(0x1e77a9e0), DICO(0x243ea800), DICO(0x2a4e3280), DICO(0x2ff532c0),
+- DICO(0x35d27680), DICO(0x3b8cdb00), DICO(0x41463000), DICO(0x4706c700),
+- DICO(0x4ca42d80), DICO(0x525d9200), DICO(0x57dabb80), DICO(0x5d59a800),
+- DICO(0x03620dec), DICO(0x095872e0), DICO(0x108d4920), DICO(0x16e9ea00),
+- DICO(0x1d60b2e0), DICO(0x235e9d00), DICO(0x29893b80), DICO(0x2f59a3c0),
+- DICO(0x3556b880), DICO(0x3b10bdc0), DICO(0x40f49500), DICO(0x469cc480),
+- DICO(0x4c762d00), DICO(0x51f16980), DICO(0x578c6d00), DICO(0x5c9b5a00),
+- DICO(0x05dd9bc0), DICO(0x079c5b20), DICO(0x0d319af0), DICO(0x18997040),
+- DICO(0x1c0a1980), DICO(0x20e926c0), DICO(0x25ca1640), DICO(0x29879340),
+- DICO(0x30b27040), DICO(0x36077340), DICO(0x39ac3d00), DICO(0x3d686cc0),
+- DICO(0x428e5f00), DICO(0x47c1bf80), DICO(0x4e720800), DICO(0x5b419880),
+- DICO(0x07694258), DICO(0x0b50db90), DICO(0x0f384950), DICO(0x140dac40),
+- DICO(0x17c50d80), DICO(0x1b49b300), DICO(0x24746200), DICO(0x2ce92fc0),
+- DICO(0x309fdac0), DICO(0x35c02a00), DICO(0x3aa3df00), DICO(0x3e1edb00),
+- DICO(0x431ad280), DICO(0x4b57f500), DICO(0x51463980), DICO(0x586b5200),
+- DICO(0x06401dd0), DICO(0x08d3d9b0), DICO(0x0ca0f510), DICO(0x10ed1920),
+- DICO(0x1451c2e0), DICO(0x2082f640), DICO(0x2872c0c0), DICO(0x2ca9da00),
+- DICO(0x3219cd00), DICO(0x35977300), DICO(0x3a8ba1c0), DICO(0x43d5f280),
+- DICO(0x49a51f00), DICO(0x4de9b400), DICO(0x5362ef80), DICO(0x59387300),
+- DICO(0x0589c430), DICO(0x07809918), DICO(0x0d086f80), DICO(0x10371c20),
+- DICO(0x151842c0), DICO(0x1bfcb1c0), DICO(0x22441040), DICO(0x2722b5c0),
+- DICO(0x2b603fc0), DICO(0x314465c0), DICO(0x40308b00), DICO(0x47d5a200),
+- DICO(0x4bf7e000), DICO(0x4f937200), DICO(0x5584eb00), DICO(0x5cb02200),
+- DICO(0x03b592f0), DICO(0x056ba738), DICO(0x0a8e2250), DICO(0x172436c0),
+- DICO(0x1ad35da0), DICO(0x1d72dc80), DICO(0x20cd3900), DICO(0x2a962940),
+- DICO(0x2f3b6700), DICO(0x33312b40), DICO(0x38dc6680), DICO(0x41659200),
+- DICO(0x4d36a380), DICO(0x52b00980), DICO(0x58c82800), DICO(0x5d741600),
+- DICO(0x05bdfe10), DICO(0x0756da20), DICO(0x0cd31fe0), DICO(0x130f1820),
+- DICO(0x1561caa0), DICO(0x1962ab20), DICO(0x1c310840), DICO(0x28bf6f80),
+- DICO(0x2d2d4500), DICO(0x3230f900), DICO(0x3ac2ea80), DICO(0x3ebe71c0),
+- DICO(0x48280700), DICO(0x50254900), DICO(0x5850a200), DICO(0x5e687200),
+- DICO(0x04e2b7e8), DICO(0x067f5430), DICO(0x0a8899a0), DICO(0x0d571560),
+- DICO(0x1c42f440), DICO(0x22e21fc0), DICO(0x27074340), DICO(0x2c493240),
+- DICO(0x2f7ece00), DICO(0x33959ec0), DICO(0x392d3000), DICO(0x459fc800),
+- DICO(0x4ba5f700), DICO(0x4fde7780), DICO(0x55f90380), DICO(0x5c928b00),
+- DICO(0x0557b940), DICO(0x075f0158), DICO(0x0bd8c540), DICO(0x0f4ee370),
+- DICO(0x141dc900), DICO(0x1b241f00), DICO(0x21c32a80), DICO(0x29a23980),
+- DICO(0x2e475380), DICO(0x3616f9c0), DICO(0x3a52a500), DICO(0x40345f00),
+- DICO(0x4763a500), DICO(0x4eb5bb80), DICO(0x561d4480), DICO(0x5d388580),
+- DICO(0x057d7d08), DICO(0x0738c240), DICO(0x0bf46e10), DICO(0x0ec93da0),
+- DICO(0x14ab3cc0), DICO(0x23d0f5c0), DICO(0x271e9900), DICO(0x2c0ee4c0),
+- DICO(0x301d1f00), DICO(0x33868040), DICO(0x37cdde00), DICO(0x3c805440),
+- DICO(0x43c69200), DICO(0x4f5c9a00), DICO(0x56eb3e80), DICO(0x5cdadc80),
+- DICO(0x06cdbab0), DICO(0x0999e600), DICO(0x0df39790), DICO(0x12ffc9a0),
+- DICO(0x15cfe7a0), DICO(0x1c599300), DICO(0x21afd600), DICO(0x26842bc0),
+- DICO(0x32067c00), DICO(0x368bb080), DICO(0x3c350c40), DICO(0x44e8be00),
+- DICO(0x4ac84000), DICO(0x4f9c1280), DICO(0x5449ec00), DICO(0x594d5880),
+- DICO(0x049a6bd0), DICO(0x06849f08), DICO(0x10592b40), DICO(0x168c1940),
+- DICO(0x1992df40), DICO(0x1e91b300), DICO(0x2237e100), DICO(0x2cd73a80),
+- DICO(0x30e7c100), DICO(0x361a45c0), DICO(0x3cdd1f40), DICO(0x41d5d100),
+- DICO(0x46f79480), DICO(0x4e44c880), DICO(0x55830e80), DICO(0x5d7c0680),
+- DICO(0x05087958), DICO(0x06fb7e40), DICO(0x0ac5ace0), DICO(0x14e91d80),
+- DICO(0x19ac68c0), DICO(0x1dbf7600), DICO(0x26f916c0), DICO(0x2bd2c980),
+- DICO(0x307f7900), DICO(0x38e07e40), DICO(0x3df7f1c0), DICO(0x41323d00),
+- DICO(0x44d2f480), DICO(0x48fb0480), DICO(0x51e17900), DICO(0x5c15d700),
+- DICO(0x0346cf40), DICO(0x05423408), DICO(0x0b640ce0), DICO(0x13055060),
+- DICO(0x1a8c0b60), DICO(0x1d8d2280), DICO(0x218b6500), DICO(0x2c385700),
+- DICO(0x30927b40), DICO(0x35d82880), DICO(0x3aa87e00), DICO(0x3da46a40),
+- DICO(0x45ea5280), DICO(0x511ecb80), DICO(0x57b53b00), DICO(0x5d491400),
+- DICO(0x056aa1c8), DICO(0x075a09a0), DICO(0x0a5d61d0), DICO(0x13cb9fe0),
+- DICO(0x1f924dc0), DICO(0x237a11c0), DICO(0x277d6b80), DICO(0x2c2ba440),
+- DICO(0x30195c80), DICO(0x35250cc0), DICO(0x3b718200), DICO(0x40113c80),
+- DICO(0x44df2680), DICO(0x49f0ed80), DICO(0x50791980), DICO(0x5ac10600),
+- DICO(0x046f1e50), DICO(0x061dd758), DICO(0x1236bec0), DICO(0x16c07340),
+- DICO(0x1a7399c0), DICO(0x1f61ee20), DICO(0x244b2280), DICO(0x2b803e40),
+- DICO(0x2eda5300), DICO(0x331210c0), DICO(0x3773bfc0), DICO(0x411c8400),
+- DICO(0x488ff380), DICO(0x4fad2700), DICO(0x55845000), DICO(0x5ca74c00),
+- DICO(0x04b456f0), DICO(0x05fca198), DICO(0x0ad056d0), DICO(0x19c3bfe0),
+- DICO(0x1d446100), DICO(0x20f67200), DICO(0x24a40b40), DICO(0x28d472c0),
+- DICO(0x2da813c0), DICO(0x31880200), DICO(0x35344f40), DICO(0x3ca7f340),
+- DICO(0x4aa94300), DICO(0x4f921500), DICO(0x5516d700), DICO(0x5c832880),
+- DICO(0x07f468c0), DICO(0x0bbb6e90), DICO(0x0f0f8730), DICO(0x143d6180),
+- DICO(0x198b84c0), DICO(0x1c6b30a0), DICO(0x219c8000), DICO(0x28795780),
+- DICO(0x2cce3d00), DICO(0x329b1100), DICO(0x3a8d2240), DICO(0x3f579080),
+- DICO(0x45a74400), DICO(0x4d000f80), DICO(0x52bd6880), DICO(0x5a743a80),
+- DICO(0x06979498), DICO(0x088fecf0), DICO(0x0f1dac90), DICO(0x12077160),
+- DICO(0x16d5b120), DICO(0x1c5465c0), DICO(0x21ad14c0), DICO(0x282be280),
+- DICO(0x2b66a380), DICO(0x2fa3f200), DICO(0x35a06500), DICO(0x3a458d00),
+- DICO(0x44aefc00), DICO(0x4e92f600), DICO(0x55b9fa80), DICO(0x5cfe0280),
+- DICO(0x0552b408), DICO(0x06f6ce38), DICO(0x0e8f8d80), DICO(0x1395e900),
+- DICO(0x17c7b440), DICO(0x1ec64dc0), DICO(0x236e2200), DICO(0x2abc0b80),
+- DICO(0x2e131240), DICO(0x32921100), DICO(0x372633c0), DICO(0x3ca97840),
+- DICO(0x496e5000), DICO(0x4f86a800), DICO(0x54072300), DICO(0x5be31c80),
+- DICO(0x0470c0b8), DICO(0x0662c468), DICO(0x0c493fd0), DICO(0x1a1949c0),
+- DICO(0x1febcc20), DICO(0x2364e900), DICO(0x2a0cce00), DICO(0x2f6f8140),
+- DICO(0x3418b000), DICO(0x3c5c7a40), DICO(0x42d39100), DICO(0x476c2b00),
+- DICO(0x4e11c300), DICO(0x53621500), DICO(0x583fd280), DICO(0x5ce26600),
+- DICO(0x04b006c0), DICO(0x09a1ed40), DICO(0x135aee00), DICO(0x193b5180),
+- DICO(0x1f3679a0), DICO(0x24fdbcc0), DICO(0x2b823e00), DICO(0x31835780),
+- DICO(0x37c74cc0), DICO(0x3df66780), DICO(0x43c18580), DICO(0x49465980),
+- DICO(0x4ed0ce00), DICO(0x53d6fb80), DICO(0x59064300), DICO(0x5deaa100),
+- DICO(0x03cbc49c), DICO(0x07735930), DICO(0x138aaa20), DICO(0x1a1e69a0),
+- DICO(0x21be93c0), DICO(0x2936f780), DICO(0x2fa76f80), DICO(0x34ae6b00),
+- DICO(0x396b7b80), DICO(0x3dbc6700), DICO(0x421a9100), DICO(0x46fd2180),
+- DICO(0x4c5dca80), DICO(0x51923b80), DICO(0x576d1300), DICO(0x5d288680),
+- DICO(0x03cab7d0), DICO(0x052c88b8), DICO(0x09ed24f0), DICO(0x1c261820),
+- DICO(0x209096c0), DICO(0x2361e080), DICO(0x27292800), DICO(0x2bbdc6c0),
+- DICO(0x3292da80), DICO(0x36866a40), DICO(0x3c4d5100), DICO(0x45233400),
+- DICO(0x4d928a00), DICO(0x52ca9d00), DICO(0x5820d000), DICO(0x5d903880),
+- DICO(0x03f83718), DICO(0x0540fa90), DICO(0x13028120), DICO(0x1ad6e160),
+- DICO(0x1d784880), DICO(0x22028900), DICO(0x25976b40), DICO(0x2b293700),
+- DICO(0x2ddb86c0), DICO(0x317c4340), DICO(0x34e62ec0), DICO(0x3b71bd00),
+- DICO(0x4bc34780), DICO(0x52982400), DICO(0x57fa2800), DICO(0x5f19cc00),
+- DICO(0x049ceb50), DICO(0x06a8d4e0), DICO(0x09db2470), DICO(0x120e3e60),
+- DICO(0x1c8ebb80), DICO(0x21221d00), DICO(0x2679bfc0), DICO(0x2b1e7600),
+- DICO(0x2ebbcf80), DICO(0x32d5afc0), DICO(0x3d1bef00), DICO(0x41b11a00),
+- DICO(0x45bb2d80), DICO(0x4cb70300), DICO(0x572fdc80), DICO(0x5d876e80),
+- DICO(0x04abda68), DICO(0x06698cd0), DICO(0x0ca87230), DICO(0x15086a80),
+- DICO(0x176cf4e0), DICO(0x22899440), DICO(0x268fc500), DICO(0x2ba2d940),
+- DICO(0x33505980), DICO(0x36944bc0), DICO(0x3b20c280), DICO(0x437e8f00),
+- DICO(0x4bf29e80), DICO(0x51776a80), DICO(0x57a77800), DICO(0x5cf6c180),
+- DICO(0x06d7f5c0), DICO(0x08fd3cc0), DICO(0x0d8807e0), DICO(0x1140d500),
+- DICO(0x146dfc80), DICO(0x1e9fbaa0), DICO(0x23d7bf00), DICO(0x28b2ae80),
+- DICO(0x2e5a9b00), DICO(0x327005c0), DICO(0x37736640), DICO(0x4001c500),
+- DICO(0x4a862b00), DICO(0x4f7a2e00), DICO(0x54a22080), DICO(0x5b76c380),
+- DICO(0x0671fb68), DICO(0x08e4bf30), DICO(0x0d801250), DICO(0x1176b820),
+- DICO(0x15128860), DICO(0x1ee21180), DICO(0x24799580), DICO(0x29415a40),
+- DICO(0x2efa2380), DICO(0x33fe5040), DICO(0x39bf6d00), DICO(0x3f28b380),
+- DICO(0x442b2280), DICO(0x493de680), DICO(0x54377700), DICO(0x5d3a5480),
+- DICO(0x065b7970), DICO(0x087820b0), DICO(0x0d8d6aa0), DICO(0x16718620),
+- DICO(0x1a3a8f40), DICO(0x1f4099c0), DICO(0x24d87b40), DICO(0x296d85c0),
+- DICO(0x2f887c80), DICO(0x342d1b40), DICO(0x3887fc40), DICO(0x3d758b40),
+- DICO(0x42641c80), DICO(0x47bf6980), DICO(0x55f82900), DICO(0x5e132a00),
+- DICO(0x05ddbc00), DICO(0x081f17a0), DICO(0x0bf23ac0), DICO(0x12fc8d60),
+- DICO(0x172bc440), DICO(0x1a833540), DICO(0x1e942200), DICO(0x21e477c0),
+- DICO(0x2e75da80), DICO(0x399efac0), DICO(0x3dfb6900), DICO(0x428b3780),
+- DICO(0x4922a080), DICO(0x4d4c1700), DICO(0x51bbee00), DICO(0x5b4cfc80),
+- DICO(0x06ecf380), DICO(0x08f83990), DICO(0x0cb55680), DICO(0x140b2860),
+- DICO(0x18084d00), DICO(0x1aff9940), DICO(0x1f5f6f00), DICO(0x224a3d80),
+- DICO(0x2b0f49c0), DICO(0x3613b280), DICO(0x39188f40), DICO(0x3efa3640),
+- DICO(0x4771e400), DICO(0x4ca32380), DICO(0x54627580), DICO(0x5cb91000),
+- DICO(0x069e7f98), DICO(0x0870c760), DICO(0x0d7b73a0), DICO(0x15ab1040),
+- DICO(0x18a4d220), DICO(0x1c4c1f20), DICO(0x1ffaf200), DICO(0x24142580),
+- DICO(0x30e47540), DICO(0x37340200), DICO(0x3a69af40), DICO(0x3ed471c0),
+- DICO(0x44157880), DICO(0x486b7f00), DICO(0x52ed2b00), DICO(0x5ce3a980),
+- DICO(0x047f1080), DICO(0x06463230), DICO(0x0b566e80), DICO(0x0edb9080),
+- DICO(0x128a2fa0), DICO(0x1748b340), DICO(0x210b2b00), DICO(0x28099b80),
+- DICO(0x2f519740), DICO(0x36fe82c0), DICO(0x3d924b80), DICO(0x43cd3c00),
+- DICO(0x4a774680), DICO(0x50d15f00), DICO(0x573b3580), DICO(0x5d4c1c00),
+- DICO(0x05fa6a68), DICO(0x0866e4c0), DICO(0x0d133cc0), DICO(0x156d6b20),
+- DICO(0x18abebe0), DICO(0x1d374900), DICO(0x23d23d00), DICO(0x27b370c0),
+- DICO(0x2f63ef00), DICO(0x352a0600), DICO(0x3a643a40), DICO(0x3f57f980),
+- DICO(0x457a7f00), DICO(0x520f6200), DICO(0x593b2c80), DICO(0x5e192b80),
+- DICO(0x04e4e0c8), DICO(0x067c3450), DICO(0x0acabe70), DICO(0x1865eec0),
+- DICO(0x1c5e9bc0), DICO(0x202facc0), DICO(0x24a609c0), DICO(0x28db7b00),
+- DICO(0x2efbd780), DICO(0x336fe5c0), DICO(0x3819a5c0), DICO(0x3e709b40),
+- DICO(0x4435ff80), DICO(0x4bd5fb80), DICO(0x5564a100), DICO(0x5d0a4980),
+- DICO(0x05a72f00), DICO(0x070199b0), DICO(0x0e654780), DICO(0x14fc7780),
+- DICO(0x174283c0), DICO(0x1b231480), DICO(0x1e7b9000), DICO(0x27a013c0),
+- DICO(0x2b42f500), DICO(0x2fd9ca00), DICO(0x3672a0c0), DICO(0x3cc23f40),
+- DICO(0x48299d80), DICO(0x4f92a800), DICO(0x564d7680), DICO(0x5d3ab580),
+- DICO(0x03e63764), DICO(0x05baa3f0), DICO(0x0ab2a300), DICO(0x12cc5f60),
+- DICO(0x19a8d5e0), DICO(0x1ea788e0), DICO(0x22cd50c0), DICO(0x25d48a00),
+- DICO(0x29924540), DICO(0x32762a00), DICO(0x3bba55c0), DICO(0x4222e800),
+- DICO(0x4aba1280), DICO(0x501d0b80), DICO(0x57091200), DICO(0x5d6bf180),
+- DICO(0x047daeb0), DICO(0x069548b8), DICO(0x0b002410), DICO(0x13ff7060),
+- DICO(0x186aec40), DICO(0x210db240), DICO(0x26f1ce80), DICO(0x2b73c9c0),
+- DICO(0x33d57240), DICO(0x385898c0), DICO(0x3eea8cc0), DICO(0x43c79b00),
+- DICO(0x496ec200), DICO(0x4e150780), DICO(0x54dcb700), DICO(0x5c3f7380),
+- DICO(0x079fd258), DICO(0x0b93bd50), DICO(0x0ff7d8b0), DICO(0x14bd4e00),
+- DICO(0x19536ae0), DICO(0x1d8b1640), DICO(0x23747cc0), DICO(0x2861f280),
+- DICO(0x2d7d2880), DICO(0x3583b040), DICO(0x3c3cab00), DICO(0x41b7b580),
+- DICO(0x498cfc80), DICO(0x506cbd00), DICO(0x57847600), DICO(0x5d05de80),
+- DICO(0x06434ec0), DICO(0x0805ccd0), DICO(0x0c4b4c00), DICO(0x13d551c0),
+- DICO(0x1685abe0), DICO(0x1a83ea60), DICO(0x1ddc3700), DICO(0x22bc4600),
+- DICO(0x2c7ca5c0), DICO(0x30a589c0), DICO(0x395a8700), DICO(0x40c92900),
+- DICO(0x472fae80), DICO(0x4f6f6e80), DICO(0x571b3f80), DICO(0x5d8e6980),
+- DICO(0x05ec21b0), DICO(0x079ee388), DICO(0x0e4b4580), DICO(0x11abf100),
+- DICO(0x16588ec0), DICO(0x1c984ec0), DICO(0x20a384c0), DICO(0x28d6be00),
+- DICO(0x2bcca740), DICO(0x3604b600), DICO(0x3f027280), DICO(0x434af000),
+- DICO(0x48dac280), DICO(0x4d7e8a00), DICO(0x51f61800), DICO(0x5a6d9380),
+- DICO(0x0552c6c0), DICO(0x070c22a0), DICO(0x0a411b50), DICO(0x0e3e5270),
+- DICO(0x1193bb60), DICO(0x1b177e00), DICO(0x275b2500), DICO(0x2b42bd80),
+- DICO(0x322d7e40), DICO(0x3a170880), DICO(0x3d66b580), DICO(0x41413280),
+- DICO(0x46a9ce80), DICO(0x4e4e3800), DICO(0x571f8380), DICO(0x5ddae380),
+- DICO(0x055602c0), DICO(0x06e69118), DICO(0x0c9d13f0), DICO(0x1090d500),
+- DICO(0x138d2280), DICO(0x171bf540), DICO(0x1b585180), DICO(0x288b9740),
+- DICO(0x2db202c0), DICO(0x3525e680), DICO(0x3c303900), DICO(0x4311df80),
+- DICO(0x49b92c00), DICO(0x509de900), DICO(0x56e9a080), DICO(0x5d523a80),
+- DICO(0x04e79810), DICO(0x069626e8), DICO(0x0a6cf680), DICO(0x0da668c0),
+- DICO(0x115872a0), DICO(0x2032eec0), DICO(0x25345dc0), DICO(0x2ae8ea40),
+- DICO(0x30224280), DICO(0x351ff640), DICO(0x3ce65a80), DICO(0x454bff00),
+- DICO(0x4ee08980), DICO(0x543b4280), DICO(0x59c19280), DICO(0x5ddfbb00),
+- DICO(0x03f0bb98), DICO(0x0588f4f0), DICO(0x0a862bc0), DICO(0x14ec76e0),
+- DICO(0x184b8a80), DICO(0x1f7bbd80), DICO(0x23f1a7c0), DICO(0x2c367900),
+- DICO(0x3234af80), DICO(0x35460ac0), DICO(0x38514c00), DICO(0x3d5f3540),
+- DICO(0x48394980), DICO(0x4fbdd380), DICO(0x56de0280), DICO(0x5d4e6500),
+- DICO(0x06050f28), DICO(0x08070af0), DICO(0x0be31240), DICO(0x0f5e53e0),
+- DICO(0x125f1740), DICO(0x215b1fc0), DICO(0x2883d880), DICO(0x2c181080),
+- DICO(0x32810280), DICO(0x35d56800), DICO(0x3a9b0880), DICO(0x3ffaaf80),
+- DICO(0x44c65500), DICO(0x4a45ae80), DICO(0x56b4ed80), DICO(0x5e4adc00),
+- DICO(0x0372bbb4), DICO(0x04ea4848), DICO(0x09b8de70), DICO(0x151b4a40),
+- DICO(0x1be65a00), DICO(0x207655c0), DICO(0x2720dd00), DICO(0x2fc6cc00),
+- DICO(0x35b063c0), DICO(0x39bd30c0), DICO(0x3dc5b580), DICO(0x42af7b00),
+- DICO(0x48d2bf00), DICO(0x4f46bb80), DICO(0x55f7ca80), DICO(0x5ca7e980),
+- DICO(0x033f868c), DICO(0x04d9a0e0), DICO(0x0a18d6d0), DICO(0x13da5580),
+- DICO(0x181ae880), DICO(0x207d8580), DICO(0x262022c0), DICO(0x2c6de040),
+- DICO(0x3321f100), DICO(0x3927f0c0), DICO(0x3f74ce40), DICO(0x4573e980),
+- DICO(0x4ba66c80), DICO(0x51a26100), DICO(0x57d3a800), DICO(0x5d52e780),
+- DICO(0x05189860), DICO(0x07231848), DICO(0x0b915710), DICO(0x0f05d6c0),
+- DICO(0x13bb0820), DICO(0x223adf00), DICO(0x26ce1ec0), DICO(0x2ce1ac00),
+- DICO(0x3401f6c0), DICO(0x3b8c2240), DICO(0x40e4a400), DICO(0x45674f00),
+- DICO(0x4b04b880), DICO(0x4f253200), DICO(0x54168600), DICO(0x58f52780),
+- DICO(0x0338d184), DICO(0x05205790), DICO(0x09abcd80), DICO(0x0f53ff60),
+- DICO(0x1a7fe900), DICO(0x1ef93860), DICO(0x238e2d80), DICO(0x2bd81bc0),
+- DICO(0x33161240), DICO(0x368cfb80), DICO(0x3a28b5c0), DICO(0x40c7a600),
+- DICO(0x4bac7780), DICO(0x524b7880), DICO(0x58638480), DICO(0x5da07b00),
+- DICO(0x04d06f38), DICO(0x065f1518), DICO(0x0c9b31b0), DICO(0x10570d40),
+- DICO(0x15e790a0), DICO(0x20f16380), DICO(0x246f23c0), DICO(0x2e222800),
+- DICO(0x3198bf00), DICO(0x34b84640), DICO(0x38f5b440), DICO(0x4312df80),
+- DICO(0x4d2d3000), DICO(0x5209ee80), DICO(0x579cf180), DICO(0x5cb37680),
+- DICO(0x042e6560), DICO(0x05eaff30), DICO(0x0a090d30), DICO(0x0d9f2ab0),
+- DICO(0x1a6f0260), DICO(0x209e0c00), DICO(0x25dc95c0), DICO(0x29f89840),
+- DICO(0x2f372840), DICO(0x3a301940), DICO(0x3f0e2e80), DICO(0x44465c80),
+- DICO(0x49207780), DICO(0x4dfdab80), DICO(0x532ec000), DICO(0x5acefd00),
+- DICO(0x04e18ad8), DICO(0x06d5b660), DICO(0x0b2a22d0), DICO(0x0e0e4ef0),
+- DICO(0x198304a0), DICO(0x1e4a25c0), DICO(0x23de37c0), DICO(0x290679c0),
+- DICO(0x2d523b00), DICO(0x337df940), DICO(0x37948100), DICO(0x3de07300),
+- DICO(0x49ee6e80), DICO(0x50576100), DICO(0x55fb1e00), DICO(0x5d080500),
+- DICO(0x05312308), DICO(0x070463f0), DICO(0x0daffba0), DICO(0x12d8c3c0),
+- DICO(0x163ab7a0), DICO(0x20c64c40), DICO(0x24c8fe40), DICO(0x2a6f65c0),
+- DICO(0x3055e100), DICO(0x34420d80), DICO(0x389ded00), DICO(0x3cc57640),
+- DICO(0x4280cd00), DICO(0x4e0a4c00), DICO(0x57675f00), DICO(0x5d87d480),
+- DICO(0x047bd598), DICO(0x06cb1498), DICO(0x0c359930), DICO(0x138165e0),
+- DICO(0x1cae3640), DICO(0x21647640), DICO(0x2836fac0), DICO(0x2cd7b840),
+- DICO(0x30d839c0), DICO(0x360c9440), DICO(0x3ae5ca40), DICO(0x40a93b00),
+- DICO(0x49401e80), DICO(0x4f739c80), DICO(0x54f33c00), DICO(0x5c190200),
+- DICO(0x051c0000), DICO(0x06b45258), DICO(0x0a5eee50), DICO(0x0d46fc30),
+- DICO(0x125bbc60), DICO(0x253d8cc0), DICO(0x2a1fd6c0), DICO(0x2df4cf80),
+- DICO(0x3239e3c0), DICO(0x35a683c0), DICO(0x3b0bb980), DICO(0x409b3d00),
+- DICO(0x46633580), DICO(0x4f2b0600), DICO(0x577cea80), DICO(0x5d86ef00),
+- DICO(0x03d19eec), DICO(0x07cce6d0), DICO(0x143b4b00), DICO(0x1a657880),
+- DICO(0x212e0280), DICO(0x2831fbc0), DICO(0x2f8ba080), DICO(0x35db8040),
+- DICO(0x3bf17f00), DICO(0x413eb100), DICO(0x46154900), DICO(0x4ae18080),
+- DICO(0x4f9ba180), DICO(0x5428ba00), DICO(0x590e9080), DICO(0x5de0d880),
+- DICO(0x08c7e720), DICO(0x0ff14810), DICO(0x1758cc40), DICO(0x1cc744c0),
+- DICO(0x23e45cc0), DICO(0x2b527940), DICO(0x32138580), DICO(0x37b77380),
+- DICO(0x3d7da480), DICO(0x4275a800), DICO(0x473ecf00), DICO(0x4bc7dc80),
+- DICO(0x50512400), DICO(0x54d2c600), DICO(0x598ce680), DICO(0x5e1e0800),
+- DICO(0x09167910), DICO(0x107644a0), DICO(0x171a59e0), DICO(0x1be1ea60),
+- DICO(0x21347680), DICO(0x265a5b00), DICO(0x2be41a40), DICO(0x3116e700),
+- DICO(0x368b0300), DICO(0x3c225e80), DICO(0x41a6e880), DICO(0x47631680),
+- DICO(0x4d47d900), DICO(0x52a28400), DICO(0x583f0e80), DICO(0x5d77bc80),
+- DICO(0x040bdf88), DICO(0x05b062a0), DICO(0x0b4a2f70), DICO(0x1b8cd880),
+- DICO(0x1ec58c40), DICO(0x23661880), DICO(0x2790ba80), DICO(0x2d0d6c40),
+- DICO(0x34f0bc40), DICO(0x3a353f80), DICO(0x3fc3bc40), DICO(0x44998700),
+- DICO(0x49b17080), DICO(0x4f31fa00), DICO(0x55311c80), DICO(0x5b5c8f80),
+- DICO(0x043e2bd0), DICO(0x0645b0f0), DICO(0x0ade5b90), DICO(0x0d653a90),
+- DICO(0x1bc224a0), DICO(0x1f623dc0), DICO(0x27e9a840), DICO(0x2c719bc0),
+- DICO(0x2f2ac040), DICO(0x32688300), DICO(0x36695c00), DICO(0x3b8abe40),
+- DICO(0x47153a80), DICO(0x52491b00), DICO(0x57ba7680), DICO(0x5ce6c300),
+- DICO(0x052940b8), DICO(0x06f28228), DICO(0x0a741c90), DICO(0x0daa3110),
+- DICO(0x113bb2e0), DICO(0x2010b640), DICO(0x2610f380), DICO(0x2a5c7740),
+- DICO(0x2f7703c0), DICO(0x3388d080), DICO(0x3ceabe40), DICO(0x42462a80),
+- DICO(0x47fb0e00), DICO(0x4f7ac480), DICO(0x5706f580), DICO(0x5d92b800),
+- DICO(0x03a134a4), DICO(0x05623470), DICO(0x090a0fe0), DICO(0x12f7d3e0),
+- DICO(0x1d63e440), DICO(0x20e6ac80), DICO(0x247da8c0), DICO(0x27d99600),
+- DICO(0x312e99c0), DICO(0x368fb380), DICO(0x3b3e3ec0), DICO(0x40fead80),
+- DICO(0x4888fa00), DICO(0x4fbd5600), DICO(0x5795a480), DICO(0x5d973000),
+- DICO(0x05697990), DICO(0x06f33800), DICO(0x0b298290), DICO(0x0de47a60),
+- DICO(0x12ef62a0), DICO(0x21e30a00), DICO(0x25f8ff00), DICO(0x2b2287c0),
+- DICO(0x2f11fc00), DICO(0x33138000), DICO(0x37b49f80), DICO(0x41325100),
+- DICO(0x4ab62800), DICO(0x501eae80), DICO(0x56228780), DICO(0x5c5d8300),
+- DICO(0x063830d8), DICO(0x08a76a30), DICO(0x0d376890), DICO(0x117d3a00),
+- DICO(0x1476e5c0), DICO(0x1e215720), DICO(0x24bcd680), DICO(0x29674ac0),
+- DICO(0x2faab340), DICO(0x33843a00), DICO(0x3822e900), DICO(0x3d30b6c0),
+- DICO(0x49cd5480), DICO(0x53187d00), DICO(0x591fe100), DICO(0x5db30f80),
+- DICO(0x05cdc378), DICO(0x075c50c8), DICO(0x0e01f830), DICO(0x12b70480),
+- DICO(0x15e333e0), DICO(0x192c9f40), DICO(0x1d2d6b80), DICO(0x2c09ca40),
+- DICO(0x2eea5cc0), DICO(0x32c89380), DICO(0x376a5b40), DICO(0x42a42600),
+- DICO(0x4c695900), DICO(0x5269e380), DICO(0x586d6c80), DICO(0x5cebdb80),
+- DICO(0x052bbb80), DICO(0x0702e268), DICO(0x0ca196d0), DICO(0x0f48cef0),
+- DICO(0x19d28b60), DICO(0x1ec44a40), DICO(0x24d40f00), DICO(0x29e1eac0),
+- DICO(0x2cafaa80), DICO(0x301bd4c0), DICO(0x357ec200), DICO(0x42254480),
+- DICO(0x4be32000), DICO(0x4f7a4a00), DICO(0x5447fc00), DICO(0x5cca6a00),
+- DICO(0x050fdd18), DICO(0x06c77e10), DICO(0x10561140), DICO(0x1564c340),
+- DICO(0x1867abe0), DICO(0x1f00fba0), DICO(0x22c06240), DICO(0x2aed7680),
+- DICO(0x2ecc24c0), DICO(0x32abb300), DICO(0x36b42340), DICO(0x3ed8f480),
+- DICO(0x4bbdfe80), DICO(0x516bf800), DICO(0x58688b00), DICO(0x5dd44980),
+- DICO(0x058aa130), DICO(0x07d69ba8), DICO(0x0d521f40), DICO(0x0ff37ba0),
+- DICO(0x18125ec0), DICO(0x1f3a4520), DICO(0x23349840), DICO(0x2c759580),
+- DICO(0x2fc21c00), DICO(0x33a42fc0), DICO(0x3dc92900), DICO(0x47befd00),
+- DICO(0x4ccd2480), DICO(0x5197a200), DICO(0x56a2ea00), DICO(0x5bdfa900),
+- DICO(0x05ac8640), DICO(0x076aec88), DICO(0x0e2e3230), DICO(0x114b6f40),
+- DICO(0x155d10a0), DICO(0x19bac600), DICO(0x1fbd75c0), DICO(0x2459c0c0),
+- DICO(0x28229b80), DICO(0x2f586fc0), DICO(0x3d0697c0), DICO(0x42a7a500),
+- DICO(0x49b0bb80), DICO(0x4e642e80), DICO(0x55774280), DICO(0x5d1a7900),
+- DICO(0x05efb470), DICO(0x0831c8a0), DICO(0x0d35ece0), DICO(0x13edc400),
+- DICO(0x16c8fec0), DICO(0x1bb25860), DICO(0x204f3140), DICO(0x277b8a40),
+- DICO(0x2fe9a000), DICO(0x33af7c40), DICO(0x3b7d2900), DICO(0x419c9a80),
+- DICO(0x4591dc80), DICO(0x4bdafd00), DICO(0x55638880), DICO(0x5cef2300),
+- DICO(0x05cf4988), DICO(0x078fa8c0), DICO(0x0c291950), DICO(0x12e05320),
+- DICO(0x155997e0), DICO(0x195df540), DICO(0x1c1b82c0), DICO(0x22c29400),
+- DICO(0x307edec0), DICO(0x34e829c0), DICO(0x3b1b5040), DICO(0x434de400),
+- DICO(0x496b9900), DICO(0x4ff88080), DICO(0x5604c480), DICO(0x5c84b080),
+- DICO(0x03679fa4), DICO(0x050d4a20), DICO(0x09feec10), DICO(0x100a21e0),
+- DICO(0x1483b260), DICO(0x1d76c780), DICO(0x24e75c80), DICO(0x2bd62880),
+- DICO(0x32350a40), DICO(0x38be01c0), DICO(0x3f05a280), DICO(0x45295e80),
+- DICO(0x4b554800), DICO(0x51618880), DICO(0x575a1500), DICO(0x5d109d80),
+- DICO(0x034ffd08), DICO(0x04dccea8), DICO(0x07e289b8), DICO(0x0d6950d0),
+- DICO(0x189acec0), DICO(0x1e3bf240), DICO(0x2535aa40), DICO(0x2b88d140),
+- DICO(0x329bbb00), DICO(0x386c3500), DICO(0x3e950800), DICO(0x44c43f00),
+- DICO(0x4b089780), DICO(0x51223280), DICO(0x574c9780), DICO(0x5d366400),
+- DICO(0x036d8db8), DICO(0x04fd88b8), DICO(0x09700a70), DICO(0x116b73c0),
+- DICO(0x17258c40), DICO(0x1fd03000), DICO(0x23fdf400), DICO(0x28e08dc0),
+- DICO(0x32d688c0), DICO(0x37920b00), DICO(0x3daaa080), DICO(0x46a16c00),
+- DICO(0x4f8c3100), DICO(0x54a13700), DICO(0x59d24b80), DICO(0x5cea4d80),
+- DICO(0x05797c88), DICO(0x080dc8f0), DICO(0x0bd21520), DICO(0x1095b540),
+- DICO(0x138fd400), DICO(0x1aed19c0), DICO(0x29fead00), DICO(0x2f70cec0),
+- DICO(0x3327df00), DICO(0x3a812d00), DICO(0x400a8380), DICO(0x449daa00),
+- DICO(0x4cd6b600), DICO(0x51f12400), DICO(0x56bdfd80), DICO(0x5be0a100),
+- DICO(0x04de6d78), DICO(0x072aed40), DICO(0x0c6fc460), DICO(0x0f260220),
+- DICO(0x179d00c0), DICO(0x1e8244e0), DICO(0x23867240), DICO(0x2baf7680),
+- DICO(0x2fa6d240), DICO(0x37e83d40), DICO(0x3d1cbfc0), DICO(0x439d0a00),
+- DICO(0x49fd3e00), DICO(0x50095e80), DICO(0x559f2080), DICO(0x5b889a00),
+- DICO(0x042f5c10), DICO(0x061ab3e8), DICO(0x0dd8f160), DICO(0x126e0b40),
+- DICO(0x16ea9040), DICO(0x20a31700), DICO(0x24608140), DICO(0x2ec65080),
+- DICO(0x334e1a40), DICO(0x38252100), DICO(0x3fff0900), DICO(0x46519a80),
+- DICO(0x4c5e0d80), DICO(0x518c5800), DICO(0x56c5b080), DICO(0x5c6ebb80),
+- DICO(0x045ce230), DICO(0x067547b0), DICO(0x0a21c670), DICO(0x1408b820),
+- DICO(0x1c0505c0), DICO(0x1e806c80), DICO(0x26d3c640), DICO(0x2ca573c0),
+- DICO(0x3014d880), DICO(0x377108c0), DICO(0x3f35cf80), DICO(0x43566100),
+- DICO(0x4a612900), DICO(0x5160c780), DICO(0x57d3e300), DICO(0x5d414b80),
+- DICO(0x04c8eda8), DICO(0x06a32320), DICO(0x09ab2590), DICO(0x14230760),
+- DICO(0x20fb23c0), DICO(0x24aa2880), DICO(0x285a2580), DICO(0x2c464ac0),
+- DICO(0x30098280), DICO(0x36232780), DICO(0x3e428d40), DICO(0x42982280),
+- DICO(0x47e60d80), DICO(0x4e1ecc00), DICO(0x55eb9200), DICO(0x5c81ed00),
+- DICO(0x040d0b90), DICO(0x0586c5c0), DICO(0x0bea2190), DICO(0x1dc8dd60),
+- DICO(0x20a07c40), DICO(0x2437e580), DICO(0x27ca5fc0), DICO(0x2d017980),
+- DICO(0x34100040), DICO(0x38d3afc0), DICO(0x3da9b700), DICO(0x42082480),
+- DICO(0x46586f00), DICO(0x4e3c3d80), DICO(0x55e1ee00), DICO(0x5c938d00),
+- DICO(0x03d18c64), DICO(0x05941d60), DICO(0x116b2560), DICO(0x19cc8820),
+- DICO(0x1ce930c0), DICO(0x22626080), DICO(0x26d2cf80), DICO(0x2ce2c980),
+- DICO(0x305361c0), DICO(0x34b65900), DICO(0x39ee5b40), DICO(0x41508400),
+- DICO(0x47ee1e80), DICO(0x50311180), DICO(0x56cb0c00), DICO(0x5d561680),
+- DICO(0x0af22cf0), DICO(0x154e1c60), DICO(0x1b44ff60), DICO(0x2087d0c0),
+- DICO(0x252f7380), DICO(0x28fe66c0), DICO(0x2d0e9800), DICO(0x30f7ee00),
+- DICO(0x3606d640), DICO(0x3bac0a40), DICO(0x417c3700), DICO(0x470c2900),
+- DICO(0x4cc20d00), DICO(0x51e55e80), DICO(0x576bc200), DICO(0x5caa7080),
+- DICO(0x043314e0), DICO(0x05cb47b0), DICO(0x0985df20), DICO(0x185a22c0),
+- DICO(0x1ea68300), DICO(0x21af9100), DICO(0x25cdcb40), DICO(0x297e0a80),
+- DICO(0x3142ac80), DICO(0x358bb040), DICO(0x3a1345c0), DICO(0x402ca580),
+- DICO(0x4d964780), DICO(0x5420cf80), DICO(0x592adf80), DICO(0x5dfe7a80),
+- DICO(0x04c70e20), DICO(0x062fd6f0), DICO(0x113c60a0), DICO(0x159e9900),
+- DICO(0x1933e5a0), DICO(0x1decffa0), DICO(0x22373400), DICO(0x27ed7180),
+- DICO(0x2a8349c0), DICO(0x2f78f940), DICO(0x3d5c8540), DICO(0x429c3500),
+- DICO(0x4936e300), DICO(0x4de08d00), DICO(0x52627700), DICO(0x5d822680),
+- DICO(0x04982770), DICO(0x06ab1ad8), DICO(0x0cba1090), DICO(0x10839d60),
+- DICO(0x1acd6a60), DICO(0x1f554560), DICO(0x2431c1c0), DICO(0x295db800),
+- DICO(0x2d374c00), DICO(0x31f2fd80), DICO(0x3a200480), DICO(0x416bea80),
+- DICO(0x4ba1ce00), DICO(0x52a88000), DICO(0x58d0db00), DICO(0x5d3e5800),
+- DICO(0x059e0e70), DICO(0x08166ba0), DICO(0x0c9df590), DICO(0x11de5f40),
+- DICO(0x14c08ea0), DICO(0x1c5ad6e0), DICO(0x24178ec0), DICO(0x28eb7640),
+- DICO(0x31626280), DICO(0x35d43100), DICO(0x3cad10c0), DICO(0x422e1480),
+- DICO(0x49baee00), DICO(0x53dd7180), DICO(0x5a17bb80), DICO(0x5e4bb180),
+- DICO(0x03c64d00), DICO(0x05de0b28), DICO(0x0ccb82b0), DICO(0x144b1c00),
+- DICO(0x19e39ec0), DICO(0x21e795c0), DICO(0x28149380), DICO(0x2f1ff7c0),
+- DICO(0x35b7c900), DICO(0x3c5f4800), DICO(0x42799c00), DICO(0x48746180),
+- DICO(0x4e8f4d00), DICO(0x53b98380), DICO(0x58d60000), DICO(0x5d71a000),
+- DICO(0x050a2990), DICO(0x071bdb88), DICO(0x0f0d76b0), DICO(0x17a78de0),
+- DICO(0x1aa20720), DICO(0x22eea3c0), DICO(0x276e9640), DICO(0x2ecc4d80),
+- DICO(0x335f7900), DICO(0x37838640), DICO(0x3c81be80), DICO(0x41a4e400),
+- DICO(0x476fa280), DICO(0x4f2ab780), DICO(0x56e87b80), DICO(0x5cbf2900),
+- DICO(0x06724c98), DICO(0x099f5e20), DICO(0x119bcec0), DICO(0x16be11a0),
+- DICO(0x19d53b00), DICO(0x1eb51360), DICO(0x2302c300), DICO(0x29c20d40),
+- DICO(0x30dd5200), DICO(0x36576a80), DICO(0x3e3e7540), DICO(0x45aa9f80),
+- DICO(0x4c833300), DICO(0x51d7ed00), DICO(0x57a4a380), DICO(0x5cce9100),
+- DICO(0x05588b60), DICO(0x075a70a0), DICO(0x0ef96e30), DICO(0x12ac1100),
+- DICO(0x1649dde0), DICO(0x1a50cdc0), DICO(0x22486140), DICO(0x27c7c800),
+- DICO(0x2e08bd80), DICO(0x355d20c0), DICO(0x3925a9c0), DICO(0x44e2b480),
+- DICO(0x4fa4e680), DICO(0x5470e180), DICO(0x595fee80), DICO(0x5d672f00),
+- DICO(0x04a781c0), DICO(0x060a89f0), DICO(0x111f56a0), DICO(0x16b93be0),
+- DICO(0x19ce9120), DICO(0x1e1fda60), DICO(0x2259f880), DICO(0x285cad80),
+- DICO(0x2b140ec0), DICO(0x2f069940), DICO(0x33bbce40), DICO(0x3dd3e6c0),
+- DICO(0x49154880), DICO(0x5008e380), DICO(0x568c4680), DICO(0x5da43780),
+- DICO(0x053ade38), DICO(0x0708a200), DICO(0x0bad43d0), DICO(0x1860cf40),
+- DICO(0x1c40dbe0), DICO(0x1f5a0120), DICO(0x25bcf7c0), DICO(0x29e0c840),
+- DICO(0x2f223840), DICO(0x390c8940), DICO(0x3e1d7340), DICO(0x41c6a000),
+- DICO(0x46cc2880), DICO(0x5006e280), DICO(0x5744e180), DICO(0x5d297780),
+- DICO(0x0401a3f0), DICO(0x07be4a08), DICO(0x14f5f1a0), DICO(0x1c348080),
+- DICO(0x226753c0), DICO(0x274b1b80), DICO(0x2c11a300), DICO(0x30798c00),
+- DICO(0x35598c80), DICO(0x3aab18c0), DICO(0x4030f380), DICO(0x45c7b400),
+- DICO(0x4be5be00), DICO(0x5180db80), DICO(0x57613b00), DICO(0x5cffff80),
+- DICO(0x084b3090), DICO(0x0fe5b3b0), DICO(0x16dfd480), DICO(0x1d0aa700),
+- DICO(0x24e08180), DICO(0x2b498640), DICO(0x30885b80), DICO(0x34ccc480),
+- DICO(0x38fedec0), DICO(0x3cdf9c40), DICO(0x41737600), DICO(0x46ab9800),
+- DICO(0x4c772e80), DICO(0x51e5b980), DICO(0x57df9900), DICO(0x5d5d7180),
+- DICO(0x09549f00), DICO(0x12b84da0), DICO(0x1aeaf1c0), DICO(0x2142a9c0),
+- DICO(0x275c9a00), DICO(0x2c260c80), DICO(0x3038c700), DICO(0x34081d00),
+- DICO(0x38612f40), DICO(0x3d0bf8c0), DICO(0x42473e00), DICO(0x47ecad80),
+- DICO(0x4db34380), DICO(0x52f0ab00), DICO(0x584cc980), DICO(0x5d62ae80),
+- DICO(0x0aeca1e0), DICO(0x14354700), DICO(0x19955ba0), DICO(0x1de331e0),
+- DICO(0x21cd60c0), DICO(0x25e72d80), DICO(0x2a402880), DICO(0x2efa64c0),
+- DICO(0x3478d9c0), DICO(0x3a889e80), DICO(0x40744e00), DICO(0x4626fe80),
+- DICO(0x4bd80900), DICO(0x51120f00), DICO(0x56d8d280), DICO(0x5c654400),
+- DICO(0x07a40af8), DICO(0x0e65ec20), DICO(0x14c76780), DICO(0x19b35a60),
+- DICO(0x1f76b7c0), DICO(0x24f512c0), DICO(0x2ae89f00), DICO(0x3036c3c0),
+- DICO(0x36041800), DICO(0x3bc4df80), DICO(0x41adb080), DICO(0x477fbb80),
+- DICO(0x4d5aa480), DICO(0x52cb0600), DICO(0x586f7280), DICO(0x5db40180),
+- DICO(0x03997610), DICO(0x06175db0), DICO(0x0ea8c9c0), DICO(0x14397000),
+- DICO(0x1ba34f60), DICO(0x22346680), DICO(0x28958080), DICO(0x2ea76840),
+- DICO(0x33ee68c0), DICO(0x39e769c0), DICO(0x3f862500), DICO(0x4579b080),
+- DICO(0x4b49cd00), DICO(0x5107da80), DICO(0x573cde00), DICO(0x5d090780),
+- DICO(0x046fc2f8), DICO(0x0640dbc0), DICO(0x09da7ab0), DICO(0x174e4220),
+- DICO(0x23dc8cc0), DICO(0x27016200), DICO(0x2a9a5240), DICO(0x2e6cc7c0),
+- DICO(0x321ced40), DICO(0x38ca2d00), DICO(0x41482680), DICO(0x451e3700),
+- DICO(0x4b90d800), DICO(0x50d0ba80), DICO(0x55602e80), DICO(0x5a465200),
+- DICO(0x03ca7e28), DICO(0x057c9dd0), DICO(0x0c9ff0e0), DICO(0x1957fae0),
+- DICO(0x1fef7860), DICO(0x27920c80), DICO(0x2cb233c0), DICO(0x32015c80),
+- DICO(0x36af4f40), DICO(0x3ac18240), DICO(0x3f93d8c0), DICO(0x44eaef80),
+- DICO(0x4aab5d80), DICO(0x50840e80), DICO(0x56c4cc80), DICO(0x5cb26600),
+- DICO(0x038d53f8), DICO(0x050d1118), DICO(0x0bc14690), DICO(0x18918000),
+- DICO(0x1e2a6ee0), DICO(0x24cc0c00), DICO(0x2a767d40), DICO(0x2e614940),
+- DICO(0x32859c40), DICO(0x377fd940), DICO(0x3d3a3e40), DICO(0x43e81380),
+- DICO(0x4aaac080), DICO(0x509e7800), DICO(0x57023a00), DICO(0x5d733c00),
+- DICO(0x04cfa5e0), DICO(0x06deeb38), DICO(0x0a501c40), DICO(0x136d8aa0),
+- DICO(0x17f16e40), DICO(0x1c119300), DICO(0x26154b00), DICO(0x2a0da100),
+- DICO(0x2f5935c0), DICO(0x37108d40), DICO(0x3aef07c0), DICO(0x3fccf340),
+- DICO(0x47e4a080), DICO(0x4d8de100), DICO(0x54eb6980), DICO(0x5cdb5380)};
+-
+-/* ACELP: table for decoding
+- adaptive codebook gain g_p (left column). Scaled by 2.0f.
+- innovative codebook gain g_c (right column). Scaled by 16.0f.
+-*/
+-const FIXP_SGL fdk_t_qua_gain7b[128 * 2] = {
+- 204, 441, 464, 1977, 869, 1077, 1072, 3062, 1281, 4759, 1647,
+- 1539, 1845, 7020, 1853, 634, 1995, 2336, 2351, 15400, 2661, 1165,
+- 2702, 3900, 2710, 10133, 3195, 1752, 3498, 2624, 3663, 849, 3984,
+- 5697, 4214, 3399, 4415, 1304, 4695, 2056, 5376, 4558, 5386, 676,
+- 5518, 23554, 5567, 7794, 5644, 3061, 5672, 1513, 5957, 2338, 6533,
+- 1060, 6804, 5998, 6820, 1767, 6937, 3837, 7277, 414, 7305, 2665,
+- 7466, 11304, 7942, 794, 8007, 1982, 8007, 1366, 8326, 3105, 8336,
+- 4810, 8708, 7954, 8989, 2279, 9031, 1055, 9247, 3568, 9283, 1631,
+- 9654, 6311, 9811, 2605, 10120, 683, 10143, 4179, 10245, 1946, 10335,
+- 1218, 10468, 9960, 10651, 3000, 10951, 1530, 10969, 5290, 11203, 2305,
+- 11325, 3562, 11771, 6754, 11839, 1849, 11941, 4495, 11954, 1298, 11975,
+- 15223, 11977, 883, 11986, 2842, 12438, 2141, 12593, 3665, 12636, 8367,
+- 12658, 1594, 12886, 2628, 12984, 4942, 13146, 1115, 13224, 524, 13341,
+- 3163, 13399, 1923, 13549, 5961, 13606, 1401, 13655, 2399, 13782, 3909,
+- 13868, 10923, 14226, 1723, 14232, 2939, 14278, 7528, 14439, 4598, 14451,
+- 984, 14458, 2265, 14792, 1403, 14818, 3445, 14899, 5709, 15017, 15362,
+- 15048, 1946, 15069, 2655, 15405, 9591, 15405, 4079, 15570, 7183, 15687,
+- 2286, 15691, 1624, 15699, 3068, 15772, 5149, 15868, 1205, 15970, 696,
+- 16249, 3584, 16338, 1917, 16424, 2560, 16483, 4438, 16529, 6410, 16620,
+- 11966, 16839, 8780, 17030, 3050, 17033, 18325, 17092, 1568, 17123, 5197,
+- 17351, 2113, 17374, 980, 17566, 26214, 17609, 3912, 17639, 32767, 18151,
+- 7871, 18197, 2516, 18202, 5649, 18679, 3283, 18930, 1370, 19271, 13757,
+- 19317, 4120, 19460, 1973, 19654, 10018, 19764, 6792, 19912, 5135, 20040,
+- 2841, 21234, 19833};
+-
+-/* ACELP: factor table for interpolation of LPC coeffs in LSP domain */
+-const FIXP_SGL lsp_interpol_factor[2][NB_SUBFR] = {
+- {FL2FXCONST_SGL(0.125f), FL2FXCONST_SGL(0.375f), FL2FXCONST_SGL(0.625f),
+- FL2FXCONST_SGL(0.875f)}, /* for coreCoderFrameLength = 1024 */
+- {FL2FXCONST_SGL(0.166667f), FL2FXCONST_SGL(0.5f), FL2FXCONST_SGL(0.833333f),
+- 0x0} /* for coreCoderFrameLength = 768 */
+-};
+-
+-/* For bass post filter */
+-#ifndef TABLE_filt_lp
+-const FIXP_SGL fdk_dec_filt_lp[1 + L_FILT] = {
+- FL2FXCONST_SGL_FILT(0.088250f), FL2FXCONST_SGL_FILT(0.086410f),
+- FL2FXCONST_SGL_FILT(0.081074f), FL2FXCONST_SGL_FILT(0.072768f),
+- FL2FXCONST_SGL_FILT(0.062294f), FL2FXCONST_SGL_FILT(0.050623f),
+- FL2FXCONST_SGL_FILT(0.038774f), FL2FXCONST_SGL_FILT(0.027692f),
+- FL2FXCONST_SGL_FILT(0.018130f), FL2FXCONST_SGL_FILT(0.010578f),
+- FL2FXCONST_SGL_FILT(0.005221f), FL2FXCONST_SGL_FILT(0.001946f),
+- FL2FXCONST_SGL_FILT(0.000385f)};
+-#endif
+-
+-/* FAC window tables for coreCoderFrameLength = 1024 */
+-const FIXP_WTB FacWindowSynth128[] = {
+- WTC(0x7fff6216), WTC(0x7ffa72d1), WTC(0x7ff09478), WTC(0x7fe1c76b),
+- WTC(0x7fce0c3e), WTC(0x7fb563b3), WTC(0x7f97cebd), WTC(0x7f754e80),
+- WTC(0x7f4de451), WTC(0x7f2191b4), WTC(0x7ef05860), WTC(0x7eba3a39),
+- WTC(0x7e7f3957), WTC(0x7e3f57ff), WTC(0x7dfa98a8), WTC(0x7db0fdf8),
+- WTC(0x7d628ac6), WTC(0x7d0f4218), WTC(0x7cb72724), WTC(0x7c5a3d50),
+- WTC(0x7bf88830), WTC(0x7b920b89), WTC(0x7b26cb4f), WTC(0x7ab6cba4),
+- WTC(0x7a4210d8), WTC(0x79c89f6e), WTC(0x794a7c12), WTC(0x78c7aba2),
+- WTC(0x78403329), WTC(0x77b417df), WTC(0x77235f2d), WTC(0x768e0ea6),
+- WTC(0x75f42c0b), WTC(0x7555bd4c), WTC(0x74b2c884), WTC(0x740b53fb),
+- WTC(0x735f6626), WTC(0x72af05a7), WTC(0x71fa3949), WTC(0x71410805),
+- WTC(0x708378ff), WTC(0x6fc19385), WTC(0x6efb5f12), WTC(0x6e30e34a),
+- WTC(0x6d6227fa), WTC(0x6c8f351c), WTC(0x6bb812d1), WTC(0x6adcc964),
+- WTC(0x69fd614a), WTC(0x6919e320), WTC(0x683257ab), WTC(0x6746c7d8),
+- WTC(0x66573cbb), WTC(0x6563bf92), WTC(0x646c59bf), WTC(0x637114cc),
+- WTC(0x6271fa69), WTC(0x616f146c), WTC(0x60686ccf), WTC(0x5f5e0db3),
+- WTC(0x5e50015d), WTC(0x5d3e5237), WTC(0x5c290acc), WTC(0x5b1035cf),
+- WTC(0x59f3de12), WTC(0x58d40e8c), WTC(0x57b0d256), WTC(0x568a34a9),
+- WTC(0x556040e2), WTC(0x5433027d), WTC(0x53028518), WTC(0x51ced46e),
+- WTC(0x5097fc5e), WTC(0x4f5e08e3), WTC(0x4e210617), WTC(0x4ce10034),
+- WTC(0x4b9e0390), WTC(0x4a581c9e), WTC(0x490f57ee), WTC(0x47c3c22f),
+- WTC(0x46756828), WTC(0x452456bd), WTC(0x43d09aed), WTC(0x427a41d0),
+- WTC(0x4121589b), WTC(0x3fc5ec98), WTC(0x3e680b2c), WTC(0x3d07c1d6),
+- WTC(0x3ba51e29), WTC(0x3a402dd2), WTC(0x38d8fe93), WTC(0x376f9e46),
+- WTC(0x36041ad9), WTC(0x34968250), WTC(0x3326e2c3), WTC(0x31b54a5e),
+- WTC(0x3041c761), WTC(0x2ecc681e), WTC(0x2d553afc), WTC(0x2bdc4e6f),
+- WTC(0x2a61b101), WTC(0x28e5714b), WTC(0x27679df4), WTC(0x25e845b6),
+- WTC(0x24677758), WTC(0x22e541af), WTC(0x2161b3a0), WTC(0x1fdcdc1b),
+- WTC(0x1e56ca1e), WTC(0x1ccf8cb3), WTC(0x1b4732ef), WTC(0x19bdcbf3),
+- WTC(0x183366e9), WTC(0x16a81305), WTC(0x151bdf86), WTC(0x138edbb1),
+- WTC(0x120116d5), WTC(0x1072a048), WTC(0x0ee38766), WTC(0x0d53db92),
+- WTC(0x0bc3ac35), WTC(0x0a3308bd), WTC(0x08a2009a), WTC(0x0710a345),
+- WTC(0x057f0035), WTC(0x03ed26e6), WTC(0x025b26d7), WTC(0x00c90f88),
+-};
+-const FIXP_WTB FacWindowZir128[] = {
+- WTC(0x7f36f078), WTC(0x7da4d929), WTC(0x7c12d91a), WTC(0x7a80ffcb),
+- WTC(0x78ef5cbb), WTC(0x775dff66), WTC(0x75ccf743), WTC(0x743c53cb),
+- WTC(0x72ac246e), WTC(0x711c789a), WTC(0x6f8d5fb8), WTC(0x6dfee92b),
+- WTC(0x6c71244f), WTC(0x6ae4207a), WTC(0x6957ecfb), WTC(0x67cc9917),
+- WTC(0x6642340d), WTC(0x64b8cd11), WTC(0x6330734d), WTC(0x61a935e2),
+- WTC(0x602323e5), WTC(0x5e9e4c60), WTC(0x5d1abe51), WTC(0x5b9888a8),
+- WTC(0x5a17ba4a), WTC(0x5898620c), WTC(0x571a8eb5), WTC(0x559e4eff),
+- WTC(0x5423b191), WTC(0x52aac504), WTC(0x513397e2), WTC(0x4fbe389f),
+- WTC(0x4e4ab5a2), WTC(0x4cd91d3d), WTC(0x4b697db0), WTC(0x49fbe527),
+- WTC(0x489061ba), WTC(0x4727016d), WTC(0x45bfd22e), WTC(0x445ae1d7),
+- WTC(0x42f83e2a), WTC(0x4197f4d4), WTC(0x403a1368), WTC(0x3edea765),
+- WTC(0x3d85be30), WTC(0x3c2f6513), WTC(0x3adba943), WTC(0x398a97d8),
+- WTC(0x383c3dd1), WTC(0x36f0a812), WTC(0x35a7e362), WTC(0x3461fc70),
+- WTC(0x331effcc), WTC(0x31def9e9), WTC(0x30a1f71d), WTC(0x2f6803a2),
+- WTC(0x2e312b92), WTC(0x2cfd7ae8), WTC(0x2bccfd83), WTC(0x2a9fbf1e),
+- WTC(0x2975cb57), WTC(0x284f2daa), WTC(0x272bf174), WTC(0x260c21ee),
+- WTC(0x24efca31), WTC(0x23d6f534), WTC(0x22c1adc9), WTC(0x21affea3),
+- WTC(0x20a1f24d), WTC(0x1f979331), WTC(0x1e90eb94), WTC(0x1d8e0597),
+- WTC(0x1c8eeb34), WTC(0x1b93a641), WTC(0x1a9c406e), WTC(0x19a8c345),
+- WTC(0x18b93828), WTC(0x17cda855), WTC(0x16e61ce0), WTC(0x16029eb6),
+- WTC(0x1523369c), WTC(0x1447ed2f), WTC(0x1370cae4), WTC(0x129dd806),
+- WTC(0x11cf1cb6), WTC(0x1104a0ee), WTC(0x103e6c7b), WTC(0x0f7c8701),
+- WTC(0x0ebef7fb), WTC(0x0e05c6b7), WTC(0x0d50fa59), WTC(0x0ca099da),
+- WTC(0x0bf4ac05), WTC(0x0b4d377c), WTC(0x0aaa42b4), WTC(0x0a0bd3f5),
+- WTC(0x0971f15a), WTC(0x08dca0d3), WTC(0x084be821), WTC(0x07bfccd7),
+- WTC(0x0738545e), WTC(0x06b583ee), WTC(0x06376092), WTC(0x05bdef28),
+- WTC(0x0549345c), WTC(0x04d934b1), WTC(0x046df477), WTC(0x040777d0),
+- WTC(0x03a5c2b0), WTC(0x0348d8dc), WTC(0x02f0bde8), WTC(0x029d753a),
+- WTC(0x024f0208), WTC(0x02056758), WTC(0x01c0a801), WTC(0x0180c6a9),
+- WTC(0x0145c5c7), WTC(0x010fa7a0), WTC(0x00de6e4c), WTC(0x00b21baf),
+- WTC(0x008ab180), WTC(0x00683143), WTC(0x004a9c4d), WTC(0x0031f3c2),
+- WTC(0x001e3895), WTC(0x000f6b88), WTC(0x00058d2f), WTC(0x00009dea),
+-};
+-const FIXP_WTB FacWindowSynth64[] = {
+- WTC(0x7ffd885a), WTC(0x7fe9cbc0), WTC(0x7fc25596), WTC(0x7f872bf3),
+- WTC(0x7f3857f6), WTC(0x7ed5e5c6), WTC(0x7e5fe493), WTC(0x7dd6668f),
+- WTC(0x7d3980ec), WTC(0x7c894bde), WTC(0x7bc5e290), WTC(0x7aef6323),
+- WTC(0x7a05eead), WTC(0x7909a92d), WTC(0x77fab989), WTC(0x76d94989),
+- WTC(0x75a585cf), WTC(0x745f9dd1), WTC(0x7307c3d0), WTC(0x719e2cd2),
+- WTC(0x7023109a), WTC(0x6e96a99d), WTC(0x6cf934fc), WTC(0x6b4af279),
+- WTC(0x698c246c), WTC(0x67bd0fbd), WTC(0x65ddfbd3), WTC(0x63ef3290),
+- WTC(0x61f1003f), WTC(0x5fe3b38d), WTC(0x5dc79d7c), WTC(0x5b9d1154),
+- WTC(0x59646498), WTC(0x571deefa), WTC(0x54ca0a4b), WTC(0x5269126e),
+- WTC(0x4ffb654d), WTC(0x4d8162c4), WTC(0x4afb6c98), WTC(0x4869e665),
+- WTC(0x45cd358f), WTC(0x4325c135), WTC(0x4073f21d), WTC(0x3db832a6),
+- WTC(0x3af2eeb7), WTC(0x382493b0), WTC(0x354d9057), WTC(0x326e54c7),
+- WTC(0x2f875262), WTC(0x2c98fbba), WTC(0x29a3c485), WTC(0x26a82186),
+- WTC(0x23a6887f), WTC(0x209f701c), WTC(0x1d934fe5), WTC(0x1a82a026),
+- WTC(0x176dd9de), WTC(0x145576b1), WTC(0x1139f0cf), WTC(0x0e1bc2e4),
+- WTC(0x0afb6805), WTC(0x07d95b9e), WTC(0x04b6195d), WTC(0x01921d20),
+-};
+-const FIXP_WTB FacWindowZir64[] = {
+- WTC(0x7e6de2e0), WTC(0x7b49e6a3), WTC(0x7826a462), WTC(0x750497fb),
+- WTC(0x71e43d1c), WTC(0x6ec60f31), WTC(0x6baa894f), WTC(0x68922622),
+- WTC(0x657d5fda), WTC(0x626cb01b), WTC(0x5f608fe4), WTC(0x5c597781),
+- WTC(0x5957de7a), WTC(0x565c3b7b), WTC(0x53670446), WTC(0x5078ad9e),
+- WTC(0x4d91ab39), WTC(0x4ab26fa9), WTC(0x47db6c50), WTC(0x450d1149),
+- WTC(0x4247cd5a), WTC(0x3f8c0de3), WTC(0x3cda3ecb), WTC(0x3a32ca71),
+- WTC(0x3796199b), WTC(0x35049368), WTC(0x327e9d3c), WTC(0x30049ab3),
+- WTC(0x2d96ed92), WTC(0x2b35f5b5), WTC(0x28e21106), WTC(0x269b9b68),
+- WTC(0x2462eeac), WTC(0x22386284), WTC(0x201c4c73), WTC(0x1e0effc1),
+- WTC(0x1c10cd70), WTC(0x1a22042d), WTC(0x1842f043), WTC(0x1673db94),
+- WTC(0x14b50d87), WTC(0x1306cb04), WTC(0x11695663), WTC(0x0fdcef66),
+- WTC(0x0e61d32e), WTC(0x0cf83c30), WTC(0x0ba0622f), WTC(0x0a5a7a31),
+- WTC(0x0926b677), WTC(0x08054677), WTC(0x06f656d3), WTC(0x05fa1153),
+- WTC(0x05109cdd), WTC(0x043a1d70), WTC(0x0376b422), WTC(0x02c67f14),
+- WTC(0x02299971), WTC(0x01a01b6d), WTC(0x012a1a3a), WTC(0x00c7a80a),
+- WTC(0x0078d40d), WTC(0x003daa6a), WTC(0x00163440), WTC(0x000277a6),
+-};
+-const FIXP_WTB FacWindowSynth32[] = {
+- WTC(0x7ff62182), WTC(0x7fa736b4), WTC(0x7f0991c4), WTC(0x7e1d93ea),
+- WTC(0x7ce3ceb2), WTC(0x7b5d039e), WTC(0x798a23b1), WTC(0x776c4edb),
+- WTC(0x7504d345), WTC(0x72552c85), WTC(0x6f5f02b2), WTC(0x6c242960),
+- WTC(0x68a69e81), WTC(0x64e88926), WTC(0x60ec3830), WTC(0x5cb420e0),
+- WTC(0x5842dd54), WTC(0x539b2af0), WTC(0x4ebfe8a5), WTC(0x49b41533),
+- WTC(0x447acd50), WTC(0x3f1749b8), WTC(0x398cdd32), WTC(0x33def287),
+- WTC(0x2e110a62), WTC(0x2826b928), WTC(0x2223a4c5), WTC(0x1c0b826a),
+- WTC(0x15e21445), WTC(0x0fab272b), WTC(0x096a9049), WTC(0x03242abf),
+-};
+-const FIXP_WTB FacWindowZir32[] = {
+- WTC(0x7cdbd541), WTC(0x76956fb7), WTC(0x7054d8d5), WTC(0x6a1debbb),
+- WTC(0x63f47d96), WTC(0x5ddc5b3b), WTC(0x57d946d8), WTC(0x51eef59e),
+- WTC(0x4c210d79), WTC(0x467322ce), WTC(0x40e8b648), WTC(0x3b8532b0),
+- WTC(0x364beacd), WTC(0x3140175b), WTC(0x2c64d510), WTC(0x27bd22ac),
+- WTC(0x234bdf20), WTC(0x1f13c7d0), WTC(0x1b1776da), WTC(0x1759617f),
+- WTC(0x13dbd6a0), WTC(0x10a0fd4e), WTC(0x0daad37b), WTC(0x0afb2cbb),
+- WTC(0x0893b125), WTC(0x0675dc4f), WTC(0x04a2fc62), WTC(0x031c314e),
+- WTC(0x01e26c16), WTC(0x00f66e3c), WTC(0x0058c94c), WTC(0x0009de7e),
+-};
+-
+-/* FAC window tables for coreCoderFrameLength = 768 */
+-const FIXP_WTB FacWindowSynth96[] = {
+- WTC(0x7ffee744), WTC(0x7ff62182), WTC(0x7fe49698), WTC(0x7fca47b9),
+- WTC(0x7fa736b4), WTC(0x7f7b65ef), WTC(0x7f46d86c), WTC(0x7f0991c4),
+- WTC(0x7ec3962a), WTC(0x7e74ea6a), WTC(0x7e1d93ea), WTC(0x7dbd98a4),
+- WTC(0x7d54ff2e), WTC(0x7ce3ceb2), WTC(0x7c6a0ef2), WTC(0x7be7c847),
+- WTC(0x7b5d039e), WTC(0x7ac9ca7a), WTC(0x7a2e26f2), WTC(0x798a23b1),
+- WTC(0x78ddcbf5), WTC(0x78292b8d), WTC(0x776c4edb), WTC(0x76a742d1),
+- WTC(0x75da14ef), WTC(0x7504d345), WTC(0x74278c72), WTC(0x73424fa0),
+- WTC(0x72552c85), WTC(0x71603361), WTC(0x706374ff), WTC(0x6f5f02b2),
+- WTC(0x6e52ee52), WTC(0x6d3f4a40), WTC(0x6c242960), WTC(0x6b019f1a),
+- WTC(0x69d7bf57), WTC(0x68a69e81), WTC(0x676e5183), WTC(0x662eedc3),
+- WTC(0x64e88926), WTC(0x639b3a0b), WTC(0x62471749), WTC(0x60ec3830),
+- WTC(0x5f8ab487), WTC(0x5e22a487), WTC(0x5cb420e0), WTC(0x5b3f42ae),
+- WTC(0x59c42381), WTC(0x5842dd54), WTC(0x56bb8a90), WTC(0x552e4605),
+- WTC(0x539b2af0), WTC(0x520254ef), WTC(0x5063e008), WTC(0x4ebfe8a5),
+- WTC(0x4d168b8b), WTC(0x4b67e5e4), WTC(0x49b41533), WTC(0x47fb3757),
+- WTC(0x463d6a87), WTC(0x447acd50), WTC(0x42b37e96), WTC(0x40e79d8c),
+- WTC(0x3f1749b8), WTC(0x3d42a2ec), WTC(0x3b69c947), WTC(0x398cdd32),
+- WTC(0x37abff5d), WTC(0x35c750bc), WTC(0x33def287), WTC(0x31f30638),
+- WTC(0x3003ad85), WTC(0x2e110a62), WTC(0x2c1b3efb), WTC(0x2a226db5),
+- WTC(0x2826b928), WTC(0x26284422), WTC(0x2427319d), WTC(0x2223a4c5),
+- WTC(0x201dc0ef), WTC(0x1e15a99a), WTC(0x1c0b826a), WTC(0x19ff6f2a),
+- WTC(0x17f193c5), WTC(0x15e21445), WTC(0x13d114d0), WTC(0x11beb9aa),
+- WTC(0x0fab272b), WTC(0x0d9681c2), WTC(0x0b80edf1), WTC(0x096a9049),
+- WTC(0x07538d6b), WTC(0x053c0a01), WTC(0x03242abf), WTC(0x010c1460),
+-};
+-const FIXP_WTB FacWindowZir96[] = {
+- WTC(0x7ef3eba0), WTC(0x7cdbd541), WTC(0x7ac3f5ff), WTC(0x78ac7295),
+- WTC(0x76956fb7), WTC(0x747f120f), WTC(0x72697e3e), WTC(0x7054d8d5),
+- WTC(0x6e414656), WTC(0x6c2eeb30), WTC(0x6a1debbb), WTC(0x680e6c3b),
+- WTC(0x660090d6), WTC(0x63f47d96), WTC(0x61ea5666), WTC(0x5fe23f11),
+- WTC(0x5ddc5b3b), WTC(0x5bd8ce63), WTC(0x59d7bbde), WTC(0x57d946d8),
+- WTC(0x55dd924b), WTC(0x53e4c105), WTC(0x51eef59e), WTC(0x4ffc527b),
+- WTC(0x4e0cf9c8), WTC(0x4c210d79), WTC(0x4a38af44), WTC(0x485400a3),
+- WTC(0x467322ce), WTC(0x449636b9), WTC(0x42bd5d14), WTC(0x40e8b648),
+- WTC(0x3f186274), WTC(0x3d4c816a), WTC(0x3b8532b0), WTC(0x39c29579),
+- WTC(0x3804c8a9), WTC(0x364beacd), WTC(0x34981a1c), WTC(0x32e97475),
+- WTC(0x3140175b), WTC(0x2f9c1ff8), WTC(0x2dfdab11), WTC(0x2c64d510),
+- WTC(0x2ad1b9fb), WTC(0x29447570), WTC(0x27bd22ac), WTC(0x263bdc7f),
+- WTC(0x24c0bd52), WTC(0x234bdf20), WTC(0x21dd5b79), WTC(0x20754b79),
+- WTC(0x1f13c7d0), WTC(0x1db8e8b7), WTC(0x1c64c5f5), WTC(0x1b1776da),
+- WTC(0x19d1123d), WTC(0x1891ae7d), WTC(0x1759617f), WTC(0x162840a9),
+- WTC(0x14fe60e6), WTC(0x13dbd6a0), WTC(0x12c0b5c0), WTC(0x11ad11ae),
+- WTC(0x10a0fd4e), WTC(0x0f9c8b01), WTC(0x0e9fcc9f), WTC(0x0daad37b),
+- WTC(0x0cbdb060), WTC(0x0bd8738e), WTC(0x0afb2cbb), WTC(0x0a25eb11),
+- WTC(0x0958bd2f), WTC(0x0893b125), WTC(0x07d6d473), WTC(0x0722340b),
+- WTC(0x0675dc4f), WTC(0x05d1d90e), WTC(0x05363586), WTC(0x04a2fc62),
+- WTC(0x041837b9), WTC(0x0395f10e), WTC(0x031c314e), WTC(0x02ab00d2),
+- WTC(0x0242675c), WTC(0x01e26c16), WTC(0x018b1596), WTC(0x013c69d6),
+- WTC(0x00f66e3c), WTC(0x00b92794), WTC(0x00849a11), WTC(0x0058c94c),
+- WTC(0x0035b847), WTC(0x001b6968), WTC(0x0009de7e), WTC(0x000118bc),
+-};
+-const FIXP_WTB FacWindowSynth48[] = {
+- WTC(0x7ffb9d15), WTC(0x7fd8878e), WTC(0x7f92661d), WTC(0x7f294bfd),
+- WTC(0x7e9d55fc), WTC(0x7deeaa7a), WTC(0x7d1d7958), WTC(0x7c29fbee),
+- WTC(0x7b1474fd), WTC(0x79dd3098), WTC(0x78848414), WTC(0x770acdec),
+- WTC(0x757075ac), WTC(0x73b5ebd1), WTC(0x71dba9ab), WTC(0x6fe2313c),
+- WTC(0x6dca0d14), WTC(0x6b93d02e), WTC(0x694015c3), WTC(0x66cf8120),
+- WTC(0x6442bd7e), WTC(0x619a7dce), WTC(0x5ed77c8a), WTC(0x5bfa7b82),
+- WTC(0x590443a7), WTC(0x55f5a4d2), WTC(0x52cf758f), WTC(0x4f9292dc),
+- WTC(0x4c3fdff4), WTC(0x48d84609), WTC(0x455cb40c), WTC(0x41ce1e65),
+- WTC(0x3e2d7eb1), WTC(0x3a7bd382), WTC(0x36ba2014), WTC(0x32e96c09),
+- WTC(0x2f0ac320), WTC(0x2b1f34eb), WTC(0x2727d486), WTC(0x2325b847),
+- WTC(0x1f19f97b), WTC(0x1b05b40f), WTC(0x16ea0646), WTC(0x12c8106f),
+- WTC(0x0ea0f48c), WTC(0x0a75d60e), WTC(0x0647d97c), WTC(0x02182427),
+-};
+-const FIXP_WTB FacWindowZir48[] = {
+- WTC(0x7de7dbd9), WTC(0x79b82684), WTC(0x758a29f2), WTC(0x715f0b74),
+- WTC(0x6d37ef91), WTC(0x6915f9ba), WTC(0x64fa4bf1), WTC(0x60e60685),
+- WTC(0x5cda47b9), WTC(0x58d82b7a), WTC(0x54e0cb15), WTC(0x50f53ce0),
+- WTC(0x4d1693f7), WTC(0x4945dfec), WTC(0x45842c7e), WTC(0x41d2814f),
+- WTC(0x3e31e19b), WTC(0x3aa34bf4), WTC(0x3727b9f7), WTC(0x33c0200c),
+- WTC(0x306d6d24), WTC(0x2d308a71), WTC(0x2a0a5b2e), WTC(0x26fbbc59),
+- WTC(0x2405847e), WTC(0x21288376), WTC(0x1e658232), WTC(0x1bbd4282),
+- WTC(0x19307ee0), WTC(0x16bfea3d), WTC(0x146c2fd2), WTC(0x1235f2ec),
+- WTC(0x101dcec4), WTC(0x0e245655), WTC(0x0c4a142f), WTC(0x0a8f8a54),
+- WTC(0x08f53214), WTC(0x077b7bec), WTC(0x0622cf68), WTC(0x04eb8b03),
+- WTC(0x03d60412), WTC(0x02e286a8), WTC(0x02115586), WTC(0x0162aa04),
+- WTC(0x00d6b403), WTC(0x006d99e3), WTC(0x00277872), WTC(0x000462eb),
+-};
+diff --git a/libAACdec/src/usacdec_rom.h b/libAACdec/src/usacdec_rom.h
+deleted file mode 100644
+index f969e90..0000000
+--- a/libAACdec/src/usacdec_rom.h
++++ /dev/null
+@@ -1,154 +0,0 @@
+-/* -----------------------------------------------------------------------------
+-Software License for The Fraunhofer FDK AAC Codec Library for Android
+-
+-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+-Forschung e.V. All rights reserved.
+-
+- 1. INTRODUCTION
+-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+-scheme for digital audio. This FDK AAC Codec software is intended to be used on
+-a wide variety of Android devices.
+-
+-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+-general perceptual audio codecs. AAC-ELD is considered the best-performing
+-full-bandwidth communications codec by independent studies and is widely
+-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+-specifications.
+-
+-Patent licenses for necessary patent claims for the FDK AAC Codec (including
+-those of Fraunhofer) may be obtained through Via Licensing
+-(www.vialicensing.com) or through the respective patent owners individually for
+-the purpose of encoding or decoding bit streams in products that are compliant
+-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+-Android devices already license these patent claims through Via Licensing or
+-directly from the patent owners, and therefore FDK AAC Codec software may
+-already be covered under those patent licenses when it is used for those
+-licensed purposes only.
+-
+-Commercially-licensed AAC software libraries, including floating-point versions
+-with enhanced sound quality, are also available from Fraunhofer. Users are
+-encouraged to check the Fraunhofer website for additional applications
+-information and documentation.
+-
+-2. COPYRIGHT LICENSE
+-
+-Redistribution and use in source and binary forms, with or without modification,
+-are permitted without payment of copyright license fees provided that you
+-satisfy the following conditions:
+-
+-You must retain the complete text of this software license in redistributions of
+-the FDK AAC Codec or your modifications thereto in source code form.
+-
+-You must retain the complete text of this software license in the documentation
+-and/or other materials provided with redistributions of the FDK AAC Codec or
+-your modifications thereto in binary form. You must make available free of
+-charge copies of the complete source code of the FDK AAC Codec and your
+-modifications thereto to recipients of copies in binary form.
+-
+-The name of Fraunhofer may not be used to endorse or promote products derived
+-from this library without prior written permission.
+-
+-You may not charge copyright license fees for anyone to use, copy or distribute
+-the FDK AAC Codec software or your modifications thereto.
+-
+-Your modified versions of the FDK AAC Codec must carry prominent notices stating
+-that you changed the software and the date of any change. For modified versions
+-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+-AAC Codec Library for Android."
+-
+-3. NO PATENT LICENSE
+-
+-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+-Fraunhofer provides no warranty of patent non-infringement with respect to this
+-software.
+-
+-You may use this FDK AAC Codec software or modifications thereto only for
+-purposes that are authorized by appropriate patent licenses.
+-
+-4. DISCLAIMER
+-
+-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+-including but not limited to the implied warranties of merchantability and
+-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+-or consequential damages, including but not limited to procurement of substitute
+-goods or services; loss of use, data, or profits, or business interruption,
+-however caused and on any theory of liability, whether in contract, strict
+-liability, or tort (including negligence), arising in any way out of the use of
+-this software, even if advised of the possibility of such damage.
+-
+-5. CONTACT INFORMATION
+-
+-Fraunhofer Institute for Integrated Circuits IIS
+-Attention: Audio and Multimedia Departments - FDK AAC LL
+-Am Wolfsmantel 33
+-91058 Erlangen, Germany
+-
+-www.iis.fraunhofer.de/amm
+-amm-info@iis.fraunhofer.de
+------------------------------------------------------------------------------ */
+-
+-/**************************** AAC decoder library ******************************
+-
+- Author(s): M. Jander
+-
+- Description: re8.h
+-
+-*******************************************************************************/
+-
+-#ifndef USACDEC_ROM_H
+-#define USACDEC_ROM_H
+-
+-#include "common_fix.h"
+-#include "FDK_lpc.h"
+-
+-#include "usacdec_const.h"
+-
+-/* RE8 lattice quantiser constants */
+-#define NB_SPHERE 32
+-#define NB_LEADER 37
+-#define NB_LDSIGN 226
+-#define NB_LDQ3 9
+-#define NB_LDQ4 28
+-
+-#define LSF_SCALE 13
+-
+-/* RE8 lattice quantiser tables */
+-extern const UINT fdk_dec_tab_factorial[8];
+-extern const UCHAR fdk_dec_Ia[NB_LEADER];
+-extern const UCHAR fdk_dec_Ds[NB_LDSIGN];
+-extern const USHORT fdk_dec_Is[NB_LDSIGN];
+-extern const UCHAR fdk_dec_Ns[], fdk_dec_A3[], fdk_dec_A4[];
+-extern const UCHAR fdk_dec_Da[][8];
+-extern const USHORT fdk_dec_I3[], fdk_dec_I4[];
+-
+-/* temp float tables for LPC decoding */
+-extern const FIXP_LPC fdk_dec_lsf_init[16];
+-extern const FIXP_LPC fdk_dec_dico_lsf_abs_8b[16 * 256];
+-
+-/* ACELP tables */
+-#define SF_QUA_GAIN7B 4
+-extern const FIXP_SGL fdk_t_qua_gain7b[128 * 2];
+-extern const FIXP_SGL lsp_interpol_factor[2][NB_SUBFR];
+-
+-/* For bass post filter */
+-#define L_FILT 12 /* Delay of up-sampling filter */
+-
+-extern const FIXP_SGL fdk_dec_filt_lp[1 + L_FILT];
+-
+-extern const FIXP_WTB FacWindowSynth128[128];
+-extern const FIXP_WTB FacWindowZir128[128];
+-extern const FIXP_WTB FacWindowSynth64[64];
+-extern const FIXP_WTB FacWindowZir64[64];
+-extern const FIXP_WTB FacWindowSynth32[32];
+-extern const FIXP_WTB FacWindowZir32[32];
+-extern const FIXP_WTB FacWindowSynth96[96];
+-extern const FIXP_WTB FacWindowZir96[96];
+-extern const FIXP_WTB FacWindowSynth48[48];
+-extern const FIXP_WTB FacWindowZir48[48];
+-
+-#endif /* USACDEC_ROM_H */
+--
+cgit v1.1
+
include $(TOPDIR)/rules.mk
PKG_NAME:=shairport-sync
-PKG_VERSION:=3.2.2
-PKG_RELEASE:=3
+PKG_VERSION:=3.3.5
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/mikebrady/shairport-sync/tar.gz/$(PKG_VERSION)?
-PKG_HASH:=4f1ee142b887842727ae0c310e21c83ea2386518e841a25c7ddb015d08b54eba
+PKG_HASH:=9757dd7f19c0bc28cb06a6753305c3ed89da2d271d069b36d1b12173309c1459
PKG_MAINTAINER:=Ted Hess <thess@kitschensync.net>, \
Mike Brady <mikebrady@eircom.net>
--- a/Makefile.am
+++ b/Makefile.am
-@@ -17,10 +17,6 @@ else
+@@ -23,10 +23,6 @@ else
endif
endif
if USE_CUSTOMPIDDIR
AM_CFLAGS+= \
-DPIDDIR=\"$(CUSTOM_PID_DIR)\"
-@@ -66,11 +62,6 @@ if USE_PA
+@@ -80,11 +76,6 @@ if USE_PA
shairport_sync_SOURCES += audio_pa.c
endif
-if USE_CONVOLUTION
-shairport_sync_SOURCES += FFTConvolver/AudioFFT.cpp FFTConvolver/FFTConvolver.cpp FFTConvolver/Utilities.cpp FFTConvolver/convolver.cpp
--AM_CXXFLAGS = -std=c++11
+-AM_CXXFLAGS += -std=c++11
-endif
-
if USE_DNS_SD
endif
--- a/configure.ac
+++ b/configure.ac
-@@ -18,7 +18,6 @@ with_os=`echo ${with_os} | tr '[[:upper:]]' '[[:lower:]]' `
+@@ -19,7 +19,6 @@ with_os=`echo ${with_os} | tr '[[:upper:]]' '[[:lower:]]' `
# Checks for programs.
AC_PROG_CC
PKG_NAME:=bonnie++
PKG_VERSION:=1.98
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tgz
PKG_SOURCE_URL:=https://www.coker.com.au/bonnie++/
PKG_HASH:=6e0bcbc08b78856fd998dd7bcb352d4615a99c26c2dc83d5b8345b102bad0b04
-PKG_MAINTAINER:=Florian Fainelli <florian@openwrt.org>
+PKG_MAINTAINER:=
PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=copyright.txt
tests of hard drive and file system performance.
endef
-ifeq ($(CONFIG_USE_UCLIBCXX),y)
-TARGET_LDFLAGS += -nodefaultlibs
-endif
-
-TARGET_CXXFLAGS += -ffunction-sections -fdata-sections -fno-rtti -flto -std=c++98
+TARGET_CXXFLAGS += -ffunction-sections -fdata-sections -fno-rtti -flto
define Package/bonniexx/install
$(INSTALL_DIR) $(1)/usr/bin
include $(TOPDIR)/rules.mk
PKG_NAME:=btrfs-progs
-PKG_VERSION:=5.3.1
+PKG_VERSION:=5.4
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-v$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=@KERNEL/linux/kernel/people/kdave/btrfs-progs
-PKG_HASH:=bfa31ae60e54a068fd24e075a90b72f89b8e9006659273fbcecc2e1c790cda38
+PKG_HASH:=0f973295911224ce15a10f9c9a0d9773d13a7f0d04959afb88783009b65670fa
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-v$(PKG_VERSION)
PKG_MAINTAINER:=Karel Kočí <karel.koci@nic.cz>
include $(TOPDIR)/rules.mk
PKG_NAME:=byobu
-PKG_VERSION:=5.129
+PKG_VERSION:=5.130
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).orig.tar.gz
PKG_SOURCE_URL:=https://launchpad.net/byobu/trunk/$(PKG_VERSION)/+download
-PKG_HASH:=e5135f20750c359b6371ee87cf2729c6038fbf3a6e66680e67f6a2125b07c2b9
+PKG_HASH:=47e414161dda124287b9ec1cf94acc716b49e7428c6ec7efeed181f477e17461
PKG_LICENSE:=GPL-3.0
PKG_LICENSE_FILES:=COPYING
include $(TOPDIR)/rules.mk
PKG_NAME:=cache-domains
-PKG_VERSION:=1.0.0
+PKG_VERSION:=2.0.0
PKG_RELEASE:=1
PKG_MAINTAINER:=Gerard Ryan <G.M0N3Y.2503@gmail.com>
endef
define Package/cache-domains/description/default
-Service to dynamically configure the local DNS (dnsmasq) to redirect game content servers to a LAN cache.
+hotplug script to dynamically configure the local DNS (dnsmasq) to redirect game content servers to a LAN cache.
Definitive list dynamically obtained from https://github.com/uklans/cache-domains.
endef
define Package/cache-domains/install/default
- $(INSTALL_DIR) $(1)/etc/init.d
- $(INSTALL_BIN) ./files/cache-domains.init $(1)/etc/init.d/cache-domains
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) ./files/cache-domains $(1)/usr/bin/
+
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/iface/
+ $(INSTALL_BIN) ./files/30-cache-domains $(1)/etc/hotplug.d/iface/
endef
Build/Compile=# Nothing to compile, just install the scripts
# cache-domains
-Service to dynamically configure the local DNS (dnsmasq) to redirect game content servers to a LAN cache. Definitive list dynamically obtained from https://github.com/uklans/cache-domains.
+hotplug script to dynamically configure the local DNS (dnsmasq) to redirect game content servers to a LAN cache. Definitive list dynamically obtained from https://github.com/uklans/cache-domains.
## Configuration
Configuration file follows the same [syntax as the upsteam file](https://github.com/uklans/cache-domains/blob/master/scripts/config.example.json). The key for each `cache_domain` member matches the name of one of the `.txt` files in the [upstream root directory](https://github.com/uklans/cache-domains/blob/master/), except for the `default` key which matches the all the unreferenced `.txt` files. The value of each `cache_domain` member maps to one of the keys of the `ips` members, Thus mapping a cached domain to a list of IP addresses/LAN cache server.
}
```
-## Startup/Shutdown
-On start the local DNS (dnsmasq) will be configured to redirect the configured cache domains and on stop the redirection will be removed.
+## Configure/Cleanup
+`/usr/bin/cache-domains configure` will configure the local DNS (dnsmasq) to redirect the configured cache domains. `/usr/bin/cache-domains cleanup` will cleanup redirection. The hotplug script calls `/usr/bin/cache-domains configure` when the WAN interface is brought up.
## Testing
With the above configuration set and the service running `nslookup swcdn.apple.com` would return `10.10.3.12`
--- /dev/null
+#!/bin/sh
+
+source /lib/functions/network.sh
+network_find_wan WAN_IFACE
+
+if [ "${ACTION}" == "ifup" ] && [ "${INTERFACE}" == "${WAN_IFACE}" ] && [ ! -d /var/cache-domains ]; then
+ /usr/bin/cache-domains configure
+fi
--- /dev/null
+#!/bin/sh
+
+CACHE_DOMAINS_DIR="/var/cache-domains"
+CACHE_DOMAINS_SRC="https://api.github.com/repos/uklans/cache-domains/tarball/master"
+CONFIG_FILE="/etc/cache-domains.json"
+
+configure() {
+ mkdir -p ${CACHE_DOMAINS_DIR}
+ rm -fr ${CACHE_DOMAINS_DIR}/*
+
+ if ! wget -qO - ${CACHE_DOMAINS_SRC} | tar -xzC ${CACHE_DOMAINS_DIR}; then
+ echo "ERROR: Could not retrieve ${CACHE_DOMAINS_SRC}"
+ return 1
+ fi
+
+ INITIAL_DIR="$(pwd)"
+ cd ${CACHE_DOMAINS_DIR}/*/scripts/
+
+ if [ ! -f ${CONFIG_FILE} ]; then
+ cp config.example.json ${CONFIG_FILE}
+ echo "Using example config file ${CONFIG_FILE}"
+ fi
+
+ cp ${CONFIG_FILE} config.json
+ ./create-dnsmasq.sh
+ cp ./output/dnsmasq/* /var/dnsmasq.d/
+
+ cd ${INITIAL_DIR}
+
+ /etc/init.d/dnsmasq restart
+}
+
+cleanup() {
+ # leave dnsmasq in a clean state
+ for FILE in ${CACHE_DOMAINS_DIR}/*/scripts/output/dnsmasq/*; do
+ rm -f /tmp/dnsmasq.d/$(basename ${FILE})
+ done
+
+ /etc/init.d/dnsmasq restart
+}
+
+case ${1} in
+ config*)
+ configure
+ ;;
+ clean*)
+ cleanup
+ ;;
+ *)
+ echo "${0} <configure|cleanup>"
+ ;;
+esac
+++ /dev/null
-#!/bin/sh /etc/rc.common
-
-START=24
-SERVICE_NAME=cache-domains
-CACHE_DOMAINS_DIR="/var/${SERVICE_NAME}"
-CACHE_DOMAINS_SRC="https://api.github.com/repos/uklans/cache-domains/tarball/master"
-CONFIG_FILE="/etc/${SERVICE_NAME}.json"
-
-start() {
- mkdir -p ${CACHE_DOMAINS_DIR}
- rm -fr ${CACHE_DOMAINS_DIR}/*
-
- if ! wget -qO - ${CACHE_DOMAINS_SRC} | tar -xzC ${CACHE_DOMAINS_DIR}; then
- echo "ERROR: Could not retrieve ${CACHE_DOMAINS_SRC}"
- return 1
- fi
-
- INITIAL_DIR="$(pwd)"
- cd ${CACHE_DOMAINS_DIR}/*/scripts/
-
- if [ ! -f ${CONFIG_FILE} ]; then
- cp config.example.json ${CONFIG_FILE}
- echo "Using example config file ${CONFIG_FILE}"
- fi
-
- cp ${CONFIG_FILE} config.json
- ./create-dnsmasq.sh
- cp ./output/dnsmasq/* /tmp/dnsmasq.d/
-
- cd ${INITIAL_DIR}
-
- /etc/init.d/dnsmasq restart
-}
-
-stop() {
- # leave dnsmasq in a clean state
- for FILE in ${CACHE_DOMAINS_DIR}/*/scripts/output/dnsmasq/*; do
- rm -f /tmp/dnsmasq.d/$(basename ${FILE})
- done
-
- /etc/init.d/dnsmasq restart
-}
PKG_NAME:=collectd
PKG_VERSION:=5.10.0
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://collectd.org/files/ \
#config plugin 'uptime'
# option enable '0'
+#config plugin 'vmem'
+# option enable '0'
+# option Verbose '0'
--- /dev/null
+{
+ "bool": [
+ "Verbose"
+ ]
+}
PKG_NAME:=evtest
PKG_VERSION:=1.34
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://cgit.freedesktop.org/evtest/snapshot
--- /dev/null
+From 12d5ea5ca2d9a47a1cab06caf2b36967667a3daf Mon Sep 17 00:00:00 2001
+From: Leo <thinkabit.ukim@gmail.com>
+Date: Sun, 24 Nov 2019 20:58:20 +0100
+Subject: [PATCH] Add missing include of limits.h for PATH_MAX
+
+---
+ evtest.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/evtest.c b/evtest.c
+index 548c203..be5e42c 100644
+--- a/evtest.c
++++ b/evtest.c
+@@ -59,6 +59,7 @@
+ #include <sys/time.h>
+ #include <sys/types.h>
+ #include <unistd.h>
++#include <limits.h> /* PATH_MAX */
+
+ #define BITS_PER_LONG (sizeof(long) * 8)
+ #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+--
+2.22.0
+
PKG_NAME:=fish
PKG_VERSION:=3.0.2
-PKG_RELEASE:=5
+PKG_RELEASE:=6
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/fish-shell/fish-shell/releases/download/$(PKG_VERSION)
grep fish $${IPKG_INSTROOT}/etc/shells || \
echo "/usr/bin/fish" >> $${IPKG_INSTROOT}/etc/shells
- # Backwards compatibility
- if [ -e /bin/fish ] && { [ ! -L /bin/fish ] || [ "$(readlink -fn $${IPKG_INSTROOT}/bin/fish)" != "../$(CONFIGURE_PREFIX)/bin/fish" ]; }; then
- ln -fs "../$(CONFIGURE_PREFIX)/bin/fish" "$${IPKG_INSTROOT}/bin/fish"
- fi
+# Backwards compatibility
+if [ -e /bin/fish ] && { [ ! -L /bin/fish ] || [ "$(readlink -fn $${IPKG_INSTROOT}/bin/fish)" != "../$(CONFIGURE_PREFIX)/bin/fish" ]; }; then
+ ln -fs "../$(CONFIGURE_PREFIX)/bin/fish" "$${IPKG_INSTROOT}/bin/fish"
+fi
endef
define Package/fish/postrm
--- /dev/null
+From c132a2aa53f3a4ca0ab26395a4936ecf3fd030f2 Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Fri, 13 Dec 2019 21:50:06 -0800
+Subject: [PATCH] common.cpp: Don't always include cxxabi.h
+
+cxxabi.h is not available with LLVM's libcxx
+---
+ src/common.cpp | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/src/common.cpp b/src/common.cpp
+index cfa4cb0d81..96873f17a9 100644
+--- a/src/common.cpp
++++ b/src/common.cpp
+@@ -1,8 +1,11 @@
+ // Various functions, mostly string utilities, that are used by most parts of fish.
+ #include "config.h"
+
+-#include <ctype.h>
++#ifdef HAVE_BACKTRACE_SYMBOLS
+ #include <cxxabi.h>
++#endif
++
++#include <ctype.h>
+ #include <dlfcn.h>
+ #include <errno.h>
+ #include <fcntl.h>
PKG_LICENSE:=GPL-3.0-or-later
PKG_LICENSE_FILES:=COPYING
-PKG_MAINTAINER:=Florian Fainelli <florian@openwrt.org>
+PKG_MAINTAINER:=
PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).orig.tar.gz
PKG_SOURCE_URL:=http://archive.ubuntu.com/ubuntu/pool/universe/h/$(PKG_NAME)
include $(TOPDIR)/rules.mk
PKG_NAME:=hplip
-PKG_VERSION:=3.19.6
-PKG_RELEASE:=2
+PKG_VERSION:=3.19.12
+PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/hplip
-PKG_HASH:=fcdaedee9ed17d2e70f3aff9558a452d99443d1b93d6623132faf3f3ae61d66d
+PKG_HASH:=b7f398502fb659e0de8e54976237e3c6a64fec0b3c36054a515876f7b006b255
PKG_MAINTAINER:=Luiz Angelo Daros de Luca <luizluca@gmail.com>
PKG_LICENSE:=GPL-2.0 GPL-2.0-or-later
--- a/configure.in
+++ b/configure.in
-@@ -598,6 +598,10 @@ if test "$class_driver" = "no" && test "$hpijs_only_build" = "no" && test "$hpcu
+@@ -601,6 +601,10 @@ if test "$class_driver" = "no" && test "
else
AC_CHECK_LIB([usb-1.0], [libusb_init], [LIBS="$LIBS"], [AC_MSG_ERROR([cannot find libusb 1.0 support], 2)])
AC_CHECK_HEADERS(libusb-1.0/libusb.h, ,[AC_MSG_ERROR([cannot find libusb-1.0-devel support], 11)])
#include "hpmud.h"
#include "hp_ipp.h"
#include "soap.h"
-@@ -145,98 +144,6 @@ static int GetUriLine(char *buf, char *uri, char **tail)
+@@ -145,98 +144,6 @@ static int GetUriLine(char *buf, char *u
return i;
}
char* token = NULL;
enum HPMUD_RESULT stat;
-@@ -304,34 +210,6 @@ static int DevDiscovery(int localOnly)
+@@ -304,33 +210,6 @@ static int DevDiscovery(int localOnly)
total += AddDevice(uri);
}
-
+ memset(message, 0, sizeof(message));
- /* Look for Network Scan devices if localonly flag if FALSE. */
- if (!localOnly)
-- {
+- {
- /* Look for all-in-one scan devices for which print queue created */
- cnt = GetCupsPrinters(&cups_printer);
- for (i=0; i<cnt; i++)
- SendScanEvent("hpaio:/net/HP_Scan_Devices?ip=1.1.1.1", EVENT_ERROR_NO_PROBED_DEVICES_FOUND);
- }
- }
--
+
bugout:
return total;
- }
--- /dev/null
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=idevicerestore
+PKG_SOURCE_DATE:=2019-12-13
+PKG_SOURCE_VERSION:=a2a6ad16d2c3157153aae7e0835e478237b01507
+PKG_RELEASE:=1
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL=https://github.com/libimobiledevice/idevicerestore
+PKG_MIRROR_HASH:=522bd35a0a4e8cc64ef9b29716e88efd84829e81c9c00ce9170fef285ac4b137
+
+PKG_MAINTAINER:=Rosen Penev <rosenp@gmail.com>
+PKG_LICENSE:=GPL-2.0-or-later
+PKG_LICENSE_FILES:=COPYING
+
+PKG_FIXUP:=autoreconf
+PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/idevicerestore
+ SECTION:=utils
+ CATEGORY:=Utilities
+ SUBMENU:=libimobiledevice
+ TITLE:=Restore/upgrade firmware of iOS devices
+ URL:=https://github.com/libimobiledevice/idevicerestore
+ DEPENDS:=+libirecovery +libzip +libcurl +usbmuxd
+endef
+
+define Package/idevicerestore/description
+ The idevicerestore tool allows to restore firmware files to iOS devices.
+ It is a full reimplementation of all granular steps which are performed
+ during restore of a firmware to a device.
+endef
+
+define Package/idevicerestore/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(CP) $(PKG_INSTALL_DIR)/usr/bin/idevicerestore $(1)/usr/bin/
+endef
+
+$(eval $(call BuildPackage,idevicerestore))
include $(TOPDIR)/rules.mk
PKG_NAME:=lcd4linux
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/feckert/lcd4linux
--- /dev/null
+--- a/plugin_i2c_sensors.c
++++ b/plugin_i2c_sensors.c
+@@ -68,6 +68,7 @@
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <dirent.h>
++#include <limits.h>
+
+ #include "debug.h"
+ #include "plugin.h"
PKG_NAME:=lxc
PKG_VERSION:=2.1.1
-PKG_RELEASE:=4
-
-PKG_LICENSE:=LGPL-2.1-or-later BSD-2-Clause GPL-2.0
-PKG_MAINTAINER:=Marko Ratkaj <marko.ratkaj@sartura.hr>
+PKG_RELEASE:=5
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://linuxcontainers.org/downloads/lxc/
PKG_HASH:=68663a67450a8d6734e137eac54cc7077209fb15c456eec401a2c26e6386eff6
+PKG_LICENSE:=LGPL-2.1-or-later BSD-2-Clause GPL-2.0
+PKG_MAINTAINER:=Marko Ratkaj <marko.ratkaj@sartura.hr>
+
PKG_BUILD_DEPENDS:=lua
PKG_BUILD_PARALLEL:=1
$(CP) \
$(PKG_INSTALL_DIR)/usr/lib/pkgconfig/lxc.pc \
$(1)/usr/lib/pkgconfig/
+ $(SED) 's,/usr/include,$$$${prefix}/include,g' $(1)/usr/lib/pkgconfig/lxc.pc
+ $(SED) 's,/usr/lib,$$$${prefix}/lib,g' $(1)/usr/lib/pkgconfig/lxc.pc
endef
+diff --git a/mt.c b/mt.c
+index d4058c0..4837808 100644
--- a/mt.c
+++ b/mt.c
-@@ -21,6 +21,7 @@
+@@ -20,6 +20,7 @@
+ #include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
- #include <sys/stat.h>
+#include <sys/sysmacros.h>
+ #include <sys/stat.h>
#include <sys/utsname.h>
- #include "mtio.h"
+diff --git a/stinit.c b/stinit.c
+index 5a50341..af5582c 100644
+--- a/stinit.c
++++ b/stinit.c
+@@ -16,6 +16,7 @@
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <dirent.h>
++#include <limits.h>
+ #include <sys/stat.h>
+ #include <sys/ioctl.h>
+ #include <sys/sysmacros.h>
include $(TOPDIR)/rules.mk
PKG_NAME:=nano
-PKG_VERSION:=4.5
+PKG_VERSION:=4.6
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=@GNU/nano
-PKG_HASH:=ded5c38f5ecd9de2b624e0db8013a375c169d3fbbd49575967b868847df8f533
+PKG_HASH:=9bac3a4153774fd921dd3eb291986d43985466b081165b5ac5262b37b79628e9
PKG_LICENSE:=GPL-3.0-or-later
PKG_LICENSE_FILES:=COPYING
include $(TOPDIR)/rules.mk
PKG_NAME:=nnn
-PKG_VERSION:=2.7
+PKG_VERSION:=2.8.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-v$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/jarun/nnn/tar.gz/v$(PKG_VERSION)?
-PKG_HASH:=0592c7cbcf2cf66cacac49e9204636480820b1bc74e4187dd7ee06945a6d07c5
+PKG_HASH:=cadf9cf8038433aeeb50a777180ad4b309ac7d2fec81c7da177ddca515812f06
PKG_MAINTAINER:=Josef Schlehofer <pepe.schlehofer@gmail.com>
PKG_LICENSE:=BSD-2-Clause
CATEGORY:=Utilities
TITLE:=Full-featured terminal file manager
URL:=https://github.com/jarun/nnn
- DEPENDS:=+libncurses +libreadline +findutils-xargs
+ DEPENDS:=+libncurses +libreadline
endef
define Package/nnn/description
PKG_SOURCE_VERSION:=32408520fcebe785983a68e39ec83830a3005779
PKG_MIRROR_HASH:=b5ae48fd300f75b948a2b2a5f6cd4465b7a336495685f73100ad33a5d43a4c05
-PKG_MAINTAINER:=Florian Fainelli <florian@openwrt.org>
+PKG_MAINTAINER:=Michael Heimpold <mhei@heimpold.de>
PKG_LICENSE:=ISC
PKG_LICENSE_FILES:=LICENSE
PKG_NAME:=opensc
PKG_VERSION:=0.19.0
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_HASH:=2c5a0e4df9027635290b9c0f3addbbf0d651db5ddb0ab789cb0e978f02fd5826
PKG_LICENSE:=LGPL-2.1-or-later
--- /dev/null
+--- a/src/libopensc/sc-ossl-compat.h
++++ b/src/libopensc/sc-ossl-compat.h
+@@ -76,6 +76,21 @@ extern "C" {
+ })
+ #endif /* OPENSSL_VERSION_NUMBER =< 0x00907000L */
+
++/*
++ * 1.1.0 depracated ERR_load_crypto_strings(), SSL_load_error_strings(), ERR_free_strings()
++ * and ENGINE_load_dynamic.EVP_CIPHER_CTX_cleanup and EVP_CIPHER_CTX_init are replaced
++ * by EVP_CIPHER_CTX_reset.
++ * But for compatability with LibreSSL and older OpenSSL. OpenSC uses the older functions
++ */
++#if OPENSSL_API_COMPAT >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
++#define ERR_load_crypto_strings(x) {}
++#define SSL_load_error_strings(x) {}
++#define ERR_free_strings(x) {}
++#define ENGINE_load_dynamic(x) {}
++#define EVP_CIPHER_CTX_cleanup(x) EVP_CIPHER_CTX_reset(x)
++#define EVP_CIPHER_CTX_init(x) EVP_CIPHER_CTX_reset(x)
++#endif
++
+ /*
+ * 1.1 renames RSA_PKCS1_SSLeay to RSA_PKCS1_OpenSSL
+ * use RSA_PKCS1_OpenSSL
+--- a/src/pkcs15init/pkcs15-oberthur-awp.c
++++ b/src/pkcs15init/pkcs15-oberthur-awp.c
+@@ -37,6 +37,7 @@
+ #include "libopensc/asn1.h"
+
+ #ifdef ENABLE_OPENSSL
++#include "libopensc/sc-ossl-compat.h"
+
+ struct awp_lv zero_lv = { 0, NULL };
+ struct awp_lv x30_lv = { 0x10, (unsigned char *)"0000000000000000" };
PKG_NAME:=pciutils
PKG_VERSION:=3.6.2
-PKG_RELEASE:=3
+PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=@KERNEL/software/utils/pciutils
$(CP) $(PKG_INSTALL_DIR)/usr/lib/*.so* $(1)/usr/lib
$(INSTALL_DIR) $(1)/usr/lib/pkgconfig
$(CP) $(PKG_BUILD_DIR)/lib/libpci.pc $(1)/usr/lib/pkgconfig
+ $(SED) 's,/usr/include,$$$${prefix}/include,g' $(1)/usr/lib/pkgconfig/libpci.pc
+ $(SED) 's,/usr/lib,$$$${prefix}/lib,g' $(1)/usr/lib/pkgconfig/libpci.pc
$(INSTALL_DIR) $(1)/usr/include/pci
$(CP) $(foreach i,pci.h config.h header.h types.h, \
$(PKG_BUILD_DIR)/lib/$(i)) $(1)/usr/include/pci
PKG_NAME:=procps-ng
PKG_VERSION:=3.3.15
-PKG_RELEASE:=3
+PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=@SF/procps-ng
PKG_HASH:=10bd744ffcb3de2d591d2f6acf1a54a7ba070fdcc432a855931a5057149f0465
-PKG_MAINTAINER:=Gergely Kiss <mail.gery@gmail.com>
-PKG_LICENSE:=GPL-2.0
+PKG_MAINTAINER:=
+PKG_LICENSE:=GPL-2.0-or-later
PKG_LICENSE_FILES:=COPYING COPYING.LIB
PKG_BUILD_PARALLEL:=1
$(call Package/procps-ng/Default)
DEPENDS:=procps-ng
TITLE:=Applet $(2) from the procps-ng package
- DEFAULT:=n
ALTERNATIVES:=200:$(3)/$(2):$(3)/$(1)
endef
include $(TOPDIR)/rules.mk
PKG_NAME:=qemu
-PKG_VERSION:=4.1.1
+PKG_VERSION:=4.2.0
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
-PKG_HASH:=ed6fdbbdd272611446ff8036991e9b9f04a2ab2e3ffa9e79f3bab0eb9a95a1d2
+PKG_HASH:=d3481d4108ce211a053ef15be69af1bdd9dde1510fda80d92be0f6c3e98768f0
PKG_SOURCE_URL:=http://download.qemu.org/
PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=LICENSE tcg/LICENSE
--- /dev/null
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=restic
+PKG_VERSION:=0.9.6
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/restic/restic/tar.gz/v${PKG_VERSION}?
+PKG_HASH:=1cc8655fa99f06e787871a9f8b5ceec283c856fa341a5b38824a0ca89420b0fe
+
+PKG_LICENSE:=BSD-2-Clause
+PKG_LICENSE_FILES:=LICENSE
+PKG_MAINTAINER:=Markus Weippert <markus@gekmihesg.de>
+
+PKG_BUILD_DEPENDS:=golang/host
+PKG_BUILD_PARALLEL:=1
+PKG_USE_MIPS16:=0
+
+GO_PKG:=github.com/restic/restic/
+GO_PKG_BUILD_PKG:=github.com/restic/restic/cmd/restic/
+GO_PKG_LDFLAGS:=-s -w
+GO_PKG_LDFLAGS_X:=main.version=$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+include ../../lang/golang/golang-package.mk
+
+define Package/restic
+ TITLE:=restic backup program
+ URL:=http://github.com/restic/restic
+ DEPENDS:=$(GO_ARCH_DEPENDS)
+ SECTION:=utils
+ CATEGORY:=Utilities
+endef
+
+define Package/restic/description
+restic is a backup program that is fast, efficient and secure. It supports the
+three major operating systems (Linux, macOS, Windows) and a few smaller ones
+(FreeBSD, OpenBSD).
+endef
+
+$(eval $(call GoBinPackage,restic))
+$(eval $(call BuildPackage,restic))
PKG_NAME:=shadow
PKG_VERSION:=4.6
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://github.com/shadow-maint/shadow/releases/download/$(PKG_VERSION)
--- /dev/null
+--- a/etc/login.defs
++++ b/etc/login.defs
+@@ -317,7 +317,7 @@ CHFN_RESTRICT rwh
+ # Note: If you use PAM, it is recommended to use a value consistent with
+ # the PAM modules configuration.
+ #
+-#ENCRYPT_METHOD DES
++ENCRYPT_METHOD SHA512
+
+ #
+ # Only works if ENCRYPT_METHOD is set to SHA256 or SHA512.
PKG_SOURCE_URL:=@SF/stoken
PKG_HASH:=aa2b481b058e4caf068f7e747a2dcf5772bcbf278a4f89bc9efcbf82bcc9ef5a
-PKG_MAINTAINER:=Florian Fainelli <florian@openwrt.org>
+PKG_MAINTAINER:=
PKG_LICENSE:=LGPL-2.1
PKG_INSTALL:=1
include $(TOPDIR)/rules.mk
PKG_NAME:=tmux
-PKG_VERSION:=2.9a
+PKG_VERSION:=3.0a
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://github.com/tmux/tmux/releases/download/$(PKG_VERSION)
-PKG_HASH:=839d167a4517a6bffa6b6074e89a9a8630547b2dea2086f1fad15af12ab23b25
+PKG_SOURCE_URL:=https://codeload.github.com/tmux/tmux/tar.gz/$(PKG_VERSION)?
+PKG_HASH:=523093fc71cb51345202ee50bd2a296a76a76060499958b9adc383cf7926ee66
PKG_MAINTAINER:=Maxim Storchak <m.storchak@gmail.com>
PKG_LICENSE:=ISC
PKG_NAME:=ttyd
PKG_VERSION:=1.5.2
-PKG_RELEASE:=1
+PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/tsl0922/ttyd/tar.gz/$(PKG_VERSION)?
# close all open connections
killall "$NAME"
}
+
+service_triggers() {
+ procd_add_reload_trigger "$NAME"
+}
--- /dev/null
+--- a/src/server.c
++++ b/src/server.c
+@@ -6,6 +6,7 @@
+ #include <getopt.h>
+ #include <signal.h>
+ #include <sys/stat.h>
++#include <syslog.h>
+
+ #include <libwebsockets.h>
+ #include <json.h>
+@@ -418,7 +419,8 @@ main(int argc, char **argv) {
+ return -1;
+ }
+
+- lws_set_log_level(debug_level, NULL);
++ openlog("ttyd", LOG_NDELAY | LOG_PID, LOG_DAEMON);
++ lws_set_log_level(debug_level, lwsl_emit_syslog);
+
+ #if LWS_LIBRARY_VERSION_MAJOR >= 2
+ char server_hdr[128] = "";
PKG_SOURCE_URL:=https://github.com/blogic/uledd.git
PKG_SOURCE_PROTO:=git
-PKG_SOURCE_VERSION:=bc94c7e52009f7ec33b23652502b4754351d8040
-PKG_MIRROR_HASH:=23a407197d6a423bb0b32f381e93ad3676e15f07465d7b53c843a2b510c7c284
+PKG_SOURCE_VERSION:=b7abc41ac4e04131e5a81f0f1de4e4ffb6ae16eb
+PKG_MIRROR_HASH:=751d6336619f282aa571cbd3aa64df9b326da74fc56477a425d49cb2b0a12aea
PKG_MAINTAINER:=John Crispin <john@phrozen.org>
-PKG_LICENSE:=GPL-2.0
+PKG_LICENSE:=LGPL-2.1-only
CMAKE_INSTALL:=1
define Package/uledd
SECTION:=utils
CATEGORY:=Utilities
- DEPENDS:=+libubox +libubus
+ DEPENDS:=+libubox +libubus +libblobmsg-json +libjson-c
TITLE:=PWM/RGB LED ubus frontend
endef
include $(TOPDIR)/rules.mk
PKG_NAME:=unrar
-PKG_VERSION:=5.8.3
+PKG_VERSION:=5.8.4
PKG_RELEASE:=1
PKG_SOURCE:=unrarsrc-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://www.rarlab.com/rar
-PKG_HASH:=3591685c8f5bbcb0be09de3d0a0544adb88966b9cccb80986f6cd2b534fd91a6
+PKG_HASH:=0b7cb2307ef7e65f631496376ce2fdf98b9b0f2136dc4467408ef63f3bf92f96
PKG_MAINTAINER:=Álvaro Fernández Rojas <noltari@gmail.com>, \
Ted Hess <thess@kitschensync.net>
include $(TOPDIR)/rules.mk
PKG_NAME:=usbmuxd
-PKG_SOURCE_DATE:=2019-03-04
-PKG_SOURCE_VERSION:=b1b0bf390363fa36aff1bc09443ff751943b9c34
+PKG_SOURCE_DATE:=2019-12-16
+PKG_SOURCE_VERSION:=ec5ff91cfabd30637f8af8f5c79baf4d7818ce57
PKG_RELEASE:=1
-PKG_MAINTAINER:=
-PKG_LICENSE:=GPL-2.0
-PKG_LICENSE_FILES:=COPYING.GPLv2
-PKG_CPE_ID:=cpe:/a:nikias_bassen:usbmuxd
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL=https://github.com/libimobiledevice/usbmuxd
+PKG_MIRROR_HASH:=1d0f2fa3842fbcbebe4b7d323829703e29a3c1a078c62b4a783e4c99a8a2f576
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_DATE).tar.gz
-PKG_SOURCE_URL=https://codeload.github.com/libimobiledevice/usbmuxd/tar.gz/$(PKG_SOURCE_VERSION)?
-PKG_HASH:=ca4275dbc21e8d9c926e65943b605ea5a6112d30eb3f9e655d3983da87ac6798
-PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_SOURCE_VERSION)
+PKG_MAINTAINER:=Rosen Penev <rosenp@gmail.com>
+PKG_LICENSE:=GPL-2.0-or-later
+PKG_LICENSE_FILES:=COPYING.GPLv2
+PKG_CPE_ID:=cpe:/a:libimobiledevice:usbmuxd
PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
define Package/usbmuxd
SECTION:=utils
CATEGORY:=Utilities
+ SUBMENU:=libimobiledevice
TITLE:=USB multiplexing daemon
- URL:=http://www.libimobiledevice.org/
+ URL:=https://www.libimobiledevice.org/
DEPENDS:=+librt +libusb-1.0 +libusbmuxd +libopenssl +libimobiledevice
endef
uses a dedicated USB interface as a virtual network device.
endef
+define Package/usbmuxd/conffiles
+/etc/lockdown
+/etc/lockdown/SystemConfiguration.plist
+endef
+
CONFIGURE_ARGS += --without-systemd
define Package/usbmuxd/install
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/usbmuxd.init $(1)/etc/init.d/usbmuxd
$(INSTALL_DIR) $(1)/usr/sbin
- $(CP) $(PKG_INSTALL_DIR)/usr/sbin/usbmuxd $(1)/usr/sbin/
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/usbmuxd $(1)/usr/sbin/
endef
$(eval $(call BuildPackage,usbmuxd))
--- /dev/null
+#!/bin/sh /etc/rc.common
+
+START=94
+
+USE_PROCD=1
+PROG=/usr/sbin/usbmuxd
+
+start_service() {
+ procd_open_instance
+ procd_set_param command $PROG -f
+ procd_set_param stderr 1
+ procd_close_instance
+}
+
+reload_service() {
+ procd_send_signal $PROG
+}
--- /dev/null
+--- a/src/conf.c
++++ b/src/conf.c
+@@ -126,7 +126,7 @@ const char *config_get_config_dir()
+ #ifdef __APPLE__
+ base_config_dir = strdup("/var/db");
+ #else
+- base_config_dir = strdup("/var/lib");
++ base_config_dir = strdup("/etc");
+ #endif
+ #endif
+ __config_dir = string_concat(base_config_dir, DIR_SEP_S, CONFIG_DIR, NULL);
PKG_NAME:=zsh
PKG_VERSION:=5.6.2
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=@SF/zsh
grep zsh $${IPKG_INSTROOT}/etc/shells || \
echo "/usr/bin/zsh" >> $${IPKG_INSTROOT}/etc/shells
- # Backwards compatibility
- if [[ -e /bin/zsh ]] && ([[ ! -L /bin/zsh ]] || [[ "$(readlink -fn $${IPKG_INSTROOT}/bin/zsh)" != "../$(CONFIGURE_PREFIX)/bin/zsh" ]]); then
- ln -fs "../$(CONFIGURE_PREFIX)/bin/zsh" "$${IPKG_INSTROOT}/bin/zsh"
- fi
+# Backwards compatibility
+if [ -e /bin/zsh ] && { [ ! -L /bin/zsh ] || [ "$(readlink -fn $${IPKG_INSTROOT}/bin/zsh)" != "../$(CONFIGURE_PREFIX)/bin/zsh" ]; }; then
+ ln -fs "../$(CONFIGURE_PREFIX)/bin/zsh" "$${IPKG_INSTROOT}/bin/zsh"
+fi
endef
define Package/zsh/install
endef
define Package/zsh/postrm
- rm -rf "$${IPKG_INSTROOT}/$(CONFIGURE_PREFIX)/share/zsh/$(PKG_VERSION)"
+#!/bin/sh
+rm -rf "$${IPKG_INSTROOT}/$(CONFIGURE_PREFIX)/share/zsh/$(PKG_VERSION)"
endef
$(eval $(call BuildPackage,zsh))
PKG_NAME:=zstd
PKG_VERSION:=1.4.4
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/facebook/zstd/tar.gz/v$(PKG_VERSION)?
--- /dev/null
+From f62cf1fff5dabcfaaa8c85638723bc19842f52f4 Mon Sep 17 00:00:00 2001
+From: Sergey Dryabzhinsky <sergey.dryabzhinsky+github@gmail.com>
+Date: Tue, 19 Nov 2019 23:15:28 +0300
+Subject: [PATCH] Fix typo in util.c
+
+There must be mtim*e*
+---
+ programs/util.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/programs/util.c b/programs/util.c
+index 5d15450d2..d3ffc1133 100644
+--- a/programs/util.c
++++ b/programs/util.c
+@@ -73,7 +73,7 @@ int UTIL_setFileStat(const char *filename, stat_t *statbuf)
+ {
+ /* (atime, mtime) */
+ struct timespec timebuf[2] = { {0, UTIME_NOW} };
+- timebuf[1] = statbuf->st_mtim;
++ timebuf[1] = statbuf->st_mtime;
+ res += utimensat(AT_FDCWD, filename, timebuf, 0);
+ }
+ #endif
--- /dev/null
+From 612a06eb3ef7f42739ace99fbca6ad63b788d46c Mon Sep 17 00:00:00 2001
+From: Sergey Dryabzhinsky <sergey.dryabzhinsky+github@gmail.com>
+Date: Tue, 19 Nov 2019 23:24:00 +0300
+Subject: [PATCH] Update util.c
+
+---
+ programs/util.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/programs/util.c b/programs/util.c
+index d3ffc1133..aa75ca6d4 100644
+--- a/programs/util.c
++++ b/programs/util.c
+@@ -73,7 +73,7 @@ int UTIL_setFileStat(const char *filename, stat_t *statbuf)
+ {
+ /* (atime, mtime) */
+ struct timespec timebuf[2] = { {0, UTIME_NOW} };
+- timebuf[1] = statbuf->st_mtime;
++ timebuf[1].tv_sec = statbuf->st_mtime;
+ res += utimensat(AT_FDCWD, filename, timebuf, 0);
+ }
+ #endif