diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dde066dc2e84ac924b436af72873ce35369e9853..251979e57f7fc83c92ec41f8d80c34c93d413a11 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -323,12 +323,11 @@ stages:
.rules-pytest-to-ref-short:
rules:
+ - if: $PYTEST_MLD_SHORT # Set by scheduled pipeline
- if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == "pytest-compare"
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_PIPELINE_SOURCE == 'push'
when: never
- - if: $CI_PIPELINE_SOURCE == 'schedule'
- when: never
.rules-pytest-to-input-short:
rules:
diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj
index d64c05ecbdc622573524d118b152fe819a171d5b..9bb04c8356cac9448951005f90405636d94e2f1d 100644
--- a/Workspace_msvc/lib_com.vcxproj
+++ b/Workspace_msvc/lib_com.vcxproj
@@ -138,7 +138,6 @@
-
@@ -200,47 +199,45 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
@@ -326,7 +323,6 @@
-
@@ -345,4 +341,4 @@
-
\ No newline at end of file
+
diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters
index c58edbff66fed647de45957935168e3d43c45bca..b9769e3ec6a62093e8d490955823c8466cfc7b77 100644
--- a/Workspace_msvc/lib_com.vcxproj.filters
+++ b/Workspace_msvc/lib_com.vcxproj.filters
@@ -1,81 +1,6 @@
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
common_all_c
@@ -379,9 +304,6 @@
common_all_c
-
- common_all_c
-
common_all_c
@@ -469,18 +391,6 @@
common_ivas_c
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
-
- common_ivas_c
-
common_ivas_c
@@ -493,18 +403,12 @@
common_ivas_c
-
- common_ivas_c
-
common_all_c
common_all_c
-
- common_all_c
-
common_all_c
@@ -544,6 +448,96 @@
common_all_c
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
+
+ common_ivas_c
+
@@ -588,9 +582,6 @@
common_h
-
- common_h
-
common_h
diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj
index 60498497b8f1383a4b8deb5d0e700056f1e18b52..5c19bc811cc295a937124b8537dd239cb82d5758 100644
--- a/Workspace_msvc/lib_dec.vcxproj
+++ b/Workspace_msvc/lib_dec.vcxproj
@@ -145,22 +145,17 @@
-
-
-
false
-
-
@@ -176,9 +171,7 @@
-
-
@@ -191,12 +184,10 @@
-
-
@@ -216,74 +207,72 @@
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
+
-
+
-
-
-
+
+
+
-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
@@ -310,18 +299,15 @@
-
-
-
diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters
index cc75944150d8853254cef72ce7bb1881cc39508e..8a4fc4605a1170b9da66c90a81b8bdd4134573c7 100644
--- a/Workspace_msvc/lib_dec.vcxproj.filters
+++ b/Workspace_msvc/lib_dec.vcxproj.filters
@@ -8,9 +8,6 @@
decoder_evs_c
-
- decoder_evs_c
-
decoder_evs_c
@@ -74,198 +71,51 @@
decoder_ivas_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
decoder_ivas_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
decoder_ivas_c
decoder_ivas_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
decoder_ivas_c
decoder_ivas_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
decoder_ivas_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
decoder_ivas_c
-
- decoder_ivas_c
-
decoder_ivas_c
-
- decoder_ivas_c
-
decoder_ivas_c
decoder_ivas_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
decoder_ivas_c
decoder_ivas_c
-
- decoder_ivas_c
-
decoder_ivas_c
decoder_ivas_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
decoder_ivas_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
decoder_all_c
@@ -275,36 +125,24 @@
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
@@ -320,15 +158,9 @@
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
@@ -365,9 +197,6 @@
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
@@ -380,9 +209,6 @@
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
@@ -437,9 +263,6 @@
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
@@ -515,15 +338,9 @@
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
@@ -542,9 +359,6 @@
decoder_all_c
-
- decoder_all_c
-
decoder_all_c
@@ -560,6 +374,150 @@
decoder_all_c
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
+
+ decoder_ivas_c
+
diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj
index 3b1004b285bb6373f1cae4902e57773c94324dda..eb9d1330e3142d06c6744a5dc771fe4e41b56d7a 100644
--- a/Workspace_msvc/lib_enc.vcxproj
+++ b/Workspace_msvc/lib_enc.vcxproj
@@ -215,127 +215,71 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
@@ -373,19 +317,9 @@
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters
index 0c3220178924f65ff87dfee9b4c2a57195bfd1d9..8990971637ef90b8f3a11fbd672278a29d3f89da 100644
--- a/Workspace_msvc/lib_enc.vcxproj.filters
+++ b/Workspace_msvc/lib_enc.vcxproj.filters
@@ -8,75 +8,39 @@
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
@@ -92,54 +56,33 @@
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
encoder_evs_c
-
- encoder_evs_c
-
encoder_evs_c
@@ -164,174 +107,9 @@
encoder_evs_c
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
encoder_ivas_c
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
-
- encoder_ivas_c
-
encoder_all_c
@@ -347,135 +125,72 @@
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
@@ -494,9 +209,6 @@
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
@@ -506,27 +218,15 @@
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
@@ -536,45 +236,24 @@
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
@@ -590,39 +269,21 @@
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
@@ -632,27 +293,15 @@
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
@@ -668,21 +317,12 @@
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
@@ -719,9 +359,6 @@
encoder_all_c
-
- encoder_all_c
-
encoder_all_c
@@ -800,6 +437,171 @@
encoder_all_c
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
+
+ encoder_ivas_c
+
diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj
index 5b50ade13794292b7a227438fb13fc42d311b24e..2ca8b2dfb26f1a268b7a4dd743529c8e2261d4df 100644
--- a/Workspace_msvc/lib_rend.vcxproj
+++ b/Workspace_msvc/lib_rend.vcxproj
@@ -136,45 +136,45 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -208,4 +208,4 @@
-
\ No newline at end of file
+
diff --git a/Workspace_msvc/lib_rend.vcxproj.filters b/Workspace_msvc/lib_rend.vcxproj.filters
index 01f3dfb74b19aaa5bbfbce01fa14d68eaf0e5af8..47b4fee016dc94ad61f00c2602859943261c3412 100644
--- a/Workspace_msvc/lib_rend.vcxproj.filters
+++ b/Workspace_msvc/lib_rend.vcxproj.filters
@@ -2,124 +2,124 @@
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
-
+
rend_c
@@ -143,9 +143,6 @@
rend_h
-
- rend_h
-
diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c
index 076bc8d9263d1f59c12906bb796fcbd5f245f591..46f8ecea1e78f01164d1acc083f29d3c26b145b6 100644
--- a/lib_com/ari_hm_fx.c
+++ b/lib_com/ari_hm_fx.c
@@ -10,7 +10,6 @@
#include "basop_util.h"
#include "rom_com.h"
#include "prot_fx.h"
-#include "prot.h"
#define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) )
void UnmapIndex(
diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c
index de22a7cf34863a72a79c2ba62661753766146176..846b4dceab0befaa6257563eda540e785fb7c1d9 100644
--- a/lib_com/arith_coder_fx.c
+++ b/lib_com/arith_coder_fx.c
@@ -6,7 +6,6 @@
#include
#include "options.h"
#include "prot_fx.h"
-#include "prot.h"
#include "basop_util.h"
#include "basop_proto_func.h"
#include "cnst.h"
diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c
index 378faae0f912a9af3b62e846b29ec38b8fbb44d4..8038c4f91e44fa3d4f3be746e03c2e3f1a7816ce 100644
--- a/lib_com/basop_tcx_utils.c
+++ b/lib_com/basop_tcx_utils.c
@@ -40,7 +40,7 @@
#include "cnst.h"
#include "basop_proto_func.h"
#include "stl.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#define WMC_TOOL_SKIP
diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c
index 92a8e3928cf25b050ed7cc0a5766181b60f4a66f..30ae2d47b028021152ead282c240af1a18c6f46b 100644
--- a/lib_com/bitalloc_fx.c
+++ b/lib_com/bitalloc_fx.c
@@ -7,7 +7,6 @@
#include "cnst.h" /* Common constants */
#include "rom_com.h" /* Static table prototypes */
#include "prot_fx.h" /* Function prototypes */
-#include "prot.h" /* Function prototypes */
void bitalloc_fx(
Word16 *y, /* i : reordered norm of sub-vectors Q0 */
diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c
index f2a074ba52262775d8bd34d2298645746b971661..88b276126a66e4b3aa9064e073b9cd8295264f27 100644
--- a/lib_com/bits_alloc_fx.c
+++ b/lib_com/bits_alloc_fx.c
@@ -408,7 +408,7 @@ static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk(
return bitsused;
}
-/*#ifdef IVAS_CODE Below basop operators are missing */
+
/*-------------------------------------------------------------------*
* fcb_table()
*
@@ -3271,4 +3271,3 @@ Word16 set_ACELP_flag_IVAS(
return 0;
}
}
-/*#endif IVAS_CODE*/
diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c
index e5754fa3550fc318b4ab703338a30db52018fa1d..9c0a53f8f541644be805662bdde778e026fd1a7c 100644
--- a/lib_com/bitstream.c
+++ b/lib_com/bitstream.c
@@ -38,7 +38,6 @@
#include
#include "options.h"
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "stat_enc.h"
#include "stat_dec.h"
@@ -1884,7 +1883,7 @@ static void decision_matrix_core_dec(
* Set up MDCT core switching if indicated in the bitstream
*-------------------------------------------------------------------*/
-void mdct_switching_dec(
+void mdct_switching_dec_ivas_fx(
Decoder_State *st /* i/o: decoder state structure */
)
{
diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c
index b236080217f473564ebc563bc19da54fa5462cc2..a9aa6bf67fdb213eeaef537c3abd77dbb9730e08 100644
--- a/lib_com/cldfb.c
+++ b/lib_com/cldfb.c
@@ -39,7 +39,6 @@
#include "options.h"
#include
#include "stat_dec.h"
-#include "prot.h"
#include "prot_fx.h"
#include "rom_com.h"
#include "rom_com_fx.h"
diff --git a/lib_com/cng_exc.c b/lib_com/cng_exc.c
deleted file mode 100644
index 494305e6f6435bf08e82e84ff48aa93390afef7d..0000000000000000000000000000000000000000
--- a/lib_com/cng_exc.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
-
-/*---------------------------------------------------------------------*
- * Local constants
- *---------------------------------------------------------------------*/
-
-#define A2 0.2f
-#define GAIN_VAR 0.000011f
-
-
-/*-------------------------------------------------------*
- * cng_params_upd()
- *
- * update CNG parameters
- *-------------------------------------------------------*/
diff --git a/lib_com/codec_tcx_common.c b/lib_com/codec_tcx_common.c
index f6da34b5583d96ee20611780db70092f10014bfa..1ebc2829c15493506950bd608ca397162826847c 100644
--- a/lib_com/codec_tcx_common.c
+++ b/lib_com/codec_tcx_common.c
@@ -6,7 +6,6 @@
#include
#include
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#include "basop_util.h"
#include "rom_basop_util.h"
diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c
index 8d360c6a33ce404a2f0c4d7881bffb361206ba1e..ed72605de96233aa45f2a5460dc6032004e49efa 100644
--- a/lib_com/core_com_config.c
+++ b/lib_com/core_com_config.c
@@ -38,10 +38,9 @@
#include
#include "options.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#define FSCALE_DENOM_BY_12800_Q15 1311
@@ -551,63 +550,6 @@ int16_t sr2fscale(
return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 );
}
-/*-------------------------------------------------------------------*
- * getCoreSamplerateMode2_flt()
- *
- *
- *-------------------------------------------------------------------*/
-
-int32_t getCoreSamplerateMode2_flt(
- const int16_t element_mode, /* i : IVAS element mode */
- const int32_t total_brate, /* i : total bitrate */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */
- const int16_t rf_mode, /* i : flag to signal the RF mode */
- const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */
-)
-{
- int32_t sr_core = 0;
-
- if ( bwidth == NB )
- {
- sr_core = INT_FS_12k8;
- }
- else if ( element_mode == EVS_MONO && ( ( bwidth == WB && total_brate < ACELP_13k20 ) || ( bwidth == SWB && total_brate <= ACELP_13k20 ) || ( rf_mode == 1 ) ) )
- {
- sr_core = INT_FS_12k8;
- }
- else if ( element_mode > EVS_MONO && flag_ACELP16k == 0 )
- {
- sr_core = INT_FS_12k8;
- }
- else if ( bwidth == WB || ( bwidth == SWB && total_brate <= ACELP_32k ) || ( bwidth == FB && total_brate <= ACELP_32k ) )
- {
- sr_core = INT_FS_16k;
- }
- else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && !is_ism_format )
- {
- sr_core = INT_FS_16k;
- }
- else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE_ISM && element_mode == IVAS_SCE && is_ism_format )
- {
- sr_core = INT_FS_16k;
- }
- else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && is_ism_format )
- {
- sr_core = 25600;
- }
- else if ( ( ( bwidth == SWB || bwidth == FB ) && element_mode == EVS_MONO && total_brate <= HQ_64k ) || ( element_mode > IVAS_SCE && ( ( bwidth == SWB && total_brate <= IVAS_96k ) || ( bwidth == FB && total_brate <= IVAS_96k ) ) ) )
- {
- sr_core = 25600;
- }
- else if ( bwidth == SWB || bwidth == FB )
- {
- sr_core = 32000;
- }
-
- return sr_core;
-}
-
Word32 getCoreSamplerateMode2(
const Word16 element_mode, /* i : IVAS element mode Q0*/
const Word32 total_brate, /* i : total bitrate Q0*/
@@ -1235,8 +1177,8 @@ void init_tcx_window_cfg_fx(
}
/*Mid-OLA*/
/*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/
- hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); /*Q0*/
- hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); /*Q0*/
+ hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); /*Q0*/
+ hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); /*Q0*/
move16();
move16();
assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" );
diff --git a/lib_com/deemph.c b/lib_com/deemph.c
index b2b43cf723086f91f455c975a0db37760bfbca6a..c03a050bca095711ea2e0c6a07e721aeb29e1dbf 100644
--- a/lib_com/deemph.c
+++ b/lib_com/deemph.c
@@ -36,9 +36,8 @@
#include
#include "options.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
void deemph_fx_32(
diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c
index ae0a2c4697dc6e4f1d9683227303e8a0c20812fb..0398eb671a638c4c81a91908908983e17b8cbced 100644
--- a/lib_com/delay_comp.c
+++ b/lib_com/delay_comp.c
@@ -36,10 +36,9 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_cnst.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
/*--------------------------------------------------------------------------
* get_delay()
diff --git a/lib_com/disclaimer.c b/lib_com/disclaimer.c
index ba0973f97ec04508dda0ac2f6132ad3ac562c0cd..1a01c2c320d249726ccf142ca9a0390f2846ac24 100644
--- a/lib_com/disclaimer.c
+++ b/lib_com/disclaimer.c
@@ -36,7 +36,7 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#define WMC_TOOL_SKIP
diff --git a/lib_com/enr_1_az.c b/lib_com/enr_1_az.c
index 81fb78262435c66a23d564dc26f15444b91bf27a..5c99cdfa5e27692d9373f9e5bec6e1b046f8b380 100644
--- a/lib_com/enr_1_az.c
+++ b/lib_com/enr_1_az.c
@@ -37,9 +37,8 @@
#include
#include "options.h"
#include "cnst.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
Word16 Enr_1_Az_fx_o( /* o : impulse response energy Q3 */
diff --git a/lib_com/env_adj.c b/lib_com/env_adj.c
index 18520e188655666eb58e0a9ef12e83b364be5c1f..5a83dbe5fa8af935aa151a8fdb7d87738100c789 100644
--- a/lib_com/env_adj.c
+++ b/lib_com/env_adj.c
@@ -38,9 +38,8 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
/*--------------------------------------------------------------------------*
* env_adj()
diff --git a/lib_com/env_stab.c b/lib_com/env_stab.c
index b80fd0a8bddfbcee88da6ec12e1600dd9cf635dd..a3140b4e498beb79ffa011af6baa60bbeb0a2bad 100644
--- a/lib_com/env_stab.c
+++ b/lib_com/env_stab.c
@@ -39,11 +39,10 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
#include "stl.h"
-#include "prot_fx.h"
/*--------------------------------------------------------------------------*
* Local constants
*--------------------------------------------------------------------------*/
diff --git a/lib_com/env_stab_trans.c b/lib_com/env_stab_trans.c
index 8c6ec265fca667c94303d50eff38b3d3486f36f1..829bef5f40f99a7245b65102c1f3aad4f685aa7d 100644
--- a/lib_com/env_stab_trans.c
+++ b/lib_com/env_stab_trans.c
@@ -38,10 +38,9 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
/*--------------------------------------------------------------------------*
* env_stab_transient_detect()
*
diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c
index 138b8c1bc082d6d0b0b4db78e771cc1115c46458..4ff9c6c1129555fe39b5ea34e4200f9afe451741 100644
--- a/lib_com/est_tilt_fx.c
+++ b/lib_com/est_tilt_fx.c
@@ -40,18 +40,12 @@ Word16 est_tilt_fx( /* o : tilt of the code
const Word32 gain_code, /* i : algebraic code gain Q16 */
Word16 *voice_fac, /* o : voicing factor Q15 */
const Word16 Q_exc /* i : Scaling factor of excitation Q0 */
-#ifdef ADD_LRTD
- ,
- const Word16 L_subfr /* i : Sub frame length */
-#endif
)
{
Word16 i, tmp, exp, ener1, exp1, ener2, exp2;
Word32 L_tmp;
Word16 tilt_code;
-#ifdef ADD_LRTD
- PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " )
-#endif
+
ener1 = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp1 ) );
exp1 = sub( exp1, add( Q_exc, Q_exc ) );
L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */
@@ -117,26 +111,23 @@ Word16 est_tilt_fx( /* o : tilt of the code
/* RETURN ARGUMENTS : */
/* _ (Word16) tolt_code : tilt of the code Q15 */
/*=======================================================================*/
-Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */
- const Word16 *exc, /* i : adaptive excitation vector Qx */
- const Word16 gain_pit, /* i : adaptive gain Q14 */
- const Word16 *code, /* i : algebraic excitation vector Q9 */
- const Word32 gain_code, /* i : algebraic code gain Q16 */
- Word16 *voice_fac, /* o : voicing factor Q15 */
- const Word16 Q_exc /* i : Scaling factor of excitation Q0 */
-#if 1 // def ADD_LRTD
- ,
- const Word16 L_subfr, /* i : Sub frame length */
- const Word16 flag_tilt /* i : flag for special tilt */
-#endif
+
+/* o : tilt of the code Q15 */
+Word16 est_tilt_ivas_fx(
+ const Word16 *exc, /* i : adaptive excitation vector Qx */
+ const Word16 gain_pit, /* i : adaptive gain Q14 */
+ const Word16 *code, /* i : algebraic excitation vector Q9 */
+ const Word32 gain_code, /* i : algebraic code gain Q16 */
+ Word16 *voice_fac, /* o : voicing factor Q15 */
+ const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */
+ const Word16 L_subfr, /* i : Sub frame length */
+ const Word16 flag_tilt /* i : flag for special tilt */
)
{
Word16 i, tmp, exp, ener1, exp1, ener2, exp2;
Word32 L_tmp;
Word16 tilt_code;
-#ifdef ADD_LRTD
- PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " )
-#endif
+
ener1 = extract_h( Dot_product12( exc, exc, L_subfr, &exp1 ) );
exp1 = sub( exp1, add( Q_exc, Q_exc ) );
L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */
diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c
index f4468bd0b7107909f4d29adb81472267ff836aa8..78809ed2c6a0dd5a4ca9ba595896388b03106c75 100644
--- a/lib_com/fd_cng_com_fx.c
+++ b/lib_com/fd_cng_com_fx.c
@@ -12,7 +12,6 @@
#include "prot_fx.h"
#include "prot_fx_enc.h"
#include "ivas_prot_fx.h"
-#include "prot.h"
#define FFT_SCALING_512 1073741824 // Q22
#define FFT_SCALING_640 1342177280 // Q22
@@ -566,11 +565,6 @@ void minimum_statistics(
Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */
Word16 *msPeriodogBufPtr, /* i/o: Counter */
HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
-#ifdef IVAS_CODE_CNG
- ,
- const Word16 enc_dec, /* i : encoder/decoder indicator */
- const Word16 element_mode /* i : IVAS element mode type */
-#endif
)
{
Word16 i, j, k, s, s1, s2, s3;
diff --git a/lib_com/fft.c b/lib_com/fft.c
index 352a24be9f15eef4afe81bb41463b90651e525b4..e262f3909f179ea67b91c160866b1f62cd2b411a 100644
--- a/lib_com/fft.c
+++ b/lib_com/fft.c
@@ -39,7 +39,7 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c
index 1b095e34620b59ece817572a2b5bc9895222ff60..73ff582df61d5583b183473ee303d95f84dc675a 100644
--- a/lib_com/fft_fx.c
+++ b/lib_com/fft_fx.c
@@ -44,7 +44,7 @@
#include "options.h"
#include
#include "cnst.h"
-// #include "prot.h"
+// #include "prot_fx.h"
#include "prot_fx.h"
//#include "cnst_fx.h"
#include "rom_com.h"
@@ -4727,6 +4727,16 @@ static void fft_len16(
cmplx t[4];
cmplx y[16];
+#ifdef OPT_STEREO_32KBPS_V1
+ s[0] = x[0]; // Qx
+ move64();
+ s[1] = x[4]; // Qx
+ move64();
+ s[2] = x[8]; // Qx
+ move64();
+ s[3] = x[12]; // Qx
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
s[0] = CL_shr( x[0], SCALEFACTOR16 ); // Qx
move64();
s[1] = CL_shr( x[4], SCALEFACTOR16 ); // Qx
@@ -4735,6 +4745,7 @@ static void fft_len16(
move64();
s[3] = CL_shr( x[12], SCALEFACTOR16 ); // Qx
move64();
+#endif /* OPT_STEREO_32KBPS_V1 */
t[0] = CL_add( s[0], s[2] );
move64();
@@ -4754,6 +4765,16 @@ static void fft_len16(
y[3] = CL_add( t[1], t[3] );
move64();
+#ifdef OPT_STEREO_32KBPS_V1
+ s[0] = x[1]; // Qx
+ move64();
+ s[1] = x[5]; // Qx
+ move64();
+ s[2] = x[9]; // Qx
+ move64();
+ s[3] = x[13]; // Qx
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
s[0] = CL_shr( x[1], SCALEFACTOR16 ); // Qx
move64();
s[1] = CL_shr( x[5], SCALEFACTOR16 ); // Qx
@@ -4762,6 +4783,7 @@ static void fft_len16(
move64();
s[3] = CL_shr( x[13], SCALEFACTOR16 ); // Qx
move64();
+#endif /* OPT_STEREO_32KBPS_V1 */
t[0] = CL_add( s[0], s[2] );
move64();
@@ -4781,6 +4803,16 @@ static void fft_len16(
y[7] = CL_add( t[1], t[3] );
move64();
+#ifdef OPT_STEREO_32KBPS_V1
+ s[0] = x[2]; // Qx
+ move64();
+ s[1] = x[6]; // Qx
+ move64();
+ s[2] = x[10]; // Qx
+ move64();
+ s[3] = x[14]; // Qx
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
s[0] = CL_shr( x[2], SCALEFACTOR16 ); // Qx
move64();
s[1] = CL_shr( x[6], SCALEFACTOR16 ); // Qx
@@ -4789,6 +4821,7 @@ static void fft_len16(
move64();
s[3] = CL_shr( x[14], SCALEFACTOR16 ); // Qx
move64();
+#endif /* OPT_STEREO_32KBPS_V1 */
t[0] = CL_add( s[0], s[2] );
move64();
@@ -4810,6 +4843,16 @@ static void fft_len16(
y[11] = CL_add( t[1], t[3] );
move64();
+#ifdef OPT_STEREO_32KBPS_V1
+ s[0] = x[3]; // Qx
+ move64();
+ s[1] = x[7]; // Qx
+ move64();
+ s[2] = x[11]; // Qx
+ move64();
+ s[3] = x[15]; // Qx
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
s[0] = CL_shr( x[3], SCALEFACTOR16 ); // Qx
move64();
s[1] = CL_shr( x[7], SCALEFACTOR16 ); // Qx
@@ -4818,6 +4861,7 @@ static void fft_len16(
move64();
s[3] = CL_shr( x[15], SCALEFACTOR16 ); // Qx
move64();
+#endif /* OPT_STEREO_32KBPS_V1 */
t[0] = CL_add( s[0], s[2] );
move64();
@@ -4978,6 +5022,18 @@ static void fft_len20_fx(
cmplx tt[4];
cmplx y[20];
+#ifdef OPT_STEREO_32KBPS_V1
+ xx[0] = x[0]; // Qx
+ move64();
+ xx[1] = x[16]; // Qx
+ move64();
+ xx[2] = x[12]; // Qx
+ move64();
+ xx[3] = x[8]; // Qx
+ move64();
+ xx[4] = x[4]; // Qx
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
xx[0] = CL_shr( x[0], SCALEFACTOR20 ); // Qx
move64();
xx[1] = CL_shr( x[16], SCALEFACTOR20 ); // Qx
@@ -4988,6 +5044,7 @@ static void fft_len20_fx(
move64();
xx[4] = CL_shr( x[4], SCALEFACTOR20 ); // Qx
move64();
+#endif /* OPT_STEREO_32KBPS_V1 */
s[0] = CL_add( xx[1], xx[4] );
move64();
@@ -5023,6 +5080,18 @@ static void fft_len20_fx(
y[12] = CL_msu_j( s[2], s[3] );
move64();
+#ifdef OPT_STEREO_32KBPS_V1
+ xx[0] = x[5];
+ move64();
+ xx[1] = x[1];
+ move64();
+ xx[2] = x[17];
+ move64();
+ xx[3] = x[13];
+ move64();
+ xx[4] = x[9];
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
xx[0] = CL_shr( x[5], SCALEFACTOR20 );
move64();
xx[1] = CL_shr( x[1], SCALEFACTOR20 );
@@ -5033,6 +5102,7 @@ static void fft_len20_fx(
move64();
xx[4] = CL_shr( x[9], SCALEFACTOR20 );
move64();
+#endif /* OPT_STEREO_32KBPS_V1 */
s[0] = CL_add( xx[1], xx[4] );
move64();
@@ -5068,6 +5138,18 @@ static void fft_len20_fx(
y[13] = CL_msu_j( s[2], s[3] );
move64();
+#ifdef OPT_STEREO_32KBPS_V1
+ xx[0] = x[10];
+ move64();
+ xx[1] = x[6];
+ move64();
+ xx[2] = x[2];
+ move64();
+ xx[3] = x[18];
+ move64();
+ xx[4] = x[14];
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
xx[0] = CL_shr( x[10], SCALEFACTOR20 );
move64();
xx[1] = CL_shr( x[6], SCALEFACTOR20 );
@@ -5078,6 +5160,7 @@ static void fft_len20_fx(
move64();
xx[4] = CL_shr( x[14], SCALEFACTOR20 );
move64();
+#endif /* OPT_STEREO_32KBPS_V1 */
s[0] = CL_add( xx[1], xx[4] );
move64();
@@ -5113,6 +5196,18 @@ static void fft_len20_fx(
y[14] = CL_msu_j( s[2], s[3] );
move64();
+#ifdef OPT_STEREO_32KBPS_V1
+ xx[0] = x[15];
+ move64();
+ xx[1] = x[11];
+ move64();
+ xx[2] = x[7];
+ move64();
+ xx[3] = x[3];
+ move64();
+ xx[4] = x[19];
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
xx[0] = CL_shr( x[15], SCALEFACTOR20 );
move64();
xx[1] = CL_shr( x[11], SCALEFACTOR20 );
@@ -5123,6 +5218,7 @@ static void fft_len20_fx(
move64();
xx[4] = CL_shr( x[19], SCALEFACTOR20 );
move64();
+#endif /* OPT_STEREO_32KBPS_V1 */
s[0] = CL_add( xx[1], xx[4] );
move64();
@@ -6501,6 +6597,239 @@ static void fft_lenN(
cmplx s[8];
cmplx y[8];
+#ifdef OPT_STEREO_32KBPS_V1
+ y[1] = xx[1 * dim1];
+ move64();
+ y[2] = xx[2 * dim1];
+ move64();
+ y[3] = xx[3 * dim1];
+ move64();
+ y[4] = xx[4 * dim1];
+ move64();
+ y[5] = xx[5 * dim1];
+ move64();
+ y[6] = xx[6 * dim1];
+ move64();
+ y[7] = xx[7 * dim1];
+ move64();
+
+ test();
+ test();
+ IF( EQ_16( dim1, 8 ) || EQ_16( dim1, 16 ) || EQ_16( dim1, 32 ) )
+ {
+ FOR( i = 0; i < dim1; i++ )
+ {
+ {
+ y[0] = xx[i];
+ move64();
+ };
+ IF( i > 0 )
+ {
+ {
+ y[1] = CL_mac_j( CL_scale( xx[( i + ( 1 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 1 ) * dim1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 1 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 1 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[2] = CL_mac_j( CL_scale( xx[( i + ( 2 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 2 ) * dim1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 2 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 2 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[3] = CL_mac_j( CL_scale( xx[( i + ( 3 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 3 ) * dim1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 3 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 3 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[4] = CL_mac_j( CL_scale( xx[( i + ( 4 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 4 ) * dim1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 4 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 4 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[5] = CL_mac_j( CL_scale( xx[( i + ( 5 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 5 ) * dim1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 5 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 5 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[6] = CL_mac_j( CL_scale( xx[( i + ( 6 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 6 ) * dim1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 6 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 6 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[7] = CL_mac_j( CL_scale( xx[( i + ( 7 * dim1 ) )], W[( ( ( sc * i ) + ( ( sc * 7 ) * dim1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 7 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( sc * 7 ) * dim1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ }
+
+ t[0] = CL_add( y[0], y[4] );
+ move64();
+ t[1] = CL_sub( y[0], y[4] );
+ move64();
+ t[2] = CL_add( y[1], y[5] );
+ move64();
+ t[3] = CL_sub( y[1], y[5] );
+ move64();
+ t[4] = CL_add( y[2], y[6] );
+ move64();
+ t[5] = CL_sub( y[2], y[6] );
+ move64();
+ t[6] = CL_add( y[3], y[7] );
+ move64();
+ t[7] = CL_sub( y[3], y[7] );
+ move64();
+
+ s[0] = CL_add( t[0], t[4] );
+ move64();
+ s[2] = CL_sub( t[0], t[4] );
+ move64();
+ s[4] = CL_mac_j( t[1], t[5] );
+ move64();
+ s[5] = CL_msu_j( t[1], t[5] );
+ move64();
+ s[1] = CL_add( t[2], t[6] );
+ move64();
+ s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) );
+ move64();
+
+ t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) );
+ move64();
+ t[1] = CL_sub( t[3], t[7] );
+ move64();
+
+ s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); // Qx
+ move64();
+ s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); // Qx
+ move64();
+ s[7] = CL_conjugate( s[7] );
+ move64();
+
+ x[i] = CL_add( s[0], s[1] );
+ move64();
+ x[( i + ( 1 * dim1 ) )] = CL_add( s[5], s[6] );
+ move64();
+ x[( i + ( 2 * dim1 ) )] = CL_sub( s[2], s[3] );
+ move64();
+ x[( i + ( 3 * dim1 ) )] = CL_add( s[4], s[7] );
+ move64();
+ x[( i + ( 4 * dim1 ) )] = CL_sub( s[0], s[1] );
+ move64();
+ x[( i + ( 5 * dim1 ) )] = CL_sub( s[5], s[6] );
+ move64();
+ x[( i + ( 6 * dim1 ) )] = CL_add( s[2], s[3] );
+ move64();
+ x[( i + ( 7 * dim1 ) )] = CL_sub( s[4], s[7] );
+ move64();
+ }
+ }
+ ELSE
+ {
+ FOR( i = 0; i < dim1; i++ )
+ {
+ {
+ y[0] = xx[i];
+ move64();
+ };
+ IF( i > 0 )
+ {
+ {
+ y[1] = CL_mac_j( CL_scale( xx[( i + ( 1 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 1 ) * dim1 ) << 1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 1 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 1 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[2] = CL_mac_j( CL_scale( xx[( i + ( 2 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 2 ) * dim1 ) << 1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 2 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 2 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[3] = CL_mac_j( CL_scale( xx[( i + ( 3 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 3 ) * dim1 ) << 1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 3 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 3 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[4] = CL_mac_j( CL_scale( xx[( i + ( 4 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 4 ) * dim1 ) << 1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 4 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 4 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[5] = CL_mac_j( CL_scale( xx[( i + ( 5 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 5 ) * dim1 ) << 1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 5 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 5 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[6] = CL_mac_j( CL_scale( xx[( i + ( 6 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 6 ) * dim1 ) << 1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 6 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 6 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ {
+ y[7] = CL_mac_j( CL_scale( xx[( i + ( 7 * dim1 ) )], W[( ( ( sc * i ) + ( ( ( sc * 7 ) * dim1 ) << 1 ) ) - Woff )] ),
+ CL_scale( xx[( i + ( 7 * dim1 ) )], W[( ( ( ( sc * i ) + ( ( ( sc * 7 ) * dim1 ) << 1 ) ) + 1 ) - Woff )] ) ); // Qx
+ move64();
+ };
+ }
+
+ t[0] = CL_add( y[0], y[4] );
+ move64();
+ t[1] = CL_sub( y[0], y[4] );
+ move64();
+ t[2] = CL_add( y[1], y[5] );
+ move64();
+ t[3] = CL_sub( y[1], y[5] );
+ move64();
+ t[4] = CL_add( y[2], y[6] );
+ move64();
+ t[5] = CL_sub( y[2], y[6] );
+ move64();
+ t[6] = CL_add( y[3], y[7] );
+ move64();
+ t[7] = CL_sub( y[3], y[7] );
+ move64();
+
+ s[0] = CL_add( t[0], t[4] );
+ move64();
+ s[2] = CL_sub( t[0], t[4] );
+ move64();
+ s[4] = CL_mac_j( t[1], t[5] );
+ move64();
+ s[5] = CL_msu_j( t[1], t[5] );
+ move64();
+ s[1] = CL_add( t[2], t[6] );
+ move64();
+ s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) );
+ move64();
+
+ t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) );
+ move64();
+ t[1] = CL_sub( t[3], t[7] );
+ move64();
+
+ s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); // Qx
+ move64();
+ s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); // Qx
+ move64();
+ s[7] = CL_conjugate( s[7] );
+ move64();
+
+ x[i] = CL_add( s[0], s[1] );
+ move64();
+ x[( i + ( 1 * dim1 ) )] = CL_add( s[5], s[6] );
+ move64();
+ x[( i + ( 2 * dim1 ) )] = CL_sub( s[2], s[3] );
+ move64();
+ x[( i + ( 3 * dim1 ) )] = CL_add( s[4], s[7] );
+ move64();
+ x[( i + ( 4 * dim1 ) )] = CL_sub( s[0], s[1] );
+ move64();
+ x[( i + ( 5 * dim1 ) )] = CL_sub( s[5], s[6] );
+ move64();
+ x[( i + ( 6 * dim1 ) )] = CL_add( s[2], s[3] );
+ move64();
+ x[( i + ( 7 * dim1 ) )] = CL_sub( s[4], s[7] );
+ move64();
+ }
+ }
+#else /* OPT_STEREO_32KBPS_V1 */
test();
test();
test();
@@ -6781,6 +7110,7 @@ static void fft_lenN(
move64();
}
}
+#endif /* OPT_STEREO_32KBPS_V1 */
BREAK;
}
@@ -7173,7 +7503,11 @@ void rfft_fx(
move32();
x[( length - ( i << 1 ) )] = Mpy_32_16_1( L_add( t1, t3 ), 16384 /*0.5.Q15*/ );
move32();
+#ifdef OPT_STEREO_32KBPS_V1
+ x[( ( length - ( i << 1 ) ) + 1 )] = Mpy_32_16_1( L_add( t2, t4 ), -16384 /*0.5.Q15*/ );
+#else /* OPT_STEREO_32KBPS_V1 */
x[( ( length - ( i << 1 ) ) + 1 )] = Mpy_32_16_1( L_negate( L_add( t2, t4 ) ), 16384 /*0.5.Q15*/ );
+#endif /* OPT_STEREO_32KBPS_V1 */
move32();
}
diff --git a/lib_com/fft_rel.c b/lib_com/fft_rel.c
index 839b2faaf0012cb535e19a5ba8dbf265d6dccb62..1d020cabdd7d013f554eeb3d0a697e73682881d9 100644
--- a/lib_com/fft_rel.c
+++ b/lib_com/fft_rel.c
@@ -36,10 +36,9 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
/*---------------------------------------------------------------------*
* Local constants
diff --git a/lib_com/fill_spectrum.c b/lib_com/fill_spectrum.c
index 12ed75f0af89e02d3977505249687b75ebe7d7c4..bd9080a7bd41747ba25f9a5cecce507c5ac55e63 100644
--- a/lib_com/fill_spectrum.c
+++ b/lib_com/fill_spectrum.c
@@ -38,9 +38,8 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/findpulse.c b/lib_com/findpulse.c
index f2347d5b37f70a5bf9c5dd41296eb9d59f8da7b1..68853e06142c91523103ce2ae595215b69bbe61c 100644
--- a/lib_com/findpulse.c
+++ b/lib_com/findpulse.c
@@ -37,10 +37,9 @@
#include
#include "options.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "cnst.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
/*----------------------------------------------------------------------------------*
* findpulse()
diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c
index 41d90359f4a2643524d1abd16276b9c1e374512e..8b69e05e8811edbc273a3cd78e735d1bc0f99375 100644
--- a/lib_com/float_to_fix_ops.c
+++ b/lib_com/float_to_fix_ops.c
@@ -3,7 +3,6 @@
#include
#include
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#define WMC_TOOL_SKIP
@@ -184,14 +183,14 @@ Word16 Q_factor( float x )
{
Word16 Q = 15;
if ( x >= 1 || x <= -1 )
- Q = norm_s( (Word16) abs( (Word32) x ) );
+ Q = norm_s( (Word16) L_abs( (Word32) x ) );
return Q;
}
Word16 Q_factor_L( float x )
{
Word16 Q = 31;
if ( x >= 1 || x <= -1 )
- Q = norm_l( abs( (Word32) x ) );
+ Q = norm_l( L_abs( (Word32) x ) );
return Q;
}
Word16 Q_factor_L_32( Word32 x )
@@ -207,7 +206,7 @@ Word16 Q_factor_arr( float *x, Word16 l )
for ( int i = 0; i < l; i++ )
{
if ( x[i] >= 1 || x[i] <= -1 )
- Q = s_min( Q, norm_s( (Word16) abs( (Word32) x[i] ) ) );
+ Q = s_min( Q, norm_s( (Word16) L_abs( (Word32) x[i] ) ) );
}
return Q;
}
@@ -217,7 +216,7 @@ Word16 Q_factor_arrL( float *x, Word16 l )
for ( int i = 0; i < l; i++ )
{
if ( x[i] >= 1 || x[i] <= -1 )
- Q = s_min( Q, norm_l( (Word32) abs( (Word32) x[i] ) ) );
+ Q = s_min( Q, norm_l( (Word32) L_abs( (Word32) x[i] ) ) );
}
return Q;
}
diff --git a/lib_com/frame_ener.c b/lib_com/frame_ener.c
deleted file mode 100644
index e89c4dfad4e22bf0430a33058d441cfcbd4c0956..0000000000000000000000000000000000000000
--- a/lib_com/frame_ener.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "prot.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-/*----------------------------------------------------------------------------------*
- * fer_energy()
- *
- * Estimation of pitch-synchronous (voiced sounds) or half-frame energy
- *----------------------------------------------------------------------------------*/
-
-#ifndef IVAS_FLOAT_FIXED
-void fer_energy(
- const int16_t L_frame, /* i : frame length */
- const int16_t clas, /* i : frame classification */
- const float *synth, /* i : synthesized speech at Fs = 12k8 Hz */
- const float pitch, /* i : pitch period */
- float *enr, /* o : pitch-synchronous or half_frame energy */
- const int16_t offset /* i : speech pointer offset (0 or L_frame) */
-)
-{
- int16_t len;
- const float *pt_synth;
-
- if ( clas == VOICED_CLAS || clas == ONSET || clas == SIN_ONSET ) /* Voiced or Onset current frame */
- {
- len = (int16_t) ( pitch + 0.5f ); /* pitch value */
-
- pt_synth = synth;
- if ( offset != 0 )
- {
- pt_synth = synth + L_frame - len;
- }
-
- emaximum( pt_synth, len, enr ); /* pitch synchronous E */
- }
- else
- {
- pt_synth = synth;
- if ( offset != 0 )
- {
- pt_synth = synth + L_frame / 2;
- }
-
- *enr = dotp( pt_synth, pt_synth, L_frame / 2 );
- *enr /= (float) ( L_frame / 2 );
- }
- return;
-}
-#endif
-
-void fer_energy_fx(
- const Word16 L_frame, /* i : frame length */
- const Word16 clas, /* i : frame classification */
- const Word32 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q(q_synth) */
- const Word16 q_synth, /* i : synthesized speech at Fs = 12k8 Hz */
- const Word16 pitch, /* i : pitch period Q0 */
- Word32 *enr, /* o : pitch-synchronous or half_frame energy Q0 */
- const Word16 offset /* i : speech pointer offset (0 or L_frame) */
-)
-{
- Word16 len, shift, exp;
- const Word32 *pt_synth;
- Word16 enr_tmp, i;
- Word64 W_tmp;
-
- test();
- test();
- IF( EQ_16( clas, VOICED_CLAS ) || EQ_16( clas, ONSET ) || EQ_16( clas, SIN_ONSET ) ) /* Voiced or Onset current frame */
- {
- len = ( pitch ); /* pitch value */
- move16();
-
- pt_synth = synth;
- IF( offset != 0 )
- {
- pt_synth = synth + sub( L_frame, len );
- }
-
- emaximum_32fx( q_synth, pt_synth, len, enr ); /* pitch synchronous E */
- }
- ELSE
- {
- pt_synth = synth;
- IF( offset != 0 )
- {
- pt_synth = synth + shr( L_frame, 1 );
- }
-
- W_tmp = 0;
- move64();
- FOR( i = 0; i < L_frame / 2; i++ )
- {
- W_tmp = W_add( W_tmp, W_mult0_32_32( pt_synth[i], pt_synth[i] ) ); // Q = q_synth * 2
- }
- shift = W_norm( W_tmp );
- W_tmp = W_shl( W_tmp, shift ); // Q = q_synth * 2 + shift
- *enr = W_extract_h( W_tmp ); // Q = q_synth * 2 + shift - 32
- move32();
-
- enr_tmp = BASOP_Util_Divide3216_Scale( *enr, shr( L_frame, 1 ) /*Q0*/, &exp );
- *enr = L_shr( L_deposit_l( enr_tmp ), sub( sub( sub( shift, 32 ), exp ), 1 ) ); /*Q0*/
- move32();
- }
- return;
-}
-
-
-/*----------------------------------------------------------------------------------*
- * frame_ener()
- *
- * Estimation of pitch-synchronous (voiced) or mean half-frame (unvoiced) energy
- *----------------------------------------------------------------------------------*/
-Word16 frame_ener_fx(
- const Word16 L_frame, /* i : length of the frame */
- const Word16 clas, /* i : frame classification */
- const Word16 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q_new */
- const Word16 pitch, /* i : pitch period Q0 */
- Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */
- const Word16 offset, /* i : speech pointer offset (0 or L_FRAME) */
- const Word16 Q_new, /* i : Scaling factor */
- Word16 shift, /* i : Shift need to obtain 12 bits vectors */
- const Word16 enc /* i : Encoder/decoder */
-)
-{
- Word16 len, exp_enrq, exp_tmp, pos;
- Word16 i;
- const Word16 *pt_synth;
- Word32 Ltmp;
-
- exp_enrq = 0;
- move16();
- test();
- test();
- IF( ( EQ_16( clas, VOICED_CLAS ) ) || ( EQ_16( clas, ONSET ) ) || ( EQ_16( clas, SIN_ONSET ) ) ) /* current frame is voiced */
- {
- /* current frame is voiced */
- len = pitch;
- move16(); /* pitch value at the end of frame */
- pt_synth = synth;
- if ( offset != 0 )
- {
- pt_synth = synth + sub( L_frame, len );
- }
- emaximum_fx( Q_new, pt_synth, len, enr_q );
- IF( enc != 0 )
- {
- exp_enrq = norm_l( *enr_q );
- *enr_q = L_shl( *enr_q, exp_enrq );
- move32();
- exp_enrq = sub( exp_enrq, 2 );
- }
- }
- ELSE
- {
- /* current frame is unvoiced */
- Word16 L_frame2, exp2, enr_q_tmp;
-
- L_frame2 = shr( L_frame, 1 );
- pos = 0;
- move16();
-
- if ( offset != 0 )
- {
- pos = sub( L_frame, L_frame2 );
- }
- Ltmp = L_mult_sat( synth[pos], synth[pos] ); /*2 * Qnew + 1*/
- FOR( i = 1; i < L_frame2; i++ )
- {
- Ltmp = L_mac_sat( Ltmp, synth[pos + i], synth[pos + i] ); /*2 * Qnew + 1*/
- }
- test();
- IF( EQ_32( Ltmp, MAX_32 ) || enc != 0 )
- {
- /* scale down when overflow occurs */
- *enr_q = Energy_scale( synth + pos, L_frame2, shift, &exp_enrq );
- move32();
- }
- ELSE
- {
- shift = 0;
- move16();
- /* Normalize acc in Q31 (energy already calculated) */
- pos = norm_l( Ltmp );
- Ltmp = L_shl( Ltmp, pos );
- exp_enrq = sub( 30, pos ); /* exponent = 0..30 */
- *enr_q = Ltmp;
- move32();
- }
-
- /* enr2 = 1.0f/L_FRAME2 * dot_product(synth, synth, L_FRAME2) */
- exp_enrq = sub( exp_enrq, shl( shift, 1 ) );
-
- IF( enc != 0 )
- {
- assert( L_frame == 256 || L_frame == 320 );
-
- exp_tmp = add( shl( Q_new, 1 ), -2 + 7 ); /* L_subfr == L_SUBFR */
- exp_enrq = sub( exp_enrq, exp_tmp );
- exp_enrq = sub( 31, exp_enrq );
-
- IF( EQ_16( L_frame, 320 ) )
- {
- *enr_q = Mult_32_16( *enr_q, 26214 ); /*x 0.8 to get /160*/
- move32();
- i = norm_l( *enr_q );
- *enr_q = L_shl( *enr_q, i );
- move32();
- exp_enrq = add( i, exp_enrq );
- }
- }
- ELSE
- {
- exp_enrq = sub( exp_enrq, add( Q_new, Q_new ) );
- enr_q_tmp /*Q30 exp2+exp_enrq*/ = BASOP_Util_Divide3216_Scale( *enr_q /*Q31*/, L_frame2 /*Q0*/, &exp2 );
- *enr_q = L_shr( L_deposit_l( enr_q_tmp ), sub( 30, add( exp2, exp_enrq ) ) ); /*Q0*/
- move32();
- *enr_q = L_add( *enr_q, 1 );
- move32();
- exp_enrq = 0;
- move16();
- }
- }
-
- return exp_enrq;
-}
-
-/*------------------------------------------------------------------------*
- * frame_energy()
- *
- * Compute pitch-synchronous energy at the frame end
- *------------------------------------------------------------------------*/
-Word16 frame_energy_fx( /* o : Frame energy in Q8 */
- Word16 L_frame,
- const Word16 *pitch, /* i : pitch values for each subframe Q6 */
- const Word16 *speech, /* i : pointer to speech signal for E computation Q_syn*/
- const Word16 lp_speech, /* i : long term active speech energy average Q8 */
- Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */
- const Word16 Q_syn /* i : Synthesis scaling */
-)
-{
- Word32 Ltmp;
- const Word16 *pt1;
- Word16 tmp16, exp1, exp2, tmp1, tmp2;
- Word16 len, enern;
-#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
- move32();
-#endif
-
-
- /* len = (0.5f * (pitch[2]/64.0 + pitch[3]/64.0) + 0.5f) */
- len = mult_r( add_o( pitch[2], pitch[3], &Overflow ), 256 );
-
- if ( LT_16( len, L_SUBFR ) )
- {
- len = shl( len, 1 );
- }
- pt1 = speech + sub( L_frame, len );
-
- /* *frame_ener = 10.0f * log10(dot_product(pt1, pt1, len) / (float)len) */
-
- tmp1 = norm_s( len );
- tmp2 = shl( len, tmp1 );
- tmp1 = sub( 15, tmp1 );
-
- Ltmp = Dot_productSq16HQ( 0, pt1, len, &exp1 );
- exp1 = sub( exp1, shl( Q_syn, 1 ) );
- exp1 = sub( exp1, 1 ); /* compensation of leftshift caused by mac operation in dot_productSq16HQ */
- tmp16 = BASOP_Util_Divide3216_Scale( Ltmp, len, &exp2 );
-
- exp1 = add( exp1, exp2 );
- exp1 = add( exp1, 1 ); /* compensate result of division Q-1 */
-
-
- tmp2 = norm_s( tmp16 );
- Ltmp = L_shl( L_deposit_h( tmp16 ), tmp2 ); /*Q16, (exp1-tmp2) = Q31, exp1-tmp2+15*/
-
- Ltmp = BASOP_Util_Log2( Ltmp ); /*Q(31-6) = Q25*/
- exp1 = sub( 15 + exp1, tmp2 );
-
- /*add ld(2^exp1)=exp1 but check format, first*/
- tmp16 = sub( sub( 15, norm_s( exp1 ) ), 5 ); /*factor to shift Ltmp and exp1 with (shr) to avoid overflows when adding*/
- Ltmp = L_shr_o( Ltmp, tmp16, &Overflow ); /*Q25, tmp16*/
- exp2 = shr( exp1, tmp16 ); /*Q0 , tmp16*/
- Ltmp = L_add_o( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ), &Overflow ); /*Q25, tmp16, normalized*/
-
- /*make 10*log10 out of log2*/
- Ltmp = Mpy_32_16_1( Ltmp, LG10 ); /*Q25,tmp16 * Q13 = Q23, tmp16*/
- *frame_ener = extract_h( L_shl_o( Ltmp, add( tmp16, 1 ), &Overflow ) ); /*Q8*/
- move16();
- enern = sub_o( *frame_ener, lp_speech, &Overflow ); /*Q8*/
-
- return enern;
-}
diff --git a/lib_com/frame_ener_fx.c b/lib_com/frame_ener_fx.c
index 4428c07964003506079fb33e6568451c4c8f1820..68fdf33c3a2db5ba8703f436ddc1e1043d17eef4 100644
--- a/lib_com/frame_ener_fx.c
+++ b/lib_com/frame_ener_fx.c
@@ -38,9 +38,8 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
/*----------------------------------------------------------------------------------*
* fer_energy()
*
diff --git a/lib_com/get_gain.c b/lib_com/get_gain.c
deleted file mode 100644
index 89b5fa3de291311902c7769b951cb2fd901bf218..0000000000000000000000000000000000000000
--- a/lib_com/get_gain.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "prot.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-/*----------------------------------------------------------------------------------*
- * get_gain()
- *
- *
- *----------------------------------------------------------------------------------*/
-
-#ifndef IVAS_FLOAT_FIXED
-/*! r: codebook gain (adaptive or fixed) */
-float get_gain_flt(
- const float x[], /* i : target signal */
- const float y[], /* i : filtered codebook excitation */
- const int16_t n, /* i : segment length */
- float *en_y /* o : energy of y (sum of y[]^2, optional) */
-)
-{
- float corr = 0.0f, ener = 1e-6f;
- int16_t i;
-
- for ( i = 0; i < n; i++ )
- {
- corr += x[i] * y[i];
- ener += y[i] * y[i];
- }
-
- if ( en_y )
- {
- *en_y = ener;
- }
-
- return ( corr / ener );
-}
-#endif
-
-Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */
- const Word16 x[], /* input : target signal Qx */
- const Word16 y[], /* input : filtered codebook excitation Qx */
- const Word16 n /* input : segment length */
-)
-{
- Word32 tcorr, tener, Lgain;
- Word16 exp_c, exp_e, exp, tmp;
-#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
- move32();
-#endif
-
-
- tcorr = L_deposit_l( 0 );
- tener = L_deposit_l( 0 );
-
-
- /*----------------------------------------------------------------*
- * Find gain based on inter-correlation product
- *----------------------------------------------------------------*/
-
- tcorr = Dot_product16HQ( 0, x, y, n, &exp_c );
- tener = Dot_productSq16HQ( 0, y, n, &exp_e );
-
- BASOP_Util_Divide_MantExp( round_fx_o( tcorr, &Overflow ), exp_c, s_max( round_fx_o( tener, &Overflow ), 1 ), exp_e, &tmp, &exp );
- Lgain = L_shl_o( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ), &Overflow ) /*Q16*/;
-
- return Lgain;
-}
-
-Word32 get_gain2( /* output: codebook gain (adaptive or fixed) Q16 */
- const Word16 x[], /* input : target signal */
- const Word16 y[], /* input : filtered codebook excitation */
- const Word16 n /* input : segment length */
-)
-{
- Word32 tcorr, tener, Lgain;
- Word16 m_corr, m_ener, negative, Q_corr, Q_ener;
-#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
- move32();
-#endif
-
- negative = 0;
- move16();
-
- /*----------------------------------------------------------------*
- * Find gain based on inter-correlation product
- *----------------------------------------------------------------*/
- tcorr = Dot_product16HQ( 0, x, y, n, &Q_corr );
- tener = Dot_productSq16HQ( 0, y, n, &Q_ener );
-
- tener = L_max( tener, 1 );
-
- if ( tcorr <= 0 )
- {
- negative = 1;
- move16();
- }
- BASOP_SATURATE_WARNING_OFF_EVS /*tcorr max be negative maxvall - not critical*/
- tcorr = L_abs( tcorr );
- BASOP_SATURATE_WARNING_ON_EVS
-
- m_corr = extract_h( tcorr );
-
- m_ener = extract_h( tener );
-
- IF( GT_16( m_corr, m_ener ) )
- {
- m_corr = shr( m_corr, 1 );
- Q_corr = add( Q_corr, 1 );
- }
- if ( m_ener == 0 )
- {
- move16();
- m_corr = 0x7FFF;
- }
- IF( m_ener != 0 )
- {
- m_corr = div_s( m_corr, m_ener );
- }
-
- Q_corr = sub( Q_corr, Q_ener );
-
- Lgain = L_shl_o( L_deposit_l( m_corr ), add( Q_corr, 1 ), &Overflow ); /* Lgain in Q16 */
-
- if ( negative != 0 )
- {
- Lgain = L_negate( Lgain ); /* Lgain in Q16 */
- }
-
-
- return Lgain;
-}
diff --git a/lib_com/get_gain_fx.c b/lib_com/get_gain_fx.c
index d4c2413c35dcd4893fbfd11e84b593c433b901e9..8ec4f5a40314afa27263cb7a4a77d8a31dd8d53c 100644
--- a/lib_com/get_gain_fx.c
+++ b/lib_com/get_gain_fx.c
@@ -36,9 +36,8 @@
#include
#include "options.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
/*----------------------------------------------------------------------------------*
* get_gain()
diff --git a/lib_com/gs_bitallocation_fx.c b/lib_com/gs_bitallocation_fx.c
index 47d3679a8289eff3a9131a3cb23f86eab3c5e7cb..87ba794d46728dabaed82ef6287774aad7c09f14 100644
--- a/lib_com/gs_bitallocation_fx.c
+++ b/lib_com/gs_bitallocation_fx.c
@@ -120,40 +120,7 @@ void bands_and_bit_alloc_fx(
move16();
bit_new_bands = 5;
move16();
-#ifdef ADD_LRTD
- if ( GT_32( core_brate, ACELP_16k40 ) && EQ_16( L_frame, L_FRAME16k ) )
- {
- bit_new_bands = 7;
- move16();
- }
-
- i = 0;
- move16();
- WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) )
- {
- IF( LE_32( core_brate, brate_intermed_tbl[i] ) )
- {
- BREAK;
- }
-
- IF( EQ_32( brate_intermed_tbl[i], ACELP_24k40 ) )
- {
- BREAK;
- }
-
- i = add( i, 1 );
- }
-
- if ( GT_16( element_mode, EVS_MONO ) && EQ_16( coder_type, AUDIO ) &&
- LE_32( core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */
- {
- i = sub( i, 1 );
- }
-
- bit_index = i_mult2( BRATE2IDX_fx( brate_intermed_tbl[i] ), 17 );
-#else
bit_index = i_mult2( BRATE2IDX_fx( core_brate ), 17 );
-#endif
bit_index_mem = bit_index;
move16();
@@ -189,668 +156,330 @@ void bands_and_bit_alloc_fx(
move16();
}
-#ifdef ADD_LRTD
- if ( L_frame == L_FRAME16k )
+ IF( EQ_16( GSC_noisy_speech, 1 ) )
{
- *bit -= 8;
- }
+ SWB_bit_budget = *bit;
+ move16();
+ nb_bands = 5;
+ move16();
- if ( coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT ) /* can happen only for 2nd channel inactive */
- {
- *bit += GSC_LRES_NB_NITS;
- }
+ st_band = nb_bands;
+ move16();
- if ( *bit > 0 )
- {
- if ( GSC_IVAS_mode > 0 )
- {
- SWB_bit_budget = *bit;
- st_band = 5;
+ set32_fx( bits_per_bands, 0, MBANDS_GN );
+ /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */
+ bit_fracf = L_mult( div_s( 1, nb_bands ), shl( SWB_bit_budget, 2 ) ); /* Q18 */
- set_f( bits_per_bands, 0, MBANDS_GN_BITALLOC16k );
+ nb_tot_bands = sub( nb_bands_max, 6 );
+ nb_tot_bands = s_min( nb_tot_bands, 16 );
- /* 2- Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */
- bit_fracf = ( -0.125f * Diff_len + 76.0f ) / 100;
- bit_fracf = check_bounds( bit_fracf, 0.50f, 0.75f );
+ FOR( j = 0; j < 2; j++ )
+ {
+ i = j;
+ move16();
+ max_ener_band[j] = i;
+ move16();
+ ener_vec[i] = 0;
+ move16();
+ }
- /* Adjusment of the bitrate between LF and HF base on the content type */
- /* 1 = new GSC bit alloc
- 2 = GSC bit alloc for tc frame
- 3 = more music like (should not happen often given music is coded with dft) */
+ FOR( ; j < nb_bands; j++ )
+ {
+ i = maximum_fx( ener_vec, nb_tot_bands, &etmp );
+ max_ener_band[j] = i;
+ move16();
+ ener_vec[i] = 0;
+ move16();
+ }
- if ( GSC_IVAS_mode <= 3 )
- {
- nb_bands_max -= 6;
- }
+ set32_fx( bits_per_bands, bit_fracf, nb_bands );
+ }
+ ELSE
+ {
+ bit_index++;
+ bit_tmp = sub( *bit, GSC_freq_bits[bit_index] );
+ bit_index++;
+ nb_bands_max = add( nb_bands_max, GSC_freq_bits[bit_index] );
+ bit_index++;
- if ( GSC_IVAS_mode == 2 )
- {
- bit_fracf += 0.1f;
- nb_bands_max--;
- }
+ *pvq_len = 112;
+ move16();
+ st_band = 7;
+ move16();
- if ( GSC_IVAS_mode == 3 )
- {
- bit_fracf -= 0.1f;
- nb_bands_max += 3;
- }
+ IF( LE_32( core_brate, ACELP_9k60 ) )
+ {
+ *pvq_len = 80;
+ move16();
+ st_band = 5;
+ move16();
- /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/
- /* Adjust the number of band based on the content type and bitrate */
- nb_bands_adj = 1.0f;
- if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG )
- {
- nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;
- }
- else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG )
+ IF( Diff_len == 0 )
{
- nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;
+ nb_bands_max = add( nb_bands_max, 2 );
+ bit_tmp = sub( bit_tmp, 13 );
}
- nb_bands_max = (int16_t) ( nb_bands_max * nb_bands_adj + 0.5f );
- nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands );
+ }
- bit_fracf *= SWB_bit_budget;
+ ELSE IF( Diff_len == 0 )
+ {
+ nb_bands_max = add( nb_bands_max, 2 );
+ bit_tmp = sub( bit_tmp, 17 );
+ }
- /* Estimation of the number of bit used in HF */
- /* with only the first weigthing The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */
- mb = .17f * bit_fracf;
- mp = ( 2.0f * DSR_NB_PULSE );
- if ( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 )
- {
- mp = 1.5f * DSR_NB_PULSE;
- }
- else if ( core_brate < GSC_L_RATE_STG )
+ nb_bands = shr( *pvq_len, 4 );
+
+ /*------------------------------------------------------------------------
+ * Ajustement of the maximum number of bands in function of the
+ * dynamics of the spectrum (more or less speech like)
+ *-----------------------------------------------------------------------*/
+ test();
+ test();
+ test();
+ test();
+ IF( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) )
+ {
+ /* Probably classification error -> concentrate bits on LF */
+ if ( GE_32( core_brate, ACELP_8k00 ) )
{
- mp = DSR_NB_PULSE;
+ nb_bands_max = add( nb_bands, 1 );
}
-
- /* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/
- /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */
- /* compute the total possible number of band to be coded */
- nb_tot_bands = (int16_t) ( ( SWB_bit_budget - bit_fracf ) / ( mp + ( mb - mp ) / 2.0f ) );
- mp = min( mp, mb );
- if ( nb_tot_bands + st_band > nb_bands_max )
+ else
{
- bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands + st_band - nb_bands_max );
- bit_adj = max( 0, bit_adj );
- nb_tot_bands = nb_bands_max - st_band;
- bit_fracf += bit_adj;
+ nb_bands_max = nb_bands;
+ move16();
}
- nb_tot_bands += st_band;
+ }
+ ELSE IF( GE_16( noise_lev, NOISE_LEVEL_SP2 ) ||
+ ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) ) /* Very low dynamic, tend to speech, do not try to code HF at all */
+ {
+ nb_bands_max = sub( nb_bands_max, 2 );
+ }
+ ELSE IF( GE_16( noise_lev, NOISE_LEVEL_SP1 ) ) /* Very low dynamic, tend to speech, code less HF */
+ {
+ nb_bands_max = sub( nb_bands_max, 1 );
+ }
- /* Allocate bits to LF */
- etmp = 0.23f;
- for ( j = 0; j < st_band; j++ )
- {
- i = j;
- max_ener_band[j] = i;
- ener_vec[i] = MIN16B;
- bits_per_bands[j] = etmp * bit_fracf;
- etmp -= 0.015f;
- }
+ test();
+ if ( ( EQ_16( bwidth, NB ) ) && GT_16( nb_bands_max, 10 ) )
+ {
+ nb_bands_max = 10;
+ move16();
+ }
- SWB_bit_budget -= bit_fracf;
+ /*------------------------------------------------------------------------
+ * Find extra number of band to code according to bit rate availables
+ *-----------------------------------------------------------------------*/
+ test();
+ WHILE( GE_16( bit_tmp, bit_new_bands ) && LE_16( nb_bands, sub( nb_bands_max, 1 ) ) )
+ {
+ test();
+ bit_tmp = sub( bit_tmp, bit_new_bands );
+ nb_bands = add( nb_bands, 1 );
+ }
- /* Find low energy band in HF */
- set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k );
- for ( i = st_band + 2; i < nb_tot_bands - 1; i++ )
- {
- if ( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] )
- {
- nb_pulse_per_band[i] = 1;
- }
- }
- for ( j = st_band; j < nb_tot_bands; j++ )
- {
- if ( j > 6 )
- {
- i = maximum( ener_vec, nb_tot_bands, &etmp );
- }
- else
- {
- i = j;
- }
+ /*------------------------------------------------------------------------
+ * Fractional bits to distribute on the first x bands
+ *-----------------------------------------------------------------------*/
- max_ener_band[j] = i;
- ener_vec[i] = MIN16B;
- }
+ {
+ bit_fracf = L_mult( div_s( 1, st_band ), shl( bit_tmp, 2 ) ); /* Q18 */
+ }
+ /*------------------------------------------------------------------------
+ * Complete the bit allocation per frequency band
+ *-----------------------------------------------------------------------*/
+ imax = 5;
+ move16();
- /* Recompute the final bit distribution for HF */
- if ( nb_tot_bands > st_band )
- {
- bit_fracf = DSR_NB_PULSE;
- mb = ( SWB_bit_budget * 2 / ( nb_tot_bands - st_band ) ) - mp;
- bit_fracf = ( mb - mp ) / ( nb_tot_bands - st_band );
- mb -= bit_fracf;
- /* Do the distribution */
- for ( j = st_band; j < nb_tot_bands; j++ )
- {
- if ( nb_pulse_per_band[max_ener_band[j]] > 1 )
- {
- bits_per_bands[max_ener_band[j]] = mb;
- }
- else
- {
- bits_per_bands[max_ener_band[j]] = 4.5f;
- }
- mb -= bit_fracf;
- SWB_bit_budget -= bits_per_bands[max_ener_band[j]];
- }
- }
+ if ( GT_32( core_brate, ACELP_9k60 ) )
+ {
+ imax = 7;
+ move16();
+ }
+ FOR( i = 0; i < imax; i++ )
+ {
+ bits_per_bands[i] = L_add( GSC_freq_bits_fx[bit_index], bit_fracf );
+ move32(); /* Q18 */
+ bit_index = add( bit_index, 1 );
+ }
- /* Series of verification in case bit allocated != the budget */
- if ( SWB_bit_budget > 0 )
+ IF( Diff_len == 0 )
+ {
+ bit_index = add( bit_index_mem, 10 );
+ FOR( i = 0; i < 7; i++ )
{
- i = st_band - 1;
- while ( SWB_bit_budget > 0 )
- {
- bits_per_bands[i]++;
- SWB_bit_budget--;
- i--;
- if ( i == -1 )
- {
- i = st_band - 1;
- }
- }
+ bits_per_bands[i] = L_add( bits_per_bands[i], GSC_freq_bits_fx[bit_index] );
+ move32(); /*chk Q18 */
+ bit_index = add( bit_index, 1 );
}
+ }
- nb_bands = nb_tot_bands;
-
- sum_bit = 0;
- j = 0;
- for ( i = 0; i < nb_bands; i++ )
- {
- if ( bits_per_bands[i] > 112 )
- {
- sum_bit += bits_per_bands[i] - 112;
- bits_per_bands[i] = 112;
- j = i + 1;
- }
-
- /* safety check for overage bit reallocation */
- else if ( bits_per_bands[i] + sum_bit / 3 > 112 )
- {
- j = i + 1;
- }
- }
+ /*--------------------------------------------------------------------------
+ * Complete the bit allocation per frequency band for 16kHz high brate mode
+ *--------------------------------------------------------------------------*/
- if ( sum_bit != 0 )
+ {
+ FOR( j = st_band; j < nb_bands; j++ )
{
- sum_bit /= ( nb_bands - j );
- for ( i = j; i < nb_bands; i++ )
- {
- bits_per_bands[i] += sum_bit;
- }
+ bits_per_bands[j] = L_shl( bit_new_bands, 18 );
+ move32(); /*chk Q18 */
}
}
- else
-#endif
- IF( EQ_16( GSC_noisy_speech, 1 ) )
- {
- SWB_bit_budget = *bit;
- move16();
- nb_bands = 5;
- move16();
-
-#ifdef ADD_LRTD
-
- fzero_val = 0.0f;
- if ( element_mode > EVS_MONO )
- {
- fzero_val = MIN16B_FLT;
- }
-
- if ( coder_type == UNVOICED && element_mode > EVS_MONO )
- {
- nb_bands = 3;
- if ( SWB_bit_budget > 20 )
- {
- nb_bands = 5;
- }
- }
- else if ( bwidth < SWB )
- {
- nb_bands = 7;
- }
-#endif
+ /*--------------------------------------------------------------------------
+ * Compute a maximum band (band offset) for the search on maximal energy
+ * This is function of the spectral dynamic and the bitrate
+ *--------------------------------------------------------------------------*/
- st_band = nb_bands;
- move16();
+ bandoffset = sub( nb_tot_bands, add( nb_bands, 2 ) );
- set32_fx( bits_per_bands, 0, MBANDS_GN );
- /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */
- bit_fracf = L_mult( div_s( 1, nb_bands ), shl( SWB_bit_budget, 2 ) ); /* Q18 */
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( LE_16( noise_lev, NOISE_LEVEL_SP1a ) )
+ {
+ bandoffset = sub( bandoffset, 1 );
+ }
+ ELSE IF( ( LE_32( core_brate, ACELP_13k20 ) && ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) ) ||
+ ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) )
+ {
+ bandoffset = add( bandoffset, 1 );
+ }
- nb_tot_bands = sub( nb_bands_max, 6 );
- nb_tot_bands = s_min( nb_tot_bands, 16 );
+ bandoffset = s_max( bandoffset, 0 );
- FOR( j = 0; j < 2; j++ )
- {
- i = j;
- move16();
- max_ener_band[j] = i;
- move16();
- ener_vec[i] = 0;
- move16();
- }
-#ifdef ADD_LRTD
- if ( bwidth < SWB )
- {
- if ( coder_type == UNVOICED && element_mode > EVS_MONO )
- {
- nb_tot_bands = 5;
- }
-#endif
- FOR( ; j < nb_bands; j++ )
- {
- i = maximum_fx( ener_vec, nb_tot_bands, &etmp );
- max_ener_band[j] = i;
- move16();
- ener_vec[i] = 0;
- move16();
- }
-#ifdef ADD_LRTD
- }
- else
- {
- for ( ; j < nb_bands; j++ )
- {
- i = maximum( ener_vec, nb_tot_bands, &etmp );
- max_ener_band[j] = i;
- ener_vec[i] = fzero_val;
- }
- }
-#endif
- set32_fx( bits_per_bands, bit_fracf, nb_bands );
- }
- ELSE
+ /*--------------------------------------------------------------------------
+ * Initiazed sorted vector
+ * For the first x bands to be included in th final sorted vector
+ * Sort the remaining bands in decrease energy order
+ *--------------------------------------------------------------------------*/
+ FOR( j = 0; j < nb_tot_bands; j++ )
{
- bit_index++;
- bit_tmp = sub( *bit, GSC_freq_bits[bit_index] );
- bit_index++;
- nb_bands_max = add( nb_bands_max, GSC_freq_bits[bit_index] );
- bit_index++;
-
- *pvq_len = 112;
+ max_ener_band[j] = -10;
move16();
- st_band = 7;
+ }
+ FOR( j = 0; j < st_band; j++ )
+ {
+ max_ener_band[j] = j;
move16();
-#ifdef ADD_LRTD
- if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 )
- {
- *pvq_len = 160;
- st_band = 10;
- nb_bands = *pvq_len / 16;
- bit_tmp -= 35;
- bit_new_bands = 5;
- }
-#endif
- IF( LE_32( core_brate, ACELP_9k60 ) )
- {
- *pvq_len = 80;
- move16();
- st_band = 5;
- move16();
-
- IF( Diff_len == 0 )
- {
- nb_bands_max = add( nb_bands_max, 2 );
- bit_tmp = sub( bit_tmp, 13 );
- }
- }
-
- ELSE IF( Diff_len == 0 )
- {
- nb_bands_max = add( nb_bands_max, 2 );
- bit_tmp = sub( bit_tmp, 17 );
- }
-
- nb_bands = shr( *pvq_len, 4 );
-#ifdef ADD_LRTD
- nb_bands_max = min( nb_bands_max, MBANDS_GN_BITALLOC16k );
-#endif
- /*------------------------------------------------------------------------
- * Ajustement of the maximum number of bands in function of the
- * dynamics of the spectrum (more or less speech like)
- *-----------------------------------------------------------------------*/
- test();
- test();
- test();
- test();
- IF( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) )
- {
- /* Probably classification error -> concentrate bits on LF */
-#ifdef ADD_LRTD
- if ( L_frame == L_FRAME16k && core_brate >= ACELP_24k40 )
- {
- nb_bands_max = nb_tot_bands - 2;
- }
- else if ( core_brate >= ACELP_16k40 )
- {
- nb_bands_max = nb_bands + 2;
- }
- else
-#endif
- if ( GE_32( core_brate, ACELP_8k00 ) )
- {
- nb_bands_max = add( nb_bands, 1 );
- }
- else
- {
- nb_bands_max = nb_bands;
- move16();
- }
- }
- ELSE IF( GE_16( noise_lev, NOISE_LEVEL_SP2 ) ||
- ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) ) /* Very low dynamic, tend to speech, do not try to code HF at all */
- {
- nb_bands_max = sub( nb_bands_max, 2 );
- }
- ELSE IF( GE_16( noise_lev, NOISE_LEVEL_SP1 ) ) /* Very low dynamic, tend to speech, code less HF */
- {
- nb_bands_max = sub( nb_bands_max, 1 );
- }
-#ifdef ADD_LRTD
- if ( L_frame == L_FRAME16k )
- {
- if ( core_brate < ACELP_24k40 )
- {
- nb_bands_max -= 4;
- }
- else if ( core_brate < ACELP_32k )
- {
- if ( Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2 )
- {
- nb_bands_max -= 2;
- bit_new_bands *= 2;
- }
- }
- else if ( core_brate >= ACELP_32k )
- {
- bit_new_bands *= 2;
- }
- }
-
-#endif
- test();
- if ( ( EQ_16( bwidth, NB ) ) && GT_16( nb_bands_max, 10 ) )
- {
- nb_bands_max = 10;
- move16();
- }
-
- /*------------------------------------------------------------------------
- * Find extra number of band to code according to bit rate availables
- *-----------------------------------------------------------------------*/
- test();
- WHILE( GE_16( bit_tmp, bit_new_bands ) && LE_16( nb_bands, sub( nb_bands_max, 1 ) ) )
- {
- test();
- bit_tmp = sub( bit_tmp, bit_new_bands );
- nb_bands = add( nb_bands, 1 );
- }
-
- /*------------------------------------------------------------------------
- * Fractional bits to distribute on the first x bands
- *-----------------------------------------------------------------------*/
-#ifdef ADD_LRTD
- if ( L_frame == L_FRAME16k && core_brate > ACELP_32k )
- {
- bit_fracf = 0;
- }
- else
-#endif
- {
- bit_fracf = L_mult( div_s( 1, st_band ), shl( bit_tmp, 2 ) ); /* Q18 */
- }
- /*------------------------------------------------------------------------
- * Complete the bit allocation per frequency band
- *-----------------------------------------------------------------------*/
- imax = 5;
+ ener_vec[j] = -10;
move16();
+ }
+ pos = st_band;
+ move16();
+ FOR( ; j < nb_bands; j++ )
+ {
+ i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp );
+ pos = s_max( pos, i );
+ max_ener_band[j] = i;
+ move16();
+ ener_vec[i] = -10;
+ move16();
+ }
- if ( GT_32( core_brate, ACELP_9k60 ) )
+ /* re-allocate bits to the frames such that the highest band with allocated bits is higher than the threshold */
+ test();
+ test();
+ test();
+ IF( GT_16( sub( nb_tot_bands, bandoffset ), nb_bands ) && ( GT_16( pos, 7 ) && EQ_32( core_brate, ACELP_8k00 ) ) && EQ_16( bwidth, WB ) )
+ {
+ band = sub( nb_tot_bands, add( bandoffset, nb_bands ) );
+ FOR( j = 0; j < band; j++ )
{
- imax = 7;
+ i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp );
+ max_ener_band[add( nb_bands, j )] = i;
move16();
+ ener_vec[i] = -10;
+ move16();
+ bits_per_bands[add( nb_bands, j )] = 1310720;
+ move32(); /*Q18 */
}
- FOR( i = 0; i < imax; i++ )
- {
- bits_per_bands[i] = L_add( GSC_freq_bits_fx[bit_index], bit_fracf );
- move32(); /* Q18 */
- bit_index = add( bit_index, 1 );
- }
-#ifdef ADD_LRTD
- if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 )
- {
- bit_index = 0;
- i = imax - 1;
- bits_per_bands[i] += Compl_GSC_freq_bits[bit_index];
- i++;
- bit_index++;
+ nb_bands = add( nb_bands, band );
- for ( ; i < 10; i++ )
- {
- bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf;
- bit_index++;
- }
- }
-#endif
- IF( Diff_len == 0 )
- {
- bit_index = add( bit_index_mem, 10 );
- FOR( i = 0; i < 7; i++ )
- {
- bits_per_bands[i] = L_add( bits_per_bands[i], GSC_freq_bits_fx[bit_index] );
- move32(); /*chk Q18 */
- bit_index = add( bit_index, 1 );
- }
- }
-#ifdef ADD_LRTD
- if ( bit_fracf < 0 )
- {
- for ( j = 0; j < nb_tot_bands; j++ )
- {
- bits_per_bands[j] = max( bits_per_bands[j], 0 );
- }
- }
+ bit_tmp = i_mult2( band, 5 );
-#endif
- /*--------------------------------------------------------------------------
- * Complete the bit allocation per frequency band for 16kHz high brate mode
- *--------------------------------------------------------------------------*/
-#ifdef ADD_LRTD
- if ( L_frame == L_FRAME16k && core_brate > ACELP_32k )
+ IF( LE_16( band, 2 ) )
{
- for ( j = st_band; j < nb_bands; j++ )
+ FOR( j = sub( st_band, 1 ); j < nb_bands; j++ )
{
- bits_per_bands[j] = bit_new_bands;
+ bits_per_bands[j] = L_add( bits_per_bands[j], 262144 ); /*Q18 */
+ move32();
}
-
- bit_fracf = ( 1.0f / nb_bands ) * ( bit_tmp );
-
- etmp = 2.0f * bit_fracf / ( nb_bands + 1 );
- bit_fracf = etmp;
- for ( j = nb_bands - 1; j >= 0; j-- )
- {
- bits_per_bands[j] += etmp;
- etmp += bit_fracf;
- }
- }
- else
-#endif
- {
- FOR( j = st_band; j < nb_bands; j++ )
- {
- bits_per_bands[j] = L_shl( bit_new_bands, 18 );
- move32(); /*chk Q18 */
- }
- }
-
- /*--------------------------------------------------------------------------
- * Compute a maximum band (band offset) for the search on maximal energy
- * This is function of the spectral dynamic and the bitrate
- *--------------------------------------------------------------------------*/
-
- bandoffset = sub( nb_tot_bands, add( nb_bands, 2 ) );
-
- test();
- test();
- test();
- test();
- test();
- IF( LE_16( noise_lev, NOISE_LEVEL_SP1a ) )
- {
- bandoffset = sub( bandoffset, 1 );
- }
- ELSE IF( ( LE_32( core_brate, ACELP_13k20 ) && ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) ) ||
- ( LE_32( core_brate, ACELP_13k20 ) && GE_32( core_brate, ACELP_9k60 ) && cor_strong_limit == 0 ) )
- {
- bandoffset = add( bandoffset, 1 );
+ bit_tmp = add( bit_tmp, add( sub( nb_bands, st_band ), 1 ) );
}
- bandoffset = s_max( bandoffset, 0 );
-
- /*--------------------------------------------------------------------------
- * Initiazed sorted vector
- * For the first x bands to be included in th final sorted vector
- * Sort the remaining bands in decrease energy order
- *--------------------------------------------------------------------------*/
- FOR( j = 0; j < nb_tot_bands; j++ )
- {
- max_ener_band[j] = -10;
- move16();
- }
- FOR( j = 0; j < st_band; j++ )
- {
- max_ener_band[j] = j;
- move16();
- ener_vec[j] = -10;
- move16();
- }
- pos = st_band;
+ i = 0;
move16();
- FOR( ; j < nb_bands; j++ )
- {
- i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp );
- pos = s_max( pos, i );
- max_ener_band[j] = i;
- move16();
- ener_vec[i] = -10;
- move16();
- }
-
- /* re-allocate bits to the frames such that the highest band with allocated bits is higher than the threshold */
- test();
- test();
- test();
- IF( GT_16( sub( nb_tot_bands, bandoffset ), nb_bands ) && ( GT_16( pos, 7 ) && EQ_32( core_brate, ACELP_8k00 ) ) && EQ_16( bwidth, WB ) )
+ j = 0;
+ move16();
+ FOR( ; bit_tmp > 0; bit_tmp-- )
{
- band = sub( nb_tot_bands, add( bandoffset, nb_bands ) );
- FOR( j = 0; j < band; j++ )
+ bits_per_bands[j] = L_sub( bits_per_bands[j], 262144 ); /*Q18 */
+ j = add( j, 1 );
+ if ( EQ_16( j, sub( st_band, i ) ) )
{
- i = maximum_fx( ener_vec, sub( nb_tot_bands, bandoffset ), &etmp );
- max_ener_band[add( nb_bands, j )] = i;
+ j = 0;
move16();
- ener_vec[i] = -10;
- move16();
- bits_per_bands[add( nb_bands, j )] = 1310720;
- move32(); /*Q18 */
- }
- nb_bands = add( nb_bands, band );
-
- bit_tmp = i_mult2( band, 5 );
-
- IF( LE_16( band, 2 ) )
- {
- FOR( j = sub( st_band, 1 ); j < nb_bands; j++ )
- {
- bits_per_bands[j] = L_add( bits_per_bands[j], 262144 ); /*Q18 */
- move32();
- }
- bit_tmp = add( bit_tmp, add( sub( nb_bands, st_band ), 1 ) );
}
-
- i = 0;
- move16();
- j = 0;
- move16();
- FOR( ; bit_tmp > 0; bit_tmp-- )
+ test();
+ if ( j == 0 && LT_16( i, sub( st_band, 1 ) ) )
{
- bits_per_bands[j] = L_sub( bits_per_bands[j], 262144 ); /*Q18 */
- j = add( j, 1 );
- if ( EQ_16( j, sub( st_band, i ) ) )
- {
- j = 0;
- move16();
- }
- test();
- if ( j == 0 && LT_16( i, sub( st_band, 1 ) ) )
- {
- i = add( i, 1 );
- }
+ i = add( i, 1 );
}
}
}
- /*--------------------------------------------------------------------------
- * Bit sum verification for GSC inactive at very high rate
- * The maximum number of bits per band of length 16 is 112
- * Redistribute the overage bits if needed
- *--------------------------------------------------------------------------*/
- sum_bit = 0;
- move16();
- j = 0;
- move16();
- FOR( i = 0; i < nb_bands; i++ )
- {
- L_tmp = Mult_32_16( sum_bit, 10923 );
-
- IF( GT_32( bits_per_bands[i], 29360128 ) ) /* 112 in Q18 */
- {
- sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 ) ); /* Q18 */
- bits_per_bands[i] = 29360128;
- move32();
- j = add( i, 1 );
- }
- ELSE IF( GT_32( L_add( bits_per_bands[i], L_tmp ), 29360128 ) ) /* Q18 */
- {
- j = add( i, 1 );
- }
- }
+ }
+ /*--------------------------------------------------------------------------
+ * Bit sum verification for GSC inactive at very high rate
+ * The maximum number of bits per band of length 16 is 112
+ * Redistribute the overage bits if needed
+ *--------------------------------------------------------------------------*/
+ sum_bit = 0;
+ move16();
+ j = 0;
+ move16();
+ FOR( i = 0; i < nb_bands; i++ )
+ {
+ L_tmp = Mult_32_16( sum_bit, 10923 );
- IF( sum_bit != 0 )
- {
- tmp = sub( nb_bands, j );
- sum_bit = Mult_32_16( sum_bit, div_s( 1, tmp ) ); /* Q18 */
- FOR( i = j; i < nb_bands; i++ )
- {
- bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit );
- move32(); /* Q18 */
- }
- }
- /*--------------------------------------------------------------------------
- * second step of bit sum verification, normally sum_bit == *bit
- *--------------------------------------------------------------------------*/
- w_sum_bit = 0;
- move16();
- FOR( i = 0; i < nb_bands; i++ )
+ IF( GT_32( bits_per_bands[i], 29360128 ) ) /* 112 in Q18 */
{
- out_bits_per_bands[i] = shl( extract_l( L_shr( bits_per_bands[i], 18 ) ), 3 );
- move16();
- w_sum_bit = add( w_sum_bit, out_bits_per_bands[i] ); /* Q3 */
+ sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 ) ); /* Q18 */
+ bits_per_bands[i] = 29360128;
+ move32();
+ j = add( i, 1 );
}
- tmp = shl( *bit, 3 );
-#ifdef ADD_LRTD
- if ( GSC_IVAS_mode != 0 && sum_bit < *bit ) /* If we need to add bits, we are doing it on the LF */
+ ELSE IF( GT_32( L_add( bits_per_bands[i], L_tmp ), 29360128 ) ) /* Q18 */
{
- reajust_bits( bits_per_bands, 0, nb_bands, (int16_t) sum_bit, *bit );
+ j = add( i, 1 );
}
- else
+ }
+
+ IF( sum_bit != 0 )
+ {
+ tmp = sub( nb_bands, j );
+ sum_bit = Mult_32_16( sum_bit, div_s( 1, tmp ) ); /* Q18 */
+ FOR( i = j; i < nb_bands; i++ )
{
- reajust_bits( bits_per_bands, nb_bands - 1, 0, (int16_t) sum_bit, *bit );
+ bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit );
+ move32(); /* Q18 */
}
-#else
+ }
+ /*--------------------------------------------------------------------------
+ * second step of bit sum verification, normally sum_bit == *bit
+ *--------------------------------------------------------------------------*/
+ w_sum_bit = 0;
+ move16();
+ FOR( i = 0; i < nb_bands; i++ )
+ {
+ out_bits_per_bands[i] = shl( extract_l( L_shr( bits_per_bands[i], 18 ) ), 3 );
+ move16();
+ w_sum_bit = add( w_sum_bit, out_bits_per_bands[i] ); /* Q3 */
+ }
+ tmp = shl( *bit, 3 );
+
IF( GT_16( tmp, w_sum_bit ) )
{
i = sub( nb_bands, 1 );
@@ -866,88 +495,24 @@ void bands_and_bit_alloc_fx(
}
}
}
-#endif
- /*--------------------------------------------------------------------------
- * Recompute the real number/length of frequency bands to encode
- *--------------------------------------------------------------------------*/
- *nb_subbands = nb_bands;
- move16();
- *pvq_len = shl( *nb_subbands, 4 );
- /*--------------------------------------------------------------------------
- * Concatenate bands (encoder only)
- *--------------------------------------------------------------------------*/
- IF( exc_diff != NULL )
- {
- FOR( j = 0; j < nb_bands; j++ )
- {
- Copy( exc_diff + shl( max_ener_band[j], 4 ), concat_in + shl( j, 4 ), 16 );
- }
- }
-#ifdef ADD_LRTD
- }
- else /* *bit == 0 */
- {
- set_s( bits_per_bands_s, 0, nb_tot_bands );
- *nb_subbands = 0;
- *pvq_len = 0;
- }
-#endif
- return;
-}
-#ifdef ADD_LRTD
-/*-------------------------------------------------------------------*
- * reajust_bits()
- *
- *
- *-------------------------------------------------------------------*/
-
-static void reajust_bits(
- float *bits_per_bands,
- const int16_t st_band,
- const int16_t end_band,
- const int16_t sum_bit_in,
- const int16_t bit_bdgt_in )
-{
- int16_t i, amount_to_add, incr;
- int16_t bit_bdgt, sum_bit;
-
- incr = 1;
- if ( end_band < st_band )
- {
- incr = -1;
- }
-
- if ( bit_bdgt_in < sum_bit_in )
- {
- amount_to_add = -1;
- bit_bdgt = sum_bit_in;
- sum_bit = bit_bdgt_in;
- }
- else
- {
- bit_bdgt = bit_bdgt_in;
- sum_bit = sum_bit_in;
- amount_to_add = 1;
- }
+ /*--------------------------------------------------------------------------
+ * Recompute the real number/length of frequency bands to encode
+ *--------------------------------------------------------------------------*/
+ *nb_subbands = nb_bands;
+ move16();
+ *pvq_len = shl( *nb_subbands, 4 );
- i = st_band;
- while ( bit_bdgt > sum_bit )
+ /*--------------------------------------------------------------------------
+ * Concatenate bands (encoder only)
+ *--------------------------------------------------------------------------*/
+ IF( exc_diff != NULL )
{
- if ( amount_to_add > 0 || ( amount_to_add < 0 && bits_per_bands[i] > 1 ) )
+ FOR( j = 0; j < nb_bands; j++ )
{
- bits_per_bands[i] += amount_to_add;
- sum_bit += (int16_t) abs( amount_to_add );
- }
-
- i += incr;
- if ( i == end_band )
- {
- i = st_band;
+ Copy( exc_diff + shl( max_ener_band[j], 4 ), concat_in + shl( j, 4 ), 16 );
}
}
return;
}
-
-#endif
diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c
index 0ab1670151c5e748105ad5463fa21ba9232e3ed3..0921dc88ca1d69e896ea1a8db45e65a6dc95f0c7 100644
--- a/lib_com/gs_bitallocation_ivas_fx.c
+++ b/lib_com/gs_bitallocation_ivas_fx.c
@@ -5,7 +5,6 @@
#include "options.h" /* Compilation switches */
#include "cnst.h" /* Common constants */
#include "rom_com.h" /* Static table prototypes */
-#include "prot.h" /* Function prototypes */
#include "prot_fx.h" /* Function prototypes */
#include "ivas_prot.h" /* Function prototypes */
#include "assert.h" /* Debug prototypes */
@@ -103,8 +102,8 @@ void bands_and_bit_alloc_ivas_fx(
Word16 etmp;
Word16 tmp;
Word16 pos, band;
- Word32 SWB_bit_budget; // Q0 -> Q18
- Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; // Q18
+ Word32 SWB_bit_budget; /* Q0 -> Q18 */
+ Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; /* Q18 */
Word16 w_sum_bit;
Word16 fzero_val;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
@@ -148,7 +147,7 @@ void bands_and_bit_alloc_ivas_fx(
move16();
bit_new_bands = 5;
move16();
-#if 1 // def ADD_LRTD
+
test();
if ( GT_32( core_brate, ACELP_16k40 ) && EQ_16( L_frame, L_FRAME16k ) )
{
@@ -183,9 +182,6 @@ void bands_and_bit_alloc_ivas_fx(
}
bit_index = i_mult2( BRATE2IDX_fx( brate_intermed_tbl[i] ), 17 );
-#else
- bit_index = i_mult2( BRATE2IDX_fx( core_brate ), 17 );
-#endif
bit_index_mem = bit_index;
move16();
@@ -221,7 +217,6 @@ void bands_and_bit_alloc_ivas_fx(
move16();
}
-#if 1 // def ADD_LRTD
IF( EQ_16( L_frame, L_FRAME16k ) )
{
*bit = sub( *bit, 8 );
@@ -242,18 +237,12 @@ void bands_and_bit_alloc_ivas_fx(
nb_tot_bands = Find_bit_alloc_IVAS_fx( core_brate, GSC_IVAS_mode, Diff_len, nb_tot_bands, bit, max_ener_band, ener_vec, bits_per_bands );
nb_bands = nb_tot_bands;
}
- ELSE
-#endif
- IF( EQ_16( GSC_noisy_speech, 1 ) )
+ ELSE IF( EQ_16( GSC_noisy_speech, 1 ) )
{
SWB_bit_budget = *bit; /*Q0*/
move32();
nb_bands = 5;
move16();
-
-#if 1 // def ADD_LRTD
-
- // fzero_val = 0.0f;
fzero_val = 0;
move16();
@@ -281,8 +270,6 @@ void bands_and_bit_alloc_ivas_fx(
move16();
}
-#endif
-
st_band = nb_bands;
move16();
@@ -298,11 +285,10 @@ void bands_and_bit_alloc_ivas_fx(
move16();
max_ener_band[j] = i;
move16();
- // ener_vec[i] = 0;
ener_vec[i] = fzero_val;
move16();
}
-#if 1 // def ADD_LRTD
+
IF( LT_16( bwidth, SWB ) )
{
test();
@@ -311,17 +297,15 @@ void bands_and_bit_alloc_ivas_fx(
nb_tot_bands = 5;
move16();
}
-#endif
+
FOR( ; j < nb_bands; j++ )
{
i = maximum_fx( ener_vec, nb_tot_bands, &etmp );
max_ener_band[j] = i;
move16();
- // ener_vec[i] = 0;
ener_vec[i] = fzero_val;
move16();
}
-#if 1 // def ADD_LRTD
}
ELSE
{
@@ -334,7 +318,7 @@ void bands_and_bit_alloc_ivas_fx(
move16();
}
}
-#endif
+
set32_fx( bits_per_bands, bit_fracf, nb_bands );
}
ELSE
@@ -349,7 +333,7 @@ void bands_and_bit_alloc_ivas_fx(
move16();
st_band = 7;
move16();
-#if 1 // def ADD_LRTD
+
test();
IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_16k40 ) )
{
@@ -362,7 +346,7 @@ void bands_and_bit_alloc_ivas_fx(
bit_new_bands = 5;
move16();
}
-#endif
+
IF( LE_32( core_brate, ACELP_9k60 ) )
{
*pvq_len = 80;
@@ -384,9 +368,8 @@ void bands_and_bit_alloc_ivas_fx(
}
nb_bands = shr( *pvq_len, 4 );
-#if 1 // def ADD_LRTD
nb_bands_max = s_min( nb_bands_max, MBANDS_GN_BITALLOC16k );
-#endif
+
/*------------------------------------------------------------------------
* Ajustement of the maximum number of bands in function of the
* dynamics of the spectrum (more or less speech like)
@@ -398,7 +381,6 @@ void bands_and_bit_alloc_ivas_fx(
IF( coder_type == INACTIVE || GE_16( noise_lev, NOISE_LEVEL_SP3 ) )
{
/* Probably classification error -> concentrate bits on LF */
-#if 1 // def ADD_LRTD
IF( EQ_16( L_frame, L_FRAME16k ) && GE_32( core_brate, ACELP_24k40 ) )
{
nb_bands_max = sub( nb_tot_bands, 2 );
@@ -407,9 +389,7 @@ void bands_and_bit_alloc_ivas_fx(
{
nb_bands_max = add( nb_bands, 2 );
}
- ELSE
-#endif
- IF( GE_32( core_brate, ACELP_8k00 ) )
+ ELSE IF( GE_32( core_brate, ACELP_8k00 ) )
{
nb_bands_max = add( nb_bands, 1 );
}
@@ -428,7 +408,7 @@ void bands_and_bit_alloc_ivas_fx(
{
nb_bands_max = sub( nb_bands_max, 1 );
}
-#if 1 // def ADD_LRTD
+
IF( EQ_16( L_frame, L_FRAME16k ) )
{
IF( LT_32( core_brate, ACELP_24k40 ) )
@@ -450,7 +430,6 @@ void bands_and_bit_alloc_ivas_fx(
}
}
-#endif
test();
if ( ( bwidth == NB ) && GT_16( nb_bands_max, 10 ) )
{
@@ -472,7 +451,7 @@ void bands_and_bit_alloc_ivas_fx(
/*------------------------------------------------------------------------
* Fractional bits to distribute on the first x bands
*-----------------------------------------------------------------------*/
-#if 1 // def ADD_LRTD
+
test();
IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_32k ) )
{
@@ -480,10 +459,10 @@ void bands_and_bit_alloc_ivas_fx(
move32();
}
ELSE
-#endif
{
bit_fracf = Find_bit_frac_fx( st_band, bit_tmp ); /*Q18*/
}
+
/*------------------------------------------------------------------------
* Complete the bit allocation per frequency band
*-----------------------------------------------------------------------*/
@@ -501,13 +480,12 @@ void bands_and_bit_alloc_ivas_fx(
move32(); /* Q18 */
bit_index = add( bit_index, 1 );
}
-#if 1 // def ADD_LRTD
+
IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_16k40 ) )
{
bit_index = 0;
move16();
i = sub( imax, 1 );
- // bits_per_bands[i] += Compl_GSC_freq_bits[bit_index];
bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( Compl_GSC_freq_bits[bit_index], Q18 ) ); /*Q18*/
move32();
i = add( i, 1 );
@@ -515,13 +493,12 @@ void bands_and_bit_alloc_ivas_fx(
FOR( ; i < 10; i++ )
{
- // bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf;
bits_per_bands[i] = L_add( bits_per_bands[i], L_add( L_shl( Compl_GSC_freq_bits[bit_index], Q18 ), bit_fracf ) ); /*Q18*/
move32();
bit_index = add( bit_index, 1 );
}
}
-#endif
+
IF( Diff_len == 0 )
{
bit_index = add( bit_index_mem, 10 );
@@ -532,7 +509,7 @@ void bands_and_bit_alloc_ivas_fx(
bit_index = add( bit_index, 1 );
}
}
-#if 1 // def ADD_LRTD
+
IF( bit_fracf < 0 )
{
FOR( j = 0; j < nb_tot_bands; j++ )
@@ -542,39 +519,33 @@ void bands_and_bit_alloc_ivas_fx(
}
}
-#endif
/*--------------------------------------------------------------------------
* Complete the bit allocation per frequency band for 16kHz high brate mode
*--------------------------------------------------------------------------*/
-#if 1 // def ADD_LRTD
+
test();
IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_32k ) )
{
FOR( j = st_band; j < nb_bands; j++ )
{
- // bits_per_bands[j] = bit_new_bands;
bits_per_bands[j] = L_shl( bit_new_bands, Q18 );
move32();
}
- // bit_fracf = (1.0f / nb_bands) * (bit_tmp);
bit_fracf = L_shl( L_mult0( idiv1616( 16384, nb_bands ), bit_tmp ), 4 ); /*Q18*/
- // etmp = 2.0f * bit_fracf / (nb_bands + 1);
- etmp = divide3216( L_shr( bit_fracf, Q2 ), add( nb_bands, 1 ) ); // Q15
- // bit_fracf = etmp;
- bit_fracf = L_shl( etmp, Q3 ); // Q18
+ etmp = divide3216( L_shr( bit_fracf, Q2 ), add( nb_bands, 1 ) ); /* Q15 */
+
+ bit_fracf = L_shl( etmp, Q3 ); /* Q18 */
+
FOR( j = nb_bands - 1; j >= 0; j-- )
{
- // bits_per_bands[j] = etmp;
- // etmp += bit_fracf;
- bits_per_bands[j] = L_add( bits_per_bands[j], L_shl( etmp, Q3 ) ); // Q18
+ bits_per_bands[j] = L_add( bits_per_bands[j], L_shl( etmp, Q3 ) ); /* Q18 */
move32();
etmp = extract_l( L_add( etmp, L_shr( bit_fracf, Q3 ) ) );
}
}
ELSE
-#endif
{
FOR( j = st_band; j < nb_bands; j++ )
{
@@ -688,6 +659,7 @@ void bands_and_bit_alloc_ivas_fx(
}
}
}
+
/*--------------------------------------------------------------------------
* Bit sum verification for GSC inactive at very high rate
* The maximum number of bits per band of length 16 is 112
@@ -724,19 +696,20 @@ void bands_and_bit_alloc_ivas_fx(
move32(); /* Q18 */
}
}
+
/*--------------------------------------------------------------------------
* second step of bit sum verification, normally sum_bit == *bit
*--------------------------------------------------------------------------*/
-#if 1 // def ADD_LRTD
+
sum_bit = 0;
move32();
FOR( i = 0; i < nb_bands; i++ )
{
- // bits_per_bands[i] = (float)floor(bits_per_bands[i]);
bits_per_bands[i] = L_shl( L_shr( bits_per_bands[i], Q18 ), Q18 );
move32();
sum_bit = L_add( sum_bit, L_shr( bits_per_bands[i], Q18 ) ); /*Q0*/
}
+
test();
IF( GSC_IVAS_mode != 0 && LT_32( sum_bit, *bit ) ) /* If we need to add bits, we are doing it on the LF */
{
@@ -755,23 +728,7 @@ void bands_and_bit_alloc_ivas_fx(
w_sum_bit = add( w_sum_bit, out_bits_per_bands[i] ); /* Q3 */
}
tmp = shl( *bit, 3 );
-#else
- IF( GT_16( tmp, w_sum_bit ) )
- {
- i = sub( nb_bands, 1 );
- move16();
- FOR( ; tmp > w_sum_bit; w_sum_bit += ( 1 << 3 ) )
- {
- out_bits_per_bands[i] = add( out_bits_per_bands[i], 1 << 3 );
- move16();
- i = sub( i, 1 );
- IF( i == 0 )
- {
- i = sub( nb_bands, 1 );
- }
- }
- }
-#endif
+
/*--------------------------------------------------------------------------
* Recompute the real number/length of frequency bands to encode
*--------------------------------------------------------------------------*/
@@ -790,7 +747,6 @@ void bands_and_bit_alloc_ivas_fx(
Copy( exc_diff + shl( max_ener_band[j], 4 ), concat_in + shl( j, 4 ), 16 );
}
}
-#if 1 // def ADD_LRTD
}
ELSE /* *bit == 0 */
{
@@ -800,10 +756,11 @@ void bands_and_bit_alloc_ivas_fx(
*pvq_len = 0;
move16();
}
-#endif
+
return;
}
-#if 1 // def ADD_LRTD
+
+
/*-------------------------------------------------------------------*
* reajust_bits()
*
@@ -924,26 +881,28 @@ static Word32 Find_bit_frac_fx(
return ( L_out );
}
-static Word16 Find_bit_alloc_IVAS_fx( /*o: Number of band to encode */
- const Word32 core_brate, /* i : core bit rate */
- const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */
- const Word16 Diff_len, /* i : Length of the difference signal (before pure spectral)*/
- const Word16 nb_tot_bands_in, /* i : total number of band */
- Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */
- Word16 *max_ener_band, /* i/o: Energy based sorted order */
- Word16 *ener_vec, /* i/o: Energy per band order */
- Word32 *bits_per_bands /* o : Number of bit allowed per allowed subband Q18 */
+
+/* o : Number of band to encode */
+static Word16 Find_bit_alloc_IVAS_fx(
+ const Word32 core_brate, /* i : core bit rate */
+ const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */
+ const Word16 Diff_len, /* i : Length of the difference signal (before pure spectral)*/
+ const Word16 nb_tot_bands_in, /* i : total number of band */
+ Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */
+ Word16 *max_ener_band, /* i/o: Energy based sorted order */
+ Word16 *ener_vec, /* i/o: Energy per band order */
+ Word32 *bits_per_bands /* o : Number of bit allowed per allowed subband Q18 */
)
{
Word32 mp, mb, nb_bands_adj, bit_adj;
Word16 nb_pulse_per_band[MBANDS_GN_BITALLOC16k];
- Word32 SWB_bit_budget; // Q0 -> Q18
+ Word32 SWB_bit_budget; /* Q0 -> Q18 */
Word16 i, j, nb_bands_max, st_band, nb_tot_bands_loc, etmp;
Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/;
Word16 d_tmp, e_div, tmp16;
Word32 Ltmp, etmp_32fx;
- SWB_bit_budget = *bit; // Q0
+ SWB_bit_budget = *bit; /* Q0 */
st_band = 5;
nb_bands_max = nb_tot_bands_in;
@@ -993,12 +952,12 @@ static Word16 Find_bit_alloc_IVAS_fx( /*o: Number
IF( EQ_16( GSC_IVAS_mode, 1 ) && LT_32( core_brate, GSC_L_RATE_STG ) )
{
/* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/
- nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, Q18 ) ), Q18_0_75 ); // Q18
+ nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, Q18 ) ), Q18_0_75 ); /* Q18 */
}
ELSE IF( NE_16( GSC_IVAS_mode, 2 ) && GT_32( core_brate, GSC_H_RATE_STG ) )
{
/*nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;*/
- nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, Q18 ) ), Q18_1_2 ); // Q18
+ nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, Q18 ) ), Q18_1_2 ); /* Q18 */
}
/*nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);*/
@@ -1131,7 +1090,7 @@ static Word16 Find_bit_alloc_IVAS_fx( /*o: Number
move32();
}
mb = L_sub( mb, bit_fracf );
- SWB_bit_budget = L_sub( SWB_bit_budget, bits_per_bands[max_ener_band[j]] ); // Q18
+ SWB_bit_budget = L_sub( SWB_bit_budget, bits_per_bands[max_ener_band[j]] ); /* Q18 */
}
}
@@ -1192,17 +1151,23 @@ static Word16 Find_bit_alloc_IVAS_fx( /*o: Number
move32();
}
}
+
return nb_tot_bands_loc;
}
-static Word16 Find_norm_inv_fx( const Word32 ToDivide, Word16 *e_div ) /* Find normalized 1 / ToDivide */
+
+/* Find normalized 1 / ToDivide */
+static Word16 Find_norm_inv_fx(
+ const Word32 ToDivide,
+ Word16 *e_div )
{
Word16 d_tmp, e_tmp;
+
e_tmp = norm_l( ToDivide );
d_tmp = round_fx( L_shl( ToDivide, e_tmp ) );
d_tmp = div_s( 16384, d_tmp ); /* 1.0 in Q14, dividend is normalize so >= 16384 as required for the division */
*e_div = sub( 14, e_tmp );
move16();
+
return d_tmp;
}
-#endif
diff --git a/lib_com/gs_gains.c b/lib_com/gs_gains.c
index 9adb448a4b21203625d0bd16617464f47c9096f7..8fa7694755c7c5ac9f912f26abdff9211895ff07 100644
--- a/lib_com/gs_gains.c
+++ b/lib_com/gs_gains.c
@@ -39,7 +39,6 @@
#include
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
#include "prot_fx.h"
#include "wmc_auto.h"
diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c
index d2a576dbe94521f4280f2ad50e0b3b6fbdf77a37..2e00e4641e177d2e17d2bbecbe6c93f93c522e1a 100644
--- a/lib_com/gs_noisefill_fx.c
+++ b/lib_com/gs_noisefill_fx.c
@@ -793,7 +793,6 @@ void highband_exc_dct_in_fx(
{
IF( exc_diffQ[i] == 0 )
{
- // PMT("code below to be validated for IVAS use")
/* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
tmp = shr( tmp, sub( 15, Qexc_diffQ ) ); /*qNoise_fac */
@@ -876,66 +875,7 @@ void highband_exc_dct_in_fx(
/*--------------------------------------------------------------------------------------*
* Apply decoded gain onto the difference signal
*--------------------------------------------------------------------------------------*/
-#ifdef ADD_LRTD
- if ( GSC_IVAS_mode >= 1 )
- {
- float scale_factLF = 0.9f;
- float scale_factHF = 0.9f;
-
- if ( GSC_IVAS_mode == 1 && GSC_noisy_speech == 0 )
- {
- scale_factHF = 0.8f;
- }
- else if ( GSC_IVAS_mode == 2 || GSC_noisy_speech == 1 )
- {
- scale_factHF = 0.71f;
- }
- else if ( GSC_IVAS_mode == 3 )
- {
- scale_factHF = 0.9f;
- }
- for ( i = 0; i < pit_band_idx * 16; i++ )
- {
- exc_diffQ[i] *= scale_factLF;
- }
- for ( ; i < L_frame; i++ )
- {
- exc_diffQ[i] *= scale_factHF;
- }
- }
- else if ( GSC_noisy_speech )
- {
- float scale_fact = 0.9f;
-
- if ( element_mode == IVAS_CPE_TD )
- {
- if ( coder_type == INACTIVE )
- {
- scale_fact = 1.0f;
- }
- else
- {
- scale_fact = 0.95f;
- }
- }
- else if ( element_mode > IVAS_SCE )
- {
- scale_fact = 0.71f;
- }
- for ( i = 0; i < L_frame; i++ )
- {
- exc_diffQ[i] *= scale_fact;
- }
- }
- if ( GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20 )
- {
- for ( i = 80; i < L_frame; i++ )
- {
- exc_diffQ[i] *= ( +0.0024f * (float) i + 1.192f );
- }
- }
-#else
IF( GSC_noisy_speech )
{
FOR( i = 0; i < L_frame; i++ )
@@ -944,7 +884,7 @@ void highband_exc_dct_in_fx(
move16();
}
}
-#endif
+
Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );
IF( exc_wo_nf != NULL )
@@ -1232,7 +1172,6 @@ void highband_exc_dct_in_ivas_fx(
{
IF( exc_diffQ[i] == 0 )
{
- // PMT("code below to be validated for IVAS use")
/* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
tmp = shr( tmp, sub( 15, Qexc_diffQ ) ); /*qNoise_fac */
@@ -1313,105 +1252,86 @@ void highband_exc_dct_in_ivas_fx(
}
}
}
+
/*--------------------------------------------------------------------------------------*
* Apply decoded gain onto the difference signal
*--------------------------------------------------------------------------------------*/
-#if 1 // def ADD_LRTD
+
IF( GSC_IVAS_mode >= 1 )
{
- // float scale_factLF = 0.9f;
- Word16 scale_factLF = 29491;
+ Word16 scale_factLF = 29491; /* 0.9f */
move16();
- // float scale_factHF = 0.9f;
- Word16 scale_factHF = 29491;
+ Word16 scale_factHF = 29491; /* 0.9f */
move16();
test();
test();
IF( EQ_16( GSC_IVAS_mode, 1 ) && GSC_noisy_speech == 0 )
{
- // scale_factHF = 0.8f;
scale_factHF = 26214;
move16();
}
ELSE IF( EQ_16( GSC_IVAS_mode, 2 ) || EQ_16( GSC_noisy_speech, 1 ) )
{
- // scale_factHF = 0.71f;
- scale_factHF = 23265;
+ scale_factHF = 23265; /* 0.71f */
move16();
}
ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) )
{
- // scale_factHF = 0.9f;
- scale_factHF = 29491;
+ scale_factHF = 29491; /* 0.9f */
move16();
}
FOR( i = 0; i < pit_band_idx * 16; i++ )
{
- // exc_diffQ[i] *= scale_factLF;
exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factLF );
}
FOR( ; i < L_frame; i++ )
{
- // exc_diffQ[i] *= scale_factHF;
exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factHF );
move16();
}
}
ELSE IF( GSC_noisy_speech )
{
- // float scale_fact = 0.9f;
- Word16 scale_fact = 29491;
+ Word16 scale_fact = 29491; /* 0.9f */
move16();
IF( EQ_16( element_mode, IVAS_CPE_TD ) )
{
IF( coder_type == INACTIVE )
{
- // scale_fact = 1.0f;
- scale_fact = 32767;
+ scale_fact = 32767; /* 1.0f */
move16();
}
ELSE
{
- // scale_fact = 0.95f;
- scale_fact = 31129;
+ scale_fact = 31129; /* 0.95f */
move16();
}
}
ELSE IF( GT_16( element_mode, IVAS_SCE ) )
{
- // scale_fact = 0.71f;
- scale_fact = 23265;
+ scale_fact = 23265; /* 0.71f */
move16();
}
FOR( i = 0; i < L_frame; i++ )
{
- // exc_diffQ[i] *= scale_fact;
exc_diffQ[i] = mult_r( exc_diffQ[i], scale_fact );
move16();
}
}
+
IF( GSC_noisy_speech && GT_16( element_mode, IVAS_SCE ) && LT_32( core_brate, ACELP_7k20 ) )
{
FOR( i = 80; i < L_frame; i++ )
{
- // exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f);
+ /* exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); */
exc_diffQ[i] = mult_r( shl( exc_diffQ[i], 1 ) /*Q16*/, (Word16) L_shr( L_add( 629 * i, 312475 ) /*Q18*/, Q4 ) /*Q14*/ );
move16();
}
}
-#else
- IF( GSC_noisy_speech )
- {
- FOR( i = 0; i < L_frame; i++ )
- {
- exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 );
- move16();
- }
- }
-#endif
+
Word16 Q_tmp = *Q_exc;
move16();
Word16 Q_old = *Q_exc;
diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c
deleted file mode 100644
index 58b49172d76f012203cbab808f6f64fb103d74d5..0000000000000000000000000000000000000000
--- a/lib_com/gs_preech.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-/*-------------------------------------------------------------------*
- * Local constants
- *-------------------------------------------------------------------*/
-
-#define ATT_LENGHT16k 80
-#ifndef IVAS_FLOAT_FIXED
-#define INV_L_FRAME16k ( 1.0f / L_FRAME16k )
-#endif
-
-#define ATT_LENGHT 64
-#define ATT_SEG_LEN ( L_FRAME / ATT_LENGHT )
-
-#ifndef IVAS_FLOAT_FIXED
-#define INV_ATT_SEG_LEN ( 1.0f / ATT_SEG_LEN )
-#define INV_L_FRAME ( 1.0f / L_FRAME )
-#endif
-
-#ifndef IVAS_FLOAT_FIXED
-/*-------------------------------------------------------------------*
- * pre_echo_att()
- *
- * Attenuation of the pre-echo when encoder specifies an attack
- *-------------------------------------------------------------------*/
-
-void pre_echo_att(
- float *Last_frame_ener, /* i/o: Energy of the last frame */
- float *exc, /* i/o: Excitation of the current frame */
- const int16_t attack_flag, /* i : attack flag (GSC or TC) */
- const int16_t last_coder_type, /* i : Last coder type */
- const int16_t L_frame /* i : frame length */
-)
-{
- float etmp;
- float etmp1;
- float finc[ATT_LENGHT16k], ratio_float, inv_l_frame;
- int16_t att_len;
- int16_t attack_pos, i;
-
- if ( attack_flag > 0 && last_coder_type == AUDIO )
- {
- /*-------------------------------------------------------------------------*
- * Find where the onset (attack) occurs by computing the energy per section
- * The inverse weighting aims to favor the first maxima in case of
- * gradual onset
- *-------------------------------------------------------------------------*/
-
- att_len = ATT_LENGHT;
- if ( L_frame == L_FRAME16k )
- {
- att_len = ATT_LENGHT16k;
- }
- for ( i = 0; i < att_len; i++ )
- {
- finc[i] = sum2_f( exc + i * ATT_SEG_LEN, ATT_SEG_LEN ) * ( (float) ( att_len - i ) / ( att_len ) );
- }
- etmp = -1;
- attack_pos = maximum( finc, att_len, &etmp );
-
- /* Scaled the maximum energy and allowed 6 dB increase*/
- etmp *= INV_ATT_SEG_LEN;
- etmp1 = etmp;
- *Last_frame_ener *= 4.0f;
-
- /* If the maximum normalized energy > last frame energy + 6dB */
- if ( etmp > *Last_frame_ener && attack_pos > 0 )
- {
- /* Find the average energy before the attack */
- etmp = sum_f( finc, attack_pos ) + 0.01f;
- etmp /= ( attack_pos * ATT_SEG_LEN );
-
- /* Find the correction factor and apply it before the attack */
- ratio_float = (float) sqrt( *Last_frame_ener / etmp );
-
-
- /* Pre-echo atttenuation should never increase the energy */
- ratio_float = min( ratio_float, 1.0f );
- for ( i = 0; i < attack_pos * ATT_SEG_LEN; i++ )
- {
- exc[i] *= ratio_float;
- }
- }
- *Last_frame_ener = etmp1;
- }
- else
- {
- /*-------------------------------------------------------*
- * In normal cases, just compute the energy of the frame
- *-------------------------------------------------------*/
-
- etmp = sum2_f( exc, L_frame ) + 0.01f;
- inv_l_frame = INV_L_FRAME;
- if ( L_frame == L_FRAME16k )
- {
- inv_l_frame = INV_L_FRAME16k;
- }
- etmp *= inv_l_frame;
- *Last_frame_ener = etmp;
- }
-
- return;
-}
-#endif
-
-void pre_echo_att_fx(
- Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/
- Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/
- const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/
- const Word16 Q_new,
- const Word16 last_coder_type, /* i : Last coding mode Q0*/
- const Word16 L_frame /* i : Frame length Q0*/
-)
-{
- Word32 etmp_fx;
- Word32 finc_fx[ATT_LENGHT16k] = { 0 };
- move16();
- Word16 ratio_fx;
- Word16 attack_pos_fx, i;
- Word32 L_tmp, L_tmp1;
- Word16 tmp, n1, n2, exp, frac1, frac2;
- Word32 etmp1_fx;
- Word16 att_len;
-
- test();
- IF( gsc_attack_flag_fx > 0 && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */
- {
- /*-------------------------------------------------------------------------*
- * Find where the onset (attack) occurs by computing the energy per section
- * The inverse weighting aims to favor the first maxima in case of
- * gradual onset
- *-------------------------------------------------------------------------*/
- att_len = ATT_LENGHT; /* Q0 */
- move16();
- if ( EQ_16( L_frame, L_FRAME16k ) )
- {
- att_len = ATT_LENGHT16k; /* Q0 */
- move16();
- }
- FOR( i = 0; i < att_len; i++ )
- {
- L_tmp = sum2_fx( &exc_fx[i * 4], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/
- tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */
- L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */
- finc_fx[i] = L_tmp;
- move32(); /*2*Q_new+1 */
- }
-
- attack_pos_fx = maximum_32_fx( finc_fx, att_len, &etmp_fx );
-
- /* Scaled the maximum energy and allowed 6 dB increase*/
- etmp_fx = L_shr( etmp_fx, add( 2 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */
- etmp1_fx = etmp_fx;
- move32();
- *Last_frame_ener_fx = L_shl_sat( *Last_frame_ener_fx, 2 );
- move32(); /*2*Q_new+1 */
-
- /* If the maximum normalized energy > last frame energy + 6dB */
- test();
- IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 )
- {
- /* Find the average energy before the attack */
- L_tmp = sum32_fx( finc_fx, attack_pos_fx ); /*Q1 */
- L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */
- tmp = round_fx( Isqrt( L_tmp1 ) ); /*Q15 */
- L_tmp = L_shr( L_tmp, 2 ); /*Q1 ; ATT_SEG_LEN=4 */
- etmp_fx = Mult_32_16( L_tmp, tmp ); /*Q1 */
-
- etmp_fx = L_shr( etmp_fx, add( 1 - 4, shl( Q_new, 1 ) ) ); /* makes etmp i nQ4 as *Last_frame_ener_fx */
- /* Find the correction factor and apply it before the attack */
- /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/
- /* = isqrt(etmp/(*Last_frame_ener)) */
- etmp_fx = L_max( etmp_fx, 1 );
- *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 );
- move32();
- n1 = norm_l( etmp_fx );
- n2 = norm_l( *Last_frame_ener_fx );
-
- n1 = sub( n1, 1 );
- exp = sub( n1, n2 );
-
- frac1 = round_fx( L_shl( etmp_fx, n1 ) );
- frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) );
- L_tmp = L_mult0( 128, div_s( frac1, frac2 ) ); /* s = gain_out / gain_in */
- L_tmp = L_shr( L_tmp, exp ); /* add exponent */
-
- L_tmp = Isqrt( L_tmp );
- ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Q13 */
-
- /* Pre-echo atttenuation should never increase the energy */
- ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */
- FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ )
- {
- /*exc_fx[i] *= ratio_fx;*/
- exc_fx[i] = round_fx( L_shl( L_mac( -8192, exc_fx[i], ratio_fx ), 2 ) );
- move16();
- }
- }
- *Last_frame_ener_fx = etmp1_fx; /*2*Q_new+1*/
- move32();
- }
- ELSE
- {
- /*-------------------------------------------------------*
- * In normal cases, just compute the energy of the frame
- *-------------------------------------------------------*/
-
- etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */
-#ifdef ADD_LRTD
- PMTE()
- etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/
-#else
- etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/
-#endif
- *Last_frame_ener_fx = etmp_fx;
- move32(); /*2*Q_new+1*/
- }
-
- return;
-}
-
-
-void pre_echo_att_ivas_fx(
- Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/
- Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/
- const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/
- const Word16 Q_new,
- const Word16 last_coder_type, /* i : Last coding mode Q0*/
- const Word16 L_frame /* i : Frame length Q0*/
-)
-{
- Word32 etmp_fx;
- Word32 finc_fx[ATT_LENGHT16k] = { 0 };
- move16();
- Word16 ratio_fx;
- Word16 attack_pos_fx, i;
- Word32 L_tmp, L_tmp1;
- Word16 tmp, n1, n2, exp, frac1, frac2;
- Word32 etmp1_fx;
- Word16 att_len;
-
- test();
- IF( gsc_attack_flag_fx > 0 && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */
- {
- /*-------------------------------------------------------------------------*
- * Find where the onset (attack) occurs by computing the energy per section
- * The inverse weighting aims to favor the first maxima in case of
- * gradual onset
- *-------------------------------------------------------------------------*/
- att_len = ATT_LENGHT; /* Q0 */
- move16();
- if ( EQ_16( L_frame, L_FRAME16k ) )
- {
- att_len = ATT_LENGHT16k; /* Q0 */
- move16();
- }
- FOR( i = 0; i < att_len; i++ )
- {
- L_tmp = sum2_fx( &exc_fx[i * 4], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/
- tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */
- L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */
- finc_fx[i] = L_tmp;
- move32(); /*2*Q_new+1 */
- }
-
- attack_pos_fx = maximum_32_fx( finc_fx, att_len, &etmp_fx );
-
- /* Scaled the maximum energy and allowed 6 dB increase*/
- etmp_fx = L_shr( etmp_fx, add( 2 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */
- etmp1_fx = etmp_fx;
- move32();
- *Last_frame_ener_fx = L_shl_sat( *Last_frame_ener_fx, 2 );
- move32(); /*2*Q_new+1 */
-
- /* If the maximum normalized energy > last frame energy + 6dB */
- test();
- IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 )
- {
- /* Find the average energy before the attack */
- L_tmp = sum32_fx( finc_fx, attack_pos_fx ); /*Q1 */
- L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */
- tmp = round_fx( Isqrt( L_tmp1 ) ); /*Q15 */
- L_tmp = L_shr( L_tmp, 2 ); /*Q1 ; ATT_SEG_LEN=4 */
- etmp_fx = Mult_32_16( L_tmp, tmp ); /*Q1 */
-
- etmp_fx = L_shr( etmp_fx, add( 1 - 4, shl( Q_new, 1 ) ) ); /* makes etmp i nQ4 as *Last_frame_ener_fx */
- /* Find the correction factor and apply it before the attack */
- /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/
- /* = isqrt(etmp/(*Last_frame_ener)) */
- etmp_fx = L_max( etmp_fx, 1 );
- *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 );
- move32();
- n1 = norm_l( etmp_fx );
- n2 = norm_l( *Last_frame_ener_fx );
-
- n1 = sub( n1, 1 );
- exp = sub( n1, n2 );
-
- frac1 = round_fx( L_shl( etmp_fx, n1 ) );
- frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) );
- L_tmp = L_mult0( 128, div_s( frac1, frac2 ) ); /* s = gain_out / gain_in */
- L_tmp = L_shr( L_tmp, exp ); /* add exponent */
-
- L_tmp = Isqrt( L_tmp );
- ratio_fx = round_fx( L_shl( L_tmp, 9 ) );
-
- /* Pre-echo atttenuation should never increase the energy */
- ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */
- FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ )
- {
- /*exc_fx[i] *= ratio_fx;*/
- exc_fx[i] = round_fx( L_shl( L_mac( -8192, exc_fx[i], ratio_fx ), 2 ) );
- move16();
- }
- }
- *Last_frame_ener_fx = etmp1_fx; /* 2 * Q_new + 1 */
- move32();
- }
- ELSE
- {
- /*-------------------------------------------------------*
- * In normal cases, just compute the energy of the frame
- *-------------------------------------------------------*/
- Word16 exp_etmp = sub( 15, Q_new );
- etmp_fx = sum2_16_exp_fx( exc_fx, L_frame, &exp_etmp, 7 ); /* Q = 31-exp_etmp */
-
- etmp_fx = L_shr( etmp_fx, 8 ); /*31-exp_etmp//INV_L_FRAME = 1/256*/
-
- IF( EQ_16( L_frame, L_FRAME16k ) )
- {
- etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*31 - exp_etmp*/
- }
- *Last_frame_ener_fx = L_shl( etmp_fx, sub( shl( Q_new, 1 ), sub( 30 /*31-1*/, exp_etmp ) ) ); /*2*Q_new+1*/
- move32(); /*2*Q_new+1*/
- }
-
- return;
-}
diff --git a/lib_com/gs_preech_fx.c b/lib_com/gs_preech_fx.c
index 9d905bcf290d87170d612499c3fa426e167d7a99..3b3eaa7776b9ff3c7403e4cb7f30decf8bf77a2b 100644
--- a/lib_com/gs_preech_fx.c
+++ b/lib_com/gs_preech_fx.c
@@ -39,9 +39,8 @@
#include
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
/*-------------------------------------------------------------------*
* Local constants
@@ -154,13 +153,8 @@ void pre_echo_att_fx(
* In normal cases, just compute the energy of the frame
*-------------------------------------------------------*/
- etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */
-#ifdef ADD_LRTD
- PMTE()
- etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/
-#else
+ etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */
etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/
-#endif
*Last_frame_ener_fx = etmp_fx;
move32(); /*2*Q_new+1*/
}
diff --git a/lib_com/hp50.c b/lib_com/hp50.c
deleted file mode 100644
index 6920063d42ab74e6fa769c49dbc4ea397580ba2d..0000000000000000000000000000000000000000
--- a/lib_com/hp50.c
+++ /dev/null
@@ -1,728 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include "prot.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-/*
- * hp20
- *
- * Function:
- * 2nd order high pass filter with nominal cut off frequency at 20 Hz.
- *
- * Returns:
- * void
- */
-
-#ifndef IVAS_FLOAT_FIXED
-void hp20_flt(
- Float32 signal[],
- const Word16 lg,
- Float32 mem[],
- const Word32 Fs )
-{
- Word16 i;
- Float32 x0, x1, x2, y0, y1, y2;
- Float32 a1, a2, b1, b2;
-
- y1 = mem[0];
- y2 = mem[1];
- x0 = mem[2];
- x1 = mem[3];
-
- if ( Fs == 8000 )
- {
- /* hp filter 20Hz at 3dB for 8000KHz input sampling rate
- [b,a] = butter(2, 20.0/4000.0, 'high');
- b = [0.988954248067140 -1.977908496134280 0.988954248067140]
- a =[1.000000000000000 -1.977786483776764 0.978030508491796]*/
- a1 = 1.977786483776764f;
- a2 = -0.978030508491796f;
- b1 = -1.977908496134280f;
- b2 = 0.988954248067140f;
- }
- else if ( Fs == 16000 )
- {
- /* hp filter 20Hz at 3dB for 16000KHz sampling rate
- [b,a] = butter(2, 20.0/8000.0, 'high');
- b =[ 0.994461788958195 -1.988923577916390 0.994461788958195]
- a =[1.000000000000000 -1.988892905899653 0.988954249933127] */
- a1 = 1.988892905899653f;
- a2 = -0.988954249933127f;
- b1 = -1.988923577916390f;
- b2 = 0.994461788958195f;
- }
- else if ( Fs == 32000 )
- {
- /* hp filter 20Hz at 3dB for 32000KHz sampling rate
- [b,a] = butter(2, 20.0/16000.0, 'high');
- b =[0.997227049904470 -1.994454099808940 0.997227049904470]
- a =[1.000000000000000 -1.994446410541927 0.994461789075954]*/
- a1 = 1.994446410541927f;
- a2 = -0.994461789075954f;
- b1 = -1.994454099808940f;
- b2 = 0.997227049904470f;
- }
- else
- {
- /* hp filter 20Hz at 3dB for 48000KHz sampling rate
- [b,a] = butter(2, 20.0/24000.0, 'high');
- b =[ 0.998150511190452 -1.996301022380904 0.998150511190452]
- a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/
- a1 = 1.996297601769122f;
- a2 = -0.996304442992686f;
- b1 = -1.996301022380904f;
- b2 = 0.998150511190452f;
- }
-
- for ( i = 0; i < lg; i++ )
- {
- x2 = x1;
- x1 = x0;
- x0 = signal[i];
- y0 = ( y1 * a1 ) + ( y2 * a2 ) + ( x0 * b2 ) + ( x1 * b1 ) + ( x2 * b2 );
- signal[i] = y0;
- y2 = y1;
- y1 = y0;
- }
-
- mem[0] = ( ( y1 > 1e-10 ) | ( y1 < -1e-10 ) ) ? y1 : 0;
- mem[1] = ( ( y2 > 1e-10 ) | ( y2 < -1e-10 ) ) ? y2 : 0;
- mem[2] = ( ( x0 > 1e-10 ) | ( x0 < -1e-10 ) ) ? x0 : 0;
- mem[3] = ( ( x1 > 1e-10 ) | ( x1 < -1e-10 ) ) ? x1 : 0;
-
- return;
-}
-#endif
-
-
-#define HP20_COEFF_SCALE ( 2 )
-/*
- * hp20
- *
- * Function:
- * 2nd order high pass filter with nominal cut off frequency at 20 Hz.
- *
- * Returns:
- * void
- */
-
-static Word32 HP50_Mode2_Mpy_32_16_fix( Word32 a, Word16 b )
-{
- Word32 result = Mpy_32_16_1( a, b );
- /* perform rounding towards lower value for negative results */
- if ( result < 0 )
- result = L_add( result, 1 );
- return result;
-}
-
-static Word32 HP50_Mpy_32_32_fix( Word32 a, Word32 b )
-{
- Word32 result = Mpy_32_32( a, b );
- /* perform rounding towards lower value for negative results */
- if ( result < 0 )
- result = L_add( result, 1 );
- return result;
-}
-
-
-static void filter_2nd_order(
- Word16 signal[],
- const Word16 stride,
- const Word16 prescale,
- const Word16 lg,
- Word32 mem[4],
- Word32 a1,
- Word32 a2,
- Word32 b1,
- Word32 b2 )
-{
-
- Word16 i;
- Word16 x2, x1;
- Word32 L_sum, L_y1, L_y2;
-#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
-#endif
-
-
- /*
- * Saturation: The states of the filter, namely L_y1 and L_y2 shall
- * never saturate, because that causes error in the filter feedback.
- * The final output written into signal[] might saturate because of
- * unavoidable filter overshoot.
- */
-
- /* Execute first 2 iterations with 32-bit x anx y memory values */
- BASOP_SATURATE_ERROR_ON_EVS
- L_sum = HP50_Mpy_32_32_fix( b2, mem[2] ); /* b2*x2 */
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( b1, mem[3] ) ); /* b1*x1 */
- x2 = shr( signal[0], prescale );
- L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x2 ) ); /* b2*x0 */
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[0], a2 ) ); /* y2*a2 */
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[1], a1 ) ); /* y1*a1 */
-
- L_y2 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow );
- BASOP_SATURATE_ERROR_OFF_EVS
- BASOP_SATURATE_WARNING_OFF_EVS
- signal[0] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow );
- BASOP_SATURATE_WARNING_ON_EVS
-
- BASOP_SATURATE_ERROR_ON_EVS
- L_sum = HP50_Mpy_32_32_fix( b2, mem[3] ); /* b2*x2 */
- L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b1, x2 ) ); /* b1*x1 */
- x1 = shr( signal[stride], prescale );
- L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x1 ) ); /* b2*x0 */
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[1], a2 ) ); /* y2*a2 */
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a1 ) ); /* y1*a1 */
-
- L_y1 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow );
- BASOP_SATURATE_ERROR_OFF_EVS
- BASOP_SATURATE_WARNING_OFF_EVS
- signal[stride] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow );
- BASOP_SATURATE_WARNING_ON_EVS
- move16();
-
- /* New we use a trick and toggle x1/x2 and L_y1/L_y2 to save a few cycles unrolling the loop by 2 */
- FOR( i = 2; i < lg; i += 2 )
- {
- /* y[i+0] = b2*x[i-2] + b1*x[i-1] + b2*x[i-0] + a2*y[i-2] + a1*y[i-1]; */
- BASOP_SATURATE_ERROR_ON_EVS
- L_sum = HP50_Mode2_Mpy_32_16_fix( b2, x2 );
- L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b1, x1 ) );
- x2 = shr( signal[i * stride], prescale );
- L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x2 ) );
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a2 ) );
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y1, a1 ) );
-
- L_y2 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow );
- BASOP_SATURATE_ERROR_OFF_EVS
- BASOP_SATURATE_WARNING_OFF_EVS
- signal[i_mult( i, stride )] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow );
- BASOP_SATURATE_WARNING_ON_EVS
- /* y[i+1] = b2*x[i-1] + b1*x[i-0] + b2*x[i+1] + a2*y[i-1] + a1*y[i+0]; */
- BASOP_SATURATE_ERROR_ON_EVS
- L_sum = HP50_Mode2_Mpy_32_16_fix( b2, x1 );
- L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b1, x2 ) );
- x1 = shr( signal[( i + 1 ) * stride], prescale );
- L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x1 ) );
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y1, a2 ) );
- L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a1 ) );
-
- L_y1 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow );
- BASOP_SATURATE_ERROR_OFF_EVS
- BASOP_SATURATE_WARNING_OFF_EVS
- signal[i_mult( add( i, 1 ), stride )] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow );
- BASOP_SATURATE_WARNING_ON_EVS
- move16();
- }
- /* update static filter memory from variables */
- mem[0] = L_y2;
- move32();
- mem[1] = L_y1;
- move32();
- mem[2] = L_deposit_h( x2 );
- move32();
- mem[3] = L_deposit_h( x1 );
- move32();
-
-
- return;
-}
-
-
-void hp20( Word16 signal[], /* i/o: signal to filter any */
- const Word16 stride, /* i : stride to be applied accessing signal */
- const Word16 lg, /* i : length of signal (integer) Q0 */
- Word32 mem[5], /* i/o: static filter memory with this layout: */
- /* mem[0]: y[-2] (32-bit) */
- /* mem[1]; y[-1] (32-bit) */
- /* mem[2]: x[-2] << 16 */
- /* mem[3]: x[-1] << 16 */
- /* Note: mem[0..3] need to be scaled per frame */
- /* mem[4]: states scale */
- const Word32 sFreq ) /* i : input sampling rate Q0 */
-{
- Word32 a1, b1, a2, b2;
- Word16 prescale, prescaleOld, diff;
-#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
-#endif
-
-
- prescale = getScaleFactor16( signal, lg );
- prescaleOld = extract_l( mem[4] );
- diff = norm_l( L_shl_sat( mem[2], prescaleOld ) );
- if ( mem[2] != 0 )
- {
- prescale = s_min( prescale, diff );
- }
- diff = norm_l( L_shl_o( mem[3], prescaleOld, &Overflow ) );
- if ( mem[3] != 0 )
- {
- prescale = s_min( prescale, diff );
- }
- /* Take into account the left shift performed into the loop + 1 bit headroom*/
- prescale = s_max( -12, sub( 1 + HP20_COEFF_SCALE, prescale ) );
- IF( prescale != prescaleOld )
- {
- diff = sub( prescale, prescaleOld );
- mem[0] = L_shr_o( mem[0], diff, &Overflow );
- move32();
- mem[1] = L_shr_o( mem[1], diff, &Overflow );
- move32();
- mem[2] = L_shr_o( mem[2], diff, &Overflow );
- move32();
- mem[3] = L_shr_o( mem[3], diff, &Overflow );
- move32();
- mem[4] = L_deposit_l( prescale );
- }
-
- IF( EQ_32( sFreq, 8000 ) )
- {
- /* hp filter 20Hz at 3dB for 8000 Hz input sampling rate
- [b,a] = butter(2, 20.0/4000.0, 'high');
- b = [0.988954248067140 -1.977908496134280 0.988954248067140]
- a = [1.000000000000000 -1.977786483776764 0.978030508491796]*/
- a1 = 1061816033l /* 1.977786483776764 Q29*/;
- move32();
- a2 = -525076131l /*-0.978030508491796 Q29*/;
- move32();
- b1 = -1061881538l /*-1.977908496134280 Q29*/;
- move32();
- b2 = 530940769l /* 0.988954248067140 Q29*/;
- move32();
- }
- ELSE IF( EQ_32( sFreq, 16000 ) )
- {
- /* hp filter 20Hz at 3dB for 16000KHz sampling rate
- [b,a] = butter(2, 20.0/8000.0, 'high');
- b = [0.994461788958195 -1.988923577916390 0.994461788958195]
- a = [1.000000000000000 -1.988892905899653 0.988954249933127] */
- a1 = 1067778748l /* 1.988892905899653 Q29*/;
- move32();
- a2 = -530940770l /*-0.988954249933127 Q29*/;
- move32();
- b1 = -1067795215l /*-1.988923577916390 Q29*/;
- move32();
- b2 = 533897608l /* 0.994461788958195 Q29*/;
- move32();
- }
- ELSE IF( EQ_32( sFreq, 32000 ) )
- {
- /* hp filter 20Hz at 3dB for 32000KHz sampling rate
- [b,a] = butter(2, 20.0/16000.0, 'high');
- b = [0.997227049904470 -1.994454099808940 0.997227049904470]
- a = [1.000000000000000 -1.994446410541927 0.994461789075954]*/
- a1 = 1070760263l /* 1.994446410541927 Q29*/;
- move32();
- a2 = -533897608l /*-0.994461789075954 Q29*/;
- move32();
- b1 = -1070764392l /*-1.994454099808940 Q29*/;
- move32();
- b2 = 535382196l /* 0.997227049904470 Q29*/;
- move32();
- }
- ELSE
- {
- assert( sFreq == 48000 );
- /* hp filter 20Hz at 3dB for 48000KHz sampling rate
- [b,a] = butter(2, 20.0/24000.0, 'high');
- b =[0.998150511190452 -1.996301022380904 0.998150511190452]
- a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/
- a1 = 1071754114l /* 1.996297601769122 Q29*/;
- move32();
- a2 = -534886875l /*-0.996304442992686 Q29*/;
- move32();
- b1 = -1071755951l /*-1.996301022380904 Q29*/;
- move32();
- b2 = 535877975l /* 0.998150511190452 Q29*/;
- move32();
- }
-
-
- filter_2nd_order( signal, stride, prescale, lg,
- mem, a1, a2, b1, b2 );
-
- return;
-}
-
-
-#ifdef HP20_FIX32_RECODING
-void hp20_fx_32(
- Word32 signal_fx[],
- const Word16 lg,
- Word32 mem_fx[],
- const Word32 Fs )
-{
- Word32 i;
- Word32 a1_fx, a2_fx, b1_fx, b2_fx;
- Word32 diff_pos, diff_neg;
- Flag Overflow = 0;
- Word16 prescale, prescaleOld, prescale_current_frame, diff;
-
- prescale = getScaleFactor32( signal_fx, lg );
- prescale_current_frame = s_min( 3, sub( 1 + HP20_COEFF_SCALE, prescale ) );
-
-
- prescaleOld = extract_l( mem_fx[4] );
-
- diff_pos = norm_l( L_shl_o( L_max( mem_fx[2], mem_fx[3] ), prescaleOld, &Overflow ) );
- diff_neg = norm_l( L_shl_o( L_min( mem_fx[2], mem_fx[3] ), prescaleOld, &Overflow ) );
-
- diff = L_max( diff_pos, diff_neg );
-
- IF( NE_16( diff, 0 ) )
- {
- prescale = s_min( prescale, diff );
- }
-
- prescale = s_min( 3, sub( 1 + HP20_COEFF_SCALE, prescale ) );
-
- diff = sub( prescale, prescaleOld );
- mem_fx[0] = L_shr_o( mem_fx[0], diff, &Overflow );
- move32();
- mem_fx[1] = L_shr_o( mem_fx[1], diff, &Overflow );
- move32();
- mem_fx[2] = L_shr_o( mem_fx[2], diff, &Overflow );
- move32();
- mem_fx[3] = L_shr_o( mem_fx[3], diff, &Overflow );
- move32();
- mem_fx[4] = L_deposit_l( prescale_current_frame );
- move32();
-
- IF( EQ_32( Fs, 8000 ) )
- {
- /* hp filter 20Hz at 3dB for 8000KHz input sampling rate
- [b,a] = butter(2, 20.0/4000.0, 'high');
- b = [0.988954248067140 -1.977908496134280 0.988954248067140]
- a =[1.000000000000000 -1.977786483776764 0.978030508491796]*/
- a1_fx = 1061816033l /* 1.977786483776764 Q29*/;
- a2_fx = -525076131l /*-0.978030508491796 Q29*/;
- b1_fx = -1061881538l /*-1.977908496134280 Q29*/;
- b2_fx = 530940769l /* 0.988954248067140 Q29*/;
- }
- ELSE IF( EQ_32( Fs, 16000 ) )
- {
- /* hp filter 20Hz at 3dB for 16000KHz sampling rate
- [b,a] = butter(2, 20.0/8000.0, 'high');
- b =[ 0.994461788958195 -1.988923577916390 0.994461788958195]
- a =[1.000000000000000 -1.988892905899653 0.988954249933127] */
- a1_fx = 1067778748l /* 1.988892905899653 Q29*/;
- a2_fx = -530940770l /*-0.988954249933127 Q29*/;
- b1_fx = -1067795215l /*-1.988923577916390 Q29*/;
- b2_fx = 533897608l /* 0.994461788958195 Q29*/;
- }
- ELSE IF( EQ_32( Fs, 32000 ) )
- {
- /* hp filter 20Hz at 3dB for 32000KHz sampling rate
- [b,a] = butter(2, 20.0/16000.0, 'high');
- b =[0.997227049904470 -1.994454099808940 0.997227049904470]
- a =[1.000000000000000 -1.994446410541927 0.994461789075954]*/
- a1_fx = 1070760263l /* 1.994446410541927 Q29*/;
- a2_fx = -533897608l /*-0.994461789075954 Q29*/;
- b1_fx = -1070764392l /*-1.994454099808940 Q29*/;
- b2_fx = 535382196l /* 0.997227049904470 Q29*/;
- }
- ELSE
- {
- /* hp filter 20Hz at 3dB for 48000KHz sampling rate
- [b,a] = butter(2, 20.0/24000.0, 'high');
- b =[ 0.998150511190452 -1.996301022380904 0.998150511190452]
- a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/
- a1_fx = 1071754114l /* 1.996297601769122 Q29*/;
- a2_fx = -534886875l /*-0.996304442992686 Q29*/;
- b1_fx = -1071755951l /*-1.996301022380904 Q29*/;
- b2_fx = 535877975l /* 0.998150511190452 Q29*/;
- }
- move32();
- move32();
- move32();
- move32();
- Word64 W_sum, W_y0, W_y1, W_y2;
- Word32 x0, x1, x2;
-
- W_sum = W_mult_32_32( b2_fx, mem_fx[2] ); /* b2*x2 */
- W_sum = W_mac_32_32( W_sum, b1_fx, mem_fx[3] ); /* b1*x1 */
- x2 = L_shr( signal_fx[0], prescale );
- W_sum = W_mac_32_32( W_sum, b2_fx, x2 ); /* b2*x0 */
- W_sum = W_mac_32_32( W_sum, mem_fx[0], a2_fx ); /* y2*a2 */
- W_sum = W_mac_32_32( W_sum, mem_fx[1], a1_fx ); /* y1*a1 */
- W_y2 = W_shl( W_sum, HP20_COEFF_SCALE );
- signal_fx[0] = W_extract_h( W_shl( W_y2, prescale ) );
- move32();
-
- W_sum = W_mult_32_32( b2_fx, mem_fx[3] ); /* b2*x2 */
- W_sum = W_mac_32_32( W_sum, b1_fx, x2 ); /* b1*x1 */
- x1 = L_shr( signal_fx[1], prescale );
- W_sum = W_mac_32_32( W_sum, b2_fx, x1 ); /* b2*x0 */
- W_sum = W_mac_32_32( W_sum, mem_fx[1], a2_fx ); /* y2*a2 */
- W_sum = W_mac_32_32( W_sum, W_extract_h( W_y2 ), a1_fx ); /* y1*a1 */
- W_y1 = W_shl( W_sum, HP20_COEFF_SCALE );
- signal_fx[1] = W_extract_h( W_shl( W_y1, prescale ) );
- move32();
-
- diff = sub( prescale_current_frame, prescale );
- W_y1 = W_shr( W_y1, diff );
- W_y2 = W_shr( W_y2, diff );
- x2 = L_shr( x2, diff );
- x1 = L_shr( x1, diff );
-
- FOR( i = 2; i < lg; i++ )
- {
- W_sum = W_mult_32_32( b2_fx, x2 ); /* b2*x2 */
- W_sum = W_mac_32_32( W_sum, b1_fx, x1 ); /* b1*x1 */
- x0 = L_shr( signal_fx[i], prescale_current_frame );
- W_sum = W_mac_32_32( W_sum, b2_fx, x0 ); /* b2*x0 */
- W_sum = W_mac_32_32( W_sum, W_extract_h( W_y2 ), a2_fx ); /* y2*a2 */
- W_sum = W_mac_32_32( W_sum, W_extract_h( W_y1 ), a1_fx ); /* y1*a1 */
- W_y0 = W_shl( W_sum, HP20_COEFF_SCALE );
-
- signal_fx[i] = W_extract_h( W_shl( W_y0, prescale_current_frame ) );
- move32();
-
- x2 = x1;
- x1 = x0;
- W_y2 = W_y1;
- W_y1 = W_y0;
-
- move32();
- move32();
- move64();
- move64();
- }
-
- mem_fx[0] = W_extract_h( W_y2 );
- mem_fx[1] = W_extract_h( W_y1 );
- mem_fx[2] = x2;
- mem_fx[3] = x1;
-
- move32();
- move32();
- move32();
- move32();
-
- return;
-}
-#else
-void hp20_fx_32(
- Word32 signal_fx[],
- const Word16 lg,
- Word32 mem_fx[],
- const Word32 Fs )
-{
- Word16 i;
- Word32 a1_fx, a2_fx, b1_fx, b2_fx;
- Word16 Qx0, Qx1, Qx2, Qy1, Qprev_y1, Qy2, Qprev_y2, Qmin;
- Word64 x0_fx64, x1_fx64, x2_fx64, y0_fx64, y1_fx64, y2_fx64, R1, R2, R3, R4, R5;
-
- IF( EQ_32( Fs, 8000 ) )
- {
- /* hp filter 20Hz at 3dB for 8000KHz input sampling rate
- [b,a] = butter(2, 20.0/4000.0, 'high');
- b = [0.988954248067140 -1.977908496134280 0.988954248067140]
- a =[1.000000000000000 -1.977786483776764 0.978030508491796]*/
- a1_fx = 1061816033l /* 1.977786483776764 Q29*/;
- a2_fx = -525076131l /*-0.978030508491796 Q29*/;
- b1_fx = -1061881538l /*-1.977908496134280 Q29*/;
- b2_fx = 530940769l /* 0.988954248067140 Q29*/;
- }
- ELSE IF( EQ_32( Fs, 16000 ) )
- {
- /* hp filter 20Hz at 3dB for 16000KHz sampling rate
- [b,a] = butter(2, 20.0/8000.0, 'high');
- b =[ 0.994461788958195 -1.988923577916390 0.994461788958195]
- a =[1.000000000000000 -1.988892905899653 0.988954249933127] */
- a1_fx = 1067778748l /* 1.988892905899653 Q29*/;
- a2_fx = -530940770l /*-0.988954249933127 Q29*/;
- b1_fx = -1067795215l /*-1.988923577916390 Q29*/;
- b2_fx = 533897608l /* 0.994461788958195 Q29*/;
- }
- ELSE IF( EQ_32( Fs, 32000 ) )
- {
- /* hp filter 20Hz at 3dB for 32000KHz sampling rate
- [b,a] = butter(2, 20.0/16000.0, 'high');
- b =[0.997227049904470 -1.994454099808940 0.997227049904470]
- a =[1.000000000000000 -1.994446410541927 0.994461789075954]*/
- a1_fx = 1070760263l /* 1.994446410541927 Q29*/;
- a2_fx = -533897608l /*-0.994461789075954 Q29*/;
- b1_fx = -1070764392l /*-1.994454099808940 Q29*/;
- b2_fx = 535382196l /* 0.997227049904470 Q29*/;
- }
- ELSE
- {
- /* hp filter 20Hz at 3dB for 48000KHz sampling rate
- [b,a] = butter(2, 20.0/24000.0, 'high');
- b =[ 0.998150511190452 -1.996301022380904 0.998150511190452]
- a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/
- a1_fx = 1071754114l /* 1.996297601769122 Q29*/;
- a2_fx = -534886875l /*-0.996304442992686 Q29*/;
- b1_fx = -1071755951l /*-1.996301022380904 Q29*/;
- b2_fx = 535877975l /* 0.998150511190452 Q29*/;
- }
- move32();
- move32();
- move32();
- move32();
-
- Qprev_y1 = extract_l( mem_fx[4] );
- Qprev_y2 = extract_l( mem_fx[5] );
- y1_fx64 = W_deposit32_l( mem_fx[0] );
- y2_fx64 = W_deposit32_l( mem_fx[1] );
- x0_fx64 = W_deposit32_l( mem_fx[2] );
- x1_fx64 = W_deposit32_l( mem_fx[3] );
-
- FOR( i = 0; i < lg; i++ )
- {
- x2_fx64 = x1_fx64;
- move64();
- x1_fx64 = x0_fx64;
- move64();
- x0_fx64 = W_deposit32_l( signal_fx[i] );
-
- Qy1 = W_norm( y1_fx64 );
- if ( y1_fx64 == 0 )
- {
- Qy1 = 62;
- move16();
- }
- Qy1 = sub( Qy1, 34 );
- R1 = W_mult0_32_32( W_extract_l( W_shl( y1_fx64, Qy1 ) ), a1_fx );
- Qy1 = add( Qy1, Qprev_y1 );
-
- Qy2 = W_norm( y2_fx64 );
- if ( y2_fx64 == 0 )
- {
- Qy2 = 62;
- move16();
- }
- Qy2 = sub( Qy2, 34 );
- R2 = W_mult0_32_32( W_extract_l( W_shl( y2_fx64, Qy2 ) ), a2_fx );
- Qy2 = add( Qy2, Qprev_y2 );
-
- Qx0 = W_norm( x0_fx64 );
- if ( x0_fx64 == 0 )
- {
- Qx0 = 62;
- move16();
- }
- Qx0 = sub( Qx0, 34 );
- R3 = W_mult0_32_32( W_extract_l( W_shl( x0_fx64, Qx0 ) ), b2_fx );
-
- Qx1 = W_norm( x1_fx64 );
- if ( x1_fx64 == 0 )
- {
- Qx1 = 62;
- move16();
- }
- Qx1 = sub( Qx1, 34 );
- R4 = W_mult0_32_32( W_extract_l( W_shl( x1_fx64, Qx1 ) ), b1_fx );
-
- Qx2 = W_norm( x2_fx64 );
- if ( x2_fx64 == 0 )
- {
- Qx2 = 62;
- move16();
- }
- Qx2 = sub( Qx2, 34 );
- R5 = W_mult0_32_32( W_extract_l( W_shl( x2_fx64, Qx2 ) ), b2_fx );
-
- Qmin = s_min( Qy1, Qy2 );
-
- y0_fx64 = W_add( W_shr( R1, sub( Qy1, Qmin ) ), W_shr( R2, sub( Qy2, Qmin ) ) );
-
- Qmin = s_min( Qmin, Qx0 );
- Qmin = s_min( Qmin, Qx1 );
- Qmin = s_min( Qmin, Qx2 );
-
- y0_fx64 = W_add( W_shr( y0_fx64, sub( s_min( Qy1, Qy2 ), Qmin ) ), W_add( W_shr( R3, sub( Qx0, Qmin ) ), W_add( W_shr( R4, sub( Qx1, Qmin ) ), W_shr( R5, sub( Qx2, Qmin ) ) ) ) );
-
- y0_fx64 = W_shr( y0_fx64, 29 );
-
- signal_fx[i] = W_extract_l( W_shr( y0_fx64, Qmin ) );
- move32();
- IF( signal_fx[i] < 0 )
- {
- signal_fx[i] = L_add( signal_fx[i], 1 );
- move32();
- }
-
- y2_fx64 = y1_fx64;
- y1_fx64 = y0_fx64;
- Qprev_y2 = Qprev_y1;
- Qprev_y1 = Qmin;
- move64();
- move64();
- move16();
- move16();
- }
-
- Qy1 = W_norm( y1_fx64 );
- test();
- IF( y1_fx64 != 0 && LT_16( Qy1, 32 ) )
- {
- y1_fx64 = W_shr( y1_fx64, sub( 32, Qy1 ) );
- Qprev_y1 = sub( Qprev_y1, sub( 32, Qy1 ) );
- }
-
- Qy2 = W_norm( y2_fx64 );
- test();
- IF( y2_fx64 != 0 && LT_16( Qy2, 32 ) )
- {
- y2_fx64 = W_shr( y2_fx64, sub( 32, Qy2 ) );
- Qprev_y2 = sub( Qprev_y2, sub( 32, Qy2 ) );
- }
-
- mem_fx[0] = W_extract_l( y1_fx64 );
- mem_fx[1] = W_extract_l( y2_fx64 );
- mem_fx[2] = W_extract_l( x0_fx64 );
- mem_fx[3] = W_extract_l( x1_fx64 );
- mem_fx[4] = Qprev_y1;
- mem_fx[5] = Qprev_y2;
- move32();
- move32();
- move32();
- move32();
- move32();
- move32();
-
- return;
-}
-#endif
diff --git a/lib_com/hp50_fx.c b/lib_com/hp50_fx.c
index 84bbf8b3c3c94aefd82d69344e4fa5d9362c0408..f5e7105cfcf9dfeebad0e4bff0d5a262cc8a7dd8 100644
--- a/lib_com/hp50_fx.c
+++ b/lib_com/hp50_fx.c
@@ -37,19 +37,8 @@
#include
#include
#include "options.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
-
-/*
- * hp20
- *
- * Function:
- * 2nd order high pass filter with nominal cut off frequency at 20 Hz.
- *
- * Returns:
- * void
- */
+#include "wmc_auto.h"
#define HP20_COEFF_SCALE ( 2 )
@@ -469,8 +458,14 @@ void hp20_fx_32(
{
Word16 i;
Word32 a1_fx, a2_fx, b1_fx, b2_fx;
+#ifdef OPT_STEREO_32KBPS_V1
+ Word16 Qy1, Qy2, Qmin;
+ Word64 y0_fx64, y1_fx64, y2_fx64;
+ Word32 x0, x1, x2;
+#else /* OPT_STEREO_32KBPS_V1 */
Word16 Qx0, Qx1, Qx2, Qy1, Qprev_y1, Qy2, Qprev_y2, Qmin;
Word64 x0_fx64, x1_fx64, x2_fx64, y0_fx64, y1_fx64, y2_fx64, R1, R2, R3, R4, R5;
+#endif /* OPT_STEREO_32KBPS_V1 */
IF( EQ_32( Fs, 8000 ) )
{
@@ -521,15 +516,64 @@ void hp20_fx_32(
move32();
move32();
+#ifdef OPT_STEREO_32KBPS_V1
+ y1_fx64 = W_add( W_deposit32_l( mem_fx[0] ), W_deposit32_h( mem_fx[1] ) );
+ y2_fx64 = W_add( W_deposit32_l( mem_fx[2] ), W_deposit32_h( mem_fx[3] ) );
+
+ x0 = mem_fx[4];
+ move32();
+ x1 = mem_fx[5];
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
Qprev_y1 = extract_l( mem_fx[4] );
Qprev_y2 = extract_l( mem_fx[5] );
y1_fx64 = W_deposit32_l( mem_fx[0] );
y2_fx64 = W_deposit32_l( mem_fx[1] );
x0_fx64 = W_deposit32_l( mem_fx[2] );
x1_fx64 = W_deposit32_l( mem_fx[3] );
+#endif /* OPT_STEREO_32KBPS_V1 */
FOR( i = 0; i < lg; i++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ x2 = x1;
+ move32();
+ x1 = x0;
+ move32();
+ x0 = signal_fx[i];
+ move32();
+
+ Qy1 = W_norm( y1_fx64 );
+ if ( y1_fx64 == 0 )
+ {
+ Qy1 = 62;
+ move16();
+ }
+
+ Qy2 = W_norm( y2_fx64 );
+ if ( y2_fx64 == 0 )
+ {
+ Qy2 = 62;
+ move16();
+ }
+
+ Qmin = s_min( Qy1, Qy2 );
+
+ Qmin = sub( Qmin, 34 );
+
+ y0_fx64 = W_mac_32_32( W_mult_32_32( W_shl_sat_l( y1_fx64, Qmin ), a1_fx ), W_shl_sat_l( y2_fx64, Qmin ), a2_fx ); // Qmin + Q29 + Q30 + 1
+
+ Word64 temp = W_mac_32_32( W_mac_32_32( W_mult_32_32( x2, b2_fx ), x1, b1_fx ), x0, b2_fx ); // Q30
+ Word64 y0_fx = W_shr( y0_fx64, add( Qmin, Q30 ) ); // Q30
+ y0_fx64 = W_add( temp, y0_fx ); // Q30
+ signal_fx[i] = W_shl_sat_l( y0_fx64, -Q30 );
+ move32();
+
+ y2_fx64 = y1_fx64;
+ move64();
+ y1_fx64 = y0_fx64;
+ move64();
+#else /* OPT_STEREO_32KBPS_V1 */
x2_fx64 = x1_fx64;
move64();
x1_fx64 = x0_fx64;
@@ -611,8 +655,17 @@ void hp20_fx_32(
move64();
move16();
move16();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
+#ifdef OPT_STEREO_32KBPS_V1
+ mem_fx[0] = W_extract_l( y1_fx64 );
+ mem_fx[1] = W_extract_h( y1_fx64 );
+ mem_fx[2] = W_extract_l( y2_fx64 );
+ mem_fx[3] = W_extract_h( y2_fx64 );
+ mem_fx[4] = x0;
+ mem_fx[5] = x1;
+#else /* OPT_STEREO_32KBPS_V1 */
Qy1 = W_norm( y1_fx64 );
test();
IF( y1_fx64 != 0 && LT_16( Qy1, 32 ) )
@@ -635,6 +688,8 @@ void hp20_fx_32(
mem_fx[3] = W_extract_l( x1_fx64 );
mem_fx[4] = Qprev_y1;
mem_fx[5] = Qprev_y2;
+#endif /* OPT_STEREO_32KBPS_V1 */
+
move32();
move32();
move32();
diff --git a/lib_com/hq2_core_com.c b/lib_com/hq2_core_com.c
index bc4edb8693cb17aed07ff08d218a7eaa169673ec..121dae06a1ef18c4cd878c09921758a9d0ced65e 100644
--- a/lib_com/hq2_core_com.c
+++ b/lib_com/hq2_core_com.c
@@ -39,7 +39,7 @@
#include
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "basop_util.h"
#include "basop_proto_func.h"
#include "wmc_auto.h"
diff --git a/lib_com/hq_conf.c b/lib_com/hq_conf.c
index c139a493c8601785881ef08bd5a5a781704d1955..90a256ceab3e43b00c51885fe3e3ac35efea1113 100644
--- a/lib_com/hq_conf.c
+++ b/lib_com/hq_conf.c
@@ -38,9 +38,8 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
void hq_configure_fx(
diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c
index 4426f85d98d0b79248d5308c349ecef0561ad8ad..cf3ce202e0f0951c92b3610319cb5e7db95146b8 100644
--- a/lib_com/hq_tools_fx.c
+++ b/lib_com/hq_tools_fx.c
@@ -39,7 +39,6 @@
#include "rom_com.h" /* Static table prototypes FIP version */
#include "stl.h" /* required for wmc_tool */
#include "prot_fx.h"
-#include "prot.h"
#include "ivas_prot_fx.h"
/*--------------------------------------------------------------------------*
diff --git a/lib_com/ifft_rel.c b/lib_com/ifft_rel.c
index 423eea46d7f8d5965fb9c002f3096d4d2efde2df..9e64a4e254f17bd36d456d3d45bf35d36612720d 100644
--- a/lib_com/ifft_rel.c
+++ b/lib_com/ifft_rel.c
@@ -36,10 +36,9 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
/*-----------------------------------------------------------------*
* Local constants
*-----------------------------------------------------------------*/
diff --git a/lib_com/int_lsp.c b/lib_com/int_lsp.c
index 0f673b8fd610188a6dc014914aaa54fac9ce713d..570e9ebd987527155d240e94341b7224aa876224 100644
--- a/lib_com/int_lsp.c
+++ b/lib_com/int_lsp.c
@@ -37,10 +37,9 @@
#include
#include "options.h"
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
void int_lsp_fx(
diff --git a/lib_com/interleave_spectrum.c b/lib_com/interleave_spectrum.c
index 745ee6ac3d7da541cf8d62ac6fc71e2386ed5f05..5c4c98e291e33db70a7fa6a8763926f963fe485c 100644
--- a/lib_com/interleave_spectrum.c
+++ b/lib_com/interleave_spectrum.c
@@ -37,10 +37,9 @@
#include
#include "options.h"
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/interpol.c b/lib_com/interpol.c
index 45021f1c274004c456b85e5eddbe8a84982f4d3c..a490a755269c9fa7d3f9bdeb440b60bf7f483253 100644
--- a/lib_com/interpol.c
+++ b/lib_com/interpol.c
@@ -36,10 +36,9 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "rom_com.h"
-#include "prot_fx.h"
#include "prot_fx_enc.h"
diff --git a/lib_com/ivas_agc_com_fx.c b/lib_com/ivas_agc_com_fx.c
index b2c09fa073e524dfbc82dcaa88db2e910746b719..94e6b222fcd0401e042f3f0409e435ba82ebc4a4 100644
--- a/lib_com/ivas_agc_com_fx.c
+++ b/lib_com/ivas_agc_com_fx.c
@@ -38,7 +38,7 @@
#include "ivas_prot_fx.h"
#include
#include "wmc_auto.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
/*------------------------------------------------------------------------------------------*
* Local constants
diff --git a/lib_com/ivas_arith.c b/lib_com/ivas_arith_fx.c
similarity index 99%
rename from lib_com/ivas_arith.c
rename to lib_com/ivas_arith_fx.c
index 2f729bbd4e6d4b9675349adb8ec2bcc998628734..006a31177873484eeb93f6aa14cd71f38c6b969f 100644
--- a/lib_com/ivas_arith.c
+++ b/lib_com/ivas_arith_fx.c
@@ -33,9 +33,8 @@
#include
#include "options.h"
#include "wmc_auto.h"
-#include "prot.h"
-#include "ivas_prot.h"
#include "prot_fx.h"
+#include "ivas_prot.h"
#include "ivas_prot_fx.h"
#include "stat_dec.h"
diff --git a/lib_com/ivas_avq_pos_reorder_com.c b/lib_com/ivas_avq_pos_reorder_com_fx.c
similarity index 99%
rename from lib_com/ivas_avq_pos_reorder_com.c
rename to lib_com/ivas_avq_pos_reorder_com_fx.c
index ac539b7879b99ccf2941f6768be01caba574fdbb..25f8be3ad2ae64b4b05bc88bfc19b22043377621 100644
--- a/lib_com/ivas_avq_pos_reorder_com.c
+++ b/lib_com/ivas_avq_pos_reorder_com_fx.c
@@ -32,7 +32,7 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
/*-----------------------------------------------------------------*
diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth_fx.c
similarity index 99%
rename from lib_com/ivas_cov_smooth.c
rename to lib_com/ivas_cov_smooth_fx.c
index 445ea8c78e22e5e04815372b1df63d22601dc3a8..acc0df8215a514ccf2033f6ee2b971879a52f73c 100644
--- a/lib_com/ivas_cov_smooth.c
+++ b/lib_com/ivas_cov_smooth_fx.c
@@ -35,7 +35,6 @@
#include "cnst.h"
#include "ivas_prot.h"
#include "wmc_auto.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com_fx.c
similarity index 99%
rename from lib_com/ivas_dirac_com.c
rename to lib_com/ivas_dirac_com_fx.c
index 557db9696924b28e7e610943125931ebb4c2d13c..9b60b2c5c9b963c93ca20b070ad2ab4951d1238c 100644
--- a/lib_com/ivas_dirac_com.c
+++ b/lib_com/ivas_dirac_com_fx.c
@@ -37,10 +37,9 @@
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "cnst.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com_fx.h"
diff --git a/lib_com/ivas_entropy_coder_common.c b/lib_com/ivas_entropy_coder_common_fx.c
similarity index 99%
rename from lib_com/ivas_entropy_coder_common.c
rename to lib_com/ivas_entropy_coder_common_fx.c
index d28828d6f4d20b163ab0e4a57faaf83391e359c8..99381d19aced0fb0422feb9c024141284b06471a 100644
--- a/lib_com/ivas_entropy_coder_common.c
+++ b/lib_com/ivas_entropy_coder_common_fx.c
@@ -35,7 +35,7 @@
#include "ivas_prot.h"
#include "ivas_rom_com.h"
#include "math.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer_fx.c
similarity index 99%
rename from lib_com/ivas_fb_mixer.c
rename to lib_com/ivas_fb_mixer_fx.c
index 498de0188e11b973567acde6d1771ffe56d3b866..883861024e23cf96e9d31b9bfd0048ddd5506078 100644
--- a/lib_com/ivas_fb_mixer.c
+++ b/lib_com/ivas_fb_mixer_fx.c
@@ -34,13 +34,12 @@
#include
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#include "ivas_rom_com_fx.h"
@@ -1289,7 +1288,7 @@ static ivas_error ivas_filterbank_setup_fx(
ivas_get_active_bins_fx( &pAll_bins_per_band, &pAll_bins_per_band_abs, &pAll_bins_start_offset, &pAll_bins_start_offset_abs, sampling_rate );
- IF( EQ_16( pCfg->fb_latency, NS2SA( sampling_rate, DELAY_FB_1_NS ) ) )
+ IF( EQ_16( pCfg->fb_latency, NS2SA_FX2( sampling_rate, DELAY_FB_1_NS ) ) )
{
pAll_fb_fr_fx[0] = ivas_fb_fr_12band_1ms_re_fx; // Q30
move32();
@@ -1478,7 +1477,7 @@ static ivas_error ivas_fb_mixer_get_window_fx(
error = IVAS_ERR_OK;
move32();
- IF( EQ_16( fade_len, NS2SA( sampling_rate, DELAY_FB_4_NS ) ) )
+ IF( EQ_16( fade_len, NS2SA_FX2( sampling_rate, DELAY_FB_4_NS ) ) )
{
SWITCH( sampling_rate )
{
@@ -1495,7 +1494,7 @@ static ivas_error ivas_fb_mixer_get_window_fx(
return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" );
}
}
- ELSE IF( EQ_16( fade_len, NS2SA( sampling_rate, DELAY_FB_1_NS ) ) )
+ ELSE IF( EQ_16( fade_len, NS2SA_FX2( sampling_rate, DELAY_FB_1_NS ) ) )
{
SWITCH( sampling_rate )
{
diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters_fx.c
similarity index 100%
rename from lib_com/ivas_filters.c
rename to lib_com/ivas_filters_fx.c
diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com_fx.c
similarity index 99%
rename from lib_com/ivas_ism_com.c
rename to lib_com/ivas_ism_com_fx.c
index 74e9641aaa290fb689cd3a0ceb4b414d024c05c5..f1201b06ca6952cf7a20f39173cd0af07e4714d2 100644
--- a/lib_com/ivas_ism_com.c
+++ b/lib_com/ivas_ism_com_fx.c
@@ -35,15 +35,13 @@
#include "cnst.h"
#include "ivas_cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_stat_com.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
-#define IVAS_FLOAT_FIXED_TO_BE_REMOVED
/*-----------------------------------------------------------------------*
* Local constants
diff --git a/lib_com/ivas_lfe_com.c b/lib_com/ivas_lfe_com_fx.c
similarity index 99%
rename from lib_com/ivas_lfe_com.c
rename to lib_com/ivas_lfe_com_fx.c
index 4d993d64f1b23234bb43c5b46800a632f92b1e2a..7464c41c2c47a4c1d7871f37ada1bcef1e8d1afa 100644
--- a/lib_com/ivas_lfe_com.c
+++ b/lib_com/ivas_lfe_com_fx.c
@@ -34,7 +34,7 @@
#include "math.h"
#include "options.h"
#include "ivas_stat_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
diff --git a/lib_com/ivas_limiter.c b/lib_com/ivas_limiter_fx.c
similarity index 99%
rename from lib_com/ivas_limiter.c
rename to lib_com/ivas_limiter_fx.c
index 479248160371a3d76af67111c80c523275a5a9a5..824e443a3a45228df99fd5995957d0310b96cee6 100644
--- a/lib_com/ivas_limiter.c
+++ b/lib_com/ivas_limiter_fx.c
@@ -33,7 +33,7 @@
#include
#include "options.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot_rend.h"
#include "ivas_rom_rend.h"
#include "ivas_rom_com.h"
diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com_fx.c
similarity index 99%
rename from lib_com/ivas_masa_com.c
rename to lib_com/ivas_masa_com_fx.c
index 35db926d0a60f6ac52e7e35bdaab20bac34de81c..fbe752aad277923102b1796d3c52f8bf9e301d19 100644
--- a/lib_com/ivas_masa_com.c
+++ b/lib_com/ivas_masa_com_fx.c
@@ -34,14 +34,13 @@
#include
#include "options.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "ivas_rom_com.h"
#include "ivas_stat_dec.h"
#include "wmc_auto.h"
#include "ivas_rom_com_fx.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/ivas_mc_com.c b/lib_com/ivas_mc_com_fx.c
similarity index 99%
rename from lib_com/ivas_mc_com.c
rename to lib_com/ivas_mc_com_fx.c
index 88d6c1b5ec8526ac9afc06ac569ae91fc1a4d4f2..62d623b830daf6924b4d4cfc0dd9468e6b2d1bd2 100644
--- a/lib_com/ivas_mc_com.c
+++ b/lib_com/ivas_mc_com_fx.c
@@ -34,7 +34,7 @@
#include
#include "options.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com_fx.c
similarity index 99%
rename from lib_com/ivas_mc_param_com.c
rename to lib_com/ivas_mc_param_com_fx.c
index d69da849a4450816e9bb35fe78facfc4c6e96833..a54abe7ab00d5ee98841b9788f28d2f467cce7b7 100644
--- a/lib_com/ivas_mc_param_com.c
+++ b/lib_com/ivas_mc_param_com_fx.c
@@ -35,7 +35,6 @@
#include
#include "options.h"
#include "ivas_cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_stat_com.h"
diff --git a/lib_com/ivas_mcmasa_com.c b/lib_com/ivas_mcmasa_com-fx.c
similarity index 100%
rename from lib_com/ivas_mcmasa_com.c
rename to lib_com/ivas_mcmasa_com-fx.c
diff --git a/lib_com/ivas_mct_com.c b/lib_com/ivas_mct_com_fx.c
similarity index 99%
rename from lib_com/ivas_mct_com.c
rename to lib_com/ivas_mct_com_fx.c
index b220d69a7651fbe29593101d76d17ad20d306022..1f3c58153b3b52bd4f97ef03ebea6305f01dfd14 100644
--- a/lib_com/ivas_mct_com.c
+++ b/lib_com/ivas_mct_com_fx.c
@@ -34,7 +34,7 @@
#include "options.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include
diff --git a/lib_com/ivas_mdct_core_com.c b/lib_com/ivas_mdct_core_com_fx.c
similarity index 99%
rename from lib_com/ivas_mdct_core_com.c
rename to lib_com/ivas_mdct_core_com_fx.c
index a5cfb8673abbf845b4938d48d8a14dd73cdc3b49..000f3992f1f1670bcd13f82edf20e8cd4adf3072 100644
--- a/lib_com/ivas_mdct_core_com.c
+++ b/lib_com/ivas_mdct_core_com_fx.c
@@ -34,9 +34,8 @@
#include "options.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
#include "ivas_prot_fx.h"
/*--------------------------------------------------------------------------*
diff --git a/lib_com/ivas_mdft_imdft.c b/lib_com/ivas_mdft_imdft_fx.c
similarity index 99%
rename from lib_com/ivas_mdft_imdft.c
rename to lib_com/ivas_mdft_imdft_fx.c
index 0f24fba817b5c3f3781266a7e8dc55033bfc01a0..b104443073a0d1bc311186a9a88deeee447b3c5b 100644
--- a/lib_com/ivas_mdft_imdft.c
+++ b/lib_com/ivas_mdft_imdft_fx.c
@@ -33,14 +33,13 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_rom_com.h"
#include
#include "wmc_auto.h"
#include
#include
-#include "prot_fx.h"
#include "debug.h"
#include "ivas_rom_com_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com_fx.c
similarity index 99%
rename from lib_com/ivas_omasa_com.c
rename to lib_com/ivas_omasa_com_fx.c
index eb230b224a57dd7e58e083a97dbef256d2577c19..ef63502854d78c30549ba6dbcae6ad0c7171478f 100644
--- a/lib_com/ivas_omasa_com.c
+++ b/lib_com/ivas_omasa_com_fx.c
@@ -35,11 +35,10 @@
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_rom_com.h"
#include "rom_com.h"
#include
-#include "prot_fx.h"
/*---------------------------------------------------------------
* Local constants
diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools_fx.c
similarity index 99%
rename from lib_com/ivas_pca_tools.c
rename to lib_com/ivas_pca_tools_fx.c
index 5689e81c01988cc20f6fb56879945270a0b03788..1e36c5e8e8bcf0f1ffb18a7e31a39c5ccfec1018 100644
--- a/lib_com/ivas_pca_tools.c
+++ b/lib_com/ivas_pca_tools_fx.c
@@ -38,7 +38,6 @@
#include
#include "ivas_rom_com.h"
#include "wmc_auto.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h
index 1e7c52df54b3b5241fc6eb4757b6d4a3fe7aca7a..8d5e4a29adfe509506287dfe2320982c39b81ec8 100644
--- a/lib_com/ivas_prot.h
+++ b/lib_com/ivas_prot.h
@@ -46,7 +46,6 @@
#include "ivas_stat_com.h"
#include "ivas_error_utils.h"
-#define IVAS_FLOAT_FIXED_TO_BE_REMOVED
/* clang-format off */
diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h
index fea1ff7e40023d0976e413fda31166a4935290a6..34794498717c02992d404ebc177c00f5da67e126 100644
--- a/lib_com/ivas_prot_fx.h
+++ b/lib_com/ivas_prot_fx.h
@@ -1315,6 +1315,20 @@ Word16 matrix_diag_product_fx(
Word32 *Z, /* o : resulting matrix after the matrix multiplication */
Word16 *Z_e );
+#ifdef OPT_BASOP_ADD_v1
+Word16 matrix_diag_product_fx_2(
+ const Word32 *X, /* i : left hand matrix Q31 - X_e*/
+ const Word16 X_e,
+ const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/
+ const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/
+ const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/
+ const Word32 *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements Q31 - Y_e*/
+ const Word16 *Y_e,
+ const Word16 entriesY, /* i : number of entries in the diagonal Q0*/
+ Word32 *Z, /* o : resulting matrix after the matrix multiplication Q31 - Z_e*/
+ Word16 *Z_e );
+#endif /* OPT_BASOP_ADD_v1 */
+
Word16 matrix_diag_product_fx_1(
const Word32 *X, /* i : left hand matrix */
const Word16 *X_e,
@@ -2955,7 +2969,7 @@ void stereo_dft_enc_write_BS_fx(
void stereo_dft_enc_res_fx(
STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */
- const Word32 *input_8k, /* i : input buffer sampled at 8kHz Q16 */
+ const Word32 *input_8k, /* i : input buffer sampled at 8kHz Q15 */
BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
Word16 *nb_bits, /* o : number of bits written */
const Word16 max_bits );
@@ -4761,6 +4775,8 @@ Word32 dot_product_cholesky_fx(
const Word32 *A, /* i : Cholesky matrix A */
const Word16 N /* i : vector & matrix size */
);
+
+#ifndef DOT_PROD_CHOLESKY_64BIT
Word32 dot_product_cholesky_fixed(
const Word32 *x, /* i : vector x */
const Word32 *A, /* i : Cholesky matrix A */
@@ -4768,6 +4784,13 @@ Word32 dot_product_cholesky_fixed(
const Word16 exp_x,
const Word16 exp_A,
Word16 *exp_sum );
+#else
+Word64 dot_product_cholesky_fixed(
+ const Word32 *x, /* i : vector x */
+ const Word32 *A, /* i : Cholesky matrix A */
+ const Word16 N /* i : vector & matrix size */
+);
+#endif
void v_mult_mat_fx(
Word32 *y_fx, /* o : the product x*A */
@@ -5912,8 +5935,7 @@ ivas_error ivas_compute_core_buffers_fx(
Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */
Word16 Q_old_inp_16k,
Word16 Q_r[2],
- Word16 *Q_new,
- Word16 downscale_buf_speech_enc_pe );
+ Word16 *Q_new );
ivas_error ivas_enc_fx(
Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com_fx.c
similarity index 99%
rename from lib_com/ivas_qmetadata_com.c
rename to lib_com/ivas_qmetadata_com_fx.c
index cbc67de00687671820538f9c8f4741fb28928c9d..79a585e8b121e286d4bde9ae24bed1c51660fd2c 100644
--- a/lib_com/ivas_qmetadata_com.c
+++ b/lib_com/ivas_qmetadata_com_fx.c
@@ -37,10 +37,9 @@
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "cnst.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com_fx.h"
diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com_fx.c
similarity index 99%
rename from lib_com/ivas_qspherical_com.c
rename to lib_com/ivas_qspherical_com_fx.c
index 8ef48be2e355803124f13020b97b562ca6d85615..5caa850cbbe9b7f96998ef990021fcf5c532bdff 100644
--- a/lib_com/ivas_qspherical_com.c
+++ b/lib_com/ivas_qspherical_com_fx.c
@@ -37,12 +37,10 @@
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "cnst.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
-#include "prot_fx.h"
#include "ivas_rom_com_fx.h"
diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config_fx.c
similarity index 99%
rename from lib_com/ivas_sba_config.c
rename to lib_com/ivas_sba_config_fx.c
index 94ceb8e3cb1b4a9ae6b0c252636f3641b96ad360..38785956c36f90dd1d6435f7a443217eee8284e7 100644
--- a/lib_com/ivas_sba_config.c
+++ b/lib_com/ivas_sba_config_fx.c
@@ -37,7 +37,7 @@
#include "cnst.h"
#include "ivas_cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_stat_com.h"
#include "ivas_rom_com.h"
diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c
index 788fb3c56568b76a9da297901c393c1ded640571..f35de8eb0037c6c2cc6bb174c0492e7d6fe528e6 100644
--- a/lib_com/ivas_sns_com_fx.c
+++ b/lib_com/ivas_sns_com_fx.c
@@ -33,7 +33,6 @@
#include
#include "options.h"
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "rom_com.h"
diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com_fx.c
similarity index 99%
rename from lib_com/ivas_spar_com.c
rename to lib_com/ivas_spar_com_fx.c
index 0ebae0de678aacc93972eab223eefd9cb9908cf3..6c80c189894f17f7dcdfa66aac5faacf74b05e84 100644
--- a/lib_com/ivas_spar_com.c
+++ b/lib_com/ivas_spar_com_fx.c
@@ -35,7 +35,6 @@
#include "options.h"
#include "basop_util.h"
#include "ivas_stat_com.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "rom_com.h"
@@ -4005,7 +4004,8 @@ void ivas_get_spar_md_from_dirac_enc_fx(
move16();
P_norm_fx[0] = 0;
move32();
- FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ )
+ Word16 len = s_max( 0, sub( foa_ch, ndm ) );
+ FOR( i = 0; i < len; i++ )
{
P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31
move32();
@@ -4015,7 +4015,8 @@ void ivas_get_spar_md_from_dirac_enc_fx(
P_norm_fx[1] = 0;
move32();
- FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ )
+ len = s_max( 0, sub( s_min( num_ch, hoa2_ch ), ndm ) );
+ FOR( ; i < len; i++ ) // max( 0, ( min( num_ch, hoa2_ch ) - ndm ) )
{
P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31
move32();
@@ -4032,8 +4033,8 @@ void ivas_get_spar_md_from_dirac_enc_fx(
}
P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31
move32();
-
- FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ )
+ len = s_max( 0, sub( foa_ch, ndm ) );
+ FOR( i = 0; i < len; i++ ) // i < max( 0, ( foa_ch - ndm ) )
{
idx = sub( remix_order[i + ndm], ndm );
P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31
@@ -4046,7 +4047,8 @@ void ivas_get_spar_md_from_dirac_enc_fx(
move32();
}
}
- FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ )
+ len = s_max( 0, sub( s_min( num_ch, hoa2_ch ), ndm ) );
+ FOR( ; i < len; i++ ) // i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) )
{
idx = sub( remix_order[i + ndm], ndm );
P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31
@@ -4058,6 +4060,7 @@ void ivas_get_spar_md_from_dirac_enc_fx(
move32();
}
}
+
FOR( ; i < ( num_ch - ndm ); i++ )
{
idx = sub( remix_order[i + ndm], ndm );
@@ -4223,7 +4226,8 @@ void ivas_get_spar_md_from_dirac_enc_fx(
/*normalize 2nd order*/
norm_fx = 0;
move32();
- FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ )
+ Word16 min_ch_order = s_min( hoa2_ch_order, num_ch_order );
+ FOR( ch = foa_ch; ch < min_ch_order; ch++ )
{
norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29
}
@@ -4244,7 +4248,8 @@ void ivas_get_spar_md_from_dirac_enc_fx(
move16();
}
norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30
- FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ )
+ min_ch_order = s_min( hoa2_ch_order, num_ch_order );
+ FOR( ch = foa_ch; ch < min_ch_order; ch++ )
{
IF( LT_32( norm_fx, EPSILON_FX_THR ) )
{
@@ -4558,7 +4563,8 @@ void ivas_get_spar_md_from_dirac_fx(
move16();
P_norm_fx[0] = 0;
move32();
- FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ )
+ Word16 len = s_max( 0, sub( foa_ch, ndm ) );
+ FOR( i = 0; i < len; i++ ) // i < max( 0, sub( foa_ch, ndm ) )
{
P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31
move32();
@@ -4568,7 +4574,8 @@ void ivas_get_spar_md_from_dirac_fx(
P_norm_fx[1] = 0;
move32();
- FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ )
+ len = s_max( 0, sub( s_min( num_ch, hoa2_ch ), ndm ) );
+ FOR( ; i < len; i++ ) // i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) )
{
P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31
move32();
@@ -4585,8 +4592,8 @@ void ivas_get_spar_md_from_dirac_fx(
}
P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31
move32();
-
- FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ )
+ len = s_max( 0, sub( foa_ch, ndm ) );
+ FOR( i = 0; i < len; i++ ) // i < max( 0, ( foa_ch - ndm ) )
{
idx = sub( remix_order[i + ndm], ndm );
P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31
@@ -4599,7 +4606,8 @@ void ivas_get_spar_md_from_dirac_fx(
move32();
}
}
- FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ )
+ len = s_max( 0, sub( s_min( num_ch, hoa2_ch ), ndm ) );
+ FOR( ; i < len; i++ ) // i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) )
{
idx = sub( remix_order[i + ndm], ndm );
P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31
@@ -4776,7 +4784,8 @@ void ivas_get_spar_md_from_dirac_fx(
/*normalize 2nd order*/
norm_fx = 0;
move32();
- FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ )
+ Word16 min_ch_order = s_min( hoa2_ch_order, num_ch_order );
+ FOR( ch = foa_ch; ch < min_ch_order; ch++ )
{
norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29
}
@@ -4797,7 +4806,8 @@ void ivas_get_spar_md_from_dirac_fx(
move16();
}
norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30
- FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ )
+ min_ch_order = s_min( hoa2_ch_order, num_ch_order );
+ FOR( ch = foa_ch; ch < min_ch_order; ch++ )
{
IF( LT_32( norm_fx, EPSILON_FX_THR ) )
{
diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util_fx.c
similarity index 99%
rename from lib_com/ivas_spar_com_quant_util.c
rename to lib_com/ivas_spar_com_quant_util_fx.c
index 0f0e003dd3be3d4b58764a2c74e899361f74f26c..8292de5c101c0517ec8239feeac508dc06e78bbc 100644
--- a/lib_com/ivas_spar_com_quant_util.c
+++ b/lib_com/ivas_spar_com_quant_util_fx.c
@@ -33,7 +33,6 @@
#include
#include "options.h"
#include "math.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_rom_com.h"
diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com_fx.c
similarity index 99%
rename from lib_com/ivas_stereo_dft_com.c
rename to lib_com/ivas_stereo_dft_com_fx.c
index 1157fffcf9664bf918466201103087f011585b21..80e64c0ccc4a54e4f984314164b89fb0b329b6d3 100644
--- a/lib_com/ivas_stereo_dft_com.c
+++ b/lib_com/ivas_stereo_dft_com_fx.c
@@ -36,7 +36,7 @@
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "cnst.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/ivas_stereo_eclvq_com_fx.c b/lib_com/ivas_stereo_eclvq_com_fx.c
index b4fb6642953e1a7d7e2a713eaf572950992addf9..d0ffff39ce3b743b02529abcc2bef03b9c8d6234 100644
--- a/lib_com/ivas_stereo_eclvq_com_fx.c
+++ b/lib_com/ivas_stereo_eclvq_com_fx.c
@@ -37,7 +37,7 @@
#include "ivas_prot_fx.h"
#include "ivas_cnst.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
/*---------------------------------------------------------------
diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c
index 78a3c90caa265dec0fdbca7344d3d390b86763a2..9aa880842290c9e374ff0b58a8a0335102e6490d 100644
--- a/lib_com/ivas_stereo_ica_com_fx.c
+++ b/lib_com/ivas_stereo_ica_com_fx.c
@@ -36,7 +36,6 @@
#include "options.h"
#include "cnst.h"
#include "ivas_cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "wmc_auto.h"
diff --git a/lib_com/ivas_stereo_mdct_bands_com.c b/lib_com/ivas_stereo_mdct_bands_com_fx.c
similarity index 99%
rename from lib_com/ivas_stereo_mdct_bands_com.c
rename to lib_com/ivas_stereo_mdct_bands_com_fx.c
index b1750fd16a3148fa01e314412e5ae620b41c687f..c21abcf8ca8aeff3f5a3461c26bd4634de435371 100644
--- a/lib_com/ivas_stereo_mdct_bands_com.c
+++ b/lib_com/ivas_stereo_mdct_bands_com_fx.c
@@ -37,9 +37,8 @@
#include "ivas_rom_com.h"
#include "ivas_prot.h"
#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
#include "ivas_prot_fx.h"
/*-------------------------------------------------------------------*
diff --git a/lib_com/ivas_stereo_mdct_stereo_com.c b/lib_com/ivas_stereo_mdct_stereo_com_fx.c
similarity index 100%
rename from lib_com/ivas_stereo_mdct_stereo_com.c
rename to lib_com/ivas_stereo_mdct_stereo_com_fx.c
diff --git a/lib_com/ivas_stereo_psychlpc_com.c b/lib_com/ivas_stereo_psychlpc_com_fx.c
similarity index 99%
rename from lib_com/ivas_stereo_psychlpc_com.c
rename to lib_com/ivas_stereo_psychlpc_com_fx.c
index 996b262db669270cf1f79828cfc99cd04d902c7c..cb3c39df2ae68c173550b31bd7e108e5532b83e8 100644
--- a/lib_com/ivas_stereo_psychlpc_com.c
+++ b/lib_com/ivas_stereo_psychlpc_com_fx.c
@@ -34,7 +34,7 @@
#include "options.h"
#include "ivas_rom_com.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "wmc_auto.h"
#include
diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc_fx.c
similarity index 99%
rename from lib_com/ivas_stereo_td_bit_alloc.c
rename to lib_com/ivas_stereo_td_bit_alloc_fx.c
index 14ab8131e196032a592316911b5a25ce4a34df8c..9074473d730ae31df6e5ddbbe03dfd6f75f247a6 100644
--- a/lib_com/ivas_stereo_td_bit_alloc.c
+++ b/lib_com/ivas_stereo_td_bit_alloc_fx.c
@@ -38,9 +38,8 @@
#include "ivas_prot.h"
#include "ivas_rom_com.h"
#include "ivas_cnst.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com_fx.h"
diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools_fx.c
similarity index 86%
rename from lib_com/ivas_tools.c
rename to lib_com/ivas_tools_fx.c
index ec3c30723a14064891ab567e01b2f2dcdb4fdf9a..e460637f77247ee40b3ce977e3744b63c9352e80 100644
--- a/lib_com/ivas_tools.c
+++ b/lib_com/ivas_tools_fx.c
@@ -34,11 +34,10 @@
#include
#include "options.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "wmc_auto.h"
#include "ivas_rom_com.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#define ANGLE_90_DEG_Q22 377487360
@@ -606,6 +605,7 @@ void v_sub32_fx(
* Therefore, S=A*A' where A is upper triangular matrix of size (m*m+m)/2 (zeros ommitted, column-wise)
*---------------------------------------------------------------------*/
+#ifndef DOT_PROD_CHOLESKY_64BIT
/*! r: the dot product x'*A*A'*x */
Word32 dot_product_cholesky_fixed(
const Word32 *x, /* i : vector x Q31 - exp_x*/
@@ -642,6 +642,44 @@ Word32 dot_product_cholesky_fixed(
return suma;
}
+#else
+/*! r: the dot product x'*A*A'*x */
+Word64 dot_product_cholesky_fixed(
+ const Word32 *x, /* i : vector x Q31 - exp_x*/
+ const Word32 *A, /* i : Cholesky matrix A Q31 - exp_A*/
+ const Word16 N /* i : vector & matrix size Q0*/
+)
+{
+ Word16 i, j;
+ Word64 suma, tmp_sum;
+ Word32 mul;
+ Word32 tmp;
+ const Word32 *pt_x, *pt_A;
+ pt_A = A;
+ suma = 0;
+ move64();
+
+ FOR( i = 0; i < N; i++ )
+ {
+ tmp_sum = 0;
+ move32();
+ pt_x = x;
+
+ FOR( j = 0; j <= i; j++ )
+ {
+ mul = Mpy_32_32( *pt_x++, *pt_A++ );
+ tmp_sum = W_add( tmp_sum, W_deposit32_l( mul ) );
+ }
+
+ tmp_sum = W_shr( tmp_sum, 4 ); // to make sure that the tmp_sum will not overflow
+ tmp = W_extract_l( tmp_sum );
+ suma = W_mac_32_32( suma, tmp, tmp );
+ }
+
+ return suma;
+}
+#endif
+
void v_mult_mat_fixed(
Word32 *y, /* o : the product x*A Qx - guardbits*/
const Word32 *x, /* i : vector x Qx*/
@@ -941,7 +979,9 @@ Word16 matrix_product_mant_exp_fx(
Word16 out_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
Word16 *Zp_fx_e = out_e;
Word16 row, col;
+#ifndef OPT_BASOP_ADD_v1
Word16 x_idx, y_idx;
+#endif /* OPT_BASOP_ADD_v1 */
Word64 temp;
Word16 temp_e;
Word16 prod_e = add( X_fx_e, Y_fx_e );
@@ -968,9 +1008,13 @@ Word16 matrix_product_mant_exp_fx(
FOR( k = 0; k < rowsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ temp = W_mac_32_32( temp, X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ); // X_fx_e + Y_fx_e
+#else /* OPT_BASOP_ADD_v1 */
x_idx = k + i * rowsX;
y_idx = k + j * rowsY;
temp = W_mac_32_32( temp, X_fx[x_idx], Y_fx[y_idx] ); // X_fx_e + Y_fx_e
+#endif /* OPT_BASOP_ADD_v1 */
}
/* Maximize accumulated value to 32-bit */
temp_e = W_norm( temp );
@@ -1008,9 +1052,13 @@ Word16 matrix_product_mant_exp_fx(
move64();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ temp = W_mac_32_32( temp, X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ); // X_fx_e + Y_fx_e
+#else /* OPT_BASOP_ADD_v1 */
x_idx = i + k * rowsX;
y_idx = j + k * rowsY;
temp = W_mac_32_32( temp, X_fx[x_idx], Y_fx[y_idx] ); // X_fx_e + Y_fx_e
+#endif /* OPT_BASOP_ADD_v1 */
}
/* Maximize accumulated value to 32-bit */
temp_e = W_norm( temp );
@@ -1048,9 +1096,13 @@ Word16 matrix_product_mant_exp_fx(
move64();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ temp = W_mac_32_32( temp, X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ); // X_fx_e + Y_fx_e
+#else /* OPT_BASOP_ADD_v1 */
x_idx = k + i * rowsX;
y_idx = j + k * rowsY;
temp = W_mac_32_32( temp, X_fx[x_idx], Y_fx[y_idx] ); // X_fx_e + Y_fx_e
+#endif /* OPT_BASOP_ADD_v1 */
}
/* Maximize accumulated value to 32-bit */
temp_e = W_norm( temp );
@@ -1089,9 +1141,13 @@ Word16 matrix_product_mant_exp_fx(
move64();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ temp = W_mac_32_32( temp, X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ); // X_fx_e + Y_fx_e
+#else /* OPT_BASOP_ADD_v1 */
x_idx = i + k * rowsX;
y_idx = k + j * rowsY;
- temp = W_mac_32_32( temp, X_fx[x_idx], Y_fx[y_idx] ); // X_fx_e + Y_fx_e
+ temp = W_mac_32_32( temp, X_fx[x_idx], Y_fx[y_idx] ); // X_fx_e + Y_fx_e
+#endif /* OPT_BASOP_ADD_v1 */
}
/* Maximize accumulated value to 32-bit */
temp_e = W_norm( temp );
@@ -1149,7 +1205,9 @@ Word16 matrix_product_fx(
)
{
Word16 i, j, k;
+#ifndef OPT_BASOP_ADD_v1
Word16 x_idx, y_idx;
+#endif /* OPT_BASOP_ADD_v1 */
Word32 *Zp_fx = Z_fx;
/* Processing */
@@ -1170,9 +1228,13 @@ Word16 matrix_product_fx(
move32();
FOR( k = 0; k < rowsX; ++k )
{
- x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
- y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
- ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
+#ifdef OPT_BASOP_ADD_v1
+ ( *Zp_fx ) = Madd_32_32( *Zp_fx, X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ); /*Qx + Qy - 31*/
+#else /* OPT_BASOP_ADD_v1 */
+ x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
+ y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
+ ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
}
Zp_fx++;
@@ -1193,9 +1255,13 @@ Word16 matrix_product_fx(
move32();
FOR( k = 0; k < colsX; ++k )
{
- x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/
- y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
- ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
+#ifdef OPT_BASOP_ADD_v1
+ ( *Zp_fx ) = Madd_32_32( *Zp_fx, X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ); /*Qx + Qy - 31*/
+#else /* OPT_BASOP_ADD_v1 */
+ x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/
+ y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
+ ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
}
Zp_fx++;
@@ -1216,9 +1282,13 @@ Word16 matrix_product_fx(
move32();
FOR( k = 0; k < colsX; ++k )
{
- x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
- y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
- ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
+#ifdef OPT_BASOP_ADD_v1
+ ( *Zp_fx ) = Madd_32_32( *Zp_fx, X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ); /*Qx + Qy - 31*/
+#else /* OPT_BASOP_ADD_v1 */
+ x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
+ y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
+ ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
}
@@ -1241,9 +1311,13 @@ Word16 matrix_product_fx(
move32();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ ( *Zp_fx ) = L_add_sat( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); /*Qx + Qy - 31*/
+#else /* OPT_BASOP_ADD_v1 */
x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/
y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
( *Zp_fx ) = L_add_sat( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
+#endif /* OPT_BASOP_ADD_v1 */
// TODO: overflow of Z_fx to be checked
move32();
}
@@ -1268,7 +1342,9 @@ Word16 matrix_product_q30_fx(
)
{
Word16 i, j, k;
+#ifndef OPT_BASOP_ADD_v1
Word16 x_idx, y_idx;
+#endif /* OPT_BASOP_ADD_v1 */
Word32 *Zp_fx = Z_fx;
Word64 W_tmp;
@@ -1291,10 +1367,14 @@ Word16 matrix_product_q30_fx(
move64();
FOR( k = 0; k < rowsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); // Q56
+#else /* OPT_BASOP_ADD_v1 */
//( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) );
x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56
+#endif /* OPT_BASOP_ADD_v1 */
}
W_tmp = W_shl( W_tmp, 6 ); /*Q62*/
( *Zp_fx ) = W_round64_L( W_tmp ); /*Q30*/
@@ -1318,10 +1398,14 @@ Word16 matrix_product_q30_fx(
move64();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); // Q56
+#else /* OPT_BASOP_ADD_v1 */
//( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) );
x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/
y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56
+#endif /* OPT_BASOP_ADD_v1 */
}
W_tmp = W_shl( W_tmp, 6 ); /*Q62*/
( *Zp_fx ) = W_round64_L( W_tmp ); /*Q30*/
@@ -1345,9 +1429,11 @@ Word16 matrix_product_q30_fx(
move64();
FOR( k = 0; k < colsX; ++k )
{
+#ifndef OPT_BASOP_ADD_v1
//( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) );
x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
+#endif /* OPT_BASOP_ADD_v1 */
W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); // Q56
}
@@ -1374,10 +1460,14 @@ Word16 matrix_product_q30_fx(
move64();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); // Q56
+#else /* OPT_BASOP_ADD_v1 */
//( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) );
x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/
y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56
+#endif /* OPT_BASOP_ADD_v1 */
}
W_tmp = W_shl( W_tmp, 6 ); /*Q62*/
( *Zp_fx ) = W_round64_L( W_tmp ); /*Q30*/
@@ -1410,7 +1500,9 @@ Word16 matrix_product_mant_exp(
Word16 *Zp_e = Z_e;
Word32 L_tmp;
Word16 tmp_e;
+#ifndef OPT_BASOP_ADD_v1
Word16 x_idx, y_idx;
+#endif /* OPT_BASOP_ADD_v1 */
/* Processing */
test();
@@ -1432,11 +1524,16 @@ Word16 matrix_product_mant_exp(
move16();
FOR( k = 0; k < rowsX; ++k )
{
- x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
- y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
+#ifdef OPT_BASOP_ADD_v1
+ L_tmp = Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ); /*Q31 - (X_e + Y_e)*/
+ tmp_e = add( X_e[k + i * rowsX], Y_e[k + j * rowsY] );
+#else /* OPT_BASOP_ADD_v1 */
+ x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
+ y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
//( *Zp ) += X[k + i * rowsX] * Y[k + j * rowsY];
L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Q31 - (X_e + Y_e)*/
tmp_e = add( X_e[x_idx], Y_e[y_idx] );
+#endif /* OPT_BASOP_ADD_v1 */
( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e );
move32();
@@ -1464,11 +1561,16 @@ Word16 matrix_product_mant_exp(
move16();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ L_tmp = Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ); /*Q31 - (X_e + Y_e)*/
+ tmp_e = add( X_e[i + k * rowsX], Y_e[j + k * rowsY] );
+#else /* OPT_BASOP_ADD_v1 */
x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/
y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
//( *Zp ) += X_fx[i + k * rowsX] * Y_fx[j + k * rowsY];
L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Q31 - (X_e + Y_e)*/
tmp_e = add( X_e[x_idx], Y_e[y_idx] );
+#endif /* OPT_BASOP_ADD_v1 */
( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e );
( *Zp_e ) = tmp_e;
@@ -1495,11 +1597,16 @@ Word16 matrix_product_mant_exp(
move16();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ L_tmp = Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ); /*Q31 - (X_e + Y_e)*/
+ tmp_e = add( X_e[k + i * rowsX], Y_e[j + k * rowsY] );
+#else /* OPT_BASOP_ADD_v1 */
x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/
y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
//( *Zp ) += X_fx[k + i * rowsX] * Y_fx[j + k * rowsY];
L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Q31 - (X_e + Y_e)*/
tmp_e = add( X_e[x_idx], Y_e[y_idx] );
+#endif /* OPT_BASOP_ADD_v1 */
( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e );
move32();
@@ -1529,11 +1636,16 @@ Word16 matrix_product_mant_exp(
move16();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ L_tmp = Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ); /*Q31 - (X_e + Y_e)*/
+ tmp_e = add( X_e[i + k * rowsX], Y_e[k + j * rowsY] );
+#else /* OPT_BASOP_ADD_v1 */
x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/
y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
//( *Zp ) += X_fx[i + k * rowsX] * Y_fx[k + j * rowsY];
L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Q31 - (X_e + Y_e)*/
tmp_e = add( X_e[x_idx], Y_e[y_idx] );
+#endif /* OPT_BASOP_ADD_v1 */
( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e );
move32();
@@ -1564,7 +1676,9 @@ Word16 matrix_diag_product_fx(
{
Word16 i, j;
Word32 *Zp = Z;
+#ifndef OPT_BASOP_ADD_v1
Word16 tmp;
+#endif /* OPT_BASOP_ADD_v1 */
/* Processing */
IF( EQ_16( transpX, 1 ) ) /* We use X transpose */
@@ -1577,8 +1691,12 @@ Word16 matrix_diag_product_fx(
{
FOR( i = 0; i < colsX; ++i )
{
+#ifdef OPT_BASOP_ADD_v1
+ *( Zp ) = Mpy_32_32( X[j + i * rowsX], Y[j] ); /*Q31 - (X_e + Y_e)*/
+#else /* OPT_BASOP_ADD_v1 */
tmp = add( j, imult1616( i, rowsX ) );
- *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/
+ *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
Zp++;
}
@@ -1609,6 +1727,100 @@ Word16 matrix_diag_product_fx(
return EXIT_SUCCESS;
}
+#ifdef OPT_BASOP_ADD_v1
+Word16 matrix_diag_product_fx_2(
+ const Word32 *X, /* i : left hand matrix Q31 - X_e*/
+ const Word16 X_e,
+ const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/
+ const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/
+ const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/
+ const Word32 *Y, /* i : right hand diagonal matrix as vector containing the diagonal elements Q31 - Y_e*/
+ const Word16 *Y_e,
+ const Word16 entriesY, /* i : number of entries in the diagonal Q0*/
+ Word32 *Z, /* o : resulting matrix after the matrix multiplication Q31 - Z_e*/
+ Word16 *Z_e )
+{
+ Word16 i, j;
+ Word32 *Zp = Z;
+ Word16 *Z_ep = Z_e;
+ Word16 tmp;
+ Word16 max_exp = -31;
+ move16();
+
+ /* Processing */
+ IF( EQ_16( transpX, 1 ) ) /* We use X transpose */
+ {
+ IF( NE_16( rowsX, entriesY ) )
+ {
+ return EXIT_FAILURE;
+ }
+ FOR( j = 0; j < entriesY; ++j )
+ {
+ FOR( i = 0; i < colsX; ++i )
+ {
+ tmp = j + i * rowsX; /*Q0*/
+ *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/
+ move32();
+ Zp++;
+ *( Z_ep ) = add( X_e, Y_e[j] );
+ move16();
+ max_exp = s_max( max_exp, *Z_ep ); // Find the max exp
+ Z_ep++;
+ }
+ }
+
+ Zp = Z;
+ Z_ep = Z_e;
+ FOR( j = 0; j < entriesY; ++j )
+ {
+ FOR( i = 0; i < colsX; ++i )
+ {
+ *Zp = L_shr( *Zp, sub( max_exp, *Z_ep ) );
+ *Z_ep = max_exp;
+ Zp++;
+ Z_ep++;
+ }
+ }
+ }
+ ELSE /* Regular case */
+ {
+ IF( NE_16( colsX, entriesY ) )
+ {
+ return EXIT_FAILURE;
+ }
+
+ FOR( j = 0; j < entriesY; ++j )
+ {
+ FOR( i = 0; i < rowsX; ++i )
+ {
+ *( Zp ) = Mpy_32_32( *( X ), Y[j] ); /*Q31 - (X_e + Y_e)*/
+ move32();
+ Zp++;
+ *( Z_ep ) = add( X_e, Y_e[j] );
+ move16();
+ max_exp = s_max( max_exp, *Z_ep ); // Find the max exp
+ Z_ep++;
+ X++;
+ }
+ }
+ Zp = Z;
+ Z_ep = Z_e;
+ FOR( j = 0; j < entriesY; ++j )
+ {
+ FOR( i = 0; i < rowsX; ++i )
+ {
+ *Zp = L_shr( *Zp, sub( max_exp, *Z_ep ) );
+ *Z_ep = max_exp;
+ Zp++;
+ Z_ep++;
+ }
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+#endif /* OPT_BASOP_ADD_v1 */
+
Word16 matrix_diag_product_fx_1(
const Word32 *X, /* i : left hand matrix Q31 - X_e*/
const Word16 *X_e,
@@ -1624,7 +1836,9 @@ Word16 matrix_diag_product_fx_1(
Word16 i, j;
Word32 *Zp = Z;
Word16 *Z_ep = Z_e;
+#ifndef OPT_BASOP_ADD_v1
Word16 tmp;
+#endif /* OPT_BASOP_ADD_v1 */
/* Processing */
IF( EQ_16( transpX, 1 ) ) /* We use X transpose */
@@ -1637,11 +1851,19 @@ Word16 matrix_diag_product_fx_1(
{
FOR( i = 0; i < colsX; ++i )
{
+#ifdef OPT_BASOP_ADD_v1
+ *( Zp ) = Mpy_32_32( X[j + i * rowsX], Y[j] ); /*Q31 - (X_e + Y_e)*/
+#else /* OPT_BASOP_ADD_v1 */
tmp = add( j, imult1616( i, rowsX ) ); /*Q0*/
*( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
Zp++;
+#ifdef OPT_BASOP_ADD_v1
+ *( Z_ep ) = add( X_e[j + i * rowsX], Y_e[j] );
+#else /* OPT_BASOP_ADD_v1 */
*( Z_ep ) = add( X_e[tmp], Y_e[j] );
+#endif /* OPT_BASOP_ADD_v1 */
move16();
Z_ep++;
}
@@ -1687,7 +1909,9 @@ Word16 diag_matrix_product_fx(
{
Word16 i, j;
Word32 *Zp = Z;
+#ifndef OPT_BASOP_ADD_v1
Word16 tmp;
+#endif /* OPT_BASOP_ADD_v1 */
/* Processing */
IF( EQ_16( transpX, 1 ) ) /* We use X transpose */
@@ -1700,8 +1924,12 @@ Word16 diag_matrix_product_fx(
{
FOR( j = 0; j < entriesY; ++j )
{
- tmp = add( i, imult1616( j, rowsX ) ); /*Q0*/
- *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/
+#ifdef OPT_BASOP_ADD_v1
+ *( Zp ) = Mpy_32_32( X[i + j * rowsX], Y[j] ); /*Q31 - (X_e + Y_e)*/
+#else /* OPT_BASOP_ADD_v1 */
+ tmp = add( i, imult1616( j, rowsX ) ); /*Q0*/
+ *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); /*Q31 - (X_e + Y_e)*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
Zp++;
}
@@ -1747,7 +1975,9 @@ Word16 matrix_product_diag_fx(
{
Word16 j, k;
Word32 *Zp = Z;
+#ifndef OPT_BASOP_ADD_v1
Word16 y_idx, x_idx;
+#endif /* OPT_BASOP_ADD_v1 */
/* Processing */
test();
@@ -1766,9 +1996,13 @@ Word16 matrix_product_diag_fx(
move32();
FOR( k = 0; k < rowsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ ( *Zp ) = Madd_32_32( ( *Zp ), X[k + j * rowsX], Y[k + j * rowsY] ); /*Q31 - (X_e + Y_e)*/
+#else /* OPT_BASOP_ADD_v1 */
x_idx = add( k, imult1616( j, rowsX ) ); /*Q0*/
y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); /*Q31 - (X_e + Y_e)*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
}
Zp++;
@@ -1786,9 +2020,13 @@ Word16 matrix_product_diag_fx(
move32();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ ( *Zp ) = Madd_32_32( ( *Zp ), X[j + k * rowsX], Y[j + k * rowsY] ); /*Q31 - (X_e + Y_e)*/
+#else /* OPT_BASOP_ADD_v1 */
x_idx = add( j, imult1616( k, rowsX ) ); /*Q0*/
y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); /*Q31 - (X_e + Y_e)*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
}
Zp++;
@@ -1808,9 +2046,13 @@ Word16 matrix_product_diag_fx(
move32();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ ( *Zp ) = Madd_32_32( ( *Zp ), X[k + j * rowsX], Y[j + k * rowsY] ); /*Q31 - (X_e + Y_e)*/
+#else /* OPT_BASOP_ADD_v1 */
x_idx = add( k, imult1616( j, rowsX ) ); /*Q0*/
y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/
( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); /*Q31 - (X_e + Y_e)*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
}
@@ -1830,9 +2072,13 @@ Word16 matrix_product_diag_fx(
move32();
FOR( k = 0; k < colsX; ++k )
{
+#ifdef OPT_BASOP_ADD_v1
+ ( *Zp ) = Madd_32_32( ( *Zp ), X[j + k * rowsX], Y[k + j * rowsY] ); /*Q31 - (X_e + Y_e)*/
+#else /* OPT_BASOP_ADD_v1 */
x_idx = add( j, imult1616( k, rowsX ) ); /*Q0*/
y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/
( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); /*Q31 - (X_e + Y_e)*/
+#endif /* OPT_BASOP_ADD_v1 */
move32();
}
Zp++;
diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det_fx.c
similarity index 99%
rename from lib_com/ivas_transient_det.c
rename to lib_com/ivas_transient_det_fx.c
index b5ea507eb4065efc85019a44e0eb8bc226428e45..97025b46f7330ed8f861efeaa3c2815e2cd4bd30 100644
--- a/lib_com/ivas_transient_det.c
+++ b/lib_com/ivas_transient_det_fx.c
@@ -34,11 +34,10 @@
#include "options.h"
#include "math.h"
#include "wmc_auto.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#include "ivas_stat_com.h"
/*------------------------------------------------------------------------------------------*
diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c
index e0871fa70124f1d3479f0d1801c8e71c503ce419..9fb2872711d553565e75f883d9ddeafaef19cd40 100644
--- a/lib_com/lag_wind.c
+++ b/lib_com/lag_wind.c
@@ -37,7 +37,6 @@
#include
#include
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#include "cnst.h"
#include "rom_com.h"
diff --git a/lib_com/lerp.c b/lib_com/lerp.c
index bb33d9922c50b3f745edce408841d7671f56b12e..4e306b93698eaff8917a518ff6f531615683af53 100644
--- a/lib_com/lerp.c
+++ b/lib_com/lerp.c
@@ -36,154 +36,25 @@
#include
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#include "wmc_auto.h"
-
/*-------------------------------------------------------------*
* Local function prototypes
*-------------------------------------------------------------*/
-static void lerp_proc_flt( const float *f, float *f_out, const int16_t bufferNewSize, const int16_t bufferOldSize );
-
-
/*-------------------------------------------------------------*
* procedure lerp_flt() *
* *
* *
*-------------------------------------------------------------*/
-void lerp_flt(
- const float *f,
- float *f_out,
- const int16_t bufferNewSize,
- const int16_t bufferOldSize_inp )
-{
- float maxFac;
- int16_t bufferOldSize, tmpNewSize;
-
- maxFac = 507.0 / 128.0;
- bufferOldSize = bufferOldSize_inp;
-
- if ( (float) bufferNewSize / bufferOldSize > maxFac )
- {
- tmpNewSize = bufferOldSize * 2;
- while ( bufferNewSize > bufferOldSize )
- {
- if ( (float) bufferNewSize / bufferOldSize <= maxFac )
- {
- tmpNewSize = bufferNewSize;
- }
-
- lerp_proc_flt( f, f_out, tmpNewSize, bufferOldSize );
-
- f = f_out;
- bufferOldSize = tmpNewSize;
- tmpNewSize *= 2;
- }
- }
- else if ( (float) bufferOldSize / bufferNewSize > maxFac )
- {
- tmpNewSize = bufferOldSize / 2;
- while ( bufferNewSize < bufferOldSize )
- {
- if ( (float) bufferOldSize / bufferNewSize <= maxFac )
- {
- tmpNewSize = bufferNewSize;
- }
-
- lerp_proc_flt( f, f_out, tmpNewSize, bufferOldSize );
-
- f = f_out;
- bufferOldSize = tmpNewSize;
- tmpNewSize /= 2;
- }
- }
- else
- {
- lerp_proc_flt( f, f_out, bufferNewSize, bufferOldSize );
- }
-
- return;
-}
-
/*-------------------------------------------------------------*
* procedure lerp_proc_flt() *
* *
* *
*-------------------------------------------------------------*/
-static void lerp_proc_flt(
- const float *f,
- float *f_out,
- const int16_t bufferNewSize,
- const int16_t bufferOldSize )
-{
- int16_t i, idx;
- float pos, shift, diff;
- float buf[2 * L_FRAME_MAX];
- Word16 tmp;
-
- if ( bufferNewSize == bufferOldSize )
- {
- mvr2r( f, buf, bufferNewSize );
- mvr2r( buf, f_out, bufferNewSize );
- return;
- }
-
- /* Using the basop code to avoid reading beyond end of input for bufferOldSize=320, bufferNewSize=640 */
- tmp = div_s( bufferOldSize, shl( bufferNewSize, 4 ) );
- shift = (float) ( L_shl( L_deposit_l( tmp ), 4 - 15 + 16 ) ) / 65536.0f;
- pos = 0.5f * shift - 0.5f;
-
- if ( shift < 0.3f )
- {
- pos = pos - 0.13f;
- }
-
- /* first point of interpolation */
- if ( pos < 0 )
- {
- buf[0] = f[0] + pos * ( f[1] - f[0] );
- }
- else
- {
- idx = (int16_t) pos;
- diff = pos - idx;
- buf[0] = f[idx] + diff * ( f[idx + 1] - f[idx] );
- }
-
- pos += shift;
-
- for ( i = 1; i < bufferNewSize - 1; i++ )
- {
- idx = (int16_t) pos;
- diff = pos - idx;
-
- buf[i] = f[idx] + diff * ( f[idx + 1] - f[idx] );
- pos += shift;
- }
-
-
- /* last point */
- idx = (int16_t) pos;
-
- if ( pos > bufferOldSize - 1 )
- {
- idx = bufferOldSize - 2;
- }
-
- diff = pos - idx;
-
- buf[bufferNewSize - 1] = f[idx] + diff * ( f[idx + 1] - f[idx] );
-
- mvr2r( buf, f_out, bufferNewSize );
-
- return;
-}
-
-
/*-------------------------------------------------------------*
* Local constants
*-------------------------------------------------------------*/
@@ -430,7 +301,7 @@ static void lerp_proc32( Word32 *f /*Qx*/, Word32 *f_out /*Qx*/, Word16 bufferNe
{
diff = sub( 16384 /*0.5f Q15*/, diff ); /*Q15*/
}
- *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ) ); /*Qx*/
+ *ptr++ = L_add_sat( f[idx], L_sub( Mpy_32_16_1( f[idx + 1], diff ), Mpy_32_16_1( f[idx], diff ) ) ); /*Qx*/
move32();
pos = L_add( pos, shift ); /*Q16*/
idx = extract_h( pos );
diff --git a/lib_com/limit_t0.c b/lib_com/limit_t0.c
deleted file mode 100644
index d49cad28376c7dd239a9bcd7634582d235a1f225..0000000000000000000000000000000000000000
--- a/lib_com/limit_t0.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "cnst.h"
-#include "prot.h"
-#include "wmc_auto.h"
-
-/*-------------------------------------------------*
- * Local constants
- *-------------------------------------------------*/
-
-#define LIMIT_PIT_REL_LOWER 2 /* delta interval to extend pitch coding in relative Q */
-#define LIMIT_PIT_REL_UPPER 0
-
-/*-------------------------------------------------*
- * limit_T0()
- *
- * Close-loop pitch lag search limitation
- *-------------------------------------------------*/
-
-void limit_T0(
- const int16_t L_frame, /* i : length of the frame */
- const int16_t delta, /* i : Half the close-loop searched interval */
- const int16_t pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */
- const int16_t limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */
- const int16_t T0, /* i : rough pitch estimate around which the search is done */
- const int16_t T0_frac, /* i : pitch estimate fractional part */
- int16_t *T0_min, /* o : lower pitch limit */
- int16_t *T0_max /* o : higher pitch limit */
-)
-{
- int16_t delta2, T1;
- int16_t pit_min, pit_max;
-
- if ( limit_flag == 0 ) /* restrained Q limits */
- {
- /* set limits */
- if ( L_frame == L_FRAME )
- {
- pit_max = PIT_MAX;
- pit_min = PIT_MIN;
- }
- else /* L_frame == L_FRAME16k */
- {
- pit_max = PIT16k_MAX;
- pit_min = PIT16k_MIN;
- }
-
- delta2 = 2 * delta - 1;
-
- T1 = T0;
- if ( T0_frac >= 2 )
- {
- T1++;
- }
- *T0_min = T1 - delta;
-
- if ( *T0_min < pit_min )
- {
- *T0_min = pit_min;
- }
- *T0_max = *T0_min + delta2;
-
- if ( *T0_max > pit_max )
- {
- *T0_max = pit_max;
- *T0_min = *T0_max - delta2;
- }
- }
- else /* extended Q limits */
- {
-
- /* set limits */
- if ( L_frame == L_FRAME )
- {
- pit_max = PIT_MAX;
- pit_min = PIT_MIN_EXTEND;
-
- if ( limit_flag == 2 )
- {
- pit_min = PIT_MIN_DOUBLEEXTEND;
- }
- }
- else /* L_frame == L_FRAME16k */
- {
- pit_max = PIT16k_MAX;
- pit_min = PIT16k_MIN_EXTEND;
- }
-
- delta2 = 2 * delta - 1;
-
- T1 = T0;
- if ( T0_frac >= 2 )
- {
- T1++;
- }
- *T0_min = T1 - delta;
-
- if ( pit_flag == 0 )
- {
- /* subframes with absolute search: keep Q range */
- if ( *T0_min < pit_min )
- {
- *T0_min = pit_min;
- }
- *T0_max = *T0_min + delta2;
-
- if ( *T0_max > pit_max )
- {
- *T0_max = pit_max;
- *T0_min = *T0_max - delta2;
- }
- }
- else
- {
- /* subframes with relative search: extend Q range */
- if ( *T0_min < pit_min - LIMIT_PIT_REL_LOWER )
- {
- *T0_min = pit_min - LIMIT_PIT_REL_LOWER;
- }
-
- if ( *T0_min < L_INTERPOL )
- {
- *T0_min = L_INTERPOL;
- }
- *T0_max = *T0_min + delta2;
-
- if ( *T0_max > pit_max + LIMIT_PIT_REL_UPPER )
- {
- *T0_max = pit_max + LIMIT_PIT_REL_UPPER;
- *T0_min = *T0_max - delta2;
- }
- }
- }
-
- return;
-}
-
-
-/*-------------------------------------------------*
- * Routine limit_T0_voiced_ivas()
- *
- * Close-loop pitch lag search limitation
- *-------------------------------------------------*/
-
-void limit_T0_voiced_ivas(
- const int16_t nbits,
- const int16_t res,
- const int16_t T0, /* i : rough pitch estimate around which the search is done */
- const int16_t T0_frac, /* i : pitch estimate fractional part */
- const int16_t T0_res, /* i : pitch resolution */
- int16_t *T0_min, /* o : lower pitch limit */
- int16_t *T0_min_frac, /* o : lower pitch limit */
- int16_t *T0_max, /* o : higher pitch limit */
- int16_t *T0_max_frac, /* o : higher pitch limit */
- const int16_t pit_min, /* i : Minimum pitch lag */
- const int16_t pit_max /* i : Maximum pitch lag */
-)
-{
- int16_t T1, temp1, temp2;
-
- /* Mid-point */
- T1 = T0;
- if ( ( T0_res > 1 ) && ( T0_frac >= ( T0_res >> 1 ) ) )
- {
- T1++;
- }
-
- /* Lower-bound */
- temp1 = ( T1 * res ) - ( 1 << ( nbits - 1 ) );
- temp2 = temp1 / res;
- *T0_min = temp2;
- *T0_min_frac = temp1 - temp2 * res;
- if ( *T0_min < pit_min )
- {
- *T0_min = pit_min;
- *T0_min_frac = 0;
- }
-
- /* Higher-bound */
- temp1 = ( *T0_min * res ) + *T0_min_frac + ( 1 << nbits ) - 1;
- temp2 = temp1 / res;
- *T0_max = temp2;
- *T0_max_frac = temp1 - temp2 * res;
- if ( *T0_max > pit_max )
- {
- *T0_max = pit_max;
- *T0_max_frac = res - 1;
- temp1 = ( *T0_max * res ) + *T0_max_frac - ( 1 << nbits ) + 1;
- temp2 = temp1 / res;
- *T0_min = temp2;
- *T0_min_frac = temp1 - temp2 * res;
- }
-
- return;
-}
diff --git a/lib_com/longarith.c b/lib_com/longarith.c
index 66c5dd15ef0e35eac14d866e775ae82f56560561..8946e41aacfbd8b52834f85e8910c07cbbb0f3ce 100644
--- a/lib_com/longarith.c
+++ b/lib_com/longarith.c
@@ -37,10 +37,9 @@
#include
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*-------------------------------------------------------------------*
diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c
index 61ead2bf2a75118ce2399146e065fd243fae0077..4f493cacde1c222cba29c4859e08beb17776da29 100644
--- a/lib_com/lsp_conv_poly_fx.c
+++ b/lib_com/lsp_conv_poly_fx.c
@@ -6,10 +6,9 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
/*-------------------------------------------------------------------*
* Local constants
diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c
index 4af93522dd07e3c4ce6d92e13e36644fc040c642..7ed3cb59b62389a3fa6166306cc6d632a9d44885 100644
--- a/lib_com/modif_fs.c
+++ b/lib_com/modif_fs.c
@@ -38,10 +38,9 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
void Interpolate_allpass_steep_32(
@@ -115,6 +114,22 @@ void Decimate_allpass_steep_fx32(
/* upper allpass filter chain */
FOR( k = 0; k < N / 2; k++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ temp[0] = Madd_32_16( mem[0], in[2 * k], AP1_STEEP_FX[0] ); // Qx
+ move32();
+ mem[0] = Msub_32_16( in[2 * k], temp[0], AP1_STEEP_FX[0] ); // Qx
+ move32();
+
+ temp[1] = Madd_32_16( mem[1], temp[0], AP1_STEEP_FX[1] ); // Qx
+ move32();
+ mem[1] = Msub_32_16( temp[0], temp[1], AP1_STEEP_FX[1] ); // Qx
+ move32();
+
+ out[k] = Madd_32_16( mem[ALLPASSSECTIONS_STEEP - 1], temp[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx
+ move32();
+ mem[ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp[ALLPASSSECTIONS_STEEP - 2], out[k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
temp[0] = L_add( mem[0], Mpy_32_16_1( in[2 * k], AP1_STEEP_FX[0] ) ); // Qx
move32();
mem[0] = L_sub( in[2 * k], Mpy_32_16_1( temp[0], AP1_STEEP_FX[0] ) ); // Qx
@@ -129,17 +144,31 @@ void Decimate_allpass_steep_fx32(
move32();
mem[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out[k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
/* lower allpass filter chain */
+#ifdef OPT_STEREO_32KBPS_V1
+ temp[0] = Madd_32_16( mem[ALLPASSSECTIONS_STEEP], mem[2 * ALLPASSSECTIONS_STEEP], AP2_STEEP_FX[0] ); // Qx
+ move32();
+ mem[ALLPASSSECTIONS_STEEP] = Msub_32_16( mem[2 * ALLPASSSECTIONS_STEEP], temp[0], AP2_STEEP_FX[0] ); // Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( mem[2 * ALLPASSSECTIONS_STEEP], AP2_STEEP_FX[0] ) ); // Qx
move32();
mem[ALLPASSSECTIONS_STEEP] = L_sub( mem[2 * ALLPASSSECTIONS_STEEP], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); // Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
/* for better performance, unroll this loop */
FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ temp[n] = Madd_32_16( mem[ALLPASSSECTIONS_STEEP + n], temp[n - 1], AP2_STEEP_FX[n] ); // Qx
+ move32();
+ mem[ALLPASSSECTIONS_STEEP + 1] = Msub_32_16( temp[n - 1], temp[n], AP2_STEEP_FX[n] ); // Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); // Qx
move32();
/*if ( fabs( temp[n] ) < 1e-12 )
@@ -148,26 +177,48 @@ void Decimate_allpass_steep_fx32(
}*/
mem[ALLPASSSECTIONS_STEEP + 1] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); // Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
+#ifdef OPT_STEREO_32KBPS_V1
+ temp[ALLPASSSECTIONS_STEEP - 1] = Madd_32_16( mem[2 * ALLPASSSECTIONS_STEEP - 1], temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx
+ move32();
+
+ mem[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp[ALLPASSSECTIONS_STEEP - 2], temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx
move32();
mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
out[0] = W_round48_L( W_mac_32_16( W_mult_32_16( out[0], 16384 /*0.5 in Q15*/ ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 /*0.5 in Q15*/ ) ); // Qx
move32();
FOR( k = 1; k < N / 2; k++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ temp[0] = Madd_32_16( mem[ALLPASSSECTIONS_STEEP], in[2 * k - 1], AP2_STEEP_FX[0] ); // Qx
+ move32();
+ mem[ALLPASSSECTIONS_STEEP] = Msub_32_16( in[2 * k - 1], temp[0], AP2_STEEP_FX[0] ); // Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[sub( shl( k, 1 ), 1 )], AP2_STEEP_FX[0] ) ); // Qx
move32();
mem[ALLPASSSECTIONS_STEEP] = L_sub( in[sub( shl( k, 1 ), 1 )], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); // Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
/* for better performance, unroll this loop */
FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ temp[n] = Madd_32_16( mem[ALLPASSSECTIONS_STEEP + n], temp[n - 1], AP2_STEEP_FX[n] ); // Qx
+ move32();
+ mem[ALLPASSSECTIONS_STEEP + n] = Msub_32_16( temp[n - 1], temp[n], AP2_STEEP_FX[n] ); // Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); // Qx
move32();
/*if ( fabs( temp[n] ) < 1e-12 )
@@ -176,12 +227,20 @@ void Decimate_allpass_steep_fx32(
}*/
mem[ALLPASSSECTIONS_STEEP + n] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); // Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
+#ifdef OPT_STEREO_32KBPS_V1
+ temp[ALLPASSSECTIONS_STEEP - 1] = Madd_32_16( mem[2 * ALLPASSSECTIONS_STEEP - 1], temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx
+ move32();
+ mem[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp[ALLPASSSECTIONS_STEEP - 2], temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx
move32();
mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
out[k] = W_round48_L( W_mac_32_16( W_mult_32_16( out[k], 16384 /*0.5 in Q15*/ ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 /*0.5 in Q15*/ ) ); // Qx
move32();
}
@@ -211,12 +270,21 @@ void interpolate_3_over_2_allpass_32(
FOR( i = 0; i < len; i++ )
{
/* Upper branch */
+#ifdef OPT_STEREO_32KBPS_V1
+ Vu[0] = Madd_32_16( mem[0], L_sub( input[i], mem[1] ), filt_coeff[0] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+ Vu[1] = Madd_32_16( mem[1], L_sub( Vu[0], mem[2] ), filt_coeff[1] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+ mem[3] = Madd_32_16( mem[2], L_sub( Vu[1], mem[3] ), filt_coeff[2] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
Vu[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); // Qx + Q15 - Q15 -> Qx
move32();
Vu[1] = L_add( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); // Qx + Q15 - Q15 -> Qx
move32();
mem[3] = L_add( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); // Qx + Q15 - Q15 -> Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
mem[1] = Vu[0]; // Qx
move32();
@@ -226,12 +294,21 @@ void interpolate_3_over_2_allpass_32(
move32();
/* Middle branch */
+#ifdef OPT_STEREO_32KBPS_V1
+ Vm[0] = Madd_32_16( mem[0], L_sub( input[i], mem[4] ), filt_coeff[3] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+ Vm[1] = Madd_32_16( mem[4], L_sub( Vm[0], mem[5] ), filt_coeff[4] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+ mem[6] = Madd_32_16( mem[5], L_sub( Vm[1], mem[6] ), filt_coeff[5] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
Vm[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); // Qx + Q15 - Q15 -> Qx
move32();
Vm[1] = L_add( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); // Qx + Q15 - Q15 -> Qx
move32();
mem[6] = L_add( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); // Qx + Q15 - Q15 -> Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
mem[4] = Vm[0]; // Qx
move32();
@@ -241,12 +318,21 @@ void interpolate_3_over_2_allpass_32(
move32();
/* Lower branch */
+#ifdef OPT_STEREO_32KBPS_V1
+ Vl[0] = Madd_32_16( mem[0], L_sub( input[i], mem[7] ), filt_coeff[6] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+ Vl[1] = Madd_32_16( mem[7], L_sub( Vl[0], mem[8] ), filt_coeff[7] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+ mem[9] = Madd_32_16( mem[8], L_sub( Vl[1], mem[9] ), filt_coeff[8] ); // Qx + Q15 - Q15 -> Qx
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
Vl[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); // Qx + Q15 - Q15 -> Qx
move32();
Vl[1] = L_add( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); // Qx + Q15 - Q15 -> Qx
move32();
mem[9] = L_add( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); // Qx + Q15 - Q15 -> Qx
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
mem[0] = input[i]; // Qx
move32();
@@ -265,10 +351,17 @@ void interpolate_3_over_2_allpass_32(
{
mem_temp = out1_buff[2 * i];
move32();
+#ifdef OPT_STEREO_32KBPS_V1
+ out[i] = Madd_32_16( Mpy_32_16_1( L_add( mem_temp, mem[10] ), 1550 ), L_add( mem[11], mem[14] ), -4965 ); // Qx + Q15 - Q15 -> Qx
+ // 0.0473147f in Q15 -> 1550, -0.151521f in Q15 -> -4965
+ out[i] = Madd_32_16( out[i], L_add( mem[12], mem[13] ), 20125 );
+ // 0.614152f in Q15 -> 20125
+#else /* OPT_STEREO_32KBPS_V1 */
out[i] = L_add( Mpy_32_16_1( L_add( mem_temp, mem[10] ), 1550 ), Mpy_32_16_1( L_add( mem[11], mem[14] ), -4965 ) ); // Qx + Q15 - Q15 -> Qx
// 0.0473147f in Q15 -> 1550, -0.151521f in Q15 -> -4965
out[i] = L_add( out[i], Mpy_32_16_1( L_add( mem[12], mem[13] ), 20125 ) );
// 0.614152f in Q15 -> 20125
+#endif /* OPT_STEREO_32KBPS_V1 */
mem[10] = mem[11]; // Qx
move32();
mem[11] = mem[12]; // Qx
diff --git a/lib_com/mslvq_com.c b/lib_com/mslvq_com.c
index 34e2083b96bd5146f205f9dd6d3f91e3be14af53..a15b116110d15462512689ca4a062eea6efa68ae 100644
--- a/lib_com/mslvq_com.c
+++ b/lib_com/mslvq_com.c
@@ -38,10 +38,9 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
/*-----------------------------------------------------------------*
diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c
index 14c9b6d975f6281f36c620fe66b88bfece809c52..10e5604335a7b1ad471ffb3cf631bf2b8c6856aa 100644
--- a/lib_com/mslvq_com_fx.c
+++ b/lib_com/mslvq_com_fx.c
@@ -31,7 +31,6 @@
*******************************************************************************************************/
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_cnst.h"
#include "stl.h"
@@ -122,9 +121,33 @@ void init_lvq_fx(
)
{
Word16 i, j;
+#ifdef OPT_STEREO_32KBPS_V1
+ Word16 k;
+#endif /* OPT_STEREO_32KBPS_V1 */
/* safety-net mode */
FOR( i = 0; i < MAX_NO_MODES; i++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ FOR( ( j = 0, k = 0 ); j < MAX_NO_SCALES; ( j++, k++ ) )
+ {
+ if ( ( no_lead_fx[i][j] <= 0 ) )
+ {
+ j = MAX_NO_SCALES;
+ }
+ }
+ no_scales[i][0] = k;
+ move16();
+
+ FOR( k = 0; j < MAX_NO_SCALES << 1; ( j++, k++ ) )
+ {
+ if ( no_lead_fx[i][j] <= 0 )
+ {
+ j = MAX_NO_SCALES << 1;
+ }
+ }
+ no_scales[i][1] = k;
+ move16();
+#else /* OPT_STEREO_32KBPS_V1 */
j = 0;
move16();
test();
@@ -143,10 +166,35 @@ void init_lvq_fx(
}
no_scales[i][1] = sub( j, MAX_NO_SCALES );
move16();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
/* predictive mode */
FOR( i = 0; i < MAX_NO_MODES_p; i++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ FOR( ( j = 0, k = 0 ); j < MAX_NO_SCALES; ( j++, k++ ) )
+ {
+
+ if ( ( no_lead_p_fx[i][j] <= 0 ) )
+ {
+ j = MAX_NO_SCALES;
+ }
+ }
+ no_scales_p[i][0] = k;
+ move16();
+
+ FOR( k = 0; j < MAX_NO_SCALES << 1; ( j++, k++ ) )
+ {
+
+ if ( ( no_lead_p_fx[i][j] <= 0 ) )
+ {
+ j = MAX_NO_SCALES << 1;
+ }
+ }
+
+ no_scales_p[i][1] = k;
+ move16();
+#else /* OPT_STEREO_32KBPS_V1 */
j = 0;
move16();
WHILE( ( LT_16( j, MAX_NO_SCALES ) ) && ( no_lead_p_fx[i][j] > 0 ) )
@@ -165,6 +213,7 @@ void init_lvq_fx(
}
no_scales_p[i][1] = sub( j, MAX_NO_SCALES );
move16();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
/* index offsets for each truncation */
init_offset_fx( offset_scale1, offset_scale2, offset_scale1_p, offset_scale2_p, no_scales, no_scales_p );
diff --git a/lib_com/options.h b/lib_com/options.h
index 8eb05953721b588c598ebb17c4d07c2e7ad10bb3..7aeea040f3daaff76ae2076760fa45d4da6cd214 100755
--- a/lib_com/options.h
+++ b/lib_com/options.h
@@ -67,15 +67,11 @@
#define BASOP_NOGLOB_DECLARE_LOCAL
#endif
-#define IVAS_FLOAT_FIXED
#define IVAS_FLOAT_FIXED_CONVERSIONS /* Temporary macro to keep track of intermediate flt to fixed and fixed to flt conversions */
#define MSAN_FIX
-#define ISM_DISABLE
#define FIX_TMP_714
#define BASOP_NOGLOB_TMP_715
#define EVS_FUNC_MODIFIED
-//#define EVS_FLOAT_ENC
-#define IVAS_CNST
#define REMOVE_IVAS_UNUSED_PARAMETERS_WARNING /*temporary operation on unused EVS parameters to remove warnings, these parameters will be used in IVAS */
#define MOD_BIT_ALLOC_ROM_TABLE /* Just to highlight modification in bit allocation table and to ensure these modifications doesn't affect EVS modes*/
#define SIMPLIFY_CODE_BE // Simplify synthesis loop
@@ -173,7 +169,6 @@
#define NONBE_FIX_1277_EVS_DTX_HIGH_RATE_THRESHOLD /* VA/Eri: FLP issue 1277: Fix Mismatch in DTX high-rate threshold between EVS float and BASOP */
#define NONBE_FIX_708_OSBA_BR_SWITCHING_CRASH /* FhG: issue 708: fix crash in OSBA BR switching with long test vectors */
-
/* #################### Start BASOP porting switches ############################ */
#define SPLIT_REND_WITH_HEAD_ROT /* Dlb,FhG: Split Rendering contributions 21 and 35 */
@@ -184,4 +179,7 @@
/* #################### End BASOP porting switches ############################ */
+//#define OPT_STEREO_32KBPS_V1 /* Optimization made in stereo decoding path for 32kbps decoding */
+#define DOT_PROD_CHOLESKY_64BIT /* FhG: Issue 1323, optimized 64 bit implementation of dot_product_cholesky() */
+#define OPT_BASOP_ADD_v1 /* optimizations to avoid usage of BASOP_Util_Add_MantExp */
#endif
diff --git a/lib_com/preemph.c b/lib_com/preemph.c
index 490a18aef187ffac1e65529de8eee2cbe3b3a3d1..9ebc0f72a81c39542312ff9e6bbd3d76b5a49197 100644
--- a/lib_com/preemph.c
+++ b/lib_com/preemph.c
@@ -36,7 +36,7 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
/*-------------------------------------------------------------*
diff --git a/lib_com/prot.h b/lib_com/prot.h
deleted file mode 100644
index 16f4659a049c5ed94b4ab49b59571b7e5e3ff5a3..0000000000000000000000000000000000000000
--- a/lib_com/prot.h
+++ /dev/null
@@ -1,8339 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#ifndef PROT_H
-#define PROT_H
-
-#include
-#include
-#include
-#include "options.h"
-#include "typedef.h"
-#include "stat_enc.h"
-#include "stat_dec.h"
-#include "stat_com.h"
-#include "ivas_stat_com.h"
-#include "ivas_stat_enc.h"
-#include "ivas_stat_dec.h"
-#include "cnst.h"
-#include "stl.h"
-#include "ivas_error_utils.h"
-
-
-/*----------------------------------------------------------------------------------*
- * Prototypes of global macros
- *----------------------------------------------------------------------------------*/
-
-#ifndef min
-#define min( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )
-#endif
-
-#ifndef max
-#define max( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
-#endif
-
-#ifndef TRUNC
-#define TRUNC( x ) ( (int16_t) ( ( ( x ) >= 32767. ? 32767 : ( ( x ) <= -32768. ? -32768 : ( x ) ) ) + 0.5 ) )
-#endif
-
-#define log_base_2( x ) ( (double) log( (double) ( x ) ) * 1.4426950408889634074f )
-#define round_f( x ) ( ( ( x ) > 0 ) ? (int32_t) ( ( x ) + 0.5f ) : ( -(int32_t) ( ( -x ) + 0.5f ) ) )
-
-#ifndef ABSVAL
-#define ABSVAL( a ) ( ( a ) >= 0 ? ( a ) : ( -( a ) ) )
-#endif
-
-#ifndef SQR
-#define SQR( a ) ( ( a ) * ( a ) )
-#endif
-
-#ifndef SWAP
-#define SWAP( a, b ) \
- { \
- tempr = ( a ); \
- ( a ) = ( b ); \
- ( b ) = tempr; \
- }
-#endif
-
-#ifndef swap
-#define swap( x, y, type ) \
- { \
- type u__p; \
- u__p = x; \
- x = y; \
- y = u__p; \
- }
-#endif
-
-#define set_max( a, b ) \
- { \
- if ( ( b ) > *a ) \
- { \
- *a = ( b ); \
- } \
- } /* If the first argument is already the highes or lowest, nothing is done. */
-#define set_min( a, b ) \
- { \
- if ( ( b ) < *a ) \
- { \
- *a = ( b ); \
- } \
- } /* Otherwise, the 2nd arg is stored at the address of the first arg. */
-
-
-/*----------------------------------------------------------------------------------*
- * MODE1 prototypes
- *----------------------------------------------------------------------------------*/
-
-/*! r: inverse square root of input value */
-float inv_sqrt(
- const float x /* i : input value */
-);
-
-/*! r: output random value */
-int16_t own_random(
- int16_t *seed /* i/o: random seed */
-);
-
-/*! r: sign of x (+1/-1) */
-float sign(
- const float x /* i : input value of x */
-);
-
-/*! r: logarithm2 of x */
-float log2_f(
- const float x /* i : input value of x */
-);
-
-int16_t norm_ul_float(
- uint32_t UL_var1 );
-
-/*! r: sum of all vector elements */
-int16_t sum_s(
- const int16_t *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-);
-
-/*! r: sum of all vector elements */
-int32_t sum_l(
- const int32_t *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-);
-
-/*! r: sum of all vector elements */
-float sum_f(
- const float *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-);
-
-/*! r: sum of all squared vector elements */
-float sum2_f(
- const float *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-);
-
-void set_c(
- int8_t y[], /* i/o: Vector to set */
- const int8_t a, /* i : Value to set the vector to */
- const int32_t N /* i : Length of the vector */
-);
-
-void set_s(
- int16_t y[], /* i/o: Vector to set */
- const int16_t a, /* i : Value to set the vector to */
- const int16_t N /* i : Lenght of the vector */
-);
-
-void set_l(
- int32_t y[], /* i/o: Vector to set */
- const int32_t a, /* i : Value to set the vector to */
- const int16_t N /* i : Length of the vector */
-);
-
-void set_f(
- float y[], /* i/o: Vector to set */
- const float a, /* i : Value to set the vector to */
- const int16_t N /* i : Lenght of the vector */
-);
-
-void set_zero_fx(
- Word32 *vec, /* o : input vector */
- const Word16 lvec /* i : length of the vector */
-);
-void set_zero2_fx(
- Word32 *vec, /* o : input vector */
- const Word32 lvec /* i : length of the vector */
-);
-void set16_zero_fx(
- Word16 *vec, /* o : input vector */
- const Word16 lvec /* i : length of the vector */
-);
-
-void set_zero(
- float *vec, /* o : input vector */
- const int16_t lvec /* i : length of the vector */
-);
-
-void mvr2r(
- const float x[], /* i : input vector */
- float y[], /* o : output vector */
- const int16_t n /* i : vector size */
-);
-
-void mvs2s(
- const int16_t x[], /* i : input vector */
- int16_t y[], /* o : output vector */
- const int16_t n /* i : vector size */
-);
-
-uint32_t mvr2s(
- const float x[], /* i : input vector */
- int16_t y[], /* o : output vector */
- const int16_t n /* i : vector size */
-);
-
-void mvs2r(
- const int16_t x[], /* i : input vector */
- float y[], /* o : output vector */
- const int16_t n /* i : vector size */
-);
-
-void mvl2l(
- const int32_t x[], /* i : input vector */
- int32_t y[], /* o : output vector */
- const int16_t n /* i : vector size */
-);
-
-
-/*! r: index of the maximum value in the input vector */
-int16_t maximum(
- const float *vec, /* i : input vector */
- const int16_t lvec, /* i : length of input vector */
- float *max_val /* o : maximum value in the input vector */
-);
-/*! r: index of the maximum value in the input vector */
-int16_t maximumAbs(
- const float *vec, /* i : input vector */
- const int16_t lvec, /* i : length of input vector */
- float *max_val /* o : maximum value in the input vector */
-);
-
-Word16 maximumAbs_l(
- const Word32 *vec, /* i : input vector */
- const Word16 lvec, /* i : length of input vector */
- Word32 *max_val /* o : maximum value in the input vector */
-);
-
-/*! r: index of the minimum value in the input vector */
-int16_t minimum(
- const float *vec, /* i : input vector */
- const int16_t lvec, /* i : length of input vector */
- float *min_val /* o : minimum value in the input vector */
-);
-
-/*! r: index of the minimum value in the input vector */
-int16_t minimum_s(
- const int16_t *vec, /* i : Input vector */
- const int16_t lvec, /* i : Vector length */
- int16_t *min_val /* o : minimum value in the input vector */
-);
-
-/*! r: return index with max energy value in vector */
-int16_t emaximum(
- const float *vec, /* i : input vector */
- const int16_t lvec, /* i : length of input vector */
- float *ener_max /* o : maximum energy value */
-);
-
-/*! r: vector mean */
-float mean(
- const float *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-);
-
-/*! r: dot product of x[] and y[] */
-float dotp(
- const float x[], /* i : vector x[] */
- const float y[], /* i : vector y[] */
- const int16_t n /* i : vector length */
-);
-
-void conv(
- const float x[], /* i : input vector */
- const float h[], /* i : impulse response (or second input vector) */
- float y[], /* o : output vetor (result of convolution) */
- const int16_t L /* i : vector size */
-);
-
-void fir(
- const float x[], /* i : input vector */
- const float h[], /* i : impulse response of the FIR filter */
- float y[], /* o : output vector (result of filtering) */
- float mem[], /* i/o: memory of the input signal (M samples) */
- const int16_t L, /* i : input vector size */
- const int16_t K, /* i : order of the FIR filter (M+1 coefs.) */
- const int16_t upd /* i : 1 = update the memory, 0 = not */
-);
-
-void v_add(
- const float x1[], /* i : Input vector 1 */
- const float x2[], /* i : Input vector 2 */
- float y[], /* o : Output vector that contains vector 1 + vector 2 */
- const int16_t N /* i : Vector length */
-);
-
-void v_sub(
- const float x1[], /* i : Input vector 1 */
- const float x2[], /* i : Input vector 2 */
- float y[], /* o : Output vector that contains vector 1 - vector 2 */
- const int16_t N /* i : Vector length */
-);
-
-void v_mult(
- const float x1[], /* i : Input vector 1 */
- const float x2[], /* i : Input vector 2 */
- float y[], /* o : Output vector that contains vector 1 .* vector 2*/
- const int16_t N /* i : Vector length */
-);
-
-void v_multc(
- const float x[], /* i : Input vector */
- const float c, /* i : Constant */
- float y[], /* o : Output vector that contains c*x */
- const int16_t N /* i : Vector length */
-);
-
-/*! r: index of the winning codeword */
-int16_t squant(
- const float x, /* i : scalar value to quantize */
- float *xq, /* o : quantized value */
- const float cb[], /* i : codebook */
- const int16_t cbsize /* i : codebook size */
-);
-
-int16_t squant_int(
- uint8_t x, /* i : scalar value to quantize */
- uint8_t *xq, /* o : quantized value */
- const uint8_t *cb, /* i : codebook */
- const int16_t cbsize /* i : codebook size */
-);
-
-/*! r: index of the winning codevector */
-int16_t vquant(
- float x[], /* i : vector to quantize */
- const float x_mean[], /* i : vector mean to subtract (0 if none) */
- float xq[], /* o : quantized vector */
- const float cb[], /* i : codebook */
- const int16_t dim, /* i : dimension of codebook vectors */
- const int16_t cbsize /* i : codebook size */
-);
-
-/*! r: index of the winning codevector */
-int16_t w_vquant(
- float x[], /* i : vector to quantize */
- const float x_mean[], /* i : vector mean to subtract (0 if none) */
- const int16_t weights[], /* i : error weights */
- float xq[], /* o : quantized vector */
- const float cb[], /* i : codebook */
- const int16_t dim, /* i : dimension of codebook vectors */
- const int16_t cbsize, /* i : codebook size */
- const int16_t reverse /* i : reverse codebook vectors */
-);
-
-/*! r: index of the winning codeword */
-int16_t usquant(
- const float x, /* i : scalar value to quantize */
- float *xq, /* o : quantized value */
- const float qlow, /* i : lowest codebook entry (index 0) */
- const float delta, /* i : quantization step */
- const int16_t cbsize /* i : codebook size */
-);
-
-/*! r: dequanzited gain */
-float usdequant(
- const int16_t idx, /* i : quantizer index */
- const float qlow, /* i : lowest codebook entry (index 0) */
- const float delta /* i : quantization step */
-);
-
-void v_sort_float(
- float *r, /* i/o: Vector to be sorted in place */
- const int16_t lo, /* i : Low limit of sorting range */
- const int16_t up /* i : High limit of sorting range */
-);
-
-void sort(
- uint16_t *x, /* i/o: Vector to be sorted */
- uint16_t len /* i/o: vector length */
-);
-
-void sort_l(
- Word32 *x, /* i/o: Vector to be sorted */
- Word16 len /* i/o: vector length */
-);
-
-/*! r: variance of vector */
-float var(
- const float *x, /* i : input vector */
- const int16_t len /* i : length of inputvector */
-);
-
-/*! r: standard deviation */
-float std_dev(
- const float *x, /* i : input vector */
- const int16_t len /* i : length of the input vector */
-);
-
-/*! r: the dot product x'*A*x */
-float dot_product_mat(
- const float *x, /* i : vector x */
- const float *A, /* i : matrix A */
- const int16_t m /* i : vector length */
-);
-
-float root_a(
- float a );
-
-float root_a_over_b(
- float a,
- float b );
-
-void polezero_filter(
- const float *in, /* i : input vector */
- float *out, /* o : output vector */
- const int16_t N, /* i : input vector size */
- const float *b, /* i : numerator coefficients */
- const float *a, /* i : denominator coefficients */
- const int16_t order, /* i : filter order */
- float *mem /* i/o: filter memory */
-);
-
-double rint_new(
- double x /* i/o: Round to the nearest integer with mid point exception */
-);
-
-double anint(
- double x /* i/o: Round to the nearest integer */
-);
-
-/*! r: Output either 1 if Numeric, 0 if NaN or Inf */
-int16_t is_numeric_float(
- float x /* i : Input value which is checked if numeric or not */
-);
-
-void delay_signal_float(
- float x[], /* i/o: signal to be delayed */
- const int16_t len, /* i : length of the input signal */
- float mem[], /* i/o: synchronization memory */
- const int16_t delay /* i : delay in samples */
-);
-
-ivas_error push_indice(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- int16_t id, /* i : ID of the indice */
- uint16_t value, /* i : value of the quantized indice */
- int16_t nb_bits /* i : number of bits used to quantize the indice */
-);
-
-ivas_error push_next_indice(
- BSTR_ENC_HANDLE hBstr,
- UWord16 value, /* i : value of the quantized indice */
- Word16 nb_bits /* i : number of bits used to quantize the indice */
-);
-
-ivas_error push_next_bits(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const UWord16 bits[], /* i : bit buffer to pack, sequence of single bits */
- const Word16 nb_bits /* i : number of bits to pack */
-);
-
-/*! r: maximum number of indices */
-Word16 get_ivas_max_num_indices_fx(
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- const Word32 ivas_total_brate /* i : IVAS total bitrate */
-);
-
-/*! r: maximum number of indices */
-int16_t get_BWE_max_num_indices(
- const int32_t extl_brate /* i : extensiona layer bitrate */
-);
-
-/*! r: maximum number of indices */
-Word16 get_ivas_max_num_indices_metadata_fx(
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- const Word32 ivas_total_brate /* i : IVAS total bitrate */
-);
-ivas_error ind_list_realloc(
- INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */
- const int16_t max_num_indices, /* i : new maximum number of allowed indices in the list */
- Encoder_Struct *st_ivas /* i : IVAS encoder structure */
-);
-
-ivas_error check_ind_list_limits(
- BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */
-);
-
-void move_indices(
- INDICE_HANDLE old_ind_list, /* i/o: old location of indices */
- INDICE_HANDLE new_ind_list, /* i/o: new location of indices */
- const int16_t nb_indices /* i : number of moved indices */
-);
-
-/*! r: index of the indice in the list, -1 if not found */
-int16_t find_indice(
- BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */
- const int16_t id, /* i : ID of the indice */
- uint16_t *value, /* o : value of the quantized indice */
- int16_t *nb_bits /* o : number of bits used to quantize the indice */
-);
-
-/*! r: number of deleted indices */
-uint16_t delete_indice(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t id /* i : ID of the indice */
-);
-
-/*! r: value of the indice */
-uint16_t get_next_indice(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t nb_bits /* i : number of bits that were used to quantize the indice */
-);
-
-/*! r: value of the indice */
-uint16_t get_next_indice_1(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-void get_next_indice_tmp(
- Decoder_State *st, /* o : decoder state structure */
- int16_t nb_bits /* i : number of bits that were used to quantize the indice */
-);
-
-/*! r: value of the indice */
-uint16_t get_indice(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t pos, /* i : absolute position in the bitstream */
- int16_t nb_bits /* i : number of bits that were used to quantize the indice */
-);
-
-/*! r: value of the indice */
-uint16_t get_indice_1(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t pos /* i : absolute position in the bitstream */
-);
-
-void reset_indices_enc(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t max_num_indices /* i : max number of indices */
-);
-
-void reset_indices_dec(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-ivas_error write_indices_ivas(
- Encoder_Struct *st_ivas, /* i/o: encoder state structure */
- uint16_t *bit_stream, /* i/o: output bitstream */
- uint16_t *num_bits /* i/o: number of bits written to output */
-);
-
-Word16 rate2EVSmode_float(
- const Word32 brate, /* i : bitrate */
- int16_t *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */
-);
-
-
-/*! r: 1 = OK, 0 = something wrong */
-ivas_error read_indices(
- Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
- uint16_t bit_stream[], /* i : bitstream buffer */
- UWord16 num_bits, /* i : number of bits in bitstream */
- int16_t *prev_ft_speech,
- int16_t *CNG,
- int16_t bfi /* i : bad frame indicator */
-);
-
-
-void ivas_set_bitstream_pointers(
- Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
-);
-
-Decoder_State **reset_elements(
- Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
-);
-
-
-void convertSerialToBytestream(
- const uint16_t *const serial, /* i : input serial bitstream with values 0 and 1 */
- const uint16_t num_bits, /* i : number of bits in the input bitstream */
- uint8_t *const bytestream /* o : output compact bitstream (bytestream) */
-);
-
-void convertBytestreamToSerial(
- const uint8_t *const bytestream, /* i : input compact bitstream (bytestream) */
- const uint16_t num_bits, /* i : number of bits in the input bitstream */
- uint16_t *const serial /* o : output serial bitstream with values 0 and 1 */
-);
-
-void mdct_switching_dec(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-void evs_dec_previewFrame_float(
- uint8_t *bitstream, /* i : bitstream pointer */
- int16_t bitstreamSize, /* i : bitstream size */
- int16_t *partialCopyFrameType, /* o : frame type of the partial copy */
- int16_t *partialCopyOffset /* o : offset of the partial copy relative to the primary copy */
-);
-
-
-void getPartialCopyInfo_float(
- Decoder_State *st, /* i : decoder state structure */
- int16_t *sharpFlag );
-
-void get_NextCoderType(
- uint8_t *bitstream, /* i : bitstream */
- int16_t *next_coder_type /* o : next coder type */
-);
-
-int16_t print_disclaimer(
- FILE *fPtr );
-
-
-/*! r: delay value in ns */
-int32_t get_delay(
- const int16_t enc_dec, /* i : encoder/decoder flag */
- const int32_t io_fs, /* i : input/output sampling frequency */
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */
-);
-
-void decision_matrix_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- int16_t *hq_core_type /* o : HQ core type */
-);
-
-void signaling_enc(
- Encoder_State *st /* i : encoder state structure */
-);
-
-int16_t signaling_mode1_tcx20_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t push /* i : flag to push indice */
-);
-
-void decision_matrix_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t *sharpFlag, /* o : formant sharpening flag */
- int16_t *hq_core_type, /* o : HQ core type */
- int16_t *core_switching_flag /* o : ACELP->HQ switching frame flag */
-);
-
-
-void amr_wb_dec_init(
- AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */
-);
-
-void hf_synth_amr_wb_init(
- AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */
-);
-
-void hf_synth_amr_wb_reset(
- AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */
- ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */
-);
-
-void hf_synth_amr_wb(
- AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */
- ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t output_frame, /* i : output frame length */
- const float *Aq, /* i : quantized Az */
- const float *exc, /* i : excitation at 12.8 kHz */
- float *synth, /* i/o: synthesis signal at 12.8 kHz */
- int16_t *amr_io_class, /* i : signal class (determined by FEC algorithm) */
- float *synth_out, /* i/o: synthesis signal at output Fs */
- float fmerit, /* i : classify parameter from FEC */
- const int16_t *hf_gain, /* i : decoded HF gain */
- const float *voice_factors, /* i : voicing factors */
- const float pitch_buf[], /* i : pitch buffer */
- const float ng_ener_ST, /* i : Noise gate - short-term energy */
- const float *lsf_new /* i : ISF vector */
-);
-
-void hf_cod_init(
- float *mem_hp400_enc, /* o : memory of hp 400 Hz filter */
- float *mem_hf1_enc, /* o : HF band-pass filter memory */
- float *mem_syn_hf_enc, /* o : HF synthesis memory */
- float *mem_hf2_enc, /* o : HF band-pass filter memory */
- float *gain_alpha /* o : smoothing gain for transitions between active and inactive frames */
-);
-
-void hf_cod(
- const int32_t core_brate, /* i : core bitrate */
- const float *speech16k, /* i : original speech at 16 kHz */
- const float Aq[], /* i : quantized Aq */
- const float exc[], /* i : excitation at 12.8 kHz */
- float synth[], /* i : 12.8kHz synthesis signal */
- int16_t *seed2_enc, /* i/o: random seed for HF noise gen */
- float *mem_hp400_enc, /* i/o: memory of hp 400 Hz filter */
- float *mem_syn_hf_enc, /* i/o: HF synthesis memory */
- float *mem_hf1_enc, /* i/o: HF band-pass filter memory */
- float *mem_hf2_enc, /* i/o: HF band-pass filter memory */
- const int16_t *dtxHangoverCount,
- float *gain_alpha, /* i/o: smoothing gain for transitions between active and inactive frames */
- int16_t *hf_gain /* o : HF gain to be transmitted to decoder */
-);
-
-void hf_synth_init(
- ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */
-);
-
-void hf_synth_reset(
- ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */
-);
-
-void hf_synth(
- ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t output_frame, /* i : output frame length */
- const float *Aq, /* i : quantized Az */
- const float *exc, /* i : excitation at 12.8 kHz */
- float *synth, /* i/o: 12.8kHz synthesis signal */
- float *synth16k /* i/o: 16kHz synthesis signal */
-);
-
-void fft_rel(
- float x[], /* i/o: input/output vector */
- const int16_t n, /* i : vector length */
- const int16_t m /* i : log2 of vector length */
-);
-
-void ifft_rel(
- float io[], /* i/o: input/output vector */
- const int16_t n, /* i : vector length */
- const int16_t m /* i : log2 of vector length */
-);
-
-void preemph(
- float *signal, /* i/o: signal */
- const float mu, /* i : preemphasis factor */
- const int16_t L, /* i : vector size */
- float *mem /* i/o: memory (x[-1]) */
-);
-void preemph_ivas_fx(
- Word32 *signal, /* i/o: signal Qx*/
- const Word16 mu, /* i : preemphasis factor Q15*/
- const Word16 L, /* i : vector size Q0*/
- Word32 *mem /* i/o: memory (x[-1]) Qx*/
-);
-void cb_shape(
- const int16_t preemphFlag, /* i : flag for pre-emphasis */
- const int16_t pitchFlag, /* i : flag for pitch sharpening */
- const int16_t scramblingFlag, /* i : flag for phase scrambling */
- const int16_t formantFlag, /* i : flag for formant sharpening */
- const int16_t formantTiltFlag, /* i : flag for formant tilt */
- const float g1, /* i : formant sharpening numerator weighting */
- const float g2, /* i : formant sharpening denominator weighting */
- const float *p_Aq, /* i : LP filter coefficients */
- float *code, /* i/o: signal to shape */
- const float tilt_code, /* i : tilt of code */
- const float pt_pitch, /* i : pointer to current subframe fractional pitch*/
- const int16_t L_subfr /* i : subfframe length */
-);
-
-void CNG_exc(
- const int32_t core_brate, /* i : core bitrate */
- const int16_t L_frame, /* i : length of the frame */
- float *Enew, /* i/o: decoded SID energy */
- int16_t *seed, /* i/o: random generator seed */
- float exc[], /* o : current non-enhanced excitation */
- float exc2[], /* o : current enhanced excitation */
- float *lp_ener, /* i/o: LP filtered E */
- const int32_t last_core_brate, /* i : previous frame core bitrate */
- int16_t *first_CNG, /* i/o: first CNG frame flag for energy init. */
- int16_t *cng_ener_seed, /* i/o: random generator seed for CNG energy */
- float bwe_exc[], /* o : excitation for SWB TBE */
- const int16_t allow_cn_step, /* i : allow CN step */
- int16_t *last_allow_cn_step, /* i/o: last CN_step */
- const int16_t num_ho, /* i : number of selected hangover frames */
- float q_env[],
- float *lp_env,
- float *old_env,
- float *exc_mem,
- float *exc_mem1,
- int16_t *sid_bw,
- int16_t *cng_ener_seed1,
- float exc3[],
- const int16_t Opt_AMR_WB, /* i : AMR-WB interop flag */
- const int16_t element_mode /* i : IVAS Element mode */
-);
-
-
-void cng_params_postupd(
- const int16_t ho_circ_ptr, /* i : pointer for CNG averaging buffers */
- int16_t *cng_buf_cnt, /* i/o: counter for CNG store buffers */
- const float *cng_exc2_buf, /* i : Excitation buffer */
- const int32_t *cng_brate_buf, /* i : bitrate buffer */
- float ho_env_circ[], /* i/o: Envelope buffer */
- const int16_t element_mode, /* i : Element mode */
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-void calculate_hangover_attenuation_gain(
- Encoder_State *st, /* i : encoder state structure */
- float *att, /* o : attenuation factor */
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-int16_t get_cng_mode_ivas(
- const int32_t last_active_brate /* i : last active bitrate */
-);
-
-void disf_ns_28b(
- int16_t *indice, /* i : quantized indices, use indice[0] = -1 in the decoder*/
- float *isf_q /* o : ISF in the frequency domain (0..6400) */
-);
-
-void limit_T0(
- const int16_t L_frame, /* i : length of the frame */
- const int16_t delta, /* i : Half the close-loop searched interval */
- const int16_t pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */
- const int16_t limit_flag, /* i : flag for limits (0=restrained, 1=extended) */
- const int16_t T0, /* i : rough pitch estimate around which the search is done */
- const int16_t T0_frac, /* i : pitch estimate fractional part */
- int16_t *T0_min, /* o : lower pitch limit */
- int16_t *T0_max /* o : higher pitch limit */
-);
-
-/*! r: interpolated value */
-float interpolation(
- const float *x, /* i : input vector */
- const float *win, /* i : interpolation window */
- const int16_t frac, /* i : fraction */
- const int16_t up_samp, /* i : upsampling factor */
- const int16_t nb_coef /* i : nb of filter coef */
-);
-
-void deemph(
- float *signal, /* i/o: signal */
- const float mu, /* i : deemphasis factor */
- const int16_t L, /* i : vector size */
- float *mem /* i/o: memory (y[-1]) */
-);
-
-void weight_a(
- const float *a, /* i : LP filter coefficients */
- float *ap, /* o : weighted LP filter coefficients */
- const float gamma, /* i : weighting factor */
- const int16_t m /* i : order of LP filter */
-);
-
-void weight_a_subfr(
- const int16_t nb_subfr, /* i : number of subframes */
- const float *a, /* i : LP filter coefficients */
- float *ap, /* o : weighted LP filter coefficients */
- const float gamma, /* i : weighting factor */
- const int16_t m /* i : order of LP filter */
-);
-
-void syn_12k8(
- const int16_t L_frame, /* i : length of the frame */
- const float *Aq, /* i : LP filter coefficients */
- const float *exc, /* i : input signal */
- float *synth, /* o : output signal */
- float *mem, /* i/o: initial filter states */
- const int16_t update_m /* i : update memory flag: 0 --> no memory update */
-); /* 1 --> update of memory */
-
-void syn_filt(
- const float a[], /* i : LP filter coefficients */
- const int16_t m, /* i : order of LP filter */
- const float x[], /* i : input signal */
- float y[], /* o : output signal */
- const int16_t l, /* i : size of filtering */
- float mem[], /* i/o: initial filter states */
- const int16_t update_m /* i : update memory flag: 0 --> no memory update */
-); /* 1 --> update of memory */
-
-void synth_mem_updt2_flt(
- const int16_t L_frame, /* i : frame length */
- const int16_t last_L_frame, /* i : frame length */
- float old_exc[], /* i/o: excitation buffer */
- float mem_syn_r[], /* i/o: synthesis filter memory */
- float mem_syn2[], /* o : synthesis filter memory for find_target */
- float mem_syn[], /* o : synthesis filter memory for find_target */
- const int16_t dec /* i : flag for decoder indication */
-);
-
-void int_lsp(
- const int16_t L_frame, /* i : length of the frame */
- const float lsp_old[], /* i : LSPs from past frame */
- const float lsp_new[], /* i : LSPs from present frame */
- float *Aq, /* o : LP coefficients in both subframes */
- const int16_t m, /* i : order of LP filter */
- const float *int_coeffs, /* i : interpolation coefficients */
- const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */
-);
-
-void int_lsp4(
- const int16_t L_frame, /* i : length of the frame */
- const float lsp_old[], /* i : previous end-frame LSPs */
- const float lsp_mid[], /* i : current mid-frame LSPs */
- const float lsp_new[], /* i : current end-frame LSPs */
- float *Aq, /* o : LP coefficients in both subframes */
- const int16_t m, /* i : order of LP filter */
- int16_t relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */
-);
-
-/*! r: length of output */
-int16_t modify_Fs(
- const float sigIn[], /* i : signal to decimate */
- const int16_t lg, /* i : length of input */
- const int32_t fin, /* i : frequency of input */
- float sigOut[], /* o : decimated signal */
- const int32_t fout, /* i : frequency of output */
- float mem[], /* i/o: filter memory */
- const int16_t nblp /* i : flag indicating if NB low-pass is applied */
-);
-
-void pred_lt4_flt(
- const float excI[], /* i : input excitation buffer */
- float excO[], /* o : output excitation buffer */
- const int16_t T0, /* i : integer pitch lag */
- int16_t frac, /* i : fraction of lag */
- const int16_t L_subfr, /* i : subframe size */
- const float *win, /* i : interpolation window */
- const int16_t nb_coef, /* i : nb of filter coef */
- const int16_t up_sample /* i : up_sample */
-);
-
-void pred_lt4_tc_flt(
- float exc[], /* i : excitation buffer */
- const int16_t T0, /* i : integer pitch lag */
- int16_t frac, /* i : fraction of lag */
- const float *win, /* i : interpolation window */
- const int16_t imp_pos, /* i : glottal impulse position */
- const int16_t i_subfr /* i : subframe index */
-);
-
-void residu(
- const float *a, /* i : LP filter coefficients */
- const int16_t m, /* i : order of LP filter */
- const float *x, /* i : input signal (usually speech) */
- float *y, /* o : output signal (usually residual) */
- const int16_t l /* i : size of filtering */
-);
-
-void calc_residu(
- const float *speech, /* i : weighted speech signal */
- float *res, /* o : residual signal */
- const float *p_Aq, /* i : quantized LP filter coefficients */
- const int16_t L_frame /* i : size of frame */
-);
-
-/*! r: impulse response energy */
-float enr_1_Az(
- const float Aq[], /* i : LP filter coefs */
- const int16_t len /* i : impulse response length */
-);
-
-void Es_pred_enc(
- float *Es_pred, /* o : predicited scaled innovation energy */
- int16_t *Es_pred_indice, /* o : indice corresponding to above parameter */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t L_subfr, /* i : length of the subframe */
- const float *res, /* i : residual signal */
- const float *voicing, /* i : normal. correlattion in three 1/2frames */
- const int16_t nb_bits, /* i : allocated number of bits */
- const int16_t no_ltp /* i : no_ltp flag */
-);
-
-void create_offset(
- UWord32 *offset_scale1,
- UWord32 *offset_scale2,
- const int16_t mode,
- const int16_t prediction_flag );
-
-float mslvq(
- float *pTmp, /* i : M-dimensional input vector */
- float *quant, /* o : quantized vector */
- float *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */
- int16_t *idx_lead, /* o : leader index for each 8-dim subvector */
- int16_t *idx_scale, /* o : scale index for each subvector */
- const float *w, /* i : weights for LSF quantization */
- const int16_t mode, /* i : number indicating the coding mode */
- const int16_t mode_glb, /* i : LVQ coding mode */
- const int16_t pred_flag /* i : prediction flag (0: safety net, 1 - predictive )*/
-);
-
-void permute(
- float *pTmp1, /* i/o: vector whose components are to be permuted */
- const int16_t *perm /* i : permutation info (indexes that should be interchanged), max two perms */
-);
-
-void sort_desc_ind(
- float *s,
- const int16_t len,
- int16_t *ind );
-
-float mslvq_cng(
- int16_t idx_cv, /* i : index of cv from previous stage */
- float *pTmp, /* i : 16 dimensional input vector */
- float *quant, /* o : quantized vector */
- float *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */
- int16_t *idx_lead, /* o : leader index for each 8-dim subvector */
- int16_t *idx_scale, /* o : scale index for each subvector */
- const float *w /* i : weights for LSF quantization */
-);
-
-int16_t deindex_lvq_cng(
- int16_t *index, /* i : index to be decoded, as an array of 3 short */
- float *x_lvq, /* o : decoded codevector */
- const int16_t idx_cv, /* i : relative mode_lvq, wrt START_CNG */
- const int16_t no_bits /* i : number of bits for lattice */
-);
-
-void multiply32_32_64(
- UWord32 x, /* i : operand 1 */
- UWord32 y, /* i : operand 2 */
- UWord32 *res /* o : result as array of two uint32 */
-);
-
-int16_t deindex_lvq(
- int16_t *index, /* i : index to be decoded, as an array of 3 short */
- float *x_lvq, /* o : decoded codevector */
- const int16_t mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */
- const int16_t sf_flag, /* i : safety net flag */
- const int16_t no_bits /* i : number of bits for lattice */
-);
-
-void index_lvq(
- float *quant, /* i : codevector to be indexed (2 8-dim subvectors) */
- int16_t *idx_lead, /* i : leader class index for each subvector */
- int16_t *idx_scale, /* i : scale index for each subvector */
- const int16_t mode, /* i : integer signaling the quantizer structure for the current bitrate */
- int16_t *index, /* o : encoded index (represented on 3 short each with 15 bits ) */
- const int16_t prediction_flag /* i : predictive mode or not */
-);
-
-int16_t qlsf_ARSN_tcvq_Dec_16k(
- float *y, /* o : Quantized LSF vector */
- int16_t *indice, /* i : Indices */
- const int16_t nBits /* i : number of bits */
-);
-
-
-int16_t lsf_bctcvq_decprm_ivas(
- Decoder_State *st,
- int16_t *param_lpc );
-
-
-void disf_2s_36b(
- int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
- float *isf_q, /* o : quantized ISFs in the cosine domain */
- float *mem_AR, /* i/o: quantizer memory for AR model */
- float *mem_MA /* i/o: quantizer memory for MA model */
-);
-
-void disf_2s_46b(
- int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
- float *isf_q, /* o : quantized ISFs in the cosine domain */
- float *mem_AR, /* o : quantizer memory for AR model */
- float *mem_MA /* i/o: quantizer memory for MA model */
-);
-
-void re8_k2y(
- const int16_t *k, /* i : Voronoi index k[0..7] */
- const int16_t m, /* i : Voronoi modulo (m = 2^r = 1<=2) */
- int16_t *y /* o : 8-dimensional point y[0..7] in RE8 */
-);
-
-void re8_PPV(
- const float x[], /* i : point in R^8 */
- int16_t y[] /* o : point in RE8 (8-dimensional integer vector) */
-);
-
-void enhancer(
- const int16_t codec_mode, /* i : flag indicating Codec Mode */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t cbk_index, /* i : */
- const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- const int16_t coder_type, /* i : coding type */
- const int16_t L_frame, /* i : frame size */
- const float voice_fac, /* i : subframe voicing estimation */
- const float stab_fac, /* i : LP filter stablility measure */
- const float norm_gain_code, /* i : normalized innovative cb. gain */
- const float gain_inov, /* i : gain of the unscaled innovation */
- float *gc_threshold, /* i/o: code threshold */
- float *code, /* i/o: innovation */
- float *exc2, /* i/o: adapt. excitation/total exc. */
- const float gain_pit, /* i : Quantized pitch gain */
- float *dispMem /* i/o: Phase dispersion algorithm memory */
-);
-
-void phase_dispersion_flt(
- const float gain_code, /* i : gain of code */
- const float gain_pit, /* i : gain of pitch */
- float code[], /* i/o: code vector */
- const int16_t mode, /* i : level, 0=hi, 1=lo, 2=off */
- float disp_mem[] /* i/o: static memory (size = 8) */
-);
-
-void re8_vor(
- int16_t y[], /* i : point in RE8 (8-dimensional integer vector) */
- int16_t *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */
- int16_t k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 */
- int16_t c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */
- int16_t *ka /* o : identifier of absolute leader (needed to index c)*/
-);
-
-void DoRTFT480(
- float *x, /* i/o: real part of input and output data */
- float *y /* i/o: imaginary part of input and output data */
-);
-
-void DoRTFT320(
- float *x, /* i/o: real part of input and output data */
- float *y /* i/o: imaginary part of input and output data */
-);
-
-void DoRTFT160(
- float *x, /* i/o: real part of input and output data */
- float *y /* i/o: imaginary part of input and output data */
-);
-
-void DoRTFT128(
- float *x, /* i/o: real part of input and output data */
- float *y /* i/o: imaginary part of input and output data */
-);
-
-void DoRTFT120(
- float *x, /* i/o: real part of input and output data */
- float *y /* i/o: imaginary part of input and output data */
-);
-
-void DoRTFT80(
- float *x, /* i/o: real part of input and output data */
- float *y /* i/o: imaginary part of input and output data */
-);
-
-void DoRTFT20(
- float *x, /* i/o: real part of input and output data */
- float *y /* i/o: imaginary part of input and output data */
-);
-
-void DoRTFT40(
- float *x, /* i/o: real part of input and output data */
- float *y /* i/o: imaginary part of input and output data */
-);
-
-void DoRTFTn(
- float *x, /* i/o: real part of input and output data */
- float *y, /* i/o: imaginary part of input and output data */
- const int16_t n /* i : size of the FFT n=(2^k) up to 1024 */
-);
-
-void BASOP_cfft_ivas(
- Word32 *re, /* i/o: real part */
- Word32 *im, /* i/o: imag part */
- Word16 s, /* i : stride real and imag part */
- Word16 *scale /* i : scalefactor */
-);
-
-void fft(
- float *re, /* i/o: real part */
- float *im, /* i/o: imag part */
- const int16_t length, /* i : length of fft */
- const int16_t s /* i : sign */
-);
-
-void rfft(
- float *x, /* i/o: values */
- const float *w, /* i : window */
- const int16_t length, /* i : length of fft */
- const int16_t isign /* i : sign */
-);
-
-void sinq(
- const float tmp, /* i : sinus factor cos(tmp*i+phi) */
- const float phi, /* i : sinus phase cos(tmp*i+phi) */
- const int16_t N, /* i : size of output */
- float x[] /* o : output vector */
-);
-
-void edct2(
- const int16_t n,
- const int16_t isgn,
- float *in,
- float *a,
- const int16_t *ip,
- const float *w );
-
-void stat_noise_uv_mod(
- const int16_t coder_type, /* i : coder type */
- float noisiness, /* i : noisiness parameter */
- const float *const lsp_old, /* i : old LSP vector at 4th sfr */
- const float *const lsp_new, /* i : LSP vector at 4th sfr */
- const float *const lsp_mid, /* i : LSP vector at 2nd sfr */
- float *Aq, /* o : A(z) quantized for the 4 subframes */
- float *exc2, /* o : excitation buffer */
- const int16_t bfi, /* i : bad frame indicator */
- float *ge_sm, /* i/o: smoothed excitation gain */
- int16_t *uv_count, /* i/o: unvoiced counter */
- int16_t *act_count, /* i/o: activation counter */
- float lspold_s[], /* i/o: old LSP */
- int16_t *noimix_seed, /* i/o: mixture seed */
- float *st_min_alpha, /* i/o: minimum alpha */
- float *exc_pe, /* i/o: memory of the preemphasis filter */
- const int32_t bitrate, /* i : core bitrate */
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-void limit_band_noise_level_calc(
- const int16_t *wnorm, /* i : reordered norm of sub-vectors */
- int16_t *limit, /* o : highest band of bit allocation */
- const int32_t core_brate, /* i : core bitrate */
- float *noise_level /* o : noise level */
-);
-
-/*! r: hqswb_clas */
-int16_t peak_avrg_ratio(
- const int32_t total_brate, /* i : total bitrate */
- const float *input_hi, /* i : input signal */
- const int16_t N, /* i : number of coefficients */
- int16_t *mode_count, /* i/o: HQ_HARMONIC mode count */
- int16_t *mode_count1 /* i/o: HQ_NORMAL mode count */
-);
-
-/*! r: Number of coefficients in nf codebook */
-int16_t build_nf_codebook(
- const int16_t flag_32K_env_ho, /* i : Envelope attenuation hangover flag */
- const float *coeff, /* i : Coded spectral coefficients */
- const int16_t *sfm_start, /* i : Subband start indices */
- const int16_t *sfmsize, /* i : Subband widths */
- const int16_t *sfm_end, /* i : Subband end indices */
- const int16_t nb_sfm, /* i : Last coded band */
- const int16_t *R, /* i : Per-band bit allocation */
- float *CodeBook, /* o : Noise-fill codebook */
- float *CodeBook_mod /* o : Densified noise-fill codebook */
-);
-
-void apply_noisefill_HQ(
- const int16_t *R, /* i : bit allocation */
- const int16_t length, /* i : input frame length */
- const int16_t flag_32K_env_ho, /* i : envelope stability hangover flag */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t last_sfm, /* i : last coded subband */
- const float *CodeBook, /* i : Noise-fill codebook */
- const float *CodeBook_mod, /* i : Densified noise-fill codebook */
- const int16_t cb_size, /* i : Codebook length */
- const int16_t *sfm_start, /* i : Subband start coefficient */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- const int16_t *sfmsize, /* i : Subband band width */
- float *coeff /* i/o: coded/noisefilled spectrum */
-);
-
-void harm_bwe_fine(
- const int16_t *R, /* i : bit allocation */
- const int16_t last_sfm, /* i : last coded subband */
- const int16_t high_sfm, /* i : higher transition band to BWE */
- const int16_t num_sfm, /* i : total number of bands */
- const int16_t *norm, /* i : quantization indices for norms */
- const int16_t *sfm_start, /* i : Subband start coefficient */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- int16_t *prev_L_swb_norm, /* i/o: last normalize length */
- float *coeff, /* i/o: coded/noisefilled normalized spectrum */
- float *coeff_out, /* o : coded/noisefilled spectrum */
- float *coeff_fine /* o : BWE fine structure */
-);
-
-void hvq_bwe_fine(
- const int16_t last_sfm, /* i : last coded subband */
- const int16_t num_sfm, /* i : total number of bands */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- const int16_t *peak_idx, /* i : Peak index */
- const int16_t Npeaks, /* i : Number of peaks */
- int16_t *peak_pos, /* i/o: Peak positions */
- int16_t *prev_L_swb_norm, /* i/o: last normalize length */
- float *coeff, /* i/o: coded/noisefilled normalized spectrum */
- int16_t *bwe_peaks, /* o : Positions of peaks in BWE */
- float *coeff_fine /* o : HVQ BWE fine structure */
-);
-
-void hq_fold_bwe(
- const int16_t last_sfm, /* i : last coded subband */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- const int16_t num_sfm, /* i : Number of subbands */
- float *coeff /* i/o: coded/noisefilled normalized spectrum */
-);
-
-void apply_nf_gain(
- const int16_t nf_idx, /* i : noise fill gain index */
- const int16_t last_sfm, /* i : last coded subband */
- const int16_t *R, /* i : bit allocation */
- const int16_t *sfm_start, /* i : Subband start coefficient */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- float *coeff /* i/o: coded/noisefilled normalized spectrum */
-
-);
-
-void hq_generic_fine(
- float *coeff, /* i : coded/noisefilled normalized spectrum */
- const int16_t last_sfm, /* i : Last coded band */
- const int16_t *sfm_start, /* i : Subband start coefficient */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
- float *coeff_out1 /* o : HQ GENERIC input */
-);
-
-void harm_bwe(
- const float *coeff_fine, /* i : fine structure for BWE */
- const float *coeff, /* i : coded/noisefilled normalized spectrum */
- const int16_t num_sfm, /* i : Number of subbands */
- const int16_t *sfm_start, /* i : Subband start coefficient */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- const int16_t last_sfm, /* i : last coded subband */
- const int16_t high_sfm, /* i : higher transition band to BWE */
- const int16_t *R, /* i : bit allocation */
- const int16_t prev_hq_mode, /* i : previous hq mode */
- int16_t *norm, /* i/o: quantization indices for norms */
- float *noise_level, /* i/o: noise levels for harmonic modes */
- float *prev_noise_level, /* i/o: noise factor in previous frame */
- int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
- float *coeff_out, /* o : coded/noisefilled spectrum */
- const int16_t element_mode /* i : element mode */
-);
-
-void hvq_bwe(
- const float *coeff, /* i : coded/noisefilled spectrum */
- const float *coeff_fine, /* i : BWE fine structure */
- const int16_t *sfm_start, /* i : Subband start coefficient */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- const int16_t *sfm_len, /* i : Subband length */
- const int16_t last_sfm, /* i : last coded subband */
- const int16_t prev_hq_mode, /* i : previous hq mode */
- const int16_t *bwe_peaks, /* i : HVQ bwe peaks */
- const int16_t bin_th, /* i : HVQ transition bin */
- const int16_t num_sfm, /* i : Number of bands */
- const int32_t core_brate, /* i : Core bitrate */
- const int16_t *R, /* i : Bit allocation */
- int16_t *norm, /* i/o: quantization indices for norms */
- float *noise_level, /* i/o: noise levels for harmonic modes */
- float *prev_noise_level, /* i/o: noise factor in previous frame */
- int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
- float *coeff_out /* o : coded/noisefilled spectrum */
-);
-
-void hvq_concat_bands(
- const int16_t pvq_bands, /* i : Number of bands in concatenated PVQ target */
- const int16_t *sel_bnds, /* i : Array of selected high bands */
- const int16_t n_sel_bnds, /* i : Number of selected high bands */
- int16_t *hvq_band_start, /* o : Band start indices */
- int16_t *hvq_band_width, /* o : Band widths */
- int16_t *hvq_band_end /* o : Band end indices */
-);
-
-void hq_generic_bwe(
- const int16_t HQ_mode, /* i : HQ mode */
- float *coeff_out1, /* i/o: BWE input & temporary buffer */
- const float *hq_generic_fenv, /* i : SWB frequency envelopes */
- float *coeff_out, /* o : SWB signal in MDCT domain */
- const int16_t hq_generic_offset, /* i : frequency offset for representing hq generic*/
- int16_t *prev_L_swb_norm, /* i/o: last normalize length */
- const int16_t hq_generic_exc_clas, /* i : hq generic hf excitation class */
- const int16_t *sfm_end, /* i : End of bands */
- const int16_t num_sfm, /* i : Number of bands */
- const int16_t num_env_bands, /* i : Number of coded envelope bands */
- const int16_t *R /* i : Bit allocation */
-);
-
-void map_hq_generic_fenv_norm(
- const int16_t hqswb_clas, /* i : signal classification flag */
- const float *hq_generic_fenv, /* i : HQ GENERIC envelope */
- int16_t *ynrm, /* o : high band norm indices */
- int16_t *normqlg2, /* o : high band norm values */
- const int16_t num_env_bands, /* i : Number coded envelope bands */
- const int16_t nb_sfm, /* i : Number of envelope bands */
- const int16_t hq_generic_offset /* i : Freq offset for HQ GENERIC */
-);
-
-/*! r: Number of bits consumed for the delta coding */
-int16_t calc_nor_delta_hf(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const float *t_audio, /* i : transform-domain coefficients */
- int16_t *ynrm, /* i/o: norm indices */
- int16_t *Rsubband, /* i/o: sub-band bit allocation */
- const int16_t num_env_bands, /* i : Number coded envelope bands */
- const int16_t nb_sfm, /* i : Number of envelope bands */
- const int16_t *sfmsize, /* i : band length */
- const int16_t *sfm_start, /* i : Start index of bands */
- const int16_t core_sfm /* i : index of the end band for core */
-);
-
-/*! r: Number of bits consumed for the delta coding */
-int16_t get_nor_delta_hf(
- Decoder_State *st, /* i/o: Decoder state */
- int16_t *ynrm, /* i/o: norm indices */
- int16_t *Rsubband, /* i/o: sub-band bit allocation */
- const int16_t num_env_bands, /* i : Number coded envelope bands */
- const int16_t nb_sfm, /* i : Number of envelope bands */
- const int16_t core_sfm ); /* i : index of the end band for core */
-
-void hq_wb_nf_bwe(
- const float *coeff, /* i : coded/noisefilled normal. spectrum */
- const int16_t is_transient, /* i : is transient flag */
- const int16_t prev_bfi, /* i : previous bad frame indicator */
- const float *normq_v, /* i : norms */
- const int16_t num_sfm, /* i : Number of subbands */
- const int16_t *sfm_start, /* i : Subband start coefficient */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- const int16_t *sfmsize, /* i : Subband band width */
- const int16_t last_sfm, /* i : last coded subband */
- const int16_t *R, /* i : bit allocation */
- const int16_t prev_is_transient, /* i : previous transient flag */
- float *prev_normq, /* i/o: previous norms */
- float *prev_env, /* i/o: previous noise envelopes */
- int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
- float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */
- int16_t *prev_R, /* i/o: previous frame bit allocation info. */
- float *coeff_out /* o : coded/noisefilled spectrum */
-);
-
-/*! r: Number of bits */
-int16_t encode_envelope_indices(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t num_sfm, /* i : Number of subbands */
- const int16_t numnrmibits, /* i : Bitrate of fall-back coding mode */
- int16_t *difidx, /* i/o: Diff indices/encoded diff indices */
- int16_t *LCmode, /* o : Coding mode */
- const int16_t flag_pack, /* i : indicator of packing or estimating bits */
- const int16_t flag_HQ2, /* i : indicator of HQ2 core */
- const int16_t is_transient /* i : transient flag */
-);
-
-void diff_envelope_coding(
- const int16_t is_transient, /* i : transient indicator */
- const int16_t num_env_bands, /* i : number of envelope bands to code */
- const int16_t start_norm, /* i : start of envelope coding */
- int16_t *ynrm, /* i/o: quantization indices for norms */
- int16_t *normqlg2, /* i/o: quantized norms */
- int16_t *difidx /* o : differential code */
-);
-
-/*! r: Number of bits */
-int16_t decode_envelope_indices(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t start_norm, /* i : First SDE encoded norm */
- const int16_t num_sfm, /* i : Number of norms */
- const int16_t numnrmibits, /* i : Bitrate of fall-back coding mode */
- int16_t *ynrm, /* o : Decoded norm indices */
- const int16_t flag_HQ2, /* i : indicator of HQ2 core */
- const int16_t is_transient /* i : transient flag */
-);
-
-/*! r: Number of bits */
-void dequantize_norms(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t start_norm, /* i : First SDE encoded norm */
- const int16_t num_sfm, /* i : Number of norms */
- const int16_t is_transient, /* i : Transient flag */
- int16_t *ynrm, /* o : Decoded norm indices */
- int16_t *normqlg2 /* o : Log2 of decoded norms */
-);
-
-void hq_configure(
- const int16_t length, /* i : Frame length */
- const int16_t hqswb_clas, /* i : HQ SWB class */
- const int32_t core_brate, /* i : core bitrate */
- int16_t *num_sfm, /* o : Total number of subbands */
- int16_t *nb_sfm, /* o : Total number of coded bands */
- int16_t *start_norm, /* o : First norm to be SDE encoded */
- int16_t *num_sde_norm, /* o : Number of norms for SDE encoding */
- int16_t *numnrmibits, /* o : Number of bits in fall-back norm encoding */
- int16_t *hq_generic_offset, /* o : Freq offset for HQ GENERIC */
- int16_t *sfmsize, /* o : Subband bandwidths */
- int16_t *sfm_start, /* o : Subband start coefficients */
- int16_t *sfm_end /* o : Subband end coefficients */
-);
-
-/*! r: Consumed bits */
-int16_t hvq_enc(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t bwidth, /* i : audio bandwidth */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t hvq_bits, /* i : HVQ bit budget */
- const int16_t Npeaks, /* i : Number of peaks */
- const int16_t *ynrm, /* i : Envelope coefficients */
- int16_t *R, /* i/o: Bit allocation/updated bit allocation */
- int16_t *peaks, /* i/o: Peak pos. / Encoded peak pos. */
- float *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */
- float *noise_level, /* o : Quantized noise level */
- const float *pe_gains, /* i : Peak gains */
- const float *coefs, /* i : spectrum coefficients */
- float *coefs_out /* o : encoded spectrum coefficients */
-);
-/*! r: Consumed bits */
-int16_t hq_classifier_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const int32_t core_brate, /* i : Core bitrate */
- const int16_t length, /* i : Frame length */
- int16_t *is_transient, /* o : Transient flag */
- int16_t *hqswb_clas /* o : HQ class */
-);
-
-void hq_bit_allocation(
- const int32_t core_brate, /* i : Core bitrate */
- const int16_t length, /* i : Frame length */
- const int16_t hqswb_clas, /* i : HQ class */
- int16_t *num_bits, /* i/o: Remaining bit budget */
- const int16_t *normqlg2, /* i : Quantized norms */
- const int16_t nb_sfm, /* i : Number sub bands to be encoded */
- const int16_t *sfmsize, /* i : Sub band bandwidths */
- float *noise_level, /* o : HVQ noise level */
- int16_t *R, /* o : Bit allocation per sub band */
- int16_t *Rsubband, /* o : Fractional bit allocation (Q3) */
- int16_t *sum, /* o : Sum of allocated shape bits */
- int16_t *core_sfm, /* o : Last coded band in core */
- const int16_t num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */
-);
-
-void enforce_zero_for_min_envelope(
- const int16_t hqswb_clas, /* i : HQ coding class */
- const int16_t *ynrm, /* i : Envelope indices */
- float *coefsq, /* i/o: Quantized spectrum/zeroed spectrum */
- int16_t nb_sfm, /* i : Number of coded sub bands */
- const int16_t *sfm_start, /* i : Sub band start indices */
- const int16_t *sfm_end /* i : Sub band end indices */
-);
-
-void apply_envelope(
- const float *coeff, /* i/o: Coded/noisefilled normalized spectrum */
- const int16_t *norm, /* i : Envelope */
- const float *norm_adj, /* i : Envelope adjustment */
- const int16_t num_sfm, /* i : Total number of bands */
- const int16_t last_sfm, /* i : Last coded band */
- const int16_t HQ_mode, /* i : HQ mode */
- const int16_t length, /* i : Frame length */
- const int16_t *sfm_start, /* i : Sub band start indices */
- const int16_t *sfm_end, /* i : Sub band end indices */
- float *normq_v, /* o : Envelope with adjustment */
- float *coeff_out, /* o : coded/noisefilled spectrum */
- float *coeff_out1 /* o : noisefilled spectrum for HQ SWB BWE */
-);
-
-void apply_envelope_enc(
- float *coeff, /* i/o: Normalized/scaled normalized spectrum */
- const int16_t *norm, /* i : Envelope */
- const int16_t num_sfm, /* i : Total number of bands */
- const int16_t *sfm_start, /* i : Sub band start indices */
- const int16_t *sfm_end /* i : Sub band end indices */
-);
-
-/*! r: Leading_sign_index, index, size, k_val */
-PvqEntry mpvq_encode_vec(
- const int16_t *vec_in, /* i : Signed pulse train */
- const int16_t dim_in, /* i : Dimension */
- int16_t k_val_local /* i/o: Num unit pulses */
-);
-
-/*! r: Size, dim, k_val */
-PvqEntry get_size_mpvq_calc_offset(
- const int16_t dim_in, /* i : Dimension */
- const int16_t k_val_in, /* i : Num unit pulses */
- uint32_t *h_mem /* o : Offsets */
-);
-
-void mpvq_decode_vec(
- const PvqEntry *entry, /* i : Sign_ind, index, dim, k_val */
- uint32_t *h_mem, /* i : A/U offsets */
- int16_t *vec_out /* o : Pulse train */
-);
-
-/*! r: Multiplication result */
-uint32_t UMult_32_32(
- const uint32_t UL_var1, /* i : factor 1 */
- const uint32_t UL_var2 /* i : factor 2 */
-);
-
-/*! r: inverse */
-uint32_t UL_inverse_float(
- const uint32_t UL_val, /* i : input value Q_exp */
- int16_t *exp /* i/o: input exp / result exp */
-);
-
-/*! r: ratio */
-Word16 ratio_float(
- const Word32 numer, /* i : numerator */
- const Word32 denom, /* i : denominator */
- Word16 *expo /* i/o: input exp / result exp */
-);
-
-/*! r: Angle between 0 and EVS_PI/2 radian (Q14) */
-Word16 atan2_fx_flt(
- const Word32 y, /* i : near side (Argument must be positive) (Q15) */
- const Word32 x /* i : opposite side (Q15) */
-);
-
-void pvq_encode_frame(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const float *coefs_norm, /* i : normalized coefficients to encode */
- float *coefs_quant, /* o : quantized coefficients */
- float *gopt, /* o : optimal shape gains */
- int16_t *npulses, /* o : number of pulses per band */
- int16_t *pulse_vector, /* o : non-normalized pulse shapes */
- const int16_t *sfm_start, /* i : indices of first coefficients in the bands */
- const int16_t *sfm_end, /* i : indices of last coefficients in the bands */
- const int16_t *sfmsize, /* i : band sizes */
- const int16_t nb_sfm, /* i : total number of bands */
- const int16_t *R, /* i : bitallocation per band (Q3) */
- const int16_t pvq_bits, /* i : number of bits avaiable */
- const int16_t core /* i : core */
-);
-
-void pvq_decode_frame(
- Decoder_State *st, /* i/o: Decoder state */
- float *coefs_quant, /* o : quantized coefficients */
- int16_t *npulses, /* o : number of pulses per band */
- int16_t *pulse_vector, /* o : non-normalized pulse shapes */
- const int16_t *sfm_start, /* i : indices of first coeffs in the bands */
- const int16_t *sfm_end, /* i : indices of last coeffs in the bands */
- const int16_t *sfmsize, /* i : band sizes */
- const int16_t nb_sfm, /* i : total number of bands */
- const int16_t *R, /* i : bitallocation per band (Q3) */
- const int16_t pvq_bits, /* i : number of bits avaiable */
- const int16_t core /* i : core */
-);
-
-void srt_vec_ind(
- const int16_t *linear, /* linear input */
- int16_t *srt, /* sorted output */
- int16_t *I, /* index for sorted output */
- const int16_t length );
-
-void srt_vec_ind_f(
- const float *linear, /* linear input */
- float *srt, /* sorted output */
- int16_t *I, /* index for sorted output */
- const int16_t length /* length of vector */
-);
-
-/*! r: floor(sqrt(input)) */
-uint32_t floor_sqrt_exact(
- const uint32_t input /* i : unsigned input [0.. UINT_MAX/4] */
-);
-
-void fine_gain_quant(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t *ord, /* i : Indices for energy order */
- const int16_t num_sfm, /* i : Number of bands */
- const int16_t *gain_bits, /* i : Gain adjustment bits per sub band */
- float *fg_pred, /* i/o: Predicted gains / Corrected gains */
- const float *gopt /* i : Optimal gains */
-);
-
-void apply_gain(
- const int16_t *ord, /* i : Indices for energy order */
- const int16_t *band_start, /* i : Sub band start indices */
- const int16_t *band_end, /* i : Sub band end indices */
- const int16_t num_sfm, /* i : Number of bands */
- const float *gains, /* i : Band gain vector */
- float *xq /* i/o: float synthesis / gain adjusted synth */
-);
-
-void fine_gain_pred(
- const int16_t *sfm_start, /* i : Sub band start indices */
- const int16_t *sfm_end, /* i : Sub band end indices */
- const int16_t *sfm_size, /* i : Sub band bandwidths */
- const int16_t *i_sort, /* i : Energy sorting indices */
- const int16_t *K, /* i : Number of pulses per band */
- const int16_t *maxpulse, /* i : Maximum pulse per band */
- const int16_t *R, /* i : Bits per sub band (Q3) */
- const int16_t num_sfm, /* i : Number of sub bands */
- float *xq, /* i/o: Quantized vector /quantized vector with finegain adj */
- int16_t *y, /* i/o: Quantized vector */
- float *fg_pred, /* o : Predicted fine gains */
- const int16_t core /* i : Core */
-);
-
-void fine_gain_dec(
- Decoder_State *st, /* i/o: Decoder state struct */
- const int16_t *ord, /* i : Indices for energy order */
- const int16_t num_sfm, /* i : Number of bands */
- const int16_t *gain_bits, /* i : Gain adjustment bits per sub band */
- float *fg_pred /* i/o: Predicted gains / Corrected gains */
-);
-
-void get_max_pulses(
- const int16_t *band_start, /* i : Sub band start indices */
- const int16_t *band_end, /* i : Sub band end indices */
- const int16_t *k_sort, /* i : Indices for sorting by energy */
- const int16_t *npulses, /* i : Pulses per sub band */
- const int16_t BANDS, /* i : Number of bands */
- int16_t *inp_vector, /* i/o: Encoded shape vectors */
- int16_t *maxpulse /* o : Maximum pulse height per band */
-);
-
-Word32 ar_div_ivas(
- Word32 num,
- Word32 denum );
-
-void ar_encoder_start(
- PARCODEC arInst,
- TCQ_PBITSTREAM bsInst,
- int16_t max_bits );
-
-void ar_decoder_start(
- PARCODEC arInst,
- TCQ_PBITSTREAM bsInst );
-
-void ar_encoder_done(
- PARCODEC arInst );
-
-void ar_decoder_done(
- PARCODEC arInst );
-
-
-Word32 Mult_32_16(
- Word32 a,
- Word16 b );
-
-Word32 Mult_32_32(
- Word32 a,
- Word32 b );
-
-
-void decode_mangitude_tcq_fx_ivas(
- ARCODEC *pardec,
- Word16 size,
- Word16 npulses,
- Word16 nzpos,
- Word32 *positions,
- Word32 *out,
- Word32 *surplus_fx );
-
-void decode_signs_fx_ivas(
- ARCODEC *pardec,
- Word16 size,
- Word32 *out );
-
-void srt_vec_ind_fx_ivas(
- const Word32 *linear,
- Word32 *srt,
- Word16 *I,
- Word16 length );
-
-
-void bit_allocation_second_fx2(
- Word32 *Rk,
- Word32 *Rk_sort,
- Word16 BANDS,
- const Word16 *band_width,
- Word16 *k_sort,
- Word16 *k_num,
- const Word16 *p2a_flags,
- const Word16 p2a_bands,
- const Word16 *last_bitalloc,
- const Word16 input_frame );
-
-
-Word32 encode_magnitude_tcq_fx_ivas(
- ARCODEC *parenc,
- float *magn_fx,
- Word16 size,
- Word16 npulses,
- Word16 nzpos,
- Word32 *savedstates,
- Word32 *est_frame_bits_fx );
-
-Word32 encode_signs_fx_ivas(
- ARCODEC *parenc,
- float *magn,
- Word16 size,
- Word16 npos,
- Word32 *est_frame_bits_fx );
-
-Word32 encode_magnitude_usq_fx_ivas(
- ARCODEC *parenc,
- float *magn_fx,
- Word16 size,
- Word16 npulses,
- Word16 nzpos,
- Word32 *est_frame_bits_fx );
-
-ivas_error tcq_core_LR_enc(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- int32_t inp_vector[],
- const float coefs_norm[],
- float coefs_quant[],
- const int16_t bit_budget, /* number of bits */
- const int16_t nb_sfm,
- const int16_t *sfm_start,
- const int16_t *sfm_end,
- const int16_t *sfmsize,
- Word32 *Rk_fx,
- int16_t *npulses,
- int16_t *k_sort,
- const int16_t *p2a_flags,
- const int16_t p2a_bands,
- const int16_t *last_bitalloc,
- const int16_t input_frame,
- const int16_t adjustFlag,
- const int16_t is_transient );
-
-void tcq_core_LR_dec(
- Decoder_State *st,
- int32_t *inp_vector,
- const int16_t bit_budget,
- const int16_t bands,
- const int16_t *band_start,
- const int16_t *band_width,
- Word32 *Rk_fx,
- int16_t npulses[],
- int16_t *k_sort,
- const int16_t *p2a_flags,
- const int16_t p2a_bands,
- const int16_t *last_bitalloc,
- const int16_t input_frame,
- const int16_t adjustFlag,
- const int16_t *is_transient );
-
-
-void TCQLSB(
- int16_t bcount,
- float *abuffer,
- float *mbuffer,
- float *sbuffer,
- int16_t *dpath );
-
-void RestoreTCQ(
- float *magn,
- int16_t size,
- int16_t *bcount,
- float *mbuffer );
-
-void SaveTCQdata(
- PARCODEC arInst,
- int16_t *dpath,
- int16_t bcount );
-
-void LoadTCQdata(
- PARCODEC arInst,
- int16_t *dpath,
- int16_t bcount );
-
-void RestoreTCQdec(
- int32_t *magn,
- int16_t size,
- int16_t *bcount,
- float *mbuffer );
-
-void TCQLSBdec(
- int16_t *dpath,
- float *mbuffer,
- int16_t bcount );
-
-void bit_allocation_second_fx2(
- Word32 *Rk,
- Word32 *Rk_sort,
- Word16 BANDS,
- const Word16 *band_width,
- Word16 *k_sort,
- Word16 *k_num,
- const Word16 *p2a_flags,
- const Word16 p2a_bands,
- const Word16 *last_bitalloc,
- const Word16 input_frame );
-
-void io_ini_enc(
- const int32_t argc, /* i : command line arguments number */
- char *argv[], /* i : command line arguments */
- FILE **f_input, /* o : input signal file */
- FILE **f_stream, /* o : output bitstream file */
- FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */
- FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */
- FILE **f_metadata, /* o : metadata files (NULL if N/A) */
-#ifdef DEBUGGING
- FILE **f_force, /* o : force switching profile (0 if N/A) */
-#endif
- FILE **f_rf, /* o : channel aware configuration file */
- int16_t *quietMode, /* o : limit printouts */
- int16_t *noDelayCmp, /* o : turn off delay compensation */
- Encoder_Struct *st /* o : IVAS encoder structure */
-);
-
-void read_next_rfparam(
- int16_t *rf_fec_offset, /* o : RF offset */
- int16_t *rf_fec_indicator, /* o : RF FEC indicator */
- FILE *f_rf /* i : file pointer to read parameters */
-);
-
-void read_next_brate(
- int32_t *total_brate, /* i/o: total bitrate */
- const int32_t last_total_brate, /* i : last total bitrate */
- FILE *f_rate, /* i : bitrate switching profile (0 if N/A) */
- const int16_t element_mode, /* i : IVAS element mode */
- int32_t input_Fs, /* i : input sampling frequency */
- int16_t *Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- int16_t *Opt_SC_VBR, /* i/o: SC-VBR flag */
- int16_t *codec_mode /* i/o: Mode 1 or 2 */
-);
-
-void read_next_bwidth(
- int16_t *max_bwidth, /* i/o: maximum encoded bandwidth */
- FILE *f_bwidth, /* i : bandwidth switching profile (0 if N/A) */
- int32_t *bwidth_profile_cnt, /* i/o: counter of frames for bandwidth switching profile file */
- int32_t input_Fs /* i : input sampling rate */
-);
-
-#ifdef DEBUGGING
-void read_next_force(
- int16_t *force, /* i/o: force value (0/1, 0 = speech, 1 = music)*/
- FILE *f_force, /* i : force switching profile (0 if N/A) */
- int32_t *force_profile_cnt /* i/o: counter of frames for force switching profile file */
-);
-#endif
-
-ivas_error init_encoder_ivas_fx(
- Encoder_State *st, /* i/o: state structure */
- Encoder_Struct *st_ivas, /* i/o: encoder state structure */
- const Word16 idchan, /* i : channel ID */
- const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */
- const Word16 interval_SID, /* i : interval for SID update */
- const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */
- const ISM_MODE ism_mode, /* i : ISM mode */
- const Word32 element_brate /* i : element bitrate */
-);
-
-void LPDmem_enc_init(
- LPD_state_HANDLE hLPDmem /* i/o: LP memories */
-);
-
-ivas_error evs_enc(
- Encoder_State *st, /* i/o: state structure */
- const int16_t *data, /* i : input signal */
- float *mem_hp20_in, /* i/o: hp20 filter memory */
- const int16_t n_samples /* i : number of input samples */
-);
-void amr_wb_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t *data, /* i : input signal */
- float *mem_hp20_in, /* i/o: hp20 filter memory */
- const int16_t n_samples /* i : number of input samples */
-);
-
-void sc_vbr_enc_init(
- SC_VBR_ENC_HANDLE hSC_VBR /* i/o: SC-VBR encoder handle */
-);
-
-void amr_wb_enc_init(
- AMRWB_IO_ENC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO encoder handle */
-);
-
-void pre_proc(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t input_frame, /* i : frame length */
- float old_inp_12k8[], /* i/o: buffer of old input signal */
- float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */
- float **inp, /* o : ptr. to inp. signal in the current frame*/
- float fr_bands[2 * NB_BANDS], /* i : energy in frequency bands */
- float *ener, /* o : residual energy from Levinson-Durbin */
- int16_t pitch_orig[3], /* o : open-loop pitch values for quantization */
- float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */
- float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */
- float epsP[M + 1], /* i/o: LP prediction errors */
- float lsp_new[M], /* i/o: LSPs at the end of the frame */
- float lsp_mid[M], /* i/o: LSPs in the middle of the frame */
- int16_t *vad_hover_flag, /* i : VAD hangover flag */
- int16_t *attack_flag, /* o : attack flag */
- float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
- int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */
- float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */
- float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */
- int16_t *hq_core_type /* o : HQ core type */
-);
-
-
-/*! r: HQ_CORE/TCX_20_CORE decision */
-int16_t mdct_classifier(
- Encoder_State *st, /* i/o: Encoder state variable */
- const float *fft_buff, /* i : FFT spectrum from fft_rel */
- const float enerBuffer[], /* i : energy buffer */
- const int32_t brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */
-);
-
-void MDCT_selector(
- Encoder_State *st, /* i/o: Encoder State */
- const float sp_floor, /* i : Noise floor estimate */
- const float Etot, /* i : Total energy */
- const float cor_map_sum, /* i : sum of correlation map */
- const float enerBuffer[] /* i : energy buffer */
-);
-
-ivas_error acelp_core_enc_ivas_fx(
- Encoder_State *st, /* i/o: encoder state structure */
- const Word16 inp[], /* i : input signal of the current frame Q_new*/
- Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/
- Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/
- const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/
- Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/
- Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/
- const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/
- const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/
- Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/
- Word16 *voice_factors_fx, /* o : voicing factors Q15*/
- Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/
- Word16 *q_old_syn_12k8_16,
- Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/
- Word16 *unbits, /* o : number of unused bits Q0*/
- STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
- Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/
- Word16 Q_new );
-
-ivas_error acelp_core_switch_dec_bfi(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-void acelp_core_switch_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const float inp12k8[], /* i : input signal @12.8 kHz */
- const float inp16k[], /* i : input signal @16 kHz */
- const float A[NB_SUBFR16k * ( M + 1 )] /* i : A(z) unquantized for the 4 subframes */
-);
-
-/*! r: length of output */
-int16_t modify_Fs_intcub3m_sup(
- const float sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */
- const int16_t lg, /* i : length of input */
- const int32_t fin, /* i : frequency of input */
- float sigOut[], /* o : decimated signal */
- const int32_t fout, /* i : frequency of output */
- int16_t *delayout /* o : delay of output */
-);
-
-void core_switching_OLA(
- const float *mem_over_hp, /* i : upsampling filter memory */
- const int16_t last_L_frame, /* i : last L_frame lengthture */
- const int32_t output_Fs, /* i : output sampling rate */
- float *synth, /* i/o: synthesized signal from HQ core */
- const float *synth_subfr_out, /* i : synthesized signal from ACELP core */
- float *synth_subfr_bwe, /* i : synthesized BWE from ACELP core */
- const int16_t output_frame, /* i : output frame length */
- const int16_t bwidth /* i : output bandwidth */
-);
-
-void retro_interp4_5(
- const float *syn,
- float *pst_old_syn );
-
-void retro_interp5_4(
- float *pst_old_syn );
-void core_switching_hq_prepare_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t *num_bits, /* i/o: bit budget update */
- const int16_t input_frame /* i : input frame length */
-);
-
-ivas_error acelp_core_switch_dec(
- Decoder_State *st, /* i/o: decoder structure */
- float *synth_subfr_out, /* o : synthesized ACELP subframe */
- float *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE */
- const int16_t output_frame, /* i : input frame length */
- const int16_t core_switching_flag, /* i : core switching flag */
- float *mem_synth, /* o : synthesis to overlap */
- const int16_t nchan_out /* i : number of output channels */
-);
-
-void ResetSHBbuffer_Enc(
- TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */
-);
-
-void ResetSHBbuffer_Dec(
- TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- const int16_t extl /* i : BWE extension layer */
-);
-
-void calc_st_filt(
- const float *apond2, /* i : coefficients of numerator */
- const float *apond1, /* i : coefficients of denominator */
- float *parcor0, /* o : 1st parcor calcul. on composed filter */
- float *sig_ltp_ptr, /* i/o: input of 1/A(gamma1) : scaled by 1/g0 */
- float *mem_zero, /* i/o: All zero memory */
- const int16_t L_subfr, /* i : the length of subframe */
- const int16_t extl /* i : extension layer info */
-);
-
-
-void scale_st_ivas(
- const float *sig_in, /* i : postfilter input signal */
- float *sig_out, /* i/o: postfilter output signal */
- float *gain_prec, /* i/o: last value of gain for subframe */
- const int16_t L_subfr, /* i : the length of subframe */
- const int16_t extl /* i : extension layer info */
-);
-
-void filt_mu(
- const float *sig_in, /* i : signal (beginning at sample -1) */
- float *sig_out, /* o : output signal */
- const float parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */
- const int16_t L_subfr, /* i : the length of subframe */
- const int16_t extl /* i : extension layer info */
-);
-
-void PostShortTerm(
- float *sig_in, /* i : input signal (ptr. to current subframe */
- float *lpccoeff, /* i : LPC coefficients for current subframe */
- float *sig_out, /* o : postfiltered output */
- float *mem_stp, /* i/o: postfilter memory */
- float *ptr_mem_stp, /* i/o: pointer to postfilter memory */
- float *ptr_gain_prec, /* i/o: for gain adjustment */
- float *mem_zero, /* i/o: null memory to compute h_st */
- const float formant_fac /* i : Strength of post-filter [0,1] */
-);
-
-/*! r: Formant filter strength [0,1] */
-float swb_formant_fac(
- const float lpc_shb2, /* i : 2nd HB LPC coefficient */
- float *tilt_mem /* i/o: Tilt smoothing memory */
-);
-
-void GenShapedSHBExcitation(
- float *excSHB, /* o : synthesized shaped shb exctiation */
- const float *lpc_shb, /* i : lpc coefficients */
- float *exc16kWhtnd, /* o : whitened synthesized shb excitation */
- float *mem_csfilt, /* i/o: memory */
- float *mem_genSHBexc_filt_down_shb, /* i/o: memory */
- float *state_lpc_syn, /* i/o: memory */
- const int16_t coder_type, /* i : coding type */
- const float *bwe_exc_extended, /* i : bandwidth extended excitation */
- int16_t bwe_seed[], /* i/o: random number generator seed */
- float voice_factors[], /* i : voicing factor */
- const int16_t extl, /* i : extension layer */
- float *tbe_demph, /* i/o: de-emphasis memory */
- float *tbe_premph, /* i/o: pre-emphasis memory */
- float *lpc_shb_sf, /* i : LP coefficients */
- float *shb_ener_sf, /* i : SHB subframe energies */
- float *shb_res_gshape, /* i : SHB LP residual gain shape */
- float *shb_res, /* i : SHB residual used in encoder only */
- int16_t *vf_ind, /* i/o: Mixing factor index */
- const float formant_fac, /* i : Formant sharpening factor [0..1] */
- float fb_state_lpc_syn[], /* i/o: memory */
- float *fb_tbe_demph, /* i/o: fb de-emphasis memory */
- const int32_t total_brate, /* i : overall bitrate */
- const int16_t prev_bfi, /* i : previous frame was lost flag */
- const int16_t element_mode, /* i : element mode */
- const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */
- float *nlExc16k, /* i/o: NL exc for IC-BWE */
- float *mixExc16k, /* i/o: exc spreading for IC-BWE */
- const int32_t extl_brate, /* i : TD BWE bitrate */
- const int16_t MSFlag, /* i : Multi-source flag */
- float EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */
- float *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */
- float *prev_mix_factor, /* i/o: mixing factor in the previous frame */
- float *Env_error, /* o : error in SHB residual envelope modelling*/
- float Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */
-);
-
-void GenSHBSynth(
- const float *shb_target_speech, /* i : input synthesized speech */
- float *shb_syn_speech_32k, /* o : output highband component */
- float Hilbert_Mem[], /* i/o: memory */
- float state_lsyn_filt_shb_local[], /* i/o: memory */
- const int16_t L_frame, /* i : ACELP Frame length */
- int16_t *syn_dm_phase );
-
-void ScaleShapedSHB(
- const int16_t length, /* i : SHB overlap length */
- float *synSHB, /* i/o: synthesized shb signal */
- float *overlap, /* i/o: buffer for overlap-add */
- const float *subgain, /* i : subframe gain */
- const float frame_gain, /* i : frame gain */
- const float *win, /* i : window */
- const float *subwin /* i : subframes window */
-);
-
-void Interpolate_allpass_steep(
- const float *in, /* i : input array of size N */
- float *mem, /* i/o: memory */
- const int16_t N, /* i : number of input samples */
- float *out /* o : output array of size 2*N */
-);
-
-void Decimate_allpass_steep(
- const float *in, /* i : input array of size N */
- float *mem, /* i/o: memory */
- const int16_t N, /* i : number of input samples */
- float *out /* o : output array of size N/2 */
-);
-
-void interpolate_3_over_2_allpass(
- const float *input, /* i : input signal */
- const int16_t len, /* i : number of input samples */
- float *out, /* o : output signal */
- float *mem /* i/o: memory */
-);
-
-void decimate_2_over_3_allpass(
- const float *input, /* i : input signal */
- const int16_t len, /* i : number of input samples */
- float *out, /* o : output signal */
- float *mem, /* i/o: memory */
- float *lp_mem );
-
-void interpolate_3_over_1_allpass(
- const float *input, /* i : input signal */
- const int16_t len, /* i : number of input samples */
- float *out, /* o : output signal */
- float *mem /* i/o: memory */
-);
-
-void InitSWBencBuffer(
- TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */
-);
-
-void InitSWBencBufferStates(
- TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- float *shb_speech /* o : SHB target signal (6-14kHz) at 16kHz */
-);
-
-void swb_tbe_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */
- const float *new_speech, /* i : original input signal */
- const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
- const float voice_factors[], /* i : voicing factors */
- float *White_exc16k, /* o : shaped white excitation for the FB TBE */
- const float pitch_buf[] /* i : pitch for each subframe */
-);
-
-void swb_tbe_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */
- const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
- const float voice_factors[], /* i : voicing factors */
- const float old_syn_12k8_16k[], /* i : low band synthesis at 12.8kHz or 16kHz */
- float *White_exc16k, /* o : shaped white excitation for the FB TBE */
- float *synth, /* i/o: ACELP core synthesis/final synthesis */
- float *pitch_buf );
-
-void flip_and_downmix_generic(
- float input[], /* i : input spectrum */
- float output[], /* o : output spectrum */
- const int16_t length, /* i : length of spectra */
- float mem1_ext[HILBERT_ORDER1], /* i/o: Hilbert filter memory */
- float mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory */
- float mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory */
- int16_t *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */
-);
-void flip_and_downmix_generic_fx_32(
- Word32 input[], /* i : input spectrum Qx*/
- Word32 output[], /* o : output spectrum Qx*/
- const Word16 length, /* i : length of spectra */
- Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx*/
- Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/
- Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/
- Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */
-);
-void non_linearity(
- const float input[], /* i : input signal */
- float output[], /* i : output signal */
- float old_bwe_exc_extended[], /* i/o: memory bugffer */
- const int16_t length, /* i : input length */
- float *prev_scale, /* i/o: memory */
- const int16_t coder_type, /* i : Coder Type */
- const float *voice_factors, /* i : Voice Factors */
- const int16_t L_frame /* i : ACELP frame length */
-);
-
-void interp_code_5over2(
- const float inp_code[], /* i : input vector */
- float interp_code[], /* o : output vector */
- const int16_t inp_length /* i : length of the input vector */
-);
-
-void interp_code_4over2(
- const float inp_code[], /* i : input vector */
- float interp_code[], /* o : output vector */
- const int16_t inp_length /* i : length of the input vector */
-);
-
-void flip_spectrum_and_decimby4(
- const float input[], /* i : input spectrum */
- float output[], /* o : output spectrum */
- const int16_t length, /* i : vector length */
- float mem1[], /* i/o: memory */
- float mem2[], /* i/o: memory */
- const int16_t ramp_flag /* i : flag to trigger slow ramp-up of output */
-);
-
-void GenShapedWBExcitation(
- float *excSHB, /* o : synthesized shaped shb exctiation */
- const float *lpc_shb, /* i : lpc coefficients */
- float *exc4kWhtnd, /* o : whitened synthesized shb excitation */
- float *mem_csfilt, /* i/o: memory */
- float *mem_genSHBexc_filt_down1, /* i/o: memory */
- float *mem_genSHBexc_filt_down2, /* i/o: memory */
- float *mem_genSHBexc_filt_down3, /* i/o: memory */
- float *state_lpc_syn, /* i/o: memory */
- const int16_t coder_type, /* i : coding type */
- const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
- int16_t bwe_seed[], /* i/o: random number generator seed */
- const float voice_factors[], /* i : voicing factor */
- const int16_t uv_flag, /* i : unvoiced flag */
- const int16_t igf_flag );
-
-void GenWBSynth(
- const float *input_synspeech, /* i : input synthesized speech */
- float *shb_syn_speech_16k, /* o : output highband compnent */
- float *state_lsyn_filt_shb1, /* i/o: memory */
- float *state_lsyn_filt_shb2 /* i/o: memory */
-);
-
-void wb_tbe_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */
- const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
- const float pitch_buf[], /* i : pitch for each subframe */
- const float voicing[] /* o : OL maximum normalized correlation */
-);
-
-void wb_tbe_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const float *bwe_exc_extended, /* i : bandwidth extended exciatation */
- const float voice_factors[], /* i : voicing factors */
- float *synth /* i/o: ACELP core synthesis/final synthesis */
-);
-
-void tbe_write_bitstream(
- Encoder_State *st /* i/o: encoder state structure */
-);
-
-void tbe_read_bitstream(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-void GenTransition(
- TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- float *outputHB, /* o : synthesized HB transitions signal */
- const int32_t output_Fs, /* i : output sampling rate */
- const int16_t element_mode, /* i : element mode */
- const int16_t L_frame, /* i : ACELP frame length */
- const int16_t rf_flag, /* i : RF flag */
- const int32_t total_brate /* i : total bitrate */
-);
-
-
-void GenTransition_fixed(
- TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */
- const Word32 output_Fs, /* i : output sampling rate : Q0 */
- const Word16 element_mode, /* i : element mode : Q0 */
- const Word16 L_frame, /* i : ACELP frame length : Q0 */
- const Word16 rf_flag, /* i : RF flag : Q0 */
- const Word32 total_brate, /* i : total bitrate : Q0 */
- const Word16 prev_Qx );
-
-void GenTransition_WB(
- TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- float *outputHB, /* o : synthesized HB transitions signal */
- const int32_t output_Fs /* i : output sampling rate */
-);
-
-void GenTransition_WB_fixed(
- TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */
- const Word32 output_Fs /* i : output sampling rate */
-);
-
-void td_bwe_dec_init(
- TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- const int16_t extl, /* i : BWE extension layer */
- const int32_t output_Fs /* i : output sampling rate */
-);
-
-void TBEreset_enc(
- TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- const int16_t last_core, /* i : last core */
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-void TBEreset_dec(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-/*! r: TBE bit consumption per frame */
-int16_t get_tbe_bits(
- const int32_t total_brate, /* i : overall bitrate */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t rf_mode /* i : channel aware mode */
-);
-
-void fb_tbe_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const float new_input[], /* i : input speech at 48 kHz sample rate */
- const float fb_exc[] /* i : FB excitation from the SWB part */
-);
-
-void fb_tbe_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const float fb_exc[], /* i : FB excitation from the SWB part */
- float *hb_synth, /* i/o: high-band synthesis */
- float *fb_synth_ref, /* o : high-band synthesis 16-20 kHz */
- const int16_t output_frame /* i : output frame length */
-);
-
-void calc_tilt_bwe(
- const float *sp, /* i : input signal */
- float *tilt, /* o : signal tilt */
- const int16_t N /* i : signal length */
-);
-
-void fd_bwe_enc_init(
- FD_BWE_ENC_HANDLE hBWE_FD /* i/o: FD BWE data handle */
-);
-
-void swb_pre_proc(
- Encoder_State *st, /* i/o: encoder state structure */
- float *new_swb_speech, /* o : original input signal at 32kHz */
- float *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz */
- float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer */
- float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer */
- CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */
-);
-
-void wb_pre_proc(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t last_element_mode, /* i : last element mode */
- const float *new_inp_resamp16k, /* i : original input signal */
- float *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */
-);
-
-void wb_bwe_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *new_wb_speech /* i : original input signal at 16kHz */
-);
-
-void wb_bwe_dec_flt(
- Decoder_State *st, /* i/o: decoder state structure */
- const float output[], /* i : synthesis @internal Fs */
- float *synth, /* i/o: ACELP core synthesis/final synthesis */
- float *hb_synth, /* o : SHB synthesis/final synthesis */
- const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
- const int16_t output_frame, /* i : frame length */
- const float voice_factors[], /* i : voicing factors */
- const float pitch_buf[] /* i : pitch buffer */
-);
-
-void swb_bwe_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t last_element_mode, /* i : last element mode */
- const float *old_input_12k8, /* i : input signal @12.8kHz for SWB BWE */
- const float *old_input_16k, /* i : input signal @16kHz for SWB BWE */
- const float *old_syn_12k8_16k, /* i : ACELP core synthesis at 12.8kHz or 16kHz*/
- const float *new_swb_speech, /* i : original input signal at 32kHz */
- const float *shb_speech /* i : SHB target signal (6-14kHz) at 16kHz */
-);
-
-void swb_bwe_enc_hr(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *new_input, /* i : input signal */
- const int16_t input_frame, /* i : frame length */
- const int16_t unbits /* i : number of core unused bits */
-);
-
-void fd_bwe_dec_init_flt(
- FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */
-);
-
-void swb_bwe_dec_flt(
- Decoder_State *st, /* i/o: decoder state structure */
- const float output[], /* i : synthesis @internal Fs */
- const float *synth, /* i : ACELP core synthesis/final synthesis */
- float *hb_synth, /* o : SHB synthesis/final synthesis */
- const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
- const int16_t output_frame /* i : frame length */
-);
-
-void hr_bwe_dec_init_flt(
- HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */
-);
-
-void swb_bwe_dec_hr(
- Decoder_State *st, /* i/o: decoder state structure */
- const float *syn_12k8_16k, /* i : ACELP core synthesis @16kHz */
- float *hb_synth, /* o : SHB synthesis */
- const int16_t output_frame, /* i : frame length */
- const int16_t unbits, /* i : number of core unused bits */
- const float pitch_buf[] /* i : pitch buffer */
-);
-
-
-void calc_normal_length(
- const int16_t core, /* i : core */
- const float *sp, /* i : input signal */
- const int16_t mode, /* i : input mode */
- const int16_t extl, /* i : extension layer */
- int16_t *L_swb_norm, /* o : normalize length */
- int16_t *prev_L_swb_norm /* i/o: last normalize length */
-);
-
-void calc_norm_envelop(
- const float SWB_signal[], /* i : SWB spectrum */
- float *envelope, /* o : normalized envelope */
- const int16_t L_swb_norm, /* i : length of envelope */
- const int16_t SWB_flength, /* i : Length of input/output */
- const int16_t st_offset /* i : offset */
-);
-
-void time_envelop_shaping(
- float werr[], /* i/o: SHB synthesis */
- float SWB_tenv[], /* i/o: frequency envelope */
- const int16_t L /* i : frame length */
-);
-
-void time_reduce_pre_echo(
- const float *synth, /* i : ACELP core synthesis */
- float *error, /* o : SHB BWE synthesis */
- float prev_td_energy, /* o : last td energy */
- const int16_t L /* i : subframe length */
-);
-
-int16_t WB_BWE_gain_pred(
- float *WB_fenv, /* o : WB frequency envelopes */
- const float *core_dec_freq, /* i : Frequency domain core decoded signal */
- const int16_t coder_type, /* i : coding type */
- const int16_t prev_code_type, /* i : coding type of last frame */
- const float prev_WB_fenv, /* i : envelope for last frame */
- const float voice_factors[], /* i : voicing factors */
- const float pitch_buf[], /* i : pitch buffer */
- const int32_t last_core_brate, /* i : previous frame core bitrate */
- const float last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */
- const int16_t last_extl, /* i : extl. layer for last frame */
- const float tilt );
-
-void WB_BWE_decoding(
- const float *core_dec_freq, /* i : Frequency domain core decoded signal */
- float *WB_fenv, /* i : WB frequency envelopes */
- float *WB_signal, /* o : WB signal in MDCT domain */
- const int16_t WB_flength, /* i : Length of input/output */
- const int16_t mode, /* i : classification for WB signal */
- const int16_t last_extl, /* i : extl. layer for last frame */
- float *prev_Energy, /* i/o: energy for last frame */
- float *prev_WB_fenv, /* i/o: envelope for last frame */
- int16_t *prev_L_wb_norm, /* i/o: length for last frame wb norm */
- const int16_t extl, /* i : extension layer */
- const int16_t coder_type, /* i : coding type */
- const int32_t total_brate, /* i : core layer bitrate */
- int16_t *Seed, /* i/o: random generator seed */
- int16_t *prev_flag, /* i/o: attenu flag of last frame */
- int16_t prev_coder_type /* i : coding type of last frame */
-);
-
-void SWB_BWE_decoding(
- const float *core_dec_freq, /* i : Frequency domain core decoded signal */
- float *SWB_fenv, /* i/o: SWB frequency envelopes */
- float *SWB_signal, /* o : SWB signal in MDCT domain */
- const int16_t SWB_flength, /* i : Length of input/output */
- const int16_t mode, /* i : classification for SWB signal */
- int16_t *frica_flag, /* o : fricative signal flag */
- float *prev_Energy, /* i/o: energy for last frame */
- float *prev_SWB_fenv, /* i/o: envelope for last frame */
- int16_t *prev_L_swb_norm, /* i/o: length for last frame wb norm */
- const float tilt_nb, /* i : tilt of synthesis wb signal */
- int16_t *Seed, /* i/o: random generator seed */
- const int16_t st_offset, /* i : offset value due to different core */
- float *prev_weight, /* i/o: excitation weight value of last frame */
- const int16_t extl, /* i : extension layer */
- const int16_t last_extl /* i : extension layer of last frame */
-);
-
-void CNG_reset_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- float *pitch_buf, /* o : floating pitch for each subframe */
- float *voice_factors, /* o : voicing factors */
- int16_t VBR_cng_reset_flag );
-
-/*! r: stability flag */
-uint16_t a2rc(
- const float *a, /* i : LPC coefficients */
- float *refl, /* o : Reflection co-efficients */
- const int16_t lpcorder /* i : LPC order */
-);
-
-
-void analy_sp(
- const int16_t element_mode, /* i : element mode */
- CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
- const int32_t input_Fs, /* i : input sampling rate */
- float *speech, /* i : speech buffer */
- float *Bin_E, /* o : per bin log energy spectrum */
- float *Bin_E_old, /* o : per bin log energy spectrum for mid-frame */
- float *fr_bands, /* o : per band energy spectrum (2 analyses) */
- float lf_E[], /* o : per bin E for first VOIC_BINS bins (without DC) */
- float *Etot, /* o : total input energy */
- const int16_t min_band, /* i : minimum critical band */
- const int16_t max_band, /* i : maximum critical band */
- float *band_ener, /* o : energy in critical frequency bands without minimum noise floor E_MIN */
- float *PS, /* o : Per bin energy spectrum */
- float *fft_buff /* o : FFT coefficients */
-);
-
-void CNG_enc(
- Encoder_State *st, /* i/o: State structure */
- float Aq[], /* o : LP coefficients */
- const float *speech, /* i : pointer to current frame input speech buffer */
- float enr, /* i : frame energy output from Levinson recursion */
- const float *lsp_mid, /* i : mid frame LSPs */
- float *lsp_new, /* i/o: current frame LSPs */
- float *lsf_new, /* i/o: current frame LSFs */
- int16_t *allow_cn_step, /* o : allow CN step */
- float *q_env,
- int16_t *sid_bw );
-
-void swb_CNG_enc(
- Encoder_State *st, /* i/o: State structure */
- const float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */
- const float *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz */
-);
-
-void lsf_enc(
- Encoder_State *st, /* i/o: state structure */
- float *lsf_new, /* o : quantized LSF vector */
- float *lsp_new, /* i/o: LSP vector to quantize/quantized */
- float *lsp_mid, /* i : mid-frame LSP vector */
- float *Aq, /* o : quantized A(z) for 4 subframes */
- const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
- const int16_t GSC_IVAS_mode, /* i : GSC IVAS mode */
- const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */
-);
-
-void isf_enc_amr_wb(
- Encoder_State *st, /* i/o: state structure */
- float *isf_new, /* o : quantized ISF vector */
- float *isp_new, /* i/o: ISP vector to quantize/quantized */
- float *Aq /* o : quantized A(z) for 4 subframes */
-);
-
-void find_targets(
- const float *speech, /* i : pointer to the speech frame */
- const float *mem_syn, /* i : memory of the synthesis filter */
- const int16_t i_subfr, /* i : subframe index */
- float *mem_w0, /* i/o: weighting filter denominator memory */
- const float *p_Aq, /* i : interpolated quantized A(z) filter */
- const float *res, /* i : residual signal */
- const int16_t L_subfr, /* i : length of vectors for gain quantization */
- const float *Ap, /* i : unquantized A(z) filter with bandwidth expansion */
- const float tilt_fac, /* i : tilt factor */
- float *xn, /* o : Close-loop Pitch search target vector */
- float *cn, /* o : target vector in residual domain */
- float *h1 /* o : impulse response of weighted synthesis filter */
-);
-
-Word16 quant_2p_2N1_fx( /* o: return (2*N)+1 bits */
- const Word16 pos1, /* i: position of the pulse 1 */
- const Word16 pos2, /* i: position of the pulse 2 */
- const Word16 N /* i: number of bits FOR position */
-);
-void find_tilt(
- const float fr_bands[], /* i : energy in frequency bands */
- const float bckr[], /* i : per band background noise energy estimate */
- float ee[2], /* o : lf/hf E ration for present frame */
- const int16_t pitch[3], /* i : open loop pitch values for 3 half-frames */
- const float voicing[3], /* i : normalized correlation for 3 half-frames */
- const float *lf_E, /* i : per bin energy for low frequencies */
- const float corr_shift, /* i : normalized correlation correction */
- const int16_t bwidth, /* i : input signal bandwidth */
- const int16_t max_band, /* i : maximum critical band */
- float hp_E[], /* o : energy in HF */
- const int16_t codec_mode, /* i : Mode 1 or 2 */
- float *bckr_tilt_lt, /* i/o: lf/hf E ratio of background noise */
- int16_t Opt_vbr_mode );
-
-void init_gp_clip(
- float mem[] /* o : memory of gain of pitch clipping algorithm */
-);
-
-int16_t gp_clip(
- const int16_t element_mode, /* i : element mode */
- const int32_t core_brate, /* i : core bitrate */
- const float *voicing, /* i : normalized correlations (from OL pitch) */
- const int16_t i_subfr, /* i : subframe index */
- const int16_t coder_type, /* i : coding type */
- const float xn[], /* i : target vector */
- float mem[] /* i/o: memory of gain of pitch clipping algorithm */
-);
-
-void gp_clip_test_lsf(
- const int16_t element_mode, /* i : element mode */
- const int32_t core_brate, /* i : core bitrate */
- const float lsf[], /* i : LSF vector */
- float mem[], /* i/o: memory of gain of pitch clipping algorithm */
- const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */
-);
-
-void gp_clip_test_gain_pit(
- const int16_t element_mode, /* i : element mode */
- const int32_t core_brate, /* i : core bitrate */
- const float gain_pit, /* i : gain of quantized pitch */
- float mem[] /* i/o: memory of gain of pitch clipping algorithm */
-);
-
-void analy_lp(
- const float speech[], /* i : pointer to the denoised speech frame */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t L_look, /* i : look-ahead length */
- float *ener, /* o : residual signal energy */
- float A[], /* o : A(z) filter coefficients */
- float epsP[], /* o : LP analysis residual energies for each iteration */
- float lsp_new[], /* o : current frame ISPs */
- float lsp_mid[], /* o : current mid-frame ISPs */
- float lsp_old[], /* i/o: previous frame unquantized ISPs */
- const int16_t Top[2], /* i : open loop pitch lag */
- const float Tnc[2], /* i : open loop pitch gain */
- const int32_t sr_core, /* i : internal sampling rate */
- const int16_t sec_chan_low_rate /* i : TD secondary channel flag */
-);
-
-void analy_lp_AMR_WB(
- const float speech[], /* i : pointer to the speech frame */
- float *ener, /* o : residual energy from Levinson-Durbin */
- float A[], /* o : A(z) filter coefficients */
- float epsP[], /* o : LP analysis residual energies for each iteration */
- float isp_new[], /* o : current frame ISPs */
- float isp_old[], /* i/o: previous frame unquantized ISPs */
- float isf_new[], /* o : current frame ISFs */
- const int16_t Top, /* i : open loop pitch lag */
- const float Tnc /* i : open loop pitch gain */
-);
-
-void noise_est_init(
- NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */
-);
-
-void speech_music_clas_init(
- SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */
-);
-
-void long_enr(
- Encoder_State *st, /* i/o: encoder state structure */
- const float Etot, /* i : total channel energy */
- const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */
- const int16_t high_lpn_flag, /* i : sp/mus LPN flag */
- FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */
- const int16_t n_chan, /* i : number of channels */
- const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover LR channels */
- const float Etot_LR[] /* i : total channel energy LR channels */
-);
-
-void noise_est_pre(
- const float Etot, /* i : Energy of current frame */
- const int16_t ini_frame, /* i : Frame number (init) */
- NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation data handle */
- const int16_t idchan, /* i : channel ID */
- const int16_t element_mode, /* i : element mode */
- const int16_t last_element_mode /* i : last element mode */
-);
-
-void noise_est_down(
- const float fr_bands[], /* i : per band input energy (contains 2 vectors) */
- float bckr[], /* i/o: per band background noise energy estimate */
- float tmpN[], /* o : temporary noise update */
- float enr[], /* o : averaged energy over both subframes */
- const int16_t min_band, /* i : minimum critical band */
- const int16_t max_band, /* i : maximum critical band */
- float *totalNoise, /* o : noise estimate over all critical bands */
- const float Etot, /* i : Energy of current frame */
- float *Etot_last, /* i/o: Energy of last frame */
- float *Etot_v_h2 /* i/o: Energy variaions of noise frames */
-);
-
-void noise_est(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t old_pitch1, /* i : previous frame OL pitch[1] */
- const float tmpN[], /* i : temporary noise update */
- const float *epsP, /* i : LP prediction error energies */
- const float Etot, /* i : total channel E */
- const float relE, /* i : relative frame energy */
- const float corr_shift, /* i : normalized correlation correction */
- const float enr[], /* i : averaged energy over both subframes */
- float fr_bands[], /* i : spectrum per critical bands of the current frame */
- float *cor_map_sum, /* o : sum of correlation map from mult-harm analysis */
- float *ncharX, /* o : noise character for sp/mus classifier */
- float *sp_div, /* o : soectral diversity feature */
- float *non_staX, /* o : non-stationarity for sp/mus classifier */
- int16_t *loc_harm, /* o : multi-harmonicity flag for UV classifier */
- const float *lf_E, /* i : per bin energy for low frequencies */
- int16_t *st_harm_cor_cnt, /* i : 1st harm correlation timer */
- const float Etot_l_lp, /* i : Smoothed low energy */
- float *sp_floor, /* o : noise floor estimate */
- float S_map[], /* o : short-term correlation map */
- STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */
- FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */
- const int16_t ini_frame /* i : Frame number (init) */
-);
-
-void vad_param_updt(
- Encoder_State *st, /* i/o: encoder state structure */
- const float corr_shift, /* i : correlation shift */
- const float corr_shiftR, /* i : correlation shift right channel */
- const float A[], /* i : A(z) unquantized for the 4 subframes */
- const int16_t old_pitch1, /* i : previous frame OL pitch[1] */
- FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */
- const int16_t n_channels /* i : number of channels */
-);
-
-
-void lp_gain_updt(
- const int16_t i_subfr, /* i : subframe number */
- const float gain_pit, /* i : Decoded gain pitch */
- const float norm_gain_code, /* i : Normalised gain code */
- float *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) */
- float *lp_gainc, /* i/o: LP-filtered code gain (FEC) */
- const int16_t L_frame /* i : length of the frame */
-);
-
-void GSC_enc_init(
- GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */
-);
-
-
-/*! r: index of the last band where pitch contribution is significant */
-int16_t Pit_exc_contribution_len(
- Encoder_State *st, /* i/o: state structure */
- const float *dct_res, /* i : DCT of residual */
- float *dct_pitex, /* i/o: DCT of pitch contribution */
- float *pitch_buf, /* i/o: Pitch per subframe */
- int16_t *hangover /* i : Hangover for the time contribution switching */
-);
-
-int16_t stab_est(
- float etot, /* i : Total energy of the current frame */
- float *lt_diff_etot, /* i/o: Long term total energy variation */
- float *mem_etot, /* i/o: Total energy memory */
- int16_t *nb_thr_3, /* i/o: Number of consecutives frames of level 3 */
- int16_t *nb_thr_1, /* i/o: Number of consecutives frames of level 1 */
- float *thresh, /* i/o: Detection thresold */
- int16_t *last_music_flag, /* i/o: Previous music detection ouptut */
- const int16_t vad_flag /* i : VAD flag */
-);
-
-float gsc_gainQ(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t element_mode, /* i : element mode */
- const int16_t idchan, /* i : channel ID */
- const float y_gain4[], /* i : gain per band */
- float y_gainQ[], /* o : quantized gain per band */
- const int32_t core_brate, /* i : Core rate */
- const int16_t coder_type, /* i : coding type */
- const int16_t bwidth, /* i : input signal bandwidth */
- const int16_t L_frame, /* i : frame length */
- const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */
- const int32_t core_brate_inp /* i : true core brate */
-);
-
-void Comp_and_apply_gain(
- float exc_diffQ[], /* i/o: gain per band */
- float Ener_per_bd_iQ[], /* o : Quant Ener per band */
- float Ener_per_bd_yQ[], /* o : Ener per band for quantize y */
- int16_t Mbands_gn, /* i : number of bands */
- const int16_t ReUseGain /* i : Reuse the gain in Ener_per_bd_yQ */
-);
-
-void bands_and_bit_alloc_ivas_fx(
- const Word16 cor_strong_limit, /* i : HF correlation */
- const Word16 noise_lev, /* i : dwn scaling factor */
- const Word32 core_brate, /* i : core bit rate */
- const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/
- const Word16 bits_used, /* i : Number of bit used before frequency Q */
- Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */
- const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */
- Word16 *max_ener_band, /* o : Sorted order */
- Word16 *out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */
- Word16 *nb_subbands, /* o : Number of subband allowed */
- const Word16 *exc_diff, /* i : Difference signal to quantize (encoder side only) */
- Word16 *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */
- Word16 *pvq_len, /* o : Number of bin covered with the PVQ */
- const Word16 coder_type, /* i : coding type */
- const Word16 bwidth, /* i : input signal bandwidth */
- const Word16 GSC_noisy_speech, /* i : GSC noisy speech flag */
- const Word16 L_frame, /* i : frame length */
- const Word16 element_mode, /* i : element mode */
- const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */
-);
-
-void GSC_dec_init_ivas(
- GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */
-);
-
-void decod_audio(
- Decoder_State *st, /* i/o: decoder static memory */
- float dct_epit[], /* o : GSC excitation in DCT domain */
- const float *Aq, /* i : LP filter coefficient */
- float *tmp_noise, /* o : long term temporary noise energy */
- float *pitch_buf, /* o : floating pitch values for each subframe */
- float *voice_factors, /* o : voicing factors */
- float *exc_dct_in, /* i/o: adapt. excitation exc */
- float *exc2, /* i/o: adapt. excitation/total exc */
- float *bwe_exc, /* o : excitation for SWB TBE */
- float *lsf_new, /* i : current frame ISF vector */
- float *gain_buf, /* o : floating pitch gain for each subframe */
- const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag */
- const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
- const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-);
-
-void gsc_dec(
- Decoder_State *st, /* i/o: State structure */
- float exc_dct_in[], /* i/o: dct of pitch-only/total excitation */
- const int16_t pit_band_idx, /* i : pitch band index */
- const int16_t Diff_len, /* i : */
- const int16_t bits_used, /* i : total number of bits used */
- const int16_t nb_subfr, /* i : Number of subframe considered */
- const int16_t coder_type, /* i : coding type */
- int16_t *last_bin, /* i : last bin of bit allocation */
- const float *lsf_new, /* i : ISFs at the end of the frame */
- float *exc_wo_nf, /* o : excitation (in f domain) without noisefill*/
- float *tmp_noise /* o : long-term noise energy */
-);
-
-void dec_pit_exc(
- Decoder_State *st, /* i/o: decoder static memory */
- const int16_t L_frame, /* i : length of the frame */
- const float *Aq, /* i : LP filter coefficient */
- const float Es_pred, /* i : predicted scaled innov. energy */
- float *pitch_buf, /* o : floating pitch values for each subframe */
- float *code, /* o : innovation */
- float *exc, /* i/o: adapt. excitation exc */
- const int16_t nb_subfr, /* i : Number of subframe considered */
- float *gain_buf, /* o : floating pitch gain for each subframe */
- const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-);
-
-void music_postfilt_init_flt(
- MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */
-);
-
-void LD_music_post_filter(
- MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */
- const float dtc_in[], /* i : input synthesis */
- float dtc_out[], /* o : output synthesis */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t coder_type, /* i : Coder type : -1 in case of IO */
- const int16_t Last_coder_type /* i : last Coder type */
-);
-
-void Post_music_postP(
- float dct_buffer_in[], /* i/o: excitation buffer */
- float exc_buffer_out[], /* o : DCT output buffer */
- float *exc2, /* i/o: Current excitation to be overwriten */
- const float *mem_tmp, /* i : previous frame synthesis memory */
- float *st_mem_syn2, /* i/o: current frame synthesis memory */
- const float *Aq, /* i : LPC filter coefficients */
- float *syn /* i/o: 12k8 synthesis */
-);
-
-void Prep_music_postP(
- float exc_buffer_in[], /* i/o: excitation buffer */
- float dct_buffer_out[], /* o : DCT output buffer */
- float filt_lfE[], /* i/o: long term spectrum energy */
- const int16_t last_core, /* i : last core */
- const float *pitch_buf, /* i : current frame pitch information */
- float *LDm_enh_lp_gbin /* o : smoothed suppression gain, per bin FFT */
-);
-
-void speech_music_classif(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *new_inp, /* i : new input signal */
- const float *inp, /* i : input signal to locate attach position */
- const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */
- const float lsp_new[M], /* i : LSPs in current frame */
- const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */
- const float epsP[M + 1], /* i : LP prediciton error */
- const float PS[], /* i : energy spectrum */
- const float Etot, /* i : total frame energy */
- const float old_cor, /* i : max correlation from previous frame */
- int16_t *attack_flag, /* o : attack flag (GSC or TC) */
- const float non_staX, /* i : unbound non-stationarity for sp/mus classifier */
- const float relE, /* i : relative frame energy */
- int16_t *high_lpn_flag, /* o : sp/mus LPN flag */
- const int16_t flag_spitch /* i : flag to indicate very short stable pitch */
-);
-void ivas_find_wsp_fx(
- const Word16 L_frame, /* i : length of the frame Q0*/
- const Word16 L_subfr, /* i : length of subframe Q0*/
- const Word16 nb_subfr, /* i : number of subframes Q0*/
- const Word16 *A_fx,
- /* i : A(z) filter coefficients */ // Q12
- Word16 *Aw_fx,
- /* o : weighted A(z) filter coefficients */ // Q12
- const Word16 *speech_fx,
- /* i : pointer to the denoised speech frame */ // Q_new
- const Word16 tilt_fact,
- /* i : tilt factor */ // Q15
- Word16 *wsp_fx,
- /* o : poitnter to the weighted speech frame */ // Q_new
- Word16 *mem_wsp_fx,
- /* i/o: W(Z) denominator memory */ // Q_new
- const Word16 gamma,
- /* i : weighting factor */ // Q15
- const Word16 L_look /* i : look-ahead Q0*/
-);
-
-void gain_enc_amr_wb(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const float *xn, /* i : target vector */
- const float *y1, /* i : zero-memory filtered adaptive excitation */
- const float *y2, /* i : zero-memory filtered algebraic codebook excitation */
- const float *code, /* i : algebraic excitation */
- const int32_t core_brate, /* i : core bitrate */
- float *gain_pit, /* i/o: Pitch gain / Quantized pitch gain */
- float *gain_code, /* o : Quantized codebook gain */
- float *gain_inov, /* o : innovation gain */
- float *norm_gain_code, /* o : norm. gain of the codebook excitation */
- float *coeff, /* i/o: correlations , -2,, -2 and 2 */
- const int16_t clip_gain, /* i : gain pitch clipping flag (1 = clipping) */
- float *past_qua_en /* i/o: gain quantization memory (4 words) */
-);
-
-void gain_enc_lbr(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t gains_mode[], /* i : gain bits */
- const int16_t coder_type, /* i : coding type */
- const int16_t i_subfr, /* i : subframe index */
- const float *xn, /* i : target vector */
- const float *y1, /* i : zero-memory filtered adaptive excitation */
- const float *y2, /* i : zero-memory filtered algebraic codebook excitation */
- const float *code, /* i : algebraic excitation */
- float *gain_pit, /* o : quantized pitch gain */
- float *gain_code, /* o : quantized codebook gain */
- float *gain_inov, /* o : gain of the innovation (used for normalization) */
- float *norm_gain_code, /* o : norm. gain of the codebook excitation */
- float *g_corr, /* i/o: correlations , -2,, -2 and 2 */
- float gains_mem[], /* i/o: pitch gain and code gain from previous subframes */
- const int16_t clip_gain, /* i : gain pitch clipping flag (1 = clipping) */
- const int16_t L_subfr /* i : subfr Lenght */
-);
-
-void gain_enc_mless(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t gains_mode[], /* i : gain bits */
- const int16_t element_mode, /* i : element mode */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t i_subfr, /* i : subframe index */
- const int16_t tc_subfr, /* i : TC subframe index */
- const float *xn, /* i : target vector */
- const float *y1, /* i : zero-memory filtered adaptive excitation */
- const float *y2, /* i : zero-memory filtered algebraic codebook excitation */
- const float *code, /* i : algebraic excitation */
- const float Es_pred, /* i : predicted scaled innovation energy */
- float *gain_pit, /* o : quantized pitch gain */
- float *gain_code, /* o : quantized codebook gain */
- float *gain_inov, /* o : innovation gain */
- float *norm_gain_code, /* o : norm. gain of the codebook excitation */
- float *coeff, /* i/o: correlations , -2,, -2 and 2 */
- const int16_t clip_gain /* i : gain pitch clipping flag (1 = clipping) */
-);
-
-void gain_enc_SQ(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t gains_mode[], /* i : gain bits */
- const int16_t i_subfr, /* i : subframe index */
- const float *xn, /* i : target vector */
- const float *yy1, /* i : zero-memory filtered adaptive excitation */
- const float *y2, /* i : zero-memory filtered algebraic codebook excitation */
- const float *code, /* i : algebraic excitation */
- const float Es_pred, /* i : predicted scaled innovation energy */
- float *gain_pit, /* o : quantized pitch gain */
- float *gain_code, /* o : quantized codebook gain */
- float *gain_inov, /* o : gain of the innovation (used for normalization) */
- float *norm_gain_code, /* o : norm. gain of the codebook excitation */
- float *g_corr, /* i/o: correlations , -2,, -2 and 2 */
- const int16_t clip_gain /* i : gain pitch clipping flag (1 = clipping) */
-);
-
-/*! r: Return index of quantization */
-int16_t gain_enc_gaus(
- float *gain, /* i/o: Code gain to quantize */
- const int16_t bits, /* i : number of bits to quantize */
- const float lowBound, /* i : lower bound of quantizer (dB) */
- const float topBound /* i : upper bound of quantizer (dB) */
-);
-
-void E_corr_xy2(
- const float xn[], /* i : target vector */
- const float y1[], /* i : filtered excitation components 1 */
- const float y2[], /* i : filtered excitation components 2 */
- float g_corr[], /* o : correlations between x, y1, y2, y3, y4 */
- const int16_t L_subfr /* i : subframe size */
-);
-
-
-/*! r: coding type */
-int16_t find_uv(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *pitch_fr, /* i : pointer to adjusted fractional pitch (4 val.) */
- const float *voicing_fr, /* i : refined correlation for each subframes */
- const float *speech, /* i : pointer to speech signal for E computation */
- const float *ee, /* i : lf/hf Energy ratio for present frame */
- float *dE1X, /* o : sudden energy increase for S/M classifier */
- const float corr_shift, /* i : normalized correlation correction in noise */
- const float relE, /* i : relative frame energy */
- const float Etot, /* i : total energy */
- const float hp_E[], /* i : energy in HF */
- int16_t *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */
- const int16_t last_core_orig, /* i : original last core */
- STEREO_CLASSIF_HANDLE hStereoClf /* i/o: stereo classifier structure */
-);
-
-/*! r: classification for current frames */
-int16_t signal_clas(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *speech, /* i : pointer to speech signal for E computation */
- const float *ee, /* i : lf/hf E ration for 2 half-frames */
- const float relE, /* i : frame relative E to the long term average */
- const int16_t L_look, /* i : look-ahead */
- int16_t *clas_mod /* o : class flag for NOOP detection */
-);
-
-void select_TC(
- const int16_t codec_mode, /* i : codec mode */
- const int16_t tc_cnt, /* i : TC frame counter */
- int16_t *coder_type, /* i/o: coder type */
- const int16_t localVAD /* i : VAD without hangover */
-);
-
-
-void wb_vad_init(
- VAD_HANDLE hVAD /* i/o: VAD data handle */
-);
-
-int16_t dtx_hangover_addition(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t vad_flag, /* i : VAD flag */
- const float snr, /* i : input single SNR estimate */
- const int16_t cldfb_subtraction, /* i : */
- int16_t *vad_hover_flag, /* o : VAD hangover flag */
- VAD_HANDLE hVAD, /* i/o: VAD handle for L or R channel */
- NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */
- int16_t *rem_dtx_ho /* o : Expected remaining hangover frames */
-);
-
-int16_t wb_vad(
- Encoder_State *st, /* i/o: encoder state structure */
- const float fr_bands[], /* i : per band input energy (contains 2 vectors) */
- int16_t *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */
- int16_t *clean_speech_HO, /* o : SC-VBR clean speech HO flag */
- int16_t *NB_speech_HO, /* o : SC-VBR NB speech HO flag */
- float *snr_sum_he, /* i : voicing metric from SAD */
- int16_t *localVAD_HE_SAD, /* o : HE_SAD decision without hangovers */
- int16_t *flag_noisy_speech_snr, /* o : */
- VAD_HANDLE hVAD, /* i/o: VAD handle */
- NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */
- float lp_speech, /* i : long term active speech energy average */
- float lp_noise /* i : long term noise energy */
-);
-
-void bw_detect(
- Encoder_State *st, /* i/o: Encoder State */
- const float signal_in[], /* i : input signal */
- float *spectrum, /* i : MDCT spectrum */
- const float *enerBuffer, /* i : energy buffer */
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- const int16_t mct_on /* i : flag MCT mode */
-);
-
-void set_bw(
- const int16_t element_mode, /* i : element mode */
- const int32_t element_brate, /* i : element bitrate */
- Encoder_State *st, /* i/o: Encoder State */
- const int16_t codec_mode /* i : codec mode */
-);
-
-float gaus_encode(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t i_subfr, /* i : subframe index */
- const float *h1, /* i : weighted filter input response */
- const float *xn, /* i : target vector */
- float *exc, /* o : pointer to excitation signal frame */
- float *mem_w0, /* o : weighting filter denominator memory */
- float *gp_clip_mem, /* o : memory of gain of pitch clipping algorithm */
- float *tilt_code, /* o : synthesis excitation spectrum tilt */
- float *code, /* o : algebraic excitation */
- float *gain_code, /* o : Code gain. */
- float *y2, /* o : zero-memory filtered adaptive excitation */
- float *gain_inov, /* o : innovation gain */
- float *voice_fac, /* o : voicing factor */
- float *gain_pit, /* o : adaptive excitation gain */
- float *norm_gain_code /* o : normalized innovative cb. gain */
-);
-
-void td_cng_enc_init(
- TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */
- const int16_t Opt_DTX_ON, /* i : flag indicating DTX operation */
- const int16_t max_bwidth /* i : maximum encoded bandwidth */
-);
-
-void dtx(
- Encoder_State *st, /* i/o: encoder state structure */
- const int32_t ivas_total_brate, /* i : IVAS total bitrate */
- const int16_t vad, /* i : VAD flag for DTX */
- const float speech[] /* i : Pointer to the speech frame */
-);
-
-void dtx_hangover_control(
- Encoder_State *st, /* i/o: encoder state structure */
- const float lsp_new[M] /* i : current frame LSPs */
-);
-
-
-void updt_enc_common(
- Encoder_State *st /* i/o: encoder state structure */
-);
-
-void updt_IO_switch_enc(
- Encoder_State *st, /* i/o: state structure */
- const int16_t input_frame /* i : input frame length */
-);
-
-void transition_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t i_subfr, /* i : subframe index */
- int16_t *tc_subfr, /* i/o: TC subframe index */
- int16_t *Jopt_flag, /* i : joint optimization flag */
- int16_t *position, /* i/o: maximum of residual signal index */
- int16_t *T0, /* i/o: close loop integer pitch */
- int16_t *T0_frac, /* i/o: close loop fractional part of the pitch */
- int16_t *T0_min, /* i/o: lower limit for close-loop search */
- int16_t *T0_max, /* i/o: higher limit for close-loop search */
- float *exc, /* i/o: pointer to excitation signal frame */
- float *y1, /* o : zero-memory filtered adaptive excitation */
- const float *h1, /* i : weighted filter input response */
- const float *xn, /* i : target vector */
- float *xn2, /* o : target vector for innovation search */
- float *gp_cl, /* i/o: memory of gain of pitch clipping algorithm */
- float *gain_pit, /* o : adaptive excitation gain */
- float *g_corr, /* o : ACELP correlation values */
- int16_t *clip_gain, /* i/o: adaptive gain clipping flag */
- float **pt_pitch, /* o : floating pitch values */
- float *bwe_exc, /* i/o: excitation for SWB TBE */
- int16_t *unbits /* i/o: unused bits */
-);
-
-void tc_classif_enc(
- const int16_t L_frame, /* i : length of the frame */
- int16_t *tc_subfr, /* i/o: TC subframe index */
- int16_t *position, /* i/o: maximum of residual signal index */
- const int16_t attack_flag, /* i : attack flag */
- const int16_t pitch, /* i : open loop pitch estimates for first halfframe */
- const float *res /* i : pointer to the LP residual signal frame */
-);
-
-
-void gain_enc_tc(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t gains_mode[], /* i : gain bits */
- const int16_t i_subfr, /* i : subframe index */
- const float xn[], /* i : target vector */
- const float y2[], /* i : zero-memory filtered algebraic codebook excitation */
- const float code[], /* i : algebraic excitation */
- const float Es_pred, /* i : predicted scaled innovation energy */
- float *gain_pit, /* o : pitch gain / Quantized pitch gain */
- float *gain_code, /* o : quantized codebook gain */
- float *gain_inov, /* o : innovation gain */
- float *norm_gain_code /* o : norm. gain of the codebook excitation */
-);
-
-
-/*! r: comfort noise gain factor */
-float AVQ_cod(
- const float xri[], /* i : vector to quantize */
- int16_t xriq[], /* o : quantized normalized vector (assuming the bit budget is enough) */
- const int16_t nb_bits, /* i : number of allocated bits */
- const int16_t Nsv /* i : number of subvectors (lg=Nsv*8) */
-);
-
-void AVQ_encmux(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const int16_t extl, /* i : extension layer */
- int16_t xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */
- int16_t *nb_bits, /* i/o: number of allocated bits */
- const int16_t Nsv, /* i : number of subvectors */
- int16_t nq[], /* o : AVQ nq index */
- int16_t avq_bit_sFlag, /* i : flag indicating AVQ bit savings */
- int16_t trgtSvPos /* i : target SV for AVQ bit savings */
-);
-
-void ordr_esti(
- const int16_t k, /* i : sub-vector index */
- int16_t *Mpos, /* i/o: dominant sub-vector position from ACV */
- int16_t svOrder[], /* i/o: AVQ sub-vector order */
- const int16_t Nsv /* i : total sub-vectors in a sub-frames */
-);
-
-void re8_cod(
- int16_t x[], /* i : point in RE8 (8-dimensional integer vector) */
- int16_t *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */
- uint16_t *I, /* o : index of c (pointer to unsigned 16-bit word) */
- int16_t k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */
-);
-
-void pre_exc(
- const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- const int16_t L_frame, /* i : frame length */
- const float *speech, /* i : input speech */
- const float *p_Aq, /* i : 12k8 Lp coefficient */
- const float *p_A, /* i : unquantized A(q) filter with bandwidth expansion */
- const int16_t coder_type, /* i : coding type */
- const int16_t i_subfr, /* i : current sub frame indicator */
- float *Ap, /* o : weighted LP filter coefficients */
- const float *res, /* i : residual signal */
- float *h1, /* o : impulse response of weighted synthesis filter */
- float *xn, /* o : close-loop Pitch search target vector */
- float *cn, /* o : target vector in residual domain */
- float *mem_syn, /* i/o: memory of the synthesis filter */
- float *mem_w0, /* i/o: weighting filter denominator memory */
- const int16_t L_subfr /* i : subframe length */
-);
-
-
-void encod_amr_wb(
- Encoder_State *st, /* i/o: state structure */
- const float speech[], /* i : input speech */
- const float Aw[], /* i : weighted A(z) unquantized for subframes */
- const float Aq[], /* i : 12k8 Lp coefficient */
- const float *res, /* i : residual signal */
- float *syn, /* i/o: core synthesis */
- float *exc, /* i/o: current non-enhanced excitation */
- float *exc2, /* i/o: current enhanced excitation */
- float *pitch_buf, /* i/o: floating pitch values for each subframe */
- int16_t hf_gain[NB_SUBFR], /* o : decoded HF gain */
- const float *speech16k /* i : input speech @16kHz */
-);
-
-void stat_noise_uv_enc(
- Encoder_State *st, /* i/o: state structure */
- const float *epsP, /* i : LP prediction errors */
- const float *isp_new, /* i : immittance spectral pairs at 4th sfr */
- const float *isp_mid, /* i : immittance spectral pairs at 2nd sfr */
- float *Aq, /* i/o: A(z) quantized for the 4 subframes */
- float *exc2, /* i/o: excitation buffer */
- const int16_t uc_two_stage_flag /* o : flag undicating two-stage UC */
-);
-
-void re8_compute_base_index(
- const int16_t *x, /* i : Elemen of Q2, Q3 or Q4 */
- const int16_t ka, /* i : Identifier of the absolute leader related to x */
- uint16_t *I /* o : index */
-);
-
-void transf_cdbk_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */
- const int16_t i_subfr, /* i : subframe index */
- float cn[], /* i/o: target vector in residual domain */
- float exc[], /* i/o: pointer to excitation signal frame */
- const float *p_Aq, /* i : 12k8 Lp coefficient */
- const float Ap[], /* i : weighted LP filter coefficients */
- const float h1[], /* i : weighted filter input response */
- float xn[], /* i/o: target vector */
- float xn2[], /* i/o: target vector for innovation search */
- float y1[], /* i/o: zero-memory filtered adaptive excitation */
- const float y2[], /* i : zero-memory filtered innovative excitation */
- const float Es_pred, /* i : predicited scaled innovation energy */
- float *gain_pit, /* i/o: adaptive excitation gain */
- const float gain_code, /* i : innovative excitation gain */
- float g_corr[], /* o : ACELP correlation values */
- const int16_t clip_gain, /* i : adaptive gain clipping flag */
- float *gain_preQ, /* o : prequantizer excitation gain */
- float code_preQ[], /* o : prequantizer excitation */
- int16_t *unbits /* i/o: number of AVQ unused bits */
-);
-void deemph_lpc(
- float *p_Aq_cuerr, /* i : LP coefficients current frame */
- float *p_Aq_old, /* i : LP coefficients previous frame */
- float *LPC_de_curr, /* o : De-emphasized LP coefficients current frame */
- float *LPC_de_old, /* o : De-emphasized LP coefficients previous frame*/
- const int16_t deemph_old );
-
-void Interpol_delay(
- float *out, /* o : pitch interpolation output */
- float *last, /* i : last frame pitch lag */
- float *current, /* i : current frame pitch lag */
- int16_t SubNum, /* i : subframe number */
- const float *frac /* i : interpolation constant */
-);
-
-void dequantize_uvg(
- int16_t iG1, /* i : gain 1 index */
- int16_t *iG2, /* i : gain 2 index */
- float *G, /* o : quantized gain */
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-void generate_nelp_excitation(
- int16_t *seed, /* i/o: random number seed */
- float *Gains, /* i : excitation gains */
- float *output, /* o : excitation output */
- float gain_fac /* i : gain factor */
-);
-
-void nelp_encoder(
- Encoder_State *st, /* i/o: encoder state */
- float *in, /* i : residual signal */
- float *exc, /* o : NELP quantized excitation signal */
- const int16_t reduce_gains );
-
-void encod_nelp(
- Encoder_State *st, /* i/o: state structure */
- const float *speech, /* i : input speech */
- const float Aw[], /* i : weighted A(z) unquantized for subframes */
- const float *Aq, /* i : 12k8 Lp coefficient */
- float *res, /* o : residual signal */
- float *synth, /* o : core synthesis */
- float *tmp_noise, /* o : long-term noise energy */
- float *exc, /* i/o: current non-enhanced excitation */
- float *exc2, /* i/o: current enhanced excitation */
- float *pitch_buf, /* o : floating pitch values for each subframe */
- float *voice_factors, /* o : voicing factors */
- float *bwe_exc /* o : excitation for SWB TBE */
-);
-
-void realft(
- float *data, /* i/o: data array */
- int16_t n, /* i : length of data array */
- int16_t isign /* i : sign +1 or -1 */
-);
-
-ivas_error DTFS_new(
- DTFS_STRUCTURE **dtfs_out );
-
-void DTFS_copy(
- DTFS_STRUCTURE *Xout, /* o : DTFS */
- DTFS_STRUCTURE Xinp /* i : DTFS */
-);
-
-void DTFS_sub(
- DTFS_STRUCTURE *tmp, /* o : output DFTS */
- DTFS_STRUCTURE X1, /* i : DTFS input 1 */
- DTFS_STRUCTURE X2 /* i : DTFS input 2 */
-);
-
-void DTFS_to_fs(
- const float *x, /* i : Time domain signal */
- const int16_t N, /* i : Length of input vector */
- DTFS_STRUCTURE *X, /* o : DTFS structure with a, b, lag */
- const int32_t sampling_rate,
- const int16_t FR_flag /* i : FR flag */
-);
-
-void DTFS_fs_inv(
- DTFS_STRUCTURE *X, /* i : DTFS */
- float *x, /* o : time domain sig */
- const int16_t N, /* i : Output length */
- float ph0 /* i : Input phase */
-);
-
-void DTFS_car2pol(
- DTFS_STRUCTURE *X /* i/o: DTFS structure a, b, lag */
- /* input in Cartesion, output in Polar */
-);
-
-void DTFS_pol2car(
- DTFS_STRUCTURE *X /* i/o: DTFS structure a, b, lag */
- /* input in Polar, output in Cartesian */
-);
-
-/*! r: Return Input RMS between f1/f2 b4 scaling */
-float DTFS_setEngyHarm(
- float f1, /* i : lower band freq of input to control energy */
- float f2, /* i : upper band freq of input to control energy */
- float g1, /* i : lower band freq of output to control energy */
- float g2, /* i : upper band freq of output to control energy */
- float en2, /* i : Target Energy to set the DTFS to */
- DTFS_STRUCTURE *X /* i/o: DTFS to adjust the energy of */
-);
-
-void DTFS_to_erb(
- DTFS_STRUCTURE X, /* i : DTFS input */
- float *out /* o : ERB output */
-);
-
-void DTFS_zeroPadd(
- const int16_t N, /* i : Target lag */
- DTFS_STRUCTURE *X /* i/o: DTFS */
-);
-
-/*! r: Energy */
-float DTFS_getEngy(
- DTFS_STRUCTURE X /* i : DTFS to compute energy of */
-);
-
-void DTFS_adjustLag(
- DTFS_STRUCTURE *X_DTFS, /* i/o: DTFS to adjust lag for */
- const int16_t N /* i : Target lag */
-);
-
-void DTFS_poleFilter(
- DTFS_STRUCTURE *X, /* i/o: DTFS to poleFilter inplace */
- const float *LPC, /* i : LPCs */
- const int16_t N /* i : LPCORDER */
-);
-
-void DTFS_zeroFilter(
- DTFS_STRUCTURE *X, /* i/o: DTFS to zeroFilter inplace */
- const float *LPC, /* i : LPCs */
- const int16_t N /* i : LPCORDER */
-);
-
-float DTFS_alignment_full(
- DTFS_STRUCTURE X1_DTFS, /* i : reference DTFS */
- DTFS_STRUCTURE X2_DTFS, /* i : DTFS to shift */
- const int16_t num_steps /* i : resolution */
-);
-
-void DTFS_phaseShift(
- DTFS_STRUCTURE *X, /* i : DTFS to shift */
- float ph /* i : phase to shift */
-);
-
-void erb_add(
- float *curr_erb, /* i/o: current ERB */
- const int16_t l, /* i : current lag */
- const float *prev_erb, /* i : previous ERB */
- const int16_t pl, /* i : previous lag */
- const int16_t *index, /* i : ERB index */
- const int16_t num_erb /* i : number of ERBs */
-);
-
-void erb_slot(
- int16_t lag, /* i : input lag */
- int16_t *out, /* o : ERB slots */
- float *mfreq, /* i : ERB frequencies */
- int16_t num_erb /* i : number of ERBs */
-);
-
-void erb_diff(
- const float *prev_erb, /* i : previous ERB */
- const int16_t pl, /* i : previous lag */
- const float *curr_erb, /* i : current ERB */
- const int16_t l, /* i : current lag */
- const float *curr_lsp, /* i : current LSP coefficients */
- float *out, /* o : ERB difference */
- int16_t *index, /* i : ERB index */
- const int16_t num_erb /* i : Number of ERBs */
-);
-
-void DTFS_erb_inv(
- float *in, /* i : ERB inpt */
- int16_t *slot, /* i : ERB slots filled based on lag */
- float *mfreq, /* i : erb frequence edges */
- DTFS_STRUCTURE *X, /* o : DTFS after erb-inv */
- const int16_t num_erb /* i : Number of ERB bands */
-);
-
-ivas_error ppp_quarter_encoder(
- int16_t *returnFlag, /* o : return value */
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- DTFS_STRUCTURE *CURRCW_Q, /* o : Quantized (amp/phase) DTFS */
- DTFS_STRUCTURE *TARGETCW, /* o : DTFS with quant phase but unquant Amp */
- const int16_t prevCW_lag, /* i : previous lag */
- DTFS_STRUCTURE vCURRCW_NQ, /* i : Unquantized DTFS */
- const float *curr_lpc, /* i : LPCS */
- float *lastLgainE, /* i/o: last low band gain */
- float *lastHgainE, /* i/o: last high band gain */
- float *lasterbE, /* i/o: last ERB vector */
- DTFS_STRUCTURE PREV_CW_E /* i : past DTFS */
-);
-
-ivas_error WIsyn(
- DTFS_STRUCTURE PREVCW, /* i : Prev frame DTFS */
- DTFS_STRUCTURE *CURR_CW_DTFS, /* i/o: Curr frame DTFS */
- const float *curr_lpc, /* i : LPC */
- float *ph_offset, /* i/o: Phase offset to line up at end of frame */
- float *out, /* o : Waveform Interpolated time domain signal */
- const int16_t N, /* i : Number of samples of output to generate */
- const int16_t FR_flag /* i : called for post-smoothing in FR */
-);
-
-void set_ppp_mode(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */
- const int16_t clean_speech_HO, /* i : SC-VBR clean speech HO flag */
- const int16_t NB_speech_HO, /* i : SC-VBR NB speech HO flag */
- const int16_t localVAD_he /* i : HE-SAD flag without hangover */
-);
-
-ivas_error ppp_voiced_encoder(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- SC_VBR_ENC_HANDLE hSC_VBR, /* i/o: SC-VBR state structure */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t last_coder_type_raw, /* i : raw last_coder_type */
- const float old_pitch_buf[], /* i : buffer of old subframe pitch values */
- float *in, /* i : residual signal */
- float *out, /* o : Quantized residual signal */
- const int16_t delay, /* i : open loop pitch */
- float *lpc1, /* i : prev frame de-emphasized LPC */
- float *lpc2, /* i : current frame de-emphasized LPC */
- float *exc, /* i : previous frame quantized excitation */
- float *pitch /* o : floating pitch values for each subframe */
-);
-
-ivas_error encod_ppp(
- Encoder_State *st, /* i/o: state structure */
- const float speech[], /* i : input speech */
- const float Aw[], /* i : weighted A(z) unquantized for subframes */
- const float Aq[], /* i : 12k8 Lp coefficient */
- float *res, /* i/o: residual signal */
- float *synth, /* i/o: core synthesis */
- float *exc, /* i/o: current non-enhanced excitation */
- float *exc2, /* i/o: current enhanced excitation */
- float *pitch_buf, /* i/o: floating pitch values for each subframe */
- float *voice_factors, /* o : voicing factors */
- float *bwe_exc /* o : excitation for SWB TBE */
-);
-
-void reset_rf_indices(
- RF_ENC_HANDLE hRF, /* i/o: RF state structure */
- const int16_t L_frame, /* i : frame length */
- int16_t *rf_target_bits_write );
-
-void signaling_enc_rf(
- Encoder_State *st /* i/o: encoder state structure */
-);
-
-ivas_error acelp_core_dec(
- Decoder_State *st, /* i/o: Decoder state structure */
- float output[], /* o : synthesis @internal Fs */
- float synth[], /* o : synthesis */
- float save_hb_synth[], /* o : HB synthesis */
- float bwe_exc_extended[], /* i/o: bandwidth extended excitation */
- float *voice_factors, /* o : voicing factors */
- float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */
- const int16_t sharpFlag, /* i : formant sharpening flag */
- float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */
- int16_t *unbits, /* o : number of unused bits */
- int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */
- STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */
- const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */
- const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */
- const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
- const int16_t last_element_mode, /* i : last element mode */
- const int32_t last_element_brate, /* i : last element bitrate */
- const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
- const int16_t nchan_out, /* i : number of output channels */
- STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
- const int16_t read_sid_info /* i : read SID info flag */
-);
-
-void bass_psfilter_init(
- BPF_DEC_HANDLE hBPF /* o : BPF data handle */
-);
-
-void bass_psfilter(
- BPF_DEC_HANDLE hBPF, /* o : BPF data handle */
- const int16_t Opt_AMR_WB, /* i : AMR-WB IO flag */
- const float synth_in[], /* i : synthesis (at 16kHz) */
- const int16_t L_frame, /* i : length of the last frame */
- const float pitch_buf[], /* i : pitch for every subfr [0,1,2,3] */
- const int16_t bpf_off, /* i : do not use BPF when set to 1 */
- float v_stab, /* i : stability factor */
- float *v_stab_smooth, /* i : smoothed stability factor */
- const int16_t coder_type, /* i : coder_type */
- float bpf_noise_buf[] /* o : BPF error signal (at int_fs) */
-);
-
-void CNG_reset_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- float *pitch_buf, /* o : floating pitch for each subframe */
- float *voice_factors /* o : voicing factors */
-);
-
-void updt_dec(
- Decoder_State *st, /* i/o: state structure */
- const float *old_exc, /* i : buffer of excitation */
- const float *pitch_buf, /* i : floating pitch values for each subframe */
- const float Es_pred, /* i : predicited scaled innovation energy */
- const float *Aq, /* i : A(z) quantized for all subframes */
- const float *lsf_new, /* i : current frame LSF vector */
- const float *lsp_new, /* i : current frame LSP vector */
- const float voice_factors[], /* i : voicing factors */
- const float *old_bwe_exc, /* i : buffer of excitation */
- const float *gain_buf /* o : floating pitch gain for each subframe */
-);
-
-void updt_IO_switch_dec(
- const int16_t output_frame, /* i : output frame length */
- Decoder_State *st /* i/o: state structure */
-);
-
-void updt_dec_common(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t hq_core_type, /* i : HQ core type */
- const int16_t concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */
- const float *synth /* i : decoded synthesis */
-);
-
-void td_cng_dec_init(
- DEC_CORE_HANDLE st /* i/o: decoder state structure */
-);
-
-void CNG_dec(
- Decoder_State *st, /* i/o: State structure */
- const int16_t last_element_mode, /* i : last element mode */
- float Aq[], /* o : LP coefficients */
- float *lsp_new, /* i/o: current frame LSPs */
- float *lsf_new, /* i/o: current frame LSFs */
- int16_t *allow_cn_step, /* o : allow cn step */
- int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */
- float *q_env );
-
-void swb_CNG_dec(
- Decoder_State *st, /* i/o: State structure */
- const float *synth, /* i : ACELP core synthesis at 32kHz */
- float *shb_synth, /* o : high-band CNG synthesis */
- const int16_t sid_bw /* i : 0-NB/WB, 1-SWB SID */
-);
-
-void lsf_dec(
- Decoder_State *st, /* i/o: State structure */
- const int16_t tc_subfr, /* i : TC subframe index */
- float *Aq, /* o : quantized A(z) for 4 subframes */
- int16_t *LSF_Q_prediction, /* o : LSF prediction mode */
- float *lsf_new, /* o : de-quantized LSF vector */
- float *lsp_new, /* o : de-quantized LSP vector */
- float *lsp_mid, /* o : de-quantized mid-frame LSP vector */
- const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
- const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */
-);
-
-void isf_dec_amr_wb(
- Decoder_State *st, /* i/o: State structure */
- float *Aq, /* o : quantized A(z) for 4 subframes */
- float *isf_new, /* o : de-quantized ISF vector */
- float *isp_new /* o : de-quantized ISP vector */
-);
-
-void Es_pred_dec(
- float *Es_pred, /* o : predicted scaled innovation energy */
- const int16_t enr_idx, /* i : indice */
- const int16_t nb_bits, /* i : number of bits */
- const int16_t no_ltp /* i : no LTP flag */
-);
-
-void gaus_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t i_subfr, /* i : subframe index */
- float *code, /* o : gaussian excitation */
- float *norm_gain_code, /* o : gain of the normalized gaussian excitation */
- float *lp_gainp, /* i/o: lp filtered pitch gain(FER) */
- float *lp_gainc, /* i/o: lp filtered code gain (FER) */
- float *gain_inov, /* o : unscaled innovation gain */
- float *tilt_code, /* o : synthesis excitation spectrum tilt */
- float *voice_fac, /* o : estimated voicing factor */
- float *gain_pit, /* o : reset pitch gain */
- float *pt_pitch, /* o : reset floating pitch buffer */
- float *exc, /* o : excitation signal frame */
- float *gain_code, /* o : gain of the gaussian excitation */
- float *exc2 /* o : scaled excitation signal frame */
-);
-
-void gain_dec_amr_wb(
- Decoder_State *st, /* i/o: decoder state structure */
- const int32_t core_brate, /* i : core bitrate */
- float *gain_pit, /* o : Quantized pitch gain */
- float *gain_code, /* o : Quantized codeebook gain */
- float *past_qua_en, /* i/o: gain quantization memory (4 words) */
- float *gain_inov, /* o : unscaled innovation gain */
- const float *code, /* i : algebraic code excitation */
- float *norm_gain_code /* o : norm. gain of the codebook excitation */
-);
-
-void gain_dec_lbr(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t coder_type, /* i : coding type */
- const int16_t i_subfr, /* i : subframe index */
- const float *code, /* i : algebraic excitation */
- float *gain_pit, /* o : quantized pitch gain */
- float *gain_code, /* o : quantized codebook gain */
- float *gain_inov, /* o : gain of the innovation (used for normalization) */
- float *norm_gain_code, /* o : norm. gain of the codebook excitation */
- float gains_mem[], /* i/o: pitch gain and code gain from previous subframes */
- const int16_t L_subfr /* i : subframe length */
-);
-
-void gain_dec_mless(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t coder_type, /* i : coding type */
- const int16_t i_subfr, /* i : subframe number */
- const int16_t tc_subfr, /* i : TC subframe index */
- const float *code, /* i : algebraic code excitation */
- const float Es_pred, /* i : predicted scaled innov. energy */
- float *gain_pit, /* o : Quantized pitch gain */
- float *gain_code, /* o : Quantized codeebook gain */
- float *gain_inov, /* o : unscaled innovation gain */
- float *norm_gain_code /* o : norm. gain of the codebook excitation */
-);
-
-void gain_dec_SQ(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t i_subfr, /* i : subframe number */
- const float *code, /* i : algebraic code excitation */
- const float Es_pred, /* i : predicted scaled innov. energy */
- float *gain_pit, /* o : Quantized pitch gain */
- float *gain_code, /* o : Quantized codeebook gain */
- float *gain_inov, /* o : unscaled innovation gain */
- float *norm_gain_code /* o : norm. gain of the codebook excitation */
-);
-
-/*! r: quantized codebook gain */
-float gain_dec_gaus(
- const int16_t index, /* i : quantization index */
- const int16_t bits, /* i : number of bits to quantize */
- const float lowBound, /* i : lower bound of quantizer (dB) */
- const float topBound, /* i : upper bound of quantizer (dB) */
- const float gain_inov, /* i : unscaled innovation gain */
- float *norm_gain_code /* o : gain of normalized gaus. excit. */
-);
-
-/*! r: floating pitch value */
-float pit_decode_flt(
- Decoder_State *st, /* i/o: decoder state structure */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- const int16_t L_frame, /* i : length of the frame */
- int16_t i_subfr, /* i : subframe index */
- const int16_t coder_type, /* i : coding type */
- int16_t *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */
- int16_t *T0, /* o : close loop integer pitch */
- int16_t *T0_frac, /* o : close loop fractional part of the pitch */
- int16_t *T0_min, /* i/o: delta search min for sf 2 & 4 */
- int16_t *T0_max, /* i/o: delta search max for sf 2 & 4 */
- const int16_t L_subfr, /* i : subframe length */
- const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-);
-
-void abs_pit_dec_flt(
- const int16_t fr_steps, /* i : fractional resolution steps (0, 2, 4) */
- int16_t pitch_index, /* i : pitch index */
- const int16_t limit_flag, /* i : restrained(0) or extended(1) Q limits */
- int16_t *T0, /* o : integer pitch lag */
- int16_t *T0_frac /* o : pitch fraction */
-);
-
-void delta_pit_dec_flt(
- const int16_t fr_steps, /* i : fractional resolution steps (0, 2, 4) */
- const int16_t pitch_index, /* i : pitch index */
- int16_t *T0, /* o : integer pitch lag */
- int16_t *T0_frac, /* o : pitch fraction */
- const int16_t T0_min /* i : delta search min */
-);
-
-void pit_Q_dec_flt(
- const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- const int16_t pitch_index, /* i : pitch index */
- const int16_t nBits, /* i : # of Q bits */
- const int16_t delta, /* i : Half the CL searched interval */
- const int16_t pit_flag, /* i : absolute(0) or delta(1) pitch Q */
- const int16_t limit_flag, /* i : restrained(0) or extended(1) Q limits */
- int16_t *T0, /* o : integer pitch lag */
- int16_t *T0_frac, /* o : pitch fraction */
- int16_t *T0_min, /* i/o: delta search min */
- int16_t *T0_max, /* i/o: delta search max */
- int16_t *BER_detect /* o : BER detect flag */
-);
-
-void pit16k_Q_dec_flt(
- const int16_t pitch_index, /* i : pitch index */
- const int16_t nBits, /* i : # of Q bits */
- const int16_t limit_flag, /* i : restrained(0) or extended(1) Q limits */
- int16_t *T0, /* o : integer pitch lag */
- int16_t *T0_frac, /* o : pitch fraction */
- int16_t *T0_min, /* i/o: delta search min */
- int16_t *T0_max, /* i/o: delta search max */
- int16_t *BER_detect /* o : BER detect flag */
-);
-
-
-void inov_decode(
- Decoder_State *st, /* i/o: decoder state structure */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t sharpFlag, /* i : formant sharpening flag */
- const int16_t i_subfr, /* i : subframe index */
- const float *p_Aq, /* i : LP filter coefficients */
- const float tilt_code, /* i : tilt of of the excitation of previous subframe */
- const float pt_pitch, /* i : pointer to current subframe fractional pitch */
- float *code, /* o : algebraic excitation */
- const int16_t L_subfr /* i : subframe length */
-);
-
-void dec_acelp_1t64(
- Decoder_State *st, /* i/o: decoder state structure */
- float code[], /* o : algebraic (fixed) codebook excitation */
- const int16_t L_subfr /* i : subframe length */
-);
-
-void dec_acelp_2t32(
- Decoder_State *st, /* i/o: decoder state structure */
- float code[] /* o : algebraic (fixed) codebook excitation */
-);
-
-void dec_acelp_4t64(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t nbbits, /* i : number of bits per codebook */
- float code[], /* o : algebraic (fixed) codebook excitation */
- const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */
-);
-
-
-void FEC_exc_estim(
- Decoder_State *st, /* i/o: Decoder static memory */
- const int16_t L_frame, /* i : length of the frame */
- float *old_exc, /* i/o: excitation buffer */
- float *exc2, /* o : excitation buffer (for synthesis) */
- float *exc_dct_in, /* o : GSC excitation in DCT domain */
- float *pitch_buf, /* o : Floating pitch for each subframe */
- float *tmp_tc, /* o : FEC pitch */
- float *voice_factors, /* o : voicing factors */
- float *bwe_exc, /* i/o: excitation for SWB TBE */
- float *lsf_new, /* i : ISFs at the end of the frame */
- float *tmp_noise /* o : long-term noise energy */
-);
-
-void FEC_lsf2lsp_interp_flt(
- Decoder_State *st, /* i/o: Decoder static memory */
- const int16_t L_frame, /* i : length of the frame */
- float *Aq, /* o : calculated A(z) for 4 subframes */
- float *lsf, /* o : estimated LSF vector */
- float *lsp /* o : estimated LSP vector */
-);
-
-void FEC_lsf_estim_enc(
- Encoder_State *st, /* i : Encoder static memory */
- float *lsf /* o : estimated LSF vector */
-);
-
-float frame_energy(
- const int16_t L_frame, /* i : length of the frame */
- const float *pitch, /* i : pitch values for each subframe */
- const float *speech, /* i : pointer to speech signal for E computation */
- const float lp_speech, /* i : long term active speech energy average */
- float *frame_ener /* o : pitch-synchronous energy at frame end */
-);
-
-void FEC_SinOnset(
- float *exc, /* i/o: exc vector to modify */
- int16_t puls_pos, /* i : Last pulse position desired */
- int16_t T0, /* i : decoded first frame pitch */
- float enr_q, /* i : energy provided by the encoder */
- float *Aq, /* i : Lsp coefficient */
- const int16_t L_frame /* i : Frame length */
-);
-
-int16_t FEC_enhACB(
- const int16_t L_frame, /* i : Frame length */
- const int16_t last_L_frame, /* i : frame length of last frame */
- float *exc_io, /* i/o: Adaptive codebook memory */
- const int16_t new_pit, /* i : decoded first frame pitch */
- const int16_t puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */
- const float bfi_pitch /* i : Pitch used for concealment */
-);
-
-void FEC_scale_syn(
- const int16_t L_frame, /* i : length of the frame */
- int16_t clas, /* i/o: frame classification */
- const int16_t last_good, /* i : last good frame classification */
- float *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */
- const float *pitch, /* i : pitch values for each subframe */
- float enr_old, /* i : energy at the end of prvious frame */
- float enr_q, /* i : transmitted energy for current frame */
- const int16_t coder_type, /* i : coding type */
- const int16_t LSF_Q_prediction, /* i : LSF prediction mode */
- int16_t *scaling_flag, /* i/o: flag to indicate energy control of syn */
- float *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */
- float *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */
- const int16_t bfi, /* i : current frame BFI */
- const int32_t total_brate, /* i : total bitrate */
- const int16_t prev_bfi, /* i : previous frame BFI */
- const int32_t last_core_brate, /* i : previous frame core bitrate */
- float *exc, /* i/o: excitation signal without enhancement */
- float *exc2, /* i/o: excitation signal with enhancement */
- const float Aq[], /* i : LP filter coefs */
- float *old_enr_LP, /* i/o: LP filter E of last good voiced frame */
- const float *mem_tmp, /* i : temp. initial synthesis filter states */
- float *mem_syn, /* o : initial synthesis filter states */
- const int16_t avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */
- const int16_t force_scaling /* i : force scaling */
-);
-
-void FEC_pitch_estim(
- const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- const int16_t last_core, /* i : last core */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t clas, /* i : current frame classification */
- const int16_t last_good, /* i : last good clas information */
- const float pitch_buf[], /* i : Floating pitch for each subframe */
- const float old_pitch_buf[], /* i : buffer of old subframe pitch values */
- float *bfi_pitch, /* i/o: update of the estimated pitch for FEC */
- int16_t *bfi_pitch_frame, /* o : frame length when pitch was updated */
- int16_t *upd_cnt, /* i/o: update counter */
- const int16_t coder_type );
-
-void FEC_encode(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const ACELP_config acelp_cfg, /* i : configuration of the ACELP */
- const float *synth, /* i : pointer to synthesized speech for E computation */
- const int16_t coder_type, /* i : type of coder */
- int16_t clas, /* i : signal clas for current frame */
- const float *fpit, /* i : close loop fractional pitch buffer */
- const float *res, /* i : LP residual signal frame */
- int16_t *last_pulse_pos, /* i/o: Position of the last pulse */
- const int16_t L_frame, /* i : Frame length */
- const int32_t total_brate /* i : total codec bitrate */
-);
-
-int16_t FEC_pos_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t *last_pulse_pos, /* o : Last glottal pulse position in the lost ACB */
- float *enr_q, /* o : Decoded energy */
- const int16_t nBits_es_Pred /* i : number of bits for Es_pred Q */
-);
-
-void improv_amr_wb_gs(
- const int16_t clas, /* i : bitrate allocated to the core */
- const int16_t coder_type, /* i : coder_type */
- const int32_t core_brate, /* i : bitrate allocated to the core */
- int16_t *seed_tcx, /* i/o: Seed used for noise generation */
- float *old_Aq, /* i/o: old LPC filter coefficient */
- float *mem_syn2, /* i/o: synthesis memory */
- const float lt_voice_fac, /* i/o: long term voice factor */
- const int16_t locattack, /* i : Flag for a detected attack */
- float *Aq, /* i/o: Decoded LP filter coefficient */
- float *exc2, /* i/o: Decoded complete excitation */
- float *mem_tmp, /* i/o: synthesis temporary memory */
- float *syn, /* i/o: Decoded synthesis to be updated */
- const float *pitch_buf, /* i : Decoded pitch buffer */
- const float Last_ener, /* i : Last energy */
- const int16_t rate_switching_reset, /* i : rate switching reset flag */
- const int16_t last_coder_type, /* i : Last coder_type */
- const int16_t VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */
-);
-
-int16_t tc_classif(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-void transition_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t i_subfr, /* i : subframe index */
- const int16_t tc_subfr, /* i : TC subframe index */
- int16_t *Jopt_flag, /* i : joint optimization flag */
- float *exc, /* i/o: current frame excitation signal */
- int16_t *T0, /* o : close loop integer pitch */
- int16_t *T0_frac, /* o : close loop fractional part of the pitch */
- int16_t *T0_min, /* i/o: delta search min for sf 2 & 4 */
- int16_t *T0_max, /* i/o: delta search max for sf 2 & 4 */
- float **pt_pitch, /* o : floating pitch values */
- int16_t *position, /* i/o: first glottal impulse position in frame */
- float *bwe_exc /* i/o: excitation for SWB TBE */
-);
-
-void gain_dec_tc(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t i_subfr, /* i : subframe number */
- const float Es_pred, /* i : predicted scaled innov. energy */
- const float *code, /* i : algebraic code excitation */
- float *gain_pit, /* o : pitch gain */
- float *gain_code, /* o : Quantized codeebook gain */
- float *gain_inov, /* o : unscaled innovation gain */
- float *norm_gain_code /* o : norm. gain of the codebook excit. */
-);
-
-void stat_noise_uv_dec(
- Decoder_State *st, /* i/o: decoder static memory */
- const float *lsp_new, /* i : end-frame LSP vector */
- const float *lsp_mid, /* i : mid-frame LSP vector */
- float *Aq, /* o : A(z) quantized for the 4 subframes */
- float *exc2, /* i/o: excitation buffer */
- const int16_t uc_two_stage_flag /* 1 : flag undicating two-stage UC */
-);
-
-void sc_vbr_dec_init_flt(
- SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle */
-);
-
-void decod_nelp(
- Decoder_State *st, /* i/o: decoder static memory */
- float *tmp_noise, /* o : long term temporary noise energy */
- float *pitch_buf, /* o : floating pitch values for each subframe */
- float *exc, /* o : adapt. excitation exc */
- float *exc2, /* o : adapt. excitation/total exc */
- float *voice_factors, /* o : voicing factors */
- float *bwe_exc, /* o : excitation for SWB TBE */
- const int16_t bfi, /* i : bad frame indicator */
- float *gain_buf /* o : floating pitch gain for each subframe */
-);
-
-void nelp_decoder(
- Decoder_State *st, /* i/o: decoder static memory */
- float *exc_nelp, /* o : adapt. excitation/total exc */
- float *exc, /* o : adapt. excitation exc */
- int16_t bfi, /* i : frame error rate */
- const int16_t coder_type, /* i : coding type */
- float *gain_buf /* o : floating pitch gain for each subframe */
-);
-
-ivas_error decod_ppp(
- Decoder_State *st, /* i/o: state structure */
- const float Aq[], /* i : 12k8 Lp coefficient */
- float *pitch_buf, /* i/o: floating pitch values for each subframe */
- float *exc, /* i/o: current non-enhanced excitation */
- float *exc2, /* i/o: current enhanced excitation */
- float *voice_factors, /* o : voicing factors */
- float *bwe_exc, /* o : excitation for SWB TBE */
- float *gain_buf, /* o : floating pitch gain for each subframe */
- const int16_t bfi /* i : BFI flag */
-);
-
-ivas_error ppp_quarter_decoder(
- Decoder_State *st, /* i/o: decoder state structure */
- DTFS_STRUCTURE *CURRCW_Q_DTFS, /* i/o: Current CW DTFS */
- int16_t prevCW_lag, /* i : Previous lag */
- float *lastLgainD, /* i/o: Last gain lowband */
- float *lastHgainD, /* i/o: Last gain highwband */
- float *lasterbD, /* i/o: Last ERB vector */
- int16_t bfi, /* i : FER flag */
- DTFS_STRUCTURE PREV_CW_D /* i : Previous DTFS */
-);
-
-ivas_error ppp_voiced_decoder(
- Decoder_State *st, /* i/o: state structure */
- float *out, /* o : residual signal */
- const float *lpc2, /* i : current frame LPC */
- float *exc, /* i : previous frame excitation */
- float *pitch, /* o : floating pitch values for each subframe */
- const int16_t bfi /* i : BFI flag */
-);
-
-void AVQ_demuxdec(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t xriq[], /* o : decoded subvectors [0..8*Nsv-1] */
- int16_t *nb_bits, /* i/o: number of allocated bits */
- const int16_t Nsv, /* i : number of subvectors */
- int16_t nq[], /* i/o: AVQ nq index */
- int16_t avq_bit_sFlag, /* i : flag for AVQ bit saving solution*/
- int16_t trgtSvPos /* i : target SV for AVQ bit savings */
-);
-
-
-void Init_post_filter_ivas(
- PFSTAT_HANDLE hPFstat /* i : post-filter state memories */
-);
-
-void nb_post_filt_ivas(
- const int16_t L_frame, /* i : frame length */
- const int16_t L_subfr, /* i : sub-frame length */
- PFSTAT_HANDLE hPFstat, /* i/o: Post filter related memories */
- float *lp_noise, /* i/o: long term noise energy */
- const float tmp_noise, /* i : noise energy */
- float *synth, /* i/o: synthesis */
- const float *Aq, /* i : LP filter coefficient */
- const float *pitch_buf, /* i : Floating pitch for each subframe */
- const int16_t coder_type, /* i : coder_type -> deactivated in AUDIO */
- const int16_t BER_detect, /* i : BER detect flag */
- const int16_t disable_hpf /* i : flag to diabled HPF */
-);
-
-void decod_unvoiced(
- Decoder_State *st, /* i/o: decoder static memory */
- const float *Aq, /* i : LP filter coefficient */
- const float Es_pred, /* i : predicted scaled innov. energy */
- const int16_t uc_two_stage_flag, /* i : flag indicating two-stage UC */
- float *tmp_noise, /* o : long term temporary noise energy */
- float *pitch_buf, /* o : floating pitch values for each subframe */
- float *voice_factors, /* o : voicing factors */
- float *exc, /* o : adapt. excitation exc */
- float *exc2, /* o : adapt. excitation/total exc */
- float *bwe_exc, /* i/o: excitation for SWB TBE */
- float *gain_buf /* o : floating pitch gain for each subfram */
-);
-
-void decod_tran(
- Decoder_State *st, /* i/o: decoder static memory */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t tc_subfr, /* i : TC subframe index */
- const float *Aq, /* i : LP filter coefficient */
- const float Es_pred, /* i : predicted scaled innov. energy */
- float *pitch_buf, /* o : floating pitch values for each subframe */
- float *voice_factors, /* o : voicing factors */
- float *exc, /* i/o: adapt. excitation exc */
- float *exc2, /* i/o: adapt. excitation/total exc */
- float *bwe_exc, /* i/o: excitation for SWB TBE */
- int16_t *unbits, /* i/o: number of unused bits */
- const int16_t sharpFlag, /* i : formant sharpening flag */
- float *gain_buf /* o : floating pitch gain for each subframe */
-);
-
-ivas_error decod_gen_voic(
- Decoder_State *st, /* i/o: decoder static memory */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t sharpFlag, /* i : formant sharpening flag */
- const float *Aq, /* i : LP filter coefficient */
- const float Es_pred, /* i : predicted scaled innov. energy */
- const int16_t do_WI, /* i : FEC fast recovery flag */
- float *pitch_buf, /* o : floating pitch for each subframe */
- float *voice_factors, /* o : voicing factors */
- float *exc, /* i/o: adapt. excitation exc */
- float *exc2, /* i/o: adapt. excitation/total exc */
- float *bwe_exc, /* i/o: excitation for SWB TBE */
- int16_t *unbits, /* i/o: number of unused bits */
- float *gain_buf, /* o : floating pitch gain for each subframe */
- const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-);
-
-void decod_amr_wb(
- Decoder_State *st, /* i/o: decoder static memory */
- const float *Aq, /* i : LP filter coefficients */
- float *pitch_buf, /* o : floating pitch values for each subframe */
- float *exc, /* i/o: adapt. excitation exc */
- float *exc2, /* i/o: adapt. excitation/total exc */
- int16_t hf_gain[NB_SUBFR], /* o : decoded HF gain */
- float *voice_factors, /* o : voicing factors */
- float *gain_buf /* o : floating pitch gain for each subframe */
-);
-
-ivas_error init_decoder(
- Decoder_State *st, /* o : Decoder static variables structure */
- const int16_t idchan, /* i : channel ID */
- const MC_MODE mc_mode /* i : MC mode */
-);
-
-void destroy_cldfb_decoder_flt(
- Decoder_State *st /* o : Decoder static variables structure */
-);
-
-void HQ_core_dec_init_flt(
- HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */
-);
-
-void HQ_nbfec_init_flt(
- HQ_NBFEC_HANDLE hHQ_nbfec /* i/o: HQ NB FEC data handle */
-);
-
-ivas_error evs_dec(
- Decoder_State *st, /* i/o: Decoder state structure */
- float mem_hp20_out[L_HP20_MEM], /* i/o: HP filter memory for synthesis */
- float *output, /* o : output synthesis signal */
- FRAME_MODE frameMode /* i : Decoder frame mode */
-);
-
-void get_next_frame_parameters(
- Decoder_State *st /* i/o: Decoder state structure */
-);
-
-ivas_error amr_wb_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- float mem_hp20_out[L_HP20_MEM], /* i/o: HP filter memory for synthesis */
- float *output /* o : synthesis output */
-);
-
-void transf_cdbk_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */
- const int16_t i_subfr, /* i : subframe index */
- const float Es_pred, /* i : predicited scaled innovation energy */
- const float gain_code, /* i : innovative excitation gain */
- float *gain_preQ, /* o : prequantizer excitation gain */
- float *norm_gain_preQ, /* o : normalized prequantizer excitation gain */
- float code_preQ[], /* o : prequantizer excitation */
- int16_t *unbits /* o : number of AVQ unused bits */
-);
-
-/*! r: decoded gain */
-float gain_dequant(
- int16_t index, /* i : quantization index */
- const float min_val, /* i : value of lower limit */
- const float max_val, /* i : value of upper limit */
- const int16_t bits /* i : number of bits to dequantize */
-);
-
-void hq_core_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *audio, /* i : input audio signal */
- const int16_t input_frame, /* i : frame length */
- const int16_t hq_core_type, /* i : HQ core type */
- const int16_t Voicing_flag, /* i : Voicing flag for FER method selection */
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-int16_t detect_transient(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *in, /* i : input signal */
- const int16_t L /* i : length */
-);
-
-void wtda(
- const float *new_audio, /* i : input audio */
- float *wtda_audio, /* o : windowed audio */
- float *old_wtda, /* i/o: windowed audio from previous frame */
- const int16_t left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */
- const int16_t right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */
- const int16_t L /* i : length */
-);
-
-void wtda_ext(
- const float *new_audio, /* i : input audio */
- float *wtda_audio, /* o : windowed audio */
- const int16_t left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */
- const int16_t right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */
- const int16_t L, /* i : length */
- const uint16_t kernel_type /* i : transform kernel type (0 - 3) */
-);
-
-void tcx_get_windows_mode1_flt(
- const int16_t left_mode, /* i : overlap mode of left window half */
- const int16_t right_mode, /* i : overlap mode of right window half */
- float *left_win, /* o : left overlap window */
- float *right_win, /* o : right overlap window */
- float *left_win_int, /* o : left overlap window */
- float *right_win_int, /* o : right overlap window */
- const int16_t L /* i : length */
-);
-
-void direct_transform(
- const float *in32, /* i : input signal */
- float *out32, /* o : output transformation */
- const int16_t is_transient, /* i : transient flag */
- const int16_t L, /* i : length */
- const int16_t element_mode /* i : IVAS element mode */
-);
-
-
-void interleave_spectrum(
- float *coefs, /* i/o: input and output coefficients */
- const int16_t length /* i : length of spectrum */
-);
-
-void hq_hr_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- float *coefs, /* i/o: transform-domain coefficients */
- const int16_t length, /* i : length of spectrum */
- int16_t *num_bits, /* i/o: number of available bits */
- const int16_t is_transient, /* i : transient flag */
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-void huff_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t N, /* i : Number of codewords to decode */
- const int16_t buffer_len, /* i : Number of bits to read */
- const int16_t num_lengths, /* i : Number of different huffman codeword lengths */
- const int16_t *thres, /* i : Threshold of first codeword of each length */
- const int16_t *offset, /* i : Offset for first codeword */
- const int16_t *huff_tab, /* i : Huffman table order by codeword lengths */
- int16_t *index /* o : Decoded index */
-);
-
-void reordernorm(
- const int16_t *ynrm, /* i : quantization indices for norms */
- const int16_t *normqlg2, /* i : quantized norms */
- int16_t *idxbuf, /* o : reordered quantization indices */
- int16_t *normbuf, /* o : reordered quantized norms */
- const int16_t nb_sfm /* i : number of bands */
-);
-
-void diffcod(
- const int16_t N, /* i : number of sub-vectors */
- int16_t *y, /* i/o: indices of quantized norms */
- int16_t *difidx /* o : differential code */
-);
-
-void diffcod_lrmdct(
- const int16_t N, /* i : number of sub-vectors */
- const int16_t be_ref, /* i : band energy reference */
- int16_t *y, /* i/o: indices of quantized norms */
- int16_t *difidx, /* o : differential code */
- const int16_t is_transient /* i : transient flag */
-);
-
-void bitallocsum(
- int16_t *R, /* i : bit-allocation vector */
- const int16_t nb_sfm, /* i : number of sub-vectors */
- int16_t *sum, /* o : total number of bits allocated */
- int16_t *Rsubband, /* o : rate per subband (Q3) */
- const int16_t num_bits, /* i : number of bits */
- const int16_t length, /* i : length of spectrum */
- const int16_t *sfmsize /* i : Length of bands */
-);
-/*! r: BWE class */
-int16_t swb_bwe_gain_deq_flt(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t core, /* i : core */
- float *SWB_tenv, /* o : time-domain BWE envelope */
- float *SWB_fenv, /* o : frequency-domain BWE envelope */
- const int16_t hr_flag, /* i : high rate flag */
- const int16_t hqswb_clas /* i : HQ BWE class */
-);
-
-void save_old_syn(
- const int16_t L_frame, /* i : frame length */
- const float syn[], /* i : ACELP synthesis */
- float old_syn[], /* o : old synthesis buffer */
- float old_syn_12k8_16k[], /* i/o: old synthesis buffer */
- const float preemph_fac, /* i : preemphasis factor */
- float *mem_deemph /* i/o: deemphasis filter memory */
-);
-
-void hq_generic_hf_decoding(
- const int16_t HQ_mode, /* i : HQ mode */
- float *coeff_out1, /* i/o: BWE input & temporary buffer */
- const float *hq_generic_fenv, /* i : SWB frequency envelopes */
- float *coeff_out, /* o : SWB signal in MDCT domain */
- const int16_t hq_generic_offset, /* i : frequency offset for representing hq swb bwe*/
- int16_t *prev_L_swb_norm, /* i/o: last normalize length */
- const int16_t hq_swb_bwe_exc_clas, /* i : bwe excitation class */
- const int16_t *R );
-
-void hq_core_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- float out[], /* o : output synthesis */
- const int16_t output_frame, /* i : output frame length */
- const int16_t hq_core_type, /* i : HQ core type */
- const int16_t core_switching_flag, /* i : ACELP->HQ switching frame flag */
- float *output /* o : LB synthesis in case of ACELP-HQ switch */
-);
-
-void IMDCT(
- float *x,
- float *old_syn_overl,
- float *syn_Overl_TDAC,
- float *xn_buf,
- const float *tcx_aldo_window_1_trunc,
- const float *tcx_aldo_window_2,
- const float *tcx_mdct_window_half,
- const float *tcx_mdct_window_minimum,
- const float *tcx_mdct_window_trans,
- const int16_t tcx_mdct_window_half_length,
- const int16_t tcx_mdct_window_min_length,
- int16_t index,
- const uint16_t kernel_type, /* i : TCX transform kernel type */
- const int16_t left_rect,
- const int16_t tcx_offset,
- const int16_t overlap,
- const int16_t L_frame,
- const int16_t L_frameTCX,
- const int16_t L_spec_TCX5,
- const int16_t L_frame_glob,
- const int16_t frame_cnt,
- const int16_t bfi,
- float *old_out,
- const int16_t FB_flag,
- Decoder_State *st,
- const int16_t fullband,
- float *acelp_zir );
-
-void hq_hr_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- float *t_audio_q, /* o : transform-domain coefficients */
- const int16_t length, /* i : frame length */
- const int16_t num_bits, /* i : number of available bits */
- int16_t *ynrm, /* o : norm quantization index vector */
- int16_t *is_transient, /* o : transient flag */
- int16_t *hqswb_clas, /* o : HQ SWB class */
- float *SWB_fenv, /* o : SWB frequency envelopes */
- const int16_t core_switching_flag /* i : Core switching flag */
-
-);
-
-void hdecnrm_context(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t N, /* i : number of norms */
- int16_t *index, /* o : indices of quantized norms */
- int16_t *n_length /* o : decoded stream length */
-);
-
-void hdecnrm_tran(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t N, /* i : number of norms */
- int16_t *index /* o : indices of quantized norms */
-);
-
-void hdecnrm_resize(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t N, /* i : number of SFMs */
- int16_t *index /* o : norm quantization index vector */
-);
-
-void hdecnrm(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t N, /* i : number of norms */
- int16_t *index /* o : indices of quantized norms */
-);
-
-/*! r: index of last band */
-int16_t find_last_band(
- const int16_t *bitalloc, /* i : bit allocation */
- const int16_t nb_sfm /* i : number of possibly coded bands */
-);
-
-void fill_spectrum(
- float *coeff, /* i/o: normalized MLT spectrum / nf spectrum */
- int16_t *R, /* i : number of pulses per band */
- const int16_t is_transient, /* i : transient flag */
- int16_t norm[], /* i : quantization indices for norms */
- const float *hq_generic_fenv, /* i : HQ GENERIC envelope */
- const int16_t hq_generic_offset, /* i : HQ GENERIC offset */
- const int16_t nf_idx, /* i : noise fill index */
- const int16_t length, /* i : Length of spectrum (32 or 48 kHz) */
- const float env_stab, /* i : Envelope stability measure [0..1] */
- int16_t *no_att_hangover, /* i/o: Frame counter for attenuation hangover */
- float *energy_lt, /* i/o: Long-term energy measure for transient detection */
- int16_t *bwe_seed, /* i/o: random seed for generating BWE input */
- const int16_t hq_generic_exc_clas, /* i : HF excitation class */
- const int16_t core_sfm, /* i : index of the end band for core */
- int16_t HQ_mode, /* i : HQ mode */
- float noise_level[], /* i : noise level for harmonic modes */
- int32_t core_brate, /* i : target bitrate */
- float prev_noise_level[], /* i/o: noise factor in previous frame */
- int16_t *prev_R, /* i/o: bit allocation info. in previous frame */
- float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */
- const int16_t *peak_idx, /* i : peak positions */
- const int16_t Npeaks, /* i : number of peaks */
- const int16_t *npulses, /* i : Number of assigned pulses per band */
- int16_t prev_is_transient, /* i : previous transient flag */
- float *prev_normq, /* i : previous norms */
- float *prev_env, /* i : previous noise envelopes */
- int16_t prev_bfi, /* i : previous bad frame indicator */
- const int16_t *sfmsize, /* i : Length of bands */
- const int16_t *sfm_start, /* i : Start of bands */
- const int16_t *sfm_end, /* i : End of bands */
- int16_t *prev_L_swb_norm, /* i/o: last normalize length for harmonic mode */
- int16_t prev_hq_mode, /* i : previous HQ mode */
- const int16_t num_sfm, /* i : Number of bands */
- const int16_t num_env_bands, /* i : Number of envelope bands */
- const int16_t element_mode /* i : element mode */
-);
-
-void de_interleave_spectrum(
- float *coefs, /* i/o: input and output coefficients */
- int16_t length /* i : length of spectrum */
-);
-
-void inverse_transform(
- const float *InMDCT, /* i : input MDCT vector */
- float *Out, /* o : output vector */
- const int16_t IsTransient, /* i : transient flag */
- const int16_t L, /* i : output frame length */
- const int16_t L_inner, /* i : length of the transform */
- const int16_t element_mode /* i : IVAS element mode */
-);
-
-void window_ola(
- const float *ImdctOut, /* i : input */
- float *auOut, /* o : output audio */
- float *OldauOut, /* i/o: audio from previous frame */
- const int16_t L, /* i : length */
- const int16_t right_mode,
- const int16_t left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */
- const int16_t use_bfi_win, /* i : use BFI windowing */
- const int16_t oldHqVoicing, /* i : previous HqVoicing */
- float *oldgapsynth /* i : previous gapsynth */
-);
-
-void window_ola_ext(
- const float *ImdstOut, /* i : input */
- float *auOut, /* o : output audio */
- float *OldauOut, /* i/o: audio from previous frame */
- const int16_t L, /* i : length */
- const int16_t right_mode,
- const int16_t left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */
- const uint16_t kernel_type /* i : transform kernel type */
-);
-
-void map_quant_weight(
- const int16_t normqlg2[], /* i : quantized norms */
- int16_t wnorm[], /* o : weighted norm */
- const int16_t is_transient /* i : transient flag */
-);
-
-void recovernorm(
- const int16_t *const idxbuf, /* i : reordered quantization indices */
- int16_t *ynrm, /* o : recovered quantization indices */
- int16_t *normqlg2, /* o : recovered quantized norms */
- const int16_t nb_sfm /* i : number of subbands */
-);
-
-void reordvct(
- int16_t *y, /* i/o: vector to rearrange */
- const int16_t N, /* i : dimensions */
- int16_t *idx /* o : reordered vector index */
-);
-
-void bitalloc(
- int16_t *y, /* i : reordered norm of sub-vectors */
- int16_t *idx, /* i : reordered sub-vector indices */
- int16_t sum, /* i : number of available bits */
- int16_t N, /* i : number of norms */
- int16_t K, /* i : maximum number of bits per dimension */
- int16_t *r, /* o : bit-allacation vector */
- const int16_t *sfmsize, /* i : Length of bands */
- const int16_t hqswb_clas /* i : signal classification flag */
-);
-
-/*! r: Integer (truncated) number of allocated bits */
-int16_t BitAllocF(
- int16_t *y, /* i : norm of sub-vectors */
- int32_t bit_rate, /* i : bitrate */
- int16_t B, /* i : number of available bits */
- int16_t N, /* i : number of sub-vectors */
- int16_t *R, /* o : bit-allocation indicator */
- int16_t *Rsubband, /* o : sub-band bit-allocation vector (Q3) */
- const int16_t hqswb_clas, /* i : hq swb class */
- const int16_t num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */
-);
-
-/*! r: Integer (truncated) number of allocated bits */
-int16_t BitAllocWB(
- int16_t *y, /* i : norm of sub-vectors */
- int16_t B, /* i : number of available bits */
- int16_t N, /* i : number of sub-vectors */
- int16_t *R, /* o : bit-allocation indicator */
- int16_t *Rsubband ); /* o : sub-band bit-allocation vector (Q3) */
-
-/*! r: Number of low frequency bands */
-int16_t hvq_pvq_bitalloc(
- int16_t num_bits, /* i/o: Number of available bits (including gain bits) */
- const int32_t core_brate, /* i : bitrate */
- const int16_t bwidth, /* i : Encoded bandwidth */
- const int16_t *ynrm, /* i : Envelope coefficients */
- const int32_t manE_peak, /* i : Peak energy mantissa */
- const int16_t expE_peak, /* i : Peak energy exponent */
- int16_t *Rk, /* o : bit allocation for concatenated vector */
- int16_t *R, /* i/o: Global bit allocation */
- int16_t *sel_bands, /* o : Selected bands for encoding */
- int16_t *n_sel_bands /* o : No. of selected bands for encoding */
-);
-
-void floating_point_add_float(
- int32_t *mx, /* i/o: mantissa of the addend Q31 */
- int16_t *ex, /* i/o: exponent of the addend Q0 */
- const int32_t my, /* i : mantissa of the adder Q31 */
- const int16_t ey /* i : exponent of the adder Q0 */
-);
-
-/*! r: Number of bits needed */
-int16_t rc_get_bits2(
- const int16_t N, /* i : Number of bits currently used */
- const uint32_t range /* i : Range of range coder */
-);
-
-void rc_enc_init(
- PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */
- int16_t tot_bits /* i : Total bit budget */
-);
-
-void rc_encode(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */
- const uint32_t cum_freq, /* i : Cumulative frequency up to symbol */
- const uint32_t sym_freq, /* i : Symbol probability */
- const uint32_t tot /* i : Total cumulative frequency */
-);
-
-void rc_enc_finish(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */
-);
-
-void rc_enc_bits(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */
- const uint32_t value, /* i : Value to encode */
- const int16_t bits /* i : Number of bits used */
-);
-
-void rc_enc_uniform(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */
- uint32_t value, /* i : Value to encode */
- uint32_t tot /* i : Maximum value */
-);
-
-void rc_dec_init(
- Decoder_State *st, /* i/o: Decoder State */
- PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */
- int16_t tot_bits /* i : Total bit budget */
-);
-
-/*! r: Decoded value */
-uint32_t rc_decode(
- int16_t *BER_detect, /* o : Bit error detection flag */
- PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */
- uint32_t tot /* i : Total cumulative frequency */
-);
-
-void rc_dec_update(
- Decoder_State *st, /* i/o: Decoder State */
- PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */
- const uint32_t cum_freq, /* i : Cumulative frequency */
- const uint32_t sym_freq /* i : Symbol frequency */
-);
-
-/*! r: Decoded value */
-uint32_t rc_dec_bits(
- Decoder_State *st, /* i/o: Decoder State */
- PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */
- const int16_t bits /* i : Number of bits */
-);
-
-/*! r: Decoded value */
-uint32_t rc_dec_uniform(
- Decoder_State *st, /* i/o: Decoder State */
- PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */
- const uint32_t tot /* i : Maximum value */
-);
-
-void rc_dec_finish(
- Decoder_State *st, /* i/o: decoder state structure */
- PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */
-);
-
-/*! r: number of bits encoded */
-int16_t pvq_core_enc(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- float coefs_norm[], /* i/o: normalized coefficients to encode */
- float coefs_quant[], /* o : quantized coefficients */
- const int16_t bits_tot, /* i : total number of bits */
- const int16_t nb_sfm, /* i : number of bands */
- const int16_t *sfm_start, /* i : Subband start coefficient */
- const int16_t *sfm_end, /* i : Subband end coefficient */
- const int16_t *sfmsize, /* i : subband width */
- int16_t *R, /* i/o: Bit allocation/Adjusted bit alloc. (Q3) */
- int16_t *Rs, /* i/o: Integer bit allocation */
- int16_t *npulses, /* o : number of pulses */
- int16_t *maxpulse, /* i : maximum pulse per band */
- const int16_t core /* i : number of bands */
-);
-
-/*! r: number of bits decoded */
-int16_t pvq_core_dec(
- Decoder_State *st, /* i/o: Decoder state */
- const int16_t *sfm_start, /* i : indices of first coeffs in the bands */
- const int16_t *sfm_end, /* i : indices of last coeffs in the bands */
- const int16_t *sfmsize, /* i : band sizes */
- float coefs_quant[], /* o : output MDCT */
- const int16_t bits_tot, /* i : bit budget */
- const int16_t nb_sfm, /* i : number of bands */
- int16_t *R, /* i/o: Bit allocation/Adjusted bit alloc.(Q3) */
- int16_t *Rs, /* i/o: Integer bit allocation */
- int16_t *npulses, /* o : number of pulses per band */
- int16_t *maxpulse, /* o : maximum pulse per band */
- const int16_t core /* i : core */
-);
-
-void pvq_encode(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */
- const float *x, /* i : vector to quantize */
- int16_t *y, /* o : quantized vector (non-scaled integer)*/
- float *xq, /* o : quantized vector (scaled float) */
- const int16_t pulses, /* i : number of allocated pulses */
- const int16_t N, /* i : Length of vector */
- const float gain /* i : Gain */
-);
-
-void pvq_decode(
- Decoder_State *st, /* i/o: Decoder State */
- PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */
- float *xq, /* o : decoded vector (scaled float) */
- int16_t *y, /* o : decoded vector (non-scaled short)*/
- const int16_t K, /* i : number of allocated pulses */
- const int16_t N, /* i : Length of vector */
- const float gain /* i : Gain */
-);
-
-void rangeCoderFinalizationFBits(
- const int16_t Brc, /* i : Current number of decoded bits */
- const uint32_t INTrc, /* i : Range coder state */
- int16_t *FBits /* i : Fractional finalization bits */
-);
-
-void bandBitsAdjustment(
- const int16_t Brc, /* i : Current number of read quanta in range coder */
- const uint32_t INTrc, /* i : Range coder state */
- const int16_t Bavail, /* i : Available number of quanta */
- const int16_t Nbands, /* i : Number of bands */
- const int16_t D, /* i : Remaining number of bands to encode */
- const int16_t L, /* i : Size of current band */
- const int16_t Bband, /* i : Quanta allocation for current band */
- const int16_t Breserv, /* i : Quanta reservoir */
- int16_t *Bband_adj, /* o : Actual used number of quanta */
- int16_t *Brem, /* o : Quanta remaining */
- int16_t *Breservplus /* o : Quanta pool size */
-);
-
-void conservativeL1Norm(
- const int16_t L, /* i : Length of vector segment */
- const int16_t Qvec, /* i : Assigned number of quanta */
- const int16_t Fcons, /* i : Conservative rounding flag */
- const int16_t Qavail, /* i : Input quanta remaining */
- const int16_t Qreserv, /* i : Input quanta in reservoir */
- const int16_t Dspec, /* i : assigned diracs from bitalloc */
- int16_t *Dvec, /* o : actual number of diracs */
- int16_t *Qspare, /* o : Output quanta remaining */
- int16_t *Qreservplus, /* o : Output quanta in reservoir */
- int16_t *Dspecplus /* o : Output number of diracs */
-);
-
-void NearOppSplitAdjustment(
- const int16_t qband, /* i : quanta for current band */
- const int16_t qzero, /* i : range coder finalization quanta */
- const int16_t Qac, /* i : range coder current quanta */
- const uint32_t INTac, /* i : range coder state */
- const int16_t qglobal, /* i : quanta input */
- const int16_t FlagCons, /* i : conservative rounding flag */
- const int16_t Np, /* i : number of parts */
- const int16_t Nhead, /* i : first part */
- const int16_t Ntail, /* i : remaining parts */
- const int16_t Nnear, /* i : length of near component */
- const int16_t Nopp, /* i : length of opposite component */
- int16_t oppRQ3, /* i : ratio */
- int16_t *qnear, /* o : quantized near */
- int16_t *qopp, /* o : quantized opposite */
- int16_t *qglobalupd /* o : quanta remaining */
-);
-
-/*! r: Approximate integer division for positive input */
-int32_t intLimCDivPos(
- const int32_t NUM, /* i : numerator */
- const int16_t DEN /* i : denominator */
-);
-
-/*! r: Approximate integer division */
-int16_t shrtCDivSignedApprox_flt(
- const int16_t num, /* i : numerator */
- const int16_t den /* i : denominator */
-);
-
-void QuantaPerDsDirac(
- const int16_t td, /* i : Length of vector segment */
- const int16_t dsDiracIndex, /* i : Quanta table index */
- const uint8_t *const *dimFrQuanta, /* i : Quanta lookup table */
- int16_t *Quanta /* i : Quanta */
-);
-
-void obtainEnergyQuantizerDensity(
- const int16_t L_in, /* i : left vector energy */
- const int16_t R_in, /* i : right vector energy */
- int16_t *Density /* o : quantizer density */
-);
-
-void densityAngle2RmsProjDec(
- const int16_t D, /* i : density */
- const int16_t indexphi, /* i : decoded index from AR dec */
- int16_t *oppQ15, /* o : opposite */
- int16_t *nearQ15, /* o : near */
- int16_t *oppRatioQ3 /* o : ratio */
-);
-
-void densityAngle2RmsProjEnc(
- const int16_t D, /* i : density */
- const int16_t phiQ14uq, /* i : angle */
- int16_t *indexphi, /* o : index */
- int16_t *oppQ15, /* o : opposite */
- int16_t *nearQ15, /* o : near */
- int16_t *oppRatioQ3 /* o : ratio */
-);
-
-void env_adj(
- const int16_t *pulses, /* i : number of pulses per band */
- const int16_t length, /* i : length of spectrum */
- const int16_t last_sfm, /* i : Index of last band */
- float *adj, /* o : Adjustment factors for the envelope */
- const float env_stab, /* i : Envelope stability parameter */
- const int16_t *sfmsize /* i : Length of bands */
-);
-
-float env_stability(
- const int16_t *ynrm, /* i : Norm vector for current frame */
- const int16_t nb_sfm, /* i : Number of sub-bands */
- int16_t *mem_norm, /* i/o: Norm vector memory from past frame */
- int16_t *mem_env_delta, /* i/o: Envelope stability memory for smoothing*/
- const int16_t core_switching_flag /* i : Core switching flag */
-);
-
-/*! r: New speech/music state */
-float env_stab_smo(
- float env_stab, /* i : env_stab value */
- float *env_stab_state_p, /* i/o: env_stab state probabilities */
- int16_t *ho_cnt /* i/o: hangover counter for speech state */
-);
-void core_switching_post_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- // const float *old_inp_12k8, /* i : old input signal @12.8kHz */
- float *old_inp_12k8, /* i : old input signal @12.8kHz */
- // const float *old_inp_16k, /* i : old input signal @16kHz */
- float *old_inp_16k, /* i : old input signal @16kHz */
- // const float A[] /* i : unquant. LP filter coefs. */
- Word16 A_fx[], /* i : unquant. LP filter coefs. */
- Word16 Q_new );
-ivas_error core_switching_post_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- float *synth, /* i/o: output synthesis */
- float *output, /* i/o: LB synth/upsampled LB synth */
- float output_mem[], /* i : OLA memory from last TCX/HQ frame */
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
- const int16_t output_frame, /* i : frame length */
- const int16_t core_switching_flag, /* i : ACELP->HQ switching frame flag */
- const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */
- const int16_t nchan_out, /* i : number of output channels */
- const int16_t last_element_mode /* i : element mode of previous frame */
-);
-
-ivas_error core_switching_pre_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t output_frame, /* i : frame length */
- const int32_t last_core_brate_st0, /* i : channel 0 last core bitrate */
- const int16_t nchan_out, /* i : number of output channels */
- const int16_t last_element_mode, /* i : last_element_mode */
- const int32_t last_element_brate /* i : last element bitrate */
-);
-
-void bandwidth_switching_detect(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-void bw_switching_pre_proc(
- Decoder_State *st, /* i/o: decoder state structure */
- const float *old_syn_12k8_16k, /* i : ACELP core synthesis @ 12.8kHz or 16kHz */
- const int32_t last_element_brate, /* i : last element bitrate */
- const int16_t nchan_out /* i : number of output channels */
-);
-
-void updt_bw_switching(
- Decoder_State *st, /* i/o: decoder state structure */
- const float *synth /* i : float synthesis signal */
-);
-
-void swb_tbe_reset(
- float mem_csfilt[],
- float mem_genSHBexc_filt_down_shb[],
- float state_lpc_syn[],
- float syn_overlap[],
- float state_syn_shbexc[],
- float *tbe_demph,
- float *tbe_premph,
- float mem_stp_swb[],
- float *gain_prec_swb );
-
-void swb_tbe_reset_synth(
- float genSHBsynth_Hilbert_Mem[],
- float genSHBsynth_state_lsyn_filt_shb_local[] );
-
-void find_td_envelope(
- const float inp[],
- const int16_t len,
- const int16_t len_h,
- float mem_h[],
- float out[] );
-
-void fb_tbe_reset_enc(
- float elliptic_bpf_2_48k_mem[][4],
- float *prev_fb_energy );
-
-void fb_tbe_reset_synth(
- float fbbwe_hpf_mem[][4],
- float *prev_fbbwe_ratio );
-
-void wb_tbe_extras_reset(
- float mem_genSHBexc_filt_down_wb2[],
- float mem_genSHBexc_filt_down_wb3[] );
-
-void wb_tbe_extras_reset_synth(
- float state_lsyn_filt_shb[],
- float state_lsyn_filt_dwn_shb[],
- float mem_resamp_HB[] );
-
-void tbe_celp_exc_flt(
- const int16_t element_mode, /* i : element mode */
- const int16_t idchan, /* i : channel ID */
- float *bwe_exc, /* i/o: BWE excitation */
- const int16_t L_frame, /* i : frame length */
- const int16_t L_subfr, /* i : subframe length */
- const int16_t i_subfr, /* i : subframe index */
- const int16_t T0, /* i : integer pitch lag */
- const int16_t T0_frac, /* i : fraction of lag */
- float *error, /* i/o: error */
- const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */
-);
-
-void prep_tbe_exc(
- const int16_t L_frame, /* i : length of the frame */
- const int16_t L_subfr, /* i : subframe length */
- const int16_t i_subfr, /* i : subframe index */
- const float gain_pit, /* i : Pitch gain */
- const float gain_code, /* i : algebraic codebook gain */
- const float code[], /* i : algebraic excitation */
- const float voice_fac, /* i : voicing factor */
- float *voice_factors, /* o : TBE voicing factor */
- float bwe_exc[], /* i/o: excitation for TBE */
- const float gain_preQ, /* i : prequantizer excitation gain */
- const float code_preQ[], /* i : prequantizer excitation */
- const int16_t T0, /* i : integer pitch variables */
- const int16_t coder_type, /* i : coding type */
- const int32_t core_brate, /* i : core bitrate */
- const int16_t element_mode, /* i : element mode */
- const int16_t idchan, /* i : channel ID */
- const int16_t flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */
- const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */
-);
-
-void synthesise_fb_high_band(
- const float excitation_in[], /* i : full band excitation */
- float output[], /* o : high band speech - 14.0 to 20 kHz */
- const float fb_exc_energy, /* i : full band excitation energy */
- const float ratio_float, /* i : energy ratio */
- const int16_t L_frame, /* i : ACELP frame length */
- const int16_t bfi, /* i : BFI flag */
- float *prev_fbbwe_ratio, /* o : previous frame energy for FEC */
- float bpf_memory[][4] /* i/o: memory for elliptic bpf 48k */
-);
-
-void elliptic_bpf_48k_generic(
- const float input[], /* i : input signal */
- float output[], /* o : output signal */
- float memory[][4], /* i/o: 4 arrays for memory */
- const float full_band_bpf[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 */
-);
-
-void HQ_FEC_processing(
- Decoder_State *st, /* i/o: decoder state structure */
- float *t_audio_q, /* o : MDCT coeffs. (for synthesis) */
- int16_t is_transient, /* i : Old flag for transient */
- float ynrm_values[][MAX_PGF], /* i : Old average Norm values for each group of bands */
- float r_p_values[][MAX_ROW], /* i : Computed y-intercept and slope by Regression */
- int16_t num_Sb, /* i : Number of sub-band group */
- int16_t nb_sfm, /* i : Number of sub-band */
- int16_t *Num_bands_p, /* i : Number of coeffs. for each sub-band */
- int16_t output_frame, /* i : Frame size */
- const int16_t *sfm_start, /* i : Start of bands */
- const int16_t *sfm_end /* i : End of bands */
-);
-
-void HQ_FEC_Mem_update(
- Decoder_State *st, /* i/o: decoder state structure */
- const float *t_audio_q,
- float *normq,
- int16_t *ynrm,
- const int16_t *Num_bands_p,
- const int16_t is_transient,
- const int16_t hqswb_clas,
- const int16_t c_switching_flag,
- const int16_t nb_sfm,
- const int16_t num_Sb,
- float *mean_en_high,
- const int16_t hq_core_type, /* i : normal or low-rate MDCT(HQ) core */
- const int16_t output_frame /* i : Frame size */
-);
-
-void time_domain_FEC_HQ(
- Decoder_State *st, /* i : Decoder State */
- float *wtda_audio, /* i : input */
- float *out, /* o : output audio */
- const float mean_en_high, /* i : transient flag */
- const int16_t output_frame /* i : Frame size */
-);
-
-void save_synthesis_hq_fec(
- Decoder_State *st, /* i/o: decoder state structure */
- const float *output, /* i : decoded synthesis */
- const int16_t output_frame, /* i : decoded synthesis */
- CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */
-);
-
-void Next_good_after_burst_erasures(
- const float *ImdctOut, /* i : input */
- float *auOut, /* o : output audio */
- float *OldauOut, /* i/o: audio from previous frame */
- const int16_t ol_size /* i : overlap size */
-);
-
-
-void reset_preecho_dec(
- HQ_DEC_HANDLE hHQ_core /* i/o: HQ decoder handle */
-);
-
-void preecho_sb(
- const int32_t core_brate, /* i : core bitrate */
- const float wtda_audio[], /* i : imdct signal */
- float *rec_sig, /* i : reconstructed signal, output of the imdct transform */
- const int16_t framelength, /* i : frame length */
- float *memfilt_lb, /* i/o: memory */
- float *mean_prev_hb, /* i/o: memory */
- float *smoothmem, /* i/o: memory */
- float *mean_prev, /* i/o: memory */
- float *mean_prev_nc, /* i/o: memory */
- float *wmold_hb, /* i/o: memory */
- int16_t *prevflag, /* i/o: flag */
- int16_t *pastpre, /* i/o: flag */
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-void hq2_core_configure(
- const int16_t frame_length, /* i : frame length */
- const int16_t num_bits, /* i : number of bits */
- const int16_t is_transient, /* i : transient flag */
- int16_t *bands,
- int16_t *length,
- int16_t band_width[],
- int16_t band_start[],
- int16_t band_end[],
- Word32 *L_qint, /* o : Q29 */
- Word16 *eref_fx, /* o : Q10 */
- Word16 *bit_alloc_weight_fx, /* o : Q13 */
- int16_t *gqlevs,
- int16_t *Ngq,
- int16_t *p2a_bands,
- float *p2a_th,
- float *pd_thresh,
- float *ld_slope,
- float *ni_coef,
- float *ni_pd_th,
- int32_t bwe_br );
-
-void hq_lr_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- float t_audio[], /* i/o: transform-domain coefs. */
- const int16_t inner_frame, /* i : inner frame length */
- int16_t *num_bits, /* i/o: number of available bits */
- const int16_t is_transient /* i : transient flag */
-);
-
-void hq_lr_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- float yout[], /* o : transform-domain output coefs. */
- const int16_t inner_frame, /* i : inner frame length */
- int16_t num_bits, /* i : number of available bits */
- int16_t *is_transient /* o : transient flag */
-);
-
-void hq2_bit_alloc(
- const float band_energy[], /* i : band energy of each subband */
- const int16_t bands, /* i : total number of subbands in a frame */
- Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */
- int16_t *bit_budget, /* i/o: bit bugdet */
- int16_t *p2a_flags, /* i : HF tonal indicator */
- const Word16 weight_fx, /* i : weight (Q13) */
- const int16_t band_width[], /* i : Sub band bandwidth */
- const int16_t num_bits, /* i : available bits */
- const int16_t hqswb_clas, /* i : HQ2 class information */
- const int16_t bwidth, /* i : input bandwidth */
- const int16_t is_transient /* i : indicator HQ_TRANSIENT or not */
-);
-
-void hq2_noise_inject(
- float y2hat[],
- const int16_t band_start[],
- const int16_t band_end[],
- const int16_t band_width[],
- float Ep[],
- float Rk[],
- const int16_t npulses[],
- int16_t ni_seed,
- const int16_t bands,
- const int16_t ni_start_band,
- const int16_t bw_low,
- const int16_t bw_high,
- const float enerL,
- const float enerH,
- float last_ni_gain[],
- float last_env[],
- int16_t *last_max_pos_pulse,
- int16_t *p2a_flags,
- int16_t p2a_bands,
- const int16_t hqswb_clas,
- const int16_t bwidth,
- const int32_t bwe_br );
-
-void mdct_spectrum_denorm(
- const int32_t inp_vector[],
- float y2[],
- const int16_t band_start[],
- const int16_t band_end[],
- const int16_t band_width[],
- const float band_energy[],
- const int16_t npulses[],
- const int16_t bands,
- const float ld_slope,
- const float pd_thresh );
-
-void reverse_transient_frame_energies(
- float band_energy[], /* o : band energies */
- const int16_t bands /* i : number of bands */
-);
-
-
-void hvq_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t num_bits, /* i : Number of available bits */
- const int32_t core_brate, /* i : Core bitrate */
- const int16_t *ynrm, /* i : Envelope coefficients */
- int16_t *R, /* i/o: Bit allocation/updated bit allocation */
- float *noise_level, /* o : Noise level */
- int16_t *peak_idx, /* o : Peak position vector */
- int16_t *Npeaks, /* o : Total number of peaks */
- float *coefsq_norm, /* o : Output vector */
- const int16_t core /* i : Core */
-);
-
-void hq_configure_bfi(
- int16_t *nb_sfm, /* o : Number of sub bands */
- int16_t *num_Sb, /* o : Number of FEC sub bands ? */
- int16_t *num_bands_p, /* o : FEC sub bands */
- const int16_t **sfmsize, /* o : Subband bandwidths */
- const int16_t **sfm_start, /* o : Subband start coefficients */
- const int16_t **sfm_end /* o : Subband end coefficients */
-);
-
-void swb_bwe_enc_lr(
- Encoder_State *st, /* i/o: encoder state structure */
- const float m_core[], /* i : core synthesis (MDCT) */
- const float m_orig[], /* i/o: scaled orig signal (MDCT) */
- float m[], /* o : output, SWB part (MDCT) */
- const int32_t total_brate, /* i : total bitrate for selecting subband pattern */
- int16_t BANDS,
- int16_t *band_start,
- int16_t *band_end,
- float *band_energy,
- int16_t *p2a_flags,
- const int16_t hqswb_clas,
- int16_t lowlength,
- int16_t highlength,
- int16_t *prev_frm_index,
- const int16_t har_bands,
- int16_t *prev_frm_hfe2,
- int16_t *prev_stab_hfe2,
- int16_t band_width[],
- const float y2_ni[],
- int16_t *ni_seed );
-
-void swb_bwe_dec_lr(
- Decoder_State *st, /* i/o: decoder state structure */
- const float m_core[], /* i : lowband synthesis */
- float m[], /* o : highband synthesis with lowband zeroed */
- const int32_t total_brate, /* i : total bitrate for selecting subband pattern */
- int16_t BANDS,
- int16_t *band_start,
- int16_t *band_end,
- float *band_energy,
- int16_t *p2a_flags,
- const int16_t hqswb_clas,
- int16_t lowlength,
- int16_t highlength,
- const int16_t har_bands,
- int16_t *prev_frm_hfe2,
- int16_t *prev_stab_hfe2,
- int16_t band_width[],
- const float y2_ni[],
- int16_t *ni_seed );
-
-int16_t get_usebit_npswb(
- const int16_t hqswb_clas );
-
-void GetPredictedSignal(
- const float *predBuf, /* i : prediction buffer */
- float *outBuf, /* o : output buffer */
- const int16_t lag, /* i : prediction buffer offset */
- const int16_t fLen, /* i : length of loop (output) */
- const float gain /* i : gain to be applied */
-);
-
-void convert_lagIndices_pls2smp(
- int16_t lagIndices_in[],
- int16_t nBands_search,
- int16_t lagIndices_out[],
- const float sspectra[],
- const int16_t sbWidth[],
- const int16_t fLenLow );
-
-void FindNBiggest2_simple(
- const float *inBuf, /* i : input buffer (searched) */
- GainItem *g, /* o : N biggest components found */
- const int16_t nIdx, /* i : search length */
- int16_t *n, /* i : number of components searched (N biggest) */
- const int16_t N_NBIGGESTSEARCH );
-
-void updat_prev_frm(
- float y2[],
- float t_audio[],
- const int32_t bwe_br,
- const int16_t length,
- const int16_t inner_frame,
- const int16_t bands,
- const int16_t bwidth,
- const int16_t is_transient,
- const int16_t hqswb_clas,
- int16_t *prev_hqswb_clas,
- int16_t *prev_SWB_peak_pos,
- int16_t prev_SWB_peak_pos_tmp[],
- int16_t *prev_frm_hfe2,
- int16_t *prev_stab_hfe2,
- const int16_t bws_cnt );
-
-void hf_parinitiz(
- const int32_t total_brate,
- const int16_t hqswb_clas,
- int16_t lowlength,
- int16_t highlength,
- int16_t wBands[],
- const int16_t **subband_search_offset,
- const int16_t **subband_offsets,
- int16_t *nBands,
- int16_t *nBands_search,
- int16_t *swb_lowband,
- int16_t *swb_highband );
-
-float spectrumsmooth_noiseton(
- float spectra[],
- const float spectra_ni[],
- float sspectra[],
- float sspectra_diff[],
- float sspectra_ni[],
- const int16_t fLenLow,
- int16_t *ni_seed );
-
-void noiseinj_hf(
- float xSynth_har[],
- const float th_g[],
- const float band_energy[],
- float *prev_En_sb,
- const int16_t p2a_flags[],
- const int16_t BANDS,
- const int16_t band_start[],
- const int16_t band_end[],
- const int16_t fLenLow );
-
-void noise_extr_corcod(
- float spectra[],
- const float spectra_ni[],
- float sspectra[],
- float sspectra_diff[],
- float sspectra_ni[],
- const int16_t fLenLow,
- int16_t prev_hqswb_clas,
- float *prev_ni_ratio );
-
-void genhf_noise(
- float noise_flr[],
- float xSynth_har[],
- float *predBuf,
- int16_t bands, /* i : total number of subbands in a frame */
- int16_t harmonic_band, /* i : Number of LF harmonic frames */
- int16_t har_freq_est2,
- int16_t pos_max_hfe2,
- int16_t *pul_res,
- GainItem pk_sf[],
- const int16_t fLenLow,
- const int16_t fLenHigh,
- const int16_t sbWidth[],
- const int16_t lagIndices[],
- const int16_t subband_offsets[],
- const int16_t subband_search_offset[] );
-
-void ton_ene_est(
- float xSynth_har[],
- float be_tonal[],
- float band_energy[],
- int16_t band_start[],
- int16_t band_end[],
- int16_t band_width[],
- const int16_t fLenLow,
- const int16_t fLenHigh,
- int16_t bands,
- int16_t har_bands,
- float ni_lvl,
- GainItem pk_sf[],
- int16_t *pul_res );
-
-void Gettonl_scalfact(
- float *outBuf, /* o : synthesized spectrum */
- const float *codbuf, /* i : core coder */
- const int16_t fLenLow, /* i : lowband length */
- const int16_t fLenHigh, /* i : highband length */
- int16_t harmonic_band, /* i : Number of LF harmonic frames */
- int16_t bands, /* i : total number of subbands in a frame */
- float *band_energy, /* i : band energy of each subband */
- int16_t *band_start, /* i : subband start indices */
- int16_t *band_end, /* i : subband end indices */
- const int16_t p2aflags[],
- float be_tonal[],
- GainItem *pk_sf,
- int16_t *pul_res );
-
-void SpectrumSmoothing(
- float *inBuf,
- float *outBuf,
- const int16_t fLen,
- const float th_cut );
-
-void hq2_bit_alloc_har(
- float *y, /* i : band energy of sub-vectors */
- int16_t B, /* i : number of available bits */
- int16_t N, /* i : number of sub-vectors */
- Word32 *L_Rsubband,
- int16_t p2a_bands,
- int32_t core_brate, /* i : core bitrate */
- int16_t p2a_flags[],
- int16_t band_width[] );
-
-void GetSynthesizedSpecThinOut(
- const float *predBuf,
- float *outBuf,
- const int16_t nBands,
- const int16_t *sbWidth,
- const int16_t *lagIndices,
- const float *lagGains,
- const int16_t predBufLen );
-
-void return_bits_normal2(
- int16_t *bit_budget,
- const int16_t p2a_flags[],
- const int16_t bands,
- const int16_t bits_lagIndices[] );
-
-void GetlagGains(
- const float *predBuf,
- const float *band_energy,
- const int16_t nBands,
- const int16_t *sbWidth,
- const int16_t *lagIndices,
- const int16_t predBufLen,
- float *lagGains );
-
-void preset_hq2_swb(
- const int16_t hqswb_clas,
- const int16_t band_end[],
- int16_t *har_bands,
- int16_t p2a_bands,
- const int16_t length,
- const int16_t bands,
- int16_t *lowlength,
- int16_t *highlength,
- float m[] );
-
-void post_hq2_swb(
- const float m[],
- const int16_t lowlength,
- const int16_t highlength,
- const int16_t hqswb_clas,
- const int16_t har_bands,
- const int16_t bands,
- const int16_t p2a_flags[],
- const int16_t band_start[],
- const int16_t band_end[],
- float y2[],
- int16_t npulses[] );
-
-void har_denorm_pulcnt(
- float spectra[], /* i/o: MDCT domain spectrum */
- const int16_t band_start[], /* i : Number subbands/Frame */
- const int16_t band_end[], /* i : Band Start of each SB */
- const float band_energy[], /* i : Band end of each SB */
- const int16_t band_width[],
- const int16_t npulses[],
- const int16_t har_bands /* i : No. of harmonic bands */
-);
-
-int16_t har_est(
- float spectra[],
- const int16_t N,
- int16_t *har_freq_est1,
- int16_t *har_freq_est2,
- int16_t *flag_dis,
- int16_t *prev_frm_hfe2,
- const int16_t subband_search_offset[],
- const int16_t sbWidth[],
- int16_t *prev_stab_hfe2 );
-
-void spt_shorten_domain_pre(
- const int16_t band_start[],
- const int16_t band_end[],
- const int16_t prev_SWB_peak_pos[],
- const int16_t BANDS,
- const int32_t bwe_br,
- int16_t new_band_start[],
- int16_t new_band_end[],
- int16_t new_band_width[] );
-
-void spt_shorten_domain_band_save(
- const int16_t bands,
- const int16_t band_start[],
- const int16_t band_end[],
- const int16_t band_width[],
- int16_t org_band_start[],
- int16_t org_band_end[],
- int16_t org_band_width[] );
-
-void spt_shorten_domain_band_restore(
- const int16_t bands,
- int16_t band_start[],
- int16_t band_end[],
- int16_t band_width[],
- const int16_t org_band_start[],
- const int16_t org_band_end[],
- const int16_t org_band_width[] );
-
-void spt_swb_peakpos_tmp_save(
- const float y2[],
- const int16_t bands,
- const int16_t band_start[],
- const int16_t band_end[],
- int16_t prev_SWB_peak_pos_tmp[] );
-
-void hq_ecu(
- const float *prevsynth, /* i : buffer of previously synthesized signal */
- float *ecu_rec, /* o : reconstructed frame in tda domain */
- int16_t *time_offs, /* i/o: Sample offset for consecutive frame losses*/
- float *X_sav, /* i/o: Stored spectrum of prototype frame */
- int16_t *num_p, /* i/o: Number of identified peaks */
- int16_t *plocs, /* i/o: Peak locations */
- float *plocsi, /* i/o: Interpolated peak locations */
- const float env_stab, /* i : Envelope stability parameter */
- int16_t *last_fec, /* i/o: Flag for usage of pitch dependent ECU */
- const int16_t ph_ecu_HqVoicing, /* i : HQ Voicing flag */
- int16_t *ph_ecu_active, /* i : Phase ECU active flag */
- float *gapsynth, /* o : Gap synthesis */
- const int16_t prev_bfi, /* i : indicating burst frame error */
- const int16_t old_is_transient[2], /* i : flags indicating previous transient frames*/
- float *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/
- float Xavg[LGW_MAX], /* i/o: Frequency group average gain to fade to */
- float *beta_mute, /* o : Factor for long-term mute */
- const int16_t output_frame, /* i : frame length */
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-void peakfinder(
- const float *x0, /* i : vector from which the maxima will be found */
- const int16_t len0, /* i : length of input vector */
- int16_t *plocs, /* o : the indicies of the identified peaks in x0 */
- int16_t *cInd, /* o : number of identified peaks */
- const float sel, /* i : The amount above surrounding data for a peak to be identified */
- const int16_t endpoints /* i : Flag to include endpoints in peak search */
-);
-
-/*! r: interpolated maximum position */
-float imax_pos(
- const float *y /* i : Input vector for peak interpolation */
-);
-
-
-void fft3(
- const float X[], /* i : input frame */
- float Y[], /* o : DFT of input frame */
- const int16_t n /* i : block length (must be radix 3) */
-);
-
-void ifft3(
- const float X[], /* i : input frame */
- float Y[], /* o : iDFT of input frame */
- const int16_t n /* i : block length (must be radix 3) */
-);
-
-/*! r: updated estimate of background noise */
-void minimumStatistics(
- float *noiseLevelMemory, /* i/o: internal state */
- int16_t *noiseLevelIndex, /* i/o: internal state */
- int16_t *currLevelIndex, /* i/o: internal state (circular buffer) */
- float *noiseEstimate, /* i/o: previous estimate of background noise */
- float *lastFrameLevel, /* i/o: level of the last frame */
- float currentFrameLevel, /* i : level of the current frame */
- const float minLev, /* i : minimum level */
- const int16_t buffSize /* i : buffer size */
-);
-
-void E_ACELP_toeplitz_mul(
- const float R[],
- const float c[],
- float d[] );
-
-void E_ACELP_innovative_codebook(
- const float *exc, /* i : pointer to the excitation frame */
- const int16_t T0, /* i : integer pitch lag */
- const int16_t T0_frac, /* i : fraction of lag */
- const int16_t T0_res, /* i : pitch resolution */
- const float pitch_gain, /* i : adaptive codebook gain */
- const float tilt_code, /* i : tilt factor */
- ACELP_config *acelp_cfg, /* i/o: configuration of the ACELP */
- const int16_t i_subfr, /* i : subframe index */
- const float *Aq, /* i : quantized LPC coefficients */
- const float *h1, /* i : impulse response of weighted synthesis filter */
- const float *xn, /* i : Close-loop Pitch search target vector */
- const float *cn, /* i : Innovative codebook search target vector */
- const float *y1, /* i : zero-memory filtered adaptive excitation */
- float *y2, /* o : zero-memory filtered algebraic excitation */
- const int16_t acelpautoc, /* i : autocorrelation mode enabled */
- int16_t **pt_indice, /* i/o: quantization indices pointer */
- float *code, /* o : innovative codebook */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t last_L_frame, /* i : length of the last frame */
- const int32_t total_brate /* i : total bitrate */
-);
-
-int16_t E_ACELP_code43bit(
- const float code[],
- uint32_t *ps,
- int16_t *p,
- uint16_t idxs[] );
-void D_ACELP_indexing_ivas(
- float code[],
- PulseConfig config,
- const int16_t num_tracks,
- int16_t prm[],
- int16_t *BER_detect );
-
-void D_ACELP_decode_43bit(
- uint16_t idxs[],
- float code[],
- int16_t *pulsestrack );
-
-void fcb_pulse_track_joint_decode_ivas(
- uint16_t *idxs,
- const int16_t wordcnt,
- uint32_t *index_n,
- const int16_t *pulse_num,
- const int16_t track_num );
-
-void lag_wind_flt(
- float r[], /* i/o: autocorrelations */
- const int16_t m, /* i : order of LP filter */
- const int32_t sr_core, /* i : sampling rate */
- const int16_t strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */
-);
-
-void adapt_lag_wind_fx(
- float r[], /* i/o: autocorrelations */
- const int16_t m, /* i : order of LP filter */
- const int16_t Top, /* i : open loop pitch lags from curr. frame (or NULL if n/a) */
- const float Tnc, /* i : open loop pitch gains from curr. frame (NULL if n/a) */
- const int32_t sr_core /* i : core sampling rate */
-);
-
-void core_coder_reconfig(
- Encoder_State *st, /* i/o: encoder state structure */
- const int32_t last_total_brate /* i : last total bitrate */
-);
-
-void core_coder_mode_switch(
- Encoder_State *st, /* i/o: encoder state structure */
- const int32_t last_total_brate, /* i : last bitrate */
- const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0)*/
-);
-
-void enc_acelp_tcx_main(
- Encoder_State *st, /* i/o: encoder state structure */
- const float new_samples[], /* i : new samples */
- float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/
- const float lsp_new[M], /* i : LSPs at the end of the frame */
- const float lsp_mid[M], /* i : LSPs at the middle of the frame */
- float bwe_exc_extended[], /* i/o: bandwidth extended excitation */
- float *voice_factors, /* o : voicing factors */
- float pitch_buf[], /* o : floating pitch for each subframe */
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-void getTCXMode_ivas(
- Decoder_State *st, /* i/o: decoder memory state */
- Decoder_State *st0, /* i : bitstream */
- const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0)*/
-);
-
-void getTCXWindowing_ivas(
- const Word16 core, /* i : current frame mode */
- const Word16 last_core, /* i : last frame mode */
- const Word16 element_mode, /* i : element mode */
- TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */
- Decoder_State *st0 /* i : bitstream */
-);
-
-void getLPCparam_ivas(
- Decoder_State *st, /* i/o: decoder memory state */
- int16_t param_lpc[], /* o : LTP parameters */
- Decoder_State *st0, /* i : bitstream */
- const int16_t ch, /* i : channel */
- const int16_t sns_low_br_mode /* i : SNS low-bitrate mode */
-);
-
-void getTCXparam_ivas(
- Decoder_State *st, /* i/o: Decoder State handle */
- Decoder_State *st0, /* i : bitstream */
- CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */
- int16_t param[], /* o : decoded parameters */
- const int16_t bits_common, /* i : number of common bits */
- const int16_t start_bit_pos, /* i : position of the start bit */
- const int16_t *no_param_tns, /* i : number of TNS parameters per subframe */
- int16_t p_param[2], /* o : pointer to parameters for next round of bs reading*/
- int16_t nTnsBitsTCX10[2],
- const int16_t pre_past_flag );
-
-void pitch_pred_linear_fit_flt(
- const int16_t nbLostCmpt, /* i : bfi counter */
- const int16_t last_good, /* i : last classification type */
- float *old_pitch_buf, /* i : pitch lag buffer */
- float *old_fpitch, /* i/o: pitch used for initial ACB generation */
- float *T0_out, /* o : estimated close loop pitch */
- const int16_t pit_min, /* i : Minimum pitch lag */
- const int16_t pit_max, /* i : Maximum pitch lag */
- float *mem_pitch_gain, /* i : lag pitch gain [0] is the most recent subfr lag */
- const int16_t limitation,
- const int16_t plc_use_future_lag, /* i : number of subframes to predict */
- int16_t *extrapolationFailed, /* o : flag if extrap decides not to change the pitch */
- const int16_t nb_subfr /* i : number of ACELP subframes */
-);
-
-void get_subframe_pitch_flt(
- const int16_t nSubframes, /* i : number of subframes */
- float pitchStart, /* i : starting pitch lag (in subframe -1) */
- float pitchEnd, /* i : ending pitch lag (in subframe nSubframes-1) */
- float *pitchBuf /* o : interpolated pitch lag per subframe */
-);
-
-void core_encode_openloop(
- Encoder_State *st, /* i/o: encoder state structure */
- const float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/
- const float lsp_new[M], /* i : LSPs at the end of the frame */
- const float lsp_mid[M], /* i : LSPs at the middle of the frame */
- float *pitch_buf, /* i/o: floating pitch values for each subfr*/
- float *voice_factors, /* o : voicing factors */
- float *ptr_bwe_exc, /* o : excitation for SWB TBE */
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-void core_acelp_tcx20_switching(
- Encoder_State *st, /* i/o: encoder state structure */
- float non_staX, /* i : unbound non-stationarity for sp/mu clas */
- float *pitch_fr, /* i/o: fraction pitch values */
- float *voicing_fr, /* i/o: fractional voicing values */
- const float currTempFlatness, /* i : flatness */
- const float lsp_mid[M], /* i : LSPs at the middle of the frame */
- const float stab_fac /* i : LP filter stability */
-);
-
-void core_encode_twodiv(
- Encoder_State *st, /* i/o: coder memory state */
- const float new_samples[], /* i : new samples */
- float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-void core_encode_update(
- Encoder_State *st /* i/o: encoder state structure */
-);
-
-void core_encode_update_cng(
- Encoder_State *st, /* i/o: encoder state structure */
- float *timeDomainBuffer,
- float *A,
- const float Aw[] /* i : weighted A(z) unquant. for subframes*/
-);
-
-void core_signal_analysis_high_bitrate(
- const float *new_samples,
- const int16_t T_op[3], /* i : open-loop pitch values for quantiz. */
- float lsp_new[],
- float lsp_mid[],
- Encoder_State *st,
- float *mdst_spectrum[2],
- int16_t pTnsSize[],
- int16_t pTnsBits[],
- int16_t param_core[],
- int16_t *ltpBits,
- float *windowed_samples, /* i/o: backup of windowed time signal */
- const int16_t L_frame,
- const int16_t L_frameTCX,
- const int16_t last_element_mode,
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-void encode_acelp_gains(
- const float *code,
- const int16_t gains_mode,
- const float mean_ener_code,
- const int16_t clip_gain,
- ACELP_CbkCorr *g_corr,
- float *gain_pit,
- float *gain_code,
- int16_t **pt_indice,
- float *past_gcode,
- float *gain_inov,
- const int16_t L_subfr,
- float *code2,
- float *gain_code2,
- const int16_t noisy_speech_flag );
-
-int16_t gain_enc_gacelp_uv(
- const float *code, /* i : algebraic excitation */
- const float *code2, /* i : gaussian excitation */
- const int16_t lcode, /* i : Subframe size */
- const float mean_ener, /* i : quantized mean energy of the frame */
- float *gain_pit, /* o : quantized pitch gain */
- float *gain_code, /* o : quantized codebook gain */
- float *gain_code2, /* o : quantized codebook gain */
- ACELP_CbkCorr *coeff, /* i/o: correlations , -2,, -2 and 2 */
- float *past_gcode, /* i/o: past gain of code */
- float *gain_inov, /* o : unscaled innovation gain */
- const int16_t noisy_speech_flag /* i : noisy speech flag */
-);
-
-int16_t Mode2_gain_enc_mless(
- const float *code, /* i : algebraic excitation */
- const int16_t lcode, /* i : Subframe size */
- float *gain_pit, /* o : quantized pitch gain */
- float *gain_code, /* o : quantized codebook gain */
- ACELP_CbkCorr *coeff, /* i/o: correlations , -2,, -2 and 2 */
- const float mean_ener, /* i : mean_ener defined in open-loop (3 bits) */
- const int16_t clip_gain, /* i : gain pitch clipping flag (1 = clipping) */
- float *past_gcode, /* i/o: past gain of code */
- float *gain_inov, /* o : unscaled innovation gain */
- const int16_t coder_type /* i : type of coder */
-);
-
-void decode_acelp_gains(
- const float *code,
- const int16_t gains_mode,
- const float mean_ener_code,
- float *gain_pit,
- float *gain_code,
- int16_t **pt_indice,
- float *past_gpit,
- float *past_gcode,
- float *gain_inov,
- const int16_t L_subfr,
- float *code2,
- float *gain_code2 );
-
-void gain_dec_gacelp_uv(
- int16_t index, /* i/o: Quantization index vector */
- const float *code, /* i : algebraic code excitation */
- const float *code2, /* i : algebraic code excitation */
- const float mean_ener, /* i : mean energy */
- const int16_t lcode, /* i : Subframe size */
- float *gain_pit, /* o : Quantized pitch gain */
- float *gain_code, /* o : Quantized codebook gain */
- float *gain_code2, /* o : Quantized codebook gain */
- float *past_gpit, /* i/o: past gain of pitch */
- float *past_gcode, /* i/o: past energy of code */
- float *gain_inov /* o : unscaled innovation gain */
-);
-
-void limit_T0_voiced_ivas(
- const int16_t nbits,
- const int16_t res,
- const int16_t T0, /* i : rough pitch estimate around which the search is done */
- const int16_t T0_frac, /* i : pitch estimate fractional part */
- const int16_t T0_res, /* i : pitch resolution */
- int16_t *T0_min, /* o : lower pitch limit */
- int16_t *T0_min_frac, /* o : lower pitch limit */
- int16_t *T0_max, /* o : higher pitch limit */
- int16_t *T0_max_frac, /* o : higher pitch limit */
- const int16_t pit_min, /* i : Minimum pitch lag */
- const int16_t pit_max /* i : Maximum pitch lag */
-);
-
-
-/*! r: floating pitch value */
-float Mode2_pit_decode_flt(
- const int16_t coder_type, /* i : coding model */
- const int16_t i_subfr, /* i : subframe index */
- const int16_t L_subfr, /* i : sub-frame length */
- int16_t **pt_indice, /* i/o: quantization indices pointer */
- int16_t *T0, /* o : close loop integer pitch */
- int16_t *T0_frac, /* o : close loop fractional part of the pitch */
- int16_t *T0_res, /* i/o: pitch resolution */
- int16_t *T0_min, /* i/o: lower limit for close-loop search */
- int16_t *T0_min_frac, /* i/o: lower limit for close-loop search */
- int16_t *T0_max, /* i/o: higher limit for close-loop search */
- int16_t *T0_max_frac, /* i/o: higher limit for close-loop search */
- const int16_t pit_min,
- const int16_t pit_fr1,
- const int16_t pit_fr1b,
- const int16_t pit_fr2,
- const int16_t pit_max,
- const int16_t pit_res_max );
-
-void Mode2_abs_pit_dec_flt(
- int16_t *T0, /* o : integer pitch lag */
- int16_t *T0_frac, /* o : pitch fraction */
- int16_t *T0_res, /* o : pitch resolution */
- int16_t **pt_indice, /* i/o: pointer to Vector of Q indexes */
- const int16_t pit_min,
- const int16_t pit_fr1,
- const int16_t pit_fr2,
- const int16_t pit_res_max );
-
-void Mode2_delta_pit_dec_flt(
- int16_t *T0, /* o : integer pitch lag */
- int16_t *T0_frac, /* o : pitch fraction */
- int16_t T0_res, /* i : pitch resolution */
- int16_t *T0_min, /* i : delta search min */
- int16_t *T0_min_frac, /* i : delta search min */
- int16_t **pt_indice /* i/o: pointer to Vector of Q indexes */
-);
-
-void formant_post_filt_ivas(
- PFSTAT_HANDLE hPFstat, /* i/o: Post filter related memories */
- float *synth_in, /* i : 12k8 synthesis */
- const float *Aq, /* i : LP filter coefficient */
- float *synth_out, /* i/o: input signal */
- const int16_t L_frame, /* i : frame length */
- const int16_t L_subfr, /* i : sub-frame length */
- const float lp_noise, /* i : background noise energy */
- const int32_t brate, /* i : bitrate */
- const int16_t off_flag /* i : Off flag */
-);
-
-
-int16_t dlpc_avq(
- int16_t *index, /* i : Quantization indices */
- float *LSF_Q, /* o : Quantized LSF vectors */
- const int16_t numlpc, /* i : Number of sets of lpc */
- const int32_t sr_core /* i : internal sampling rate */
-);
-
-int16_t decode_lpc_avq(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t numlpc, /* i : Number of sets of lpc */
- int16_t *param_lpc, /* o : lpc parameters */
- const int16_t ch, /* i : channel */
- const int16_t element_mode, /* i : element mode */
- const int16_t sns_low_br_mode /* i : SNS low-bitrate mode */
-);
-
-
-void vlpc_2st_dec_flt(
- float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */
- int16_t *indx, /* i : index[] (4 bits per words) */
- const int16_t mode, /* i : 0=abs, >0=rel */
- const int32_t sr_core /* i : internal sampling rate */
-);
-
-void lsf_weight_2st_flt(
- const float *lsfq,
- float *w,
- const int16_t mode,
- const int32_t sr_core );
-
-void mdct_window_sine_flt(
- float *window,
- const int32_t Fs,
- const int16_t n,
- const int16_t window_type,
- const int16_t element_mode );
-
-void mdct_window_aldo_flt(
- float *window1,
- float *window2,
- const int16_t n );
-
-void AVQ_cod_lpc(
- const float nvec[], /* i : vector to quantize */
- int16_t nvecq[], /* o : quantized normalized vector (assuming the bit budget is enough) */
- int16_t *indx, /* o : index[] (4 bits per words) */
- const int16_t Nsv /* i : number of subvectors (lg=Nsv*8) */
-);
-
-void AVQ_dec_lpc_ivas(
- const int16_t indx[], /* i : index[] (4 bits per words) */
- int16_t nvecq[], /* o : vector quantized */
- const int16_t Nsv /* i : number of subvectors (lg=Nsv*8) */
-);
-
-void vlpc_1st_dec_flt(
- const int16_t index, /* i : codebook index */
- float *lsfq, /* i/o: i:prediction o:quantized lsf */
- const int32_t sr_core );
-
-void WindowSignal_flt(
- TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */
- int16_t offset, /* i : left folding point offset relative to the input signal pointer */
- const int16_t left_overlap_mode, /* i : overlap mode of left window half */
- const int16_t right_overlap_mode, /* i : overlap mode of right window half */
- int16_t *left_overlap_length, /* o : TCX window left overlap length */
- int16_t *right_overlap_length, /* o : TCX window right overlap length */
- const float in[], /* i : input signal */
- int16_t *L_frame, /* i/o: frame length */
- float out[], /* o : output windowed signal */
- const int16_t truncate_aldo, /* i : nonzero to truncate long ALDO slope */
- const int16_t fullband /* i : fullband flag */
-);
-
-void HBAutocorrelation(
- TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */
- const int16_t left_mode, /* i : overlap mode of left window half */
- const int16_t right_mode, /* i : overlap mode of right window half */
- float speech[], /* i : speech */
- int16_t L_frame_glob, /* i/o: frame length */
- float *r /* o : autocorrelations vector */
-);
-
-void TNSAnalysis(
- TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */
- const int16_t L_frame, /* i : frame length */
- int16_t L_spec, /* i : length of the spectrum */
- const int16_t transform_type, /* i : transform type for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */
- const int16_t isAfterACELP, /* i : Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */
- float spectrum[], /* i : MDCT spectrum of the subframe */
- TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */
- const float ltp_gain, /* i : ltp gain */
- STnsData *pTnsData, /* o : TNS data */
- int8_t *pfUseTns, /* o : Flag indicating if TNS is used */
- float *predictionGain /* o : TNS prediction gain */
-);
-
-void CalculateTnsFilt(
- STnsConfig const *pTnsConfig, /* i : TNS Configuration struct */
- const float pSpectrum[], /* i : MDCT spectrum */
- STnsData *pTnsData, /* o : TNS data struct */
- float *predictionGain /* o : TNS prediction gain */
-);
-
-void ShapeSpectrum(
- TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */
- const float A[], /* i : quantized coefficients NxAz_q[M+1] */
- float gainlpc[], /* o : MDCT gains for the previous frame */
- const int16_t L_frame_glob, /* i : frame length */
- int16_t L_spec, /* i : length of the spectrum */
- float spectrum[], /* i/o: MDCT spectrum */
- const int8_t fUseTns, /* i : Flag indicating if TNS is used */
- Encoder_State *st, /* i/o: encoder state structure */
- float *scf /* i : scale factors */
-);
-
-void QuantizeSpectrum(
- Encoder_State *st, /* i/o: encoder state structure */
- const float A[], /* i : quantized coefficients NxAz_q[M+1] */
- const Word16 Aqind[], /* i : frame-independent quantized coeffs (M+1) */
- float gainlpc[], /* i : MDCT gains of the previous frame */
- float synth[], /* o : synthesis buffer */
- const int16_t nb_bits, /* i : bit budget */
- const int16_t tnsSize, /* i : number of tns parameters put into prm */
- int16_t prm[], /* o : tcx parameters */
- const int16_t frame_cnt, /* i : frame counter in the super_frame */
- CONTEXT_HM_CONFIG *hm_cfg, /* i : HM configuration */
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-/*! r: index of next coefficient */
-int16_t get_next_coeff_mapped_ivas(
- int16_t ii[2], /* i/o: coefficient indexes */
- int32_t *pp, /* o : peak(1)/hole(0) indicator */
- int16_t *idx, /* o : index in unmapped domain */
- CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */
-);
-
-
-void ACcontextMapping_encode2_no_mem_s17_LC(
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- int16_t *x,
- int16_t nt,
- int16_t lastnz,
- int16_t nbbits,
- int16_t resQMaxBits,
- CONTEXT_HM_CONFIG *hm_cfg );
-
-int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas(
- Decoder_State *st, /* i/o: decoder state */
- int16_t *x, /* o : decoded spectrum */
- int16_t nt, /* i : size of spectrum */
- int16_t nbbits, /* i : bit budget */
- int16_t resQMaxBits, /* i : residual coding maximum bits */
- CONTEXT_HM_CONFIG *hm_cfg /* i : context-based harmonic model configuration */
-);
-
-int16_t ACcontextMapping_encode2_estimate_no_mem_s17_LC(
- const int16_t *x,
- const int16_t nt,
- int16_t *lastnz,
- int16_t *nEncoded,
- const int16_t target,
- int16_t *stop,
- CONTEXT_HM_CONFIG *hm_cfg );
-
-void RCcontextMapping_encode2_no_mem_s17_LCS(
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- int16_t *x,
- const int16_t nt,
- int16_t lastnz,
- const int16_t nbbits,
- const int16_t resQMaxBits,
- CONTEXT_HM_CONFIG *hm_cfg );
-
-int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
- Decoder_State *st, /* i/o: decoder state */
- int16_t *x, /* o : decoded spectrum */
- const int16_t nt, /* i : size of spectrum */
- const int16_t nbbits, /* i : bit budget */
- const int16_t resQMaxBits, /* i : residual coding maximum bits */
- CONTEXT_HM_CONFIG *hm_cfg /* i : context-based harmonic model configuration */
-);
-
-int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS(
- int16_t *x, /* Spectral coefficients */
- const int16_t nt, /* L - size of spectrum (no. of spectral coefficients) */
- int16_t *lastnz_out,
- int16_t *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring */
- const int16_t target, /* Target bits */
- int16_t *stop,
- int16_t mode,
- CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */
-);
-
-Word16 RCcontextMapping_encode2_estimate_bandWise_start_fx(
- Word16 *x, /* Q0 */
- const Word16 nt, /* Q0 */
- const Word16 target, /* Q0 */
- HANDLE_RC_CONTEXT_MEM hContextMem );
-
-Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
- Word16 *x, /* Q0 */
- const Word16 start_line, /* Q0 */
- const Word16 end_line, /* Q0 */
- HANDLE_RC_CONTEXT_MEM hContextMem /* Q0 */
-);
-
-void tcx_get_windows_flt(
- TCX_CONFIG_HANDLE hTcxCfg, /* i : TCX configuration */
- const int16_t left_mode, /* i : overlap mode of left window half */
- const int16_t right_mode, /* i : overlap mode of right window half */
- int16_t *left_overlap, /* o : left overlap length */
- const float **left_win, /* o : left overlap window */
- int16_t *right_overlap, /* o : right overlap length */
- const float **right_win, /* o : right overlap window */
- const int16_t fullband /* i : fullband flag */
-);
-
-void tcx_windowing_analysis_flt(
- const float *signal, /* i : signal vector */
- const int16_t L_frame, /* i : frame length */
- const int16_t left_overlap, /* i : left overlap length */
- const float *left_win, /* i : left overlap window */
- const int16_t right_overlap, /* i : right overlap length */
- const float *right_win, /* i : right overlap window */
- float *output /* o : windowed signal vector */
-);
-
-void tcx_windowing_synthesis_current_frame_flt(
- float *signal, /* i/o: signal vector */
- const float *window, /* i : TCX window vector */
- const float *window_half, /* i : TCX window vector for half-overlap window */
- const float *window_min, /* i : TCX minimum overlap window */
- const int16_t window_length, /* i : TCX window length */
- const int16_t window_half_length, /* i : TCX half window length */
- const int16_t window_min_length, /* i : TCX minimum overlap length */
- const int16_t left_rect, /* i : left part is rectangular */
- const int16_t left_mode, /* i : overlap mode of left window half */
- float *acelp_zir, /* i/o: acelp ZIR */
- const float *old_syn, /* i : old synthesis */
- const float *syn_overl, /* i : overlap synthesis */
- const float *A_zir,
- const float *window_trans, /* i : window for transition from ACELP */
- int16_t acelp_zir_len,
- const int16_t acelp_mem_len,
- const int16_t last_core_bfi, /* i : last mode */
- const int16_t last_is_cng,
- const int16_t fullbandScale );
-
-void tcx_windowing_synthesis_past_frame_flt(
- float *signal, /* i/o: signal vector */
- const float *window, /* i : TCX window vector */
- const float *window_half, /* i : TCX window vector for half-overlap window */
- const float *window_min, /* i : TCX minimum overlap window */
- const int16_t window_length, /* i : TCX window length */
- const int16_t window_half_length, /* i : TCX half window length */
- const int16_t window_min_length, /* i : TCX minimum overlap length */
- const int16_t right_mode /* i : overlap mode (left_mode of current frame) */
-);
-
-void ProcessIGF(
- Encoder_State *st, /* i : Encoder state */
- float *pMDCTSpectrum, /* i : MDCT spectrum */
- const float *pITFMDCTSpectrum, /* i : MDCT spectrum fir ITF */
- float *pPowerSpectrum, /* i : MDCT^2 + MDST^2 spectrum, or estimate */
- const int16_t isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */
- const int16_t frameno, /* i : flag indicating index of current subframe */
- const int16_t sp_aud_decision0, /* i : first stage switching decision */
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-void ProcessStereoIGF(
- STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct,
- Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */
- int16_t ms_mask[2][MAX_SFB], /* i : bandwise MS mask */
- float *pITFMDCTSpectrum[CPE_CHANNELS][NB_DIV], /* i : MDCT spectrum fir ITF */
- float *pPowerSpectrum[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */
- float *pPowerSpectrumMsInv[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */
- float *inv_spectrum[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */
- const int16_t frameno, /* i : flag indicating index of current subframe*/
- const int16_t sp_aud_decision0, /* i : sp_aud_decision0 */
- const int32_t element_brate, /* i : element bitrate */
- const int16_t mct_on /* i : flag mct block (1) or stereo (0) */
-);
-
-void AnalyzePowerSpectrum(
- Encoder_State *st, /* i/o: encoder states */
- const int16_t L_frame, /* i : frame length */
- const int16_t L_frameTCX, /* i : full band frame length */
- const int16_t left_overlap, /* i : left overlap length */
- const int16_t right_overlap, /* i : right overlap length */
- const float mdctSpectrum[], /* i : MDCT spectrum */
- const float signal[], /* i : windowed signal corresponding to mdctSpectrum */
- float powerSpec[] /* o : Power spectrum */
-);
-
-void lpc2mdct_flt(
- float *lpcCoeffs,
- const int16_t lpcOrder,
- float mdct_gains[],
- const int16_t length,
- const int16_t noInverse );
-
-void mdct_preShaping(
- float x[],
- const int16_t lg,
- const float gains[] );
-
-void mdct_noiseShaping_flt(
- float x[],
- const int16_t lg,
- const float gains[],
- const int16_t nBands );
-
-
-void PsychAdaptLowFreqDeemph_flt(
- float x[],
- const float lpcGains[],
- float lf_deemph_factors[] );
-
-void AdaptLowFreqDeemph_flt(
- float x[],
- int16_t tcx_lpc_shaped_ari,
- const float lpcGains[],
- const int16_t lg,
- float lf_deemph_factors[] );
-
-
-void tcx_noise_filling_flt(
- float *Q,
- const int16_t noiseFillSeed,
- const int16_t iFirstLine,
- const int16_t lowpassLine,
- const int16_t nTransWidth,
- const int16_t L_frame,
- const float tiltCompFactor,
- float fac_ns,
- Word16 *infoTCXNoise,
- const int16_t element_mode /* i : IVAS element mode */
-);
-
-
-void tcx_decoder_memory_update_flt(
- Decoder_State *st, /* i/o: decoder memory state */
- const float *xn_buf, /* i : mdct output buffer */
- float *synth, /* i/o: synth */
- const float *A /* i : Quantized LPC coefficients */
-);
-
-
-/*! r: number of bits used (including "bits") */
-int16_t tcx_ari_res_invQ_spec_flt(
- float x_Q[], /* i/o: quantized spectrum */
- const int16_t L_frame, /* i : number of lines */
- const int16_t prm[], /* i : bitstream */
- int16_t target_bits, /* i : number of bits available */
- int16_t bits, /* i : number of bits used so far */
- const float deadzone, /* i : quantizer deadzone */
- const float x_fac[] /* i : spectrum post-quantization factors */
-);
-
-
-void ari_copy_states(
- Tastat *source,
- Tastat *dest );
-
-
-void ari_start_encoding_14bits(
- Tastat *s );
-
-
-void ari_start_decoding_14bits_ivas(
- Decoder_State *st,
- Tastat *s );
-
-int16_t ari_start_decoding_14bits_prm_ivas(
- const int16_t *ptr,
- int16_t bp,
- Tastat *s );
-
-void ari_decode_14bits_s17_ext_ivas(
- Decoder_State *st,
- uint16_t *res,
- Tastat *s,
- const uint16_t *cum_freq );
-
-void ari_decode_14bits_s27_ext_ivas(
- Decoder_State *st,
- uint16_t *res,
- Tastat *s,
- const uint16_t *cum_freq );
-
-void ari_decode_14bits_bit_ext_ivas(
- Decoder_State *st,
- uint16_t *res,
- Tastat *s );
-
-/*! r: Q15 */
-Word16 expfp_evs_fx(
- const Word16 x, /* i : mantissa Q15-e */
- const Word16 x_e /* i : exponent Q0 */
-);
-
-
-void tcx_arith_render_envelope_ivas_fx(
- const Word16 A_ind[], /* i : LPC coefficients of signal envelope Q12*/
- const Word16 L_frame, /* i : number of spectral lines Q0*/
- const Word16 L_spec, /* i : length of the coded spectrum Q0*/
- const Word16 preemph_fac, /* i : pre-emphasis factor Q15*/
- const Word16 gamma_w, /* i : A_ind -> weighted envelope factor Q15*/
- const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor Q14*/
- Word32 env[] /* o : shaped signal envelope Q16*/
-);
-
-int16_t ari_encode_14bits_range(
- int16_t *ptr,
- int16_t bp,
- int32_t bits,
- Tastat *s,
- uint16_t cum_freq_low,
- uint16_t cum_freq_high );
-
-
-int16_t ari_done_cbr_encoding_14bits(
- int16_t *ptr,
- int16_t bp,
- int32_t bits,
- Tastat *s );
-
-
-void tcx_arith_encode_envelope(
- float spectrum[], /* i/o: MDCT coefficients */
- int16_t signs[], /* o : signs (spectrum[.]<0) */
- const int16_t L_frame, /* i : frame or MDCT length */
- const int16_t L_spec, /* i : length w/o BW limitation */
- Encoder_State *st, /* i/o: coder state */
- const Word16 A_ind[], /* i : quantised LPC coefficients */
- int16_t target_bits, /* i : number of available bits */
- int16_t prm[], /* o : bitstream parameters */
- const int16_t use_hm, /* i : use HM in current frame? */
- int16_t prm_hm[], /* o : HM parameter area */
- const int16_t tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/
- int16_t *arith_bits, /* o : bits used for ari. coding */
- int16_t *signaling_bits, /* o : bits used for signaling */
- const int16_t low_complexity /* i : low-complexity flag */
-);
-
-void tcx_arith_decode_envelope(
- Decoder_State *st, /* i/o: coder state */
- float q_spectrum[], /* o : quantised MDCT coefficients */
- const int16_t L_frame, /* i : frame or MDCT length */
- int16_t L_spec, /* i : length w/o BW limitation */
- const Word16 A_ind[], /* i : quantised LPC coefficients */
- const int16_t target_bits, /* i : number of available bits */
- const int16_t prm[], /* i : bitstream parameters */
- const int16_t use_hm, /* i : use HM in current frame? */
- const int16_t prm_hm[], /* i : HM parameter area */
- int16_t tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/
- int16_t *arith_bits, /* o : bits used for ari. coding */
- int16_t *signaling_bits, /* o : bits used for signaling */
- const int16_t low_complexity /* i : low-complexity flag */
-);
-
-void tcx_arith_decode_envelope_ivas_fx(
- Decoder_State *st, /* i/o: coder state */
- Word32 q_spectrum[], /* o : quantised MDCT coefficients */
- Word16 *q_spectrum_e, /* o : MDCT exponent */
- const Word16 L_frame, /* i : frame or MDCT length */
- Word16 L_spec, /* i : length w/o BW limitation */
- const Word16 A_ind[], /* i : quantised LPC coefficients */
- const Word16 target_bits, /* i : number of available bits */
- Word16 prm[], /* i : bitstream parameters */
- const Word16 use_hm, /* i : use HM in current frame? */
- const Word16 prm_hm[], /* i : HM parameter area */
- Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/
- Word16 *arith_bits, /* o : bits used for ari. coding */
- Word16 *signaling_bits, /* o : bits used for signaling */
- const Word16 low_complexity /* i : low-complexity flag */
-);
-
-
-void UnmapIndex_fx(
- const Word16 PeriodicityIndex, /* Q0 */
- const Word16 Bandwidth, /* Q0 */
- const Word16 LtpPitchLag, /* Q0 */
- const Word8 SmallerLags, /* Q0 */
- Word16 *FractionalResolution, /* Q0 */
- Word32 *Lag /* Q0 */
-);
-
-/*! r: PeriodicityIndex */
-int16_t SearchPeriodicityIndex(
- const float Mdct[], /* i : Coefficients, Mdct[0..NumCoeffs-1] */
- const float UnfilteredMdct[], /* i : Unfiltered coefficients, UnfilteredMdct[0..NumCoeffs-1] */
- const int16_t NumCoeffs, /* i : Number of coefficients */
- const int16_t shortTargetBits, /* i : Target bit budget (excl. Done flag) */
- const int16_t LtpPitchLag, /* i : TCX-LTP pitch */
- const float LtpGain, /* i : LTP gain */
- float *RelativeScore /* o : Energy concentration factor */
-);
-
-
-int16_t EncodeIndex(
- const int16_t Bandwidth, /* o : NB, 1: (S)WB */
- int16_t PeriodicityIndex,
- BSTR_ENC_HANDLE hBstr );
-
-
-Word16 CountIndexBits_fx(
- Word16 Bandwidth, /* 0: NB, 1: (S)WB Q0*/
- Word16 PeriodicityIndex /* Q0 */
-);
-
-int16_t DecodeIndex(
- Decoder_State *st,
- const int16_t Bandwidth, /* o : NB, 1: (S)WB */
- int16_t *PeriodicityIndex );
-
-#define GET_ADJ( T, L ) GET_ADJ2( T, L, *FractionalResolution )
-#define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) )
-
-
-Word32 tcx_hm_render_fx(
- const Word32 lag, /* i: pitch lag Q0 */
- const Word16 fract_res, /* i: fractional resolution of the lag Q0 */
- Word16 p[] /* o: harmonic model Q13 */
-);
-
-
-void tcx_hm_modify_envelope_fx(
- const Word16 gain, /* i: HM gain Q11 */
- const Word32 lag, /* i: pitch lag Q0 */
- const Word16 fract_res, /* i: fractional resolution of the lag Q0 */
- const Word16 p[], /* i: harmonic model Q13 */
- Word32 env[], /* i/o: envelope Q16 */
- const Word16 L_frame /* i: number of spectral lines Q0 */
-);
-
-void tcx_hm_analyse(
- const float abs_spectrum[], /* i : absolute spectrum */
- const int16_t L_frame, /* i : number of spectral lines */
- Word32 env[], /* i/o: envelope shape (Q16) */
- const int16_t targetBits, /* i : target bit budget */
- const int16_t coder_type, /* i : GC/VC coder type */
- int16_t prm_hm[], /* o : HM parameters */
- int16_t LtpPitchLag, /* i : LTP pitch lag or -1 if none */
- const float LtpGain, /* i : LTP gain */
- int16_t *hm_bits /* o : bit consumption */
-);
-
-void tcx_hm_decode_ivas(
- const int16_t L_frame, /* i : number of spectral lines */
- Word32 env[], /* i/o: envelope shape (Q16) */
- const int16_t targetBits, /* i : target bit budget */
- const int16_t coder_type, /* i : GC/VC coder type */
- const int16_t prm_hm[], /* i : HM parameters */
- const int16_t LtpPitchLag, /* i : LTP pitch lag or -1 if none */
- int16_t *hm_bits /* o : bit consumption */
-);
-
-void tcx_hm_decode(
- const Word16 L_frame, /* i : number of spectral lines */
- Word32 env[], /* i/o: envelope shape (Q16) */
- const Word16 targetBits, /* i : target bit budget */
- const Word16 coder_type, /* i : GC/VC coder type */
- const Word16 prm_hm[], /* i : HM parameters */
- const Word16 LtpPitchLag, /* i : LTP pitch lag or -1 if none */
- Word16 *hm_bits /* o : bit consumption */
-);
-
-void coder_tcx(
- Encoder_State *st, /* i/o: encoder state structure */
- TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */
- const float A[], /* i : quantized coefficients NxAz_q[M+1] */
- const Word16 Aqind[], /* i : frame-independent quantized coefficients (M+1) */
- float synth[], /* o : decoded synthesis */
- const int16_t L_frame_glob, /* i : frame length */
- const int16_t L_frameTCX_glob,
- const int16_t L_spec,
- int16_t nb_bits, /* i : bit budget */
- float spectrum[], /* i/o: MDCT spectrum */
- int16_t prm[], /* o : tcx parameters */
- CONTEXT_HM_CONFIG *hm_cfg,
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-void coder_tcx_post(
- Encoder_State *st, /* i/o: encoder memory state */
- float *A, /* o : Quantized LPC coefficients */
- const float *Ai /* i : Unquantized (interpolated) LPC coefficients */
-);
-
-void decoder_tcx(
- Decoder_State *st, /* i/o: coder memory state */
- int16_t prm[], /* i : parameters */
- float A[], /* i : coefficients NxAz[M+1] */
- Word16 Aind[], /* i : frame-independent coefficients Az[M+1]*/
- float synth[], /* i/o: synth[-M..lg] */
- float synthFB[], /* i/o: encoder memory state */
- const int16_t bfi, /* i : Bad frame indicator */
- const int16_t frame_cnt, /* i : frame counter in the super_frame */
- const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */
-);
-
-void decoder_tcx_post(
- Decoder_State *st, /* i/o: decoder memory state */
- float *synth,
- float *synthFB,
- float *A, /* i : A(z) filter coefficients */
- const int16_t bfi,
- const int16_t isMCT );
-
-void coder_acelp(
- Encoder_State *st, /* i/o: coder memory state */
- const float A[], /* i : coefficients 4xAz[M+1] */
- const float Aq[], /* i : coefficients 4xAz_q[M+1] */
- const float speech[], /* i : speech[-M..lg] */
- LPD_state *LPDmem, /* i/o: ACELP memories */
- int16_t *prm, /* o : acelp parameters */
- const float stab_fac,
- const int16_t target_bits,
- float *gain_pitch_buf, /* o : gain pitch values */
- float *gain_code_buf, /* o : gain code values */
- float *pitch_buf, /* o : pitch values for each subfr.*/
- float *voice_factors, /* o : voicing factors */
- float *bwe_exc /* o : excitation for SWB TBE */
-);
-
-void coder_acelp_rf(
- const int16_t target_bits, /* i : target bits */
- const float speech[], /* i : speech[-M..lg] */
- const int16_t coder_type, /* i : coding type */
- const int16_t rf_frame_type, /* i : rf_frame_type */
- const float A[], /* i : coefficients 4xAz[M+1] */
- const float Aq[], /* i : coefficients 4xAz_q[M+1] */
- const float voicing[], /* i : open-loop LTP gain */
- const int16_t T_op[], /* i : open-loop LTP lag */
- const float stab_fac, /* i : LP stability factor */
- Encoder_State *st, /* i/o: coder memory state */
- ACELP_config *acelp_cfg, /* i/o: configuration of the ACELP */
- float *exc_rf, /* i/o: pointer to RF excitation */
- float *syn_rf /* i/o: pointer to RF synthesis */
-);
-
-void decoder_acelp(
- Decoder_State *st, /* i/o: coder memory state */
- int16_t prm[], /* i : parameters */
- const float A[], /* i : coefficients NxAz[M+1] */
- ACELP_config acelp_cfg, /* i : ACELP config */
- float synth[], /* i/o: synthesis */
- int16_t *pT, /* o : pitch for all subframe */
- float *pgainT, /* o : pitch gain for all subfr */
- const float stab_fac, /* i : stability of isf */
- float *pitch_buffer, /* o : pitch values for each subfr.*/
- float *voice_factors, /* o : voicing factors */
- const int16_t LSF_Q_prediction, /* i : LSF prediction mode */
- float *bwe_exc /* o : excitation for SWB TBE */
-);
-
-void writeTCXMode_fx(
- Encoder_State *st, /* i/o: encoder state structure */
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/
- Word16 *nbits_start /* o : nbits start Q0*/
-);
-
-void writeTCXWindowing_fx(
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- const Word16 overlap_mode /* i : overlap mode Q0*/
-);
-
-void writeLPCparam(
- Encoder_State *st, /* i/o: encoder state structure */
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- const int16_t param_lpc[], /* i : LPC parameters to write */
- const int16_t bits_param_lpc[], /* i : bits per LPC parameter */
- const int16_t no_param_lpc, /* i : number of LPC parameters */
- int16_t *nbits_lpc /* o : LPC bits written */
-);
-
-void enc_prm(
- Encoder_State *st, /* i/o: encoder state structure */
- int16_t param[], /* i : parameters */
- int16_t param_lpc[], /* i : LPC parameters */
- CONTEXT_HM_CONFIG hm_cfg[],
- const int16_t bits_param_lpc[],
- const int16_t no_param_lpc );
-
-void writeTCXparam(
- Encoder_State *st, /* i/o: Encoder State handle */
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- CONTEXT_HM_CONFIG hm_cfg[], /* i/o: HM config */
- int16_t param[], /* i : parameters */
- const int16_t nbits_header,
- const int16_t nbits_start,
- const int16_t nbits_lpc,
- const int16_t *no_param_tns, /* i : number of TNS parameters per subframe */
- int16_t p_param[2], /* i/o: pointer to parameters from previous bs writing */
- const int16_t target_bitsTCX10[2],
- const int16_t pre_past_flag );
-
-void enc_prm_rf(
- Encoder_State *st, /* i/o: encoder memory state */
- const int16_t rf_frame_type,
- const int16_t fec_offset );
-
-void dec_prm_hm_ivas(
- Decoder_State *st, /* i/o: decoder memory state */
- int16_t *prm_hm,
- const int16_t hm_size );
-
-void dec_prm_ivas(
- Decoder_State *st, /* i/o: decoder memory state */
- int16_t param[], /* o : decoded parameters */
- int16_t param_lpc[], /* i : LPC parameters */
- int16_t *total_nbbits, /* i/o: number of bits / decoded bits */
- int16_t *bitsRead );
-void gaus_L2_dec_flt(
- float *code, /* o : decoded gaussian codevector */
- float tilt_code,
- const float *A,
- float formant_enh_num,
- int16_t *seed_acelp /* i/o: random seed */
-);
-
-/*! r: interpolated value */
-float interpolation(
- const float *x, /* i : input vector */
- const float *win, /* i : interpolation window */
- const int16_t frac, /* i : fraction */
- const int16_t up_samp, /* i : upsampling factor */
- const int16_t nb_coef /* i : nb of filter coef */
-);
-
-void predict_signal_flt(
- const float excI[], /* i : input excitation buffer */
- float excO[], /* o : output excitation buffer */
- const int16_t T0, /* i : integer pitch lag */
- int16_t frac, /* i : fraction of lag */
- const int16_t frac_max, /* i : max fraction */
- const int16_t L_subfr /* i : subframe size */
-);
-
-void tcx_ltp_encode(
- Encoder_State *st,
- const int16_t tcxMode,
- const int16_t L_frame,
- const float *speech,
- float *speech_ltp,
- const float *wsp,
- const int16_t Top[],
- int16_t *ltp_param,
- int16_t *ltp_bits,
- float *A,
- const int16_t disable_ltp,
- const int16_t element_mode );
-
-void tcx_ltp_post_flt(
- Decoder_State *st,
- TCX_LTP_DEC_HANDLE hTcxLtpDec,
- const int16_t core,
- const int16_t output_frame,
- const int16_t L_frame,
- float sig[],
- const float tcx_buf[] );
-
-int16_t tcx_ltp_decode_params_flt(
- int16_t *ltp_param,
- int16_t *pitch_int,
- int16_t *pitch_fr,
- float *gain,
- const int16_t pitmin,
- const int16_t pitfr1,
- const int16_t pitfr2,
- const int16_t pitmax,
- const int16_t pitres );
-
-void create_IDCT_N_Matrix(
- float *inv_matrixFloatQ, /* i/o: RAM buffer */
- const int16_t N, /* i : DCT length, number of time samples */
- const int16_t n_cols, /* i : number of dct coeffs (as DCT may be truncated) */
- const int16_t alloc_size /* i : RAM buffer size in elements */
-);
-
-void dctT2_N_apply_matrix(
- const float *input, /* i : input in fdcng or DCT(fdcng) domain */
- float *output, /* o : output in DCT(fdcng) or fdcng ordomain */
- const int16_t dct_dim, /* i : dct processing dim possibly truncated */
- const int16_t fdcngvq_dim, /* i : fdcng domain length */
- const float *matrix, /* i : IDCT matrix */
- const int16_t matrix_row_dim, /* i : */
- const DCTTYPE dcttype /* i : matrix operation type */
-);
-
-void extend_dctN_input(
- const float *input, /* i : input in fdcng domain */
- const float *dct_input, /* i : input in dctN(fdcng) domain */
- const int16_t in_dim, /* i : in_dim == N */
- float *ext_sig, /* o : extended output in fdcng domain */
- const int16_t out_dim, /* i : output total dim */
- float *matrix, /* i : idct synthesis matrix N rows, n_cols columns */
- const int16_t n_cols, /* i : number of columns == DCT truncation length */
- const DCTTYPE dcttype /* i : matrix operation type */
-);
-
-
-void PulseResynchronization(
- const float *src_exc, /* i : Input excitation buffer */
- float *dst_exc, /* o : output excitation buffer */
- const int16_t nFrameLength, /* i : frame length */
- const int16_t nSubframes, /* i : Number of subframes */
- const float pitchStart, /* i : Pitch at the end of the last frame */
- const float pitchEnd /* i : Pitch at the end of the current frame */
-);
-
-void con_acelp(
- float A[], /* i : coefficients NxAz[M+1] */
- const int16_t coder_type, /* i : ACELP coder type */
- float synth[], /* i/o: synthesis */
- int16_t *pT, /* o : pitch for all subframe */
- float *pgainT, /* o : pitch gain for all subfr */
- float stab_fac, /* i : stability of isf */
- Decoder_State *st, /* i/o: coder memory state */
- float pitch_buffer[], /* i/o: floating pitch values for each subframe */
- float *voice_factors, /* o : voicing factors */
- float *bwe_exc /* o : excitation for SWB TBE */
-);
-
-void con_tcx(
- Decoder_State *st, /* i/o: coder memory state */
- float synth[], /* i/o: synth[] */
- const float coh, /* i : coherence of stereo signal */
- int16_t *noise_seed, /* i/o: noise seed for stereo */
- const int16_t only_left, /* i : TD-PLC only in left channel */
- const float A_cng[] /* i : CNG LP filter coefficients */
-);
-
-int16_t lsf_msvq_ma_decprm_ivas(
- Decoder_State *st,
- int16_t *param_lpc );
-
-int16_t dec_lsf_tcxlpc_ivas(
- Decoder_State *st, /* i : Decoder state */
- int16_t **indices, /* o : Ptr to VQ indices */
- const int16_t narrowband, /* i : narrowband flag */
- const int16_t cdk /* i : codebook selector */
-);
-
-int16_t D_lsf_tcxlpc_ivas(
- const int16_t indices[], /* i : VQ indices */
- float lsf_q[], /* o : quantized lsf */
- Word16 lsp_q_ind[], /* o : quantized lsp (w/o MA prediction) */
- const int16_t narrowband, /* i : narrowband flag */
- const int16_t cdk, /* i : codebook selector */
- const float mem_MA[] /* i : MA memory */
-);
-
-int16_t Q_lsf_tcxlpc(
- /* const */ float lsf[], /* i : original lsf */
- float lsf_q[], /* o : quantized lsf */
- Word16 lsp_q_ind[], /* o : quantized lsp (w/o MA prediction) */
- int16_t indices[], /* o : VQ indices */
- const int16_t narrowband, /* i : narrowband flag */
- const int16_t cdk, /* i : codebook selector */
- const float mem_MA[], /* i : MA memory */
- const int16_t coder_type, /* i : acelp extended mode */
- const float *Bin_Ener /* i : Spectrum energy */
-);
-
-void midlsf_enc(
- const float qlsf0[],
- const float qlsf1[],
- const float lsf[],
- int16_t *idx,
- const int16_t N,
- const float *Bin_Ener,
- const int16_t narrowBand,
- const int32_t sr_core,
- const int16_t coder_type );
-
-void lsf_end_enc(
- Encoder_State *st,
- const float *lsf,
- float *qlsf,
- const int16_t nBits,
- const int16_t coder_type_org,
- const int16_t force_sf,
- int16_t *lpc_param,
- int16_t *no_stages,
- int16_t *bits_param_lpc,
- const int16_t coder_type_raw,
- const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */
-);
-
-void lsf_end_dec(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t coder_type_org, /* i : coding type */
- const int16_t bwidth, /* i : input signal bandwidth */
- const int16_t nBits, /* i : number of bits used for ISF quantization*/
- float *qlsf, /* o : quantized LSFs in the cosine domain */
- int16_t *lpc_param, /* i : LPC parameters */
- int16_t *LSF_Q_prediction, /* o : LSF prediction mode */
- int16_t *nb_indices, /* o : number of indices */
- const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */
-);
-
-void lpc_quantization(
- Encoder_State *st,
- const float lsp[],
- const float lspmid[],
- float lsp_q[],
- float lsf_q[],
- float lspmid_q[],
- const int16_t coder_type,
- const int16_t acelp_midLpc,
- int16_t param_lpc[],
- int16_t nbits_lpc[],
- int16_t *bits_param_lpc,
- int16_t *no_param_lpc );
-
-void lpc_unquantize(
- Decoder_State *st,
- float *lsf,
- float *lsp,
- int16_t *param_lpc,
- float *lspmid,
- float *lsfmid,
- const int16_t coder_type,
- int16_t *LSF_Q_prediction /* o : LSF prediction mode */
-);
-
-void dlpc_bfi_flt(
- const int16_t L_frame,
- float *lsf_q, /* o : quantized lsfs */
- const float *lsfold, /* i : past quantized lsf */
- const int16_t last_good, /* i : last good received frame */
- const int16_t nbLostCmpt, /* i : counter of consecutive bad frames */
- float mem_MA[], /* i/o: quantizer memory for MA model */
- float mem_AR[], /* i/o: quantizer memory for MA model */
- float *stab_fac, /* i : lsf stability factor */
- float *lsf_adaptive_mean, /* i : lsf adaptive mean, updated when BFI==0 */
- const int16_t numlpc, /* i : Number of division per superframe */
- float lsf_cng[],
- const int16_t plcBackgroundNoiseUpdated,
- float *lsf_q_cng, /* o : quantized lsfs of background noise */
- float *old_lsf_q_cng, /* o : old quantized lsfs for background noise */
- const float lsfBase[] /* i : base for differential lsf coding */
-);
-
-void Unified_weighting(
- const float Bin_Ener_128[], /* i : FFT Bin energy 128 bins in two sets */
- const float lsf[], /* i : LSF vector */
- float w[], /* o : LP weighting filter (numerator) */
- const int16_t narrowBand, /* i : flag for Narrowband */
- const int16_t unvoiced, /* i : flag for Unvoiced frame */
- const int32_t sr_core, /* i : sampling rate of core-coder */
- const int16_t order /* i : LP order */
-);
-
-int16_t vad_init(
- VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */
-);
-
-int16_t vad_proc(
- float realValues[16][60], /* i : CLDFB real values */
- float imagValues[16][60], /* i : CLDFB imag values */
- float *sb_power, /* i/o: Energy of CLDFB data */
- const int16_t numBands, /* i : number of input bands */
- VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- int16_t *cldfb_addition,
- const int16_t vada_flag /* i : VAD flag */
-);
-
-
-int16_t update_decision(
- VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- const float snr, /* i : frequency domain SNR */
- const float tsnr, /* i : time domain SNR */
- const float frame_energy, /* i : current frame energy */
- const float high_eng, /* i : current frame high frequency energy */
- const int16_t vad_flag, /* i : VAD flag */
- const int16_t music_backgound_f /* i : background music flag */
-);
-
-void frame_spec_dif_cor_rate(
- float spec_amp[], /* i : spectral amplitude */
- float pre_spec_low_dif[], /* i/o: low spectrum different */
- float f_tonality_rate[] /* o : tonality rate */
-);
-
-
-void SNR_calc(
- const float frame_sb_energy[], /* i : energy of sub-band divided non-uniformly*/
- const float sb_bg_energy[], /* i : sub-band background energy */
- const float t_bg_energy, /* i : time background energy of several frames*/
- float *snr, /* o : frequency domain SNR */
- float *tsnr, /* o : time domain SNR */
- const float frame_energy, /* i : current frame energy */
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-void background_update(
- VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- float frame_energy, /* i : current frame energy 2 */
- const int16_t update_flag, /* i : current frame update flag */
- const int16_t music_backgound_f, /* i : background music flag */
- const float snr );
-
-void bg_music_decision(
- VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- int16_t *music_backgound_f, /* i : background music flag */
- const float frame_energy /* i : current frame energy 1 */
-);
-
-void est_energy(
- float sb_power[], /* o : energy of sub-band divided uniformly */
- float frame_sb_energy[], /* o : energy of sub-band divided non-uniformly*/
- float *p_frame_energy, /* o : frame energy 1 */
- float *p_frame_energy2, /* o : frame energy 2 */
- float *p_high_energy, /* o : high frequency energy */
- const int16_t bw /* i : bandwidth */
-);
-
-
-int16_t comvad_decision(
- VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- const float snr, /* i : frequency domain SNR */
- const float tsnr, /* i : time domain SNR */
- const float snr_flux, /* i : average tsnr of several frames */
- const float lt_snr, /* i : long time SNR calculated by fg_energy and bg_energy*/
- const float lt_snr_org, /* i : original long time SNR */
- const float lf_snr, /* i : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/
- const float frame_energy, /* i : current frame energy */
- const int16_t music_backgound_f, /* i : background music flag */
- int16_t *cldfb_addition,
- const int16_t vada_flag /* i : VAD flag */
-);
-
-void calc_snr_flux(
- float tsnr, /* i : time-domain SNR */
- float pre_snr[], /* i/o: time-domain SNR storage */
- float *snr_flux /* o : average tsnr */
-);
-
-void calc_lt_snr(
- float *lt_snr_org, /* o : original long time SNR */
- float *lt_snr, /* o : long time SNR calculated by fg_energy and bg_energy*/
- const float fg_energy, /* i : foreground energy sum */
- const int16_t fg_energy_count, /* i : number of the foreground energy frame */
- const float bg_energy, /* i : background energy sum */
- const int16_t bg_energy_count, /* i : number of the background energy frame */
- const int16_t bw_index, /* i : band width index */
- const float lt_noise_sp_center0 /* i : long time noise spectral center by 0 */
-);
-
-void calc_lf_snr(
- float *lf_snr_smooth, /* o : smoothed lf_snr */
- float *lf_snr, /* o : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/
- const float l_speech_snr, /* i : sum of active frames snr */
- const int16_t l_speech_snr_count, /* i : number of the active frame */
- const float l_silence_snr, /* i : sum of the nonactive frames snr */
- const int16_t l_silence_snr_count, /* i : number of the nonactive frame */
- const int16_t fg_energy_count, /* i : number of the foreground energy frame */
- const int16_t bg_energy_count, /* i : number of the background energy frame */
- const int16_t bw_index /* i : band width index */
-);
-
-float construct_snr_thresh(
- const float sp_center[], /* i : spectral center */
- const float snr_flux, /* i : snr flux */
- const float lt_snr, /* i : long time time domain snr */
- const float lf_snr, /* i : long time frequency domain snr */
- const int16_t continuous_speech_num, /* i : continuous speech number */
- const int16_t continuous_noise_num, /* i : continuous noise number */
- const int16_t fg_energy_est_start, /* i : whether if estimated energy */
- const int16_t bw_index /* i : band width index */
-);
-
-void minimum_statistics_flt(
- const int16_t len, /* i : Vector length */
- const int16_t lenFFT, /* i : Length of the FFT part of the vectors */
- float *psize_flt,
- float *msPeriodog, /* i : Periodograms */
- float *msNoiseFloor,
- float *msNoiseEst, /* o : Noise estimates */
- float *msAlpha,
- float *msPsd,
- float *msPsdFirstMoment,
- float *msPsdSecondMoment,
- float *msMinBuf,
- float *msBminWin,
- float *msBminSubWin,
- float *msCurrentMin,
- float *msCurrentMinOut,
- float *msCurrentMinSubWindow,
- int16_t *msLocalMinFlag,
- int16_t *msNewMinFlag,
- float *msPeriodogBuf,
- int16_t *msPeriodogBufPtr,
- HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
- const int16_t enc_dec, /* i : encoder/decoder indicator */
- const int16_t element_mode /* i : IVAS element mode */
-);
-
-void generate_comfort_noise_enc(
- Encoder_State *st /* i/o: encoder state structure */
-);
-
-void generate_comfort_noise_dec(
- float **bufferReal, /* o : Real part of input bands */
- float **bufferImag, /* o : Imaginary part of input bands */
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t nchan_out /* i : number of output channels */
-);
-
-void generate_comfort_noise_dec_hf(
- float **bufferReal, /* o : Real part of input bands */
- float **bufferImag, /* o : Imaginary part of input bands */
- HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
- const int16_t cng_flag /* i : CNG Flag */
-);
-
-void generate_masking_noise(
- float *timeDomainBuffer, /* i/o: time-domain signal */
- HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
- const int16_t length, /* i : frame size */
- const int16_t core, /* i : core */
- const int16_t return_noise, /* i : noise is returned instead of added */
- const int16_t secondary, /* i : indicator for secondary channel */
- const int16_t element_mode, /* i : element mode */
- STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
- const int16_t nchan_out /* i : number of output channels */
-);
-
-void generate_masking_noise_update_seed(
- HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
-);
-
-void generate_masking_noise_mdct(
- float *mdctBuffer, /* i/o: time-domain signal */
- HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
-);
-
-void SynthesisSTFT_dirac_flt(
- float *fftBuffer, /* i : FFT bins */
- float *timeDomainOutput,
- float *olapBuffer,
- const float *olapWin,
- const int16_t samples_out,
- HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
-);
-
-void generate_masking_noise_dirac(
- HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
- HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */
- float *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */
- float *Cldfb_RealBuffer, /* o : CLDFD real buffer */
- float *Cldfb_ImagBuffer, /* o : CLDFD imaginary buffer */
- const int16_t slot_index, /* i : CLDFB slot index */
- const int16_t cna_flag, /* i : CNA flag for LB and HB */
- const int16_t fd_cng_flag /* i : FD-CNG flag for HB */
-);
-
-void generate_stereo_masking_noise(
- float *syn, /* i/o: time-domain signal */
- Decoder_State *st, /* i/o: decoder state structure */
- STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */
- const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
- const int16_t fadeOut, /* i : only fade out of previous state */
- STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
- const int16_t nchan_out /* i : number of output channels */
-);
-
-void apply_scale_flt(
- float *scale, /* i : scale factor */
- const int16_t bwidth, /* i : audio bandwidth */
- const int32_t brate, /* i : Bit rate */
- const SCALE_SETUP *scaleTable, /* i : Scale table */
- const int16_t scaleTableSize /* i : Size of scale table */
-);
-
-void compress_range_flt(
- float *in,
- float *out,
- const int16_t len );
-
-void expand_range_flt(
- float *in,
- float *out,
- const int16_t len );
-
-void bandcombinepow_flt(
- const float *bandpow, /* i : Power for each band */
- const int16_t nband, /* i : Number of bands */
- int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */
- const int16_t npart, /* i : Number of partitions */
- const float *psize_inv_flt, /* i : Inverse partition sizes */
- float *partpow /* o : Power for each partition */
-);
-
-void scalebands_flt(
- const float *partpow, /* i : Power for each partition */
- int16_t *part, /* i : Partition upper boundaries (band indices starting from 0) */
- const int16_t npart, /* i : Number of partitions */
- int16_t *midband, /* i : Central band of each partition */
- const int16_t nFFTpart, /* i : Number of FFT partitions */
- const int16_t nband, /* i : Number of bands */
- float *bandpow, /* o : Power for each band */
- const int16_t flag_fft_en );
-
-void AnalysisSTFT_flt(
- const float *timeDomainInput,
- float *fftBuffer, /* o : FFT bins */
- HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */
-);
-
-void SynthesisSTFT_flt(
- float *fftBuffer,
- float *timeDomainOutput,
- float *olapBuffer,
- const float *olapWin,
- const int16_t tcx_transition,
- HANDLE_FD_CNG_COM hFdCngCom,
- const int16_t element_mode, /* i : element mode */
- const int16_t nchan_out /* i : number of output channels */
-);
-
-void lpc_from_spectrum_flt(
- HANDLE_FD_CNG_COM hFdCngCom,
- const int16_t start,
- const int16_t stop,
- const float preemph_fac );
-
-ivas_error createFdCngDec(
- HANDLE_FD_CNG_DEC *hFdCngDec );
-
-void deleteFdCngDec(
- HANDLE_FD_CNG_DEC *hFdCngDec );
-
-void initFdCngDec(
- DEC_CORE_HANDLE st /* i/o: decoder state structure */
-);
-
-void configureFdCngDec(
- HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */
- const int16_t bwidth,
- const int32_t total_brate,
- const int16_t L_frame,
- const int16_t last_L_frame,
- const int16_t element_mode );
-
-void ApplyFdCng(
- float *timeDomainInput,
- float *powerSpectrum,
- float **realBuffer, /* i/o: Real part of the buffer */
- float **imagBuffer, /* i/o: Imaginary part of the buffer */
- Decoder_State *st,
- const int16_t concealWholeFrame, /* i : binary flag indicating frame loss */
- const int16_t is_music );
-
-void generate_comfort_noise_dec(
- float **bufferReal, /* o : Real part of input bands */
- float **bufferImag, /* o : Imaginary part of input bands */
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t nchan_out /* i : number of output channels */
-);
-
-/*! r: CNG energy */
-float cng_energy(
- const int16_t element_mode, /* i : element mode */
- const int16_t bwidth, /* i : audio bandwidh */
- const int16_t CNG_mode, /* i : mode for DTX configuration */
- const float CNG_att, /* i : attenuation factor for CNG */
- const float *inputBuffer, /* i : input signal */
- const int16_t len /* i : vector length */
-);
-
-void FdCng_decodeSID(
- Decoder_State *st /* i/o: decoder state structure */
-);
-
-void FdCng_exc_flt(
- HANDLE_FD_CNG_COM hFdCngCom,
- int16_t *CNG_mode,
- const int16_t L_frame,
- const float *lsp_old,
- const int16_t first_CNG,
- float *lsp_CNG,
- float *Aq, /* o : LPC coeffs */
- float *lsp_new, /* o : lsp */
- float *lsf_new, /* o : lsf */
- float *exc, /* o : LP excitation */
- float *exc2, /* o : LP excitation */
- float *bwe_exc /* o : LP excitation for BWE */
-);
-
-void noisy_speech_detection(
- HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */
- const int16_t vad, /* i : VAD flag */
- const float syn[] /* i : input time-domain frame */
-);
-
-void deleteFdCngEnc(
- HANDLE_FD_CNG_ENC *hFdCngEnc /* i/o: FD_CNG structure */
-);
-
-
-void resetFdCngEnc(
- Encoder_State *st /* i/o: encoder state structure */
-);
-
-void perform_noise_estimation_enc(
- float *band_energies, /* i : energy in critical bands without minimum noise floor E_MIN */
- float *enerBuffer, /* i : energy buffer */
- HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */
- const int32_t input_Fs, /* i : input sampling rate */
- CPE_ENC_HANDLE hCPE );
-
-void AdjustFirstSID(
- Encoder_State *st /* i/o: encoder state structure */
-);
-
-void FdCng_encodeSID(
- Encoder_State *st /* i/o: encoder state structure */
-);
-
-void GetParameters(
- ParamsBitMap const *paramsBitMap,
- const int16_t nParams,
- void const *pParameter,
- int16_t **pStream,
- int16_t *pnSize,
- int16_t *pnBits );
-
-void SetParameters(
- ParamsBitMap const *paramsBitMap,
- const int16_t nParams,
- void *pParameter,
- const int16_t **pStream,
- int16_t *pnSize );
-
-void WriteToBitstream(
- ParamsBitMap const *paramsBitMap,
- const int16_t nParams,
- const int16_t **pStream,
- int16_t *pnSize,
- BSTR_ENC_HANDLE hBstr,
- int16_t *pnBits );
-
-void ReadFromBitstream(
- ParamsBitMap const *paramsBitMap,
- const int16_t nArrayLength,
- Decoder_State *st,
- int16_t **pStream,
- int16_t *pnSize );
-
-void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue );
-void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value );
-void const *GetNumOfTnsFilters_flt( void const *p, const int16_t index, int16_t *pValue );
-void *SetNumOfTnsFilters_flt( void *p, const int16_t index, const int16_t value );
-
-int16_t DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
-int16_t DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
-
-int16_t DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
-
-int16_t DecodeTnsFilterOrderSWBTCX10_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
-int16_t DecodeTnsFilterOrderSWBTCX20_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
-
-int16_t EncodeTnsFilterOrderSWBTCX10_flt( const int16_t value, const int16_t index );
-
-int16_t GetTnsFilterOrderBitsSWBTCX10_flt( const int16_t value, const int16_t index );
-int16_t DecodeTnsFilterOrder_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
-
-void ResetTnsData_flt(
- STnsData *pTnsData );
-
-void ClearTnsFilterCoefficients_flt(
- STnsFilter *pTnsFilter );
-
-
-int16_t DetectTnsFilt(
- const STnsConfig *pTnsConfig, /* i : TNS Configuration struct */
- const float pSpectrum[], /* i : MDCT spectrum */
- TRAN_DET_HANDLE hTranDet, /* i : transient detection handle */
- const int16_t isTCX10, /* i : TCX10 or TCX20? */
- const float ltp_gain, /* i : LTP gain */
- STnsData *pTnsData, /* o : TNS data struct */
- float *predictionGain /* o : TNS prediction gain */
-);
-
-void EncodeTnsData(
- STnsConfig const *pTnsConfig, /* i : TNS Configuration struct */
- STnsData const *pTnsData, /* i : TNS data struct (quantized param) */
- int16_t *stream, /* o : internal data stream */
- int16_t *pnSize, /* o : number of written parameters */
- int16_t *pnBits /* o : number of written bits */
-);
-
-int16_t DecodeTnsData_ivas(
- STnsConfig const *pTnsConfig,
- const int16_t *stream,
- int16_t *pnSize,
- STnsData *pTnsData );
-
-void WriteTnsData(
- const STnsConfig *pTnsConfig, /* i : TNS Configuration struct */
- const int16_t *stream, /* i : internal data stream */
- int16_t *pnSize, /* o : number of written parameters */
- BSTR_ENC_HANDLE hBstr, /* o : bitstream */
- int16_t *pnBits /* o : number of written bits */
-);
-
-void ReadTnsData_ivas(
- STnsConfig const *pTnsConfig,
- Decoder_State *st,
- int16_t *pnBits,
- int16_t *stream,
- int16_t *pnSize );
-
-void cldfbAnalysis_ivas(
- const float *timeIn, /* i : time buffer */
- float **realBuffer, /* o : real value buffer */
- float **imagBuffer, /* o : imag value buffer */
- const int16_t samplesToProcess, /* i : number of input samples */
- HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filterbank state */
-);
-
-void cldfbAnalysis_ts_ivas(
- const float *timeIn, /* i : time buffer */
- float realBuffer[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */
- float imagBuffer[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */
- const int16_t samplesToProcess, /* i : samples to process */
- HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filterbank state */
-);
-
-void cldfbSynthesis_ivas(
- float **realBuffer, /* i : real values */
- float **imagBuffer, /* i : imag values */
- float *timeOut, /* o : synthesized output */
- const int16_t samplesToProcess, /* i : number of samples */
- HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filter bank state */
-);
-
-void configureCldfb_ivas(
- HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */
- const int32_t sampling_rate /* i : sampling rate */
-);
-
-
-void analysisCldfbEncoder_ivas(
- Encoder_State *st, /* i/o: encoder state structure */
- const float *timeIn,
- const int16_t samplesToProcess,
- float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
- float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
- float *ppBuf_Ener );
-
-void analysisCldfbEncoder_ivas_fx(
- Encoder_State *st, /* i/o: encoder state structure */
- Word32 *timeIn, /*q11*/
- Word16 timeInq, /*q0*/
- Word16 samplesToProcess, /*q0*/
- Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
- Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
- Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
- Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
- Word32 *ppBuf_Ener,
- Word16 *enerBuffSum_exp,
- CLDFB_SCALE_FACTOR *scale );
-
-ivas_error openCldfb_ivas(
- HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */
- CLDFB_TYPE type, /* i : analysis or synthesis */
- const int32_t sampling_rate, /* i : sampling rate */
- CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */
-);
-
-ivas_error openCldfb_ivas_enc(
- HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */
- CLDFB_TYPE type, /* i : analysis or synthesis */
- const Word32 sampling_rate, /* i : sampling rate */
- CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */
-);
-
-void resampleCldfb_ivas(
- HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */
- const int32_t newSamplerate /* i : new samplerate to operate */
-);
-
-ivas_error cldfb_save_memory_ivas(
- HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */
-);
-
-void cldfb_restore_memory_ivas(
- HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */
-);
-
-void cldfb_reset_memory_ivas(
- HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */
-);
-
-void deleteCldfb_ivas(
- HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */
-);
-
-void fft_cldfb(
- float *data, /* i/o: input/output vector */
- const int16_t size /* i : size of fft operation */
-);
-
-void BITS_ALLOC_init_config_acelp_IVAS(
- const int32_t bit_rate,
- const int16_t narrowBand,
- const int16_t nb_subfr,
- ACELP_config *acelp_cfg /* o : configuration structure of ACELP */
-);
-
-int16_t BITS_ALLOC_config_acelp_IVAS(
- const int16_t bits_frame, /* i : remaining bit budget for the frame */
- const int16_t coder_type, /* i : acelp coder type */
- ACELP_config *acelp_cfg, /* i/o: configuration structure of ACELP */
- const int16_t narrowband, /* i : narrowband flag */
- const int16_t nb_subfr /* i : number of subframes */
-);
-
-
-void FEC_clas_estim(
- const float *syn,
- const float *pitch, /* i : pitch values for each subframe */
- const int16_t L_frame, /* i : length of the frame */
- const int16_t coder_type, /* i : coder type */
- const int16_t codec_mode, /* i : codec mode */
- float *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */
- int16_t *clas, /* i/o: frame classification */
- float *lp_speech, /* i/o: long term active speech energy average */
- const int16_t Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- int16_t *decision_hyst, /* i/o: hysteresis of the music/speech decision */
- int16_t *locattack, /* i/o: detection of attack (mainly to localized speech burst) */
- int16_t *UV_cnt, /* i/o: number of consecutives frames classified as UV */
- float *LT_UV_cnt, /* i/o: long term consecutives frames classified as UV */
- float *Last_ener, /* i/o: last_energy frame */
- int16_t *amr_io_class, /* i/o: classification for AMR-WB IO mode */
- float *lt_diff_etot, /* i/o: long-term total energy variation */
- float *class_para, /* o : classification para. fmerit1 */
- const float LTP_Gain, /* i : */
- const int16_t narrowBand, /* i : */
- const SIGNAL_CLASSIFIER_MODE mode, /* i : */
- const int16_t bfi, /* i : */
- const float preemph_fac, /* i : */
- const int16_t tcxonly, /* i : */
- const int32_t last_core_brate, /* i : last core bitrate */
- const int16_t FEC_mode /* i : ACELP FEC mode */
-);
-
-
-void SetTCXModeInfo(
- Encoder_State *st, /* i/o: encoder state structure */
- TRAN_DET_HANDLE hTranDet, /* i/o: transient detection handle */
- int16_t *tcxModeOverlap /* o : window overlap of current frame */
-);
-
-void TCX_MDCT_flt(
- const float *x,
- float *y,
- const int16_t l,
- const int16_t m,
- const int16_t r,
- const int16_t element_mode );
-
-void TCX_MDST_flt(
- const float *x,
- float *y,
- const int16_t l,
- const int16_t m,
- const int16_t r,
- const int16_t element_mode );
-
-void TCX_MDCT_Inverse_flt(
- const float *x,
- float *y,
- const int16_t l,
- const int16_t m,
- const int16_t r,
- const int16_t element_mode );
-
-void TCX_MDST_Inverse_flt(
- const float *x,
- float *y,
- const int16_t l,
- const int16_t m,
- const int16_t r,
- const int16_t element_mode );
-
-void TCX_MDXT_Inverse_flt(
- const float *x,
- float *y,
- const int16_t l,
- const int16_t m,
- const int16_t r,
- const uint16_t kernel_type );
-
-void post_decoder_flt(
- Decoder_State *st,
- float synth_buf[],
- const float pit_gain[],
- const int16_t pitch[],
- float signal_out[],
- float bpf_noise_buf[] );
-void cldfb_synth_set_bandsToZero_flt(
- Decoder_State *st, /* i/o: decoder state structure */
- float **rAnalysis,
- float **iAnalysis,
- const int16_t nTimeSlots );
-
-void longadd(
- uint16_t a[], /* i/o: vector of the length lena */
- const uint16_t b[], /* i/o: vector of the length lenb */
- const int16_t lena, /* i/o: length of vector a[] */
- const int16_t lenb /* i/o: length of vector b[] */
-);
-
-void longshiftright(
- uint16_t a[], /* i : vector of the length lena */
- const int16_t b, /* i : number of bit positions to shift right */
- uint16_t d[], /* o : vector of the length lend */
- int16_t lena, /* i : length of vector a[] */
- const int16_t lend /* i : length of vector d[] */
-);
-
-void longshiftleft(
- const uint16_t a[], /* i : vector of the length len */
- const int16_t b, /* i : number of bit positions to shift left */
- uint16_t d[], /* o : vector of the length len */
- const int16_t len /* i : length of vector a[] and d[] */
-);
-
-void open_decoder_LPD(
- Decoder_State *st, /* i/o: decoder state structure */
- const int32_t total_brate, /* i : total bitrate */
- const int32_t last_total_brate, /* i : last total bitrate */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
- const int16_t last_element_mode, /* i : last element mode */
- const int16_t is_init /* i : indicate call during initialization */
-);
-
-void acelp_plc_mdct_transition(
- Decoder_State *st /* i/o: Decoder state */
-);
-
-void tcxltp_dec_init(
- TCX_LTP_DEC_HANDLE hTcxLtpDec,
- const int16_t ini_frame,
- const int16_t last_codec_mode,
- const int16_t element_mode,
- const int16_t pit_max,
- const int32_t sr_core );
-
-void reset_tcx_overl_buf(
- TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */
-);
-
-void update_decoder_LPD_cng_flt(
- Decoder_State *st, /* i/o: decoder state structure */
- float *timeDomainBuffer,
- float *A,
- float *bpf_noise_buf );
-
-void reconfig_decoder_LPD_ivas(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t bits_frame, /* i : bit budget */
- const int16_t bwidth, /* i : audio bandwidth */
- const int32_t total_brate, /* i : total bitrate */
- const int16_t L_frame_old /* i : frame length */
-);
-
-void mode_switch_decoder_LPD(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t bwidth, /* i : audio bandwidth */
- const int32_t total_brate, /* i : total bitrate */
- const int32_t last_total_brate, /* i : last frame total bitrate */
- const int16_t frame_size_index, /* i : index determining the frame size */
- const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/
- const int16_t last_element_mode /* i : last element mode */
-);
-
-void dec_acelp_tcx_frame(
- Decoder_State *st, /* i/o: decoder state structure */
- int16_t *concealWholeFrame, /* i/o: concealment flag */
- float *output, /* o : synthesis */
- float *bpf_noise_buf, /* i/o: BPF noise buffer */
- float *pcmbufFB, /* o : synthesis @output_FS */
- float bwe_exc_extended[], /* i/o: bandwidth extended excitation */
- float *voice_factors, /* o : voicing factors */
- float pitch_buf[], /* o : floating pitch for each subframe */
- STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */
-);
-
-void decoder_LPD(
- Decoder_State *st, /* i/o: decoder memory state pointer */
- float signal_out[], /* o : signal with LPD delay (7 subfrs) */
- float signal_outFB[], /* o : synthesis @output_FS */
- int16_t *total_nbbits, /* i/o: number of bits / decoded bits */
- float *bpf_noise_buf, /* i/o: BPF noise buffer */
- int16_t bfi, /* i : BFI flag */
- int16_t *bitsRead, /* o : number of read bits */
- int16_t param[], /* o : buffer of parameters */
- float *pitch_buf, /* i/o: floating pitch values for each subfr*/
- float *voice_factors, /* o : voicing factors */
- float *ptr_bwe_exc /* o : excitation for SWB TBE */
-);
-
-int16_t tcxGetNoiseFillingTilt_flt(
- const float A[],
- const int16_t L_frame,
- const int16_t mode,
- float *noiseTiltFactor );
-
-void tcxFormantEnhancement_flt(
- float xn_buf[],
- const float *gainlpc,
- float spectrum[],
- const int16_t L_frame );
-
-void tcxInvertWindowGrouping_flt(
- TCX_CONFIG_HANDLE hTcxCfg,
- float xn_buf[],
- float spectrum[],
- const int16_t L_frame,
- const int8_t fUseTns,
- const int16_t last_core,
- const int16_t index,
- const int16_t frame_cnt,
- const int16_t bfi );
-
-void tcx5SpectrumInterleaving(
- const int16_t tcx5Size,
- float *spectrum );
-
-void tcx5SpectrumDeinterleaving(
- const int16_t tcx5Size,
- float *spectrum );
-
-void tcx5TnsGrouping(
- const int16_t L_frame,
- const int16_t L_spec,
- float *spectrum );
-
-void tcx5TnsUngrouping(
- const int16_t L_frame,
- const int16_t L_spec,
- float *spectrum,
- const int16_t enc_dec );
-
-void lerp_flt(
- const float *f,
- float *f_out,
- const int16_t bufferNewSize,
- const int16_t bufferOldSize );
-
-void encoderSideLossSimulation(
- Encoder_State *st,
- PLC_ENC_EVS_HANDLE hPlc_Ext,
- float *isf_q,
- const float stab_fac,
- const int16_t calcOnlyISF,
- const int16_t L_frame );
-
-void enc_prm_side_Info(
- PLC_ENC_EVS_HANDLE hPlc_Ext,
- Encoder_State *st );
-
-void GplcTcxEncSetup(
- const int16_t tcxltp_pitch_int,
- PLC_ENC_EVS_HANDLE hPlc_Ext );
-
-int16_t encSideSpecPowDiffuseDetector(
- float *isf_ref,
- float *isf_con,
- const int32_t sr_core,
- float *prev_isf4_mean,
- const int16_t sw,
- const int16_t coder_type );
-
-void updateSpecPowDiffuseIdx(
- const float gain_pitch_buf[], /* i : gain pitch values */
- const float gain_code_buf[], /* i : gain pitch values */
- int16_t glr_idx[2], /* o : */
- float mean_gc[2] /* o : */
-);
-
-void getLookAheadResSig_flt(
- float *speechLookAhead,
- const float *A,
- float *res,
- const int16_t L_frame,
- const int16_t L_subfr,
- const int16_t m,
- const int16_t numSubFrame );
-
-void updatelsfForConcealment_flt(
- PLC_ENC_EVS_HANDLE decState,
- float *lsf );
-
-void getConcealedLP_flt(
- PLC_ENC_EVS_HANDLE memDecState,
- float *AqCon,
- const float xsfBase[],
- const int32_t sr_core,
- const int16_t last_good,
- const int16_t L_frame );
-
-void RecLpcSpecPowDiffuseLc_flt(
- float *ispq,
- float *isp_old,
- float *isfq,
- Decoder_State *st,
- const int16_t reset_q );
-
-void modify_lsf_flt(
- float *lsf,
- const int16_t n,
- const int32_t sr_core,
- const int16_t reset_q );
-
-void init_PLC_enc(
- PLC_ENC_EVS_HANDLE hPlcExt,
- const int32_t sr_core );
-
-void gPLC_encInfo(
- PLC_ENC_EVS_HANDLE hPlcExt,
- const int32_t total_brate,
- const int16_t bwidth,
- const int16_t last_clas,
- const int16_t coder_type );
-
-void resetTecDec(
- TEC_DEC_HANDLE hTecDec );
-
-void calcGainTemp_TBE(
- float **pCldfbRealSrc,
- float **pCldfbImagSrc,
- float *loBuffer,
- const int16_t startPos, /*!< Start position of the current envelope. */
- const int16_t stopPos, /*!< Stop position of the current envelope. */
- const int16_t lowSubband, /* lowSubband */
- float *pGainTemp,
- const int16_t code );
-
-void procTecTfa_TBE(
- float *hb_synth,
- float *gain,
- const int16_t flat_flag,
- const int16_t last_core,
- const int16_t L_subfr,
- const int16_t code );
-
-void resetTecEnc(
- TEC_ENC_HANDLE hTecEnc,
- const int16_t flag );
-
-void calcHiEnvLoBuff(
- const int16_t noCols,
- const int16_t *pFreqBandTable, /* i : freqbandTable */
- const int16_t nSfb, /* i : Number of scalefactors */
- float **pYBuf,
- float *loBuf,
- float *hiTempEnv );
-
-void calcLoEnvCheckCorrHiLo(
- const int16_t noCols,
- const int16_t *pFreqBandTable, /* i : freqbandTable */
- float *loBuf,
- float *loTempEnv,
- float *loTempEnv_ns,
- float *hiTempEnv,
- int16_t *corr_flag /* o : 0 for original, 1 for TEC */
-);
-
-
-void tecEnc_TBE(
- int16_t *corrFlag,
- const float *voicing,
- const int16_t coder_type );
-
-void set_TEC_TFA_code(
- const int16_t corrFlag,
- int16_t *tec_flag,
- int16_t *tfa_flag );
-
-float Damping_fact_flt(
- const int16_t coder_type, /* i : ACELP core coder type */
- const int16_t nbLostCmpt, /* i : compt for number of consecutive lost frame */
- int16_t last_good, /* i : class of last good received frame */
- float stab_fac, /* i : LSF stability factor */
- float *lp_gainp, /* i/o: low passed pitch gain used for concealment */
- const int16_t core /* i : current core: ACELP = 0, TCX20 = 1, TCX10 = 2 */
-);
-
-float getLevelSynDeemph(
- const float h1Init[], /* i : input value or vector to be processed */
- const float A[], /* i : LPC coefficients */
- const int16_t lenLpcExc, /* i : length of the LPC excitation buffer */
- const float preemph_fac, /* i : preemphasis factor */
- const int16_t numLoops /* i : number of loops */
-);
-
-void genPlcFiltBWAdap(
- const int32_t sr_core, /* i : core sampling rate */
- float *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc */
- const int16_t type, /* i : type of filter, either 0 : lowpass or 1 : highpass */
- const float alpha /* i : fade out factor [0 1) used decrease filter tilt */
-);
-
-void highPassFiltering(
- const int16_t last_good, /* i : last classification type */
- const int16_t L_buffer, /* i : buffer length */
- float exc2[], /* i/o: unvoiced excitation before the high pass filtering */
- const float hp_filt[], /* i : high pass filter coefficients */
- const int16_t l_fir_fer /* i : high pass filter length */
-);
-
-int16_t GetPLCModeDecision(
- Decoder_State *st /* i/o: decoder memory state pointer */
-);
-
-void addBassPostFilter(
- const float *harm_timeIn,
- const int16_t samplesToProcess,
- float **rAnalysis,
- float **iAnalysis,
- HANDLE_CLDFB_FILTER_BANK cldfb );
-
-ivas_error TonalMDCTConceal_Init_ivas(
- TonalMDCTConcealPtr hTonalMDCTConc,
- const uint16_t samplesPerBlock,
- const uint16_t nSamplesCore,
- const uint16_t nScaleFactors,
- TCX_CONFIG_HANDLE hTcxCfg );
-
-void TonalMDCTConceal_SaveFreqSignal_ivas(
- TonalMDCTConcealPtr hTonalMDCTConc,
- const float *mdctSpectrum,
- const uint16_t numSamples,
- const uint16_t nNewSamplesCore,
- const float *scaleFactors,
- const int16_t infoIGFStartLine );
-
-void TonalMDCTConceal_UpdateState_ivas(
- TonalMDCTConcealPtr hTonalMDCTConc,
- const int16_t numSamples,
- const float pitchLag,
- const int16_t badBlock,
- const int16_t tonalConcealmentActive );
-
-void TonalMDCTConceal_SaveTimeSignal_ivas(
- TonalMDCTConcealPtr hTonalMDCTConc,
- float *timeSignal,
- const int16_t numSamples );
-
-void TonalMDCTConceal_Detect_ivas(
- const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */
- const float pitchLag, /*IN */
- int16_t *umIndices, /*OUT*/
- const PsychoacousticParameters *psychParamsCurrent /*IN*/
-);
-
-void TonalMDCTConceal_Apply_ivas(
- TonalMDCTConcealPtr hTonalMDCTConc, /*IN */
- float *mdctSpectrum, /*OUT*/
- const PsychoacousticParameters *psychParamsCurrent /*IN*/
-);
-
-void TonalMDCTConceal_InsertNoise_ivas(
- const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */
- float *mdctSpectrum, /*OUT*/
- const int16_t tonalConcealmentActive,
- int16_t *pSeed, /*IN/OUT*/
- const float tiltCompFactor,
- const float crossfadeGain,
- const float concealment_noise[L_FRAME48k],
- const float cngLevelBackgroundTrace_bfi,
- const int16_t crossOverFreq );
-
-void DetectTonalComponents_flt(
- uint16_t indexOfTonalPeak[],
- uint16_t lowerIndex[],
- uint16_t upperIndex[],
- uint16_t *pNumIndexes,
- const float lastPitchLag,
- const float currentPitchLag,
- const float lastMDCTSpectrum[],
- const float scaleFactors[],
- const float secondLastPowerSpectrum[],
- const uint16_t nSamples,
- const uint16_t nSamplesCore,
- float floorPowerSpectrum,
- const PsychoacousticParameters *psychParamsCurrent );
-
-void RefineTonalComponents_flt(
- uint16_t indexOfTonalPeak[],
- uint16_t lowerIndex[],
- uint16_t upperIndex[],
- float phaseDiff[],
- float phases[],
- uint16_t *pNumIndexes,
- const float lastPitchLag,
- const float currentPitchLag,
- const float lastMDCTSpectrum[],
- const float scaleFactors[],
- const float secondLastPowerSpectrum[],
- const uint16_t nSamples,
- const uint16_t nSamplesCore,
- float floorPowerSpectrum,
- const PsychoacousticParameters *psychParamsCurrent );
-
-ivas_error PsychoacousticParameters_Init(
- const int32_t sr_core, /* i : sampling rate of core-coder */
- const int16_t nBins, /* i : Number of bins (spectral lines) */
- const int8_t nBands, /* i : Number of spectrum subbands */
- const int16_t isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */
- const int16_t isWarped, /* i : Flag indicating if the scale is linear or warped */
- PsychoacousticParameters *pPsychParams );
-
-void concealment_init(
- const int16_t L_frameTCX,
- T_PLCInfo_HANDLE hPlcInfo );
-
-void concealment_decode(
- const int16_t core,
- float *invkoef,
- T_PLCInfo_HANDLE hPlcInfo );
-
-void concealment_update(
- const int16_t bfi,
- const int16_t core,
- const int16_t harmonic,
- float *invkoef,
- T_PLCInfo_HANDLE hPlcInfo );
-
-void concealment_update2(
- const float *outx_new,
- T_PLCInfo_HANDLE hPlcInfo,
- const int16_t L_frameTCX );
-
-void concealment_signal_tuning(
- Decoder_State *st,
- const int16_t bfi,
- float *outx_new,
- const int16_t past_core_mode );
-
-void waveform_adj2(
- T_PLCInfo_HANDLE hPlcInfo,
- float *overlapbuf,
- float *outx_new,
- const int16_t delay,
- const int16_t bfi_cnt,
- const int16_t bfi );
-
-float SFM_Cal(
- const float fcoef[],
- const int16_t n );
-
-void set_state_ivas(
- int16_t *state,
- const int16_t num,
- const int16_t N );
-
-int16_t RFFTN(
- float *afftData,
- const float *trigPtr,
- const int16_t len,
- const int16_t isign );
-
-void DoFFT(
- float *re2,
- float *im2,
- const int16_t length );
-
-/*! r: flag indicating a valid bitrate */
-int16_t is_EVS_bitrate(
- const int32_t ivas_total_brate, /* i : EVS total bitrate */
- int16_t *Opt_AMR_WB /* i : AMR-WB IO flag */
-);
-
-int16_t getTcxonly_ivas(
- const int16_t element_mode, /* i : IVAS element mode */
- const int32_t total_brate, /* i : total bitrate */
- const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/
- const int16_t is_ism_format /* i : flag indicating ISM format */
-);
-
-int16_t getTnsAllowed(
- const int32_t total_brate, /* i : total bitrate */
- const int16_t igf, /* i : flag indicating IGF activity*/
- const int16_t element_mode /* i : IVAS element mode */
-);
-
-int16_t getCtxHm(
- const int16_t element_mode, /* i : IVAS element mode */
- const int32_t total_brate, /* i : total bitrate */
- const int16_t rf_flag /* i : flag to signal the RF mode */
-);
-
-int16_t getResq(
- const int32_t total_brate /* i : total bitrate */
-);
-
-int16_t getMdctWindowLength(
- const int16_t fscale );
-
-int16_t sr2fscale(
- const int32_t sr_core /* i : internal sampling rate */
-);
-
-int32_t getCoreSamplerateMode2_flt(
- const int16_t element_mode, /* i : IVAS element mode */
- const int32_t total_brate, /* i : total bitrate */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */
- const int16_t rf_mode, /* i : flag to signal the RF mode */
- const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */
-);
-
-float getTcxBandwidth_flt(
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-
-int16_t getCnaPresent(
- const int16_t element_mode, /* i : element mode */
- const int32_t element_brate, /* i : element bitrate */
- const int32_t total_brate, /* i : total bitrate */
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-int16_t getTcxLtp(
- const int32_t sr_core /* i : internal sampling rate */
-);
-
-int16_t initPitchLagParameters(
- const int32_t sr_core, /* i : internal sampling rate */
- int16_t *pit_min,
- int16_t *pit_fr1,
- int16_t *pit_fr1b,
- int16_t *pit_fr2,
- int16_t *pit_max );
-
-void attenuateNbSpectrum(
- const int16_t L_frame,
- float *spectrum );
-
-void SetModeIndex(
- Encoder_State *st, /* i : Encoder state */
- const int32_t last_total_brate, /* i : last total bitrate */
- const int16_t last_element_mode, /* i : last IVAS element mode */
- const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
-);
-
-int16_t getNumTcxCodedLines(
- const int16_t bwidth /* i : audio bandwidth */
-);
-
-int16_t getTcxLpcShapedAri(
- const int32_t total_brate, /* i : total bitrate */
- const int16_t rf_mode, /* i : flag to signal the RF mode */
- const int16_t element_mode /* i : IVAS element mode */
-);
-
-void IGFEncApplyMono(
- Encoder_State *st, /* i : Encoder state */
- const int16_t igfGridIdx, /* i : IGF grid index */
- float *pMDCTSpectrum, /* i/o: MDCT spectrum */
- float *pPowerSpectrum, /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */
- const int16_t isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */
- const int16_t isTNSActive, /* i : flag indicating if the TNS is active */
- const int16_t sp_aud_decision0, /* i : first stage switching decision */
- const int16_t vad_hover_flag /* i : VAD hangover flag */
-);
-
-void IGFEncApplyStereo(
- STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */
- int16_t ms_mask[2][MAX_SFB], /* i : bandwise MS mask */
- const IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS], /* i : instance handle of IGF Encoder */
- const int16_t igfGridIdx, /* i : IGF grid index */
- Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */
- float *pPowerSpectrum[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */
- float *pPowerSpectrumMsInv[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */
- float *inv_spectrum[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */
- const int16_t frameno, /* i : flag indicating index of current subframe */
- const int16_t sp_aud_decision0, /* i : sp_aud_decision0 */
- const int32_t element_brate, /* i : element bitrate */
- const int16_t mct_on /* i : flag mct block (1) or stereo (0) */
-);
-
-
-void IGFEncResetTCX10BitCounter_ivas_fx(
- const IGF_ENC_INSTANCE_HANDLE hIGFEnc /* i : instance handle of IGF Encoder */
-);
-
-ivas_error IGF_Reconfig(
- IGF_ENC_INSTANCE_HANDLE *hIGFEnc, /* i/o: instance handle of IGF Encoder */
- const int16_t igf, /* i : IGF on/off */
- const int16_t reset, /* i : reset flag */
- const int32_t brate, /* i : bitrate for configuration */
- const int16_t bwidth, /* i : signal bandwidth */
- const int16_t element_mode, /* i : IVAS element mode */
- const int16_t rf_mode /* i : flag to signal the RF mode */
-);
-
-void IGFEncSetMode(
- const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */
- const int32_t total_brate, /* i : encoder total bitrate */
- const int16_t bwidth, /* i : encoder audio bandwidth */
- const int16_t element_mode, /* i : IVAS element mode */
- const int16_t rf_mode /* i : flag to signal the RF mode */
-);
-
-/*! r: number of bits written per frame */
-int16_t IGFEncWriteBitstream(
- const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- int16_t *pBitOffset, /* i : ptr to bitOffset counter */
- const int16_t igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */
- const int16_t isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */
-);
-
-/*! r: total number of bits written */
-int16_t IGFEncWriteConcatenatedBitstream(
- const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */
- BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */
-);
-
-void IGFDecApplyMono_flt(
- const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i : instance handle of IGF Decoder */
- float *spectrum, /* i/o: MDCT spectrum */
- const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
- const int16_t bfi, /* i : frame loss == 1, frame good == 0 */
- const int16_t element_mode /* i : IVAS element mode */
-);
-
-void IGFDecCopyLPCFlatSpectrum_flt(
- const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */
- const float *pSpectrumFlat, /* i : LPC flattend spectrum from TCX dec */
- const int16_t igfGridIdx /* i : IGF grid index */
-);
-
-void IGFDecReadData_flt(
- const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Deccoder */
- Decoder_State *st, /* i : decoder state */
- const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
- const int16_t isIndepFrame /* i : if 1: arith dec force reset, if 0: no reset */
-);
-
-/*! r: return igfAllZero flag indicating if no envelope is transmitted */
-int16_t IGFDecReadLevel_flt(
- const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Deccoder */
- Decoder_State *st, /* i : decoder state */
- const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
- const int16_t isIndepFrame /* i : if 1: arith dec force reset, if 0: no reset */
-);
-
-void IGFDecRestoreTCX10SubFrameData_flt(
- const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */
- const int16_t subFrameIdx /* i : index of subframe */
-);
-
-void init_igf_dec_flt(
- IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */
-);
-
-void IGFDecSetMode_flt(
- const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */
- const int32_t total_brate, /* i : bitrate */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t element_mode, /* i : IVAS element mode */
- const int16_t defaultStartLine, /* i : default start subband index */
- const int16_t defaultStopLine, /* i : default stop subband index */
- const int16_t rf_mode /* i : flag to signal the RF mode */
-);
-
-void IGFDecStoreTCX10SubFrameData_flt(
- const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */
- const int16_t subFrameIdx /* i : index of subframe */
-);
-
-void IGFDecUpdateInfo_flt(
- const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */
- const int16_t subFrameIdx, /* i : subframe index */
- const int16_t igfGridIdx /* i : IGF grid index */
-);
-
-/*! r: error value: 0 -> error, 1 -> ok */
-int16_t IGFCommonFuncsIGFConfiguration_flt(
- const int32_t total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t element_mode, /* i : IVAS element mode */
- H_IGF_INFO hIGFInfo, /* o : IGF info handle */
- const int16_t rf_mode /* i : flag to signal the RF mode */
-);
-
-/*! r: error value: 0 -> error, 1 -> ok */
-int16_t IGFCommonFuncsIGFGetCFTables_flt(
- const int32_t total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t element_mode, /* i : element mode */
- const int16_t rf_mode, /* i : flag to signal the RF mode */
- const uint16_t **cf_se00, /* i : CF table for t == 0 and f == 0 */
- const uint16_t **cf_se01, /* i : CF table for t == 0 and f == 1 */
- int16_t *cf_off_se01, /* o : offset for CF table above */
- const uint16_t **cf_se02, /* i : CF tables for t == 0 and f >= 2 */
- const int16_t **cf_off_se02, /* o : offsets for CF tables above */
- const uint16_t **cf_se10, /* i : CF table for t == 1 and f == 0 */
- int16_t *cf_off_se10, /* o : offset for CF table above */
- const uint16_t **cf_se11, /* i : CF tables for t == 1 and f >= 1 */
- const int16_t **cf_off_se11 /* o : offsets for CF tables above */
-);
-
-/*! r: multiplication factor */
-int16_t IGF_ApplyTransFac_flt(
- const int16_t val, /* i : input value for multiplication, Q15 */
- const float transFac /* i : multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */
-);
-
-/*! r: return bitrate index */
-int16_t IGF_MapBitRateToIndex_flt(
- const int32_t brate, /* i : bitrate */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t element_mode, /* i : element mode */
- const int16_t rf_mode /* i : flag to signal the RF mode */
-);
-
-
-void IGFSCFDecoderOpen_ivas(
- IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i : handle to public data */
- H_IGF_INFO hIgfInfo, /* i : IGF info handle */
- const int32_t total_brate,
- const int16_t bwidth,
- const int16_t element_mode,
- const int16_t rf_mode );
-
-void IGFSCFDecoderReset_ivas(
- IGFSCFDEC_INSTANCE_HANDLE hPublicData /* i : handle to public data or NULL in case there was no instance created */
-);
-
-void IGFSCFDecoderDecode_ivas(
- IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i : handle to public data or NULL in case there was no instance created */
- Decoder_State *st, /* i/o: pointer to decoder state */
- int16_t *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */
- const int16_t igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */
- const int16_t indepFlag /* i : if 1 on input the decoder will be forced to reset,
- if 0 on input the decoder will be forced to encode without a reset */
-);
-
-/*! r: offset value */
-int16_t tbe_celp_exc_offset_flt(
- const int16_t T0, /* i : Integer pitch */
- const int16_t T0_frac /* i : Fractional part of the pitch */
-);
-
-void blend_subfr2_flt(
- float *sigIn1, /* i : input signal for fade-out */
- float *sigIn2, /* i : input signal for fade-in */
- float *sigOut /* o : output signal */
-);
-
-void init_tcx_window_cfg(
- TCX_CONFIG_HANDLE hTcxCfg, /* i : TCX Config handle */
- const int32_t sr_core, /* i : SR core */
- const int32_t input_Fs, /* i : input/output SR */
- const int16_t L_frame, /* i : L_frame at sr_core */
- const int16_t L_frameTCX, /* i : L_frame at i/o SR */
- const int16_t encoderLookahead_enc, /* i : encoder LA at sr_core */
- const int16_t encoderLookahead_FB, /* i : encoder LA at i/o SR */
- const int16_t mdctWindowLength, /* i : window length at sr_core */
- const int16_t mdctWindowLengthFB, /* i : window length at i/o SR */
- const int16_t element_mode /* i : mode of CPE/SCE */
-);
-
-void init_tcx_cfg(
- TCX_CONFIG_HANDLE hTcxCfg,
- const int32_t total_brate,
- const int32_t sr_core,
- const int32_t input_Fs,
- const int16_t L_frame,
- const int16_t bwidth,
- const int16_t L_frameTCX,
- const int16_t fscale,
- const int16_t encoderLookahead_enc,
- const int16_t encoderLookahead_FB,
- const float preemph_fac,
- const int16_t tcxonly,
- const int16_t rf_mode,
- const int16_t igf,
- const int16_t infoIGFStopFreq,
- const int16_t element_mode,
- const int16_t ini_frame,
- const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
-);
-
-#endif
diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h
index e9269e0f90fc30c91799b6cc19cecb246445fd41..7bc835807b3424cf93673fb47d7d8203fe1753f1 100644
--- a/lib_com/prot_fx.h
+++ b/lib_com/prot_fx.h
@@ -49,14 +49,63 @@
#include "ivas_cnst.h"
#include "stat_enc.h"
#include "stat_dec.h"
+#include "stat_com.h"
#include "ivas_stat_enc.h"
#include "ivas_stat_dec.h"
+#include "ivas_stat_com.h"
#include "ivas_error.h"
#include "ivas_error_utils.h"
#include "complex_basop.h"
#define TCX_IMDCT_SCALE 15
#define TCX_IMDCT_HEADROOM 1
+
+/*----------------------------------------------------------------------------------*
+ * Prototypes of global macros
+ *----------------------------------------------------------------------------------*/
+
+#ifndef min
+#define min( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )
+#endif
+
+#ifndef max
+#define max( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
+#endif
+
+#ifndef TRUNC
+#define TRUNC( x ) ( (int16_t) ( ( ( x ) >= 32767. ? 32767 : ( ( x ) <= -32768. ? -32768 : ( x ) ) ) + 0.5 ) )
+#endif
+
+#define log_base_2( x ) ( (double) log( (double) ( x ) ) * 1.4426950408889634074f )
+#define round_f( x ) ( ( ( x ) > 0 ) ? (int32_t) ( ( x ) + 0.5f ) : ( -(int32_t) ( ( -x ) + 0.5f ) ) )
+
+#ifndef ABSVAL
+#define ABSVAL( a ) ( ( a ) >= 0 ? ( a ) : ( -( a ) ) )
+#endif
+
+#ifndef SQR
+#define SQR( a ) ( ( a ) * ( a ) )
+#endif
+
+#ifndef SWAP
+#define SWAP( a, b ) \
+ { \
+ tempr = ( a ); \
+ ( a ) = ( b ); \
+ ( b ) = tempr; \
+ }
+#endif
+
+#ifndef swap
+#define swap( x, y, type ) \
+ { \
+ type u__p; \
+ u__p = x; \
+ x = y; \
+ y = u__p; \
+ }
+#endif
+
/*================================================================================*/
/* conversion functions: */
/*================================================================================*/
@@ -4866,24 +4915,18 @@ Word16 est_tilt_fx( /* o : tilt of the code
const Word32 gain_code, /* i : algebraic code gain Q16 */
Word16 *voice_fac, /* o : voicing factor Q15 */
const Word16 Q_exc /* i : Scaling factor of excitation Q0 */
-#ifdef ADD_LRTD
- ,
- const Word16 L_subfr /* i : Sub frame lenght */
-#endif
);
-Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */
- const Word16 *exc, /* i : adaptive excitation vector Qx */
- const Word16 gain_pit, /* i : adaptive gain Q14 */
- const Word16 *code, /* i : algebraic excitation vector Q9 */
- const Word32 gain_code, /* i : algebraic code gain Q16 */
- Word16 *voice_fac, /* o : voicing factor Q15 */
- const Word16 Q_exc /* i : Scaling factor of excitation Q0 */
-#if 1 // def ADD_LRTD
- ,
- const Word16 L_subfr, /* i : Sub frame length */
- const Word16 flag_tilt /* i : flag for special tilt */
-#endif
+/* o : tilt of the code Q15 */
+Word16 est_tilt_ivas_fx(
+ const Word16 *exc, /* i : adaptive excitation vector Qx */
+ const Word16 gain_pit, /* i : adaptive gain Q14 */
+ const Word16 *code, /* i : algebraic excitation vector Q9 */
+ const Word32 gain_code, /* i : algebraic code gain Q16 */
+ Word16 *voice_fac, /* o : voicing factor Q15 */
+ const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */
+ const Word16 L_subfr, /* i : Sub frame length */
+ const Word16 flag_tilt /* i : flag for special tilt */
);
Word16 Est_tilt2( /* o : tilt of the code */
@@ -6063,10 +6106,7 @@ void TBEreset_dec_fx(
void td_bwe_dec_init_fx(
Decoder_State *st_fx, /* i/o: SHB decoder structure */
TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
-#ifdef ADD_IVAS_BWE
- const Word16 extl, /* i : BWE extension layer */
-#endif
- const Word32 output_Fs /* i : output sampling rate */
+ const Word32 output_Fs /* i : output sampling rate */
);
// lsf_dec_fx.c
@@ -7127,30 +7167,21 @@ void dec_pit_exc_fx(
const Word16 nb_subfr_fx /* i : Number of subframe considered */
,
Word16 *gain_buf /*Q14*/
-#ifdef ADD_LRTD
- ,
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-#endif
);
void dec_pit_exc_ivas_fx(
- Decoder_State *st_fx, /* i/o: decoder static memory */
- const Word16 *Aq_fx, /* i : LP filter coefficient */
- const Word16 coder_type, /* i : coding type */
- const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
- Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */
- Word16 *code_fx, /* o : innovation */
- Word16 *exc_fx, /* i/o: adapt. excitation exc */
- Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
- const Word16 nb_subfr_fx /* i : Number of subframe considered */
- ,
- Word16 *gain_buf /*Q14*/
-#if 1 // def ADD_LRTD
- ,
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ const Word16 *Aq_fx, /* i : LP filter coefficient */
+ const Word16 coder_type, /* i : coding type */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */
+ Word16 *code_fx, /* o : innovation */
+ Word16 *exc_fx, /* i/o: adapt. excitation exc */
+ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
+ const Word16 nb_subfr_fx, /* i : Number of subframe considered */
+ Word16 *gain_buf, /*Q14*/
const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-#endif
);
// pit_dec_fx.c
@@ -7205,28 +7236,24 @@ Word16 pit_decode_fx( /* o : floating pitch value
Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */
Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */
const Word16 L_subfr /* i : subframe length */
-#ifdef ADD_LRTD
- ,
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-#endif
);
-Word16 pit_decode_ivas_fx( /* o : floating pitch value */
- Decoder_State *st_fx, /* i/o: decoder state structure */
- const Word32 core_brate, /* i : core bitrate */
- const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
- const Word16 L_frame, /* i : length of the frame */
- Word16 i_subfr, /* i : subframe index */
- const Word16 coder_type, /* i : coding type */
- Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */
- Word16 *T0, /* o : close loop integer pitch */
- Word16 *T0_frac, /* o : close loop fractional part of the pitch */
- Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */
- Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */
- const Word16 L_subfr, /* i : subframe length */
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */
+/* o : floating pitch value */
+Word16 pit_decode_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder state structure */
+ const Word32 core_brate, /* i : core bitrate */
+ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const Word16 L_frame, /* i : length of the frame */
+ Word16 i_subfr, /* i : subframe index */
+ const Word16 coder_type, /* i : coding type */
+ Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */
+ Word16 *T0, /* o : close loop integer pitch */
+ Word16 *T0_frac, /* o : close loop fractional part of the pitch */
+ Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */
+ Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */
+ const Word16 L_subfr, /* i : subframe length */
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */
);
void pit_Q_dec_fx(
@@ -7607,15 +7634,6 @@ void perform_noise_estimation_dec_fx(
float *power_spectrum,
#endif
HANDLE_FD_CNG_DEC hFdCngDec /* i/o: FD_CNG structure containing all buffers and variables */
-#ifdef IVAS_CODE_CNG
- ,
- const Word16 element_mode, /* i : element mode */
- const Word16 bwidth, /* i : audio bandwidth */
- const Word16 L_frame, /* i : frame length at internal Fs */
- const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */
- const Word32 last_core_brate, /* i : previous frame core bitrate */
- const Word16 VAD /* i : VAD flag in the decoder */
-#endif
);
void perform_noise_estimation_dec_ivas_fx(
@@ -7728,19 +7746,12 @@ Word16 WB_BWE_gain_deq_fx(
);
Word16 wb_bwe_dec_fx(
-#ifdef ADD_IVAS_BWE
- const Word16 output[], /* i : suntehsis @ internal Fs */
-#endif
- Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */
- Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
-#ifdef ADD_IVAS_BWE
- const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
-#endif
+ Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */
+ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
const Word16 output_frame, /* i : frame length */
Word16 *voice_factors_fx, /* i : voicing factors Q15 */
const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */
- Decoder_State *st_fx /* i/o: decoder state structure */
- ,
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 *Qpost );
Word16 swb_bwe_gain_deq_fx( /* o : BWE class */
@@ -7752,18 +7763,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class
const Word16 hqswb_clas /* i : HQ BWE class */
);
-Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/
-#ifdef ADD_IVAS_BWE
- const Word16 output[], /* i : suntehsis @ internal Fs */
-#endif
- Decoder_State *st_fx, /* i/o: decoder state structure */
- Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */
- Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
-#ifdef ADD_IVAS_BWE
- const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
-#endif
- const Word16 output_frame /* i : frame length */
- ,
+Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/
+ Decoder_State *st_fx, /* i/o: decoder state structure */
+ Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */
+ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
+ const Word16 output_frame, /* i : frame length */
Word16 *Qpost );
void fd_bwe_dec_init(
@@ -8039,22 +8043,12 @@ ivas_error core_switching_pre_dec_fx(
);
ivas_error core_switching_post_dec_fx(
- Decoder_State *st_fx, /* i/o: decoder state structure */
- Word16 *synth, /* i/o: output synthesis Qsynth Qsynth*/
-#ifdef IVAS_CODE_SWITCHING
- float *output, /* i/o: LB synth/upsampled LB synth */
- float output_mem[], /* i : OLA memory from last TCX/HQ frame */
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
-#endif
+ Decoder_State *st_fx, /* i/o: decoder state structure */
+ Word16 *synth, /* i/o: output synthesis Qsynth Qsynth*/
const Word16 output_frame, /* i : frame length Q0*/
const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/
-#ifdef IVAS_CODE_SWITCHING
- const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */
- const Word16 nchan_out, /* i : number of output channels */
-#endif
- const Word16 last_element_mode, /* i : element mode of previous frame Q0*/
- Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */
+ const Word16 last_element_mode, /* i : element mode of previous frame Q0*/
+ Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */
);
ivas_error core_switching_post_dec_ivas_fx(
@@ -8744,10 +8738,6 @@ Word16 dec_acelp_tcx_frame_fx(
Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */
Word16 *voice_factors, /* o : voicing factors */
Word16 pitch_buf[] /* o : floating pitch for each subframe */
-#ifdef IVAS_CODE_CNG
- ,
- STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */
-#endif
);
// dec_LPD_fx.c
@@ -10979,7 +10969,6 @@ void IGFEncConcatenateBitstream(
BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */
);
-#endif
void hq_generic_hf_encoding_fx(
const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */
@@ -11264,3 +11253,746 @@ void WriteToBitstream_ivas_fx(
Word16 *pnSize,
BSTR_ENC_HANDLE hBstr,
Word16 *pnBits );
+
+
+/*===========================================================================================*/
+/*----------------------------------------------------------------------------------*
+ * MODE1 prototypes
+ *----------------------------------------------------------------------------------*/
+
+/*! r: inverse square root of input value */
+float inv_sqrt(
+ const float x /* i : input value */
+);
+
+/*! r: output random value */
+int16_t own_random(
+ int16_t *seed /* i/o: random seed */
+);
+
+/*! r: sign of x (+1/-1) */
+float sign(
+ const float x /* i : input value of x */
+);
+
+/*! r: logarithm2 of x */
+float log2_f(
+ const float x /* i : input value of x */
+);
+
+int16_t norm_ul_float(
+ uint32_t UL_var1 );
+
+/*! r: sum of all vector elements */
+int16_t sum_s(
+ const int16_t *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+/*! r: sum of all vector elements */
+int32_t sum_l(
+ const int32_t *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+/*! r: sum of all squared vector elements */
+float sum2_f(
+ const float *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+void set_c(
+ int8_t y[], /* i/o: Vector to set */
+ const int8_t a, /* i : Value to set the vector to */
+ const int32_t N /* i : Length of the vector */
+);
+
+void set_s(
+ int16_t y[], /* i/o: Vector to set */
+ const int16_t a, /* i : Value to set the vector to */
+ const int16_t N /* i : Lenght of the vector */
+);
+
+void set_l(
+ int32_t y[], /* i/o: Vector to set */
+ const int32_t a, /* i : Value to set the vector to */
+ const int16_t N /* i : Length of the vector */
+);
+
+void set_f(
+ float y[], /* i/o: Vector to set */
+ const float a, /* i : Value to set the vector to */
+ const int16_t N /* i : Lenght of the vector */
+);
+
+void set_zero_fx(
+ Word32 *vec, /* o : input vector */
+ const Word16 lvec /* i : length of the vector */
+);
+void set_zero2_fx(
+ Word32 *vec, /* o : input vector */
+ const Word32 lvec /* i : length of the vector */
+);
+void set16_zero_fx(
+ Word16 *vec, /* o : input vector */
+ const Word16 lvec /* i : length of the vector */
+);
+
+void set_zero(
+ float *vec, /* o : input vector */
+ const int16_t lvec /* i : length of the vector */
+);
+
+void mvr2r(
+ const float x[], /* i : input vector */
+ float y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+void mvs2s(
+ const int16_t x[], /* i : input vector */
+ int16_t y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+uint32_t mvr2s(
+ const float x[], /* i : input vector */
+ int16_t y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+void mvs2r(
+ const int16_t x[], /* i : input vector */
+ float y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+void mvl2l(
+ const int32_t x[], /* i : input vector */
+ int32_t y[], /* o : output vector */
+ const int16_t n /* i : vector size */
+);
+
+
+/*! r: index of the maximum value in the input vector */
+int16_t maximum(
+ const float *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ float *max_val /* o : maximum value in the input vector */
+);
+/*! r: index of the maximum value in the input vector */
+int16_t maximumAbs(
+ const float *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ float *max_val /* o : maximum value in the input vector */
+);
+
+Word16 maximumAbs_l(
+ const Word32 *vec, /* i : input vector */
+ const Word16 lvec, /* i : length of input vector */
+ Word32 *max_val /* o : maximum value in the input vector */
+);
+
+/*! r: index of the minimum value in the input vector */
+int16_t minimum(
+ const float *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ float *min_val /* o : minimum value in the input vector */
+);
+
+/*! r: index of the minimum value in the input vector */
+int16_t minimum_s(
+ const int16_t *vec, /* i : Input vector */
+ const int16_t lvec, /* i : Vector length */
+ int16_t *min_val /* o : minimum value in the input vector */
+);
+
+/*! r: return index with max energy value in vector */
+int16_t emaximum(
+ const float *vec, /* i : input vector */
+ const int16_t lvec, /* i : length of input vector */
+ float *ener_max /* o : maximum energy value */
+);
+
+/*! r: vector mean */
+float mean(
+ const float *vec, /* i : input vector */
+ const int16_t lvec /* i : length of input vector */
+);
+
+/*! r: dot product of x[] and y[] */
+float dotp(
+ const float x[], /* i : vector x[] */
+ const float y[], /* i : vector y[] */
+ const int16_t n /* i : vector length */
+);
+
+void v_add(
+ const float x1[], /* i : Input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 + vector 2 */
+ const int16_t N /* i : Vector length */
+);
+
+void v_sub(
+ const float x1[], /* i : Input vector 1 */
+ const float x2[], /* i : Input vector 2 */
+ float y[], /* o : Output vector that contains vector 1 - vector 2 */
+ const int16_t N /* i : Vector length */
+);
+
+/*! r: dequanzited gain */
+float usdequant(
+ const int16_t idx, /* i : quantizer index */
+ const float qlow, /* i : lowest codebook entry (index 0) */
+ const float delta /* i : quantization step */
+);
+
+void sort(
+ uint16_t *x, /* i/o: Vector to be sorted */
+ uint16_t len /* i/o: vector length */
+);
+
+void sort_l(
+ Word32 *x, /* i/o: Vector to be sorted */
+ Word16 len /* i/o: vector length */
+);
+
+
+ivas_error push_indice(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ int16_t id, /* i : ID of the indice */
+ uint16_t value, /* i : value of the quantized indice */
+ int16_t nb_bits /* i : number of bits used to quantize the indice */
+);
+
+ivas_error push_next_indice(
+ BSTR_ENC_HANDLE hBstr,
+ UWord16 value, /* i : value of the quantized indice */
+ Word16 nb_bits /* i : number of bits used to quantize the indice */
+);
+
+ivas_error push_next_bits(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const UWord16 bits[], /* i : bit buffer to pack, sequence of single bits */
+ const Word16 nb_bits /* i : number of bits to pack */
+);
+
+/*! r: maximum number of indices */
+Word16 get_ivas_max_num_indices_fx(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const Word32 ivas_total_brate /* i : IVAS total bitrate */
+);
+
+/*! r: maximum number of indices */
+int16_t get_BWE_max_num_indices(
+ const int32_t extl_brate /* i : extensiona layer bitrate */
+);
+
+/*! r: maximum number of indices */
+Word16 get_ivas_max_num_indices_metadata_fx(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const Word32 ivas_total_brate /* i : IVAS total bitrate */
+);
+ivas_error ind_list_realloc(
+ INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */
+ const int16_t max_num_indices, /* i : new maximum number of allowed indices in the list */
+ Encoder_Struct *st_ivas /* i : IVAS encoder structure */
+);
+
+ivas_error check_ind_list_limits(
+ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */
+);
+
+void move_indices(
+ INDICE_HANDLE old_ind_list, /* i/o: old location of indices */
+ INDICE_HANDLE new_ind_list, /* i/o: new location of indices */
+ const int16_t nb_indices /* i : number of moved indices */
+);
+
+/*! r: index of the indice in the list, -1 if not found */
+int16_t find_indice(
+ BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */
+ const int16_t id, /* i : ID of the indice */
+ uint16_t *value, /* o : value of the quantized indice */
+ int16_t *nb_bits /* o : number of bits used to quantize the indice */
+);
+
+/*! r: number of deleted indices */
+uint16_t delete_indice(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t id /* i : ID of the indice */
+);
+
+/*! r: value of the indice */
+uint16_t get_next_indice(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+);
+
+/*! r: value of the indice */
+uint16_t get_next_indice_1(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+void get_next_indice_tmp(
+ Decoder_State *st, /* o : decoder state structure */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+);
+
+/*! r: value of the indice */
+uint16_t get_indice(
+ Decoder_State *st, /* i/o: decoder state structure */
+ int16_t pos, /* i : absolute position in the bitstream */
+ int16_t nb_bits /* i : number of bits that were used to quantize the indice */
+);
+
+void reset_indices_enc(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const int16_t max_num_indices /* i : max number of indices */
+);
+
+void reset_indices_dec(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+Word16 rate2EVSmode_float(
+ const Word32 brate, /* i : bitrate */
+ int16_t *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */
+);
+
+
+/*! r: 1 = OK, 0 = something wrong */
+ivas_error read_indices(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ uint16_t bit_stream[], /* i : bitstream buffer */
+ UWord16 num_bits, /* i : number of bits in bitstream */
+ int16_t *prev_ft_speech,
+ int16_t *CNG,
+ int16_t bfi /* i : bad frame indicator */
+);
+
+
+void ivas_set_bitstream_pointers(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+Decoder_State **reset_elements(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+);
+
+void mdct_switching_dec_ivas_fx(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+
+int16_t print_disclaimer(
+ FILE *fPtr );
+
+void fft_rel(
+ float x[], /* i/o: input/output vector */
+ const int16_t n, /* i : vector length */
+ const int16_t m /* i : log2 of vector length */
+);
+
+void preemph_ivas_fx(
+ Word32 *signal, /* i/o: signal Qx*/
+ const Word16 mu, /* i : preemphasis factor Q15*/
+ const Word16 L, /* i : vector size Q0*/
+ Word32 *mem /* i/o: memory (x[-1]) Qx*/
+);
+
+void create_offset(
+ UWord32 *offset_scale1,
+ UWord32 *offset_scale2,
+ const int16_t mode,
+ const int16_t prediction_flag );
+
+void BASOP_cfft_ivas(
+ Word32 *re, /* i/o: real part */
+ Word32 *im, /* i/o: imag part */
+ Word16 s, /* i : stride real and imag part */
+ Word16 *scale /* i : scalefactor */
+);
+
+Word32 ar_div_ivas(
+ Word32 num,
+ Word32 denum );
+
+Word32 Mult_32_16(
+ Word32 a,
+ Word16 b );
+
+Word32 Mult_32_32(
+ Word32 a,
+ Word32 b );
+
+
+void bit_allocation_second_fx2(
+ Word32 *Rk,
+ Word32 *Rk_sort,
+ Word16 BANDS,
+ const Word16 *band_width,
+ Word16 *k_sort,
+ Word16 *k_num,
+ const Word16 *p2a_flags,
+ const Word16 p2a_bands,
+ const Word16 *last_bitalloc,
+ const Word16 input_frame );
+
+void bit_allocation_second_fx2(
+ Word32 *Rk,
+ Word32 *Rk_sort,
+ Word16 BANDS,
+ const Word16 *band_width,
+ Word16 *k_sort,
+ Word16 *k_num,
+ const Word16 *p2a_flags,
+ const Word16 p2a_bands,
+ const Word16 *last_bitalloc,
+ const Word16 input_frame );
+
+#ifdef DEBUGGING
+void read_next_force(
+ int16_t *force, /* i/o: force value (0/1, 0 = speech, 1 = music)*/
+ FILE *f_force, /* i : force switching profile (0 if N/A) */
+ int32_t *force_profile_cnt /* i/o: counter of frames for force switching profile file */
+);
+#endif
+
+ivas_error init_encoder_ivas_fx(
+ Encoder_State *st, /* i/o: state structure */
+ Encoder_Struct *st_ivas, /* i/o: encoder state structure */
+ const Word16 idchan, /* i : channel ID */
+ const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */
+ const Word16 interval_SID, /* i : interval for SID update */
+ const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */
+ const ISM_MODE ism_mode, /* i : ISM mode */
+ const Word32 element_brate /* i : element bitrate */
+);
+
+ivas_error acelp_core_enc_ivas_fx(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const Word16 inp[], /* i : input signal of the current frame Q_new*/
+ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/
+ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/
+ const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/
+ Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/
+ Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/
+ const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/
+ const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/
+ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/
+ Word16 *voice_factors_fx, /* o : voicing factors Q15*/
+ Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/
+ Word16 *q_old_syn_12k8_16,
+ Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/
+ Word16 *unbits, /* o : number of unused bits Q0*/
+ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
+ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/
+ Word16 Q_new );
+
+void flip_and_downmix_generic_fx_32(
+ Word32 input[], /* i : input spectrum Qx*/
+ Word32 output[], /* o : output spectrum Qx*/
+ const Word16 length, /* i : length of spectra */
+ Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx*/
+ Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/
+ Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/
+ Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */
+);
+
+void GenTransition_fixed(
+ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */
+ const Word32 output_Fs, /* i : output sampling rate : Q0 */
+ const Word16 element_mode, /* i : element mode : Q0 */
+ const Word16 L_frame, /* i : ACELP frame length : Q0 */
+ const Word16 rf_flag, /* i : RF flag : Q0 */
+ const Word32 total_brate, /* i : total bitrate : Q0 */
+ const Word16 prev_Qx );
+
+void GenTransition_WB_fixed(
+ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */
+ const Word32 output_Fs /* i : output sampling rate */
+);
+
+Word16 quant_2p_2N1_fx( /* o: return (2*N)+1 bits */
+ const Word16 pos1, /* i: position of the pulse 1 */
+ const Word16 pos2, /* i: position of the pulse 2 */
+ const Word16 N /* i: number of bits FOR position */
+);
+
+void bands_and_bit_alloc_ivas_fx(
+ const Word16 cor_strong_limit, /* i : HF correlation */
+ const Word16 noise_lev, /* i : dwn scaling factor */
+ const Word32 core_brate, /* i : core bit rate */
+ const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/
+ const Word16 bits_used, /* i : Number of bit used before frequency Q */
+ Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */
+ const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */
+ Word16 *max_ener_band, /* o : Sorted order */
+ Word16 *out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */
+ Word16 *nb_subbands, /* o : Number of subband allowed */
+ const Word16 *exc_diff, /* i : Difference signal to quantize (encoder side only) */
+ Word16 *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */
+ Word16 *pvq_len, /* o : Number of bin covered with the PVQ */
+ const Word16 coder_type, /* i : coding type */
+ const Word16 bwidth, /* i : input signal bandwidth */
+ const Word16 GSC_noisy_speech, /* i : GSC noisy speech flag */
+ const Word16 L_frame, /* i : frame length */
+ const Word16 element_mode, /* i : element mode */
+ const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */
+);
+
+void ivas_find_wsp_fx(
+ const Word16 L_frame, /* i : length of the frame Q0*/
+ const Word16 L_subfr, /* i : length of subframe Q0*/
+ const Word16 nb_subfr, /* i : number of subframes Q0*/
+ const Word16 *A_fx,
+ /* i : A(z) filter coefficients */ // Q12
+ Word16 *Aw_fx,
+ /* o : weighted A(z) filter coefficients */ // Q12
+ const Word16 *speech_fx,
+ /* i : pointer to the denoised speech frame */ // Q_new
+ const Word16 tilt_fact,
+ /* i : tilt factor */ // Q15
+ Word16 *wsp_fx,
+ /* o : poitnter to the weighted speech frame */ // Q_new
+ Word16 *mem_wsp_fx,
+ /* i/o: W(Z) denominator memory */ // Q_new
+ const Word16 gamma,
+ /* i : weighting factor */ // Q15
+ const Word16 L_look /* i : look-ahead Q0*/
+);
+
+Word16 RCcontextMapping_encode2_estimate_bandWise_start_fx(
+ Word16 *x, /* Q0 */
+ const Word16 nt, /* Q0 */
+ const Word16 target, /* Q0 */
+ HANDLE_RC_CONTEXT_MEM hContextMem );
+
+Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
+ Word16 *x, /* Q0 */
+ const Word16 start_line, /* Q0 */
+ const Word16 end_line, /* Q0 */
+ HANDLE_RC_CONTEXT_MEM hContextMem /* Q0 */
+);
+
+
+/*! r: Q15 */
+Word16 expfp_evs_fx(
+ const Word16 x, /* i : mantissa Q15-e */
+ const Word16 x_e /* i : exponent Q0 */
+);
+
+
+void tcx_arith_render_envelope_ivas_fx(
+ const Word16 A_ind[], /* i : LPC coefficients of signal envelope Q12*/
+ const Word16 L_frame, /* i : number of spectral lines Q0*/
+ const Word16 L_spec, /* i : length of the coded spectrum Q0*/
+ const Word16 preemph_fac, /* i : pre-emphasis factor Q15*/
+ const Word16 gamma_w, /* i : A_ind -> weighted envelope factor Q15*/
+ const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor Q14*/
+ Word32 env[] /* o : shaped signal envelope Q16*/
+);
+
+void tcx_arith_decode_envelope_ivas_fx(
+ Decoder_State *st, /* i/o: coder state */
+ Word32 q_spectrum[], /* o : quantised MDCT coefficients */
+ Word16 *q_spectrum_e, /* o : MDCT exponent */
+ const Word16 L_frame, /* i : frame or MDCT length */
+ Word16 L_spec, /* i : length w/o BW limitation */
+ const Word16 A_ind[], /* i : quantised LPC coefficients */
+ const Word16 target_bits, /* i : number of available bits */
+ Word16 prm[], /* i : bitstream parameters */
+ const Word16 use_hm, /* i : use HM in current frame? */
+ const Word16 prm_hm[], /* i : HM parameter area */
+ Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/
+ Word16 *arith_bits, /* o : bits used for ari. coding */
+ Word16 *signaling_bits, /* o : bits used for signaling */
+ const Word16 low_complexity /* i : low-complexity flag */
+);
+
+
+void UnmapIndex_fx(
+ const Word16 PeriodicityIndex, /* Q0 */
+ const Word16 Bandwidth, /* Q0 */
+ const Word16 LtpPitchLag, /* Q0 */
+ const Word8 SmallerLags, /* Q0 */
+ Word16 *FractionalResolution, /* Q0 */
+ Word32 *Lag /* Q0 */
+);
+
+#define GET_ADJ( T, L ) GET_ADJ2( T, L, *FractionalResolution )
+#define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) )
+
+
+Word32 tcx_hm_render_fx(
+ const Word32 lag, /* i: pitch lag Q0 */
+ const Word16 fract_res, /* i: fractional resolution of the lag Q0 */
+ Word16 p[] /* o: harmonic model Q13 */
+);
+
+
+void tcx_hm_modify_envelope_fx(
+ const Word16 gain, /* i: HM gain Q11 */
+ const Word32 lag, /* i: pitch lag Q0 */
+ const Word16 fract_res, /* i: fractional resolution of the lag Q0 */
+ const Word16 p[], /* i: harmonic model Q13 */
+ Word32 env[], /* i/o: envelope Q16 */
+ const Word16 L_frame /* i: number of spectral lines Q0 */
+);
+
+void tcx_hm_decode(
+ const Word16 L_frame, /* i : number of spectral lines */
+ Word32 env[], /* i/o: envelope shape (Q16) */
+ const Word16 targetBits, /* i : target bit budget */
+ const Word16 coder_type, /* i : GC/VC coder type */
+ const Word16 prm_hm[], /* i : HM parameters */
+ const Word16 LtpPitchLag, /* i : LTP pitch lag or -1 if none */
+ Word16 *hm_bits /* o : bit consumption */
+);
+
+void writeTCXMode_fx(
+ Encoder_State *st, /* i/o: encoder state structure */
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/
+ Word16 *nbits_start /* o : nbits start Q0*/
+);
+
+void writeTCXWindowing_fx(
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ const Word16 overlap_mode /* i : overlap mode Q0*/
+);
+
+void writeLPCparam(
+ Encoder_State *st, /* i/o: encoder state structure */
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ const int16_t param_lpc[], /* i : LPC parameters to write */
+ const int16_t bits_param_lpc[], /* i : bits per LPC parameter */
+ const int16_t no_param_lpc, /* i : number of LPC parameters */
+ int16_t *nbits_lpc /* o : LPC bits written */
+);
+
+void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue );
+void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value );
+void const *GetNumOfTnsFilters_flt( void const *p, const int16_t index, int16_t *pValue );
+void *SetNumOfTnsFilters_flt( void *p, const int16_t index, const int16_t value );
+
+int16_t DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
+int16_t DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
+
+int16_t DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
+
+int16_t DecodeTnsFilterOrderSWBTCX10_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
+int16_t DecodeTnsFilterOrderSWBTCX20_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
+
+int16_t EncodeTnsFilterOrderSWBTCX10_flt( const int16_t value, const int16_t index );
+
+int16_t GetTnsFilterOrderBitsSWBTCX10_flt( const int16_t value, const int16_t index );
+int16_t DecodeTnsFilterOrder_flt( Decoder_State *st, const int16_t index, int16_t *pValue );
+
+void ResetTnsData_flt(
+ STnsData *pTnsData );
+
+void ClearTnsFilterCoefficients_flt(
+ STnsFilter *pTnsFilter );
+
+void EncodeTnsData(
+ STnsConfig const *pTnsConfig, /* i : TNS Configuration struct */
+ STnsData const *pTnsData, /* i : TNS data struct (quantized param) */
+ Word16 *stream, /* o : internal data stream */
+ Word16 *pnSize, /* o : number of written parameters */
+ Word16 *pnBits /* o : number of written bits */
+);
+
+Word16 DecodeTnsData_ivas(
+ STnsConfig const *pTnsConfig,
+ const Word16 *stream,
+ Word16 *pnSize,
+ STnsData *pTnsData );
+
+void WriteTnsData(
+ const STnsConfig *pTnsConfig, /* i : TNS Configuration struct */
+ const Word16 *stream, /* i : internal data stream */
+ Word16 *pnSize, /* o : number of written parameters */
+ BSTR_ENC_HANDLE hBstr, /* o : bitstream */
+ Word16 *pnBits /* o : number of written bits */
+);
+
+void ReadTnsData_ivas(
+ STnsConfig const *pTnsConfig,
+ Decoder_State *st,
+ Word16 *pnBits,
+ Word16 *stream,
+ Word16 *pnSize );
+
+void analysisCldfbEncoder_ivas_fx(
+ Encoder_State *st, /* i/o: encoder state structure */
+ Word32 *timeIn, /*q11*/
+ Word16 timeInq, /*q0*/
+ Word16 samplesToProcess, /*q0*/
+ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
+ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
+ Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
+ Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
+ Word32 *ppBuf_Ener,
+ Word16 *enerBuffSum_exp,
+ CLDFB_SCALE_FACTOR *scale );
+
+ivas_error openCldfb_ivas(
+ HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */
+ CLDFB_TYPE type, /* i : analysis or synthesis */
+ const int32_t sampling_rate, /* i : sampling rate */
+ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */
+);
+
+ivas_error openCldfb_ivas_enc(
+ HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */
+ CLDFB_TYPE type, /* i : analysis or synthesis */
+ const Word32 sampling_rate, /* i : sampling rate */
+ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */
+);
+
+void resampleCldfb_ivas(
+ HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */
+ const Word32 newSamplerate /* i : new samplerate to operate */
+);
+
+ivas_error cldfb_save_memory_ivas(
+ HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */
+);
+
+void deleteCldfb_ivas(
+ HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */
+);
+
+/*! r: flag indicating a valid bitrate */
+Word16 is_EVS_bitrate(
+ const Word32 ivas_total_brate, /* i : EVS total bitrate */
+ Word16 *Opt_AMR_WB /* i : AMR-WB IO flag */
+);
+
+void IGFEncResetTCX10BitCounter_ivas_fx(
+ const IGF_ENC_INSTANCE_HANDLE hIGFEnc /* i : instance handle of IGF Encoder */
+);
+
+ivas_error IGF_Reconfig(
+ IGF_ENC_INSTANCE_HANDLE *hIGFEnc, /* i/o: instance handle of IGF Encoder */
+ const Word16 igf, /* i : IGF on/off */
+ const Word16 reset, /* i : reset flag */
+ const Word32 brate, /* i : bitrate for configuration */
+ const Word16 bwidth, /* i : signal bandwidth */
+ const Word16 element_mode, /* i : IVAS element mode */
+ const Word16 rf_mode /* i : flag to signal the RF mode */
+);
+
+void ordr_esti(
+ const Word16 k, /* i : sub-vector index */
+ Word16 *Mpos, /* i/o: dominant sub-vector position from ACV */
+ Word16 svOrder[], /* i/o: AVQ sub-vector order */
+ const Word16 Nsv /* i : total sub-vectors in a sub-frames */
+);
+
+/*===========================================================================================*/
+#endif
diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c
index ed914f2a159085a0359e1951557f5ff2ffb59e4b..479bc04d9c357ca0101de7e154b903b3e4d75924 100644
--- a/lib_com/pvq_com_fx.c
+++ b/lib_com/pvq_com_fx.c
@@ -4,7 +4,6 @@
#include
#include "options.h" /* Compilation switches */
#include "prot_fx.h" /* Function prototypes */
-#include "prot.h" /* Function prototypes */
#include "cnst.h" /* Common constants */
#include "rom_com.h" /* Static table prototypes */
diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c
index 665dbfae622164864d8dd41dce80d9254ed1c263..32d18d1feb543401666d751fb554240dce4e8e6f 100644
--- a/lib_com/residu_fx.c
+++ b/lib_com/residu_fx.c
@@ -7,7 +7,6 @@
#include "cnst.h" /* Common constants */
#include "rom_com.h" /* Static table prototypes */
#include "prot_fx.h"
-#include "prot.h"
/*--------------------------------------------------------------------*
* residu_ivas_fx()
diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c
index bad47f0659a392b758428ff3284aad3228dee9d8..172dadf82da9d517192d902c04d101cc1f3c6453 100644
--- a/lib_com/rom_com.c
+++ b/lib_com/rom_com.c
@@ -38,10 +38,9 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "basop_util.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
/* clang-format off */
diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c
index 6116588846bb66eca53cc1f41ed7ef8870094cd3..49f50e1622ba4a26b851bc236695c6e4b472078d 100644
--- a/lib_com/rom_com_fx.c
+++ b/lib_com/rom_com_fx.c
@@ -38,7 +38,7 @@
EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
====================================================================================*/
-#include "prot.h"
+#include "prot_fx.h"
#include "basop_util.h"
#include "wmc_auto.h"
#include "rom_com_fx.h"
diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c
index 0028210502634f7a8a5c8d0acfa27686bcc81435..2ce2ffd12b8aad3cf41c48a53bfb7c253b1ee80b 100644
--- a/lib_com/scale_mem_fx.c
+++ b/lib_com/scale_mem_fx.c
@@ -307,8 +307,15 @@ void scale_sig32(
/* saturation can occur here */
x[i] = L_shl( x[i], exp0 );
move32();
+#ifdef OPT_STEREO_32KBPS_V1
+ if ( 0 == exp0 )
+ {
+ i = lg;
+ }
+#endif /* OPT_STEREO_32KBPS_V1 */
}
}
+
void scale_sig32_r(
Word32 x[], /* i/o: signal to scale Qx */
const Word16 lg, /* i : size of x[] Q0 */
@@ -322,6 +329,12 @@ void scale_sig32_r(
/* saturation can occur here */
x[i] = L_shl_r( x[i], exp0 );
move32();
+#ifdef OPT_STEREO_32KBPS_V1
+ if ( 0 == exp0 )
+ {
+ i = lg;
+ }
+#endif /* OPT_STEREO_32KBPS_V1 */
}
}
diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c
index 2aa781a43d661d9fe53b5f244aaf56229a056078..1f112c9110f1ac20abd5a854fd8ab0f1777042b1 100644
--- a/lib_com/swb_tbe_com.c
+++ b/lib_com/swb_tbe_com.c
@@ -38,7 +38,6 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c
index 6cdf1185ade75e8eeecc06865dbb904e990bcdbe..7e9471c45b04a77a33f67679e751f60168fc5a05 100644
--- a/lib_com/swb_tbe_com_fx.c
+++ b/lib_com/swb_tbe_com_fx.c
@@ -7,7 +7,6 @@
#include "options.h"
#include "cnst.h" /* Common constants */
#include "rom_com.h" /* Static table prototypes */
-#include "prot.h"
#include "prot_fx.h"
#include "basop_util.h"
#include "ivas_prot_fx.h"
diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c
index 6e0f7e716fe0805021cb84d32f99f69cb7af69a0..968cc8359120850e8eb2596ae92a9464a0694200 100644
--- a/lib_com/syn_filt_fx.c
+++ b/lib_com/syn_filt_fx.c
@@ -639,25 +639,7 @@ void synth_mem_updt2(
{
lerp( old_exc + L_EXC_MEM - last_L_frame, old_exc + L_EXC_MEM - L_frame, L_frame, last_L_frame );
}
-#ifdef ADD_LRTD
- IF( EQ_16( dec, DEC_IVAS ) )
- {
- IF( EQ_16( L_frame, L_FRAME16k ) )
- {
- /* find scaling factor */
- PME()
- en1 = 1.25f * sum2_f( mem_syn2, M );
- en2 = sum2_f( mem_syn_r + L_SYN_MEM - M, M );
- loc_rat = sqrtf( en2 ) / ( sqrtf( en1 ) + 0.01f );
- /* scale synthesis filter memory */
- FOR( i = 0; i < M; i++ )
- {
- mem_syn_r[L_SYN_MEM - M + i] *= loc_rat;
- }
- }
- }
-#endif
/*Resamp memory*/
/*Size of LPC syn memory*/
/* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */
diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c
index 55228e0b348b663d3d7c9eba8dd3408c9ef146b7..9d7cb9254a7f93061a7183406fb65853e8559889 100644
--- a/lib_com/tcx_ltp_fx.c
+++ b/lib_com/tcx_ltp_fx.c
@@ -1282,7 +1282,7 @@ void tcx_ltp_post(
filtIdx = 0; /* just to avoid comilation warnings */
move16();
- tcx_buf_len = NS2SA( st->output_Fs, TCXLTP_DELAY_NS ); /* Q0 */
+ tcx_buf_len = NS2SA_FX2( st->output_Fs, TCXLTP_DELAY_NS ); /* Q0 */
SideInfoOnly = 0;
move16();
if ( GE_32( total_brate, HQ_96k ) )
diff --git a/lib_com/tcx_mdct_window.c b/lib_com/tcx_mdct_window.c
index cececd8f5228da3cc6c000f11b8866edda7ae1dd..44ce806f73305390709b042c43728ab19ae3aab0 100644
--- a/lib_com/tcx_mdct_window.c
+++ b/lib_com/tcx_mdct_window.c
@@ -39,7 +39,6 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c
index 4e40e4ab2d30843044c2c715bb0624e7984d2e37..c5ff95e04e68c7904a93ddc7444440333131cded 100644
--- a/lib_com/tcx_utils_fx.c
+++ b/lib_com/tcx_utils_fx.c
@@ -9,7 +9,6 @@
#include "rom_com.h"
#include "rom_basop_util.h"
#include "basop_util.h"
-#include "prot.h"
#define inv_int InvIntTable
diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c
index 515746bd5fbd8cde2712c4300e049a7415ae96c9..101bc1df8b6552407c352786dc2e08dd79ec5ec0 100644
--- a/lib_com/tns_base.c
+++ b/lib_com/tns_base.c
@@ -12,7 +12,6 @@
#include "rom_com.h"
#include "prot_fx.h"
#include "basop_util.h"
-#include "prot.h"
/*----------------------------------------------------------------------------
* Local constants
diff --git a/lib_com/tools.c b/lib_com/tools.c
index 4d9f5e956e17d513f53624c4a71769e7de8dd443..e4ccd9955ff0ec12a935b289f98e151da54c2be2 100644
--- a/lib_com/tools.c
+++ b/lib_com/tools.c
@@ -37,7 +37,6 @@
#include
#include "options.h"
#include
-#include "prot.h"
#include "prot_fx.h"
#include "wmc_auto.h"
@@ -136,23 +135,6 @@ int16_t sum_s(
return tmp;
}
-/*! r: sum of all vector elements */
-int32_t sum_l(
- const int32_t *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-)
-{
- int16_t i;
- int32_t tmpL;
-
- tmpL = 0;
- for ( i = 0; i < lvec; i++ )
- {
- tmpL += vec[i];
- }
-
- return tmpL;
-}
/*! r: sum of all vector elements */
Word32 sum_l_fx(
const Word32 *vec, /* i : input vector */
@@ -171,23 +153,6 @@ Word32 sum_l_fx(
return tmpL;
}
-/*! r: sum of all vector elements */
-float sum_f(
- const float *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-)
-{
- int16_t i;
- float tmp;
-
- tmp = 0.0f;
- for ( i = 0; i < lvec; i++ )
- {
- tmp += vec[i];
- }
-
- return tmp;
-}
/*----------------------------------------------------------------------
* sum2_f()
@@ -228,22 +193,6 @@ Word32 sum2_f_16_gb_fx(
return tmp;
}
-float sum2_f(
- const float *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-)
-{
- int16_t i;
- float tmp;
-
- tmp = 0.0f;
- for ( i = 0; i < lvec; i++ )
- {
- tmp += vec[i] * vec[i];
- }
-
- return tmp;
-}
Word32 sum2_16_exp_fx(
const Word16 *vec, /* i : input vector Q(15 - exp) */
@@ -532,101 +481,6 @@ void mvs2s(
return;
}
-uint32_t mvr2s(
- const float x[], /* i : input vector */
- int16_t y[], /* o : output vector */
- const int16_t n /* i : vector size */
-)
-{
- int16_t i;
- float temp;
- uint32_t noClipping = 0;
-
- if ( n <= 0 )
- {
- /* cannot transfer vectors with size 0 */
- return 0;
- }
-
- if ( (void *) y <= (const void *) x )
- {
- for ( i = 0; i < n; i++ )
- {
- temp = x[i];
- temp = (float) floor( temp + 0.5f );
-
- if ( temp > MAX16B_FLT )
- {
- temp = MAX16B_FLT;
- noClipping++;
- }
- else if ( temp < MIN16B_FLT )
- {
- temp = MIN16B_FLT;
- noClipping++;
- }
-
- y[i] = (int16_t) temp;
- }
- }
- else
- {
- for ( i = n - 1; i >= 0; i-- )
- {
- temp = x[i];
- temp = (float) floor( temp + 0.5f );
-
- if ( temp > MAX16B_FLT )
- {
- temp = MAX16B_FLT;
- noClipping++;
- }
- else if ( temp < MIN16B_FLT )
- {
- temp = MIN16B_FLT;
- noClipping++;
- }
-
- y[i] = (int16_t) temp;
- }
- }
-
- return noClipping;
-}
-
-void mvs2r(
- const int16_t x[], /* i : input vector */
- float y[], /* o : output vector */
- const int16_t n /* i : vector size */
-)
-{
- int16_t i;
-
- if ( n <= 0 )
- {
- /* cannot transfer vectors with size 0 */
- return;
- }
-
- if ( (void *) y < (const void *) x )
- {
- for ( i = 0; i < n; i++ )
- {
- y[i] = (float) x[i];
- }
- }
- else
- {
- for ( i = n - 1; i >= 0; i-- )
- {
- y[i] = (float) x[i];
- }
- }
-
- return;
-}
-
-
void mvl2l(
const int32_t x[], /* i : input vector */
int32_t y[], /* o : output vector */
@@ -659,44 +513,6 @@ void mvl2l(
return;
}
-
-/*---------------------------------------------------------------------*
- * maximum()
- *
- * Find index and value of the maximum in a vector
- *---------------------------------------------------------------------*/
-
-/*! r: index of the maximum value in the input vector */
-int16_t maximum(
- const float *vec, /* i : input vector */
- const int16_t lvec, /* i : length of input vector */
- float *max_val /* o : maximum value in the input vector */
-)
-{
- int16_t j, ind;
- float tmp;
-
- ind = 0;
- tmp = vec[0];
-
- for ( j = 1; j < lvec; j++ )
- {
- if ( vec[j] > tmp )
- {
- ind = j;
- tmp = vec[j];
- }
- }
-
- if ( max_val != NULL )
- {
- *max_val = tmp;
- }
-
- return ind;
-}
-
-
/*! r: index of the maximum value in the input vector */
Word16 maximum_s(
const Word16 *vec, /* i : input vector */
@@ -766,42 +582,6 @@ Word16 maximum_l(
return ind;
}
-/*---------------------------------------------------------------------*
- * maximumAbs()
- *
- * Find index and value of the maximum in a vector
- *---------------------------------------------------------------------*/
-
-/*! r: index of the maximum value in the input vector */
-int16_t maximumAbs(
- const float *vec, /* i : input vector */
- const int16_t lvec, /* i : length of input vector */
- float *max_val /* o : maximum value in the input vector */
-)
-{
- int16_t j, ind;
- float tmp;
-
- ind = 0;
- tmp = (float) fabs( vec[0] );
-
- for ( j = 1; j < lvec; j++ )
- {
- if ( (float) fabs( vec[j] ) > tmp )
- {
- ind = j;
- tmp = (float) fabs( vec[j] );
- }
- }
-
- if ( max_val != NULL )
- {
- *max_val = tmp;
- }
-
- return ind;
-}
-
/*! r: index of the maximum value in the input vector */
Word16 maximumAbs_l(
const Word32 *vec, /* i : input vector */
@@ -835,42 +615,6 @@ Word16 maximumAbs_l(
return ind;
}
-/*---------------------------------------------------------------------*
- * minimum()
- *
- * Find index of a minimum in a vector
- *---------------------------------------------------------------------*/
-
-/*! r: index of the minimum value in the input vector */
-int16_t minimum(
- const float *vec, /* i : input vector */
- const int16_t lvec, /* i : length of input vector */
- float *min_val /* o : minimum value in the input vector */
-)
-{
- int16_t j, ind;
- float tmp;
-
- ind = 0;
- tmp = vec[0];
-
- for ( j = 1; j < lvec; j++ )
- {
- if ( vec[j] < tmp )
- {
- ind = j;
- tmp = vec[j];
- }
- }
-
- if ( min_val != NULL )
- {
- *min_val = tmp;
- }
-
- return ind;
-}
-
/*-------------------------------------------------------------------*
* minimum_s()
*
@@ -988,59 +732,6 @@ Word16 minimum_l(
return ind;
}
-/*---------------------------------------------------------------------*
- * emaximum()
- *
- * Find index of a maximum energy in a vector
- *---------------------------------------------------------------------*/
-
-/*! r: return index with max energy value in vector */
-int16_t emaximum(
- const float *vec, /* i : input vector */
- const int16_t lvec, /* i : length of input vector */
- float *ener_max /* o : maximum energy value */
-)
-{
- int16_t j, ind;
- float temp;
-
- *ener_max = 0.0f;
- ind = 0;
-
- for ( j = 0; j < lvec; j++ )
- {
- temp = vec[j] * vec[j];
-
- if ( temp > *ener_max )
- {
- ind = j;
- *ener_max = temp;
- }
- }
-
- return ind;
-}
-
-
-/*---------------------------------------------------------------------*
- * mean()
- *
- * Find the mean of the vector
- *---------------------------------------------------------------------*/
-
-/*! r: mean of vector */
-float mean(
- const float *vec, /* i : input vector */
- const int16_t lvec /* i : length of input vector */
-)
-{
- float tmp;
-
- tmp = sum_f( vec, lvec ) / (float) lvec;
-
- return tmp;
-}
-
/*---------------------------------------------------------------------*
* dotp()
*
@@ -1168,114 +859,6 @@ float inv_sqrt(
return (float) ( 1.0 / sqrt( x ) );
}
-
-/*-------------------------------------------------------------------*
- * conv()
- *
- * Convolution between vectors x[] and h[] written to y[]
- * All vectors are of length L. Only the first L samples of the
- * convolution are considered.
- *-------------------------------------------------------------------*/
-
-void conv(
- const float x[], /* i : input vector */
- const float h[], /* i : impulse response (or second input vector) */
- float y[], /* o : output vetor (result of convolution) */
- const int16_t L /* i : vector size */
-)
-{
- float temp;
- int16_t i, n;
- for ( n = 0; n < L; n++ )
- {
- temp = x[0] * h[n];
- for ( i = 1; i <= n; i++ )
- {
- temp += x[i] * h[n - i];
- }
- y[n] = temp;
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------*
- * fir()
- *
- * FIR filtering of vector x[] with filter having impulse response h[]
- * written to y[]
- * The input vector has length L and the FIR filter has an order of K, i.e.
- * K+1 coefficients. The memory of the input signal is provided in the vector mem[]
- * which has K values
- * The maximum length of the input signal is L_FRAME32k and the maximum order
- * of the FIR filter is L_FILT_MAX
- *-------------------------------------------------------------------*/
-
-void fir(
- const float x[], /* i : input vector */
- const float h[], /* i : impulse response of the FIR filter */
- float y[], /* o : output vector (result of filtering) */
- float mem[], /* i/o: memory of the input signal (L samples) */
- const int16_t L, /* i : input vector size */
- const int16_t K, /* i : order of the FIR filter (K+1 coefs.) */
- const int16_t upd /* i : 1 = update the memory, 0 = not */
-)
-{
- float buf_in[L_FRAME48k + 60], buf_out[L_FRAME48k], s;
- int16_t i, j;
-
- /* prepare the input buffer (copy and update memory) */
- mvr2r( mem, buf_in, K );
- mvr2r( x, buf_in + K, L );
-
- if ( upd )
- {
- mvr2r( buf_in + L, mem, K );
- }
-
- /* do the filtering */
- for ( i = 0; i < L; i++ )
- {
- s = buf_in[K + i] * h[0];
-
- for ( j = 1; j <= K; j++ )
- {
- s += h[j] * buf_in[K + i - j];
- }
-
- buf_out[i] = s;
- }
-
- /* copy to the output buffer */
- mvr2r( buf_out, y, L );
-
- return;
-}
-
-/*-------------------------------------------------------------------*
- * v_add()
- *
- * Addition of two vectors sample by sample
- *-------------------------------------------------------------------*/
-
-void v_add(
- const float x1[], /* i : Input vector 1 */
- const float x2[], /* i : Input vector 2 */
- float y[], /* o : Output vector that contains vector 1 + vector 2 */
- const int16_t N /* i : Vector length */
-)
-{
- int16_t i;
-
- for ( i = 0; i < N; i++ )
- {
- y[i] = x1[i] + x2[i];
- }
-
- return;
-}
-
-
/*-------------------------------------------------------------------*
* v_add_w64()
*
@@ -1351,55 +934,9 @@ void v_sub_fixed(
}
/*-------------------------------------------------------------------*
- * v_mult()
+ * v_multc_fixed()
*
- * Multiplication of two vectors
- *-------------------------------------------------------------------*/
-
-void v_mult(
- const float x1[], /* i : Input vector 1 */
- const float x2[], /* i : Input vector 2 */
- float y[], /* o : Output vector that contains vector 1 .* vector 2 */
- const int16_t N /* i : Vector length */
-)
-{
- int16_t i;
-
- for ( i = 0; i < N; i++ )
- {
- y[i] = x1[i] * x2[i];
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------*
- * v_multc()
- *
- * Multiplication of vector by constant
- *-------------------------------------------------------------------*/
-
-void v_multc(
- const float x[], /* i : Input vector */
- const float c, /* i : Constant */
- float y[], /* o : Output vector that contains c*x */
- const int16_t N /* i : Vector length */
-)
-{
- int16_t i;
-
- for ( i = 0; i < N; i++ )
- {
- y[i] = c * x[i];
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------*
- * v_multc_fixed()
- *
- * Multiplication of vector by constant
+ * Multiplication of vector by constant
*-------------------------------------------------------------------*/
void v_multc_fixed(
@@ -1456,102 +993,6 @@ void v_multc_fixed_16_16(
return;
}
-/*-------------------------------------------------------------------*
- * squant()
- *
- * Scalar quantizer according to MMSE criterion (nearest neighbour in Euclidean space)
- *
- * Searches a given codebook to find the nearest neighbour in Euclidean space.
- * Index of the winning codeword and the winning codeword itself are returned.
- *-------------------------------------------------------------------*/
-
-/*! r: index of the winning codeword */
-int16_t squant(
- const float x, /* i : scalar value to quantize */
- float *xq, /* o : quantized value */
- const float cb[], /* i : codebook */
- const int16_t cbsize /* i : codebook size */
-)
-{
- float dist, mindist, tmp;
- int16_t c, idx;
-
- idx = 0;
- mindist = 1e16f;
-
- for ( c = 0; c < cbsize; c++ )
- {
- dist = 0.0f;
- tmp = x - cb[c];
- dist += tmp * tmp;
- if ( dist < mindist )
- {
- mindist = dist;
- idx = c;
- }
- }
-
- *xq = cb[idx];
-
- return idx;
-}
-
-/*! r: index of the winning codeword */
-int16_t squant_int(
- uint8_t x, /* i : scalar value to quantize */
- uint8_t *xq, /* o : quantized value */
- const uint8_t *cb, /* i : codebook */
- const int16_t cbsize /* i : codebook size */
-)
-{
- int16_t i, idx;
- float mindist, d;
-
- idx = 0;
- mindist = 10000000.0f;
- for ( i = 0; i < cbsize; i++ )
- {
- d = (float) ( x - cb[i] ) * ( x - cb[i] );
- if ( d < mindist )
- {
- mindist = d;
- idx = i;
- }
- }
- *xq = cb[idx];
-
- return idx;
-}
-
-
-/*-------------------------------------------------------------------*
- * usquant()
- *
- * Uniform scalar quantizer according to MMSE criterion
- * (nearest neighbour in Euclidean space)
- *
- * Applies quantization based on scale and round operations.
- * Index of the winning codeword and the winning codeword itself are returned.
- *-------------------------------------------------------------------*/
-
-/*! r: index of the winning codeword */
-int16_t usquant(
- const float x, /* i : scalar value to quantize */
- float *xq, /* o : quantized value */
- const float qlow, /* i : lowest codebook entry (index 0) */
- const float delta, /* i : quantization step */
- const int16_t cbsize /* i : codebook size */
-)
-{
- int16_t idx;
-
- idx = (int16_t) max( 0.f, min( cbsize - 1, ( ( x - qlow ) / delta + 0.5f ) ) );
- *xq = idx * delta + qlow;
-
- return idx;
-}
-
-
/*-------------------------------------------------------------------*
* usdequant()
*
@@ -1573,219 +1014,6 @@ float usdequant(
return ( g );
}
-
-/*-------------------------------------------------------------------*
- * vquant()
- *
- * Vector quantizer according to MMSE criterion (nearest neighbour in Euclidean space)
- *
- * Searches a given codebook to find the nearest neighbour in Euclidean space.
- * Index of the winning codevector and the winning vector itself are returned.
- *-------------------------------------------------------------------*/
-
-/*! r: index of the winning codevector */
-int16_t vquant(
- float x[], /* i : vector to quantize */
- const float x_mean[], /* i : vector mean to subtract (0 if none) */
- float xq[], /* o : quantized vector */
- const float cb[], /* i : codebook */
- const int16_t dim, /* i : dimension of codebook vectors */
- const int16_t cbsize /* i : codebook size */
-)
-{
- float dist, mindist, tmp;
- int16_t c, d, idx, j;
-
- idx = 0;
- mindist = 1e16f;
-
- if ( x_mean != 0 )
- {
- for ( d = 0; d < dim; d++ )
- {
- x[d] -= x_mean[d];
- }
- }
-
- j = 0;
- for ( c = 0; c < cbsize; c++ )
- {
- dist = 0.0f;
- for ( d = 0; d < dim; d++ )
- {
- tmp = x[d] - cb[j++];
- dist += tmp * tmp;
- }
-
- if ( dist < mindist )
- {
- mindist = dist;
- idx = c;
- }
- }
-
- if ( xq == 0 )
- {
- return idx;
- }
-
- j = idx * dim;
- for ( d = 0; d < dim; d++ )
- {
- xq[d] = cb[j++];
- }
-
- if ( x_mean != 0 )
- {
- for ( d = 0; d < dim; d++ )
- {
- xq[d] += x_mean[d];
- }
- }
-
- return idx;
-}
-
-/*-------------------------------------------------------------------*
- * w_vquant()
- *
- * Vector quantizer according to MMSE criterion (nearest neighbour in Euclidean space)
- *
- * Searches a given codebook to find the nearest neighbour in Euclidean space.
- * Weights are put on the error for each vector element.
- * Index of the winning codevector and the winning vector itself are returned.
- *-------------------------------------------------------------------*/
-
-/*! r: index of the winning codevector */
-int16_t w_vquant(
- float x[], /* i : vector to quantize */
- const float x_mean[], /* i : vector mean to subtract (0 if none) */
- const int16_t weights[], /* i : error weights */
- float xq[], /* o : quantized vector */
- const float cb[], /* i : codebook */
- const int16_t dim, /* i : dimension of codebook vectors */
- const int16_t cbsize, /* i : codebook size */
- const int16_t rev_vect /* i : reverse codebook vectors */
-)
-{
- float dist, mindist, tmp;
- int16_t c, d, idx, j, k;
-
- idx = 0;
- mindist = 1e16f;
-
- if ( x_mean != 0 )
- {
- for ( d = 0; d < dim; d++ )
- {
- x[d] -= x_mean[d];
- }
- }
-
- j = 0;
- if ( rev_vect )
- {
- k = dim - 1;
- for ( c = 0; c < cbsize; c++ )
- {
- dist = 0.0f;
-
- for ( d = k; d >= 0; d-- )
- {
- tmp = x[d] - cb[j++];
- dist += weights[d] * ( tmp * tmp );
- }
-
- if ( dist < mindist )
- {
- mindist = dist;
- idx = c;
- }
- }
-
- if ( xq == 0 )
- {
- return idx;
- }
-
- j = idx * dim;
- for ( d = k; d >= 0; d-- )
- {
- xq[d] = cb[j++];
- }
- }
- else
- {
- for ( c = 0; c < cbsize; c++ )
- {
- dist = 0.0f;
-
- for ( d = 0; d < dim; d++ )
- {
- tmp = x[d] - cb[j++];
- dist += weights[d] * ( tmp * tmp );
- }
-
- if ( dist < mindist )
- {
- mindist = dist;
- idx = c;
- }
- }
-
- if ( xq == 0 )
- {
- return idx;
- }
-
- j = idx * dim;
- for ( d = 0; d < dim; d++ )
- {
- xq[d] = cb[j++];
- }
- }
-
- if ( x_mean != 0 )
- {
- for ( d = 0; d < dim; d++ )
- {
- xq[d] += x_mean[d];
- }
- }
-
- return idx;
-}
-
-
-/*----------------------------------------------------------------------------------*
- * v_sort()
- *
- * Sorting of vectors. This is very fast with almost ordered vectors.
- *----------------------------------------------------------------------------------*/
-
-void v_sort_float(
- float *r, /* i/o: Vector to be sorted in place */
- const int16_t lo, /* i : Low limit of sorting range */
- const int16_t up /* I : High limit of sorting range */
-)
-{
- int16_t i, j;
- float tempr;
-
- for ( i = up - 1; i >= lo; i-- )
- {
- tempr = r[i];
- for ( j = i + 1; j <= up && ( tempr > r[j] ); j++ )
- {
- r[j - 1] = r[j];
- }
-
- r[j - 1] = tempr;
- }
-
- return;
-}
-
void sort(
UWord16 *x, /* i/o: Vector to be sorted */
UWord16 len /* i/o: vector length */
@@ -1810,426 +1038,3 @@ void sort(
return;
}
-
-/*---------------------------------------------------------------------*
- * var()
- *
- * Calculate the variance of a vector
- *---------------------------------------------------------------------*/
-
-/*! r: variance of vector */
-float var(
- const float *x, /* i : input vector */
- const int16_t len /* i : length of inputvector */
-)
-{
- float m;
- float v;
- int16_t i;
-
- m = mean( x, len );
-
- v = 0.0f;
- for ( i = 0; i < len; i++ )
- {
- v += ( x[i] - m ) * ( x[i] - m );
- }
- v /= len;
-
- return v;
-}
-
-
-/*---------------------------------------------------------------------*
- * std_dev()
- *
- * Calculate the standard deviation of a vector
- *---------------------------------------------------------------------*/
-
-/*! r: standard deviation */
-float std_dev(
- const float *x, /* i : input vector */
- const int16_t len /* i : length of the input vector */
-)
-{
- int16_t i;
- float std;
-
- std = 1e-16f;
- for ( i = 0; i < len; i++ )
- {
- std += x[i] * x[i];
- }
-
- std = (float) sqrt( std / len );
-
- return std;
-}
-
-
-/*---------------------------------------------------------------------*
- * dot_product_mat()
- *
- * Calculates dot product of type x'*A*x, where x is column vector of size m,
- * and A is square matrix of size m*m
- *---------------------------------------------------------------------*/
-
-/*! r: the dot product x'*A*x */
-float dot_product_mat(
- const float *x, /* i : vector x */
- const float *A, /* i : matrix A */
- const int16_t m /* i : vector & matrix size */
-)
-{
- int16_t i, j;
- float suma, tmp_sum;
- const float *pt_x, *pt_A;
-
- pt_A = A;
- suma = 0;
-
- for ( i = 0; i < m; i++ )
- {
- tmp_sum = 0;
- pt_x = x;
- for ( j = 0; j < m; j++ )
- {
- tmp_sum += *pt_x++ * *pt_A++;
- }
-
- suma += x[i] * tmp_sum;
- }
-
- return suma;
-}
-
-
-/*--------------------------------------------------------------------------------*
- * polezero_filter()
- *
- * Y(Z)=X(Z)(b[0]+b[1]z^(-1)+..+b[L]z^(-L))/(a[0]+a[1]z^(-1)+..+a[M]z^(-M))
- * mem[n]=x[n]+cp[0]mem[n-1]+..+cp[M-1]mem[n-M], where cp[i]=-a[i+1]/a[0]
- * y[n]=cz[0]mem[n]+cz[1]mem[n-1]+..+cz[L]mem[n-L], where cz[i]=b[i]/a[0]
- * mem={mem[n-K] mem[n-K+1] . . . . mem[n-2] mem[n-1]}, where K=max(L,M)
- *
- * a[0] must be equal to 1.0f!
- *---------------------------------------------------------------------------------*/
-
-void polezero_filter(
- const float *in, /* i : input vector */
- float *out, /* o : output vector */
- const int16_t N, /* i : input vector size */
- const float *b, /* i : numerator coefficients */
- const float *a, /* i : denominator coefficients */
- const int16_t order, /* i : filter order */
- float *mem /* i/o: filter memory */
-)
-{
- int16_t i, j, k;
-
-
- for ( i = 0; i < order; i++ )
- {
- out[i] = in[i] * b[0];
- for ( j = 0; j < i; j++ )
- {
- out[i] += in[i - 1 - j] * b[j + 1] - out[i - 1 - j] * a[j + 1];
- }
-
- for ( k = order - 1; j < order; j++, k-- )
- {
- out[i] += mem[k] * b[j + 1] - mem[k + order] * a[j + 1];
- }
- }
-
- for ( ; i < N; i++ )
- {
- out[i] = in[i] * b[0];
- for ( j = 0; j < order; j++ )
- {
- out[i] += in[i - 1 - j] * b[j + 1] - out[i - 1 - j] * a[j + 1];
- }
- }
-
- for ( i = 0; i < order; i++ )
- {
- mem[i] = in[N - order + i];
- mem[i + order] = out[N - order + i];
- }
-
- return;
-}
-
-#define WMC_TOOL_SKIP
-static float fleft_shift( float input, const int16_t shift )
-{
- return ( input * (float) pow( 2.0, (double) shift ) );
-}
-
-static float fright_shift( float input, const int16_t shift )
-{
- return ( input * (float) pow( 0.5, (double) shift ) );
-}
-#undef WMC_TOOL_SKIP
-
-
-/*--------------------------------------------------------------------------------*
- * root_a()
- *
- * Implements a quadratic approximation to sqrt(a)
- * Firstly, a is normalized to lie between 0.25 & 1.0
- * by shifting the input left or right by an even number of
- * shifts. Even shifts represent powers of 4 which, after
- * the sqrt, can easily be converted to powers of 2 and are
- * easily dealt with.
- * At the heart of the algorithm is a quadratic
- * approximation of the curve sqrt(a) for 0.25 <= a <= 1.0.
- * Sqrt(a) approx = 0.27 + 1.0127 * a - 0.2864 * a^2
- *
- *---------------------------------------------------------------------------------*/
-
-float root_a(
- float a )
-{
- int16_t shift_a;
- float mod_a;
- float approx;
-
- if ( a <= 0.0f )
- {
- return 0.0;
- }
-
-#define WMC_TOOL_SKIP
- /* This next piece of code implements a "norm" function */
- /* and returns the shift needed to scale "a" to have a */
- /* 1 in the (MSB-1) position. This is equivalent to */
- /* giving a value between 0.5 & 1.0. */
- mod_a = a;
-
- shift_a = 0;
- while ( mod_a > 1.0 )
- {
- mod_a /= 2.0;
- shift_a--;
- }
-
- while ( mod_a < 0.5 )
- {
- mod_a *= 2.0;
- shift_a++;
- }
-#undef WMC_TOOL_SKIP
-
- shift_a &= 0xfffe;
- mod_a = fleft_shift( a, shift_a );
-
- approx = 0.27f + 1.0127f * mod_a - 0.2864f * mod_a * mod_a;
-
- approx = fright_shift( approx, ( shift_a >> 1 ) );
-
- return ( approx );
-}
-
-/*--------------------------------------------------------------------------------*
- * root_a_over_b()
- *
- * Implements an approximation to sqrt(a/b)
- * Firstly a & b are normalized to lie between 0.25 & 1.0
- * by shifting the inputs left or right by an even number
- * of shifts.
- * Even shifts represent powers of 4 which, after the sqrt,
- * become powers of 2 and are easily dealt with.
- * At the heart of the algorithm is an approximation of the
- * curve sqrt(a/b) for 0.25 <= a <= 1.0 & 0.25 <= b <= 1.0.
- * Given the value of b, the 2nd order coefficients p0, p1
- * & p2 can be determined so that...
- * Sqrt(a/b) approx = p0 + p1 * a + p2 * a^2
- * where p0 approx = 0.7176 - 0.8815 * b + 0.4429 * b^2
- * p1 approx = 2.6908 - 3.3056 * b + 1.6608 * b^2
- * p2 approx = -0.7609 + 0.9346 * b - 0.4695 * b^2
- *
- *---------------------------------------------------------------------------------*/
-
-float root_a_over_b(
- float a,
- float b )
-{
- int16_t shift_a, shift_b, shift;
- float mod_a, mod_b;
- float p2 = -0.7609f;
- float p1 = 2.6908f;
- float p0 = 0.7176f;
- float b_sqr;
- float approx;
-
- if ( ( a <= 0.0f ) || ( b <= 0.0f ) )
- {
- return 0.0;
- }
-#define WMC_TOOL_SKIP
- if ( isinf( a ) )
-#undef WMC_TOOL_SKIP
- {
- return FLT_MAX;
- }
-#define WMC_TOOL_SKIP
- if ( isinf( b ) )
-#undef WMC_TOOL_SKIP
- {
- return 0.f;
- }
-
- a += 0x00000001;
- b += 0x00000001;
-
-#define WMC_TOOL_SKIP
- /* This next piece of code implements a "norm" function */
- /* and returns the shift needed to scale "a" to have a */
- /* 1 in the (MSB-1) position. This is equivalent to */
- /* giving a value between 0.5 & 1.0. */
- mod_a = a;
-
- shift_a = 0;
- while ( mod_a > 1.0 )
- {
- mod_a /= 2.0;
- shift_a--;
- }
-
- while ( mod_a < 0.5 )
- {
- mod_a *= 2.0;
- shift_a++;
- }
-#undef WMC_TOOL_SKIP
-
- shift_a &= 0xfffe;
- mod_a = fleft_shift( a, shift_a );
-
-#define WMC_TOOL_SKIP
- /* This next piece of code implements a "norm" function */
- /* and returns the shift needed to scale "b" to have a */
- /* 1 in the (MSB-1) position. This is equivalent to */
- /* giving a value between 0.5 & 1.0. */
- mod_b = b;
-
- shift_b = 0;
- while ( mod_b > 1.0 )
- {
- mod_b /= 2.0;
- shift_b--;
- }
-
- while ( mod_b < 0.5 )
- {
- mod_b *= 2.0;
- shift_b++;
- }
-#undef WMC_TOOL_SKIP
-
- shift_b &= 0xfffe;
- mod_b = fleft_shift( b, shift_b );
-
- shift = ( shift_b - shift_a ) >> 1;
-
- b_sqr = mod_b * mod_b;
-
- p2 += 0.9346f * mod_b + -0.4695f * b_sqr;
- p1 += -3.3056f * mod_b + 1.6608f * b_sqr;
- p0 += -0.8815f * mod_b + 0.4429f * b_sqr;
-
- approx = p0 + p1 * mod_a + p2 * mod_a * mod_a;
-
- approx = fleft_shift( approx, shift );
-
- return ( approx );
-}
-
-/*--------------------------------------------------------------------------------*
- * rint_new()
- *
- * Round to the nearest integer with mid-point exception
- *---------------------------------------------------------------------------------*/
-
-double rint_new(
- double x )
-{
- int16_t a;
-
- /* middle value point test */
- if ( ceil( x + 0.5 ) == floor( x + 0.5 ) )
- {
- a = (int16_t) ceil( x );
-
- if ( a % 2 == 0 )
- {
- return ceil( x );
- }
- else
- {
- return floor( x );
- }
- }
- else
- {
- return floor( x + 0.5 );
- }
-}
-
-
-/*-------------------------------------------------------------------*
- * anint()
- *
- * Round to the nearest integer.
- *-------------------------------------------------------------------*/
-
-double anint(
- double x )
-{
- return ( x ) >= 0 ? (int32_t) ( ( x ) + 0.5 ) : (int32_t) ( (x) -0.5 );
-}
-
-/*-------------------------------------------------------------------*
- * is_numeric_float()
- *
- * Returns 0 for all NaN and Inf values defined according to IEEE 754
- * floating point number's definition. Returns 1 for numeric values.
- *-------------------------------------------------------------------*/
-
-int16_t is_numeric_float(
- float x )
-{
- union float_int
- {
- float float_val;
- int32_t int_val;
- } float_int;
-
- float_int.float_val = x;
-
- return ( ( float_int.int_val & 0x7f800000 ) != 0x7f800000 );
-}
-
-/*-------------------------------------------------------------------*
- * delay_signal_float()
- *
- * Delay buffer by defined number of samples
- *-------------------------------------------------------------------*/
-
-void delay_signal_float(
- float x[], /* i/o: signal to be delayed */
- const int16_t len, /* i : length of the input signal */
- float mem[], /* i/o: synchronization memory */
- const int16_t delay /* i : delay in samples */
-)
-{
- float tmp_buffer[L_FRAME48k];
-
- mvr2r( mem, tmp_buffer, delay );
- mvr2r( x + len - delay, mem, delay );
- mvr2r( x, x + delay, len - delay );
- mvr2r( tmp_buffer, x, delay );
-
- return;
-}
diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c
index 1e23ea44927a5d57157ba6cc1460e6686847ae60..6f46fdfa3c3ecce8ba76d364ee0eb226a49c2b90 100644
--- a/lib_com/tools_fx.c
+++ b/lib_com/tools_fx.c
@@ -50,7 +50,6 @@
#include "basop32.h"
#include "wmc_auto.h"
#include "prot_fx_enc.h"
-#include "prot.h"
#include "ivas_prot_fx.h"
#define INV_BANDS10 3277 /* 1/10 in Q15 */
diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c
index fbe0f0d6ddd6910eabb38ed912be67dad0d819a3..0033e2c9e5d37a44f7ca4989d041c25881c5d0af 100644
--- a/lib_com/trans_inv_fx.c
+++ b/lib_com/trans_inv_fx.c
@@ -84,7 +84,9 @@ void preecho_sb_fx(
UWord16 tmp_u16;
Word32 mean_prev_hb_fx_loc, mean_prev_nc_fx_loc, mean_prev_fx_loc; /* */
Word16 q16p1, qmemp1, qtmp;
-
+#ifdef OPT_STEREO_32KBPS_V1
+ Word16 shift_q = sub( 15, q_sig32 );
+#endif /* OPT_STEREO_32KBPS_V1 */
q16p1 = add( q_sig16, 1 );
qmemp1 = q16p1;
@@ -137,6 +139,18 @@ void preecho_sb_fx(
/* len3xLp20 = framelength/2-(short)((float)framelength*N_ZERO_MDCT/FRAME_SIZE_MS); in float*/
fxptr1 = imdct_mem_fx;
+#ifdef OPT_STEREO_32KBPS_V1
+ FOR( i = 0; i < len3xLp20; i++ )
+ {
+ *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[len3xLp20 - 1 - i], shift_q ) ) ); /*Q-1*/
+ move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */
+ }
+ FOR( i = 0; i < framelength >> 1; i++ )
+ {
+ *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], shift_q ) ) ); /*Q-1*/
+ move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */
+ }
+#else /* OPT_STEREO_32KBPS_V1 */
fx32ptr1 = wtda_audio_fx + len3xLp20 - 1; /*q_sig32*/
FOR( i = 0; i < len3xLp20; i++ )
{
@@ -148,7 +162,10 @@ void preecho_sb_fx(
*fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], sub( 15, q_sig32 ) ) ) ); /*Q-1*/
move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */
}
+#endif /* OPT_STEREO_32KBPS_V1 */
+
qmemp1 = 0; /*already in q-1*/
+ move16();
subframelength = shr( framelength, LOG2_NUMSF ); /*Q0*/
subsubframelength = shr( subframelength, log2_num_subsubframes ); /*Q0*/
@@ -391,6 +408,17 @@ void preecho_sb_fx(
move16();
FOR( i = 1; i <= NUMSF; i++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ max_es_hb_fx = L_max( max_es_hb_fx, es_mdct_hb_fx[i] ); /* max energy low band, 8 present and 1 future subframes */
+
+ max_es_fx = L_max( max_es_fx, es_mdct_fx[i] ); /* max energy low band, 8 present and 1 future subframes */
+
+ if ( GE_32( es_mdct_fx[i], max_es_fx ) ) /* '=' to handle the first window*/
+ {
+ maxind = i;
+ move16();
+ }
+#else /* OPT_STEREO_32KBPS_V1 */
IF( GE_32( es_mdct_hb_fx[i], max_es_hb_fx ) ) /* '=' to handle the first window*/
{
max_es_hb_fx = L_add( es_mdct_hb_fx[i], 0 ); /* max energy low band, 8 present and 1 future subframes */
@@ -402,6 +430,7 @@ void preecho_sb_fx(
maxind = i;
move16();
}
+#endif /* OPT_STEREO_32KBPS_V1 */
}
cnt2 = cnt5 = 0;
diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c
index 19725735ae1d549aecbf4640c6f70f9747a88525..2948e725ecdb0ca7d1add2a05b91500c4b2b8aaa 100644
--- a/lib_com/window_ola_fx.c
+++ b/lib_com/window_ola_fx.c
@@ -833,13 +833,13 @@ void core_switching_OLA_fx(
IF( ( output_frame - L_FRAME16k ) == 0 ) /* no resampling */
{
- Copy( mem_over_hp + 2, tmp_buf_switch + i_mult2( SWITCH_GAP_LENGTH_8k, delta ), NS2SA( output_Fs, DELAY_CLDFB_NS ) );
+ Copy( mem_over_hp + 2, tmp_buf_switch + i_mult2( SWITCH_GAP_LENGTH_8k, delta ), NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ) );
}
ELSE
{
IF( ( output_frame - L_FRAME8k ) == 0 ) /* not done yet */
{
- Copy( synth_subfr_out + SWITCH_GAP_LENGTH_8k, tmp_buf_switch + SWITCH_GAP_LENGTH_8k, NS2SA( output_Fs, DELAY_CLDFB_NS ) ); /* copy subframe to tmp buffer */
+ Copy( synth_subfr_out + SWITCH_GAP_LENGTH_8k, tmp_buf_switch + SWITCH_GAP_LENGTH_8k, NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ) ); /* copy subframe to tmp buffer */
}
ELSE
{
@@ -950,7 +950,7 @@ void core_switching_OLA_fx(
pt = synth;
pt2 = tmp_buf_switch;
- tmp = NS2SA( output_Fs, DELAY_CLDFB_NS );
+ tmp = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS );
move16();
pt3 = synth_subfr_bwe;
diff --git a/lib_com/wtda.c b/lib_com/wtda.c
index a7ea5314c916b07875136020956b2a30358d72ad..3fb40813816c7b4462bdcc3ec82b8df2314fb845 100644
--- a/lib_com/wtda.c
+++ b/lib_com/wtda.c
@@ -37,11 +37,10 @@
#include
#include "options.h"
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include
#include "wmc_auto.h"
-#include "prot_fx.h"
void wtda_fx32(
diff --git a/lib_dec/FEC_HQ_core.c b/lib_dec/FEC_HQ_core.c
deleted file mode 100644
index 6a119b365552212f9ae48f4a3e4c760f9d226dac..0000000000000000000000000000000000000000
--- a/lib_dec/FEC_HQ_core.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "rom_dec.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-
-void save_synthesis_hq_fec_fx(
- Decoder_State *st, /* i/o: decoder state structure */
- const Word32 output_fx[], /* i : decoded synthesis */
- const Word16 output_frame, /* i : decoded synthesis */
- CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */
-)
-{
- Word16 post_hq_delay;
-
- SWITCH( st->element_mode )
- {
- case EVS_MONO:
- post_hq_delay = NS2SA_FX2( st->output_Fs, POST_HQ_DELAY_NS );
- BREAK;
- case IVAS_SCE:
- post_hq_delay = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS );
- BREAK;
- case IVAS_CPE_DFT:
- test();
- IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF )
- {
- post_hq_delay = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS );
- }
- ELSE
- {
- post_hq_delay = 0;
- move16();
- }
- BREAK;
- default:
- post_hq_delay = 0;
- move16();
- BREAK;
- }
-
- test();
- test();
- test();
- test();
- test();
- IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) )
- {
- Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ) );
- FOR( Word16 i = 0; i < output_frame; i++ )
- {
- st->hTcxDec->old_synthFB_fx[( ( i + output_frame ) - post_hq_delay )] = extract_h( L_shl_sat( output_fx[i], 16 ) ); // Q16
- move16();
- }
-
- IF( st->element_mode == EVS_MONO )
- {
- /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill
- this buffer are not available for all cases, the impact on the output is limited */
-
- set16_fx( st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), 0, post_hq_delay );
- IF( GE_16( output_frame, L_FRAME16k ) )
- {
- Copy( st->prev_synth_buffer_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
- }
- ELSE
- {
- Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
- }
-
- IF( st->core != ACELP_CORE )
- {
- IF( GE_16( output_frame, L_FRAME16k ) )
- {
- Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) );
- Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
- }
- ELSE
- {
- Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) );
- Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
- }
- }
- }
- ELSE
- {
- IF( st->core != ACELP_CORE )
- {
- Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), post_hq_delay );
- Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
- }
- }
- }
- return;
-}
diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c
index f88927ee50f3d5ee6c7d6a412805ee7e9fe9151e..09bc652be8b7cfbb370f18938ca0ac32632bcb56 100644
--- a/lib_dec/FEC_HQ_core_fx.c
+++ b/lib_dec/FEC_HQ_core_fx.c
@@ -1961,6 +1961,98 @@ static void Next_good_after_burst_erasures_fx(
return;
}
+
+void save_synthesis_hq_fec_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const Word32 output_fx[], /* i : decoded synthesis */
+ const Word16 output_frame, /* i : decoded synthesis */
+ CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */
+)
+{
+ Word16 post_hq_delay;
+
+ SWITCH( st->element_mode )
+ {
+ case EVS_MONO:
+ post_hq_delay = NS2SA_FX2( st->output_Fs, POST_HQ_DELAY_NS );
+ BREAK;
+ case IVAS_SCE:
+ post_hq_delay = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS );
+ BREAK;
+ case IVAS_CPE_DFT:
+ test();
+ IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF )
+ {
+ post_hq_delay = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS );
+ }
+ ELSE
+ {
+ post_hq_delay = 0;
+ move16();
+ }
+ BREAK;
+ default:
+ post_hq_delay = 0;
+ move16();
+ BREAK;
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) )
+ {
+ Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ) );
+ FOR( Word16 i = 0; i < output_frame; i++ )
+ {
+ st->hTcxDec->old_synthFB_fx[( ( i + output_frame ) - post_hq_delay )] = extract_h( L_shl_sat( output_fx[i], 16 ) ); // Q16
+ move16();
+ }
+
+ IF( st->element_mode == EVS_MONO )
+ {
+ /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill
+ this buffer are not available for all cases, the impact on the output is limited */
+
+ set16_fx( st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), 0, post_hq_delay );
+ IF( GE_16( output_frame, L_FRAME16k ) )
+ {
+ Copy( st->prev_synth_buffer_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
+ }
+ ELSE
+ {
+ Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
+ }
+
+ IF( st->core != ACELP_CORE )
+ {
+ IF( GE_16( output_frame, L_FRAME16k ) )
+ {
+ Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) );
+ Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
+ }
+ ELSE
+ {
+ Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) );
+ Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
+ }
+ }
+ }
+ ELSE
+ {
+ IF( st->core != ACELP_CORE )
+ {
+ Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), post_hq_delay );
+ Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
+ }
+ }
+ }
+ return;
+}
+
+
#ifdef ADD_IVAS_HQ_CODE_FEC
/*--------------------------------------------------------------------------
* save_synthesis_hq_fec()
diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c
index 708fc39e6544f87830590ccc9a2c584121938d50..34d01d7fe0ea41b37e77e9096bfc0ebedb3f5128 100644
--- a/lib_dec/FEC_HQ_phase_ecu_fx.c
+++ b/lib_dec/FEC_HQ_phase_ecu_fx.c
@@ -2156,7 +2156,7 @@ static void ivas_subst_spec_fx(
ELSE
{
// tmp = NS2SA(output_frame*50,PH_ECU_ALDO_OLP2_NS-PH_ECU_LOOKAHEAD_NS);
- tmp = NS2SA_FX2( output_frame * 50, PH_ECU_ALDO_OLP2_NS );
+ tmp = NS2SA_FX2( L_mult0( output_frame, 50 ), PH_ECU_ALDO_OLP2_NS );
move16();
tmp = sub( tmp, ph_ecu_lookahead );
tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) );
@@ -2559,7 +2559,7 @@ static void subst_spec_fx(
}
ELSE
{
- tmp = NS2SA( output_frame * 50, PH_ECU_ALDO_OLP2_NS - PH_ECU_LOOKAHEAD_NS );
+ tmp = NS2SA_FX2( L_mult0( output_frame, 50 ), PH_ECU_ALDO_OLP2_NS - PH_ECU_LOOKAHEAD_NS );
move16();
tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) );
tmp = sub( tmp, shr( output_frame, 1 ) );
@@ -2920,9 +2920,9 @@ static void ivas_rec_wtda_fx(
Word16 copy_len;
Word16 ola_len;
- copy_len = NS2SA( output_frame * FRAMES_PER_SEC, ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* prototype fill on each side of xsubst to fill MDCT Frame */
+ copy_len = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* prototype fill on each side of xsubst to fill MDCT Frame */
move16();
- ola_len = NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* remaining lengt of LA_ZEROS to overlap add decoded with xsubst */
+ ola_len = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* remaining lengt of LA_ZEROS to overlap add decoded with xsubst */
move16();
xf_len = 26;
@@ -2980,7 +2980,7 @@ static void ivas_rec_wtda_fx(
}
/* extract reconstructed frame with aldo window */
- timesh = sub( NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ), shr( sub( shl( output_frame, 1 ), Lprot ), 1 ) );
+ timesh = sub( NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ), shr( sub( shl( output_frame, 1 ), Lprot ), 1 ) );
set16_fx( xsubst_, 0, add( sub( shl( output_frame, 1 ), Lprot ), timesh ) );
Copy( X, xsubst_ + add( sub( shl( output_frame, 1 ), Lprot ), timesh ), sub( Lprot, timesh ) );
@@ -2988,9 +2988,9 @@ static void ivas_rec_wtda_fx(
/* Copy and OLA look ahead zero part of MDCT window from decoded signal */
IF( element_mode != EVS_MONO )
{
- Copy( old_dec, xsubst_ + NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ), copy_len ); /* also need to scale to Q0 ?? */
+ Copy( old_dec, xsubst_ + NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ), copy_len ); /* also need to scale to Q0 ?? */
pOld = old_dec + copy_len;
- pNew = xsubst_ + add( copy_len, NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ) );
+ pNew = xsubst_ + add( copy_len, NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ) );
tmp = div_s( 1, shl( ola_len, 1 ) ); // Q15
tmp = round_fx( L_shl( L_mult( tmp, EVS_PI_FX ), 2 ) ); // Q15
sinq_fx( tmp, 0, ola_len, xfwin );
@@ -4583,7 +4583,7 @@ static void ivas_fec_noise_filling_fx(
}
ELSE
{
- kk = NS2SA( L * FRAMES_PER_SEC, N_ZERO_MDCT_NS );
+ kk = NS2SA_FX2( L_mult0( L, FRAMES_PER_SEC ), N_ZERO_MDCT_NS );
p_mdct_ola = old_out + kk;
}
@@ -4595,11 +4595,11 @@ static void ivas_fec_noise_filling_fx(
{
L_tmp = L_mult( *sinq_tab, *sinq_tab ); /*Q30 */
sinq_tab++;
- q2 = round_fx( L_sub( 2147483647, L_tmp ) ); /*Q15 */
- q1 = round_fx( L_tmp ); /*Q15 */
- L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */
- L_tmp = L_mac( L_tmp, shr( *pt6++, Q_old_out ), q2 ); /*Qsynth+16 */
- ( *pt1++ ) = round_fx( L_tmp ); /*Qsynth */
+ q2 = round_fx( L_sub( 2147483647, L_tmp ) ); /*Q15 */
+ q1 = round_fx( L_tmp ); /*Q15 */
+ L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */
+ L_tmp = L_add( L_tmp, L_shr( Mpy_32_16_1( L_deposit_h( *pt6++ ), q2 ), Q_old_out ) ); /*Qsynth+16 */
+ ( *pt1++ ) = round_fx( L_tmp ); /*Qsynth */
move16();
}
@@ -4939,7 +4939,7 @@ static void ivas_hq_phase_ecu_fx(
IF( element_mode == EVS_MONO )
{
- ph_ecu_lookahead = NS2SA( output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS );
+ ph_ecu_lookahead = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), PH_ECU_LOOKAHEAD_NS );
move16();
}
ELSE
@@ -5018,7 +5018,7 @@ static void ivas_hq_phase_ecu_fx(
alpha, beta, *beta_mute, Xavg, element_mode, ph_ecu_lookahead, noise_fac );
/* reconstructed frame in tda domain */
- old_dec = prevsynth + sub( shl( output_frame, 1 ), NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ) );
+ old_dec = prevsynth + sub( shl( output_frame, 1 ), NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ) );
ivas_rec_frame_fx( X, ecu_rec, output_frame, *Q_spec, old_dec, element_mode, num_p, plocs );
*last_fec = 0;
@@ -5223,11 +5223,11 @@ void ivas_hq_ecu_fx(
move16();
IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
{
- fec_alg_input = prevsynth + NS2SA( output_frame * FRAMES_PER_SEC, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS );
+ fec_alg_input = prevsynth + NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS );
}
ELSE
{
- fec_alg_input = prevsynth - NS2SA( output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS );
+ fec_alg_input = prevsynth - NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), PH_ECU_LOOKAHEAD_NS );
}
/* init (values ar changed after) */
@@ -5286,7 +5286,7 @@ void ivas_hq_ecu_fx(
}
ELSE
{
- ivas_hq_phase_ecu_fx( prevsynth - NS2SA( output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS ), ecu_rec, time_offs, X_sav, Q_spec, num_p, plocs, plocsi,
+ ivas_hq_phase_ecu_fx( prevsynth - NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), PH_ECU_LOOKAHEAD_NS ), ecu_rec, time_offs, X_sav, Q_spec, num_p, plocs, plocsi,
env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient,
mag_chg_1st, Xavg, beta_mute, st_fx->bwidth, output_frame, corr, st_fx->element_mode );
@@ -5354,7 +5354,7 @@ void hq_ecu_fx(
#ifdef IVAS_FEC_ECU_TO_COMPLETE
fec_ecu_pitch_fx( fec_alg_input, prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing );
#else
- fec_ecu_pitch_fx( prevsynth + NS2SA( output_frame * 50, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing );
+ fec_ecu_pitch_fx( prevsynth + NS2SA_FX2( L_mult0( output_frame, 50 ), ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing );
#endif
}
ELSE
@@ -5409,7 +5409,7 @@ void hq_ecu_fx(
( LT_32( st_fx->total_brate, 48000 ) && ( ( ph_ecu_HqVoicing || GT_16( corr, 27853 ) ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) ) ) )
{
- fec_alg_fx( prevsynth + NS2SA( output_frame * 50, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth );
+ fec_alg_fx( prevsynth + NS2SA_FX2( L_mult0( output_frame, 50 ), ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth );
*last_fec = 1;
move16();
*ph_ecu_active = 0;
diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c
index 1b2207491020bd08416ac1c78f69aeef75ab491c..c0ad52a480b9afacbd38829c530d103dded68f0c 100644
--- a/lib_dec/acelp_core_dec_fx.c
+++ b/lib_dec/acelp_core_dec_fx.c
@@ -107,9 +107,6 @@ ivas_error acelp_core_dec_fx(
Word16 uc_two_stage_flag, dec;
Word16 nb_bits, indice;
Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag;
-#ifdef ADD_LRTD
- Word16 *p_tdm_Pri_pitch_buf;
-#endif
MUSIC_POSTFILT_HANDLE hMusicPF;
BPF_DEC_HANDLE hBPF;
TD_BWE_DEC_HANDLE hBWE_TD;
@@ -146,66 +143,6 @@ ivas_error acelp_core_dec_fx(
return error;
}
-
-#ifdef IVAS_CODE
- output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC );
-
- /*----------------------------------------------------------------*
- * stereo SID and CNG frames processing
- *----------------------------------------------------------------*/
-
- if ( st->core_brate <= SID_2k40 && st->element_mode == IVAS_CPE_DFT && nchan_out == 2 )
- {
- if ( st->cng_type == FD_CNG )
- {
- configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
-
- /* Only run parameter decoding in SID frames */
- if ( st->core_brate == SID_2k40 )
- {
- FdCng_decodeSID_fx( st );
- }
-
- for ( i = 0; i < NPART; i++ )
- {
- st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + ( 1 - STEREO_DFT_FD_FILT ) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i];
- }
-
-#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT
- ApplyFdCng_fx( NULL, NULL, NULL, NULL, st, 0, 0 );
-#else
- ApplyFdCng_fx( NULL, NULL, NULL, NULL, st, 0, 0 );
-#endif
- }
- else
- {
- configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
-
- /* decode CNG parameters */
- CNG_dec( st, last_element_mode, Aq, lsp_new, lsf_new, &allow_cn_step, sid_bw, q_env );
-
- /* comfort noise generation */
- CNG_exc( st->core_brate, st->L_frame, &st->hTdCngDec->Enew, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->hTdCngDec->num_ho, q_env, st->hTdCngDec->lp_env, st->hTdCngDec->old_env, st->hTdCngDec->exc_mem, st->hTdCngDec->exc_mem1, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode );
-
- mvr2r( Aq, st->Aq_cng, M + 1 );
-
- /* update old LSP and LSF vector */
- mvr2r( lsf_new, st->lsf_old, M );
- mvr2r( lsp_new, st->lsp_old, M );
- }
-
- set_f( output, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */
- set_f( synth, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */
-
- /* CN generation done in DFT domain */
- wmops_sub_end();
- return error;
- }
-
- /*----------------------------------------------------------------*
- * Active frames processing
- *----------------------------------------------------------------*/
-#endif
FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
{
set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
@@ -268,13 +205,7 @@ ivas_error acelp_core_dec_fx(
move32();
}
}
-#ifdef IVAS_CODE
- if ( st->hFdCngDec != NULL && ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA ) )
- {
- set_zero( st->hFdCngDec->hFdCngCom->olapBufferSynth2, FFTLEN );
- set_zero( hStereoCng->olapBufferSynth22, FFTLEN );
- }
-#endif
+
st_fx->clas_dec = st_fx->last_good;
move16();
enr_q_fx = 0;
@@ -359,9 +290,6 @@ ivas_error acelp_core_dec_fx(
tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag;
tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode;
tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag;
-#ifdef ADD_LRTD
- p_tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf;
-#endif
move16();
move16();
move16();
@@ -380,9 +308,6 @@ ivas_error acelp_core_dec_fx(
move16();
}
tdm_Pitch_reuse_flag = 0;
-#ifdef ADD_LRTD
- p_tdm_Pri_pitch_buf = NULL;
-#endif
move16();
}
/*----------------------------------------------------------------*
@@ -422,7 +347,7 @@ ivas_error acelp_core_dec_fx(
Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56)
}
set16_fx( st_fx->mem_MA_fx, 0, M );
-#if 1 // def IVAS_CODE
+
dec = DEC;
move16();
IF( NE_16( st_fx->element_mode, EVS_MONO ) )
@@ -433,9 +358,7 @@ ivas_error acelp_core_dec_fx(
/* update synthesis filter memories */
synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, dec );
-#else
- synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC );
-#endif
+
Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc
Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/
@@ -600,7 +523,7 @@ ivas_error acelp_core_dec_fx(
{
tc_subfr_fx = tc_classif_fx( st_fx, st_fx->L_frame );
}
-#if 1 // def IVAS_CODE
+
/*----------------------------------------------------------------*
* Decoding of GSC IVAS mode
*----------------------------------------------------------------*/
@@ -620,7 +543,7 @@ ivas_error acelp_core_dec_fx(
move16();
}
}
-#endif
+
/*----------------------------------------------------------------*
* Decoding of inactive CNG frames
*----------------------------------------------------------------*/
@@ -632,22 +555,13 @@ ivas_error acelp_core_dec_fx(
{
CNG_dec_fx( st_fx, st_fx->last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env );
-#ifdef IVAS_CODE
- local_element_mode = st_fx->element_mode;
- move16();
- IF( ( EQ_16( nchan_out, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st_fx->masa_sid_format, 1 ) )
- {
- local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */
- move16();
- }
-#endif
+
/* comfort noise generation */
CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate,
&st_fx->first_CNG, &( st_fx->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step_fx, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho,
q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode );
-#if 1 // def IVAS_CODE
+
Copy( Aq_fx, st_fx->Aq_cng, M + 1 ); // Q12
-#endif
}
ELSE
{
@@ -658,32 +572,7 @@ ivas_error acelp_core_dec_fx(
*sid_bw = 0;
move16();
}
-#ifdef IVAS_CODE
- if ( st->element_mode == IVAS_CPE_DFT )
- {
- assert( nchan_out == 1 );
-
- for ( i = 0; i < NPART; i++ )
- {
- st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + ( 1 - STEREO_DFT_FD_FILT ) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i];
- }
-#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT
- ApplyFdCng_fx( syn, 0, NULL, realBuffer, imagBuffer, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
-#else
- ApplyFdCng_fx( syn, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
-#endif
- }
- if ( !read_sid_info )
- {
- float noise_lvl_highest;
- noise_lvl_highest = st->hFdCngDec->hFdCngCom->cngNoiseLevel[st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand - 1];
- for ( int16_t b = st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; b < st->hFdCngDec->hFdCngCom->stopBand; b++ )
- {
- st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest;
- }
- }
-#endif
generate_comfort_noise_dec_fx( NULL, NULL, NULL, st_fx, &( st_fx->Q_exc ), 2, -1 );
FdCng_exc( st_fx->hFdCngDec->hFdCngCom, &st_fx->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx, st_fx->first_CNG, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx );
@@ -818,10 +707,6 @@ ivas_error acelp_core_dec_fx(
move16();
st_fx->last_nq_preQ = 0;
move16();
-#ifdef IVAS_CODE
- st_fx->last_code_preq = 0;
- move16();
-#endif
}
st_fx->use_acelp_preq = 0;
@@ -830,86 +715,10 @@ ivas_error acelp_core_dec_fx(
/*-----------------------------------------------------------------*
* LSF de-quantization and interpolation
*-----------------------------------------------------------------*/
-#ifdef ADD_LRTD
- if ( !tdm_lp_reuse_flag )
-#endif
- {
- lsf_dec_fx( st_fx, tc_subfr_fx, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode,
- tdm_lsfQ_PCh );
- }
-#ifdef ADD_LRTD
- else
- {
- const float *pt_interp_2;
-#ifdef LSF_RE_USE_SECONDARY_CHANNEL
- if ( st->active_cnt != 1 )
- {
- int16_t beta_index;
-
- beta_index = get_next_indice( st, TDM_IC_LSF_PRED_BITS );
- tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, &beta_index );
- }
- else
- {
- mvr2r( tdm_lspQ_PCh, lsp_new, M );
- mvr2r( tdm_lsfQ_PCh, lsf_new, M );
- }
-#else
- mvr2r( tdm_lspQ_PCh, lsp_new, M );
- mvr2r( tdm_lsfQ_PCh, lsf_new, M );
-#endif
- if ( st->rate_switching_reset )
- {
- /* extrapolation in case of unstable LSF convert */
- mvr2r( lsp_new, st->lsp_old, M );
- mvr2r( lsf_new, st->lsf_old, M );
- }
-
- pt_interp_2 = interpol_frac_12k8;
- if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED )
- {
- pt_interp_2 = interpol_frac2;
- }
-
- if ( st->active_cnt == 1 )
- {
- mvr2r( lsp_new, st->lsp_old, M );
- lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core );
- }
- /* LSP interpolation and conversion of LSPs to A(z) */
- int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 );
- /* Check LSF stability (distance between old LSFs and current LSFs) */
- st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame );
- }
+ lsf_dec_fx( st_fx, tc_subfr_fx, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode,
+ tdm_lsfQ_PCh );
- if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO )
- {
- /* Prepare ACB memory from last HQ frame */
- old_exc_s = st->old_exc + L_EXC_MEM_DEC - st->L_frame;
- tmpF = *old_exc_s;
- st->mem_deemph = old_exc_s[st->L_frame - 1];
- preemph( old_exc_s, st->preemph_fac, L_FRAME16k, &tmpF );
- mvr2r( old_exc_s + st->L_frame - M, st->mem_syn2, M );
- residu( Aq, M, old_exc_s, old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame );
- }
- if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO )
- {
- /* Prepare ACB memory of old_bwe_exc */
-#ifdef CR_FIX_639_HQ_ACELP_TRANSITION
- if ( st->L_frame == L_FRAME )
- {
- lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
- }
- else
- {
- lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
- }
-#else
- lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
-#endif
- }
-#endif
/*-----------------------------------------------------------------*
* FEC - first good frame after lost frame(s) (possibility to correct the ACB)
*-----------------------------------------------------------------*/
@@ -979,27 +788,7 @@ ivas_error acelp_core_dec_fx(
test();
test();
-#ifdef ADD_LRTD
- IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */
- {
- IF( LE_16( st_fx->coder_type, UNVOICED ) )
- {
- tdm_low_rate_dec( st_fx, dct_exc_tmp, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new );
- }
- ELSE /* GENERIC */
- {
- decod_gen_2sbfr( st_fx, sharpFlag, Aq, pitch_buf, voice_factors, exc, exc2, bwe_exc, gain_buf, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf );
-
- IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) )
- {
- tmp_noise = st_fx->lp_gainc_fx;
- move16();
- }
- }
- }
- else
-#endif
- IF( EQ_16( st_fx->nelp_mode_dec, 1 ) )
+ IF( EQ_16( st_fx->nelp_mode_dec, 1 ) )
{
/* SC-VBR - NELP frames */
Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0
@@ -1033,12 +822,7 @@ ivas_error acelp_core_dec_fx(
}
ELSE IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) ) )
{
- decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf
-#ifdef ADD_LRTD
- ,
- tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf
-#endif
- );
+ decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf );
tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/
}
ELSE
@@ -1519,103 +1303,8 @@ ivas_error acelp_core_dec_fx(
#endif
}
/* CNA: Generate additional comfort noise to mask potential coding artefacts */
-
-#ifdef IVAS_CODE
- if ( !st->cna_dirac_flag )
- {
- /* CNA: Generate additional comfort noise to mask potential coding artefacts */
- if ( st->flag_cna && !( st->coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) )
- {
- if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 )
- {
- if ( hStereoCng->flag_cna_fade )
- {
- generate_stereo_masking_noise( syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out );
- hStereoCng->flag_cna_fade = 0;
- }
- else
- {
- if ( st->element_mode != last_element_mode && st->idchan == 0 )
- {
- /* Clear memory for secondary channel CNA */
- set_f( hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2 );
- }
-
- generate_stereo_masking_noise( syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out );
- }
- }
- else if ( st->element_mode != IVAS_CPE_DFT )
- {
- if ( st->idchan == 0 )
- {
- if ( st->element_mode != last_element_mode )
- {
- set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.0f, st->hFdCngDec->hFdCngCom->fftlen );
- }
- generate_masking_noise_fx( syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out );
- }
- }
- }
- else if ( st->flag_cna && st->coder_type == AUDIO && ( ( st->last_core == ACELP_CORE && !( st->last_coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || st->last_core == TCX_20_CORE ) )
- {
- if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 )
- {
- generate_stereo_masking_noise( syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out );
- hStereoCng->flag_cna_fade = 1;
- }
- else
- {
- v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4, (float) ( st->hFdCngDec->hFdCngCom->fftlen / 2 ), temp_buf, st->hFdCngDec->hFdCngCom->frameSize / 2 );
- v_add( temp_buf, syn, syn, st->hFdCngDec->hFdCngCom->frameSize / 2 );
- }
- }
- else
- {
- if ( hStereoCng != NULL )
- {
- hStereoCng->flag_cna_fade = 1;
- hStereoCng->enableSecCNA = 0;
- }
- }
-
- if ( st->element_mode == IVAS_CPE_TD )
- {
- /*Noise estimate*/
- if ( st->idchan == 0 && ( nchan_out == 2 || ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 ) ) )
- {
-#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT
- ApplyFdCng_fx( syn, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
-#else
- ApplyFdCng_fx( syn, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
-#endif
- }
- }
- }
-#endif
}
-#ifdef IVAS_CODE
- if ( !st->cna_dirac_flag )
- {
- if ( st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( ( st->last_core == ACELP_CORE && !( st->last_coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || st->last_core == AMR_WB_CORE ) )
- {
- v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2 );
- v_add( temp_buf, syn, syn, st->L_frame / 2 );
- }
-
- if ( st->flag_cna == 0 || ( st->coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) )
- {
- if ( st->idchan == 0 )
- {
- set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, st->hFdCngDec->hFdCngCom->fftlen );
- }
- if ( hStereoCng != NULL && st->idchan == 0 )
- {
- set_f( hStereoCng->olapBufferSynth22, 0.f, st->hFdCngDec->hFdCngCom->fftlen );
- }
- }
- }
-#else
test();
test();
test();
@@ -1632,9 +1321,7 @@ ivas_error acelp_core_dec_fx(
move16();
}
}
-#endif
-#ifndef IVAS_CODE
test();
test();
test();
@@ -1654,7 +1341,6 @@ ivas_error acelp_core_dec_fx(
{
set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen );
}
-#endif
}
/*----------------------------------------------------------------*
@@ -1676,10 +1362,7 @@ ivas_error acelp_core_dec_fx(
move16();
}
}
-#ifdef ADD_LRTD
- /* analyze pitch coherence for bass post-filter */
- bpf_pitch_coherence( st, pitch_buf );
-#endif
+
test();
IF( !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->bpf_off ) )
{
@@ -1702,20 +1385,6 @@ ivas_error acelp_core_dec_fx(
test();
IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft )
{
-#ifdef IVAS_CODE
- float realBufferSave[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
- float imagBufferSave[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
- float *pRealSave[CLDFB_NO_COL_MAX], *pImagSave[CLDFB_NO_COL_MAX];
- for ( i = 0; i < CLDFB_NO_COL_MAX; i++ )
- {
- pRealSave[i] = realBufferSave[i];
- pImagSave[i] = imagBufferSave[i];
- }
- if ( st->p_bpf_noise_buf )
- {
- mvr2r( bpf_error_signal, st->p_bpf_noise_buf, st->L_frame );
- }
-#endif
/* analysis of the synthesis at internal sampling rate */
cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX, workBuffer );
@@ -1776,40 +1445,6 @@ ivas_error acelp_core_dec_fx(
/* synthesis of the combined signal */
st_fx->Q_syn2 = st_fx->Q_syn;
move16();
-#ifdef IVAS_CODE
- if ( save_hb_synth != NULL )
- {
- /* save and then zero-out lowband */
- for ( int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
- {
- for ( i = 0; i < CLDFB_NO_COL_MAX; i++ )
- {
- realBufferSave[i][j] = realBuffer[i][j];
- imagBufferSave[i][j] = imagBuffer[i][j];
- if ( j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots )
- {
- realBuffer[i][j] = 0.0f;
- imagBuffer[i][j] = 0.0f;
- }
- }
- }
-
- cldfbSynthesis( realBuffer, imagBuffer, save_hb_synth, -1, st->cldfbSynHB );
-
- /* restore lowband */
- for ( int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
- {
- for ( i = 0; i < CLDFB_NO_COL_MAX; i++ )
- {
- realBuffer[i][j] = realBufferSave[i][j];
- imagBuffer[i][j] = imagBufferSave[i][j];
- }
- }
-
- cldfbSynthesis( pRealSave, pImagSave, synth, -1, st->cldfbSyn );
- }
- else
-#endif
{
cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate( st_fx->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer );
}
@@ -1821,34 +1456,7 @@ ivas_error acelp_core_dec_fx(
/* save synthesis - needed in case of core switching */
Copy( synth_out, st_fx->previoussynth_fx, output_frame );
}
-#ifdef IVAS_CODE
- ELSE
- {
- int16_t nSamples = NS2SA( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */
- /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */
- cldfbAnalysis( syn + st->L_frame - nSamples, realBuffer, imagBuffer, nSamples, st->cldfbAna );
-
- /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */
- addBassPostFilter( bpf_error_signal + st->L_frame - nSamples, st->bpf_off ? 0 : nSamples, realBuffer, imagBuffer, st->cldfbBPF );
-
- /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */
- cldfbSynthesis( realBuffer, imagBuffer, synth /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn );
-
- if ( st->p_bpf_noise_buf )
- {
- mvr2r( bpf_error_signal, st->p_bpf_noise_buf, st->L_frame );
- }
-
- set_f( synth, 0.0f, output_frame );
- }
-
- /* Copy output signal */
- if ( st->element_mode > EVS_MONO )
- {
- mvr2r( syn, output, st->L_frame );
- }
-#endif
/*-----------------------------------------------------------------*
* Bandwidth extension 6kHz-7kHz
*-----------------------------------------------------------------*/
diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c
index 42e4e36ef155b0bf5f11146901f3d5ab4d1eeda8..11379a62d3b1d91adf5129d78e72c21be5a48375 100644
--- a/lib_dec/acelp_core_dec_ivas_fx.c
+++ b/lib_dec/acelp_core_dec_ivas_fx.c
@@ -39,7 +39,6 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
@@ -1100,12 +1099,8 @@ ivas_error acelp_core_dec_ivas_fx(
ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) )
{
/* AUDIO and INACTIVE frames (coded by GSC technology) */
- decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx
-#if 1 // def ADD_LRTD
- ,
- tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx
-#endif
- );
+ decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx,
+ tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx );
tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
}
ELSE
@@ -1908,7 +1903,11 @@ ivas_error acelp_core_dec_ivas_fx(
scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); // Q_imag
}
- scale_sig32_r( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1)
+#ifdef OPT_STEREO_32KBPS_V1
+ scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1)
+#else /* OPT_STEREO_32KBPS_V1 */
+ scale_sig32_r( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1)
+#endif /* OPT_STEREO_32KBPS_V1 */
st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 );
move16();
#ifndef MSAN_FIX
@@ -1989,7 +1988,11 @@ ivas_error acelp_core_dec_ivas_fx(
scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
}
- scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1)
+#ifdef OPT_STEREO_32KBPS_V1
+ scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1)
+#else /* OPT_STEREO_32KBPS_V1 */
+ scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1)
+#endif /* OPT_STEREO_32KBPS_V1 */
st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 );
move16();
#ifndef MSAN_FIX
@@ -2096,12 +2099,16 @@ ivas_error acelp_core_dec_ivas_fx(
scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
}
- scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1)
+#ifdef OPT_STEREO_32KBPS_V1
+ scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1)
+#else /* OPT_STEREO_32KBPS_V1 */
+ scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1)
+#endif /* OPT_STEREO_32KBPS_V1 */
#ifndef MSAN_FIX
Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 );
#endif
- cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn );
+ cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn );
#ifdef MSAN_FIX
Scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0
diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c
index 3875339571c907267d06ede6126a3022dc03d558..fc8aba043d80645168b7ea39c9718b5c41bebbbe 100644
--- a/lib_dec/acelp_core_switch_dec_fx.c
+++ b/lib_dec/acelp_core_switch_dec_fx.c
@@ -7,7 +7,6 @@
#include "cnst.h" /* Common constants */
#include "rom_com.h" /* Static table prototypes */
#include "prot_fx.h" /* Function prototypes */
-#include "prot.h" /* Function prototypes */
/*---------------------------------------------------------------------*
* Local function prototypes
*---------------------------------------------------------------------*/
@@ -242,7 +241,7 @@ ivas_error acelp_core_switch_dec_fx(
*Q_syn = 0;
move16();
- Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), ( SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */
+ Copy_Scale_sig( synth_intFreq + sub( NS2SA_FX2( i_mult( L_frame_for_cs, 50 ), ( SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA_FX2( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */
/*----------------------------------------------------------------*
* BWE decoding
diff --git a/lib_dec/ari_dec.c b/lib_dec/ari_dec.c
deleted file mode 100644
index b45cb5d9c77b2379a1d38cc544eb9ba5a8d42d53..0000000000000000000000000000000000000000
--- a/lib_dec/ari_dec.c
+++ /dev/null
@@ -1,338 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include "cnst.h"
-#include "prot.h"
-#include "prot_fx.h"
-#include "stat_com.h"
-#include "basop_util.h"
-#include "wmc_auto.h"
-
-
-/*---------------------------------------------------------------
- * Ari decode 14 bits routines
- -------------------------------------------------------------*/
-
-/*---------------------------------------------------------------
- * ari_start_decoding_14bits_ivas()
- *
- * Start ArCo decoding
- *-------------------------------------------------------------*/
-
-
-Word16 ari_start_decoding_14bits_prm_ivas_fx(
- const Word16 *ptr,
- Word16 bp,
- Tastat *s )
-{
- Word32 val;
- Word16 i;
- const Word16 *p;
-
- val = 0;
- move32();
- p = ptr + bp;
-
- FOR( i = 0; i < cbitsnew; i++ )
- {
- val = L_or( L_shl( val, 1 ), *( p + i ) );
- }
- s->low = 0;
- move32();
- s->high = ari_q4new;
- move32();
- s->value = val;
- move32();
-
- return add( bp, i );
-}
-
-
-Word16 ari_decode_14bits_pow_ivas(
- Word16 *ptr,
- Word16 bp,
- Word16 bits,
- Word16 *res,
- Tastat *s,
- UWord16 base )
-{
- UWord16 symbol;
- Word32 low, high;
- UWord32 range, value, cum;
- Word16 pows[12]; /* "base" to the power of 2, 4, 8,... 2^12 */
- Word16 lowlim, highlim, testval;
- Word16 k;
-
- highlim = 0;
- low = s->low;
- high = L_add( s->high, 1 );
- value = s->value;
- lowlim = 0;
- symbol = 0;
- move16();
- move32();
- move32();
- move16();
- move16();
-
- range = (UWord32) W_sub( high, low );
- move32();
-
- /* the value read from bitstream */
- assert( value >= (UWord32) low );
- cum = (UWord32) W_add( W_shl( ( W_sub( value, low ) ), stat_bitsnew ), ( 1 << stat_bitsnew ) - 1 );
- move32();
-
- /* search for the interval where "cum" fits */
- IF( GT_64( W_mult0_32_32( L_shr( base, 1 ), range ), cum ) ) /* below pow-1 */
- {
- pows[0] = testval = base;
- move16();
- move16();
- /* increase exponent until it is smaller than "cum" */
- FOR( k = 1; k < 12; k++ )
- {
- highlim = testval;
- move16();
- pows[k] = mult_r( pows[k - 1], pows[k - 1] );
- move16();
- testval = mult_r( pows[k], base );
- IF( LE_64( W_mult0_32_32( shr( testval, 1 ), range ), cum ) ) /* found! big range is [lowlim,testval], (now narrow it down) */
- {
- lowlim = testval;
- move16();
- k = sub( k, 1 );
- symbol = (UWord16) L_shl( 1, k );
- BREAK;
- }
- }
- assert( k < 12 ); /* maximum 2^10-1*/
- /* narrow the range down */
- FOR( k--; k > 0; k-- )
- {
- testval = mult_r( highlim, pows[k] );
- IF( LE_64( W_mult0_32_32( shr( testval, 1 ), range ), cum ) )
- {
- lowlim = testval;
- move16();
- symbol = (UWord16) L_sub( symbol, L_shl( 1, sub( k, 1 ) ) );
- }
- ELSE
- {
- highlim = testval;
- move16();
- }
- }
- highlim = shr( highlim, 1 );
- lowlim = shr( lowlim, 1 );
- }
- ELSE /* trivial case, above pow-1, that is, first symbol */
- {
- symbol = 0;
- lowlim = extract_l( L_shr( base, 1 ) );
- highlim = 16384;
- move16();
- move16();
- }
-
-
- high = L_add( low, mul_sbc_14bits( range, highlim ) );
-
- low = L_add( low, mul_sbc_14bits( range, lowlim ) );
-
- /*ptr init for ptr*/
- FOR( ; bp < bits; )
- {
- IF( GT_32( high, ari_q2new ) )
- {
- IF( GE_32( low, ari_q2new ) )
- {
- value = (UWord32) W_sub( value, ari_q2new );
- low = L_sub( low, ari_q2new );
- high = L_sub( high, ari_q2new );
- }
- ELSE
- {
- test();
- IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) )
- {
- value = (UWord32) W_sub( value, ari_q1new );
- low = L_sub( low, ari_q1new );
- high = L_sub( high, ari_q1new );
- }
- ELSE
- {
- BREAK;
- }
- }
- }
- low = L_add( low, low );
- high = L_add( high, high );
-
- assert( abs( ptr[bp] ) <= 1 && "AC expects reading binary values!!!" );
-
- value = (UWord32) ( W_shl( value, 1 ) | ptr[bp++] );
- }
-
- test();
- test();
- test();
- IF( !( NE_16( bp, bits ) || !( EQ_32( s->low, low ) && ( EQ_32( s->high, high ) ) && ( EQ_64( s->value, value ) ) ) ) )
- {
- /* This should not happen except of bit errors. */
- s->high = s->low = 0;
- move32();
- move32();
- *res = 0;
- move16();
- return -1;
- }
-
- s->low = low;
- s->high = L_sub( high, 1 );
- s->value = value;
- move32();
- move32();
- move32();
-
- *res = symbol;
- move16();
- return bp;
-}
-
-Word16 ari_decode_14bits_sign_ivas(
- Word16 *ptr,
- Word16 bp,
- Word16 bits,
- Word16 *res,
- Tastat *s )
-{
- Word16 symbol;
- Word32 low, high;
- UWord32 range, value, cum;
-
- low = s->low;
- high = L_add( s->high, 1 );
- value = s->value;
- move32();
- move32();
-
- range = (UWord32) W_sub( high, low );
-
- IF( LT_16( bp, bits ) )
- {
- assert( value >= (UWord32) low );
- cum = (UWord32) W_add( W_shl( ( W_sub( value, low ) ), stat_bitsnew ), ( 1 << stat_bitsnew ) - 1 );
- IF( GT_64( W_shl( range, 13 ), cum ) )
- {
- symbol = 2;
- move16();
- high = L_add( low, W_extract_l( W_shr( range, 1 ) ) );
- }
- ELSE
- {
- symbol = 1;
- move16();
- low = L_add( low, W_extract_l( W_shr( range, 1 ) ) );
- }
-
- /*ptr init for ptr*/
- FOR( ; bp < bits; )
- {
- IF( GT_32( high, ari_q2new ) )
- {
- IF( GE_32( low, ari_q2new ) )
- {
- value = (UWord32) W_sub( value, ari_q2new );
- low = L_sub( low, ari_q2new );
- high = L_sub( high, ari_q2new );
- }
- ELSE
- {
- test();
- IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) )
- {
- value = (UWord32) W_sub( value, ari_q1new );
- low = L_sub( low, ari_q1new );
- high = L_sub( high, ari_q1new );
- }
- ELSE
- {
- BREAK;
- }
- }
- }
- low = L_add( low, low );
- high = L_add( high, high );
-
- assert( abs( ptr[bp] ) <= 1 && "AC expects reading binary values!!!" );
-
- value = (UWord32) ( W_shl( value, 1 ) | ptr[bp++] );
- }
- }
- ELSE
- {
- cum = (UWord32) W_sub( value, low );
- range = (UWord32) W_shr( range, 1 );
- IF( GT_64( range, cum ) )
- {
- symbol = 2;
- move16();
- high = L_add( low, range );
- }
- ELSE
- {
- symbol = 1;
- move16();
- low = L_add( low, range );
- }
- }
-
- s->low = low;
- s->high = L_sub( high, 1 );
- s->value = value;
- move32();
- move32();
- move32();
-
- *res = symbol;
- move16();
-
- return bp;
-}
diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c
index 3681568f28f46665132a75fefe5aa2ec05ac5bca..3aabbdaa58cbcdda0a7c83d962eb9297c8a8608f 100644
--- a/lib_dec/ari_dec_fx.c
+++ b/lib_dec/ari_dec_fx.c
@@ -551,3 +551,291 @@ Word16 ari_decode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *r
{
return ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, 0, ari_lookup_sign_fx );
}
+
+/*---------------------------------------------------------------
+ * ari_start_decoding_14bits_ivas()
+ *
+ * Start ArCo decoding
+ *-------------------------------------------------------------*/
+
+
+Word16 ari_start_decoding_14bits_prm_ivas_fx(
+ const Word16 *ptr,
+ Word16 bp,
+ Tastat *s )
+{
+ Word32 val;
+ Word16 i;
+ const Word16 *p;
+
+ val = 0;
+ move32();
+ p = ptr + bp;
+
+ FOR( i = 0; i < cbitsnew; i++ )
+ {
+ val = L_or( L_shl( val, 1 ), *( p + i ) );
+ }
+ s->low = 0;
+ move32();
+ s->high = ari_q4new;
+ move32();
+ s->value = val;
+ move32();
+
+ return add( bp, i );
+}
+
+
+Word16 ari_decode_14bits_pow_ivas(
+ Word16 *ptr,
+ Word16 bp,
+ Word16 bits,
+ Word16 *res,
+ Tastat *s,
+ UWord16 base )
+{
+ UWord16 symbol;
+ Word32 low, high;
+ UWord32 range, value, cum;
+ Word16 pows[12]; /* "base" to the power of 2, 4, 8,... 2^12 */
+ Word16 lowlim, highlim, testval;
+ Word16 k;
+
+ highlim = 0;
+ low = s->low;
+ high = L_add( s->high, 1 );
+ value = s->value;
+ lowlim = 0;
+ symbol = 0;
+ move16();
+ move32();
+ move32();
+ move16();
+ move16();
+
+ range = (UWord32) W_sub( high, low );
+ move32();
+
+ /* the value read from bitstream */
+ assert( value >= (UWord32) low );
+ cum = (UWord32) W_add( W_shl( ( W_sub( value, low ) ), stat_bitsnew ), ( 1 << stat_bitsnew ) - 1 );
+ move32();
+
+ /* search for the interval where "cum" fits */
+ IF( GT_64( W_mult0_32_32( L_shr( base, 1 ), range ), cum ) ) /* below pow-1 */
+ {
+ pows[0] = testval = base;
+ move16();
+ move16();
+ /* increase exponent until it is smaller than "cum" */
+ FOR( k = 1; k < 12; k++ )
+ {
+ highlim = testval;
+ move16();
+ pows[k] = mult_r( pows[k - 1], pows[k - 1] );
+ move16();
+ testval = mult_r( pows[k], base );
+ IF( LE_64( W_mult0_32_32( shr( testval, 1 ), range ), cum ) ) /* found! big range is [lowlim,testval], (now narrow it down) */
+ {
+ lowlim = testval;
+ move16();
+ k = sub( k, 1 );
+ symbol = (UWord16) L_shl( 1, k );
+ BREAK;
+ }
+ }
+ assert( k < 12 ); /* maximum 2^10-1*/
+ /* narrow the range down */
+ FOR( k--; k > 0; k-- )
+ {
+ testval = mult_r( highlim, pows[k] );
+ IF( LE_64( W_mult0_32_32( shr( testval, 1 ), range ), cum ) )
+ {
+ lowlim = testval;
+ move16();
+ symbol = (UWord16) L_sub( symbol, L_shl( 1, sub( k, 1 ) ) );
+ }
+ ELSE
+ {
+ highlim = testval;
+ move16();
+ }
+ }
+ highlim = shr( highlim, 1 );
+ lowlim = shr( lowlim, 1 );
+ }
+ ELSE /* trivial case, above pow-1, that is, first symbol */
+ {
+ symbol = 0;
+ lowlim = extract_l( L_shr( base, 1 ) );
+ highlim = 16384;
+ move16();
+ move16();
+ }
+
+
+ high = L_add( low, mul_sbc_14bits( range, highlim ) );
+
+ low = L_add( low, mul_sbc_14bits( range, lowlim ) );
+
+ /*ptr init for ptr*/
+ FOR( ; bp < bits; )
+ {
+ IF( GT_32( high, ari_q2new ) )
+ {
+ IF( GE_32( low, ari_q2new ) )
+ {
+ value = (UWord32) W_sub( value, ari_q2new );
+ low = L_sub( low, ari_q2new );
+ high = L_sub( high, ari_q2new );
+ }
+ ELSE
+ {
+ test();
+ IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) )
+ {
+ value = (UWord32) W_sub( value, ari_q1new );
+ low = L_sub( low, ari_q1new );
+ high = L_sub( high, ari_q1new );
+ }
+ ELSE
+ {
+ BREAK;
+ }
+ }
+ }
+ low = L_add( low, low );
+ high = L_add( high, high );
+
+ assert( abs( ptr[bp] ) <= 1 && "AC expects reading binary values!!!" );
+
+ value = (UWord32) ( W_shl( value, 1 ) | ptr[bp++] );
+ }
+
+ test();
+ test();
+ test();
+ IF( !( NE_16( bp, bits ) || !( EQ_32( s->low, low ) && ( EQ_32( s->high, high ) ) && ( EQ_64( s->value, value ) ) ) ) )
+ {
+ /* This should not happen except of bit errors. */
+ s->high = s->low = 0;
+ move32();
+ move32();
+ *res = 0;
+ move16();
+ return -1;
+ }
+
+ s->low = low;
+ s->high = L_sub( high, 1 );
+ s->value = value;
+ move32();
+ move32();
+ move32();
+
+ *res = symbol;
+ move16();
+ return bp;
+}
+
+Word16 ari_decode_14bits_sign_ivas(
+ Word16 *ptr,
+ Word16 bp,
+ Word16 bits,
+ Word16 *res,
+ Tastat *s )
+{
+ Word16 symbol;
+ Word32 low, high;
+ UWord32 range, value, cum;
+
+ low = s->low;
+ high = L_add( s->high, 1 );
+ value = s->value;
+ move32();
+ move32();
+
+ range = (UWord32) W_sub( high, low );
+
+ IF( LT_16( bp, bits ) )
+ {
+ assert( value >= (UWord32) low );
+ cum = (UWord32) W_add( W_shl( ( W_sub( value, low ) ), stat_bitsnew ), ( 1 << stat_bitsnew ) - 1 );
+ IF( GT_64( W_shl( range, 13 ), cum ) )
+ {
+ symbol = 2;
+ move16();
+ high = L_add( low, W_extract_l( W_shr( range, 1 ) ) );
+ }
+ ELSE
+ {
+ symbol = 1;
+ move16();
+ low = L_add( low, W_extract_l( W_shr( range, 1 ) ) );
+ }
+
+ /*ptr init for ptr*/
+ FOR( ; bp < bits; )
+ {
+ IF( GT_32( high, ari_q2new ) )
+ {
+ IF( GE_32( low, ari_q2new ) )
+ {
+ value = (UWord32) W_sub( value, ari_q2new );
+ low = L_sub( low, ari_q2new );
+ high = L_sub( high, ari_q2new );
+ }
+ ELSE
+ {
+ test();
+ IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) )
+ {
+ value = (UWord32) W_sub( value, ari_q1new );
+ low = L_sub( low, ari_q1new );
+ high = L_sub( high, ari_q1new );
+ }
+ ELSE
+ {
+ BREAK;
+ }
+ }
+ }
+ low = L_add( low, low );
+ high = L_add( high, high );
+
+ assert( abs( ptr[bp] ) <= 1 && "AC expects reading binary values!!!" );
+
+ value = (UWord32) ( W_shl( value, 1 ) | ptr[bp++] );
+ }
+ }
+ ELSE
+ {
+ cum = (UWord32) W_sub( value, low );
+ range = (UWord32) W_shr( range, 1 );
+ IF( GT_64( range, cum ) )
+ {
+ symbol = 2;
+ move16();
+ high = L_add( low, range );
+ }
+ ELSE
+ {
+ symbol = 1;
+ move16();
+ low = L_add( low, range );
+ }
+ }
+
+ s->low = low;
+ s->high = L_sub( high, 1 );
+ s->value = value;
+ move32();
+ move32();
+ move32();
+
+ *res = symbol;
+ move16();
+
+ return bp;
+}
diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c
index da7722325058b1ca10f3ed0060b97a37d320444b..ef4fb62d5579e0f89500a76227fbe459a7f1719e 100644
--- a/lib_dec/ari_hm_dec.c
+++ b/lib_dec/ari_hm_dec.c
@@ -40,10 +40,9 @@
#include "cnst.h"
#include "stl.h"
#include "basop_util.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
Word16
DecodeIndex_fx(
diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c
deleted file mode 100644
index 93bd8877cf6f23910bb7436b7bb6528b7f0e54ef..0000000000000000000000000000000000000000
--- a/lib_dec/arith_coder_dec.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include "cnst.h"
-#include "prot.h"
-#include "rom_com.h"
-#include "basop_util.h"
-#include "basop_proto_func.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-/*-------------------------------------------------------*
- * tcx_arith_decode()
- *
- *
- *-------------------------------------------------------*/
-
-/*! r: number of bits consumed */
-
-static Word16 tcx_arith_decode_ivas_fx(
- const Word16 L_frame, /* i : number of spectral lines */
- const Word16 envelope[], /* i : scaled envelope (Q15-envelope_e) */
- Word16 envelope_e, /* i : scaled envelope exponent (Q0) */
- const Word16 target_bits, /* i : target bit budget */
- Word16 prm[], /* i : bitstream parameters */
- Word32 q_spectrum[], /* o : scalar quantized spectrum (Q31-q_spectrum_e) */
- Word16 *q_spectrum_e /* o : spectrum exponent */
-)
-{
- Word16 bp, k, q;
- Word16 s;
- Tastat as;
- UWord16 exp_k;
- Word16 tmp;
-
- bp = ari_start_decoding_14bits_prm_ivas_fx( prm, 0, &as );
-
- tmp = sub( envelope_e, 1 );
-
- FOR( k = 0; k < L_frame; k++ )
- {
- IF( EQ_16( envelope[k], 0 ) ) /* safety check in case of bit errors */
- {
- set32_fx( q_spectrum, 0, L_frame );
- return -1;
- }
- ELSE
- {
- exp_k = expfp_evs_fx( negate( envelope[k] ), tmp );
- }
-
- /* decode line magnitude */
- bp = ari_decode_14bits_pow_ivas( prm, bp, target_bits, &q, &as, exp_k );
-
- IF( q )
- {
- /* line is non-zero, decode sign */
- bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as );
- q_spectrum[k] = L_mult( q, sub( 3, shl( s, 1 ) ) );
- move32();
- q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); // Q(31-20)
- move32();
- }
- ELSE
- {
- /* line is zero, no sign needed */
- q_spectrum[k] = 0;
- move32();
- }
-
- IF( LE_32( as.high, as.low ) )
- {
- if ( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */
- {
- bp = -1;
- move16();
- }
- BREAK; /* no bits left, so exit loop */
- }
- }
- *q_spectrum_e = SPEC_EXP_DEC;
- move16();
-
- set32_fx( q_spectrum + k, 0, sub( L_frame, k ) );
-
- return bp;
-}
-
-/*-------------------------------------------------------*
- * tcx_arith_decode_envelope()
- *
- *
- *-------------------------------------------------------*/
-
-void tcx_arith_decode_envelope_ivas_fx(
- Decoder_State *st, /* i/o: coder state */
- Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */
- Word16 *q_spectrum_e, /* o : MDCT exponent */
- const Word16 L_frame, /* i : frame or MDCT length */
- Word16 L_spec, /* i : length w/o BW limitation */
- const Word16 A_ind[], /* i : quantised LPC coefficients */
- const Word16 target_bits, /* i : number of available bits */
- Word16 prm[], /* i : bitstream parameters */
- const Word16 use_hm, /* i : use HM in current frame? */
- const Word16 prm_hm[], /* i : HM parameter area */
- Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/
- Word16 *arith_bits, /* o : bits used for ari. coding */
- Word16 *signaling_bits, /* o : bits used for signaling */
- const Word16 low_complexity /* i : low-complexity flag */
-)
-{
- Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */
- Word16 *envelope; /* scaled envelope (Q15-e) */
- Word16 envelope_e;
- Word16 L_spec_core;
- TCX_CONFIG_HANDLE hTcxCfg;
- TCX_DEC_HANDLE hTcxDec;
- Word16 gamma_w, gamma_uw;
- Word16 hm_bits;
-
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( GT_16( L_spec, N_MAX_ARI ) || ( ( st->element_mode == EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) ||
- ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) ||
- ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) ||
- ( target_bits <= 0 ) )
- {
- /* this could happen in case of bit errors */
- st->BER_detect = 1;
- move16();
- L_spec = N_MAX_ARI;
- move16();
- *signaling_bits = 0;
- move16();
- *arith_bits = 0;
- move16();
- set32_fx( q_spectrum, 0, L_frame );
-
- return;
- }
-
- hTcxCfg = st->hTcxCfg;
- hTcxDec = st->hTcxDec;
- *signaling_bits = 0;
- move16();
-
- assert( hTcxDec->enableTcxLpc );
- gamma_w = MAX16B;
- move16();
- gamma_uw = st->inv_gamma;
- move16();
-
-#define WMC_TOOL_SKIP
- tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env );
-#undef WMC_TOOL_SKIP
-
- IF( use_hm != 0 )
- {
- IF( prm_hm[0] != 0 )
- {
- tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits );
-
- IF( hm_bits < 0 )
- {
- st->BER_detect = 1;
- move16();
- *signaling_bits = 0;
- move16();
- *arith_bits = 0;
- move16();
- set32_fx( q_spectrum, 0, L_frame );
-
- return;
- }
- }
- ELSE
- {
- hm_bits = 1;
- move16();
- }
- *signaling_bits = add( *signaling_bits, hm_bits );
- move16();
- }
-
- L_spec_core = L_spec;
- move16();
- IF( st->igf )
- {
- L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine );
- }
-
- envelope = (Word16 *) env;
- tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e );
-
- *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e );
- move16();
-
- /* safety check in case of bit errors */
- IF( *arith_bits < 0 )
- {
- st->BER_detect = 1;
- move16();
- set32_fx( q_spectrum, 0, L_frame );
- }
-
- set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) );
-
- return;
-}
diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c
index 4a18f64f9af7a503a0e66756353605e7e5d03b07..60a59c4da469f113f7195179ed0521d2c343bc2d 100644
--- a/lib_dec/arith_coder_dec_fx.c
+++ b/lib_dec/arith_coder_dec_fx.c
@@ -8,6 +8,8 @@
#include "cnst.h"
#include "rom_com.h"
#include "prot_fx.h"
+#include "basop_util.h"
+#include "basop_proto_func.h"
/* Returns: number of bits consumed */
static Word16 tcx_arith_decode_fx(
@@ -213,3 +215,207 @@ void tcx_arith_decode_envelope_fx(
set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) );
}
+
+/*-------------------------------------------------------*
+ * tcx_arith_decode()
+ *
+ *
+ *-------------------------------------------------------*/
+
+/*! r: number of bits consumed */
+
+static Word16 tcx_arith_decode_ivas_fx(
+ const Word16 L_frame, /* i : number of spectral lines */
+ const Word16 envelope[], /* i : scaled envelope (Q15-envelope_e) */
+ Word16 envelope_e, /* i : scaled envelope exponent (Q0) */
+ const Word16 target_bits, /* i : target bit budget */
+ Word16 prm[], /* i : bitstream parameters */
+ Word32 q_spectrum[], /* o : scalar quantized spectrum (Q31-q_spectrum_e) */
+ Word16 *q_spectrum_e /* o : spectrum exponent */
+)
+{
+ Word16 bp, k, q;
+ Word16 s;
+ Tastat as;
+ UWord16 exp_k;
+ Word16 tmp;
+
+ bp = ari_start_decoding_14bits_prm_ivas_fx( prm, 0, &as );
+
+ tmp = sub( envelope_e, 1 );
+
+ FOR( k = 0; k < L_frame; k++ )
+ {
+ IF( EQ_16( envelope[k], 0 ) ) /* safety check in case of bit errors */
+ {
+ set32_fx( q_spectrum, 0, L_frame );
+ return -1;
+ }
+ ELSE
+ {
+ exp_k = expfp_evs_fx( negate( envelope[k] ), tmp );
+ }
+
+ /* decode line magnitude */
+ bp = ari_decode_14bits_pow_ivas( prm, bp, target_bits, &q, &as, exp_k );
+
+ IF( q )
+ {
+ /* line is non-zero, decode sign */
+ bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as );
+ q_spectrum[k] = L_mult( q, sub( 3, shl( s, 1 ) ) );
+ move32();
+ q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); // Q(31-20)
+ move32();
+ }
+ ELSE
+ {
+ /* line is zero, no sign needed */
+ q_spectrum[k] = 0;
+ move32();
+ }
+
+ IF( LE_32( as.high, as.low ) )
+ {
+ if ( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */
+ {
+ bp = -1;
+ move16();
+ }
+ BREAK; /* no bits left, so exit loop */
+ }
+ }
+ *q_spectrum_e = SPEC_EXP_DEC;
+ move16();
+
+ set32_fx( q_spectrum + k, 0, sub( L_frame, k ) );
+
+ return bp;
+}
+
+/*-------------------------------------------------------*
+ * tcx_arith_decode_envelope()
+ *
+ *
+ *-------------------------------------------------------*/
+
+void tcx_arith_decode_envelope_ivas_fx(
+ Decoder_State *st, /* i/o: coder state */
+ Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */
+ Word16 *q_spectrum_e, /* o : MDCT exponent */
+ const Word16 L_frame, /* i : frame or MDCT length */
+ Word16 L_spec, /* i : length w/o BW limitation */
+ const Word16 A_ind[], /* i : quantised LPC coefficients */
+ const Word16 target_bits, /* i : number of available bits */
+ Word16 prm[], /* i : bitstream parameters */
+ const Word16 use_hm, /* i : use HM in current frame? */
+ const Word16 prm_hm[], /* i : HM parameter area */
+ Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/
+ Word16 *arith_bits, /* o : bits used for ari. coding */
+ Word16 *signaling_bits, /* o : bits used for signaling */
+ const Word16 low_complexity /* i : low-complexity flag */
+)
+{
+ Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */
+ Word16 *envelope; /* scaled envelope (Q15-e) */
+ Word16 envelope_e;
+ Word16 L_spec_core;
+ TCX_CONFIG_HANDLE hTcxCfg;
+ TCX_DEC_HANDLE hTcxDec;
+ Word16 gamma_w, gamma_uw;
+ Word16 hm_bits;
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( GT_16( L_spec, N_MAX_ARI ) || ( ( st->element_mode == EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) ||
+ ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) ||
+ ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) ||
+ ( target_bits <= 0 ) )
+ {
+ /* this could happen in case of bit errors */
+ st->BER_detect = 1;
+ move16();
+ L_spec = N_MAX_ARI;
+ move16();
+ *signaling_bits = 0;
+ move16();
+ *arith_bits = 0;
+ move16();
+ set32_fx( q_spectrum, 0, L_frame );
+
+ return;
+ }
+
+ hTcxCfg = st->hTcxCfg;
+ hTcxDec = st->hTcxDec;
+ *signaling_bits = 0;
+ move16();
+
+ assert( hTcxDec->enableTcxLpc );
+ gamma_w = MAX16B;
+ move16();
+ gamma_uw = st->inv_gamma;
+ move16();
+
+#define WMC_TOOL_SKIP
+ tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env );
+#undef WMC_TOOL_SKIP
+
+ IF( use_hm != 0 )
+ {
+ IF( prm_hm[0] != 0 )
+ {
+ tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits );
+
+ IF( hm_bits < 0 )
+ {
+ st->BER_detect = 1;
+ move16();
+ *signaling_bits = 0;
+ move16();
+ *arith_bits = 0;
+ move16();
+ set32_fx( q_spectrum, 0, L_frame );
+
+ return;
+ }
+ }
+ ELSE
+ {
+ hm_bits = 1;
+ move16();
+ }
+ *signaling_bits = add( *signaling_bits, hm_bits );
+ move16();
+ }
+
+ L_spec_core = L_spec;
+ move16();
+ IF( st->igf )
+ {
+ L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine );
+ }
+
+ envelope = (Word16 *) env;
+ tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e );
+
+ *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e );
+ move16();
+
+ /* safety check in case of bit errors */
+ IF( *arith_bits < 0 )
+ {
+ st->BER_detect = 1;
+ move16();
+ set32_fx( q_spectrum, 0, L_frame );
+ }
+
+ set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) );
+
+ return;
+}
diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c
index 3bf7e3eb62ff897d2028a462d3e8f30c33ead199..a8ba2bfc3612253b30e153d2cb22f863afe3d4a4 100644
--- a/lib_dec/avq_dec_fx.c
+++ b/lib_dec/avq_dec_fx.c
@@ -7,7 +7,6 @@
#include "options.h" /* Compilation switches */
#include "cnst.h" /* Common constants */
#include "rom_com.h" /* Static table prototypes */
-#include "prot.h" /* Function prototypes */
#include "prot_fx.h" /* Function prototypes */
/*-------------------------------------------------------------------*
diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c
deleted file mode 100644
index 478a814744be7f47d9ae8df548e54b14d10d289c..0000000000000000000000000000000000000000
--- a/lib_dec/bass_psfilter.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "prot.h"
-#include "prot_fx.h"
-#include "ivas_prot.h"
-#include "cnst.h"
-#include "stat_dec.h"
-#include "rom_com.h"
-#include
-#include "wmc_auto.h"
-#include "ivas_prot_fx.h"
-
-/*---------------------------------------------------------------------*
- * Local constants
- *---------------------------------------------------------------------*/
-
-
-#define NBPSF_L_EXTRA 120
-#define BPF_STOP_STOPBAND_16 16
-#define K_PC_DEC_FX -1170 /* -0.0357f in Q15 */
-#define K_PC_DEC_FX32 -76665166 /* -0.0357f in Q31 */
-#define C_PC_DEC_FX 6583 /*in Q8*/
-
-/*---------------------------------------------------------------------*
- * Local function prototypes
- *---------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------*
- * bass_psfilter()
- *
- * Perform low-frequency postfiltering
- *---------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------*
- * Pit_track()
- *
- * Perform pitch tracking and test pitch/2 to avoid continuous pitch doubling
- *---------------------------------------------------------------------*/
-
-/*! r: Pitch */
-
-
-/*---------------------------------------------------------------------*
- * addBassPostFilter()
- *
- * Add BPF component in cldfb domain
- *---------------------------------------------------------------------*/
-
-
-void addBassPostFilter_ivas_fx(
- const Word32 *harm_timeIn_fx, // Qx
- const Word16 samplesToProcess,
- Word32 **rAnalysis_fx, // Qx - 5
- Word32 **iAnalysis_fx, // Qx - 5
- HANDLE_CLDFB_FILTER_BANK cldfb )
-{
- Word32 *tmp_R_fx[CLDFB_NO_COL_MAX];
- Word32 *tmp_I_fx[CLDFB_NO_COL_MAX];
- Word32 cldfbBufferReal_fx[CLDFB_NO_COL_MAX][20];
- Word32 cldfbBufferImag_fx[CLDFB_NO_COL_MAX][20];
- Word16 i, b;
- Word16 maxBand;
- const Word32 *weights_fx;
- Word16 nCol = cldfb->no_col;
- move16();
- Word16 nColToProcess = nCol;
- move16();
- Word16 nChan = cldfb->no_channels;
- move16();
- IF( GT_16( samplesToProcess, -1 ) )
- {
- nColToProcess = idiv1616( sub( add( samplesToProcess, cldfb->no_channels ), 1 ), cldfb->no_channels );
- move16();
- }
-
- assert( nCol == 16 );
-
- weights_fx = bpf_weights_16_ivas_fx_32;
-
- IF( GT_16( nChan, BPF_STOP_STOPBAND_16 ) )
- {
- maxBand = BPF_STOP_STOPBAND_16;
- move16();
- }
- ELSE
- {
- maxBand = nChan;
- move16();
- }
-
- FOR( i = 0; i < nColToProcess; i++ )
- {
- tmp_R_fx[i] = cldfbBufferReal_fx[i];
- tmp_I_fx[i] = cldfbBufferImag_fx[i];
- }
-
- cldfbAnalysis_ivas_fx( harm_timeIn_fx, tmp_R_fx, tmp_I_fx, samplesToProcess, cldfb );
-
- /* now do the subtraction */
- FOR( i = 0; i < nColToProcess; i++ )
- {
- /* loop over low frequency bands */
- FOR( b = 0; b < maxBand; b++ )
- {
- rAnalysis_fx[i][b] = Msub_32_32( rAnalysis_fx[i][b], tmp_R_fx[i][b], weights_fx[b] ); // Qx - 6
- move32();
- iAnalysis_fx[i][b] = Msub_32_32( iAnalysis_fx[i][b], tmp_I_fx[i][b], weights_fx[b] ); // Qx - 6
- move32();
- }
- }
-
- return;
-}
-
-
-/*---------------------------------------------------------------------*
- * res_bpf_adapt_ivas_fx()
- *
- * Analyze BPF output and decide if it should be applied on DFT stereo
- * residual signal
- *---------------------------------------------------------------------*/
-
-/*! r: Decision to enable or disable BPF on DFT stereo residual */
-Word16 res_bpf_adapt_ivas_fx(
- STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */
- const Word32 *bpf_error_signal_8k, /* i : BPF modification signal */
- Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer Q12 */
- Word16 q_res )
-{
- Word32 error_nrg;
- Word32 tmp;
- Word32 res_hb_nrg;
- Word16 bpf_error_ratio;
- Word16 res_bpf_flag;
- Word16 i;
- Word16 i_start;
- Word16 i_end;
- Word16 bw_inv;
- Word64 W_tmp;
-
- IF( EQ_16( hStereoDft->res_cod_band_max, 6 ) )
- {
- i_start = 39;
- move16();
- i_end = 64;
- move16();
- bw_inv = 1311;
- move16(); /* 1/(64 - 39) in Q15 */
- }
- ELSE
- {
- i_start = 28;
- move16();
- i_end = 40;
- move16();
- bw_inv = 2720;
- move16(); /* 1/(40 - 28) in Q15*/
- }
-
- /* Measure energy of high frequency band in MDCT domain */
- res_hb_nrg = L_deposit_l( 0 );
- W_tmp = W_deposit32_l( 0 );
- FOR( i = i_start; i < i_end; i++ )
- {
- W_tmp = W_add_nosat( W_tmp, W_mult0_32_32( res_buf[i], res_buf[i] ) );
- }
-
- res_hb_nrg = W_extract_l( W_shr( W_tmp, shl( q_res, 1 ) ) ); // Q0
- res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); // Q0
- res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) );
- hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg;
- move32();
-
- /* Measure energy of discontinuities at subframe boundaries */
- error_nrg = 0;
- move32();
- FOR( i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k )
- {
- tmp = L_sub( bpf_error_signal_8k[i], hStereoDft->bpf_error_signal_last_fx );
- error_nrg = Madd_32_32( error_nrg, tmp, tmp );
- hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[( i + ( STEREO_DFT_L_SUBFR_8k - 1 ) )];
- move32();
- }
- error_nrg = L_shl( error_nrg, 1 ); // Q0
- error_nrg = Mpy_32_16_1( error_nrg, 6553 /* 0.2f in Q15 */ ); /* Division by 5 for average value */
- /* Form decision variable and apply limit */
- IF( LT_32( ( L_shr( error_nrg, 1 ) ), res_hb_nrg ) )
- {
- Word16 temp;
- bpf_error_ratio = BASOP_Util_Divide3232_Scale( error_nrg, res_hb_nrg, &temp );
- bpf_error_ratio = shl( bpf_error_ratio, sub( 13, sub( 15, temp ) ) );
- }
- ELSE
- {
- bpf_error_ratio = ONE_IN_Q14; // Q13
- move16();
- }
- bpf_error_ratio = add( mult( STEREO_DFT_BPF_ADAPT_BETA_FX, bpf_error_ratio ), mult( ( MAX_16 - STEREO_DFT_BPF_ADAPT_BETA_FX ), hStereoDft->bpf_error_ratio_mem_fx ) );
- hStereoDft->bpf_error_ratio_mem_fx = bpf_error_ratio;
- move16();
-
- res_bpf_flag = (Word16) LT_16( bpf_error_ratio, ONE_IN_Q13 );
- move16();
-
- return res_bpf_flag;
-}
-
-void bpf_pitch_coherence_ivas_fx(
- Decoder_State *st, /* i/o: decoder state structure */
- const Word32 pitch_buf[] /* i : pitch for every subfr [0,1,2,3] Q20 */
-)
-{
- Word16 nb_subfr;
- Word32 pc, pcn1, pcn2, pcn3;
- Word32 scaled_inv_L_frame; // Q8 + Q23
-
- SWITCH( st->L_frame )
- {
- case 80:
- scaled_inv_L_frame = 26843545; // 1/80 in Q31
- move32();
- BREAK;
- case 160:
- scaled_inv_L_frame = 13421773; // 1/160 in Q31
- move32();
- BREAK;
- case 256:
- scaled_inv_L_frame = 8388608; // 1/256 in Q31
- move32();
- BREAK;
- case 320:
- scaled_inv_L_frame = 6710886; // 1/320 in Q31
- move32();
- BREAK;
- case 512:
- scaled_inv_L_frame = 4194304; // 1/512 in Q31
- move32();
- BREAK;
- case 640:
- scaled_inv_L_frame = 3355443; // 1/640 in Q31
- move32();
- BREAK;
- case 960:
- scaled_inv_L_frame = 2236962; // 1/80 in Q31
- move32();
- BREAK;
- default:
- scaled_inv_L_frame = 0;
- move32();
- }
-
- nb_subfr = shr( st->L_frame, 6 );
- test();
- IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && ( st->element_mode != EVS_MONO ) )
- {
- pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[nb_subfr + 1] ) ) );
- pc = Mpy_32_32( pc, scaled_inv_L_frame );
- pcn1 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX );
- pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); // 4096 = 1 in Q12
-
- pc = L_abs( L_sub( L_add( pitch_buf[nb_subfr - 1], pitch_buf[nb_subfr - 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) );
- pc = Mpy_32_32( pc, scaled_inv_L_frame );
- pcn2 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX );
- pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); // 4096 = 1 in Q12
-
- pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) );
- pc = Mpy_32_32( pc, scaled_inv_L_frame );
- pcn3 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX );
- pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); // 4096 = 1 in Q12
-
- IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 /*2.5f in Q12*/ ) )
- {
- st->hBPF->psf_att_fx = 13107; //.4 in Q15
- move16(); /*Q15*/
- set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr );
- }
- }
-
- return;
-}
diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c
index c11e30c93af6770d9f053cd177f56482d43484d1..75cabf160042c12159d477ea02f447c97ef37456 100644
--- a/lib_dec/bass_psfilter_fx.c
+++ b/lib_dec/bass_psfilter_fx.c
@@ -4,11 +4,12 @@
#include
#include
-#include "options.h" /* Compilation switches */
-#include "prot_fx.h" /* Function prototypes */
-#include "cnst.h" /* Common constants */
-#include "rom_com.h" /* Static table prototypes */
-#include "rom_dec.h" /* Static table prototypes */
+#include "options.h" /* Compilation switches */
+#include "prot_fx.h" /* Function prototypes */
+#include "ivas_prot_fx.h" /* Function prototypes */
+#include "cnst.h" /* Common constants */
+#include "rom_com.h" /* Static table prototypes */
+#include "rom_dec.h" /* Static table prototypes */
#include "basop_util.h"
/*---------------------------------------------------------------------*
@@ -17,6 +18,9 @@
#define NBPSF_L_EXTRA 120
#define BPF_STOP_STOPBAND_16 16
+#define K_PC_DEC_FX -1170 /* -0.0357f in Q15 */
+#define K_PC_DEC_FX32 -76665166 /* -0.0357f in Q31 */
+#define C_PC_DEC_FX 6583 /*in Q8*/
/*---------------------------------------------------------------------*
* Local function prototypes
@@ -889,6 +893,246 @@ void addBassPostFilter_fx(
return;
}
+/*---------------------------------------------------------------------*
+ * addBassPostFilter()
+ *
+ * Add BPF component in cldfb domain
+ *---------------------------------------------------------------------*/
+
+
+void addBassPostFilter_ivas_fx(
+ const Word32 *harm_timeIn_fx, // Qx
+ const Word16 samplesToProcess,
+ Word32 **rAnalysis_fx, // Qx - 5
+ Word32 **iAnalysis_fx, // Qx - 5
+ HANDLE_CLDFB_FILTER_BANK cldfb )
+{
+ Word32 *tmp_R_fx[CLDFB_NO_COL_MAX];
+ Word32 *tmp_I_fx[CLDFB_NO_COL_MAX];
+ Word32 cldfbBufferReal_fx[CLDFB_NO_COL_MAX][20];
+ Word32 cldfbBufferImag_fx[CLDFB_NO_COL_MAX][20];
+ Word16 i, b;
+ Word16 maxBand;
+ const Word32 *weights_fx;
+ Word16 nCol = cldfb->no_col;
+ move16();
+ Word16 nColToProcess = nCol;
+ move16();
+ Word16 nChan = cldfb->no_channels;
+ move16();
+ IF( GT_16( samplesToProcess, -1 ) )
+ {
+ nColToProcess = idiv1616( sub( add( samplesToProcess, cldfb->no_channels ), 1 ), cldfb->no_channels );
+ move16();
+ }
+
+ assert( nCol == 16 );
+
+ weights_fx = bpf_weights_16_ivas_fx_32;
+
+ IF( GT_16( nChan, BPF_STOP_STOPBAND_16 ) )
+ {
+ maxBand = BPF_STOP_STOPBAND_16;
+ move16();
+ }
+ ELSE
+ {
+ maxBand = nChan;
+ move16();
+ }
+
+ FOR( i = 0; i < nColToProcess; i++ )
+ {
+ tmp_R_fx[i] = cldfbBufferReal_fx[i];
+ tmp_I_fx[i] = cldfbBufferImag_fx[i];
+ }
+
+ cldfbAnalysis_ivas_fx( harm_timeIn_fx, tmp_R_fx, tmp_I_fx, samplesToProcess, cldfb );
+
+ /* now do the subtraction */
+ FOR( i = 0; i < nColToProcess; i++ )
+ {
+ /* loop over low frequency bands */
+ FOR( b = 0; b < maxBand; b++ )
+ {
+ rAnalysis_fx[i][b] = Msub_32_32( rAnalysis_fx[i][b], tmp_R_fx[i][b], weights_fx[b] ); // Qx - 6
+ move32();
+ iAnalysis_fx[i][b] = Msub_32_32( iAnalysis_fx[i][b], tmp_I_fx[i][b], weights_fx[b] ); // Qx - 6
+ move32();
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * res_bpf_adapt_ivas_fx()
+ *
+ * Analyze BPF output and decide if it should be applied on DFT stereo
+ * residual signal
+ *---------------------------------------------------------------------*/
+
+/*! r: Decision to enable or disable BPF on DFT stereo residual */
+Word16 res_bpf_adapt_ivas_fx(
+ STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */
+ const Word32 *bpf_error_signal_8k, /* i : BPF modification signal */
+ Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer Q12 */
+ Word16 q_res )
+{
+ Word32 error_nrg;
+ Word32 tmp;
+ Word32 res_hb_nrg;
+ Word16 bpf_error_ratio;
+ Word16 res_bpf_flag;
+ Word16 i;
+ Word16 i_start;
+ Word16 i_end;
+ Word16 bw_inv;
+ Word64 W_tmp;
+
+ IF( EQ_16( hStereoDft->res_cod_band_max, 6 ) )
+ {
+ i_start = 39;
+ move16();
+ i_end = 64;
+ move16();
+ bw_inv = 1311;
+ move16(); /* 1/(64 - 39) in Q15 */
+ }
+ ELSE
+ {
+ i_start = 28;
+ move16();
+ i_end = 40;
+ move16();
+ bw_inv = 2720;
+ move16(); /* 1/(40 - 28) in Q15*/
+ }
+
+ /* Measure energy of high frequency band in MDCT domain */
+ res_hb_nrg = L_deposit_l( 0 );
+ W_tmp = W_deposit32_l( 0 );
+ FOR( i = i_start; i < i_end; i++ )
+ {
+ W_tmp = W_add_nosat( W_tmp, W_mult0_32_32( res_buf[i], res_buf[i] ) );
+ }
+
+ res_hb_nrg = W_extract_l( W_shr( W_tmp, shl( q_res, 1 ) ) ); // Q0
+ res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); // Q0
+ res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) );
+ hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg;
+ move32();
+
+ /* Measure energy of discontinuities at subframe boundaries */
+ error_nrg = 0;
+ move32();
+ FOR( i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k )
+ {
+ tmp = L_sub( bpf_error_signal_8k[i], hStereoDft->bpf_error_signal_last_fx );
+ error_nrg = Madd_32_32( error_nrg, tmp, tmp );
+ hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[( i + ( STEREO_DFT_L_SUBFR_8k - 1 ) )];
+ move32();
+ }
+ error_nrg = L_shl( error_nrg, 1 ); // Q0
+ error_nrg = Mpy_32_16_1( error_nrg, 6553 /* 0.2f in Q15 */ ); /* Division by 5 for average value */
+ /* Form decision variable and apply limit */
+ IF( LT_32( ( L_shr( error_nrg, 1 ) ), res_hb_nrg ) )
+ {
+ Word16 temp;
+ bpf_error_ratio = BASOP_Util_Divide3232_Scale( error_nrg, res_hb_nrg, &temp );
+ bpf_error_ratio = shl( bpf_error_ratio, sub( 13, sub( 15, temp ) ) );
+ }
+ ELSE
+ {
+ bpf_error_ratio = ONE_IN_Q14; // Q13
+ move16();
+ }
+ bpf_error_ratio = add( mult( STEREO_DFT_BPF_ADAPT_BETA_FX, bpf_error_ratio ), mult( ( MAX_16 - STEREO_DFT_BPF_ADAPT_BETA_FX ), hStereoDft->bpf_error_ratio_mem_fx ) );
+ hStereoDft->bpf_error_ratio_mem_fx = bpf_error_ratio;
+ move16();
+
+ res_bpf_flag = (Word16) LT_16( bpf_error_ratio, ONE_IN_Q13 );
+ move16();
+
+ return res_bpf_flag;
+}
+
+void bpf_pitch_coherence_ivas_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const Word32 pitch_buf[] /* i : pitch for every subfr [0,1,2,3] Q20 */
+)
+{
+ Word16 nb_subfr;
+ Word32 pc, pcn1, pcn2, pcn3;
+ Word32 scaled_inv_L_frame; // Q8 + Q23
+
+ SWITCH( st->L_frame )
+ {
+ case 80:
+ scaled_inv_L_frame = 26843545; // 1/80 in Q31
+ move32();
+ BREAK;
+ case 160:
+ scaled_inv_L_frame = 13421773; // 1/160 in Q31
+ move32();
+ BREAK;
+ case 256:
+ scaled_inv_L_frame = 8388608; // 1/256 in Q31
+ move32();
+ BREAK;
+ case 320:
+ scaled_inv_L_frame = 6710886; // 1/320 in Q31
+ move32();
+ BREAK;
+ case 512:
+ scaled_inv_L_frame = 4194304; // 1/512 in Q31
+ move32();
+ BREAK;
+ case 640:
+ scaled_inv_L_frame = 3355443; // 1/640 in Q31
+ move32();
+ BREAK;
+ case 960:
+ scaled_inv_L_frame = 2236962; // 1/80 in Q31
+ move32();
+ BREAK;
+ default:
+ scaled_inv_L_frame = 0;
+ move32();
+ }
+
+ nb_subfr = shr( st->L_frame, 6 );
+ test();
+ IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && ( st->element_mode != EVS_MONO ) )
+ {
+ pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[nb_subfr + 1] ) ) );
+ pc = Mpy_32_32( pc, scaled_inv_L_frame );
+ pcn1 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX );
+ pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); // 4096 = 1 in Q12
+
+ pc = L_abs( L_sub( L_add( pitch_buf[nb_subfr - 1], pitch_buf[nb_subfr - 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) );
+ pc = Mpy_32_32( pc, scaled_inv_L_frame );
+ pcn2 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX );
+ pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); // 4096 = 1 in Q12
+
+ pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) );
+ pc = Mpy_32_32( pc, scaled_inv_L_frame );
+ pcn3 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX );
+ pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); // 4096 = 1 in Q12
+
+ IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 /*2.5f in Q12*/ ) )
+ {
+ st->hBPF->psf_att_fx = 13107; //.4 in Q15
+ move16(); /*Q15*/
+ set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr );
+ }
+ }
+
+ return;
+}
+
+
#ifdef ADD_BPF_ADAPT
/*---------------------------------------------------------------------*
* res_bpf_adapt()
diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c
index 3590dae71f9caf434f47e419f4ffcb37e4d4d672..ab349773ee6e3948dc03edf782479bb9e57ce3c5 100644
--- a/lib_dec/cng_dec_fx.c
+++ b/lib_dec/cng_dec_fx.c
@@ -6,7 +6,6 @@
#include "options.h" /* Compilation switches */
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_cnst.h"
@@ -1513,12 +1512,6 @@ static void shb_CNG_decod_fx(
}
ELSE
{
-#ifdef IVAS_CODE_CNG
- /* de-quantization of SHB CNG parameters */ To be verified
- L_tmp = L_mult( idx_ener_fx, 17615 ); /*Q13*/
- st_fx->last_shb_cng_ener_fx = extract_l( L_shr( L_sub( L_tmp, 147962 ), 5 ) ); /*Q8 */
- move16();
-#endif
}
}
}
@@ -1549,9 +1542,6 @@ static void shb_CNG_decod_fx(
Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */
-#ifdef IVAS_CODE_CNG
- // mvr2r(shb_lpcCNG, st->hTdCngDec->shb_lpcCNG, LPC_SHB_ORDER + 1);
-#endif
/* SHB energy estimation */
wb_ener_fx = L_deposit_l( 1 ); /*Q1 */
FOR( i = 0; i < L_FRAME32k; i++ )
@@ -1695,9 +1685,7 @@ static void shb_CNG_decod_fx(
L_tmp = L_deposit_h( tmp ); /*Q31 */
tmp = sub( add( 5, exp ), add( q, exp1 ) );
L_gain_fx = Isqrt_lc( L_tmp, &tmp ); /*Q31-Qtmp */
-#ifdef IVAS_CODE_CNG
- st->hTdCngDec->shb_cng_gain = ener_fx;
-#endif
+
FOR( i = 0; i < L_FRAME16k; i++ )
{
shb_syn16k_fx[i] = extract_l( L_shr( Mpy_32_16_1( L_gain_fx, excSHB_fx[i] ), sub( 5, tmp ) ) ); /*Q3 = 31-Qtmp-8-15-5+Qtmp */
@@ -1726,11 +1714,8 @@ static void shb_CNG_decod_fx(
{
interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st_fx->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 );
}
-#ifdef IVAS_CODE_CNG
- ResetSHBbuffer_Dec( st->hBWE_TD, st->extl );
-#else
+
ResetSHBbuffer_Dec_fx( st_fx );
-#endif
return;
}
@@ -2037,20 +2022,6 @@ void td_cng_dec_init_fx(
move16();
hTdCngDec->last_allow_cn_step = 0;
move16();
-#ifdef IVAS_CODE_CNG
- // mvr2r(st->lsp_old, st->lspCNG, M);
- // hTdCngDec->shb_cng_ener = -6.02f;
- IF( st->element_mode != EVS_MONO )
- {
- // set_f(hTdCngDec->shb_lpcCNG, 0.0f, LPC_SHB_ORDER + 1);
- // hTdCngDec->shb_lpcCNG[0] = 1.0f;
- // hTdCngDec->shb_cng_gain = -82.0; /* a dB value approximately corresponding to shb index 0(used as index -15) */
- }
- // hTdCngDec->wb_cng_ener = -6.02f;
- // hTdCngDec->last_wb_cng_ener = -6.02f;
- // hTdCngDec->last_shb_cng_ener = -6.02f;
- // hTdCngDec->swb_cng_seed = RANDOM_INITSEED;
-#endif
hTdCngDec->ho_hist_ptr = -1;
move16();
hTdCngDec->ho_sid_bw = L_deposit_l( 0 );
@@ -2081,26 +2052,6 @@ void td_cng_dec_init_fx(
set16_fx( hTdCngDec->exc_mem_fx, 0, 24 );
set16_fx( hTdCngDec->exc_mem1_fx, 0, 30 );
set32_fx( hTdCngDec->old_env_fx, 0, NUM_ENV_CNG );
-#ifdef IVAS_CODE_CNG
- // st->CNG_mode = -1;
- // for (i = 0; i < LPC_SHB_ORDER; i++)
- //{
- // IF (st->element_mode != EVS_MONO)
- // {
- // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)(i + 1)) / ((float)(LPC_SHB_ORDER + 1));
- // }
- // else
- // {
- // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)i) / ((float)LPC_SHB_ORDER);
- // }
- // hTdCngDec->lsp_shb_prev_prev[i] = hTdCngDec->lsp_shb_prev[i];
- // }
-
- // hTdCngDec->shb_dtx_count = 0;
- // hTdCngDec->trans_cnt = 0;
- // hTdCngDec->last_shb_ener = 0.001f;
- // set_f(hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN);
-#endif
hTdCngDec->burst_cnt = 0;
move16();
diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c
deleted file mode 100644
index 37c397bbf8c4ba8044d86fd7d321d3f04956186e..0000000000000000000000000000000000000000
--- a/lib_dec/core_dec_init.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "stat_com.h"
-#include "cnst.h"
-#include "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-/*-----------------------------------------------------------------------*
- * open_decoder_LPD()
- *
- * Initialization of state variables
- *-----------------------------------------------------------------------*/
-/*-----------------------------------------------------------------------*
- * tcxltp_dec_init()
- *
- * Initialization TCX-LTP handle
- *-----------------------------------------------------------------------*/
-/*-----------------------------------------------------------------------*
- * reset_tcx_overl_buf()
- *
- * Reset TCX core overlap buffers
- *-----------------------------------------------------------------------*/
-
-void reset_tcx_overl_buf_fx(
- TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */
-)
-{
- set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
- hTcxDec->Q_old_syn_Overl = 0;
- move16();
- set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
- hTcxDec->Q_syn_Overl_TDAC = 0;
- move16();
- set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
- hTcxDec->Q_syn_Overl = 0;
- move16();
- set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
- hTcxDec->Q_syn_Overl_TDACFB = 0;
- move16();
- return;
-}
-
-/*-----------------------------------------------------------------------*
- * acelp_plc_mdct_transition()
- *
- * Prepare MDCT OLA memories in TCX/HQ after ACELP PLC
- *-----------------------------------------------------------------------*/
diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c
index 671dbfd2ca520671ad8ab10abb004f32f8b055f2..dd268fe083ed61cdf5e23233a66d88a24d2148ae 100644
--- a/lib_dec/core_dec_init_fx.c
+++ b/lib_dec/core_dec_init_fx.c
@@ -7,7 +7,6 @@
#include
#include
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#include "basop_util.h"
#include "rom_com.h"
@@ -2191,3 +2190,28 @@ void open_decoder_LPD_ivas_fx(
return;
}
+
+/*-----------------------------------------------------------------------*
+ * reset_tcx_overl_buf()
+ *
+ * Reset TCX core overlap buffers
+ *-----------------------------------------------------------------------*/
+
+void reset_tcx_overl_buf_fx(
+ TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */
+)
+{
+ set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
+ hTcxDec->Q_old_syn_Overl = 0;
+ move16();
+ set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
+ hTcxDec->Q_syn_Overl_TDAC = 0;
+ move16();
+ set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
+ hTcxDec->Q_syn_Overl = 0;
+ move16();
+ set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
+ hTcxDec->Q_syn_Overl_TDACFB = 0;
+ move16();
+ return;
+}
diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c
index c7d2c526574e7a61c710be168e72836de7c5b81b..2fd3f1d2ec32c0b8b0308378c73062f344bbfe71 100644
--- a/lib_dec/core_dec_switch_fx.c
+++ b/lib_dec/core_dec_switch_fx.c
@@ -8,7 +8,6 @@
#include "basop_util.h"
#include "prot_fx.h"
#include "rom_com.h"
-#include "prot.h"
void mode_switch_decoder_LPD_fx(
Decoder_State *st, /* i/o: decoder state structure */
diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c
deleted file mode 100644
index 4c48a6fa870f591d77cb92bb17d7ba477ad7da55..0000000000000000000000000000000000000000
--- a/lib_dec/core_switching_dec.c
+++ /dev/null
@@ -1,1076 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "prot_fx.h"
-#include "ivas_cnst.h"
-#include "wmc_auto.h"
-
-#include "ivas_prot_fx.h"
-#include "debug.h"
-/*---------------------------------------------------------------------*
- * Local prototypes
- *---------------------------------------------------------------------*/
-
-
-/*---------------------------------------------------------------------*
- * core_switching_pre_dec()
- *
- * Preprocessing/preparation for ACELP/HQ core switching
- *---------------------------------------------------------------------*/
-ivas_error core_switching_pre_dec_ivas_fx(
- Decoder_State *st, /* i/o: decoder state structure */
- const Word16 output_frame, /* i : frame length */
- const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */
- const Word16 nchan_out, /* i : number of output channels */
- const Word16 last_element_mode, /* i : last_element_mode */
- const Word32 last_element_brate, /* i : last element bitrate */
- Word16 Q_old_synthFB,
- Word16 *Q_olapBufferSynth,
- Word16 *Q_olapBufferSynth2 )
-{
- Word32 tmp_fx; /*Q-12*/
- Word16 i, oldLenClasBuff, newLenClasBuff;
- ivas_error error;
- Word16 exp = 25;
- move16();
- error = IVAS_ERR_OK;
- move32();
-
- /* Codec mode switching */
- test();
- test();
- test();
- IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && ( st->element_mode > EVS_MONO ) ) )
- {
- st->mem_deemph_fx = st->syn[M];
- move16();
- set16_fx( st->agc_mem_fx, 0, 2 );
- Scale_sig( &( st->mem_deemph_fx ), 1, st->Q_syn ); /* Brings mem_deemph to Qsyn */
-
- Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/
-
- st->bpf_off = 1;
- move16();
- IF( st->hPFstat != NULL )
- {
- Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/
- Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem , Q_syn*/
- Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/
- set16_fx( st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/
- }
- IF( st->hBPF != NULL )
- {
- st->hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */
- st->hBPF->pst_mem_deemp_err_fx = 0;
- move16();
- move16();
- }
- st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); // Q(23+1-16)->Q8
- move16();
-
- /* reset old HB synthesis buffer */
- IF( EQ_16( st->last_L_frame, L_FRAME ) )
- {
- st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS );
- }
- ELSE
- {
- st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS );
- }
- move16();
- set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) );
-
- test();
- IF( st->hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) )
- {
-#ifdef MSAN_FIX
- st->hBWE_TD->prev_hb_synth_fx_exp = 31;
- move16();
-#endif // MSAN_FIX
- /* reset BWE memories */
- set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
- st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
- move32();
- }
-
- /* reset upd_cnt */
- st->upd_cnt = MAX_UPD_CNT;
- move16();
-
- st->igf = 0;
- move16();
-
- test();
- IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
- {
- hf_synth_reset_fx( st->hBWE_zero );
-#ifdef MSAN_FIX
- set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
-#endif
- }
-
- IF( st->hBWE_FD != NULL )
- {
- set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
- }
-
- IF( st->hHQ_core != NULL )
- {
- set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB );
- set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB );
-
- set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
- set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
-
- st->hHQ_core->last_max_pos_pulse = 0;
- move16();
-
- IF( GT_32( st->output_Fs, 16000 ) )
- {
- set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
- }
-
- /* pre-echo */
- st->hHQ_core->pastpre = 0;
- move16();
- }
-
- /* reset the GSC pre echo energy threshold in case of switching */
- if ( st->hGSCDec != NULL )
- {
- st->hGSCDec->Last_frame_ener_fx = MAX_32;
- move32();
- }
-
- test();
- IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) )
- {
- IF( st->element_mode == EVS_MONO )
- {
- st->last_core = HQ_CORE;
- move16();
-
- Copy32( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer32_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
- // Copy_Scale_sig_32_16( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); //Q11 -> Q0
- }
-
- IF( st->hHQ_core != NULL )
- {
- set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
- set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
- st->hHQ_core->last_max_pos_pulse = 0;
- move16();
-
- set16_fx( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM );
- st->hHQ_core->prev_frm_hfe2 = 0;
- st->hHQ_core->prev_stab_hfe2 = 0;
- move16();
- move16();
- }
- }
-
- IF( st->prev_bfi != 0 )
- {
- Word16 delay_comp;
-
- /*switch off Hq Voicing as it was not updated in MODE2*/
- IF( st->hHQ_core != NULL )
- {
- st->hHQ_core->oldHqVoicing = 0;
- st->hHQ_core->HqVoicing = 0;
- move16();
- move16();
- }
-
- delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
- /*TODO To be tested:control not entering the block*/
- test();
- test();
- IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) )
- {
- /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/
- assert( 0 );
- Word32 *realBuffer_fx[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer_fx[CLDFB_NO_COL_MAX_SWITCH];
- Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX];
- Word32 syn_Overl_fx[320];
- Word32 fer_samples_fx[960];
- Copy_Scale_sig_16_32_DEPREC( st->hTcxDec->syn_Overl, syn_Overl_fx, 320, 15 );
- Copy_Scale_sig_16_32_DEPREC( st->hHQ_core->fer_samples_fx, fer_samples_fx, 960, 15 );
-
-
- FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ )
- {
- set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
- set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
- realBuffer_fx[i] = realBufferTmp_fx[i];
- imagBuffer_fx[i] = imagBufferTmp_fx[i];
- }
-
- /* CLDFB analysis of the synthesis at internal sampling rate */
- IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
-
- cldfbAnalysis_ivas_fx( syn_Overl_fx, realBuffer_fx, imagBuffer_fx, delay_comp, st->cldfbAna );
- cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/
-
- /* CLDFB synthesis of the combined signal */
- IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
-
- cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, st->cldfbSyn );
- cldfb_restore_memory_ivas_fx( st->cldfbSyn );
- Copy_Scale_sig_32_16( syn_Overl_fx, st->hTcxDec->syn_Overl, 320, 15 );
- Copy_Scale_sig_32_16( fer_samples_fx, st->hHQ_core->fer_samples_fx, 960, 9 );
- }
-
- test();
- test();
- IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) )
- {
- lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) );
- /*Set to zero the remaining part*/
- set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) );
- }
- }
-
- st->use_acelp_preq = 0;
- st->reset_mem_AR = 0;
- move16();
- move16();
- }
-
- /*FEC*/
- IF( LE_16( st->L_frame, L_FRAME16k ) )
- {
- test();
- IF( LE_16( st->last_L_frame, L_FRAME16k ) && NE_16( st->core, HQ_CORE ) )
- {
- IF( NE_16( st->L_frame, st->last_L_frame ) )
- {
- IF( GT_16( st->L_frame, st->last_L_frame ) )
- {
- oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) );
- newLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
- move16();
- }
- ELSE
- {
- oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
- move16();
- newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) );
- }
- lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff );
- }
- }
- ELSE
- {
- set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM );
- }
- }
-
- /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores
- within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */
- test();
- test();
- IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) )
- {
- st->last_ppp_mode_dec = 0;
- st->last_nelp_mode_dec = 0;
- move16();
- move16();
- }
-
- /* Handle state reset of stat_noise_uv_mod memory */
- test();
- test();
- test();
- IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) )
- {
- st->act_count = 3;
- st->uv_count = 0;
- move16();
- move16();
- }
-
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) &&
- NE_32( st->core_brate, SID_2k40 ) && ( st->core_brate != FRAME_NO_DATA ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) )
- {
- test();
- if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) )
- {
- st->hPFstat->reset = 1;
- move16();
- }
-
- IF( EQ_16( st->L_frame, L_FRAME16k ) )
- {
- Copy( TRWB2_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */
- Copy( TRWB2_Ave_fx, st->lsfoldbfi1_fx, M );
- Copy( TRWB2_Ave_fx, st->lsfoldbfi0_fx, M );
- Copy( TRWB2_Ave_fx, st->lsf_adaptive_mean_fx, M );
- lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_16k );
- }
- ELSE
- {
- Copy( TRWB_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */
- Copy( TRWB_Ave_fx, st->lsfoldbfi1_fx, M );
- Copy( TRWB_Ave_fx, st->lsfoldbfi0_fx, M );
- Copy( TRWB_Ave_fx, st->lsf_adaptive_mean_fx, M );
- lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_12k8 );
- }
-
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL )
- {
- /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */
- set16_fx( st->hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 );
- set16_fx( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, 0, FFTLEN );
- set16_fx( st->agc_mem_fx, 0, 2 );
- }
- st->mem_deemph_fx = 0;
- move16();
- IF( !st->last_con_tcx )
- {
- set16_fx( st->mem_syn2_fx, 0, M );
- }
- set16_fx( st->mem_syn1_fx, 0, M );
- if ( st->hBWE_TD != NULL )
- {
- st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
- move32();
- }
-
- /* Reset ACELP parameters */
- set16_fx( st->mem_MA_fx, 0, M );
-
- IF( EQ_32( st->sr_core, INT_FS_16k ) )
- {
- Copy( GEWB2_Ave_fx, st->mem_AR_fx, M );
- }
- ELSE
- {
- Copy( GEWB_Ave_fx, st->mem_AR_fx, M );
- }
-
- st->tilt_code_fx = 0;
- st->gc_threshold_fx = 0;
- st->dm_fx.prev_gain_code = 0;
- st->dm_fx.prev_state = 0;
- move16();
- move32();
- move32();
- move16();
- set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
-
- st->last_coder_type = GENERIC;
- move16();
-
- fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/
- st->lp_gainp_fx = 0;
- move16();
- st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/
- move16();
- st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/
- move16();
-
- st->last_voice_factor_fx = 0;
- st->Last_GSC_noisy_speech_flag = 0;
- move16();
- move16();
-
- /* reset CLDFB memories */
- cldfb_reset_memory_fx( st->cldfbAna );
- cldfb_reset_memory_fx( st->cldfbBPF );
- cldfb_reset_memory_fx( st->cldfbSyn );
-
- /* reset TBE memories */
- test();
- test();
- IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && ( st->element_mode > EVS_MONO ) ) )
- {
- set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC );
- }
- ELSE IF( LT_16( st->L_frame, L_FRAME16k ) )
- {
- /* resample from 16kHz to 12.8kHZ */
- synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC );
- }
-
- IF( st->hBWE_TD != NULL )
- {
- set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
- }
-
- test();
- IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
- {
- hf_synth_reset_fx( st->hBWE_zero );
-#ifdef MSAN_FIX
- set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
-#endif
- }
-
- IF( st->hBWE_FD != NULL )
- {
- set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
- }
- }
-
- test();
- test();
- test();
- IF( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) )
- {
- IF( st->hBWE_TD != NULL )
- {
- st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
- move32();
- set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
- }
-
- st->tilt_code_fx = 0;
- st->gc_threshold_fx = 0;
- st->dm_fx.prev_gain_code = 0;
- st->dm_fx.prev_state = 0;
- move16();
- move32();
- move32();
- move16();
- set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
- st->last_coder_type = GENERIC;
- move16();
- fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/
-
- st->lp_gainp_fx = 0;
- move16();
- st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/
- move16();
- st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/
- move16();
-
- st->last_voice_factor_fx = 0;
- st->Last_GSC_noisy_speech_flag = 0;
- move16();
- move16();
-
- test();
- IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
- {
- hf_synth_reset_fx( st->hBWE_zero );
-#ifdef MSAN_FIX
- set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
-#endif
- }
-
- IF( st->hBWE_FD != NULL )
- {
- set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
- }
-
- test();
- test();
- test();
- IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) )
- {
- /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */
- Word16 offset;
- offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels );
- Word32 *old_synthFB_fx;
- IF( ( old_synthFB_fx = (Word32 *) malloc( st->hTcxDec->old_synth_lenFB * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) );
- }
-#ifdef FIX_ISSUE_1237
- Copy_Scale_sig_16_32_no_sat( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10
-#else
- Copy_Scale_sig_16_32_DEPREC( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10
-#endif
- Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset );
- st->cldfbAna->Q_cldfb_state = Q10;
- move16();
- IF( old_synthFB_fx )
- free( old_synthFB_fx );
- }
- }
-
- test();
- test();
- test();
- test();
- IF( EQ_16( st->core, HQ_CORE ) && ( ( st->last_core == ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( ( st->element_mode != EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) )
- {
- set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB );
- set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB );
-
- set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
- set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
- st->hHQ_core->last_max_pos_pulse = 0;
- move16();
-
- set16_fx( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM );
- st->hHQ_core->prev_frm_hfe2 = 0;
- st->hHQ_core->prev_stab_hfe2 = 0;
- move16();
- move16();
- IF( GT_32( st->output_Fs, 16000 ) )
- {
- set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
- }
-
- IF( st->element_mode != EVS_MONO )
- {
- /* Estimate mem_env_delta to reinit env_stab */
- tmp_fx = L_max( 0, L_add( ENV_STAB_EST1_FX, L_add( Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ), Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ) ) ); /*Q12*/
-
- st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */
- move16();
- test();
- IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) )
- {
- set16_fx( st->hHQ_core->old_out_fx, 0, output_frame );
- set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k );
- set16_fx( st->hHQ_core->old_out_LB_fx, 0, L_FRAME16k );
- }
-
- st->hHQ_core->no_att_hangover = 0;
- move16();
- st->hHQ_core->energy_lt_fx = 2457600; /*300.0f Q13*/
- move32();
- set16_fx( st->hHQ_core->old_is_transient, 0, 3 );
- set16_fx( st->hHQ_core->prev_noise_level_fx, 0, 2 );
- st->hHQ_core->prev_R = 0;
- move16();
- set16_fx( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 );
- st->hHQ_core->prev_hqswb_clas = HQ_NORMAL;
- st->hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/
- move16();
- move16();
- set16_fx( st->hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS );
- }
- ELSE
- {
- set16_fx( st->hHQ_core->old_out_fx, 0, output_frame );
- set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k );
- }
- }
-
- /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */
- IF( st->hHQ_core != NULL )
- {
- st->hHQ_core->pastpre = sub( st->hHQ_core->pastpre, 1 );
- move16();
- IF( st->hHQ_core->pastpre < 0 )
- {
- reset_preecho_dec_fx( st->hHQ_core );
- }
- }
- test();
- IF( st->core_brate == FRAME_NO_DATA )
- {
- st->VAD = 0;
- st->m_frame_type = ZERO_FRAME;
- }
- ELSE IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, SID_1k75 ) )
- {
- st->VAD = 0;
- st->m_frame_type = SID_FRAME;
- }
- ELSE
- {
- st->VAD = 1;
- st->m_frame_type = ACTIVE_FRAME;
- }
-
- move16();
- move16();
- /*switch on CNA on active frames*/
- IF( ( st->element_mode == EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */
- {
- test();
- test();
- test();
- test();
- test();
- test();
- IF( st->VAD && ( ( NE_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, CNA_MAX_BRATE ) ) || ( EQ_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, ACELP_8k85 ) ) ) )
- {
- st->flag_cna = 1;
- move16();
- }
- ELSE IF( st->VAD || ( EQ_16( st->cng_type, FD_CNG ) && EQ_16( st->L_frame, L_FRAME16k ) ) )
- {
- st->flag_cna = 0;
- move16();
- }
- }
-
- if ( EQ_16( st->core, AMR_WB_CORE ) )
- {
- st->cng_type = LP_CNG;
- move16();
- }
-
- /* Reconfigure CNG */
- test();
- test();
- test();
- test();
- IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || ( st->ini_frame == 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) )
- {
- /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/
- IF( NE_16( st->core, AMR_WB_CORE ) )
- {
- test();
- IF( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) )
- {
- configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, ACELP_9k60, st->L_frame, st->last_L_frame, st->element_mode );
- }
- ELSE
- {
- configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode );
- }
- }
- ELSE
- {
- configureFdCngDec_ivas_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode );
-
- if ( st->VAD )
- {
- st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate;
- move32();
- }
- }
- test();
- test();
- IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->L_frame, L_FRAME16k ) && LE_16( st->last_L_frame, L_FRAME16k ) )
- {
- test();
- IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) )
- {
- lerp( st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->L_frame, st->L_frame, st->last_L_frame );
- }
-
- L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 );
-
- test();
- IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) )
- {
- L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth );
-
- IF( EQ_16( st->L_frame, L_FRAME ) )
- {
- FOR( i = 0; i < ( st->L_frame * 2 ); i++ )
- {
- st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ );
- move32();
- }
- }
- ELSE
- {
- FOR( i = 0; i < ( st->L_frame * 2 ); i++ )
- {
- st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ );
- move32();
- }
- }
- }
- }
- }
-
- return error;
-}
-/*---------------------------------------------------------------------*
- * core_switching_hq_prepare_dec()
- *
- * Preprocessing in the first HQ frame after ACELP frame
- * Modify bit allocation for HQ core by removing ACELP subframe budget
- *---------------------------------------------------------------------*/
-
-/*---------------------------------------------------------------------*
- * bandwidth_switching_detect()
- *
- * Classification for band-width switching
- *---------------------------------------------------------------------*/
-
-void bandwidth_switching_detect_ivas_fx(
- Decoder_State *st_fx /* i/o: encoder state structure */
-)
-{
- test();
- test();
- IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) )
- {
- /* there is no BWE in TD stereo secondary channel and in MDCT stereo, IGF is part of the core decoding -> no BW switching -> reset BWS counters */
- st_fx->prev_bws_cnt = 0;
- st_fx->bws_cnt = 0;
- st_fx->bws_cnt1 = 0;
- move16();
- move16();
- move16();
-
- return;
- }
- /* update band-width switching counter */
- test();
- test();
- test();
- test();
- IF( GE_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) )
- {
- st_fx->bws_cnt1 = 0;
- move16();
- }
- ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) && ( st_fx->last_low_rate_mode == 0 ) )
- {
- st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 );
- move16();
- }
- ELSE IF( st_fx->bws_cnt1 > 0 )
- {
- IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) )
- {
- st_fx->bws_cnt = sub( shl( sub( N_NS2W_FRAMES, st_fx->bws_cnt1 ), 1 ), 1 );
- move16();
- }
- ELSE
- {
- st_fx->bws_cnt = 0;
- move16();
- }
-
- IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) )
- {
- st_fx->bws_cnt1 = 0;
- move16();
- }
- ELSE
- {
- IF( EQ_16( st_fx->bwidth, SWB ) )
- {
- st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 );
- move16();
- }
- ELSE
- {
- st_fx->bws_cnt1 = 0;
- move16();
- }
- }
- }
-
- /* update band-width switching counter */
- test();
- test();
- test();
- IF( GE_16( st_fx->bws_cnt, N_WS2N_FRAMES ) )
- {
- st_fx->bws_cnt = 0;
- move16();
- }
- ELSE IF( LT_32( st_fx->total_brate, ACELP_9k60 ) && GT_32( st_fx->last_core_brate, ACELP_9k60 ) && LT_16( st_fx->bwidth, st_fx->last_bwidth ) && EQ_16( st_fx->bwidth, WB ) )
- {
- st_fx->bws_cnt = add( st_fx->bws_cnt, 1 );
- move16();
- }
- ELSE IF( st_fx->bws_cnt > 0 )
- {
- IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) )
- {
- st_fx->bws_cnt1 = shr( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 1 );
- move16();
- }
- ELSE
- {
- st_fx->bws_cnt1 = 0;
- move16();
- }
-
- IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) )
- {
- st_fx->bws_cnt = 0;
- move16();
- }
- ELSE
- {
- IF( EQ_16( st_fx->bwidth, WB ) )
- {
- st_fx->bws_cnt = add( st_fx->bws_cnt, 1 );
- move16();
- }
- ELSE
- {
- st_fx->bws_cnt = 0;
- move16();
- }
- }
- }
-
- return;
-}
-
-
-/*---------------------------------------------------------------------*
- * bw_switching_pre_proc()
- *
- * Band-width switching pre-processing
- *---------------------------------------------------------------------*/
-void ivas_bw_switching_pre_proc_fx(
- Decoder_State *st, /* i/o: decoder state structure */
- const Word32 last_element_brate, /* i : last element bitrate */
- const Word16 nchan_out /* i : number of output channels */,
- Word32 *old_syn_12k8_16k_fx,
- Word16 Q,
- Word16 Q_audio )
-{
- Word16 i;
- Word32 syn_dct_fx[L_FRAME];
-
-
- Flag Overflow = 0;
- move32();
-
- IF( st->element_mode > EVS_MONO )
- {
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) )
- {
- /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */
- Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k];
- Copy_Scale_sig_32_16( old_syn_12k8_16k_fx, old_syn_12k8_16k_tmp_16fx, st->L_frame, sub( -1, Q ) );
- st->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st->L_frame ), sub( Q, 8 ) ) ); // Q24+(Q-8) - 16
- move16();
- }
-
- return;
- }
-
-
- test();
- test();
- IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) )
- {
- /*----------------------------------------------------------------------*
- * Calculate tilt of the ACELP core synthesis
- *----------------------------------------------------------------------*/
-
- st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame );
- move16();
- /*-------------------------------------------------------------------------------*
- * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis
- *-------------------------------------------------------------------------------*/
- edct_fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q );
- Word64 W_tmp = 0;
- move64();
- Word32 tmp;
- Word16 shift;
- FOR( i = 0; i < L_FRAME / 2; i++ )
- {
- W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) );
- }
- shift = W_norm( W_tmp );
- W_tmp = W_shl( W_tmp, shift );
- tmp = W_extract_h( W_tmp );
- tmp = L_shr( tmp, 8 );
-
- tmp = getSqrtWord32( tmp );
- st->enerLL_fx = tmp;
- move32();
- st->enerLL_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 );
- move16();
- W_tmp = 0;
- move64();
- FOR( ; i < L_FRAME; i++ )
- {
- W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) );
- }
- shift = W_norm( W_tmp );
- W_tmp = W_shl( W_tmp, shift );
- tmp = W_extract_h( W_tmp ); // Q = Q + shift - 32
- tmp = L_shr( tmp, 7 ); // divide by 128
- tmp = getSqrtWord32( tmp );
- st->enerLH_fx = tmp;
- move32();
- st->enerLH_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 );
- move16();
- }
- ELSE
- {
- IF( st->hHQ_core->old_is_transient[0] )
- {
- Word32 tmp, L_tmp = 0;
- move32();
- FOR( i = 0; i < 32; i++ )
- {
- L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
- }
- tmp = L_shr( L_tmp, 5 ); // divide by 32
- tmp = getSqrtWord32( tmp );
- st->enerLL_fx = tmp;
- move32();
- st->enerLL_fx_Q = Q_audio;
- move16();
-
- L_tmp = 0;
- move32();
- FOR( ; i < 64; i++ )
- {
- L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
- }
-
- tmp = L_shr( L_tmp, 5 ); // divide by 32
- tmp = getSqrtWord32( tmp );
- st->enerLH_fx = tmp;
- move32();
- st->enerLH_fx_Q = Q_audio;
- move16();
- }
- ELSE
- {
- Word32 tmp, L_tmp = 0;
- move32();
- FOR( i = 0; i < L_FRAME / 2; i++ )
- {
- L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
- }
- tmp = L_shr( L_tmp, 5 ); // divide by 32
- tmp = getSqrtWord32( tmp );
- st->enerLL_fx = tmp;
- move32();
- st->enerLL_fx_Q = Q_audio;
- move16();
-
- L_tmp = 0;
- move32();
- FOR( ; i < L_FRAME; i++ )
- {
- L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
- }
- tmp = L_shr( L_tmp, 5 ); // divide by 32
- tmp = getSqrtWord32( tmp );
- st->enerLL_fx = tmp;
- move32();
- st->enerLL_fx_Q = Q_audio;
- move16();
- }
- }
-
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) )
- {
-
- st->prev_ener_shb_fx = 0;
- move16();
- IF( st->hBWE_FD != NULL )
- {
- set16_fx( st->prev_SWB_fenv_fx, 0, SWB_FENV );
- }
- }
- ELSE IF( ( ( ( st->core == ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) )
- {
- st->attenu_fx = 3277; // 0.1f in Q15
- move16();
- }
-
- test();
- test();
- test();
- test();
- test();
- if ( EQ_16( st->last_core, HQ_CORE ) || ( ( st->last_core == ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) )
- {
- st->prev_fractive = 0;
- move16();
- }
-
- return;
-}
-/*---------------------------------------------------------------------*
- * core_switch_lb_upsamp()
- *
- * Resample HQ/TCX-LB to the output sampling rate (8/16/32/48 kHz)
- *---------------------------------------------------------------------*/
-
-
-/*---------------------------------------------------------------------*
- * smoothTransitionDtxToTcx()
- *
- * apply smoothing to the transition part for inactive to active transitions in DTX
- *---------------------------------------------------------------------*/
-
-#define TRANSITION_SMOOTHING_LEN_16k 15
-#define TRANSITION_SMOOTHING_LEN_32k 31
-#define TRANSITION_SMOOTHING_LEN_48k 47
diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c
index 17df8b5ca95b3054abcf4109bb92b63cd55ad32a..17b3f9fbce087c9e1e928e102fcea636877ceaa8 100644
--- a/lib_dec/core_switching_dec_fx.c
+++ b/lib_dec/core_switching_dec_fx.c
@@ -16,10 +16,6 @@
*
*
*---------------------------------------------------------------------*/
-#ifdef IVAS_CODE_SWITCHING
-static void core_switch_lb_upsamp( Decoder_State *st, float *output );
-static void smoothTransitionDtxToTcx( float synth[], const int16_t output_frame, const int16_t delay_comp );
-#endif
static void smoothTransitionDtxToTcx_fx( Word16 synth[], const Word16 output_frame, const Word16 delay_comp );
static void core_switch_lb_upsamp_fx( Decoder_State *st, Word32 *output );
@@ -189,30 +185,11 @@ void bw_switching_pre_proc_fx(
Flag Overflow = 0;
move32();
#endif
-#ifdef IVAS_CODE_SWITCHING
+
IF( st_fx->element_mode > EVS_MONO )
{
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( EQ_16( st_fx->core, ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) &&
- st_fx->hBWE_FD != NULL && !( LE_16( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) &&
- !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st_fx->idchan, 1 ) && LE_16( last_element_brate, IVAS_SID_4k4 ) ) )
- {
- /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */
- calc_tilt_bwe( old_syn_12k8_16k, &st->tilt_wb, st->L_frame );
- }
-
- return;
}
-#endif
+
test();
test();
IF( EQ_16( st_fx->core, ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) )
@@ -321,149 +298,7 @@ void bw_switching_pre_proc_fx(
return;
}
-#ifdef IVAS_CODE_SWITCHING
-
-
-/*---------------------------------------------------------------------*
- * core_switch_lb_upsamp()
- *
- * Resample HQ/TCX-LB to the output sampling rate (8/16/32/48 kHz)
- *---------------------------------------------------------------------*/
-
-static void core_switch_lb_upsamp(
- Decoder_State *st, /* i/o: Decoder state */
- float *output /* i/o: LB synth/upsampled LB synth */
-)
-{
- int16_t i;
- float *realBuffer[CLDFB_OVRLP_MIN_SLOTS], *imagBuffer[CLDFB_OVRLP_MIN_SLOTS];
- float realBufferTmp[CLDFB_OVRLP_MIN_SLOTS][CLDFB_NO_CHANNELS_MAX];
- float imagBufferTmp[CLDFB_OVRLP_MIN_SLOTS][CLDFB_NO_CHANNELS_MAX];
-
- /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
- for ( i = 0; i < CLDFB_OVRLP_MIN_SLOTS; i++ )
- {
- set_f( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
- set_f( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
- realBuffer[i] = realBufferTmp[i];
- imagBuffer[i] = imagBufferTmp[i];
- }
-
- /* check if the CLDFB works on the right sample rate */
- if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame )
- {
- resampleCldfb( st->cldfbAna, st->L_frame * FRAMES_PER_SEC );
-
- if ( st->cldfbBPF != NULL && st->L_frame <= L_FRAME16k )
- {
- resampleCldfb( st->cldfbBPF, st->L_frame * FRAMES_PER_SEC );
- }
-
- if ( st->ini_frame > 0 )
- {
- st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels;
- }
- }
-
- /* analysis of the synthesis at internal sampling rate */
- cldfbAnalysis( output, realBuffer, imagBuffer, CLDFB_OVRLP_MIN_SLOTS * st->cldfbAna->no_channels, st->cldfbAna );
-
- /* analysis and add the BPF error signal */
- if ( st->p_bpf_noise_buf )
- {
- addBassPostFilter( st->p_bpf_noise_buf, st->bpf_off ? 0 : CLDFB_OVRLP_MIN_SLOTS * st->cldfbBPF->no_channels, realBuffer, imagBuffer, st->cldfbBPF );
- }
-
- /* set output mask for upsampling */
- if ( st->bwidth == NB )
- {
- /* set NB mask for upsampling */
- st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - 10;
- }
- else if ( st->cldfbSyn->bandsToZero != st->cldfbSyn->no_channels - st->cldfbAna->no_channels )
- {
- /* in case of BW switching, re-init to default */
- st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels;
- }
-
- /* synthesis of the combined signal */
- cldfbSynthesis( realBuffer, imagBuffer, output, CLDFB_OVRLP_MIN_SLOTS * st->cldfbSyn->no_channels, st->cldfbSyn );
-
- /* save synthesis - needed in case of core switching */
- if ( st->hTcxDec != NULL )
- {
- mvr2r( output, st->previoussynth, st->hTcxDec->L_frameTCX );
- }
-
- return;
-}
-
-/*---------------------------------------------------------------------*
- * smoothTransitionMdctStereoDtx()
- *
- * apply smoothing to the transition part for MDCT-Stereo DTX
- *---------------------------------------------------------------------*/
-
-#define TRANSITION_SMOOTHING_LEN_16k 15
-#define TRANSITION_SMOOTHING_LEN_32k 31
-#define TRANSITION_SMOOTHING_LEN_48k 47
-
-static void smoothTransitionMdctStereoDtx(
- float synth[], /* i/o: synthesis */
- const int16_t output_frame, /* i : output frame length */
- const int16_t delay_comp /* i : delay compensation in samples */
-)
-{
- int16_t i, filter_len;
- float w, mem, step, fade_in;
- float smoothing_input_buffer[2 * NS2SA( 48000, DELAY_CLDFB_NS ) + TRANSITION_SMOOTHING_LEN_48k];
- float smoothing_out_buffer[2 * NS2SA( 48000, DELAY_CLDFB_NS ) + TRANSITION_SMOOTHING_LEN_48k];
-
- filter_len = TRANSITION_SMOOTHING_LEN_16k;
- if ( output_frame == L_FRAME32k )
- {
- filter_len = TRANSITION_SMOOTHING_LEN_32k;
- }
- else if ( output_frame == L_FRAME48k )
- {
- filter_len = TRANSITION_SMOOTHING_LEN_48k;
- }
-
- /* prepare buffer */
- for ( i = 0; i < filter_len / 2; i++ )
- {
- smoothing_input_buffer[i] = synth[0];
- }
- mvr2r( synth, smoothing_input_buffer + filter_len / 2, 2 * delay_comp + filter_len / 2 );
-
- /* apply Mean filter */
- w = 1.f / filter_len;
- mem = sum_f( smoothing_input_buffer, filter_len );
- for ( i = 0; i < 2 * delay_comp; i++ )
- {
- smoothing_out_buffer[i] = w * mem;
- mem = mem - smoothing_input_buffer[i] + smoothing_input_buffer[i + filter_len];
- }
-
- /* apply fades around transition */
- step = 1.f / delay_comp;
- fade_in = 0.f;
- for ( i = 0; i < delay_comp; i++ )
- {
- synth[i] = smoothing_out_buffer[i] * fade_in + synth[i] * ( 1 - fade_in );
- fade_in += step;
- }
-
- fade_in = 0.f;
- for ( ; i < 2 * delay_comp; i++ )
- {
- synth[i] = synth[i] * fade_in + smoothing_out_buffer[i] * ( 1 - fade_in );
- fade_in += step;
- }
- return;
-}
-#endif
/*---------------------------------------------------------------------*
* core_switching_pre_dec_fx()
*
@@ -738,13 +573,7 @@ ivas_error core_switching_pre_dec_fx(
test();
test();
- IF( ( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) )
- //#ifdef IVAS_CODE_SWITCHING
- // || ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD) ||
- // (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && last_element_mode == IVAS_CPE_DFT)) && EQ_16(nchan_out,2) &&
- // NE_16(st_fx->core_brate, SID_2k40) && NE_16(st_fx->core_brate, FRAME_NO_DATA) && (EQ_16(last_core_brate_st0, FRAME_NO_DATA) || EQ_16(last_core_brate_st0, SID_2k40)))
- //#endif
- )
+ IF( ( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) )
{
test();
IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) )
@@ -770,14 +599,7 @@ ivas_error core_switching_pre_dec_fx(
lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX );
}
-#ifdef IVAS_CODE_SWITCHING
- if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && nchan_out == 2 && st->core_brate > SID_2k40 && ( last_core_brate_st0 == FRAME_NO_DATA || last_core_brate_st0 == SID_2k40 ) && st->hTcxDec != NULL )
- {
- /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */
- set_f( st->hTcxDec->old_syn_Overl, 0.0f, L_FRAME32k / 2 );
- set_f( st->hFdCngDec->hFdCngCom->olapBufferAna, 0.0f, FFTLEN );
- }
-#endif
+
set16_fx( st_fx->agc_mem_fx, 0, 2 );
st_fx->mem_deemph_fx = 0;
move16();
@@ -876,47 +698,7 @@ ivas_error core_switching_pre_dec_fx(
set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) );
}
}
-#ifdef IVAS_CODE_SWITCHING
- if ( ( st->core == ACELP_CORE || st->core == AMR_WB_CORE ) && ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) )
- {
- if ( st->hBWE_TD != NULL )
- {
- st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f;
- set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 );
- }
-
- st->tilt_code = 0.0f;
- st->gc_threshold = 0.0f;
- set_f( st->dispMem, 0, 8 );
- st->last_coder_type = GENERIC;
-
- fer_energy( output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1 );
- st->lp_gainp = 0.0f;
- st->lp_gainc = (float) sqrt( st->lp_ener );
-
- st->last_voice_factor = 0;
- st->Last_GSC_noisy_speech_flag = 0;
-
- if ( st->output_Fs >= 16000 && st->hBWE_zero != NULL )
- {
- hf_synth_reset( st->hBWE_zero );
- }
-
- if ( st->hBWE_FD != NULL )
- {
- set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
- }
-
- if ( nchan_out == 1 && st->element_mode == IVAS_CPE_DFT && st->element_brate <= IVAS_24k4 && last_element_brate > IVAS_24k4 )
- {
- /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */
- int16_t offset;
- offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels;
- mvr2r( st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state, offset );
- }
- }
-#endif
test();
test();
test();
@@ -941,40 +723,16 @@ ivas_error core_switching_pre_dec_fx(
{
set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
}
-#ifdef IVAS_CODE_SWITCHING
- if ( st->element_mode != EVS_MONO )
- {
- /* Estimate mem_env_delta to reinit env_stab */
- tmp = max( 0, ENV_STAB_EST1 + ( ENV_STAB_EST2 * st->stab_fac_smooth_lt ) + ( ENV_STAB_EST3 * st->log_energy_diff_lt ) );
- st->hHQ_core->mem_env_delta = (int16_t) min( MAX16B, (int32_t) ( tmp * ( 1 << 12 ) ) ); /* Convert to Q12 and handle saturation */
-
- if ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE )
- {
- set_f( st->hHQ_core->old_out, 0, output_frame );
- set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k );
- }
-
- st->hHQ_core->no_att_hangover = 0;
- st->hHQ_core->energy_lt = 300.0f;
- set_s( st->hHQ_core->old_is_transient, 0, 3 );
- set_f( st->hHQ_core->prev_noise_level, 0.0f, 2 );
- st->hHQ_core->prev_R = 0;
- set_s( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 );
- st->hHQ_core->prev_hqswb_clas = HQ_NORMAL;
- st->hHQ_core->prev_ni_ratio = 0.5f;
- set_f( st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS );
+ if ( st_fx->element_mode != EVS_MONO )
+ {
}
else
-#endif
{
set16_fx( hHQ_core->old_out_fx, 0, output_frame );
hHQ_core->Q_old_wtda_LB = 15;
hHQ_core->Q_old_wtda = 15;
move16();
-#ifdef IVAS_CODE_SWITCHING
- set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k );
-#endif
}
}
@@ -1081,12 +839,10 @@ ivas_error core_switching_pre_dec_fx(
IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && LE_16( st_fx->L_frame, L_FRAME16k ) && LE_16( st_fx->last_L_frame, L_FRAME16k ) )
{
test();
-#ifdef IVAS_CODE_SWITCHING
IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) )
{
- lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferAna + st_fx->last_L_frame, st_fx->hFdCngDec->hFdCngCom->olapBufferAna + st_fx->L_frame, st_fx->L_frame, st_fx->last_L_frame );
}
-#endif
+
lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st_fx->L_frame, 1 ), shl( st_fx->last_L_frame, 1 ) );
test();
IF( LE_32( st_fx->total_brate, SID_2k40 ) && LE_32( st_fx->last_total_brate, SID_2k40 ) )
@@ -1122,22 +878,12 @@ ivas_error core_switching_pre_dec_fx(
*---------------------------------------------------------------------*/
ivas_error core_switching_post_dec_fx(
- Decoder_State *st_fx, /* i/o: decoder state structure */
- Word16 *synth, /* i/o: output synthesis Qsynth*/
-#ifdef IVAS_CODE_SWITCHING
- float *output, /* i/o: LB synth/upsampled LB synth */
- float output_mem[], /* i : OLA memory from last TCX/HQ frame */
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
-#endif
+ Decoder_State *st_fx, /* i/o: decoder state structure */
+ Word16 *synth, /* i/o: output synthesis Qsynth*/
const Word16 output_frame, /* i : frame length Q0*/
const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/
-#ifdef IVAS_CODE_SWITCHING
- const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */
- const Word16 nchan_out, /* i : number of output channels */
-#endif
- const Word16 last_element_mode, /* i : element mode of previous frame Q0*/
- Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */
+ const Word16 last_element_mode, /* i : element mode of previous frame Q0*/
+ Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */
)
{
Word16 i, delay_comp, delta;
@@ -1152,9 +898,6 @@ ivas_error core_switching_post_dec_fx(
HQ_DEC_HANDLE hHQ_core;
ivas_error error;
-#ifdef IVAS_CODE_SWITCHING
- int16_t offset;
-#endif
#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING
(void) ( last_element_mode );
#endif
@@ -1164,8 +907,6 @@ ivas_error core_switching_post_dec_fx(
error = IVAS_ERR_OK;
move32();
- // PMT("core_switching_post_dec_fx : Only handles has been converted, code needs to be entirely reviewed ")
-
/* Rescale synthesis in Q0 to avoid multiple rescaling after */
tmp = Find_Max_Norm16( synth, output_frame );
Scale_sig( synth, output_frame, tmp );
@@ -1560,8 +1301,6 @@ ivas_error core_switching_post_dec_ivas_fx(
error = IVAS_ERR_OK;
move32();
- // PMT("core_switching_post_dec_fx : Only handles has been converted, code needs to be entirely reviewed ")
-
/* Rescale synthesis in Q0 to avoid multiple rescaling after */
tmp = Find_Max_Norm16( synth, output_frame );
Scale_sig( synth, output_frame, tmp ); /* Qsynth + tmp */
@@ -1765,7 +1504,7 @@ ivas_error core_switching_post_dec_ivas_fx(
Copy_Scale_sig( st_fx->previoussynth_fx, synth, delay_comp, *Qsynth ); /* Qsynth */
/* Overlap between TCX-LB and TCX-FB*/
- Word16 tmpDelta = NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS );
+ Word16 tmpDelta = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS );
Word32 L_tmp2;
FOR( i = 0; i < tmpDelta; i++ )
{
@@ -1924,7 +1663,7 @@ ivas_error core_switching_post_dec_ivas_fx(
}
IF( output_mem_fx != NULL )
{
- Scale_sig( output_mem_fx, NS2SA( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); /* Qtmp */
+ Scale_sig( output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); /* Qtmp */
}
*Qsynth = Qtmp;
move16();
@@ -2435,3 +2174,1012 @@ static void smoothTransitionDtxToTcx_fx(
return;
}
+
+
+/*---------------------------------------------------------------------*
+ * core_switching_pre_dec()
+ *
+ * Preprocessing/preparation for ACELP/HQ core switching
+ *---------------------------------------------------------------------*/
+ivas_error core_switching_pre_dec_ivas_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const Word16 output_frame, /* i : frame length */
+ const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */
+ const Word16 nchan_out, /* i : number of output channels */
+ const Word16 last_element_mode, /* i : last_element_mode */
+ const Word32 last_element_brate, /* i : last element bitrate */
+ Word16 Q_old_synthFB,
+ Word16 *Q_olapBufferSynth,
+ Word16 *Q_olapBufferSynth2 )
+{
+ Word32 tmp_fx; /*Q-12*/
+ Word16 i, oldLenClasBuff, newLenClasBuff;
+ ivas_error error;
+ Word16 exp = 25;
+ move16();
+ error = IVAS_ERR_OK;
+ move32();
+
+ /* Codec mode switching */
+ test();
+ test();
+ test();
+ IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && ( st->element_mode > EVS_MONO ) ) )
+ {
+ st->mem_deemph_fx = st->syn[M];
+ move16();
+ set16_fx( st->agc_mem_fx, 0, 2 );
+ Scale_sig( &( st->mem_deemph_fx ), 1, st->Q_syn ); /* Brings mem_deemph to Qsyn */
+
+ Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/
+
+ st->bpf_off = 1;
+ move16();
+ IF( st->hPFstat != NULL )
+ {
+ Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/
+ Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem , Q_syn*/
+ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/
+ set16_fx( st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/
+ }
+ IF( st->hBPF != NULL )
+ {
+ st->hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */
+ st->hBPF->pst_mem_deemp_err_fx = 0;
+ move16();
+ move16();
+ }
+ st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); // Q(23+1-16)->Q8
+ move16();
+
+ /* reset old HB synthesis buffer */
+ IF( EQ_16( st->last_L_frame, L_FRAME ) )
+ {
+ st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS );
+ }
+ ELSE
+ {
+ st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS );
+ }
+ move16();
+ set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) );
+
+ test();
+ IF( st->hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) )
+ {
+#ifdef MSAN_FIX
+ st->hBWE_TD->prev_hb_synth_fx_exp = 31;
+ move16();
+#endif // MSAN_FIX
+ /* reset BWE memories */
+ set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
+ st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
+ move32();
+ }
+
+ /* reset upd_cnt */
+ st->upd_cnt = MAX_UPD_CNT;
+ move16();
+
+ st->igf = 0;
+ move16();
+
+ test();
+ IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
+ {
+ hf_synth_reset_fx( st->hBWE_zero );
+#ifdef MSAN_FIX
+ set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
+#endif
+ }
+
+ IF( st->hBWE_FD != NULL )
+ {
+ set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
+ }
+
+ IF( st->hHQ_core != NULL )
+ {
+ set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB );
+ set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB );
+
+ set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
+ set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
+
+ st->hHQ_core->last_max_pos_pulse = 0;
+ move16();
+
+ IF( GT_32( st->output_Fs, 16000 ) )
+ {
+ set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
+ }
+
+ /* pre-echo */
+ st->hHQ_core->pastpre = 0;
+ move16();
+ }
+
+ /* reset the GSC pre echo energy threshold in case of switching */
+ if ( st->hGSCDec != NULL )
+ {
+ st->hGSCDec->Last_frame_ener_fx = MAX_32;
+ move32();
+ }
+
+ test();
+ IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) )
+ {
+ IF( st->element_mode == EVS_MONO )
+ {
+ st->last_core = HQ_CORE;
+ move16();
+
+ Copy32( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer32_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
+ // Copy_Scale_sig_32_16( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); //Q11 -> Q0
+ }
+
+ IF( st->hHQ_core != NULL )
+ {
+ set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
+ set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
+ st->hHQ_core->last_max_pos_pulse = 0;
+ move16();
+
+ set16_fx( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM );
+ st->hHQ_core->prev_frm_hfe2 = 0;
+ st->hHQ_core->prev_stab_hfe2 = 0;
+ move16();
+ move16();
+ }
+ }
+
+ IF( st->prev_bfi != 0 )
+ {
+ Word16 delay_comp;
+
+ /*switch off Hq Voicing as it was not updated in MODE2*/
+ IF( st->hHQ_core != NULL )
+ {
+ st->hHQ_core->oldHqVoicing = 0;
+ st->hHQ_core->HqVoicing = 0;
+ move16();
+ move16();
+ }
+
+ delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
+ /*TODO To be tested:control not entering the block*/
+ test();
+ test();
+ IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) )
+ {
+ /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/
+ assert( 0 );
+ Word32 *realBuffer_fx[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer_fx[CLDFB_NO_COL_MAX_SWITCH];
+ Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX];
+ Word32 syn_Overl_fx[320];
+ Word32 fer_samples_fx[960];
+ Copy_Scale_sig_16_32_DEPREC( st->hTcxDec->syn_Overl, syn_Overl_fx, 320, 15 );
+ Copy_Scale_sig_16_32_DEPREC( st->hHQ_core->fer_samples_fx, fer_samples_fx, 960, 15 );
+
+
+ FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ )
+ {
+ set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
+ set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
+ realBuffer_fx[i] = realBufferTmp_fx[i];
+ imagBuffer_fx[i] = imagBufferTmp_fx[i];
+ }
+
+ /* CLDFB analysis of the synthesis at internal sampling rate */
+ IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+
+ cldfbAnalysis_ivas_fx( syn_Overl_fx, realBuffer_fx, imagBuffer_fx, delay_comp, st->cldfbAna );
+ cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/
+
+ /* CLDFB synthesis of the combined signal */
+ IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+
+ cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, st->cldfbSyn );
+ cldfb_restore_memory_ivas_fx( st->cldfbSyn );
+ Copy_Scale_sig_32_16( syn_Overl_fx, st->hTcxDec->syn_Overl, 320, 15 );
+ Copy_Scale_sig_32_16( fer_samples_fx, st->hHQ_core->fer_samples_fx, 960, 9 );
+ }
+
+ test();
+ test();
+ IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) )
+ {
+ lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) );
+ /*Set to zero the remaining part*/
+ set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) );
+ }
+ }
+
+ st->use_acelp_preq = 0;
+ st->reset_mem_AR = 0;
+ move16();
+ move16();
+ }
+
+ /*FEC*/
+ IF( LE_16( st->L_frame, L_FRAME16k ) )
+ {
+ test();
+ IF( LE_16( st->last_L_frame, L_FRAME16k ) && NE_16( st->core, HQ_CORE ) )
+ {
+ IF( NE_16( st->L_frame, st->last_L_frame ) )
+ {
+ IF( GT_16( st->L_frame, st->last_L_frame ) )
+ {
+ oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) );
+ newLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
+ move16();
+ }
+ ELSE
+ {
+ oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
+ move16();
+ newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) );
+ }
+ lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff );
+ }
+ }
+ ELSE
+ {
+ set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM );
+ }
+ }
+
+ /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores
+ within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */
+ test();
+ test();
+ IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) )
+ {
+ st->last_ppp_mode_dec = 0;
+ st->last_nelp_mode_dec = 0;
+ move16();
+ move16();
+ }
+
+ /* Handle state reset of stat_noise_uv_mod memory */
+ test();
+ test();
+ test();
+ IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) )
+ {
+ st->act_count = 3;
+ st->uv_count = 0;
+ move16();
+ move16();
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) &&
+ NE_32( st->core_brate, SID_2k40 ) && ( st->core_brate != FRAME_NO_DATA ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) )
+ {
+ test();
+ if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) )
+ {
+ st->hPFstat->reset = 1;
+ move16();
+ }
+
+ IF( EQ_16( st->L_frame, L_FRAME16k ) )
+ {
+ Copy( TRWB2_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */
+ Copy( TRWB2_Ave_fx, st->lsfoldbfi1_fx, M );
+ Copy( TRWB2_Ave_fx, st->lsfoldbfi0_fx, M );
+ Copy( TRWB2_Ave_fx, st->lsf_adaptive_mean_fx, M );
+ lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_16k );
+ }
+ ELSE
+ {
+ Copy( TRWB_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */
+ Copy( TRWB_Ave_fx, st->lsfoldbfi1_fx, M );
+ Copy( TRWB_Ave_fx, st->lsfoldbfi0_fx, M );
+ Copy( TRWB_Ave_fx, st->lsf_adaptive_mean_fx, M );
+ lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_12k8 );
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL )
+ {
+ /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */
+ set16_fx( st->hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 );
+ set16_fx( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, 0, FFTLEN );
+ set16_fx( st->agc_mem_fx, 0, 2 );
+ }
+ st->mem_deemph_fx = 0;
+ move16();
+ IF( !st->last_con_tcx )
+ {
+ set16_fx( st->mem_syn2_fx, 0, M );
+ }
+ set16_fx( st->mem_syn1_fx, 0, M );
+ if ( st->hBWE_TD != NULL )
+ {
+ st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
+ move32();
+ }
+
+ /* Reset ACELP parameters */
+ set16_fx( st->mem_MA_fx, 0, M );
+
+ IF( EQ_32( st->sr_core, INT_FS_16k ) )
+ {
+ Copy( GEWB2_Ave_fx, st->mem_AR_fx, M );
+ }
+ ELSE
+ {
+ Copy( GEWB_Ave_fx, st->mem_AR_fx, M );
+ }
+
+ st->tilt_code_fx = 0;
+ st->gc_threshold_fx = 0;
+ st->dm_fx.prev_gain_code = 0;
+ st->dm_fx.prev_state = 0;
+ move16();
+ move32();
+ move32();
+ move16();
+ set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
+
+ st->last_coder_type = GENERIC;
+ move16();
+
+ fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/
+ st->lp_gainp_fx = 0;
+ move16();
+ st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/
+ move16();
+ st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/
+ move16();
+
+ st->last_voice_factor_fx = 0;
+ st->Last_GSC_noisy_speech_flag = 0;
+ move16();
+ move16();
+
+ /* reset CLDFB memories */
+ cldfb_reset_memory_fx( st->cldfbAna );
+ cldfb_reset_memory_fx( st->cldfbBPF );
+ cldfb_reset_memory_fx( st->cldfbSyn );
+
+ /* reset TBE memories */
+ test();
+ test();
+ IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && ( st->element_mode > EVS_MONO ) ) )
+ {
+ set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC );
+ }
+ ELSE IF( LT_16( st->L_frame, L_FRAME16k ) )
+ {
+ /* resample from 16kHz to 12.8kHZ */
+ synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC );
+ }
+
+ IF( st->hBWE_TD != NULL )
+ {
+ set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
+ }
+
+ test();
+ IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
+ {
+ hf_synth_reset_fx( st->hBWE_zero );
+#ifdef MSAN_FIX
+ set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
+#endif
+ }
+
+ IF( st->hBWE_FD != NULL )
+ {
+ set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
+ }
+ }
+
+ test();
+ test();
+ test();
+ IF( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) )
+ {
+ IF( st->hBWE_TD != NULL )
+ {
+ st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
+ move32();
+ set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
+ }
+
+ st->tilt_code_fx = 0;
+ st->gc_threshold_fx = 0;
+ st->dm_fx.prev_gain_code = 0;
+ st->dm_fx.prev_state = 0;
+ move16();
+ move32();
+ move32();
+ move16();
+ set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
+ st->last_coder_type = GENERIC;
+ move16();
+ fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/
+
+ st->lp_gainp_fx = 0;
+ move16();
+ st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/
+ move16();
+ st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/
+ move16();
+
+ st->last_voice_factor_fx = 0;
+ st->Last_GSC_noisy_speech_flag = 0;
+ move16();
+ move16();
+
+ test();
+ IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
+ {
+ hf_synth_reset_fx( st->hBWE_zero );
+#ifdef MSAN_FIX
+ set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
+#endif
+ }
+
+ IF( st->hBWE_FD != NULL )
+ {
+ set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
+ }
+
+ test();
+ test();
+ test();
+ IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) )
+ {
+ /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */
+ Word16 offset;
+ offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels );
+ Word32 *old_synthFB_fx;
+ IF( ( old_synthFB_fx = (Word32 *) malloc( st->hTcxDec->old_synth_lenFB * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) );
+ }
+#ifdef FIX_ISSUE_1237
+ Copy_Scale_sig_16_32_no_sat( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10
+#else
+ Copy_Scale_sig_16_32_DEPREC( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10
+#endif
+ Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset );
+ st->cldfbAna->Q_cldfb_state = Q10;
+ move16();
+ IF( old_synthFB_fx )
+ free( old_synthFB_fx );
+ }
+ }
+
+ test();
+ test();
+ test();
+ test();
+ IF( EQ_16( st->core, HQ_CORE ) && ( ( st->last_core == ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( ( st->element_mode != EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) )
+ {
+ set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB );
+ set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB );
+
+ set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
+ set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
+ st->hHQ_core->last_max_pos_pulse = 0;
+ move16();
+
+ set16_fx( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM );
+ st->hHQ_core->prev_frm_hfe2 = 0;
+ st->hHQ_core->prev_stab_hfe2 = 0;
+ move16();
+ move16();
+ IF( GT_32( st->output_Fs, 16000 ) )
+ {
+ set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
+ }
+
+ IF( st->element_mode != EVS_MONO )
+ {
+ /* Estimate mem_env_delta to reinit env_stab */
+ tmp_fx = L_max( 0, L_add( ENV_STAB_EST1_FX, L_add( Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ), Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ) ) ); /*Q12*/
+
+ st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */
+ move16();
+ test();
+ IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) )
+ {
+ set16_fx( st->hHQ_core->old_out_fx, 0, output_frame );
+ set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k );
+ set16_fx( st->hHQ_core->old_out_LB_fx, 0, L_FRAME16k );
+ }
+
+ st->hHQ_core->no_att_hangover = 0;
+ move16();
+ st->hHQ_core->energy_lt_fx = 2457600; /*300.0f Q13*/
+ move32();
+ set16_fx( st->hHQ_core->old_is_transient, 0, 3 );
+ set16_fx( st->hHQ_core->prev_noise_level_fx, 0, 2 );
+ st->hHQ_core->prev_R = 0;
+ move16();
+ set16_fx( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 );
+ st->hHQ_core->prev_hqswb_clas = HQ_NORMAL;
+ st->hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/
+ move16();
+ move16();
+ set16_fx( st->hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS );
+ }
+ ELSE
+ {
+ set16_fx( st->hHQ_core->old_out_fx, 0, output_frame );
+ set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k );
+ }
+ }
+
+ /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */
+ IF( st->hHQ_core != NULL )
+ {
+ st->hHQ_core->pastpre = sub( st->hHQ_core->pastpre, 1 );
+ move16();
+ IF( st->hHQ_core->pastpre < 0 )
+ {
+ reset_preecho_dec_fx( st->hHQ_core );
+ }
+ }
+ test();
+ IF( st->core_brate == FRAME_NO_DATA )
+ {
+ st->VAD = 0;
+ st->m_frame_type = ZERO_FRAME;
+ }
+ ELSE IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, SID_1k75 ) )
+ {
+ st->VAD = 0;
+ st->m_frame_type = SID_FRAME;
+ }
+ ELSE
+ {
+ st->VAD = 1;
+ st->m_frame_type = ACTIVE_FRAME;
+ }
+
+ move16();
+ move16();
+ /*switch on CNA on active frames*/
+ IF( ( st->element_mode == EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( st->VAD && ( ( NE_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, CNA_MAX_BRATE ) ) || ( EQ_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, ACELP_8k85 ) ) ) )
+ {
+ st->flag_cna = 1;
+ move16();
+ }
+ ELSE IF( st->VAD || ( EQ_16( st->cng_type, FD_CNG ) && EQ_16( st->L_frame, L_FRAME16k ) ) )
+ {
+ st->flag_cna = 0;
+ move16();
+ }
+ }
+
+ if ( EQ_16( st->core, AMR_WB_CORE ) )
+ {
+ st->cng_type = LP_CNG;
+ move16();
+ }
+
+ /* Reconfigure CNG */
+ test();
+ test();
+ test();
+ test();
+ IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || ( st->ini_frame == 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) )
+ {
+ /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/
+ IF( NE_16( st->core, AMR_WB_CORE ) )
+ {
+ test();
+ IF( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) )
+ {
+ configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, ACELP_9k60, st->L_frame, st->last_L_frame, st->element_mode );
+ }
+ ELSE
+ {
+ configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode );
+ }
+ }
+ ELSE
+ {
+ configureFdCngDec_ivas_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode );
+
+ if ( st->VAD )
+ {
+ st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate;
+ move32();
+ }
+ }
+ test();
+ test();
+ IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->L_frame, L_FRAME16k ) && LE_16( st->last_L_frame, L_FRAME16k ) )
+ {
+ test();
+ IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) )
+ {
+ lerp( st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->L_frame, st->L_frame, st->last_L_frame );
+ }
+
+ L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 );
+
+ test();
+ IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) )
+ {
+ L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth );
+
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ FOR( i = 0; i < ( st->L_frame * 2 ); i++ )
+ {
+ st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ );
+ move32();
+ }
+ }
+ ELSE
+ {
+ FOR( i = 0; i < ( st->L_frame * 2 ); i++ )
+ {
+ st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ );
+ move32();
+ }
+ }
+ }
+ }
+ }
+
+ return error;
+}
+/*---------------------------------------------------------------------*
+ * core_switching_hq_prepare_dec()
+ *
+ * Preprocessing in the first HQ frame after ACELP frame
+ * Modify bit allocation for HQ core by removing ACELP subframe budget
+ *---------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------*
+ * bandwidth_switching_detect()
+ *
+ * Classification for band-width switching
+ *---------------------------------------------------------------------*/
+
+void bandwidth_switching_detect_ivas_fx(
+ Decoder_State *st_fx /* i/o: encoder state structure */
+)
+{
+ test();
+ test();
+ IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) )
+ {
+ /* there is no BWE in TD stereo secondary channel and in MDCT stereo, IGF is part of the core decoding -> no BW switching -> reset BWS counters */
+ st_fx->prev_bws_cnt = 0;
+ st_fx->bws_cnt = 0;
+ st_fx->bws_cnt1 = 0;
+ move16();
+ move16();
+ move16();
+
+ return;
+ }
+ /* update band-width switching counter */
+ test();
+ test();
+ test();
+ test();
+ IF( GE_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) )
+ {
+ st_fx->bws_cnt1 = 0;
+ move16();
+ }
+ ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) && ( st_fx->last_low_rate_mode == 0 ) )
+ {
+ st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 );
+ move16();
+ }
+ ELSE IF( st_fx->bws_cnt1 > 0 )
+ {
+ IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) )
+ {
+ st_fx->bws_cnt = sub( shl( sub( N_NS2W_FRAMES, st_fx->bws_cnt1 ), 1 ), 1 );
+ move16();
+ }
+ ELSE
+ {
+ st_fx->bws_cnt = 0;
+ move16();
+ }
+
+ IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) )
+ {
+ st_fx->bws_cnt1 = 0;
+ move16();
+ }
+ ELSE
+ {
+ IF( EQ_16( st_fx->bwidth, SWB ) )
+ {
+ st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 );
+ move16();
+ }
+ ELSE
+ {
+ st_fx->bws_cnt1 = 0;
+ move16();
+ }
+ }
+ }
+
+ /* update band-width switching counter */
+ test();
+ test();
+ test();
+ IF( GE_16( st_fx->bws_cnt, N_WS2N_FRAMES ) )
+ {
+ st_fx->bws_cnt = 0;
+ move16();
+ }
+ ELSE IF( LT_32( st_fx->total_brate, ACELP_9k60 ) && GT_32( st_fx->last_core_brate, ACELP_9k60 ) && LT_16( st_fx->bwidth, st_fx->last_bwidth ) && EQ_16( st_fx->bwidth, WB ) )
+ {
+ st_fx->bws_cnt = add( st_fx->bws_cnt, 1 );
+ move16();
+ }
+ ELSE IF( st_fx->bws_cnt > 0 )
+ {
+ IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) )
+ {
+ st_fx->bws_cnt1 = shr( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 1 );
+ move16();
+ }
+ ELSE
+ {
+ st_fx->bws_cnt1 = 0;
+ move16();
+ }
+
+ IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) )
+ {
+ st_fx->bws_cnt = 0;
+ move16();
+ }
+ ELSE
+ {
+ IF( EQ_16( st_fx->bwidth, WB ) )
+ {
+ st_fx->bws_cnt = add( st_fx->bws_cnt, 1 );
+ move16();
+ }
+ ELSE
+ {
+ st_fx->bws_cnt = 0;
+ move16();
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * bw_switching_pre_proc()
+ *
+ * Band-width switching pre-processing
+ *---------------------------------------------------------------------*/
+void ivas_bw_switching_pre_proc_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const Word32 last_element_brate, /* i : last element bitrate */
+ const Word16 nchan_out /* i : number of output channels */,
+ Word32 *old_syn_12k8_16k_fx,
+ Word16 Q,
+ Word16 Q_audio )
+{
+ Word16 i;
+ Word32 syn_dct_fx[L_FRAME];
+
+
+ Flag Overflow = 0;
+ move32();
+
+ IF( st->element_mode > EVS_MONO )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) )
+ {
+ /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */
+ Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k];
+ Copy_Scale_sig_32_16( old_syn_12k8_16k_fx, old_syn_12k8_16k_tmp_16fx, st->L_frame, sub( -1, Q ) );
+ st->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st->L_frame ), sub( Q, 8 ) ) ); // Q24+(Q-8) - 16
+ move16();
+ }
+
+ return;
+ }
+
+
+ test();
+ test();
+ IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) )
+ {
+ /*----------------------------------------------------------------------*
+ * Calculate tilt of the ACELP core synthesis
+ *----------------------------------------------------------------------*/
+
+ st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame );
+ move16();
+ /*-------------------------------------------------------------------------------*
+ * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis
+ *-------------------------------------------------------------------------------*/
+ edct_fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q );
+ Word64 W_tmp = 0;
+ move64();
+ Word32 tmp;
+ Word16 shift;
+ FOR( i = 0; i < L_FRAME / 2; i++ )
+ {
+ W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) );
+ }
+ shift = W_norm( W_tmp );
+ W_tmp = W_shl( W_tmp, shift );
+ tmp = W_extract_h( W_tmp );
+ tmp = L_shr( tmp, 8 );
+
+ tmp = getSqrtWord32( tmp );
+ st->enerLL_fx = tmp;
+ move32();
+ st->enerLL_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 );
+ move16();
+ W_tmp = 0;
+ move64();
+ FOR( ; i < L_FRAME; i++ )
+ {
+ W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) );
+ }
+ shift = W_norm( W_tmp );
+ W_tmp = W_shl( W_tmp, shift );
+ tmp = W_extract_h( W_tmp ); // Q = Q + shift - 32
+ tmp = L_shr( tmp, 7 ); // divide by 128
+ tmp = getSqrtWord32( tmp );
+ st->enerLH_fx = tmp;
+ move32();
+ st->enerLH_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 );
+ move16();
+ }
+ ELSE
+ {
+ IF( st->hHQ_core->old_is_transient[0] )
+ {
+ Word32 tmp, L_tmp = 0;
+ move32();
+ FOR( i = 0; i < 32; i++ )
+ {
+ L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
+ }
+ tmp = L_shr( L_tmp, 5 ); // divide by 32
+ tmp = getSqrtWord32( tmp );
+ st->enerLL_fx = tmp;
+ move32();
+ st->enerLL_fx_Q = Q_audio;
+ move16();
+
+ L_tmp = 0;
+ move32();
+ FOR( ; i < 64; i++ )
+ {
+ L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
+ }
+
+ tmp = L_shr( L_tmp, 5 ); // divide by 32
+ tmp = getSqrtWord32( tmp );
+ st->enerLH_fx = tmp;
+ move32();
+ st->enerLH_fx_Q = Q_audio;
+ move16();
+ }
+ ELSE
+ {
+ Word32 tmp, L_tmp = 0;
+ move32();
+ FOR( i = 0; i < L_FRAME / 2; i++ )
+ {
+ L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
+ }
+ tmp = L_shr( L_tmp, 5 ); // divide by 32
+ tmp = getSqrtWord32( tmp );
+ st->enerLL_fx = tmp;
+ move32();
+ st->enerLL_fx_Q = Q_audio;
+ move16();
+
+ L_tmp = 0;
+ move32();
+ FOR( ; i < L_FRAME; i++ )
+ {
+ L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
+ }
+ tmp = L_shr( L_tmp, 5 ); // divide by 32
+ tmp = getSqrtWord32( tmp );
+ st->enerLL_fx = tmp;
+ move32();
+ st->enerLL_fx_Q = Q_audio;
+ move16();
+ }
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) )
+ {
+
+ st->prev_ener_shb_fx = 0;
+ move16();
+ IF( st->hBWE_FD != NULL )
+ {
+ set16_fx( st->prev_SWB_fenv_fx, 0, SWB_FENV );
+ }
+ }
+ ELSE IF( ( ( ( st->core == ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) )
+ {
+ st->attenu_fx = 3277; // 0.1f in Q15
+ move16();
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ if ( EQ_16( st->last_core, HQ_CORE ) || ( ( st->last_core == ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) )
+ {
+ st->prev_fractive = 0;
+ move16();
+ }
+
+ return;
+}
diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c
index 58f9048c4c69194c0874af32fad1343b5a9bde92..ee6ef65a6ce3aa2b91e1020f51ad5f12405baa84 100644
--- a/lib_dec/dec4t64_fx.c
+++ b/lib_dec/dec4t64_fx.c
@@ -793,242 +793,7 @@ void D_ACELP_decode_43bit_fx( UWord16 idxs[], Word16 code[], Word16 *pulsestrack
return;
}
-#ifdef IVAS_CODE_FCB
-/*-------------------------------------------------------*
- * dec_1p_N1()
- *
- * Decode 1 pulse with N+1 bits
- *-------------------------------------------------------*/
-
-static void dec_1p_N1_L_subfr(
- const int32_t index, /* i : quantization index */
- const int16_t nb_pos, /* i : number of positions */
- const int16_t N, /* i : nb. of bits */
- int16_t pos[] /* o : pulse position */
-)
-{
- int16_t i, pos1;
- int32_t mask;
-
- mask = ( ( 1 << N ) - 1 );
- pos1 = (int16_t) ( index & mask );
- i = (int16_t) ( index >> N ) & 1;
-
- if ( i == 1 )
- {
- pos1 += nb_pos;
- }
-
- pos[0] = pos1;
-
- return;
-}
-
-/*-------------------------------------------------------*
- * add_pulses()
- *
- * Add decoded pulses to the codeword
- *-------------------------------------------------------*/
-
-static void add_pulses_L_subfr(
- const int16_t nb_pos, /* i : number of positions */
- const int16_t pos[], /* i : pulse position */
- const int16_t nb_pulse, /* i : nb. of pulses */
- const int16_t track, /* i : no. of the tracks */
- float code[] /* i/o: decoded codevector */
-)
-{
- int16_t i, k;
-
- for ( k = 0; k < nb_pulse; k++ )
- {
- i = ( ( pos[k] & ( nb_pos - 1 ) ) * NB_TRACK_FCB_4T ) + track;
- if ( ( pos[k] & nb_pos ) == 0 )
- {
- code[i] += 1.0f;
- }
- else
- {
- code[i] -= 1.0f;
- }
- }
-
- return;
-}
-
-/*----------------------------------------------------------------------------------*
- * dec_acelp_fast()
- *
- * fast algebraic codebook decoder
- *----------------------------------------------------------------------------------*/
-
-void dec_acelp_fast(
- Decoder_State *st, /* i/o: decoder state structure */
- const int16_t cdk_index, /* i : codebook index */
- float code[], /* o : algebraic (fixed) codebook excitation */
- const int16_t L_subfr /* i : subframe length */
-)
-{
- int16_t k, pos[7], skip_track;
- int32_t L_index;
- PulseConfig config;
-
- skip_track = -1;
- set_f( code, 0.0f, L_subfr );
-
- if ( L_subfr == L_SUBFR )
- {
- config = PulseConfTable[cdk_index];
-
- if ( cdk_index == 2 )
- {
- dec_acelp_2t32( st, code );
- }
- else if ( config.nb_pulse == 2 )
- {
- /* 10 bits, 2 pulses, 4 tracks 1010 (used only even tracks) */
- for ( k = 0; k < NB_TRACK_FCB_4T - 1; k += 2 )
- {
- L_index = get_next_indice( st, 5 );
- dec_1p_N1( L_index, 4, 0, pos );
- add_pulses( pos, 1, k, code );
- }
- }
- else if ( config.nb_pulse == 3 )
- {
- if ( config.codetrackpos == TRACKPOS_FIXED_FIRST )
- {
- /* 15 bits, 3 pulses, 4 tracks 1110 fixed track to first ? */
- for ( k = 0; k < NB_TRACK_FCB_4T - 1; k++ )
- {
- L_index = get_next_indice( st, 5 );
- dec_1p_N1( L_index, 4, 0, pos );
- add_pulses( pos, 1, k, code );
- }
- }
- else if ( config.codetrackpos == TRACKPOS_FREE_THREE )
- {
- /* 17 bits, 3 pulses, 4 tracks (used all tracks) - 1110, 1101, 1011, 0111 */
- skip_track = get_next_indice( st, 2 );
- for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
- {
- if ( k != skip_track )
- {
- L_index = get_next_indice( st, 5 );
- dec_1p_N1( L_index, 4, 0, pos );
- add_pulses( pos, 1, k, code );
- }
- }
- }
- }
- else
- {
- if ( config.bits == 20 )
- {
- skip_track = -1;
- }
- else if ( config.codetrackpos == TRACKPOS_FIXED_FIRST )
- {
- skip_track = 0;
- }
- else if ( config.codetrackpos == TRACKPOS_FREE_ONE )
- {
- skip_track = get_next_indice( st, 2 );
- }
-
- for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
- {
- if ( k == skip_track )
- {
- L_index = get_next_indice( st, 9 );
- dec_2p_2N1( L_index, 4, 0, pos );
- add_pulses( pos, 2, k, code );
- }
- else
- {
- L_index = get_next_indice( st, 5 );
- dec_1p_N1( L_index, 4, 0, pos );
- add_pulses( pos, 1, k, code );
- }
- }
- }
- }
- else /* L_subfr == 2*L_SUBFR */
- {
- config.bits = cdk_index;
-
- if ( cdk_index == 14 )
- {
- /* 14 bits, 2 pulses, 2 tracks: 11 (used all tracks) */
- int16_t index, i0, i1;
-
- index = get_next_indice( st, 14 );
-
- i0 = ( ( index >> 7 ) & ( NB_POS_FCB_2T_128 - 1 ) ) * NB_TRACK_FCB_2T;
- i1 = ( ( index & ( NB_POS_FCB_2T_128 - 1 ) ) * NB_TRACK_FCB_2T ) + 1;
-
- code[i0] = -1.0f;
- if ( ( index & 0x2000 ) == 0 )
- {
- code[i0] = 1.0f;
- }
-
- code[i1] = -1.0f;
- if ( ( index & 0x40 ) == 0 )
- {
- code[i1] = 1.0f;
- }
- }
- else if ( cdk_index == 12 )
- {
- /* 12 bits, 2 pulses, 4 tracks: 1010 (used only even tracks) */
- for ( k = 0; k < NB_TRACK_FCB_4T - 1; k += 2 )
- {
- L_index = get_next_indice( st, 6 );
- dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos );
- add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code );
- }
- }
- else if ( cdk_index == 18 )
- {
- /* 18 bits, 3 pulses, 4 tracks: 1110 (used first three tracks) */
- for ( k = 0; k < NB_TRACK_FCB_4T - 1; k++ )
- {
- L_index = get_next_indice( st, 6 );
- dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos );
- add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code );
- }
- }
- else if ( cdk_index == 20 )
- {
- /* 20 bits, 3 pulses, 4 tracks (used all tracks): 1110, 1101, 1011, 0111 */
- skip_track = get_next_indice( st, 2 );
- for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
- {
- if ( k != skip_track )
- {
- L_index = get_next_indice( st, 6 );
- dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos );
- add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code );
- }
- }
- }
- else if ( cdk_index == 24 )
- {
- /* 24 bits, 4 pulses, 4 tracks: 1111 */
- for ( k = 0; k < NB_TRACK_FCB_4T; k++ )
- {
- L_index = get_next_indice( st, 6 );
- dec_1p_N1_L_subfr( L_index, NB_POS_FCB_4T_128, 5, pos );
- add_pulses_L_subfr( NB_POS_FCB_4T_128, pos, 1, k, code );
- }
- }
- }
-
- return;
-}
-#endif
/*-------------------------------------------------------*
* dec_1p_N1()
diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c
index 7edd2354961721af2eb1ee3be18067cd3f76704f..04a41ed46c9a3ca1b4f0110d3eb3b60872886ffa 100644
--- a/lib_dec/dec_acelp_tcx_main_fx.c
+++ b/lib_dec/dec_acelp_tcx_main_fx.c
@@ -10,12 +10,7 @@
#include "stat_com.h"
#include "prot_fx.h"
#include "basop_util.h"
-static void decode_frame_type_fx( Decoder_State *st
-#ifdef IVAS_CODE_CNG
- ,
- STEREO_CNG_DEC_HANDLE hStereoCng
-#endif
-)
+static void decode_frame_type_fx( Decoder_State *st )
{
Word32 L_tmp;
Word16 num_bits;
@@ -259,9 +254,7 @@ static void decode_frame_type_fx( Decoder_State *st
IF( EQ_16( st->m_frame_type, SID_FRAME ) && NE_16( st->hFdCngDec->hFdCngCom->frame_type_previous, ACTIVE_FRAME ) )
{
lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame * 2, st->last_L_frame * 2 );
-#ifdef IVAS_CODE_CNG
- lerp( hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22, st->L_frame * 2, st->last_L_frame * 2 );
-#endif
+
IF( EQ_16( st->L_frame, L_FRAME ) )
{
FOR( n = 0; n < shl( st->L_frame, 1 ); n++ )
@@ -311,10 +304,6 @@ Word16 dec_acelp_tcx_frame_fx(
Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q0 */
Word16 *voice_factors, /* o : voicing factors Q15 */
Word16 pitch_buf[] /* o : floating pitch for each subframe Q6 */
-#ifdef IVAS_CODE_CNG
- ,
- STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */
-#endif
)
{
Word16 num_bits;
@@ -366,12 +355,7 @@ Word16 dec_acelp_tcx_frame_fx(
Word32 total_brate = st->last_total_brate;
move32();
- decode_frame_type_fx( st
-#ifdef IVAS_CODE_CNG
- ,
- hStereoCng
-#endif
- );
+ decode_frame_type_fx( st );
st->force_lpd_reset = 0;
move16();
diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c
index baea98a2c0883f936ad95cb0290a90234fdcadf6..415b4584e53c884068ce8f194e63305bc2ed8dd9 100644
--- a/lib_dec/dec_amr_wb_fx.c
+++ b/lib_dec/dec_amr_wb_fx.c
@@ -71,12 +71,8 @@ void decod_amr_wb_fx(
* Decode pitch lag
*----------------------------------------------------------------------*/
- *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR
-#ifdef ADD_LRTD
- ,
- 0, NULL
-#endif
- );
+ *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR );
+
/*--------------------------------------------------------------*
* Find the adaptive codebook vector
*--------------------------------------------------------------*/
diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c
index b1cb2b5161aee7a69f1a9f8c2f141baeb6af73d3..aff7e56564e134e0492ba56f92bed3e6882af87b 100644
--- a/lib_dec/dec_higher_acelp_fx.c
+++ b/lib_dec/dec_higher_acelp_fx.c
@@ -8,7 +8,6 @@
#include "prot_fx.h" /* Function prototypes */
#include "rom_com.h" /* Static table prototypes */
-#define IVAS_CODE
#define IVAS_CODE_AVQ
/*-----------------------------------------------------------------*
* transf_cdbk_dec()
@@ -36,7 +35,6 @@ void transf_cdbk_dec_fx(
Flag Overflow = 0;
move32();
#endif
-#ifdef IVAS_CODE
Word16 avq_bit_sFlag;
Word16 trgtSvPos;
Word16 Nsv;
@@ -50,7 +48,7 @@ void transf_cdbk_dec_fx(
move16();
avq_bit_sFlag = 1;
}
-#endif
+
/*--------------------------------------------------------------*
* Set bit-allocation
*--------------------------------------------------------------*/
@@ -112,7 +110,7 @@ void transf_cdbk_dec_fx(
*gain_preQ = round_fx( L_tmp ); /* Q2*/
move16();
}
-#ifdef IVAS_CODE
+
trgtSvPos = sub( Nsv, 1 );
test();
test();
@@ -126,7 +124,7 @@ void transf_cdbk_dec_fx(
move16();
move16();
}
-#endif
+
/*--------------------------------------------------------------*
* Demultiplex and decode subvectors from bit-stream
*--------------------------------------------------------------*/
diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c
index 4e18eebce4bfc689e7c6fd9e9fc04aa1796636dd..746b668198d4c2d0a3ff030739b0d40d82b23952 100644
--- a/lib_dec/dec_pit_exc_fx.c
+++ b/lib_dec/dec_pit_exc_fx.c
@@ -41,11 +41,6 @@ void dec_pit_exc_fx(
const Word16 nb_subfr_fx /* i : Number of subframe considered */
,
Word16 *gain_buf /*Q14*/
-#ifdef ADD_LRTD
- ,
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-#endif
)
{
Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */
@@ -179,12 +174,7 @@ void dec_pit_exc_fx(
/*----------------------------------------------------------------------*
* Decode pitch lag
*----------------------------------------------------------------------*/
- *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx
-#ifdef ADD_LRTD
- ,
- tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf
-#endif
- );
+ *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx );
move16();
/*--------------------------------------------------------------*
@@ -207,12 +197,7 @@ void dec_pit_exc_fx(
gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
- st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0
-#ifdef ADD_LRTD
- ,
- L_subfr_fx
-#endif
- );
+ st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 );
move16();
}
ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */
@@ -225,12 +210,7 @@ void dec_pit_exc_fx(
gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx );
- st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0
-#ifdef ADD_LRTD
- ,
- L_subfr_fx
-#endif
- );
+ st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 );
move16();
}
ELSE
@@ -457,22 +437,18 @@ void dec_pit_exc_fx(
/* _ None */
/*==========================================================================*/
void dec_pit_exc_ivas_fx(
- Decoder_State *st_fx, /* i/o: decoder static memory */
- const Word16 *Aq_fx, /* i : LP filter coefficient */
- const Word16 coder_type, /* i : coding type */
- const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
- Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */
- Word16 *code_fx, /* o : innovation */
- Word16 *exc_fx, /* i/o: adapt. excitation exc */
- Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
- const Word16 nb_subfr_fx /* i : Number of subframe considered */
- ,
- Word16 *gain_buf /*Q14*/
-#if 1 // def ADD_LRTD
- ,
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ const Word16 *Aq_fx, /* i : LP filter coefficient */
+ const Word16 coder_type, /* i : coding type */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */
+ Word16 *code_fx, /* o : innovation */
+ Word16 *exc_fx, /* i/o: adapt. excitation exc */
+ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
+ const Word16 nb_subfr_fx, /* i : Number of subframe considered */
+ Word16 *gain_buf, /*Q14*/
const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-#endif
)
{
Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */
@@ -591,9 +567,11 @@ void dec_pit_exc_ivas_fx(
set16_fx( st_fx->acelp_cfg.pitch_bits, 9, 4 );
set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, 5 );
}
+
/*------------------------------------------------------------------*
* ACELP subframe loop
*------------------------------------------------------------------*/
+
p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */
pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
pt_gain = gain_buf; /* pointer to the gain buffer */
@@ -602,12 +580,8 @@ void dec_pit_exc_ivas_fx(
/*----------------------------------------------------------------------*
* Decode pitch lag
*----------------------------------------------------------------------*/
- *pt_pitch_fx = pit_decode_ivas_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx
-#if 1 // def ADD_LRTD
- ,
- tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf
-#endif
- );
+
+ *pt_pitch_fx = pit_decode_ivas_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
move16();
/*--------------------------------------------------------------*
@@ -623,6 +597,7 @@ void dec_pit_exc_ivas_fx(
IF( EQ_16( use_fcb, 1 ) )
{
inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx );
+
/*--------------------------------------------------------------*
* Gain decoding
* Estimate spectrum tilt and voicing
@@ -630,18 +605,14 @@ void dec_pit_exc_ivas_fx(
gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
- st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0
-#if 1 // def ADD_LRTD
- ,
- L_subfr_fx, 0
-#endif
- );
+ st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 );
move16();
}
ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */
{
/*inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx);*/
inov_decode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, 0, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx );
+
/*--------------------------------------------------------------*
* Gain decoding
* Estimate spectrum tilt and voicing
@@ -649,12 +620,7 @@ void dec_pit_exc_ivas_fx(
gain_dec_lbr_ivas_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx );
- st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0
-#if 1 // def ADD_LRTD
- ,
- L_subfr_fx, 0
-#endif
- );
+ st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 );
move16();
}
ELSE
diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c
deleted file mode 100644
index 7b4567f7ad8bb192b6f6fa17cb60378fb9ea499e..0000000000000000000000000000000000000000
--- a/lib_dec/dec_prm.c
+++ /dev/null
@@ -1,328 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include "cnst.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-/*-------------------------------------------------------------------*
- * getTCXMode_ivas()
- *
- * get TCX mode
- *--------------------------------------------------------------------*/
-void getTCXMode_ivas_fx(
- Decoder_State *st, /* i/o: decoder memory state */
- Decoder_State *st0, /* i : bitstream */
- const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */
-)
-{
- UWord16 ind;
-
- IF( st->tcxonly )
- {
- /* get core */
- ind = get_next_indice_fx( st0, 1 ); /* Store decoder memory of last_core */
- st->core = add( ind, TCX_20_CORE );
- move16();
- /* get class */
- ind = get_next_indice_fx( st0, 2 );
-
- st->clas_dec = ONSET;
- move16();
- IF( ind == 0 )
- {
- st->clas_dec = UNVOICED_CLAS;
- move16();
- }
- ELSE IF( EQ_16( ind, 1 ) )
- {
- IF( GE_16( st->last_good, VOICED_TRANSITION ) )
- {
- st->clas_dec = VOICED_TRANSITION;
- move16();
- }
- ELSE
- {
- st->clas_dec = UNVOICED_TRANSITION;
- move16();
- }
- }
- ELSE IF( EQ_16( ind, 2 ) )
- {
- st->clas_dec = VOICED_CLAS;
- move16();
- }
-
- st->coder_type = INACTIVE;
- move16();
- test();
- IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag )
- {
- st->VAD = get_next_indice_fx( st0, 1 );
- move16();
- }
- ELSE
- {
- st->VAD = 0;
- move16();
- }
- }
- ELSE
- {
- IF( EQ_16( st->mdct_sw, MODE1 ) )
- {
- /* 2 bits instead of 3 as TCX is already signaled */
- st->core = TCX_20_CORE;
- move16();
- st->hTcxCfg->coder_type = get_next_indice_fx( st0, 2 );
- move16();
- st->coder_type = st->hTcxCfg->coder_type;
- move16();
- }
- ELSE
- {
- IF( EQ_16( st->mdct_sw_enable, MODE2 ) )
- {
- IF( get_next_indice_1_fx( st0 ) )
- {
- ind = get_next_indice_fx( st0, 3 );
- assert( !( ind & 4 ) || !"HQ_CORE encountered in dec_prm_ivas" );
- st->core = TCX_20_CORE;
- move16();
- st->hTcxCfg->coder_type = ind;
- move16();
- st->coder_type = st->hTcxCfg->coder_type;
- move16();
- }
- ELSE /* ACELP */
- {
- st->core = ACELP_CORE;
- move16();
- st->coder_type = get_next_indice_fx( st0, 2 );
- move16();
- }
- }
- ELSE
- {
- IF( EQ_16( st->rf_flag, 1 ) )
- {
- IF( !st->use_partial_copy )
- {
- ind = get_next_indice_fx( st0, 1 );
- IF( ind == 0 )
- {
- st->core = ACELP_CORE;
- move16();
- }
- ELSE
- {
- st->core = TCX_20_CORE;
- move16();
- st->hTcxCfg->coder_type = st->coder_type;
- move16();
- }
- }
- }
- ELSE
- {
- ind = get_next_indice_fx( st, 3 );
- IF( LT_16( ind, ACELP_MODE_MAX ) )
- {
- st->core = ACELP_CORE;
- move16();
- st->coder_type = ind;
- move16();
- }
- ELSE
- {
- st->core = TCX_20_CORE;
- move16();
- st->hTcxCfg->coder_type = sub( ind, ACELP_MODE_MAX );
- move16();
- st->coder_type = st->hTcxCfg->coder_type;
- move16();
- }
- }
- }
- }
-
- IF( EQ_16( st->element_mode, EVS_MONO ) )
- {
- test();
- IF( st->igf && EQ_16( st->core, ACELP_CORE ) )
- {
- st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) );
- move16();
- }
-
- IF( st->rf_flag )
- {
- st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */
- move16();
- }
- }
-
- /* Inactive frame detection on non-DTX mode */
- IF( EQ_16( st->coder_type, INACTIVE ) )
- {
- st->VAD = 0;
- move16();
- }
- ELSE
- {
- st->VAD = 1;
- move16();
- }
- }
-
- /*Core extended mode mapping for correct PLC classification*/
- st->core_ext_mode = st->coder_type;
- move16();
- if ( EQ_16( st->coder_type, INACTIVE ) )
- {
- st->core_ext_mode = UNVOICED;
- move16();
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------*
- * getTCXWindowing_ivas()
- *
- * get TCX transform type for each subframe
- *--------------------------------------------------------------------*/
-void getTCXWindowing_ivas_fx(
- const Word16 core, /* i : current core */
- const Word16 last_core, /* i : last frame core */
- const Word16 element_mode, /* i : element mode */
- TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */
- Decoder_State *st0 /* i : bitstream */
-)
-{
- Word16 overlap_code;
-
- /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */
- test();
- test();
- test();
- IF( EQ_16( last_core, ACELP_CORE ) || EQ_16( last_core, AMR_WB_CORE ) )
- {
- hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
- move16();
- }
- ELSE IF( EQ_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) )
- {
- hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP;
- move16();
- }
- ELSE IF( NE_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) )
- {
- hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
- move16();
- }
- ELSE
- {
- hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
- move16();
- }
-
- /* Set the current overlap mode based on the current frame type and coded overlap mode */
- hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
- move16();
-
- IF( NE_16( core, ACELP_CORE ) )
- {
- overlap_code = 0;
- move16();
- IF( get_next_indice_fx( st0, 1 ) )
- {
- overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
- }
-
- assert( MIN_OVERLAP == 2 && HALF_OVERLAP == 3 );
- hTcxCfg->tcx_curr_overlap_mode = overlap_code;
- move16();
- /*TCX10 : always symmetric windows*/
- test();
- test();
- test();
- IF( EQ_16( core, TCX_20_CORE ) && ( overlap_code == 0 ) && NE_16( last_core, ACELP_CORE ) && NE_16( last_core, AMR_WB_CORE ) )
- {
- hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
- move16();
- }
- }
-
- test();
- IF( NE_16( element_mode, EVS_MONO ) && EQ_16( core, TCX_10_CORE ) )
- {
- /* also read last overlap */
- overlap_code = 0;
- move16();
-
- IF( get_next_indice_fx( st0, 1 ) )
- {
- overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
- }
-
- hTcxCfg->tcx_last_overlap_mode = overlap_code;
- move16();
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------*
- * getLPCparam_ivas()
- *
- * get LPC parameters
- *--------------------------------------------------------------------*/
-
-
-/*-----------------------------------------------------------------*
- * Function dec_prm_ivas() *
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
- *
- * SQ is used for TCX modes
- *
- * decode parameters according to selected mode *
- *-----------------------------------------------------------------*/
diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c
index 73edd3b3b3c98d0a0018f9e206153a54254a3ec3..3d277807d2fed95764ba8e3c4992662fd26eac4b 100644
--- a/lib_dec/dec_prm_fx.c
+++ b/lib_dec/dec_prm_fx.c
@@ -1742,3 +1742,272 @@ void dec_prm_fx(
return;
}
+
+
+/*-------------------------------------------------------------------*
+ * getTCXMode_ivas()
+ *
+ * get TCX mode
+ *--------------------------------------------------------------------*/
+void getTCXMode_ivas_fx(
+ Decoder_State *st, /* i/o: decoder memory state */
+ Decoder_State *st0, /* i : bitstream */
+ const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */
+)
+{
+ UWord16 ind;
+
+ IF( st->tcxonly )
+ {
+ /* get core */
+ ind = get_next_indice_fx( st0, 1 ); /* Store decoder memory of last_core */
+ st->core = add( ind, TCX_20_CORE );
+ move16();
+ /* get class */
+ ind = get_next_indice_fx( st0, 2 );
+
+ st->clas_dec = ONSET;
+ move16();
+ IF( ind == 0 )
+ {
+ st->clas_dec = UNVOICED_CLAS;
+ move16();
+ }
+ ELSE IF( EQ_16( ind, 1 ) )
+ {
+ IF( GE_16( st->last_good, VOICED_TRANSITION ) )
+ {
+ st->clas_dec = VOICED_TRANSITION;
+ move16();
+ }
+ ELSE
+ {
+ st->clas_dec = UNVOICED_TRANSITION;
+ move16();
+ }
+ }
+ ELSE IF( EQ_16( ind, 2 ) )
+ {
+ st->clas_dec = VOICED_CLAS;
+ move16();
+ }
+
+ st->coder_type = INACTIVE;
+ move16();
+ test();
+ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag )
+ {
+ st->VAD = get_next_indice_fx( st0, 1 );
+ move16();
+ }
+ ELSE
+ {
+ st->VAD = 0;
+ move16();
+ }
+ }
+ ELSE
+ {
+ IF( EQ_16( st->mdct_sw, MODE1 ) )
+ {
+ /* 2 bits instead of 3 as TCX is already signaled */
+ st->core = TCX_20_CORE;
+ move16();
+ st->hTcxCfg->coder_type = get_next_indice_fx( st0, 2 );
+ move16();
+ st->coder_type = st->hTcxCfg->coder_type;
+ move16();
+ }
+ ELSE
+ {
+ IF( EQ_16( st->mdct_sw_enable, MODE2 ) )
+ {
+ IF( get_next_indice_1_fx( st0 ) )
+ {
+ ind = get_next_indice_fx( st0, 3 );
+ assert( !( ind & 4 ) || !"HQ_CORE encountered in dec_prm_ivas" );
+ st->core = TCX_20_CORE;
+ move16();
+ st->hTcxCfg->coder_type = ind;
+ move16();
+ st->coder_type = st->hTcxCfg->coder_type;
+ move16();
+ }
+ ELSE /* ACELP */
+ {
+ st->core = ACELP_CORE;
+ move16();
+ st->coder_type = get_next_indice_fx( st0, 2 );
+ move16();
+ }
+ }
+ ELSE
+ {
+ IF( EQ_16( st->rf_flag, 1 ) )
+ {
+ IF( !st->use_partial_copy )
+ {
+ ind = get_next_indice_fx( st0, 1 );
+ IF( ind == 0 )
+ {
+ st->core = ACELP_CORE;
+ move16();
+ }
+ ELSE
+ {
+ st->core = TCX_20_CORE;
+ move16();
+ st->hTcxCfg->coder_type = st->coder_type;
+ move16();
+ }
+ }
+ }
+ ELSE
+ {
+ ind = get_next_indice_fx( st, 3 );
+ IF( LT_16( ind, ACELP_MODE_MAX ) )
+ {
+ st->core = ACELP_CORE;
+ move16();
+ st->coder_type = ind;
+ move16();
+ }
+ ELSE
+ {
+ st->core = TCX_20_CORE;
+ move16();
+ st->hTcxCfg->coder_type = sub( ind, ACELP_MODE_MAX );
+ move16();
+ st->coder_type = st->hTcxCfg->coder_type;
+ move16();
+ }
+ }
+ }
+ }
+
+ IF( EQ_16( st->element_mode, EVS_MONO ) )
+ {
+ test();
+ IF( st->igf && EQ_16( st->core, ACELP_CORE ) )
+ {
+ st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) );
+ move16();
+ }
+
+ IF( st->rf_flag )
+ {
+ st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */
+ move16();
+ }
+ }
+
+ /* Inactive frame detection on non-DTX mode */
+ IF( EQ_16( st->coder_type, INACTIVE ) )
+ {
+ st->VAD = 0;
+ move16();
+ }
+ ELSE
+ {
+ st->VAD = 1;
+ move16();
+ }
+ }
+
+ /*Core extended mode mapping for correct PLC classification*/
+ st->core_ext_mode = st->coder_type;
+ move16();
+ if ( EQ_16( st->coder_type, INACTIVE ) )
+ {
+ st->core_ext_mode = UNVOICED;
+ move16();
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * getTCXWindowing_ivas()
+ *
+ * get TCX transform type for each subframe
+ *--------------------------------------------------------------------*/
+void getTCXWindowing_ivas_fx(
+ const Word16 core, /* i : current core */
+ const Word16 last_core, /* i : last frame core */
+ const Word16 element_mode, /* i : element mode */
+ TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */
+ Decoder_State *st0 /* i : bitstream */
+)
+{
+ Word16 overlap_code;
+
+ /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */
+ test();
+ test();
+ test();
+ IF( EQ_16( last_core, ACELP_CORE ) || EQ_16( last_core, AMR_WB_CORE ) )
+ {
+ hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
+ move16();
+ }
+ ELSE IF( EQ_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) )
+ {
+ hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP;
+ move16();
+ }
+ ELSE IF( NE_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) )
+ {
+ hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
+ move16();
+ }
+ ELSE
+ {
+ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
+ move16();
+ }
+
+ /* Set the current overlap mode based on the current frame type and coded overlap mode */
+ hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
+ move16();
+
+ IF( NE_16( core, ACELP_CORE ) )
+ {
+ overlap_code = 0;
+ move16();
+ IF( get_next_indice_fx( st0, 1 ) )
+ {
+ overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
+ }
+
+ assert( MIN_OVERLAP == 2 && HALF_OVERLAP == 3 );
+ hTcxCfg->tcx_curr_overlap_mode = overlap_code;
+ move16();
+ /*TCX10 : always symmetric windows*/
+ test();
+ test();
+ test();
+ IF( EQ_16( core, TCX_20_CORE ) && ( overlap_code == 0 ) && NE_16( last_core, ACELP_CORE ) && NE_16( last_core, AMR_WB_CORE ) )
+ {
+ hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
+ move16();
+ }
+ }
+
+ test();
+ IF( NE_16( element_mode, EVS_MONO ) && EQ_16( core, TCX_10_CORE ) )
+ {
+ /* also read last overlap */
+ overlap_code = 0;
+ move16();
+
+ IF( get_next_indice_fx( st0, 1 ) )
+ {
+ overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
+ }
+
+ hTcxCfg->tcx_last_overlap_mode = overlap_code;
+ move16();
+ }
+
+ return;
+}
diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c
deleted file mode 100644
index aca84d9d9cb01237ba9c9d644a876986d3d6335e..0000000000000000000000000000000000000000
--- a/lib_dec/dec_tcx.c
+++ /dev/null
@@ -1,508 +0,0 @@
-
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "prot.h"
-#include "ivas_prot.h"
-#include "prot_fx.h"
-#include
-#include "options.h"
-#include
-#include "stat_com.h"
-#include "cnst.h"
-#include "wmc_auto.h"
-#include "ivas_rom_com.h"
-#include "ivas_prot_fx.h"
-#include "debug.h"
-
-/*-------------------------------------------------------------------*
- * decoder_tcx_post()
- *
- *
- *-------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------*
- * decoder_tcx_tns()
- *
- * TCX: TNS application
- *-------------------------------------------------------------------*/
-
-void decoder_tcx_tns_fx(
- Decoder_State *st, /* i/o: coder memory state */
- const Word16 L_frame_glob, /* i : frame length */
- const Word16 L_spec,
- const Word16 L_frame,
- const Word16 L_frameTCX,
- Word32 x_fx[N_MAX], // Qx
- const Word16 fUseTns, /* i : flag that is set if TNS data is present */
- STnsData *tnsData,
- const Word16 bfi, /* i : Bad frame indicator */
- const Word16 frame_cnt, /* i : frame counter in the super frame */
- const Word16 whitenedDomain,
- Word16 *length )
-{
- Word16 index, isTCX5, L, tmp;
- TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg;
-
- index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */
- move16();
-
- isTCX5 = 0;
- move16();
- L = L_frameTCX;
- move16();
- tmp = L;
- move16();
-
- test();
- IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) )
- {
- test();
- test();
- IF( NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) )
- {
- /* fix sub-window overlap */
- hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
- move16();
- }
-
- test();
- test();
- test();
- IF( ( NE_16( hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) )
- {
- L = L_spec;
- move16();
- tmp = L;
- move16();
- }
-
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ||
- ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) ||
- ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) &&
- NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) )
- {
- isTCX5 = 1;
- move16();
-
- tcx5SpectrumDeinterleaving_fx( shr( L, 1 ), x_fx );
- }
- }
-
- /*-----------------------------------------------------------*
- * Temporal Noise Shaping Synthesis *
- *-----------------------------------------------------------*/
-
-
- test();
- test();
- test();
- IF( NE_16( hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) && EQ_16( tnsData->tnsOnWhitenedSpectra, whitenedDomain ) )
- {
- /* Apply TNS to get the reconstructed signal */
- SetTnsConfig( hTcxCfg, L_frame_glob == st->L_frame, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) );
-
- test();
- test();
- IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( isTCX5, 0 ) )
- {
- tcx5TnsGrouping_fx( shr( L, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx );
- }
-
- ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, tnsData, x_fx, 0 );
-
- test();
- test();
- IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( isTCX5, 0 ) )
- {
- test();
- IF( EQ_16( st->element_mode, EVS_MONO ) || LT_16( L_spec, L_frameTCX ) ) /* todo: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */
- {
- tcx5TnsUngrouping_fx( shr( L_frameTCX, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx, DEC );
- tmp = L_frameTCX;
- move16();
- }
- ELSE
- {
- tcx5TnsUngrouping_fx( shr( L, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx, DEC );
- }
- }
- }
- test();
- IF( NE_16( whitenedDomain, 0 ) && NE_16( isTCX5, 0 ) )
- {
- tcx5SpectrumInterleaving_fx( shr( L, 1 ), x_fx );
- }
-
- /* restore index */
- test();
- test();
- test();
- test();
- IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) )
- {
- /* restore sub-window overlap */
- hTcxCfg->tcx_last_overlap_mode = index;
- move16();
- }
-
- if ( length != NULL )
- {
- *length = tmp;
- move16();
- }
-
- return;
-}
-
-
-void decoder_tcx_imdct_fx(
- Decoder_State *st, /* i/o: coder memory state */
- const Word16 L_frame_glob, /* i : frame length */
- const Word16 L_frameTCX_glob,
- const Word16 L_spec,
- const Word16 tcx_offset,
- const Word16 tcx_offsetFB,
- const Word16 L_frame,
- const Word16 L_frameTCX,
- const Word16 left_rect,
- Word32 x_fx[N_MAX], // Q(11)
- Word16 q_x,
- Word16 xn_buf_fx[], // Q(-2)
- Word16 q_win,
- const UWord16 kernelType, /* i : TCX transform kernel type */
- const Word16 fUseTns, /* i : flag that is set if TNS data is present */
- Word16 synth_fx[], // Q(-2) /* i/o: synth[-M..L_frame] */
- Word16 synthFB_fx[], // Q(-2)
- const Word16 bfi, /* i : Bad frame indicator */
- const Word16 frame_cnt, /* i : frame counter in the super frame */
- const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */
-)
-{
- Word16 j, L, overlap, curr_order, startLine, endLine, isTCX5;
- Word16 overlapFB;
- Word32 x_tmp_fx[L_FRAME_PLUS];
- Word32 xn_bufFB_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX] = { 0 };
- Word16 xn_bufFB_fx_16[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX];
- Word16 acelp_zir_fx[L_FRAME_MAX / 2];
- Word32 x_itf_fx[N_MAX_TCX - IGF_START_MN];
- Word16 index, proc = 0;
- TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
- TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
- TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg;
- Word16 predictionGain_fx;
- Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; // q_a_itf
- Word16 q_a_itf = 15;
- Word16 x_e = sub( 31, q_x );
- move16();
- Word16 shift_q = sub( q_x, q_win );
-
- /*-----------------------------------------------------------------*
- * Initializations
- *-----------------------------------------------------------------*/
-
- /* Init lengths */
- overlap = hTcxCfg->tcx_mdct_window_length;
- move16();
- overlapFB = hTcxCfg->tcx_mdct_window_lengthFB;
- move16();
-
- index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */
- move16();
- test();
- test();
- test();
- test();
- IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly != 0 ) && ( frame_cnt != 0 ) && ( bfi == 0 ) && ( st->last_core != ACELP_CORE ) )
- {
- /* fix sub-window overlap */
- hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
- move16();
- }
-
- IF( st->igf != 0 )
- {
- proc = st->hIGFDec->flatteningTrigger;
- move16();
-
- test();
- IF( proc && fUseTns != 0 )
- {
- proc = 0;
- move16();
- }
-
- IF( proc )
- {
-
- startLine = st->hIGFDec->infoIGFStartLine;
- move16();
- endLine = st->hIGFDec->infoIGFStopLine;
- move16();
- curr_order = 0;
- move16();
- predictionGain_fx = 0;
- move16();
- L = L_frameTCX;
- move16();
- isTCX5 = 0;
- move16();
-
- /* interleave again for ITF */
- test();
- IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly )
- {
- test();
- test();
- test();
- IF( ( hTcxCfg->fIsTNSAllowed && ( fUseTns != 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) )
- {
- L = L_spec;
- move16();
- }
-
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( ( bfi == 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) ||
- ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( index == 0 ) ) ) ) ||
- ( ( bfi != 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) &&
- ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) ) )
- {
- isTCX5 = 1;
- move16();
-
- tcx5SpectrumInterleaving_fx( shr( L, 1 ), x_fx );
- }
- }
-
- FOR( j = startLine; j < endLine; j++ )
- {
- IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) )
- {
- x_itf_fx[j - IGF_START_MN] = x_fx[j]; // q_x
- move32();
- x_fx[j] = st->hIGFDec->virtualSpec_fx[j - IGF_START_MN];
- move32();
- }
- }
-
- ITF_Detect_fx( x_fx + IGF_START_MN, startLine, endLine, 8 /*maxOrder*/, A_itf_fx, &q_a_itf, &predictionGain_fx, &curr_order, shl( x_e, 1 ) );
-
- ITF_Apply_fx( x_fx, startLine, endLine, A_itf_fx, q_a_itf, curr_order );
-
- FOR( j = startLine; j < endLine; j++ )
- {
- IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) )
- {
- x_fx[j] = x_itf_fx[j - IGF_START_MN]; // q_x
- move32();
- }
- }
-
- /* deinterleave */
- IF( NE_16( isTCX5, 0 ) )
- {
- tcx5SpectrumDeinterleaving_fx( shr( L, 1 ), x_fx );
- }
- }
- }
-
- /*-----------------------------------------------------------*
- * Prepare OLA buffer after waveadjustment. *
- * Compute inverse MDCT of x[]. *
- *-----------------------------------------------------------*/
-
-
- IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
- {
- Word16 copy_len = s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) );
- set32_fx( x_tmp_fx, 0, L_FRAME_PLUS );
- Copy32( x_fx, x_tmp_fx, copy_len ); // q_x
- Copy32( x_fx, xn_bufFB_fx, copy_len ); // q_x
- }
- ELSE IF( ( st->element_mode == EVS_MONO ) )
- {
- Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x
- }
- ELSE
- {
- Word16 copy_len = s_max( L_spec, s_max( L_frame, L_frameTCX ) );
- Copy32( x_fx, x_tmp_fx, copy_len ); // q_x
- Copy32( x_fx, xn_bufFB_fx, copy_len ); // q_x
- }
-
- IF( ( st->igf != 0 ) )
- {
- set32_fx( xn_bufFB_fx + st->hIGFDec->infoIGFStartLine, 0, L_frameTCX - st->hIGFDec->infoIGFStartLine );
- }
-
- test();
- IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && !sba_dirac_stereo_flag )
- {
-
- IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2,
- hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index,
- kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win );
- }
-
- /* Generate additional comfort noise to mask potential coding artefacts */
- test();
- test();
- test();
- IF( ( st->flag_cna != 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->cna_dirac_flag == 0 ) )
- {
- generate_masking_noise_mdct_ivas_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom );
- FOR( Word16 ind = 0; ind < L_frame; ind++ )
- {
- x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); // q_x
- }
- }
-
- test();
- IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( sba_dirac_stereo_flag != 0 ) )
- {
- Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x
-
- IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index,
- kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win );
- }
-
- FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ )
- {
- xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], shift_q ) ); // q_x
- move16();
- }
-
- Word16 ratio_e;
- Word16 ratio = BASOP_Util_Divide1616_Scale( L_frameTCX_glob, L_frame_glob, &ratio_e ); // Q = 15-ratio_e. * FSCALE_DENOM is (1 << 9)
- ratio = shr( ratio, sub( 6, ratio_e ) );
-
- IF( st->element_mode != EVS_MONO )
- {
- IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB,
- hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index,
- kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win );
- }
- ELSE
- {
-
- IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index,
- kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win );
- }
- FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ )
- {
- xn_bufFB_fx[ind] = L_shl( L_deposit_l( xn_bufFB_fx_16[ind] ), shift_q ); // Q_x
- }
-
- IF( ( bfi == 0 ) )
- {
- Word16 res_m, res_e = 0;
- move16();
- st->second_last_tns_active = st->last_tns_active;
- move16();
- st->last_tns_active = hTcxCfg->fIsTNSAllowed & fUseTns;
- move16();
- hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch;
- move32();
- hTcxDec->tcxltp_second_last_pitch = st->old_fpitch;
- move32();
- res_m = BASOP_Util_Divide1616_Scale( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max, &res_e );
- st->old_fpitch = L_add( L_shl( hTcxLtpDec->tcxltp_pitch_int, 16 ), L_shl( res_m, add( res_e, 1 ) ) );
-
- IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
- {
- // Using sat as a single instruction shifts and extracts
- st->old_fpitch = W_shl_sat_l( W_mult0_32_32( st->old_fpitch, L_frame_glob ), -8 ); // Divide by 256 ==> SHR by 8
- move32();
- }
-
- IF( GT_16( st->element_mode, EVS_MONO ) )
- {
- res_m = BASOP_Util_Divide1616_Scale( L_frameTCX_glob, L_frame_glob, &res_e );
- st->old_fpitchFB = L_shl( Mpy_32_16_1( st->old_fpitch, res_m ), res_e );
- move32();
- }
- ELSE
- {
- res_m = BASOP_Util_Divide1616_Scale( L_frameTCX, L_frame, &res_e );
- st->old_fpitchFB = L_shl( Mpy_32_16_1( st->old_fpitch, res_m ), res_e );
- move32();
- }
- }
-
- /* Update old_syn_overl */
- IF( hTcxCfg->last_aldo == 0 )
- {
- Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); // Q(-2)
- FOR( Word16 ind = 0; ind < overlapFB; ind++ )
- {
- hTcxDec->syn_OverlFB[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + L_frameTCX )], shift_q ) ); // q_x
- }
- }
-
- /* Output */
- Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); // Q(-2)
- FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ )
- {
- synthFB_fx[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ); // q_x
- }
-
-
- return;
-}
-
-/*-------------------------------------------------------------------*
- * init_tcx_info()
- *
- * Initialize lengths for TCX processing, update IGF subframe info
- *-------------------------------------------------------------------*/
diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c
index a0556437dbdba05954c2ae8cef80c71761abf197..00f372154d0b6ad725b3e2c6078d16fa6b9d9e33 100644
--- a/lib_dec/dec_tcx_fx.c
+++ b/lib_dec/dec_tcx_fx.c
@@ -9,7 +9,6 @@
#include "basop_util.h"
#include "stl.h"
#include "options.h"
-#include "prot.h"
#include "math.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
@@ -3808,7 +3807,7 @@ void decoder_tcx_invQ_fx(
FOR( i = 0; i < noiseFillingSize; ++i )
{
tmp32 = L_shr( x[i], sub( 31, *x_e ) );
- *nf_seed = add_o( *nf_seed, (Word16) abs( tmp32 ) * i * 2, &Overflow );
+ *nf_seed = add_o( *nf_seed, shl( i_mult( (Word16) L_abs( tmp32 ), i ), 1 ), &Overflow ); // abs( tmp32 ) * i * 2
move16();
}
}
@@ -3876,7 +3875,8 @@ void decoder_tcx_invQ_fx(
test();
IF( !st->tcxonly || ( hTcxCfg->resq && hTcxDec->tcx_lpc_shaped_ari ) )
{
- FOR( i = 0; i < max( L_spec, L_frameTCX ); i++ )
+ Word16 len = s_max( L_spec, L_frameTCX );
+ FOR( i = 0; i < len; i++ )
{
xn_buf[i] = ONE_IN_Q14;
move16();
@@ -4856,3 +4856,449 @@ void decoder_tcx_noiseshaping_igf_fx(
return;
}
+
+
+/*-------------------------------------------------------------------*
+ * decoder_tcx_tns()
+ *
+ * TCX: TNS application
+ *-------------------------------------------------------------------*/
+
+void decoder_tcx_tns_fx(
+ Decoder_State *st, /* i/o: coder memory state */
+ const Word16 L_frame_glob, /* i : frame length */
+ const Word16 L_spec,
+ const Word16 L_frame,
+ const Word16 L_frameTCX,
+ Word32 x_fx[N_MAX], // Qx
+ const Word16 fUseTns, /* i : flag that is set if TNS data is present */
+ STnsData *tnsData,
+ const Word16 bfi, /* i : Bad frame indicator */
+ const Word16 frame_cnt, /* i : frame counter in the super frame */
+ const Word16 whitenedDomain,
+ Word16 *length )
+{
+ Word16 index, isTCX5, L, tmp;
+ TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg;
+
+ index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */
+ move16();
+
+ isTCX5 = 0;
+ move16();
+ L = L_frameTCX;
+ move16();
+ tmp = L;
+ move16();
+
+ test();
+ IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly != 0 )
+ {
+ test();
+ test();
+ IF( frame_cnt != 0 && bfi == 0 && st->last_core != ACELP_CORE )
+ {
+ /* fix sub-window overlap */
+ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
+ move16();
+ }
+
+ test();
+ test();
+ test();
+ IF( ( NE_16( hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) )
+ {
+ L = L_spec;
+ move16();
+ tmp = L;
+ move16();
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ||
+ ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) ||
+ ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) &&
+ NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) )
+ {
+ isTCX5 = 1;
+ move16();
+
+ tcx5SpectrumDeinterleaving_fx( shr( L, 1 ), x_fx );
+ }
+ }
+
+ /*-----------------------------------------------------------*
+ * Temporal Noise Shaping Synthesis *
+ *-----------------------------------------------------------*/
+
+
+ test();
+ test();
+ test();
+ IF( NE_16( hTcxCfg->fIsTNSAllowed, 0 ) && fUseTns != 0 && NE_16( bfi, 1 ) && EQ_16( tnsData->tnsOnWhitenedSpectra, whitenedDomain ) )
+ {
+ /* Apply TNS to get the reconstructed signal */
+ SetTnsConfig( hTcxCfg, L_frame_glob == st->L_frame, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) );
+
+ test();
+ test();
+ IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly != 0 && isTCX5 != 0 )
+ {
+ tcx5TnsGrouping_fx( shr( L, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx );
+ }
+
+ ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, tnsData, x_fx, 0 );
+
+ test();
+ test();
+ IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly != 0 && isTCX5 != 0 )
+ {
+ test();
+ IF( st->element_mode == EVS_MONO || LT_16( L_spec, L_frameTCX ) ) /* todo: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */
+ {
+ tcx5TnsUngrouping_fx( shr( L_frameTCX, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx, DEC );
+ tmp = L_frameTCX;
+ move16();
+ }
+ ELSE
+ {
+ tcx5TnsUngrouping_fx( shr( L, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx, DEC );
+ }
+ }
+ }
+ test();
+ IF( NE_16( whitenedDomain, 0 ) && NE_16( isTCX5, 0 ) )
+ {
+ tcx5SpectrumInterleaving_fx( shr( L, 1 ), x_fx );
+ }
+
+ /* restore index */
+ test();
+ test();
+ test();
+ test();
+ IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) )
+ {
+ /* restore sub-window overlap */
+ hTcxCfg->tcx_last_overlap_mode = index;
+ move16();
+ }
+
+ if ( length != NULL )
+ {
+ *length = tmp;
+ move16();
+ }
+
+ return;
+}
+
+
+void decoder_tcx_imdct_fx(
+ Decoder_State *st, /* i/o: coder memory state */
+ const Word16 L_frame_glob, /* i : frame length */
+ const Word16 L_frameTCX_glob,
+ const Word16 L_spec,
+ const Word16 tcx_offset,
+ const Word16 tcx_offsetFB,
+ const Word16 L_frame,
+ const Word16 L_frameTCX,
+ const Word16 left_rect,
+ Word32 x_fx[N_MAX], // Q(11)
+ Word16 q_x,
+ Word16 xn_buf_fx[], // Q(-2)
+ Word16 q_win,
+ const UWord16 kernelType, /* i : TCX transform kernel type */
+ const Word16 fUseTns, /* i : flag that is set if TNS data is present */
+ Word16 synth_fx[], // Q(-2) /* i/o: synth[-M..L_frame] */
+ Word16 synthFB_fx[], // Q(-2)
+ const Word16 bfi, /* i : Bad frame indicator */
+ const Word16 frame_cnt, /* i : frame counter in the super frame */
+ const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */
+)
+{
+ Word16 j, L, overlap, curr_order, startLine, endLine, isTCX5;
+ Word16 overlapFB;
+ Word32 x_tmp_fx[L_FRAME_PLUS];
+ Word32 xn_bufFB_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX] = { 0 };
+ Word16 xn_bufFB_fx_16[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX];
+ Word16 acelp_zir_fx[L_FRAME_MAX / 2];
+ Word32 x_itf_fx[N_MAX_TCX - IGF_START_MN];
+ Word16 index, proc = 0;
+ TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
+ TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
+ TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg;
+ Word16 predictionGain_fx;
+ Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; // q_a_itf
+ Word16 q_a_itf = 15;
+ Word16 x_e = sub( 31, q_x );
+ move16();
+ Word16 shift_q = sub( q_x, q_win );
+
+ /*-----------------------------------------------------------------*
+ * Initializations
+ *-----------------------------------------------------------------*/
+
+ /* Init lengths */
+ overlap = hTcxCfg->tcx_mdct_window_length;
+ move16();
+ overlapFB = hTcxCfg->tcx_mdct_window_lengthFB;
+ move16();
+
+ index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */
+ move16();
+ test();
+ test();
+ test();
+ test();
+ IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly != 0 ) && ( frame_cnt != 0 ) && ( bfi == 0 ) && ( st->last_core != ACELP_CORE ) )
+ {
+ /* fix sub-window overlap */
+ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
+ move16();
+ }
+
+ IF( st->igf != 0 )
+ {
+ proc = st->hIGFDec->flatteningTrigger;
+ move16();
+
+ test();
+ IF( proc && fUseTns != 0 )
+ {
+ proc = 0;
+ move16();
+ }
+
+ IF( proc )
+ {
+
+ startLine = st->hIGFDec->infoIGFStartLine;
+ move16();
+ endLine = st->hIGFDec->infoIGFStopLine;
+ move16();
+ curr_order = 0;
+ move16();
+ predictionGain_fx = 0;
+ move16();
+ L = L_frameTCX;
+ move16();
+ isTCX5 = 0;
+ move16();
+
+ /* interleave again for ITF */
+ test();
+ IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly )
+ {
+ test();
+ test();
+ test();
+ IF( ( hTcxCfg->fIsTNSAllowed && ( fUseTns != 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) )
+ {
+ L = L_spec;
+ move16();
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( ( bfi == 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) ||
+ ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( index == 0 ) ) ) ) ||
+ ( ( bfi != 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) &&
+ ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) ) )
+ {
+ isTCX5 = 1;
+ move16();
+
+ tcx5SpectrumInterleaving_fx( shr( L, 1 ), x_fx );
+ }
+ }
+
+ FOR( j = startLine; j < endLine; j++ )
+ {
+ IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) )
+ {
+ x_itf_fx[j - IGF_START_MN] = x_fx[j]; // q_x
+ move32();
+ x_fx[j] = st->hIGFDec->virtualSpec_fx[j - IGF_START_MN];
+ move32();
+ }
+ }
+
+ ITF_Detect_fx( x_fx + IGF_START_MN, startLine, endLine, 8 /*maxOrder*/, A_itf_fx, &q_a_itf, &predictionGain_fx, &curr_order, shl( x_e, 1 ) );
+
+ ITF_Apply_fx( x_fx, startLine, endLine, A_itf_fx, q_a_itf, curr_order );
+
+ FOR( j = startLine; j < endLine; j++ )
+ {
+ IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) )
+ {
+ x_fx[j] = x_itf_fx[j - IGF_START_MN]; // q_x
+ move32();
+ }
+ }
+
+ /* deinterleave */
+ IF( NE_16( isTCX5, 0 ) )
+ {
+ tcx5SpectrumDeinterleaving_fx( shr( L, 1 ), x_fx );
+ }
+ }
+ }
+
+ /*-----------------------------------------------------------*
+ * Prepare OLA buffer after waveadjustment. *
+ * Compute inverse MDCT of x[]. *
+ *-----------------------------------------------------------*/
+
+
+ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
+ {
+ Word16 copy_len = s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) );
+ set32_fx( x_tmp_fx, 0, L_FRAME_PLUS );
+ Copy32( x_fx, x_tmp_fx, copy_len ); // q_x
+ Copy32( x_fx, xn_bufFB_fx, copy_len ); // q_x
+ }
+ ELSE IF( ( st->element_mode == EVS_MONO ) )
+ {
+ Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x
+ }
+ ELSE
+ {
+ Word16 copy_len = s_max( L_spec, s_max( L_frame, L_frameTCX ) );
+ Copy32( x_fx, x_tmp_fx, copy_len ); // q_x
+ Copy32( x_fx, xn_bufFB_fx, copy_len ); // q_x
+ }
+
+ IF( ( st->igf != 0 ) )
+ {
+ set32_fx( xn_bufFB_fx + st->hIGFDec->infoIGFStartLine, 0, L_frameTCX - st->hIGFDec->infoIGFStartLine );
+ }
+
+ test();
+ IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && !sba_dirac_stereo_flag )
+ {
+
+ IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2,
+ hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index,
+ kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win );
+ }
+
+ /* Generate additional comfort noise to mask potential coding artefacts */
+ test();
+ test();
+ test();
+ IF( ( st->flag_cna != 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->cna_dirac_flag == 0 ) )
+ {
+ generate_masking_noise_mdct_ivas_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom );
+ FOR( Word16 ind = 0; ind < L_frame; ind++ )
+ {
+ x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); // q_x
+ }
+ }
+
+ test();
+ IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( sba_dirac_stereo_flag != 0 ) )
+ {
+ Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x
+
+ IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index,
+ kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win );
+ }
+
+ FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ )
+ {
+ xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], shift_q ) ); // q_x
+ move16();
+ }
+
+ Word16 ratio_e;
+ Word16 ratio = BASOP_Util_Divide1616_Scale( L_frameTCX_glob, L_frame_glob, &ratio_e ); // Q = 15-ratio_e. * FSCALE_DENOM is (1 << 9)
+ ratio = shr( ratio, sub( 6, ratio_e ) );
+
+ IF( st->element_mode != EVS_MONO )
+ {
+ IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB,
+ hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index,
+ kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win );
+ }
+ ELSE
+ {
+
+ IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index,
+ kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win );
+ }
+ FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ )
+ {
+ xn_bufFB_fx[ind] = L_shl( L_deposit_l( xn_bufFB_fx_16[ind] ), shift_q ); // Q_x
+ }
+
+ IF( ( bfi == 0 ) )
+ {
+ Word16 res_m, res_e = 0;
+ move16();
+ st->second_last_tns_active = st->last_tns_active;
+ move16();
+ st->last_tns_active = hTcxCfg->fIsTNSAllowed & fUseTns;
+ move16();
+ hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch;
+ move32();
+ hTcxDec->tcxltp_second_last_pitch = st->old_fpitch;
+ move32();
+ res_m = BASOP_Util_Divide1616_Scale( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max, &res_e );
+ st->old_fpitch = L_add( L_shl( hTcxLtpDec->tcxltp_pitch_int, 16 ), L_shl( res_m, add( res_e, 1 ) ) );
+
+ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
+ {
+ // Using sat as a single instruction shifts and extracts
+ st->old_fpitch = W_shl_sat_l( W_mult0_32_32( st->old_fpitch, L_frame_glob ), -8 ); // Divide by 256 ==> SHR by 8
+ move32();
+ }
+
+ IF( GT_16( st->element_mode, EVS_MONO ) )
+ {
+ res_m = BASOP_Util_Divide1616_Scale( L_frameTCX_glob, L_frame_glob, &res_e );
+ st->old_fpitchFB = L_shl( Mpy_32_16_1( st->old_fpitch, res_m ), res_e );
+ move32();
+ }
+ ELSE
+ {
+ res_m = BASOP_Util_Divide1616_Scale( L_frameTCX, L_frame, &res_e );
+ st->old_fpitchFB = L_shl( Mpy_32_16_1( st->old_fpitch, res_m ), res_e );
+ move32();
+ }
+ }
+
+ /* Update old_syn_overl */
+ IF( hTcxCfg->last_aldo == 0 )
+ {
+ Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); // Q(-2)
+ FOR( Word16 ind = 0; ind < overlapFB; ind++ )
+ {
+ hTcxDec->syn_OverlFB[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + L_frameTCX )], shift_q ) ); // q_x
+ }
+ }
+
+ /* Output */
+ Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); // Q(-2)
+ FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ )
+ {
+ synthFB_fx[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ); // q_x
+ }
+
+
+ return;
+}
diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c
index a83de038afe2e1fa2a92923f65ca270fec68b461..f9833e80a85cc38309828ee2b6f2d0764df82741 100644
--- a/lib_dec/decision_matrix_dec_fx.c
+++ b/lib_dec/decision_matrix_dec_fx.c
@@ -681,12 +681,12 @@ void decision_matrix_dec_fx(
st->nb_subfr = NB_SUBFR16k;
move16();
}
-#if 1 // def ADD_IVAS_BWE 0> NEEDED for IO with conf_acelp1
+
st->extl_orig = st->extl;
move16();
st->extl_brate_orig = st->extl_brate;
move32();
-#endif
+
test();
IF( EQ_32( st->output_Fs, 8000 ) )
{
diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c
index de644843362064518ad334eee93afa097fb7a7f3..f20ff77f30367e0dc15e2f7936f0d46892a4a014 100644
--- a/lib_dec/evs_dec_fx.c
+++ b/lib_dec/evs_dec_fx.c
@@ -36,11 +36,7 @@ ivas_error evs_dec_fx(
Word16 exp, fra;
Word16 tmp_buffer_fx[L_FRAME48k];
Word16 tmp16, tmp16_2;
-#ifdef IVAS_CODE
- Word16 synth_fx[L_FRAME48k];
-#else
Word16 synth_fx[L_FRAME48k + HQ_DELTA_MAX * HQ_DELAY_COMP];
-#endif
Word16 fb_exc_fx[L_FRAME16k];
Word16 pitch_buf_fx[NB_SUBFR16k] = { 0 };
Word16 Q_fb_exc;
@@ -333,7 +329,7 @@ ivas_error evs_dec_fx(
/*---------------------------------------------------------------------*
* Preprocessing (preparing) for ACELP/HQ core switching
*---------------------------------------------------------------------*/
- // PMT("core_switching_pre_dec_fx missign args")
+
IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK )
{
return error;
@@ -346,7 +342,6 @@ ivas_error evs_dec_fx(
IF( EQ_16( st_fx->core, ACELP_CORE ) )
{
/* ACELP core decoder */
-
IF( ( error = acelp_core_dec_fx( st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK )
{
return error;
@@ -356,25 +351,16 @@ ivas_error evs_dec_fx(
}
ELSE
{
- // PMT("HQ core missing args")
-
hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag );
Qpostd = Q_synth;
move16();
}
+
/*---------------------------------------------------------------------*
* Postprocessing for ACELP/HQ core switching
*---------------------------------------------------------------------*/
- if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx,
-#ifdef IVAS_CODE_SWITCHING
- output, output_mem[], IVAS_FORMAT ivas_format, use_cldfb_for_dft,
-#endif
- output_frame, core_switching_flag,
-#ifdef IVAS_CODE_SWITCHING
- sba_dirac_stereo_flag, nchan_out,
-#endif
- st_fx->last_element_mode, &Qpostd ) ) != IVAS_ERR_OK )
+ if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, st_fx->last_element_mode, &Qpostd ) ) != IVAS_ERR_OK )
{
return error;
}
@@ -382,7 +368,6 @@ ivas_error evs_dec_fx(
* Pre-processing for bandwidth switching
*---------------------------------------------------------------------*/
- /// PMT("bw_switching_pre_proc_fx missing args")
bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx );
/*---------------------------------------------------------------------*
@@ -398,15 +383,7 @@ ivas_error evs_dec_fx(
ELSE IF( EQ_16( st_fx->extl, WB_BWE ) && st_fx->bws_cnt == 0 )
{
/* WB BWE decoder */
- hb_synth_fx_exp = wb_bwe_dec_fx(
-#ifdef ADD_IVAS_BWE
- NULL,
-#endif
- synth_fx, hb_synth_fx,
-#ifdef ADD_IVAS_BWE
- 0,
-#endif
- output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); /*Q0*/
+ hb_synth_fx_exp = wb_bwe_dec_fx( synth_fx, hb_synth_fx, output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); /*Q0*/
}
/*---------------------------------------------------------------------*
@@ -449,15 +426,7 @@ ivas_error evs_dec_fx(
( GE_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->core, ACELP_CORE ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) )
{
/* SWB BWE decoder */
- hb_synth_fx_exp = swb_bwe_dec_fx(
-#ifdef ADD_IVAS_BWE
- NULL,
-#endif
- st_fx, synth_fx, hb_synth_fx,
-#ifdef ADD_IVAS_BWE
- 0,
-#endif
- output_frame, &Qpostd ); /*Q0*/
+ hb_synth_fx_exp = swb_bwe_dec_fx( st_fx, synth_fx, hb_synth_fx, output_frame, &Qpostd ); /*Q0*/
}
ELSE IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) )
{
@@ -919,7 +888,7 @@ ivas_error evs_dec_fx(
IF( ( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, FB ) ) &&
( ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) )
{
- GenTransition_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, 2 * NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), hb_synth_fx,
+ GenTransition_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, shl( NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), 1 ), hb_synth_fx,
hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx,
hBWE_TD->mem_resamp_HB_32k_fx,
&( hBWE_TD->syn_dm_phase ), st_fx->output_Fs, hBWE_TD->int_3_over_2_tbemem_dec_fx, st_fx->rf_flag, st_fx->total_brate );
@@ -929,7 +898,7 @@ ivas_error evs_dec_fx(
}
ELSE IF( EQ_16( st_fx->bwidth, WB ) && EQ_16( st_fx->last_extl, WB_TBE ) )
{
- GenTransition_WB_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, st_fx->prev_Qx, 2 * NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), hb_synth_fx,
+ GenTransition_WB_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, st_fx->prev_Qx, shl( NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), 1 ), hb_synth_fx,
hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, st_fx->output_Fs, hBWE_TD->mem_resamp_HB_fx );
hb_synth_fx_exp = st_fx->prev_Qx;
@@ -1327,12 +1296,12 @@ ivas_error evs_dec_fx(
{
IF( EQ_32( st_fx->output_Fs, 8000 ) )
{
- Copy( hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*st_fx->q_prev_synth_buffer_fx*/
+ Copy( hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*st_fx->q_prev_synth_buffer_fx*/
}
ELSE
{
- Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /*st_fx->Qprev_synth_buffer_fx*/
- Copy( hTcxDec->FBTCXdelayBuf + NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*Q0*/
+ Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /*st_fx->Qprev_synth_buffer_fx*/
+ Copy( hTcxDec->FBTCXdelayBuf + NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st_fx->delay_buf_out_fx, NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*Q0*/
}
}
}
@@ -1362,7 +1331,7 @@ ivas_error evs_dec_fx(
Scale_sig( output_sp, output_frame, timeIn_e ); /*timeIn_e*/
- tcx_ltp_post( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS ) + tmps,
+ tcx_ltp_post( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, add( NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS ), tmps ),
output_sp, hTcxDec->FBTCXdelayBuf );
Copy( output_sp, synth_fx, output_frame ); /*timeIn_e*/
@@ -1372,7 +1341,7 @@ ivas_error evs_dec_fx(
/*----------------------------------------------------------------*
* Save synthesis for HQ FEC
*----------------------------------------------------------------*/
- // PMT("The code below could be move to save_synthesis_hq_fec")
+
post_hq_delay = NS2SA_FX2( st_fx->output_Fs, POST_HQ_DELAY_NS );
IF( EQ_16( st_fx->codec_mode, MODE1 ) )
{
@@ -1397,8 +1366,8 @@ ivas_error evs_dec_fx(
ELSE
{
- Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); /*Q0*/
- Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ) - NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); /*Q0*/
+ Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); /*Q0*/
+ Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); /*Q0*/
}
}
}
diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c
deleted file mode 100644
index dd3adb2470ab33c3b0d5da3f21bad0e8c9cb366b..0000000000000000000000000000000000000000
--- a/lib_dec/fd_cng_dec.c
+++ /dev/null
@@ -1,1393 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include
-#include "prot.h"
-#include "ivas_prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
-#include "ivas_prot.h"
-#include "ivas_rom_dec.h"
-#include "ivas_rom_com_fx.h"
-#include "prot_fx.h"
-#include "ivas_prot_fx.h"
-#include "basop_util.h"
-#include "rom_basop_util.h"
-
-/*-------------------------------------------------------------------
- * Local constants
- *-------------------------------------------------------------------*/
-
-#define DELTA_MASKING_NOISE_Q15 0
-#define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */
-#define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */
-#define LOG_10_BASE_2 1783446566 /* Q29 */
-#define GAIN_Q_OFFSET_IVAS_FX 45
-#define LOG_10_BASE_2_BY_10_Q31 713378606
-#define TWO_BY_THREE_Q31 1431655765
-#define ONE_BY_FRAMES_PER_SEC_Q15 656
-#define NB_LAST_BAND_SCALE_Q31 1717986918
-#define SWB_13k2_LAST_BAND_SCALE_Q31 1717986918
-
-/*-------------------------------------------------------------------
- * Local fucntions declarations
- *-------------------------------------------------------------------*/
-
-/*-------------------------------------------------------------------
- * createFdCngDec()
- *
- * Create an instance of type FD_CNG
- *-------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------
- * initFdCngDec()
- *
- * Initialize an instance of type FD_CNG
- *-------------------------------------------------------------------*/
-void configureFdCngDec_ivas_fx(
- HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */
- const Word16 bwidth, /*Q0*/
- const Word32 total_brate, /*Q0*/
- const Word16 L_frame, /*Q0*/
- const Word16 last_L_frame, /*Q0*/
- const Word16 element_mode /*Q0*/ )
-{
- Word16 j, stopBandFR;
- HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom;
-
- hsCom->CngBandwidth = bwidth; /*Q0*/
- move16();
- if ( EQ_16( hsCom->CngBandwidth, FB ) )
- {
- hsCom->CngBandwidth = SWB;
- move16();
- }
- test();
- IF( NE_32( total_brate, FRAME_NO_DATA ) && NE_32( total_brate, SID_2k40 ) )
- {
- hsCom->CngBitrate = total_brate; /*Q0*/
- move32();
- }
- ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) )
- {
- /* set minimum active CBR bitrate IF CngBitrate is uninitialized */
- IF( element_mode > EVS_MONO )
- {
- hsCom->CngBitrate = IVAS_13k2;
- move32();
- }
- ELSE
- {
- hsCom->CngBitrate = ACELP_7k20;
- move32();
- }
- }
-
- /* FD-CNG config for MDCT-Stereo is always the same (since for > 48 kbps only) */
- /* This may need adjustment in the future IF 2TC DTX for some mode uses MDCT-Stereo DTX for lower bitrates too */
- if ( EQ_16( element_mode, IVAS_CPE_MDCT ) )
- {
- hsCom->CngBitrate = IVAS_48k;
- move32();
- }
- hsCom->numSlots = 16;
- move32();
-
- /* NB configuration */
- IF( EQ_16( bwidth, NB ) )
- {
- hsCom->FdCngSetup = FdCngSetup_nb;
- hsCom->numCoreBands = 16;
- move16();
- hsCom->regularStopBand = 16;
- move16();
- }
-
- /* WB configuration */
- ELSE IF( EQ_16( bwidth, WB ) )
- {
- /* FFT 6.4kHz, no CLDFB */
- test();
- test();
- IF( LE_32( hsCom->CngBitrate, ACELP_8k00 ) && EQ_16( L_frame, L_FRAME ) )
- {
- hsCom->FdCngSetup = FdCngSetup_wb1;
- hsCom->numCoreBands = 16;
- move16();
- hsCom->regularStopBand = 16;
- move16();
- }
- /* FFT 6.4kHz, CLDFB 8.0kHz */
- ELSE IF( LE_32( hsCom->CngBitrate, ACELP_13k20 ) || EQ_16( L_frame, L_FRAME ) )
- {
- hsCom->FdCngSetup = FdCngSetup_wb2;
- hsCom->numCoreBands = 16;
- move16();
- hsCom->regularStopBand = 20;
- move16();
- IF( EQ_16( L_frame, L_FRAME16k ) )
- {
- hsCom->FdCngSetup = FdCngSetup_wb2;
- hsCom->numCoreBands = 20;
- move16();
- hsCom->regularStopBand = 20;
- move16();
- hsCom->FdCngSetup.fftlen = 640;
- move16();
- hsCom->FdCngSetup.stopFFTbin = 256;
- move16();
- }
- }
- /* FFT 8.0kHz, no CLDFB */
- ELSE
- {
- hsCom->FdCngSetup = FdCngSetup_wb3;
- hsCom->numCoreBands = 20;
- move16();
- hsCom->regularStopBand = 20;
- move16();
- }
- }
-
- /* SWB/FB configuration */
- ELSE
- {
- /* FFT 6.4kHz, CLDFB 14kHz */
- IF( EQ_16( L_frame, L_FRAME ) )
- {
- hsCom->FdCngSetup = FdCngSetup_swb1;
- hsCom->numCoreBands = 16;
- move16();
- hsCom->regularStopBand = 35;
- move16();
- }
- /* FFT 8.0kHz, CLDFB 16kHz */
- ELSE
- {
- hsCom->FdCngSetup = FdCngSetup_swb2;
- hsCom->numCoreBands = 20;
- move16();
- hsCom->regularStopBand = 40;
- move16();
- test();
- if ( EQ_16( last_L_frame, L_FRAME ) && EQ_16( element_mode, IVAS_CPE_DFT ) )
- {
- hsCom->regularStopBand = 35;
- move16();
- }
- }
- }
-
-
- hsCom->fftlen = hsCom->FdCngSetup.fftlen;
- move16();
- hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin;
- move16();
-
- /* Configure the SID quantizer and the Comfort Noise Generator */
-
- hsCom->startBand = 2;
- move16();
- hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[( hsCom->FdCngSetup.numPartitions - 1 )], 1 ); /*Q0*/
- initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 );
-
- IF( EQ_16( hsCom->stopFFTbin, 160 ) )
- {
- hsCom->nFFTpart = 17;
- move16();
- }
- ELSE IF( EQ_16( hsCom->stopFFTbin, 256 ) )
- {
- hsCom->nFFTpart = 20;
- move16();
- }
- ELSE
- {
- hsCom->nFFTpart = 21;
- move16();
- }
- hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); /*Q0*/
- move16();
- FOR( j = 0; j < hsCom->nCLDFBpart; j++ )
- {
- hsCom->CLDFBpart[j] = sub( hsCom->part[( j + hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); /*Q0*/
- move16();
- hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[( j + hsCom->nFFTpart )];
- move16();
- }
-
- stopBandFR = 40; //(Word16)floor(1000.f /*Hz*/ / 25.f /*Hz/Bin*/);
- move16();
- if ( GT_16( stopBandFR, hsCom->stopFFTbin ) )
- {
- stopBandFR = hsCom->stopFFTbin; /*Q0*/
- move16();
- }
-
- initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR );
-
- hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; /*Q0*/
- move16();
-
- BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) );
- BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) );
-
- SWITCH( hsCom->fftlen )
- {
- case 512:
- hsCom->olapWinAna_fx = olapWinAna512_fx; /*Q30*/
- hsCom->fftSineTab_fx = NULL;
- hsCom->olapWinSyn_fx = olapWinSyn256_fx; /*Q15*/
- hsCom->fftlenShift = 8;
- move16();
- hsCom->fftlenFac = 32767 /*1.0 Q15*/;
- move16();
- BREAK;
- case 640:
- hsCom->olapWinAna_fx = olapWinAna640_fx; /*Q30*/
- hsCom->fftSineTab_fx = fftSineTab640_fx; /*Q15*/
- hsCom->olapWinSyn_fx = olapWinSyn320_fx; /*Q15*/
- hsCom->fftlenShift = 9;
- move16();
- hsCom->fftlenFac = 20480 /*0.625 Q15*/;
- move16();
- BREAK;
- default:
- assert( !"Unsupported FFT length for FD-based CNG" );
- BREAK;
- }
- BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) );
- BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) );
- hsCom->frameSize = shr( hsCom->fftlen, 1 );
-
- return;
-}
-
-/*-------------------------------------------------------------------
- * deleteFdCngDec()
- *
- * Delete the instance of type FD_CNG
- *-------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------
- * ApplyFdCng()
- *
- * Apply the CLDFB-based CNG at the decoder
- *-------------------------------------------------------------------*/
-
-/*-------------------------------------------------------------------
- * FdCng_decodeSID()
- *
- * Decode the FD-CNG bitstream
- *-------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------
- * FdCng_decodeSID_ivas_fx()
- *
- * Decode the FD-CNG bitstream
- *-------------------------------------------------------------------*/
-
-void FdCng_decodeSID_ivas_fx(
- Decoder_State *st /* i/o: decoder state structure */
-)
-{
- Word16 N;
- Word32 *sidNoiseEst;
- Word32 gain;
- Word16 i, index;
- Word32 v[32];
- Word16 indices[32];
- HANDLE_FD_CNG_COM hFdCngCom;
- Word32 *invTrfMatrix_fx;
- Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
- Word16 tmp16;
-
- IF( st->element_mode == EVS_MONO )
- {
- tmp16 = GAIN_Q_OFFSET_EVS_FX_Q0;
- move16();
- }
- ELSE
- {
- tmp16 = GAIN_Q_OFFSET_IVAS_FX_Q0;
- move16();
- }
-
- const Word16 gain_q_offset = tmp16; /* Q0 */
- move16();
-
- invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /*Q31*/
-
- hFdCngCom = ( st->hFdCngDec )->hFdCngCom;
-
- sidNoiseEst = hFdCngCom->sidNoiseEst; /*Q16*/
-
- N = hFdCngCom->npart; /*Q0*/
- move16();
- gain = 0;
- move32();
- hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 );
- move16();
-
- /* Read bitstream */
- FOR( i = 0; i < FD_CNG_stages_37bits; i++ )
- {
- indices[i] = get_next_indice_fx( st, bits_37bits[i] ); /*Q0*/
- move16();
- }
-
- index = get_next_indice_fx( st, 7 );
-
- /* MSVQ decoder */
-
- IF( st->element_mode != EVS_MONO )
- {
- create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC );
- msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7 );
- }
- ELSE
- { /* Legacy EVS_MONO MSVQ tables */
- msvq_dec_fx( cdk_37bits, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL, 7 );
- }
-
-
- /* Decode gain */
- // gain = ((float)index - gain_q_offset) / 1.5f;
- gain = L_mult0( sub( index, gain_q_offset ), 21845 ); // Q15
-
- /* Apply gain and undo log */
- Word16 res_exp[NPART];
- Word16 max_res_exp = 0;
- move16();
- FOR( i = 0; i < N; i++ )
- {
- sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); /*Q31 - res_exp[i]*/
- move32();
- if ( LT_16( max_res_exp, res_exp[i] ) )
- {
- max_res_exp = res_exp[i];
- move16();
- }
- }
-
- FOR( i = 0; i < N; i++ )
- {
- sidNoiseEst[i] = L_shr( sidNoiseEst[i], sub( max_res_exp, res_exp[i] ) ); /*Q31 - max_res_exp*/
- move32();
- }
-
- hFdCngCom->sidNoiseEstExp = max_res_exp;
- move16();
-
- /* NB last band energy compensation */
-
- IF( hFdCngCom->CngBandwidth == NB )
- {
- sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/
- move32();
- }
-
- test();
- IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) )
- {
- sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/
- move32();
- }
-
- scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 );
- hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp;
- move16();
-
- lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac );
-
- return;
-}
-
-/*-------------------------------------------------------------------
- * noisy_speech_detection()
- *
- *
- *-------------------------------------------------------------------*/
-
-/*-------------------------------------------------------------------
- * generate_comfort_noise_dec()
- *
- * Generate the comfort noise based on the target noise level
- *-------------------------------------------------------------------*/
-
-/*-------------------------------------------------------------------
- * generate_masking_noise()
- *
- * Generate additional comfort noise (kind of noise filling)
- *-------------------------------------------------------------------*/
-
-/*-------------------------------------------------------------------
- * generate_masking_noise_ivas_fx()
- *
- * Generate additional comfort noise (kind of noise filling)
- *-------------------------------------------------------------------*/
-
-void generate_masking_noise_ivas_fx(
- Word32 *timeDomainBuffer, /* i/o: time-domain signal Q31 - *exp_out*/
- Word16 *exp_out, /* o : time-domain signal exp */
- HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
- const Word16 length, /* i : frame size Q0*/
- const Word16 core, /* i : core Q0*/
- const Word16 return_noise, /* i : noise is returned instead of added Q0*/
- const Word16 secondary, /* i : flag to indicate secondary noise generation Q0*/
- const Word16 element_mode, /* i : element mode Q0*/
- STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
- const Word16 nchan_out /* i : number of output channels Q0*/
-)
-{
- Word32 *cngNoiseLevel_fx = hFdCngCom->cngNoiseLevel;
- Word32 *ptr_level_fx = cngNoiseLevel_fx;
- Word32 *fftBuffer_fx = hFdCngCom->fftBuffer;
- Word16 i;
- Word32 maskingNoise_fx[L_FRAME16k];
- Word32 *ptr_r_fx;
- Word32 *ptr_i_fx;
- Word16 startBand;
- Word16 *seed = &( hFdCngCom->seed );
- Word32 scale_fx;
- Word16 shift;
- scale_fx = 0x40000000; // 1.0 in Q30
- move32();
- startBand = hFdCngCom->startBand; /*Q0*/
- move16();
- shift = getScaleFactor32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
- if ( LT_16( sub( hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
- {
- shift = sub( hFdCngCom->cngNoiseLevelExp, 4 ); /*Q0*/
- }
- scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); /*hFdCngCom->cngNoiseLevelExp*/
- hFdCngCom->cngNoiseLevelExp = sub( hFdCngCom->cngNoiseLevelExp, shift );
- move16();
-
- /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
- *exp_out = Q15;
- move16();
- IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) )
- {
- IF( NE_16( core, AMR_WB_CORE ) )
- {
- /* Compute additional CN level */
- FOR( i = 0; i < SIZE_SCALE_TABLE_CN; i++ )
- {
- test();
- test();
- if ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) &&
- GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) &&
- LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) )
- {
- BREAK;
- }
- }
-
- scale_fx = L_deposit_h( scaleTable_cn_only[i].scale_ivas ); /* Q30 */
- }
- ELSE
- {
- /* Compute additional CN level */
- FOR( i = 0; i < SIZE_SCALE_TABLE_CN_AMRWB; i++ )
- {
- if ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only_amrwbio[i][0] ) )
- {
- BREAK;
- }
- }
-
- IF( LT_16( i, SIZE_SCALE_TABLE_CN_AMRWB ) )
- {
- scale_fx = L_deposit_h( scaleTable_cn_only_amrwbio[i][1] ); /* Q30 */
- }
- ELSE
- {
- scale_fx = 0;
- move32();
- }
- }
-
- /* Exclude clean speech */
- scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); // Q30
-
- /* Generate Gaussian random noise in real and imaginary parts of the FFT bins
- Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */
- IF( startBand == 0 )
- {
- rand_gauss_fx( &fftBuffer_fx[0], seed, *exp_out ); // Q15
- ptr_r_fx = fftBuffer_fx + 2; /*Q31 - hFdCngCom->fftBuffer_exp*/
- Word16 exp1;
- exp1 = add( hFdCngCom->cngNoiseLevelExp, 1 );
- Word32 mpy1;
- mpy1 = Sqrt32( Mpy_32_32( scale_fx, *ptr_level_fx ), &exp1 ); /*Q31 - exp1*/
- mpy1 = L_shl( mpy1, exp1 ); // Q31
- fftBuffer_fx[0] = Mpy_32_32( fftBuffer_fx[0], mpy1 ); /* DC component in FFT */ // Q = Q15
- ptr_level_fx++;
- }
- ELSE
- {
- fftBuffer_fx[0] = 0;
- move32();
- set32_fx( fftBuffer_fx + 2, 0, shl( sub( startBand, 1 ), 1 ) );
- ptr_r_fx = fftBuffer_fx + shl( startBand, 1 ); /*Q31 - hFdCngCom->fftBuffer_exp*/
- }
- ptr_i_fx = ptr_r_fx + 1;
- FOR( ; ptr_level_fx < cngNoiseLevel_fx + hFdCngCom->stopFFTbin - startBand; ptr_level_fx++ )
- {
- /* Real part in FFT bins */
- rand_gauss_fx( ptr_r_fx, seed, *exp_out ); // Q15
- Word16 exp2;
- exp2 = add( hFdCngCom->cngNoiseLevelExp, 1 );
- Word32 mpy2;
- mpy2 = Sqrt32( L_shr( Mpy_32_32( scale_fx, *ptr_level_fx ), 1 ), &exp2 ); /*Q31 - exp2*/
- ( *ptr_r_fx ) = L_shl( Mpy_32_32( *ptr_r_fx, mpy2 ), exp2 ); // Q = Q15
- move32();
- ptr_r_fx += 2;
-
- /* Imaginary part in FFT bins */
- rand_gauss_fx( ptr_i_fx, seed, *exp_out ); // Q15
- ( *ptr_i_fx ) = L_shl( Mpy_32_32( *ptr_i_fx, mpy2 ), exp2 ); // Q = Q15
- ptr_i_fx += 2;
- }
-
- /* Remaining FFT bins are set to zero */
- set32_fx( fftBuffer_fx + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) );
- /* Nyquist frequency is discarded */
- fftBuffer_fx[1] = 0;
- move32();
- }
- ELSE
- {
- /* very low level case - update random seeds and reset FFT buffer; don't fully skip SynthesisSTFT_flt(), because of the buffer updates done there... */
- generate_masking_noise_update_seed_fx( hFdCngCom );
-
- set32_fx( fftBuffer_fx, 0, hFdCngCom->fftlen );
- }
-
- /* Perform STFT synthesis */
- IF( secondary )
- {
- SynthesisSTFT_fx( fftBuffer_fx, maskingNoise_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out );
- }
- ELSE
- {
- SynthesisSTFT_fx( fftBuffer_fx, maskingNoise_fx, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out );
- }
- *exp_out = sub( *exp_out, Q9 );
- move16();
-
- /* Add some comfort noise on top of decoded signal */
- IF( return_noise )
- {
- Copy32( maskingNoise_fx, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); /*Q31 - *exp_out*/
- }
- ELSE
- {
- v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); /*Q31 - *exp_out*/
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------
- * generate_masking_noise_update_seed()
- *
- * Update seed for scenarios where generate_masking_noise() is
- * not called based on signal statistics
- *-------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------
- * generate_stereo_masking_noise_fx()
- *
- * Generate additional comfort noise (kind of noise filling)
- *-------------------------------------------------------------------*/
-
-void generate_stereo_masking_noise_fx(
- Word16 *syn, /* i/o: time-domain signal Q_syn*/
- Word16 Q_syn,
- Decoder_State *st, /* i/o: decoder state structure */
- STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */
- const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel Q0*/
- const Word16 fadeOut, /* i : only fade out of previous state Q0*/
- STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */
- const Word16 nchan_out /* i : number of output channels Q0*/
-)
-{
- HANDLE_FD_CNG_COM hFdCngCom;
- Word32 gamma_fx, scale_fx /*, SP_ratio_fx needs to be integrated*/;
- Word32 Np_fx[L_FRAME16k];
- Word32 Ns_fx[L_FRAME16k];
- Word32 N1_fx[L_FRAME16k];
- Word32 N2_fx[L_FRAME16k];
- Word16 N1_fx_exp, N2_fx_exp;
- Word16 i;
-
- IF( st->idchan == 0 )
- {
- hFdCngCom = st->hFdCngDec->hFdCngCom;
-#ifdef FIX_ISSUE_1237
- Copy_Scale_sig_16_32_no_sat( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); /*Q6*/
-#else
- Copy_Scale_sig_16_32_DEPREC( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); /*Q6*/
-#endif
- Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, shr( hFdCngCom->frameSize, 1 ) ); /*st->Q_syn*/
-
- set32_fx( &Np_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) );
- set32_fx( &Ns_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) );
-
- IF( !fadeOut )
- {
-#ifdef FIX_ISSUE_1237
- Copy_Scale_sig_16_32_no_sat( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); /*Q15*/
-#else
- Copy_Scale_sig_16_32_DEPREC( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); /*Q15*/
-#endif
- generate_masking_noise_ivas_fx( N1_fx, &N1_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out ); // N1_fx Q6
- /* Generate masking noise for secondary channel */
- IF( flag_sec_CNA )
- {
- generate_masking_noise_ivas_fx( N2_fx, &N2_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out ); // N2_fx Q6
- gamma_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); /*Q30*/
- scale_fx = ONE_IN_Q30;
- move32();
- IF( LT_32( gamma_fx, 966367642 /* 0.9 in Q30 */ ) )
- {
- Word16 exp_gamma;
- exp_gamma = 0;
- move16();
- Word16 divisor1;
- divisor1 = Inv16( (Word16) L_shr( L_sub( ONE_IN_Q30, gamma_fx ), Q15 ), &exp_gamma ); // Q15-exp_gamma
- gamma_fx = L_shl( Mpy_32_16_1( gamma_fx, divisor1 ), exp_gamma ); // Q30
- Word16 exp_gamma1, exp_gamma2, exp_gamma3;
- exp_gamma1 = Q1;
- exp_gamma2 = Q1;
- exp_gamma3 = Q1;
- move16();
- move16();
- move16();
- gamma_fx = Sqrt32( L_add( gamma_fx, ONE_IN_Q30 ), &exp_gamma1 ); /*Q31 - exp_gamma1*/
- Word32 temp;
- temp = Sqrt32( gamma_fx, &exp_gamma2 ); // Q31-exp_gamma1
- gamma_fx = L_sub( gamma_fx, L_shl( temp, sub( exp_gamma2, exp_gamma1 ) ) ); // Q31-exp_gamma1
- gamma_fx = L_shl( gamma_fx, sub( exp_gamma1, Q1 ) ); // Q30
- Word32 divisor2;
- divisor2 = Sqrt32( L_add( ONE_IN_Q30, L_shl( Mpy_32_32( gamma_fx, gamma_fx ), Q1 ) ), &exp_gamma3 ); // Q31 - exp_gamma3
- scale_fx = L_shl( divide3232( ONE_IN_Q30, divisor2 ), add( Q15, exp_gamma3 ) ); // Q30
- }
- ELSE
- {
- gamma_fx = 0;
- move16();
- }
-
- FOR( i = 0; i < 2 * hFdCngCom->frameSize / 4; i++ )
- {
- Np_fx[i] = L_add( Np_fx[i],
- Mpy_32_32( scale_fx, L_shl( L_add( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ) ); // Q6
- move32();
- Word32 add2;
- add2 = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6
- if ( hStereoCng->c_PS_LT_fx < 0 )
- {
- add2 = L_negate( add2 ); /*Q6*/
- }
- Ns_fx[i] = L_add( Ns_fx[i], add2 ); /*Q6*/
- move32();
- }
- FOR( ; i < hFdCngCom->frameSize; i++ )
- {
- Np_fx[i] = Mpy_32_32( scale_fx, L_shl( L_add( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6
- move32();
- Ns_fx[i] = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6
- move32();
- IF( hStereoCng->c_PS_LT_fx < 0 )
- {
- Ns_fx[i] = L_negate( Ns_fx[i] );
- move32();
- }
- }
- /* Below code to be converted */
- Word32 scale_fx_tmp = Mpy_32_32( scale_fx, L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ) ); // Q21
- FOR( i = 0; i < shr( hFdCngCom->frameSize, 1 ); i++ )
- {
- hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp,
- L_add( L_shr( hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )], Q15 ),
- Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ) ) ),
- Q14 ); // Q_olap
- move16();
- hStereoCng->olapBufferSynth22_fx[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp,
- L_sub( L_shr( hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )], Q15 ),
- Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ) ) ),
- Q14 ); // Q_olap
- move16();
- }
- }
- ELSE
- {
- FOR( i = 0; i < shr( hFdCngCom->frameSize, 1 ); i++ )
- {
- Np_fx[i] = L_add( Np_fx[i], N1_fx[i] ); // Q6
- move32();
- }
- Copy32( &N1_fx[( hFdCngCom->frameSize / 2 )], &Np_fx[( hFdCngCom->frameSize / 2 )], shr( hFdCngCom->frameSize, 1 ) ); /*Q6*/
- scale_fx = L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ); // Q21
- FOR( i = 0; i < hFdCngCom->frameSize; i++ )
- {
- hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ), Q6 ); // Q_olap
- move16();
- }
- }
-
- Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, sub( st->Q_syn, 15 ) ); /*st->Q_syn*/
- }
- ELSE
- {
- set16_fx( hFdCngCom->olapBufferSynth2, 0, shr( hFdCngCom->frameSize, 1 ) );
- set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( hFdCngCom->frameSize, 1 ) );
- }
- IF( flag_sec_CNA )
- {
- Copy_Scale_sig_32_16( Ns_fx, hStereoCng->maskingNoiseS_fx, hFdCngCom->frameSize, 0 ); // Q6
- hStereoCng->enableSecCNA = 1;
- move16();
- }
- ELSE
- {
- set16_fx( hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize );
- }
-
- /* add masking noise */
- FOR( i = 0; i < hFdCngCom->frameSize; i++ )
- {
- syn[i] = add( syn[i], (Word16) L_shr( Np_fx[i], sub( Q16 + Q6, Q_syn ) ) ); // Q_syn
- move16();
- }
- }
- ELSE IF( hStereoCng->enableSecCNA )
- {
- Word16 SP_ratio_fx;
- SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis Q15*/
- Word16 prevSP_ratio_fx;
- prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis Q15*/
- move16();
- /* scale and add masking noise */
- FOR( i = 0; i < shr( *hStereoCng->frameSize, 2 ); i++ )
- {
- Word16 s;
- Word16 scale_fx_tmp;
- scale_fx_tmp = BASOP_Util_Divide3216_Scale( L_add( L_mult0( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), L_mult0( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ), &s ); // Q15
- scale_fx_tmp = shl( scale_fx_tmp, s );
- syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/
- move16();
- }
- FOR( ; i < *hStereoCng->frameSize / 2; i++ )
- {
- syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/
- move16();
- }
- FOR( ; i < *hStereoCng->frameSize; i++ )
- {
- syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/
- move16();
- }
- hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /*Q15*/
- move16();
- }
-
- return;
-}
-void generate_masking_noise_lb_dirac_fx(
- HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
- Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA Q11*/
- const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered Q0*/
- const Word16 cna_flag /* i : CNA flag for LB and HB Q0*/
-)
-{
- Word16 i;
- Word32 *cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*hFdCngCom->cngNoiseLevelExp*/
- Word32 *fftBuffer = hFdCngCom->fftBuffer; /*hFdCngCom->fftBuffer_exp*/
- Word32 *ptr_r;
- Word32 *ptr_i;
- Word32 *ptr_level;
- Word16 *seed = &( hFdCngCom->seed );
- Word32 scale;
- Word16 n_samples_out, n_samples_start, n_samples_out_loop;
-
- push_wmops( "fd_cng_dirac" );
-
- /* Init */
- scale = 0;
- move32();
- n_samples_out = i_mult( shr( hFdCngCom->frameSize, 4 ), nCldfbTs );
- n_samples_start = 0;
- move16();
- Word16 exp_out = Q11;
- move16();
- /*LB CLDFB - CNA from STFT*/
- IF( cna_flag )
- {
- /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
- IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) )
- {
- /* Compute additional CN level */
- FOR( i = 0; i < 15; i++ )
- {
- test();
- test();
- if ( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode ) ) &&
- GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) &&
- LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) )
- {
- BREAK;
- }
- }
-
- scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */
- scale = Mpy_32_16_1( scale, hFdCngCom->likelihood_noisy_speech ); /* Q30 */
- }
- }
-
- /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/
- test();
- IF( cna_flag && tdBuffer != NULL )
- {
- WHILE( n_samples_out > 0 )
- {
- n_samples_out_loop = s_min( hFdCngCom->frameSize, n_samples_out );
- IF( scale != 0 )
- {
- /*Generate LF comfort noise only at first slot, for the whole frame*/
- ptr_level = cngNoiseLevel; /*hFdCngCom->cngNoiseLevelExp*/
-
- /* Generate Gaussian random noise in real and imaginary parts of the FFT bins
- Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */
- IF( EQ_16( hFdCngCom->startBand, 0 ) )
- {
- rand_gauss_fx( &fftBuffer[0], seed, exp_out );
- ptr_r = fftBuffer + 2; /*hFdCngCom->fftBuffer_exp*/
-
- Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp );
- Word32 sqr = Sqrt32( L_shr( Mpy_32_32( scale, *ptr_level ), 1 ), &exp2 ); /* DC component in FFT Q31 - exp2*/
- sqr = L_shl( sqr, exp2 ); /*Q31*/
- fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqr ); /* DC component in FFT Q31 - hFdCngCom->fftBuffer_exp*/
- move32();
- ptr_level++;
- }
- ELSE
- {
- fftBuffer[0] = 0;
- move32();
- set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) );
- ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); /*hFdCngCom->fftBuffer_exp*/
- }
- ptr_i = ptr_r + 1; /*hFdCngCom->fftBuffer_exp*/
-
- FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ )
- {
- rand_gauss_fx( ptr_r, seed, exp_out );
- Word16 exp2 = hFdCngCom->cngNoiseLevelExp;
- Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); /*Q31 - exp2*/
- ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); /*Q31 - hFdCngCom->fftBuffer_exp*/
- move32();
- ptr_r += 2;
-
- /* Imaginary part in FFT bins */
- rand_gauss_fx( ptr_i, seed, exp_out );
- ( *ptr_i ) = L_shl( Mpy_32_32( *ptr_i, mpy2 ), exp2 ); /*Q31 - hFdCngCom->fftBuffer_exp*/
- move32();
- ptr_i += 2;
- }
- /* Remaining FFT bins are set to zero */
- set32_fx( fftBuffer + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) );
- /* Nyquist frequency is discarded */
- fftBuffer[1] = 0;
- move32();
-
- /* Perform STFT synthesis */
- SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom );
- scale_sig32( tdBuffer + n_samples_start, n_samples_out_loop, Q9 ); // Q2 -> Q11
- }
-
- ELSE
- {
- /* very low level case - update random seeds */
- generate_masking_noise_update_seed_fx( hFdCngCom );
-
- set32_fx( fftBuffer, 0, hFdCngCom->fftlen );
- /* Perform STFT synthesis */
- SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom );
- }
- hFdCngCom->fftBuffer_exp = 31 - 11;
- move16();
- n_samples_out = sub( n_samples_out, hFdCngCom->frameSize );
- n_samples_start = add( n_samples_start, hFdCngCom->frameSize );
- }
- }
-
- pop_wmops();
-
- return;
-}
-void generate_masking_noise_dirac_ivas_fx(
- HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
- HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */
- Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA q_input*/
- Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer q_cldfb*/
- Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer q_cldfb*/
- const Word16 slot_index, /* i : CLDFB slot index Q0*/
- const Word16 cna_flag, /* i : CNA flag for LB and HB Q0*/
- const Word16 fd_cng_flag, /* i : FD-CNG flag for HB Q0*/
- Word16 q_input,
- Word16 *q_cldfb )
-{
- Word16 i;
- Word32 *ptr_level_fx;
- Word16 *seed = &( hFdCngCom->seed );
- Word32 scale_fx;
- Word16 q_scale, q_shift, q_ptr_level;
-
- push_wmops( "fd_cng_dirac" );
-
- /* Init */
- scale_fx = 0;
- move32();
-
- /* Resample CLDFB memories if necessary*/
- IF( NE_16( i_mult( h_cldfb->no_channels, h_cldfb->no_col ), hFdCngCom->frameSize ) )
- {
- resampleCldfb_ivas_fx( h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC );
- }
-
- set32_fx( Cldfb_RealBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX );
- set32_fx( Cldfb_ImagBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX );
-
- /*LB CLDFB - CNA from STFT*/
- IF( cna_flag != 0 )
- {
- /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
- IF( hFdCngCom->likelihood_noisy_speech > 0 )
- {
- /* Compute additional CN level */
- FOR( i = 0; i < 15; i++ )
- {
- test();
- test();
- if ( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode ) ) &&
- ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) ) &&
- ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) ) )
- {
- BREAK;
- }
- }
-
- scale_fx = L_shr( L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ), Q3 ); /* Q27 */
- scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech );
- }
- }
- /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/
- IF( cna_flag && tdBuffer_fx != NULL )
- {
- *q_cldfb = q_input;
- move16();
- IF( scale_fx != 0 )
- {
- /* LF CLDFB*/
- cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[( hFdCngCom->numCoreBands * slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb );
- }
- ELSE
- {
- /* LB ana CLDFB*/
- cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[( hFdCngCom->numCoreBands * slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb );
- }
- }
-
- /*HF CLDFB - CNA and/or FD-CNG*/
- if ( fd_cng_flag )
- {
- scale_fx = L_add( scale_fx, ONE_IN_Q27 ); // 1 in Q27
- }
- IF( scale_fx != 0 )
- {
- q_scale = 27;
- move16();
- q_shift = norm_l( scale_fx );
- scale_fx = L_shl( scale_fx, q_shift ); /*q_scale+q_shift*/
- q_scale = add( q_scale, q_shift );
- scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2 * Q8 - 34
- q_scale = sub( add( q_scale, 2 * Q8 ), 31 );
- ptr_level_fx = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/
- q_ptr_level = sub( 31, hFdCngCom->cngNoiseLevelExp );
-
- FOR( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ )
- {
- Word32 num;
- Word16 exp, q_num;
- q_shift = norm_l( scale_fx );
- scale_fx = L_shl( scale_fx, q_shift ); /*q_scale+q_shift*/
- q_scale = add( q_scale, q_shift );
- num = Mpy_32_32( scale_fx, *ptr_level_fx ); /*q_num*/
- q_num = sub( add( q_scale, q_ptr_level ), 31 );
- exp = sub( 31, q_num );
- num = Sqrt32( num, &exp ); /*Q31 - exp*/
- /* Real part in CLDFB band */
- rand_gauss_fx( &Cldfb_RealBuffer_fx[i], seed, *q_cldfb );
- Cldfb_RealBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_RealBuffer_fx[i], num ), exp );
- move32();
- /* Imaginary part in CLDFB band */
- rand_gauss_fx( &Cldfb_ImagBuffer_fx[i], seed, *q_cldfb );
- Cldfb_ImagBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_ImagBuffer_fx[i], num ), exp );
- move32();
-
- ptr_level_fx++;
- }
- }
-
- pop_wmops();
-
- return;
-}
-
-
-/*-------------------------------------------------------------------
- * FdCngDecodeMDCTStereoSID()
- *
- * Decode FD-Cng parameters for CNG in MDCT-Stereo mode from the bitstream
- *
- *-------------------------------------------------------------------*/
-
-void FdCngDecodeMDCTStereoSID_fx(
- CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
-)
-{
- DEC_CORE_HANDLE sts[CPE_CHANNELS];
- HANDLE_FD_CNG_COM hFdCngCom;
- Word32 *ms_ptr_fx[CPE_CHANNELS];
- Word32 *lr_ptr_fx[CPE_CHANNELS];
- Word32 logNoiseEst_fx[CPE_CHANNELS][NPART];
- Word32 gain_fx[CPE_CHANNELS];
- Word16 indices[FD_CNG_stages_37bits];
- Word16 N, i, ch, p, stages;
- Word16 is_out_ms;
- Word32 *invTrfMatrix_fx;
- Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
- Word16 shift, exp_diff, max_exp_idx;
- Word16 exp_arr[NPART];
- Word32 tmp32, tmp32_arr[NPART];
-
- invTrfMatrix_fx = (Word32 *) tmpRAM_fx;
- create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC ); // Q31
-
- is_out_ms = 0;
- move16();
- if ( hCPE->hCoreCoder[0]->cng_sba_flag )
- {
- is_out_ms = 1;
- move16();
- }
-
- N = 0; /* to avoid compilation warning */
- move16();
-
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- sts[ch] = hCPE->hCoreCoder[ch];
- ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; /*Q20*/
- lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; /*Q18*/
- }
-
- /* decode noise shapes and gains */
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- sts[ch] = hCPE->hCoreCoder[ch];
- hFdCngCom = ( sts[ch]->hFdCngDec )->hFdCngCom;
- N = hFdCngCom->npart;
- move16();
- hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 ); /*Q0*/
- move16();
-
- IF( ch )
- {
- stages = FD_CNG_JOINT_stages_25bits;
- move16();
- }
- ELSE
- {
- stages = FD_CNG_stages_37bits;
- move16();
- }
-
- /* read bitstream */
- FOR( i = 0; i < stages; i++ )
- {
- indices[i] = get_next_indice_fx( sts[ch], bits_37bits[i] ); /*Q0*/
- move16();
- }
- {
- gain_fx[ch] = Mpy_32_32( L_shl( L_sub( get_next_indice_fx( sts[ch], 7 ), GAIN_Q_OFFSET_IVAS_FX ), Q20 ), TWO_BY_THREE_Q31 /* 2/3 in Q31 */ ); // Q20
- move32();
- }
-
- /* MSVQ decoder */
- shift = find_guarded_bits_fx( N );
- msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, ms_ptr_fx[ch], NULL, 7 ); // Q20 - shift
-
- Scale_sig32( ms_ptr_fx[ch], N, shift ); // Q20
- }
-
- dtx_read_padding_bits_fx( sts[1], mult( sub( IVAS_SID_5k2, 4400 ), ONE_BY_FRAMES_PER_SEC_Q15 ) );
-
- IF( sts[0]->hFdCngDec->hFdCngCom->no_side_flag )
- {
- set32_fx( ms_ptr_fx[1], 0, NPART );
- }
-
- IF( EQ_16( is_out_ms, 0 ) )
- {
- inverseMS_fx( N, ms_ptr_fx[0], ms_ptr_fx[1], ONE_IN_Q31 );
- }
-
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- max_exp_idx = 0;
- move16();
- hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom;
- FOR( p = 0; p < N; p++ )
- {
- tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20
- tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); /*Q31 - exp_arr[p]*/
- move32();
- if ( LT_16( exp_arr[max_exp_idx], exp_arr[p] ) )
- {
- max_exp_idx = p; /*Q0*/
- move16();
- }
- }
-
- // Bringing in same exponent
- FOR( p = 0; p < N; p++ )
- {
- lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); /*Q31 - exp_arr[max_exp_idx]*/
- move32();
- }
-
- hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx];
- move16();
-
- scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 );
-
- hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp;
- move16();
-
- lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
- }
-
- test();
- IF( EQ_16( hCPE->nchan_out, 1 ) && LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) )
- {
- /* create proper M noise shape in channel zero after gains have been applied */
- exp_diff = sub( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp );
- move16();
- FOR( p = 0; p < N; p++ )
- {
- IF( GT_16( exp_diff, 0 ) )
- {
- sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); /*Q18*/
- move32();
- }
- ELSE
- {
- sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); /*Q18*/
- move32();
- }
- }
- IF( LT_16( exp_diff, 0 ) )
- {
- sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp = add( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, negate( exp_diff ) );
- move16();
- }
- }
-
- return;
-}
-
-
-/*-------------------------------------------------------------------
- * FdCngDecodeDiracMDCTStereoSID_fx()
- *
- * Decode FD-CNG parameters for CNG in 2TC DirAC mode from the bitstream
- *-------------------------------------------------------------------*/
-
-void FdCngDecodeDiracMDCTStereoSID_fx(
- CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
-)
-{
- DEC_CORE_HANDLE sts[CPE_CHANNELS];
- HANDLE_FD_CNG_COM hFdCngCom;
- Word32 *ms_ptr_fx[CPE_CHANNELS];
- Word32 *lr_ptr_fx[CPE_CHANNELS];
- Word32 logNoiseEst_fx[CPE_CHANNELS][NPART];
- Word32 gain_fx[CPE_CHANNELS];
- Word16 indices[FD_CNG_stages_37bits];
- Word16 N, i, ch, p;
- Word32 *invTrfMatrix_fx;
- Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
- Word16 shift, exp_diff, max_exp_idx;
- Word16 exp_arr[NPART];
- Word32 tmp32, tmp32_arr[NPART];
-
- invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /* dynamically filled */
- create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC ); // Q31
-
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- sts[ch] = hCPE->hCoreCoder[ch];
- ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; /*Q20*/
- lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; /*Q20*/
- ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++; /*Q18*/
- }
-
- /* decode noise shapes and gains */
- hFdCngCom = ( sts[0]->hFdCngDec )->hFdCngCom;
- N = hFdCngCom->npart; /*Q0*/
- move16();
-
- /* read bitstream */
- FOR( i = 0; i < FD_CNG_stages_37bits; i++ )
- {
- indices[i] = get_next_indice_fx( sts[0], bits_37bits[i] ); /*Q0*/
- move16();
- }
- gain_fx[0] = Mpy_32_32( L_shl( L_sub( get_next_indice_fx( sts[0], 7 ), GAIN_Q_OFFSET_IVAS_FX ), Q20 ), TWO_BY_THREE_Q31 /* 2/3 in Q31 */ ); // Q20
- move32();
-
- gain_fx[1] = gain_fx[0]; /*Q20*/
- move32();
-
- /* MSVQ decoder */
- shift = find_guarded_bits_fx( N );
- msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, ms_ptr_fx[0], NULL, 7 ); // Q20 - shift
-
- Scale_sig32( ms_ptr_fx[0], N, shift ); // Q20
-
- Copy32( ms_ptr_fx[0], ms_ptr_fx[1], N ); /*Q20*/
-
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- max_exp_idx = 0;
- move16();
- hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom;
-
- FOR( p = 0; p < N; p++ )
- {
- tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20
- tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); /*Q31 - exp_arr[p]*/
- move32();
- if ( LT_16( exp_arr[max_exp_idx], exp_arr[p] ) )
- {
- max_exp_idx = p; /*Q0*/
- move16();
- }
- }
-
- // Bringing in same exponent
- FOR( p = 0; p < N; p++ )
- {
- lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); /*Q20*/
- move32();
- }
-
- hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx]; /*Q0*/
- move16();
-
- /* NB last band energy compensation */
- test();
- IF( hFdCngCom->CngBandwidth == NB )
- {
- lr_ptr_fx[ch][( N - 1 )] = Mpy_32_32( lr_ptr_fx[ch][( N - 1 )], NB_LAST_BAND_SCALE_Q31 ); /*Q20*/
- move32();
- }
- ELSE IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) )
- {
- lr_ptr_fx[ch][( N - 1 )] = Mpy_32_32( lr_ptr_fx[ch][( N - 1 )], SWB_13k2_LAST_BAND_SCALE_Q31 ); /*Q20*/
- move32();
- }
-
- scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 );
-
- hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp;
- move16();
-
- lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
- }
- sts[0]->hFdCngDec->hFdCngCom->coherence_fx = 0;
- move16();
- sts[1]->hFdCngDec->hFdCngCom->coherence_fx = 0;
- move16();
-
- IF( EQ_16( hCPE->nchan_out, 1 ) )
- {
- /* create proper M noise shape in channel zero after gains have been applied */
- exp_diff = sub( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp );
- FOR( p = 0; p < N; p++ )
- {
- IF( exp_diff > 0 )
- {
- sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); /*Q18*/
- move32();
- }
- ELSE
- {
- sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); /*Q18*/
- move32();
- }
- }
- IF( exp_diff < 0 )
- {
- sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp = add( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, negate( exp_diff ) );
- move16();
- }
- }
-
- return;
-}
diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c
index fa7e602a54da5179a26696905633c5077bfef264..c509d5d1028b46af70fc21b31ddc1953b2e8fd10 100644
--- a/lib_dec/fd_cng_dec_fx.c
+++ b/lib_dec/fd_cng_dec_fx.c
@@ -20,10 +20,18 @@
#endif
-#define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */
-#define ST_PERIODOG_FACT_Q15 29491 /* 0.9 in Q15, short-term filter factor for periodogram */
-#define CNA_ACT_DN_FACT_Q15 22938 /* 0.7 in Q15, downward updating factor for CNA during active frames */
-#define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */
+#define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */
+#define ST_PERIODOG_FACT_Q15 29491 /* 0.9 in Q15, short-term filter factor for periodogram */
+#define CNA_ACT_DN_FACT_Q15 22938 /* 0.7 in Q15, downward updating factor for CNA during active frames */
+#define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */
+#define DELTA_MASKING_NOISE_Q15 0
+#define LOG_10_BASE_2 1783446566 /* Q29 */
+#define GAIN_Q_OFFSET_IVAS_FX 45
+#define LOG_10_BASE_2_BY_10_Q31 713378606
+#define TWO_BY_THREE_Q31 1431655765
+#define ONE_BY_FRAMES_PER_SEC_Q15 656
+#define NB_LAST_BAND_SCALE_Q31 1717986918
+#define SWB_13k2_LAST_BAND_SCALE_Q31 1717986918
/********************************
* External tables *
@@ -271,30 +279,6 @@ void initFdCngDec_fx(
hFdCngDec->smoothed_psd_exp = 0;
move16();
-#ifdef IVAS_CODE_CNG
- set_f( hFdCngDec->hFdCngCom->sidNoiseEstLp, 0.0f, NPART );
-
- set_f( hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k );
- set_f( hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING );
-
- hFdCngDec->ms_last_inactive_bwidth = NB;
- hFdCngDec->ms_cnt_bw_up = 0;
-
- hFdCngDec->cna_LR_LT = 0.5f;
- hFdCngDec->cna_ILD_LT = 0.0f;
- hFdCngDec->first_cna_noise_updated = 0;
- hFdCngDec->first_cna_noise_update_cnt = 0;
- hFdCngDec->cna_nbands = 6;
- mvs2s( cna_init_bands, hFdCngDec->cna_band_limits, MAX_CNA_NBANDS + 1 );
- hFdCngDec->cna_act_fact = 1.0f;
- hFdCngDec->cna_rescale_fact = 0.0f;
- hFdCngDec->cna_seed = 5687;
- set_zero( hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX );
- set_zero( hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX );
-
- st->CNG_mode = -1;
- mvr2r( st->lsp_old, st->lspCNG, M );
-#endif
return;
}
/*
@@ -1024,12 +1008,6 @@ Word16 ApplyFdCng_fx(
hFdCngCom->psize_inv,
hFdCngDec->partNoiseShape,
&hFdCngDec->partNoiseShape_exp );
-#ifdef IVAS_CODE_CNG
- IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
- {
- Copy( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART );
- }
-#endif
}
IF( EQ_16( st->m_frame_type, SID_FRAME ) )
@@ -1046,11 +1024,8 @@ Word16 ApplyFdCng_fx(
{
if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
{
-#ifdef IVAS_CODE_CNG
- sidNoiseEst = hFdCngCom->sidNoiseEstLp;
- move16();
-#endif
}
+
/* Interpolate the CLDFB band levels from the SID (partition) levels */
IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) )
{
@@ -1128,24 +1103,7 @@ Word16 ApplyFdCng_fx(
move16();
}
}
-#ifdef IVAS_CODE_CNG
- else if ( st->element_mode == IVAS_CPE_DFT )
- {
- if ( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) )
- {
- sidNoiseEst = hFdCngCom->sidNoiseEstLp;
- j = 0;
- for ( k = 0; k < hFdCngCom->nFFTpart; k++ )
- {
- factor = ( sidNoiseEst[k] + DELTA ) / ( hFdCngDec->partNoiseShape[k] + DELTA );
- for ( ; j <= hFdCngCom->part[k]; j++ )
- {
- cngNoiseLevel[j] = hFdCngDec->bandNoiseShape[j] * factor;
- }
- }
- }
- }
-#endif
+
IF( EQ_16( st->codec_mode, MODE2 ) )
{
/* Generate comfort noise during SID or zero frames */
@@ -1858,15 +1816,6 @@ void perform_noise_estimation_dec_fx(
float *power_spectrum,
#endif
HANDLE_FD_CNG_DEC hFdCngDec /* i/o: FD_CNG structure containing all buffers and variables */
-#ifdef IVAS_CODE_CNG
- ,
- const int16_t element_mode, /* i : element mode */
- const int16_t bwidth, /* i : audio bandwidth */
- const int16_t L_frame, /* i : frame length at internal Fs */
- const int16_t last_L_frame, /* i : frame length of the last frame at internal Fs */
- const int32_t last_core_brate, /* i : previous frame core bitrate */
- const int16_t VAD /* i : VAD flag in the decoder */
-#endif
)
{
Word16 i, tmp_r, tmp_i, fac, fftBuffer_exp;
@@ -1875,10 +1824,6 @@ void perform_noise_estimation_dec_fx(
Word16 *part, *psize_inv, *psize_norm;
Word32 tmp, *fftBuffer, *periodog, *ptr_per, *ptr_r, *ptr_i;
-#ifdef IVAS_CODE_CNG
- PMT( "lots of code related to IVAS needs to be done " )
-#endif
-
/* pointer initialization */
periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/
@@ -1911,238 +1856,7 @@ void perform_noise_estimation_dec_fx(
AnalysisSTFT( timeDomainInput, Q, fftBuffer, &fftBuffer_exp, hFdCngDec->hFdCngCom );
#endif
fftBuffer_exp = add( fftBuffer_exp, WORD16_BITS - 1 );
-#ifdef IVAS_CODE_CNG
- if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT )
- {
- /* Calculate periodogram (squared magnitude in each FFT bin) */
- if ( startBand == 0 )
- {
- ( *ptr_per ) = fftBuffer[0] * fftBuffer[0];
- ptr_per++;
- ptr_r = fftBuffer + 2;
- }
- else
- {
- ptr_r = fftBuffer + 2 * startBand;
- }
-
- ptr_i = ptr_r + 1;
-
- for ( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ )
- {
- ( *ptr_per ) = ( *ptr_r ) * ( *ptr_r ) + ( *ptr_i ) * ( *ptr_i );
- ptr_r += 2;
- ptr_i += 2;
- }
-
- /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/
- v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand );
-
- /* Combine bins of power spectrum into partitions */
- i = 0;
- for ( p = 0; p < npart; p++ )
- {
-
- /* calculate mean over all bins in power partition */
- temp = 0;
- for ( ; i <= part[p]; i++ )
- {
- temp += periodog[i];
- }
- msPeriodog[p] = temp * psize_inv[p];
- }
-
- /* compensate for the loss of variance - don't do when first noise update is not completed yet due to risk of msPeriodog[p] < 0 */
- if ( hFdCngDec->first_cna_noise_updated )
- {
- i = 0;
- for ( p = 0; p < npart; p++ )
- {
- /* calculate variance over all bins in power partition */
- temp = 0;
- for ( ; i <= part[p]; i++ )
- {
- delta = periodog[i] - msPeriodog[p];
- temp += delta * delta;
- }
- temp *= psize_inv[p];
-
- /* compensate for the loss of variance */
- msPeriodog[p] = (float) ( msPeriodog[p] + sqrt( temp ) * rand_gauss( &ftemp, &hFdCngDec->cna_seed ) );
-
- if ( msPeriodog[p] < 1e-5f )
- {
- msPeriodog[p] = 1e-5f;
- }
- }
- }
-
- /* calculate total energy (short-term and long-term) */
- enr_tot = sum_f( msPeriodog, npart ) + EPSILON;
- enr_tot0 = sum_f( msNoiseEst, npart ) + EPSILON;
-
- /* update short-term periodogram on larger partitions */
- for ( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ )
- {
- if ( L_frame != last_L_frame || last_core_brate <= SID_2k40 )
- {
- /* core Fs has changed or last frame was SID/NO_DATA -> re-initialize short-term periodogram */
- hFdCngDec->msPeriodog_ST[p] = msPeriodog[p];
- }
- else
- {
- hFdCngDec->msPeriodog_ST[p] = (float) ( ST_PERIODOG_FACT * hFdCngDec->msPeriodog_ST[p] + ( 1 - ST_PERIODOG_FACT ) * msPeriodog[p] );
- }
- }
-
- /* core Fs has changed -> partitions have changed -> re-calculate long-term periodogram */
- /* part L_FRAME16k L_FRAME */
- /* ... */
- /* [55] 146 146 */
- /* [56] 174 160 */
- /* [57] 210 174 */
- /* [58] 254 190 */
- /* [59] 306 210 */
- /* [60] 317 230 */
- /* [61] 253 */
-
- if ( last_L_frame == L_FRAME16k && L_frame == L_FRAME )
- {
- msNoiseEst[61] = msNoiseEst[58];
- msNoiseEst[60] = min( msNoiseEst[58], msNoiseEst[57] );
- msNoiseEst[59] = msNoiseEst[57];
- msNoiseEst[58] = msNoiseEst[56];
- msNoiseEst[57] = msNoiseEst[56];
- msNoiseEst[56] = min( msNoiseEst[56], msNoiseEst[55] );
- }
- else if ( last_L_frame == L_FRAME && L_frame == L_FRAME16k )
- {
- msNoiseEst[56] = min( msNoiseEst[56], msNoiseEst[57] );
- msNoiseEst[57] = min( msNoiseEst[58], msNoiseEst[59] );
- msNoiseEst[58] = min( msNoiseEst[60], msNoiseEst[61] );
- msNoiseEst[59] = 0.0f;
- msNoiseEst[60] = 0.0f;
- msNoiseEst[61] = 0.0f;
-
- hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES;
- }
-
- /* Smooth with IIR filter */
- if ( !hFdCngDec->first_cna_noise_updated )
- {
- if ( !VAD )
- {
- /* background noise update with moving average */
- alpha = 1.0f / ( hFdCngDec->first_cna_noise_update_cnt + 1 );
- for ( p = 0; p < npart; p++ )
- {
- msNoiseEst[p] = ( 1 - alpha ) * msNoiseEst[p] + alpha * msPeriodog[p];
- }
-
- /* check, if we reached the required number of first CNA noise update frames */
- if ( hFdCngDec->first_cna_noise_update_cnt < FIRST_CNA_NOISE_UPD_FRAMES - 1 )
- {
- hFdCngDec->first_cna_noise_update_cnt++;
- }
- else
- {
- hFdCngDec->first_cna_noise_updated = 1;
- if ( hFdCngDec->hFdCngCom->msFrCnt_init_counter == 0 )
- {
- hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1;
- }
- }
- }
- else
- {
- hFdCngDec->first_cna_noise_update_cnt = 0;
- }
- }
- else
- {
- hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1;
- if ( VAD )
- {
- /* no updates during active frames except for significant energy drops */
- enr_ratio = enr_tot / enr_tot0;
- if ( enr_ratio < 0.5f )
- {
- /* total energy significantly decreases during active frames -> downward update */
- wght = lin_interp( enr_ratio, 0.0f, 0.8f, 0.5f, 0.95f, 1 );
- for ( p = 0; p < npart; p++ )
- {
- if ( msPeriodog[p] < msNoiseEst[p] )
- {
- msNoiseEst[p] = wght * msNoiseEst[p] + ( 1 - wght ) * msPeriodog[p];
- }
- }
- }
- else
- {
- /* energy significantly decreases in one of the larger partitions during active frames -> downward update */
- for ( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ )
- {
- if ( hFdCngDec->msPeriodog_ST[p] < msNoiseEst[p] )
- {
- msNoiseEst[p] = (float) ( CNA_ACT_DN_FACT * msNoiseEst[p] + ( 1 - CNA_ACT_DN_FACT ) * hFdCngDec->msPeriodog_ST[p] );
- }
- }
- }
- }
- else
- {
-
- if ( bwidth >= WB && hFdCngDec->ms_last_inactive_bwidth == NB )
- {
- /* bandwidth increased -> set counter for fast initilization */
- hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES;
- }
- hFdCngDec->ms_last_inactive_bwidth = bwidth;
- /* update background noise during inactive frames */
- ptr_per = msNoiseEst;
- for ( p = 0; p < npart; p++ )
- {
- enr = msPeriodog[p];
- alpha = 0.95f;
- /* bandwidth increased -> do fast re-initilization */
- if ( hFdCngDec->ms_cnt_bw_up > 0 && p > 55 )
- {
- alpha = 1.0f / ( hFdCngDec->ms_cnt_bw_up + 1 );
- }
- else if ( enr < *ptr_per && part[p] == 1 )
- {
- /* faster downward update for single-bin partitions */
- alpha = 0.8f;
- }
- else if ( enr > 2.0f * ( *ptr_per ) )
- {
- /* prevent abrupt upward updates */
- enr = 2.0f * ( *ptr_per );
- }
-
- /* IIR smoothing */
- *ptr_per *= alpha;
- *ptr_per += ( 1 - alpha ) * enr;
- ptr_per++;
- }
-
- if ( hFdCngDec->ms_cnt_bw_up > 0 )
- {
- hFdCngDec->ms_cnt_bw_up--;
- }
- }
- }
-
- mvr2r( msNoiseEst, hFdCngDec->msPsd, npart );
-
- /* Expand partitions into bins of power spectrum */
- scalebands( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, stopFFTbin - startBand, hFdCngDec->bandNoiseShape, 1 );
- mvr2r( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd[startBand], stopFFTbin - startBand );
- set_zero( &hFdCngDec->smoothed_psd[stopFFTbin], L_FRAME16k - stopFFTbin );
- }
- else
-#endif
{
#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT
if ( element_mode == IVAS_CPE_MDCT && power_spectrum != NULL )
@@ -2294,12 +2008,7 @@ void perform_noise_estimation_dec_fx(
hFdCngDec->msNewMinFlag,
hFdCngDec->msPeriodogBuf,
&( hFdCngDec->msPeriodogBufPtr ),
- hFdCngDec->hFdCngCom
-#ifdef IVAS_CODE_CNG
- ,
- DEC, element_mode
-#endif
- );
+ hFdCngDec->hFdCngCom );
/* Expand MS outputs */
expand_range( hFdCngDec->msLogNoiseEst, hFdCngDec->msNoiseEst, &hFdCngDec->msNoiseEst_exp, npart );
@@ -2339,10 +2048,6 @@ void perform_noise_estimation_dec_ivas_fx(
Word16 q_shift;
Word32 max_l;
Word16 norm_shift;
-#ifdef IVAS_CODE_CNG
- PMT( "lots of code related to IVAS needs to be done " )
-#endif
-
/* pointer initialization */
periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/
@@ -3621,9 +3326,9 @@ void generate_comfort_noise_dec_fx(
IF( st->hTcxCfg->last_aldo != 0 )
{
- FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ )
+ FOR( i = 0; i < hFdCngCom->frameSize - NS2SA( st->sr_core, N_ZERO_MDCT_NS ); i++ )
{
- timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/
+ timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/
move16();
}
}
@@ -4160,9 +3865,9 @@ void generate_comfort_noise_dec_ivas_fx(
IF( st->hTcxCfg->last_aldo != 0 )
{
- FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ )
+ FOR( i = 0; i < hFdCngCom->frameSize - NS2SA( st->sr_core, N_ZERO_MDCT_NS ); i++ )
{
- timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/
+ timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/
move16();
}
}
@@ -5025,318 +4730,969 @@ void generate_masking_noise_mdct_ivas_fx(
return;
}
-#ifdef IVAS_CODE_CNG
/*-------------------------------------------------------------------
- * generate_stereo_masking_noise()
+ * initFdCngDec()
*
- * Generate additional comfort noise (kind of noise filling)
+ * Initialize an instance of type FD_CNG
*-------------------------------------------------------------------*/
-
-void generate_stereo_masking_noise(
- float *syn, /* i/o: time-domain signal */
- Decoder_State *st, /* i/o: decoder state structure */
- STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */
- const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
- const int16_t fadeOut, /* i : only fade out of previous state */
- STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */
- const int16_t nchan_out /* i : number of output channels */
-)
+void configureFdCngDec_ivas_fx(
+ HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */
+ const Word16 bwidth, /*Q0*/
+ const Word32 total_brate, /*Q0*/
+ const Word16 L_frame, /*Q0*/
+ const Word16 last_L_frame, /*Q0*/
+ const Word16 element_mode /*Q0*/ )
{
- HANDLE_FD_CNG_COM hFdCngCom;
- float gamma, scale, SP_ratio;
- float Np[L_FRAME16k];
- float Ns[L_FRAME16k];
- float N1[L_FRAME16k];
- float N2[L_FRAME16k];
- int16_t i;
-
- if ( st->idchan == 0 )
- {
- hFdCngCom = st->hFdCngDec->hFdCngCom;
- mvr2r( hFdCngCom->olapBufferSynth2, Np, hFdCngCom->frameSize / 2 );
- mvr2r( hStereoCng->olapBufferSynth22, Ns, hFdCngCom->frameSize / 2 );
- set_f( &Np[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2 );
- set_f( &Ns[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2 );
-
- if ( !fadeOut )
- {
- generate_masking_noise_fx( N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out );
- /* Generate masking noise for secondary channel */
- if ( flag_sec_CNA )
- {
- generate_masking_noise_fx( N2, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out );
- gamma = hStereoCng->c_PS_LT * hStereoCng->c_PS_LT;
- scale = 1.0f;
- if ( gamma < 0.9f )
- {
- gamma = gamma / ( 1 - gamma );
- gamma = (float) sqrt( gamma + 1 ) - (float) sqrt( gamma );
- scale = 1.0f / (float) sqrt( 1 + gamma * gamma );
- }
- else
- {
- gamma = 0.0f;
- }
-
- for ( i = 0; i < 2 * hFdCngCom->frameSize / 4; i++ )
- {
- Np[i] += scale * ( N1[i] + gamma * N2[i] );
- Ns[i] += scale * sign( hStereoCng->c_PS_LT ) * ( N1[i] - gamma * N2[i] );
- }
- for ( ; i < hFdCngCom->frameSize; i++ )
- {
- Np[i] = scale * ( N1[i] + gamma * N2[i] );
- Ns[i] = scale * sign( hStereoCng->c_PS_LT ) * ( N1[i] - gamma * N2[i] );
- }
- scale *= (float) ( hFdCngCom->fftlen / 2 );
- for ( i = 0; i < hFdCngCom->frameSize / 2; i++ )
- {
- hFdCngCom->olapBufferSynth2[i] = scale * ( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4] );
- hStereoCng->olapBufferSynth22[i] = sign( hStereoCng->c_PS_LT ) * scale * ( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4] );
- }
- }
- else
- {
- for ( i = 0; i < hFdCngCom->frameSize / 2; i++ )
- {
- Np[i] += N1[i];
- }
- mvr2r( &N1[hFdCngCom->frameSize / 2], &Np[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2 );
- scale = (float) ( hFdCngCom->fftlen / 2 );
- for ( i = 0; i < hFdCngCom->frameSize; i++ )
- {
- hFdCngCom->olapBufferSynth2[i] = scale * hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4];
- }
- }
- }
- else
- {
- set_f( hFdCngCom->olapBufferSynth2, 0.0f, hFdCngCom->frameSize / 2 );
- set_f( hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize / 2 );
- }
- if ( flag_sec_CNA )
- {
- mvr2r( Ns, hStereoCng->maskingNoiseS, hFdCngCom->frameSize );
- hStereoCng->enableSecCNA = 1;
- }
- else
- {
- set_f( hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize );
- }
+ Word16 j, stopBandFR;
+ HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom;
- /* add masking noise */
- v_add( Np, syn, syn, hFdCngCom->frameSize );
+ hsCom->CngBandwidth = bwidth; /*Q0*/
+ move16();
+ if ( EQ_16( hsCom->CngBandwidth, FB ) )
+ {
+ hsCom->CngBandwidth = SWB;
+ move16();
}
- else if ( hStereoCng->enableSecCNA )
+ test();
+ IF( NE_32( total_brate, FRAME_NO_DATA ) && NE_32( total_brate, SID_2k40 ) )
{
- SP_ratio = hStereoTD->SP_ratio_LT; /* Use long-term SP ratio based on L/R synthesis */
- /* scale and add masking noise */
- for ( i = 0; i < *hStereoCng->frameSize / 4; i++ )
- {
- scale = ( ( hStereoTD->prevSP_ratio * ( *hStereoCng->frameSize / 4 - (float) i ) + SP_ratio * (float) i ) / ( *hStereoCng->frameSize / 4 ) );
- syn[i] += scale * hStereoCng->maskingNoiseS[i];
- }
- for ( ; i < *hStereoCng->frameSize / 2; i++ )
+ hsCom->CngBitrate = total_brate; /*Q0*/
+ move32();
+ }
+ ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) )
+ {
+ /* set minimum active CBR bitrate IF CngBitrate is uninitialized */
+ IF( element_mode > EVS_MONO )
{
- syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i];
+ hsCom->CngBitrate = IVAS_13k2;
+ move32();
}
- for ( ; i < *hStereoCng->frameSize; i++ )
+ ELSE
{
- syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i];
+ hsCom->CngBitrate = ACELP_7k20;
+ move32();
}
- hStereoTD->prevSP_ratio = SP_ratio;
}
- return;
-}
-
-/*-------------------------------------------------------------------
- * generate_masking_noise_hf_cldfb()
- *
+ /* FD-CNG config for MDCT-Stereo is always the same (since for > 48 kbps only) */
+ /* This may need adjustment in the future IF 2TC DTX for some mode uses MDCT-Stereo DTX for lower bitrates too */
+ if ( EQ_16( element_mode, IVAS_CPE_MDCT ) )
+ {
+ hsCom->CngBitrate = IVAS_48k;
+ move32();
+ }
+ hsCom->numSlots = 16;
+ move32();
+
+ /* NB configuration */
+ IF( EQ_16( bwidth, NB ) )
+ {
+ hsCom->FdCngSetup = FdCngSetup_nb;
+ hsCom->numCoreBands = 16;
+ move16();
+ hsCom->regularStopBand = 16;
+ move16();
+ }
+
+ /* WB configuration */
+ ELSE IF( EQ_16( bwidth, WB ) )
+ {
+ /* FFT 6.4kHz, no CLDFB */
+ test();
+ test();
+ IF( LE_32( hsCom->CngBitrate, ACELP_8k00 ) && EQ_16( L_frame, L_FRAME ) )
+ {
+ hsCom->FdCngSetup = FdCngSetup_wb1;
+ hsCom->numCoreBands = 16;
+ move16();
+ hsCom->regularStopBand = 16;
+ move16();
+ }
+ /* FFT 6.4kHz, CLDFB 8.0kHz */
+ ELSE IF( LE_32( hsCom->CngBitrate, ACELP_13k20 ) || EQ_16( L_frame, L_FRAME ) )
+ {
+ hsCom->FdCngSetup = FdCngSetup_wb2;
+ hsCom->numCoreBands = 16;
+ move16();
+ hsCom->regularStopBand = 20;
+ move16();
+ IF( EQ_16( L_frame, L_FRAME16k ) )
+ {
+ hsCom->FdCngSetup = FdCngSetup_wb2;
+ hsCom->numCoreBands = 20;
+ move16();
+ hsCom->regularStopBand = 20;
+ move16();
+ hsCom->FdCngSetup.fftlen = 640;
+ move16();
+ hsCom->FdCngSetup.stopFFTbin = 256;
+ move16();
+ }
+ }
+ /* FFT 8.0kHz, no CLDFB */
+ ELSE
+ {
+ hsCom->FdCngSetup = FdCngSetup_wb3;
+ hsCom->numCoreBands = 20;
+ move16();
+ hsCom->regularStopBand = 20;
+ move16();
+ }
+ }
+
+ /* SWB/FB configuration */
+ ELSE
+ {
+ /* FFT 6.4kHz, CLDFB 14kHz */
+ IF( EQ_16( L_frame, L_FRAME ) )
+ {
+ hsCom->FdCngSetup = FdCngSetup_swb1;
+ hsCom->numCoreBands = 16;
+ move16();
+ hsCom->regularStopBand = 35;
+ move16();
+ }
+ /* FFT 8.0kHz, CLDFB 16kHz */
+ ELSE
+ {
+ hsCom->FdCngSetup = FdCngSetup_swb2;
+ hsCom->numCoreBands = 20;
+ move16();
+ hsCom->regularStopBand = 40;
+ move16();
+ test();
+ if ( EQ_16( last_L_frame, L_FRAME ) && EQ_16( element_mode, IVAS_CPE_DFT ) )
+ {
+ hsCom->regularStopBand = 35;
+ move16();
+ }
+ }
+ }
+
+
+ hsCom->fftlen = hsCom->FdCngSetup.fftlen;
+ move16();
+ hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin;
+ move16();
+
+ /* Configure the SID quantizer and the Comfort Noise Generator */
+
+ hsCom->startBand = 2;
+ move16();
+ hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[( hsCom->FdCngSetup.numPartitions - 1 )], 1 ); /*Q0*/
+ initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 );
+
+ IF( EQ_16( hsCom->stopFFTbin, 160 ) )
+ {
+ hsCom->nFFTpart = 17;
+ move16();
+ }
+ ELSE IF( EQ_16( hsCom->stopFFTbin, 256 ) )
+ {
+ hsCom->nFFTpart = 20;
+ move16();
+ }
+ ELSE
+ {
+ hsCom->nFFTpart = 21;
+ move16();
+ }
+ hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); /*Q0*/
+ move16();
+ FOR( j = 0; j < hsCom->nCLDFBpart; j++ )
+ {
+ hsCom->CLDFBpart[j] = sub( hsCom->part[( j + hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); /*Q0*/
+ move16();
+ hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[( j + hsCom->nFFTpart )];
+ move16();
+ }
+
+ stopBandFR = 40; //(Word16)floor(1000.f /*Hz*/ / 25.f /*Hz/Bin*/);
+ move16();
+ if ( GT_16( stopBandFR, hsCom->stopFFTbin ) )
+ {
+ stopBandFR = hsCom->stopFFTbin; /*Q0*/
+ move16();
+ }
+
+ initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR );
+
+ hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; /*Q0*/
+ move16();
+
+ BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) );
+ BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) );
+
+ SWITCH( hsCom->fftlen )
+ {
+ case 512:
+ hsCom->olapWinAna_fx = olapWinAna512_fx; /*Q30*/
+ hsCom->fftSineTab_fx = NULL;
+ hsCom->olapWinSyn_fx = olapWinSyn256_fx; /*Q15*/
+ hsCom->fftlenShift = 8;
+ move16();
+ hsCom->fftlenFac = 32767 /*1.0 Q15*/;
+ move16();
+ BREAK;
+ case 640:
+ hsCom->olapWinAna_fx = olapWinAna640_fx; /*Q30*/
+ hsCom->fftSineTab_fx = fftSineTab640_fx; /*Q15*/
+ hsCom->olapWinSyn_fx = olapWinSyn320_fx; /*Q15*/
+ hsCom->fftlenShift = 9;
+ move16();
+ hsCom->fftlenFac = 20480 /*0.625 Q15*/;
+ move16();
+ BREAK;
+ default:
+ assert( !"Unsupported FFT length for FD-based CNG" );
+ BREAK;
+ }
+ BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) );
+ BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) );
+ hsCom->frameSize = shr( hsCom->fftlen, 1 );
+
+ return;
+}
+
+/*-------------------------------------------------------------------
+ * FdCng_decodeSID_ivas_fx()
+ *
+ * Decode the FD-CNG bitstream
+ *-------------------------------------------------------------------*/
+
+void FdCng_decodeSID_ivas_fx(
+ Decoder_State *st /* i/o: decoder state structure */
+)
+{
+ Word16 N;
+ Word32 *sidNoiseEst;
+ Word32 gain;
+ Word16 i, index;
+ Word32 v[32];
+ Word16 indices[32];
+ HANDLE_FD_CNG_COM hFdCngCom;
+ Word32 *invTrfMatrix_fx;
+ Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
+ Word16 tmp16;
+
+ IF( st->element_mode == EVS_MONO )
+ {
+ tmp16 = GAIN_Q_OFFSET_EVS_FX_Q0;
+ move16();
+ }
+ ELSE
+ {
+ tmp16 = GAIN_Q_OFFSET_IVAS_FX_Q0;
+ move16();
+ }
+
+ const Word16 gain_q_offset = tmp16; /* Q0 */
+ move16();
+
+ invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /*Q31*/
+
+ hFdCngCom = ( st->hFdCngDec )->hFdCngCom;
+
+ sidNoiseEst = hFdCngCom->sidNoiseEst; /*Q16*/
+
+ N = hFdCngCom->npart; /*Q0*/
+ move16();
+ gain = 0;
+ move32();
+ hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 );
+ move16();
+
+ /* Read bitstream */
+ FOR( i = 0; i < FD_CNG_stages_37bits; i++ )
+ {
+ indices[i] = get_next_indice_fx( st, bits_37bits[i] ); /*Q0*/
+ move16();
+ }
+
+ index = get_next_indice_fx( st, 7 );
+
+ /* MSVQ decoder */
+
+ IF( st->element_mode != EVS_MONO )
+ {
+ create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC );
+ msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7 );
+ }
+ ELSE
+ { /* Legacy EVS_MONO MSVQ tables */
+ msvq_dec_fx( cdk_37bits, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL, 7 );
+ }
+
+
+ /* Decode gain */
+ // gain = ((float)index - gain_q_offset) / 1.5f;
+ gain = L_mult0( sub( index, gain_q_offset ), 21845 ); // Q15
+
+ /* Apply gain and undo log */
+ Word16 res_exp[NPART];
+ Word16 max_res_exp = 0;
+ move16();
+ FOR( i = 0; i < N; i++ )
+ {
+ sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); /*Q31 - res_exp[i]*/
+ move32();
+ if ( LT_16( max_res_exp, res_exp[i] ) )
+ {
+ max_res_exp = res_exp[i];
+ move16();
+ }
+ }
+
+ FOR( i = 0; i < N; i++ )
+ {
+ sidNoiseEst[i] = L_shr( sidNoiseEst[i], sub( max_res_exp, res_exp[i] ) ); /*Q31 - max_res_exp*/
+ move32();
+ }
+
+ hFdCngCom->sidNoiseEstExp = max_res_exp;
+ move16();
+
+ /* NB last band energy compensation */
+
+ IF( hFdCngCom->CngBandwidth == NB )
+ {
+ sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/
+ move32();
+ }
+
+ test();
+ IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) )
+ {
+ sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/
+ move32();
+ }
+
+ scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 );
+ hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp;
+ move16();
+
+ lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac );
+
+ return;
+}
+
+/*-------------------------------------------------------------------
+ * generate_masking_noise_ivas_fx()
+ *
* Generate additional comfort noise (kind of noise filling)
*-------------------------------------------------------------------*/
-void generate_masking_noise_dirac(
+void generate_masking_noise_ivas_fx(
+ Word32 *timeDomainBuffer, /* i/o: time-domain signal Q31 - *exp_out*/
+ Word16 *exp_out, /* o : time-domain signal exp */
HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
- HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */
- float *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */
- float *Cldfb_RealBuffer, /* o : CLDFD real buffer */
- float *Cldfb_ImagBuffer, /* o : CLDFD imaginary buffer */
- const int16_t slot_index, /* i : CLDFB slot index */
- const int16_t cna_flag, /* i : CNA flag for LB and HB */
- const int16_t fd_cng_flag /* i : FD-CNG flag for HB */
+ const Word16 length, /* i : frame size Q0*/
+ const Word16 core, /* i : core Q0*/
+ const Word16 return_noise, /* i : noise is returned instead of added Q0*/
+ const Word16 secondary, /* i : flag to indicate secondary noise generation Q0*/
+ const Word16 element_mode, /* i : element mode Q0*/
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
+ const Word16 nchan_out /* i : number of output channels Q0*/
+)
+{
+ Word32 *cngNoiseLevel_fx = hFdCngCom->cngNoiseLevel;
+ Word32 *ptr_level_fx = cngNoiseLevel_fx;
+ Word32 *fftBuffer_fx = hFdCngCom->fftBuffer;
+ Word16 i;
+ Word32 maskingNoise_fx[L_FRAME16k];
+ Word32 *ptr_r_fx;
+ Word32 *ptr_i_fx;
+ Word16 startBand;
+ Word16 *seed = &( hFdCngCom->seed );
+ Word32 scale_fx;
+ Word16 shift;
+ scale_fx = 0x40000000; // 1.0 in Q30
+ move32();
+ startBand = hFdCngCom->startBand; /*Q0*/
+ move16();
+ shift = getScaleFactor32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
+ if ( LT_16( sub( hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
+ {
+ shift = sub( hFdCngCom->cngNoiseLevelExp, 4 ); /*Q0*/
+ }
+ scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); /*hFdCngCom->cngNoiseLevelExp*/
+ hFdCngCom->cngNoiseLevelExp = sub( hFdCngCom->cngNoiseLevelExp, shift );
+ move16();
+
+ /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
+ *exp_out = Q15;
+ move16();
+ IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) )
+ {
+ IF( NE_16( core, AMR_WB_CORE ) )
+ {
+ /* Compute additional CN level */
+ FOR( i = 0; i < SIZE_SCALE_TABLE_CN; i++ )
+ {
+ test();
+ test();
+ if ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) &&
+ GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) &&
+ LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) )
+ {
+ BREAK;
+ }
+ }
+
+ scale_fx = L_deposit_h( scaleTable_cn_only[i].scale_ivas ); /* Q30 */
+ }
+ ELSE
+ {
+ /* Compute additional CN level */
+ FOR( i = 0; i < SIZE_SCALE_TABLE_CN_AMRWB; i++ )
+ {
+ if ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only_amrwbio[i][0] ) )
+ {
+ BREAK;
+ }
+ }
+
+ IF( LT_16( i, SIZE_SCALE_TABLE_CN_AMRWB ) )
+ {
+ scale_fx = L_deposit_h( scaleTable_cn_only_amrwbio[i][1] ); /* Q30 */
+ }
+ ELSE
+ {
+ scale_fx = 0;
+ move32();
+ }
+ }
+
+ /* Exclude clean speech */
+ scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); // Q30
+
+ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins
+ Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */
+ IF( startBand == 0 )
+ {
+ rand_gauss_fx( &fftBuffer_fx[0], seed, *exp_out ); // Q15
+ ptr_r_fx = fftBuffer_fx + 2; /*Q31 - hFdCngCom->fftBuffer_exp*/
+ Word16 exp1;
+ exp1 = add( hFdCngCom->cngNoiseLevelExp, 1 );
+ Word32 mpy1;
+ mpy1 = Sqrt32( Mpy_32_32( scale_fx, *ptr_level_fx ), &exp1 ); /*Q31 - exp1*/
+ mpy1 = L_shl( mpy1, exp1 ); // Q31
+ fftBuffer_fx[0] = Mpy_32_32( fftBuffer_fx[0], mpy1 ); /* DC component in FFT */ // Q = Q15
+ ptr_level_fx++;
+ }
+ ELSE
+ {
+ fftBuffer_fx[0] = 0;
+ move32();
+ set32_fx( fftBuffer_fx + 2, 0, shl( sub( startBand, 1 ), 1 ) );
+ ptr_r_fx = fftBuffer_fx + shl( startBand, 1 ); /*Q31 - hFdCngCom->fftBuffer_exp*/
+ }
+ ptr_i_fx = ptr_r_fx + 1;
+ FOR( ; ptr_level_fx < cngNoiseLevel_fx + hFdCngCom->stopFFTbin - startBand; ptr_level_fx++ )
+ {
+ /* Real part in FFT bins */
+ rand_gauss_fx( ptr_r_fx, seed, *exp_out ); // Q15
+ Word16 exp2;
+ exp2 = add( hFdCngCom->cngNoiseLevelExp, 1 );
+ Word32 mpy2;
+ mpy2 = Sqrt32( L_shr( Mpy_32_32( scale_fx, *ptr_level_fx ), 1 ), &exp2 ); /*Q31 - exp2*/
+ ( *ptr_r_fx ) = L_shl( Mpy_32_32( *ptr_r_fx, mpy2 ), exp2 ); // Q = Q15
+ move32();
+ ptr_r_fx += 2;
+
+ /* Imaginary part in FFT bins */
+ rand_gauss_fx( ptr_i_fx, seed, *exp_out ); // Q15
+ ( *ptr_i_fx ) = L_shl( Mpy_32_32( *ptr_i_fx, mpy2 ), exp2 ); // Q = Q15
+ ptr_i_fx += 2;
+ }
+
+ /* Remaining FFT bins are set to zero */
+ set32_fx( fftBuffer_fx + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) );
+ /* Nyquist frequency is discarded */
+ fftBuffer_fx[1] = 0;
+ move32();
+ }
+ ELSE
+ {
+ /* very low level case - update random seeds and reset FFT buffer; don't fully skip SynthesisSTFT_flt(), because of the buffer updates done there... */
+ generate_masking_noise_update_seed_fx( hFdCngCom );
+
+ set32_fx( fftBuffer_fx, 0, hFdCngCom->fftlen );
+ }
+
+ /* Perform STFT synthesis */
+ IF( secondary )
+ {
+ SynthesisSTFT_fx( fftBuffer_fx, maskingNoise_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out );
+ }
+ ELSE
+ {
+ SynthesisSTFT_fx( fftBuffer_fx, maskingNoise_fx, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out );
+ }
+ *exp_out = sub( *exp_out, Q9 );
+ move16();
+
+ /* Add some comfort noise on top of decoded signal */
+ IF( return_noise )
+ {
+ Copy32( maskingNoise_fx, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); /*Q31 - *exp_out*/
+ }
+ ELSE
+ {
+ v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); /*Q31 - *exp_out*/
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------
+ * generate_stereo_masking_noise_fx()
+ *
+ * Generate additional comfort noise (kind of noise filling)
+ *-------------------------------------------------------------------*/
+
+void generate_stereo_masking_noise_fx(
+ Word16 *syn, /* i/o: time-domain signal Q_syn*/
+ Word16 Q_syn,
+ Decoder_State *st, /* i/o: decoder state structure */
+ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */
+ const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel Q0*/
+ const Word16 fadeOut, /* i : only fade out of previous state Q0*/
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */
+ const Word16 nchan_out /* i : number of output channels Q0*/
)
{
- int16_t i;
- float *cngNoiseLevel = hFdCngCom->cngNoiseLevel;
- float *fftBuffer = hFdCngCom->fftBuffer;
- float *ptr_r;
- float *ptr_i;
- float *ptr_level;
- int16_t *seed = &( hFdCngCom->seed );
- float scale;
+ HANDLE_FD_CNG_COM hFdCngCom;
+ Word32 gamma_fx, scale_fx /*, SP_ratio_fx needs to be integrated*/;
+ Word32 Np_fx[L_FRAME16k];
+ Word32 Ns_fx[L_FRAME16k];
+ Word32 N1_fx[L_FRAME16k];
+ Word32 N2_fx[L_FRAME16k];
+ Word16 N1_fx_exp, N2_fx_exp;
+ Word16 i;
- wmops_sub_start( "fd_cng_dirac" );
+ IF( st->idchan == 0 )
+ {
+ hFdCngCom = st->hFdCngDec->hFdCngCom;
+#ifdef FIX_ISSUE_1237
+ Copy_Scale_sig_16_32_no_sat( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); /*Q6*/
+#else
+ Copy_Scale_sig_16_32_DEPREC( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); /*Q6*/
+#endif
+ Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, shr( hFdCngCom->frameSize, 1 ) ); /*st->Q_syn*/
- /* Init */
- scale = 0.f;
+ set32_fx( &Np_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) );
+ set32_fx( &Ns_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) );
- /* Resample CLDFB memories if necessary*/
- if ( ( h_cldfb->no_channels * h_cldfb->no_col ) != hFdCngCom->frameSize )
+ IF( !fadeOut )
+ {
+#ifdef FIX_ISSUE_1237
+ Copy_Scale_sig_16_32_no_sat( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); /*Q15*/
+#else
+ Copy_Scale_sig_16_32_DEPREC( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); /*Q15*/
+#endif
+ generate_masking_noise_ivas_fx( N1_fx, &N1_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out ); // N1_fx Q6
+ /* Generate masking noise for secondary channel */
+ IF( flag_sec_CNA )
+ {
+ generate_masking_noise_ivas_fx( N2_fx, &N2_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out ); // N2_fx Q6
+ gamma_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); /*Q30*/
+ scale_fx = ONE_IN_Q30;
+ move32();
+ IF( LT_32( gamma_fx, 966367642 /* 0.9 in Q30 */ ) )
+ {
+ Word16 exp_gamma;
+ exp_gamma = 0;
+ move16();
+ Word16 divisor1;
+ divisor1 = Inv16( (Word16) L_shr( L_sub( ONE_IN_Q30, gamma_fx ), Q15 ), &exp_gamma ); // Q15-exp_gamma
+ gamma_fx = L_shl( Mpy_32_16_1( gamma_fx, divisor1 ), exp_gamma ); // Q30
+ Word16 exp_gamma1, exp_gamma2, exp_gamma3;
+ exp_gamma1 = Q1;
+ exp_gamma2 = Q1;
+ exp_gamma3 = Q1;
+ move16();
+ move16();
+ move16();
+ gamma_fx = Sqrt32( L_add( gamma_fx, ONE_IN_Q30 ), &exp_gamma1 ); /*Q31 - exp_gamma1*/
+ Word32 temp;
+ temp = Sqrt32( gamma_fx, &exp_gamma2 ); // Q31-exp_gamma1
+ gamma_fx = L_sub( gamma_fx, L_shl( temp, sub( exp_gamma2, exp_gamma1 ) ) ); // Q31-exp_gamma1
+ gamma_fx = L_shl( gamma_fx, sub( exp_gamma1, Q1 ) ); // Q30
+ Word32 divisor2;
+ divisor2 = Sqrt32( L_add( ONE_IN_Q30, L_shl( Mpy_32_32( gamma_fx, gamma_fx ), Q1 ) ), &exp_gamma3 ); // Q31 - exp_gamma3
+ scale_fx = L_shl( divide3232( ONE_IN_Q30, divisor2 ), add( Q15, exp_gamma3 ) ); // Q30
+ }
+ ELSE
+ {
+ gamma_fx = 0;
+ move16();
+ }
+
+ FOR( i = 0; i < 2 * hFdCngCom->frameSize / 4; i++ )
+ {
+ Np_fx[i] = L_add( Np_fx[i],
+ Mpy_32_32( scale_fx, L_shl( L_add( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ) ); // Q6
+ move32();
+ Word32 add2;
+ add2 = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6
+ if ( hStereoCng->c_PS_LT_fx < 0 )
+ {
+ add2 = L_negate( add2 ); /*Q6*/
+ }
+ Ns_fx[i] = L_add( Ns_fx[i], add2 ); /*Q6*/
+ move32();
+ }
+ FOR( ; i < hFdCngCom->frameSize; i++ )
+ {
+ Np_fx[i] = Mpy_32_32( scale_fx, L_shl( L_add( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6
+ move32();
+ Ns_fx[i] = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6
+ move32();
+ IF( hStereoCng->c_PS_LT_fx < 0 )
+ {
+ Ns_fx[i] = L_negate( Ns_fx[i] );
+ move32();
+ }
+ }
+ /* Below code to be converted */
+ Word32 scale_fx_tmp = Mpy_32_32( scale_fx, L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ) ); // Q21
+ FOR( i = 0; i < shr( hFdCngCom->frameSize, 1 ); i++ )
+ {
+ hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp,
+ L_add( L_shr( hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )], Q15 ),
+ Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ) ) ),
+ Q14 ); // Q_olap
+ move16();
+ hStereoCng->olapBufferSynth22_fx[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp,
+ L_sub( L_shr( hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )], Q15 ),
+ Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ) ) ),
+ Q14 ); // Q_olap
+ move16();
+ }
+ }
+ ELSE
+ {
+ FOR( i = 0; i < shr( hFdCngCom->frameSize, 1 ); i++ )
+ {
+ Np_fx[i] = L_add( Np_fx[i], N1_fx[i] ); // Q6
+ move32();
+ }
+ Copy32( &N1_fx[( hFdCngCom->frameSize / 2 )], &Np_fx[( hFdCngCom->frameSize / 2 )], shr( hFdCngCom->frameSize, 1 ) ); /*Q6*/
+ scale_fx = L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ); // Q21
+ FOR( i = 0; i < hFdCngCom->frameSize; i++ )
+ {
+ hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ), Q6 ); // Q_olap
+ move16();
+ }
+ }
+
+ Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, sub( st->Q_syn, 15 ) ); /*st->Q_syn*/
+ }
+ ELSE
+ {
+ set16_fx( hFdCngCom->olapBufferSynth2, 0, shr( hFdCngCom->frameSize, 1 ) );
+ set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( hFdCngCom->frameSize, 1 ) );
+ }
+ IF( flag_sec_CNA )
+ {
+ Copy_Scale_sig_32_16( Ns_fx, hStereoCng->maskingNoiseS_fx, hFdCngCom->frameSize, 0 ); // Q6
+ hStereoCng->enableSecCNA = 1;
+ move16();
+ }
+ ELSE
+ {
+ set16_fx( hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize );
+ }
+
+ /* add masking noise */
+ FOR( i = 0; i < hFdCngCom->frameSize; i++ )
+ {
+ syn[i] = add( syn[i], (Word16) L_shr( Np_fx[i], sub( Q16 + Q6, Q_syn ) ) ); // Q_syn
+ move16();
+ }
+ }
+ ELSE IF( hStereoCng->enableSecCNA )
{
- resampleCldfb( h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC );
+ Word16 SP_ratio_fx;
+ SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis Q15*/
+ Word16 prevSP_ratio_fx;
+ prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis Q15*/
+ move16();
+ /* scale and add masking noise */
+ FOR( i = 0; i < shr( *hStereoCng->frameSize, 2 ); i++ )
+ {
+ Word16 s;
+ Word16 scale_fx_tmp;
+ scale_fx_tmp = BASOP_Util_Divide3216_Scale( L_add( L_mult0( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), L_mult0( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ), &s ); // Q15
+ scale_fx_tmp = shl( scale_fx_tmp, s );
+ syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/
+ move16();
+ }
+ FOR( ; i < *hStereoCng->frameSize / 2; i++ )
+ {
+ syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/
+ move16();
+ }
+ FOR( ; i < *hStereoCng->frameSize; i++ )
+ {
+ syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/
+ move16();
+ }
+ hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /*Q15*/
+ move16();
}
- set_zero( Cldfb_RealBuffer, CLDFB_NO_CHANNELS_MAX );
- set_zero( Cldfb_ImagBuffer, CLDFB_NO_CHANNELS_MAX );
+ return;
+}
+void generate_masking_noise_lb_dirac_fx(
+ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
+ Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA Q11*/
+ const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered Q0*/
+ const Word16 cna_flag /* i : CNA flag for LB and HB Q0*/
+)
+{
+ Word16 i;
+ Word32 *cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*hFdCngCom->cngNoiseLevelExp*/
+ Word32 *fftBuffer = hFdCngCom->fftBuffer; /*hFdCngCom->fftBuffer_exp*/
+ Word32 *ptr_r;
+ Word32 *ptr_i;
+ Word32 *ptr_level;
+ Word16 *seed = &( hFdCngCom->seed );
+ Word32 scale;
+ Word16 n_samples_out, n_samples_start, n_samples_out_loop;
+
+ push_wmops( "fd_cng_dirac" );
+ /* Init */
+ scale = 0;
+ move32();
+ n_samples_out = i_mult( shr( hFdCngCom->frameSize, 4 ), nCldfbTs );
+ n_samples_start = 0;
+ move16();
+ Word16 exp_out = Q11;
+ move16();
/*LB CLDFB - CNA from STFT*/
-#ifdef DEBUG_MODE_DIRAC
- {
- int16_t tmp_s;
- tmp_s = (int16_t) ( 32768.f * 0.5f * hFdCngCom->likelihood_noisy_speech * cna_flag + 0.5f );
- dbgwrite( &tmp_s, sizeof( int16_t ), 1, hFdCngCom->frameSize / 16, "./res/ivas_dirac_likelihood_noisy.pcm" );
- }
-#endif
- if ( cna_flag )
+ IF( cna_flag )
{
/* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
- if ( hFdCngCom->likelihood_noisy_speech > DELTA_MASKING_NOISE )
+ IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) )
{
/* Compute additional CN level */
- for ( i = 0; i < 15; i++ )
+ FOR( i = 0; i < 15; i++ )
{
- if ( ( hFdCngCom->CngBandwidth == scaleTable_cn_dirac[i].bwmode ) &&
- ( hFdCngCom->CngBitrate >= scaleTable_cn_dirac[i].bitrateFrom ) &&
- ( hFdCngCom->CngBitrate < scaleTable_cn_dirac[i].bitrateTo ) )
+ test();
+ test();
+ if ( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode ) ) &&
+ GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) &&
+ LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) )
{
- break;
+ BREAK;
}
}
- scale = (float) pow( 10.f, -scaleTable_cn_dirac[i].scale / 10.f ) - 1.f;
- scale *= hFdCngCom->likelihood_noisy_speech;
+ scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */
+ scale = Mpy_32_16_1( scale, hFdCngCom->likelihood_noisy_speech ); /* Q30 */
}
}
/* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/
- if ( cna_flag && tdBuffer != NULL )
+ test();
+ IF( cna_flag && tdBuffer != NULL )
{
- if ( scale != 0 )
+ WHILE( n_samples_out > 0 )
{
- /*Generate LF comfort noise only at first slot, for the whole frame*/
- if ( slot_index == 0 )
+ n_samples_out_loop = s_min( hFdCngCom->frameSize, n_samples_out );
+ IF( scale != 0 )
{
- ptr_level = cngNoiseLevel;
+ /*Generate LF comfort noise only at first slot, for the whole frame*/
+ ptr_level = cngNoiseLevel; /*hFdCngCom->cngNoiseLevelExp*/
/* Generate Gaussian random noise in real and imaginary parts of the FFT bins
- Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */
- if ( hFdCngCom->startBand == 0 )
+ Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */
+ IF( EQ_16( hFdCngCom->startBand, 0 ) )
{
- rand_gauss( &fftBuffer[0], seed );
- ptr_r = fftBuffer + 2;
- fftBuffer[0] *= (float) sqrt( scale * *ptr_level ); /* DC component in FFT */
+ rand_gauss_fx( &fftBuffer[0], seed, exp_out );
+ ptr_r = fftBuffer + 2; /*hFdCngCom->fftBuffer_exp*/
+
+ Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp );
+ Word32 sqr = Sqrt32( L_shr( Mpy_32_32( scale, *ptr_level ), 1 ), &exp2 ); /* DC component in FFT Q31 - exp2*/
+ sqr = L_shl( sqr, exp2 ); /*Q31*/
+ fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqr ); /* DC component in FFT Q31 - hFdCngCom->fftBuffer_exp*/
+ move32();
ptr_level++;
}
- else
+ ELSE
{
- fftBuffer[0] = 0.f;
- set_f( fftBuffer + 2, 0.0f, 2 * ( hFdCngCom->startBand - 1 ) );
- ptr_r = fftBuffer + 2 * hFdCngCom->startBand;
+ fftBuffer[0] = 0;
+ move32();
+ set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) );
+ ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); /*hFdCngCom->fftBuffer_exp*/
}
- ptr_i = ptr_r + 1;
+ ptr_i = ptr_r + 1; /*hFdCngCom->fftBuffer_exp*/
- for ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++ )
+ FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ )
{
- /* Real part in FFT bins */
- rand_gauss( ptr_r, seed );
- ( *ptr_r ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
+ rand_gauss_fx( ptr_r, seed, exp_out );
+ Word16 exp2 = hFdCngCom->cngNoiseLevelExp;
+ Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); /*Q31 - exp2*/
+ ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); /*Q31 - hFdCngCom->fftBuffer_exp*/
+ move32();
ptr_r += 2;
+
/* Imaginary part in FFT bins */
- rand_gauss( ptr_i, seed );
- ( *ptr_i ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
+ rand_gauss_fx( ptr_i, seed, exp_out );
+ ( *ptr_i ) = L_shl( Mpy_32_32( *ptr_i, mpy2 ), exp2 ); /*Q31 - hFdCngCom->fftBuffer_exp*/
+ move32();
ptr_i += 2;
}
-
/* Remaining FFT bins are set to zero */
- set_f( fftBuffer + 2 * hFdCngCom->stopFFTbin, 0.0f, hFdCngCom->fftlen - 2 * hFdCngCom->stopFFTbin );
+ set32_fx( fftBuffer + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) );
/* Nyquist frequency is discarded */
- fftBuffer[1] = 0.f;
+ fftBuffer[1] = 0;
+ move32();
/* Perform STFT synthesis */
- SynthesisSTFT( fftBuffer, tdBuffer, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom, X, Y, -1, -1 );
-
-#ifdef DEBUG_MODE_DIRAC
- {
- int16_t tmp[1000];
-
- for ( i = 0; i < hFdCngCom->frameSize; i++ )
- {
- tmp[i] = (int16_t) ( tdBuffer[i] + 0.5f );
- }
- dbgwrite( tmp, sizeof( int16_t ), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm" );
- }
-#endif
+ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom );
+ scale_sig32( tdBuffer + n_samples_start, n_samples_out_loop, Q9 ); // Q2 -> Q11
}
- /* LF CLDFB*/
- cldfbAnalysis_ts( &( tdBuffer[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb );
- }
- else
- {
- if ( slot_index == 0 )
+ ELSE
{
/* very low level case - update random seeds */
generate_masking_noise_update_seed_fx( hFdCngCom );
- set_f( fftBuffer, 0.f, hFdCngCom->fftlen );
-
+ set32_fx( fftBuffer, 0, hFdCngCom->fftlen );
/* Perform STFT synthesis */
- SynthesisSTFT( fftBuffer, tdBuffer, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom, X, Y, -1, -1 );
+ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom );
+ }
+ hFdCngCom->fftBuffer_exp = 31 - 11;
+ move16();
+ n_samples_out = sub( n_samples_out, hFdCngCom->frameSize );
+ n_samples_start = add( n_samples_start, hFdCngCom->frameSize );
+ }
+ }
-#ifdef DEBUG_MODE_DIRAC
- {
- int16_t tmp[1000];
+ pop_wmops();
- for ( i = 0; i < hFdCngCom->frameSize; i++ )
- {
- tmp[i] = (int16_t) ( tdBuffer[i] + 0.5f );
- }
- dbgwrite( tmp, sizeof( int16_t ), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm" );
+ return;
+}
+void generate_masking_noise_dirac_ivas_fx(
+ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
+ HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */
+ Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA q_input*/
+ Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer q_cldfb*/
+ Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer q_cldfb*/
+ const Word16 slot_index, /* i : CLDFB slot index Q0*/
+ const Word16 cna_flag, /* i : CNA flag for LB and HB Q0*/
+ const Word16 fd_cng_flag, /* i : FD-CNG flag for HB Q0*/
+ Word16 q_input,
+ Word16 *q_cldfb )
+{
+ Word16 i;
+ Word32 *ptr_level_fx;
+ Word16 *seed = &( hFdCngCom->seed );
+ Word32 scale_fx;
+ Word16 q_scale, q_shift, q_ptr_level;
+
+ push_wmops( "fd_cng_dirac" );
+
+ /* Init */
+ scale_fx = 0;
+ move32();
+
+ /* Resample CLDFB memories if necessary*/
+ IF( NE_16( i_mult( h_cldfb->no_channels, h_cldfb->no_col ), hFdCngCom->frameSize ) )
+ {
+ resampleCldfb_ivas_fx( h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC );
+ }
+
+ set32_fx( Cldfb_RealBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX );
+ set32_fx( Cldfb_ImagBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX );
+
+ /*LB CLDFB - CNA from STFT*/
+ IF( cna_flag != 0 )
+ {
+ /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
+ IF( hFdCngCom->likelihood_noisy_speech > 0 )
+ {
+ /* Compute additional CN level */
+ FOR( i = 0; i < 15; i++ )
+ {
+ test();
+ test();
+ if ( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode ) ) &&
+ ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) ) &&
+ ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) ) )
+ {
+ BREAK;
}
-#endif
}
+ scale_fx = L_shr( L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ), Q3 ); /* Q27 */
+ scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech );
+ }
+ }
+ /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/
+ IF( cna_flag && tdBuffer_fx != NULL )
+ {
+ *q_cldfb = q_input;
+ move16();
+ IF( scale_fx != 0 )
+ {
+ /* LF CLDFB*/
+ cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[( hFdCngCom->numCoreBands * slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb );
+ }
+ ELSE
+ {
/* LB ana CLDFB*/
- cldfbAnalysis_ts( &( tdBuffer[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb );
+ cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[( hFdCngCom->numCoreBands * slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb );
}
}
/*HF CLDFB - CNA and/or FD-CNG*/
if ( fd_cng_flag )
{
- scale += 1.f;
+ scale_fx = L_add( scale_fx, ONE_IN_Q27 ); // 1 in Q27
}
- if ( scale != 0 )
+ IF( scale_fx != 0 )
{
- scale *= CLDFB_SCALING_FLT * ( h_cldfb->scale * h_cldfb->scale * 8.f );
- ptr_level = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand;
-
- for ( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ )
+ q_scale = 27;
+ move16();
+ q_shift = norm_l( scale_fx );
+ scale_fx = L_shl( scale_fx, q_shift ); /*q_scale+q_shift*/
+ q_scale = add( q_scale, q_shift );
+ scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2 * Q8 - 34
+ q_scale = sub( add( q_scale, 2 * Q8 ), 31 );
+ ptr_level_fx = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/
+ q_ptr_level = sub( 31, hFdCngCom->cngNoiseLevelExp );
+
+ FOR( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ )
{
+ Word32 num;
+ Word16 exp, q_num;
+ q_shift = norm_l( scale_fx );
+ scale_fx = L_shl( scale_fx, q_shift ); /*q_scale+q_shift*/
+ q_scale = add( q_scale, q_shift );
+ num = Mpy_32_32( scale_fx, *ptr_level_fx ); /*q_num*/
+ q_num = sub( add( q_scale, q_ptr_level ), 31 );
+ exp = sub( 31, q_num );
+ num = Sqrt32( num, &exp ); /*Q31 - exp*/
/* Real part in CLDFB band */
- rand_gauss( &Cldfb_RealBuffer[i], seed );
- Cldfb_RealBuffer[i] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
+ rand_gauss_fx( &Cldfb_RealBuffer_fx[i], seed, *q_cldfb );
+ Cldfb_RealBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_RealBuffer_fx[i], num ), exp );
+ move32();
/* Imaginary part in CLDFB band */
- rand_gauss( &Cldfb_ImagBuffer[i], seed );
- Cldfb_ImagBuffer[i] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
+ rand_gauss_fx( &Cldfb_ImagBuffer_fx[i], seed, *q_cldfb );
+ Cldfb_ImagBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_ImagBuffer_fx[i], num ), exp );
+ move32();
- ptr_level++;
+ ptr_level_fx++;
}
}
- wmops_sub_end();
+ pop_wmops();
return;
}
@@ -5349,94 +5705,155 @@ void generate_masking_noise_dirac(
*
*-------------------------------------------------------------------*/
-void FdCngDecodeMDCTStereoSID(
+void FdCngDecodeMDCTStereoSID_fx(
CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
)
{
DEC_CORE_HANDLE sts[CPE_CHANNELS];
HANDLE_FD_CNG_COM hFdCngCom;
- float *ms_ptr[CPE_CHANNELS];
- float *lr_ptr[CPE_CHANNELS];
- float logNoiseEst[CPE_CHANNELS][NPART];
- float gain[CPE_CHANNELS];
- int16_t indices[FD_CNG_stages_37bits];
- int16_t N, i, ch, p, stages;
- int16_t is_out_ms;
+ Word32 *ms_ptr_fx[CPE_CHANNELS];
+ Word32 *lr_ptr_fx[CPE_CHANNELS];
+ Word32 logNoiseEst_fx[CPE_CHANNELS][NPART];
+ Word32 gain_fx[CPE_CHANNELS];
+ Word16 indices[FD_CNG_stages_37bits];
+ Word16 N, i, ch, p, stages;
+ Word16 is_out_ms;
+ Word32 *invTrfMatrix_fx;
+ Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
+ Word16 shift, exp_diff, max_exp_idx;
+ Word16 exp_arr[NPART];
+ Word32 tmp32, tmp32_arr[NPART];
+
+ invTrfMatrix_fx = (Word32 *) tmpRAM_fx;
+ create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC ); // Q31
is_out_ms = 0;
+ move16();
if ( hCPE->hCoreCoder[0]->cng_sba_flag )
{
is_out_ms = 1;
+ move16();
}
N = 0; /* to avoid compilation warning */
+ move16();
- for ( ch = 0; ch < CPE_CHANNELS; ch++ )
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
{
sts[ch] = hCPE->hCoreCoder[ch];
- ms_ptr[ch] = &logNoiseEst[ch][0];
- lr_ptr[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0];
+ ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; /*Q20*/
+ lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; /*Q18*/
}
/* decode noise shapes and gains */
- for ( ch = 0; ch < CPE_CHANNELS; ch++ )
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
{
sts[ch] = hCPE->hCoreCoder[ch];
hFdCngCom = ( sts[ch]->hFdCngDec )->hFdCngCom;
N = hFdCngCom->npart;
- hFdCngCom->sid_frame_counter++;
+ move16();
+ hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 ); /*Q0*/
+ move16();
- if ( ch )
+ IF( ch )
{
stages = FD_CNG_JOINT_stages_25bits;
+ move16();
}
- else
+ ELSE
{
stages = FD_CNG_stages_37bits;
+ move16();
}
/* read bitstream */
- for ( i = 0; i < stages; i++ )
+ FOR( i = 0; i < stages; i++ )
{
- indices[i] = get_next_indice( sts[ch], bits_37bits[i] );
+ indices[i] = get_next_indice_fx( sts[ch], bits_37bits[i] ); /*Q0*/
+ move16();
}
{
- gain[ch] = ( (float) get_next_indice( sts[ch], 7 ) - GAIN_Q_OFFSET_IVAS ) / 1.5f;
+ gain_fx[ch] = Mpy_32_32( L_shl( L_sub( get_next_indice_fx( sts[ch], 7 ), GAIN_Q_OFFSET_IVAS_FX ), Q20 ), TWO_BY_THREE_Q31 /* 2/3 in Q31 */ ); // Q20
+ move32();
}
/* MSVQ decoder */
- msvq_dec( cdk_37bits_ivas, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, ms_ptr[ch], NULL );
+ shift = find_guarded_bits_fx( N );
+ msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, ms_ptr_fx[ch], NULL, 7 ); // Q20 - shift
+
+ Scale_sig32( ms_ptr_fx[ch], N, shift ); // Q20
}
- if ( sts[0]->hFdCngDec->hFdCngCom->no_side_flag )
+ dtx_read_padding_bits_fx( sts[1], mult( sub( IVAS_SID_5k2, 4400 ), ONE_BY_FRAMES_PER_SEC_Q15 ) );
+
+ IF( sts[0]->hFdCngDec->hFdCngCom->no_side_flag )
{
- set_zero( ms_ptr[1], NPART );
+ set32_fx( ms_ptr_fx[1], 0, NPART );
}
- if ( is_out_ms == 0 )
+ IF( EQ_16( is_out_ms, 0 ) )
{
- inverseMS( N, ms_ptr[0], ms_ptr[1], 1.f );
+ inverseMS_fx( N, ms_ptr_fx[0], ms_ptr_fx[1], ONE_IN_Q31 );
}
- for ( ch = 0; ch < CPE_CHANNELS; ch++ )
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
{
+ max_exp_idx = 0;
+ move16();
hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom;
- for ( p = 0; p < N; p++ )
+ FOR( p = 0; p < N; p++ )
{
- lr_ptr[ch][p] = powf( 10.f, ( ms_ptr[ch][p] + gain[ch] ) / 10.f );
+ tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20
+ tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); /*Q31 - exp_arr[p]*/
+ move32();
+ if ( LT_16( exp_arr[max_exp_idx], exp_arr[p] ) )
+ {
+ max_exp_idx = p; /*Q0*/
+ move16();
+ }
+ }
+
+ // Bringing in same exponent
+ FOR( p = 0; p < N; p++ )
+ {
+ lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); /*Q31 - exp_arr[max_exp_idx]*/
+ move32();
}
- scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 );
+ hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx];
+ move16();
+
+ scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 );
+
+ hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp;
+ move16();
lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
}
- if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_4k4 )
+ test();
+ IF( EQ_16( hCPE->nchan_out, 1 ) && LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) )
{
/* create proper M noise shape in channel zero after gains have been applied */
- for ( p = 0; p < N; p++ )
+ exp_diff = sub( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp );
+ move16();
+ FOR( p = 0; p < N; p++ )
+ {
+ IF( GT_16( exp_diff, 0 ) )
+ {
+ sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); /*Q18*/
+ move32();
+ }
+ ELSE
+ {
+ sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); /*Q18*/
+ move32();
+ }
+ }
+ IF( LT_16( exp_diff, 0 ) )
{
- sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * ( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p] );
+ sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp = add( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, negate( exp_diff ) );
+ move16();
}
}
@@ -5445,86 +5862,141 @@ void FdCngDecodeMDCTStereoSID(
/*-------------------------------------------------------------------
- * FdCngDecodeDiracMDCTStereoSID()
+ * FdCngDecodeDiracMDCTStereoSID_fx()
*
- * Decode FD-Cng parameters for CNG in 2TC DirAC mode from the bitstream
+ * Decode FD-CNG parameters for CNG in 2TC DirAC mode from the bitstream
*-------------------------------------------------------------------*/
-void FdCngDecodeDiracMDCTStereoSID(
+void FdCngDecodeDiracMDCTStereoSID_fx(
CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
)
{
DEC_CORE_HANDLE sts[CPE_CHANNELS];
HANDLE_FD_CNG_COM hFdCngCom;
- float *ms_ptr[CPE_CHANNELS];
- float *lr_ptr[CPE_CHANNELS];
- float logNoiseEst[CPE_CHANNELS][NPART];
- float gain[CPE_CHANNELS];
- int16_t indices[FD_CNG_stages_37bits];
- int16_t N, i, ch, p;
-
- for ( ch = 0; ch < CPE_CHANNELS; ch++ )
+ Word32 *ms_ptr_fx[CPE_CHANNELS];
+ Word32 *lr_ptr_fx[CPE_CHANNELS];
+ Word32 logNoiseEst_fx[CPE_CHANNELS][NPART];
+ Word32 gain_fx[CPE_CHANNELS];
+ Word16 indices[FD_CNG_stages_37bits];
+ Word16 N, i, ch, p;
+ Word32 *invTrfMatrix_fx;
+ Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
+ Word16 shift, exp_diff, max_exp_idx;
+ Word16 exp_arr[NPART];
+ Word32 tmp32, tmp32_arr[NPART];
+
+ invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /* dynamically filled */
+ create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC ); // Q31
+
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
{
sts[ch] = hCPE->hCoreCoder[ch];
- ms_ptr[ch] = &logNoiseEst[ch][0];
- lr_ptr[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0];
- ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++;
+ ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; /*Q20*/
+ lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; /*Q20*/
+ ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++; /*Q18*/
}
/* decode noise shapes and gains */
hFdCngCom = ( sts[0]->hFdCngDec )->hFdCngCom;
- N = hFdCngCom->npart;
+ N = hFdCngCom->npart; /*Q0*/
+ move16();
/* read bitstream */
- for ( i = 0; i < FD_CNG_stages_37bits; i++ )
+ FOR( i = 0; i < FD_CNG_stages_37bits; i++ )
{
- indices[i] = get_next_indice( sts[0], bits_37bits[i] );
+ indices[i] = get_next_indice_fx( sts[0], bits_37bits[i] ); /*Q0*/
+ move16();
}
- gain[0] = ( (float) get_next_indice( sts[0], 7 ) - GAIN_Q_OFFSET_IVAS ) / 1.5f;
- gain[1] = gain[0];
+ gain_fx[0] = Mpy_32_32( L_shl( L_sub( get_next_indice_fx( sts[0], 7 ), GAIN_Q_OFFSET_IVAS_FX ), Q20 ), TWO_BY_THREE_Q31 /* 2/3 in Q31 */ ); // Q20
+ move32();
+
+ gain_fx[1] = gain_fx[0]; /*Q20*/
+ move32();
/* MSVQ decoder */
- msvq_dec( cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, ms_ptr[0], NULL );
- mvr2r( ms_ptr[0], ms_ptr[1], N );
+ shift = find_guarded_bits_fx( N );
+ msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, ms_ptr_fx[0], NULL, 7 ); // Q20 - shift
+
+ Scale_sig32( ms_ptr_fx[0], N, shift ); // Q20
- /*inverseMS( N, ms_ptr[0], ms_ptr[1], 1.f );*/
+ Copy32( ms_ptr_fx[0], ms_ptr_fx[1], N ); /*Q20*/
- for ( ch = 0; ch < CPE_CHANNELS; ch++ )
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
{
+ max_exp_idx = 0;
+ move16();
hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom;
- for ( p = 0; p < N; p++ )
+
+ FOR( p = 0; p < N; p++ )
+ {
+ tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20
+ tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); /*Q31 - exp_arr[p]*/
+ move32();
+ if ( LT_16( exp_arr[max_exp_idx], exp_arr[p] ) )
+ {
+ max_exp_idx = p; /*Q0*/
+ move16();
+ }
+ }
+
+ // Bringing in same exponent
+ FOR( p = 0; p < N; p++ )
{
- lr_ptr[ch][p] = powf( 10.f, ( ms_ptr[ch][p] + gain[ch] ) / 10.f );
+ lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); /*Q20*/
+ move32();
}
+ hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx]; /*Q0*/
+ move16();
+
/* NB last band energy compensation */
- if ( hFdCngCom->CngBandwidth == NB )
+ test();
+ IF( hFdCngCom->CngBandwidth == NB )
{
- lr_ptr[ch][N - 1] *= NB_LAST_BAND_SCALE;
+ lr_ptr_fx[ch][( N - 1 )] = Mpy_32_32( lr_ptr_fx[ch][( N - 1 )], NB_LAST_BAND_SCALE_Q31 ); /*Q20*/
+ move32();
}
- else if ( hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20 )
+ ELSE IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) )
{
- lr_ptr[ch][N - 1] *= SWB_13k2_LAST_BAND_SCALE;
+ lr_ptr_fx[ch][( N - 1 )] = Mpy_32_32( lr_ptr_fx[ch][( N - 1 )], SWB_13k2_LAST_BAND_SCALE_Q31 ); /*Q20*/
+ move32();
}
- scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 );
+ scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 );
+
+ hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp;
+ move16();
lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
}
- sts[0]->hFdCngDec->hFdCngCom->coherence = 0.0f;
- sts[1]->hFdCngDec->hFdCngCom->coherence = 0.0f;
+ sts[0]->hFdCngDec->hFdCngCom->coherence_fx = 0;
+ move16();
+ sts[1]->hFdCngDec->hFdCngCom->coherence_fx = 0;
+ move16();
- if ( hCPE->nchan_out == 1 )
+ IF( EQ_16( hCPE->nchan_out, 1 ) )
{
/* create proper M noise shape in channel zero after gains have been applied */
- for ( p = 0; p < N; p++ )
+ exp_diff = sub( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp );
+ FOR( p = 0; p < N; p++ )
+ {
+ IF( exp_diff > 0 )
+ {
+ sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); /*Q18*/
+ move32();
+ }
+ ELSE
+ {
+ sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); /*Q18*/
+ move32();
+ }
+ }
+ IF( exp_diff < 0 )
{
- sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * ( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p] );
+ sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp = add( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, negate( exp_diff ) );
+ move16();
}
- sts[0]->hFdCngDec->hFdCngCom->coherence = 0.0f;
- sts[1]->hFdCngDec->hFdCngCom->coherence = 0.0f;
}
return;
}
-#endif
diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c
index 3a39f9e3312ee58ab31739545e069199f2d2accb..6c63377fd4798954750060a7477bcf5bf9ad161e 100644
--- a/lib_dec/gs_dec_fx.c
+++ b/lib_dec/gs_dec_fx.c
@@ -6,7 +6,6 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_cnst.h"
/*=========================================================================*/
@@ -75,12 +74,7 @@ void decod_audio_fx(
/* decode GSC SWB speech flag */
test();
-#if !defined ADD_LRTD
IF( st_fx->coder_type != INACTIVE && GE_32( st_fx->total_brate, ACELP_13k20 ) )
-#else
- if ( st_fx->GSC_IVAS_mode >= 1 || ( st_fx->coder_type != INACTIVE && ( ( st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20 ) ||
- ( st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k ) ) ) )
-#endif
{
st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */
move16();
@@ -98,30 +92,17 @@ void decod_audio_fx(
}
/* set bit-allocation */
-#ifdef ADD_LRTD
-#ifdef NONBE_FIX_GSC_BSTR
- config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode );
-#else
- config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode );
-#endif
-#else
#ifdef NONBE_FIX_GSC_BSTR
config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode );
#else
config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode );
-#endif
#endif
/*---------------------------------------------------------------*
* Decode energy dynamics
*---------------------------------------------------------------*/
-#if defined ADD_LRTD
- test();
- test();
- IF( st_fx->GSC_IVAS_mode >= 1 || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && st_fx->GSC_IVAS_mode == 0 ) )
-#else
+
IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) )
-#endif
{
nb_subfr = NB_SUBFR; /* Q0 */
move16();
@@ -129,25 +110,6 @@ void decod_audio_fx(
move16();
hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */
move16();
-#ifdef ADD_LRTD
- if ( st_fx->GSC_IVAS_mode >= 1 )
- {
- if ( st_fx->core_brate < GSC_L_RATE_STG && st_fx->GSC_IVAS_mode < 3 )
- {
- nb_subfr = 2;
- }
- hGSCDec->noise_lev = NOISE_LEVEL_SP2;
-
- if ( st_fx->GSC_IVAS_mode == 3 ) /* Music like */
- {
- hGSCDec->noise_lev = NOISE_LEVEL_SP0;
- }
- else if ( st_fx->GSC_noisy_speech == 0 ) /* speech like but not noisy */
- {
- hGSCDec->noise_lev = NOISE_LEVEL_SP3;
- }
- }
-#endif
}
ELSE
{
@@ -165,54 +127,30 @@ void decod_audio_fx(
/*---------------------------------------------------------------*
* Decode number of subframes
*---------------------------------------------------------------*/
-#ifdef ADD_LRTD
- if ( st_fx->L_frame == L_FRAME16k && ( st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type == INACTIVE ) )
- {
- hGSCDec->cor_strong_limit = 0;
- nb_subfr = 1;
- }
- else
-#endif
+
+
+ hGSCDec->cor_strong_limit = 1; /* Q0 */
+ move16();
+ nb_subfr = SWNB_SUBFR;
+ move16();
+
+ IF( GE_32( st_fx->core_brate, ACELP_9k60 ) )
{
- hGSCDec->cor_strong_limit = 1; /* Q0 */
+ nbits = 1;
move16();
- nb_subfr = SWNB_SUBFR;
+ nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */
move16();
- IF( GE_32( st_fx->core_brate, ACELP_9k60 ) )
+ IF( s_and( nb_frame_flg, 0x1 ) == 0 )
{
- nbits = 1;
+ nb_subfr = 2 * SWNB_SUBFR; /* Q0 */
move16();
-#ifdef ADD_LRTD
- if ( st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR )
- {
- nbits = 2;
- }
-#endif
- nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */
+ hGSCDec->cor_strong_limit = 0;
move16();
-
- IF( s_and( nb_frame_flg, 0x1 ) == 0 )
- {
- nb_subfr = 2 * SWNB_SUBFR; /* Q0 */
- move16();
- hGSCDec->cor_strong_limit = 0;
- move16();
- }
-#ifdef ADD_LRTD
- else if ( st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR )
- {
- nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */
- }
-
- if ( ( nb_frame_flg >> 1 ) == 1 )
- {
- nb_subfr *= 2;
- }
-#endif
}
}
}
+
/*---------------------------------------------------------------*
* Decode the last band where the adaptive (pitch) contribution is significant
*---------------------------------------------------------------*/
@@ -282,13 +220,7 @@ void decod_audio_fx(
* Decode adaptive (pitch) excitation contribution
*---------------------------------------------------------------*/
test();
-#ifdef ADD_LRTD
- if ( !( st_fx->GSC_IVAS_mode > 0 && st_fx->L_frame / nb_subfr == 2 * L_SUBFR && st_fx->GSC_IVAS_mode < 3 ) &&
- ( ( st_fx->core_brate >= MIN_RATE_FCB || st_fx->GSC_noisy_speech ) &&
- ( ( nb_subfr == NB_SUBFR && st_fx->L_frame == L_FRAME ) || ( nb_subfr == NB_SUBFR16k && st_fx->L_frame == L_FRAME16k ) ) ) )
-#else
IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) && EQ_16( nb_subfr, NB_SUBFR ) )
-#endif
{
Word16 indice;
nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; /* Q0 */
@@ -303,11 +235,9 @@ void decod_audio_fx(
Es_pred_dec_fx( &Es_pred, indice, nbits, 0 );
}
-#ifdef ADD_LRTD
- dec_pit_exc_fx( st_fx, Aq, coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
-#else
+
dec_pit_exc_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf );
-#endif
+
IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
{
minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit );
@@ -439,39 +369,19 @@ void decod_audio_fx(
tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */
move16();
-#ifdef IVAS_CODE
- if ( st_fx->extl_brate_fx_orig > 0 )
-#else
+
if ( st_fx->extl_brate > 0 )
-#endif
{
/* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */
tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */
}
-
- test();
-#if defined ADD_LRTD
- test();
- if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 )
-#else
test();
if ( st_fx->coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) )
-#endif
{
tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); /* Q0 */
}
-#ifdef ADD_LRTD
- IF( EQ_16( st_fx->idchan, 1 ) )
- {
- tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS );
- IF( EQ_16( st_fx->tdm_LRTD_flag, 1 ) )
- {
- tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA );
- }
- }
-#endif
gsc_dec_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc );
/*--------------------------------------------------------------------------------------*
* iDCT transform
@@ -612,26 +522,19 @@ void decod_audio_ivas_fx(
}
/* set bit-allocation */
-#if 1 // def ADD_LRTD
#ifdef NONBE_FIX_GSC_BSTR
config_acelp1_IVAS( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode );
#else
config_acelp1_IVAS( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode );
#endif
-#else
- config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode );
-#endif
/*---------------------------------------------------------------*
* Decode energy dynamics
*---------------------------------------------------------------*/
-#if 1 // defined ADD_LRTD
+
test();
test();
IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && st_fx->GSC_IVAS_mode == 0 ) )
-#else
- IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) )
-#endif
{
nb_subfr = NB_SUBFR; /* Q0 */
move16();
@@ -639,7 +542,7 @@ void decod_audio_ivas_fx(
move16();
hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */
move16();
-#if 1 // def ADD_LRTD
+
IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) )
{
test();
@@ -662,7 +565,6 @@ void decod_audio_ivas_fx(
move16();
}
}
-#endif
}
ELSE
{
@@ -680,7 +582,7 @@ void decod_audio_ivas_fx(
/*---------------------------------------------------------------*
* Decode number of subframes
*---------------------------------------------------------------*/
-#if 1 // def ADD_LRTD
+
test();
test();
IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( LE_32( st_fx->core_brate, ACELP_13k20 ) || st_fx->coder_type == INACTIVE ) )
@@ -691,7 +593,6 @@ void decod_audio_ivas_fx(
move16();
}
ELSE
-#endif
{
hGSCDec->cor_strong_limit = 1; /* Q0 */
move16();
@@ -702,14 +603,14 @@ void decod_audio_ivas_fx(
{
nbits = 1; /* Q0 */
move16();
-#if 1 // def ADD_LRTD
+
test();
if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) )
{
nbits = 2; /* Q0 */
move16();
}
-#endif
+
nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */
move16();
@@ -721,7 +622,6 @@ void decod_audio_ivas_fx(
hGSCDec->cor_strong_limit = 0;
move16();
}
-#if 1 // def ADD_LRTD
ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) )
{
nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */
@@ -732,18 +632,17 @@ void decod_audio_ivas_fx(
{
nb_subfr = shl( nb_subfr, 1 ); /* Q0 */
}
-#endif
}
}
}
-#if 1
+
test();
if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) )
{
nb_subfr = NB_SUBFR16k; /* Q0 */
move16();
}
-#endif
+
/*---------------------------------------------------------------*
* Decode the last band where the adaptive (pitch) contribution is significant
*---------------------------------------------------------------*/
@@ -802,7 +701,6 @@ void decod_audio_ivas_fx(
hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */
move16();
-
/*--------------------------------------------------------------------------------------*
* Decode adaptive (pitch) excitation contribution
* Reset unvaluable part of the adaptive (pitch) excitation contribution
@@ -813,7 +711,6 @@ void decod_audio_ivas_fx(
* Decode adaptive (pitch) excitation contribution
*---------------------------------------------------------------*/
test();
-#if 1 // def ADD_LRTD
test();
test();
test();
@@ -824,9 +721,6 @@ void decod_audio_ivas_fx(
IF( !( ( st_fx->GSC_IVAS_mode > 0 ) && EQ_16( idiv1616( st_fx->L_frame, nb_subfr ), 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) &&
( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || st_fx->GSC_noisy_speech ) &&
( ( EQ_16( nb_subfr, NB_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) ) )
-#else
- IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) && EQ_16( nb_subfr, NB_SUBFR ) )
-#endif
{
Word16 indice;
nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; /* Q0 */
@@ -841,11 +735,9 @@ void decod_audio_ivas_fx(
Es_pred_dec_fx( &Es_pred, indice, nbits, 0 );
}
-#if 1 // def ADD_LRTD
+
dec_pit_exc_ivas_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
-#else
- dec_pit_exc_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf );
-#endif
+
IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
{
minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit );
@@ -977,29 +869,20 @@ void decod_audio_ivas_fx(
tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */
move16();
-#if 1 // def IVAS_CODE
+
if ( st_fx->extl_brate_orig > 0 )
-#else
- if ( st_fx->extl_brate > 0 )
-#endif
{
/* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */
tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */
}
-
test();
-#if 1 // defined ADD_LRTD
test();
if ( st_fx->coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 )
-#else
- if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) )
-#endif
{
tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); /* Q0 */
}
-#if 1 // ydef ADD_LRTD
IF( EQ_16( st_fx->idchan, 1 ) )
{
tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); /* Q0 */
@@ -1008,7 +891,7 @@ void decod_audio_ivas_fx(
tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); /* Q0 */
}
}
-#endif
+
Word16 Q_exc_old = st_fx->Q_exc;
move16();
gsc_dec_ivas_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, &st_fx->Q_exc );
@@ -1105,7 +988,6 @@ void gsc_dec_fx(
Word16 Q_exc )
{
Word16 i, j, bit, nb_subbands, pvq_len;
-#if 1 // def ADD_LRTD
Word16 bitallocation_band[MBANDS_GN_BITALLOC16k];
Word16 bitallocation_exc[2];
Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k];
@@ -1113,15 +995,6 @@ void gsc_dec_fx(
Word16 exc_diffQ[L_FRAME16k];
Word16 bits_per_bands[MBANDS_GN_BITALLOC16k];
Word16 concat_out[L_FRAME16k];
-#else
- Word16 bitallocation_band[MBANDS_GN];
- Word16 bitallocation_exc[2];
- Word16 Ener_per_bd_iQ[MBANDS_GN];
- Word16 max_ener_band[MBANDS_GN];
- Word16 exc_diffQ[L_FRAME];
- Word16 bits_per_bands[MBANDS_GN];
- Word16 concat_out[L_FRAME];
-#endif
Word16 inpulses_fx[NB_SFM];
Word16 imaxpulse_fx[NB_SFM];
Word16 mean_gain;
@@ -1145,22 +1018,7 @@ void gsc_dec_fx(
*--------------------------------------------------------------------------------------*/
bit = bits_used;
move16();
-#ifdef ADD_LRTD
- test();
- test();
- test();
- test();
- IF( EQ_16( coder_type, INACTIVE ) && ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) || EQ_16( st_fx->element_mode, IVAS_SCE ) ) && LE_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) )
- {
- bit = add( bit, GSC_LRES_NB_NITS );
- }
- IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
- {
- Mbands_gn = MBANDS_GN16k;
- move16();
- }
-#endif
set16_fx( exc_diffQ, 0, st_fx->L_frame );
/*--------------------------------------------------------------------------------------*
@@ -1184,33 +1042,8 @@ void gsc_dec_fx(
}
ELSE
{
-
-#ifdef ADD_LRTD
- i = 0;
- move16();
- While( LT_16( i, SIZE_BRATE_INTERMED_TBL ) )
- {
- IF( LQ_32( st_fx->core_brate, brate_intermed_tbl[i] ) )
- {
- break;
- }
- i = add( i, 1 );
- }
-
- test();
- test();
- test();
- test();
- IF( GT_16( st_fx->element_mode, EVS_MONO ) > &&EQ_16( coder_type, AUDIO ) &&
- LE_32( st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */
- {
- i--;
- }
- mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth );
-
-#else
mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q12 */
-#endif
+
st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */
move16();
}
@@ -1236,10 +1069,7 @@ void gsc_dec_fx(
* reduce spectral dynamic
* save spectrum
*--------------------------------------------------------------------------------------*/
-#ifdef ADD_LRTD
- max_eq = 32767;
- move16();
-#endif
+
test();
IF( EQ_16( st_fx->last_good, INACTIVE_CLAS ) || EQ_16( st_fx->Last_GSC_noisy_speech_flag, 1 ) )
{
@@ -1270,12 +1100,6 @@ void gsc_dec_fx(
max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech,
st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode );
-#ifdef ADD_LRTD
- if ( bit == 0 )
- {
- set16_fx( concact_out, 0, L_FRAME16k );
- }
-#endif
{
pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE );
Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */
@@ -1283,17 +1107,6 @@ void gsc_dec_fx(
seed_init = 0;
move16();
-#ifdef ADD_LRTD
- max_eq = 0.0f;
- max_eq_val = 1.0f;
-
- if ( ( ( st_fx->core_brate < ACELP_7k20 && st_fx->GSC_noisy_speech == 1 ) || st_fx->core_brate < 6000 ) && coder_type <= UNVOICED )
- {
- j = emaximum( concat_out, nb_subbands * 16, &max_eq );
- max_eq = (float) ( max_eq_val / ( fabs( concat_out[j] ) + 0.01f ) );
- max_eq = min( max_eq_val, max_eq );
- }
-#endif
/* Reorder Q bands */
FOR( j = 0; j < nb_subbands; j++ )
{
@@ -1350,34 +1163,8 @@ void gsc_dec_fx(
* Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal
* Gain is based on the inter-correlation gain between the pulses found and residual signal
*--------------------------------------------------------------------------------------*/
-#ifdef ADD_LRTD
- test();
- test();
- test();
- test();
- test();
- test();
- IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) )
- {
- FOR( i = 64; i < st_fx->L_frame; i++ )
- {
- PMT( "GSC FIX point to be done here" )
- exc_diffQ[i] *= max_eq;
- }
- }
- ELSE IF( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( st_fx->coder_type, UNVOICED ) )
- {
- FOR( i = 0; i < L_FRAME; i++ )
- {
- PMT( "GSC FIX point to be done here" )
- exc_diffQ[i] *= max_eq;
- }
- }
- else
-#endif
- {
- freq_dnw_scaling_fx( hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame );
- }
+
+ freq_dnw_scaling_fx( hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame );
}
/*--------------------------------------------------------------------------------------*
@@ -1432,7 +1219,6 @@ void gsc_dec_ivas_fx(
Word16 *Q_exc )
{
Word16 i, j, bit, nb_subbands, pvq_len;
-#if 1 // def ADD_LRTD
Word16 bitallocation_band[MBANDS_GN_BITALLOC16k];
Word16 bitallocation_exc[2];
Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k];
@@ -1441,19 +1227,10 @@ void gsc_dec_ivas_fx(
Word16 bits_per_bands[MBANDS_GN_BITALLOC16k];
Word16 concat_out[L_FRAME16k];
Word16 max_eq, max_eq_val;
-#else
- Word16 bitallocation_band[MBANDS_GN];
- Word16 bitallocation_exc[2];
- Word16 Ener_per_bd_iQ[MBANDS_GN];
- Word16 max_ener_band[MBANDS_GN];
- Word16 exc_diffQ[L_FRAME];
- Word16 bits_per_bands[MBANDS_GN];
- Word16 concat_out[L_FRAME];
-#endif
Word16 inpulses_fx[NB_SFM];
Word16 imaxpulse_fx[NB_SFM];
Word16 mean_gain;
- Word16 Mbands_gn = 16;
+ Word16 Mbands_gn = MBANDS_GN;
Word16 Qexc_diffQ = Q_PVQ_OUT;
Word32 L_tmp;
Word16 Q_tmp;
@@ -1461,8 +1238,8 @@ void gsc_dec_ivas_fx(
GSC_DEC_HANDLE hGSCDec;
hGSCDec = st_fx->hGSCDec;
- move16(); // for Mbands_gn
- move16(); // for Qexc_diffQ
+ move16(); /* for Mbands_gn */
+ move16(); /* for Qexc_diffQ */
set16_fx( inpulses_fx, 0, NB_SFM );
set16_fx( imaxpulse_fx, 0, NB_SFM );
@@ -1471,7 +1248,7 @@ void gsc_dec_ivas_fx(
*--------------------------------------------------------------------------------------*/
bit = bits_used;
move16();
-#if 1 // def ADD_LRTD
+
test();
test();
test();
@@ -1485,7 +1262,7 @@ void gsc_dec_ivas_fx(
Mbands_gn = MBANDS_GN16k; /* Q0 */
move16();
}
-#endif
+
set16_fx( exc_diffQ, 0, st_fx->L_frame );
/*--------------------------------------------------------------------------------------*
@@ -1509,8 +1286,6 @@ void gsc_dec_ivas_fx(
}
ELSE
{
-
-#if 1 // def ADD_LRTD
i = 0;
move16();
WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) )
@@ -1532,9 +1307,6 @@ void gsc_dec_ivas_fx(
}
mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */
-#else
- mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth );
-#endif
st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */
move16();
}
@@ -1560,17 +1332,17 @@ void gsc_dec_ivas_fx(
* reduce spectral dynamic
* save spectrum
*--------------------------------------------------------------------------------------*/
-#if 1 // def ADD_LRTD
+
max_eq = 32767;
move16();
-#endif
+
test();
IF( EQ_16( st_fx->last_good, INACTIVE_CLAS ) || EQ_16( st_fx->Last_GSC_noisy_speech_flag, 1 ) )
{
FOR( i = 0; i < st_fx->L_frame; i++ )
{
L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/
- L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */
+ L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /*Q10*/
hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/
move16();
}
@@ -1594,27 +1366,24 @@ void gsc_dec_ivas_fx(
max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech,
st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode );
-#if 1 // def ADD_LRTD
IF( bit == 0 )
{
set16_fx( concat_out, 0, L_FRAME16k );
}
-#endif
- {
- pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE );
+
+ pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE );
#ifdef MSAN_FIX
- IF( nb_subbands > 0 )
- {
- Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */
- }
-#else
+ IF( nb_subbands > 0 )
+ {
Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */
-#endif
}
+#else
+ Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */
+#endif
+
seed_init = 0;
move16();
-#if 1 // def ADD_LRTD
max_eq = 0;
move16();
max_eq_val = 32767; /* 1.0f in Q15 */
@@ -1626,7 +1395,6 @@ void gsc_dec_ivas_fx(
IF( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( coder_type, UNVOICED ) )
{
j = maximum_fx( concat_out, imult1616( nb_subbands, 16 ), &max_eq );
- // max_eq = max_eq_val / (abs_s(concat_out[j]) + 328 /*0.01f*/ );
Word16 temp_max_eq = add( abs_s( concat_out[j] ), 10 ) /*0.01f in Q10*/;
if ( LE_16( temp_max_eq, ONE_IN_Q10 ) )
{
@@ -1641,7 +1409,7 @@ void gsc_dec_ivas_fx(
max_eq = shl( max_eq, exp ); /* Q15 */
}
}
-#endif
+
/* Reorder Q bands */
FOR( j = 0; j < nb_subbands; j++ )
{
@@ -1701,7 +1469,7 @@ void gsc_dec_ivas_fx(
* Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal
* Gain is based on the inter-correlation gain between the pulses found and residual signal
*--------------------------------------------------------------------------------------*/
-#if 1 // def ADD_LRTD
+
test();
test();
test();
@@ -1710,8 +1478,6 @@ void gsc_dec_ivas_fx(
{
FOR( i = 64; i < st_fx->L_frame; i++ )
{
- // PMT("GSC FIX point to be done here")
- // exc_diffQ[i] *= max_eq;
exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); /* Q_PVQ_OUT */
move16();
}
@@ -1720,14 +1486,11 @@ void gsc_dec_ivas_fx(
{
FOR( i = 0; i < L_FRAME; i++ )
{
- // PMT("GSC FIX point to be done here")
- // exc_diffQ[i] *= max_eq;
exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); /* Q_PVQ_OUT */
move16();
}
}
ELSE
-#endif
{
freq_dnw_scaling_fx( hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame );
}
@@ -1768,17 +1531,11 @@ void GSC_dec_init(
move16();
move16();
-#ifdef ADD_LRTD
- set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k );
- set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k );
- set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN_BITALLOC16k );
- set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN_BITALLOC16k );
-#else
set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME );
set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME );
set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN );
set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN ); /*Q12*/
-#endif
+
hGSCDec->last_ener_fx = 0;
move16();
set16_fx( hGSCDec->last_bitallocation_band, 0, 6 );
diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c
index c61bf95ce2298f39e258b4d8f1a0e63a8ee639fd..ee7a7eca61bb4ef92182e732a772ae6b5c787f0f 100644
--- a/lib_dec/hf_synth_fx.c
+++ b/lib_dec/hf_synth_fx.c
@@ -7,7 +7,6 @@
#include "prot_fx.h" /* Function prototypes */
#include "rom_com.h" /* Static table prototypes */
#include "basop32.h"
-#include "prot.h"
/*---------------------------------------------------------------------*
* Local constants
diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c
index 626f25ef4861d56dfdc4a97bf817b3929084e0a2..86cf9784aa1eb3346aa7c52a16d78f7e2808f40e 100644
--- a/lib_dec/hq_core_dec_fx.c
+++ b/lib_dec/hq_core_dec_fx.c
@@ -6,7 +6,6 @@
#include "cnst.h" /* Common constants */
#include "prot_fx.h" /* Function prototypes */
#include "rom_com.h" /* Static table prototypes */
-#include "prot.h"
#include "ivas_prot_fx.h"
/*--------------------------------------------------------------------------
* hq_core_dec()
diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c
index 4f74c31ca8f1484fb0b9066555abc59658062070..907a4a350538d3c7ba7c5e5cd46bc451df007856 100644
--- a/lib_dec/igf_dec_fx.c
+++ b/lib_dec/igf_dec_fx.c
@@ -8,10 +8,9 @@
#include
#include "options.h"
#include "stl.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#include "cnst.h"
#include "stat_dec.h"
#include "basop_util.h"
diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c
deleted file mode 100644
index 2b80913050f8377570fb2b62377a6b71cdbb3d5a..0000000000000000000000000000000000000000
--- a/lib_dec/init_dec.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "cnst.h"
-#include "ivas_cnst.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-/*----------------------------------------------------------------------*
- * init_decoder()
- *
- * Initialization of static variables for the decoder
- *----------------------------------------------------------------------*/
-
-/*----------------------------------------------------------------------*
- * reset_preecho_dec()
- *
- * Initialization of static variables for pre-echo
- *----------------------------------------------------------------------*/
-
-/*----------------------------------------------------------------------*
- * destroy_cldfb_decoder_flt()
- *
- * Free memory which was allocated in init_decoder()
- *----------------------------------------------------------------------*/
-void destroy_cldfb_decoder_ivas_fx(
- Decoder_State *st /* o : Decoder static variables structure */
-)
-{
- /* CLDFB BPF & resampling tools */
- deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */
- deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */
- deleteCldfb_ivas_fx( &st->cldfbSyn ); /* delete synthesis at output sampling rate */
- deleteCldfb_ivas_fx( &st->cldfbSynHB );
-
- deleteFdCngDec_fx( &st->hFdCngDec );
-
- return;
-}
diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c
index d709ff5fcfcc2a11824bc4c07aa47688b3e0f6ec..3865cd61c5cd79904d82f4f4cac7708ad6c6e0a3 100644
--- a/lib_dec/init_dec_fx.c
+++ b/lib_dec/init_dec_fx.c
@@ -8,7 +8,6 @@
#include "rom_com.h" /* Static table prototypes */
#include "stl.h" /* required for wmc_tool */
#include "basop_util.h"
-#include "prot.h"
#include "ivas_prot_fx.h"
/*----------------------------------------------------------------------*
@@ -20,10 +19,6 @@
ivas_error init_decoder_fx(
Decoder_State *st_fx, /* o: Decoder static variables structure */
const Word16 idchan /* i : channel ID */
-#ifdef IVAS_CODE
- ,
- const MC_MODE mc_mode /* i : MC mode */
-#endif
)
{
Word16 i;
@@ -493,8 +488,8 @@ ivas_error init_decoder_fx(
set16_fx( st_fx->hTcxDec->FBTCXdelayBuf, 0, 111 );
- st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA( st_fx->output_Fs, PH_ECU_MEM_NS );
- st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS );
+ st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS );
+ st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS );
}
ELSE
{
@@ -536,11 +531,7 @@ ivas_error init_decoder_fx(
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) );
}
- td_bwe_dec_init_fx( st_fx, st_fx->hBWE_TD,
-#ifdef ADD_IVAS_BWE
- st_fx->extl,
-#endif
- st_fx->output_Fs );
+ td_bwe_dec_init_fx( st_fx, st_fx->hBWE_TD, st_fx->output_Fs );
#ifdef MSAN_FIX
st_fx->hBWE_TD->prev_hb_synth_fx_exp = 31;
@@ -778,11 +769,7 @@ ivas_error init_decoder_fx(
resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 1 );
test();
-#ifdef IVAS_CODE
- IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) // TBV Fixed point missing
-#else
IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ )
-#endif
{
/* Create FD_CNG instance */
@@ -1822,3 +1809,18 @@ void destroy_cldfb_decoder_fx(
return;
}
+
+void destroy_cldfb_decoder_ivas_fx(
+ Decoder_State *st /* o : Decoder static variables structure */
+)
+{
+ /* CLDFB BPF & resampling tools */
+ deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */
+ deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */
+ deleteCldfb_ivas_fx( &st->cldfbSyn ); /* delete synthesis at output sampling rate */
+ deleteCldfb_ivas_fx( &st->cldfbSynHB );
+
+ deleteFdCngDec_fx( &st->hFdCngDec );
+
+ return;
+}
diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c
index ef65c4fcd20fd8f3af216ccf3b7ff5df989c275b..1ab1efe8fa8c587a2494997818d9694b6cc63a71 100644
--- a/lib_dec/inov_dec_fx.c
+++ b/lib_dec/inov_dec_fx.c
@@ -113,7 +113,7 @@ void inov_decode_fx(
move16();
bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0
move16();
- // PMT("CONDITION above is missing -> idchan")
+
FOR( i = 0; i < wordcnt; i++ )
{
indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, 16 ) ); // Q0
@@ -298,7 +298,7 @@ void inov_decode_ivas_fx(
move16();
bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0
move16();
- // PMT("CONDITION above is missing -> idchan")
+
FOR( i = 0; i < wordcnt; i++ )
{
indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); // Q0
diff --git a/lib_dec/ivas_agc_dec_fx.c b/lib_dec/ivas_agc_dec_fx.c
index f5418abc658150e90f9d9b5f98dd073fd8581089..e73d89158436a2a12bf93f0dad35cf4195458fff 100644
--- a/lib_dec/ivas_agc_dec_fx.c
+++ b/lib_dec/ivas_agc_dec_fx.c
@@ -34,7 +34,6 @@
#include
#include
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal_fx.c
similarity index 97%
rename from lib_dec/ivas_binRenderer_internal.c
rename to lib_dec/ivas_binRenderer_internal_fx.c
index d1620026df32b3890a36b68e1dc6e537092feba2..e3a66da49a0fcd61de41b62c008ece0f80c8d751 100644
--- a/lib_dec/ivas_binRenderer_internal.c
+++ b/lib_dec/ivas_binRenderer_internal_fx.c
@@ -33,7 +33,7 @@
#include
#include "options.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
#include "cnst.h"
@@ -43,7 +43,6 @@
#include "ivas_rom_com.h"
#include "ivas_rom_binauralRenderer.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com_fx.h"
#include "debug.h"
@@ -73,9 +72,17 @@ static void ivas_binRenderer_filterModule_fx(
{
Word16 bandIdx, k, chIdx, tapIdx;
Word32 *filterStatesLeftRealPtr_fx, *filterStatesLeftImagPtr_fx;
+#ifdef OPT_BASOP_ADD_v1
+ Word16 Q_filterStates;
+#else /* OPT_BASOP_ADD_v1 */
Word16 *Q_filterStates;
+#endif /* OPT_BASOP_ADD_v1 */
const Word32 *filterTapsLeftRealPtr_fx, *filterTapsLeftImagPtr_fx, *filterTapsRightRealPtr_fx, *filterTapsRightImagPtr_fx;
Word16 shift_q;
+#ifdef OPT_BASOP_ADD_v1
+ Q_filterStates = hBinRenderer->hBinRenConvModule->Q_filterStatesLeft;
+ move16();
+#endif /* OPT_BASOP_ADD_v1 */
FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
{
@@ -88,8 +95,9 @@ static void ivas_binRenderer_filterModule_fx(
#else
filterStatesLeftRealPtr_fx = (Word32 *) &( hBinRenderer->hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx][0] );
filterStatesLeftImagPtr_fx = (Word32 *) &( hBinRenderer->hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx][0] );
+#ifndef OPT_BASOP_ADD_v1
Q_filterStates = (Word16 *) &( hBinRenderer->hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx][0] );
-#endif
+#endif /* OPT_BASOP_ADD_v1 */
filterTapsLeftRealPtr_fx = hBinRenderer->hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx]; // Q29
filterTapsLeftImagPtr_fx = hBinRenderer->hBinRenConvModule->filterTapsLeftImag_fx[bandIdx][chIdx]; // Q29
@@ -111,39 +119,59 @@ static void ivas_binRenderer_filterModule_fx(
filterStatesLeftImagPtr_fx[tapIdx] = filterStatesLeftImagPtr_fx[tapIdx - 1];
move32();
+#ifndef OPT_BASOP_ADD_v1
shift_q = sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] );
outRealLeft_fx = W_shr( outRealLeft_fx, shift_q );
outImagLeft_fx = W_shr( outImagLeft_fx, shift_q );
outRealRight_fx = W_shr( outRealRight_fx, shift_q );
outImagRight_fx = W_shr( outImagRight_fx, shift_q );
+#endif /* OPT_BASOP_ADD_v1 */
- outRealLeft_fx = W_mac_32_32( outRealLeft_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsLeftRealPtr_fx[tapIdx] );
- outRealLeft_fx = W_mac_32_32( outRealLeft_fx, L_negate( filterStatesLeftImagPtr_fx[tapIdx] ), filterTapsLeftImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates[tapIdx - 1]
+ outRealLeft_fx = W_mac_32_32( outRealLeft_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsLeftRealPtr_fx[tapIdx] ); // Q30 + Q_filterStates
+ outRealLeft_fx = W_mac_32_32( outRealLeft_fx, L_negate( filterStatesLeftImagPtr_fx[tapIdx] ), filterTapsLeftImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates
- outImagLeft_fx = W_mac_32_32( outImagLeft_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsLeftImagPtr_fx[tapIdx] );
- outImagLeft_fx = W_mac_32_32( outImagLeft_fx, filterStatesLeftImagPtr_fx[tapIdx], filterTapsLeftRealPtr_fx[tapIdx] );
+ outImagLeft_fx = W_mac_32_32( outImagLeft_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsLeftImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates
+ outImagLeft_fx = W_mac_32_32( outImagLeft_fx, filterStatesLeftImagPtr_fx[tapIdx], filterTapsLeftRealPtr_fx[tapIdx] ); // Q30 + Q_filterStates
- outRealRight_fx = W_mac_32_32( outRealRight_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsRightRealPtr_fx[tapIdx] );
- outRealRight_fx = W_mac_32_32( outRealRight_fx, L_negate( filterStatesLeftImagPtr_fx[tapIdx] ), filterTapsRightImagPtr_fx[tapIdx] );
-
- outImagRight_fx = W_mac_32_32( outImagRight_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsRightImagPtr_fx[tapIdx] );
- outImagRight_fx = W_mac_32_32( outImagRight_fx, filterStatesLeftImagPtr_fx[tapIdx], filterTapsRightRealPtr_fx[tapIdx] );
+ outRealRight_fx = W_mac_32_32( outRealRight_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsRightRealPtr_fx[tapIdx] ); // Q30 + Q_filterStates
+ outRealRight_fx = W_mac_32_32( outRealRight_fx, L_negate( filterStatesLeftImagPtr_fx[tapIdx] ), filterTapsRightImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates
+ outImagRight_fx = W_mac_32_32( outImagRight_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsRightImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates
+ outImagRight_fx = W_mac_32_32( outImagRight_fx, filterStatesLeftImagPtr_fx[tapIdx], filterTapsRightRealPtr_fx[tapIdx] ); // Q30 + Q_filterStates
+#ifndef OPT_BASOP_ADD_v1
Q_filterStates[tapIdx] = Q_filterStates[tapIdx - 1];
move16();
+#endif /* OPT_BASOP_ADD_v1 */
}
+
+#ifdef OPT_BASOP_ADD_v1
+ shift_q = add( sub( Q_filterStates, Q_curr ), 1 );
+#else /* OPT_BASOP_ADD_v1 */
shift_q = add( sub( Q_filterStates[1], Q_curr ), 1 );
- outRealLeft_fx = W_shr( outRealLeft_fx, shift_q );
- outImagLeft_fx = W_shr( outImagLeft_fx, shift_q );
- outRealRight_fx = W_shr( outRealRight_fx, shift_q );
- outImagRight_fx = W_shr( outImagRight_fx, shift_q );
+#endif /* OPT_BASOP_ADD_v1 */
+
+#ifdef OPT_BASOP_ADD_v1
+ IF( shift_q != 0 )
+ {
+#endif /* OPT_BASOP_ADD_v1 */
+ outRealLeft_fx = W_shr( outRealLeft_fx, shift_q ); // Q_curr
+ outImagLeft_fx = W_shr( outImagLeft_fx, shift_q ); // Q_curr
+ outRealRight_fx = W_shr( outRealRight_fx, shift_q ); // Q_curr
+ outImagRight_fx = W_shr( outImagRight_fx, shift_q ); // Q_curr
+#ifdef OPT_BASOP_ADD_v1
+ hBinRenderer->hBinRenConvModule->Q_filterStatesLeft = Q_curr;
+ move16();
+ }
+#endif /* OPT_BASOP_ADD_v1 */
filterStatesLeftRealPtr_fx[0] = CLDFB_real[chIdx][k][bandIdx];
move32();
filterStatesLeftImagPtr_fx[0] = CLDFB_imag[chIdx][k][bandIdx];
move32();
+#ifndef OPT_BASOP_ADD_v1
Q_filterStates[0] = Q_curr;
move16();
+#endif /* OPT_BASOP_ADD_v1 */
/* Left Real and Imag */
@@ -408,10 +436,12 @@ static ivas_error ivas_binRenderer_convModuleOpen(
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
}
+#ifndef OPT_BASOP_ADD_v1
IF( ( hBinRenConvModule->Q_filterStatesLeft = (Word16 ***) malloc( hBinRenderer->conv_band * sizeof( Word16 ** ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
}
+#endif /* OPT_BASOP_ADD_v1 */
FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
{
@@ -425,10 +455,12 @@ static ivas_error ivas_binRenderer_convModuleOpen(
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
}
+#ifndef OPT_BASOP_ADD_v1
IF( ( hBinRenConvModule->Q_filterStatesLeft[bandIdx] = (Word16 **) malloc( hBinRenderer->nInChannels * sizeof( Word16 * ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
}
+#endif /* OPT_BASOP_ADD_v1 */
FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ )
{
@@ -442,10 +474,12 @@ static ivas_error ivas_binRenderer_convModuleOpen(
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
}
+#ifndef OPT_BASOP_ADD_v1
IF( ( hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx] = (Word16 *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( Word16 ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
}
+#endif /* OPT_BASOP_ADD_v1 */
}
}
#endif
@@ -492,8 +526,12 @@ static ivas_error ivas_binRenderer_convModuleOpen(
#ifndef SPLIT_REND_WITH_HEAD_ROT
set32_fx( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] );
set32_fx( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] );
+#ifdef OPT_BASOP_ADD_v1
+ hBinRenConvModule->Q_filterStatesLeft = 31;
+ move16();
+#else /* OPT_BASOP_ADD_v1 */
set16_fx( hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx], 31, hBinRenConvModule->numTapsArray[bandIdx] );
-#endif
+#endif /* OPT_BASOP_ADD_v1 */
IF( isLoudspeaker )
{
hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftBRIRReal_fx[bandIdx][tmp];
@@ -508,8 +546,12 @@ static ivas_error ivas_binRenderer_convModuleOpen(
/* set the memories to zero */
set32_fx( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTaps );
set32_fx( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTaps );
+#ifdef OPT_BASOP_ADD_v1
+ hBinRenConvModule->Q_filterStatesLeft = 31;
+ move16();
+#else /* OPT_BASOP_ADD_v1 */
set16_fx( hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx], 31, hBinRenConvModule->numTaps );
-#endif
+#endif /* OPT_BASOP_ADD_v1 */
IF( isLoudspeaker )
{
hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_fx[bandIdx][tmp];
@@ -1585,8 +1627,10 @@ static void ivas_binRenderer_convModuleClose_fx(
free( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx] );
hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx] = NULL;
+#ifndef OPT_BASOP_ADD_v1
free( hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx] );
hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx] = NULL;
+#endif /* OPT_BASOP_ADD_v1 */
}
free( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx] );
@@ -1595,8 +1639,10 @@ static void ivas_binRenderer_convModuleClose_fx(
free( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx] );
hBinRenConvModule->filterStatesLeftImag_fx[bandIdx] = NULL;
+#ifndef OPT_BASOP_ADD_v1
free( hBinRenConvModule->Q_filterStatesLeft[bandIdx] );
hBinRenConvModule->Q_filterStatesLeft[bandIdx] = NULL;
+#endif /* OPT_BASOP_ADD_v1 */
}
#endif
free( hBinRenConvModule->filterStatesLeftReal_fx );
@@ -1605,8 +1651,10 @@ static void ivas_binRenderer_convModuleClose_fx(
free( hBinRenConvModule->filterStatesLeftImag_fx );
hBinRenConvModule->filterStatesLeftImag_fx = NULL;
+#ifndef OPT_BASOP_ADD_v1
free( hBinRenConvModule->Q_filterStatesLeft );
hBinRenConvModule->Q_filterStatesLeft = NULL;
+#endif /* OPT_BASOP_ADD_v1 */
free( ( *hBinRenderer )->hBinRenConvModule );
( *hBinRenderer )->hBinRenConvModule = NULL;
diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_core_dec.c
rename to lib_dec/ivas_core_dec_fx.c
index 92b43092b8a4355de0913c6fd026333ae38900c5..5bb4736e9b534b3baf30eb66a01ea3bf26dcae1b 100644
--- a/lib_dec/ivas_core_dec.c
+++ b/lib_dec/ivas_core_dec_fx.c
@@ -36,12 +36,11 @@
#include
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
@@ -1639,15 +1638,15 @@ ivas_error ivas_core_dec_fx(
move16();
move16();
- Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -( Q11 ) ); // Q0
+ Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -( Q11 ) ); // Q0
st->q_prev_synth_buffer_fx = 0;
move16();
exp_ouput = Find_Max_Norm32( output_32_fx[n], output_frame );
exp_ouput = add( exp_ouput, Q11 );
- exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
+ exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
exp_prev_synth_buffer = add( exp_prev_synth_buffer, st->q_prev_synth_buffer_fx );
- exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), sub( add( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ) );
+ exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), sub( add( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ), NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ) );
exp_delay_buf_out = Find_Max_Norm16( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) );
exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ) );
exp_max = s_min( exp_synth_history, exp_ouput );
@@ -1660,7 +1659,7 @@ ivas_error ivas_core_dec_fx(
Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); // Q(31-exp_max)
Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); // exp_max
Scale_sig( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); // Q(31-exp_max)
- Scale_sig( st->prev_synth_buffer_fx, NS2SA_FX2( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); // Q(exp_max - prev_synth_buffer_fx)
+ Scale_sig( st->prev_synth_buffer_fx, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); // Q(exp_max - prev_synth_buffer_fx)
Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, 0 ) ); // Q(31-exp_max)
st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx );
diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig_fx.c
similarity index 99%
rename from lib_dec/ivas_corecoder_dec_reconfig.c
rename to lib_dec/ivas_corecoder_dec_reconfig_fx.c
index 89ca9a5ba322dd43247aa6d06e921444a4461c3d..697f9d7154ba31dd49d74dc60ba3deaa39366d1a 100644
--- a/lib_dec/ivas_corecoder_dec_reconfig.c
+++ b/lib_dec/ivas_corecoder_dec_reconfig_fx.c
@@ -35,7 +35,6 @@
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
#include "prot_fx.h"
-#include "prot.h"
#include
#include "wmc_auto.h"
diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c
index c22c617c075b377a741849e82fc8379c8237b032..9bf53f1de04643c3e6da7c41c4c8c14bd3edee57 100644
--- a/lib_dec/ivas_cpe_dec_fx.c
+++ b/lib_dec/ivas_cpe_dec_fx.c
@@ -36,10 +36,9 @@
#include "cnst.h"
#include "ivas_cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#include
diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_decision_matrix_dec.c
rename to lib_dec/ivas_decision_matrix_dec_fx.c
index a8c151edb34868f138aef7a5fb254ea0f60c016f..f7fd5e8e253b706595d3a1a793cd1f7618f241d9 100644
--- a/lib_dec/ivas_decision_matrix_dec.c
+++ b/lib_dec/ivas_decision_matrix_dec_fx.c
@@ -35,11 +35,10 @@
#include "stat_dec.h"
#include "rom_com.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_cnst.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*-----------------------------------------------------------------*
* ivas_decision_matrix_dec()
diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_dirac_dec.c
rename to lib_dec/ivas_dirac_dec_fx.c
index 560a1b43f8fcd9c5ebed6b7e4cb9198f311f459f..43f804824227cbc31809de2cb2f7447d501343ca 100644
--- a/lib_dec/ivas_dirac_dec.c
+++ b/lib_dec/ivas_dirac_dec_fx.c
@@ -35,7 +35,7 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
#include "ivas_cnst.h"
@@ -43,7 +43,6 @@
#include "ivas_rom_dec.h"
#include "ivas_rom_rend.h"
#include "wmc_auto.h"
-#include "prot_fx.h" /* Function prototypes */
#include "ivas_rom_com_fx.h"
#include "ivas_prot_fx.h"
@@ -2155,7 +2154,7 @@ void ivas_dirac_dec_render_fx(
output_f_local_fx[ch] = output_f_local_buff_fx[ch];
set_zero_fx( output_f_local_fx[ch], nSamplesAsked );
}
- slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL
+ slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL
/* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov_fx.c
similarity index 92%
rename from lib_dec/ivas_dirac_output_synthesis_cov.c
rename to lib_dec/ivas_dirac_output_synthesis_cov_fx.c
index 13d8fc940a625213ddf73eecc73693fed23bef9f..e03913f8ab73138dc9701de680eb2151c2ef5610 100644
--- a/lib_dec/ivas_dirac_output_synthesis_cov.c
+++ b/lib_dec/ivas_dirac_output_synthesis_cov_fx.c
@@ -40,7 +40,7 @@
#include "cnst.h"
#include "rom_enc.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_stat_dec.h"
#include "ivas_cnst.h"
@@ -48,7 +48,6 @@
#include "ivas_rom_dec.h"
#include "wmc_auto.h"
#include "rom_dec.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
@@ -725,7 +724,11 @@ Word16 computeMixingMatrices_fx(
Word32 G_hat_fx[MAX_OUTPUT_CHANNELS];
Word16 G_hat_buff_e[MAX_OUTPUT_CHANNELS];
+#ifdef OPT_BASOP_ADD_v1
+ Word16 mat_mult_buffer2_e, mat_mult_buffer3_e;
+#else /* OPT_BASOP_ADD_v1 */
Word16 mat_mult_buffer1_e, mat_mult_buffer2_e, mat_mult_buffer3_e;
+#endif /* OPT_BASOP_ADD_v1 */
Word32 mat_mult_buffer3_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
@@ -775,7 +778,9 @@ Word16 computeMixingMatrices_fx(
mat2svdMat_fx( Cy_fx, svd_in_buffer_fx, lengthCy, lengthCy, 0 );
svd_fx( svd_in_buffer_fx, Cy_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, svd_s_buffer_e, lengthCy, lengthCy );
-
+#ifdef OPT_BASOP_ADD_v1
+ Word16 max_e = -32;
+#endif /* OPT_BASOP_ADD_v1 */
/* Computing Ky */
FOR( i = 0; i < lengthCy; ++i )
{
@@ -788,8 +793,20 @@ Word16 computeMixingMatrices_fx(
move32();
Ky_fx_e[i + ( j * lengthCy )] = tmp_e;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ max_e = s_max( max_e, tmp_e );
+#endif /* OPT_BASOP_ADD_v1 */
}
}
+#ifdef OPT_BASOP_ADD_v1
+ FOR( i = 0; i < lengthCy * lengthCy; ++i )
+ {
+ Ky_fx[i] = L_shr( Ky_fx[i], sub( max_e, Ky_fx_e[i] ) );
+ move32();
+ Ky_fx_e[i] = max_e;
+ move16();
+ }
+#endif /* OPT_BASOP_ADD_v1 */
/*-----------------------------------------------------------------*
* Decomposition of Cx
@@ -800,7 +817,9 @@ Word16 computeMixingMatrices_fx(
mat2svdMat_fx( Cx_fx, svd_in_buffer_fx, lengthCx, lengthCx, 0 );
svd_fx( svd_in_buffer_fx, Cx_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, svd_s_buffer_e, lengthCx, lengthCx );
-
+#ifdef OPT_BASOP_ADD_v1
+ max_e = -32;
+#endif /* OPT_BASOP_ADD_v1 */
FOR( i = 0; i < lengthCx; ++i )
{
FOR( j = 0; j < lengthCx; ++j )
@@ -812,9 +831,20 @@ Word16 computeMixingMatrices_fx(
move32();
Kx_fx_e[( i + ( j * lengthCx ) )] = tmp_e;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ max_e = s_max( max_e, tmp_e );
+#endif /* OPT_BASOP_ADD_v1 */
}
}
-
+#ifdef OPT_BASOP_ADD_v1
+ FOR( i = 0; i < lengthCx * lengthCx; ++i )
+ {
+ Kx_fx[i] = L_shr( Kx_fx[i], sub( max_e, Kx_fx_e[i] ) );
+ move32();
+ Kx_fx_e[i] = max_e;
+ move16();
+ }
+#endif /* OPT_BASOP_ADD_v1 */
FOR( i = 0; i < lengthCx; ++i )
{
@@ -938,14 +968,25 @@ Word16 computeMixingMatrices_fx(
/* Computing the input matrix Kx'*Q'*G_hat'*Ky */
+#ifdef OPT_BASOP_ADD_v1
+ Word16 mat_mult_buffer1_fx_e;
+#else /* OPT_BASOP_ADD_v1 */
Word16 mat_mult_buffer1_fx_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
Word16 Q_e_arr[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS];
set16_fx( Q_e_arr, Q_e, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
matrix_product_mant_exp( Kx_fx, Kx_fx_e, lengthCx, lengthCx, 1, Q_fx, Q_e_arr, lengthCy, lengthCx, 1, mat_mult_buffer1_fx, mat_mult_buffer1_fx_e );
+#endif /* OPT_BASOP_ADD_v1 */
Word16 mat_mult_buffer2_fx_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
+#ifdef OPT_BASOP_ADD_v1
+ matrix_product_mant_exp_fx( Kx_fx, Kx_fx_e[0], lengthCx, lengthCx, 1, Q_fx, Q_e, lengthCy, lengthCx, 1, mat_mult_buffer1_fx, &mat_mult_buffer1_fx_e );
+
+ matrix_diag_product_fx_2( mat_mult_buffer1_fx, mat_mult_buffer1_fx_e, lengthCx, lengthCy, 0, G_hat_fx, G_hat_buff_e, lengthCy, mat_mult_buffer2_fx, mat_mult_buffer2_fx_e );
+
+ matrix_product_mant_exp_fx( mat_mult_buffer2_fx, mat_mult_buffer2_fx_e[0], lengthCx, lengthCy, 0, Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_fx_e );
+#else /* OPT_BASOP_ADD_v1 */
matrix_diag_product_fx_1( mat_mult_buffer1_fx, mat_mult_buffer1_fx_e, lengthCx, lengthCy, 0, G_hat_fx, G_hat_buff_e, lengthCy, mat_mult_buffer2_fx, mat_mult_buffer2_fx_e );
matrix_product_mant_exp( mat_mult_buffer2_fx, mat_mult_buffer2_fx_e, lengthCx, lengthCy, 0, Ky_fx, Ky_fx_e, lengthCy, lengthCy, 0, mat_mult_buffer1_fx, mat_mult_buffer1_fx_e );
@@ -969,6 +1010,7 @@ Word16 computeMixingMatrices_fx(
mat_mult_buffer1_e = exp;
move16();
+#endif /* OPT_BASOP_ADD_v1 */
IF( LT_16( lengthCx, lengthCy ) )
{
@@ -977,7 +1019,11 @@ Word16 computeMixingMatrices_fx(
move16();
nC = lengthCx;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ svd_fx( svd_in_buffer_fx, mat_mult_buffer1_fx_e, svd_v_buffer_fx, svd_s_buffer_fx, svd_u_buffer_fx, svd_s_buffer_e, nL, nC );
+#else /* OPT_BASOP_ADD_v1 */
svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_v_buffer_fx, svd_s_buffer_fx, svd_u_buffer_fx, svd_s_buffer_e, nL, nC );
+#endif /* OPT_BASOP_ADD_v1 */
}
ELSE
{
@@ -986,7 +1032,11 @@ Word16 computeMixingMatrices_fx(
move16();
nC = lengthCy;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ svd_fx( svd_in_buffer_fx, mat_mult_buffer1_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, svd_s_buffer_e, nL, nC );
+#else /* OPT_BASOP_ADD_v1 */
svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, svd_s_buffer_e, nL, nC );
+#endif /* OPT_BASOP_ADD_v1 */
}
/* Actually Processing P */
@@ -997,25 +1047,46 @@ Word16 computeMixingMatrices_fx(
svdMat2mat_fx( svd_v_buffer_fx, mat_mult_buffer1_fx, lengthCy, lengthCx );
svdMat2mat_fx( svd_u_buffer_fx, mat_mult_buffer2_fx, lengthCx, lengthCx );
+#ifdef OPT_BASOP_ADD_v1
+ mat_mult_buffer1_fx_e = 0;
+#else /* OPT_BASOP_ADD_v1 */
mat_mult_buffer1_e = 0;
+#endif /* OPT_BASOP_ADD_v1 */
move16();
mat_mult_buffer2_e = 0;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_fx_e, lengthCy, lengthCx, 0,
+ mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1,
+ mat_mult_buffer3_fx, &mat_mult_buffer3_e );
+#else /* OPT_BASOP_ADD_v1 */
matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0,
mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1,
mat_mult_buffer3_fx, &mat_mult_buffer3_e );
+#endif /* OPT_BASOP_ADD_v1 */
/************************ Formulate M **********************/
+#ifdef OPT_BASOP_ADD_v1
+ matrix_product_mant_exp_fx( Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer3_fx, mat_mult_buffer3_e, lengthCy, lengthCx, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_fx_e );
+#else /* OPT_BASOP_ADD_v1 */
Word16 mat_mult_buffer3_fx_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
set16_fx( mat_mult_buffer3_fx_e, mat_mult_buffer3_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
matrix_product_mant_exp( Ky_fx, Ky_fx_e, lengthCy, lengthCy, 0, mat_mult_buffer3_fx, mat_mult_buffer3_fx_e, lengthCy, lengthCx, 0, mat_mult_buffer1_fx, mat_mult_buffer1_fx_e );
+#endif /* OPT_BASOP_ADD_v1 */
Word16 mixing_matrix_fx_e[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
+#ifdef OPT_BASOP_ADD_v1
+ Word16 mat_mult_buffer1_fx_e1[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
+ set16_fx( mat_mult_buffer1_fx_e1, mat_mult_buffer1_fx_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
+
+ matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_fx_e1, lengthCy, lengthCx, 0, Kx_reg_inv_fx, Kx_reg_inv_e, lengthCx, lengthCx, 0, mixing_matrix_fx, mixing_matrix_fx_e );
+#else /* OPT_BASOP_ADD_v1 */
matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_fx_e, lengthCy, lengthCx, 0, Kx_reg_inv_fx, Kx_reg_inv_e, lengthCx, lengthCx, 0, mixing_matrix_fx, mixing_matrix_fx_e );
+#endif /* OPT_BASOP_ADD_v1 */
/*-----------------------------------------------------------------*
* Formulate Cr
@@ -1026,9 +1097,15 @@ Word16 computeMixingMatrices_fx(
Word16 Cx_e_arr[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
set16_fx( Cx_e_arr, Cx_fx_e, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
+#ifdef OPT_BASOP_ADD_v1
+ matrix_product_mant_exp( mixing_matrix_fx, mixing_matrix_fx_e, lengthCy, lengthCx, 0, Cx_fx, Cx_e_arr, lengthCx, lengthCx, 0, mat_mult_buffer1_fx, mat_mult_buffer1_fx_e1 );
+
+ matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_fx_e1, lengthCy, lengthCx, 0, mixing_matrix_fx, mixing_matrix_fx_e, lengthCy, lengthCx, 1, mat_mult_buffer2_fx, mat_mult_buffer2_fx_e );
+#else /* OPT_BASOP_ADD_v1 */
matrix_product_mant_exp( mixing_matrix_fx, mixing_matrix_fx_e, lengthCy, lengthCx, 0, Cx_fx, Cx_e_arr, lengthCx, lengthCx, 0, mat_mult_buffer1_fx, mat_mult_buffer1_fx_e );
matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_fx_e, lengthCy, lengthCx, 0, mixing_matrix_fx, mixing_matrix_fx_e, lengthCy, lengthCx, 1, mat_mult_buffer2_fx, mat_mult_buffer2_fx_e );
+#endif /* OPT_BASOP_ADD_v1 */
exp = mixing_matrix_fx_e[0];
move16();
@@ -1067,7 +1144,11 @@ Word16 computeMixingMatrices_fx(
}
/* Avoid Meaningless negative main diagonal elements */
+#ifdef OPT_BASOP_ADD_v1
+ IF( Cr_fx[i + ( i * lengthCy )] < 0 )
+#else /* OPT_BASOP_ADD_v1 */
IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[i + ( i * lengthCy )], exp, 0, 0 ) < 0 )
+#endif /* OPT_BASOP_ADD_v1 */
{
Cr_fx[i + ( i * lengthCy )] = 0;
move32();
@@ -1129,7 +1210,11 @@ Word16 computeMixingMatrices_fx(
{
/* Avoid correction for very small energies,
main diagonal elements of Cy_tilde_p may be negative */
+#ifdef OPT_BASOP_ADD_v1
+ IF( Cy_tilde_p_fx[i + ( i * lengthCy )] < 0 )
+#else /* OPT_BASOP_ADD_v1 */
IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[i + ( i * lengthCy )], mat_mult_buffer2_e, 0, 0 ) < 0 )
+#endif /* OPT_BASOP_ADD_v1 */
{
adj_fx_p[i] = 1073741824; // 1.0f in Q30
move32();
@@ -1148,7 +1233,12 @@ Word16 computeMixingMatrices_fx(
move16();
}
+#ifdef OPT_BASOP_ADD_v1
+ Word32 temp = W_shl_sat_l( W_deposit32_l( 4 ), sub( 31, adj_e[i] ) );
+ IF( GT_32( adj_fx_p[i], temp ) )
+#else /* OPT_BASOP_ADD_v1 */
IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], adj_e[i], 1073741824, 3 ) > 0 )
+#endif /* OPT_BASOP_ADD_v1 */
{
adj_fx_p[i] = 1073741824; // 1.0f in Q30
move32();
@@ -1281,6 +1371,9 @@ Word16 computeMixingMatricesResidual_fx(
svd_fx( svd_in_buffer_fx, Cy_fx_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, svd_s_buffer_e, lengthCy, lengthCy );
/* Computing Ky */
+#ifdef OPT_BASOP_ADD_v1
+ Word16 max_e = -32;
+#endif /* OPT_BASOP_ADD_v1 */
FOR( i = 0; i < lengthCy; ++i )
{
FOR( j = 0; j < lengthCy; ++j )
@@ -1292,9 +1385,22 @@ Word16 computeMixingMatricesResidual_fx(
move32();
Ky_fx_e[i + j * lengthCy] = tmp_e;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ max_e = s_max( max_e, tmp_e );
+#endif /* OPT_BASOP_ADD_v1 */
}
}
+#ifdef OPT_BASOP_ADD_v1
+ FOR( i = 0; i < lengthCy * lengthCy; ++i )
+ {
+ Ky_fx[i] = L_shr( Ky_fx[i], sub( max_e, Ky_fx_e[i] ) );
+ move32();
+ Ky_fx_e[i] = max_e;
+ move16();
+ }
+#endif /* OPT_BASOP_ADD_v1 */
+
/*-----------------------------------------------------------------*
* Decomposition of Cx
*-----------------------------------------------------------------*/
@@ -1305,7 +1411,9 @@ Word16 computeMixingMatricesResidual_fx(
* square root of the diagonal of Cx */
/* Computing Kx */
-
+#ifdef OPT_BASOP_ADD_v1
+ max_e = -32;
+#endif /* OPT_BASOP_ADD_v1 */
FOR( i = 0; i < lengthCx; ++i )
{
exp = Cx_e;
@@ -1314,24 +1422,46 @@ Word16 computeMixingMatricesResidual_fx(
move32();
Kx_fx_e[i] = exp;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ max_e = s_max( max_e, exp );
+#endif /* OPT_BASOP_ADD_v1 */
}
+#ifdef OPT_BASOP_ADD_v1
+ FOR( i = 0; i < lengthCx; ++i )
+ {
+ Kx_fx[i] = L_shr( Kx_fx[i], sub( max_e, Kx_fx_e[i] ) );
+ move32();
+ Kx_fx_e[i] = max_e;
+ move16();
+ }
+#endif /* OPT_BASOP_ADD_v1 */
+
/*-----------------------------------------------------------------*
* Regularization of Sx
*-----------------------------------------------------------------*/
limit_fx = Kx_fx[0];
move32();
+#ifndef OPT_BASOP_ADD_v1
limit_e = Kx_fx_e[0];
move16();
+#endif /* OPT_BASOP_ADD_v1 */
+
FOR( i = 1; i < lengthCx; i++ )
{
+#ifdef OPT_BASOP_ADD_v1
+ IF( GT_32( Kx_fx[i], limit_fx ) )
+#else /* OPT_BASOP_ADD_v1 */
IF( BASOP_Util_Cmp_Mant32Exp( Kx_fx[i], Kx_fx_e[i], limit_fx, limit_e ) > 0 )
+#endif /* OPT_BASOP_ADD_v1 */
{
limit_fx = Kx_fx[i];
move32();
+#ifndef OPT_BASOP_ADD_v1
limit_e = Kx_fx_e[i];
move16();
+#endif /* OPT_BASOP_ADD_v1 */
}
}
@@ -1339,7 +1469,11 @@ Word16 computeMixingMatricesResidual_fx(
L_tmp = L_add( L_tmp, EPSILLON_FX );
limit_fx = L_tmp;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ limit_e = add( Kx_fx_e[0], reg_Sx_e );
+#else /* OPT_BASOP_ADD_v1 */
limit_e = add( limit_e, reg_Sx_e );
+#endif /* OPT_BASOP_ADD_v1 */
FOR( i = 0; i < lengthCx; ++i )
{
@@ -1488,10 +1622,16 @@ Word16 computeMixingMatricesResidual_fx(
* Formulate M
*-----------------------------------------------------------------*/
+
+#ifdef OPT_BASOP_ADD_v1
+ matrix_product_mant_exp_fx( Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer3_fx, mat_mult_buffer3_e, lengthCy, lengthCx, 0, mat_mult_buffer1_fx, mat_mult_buffer1_buff_e );
+ set16_fx( mat_mult_buffer1_buff_e, mat_mult_buffer1_buff_e[0], MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
+#else /* OPT_BASOP_ADD_v1 */
Word16 mat_mult_buffer3_fx_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
set16_fx( mat_mult_buffer3_fx_e, mat_mult_buffer3_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
matrix_product_mant_exp( Ky_fx, Ky_fx_e, lengthCy, lengthCy, 0, mat_mult_buffer3_fx, mat_mult_buffer3_fx_e, lengthCy, lengthCx, 0, mat_mult_buffer1_fx, mat_mult_buffer1_buff_e );
+#endif /* OPT_BASOP_ADD_v1 */
Word16 mixing_matrix_fx_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
@@ -1576,7 +1716,12 @@ Word16 computeMixingMatricesResidual_fx(
move32();
adj_buff_e[i] = scale;
move16();
+#ifdef OPT_BASOP_ADD_v1
+ Word32 temp = W_shl_sat_l( W_deposit32_l( 4 ), sub( 31, scale ) );
+ IF( GT_32( adj_fx_p[i], temp ) ) // 1073741824 -> 1.0f in Q30
+#else /* OPT_BASOP_ADD_v1 */
IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) // 1073741824 -> 1.0f in Q30
+#endif /* OPT_BASOP_ADD_v1 */
{
adj_fx_p[i] = 1073741824; // 1.0f in Q30
move32();
@@ -1971,7 +2116,12 @@ Word16 computeMixingMatricesISM_fx(
}
}
+#ifdef OPT_BASOP_ADD_v1
+ Word32 temp = W_shl_sat_l( W_deposit32_l( 4 ), sub( 31, temp_e[i] ) );
+ IF( GT_32( adj_fx[i], temp ) )
+#else /* OPT_BASOP_ADD_v1 */
IF( BASOP_Util_Cmp_Mant32Exp( adj_fx[i], temp_e[i], MAX_32, 2 ) > 0 )
+#endif /* OPT_BASOP_ADD_v1 */
{
adj_fx[i] = MAX_32;
move32();
diff --git a/lib_dec/ivas_entropy_decoder.c b/lib_dec/ivas_entropy_decoder_fx.c
similarity index 99%
rename from lib_dec/ivas_entropy_decoder.c
rename to lib_dec/ivas_entropy_decoder_fx.c
index 0c489fb04ccc58831bbe4bad92f233b400b67a86..e637a6a93d7bfe0b06b91b85fe0b5dfc9436b2d6 100644
--- a/lib_dec/ivas_entropy_decoder.c
+++ b/lib_dec/ivas_entropy_decoder_fx.c
@@ -32,13 +32,12 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c
index dc9126607a389e38f6f082a6686cbf5a5005a19f..c55da7699570a7cfe1bf04621c096cdf2d366885 100644
--- a/lib_dec/ivas_init_dec.c
+++ b/lib_dec/ivas_init_dec.c
@@ -40,9 +40,8 @@
#include "rom_com.h"
#include "ivas_rom_com.h"
#include "ivas_stat_enc.h"
-#include "prot.h"
-#include "wmc_auto.h"
#include "prot_fx.h"
+#include "wmc_auto.h"
#include "ivas_prot_fx.h"
#ifdef SPLIT_REND_WITH_HEAD_ROT
#include "lib_isar_pre_rend.h"
@@ -2281,7 +2280,7 @@ ivas_error ivas_init_decoder_fx(
}
}
- granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
+ granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
@@ -2589,7 +2588,7 @@ ivas_error ivas_init_decoder_fx(
/* no module has yet open the TC buffer, open a default one */
n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
- IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
+ IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
{
return error;
}
diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_ism_dec.c
rename to lib_dec/ivas_ism_dec_fx.c
index 785e1a0a1e9726762e8fed6303171acd90cca6eb..ea974eb5e0d4d41bdbd4d02f58e6a446d86278d2 100644
--- a/lib_dec/ivas_ism_dec.c
+++ b/lib_dec/ivas_ism_dec_fx.c
@@ -32,13 +32,12 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
#include "ivas_prot_rend.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*-------------------------------------------------------------------------*
diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_ism_dtx_dec.c
rename to lib_dec/ivas_ism_dtx_dec_fx.c
index 0365005bee964400c30e6851e082e247ad989f7b..cbf088597f8d35a44d6640f19e134ff8136d2ba8 100644
--- a/lib_dec/ivas_ism_dtx_dec.c
+++ b/lib_dec/ivas_ism_dtx_dec_fx.c
@@ -35,10 +35,9 @@
#include "options.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
/*-------------------------------------------------------------------*
* ivas_ism_dtx_dec_fx()
diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_ism_metadata_dec.c
rename to lib_dec/ivas_ism_metadata_dec_fx.c
index 833ed5e163ea183ee61efef20a29d7738f0c8818..a6f5e47b6acb39a2975b54e05f123d383fa40618 100644
--- a/lib_dec/ivas_ism_metadata_dec.c
+++ b/lib_dec/ivas_ism_metadata_dec_fx.c
@@ -37,7 +37,6 @@
#include "ivas_prot_fx.h"
#include "ivas_rom_com.h"
#include "ivas_rom_com_fx.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_stat_enc.h"
#include
diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_ism_param_dec.c
rename to lib_dec/ivas_ism_param_dec_fx.c
index a8b02fe2ad5029192a6229ffa477d36510dd1967..a7aa8619372c2a72abc661491cb11c13cc189ec8 100644
--- a/lib_dec/ivas_ism_param_dec.c
+++ b/lib_dec/ivas_ism_param_dec_fx.c
@@ -36,13 +36,12 @@
#include "options.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
#include "ivas_rom_dec.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#include "debug.h"
#include "ivas_rom_com_fx.h"
@@ -810,7 +809,6 @@ ivas_error ivas_param_ism_dec_open_fx(
IF( st_ivas->hTcBuffer == NULL )
{
- move16(); // NS2SA
IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
{
diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer_fx.c
similarity index 99%
rename from lib_dec/ivas_ism_renderer.c
rename to lib_dec/ivas_ism_renderer_fx.c
index 738e5a598f06c3c7b6c66aa3d26ae32d33ee45b1..a19ba70ec3414eb83a9b25be539aa8e652759408 100644
--- a/lib_dec/ivas_ism_renderer.c
+++ b/lib_dec/ivas_ism_renderer_fx.c
@@ -33,7 +33,6 @@
#include
#include "options.h"
#include "ivas_cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_jbm_dec.c
rename to lib_dec/ivas_jbm_dec_fx.c
index cf98199b28d19b2ef89a6e0c371afb697409430f..3504ef945d574715ea1bfd9e03cee3e2a52ae793 100644
--- a/lib_dec/ivas_jbm_dec.c
+++ b/lib_dec/ivas_jbm_dec_fx.c
@@ -35,7 +35,7 @@
#include "cnst.h"
#include "ivas_cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
#include "ivas_prot_rend.h"
@@ -46,7 +46,6 @@
#ifdef DEBUGGING
#include "debug.h"
#endif
-#include "prot_fx.h"
/*-----------------------------------------------------------------------*
@@ -431,8 +430,8 @@ ivas_error ivas_jbm_dec_tc_fx(
scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
FOR( i = 0; i < CPE_CHANNELS; ++i )
{
- scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
- scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
+ scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
+ scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
}
IF( hCPE->hCoreCoder[0] != NULL )
{
@@ -522,7 +521,7 @@ ivas_error ivas_jbm_dec_tc_fx(
#ifdef MSAN_FIX
FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ )
{
- Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); // q_prev_synth_fx
+ Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
}
#else
Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 );
@@ -537,7 +536,7 @@ ivas_error ivas_jbm_dec_tc_fx(
#ifdef MSAN_FIX
FOR( int ii = 0; ii < CPE_CHANNELS; ii++ )
{
- Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11
+ Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11
}
#else
Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx );
@@ -968,8 +967,8 @@ ivas_error ivas_jbm_dec_tc_fx(
scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );
FOR( i = 0; i < CPE_CHANNELS; ++i )
{
- scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
- scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
+ scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
+ scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
}
IF( hCPE->hCoreCoder[0] != NULL )
{
@@ -1008,7 +1007,7 @@ ivas_error ivas_jbm_dec_tc_fx(
}
#ifdef MSAN_FIX
FOR( i = 0; i < CPE_CHANNELS; i++ )
- Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, 11 ) ); // q_prev_synth_fx
+ Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
#else
Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 );
#endif
@@ -1028,8 +1027,8 @@ ivas_error ivas_jbm_dec_tc_fx(
scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
FOR( i = 0; i < CPE_CHANNELS; ++i )
{
- scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
- scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
+ scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
+ scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
}
IF( hCPE->hCoreCoder[0] != NULL )
@@ -1427,8 +1426,8 @@ ivas_error ivas_jbm_dec_tc_fx(
scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );
FOR( i = 0; i < CPE_CHANNELS; ++i )
{
- scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
- scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
+ scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
+ scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
}
IF( hCPE->hCoreCoder[0] != NULL )
@@ -1473,7 +1472,7 @@ ivas_error ivas_jbm_dec_tc_fx(
}
#ifdef MSAN_FIX
FOR( i = 0; i < CPE_CHANNELS; i++ )
- Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, 11 ) ); // q_prev_synth_fx
+ Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
#else
Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 );
#endif
@@ -1484,7 +1483,7 @@ ivas_error ivas_jbm_dec_tc_fx(
}
#ifdef MSAN_FIX
FOR( i = 0; i < CPE_CHANNELS; i++ )
- Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11
+ Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11
#else
Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx );
#endif // MSAN_FIX
diff --git a/lib_dec/ivas_lfe_dec_fx.c b/lib_dec/ivas_lfe_dec_fx.c
index 616b15c6ed0ac675c8b53208e30a0fc94db39fcd..e68c0142df2b4dae3c1863e09750b09b16d0b715 100644
--- a/lib_dec/ivas_lfe_dec_fx.c
+++ b/lib_dec/ivas_lfe_dec_fx.c
@@ -32,7 +32,6 @@
#include
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c
index f5e7816add00985fbb77806c8e5ebff3b0bdb45e..018f99fe74f80bba1a0d006fa4690e2ee2fe19e3 100644
--- a/lib_dec/ivas_lfe_plc_fx.c
+++ b/lib_dec/ivas_lfe_plc_fx.c
@@ -32,7 +32,6 @@
#include
#include "options.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_rom_com.h"
@@ -397,7 +396,7 @@ static Word16 lfeplc_lev_dur_fx(
IF( LT_16( rc_q_fx[i - 1], 31 ) )
{
- IF( GT_32( abs( rc_fx[i - 1] ), L_shr( 2146302532, sub( 31, rc_q_fx[i - 1] ) ) ) ) // 2146302532 = 0.99945f in Q31
+ IF( GT_32( L_abs( rc_fx[i - 1] ), L_shr( 2146302532, sub( 31, rc_q_fx[i - 1] ) ) ) ) // 2146302532 = 0.99945f in Q31
{
return 1;
}
@@ -414,7 +413,7 @@ static Word16 lfeplc_lev_dur_fx(
}
ELSE
{
- IF( GT_32( abs( L_shr( rc_fx[i - 1], sub( rc_q_fx[i - 1], 31 ) ) ), 2146302532 ) ) // 2146302532 = 0.00045f in Q31
+ IF( GT_32( L_abs( L_shr( rc_fx[i - 1], sub( rc_q_fx[i - 1], 31 ) ) ), 2146302532 ) ) // 2146302532 = 0.00045f in Q31
{
return 1;
}
@@ -466,7 +465,7 @@ static Word16 d_a2rc_fx(
move32();
km_q_fx = ff_q_fx[m];
move16();
- IF( GE_64( W_shr( abs( km_fx ), sub( ff_q_fx[m], Q30 ) ), W_deposit32_l( ONE_IN_Q30 ) ) )
+ IF( GE_64( W_shr( L_abs( km_fx ), sub( ff_q_fx[m], Q30 ) ), W_deposit32_l( ONE_IN_Q30 ) ) )
{
FOR( j = 0; j < lpcorder; j++ )
{
@@ -827,7 +826,7 @@ static Word32 find_max_delta_fx(
IF( !stable )
{
- temp = abs( eps_fx );
+ temp = L_abs( eps_fx );
IF( GT_32( L_shr( temp, sub( eps_q_fx, 31 ) ), EPS_STOP_Q31 ) )
{
exp1 = norm_l( -temp );
@@ -837,12 +836,12 @@ static Word32 find_max_delta_fx(
}
ELSE
{
- eps_fx = L_negate( abs( eps_fx ) );
+ eps_fx = L_negate( L_abs( eps_fx ) );
}
}
ELSE
{
- temp = abs( eps_fx );
+ temp = L_abs( eps_fx );
if ( LT_32( L_shr( temp, sub( eps_q_fx, 31 ) ), EPS_STOP_Q31 ) )
{
BREAK;
diff --git a/lib_dec/ivas_ls_custom_dec.c b/lib_dec/ivas_ls_custom_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_ls_custom_dec.c
rename to lib_dec/ivas_ls_custom_dec_fx.c
index eabee357b27573fb6d2b978cb52b7449725415b0..45f59d82f5ab45887e78c84c9474596a869ec081 100644
--- a/lib_dec/ivas_ls_custom_dec.c
+++ b/lib_dec/ivas_ls_custom_dec_fx.c
@@ -32,10 +32,9 @@
#include
#include "options.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*-----------------------------------------------------------------------*
diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_masa_dec.c
rename to lib_dec/ivas_masa_dec_fx.c
index 25053e3ab04752c487a9b99176eafee2639aabf2..19ce363b20890875ed06b4fa9b8fc9c5e74f14f0 100644
--- a/lib_dec/ivas_masa_dec.c
+++ b/lib_dec/ivas_masa_dec_fx.c
@@ -40,7 +40,6 @@
#include "rom_com.h"
#include "ivas_rom_com.h"
#include "ivas_stat_dec.h"
-#include "prot.h"
#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
@@ -836,7 +835,7 @@ ivas_error ivas_masa_dec_open_fx(
nchan_to_allocate = add( nchan_to_allocate, 1 );
}
- IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_transport, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK )
+ IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_transport, nchan_to_allocate, nchan_to_allocate, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK )
{
return error;
}
diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c
deleted file mode 100644
index 7ed698ab81eb0a7440797bc69078805e8417b180..0000000000000000000000000000000000000000
--- a/lib_dec/ivas_mc_param_dec.c
+++ /dev/null
@@ -1,3855 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "rom_enc.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "ivas_prot.h"
-#include "ivas_prot_rend.h"
-#include "ivas_cnst.h"
-#include "ivas_rom_com.h"
-#include "ivas_rom_dec.h"
-#include "math.h"
-#include "wmc_auto.h"
-#include "rom_dec.h"
-#include "prot_fx.h"
-#include "ivas_prot_fx.h"
-
-#define INV_EPSILON_MANT 214748365
-
-/*-----------------------------------------------------------------------*
- * Local constants
- *-----------------------------------------------------------------------*/
-
-#define PARAM_MC_LOCAL_SZ_LFE_MAP 5
-
-/*-----------------------------------------------------------------------*
- * Local typedefs
- *-----------------------------------------------------------------------*/
-
-typedef struct parameter_band_mapping_struct
-{
- Word16 n_source_bands[20];
- Word16 source_band_idx[20][4];
- Word16 source_band_factor_fx[20][4]; /*Q15*/
-
-} PARAM_MC_PARAMETER_BAND_MAPPING;
-
-/*-----------------------------------------------------------------------*
- * Local function prototypes
- *-----------------------------------------------------------------------*/
-
-static void ivas_param_mc_dec_init_fx( PARAM_MC_DEC_HANDLE hParamMC, const Word16 nchan_in, const Word16 nchan_out );
-
-static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 nY, const Word16 slot_idx );
-static Word16 ivas_param_mc_range_decoder_LC_fx( UWord16 *bit_buffer, Word16 *x, Word16 *BER_detect, const Word16 sz_seq, const Word16 sz_alphabet, const UWord16 *cft, const UWord16 *sft, const Word16 tot_shift, const Word16 nbbits );
-
-
-static void ivas_param_mc_get_mixing_matrices_fx(
- PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
- IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
- Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands */
- Word16 Cx_in_e,
- const Word16 param_band_idx,
- Word32 *mixing_matrix_fx[],
- Word16 *mixing_matrix_e,
- Word32 *mixing_matrix_res_fx[],
- Word16 *mixing_matrix_res_e,
- const Word16 nY_intern, /* i : number of channels in the transported format */
- const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */
- const Word16 nX, /* i : number of transport channels */
- const Word16 nY_cov /* i : number of covariance synthesis output channels */
-);
-
-static Word16 ivas_param_mc_uniform_decoder_fx( Word16 *seq, const Word16 sz_seq, const Word16 *alphabet, const Word16 N, UWord16 bit_buffer[PARAM_MC_MAX_BITS] );
-static void ivas_param_mc_dec_compute_interpolator_fx( const UWord16 bAttackPresent, const UWord16 attackPos, const UWord16 interp_length, Word16 *interpolator );
-
-static void param_mc_set_num_synth_bands( const Word32 output_Fs, PARAM_MC_DEC_HANDLE hParamMC );
-
-static void ivas_param_mc_get_param_band_mapping( const Word16 n_target_bands, const Word16 *target_band_grouping, const Word16 n_source_bands, const Word16 *source_band_grouping, PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping );
-
-
-static void ivas_param_mc_bs_decode_parameter_values_fx( UWord16 bit_buffer[], Word16 *bit_pos, const Word16 max_bits, Word16 *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const Word16 map_size_wo_lfe, const Word16 map_size, const Word16 num_lfe_bands, const Word16 band_step, const Word16 num_param_bands, Word16 *value_buffer );
-static void ivas_param_mc_dequantize_cov_fx( PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e );
-static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, Word16 Q_proto_mtx );
-static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY );
-
-
-static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t num_freq_bands /*, Word16 RealBuffer_fx_e, Word16 ImagBuffer_fx_e, Word16 *common_e*/ );
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dec_open()
- *
- * Open Parametric MC decoder handle
- *-------------------------------------------------------------------------*/
-
-ivas_error ivas_param_mc_dec_open_fx(
- Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
-)
-{
- Word16 k, nchan_transport;
- PARAM_MC_DEC_HANDLE hParamMC;
- Word16 nchan_out_transport;
- Word16 nchan_out_cov;
- Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
- Word32 proto_mtx_norm_fx;
- Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
- Word16 max_param_band_residual;
- UWord16 config_index;
- MC_LS_SETUP mc_ls_setup;
- AUDIO_CONFIG output_config;
- Word32 output_Fs, ivas_total_brate;
- ivas_error error;
-
- error = IVAS_ERR_OK;
- move32();
-
- /*-----------------------------------------------------------------*
- * prepare library opening
- *-----------------------------------------------------------------*/
-
- IF( ( hParamMC = (PARAM_MC_DEC_HANDLE) malloc( sizeof( PARAM_MC_DEC_DATA ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
-
- IF( ( hParamMC->hMetadataPMC = (HANDLE_IVAS_PARAM_MC_METADATA) malloc( sizeof( IVAS_PARAM_MC_METADATA ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC metadata \n" ) );
- }
-
- output_Fs = st_ivas->hDecoderConfig->output_Fs;
- move32();
- output_config = st_ivas->hDecoderConfig->output_config;
- move32();
- ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
- move32();
- mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
- nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
- hParamMC->hoa_encoder_fx = NULL;
-
- /* determine the synthesis config */
- test();
- test();
- test();
- test();
- test();
- IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( st_ivas->transport_config, output_config ) )
- {
- hParamMC->synthesis_conf = PARAM_MC_SYNTH_DIRECT;
- move32();
- }
- ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
- {
- hParamMC->synthesis_conf = PARAM_MC_SYNTH_MONO_STEREO;
- move32();
- }
- ELSE IF( NE_32( st_ivas->transport_config, output_config ) )
- {
- test();
- test();
- IF( ( NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, audioCfg2channels( output_config ) ) ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, st_ivas->hOutSetup.nchan_out_woLFE ) ) )
- {
- hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_COV;
- move32();
- /* need to reset the intern config */
- st_ivas->intern_config = output_config;
- move32();
- ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
- IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
- {
- st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk;
- move32();
- st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; // Q22
- st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; // Q22
- }
- }
- ELSE
- {
- hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_CLDFB;
- move32();
- }
- }
-
- hParamMC->ls_conv_dmx_matrix_fx = NULL;
-
- test();
- IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
- }
- ELSE
- {
- nchan_out_cov = nchan_out_transport;
- move16();
- }
-
- st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
- move16();
- config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
- nchan_transport = st_ivas->nchan_transport;
- move16();
-
- SWITCH( nchan_transport )
- {
- case 4:
- case 3:
- st_ivas->nCPE = 2;
- move16();
- st_ivas->nSCE = 0;
- move16();
- st_ivas->element_mode_init = IVAS_CPE_MDCT;
- move16();
- BREAK;
- case 2:
- st_ivas->nCPE = 1;
- move16();
- st_ivas->nSCE = 0;
- move16();
- st_ivas->element_mode_init = IVAS_CPE_MDCT;
- move16();
-
- BREAK;
- }
-
- /*-----------------------------------------------------------------*
- * set input parameters
- *-----------------------------------------------------------------*/
-
- // hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX;
- Word16 temp_e;
- Word16 temp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &temp_e );
- temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0
- temp = BASOP_Util_Divide1616_Scale( temp, CLDFB_NO_COL_MAX, &temp_e );
- temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0
- hParamMC->slot_size = temp;
- move16();
- set16_fx( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
- set16_fx( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
- hParamMC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
- move16();
-
- // hParamMC->num_freq_bands = (int16_t)(output_Fs * INV_CLDFB_BANDWIDTH + 0.5f);
- hParamMC->num_freq_bands = extract_l( Mpy_32_32_r( output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) );
- move16();
- hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands;
- move16();
- ivas_param_mc_metadata_open_fx( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC );
-
- /* init arrays for quantized parameters */
-
- IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); // Q8
- set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) ); // Q15
-
- param_mc_set_num_synth_bands( output_Fs, hParamMC );
-
- /* Band Grouping */
- IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) )
- {
- Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 );
- }
- ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) )
- {
- Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 );
- }
- ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) )
- {
- Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 );
- }
- ELSE
- {
- assert( 0 && "nbands must be 20, 14, or 10!" );
- }
-
- /* set max parameter band for abs cov */
- k = 0;
- move16();
- WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) )
- {
- hParamMC->max_param_band_abs_cov = k;
- move16();
- k = add( k, 1 );
- }
-
- /*-----------------------------------------------------------------*
- * open sub-modules
- *-----------------------------------------------------------------*/
-
- /* prototype signal computation */
-
- test();
- test();
- IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
-
- /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */
- test();
- IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
-
- FOR( k = 0; k < nchan_out_transport; k++ )
- {
- Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); /*Q30*/
- }
-
- /* convert ParamMC parameter bands to SFB */
- IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth;
- move16();
- FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ )
- {
- st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] );
- move16();
- }
- }
- ELSE
- {
- /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */
- ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
- }
- }
- }
- IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, imult1616( nchan_transport, nchan_out_transport ) ); /*Q31*/
-
- hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport );
- move16();
-
- test();
- IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); /*Q.26*/
- matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx ); /*Q.26*/
- Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); /*Q.26*/
- IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- proto_mtx_norm_fx = ONE_IN_Q26; /*Q26*/
- move32();
- FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ )
- {
- proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); /*Q.26*/
- }
- proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/
-
- /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */
- FOR( k = 0; k < nchan_transport; k++ )
- {
- FOR( Word16 i = 0; i < nchan_out_cov; i++ )
- {
- st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[k * nchan_out_cov + i], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/
- move32();
- }
- }
- }
- }
- ELSE
- {
- Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); /*Q.31*/
- Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); /*Scaling down to 26*/
- }
-
- IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- hParamMC->num_outputs_diff = 0;
- move16();
- hParamMC->diff_proto_info = NULL;
- hParamMC->h_output_synthesis_params.use_onset_filters = 0;
- move16();
- hParamMC->max_band_decorr = 0;
- move16();
- hParamMC->h_freq_domain_decorr_ap_params = NULL;
- hParamMC->h_freq_domain_decorr_ap_state = NULL;
- }
- ELSE
- {
- hParamMC->num_outputs_diff = nchan_out_cov;
- move16();
- IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
-
- IF( NE_32( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
-
- /* decorrelation */
- hParamMC->h_freq_domain_decorr_ap_params = NULL;
- hParamMC->h_freq_domain_decorr_ap_state = NULL;
-
- ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0
-
- IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff,
- hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ),
- IVAS_ERR_OK ) )
- {
- return error;
- }
-
- hParamMC->h_output_synthesis_params.use_onset_filters = 0;
- move16();
- hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr;
- move16();
- }
- hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded];
- move16();
- max_param_band_residual = 0;
- move16();
-
- FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
- {
- IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
- {
- max_param_band_residual = k;
- move16();
- assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr );
- break;
- }
- }
-
- /* output synthesis */
- IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
-
- ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx );
-
- /* Head or external rotation */
- test();
- test();
- test();
- IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
- {
- IF( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hParamMC->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER );
- }
-
- /*-----------------------------------------------------------------*
- * memory allocation
- *-----------------------------------------------------------------*/
-
- IF( hParamMC->max_band_decorr > 0 )
- {
- IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- IF( ( hParamMC->proto_frame_dec_f_fx = (Word32 *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- }
- ELSE
- {
- hParamMC->proto_frame_f_fx = NULL;
- hParamMC->proto_frame_dec_f_fx = NULL;
- }
-
- ivas_param_mc_dec_init_fx( hParamMC, nchan_transport, nchan_out_cov );
-
- IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- Word16 n_cldfb_slots;
-
- n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS;
- move16();
- IF( st_ivas->hDecoderConfig->Opt_tsm )
- {
- n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS;
- move16();
- }
-
- Word16 cldfb_buf_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
- IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
- }
- set32_fx( hParamMC->Cldfb_RealBuffer_tc_fx, 0, cldfb_buf_size );
- IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
- }
- set32_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, 0, cldfb_buf_size );
-
- hParamMC->sz = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
- move16();
-
- IF( st_ivas->hTcBuffer == NULL )
- {
- IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
- }
- }
- ELSE
- {
- hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
- hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
- }
-
- hParamMC->subframes_rendered = 0;
- move16();
- hParamMC->slots_rendered = 0;
- move16();
-
- st_ivas->hParamMC = hParamMC;
- return error;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_get_param_band_mapping()
- *
- *
- *-------------------------------------------------------------------------*/
-
-static void ivas_param_mc_get_param_band_mapping(
- const Word16 n_target_bands,
- const Word16 *target_band_grouping,
- const Word16 n_source_bands,
- const Word16 *source_band_grouping,
- PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping )
-{
- Word16 target_band_idx;
- Word16 source_band_idx = 0;
- move16();
- Word16 source_band_cnt_total;
-
- FOR( target_band_idx = 0; target_band_idx < n_target_bands; target_band_idx++ )
- {
- Word16 upper = target_band_grouping[target_band_idx + 1];
- Word16 lower = target_band_grouping[target_band_idx];
- Word16 source_band_in_target_band_cnt = 0;
- Word16 norm_fac_fx = 32767; // 1.Q15
- source_band_cnt_total = 0;
- move16();
- move16();
- move16();
-
- FOR( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ )
- {
- /* find lowest corresponding source band*/
- test();
- IF( LE_16( source_band_grouping[source_band_idx], lower ) && GE_16( source_band_grouping[source_band_idx + 1], lower ) )
- {
- DO
- {
- Word16 source_bands_in_target_band = sub( s_min( source_band_grouping[source_band_idx + 1], upper ), s_max( source_band_grouping[source_band_idx], lower ) );
- IF( source_bands_in_target_band )
- {
- source_band_cnt_total = add( source_band_cnt_total, source_bands_in_target_band );
- parameter_band_mapping->source_band_idx[target_band_idx][source_band_in_target_band_cnt] = source_band_idx;
- parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_in_target_band_cnt++] = shl( source_bands_in_target_band, 10 ); /*Q10*/
- move16();
- move16();
- }
- source_band_idx++;
- }
- WHILE( LE_16( source_band_grouping[source_band_idx], upper ) && LT_16( source_band_idx, n_source_bands ) );
- BREAK;
- }
- }
- norm_fac_fx = div_s( 1, source_band_cnt_total ); /*Q15*/
- FOR( source_band_idx = 0; source_band_idx < source_band_in_target_band_cnt; source_band_idx++ )
- {
- parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx] = shl_sat( mult( parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx], norm_fac_fx ) /*Q10*/, 5 ); /*Q15*/
- move16();
- }
- parameter_band_mapping->n_source_bands[target_band_idx] = source_band_in_target_band_cnt;
- move16();
- }
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dec_reconfig()
- *
- * Reconfiguration of ParamMC decoder
- *-------------------------------------------------------------------------*/
-
-ivas_error ivas_param_mc_dec_reconfig_fx(
- Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
-)
-{
- Word16 k, nchan_transport;
- PARAM_MC_DEC_HANDLE hParamMC;
- Word16 nchan_out_transport;
- Word16 nchan_out_cov;
- Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
- Word32 proto_mtx_norm_fx;
- Word16 max_param_band_residual;
- UWord16 config_index;
- MC_LS_SETUP mc_ls_setup;
- Word32 output_Fs, ivas_total_brate;
- ivas_error error;
- Word16 nchan_transport_old;
- Word16 num_param_bands_old;
- PARAM_MC_PARAMETER_BAND_MAPPING parameter_band_mapping;
- Word16 band_grouping_old[20 + 1];
-
- hParamMC = st_ivas->hParamMC;
- error = IVAS_ERR_OK;
- move32();
- /* save important config information from the previous state */
- nchan_transport_old = st_ivas->nchan_transport;
- move32();
- num_param_bands_old = hParamMC->hMetadataPMC->num_parameter_bands;
- move32();
-
- /*-----------------------------------------------------------------*
- * prepare library opening
- *-----------------------------------------------------------------*/
-
- output_Fs = st_ivas->hDecoderConfig->output_Fs;
- move32();
- ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
- move32();
- mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
- nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
-
- test();
- IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
- }
- ELSE
- {
- nchan_out_cov = nchan_out_transport;
- move16();
- }
-
- st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
- move16();
- config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
- nchan_transport = st_ivas->nchan_transport;
- move16();
-
- SWITCH( nchan_transport )
- {
- case 4:
- case 3:
- st_ivas->nCPE = 2;
- move16();
- st_ivas->nSCE = 0;
- move16();
- st_ivas->element_mode_init = IVAS_CPE_MDCT;
- move16();
- BREAK;
- case 2:
- st_ivas->nCPE = 1;
- move16();
- st_ivas->nSCE = 0;
- move16();
- st_ivas->element_mode_init = IVAS_CPE_MDCT;
- move16();
-
- BREAK;
- }
-
- /*-----------------------------------------------------------------*
- * set input parameters
- *-----------------------------------------------------------------*/
- hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); // Q0
- move16();
- hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands;
- move16();
-
- Copy( hParamMC->band_grouping, band_grouping_old, add( hParamMC->hMetadataPMC->num_parameter_bands, 1 ) );
- ivas_param_mc_metadata_open_fx( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC );
- /* Band Grouping */
- IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) )
- {
- Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 );
- }
- ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) )
- {
- Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 );
- }
- ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) )
- {
- Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 );
- }
- ELSE
- {
- assert( 0 && "nbands must be 20, 14, or 10!" );
- }
-
- ivas_param_mc_get_param_band_mapping( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->band_grouping, num_param_bands_old, band_grouping_old, ¶meter_band_mapping );
-
- test();
- IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) )
- {
- Word16 *ild_q_old_fx = hParamMC->icld_q_fx; // Q8
- Word16 *icc_q_old_fx = hParamMC->icc_q_fx; // Q15
-
- IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); /*Q8*/
- set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); /*Q15*/
-
- /* map old to new parameter banding, only for same number of TCs, needs some more thought for a changing number of TCs */
- test();
- IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) )
- {
- Word16 new_param_band_idx, param_idx, source_param_idx;
- Word16 num_param_lfe;
- Word16 *p_icc_new_fx = hParamMC->icc_q_fx; // Q15
- Word16 *p_ild_new_fx = hParamMC->icld_q_fx; // Q8
- Word16 p_ild_new_e = 23;
- move16();
- Word16 p_ild_new_tmp;
-
- /* ICC */
- num_param_lfe = hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe;
- move16();
- FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
- {
- FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ )
- {
- *p_icc_new_fx = 0;
- move16();
- FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
- {
- *p_icc_new_fx = add( *p_icc_new_fx, mult( icc_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); /*Q15*/
- move16();
- }
- p_icc_new_fx++;
- }
- }
-
- /* ILD */
- num_param_lfe = hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe;
- move16();
- FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
- {
- FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ )
- {
- *p_ild_new_fx = 0;
- move16();
- FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
- {
- p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); // 31 - p_ild_new_e - 16
- *p_ild_new_fx = add( *p_ild_new_fx, mult( p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) );
- move16();
- }
- *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, L_shl( p_ild_new_e, 25 ) ) ), 24660 /*3.Q13*/ ), 15 ) ); // Q8
- move16();
- p_ild_new_fx++;
- }
- }
- }
- free( ild_q_old_fx );
- free( icc_q_old_fx );
- }
-
- param_mc_set_num_synth_bands( output_Fs, hParamMC );
-
- /* set max parameter band for abs cov */
- k = 0;
- move16();
- WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) )
- {
- hParamMC->max_param_band_abs_cov = k;
- move16();
- k = add( k, 1 );
- }
-
- /*-----------------------------------------------------------------*
- * open sub-modules
- *-----------------------------------------------------------------*/
-
- /* prototype signal computation */
-
- IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- IF( NE_16( nchan_transport_old, nchan_transport ) )
- {
- IF( st_ivas->hLsSetUpConversion != NULL )
- {
- ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
- }
-
- IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
-
- /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */
- free( hParamMC->ls_conv_dmx_matrix_fx );
-
- IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- FOR( k = 0; k < nchan_out_transport; k++ )
- {
- Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov );
- }
- }
- /* convert ParamMC parameter bands to SFB */
-
- st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth;
- move16();
- FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ )
- {
- st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] );
- move16();
- }
- FOR( ; k < MAX_SFB + 2; k++ )
- {
- st_ivas->hLsSetUpConversion->sfbOffset[k] = 0;
- move16();
- }
- }
-
- IF( NE_16( nchan_transport_old, nchan_transport ) )
- {
- free( hParamMC->proto_matrix_int_fx );
- IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport );
- move16();
- Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, hParamMC->proto_matrix_int_len ); /*Q31*/
- }
-
- test();
- IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); // Q30 -> Q26
- matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0,
- ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0,
- proto_matrix_fx /*Q26*/ );
- Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); // Q26 -> Q30
-
- IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- proto_mtx_norm_fx = ONE_IN_Q26; // Q26
- move32();
- FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ )
- {
- proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); // Q26
- }
- proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/
-
- /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */
- FOR( k = 0; k < nchan_transport; k++ )
- {
- FOR( Word16 i = 0; i < nchan_out_cov; i++ )
- {
- st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); // Q26 -> Q30
- move32();
- }
- }
- }
- }
- ELSE
- {
- Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); // proto_matrix_fx -> Q31
- Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); // proto_matrix_fx -> Q26
- }
-
- test();
- IF( NE_16( nchan_transport_old, nchan_transport ) && NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- Word16 i;
- Word16 len;
-
- /* close decorrelator */
- ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state );
-
- /* deallocate diffuse prototype info */
- IF( hParamMC->diff_proto_info )
- {
- FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ )
- {
- free( hParamMC->diff_proto_info->source_chan_idx[i] );
- hParamMC->diff_proto_info->source_chan_idx[i] = NULL;
-
- free( hParamMC->diff_proto_info->proto_fac_fx[i] );
- hParamMC->diff_proto_info->proto_fac_fx[i] = NULL;
- }
-
- free( hParamMC->diff_proto_info->source_chan_idx );
- hParamMC->diff_proto_info->source_chan_idx = NULL;
-
- free( hParamMC->diff_proto_info->proto_fac_fx );
- hParamMC->diff_proto_info->proto_fac_fx = NULL;
-
- free( hParamMC->diff_proto_info->proto_index_diff );
- hParamMC->diff_proto_info->proto_index_diff = NULL;
-
- free( hParamMC->diff_proto_info->num_source_chan_diff );
- hParamMC->diff_proto_info->num_source_chan_diff = NULL;
-
- free( hParamMC->diff_proto_info );
- hParamMC->diff_proto_info = NULL;
- }
-
- hParamMC->num_outputs_diff = nchan_out_cov;
- move16();
- IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- IF( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ) != IVAS_ERR_OK )
- {
- return error;
- }
-
- /* decorrelation */
- hParamMC->h_freq_domain_decorr_ap_params = NULL;
- hParamMC->h_freq_domain_decorr_ap_state = NULL;
-
- Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
- ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0
-
- IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff,
- hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ),
- IVAS_ERR_OK ) )
- {
- return error;
- }
- hParamMC->h_output_synthesis_params.use_onset_filters = 0;
- move16();
- hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr;
- move16();
- /* init decorrelation */
- IF( hParamMC->max_band_decorr > 0 )
- {
-
- len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr );
-
- /* init onsetDetectionPower */
- set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
- set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
- hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
- move16();
- }
- }
- hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded];
- move16();
- max_param_band_residual = 0;
- move16();
-
- FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
- {
- IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
- {
- max_param_band_residual = k;
- move16();
- assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr );
- BREAK;
- }
- }
-
- test();
- IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) )
- {
- DIRAC_OUTPUT_SYNTHESIS_COV_STATE cov_state_old = hParamMC->h_output_synthesis_cov_state;
- DIRAC_OUTPUT_SYNTHESIS_PARAMS params_old = hParamMC->h_output_synthesis_params;
-
- Word32 tmp_buf_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
-
- set_zero_fx( tmp_buf_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
-
- /* output synthesis */
- IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS,
- hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ),
- IVAS_ERR_OK ) )
- {
- return error;
- }
-
- ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx );
-
- ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual );
-
- /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */
- test();
- IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) )
- {
- Word16 new_param_band_idx, source_param_idx;
-
- FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
- {
- FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
- {
- /* Cx */
- v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_transport_old ) ); // Q(31 - cov_state_old.cx_old_e)
- v_add_fixed_me( tmp_buf_fx, cov_state_old.cx_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], imult1616( nchan_transport_old, nchan_transport_old ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx])
- /* Cy */
- v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - cov_state_old.cy_old_e)
- v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx])
- /* mixing matrix*/
- v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) ); // Q(31 - mixing_matrix_old_exp)
- v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx])
- }
- }
- FOR( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ )
- {
- FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
- {
- /* residual mixing matrix*/
- v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - mixing_matrix_res_old_exp)
- v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx])
- }
- }
- }
- ivas_dirac_dec_output_synthesis_cov_close_fx( ¶ms_old, &cov_state_old );
- }
-
- /*-----------------------------------------------------------------*
- * memory allocation
- *-----------------------------------------------------------------*/
-
- test();
- IF( ( hParamMC->max_band_decorr > 0 ) && NE_16( nchan_transport_old, nchan_transport ) )
- {
- free( hParamMC->proto_frame_f_fx );
- IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
- }
-
-
- IF( NE_16( nchan_transport_old, nchan_transport ) )
- {
- IF( NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- Word16 n_cldfb_slots;
- IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
- {
- free( hParamMC->Cldfb_RealBuffer_tc_fx );
- hParamMC->Cldfb_RealBuffer_tc_fx = NULL; // Q12
- }
- IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
- {
- free( hParamMC->Cldfb_ImagBuffer_tc_fx );
- hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; // Q12
- }
-
- n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS;
- move16();
- IF( st_ivas->hDecoderConfig->Opt_tsm )
- {
- n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS;
- move16();
- }
- Word16 cldfb_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
- IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
- }
- set_zero_fx( hParamMC->Cldfb_RealBuffer_tc_fx, cldfb_size );
-
- IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
- }
- set_zero_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, cldfb_size );
- }
- ELSE
- {
- IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
- {
- free( hParamMC->Cldfb_RealBuffer_tc_fx );
- hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
- }
- IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
- {
- free( hParamMC->Cldfb_ImagBuffer_tc_fx );
- hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
- }
- }
- }
- return error;
-}
-
-
-/*-------------------------------------------------------------------------
- * param_mc_get_num_cldfb_syntheses()
- *
- * calculate the necessary number of CLDFB synthesis instances
- *------------------------------------------------------------------------*/
-
-/*! r: number of cldfb synthesis instances */
-Word16 param_mc_get_num_cldfb_syntheses_fx(
- Decoder_Struct *st_ivas /* i : Parametric MC handle */
-)
-{
- Word16 num_cldfb_syntheses;
-
- num_cldfb_syntheses = 0;
- move16();
-
- /* sanity check*/
- IF( st_ivas->hParamMC == NULL )
- {
- assert( 0 && "ParamMC handle does not exist!\n" );
- }
-
- test();
- IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
- {
- num_cldfb_syntheses = 2;
- move16();
- }
- ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
- {
- num_cldfb_syntheses = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
- }
- ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) )
- {
- num_cldfb_syntheses = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
- }
-
- return num_cldfb_syntheses;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dec_close()
- *
- * Close Parametric MC memories
- *------------------------------------------------------------------------*/
-
-void ivas_param_mc_dec_close_fx(
- PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */
-)
-{
- UWord16 i;
- PARAM_MC_DEC_HANDLE hParamMC;
-
- IF( hParamMC_out == NULL || *hParamMC_out == NULL )
- {
- return;
- }
-
- hParamMC = *hParamMC_out;
-
- /* close sub-modules */
- ivas_dirac_dec_output_synthesis_cov_close_fx( &hParamMC->h_output_synthesis_params, &hParamMC->h_output_synthesis_cov_state );
-
- IF( hParamMC->h_freq_domain_decorr_ap_params != NULL || hParamMC->h_freq_domain_decorr_ap_state != NULL )
- {
- ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state );
- }
-
- /* parameter decoding */
- IF( hParamMC->hMetadataPMC != NULL )
- {
- free( hParamMC->hMetadataPMC );
- hParamMC->hMetadataPMC = NULL;
- }
- IF( hParamMC->icc_q_fx != NULL )
- {
- free( hParamMC->icc_q_fx );
- hParamMC->icc_q_fx = NULL; // Q15
- }
-
- IF( hParamMC->icld_q_fx != NULL )
- {
- free( hParamMC->icld_q_fx );
- hParamMC->icld_q_fx = NULL; // Q8
- }
- /* diffuse prototype info */
- IF( hParamMC->diff_proto_info )
- {
- FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ )
- {
- free( hParamMC->diff_proto_info->source_chan_idx[i] );
- hParamMC->diff_proto_info->source_chan_idx[i] = NULL;
-
- free( hParamMC->diff_proto_info->proto_fac_fx[i] );
- hParamMC->diff_proto_info->proto_fac_fx[i] = NULL;
- }
-
- free( hParamMC->diff_proto_info->source_chan_idx );
- hParamMC->diff_proto_info->source_chan_idx = NULL;
-
- free( hParamMC->diff_proto_info->proto_fac_fx );
- hParamMC->diff_proto_info->proto_fac_fx = NULL;
-
- free( hParamMC->diff_proto_info->proto_index_diff );
- hParamMC->diff_proto_info->proto_index_diff = NULL;
-
- free( hParamMC->diff_proto_info->num_source_chan_diff );
- hParamMC->diff_proto_info->num_source_chan_diff = NULL;
-
- free( hParamMC->diff_proto_info );
- hParamMC->diff_proto_info = NULL;
- }
- /* States */
- /* free prototype signal buffers */
- IF( hParamMC->proto_frame_f_fx != NULL )
- {
- free( hParamMC->proto_frame_f_fx );
- hParamMC->proto_frame_f_fx = NULL;
- }
-
- IF( hParamMC->proto_frame_dec_f_fx != NULL )
- {
- free( hParamMC->proto_frame_dec_f_fx );
- hParamMC->proto_frame_dec_f_fx = NULL;
- }
-
- IF( hParamMC->ls_conv_dmx_matrix_fx != NULL )
- {
- free( hParamMC->ls_conv_dmx_matrix_fx );
- hParamMC->ls_conv_dmx_matrix_fx = NULL;
- }
-
- IF( hParamMC->proto_matrix_int_fx != NULL )
- {
- free( hParamMC->proto_matrix_int_fx );
- hParamMC->proto_matrix_int_fx = NULL;
- }
-
- IF( hParamMC->hoa_encoder_fx != NULL )
- {
- free( hParamMC->hoa_encoder_fx );
- hParamMC->hoa_encoder_fx = NULL;
- }
- IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
- {
- free( hParamMC->Cldfb_RealBuffer_tc_fx );
- hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
- }
- IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
- {
- free( hParamMC->Cldfb_ImagBuffer_tc_fx );
- hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
- }
-
- free( *hParamMC_out );
- *hParamMC_out = NULL;
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dec_read_BS()
- *
- * Read the Parametric MC metadata
- *------------------------------------------------------------------------*/
-
-void ivas_param_mc_dec_read_BS_fx(
- const Word32 ivas_total_brate, /* i : IVAS total bitrate */
- Decoder_State *st, /* i/o: decoder state structure */
- PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder ParamMC handle */
- Word16 *nb_bits /* o : number of bits written */
-)
-{
- Word16 param_frame_idx;
- Word16 band_step;
- UWord16 bit_buffer[PARAM_MC_MAX_BITS];
- Word16 bits_to_copy;
- Word16 bit_pos;
- Word16 num_lfe_bands;
- Word16 num_param_bands;
- Word16 metadata_bit_pos;
- Word16 i, j, k;
- Word16 icc_map_size;
- Word16 icc_map_size_wo_lfe;
- Word16 ild_map_size;
- Word16 ild_map_size_wo_lfe;
- HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC;
-
- push_wmops( "param_mc_read_bs" );
-
- /* Inits */
- *nb_bits = 0;
- move16();
- hMetadataPMC = hParamMC->hMetadataPMC;
- icc_map_size = hMetadataPMC->icc_mapping_conf->icc_map_size_lfe;
- move16();
- icc_map_size_wo_lfe = hMetadataPMC->icc_mapping_conf->icc_map_size_wo_lfe;
- move16();
- ild_map_size = hMetadataPMC->ild_mapping_conf->ild_map_size_lfe;
- move16();
- ild_map_size_wo_lfe = hMetadataPMC->ild_mapping_conf->ild_map_size_wo_lfe;
- move16();
-
- IF( !st->bfi )
- {
- /*metadata_bit_pos = extract_l(ivas_total_brate / FRAMES_PER_SEC - 1);
- bits_to_copy = s_min(extract_l(ivas_total_brate / FRAMES_PER_SEC), PARAM_MC_MAX_BITS);*/
- Word16 temp = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
- metadata_bit_pos = sub( temp, 1 );
- bits_to_copy = s_min( temp, PARAM_MC_MAX_BITS );
-
- /* copy and reverse metadata */
- FOR( bit_pos = 0; bit_pos < bits_to_copy; bit_pos++ )
- {
- bit_buffer[bit_pos] = st->bit_stream[metadata_bit_pos];
- move16();
- metadata_bit_pos = sub( metadata_bit_pos, 1 );
- move16();
- }
-
- bit_pos = 0;
- move16();
-
- /* read reserved bit */
- hMetadataPMC->lfe_on = bit_buffer[bit_pos++];
- move16();
-
- /* get coded bwidth */
- {
- Word16 pos;
- Word16 bw = 0;
- move16();
- FOR( pos = 0; pos < 2; pos++ )
- {
- bw = add( bw, extract_l( L_shl( bit_buffer[bit_pos++], pos ) ) );
- }
- hMetadataPMC->coded_bwidth = bw;
- move16();
- }
-
- /* set tables if coded band width differs from last frame */
- IF( NE_16( hMetadataPMC->coded_bwidth, hMetadataPMC->last_coded_bwidth ) )
- {
- ivas_param_mc_set_coded_bands_fx( hMetadataPMC );
- param_mc_set_num_synth_bands( st->output_Fs, hParamMC );
- hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->num_param_bands_synth];
- move16();
- }
-
- param_frame_idx = bit_buffer[bit_pos++];
- move16();
- hMetadataPMC->param_frame_idx = param_frame_idx;
- move16();
- num_param_bands = hMetadataPMC->nbands_in_param_frame[param_frame_idx];
- move16();
-
- hMetadataPMC->bAttackPresent = bit_buffer[bit_pos++];
- move16();
- hMetadataPMC->attackIndex = 0;
- move16();
- band_step = 1;
- move16();
- num_lfe_bands = 0;
- move16();
-
- IF( hMetadataPMC->bAttackPresent )
- {
- FOR( i = 2; i >= 0; i-- )
- {
- hMetadataPMC->attackIndex = add( hMetadataPMC->attackIndex, extract_l( L_shl( bit_buffer[bit_pos++], i ) ) );
- }
-
- band_step = PARAM_MC_TRANSIENT_BAND_STEP;
- move16();
-
- /*num_lfe_bands = add(PARAM_MC_MAX_BAND_LFE / band_step, (PARAM_MC_MAX_BAND_LFE % band_step) ? 1 : 0);
- num_param_bands = add(hMetadataPMC->nbands_coded / band_step, ((hMetadataPMC->nbands_coded % band_step) ? 1 : 0));*/
- Word16 temp_e;
- temp = BASOP_Util_Divide3232_Scale( PARAM_MC_MAX_BAND_LFE, band_step, &temp_e );
- temp = shr( temp, sub( 15, temp_e ) );
- Word16 temp1;
- IF( PARAM_MC_MAX_BAND_LFE % band_step )
- {
- temp1 = 1;
- }
- ELSE
- {
- temp1 = 0;
- }
- move16();
- num_lfe_bands = add( temp, temp1 );
-
- temp = BASOP_Util_Divide3232_Scale( hMetadataPMC->nbands_coded, band_step, &temp_e );
- temp = shr( temp, sub( 15, temp_e ) );
- Word16 temp2;
- IF( hMetadataPMC->nbands_coded % band_step )
- {
- temp2 = 1;
- }
- ELSE
- {
- temp2 = 0;
- }
- move16();
- num_param_bands = add( temp, temp2 );
- }
- ELSE
- {
- FOR( j = 0; j < PARAM_MC_MAX_BAND_LFE; j += band_step )
- {
- IF( EQ_16( param_frame_idx, hMetadataPMC->coding_band_mapping[j] ) )
- {
- /* LFE ICC is always the last ICC in coding band 0 */
- num_lfe_bands = add( num_lfe_bands, 1 );
- move16();
- }
- }
- }
-
- IF( !hMetadataPMC->lfe_on )
- {
- num_lfe_bands = 0;
- move16();
- }
-
- ivas_param_mc_bs_decode_parameter_values_fx( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->icc_coding,
- icc_map_size_wo_lfe, icc_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icc_q_fx );
-
- IF( !st->BER_detect )
- {
- ivas_param_mc_bs_decode_parameter_values_fx( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->ild_coding,
- ild_map_size_wo_lfe, ild_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icld_q_fx );
- }
- /* set LFE ILD and ICC to zero above PARAM_MC_MAX_BAND_LFE for attack frames */
- IF( hMetadataPMC->bAttackPresent )
- {
- FOR( k = PARAM_MC_MAX_BAND_LFE; k < imult1616( band_step, num_lfe_bands ); k++ )
- {
- hParamMC->icc_q_fx[L_sub( L_mult0( add( k, 1 ), icc_map_size ), 1 )] = 32767; /* 1.0f in Q15 */
- move16();
- hParamMC->icld_q_fx[L_sub( L_mult0( add( k, 1 ), ild_map_size ), 1 )] = PARAM_MC_DEFAULT_MIN_ILD_FX; /* -92.0f in Q8 */
- move16();
- }
- }
-
- *nb_bits = bit_pos;
- move16();
-
- } /* if ( !st->bfi ) */
-
- IF( st->bfi )
- {
- /* for PLC, use the saved ILDs and ICCs from the past and set the transient flag and transient position to zero */
- hMetadataPMC->bAttackPresent = 0;
- move16();
- hMetadataPMC->attackIndex = 0;
- move16();
- }
-
- pop_wmops();
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dec_digest_tc()
- *
- *
- *------------------------------------------------------------------------*/
-
-void ivas_param_mc_dec_digest_tc_fx(
- Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
- const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */
- Word32 *transport_channels_f_fx[],
- Word16 transport_f_e )
-{
- PARAM_MC_DEC_HANDLE hParamMC;
- Word16 i, ch;
- Word16 is_next_band, skip_next_band;
- Word16 slot_idx, param_band_idx;
- Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
- Word16 nchan_out_cov;
- /*CLDFB*/
- /* format converter */
- Word16 channel_active[MAX_OUTPUT_CHANNELS];
- IVAS_OUTPUT_SETUP *hSynthesisOutputSetup;
-
- hParamMC = st_ivas->hParamMC;
- assert( hParamMC );
- Word32 *pCx, *pCx_imag;
- Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_e)
- Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_e)
- Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_next_band_e)
- Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_next_band_e)
-
- Word16 cx_buff_e[2][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
- Word16 cx_e;
- Word16 cx_imag_e, tmp_e;
- Word16 cx_imag_next_band_e, cx_next_band_e;
- Word16 qout = 0;
- move16();
-
- Word32 real_part_fx, imag_part_fx, L_tmp1, L_tmp2;
-
- Word16 max_e;
-
- push_wmops( "param_mc_dec_digest_tc" );
-
- set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
- nchan_transport = st_ivas->nchan_transport;
- move16();
- nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
-
- test();
- test();
- IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
- {
- nchan_out_cldfb = BINAURAL_CHANNELS;
- move16();
- set16_fx( channel_active, 1, nchan_out_cldfb );
- nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
- hSynthesisOutputSetup = &st_ivas->hTransSetup;
- }
- ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
- {
- nchan_out_cov = nchan_out_transport;
- move16();
- nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
- hSynthesisOutputSetup = &st_ivas->hTransSetup;
- }
- ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
- nchan_out_cldfb = nchan_out_cov;
- move16();
- set16_fx( channel_active, 1, nchan_out_cov );
- hSynthesisOutputSetup = &st_ivas->hOutSetup;
- }
- ELSE
- {
- nchan_out_cov = nchan_out_transport;
- move16();
- nchan_out_cldfb = nchan_out_transport;
- move16();
- set16_fx( channel_active, 1, nchan_out_cov );
- hSynthesisOutputSetup = &st_ivas->hTransSetup;
- }
-
- /* adapt transient position */
- IF( hParamMC->hMetadataPMC->bAttackPresent )
- {
- hParamMC->hMetadataPMC->attackIndex = s_max( 0, add( hParamMC->hMetadataPMC->attackIndex, shr( sub( nCldfbSlots, DEFAULT_JBM_CLDFB_TIMESLOTS ), 1 ) ) );
- move16();
- }
- /* adapt subframes */
- hParamMC->num_slots = nCldfbSlots;
- move16();
- hParamMC->slots_rendered = 0;
- move16();
- hParamMC->subframes_rendered = 0;
- move16();
- ivas_jbm_dec_get_adapted_subframes( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes );
- st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes;
- move16();
- Copy( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes );
-
- ivas_param_mc_dec_compute_interpolator_fx( hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx );
-
- /* loop over two bands at a time */
- FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 )
- {
- /* don't process next band if it exceeds the limit */
- skip_next_band = ( ( param_band_idx + 1 ) == hParamMC->num_param_bands_synth ) ? 1 : 0;
-
- set_zero_fx( cx_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
- set_zero_fx( cx_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
- set_zero_fx( cx_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
- set_zero_fx( cx_imag_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
-
- cx_e = 0;
- move16();
- cx_imag_e = 0;
- move16();
- cx_next_band_e = 0;
- move16();
- cx_imag_next_band_e = 0;
- move16();
- /* slot loop for gathering the input data */
- FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
- {
- IF( st_ivas->hDecoderConfig->Opt_tsm )
- {
- IF( param_band_idx == 0 ) /* only run cldfbAna once */
- {
- Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX];
- Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX];
-
- /* CLDFB Analysis*/
- FOR( ch = 0; ch < nchan_transport; ch++ )
- {
- qout = transport_f_e;
- move16();
- cldfbAnalysis_ts_fx_fixed_q( &( transport_channels_f_fx[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch], &qout );
-
- Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands );
- Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands );
- }
-
- hParamMC->Cldfb_ImagBuffer_tc_e = qout;
- move16();
- }
- }
- IF( GE_16( slot_idx, shl( hParamMC->hMetadataPMC->attackIndex, 1 ) ) )
- {
- FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
- {
- test();
- IF( is_next_band && skip_next_band )
- {
- continue;
- }
- IF( is_next_band )
- {
- ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
- /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
- &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
- /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
- cx_next_band_fx,
- &cx_next_band_e,
- cx_imag_next_band_fx,
- &cx_imag_next_band_e,
- hParamMC,
- add( param_band_idx, is_next_band ),
- nchan_transport );
- }
- ELSE
- {
- ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
- /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
- &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
- /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
- cx_fx,
- &cx_e,
- cx_imag_fx,
- &cx_imag_e,
- hParamMC,
- add( param_band_idx, is_next_band ),
- nchan_transport );
- }
- }
- }
- }
-
- Word16 tmp_cx_e, tmp_cx_imag_e;
- /* map from complex input covariance to real values */
- FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
- {
- test();
- IF( is_next_band && skip_next_band )
- {
- continue;
- }
- /* Cx for transport channels */
- IF( is_next_band )
- {
- pCx = &cx_next_band_fx[0];
- pCx_imag = &cx_imag_next_band_fx[0];
- tmp_cx_e = cx_next_band_e;
- tmp_cx_imag_e = cx_imag_next_band_e;
- }
- ELSE
- {
- pCx = &cx_fx[0];
- pCx_imag = &cx_imag_fx[0];
- tmp_cx_e = cx_e;
- tmp_cx_imag_e = cx_imag_e;
- }
-
- FOR( i = 0; i < nchan_transport * nchan_transport; i++ )
- {
- real_part_fx = pCx[i]; // Q(31 - cx_buff_e)
- imag_part_fx = pCx_imag[i];
- move32();
- move32();
- cx_buff_e[is_next_band][i] = tmp_cx_e;
- move16();
- /* (a-ib)(c+id) = ac + bd + i(ad-bc) */
- IF( LT_16( param_band_idx, hParamMC->max_param_band_abs_cov ) )
- {
- L_tmp1 = Mpy_32_32( real_part_fx, real_part_fx );
- L_tmp2 = Mpy_32_32( imag_part_fx, imag_part_fx );
- L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, add( tmp_cx_e, tmp_cx_e ), L_tmp2, add( tmp_cx_imag_e, tmp_cx_imag_e ), &tmp_e );
- pCx[i] = Sqrt32( L_tmp1, &tmp_e );
- move32();
- cx_buff_e[is_next_band][i] = tmp_e;
- move16();
- }
- ELSE
- {
- pCx[i] = real_part_fx;
- move32();
- cx_buff_e[is_next_band][i] = tmp_cx_e;
- move16();
- }
- }
- }
-
- max_e = cx_buff_e[0][0];
- move16();
-
- /* Cx for transport channels */
- FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
- {
- FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
- {
-
- IF( LT_16( max_e, cx_buff_e[is_next_band][i] ) )
- {
- max_e = cx_buff_e[is_next_band][i];
- }
- }
- }
- /* Cx for transport channels */
- FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
- {
- FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
- {
- if ( is_next_band == 0 )
- {
- cx_fx[i] = L_shr( cx_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
- }
- else
- {
- cx_next_band_fx[i] = L_shr( cx_next_band_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
- }
- move32();
- }
- }
- cx_e = max_e;
- move16();
-
-
- /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/
-
- test();
- test();
- IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) )
- {
- v_add_fx( cx_fx, cx_next_band_fx, cx_fx, imult1616( nchan_transport, nchan_transport ) );
- Copy32( cx_fx, cx_next_band_fx, imult1616( nchan_transport, nchan_transport ) );
- }
-
- FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
- {
- test();
- IF( is_next_band && skip_next_band )
- {
- continue;
- }
-
- IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- IF( is_next_band )
- {
-
- ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_next_band_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
- }
- ELSE
- {
-
- ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
- }
- }
- }
- }
- pop_wmops();
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dec()
- *
- * Parametric MC decoding process
- *------------------------------------------------------------------------*/
-
-void ivas_param_mc_dec_render_fx(
- Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
- const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */
- UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */
- UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */
- Word32 *output_f_fx[], /* o : rendered time signal Q11*/
- Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] )
-{
- PARAM_MC_DEC_HANDLE hParamMC;
- Word16 i, ch;
- Word16 subframe_idx;
- Word16 slot_idx, slot_idx_start, slot_idx_start_cldfb_synth, first_sf, last_sf, slots_to_render;
- Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
- Word16 nchan_out_cov;
-
- /*CLDFB*/
- Word32 Cldfb_RealBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
- Word32 Cldfb_ImagBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
- Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
-#else
- Word32 Cldfb_RealBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
- Word32 Cldfb_ImagBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
-#endif
- Word32 *p_output_f_fx[MAX_OUTPUT_CHANNELS];
- FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
- {
- p_output_f_fx[i] = output_f_fx[i]; // Q11
- }
- /*Decorrelator*/
- Word32 onset_filter_fx[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; // Q31
-
- /* format converter */
- Word16 channel_active[MAX_OUTPUT_CHANNELS];
- UWord16 nband_synth;
-#ifndef MSAN_FIX
- UWord16 nchan_out_init, nbands_to_zero;
-#endif
- UWord32 output_Fs;
- Word16 tmp_q = 0;
- move16();
-
- hParamMC = st_ivas->hParamMC;
- assert( hParamMC );
-
- push_wmops( "param_mc_dec_render" );
-
- set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
- nchan_transport = st_ivas->nchan_transport;
- move16();
- nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
-#ifndef MSAN_FIX
- nchan_out_init = nchan_out_transport;
- move16();
-#endif
- output_Fs = st_ivas->hDecoderConfig->output_Fs;
- move32();
-
- test();
- test();
- IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
- {
- nchan_out_cldfb = BINAURAL_CHANNELS;
- set16_fx( channel_active, 1, nchan_out_cldfb );
-#ifndef MSAN_FIX
- IF( st_ivas->hCombinedOrientationData )
- {
- nchan_out_init = MAX_INTERN_CHANNELS;
- }
-#endif
- nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
- }
- ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
- {
- nchan_out_cov = nchan_out_transport;
- move16();
- nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
- }
- ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
- {
- nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
- nchan_out_cldfb = nchan_out_cov;
- move16();
- set16_fx( channel_active, 1, nchan_out_cov );
- }
- ELSE
- {
- nchan_out_cov = nchan_out_transport;
- move16();
- nchan_out_cldfb = nchan_out_transport;
- move16();
- set16_fx( channel_active, 1, nchan_out_cov );
- }
-
- /* set everything to zero that will not be decoded */
- nband_synth = hParamMC->band_grouping[hParamMC->num_param_bands_synth];
- move16();
-#ifdef MSAN_FIX
- FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
-#else
- FOR( ch = 0; ch < nchan_out_init; ch++ )
-#endif
- {
- FOR( slot_idx = 0; slot_idx < JBM_CLDFB_SLOTS_IN_SUBFRAME; slot_idx++ )
- {
-#ifdef MSAN_FIX
- set32_fx( &( Cldfb_RealBuffer_fx[ch][slot_idx][0] ), 0, CLDFB_NO_CHANNELS_MAX );
- set32_fx( &( Cldfb_ImagBuffer_fx[ch][slot_idx][0] ), 0, CLDFB_NO_CHANNELS_MAX );
-#else
- set32_fx( &( Cldfb_RealBuffer_fx[ch][slot_idx][nband_synth] ), 0, nbands_to_zero );
- set32_fx( &( Cldfb_ImagBuffer_fx[ch][slot_idx][nband_synth] ), 0, nbands_to_zero );
-#endif
- }
- }
-
- /* loop FOR synthesis, assume we always have to render in multiples of 5ms subframes with spills */
- /*slots_to_render = min(sub(hParamMC->num_slots, hParamMC->slots_rendered), nSamplesAsked / NS2SA(output_Fs, CLDFB_SLOT_NS));
- *nSamplesRendered = slots_to_render * NS2SA(output_Fs, CLDFB_SLOT_NS);*/
- Word16 temp_e;
- Word16 temp = BASOP_Util_Divide1616_Scale( nSamplesAsked, NS2SA( output_Fs, CLDFB_SLOT_NS ), &temp_e );
- temp = shr( temp, sub( 15, temp_e ) );
- slots_to_render = s_min( sub( hParamMC->num_slots, hParamMC->slots_rendered ), temp );
- *nSamplesRendered = imult1616( slots_to_render, NS2SA( output_Fs, CLDFB_SLOT_NS ) );
- move16();
- Word16 j, k;
- first_sf = hParamMC->subframes_rendered;
- move16();
- last_sf = first_sf;
- move16();
- WHILE( slots_to_render > 0 )
- {
- slots_to_render = sub( slots_to_render, hParamMC->subframe_nbslots[last_sf] );
- last_sf = add( last_sf, 1 );
- }
- IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
- {
- FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
- {
- slots_to_render = add( slots_to_render, hParamMC->subframe_nbslots[subframe_idx] );
- }
- }
- slot_idx_start = hParamMC->slots_rendered;
- move16();
- slot_idx_start_cldfb_synth = 0;
- move16();
-
-#ifndef FIX_1009_OPT_PARAMMC_RENDER
- Flag is_zero = 1;
- move32();
-#endif
- FOR( j = 0; j < st_ivas->hParamMC->hMetadataPMC->nbands_coded; j++ )
- {
-#ifndef FIX_1009_OPT_PARAMMC_RENDER
- is_zero = 1;
- move16();
- FOR( i = 0; i < hParamMC->h_output_synthesis_cov_state.mixing_matrix_len; i++ )
- {
- IF( hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[j][i] != 0 )
- {
- is_zero = 0;
- move16();
- }
- }
- IF( is_zero )
- {
- hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[j] = 0;
- move16();
- }
- is_zero = 1;
- move16();
-#else
- Flag is_zero = is_zero_arr( hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[j], hParamMC->h_output_synthesis_cov_state.mixing_matrix_len );
- {
- if ( is_zero != 0 )
- {
- hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[j] = 0;
- move16();
- }
- }
-#endif
- IF( LT_16( st_ivas->hParamMC->band_grouping[j], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
- {
-#ifndef FIX_1009_OPT_PARAMMC_RENDER
- FOR( i = 0; i < hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len; i++ )
- {
- IF( NE_32( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[j][i], 0 ) )
- {
- is_zero = 0;
- move16();
- }
- }
- IF( is_zero )
-#else
- is_zero = is_zero_arr( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[j], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len );
- if ( is_zero != 0 )
-#endif
- {
- hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[j] = 0;
- move16();
- }
- }
- }
- FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
- {
- FOR( slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; ( slot_idx++, hParamMC->slots_rendered++ ) )
- {
- IF( hParamMC->max_band_decorr > 0 )
- {
- /*-----------------------------------------------------------------*
- * protoype signal computation
- *-----------------------------------------------------------------*/
- param_mc_protoSignalComputation_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
- &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
- hParamMC->proto_frame_f_fx, hParamMC->diff_proto_info,
- hParamMC->num_freq_bands );
- /*-----------------------------------------------------------------*
- * frequency domain decorrelation
- *-----------------------------------------------------------------*/
- /* decorrelate prototype frame */
-
- ivas_dirac_dec_decorr_process_fx( hParamMC->num_freq_bands,
- hParamMC->num_outputs_diff,
- hParamMC->diff_proto_info->num_protos_diff,
- DIRAC_SYNTHESIS_COV_MC_LS,
- nchan_transport,
- hParamMC->proto_frame_f_fx,
- Q5,
- hParamMC->diff_proto_info->num_protos_diff,
- hParamMC->diff_proto_info->proto_index_diff,
- hParamMC->proto_frame_dec_f_fx, // output
- &tmp_q,
- onset_filter_fx,
- hParamMC->h_freq_domain_decorr_ap_params,
- hParamMC->h_freq_domain_decorr_ap_state );
-
- /* copy decorrelated frame directly to output CLDFB buffer, acts also as intermediate */
- /* memory FOR the decorrelated signal */
- ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx ); // Returns Cldfb buffers in Q11(tmp_q)
-
- FOR( k = 0; k < nchan_out_cov; k++ )
- {
- FOR( Word16 l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++ )
- {
- Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6
- move32();
- Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6
- move32();
- }
- }
- }
-
- /*-----------------------------------------------------------------*
- * output synthesis
- *-----------------------------------------------------------------*/
- ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx(
- &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
- &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ),
- nchan_transport, nchan_out_cov, hParamMC );
-
- test();
- IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
- {
- test();
- IF( st_ivas->hCombinedOrientationData && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
- {
- Word16 Q_Cldfb_ImagBuffer, Q_Cldfb_RealBuffer;
- Q_Cldfb_ImagBuffer = Q6 - 5; /*max value =MAX_INTERN_CHANNELS(=16)*Cldfb_ImagBuffer_fx*/
- move16();
- Q_Cldfb_RealBuffer = Q6 - 5;
- move16();
- FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
- {
- FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
- {
- Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_ImagBuffer, Q6 ) ); // Q1
- Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_RealBuffer, Q6 ) ); // Q1
- }
- }
- ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hParamMC->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nband_synth, GAIN_LFE_FX );
- FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
- {
- FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
- {
- Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_ImagBuffer ) ); // Q6
- Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_RealBuffer ) ); // Q6
- }
- }
- }
- ELSE
- {
- /* remove LFE */
- UWord16 idx_out;
- UWord16 idx_lfe;
- IVAS_OUTPUT_SETUP hLsSetup;
-
- hLsSetup = st_ivas->hTransSetup;
- /* If LFE should be rendered, add it to other channels before removing */
- IF( st_ivas->hBinRenderer->render_lfe )
- {
- Word16 tmp_exp = 0;
- move16();
- Word16 tmp = BASOP_Util_Divide1616_Scale( GAIN_LFE_FX, hLsSetup.nchan_out_woLFE, &tmp_exp );
- tmp_exp = add( tmp_exp, ( 1 - 15 ) );
- FOR( idx_lfe = 0; idx_lfe < hLsSetup.num_lfe; idx_lfe++ )
- {
- /* Copy just the first band of LFE*/
- v_multc_fixed_16( Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], tmp, Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1 );
- v_multc_fixed_16( Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], tmp, Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1 );
-
- Scale_sig32( Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1, tmp_exp );
- Scale_sig32( Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1, tmp_exp );
- FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
- {
- IF( hLsSetup.index_lfe[idx_lfe] != ch )
- {
- v_add_fixed( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_RealBuffer_fx[ch][slot_idx], 1, 0 );
- v_add_fixed( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], 1, 0 );
- }
- }
- }
- }
-
- idx_out = 0;
- move16();
- idx_lfe = 0;
- move16();
-
- FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
- {
- test();
- IF( ( hLsSetup.num_lfe > 0 ) && EQ_16( hLsSetup.index_lfe[idx_lfe], ch ) )
- {
- IF( LT_16( idx_lfe, ( sub( hLsSetup.num_lfe, 1 ) ) ) )
- {
- idx_lfe = add( idx_lfe, 1 );
- }
- }
- ELSE IF( NE_16( ch, idx_out ) )
- {
- Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[idx_out][slot_idx], nband_synth );
- Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[idx_out][slot_idx], nband_synth );
- idx_out = add( idx_out, 1 );
- }
- ELSE
- {
- idx_out = add( idx_out, 1 );
- }
- }
- }
- }
- }
-
- test();
- IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
- {
- Word16 input_q = 6;
- move16();
-
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
- {
- IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
- {
- FOR( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
- {
- FOR( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
- {
- Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
- Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
- }
- }
- st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
- move16();
- }
- }
-#endif
-
- /* Implement binaural rendering */
- ivas_binRenderer_fx( st_ivas->hBinRenderer,
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
-#endif
- st_ivas->hCombinedOrientationData,
- hParamMC->subframe_nbslots[subframe_idx],
- Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
- Cldfb_RealBuffer_fx,
- Cldfb_ImagBuffer_fx, &input_q );
-
- FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
- {
- FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
- {
- FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
- {
- Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
- Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
- }
- }
- }
-
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- int16_t pos_idx;
- FOR( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
- {
- FOR( Word16 idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ )
- {
- FOR( Word16 idx2 = 0; idx2 < hParamMC->subframe_nbslots[subframe_idx]; idx2++ )
- {
- Scale_sig32( Cldfb_RealBuffer_Binaural_fx[pos_idx][idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6
- Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[pos_idx][idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6
- }
- }
- }
-#else
- FOR( Word16 idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ )
- {
- FOR( Word16 idx2 = 0; idx2 < hParamMC->subframe_nbslots[subframe_idx]; idx2++ )
- {
- Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6
- Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6
- }
- }
-#endif
-
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
- {
- FOR( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
- {
- FOR( slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; slot_idx++ )
- {
- FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
- {
- Copy32( Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
- Copy32( Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
- }
- }
- }
- }
-#endif
-
- /* update combined orientation access index */
- ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx] );
- }
- ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
- {
- /* format conversion*/
- ivas_lssetupconversion_process_param_mc_fx( st_ivas, hParamMC->subframe_nbslots[subframe_idx], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, channel_active );
- }
-
-
- /* CLDFB synthesis */
- FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
- {
- Word32 *RealBuffer_fx[16];
- Word32 *ImagBuffer_fx[16];
-
- IF( channel_active[ch] )
- {
- /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands FOR 48kHz */
- FOR( i = 0; i < hParamMC->subframe_nbslots[subframe_idx]; i++ )
- {
- IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
- {
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[0][ch][i]; // Q6
- ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[0][ch][i]; // Q6
-#else
- RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[ch][i]; // Q6
- ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[ch][i]; // Q6
-#endif
- }
- ELSE
- {
- RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; // Q6
- ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; // Q6
- }
- }
-
- Word16 len = add( imult1616( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
- scale_sig32( output_f_fx[ch], len, 5 - 11 );
- cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ),
- imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] );
-
- scale_sig32( output_f_fx[ch], len, 11 - 5 ); // Q11
- }
- ELSE
- {
- set32_fx( &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
- }
- }
- slot_idx_start = add( slot_idx_start, hParamMC->subframe_nbslots[subframe_idx] );
- slot_idx_start_cldfb_synth = add( slot_idx_start_cldfb_synth, hParamMC->subframe_nbslots[subframe_idx] );
- }
- IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
- {
- ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_f_fx, p_output_f_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
- }
-
- /* update */
-
- IF( EQ_16( hParamMC->slots_rendered, hParamMC->num_slots ) )
- {
- hParamMC->hMetadataPMC->last_coded_bwidth = hParamMC->hMetadataPMC->coded_bwidth;
- move16();
- param_mc_update_mixing_matrices_fx( hParamMC, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_transport, nchan_out_cov );
- }
-
-
- hParamMC->subframes_rendered = last_sf;
- move16();
- *nSamplesAvailableNext = imult1616( sub( hParamMC->num_slots, hParamMC->slots_rendered ), NS2SA( output_Fs, CLDFB_SLOT_NS ) );
- move16();
-
- FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
- {
- channel_active_fx[i] = channel_active[i];
- move16();
- }
- pop_wmops();
-
- return;
-}
-
-/*-------------------------------------------------------------------------
- * param_mc_dec_init()
- *
- * Parametric MC decoding initialization
- *------------------------------------------------------------------------*/
-
-static void ivas_param_mc_dec_init_fx(
- PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */
- const Word16 nchan_transport, /* i : number of input (transport) channels */
- const Word16 nchan_cov ) /* i : number of cov synthesis channels */
-{
- Word16 k;
- UWord16 max_param_band_residual;
- Word16 len;
-
- /*-----------------------------------------------------------------*
- * init sub-modules
- *-----------------------------------------------------------------*/
-
- /* decorrelation */
- IF( hParamMC->max_band_decorr > 0 )
- {
- len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr );
-
- /* init onsetDetectionPower */
- set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
- set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
- hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
- move16();
- }
-
- max_param_band_residual = 0;
- move16();
-
- /* output synthesis */
- FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
- {
- IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
- {
- max_param_band_residual = k;
- move16();
- BREAK;
- }
- }
-
- ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual );
-
- /*-----------------------------------------------------------------*
- * init proto frames
- *-----------------------------------------------------------------*/
-
- IF( hParamMC->max_band_decorr > 0 )
- {
- set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
- set32_fx( hParamMC->proto_frame_dec_f_fx, 0, shl( imult1616( nchan_cov, hParamMC->num_freq_bands ), 1 ) );
- }
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * Local functions
- *-------------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dec_compute_diffuse_proto()
- *
- * Compute prototypes for decorrelation
- *------------------------------------------------------------------------*/
-
-static void param_mc_protoSignalComputation_fx(
- Word32 *RealBuffer_fx, /* i : CLDFB samples of the transport channels (real part) */
- Word32 *ImagBuffer_fx, /* i : CLDFB samples of the transport channels (imaginary part) */
- Word32 *proto_frame_f_fx, /* o : interleaved complex prototype CLDFB samples */
- const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i : prototype generation information */
- const int16_t num_freq_bands /* i : number of frequency bands for the prototypes */
-)
-{
- Word16 band;
- Word16 proto_ch_idx, source_ch_cnt;
-
- Word32 *p_proto_frame_fx;
- Word32 *p_real_buffer_fx; // Q12
- Word32 *p_imag_buffer_fx; // Q12
-
- set32_fx( proto_frame_f_fx, 0, shl( imult1616( num_freq_bands, diff_proto_info->num_protos_diff ), 1 ) );
-
-
- FOR( proto_ch_idx = 0; proto_ch_idx < diff_proto_info->num_protos_diff; proto_ch_idx++ )
- {
- Word16 num_source_ch = diff_proto_info->num_source_chan_diff[proto_ch_idx];
- move16();
-
- FOR( source_ch_cnt = 0; source_ch_cnt < num_source_ch; source_ch_cnt++ )
- {
-
- Word32 fac_fx = diff_proto_info->proto_fac_fx[proto_ch_idx][source_ch_cnt];
- move32();
-
- Word16 source_ch_idx = diff_proto_info->source_chan_idx[proto_ch_idx][source_ch_cnt];
- move16();
-
- p_proto_frame_fx = &proto_frame_f_fx[shl( imult1616( proto_ch_idx, num_freq_bands ), 1 )];
- p_real_buffer_fx = &RealBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
- p_imag_buffer_fx = &ImagBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
-
- FOR( band = 0; band < num_freq_bands; band++ )
- {
-
- Word32 tmp_x = Mpy_32_32( fac_fx, ( *( p_real_buffer_fx++ ) ) ); // Q(30 + 6 - 31) :: Q5
-
- *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
- move32();
- p_proto_frame_fx++;
-
- tmp_x = Mpy_32_32( fac_fx, ( *( p_imag_buffer_fx++ ) ) ); // Q(30 + 6 - 31) :: Q5
-
- *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
- move32();
- p_proto_frame_fx++;
- }
- }
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dec_compute_diffuse_proto()
- *
- * Transfer decorrelated signals back from the decorrelator buffer to
- * the buffers used in the final synthesis
- *------------------------------------------------------------------------*/
-
-static void ivas_param_mc_dec_copy_diffuse_proto(
- PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
- Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (real part) */
- Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (imaginary part) */
- const Word16 nY, /* i : number of decorrelated channels */
- const Word16 slot_idx /* i : current time slot index */
-)
-{
- Word16 k, l;
- Word16 num_freq_bands, num_freq_bands_diff;
- Word32 *p_proto_diff_fx;
- num_freq_bands = hParamMC->num_freq_bands;
- move16();
- num_freq_bands_diff = hParamMC->h_output_synthesis_params.max_band_decorr;
- move16();
-
- FOR( k = 0; k < nY; k++ )
- {
- p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); // Q11
-
- FOR( l = 0; l < num_freq_bands_diff; l++ )
- {
- Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
- move32();
- Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
- move32();
- }
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_bin2dec()
- *
- * decode a number of bits to an integer
- *------------------------------------------------------------------------*/
-/* r : decoded integer */
-static Word16 ivas_param_mc_bin2dec_fx(
- UWord16 bits[PARAM_MC_MAX_BITS], /* i : bit buffer */
- const Word16 N /* i : number of bits to decode */
-)
-{
- Word16 i;
- Word16 out;
-
- assert( N <= 16 );
- out = 0;
- move16();
- FOR( i = 0; i < N; i++ )
- {
- out = add( out, shl( bits[i], sub( sub( N, 1 ), i ) ) );
- }
-
- return out;
-}
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_uniform_decoder()
- *
- * decode a uniformily coded sequence of float values
- *------------------------------------------------------------------------*/
-static Word16 ivas_param_mc_uniform_decoder_fx(
- Word16 *seq, /* o : decoded sequence of float values hParamCodingInfo -> Q-quant*/
- const Word16 sz_seq, /* i : number of values to decode */
- const Word16 *alphabet, /* i : codebook hParamCodingInfo -> Q-quant*/
- const Word16 N, /* i : number of bits per coded index */
- UWord16 bit_buffer[PARAM_MC_MAX_BITS] /* i : bit buffer to decode */
-)
-{
- Word16 i;
- Word16 idx;
- Word16 n_bits;
-
- n_bits = 0;
- move16();
- assert( N * sz_seq < PARAM_MC_MAX_BITS );
-
- FOR( i = 0; i < sz_seq; ++i )
- {
- idx = ivas_param_mc_bin2dec_fx( &bit_buffer[i * N], N );
- seq[i] = alphabet[idx];
- move16();
- }
-
- n_bits = imult1616( N, sz_seq );
-
- return n_bits;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_range_decoder_LC()
- *
- * decode a sequency of inidices coded with a range coder
- *------------------------------------------------------------------------*/
-static Word16 ivas_param_mc_range_decoder_LC_fx(
- UWord16 *bit_buffer, /* i : bit buffer to read from */
- Word16 *x, /* o : decoded indices */
- Word16 *BER_detect, /* o : flag for indicating a bit error */
- const Word16 sz_seq, /* i : size of the sequence to be decoded */
- const Word16 sz_alphabet, /* i : size of the alphabet */
- const UWord16 *cft, /* i : cumulative frequency table */
- const UWord16 *sft, /* i : symbol frequency table */
- const Word16 tot_shift, /* i : total frequency as a power of 2 */
- const Word16 nbbits /* i : maximum bit budget */
-)
-{
- RangeUniDecState rc_st_dec; /* State of the range decoder */
- Word16 cur_bit_pos;
- Word16 k;
- Word16 r;
-
- /* Start Decoding */
- /* Initialize range decoder */
- cur_bit_pos = 0;
- move16();
- rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, sub( nbbits, 32 ) ); /* (nbbits + 30) entries are read by the decoder */
-
- /* Main Loop through the indices */
- FOR( k = 0; k < sz_seq; k++ )
- {
- r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
- /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */
-
- /* Update bitstream pointer */
- cur_bit_pos = rc_uni_dec_virtual_finish_fx( &rc_st_dec );
-
- /* Confirm that there is no overflow */
- IF( GT_16( cur_bit_pos, nbbits ) )
- {
- *BER_detect = s_or( *BER_detect, 1 );
- move16();
- }
-
- x[k] = r;
- move16();
- }
-
- /* We don't need to finish because virtual_finish() already does the same */
- /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/
-
- /* Check for bitstream errors */
- IF( rc_st_dec.bit_error_detected != 0 )
- {
- *BER_detect = s_or( *BER_detect, 1 );
- move16();
- }
-
- return cur_bit_pos;
-}
-
-/*-------------------------------------------------------------------------
- * param_mc_compute_interpolator()
- *
- * compute the interpolator used in the final synthesis
- *------------------------------------------------------------------------*/
-
-static void ivas_param_mc_dec_compute_interpolator_fx(
- const UWord16 bAttackPresent, /* i : flag indicating if we have a transient in the current frame */
- const UWord16 attackPos, /* i : position of the transient */
- const UWord16 interp_length, /* i : number of interpolation values to be calculated */
- Word16 *interpolator /* o : interpolator */
-)
-{
- Word16 idx;
-
- IF( bAttackPresent )
- {
- FOR( idx = 0; idx < attackPos * 2; idx++ )
- {
- interpolator[idx] = 0;
- move16();
- }
- FOR( ; idx < interp_length; idx++ )
- {
- interpolator[idx] = 32767; /* 1.0f Q15 */
- move16();
- }
- }
- ELSE
- {
- ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator );
- }
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * remove_lfe_from_cy()
- *
- * remove all LFE related values from a covariance matrix
- *------------------------------------------------------------------------*/
-
-static void remove_lfe_from_cy_fx(
- const Word16 nY, /* i : dimension of the covariance matrix */
- Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP], /* i : LFE index */
- Word16 num_lfe, /* i : number of LFEs */
- Word32 *cy, /* i : covariance matrix */
- Word32 *cy_woLFE /* o : covariance matrix with LFE removed */
-)
-{
- Word16 ch_idx1, ch_idx2;
- Word16 lfe_idx1, lfe_idx2;
- Word32 *ptrCy;
- Word32 *ptrCy_out;
-
- ptrCy = cy;
- ptrCy_out = cy_woLFE;
-
- FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ )
- {
- FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
- {
- FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ )
- {
- FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
- {
- *( ptrCy_out++ ) = *( ptrCy++ );
- move32();
- }
- ptrCy++;
- }
- ptrCy--;
- }
- ptrCy += nY;
- }
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_get_mixing_matrices()
- *
- * calculate the direct and residual mixing matrices
- * using the covariance method
- *------------------------------------------------------------------------*/
-
-static void ivas_param_mc_get_mixing_matrices_fx(
- PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
- IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
- Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands Q(31 - Cx_in_e)*/
- Word16 Cx_in_e,
- const Word16 param_band_idx, /* i : parameter band index */
- Word32 *mixing_matrix_fx[], // Q(31 - mixing_matrix_e)
- Word16 *mixing_matrix_e,
- Word32 *mixing_matrix_res_fx[], // Q(31 - mixing_matrix_res_e)
- Word16 *mixing_matrix_res_e,
- const Word16 nY_intern, /* i : number of channels in the transported format */
- const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */
- const Word16 nX, /* i : number of transport channels */
- const Word16 nY_cov /* i : number of covariance synthesis output channels */
-)
-{
- Word16 matSize = MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS;
- Word16 nY_band;
- Word16 num_lfe_bands;
- Word16 brange[2];
- uint16_t i;
- Word16 ch_idx1, ch_idx2, lfe_idx1, lfe_idx2;
- Word16 remove_lfe;
- Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP];
-
- Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
- Word32 Cy_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
-
- Word32 Cy_full_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
-
- Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cr_e)
- Word16 Cr_e;
- Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Cy_diag_buff_e)
- Word16 Cy_diag_buff_e[MAX_OUTPUT_CHANNELS];
- Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - mixing_matrix_local_e)
- Word16 Cy_diag_e = 0, mixing_matrix_local_e = 0;
- Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cproto_e)
- Word16 Cproto_e;
- Word32 *proto_matrix_ptr_fx; // Q(31 - proto_matrix_ptr_e)
- Word32 *Cx_state_fx; // Q(31 - Cx_state_e)
- Word32 *Cx_old_state_fx;
- Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cy_state_e)
- Word32 *Cy_old_state_fx;
- Word16 Cx_state_e;
- Word16 Cy_state_e;
- Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mixing_matrix_res_local_e)
- Word16 mixing_matrix_res_local_e;
- Word32 L_tmp;
- Word16 tmp_e, tmp;
-
- Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
- move16();
- Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; // Q(31 - proto_matrix_noLFE_e)
-
- Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
-
- Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; // Q(31 - Cproto_diag_e)
- Word16 mat_mult_buffer1_e, proto_matrix_ptr_e, Cproto_diag_e;
-
- Word32 *ptrMM_fx;
- Word32 *ptrMM_out_fx;
-
- Word16 Cy_e, Cx_e;
- Word16 Cy_full_e;
- Word16 new_e = 0;
- move16();
-
- set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
- set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
- set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
- set_zero_fx( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
-#ifdef MSAN_FIX
- set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
-#endif
- Word16 proto_matrix_noLFE_e = 0;
- move16();
-
- Word32 Cx_in_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
-
- Copy32( Cx_in_fixed, Cx_in_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
-
- nY_band = nY_cov;
- move16();
- num_lfe_bands = 0;
- move16();
- remove_lfe = 0;
- move16();
-
- set16_fx( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP );
- IF( hSynthesisOutputSetup->num_lfe )
- {
- Word32 *proto_matrix_ptr_in_fx;
- FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ )
- {
- lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1];
- move16();
- }
- lfe_indices[hSynthesisOutputSetup->num_lfe + 1] = nY_cov;
- move16();
- proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0];
- proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0];
- proto_matrix_noLFE_e = proto_matrix_e;
- move16();
-
- set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
-
- FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
- {
- FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
- {
- FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
- {
- *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ );
- move32();
- }
- proto_matrix_ptr_in_fx++;
- }
- proto_matrix_ptr_in_fx--;
- }
-
- proto_matrix_ptr_e = proto_matrix_e;
- move16();
- }
-
- if ( hParamMC->hMetadataPMC->lfe_on )
- {
- num_lfe_bands = PARAM_MC_MAX_BAND_LFE;
- move16();
- }
- IF( hSynthesisOutputSetup->num_lfe > 0 && param_band_idx >= num_lfe_bands )
- {
- remove_lfe = 1;
- move16();
- nY_band = sub( nY_cov, hSynthesisOutputSetup->num_lfe );
- proto_matrix_ptr_fx = proto_matrix_noLFE_fx;
- proto_matrix_ptr_e = proto_matrix_noLFE_e;
- move16();
- }
- ELSE
- {
- proto_matrix_ptr_fx = hParamMC->h_output_synthesis_params.proto_matrix_fx;
- proto_matrix_ptr_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
- move16();
- }
-
- brange[0] = hParamMC->band_grouping[param_band_idx];
- move16();
- brange[1] = hParamMC->band_grouping[param_band_idx + 1];
- move16();
-
- Cx_state_fx = Cx_in_fx;
- Cx_old_state_fx = hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx];
- Cy_old_state_fx = hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx];
-
-
- /* Getting mixing mtx */
- /* estimate target cov from input cov and proto_matrix */
-
- Cx_state_e = Cx_in_e;
- move16();
- matrix_product_fx( hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx );
- mat_mult_buffer1_e = add( hParamMC->proto_matrix_int_e, Cx_in_e );
-
- matrix_product_fx( mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx );
- Cproto_e = add( mat_mult_buffer1_e, hParamMC->proto_matrix_int_e );
-
- FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ )
- {
- IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )], Cproto_e, 0, 0 ) < 0 )
- {
- Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )] = 0;
- move32();
- }
- }
-
- set_zero_fx( Cy_state_fx, matSize );
- Cy_state_e = 0;
- move16();
-
- ivas_param_mc_dequantize_cov_fx( hParamMC,
- hParamMC->icld_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ),
- hParamMC->icc_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ),
- param_band_idx, nY_cov,
- synth_config,
- nY_intern,
- nX, Cx_state_fx, Cx_state_e, Cproto_fx, Cproto_e, Cy_state_fx, &Cy_state_e );
-
- // dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state_fx.txt");
-
- /* Smoothing: Sum over two buffers */
- IF( hParamMC->hMetadataPMC->bAttackPresent )
- {
- /* no smoothing on attacks */
- Copy32( Cx_state_fx, Cx_fx, imult1616( nX, nX ) );
- Copy32( Cy_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) );
- Cy_full_e = Cy_state_e;
- move16();
- Cx_e = Cx_state_e;
- move16();
- }
- ELSE
- {
- /* smoothing gains are now identical to one, simply add up */
- // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov );
-
- v_add_fixed_me( Cx_state_fx, Cx_state_e, Cx_old_state_fx, hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_fx, &Cx_e, imult1616( nX, nX ), 1 );
- v_add_fixed_me( Cy_state_fx, Cy_state_e, Cy_old_state_fx, hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_full_fx, &Cy_full_e, imult1616( nY_cov, nY_cov ), 1 );
- }
-
- Copy32( Cx_state_fx, Cx_old_state_fx, imult1616( nX, nX ) );
-
- Copy32( Cy_state_fx, Cy_old_state_fx, imult1616( nY_cov, nY_cov ) );
-
- hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = Cx_state_e;
- move16();
- hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e;
- move16();
-
- FOR( i = 0; i < nX * nX; i++ )
- {
- if ( Cx_old_state_fx[i] != 0 )
- {
- new_e = hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx];
- move16();
- BREAK;
- }
- }
-
- hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = new_e;
- move16();
-
- new_e = 0;
- move16();
-
- FOR( i = 0; i < nY_cov * nY_cov; i++ )
- {
- if ( Cy_old_state_fx[i] != 0 )
- {
- new_e = hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx];
- move16();
- BREAK;
- }
- }
-
- hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = new_e;
- move16();
-
- /* remove LFE IF necessary */
- IF( remove_lfe )
- {
-
- Cy_e = Cy_full_e;
- remove_lfe_from_cy_fx( nY_cov, lfe_indices, hSynthesisOutputSetup->num_lfe, Cy_full_fx, Cy_fx );
- }
- ELSE
- {
- Copy32( Cy_full_fx, Cy_fx, imult1616( nY_band, nY_band ) );
- Cy_e = Cy_full_e;
- move16();
- }
-
- matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx );
- mat_mult_buffer1_e = add( proto_matrix_ptr_e, Cx_e );
-
- matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e );
-
- /* make sure we have no negative entries in Cproto_diag due to rounding errors */
-
- FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ )
- {
- if ( BASOP_Util_Cmp_Mant32Exp( Cproto_diag_fx[ch_idx1], Cproto_diag_e, 0, 0 ) < 0 )
- {
- Cproto_diag_fx[ch_idx1] = 0;
- move16();
- }
- }
-
-
- /* Computing the mixing matrices */
-
- /* bands with decorr */
- IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
- {
- computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 0, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e );
- /* Compute mixing matrix FOR residual */
- computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e );
-
- IF( NE_16( mixing_matrix_res_local_e, mixing_matrix_local_e ) )
- {
- tmp = getScaleFactor32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
- scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, tmp );
- mixing_matrix_local_e = sub( mixing_matrix_local_e, tmp );
-
- tmp = getScaleFactor32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
- scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, tmp );
- mixing_matrix_res_local_e = sub( mixing_matrix_res_local_e, tmp );
-
- scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, sub( mixing_matrix_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) );
- scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, sub( mixing_matrix_res_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) );
-
- mixing_matrix_res_local_e = mixing_matrix_local_e = s_max( mixing_matrix_local_e, mixing_matrix_res_local_e );
- move16();
- }
- IF( remove_lfe )
- {
- set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
-
- ptrMM_fx = mixing_matrix_res_local_fx;
- ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx];
- FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
- {
- FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
- {
- FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ )
- {
- FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
- {
- *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
- move32();
- }
- ptrMM_out_fx++;
- }
- ptrMM_out_fx--;
- }
- ptrMM_out_fx += nY_cov;
- }
- mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
- move16();
- }
- ELSE
- {
- Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
- mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
- move16();
- }
- }
- ELSE IF( brange[0] < hParamMC->max_band_energy_compensation )
- {
- /* Compute mixing matrices (energy compensation only) */
- computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 1, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e );
- }
- ELSE
- {
- /*IF neither decorrelation nor energy compensation is applied*/
- FOR( i = 0; i < nY_band; i++ )
- {
- tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i], L_add( Cproto_diag_fx[i], EPSILON_FX ), &tmp_e );
- tmp_e = add( Cy_diag_e, Cproto_diag_e );
- L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_e );
- Cy_diag_fx[i] = L_tmp;
- move32();
- Cy_diag_buff_e[i] = tmp_e;
- move16();
- }
-
-
- Cy_diag_e = Cy_diag_buff_e[0];
- move16();
-
- FOR( i = 1; i < nY_band; i++ )
- {
- if ( LT_16( Cy_diag_e, Cy_diag_buff_e[i] ) )
- {
- Cy_diag_e = Cy_diag_buff_e[i];
- move16();
- }
- }
-
- FOR( i = 0; i < nY_band; i++ )
- {
- Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], sub( Cy_diag_e, Cy_diag_buff_e[i] ) );
- move32();
- }
-
- diag_matrix_product_fx( Cy_diag_fx, Cy_diag_e, nY_band, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e );
- }
-
- IF( remove_lfe )
- {
- set_zero_fx( mixing_matrix_fx[param_band_idx], imult1616( nX, nY_cov ) );
- ptrMM_fx = mixing_matrix_local_fx;
- ptrMM_out_fx = mixing_matrix_fx[param_band_idx];
- FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
- {
- FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
- {
- FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
- {
- *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
- move32();
- }
- ptrMM_out_fx++;
- }
- ptrMM_out_fx--;
- }
-
- mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
- move16();
- }
- ELSE
- {
- Copy32( mixing_matrix_local_fx, mixing_matrix_fx[param_band_idx], imult1616( nY_cov, nX ) );
- mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
- move16();
- }
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_get_mono_stereo_mixing_matrices()
- *
- * calculate the direct and residual mixing matrices
- * for mono and stereo output
- *------------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------------
- * param_mc_update_mixing_matrices()
- *
- * update mixing matrix buffers
- *------------------------------------------------------------------------*/
-
-static void param_mc_update_mixing_matrices_fx(
- PARAM_MC_DEC_HANDLE hParamMC, /* i/o: Parametric MC handle */
- Word32 *mixing_matrix[], /* i : direct mixing matrices for the frame just processed */
- Word16 *mixing_matrix_exp,
- Word32 *mixing_matrix_res[], /* i : residual mixing matrices for the frame just processed */
- Word16 *mixing_matrix_res_exp,
- const UWord16 nX, /* i : number of transport channels */
- const UWord16 nY ) /* i : number of synthesis channels */
-{
- UWord16 param_band_idx;
-
- FOR( param_band_idx = 0; param_band_idx < hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ )
- {
- Word16 brange[2];
-
- brange[0] = hParamMC->band_grouping[param_band_idx];
- move16();
- brange[1] = hParamMC->band_grouping[param_band_idx + 1];
- move16();
-
- Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nX, nY ) );
- hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = mixing_matrix_exp[param_band_idx];
- move16();
-
- IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
- {
- Copy32( mixing_matrix_res[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nY, nY ) );
- hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = mixing_matrix_res_exp[param_band_idx];
- move16();
- }
- }
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dequantize_cov()
- *
- * generate the target covariance matrix
- *------------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------------
- * ivas_param_mc_dequantize_cov_fx()
- *
- * generate the target covariance matrix
- *------------------------------------------------------------------------*/
-
-static void ivas_param_mc_dequantize_cov_fx(
- PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
- Word16 *ild_q_fx, /* i : sequence of dequantized ILD values Q8 */
- Word16 *icc_q_fx, /* i : sequence of dequantized ICC values Q15*/
- const Word16 param_band_index, /* i : current parameter band */
- const Word16 nY_cov, /* i : number of output channels in the covariance synthesis */
- const PARAM_MC_SYNTHESIS_CONF synth_conf, /* i : Parametric MC synthesis configuration */
- const Word16 nY_int, /* i : number of channels in the transported format */
- const Word16 nX, /* i : number of transport channels */
- Word32 *Cx_state_fx, /* i : transport channel covariance matrix */
- Word16 Cx_state_e, /* i : exponent for transport channel covariance matrix */
- Word32 *Cproto_fx, /* i : prototype matrix */
- Word16 Cproto_e, /* i : exponent for prototype matrix */
- Word32 *Cy_state_fx, /* o : target covariance matrix */
- Word16 *Cy_state_e /* o : exponent for target covariance matrix */
-)
-{
- Word16 Cy_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
- Word16 Cp_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
-
- Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Nrqq_e)
- Word16 Nrqq_e[MAX_OUTPUT_CHANNELS];
- Word32 a_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - a_e)
- Word16 a_e[MAX_OUTPUT_CHANNELS];
- Word16 k;
- Word16 l;
- Word32 *Cyp_fx; // Q(31 - Cyp_e)
- Word16 *Cyp_e;
- Word32 ap_fx; // Q(31 - ap_e)
- Word16 ap_e;
- Word32 L_tmp;
- Word16 tmp, tmp_e;
- const PARAM_MC_ILD_MAPPING *h_ild_mapping;
- Word32 Cy_state_int_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
- Word16 Cy_state_int_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
-
- set16_fx( Cp_buf_e, Cproto_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
- set32_fx( Nrqq_fx, 0, MAX_OUTPUT_CHANNELS );
- set16_fx( Nrqq_e, 0, MAX_OUTPUT_CHANNELS );
- h_ild_mapping = hParamMC->hMetadataPMC->ild_mapping_conf;
-
- /*get back Nrg*/
- tmp = 0;
- move16();
-
- FOR( k = 0; k < nY_int; k++ )
- {
- Word32 ref_ener_fx = 0; // Q(31 - ref_ener_e)
- move32();
- Word16 ref_ener_e = 0;
- move16();
- Word16 ref_channel_cnt;
- Word16 ref_channel_idx;
-
- FOR( ref_channel_cnt = 0; ref_channel_cnt < h_ild_mapping->num_ref_channels[k]; ref_channel_cnt++ )
- {
- ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt];
- move16();
- ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[ref_channel_idx + ( ref_channel_idx * nX )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e );
- move32();
- }
-
- L_tmp = Mpy_32_16_1( 713378626, ild_q_fx[k] ); /*Q24 : L_tmp Q31 for log2(10)/10 -> 713378626 */
- L_tmp = BASOP_util_Pow2( L_tmp, 31 - 24, &tmp_e ); /*powf( 10.0f, ild_q_fx[k] / 10.0f )*/
- L_tmp = Mpy_32_32( L_tmp, Mpy_32_16_1( ref_ener_fx, hParamMC->hMetadataPMC->ild_factors_fx[k] ) );
-
- Nrqq_fx[h_ild_mapping->ild_index[k]] = L_tmp;
- move32();
- Nrqq_e[h_ild_mapping->ild_index[k]] = add( tmp_e, ref_ener_e );
- move16();
- }
-
- /* estimate ICCs from estimated Cproto */
-
- FOR( k = 0; k < nY_int; k++ )
- {
- // a_fx[k] = 1.f / ( sqrtf( Cproto_fx[k + nY_int * k] ) + EPSILON );
- tmp_e = Cp_buf_e[k + ( nY_int * k )];
- move16();
-
- IF( Cproto_fx[k + ( nY_int * k )] != 0 )
- {
- L_tmp = ISqrt32( Cproto_fx[k + ( nY_int * k )], &tmp_e );
- }
- ELSE
- {
- L_tmp = INV_EPSILON_MANT;
- move32();
- tmp_e = 15;
- move16();
- }
- a_fx[k] = L_tmp;
- move32();
- a_e[k] = tmp_e;
- move16();
-
- FOR( l = 0; l < nY_int; l++ )
- {
- Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cproto_fx[( k * nY_int ) + l], a_fx[k] );
- move32();
- Cy_state_int_e[( k * nY_int ) + l] = add( Cp_buf_e[( k * nY_int ) + l], a_e[k] );
- move16();
- }
- }
-
- FOR( k = 0; k < nY_int; k++ )
- {
- Cyp_fx = Cy_state_int_fx + k;
- Cyp_e = Cy_state_int_e + k;
- ap_fx = a_fx[k];
- move32();
- ap_e = a_e[k];
- move16();
-
- FOR( l = 0; l < nY_int; l++ )
- {
- ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
- move32();
- *Cyp_e = add( *Cyp_e, ap_e );
- move16();
-
- Cyp_fx += nY_int;
- Cyp_e += nY_int;
- }
- }
-
- /*normalizing the Cy_state_int_fx to a common exponent*/
-
- /* replace some estimated ICCs with transmitted values */
- FOR( k = 0; k < hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; k++ )
- {
- Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp );
- move32();
- Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = tmp;
- move16();
- Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp );
- move32();
- Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = tmp;
- move16();
- }
-
- test();
- IF( GE_16( param_band_index, PARAM_MC_MAX_BAND_LFE ) || ( hParamMC->hMetadataPMC->lfe_on == 0 ) )
- {
- FOR( k = 0; k < nY_int; k++ )
- {
- Cy_state_int_fx[k + ( 3 * nY_int )] = ONE_IN_Q31;
- move32();
- Cy_state_int_e[k + ( 3 * nY_int )] = 0;
- move16();
- Cy_state_int_fx[3 + ( k * nY_int )] = ONE_IN_Q31;
- move32();
- Cy_state_int_e[3 + ( k * nY_int )] = 0;
- move16();
- }
- Nrqq_fx[3] = 0;
- move32();
- }
-
- /* Generate back Covariance Mtx */
- FOR( k = 0; k < nY_int; k++ )
- {
- tmp_e = Nrqq_e[k];
- move16();
- a_fx[k] = Sqrt32( Nrqq_fx[k], &tmp_e );
- move32();
- a_e[k] = tmp_e;
- move16();
-
- /* v_multc( Cy_state_int_fx + k * nY_int, a_fx[k], Cy_state_int_fx + k * nY_int, nY_int ) */
- FOR( l = 0; l < nY_int; l++ )
- {
- Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cy_state_int_fx[( k * nY_int ) + l], a_fx[k] );
- move32();
- Cy_state_int_e[( k * nY_int ) + l] = add( Cy_state_int_e[( k * nY_int ) + l], a_e[k] );
- move16();
- }
- }
-
- FOR( k = 0; k < nY_int; k++ )
- {
- Cyp_fx = Cy_state_int_fx + k;
- Cyp_e = Cy_state_int_e + k;
- ap_fx = a_fx[k];
- move32();
- ap_e = a_e[k];
- move16();
-
- FOR( l = 0; l < nY_int; l++ )
- {
- ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
- move32();
- ( *Cyp_e ) = add( *Cyp_e, ap_e );
- move16();
-
- Cyp_fx += nY_int;
- Cyp_e += nY_int;
- }
- }
-
- IF( EQ_32( synth_conf, PARAM_MC_SYNTH_LS_CONV_COV ) )
- {
- /* Cy = dmx*Cy*dmx' */
- Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
- Word16 mat_mult_buffer1_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
- Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; // Q(31 - target_ch_ener_e)
- Word16 target_ch_ener_e[MAX_CICP_CHANNELS];
- Word32 dmx_ch_ener_fx[MAX_CICP_CHANNELS];
-
- Word16 ls_conv_dmx_matrix_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
-
- set32_fx( target_ch_ener_fx, 0, MAX_CICP_CHANNELS );
- set16_fx( target_ch_ener_e, 0, MAX_CICP_CHANNELS );
- set32_fx( dmx_ch_ener_fx, 0, MAX_CICP_CHANNELS );
- set16_fx( ls_conv_dmx_matrix_e, 1, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
-
- matrix_product_mant_exp( hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 0,
- Cy_state_int_fx, Cy_state_int_e, nY_int, nY_int, 0,
- mat_mult_buffer1_fx, mat_mult_buffer1_e );
-
- matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_cov, nY_int, 0,
- hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 1,
- Cy_state_fx, Cy_buf_e );
-
- FOR( k = 0; k < nY_cov; k++ )
- {
- FOR( l = 0; l < nY_int; l++ )
- {
- L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[k + ( l * nY_cov )], Nrqq_fx[l] );
- tmp_e = add( ls_conv_dmx_matrix_e[k + ( l + nY_cov )], Nrqq_e[l] );
- L_tmp = BASOP_Util_Add_Mant32Exp( target_ch_ener_fx[k], target_ch_ener_e[k], L_tmp, tmp_e, &tmp_e );
- target_ch_ener_fx[k] = L_tmp;
- move32();
- target_ch_ener_e[k] = tmp_e;
- move16();
- }
-
- dmx_ch_ener_fx[k] = Cy_state_fx[k + ( nY_cov * k )];
- move32();
-
- IF( dmx_ch_ener_fx[k] < 0 )
- {
- Cy_state_fx[k + ( nY_cov * k )] = L_negate( Cy_state_fx[k + ( nY_cov * k )] );
- move32();
- dmx_ch_ener_fx[k] = L_negate( dmx_ch_ener_fx[k] );
- move32();
- }
-
- IF( extract_h( dmx_ch_ener_fx[k] ) == 0 )
- {
- target_ch_ener_fx[k] = 0;
- move32();
- target_ch_ener_e[k] = 0;
- move16();
- }
- ELSE
- {
- BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[k + ( nY_cov * k )], &tmp, &tmp_e );
- tmp = Sqrt16( tmp, &tmp_e );
- target_ch_ener_fx[k] = L_deposit_h( tmp );
- move32();
- target_ch_ener_e[k] = tmp_e;
- move16();
- }
-
- FOR( l = 0; l < nY_cov; l++ )
- {
- Cy_state_fx[( k * nY_cov ) + l] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[( k * nY_cov ) + l] );
- move32();
- Cy_buf_e[( k * nY_cov ) + l] = add( target_ch_ener_e[k], Cy_buf_e[( k * nY_cov ) + l] );
- move16();
- }
-
- Cyp_fx = Cy_state_fx + k;
- Cyp_e = Cy_buf_e + k;
- ap_fx = target_ch_ener_fx[k];
- move32();
- ap_e = target_ch_ener_e[k];
- move16();
- FOR( l = 0; l < nY_cov; l++ )
- {
- ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
- move32();
- *Cyp_e = add( *Cyp_e, ap_e );
- move16();
-
- Cyp_fx += nY_cov;
- Cyp_e += nY_cov;
- }
- }
- }
- ELSE
- {
- Copy32( Cy_state_int_fx, Cy_state_fx, imult1616( nY_int, nY_int ) );
- Copy( Cy_state_int_e, Cy_buf_e, imult1616( nY_int, nY_int ) );
- }
-
- /*normalize output matrix to a common exponent*/
- tmp = 0;
- FOR( k = 0; k < nY_int * nY_int; k++ )
- {
- Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] );
- move32();
- tmp = s_max( tmp, Cy_buf_e[k] );
- }
- FOR( k = 0; k < nY_int * nY_int; k++ )
- {
- L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) );
- Cy_state_fx[k] = L_tmp;
- move32();
- }
- *Cy_state_e = tmp;
- move16();
-
- return;
-}
-
-/*-------------------------------------------------------------------------*
- * param_mc_set_num_synth_bands()
- *
- * set the number of frequency bands to be synthesized
- *-------------------------------------------------------------------------*/
-
-static void param_mc_set_num_synth_bands(
- const Word32 output_Fs, /* i : output sampling frequency */
- PARAM_MC_DEC_HANDLE hParamMC /* i/o: Parametric MC handle */
-)
-{
- UWord16 max_param_band_synth;
- const Word16 *param_mc_bands_coded;
-
- SWITCH( hParamMC->hMetadataPMC->num_parameter_bands )
- {
- case 20:
- param_mc_bands_coded = param_mc_bands_coded_20;
- BREAK;
- case 10:
- param_mc_bands_coded = param_mc_bands_coded_10;
- BREAK;
- case 14:
- default:
- param_mc_bands_coded = param_mc_bands_coded_14;
- BREAK;
- }
- move16();
- SWITCH( output_Fs )
- {
- case 8000:
- max_param_band_synth = (UWord16) param_mc_bands_coded[NB];
- BREAK;
- case 16000:
- max_param_band_synth = (UWord16) param_mc_bands_coded[WB];
- BREAK;
- case 32000:
- max_param_band_synth = (UWord16) param_mc_bands_coded[SWB];
- BREAK;
- case 48000:
- default:
- max_param_band_synth = (UWord16) param_mc_bands_coded[FB];
- BREAK;
- }
- move16();
- hParamMC->num_param_bands_synth = s_min( hParamMC->hMetadataPMC->nbands_coded, max_param_band_synth );
- move16();
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------*
- * param_mc_get_diff_proto_info()
- *
- * calculated the diffuse prototype information
- *-------------------------------------------------------------------------*/
-
-
-static ivas_error param_mc_get_diff_proto_info_fx(
- const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */
- const UWord16 nchan_transport, /* i : number of transport channels */
- const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */
- PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, /* o : generated diffuse prototype info */
- Word16 Q_proto_mtx )
-{
- Word32 proto_fac_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
- UWord16 cur_out_ch;
- UWord16 cur_diff_proto;
- UWord16 cur_transport_ch;
- UWord16 max_num_src_chan;
-
- /* Initializations */
- max_num_src_chan = 0;
- move16();
-
- set_zero_fx( proto_fac_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
- IF( ( p_diff_proto_info->proto_index_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- set16_fx( p_diff_proto_info->proto_index_diff, 0, nchan_out_cov );
-
- IF( ( p_diff_proto_info->num_source_chan_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- set16_fx( p_diff_proto_info->num_source_chan_diff, 0, nchan_out_cov );
-
- /* we have at least one prototype, copy the first one */
- p_diff_proto_info->num_protos_diff = 1;
- move16();
-
- mvr2r_inc_fixed( proto_mtx, nchan_out_cov, proto_fac_fx, nchan_out_cov, nchan_transport );
- p_diff_proto_info->proto_index_diff[0] = 0;
- move16();
-
- /* search for distinct prototypes */
- FOR( cur_out_ch = 1; cur_out_ch < nchan_out_cov; cur_out_ch++ )
- {
- UWord16 found = 0;
- move16();
-
- FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
- {
- Word32 diff_fx = 0;
- move32();
- Word32 *proto_fac_ptr_fx = proto_fac_fx + cur_diff_proto;
- const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
- FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
- {
- diff_fx = L_add( diff_fx, L_abs( L_sub( *proto_fac_ptr_fx, *proto_mtx_ptr ) ) );
- proto_fac_ptr_fx += nchan_out_cov;
- proto_mtx_ptr += nchan_out_cov;
- }
-
- /* we already have this prototype, save the index */
- IF( LT_64( W_mult0_32_32( diff_fx, 10 ), L_shl_sat( 1, Q_proto_mtx ) ) )
- {
- found = 1;
- move16();
- p_diff_proto_info->proto_index_diff[cur_out_ch] = cur_diff_proto;
- move16();
- BREAK;
- }
- }
-
- /* new distinct prototype, add it */
- IF( found == 0 )
- {
- const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
- Word16 cur_num_src_chan;
-
- cur_num_src_chan = 0;
- move16();
- FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
- {
- if ( GT_32( *proto_mtx_ptr, 0 /*EPSILON*/ ) )
- {
- cur_num_src_chan = add( cur_num_src_chan, 1 );
- }
- proto_mtx_ptr += nchan_out_cov;
- }
-
- mvr2r_inc_fixed( proto_mtx + cur_out_ch, nchan_out_cov, proto_fac_fx + p_diff_proto_info->num_protos_diff, nchan_out_cov, nchan_transport );
-
- p_diff_proto_info->proto_index_diff[cur_out_ch] = p_diff_proto_info->num_protos_diff;
- move16();
- p_diff_proto_info->num_protos_diff = add( p_diff_proto_info->num_protos_diff, 1 );
- move16();
- max_num_src_chan = s_max( max_num_src_chan, cur_num_src_chan );
- }
- }
-
- /* set up the prototype info struct */
- IF( ( p_diff_proto_info->source_chan_idx = (Word16 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word16 * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
-
- IF( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
- FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
- {
- Word32 *proto_fac_ptr;
-
- IF( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (Word16 *) malloc( max_num_src_chan * sizeof( Word16 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
-
- IF( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
- }
-
- proto_fac_ptr = proto_fac_fx + cur_diff_proto;
- FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
- {
- IF( GT_32( *proto_fac_ptr, EPSILON_FX_SMALL ) )
- {
- p_diff_proto_info->source_chan_idx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = cur_transport_ch;
- move16();
- p_diff_proto_info->proto_fac_fx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = L_shl( *proto_fac_ptr, 4 ); // (proto_fac_fx)Q26 + 4 = Q30
- move16();
- p_diff_proto_info->num_source_chan_diff[cur_diff_proto] = add( p_diff_proto_info->num_source_chan_diff[cur_diff_proto], 1 );
- move16();
- }
- proto_fac_ptr += nchan_out_cov;
- }
- }
- return IVAS_ERR_OK;
-}
-
-
-/*-------------------------------------------------------------------------*
- * ivas_param_mc_bs_decode_parameter_values()
- *
- * reads and decodes a sequence of Parametric MC parameters from the bitstream
- *-------------------------------------------------------------------------*/
-
-static void ivas_param_mc_bs_decode_parameter_values_fx(
- UWord16 bit_buffer[], /* i : bitstream buffer */
- Word16 *bit_pos, /* i/o: current bitstream buffer position */
- const Word16 max_bits, /* i : maximum available bits in the buffer */
- Word16 *BER_detect, /* i/o: bit error detection flag */
- HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, /* i : Parametric MC metadata information */
- HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, /* i : Parametric MC parameter quantization and coding tables */
- const Word16 map_size_wo_lfe, /* i : number of parameters per band (w/o LFEs) */
- const Word16 map_size, /* i : number of parameters per band (total) */
- const Word16 num_lfe_bands, /* i : number of parameter bands with coded LFE */
- const Word16 band_step, /* i : parameter band step */
- const Word16 num_param_bands, /* i : number of parameter bands to decode */
- Word16 *value_buffer /* o : output buffer for decoded parameter values hParamCodingInfo -> Q-quant*/
-)
-{
- Word16 range_coding;
- Word16 sz_seq;
- Word16 delta_coding;
- Word16 delta_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
- Word16 idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
- Word16 idx_prev;
- Word16 idx_offset;
- Word16 sz_alphabet;
- Word16 i, j, k;
- Word16 dequant_seq_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
- Word16 dequant_ordered_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
- Word16 n_lfe_idx;
-
- range_coding = bit_buffer[*bit_pos];
- move16();
- *bit_pos = add( *bit_pos, 1 );
- move16();
-
- /* Decoding the sequence */
- n_lfe_idx = sub( map_size, map_size_wo_lfe );
- sz_seq = add( imult1616( num_param_bands, map_size_wo_lfe ), imult1616( num_lfe_bands, n_lfe_idx ) );
-
- set16_fx( idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
- set16_fx( dequant_ordered_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
- set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
- IF( range_coding )
- {
- delta_coding = bit_buffer[*bit_pos];
- move16();
- *bit_pos = add( *bit_pos, 1 );
- move16();
-
- IF( delta_coding )
- {
- idx_prev = sub( add( shr( hParamCodingInfo->quantizer_size, 1 ), hParamCodingInfo->quantizer_size % 2 ), 1 );
- sz_alphabet = sub( shl( hParamCodingInfo->quantizer_size, 1 ), 1 );
- idx_offset = sub( hParamCodingInfo->quantizer_size, 1 );
-
- /* read range coded delta ICC indices */
- *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], delta_idx, BER_detect, sz_seq, sz_alphabet,
- hParamCodingInfo->cum_freq_delta, hParamCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
- move16();
-
- /* delta index to absolute index */
- FOR( j = 0; j < sz_seq; j++ )
- {
- idx[j] = add( idx_prev, sub( delta_idx[j], idx_offset ) );
- idx_prev = idx[j];
- move16();
- }
- }
- ELSE
- {
- /* read range coded absolute ICC indices */
- sz_alphabet = hParamCodingInfo->quantizer_size;
- move16();
- *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], idx, BER_detect, sz_seq, sz_alphabet,
- hParamCodingInfo->cum_freq, hParamCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
- move16();
- }
-
- /* dequantize */
- FOR( j = 0; j < sz_seq; j++ )
- {
- dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; // hParamCodingInfo -> Q-quant
- move16();
- }
- }
- ELSE
- {
- set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
- /* read uniformly coded ICCs */
- *bit_pos = add( *bit_pos, ivas_param_mc_uniform_decoder_fx( dequant_seq_fx, sz_seq, hParamCodingInfo->quantizer_fx, hParamCodingInfo->uni_bits, &bit_buffer[*bit_pos] ) );
- move16();
- }
-
- /* reorder from sequential to parameter-band-wise */
- k = 0;
- FOR( j = 0; j < map_size_wo_lfe; ++j )
- {
- FOR( i = 0; i < num_param_bands; ++i )
- {
- dequant_ordered_fx[j + ( i * map_size )] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
- move16();
- k = add( k, 1 );
- }
- }
-
- FOR( i = 0; i < num_lfe_bands; i++ )
- {
- FOR( j = 0; j < n_lfe_idx; j++ )
- {
- dequant_ordered_fx[map_size - n_lfe_idx + j + i * map_size] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
- move16();
- k = add( k, 1 );
- }
- }
-
- IF( !( *BER_detect ) )
- {
- j = 0;
- FOR( k = 0; k < hMetadataPMC->nbands_coded; k += band_step )
- {
- test();
- IF( hMetadataPMC->bAttackPresent || EQ_16( hMetadataPMC->param_frame_idx, hMetadataPMC->coding_band_mapping[k] ) )
- {
- Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); // hParamCodingInfo -> Q-quant
- j++;
- }
- IF( hMetadataPMC->bAttackPresent && k + 1 < hMetadataPMC->nbands_coded )
- {
- Copy( value_buffer + imult1616( k, map_size ), value_buffer + imult1616( add( k, 1 ), map_size ), map_size );
- }
- }
- }
-
- return;
-}
diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c
index 0d9ee27107cedfdf97ef477e77d8c0882d2917ca..897fd4433f6e28cf1d44f6d55fe5f214c1b22c47 100644
--- a/lib_dec/ivas_mc_param_dec_fx.c
+++ b/lib_dec/ivas_mc_param_dec_fx.c
@@ -1,5 +1,3796 @@
+/******************************************************************************************************
+
+ (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository. All Rights Reserved.
+
+ This software is protected by copyright law and by international treaties.
+ The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository retain full ownership rights in their respective contributions in
+ the software. This notice grants no license of any kind, including but not limited to patent
+ license, nor is any license granted by implication, estoppel or otherwise.
+
+ Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
+ contributions.
+
+ This software is provided "AS IS", without any express or implied warranties. The software is in the
+ development stage. It is intended exclusively for experts who have experience with such software and
+ solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
+ and fitness for a particular purpose are hereby disclaimed and excluded.
+
+ Any dispute, controversy or claim arising under or in relation to providing this software shall be
+ submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
+ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
+ the United Nations Convention on Contracts on the International Sales of Goods.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "rom_enc.h"
+#include "rom_com.h"
+#include "prot_fx.h"
+#include "ivas_prot.h"
+#include "ivas_prot_rend.h"
+#include "ivas_cnst.h"
+#include "ivas_rom_com.h"
+#include "ivas_rom_dec.h"
+#include "math.h"
+#include "wmc_auto.h"
+#include "rom_dec.h"
#include "ivas_prot_fx.h"
+#define INV_EPSILON_MANT 214748365
+
+/*-----------------------------------------------------------------------*
+ * Local constants
+ *-----------------------------------------------------------------------*/
+
+#define PARAM_MC_LOCAL_SZ_LFE_MAP 5
+
+/*-----------------------------------------------------------------------*
+ * Local typedefs
+ *-----------------------------------------------------------------------*/
+
+typedef struct parameter_band_mapping_struct
+{
+ Word16 n_source_bands[20];
+ Word16 source_band_idx[20][4];
+ Word16 source_band_factor_fx[20][4]; /*Q15*/
+
+} PARAM_MC_PARAMETER_BAND_MAPPING;
+
+/*-----------------------------------------------------------------------*
+ * Local function prototypes
+ *-----------------------------------------------------------------------*/
+
+static void ivas_param_mc_dec_init_fx( PARAM_MC_DEC_HANDLE hParamMC, const Word16 nchan_in, const Word16 nchan_out );
+
+static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 nY, const Word16 slot_idx );
+static Word16 ivas_param_mc_range_decoder_LC_fx( UWord16 *bit_buffer, Word16 *x, Word16 *BER_detect, const Word16 sz_seq, const Word16 sz_alphabet, const UWord16 *cft, const UWord16 *sft, const Word16 tot_shift, const Word16 nbbits );
+
+
+static void ivas_param_mc_get_mixing_matrices_fx(
+ PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
+ IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
+ Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands */
+ Word16 Cx_in_e,
+ const Word16 param_band_idx,
+ Word32 *mixing_matrix_fx[],
+ Word16 *mixing_matrix_e,
+ Word32 *mixing_matrix_res_fx[],
+ Word16 *mixing_matrix_res_e,
+ const Word16 nY_intern, /* i : number of channels in the transported format */
+ const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */
+ const Word16 nX, /* i : number of transport channels */
+ const Word16 nY_cov /* i : number of covariance synthesis output channels */
+);
+
+static Word16 ivas_param_mc_uniform_decoder_fx( Word16 *seq, const Word16 sz_seq, const Word16 *alphabet, const Word16 N, UWord16 bit_buffer[PARAM_MC_MAX_BITS] );
+static void ivas_param_mc_dec_compute_interpolator_fx( const UWord16 bAttackPresent, const UWord16 attackPos, const UWord16 interp_length, Word16 *interpolator );
+
+static void param_mc_set_num_synth_bands( const Word32 output_Fs, PARAM_MC_DEC_HANDLE hParamMC );
+
+static void ivas_param_mc_get_param_band_mapping( const Word16 n_target_bands, const Word16 *target_band_grouping, const Word16 n_source_bands, const Word16 *source_band_grouping, PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping );
+
+
+static void ivas_param_mc_bs_decode_parameter_values_fx( UWord16 bit_buffer[], Word16 *bit_pos, const Word16 max_bits, Word16 *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const Word16 map_size_wo_lfe, const Word16 map_size, const Word16 num_lfe_bands, const Word16 band_step, const Word16 num_param_bands, Word16 *value_buffer );
+static void ivas_param_mc_dequantize_cov_fx( PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e );
+static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, Word16 Q_proto_mtx );
+static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY );
+
+
+static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t num_freq_bands /*, Word16 RealBuffer_fx_e, Word16 ImagBuffer_fx_e, Word16 *common_e*/ );
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dec_open()
+ *
+ * Open Parametric MC decoder handle
+ *-------------------------------------------------------------------------*/
+
+ivas_error ivas_param_mc_dec_open_fx(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+)
+{
+ Word16 k, nchan_transport;
+ PARAM_MC_DEC_HANDLE hParamMC;
+ Word16 nchan_out_transport;
+ Word16 nchan_out_cov;
+ Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
+ Word32 proto_mtx_norm_fx;
+ Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
+ Word16 max_param_band_residual;
+ UWord16 config_index;
+ MC_LS_SETUP mc_ls_setup;
+ AUDIO_CONFIG output_config;
+ Word32 output_Fs, ivas_total_brate;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+ move32();
+
+ /*-----------------------------------------------------------------*
+ * prepare library opening
+ *-----------------------------------------------------------------*/
+
+ IF( ( hParamMC = (PARAM_MC_DEC_HANDLE) malloc( sizeof( PARAM_MC_DEC_DATA ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+
+ IF( ( hParamMC->hMetadataPMC = (HANDLE_IVAS_PARAM_MC_METADATA) malloc( sizeof( IVAS_PARAM_MC_METADATA ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC metadata \n" ) );
+ }
+
+ output_Fs = st_ivas->hDecoderConfig->output_Fs;
+ move32();
+ output_config = st_ivas->hDecoderConfig->output_config;
+ move32();
+ ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
+ move32();
+ mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
+ nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
+ hParamMC->hoa_encoder_fx = NULL;
+
+ /* determine the synthesis config */
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( st_ivas->transport_config, output_config ) )
+ {
+ hParamMC->synthesis_conf = PARAM_MC_SYNTH_DIRECT;
+ move32();
+ }
+ ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
+ {
+ hParamMC->synthesis_conf = PARAM_MC_SYNTH_MONO_STEREO;
+ move32();
+ }
+ ELSE IF( NE_32( st_ivas->transport_config, output_config ) )
+ {
+ test();
+ test();
+ IF( ( NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, audioCfg2channels( output_config ) ) ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, st_ivas->hOutSetup.nchan_out_woLFE ) ) )
+ {
+ hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_COV;
+ move32();
+ /* need to reset the intern config */
+ st_ivas->intern_config = output_config;
+ move32();
+ ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
+ IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
+ {
+ st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk;
+ move32();
+ st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; // Q22
+ st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; // Q22
+ }
+ }
+ ELSE
+ {
+ hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_CLDFB;
+ move32();
+ }
+ }
+
+ hParamMC->ls_conv_dmx_matrix_fx = NULL;
+
+ test();
+ IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
+ }
+ ELSE
+ {
+ nchan_out_cov = nchan_out_transport;
+ move16();
+ }
+
+ st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
+ move16();
+ config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
+ nchan_transport = st_ivas->nchan_transport;
+ move16();
+
+ SWITCH( nchan_transport )
+ {
+ case 4:
+ case 3:
+ st_ivas->nCPE = 2;
+ move16();
+ st_ivas->nSCE = 0;
+ move16();
+ st_ivas->element_mode_init = IVAS_CPE_MDCT;
+ move16();
+ BREAK;
+ case 2:
+ st_ivas->nCPE = 1;
+ move16();
+ st_ivas->nSCE = 0;
+ move16();
+ st_ivas->element_mode_init = IVAS_CPE_MDCT;
+ move16();
+
+ BREAK;
+ }
+
+ /*-----------------------------------------------------------------*
+ * set input parameters
+ *-----------------------------------------------------------------*/
+
+ // hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX;
+ Word16 temp_e;
+ Word16 temp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &temp_e );
+ temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0
+ temp = BASOP_Util_Divide1616_Scale( temp, CLDFB_NO_COL_MAX, &temp_e );
+ temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0
+ hParamMC->slot_size = temp;
+ move16();
+ set16_fx( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
+ set16_fx( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
+ hParamMC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
+ move16();
+
+ // hParamMC->num_freq_bands = (int16_t)(output_Fs * INV_CLDFB_BANDWIDTH + 0.5f);
+ hParamMC->num_freq_bands = extract_l( Mpy_32_32_r( output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) );
+ move16();
+ hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands;
+ move16();
+ ivas_param_mc_metadata_open_fx( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC );
+
+ /* init arrays for quantized parameters */
+
+ IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); // Q8
+ set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) ); // Q15
+
+ param_mc_set_num_synth_bands( output_Fs, hParamMC );
+
+ /* Band Grouping */
+ IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) )
+ {
+ Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 );
+ }
+ ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) )
+ {
+ Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 );
+ }
+ ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) )
+ {
+ Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 );
+ }
+ ELSE
+ {
+ assert( 0 && "nbands must be 20, 14, or 10!" );
+ }
+
+ /* set max parameter band for abs cov */
+ k = 0;
+ move16();
+ WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) )
+ {
+ hParamMC->max_param_band_abs_cov = k;
+ move16();
+ k = add( k, 1 );
+ }
+
+ /*-----------------------------------------------------------------*
+ * open sub-modules
+ *-----------------------------------------------------------------*/
+
+ /* prototype signal computation */
+
+ test();
+ test();
+ IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+
+ /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */
+ test();
+ IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+
+ FOR( k = 0; k < nchan_out_transport; k++ )
+ {
+ Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); /*Q30*/
+ }
+
+ /* convert ParamMC parameter bands to SFB */
+ IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth;
+ move16();
+ FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ )
+ {
+ st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] );
+ move16();
+ }
+ }
+ ELSE
+ {
+ /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */
+ ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
+ }
+ }
+ }
+ IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, imult1616( nchan_transport, nchan_out_transport ) ); /*Q31*/
+
+ hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport );
+ move16();
+
+ test();
+ IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); /*Q.26*/
+ matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx ); /*Q.26*/
+ Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); /*Q.26*/
+ IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ proto_mtx_norm_fx = ONE_IN_Q26; /*Q26*/
+ move32();
+ FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ )
+ {
+ proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); /*Q.26*/
+ }
+ proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/
+
+ /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */
+ FOR( k = 0; k < nchan_transport; k++ )
+ {
+ FOR( Word16 i = 0; i < nchan_out_cov; i++ )
+ {
+ st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[k * nchan_out_cov + i], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/
+ move32();
+ }
+ }
+ }
+ }
+ ELSE
+ {
+ Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); /*Q.31*/
+ Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); /*Scaling down to 26*/
+ }
+
+ IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ hParamMC->num_outputs_diff = 0;
+ move16();
+ hParamMC->diff_proto_info = NULL;
+ hParamMC->h_output_synthesis_params.use_onset_filters = 0;
+ move16();
+ hParamMC->max_band_decorr = 0;
+ move16();
+ hParamMC->h_freq_domain_decorr_ap_params = NULL;
+ hParamMC->h_freq_domain_decorr_ap_state = NULL;
+ }
+ ELSE
+ {
+ hParamMC->num_outputs_diff = nchan_out_cov;
+ move16();
+ IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+
+ IF( NE_32( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+
+ /* decorrelation */
+ hParamMC->h_freq_domain_decorr_ap_params = NULL;
+ hParamMC->h_freq_domain_decorr_ap_state = NULL;
+
+ ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0
+
+ IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff,
+ hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ),
+ IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+
+ hParamMC->h_output_synthesis_params.use_onset_filters = 0;
+ move16();
+ hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr;
+ move16();
+ }
+ hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded];
+ move16();
+ max_param_band_residual = 0;
+ move16();
+
+ FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
+ {
+ IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
+ {
+ max_param_band_residual = k;
+ move16();
+ assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr );
+ break;
+ }
+ }
+
+ /* output synthesis */
+ IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+
+ ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx );
+
+ /* Head or external rotation */
+ test();
+ test();
+ test();
+ IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
+ {
+ IF( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hParamMC->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER );
+ }
+
+ /*-----------------------------------------------------------------*
+ * memory allocation
+ *-----------------------------------------------------------------*/
+
+ IF( hParamMC->max_band_decorr > 0 )
+ {
+ IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ IF( ( hParamMC->proto_frame_dec_f_fx = (Word32 *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ }
+ ELSE
+ {
+ hParamMC->proto_frame_f_fx = NULL;
+ hParamMC->proto_frame_dec_f_fx = NULL;
+ }
+
+ ivas_param_mc_dec_init_fx( hParamMC, nchan_transport, nchan_out_cov );
+
+ IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ Word16 n_cldfb_slots;
+
+ n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS;
+ move16();
+ IF( st_ivas->hDecoderConfig->Opt_tsm )
+ {
+ n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS;
+ move16();
+ }
+
+ Word16 cldfb_buf_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
+ IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
+ }
+ set32_fx( hParamMC->Cldfb_RealBuffer_tc_fx, 0, cldfb_buf_size );
+ IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
+ }
+ set32_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, 0, cldfb_buf_size );
+
+ hParamMC->sz = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
+ move16();
+
+ IF( st_ivas->hTcBuffer == NULL )
+ {
+ IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+ }
+ }
+ ELSE
+ {
+ hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
+ hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
+ }
+
+ hParamMC->subframes_rendered = 0;
+ move16();
+ hParamMC->slots_rendered = 0;
+ move16();
+
+ st_ivas->hParamMC = hParamMC;
+ return error;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_get_param_band_mapping()
+ *
+ *
+ *-------------------------------------------------------------------------*/
+
+static void ivas_param_mc_get_param_band_mapping(
+ const Word16 n_target_bands,
+ const Word16 *target_band_grouping,
+ const Word16 n_source_bands,
+ const Word16 *source_band_grouping,
+ PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping )
+{
+ Word16 target_band_idx;
+ Word16 source_band_idx = 0;
+ move16();
+ Word16 source_band_cnt_total;
+
+ FOR( target_band_idx = 0; target_band_idx < n_target_bands; target_band_idx++ )
+ {
+ Word16 upper = target_band_grouping[target_band_idx + 1];
+ Word16 lower = target_band_grouping[target_band_idx];
+ Word16 source_band_in_target_band_cnt = 0;
+ Word16 norm_fac_fx = 32767; // 1.Q15
+ source_band_cnt_total = 0;
+ move16();
+ move16();
+ move16();
+
+ FOR( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ )
+ {
+ /* find lowest corresponding source band*/
+ test();
+ IF( LE_16( source_band_grouping[source_band_idx], lower ) && GE_16( source_band_grouping[source_band_idx + 1], lower ) )
+ {
+ DO
+ {
+ Word16 source_bands_in_target_band = sub( s_min( source_band_grouping[source_band_idx + 1], upper ), s_max( source_band_grouping[source_band_idx], lower ) );
+ IF( source_bands_in_target_band )
+ {
+ source_band_cnt_total = add( source_band_cnt_total, source_bands_in_target_band );
+ parameter_band_mapping->source_band_idx[target_band_idx][source_band_in_target_band_cnt] = source_band_idx;
+ parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_in_target_band_cnt++] = shl( source_bands_in_target_band, 10 ); /*Q10*/
+ move16();
+ move16();
+ }
+ source_band_idx++;
+ }
+ WHILE( LE_16( source_band_grouping[source_band_idx], upper ) && LT_16( source_band_idx, n_source_bands ) );
+ BREAK;
+ }
+ }
+ norm_fac_fx = div_s( 1, source_band_cnt_total ); /*Q15*/
+ FOR( source_band_idx = 0; source_band_idx < source_band_in_target_band_cnt; source_band_idx++ )
+ {
+ parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx] = shl_sat( mult( parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx], norm_fac_fx ) /*Q10*/, 5 ); /*Q15*/
+ move16();
+ }
+ parameter_band_mapping->n_source_bands[target_band_idx] = source_band_in_target_band_cnt;
+ move16();
+ }
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dec_reconfig()
+ *
+ * Reconfiguration of ParamMC decoder
+ *-------------------------------------------------------------------------*/
+
+ivas_error ivas_param_mc_dec_reconfig_fx(
+ Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+)
+{
+ Word16 k, nchan_transport;
+ PARAM_MC_DEC_HANDLE hParamMC;
+ Word16 nchan_out_transport;
+ Word16 nchan_out_cov;
+ Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
+ Word32 proto_mtx_norm_fx;
+ Word16 max_param_band_residual;
+ UWord16 config_index;
+ MC_LS_SETUP mc_ls_setup;
+ Word32 output_Fs, ivas_total_brate;
+ ivas_error error;
+ Word16 nchan_transport_old;
+ Word16 num_param_bands_old;
+ PARAM_MC_PARAMETER_BAND_MAPPING parameter_band_mapping;
+ Word16 band_grouping_old[20 + 1];
+
+ hParamMC = st_ivas->hParamMC;
+ error = IVAS_ERR_OK;
+ move32();
+ /* save important config information from the previous state */
+ nchan_transport_old = st_ivas->nchan_transport;
+ move32();
+ num_param_bands_old = hParamMC->hMetadataPMC->num_parameter_bands;
+ move32();
+
+ /*-----------------------------------------------------------------*
+ * prepare library opening
+ *-----------------------------------------------------------------*/
+
+ output_Fs = st_ivas->hDecoderConfig->output_Fs;
+ move32();
+ ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
+ move32();
+ mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
+ nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
+
+ test();
+ IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
+ }
+ ELSE
+ {
+ nchan_out_cov = nchan_out_transport;
+ move16();
+ }
+
+ st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
+ move16();
+ config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
+ nchan_transport = st_ivas->nchan_transport;
+ move16();
+
+ SWITCH( nchan_transport )
+ {
+ case 4:
+ case 3:
+ st_ivas->nCPE = 2;
+ move16();
+ st_ivas->nSCE = 0;
+ move16();
+ st_ivas->element_mode_init = IVAS_CPE_MDCT;
+ move16();
+ BREAK;
+ case 2:
+ st_ivas->nCPE = 1;
+ move16();
+ st_ivas->nSCE = 0;
+ move16();
+ st_ivas->element_mode_init = IVAS_CPE_MDCT;
+ move16();
+
+ BREAK;
+ }
+
+ /*-----------------------------------------------------------------*
+ * set input parameters
+ *-----------------------------------------------------------------*/
+ hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); // Q0
+ move16();
+ hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands;
+ move16();
+
+ Copy( hParamMC->band_grouping, band_grouping_old, add( hParamMC->hMetadataPMC->num_parameter_bands, 1 ) );
+ ivas_param_mc_metadata_open_fx( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC );
+ /* Band Grouping */
+ IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) )
+ {
+ Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 );
+ }
+ ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) )
+ {
+ Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 );
+ }
+ ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) )
+ {
+ Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 );
+ }
+ ELSE
+ {
+ assert( 0 && "nbands must be 20, 14, or 10!" );
+ }
+
+ ivas_param_mc_get_param_band_mapping( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->band_grouping, num_param_bands_old, band_grouping_old, ¶meter_band_mapping );
+
+ test();
+ IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) )
+ {
+ Word16 *ild_q_old_fx = hParamMC->icld_q_fx; // Q8
+ Word16 *icc_q_old_fx = hParamMC->icc_q_fx; // Q15
+
+ IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); /*Q8*/
+ set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); /*Q15*/
+
+ /* map old to new parameter banding, only for same number of TCs, needs some more thought for a changing number of TCs */
+ test();
+ IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) )
+ {
+ Word16 new_param_band_idx, param_idx, source_param_idx;
+ Word16 num_param_lfe;
+ Word16 *p_icc_new_fx = hParamMC->icc_q_fx; // Q15
+ Word16 *p_ild_new_fx = hParamMC->icld_q_fx; // Q8
+ Word16 p_ild_new_e = 23;
+ move16();
+ Word16 p_ild_new_tmp;
+
+ /* ICC */
+ num_param_lfe = hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe;
+ move16();
+ FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
+ {
+ FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ )
+ {
+ *p_icc_new_fx = 0;
+ move16();
+ FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
+ {
+ *p_icc_new_fx = add( *p_icc_new_fx, mult( icc_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); /*Q15*/
+ move16();
+ }
+ p_icc_new_fx++;
+ }
+ }
+
+ /* ILD */
+ num_param_lfe = hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe;
+ move16();
+ FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
+ {
+ FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ )
+ {
+ *p_ild_new_fx = 0;
+ move16();
+ FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
+ {
+ p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); // 31 - p_ild_new_e - 16
+ *p_ild_new_fx = add( *p_ild_new_fx, mult( p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) );
+ move16();
+ }
+ *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, L_shl( p_ild_new_e, 25 ) ) ), 24660 /*3.Q13*/ ), 15 ) ); // Q8
+ move16();
+ p_ild_new_fx++;
+ }
+ }
+ }
+ free( ild_q_old_fx );
+ free( icc_q_old_fx );
+ }
+
+ param_mc_set_num_synth_bands( output_Fs, hParamMC );
+
+ /* set max parameter band for abs cov */
+ k = 0;
+ move16();
+ WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) )
+ {
+ hParamMC->max_param_band_abs_cov = k;
+ move16();
+ k = add( k, 1 );
+ }
+
+ /*-----------------------------------------------------------------*
+ * open sub-modules
+ *-----------------------------------------------------------------*/
+
+ /* prototype signal computation */
+
+ IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ IF( NE_16( nchan_transport_old, nchan_transport ) )
+ {
+ IF( st_ivas->hLsSetUpConversion != NULL )
+ {
+ ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
+ }
+
+ IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+
+ /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */
+ free( hParamMC->ls_conv_dmx_matrix_fx );
+
+ IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ FOR( k = 0; k < nchan_out_transport; k++ )
+ {
+ Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov );
+ }
+ }
+ /* convert ParamMC parameter bands to SFB */
+
+ st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth;
+ move16();
+ FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ )
+ {
+ st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] );
+ move16();
+ }
+ FOR( ; k < MAX_SFB + 2; k++ )
+ {
+ st_ivas->hLsSetUpConversion->sfbOffset[k] = 0;
+ move16();
+ }
+ }
+
+ IF( NE_16( nchan_transport_old, nchan_transport ) )
+ {
+ free( hParamMC->proto_matrix_int_fx );
+ IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport );
+ move16();
+ Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, hParamMC->proto_matrix_int_len ); /*Q31*/
+ }
+
+ test();
+ IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); // Q30 -> Q26
+ matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0,
+ ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0,
+ proto_matrix_fx /*Q26*/ );
+ Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); // Q26 -> Q30
+
+ IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ proto_mtx_norm_fx = ONE_IN_Q26; // Q26
+ move32();
+ FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ )
+ {
+ proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); // Q26
+ }
+ proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/
+
+ /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */
+ FOR( k = 0; k < nchan_transport; k++ )
+ {
+ FOR( Word16 i = 0; i < nchan_out_cov; i++ )
+ {
+ st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); // Q26 -> Q30
+ move32();
+ }
+ }
+ }
+ }
+ ELSE
+ {
+ Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); // proto_matrix_fx -> Q31
+ Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); // proto_matrix_fx -> Q26
+ }
+
+ test();
+ IF( NE_16( nchan_transport_old, nchan_transport ) && NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ Word16 i;
+ Word16 len;
+
+ /* close decorrelator */
+ ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state );
+
+ /* deallocate diffuse prototype info */
+ IF( hParamMC->diff_proto_info )
+ {
+ FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ )
+ {
+ free( hParamMC->diff_proto_info->source_chan_idx[i] );
+ hParamMC->diff_proto_info->source_chan_idx[i] = NULL;
+
+ free( hParamMC->diff_proto_info->proto_fac_fx[i] );
+ hParamMC->diff_proto_info->proto_fac_fx[i] = NULL;
+ }
+
+ free( hParamMC->diff_proto_info->source_chan_idx );
+ hParamMC->diff_proto_info->source_chan_idx = NULL;
+
+ free( hParamMC->diff_proto_info->proto_fac_fx );
+ hParamMC->diff_proto_info->proto_fac_fx = NULL;
+
+ free( hParamMC->diff_proto_info->proto_index_diff );
+ hParamMC->diff_proto_info->proto_index_diff = NULL;
+
+ free( hParamMC->diff_proto_info->num_source_chan_diff );
+ hParamMC->diff_proto_info->num_source_chan_diff = NULL;
+
+ free( hParamMC->diff_proto_info );
+ hParamMC->diff_proto_info = NULL;
+ }
+
+ hParamMC->num_outputs_diff = nchan_out_cov;
+ move16();
+ IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ IF( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ /* decorrelation */
+ hParamMC->h_freq_domain_decorr_ap_params = NULL;
+ hParamMC->h_freq_domain_decorr_ap_state = NULL;
+
+ Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
+ ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0
+
+ IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff,
+ hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ),
+ IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+ hParamMC->h_output_synthesis_params.use_onset_filters = 0;
+ move16();
+ hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr;
+ move16();
+ /* init decorrelation */
+ IF( hParamMC->max_band_decorr > 0 )
+ {
+
+ len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr );
+
+ /* init onsetDetectionPower */
+ set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
+ set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
+ hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
+ move16();
+ }
+ }
+ hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded];
+ move16();
+ max_param_band_residual = 0;
+ move16();
+
+ FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
+ {
+ IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
+ {
+ max_param_band_residual = k;
+ move16();
+ assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr );
+ BREAK;
+ }
+ }
+
+ test();
+ IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) )
+ {
+ DIRAC_OUTPUT_SYNTHESIS_COV_STATE cov_state_old = hParamMC->h_output_synthesis_cov_state;
+ DIRAC_OUTPUT_SYNTHESIS_PARAMS params_old = hParamMC->h_output_synthesis_params;
+
+ Word32 tmp_buf_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
+
+ set_zero_fx( tmp_buf_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
+
+ /* output synthesis */
+ IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS,
+ hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ),
+ IVAS_ERR_OK ) )
+ {
+ return error;
+ }
+
+ ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx );
+
+ ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual );
+
+ /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */
+ test();
+ IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) )
+ {
+ Word16 new_param_band_idx, source_param_idx;
+
+ FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
+ {
+ FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
+ {
+ /* Cx */
+ v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_transport_old ) ); // Q(31 - cov_state_old.cx_old_e)
+ v_add_fixed_me( tmp_buf_fx, cov_state_old.cx_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], imult1616( nchan_transport_old, nchan_transport_old ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx])
+ /* Cy */
+ v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - cov_state_old.cy_old_e)
+ v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx])
+ /* mixing matrix*/
+ v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) ); // Q(31 - mixing_matrix_old_exp)
+ v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx])
+ }
+ }
+ FOR( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ )
+ {
+ FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
+ {
+ /* residual mixing matrix*/
+ v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - mixing_matrix_res_old_exp)
+ v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx])
+ }
+ }
+ }
+ ivas_dirac_dec_output_synthesis_cov_close_fx( ¶ms_old, &cov_state_old );
+ }
+
+ /*-----------------------------------------------------------------*
+ * memory allocation
+ *-----------------------------------------------------------------*/
+
+ test();
+ IF( ( hParamMC->max_band_decorr > 0 ) && NE_16( nchan_transport_old, nchan_transport ) )
+ {
+ free( hParamMC->proto_frame_f_fx );
+ IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
+ }
+
+
+ IF( NE_16( nchan_transport_old, nchan_transport ) )
+ {
+ IF( NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ Word16 n_cldfb_slots;
+ IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
+ {
+ free( hParamMC->Cldfb_RealBuffer_tc_fx );
+ hParamMC->Cldfb_RealBuffer_tc_fx = NULL; // Q12
+ }
+ IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
+ {
+ free( hParamMC->Cldfb_ImagBuffer_tc_fx );
+ hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; // Q12
+ }
+
+ n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS;
+ move16();
+ IF( st_ivas->hDecoderConfig->Opt_tsm )
+ {
+ n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS;
+ move16();
+ }
+ Word16 cldfb_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
+ IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
+ }
+ set_zero_fx( hParamMC->Cldfb_RealBuffer_tc_fx, cldfb_size );
+
+ IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
+ }
+ set_zero_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, cldfb_size );
+ }
+ ELSE
+ {
+ IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
+ {
+ free( hParamMC->Cldfb_RealBuffer_tc_fx );
+ hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
+ }
+ IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
+ {
+ free( hParamMC->Cldfb_ImagBuffer_tc_fx );
+ hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
+ }
+ }
+ }
+ return error;
+}
+
+
+/*-------------------------------------------------------------------------
+ * param_mc_get_num_cldfb_syntheses()
+ *
+ * calculate the necessary number of CLDFB synthesis instances
+ *------------------------------------------------------------------------*/
+
+/*! r: number of cldfb synthesis instances */
+Word16 param_mc_get_num_cldfb_syntheses_fx(
+ Decoder_Struct *st_ivas /* i : Parametric MC handle */
+)
+{
+ Word16 num_cldfb_syntheses;
+
+ num_cldfb_syntheses = 0;
+ move16();
+
+ /* sanity check*/
+ IF( st_ivas->hParamMC == NULL )
+ {
+ assert( 0 && "ParamMC handle does not exist!\n" );
+ }
+
+ test();
+ IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
+ {
+ num_cldfb_syntheses = 2;
+ move16();
+ }
+ ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
+ {
+ num_cldfb_syntheses = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
+ }
+ ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) )
+ {
+ num_cldfb_syntheses = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
+ }
+
+ return num_cldfb_syntheses;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dec_close()
+ *
+ * Close Parametric MC memories
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_dec_close_fx(
+ PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */
+)
+{
+ UWord16 i;
+ PARAM_MC_DEC_HANDLE hParamMC;
+
+ IF( hParamMC_out == NULL || *hParamMC_out == NULL )
+ {
+ return;
+ }
+
+ hParamMC = *hParamMC_out;
+
+ /* close sub-modules */
+ ivas_dirac_dec_output_synthesis_cov_close_fx( &hParamMC->h_output_synthesis_params, &hParamMC->h_output_synthesis_cov_state );
+
+ IF( hParamMC->h_freq_domain_decorr_ap_params != NULL || hParamMC->h_freq_domain_decorr_ap_state != NULL )
+ {
+ ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state );
+ }
+
+ /* parameter decoding */
+ IF( hParamMC->hMetadataPMC != NULL )
+ {
+ free( hParamMC->hMetadataPMC );
+ hParamMC->hMetadataPMC = NULL;
+ }
+ IF( hParamMC->icc_q_fx != NULL )
+ {
+ free( hParamMC->icc_q_fx );
+ hParamMC->icc_q_fx = NULL; // Q15
+ }
+
+ IF( hParamMC->icld_q_fx != NULL )
+ {
+ free( hParamMC->icld_q_fx );
+ hParamMC->icld_q_fx = NULL; // Q8
+ }
+ /* diffuse prototype info */
+ IF( hParamMC->diff_proto_info )
+ {
+ FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ )
+ {
+ free( hParamMC->diff_proto_info->source_chan_idx[i] );
+ hParamMC->diff_proto_info->source_chan_idx[i] = NULL;
+
+ free( hParamMC->diff_proto_info->proto_fac_fx[i] );
+ hParamMC->diff_proto_info->proto_fac_fx[i] = NULL;
+ }
+
+ free( hParamMC->diff_proto_info->source_chan_idx );
+ hParamMC->diff_proto_info->source_chan_idx = NULL;
+
+ free( hParamMC->diff_proto_info->proto_fac_fx );
+ hParamMC->diff_proto_info->proto_fac_fx = NULL;
+
+ free( hParamMC->diff_proto_info->proto_index_diff );
+ hParamMC->diff_proto_info->proto_index_diff = NULL;
+
+ free( hParamMC->diff_proto_info->num_source_chan_diff );
+ hParamMC->diff_proto_info->num_source_chan_diff = NULL;
+
+ free( hParamMC->diff_proto_info );
+ hParamMC->diff_proto_info = NULL;
+ }
+ /* States */
+ /* free prototype signal buffers */
+ IF( hParamMC->proto_frame_f_fx != NULL )
+ {
+ free( hParamMC->proto_frame_f_fx );
+ hParamMC->proto_frame_f_fx = NULL;
+ }
+
+ IF( hParamMC->proto_frame_dec_f_fx != NULL )
+ {
+ free( hParamMC->proto_frame_dec_f_fx );
+ hParamMC->proto_frame_dec_f_fx = NULL;
+ }
+
+ IF( hParamMC->ls_conv_dmx_matrix_fx != NULL )
+ {
+ free( hParamMC->ls_conv_dmx_matrix_fx );
+ hParamMC->ls_conv_dmx_matrix_fx = NULL;
+ }
+
+ IF( hParamMC->proto_matrix_int_fx != NULL )
+ {
+ free( hParamMC->proto_matrix_int_fx );
+ hParamMC->proto_matrix_int_fx = NULL;
+ }
+
+ IF( hParamMC->hoa_encoder_fx != NULL )
+ {
+ free( hParamMC->hoa_encoder_fx );
+ hParamMC->hoa_encoder_fx = NULL;
+ }
+ IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
+ {
+ free( hParamMC->Cldfb_RealBuffer_tc_fx );
+ hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
+ }
+ IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
+ {
+ free( hParamMC->Cldfb_ImagBuffer_tc_fx );
+ hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
+ }
+
+ free( *hParamMC_out );
+ *hParamMC_out = NULL;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dec_read_BS()
+ *
+ * Read the Parametric MC metadata
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_dec_read_BS_fx(
+ const Word32 ivas_total_brate, /* i : IVAS total bitrate */
+ Decoder_State *st, /* i/o: decoder state structure */
+ PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder ParamMC handle */
+ Word16 *nb_bits /* o : number of bits written */
+)
+{
+ Word16 param_frame_idx;
+ Word16 band_step;
+ UWord16 bit_buffer[PARAM_MC_MAX_BITS];
+ Word16 bits_to_copy;
+ Word16 bit_pos;
+ Word16 num_lfe_bands;
+ Word16 num_param_bands;
+ Word16 metadata_bit_pos;
+ Word16 i, j, k;
+ Word16 icc_map_size;
+ Word16 icc_map_size_wo_lfe;
+ Word16 ild_map_size;
+ Word16 ild_map_size_wo_lfe;
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC;
+
+ push_wmops( "param_mc_read_bs" );
+
+ /* Inits */
+ *nb_bits = 0;
+ move16();
+ hMetadataPMC = hParamMC->hMetadataPMC;
+ icc_map_size = hMetadataPMC->icc_mapping_conf->icc_map_size_lfe;
+ move16();
+ icc_map_size_wo_lfe = hMetadataPMC->icc_mapping_conf->icc_map_size_wo_lfe;
+ move16();
+ ild_map_size = hMetadataPMC->ild_mapping_conf->ild_map_size_lfe;
+ move16();
+ ild_map_size_wo_lfe = hMetadataPMC->ild_mapping_conf->ild_map_size_wo_lfe;
+ move16();
+
+ IF( !st->bfi )
+ {
+ /*metadata_bit_pos = extract_l(ivas_total_brate / FRAMES_PER_SEC - 1);
+ bits_to_copy = s_min(extract_l(ivas_total_brate / FRAMES_PER_SEC), PARAM_MC_MAX_BITS);*/
+ Word16 temp = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
+ metadata_bit_pos = sub( temp, 1 );
+ bits_to_copy = s_min( temp, PARAM_MC_MAX_BITS );
+
+ /* copy and reverse metadata */
+ FOR( bit_pos = 0; bit_pos < bits_to_copy; bit_pos++ )
+ {
+ bit_buffer[bit_pos] = st->bit_stream[metadata_bit_pos];
+ move16();
+ metadata_bit_pos = sub( metadata_bit_pos, 1 );
+ move16();
+ }
+
+ bit_pos = 0;
+ move16();
+
+ /* read reserved bit */
+ hMetadataPMC->lfe_on = bit_buffer[bit_pos++];
+ move16();
+
+ /* get coded bwidth */
+ {
+ Word16 pos;
+ Word16 bw = 0;
+ move16();
+ FOR( pos = 0; pos < 2; pos++ )
+ {
+ bw = add( bw, extract_l( L_shl( bit_buffer[bit_pos++], pos ) ) );
+ }
+ hMetadataPMC->coded_bwidth = bw;
+ move16();
+ }
+
+ /* set tables if coded band width differs from last frame */
+ IF( NE_16( hMetadataPMC->coded_bwidth, hMetadataPMC->last_coded_bwidth ) )
+ {
+ ivas_param_mc_set_coded_bands_fx( hMetadataPMC );
+ param_mc_set_num_synth_bands( st->output_Fs, hParamMC );
+ hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->num_param_bands_synth];
+ move16();
+ }
+
+ param_frame_idx = bit_buffer[bit_pos++];
+ move16();
+ hMetadataPMC->param_frame_idx = param_frame_idx;
+ move16();
+ num_param_bands = hMetadataPMC->nbands_in_param_frame[param_frame_idx];
+ move16();
+
+ hMetadataPMC->bAttackPresent = bit_buffer[bit_pos++];
+ move16();
+ hMetadataPMC->attackIndex = 0;
+ move16();
+ band_step = 1;
+ move16();
+ num_lfe_bands = 0;
+ move16();
+
+ IF( hMetadataPMC->bAttackPresent )
+ {
+ FOR( i = 2; i >= 0; i-- )
+ {
+ hMetadataPMC->attackIndex = add( hMetadataPMC->attackIndex, extract_l( L_shl( bit_buffer[bit_pos++], i ) ) );
+ }
+
+ band_step = PARAM_MC_TRANSIENT_BAND_STEP;
+ move16();
+
+ /*num_lfe_bands = add(PARAM_MC_MAX_BAND_LFE / band_step, (PARAM_MC_MAX_BAND_LFE % band_step) ? 1 : 0);
+ num_param_bands = add(hMetadataPMC->nbands_coded / band_step, ((hMetadataPMC->nbands_coded % band_step) ? 1 : 0));*/
+ Word16 temp_e;
+ temp = BASOP_Util_Divide3232_Scale( PARAM_MC_MAX_BAND_LFE, band_step, &temp_e );
+ temp = shr( temp, sub( 15, temp_e ) );
+ Word16 temp1;
+ IF( PARAM_MC_MAX_BAND_LFE % band_step )
+ {
+ temp1 = 1;
+ }
+ ELSE
+ {
+ temp1 = 0;
+ }
+ move16();
+ num_lfe_bands = add( temp, temp1 );
+
+ temp = BASOP_Util_Divide3232_Scale( hMetadataPMC->nbands_coded, band_step, &temp_e );
+ temp = shr( temp, sub( 15, temp_e ) );
+ Word16 temp2;
+ IF( hMetadataPMC->nbands_coded % band_step )
+ {
+ temp2 = 1;
+ }
+ ELSE
+ {
+ temp2 = 0;
+ }
+ move16();
+ num_param_bands = add( temp, temp2 );
+ }
+ ELSE
+ {
+ FOR( j = 0; j < PARAM_MC_MAX_BAND_LFE; j += band_step )
+ {
+ IF( EQ_16( param_frame_idx, hMetadataPMC->coding_band_mapping[j] ) )
+ {
+ /* LFE ICC is always the last ICC in coding band 0 */
+ num_lfe_bands = add( num_lfe_bands, 1 );
+ move16();
+ }
+ }
+ }
+
+ IF( !hMetadataPMC->lfe_on )
+ {
+ num_lfe_bands = 0;
+ move16();
+ }
+
+ ivas_param_mc_bs_decode_parameter_values_fx( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->icc_coding,
+ icc_map_size_wo_lfe, icc_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icc_q_fx );
+
+ IF( !st->BER_detect )
+ {
+ ivas_param_mc_bs_decode_parameter_values_fx( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->ild_coding,
+ ild_map_size_wo_lfe, ild_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icld_q_fx );
+ }
+ /* set LFE ILD and ICC to zero above PARAM_MC_MAX_BAND_LFE for attack frames */
+ IF( hMetadataPMC->bAttackPresent )
+ {
+ FOR( k = PARAM_MC_MAX_BAND_LFE; k < imult1616( band_step, num_lfe_bands ); k++ )
+ {
+ hParamMC->icc_q_fx[L_sub( L_mult0( add( k, 1 ), icc_map_size ), 1 )] = 32767; /* 1.0f in Q15 */
+ move16();
+ hParamMC->icld_q_fx[L_sub( L_mult0( add( k, 1 ), ild_map_size ), 1 )] = PARAM_MC_DEFAULT_MIN_ILD_FX; /* -92.0f in Q8 */
+ move16();
+ }
+ }
+
+ *nb_bits = bit_pos;
+ move16();
+
+ } /* if ( !st->bfi ) */
+
+ IF( st->bfi )
+ {
+ /* for PLC, use the saved ILDs and ICCs from the past and set the transient flag and transient position to zero */
+ hMetadataPMC->bAttackPresent = 0;
+ move16();
+ hMetadataPMC->attackIndex = 0;
+ move16();
+ }
+
+ pop_wmops();
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dec_digest_tc()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_dec_digest_tc_fx(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */
+ Word32 *transport_channels_f_fx[],
+ Word16 transport_f_e )
+{
+ PARAM_MC_DEC_HANDLE hParamMC;
+ Word16 i, ch;
+ Word16 is_next_band, skip_next_band;
+ Word16 slot_idx, param_band_idx;
+ Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
+ Word16 nchan_out_cov;
+ /*CLDFB*/
+ /* format converter */
+ Word16 channel_active[MAX_OUTPUT_CHANNELS];
+ IVAS_OUTPUT_SETUP *hSynthesisOutputSetup;
+
+ hParamMC = st_ivas->hParamMC;
+ assert( hParamMC );
+ Word32 *pCx, *pCx_imag;
+ Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_e)
+ Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_e)
+ Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_next_band_e)
+ Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_next_band_e)
+
+ Word16 cx_buff_e[2][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
+ Word16 cx_e;
+ Word16 cx_imag_e, tmp_e;
+ Word16 cx_imag_next_band_e, cx_next_band_e;
+ Word16 qout = 0;
+ move16();
+
+ Word32 real_part_fx, imag_part_fx, L_tmp1, L_tmp2;
+
+ Word16 max_e;
+
+ push_wmops( "param_mc_dec_digest_tc" );
+
+ set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
+ nchan_transport = st_ivas->nchan_transport;
+ move16();
+ nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
+
+ test();
+ test();
+ IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
+ {
+ nchan_out_cldfb = BINAURAL_CHANNELS;
+ move16();
+ set16_fx( channel_active, 1, nchan_out_cldfb );
+ nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
+ hSynthesisOutputSetup = &st_ivas->hTransSetup;
+ }
+ ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
+ {
+ nchan_out_cov = nchan_out_transport;
+ move16();
+ nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
+ hSynthesisOutputSetup = &st_ivas->hTransSetup;
+ }
+ ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
+ nchan_out_cldfb = nchan_out_cov;
+ move16();
+ set16_fx( channel_active, 1, nchan_out_cov );
+ hSynthesisOutputSetup = &st_ivas->hOutSetup;
+ }
+ ELSE
+ {
+ nchan_out_cov = nchan_out_transport;
+ move16();
+ nchan_out_cldfb = nchan_out_transport;
+ move16();
+ set16_fx( channel_active, 1, nchan_out_cov );
+ hSynthesisOutputSetup = &st_ivas->hTransSetup;
+ }
+
+ /* adapt transient position */
+ IF( hParamMC->hMetadataPMC->bAttackPresent )
+ {
+ hParamMC->hMetadataPMC->attackIndex = s_max( 0, add( hParamMC->hMetadataPMC->attackIndex, shr( sub( nCldfbSlots, DEFAULT_JBM_CLDFB_TIMESLOTS ), 1 ) ) );
+ move16();
+ }
+ /* adapt subframes */
+ hParamMC->num_slots = nCldfbSlots;
+ move16();
+ hParamMC->slots_rendered = 0;
+ move16();
+ hParamMC->subframes_rendered = 0;
+ move16();
+ ivas_jbm_dec_get_adapted_subframes( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes );
+ st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes;
+ move16();
+ Copy( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes );
+
+ ivas_param_mc_dec_compute_interpolator_fx( hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx );
+
+ /* loop over two bands at a time */
+ FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 )
+ {
+ /* don't process next band if it exceeds the limit */
+ skip_next_band = ( ( param_band_idx + 1 ) == hParamMC->num_param_bands_synth ) ? 1 : 0;
+
+ set_zero_fx( cx_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
+ set_zero_fx( cx_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
+ set_zero_fx( cx_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
+ set_zero_fx( cx_imag_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
+
+ cx_e = 0;
+ move16();
+ cx_imag_e = 0;
+ move16();
+ cx_next_band_e = 0;
+ move16();
+ cx_imag_next_band_e = 0;
+ move16();
+ /* slot loop for gathering the input data */
+ FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
+ {
+ IF( st_ivas->hDecoderConfig->Opt_tsm )
+ {
+ IF( param_band_idx == 0 ) /* only run cldfbAna once */
+ {
+ Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX];
+ Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX];
+
+ /* CLDFB Analysis*/
+ FOR( ch = 0; ch < nchan_transport; ch++ )
+ {
+ qout = transport_f_e;
+ move16();
+ cldfbAnalysis_ts_fx_fixed_q( &( transport_channels_f_fx[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch], &qout );
+
+ Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands );
+ Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands );
+ }
+
+ hParamMC->Cldfb_ImagBuffer_tc_e = qout;
+ move16();
+ }
+ }
+ IF( GE_16( slot_idx, shl( hParamMC->hMetadataPMC->attackIndex, 1 ) ) )
+ {
+ FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
+ {
+ test();
+ IF( is_next_band && skip_next_band )
+ {
+ continue;
+ }
+ IF( is_next_band )
+ {
+ ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
+ /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
+ &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
+ /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
+ cx_next_band_fx,
+ &cx_next_band_e,
+ cx_imag_next_band_fx,
+ &cx_imag_next_band_e,
+ hParamMC,
+ add( param_band_idx, is_next_band ),
+ nchan_transport );
+ }
+ ELSE
+ {
+ ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
+ /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
+ &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
+ /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
+ cx_fx,
+ &cx_e,
+ cx_imag_fx,
+ &cx_imag_e,
+ hParamMC,
+ add( param_band_idx, is_next_band ),
+ nchan_transport );
+ }
+ }
+ }
+ }
+
+ Word16 tmp_cx_e, tmp_cx_imag_e;
+ /* map from complex input covariance to real values */
+ FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
+ {
+ test();
+ IF( is_next_band && skip_next_band )
+ {
+ continue;
+ }
+ /* Cx for transport channels */
+ IF( is_next_band )
+ {
+ pCx = &cx_next_band_fx[0];
+ pCx_imag = &cx_imag_next_band_fx[0];
+ tmp_cx_e = cx_next_band_e;
+ tmp_cx_imag_e = cx_imag_next_band_e;
+ }
+ ELSE
+ {
+ pCx = &cx_fx[0];
+ pCx_imag = &cx_imag_fx[0];
+ tmp_cx_e = cx_e;
+ tmp_cx_imag_e = cx_imag_e;
+ }
+
+ FOR( i = 0; i < nchan_transport * nchan_transport; i++ )
+ {
+ real_part_fx = pCx[i]; // Q(31 - cx_buff_e)
+ imag_part_fx = pCx_imag[i];
+ move32();
+ move32();
+ cx_buff_e[is_next_band][i] = tmp_cx_e;
+ move16();
+ /* (a-ib)(c+id) = ac + bd + i(ad-bc) */
+ IF( LT_16( param_band_idx, hParamMC->max_param_band_abs_cov ) )
+ {
+ L_tmp1 = Mpy_32_32( real_part_fx, real_part_fx );
+ L_tmp2 = Mpy_32_32( imag_part_fx, imag_part_fx );
+ L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, add( tmp_cx_e, tmp_cx_e ), L_tmp2, add( tmp_cx_imag_e, tmp_cx_imag_e ), &tmp_e );
+ pCx[i] = Sqrt32( L_tmp1, &tmp_e );
+ move32();
+ cx_buff_e[is_next_band][i] = tmp_e;
+ move16();
+ }
+ ELSE
+ {
+ pCx[i] = real_part_fx;
+ move32();
+ cx_buff_e[is_next_band][i] = tmp_cx_e;
+ move16();
+ }
+ }
+ }
+
+ max_e = cx_buff_e[0][0];
+ move16();
+
+ /* Cx for transport channels */
+ FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
+ {
+ FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
+ {
+
+ IF( LT_16( max_e, cx_buff_e[is_next_band][i] ) )
+ {
+ max_e = cx_buff_e[is_next_band][i];
+ }
+ }
+ }
+ /* Cx for transport channels */
+ FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
+ {
+ FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
+ {
+ if ( is_next_band == 0 )
+ {
+ cx_fx[i] = L_shr( cx_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
+ }
+ else
+ {
+ cx_next_band_fx[i] = L_shr( cx_next_band_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
+ }
+ move32();
+ }
+ }
+ cx_e = max_e;
+ move16();
+
+
+ /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/
+
+ test();
+ test();
+ IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) )
+ {
+ v_add_fx( cx_fx, cx_next_band_fx, cx_fx, imult1616( nchan_transport, nchan_transport ) );
+ Copy32( cx_fx, cx_next_band_fx, imult1616( nchan_transport, nchan_transport ) );
+ }
+
+ FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
+ {
+ test();
+ IF( is_next_band && skip_next_band )
+ {
+ continue;
+ }
+
+ IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ IF( is_next_band )
+ {
+
+ ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_next_band_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
+ }
+ ELSE
+ {
+
+ ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
+ }
+ }
+ }
+ }
+ pop_wmops();
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dec()
+ *
+ * Parametric MC decoding process
+ *------------------------------------------------------------------------*/
+
+void ivas_param_mc_dec_render_fx(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */
+ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */
+ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */
+ Word32 *output_f_fx[], /* o : rendered time signal Q11*/
+ Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] )
+{
+ PARAM_MC_DEC_HANDLE hParamMC;
+ Word16 i, ch;
+ Word16 subframe_idx;
+ Word16 slot_idx, slot_idx_start, slot_idx_start_cldfb_synth, first_sf, last_sf, slots_to_render;
+ Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
+ Word16 nchan_out_cov;
+
+ /*CLDFB*/
+ Word32 Cldfb_RealBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
+ Word32 Cldfb_ImagBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
+ Word32 Cldfb_RealBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
+ Word32 Cldfb_ImagBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
+ Word32 *p_output_f_fx[MAX_OUTPUT_CHANNELS];
+ FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
+ {
+ p_output_f_fx[i] = output_f_fx[i]; // Q11
+ }
+ /*Decorrelator*/
+ Word32 onset_filter_fx[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; // Q31
+
+ /* format converter */
+ Word16 channel_active[MAX_OUTPUT_CHANNELS];
+ UWord16 nband_synth;
+#ifndef MSAN_FIX
+ UWord16 nchan_out_init, nbands_to_zero;
+#endif
+ UWord32 output_Fs;
+ Word16 tmp_q = 0;
+ move16();
+
+ hParamMC = st_ivas->hParamMC;
+ assert( hParamMC );
+
+ push_wmops( "param_mc_dec_render" );
+
+ set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
+ nchan_transport = st_ivas->nchan_transport;
+ move16();
+ nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
+#ifndef MSAN_FIX
+ nchan_out_init = nchan_out_transport;
+ move16();
+#endif
+ output_Fs = st_ivas->hDecoderConfig->output_Fs;
+ move32();
+
+ test();
+ test();
+ IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
+ {
+ nchan_out_cldfb = BINAURAL_CHANNELS;
+ set16_fx( channel_active, 1, nchan_out_cldfb );
+#ifndef MSAN_FIX
+ IF( st_ivas->hCombinedOrientationData )
+ {
+ nchan_out_init = MAX_INTERN_CHANNELS;
+ }
+#endif
+ nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
+ }
+ ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
+ {
+ nchan_out_cov = nchan_out_transport;
+ move16();
+ nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
+ }
+ ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
+ {
+ nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
+ nchan_out_cldfb = nchan_out_cov;
+ move16();
+ set16_fx( channel_active, 1, nchan_out_cov );
+ }
+ ELSE
+ {
+ nchan_out_cov = nchan_out_transport;
+ move16();
+ nchan_out_cldfb = nchan_out_transport;
+ move16();
+ set16_fx( channel_active, 1, nchan_out_cov );
+ }
+
+ /* set everything to zero that will not be decoded */
+ nband_synth = hParamMC->band_grouping[hParamMC->num_param_bands_synth];
+ move16();
+#ifdef MSAN_FIX
+ FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
+#else
+ FOR( ch = 0; ch < nchan_out_init; ch++ )
+#endif
+ {
+ FOR( slot_idx = 0; slot_idx < JBM_CLDFB_SLOTS_IN_SUBFRAME; slot_idx++ )
+ {
+#ifdef MSAN_FIX
+ set32_fx( &( Cldfb_RealBuffer_fx[ch][slot_idx][0] ), 0, CLDFB_NO_CHANNELS_MAX );
+ set32_fx( &( Cldfb_ImagBuffer_fx[ch][slot_idx][0] ), 0, CLDFB_NO_CHANNELS_MAX );
+#else
+ set32_fx( &( Cldfb_RealBuffer_fx[ch][slot_idx][nband_synth] ), 0, nbands_to_zero );
+ set32_fx( &( Cldfb_ImagBuffer_fx[ch][slot_idx][nband_synth] ), 0, nbands_to_zero );
+#endif
+ }
+ }
+
+ /* loop FOR synthesis, assume we always have to render in multiples of 5ms subframes with spills */
+ /*slots_to_render = min(sub(hParamMC->num_slots, hParamMC->slots_rendered), nSamplesAsked / NS2SA(output_Fs, CLDFB_SLOT_NS));
+ *nSamplesRendered = slots_to_render * NS2SA(output_Fs, CLDFB_SLOT_NS);*/
+ Word16 temp_e;
+ Word16 temp = BASOP_Util_Divide1616_Scale( nSamplesAsked, NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ), &temp_e );
+ temp = shr( temp, sub( 15, temp_e ) );
+ slots_to_render = s_min( sub( hParamMC->num_slots, hParamMC->slots_rendered ), temp );
+ *nSamplesRendered = imult1616( slots_to_render, NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ) );
+ move16();
+ Word16 j, k;
+ first_sf = hParamMC->subframes_rendered;
+ move16();
+ last_sf = first_sf;
+ move16();
+ WHILE( slots_to_render > 0 )
+ {
+ slots_to_render = sub( slots_to_render, hParamMC->subframe_nbslots[last_sf] );
+ last_sf = add( last_sf, 1 );
+ }
+ IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
+ {
+ FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
+ {
+ slots_to_render = add( slots_to_render, hParamMC->subframe_nbslots[subframe_idx] );
+ }
+ }
+ slot_idx_start = hParamMC->slots_rendered;
+ move16();
+ slot_idx_start_cldfb_synth = 0;
+ move16();
+
+#ifndef FIX_1009_OPT_PARAMMC_RENDER
+ Flag is_zero = 1;
+ move32();
+#endif
+ FOR( j = 0; j < st_ivas->hParamMC->hMetadataPMC->nbands_coded; j++ )
+ {
+#ifndef FIX_1009_OPT_PARAMMC_RENDER
+ is_zero = 1;
+ move16();
+ FOR( i = 0; i < hParamMC->h_output_synthesis_cov_state.mixing_matrix_len; i++ )
+ {
+ IF( hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[j][i] != 0 )
+ {
+ is_zero = 0;
+ move16();
+ }
+ }
+ IF( is_zero )
+ {
+ hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[j] = 0;
+ move16();
+ }
+ is_zero = 1;
+ move16();
+#else
+ Flag is_zero = is_zero_arr( hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[j], hParamMC->h_output_synthesis_cov_state.mixing_matrix_len );
+ {
+ if ( is_zero != 0 )
+ {
+ hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[j] = 0;
+ move16();
+ }
+ }
+#endif
+ IF( LT_16( st_ivas->hParamMC->band_grouping[j], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
+ {
+#ifndef FIX_1009_OPT_PARAMMC_RENDER
+ FOR( i = 0; i < hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len; i++ )
+ {
+ IF( NE_32( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[j][i], 0 ) )
+ {
+ is_zero = 0;
+ move16();
+ }
+ }
+ IF( is_zero )
+#else
+ is_zero = is_zero_arr( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[j], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len );
+ if ( is_zero != 0 )
+#endif
+ {
+ hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[j] = 0;
+ move16();
+ }
+ }
+ }
+ FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
+ {
+ FOR( slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; ( slot_idx++, hParamMC->slots_rendered++ ) )
+ {
+ IF( hParamMC->max_band_decorr > 0 )
+ {
+ /*-----------------------------------------------------------------*
+ * protoype signal computation
+ *-----------------------------------------------------------------*/
+ param_mc_protoSignalComputation_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
+ &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
+ hParamMC->proto_frame_f_fx, hParamMC->diff_proto_info,
+ hParamMC->num_freq_bands );
+ /*-----------------------------------------------------------------*
+ * frequency domain decorrelation
+ *-----------------------------------------------------------------*/
+ /* decorrelate prototype frame */
+
+ ivas_dirac_dec_decorr_process_fx( hParamMC->num_freq_bands,
+ hParamMC->num_outputs_diff,
+ hParamMC->diff_proto_info->num_protos_diff,
+ DIRAC_SYNTHESIS_COV_MC_LS,
+ nchan_transport,
+ hParamMC->proto_frame_f_fx,
+ Q5,
+ hParamMC->diff_proto_info->num_protos_diff,
+ hParamMC->diff_proto_info->proto_index_diff,
+ hParamMC->proto_frame_dec_f_fx, // output
+ &tmp_q,
+ onset_filter_fx,
+ hParamMC->h_freq_domain_decorr_ap_params,
+ hParamMC->h_freq_domain_decorr_ap_state );
+
+ /* copy decorrelated frame directly to output CLDFB buffer, acts also as intermediate */
+ /* memory FOR the decorrelated signal */
+ ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx ); // Returns Cldfb buffers in Q11(tmp_q)
+
+ FOR( k = 0; k < nchan_out_cov; k++ )
+ {
+ FOR( Word16 l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++ )
+ {
+ Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6
+ move32();
+ Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6
+ move32();
+ }
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * output synthesis
+ *-----------------------------------------------------------------*/
+ ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx(
+ &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
+ &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ),
+ nchan_transport, nchan_out_cov, hParamMC );
+
+ test();
+ IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
+ {
+ test();
+ IF( st_ivas->hCombinedOrientationData && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
+ {
+ Word16 Q_Cldfb_ImagBuffer, Q_Cldfb_RealBuffer;
+ Q_Cldfb_ImagBuffer = Q6 - 5; /*max value =MAX_INTERN_CHANNELS(=16)*Cldfb_ImagBuffer_fx*/
+ move16();
+ Q_Cldfb_RealBuffer = Q6 - 5;
+ move16();
+ FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
+ {
+ FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
+ {
+ Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_ImagBuffer, Q6 ) ); // Q1
+ Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_RealBuffer, Q6 ) ); // Q1
+ }
+ }
+ ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hParamMC->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nband_synth, GAIN_LFE_FX );
+ FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
+ {
+ FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
+ {
+ Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_ImagBuffer ) ); // Q6
+ Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_RealBuffer ) ); // Q6
+ }
+ }
+ }
+ ELSE
+ {
+ /* remove LFE */
+ UWord16 idx_out;
+ UWord16 idx_lfe;
+ IVAS_OUTPUT_SETUP hLsSetup;
+
+ hLsSetup = st_ivas->hTransSetup;
+ /* If LFE should be rendered, add it to other channels before removing */
+ IF( st_ivas->hBinRenderer->render_lfe )
+ {
+ Word16 tmp_exp = 0;
+ move16();
+ Word16 tmp = BASOP_Util_Divide1616_Scale( GAIN_LFE_FX, hLsSetup.nchan_out_woLFE, &tmp_exp );
+ tmp_exp = add( tmp_exp, ( 1 - 15 ) );
+ FOR( idx_lfe = 0; idx_lfe < hLsSetup.num_lfe; idx_lfe++ )
+ {
+ /* Copy just the first band of LFE*/
+ v_multc_fixed_16( Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], tmp, Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1 );
+ v_multc_fixed_16( Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], tmp, Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1 );
+
+ Scale_sig32( Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1, tmp_exp );
+ Scale_sig32( Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1, tmp_exp );
+ FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
+ {
+ IF( hLsSetup.index_lfe[idx_lfe] != ch )
+ {
+ v_add_fixed( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_RealBuffer_fx[ch][slot_idx], 1, 0 );
+ v_add_fixed( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], 1, 0 );
+ }
+ }
+ }
+ }
+
+ idx_out = 0;
+ move16();
+ idx_lfe = 0;
+ move16();
+
+ FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
+ {
+ test();
+ IF( ( hLsSetup.num_lfe > 0 ) && EQ_16( hLsSetup.index_lfe[idx_lfe], ch ) )
+ {
+ IF( LT_16( idx_lfe, ( sub( hLsSetup.num_lfe, 1 ) ) ) )
+ {
+ idx_lfe = add( idx_lfe, 1 );
+ }
+ }
+ ELSE IF( NE_16( ch, idx_out ) )
+ {
+ Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[idx_out][slot_idx], nband_synth );
+ Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[idx_out][slot_idx], nband_synth );
+ idx_out = add( idx_out, 1 );
+ }
+ ELSE
+ {
+ idx_out = add( idx_out, 1 );
+ }
+ }
+ }
+ }
+ }
+
+ test();
+ IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
+ {
+ Word16 input_q = 6;
+ move16();
+ /* Implement binaural rendering */
+ ivas_binRenderer_fx( st_ivas->hBinRenderer,
+ st_ivas->hCombinedOrientationData,
+ hParamMC->subframe_nbslots[subframe_idx],
+ Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
+ Cldfb_RealBuffer_fx,
+ Cldfb_ImagBuffer_fx, &input_q );
+
+ FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
+ {
+ FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
+ {
+ FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
+ {
+ Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
+ Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
+ }
+ }
+ }
+
+ FOR( Word16 idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ )
+ {
+ FOR( Word16 idx2 = 0; idx2 < hParamMC->subframe_nbslots[subframe_idx]; idx2++ )
+ {
+ Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6
+ Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6
+ }
+ }
+ /* update combined orientation access index */
+ ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx] );
+ }
+ ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
+ {
+ /* format conversion*/
+ ivas_lssetupconversion_process_param_mc_fx( st_ivas, hParamMC->subframe_nbslots[subframe_idx], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, channel_active );
+ }
+
+
+ /* CLDFB synthesis */
+ FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
+ {
+ Word32 *RealBuffer_fx[16];
+ Word32 *ImagBuffer_fx[16];
+
+ IF( channel_active[ch] )
+ {
+ /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands FOR 48kHz */
+ FOR( i = 0; i < hParamMC->subframe_nbslots[subframe_idx]; i++ )
+ {
+ IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
+ {
+ RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[ch][i]; // Q6
+ ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[ch][i]; // Q6
+ }
+ ELSE
+ {
+ RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; // Q6
+ ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; // Q6
+ }
+ }
+
+ Word16 len = add( imult1616( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
+ scale_sig32( output_f_fx[ch], len, 5 - 11 );
+ cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ),
+ imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] );
+
+ scale_sig32( output_f_fx[ch], len, 11 - 5 ); // Q11
+ }
+ ELSE
+ {
+ set32_fx( &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
+ }
+ }
+ slot_idx_start = add( slot_idx_start, hParamMC->subframe_nbslots[subframe_idx] );
+ slot_idx_start_cldfb_synth = add( slot_idx_start_cldfb_synth, hParamMC->subframe_nbslots[subframe_idx] );
+ }
+ IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
+ {
+ ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_f_fx, p_output_f_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
+ }
+
+ /* update */
+
+ IF( EQ_16( hParamMC->slots_rendered, hParamMC->num_slots ) )
+ {
+ hParamMC->hMetadataPMC->last_coded_bwidth = hParamMC->hMetadataPMC->coded_bwidth;
+ move16();
+ param_mc_update_mixing_matrices_fx( hParamMC, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_transport, nchan_out_cov );
+ }
+
+
+ hParamMC->subframes_rendered = last_sf;
+ move16();
+ *nSamplesAvailableNext = imult1616( sub( hParamMC->num_slots, hParamMC->slots_rendered ), NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ) );
+ move16();
+
+ FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
+ {
+ channel_active_fx[i] = channel_active[i];
+ move16();
+ }
+ pop_wmops();
+
+ return;
+}
+
+/*-------------------------------------------------------------------------
+ * param_mc_dec_init()
+ *
+ * Parametric MC decoding initialization
+ *------------------------------------------------------------------------*/
+
+static void ivas_param_mc_dec_init_fx(
+ PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */
+ const Word16 nchan_transport, /* i : number of input (transport) channels */
+ const Word16 nchan_cov ) /* i : number of cov synthesis channels */
+{
+ Word16 k;
+ UWord16 max_param_band_residual;
+ Word16 len;
+
+ /*-----------------------------------------------------------------*
+ * init sub-modules
+ *-----------------------------------------------------------------*/
+
+ /* decorrelation */
+ IF( hParamMC->max_band_decorr > 0 )
+ {
+ len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr );
+
+ /* init onsetDetectionPower */
+ set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
+ set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
+ hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
+ move16();
+ }
+
+ max_param_band_residual = 0;
+ move16();
+
+ /* output synthesis */
+ FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
+ {
+ IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
+ {
+ max_param_band_residual = k;
+ move16();
+ BREAK;
+ }
+ }
+
+ ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual );
+
+ /*-----------------------------------------------------------------*
+ * init proto frames
+ *-----------------------------------------------------------------*/
+
+ IF( hParamMC->max_band_decorr > 0 )
+ {
+ set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
+ set32_fx( hParamMC->proto_frame_dec_f_fx, 0, shl( imult1616( nchan_cov, hParamMC->num_freq_bands ), 1 ) );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Local functions
+ *-------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dec_compute_diffuse_proto()
+ *
+ * Compute prototypes for decorrelation
+ *------------------------------------------------------------------------*/
+
+static void param_mc_protoSignalComputation_fx(
+ Word32 *RealBuffer_fx, /* i : CLDFB samples of the transport channels (real part) */
+ Word32 *ImagBuffer_fx, /* i : CLDFB samples of the transport channels (imaginary part) */
+ Word32 *proto_frame_f_fx, /* o : interleaved complex prototype CLDFB samples */
+ const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i : prototype generation information */
+ const int16_t num_freq_bands /* i : number of frequency bands for the prototypes */
+)
+{
+ Word16 band;
+ Word16 proto_ch_idx, source_ch_cnt;
+
+ Word32 *p_proto_frame_fx;
+ Word32 *p_real_buffer_fx; // Q12
+ Word32 *p_imag_buffer_fx; // Q12
+
+ set32_fx( proto_frame_f_fx, 0, shl( imult1616( num_freq_bands, diff_proto_info->num_protos_diff ), 1 ) );
+
+
+ FOR( proto_ch_idx = 0; proto_ch_idx < diff_proto_info->num_protos_diff; proto_ch_idx++ )
+ {
+ Word16 num_source_ch = diff_proto_info->num_source_chan_diff[proto_ch_idx];
+ move16();
+
+ FOR( source_ch_cnt = 0; source_ch_cnt < num_source_ch; source_ch_cnt++ )
+ {
+
+ Word32 fac_fx = diff_proto_info->proto_fac_fx[proto_ch_idx][source_ch_cnt];
+ move32();
+
+ Word16 source_ch_idx = diff_proto_info->source_chan_idx[proto_ch_idx][source_ch_cnt];
+ move16();
+
+ p_proto_frame_fx = &proto_frame_f_fx[shl( imult1616( proto_ch_idx, num_freq_bands ), 1 )];
+ p_real_buffer_fx = &RealBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
+ p_imag_buffer_fx = &ImagBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
+
+ FOR( band = 0; band < num_freq_bands; band++ )
+ {
+
+ Word32 tmp_x = Mpy_32_32( fac_fx, ( *( p_real_buffer_fx++ ) ) ); // Q(30 + 6 - 31) :: Q5
+
+ *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
+ move32();
+ p_proto_frame_fx++;
+
+ tmp_x = Mpy_32_32( fac_fx, ( *( p_imag_buffer_fx++ ) ) ); // Q(30 + 6 - 31) :: Q5
+
+ *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
+ move32();
+ p_proto_frame_fx++;
+ }
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dec_compute_diffuse_proto()
+ *
+ * Transfer decorrelated signals back from the decorrelator buffer to
+ * the buffers used in the final synthesis
+ *------------------------------------------------------------------------*/
+
+static void ivas_param_mc_dec_copy_diffuse_proto(
+ PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
+ Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (real part) */
+ Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (imaginary part) */
+ const Word16 nY, /* i : number of decorrelated channels */
+ const Word16 slot_idx /* i : current time slot index */
+)
+{
+ Word16 k, l;
+ Word16 num_freq_bands, num_freq_bands_diff;
+ Word32 *p_proto_diff_fx;
+ num_freq_bands = hParamMC->num_freq_bands;
+ move16();
+ num_freq_bands_diff = hParamMC->h_output_synthesis_params.max_band_decorr;
+ move16();
+
+ FOR( k = 0; k < nY; k++ )
+ {
+ p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); // Q11
+
+ FOR( l = 0; l < num_freq_bands_diff; l++ )
+ {
+ Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
+ move32();
+ Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
+ move32();
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_bin2dec()
+ *
+ * decode a number of bits to an integer
+ *------------------------------------------------------------------------*/
+/* r : decoded integer */
+static Word16 ivas_param_mc_bin2dec_fx(
+ UWord16 bits[PARAM_MC_MAX_BITS], /* i : bit buffer */
+ const Word16 N /* i : number of bits to decode */
+)
+{
+ Word16 i;
+ Word16 out;
+
+ assert( N <= 16 );
+ out = 0;
+ move16();
+ FOR( i = 0; i < N; i++ )
+ {
+ out = add( out, shl( bits[i], sub( sub( N, 1 ), i ) ) );
+ }
+
+ return out;
+}
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_uniform_decoder()
+ *
+ * decode a uniformily coded sequence of float values
+ *------------------------------------------------------------------------*/
+static Word16 ivas_param_mc_uniform_decoder_fx(
+ Word16 *seq, /* o : decoded sequence of float values hParamCodingInfo -> Q-quant*/
+ const Word16 sz_seq, /* i : number of values to decode */
+ const Word16 *alphabet, /* i : codebook hParamCodingInfo -> Q-quant*/
+ const Word16 N, /* i : number of bits per coded index */
+ UWord16 bit_buffer[PARAM_MC_MAX_BITS] /* i : bit buffer to decode */
+)
+{
+ Word16 i;
+ Word16 idx;
+ Word16 n_bits;
+
+ n_bits = 0;
+ move16();
+ assert( N * sz_seq < PARAM_MC_MAX_BITS );
+
+ FOR( i = 0; i < sz_seq; ++i )
+ {
+ idx = ivas_param_mc_bin2dec_fx( &bit_buffer[i * N], N );
+ seq[i] = alphabet[idx];
+ move16();
+ }
+
+ n_bits = imult1616( N, sz_seq );
+
+ return n_bits;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_range_decoder_LC()
+ *
+ * decode a sequency of inidices coded with a range coder
+ *------------------------------------------------------------------------*/
+static Word16 ivas_param_mc_range_decoder_LC_fx(
+ UWord16 *bit_buffer, /* i : bit buffer to read from */
+ Word16 *x, /* o : decoded indices */
+ Word16 *BER_detect, /* o : flag for indicating a bit error */
+ const Word16 sz_seq, /* i : size of the sequence to be decoded */
+ const Word16 sz_alphabet, /* i : size of the alphabet */
+ const UWord16 *cft, /* i : cumulative frequency table */
+ const UWord16 *sft, /* i : symbol frequency table */
+ const Word16 tot_shift, /* i : total frequency as a power of 2 */
+ const Word16 nbbits /* i : maximum bit budget */
+)
+{
+ RangeUniDecState rc_st_dec; /* State of the range decoder */
+ Word16 cur_bit_pos;
+ Word16 k;
+ Word16 r;
+
+ /* Start Decoding */
+ /* Initialize range decoder */
+ cur_bit_pos = 0;
+ move16();
+ rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, sub( nbbits, 32 ) ); /* (nbbits + 30) entries are read by the decoder */
+
+ /* Main Loop through the indices */
+ FOR( k = 0; k < sz_seq; k++ )
+ {
+ r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
+ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */
+
+ /* Update bitstream pointer */
+ cur_bit_pos = rc_uni_dec_virtual_finish_fx( &rc_st_dec );
+
+ /* Confirm that there is no overflow */
+ IF( GT_16( cur_bit_pos, nbbits ) )
+ {
+ *BER_detect = s_or( *BER_detect, 1 );
+ move16();
+ }
+
+ x[k] = r;
+ move16();
+ }
+
+ /* We don't need to finish because virtual_finish() already does the same */
+ /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/
+
+ /* Check for bitstream errors */
+ IF( rc_st_dec.bit_error_detected != 0 )
+ {
+ *BER_detect = s_or( *BER_detect, 1 );
+ move16();
+ }
+
+ return cur_bit_pos;
+}
+
+/*-------------------------------------------------------------------------
+ * param_mc_compute_interpolator()
+ *
+ * compute the interpolator used in the final synthesis
+ *------------------------------------------------------------------------*/
+
+static void ivas_param_mc_dec_compute_interpolator_fx(
+ const UWord16 bAttackPresent, /* i : flag indicating if we have a transient in the current frame */
+ const UWord16 attackPos, /* i : position of the transient */
+ const UWord16 interp_length, /* i : number of interpolation values to be calculated */
+ Word16 *interpolator /* o : interpolator */
+)
+{
+ Word16 idx;
+
+ IF( bAttackPresent )
+ {
+ FOR( idx = 0; idx < attackPos * 2; idx++ )
+ {
+ interpolator[idx] = 0;
+ move16();
+ }
+ FOR( ; idx < interp_length; idx++ )
+ {
+ interpolator[idx] = 32767; /* 1.0f Q15 */
+ move16();
+ }
+ }
+ ELSE
+ {
+ ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * remove_lfe_from_cy()
+ *
+ * remove all LFE related values from a covariance matrix
+ *------------------------------------------------------------------------*/
+
+static void remove_lfe_from_cy_fx(
+ const Word16 nY, /* i : dimension of the covariance matrix */
+ Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP], /* i : LFE index */
+ Word16 num_lfe, /* i : number of LFEs */
+ Word32 *cy, /* i : covariance matrix */
+ Word32 *cy_woLFE /* o : covariance matrix with LFE removed */
+)
+{
+ Word16 ch_idx1, ch_idx2;
+ Word16 lfe_idx1, lfe_idx2;
+ Word32 *ptrCy;
+ Word32 *ptrCy_out;
+
+ ptrCy = cy;
+ ptrCy_out = cy_woLFE;
+
+ FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ )
+ {
+ FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
+ {
+ FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ )
+ {
+ FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
+ {
+ *( ptrCy_out++ ) = *( ptrCy++ );
+ move32();
+ }
+ ptrCy++;
+ }
+ ptrCy--;
+ }
+ ptrCy += nY;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_get_mixing_matrices()
+ *
+ * calculate the direct and residual mixing matrices
+ * using the covariance method
+ *------------------------------------------------------------------------*/
+
+static void ivas_param_mc_get_mixing_matrices_fx(
+ PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
+ IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
+ Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands Q(31 - Cx_in_e)*/
+ Word16 Cx_in_e,
+ const Word16 param_band_idx, /* i : parameter band index */
+ Word32 *mixing_matrix_fx[], // Q(31 - mixing_matrix_e)
+ Word16 *mixing_matrix_e,
+ Word32 *mixing_matrix_res_fx[], // Q(31 - mixing_matrix_res_e)
+ Word16 *mixing_matrix_res_e,
+ const Word16 nY_intern, /* i : number of channels in the transported format */
+ const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */
+ const Word16 nX, /* i : number of transport channels */
+ const Word16 nY_cov /* i : number of covariance synthesis output channels */
+)
+{
+ Word16 matSize = MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS;
+ Word16 nY_band;
+ Word16 num_lfe_bands;
+ Word16 brange[2];
+ uint16_t i;
+ Word16 ch_idx1, ch_idx2, lfe_idx1, lfe_idx2;
+ Word16 remove_lfe;
+ Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP];
+
+ Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
+ Word32 Cy_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
+
+ Word32 Cy_full_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
+
+ Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cr_e)
+ Word16 Cr_e;
+ Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Cy_diag_buff_e)
+ Word16 Cy_diag_buff_e[MAX_OUTPUT_CHANNELS];
+ Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - mixing_matrix_local_e)
+ Word16 Cy_diag_e = 0, mixing_matrix_local_e = 0;
+ Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cproto_e)
+ Word16 Cproto_e;
+ Word32 *proto_matrix_ptr_fx; // Q(31 - proto_matrix_ptr_e)
+ Word32 *Cx_state_fx; // Q(31 - Cx_state_e)
+ Word32 *Cx_old_state_fx;
+ Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cy_state_e)
+ Word32 *Cy_old_state_fx;
+ Word16 Cx_state_e;
+ Word16 Cy_state_e;
+ Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mixing_matrix_res_local_e)
+ Word16 mixing_matrix_res_local_e;
+ Word32 L_tmp;
+ Word16 tmp_e, tmp;
+
+ Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
+ move16();
+ Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; // Q(31 - proto_matrix_noLFE_e)
+
+ Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
+
+ Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; // Q(31 - Cproto_diag_e)
+ Word16 mat_mult_buffer1_e, proto_matrix_ptr_e, Cproto_diag_e;
+
+ Word32 *ptrMM_fx;
+ Word32 *ptrMM_out_fx;
+
+ Word16 Cy_e, Cx_e;
+ Word16 Cy_full_e;
+ Word16 new_e = 0;
+ move16();
+
+ set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
+ set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
+ set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
+ set_zero_fx( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
+#ifdef MSAN_FIX
+ set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
+#endif
+ Word16 proto_matrix_noLFE_e = 0;
+ move16();
+
+ Word32 Cx_in_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
+
+ Copy32( Cx_in_fixed, Cx_in_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
+
+ nY_band = nY_cov;
+ move16();
+ num_lfe_bands = 0;
+ move16();
+ remove_lfe = 0;
+ move16();
+
+ set16_fx( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP );
+ IF( hSynthesisOutputSetup->num_lfe )
+ {
+ Word32 *proto_matrix_ptr_in_fx;
+ FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ )
+ {
+ lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1];
+ move16();
+ }
+ lfe_indices[hSynthesisOutputSetup->num_lfe + 1] = nY_cov;
+ move16();
+ proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0];
+ proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0];
+ proto_matrix_noLFE_e = proto_matrix_e;
+ move16();
+
+ set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
+
+ FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
+ {
+ FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
+ {
+ FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
+ {
+ *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ );
+ move32();
+ }
+ proto_matrix_ptr_in_fx++;
+ }
+ proto_matrix_ptr_in_fx--;
+ }
+
+ proto_matrix_ptr_e = proto_matrix_e;
+ move16();
+ }
+
+ if ( hParamMC->hMetadataPMC->lfe_on )
+ {
+ num_lfe_bands = PARAM_MC_MAX_BAND_LFE;
+ move16();
+ }
+ IF( hSynthesisOutputSetup->num_lfe > 0 && param_band_idx >= num_lfe_bands )
+ {
+ remove_lfe = 1;
+ move16();
+ nY_band = sub( nY_cov, hSynthesisOutputSetup->num_lfe );
+ proto_matrix_ptr_fx = proto_matrix_noLFE_fx;
+ proto_matrix_ptr_e = proto_matrix_noLFE_e;
+ move16();
+ }
+ ELSE
+ {
+ proto_matrix_ptr_fx = hParamMC->h_output_synthesis_params.proto_matrix_fx;
+ proto_matrix_ptr_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
+ move16();
+ }
+
+ brange[0] = hParamMC->band_grouping[param_band_idx];
+ move16();
+ brange[1] = hParamMC->band_grouping[param_band_idx + 1];
+ move16();
+
+ Cx_state_fx = Cx_in_fx;
+ Cx_old_state_fx = hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx];
+ Cy_old_state_fx = hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx];
+
+
+ /* Getting mixing mtx */
+ /* estimate target cov from input cov and proto_matrix */
+
+ Cx_state_e = Cx_in_e;
+ move16();
+ matrix_product_fx( hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx );
+ mat_mult_buffer1_e = add( hParamMC->proto_matrix_int_e, Cx_in_e );
+
+ matrix_product_fx( mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx );
+ Cproto_e = add( mat_mult_buffer1_e, hParamMC->proto_matrix_int_e );
+
+ FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ )
+ {
+ IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )], Cproto_e, 0, 0 ) < 0 )
+ {
+ Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )] = 0;
+ move32();
+ }
+ }
+
+ set_zero_fx( Cy_state_fx, matSize );
+ Cy_state_e = 0;
+ move16();
+
+ ivas_param_mc_dequantize_cov_fx( hParamMC,
+ hParamMC->icld_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ),
+ hParamMC->icc_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ),
+ param_band_idx, nY_cov,
+ synth_config,
+ nY_intern,
+ nX, Cx_state_fx, Cx_state_e, Cproto_fx, Cproto_e, Cy_state_fx, &Cy_state_e );
+
+ // dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state_fx.txt");
+
+ /* Smoothing: Sum over two buffers */
+ IF( hParamMC->hMetadataPMC->bAttackPresent )
+ {
+ /* no smoothing on attacks */
+ Copy32( Cx_state_fx, Cx_fx, imult1616( nX, nX ) );
+ Copy32( Cy_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) );
+ Cy_full_e = Cy_state_e;
+ move16();
+ Cx_e = Cx_state_e;
+ move16();
+ }
+ ELSE
+ {
+ /* smoothing gains are now identical to one, simply add up */
+ // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov );
+
+ v_add_fixed_me( Cx_state_fx, Cx_state_e, Cx_old_state_fx, hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_fx, &Cx_e, imult1616( nX, nX ), 1 );
+ v_add_fixed_me( Cy_state_fx, Cy_state_e, Cy_old_state_fx, hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_full_fx, &Cy_full_e, imult1616( nY_cov, nY_cov ), 1 );
+ }
+
+ Copy32( Cx_state_fx, Cx_old_state_fx, imult1616( nX, nX ) );
+
+ Copy32( Cy_state_fx, Cy_old_state_fx, imult1616( nY_cov, nY_cov ) );
+
+ hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = Cx_state_e;
+ move16();
+ hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e;
+ move16();
+
+ FOR( i = 0; i < nX * nX; i++ )
+ {
+ if ( Cx_old_state_fx[i] != 0 )
+ {
+ new_e = hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx];
+ move16();
+ BREAK;
+ }
+ }
+
+ hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = new_e;
+ move16();
+
+ new_e = 0;
+ move16();
+
+ FOR( i = 0; i < nY_cov * nY_cov; i++ )
+ {
+ if ( Cy_old_state_fx[i] != 0 )
+ {
+ new_e = hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx];
+ move16();
+ BREAK;
+ }
+ }
+
+ hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = new_e;
+ move16();
+
+ /* remove LFE IF necessary */
+ IF( remove_lfe )
+ {
+
+ Cy_e = Cy_full_e;
+ remove_lfe_from_cy_fx( nY_cov, lfe_indices, hSynthesisOutputSetup->num_lfe, Cy_full_fx, Cy_fx );
+ }
+ ELSE
+ {
+ Copy32( Cy_full_fx, Cy_fx, imult1616( nY_band, nY_band ) );
+ Cy_e = Cy_full_e;
+ move16();
+ }
+
+ matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx );
+ mat_mult_buffer1_e = add( proto_matrix_ptr_e, Cx_e );
+
+ matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e );
+
+ /* make sure we have no negative entries in Cproto_diag due to rounding errors */
+
+ FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ )
+ {
+#ifdef OPT_BASOP_ADD_v1
+ if ( Cproto_diag_fx[ch_idx1] < 0 )
+#else /* OPT_BASOP_ADD_v1 */
+ if ( BASOP_Util_Cmp_Mant32Exp( Cproto_diag_fx[ch_idx1], Cproto_diag_e, 0, 0 ) < 0 )
+#endif /* OPT_BASOP_ADD_v1 */
+ {
+ Cproto_diag_fx[ch_idx1] = 0;
+ move16();
+ }
+ }
+
+
+ /* Computing the mixing matrices */
+
+ /* bands with decorr */
+ IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
+ {
+ computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 0, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e );
+ /* Compute mixing matrix FOR residual */
+ computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e );
+
+ IF( NE_16( mixing_matrix_res_local_e, mixing_matrix_local_e ) )
+ {
+ tmp = getScaleFactor32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
+ scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, tmp );
+ mixing_matrix_local_e = sub( mixing_matrix_local_e, tmp );
+
+ tmp = getScaleFactor32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
+ scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, tmp );
+ mixing_matrix_res_local_e = sub( mixing_matrix_res_local_e, tmp );
+
+ scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, sub( mixing_matrix_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) );
+ scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, sub( mixing_matrix_res_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) );
+
+ mixing_matrix_res_local_e = mixing_matrix_local_e = s_max( mixing_matrix_local_e, mixing_matrix_res_local_e );
+ move16();
+ }
+ IF( remove_lfe )
+ {
+ set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
+
+ ptrMM_fx = mixing_matrix_res_local_fx;
+ ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx];
+ FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
+ {
+ FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
+ {
+ FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ )
+ {
+ FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
+ {
+ *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
+ move32();
+ }
+ ptrMM_out_fx++;
+ }
+ ptrMM_out_fx--;
+ }
+ ptrMM_out_fx += nY_cov;
+ }
+ mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
+ move16();
+ }
+ ELSE
+ {
+ Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
+ mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
+ move16();
+ }
+ }
+ ELSE IF( brange[0] < hParamMC->max_band_energy_compensation )
+ {
+ /* Compute mixing matrices (energy compensation only) */
+ computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 1, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e );
+ }
+ ELSE
+ {
+ /*IF neither decorrelation nor energy compensation is applied*/
+ FOR( i = 0; i < nY_band; i++ )
+ {
+ tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i], L_add( Cproto_diag_fx[i], EPSILON_FX ), &tmp_e );
+ tmp_e = add( Cy_diag_e, Cproto_diag_e );
+ L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_e );
+ Cy_diag_fx[i] = L_tmp;
+ move32();
+ Cy_diag_buff_e[i] = tmp_e;
+ move16();
+ }
+
+
+ Cy_diag_e = Cy_diag_buff_e[0];
+ move16();
+
+ FOR( i = 1; i < nY_band; i++ )
+ {
+ if ( LT_16( Cy_diag_e, Cy_diag_buff_e[i] ) )
+ {
+ Cy_diag_e = Cy_diag_buff_e[i];
+ move16();
+ }
+ }
+
+ FOR( i = 0; i < nY_band; i++ )
+ {
+ Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], sub( Cy_diag_e, Cy_diag_buff_e[i] ) );
+ move32();
+ }
+
+ diag_matrix_product_fx( Cy_diag_fx, Cy_diag_e, nY_band, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e );
+ }
+
+ IF( remove_lfe )
+ {
+ set_zero_fx( mixing_matrix_fx[param_band_idx], imult1616( nX, nY_cov ) );
+ ptrMM_fx = mixing_matrix_local_fx;
+ ptrMM_out_fx = mixing_matrix_fx[param_band_idx];
+ FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
+ {
+ FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
+ {
+ FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
+ {
+ *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
+ move32();
+ }
+ ptrMM_out_fx++;
+ }
+ ptrMM_out_fx--;
+ }
+
+ mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
+ move16();
+ }
+ ELSE
+ {
+ Copy32( mixing_matrix_local_fx, mixing_matrix_fx[param_band_idx], imult1616( nY_cov, nX ) );
+ mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
+ move16();
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_get_mono_stereo_mixing_matrices()
+ *
+ * calculate the direct and residual mixing matrices
+ * for mono and stereo output
+ *------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------------
+ * param_mc_update_mixing_matrices()
+ *
+ * update mixing matrix buffers
+ *------------------------------------------------------------------------*/
+
+static void param_mc_update_mixing_matrices_fx(
+ PARAM_MC_DEC_HANDLE hParamMC, /* i/o: Parametric MC handle */
+ Word32 *mixing_matrix[], /* i : direct mixing matrices for the frame just processed */
+ Word16 *mixing_matrix_exp,
+ Word32 *mixing_matrix_res[], /* i : residual mixing matrices for the frame just processed */
+ Word16 *mixing_matrix_res_exp,
+ const UWord16 nX, /* i : number of transport channels */
+ const UWord16 nY ) /* i : number of synthesis channels */
+{
+ UWord16 param_band_idx;
+
+ FOR( param_band_idx = 0; param_band_idx < hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ )
+ {
+ Word16 brange[2];
+
+ brange[0] = hParamMC->band_grouping[param_band_idx];
+ move16();
+ brange[1] = hParamMC->band_grouping[param_band_idx + 1];
+ move16();
+
+ Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nX, nY ) );
+ hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = mixing_matrix_exp[param_band_idx];
+ move16();
+
+ IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
+ {
+ Copy32( mixing_matrix_res[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nY, nY ) );
+ hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = mixing_matrix_res_exp[param_band_idx];
+ move16();
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dequantize_cov()
+ *
+ * generate the target covariance matrix
+ *------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------------
+ * ivas_param_mc_dequantize_cov_fx()
+ *
+ * generate the target covariance matrix
+ *------------------------------------------------------------------------*/
+
+static void ivas_param_mc_dequantize_cov_fx(
+ PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
+ Word16 *ild_q_fx, /* i : sequence of dequantized ILD values Q8 */
+ Word16 *icc_q_fx, /* i : sequence of dequantized ICC values Q15*/
+ const Word16 param_band_index, /* i : current parameter band */
+ const Word16 nY_cov, /* i : number of output channels in the covariance synthesis */
+ const PARAM_MC_SYNTHESIS_CONF synth_conf, /* i : Parametric MC synthesis configuration */
+ const Word16 nY_int, /* i : number of channels in the transported format */
+ const Word16 nX, /* i : number of transport channels */
+ Word32 *Cx_state_fx, /* i : transport channel covariance matrix */
+ Word16 Cx_state_e, /* i : exponent for transport channel covariance matrix */
+ Word32 *Cproto_fx, /* i : prototype matrix */
+ Word16 Cproto_e, /* i : exponent for prototype matrix */
+ Word32 *Cy_state_fx, /* o : target covariance matrix */
+ Word16 *Cy_state_e /* o : exponent for target covariance matrix */
+)
+{
+ Word16 Cy_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
+ Word16 Cp_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
+
+ Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Nrqq_e)
+ Word16 Nrqq_e[MAX_OUTPUT_CHANNELS];
+ Word32 a_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - a_e)
+ Word16 a_e[MAX_OUTPUT_CHANNELS];
+ Word16 k;
+ Word16 l;
+ Word32 *Cyp_fx; // Q(31 - Cyp_e)
+ Word16 *Cyp_e;
+ Word32 ap_fx; // Q(31 - ap_e)
+ Word16 ap_e;
+ Word32 L_tmp;
+ Word16 tmp, tmp_e;
+ const PARAM_MC_ILD_MAPPING *h_ild_mapping;
+ Word32 Cy_state_int_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
+ Word16 Cy_state_int_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
+
+ set16_fx( Cp_buf_e, Cproto_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
+ set32_fx( Nrqq_fx, 0, MAX_OUTPUT_CHANNELS );
+ set16_fx( Nrqq_e, 0, MAX_OUTPUT_CHANNELS );
+ h_ild_mapping = hParamMC->hMetadataPMC->ild_mapping_conf;
+
+ /*get back Nrg*/
+ tmp = 0;
+ move16();
+
+ FOR( k = 0; k < nY_int; k++ )
+ {
+ Word32 ref_ener_fx = 0; // Q(31 - ref_ener_e)
+ move32();
+ Word16 ref_ener_e = 0;
+ move16();
+ Word16 ref_channel_cnt;
+ Word16 ref_channel_idx;
+
+ FOR( ref_channel_cnt = 0; ref_channel_cnt < h_ild_mapping->num_ref_channels[k]; ref_channel_cnt++ )
+ {
+ ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt];
+ move16();
+ ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[ref_channel_idx + ( ref_channel_idx * nX )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e );
+ move32();
+ }
+
+ L_tmp = Mpy_32_16_1( 713378626, ild_q_fx[k] ); /*Q24 : L_tmp Q31 for log2(10)/10 -> 713378626 */
+ L_tmp = BASOP_util_Pow2( L_tmp, 31 - 24, &tmp_e ); /*powf( 10.0f, ild_q_fx[k] / 10.0f )*/
+ L_tmp = Mpy_32_32( L_tmp, Mpy_32_16_1( ref_ener_fx, hParamMC->hMetadataPMC->ild_factors_fx[k] ) );
+
+ Nrqq_fx[h_ild_mapping->ild_index[k]] = L_tmp;
+ move32();
+ Nrqq_e[h_ild_mapping->ild_index[k]] = add( tmp_e, ref_ener_e );
+ move16();
+ }
+
+ /* estimate ICCs from estimated Cproto */
+
+ FOR( k = 0; k < nY_int; k++ )
+ {
+ // a_fx[k] = 1.f / ( sqrtf( Cproto_fx[k + nY_int * k] ) + EPSILON );
+ tmp_e = Cp_buf_e[k + ( nY_int * k )];
+ move16();
+
+ IF( Cproto_fx[k + ( nY_int * k )] != 0 )
+ {
+ L_tmp = ISqrt32( Cproto_fx[k + ( nY_int * k )], &tmp_e );
+ }
+ ELSE
+ {
+ L_tmp = INV_EPSILON_MANT;
+ move32();
+ tmp_e = 15;
+ move16();
+ }
+ a_fx[k] = L_tmp;
+ move32();
+ a_e[k] = tmp_e;
+ move16();
+
+ FOR( l = 0; l < nY_int; l++ )
+ {
+ Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cproto_fx[( k * nY_int ) + l], a_fx[k] );
+ move32();
+ Cy_state_int_e[( k * nY_int ) + l] = add( Cp_buf_e[( k * nY_int ) + l], a_e[k] );
+ move16();
+ }
+ }
+
+ FOR( k = 0; k < nY_int; k++ )
+ {
+ Cyp_fx = Cy_state_int_fx + k;
+ Cyp_e = Cy_state_int_e + k;
+ ap_fx = a_fx[k];
+ move32();
+ ap_e = a_e[k];
+ move16();
+
+ FOR( l = 0; l < nY_int; l++ )
+ {
+ ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
+ move32();
+ *Cyp_e = add( *Cyp_e, ap_e );
+ move16();
+
+ Cyp_fx += nY_int;
+ Cyp_e += nY_int;
+ }
+ }
+
+ /*normalizing the Cy_state_int_fx to a common exponent*/
+
+ /* replace some estimated ICCs with transmitted values */
+ FOR( k = 0; k < hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; k++ )
+ {
+ Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp );
+ move32();
+ Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = tmp;
+ move16();
+ Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp );
+ move32();
+ Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = tmp;
+ move16();
+ }
+
+ test();
+ IF( GE_16( param_band_index, PARAM_MC_MAX_BAND_LFE ) || ( hParamMC->hMetadataPMC->lfe_on == 0 ) )
+ {
+ FOR( k = 0; k < nY_int; k++ )
+ {
+ Cy_state_int_fx[k + ( 3 * nY_int )] = ONE_IN_Q31;
+ move32();
+ Cy_state_int_e[k + ( 3 * nY_int )] = 0;
+ move16();
+ Cy_state_int_fx[3 + ( k * nY_int )] = ONE_IN_Q31;
+ move32();
+ Cy_state_int_e[3 + ( k * nY_int )] = 0;
+ move16();
+ }
+ Nrqq_fx[3] = 0;
+ move32();
+ }
+
+ /* Generate back Covariance Mtx */
+ FOR( k = 0; k < nY_int; k++ )
+ {
+ tmp_e = Nrqq_e[k];
+ move16();
+ a_fx[k] = Sqrt32( Nrqq_fx[k], &tmp_e );
+ move32();
+ a_e[k] = tmp_e;
+ move16();
+
+ /* v_multc( Cy_state_int_fx + k * nY_int, a_fx[k], Cy_state_int_fx + k * nY_int, nY_int ) */
+ FOR( l = 0; l < nY_int; l++ )
+ {
+ Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cy_state_int_fx[( k * nY_int ) + l], a_fx[k] );
+ move32();
+ Cy_state_int_e[( k * nY_int ) + l] = add( Cy_state_int_e[( k * nY_int ) + l], a_e[k] );
+ move16();
+ }
+ }
+
+ FOR( k = 0; k < nY_int; k++ )
+ {
+ Cyp_fx = Cy_state_int_fx + k;
+ Cyp_e = Cy_state_int_e + k;
+ ap_fx = a_fx[k];
+ move32();
+ ap_e = a_e[k];
+ move16();
+
+ FOR( l = 0; l < nY_int; l++ )
+ {
+ ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
+ move32();
+ ( *Cyp_e ) = add( *Cyp_e, ap_e );
+ move16();
+
+ Cyp_fx += nY_int;
+ Cyp_e += nY_int;
+ }
+ }
+
+ IF( EQ_32( synth_conf, PARAM_MC_SYNTH_LS_CONV_COV ) )
+ {
+ /* Cy = dmx*Cy*dmx' */
+ Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
+ Word16 mat_mult_buffer1_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
+ Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; // Q(31 - target_ch_ener_e)
+ Word16 target_ch_ener_e[MAX_CICP_CHANNELS];
+ Word32 dmx_ch_ener_fx[MAX_CICP_CHANNELS];
+
+ Word16 ls_conv_dmx_matrix_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
+
+ set32_fx( target_ch_ener_fx, 0, MAX_CICP_CHANNELS );
+ set16_fx( target_ch_ener_e, 0, MAX_CICP_CHANNELS );
+ set32_fx( dmx_ch_ener_fx, 0, MAX_CICP_CHANNELS );
+ set16_fx( ls_conv_dmx_matrix_e, 1, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
+
+ matrix_product_mant_exp( hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 0,
+ Cy_state_int_fx, Cy_state_int_e, nY_int, nY_int, 0,
+ mat_mult_buffer1_fx, mat_mult_buffer1_e );
+
+ matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_cov, nY_int, 0,
+ hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 1,
+ Cy_state_fx, Cy_buf_e );
+
+ FOR( k = 0; k < nY_cov; k++ )
+ {
+ FOR( l = 0; l < nY_int; l++ )
+ {
+ L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[k + ( l * nY_cov )], Nrqq_fx[l] );
+ tmp_e = add( ls_conv_dmx_matrix_e[k + ( l + nY_cov )], Nrqq_e[l] );
+ L_tmp = BASOP_Util_Add_Mant32Exp( target_ch_ener_fx[k], target_ch_ener_e[k], L_tmp, tmp_e, &tmp_e );
+ target_ch_ener_fx[k] = L_tmp;
+ move32();
+ target_ch_ener_e[k] = tmp_e;
+ move16();
+ }
+
+ dmx_ch_ener_fx[k] = Cy_state_fx[k + ( nY_cov * k )];
+ move32();
+
+ IF( dmx_ch_ener_fx[k] < 0 )
+ {
+ Cy_state_fx[k + ( nY_cov * k )] = L_negate( Cy_state_fx[k + ( nY_cov * k )] );
+ move32();
+ dmx_ch_ener_fx[k] = L_negate( dmx_ch_ener_fx[k] );
+ move32();
+ }
+
+ IF( extract_h( dmx_ch_ener_fx[k] ) == 0 )
+ {
+ target_ch_ener_fx[k] = 0;
+ move32();
+ target_ch_ener_e[k] = 0;
+ move16();
+ }
+ ELSE
+ {
+ BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[k + ( nY_cov * k )], &tmp, &tmp_e );
+ tmp = Sqrt16( tmp, &tmp_e );
+ target_ch_ener_fx[k] = L_deposit_h( tmp );
+ move32();
+ target_ch_ener_e[k] = tmp_e;
+ move16();
+ }
+
+ FOR( l = 0; l < nY_cov; l++ )
+ {
+ Cy_state_fx[( k * nY_cov ) + l] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[( k * nY_cov ) + l] );
+ move32();
+ Cy_buf_e[( k * nY_cov ) + l] = add( target_ch_ener_e[k], Cy_buf_e[( k * nY_cov ) + l] );
+ move16();
+ }
+
+ Cyp_fx = Cy_state_fx + k;
+ Cyp_e = Cy_buf_e + k;
+ ap_fx = target_ch_ener_fx[k];
+ move32();
+ ap_e = target_ch_ener_e[k];
+ move16();
+ FOR( l = 0; l < nY_cov; l++ )
+ {
+ ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
+ move32();
+ *Cyp_e = add( *Cyp_e, ap_e );
+ move16();
+
+ Cyp_fx += nY_cov;
+ Cyp_e += nY_cov;
+ }
+ }
+ }
+ ELSE
+ {
+ Copy32( Cy_state_int_fx, Cy_state_fx, imult1616( nY_int, nY_int ) );
+ Copy( Cy_state_int_e, Cy_buf_e, imult1616( nY_int, nY_int ) );
+ }
+
+ /*normalize output matrix to a common exponent*/
+ tmp = 0;
+ FOR( k = 0; k < nY_int * nY_int; k++ )
+ {
+ Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] );
+ move32();
+ tmp = s_max( tmp, Cy_buf_e[k] );
+ }
+ FOR( k = 0; k < nY_int * nY_int; k++ )
+ {
+ L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) );
+ Cy_state_fx[k] = L_tmp;
+ move32();
+ }
+ *Cy_state_e = tmp;
+ move16();
+
+ return;
+}
+
+/*-------------------------------------------------------------------------*
+ * param_mc_set_num_synth_bands()
+ *
+ * set the number of frequency bands to be synthesized
+ *-------------------------------------------------------------------------*/
+
+static void param_mc_set_num_synth_bands(
+ const Word32 output_Fs, /* i : output sampling frequency */
+ PARAM_MC_DEC_HANDLE hParamMC /* i/o: Parametric MC handle */
+)
+{
+ UWord16 max_param_band_synth;
+ const Word16 *param_mc_bands_coded;
+
+ SWITCH( hParamMC->hMetadataPMC->num_parameter_bands )
+ {
+ case 20:
+ param_mc_bands_coded = param_mc_bands_coded_20;
+ BREAK;
+ case 10:
+ param_mc_bands_coded = param_mc_bands_coded_10;
+ BREAK;
+ case 14:
+ default:
+ param_mc_bands_coded = param_mc_bands_coded_14;
+ BREAK;
+ }
+ move16();
+ SWITCH( output_Fs )
+ {
+ case 8000:
+ max_param_band_synth = (UWord16) param_mc_bands_coded[NB];
+ BREAK;
+ case 16000:
+ max_param_band_synth = (UWord16) param_mc_bands_coded[WB];
+ BREAK;
+ case 32000:
+ max_param_band_synth = (UWord16) param_mc_bands_coded[SWB];
+ BREAK;
+ case 48000:
+ default:
+ max_param_band_synth = (UWord16) param_mc_bands_coded[FB];
+ BREAK;
+ }
+ move16();
+ hParamMC->num_param_bands_synth = s_min( hParamMC->hMetadataPMC->nbands_coded, max_param_band_synth );
+ move16();
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------*
+ * param_mc_get_diff_proto_info()
+ *
+ * calculated the diffuse prototype information
+ *-------------------------------------------------------------------------*/
+
+
+static ivas_error param_mc_get_diff_proto_info_fx(
+ const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */
+ const UWord16 nchan_transport, /* i : number of transport channels */
+ const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */
+ PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, /* o : generated diffuse prototype info */
+ Word16 Q_proto_mtx )
+{
+ Word32 proto_fac_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
+ UWord16 cur_out_ch;
+ UWord16 cur_diff_proto;
+ UWord16 cur_transport_ch;
+ UWord16 max_num_src_chan;
+
+ /* Initializations */
+ max_num_src_chan = 0;
+ move16();
+
+ set_zero_fx( proto_fac_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
+ IF( ( p_diff_proto_info->proto_index_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ set16_fx( p_diff_proto_info->proto_index_diff, 0, nchan_out_cov );
+
+ IF( ( p_diff_proto_info->num_source_chan_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ set16_fx( p_diff_proto_info->num_source_chan_diff, 0, nchan_out_cov );
+
+ /* we have at least one prototype, copy the first one */
+ p_diff_proto_info->num_protos_diff = 1;
+ move16();
+
+ mvr2r_inc_fixed( proto_mtx, nchan_out_cov, proto_fac_fx, nchan_out_cov, nchan_transport );
+ p_diff_proto_info->proto_index_diff[0] = 0;
+ move16();
+
+ /* search for distinct prototypes */
+ FOR( cur_out_ch = 1; cur_out_ch < nchan_out_cov; cur_out_ch++ )
+ {
+ UWord16 found = 0;
+ move16();
+
+ FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
+ {
+ Word32 diff_fx = 0;
+ move32();
+ Word32 *proto_fac_ptr_fx = proto_fac_fx + cur_diff_proto;
+ const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
+ FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
+ {
+ diff_fx = L_add( diff_fx, L_abs( L_sub( *proto_fac_ptr_fx, *proto_mtx_ptr ) ) );
+ proto_fac_ptr_fx += nchan_out_cov;
+ proto_mtx_ptr += nchan_out_cov;
+ }
+
+ /* we already have this prototype, save the index */
+ IF( LT_64( W_mult0_32_32( diff_fx, 10 ), L_shl_sat( 1, Q_proto_mtx ) ) )
+ {
+ found = 1;
+ move16();
+ p_diff_proto_info->proto_index_diff[cur_out_ch] = cur_diff_proto;
+ move16();
+ BREAK;
+ }
+ }
+
+ /* new distinct prototype, add it */
+ IF( found == 0 )
+ {
+ const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
+ Word16 cur_num_src_chan;
+
+ cur_num_src_chan = 0;
+ move16();
+ FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
+ {
+ if ( GT_32( *proto_mtx_ptr, 0 /*EPSILON*/ ) )
+ {
+ cur_num_src_chan = add( cur_num_src_chan, 1 );
+ }
+ proto_mtx_ptr += nchan_out_cov;
+ }
+
+ mvr2r_inc_fixed( proto_mtx + cur_out_ch, nchan_out_cov, proto_fac_fx + p_diff_proto_info->num_protos_diff, nchan_out_cov, nchan_transport );
+
+ p_diff_proto_info->proto_index_diff[cur_out_ch] = p_diff_proto_info->num_protos_diff;
+ move16();
+ p_diff_proto_info->num_protos_diff = add( p_diff_proto_info->num_protos_diff, 1 );
+ move16();
+ max_num_src_chan = s_max( max_num_src_chan, cur_num_src_chan );
+ }
+ }
+
+ /* set up the prototype info struct */
+ IF( ( p_diff_proto_info->source_chan_idx = (Word16 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word16 * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+
+ IF( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+ FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
+ {
+ Word32 *proto_fac_ptr;
+
+ IF( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (Word16 *) malloc( max_num_src_chan * sizeof( Word16 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+
+ IF( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
+ }
+
+ proto_fac_ptr = proto_fac_fx + cur_diff_proto;
+ FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
+ {
+ IF( GT_32( *proto_fac_ptr, EPSILON_FX_SMALL ) )
+ {
+ p_diff_proto_info->source_chan_idx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = cur_transport_ch;
+ move16();
+ p_diff_proto_info->proto_fac_fx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = L_shl( *proto_fac_ptr, 4 ); // (proto_fac_fx)Q26 + 4 = Q30
+ move16();
+ p_diff_proto_info->num_source_chan_diff[cur_diff_proto] = add( p_diff_proto_info->num_source_chan_diff[cur_diff_proto], 1 );
+ move16();
+ }
+ proto_fac_ptr += nchan_out_cov;
+ }
+ }
+ return IVAS_ERR_OK;
+}
+
+
+/*-------------------------------------------------------------------------*
+ * ivas_param_mc_bs_decode_parameter_values()
+ *
+ * reads and decodes a sequence of Parametric MC parameters from the bitstream
+ *-------------------------------------------------------------------------*/
+
+static void ivas_param_mc_bs_decode_parameter_values_fx(
+ UWord16 bit_buffer[], /* i : bitstream buffer */
+ Word16 *bit_pos, /* i/o: current bitstream buffer position */
+ const Word16 max_bits, /* i : maximum available bits in the buffer */
+ Word16 *BER_detect, /* i/o: bit error detection flag */
+ HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, /* i : Parametric MC metadata information */
+ HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, /* i : Parametric MC parameter quantization and coding tables */
+ const Word16 map_size_wo_lfe, /* i : number of parameters per band (w/o LFEs) */
+ const Word16 map_size, /* i : number of parameters per band (total) */
+ const Word16 num_lfe_bands, /* i : number of parameter bands with coded LFE */
+ const Word16 band_step, /* i : parameter band step */
+ const Word16 num_param_bands, /* i : number of parameter bands to decode */
+ Word16 *value_buffer /* o : output buffer for decoded parameter values hParamCodingInfo -> Q-quant*/
+)
+{
+ Word16 range_coding;
+ Word16 sz_seq;
+ Word16 delta_coding;
+ Word16 delta_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
+ Word16 idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
+ Word16 idx_prev;
+ Word16 idx_offset;
+ Word16 sz_alphabet;
+ Word16 i, j, k;
+ Word16 dequant_seq_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
+ Word16 dequant_ordered_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
+ Word16 n_lfe_idx;
+
+ range_coding = bit_buffer[*bit_pos];
+ move16();
+ *bit_pos = add( *bit_pos, 1 );
+ move16();
+
+ /* Decoding the sequence */
+ n_lfe_idx = sub( map_size, map_size_wo_lfe );
+ sz_seq = add( imult1616( num_param_bands, map_size_wo_lfe ), imult1616( num_lfe_bands, n_lfe_idx ) );
+
+ set16_fx( idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
+ set16_fx( dequant_ordered_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
+ set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
+ IF( range_coding )
+ {
+ delta_coding = bit_buffer[*bit_pos];
+ move16();
+ *bit_pos = add( *bit_pos, 1 );
+ move16();
+
+ IF( delta_coding )
+ {
+ idx_prev = sub( add( shr( hParamCodingInfo->quantizer_size, 1 ), hParamCodingInfo->quantizer_size % 2 ), 1 );
+ sz_alphabet = sub( shl( hParamCodingInfo->quantizer_size, 1 ), 1 );
+ idx_offset = sub( hParamCodingInfo->quantizer_size, 1 );
+
+ /* read range coded delta ICC indices */
+ *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], delta_idx, BER_detect, sz_seq, sz_alphabet,
+ hParamCodingInfo->cum_freq_delta, hParamCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
+ move16();
+
+ /* delta index to absolute index */
+ FOR( j = 0; j < sz_seq; j++ )
+ {
+ idx[j] = add( idx_prev, sub( delta_idx[j], idx_offset ) );
+ idx_prev = idx[j];
+ move16();
+ }
+ }
+ ELSE
+ {
+ /* read range coded absolute ICC indices */
+ sz_alphabet = hParamCodingInfo->quantizer_size;
+ move16();
+ *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], idx, BER_detect, sz_seq, sz_alphabet,
+ hParamCodingInfo->cum_freq, hParamCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
+ move16();
+ }
+
+ /* dequantize */
+ FOR( j = 0; j < sz_seq; j++ )
+ {
+ dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; // hParamCodingInfo -> Q-quant
+ move16();
+ }
+ }
+ ELSE
+ {
+ set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
+ /* read uniformly coded ICCs */
+ *bit_pos = add( *bit_pos, ivas_param_mc_uniform_decoder_fx( dequant_seq_fx, sz_seq, hParamCodingInfo->quantizer_fx, hParamCodingInfo->uni_bits, &bit_buffer[*bit_pos] ) );
+ move16();
+ }
+
+ /* reorder from sequential to parameter-band-wise */
+ k = 0;
+ FOR( j = 0; j < map_size_wo_lfe; ++j )
+ {
+ FOR( i = 0; i < num_param_bands; ++i )
+ {
+ dequant_ordered_fx[j + ( i * map_size )] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
+ move16();
+ k = add( k, 1 );
+ }
+ }
+
+ FOR( i = 0; i < num_lfe_bands; i++ )
+ {
+ FOR( j = 0; j < n_lfe_idx; j++ )
+ {
+ dequant_ordered_fx[map_size - n_lfe_idx + j + i * map_size] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
+ move16();
+ k = add( k, 1 );
+ }
+ }
+
+ IF( !( *BER_detect ) )
+ {
+ j = 0;
+ FOR( k = 0; k < hMetadataPMC->nbands_coded; k += band_step )
+ {
+ test();
+ IF( hMetadataPMC->bAttackPresent || EQ_16( hMetadataPMC->param_frame_idx, hMetadataPMC->coding_band_mapping[k] ) )
+ {
+ Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); // hParamCodingInfo -> Q-quant
+ j++;
+ }
+ IF( hMetadataPMC->bAttackPresent && k + 1 < hMetadataPMC->nbands_coded )
+ {
+ Copy( value_buffer + imult1616( k, map_size ), value_buffer + imult1616( add( k, 1 ), map_size ), map_size );
+ }
+ }
+ }
+
+ return;
+}
+
Word16 param_mc_get_num_cldfb_syntheses_ivas_fx(
Decoder_Struct *st_ivas /* i : Parametric MC handle */
)
diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_mc_paramupmix_dec.c
rename to lib_dec/ivas_mc_paramupmix_dec_fx.c
index 9e25fcb5190335c03392834fd3c378a4a9728e69..353582b945641b132dc9c550303c72d4e97d23cc 100644
--- a/lib_dec/ivas_mc_paramupmix_dec.c
+++ b/lib_dec/ivas_mc_paramupmix_dec_fx.c
@@ -34,7 +34,6 @@
#include
#include "options.h"
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "ivas_prot.h"
@@ -133,7 +132,8 @@ void ivas_mc_paramupmix_dec_read_BS(
nb_bits_read_orig = 0;
move16();
last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /* reverse the bitstream for easier reading of indices */
- FOR( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ )
+ Word16 len = s_min( MAX_BITS_METADATA, last_bit_pos );
+ FOR( i = 0; i < len; i++ )
{
bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
move16();
@@ -270,7 +270,8 @@ void ivas_mc_paramupmix_dec_render(
ivas_mc_paramupmix_dec_sf( st_ivas, output_local_fx );
- FOR( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ )
+ Word16 num_ch = s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) );
+ FOR( ch = 0; ch < num_ch; ch++ )
{
output_local_fx[ch] += n_samples_sf;
}
@@ -418,7 +419,7 @@ ivas_error ivas_mc_paramupmix_dec_open(
move16();
}
- IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
+ IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
{
return error;
}
diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_mcmasa_dec.c
rename to lib_dec/ivas_mcmasa_dec_fx.c
index 687efb3ce45f53bbb55b970f668845e232ccea1f..c2228b610172eab88f9a4e51106e976b3010fc6e 100644
--- a/lib_dec/ivas_mcmasa_dec.c
+++ b/lib_dec/ivas_mcmasa_dec_fx.c
@@ -35,7 +35,7 @@
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_mct_core_dec.c b/lib_dec/ivas_mct_core_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_mct_core_dec.c
rename to lib_dec/ivas_mct_core_dec_fx.c
index 824370bb8bfb0d4522b78f709741ebc206dcae62..be457da471440ba698e8fc64ada90e5ac9902156 100644
--- a/lib_dec/ivas_mct_core_dec.c
+++ b/lib_dec/ivas_mct_core_dec_fx.c
@@ -33,7 +33,7 @@
#include
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
#include "cnst.h"
@@ -42,7 +42,6 @@
#include "ivas_prot.h"
#include "ivas_stat_dec.h"
#include "ivas_stat_com.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
/*-----------------------------------------------------------------*
diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_mct_dec.c
rename to lib_dec/ivas_mct_dec_fx.c
index 4af691affc0d64f83833a51c853a49944ba621ba..955fa6db0c7b19bf47aa754fe998060a234805e5 100644
--- a/lib_dec/ivas_mct_dec.c
+++ b/lib_dec/ivas_mct_dec_fx.c
@@ -38,7 +38,6 @@
#include "ivas_cnst.h"
#include "rom_com.h"
#include "prot_fx.h"
-#include "prot.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
#include "ivas_rom_com.h"
@@ -430,11 +429,11 @@ ivas_error ivas_mct_dec_fx(
Word16 output_mem_fx[L_FRAME48k];
IF( hCPE->output_mem_fx[1] != NULL )
{
- Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), -Q11 );
+ Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA_FX2( sts[n]->output_Fs, 3125000 ), -Q11 );
}
ELSE
{
- set16_fx( output_mem_fx, 0, NS2SA( sts[n]->output_Fs, 3125000 ) );
+ set16_fx( output_mem_fx, 0, NS2SA_FX2( sts[n]->output_Fs, 3125000 ) );
}
Word16 Q_synth = sub( 15, e_sig[n] );
@@ -461,9 +460,9 @@ ivas_error ivas_mct_dec_fx(
#endif
/* Save synthesis for HQ FEC */
Word32 output_fx_[L_FRAME48k];
- Copy32( output_fx[( cpe_id * CPE_CHANNELS ) + n], output_fx_, L_FRAME48k ); // Q11
- Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 ); // Q11 -> Q16
- Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); // Q11 -> Q0
+ Copy32( output_fx[( cpe_id * CPE_CHANNELS ) + n], output_fx_, L_FRAME48k ); // Q11
+ Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 ); // Q11 -> Q16
+ Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -Q11 ); // Q11 -> Q0
sts[n]->q_prev_synth_buffer_fx = 0;
move16();
diff --git a/lib_dec/ivas_mct_dec_mct_fx.c b/lib_dec/ivas_mct_dec_mct_fx_fx.c
similarity index 99%
rename from lib_dec/ivas_mct_dec_mct_fx.c
rename to lib_dec/ivas_mct_dec_mct_fx_fx.c
index 331bdc2538e1feff86a39064ef649c7926bf673d..69f60172409dd590e7d861576fd5dfd03a38b94d 100644
--- a/lib_dec/ivas_mct_dec_mct_fx.c
+++ b/lib_dec/ivas_mct_dec_mct_fx_fx.c
@@ -34,11 +34,10 @@
#include "options.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include
#include "stat_enc.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
/*----------------------------------------------------------*
diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_mdct_core_dec.c
rename to lib_dec/ivas_mdct_core_dec_fx.c
index 2158dec1c635b869514942fb7f0d1e3722bdd9f5..7f079277a5fb8b76e53ad8975ccdda0cab84849b 100644
--- a/lib_dec/ivas_mdct_core_dec.c
+++ b/lib_dec/ivas_mdct_core_dec_fx.c
@@ -33,7 +33,7 @@
#include
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
@@ -44,7 +44,6 @@
#include "ivas_stat_dec.h"
#include "ivas_stat_com.h"
#include
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
@@ -1361,7 +1360,7 @@ void ivas_mdct_core_reconstruct_fx(
/* Update */
Copy( synth_buf_fx + st->L_frame, st->hTcxDec->old_synth, st->hTcxDec->old_synth_len );
- Copy( st->hTcxDec->old_synthFB_fx + st->hTcxDec->L_frameTCX - NS2SA( st->output_Fs, PH_ECU_MEM_NS ), st->hTcxDec->synth_history_fx, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) );
+ Copy( st->hTcxDec->old_synthFB_fx + st->hTcxDec->L_frameTCX - NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ), st->hTcxDec->synth_history_fx, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) );
Copy( synth_bufFB_fx + st->hTcxDec->L_frameTCX, st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB );
st->hTcxDec->q_old_synth = q_syn;
st->hTcxDec->q_synth_history_fx = st->hTcxDec->q_old_synth;
@@ -1371,7 +1370,7 @@ void ivas_mdct_core_reconstruct_fx(
IF( st->hHQ_core != NULL )
{
- Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
+ Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + st->hTcxDec->old_synth_lenFB, NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
}
Copy( st->lsp_q_cng, st->old_lsp_q_cng, M );
diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer_fx.c
similarity index 99%
rename from lib_dec/ivas_mono_dmx_renderer.c
rename to lib_dec/ivas_mono_dmx_renderer_fx.c
index 231aee8aaf0c2a827e56898d572f899a250ba0fb..bb5dead226be1db979fd337510acdc410ee4ea1c 100644
--- a/lib_dec/ivas_mono_dmx_renderer.c
+++ b/lib_dec/ivas_mono_dmx_renderer_fx.c
@@ -34,7 +34,6 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal_fx.c
similarity index 99%
rename from lib_dec/ivas_objectRenderer_internal.c
rename to lib_dec/ivas_objectRenderer_internal_fx.c
index 98d9c73fc68294e65ddfbb653cf712dc1456fd93..f1f60d9634b0177e29d744affb8b5318725728e5 100644
--- a/lib_dec/ivas_objectRenderer_internal.c
+++ b/lib_dec/ivas_objectRenderer_internal_fx.c
@@ -32,14 +32,13 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
#include
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#include "debug.h"
diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_omasa_dec.c
rename to lib_dec/ivas_omasa_dec_fx.c
index c812dcfd1ef69e74f3ac3db7d0e776d31c63b4ab..f473dc2818738d21eec2c1cab46de3cf78d22165 100644
--- a/lib_dec/ivas_omasa_dec.c
+++ b/lib_dec/ivas_omasa_dec_fx.c
@@ -35,12 +35,11 @@
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot_rend.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*-------------------------------------------------------------------------
diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_osba_dec.c
rename to lib_dec/ivas_osba_dec_fx.c
index 0bdc3528af6206d5491fd6bd802b5ca7f213bbe9..9c111e7a20ea851e2df1b0efb0d0fad5a6eb39e9 100644
--- a/lib_dec/ivas_osba_dec.c
+++ b/lib_dec/ivas_osba_dec_fx.c
@@ -34,12 +34,11 @@
#include
#include "ivas_cnst.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot_rend.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*-------------------------------------------------------------------*
diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion_fx.c
similarity index 99%
rename from lib_dec/ivas_out_setup_conversion.c
rename to lib_dec/ivas_out_setup_conversion_fx.c
index 02f37672dd740bee0e8c443e1e1f863599eac070..4811911fd2778a35d71973288e2785d28eb5b80b 100644
--- a/lib_dec/ivas_out_setup_conversion.c
+++ b/lib_dec/ivas_out_setup_conversion_fx.c
@@ -34,13 +34,12 @@
#include "options.h"
#include
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
#include "ivas_rom_com.h"
#include "ivas_rom_rend.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "debug.h"
diff --git a/lib_dec/ivas_output_config.c b/lib_dec/ivas_output_config_fx.c
similarity index 100%
rename from lib_dec/ivas_output_config.c
rename to lib_dec/ivas_output_config_fx.c
diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c
index 4a0c62e8d6a36bf22aa51a07e8eb1e17003a757b..08ac1779994247043cd6e90e71517ed8d674476f 100644
--- a/lib_dec/ivas_pca_dec_fx.c
+++ b/lib_dec/ivas_pca_dec_fx.c
@@ -32,12 +32,11 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include
#include "ivas_cnst.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "math.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc_fx.c
similarity index 94%
rename from lib_dec/ivas_post_proc.c
rename to lib_dec/ivas_post_proc_fx.c
index dc4a1b01bb535cb49e980cd586ad705cc9669c0f..397f26bbce038c9571439bbbd6aba094bb3e8bd8 100644
--- a/lib_dec/ivas_post_proc.c
+++ b/lib_dec/ivas_post_proc_fx.c
@@ -35,7 +35,6 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
@@ -159,7 +158,7 @@ void ivas_post_proc_fx(
ELSE
{
/*Use channel 0 side info.*/
- tcx_ltp_post32( sts[0], hTcxLtpDec, TCX_20_CORE, output_frame, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ), output[k], hCPE->output_mem_fx[k], output_q );
+ tcx_ltp_post32( sts[0], hTcxLtpDec, TCX_20_CORE, output_frame, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), output[k], hCPE->output_mem_fx[k], output_q );
}
}
}
@@ -268,7 +267,7 @@ void stereo_dft_dec_core_switching_fx(
IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( sba_dirac_stereo_dtx_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */
{
/* In case of a TCX to ACELP switch next frame */
- Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/
+ Copy32( &output_fx[st->L_frame - NS2SA( ( st->L_frame * FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/
/* BPF */
test();
@@ -315,8 +314,8 @@ void stereo_dft_dec_core_switching_fx(
/* Update FB input buff with hb synth FOR last delay_tdbwe sampled */
FOR( i = 0; i < delay_tdbwe; i++ )
{
- hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] =
- L_add( hCPE->input_mem_fx[0][NS2SA_FX2( L_add( L_sub( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )], hb_synth_fx[i] ); /*Q11*/
+ hCPE->input_mem_fx[0][( ( NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] =
+ L_add( hCPE->input_mem_fx[0][NS2SA( ( ( L_frameTCX * FRAMES_PER_SEC ) - STEREO_DFT32MS_OVL_NS ) + delay_tdbwe, i )], hb_synth_fx[i] ); /*Q11*/
move32();
}
}
@@ -325,7 +324,7 @@ void stereo_dft_dec_core_switching_fx(
/* Update FB input buff with hb synth FOR last delay_tdbwe sampled */
FOR( i = 0; i < delay_tdbwe; i++ )
{
- hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] = hb_synth_fx[i]; /*Q11*/
+ hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] = hb_synth_fx[i]; /*Q11*/
move32();
}
}
@@ -368,7 +367,7 @@ void stereo_dft_dec_core_switching_fx(
/* In case of TCX frames, output LB TCX is zeroed out until the end but in case of an TCX->ACELP switch, this memory is needed, hence it is backed up */
/* Unlike the case when DFT32MS is disabled, there is only 1 DFT analysis window, hence in the TCX frame we don't want to do a DFT analysis FOR LB TCX
but in a potential ACELP frame, we want the memories of the LB TCX FOR the last OLA samples so that HB analysis can be skipped */
- Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/
+ Copy32( &output_fx[st->L_frame - NS2SA_FX2( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/
/*zero the rest FOR avoiding adding contribution except the last samples which are not considered in DFT analysis (potentially used in next ACELP frame)*/
IF( GT_32( st->last_core_brate, SID_2k40 ) )
@@ -418,8 +417,8 @@ void stereo_dft_dec_core_switching_fx(
delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*Q0*/
move16();
- Copy32( &st->hHQ_core->oldOut_fx[( nZeros - ( delay_comp + NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*Q11*/
- Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/
+ Copy32( &st->hHQ_core->oldOut_fx[nZeros - ( delay_comp + NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*Q11*/
+ Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/
Word16 mem_len;
mem_len = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /*Q0*/
@@ -462,11 +461,11 @@ void stereo_dft_dec_core_switching_fx(
Word32 delay_dft_dec_lb_inv = (Word32) ( calc_inv / delay_dft_dec_lb );
FOR( i = 0; i < delay_dft_dec_lb; i++ )
{
- hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] =
- Mpy_32_32( hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )], L_shl( i, qdelay_dft_dec_lb ) ); /*Q11 + qdelay_dft_dec_lb -31*/
+ hCPE->input_mem_LB_fx[0][( ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] =
+ Mpy_32_32( hCPE->input_mem_LB_fx[0][( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i], L_shl( i, qdelay_dft_dec_lb ) ); /*Q11 + qdelay_dft_dec_lb -31*/
move32();
- hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] =
- L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )], delay_dft_dec_lb_inv ), sub( Q31, qdelay_dft_dec_lb ) ); /*Q11*/
+ hCPE->input_mem_LB_fx[0][( ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] =
+ L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][( ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )], delay_dft_dec_lb_inv ), sub( Q31, qdelay_dft_dec_lb ) ); /*Q11*/
move32();
}
stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, q, q_DFT );
diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_qmetadata_dec.c
rename to lib_dec/ivas_qmetadata_dec_fx.c
index c225f126aa014c9ac3332c93f920a47f3d33f21c..81768af442f305c5ff5ec025929f5ffe84d75c26 100644
--- a/lib_dec/ivas_qmetadata_dec.c
+++ b/lib_dec/ivas_qmetadata_dec_fx.c
@@ -39,9 +39,8 @@
#include "ivas_rom_com.h"
#include "ivas_rom_dec.h"
#include "wmc_auto.h"
-#include "prot.h"
-
#include "prot_fx.h"
+
#include "ivas_prot_fx.h"
#include "ivas_rom_com_fx.h"
@@ -3258,7 +3257,8 @@ static Word16 read_truncGR_azimuth_fx(
move16();
IF( LE_16( allowed_bits, add( no_subframes, 1 ) ) )
{
- FOR( i = 0; i < min( allowed_bits, no_subframes ); i++ )
+ Word16 len = s_min( allowed_bits, no_subframes );
+ FOR( i = 0; i < len; i++ )
{
IF( bitstream[( *pbit_pos )--] == 0 )
{
diff --git a/lib_dec/ivas_qspherical_dec.c b/lib_dec/ivas_qspherical_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_qspherical_dec.c
rename to lib_dec/ivas_qspherical_dec_fx.c
index 43ac6030557aee745f295581b745a3df14939641..d34b5402a4ce84081152aa721c94d1f3be39fd7a 100644
--- a/lib_dec/ivas_qspherical_dec.c
+++ b/lib_dec/ivas_qspherical_dec_fx.c
@@ -37,7 +37,7 @@
#include "ivas_rom_com.h"
#include "ivas_stat_dec.h"
#include "wmc_auto.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_rom_com_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_range_uni_dec.c
rename to lib_dec/ivas_range_uni_dec_fx.c
index 6d6631f73ef26fef8765f8063be276a2c31f6056..e629111ced3c993f1a140148136f843b44220768 100644
--- a/lib_dec/ivas_range_uni_dec.c
+++ b/lib_dec/ivas_range_uni_dec_fx.c
@@ -38,10 +38,9 @@
#include "rom_com.h"
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*
diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_sba_dec.c
rename to lib_dec/ivas_sba_dec_fx.c
index f5723f8bb642b47b5da848811b2e8c27228c0dcf..233b897b260d3cecb8d7d4d996b2e2ec16b250a4 100644
--- a/lib_dec/ivas_sba_dec.c
+++ b/lib_dec/ivas_sba_dec_fx.c
@@ -35,7 +35,7 @@
#include "options.h"
#include "cnst.h"
#include "ivas_cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
#include "rom_com.h"
@@ -44,7 +44,6 @@
#include
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*-------------------------------------------------------------------*
* ivas_sba_set_cna_cng_flag()
*
@@ -235,7 +234,7 @@ ivas_error ivas_sba_dec_reconfigure_fx(
}
/* determine new granularity */
- granularity_new = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/
+ granularity_new = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/
move16();
/* this will change anyway only with binaural */
diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c
index 150d81b13d68cd228ffcd96b71dcc940e7f2ab13..21c9a115b872f290862504e08b7cb06e39c76368 100644
--- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c
+++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c
@@ -1295,7 +1295,7 @@ void ivas_sba_dirac_stereo_dec_fx(
sba_mono_flag = (Word16) EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 );
move16();
- memOffset = NS2SA( L_mult0( output_frame, FRAMES_PER_SEC ), IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS );
+ memOffset = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS );
move16();
ivas_sba_dirac_stereo_config( hStereoDft->hConfig );
diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal_fx.c
similarity index 99%
rename from lib_dec/ivas_sba_rendering_internal.c
rename to lib_dec/ivas_sba_rendering_internal_fx.c
index 434fdf5fa25d447efa4f26eaf0160d8953113e94..a42c6738999656b7aeb116bd43bd79151b032046 100644
--- a/lib_dec/ivas_sba_rendering_internal.c
+++ b/lib_dec/ivas_sba_rendering_internal_fx.c
@@ -32,7 +32,7 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
#include "ivas_stat_dec.h"
@@ -40,7 +40,6 @@
#include
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#ifdef DEBUGGING
#include "debug.h"
#endif
diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c
index ce4992046a8a59bd0604d78f2bf3c2db7a53f673..89581565c7f2c64272fb55423df6f83b391f0dcd 100644
--- a/lib_dec/ivas_sce_dec_fx.c
+++ b/lib_dec/ivas_sce_dec_fx.c
@@ -36,7 +36,6 @@
#include "cnst.h"
#include "ivas_cnst.h"
#include "rom_com.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_sns_dec_fx.c b/lib_dec/ivas_sns_dec_fx.c
index 37489e58f84ef46437d4a0e0a092550de22e5d66..1702561810172cedc36bf9336cabcd2e1514e3ae 100644
--- a/lib_dec/ivas_sns_dec_fx.c
+++ b/lib_dec/ivas_sns_dec_fx.c
@@ -32,14 +32,13 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
#include "ivas_cnst.h"
#include
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_rom_com_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder_fx.c
similarity index 99%
rename from lib_dec/ivas_spar_decoder.c
rename to lib_dec/ivas_spar_decoder_fx.c
index e10d336d8c2cab48ad137f54f9f39f60e2947164..15a91cb7775269e9b536beac4ce7fa8d1729926e 100644
--- a/lib_dec/ivas_spar_decoder.c
+++ b/lib_dec/ivas_spar_decoder_fx.c
@@ -35,7 +35,7 @@
#include
#include "options.h"
#include "ivas_stat_dec.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "string.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
@@ -45,7 +45,6 @@
#include "ivas_stat_com.h"
#include "stat_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#ifdef DEBUGGING
#include "debug.h"
diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_spar_md_dec.c
rename to lib_dec/ivas_spar_md_dec_fx.c
index 3ad16b981fbbb74b84519fd0f97391fab5677819..d1efbbd2c6e2caa80971355f297794a3759dd961 100644
--- a/lib_dec/ivas_spar_md_dec.c
+++ b/lib_dec/ivas_spar_md_dec_fx.c
@@ -33,13 +33,12 @@
#include
#include "options.h"
#include "math.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_rom_com.h"
#include
#include "wmc_auto.h"
#include "ivas_stat_dec.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com_fx.h"
@@ -937,9 +936,10 @@ Word16 ivas_spar_chk_zero_coefs_fx(
ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; /*Q0*/
move16();
- FOR( b = 0; b < min( hMdDec->spar_md.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); b++ )
+ Word16 min_bands = s_min( hMdDec->spar_md.num_bands, SPAR_DIRAC_SPLIT_START_BAND );
+ FOR( b = 0; b < min_bands; b++ )
{
- FOR( j = 0; j < sub( add( ndm, ndec ), 1 ); j++ )
+ FOR( j = 0; j < ( ( ndm + ndec ) - 1 ); j++ )
{
if ( hMdDec->spar_md.band_coeffs[b].pred_re_fx[j] != 0 )
{
@@ -949,7 +949,7 @@ Word16 ivas_spar_chk_zero_coefs_fx(
}
FOR( j = 0; j < ndec; j++ )
{
- FOR( k = 0; k < sub( ndm, 1 ); k++ )
+ FOR( k = 0; k < ( ndm - 1 ); k++ )
{
if ( hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k] != 0 )
{
diff --git a/lib_dec/ivas_stereo_adapt_GR_dec.c b/lib_dec/ivas_stereo_adapt_GR_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_stereo_adapt_GR_dec.c
rename to lib_dec/ivas_stereo_adapt_GR_dec_fx.c
index c67a52b6c77db98e288ec4fe49206d5fbfd3d800..8446af47d29a991d5f4b8a8c0a6a777fac572d34 100644
--- a/lib_dec/ivas_stereo_adapt_GR_dec.c
+++ b/lib_dec/ivas_stereo_adapt_GR_dec_fx.c
@@ -32,12 +32,11 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot.h"
#include "ivas_rom_com.h"
#include "rom_dec.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
/*---------------------------------------------------------------------*
diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c
index c8985d7cd44487fba2c473f8f404b071a2df7e39..4d50ba3508a31475b8e22806485244136461c5ef 100644
--- a/lib_dec/ivas_stereo_cng_dec.c
+++ b/lib_dec/ivas_stereo_cng_dec.c
@@ -34,13 +34,12 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#include "ivas_rom_com_fx.h"
/*-------------------------------------------------------------------
@@ -586,7 +585,8 @@ static void stereo_dft_generate_comfort_noise_fx(
ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* q_dft */
ptr_i = ptr_r + 1;
- FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ )
+ Word16 len = shr( ( sub( s_min( output_frame, i_mult( hFdCngCom->regularStopBand, 16 ) ), hFdCngCom->stopFFTbin ) ), 1 );
+ FOR( i = 0; i < len; i++ )
{
/* Real part in FFT bins */
rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft );
@@ -623,7 +623,8 @@ static void stereo_dft_generate_comfort_noise_fx(
ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* q_dft */
ptr_i = ptr_r + 1;
- FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ )
+ tmp = shr( sub( s_min( output_frame, i_mult( hFdCngCom->regularStopBand, 16 ) ), hFdCngCom->stopFFTbin ), 1 );
+ FOR( i = 0; i < tmp; i++ )
{
( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); /* q_dft + q_shift */
move32();
@@ -1450,7 +1451,11 @@ void stereo_cna_update_params_fx(
{
IF( EQ_16( hCPE->nchan_out, 1 ) )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ c_LR_fx = MAX_32;
+#else /* OPT_STEREO_32KBPS_V1 */
c_LR_fx = MAX_WORD16;
+#endif /* OPT_STEREO_32KBPS_V1 */
move32();
c_ILD_fx = 0;
move32();
@@ -1512,8 +1517,12 @@ void stereo_cna_update_params_fx(
dotLR_fx = Mpy_32_32( W_extract_l( dotLR_fx ), energy_xy_fx ); /* dotLR_fx_q + ((31 - temp_res_q) - 31)) */
dotLR_fx_q = add( dotLR_fx_q, sub( sub( 31, temp_res_q ), 31 ) );
dotLR_fx = W_deposit32_l( L_shl_sat( W_extract_l( dotLR_fx ), sub( 31, dotLR_fx_q ) ) ); /* Q31 */
- /* estimate L/R correlation factor and ILD in time domain */
+ /* estimate L/R correlation factor and ILD in time domain */
+#ifdef OPT_STEREO_32KBPS_V1
+ c_LR_fx = W_extract_l( dotLR_fx ); /* Q31 */
+#else /* OPT_STEREO_32KBPS_V1 */
c_LR_fx = extract_h( W_extract_l( dotLR_fx ) ); /* Q15 */
+#endif /* OPT_STEREO_32KBPS_V1 */
temp_res_q = 0;
move16();
@@ -1552,15 +1561,24 @@ void stereo_cna_update_params_fx(
/* update of long-term ILD and LR correlation factors for stereo CNA */
IF( !hFdCngDec->first_cna_noise_updated )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ hFdCngDec->cna_LR_LT_fx = extract_h( c_LR_fx );
+#else /* OPT_STEREO_32KBPS_V1 */
hFdCngDec->cna_LR_LT_fx = extract_l( c_LR_fx );
+#endif /* OPT_STEREO_32KBPS_V1 */
move16();
hFdCngDec->cna_ILD_LT_fx = extract_l( c_ILD_fx );
move16();
}
ELSE
{
+#ifdef OPT_STEREO_32KBPS_V1
+ hFdCngDec->cna_LR_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_LR_CORR_LT_FILT_FX, hFdCngDec->cna_LR_LT_fx ),
+ Mpy_32_32( ONE_IN_Q31 - STEREO_CNA_LR_CORR_LT_FILT_FX, c_LR_fx ) ) ); /* Q31 */
+#else /* OPT_STEREO_32KBPS_V1 */
hFdCngDec->cna_LR_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_LR_CORR_LT_FILT_FX, hFdCngDec->cna_LR_LT_fx ),
Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), extract_l( c_LR_fx ) ) ) ); /* Q31 */
+#endif /* OPT_STEREO_32KBPS_V1 */
move16();
hFdCngDec->cna_ILD_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_ILD_LT_FILT_FX, hFdCngDec->cna_ILD_LT_fx ),
diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c
index 5449521d66e72b5ae91956d37aa0b926450c07ac..166ac72e57d4b4cef7d523005e1080ff744c7e47 100644
--- a/lib_dec/ivas_stereo_dft_dec.c
+++ b/lib_dec/ivas_stereo_dft_dec.c
@@ -37,7 +37,6 @@
#include "cnst.h"
#include "rom_com.h"
#include "rom_dec.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_cnst.h"
@@ -289,7 +288,7 @@ void stereo_dft_dec_analyze_fx(
move16();
/* Offset FOR the time buffers */
- assert( ( delay >= -NS2SA_FX2( ( input_frame * FRAMES_PER_SEC ), STEREO_DFT_DELAY_DEC_BWE_NS + STEREO_DFT_OVL_NS / 2 ) ) && ( delay <= NS2SA_FX2( ( input_frame * FRAMES_PER_SEC ), STEREO_DFT_OVL_NS ) ) );
+ assert( ( delay >= -NS2SA( input_frame * FRAMES_PER_SEC, STEREO_DFT_DELAY_DEC_BWE_NS + STEREO_DFT_OVL_NS / 2 ) ) && ( delay <= NS2SA( input_frame * FRAMES_PER_SEC, STEREO_DFT_OVL_NS ) ) );
mem_size = add( delay_dec, delay );
/* Update buffers */
diff --git a/lib_dec/ivas_stereo_dft_dec_dmx.c b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c
similarity index 99%
rename from lib_dec/ivas_stereo_dft_dec_dmx.c
rename to lib_dec/ivas_stereo_dft_dec_dmx_fx.c
index 99cea064bfb06d61b94e495cf7d0a9ac35d482bb..0781d49a679fc881a89f96bf325e49cd7d78d2de 100644
--- a/lib_dec/ivas_stereo_dft_dec_dmx.c
+++ b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c
@@ -35,7 +35,7 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
@@ -43,7 +43,6 @@
#include "rom_com.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
/*-------------------------------------------------------------------------
@@ -61,8 +60,8 @@ void stereo_dft_dmx_out_reset_fx(
hStereoDftDmx->prevTargetGain_fx = ONE_IN_Q29; /* Q29 */
move32();
- set32_fx( hStereoDftDmx->memOutHB_fx, 0, NS2SA_FX2( 48000, STEREO_DFT32MS_OVL_NS ) );
- set32_fx( hStereoDftDmx->memTransitionHB_fx, 0, NS2SA_FX2( 48000, STEREO_DFT32MS_OVL_NS ) );
+ set32_fx( hStereoDftDmx->memOutHB_fx, 0, NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) );
+ set32_fx( hStereoDftDmx->memTransitionHB_fx, 0, NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) );
return;
}
diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c
index b76bddbbced0311c235340efc37b5b2155fc51fd..8dcc7ada9fe358052eabf1f4f004b6d3ca846d23 100644
--- a/lib_dec/ivas_stereo_dft_dec_fx.c
+++ b/lib_dec/ivas_stereo_dft_dec_fx.c
@@ -37,7 +37,6 @@
#include "cnst.h"
#include "rom_com.h"
#include "rom_dec.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
@@ -99,7 +98,7 @@ void stereo_dft_dec_reset_fx(
Word16 i;
Word16 j, b;
#ifdef MSAN_FIX
- set_zero_fx( hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ) );
+ set_zero_fx( hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) );
#endif
/*Configuration*/
@@ -1360,7 +1359,7 @@ void stereo_dft_dec_res_fx(
set32_fx( hCPE->hStereoDft->res_cod_mem_fx, 0, STEREO_DFT_OVL_8k );
hCPE->hStereoDft->q_res_cod_mem_fx = Q16;
move16();
- set32_fx( hCPE->input_mem_fx[1], 0, NS2SA_FX2( 8000, STEREO_DFT32MS_OVL_NS ) );
+ set32_fx( hCPE->input_mem_fx[1], 0, NS2SA( 8000, STEREO_DFT32MS_OVL_NS ) );
set16_fx( hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, STEREO_DFT_NBPSF_PIT_MAX_8k );
hCPE->hStereoDft->hBpf->pst_mem_deemp_err_fx = 0;
move16();
@@ -1519,8 +1518,11 @@ void stereo_dft_dec_fx(
HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom;
Word16 *cna_seed = &( hFdCngCom->seed );
Word32 DFT_W, DFT_Y;
+#ifndef OPT_STEREO_32KBPS_V1
Word16 q_samp_ratio = Q15;
move16();
+#endif /* OPT_STEREO_32KBPS_V1 */
+ Word16 len;
output_frame = (Word16) Mpy_32_32( L_add( st0->output_Fs, FRAMES_PER_SEC_BY_2 ), ONE_BY_FRAMES_PER_SEC_Q31 ); /* Q0 */
@@ -1528,8 +1530,12 @@ void stereo_dft_dec_fx(
* Initialization
*-----------------------------------------------------------------*/
+#ifdef OPT_STEREO_32KBPS_V1
+ samp_ratio = divide3232( st0->sr_core, st0->output_Fs ); // Q15
+#else /* OPT_STEREO_32KBPS_V1 */
samp_ratio = (Word16) BASOP_Util_Divide3232_Scale( st0->sr_core, st0->output_Fs, &q_samp_ratio );
samp_ratio = shr( samp_ratio, sub( Q15 - Q12, q_samp_ratio ) );
+#endif /* OPT_STEREO_32KBPS_V1 */
stop = shr( STEREO_DFT32MS_N_32k, 1 );
@@ -1885,7 +1891,8 @@ void stereo_dft_dec_fx(
DFT_R[2 * i + 1] = L_sub( DFT_W, DFT_Y ); /* qDFT */
move32();
}
- FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ )
+ len = s_min( stop, hStereoDft->band_limits[b + 1] );
+ FOR( i = hStereoDft->band_limits[b]; i < len; i++ )
{
DFT_W = Madd_32_32( Mpy_32_32( hStereoDft->mixer_mat_smooth_fx[0][0][b + k * IVAS_MAX_NUM_BANDS], pDFT_DMX[2 * i] ),
L_add( hStereoDft->mixer_mat_smooth_fx[0][1][b + k * IVAS_MAX_NUM_BANDS],
@@ -1992,7 +1999,8 @@ void stereo_dft_dec_fx(
}
ELSE
{
- FOR( i = hStereoDft->band_limits[b]; i < min( stop, hStereoDft->band_limits[b + 1] ); i++ )
+ len = s_min( stop, hStereoDft->band_limits[b + 1] );
+ FOR( i = hStereoDft->band_limits[b]; i < len; i++ )
{
tmp = L_add( Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ), DFT_PRED_RES[2 * i] ); /* qDFT */
@@ -2102,10 +2110,17 @@ void stereo_dft_dec_fx(
/*Nyquist Freq.*/
IF( EQ_16( hStereoDft->band_limits[b], shr( hStereoDft->NFFT, 1 ) ) )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ DFT_L[1] = Madd_32_16( pDFT_DMX[1], pDFT_DMX[1], g ); /* qDFT */
+ move32();
+ DFT_R[1] = Msub_32_16( pDFT_DMX[1], pDFT_DMX[1], g ); /* qDFT */
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
DFT_L[1] = L_add( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); /* qDFT */
move32();
DFT_R[1] = L_sub( pDFT_DMX[1], Mpy_32_16_1( pDFT_DMX[1], g ) ); /* qDFT */
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
DFT_L[1] = Mpy_32_16_1( DFT_L[1], INV_SQRT2_FX_Q15 ); /* qDFT */
move32();
DFT_R[1] = Mpy_32_16_1( DFT_R[1], INV_SQRT2_FX_Q15 ); /* qDFT */
@@ -2206,8 +2221,8 @@ void stereo_dft_dec_fx(
gamma = 0;
move16();
}
-
- FOR( i = max( hFdCngDec->cna_band_limits[b], ( hFdCngCom->startBand / 2 ) ); i < min( hFdCngDec->cna_band_limits[b + 1], ( L_FRAME16k ) >> 1 ); i++ )
+ len = s_min( hFdCngDec->cna_band_limits[b + 1], ( L_FRAME16k ) >> 1 );
+ FOR( i = s_max( hFdCngDec->cna_band_limits[b], ( hFdCngCom->startBand >> 1 ) ); i < len; i++ ) // i < min( hFdCngDec->cna_band_limits[b + 1], ( L_FRAME16k ) >> 1 );
{
Word32 l_tmp;
lev1 = *ptr_per++;
@@ -2238,27 +2253,52 @@ void stereo_dft_dec_fx(
q_cna_level = sub( Q31, add( q_cna_level, Q16 ) );
/* generate comfort noise from gaussian noise and add to the decoded DFT spectrum */
+#ifdef OPT_STEREO_32KBPS_V1
+ Word16 shift = sub( q_cna_level, hStereoDft->q_dft );
+#endif /* OPT_STEREO_32KBPS_V1 */
N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */
N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */
- l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */
- l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */
- DFT_L[2 * i] = L_add( DFT_L[2 * i], l_tmp ); /* q_dft */
+#ifdef OPT_STEREO_32KBPS_V1
+ l_tmp = Madd_32_16( Madd_32_16( N1, N1, g ), N2, gamma ); /* q_cna_level */
+ l_tmp = L_shr( l_tmp, shift ); /* q_dft */
+#else /* OPT_STEREO_32KBPS_V1 */
+ l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */
+ l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */
+#endif /* OPT_STEREO_32KBPS_V1 */
+ DFT_L[2 * i] = L_add( DFT_L[2 * i], l_tmp ); /* q_dft */
move32();
+#ifdef OPT_STEREO_32KBPS_V1
+ l_tmp = Msub_32_16( Msub_32_16( N1, N1, g ), N2, gamma ); /* q_cna_level */
+ l_tmp = L_shr( l_tmp, shift ); /* q_dft */
+ DFT_R[2 * i] = L_add( DFT_R[2 * i], l_tmp ); /* q_dft */
+#else /* OPT_STEREO_32KBPS_V1 */
l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */
l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */
DFT_R[2 * i] = L_add( DFT_R[2 * i], l_tmp ); /* q_dft */
+#endif /* OPT_STEREO_32KBPS_V1 */
move32();
N1 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */
N2 = L_shl( Mpy_32_16_1( scale_fact, rand_gauss_fix( &ftmp, cna_seed ) ), Q2 ); /* q_cna_level */
- l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */
- l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */
- DFT_L[2 * i + 1] = L_add( DFT_L[2 * i + 1], l_tmp ); /* q_dft */
+#ifdef OPT_STEREO_32KBPS_V1
+ l_tmp = Madd_32_16( Madd_32_16( N1, N1, g ), N2, gamma ); /* q_cna_level */
+ l_tmp = L_shr( l_tmp, shift ); /* q_dft */
+ DFT_L[2 * i + 1] = L_add( DFT_L[2 * i + 1], l_tmp ); /* q_dft */
+ move32();
+ l_tmp = Msub_32_16( Msub_32_16( N1, N1, g ), N2, gamma ); /* q_cna_level */
+ l_tmp = L_shr( l_tmp, shift ); /* q_dft */
+ DFT_R[2 * i + 1] = L_add( DFT_R[2 * i + 1], l_tmp ); /* q_dft */
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
+ l_tmp = L_add( Madd_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */
+ l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */
+ DFT_L[2 * i + 1] = L_add( DFT_L[2 * i + 1], l_tmp ); /* q_dft */
move32();
l_tmp = L_sub( Msub_32_16( N1, N1, g ), Mpy_32_16_1( N2, gamma ) ); /* q_cna_level */
l_tmp = L_shr( l_tmp, sub( q_cna_level, hStereoDft->q_dft ) ); /* q_dft */
DFT_R[2 * i + 1] = L_add( DFT_R[2 * i + 1], l_tmp ); /* q_dft */
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
}
@@ -2346,8 +2386,12 @@ static void stereo_dft_compute_td_stefi_params_fx(
return;
}
+#ifdef OPT_STEREO_32KBPS_V1
+ bin0 = round_fx( L_mult0( hStereoDft->NFFT, samp_ratio ) );
+#else /* OPT_STEREO_32KBPS_V1 */
bin0 = extract_l( L_shr_r( Mpy_32_16_1( (Word32) hStereoDft->NFFT, samp_ratio ), 1 ) ); /* Q0 */
bin0 = shl( bin0, Q3 );
+#endif /* OPT_STEREO_32KBPS_V1 */
bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); /* Q0 */
b = hStereoDft->nbands; /* Q0 */
move16();
@@ -2512,14 +2556,18 @@ static void stereo_dft_dequantize_ipd_fx(
*-------------------------------------------------------------------------*/
void stereo_dft_generate_res_pred_fx(
STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */
- const Word16 samp_ratio, /* i : sampling ratio Q13*/
- Word32 *pDFT_DMX, /* i : downmix signal qDFT*/
- Word32 *DFT_PRED_RES, /* o : residual prediction signal qDFT*/
- Word32 *pPredGain, /* i : residual prediction gains Q31*/
- const Word16 k, /* i : subframe index Q0*/
- Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal qDFT*/
- Word16 *stop, /* o : last FD stereo filling bin Q0*/
- const Word16 bfi /* i : BFI flag Q0*/
+#ifdef OPT_STEREO_32KBPS_V1
+ const Word16 samp_ratio, /* i : sampling ratio Q15*/
+#else /* OPT_STEREO_32KBPS_V1 */
+ const Word16 samp_ratio, /* i : sampling ratio Q13*/
+#endif /* OPT_STEREO_32KBPS_V1 */
+ Word32 *pDFT_DMX, /* i : downmix signal qDFT*/
+ Word32 *DFT_PRED_RES, /* o : residual prediction signal qDFT*/
+ Word32 *pPredGain, /* i : residual prediction gains Q31*/
+ const Word16 k, /* i : subframe index Q0*/
+ Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal qDFT*/
+ Word16 *stop, /* o : last FD stereo filling bin Q0*/
+ const Word16 bfi /* i : BFI flag Q0*/
)
{
/* general variables */
@@ -2529,7 +2577,10 @@ void stereo_dft_generate_res_pred_fx(
Word16 lb_stefi_start_band;
/* variables for enhanced stereo filling */
- Word16 norm_fac, q_norm_fac, lim_norm_fac;
+ Word16 norm_fac, q_norm_fac;
+#ifndef OPT_STEREO_32KBPS_V1
+ Word16 lim_norm_fac;
+#endif /* OPT_STEREO_32KBPS_V1 */
Word16 q_sqrt;
Word16 alpha; // gain_limit;
@@ -2543,8 +2594,13 @@ void stereo_dft_generate_res_pred_fx(
Word32 pred_gain_avg;
Word32 g2;
Word16 nbands_respred;
+#ifdef OPT_STEREO_32KBPS_V1
+ Word16 q_new, diff;
+#else /* OPT_STEREO_32KBPS_V1 */
q_norm_fac = 0;
move16();
+#endif /* OPT_STEREO_32KBPS_V1 */
+ Word16 len;
push_wmops( "gen_respred" );
/* smoothing and limiting parameters */
@@ -2566,8 +2622,12 @@ void stereo_dft_generate_res_pred_fx(
/* In ACELP mode the downmix signal is not available in bandwidth extension area. *
* Therefore, the downmix energy in the corresponding subbands is estimated. */
+#ifdef OPT_STEREO_32KBPS_V1
+ bin0 = round_fx( L_mult0( hStereoDft->NFFT, samp_ratio ) );
+#else /* OPT_STEREO_32KBPS_V1 */
bin0 = (Word16) ( L_shr( L_add( L_mult0( hStereoDft->NFFT, samp_ratio ), ONE_IN_Q12 ), Q12 + 1 ) ); /* Q0 */
move16();
+#endif /* OPT_STEREO_32KBPS_V1 */
bin0 = s_min( bin0, hStereoDft->band_limits[hStereoDft->nbands] ); /* Q0 */
b = hStereoDft->nbands;
move16();
@@ -2609,39 +2669,81 @@ void stereo_dft_generate_res_pred_fx(
move64();
/* calculate band energies (low band only in case of ACELP) */
- FOR( i = hStereoDft->band_limits[b]; i < min( hStereoDft->band_limits[b + 1], bin0 ); i++ )
+ len = s_min( hStereoDft->band_limits[b + 1], bin0 );
+ FOR( i = hStereoDft->band_limits[b]; i < len; i++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ dmx_nrg_64bit = W_mac_32_32( W_mac_32_32( dmx_nrg_64bit, pDFT_DMX[2 * i], pDFT_DMX[2 * i] ),
+ pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ); /* 2 * q_dft + 1 */
+ rev_nrg_64bit = W_mac_32_32( W_mac_32_32( rev_nrg_64bit, ap_filt_DMX[2 * i], ap_filt_DMX[2 * i] ),
+ ap_filt_DMX[2 * i + 1], ap_filt_DMX[2 * i + 1] ); /* 2 * q_dft + 1 */
+#else /* OPT_STEREO_32KBPS_V1 */
dmx_nrg_64bit = W_add( dmx_nrg_64bit,
W_add( W_mult0_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ),
W_mult0_32_32( pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ) ) ); /* 2 * q_dft */
rev_nrg_64bit = W_add( rev_nrg_64bit,
W_add( W_mult0_32_32( ap_filt_DMX[2 * i], ap_filt_DMX[2 * i] ),
W_mult0_32_32( ap_filt_DMX[2 * i + 1], ap_filt_DMX[2 * i + 1] ) ) ); /* 2 * q_dft */
+#endif /* OPT_STEREO_32KBPS_V1 */
}
+
+#ifdef OPT_STEREO_32KBPS_V1
+ q_new = add( shl( hStereoDft->q_dft, 1 ), 1 );
+ q_shift = W_norm( dmx_nrg_64bit );
+ dmx_nrg = W_shl_sat_l( dmx_nrg_64bit, sub( q_shift, 32 ) ); // 2 * hStereoDft->q_dft + 1 - (q_shift - 32)
+ dmx_nrg_q = add( q_new, sub( q_shift, 32 ) );
+ q_shift = W_norm( rev_nrg_64bit );
+ rev_nrg = W_shl_sat_l( rev_nrg_64bit, sub( q_shift, 32 ) ); // 2 * hStereoDft->q_dft + 1 - (q_shift - 32)
+ rev_nrg_q = add( q_new, sub( q_shift, 32 ) );
+ move16();
+#else /* OPT_STEREO_32KBPS_V1 */
q_shift = W_norm( dmx_nrg_64bit );
dmx_nrg = W_extract_l( W_shl( dmx_nrg_64bit, sub( q_shift, 32 ) ) ); // 2 * hStereoDft->q_dft + (q_shift - 32)
dmx_nrg_q = add( imult1616( 2, hStereoDft->q_dft ), sub( q_shift, 32 ) );
q_shift = W_norm( rev_nrg_64bit );
rev_nrg = W_extract_l( W_shl( rev_nrg_64bit, sub( q_shift, 32 ) ) ); // 2 * hStereoDft->q_dft + (q_shift - 32)
rev_nrg_q = add( imult1616( 2, hStereoDft->q_dft ), sub( q_shift, 32 ) );
+#endif /* OPT_STEREO_32KBPS_V1 */
/* Reach a common Q for dmx_nrg and rev_nrg */
q_com = s_min( dmx_nrg_q, rev_nrg_q );
dmx_nrg = L_shl( dmx_nrg, sub( q_com, dmx_nrg_q ) ); /* q_com */
rev_nrg = L_shl( rev_nrg, sub( q_com, rev_nrg_q ) ); /* q_com */
+
+#ifdef OPT_STEREO_32KBPS_V1
+ diff = sub( hStereoDft->q_smoothed_nrg, q_com );
+ IF( diff < 0 )
+#else /* OPT_STEREO_32KBPS_V1 */
IF( LT_16( hStereoDft->q_smoothed_nrg, q_com ) )
+#endif /* OPT_STEREO_32KBPS_V1 */
{
+#ifdef OPT_STEREO_32KBPS_V1
+ rev_nrg = L_shl( rev_nrg, shl( diff, 1 ) );
+ dmx_nrg = L_shl( dmx_nrg, shl( diff, 1 ) );
+#else /* OPT_STEREO_32KBPS_V1 */
rev_nrg = L_shr( rev_nrg, shl( sub( q_com, hStereoDft->q_smoothed_nrg ), 1 ) );
dmx_nrg = L_shr( dmx_nrg, shl( sub( q_com, hStereoDft->q_smoothed_nrg ), 1 ) );
+#endif /* OPT_STEREO_32KBPS_V1 */
q_com = hStereoDft->q_smoothed_nrg;
move16();
}
+#ifdef OPT_STEREO_32KBPS_V1
+ ELSE
+#else /* OPT_STEREO_32KBPS_V1 */
ELSE IF( GT_16( hStereoDft->q_smoothed_nrg, q_com ) )
+#endif /* OPT_STEREO_32KBPS_V1 */
{
+#ifdef OPT_STEREO_32KBPS_V1
+ hStereoDft->smooth_res_nrg_fx[b] = L_shr( hStereoDft->smooth_res_nrg_fx[b], shl( diff, 1 ) ); /* hStereoDft->q_smoothed_nrg */
+ move32();
+ hStereoDft->smooth_dmx_nrg_fx[b] = L_shr( hStereoDft->smooth_dmx_nrg_fx[b], shl( diff, 1 ) ); /* hStereoDft->q_smoothed_nrg */
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
hStereoDft->smooth_res_nrg_fx[b] = L_shr( hStereoDft->smooth_res_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); /* hStereoDft->q_smoothed_nrg */
move32();
hStereoDft->smooth_dmx_nrg_fx[b] = L_shr( hStereoDft->smooth_dmx_nrg_fx[b], shl( sub( hStereoDft->q_smoothed_nrg, q_com ), 1 ) ); /* hStereoDft->q_smoothed_nrg */
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
q_smoothed_nrg_local[b] = q_com;
move16();
}
@@ -2651,9 +2753,38 @@ void stereo_dft_generate_res_pred_fx(
hStereoDft->smooth_dmx_nrg_fx[b] = Madd_32_16( Mpy_32_16_1( hStereoDft->smooth_dmx_nrg_fx[b], alpha ), dmx_nrg, sub( (Word16) ( 0x7FFF ), alpha ) ); /* hStereoDft->q_smoothed_nrg */
move32();
+#ifdef OPT_STEREO_32KBPS_V1
+ // Compute norm_fac in Q14
+ norm_fac = MAX_16;
+ move16();
+#endif /* OPT_STEREO_32KBPS_V1 */
/* normalization factor */
IF( hStereoDft->smooth_res_nrg_fx[b] != 0 )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ norm_fac = 0;
+ move16();
+ IF( hStereoDft->smooth_dmx_nrg_fx[b] != 0 )
+ {
+ Word16 quo, quo_e;
+ Word32 prod;
+
+ norm_fac = BASOP_Util_Divide3232_Scale( hStereoDft->smooth_dmx_nrg_fx[b], hStereoDft->smooth_res_nrg_fx[b], &q_norm_fac ); /* q_norm_fac */
+ norm_fac = Sqrt16( norm_fac, &q_norm_fac );
+
+ quo = BASOP_Util_Divide1616_Scale( 32767, norm_fac, &quo_e ); /* q_norm_fac */
+ quo_e = sub( quo_e, q_norm_fac );
+ quo = shl_sat( quo, sub( quo_e, 1 ) ); // Q14
+ quo = s_max( 13107 /*0.8 in Q14 */, quo );
+ quo = s_min( quo, 20480 /* 1.25 in Q14*/ );
+
+ prod = L_mult( norm_fac, quo ); // exp:q_norm_fac+1
+ // Bring to Q30
+ prod = L_shl_sat( prod, q_norm_fac );
+
+ norm_fac = extract_h( prod );
+ }
+#else /* OPT_STEREO_32KBPS_V1 */
norm_fac = BASOP_Util_Divide3232_Scale( hStereoDft->smooth_dmx_nrg_fx[b], hStereoDft->smooth_res_nrg_fx[b], &q_norm_fac ); /* q_norm_fac */
norm_fac = Sqrt16( norm_fac, &q_norm_fac );
IF( norm_fac != 0 )
@@ -2709,7 +2840,9 @@ void stereo_dft_generate_res_pred_fx(
}
}
}
+#endif /* OPT_STEREO_32KBPS_V1 */
}
+#ifndef OPT_STEREO_32KBPS_V1
ELSE
{
norm_fac = MAX_16;
@@ -2717,13 +2850,22 @@ void stereo_dft_generate_res_pred_fx(
q_norm_fac = Q1;
move16();
}
+#endif /* OPT_STEREO_32KBPS_V1 */
- FOR( i = hStereoDft->band_limits[b]; i < min( hStereoDft->band_limits[b + 1], bin0 ); i++ )
+ len = s_min( hStereoDft->band_limits[b + 1], bin0 );
+ FOR( i = hStereoDft->band_limits[b]; i < len; i++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i] ), 1 ); /* q_dft */
+ move32();
+ DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i + 1] ), 1 ); /* q_dft */
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i] ), q_norm_fac ); /* q_dft */
move32();
DFT_PRED_RES[2 * i + 1] = L_shl( Mpy_32_32( Mpy_32_16_1( pPredGain[b], norm_fac ), ap_filt_DMX[2 * i + 1] ), q_norm_fac ); /* q_dft */
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
}
@@ -2833,7 +2975,8 @@ void stereo_dft_generate_res_pred_fx(
move32();
dmx_nrg = EPSILON_FIX;
move32();
- FOR( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ )
+ len = s_min( bin0, hStereoDft->band_limits[b + 1] );
+ FOR( i = hStereoDft->band_limits[b]; i < len; i++ )
{
dmx_nrg = Madd_32_32( Madd_32_32( dmx_nrg, pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ); /* 2 * q_dft - 31 */
@@ -2874,8 +3017,8 @@ void stereo_dft_generate_res_pred_fx(
q_sqrt = 0;
move16();
}
-
- FOR( i = hStereoDft->band_limits[b]; i < min( bin0, hStereoDft->band_limits[b + 1] ); i++ )
+ len = s_min( bin0, hStereoDft->band_limits[b + 1] );
+ FOR( i = hStereoDft->band_limits[b]; i < len; i++ )
{
DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, DFT_PRED_RES[2 * i] ), q_sqrt ); /* q_dft */
move32();
@@ -2932,7 +3075,8 @@ void stereo_dft_generate_res_pred_fx(
// past_dmx_nrg = EPSILON_FIX;
past_dmx_nrg = 0;
move32();
- FOR( i = bin0; i < min( ( hStereoDft->NFFT / 2 ), ( STEREO_DFT32MS_N_32k / 2 ) ); i++ )
+ len = s_min( shr( hStereoDft->NFFT, 1 ), ( STEREO_DFT32MS_N_32k >> 1 ) );
+ FOR( i = bin0; i < len; i++ ) // i < min( ( hStereoDft->NFFT / 2 ), ( hStereoDft->NFFT / 2 ) )
{
past_dmx_nrg = L_add( past_dmx_nrg, Madd_32_32( Mpy_32_32( hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1], hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] ) ); /* 2 * hStereoDft->q_DFT_past_DMX_fx[d_short_ind] - 31 */
}
@@ -2993,7 +3137,8 @@ void stereo_dft_generate_res_pred_fx(
}
q_shift = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind] );
move16();
- FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ )
+ len = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k >> 1 );
+ FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < len; i++ ) // i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 )
{
DFT_PRED_RES[2 * i] = L_shl( Mpy_32_32( g2, hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] ), q_shift ); /* q_dft */
move32();
@@ -3107,7 +3252,8 @@ void stereo_dft_generate_res_pred_fx(
move32();
dmx_nrg = EPSILON_FIX;
move32();
- FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ )
+ len = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k >> 1 );
+ FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < len; i++ ) // i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 )
{
dmx_nrg = L_add( dmx_nrg, L_shr( Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ), 1 ) ); /* 2 * q_dft - 31 - 1 */
@@ -3133,8 +3279,8 @@ void stereo_dft_generate_res_pred_fx(
g2 = L_min( Mpy_32_16_1( pred_gain_avg, STEREO_DFT_STEFFI_GAIN_AMP_FX ),
Madd_32_16( Mpy_32_16_1( pred_gain_avg, sub( (Word16) ( 0x7FFF ), STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ), g2, STEREO_DFT_STEFFI_GAIN_REST_AMT_FX ) ); /* Q31 */
-
- FOR( i = max( hStereoDft->band_limits[b], bin0 ); i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 ); i++ )
+ len = s_min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k >> 1 );
+ FOR( i = s_max( hStereoDft->band_limits[b], bin0 ); i < len; i++ ) // i < min( hStereoDft->band_limits[b + 1], STEREO_DFT32MS_N_32k / 2 )
{
DFT_PRED_RES[2 * i] = Mpy_32_32( g2, DFT_PRED_RES[2 * i] ); /* Q31 */
move32();
diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c
index 9e6878fafbc6e4b2293ea11973aa6d255cb3f744..d3415a8eb6cb987b7bf3f1ff8a0c4f5a98ddc625 100644
--- a/lib_dec/ivas_stereo_dft_plc_fx.c
+++ b/lib_dec/ivas_stereo_dft_plc_fx.c
@@ -33,7 +33,6 @@
#include
#include "options.h"
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
diff --git a/lib_dec/ivas_stereo_eclvq_dec.c b/lib_dec/ivas_stereo_eclvq_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_stereo_eclvq_dec.c
rename to lib_dec/ivas_stereo_eclvq_dec_fx.c
index ed26543d302137a13ebbe105e22a08abf1852f6e..693df8c77c430cdcf5e6e29ac61a4cc627a1887b 100644
--- a/lib_dec/ivas_stereo_eclvq_dec.c
+++ b/lib_dec/ivas_stereo_eclvq_dec_fx.c
@@ -37,7 +37,7 @@
#include "ivas_rom_com.h"
#include "ivas_rom_dec.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_stereo_esf_dec.c b/lib_dec/ivas_stereo_esf_dec_fx.c
similarity index 100%
rename from lib_dec/ivas_stereo_esf_dec.c
rename to lib_dec/ivas_stereo_esf_dec_fx.c
diff --git a/lib_dec/ivas_stereo_ica_dec.c b/lib_dec/ivas_stereo_ica_dec_fx.c
similarity index 97%
rename from lib_dec/ivas_stereo_ica_dec.c
rename to lib_dec/ivas_stereo_ica_dec_fx.c
index b72e66c5f1f0c4e3157bb801c20ce46ca568766b..b49ab53995a87adedca6677c9d331c9a05ce2f29 100644
--- a/lib_dec/ivas_stereo_ica_dec.c
+++ b/lib_dec/ivas_stereo_ica_dec_fx.c
@@ -36,12 +36,11 @@
#include
#include "cnst.h"
#include "ivas_cnst.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "wmc_auto.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "basop32.h"
#include "ivas_stat_dec.h"
@@ -126,7 +125,7 @@ void stereo_tca_dec_fx(
dsFactor = BASOP_Util_Divide3232_Scale( output_Fs, 8000, &exp_ds );
dsFactor = shr( dsFactor, sub( 15, exp_ds ) ); /* Q0 */
- tempMax = NS2SA( output_Fs, L_NCSHIFT_NS ); /* Q0 */
+ tempMax = NS2SA_FX2( output_Fs, L_NCSHIFT_NS ); /* Q0 */
hStereoTCA->corrLagStats = s_min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); /* Q0 */
bothChannelShift = 0;
@@ -343,14 +342,14 @@ void stereo_tca_scale_R_channel_fx(
return;
}
/* Scale the Right channel with the gain */
- l_ica_ovl = NS2SA( output_Fs, STEREO_L_TCA_OVLP_NS ); /* Q0 */
+ l_ica_ovl = NS2SA_FX2( output_Fs, STEREO_L_TCA_OVLP_NS ); /* Q0 */
move16();
test();
IF( EQ_16( hCPE->nchan_out, 1 ) )
{
/* in mono DMX, the scaling is done before synchro_synthesis() */
- flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); /* Q0 */
+ flat_old = NS2SA_FX2( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); /* Q0 */
move16();
test();
@@ -365,18 +364,18 @@ void stereo_tca_scale_R_channel_fx(
hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */
move32();
- flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */
+ flat_old = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */
move16();
}
}
ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
{
- flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */
+ flat_old = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */
move16();
}
ELSE
{
- flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS ); /* Q0 */
+ flat_old = NS2SA_FX2( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS ); /* Q0 */
move16();
}
diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec_fx.c
similarity index 98%
rename from lib_dec/ivas_stereo_icbwe_dec.c
rename to lib_dec/ivas_stereo_icbwe_dec_fx.c
index 6bba90febafbce125220d3e69422646f39429283..22a8c4a900d6795e88996d08a1821f5c49d2375e 100644
--- a/lib_dec/ivas_stereo_icbwe_dec.c
+++ b/lib_dec/ivas_stereo_icbwe_dec_fx.c
@@ -36,7 +36,6 @@
#include
#include "cnst.h"
#include "ivas_cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
@@ -339,7 +338,7 @@ void stereo_icBWE_dec_fx(
move32();
alpha_fx = add_sat( alpha_fx, winSlope_fx ); /* Q15 */
}
- FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ )
+ FOR( ; i < NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS ); i++ )
{
synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); // Qsyth - 1
move32();
@@ -766,7 +765,7 @@ void stereo_icBWE_dec_fx(
alpha_fx = add( alpha_fx, winSlope_fx ); /* Q15 */
}
}
- FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ )
+ FOR( ; i < NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS ); i++ )
{
synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); /* Qsyn - 1 */
move32();
@@ -933,7 +932,7 @@ void stereo_icBWE_dec_fx(
}
}
- FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ )
+ FOR( ; i < NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS ); i++ )
{
synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); /* Qsyn - 1 */
move32();
@@ -1015,7 +1014,7 @@ void stereo_icBWE_decproc_fx(
output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */
move32();
- memOffset = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); /* Q0 */
+ memOffset = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); /* Q0 */
/* LRTD stereo mode - 2xBWEs used */
test();
@@ -1070,8 +1069,8 @@ void stereo_icBWE_decproc_fx(
set32_fx( hStereoICBWE->memOutHB_fx[0], 0, memOffset );
set32_fx( hStereoICBWE->memOutHB_fx[1], 0, memOffset );
- set32_fx( hStereoICBWE->memTransitionHB_fx[0], 0, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) );
- set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) );
+ set32_fx( hStereoICBWE->memTransitionHB_fx[0], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
+ set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
}
test();
@@ -1123,13 +1122,13 @@ void stereo_icBWE_decproc_fx(
Copy32( outputHB[refChanIndx_bwe], temp0_fx + memOffset, sub( output_frame, memOffset ) ); /* Q11 */
Copy32( outputHB[!refChanIndx_bwe], temp1_fx + memOffset, sub( output_frame, memOffset ) ); /* Q11 */
- decoderDelay = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */
+ decoderDelay = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */
test();
IF( last_core != ACELP_CORE && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
{
/* hb_synth of mid band is faded out in the 1.25 ms prior to DFT analysis and the icbwe is faded in time domain */
- icbweOLASize = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); /* Q0 */
+ icbweOLASize = NS2SA_FX2( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); /* Q0 */
FOR( i = 0; i < decoderDelay; i++ )
{
@@ -1286,15 +1285,15 @@ void stereo_icBWE_decproc_fx(
ELSE
{
/* This is generated in the ACELP frame and windowed. This process is akin to GenTransition for IC-BWE */
- v_add_32( output[0], hStereoICBWE->memTransitionHB_fx[hStereoICBWE->prev_refChanIndx_bwe], output[0], NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) );
- v_add_32( output[1], hStereoICBWE->memTransitionHB_fx[!hStereoICBWE->prev_refChanIndx_bwe], output[1], NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) );
+ v_add_32( output[0], hStereoICBWE->memTransitionHB_fx[hStereoICBWE->prev_refChanIndx_bwe], output[0], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
+ v_add_32( output[1], hStereoICBWE->memTransitionHB_fx[!hStereoICBWE->prev_refChanIndx_bwe], output[1], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
}
set32_fx( hStereoICBWE->memOutHB_fx[0], 0, memOffset );
set32_fx( hStereoICBWE->memOutHB_fx[1], 0, memOffset );
- set32_fx( hStereoICBWE->memTransitionHB_fx[0], 0, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) );
- set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) );
+ set32_fx( hStereoICBWE->memTransitionHB_fx[0], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
+ set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
}
}
}
@@ -1304,13 +1303,13 @@ void stereo_icBWE_decproc_fx(
}
ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( last_core, ACELP_CORE ) )
{
- Word16 delay_tdbwe = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS );
+ Word16 delay_tdbwe = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS );
FOR( n = 0; n < hCPE->nchan_out; n++ )
{
FOR( i = 0; i < delay_tdbwe; i++ )
{
- output[n][NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i] = L_add_sat( output[n][NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i], outputHB[0][i] );
+ output[n][NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i] = L_add_sat( output[n][NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i], outputHB[0][i] );
move32();
}
}
diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c
index bf343da7f3982ab8f05bbfbc87ab90dcbbb873c6..04781a9cb9c426afba7c4897659d22294d958917 100644
--- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c
+++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c
@@ -34,13 +34,12 @@
#include
#include "options.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "cnst.h"
#include "stat_com.h"
#include "ivas_prot.h"
#include "ivas_stat_dec.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_stereo_mdct_stereo_dec.c
rename to lib_dec/ivas_stereo_mdct_stereo_dec_fx.c
index 4a788be836fe8623e2d51c64f703ce4fb42e9897..69083a078be3d4e91ba75bfb642bf426bcc73753 100644
--- a/lib_dec/ivas_stereo_mdct_stereo_dec.c
+++ b/lib_dec/ivas_stereo_mdct_stereo_dec_fx.c
@@ -36,10 +36,9 @@
#include "options.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
@@ -947,7 +946,7 @@ void applyDmxMdctStereo_fx(
test();
IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) )
{
- crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS );
+ crossfade_len = NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS );
move16();
SWITCH( hCPE->hCoreCoder[0]->output_Fs )
{
@@ -994,7 +993,7 @@ void applyDmxMdctStereo_fx(
}
ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && LE_32( hCPE->last_element_brate, IVAS_32k ) )
{
- crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, DELAY_CLDFB_NS ); /* Q0 */
+ crossfade_len = NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, DELAY_CLDFB_NS ); /* Q0 */
move16();
SWITCH( hCPE->hCoreCoder[0]->output_Fs )
{
diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec_fx.c
similarity index 97%
rename from lib_dec/ivas_stereo_switching_dec.c
rename to lib_dec/ivas_stereo_switching_dec_fx.c
index a8b74c4478248026c7a8e44ea8b31469d563eac3..2dd2a30c37c684a39a9b83b680c498ca7f84d476 100644
--- a/lib_dec/ivas_stereo_switching_dec.c
+++ b/lib_dec/ivas_stereo_switching_dec_fx.c
@@ -34,7 +34,7 @@
#include "options.h"
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com.h"
@@ -42,7 +42,6 @@
#include "wmc_auto.h"
#include
#include "ivas_prot_fx.h"
-#include "prot_fx.h"
#include "ivas_rom_com_fx.h"
/*-------------------------------------------------------------------*
@@ -415,7 +414,7 @@ ivas_error stereo_memory_dec_fx(
IF( hCPE->hCoreCoder[0]->last_core != ACELP_CORE )
{
- Copy32( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /* Q11 */
+ Copy32( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA_FX2( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /* Q11 */
}
}
@@ -470,7 +469,7 @@ ivas_error stereo_memory_dec_fx(
}
/* memory update - needed in TD stereo, TCX/HQ frame -> DFT stereo, ACELP frame switching */
- Copy32( hCPE->input_mem_LB_fx[0], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( s_min( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), 16000 ), STEREO_DFT32MS_OVL_NS ) ); /* Q11 */
+ Copy32( hCPE->input_mem_LB_fx[0], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( s_min( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), 16000 ), STEREO_DFT32MS_OVL_NS ) ); /* Q11 */
/* allocate ICBWE structure */
IF( hCPE->hStereoICBWE == NULL )
@@ -1034,11 +1033,11 @@ ivas_error stereo_memory_dec_fx(
IF( hCPE->prev_synth_chs_fx[1] == NULL )
{
st = hCPE->hCoreCoder[1];
- IF( ( hCPE->prev_synth_chs_fx[1] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA( st->output_Fs, FRAME_SIZE_NS ) ) ) == NULL )
+ IF( ( hCPE->prev_synth_chs_fx[1] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
}
- set32_fx( hCPE->prev_synth_chs_fx[1], 0, NS2SA( st->output_Fs, FRAME_SIZE_NS ) );
+ set32_fx( hCPE->prev_synth_chs_fx[1], 0, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS ) );
}
IF( hCPE->hStereoICBWE == NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
@@ -2143,7 +2142,7 @@ void stereo_td2dft_update_fx(
/* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */
IF( sts[n]->hTcxDec != NULL )
{
- ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); /* Q0 */
+ ovl_TCX = NS2SA_FX2( L_mult0( sts[n]->hTcxDec->L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /* Q0 */
move16();
Copy32( synth_fx + sts[n]->hTcxDec->L_frameTCX + hq_delay_comp - ovl_TCX, hCPE->input_mem_fx[n], sub( ovl_TCX, hq_delay_comp ) ); /* Q11 */
Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + ovl_TCX - hq_delay_comp, hq_delay_comp ); /* Q11 */
@@ -2161,7 +2160,7 @@ void stereo_td2dft_update_fx(
/* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */
IF( sts[n]->hTcxDec != NULL )
{
- ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); /* Q0 */
+ ovl_TCX = NS2SA_FX2( L_mult0( sts[n]->hTcxDec->L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /* Q0 */
move16();
Copy32( synth_fx + add( sts[n]->hTcxDec->L_frameTCX, sub( hq_delay_comp, ovl_TCX ) ), hCPE->input_mem_fx[n], sub( ovl_TCX, hq_delay_comp ) ); /* Q11 */
Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + sub( ovl_TCX, hq_delay_comp ), hq_delay_comp ); /* Q11 */
@@ -2343,15 +2342,20 @@ static Word32 ncross_corr_self_fx(
{
Word64 c_c_fx;
Word32 c_c_fx_return;
+ Word64 energy_x_fx, energy_y_fx;
+#ifndef OPT_STEREO_32KBPS_V1
Word16 c_c_fx_q;
- Word64 energy_xy_fx, energy_x_fx, energy_y_fx;
+ Word64 energy_xy_fx;
+#endif /* OPT_STEREO_32KBPS_V1 */
UWord16 j;
Word32 *signal_a_fx, *signal_b_fx;
Word32 temp_x, temp_y;
Word16 headroom_left_x, headroom_left_y;
+#ifndef OPT_STEREO_32KBPS_V1
Word16 x_inv_q, y_inv_q;
Word16 x_q, y_q;
Word16 res_q;
+#endif /* OPT_STEREO_32KBPS_V1 */
c_c_fx = 0;
move64();
energy_x_fx = 0;
@@ -2362,13 +2366,43 @@ static Word32 ncross_corr_self_fx(
signal_b_fx = &signal_fx[y]; /* Q11 */
FOR( j = 0; j < corr_len; j += subsampling )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ c_c_fx = W_mac_32_32( c_c_fx, signal_a_fx[j], signal_b_fx[j] ); /* 2 * Q11 + 1*/
+ energy_x_fx = W_mac_32_32( energy_x_fx, signal_a_fx[j], signal_a_fx[j] ); /* 2 * Q11+ 1 */
+ energy_y_fx = W_mac_32_32( energy_y_fx, signal_b_fx[j], signal_b_fx[j] ); /* 2 * Q11+ 1 */
+#else /* OPT_STEREO_32KBPS_V1 */
c_c_fx = W_add( c_c_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_b_fx[j] ) ) ); /* 2 * Q11 */
energy_x_fx = W_add( energy_x_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_a_fx[j] ) ) ); /* 2 * Q11 */
energy_y_fx = W_add( energy_y_fx, W_mult0_32_32( ( signal_b_fx[j] ), ( signal_b_fx[j] ) ) ); /* 2 * Q11 */
+#endif /* OPT_STEREO_32KBPS_V1 */
}
headroom_left_x = W_norm( energy_x_fx );
headroom_left_y = W_norm( energy_y_fx );
+#ifdef OPT_STEREO_32KBPS_V1
+ temp_x = W_extract_h( W_shl( energy_x_fx, headroom_left_x ) ); // Q23 + headroom_left_x -32
+ temp_y = W_extract_h( W_shl( energy_y_fx, headroom_left_y ) ); // Q23 + headroom_left_y -32
+ Word64 prod = W_mult0_32_32( temp_x, temp_y ); // Q(headroom_left_x + headroom_left_y - 18)
+ Word16 q_prod = W_norm( prod );
+ Word32 energy = W_extract_h( W_shl( prod, q_prod ) ); // Q(headroom_left_x + headroom_left_y + q_prod - 18) - 32
+ q_prod = sub( 81, add( add( headroom_left_x, headroom_left_y ), q_prod ) );
+ energy = Sqrt32( energy, &q_prod );
+
+ IF( LT_32( energy, L_shl_sat( 1, sub( 31, q_prod ) ) ) )
+ {
+ c_c_fx_return = W_shl_sat_l( c_c_fx, 31 - ( 2 * OUTPUT_Q + 1 ) ); // Q31
+ }
+ ELSE
+ {
+ // Maximize c_c_fx
+ Word16 q_cc = W_norm( c_c_fx );
+ Word32 num = W_extract_h( W_shl( c_c_fx, q_cc ) ); // Q(23 + q_cc - 32) -> e(40 - q_cc)
+ Word16 quo_e;
+ num = BASOP_Util_Divide3232_Scale_cadence( num, energy, &quo_e );
+ quo_e = add( sub( sub( 40, q_cc ), q_prod ), quo_e );
+ c_c_fx_return = L_shl_sat( num, quo_e ); // Q31
+ }
+#else /* OPT_STEREO_32KBPS_V1 */
IF( LT_16( headroom_left_x, 32 ) )
{
energy_x_fx = W_shr( energy_x_fx, sub( 32, headroom_left_x ) ); /* 2 * Q11 - (32 -headroom_left_x) */
@@ -2440,6 +2474,7 @@ static Word32 ncross_corr_self_fx(
c_c_fx_return = W_extract_l( c_c_fx ); /* Q31 */
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
return c_c_fx_return;
}
diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec_fx.c
similarity index 96%
rename from lib_dec/ivas_stereo_td_dec.c
rename to lib_dec/ivas_stereo_td_dec_fx.c
index d296e3f3303f9d604be289b9b99d1fbc83f2ab6c..8ab7da0355c4a237b0f41257571b7a4573e3f94b 100644
--- a/lib_dec/ivas_stereo_td_dec.c
+++ b/lib_dec/ivas_stereo_td_dec_fx.c
@@ -35,7 +35,6 @@
#include
#include "cnst.h"
#include "rom_com.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_rom_com.h"
@@ -384,7 +383,7 @@ void tdm_upmix_plain_fx(
const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/
const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/
const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/
- const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/
+ const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q30*/
const Word16 start_index, /* i : start index Q0*/
const Word16 end_index, /* i : end index Q0*/
const Word16 plus_minus_flag /* i : plus/minus flag Q0*/
@@ -396,16 +395,37 @@ void tdm_upmix_plain_fx(
{
FOR( i = start_index; i < end_index; i++ )
{
+#ifdef OPT_STEREO_32KBPS_V1
+ Word32 temp_left = Madd_32_32( SCh_2_R_fx[i], L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ); /* Qx */
+ Left_fx[i] = W_shl_sat_l( W_mult0_32_32( temp_left, inv_den_LR_ratio_fx ), -30 ); /* Qx */
+ move32();
+ Word32 temp_right = Msub_32_32( PCh_2_L_fx[i], L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ); /* Qx */
+ Right_fx[i] = W_shl_sat_l( W_mult0_32_32( temp_right, inv_den_LR_ratio_fx ), -30 ); /* Qx */
+ move32();
+#else /* OPT_STEREO_32KBPS_V1 */
Word32 temp_left = L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ); /* Qx */
Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */
move32();
Word32 temp_right = L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ); /* Qx */
Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */
move32();
+#endif /* OPT_STEREO_32KBPS_V1 */
}
}
ELSE
{
+#ifdef OPT_STEREO_32KBPS_V1
+ Word32 inv_den_LR_ratio_fx_neg = L_negate( inv_den_LR_ratio_fx );
+ FOR( i = start_index; i < end_index; i++ )
+ {
+ Word32 temp_left = Msub_32_32( SCh_2_R_fx[i], L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ); /* Qx */
+ Left_fx[i] = W_shl_sat_l( W_mult0_32_32( temp_left, inv_den_LR_ratio_fx_neg ), -30 ); /* Qx */
+ move32();
+ Word32 temp_right = Msub_32_32( PCh_2_L_fx[i], L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ); /* Qx */
+ Right_fx[i] = W_shl_sat_l( W_mult0_32_32( temp_right, inv_den_LR_ratio_fx_neg ), -30 ); /* Qx */
+ move32();
+ }
+#else /* OPT_STEREO_32KBPS_V1 */
FOR( i = start_index; i < end_index; i++ )
{
Word32 temp_left = L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ); /* Qx */
@@ -415,6 +435,7 @@ void tdm_upmix_plain_fx(
Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */
move32();
}
+#endif /* OPT_STEREO_32KBPS_V1 */
}
return;
@@ -680,17 +701,17 @@ void stereo_tdm_combine_fx(
output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */
move32();
- tdm_n_OVA = NS2SA( output_Fs, TDM_L_NOVA_NS ); /* Q0 */
+ tdm_n_OVA = NS2SA_FX2( output_Fs, TDM_L_NOVA_NS ); /* Q0 */
move16();
IF( flag_HB )
{
- upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ); /* Q0 */
+ upmixing_delay = NS2SA_FX2( output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ); /* Q0 */
move16();
}
ELSE
{
- upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_CLDFB_NS ); /* Q0 */
+ upmixing_delay = NS2SA_FX2( output_Fs, ACELP_LOOK_NS + DELAY_CLDFB_NS ); /* Q0 */
move16();
}
@@ -845,7 +866,7 @@ void stereo_tdm_combine_fx(
}
incr_fx = Mpy_32_32( L_sub( ONE_IN_Q29, fac_fx ), step ); /* Q29 */
- FOR( i = 0; i < NS2SA( output_Fs, ACELP_LOOK_NS ); i++ )
+ FOR( i = 0; i < NS2SA_FX2( output_Fs, ACELP_LOOK_NS ); i++ )
{
PCh_2_L_fx[i] = L_shl_sat( Mpy_32_32( PCh_2_L_fx[i], fac_fx ), 2 ); /* Qx */
move32();
diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_svd_dec.c
rename to lib_dec/ivas_svd_dec_fx.c
index a22502188fdbe5eb8e8cf4c443f20fc99f330e97..bb73fe7f02d501b2fe88b45dfd34b31e950a40a4 100644
--- a/lib_dec/ivas_svd_dec.c
+++ b/lib_dec/ivas_svd_dec_fx.c
@@ -32,13 +32,12 @@
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_stat_dec.h"
#include "ivas_cnst.h"
#include
#include "wmc_auto.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
/*-----------------------------------------------------------------------*
diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_tcx_core_dec.c
rename to lib_dec/ivas_tcx_core_dec_fx.c
index 37ffc51289287dcb9dcbc5477042e80c7d4f650c..c908e4dc3f3eaecc2ee926f888d5b399b8888799 100644
--- a/lib_dec/ivas_tcx_core_dec.c
+++ b/lib_dec/ivas_tcx_core_dec_fx.c
@@ -34,14 +34,13 @@
#include
#include "options.h"
#include
-#include "prot.h"
+#include "prot_fx.h"
#include "rom_com.h"
#include "stat_dec.h"
#include "wmc_auto.h"
#include "basop_proto_func.h"
#include "stat_com.h"
#include "ivas_prot.h"
-#include "prot_fx.h"
#include "ivas_prot_fx.h"
/*-------------------------------------------------------------*
diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec_fx.c
similarity index 99%
rename from lib_dec/ivas_td_low_rate_dec.c
rename to lib_dec/ivas_td_low_rate_dec_fx.c
index a4380bd4e7c3c70cb8805d432b15ce25be18d540..63819b05619f23fa244bad37563f0fa3334b3118 100644
--- a/lib_dec/ivas_td_low_rate_dec.c
+++ b/lib_dec/ivas_td_low_rate_dec_fx.c
@@ -37,7 +37,6 @@
#include "rom_com.h"
#include "ivas_rom_com.h"
#include "ivas_cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "wmc_auto.h"
diff --git a/lib_dec/jbm_jb4_circularbuffer.c b/lib_dec/jbm_jb4_circularbuffer.c
index cdabe4700874d140093d30ee06759cf4abf2be4e..f9d6d1ca148c39a2c2891ace4451261d119a2458 100644
--- a/lib_dec/jbm_jb4_circularbuffer.c
+++ b/lib_dec/jbm_jb4_circularbuffer.c
@@ -38,7 +38,7 @@
#include
#include "options.h"
#include "string.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
/* local includes */
#include "jbm_jb4_circularbuffer.h"
diff --git a/lib_dec/jbm_jb4_circularbuffer.h b/lib_dec/jbm_jb4_circularbuffer.h
index de614eeeacbc2a13a68552346507f5894375bd53..9e3102feba4dee6b3812f2aca4cdd5c6b7461c20 100644
--- a/lib_dec/jbm_jb4_circularbuffer.h
+++ b/lib_dec/jbm_jb4_circularbuffer.h
@@ -37,7 +37,7 @@
#ifndef JBM_JB4_CIRCULARBUFFER_H
#define JBM_JB4_CIRCULARBUFFER_H JBM_JB4_CIRCULARBUFFER_H
-#include "prot.h"
+#include "prot_fx.h"
#include "cnst.h"
/** handle for circular buffer (FIFO) with fixed capacity */
diff --git a/lib_dec/jbm_jb4_inputbuffer.c b/lib_dec/jbm_jb4_inputbuffer.c
index 55113ee1366b2bfff5bca8db5e6041940fa57bbd..5497a437126a701eccbc82e1aad6bf352a654f06 100644
--- a/lib_dec/jbm_jb4_inputbuffer.c
+++ b/lib_dec/jbm_jb4_inputbuffer.c
@@ -39,7 +39,7 @@
#include
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "string.h"
#include "jbm_jb4_inputbuffer.h"
#include "wmc_auto.h"
diff --git a/lib_dec/jbm_jb4_jmf.c b/lib_dec/jbm_jb4_jmf.c
index 940df5ecb7a612d96087112f41493e5ce410cd0b..5ab8242c75bbbd078d3fbc6ddc30ee102bf1b224 100644
--- a/lib_dec/jbm_jb4_jmf.c
+++ b/lib_dec/jbm_jb4_jmf.c
@@ -42,7 +42,7 @@
#include
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
/* local includes */
diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c
index 4878b7d647b5716ea3b17e70477b86dc9e54905c..002b4bc109985558a4bf8769317309d597cb8aca 100644
--- a/lib_dec/jbm_jb4sb.c
+++ b/lib_dec/jbm_jb4sb.c
@@ -48,7 +48,6 @@
#include "jbm_jb4_inputbuffer.h"
#include "jbm_jb4_jmf.h"
#include "jbm_jb4sb.h"
-#include "prot.h"
#include "prot_fx.h"
#define WMC_TOOL_SKIP
diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c
index 10b91a60c4f472e7d91281954adb26bb0948568b..ac6a28b86c99079fe16cf201a5fd06af33610ab5 100644
--- a/lib_dec/jbm_pcmdsp_apa.c
+++ b/lib_dec/jbm_pcmdsp_apa.c
@@ -44,7 +44,7 @@
#include
#include
#include "options.h"
-#include "prot.h"
+#include "prot_fx.h"
#include "wmc_auto.h"
/* local headers */
#include "jbm_pcmdsp_apa.h"
@@ -54,7 +54,6 @@
#include "rom_dec.h"
-#include "prot_fx.h"
#define INV_100_Q15 328
#define INV_400_Q15 82
#define INV_80_Q15 410
diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c
index 9753893e2cd84e406a23e383f2a8fe70e69232d4..df3981a37af7e7b178f82996a0a34df785071d14 100644
--- a/lib_dec/lib_dec_fx.c
+++ b/lib_dec/lib_dec_fx.c
@@ -37,11 +37,10 @@
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
-#include "prot.h"
-#include "ivas_prot_fx.h"
#include "prot_fx.h"
#include "isar_prot.h"
#include "lib_isar_pre_rend.h"
+#include "ivas_prot_fx.h"
#include "jbm_jb4sb.h"
#include "jbm_pcmdsp_apa.h"
@@ -1184,123 +1183,125 @@ ivas_error IVAS_DEC_GetSamples(
{
/* check if we need to run the setup function */
test();
- IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ){
+ IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
+ {
/* setup */
- IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ){
- return error;
- }
-}
-{
- /* check if we need to run the setup function, tc decoding and feeding the renderer */
- test();
- IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
- {
- Word16 nResidualSamples, nSamplesTcsScaled;
- nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
-
- test();
- IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && NE_16( (Word16) nTransportChannels, hIvasDec->nTransportChannelsOld ) )
- {
- IF( NE_32( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ), IVAS_ERR_OK ) )
+ IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) )
{
return error;
}
}
-
- /* IVAS decoder */
- IF( NE_32( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
-
- /* JBM */
- IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
{
- IF( apa_set_scale_fx( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 )
+ /* check if we need to run the setup function, tc decoding and feeding the renderer */
+ test();
+ IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
{
- return IVAS_ERR_UNKNOWN;
- }
+ Word16 nResidualSamples, nSamplesTcsScaled;
+ nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
- // tmp apaExecBuffer
- IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
- {
- Word16 tmp_apaExecBuffer[APA_BUF];
- FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i )
+ test();
+ IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && NE_16( (Word16) nTransportChannels, hIvasDec->nTransportChannelsOld ) )
{
- tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0
+ IF( NE_32( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
}
- IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 )
+
+ /* IVAS decoder */
+ IF( NE_32( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ), IVAS_ERR_OK ) )
{
- return IVAS_ERR_UNKNOWN;
+ return error;
}
- FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i )
+
+ /* JBM */
+ IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
{
- hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11
+ IF( apa_set_scale_fx( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 )
+ {
+ return IVAS_ERR_UNKNOWN;
+ }
+
+ // tmp apaExecBuffer
+ IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
+ {
+ Word16 tmp_apaExecBuffer[APA_BUF];
+ FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i )
+ {
+ tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0
+ }
+ IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 )
+ {
+ return IVAS_ERR_UNKNOWN;
+ }
+ FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i )
+ {
+ hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11
+ }
+ }
+ ELSE
+ {
+ IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer_fx, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer_fx, &nTimeScalerOutSamples ) != 0 )
+ {
+ return IVAS_ERR_UNKNOWN;
+ }
+ }
+ assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) );
+ nSamplesTcsScaled = idiv1616U( extract_l( nTimeScalerOutSamples ), nTransportChannels );
}
- }
- ELSE
- {
- IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer_fx, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer_fx, &nTimeScalerOutSamples ) != 0 )
+ ELSE
{
- return IVAS_ERR_UNKNOWN;
+ nSamplesTcsScaled = hIvasDec->nSamplesFrame;
+ move16();
+ }
+
+ /* Feed decoded transport channels samples to the renderer */
+ IF( NE_32( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer_fx ) ), IVAS_ERR_OK ) )
+ {
+ return error;
}
+
+ IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
+ {
+ /* feed residual samples to TSM for the next call */
+ IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ) != 0 )
+ {
+ return IVAS_ERR_UNKNOWN;
+ }
+ }
+ hIvasDec->hasBeenFedFrame = false;
+ move16();
}
- assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) );
- nSamplesTcsScaled = idiv1616U( extract_l( nTimeScalerOutSamples ), nTransportChannels );
- }
- ELSE
- {
- nSamplesTcsScaled = hIvasDec->nSamplesFrame;
- move16();
- }
- /* Feed decoded transport channels samples to the renderer */
- IF( NE_32( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer_fx ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
+ /* render IVAS frames directly to the output buffer */
+ nSamplesToRender = sub( nSamplesAsked, nSamplesRendered );
+ IF( NE_32( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) )
+ {
+ return error;
+ }
- IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
- {
- /* feed residual samples to TSM for the next call */
- IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ) != 0 )
+ nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
+ nSamplesToRender = sub( nSamplesToRender, nSamplesRendered_loop );
+ IF( hIvasDec->nSamplesAvailableNext == 0 )
{
- return IVAS_ERR_UNKNOWN;
+ *needNewFrame = true;
+ hIvasDec->needNewFrame = true;
+ move16();
+ move16();
+ }
+ ELSE
+ {
+ *needNewFrame = false;
+ move16();
}
}
- hIvasDec->hasBeenFedFrame = false;
- move16();
}
- /* render IVAS frames directly to the output buffer */
- nSamplesToRender = sub( nSamplesAsked, nSamplesRendered );
- IF( NE_32( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) )
- {
- return error;
- }
-
- nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
- nSamplesToRender = sub( nSamplesToRender, nSamplesRendered_loop );
- IF( hIvasDec->nSamplesAvailableNext == 0 )
- {
- *needNewFrame = true;
- hIvasDec->needNewFrame = true;
- move16();
- move16();
- }
- ELSE
- {
- *needNewFrame = false;
- move16();
- }
-}
-}
-
-*nOutSamples = nSamplesRendered;
-move16();
+ *nOutSamples = nSamplesRendered;
+ move16();
-return IVAS_ERR_OK;
+ return IVAS_ERR_OK;
}
@@ -3871,7 +3872,7 @@ static ivas_error evs_dec_main_fx(
move32();
hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 /*Q0*/ ) ); // Q0
move16();
- mdct_switching_dec( hCoreCoder[0] );
+ mdct_switching_dec_ivas_fx( hCoreCoder[0] );
FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ )
{
diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c
index 50b5ec34131966f34314a4cf6e45dd344127e03a..d263e6dd34ef5e958474f8be275b98e7582de6bc 100644
--- a/lib_dec/lsf_dec_fx.c
+++ b/lib_dec/lsf_dec_fx.c
@@ -195,7 +195,6 @@ void lsf_dec_fx(
/* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/
st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */
move16();
- // PMTE() /*IVAS_CODE to be completed */
}
}
IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
@@ -449,7 +448,6 @@ void lsf_dec_ivas_fx(
/* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/
st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */
move16();
- // PMTE() /*IVAS_CODE to be completed */
}
}
IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
@@ -664,12 +662,7 @@ void lsf_end_dec_fx(
test();
test();
-#ifdef LSF_RE_USE_SECONDARY_CHANNEL
- test();
- IF( ( EQ_16( coder_type_org, GENERIC ) ) && ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( mode2_flag == 0 ) && ( st->idchan == 0 ) )
-#else
IF( ( EQ_16( coder_type_org, GENERIC ) ) && ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( mode2_flag == 0 ) )
-#endif
{
/* this bit is used only for primary channel or mono */
coder_type = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */
diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c
index b72c2bae16296e0d49371ce46b16907438c3ba4f..1d3e9649793cb0578063ec2b5235a452812ffe1d 100644
--- a/lib_dec/pit_dec_fx.c
+++ b/lib_dec/pit_dec_fx.c
@@ -333,11 +333,6 @@ Word16 pit_decode_fx( /* o : floating pitch value
Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */
Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */
const Word16 L_subfr /* i : subframe length */
-#ifdef ADD_LRTD
- ,
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
-#endif
)
{
Word16 pitch; /*Q2*/
@@ -458,57 +453,6 @@ Word16 pit_decode_fx( /* o : floating pitch value
pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
}
-#ifdef ADD_LRTD
- ELSE IF( EQ_16( st_fx->idchan, 1 ) && ( EQ_16( tdm_Pitch_reuse_flag, 1 ) || EQ_16( nBits, 4 ) ) )
- {
- test();
- test();
- /*-------------------------------------------------------*
- * Pitch decoding with reusing of primary channel information
- *-------------------------------------------------------*/
- Word16 loc_T0, loc_frac, delta, pit_tmp1, pit_tmp2, isubfridx;
-
- delta = 4;
- pit_flag = L_SUBFR;
- move16();
- move16();
- isubfridx = shr( i_subfr, 6 );
- IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
- {
- move16();
- move16();
- pit_tmp1 = tdm_Pri_pitch_buf[isubfridx]; /*tdm_Pri_pitch_buf in Q6 ->pit_tmp1 and 2 in Q6 too */
- pit_tmp2 = tdm_Pri_pitch_buf[shr( add( i_subfr, 1 ), 6 )];
- /*loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]);*/
- loc_T0 = mac_r( L_mult( 16384, pit_tmp1, 16384, pit_tmp2 ) );
- /*loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f);*/
- }
- ELSE
- {
- /*loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR];*/
- loc_T0 = tdm_Pri_pitch_buf[isubfridx]; /*Q6*/
- /*loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f);*/
- }
- loc_frac = shr(sub(loc_T0, shl(shr(loc_T0, 6), 6)), 4)); /* Final result in Q 2*/
- loc_T0 = shr( loc_T0, 6 ); /*Q6 -> Q0*/
-
-
- limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max );
-
- IF( nBits > 0 )
- {
- pit_Q_dec_fx( 0, pitch_index, nBits, delta, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
- }
- ELSE
- {
- *T0 = loc_T0;
- *T0_frac = loc_frac;
- move16();
- move16();
- }
- printf( "function not tested yet\n" );
- }
-#endif
ELSE
{
/*-------------------------------------------------------*
diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h
index 3c1065c24203d7a41d294bf723baf7708142d40d..530cd41d0fed9de98c364a56729a24119db8dc23 100644
--- a/lib_dec/stat_dec.h
+++ b/lib_dec/stat_dec.h
@@ -529,32 +529,17 @@ typedef struct tcx_dec_structure
typedef struct gsc_dec_structure
{
- Word16 seed_tcx; /* AC mode (GSC) - seed for noise fill */
-
- Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */
- // Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */
-
- Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */
-
- Word16 noise_lev; /* AC mode (GSC) - noise level */
- // Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/
-
+ Word16 seed_tcx; /* AC mode (GSC) - seed for noise fill */
+ Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */
+ Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */
+ Word16 noise_lev; /* AC mode (GSC) - noise level */
Word16 lt_ener_per_band_fx[MBANDS_GN16k]; /* Q12 */
-
- Word32 Last_frame_ener_fx; /* AC mode (GSC) - last frame energy */
-
- Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */
-
- Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */
- // Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/
-
- Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous excitation */
-
- Word16 last_ener_fx; /* AC mode (GSC) - previous energy */
-
- Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */
- // Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */
-
+ Word32 Last_frame_ener_fx; /* AC mode (GSC) - last frame energy */
+ Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */
+ Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */
+ Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous excitation */
+ Word16 last_ener_fx; /* AC mode (GSC) - previous energy */
+ Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */
} GSC_DEC_DATA, *GSC_DEC_HANDLE;
@@ -566,10 +551,8 @@ typedef struct gsc_dec_structure
typedef struct WI_dec_structure
{
Word16 old_exc2_fx[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */
-
Word16 old_syn2_fx[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */
-
} WI_DEC_DATA, *WI_DEC_HANDLE;
diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c
deleted file mode 100644
index 68272a79fb39c7aacbc3a6fc06306ced80066c3d..0000000000000000000000000000000000000000
--- a/lib_dec/swb_bwe_dec.c
+++ /dev/null
@@ -1,681 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "prot.h"
-#include "prot_fx.h"
-#include "rom_com.h"
-#include "basop_util.h"
-#include "basop_proto_func.h"
-#include "wmc_auto.h"
-
-
-static Word16 para_pred_bws_fx(
- Decoder_State *st_fx, /* i/o: decoder state structure */
- Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn */
- Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */
- Word16 Q_syn )
-{
- Word16 i, j, k;
- Word16 mode;
- Word16 tmp, tmp_den, tmp_num;
- Word32 L_tmp, L_tmp_max;
- Word16 exp;
- Word16 *input_hi_fx;
- Word32 *mea;
- Word16 peak_fx, mag_fx;
- Word32 mean_fx[7], peak_32_fx;
- Word32 avrg1_fx, avrg2_fx, min_fx;
- Word16 att_fx;
- Word16 coder_type = st_fx->coder_type;
- move16();
-
- mode = NORMAL;
- move16();
-
- k = 0;
- move16();
- input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/
- FOR( i = 0; i < 7; i++ )
- {
- peak_fx = 0;
- move16();
- mean_fx[i] = 0;
- move16();
- FOR( j = 0; j < SHARP_WIDTH; j++ )
- {
- mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/
- peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/
- mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/
- move32();
- input_hi_fx++;
- }
-
- IF( LT_16( Q_syn, 11 ) )
- {
- tmp = 1;
- move16();
- }
- ELSE
- {
- tmp = 0;
- move16();
- if ( GT_16( shr( peak_fx, 3 ), shl( 1, Q_syn ) ) )
- {
- tmp = 1;
- move16();
- }
- }
- IF( tmp > 0 )
- {
- L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ );
- if ( L_tmp < 0 )
- {
- k = add( k, 1 );
- }
- }
- }
-
- avrg1_fx = L_deposit_l( 0 );
- avrg2_fx = L_deposit_l( 0 );
- FOR( i = 1; i < 4; i++ )
- {
- avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/
- avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/
- }
- avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/
- avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/
-
- min_fx = L_add( 2147483647, 0 ); /*2^31 */
- peak_32_fx = L_deposit_l( 0 );
- FOR( i = 4; i < 7; i++ )
- {
- IF( GT_32( mean_fx[i], L_shl( avrg2_fx, 1 ) ) )
- {
- exp = norm_l( mean_fx[i] );
- IF( LT_16( exp, 16 ) )
- {
- tmp_den = extract_l( L_shr( mean_fx[i], sub( 16, exp ) ) ); /*Qsyn - 16 + exp */
- tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*Qsyn - 16 + exp */
- }
- ELSE
- {
- tmp_den = extract_l( mean_fx[i] );
- tmp_num = extract_l( L_shl( avrg2_fx, 1 ) );
- }
-
- tmp_den = div_s( 1, tmp_den );
-
- tmp = i_mult( tmp_num, tmp_den ); /*Q15 */
-
- mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); /*Q_syn + Q15 - 15*/
- move32();
- }
- min_fx = L_min( min_fx, mean_fx[i] );
- peak_32_fx = L_max( peak_32_fx, mean_fx[i] );
- }
-
- IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) )
- {
- IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) )
- {
- min_fx = peak_32_fx;
- move32();
- }
- ELSE
- {
- tmp = extract_l( L_shr( L_mult0( st_fx->tilt_wb_fx, 17476 ), 14 ) ); /*Q15 */
- min_fx = Mult_32_16( peak_32_fx, tmp );
- }
- }
-
- test();
- IF( peak_32_fx == 0 || min_fx == 0 )
- {
- set16_fx( SWB_fenv_fx, 0, SWB_FENV );
- }
- ELSE
- {
- exp = norm_l( peak_32_fx );
- IF( LT_16( exp, 16 ) )
- {
- tmp_den = extract_l( L_shr( peak_32_fx, sub( 16, exp ) ) ); /*Qsyn - 16 + exp */
- tmp = div_s( 16384, tmp_den ); /*Q15+14 - (Qsyn - 16 + exp) */
- tmp_num = extract_l( L_shr( min_fx, sub( 16, exp ) ) ); /*Qsyn - 16 + exp */
- tmp = extract_l( L_shr( L_mult0( tmp_num, tmp ), 14 ) ); /*Q15 */
- }
- ELSE
- {
- tmp_den = extract_l( peak_32_fx ); /*Qsyn */
- exp = norm_s( tmp_den );
- tmp = div_s( shl( 1, sub( 14, exp ) ), tmp_den ); /*Q 29-exp - Qsyn */
- tmp_num = extract_l( min_fx ); /*Qsyn */
- tmp = extract_l( L_shr( L_mult0( tmp_num, tmp ), sub( 14, exp ) ) ); /*Q15 */
- }
-
- j = 0;
- move16();
- mea = &mean_fx[4];
- L_tmp_max = L_shl( 32767, add( Q_syn, 5 ) );
- FOR( i = 0; i < SWB_FENV; i++ )
- {
- if ( EQ_16( j, 5 ) )
- {
- mea++;
- j = 0;
- move16();
- }
- j = add( j, 1 );
- L_tmp = L_min( Mult_32_16( *mea, tmp ), L_tmp_max );
- SWB_fenv_fx[i] = extract_l( L_shr( L_tmp, add( Q_syn, 5 ) ) );
- move16();
- }
- }
-
- j = 0;
- move16();
- FOR( i = SWB_FENV / 2; i < SWB_FENV; i++ )
- {
- tmp = sub( 32767, i_mult( j, 2341 ) );
- SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], tmp );
- move16();
- j = add( j, 1 );
- }
-
- IF( GT_32( avrg1_fx, L_shl( avrg2_fx, 3 ) ) )
- {
- FOR( i = 0; i < SWB_FENV; i++ )
- {
- SWB_fenv_fx[i] = shr( SWB_fenv_fx[i], 1 );
- move16();
- }
- }
-
- test();
- test();
- test();
- test();
- test();
- IF( NE_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) &&
- ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) &&
- ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) )
- {
- FOR( i = 0; i < SWB_FENV; i++ )
- {
- test();
- IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 /*1/2.0f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) )
- {
- SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ) );
- move16();
- }
- ELSE
- {
- SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767 /*1.0f in Q15*/, st_fx->attenu_fx ) ) );
- move16();
- }
- }
-
- IF( LT_16( st_fx->attenu_fx, 29491 /*0.9f in Q15*/ ) )
- {
- st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 /*0.05f in Q15*/ );
- move16();
- }
- }
- ELSE
- {
- test();
- test();
- test();
- test();
- IF( NE_32( st_fx->core_brate, st_fx->last_core_brate ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ||
- ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) )
- {
- FOR( i = 0; i < SWB_FENV; i++ )
- {
- if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 /*0.5f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) )
- {
- SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i];
- move16();
- }
- }
- }
-
- FOR( i = 0; i < SWB_FENV; i++ )
- {
- SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ) );
- move16();
- }
- st_fx->attenu_fx = 3277; /*Q15*/
- move16();
- }
-
- if ( GT_16( k, 3 ) )
- {
- mode = HARMONIC;
- move16();
- }
-
-
- att_fx = i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ); /*15 */
- IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
- {
- FOR( i = 0; i < 4; i++ )
- {
- SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], att_fx );
- move16(); /*Q1 */
- }
- }
-
- FOR( i = 4; i < SWB_FENV; i++ )
- {
- SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], att_fx );
- move16(); /*Q1 */
- }
-
- return mode;
-}
-
-
-/*-------------------------------------------------------------------*
- * WB_BWE_gain_deq()
- *
- * Decoding of WB parameters
- *-------------------------------------------------------------------*/
-
-
-Word16 swb_bwe_dec_fx32(
- Decoder_State *st_fx, /* i/o: decoder state structure */
- Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */
- Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */
- Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */
- Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
- Word16 output_frame /* i : frame length */
-)
-{
- Word16 L;
- Word16 mode;
- Word16 idxGain;
- Word16 i, j, l_subfr;
- Word16 fb_band_begin;
- Word16 frica_flag = 0;
- move16();
- Word16 ener_adjust_quan_fx;
- Word16 fb_ener_adjust_fx = 0;
- move16();
- Word16 scl, new_input_fx_exp, ysynth_frame_size;
- Word16 Q_syn, Q_syn_hb, tmp, tmp2, q_tmp, Qsynth_fx16;
-
- Word16 ysynth_fx[L_FRAME48k];
- Word16 SWB_fenv_fx[SWB_FENV];
- Word16 SWB_tenv_fx[SWB_TENV];
- Word16 synth_fx16[L_FRAME48k];
- Word16 hb_synth_fx16[L_FRAME48k];
-
- Word32 L_tmp;
- Word32 yerror_fx[L_FRAME48k];
- Word32 ysynth_fx32[L_FRAME48k];
- Word32 SWB_tenv_tmp_fx[SWB_TENV];
- Word32 wtda_synth_fx[2 * L_FRAME48k];
-
- FD_BWE_DEC_HANDLE hBWE_FD;
- hBWE_FD = st_fx->hBWE_FD;
-
- /*---------------------------------------------------------------------*
- * SWB BWE decoding
- *---------------------------------------------------------------------*/
- test();
- IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
- {
- /* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */
- /* todo - delay output[] by 1.25ms ? */
- L_lerp_fx_q11( output_fx, ysynth_fx32, L_FRAME16k, st_fx->L_frame );
-
- /* windowing of the ACELP core synthesis */
- wtda_fx32( ysynth_fx32, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, /*st_fx->L_frame*/ L_FRAME16k );
-
- /* DCT of the ACELP core synthesis */
- new_input_fx_exp = 11;
- move16();
- direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, /*st_fx->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode );
- ysynth_frame_size = L_FRAME16k;
- move16();
- }
- ELSE
- {
- /* windowing of the ACELP core synthesis */
- wtda_fx32( synth_fx, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, output_frame );
-
- /* DCT of the ACELP core synthesis */
- new_input_fx_exp = 11;
- move16();
- direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode );
- ysynth_frame_size = output_frame;
- move16();
- }
-
- /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */
- scl = sub( 16 + 11, new_input_fx_exp );
- /* Possible to Upscale? */
- IF( scl > 0 )
- {
- /* Yes */
- /* Calc Room to Upscale */
- Q_syn = sub( Find_Max_Norm32( ysynth_fx32, ysynth_frame_size ), 3 );
- /* Stay within MAX_Q_NEW_INPUT */
- scl = s_min( Q_syn, scl );
- }
- /*Don't upscale if already in 15 bits*/
- IF( GT_16( scl, 15 ) )
- {
- FOR( i = 0; i < ysynth_frame_size; i++ )
- {
- ysynth_fx[i] = extract_l( ysynth_fx32[i] );
- move16();
- }
- Q_syn = new_input_fx_exp;
- move16();
- }
- ELSE
- {
- Copy_Scale_sig32_16( ysynth_fx32, ysynth_fx, ysynth_frame_size, scl );
- Q_syn = add( sub( new_input_fx_exp, 16 ), scl );
- }
-
- IF( !st_fx->bfi )
- {
- IF( st_fx->bws_cnt > 0 )
- {
- /* estimate parameters */
- mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn );
- }
- ELSE
- {
- /* de-quantization */
- mode = swb_bwe_gain_deq_fx( st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 );
- }
-
- L = SWB_FENV;
- move16();
- if ( EQ_16( mode, TRANSIENT ) )
- {
- L = SWB_FENV_TRANS;
- move16();
- }
-
- L_tmp = 0;
- move32();
- FOR( i = 0; i < L; i++ )
- {
- L_tmp = L_add( L_tmp, L_deposit_l( SWB_fenv_fx[i] ) );
- }
- q_tmp = norm_s( L );
- tmp = div_s( shl( 1, sub( 14, q_tmp ) ), L ); /*Q(29-q_tmp) */
- L_tmp = Mpy_32_16_1( L_tmp, tmp ); /*Q(1+29-q_tmp+1-16)->Q(15-q_tmp) */
- st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, add( q_tmp, 2 ) ) ); /*Q1 */
- move16();
- }
- ELSE
- {
- /* SHB FEC */
-
- IF( NE_16( hBWE_FD->prev_mode, TRANSIENT ) )
- {
- mode = hBWE_FD->prev_mode;
- move16();
- }
- ELSE
- {
- mode = NORMAL;
- move16();
- }
-
- Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV );
- }
-
- /* reconstruction of MDCT spectrum of the error signal */
- set32_fx( yerror_fx, 0, output_frame );
-
- IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
- {
- SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl );
- }
- ELSE
- {
- SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl );
- }
-
- test();
- IF( EQ_16( hBWE_FD->prev_frica_flag, 1 ) && frica_flag == 0 )
- {
- FOR( i = 0; i < L_SUBFR; i++ )
- {
- tmp = sub( 32767, extract_l( L_mult0( i, 512 ) ) ); /*Q15 */
- hBWE_FD->mem_imdct_fx[i] = mult_r( hBWE_FD->mem_imdct_fx[i], tmp );
- move16();
- }
-
- FOR( ; i < output_frame; i++ )
- {
- hBWE_FD->mem_imdct_fx[i] = 0;
- move16();
- }
- }
-
- /* decode information */
- IF( EQ_16( st_fx->extl, FB_BWE ) )
- {
- IF( !st_fx->bfi )
- {
- idxGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_FB_FRAMEGAIN );
- fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */
- }
- ELSE IF( st_fx->bfi )
- {
- fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx;
- move16();
- }
-
- st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx;
- move16();
- IF( EQ_16( mode, TRANSIENT ) )
- {
- ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 );
- }
- ELSE
- {
- IF( SWB_fenv_fx[7] != 0 )
- {
- tmp = div_s( 1, SWB_fenv_fx[7] );
- ener_adjust_quan_fx = s_min( shr( i_mult_sat( SWB_fenv_fx[13], tmp ), 2 ), 32767 );
- }
- ELSE
- {
- ener_adjust_quan_fx = 0;
- move16();
- }
- }
-
- fb_band_begin = FB_BAND_BEGIN;
- move16();
- if ( EQ_16( st_fx->L_frame, L_FRAME ) )
- {
- fb_band_begin = FB_BAND_BEGIN_12k8;
- move16();
- }
-
- j = 0;
- move16();
- FOR( i = fb_band_begin; i < add( fb_band_begin, DE_OFFSET1 ); i++ )
- {
- tmp = sub( 32767, i_mult( j, 1024 ) );
- tmp = mult_r( tmp, ener_adjust_quan_fx ); /*Q13*/
-
- tmp2 = i_mult( j, 256 ); /*Q13*/
- tmp2 = mult_r( tmp2, fb_ener_adjust_fx ); /*Q13*/
-
- tmp = add( tmp, tmp2 ); /*Q13*/
- yerror_fx[i] = L_shl( Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], tmp ), 2 ); /*15+Q_syn */
- move32();
- j = add( j, 1 );
- }
- FOR( ; i < FB_BAND_END; i++ )
- {
- yerror_fx[i] = Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], fb_ener_adjust_fx ); /*15+Q_syn */
- move32();
- }
- }
-
- /* iDCT of the error signal */
- Q_syn_hb = add( Q_syn, 15 );
- Inverse_Transform( yerror_fx, &Q_syn_hb, wtda_synth_fx, 0, output_frame, -1, st_fx->element_mode );
-
- /* inverse windowing of the error signal */
- window_ola_fx( wtda_synth_fx, hb_synth_fx16, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 );
- l_subfr = mult( output_frame, 8192 );
-
- test();
- IF( EQ_16( mode, TRANSIENT ) )
- {
- FOR( i = 0; i < SWB_TENV; i++ )
- {
- SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i] /*Q0*/, 26214 /*0.8f Q15*/ ); // Q15
- move32();
- }
-
- /* time envelope shaping when the current frame is TRANSIENT frame */
- time_envelop_shaping_ivas_fx( hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb );
-
- Q_syn_hb = sub( Q_syn_hb, 3 );
-
- hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3];
- move16();
- }
- ELSE IF( EQ_16( frica_flag, 1 ) && hBWE_FD->prev_frica_flag == 0 )
- {
- Qsynth_fx16 = Find_Max_Norm32( synth_fx, output_frame );
- Qsynth_fx16 = sub( Qsynth_fx16, shr( add( sub( 15, norm_s( l_subfr ) ), 1 ), 1 ) );
- Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 );
- Qsynth_fx16 = add( 11 - 16, Qsynth_fx16 );
-
- /* IVAS_fmToDo: synth[] is @internal_Fs!!! */
- time_reduce_pre_echo_fx( synth_fx16, hb_synth_fx16, hBWE_FD->prev_td_energy_fx, l_subfr, Qsynth_fx16, Q_syn_hb );
- }
- ELSE
- {
- tmp = i_mult2( 3, l_subfr );
- L_tmp = L_deposit_l( 0 );
-
- FOR( i = 0; i < l_subfr; i++ )
- {
- L_tmp = L_mac0_sat( L_tmp, hb_synth_fx16[add( tmp, i )], hb_synth_fx16[add( tmp, i )] ); /*(2*Q_syn_hb) */
- }
-
- L_tmp = Mult_32_16( L_tmp, div_s( 1, l_subfr ) ); /*(2*Q_syn_hb) */
- hBWE_FD->prev_td_energy_fx = 0;
- move16();
-
- IF( L_tmp != 0 )
- {
- q_tmp = norm_l( L_tmp );
- tmp = extract_h( L_shl( L_tmp, q_tmp ) );
- q_tmp = sub( q_tmp, sub( 30, shl( Q_syn_hb, 1 ) ) );
-
- tmp = div_s( 16384, tmp );
- L_tmp = L_deposit_h( tmp );
- L_tmp = Isqrt_lc( L_tmp, &q_tmp ); /*Q(31-exp) */
- hBWE_FD->prev_td_energy_fx = round_fx( L_shl( L_tmp, sub( q_tmp, 15 ) ) ); /*Q0 */
- move16();
- }
- }
-
- test();
- IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
- {
- Qsynth_fx16 = add( 16 - 11, Q_syn_hb );
- Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 );
-
- /* add HB synth from hf_synth() */
- v_add_16( hb_synth_fx16, synth_fx16, hb_synth_fx16, output_frame );
- }
-
- hBWE_FD->prev_mode = mode;
- move16();
- hBWE_FD->prev_frica_flag = frica_flag;
- move16();
-
- FOR( i = 0; i < output_frame; i++ )
- {
- hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); // Q_syn_hb
- move32();
- }
-
- return Q_syn_hb;
-}
-
-
-void fd_bwe_dec_init_fx(
- FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */
-)
-{
- set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k );
- set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) );
- hBWE_FD->prev_mode = NORMAL;
- move16();
- hBWE_FD->prev_Energy_fx = 0;
- move16();
- hBWE_FD->prev_L_swb_norm = 8;
- move16();
- hBWE_FD->Seed = 21211;
- move16();
- hBWE_FD->prev_frica_flag = 0;
- move16();
- set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k );
- hBWE_FD->prev_td_energy_fx = 0;
- move16();
- hBWE_FD->prev_weight_fx = 0;
- move16();
- hBWE_FD->prev_flag = 0;
- move16();
- hBWE_FD->prev_Energy_wb_fx = 0;
- move32();
- hBWE_FD->mem_deemph_old_syn_fx = 0;
- move16();
-
- return;
-}
diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c
index 7a6abb79001d34faf376c75c56a7b40d5af65d1a..b91dcdf328f1d9151f6574777ff24e73d0324304 100644
--- a/lib_dec/swb_bwe_dec_fx.c
+++ b/lib_dec/swb_bwe_dec_fx.c
@@ -505,19 +505,12 @@ Word16 ivas_wb_bwe_dec_fx( /* o :
}
Word16 wb_bwe_dec_fx(
-#ifdef ADD_IVAS_BWE
- const Word16 output[], /* i : suntehsis @ internal Fs */
-#endif
- Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */
- Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
-#ifdef ADD_IVAS_BWE
- const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
-#endif
+ Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */
+ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
const Word16 output_frame, /* i : frame length */
Word16 *voice_factors_fx, /* i : voicing factors Q15 */
const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */
- Decoder_State *st_fx /* i/o: decoder state structure */
- ,
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 *Qpost )
{
Word16 mode;
@@ -538,18 +531,7 @@ Word16 wb_bwe_dec_fx(
new_input_fx_exp = *Qpost;
move16();
-#ifdef ADD_IVAS_BWE
- if ( st->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft )
- {
- /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */
- /* IVAS_fmToDo: delay output[] by 1.25ms ? */
- lerp( output, ysynth, L_FRAME16k, st->L_frame );
- wtda( ysynth, wtda_synth, hBWE_FD->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k );
- direct_transform( wtda_synth, ysynth, 0, /*st->L_frame*/ L_FRAME16k, st->element_mode );
- }
- else
-#endif
{
wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx,
&hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */
@@ -574,11 +556,7 @@ Word16 wb_bwe_dec_fx(
Q_syn = add( sub( new_input_fx_exp, 16 ), scl );
IF( !st_fx->bfi )
{
-#ifdef ADD_IVAS_BWE
- IF( st_fx->extl_brate > 0 )
-#else
IF( EQ_32( st_fx->total_brate, ACELP_13k20 ) )
-#endif
{
/* de-quantization */
mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx );
@@ -654,20 +632,15 @@ Word16 wb_bwe_dec_fx(
window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame,
ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 );
-#ifdef ADD_IVAS_BWE
- test();
- IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
- {
- /* add HB synth from hf_synth() */
- v_add( hb_synth, synth, hb_synth, output_frame );
- }
-#endif
hBWE_FD->prev_mode = mode;
move16();
st_fx->prev_Q_synth = Q_syn;
move16();
+
return Q_syn_hb;
}
+
+
/*-------------------------------------------------------------------*
* swb_bwe_gain_deq()
*
@@ -910,18 +883,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class
*
* SWB BWE decoder
*-------------------------------------------------------------------*/
-Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/
-#ifdef ADD_IVAS_BWE
- const Word16 output[], /* i : suntehsis @ internal Fs */
-#endif
- Decoder_State *st_fx, /* i/o: decoder state structure */
- Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */
- Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
-#ifdef ADD_IVAS_BWE
- const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
-#endif
- const Word16 output_frame /* i : frame length */
- ,
+Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/
+ Decoder_State *st_fx, /* i/o: decoder state structure */
+ Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */
+ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
+ const Word16 output_frame, /* i : frame length */
Word16 *Qpost )
{
Word16 i, l_subfr;
@@ -957,19 +923,7 @@ Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/
/* windowing of the ACELP core synthesis */
new_input_fx_exp = *Qpost;
move16();
-#ifdef ADD_IVAS_BWE
- if ( st->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft )
- {
- /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */
- /* IVAS_fmToDo: delay output[] by 1.25ms ? */
- lerp( output, ysynthIfx, L_FRAME16k, st_fx->L_frame );
- wtda_fx( ysynth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx,
- &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k );
- direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, /*st->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode );
- }
- else
-#endif
{
wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx,
&hBWE_FD->old_wtda_swb_fx_exp,
@@ -1112,12 +1066,7 @@ Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/
}
fb_band_begin = FB_BAND_BEGIN;
move16();
-#ifdef ADD_IVAS_BWE
- IF( st_fx->L_frame == L_FRAME )
- {
- fb_band_begin = FB_BAND_BEGIN_12k8;
- }
-#endif
+
FOR( i = fb_band_begin; i < add( fb_band_begin, DE_OFFSET1 ); i++ )
{
tmp = sub( 32767, i_mult( j, 1024 ) );
@@ -1193,14 +1142,7 @@ Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/
move16();
}
}
-#ifdef ADD_IVAS_BWE
- test();
- IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
- {
- /* add HB synth from hf_synth() */
- v_add( hb_synth, synth, hb_synth, output_frame );
- }
-#endif
+
hBWE_FD->prev_frica_flag = frica_flag;
move16();
hBWE_FD->prev_mode = mode;
@@ -1223,7 +1165,7 @@ void fd_bwe_dec_init(
{
hBWE_FD->old_wtda_wb_fx_exp = 0;
move16();
- set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) );
+ set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k );
hBWE_FD->old_wtda_swb_fx_exp = 0;
move16();
@@ -1266,3 +1208,371 @@ void fd_bwe_dec_init(
return;
}
+
+/*-------------------------------------------------------------------*
+ * WB_BWE_gain_deq()
+ *
+ * Decoding of WB parameters
+ *-------------------------------------------------------------------*/
+
+
+Word16 swb_bwe_dec_fx32(
+ Decoder_State *st_fx, /* i/o: decoder state structure */
+ Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */
+ Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */
+ Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */
+ Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
+ Word16 output_frame /* i : frame length */
+)
+{
+ Word16 L;
+ Word16 mode;
+ Word16 idxGain;
+ Word16 i, j, l_subfr;
+ Word16 fb_band_begin;
+ Word16 frica_flag = 0;
+ move16();
+ Word16 ener_adjust_quan_fx;
+ Word16 fb_ener_adjust_fx = 0;
+ move16();
+ Word16 scl, new_input_fx_exp, ysynth_frame_size;
+ Word16 Q_syn, Q_syn_hb, tmp, tmp2, q_tmp, Qsynth_fx16;
+
+ Word16 ysynth_fx[L_FRAME48k];
+ Word16 SWB_fenv_fx[SWB_FENV];
+ Word16 SWB_tenv_fx[SWB_TENV];
+ Word16 synth_fx16[L_FRAME48k];
+ Word16 hb_synth_fx16[L_FRAME48k];
+
+ Word32 L_tmp;
+ Word32 yerror_fx[L_FRAME48k];
+ Word32 ysynth_fx32[L_FRAME48k];
+ Word32 SWB_tenv_tmp_fx[SWB_TENV];
+ Word32 wtda_synth_fx[2 * L_FRAME48k];
+
+ FD_BWE_DEC_HANDLE hBWE_FD;
+ hBWE_FD = st_fx->hBWE_FD;
+
+ /*---------------------------------------------------------------------*
+ * SWB BWE decoding
+ *---------------------------------------------------------------------*/
+ test();
+ IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
+ {
+ /* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */
+ /* todo - delay output[] by 1.25ms ? */
+ L_lerp_fx_q11( output_fx, ysynth_fx32, L_FRAME16k, st_fx->L_frame );
+
+ /* windowing of the ACELP core synthesis */
+ wtda_fx32( ysynth_fx32, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, /*st_fx->L_frame*/ L_FRAME16k );
+
+ /* DCT of the ACELP core synthesis */
+ new_input_fx_exp = 11;
+ move16();
+ direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, /*st_fx->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode );
+ ysynth_frame_size = L_FRAME16k;
+ move16();
+ }
+ ELSE
+ {
+ /* windowing of the ACELP core synthesis */
+ wtda_fx32( synth_fx, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, output_frame );
+
+ /* DCT of the ACELP core synthesis */
+ new_input_fx_exp = 11;
+ move16();
+ direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode );
+ ysynth_frame_size = output_frame;
+ move16();
+ }
+
+ /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */
+ scl = sub( 16 + 11, new_input_fx_exp );
+ /* Possible to Upscale? */
+ IF( scl > 0 )
+ {
+ /* Yes */
+ /* Calc Room to Upscale */
+ Q_syn = sub( Find_Max_Norm32( ysynth_fx32, ysynth_frame_size ), 3 );
+ /* Stay within MAX_Q_NEW_INPUT */
+ scl = s_min( Q_syn, scl );
+ }
+ /*Don't upscale if already in 15 bits*/
+ IF( GT_16( scl, 15 ) )
+ {
+ FOR( i = 0; i < ysynth_frame_size; i++ )
+ {
+ ysynth_fx[i] = extract_l( ysynth_fx32[i] );
+ move16();
+ }
+ Q_syn = new_input_fx_exp;
+ move16();
+ }
+ ELSE
+ {
+ Copy_Scale_sig32_16( ysynth_fx32, ysynth_fx, ysynth_frame_size, scl );
+ Q_syn = add( sub( new_input_fx_exp, 16 ), scl );
+ }
+
+ IF( !st_fx->bfi )
+ {
+ IF( st_fx->bws_cnt > 0 )
+ {
+ /* estimate parameters */
+ mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn );
+ }
+ ELSE
+ {
+ /* de-quantization */
+ mode = swb_bwe_gain_deq_fx( st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 );
+ }
+
+ L = SWB_FENV;
+ move16();
+ if ( EQ_16( mode, TRANSIENT ) )
+ {
+ L = SWB_FENV_TRANS;
+ move16();
+ }
+
+ L_tmp = 0;
+ move32();
+ FOR( i = 0; i < L; i++ )
+ {
+ L_tmp = L_add( L_tmp, L_deposit_l( SWB_fenv_fx[i] ) );
+ }
+ q_tmp = norm_s( L );
+ tmp = div_s( shl( 1, sub( 14, q_tmp ) ), L ); /*Q(29-q_tmp) */
+ L_tmp = Mpy_32_16_1( L_tmp, tmp ); /*Q(1+29-q_tmp+1-16)->Q(15-q_tmp) */
+ st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, add( q_tmp, 2 ) ) ); /*Q1 */
+ move16();
+ }
+ ELSE
+ {
+ /* SHB FEC */
+
+ IF( NE_16( hBWE_FD->prev_mode, TRANSIENT ) )
+ {
+ mode = hBWE_FD->prev_mode;
+ move16();
+ }
+ ELSE
+ {
+ mode = NORMAL;
+ move16();
+ }
+
+ Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV );
+ }
+
+ /* reconstruction of MDCT spectrum of the error signal */
+ set32_fx( yerror_fx, 0, output_frame );
+
+ IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
+ {
+ SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl );
+ }
+ ELSE
+ {
+ SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl );
+ }
+
+ test();
+ IF( EQ_16( hBWE_FD->prev_frica_flag, 1 ) && frica_flag == 0 )
+ {
+ FOR( i = 0; i < L_SUBFR; i++ )
+ {
+ tmp = sub( 32767, extract_l( L_mult0( i, 512 ) ) ); /*Q15 */
+ hBWE_FD->mem_imdct_fx[i] = mult_r( hBWE_FD->mem_imdct_fx[i], tmp );
+ move16();
+ }
+
+ FOR( ; i < output_frame; i++ )
+ {
+ hBWE_FD->mem_imdct_fx[i] = 0;
+ move16();
+ }
+ }
+
+ /* decode information */
+ IF( EQ_16( st_fx->extl, FB_BWE ) )
+ {
+ IF( !st_fx->bfi )
+ {
+ idxGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_FB_FRAMEGAIN );
+ fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */
+ }
+ ELSE IF( st_fx->bfi )
+ {
+ fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx;
+ move16();
+ }
+
+ st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx;
+ move16();
+ IF( EQ_16( mode, TRANSIENT ) )
+ {
+ ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 );
+ }
+ ELSE
+ {
+ IF( SWB_fenv_fx[7] != 0 )
+ {
+ tmp = div_s( 1, SWB_fenv_fx[7] );
+ ener_adjust_quan_fx = s_min( shr( i_mult_sat( SWB_fenv_fx[13], tmp ), 2 ), 32767 );
+ }
+ ELSE
+ {
+ ener_adjust_quan_fx = 0;
+ move16();
+ }
+ }
+
+ fb_band_begin = FB_BAND_BEGIN;
+ move16();
+ if ( EQ_16( st_fx->L_frame, L_FRAME ) )
+ {
+ fb_band_begin = FB_BAND_BEGIN_12k8;
+ move16();
+ }
+
+ j = 0;
+ move16();
+ FOR( i = fb_band_begin; i < add( fb_band_begin, DE_OFFSET1 ); i++ )
+ {
+ tmp = sub( 32767, i_mult( j, 1024 ) );
+ tmp = mult_r( tmp, ener_adjust_quan_fx ); /*Q13*/
+
+ tmp2 = i_mult( j, 256 ); /*Q13*/
+ tmp2 = mult_r( tmp2, fb_ener_adjust_fx ); /*Q13*/
+
+ tmp = add( tmp, tmp2 ); /*Q13*/
+ yerror_fx[i] = L_shl( Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], tmp ), 2 ); /*15+Q_syn */
+ move32();
+ j = add( j, 1 );
+ }
+ FOR( ; i < FB_BAND_END; i++ )
+ {
+ yerror_fx[i] = Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], fb_ener_adjust_fx ); /*15+Q_syn */
+ move32();
+ }
+ }
+
+ /* iDCT of the error signal */
+ Q_syn_hb = add( Q_syn, 15 );
+ Inverse_Transform( yerror_fx, &Q_syn_hb, wtda_synth_fx, 0, output_frame, -1, st_fx->element_mode );
+
+ /* inverse windowing of the error signal */
+ window_ola_fx( wtda_synth_fx, hb_synth_fx16, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 );
+ l_subfr = mult( output_frame, 8192 );
+
+ test();
+ IF( EQ_16( mode, TRANSIENT ) )
+ {
+ FOR( i = 0; i < SWB_TENV; i++ )
+ {
+ SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i] /*Q0*/, 26214 /*0.8f Q15*/ ); // Q15
+ move32();
+ }
+
+ /* time envelope shaping when the current frame is TRANSIENT frame */
+ time_envelop_shaping_ivas_fx( hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb );
+
+ Q_syn_hb = sub( Q_syn_hb, 3 );
+
+ hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3];
+ move16();
+ }
+ ELSE IF( EQ_16( frica_flag, 1 ) && hBWE_FD->prev_frica_flag == 0 )
+ {
+ Qsynth_fx16 = Find_Max_Norm32( synth_fx, output_frame );
+ Qsynth_fx16 = sub( Qsynth_fx16, shr( add( sub( 15, norm_s( l_subfr ) ), 1 ), 1 ) );
+ Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 );
+ Qsynth_fx16 = add( 11 - 16, Qsynth_fx16 );
+
+ /* IVAS_fmToDo: synth[] is @internal_Fs!!! */
+ time_reduce_pre_echo_fx( synth_fx16, hb_synth_fx16, hBWE_FD->prev_td_energy_fx, l_subfr, Qsynth_fx16, Q_syn_hb );
+ }
+ ELSE
+ {
+ tmp = i_mult2( 3, l_subfr );
+ L_tmp = L_deposit_l( 0 );
+
+ FOR( i = 0; i < l_subfr; i++ )
+ {
+ L_tmp = L_mac0_sat( L_tmp, hb_synth_fx16[add( tmp, i )], hb_synth_fx16[add( tmp, i )] ); /*(2*Q_syn_hb) */
+ }
+
+ L_tmp = Mult_32_16( L_tmp, div_s( 1, l_subfr ) ); /*(2*Q_syn_hb) */
+ hBWE_FD->prev_td_energy_fx = 0;
+ move16();
+
+ IF( L_tmp != 0 )
+ {
+ q_tmp = norm_l( L_tmp );
+ tmp = extract_h( L_shl( L_tmp, q_tmp ) );
+ q_tmp = sub( q_tmp, sub( 30, shl( Q_syn_hb, 1 ) ) );
+
+ tmp = div_s( 16384, tmp );
+ L_tmp = L_deposit_h( tmp );
+ L_tmp = Isqrt_lc( L_tmp, &q_tmp ); /*Q(31-exp) */
+ hBWE_FD->prev_td_energy_fx = round_fx( L_shl( L_tmp, sub( q_tmp, 15 ) ) ); /*Q0 */
+ move16();
+ }
+ }
+
+ test();
+ IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
+ {
+ Qsynth_fx16 = add( 16 - 11, Q_syn_hb );
+ Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 );
+
+ /* add HB synth from hf_synth() */
+ v_add_16( hb_synth_fx16, synth_fx16, hb_synth_fx16, output_frame );
+ }
+
+ hBWE_FD->prev_mode = mode;
+ move16();
+ hBWE_FD->prev_frica_flag = frica_flag;
+ move16();
+
+ FOR( i = 0; i < output_frame; i++ )
+ {
+ hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); // Q_syn_hb
+ move32();
+ }
+
+ return Q_syn_hb;
+}
+
+
+void fd_bwe_dec_init_fx(
+ FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */
+)
+{
+ set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k );
+ set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) );
+ hBWE_FD->prev_mode = NORMAL;
+ move16();
+ hBWE_FD->prev_Energy_fx = 0;
+ move16();
+ hBWE_FD->prev_L_swb_norm = 8;
+ move16();
+ hBWE_FD->Seed = 21211;
+ move16();
+ hBWE_FD->prev_frica_flag = 0;
+ move16();
+ set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k );
+ hBWE_FD->prev_td_energy_fx = 0;
+ move16();
+ hBWE_FD->prev_weight_fx = 0;
+ move16();
+ hBWE_FD->prev_flag = 0;
+ move16();
+ hBWE_FD->prev_Energy_wb_fx = 0;
+ move32();
+ hBWE_FD->mem_deemph_old_syn_fx = 0;
+ move16();
+
+ return;
+}
diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c
deleted file mode 100644
index 80dfad505c3822d91ca395323cbeb6a8b7e00e8e..0000000000000000000000000000000000000000
--- a/lib_dec/swb_tbe_dec.c
+++ /dev/null
@@ -1,2478 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "prot.h"
-#include "prot_fx.h"
-#include "rom_com.h"
-#include "rom_dec.h"
-#include "wmc_auto.h"
-#include "ivas_prot.h"
-#include "ivas_prot_fx.h"
-
-/*-----------------------------------------------------------------*
- * Local function prototypes
- *-----------------------------------------------------------------*/
-
-
-void find_max_mem_dec_m3(
- Decoder_State *st,
- Word16 *n_mem3 );
-
-/*-------------------------------------------------------------------*
- * ResetSHBbuffer_Dec()
- *
- *
- *-------------------------------------------------------------------*/
-
-static void calc_tilt_bwe_fx_loc(
- const Word32 *sp_fx, /* i : input signal : Q11 */
- Word32 *tilt_fx, /* o : signal tilt : tilt_fx_q */
- Word16 *tilt_fx_q, /* o : signal tilt */
- const Word16 N /* i : signal length : Q0 */
-)
-{
- Word16 i;
- Word64 r0_fx, r1_fx;
-
- r0_fx = EPSILON_FX_SMALL;
- move64();
- FOR( i = 0; i < N; i++ )
- {
- r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); /*Q11*2 - 1*/
- }
- r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); /*Q11*/
- FOR( i = 2; i < N; i++ )
- {
- IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ) /*Q11*/, L_sub( sp_fx[i - 1], sp_fx[i - 2] ) /*Q11*/ ) /*Q11 * 2 - 1*/ < 0 )
- {
- r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); /*Q11*/
- }
- }
- Word16 headroom_left_r0 = W_norm( r0_fx );
- Word16 headroom_left_r1 = W_norm( r1_fx );
- Word16 r0_q = 0, r1_q = 0;
- move16();
- move16();
- IF( LT_16( headroom_left_r0, 32 ) )
- {
- r0_fx = W_shr( r0_fx, sub( 32, headroom_left_r0 ) );
- r0_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_r0 ) ) );
- }
- ELSE
- {
- r0_q = 31 - ( 2 * OUTPUT_Q );
- move16();
- }
-
- IF( LT_16( headroom_left_r1, 32 ) )
- {
- r1_fx = W_shr( r1_fx, sub( 32, headroom_left_r1 ) );
- r1_q = sub( OUTPUT_Q, sub( 32, headroom_left_r1 ) );
- }
- ELSE
- {
- r1_q = OUTPUT_Q;
- move16();
- }
- Word32 temp_r0_inv = ISqrt32( W_extract_l( r0_fx ), &r0_q );
- Word32 res = Mpy_32_32( W_extract_l( r1_fx ), temp_r0_inv );
- // Word16 res_q = r1_q + ( r0_q < 0 ? ( 31 + ( -1 * r0_q ) ) : r0_q ) - 31;
- Word16 res_q;
- IF( r0_q < 0 )
- {
- res_q = add( r1_q, sub( add( 31, -r0_q ), 31 ) );
- }
- ELSE
- {
- res_q = add( r1_q, sub( r0_q, 31 ) );
- }
- Word16 norm_res = norm_l( res );
- IF( norm_res > 0 )
- {
- *tilt_fx = L_shl_sat( res, norm_res );
- move32();
- *tilt_fx_q = add( res_q, norm_res );
- move16();
- }
- ELSE
- {
- *tilt_fx = res;
- move32();
- *tilt_fx_q = res_q;
- move16();
- }
- return;
-}
-
-/*-------------------------------------------------------------------*
- * swb_tbe_dec()
- *
- * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module
- *-------------------------------------------------------------------*/
-static void rescale_genSHB_mem_dec(
- Decoder_State *st_fx,
- Word16 sf /*Q0*/
-)
-{
- Word16 i;
- TD_BWE_DEC_HANDLE hBWE_TD;
- hBWE_TD = st_fx->hBWE_TD;
-
- FOR( i = 0; i < NL_BUFF_OFFSET; i++ )
- {
- hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf );
- move16();
- }
-
- FOR( i = 0; i < 7; i++ )
- {
- hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf );
- move16();
- }
-
- /* -- Apply memory scaling for 13.2 and 16.4k bps using sf ----*/
- IF( LT_32( st_fx->total_brate, ACELP_24k40 ) )
- {
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf );
- move16();
- }
-
- FOR( i = 0; i < L_SHB_LAHEAD; i++ )
- {
- hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf );
- move16();
- }
- }
-
- hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf );
- move32();
-
- hBWE_TD->tbe_demph_fx = shl_r( hBWE_TD->tbe_demph_fx, sf );
- move16();
- hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf );
- move16();
-}
-
-static void gradientGainShape(
- Decoder_State *st_fx,
- Word16 *GainShape_fx, /*Q15*/
- Word32 *GainFrame_fx /* Q18 */ )
-{
- Word16 i, j, tmp;
- Word16 GainShapeTemp[NUM_SHB_SUBFR / 4];
- Word16 GainGrad0[3];
- Word16 GainGrad1[3];
- Word16 GainGradFEC[4];
- TD_BWE_DEC_HANDLE hBWE_TD;
- hBWE_TD = st_fx->hBWE_TD;
-
-
- /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */
- FOR( j = 0; j < 3; j++ )
- {
- GainGrad0[j] = sub( shr( st_fx->GainShape_Delay[j + 1], 1 ), shr( st_fx->GainShape_Delay[j], 1 ) );
- move16(); /* Q14 */
- GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) );
- move16(); /* Q14 */
- GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 /*0.4f in Q15*/ ), mult_r( GainGrad1[j], 19660 /*0.6f in Q15*/ ) );
- move16(); /* Q14 */
- }
-
- /* gradient for the first gainshape */
- test();
- test();
- test();
- IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ||
- ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) )
- {
- GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 /*0.1f in Q15*/ ), mult_r( GainGrad1[2], 29490 /*0.9f in Q15*/ ) );
- move16(); /* Q14 */
- }
- ELSE
- {
- GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 /*0.2f in Q15*/ ), mult_r( GainGrad1[1], 9830 /*0.3f in Q15*/ ) );
- move16();
- GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 /*0.5f in Q15*/ ) );
- move16(); /* Q14 */
- }
-
- /* get the first gainshape template */
- test();
- test();
- IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && ( GainGradFEC[0] > 0 ) )
- {
- GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), GainGradFEC[0] );
- move16();
- }
- ELSE IF( GainGradFEC[0] > 0 )
- {
- GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 /*0.5f in Q15*/ ) );
- move16(); /* Q14 */
- }
- ELSE
- {
- GainShapeTemp[0] = shr( st_fx->GainShape_Delay[7], 1 );
- move16(); /* Q14 */
- }
-
- /*Get the second the third and the fourth gainshape template*/
-
- tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */
- tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */
-
- test();
- IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] > 0 ) )
- {
- FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ )
- {
- GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 /*0.8f in Q15*/ ) );
- move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */
- GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ );
- move16();
- }
- }
- ELSE
- {
- test();
- IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] < 0 ) )
- {
- FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ )
- {
- GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 /*0.2f in Q15*/ ) );
- move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */
- GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ );
- move16(); /* Q14 */
- }
- }
- ELSE
- {
- FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ )
- {
- GainShapeTemp[i] = add( GainShapeTemp[i - 1], GainGradFEC[i] );
- move16();
- GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ );
- move16();
- }
- }
- }
-
- /* Get the gainshape and gain frame for the current frame*/
- test();
- test();
- test();
- IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) )
- {
- FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
- {
- FOR( j = 0; j < 4; j++ )
- {
- tmp = mult_r( GainShapeTemp[i], 19660 /*0.6f Q15*/ ); /* GainShapeTemp[i]*0.6 */
-
- IF( GT_16( 8192, tmp ) )
- {
- GainShape_fx[i * 4 + j] = shl( tmp, 2 ); /*Q15*/
- move16(); /* (GainShapeTemp[i]*0.6)>>1 */
- }
- ELSE
- {
- GainShape_fx[i * 4 + j] = 32767; /*Q15*/
- move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */
- }
- }
- }
- hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 );
- move16();
- }
- ELSE IF( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) )
- {
- FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
- {
- FOR( j = 0; j < 4; j++ )
- {
- IF( LT_16( GainShapeTemp[i], 16384 ) )
- {
- GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/
- move16();
- }
- ELSE
- {
- GainShape_fx[i * 4 + j] = 32767; // 1.0f in Q15
- move16();
- }
- }
- }
- hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 /*0.95f in Q15*/ ); /*Q15*/
- move16();
- }
- ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) )
- {
- FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
- {
- FOR( j = 0; j < 4; j++ )
- {
- GainShape_fx[i * 4 + j] = GainShapeTemp[i]; /*Q15*/
- move16();
- }
- }
- hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 /*0.5f in Q15*/ ); /*Q15*/
- move16();
- }
- ELSE
- {
- FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
- {
- FOR( j = 0; j < 4; j++ )
- {
- IF( LT_16( GainShapeTemp[i], 16384 ) )
- {
- GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/
- move16();
- }
- ELSE
- {
- GainShape_fx[i * 4 + j] = 32767; /*Q15*/
- move16();
- }
- }
- }
- hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 /*0.85f in Q15*/ ); /*Q15*/
- move16();
- }
-
- *GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */
- move32();
-}
-
-static void find_max_mem_dec(
- Decoder_State *st_fx,
- Word16 *n_mem,
- Word16 *n_mem2,
- Word16 *n_mem3 )
-{
- Word16 i;
- Word16 n_mem_32;
- Word16 max = 0;
- move16();
- Word32 Lmax = 0;
- move32();
- Word16 tempQ15, max2 = 0;
- move16();
- Word16 max3;
- Word32 tempQ32, Lmax3;
- TD_BWE_DEC_HANDLE hBWE_TD;
- hBWE_TD = st_fx->hBWE_TD;
-
- /* old BWE exc max */
- FOR( i = 0; i < NL_BUFF_OFFSET; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] );
- max = s_max( max, tempQ15 );
- }
-
- /* decimate all-pass steep memory */
- FOR( i = 0; i < 7; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] );
- max = s_max( max, tempQ15 );
- }
-
- /* -- keep norm of state_lpc_syn_fx, state_syn_shbexc_fx,
- and mem_stp_swb_fx separately for 24.4 and 32kbps ----*/
- /* findMaxMem2() inside tbe com */
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->state_lpc_syn_fx[i] );
- max2 = s_max( max2, tempQ15 );
- }
-
- /* findMaxMem2() inside tbe com */
- FOR( i = 0; i < L_SHB_LAHEAD; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->state_syn_shbexc_fx[i] );
- max2 = s_max( max2, tempQ15 );
- }
-
- /* findMaxMem2() inside tbe com */
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->mem_stp_swb_fx[i] );
- max2 = s_max( max2, tempQ15 );
- }
-
- /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */
- *n_mem2 = norm_s( max2 );
- move16();
- if ( max2 == 0 )
- {
- *n_mem2 = 15;
- move16();
- }
-
- if ( LT_32( st_fx->total_brate, ACELP_24k40 ) )
- {
- max = s_max( max, max2 );
- }
-
- /* de-emph and pre-emph memory */
- tempQ15 = abs_s( hBWE_TD->tbe_demph_fx );
- max = s_max( max, tempQ15 );
-
- tempQ15 = abs_s( hBWE_TD->tbe_premph_fx );
- max = s_max( max, tempQ15 );
-
- IF( EQ_16( st_fx->extl, FB_TBE ) )
- {
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->fb_state_lpc_syn_fx[i] );
- max = s_max( max, tempQ15 );
- }
- /* FB de-emph memory */
- tempQ15 = abs_s( hBWE_TD->fb_tbe_demph_fx );
- max = s_max( max, tempQ15 );
- }
- /* estimate the norm for 16-bit memories */
- *n_mem = norm_s( max );
- move16();
- if ( max == 0 )
- {
- *n_mem = 15;
- move16();
- }
-
- /* estimate the norm for 32-bit memories */
- Lmax = L_abs( hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */
-
- n_mem_32 = norm_l( Lmax );
- if ( Lmax == 0 )
- {
- n_mem_32 = 31;
- move16();
- }
-
- tempQ15 = sub( s_min( *n_mem, n_mem_32 ), 1 );
- *n_mem = s_max( tempQ15, 0 );
- move16();
-
- /* --------------------------------------------------------------*/
- /* Find headroom for synthesis stage associated with these memories:
- 1. st_fx->syn_overlap_fx
- 2. st_fx->genSHBsynth_state_lsyn_filt_shb_local
- 3. st_fx->genSHBsynth_Hilbert_Mem_fx (32-bit) */
- max3 = 0;
- move16();
- /* find max in prev overlapSyn */
- FOR( i = 0; i < L_SHB_LAHEAD; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->syn_overlap_fx[i] );
- max3 = s_max( max3, tempQ15 );
- }
- /* find max in prev genSHBsynth_state_lsyn_filt_shb_local_fx */
- FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] );
- max3 = s_max( max3, tempQ15 );
- }
- /* find max in prev int_3_over_2_tbemem_dec_fx */
- IF( EQ_32( st_fx->output_Fs, 48000 ) )
- {
- FOR( i = 0; i < INTERP_3_2_MEM_LEN; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->int_3_over_2_tbemem_dec_fx[i] );
- max3 = s_max( max3, tempQ15 );
- }
- }
- IF( EQ_32( st_fx->output_Fs, 16000 ) )
- {
- FOR( i = 0; i < ( 2 * ALLPASSSECTIONS_STEEP + 1 ); i++ )
- {
- tempQ15 = abs_s( hBWE_TD->mem_resamp_HB_32k_fx[i] );
- max3 = s_max( max3, tempQ15 );
- }
- }
- /* estimate the norm for 16-bit memories */
- *n_mem3 = norm_s( max3 );
- move16();
- if ( max3 == 0 )
- {
- *n_mem3 = 15;
- move16();
- }
-
- Lmax3 = 0;
- move32();
- IF( EQ_16( st_fx->L_frame, L_FRAME ) )
- {
- /* find max in prev genSHBsynth_Hilbert_Mem_fx */
- FOR( i = 0; i < HILBERT_MEM_SIZE; i++ )
- {
- tempQ32 = L_abs( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] );
- Lmax3 = L_max( Lmax3, tempQ32 );
- }
- }
-
- /* estimate the norm for 32-bit memories */
- n_mem_32 = norm_l( Lmax3 );
- if ( Lmax3 == 0 )
- {
- n_mem_32 = 31;
- move16();
- }
-
- tempQ15 = sub( s_min( *n_mem3, n_mem_32 ), 2 ); /* very important leave at least 2 bit head room
- because of the Hilber transform and Q14 coeffs */
- *n_mem3 = s_max( tempQ15, 0 );
- move16();
- /* --------------------------------------------------------------*/
-}
-
-void find_max_mem_dec_m3(
- Decoder_State *st,
- Word16 *n_mem3 )
-{
- Word16 i;
- // Word16 n_mem_32;
- Word16 tempQ15;
- Word16 max3;
- // Word32 tempQ32, Lmax3;
- TD_BWE_DEC_HANDLE hBWE_TD;
- hBWE_TD = st->hBWE_TD;
-
- /* --------------------------------------------------------------*/
- /* Find headroom for synthesis stage associated with these memories:
- 1. st->syn_overlap_fx*/
- max3 = 0;
- move16();
- /* find max in prev overlapSyn */
- FOR( i = 0; i < L_SHB_LAHEAD; i++ )
- {
- tempQ15 = abs_s( hBWE_TD->syn_overlap_fx[i] );
- max3 = s_max( max3, tempQ15 );
- }
- /* find max in prev genSHBsynth_state_lsyn_filt_shb_local_fx */
-
- /* estimate the norm for 16-bit memories */
- *n_mem3 = norm_s( max3 );
- move16();
- if ( max3 == 0 )
- {
- *n_mem3 = 15;
- move16();
- }
-}
-
-/*-------------------------------------------------------------------*
- * ivas_swb_tbe_dec_fx()
- *
- * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module
- *-------------------------------------------------------------------*/
-void ivas_swb_tbe_dec_fx(
- Decoder_State *st, /* i/o: decoder state structure */
- STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */
- const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */
- Word16 Q_exc,
- const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */
- const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */
- Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/
- Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */
- Word16 *pitch_buf_fx, /* i : Q6 */
- Word16 *Q_white_exc )
-{
- Word16 i, j, cnt, n;
- Word16 stemp;
- TD_BWE_DEC_HANDLE hBWE_TD;
- Word32 shaped_shb_excitation_fx_32[L_FRAME16k + L_SHB_LAHEAD];
- Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET];
- Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD];
- Word16 lsf_shb_fx[LPC_SHB_ORDER], lpc_shb_fx[LPC_SHB_ORDER + 1], GainShape_fx[NUM_SHB_SUBFR]; // Q12,Q12,Q15
- Word32 GainFrame_fx; // Q18
- Word32 error_fx[L_FRAME32k];
- Word16 ener_fx;
- Word32 L_ener;
- Word16 is_fractive;
- Word32 prev_pow_fx, curr_pow_fx, Lscale;
- Word16 scale_fx;
- Word16 max_val, temp_fx, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD];
- Word32 curr_frame_pow_fx;
- Word16 curr_frame_pow_exp;
- Word32 L_prev_ener_shb;
- Word16 vf_modified_fx[NB_SUBFR16k];
- Word16 f_fx, inc_fx;
- Word32 GainFrame_prevfrm_fx;
- Word32 tilt_swb_fec_32_fx;
- Word16 tilt_swb_fec_fx_q;
- Word16 tilt_swb_fec_fx;
- Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */
- Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER];
- Word16 lpc_shb_sf_fx[4 * ( LPC_SHB_ORDER + 1 )];
- const Word16 *ptr_lsp_interp_coef_fx;
- Word32 shb_ener_sf_32;
- Word16 shb_res_gshape_fx[NB_SUBFR16k];
- Word16 mixFactors_fx;
- Word16 vind;
- Word16 shb_res_dummy_fx[L_FRAME16k];
- Word16 shaped_shb_excitationTemp_fx[L_FRAME16k];
- Word32 ener_tmp_fx[NUM_SHB_SUBGAINS];
- Word16 GainShape_tmp_fx[NUM_SHB_SUBGAINS];
- Word16 pitch_fx;
- Word16 l_subframe;
- Word16 formant_fac_fx;
- Word16 synth_scale_fx;
- Word16 lsf_diff_fx[LPC_SHB_ORDER], w_fx[LPC_SHB_ORDER];
- Word16 refl_fx[M];
- Word16 tilt_para_fx;
- Word16 *nlExc16k_fx, *mixExc16k_fx;
- Word16 MSFlag;
- Word16 feedback_fx;
- Word16 GainShape_tilt_fx;
-
- // scaling
- Word16 exp, tmp;
- Word16 tmp1, tmp2;
- Word16 mean_vf;
- Word32 Lmax, L_tmp;
- Word16 frac;
- Word32 L_tmp1, L_tmp2;
- Word16 Q_bwe_exc;
- Word16 Q_bwe_exc_fb;
- Word16 Q_shb;
- Word16 n_mem, n_mem2, n_mem3, Qx, sc;
- Word16 expa, expb;
- Word16 fraca, fracb;
- Word16 exp_ener, inv_ener;
-
- hBWE_TD = st->hBWE_TD;
-
- /* initializations */
- GainFrame_fx = 0;
- move32();
- mixFactors_fx = 0;
- move16();
- shb_ener_sf_32 = 0;
- move32();
- set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k );
- if ( st->hTdCngDec != NULL )
- {
- st->hTdCngDec->shb_dtx_count = 0;
- move16();
- }
- is_fractive = 0;
- move16();
-
- IF( hStereoICBWE != NULL )
- {
- nlExc16k_fx = hStereoICBWE->nlExc16k_fx;
- mixExc16k_fx = hStereoICBWE->mixExc16k_fx;
- MSFlag = hStereoICBWE->MSFlag;
- move16();
- }
- ELSE
- {
- nlExc16k_fx = NULL;
- mixExc16k_fx = NULL;
- MSFlag = 0;
- move16();
- }
-
- /* find tilt */
- calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME );
- tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) );
- test();
- if ( st->bfi && st->clas_dec != UNVOICED_CLAS )
- {
- tilt_swb_fec_fx = hBWE_TD->tilt_swb_fec_fx;
- move16();
- }
-
- /* WB/SWB bandwidth switching */
- test();
- test();
- IF( ( GT_16( st->tilt_wb_fx, 10240 /*5 in Q11*/ ) && ( EQ_16( st->clas_dec, UNVOICED_CLAS ) ) ) || GT_16( st->tilt_wb_fx, 20480 /*10 in Q11*/ ) )
- {
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( ( st->prev_fractive == 0 ) &&
- ( LT_32( st->prev_enerLH_fx, L_shl( st->enerLH_fx, 1 ) ) && GT_32( st->prev_enerLH_fx, L_shr( st->enerLH_fx, 1 ) ) && LT_32( st->prev_enerLL_fx, L_shl( st->enerLL_fx, 1 ) ) && GT_32( st->prev_enerLL_fx, L_shr( st->enerLL_fx, 1 ) ) ) ) ||
- ( EQ_16( st->prev_fractive, 1 ) &&
- GT_32( L_shr( st->prev_enerLH_fx, 2 ), Mult_32_16( st->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/
- || ( GT_32( L_shr( st->enerLL_fx, 1 ), Mult_32_16( st->enerLH_fx, 24576 ) ) && /*24576 = 1.5 in Q14*/
- LT_16( st->tilt_wb_fx, 20480 ) ) /* 20480 = 10 in Q11*/
- )
- {
- is_fractive = 0;
- }
- ELSE
- {
- is_fractive = 1;
- }
- move16();
- }
-
- /* WB/SWB bandwidth switching */
- IF( st->bws_cnt > 0 )
- {
- f_fx = 1489; /*1.0f / 22.0f in Q15*/
- move16();
- inc_fx = 1489; /*1.0f / 22.0f in Q15*/
- move16();
-
- IF( EQ_16( is_fractive, 1 ) )
- {
- Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER );
- }
- ELSE
- {
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/
- move16();
- f_fx = add( f_fx, inc_fx ); /*Q15*/
- }
- }
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && !( ( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 ) && L_sub( st->prev_enerLH_fx, ( L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) ) || st->last_core != ACELP_CORE || ( ( st->last_core == ACELP_CORE ) && GT_32( abs( L_sub( st->last_core_brate, st->core_brate ) ), 3600 ) ) || EQ_16( s_xor( is_fractive, st->prev_fractive ), 1 ) )
- {
- set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); /*0.3536f in Q15*/
- }
- ELSE
- {
- if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) /*0.3536f in Q15*/
- {
- hBWE_TD->prev_GainShape_fx = 11587; /*0.3536f in Q15*/
- move16();
- }
- set16_fx( GainShape_fx, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR );
- }
-
- Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER );
- set16_fx( shb_res_gshape_fx, 3277 /*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */
- }
- ELSE
- {
- test();
- IF( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) )
- {
- f_fx = 1489; /*Q15*/
- move16();
- inc_fx = 1489; /*Q15*/
- move16();
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/
- move16();
- f_fx = add( f_fx, inc_fx );
- }
- }
-
- IF( !st->bfi )
- {
- IF( st->use_partial_copy )
- {
- IF( NE_16( st->last_extl, SWB_TBE ) )
- {
- hBWE_TD->GainFrame_prevfrm_fx = 0;
- move32();
- f_fx = 1489 /*0.045454f Q15*/;
- move16();
- inc_fx = 1489 /*0.045454f Q15*/;
- move16();
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/
- move16();
- f_fx = add( f_fx, inc_fx ); /*Q15*/
- }
- }
- Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER );
- set16_fx( GainShape_fx, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR );
-
- IF( EQ_16( st->rf_frame_type, RF_NELP ) )
- {
- /* Frame gain */
-
- GainFrame_fx = L_mac( SHB_GAIN_QLOW_FX, st->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX );
- L_tmp = Mult_32_16( GainFrame_fx, 27213 ); /*Q16*/ /* 3.321928 in Q13 */
-
- frac = L_Extract_lc( L_tmp, &exp );
- L_tmp = Pow2( 30, frac );
- GainFrame_fx = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/
-
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && !st->prev_use_partial_copy && EQ_16( st->prev_coder_type, UNVOICED ) && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st->next_coder_type, GENERIC ) && EQ_16( st->last_extl, SWB_TBE ) )
- {
- GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6553 /*0.2f in Q15*/ ) );
- }
- }
- ELSE
- {
- temp_fx = 0;
- move16();
- /* Frame gain */
- SWITCH( st->rf_indx_tbeGainFr )
- {
- case 0:
- GainFrame_fx = 131072; /* 0.5f in Q18 */
- move32();
- if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) )
- {
- temp_fx = 26214 /*0.8 Q15*/;
- move16();
- }
- BREAK;
- case 1:
- GainFrame_fx = 524288; /* 2.0f in Q18 */
- move32();
- test();
- if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) )
- {
- temp_fx = 26214 /*0.8 Q15*/;
- move16();
- }
- BREAK;
- case 2:
- GainFrame_fx = 1048576; /* 4.0f in Q18 */
- move32();
- test();
- if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) )
- {
- temp_fx = 26214 /*0.8 Q15*/;
- move16();
- }
- BREAK;
- case 3:
- GainFrame_fx = 2097152; /* 8.0f in Q18 */
- move32();
- test();
- if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) )
- {
- temp_fx = 26214 /*0.8 Q15*/;
- move16();
- }
- BREAK;
- default:
- fprintf( stderr, "RF SWB-TBE gain bits not supported." );
- }
-
- IF( EQ_16( st->last_extl, SWB_TBE ) )
- {
- GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp_fx ), Mult_32_16( GainFrame_fx, sub( 32767, temp_fx ) ) );
- /*Q18*/
- }
-
- IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) )
- {
- if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 /*8.0f in Q18*/ ) && LT_32( GainFrame_fx, 3059606 /*11.67f in Q18*/ ) )
- {
- GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 /*0.3f in Q15*/ ); // Q18
- }
- }
- }
- }
- ELSE
- {
- /* de-quantization */
- ivas_dequantizeSHBparams_fx_9_1( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp,
- &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag );
- if ( hStereoICBWE != NULL )
- {
- hStereoICBWE->MSFlag = MSFlag;
- move16();
- }
- }
- }
- ELSE
- {
- Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER );
- test();
- IF( EQ_16( st->codec_mode, MODE1 ) && ( st->element_mode == EVS_MONO ) )
- {
- gradientGainShape( st, GainShape_fx, &GainFrame_fx );
- }
- ELSE
- {
- FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
- {
- FOR( j = 0; j < 4; j++ )
- {
- GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] );
- move16();
- }
- }
- IF( GT_16( tilt_swb_fec_fx, ( 8 << 11 ) ) ) /* tilt_swb_fec_fx in Q11 */
- {
- IF( EQ_16( st->nbLostCmpt, 1 ) )
- {
- GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 19661 /*0.6f Q15*/ );
- }
- ELSE IF( EQ_16( st->nbLostCmpt, 2 ) )
- {
- GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 11469 /*0.35f Q15*/ );
- }
- ELSE
- {
- GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 6554 /*0.2f Q15*/ );
- }
- GainFrame_fx = Mult_32_16( GainFrame_fx, st->cummulative_damping );
- }
- ELSE
- {
- GainFrame_fx = hBWE_TD->GainFrame_prevfrm_fx;
- move32(); /* gain locking */
- }
- }
-
- IF( GE_32( st->extl_brate, SWB_TBE_2k8 ) )
- {
- test();
- IF( EQ_16( st->codec_mode, MODE1 ) && ( st->element_mode == EVS_MONO ) )
- {
- L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/
- tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */
- tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/
- i = sub( norm_s( tmp1 ), 1 );
- tmp1 = shl( tmp1, i ); /* Qi */
- IF( tmp == 0 )
- {
- tmp = 32767 /*1.0f Q15*/;
- move16(); /*Q15*/
- }
- ELSE
- {
- scale_fx = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */
- scale_fx = s_max( scale_fx, 0 );
- tmp = shl_sat( scale_fx, sub( sub( 15, exp ), i ) ); /*Q15*/
- }
- scale_fx = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */
- test();
- IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) ||
- GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) )
- {
- shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale_fx );
-
- if ( GT_16( st->nbLostCmpt, 1 ) )
- {
- shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 );
- }
- }
- ELSE
- {
- L_tmp = L_mult( scale_fx, scale_fx ); /* Q29 */
- shb_ener_sf_32 = L_shl( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, round_fx( L_tmp ) ), 2 );
- }
- }
- ELSE
- {
- test();
- IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) ||
- GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) )
- {
- shb_ener_sf_32 = L_shr( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st->cummulative_damping ), 1 );
- }
- ELSE
- {
- shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st->cummulative_damping );
- }
- }
- }
-
- shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ );
- mixFactors_fx = hBWE_TD->prev_mixFactors_fx;
- move16();
-
- IF( EQ_16( st->codec_mode, MODE1 ) )
- {
- set16_fx( shb_res_gshape_fx, 3277 /*0.2f Q14*/, 5 ); /* Q14 */
- }
- ELSE
- {
- set16_fx( shb_res_gshape_fx, 16384 /*1.0f Q14*/, 5 ); /* Q14 */
- }
- }
- }
-
- /* get the gainshape delay */
- Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 );
- FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
- {
- st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; /*Q15*/
- move16();
- }
-
- L_tmp = L_mult( voice_factors_fx[0], 8192 );
- L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 );
- L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 );
- mean_vf = mac_r( L_tmp, voice_factors_fx[3], 8192 );
-
- Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k );
-
- test();
- IF( EQ_16( st->coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) )
- {
- FOR( i = 1; i < NB_SUBFR; i++ )
- {
- L_tmp = L_mult( voice_factors_fx[i], 26214 /*0.8f Q15*/ );
- vf_modified_fx[i] = mac_r( L_tmp, voice_factors_fx[i - 1], 6554 /*0.2f Q15*/ );
- move16();
- }
-
- IF( st->L_frame != L_FRAME )
- {
- L_tmp = L_mult( voice_factors_fx[4], 26214 /*0.8f Q15*/ );
- vf_modified_fx[4] = mac_r( L_tmp, voice_factors_fx[3], 6554 /*0.2f Q15*/ );
- move16();
- }
- }
-
- test();
- IF( st->use_partial_copy && st->nelp_mode_dec )
- {
- set16_fx( vf_modified_fx, 0, NB_SUBFR16k );
- }
-
- /* SHB LSF from current frame; and convert to LSP for interpolation */
- E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER );
-
- test();
- IF( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) )
- {
- /* SHB LSP values from prev. frame for interpolation */
- Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER );
- }
- ELSE
- {
- /* Use current frame's LSPs; in effect no interpolation */
- Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER );
- }
-
- test();
- test();
- test();
- IF( ( st->bws_cnt == 0 ) && ( st->bws_cnt1 == 0 ) && ( st->prev_use_partial_copy == 0 ) && ( st->use_partial_copy == 0 ) )
- {
- lsf_diff_fx[0] = 16384;
- move16(); /*Q15*/
- lsf_diff_fx[LPC_SHB_ORDER - 1] = 16384;
- move16(); /*Q15*/
- FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ )
- {
- lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] );
- move16();
- }
-
- a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl_fx, M );
- tmp = add( 16384, shr( refl_fx[0], 1 ) ); /*Q14*/
- tmp1 = mult( 27425, tmp );
- tmp1 = mult( tmp1, tmp ); /*Q10*/
- tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/
- tilt_para_fx = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/
-
- test();
- IF( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) )
- {
- FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ )
- {
- hBWE_TD->prev_lsf_diff_fx[i - 1] = shr( lsf_diff_fx[i], 1 );
- move16();
- }
- }
-
- IF( LE_32( st->extl_brate, FB_TBE_1k8 ) )
- {
- test();
- test();
- test();
- test();
- test();
- IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( st->coder_type, TRANSITION ) || LT_16( tilt_para_fx, 1024 ) ) ) &&
- !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para_fx, 5120 ) ) )
- {
- FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ )
- {
- IF( LT_16( lsf_diff_fx[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) )
- {
- tmp = mult( 26214, lsf_diff_fx[i] );
-
- test();
- IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */
- {
- st->BER_detect = 1;
- move16();
- tmp = 0;
- move16();
- }
- ELSE
- {
- tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] );
- }
-
- tmp = s_max( tmp, 16384 );
- w_fx[i] = s_min( tmp, 32767 );
- move16();
- }
- ELSE
- {
- tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] );
-
- test();
- IF( ( lsf_diff_fx[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */
- {
- st->BER_detect = 1;
- move16();
- tmp = 0;
- move16();
- }
- ELSE
- {
- tmp = div_s( tmp, lsf_diff_fx[i] );
- }
-
- tmp = s_max( tmp, 16384 );
- w_fx[i] = s_min( tmp, 32767 );
- move16();
- }
- }
- w_fx[0] = w_fx[1];
- move16();
- w_fx[LPC_SHB_ORDER - 1] = w_fx[LPC_SHB_ORDER - 2];
- move16();
-
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w_fx[i] ) );
- tmp2 = mult( lsp_shb_2_fx[i], w_fx[i] );
- lsp_temp_fx[i] = add( tmp1, tmp2 );
- move16();
- }
- }
- ELSE
- {
- Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER );
- }
-
- /* convert from lsp to lsf */
- lsp2lsf_fx( lsp_temp_fx, lsf_shb_fx, LPC_SHB_ORDER, 1 );
- }
-
- Copy( lsf_diff_fx + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 );
- hBWE_TD->prev_tilt_para_fx = tilt_para_fx;
- move16();
- }
- ELSE
- {
- Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER );
- }
-
- IF( GE_32( st->extl_brate, SWB_TBE_2k8 ) )
- {
- /* SHB LSP interpolation */
- ptr_lsp_interp_coef_fx = interpol_frac_shb; /*Q15*/
- FOR( j = 0; j < 4; j++ )
- {
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- L_tmp = L_mult( lsp_shb_1_fx[i], ( *ptr_lsp_interp_coef_fx ) );
- lsp_temp_fx[i] = mac_r( L_tmp, lsp_shb_2_fx[i], ( *( ptr_lsp_interp_coef_fx + 1 ) ) );
- move16();
- }
- ptr_lsp_interp_coef_fx += 2;
-
- tmp = i_mult( j, ( LPC_SHB_ORDER + 1 ) );
- /* convert LSPs to LP coefficients */
- E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER );
-#ifndef FIX_1100_REMOVE_LPC_RESCALING
- /* Bring the LPCs to Q12 */
- Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) );
- lpc_shb_sf_fx[i_mult( j, ( LPC_SHB_ORDER + 1 ) )] = ONE_IN_Q12; // recheck this
- move16();
-#endif
- }
- }
-
- /* Save the SWB LSP values from current frame for interpolation */
- Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER );
-
- /* save the shb_ener and mixFactor values */
- hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx;
- move32();
- hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx;
- move32();
- hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32;
- move32();
- hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape_fx[4];
- move16();
- hBWE_TD->prev_mixFactors_fx = mixFactors_fx;
- move16();
-
- /* SWB CNG/DTX - update memories */
- IF( st->hTdCngDec != NULL )
- {
- Copy( st->hTdCngDec->lsp_shb_prev_fx, st->hTdCngDec->lsp_shb_prev_prev_fx, LPC_SHB_ORDER );
- Copy( lsf_shb_fx, st->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER );
- }
-
- /* convert LSPs back into LP coeffs */
- E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER );
- Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */
- lpc_shb_fx[0] = ONE_IN_Q12;
- move16();
-
- test();
- IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) )
- {
- Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1
- vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/
- /* i: mixFactors_fx in Q15 */
- /* o: vind in Q0 */
- }
- ELSE
- {
- vind = shl( mixFactors_fx, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*8*/
- /* i: mixFactors_fx in Q15 */
- /* o: vind in Q0 */
- }
-
- /* Determine formant PF strength */
- formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx );
- /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */
- IF( GT_32( st->total_brate, ACELP_32k ) )
- {
- FOR( j = 0; j < 4; j++ )
- {
- Copy( lpc_shb_fx, &lpc_shb_sf_fx[i_mult( j, ( LPC_SHB_ORDER + 1 ) )], LPC_SHB_ORDER + 1 );
- }
- }
-
- /* From low band excitation, generate highband excitation */
-
- /* -------- start of memory rescaling -------- */
- /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */
- Lmax = 0;
- move32();
- FOR( cnt = 0; cnt < L_FRAME32k; cnt++ )
- {
- Lmax = L_max( Lmax, L_abs( bwe_exc_extended_fx[cnt] ) );
- }
- Q_bwe_exc = norm_l( Lmax );
- if ( Lmax == 0 )
- {
- Q_bwe_exc = 31;
- move16();
- }
- Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) );
- find_max_mem_dec( st, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */
-
- tmp = add( st->prev_Q_bwe_exc, n_mem );
- if ( GT_16( Q_bwe_exc, tmp ) )
- {
- Q_bwe_exc = tmp;
- move16();
- }
-
- /* rescale the memories if Q_bwe_exc is different from previous frame */
- sc = sub( Q_bwe_exc, st->prev_Q_bwe_exc );
- IF( sc != 0 )
- {
- rescale_genSHB_mem_dec( st, sc );
- }
-
- /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */
- sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) );
-
- FOR( cnt = 0; cnt < L_FRAME32k; cnt++ )
- {
- bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) );
- move16();
- }
-
- /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */
-
- /* save the previous Q factor (32-bit) of the buffer */
- st->prev_Q_bwe_exc = Q_bwe_exc;
- move16();
-
- Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */
-
- /* -------- end of rescaling memories -------- */
-
- Q_bwe_exc_fb = st->prev_Q_bwe_exc_fb;
- move16();
-
- Q_shb = 0;
- move16();
-
- Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD );
- GenShapedSHBExcitation_ivas_dec_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx,
- hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
- st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl,
- &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32,
- shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx,
- &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st->prev_Q_bwe_syn, st->total_brate, st->prev_bfi,
- st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag,
- NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL );
-
- *Q_white_exc = Q_bwe_exc_fb;
- move16();
- IF( EQ_16( st->extl, FB_TBE ) )
- {
- st->prev_Q_bwe_exc_fb = Q_bwe_exc_fb;
- move16();
- }
- ELSE
- {
- /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value.
- 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/
- st->prev_Q_bwe_exc_fb = 51;
- move16();
- }
-
- /* rescale the TBE post proc memory */
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
- {
- hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st->prev_Q_bwe_syn ) );
- move16();
- }
- /* fill-in missing SHB excitation */
- test();
- test();
- IF( ( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) && LE_32( st->last_core_brate, SID_2k40 ) )
- {
- Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, shaped_shb_excitation_fx, L_SHB_LAHEAD );
- }
-
- IF( hStereoICBWE != NULL )
- {
- Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, hStereoICBWE->shbSynthRef_fx, L_FRAME16k );
- }
-
- test();
- IF( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) )
- {
- FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k )
- {
- /* TD BWE post-processing */
- PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx,
- hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx );
- }
-
- Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */
-
- tmp = sub( shl( Q_bwe_exc, 1 ), 31 + 16 );
- prev_pow_fx = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */
- curr_pow_fx = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */
- FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ )
- {
- prev_pow_fx = L_mac0_sat( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /*2*Q_bwe_exc*/
- curr_pow_fx = L_mac0_sat( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */
- }
-
- if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) )
- {
- curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* Q(2*Q_bwe_exc) */
- }
-
- Lscale = root_a_over_b_fx( curr_pow_fx,
- shl( Q_bwe_exc, 1 ),
- prev_pow_fx,
- shl( Q_bwe_exc, 1 ),
- &exp );
-
- FOR( i = 0; i < L_SHB_LAHEAD; i++ )
- {
- L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */
- shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */
- move16();
- }
- IF( exp < 0 )
- {
- Lscale = L_shl( Lscale, exp );
- exp = 0;
- move16();
- }
- FOR( ; i < L_SHB_LAHEAD + 10; i++ )
- {
- temp_fx = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */
- L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp_fx ); /* Q31-exp */
- temp_fx = sub( 32767 /*1.0f Q15*/, temp_fx );
- Lscale = L_add( Mult_32_16( Lscale, temp_fx ), L_tmp1 );
- L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */
- shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */
- move16();
- }
- }
- ELSE
- {
- /* reset the PF memories if the PF is not running */
- set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER );
- hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14;
- move16();
- set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER );
- }
-
- /* Update SHB excitation */
- Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */
- l_subframe = L_FRAME16k / NUM_SHB_SUBGAINS;
- move16();
- L_ener = EPSILON_FX_SMALL;
- move32();
-
- FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
- {
- L_tmp = 0;
- move32();
- ener_tmp_fx[i] = EPSILON_FX_SMALL;
- move32();
-
- Word64 tmp64 = 0;
- move64();
- FOR( j = 0; j < l_subframe; j++ )
- {
- tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation_fx[add( i_mult( i, l_subframe ), j )], shaped_shb_excitation_fx[add( i_mult( i, l_subframe ), j )] ); /* 2*Q_bwe_exc */
- }
- L_tmp = W_sat_l( tmp64 );
-
- L_tmp = Mult_32_16( L_tmp, 410 /*0.0125 Q15*/ ); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */
- IF( L_tmp != 0 )
- {
- exp = norm_l( L_tmp );
- tmp = extract_h( L_shl( L_tmp, exp ) );
- exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) );
-
- tmp = div_s( 16384, tmp );
- L_tmp = L_deposit_h( tmp );
- L_tmp = Isqrt_lc( L_tmp, &exp );
- ener_tmp_fx[i] = L_shl_sat( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */
- move32();
- L_ener = L_add_sat( L_ener, L_shr( ener_tmp_fx[i], 2 ) ); /* 2*Q_bwe_exc */
- }
- }
- ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */
- /* WB/SWB bandwidth switching */
- IF( st->bws_cnt > 0 )
- {
- IF( is_fractive == 0 )
- {
- IF( GT_16( st->tilt_wb_fx, 2048 ) ) /*assuming st->tilt_wb_fx in Q11*/
- {
- st->tilt_wb_fx = 2048;
- move16();
- }
- ELSE IF( LT_16( st->tilt_wb_fx, 1024 ) )
- {
- st->tilt_wb_fx = 1024;
- move16();
- }
- test();
- if ( EQ_16( st->prev_fractive, 1 ) && GT_16( st->tilt_wb_fx, 1024 ) )
- {
- st->tilt_wb_fx = 1024;
- move16();
- }
- }
- ELSE
- {
- IF( GT_16( st->tilt_wb_fx, 8192 ) )
- {
- IF( st->prev_fractive == 0 )
- {
- st->tilt_wb_fx = 8192;
- move16();
- }
- ELSE
- {
- st->tilt_wb_fx = 16384;
- move16();
- }
- }
- ELSE
- {
- st->tilt_wb_fx = shl( st->tilt_wb_fx, 2 );
- move16();
- }
- }
-
- IF( ener_fx != 0 )
- {
- L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 13 ) ); /* 2+11 +st->Q_syn2 -13 = st->Q_syn2*/
- exp_ener = norm_s( ener_fx );
- tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/
- inv_ener = shr( div_s( 16384, tmp ), 1 ); /*Q(15+14-2-exp-1) = 26 - exp*/
-
- test();
- IF( GT_32( L_tmp, st->enerLH_fx ) ) /*st->Q_syn2*/
- {
- st->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st->enerLH_fx, inv_ener ), sub( sub( st->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/
- move16();
- /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/
- }
- ELSE IF( LT_32( L_tmp, Mult_32_16( st->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) )
- {
- st->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st->enerLH_fx, inv_ener ), sub( sub( st->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/
- move16();
- /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/
- }
- L_tmp = L_mult0( st->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/
- GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/
- }
- ELSE
- {
- GainFrame_prevfrm_fx = 0;
- move32();
- }
-
- IF( EQ_16( is_fractive, 1 ) )
- {
- GainFrame_fx = L_shl( L_deposit_l( st->tilt_wb_fx ), 10 );
- }
- ELSE
- {
- GainFrame_fx = L_shl( L_deposit_l( st->tilt_wb_fx ), 8 );
- }
-
- test();
- IF( EQ_16( ( is_fractive & st->prev_fractive ), 1 ) && GT_32( GainFrame_fx, GainFrame_prevfrm_fx ) )
- {
- GainFrame_fx = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) ); /* 18 +15 -15 = 18*/
- }
- ELSE
- {
- test();
- test();
- test();
- test();
- IF( ( LT_32( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) && GT_32( st->prev_enerLH_fx, L_shr( st->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st->prev_enerLL_fx, 1 ), st->enerLL_fx ) && GT_32( st->prev_enerLL_fx, L_shr( st->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st->prev_fractive ) == 0 ) )
- {
- GainFrame_fx = L_add( L_shr( GainFrame_fx, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) );
- }
- ELSE
- {
- test();
- IF( ( is_fractive == 0 ) && EQ_16( st->prev_fractive, 1 ) )
- {
- L_tmp1 = L_shl( Mult_32_16( GainFrame_fx, 3277 ), 13 ); /* 31 */
- L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */
- GainFrame_fx = L_add( Mult_32_32( GainFrame_fx, L_tmp ), Mult_32_32( GainFrame_prevfrm_fx, L_tmp1 ) ); /* 18 */
- }
- ELSE
- {
- GainFrame_fx = L_add( L_shr( GainFrame_fx, 1 ), L_shr( L_min( GainFrame_prevfrm_fx, GainFrame_fx ), 1 ) ); /* 18 */
- }
- }
- }
-
- GainFrame_fx = Mult_32_16( GainFrame_fx, i_mult( sub( N_WS2N_FRAMES, st->bws_cnt ), 819 ) ); /*Q18*/
- }
- ELSE
- {
- IF( st->bws_cnt1 > 0 )
- {
- GainFrame_fx = Mult_32_16( GainFrame_fx, i_mult( st->bws_cnt1, 819 ) ); /*Q18*/
- }
- IF( GE_16( st->nbLostCmpt, 1 ) )
- {
- ener_fx = s_max( 1, ener_fx );
- exp_ener = norm_s( ener_fx );
- tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/
- inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/
- prev_ener_ratio_fx = L_shr( L_mult0( st->prev_ener_shb_fx, inv_ener ), add( sub( 9, exp_ener ), 1 ) ); /*Q: 1+27-exp-9+exp-1 = 18 */
- }
-
- IF( EQ_16( st->nbLostCmpt, 1 ) )
- {
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( st->clas_dec != UNVOICED_CLAS ) && NE_16( st->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) &&
- ( ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st->enerLL_fx, 1 ), st->prev_enerLL_fx ) ) || ( GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st->enerLH_fx, 1 ), st->prev_enerLH_fx ) ) ) )
- {
- IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) ) /*18*/
- {
- GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 13107 ), Mult_32_16( GainFrame_fx, 19661 ) ); /*18*/
- }
- ELSE IF( GT_32( L_shr( prev_ener_ratio_fx, 1 ), GainFrame_fx ) )
- {
- GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) );
- }
- ELSE
- {
- GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) );
- }
-
- test();
- IF( GT_16( tilt_swb_fec_fx, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) )
- {
- exp = norm_s( hBWE_TD->tilt_swb_fec_fx );
- tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/
- tmp = div_s( 16384, tmp ); /*Q(15+14-11-exp)*/
- tmp = extract_h( L_shl( L_mult0( tmp, st->tilt_wb_fx ), sub( exp, 1 ) ) ); /*18 -exp +11 + exp -1 -16 =12; */
- GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */
- }
- }
- ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 4096 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) &&
- ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) )
- {
- GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) );
- }
- }
- ELSE IF( GT_16( st->nbLostCmpt, 1 ) )
- {
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) )
- {
- test();
- IF( GT_16( tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) )
- {
- GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6554 /*0.2f in Q15*/ ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 /*4.0f in Q12*/ ), 3 ) ); /*Q18*/
- }
- ELSE
- {
- GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame_fx, 16384 ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 ), 3 ) ); /*Q18*/
- }
- }
- ELSE IF( GT_32( prev_ener_ratio_fx, GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) )
- {
- test();
- IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) )
- {
- GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 /*0.5f in Q15*/ ), Mult_32_16( GainFrame_fx, 16384 /*0.5f in Q15*/ ) ); /* Q18 */
- }
- ELSE
- {
- GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 /*0.2f in Q15*/ ), Mult_32_16( GainFrame_fx, 26214 /*0.8f in Q15*/ ) ); /* Q18 */
- }
- }
- }
- }
-
- st->prev_fractive = is_fractive;
- move16();
-
- /* Adjust the subframe and frame gain of the synthesized shb signal */
- /* Scale the shaped excitation */
- IF( EQ_16( st->L_frame, L_FRAME ) )
- {
- L_tmp = L_mult( pitch_buf_fx[0], 8192 );
- FOR( i = 1; i < NB_SUBFR; i++ )
- {
- L_tmp = L_mac( L_tmp, pitch_buf_fx[i], 8192 ); /* pitch_buf in Q6 x 0.25 in Q15 */
- }
- pitch_fx = round_fx( L_tmp ); /* Q6 */
- }
- ELSE
- {
- L_tmp = L_mult( pitch_buf_fx[0], 6554 );
- FOR( i = 1; i < NB_SUBFR16k; i++ )
- {
- L_tmp = L_mac( L_tmp, pitch_buf_fx[i], 6554 ); /* pitch_buf in Q6 x 0.2 in Q15 */
- }
- pitch_fx = round_fx( L_tmp ); /* Q6 */
- }
-
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( ( GE_32( st->extl_brate, SWB_TBE_2k8 ) && EQ_16( st->prev_coder_type, st->coder_type ) && NE_16( st->coder_type, UNVOICED ) ) || ( LT_32( st->extl_brate, SWB_TBE_2k8 ) && ( EQ_16( st->prev_coder_type, st->coder_type ) || ( EQ_16( st->prev_coder_type, VOICED ) && EQ_16( st->coder_type, GENERIC ) ) || ( EQ_16( st->prev_coder_type, GENERIC ) && EQ_16( st->coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st->extl, FB_TBE ) && NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) )
- {
- FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
- {
- GainShape_tmp_fx[i] = GainShape_fx[i * 4]; /* Q15 */
- move16();
- }
-
- FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
- {
- L_tmp1 = Mult_32_16( ener_tmp_fx[i], GainShape_tmp_fx[i] ); /* (2*Q_bwe_exc) */
- L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st->prev_ener_fx_Q) */
- tmp = sub( shl( Q_bwe_exc, 1 ), shl( st->prev_ener_fx_Q, 1 ) );
- L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */
- IF( GT_32( L_tmp1, L_tmp2 ) )
- {
- L_tmp = L_tmp2;
- move32();
- if ( L_tmp2 < 0 )
- {
- L_tmp = L_negate( L_tmp2 );
- }
-
- expb = norm_l( L_tmp );
- fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) );
- expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */
-
- expa = norm_l( ener_tmp_fx[i] );
- fraca = extract_h( L_shl( ener_tmp_fx[i], expa ) );
- expa = sub( 30, expa );
-
- scale_fx = shr( sub( fraca, fracb ), 15 );
- fracb = shl( fracb, scale_fx );
- expb = sub( expb, scale_fx );
-
- tmp = div_s( fracb, fraca );
- exp = sub( sub( expb, expa ), 1 );
- tmp = shl( tmp, exp );
- GainShape_tmp_fx[i] = add( tmp, shr( GainShape_tmp_fx[i], 1 ) ); /* Q15 */
- move16();
- }
-
- hBWE_TD->prev_ener_fx = ener_tmp_fx[i];
- move32();
- hBWE_TD->prev_GainShape_fx = GainShape_tmp_fx[i];
- move16();
- st->prev_ener_fx_Q = Q_bwe_exc;
- move16();
- }
-
- FOR( i = 0; i < NUM_SHB_SUBFR; i++ )
- {
- Word16 idx = 0;
- move16();
- IF( i != 0 )
- {
- idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR );
- }
- GainShape_fx[i] = GainShape_tmp_fx[idx];
- move16();
- }
- }
- ELSE
- {
- st->prev_ener_fx_Q = Q_bwe_exc;
- move16();
- }
- st->prev_Q_bwe_syn = Q_bwe_exc;
- move16();
-
-
- /* Gain shape smoothing after quantization */
- test();
- IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) )
- {
- FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
- {
- GainShape_tmp_fx[i] = GainShape_fx[i * NUM_SHB_SUBGAINS];
- move16();
- }
-
- lls_interp_n_fx( GainShape_tmp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp_fx, 1 );
-
- test();
- IF( GE_16( vind, 6 ) && LT_16( abs_s( GainShape_tilt_fx ), 3932 ) )
- {
- feedback_fx = 9830;
- move16();
- FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
- {
- GainShape_fx[i] = add_sat( mult( sub( 32767, feedback_fx ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), mult( feedback_fx, GainShape_tmp_fx[i] ) );
- move16();
- }
-
- FOR( i = NUM_SHB_SUBFR - 1; i > 0; i-- )
- {
- Word16 idx = 0;
- move16();
- IF( i != 0 )
- {
- idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR );
- }
- GainShape_fx[i] = GainShape_fx[idx];
- move16();
- }
- }
- }
-
- /* fil-in missing memory */
- test();
- test();
- IF( ( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) && LE_32( st->last_core_brate, SID_2k40 ) )
- {
- FOR( i = 0; i < L_SHB_LAHEAD; i++ )
- {
- Word16 intermediate = mult( shaped_shb_excitation_fx[i], subwin_shb_fx[L_SHB_LAHEAD - i] );
- Word32 intermediate_32 = Mpy_32_16_1( Mpy_32_16_1( GainFrame_fx, window_shb_fx[L_SHB_LAHEAD - 1 - i] ), intermediate );
- hBWE_TD->syn_overlap_fx[i] = round_fx( L_shl_sat( intermediate_32, sub( 16, ( add( Q_bwe_exc, 18 - 15 ) ) ) ) );
- move16();
- }
- }
-
- Word16 n_mem3_new = 0;
- move16();
- find_max_mem_dec_m3( st, &n_mem3_new );
-
- ScaleShapedSHB_fx( SHB_OVERLAP_LEN,
- shaped_shb_excitation_fx, /* i/o: Q_bwe_exc */
- hBWE_TD->syn_overlap_fx,
- GainShape_fx, /* Q15 */
- GainFrame_fx, /* Q18 */
- window_shb_fx,
- subwin_shb_fx,
- &Q_bwe_exc, &Qx, n_mem3_new, st->prev_Q_bwe_syn2 );
-
- IF( hStereoICBWE != NULL )
- {
- Copy_Scale_sig_16_32_DEPREC( lpc_shb_fx, hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 0 );
- Copy( GainShape_fx, hStereoICBWE->gshapeRef_fx, NUM_SHB_SUBFR );
- hStereoICBWE->gFrameRef_fx = GainFrame_fx;
- move32();
-
- Copy( shaped_shb_excitation_fx, hStereoICBWE->shbSynthRef_fx, L_FRAME16k );
- }
-
- max_val = 0;
- move16();
- FOR( i = 0; i < L_FRAME16k; i++ )
- {
- max_val = s_max( max_val, abs_s( shaped_shb_excitation_fx[i] ) ); /* Q0 */
- }
- IF( max_val == 0 )
- {
- curr_frame_pow_fx = 0;
- move32();
- n = 0;
- move16();
- }
- ELSE
- {
- n = norm_s( max_val );
- max_val = 0;
- move16();
- FOR( i = 0; i < L_FRAME16k; i++ )
- {
- shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation_fx[i], n ); /*Q_bwe_exc+n*/
- move16();
- }
-
- curr_frame_pow_fx = 0;
- move32();
- FOR( i = 0; i < L_FRAME16k; i++ )
- {
- L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/
- curr_frame_pow_fx = L_add( curr_frame_pow_fx, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/
- }
- }
- curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 );
- tmp = sub( st->prev_frame_pow_exp, curr_frame_pow_exp );
- IF( tmp > 0 ) /* shifting prev */
- {
- IF( GT_16( tmp, 32 ) )
- {
- st->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 );
- move16();
- tmp = 32;
- move16();
- }
- hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp );
- move32();
- st->prev_frame_pow_exp = curr_frame_pow_exp;
- move16();
- }
- ELSE /* shifting curr */
- {
- IF( LT_16( tmp, -32 ) )
- {
- curr_frame_pow_exp = sub( st->prev_frame_pow_exp, 32 );
- tmp = -32;
- move16();
- }
- curr_frame_pow_fx = L_shr( curr_frame_pow_fx, -tmp );
- curr_frame_pow_exp = st->prev_frame_pow_exp;
- move16();
- }
- test();
- test();
- IF( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) )
- {
- test();
- test();
- IF( ( GT_32( L_shr( curr_frame_pow_fx, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) &&
- ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st->prev_coder_type, UNVOICED ) )
- {
- L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp );
- scale_fx = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/
-
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- temp_fx = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/
- }
- ELSE
- {
- scale_fx = temp_fx = 32767;
- move16(); /*Q15*/
- move16(); /*Q15*/
- }
-
- FOR( j = 0; j < 8; j++ )
- {
- GainShape_fx[2 * j] = mult_r( GainShape_fx[2 * j], scale_fx );
- move16();
- GainShape_fx[2 * j + 1] = mult_r( GainShape_fx[2 * j + 1], scale_fx );
- move16();
- FOR( i = 0; i < L_FRAME16k / 8; i++ )
- {
- shaped_shb_excitation_fx[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation_fx[add( i, j * ( L_FRAME16k / 8 ) )], scale_fx );
- move16();
- }
-
- IF( temp_fx > 0 )
- {
- /* scale_fx <= temp_fx, due to scale_fx = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow_fx ), temp_fx = sqrt( scale_fx, 1.f/8.f )
- and curr_frame_pow_fx > st->prev_swb_bwe_frame_pow_fx -> scale_fx <= 1.0, sqrt(scale_fx, 1.f/8.f) >= scale_fx */
- IF( LT_16( scale_fx, temp_fx ) )
- {
- scale_fx = div_s( scale_fx, temp_fx );
- }
- ELSE
- {
- scale_fx = 32767;
- move16();
- }
- }
- ELSE
- {
- scale_fx = 0;
- move16();
- }
- }
- }
-
- /* adjust the FEC frame energy */
- IF( st->bfi )
- {
- scale_fx = temp_fx = 4096;
- move16(); /*Q12*/
- move16();
- IF( EQ_16( st->nbLostCmpt, 1 ) )
- {
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( GT_32( curr_frame_pow_fx, hBWE_TD->prev_swb_bwe_frame_pow_fx ) &&
- NE_16( st->prev_coder_type, UNVOICED ) &&
- ( st->last_good != UNVOICED_CLAS ) )
- {
- L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp ); /*31 - exp*/
- scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
- }
- ELSE IF( LT_32( curr_frame_pow_fx, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st->nbLostCmpt, 1 ) &&
- ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) &&
- ( EQ_16( st->prev_coder_type, UNVOICED ) || ( st->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) )
- {
- L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp );
- scale_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
- }
- }
- ELSE IF( GT_16( st->nbLostCmpt, 1 ) )
- {
- test();
- test();
- test();
- test();
- test();
- IF( GT_32( curr_frame_pow_fx, hBWE_TD->prev_swb_bwe_frame_pow_fx ) )
- {
- L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp );
- scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- temp_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
- }
- ELSE IF( LT_32( curr_frame_pow_fx, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) &&
- ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) &&
- ( EQ_16( st->prev_coder_type, UNVOICED ) || ( st->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) )
- {
- L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp );
- L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/
- scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
- temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
- }
- }
-
- FOR( j = 0; j < 8; j++ )
- {
- GainShape_fx[2 * j] = shl_sat( mult_r( GainShape_fx[2 * j], scale_fx ), 3 );
- move16(); /* 15 +12 +3-15 =15*/
- GainShape_fx[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ), 3 );
- move16();
- FOR( i = 0; i < 40; i++ )
- {
- shaped_shb_excitation_fx[i + j * L_FRAME16k / 8] = shl( mult_r( shaped_shb_excitation_fx[i + j * L_FRAME16k / 8], scale_fx ), 3 );
- move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/
- }
-
- IF( temp_fx > 0 )
- {
- IF( LT_16( scale_fx, temp_fx ) )
- {
- scale_fx = shr( div_s( scale_fx, temp_fx ), 3 );
- }
- ELSE
- {
- tmp1 = sub( norm_s( scale_fx ), 1 );
- tmp2 = norm_s( temp_fx );
- scale_fx = div_s( shl( scale_fx, tmp1 ), shl( temp_fx, tmp2 ) );
- scale_fx = shr( scale_fx, add( sub( tmp1, tmp2 ), 3 ) );
- }
- }
- ELSE
- {
- scale_fx = 0;
- move16();
- }
- }
- }
-
- hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow_fx;
- move32();
- st->prev_frame_pow_exp = curr_frame_pow_exp;
- move16();
-
- Word64 prev_ener_shb64 = 0;
- move64();
- FOR( i = 0; i < L_FRAME16k; i++ )
- {
- prev_ener_shb64 = W_mac0_16_16( prev_ener_shb64, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* Q0 */
- }
- L_prev_ener_shb = W_sat_l( prev_ener_shb64 );
-
- L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */
- st->prev_ener_shb_fx = 0;
- move16();
- IF( L_prev_ener_shb != 0 )
- {
- exp = norm_l( L_prev_ener_shb );
- tmp = extract_h( L_shl( L_prev_ener_shb, exp ) );
- exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) );
-
- tmp = div_s( 16384, tmp );
- L_tmp = L_deposit_h( tmp );
- L_tmp = Isqrt_lc( L_tmp, &exp );
- st->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */
- move16();
- }
-
- IF( st->hBWE_FD != NULL )
- {
- L_tmp = Mult_32_16( curr_frame_pow_fx, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */
- tmp = 0;
- move16();
- IF( L_tmp != 0 )
- {
- exp = norm_l( L_tmp );
- tmp = extract_h( L_shl( L_tmp, exp ) );
- exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) );
-
- tmp = div_s( 16384, tmp );
- L_tmp = L_deposit_h( tmp );
- L_tmp = Isqrt_lc( L_tmp, &exp );
- tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */
- }
- set16_fx( st->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */
- }
-
- FOR( i = 0; i < L_FRAME16k; i++ )
- {
- shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], sub( Q11, Q_bwe_exc ) );
- move32();
- }
-
- /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */
- GenSHBSynth_fx_32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) );
- Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) );
- Copy32( error_fx + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH );
-
- /* resample SHB synthesis (if needed) and scale down */
- synth_scale_fx = 32767;
- move16(); /* 1.0 in Q15 */
- if ( EQ_16( st->codec_mode, MODE1 ) )
- {
- synth_scale_fx = 29491;
- move16(); /* 0.9 in Q15 */
- }
-
- IF( EQ_32( st->output_Fs, 48000 ) )
- {
- IF( EQ_16( st->extl, FB_TBE ) )
- {
- tmp = norm_l( GainFrame_fx );
- if ( GainFrame_fx == 0 )
- {
- tmp = 31;
- move16();
- }
- L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */
-
- tmp1 = 0;
- move16();
- FOR( i = 0; i < L_FRAME16k; i++ )
- {
- Word16 idx = 0;
- move16();
- IF( i != 0 )
- {
- idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k );
- }
- L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/
- White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */
- move16();
- tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) );
- }
-
- *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */
- move16();
- tmp = norm_s( tmp1 );
- if ( tmp1 == 0 )
- {
- tmp = 15;
- move16();
- }
-
- FOR( i = 0; i < L_FRAME16k; i++ )
- {
- White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) );
- move16();
- }
- *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 );
- move16();
- }
-
- IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */
- {
- FOR( i = 0; i < L_FRAME32k; i++ )
- {
- error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx );
- move32();
- }
- }
- interpolate_3_over_2_allpass_32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 );
- }
- ELSE IF( EQ_32( st->output_Fs, 32000 ) )
- {
- IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */
- {
- FOR( i = 0; i < L_FRAME32k; i++ )
- {
- synth_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx );
- move32(); /*Qx*/
- }
- }
- ELSE
- {
- Copy32( error_fx, synth_fx, L_FRAME32k );
- }
- }
- ELSE IF( EQ_32( st->output_Fs, 16000 ) )
- {
- IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */
- {
- FOR( i = 0; i < L_FRAME32k; i++ )
- {
- error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx );
- move32();
- }
- }
-
- Decimate_allpass_steep_fx32( error_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, synth_fx );
- }
-
-
- /* Update previous frame parameters for FEC */
- Copy( lsf_shb_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER );
- IF( EQ_16( st->codec_mode, MODE1 ) )
- {
- hBWE_TD->GainFrame_prevfrm_fx = GainFrame_fx;
- move32(); /*Q18*/
- hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx;
- move16();
-
- if ( !st->bfi )
- {
- hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/
- move16();
- }
- }
- ELSE
- {
- IF( !st->bfi )
- {
- hBWE_TD->GainFrame_prevfrm_fx = GainFrame_fx;
- move32(); /*Q18*/
- hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx;
- move16();
- hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/
- move16();
- }
- }
-
- hBWE_TD->prev_ener_fx = ener_tmp_fx[NUM_SHB_SUBGAINS - 1];
- move32();
- hBWE_TD->prev_GainShape_fx = GainShape_fx[NUM_SHB_SUBFR - 1];
- move16();
- st->prev_Q_bwe_syn2 = Q_bwe_exc;
- move16();
- st->prev_Qx = Q_bwe_exc;
- move16();
-
- return;
-}
-/*-------------------------------------------------------------------*
- * Dequant_lower_LSF()
- *
- * Dequantized the lower LSFs
- *-------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------*
- * Map_higher_LSF()
- *
- * Map the higher LSFs from the lower LSFs
- *-------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------*
- * Map_higher_LSF()
- *
- * Map the higher LSFs from the lower LSFs
- *-------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------*
- * dequantizeSHBparams()
- *
- * Dequantize super highband spectral envolope, temporal gains and frame gain
- *-------------------------------------------------------------------*/
-
-
-void GenTransition_fixed(
- TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */
- const Word32 output_Fs, /* i : output sampling rate : Q0 */
- const Word16 element_mode, /* i : element mode : Q0 */
- const Word16 L_frame, /* i : ACELP frame length : Q0 */
- const Word16 rf_flag, /* i : RF flag : Q0 */
- const Word32 total_brate, /* i : total bitrate : Q0 */
- const Word16 prev_Qx )
-{
- Word16 i, length;
-
- Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN];
-
- /* set targeted length of transition signal */
- length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) );
-
- /* upsample overlap snippet */
- Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx );
-
- /* perFORm spectral flip and downmix with overlap snippet to match HB synth */
- test();
- test();
- test();
- test();
- IF( ( ( element_mode == EVS_MONO ) && ( rf_flag || EQ_32( total_brate, ACELP_9k60 ) ) ) || ( ( element_mode > EVS_MONO ) && EQ_16( L_frame, L_FRAME ) ) )
- {
- flip_and_downmix_generic_fx_32( syn_overlap_32k_fx, syn_overlap_32k_fx, 2 * SHB_OVERLAP_LEN, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + HILBERT_ORDER1, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), &( hBWE_TD->syn_dm_phase ) );
- }
- ELSE
- {
- FOR( i = 0; i < 2 * SHB_OVERLAP_LEN; i++ )
- {
- IF( i % 2 == 0 )
- {
- syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] );
- }
- ELSE
- {
- syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i];
- }
- move32();
- }
- }
-
- /* cross fade of overlap snippet and mirrored HB synth from previous frame */
- FOR( i = 0; i < 2 * L_SHB_LAHEAD; i++ )
- {
- outputHB_fx[i] = L_add_sat( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_32k_fx[i] ), Mpy_32_16_1( syn_overlap_32k_fx[i], window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i] ) );
- move32();
- }
-
- /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */
- FOR( ; i < length; i++ )
- {
- outputHB_fx[i] = L_shl( hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i], sub( Q11, prev_Qx ) );
- move32();
- }
-
- IF( EQ_32( output_Fs, 48000 ) )
- {
- interpolate_3_over_2_allpass_32( outputHB_fx, length, outputHB_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 );
- }
- ELSE IF( EQ_32( output_Fs, 16000 ) )
- {
- Decimate_allpass_steep_fx32( outputHB_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, outputHB_fx );
- }
-
- return;
-}
-void GenTransition_WB_fixed(
- TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
- Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */
- const Word32 output_Fs /* i : output sampling rate */
-)
-{
- Word16 i, length;
- Word32 speech_buf_16k1_fx[SHB_OVERLAP_LEN], speech_buf_16k2_fx[2 * SHB_OVERLAP_LEN];
- Word32 upsampled_synth_fx[L_FRAME48k];
-
- /* set targeted length of transition signal */
- length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) );
-
- /* upsample overlap snippet */
- Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx );
- Interpolate_allpass_steep_32( speech_buf_16k1_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, SHB_OVERLAP_LEN, speech_buf_16k2_fx );
-
- /* perform spectral flip and downmix with overlap snippet to match HB synth */
- FOR( i = 0; i < SHB_OVERLAP_LEN; i++ )
- {
- IF( i % 2 == 0 )
- {
- speech_buf_16k2_fx[i] = L_negate( speech_buf_16k2_fx[i] );
- move32();
- }
- ELSE
- {
- speech_buf_16k2_fx[i] = speech_buf_16k2_fx[i];
- move32();
- }
- }
-
- /* cross fade of overlap snippet and mirrored HB synth from previous frame */
- FOR( i = 0; i < L_SHB_LAHEAD; i++ )
- {
- outputHB_fx[i] = L_add( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_fx[i] ), Mpy_32_16_1( speech_buf_16k2_fx[i], window_shb_fx[L_SHB_LAHEAD - 1 - i] ) );
- move32();
- outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 );
- move32();
- }
-
- /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */
- FOR( ; i < length; i++ )
- {
- outputHB_fx[i] = hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i];
- move32();
- outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 );
- move32();
- }
-
- /* upsampling if necessary */
- IF( EQ_32( output_Fs, 32000 ) )
- {
- Interpolate_allpass_steep_32( outputHB_fx, hBWE_TD->mem_resamp_HB_fx_32, L_FRAME16k, upsampled_synth_fx );
- Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME32k );
- }
- ELSE IF( EQ_32( output_Fs, 48000 ) )
- {
- interpolate_3_over_1_allpass_32( outputHB_fx, L_FRAME16k, upsampled_synth_fx, hBWE_TD->mem_resamp_HB_fx_32 );
- Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME48k );
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------*
- * td_bwe_dec_init()
- *
- * Initialize TD BWE state structure at the decoder
- *-------------------------------------------------------------------*/
diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c
index 28ac016711566fe8063b8cbd586dd718ab271df4..cc9b681fba0ff907e5ca3a4cd863242a66e6bba6 100644
--- a/lib_dec/swb_tbe_dec_fx.c
+++ b/lib_dec/swb_tbe_dec_fx.c
@@ -31,6 +31,11 @@ Word16 dotp_loc(
const Word16 n /* i : vector length */
);
+void find_max_mem_dec_m3(
+ Decoder_State *st,
+ Word16 *n_mem3 );
+
+
/* gain shape concealment code */
static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, Word32 *GainFrame );
@@ -3695,12 +3700,12 @@ static void gradientGainShape(
IF( GT_16( 8192, tmp ) )
{
- GainShape[add( i * 4, j )] = shl( tmp, 2 );
+ GainShape[i * 4 + j] = shl( tmp, 2 );
move16(); /* (GainShapeTemp[i]*0.6)>>1 */
}
ELSE
{
- GainShape[add( i * 4, j )] = 32767;
+ GainShape[i * 4 + j] = 32767;
move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */
}
}
@@ -3716,12 +3721,12 @@ static void gradientGainShape(
{
IF( LT_16( GainShapeTemp[i], 16384 ) )
{
- GainShape[add( i * 4, j )] = shl( GainShapeTemp[i], 1 );
+ GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 );
move16();
}
ELSE
{
- GainShape[add( i * 4, j )] = 32767;
+ GainShape[i * 4 + j] = 32767;
move16();
}
}
@@ -3750,12 +3755,12 @@ static void gradientGainShape(
{
IF( LT_16( GainShapeTemp[i], 16384 ) )
{
- GainShape[add( i * 4, j )] = shl( GainShapeTemp[i], 1 );
+ GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 );
move16();
}
ELSE
{
- GainShape[add( i * 4, j )] = 32767;
+ GainShape[i * 4 + j] = 32767;
move16();
}
}
@@ -5230,10 +5235,7 @@ void td_bwe_dec_init_ivas_fx(
void td_bwe_dec_init_fx(
Decoder_State *st_fx, /* i/o: SHB decoder structure */
TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
-#ifdef ADD_IVAS_BWE
- const Word16 extl, /* i : BWE extension layer */
-#endif
- const Word32 output_Fs /* i : output sampling rate */
+ const Word32 output_Fs /* i : output sampling rate */
)
{
Word16 i;
@@ -5300,3 +5302,2019 @@ void td_bwe_dec_init_fx(
return;
}
+
+/*-------------------------------------------------------------------*
+ * ResetSHBbuffer_Dec()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static void calc_tilt_bwe_fx_loc(
+ const Word32 *sp_fx, /* i : input signal : Q11 */
+ Word32 *tilt_fx, /* o : signal tilt : tilt_fx_q */
+ Word16 *tilt_fx_q, /* o : signal tilt */
+ const Word16 N /* i : signal length : Q0 */
+)
+{
+ Word16 i;
+ Word64 r0_fx, r1_fx;
+
+ r0_fx = EPSILON_FX_SMALL;
+ move64();
+ FOR( i = 0; i < N; i++ )
+ {
+ r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); /*Q11*2 - 1*/
+ }
+ r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); /*Q11*/
+ FOR( i = 2; i < N; i++ )
+ {
+ IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ) /*Q11*/, L_sub( sp_fx[i - 1], sp_fx[i - 2] ) /*Q11*/ ) /*Q11 * 2 - 1*/ < 0 )
+ {
+ r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); /*Q11*/
+ }
+ }
+ Word16 headroom_left_r0 = W_norm( r0_fx );
+ Word16 headroom_left_r1 = W_norm( r1_fx );
+ Word16 r0_q = 0, r1_q = 0;
+ move16();
+ move16();
+ IF( LT_16( headroom_left_r0, 32 ) )
+ {
+ r0_fx = W_shr( r0_fx, sub( 32, headroom_left_r0 ) );
+ r0_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_r0 ) ) );
+ }
+ ELSE
+ {
+ r0_q = 31 - ( 2 * OUTPUT_Q );
+ move16();
+ }
+
+ IF( LT_16( headroom_left_r1, 32 ) )
+ {
+ r1_fx = W_shr( r1_fx, sub( 32, headroom_left_r1 ) );
+ r1_q = sub( OUTPUT_Q, sub( 32, headroom_left_r1 ) );
+ }
+ ELSE
+ {
+ r1_q = OUTPUT_Q;
+ move16();
+ }
+ Word32 temp_r0_inv = ISqrt32( W_extract_l( r0_fx ), &r0_q );
+ Word32 res = Mpy_32_32( W_extract_l( r1_fx ), temp_r0_inv );
+ // Word16 res_q = r1_q + ( r0_q < 0 ? ( 31 + ( -1 * r0_q ) ) : r0_q ) - 31;
+ Word16 res_q;
+ IF( r0_q < 0 )
+ {
+ res_q = add( r1_q, sub( add( 31, -r0_q ), 31 ) );
+ }
+ ELSE
+ {
+ res_q = add( r1_q, sub( r0_q, 31 ) );
+ }
+ Word16 norm_res = norm_l( res );
+ IF( norm_res > 0 )
+ {
+ *tilt_fx = L_shl_sat( res, norm_res );
+ move32();
+ *tilt_fx_q = add( res_q, norm_res );
+ move16();
+ }
+ ELSE
+ {
+ *tilt_fx = res;
+ move32();
+ *tilt_fx_q = res_q;
+ move16();
+ }
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * swb_tbe_dec()
+ *
+ * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module
+ *-------------------------------------------------------------------*/
+static void rescale_genSHB_mem_dec_ivas(
+ Decoder_State *st_fx,
+ Word16 sf /*Q0*/
+)
+{
+ Word16 i;
+ TD_BWE_DEC_HANDLE hBWE_TD;
+ hBWE_TD = st_fx->hBWE_TD;
+
+ FOR( i = 0; i < NL_BUFF_OFFSET; i++ )
+ {
+ hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf );
+ move16();
+ }
+
+ FOR( i = 0; i < 7; i++ )
+ {
+ hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf );
+ move16();
+ }
+
+ /* -- Apply memory scaling for 13.2 and 16.4k bps using sf ----*/
+ IF( LT_32( st_fx->total_brate, ACELP_24k40 ) )
+ {
+ FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf );
+ move16();
+ }
+
+ FOR( i = 0; i < L_SHB_LAHEAD; i++ )
+ {
+ hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf );
+ move16();
+ }
+ }
+
+ hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf );
+ move32();
+
+ hBWE_TD->tbe_demph_fx = shl_r( hBWE_TD->tbe_demph_fx, sf );
+ move16();
+ hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf );
+ move16();
+}
+
+void find_max_mem_dec_m3(
+ Decoder_State *st,
+ Word16 *n_mem3 )
+{
+ Word16 i;
+ // Word16 n_mem_32;
+ Word16 tempQ15;
+ Word16 max3;
+ // Word32 tempQ32, Lmax3;
+ TD_BWE_DEC_HANDLE hBWE_TD;
+ hBWE_TD = st->hBWE_TD;
+
+ /* --------------------------------------------------------------*/
+ /* Find headroom for synthesis stage associated with these memories:
+ 1. st->syn_overlap_fx*/
+ max3 = 0;
+ move16();
+ /* find max in prev overlapSyn */
+ FOR( i = 0; i < L_SHB_LAHEAD; i++ )
+ {
+ tempQ15 = abs_s( hBWE_TD->syn_overlap_fx[i] );
+ max3 = s_max( max3, tempQ15 );
+ }
+ /* find max in prev genSHBsynth_state_lsyn_filt_shb_local_fx */
+
+ /* estimate the norm for 16-bit memories */
+ *n_mem3 = norm_s( max3 );
+ move16();
+ if ( max3 == 0 )
+ {
+ *n_mem3 = 15;
+ move16();
+ }
+}
+
+/*-------------------------------------------------------------------*
+ * ivas_swb_tbe_dec_fx()
+ *
+ * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module
+ *-------------------------------------------------------------------*/
+void ivas_swb_tbe_dec_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */
+ const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */
+ Word16 Q_exc,
+ const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */
+ const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */
+ Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/
+ Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */
+ Word16 *pitch_buf_fx, /* i : Q6 */
+ Word16 *Q_white_exc )
+{
+ Word16 i, j, cnt, n;
+ Word16 stemp;
+ TD_BWE_DEC_HANDLE hBWE_TD;
+ Word32 shaped_shb_excitation_fx_32[L_FRAME16k + L_SHB_LAHEAD];
+ Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET];
+ Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD];
+ Word16 lsf_shb_fx[LPC_SHB_ORDER], lpc_shb_fx[LPC_SHB_ORDER + 1], GainShape_fx[NUM_SHB_SUBFR]; // Q12,Q12,Q15
+ Word32 GainFrame_fx; // Q18
+ Word32 error_fx[L_FRAME32k];
+ Word16 ener_fx;
+ Word32 L_ener;
+ Word16 is_fractive;
+ Word32 prev_pow_fx, curr_pow_fx, Lscale;
+ Word16 scale_fx;
+ Word16 max_val, temp_fx, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD];
+ Word32 curr_frame_pow_fx;
+ Word16 curr_frame_pow_exp;
+ Word32 L_prev_ener_shb;
+ Word16 vf_modified_fx[NB_SUBFR16k];
+ Word16 f_fx, inc_fx;
+ Word32 GainFrame_prevfrm_fx;
+ Word32 tilt_swb_fec_32_fx;
+ Word16 tilt_swb_fec_fx_q;
+ Word16 tilt_swb_fec_fx;
+ Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */
+ Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER];
+ Word16 lpc_shb_sf_fx[4 * ( LPC_SHB_ORDER + 1 )];
+ const Word16 *ptr_lsp_interp_coef_fx;
+ Word32 shb_ener_sf_32;
+ Word16 shb_res_gshape_fx[NB_SUBFR16k];
+ Word16 mixFactors_fx;
+ Word16 vind;
+ Word16 shb_res_dummy_fx[L_FRAME16k];
+ Word16 shaped_shb_excitationTemp_fx[L_FRAME16k];
+ Word32 ener_tmp_fx[NUM_SHB_SUBGAINS];
+ Word16 GainShape_tmp_fx[NUM_SHB_SUBGAINS];
+ Word16 pitch_fx;
+ Word16 l_subframe;
+ Word16 formant_fac_fx;
+ Word16 synth_scale_fx;
+ Word16 lsf_diff_fx[LPC_SHB_ORDER], w_fx[LPC_SHB_ORDER];
+ Word16 refl_fx[M];
+ Word16 tilt_para_fx;
+ Word16 *nlExc16k_fx, *mixExc16k_fx;
+ Word16 MSFlag;
+ Word16 feedback_fx;
+ Word16 GainShape_tilt_fx;
+
+ // scaling
+ Word16 exp, tmp;
+ Word16 tmp1, tmp2;
+ Word16 mean_vf;
+ Word32 Lmax, L_tmp;
+ Word16 frac;
+ Word32 L_tmp1, L_tmp2;
+ Word16 Q_bwe_exc;
+ Word16 Q_bwe_exc_fb;
+ Word16 Q_shb;
+ Word16 n_mem, n_mem2, n_mem3, Qx, sc;
+ Word16 expa, expb;
+ Word16 fraca, fracb;
+ Word16 exp_ener, inv_ener;
+
+ hBWE_TD = st->hBWE_TD;
+
+ /* initializations */
+ GainFrame_fx = 0;
+ move32();
+ mixFactors_fx = 0;
+ move16();
+ shb_ener_sf_32 = 0;
+ move32();
+ set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k );
+ if ( st->hTdCngDec != NULL )
+ {
+ st->hTdCngDec->shb_dtx_count = 0;
+ move16();
+ }
+ is_fractive = 0;
+ move16();
+
+ IF( hStereoICBWE != NULL )
+ {
+ nlExc16k_fx = hStereoICBWE->nlExc16k_fx;
+ mixExc16k_fx = hStereoICBWE->mixExc16k_fx;
+ MSFlag = hStereoICBWE->MSFlag;
+ move16();
+ }
+ ELSE
+ {
+ nlExc16k_fx = NULL;
+ mixExc16k_fx = NULL;
+ MSFlag = 0;
+ move16();
+ }
+
+ /* find tilt */
+ calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME );
+ tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) );
+ test();
+ if ( st->bfi && st->clas_dec != UNVOICED_CLAS )
+ {
+ tilt_swb_fec_fx = hBWE_TD->tilt_swb_fec_fx;
+ move16();
+ }
+
+ /* WB/SWB bandwidth switching */
+ test();
+ test();
+ IF( ( GT_16( st->tilt_wb_fx, 10240 /*5 in Q11*/ ) && ( EQ_16( st->clas_dec, UNVOICED_CLAS ) ) ) || GT_16( st->tilt_wb_fx, 20480 /*10 in Q11*/ ) )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( ( st->prev_fractive == 0 ) &&
+ ( LT_32( st->prev_enerLH_fx, L_shl( st->enerLH_fx, 1 ) ) && GT_32( st->prev_enerLH_fx, L_shr( st->enerLH_fx, 1 ) ) && LT_32( st->prev_enerLL_fx, L_shl( st->enerLL_fx, 1 ) ) && GT_32( st->prev_enerLL_fx, L_shr( st->enerLL_fx, 1 ) ) ) ) ||
+ ( EQ_16( st->prev_fractive, 1 ) &&
+ GT_32( L_shr( st->prev_enerLH_fx, 2 ), Mult_32_16( st->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/
+ || ( GT_32( L_shr( st->enerLL_fx, 1 ), Mult_32_16( st->enerLH_fx, 24576 ) ) && /*24576 = 1.5 in Q14*/
+ LT_16( st->tilt_wb_fx, 20480 ) ) /* 20480 = 10 in Q11*/
+ )
+ {
+ is_fractive = 0;
+ }
+ ELSE
+ {
+ is_fractive = 1;
+ }
+ move16();
+ }
+
+ /* WB/SWB bandwidth switching */
+ IF( st->bws_cnt > 0 )
+ {
+ f_fx = 1489; /*1.0f / 22.0f in Q15*/
+ move16();
+ inc_fx = 1489; /*1.0f / 22.0f in Q15*/
+ move16();
+
+ IF( EQ_16( is_fractive, 1 ) )
+ {
+ Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER );
+ }
+ ELSE
+ {
+ FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/
+ move16();
+ f_fx = add( f_fx, inc_fx ); /*Q15*/
+ }
+ }
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && !( ( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 ) && L_sub( st->prev_enerLH_fx, ( L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) ) || st->last_core != ACELP_CORE || ( ( st->last_core == ACELP_CORE ) && GT_32( abs( L_sub( st->last_core_brate, st->core_brate ) ), 3600 ) ) || EQ_16( s_xor( is_fractive, st->prev_fractive ), 1 ) )
+ {
+ set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); /*0.3536f in Q15*/
+ }
+ ELSE
+ {
+ if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) /*0.3536f in Q15*/
+ {
+ hBWE_TD->prev_GainShape_fx = 11587; /*0.3536f in Q15*/
+ move16();
+ }
+ set16_fx( GainShape_fx, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR );
+ }
+
+ Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER );
+ set16_fx( shb_res_gshape_fx, 3277 /*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */
+ }
+ ELSE
+ {
+ test();
+ IF( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) )
+ {
+ f_fx = 1489; /*Q15*/
+ move16();
+ inc_fx = 1489; /*Q15*/
+ move16();
+ FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/
+ move16();
+ f_fx = add( f_fx, inc_fx );
+ }
+ }
+
+ IF( !st->bfi )
+ {
+ IF( st->use_partial_copy )
+ {
+ IF( NE_16( st->last_extl, SWB_TBE ) )
+ {
+ hBWE_TD->GainFrame_prevfrm_fx = 0;
+ move32();
+ f_fx = 1489 /*0.045454f Q15*/;
+ move16();
+ inc_fx = 1489 /*0.045454f Q15*/;
+ move16();
+ FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/
+ move16();
+ f_fx = add( f_fx, inc_fx ); /*Q15*/
+ }
+ }
+ Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER );
+ set16_fx( GainShape_fx, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR );
+
+ IF( EQ_16( st->rf_frame_type, RF_NELP ) )
+ {
+ /* Frame gain */
+
+ GainFrame_fx = L_mac( SHB_GAIN_QLOW_FX, st->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX );
+ L_tmp = Mult_32_16( GainFrame_fx, 27213 ); /*Q16*/ /* 3.321928 in Q13 */
+
+ frac = L_Extract_lc( L_tmp, &exp );
+ L_tmp = Pow2( 30, frac );
+ GainFrame_fx = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && !st->prev_use_partial_copy && EQ_16( st->prev_coder_type, UNVOICED ) && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st->next_coder_type, GENERIC ) && EQ_16( st->last_extl, SWB_TBE ) )
+ {
+ GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6553 /*0.2f in Q15*/ ) );
+ }
+ }
+ ELSE
+ {
+ temp_fx = 0;
+ move16();
+ /* Frame gain */
+ SWITCH( st->rf_indx_tbeGainFr )
+ {
+ case 0:
+ GainFrame_fx = 131072; /* 0.5f in Q18 */
+ move32();
+ if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) )
+ {
+ temp_fx = 26214 /*0.8 Q15*/;
+ move16();
+ }
+ BREAK;
+ case 1:
+ GainFrame_fx = 524288; /* 2.0f in Q18 */
+ move32();
+ test();
+ if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) )
+ {
+ temp_fx = 26214 /*0.8 Q15*/;
+ move16();
+ }
+ BREAK;
+ case 2:
+ GainFrame_fx = 1048576; /* 4.0f in Q18 */
+ move32();
+ test();
+ if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) )
+ {
+ temp_fx = 26214 /*0.8 Q15*/;
+ move16();
+ }
+ BREAK;
+ case 3:
+ GainFrame_fx = 2097152; /* 8.0f in Q18 */
+ move32();
+ test();
+ if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) )
+ {
+ temp_fx = 26214 /*0.8 Q15*/;
+ move16();
+ }
+ BREAK;
+ default:
+ fprintf( stderr, "RF SWB-TBE gain bits not supported." );
+ }
+
+ IF( EQ_16( st->last_extl, SWB_TBE ) )
+ {
+ GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp_fx ), Mult_32_16( GainFrame_fx, sub( 32767, temp_fx ) ) );
+ /*Q18*/
+ }
+
+ IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) )
+ {
+ if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 /*8.0f in Q18*/ ) && LT_32( GainFrame_fx, 3059606 /*11.67f in Q18*/ ) )
+ {
+ GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 /*0.3f in Q15*/ ); // Q18
+ }
+ }
+ }
+ }
+ ELSE
+ {
+ /* de-quantization */
+ ivas_dequantizeSHBparams_fx_9_1( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp,
+ &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag );
+ if ( hStereoICBWE != NULL )
+ {
+ hStereoICBWE->MSFlag = MSFlag;
+ move16();
+ }
+ }
+ }
+ ELSE
+ {
+ Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER );
+ test();
+ IF( EQ_16( st->codec_mode, MODE1 ) && ( st->element_mode == EVS_MONO ) )
+ {
+ gradientGainShape( st, GainShape_fx, &GainFrame_fx );
+ }
+ ELSE
+ {
+ FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
+ {
+ FOR( j = 0; j < 4; j++ )
+ {
+ GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] );
+ move16();
+ }
+ }
+ IF( GT_16( tilt_swb_fec_fx, ( 8 << 11 ) ) ) /* tilt_swb_fec_fx in Q11 */
+ {
+ IF( EQ_16( st->nbLostCmpt, 1 ) )
+ {
+ GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 19661 /*0.6f Q15*/ );
+ }
+ ELSE IF( EQ_16( st->nbLostCmpt, 2 ) )
+ {
+ GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 11469 /*0.35f Q15*/ );
+ }
+ ELSE
+ {
+ GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 6554 /*0.2f Q15*/ );
+ }
+ GainFrame_fx = Mult_32_16( GainFrame_fx, st->cummulative_damping );
+ }
+ ELSE
+ {
+ GainFrame_fx = hBWE_TD->GainFrame_prevfrm_fx;
+ move32(); /* gain locking */
+ }
+ }
+
+ IF( GE_32( st->extl_brate, SWB_TBE_2k8 ) )
+ {
+ test();
+ IF( EQ_16( st->codec_mode, MODE1 ) && ( st->element_mode == EVS_MONO ) )
+ {
+ L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/
+ tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */
+ tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/
+ i = sub( norm_s( tmp1 ), 1 );
+ tmp1 = shl( tmp1, i ); /* Qi */
+ IF( tmp == 0 )
+ {
+ tmp = 32767 /*1.0f Q15*/;
+ move16(); /*Q15*/
+ }
+ ELSE
+ {
+ scale_fx = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */
+ scale_fx = s_max( scale_fx, 0 );
+ tmp = shl_sat( scale_fx, sub( sub( 15, exp ), i ) ); /*Q15*/
+ }
+ scale_fx = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */
+ test();
+ IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) ||
+ GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) )
+ {
+ shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale_fx );
+
+ if ( GT_16( st->nbLostCmpt, 1 ) )
+ {
+ shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 );
+ }
+ }
+ ELSE
+ {
+ L_tmp = L_mult( scale_fx, scale_fx ); /* Q29 */
+ shb_ener_sf_32 = L_shl( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, round_fx( L_tmp ) ), 2 );
+ }
+ }
+ ELSE
+ {
+ test();
+ IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) ||
+ GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) )
+ {
+ shb_ener_sf_32 = L_shr( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st->cummulative_damping ), 1 );
+ }
+ ELSE
+ {
+ shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st->cummulative_damping );
+ }
+ }
+ }
+
+ shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ );
+ mixFactors_fx = hBWE_TD->prev_mixFactors_fx;
+ move16();
+
+ IF( EQ_16( st->codec_mode, MODE1 ) )
+ {
+ set16_fx( shb_res_gshape_fx, 3277 /*0.2f Q14*/, 5 ); /* Q14 */
+ }
+ ELSE
+ {
+ set16_fx( shb_res_gshape_fx, 16384 /*1.0f Q14*/, 5 ); /* Q14 */
+ }
+ }
+ }
+
+ /* get the gainshape delay */
+ Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 );
+ FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
+ {
+ st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; /*Q15*/
+ move16();
+ }
+
+ L_tmp = L_mult( voice_factors_fx[0], 8192 );
+ L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 );
+ L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 );
+ mean_vf = mac_r( L_tmp, voice_factors_fx[3], 8192 );
+
+ Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k );
+
+ test();
+ IF( EQ_16( st->coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) )
+ {
+ FOR( i = 1; i < NB_SUBFR; i++ )
+ {
+ L_tmp = L_mult( voice_factors_fx[i], 26214 /*0.8f Q15*/ );
+ vf_modified_fx[i] = mac_r( L_tmp, voice_factors_fx[i - 1], 6554 /*0.2f Q15*/ );
+ move16();
+ }
+
+ IF( st->L_frame != L_FRAME )
+ {
+ L_tmp = L_mult( voice_factors_fx[4], 26214 /*0.8f Q15*/ );
+ vf_modified_fx[4] = mac_r( L_tmp, voice_factors_fx[3], 6554 /*0.2f Q15*/ );
+ move16();
+ }
+ }
+
+ test();
+ IF( st->use_partial_copy && st->nelp_mode_dec )
+ {
+ set16_fx( vf_modified_fx, 0, NB_SUBFR16k );
+ }
+
+ /* SHB LSF from current frame; and convert to LSP for interpolation */
+ E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER );
+
+ test();
+ IF( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) )
+ {
+ /* SHB LSP values from prev. frame for interpolation */
+ Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER );
+ }
+ ELSE
+ {
+ /* Use current frame's LSPs; in effect no interpolation */
+ Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER );
+ }
+
+ test();
+ test();
+ test();
+ IF( ( st->bws_cnt == 0 ) && ( st->bws_cnt1 == 0 ) && ( st->prev_use_partial_copy == 0 ) && ( st->use_partial_copy == 0 ) )
+ {
+ lsf_diff_fx[0] = 16384;
+ move16(); /*Q15*/
+ lsf_diff_fx[LPC_SHB_ORDER - 1] = 16384;
+ move16(); /*Q15*/
+ FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ )
+ {
+ lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] );
+ move16();
+ }
+
+ a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl_fx, M );
+ tmp = add( 16384, shr( refl_fx[0], 1 ) ); /*Q14*/
+ tmp1 = mult( 27425, tmp );
+ tmp1 = mult( tmp1, tmp ); /*Q10*/
+ tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/
+ tilt_para_fx = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/
+
+ test();
+ IF( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) )
+ {
+ FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ )
+ {
+ hBWE_TD->prev_lsf_diff_fx[i - 1] = shr( lsf_diff_fx[i], 1 );
+ move16();
+ }
+ }
+
+ IF( LE_32( st->extl_brate, FB_TBE_1k8 ) )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( st->coder_type, TRANSITION ) || LT_16( tilt_para_fx, 1024 ) ) ) &&
+ !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para_fx, 5120 ) ) )
+ {
+ FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ )
+ {
+ IF( LT_16( lsf_diff_fx[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) )
+ {
+ tmp = mult( 26214, lsf_diff_fx[i] );
+
+ test();
+ IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */
+ {
+ st->BER_detect = 1;
+ move16();
+ tmp = 0;
+ move16();
+ }
+ ELSE
+ {
+ tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] );
+ }
+
+ tmp = s_max( tmp, 16384 );
+ w_fx[i] = s_min( tmp, 32767 );
+ move16();
+ }
+ ELSE
+ {
+ tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] );
+
+ test();
+ IF( ( lsf_diff_fx[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */
+ {
+ st->BER_detect = 1;
+ move16();
+ tmp = 0;
+ move16();
+ }
+ ELSE
+ {
+ tmp = div_s( tmp, lsf_diff_fx[i] );
+ }
+
+ tmp = s_max( tmp, 16384 );
+ w_fx[i] = s_min( tmp, 32767 );
+ move16();
+ }
+ }
+ w_fx[0] = w_fx[1];
+ move16();
+ w_fx[LPC_SHB_ORDER - 1] = w_fx[LPC_SHB_ORDER - 2];
+ move16();
+
+ FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w_fx[i] ) );
+ tmp2 = mult( lsp_shb_2_fx[i], w_fx[i] );
+ lsp_temp_fx[i] = add( tmp1, tmp2 );
+ move16();
+ }
+ }
+ ELSE
+ {
+ Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER );
+ }
+
+ /* convert from lsp to lsf */
+ lsp2lsf_fx( lsp_temp_fx, lsf_shb_fx, LPC_SHB_ORDER, 1 );
+ }
+
+ Copy( lsf_diff_fx + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 );
+ hBWE_TD->prev_tilt_para_fx = tilt_para_fx;
+ move16();
+ }
+ ELSE
+ {
+ Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER );
+ }
+
+ IF( GE_32( st->extl_brate, SWB_TBE_2k8 ) )
+ {
+ /* SHB LSP interpolation */
+ ptr_lsp_interp_coef_fx = interpol_frac_shb; /*Q15*/
+ FOR( j = 0; j < 4; j++ )
+ {
+ FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ L_tmp = L_mult( lsp_shb_1_fx[i], ( *ptr_lsp_interp_coef_fx ) );
+ lsp_temp_fx[i] = mac_r( L_tmp, lsp_shb_2_fx[i], ( *( ptr_lsp_interp_coef_fx + 1 ) ) );
+ move16();
+ }
+ ptr_lsp_interp_coef_fx += 2;
+
+ tmp = i_mult( j, ( LPC_SHB_ORDER + 1 ) );
+ /* convert LSPs to LP coefficients */
+ E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER );
+#ifndef FIX_1100_REMOVE_LPC_RESCALING
+ /* Bring the LPCs to Q12 */
+ Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) );
+ lpc_shb_sf_fx[i_mult( j, ( LPC_SHB_ORDER + 1 ) )] = ONE_IN_Q12; // recheck this
+ move16();
+#endif
+ }
+ }
+
+ /* Save the SWB LSP values from current frame for interpolation */
+ Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER );
+
+ /* save the shb_ener and mixFactor values */
+ hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx;
+ move32();
+ hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx;
+ move32();
+ hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32;
+ move32();
+ hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape_fx[4];
+ move16();
+ hBWE_TD->prev_mixFactors_fx = mixFactors_fx;
+ move16();
+
+ /* SWB CNG/DTX - update memories */
+ IF( st->hTdCngDec != NULL )
+ {
+ Copy( st->hTdCngDec->lsp_shb_prev_fx, st->hTdCngDec->lsp_shb_prev_prev_fx, LPC_SHB_ORDER );
+ Copy( lsf_shb_fx, st->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER );
+ }
+
+ /* convert LSPs back into LP coeffs */
+ E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER );
+ Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */
+ lpc_shb_fx[0] = ONE_IN_Q12;
+ move16();
+
+ test();
+ IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) )
+ {
+ Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1
+ vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/
+ /* i: mixFactors_fx in Q15 */
+ /* o: vind in Q0 */
+ }
+ ELSE
+ {
+ vind = shl( mixFactors_fx, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*8*/
+ /* i: mixFactors_fx in Q15 */
+ /* o: vind in Q0 */
+ }
+
+ /* Determine formant PF strength */
+ formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx );
+ /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */
+ IF( GT_32( st->total_brate, ACELP_32k ) )
+ {
+ FOR( j = 0; j < 4; j++ )
+ {
+ Copy( lpc_shb_fx, &lpc_shb_sf_fx[i_mult( j, ( LPC_SHB_ORDER + 1 ) )], LPC_SHB_ORDER + 1 );
+ }
+ }
+
+ /* From low band excitation, generate highband excitation */
+
+ /* -------- start of memory rescaling -------- */
+ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */
+ Lmax = 0;
+ move32();
+ FOR( cnt = 0; cnt < L_FRAME32k; cnt++ )
+ {
+ Lmax = L_max( Lmax, L_abs( bwe_exc_extended_fx[cnt] ) );
+ }
+ Q_bwe_exc = norm_l( Lmax );
+ if ( Lmax == 0 )
+ {
+ Q_bwe_exc = 31;
+ move16();
+ }
+ Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) );
+ find_max_mem_dec( st, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */
+
+ tmp = add( st->prev_Q_bwe_exc, n_mem );
+ if ( GT_16( Q_bwe_exc, tmp ) )
+ {
+ Q_bwe_exc = tmp;
+ move16();
+ }
+
+ /* rescale the memories if Q_bwe_exc is different from previous frame */
+ sc = sub( Q_bwe_exc, st->prev_Q_bwe_exc );
+ IF( sc != 0 )
+ {
+ rescale_genSHB_mem_dec_ivas( st, sc );
+ }
+
+ /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */
+ sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) );
+
+ FOR( cnt = 0; cnt < L_FRAME32k; cnt++ )
+ {
+ bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) );
+ move16();
+ }
+
+ /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */
+
+ /* save the previous Q factor (32-bit) of the buffer */
+ st->prev_Q_bwe_exc = Q_bwe_exc;
+ move16();
+
+ Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */
+
+ /* -------- end of rescaling memories -------- */
+
+ Q_bwe_exc_fb = st->prev_Q_bwe_exc_fb;
+ move16();
+
+ Q_shb = 0;
+ move16();
+
+ Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD );
+ GenShapedSHBExcitation_ivas_dec_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx,
+ hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
+ st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl,
+ &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32,
+ shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx,
+ &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st->prev_Q_bwe_syn, st->total_brate, st->prev_bfi,
+ st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag,
+ NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL );
+
+ *Q_white_exc = Q_bwe_exc_fb;
+ move16();
+ IF( EQ_16( st->extl, FB_TBE ) )
+ {
+ st->prev_Q_bwe_exc_fb = Q_bwe_exc_fb;
+ move16();
+ }
+ ELSE
+ {
+ /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value.
+ 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/
+ st->prev_Q_bwe_exc_fb = 51;
+ move16();
+ }
+
+ /* rescale the TBE post proc memory */
+ FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st->prev_Q_bwe_syn ) );
+ move16();
+ }
+ /* fill-in missing SHB excitation */
+ test();
+ test();
+ IF( ( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) && LE_32( st->last_core_brate, SID_2k40 ) )
+ {
+ Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, shaped_shb_excitation_fx, L_SHB_LAHEAD );
+ }
+
+ IF( hStereoICBWE != NULL )
+ {
+ Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, hStereoICBWE->shbSynthRef_fx, L_FRAME16k );
+ }
+
+ test();
+ IF( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) )
+ {
+ FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k )
+ {
+ /* TD BWE post-processing */
+ PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx,
+ hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx );
+ }
+
+ Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */
+
+ tmp = sub( shl( Q_bwe_exc, 1 ), 31 + 16 );
+ prev_pow_fx = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */
+ curr_pow_fx = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */
+ FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ )
+ {
+ prev_pow_fx = L_mac0_sat( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /*2*Q_bwe_exc*/
+ curr_pow_fx = L_mac0_sat( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */
+ }
+
+ if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) )
+ {
+ curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* Q(2*Q_bwe_exc) */
+ }
+
+ Lscale = root_a_over_b_fx( curr_pow_fx,
+ shl( Q_bwe_exc, 1 ),
+ prev_pow_fx,
+ shl( Q_bwe_exc, 1 ),
+ &exp );
+
+ FOR( i = 0; i < L_SHB_LAHEAD; i++ )
+ {
+ L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */
+ shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */
+ move16();
+ }
+ IF( exp < 0 )
+ {
+ Lscale = L_shl( Lscale, exp );
+ exp = 0;
+ move16();
+ }
+ FOR( ; i < L_SHB_LAHEAD + 10; i++ )
+ {
+ temp_fx = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */
+ L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp_fx ); /* Q31-exp */
+ temp_fx = sub( 32767 /*1.0f Q15*/, temp_fx );
+ Lscale = L_add( Mult_32_16( Lscale, temp_fx ), L_tmp1 );
+ L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */
+ shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */
+ move16();
+ }
+ }
+ ELSE
+ {
+ /* reset the PF memories if the PF is not running */
+ set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER );
+ hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14;
+ move16();
+ set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER );
+ }
+
+ /* Update SHB excitation */
+ Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */
+ l_subframe = L_FRAME16k / NUM_SHB_SUBGAINS;
+ move16();
+ L_ener = EPSILON_FX_SMALL;
+ move32();
+
+ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
+ {
+ L_tmp = 0;
+ move32();
+ ener_tmp_fx[i] = EPSILON_FX_SMALL;
+ move32();
+
+ Word64 tmp64 = 0;
+ move64();
+ FOR( j = 0; j < l_subframe; j++ )
+ {
+ tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation_fx[add( i_mult( i, l_subframe ), j )], shaped_shb_excitation_fx[add( i_mult( i, l_subframe ), j )] ); /* 2*Q_bwe_exc */
+ }
+ L_tmp = W_sat_l( tmp64 );
+
+ L_tmp = Mult_32_16( L_tmp, 410 /*0.0125 Q15*/ ); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */
+ IF( L_tmp != 0 )
+ {
+ exp = norm_l( L_tmp );
+ tmp = extract_h( L_shl( L_tmp, exp ) );
+ exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) );
+
+ tmp = div_s( 16384, tmp );
+ L_tmp = L_deposit_h( tmp );
+ L_tmp = Isqrt_lc( L_tmp, &exp );
+ ener_tmp_fx[i] = L_shl_sat( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */
+ move32();
+ L_ener = L_add_sat( L_ener, L_shr( ener_tmp_fx[i], 2 ) ); /* 2*Q_bwe_exc */
+ }
+ }
+ ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */
+ /* WB/SWB bandwidth switching */
+ IF( st->bws_cnt > 0 )
+ {
+ IF( is_fractive == 0 )
+ {
+ IF( GT_16( st->tilt_wb_fx, 2048 ) ) /*assuming st->tilt_wb_fx in Q11*/
+ {
+ st->tilt_wb_fx = 2048;
+ move16();
+ }
+ ELSE IF( LT_16( st->tilt_wb_fx, 1024 ) )
+ {
+ st->tilt_wb_fx = 1024;
+ move16();
+ }
+ test();
+ if ( EQ_16( st->prev_fractive, 1 ) && GT_16( st->tilt_wb_fx, 1024 ) )
+ {
+ st->tilt_wb_fx = 1024;
+ move16();
+ }
+ }
+ ELSE
+ {
+ IF( GT_16( st->tilt_wb_fx, 8192 ) )
+ {
+ IF( st->prev_fractive == 0 )
+ {
+ st->tilt_wb_fx = 8192;
+ move16();
+ }
+ ELSE
+ {
+ st->tilt_wb_fx = 16384;
+ move16();
+ }
+ }
+ ELSE
+ {
+ st->tilt_wb_fx = shl( st->tilt_wb_fx, 2 );
+ move16();
+ }
+ }
+
+ IF( ener_fx != 0 )
+ {
+ L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 13 ) ); /* 2+11 +st->Q_syn2 -13 = st->Q_syn2*/
+ exp_ener = norm_s( ener_fx );
+ tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/
+ inv_ener = shr( div_s( 16384, tmp ), 1 ); /*Q(15+14-2-exp-1) = 26 - exp*/
+
+ test();
+ IF( GT_32( L_tmp, st->enerLH_fx ) ) /*st->Q_syn2*/
+ {
+ st->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st->enerLH_fx, inv_ener ), sub( sub( st->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/
+ move16();
+ /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/
+ }
+ ELSE IF( LT_32( L_tmp, Mult_32_16( st->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) )
+ {
+ st->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st->enerLH_fx, inv_ener ), sub( sub( st->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/
+ move16();
+ /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/
+ }
+ L_tmp = L_mult0( st->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/
+ GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/
+ }
+ ELSE
+ {
+ GainFrame_prevfrm_fx = 0;
+ move32();
+ }
+
+ IF( EQ_16( is_fractive, 1 ) )
+ {
+ GainFrame_fx = L_shl( L_deposit_l( st->tilt_wb_fx ), 10 );
+ }
+ ELSE
+ {
+ GainFrame_fx = L_shl( L_deposit_l( st->tilt_wb_fx ), 8 );
+ }
+
+ test();
+ IF( EQ_16( ( is_fractive & st->prev_fractive ), 1 ) && GT_32( GainFrame_fx, GainFrame_prevfrm_fx ) )
+ {
+ GainFrame_fx = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) ); /* 18 +15 -15 = 18*/
+ }
+ ELSE
+ {
+ test();
+ test();
+ test();
+ test();
+ IF( ( LT_32( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) && GT_32( st->prev_enerLH_fx, L_shr( st->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st->prev_enerLL_fx, 1 ), st->enerLL_fx ) && GT_32( st->prev_enerLL_fx, L_shr( st->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st->prev_fractive ) == 0 ) )
+ {
+ GainFrame_fx = L_add( L_shr( GainFrame_fx, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) );
+ }
+ ELSE
+ {
+ test();
+ IF( ( is_fractive == 0 ) && EQ_16( st->prev_fractive, 1 ) )
+ {
+ L_tmp1 = L_shl( Mult_32_16( GainFrame_fx, 3277 ), 13 ); /* 31 */
+ L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */
+ GainFrame_fx = L_add( Mult_32_32( GainFrame_fx, L_tmp ), Mult_32_32( GainFrame_prevfrm_fx, L_tmp1 ) ); /* 18 */
+ }
+ ELSE
+ {
+ GainFrame_fx = L_add( L_shr( GainFrame_fx, 1 ), L_shr( L_min( GainFrame_prevfrm_fx, GainFrame_fx ), 1 ) ); /* 18 */
+ }
+ }
+ }
+
+ GainFrame_fx = Mult_32_16( GainFrame_fx, i_mult( sub( N_WS2N_FRAMES, st->bws_cnt ), 819 ) ); /*Q18*/
+ }
+ ELSE
+ {
+ IF( st->bws_cnt1 > 0 )
+ {
+ GainFrame_fx = Mult_32_16( GainFrame_fx, i_mult( st->bws_cnt1, 819 ) ); /*Q18*/
+ }
+ IF( GE_16( st->nbLostCmpt, 1 ) )
+ {
+ ener_fx = s_max( 1, ener_fx );
+ exp_ener = norm_s( ener_fx );
+ tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/
+ inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/
+ prev_ener_ratio_fx = L_shr( L_mult0( st->prev_ener_shb_fx, inv_ener ), add( sub( 9, exp_ener ), 1 ) ); /*Q: 1+27-exp-9+exp-1 = 18 */
+ }
+
+ IF( EQ_16( st->nbLostCmpt, 1 ) )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( st->clas_dec != UNVOICED_CLAS ) && NE_16( st->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) &&
+ ( ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st->enerLL_fx, 1 ), st->prev_enerLL_fx ) ) || ( GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st->enerLH_fx, 1 ), st->prev_enerLH_fx ) ) ) )
+ {
+ IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) ) /*18*/
+ {
+ GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 13107 ), Mult_32_16( GainFrame_fx, 19661 ) ); /*18*/
+ }
+ ELSE IF( GT_32( L_shr( prev_ener_ratio_fx, 1 ), GainFrame_fx ) )
+ {
+ GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) );
+ }
+ ELSE
+ {
+ GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) );
+ }
+
+ test();
+ IF( GT_16( tilt_swb_fec_fx, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) )
+ {
+ exp = norm_s( hBWE_TD->tilt_swb_fec_fx );
+ tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/
+ tmp = div_s( 16384, tmp ); /*Q(15+14-11-exp)*/
+ tmp = extract_h( L_shl( L_mult0( tmp, st->tilt_wb_fx ), sub( exp, 1 ) ) ); /*18 -exp +11 + exp -1 -16 =12; */
+ GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */
+ }
+ }
+ ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 4096 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) &&
+ ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) )
+ {
+ GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) );
+ }
+ }
+ ELSE IF( GT_16( st->nbLostCmpt, 1 ) )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) )
+ {
+ test();
+ IF( GT_16( tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) )
+ {
+ GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6554 /*0.2f in Q15*/ ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 /*4.0f in Q12*/ ), 3 ) ); /*Q18*/
+ }
+ ELSE
+ {
+ GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame_fx, 16384 ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 ), 3 ) ); /*Q18*/
+ }
+ }
+ ELSE IF( GT_32( prev_ener_ratio_fx, GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) )
+ {
+ test();
+ IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) )
+ {
+ GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 /*0.5f in Q15*/ ), Mult_32_16( GainFrame_fx, 16384 /*0.5f in Q15*/ ) ); /* Q18 */
+ }
+ ELSE
+ {
+ GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 /*0.2f in Q15*/ ), Mult_32_16( GainFrame_fx, 26214 /*0.8f in Q15*/ ) ); /* Q18 */
+ }
+ }
+ }
+ }
+
+ st->prev_fractive = is_fractive;
+ move16();
+
+ /* Adjust the subframe and frame gain of the synthesized shb signal */
+ /* Scale the shaped excitation */
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ L_tmp = L_mult( pitch_buf_fx[0], 8192 );
+ FOR( i = 1; i < NB_SUBFR; i++ )
+ {
+ L_tmp = L_mac( L_tmp, pitch_buf_fx[i], 8192 ); /* pitch_buf in Q6 x 0.25 in Q15 */
+ }
+ pitch_fx = round_fx( L_tmp ); /* Q6 */
+ }
+ ELSE
+ {
+ L_tmp = L_mult( pitch_buf_fx[0], 6554 );
+ FOR( i = 1; i < NB_SUBFR16k; i++ )
+ {
+ L_tmp = L_mac( L_tmp, pitch_buf_fx[i], 6554 ); /* pitch_buf in Q6 x 0.2 in Q15 */
+ }
+ pitch_fx = round_fx( L_tmp ); /* Q6 */
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( ( GE_32( st->extl_brate, SWB_TBE_2k8 ) && EQ_16( st->prev_coder_type, st->coder_type ) && NE_16( st->coder_type, UNVOICED ) ) || ( LT_32( st->extl_brate, SWB_TBE_2k8 ) && ( EQ_16( st->prev_coder_type, st->coder_type ) || ( EQ_16( st->prev_coder_type, VOICED ) && EQ_16( st->coder_type, GENERIC ) ) || ( EQ_16( st->prev_coder_type, GENERIC ) && EQ_16( st->coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st->extl, FB_TBE ) && NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) )
+ {
+ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
+ {
+ GainShape_tmp_fx[i] = GainShape_fx[i * 4]; /* Q15 */
+ move16();
+ }
+
+ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
+ {
+ L_tmp1 = Mult_32_16( ener_tmp_fx[i], GainShape_tmp_fx[i] ); /* (2*Q_bwe_exc) */
+ L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st->prev_ener_fx_Q) */
+ tmp = sub( shl( Q_bwe_exc, 1 ), shl( st->prev_ener_fx_Q, 1 ) );
+ L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */
+ IF( GT_32( L_tmp1, L_tmp2 ) )
+ {
+ L_tmp = L_tmp2;
+ move32();
+ if ( L_tmp2 < 0 )
+ {
+ L_tmp = L_negate( L_tmp2 );
+ }
+
+ expb = norm_l( L_tmp );
+ fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) );
+ expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */
+
+ expa = norm_l( ener_tmp_fx[i] );
+ fraca = extract_h( L_shl( ener_tmp_fx[i], expa ) );
+ expa = sub( 30, expa );
+
+ scale_fx = shr( sub( fraca, fracb ), 15 );
+ fracb = shl( fracb, scale_fx );
+ expb = sub( expb, scale_fx );
+
+ tmp = div_s( fracb, fraca );
+ exp = sub( sub( expb, expa ), 1 );
+ tmp = shl( tmp, exp );
+ GainShape_tmp_fx[i] = add( tmp, shr( GainShape_tmp_fx[i], 1 ) ); /* Q15 */
+ move16();
+ }
+
+ hBWE_TD->prev_ener_fx = ener_tmp_fx[i];
+ move32();
+ hBWE_TD->prev_GainShape_fx = GainShape_tmp_fx[i];
+ move16();
+ st->prev_ener_fx_Q = Q_bwe_exc;
+ move16();
+ }
+
+ FOR( i = 0; i < NUM_SHB_SUBFR; i++ )
+ {
+ Word16 idx = 0;
+ move16();
+ IF( i != 0 )
+ {
+ idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR );
+ }
+ GainShape_fx[i] = GainShape_tmp_fx[idx];
+ move16();
+ }
+ }
+ ELSE
+ {
+ st->prev_ener_fx_Q = Q_bwe_exc;
+ move16();
+ }
+ st->prev_Q_bwe_syn = Q_bwe_exc;
+ move16();
+
+
+ /* Gain shape smoothing after quantization */
+ test();
+ IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) )
+ {
+ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
+ {
+ GainShape_tmp_fx[i] = GainShape_fx[i * NUM_SHB_SUBGAINS];
+ move16();
+ }
+
+ lls_interp_n_fx( GainShape_tmp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp_fx, 1 );
+
+ test();
+ IF( GE_16( vind, 6 ) && LT_16( abs_s( GainShape_tilt_fx ), 3932 ) )
+ {
+ feedback_fx = 9830;
+ move16();
+ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ )
+ {
+ GainShape_fx[i] = add_sat( mult( sub( 32767, feedback_fx ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), mult( feedback_fx, GainShape_tmp_fx[i] ) );
+ move16();
+ }
+
+ FOR( i = NUM_SHB_SUBFR - 1; i > 0; i-- )
+ {
+ Word16 idx = 0;
+ move16();
+ IF( i != 0 )
+ {
+ idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR );
+ }
+ GainShape_fx[i] = GainShape_fx[idx];
+ move16();
+ }
+ }
+ }
+
+ /* fil-in missing memory */
+ test();
+ test();
+ IF( ( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) && LE_32( st->last_core_brate, SID_2k40 ) )
+ {
+ FOR( i = 0; i < L_SHB_LAHEAD; i++ )
+ {
+ Word16 intermediate = mult( shaped_shb_excitation_fx[i], subwin_shb_fx[L_SHB_LAHEAD - i] );
+ Word32 intermediate_32 = Mpy_32_16_1( Mpy_32_16_1( GainFrame_fx, window_shb_fx[L_SHB_LAHEAD - 1 - i] ), intermediate );
+ hBWE_TD->syn_overlap_fx[i] = round_fx( L_shl_sat( intermediate_32, sub( 16, ( add( Q_bwe_exc, 18 - 15 ) ) ) ) );
+ move16();
+ }
+ }
+
+ Word16 n_mem3_new = 0;
+ move16();
+ find_max_mem_dec_m3( st, &n_mem3_new );
+
+ ScaleShapedSHB_fx( SHB_OVERLAP_LEN,
+ shaped_shb_excitation_fx, /* i/o: Q_bwe_exc */
+ hBWE_TD->syn_overlap_fx,
+ GainShape_fx, /* Q15 */
+ GainFrame_fx, /* Q18 */
+ window_shb_fx,
+ subwin_shb_fx,
+ &Q_bwe_exc, &Qx, n_mem3_new, st->prev_Q_bwe_syn2 );
+
+ IF( hStereoICBWE != NULL )
+ {
+ Copy_Scale_sig_16_32_DEPREC( lpc_shb_fx, hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 0 );
+ Copy( GainShape_fx, hStereoICBWE->gshapeRef_fx, NUM_SHB_SUBFR );
+ hStereoICBWE->gFrameRef_fx = GainFrame_fx;
+ move32();
+
+ Copy( shaped_shb_excitation_fx, hStereoICBWE->shbSynthRef_fx, L_FRAME16k );
+ }
+
+ max_val = 0;
+ move16();
+ FOR( i = 0; i < L_FRAME16k; i++ )
+ {
+ max_val = s_max( max_val, abs_s( shaped_shb_excitation_fx[i] ) ); /* Q0 */
+ }
+ IF( max_val == 0 )
+ {
+ curr_frame_pow_fx = 0;
+ move32();
+ n = 0;
+ move16();
+ }
+ ELSE
+ {
+ n = norm_s( max_val );
+ max_val = 0;
+ move16();
+ FOR( i = 0; i < L_FRAME16k; i++ )
+ {
+ shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation_fx[i], n ); /*Q_bwe_exc+n*/
+ move16();
+ }
+
+ curr_frame_pow_fx = 0;
+ move32();
+ FOR( i = 0; i < L_FRAME16k; i++ )
+ {
+ L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/
+ curr_frame_pow_fx = L_add( curr_frame_pow_fx, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/
+ }
+ }
+ curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 );
+ tmp = sub( st->prev_frame_pow_exp, curr_frame_pow_exp );
+ IF( tmp > 0 ) /* shifting prev */
+ {
+ IF( GT_16( tmp, 32 ) )
+ {
+ st->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 );
+ move16();
+ tmp = 32;
+ move16();
+ }
+ hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp );
+ move32();
+ st->prev_frame_pow_exp = curr_frame_pow_exp;
+ move16();
+ }
+ ELSE /* shifting curr */
+ {
+ IF( LT_16( tmp, -32 ) )
+ {
+ curr_frame_pow_exp = sub( st->prev_frame_pow_exp, 32 );
+ tmp = -32;
+ move16();
+ }
+ curr_frame_pow_fx = L_shr( curr_frame_pow_fx, -tmp );
+ curr_frame_pow_exp = st->prev_frame_pow_exp;
+ move16();
+ }
+ test();
+ test();
+ IF( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) )
+ {
+ test();
+ test();
+ IF( ( GT_32( L_shr( curr_frame_pow_fx, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) &&
+ ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st->prev_coder_type, UNVOICED ) )
+ {
+ L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp );
+ scale_fx = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/
+
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ temp_fx = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/
+ }
+ ELSE
+ {
+ scale_fx = temp_fx = 32767;
+ move16(); /*Q15*/
+ move16(); /*Q15*/
+ }
+
+ FOR( j = 0; j < 8; j++ )
+ {
+ GainShape_fx[2 * j] = mult_r( GainShape_fx[2 * j], scale_fx );
+ move16();
+ GainShape_fx[2 * j + 1] = mult_r( GainShape_fx[2 * j + 1], scale_fx );
+ move16();
+ FOR( i = 0; i < L_FRAME16k / 8; i++ )
+ {
+ shaped_shb_excitation_fx[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation_fx[add( i, j * ( L_FRAME16k / 8 ) )], scale_fx );
+ move16();
+ }
+
+ IF( temp_fx > 0 )
+ {
+ /* scale_fx <= temp_fx, due to scale_fx = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow_fx ), temp_fx = sqrt( scale_fx, 1.f/8.f )
+ and curr_frame_pow_fx > st->prev_swb_bwe_frame_pow_fx -> scale_fx <= 1.0, sqrt(scale_fx, 1.f/8.f) >= scale_fx */
+ IF( LT_16( scale_fx, temp_fx ) )
+ {
+ scale_fx = div_s( scale_fx, temp_fx );
+ }
+ ELSE
+ {
+ scale_fx = 32767;
+ move16();
+ }
+ }
+ ELSE
+ {
+ scale_fx = 0;
+ move16();
+ }
+ }
+ }
+
+ /* adjust the FEC frame energy */
+ IF( st->bfi )
+ {
+ scale_fx = temp_fx = 4096;
+ move16(); /*Q12*/
+ move16();
+ IF( EQ_16( st->nbLostCmpt, 1 ) )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( GT_32( curr_frame_pow_fx, hBWE_TD->prev_swb_bwe_frame_pow_fx ) &&
+ NE_16( st->prev_coder_type, UNVOICED ) &&
+ ( st->last_good != UNVOICED_CLAS ) )
+ {
+ L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp ); /*31 - exp*/
+ scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
+ }
+ ELSE IF( LT_32( curr_frame_pow_fx, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st->nbLostCmpt, 1 ) &&
+ ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) &&
+ ( EQ_16( st->prev_coder_type, UNVOICED ) || ( st->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) )
+ {
+ L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp );
+ scale_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
+ }
+ }
+ ELSE IF( GT_16( st->nbLostCmpt, 1 ) )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( GT_32( curr_frame_pow_fx, hBWE_TD->prev_swb_bwe_frame_pow_fx ) )
+ {
+ L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp );
+ scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ temp_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
+ }
+ ELSE IF( LT_32( curr_frame_pow_fx, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) &&
+ ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) &&
+ ( EQ_16( st->prev_coder_type, UNVOICED ) || ( st->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) )
+ {
+ L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp );
+ L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/
+ scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp );
+ temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/
+ }
+ }
+
+ FOR( j = 0; j < 8; j++ )
+ {
+ GainShape_fx[2 * j] = shl_sat( mult_r( GainShape_fx[2 * j], scale_fx ), 3 );
+ move16(); /* 15 +12 +3-15 =15*/
+ GainShape_fx[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ), 3 );
+ move16();
+ FOR( i = 0; i < 40; i++ )
+ {
+ shaped_shb_excitation_fx[i + j * L_FRAME16k / 8] = shl( mult_r( shaped_shb_excitation_fx[i + j * L_FRAME16k / 8], scale_fx ), 3 );
+ move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/
+ }
+
+ IF( temp_fx > 0 )
+ {
+ IF( LT_16( scale_fx, temp_fx ) )
+ {
+ scale_fx = shr( div_s( scale_fx, temp_fx ), 3 );
+ }
+ ELSE
+ {
+ tmp1 = sub( norm_s( scale_fx ), 1 );
+ tmp2 = norm_s( temp_fx );
+ scale_fx = div_s( shl( scale_fx, tmp1 ), shl( temp_fx, tmp2 ) );
+ scale_fx = shr( scale_fx, add( sub( tmp1, tmp2 ), 3 ) );
+ }
+ }
+ ELSE
+ {
+ scale_fx = 0;
+ move16();
+ }
+ }
+ }
+
+ hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow_fx;
+ move32();
+ st->prev_frame_pow_exp = curr_frame_pow_exp;
+ move16();
+
+ Word64 prev_ener_shb64 = 0;
+ move64();
+ FOR( i = 0; i < L_FRAME16k; i++ )
+ {
+ prev_ener_shb64 = W_mac0_16_16( prev_ener_shb64, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* Q0 */
+ }
+ L_prev_ener_shb = W_sat_l( prev_ener_shb64 );
+
+ L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */
+ st->prev_ener_shb_fx = 0;
+ move16();
+ IF( L_prev_ener_shb != 0 )
+ {
+ exp = norm_l( L_prev_ener_shb );
+ tmp = extract_h( L_shl( L_prev_ener_shb, exp ) );
+ exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) );
+
+ tmp = div_s( 16384, tmp );
+ L_tmp = L_deposit_h( tmp );
+ L_tmp = Isqrt_lc( L_tmp, &exp );
+ st->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */
+ move16();
+ }
+
+ IF( st->hBWE_FD != NULL )
+ {
+ L_tmp = Mult_32_16( curr_frame_pow_fx, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */
+ tmp = 0;
+ move16();
+ IF( L_tmp != 0 )
+ {
+ exp = norm_l( L_tmp );
+ tmp = extract_h( L_shl( L_tmp, exp ) );
+ exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) );
+
+ tmp = div_s( 16384, tmp );
+ L_tmp = L_deposit_h( tmp );
+ L_tmp = Isqrt_lc( L_tmp, &exp );
+ tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */
+ }
+ set16_fx( st->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */
+ }
+
+ FOR( i = 0; i < L_FRAME16k; i++ )
+ {
+ shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], sub( Q11, Q_bwe_exc ) );
+ move32();
+ }
+
+ /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */
+ GenSHBSynth_fx_32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) );
+ Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) );
+ Copy32( error_fx + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH );
+
+ /* resample SHB synthesis (if needed) and scale down */
+ synth_scale_fx = 32767;
+ move16(); /* 1.0 in Q15 */
+ if ( EQ_16( st->codec_mode, MODE1 ) )
+ {
+ synth_scale_fx = 29491;
+ move16(); /* 0.9 in Q15 */
+ }
+
+ IF( EQ_32( st->output_Fs, 48000 ) )
+ {
+ IF( EQ_16( st->extl, FB_TBE ) )
+ {
+ tmp = norm_l( GainFrame_fx );
+ if ( GainFrame_fx == 0 )
+ {
+ tmp = 31;
+ move16();
+ }
+ L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */
+
+ tmp1 = 0;
+ move16();
+ FOR( i = 0; i < L_FRAME16k; i++ )
+ {
+ Word16 idx = 0;
+ move16();
+ IF( i != 0 )
+ {
+ idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k );
+ }
+ L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/
+ White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */
+ move16();
+ tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) );
+ }
+
+ *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */
+ move16();
+ tmp = norm_s( tmp1 );
+ if ( tmp1 == 0 )
+ {
+ tmp = 15;
+ move16();
+ }
+
+ FOR( i = 0; i < L_FRAME16k; i++ )
+ {
+ White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) );
+ move16();
+ }
+ *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 );
+ move16();
+ }
+
+ IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */
+ {
+ FOR( i = 0; i < L_FRAME32k; i++ )
+ {
+ error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx );
+ move32();
+ }
+ }
+ interpolate_3_over_2_allpass_32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 );
+ }
+ ELSE IF( EQ_32( st->output_Fs, 32000 ) )
+ {
+ IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */
+ {
+ FOR( i = 0; i < L_FRAME32k; i++ )
+ {
+ synth_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx );
+ move32(); /*Qx*/
+ }
+ }
+ ELSE
+ {
+ Copy32( error_fx, synth_fx, L_FRAME32k );
+ }
+ }
+ ELSE IF( EQ_32( st->output_Fs, 16000 ) )
+ {
+ IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */
+ {
+ FOR( i = 0; i < L_FRAME32k; i++ )
+ {
+ error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx );
+ move32();
+ }
+ }
+
+ Decimate_allpass_steep_fx32( error_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, synth_fx );
+ }
+
+
+ /* Update previous frame parameters for FEC */
+ Copy( lsf_shb_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER );
+ IF( EQ_16( st->codec_mode, MODE1 ) )
+ {
+ hBWE_TD->GainFrame_prevfrm_fx = GainFrame_fx;
+ move32(); /*Q18*/
+ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx;
+ move16();
+
+ if ( !st->bfi )
+ {
+ hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/
+ move16();
+ }
+ }
+ ELSE
+ {
+ IF( !st->bfi )
+ {
+ hBWE_TD->GainFrame_prevfrm_fx = GainFrame_fx;
+ move32(); /*Q18*/
+ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx;
+ move16();
+ hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/
+ move16();
+ }
+ }
+
+ hBWE_TD->prev_ener_fx = ener_tmp_fx[NUM_SHB_SUBGAINS - 1];
+ move32();
+ hBWE_TD->prev_GainShape_fx = GainShape_fx[NUM_SHB_SUBFR - 1];
+ move16();
+ st->prev_Q_bwe_syn2 = Q_bwe_exc;
+ move16();
+ st->prev_Qx = Q_bwe_exc;
+ move16();
+
+ return;
+}
+
+void GenTransition_fixed(
+ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */
+ const Word32 output_Fs, /* i : output sampling rate : Q0 */
+ const Word16 element_mode, /* i : element mode : Q0 */
+ const Word16 L_frame, /* i : ACELP frame length : Q0 */
+ const Word16 rf_flag, /* i : RF flag : Q0 */
+ const Word32 total_brate, /* i : total bitrate : Q0 */
+ const Word16 prev_Qx )
+{
+ Word16 i, length;
+
+ Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN];
+
+ /* set targeted length of transition signal */
+ length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) );
+
+ /* upsample overlap snippet */
+ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx );
+
+ /* perFORm spectral flip and downmix with overlap snippet to match HB synth */
+ test();
+ test();
+ test();
+ test();
+ IF( ( ( element_mode == EVS_MONO ) && ( rf_flag || EQ_32( total_brate, ACELP_9k60 ) ) ) || ( ( element_mode > EVS_MONO ) && EQ_16( L_frame, L_FRAME ) ) )
+ {
+ flip_and_downmix_generic_fx_32( syn_overlap_32k_fx, syn_overlap_32k_fx, 2 * SHB_OVERLAP_LEN, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + HILBERT_ORDER1, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), &( hBWE_TD->syn_dm_phase ) );
+ }
+ ELSE
+ {
+ FOR( i = 0; i < 2 * SHB_OVERLAP_LEN; i++ )
+ {
+ IF( i % 2 == 0 )
+ {
+ syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] );
+ }
+ ELSE
+ {
+ syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i];
+ }
+ move32();
+ }
+ }
+
+ /* cross fade of overlap snippet and mirrored HB synth from previous frame */
+ FOR( i = 0; i < 2 * L_SHB_LAHEAD; i++ )
+ {
+ outputHB_fx[i] = L_add_sat( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_32k_fx[i] ), Mpy_32_16_1( syn_overlap_32k_fx[i], window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i] ) );
+ move32();
+ }
+
+ /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */
+ FOR( ; i < length; i++ )
+ {
+ outputHB_fx[i] = L_shl( hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i], sub( Q11, prev_Qx ) );
+ move32();
+ }
+
+ IF( EQ_32( output_Fs, 48000 ) )
+ {
+ interpolate_3_over_2_allpass_32( outputHB_fx, length, outputHB_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 );
+ }
+ ELSE IF( EQ_32( output_Fs, 16000 ) )
+ {
+ Decimate_allpass_steep_fx32( outputHB_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, outputHB_fx );
+ }
+
+ return;
+}
+void GenTransition_WB_fixed(
+ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
+ Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */
+ const Word32 output_Fs /* i : output sampling rate */
+)
+{
+ Word16 i, length;
+ Word32 speech_buf_16k1_fx[SHB_OVERLAP_LEN], speech_buf_16k2_fx[2 * SHB_OVERLAP_LEN];
+ Word32 upsampled_synth_fx[L_FRAME48k];
+
+ /* set targeted length of transition signal */
+ length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) );
+
+ /* upsample overlap snippet */
+ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx );
+ Interpolate_allpass_steep_32( speech_buf_16k1_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, SHB_OVERLAP_LEN, speech_buf_16k2_fx );
+
+ /* perform spectral flip and downmix with overlap snippet to match HB synth */
+ FOR( i = 0; i < SHB_OVERLAP_LEN; i++ )
+ {
+ IF( i % 2 == 0 )
+ {
+ speech_buf_16k2_fx[i] = L_negate( speech_buf_16k2_fx[i] );
+ move32();
+ }
+ ELSE
+ {
+ speech_buf_16k2_fx[i] = speech_buf_16k2_fx[i];
+ move32();
+ }
+ }
+
+ /* cross fade of overlap snippet and mirrored HB synth from previous frame */
+ FOR( i = 0; i < L_SHB_LAHEAD; i++ )
+ {
+ outputHB_fx[i] = L_add( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_fx[i] ), Mpy_32_16_1( speech_buf_16k2_fx[i], window_shb_fx[L_SHB_LAHEAD - 1 - i] ) );
+ move32();
+ outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 );
+ move32();
+ }
+
+ /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */
+ FOR( ; i < length; i++ )
+ {
+ outputHB_fx[i] = hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i];
+ move32();
+ outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 );
+ move32();
+ }
+
+ /* upsampling if necessary */
+ IF( EQ_32( output_Fs, 32000 ) )
+ {
+ Interpolate_allpass_steep_32( outputHB_fx, hBWE_TD->mem_resamp_HB_fx_32, L_FRAME16k, upsampled_synth_fx );
+ Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME32k );
+ }
+ ELSE IF( EQ_32( output_Fs, 48000 ) )
+ {
+ interpolate_3_over_1_allpass_32( outputHB_fx, L_FRAME16k, upsampled_synth_fx, hBWE_TD->mem_resamp_HB_fx_32 );
+ Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME48k );
+ }
+
+ return;
+}
diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c
deleted file mode 100644
index 6a74d3b8731bba95b0058ef635784abee6ed6311..0000000000000000000000000000000000000000
--- a/lib_dec/tonalMDCTconcealment.c
+++ /dev/null
@@ -1,436 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#define _USE_MATH_DEFINES
-
-#include
-#include
-#include "options.h"
-#include
-#include "prot.h"
-#include "ivas_prot.h"
-#include "wmc_auto.h"
-#include "ivas_prot_fx.h"
-#include "prot_fx.h"
-
-
-/*******************************************************/
-/*-------------- public functions -------------------- */
-/*******************************************************/
-
-void TonalMdctConceal_create_concealment_noise_ivas_fx(
- Word32 concealment_noise[L_FRAME48k], // Q31-concealment_noise_exp
- Word16 *concealment_noise_exp,
- CPE_DEC_HANDLE hCPE,
- const Word16 L_frameTCX, // Q0
- const Word16 L_frame, // Q0
- const Word16 idchan, // Q0
- const Word16 subframe_idx, // Q0
- const Word16 core, // Q0
- const Word16 crossfade_gain, // Q15
- const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode )
-{
- STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct;
- TonalMDCTConcealPtr hTonalMDCTConc;
- Decoder_State *st;
- HANDLE_FD_CNG_COM hFdCngCom;
- Word16 *rnd_c, *rnd;
- Word16 crossOverFreq, i, save_rnd_c, max_noise_line;
- Word16 c, c_inv, inc;
- Word32 noise_shape_buffer[L_FRAME48k];
- Word16 noise_shape_buffer_e[L_FRAME48k];
- Word16 start_idx, stop_idx, noise_shape_buffer_common_exp = MIN16B_FLT_FX, last_scf_e, temp_e;
- move16();
- Word32 *cngNoiseLevelPtr;
- Word32 last_scf;
-
- Word16 c_e, c_inv_e;
-
- push_wmops( "create_conc_noise" );
-
- hStereoMdct = hCPE->hStereoMdct;
- st = hCPE->hCoreCoder[idchan];
- hTonalMDCTConc = st->hTonalMDCTConc;
- hFdCngCom = st->hFdCngDec->hFdCngCom;
- rnd = &hStereoMdct->noise_seeds_channels[idchan];
- rnd_c = &hStereoMdct->noise_seed_common;
-
- /* determine start bin for IGF */
- IF( st->igf == 0 )
- {
- IF( st->narrowBand == 0 )
- {
- /* minimum needed for output with sampling rates lower then the
- nominal sampling rate */
- crossOverFreq = s_min( L_frameTCX, L_frame );
- }
- ELSE
- {
- crossOverFreq = L_frameTCX;
- move16();
- }
- }
- ELSE
- {
- crossOverFreq = s_min( st->hIGFDec->infoIGFStartLine, L_frameTCX );
- }
-
- /* for tonal mdct concealment with tonal components above the crossover frequency, conditionally raise the frequency index until which noise is generated */
- max_noise_line = crossOverFreq;
- move16();
- IF( st->tonal_mdct_plc_active )
- {
- max_noise_line = s_max( max_noise_line, extract_l( L_add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ) ) );
- }
-
- /* first lost frame is handled separately */
- IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed )
- {
- *rnd = add( 1977, idchan ); // Q0
- move16();
- /* will be set twice when looping over two channels, but does not matter */
- *rnd_c = 1979; // Q0
- move16();
- }
-
- IF( GT_16( crossfade_gain, 32734 ) )
- /* Due to precision loss */ /* 0.999 in Q15*/
- {
- /* In first frame, noise is weighted with zero anyway, we only need the random numbers for the sign scrambling */
- FOR( i = 0; i < max_noise_line; i++ )
- {
- *rnd = own_random( rnd );
- move16();
- concealment_noise[i] = *rnd; // Q31-concealment_noise_exp
- move32();
- }
- *concealment_noise_exp = 31;
- move16();
- pop_wmops();
-
- return;
- }
-
- save_rnd_c = *rnd_c; // Q0
- move16();
-
- c_e = 1;
- move16();
- c_inv_e = 1;
- move16();
-
- c = Sqrt16( hStereoMdct->lastCoh_fx, &c_e ); // Q1 = 15 - c_e
- c_inv = Sqrt16( sub( ONE_IN_Q14, hStereoMdct->lastCoh_fx ), &c_inv_e ); // Q2 = 15 - c_inv_e
-
- IF( NE_16( c_e, c_inv_e ) )
- {
- IF( LT_16( c_e, c_inv_e ) )
- {
- c = shr( c, sub( c_inv_e, c_e ) ); // Q0
- c_e = c_inv_e;
- move16();
- }
- ELSE
- {
- c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); // Q0
- }
- }
-
- /* pre-compute the noise shape for later weighting of the noise spectra */
- cngNoiseLevelPtr = &hFdCngCom->cngNoiseLevel[0];
- last_scf_e = hFdCngCom->cngNoiseLevelExp;
- move16();
-
- IF( GT_16( st->core, TCX_20_CORE ) )
- {
- inc = 2;
- }
- ELSE
- {
- inc = 1;
- }
- move16();
- start_idx = idiv1616( hFdCngCom->startBand, inc );
- stop_idx = idiv1616( hFdCngCom->stopFFTbin, inc );
-
- FOR( i = 0; i < start_idx; i++ )
- {
- noise_shape_buffer[i] = 0;
- move32();
- noise_shape_buffer_e[i] = 0;
- move16();
- }
- FOR( ; i < stop_idx; ( i++, cngNoiseLevelPtr += inc ) )
- {
- noise_shape_buffer_e[i] = hFdCngCom->cngNoiseLevelExp;
- move16();
- noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); // Q31-noise_shape_buffer_e[i]
- move32();
- noise_shape_buffer_common_exp = s_max( noise_shape_buffer_e[i], noise_shape_buffer_common_exp );
- }
-
- FOR( i = 0; i < stop_idx; i++ )
- {
- IF( NE_16( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) )
- {
-
- noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); // Q31- (noise_shape_buffer_common_exp-noise_shape_buffer_e[i])
- move32();
- }
- }
-
- last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); // Q31-last_scf_e
-
- IF( LT_16( noise_shape_buffer_common_exp, last_scf_e ) )
- {
- Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); // Q31- (noise_shape_buffer_common_exp-last_scf_e)
-
- noise_shape_buffer_common_exp = last_scf_e;
- move16();
- }
- ELSE
- {
- last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); // Q31-(last_scf_e-noise_shape_buffer_common_exp)
- }
-
- FOR( ; i < max_noise_line; i++ )
- {
- noise_shape_buffer[i] = last_scf; // Q31 - noise_shape_buffer_common_exp
- move32();
- }
-
- /* fill the noise vector */
- hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; // Q31
- move32();
- hTonalMDCTConc->curr_noise_nrg_exp = 0;
- move16();
- *concealment_noise_exp = add( 16, add( noise_shape_buffer_common_exp, c_e ) );
- move16();
- temp_e = hTonalMDCTConc->curr_noise_nrg_exp;
- move16();
-
- test();
- test();
- test();
- test();
- IF( EQ_16( noise_gen_mode, EQUAL_CORES ) || ( ( EQ_16( noise_gen_mode, TCX20_IN_0_TCX10_IN_1 ) && EQ_16( idchan, 0 ) ) || ( EQ_16( noise_gen_mode, TCX10_IN_0_TCX20_IN_1 ) && EQ_16( idchan, 1 ) ) ) )
- {
- /* current channel is TCX20 -> generate noise for "full-length" spectrum */
-
- FOR( i = 0; i < max_noise_line; i++ )
- {
- *rnd = own_random( rnd ); // Q0
- *rnd_c = own_random( rnd_c );
-
- move16();
- move16();
-
- concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); // Q31 - *concealment_noise_exp
- move32();
- IF( concealment_noise[i] != 0 )
- {
- hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e
- }
- hTonalMDCTConc->curr_noise_nrg_exp = temp_e;
- move16();
- }
- }
- ELSE /* ( ( noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 0 ) || ( noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 1 ) ) */
- {
- /* current channel is TCX10 and the other is TCX20 -> generate noise for "half-length" spectrum, but "increment" mid seed twice, to have the same seed in mid as the other (TCX20) channel for next frame */
- FOR( i = 0; i < max_noise_line; i++ )
- {
- *rnd = own_random( rnd ); // Q0
- *rnd_c = own_random( rnd_c ); // Q0
- move16();
- move16();
-
- concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] );
- move32();
- IF( concealment_noise[i] != 0 )
- {
- hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e
- }
- hTonalMDCTConc->curr_noise_nrg_exp = temp_e;
- move16();
-
- *rnd_c = own_random( rnd_c );
- move16();
- }
- }
-
- IF( st->tonal_mdct_plc_active )
- {
- FOR( i = crossOverFreq; i < s_max( crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ); ++i )
- {
- concealment_noise[i] = 0;
- move32();
- }
- }
-
- /* restore common seed
- - after finishing the first channel
- - after a first subframe if the current channel is TCX10 */
-
- test();
- test();
- test();
- test();
- test();
- IF( ( EQ_16( idchan, 0 ) && ( EQ_16( core, TCX_20 ) || ( EQ_16( core, TCX_10 ) && EQ_16( subframe_idx, 1 ) ) ) ) || ( EQ_16( core, TCX_10 ) && EQ_16( subframe_idx, 0 ) ) )
- {
- *rnd_c = save_rnd_c;
- move16();
- }
-
- st->seed_tcx_plc = *rnd;
- move16();
-
- pop_wmops();
-
- return;
-}
-
-
-void TonalMdctConceal_whiten_noise_shape_ivas_fx(
- Decoder_State *st,
- const Word16 L_frame,
- const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE whitening_mode )
-{
- Word16 inc, start_idx, stop_idx, i;
- Word32 *noiseLevelPtr, *scfs_bg, *scfs_for_shaping;
- Word16 noiseLevelPtr_exp;
- HANDLE_FD_CNG_COM hFdCngCom;
- Word32 whitenend_noise_shape[L_FRAME16k];
- Word16 q_wns;
- Word32 scfs_int[FDNS_NPTS];
- const PsychoacousticParameters *psychParams;
-
- push_wmops( "apply_sns_on_noise_shape" );
-
- scfs_bg = &st->hTonalMDCTConc->scaleFactorsBackground_fx[0];
- psychParams = st->hTonalMDCTConc->psychParams;
- hFdCngCom = st->hFdCngDec->hFdCngCom;
-
-#ifdef MSAN_FIX
- set32_fx( whitenend_noise_shape, 0, L_FRAME16k );
-#endif
-
- IF( EQ_32( whitening_mode, ON_FIRST_LOST_FRAME ) )
- {
- IF( GT_16( st->core, TCX_20_CORE ) )
- {
- inc = 2;
- move16();
- }
- ELSE
- {
- inc = 1;
- move16();
- }
- }
- ELSE
- {
- IF( GT_16( st->last_core, TCX_20_CORE ) )
- {
- inc = 2;
- move16();
- }
- ELSE
- {
- inc = 1;
- move16();
- }
- }
- start_idx = shr( hFdCngCom->startBand, sub( inc, 1 ) );
- stop_idx = shr( L_frame, sub( inc, 1 ) );
- noiseLevelPtr = hFdCngCom->cngNoiseLevel;
- noiseLevelPtr_exp = hFdCngCom->cngNoiseLevelExp;
- move16();
-
- FOR( Word16 j = start_idx; j < stop_idx; j++ )
- {
- whitenend_noise_shape[j] = L_shr( *noiseLevelPtr, 3 );
- move32();
- noiseLevelPtr += inc;
- }
-
- IF( EQ_32( whitening_mode, ON_FIRST_LOST_FRAME ) )
- {
- Word32 scf[SNS_NPTS];
-
- sns_compute_scf_fx( whitenend_noise_shape, psychParams, L_frame, scf, sub( sub( 31, noiseLevelPtr_exp ), 3 ) );
-
- sns_interpolate_scalefactors_fx( scfs_int, scf, ENC );
- sns_interpolate_scalefactors_fx( scfs_bg, scf, DEC );
-
- scfs_for_shaping = &scfs_int[0]; // Q16
- }
- ELSE /* whitening_mode == ON_FIRST_GOOD_FRAME */
- {
- scfs_for_shaping = &scfs_bg[0]; // Q16
- }
-
- IF( sum32_sat( scfs_for_shaping, FDNS_NPTS ) > 0 )
- {
- q_wns = sub( sub( 31, noiseLevelPtr_exp ), 3 );
- sns_shape_spectrum_fx( whitenend_noise_shape, &q_wns, psychParams, scfs_for_shaping, Q16, L_frame, NULL );
-
- IF( GT_16( add( q_wns, 1 ), sub( 31, hFdCngCom->cngNoiseLevelExp ) ) )
- {
- FOR( i = 0; i < sub( stop_idx, start_idx ); i++ )
- {
- hFdCngCom->cngNoiseLevel[i] = L_shr( whitenend_noise_shape[start_idx + i], sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) ); //(q_wns + 1)
- move32();
- }
- }
- ELSE
- {
- Copy32( whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel, sub( stop_idx, start_idx ) );
-
- scale_sig32( hFdCngCom->cngNoiseLevel + sub( stop_idx, start_idx ), sub( FFTCLDFBLEN, sub( stop_idx, start_idx ) ), sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) );
-
- hFdCngCom->cngNoiseLevelExp = sub( Q30, q_wns ); // Exponent = 31 - (q_wns + 1)
- move16();
- }
- }
- ELSE
- {
- set32_fx( hFdCngCom->cngNoiseLevel, 0, sub( stop_idx, start_idx ) );
- }
-
- pop_wmops();
-}
diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c
index a4aa23e7fbf69a6ca9283e8be81993209c0c8edb..36cadf6ffea2934dc2a7ebf63f9927240c33ba46 100644
--- a/lib_dec/tonalMDCTconcealment_fx.c
+++ b/lib_dec/tonalMDCTconcealment_fx.c
@@ -14,7 +14,6 @@
#include "cnst.h"
#include "prot_fx.h"
#include "stat_com.h"
-#include "prot.h"
#include "ivas_prot_fx.h"
#define CROSSFADE_THRESHOLD ( 32762 ) // close to 1.0f in Q15 such that (x == 1.0f) is true
@@ -3200,6 +3199,397 @@ static void CalcPowerSpec(
powerSpec[nSamples - 1] = L_shr( powerSpec[nSamples - 2], 1 );
move32();
}
+
+
+/*******************************************************/
+/*-------------- public functions -------------------- */
+/*******************************************************/
+
+void TonalMdctConceal_create_concealment_noise_ivas_fx(
+ Word32 concealment_noise[L_FRAME48k], // Q31-concealment_noise_exp
+ Word16 *concealment_noise_exp,
+ CPE_DEC_HANDLE hCPE,
+ const Word16 L_frameTCX, // Q0
+ const Word16 L_frame, // Q0
+ const Word16 idchan, // Q0
+ const Word16 subframe_idx, // Q0
+ const Word16 core, // Q0
+ const Word16 crossfade_gain, // Q15
+ const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode )
+{
+ STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct;
+ TonalMDCTConcealPtr hTonalMDCTConc;
+ Decoder_State *st;
+ HANDLE_FD_CNG_COM hFdCngCom;
+ Word16 *rnd_c, *rnd;
+ Word16 crossOverFreq, i, save_rnd_c, max_noise_line;
+ Word16 c, c_inv, inc;
+ Word32 noise_shape_buffer[L_FRAME48k];
+ Word16 noise_shape_buffer_e[L_FRAME48k];
+ Word16 start_idx, stop_idx, noise_shape_buffer_common_exp = MIN16B_FLT_FX, last_scf_e, temp_e;
+ move16();
+ Word32 *cngNoiseLevelPtr;
+ Word32 last_scf;
+
+ Word16 c_e, c_inv_e;
+
+ push_wmops( "create_conc_noise" );
+
+ hStereoMdct = hCPE->hStereoMdct;
+ st = hCPE->hCoreCoder[idchan];
+ hTonalMDCTConc = st->hTonalMDCTConc;
+ hFdCngCom = st->hFdCngDec->hFdCngCom;
+ rnd = &hStereoMdct->noise_seeds_channels[idchan];
+ rnd_c = &hStereoMdct->noise_seed_common;
+
+ /* determine start bin for IGF */
+ IF( st->igf == 0 )
+ {
+ IF( st->narrowBand == 0 )
+ {
+ /* minimum needed for output with sampling rates lower then the
+ nominal sampling rate */
+ crossOverFreq = s_min( L_frameTCX, L_frame );
+ }
+ ELSE
+ {
+ crossOverFreq = L_frameTCX;
+ move16();
+ }
+ }
+ ELSE
+ {
+ crossOverFreq = s_min( st->hIGFDec->infoIGFStartLine, L_frameTCX );
+ }
+
+ /* for tonal mdct concealment with tonal components above the crossover frequency, conditionally raise the frequency index until which noise is generated */
+ max_noise_line = crossOverFreq;
+ move16();
+ IF( st->tonal_mdct_plc_active )
+ {
+ max_noise_line = s_max( max_noise_line, extract_l( L_add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ) ) );
+ }
+
+ /* first lost frame is handled separately */
+ IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed )
+ {
+ *rnd = add( 1977, idchan ); // Q0
+ move16();
+ /* will be set twice when looping over two channels, but does not matter */
+ *rnd_c = 1979; // Q0
+ move16();
+ }
+
+ IF( GT_16( crossfade_gain, 32734 ) )
+ /* Due to precision loss */ /* 0.999 in Q15*/
+ {
+ /* In first frame, noise is weighted with zero anyway, we only need the random numbers for the sign scrambling */
+ FOR( i = 0; i < max_noise_line; i++ )
+ {
+ *rnd = own_random( rnd );
+ move16();
+ concealment_noise[i] = *rnd; // Q31-concealment_noise_exp
+ move32();
+ }
+ *concealment_noise_exp = 31;
+ move16();
+ pop_wmops();
+
+ return;
+ }
+
+ save_rnd_c = *rnd_c; // Q0
+ move16();
+
+ c_e = 1;
+ move16();
+ c_inv_e = 1;
+ move16();
+
+ c = Sqrt16( hStereoMdct->lastCoh_fx, &c_e ); // Q1 = 15 - c_e
+ c_inv = Sqrt16( sub( ONE_IN_Q14, hStereoMdct->lastCoh_fx ), &c_inv_e ); // Q2 = 15 - c_inv_e
+
+ IF( NE_16( c_e, c_inv_e ) )
+ {
+ IF( LT_16( c_e, c_inv_e ) )
+ {
+ c = shr( c, sub( c_inv_e, c_e ) ); // Q0
+ c_e = c_inv_e;
+ move16();
+ }
+ ELSE
+ {
+ c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); // Q0
+ }
+ }
+
+ /* pre-compute the noise shape for later weighting of the noise spectra */
+ cngNoiseLevelPtr = &hFdCngCom->cngNoiseLevel[0];
+ last_scf_e = hFdCngCom->cngNoiseLevelExp;
+ move16();
+
+ IF( GT_16( st->core, TCX_20_CORE ) )
+ {
+ inc = 2;
+ }
+ ELSE
+ {
+ inc = 1;
+ }
+ move16();
+ start_idx = idiv1616( hFdCngCom->startBand, inc );
+ stop_idx = idiv1616( hFdCngCom->stopFFTbin, inc );
+
+ FOR( i = 0; i < start_idx; i++ )
+ {
+ noise_shape_buffer[i] = 0;
+ move32();
+ noise_shape_buffer_e[i] = 0;
+ move16();
+ }
+ FOR( ; i < stop_idx; ( i++, cngNoiseLevelPtr += inc ) )
+ {
+ noise_shape_buffer_e[i] = hFdCngCom->cngNoiseLevelExp;
+ move16();
+ noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); // Q31-noise_shape_buffer_e[i]
+ move32();
+ noise_shape_buffer_common_exp = s_max( noise_shape_buffer_e[i], noise_shape_buffer_common_exp );
+ }
+
+ FOR( i = 0; i < stop_idx; i++ )
+ {
+ IF( NE_16( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) )
+ {
+
+ noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); // Q31- (noise_shape_buffer_common_exp-noise_shape_buffer_e[i])
+ move32();
+ }
+ }
+
+ last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); // Q31-last_scf_e
+
+ IF( LT_16( noise_shape_buffer_common_exp, last_scf_e ) )
+ {
+ Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); // Q31- (noise_shape_buffer_common_exp-last_scf_e)
+
+ noise_shape_buffer_common_exp = last_scf_e;
+ move16();
+ }
+ ELSE
+ {
+ last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); // Q31-(last_scf_e-noise_shape_buffer_common_exp)
+ }
+
+ FOR( ; i < max_noise_line; i++ )
+ {
+ noise_shape_buffer[i] = last_scf; // Q31 - noise_shape_buffer_common_exp
+ move32();
+ }
+
+ /* fill the noise vector */
+ hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; // Q31
+ move32();
+ hTonalMDCTConc->curr_noise_nrg_exp = 0;
+ move16();
+ *concealment_noise_exp = add( 16, add( noise_shape_buffer_common_exp, c_e ) );
+ move16();
+ temp_e = hTonalMDCTConc->curr_noise_nrg_exp;
+ move16();
+
+ test();
+ test();
+ test();
+ test();
+ IF( EQ_16( noise_gen_mode, EQUAL_CORES ) || ( ( EQ_16( noise_gen_mode, TCX20_IN_0_TCX10_IN_1 ) && EQ_16( idchan, 0 ) ) || ( EQ_16( noise_gen_mode, TCX10_IN_0_TCX20_IN_1 ) && EQ_16( idchan, 1 ) ) ) )
+ {
+ /* current channel is TCX20 -> generate noise for "full-length" spectrum */
+
+ FOR( i = 0; i < max_noise_line; i++ )
+ {
+ *rnd = own_random( rnd ); // Q0
+ *rnd_c = own_random( rnd_c );
+
+ move16();
+ move16();
+
+ concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); // Q31 - *concealment_noise_exp
+ move32();
+ IF( concealment_noise[i] != 0 )
+ {
+ hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e
+ }
+ hTonalMDCTConc->curr_noise_nrg_exp = temp_e;
+ move16();
+ }
+ }
+ ELSE /* ( ( noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 0 ) || ( noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 1 ) ) */
+ {
+ /* current channel is TCX10 and the other is TCX20 -> generate noise for "half-length" spectrum, but "increment" mid seed twice, to have the same seed in mid as the other (TCX20) channel for next frame */
+ FOR( i = 0; i < max_noise_line; i++ )
+ {
+ *rnd = own_random( rnd ); // Q0
+ *rnd_c = own_random( rnd_c ); // Q0
+ move16();
+ move16();
+
+ concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] );
+ move32();
+ IF( concealment_noise[i] != 0 )
+ {
+ hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e
+ }
+ hTonalMDCTConc->curr_noise_nrg_exp = temp_e;
+ move16();
+
+ *rnd_c = own_random( rnd_c );
+ move16();
+ }
+ }
+
+ IF( st->tonal_mdct_plc_active )
+ {
+ FOR( i = crossOverFreq; i < s_max( crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ); ++i )
+ {
+ concealment_noise[i] = 0;
+ move32();
+ }
+ }
+
+ /* restore common seed
+ - after finishing the first channel
+ - after a first subframe if the current channel is TCX10 */
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( EQ_16( idchan, 0 ) && ( EQ_16( core, TCX_20 ) || ( EQ_16( core, TCX_10 ) && EQ_16( subframe_idx, 1 ) ) ) ) || ( EQ_16( core, TCX_10 ) && EQ_16( subframe_idx, 0 ) ) )
+ {
+ *rnd_c = save_rnd_c;
+ move16();
+ }
+
+ st->seed_tcx_plc = *rnd;
+ move16();
+
+ pop_wmops();
+
+ return;
+}
+
+
+void TonalMdctConceal_whiten_noise_shape_ivas_fx(
+ Decoder_State *st,
+ const Word16 L_frame,
+ const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE whitening_mode )
+{
+ Word16 inc, start_idx, stop_idx, i;
+ Word32 *noiseLevelPtr, *scfs_bg, *scfs_for_shaping;
+ Word16 noiseLevelPtr_exp;
+ HANDLE_FD_CNG_COM hFdCngCom;
+ Word32 whitenend_noise_shape[L_FRAME16k];
+ Word16 q_wns;
+ Word32 scfs_int[FDNS_NPTS];
+ const PsychoacousticParameters *psychParams;
+
+ push_wmops( "apply_sns_on_noise_shape" );
+
+ scfs_bg = &st->hTonalMDCTConc->scaleFactorsBackground_fx[0];
+ psychParams = st->hTonalMDCTConc->psychParams;
+ hFdCngCom = st->hFdCngDec->hFdCngCom;
+
+#ifdef MSAN_FIX
+ set32_fx( whitenend_noise_shape, 0, L_FRAME16k );
+#endif
+
+ IF( EQ_32( whitening_mode, ON_FIRST_LOST_FRAME ) )
+ {
+ IF( GT_16( st->core, TCX_20_CORE ) )
+ {
+ inc = 2;
+ move16();
+ }
+ ELSE
+ {
+ inc = 1;
+ move16();
+ }
+ }
+ ELSE
+ {
+ IF( GT_16( st->last_core, TCX_20_CORE ) )
+ {
+ inc = 2;
+ move16();
+ }
+ ELSE
+ {
+ inc = 1;
+ move16();
+ }
+ }
+ start_idx = shr( hFdCngCom->startBand, sub( inc, 1 ) );
+ stop_idx = shr( L_frame, sub( inc, 1 ) );
+ noiseLevelPtr = hFdCngCom->cngNoiseLevel;
+ noiseLevelPtr_exp = hFdCngCom->cngNoiseLevelExp;
+ move16();
+
+ FOR( Word16 j = start_idx; j < stop_idx; j++ )
+ {
+ whitenend_noise_shape[j] = L_shr( *noiseLevelPtr, 3 );
+ move32();
+ noiseLevelPtr += inc;
+ }
+
+ IF( EQ_32( whitening_mode, ON_FIRST_LOST_FRAME ) )
+ {
+ Word32 scf[SNS_NPTS];
+
+ sns_compute_scf_fx( whitenend_noise_shape, psychParams, L_frame, scf, sub( sub( 31, noiseLevelPtr_exp ), 3 ) );
+
+ sns_interpolate_scalefactors_fx( scfs_int, scf, ENC );
+ sns_interpolate_scalefactors_fx( scfs_bg, scf, DEC );
+
+ scfs_for_shaping = &scfs_int[0]; // Q16
+ }
+ ELSE /* whitening_mode == ON_FIRST_GOOD_FRAME */
+ {
+ scfs_for_shaping = &scfs_bg[0]; // Q16
+ }
+
+ IF( sum32_sat( scfs_for_shaping, FDNS_NPTS ) > 0 )
+ {
+ q_wns = sub( sub( 31, noiseLevelPtr_exp ), 3 );
+ sns_shape_spectrum_fx( whitenend_noise_shape, &q_wns, psychParams, scfs_for_shaping, Q16, L_frame, NULL );
+
+ IF( GT_16( add( q_wns, 1 ), sub( 31, hFdCngCom->cngNoiseLevelExp ) ) )
+ {
+ FOR( i = 0; i < sub( stop_idx, start_idx ); i++ )
+ {
+ hFdCngCom->cngNoiseLevel[i] = L_shr( whitenend_noise_shape[start_idx + i], sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) ); //(q_wns + 1)
+ move32();
+ }
+ }
+ ELSE
+ {
+ Copy32( whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel, sub( stop_idx, start_idx ) );
+
+ scale_sig32( hFdCngCom->cngNoiseLevel + sub( stop_idx, start_idx ), sub( FFTCLDFBLEN, sub( stop_idx, start_idx ) ), sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) );
+
+ hFdCngCom->cngNoiseLevelExp = sub( Q30, q_wns ); // Exponent = 31 - (q_wns + 1)
+ move16();
+ }
+ }
+ ELSE
+ {
+ set32_fx( hFdCngCom->cngNoiseLevel, 0, sub( stop_idx, start_idx ) );
+ }
+
+ pop_wmops();
+}
+
+
#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT
void TonalMdctConceal_create_concealment_noise(
float concealment_noise[L_FRAME48k],
diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c
index 203f39707841de02331ada3f1c518abda24cf86e..44439540f0ba0b7aee817f8c86c81008613d8f5d 100644
--- a/lib_enc/ACcontextMapping_enc_fx.c
+++ b/lib_enc/ACcontextMapping_enc_fx.c
@@ -7,7 +7,6 @@
#include "options.h"
#include "basop_util.h"
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "rom_com.h"
@@ -1342,8 +1341,8 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
}
/* Init current 2-tuple encoding */
- a1 = (Word16) abs( x[a1_i] );
- b1 = (Word16) abs( x[b1_i] );
+ a1 = abs_s( x[a1_i] );
+ b1 = abs_s( x[b1_i] );
lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
bit_estimate_fx = W_add( bit_estimate_fx, MAKE_VARIABLE_QX( s_min( a1, 1 ), Q23 ) );
@@ -1732,7 +1731,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
/* Main Loop through the 2-tuples */
/*hContextMem->nt_half = end_line >> 1;*/
- FOR( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 )
+ Word16 len = s_min( hContextMem->lastnz, end_line );
+ FOR( k = start_line; k < len; k += 2 )
{
a1_i = k; /* Q0 */
move16();
diff --git a/lib_enc/FEC_enc_fx.c b/lib_enc/FEC_enc_fx.c
index 9106e23e70eeb8e67b6eaa8cd1be674973598811..87243e8d2fa5268c37ab5a6cb7513969450575d9 100644
--- a/lib_enc/FEC_enc_fx.c
+++ b/lib_enc/FEC_enc_fx.c
@@ -9,7 +9,6 @@
#include "rom_com.h" /* Static table prototypes */
#include "prot_fx.h" /* Function prototypes */
#include "prot_fx_enc.h" /* Function prototypes */
-#include "prot.h" /* Function prototypes */
#include "ivas_prot_fx.h" /* Function prototypes */
diff --git a/lib_enc/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c
index f44530c849cf8108fea348eef9dc8eb888cf2795..09acfd5dca1bb7bde7ab0896faee5ba2148c79d1 100644
--- a/lib_enc/SNR_calc_fx.c
+++ b/lib_enc/SNR_calc_fx.c
@@ -10,7 +10,6 @@
#include "prot_fx_enc.h" /* Function prototypes */
#include "rom_enc.h"
#include "rom_com.h"
-#include "prot.h"
/*-------------------------------------------------------------------*
diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c
index a294d12da8764c3177b6097a5d046fa52f84734c..0f58bcdad0a4fe0798740eeb61e440aa307d0812 100644
--- a/lib_enc/acelp_core_enc_fx.c
+++ b/lib_enc/acelp_core_enc_fx.c
@@ -6,7 +6,6 @@
#include
#include "options.h" /* Compilation switches */
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "stat_enc.h"
#include "rom_com.h"
@@ -39,14 +38,10 @@ ivas_error acelp_core_enc_fx(
Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn*/
Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/
Word16 *unbits_fx, /* o : number of unused bits Q0*/
+ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
+ const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */
const Word16 Q_new,
- const Word16 shift
-#ifdef ADD_LRTD
- ,
- STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
- const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */
-#endif
-)
+ const Word16 shift )
{
Word16 nBits; /* reserved bits */
Word16 i;
@@ -113,6 +108,8 @@ ivas_error acelp_core_enc_fx(
* Initialization
*------------------------------------------------------------------*/
+ (void) tdm_lsfQ_PCh;
+
Es_pred_fx = 0;
move16();
@@ -206,16 +203,14 @@ ivas_error acelp_core_enc_fx(
/* TD stereo */
test();
-#ifdef ADD_LRTD
IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) )
{
tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag;
tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode;
tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag;
- tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf;
+ tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf_fx;
}
ELSE
-#endif
{
tdm_lp_reuse_flag = 0;
tdm_low_rate_mode = 0;
@@ -333,7 +328,6 @@ ivas_error acelp_core_enc_fx(
{
IF( hTdCngEnc != NULL )
{
- /*IVAS_CODE CNG_att is missing */
enr = cng_energy_fx( st_fx->element_mode, st_fx->bwidth, hDtxEnc->CNG_mode, /*st_fx->hTdCngEnc->CNG_att*/ 0, exc_fx, st_fx->L_frame, Q_new ); // Q8
/* calculate the energy quantization index */
@@ -453,78 +447,8 @@ ivas_error acelp_core_enc_fx(
if ( !tdm_lp_reuse_flag )
{
-#ifdef LSF_RE_USE_SECONDARY_CHANNEL
- lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new );
-#else
lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new );
-#endif
}
-#ifdef ADD_LRTD
- else
- {
- const float *pt_interp_2;
-#ifdef LSF_RE_USE_SECONDARY_CHANNEL
- if ( st->active_cnt != 1 )
- {
- int16_t beta_index;
- float lsf_wgts[M];
-
- /* intra_frame prediction for the LSFs */
- lsp2lsf( lsp_new, lsf_new, M, 12800 );
-
- Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M );
-
- tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index );
-
- push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS );
- }
-#endif
- pt_interp_2 = interpol_frac_12k8;
- if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED )
- {
- pt_interp_2 = interpol_frac2;
- }
-#ifndef LSF_RE_USE_SECONDARY_CHANNEL
- if ( st->active_cnt == 1 )
- {
- mvr2r( lsp_new, st->lsp_old, M );
- lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core );
- lsp2lsf( lsp_new, lsf_new, M, st->sr_core );
- }
-#endif
- /* LSP interpolation and conversion of LSPs to A(z) */
- int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 );
-
- /* Check LSF stability (distance between old LSFs and current LSFs) */
- st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame );
- }
- if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO )
- {
- /* Prepare ACB memory from last HQ frame */
- tmpF = hLPDmem->old_exc[0];
- preemph( hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF );
- mvr2r( hLPDmem->old_exc + st->L_frame - M, hLPDmem->mem_syn, M );
- residu( Aq, M, hLPDmem->old_exc, old_exc, st->L_frame );
- }
-
- if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO )
- {
- /* Prepare ACB memory of old_bwe_exc */
-#ifdef CR_FIX_639_HQ_ACELP_TRANSITION
- if ( st->L_frame == L_FRAME )
- {
- lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
- }
- else
- {
- lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
- }
-#else
- lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
-#endif
- }
-#endif
-
/*---------------------------------------------------------------*
* Calculation of LP residual (filtering through A[z] filter)
@@ -566,26 +490,12 @@ ivas_error acelp_core_enc_fx(
*------------------------------------------------------------*/
test();
test();
-#ifdef ADD_LRTD
- if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */
+ IF( hSC_VBR->nelp_mode )
{
- if ( st->coder_type <= UNVOICED )
- {
- tdm_low_rate_enc( st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise );
- }
- else /* GENERIC */
- {
- encod_gen_2sbfr( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
- }
+ /* SC-VBR - NELP frames */
+ encod_nelp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx,
+ voice_factors_fx, bwe_exc_fx, Q_new, shift );
}
- else
-#endif
- IF( hSC_VBR->nelp_mode )
- {
- /* SC-VBR - NELP frames */
- encod_nelp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx,
- voice_factors_fx, bwe_exc_fx, Q_new, shift );
- }
ELSE IF( EQ_16( coder_type, UNVOICED ) )
{
/* UNVOICED frames (Gauss. excitation) */
@@ -621,11 +531,8 @@ ivas_error acelp_core_enc_fx(
st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode );
/* redo LSF quantization */
-#ifdef LSF_RE_USE_SECONDARY_CHANNEL
- lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new );
-#else
lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new );
-#endif
+
/* recalculation of LP residual (filtering through A[z] filter) */
calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx );
diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c
index 8268d48b142cb20ff33b821714ed20b4100168ee..90768aca13d512978efe7e20f566a7f5954d58b8 100644
--- a/lib_enc/acelp_core_switch_enc_fx.c
+++ b/lib_enc/acelp_core_switch_enc_fx.c
@@ -11,7 +11,6 @@
#include "prot_fx.h" /* Function prototypes */
#include "prot_fx_enc.h" /* Function prototypes */
#include "basop_util.h" /* Function prototypes */
-#include "prot.h"
/*---------------------------------------------------------------------*
* Local function prototypes
*---------------------------------------------------------------------*/
diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c
index d5bbfab29888b70eed940eb118b5ec21c260fc27..5a3aec3f43a5285fbb80f6ad2f3c87ed954dc59c 100644
--- a/lib_enc/amr_wb_enc_fx.c
+++ b/lib_enc/amr_wb_enc_fx.c
@@ -292,11 +292,7 @@ void amr_wb_enc_fx(
* Detect NB spectrum in a 16kHz-sampled input
*----------------------------------------------------------------*/
- analy_sp_fx( st->element_mode,
-#ifdef IVAS_CODE_CPE
- hCPE,
-#endif
- st->input_Fs, inp, Q_new, fr_bands, lf_E, &Etot, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx,
+ analy_sp_fx( st->element_mode, inp, Q_new, fr_bands, lf_E, &Etot, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx,
st->Bin_E_old_fx, PS, st->lgBin_E_fx, st->band_energies, fft_buff );
noise_est_pre_fx( Etot, st->ini_frame, hNoiseEst, 0, EVS_MONO, EVS_MONO );
@@ -351,12 +347,7 @@ void amr_wb_enc_fx(
high_lpn_flag = 0;
move16(); /* Q0 flag */
- long_enr_fx( st, Etot, localVAD_HE_SAD, high_lpn_flag
-#ifdef IVAS_CODE
- ,
- NULL, 1, NULL, NULL
-#endif
- );
+ long_enr_fx( st, Etot, localVAD_HE_SAD, high_lpn_flag );
relE = sub( Etot, st->lp_speech_fx ); /* Q8 */
IF( NE_16( st->bwidth, NB ) )
@@ -441,9 +432,6 @@ void amr_wb_enc_fx(
noise_est_fx( st, old_pitch1, tmpN, epsP_h, epsP_l, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum,
NULL, &sp_div, &Q_sp_div, &non_staX, &harm_flag,
lf_E, &hNoiseEst->harm_cor_cnt, hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_v_h2_fx, &hNoiseEst->bg_cnt, st->lgBin_E_fx, Q_new, Le_min_scaled, &sp_floor, NULL,
-#ifdef IVAS_CODE
- NULL, NULL,
-#endif
st->ini_frame );
/*----------------------------------------------------------------*
@@ -455,7 +443,7 @@ void amr_wb_enc_fx(
IF( EQ_32( st->input_Fs, 16000 ) )
{
/* no resampling needed, only delay adjustement to account for the FIR resampling delay */
- tmps = NS2SA_FX2( 16000, DELAY_FIR_RESAMPL_NS );
+ tmps = NS2SA( 16000, DELAY_FIR_RESAMPL_NS );
Copy_Scale_sig( &st->mem_decim16k_fx[tmps], new_inp_16k, tmps, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */
Copy_Scale_sig( st->input_fx, new_inp_16k + tmps, sub( input_frame, tmps ), -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */
Copy( st->input_fx + input_frame - shl( tmps, 1 ), st->mem_decim16k_fx, shl( tmps, 1 ) ); /* memory still in Q0 */
diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c
index d5333ae130e4cbdfb0ed45613db7c7d9f56761d6..185bac26bc7847ecd023228e95a204404ee2b044 100644
--- a/lib_enc/analy_sp_fx.c
+++ b/lib_enc/analy_sp_fx.c
@@ -19,9 +19,7 @@
static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies );
static void ivas_find_enr( Word16 *data, Word16 q_data, Word32 *band, Word16 *q_band, Word32 *ptE, Word16 *q_ptE, Word64 *LEtot, const Word16 min_band, const Word16 max_band, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies );
-#ifdef IVAS_CODE_CPE
-static void find_enr_dft( CPE_ENC_HANDLE hCPE, const int32_t input_Fs, float DFT_past_DMX[], float band[], float *ptE, float *Etot, const int16_t min_band, const int16_t max_band, float *Bin_E, float *band_ener );
-#endif
+
/*-------------------------------------------------------------------*
* analy_sp_fx()
@@ -31,10 +29,6 @@ static void find_enr_dft( CPE_ENC_HANDLE hCPE, const int32_t input_Fs, float DFT
void analy_sp_fx(
const Word16 element_mode, /* i : element mode */
-#ifdef IVAS_CODE_CPE
- CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
-#endif
- const Word32 input_Fs, /* i : input sampling rate */
Word16 *speech, /* i : speech buffer Q_new - preemph_bits */
const Word16 Q_new, /* i : current scaling exp Q0 */
Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */
@@ -60,9 +54,7 @@ void analy_sp_fx(
Word16 Min_val, Max_val;
Word16 Scale_fac2;
Word16 fft_temp[L_FFT];
-#ifndef IVAS_CODE_CPE
- (void) input_Fs;
-#endif
+
/*-----------------------------------------------------------------*
* Compute spectrum
* find energy per critical frequency band and total energy in dB
@@ -134,18 +126,6 @@ void analy_sp_fx(
pt_fft += L_FFT;
}
}
-#ifdef IVAS_CODE_CPE
- ELSE
- {
- /* find energy per critical band */
- find_enr_dft( hCPE, input_Fs, hCPE->hStereoDft->DFT[0], pt_bands, lf_E, Etot, min_band, max_band, Bin_E, band_ener );
- mvr2r( lf_E, lf_E + VOIC_BINS, VOIC_BINS );
- mvr2r( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 );
- mvr2r( band_ener, band_ener + NB_BANDS, NB_BANDS );
- mvr2r( pt_bands, pt_bands + NB_BANDS, NB_BANDS );
- *Etot *= 2.f;
- }
-#endif
/* Average total log energy over both half-frames */
frac_etot = 0;
diff --git a/lib_enc/ari_enc.c b/lib_enc/ari_enc.c
deleted file mode 100644
index da4d1486b8ab2c36bed04809489df3765d72cc14..0000000000000000000000000000000000000000
--- a/lib_enc/ari_enc.c
+++ /dev/null
@@ -1,316 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include "cnst.h"
-#include "prot.h"
-#include "prot_fx.h"
-#include "stat_com.h"
-#include "basop_util.h"
-#include "wmc_auto.h"
-#include "prot_fx_enc.h"
-
-
-/*---------------------------------------------------------------
- * ari_copy_states()
- *
- * Copy state
- *-------------------------------------------------------------*/
-
-void ari_copy_states(
- Tastat *source,
- Tastat *dest )
-{
- dest->low = source->low;
- dest->high = source->high;
- dest->bits_to_follow = source->bits_to_follow;
-
- return;
-}
-
-/*---------------------------------------------------------------
- Ari encoder 14 bits routines
- -------------------------------------------------------------*/
-
-/*---------------------------------------------------------------
- * ari_start_encoding_14bits()
- *
- * Start ArCo encoding
- *-------------------------------------------------------------*/
-
-void ari_start_encoding_14bits(
- Tastat *s )
-{
- /* : addressing is made with walking pointer s */
- s->low = 0;
- s->high = ari_q4new;
- s->bits_to_follow = 0;
- move32();
- move32();
- move32();
-
- return;
-}
-void ari_start_encoding_14bits_ivas_fx(
- Tastat *s )
-{
- /* : addressing is made with walking pointer s */
- s->low = 0;
- s->high = ari_q4new;
- s->bits_to_follow = 0;
- move32();
- move32();
- move32();
-
- return;
-}
-
-/*---------------------------------------------------------------
- * ari_done_encoding_14bits_ivas_fx()
- *
- * Finish ArCo encoding
- *-------------------------------------------------------------*/
-
-Word16 ari_done_encoding_14bits_ivas_fx(
- Word16 *ptr, /* Q0 */
- Word16 bp, /* Q0 */
- Tastat *s )
-{
- Word16 bit;
-
- bit = 0;
- move16();
- IF( GE_32( s->low, ari_q1new ) )
- {
- bit = s_xor( bit, 1 );
- }
- return ari_put_bit_plus_follow( ptr, bp, add( extract_l( s->bits_to_follow ), 1 ), bit );
-}
-
-
-/*---------------------------------------------------------------
- * ari_encode_14bits_ext_ivas_fx()
- *
- * encode function for extended proba tables: less branches needed for coding
- *
- *-------------------------------------------------------------*/
-Word16 ari_encode_14bits_ext_ivas_fx(
- Word16 *ptr, /* Q0 */
- Word16 bp, /* Q0 */
- Tastat *s,
- Word32 symbol, /* Q0 */
- UWord16 const *cum_freq /* Q0 */
-)
-{
- Word32 low;
- Word32 high;
- Word32 range;
- Word16 bits_to_follow;
- Word16 i;
- UWord16 temp;
- Word32 L_temp1, L_temp2;
-
- high = L_add( s->high, 0 );
- low = L_add( s->low, 0 );
- range = L_add( L_sub( high, low ), 1 ); /* Q0 */
-
- L_temp1 = L_shl( range, 15 - stat_bitsnew /*both are constants*/ );
- Mpy_32_16_ss( L_temp1, cum_freq[symbol + 1], &L_temp2, &temp );
- IF( symbol != 0 ) /* when symbol is 0, range remains unchanged */
- {
- Mpy_32_16_ss( L_temp1, cum_freq[symbol], &range, &temp );
- }
- high = L_sub( L_add( low, range ), 1 ); /* Q0 */
- low = L_add( low, L_temp2 ); /* Q0 */
-
- assert( s->bits_to_follow <= MAX_16 );
- bits_to_follow = extract_l( s->bits_to_follow ); /* Q0 */
-
- FOR( i = 0; i < 0x7FFF; i++ )
- {
- IF( LT_32( high, ari_q2new ) )
- {
- bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */
- bits_to_follow = 0;
- move16();
- }
- ELSE IF( GE_32( low, ari_q2new ) )
- {
- bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */
- bits_to_follow = 0;
- move16();
- low = L_sub( low, ari_q2new );
- high = L_sub( high, ari_q2new ); /* Subtract offset to top. */
- }
- ELSE
- {
- test();
- IF( GE_32( low, ari_q1new ) && LT_32( high, ari_q3new ) )
- {
- /* Output an opposite bit */
- /* later if in middle half. */
- bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */
- low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/
- high = L_sub( high, ari_q1new );
- }
- ELSE
- {
- BREAK; /* Otherwise exit loop. */
- }
- }
- low = L_add( low, low ); /* Q0 */
- high = L_add( L_add( high, high ), 1 ); /* Scale up code range. Q0*/
- }
-
- s->low = low; /* Q0 */
- move32();
- s->high = high; /* Q0 */
- move32();
- s->bits_to_follow = bits_to_follow; /* Q0 */
- move32();
-
- return bp;
-}
-
-
-/*------------------------------------------------------------------------
- * Function: ari_encode_14bits_high_low_fx()
- *
- *-------------------------------------------------------------------------*/
-
-static Word16 ari_encode_14bits_high_low_fx(
- Word16 *ptr, /* Q0 */
- Word16 bp, /* Q0 */
- Word16 bits, /* Q0 */
- Tastat *s,
- Word32 high, /* Q0 */
- Word32 low /* Q0 */
-)
-{
- Word16 bits_to_follow, tmp;
-
- bits_to_follow = extract_l( s->bits_to_follow ); /* Q0 */
- move16();
-
- /* while there are more than 16 bits left */
- tmp = sub( 16, bits ); /* Q0 */
- WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 )
- {
- IF( LE_32( high, ari_q2new ) )
- {
- bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */
- bits_to_follow = 0;
- move16();
- }
- ELSE IF( GE_32( low, ari_q2new ) )
- {
- bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */
- bits_to_follow = 0;
- move16();
- low = L_sub( low, ari_q2new ); /* Q0 */
- high = L_sub( high, ari_q2new ); /* Subtract offset to top. Q0*/
- }
- ELSE
- {
- test();
- IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) )
- {
- /* Output an opposite bit */
- /* later if in middle half. */
- bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */
- low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/
- high = L_sub( high, ari_q1new ); /* Q0 */
- }
- ELSE
- {
- BREAK; /* Otherwise exit loop. */
- }
- }
-
- low = L_add( low, low );
- high = L_add( high, high ); /* Scale up code range. */
- }
-
- s->low = low; /* Q0 */
- move32();
- s->high = L_sub( high, 1 ); /* Q0 */
- move32();
- s->bits_to_follow = bits_to_follow; /* Q0 */
- move16();
-
- return bp;
-}
-
-/*------------------------------------------------------------------------
- * Function: ari_encode_14bits_sign_ivas_fx()
- *
- * Encode a sign with equal probabilities.
- *-------------------------------------------------------------------------*/
-Word16 ari_encode_14bits_sign_ivas_fx(
- Word16 *ptr, /* Q0 */
- Word16 bp, /* Q0 */
- Word32 bits, /* Q0 */
- Tastat *s,
- Word16 sign /* Q0 */
-)
-{
- Word32 low, high, range;
- Word32 L_tmp;
-
- high = L_add( s->high, 1 );
- low = L_add( s->low, 0 );
- range = L_sub( high, low ); /* Q0 */
-
- L_tmp = L_shr( range, 1 );
- if ( sign != 0 )
- {
- high = L_add( low, L_tmp ); /* Q0 */
- }
- if ( sign == 0 )
- {
- low = L_add( low, L_tmp ); /* Q0 */
- }
-
- return ari_encode_14bits_high_low_fx( ptr, bp, extract_l( bits ), s, high, low );
-}
-
-/*------------------------------------------------------------------------
- * Function: ari_done_cbr_encoding_14bits()
- *
- * Finish up encoding in CBR mode.
- *-------------------------------------------------------------------------*/
diff --git a/lib_enc/ari_enc_fx.c b/lib_enc/ari_enc_fx.c
index 0ef053edd75ef58434abdc6fab944cb0851964de..29ddd838c69cfb2be54ccfd8d304168190e848bf 100644
--- a/lib_enc/ari_enc_fx.c
+++ b/lib_enc/ari_enc_fx.c
@@ -364,3 +364,226 @@ Word16 ari_done_cbr_encoding_14bits_fx(
return bp;
}
+
+void ari_start_encoding_14bits_ivas_fx(
+ Tastat *s )
+{
+ /* : addressing is made with walking pointer s */
+ s->low = 0;
+ s->high = ari_q4new;
+ s->bits_to_follow = 0;
+ move32();
+ move32();
+ move32();
+
+ return;
+}
+
+/*---------------------------------------------------------------
+ * ari_done_encoding_14bits_ivas_fx()
+ *
+ * Finish ArCo encoding
+ *-------------------------------------------------------------*/
+
+Word16 ari_done_encoding_14bits_ivas_fx(
+ Word16 *ptr, /* Q0 */
+ Word16 bp, /* Q0 */
+ Tastat *s )
+{
+ Word16 bit;
+
+ bit = 0;
+ move16();
+ IF( GE_32( s->low, ari_q1new ) )
+ {
+ bit = s_xor( bit, 1 );
+ }
+ return ari_put_bit_plus_follow( ptr, bp, add( extract_l( s->bits_to_follow ), 1 ), bit );
+}
+
+
+/*---------------------------------------------------------------
+ * ari_encode_14bits_ext_ivas_fx()
+ *
+ * encode function for extended proba tables: less branches needed for coding
+ *
+ *-------------------------------------------------------------*/
+Word16 ari_encode_14bits_ext_ivas_fx(
+ Word16 *ptr, /* Q0 */
+ Word16 bp, /* Q0 */
+ Tastat *s,
+ Word32 symbol, /* Q0 */
+ UWord16 const *cum_freq /* Q0 */
+)
+{
+ Word32 low;
+ Word32 high;
+ Word32 range;
+ Word16 bits_to_follow;
+ Word16 i;
+ UWord16 temp;
+ Word32 L_temp1, L_temp2;
+
+ high = L_add( s->high, 0 );
+ low = L_add( s->low, 0 );
+ range = L_add( L_sub( high, low ), 1 ); /* Q0 */
+
+ L_temp1 = L_shl( range, 15 - stat_bitsnew /*both are constants*/ );
+ Mpy_32_16_ss( L_temp1, cum_freq[symbol + 1], &L_temp2, &temp );
+ IF( symbol != 0 ) /* when symbol is 0, range remains unchanged */
+ {
+ Mpy_32_16_ss( L_temp1, cum_freq[symbol], &range, &temp );
+ }
+ high = L_sub( L_add( low, range ), 1 ); /* Q0 */
+ low = L_add( low, L_temp2 ); /* Q0 */
+
+ assert( s->bits_to_follow <= MAX_16 );
+ bits_to_follow = extract_l( s->bits_to_follow ); /* Q0 */
+
+ FOR( i = 0; i < 0x7FFF; i++ )
+ {
+ IF( LT_32( high, ari_q2new ) )
+ {
+ bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */
+ bits_to_follow = 0;
+ move16();
+ }
+ ELSE IF( GE_32( low, ari_q2new ) )
+ {
+ bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */
+ bits_to_follow = 0;
+ move16();
+ low = L_sub( low, ari_q2new );
+ high = L_sub( high, ari_q2new ); /* Subtract offset to top. */
+ }
+ ELSE
+ {
+ test();
+ IF( GE_32( low, ari_q1new ) && LT_32( high, ari_q3new ) )
+ {
+ /* Output an opposite bit */
+ /* later if in middle half. */
+ bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */
+ low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/
+ high = L_sub( high, ari_q1new );
+ }
+ ELSE
+ {
+ BREAK; /* Otherwise exit loop. */
+ }
+ }
+ low = L_add( low, low ); /* Q0 */
+ high = L_add( L_add( high, high ), 1 ); /* Scale up code range. Q0*/
+ }
+
+ s->low = low; /* Q0 */
+ move32();
+ s->high = high; /* Q0 */
+ move32();
+ s->bits_to_follow = bits_to_follow; /* Q0 */
+ move32();
+
+ return bp;
+}
+
+
+/*------------------------------------------------------------------------
+ * Function: ari_encode_14bits_high_low_fx()
+ *
+ *-------------------------------------------------------------------------*/
+
+static Word16 ari_encode_14bits_high_low_ivas_fx(
+ Word16 *ptr, /* Q0 */
+ Word16 bp, /* Q0 */
+ Word16 bits, /* Q0 */
+ Tastat *s,
+ Word32 high, /* Q0 */
+ Word32 low /* Q0 */
+)
+{
+ Word16 bits_to_follow, tmp;
+
+ bits_to_follow = extract_l( s->bits_to_follow ); /* Q0 */
+ move16();
+
+ /* while there are more than 16 bits left */
+ tmp = sub( 16, bits ); /* Q0 */
+ WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 )
+ {
+ IF( LE_32( high, ari_q2new ) )
+ {
+ bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */
+ bits_to_follow = 0;
+ move16();
+ }
+ ELSE IF( GE_32( low, ari_q2new ) )
+ {
+ bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */
+ bits_to_follow = 0;
+ move16();
+ low = L_sub( low, ari_q2new ); /* Q0 */
+ high = L_sub( high, ari_q2new ); /* Subtract offset to top. Q0*/
+ }
+ ELSE
+ {
+ test();
+ IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) )
+ {
+ /* Output an opposite bit */
+ /* later if in middle half. */
+ bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */
+ low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/
+ high = L_sub( high, ari_q1new ); /* Q0 */
+ }
+ ELSE
+ {
+ BREAK; /* Otherwise exit loop. */
+ }
+ }
+
+ low = L_add( low, low );
+ high = L_add( high, high ); /* Scale up code range. */
+ }
+
+ s->low = low; /* Q0 */
+ move32();
+ s->high = L_sub( high, 1 ); /* Q0 */
+ move32();
+ s->bits_to_follow = bits_to_follow; /* Q0 */
+ move16();
+
+ return bp;
+}
+
+/*------------------------------------------------------------------------
+ * Function: ari_encode_14bits_sign_ivas_fx()
+ *
+ * Encode a sign with equal probabilities.
+ *-------------------------------------------------------------------------*/
+Word16 ari_encode_14bits_sign_ivas_fx(
+ Word16 *ptr, /* Q0 */
+ Word16 bp, /* Q0 */
+ Word32 bits, /* Q0 */
+ Tastat *s,
+ Word16 sign /* Q0 */
+)
+{
+ Word32 low, high, range;
+ Word32 L_tmp;
+
+ high = L_add( s->high, 1 );
+ low = L_add( s->low, 0 );
+ range = L_sub( high, low ); /* Q0 */
+
+ L_tmp = L_shr( range, 1 );
+ if ( sign != 0 )
+ {
+ high = L_add( low, L_tmp ); /* Q0 */
+ }
+ if ( sign == 0 )
+ {
+ low = L_add( low, L_tmp ); /* Q0 */
+ }
+
+ return ari_encode_14bits_high_low_ivas_fx( ptr, bp, extract_l( bits ), s, high, low );
+}
diff --git a/lib_enc/ari_hm_enc.c b/lib_enc/ari_hm_enc.c
deleted file mode 100644
index c6e11a3f0db760424be54b7fd697d375b5b070d4..0000000000000000000000000000000000000000
--- a/lib_enc/ari_hm_enc.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "rom_enc.h"
-#include "stl.h"
-#include "basop_util.h"
-#include "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
-
-/*-------------------------------------------------------------------*
- * EncodeIndex()
- *
- *
- *-------------------------------------------------------------------*/
diff --git a/lib_enc/ari_hm_enc_fx.c b/lib_enc/ari_hm_enc_fx.c
index a94f45528ec7e3d57470eb6e72b2aace5aa198ff..76d48ccf4318fd1aa0931b8b8358876751c1d6e1 100644
--- a/lib_enc/ari_hm_enc_fx.c
+++ b/lib_enc/ari_hm_enc_fx.c
@@ -10,9 +10,7 @@
#include "basop_util.h"
#include "rom_com.h"
#include "rom_enc.h"
-#include "prot.h"
-//#include "prot_fx.h"
-#include "prot_fx.h" /* Function prototypes */
+#include "prot_fx.h"
#include "prot_fx_enc.h" /* Function prototypes */
/*-------------------------------------------------------------------*
diff --git a/lib_enc/arith_coder_enc.c b/lib_enc/arith_coder_enc.c
deleted file mode 100644
index 5625b6cf4f0b75eadea8ae2cf8bac61a4b75db4c..0000000000000000000000000000000000000000
--- a/lib_enc/arith_coder_enc.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "prot.h"
-#include "rom_com.h"
-#include "basop_util.h"
-#include "basop_proto_func.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-/*-------------------------------------------------------------------*
- * Local constants
- *-------------------------------------------------------------------*/
diff --git a/lib_enc/avq_cod.c b/lib_enc/avq_cod.c
deleted file mode 100644
index 9228e2f5d74225dead52c212c28881aa61812ea6..0000000000000000000000000000000000000000
--- a/lib_enc/avq_cod.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c
index 202d60e51dd8e9c72ef431928b3ad14fefafaef8..93a0146f32fa21e94ab10f37f779061b373dc32c 100644
--- a/lib_enc/avq_cod_fx.c
+++ b/lib_enc/avq_cod_fx.c
@@ -5,9 +5,7 @@
#include
#include "options.h" /* Compilation switches */
#include "cnst.h"
-#include /* Compilation switches */
-#include "prot.h" /* Function prototypes */
-//#include "prot_fx.h" /* Function prototypes */
+#include /* Compilation switches */
#include "prot_fx.h" /* Function prototypes */
#include "prot_fx_enc.h" /* Function prototypes */
#include "rom_com.h" /* Static table prototypes */
diff --git a/lib_enc/bass_psfilter_enc.c b/lib_enc/bass_psfilter_enc.c
deleted file mode 100644
index 9228e2f5d74225dead52c212c28881aa61812ea6..0000000000000000000000000000000000000000
--- a/lib_enc/bass_psfilter_enc.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c
deleted file mode 100644
index d86351ae8053e5deb265beef6dceb16d1cc13e22..0000000000000000000000000000000000000000
--- a/lib_enc/bw_detect.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "rom_enc.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "ivas_prot.h"
-#include "wmc_auto.h"
-
-/*-------------------------------------------------------------------*
- * Local constants
- *-------------------------------------------------------------------*/
-
-#define BWD_MIN_BRATE_WIDER_BW_MDCT IVAS_48k
-#define BWD_MIN_BRATE_WIDER_BW_ISM IVAS_32k
-#define BWD_MAX_BRATE_WIDER_BW_MDCT IVAS_80k
-#define BWD_MAX_BRATE_WIDER_BW_ISM IVAS_64k
-
-#define ALPHA_BWD 0.75f
-#define BWD_LT_THRESH 0.6f
-
-#define BWD_COUNT_MAX 100
-#define BWD_COUNT_WIDER_BW 10
-#define BWD_COUNT_WIDER_BW_MDCT 0
-
-#define CLDFB_ENER_OFFSET 1.6f
diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c
index 931b175ffcbcb81b781ceca892d01c8d71a9c16c..2e9b2c5db1fa63e6e80f58b43617227bab6bd2cb 100644
--- a/lib_enc/bw_detect_fx.c
+++ b/lib_enc/bw_detect_fx.c
@@ -67,12 +67,6 @@ void bw_detect_fx(
const Word32 *pt32;
Word32 max_NB32, max_WB32, max_SWB32, max_FB32, mean_NB32, mean_WB32, mean_SWB32, mean_FB32; /* Q11*/ /* we need Word32 for the new cldfb energy vectors */
Word16 bwd_count_wider_bw;
-#ifdef IVAS_CODE_DFT
- Word16 l_frame;
-#endif
-#ifndef IVAS_CODE_BWD
- (void) spectrum;
-#endif
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
@@ -1046,7 +1040,7 @@ void set_bw_fx(
move16();
}
}
-//#ifdef IVAS_CODE_BWD
+
/*-------------------------------------------------------------------*
* set_bw_stereo()
@@ -1093,7 +1087,8 @@ void set_bw_stereo_fx(
return;
}
-//#endif
+
+
/*-------------------------------------------------------------------*
* set_bw_mct()
*
diff --git a/lib_enc/cng_enc.c b/lib_enc/cng_enc.c
deleted file mode 100644
index 192a71f92588c5dd802efa7755d73918a0321b2c..0000000000000000000000000000000000000000
--- a/lib_enc/cng_enc.c
+++ /dev/null
@@ -1,429 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "rom_enc.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
-
-#include "prot_fx_enc.h"
-#include "prot_fx.h"
-#include "ivas_rom_com_fx.h"
-
-/*---------------------------------------------------------------------*
- * Local function prototypes
- *---------------------------------------------------------------------*/
-
-static Word16 shb_DTX_ivas_fx( Encoder_State *st, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k_fx );
-
-static void shb_CNG_encod_ivas_fx( Encoder_State *st, const Word16 update );
-
-
-void swb_CNG_enc_ivas_fx(
- Encoder_State *st, /* i/o: State structure */
- const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */
- const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */
-)
-{
- Word16 shb_SID_updt;
-
- test();
- IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
- {
- IF( st->cng_type == LP_CNG )
- {
- test();
- IF( GE_32( st->input_Fs, L_FRAME32k * FRAMES_PER_SEC ) )
- {
- /* decide if SHB SID encoding or not */
- shb_SID_updt = shb_DTX_ivas_fx( st, shb_speech_fx, syn_12k8_16k_fx );
-
- /* SHB CNG encoding */
- shb_CNG_encod_ivas_fx( st, shb_SID_updt );
- }
- ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_32( st->core_brate, SID_2k40 ) )
- {
- /* LF-boost not used in DFT-stereo, instead the bandwidth is transmitted */
- delete_indice( st->hBstr, IND_CNG_ENV1 );
- push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 );
- push_indice( st->hBstr, IND_UNUSED, 0, 4 );
- push_indice( st->hBstr, IND_SID_BW, 1, 1 );
- }
- }
- st->hTdCngEnc->last_vad = 0;
- move16();
- }
- ELSE
- {
- st->hTdCngEnc->last_vad = 1;
- move16();
- }
-
- return;
-}
-
-
-/*---------------------------------------------------------------------*
- * shb_CNG_encod()
- *
- * SID parameters encoding for SHB signal
- *---------------------------------------------------------------------*/
-
-static void shb_CNG_encod_ivas_fx(
- Encoder_State *st, /* i/o: State structure */
- const Word16 update /* i : SID update flag */
-)
-{
- Word16 idx_ener = 0;
- move16();
- BSTR_ENC_HANDLE hBstr = st->hBstr;
-
- Word16 ener_mid_dec_thr_fx;
-
- IF( EQ_16( update, 1 ) )
- {
- IF( st->element_mode == EVS_MONO )
- {
- /* 6.0 in Q8 -> 1510 */
- /* 0.9 in Q15 29491 */
- /* ( 1 / log10(2.0) ) * 0.1 in Q15 ->10886 */
- idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 29491 ), 8 ); /* Q0 */
- }
- ELSE
- {
- /*idx_ener = (int16_t)(0.7f * (0.1f * st->hTdCngEnc->mov_shb_cng_ener / (float)log10(2.0f) + 6.0f) + 0.5f);*/
- // PMT("shb_CNG_encod_fx quantization in missing")
- /* 6.0 in Q8 -> 1510 */
- /* 0.7 in Q15 22938 */
- /* ( 1 / log10(2.0) ) * 0.1 in Q15 -> 10886 */
- idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 22938 ), 8 ); /* Q0 */
- }
-
-
- if ( LT_16( st->bwidth, SWB ) )
- {
- idx_ener = 0;
- move16();
- }
-
- IF( GT_16( idx_ener, 15 ) )
- {
- idx_ener = 15;
- move16();
- }
- ELSE IF( idx_ener < 0 )
- {
- idx_ener = 0;
- move16();
- }
-
- /* prevent toggling of idx_ener by adding small dead-zone interval around decision thresholds */
- IF( st->element_mode != EVS_MONO )
- {
- IF( EQ_16( abs_s( sub( idx_ener, st->hTdCngEnc->last_idx_ener ) ), 1 ) )
- {
-
- Word16 tmp, tmp1, tmp2, scale, exp1, exp2, ener_mid_dec_thr_e;
- tmp = BASOP_Util_Divide1616_Scale( st->hTdCngEnc->last_idx_ener, 22938, &scale ); // 0.7 in Q15 ->exp 0
- scale = add( scale, ( 15 - 0 ) );
- tmp = sub( tmp, shl( 6, sub( Q15, scale ) ) );
- tmp1 = BASOP_Util_Divide1616_Scale( tmp, 3277, &exp1 );
- exp1 = add( exp1, ( scale - 0 ) );
-
- ener_mid_dec_thr_fx = shr( mult( tmp1, 9864 ), 1 ); // exp = exp
-
- tmp = BASOP_Util_Divide1616_Scale( idx_ener, 22938, &scale ); // 0.7 in Q15 ->exp 0
- scale = add( scale, ( 15 - 0 ) );
- tmp = sub( tmp, shl( 6, sub( Q15, scale ) ) );
- tmp1 = BASOP_Util_Divide1616_Scale( tmp, 3277, &exp2 );
- exp2 = add( exp2, ( scale - 0 ) );
-
- tmp2 = shr( mult( tmp1, 9864 ), 1 ); // exp = exp
-
- ener_mid_dec_thr_e = BASOP_Util_Add_MantExp( tmp2, exp2, ener_mid_dec_thr_fx, exp1, &ener_mid_dec_thr_fx );
-
-
- scale = BASOP_Util_Add_MantExp( st->hTdCngEnc->mov_shb_cng_ener_fx, 7, negate( ener_mid_dec_thr_fx ), ener_mid_dec_thr_e, &tmp );
- tmp1 = BASOP_Util_Divide1616_Scale( tmp, ener_mid_dec_thr_fx, &exp1 );
- exp1 = add( exp1, sub( scale, ener_mid_dec_thr_e ) );
- IF( LT_16( abs_s( tmp1 ), shr( 328, sub( 15, exp1 ) ) ) )
- {
- idx_ener = st->hTdCngEnc->last_idx_ener;
- move16();
- }
- }
- }
-
- st->hTdCngEnc->last_idx_ener = idx_ener;
- move16();
-
- push_indice( hBstr, IND_SHB_CNG_GAIN, idx_ener, 4 );
- push_indice( hBstr, IND_SID_BW, 1, 1 );
- delete_indice( hBstr, IND_CNG_ENV1 );
- IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
- {
- push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 );
- }
- ELSE
- {
- push_indice( hBstr, IND_UNUSED, 0, 2 );
- }
- st->hTdCngEnc->ho_sid_bw = L_shl( L_and( st->hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 );
- st->hTdCngEnc->ho_sid_bw = L_or( st->hTdCngEnc->ho_sid_bw, 0x1L );
- move32();
- move32();
- }
- ELSE IF( EQ_32( st->core_brate, SID_2k40 ) )
- {
- st->hTdCngEnc->ho_sid_bw = L_shl( L_and( st->hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 );
- move32();
- push_indice( hBstr, IND_SID_BW, 0, 1 );
- }
-
- return;
-}
-
-/*---------------------------------------------------------------------*
- * shb_DTX()
- *
- * Decide if encoding SHB SID or not
- *---------------------------------------------------------------------*/
-
-static Word16 shb_DTX_ivas_fx(
- Encoder_State *st, /* i/o: State structure */
- const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */
- const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */
-)
-{
- Word16 i;
- Word16 update;
-
- Word16 allow_cn_step = 0;
- move16();
- Word16 shb_old_speech_fx[( ACELP_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 4];
- Word16 *shb_new_speech_fx;
- Word32 wb_ener_fx;
- Word32 shb_ener_fx;
- Word16 log_wb_ener_fx;
- Word16 log_shb_ener_fx;
- Word16 tmp;
- Word16 exp;
- Word16 fra;
- Word16 att_fx; /*Q8*/
-
- TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc;
- TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD;
-
-
-#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
- move16();
-#endif
-
- shb_new_speech_fx = shb_old_speech_fx + ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4;
- Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); // old_speech_shb_fx -> Q0
- Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); // Q0
- Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); // Q0
-
- shb_ener_fx = L_deposit_l( 0 );
- FOR( i = 0; i < L_FRAME16k; i++ )
- {
- shb_ener_fx = L_mac_sat( shb_ener_fx, shb_old_speech_fx[i], shb_old_speech_fx[i] ); // ( Q0 + Q0 + Q1 ) --> Q1 due to left shift in L_mac
- }
-
- shb_ener_fx = L_add( Mpy_32_16_1( shb_ener_fx, 102 ), 1 ); /* ( 1 / L_FRAME16K ) -> 102 in Q15, shb_ener_fx in Q1 */
-
- wb_ener_fx = L_deposit_l( 0 );
- FOR( i = 0; i < st->L_frame; i++ )
- {
- wb_ener_fx = L_mac_o( wb_ener_fx, syn_12k8_16k_fx[i], syn_12k8_16k_fx[i], &Overflow ); // ( Q0 + Q0 + Q1 ) --> Q1 due to left shift in L_mac
- }
-
- wb_ener_fx = L_add( Mpy_32_16_1( wb_ener_fx, 128 ), 1 ); /* 128 in Q15, wb_ener_fx in Q1 */
-
- exp = norm_l( wb_ener_fx );
- fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) );
- exp = sub( 30 - 1, exp );
- wb_ener_fx = Mpy_32_16( exp, fra, LG10 );
-
- log_wb_ener_fx = round_fx_o( L_shl_o( wb_ener_fx, 10, &Overflow ), &Overflow ); /* log_wb_ener_fx in Q8 */
- exp = norm_l( shb_ener_fx );
- fra = Log2_norm_lc( L_shl( shb_ener_fx, exp ) );
- exp = sub( 30 - 1, exp );
- shb_ener_fx = Mpy_32_16( exp, fra, LG10 );
-
-
- test();
- IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) )
- {
- Word32 att_fx32 = 0;
- move32();
- Word16 index;
-
- apply_scale_ivas_fx( &att_fx32, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO, &index ); // Q23;
-
- att_fx = extract_l( L_shr( att_fx32, 15 ) ); // Q8
- }
- ELSE
- {
- att_fx = -1664; // Q8
- move16();
- }
-
-
- log_shb_ener_fx = sub_o( round_fx_o( L_shl_o( shb_ener_fx, 10, &Overflow ), &Overflow ), att_fx, &Overflow ); /* log_shb_ener_fx in Q8 */
-
- IF( st->hDtxEnc->first_CNG == 0 )
- {
-
-
- hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; // Q8
- hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; // Q8
- hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; // Q8
- hTdCngEnc->last_shb_cng_ener_fx = log_shb_ener_fx; // Q8
- move16();
- move16();
- move16();
- move16();
- }
- IF( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12 in Q8*/ ) )
- {
- allow_cn_step = 1;
- move16();
- }
-
- /* Also allow step if shb energy has dropped 12 dB */
- test();
- test();
- IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GT_16( sub( hTdCngEnc->mov_shb_cng_ener_fx, log_shb_ener_fx ), 3072 /*12 in Q8*/ ) )
- {
- allow_cn_step = 1;
- move16();
- }
-
- IF( EQ_16( allow_cn_step, 1 ) )
- {
- hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx;
- hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx;
- move16();
- move16();
- }
- ELSE
- {
- tmp = sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ); /* Q8 */
- tmp = mult( tmp, 29491 /* .9f in Q15*/ ); /* Q8 */
- hTdCngEnc->mov_wb_cng_ener_fx = add( hTdCngEnc->mov_wb_cng_ener_fx, tmp ); /* Q8 */
- move16();
-
- tmp = sub( log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx );
- tmp = mult( tmp, 8192 /* .25f in Q15*/ ); /* Q8 */
- hTdCngEnc->mov_shb_cng_ener_fx = add( hTdCngEnc->mov_shb_cng_ener_fx, tmp ); /* Q8 */
- move16();
- }
-
- hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 );
- update = 0;
-
- move16();
- move16();
-
- IF( EQ_32( st->core_brate, SID_2k40 ) )
- {
- test();
- test();
- test();
- IF( st->hDtxEnc->first_CNG == 0 )
- {
- update = 1;
- move16();
- }
- ELSE IF( hTdCngEnc->shb_cng_ini_cnt > 0 )
- {
- hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 );
- update = 1;
- move16();
- move16();
- }
- ELSE IF( EQ_16( hTdCngEnc->last_vad, 1 ) )
- {
- update = 1;
- move16();
- }
- ELSE IF( GE_16( hTdCngEnc->shb_NO_DATA_cnt, 100 ) )
- {
- update = 1;
- move16();
- }
- ELSE IF( GT_16( abs_s( sub( sub( hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ), sub( hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx ) ) ), 768 ) )
- {
- update = 1;
- move16();
- }
- ELSE IF( ( GE_16( st->bwidth, SWB ) && LT_16( hTdCngEnc->last_SID_bwidth, SWB ) ) || ( LT_16( st->bwidth, SWB ) && GE_16( hTdCngEnc->last_SID_bwidth, SWB ) ) )
- {
- update = 1;
- move16();
- }
-
- hTdCngEnc->last_SID_bwidth = st->bwidth;
- move16();
- }
-
- /* LF-boost not yet implemented in decoder which means that the specific wb_sid information is not used */
- test();
- test();
- if ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_32( st->core_brate, SID_2k40 ) )
- {
- update = 1;
- move16();
- }
-
- IF( EQ_16( update, 1 ) )
- {
- hTdCngEnc->last_wb_cng_ener_fx = hTdCngEnc->mov_wb_cng_ener_fx;
- hTdCngEnc->last_shb_cng_ener_fx = hTdCngEnc->mov_shb_cng_ener_fx;
- hTdCngEnc->shb_NO_DATA_cnt = 0;
- move16();
- move16();
- move16();
- }
-
- return ( update );
-}
diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c
index 4cfc193ecc5785ac74d5b4e0bc75405f86d11176..e1b5ca5625949a8625c300fcdde0e0fba92cef03 100644
--- a/lib_enc/cng_enc_fx.c
+++ b/lib_enc/cng_enc_fx.c
@@ -2,12 +2,10 @@
EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
====================================================================================*/
#include
-#include "options.h" /* Compilation switches */
-#include "cnst.h" /* Common constants */
-#include "rom_enc.h" /* Encoder static table prototypes */
-#include "rom_com.h" /* Static table prototypes */
-//#include "prot_fx.h" /* Function prototypes */
-#include "prot.h" /* Function prototypes */
+#include "options.h" /* Compilation switches */
+#include "cnst.h" /* Common constants */
+#include "rom_enc.h" /* Encoder static table prototypes */
+#include "rom_com.h" /* Static table prototypes */
#include "prot_fx.h" /* Function prototypes */
#include "prot_fx_enc.h" /* Function prototypes */
//#include "basop_mpy.h"
@@ -27,6 +25,8 @@
*---------------------------------------------------------------------*/
static void shb_CNG_encod_fx( Encoder_State *st_fx, const Word16 update_fx );
static Word16 shb_DTX_fx( Encoder_State *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k );
+static Word16 shb_DTX_ivas_fx( Encoder_State *st, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k_fx );
+static void shb_CNG_encod_ivas_fx( Encoder_State *st, const Word16 update );
/*---------------------------------------------------------------------*
* CNG_enc()
*
@@ -336,11 +336,7 @@ void CNG_enc_fx(
}
ELSE
{
-#ifdef LSF_RE_USE_SECONDARY_CHANNEL
- lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 100, 0, 0, NULL, Q_new );
-#else
lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 100, 0, 0, Q_new );
-#endif
}
/* Reset CNG history if CNG frame length is changed */
test();
@@ -729,11 +725,6 @@ void CNG_enc_fx(
test();
IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) )
{
- // PMT("Code to be completed")
-#ifdef IVAS_CODE
- att = powf( 10.0f, hTdCngEnc->CNG_att / 20.0f );
- v_multc( res1, att, res1, st->L_frame );
-#endif
}
ELSE IF( NE_16( st_fx->bwidth, NB ) )
{
@@ -911,9 +902,6 @@ void CNG_enc_fx(
test();
IF( EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) )
{
- // PMT("CNG IVAS_SCE and IVAS_CPE_DFT code missing")
- // IVAS_CODE
- // enr += hTdCngEnc->CNG_att * FAC_LOG2 / 10.0f;
}
ELSE IF( NE_16( st_fx->bwidth, NB ) )
{
@@ -2417,14 +2405,6 @@ void swb_CNG_enc_fx(
}
ELSE IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && EQ_32( st_fx->core_brate, SID_2k40 ) )
{
- // PMT("CNG IVAS_CPE_DFT code not implemented")
-#ifdef IVAS_CODE
- /* LF-boost not used in DFT-stereo, instead the bandwidth is transmitted */
- delete_indice( st->hBstr, IND_CNG_ENV1 );
- push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 );
- push_indice( st->hBstr, IND_UNUSED, 0, 4 );
- push_indice( st->hBstr, IND_SID_BW, 1, 1 );
-#endif
}
}
hTdCngEnc->last_vad = 0;
@@ -2452,9 +2432,6 @@ static void shb_CNG_encod_fx(
Word16 idx_ener_fx;
TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc;
BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
-#ifdef IVAS_CODE
- Word16 ener_mid_dec_thr;
-#endif
idx_ener_fx = 0;
move16();
@@ -2467,8 +2444,6 @@ static void shb_CNG_encod_fx(
}
ELSE
{
- /*idx_ener = (int16_t)(0.7f * (0.1f * st->hTdCngEnc->mov_shb_cng_ener / (float)log10(2.0f) + 6.0f) + 0.5f);*/
- // PMT("shb_CNG_encod_fx quantization in missing")
}
if ( LT_16( st_fx->bwidth, SWB ) )
@@ -2486,41 +2461,18 @@ static void shb_CNG_encod_fx(
{
idx_ener_fx = s_max( idx_ener_fx, 0 );
}
-#ifdef IVAS_CODE
- /* prevent toggling of idx_ener by adding small dead-zone interval around decision thresholds */
- if ( st->element_mode != EVS_MONO )
- {
- if ( abs( idx_ener - st->hTdCngEnc->last_idx_ener ) == 1 )
- {
- ener_mid_dec_thr = 0.5f * ( ( st->hTdCngEnc->last_idx_ener / 0.7f - 6.0f ) / 0.1f ) * (float) log10( 2.0f );
- ener_mid_dec_thr += 0.5f * ( ( idx_ener / 0.7f - 6.0f ) / 0.1f ) * (float) log10( 2.0f );
- if ( fabs( st->hTdCngEnc->mov_shb_cng_ener - ener_mid_dec_thr ) / ener_mid_dec_thr < ENER_MID_DEAD_ZONE )
- {
- idx_ener = st->hTdCngEnc->last_idx_ener;
- }
- }
- }
-
- st->hTdCngEnc->last_idx_ener = idx_ener;
-#endif
push_indice_fx( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4 );
push_indice_fx( hBstr, IND_SID_BW, 1, 1 );
-#ifndef IVAS_CODE
hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_CNG_ENV1].nb_bits );
hBstr->ind_list[IND_CNG_ENV1].nb_bits = -1;
move16();
move16();
-#else
- delete_indice( hBstr, IND_CNG_ENV1 );
-#endif
-#ifdef IVAS_CODE
- if ( st->element_mode == IVAS_CPE_DFT )
+
+ if ( st_fx->element_mode == IVAS_CPE_DFT )
{
- push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 );
}
else
-#endif
{
push_indice_fx( hBstr, IND_UNUSED, 0, 2 );
}
@@ -2635,13 +2587,7 @@ static Word16 shb_DTX_fx(
allow_cn_step_fx = 1;
move16();
}
-#ifdef IVAS_CODE
- /* Also allow step if shb energy has dropped 12 dB */
- if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( ( hTdCngEnc->mov_shb_cng_ener - log_shb_ener ) > 12.0f ) )
- {
- allow_cn_step = 1;
- }
-#endif
+
IF( EQ_16( allow_cn_step_fx, 1 ) )
{
hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx;
@@ -2761,13 +2707,10 @@ void calculate_hangover_attenuation_gain_fx(
test();
IF( hTdCngEnc->burst_ho_cnt > 0 && ( vad_hover_flag != 0 ) && ( NE_16( st->bwidth, NB ) || st->element_mode > EVS_MONO ) ) /* corresponds to line 504 in FLT acelp_core_enc.c */
{
-#ifdef IVAS_CODE
if ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD )
{
- *att = powf( 10.0f, ( st->hTdCngEnc->CNG_att / 160.0f ) * st->hTdCngEnc->burst_ho_cnt );
}
else
-#endif
{
offset = 5;
move16();
@@ -2839,3 +2782,375 @@ void calculate_hangover_attenuation_gain_ivas_fx(
return;
}
+
+void swb_CNG_enc_ivas_fx(
+ Encoder_State *st, /* i/o: State structure */
+ const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */
+ const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */
+)
+{
+ Word16 shb_SID_updt;
+
+ test();
+ IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
+ {
+ IF( st->cng_type == LP_CNG )
+ {
+ test();
+ IF( GE_32( st->input_Fs, L_FRAME32k * FRAMES_PER_SEC ) )
+ {
+ /* decide if SHB SID encoding or not */
+ shb_SID_updt = shb_DTX_ivas_fx( st, shb_speech_fx, syn_12k8_16k_fx );
+
+ /* SHB CNG encoding */
+ shb_CNG_encod_ivas_fx( st, shb_SID_updt );
+ }
+ ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_32( st->core_brate, SID_2k40 ) )
+ {
+ /* LF-boost not used in DFT-stereo, instead the bandwidth is transmitted */
+ delete_indice( st->hBstr, IND_CNG_ENV1 );
+ push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 );
+ push_indice( st->hBstr, IND_UNUSED, 0, 4 );
+ push_indice( st->hBstr, IND_SID_BW, 1, 1 );
+ }
+ }
+ st->hTdCngEnc->last_vad = 0;
+ move16();
+ }
+ ELSE
+ {
+ st->hTdCngEnc->last_vad = 1;
+ move16();
+ }
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * shb_CNG_encod()
+ *
+ * SID parameters encoding for SHB signal
+ *---------------------------------------------------------------------*/
+
+static void shb_CNG_encod_ivas_fx(
+ Encoder_State *st, /* i/o: State structure */
+ const Word16 update /* i : SID update flag */
+)
+{
+ Word16 idx_ener = 0;
+ move16();
+ BSTR_ENC_HANDLE hBstr = st->hBstr;
+
+ Word16 ener_mid_dec_thr_fx;
+
+ IF( EQ_16( update, 1 ) )
+ {
+ IF( st->element_mode == EVS_MONO )
+ {
+ /* 6.0 in Q8 -> 1510 */
+ /* 0.9 in Q15 29491 */
+ /* ( 1 / log10(2.0) ) * 0.1 in Q15 ->10886 */
+ idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 29491 ), 8 ); /* Q0 */
+ }
+ ELSE
+ {
+ /*idx_ener = (int16_t)(0.7f * (0.1f * st->hTdCngEnc->mov_shb_cng_ener / (float)log10(2.0f) + 6.0f) + 0.5f);*/
+ // PMT("shb_CNG_encod_fx quantization in missing")
+ /* 6.0 in Q8 -> 1510 */
+ /* 0.7 in Q15 22938 */
+ /* ( 1 / log10(2.0) ) * 0.1 in Q15 -> 10886 */
+ idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 22938 ), 8 ); /* Q0 */
+ }
+
+
+ if ( LT_16( st->bwidth, SWB ) )
+ {
+ idx_ener = 0;
+ move16();
+ }
+
+ IF( GT_16( idx_ener, 15 ) )
+ {
+ idx_ener = 15;
+ move16();
+ }
+ ELSE IF( idx_ener < 0 )
+ {
+ idx_ener = 0;
+ move16();
+ }
+
+ /* prevent toggling of idx_ener by adding small dead-zone interval around decision thresholds */
+ IF( st->element_mode != EVS_MONO )
+ {
+ IF( EQ_16( abs_s( sub( idx_ener, st->hTdCngEnc->last_idx_ener ) ), 1 ) )
+ {
+
+ Word16 tmp, tmp1, tmp2, scale, exp1, exp2, ener_mid_dec_thr_e;
+ tmp = BASOP_Util_Divide1616_Scale( st->hTdCngEnc->last_idx_ener, 22938, &scale ); // 0.7 in Q15 ->exp 0
+ scale = add( scale, ( 15 - 0 ) );
+ tmp = sub( tmp, shl( 6, sub( Q15, scale ) ) );
+ tmp1 = BASOP_Util_Divide1616_Scale( tmp, 3277, &exp1 );
+ exp1 = add( exp1, ( scale - 0 ) );
+
+ ener_mid_dec_thr_fx = shr( mult( tmp1, 9864 ), 1 ); // exp = exp
+
+ tmp = BASOP_Util_Divide1616_Scale( idx_ener, 22938, &scale ); // 0.7 in Q15 ->exp 0
+ scale = add( scale, ( 15 - 0 ) );
+ tmp = sub( tmp, shl( 6, sub( Q15, scale ) ) );
+ tmp1 = BASOP_Util_Divide1616_Scale( tmp, 3277, &exp2 );
+ exp2 = add( exp2, ( scale - 0 ) );
+
+ tmp2 = shr( mult( tmp1, 9864 ), 1 ); // exp = exp
+
+ ener_mid_dec_thr_e = BASOP_Util_Add_MantExp( tmp2, exp2, ener_mid_dec_thr_fx, exp1, &ener_mid_dec_thr_fx );
+
+
+ scale = BASOP_Util_Add_MantExp( st->hTdCngEnc->mov_shb_cng_ener_fx, 7, negate( ener_mid_dec_thr_fx ), ener_mid_dec_thr_e, &tmp );
+ tmp1 = BASOP_Util_Divide1616_Scale( tmp, ener_mid_dec_thr_fx, &exp1 );
+ exp1 = add( exp1, sub( scale, ener_mid_dec_thr_e ) );
+ IF( LT_16( abs_s( tmp1 ), shr( 328, sub( 15, exp1 ) ) ) )
+ {
+ idx_ener = st->hTdCngEnc->last_idx_ener;
+ move16();
+ }
+ }
+ }
+
+ st->hTdCngEnc->last_idx_ener = idx_ener;
+ move16();
+
+ push_indice( hBstr, IND_SHB_CNG_GAIN, idx_ener, 4 );
+ push_indice( hBstr, IND_SID_BW, 1, 1 );
+ delete_indice( hBstr, IND_CNG_ENV1 );
+ IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
+ {
+ push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 );
+ }
+ ELSE
+ {
+ push_indice( hBstr, IND_UNUSED, 0, 2 );
+ }
+ st->hTdCngEnc->ho_sid_bw = L_shl( L_and( st->hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 );
+ st->hTdCngEnc->ho_sid_bw = L_or( st->hTdCngEnc->ho_sid_bw, 0x1L );
+ move32();
+ move32();
+ }
+ ELSE IF( EQ_32( st->core_brate, SID_2k40 ) )
+ {
+ st->hTdCngEnc->ho_sid_bw = L_shl( L_and( st->hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 );
+ move32();
+ push_indice( hBstr, IND_SID_BW, 0, 1 );
+ }
+
+ return;
+}
+
+/*---------------------------------------------------------------------*
+ * shb_DTX()
+ *
+ * Decide if encoding SHB SID or not
+ *---------------------------------------------------------------------*/
+
+static Word16 shb_DTX_ivas_fx(
+ Encoder_State *st, /* i/o: State structure */
+ const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */
+ const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */
+)
+{
+ Word16 i;
+ Word16 update;
+
+ Word16 allow_cn_step = 0;
+ move16();
+ Word16 shb_old_speech_fx[( ACELP_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 4];
+ Word16 *shb_new_speech_fx;
+ Word32 wb_ener_fx;
+ Word32 shb_ener_fx;
+ Word16 log_wb_ener_fx;
+ Word16 log_shb_ener_fx;
+ Word16 tmp;
+ Word16 exp;
+ Word16 fra;
+ Word16 att_fx; /*Q8*/
+
+ TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc;
+ TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD;
+
+
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+ move16();
+#endif
+
+ shb_new_speech_fx = shb_old_speech_fx + ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4;
+ Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); // old_speech_shb_fx -> Q0
+ Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); // Q0
+ Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); // Q0
+
+ shb_ener_fx = L_deposit_l( 0 );
+ FOR( i = 0; i < L_FRAME16k; i++ )
+ {
+ shb_ener_fx = L_mac_sat( shb_ener_fx, shb_old_speech_fx[i], shb_old_speech_fx[i] ); // ( Q0 + Q0 + Q1 ) --> Q1 due to left shift in L_mac
+ }
+
+ shb_ener_fx = L_add( Mpy_32_16_1( shb_ener_fx, 102 ), 1 ); /* ( 1 / L_FRAME16K ) -> 102 in Q15, shb_ener_fx in Q1 */
+
+ wb_ener_fx = L_deposit_l( 0 );
+ FOR( i = 0; i < st->L_frame; i++ )
+ {
+ wb_ener_fx = L_mac_o( wb_ener_fx, syn_12k8_16k_fx[i], syn_12k8_16k_fx[i], &Overflow ); // ( Q0 + Q0 + Q1 ) --> Q1 due to left shift in L_mac
+ }
+
+ wb_ener_fx = L_add( Mpy_32_16_1( wb_ener_fx, 128 ), 1 ); /* 128 in Q15, wb_ener_fx in Q1 */
+
+ exp = norm_l( wb_ener_fx );
+ fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) );
+ exp = sub( 30 - 1, exp );
+ wb_ener_fx = Mpy_32_16( exp, fra, LG10 );
+
+ log_wb_ener_fx = round_fx_o( L_shl_o( wb_ener_fx, 10, &Overflow ), &Overflow ); /* log_wb_ener_fx in Q8 */
+ exp = norm_l( shb_ener_fx );
+ fra = Log2_norm_lc( L_shl( shb_ener_fx, exp ) );
+ exp = sub( 30 - 1, exp );
+ shb_ener_fx = Mpy_32_16( exp, fra, LG10 );
+
+
+ test();
+ IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) )
+ {
+ Word32 att_fx32 = 0;
+ move32();
+ Word16 index;
+
+ apply_scale_ivas_fx( &att_fx32, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO, &index ); // Q23;
+
+ att_fx = extract_l( L_shr( att_fx32, 15 ) ); // Q8
+ }
+ ELSE
+ {
+ att_fx = -1664; // Q8
+ move16();
+ }
+
+
+ log_shb_ener_fx = sub_o( round_fx_o( L_shl_o( shb_ener_fx, 10, &Overflow ), &Overflow ), att_fx, &Overflow ); /* log_shb_ener_fx in Q8 */
+
+ IF( st->hDtxEnc->first_CNG == 0 )
+ {
+
+
+ hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; // Q8
+ hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; // Q8
+ hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; // Q8
+ hTdCngEnc->last_shb_cng_ener_fx = log_shb_ener_fx; // Q8
+ move16();
+ move16();
+ move16();
+ move16();
+ }
+ IF( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12 in Q8*/ ) )
+ {
+ allow_cn_step = 1;
+ move16();
+ }
+
+ /* Also allow step if shb energy has dropped 12 dB */
+ test();
+ test();
+ IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GT_16( sub( hTdCngEnc->mov_shb_cng_ener_fx, log_shb_ener_fx ), 3072 /*12 in Q8*/ ) )
+ {
+ allow_cn_step = 1;
+ move16();
+ }
+
+ IF( EQ_16( allow_cn_step, 1 ) )
+ {
+ hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx;
+ hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx;
+ move16();
+ move16();
+ }
+ ELSE
+ {
+ tmp = sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ); /* Q8 */
+ tmp = mult( tmp, 29491 /* .9f in Q15*/ ); /* Q8 */
+ hTdCngEnc->mov_wb_cng_ener_fx = add( hTdCngEnc->mov_wb_cng_ener_fx, tmp ); /* Q8 */
+ move16();
+
+ tmp = sub( log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx );
+ tmp = mult( tmp, 8192 /* .25f in Q15*/ ); /* Q8 */
+ hTdCngEnc->mov_shb_cng_ener_fx = add( hTdCngEnc->mov_shb_cng_ener_fx, tmp ); /* Q8 */
+ move16();
+ }
+
+ hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 );
+ update = 0;
+
+ move16();
+ move16();
+
+ IF( EQ_32( st->core_brate, SID_2k40 ) )
+ {
+ test();
+ test();
+ test();
+ IF( st->hDtxEnc->first_CNG == 0 )
+ {
+ update = 1;
+ move16();
+ }
+ ELSE IF( hTdCngEnc->shb_cng_ini_cnt > 0 )
+ {
+ hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 );
+ update = 1;
+ move16();
+ move16();
+ }
+ ELSE IF( EQ_16( hTdCngEnc->last_vad, 1 ) )
+ {
+ update = 1;
+ move16();
+ }
+ ELSE IF( GE_16( hTdCngEnc->shb_NO_DATA_cnt, 100 ) )
+ {
+ update = 1;
+ move16();
+ }
+ ELSE IF( GT_16( abs_s( sub( sub( hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ), sub( hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx ) ) ), 768 ) )
+ {
+ update = 1;
+ move16();
+ }
+ ELSE IF( ( GE_16( st->bwidth, SWB ) && LT_16( hTdCngEnc->last_SID_bwidth, SWB ) ) || ( LT_16( st->bwidth, SWB ) && GE_16( hTdCngEnc->last_SID_bwidth, SWB ) ) )
+ {
+ update = 1;
+ move16();
+ }
+
+ hTdCngEnc->last_SID_bwidth = st->bwidth;
+ move16();
+ }
+
+ /* LF-boost not yet implemented in decoder which means that the specific wb_sid information is not used */
+ test();
+ test();
+ if ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_32( st->core_brate, SID_2k40 ) )
+ {
+ update = 1;
+ move16();
+ }
+
+ IF( EQ_16( update, 1 ) )
+ {
+ hTdCngEnc->last_wb_cng_ener_fx = hTdCngEnc->mov_wb_cng_ener_fx;
+ hTdCngEnc->last_shb_cng_ener_fx = hTdCngEnc->mov_shb_cng_ener_fx;
+ hTdCngEnc->shb_NO_DATA_cnt = 0;
+ move16();
+ move16();
+ move16();
+ }
+
+ return ( update );
+}
diff --git a/lib_enc/cod2t32.c b/lib_enc/cod2t32.c
deleted file mode 100644
index 167c70dbfb92ffa66483e8fa575c5d73c71c6b0a..0000000000000000000000000000000000000000
--- a/lib_enc/cod2t32.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "cnst.h"
-#include "prot.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c
index c9bbe5f30954307fb392712240508edeca860d56..a948a4656c7154b56e7af98b6e3fae967d5e5ec2 100644
--- a/lib_enc/cod2t32_fx.c
+++ b/lib_enc/cod2t32_fx.c
@@ -5,7 +5,6 @@
#include "options.h" /* Compilation switches */
#include "cnst.h" /* Common constants */
#include "rom_com.h" /* Common constants */
-#include "prot.h" /* Function prototypes */
#include "prot_fx.h" /* Function prototypes */
#include "prot_fx_enc.h" /* Function prototypes */
diff --git a/lib_enc/cod4t64.c b/lib_enc/cod4t64.c
deleted file mode 100644
index 9be976783240248ee1507bfbb571520cf1680bbf..0000000000000000000000000000000000000000
--- a/lib_enc/cod4t64.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "rom_enc.h"
-#include "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
-
-/*---------------------------------------------------------------------*
- * Local function prototypes
- *---------------------------------------------------------------------*/
diff --git a/lib_enc/cod4t64_fast.c b/lib_enc/cod4t64_fast.c
index 16651b8f29df60631c2da1e9ff9f3b3e2e633526..a901690e3f11774aa8edc3af6c180b86cb945877 100644
--- a/lib_enc/cod4t64_fast.c
+++ b/lib_enc/cod4t64_fast.c
@@ -34,7 +34,6 @@
#include "options.h"
#include
#include "cnst.h"
-#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
diff --git a/lib_enc/cod4t64_fx.c b/lib_enc/cod4t64_fx.c
index 44cde6f27d8488be31521c55cd81eb875d3a196d..99b794b42325932654eef0f13ab6f90b733671d2 100644
--- a/lib_enc/cod4t64_fx.c
+++ b/lib_enc/cod4t64_fx.c
@@ -5,10 +5,9 @@
#include "options.h" /* VMR-WB compilation switches */
#include "cnst.h" /* Common constants */
#include "rom_enc.h" /* Encoder static table prototypes */
-#include "prot.h" /* Function prototypes */
+#include "prot_fx.h" /* Function prototypes */
#include "rom_com_fx.h" /* Static table prototypes */
#include "rom_com.h" /* Static table prototypes */
-#include "prot_fx.h" /* Function prototypes */
#include "prot_fx_enc.h" /* Function prototypes */
diff --git a/lib_enc/cod_ace.c b/lib_enc/cod_ace.c
deleted file mode 100644
index 46d7a42d1a3fb4c72e12459513eb9fc9d3207c5d..0000000000000000000000000000000000000000
--- a/lib_enc/cod_ace.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "prot.h"
-#include
-#include "options.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c
deleted file mode 100644
index 88e028c86fa04d0555b66be0234c707a7c643107..0000000000000000000000000000000000000000
--- a/lib_enc/cod_tcx.c
+++ /dev/null
@@ -1,869 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include
-#include "options.h"
-#include
-#include "cnst.h"
-#include "prot.h"
-#include "wmc_auto.h"
-#include "ivas_prot.h"
-#include "ivas_rom_com.h"
-#include "ivas_rom_com_fx.h"
-#include "prot_fx_enc.h"
-#include "prot_fx.h"
-#include "ivas_prot_fx.h"
-
-
-/*-------------------------------------------------------------------*
- * TNSAnalysisStereo()
- *
- *
- *-------------------------------------------------------------------*/
-
-#define SIMILAR_TNS_THRESHOLD_FX_IN_Q15 ( 1311 )
-#define TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q7 ( 384 )
-#define TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q23 ( 25165824 )
-void TNSAnalysisStereo_fx(
- Encoder_State **sts, /* i : encoder state handle */
- Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum Qx*/
- const Word16 bWhitenedDomain, /* i : whitened domain flag Q0*/
- Word16 tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm Q0*/
- Word16 tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame Q0*/
- Word16 param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters Q0*/
- const Word16 mct_on /* i : flag mct block (1) or stereo (0) Q0*/
-)
-{
- Word16 ch, k, L_spec, L_frame, nSubframes, iFilter;
- Word32 *spectrum_fx;
- Encoder_State *st = NULL;
- TCX_ENC_HANDLE hTcxEnc = NULL;
- Word16 individual_decision[NB_DIV];
- Word32 maxPredictionGain_fx = 0, meanPredictionGain_fx;
- move32();
- Word16 maxPredictionGain_e = Q31, meanPredictionGain_e;
- move16();
- Word16 sum_e = 0;
- move16();
- individual_decision[0] = 0;
- move16();
- individual_decision[1] = 0;
- move16();
- L_spec = -1;
- move16();
- L_frame = -1;
- move16();
-
- /* TNS filter analysis, loop over channels */
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- st = sts[ch];
- IF( EQ_16( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
- {
- continue;
- }
-
- hTcxEnc = st->hTcxEnc;
-
- IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) )
- {
- nSubframes = 1;
- }
- ELSE
- {
- nSubframes = NB_DIV;
- }
- move16();
-
- FOR( k = 0; k < nSubframes; k++ )
- {
- /* reset tns on whitened domain flag */
- IF( !bWhitenedDomain )
- {
- hTcxEnc->bTnsOnWhithenedSpectra[k] = 0;
- move16();
- hTcxEnc->fUseTns[k] = 0;
- move16();
- }
- test();
- test();
- IF( st->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
- {
- spectrum_fx = hTcxEnc->spectrum_fx[k];
-
- L_frame = hTcxEnc->L_frameTCX;
- move16();
- st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( st->last_core == ACELP_CORE )];
- L_spec = st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0];
- move16();
- /*-----------------------------------------------------------*
- * Temporal Noise Shaping analysis *
- *-----------------------------------------------------------*/
-
- IF( EQ_16( hTcxEnc->transform_type[k], TCX_5 ) )
- {
- /* rearrange LF sub-window lines prior to TNS analysis & filtering */
- tcx5TnsGrouping_fx( shr( L_frame, 2 ), shr( L_spec, 1 ), spectrum_fx );
- }
-
- /* WMOPS: All initializations are either for safety or static (tables) and thus not to be counted */
-
- ResetTnsData( &hTcxEnc->tnsData[k] );
- IF( st->hTcxCfg->pCurrentTnsConfig->maxOrder <= 0 )
- {
- BREAK;
- }
-
- CalculateTnsFilt_fx( st->hTcxCfg->pCurrentTnsConfig, spectrum_fx, hTcxEnc->spectrum_e[k], &hTcxEnc->tnsData[k] );
- }
- }
- }
-
- IF( !mct_on )
- {
- /* TNS decision */
- /* if framing differs between channels, keep the filter decision per channel */
- test();
- test();
- IF( ( NE_16( sts[0]->hTcxEnc->transform_type[0], sts[1]->hTcxEnc->transform_type[0] ) &&
- NE_16( sts[0]->hTcxEnc->transform_type[1], sts[1]->hTcxEnc->transform_type[1] ) ) ||
- NE_16( sts[0]->hTcxCfg->fIsTNSAllowed, sts[1]->hTcxCfg->fIsTNSAllowed ) )
- {
- individual_decision[0] = individual_decision[1] = 1;
- move16();
- move16();
- }
- ELSE IF( bWhitenedDomain )
- {
- IF( EQ_16( sts[0]->hTcxEnc->tcxMode, TCX_20 ) )
- {
- nSubframes = 1;
- }
- ELSE
- {
- nSubframes = NB_DIV;
- }
- move16();
- FOR( k = 0; k < nSubframes; k++ )
- {
- IF( NE_16( sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k], sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
- {
- individual_decision[k] = 1;
- move16();
- }
- }
- }
-
- /* framing equal, check for similar filters, if very similar (also indicator for and M signal),
- * use at least the same decision, maybe use the same filter
- */
- {
- Word8 isTCX10;
-
- IF( EQ_16( sts[0]->hTcxEnc->tcxMode, TCX_20 ) )
- {
- nSubframes = 1;
- isTCX10 = 0;
- }
- ELSE
- {
- nSubframes = NB_DIV;
- isTCX10 = 1;
- }
- move16();
- move16();
- FOR( k = 0; k < nSubframes; k++ )
- {
- test();
- test();
- test();
- IF( sts[0]->hTcxCfg->fIsTNSAllowed && NE_16( individual_decision[k], 1 ) && ( !bWhitenedDomain || sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
- {
- Word32 maxPredGain_fx = -ONE_IN_Q31;
- move32();
- Word16 maxPredGain_e = 0;
- move16();
- sts[0]->hTcxCfg->pCurrentTnsConfig = &sts[0]->hTcxCfg->tnsConfig[sts[0]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[0]->last_core == ACELP_CORE )];
- sts[1]->hTcxCfg->pCurrentTnsConfig = &sts[1]->hTcxCfg->tnsConfig[sts[1]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[1]->last_core == ACELP_CORE )];
-
- FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
- {
- STnsFilter *pFilter[2];
- struct TnsParameters const *pTnsParameters[2];
- pFilter[0] = sts[0]->hTcxEnc->tnsData[k].filter + iFilter;
- pTnsParameters[0] = sts[0]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter;
- pFilter[1] = sts[1]->hTcxEnc->tnsData[k].filter + iFilter;
- pTnsParameters[1] = sts[1]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter;
-
- /* if prediction gain and avgSqrCoef are both close we are pretty sure the filters are quite similar, use the avg of
- * both filters for the decision
- */
-
- meanPredictionGain_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( pFilter[0]->predictionGain32, 16384 /*0.5f Q15*/ ), pFilter[0]->predictionGain_e, Mpy_32_16_1( pFilter[1]->predictionGain32, 16384 /*0.5f Q15*/ ), pFilter[1]->predictionGain_e, &meanPredictionGain_e ); // meanPredictionGain_e
- Word16 flag = BASOP_Util_Cmp_Mant32Exp( maxPredictionGain_fx, maxPredictionGain_e, meanPredictionGain_fx, meanPredictionGain_e );
- IF( flag < 0 )
- {
- maxPredictionGain_fx = meanPredictionGain_fx;
- maxPredictionGain_e = meanPredictionGain_e;
- move32();
- move16();
- }
- flag = BASOP_Util_Cmp_Mant32Exp( pFilter[0]->predictionGain32, pFilter[0]->predictionGain_e, L_deposit_h( pTnsParameters[0]->minPredictionGain ), PRED_GAIN_E );
- if ( flag < 0 )
- {
- flag = 0;
- move16();
- }
- Word16 flag_1 = BASOP_Util_Cmp_Mant32Exp( pFilter[1]->predictionGain32, pFilter[1]->predictionGain_e, L_deposit_h( pTnsParameters[1]->minPredictionGain ), PRED_GAIN_E );
- if ( flag_1 < 0 )
- {
- flag_1 = 0;
- move16();
- }
- test();
- test();
- test();
- IF( flag && LT_32( sts[0]->element_brate, IVAS_80k ) &&
- flag_1 && EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) )
- {
- pFilter[0]->predictionGain32 = pFilter[1]->predictionGain32 = meanPredictionGain_fx; /* more TNS filter sync at 48kbps */
- move32();
- move32();
- pFilter[0]->predictionGain_e = pFilter[1]->predictionGain_e = meanPredictionGain_e; /* more TNS filter sync at 48kbps */
- move16();
- move16();
- pFilter[0]->predictionGain = pFilter[1]->predictionGain = shl_sat( extract_h( meanPredictionGain_fx ), sub( meanPredictionGain_e, PRED_GAIN_E ) ); /* Q7 */
- move16();
- move16();
- }
- flag = BASOP_Util_Cmp_Mant32Exp( Mpy_32_16_1( meanPredictionGain_fx, SIMILAR_TNS_THRESHOLD_FX_IN_Q15 ), meanPredictionGain_e, L_abs( BASOP_Util_Add_Mant32Exp( pFilter[0]->predictionGain32, pFilter[0]->predictionGain_e, L_negate( pFilter[1]->predictionGain32 ), pFilter[1]->predictionGain_e, &sum_e ) ), sum_e );
- if ( flag < 0 )
- {
- flag = 0;
- move16();
- }
- test();
- IF( flag &&
- ( EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) ) )
- {
-
- Word16 maxAvgSqrCoef_fx = s_max( pFilter[0]->avgSqrCoef, pFilter[1]->avgSqrCoef ); // Q15
- Word16 meanLtpGain_fx = add( shr( sts[0]->hTcxEnc->tcxltp_gain, 1 ), shr( sts[1]->hTcxEnc->tcxltp_gain, 1 ) );
- // maxPredGain_fx = L_max( maxPredGain_fx, meanPredictionGain_fx );
- flag = BASOP_Util_Cmp_Mant32Exp( maxPredGain_fx, maxPredGain_e, meanPredictionGain_fx, meanPredictionGain_e );
- IF( flag < 0 )
- {
- maxPredGain_fx = meanPredictionGain_fx;
- maxPredGain_e = meanPredictionGain_e;
- move32();
- move16();
- }
- flag = BASOP_Util_Cmp_Mant32Exp( meanPredictionGain_fx, meanPredictionGain_e, L_deposit_h( pTnsParameters[0]->minPredictionGain ), PRED_GAIN_E );
- if ( flag < 0 )
- {
- flag = 0;
- move16();
- }
- test();
- test();
- IF( flag || GT_16( maxAvgSqrCoef_fx, pTnsParameters[0]->minAvgSqrCoef ) )
- {
- test();
- test();
- test();
- IF( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( meanLtpGain_fx, 19660 /* 0.6 in Q15*/ ) )
- {
-
- sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here,
- this may result in crash later. Changing the filter type here so the order is taken here in further section */
- IF( pFilter[0]->order != 0 )
- {
- pFilter[0]->filterType = TNS_FILTER_ON;
- move16();
- }
- ELSE
- {
- pFilter[0]->filterType = TNS_FILTER_ON_ZERO;
- move16();
- }
- sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- IF( pFilter[1]->order != 0 )
- {
- pFilter[1]->filterType = TNS_FILTER_ON;
- move16();
- }
- ELSE
- {
- pFilter[1]->filterType = TNS_FILTER_ON_ZERO;
- move16();
- }
- }
- ELSE
- {
- Word16 maxEnergyChange_fx;
- maxEnergyChange_fx = mac_r( L_mult( GetTCXMaxenergyChange_ivas_fx( sts[0]->hTranDet, isTCX10, NSUBBLOCKS, 3 ), 16384 ), GetTCXMaxenergyChange_ivas_fx( sts[1]->hTranDet, isTCX10, NSUBBLOCKS, 3 ), 16384 );
-
- IF( GE_16( maxEnergyChange_fx, shl( pTnsParameters[0]->minEnergyChange, Q3 - Q7 ) ) )
- {
- sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here,
- this may result in crash later. Changing the filter type here so the order is taken here in further section */
- IF( pFilter[0]->order != 0 )
- {
- pFilter[0]->filterType = TNS_FILTER_ON;
- move16();
- }
- ELSE
- {
- pFilter[0]->filterType = TNS_FILTER_ON_ZERO;
- move16();
- }
- sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- IF( pFilter[1]->order != 0 )
- {
- pFilter[1]->filterType = TNS_FILTER_ON;
- move16();
- }
- ELSE
- {
- pFilter[1]->filterType = TNS_FILTER_ON_ZERO;
- move16();
- }
- }
- ELSE
- {
- pFilter[0]->filterType = TNS_FILTER_OFF;
- move16();
- pFilter[1]->filterType = TNS_FILTER_OFF;
- move16();
- }
- }
- }
- ELSE IF( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 && sts[1]->hTcxEnc->tnsData[k].nFilters > 0 ) /* If a previous filter is turned on */
- {
- pFilter[0]->filterType = TNS_FILTER_ON_ZERO;
- pFilter[1]->filterType = TNS_FILTER_ON_ZERO;
- move16();
- move16();
- sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- }
- ELSE IF( NE_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) ) /* sanity check */
- {
- assert( 0 );
- }
- ELSE
- {
- pFilter[0]->filterType = TNS_FILTER_OFF;
- move16();
- pFilter[1]->filterType = TNS_FILTER_OFF;
- move16();
- }
-
- test();
- test();
- IF( EQ_16( pFilter[0]->filterType, TNS_FILTER_ON ) && EQ_16( pFilter[1]->filterType, TNS_FILTER_ON ) && LT_32( sts[0]->element_brate, IVAS_80k ) )
- {
- Word16 tmpIntValue = 0;
- move16();
- Word16 tmpCoeff[TNS_MAX_FILTER_ORDER];
- Word16 i, maxOrder = s_max( pFilter[0]->order, pFilter[1]->order );
-
- set16_fx( tmpCoeff, 0, TNS_MAX_FILTER_ORDER );
- FOR( i = 0; i < maxOrder; i++ )
- {
- tmpIntValue = s_max( tmpIntValue, abs_s( sub( pFilter[0]->coefIndex[i], pFilter[1]->coefIndex[i] ) ) );
- }
-
- IF( EQ_16( tmpIntValue, 1 ) ) /* the TNS coefficients are sufficiently similar to equalize the two filters */
- {
- FOR( i = maxOrder - 1; i >= 0; i-- )
- {
- IF( LT_16( abs_s( pFilter[0]->coefIndex[i] ), abs_s( pFilter[1]->coefIndex[i] ) ) )
- {
- tmpCoeff[i] = pFilter[0]->coefIndex[i];
- }
- ELSE
- {
- tmpCoeff[i] = pFilter[1]->coefIndex[i];
- }
- move16();
- IF( ( tmpIntValue > 0 ) && ( tmpCoeff[i] == 0 ) )
- {
- maxOrder = sub( maxOrder, 1 );
- }
- ELSE
- {
- tmpIntValue = 0;
- move16();
- }
- }
- /* make sure that maxOrder is non zero and not all coefficients are zero (could happen in rare cases) */
- IF( maxOrder > 0 )
- {
- FOR( i = TNS_MAX_FILTER_ORDER - 1; i >= 0; i-- )
- {
- pFilter[0]->coefIndex[i] = pFilter[1]->coefIndex[i] = tmpCoeff[i];
- move16();
- move16();
- }
-
- pFilter[0]->order = pFilter[1]->order = maxOrder;
- move16();
- move16();
- }
- }
- }
- }
- ELSE
- {
- individual_decision[k] = 1;
- move16();
- }
- }
-
- IF( individual_decision[k] == 0 )
- {
- IF( ( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 ) )
- {
- sts[0]->hTcxEnc->fUseTns[k] = 1;
- }
- ELSE
- {
- sts[0]->hTcxEnc->fUseTns[k] = 0;
- }
- move16();
-
- IF( ( sts[1]->hTcxEnc->tnsData[k].nFilters > 0 ) )
- {
- sts[1]->hTcxEnc->fUseTns[k] = 1;
- }
- ELSE
- {
- sts[1]->hTcxEnc->fUseTns[k] = 0;
- }
- move16();
- }
- ELSE
- {
- sts[0]->hTcxEnc->tnsData[k].nFilters = 0;
- move16();
- sts[1]->hTcxEnc->tnsData[k].nFilters = 0;
- move16();
- sts[0]->hTcxEnc->fUseTns[k] = 0;
- move16();
- sts[1]->hTcxEnc->fUseTns[k] = 0;
- move16();
- FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
- {
- sts[0]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF;
- move16();
- sts[1]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF;
- move16();
- }
- }
- Word16 flag = BASOP_Util_Cmp_Mant32Exp( TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q23, PRED_GAIN_E, maxPredGain_fx, maxPredGain_e );
- if ( flag < 0 )
- {
- flag = 0;
- move16();
- }
- test();
- test();
- test();
- IF( !bWhitenedDomain && individual_decision[k] == 0 && flag && NE_16( sts[0]->hTcxEnc->transform_type[k], TCX_5 ) )
- {
- sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1;
- move16();
- sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1;
- move16();
- sts[0]->hTcxEnc->tnsData[k].nFilters = 0;
- move16();
- sts[1]->hTcxEnc->tnsData[k].nFilters = 0;
- move16();
- sts[0]->hTcxEnc->fUseTns[k] = 0;
- move16();
- sts[1]->hTcxEnc->fUseTns[k] = 0;
- move16();
- FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
- {
- ClearTnsFilterCoefficients( sts[0]->hTcxEnc->tnsData[k].filter + iFilter );
- ClearTnsFilterCoefficients( sts[1]->hTcxEnc->tnsData[k].filter + iFilter );
- }
- }
- // maxPredictionGain_fx = L_max( maxPredictionGain_fx, maxPredGain_fx );
- flag = BASOP_Util_Cmp_Mant32Exp( maxPredictionGain_fx, maxPredictionGain_e, maxPredGain_fx, maxPredGain_e );
- IF( flag < 0 )
- {
- maxPredictionGain_fx = maxPredGain_fx;
- maxPredictionGain_e = maxPredGain_e;
- move32();
- move16();
- }
- }
- }
- }
- }
-
- /* individual decision for each channel */
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- IF( EQ_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
- {
- CONTINUE;
- }
-
- Word8 isTCX10;
-
- IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) )
- {
- nSubframes = 1;
- isTCX10 = 0;
- }
- ELSE
- {
- nSubframes = NB_DIV;
- isTCX10 = 1;
- }
- move16();
- move16();
-
- FOR( k = 0; k < nSubframes; k++ )
- {
- test();
- test();
- test();
- test();
- IF( sts[ch]->hTcxCfg->fIsTNSAllowed && ( individual_decision[k] || mct_on ) &&
- ( !bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
- {
- Word32 maxPredGain_fx = -ONE_IN_Q31; // Q31
- move32();
- Word16 maxPredGain_e = 0;
- move16();
- sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[ch]->last_core == ACELP_CORE )];
-
- FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
- {
- STnsFilter *pFilter;
- struct TnsParameters const *pTnsParameters;
- pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter;
- pTnsParameters = sts[ch]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter;
-
- // maxPredGain_fx = L_max( maxPredGain_fx, pFilter->predictionGain32 );
- Word16 flag = BASOP_Util_Cmp_Mant32Exp( maxPredGain_fx, maxPredGain_e, pFilter->predictionGain32, pFilter->predictionGain_e );
- IF( flag < 0 )
- {
- maxPredGain_fx = pFilter->predictionGain32;
- move32();
- maxPredGain_e = pFilter->predictionGain_e;
- move16();
- }
- flag = BASOP_Util_Cmp_Mant32Exp( pFilter->predictionGain32, pFilter->predictionGain_e, L_deposit_h( pTnsParameters->minPredictionGain ), PRED_GAIN_E );
- if ( flag < 0 )
- {
- flag = 0;
- move16();
- }
- test();
- IF( flag || GT_16( pFilter->avgSqrCoef, pTnsParameters->minAvgSqrCoef ) )
- {
- test();
- test();
- IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( sts[ch]->hTcxEnc->tcxltp_gain, 19660 /*.6f in Q15*/ ) )
- {
- sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here,
- this may result in crash later. Changing the filter type here so the order is taken here in further section */
- IF( pFilter->order != 0 )
- {
- pFilter->filterType = TNS_FILTER_ON;
- move16();
- }
- ELSE
- {
- pFilter->filterType = TNS_FILTER_ON_ZERO;
- move16();
- }
- }
- ELSE
- {
- Word16 maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( sts[ch]->hTranDet, isTCX10, NSUBBLOCKS, 3 );
-
- IF( GE_16( maxEnergyChange_fx, shl( pTnsParameters->minEnergyChange, Q3 - Q7 ) ) )
- {
- sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here,
- this may result in crash later. Changing the filter type here so the order is taken here in further section */
- IF( pFilter->order != 0 )
- {
- pFilter->filterType = TNS_FILTER_ON;
- move16();
- }
- ELSE
- {
- pFilter->filterType = TNS_FILTER_ON_ZERO;
- move16();
- }
- }
- ELSE
- {
- pFilter->filterType = TNS_FILTER_OFF;
- move16();
- }
- }
- }
- ELSE IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 ) /* If a previous filter is turned on */
- {
- pFilter->filterType = TNS_FILTER_ON_ZERO;
- move16();
- sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 );
- move16();
- }
- ELSE
- {
- pFilter->filterType = TNS_FILTER_OFF;
- move16();
- }
- }
-
- IF( ( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 ) )
- {
- sts[ch]->hTcxEnc->fUseTns[k] = 1;
- }
- ELSE
- {
- sts[ch]->hTcxEnc->fUseTns[k] = 0;
- }
- move16();
- Word16 flag = BASOP_Util_Cmp_Mant32Exp( TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q23, PRED_GAIN_E, maxPredGain_fx, maxPredGain_e );
- if ( flag < 0 )
- {
- flag = 0;
- move16();
- }
- test();
- test();
- IF( !bWhitenedDomain && flag && NE_16( sts[ch]->hTcxEnc->transform_type[k], TCX_5 ) )
- {
- sts[ch]->hTcxEnc->fUseTns[k] = 0;
- move16();
- sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1;
- move16();
- sts[ch]->hTcxEnc->tnsData[k].nFilters = 0;
- move16();
- FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
- {
- ClearTnsFilterCoefficients( sts[ch]->hTcxEnc->tnsData[k].filter + iFilter );
- sts[ch]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF;
- move16();
- }
- }
- // maxPredictionGain_fx = L_max( maxPredictionGain_fx, maxPredGain_fx );
- flag = BASOP_Util_Cmp_Mant32Exp( maxPredictionGain_fx, maxPredictionGain_e, maxPredGain_fx, maxPredGain_e );
- IF( flag < 0 )
- {
- maxPredictionGain_fx = maxPredGain_fx;
- maxPredictionGain_e = maxPredGain_e;
- move32();
- move16();
- }
- }
- }
- }
-
-
- /* we have the decision, set filter data accordingly */
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- IF( EQ_16( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
- {
- CONTINUE;
- }
-
- IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) )
- {
- nSubframes = 1;
- }
- ELSE
- {
- nSubframes = NB_DIV;
- }
- move16();
- FOR( k = 0; k < nSubframes; k++ )
- {
- test();
- test();
- IF( sts[ch]->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
- {
- sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[ch]->last_core == ACELP_CORE )];
-
- FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
- {
- STnsFilter *pFilter;
- pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter;
- SWITCH( pFilter->filterType )
- {
- case TNS_FILTER_OFF:
- ClearTnsFilterCoefficients( sts[ch]->hTcxEnc->tnsData[k].filter + iFilter );
- BREAK;
- case TNS_FILTER_ON_ZERO:
- /* Since TNS filter of order 0 is not allowed we have to signal in the stream filter of order 1 with the 0th coefficient equal to 0 */
- ClearTnsFilterCoefficients( pFilter );
- pFilter->order = 1;
- move16();
- BREAK;
- }
- }
- }
- }
- }
-
- /* Apply filters, loop over channels */
- FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
- {
- st = sts[ch];
- IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
- {
- CONTINUE;
- }
-
- IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) )
- {
- nSubframes = 1;
- }
- ELSE
- {
- nSubframes = NB_DIV;
- }
- move16();
-
- FOR( k = 0; k < nSubframes; k++ )
- {
- test();
- test();
- test();
- test();
- test();
- IF( bWhitenedDomain && ( ch > 0 ) && /* test for identical TNS filter data in both channels */
- sts[0]->hTcxCfg->fIsTNSAllowed && sts[0]->hTcxEnc->fUseTns[k] &&
- sts[1]->hTcxCfg->fIsTNSAllowed && sts[1]->hTcxEnc->fUseTns[k] )
- {
- Word16 equalFilterData = 0;
- move16();
- test();
- test();
- if ( EQ_16( sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters, sts[1]->hTcxCfg->pCurrentTnsConfig->nMaxFilters ) &&
- EQ_16( sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k], sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) &&
- EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) )
- {
- equalFilterData = 1;
- move16();
- }
-
- IF( equalFilterData )
- {
- FOR( iFilter = st->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
- {
- const Word16 *pDataCh0 = (const Word16 *) &sts[0]->hTcxEnc->tnsData[k].filter[iFilter];
- const Word16 *pDataCh1 = (const Word16 *) &sts[1]->hTcxEnc->tnsData[k].filter[iFilter];
- Word16 i = 2 + TNS_MAX_FILTER_ORDER; /* excl. informative float data. Portable? */
-
- move16();
- test();
- WHILE( ( i >= 0 ) && EQ_16( pDataCh0[i], pDataCh1[i] ) )
- {
- test();
- i = sub( i, 1 );
- }
- IF( i >= 0 )
- {
- equalFilterData = 0;
- move16();
- BREAK;
- }
- }
- IF( equalFilterData )
- {
- st->hTcxEnc->tnsData[k].nFilters = i_mult( st->hTcxEnc->tnsData[k].nFilters, -1 ); /* signals common TNS */
- move16();
- }
- }
- }
- test();
- test();
- IF( st->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || st->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
- {
- L_spec = st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0];
- move16();
- spectrum_fx = st->hTcxEnc->spectrum_fx[k];
- /* If TNS should be used then get the residual after applying it inplace in the spectrum */
- IF( st->hTcxEnc->fUseTns[k] )
- {
- st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[st->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( st->last_core == ACELP_CORE )];
-
- ApplyTnsFilter( st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], spectrum_fx, 1 );
- }
-
- IF( EQ_16( st->hTcxEnc->transform_type[k], TCX_5 ) )
- {
- tcx5TnsUngrouping_fx( shr( L_frame, 2 ), shr( L_spec, 1 ), st->hTcxEnc->spectrum_fx[k], ENC );
- }
-
- st->hTcxEnc->tnsData[k].tnsOnWhitenedSpectra = st->hTcxEnc->bTnsOnWhithenedSpectra[k];
- move16();
- EncodeTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], param_core[ch] + k * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, tnsSize[ch] + k, tnsBits[ch] + k );
- }
-
- IF( EQ_16( st->hTcxEnc->transform_type[k], TCX_5 ) )
- {
- tcx5SpectrumInterleaving_fx( st->hTcxCfg->tcx5SizeFB, st->hTcxEnc->spectrum_fx[k] );
- tcx5SpectrumInterleaving_fx( st->hTcxCfg->tcx5SizeFB, mdst_spectrum_fx[ch][k] );
- }
- }
- }
- return;
-}
diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c
index b2fe04ce13f5fcb65f8a7abd6a47bba15f06a1c1..c54e8ccf4c9f27b0623e805befcd7af8ce72e4b6 100644
--- a/lib_enc/cod_tcx_fx.c
+++ b/lib_enc/cod_tcx_fx.c
@@ -16,16 +16,17 @@
#include "prot_fx_enc.h"
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
#include
-#include "prot.h"
#include "ivas_prot.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com_fx.h"
-#include "prot.h"
#endif
#ifdef DEBUGGING
#include "debug.h"
#endif
+#define SIMILAR_TNS_THRESHOLD_FX_IN_Q15 ( 1311 )
+#define TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q7 ( 384 )
+#define TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q23 ( 25165824 )
/* Up to the Autocorrelation it is the same code as in GetMDCT, with the difference in the parameters in the call to tcx_windowing_analysis */
void HBAutocorrelation_fx(
@@ -5363,3 +5364,778 @@ void InternalTCXDecoder_fx(
return;
}
+
+
+void TNSAnalysisStereo_fx(
+ Encoder_State **sts, /* i : encoder state handle */
+ Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum Qx*/
+ const Word16 bWhitenedDomain, /* i : whitened domain flag Q0*/
+ Word16 tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm Q0*/
+ Word16 tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame Q0*/
+ Word16 param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters Q0*/
+ const Word16 mct_on /* i : flag mct block (1) or stereo (0) Q0*/
+)
+{
+ Word16 ch, k, L_spec, L_frame, nSubframes, iFilter;
+ Word32 *spectrum_fx, sum;
+ Encoder_State *st = NULL;
+ TCX_ENC_HANDLE hTcxEnc = NULL;
+ Word16 individual_decision[NB_DIV];
+ Word32 maxPredictionGain_fx = 0, meanPredictionGain_fx;
+ move32();
+ Word16 maxPredictionGain_e = 0, meanPredictionGain_e;
+ move16();
+ Word16 sum_e = 0;
+ move16();
+ individual_decision[0] = 0;
+ move16();
+ individual_decision[1] = 0;
+ move16();
+ L_spec = -1;
+ move16();
+ L_frame = -1;
+ move16();
+
+ /* TNS filter analysis, loop over channels */
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
+ {
+ st = sts[ch];
+ IF( EQ_16( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
+ {
+ continue;
+ }
+
+ hTcxEnc = st->hTcxEnc;
+
+ IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) )
+ {
+ nSubframes = 1;
+ }
+ ELSE
+ {
+ nSubframes = NB_DIV;
+ }
+ move16();
+
+ FOR( k = 0; k < nSubframes; k++ )
+ {
+ /* reset tns on whitened domain flag */
+ IF( !bWhitenedDomain )
+ {
+ hTcxEnc->bTnsOnWhithenedSpectra[k] = 0;
+ move16();
+ hTcxEnc->fUseTns[k] = 0;
+ move16();
+ }
+ test();
+ test();
+ IF( st->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
+ {
+ spectrum_fx = hTcxEnc->spectrum_fx[k];
+
+ L_frame = hTcxEnc->L_frameTCX;
+ move16();
+ st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( st->last_core == ACELP_CORE )];
+ L_spec = st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0];
+ move16();
+ /*-----------------------------------------------------------*
+ * Temporal Noise Shaping analysis *
+ *-----------------------------------------------------------*/
+
+ IF( EQ_16( hTcxEnc->transform_type[k], TCX_5 ) )
+ {
+ /* rearrange LF sub-window lines prior to TNS analysis & filtering */
+ tcx5TnsGrouping_fx( shr( L_frame, 2 ), shr( L_spec, 1 ), spectrum_fx );
+ }
+
+ /* WMOPS: All initializations are either for safety or static (tables) and thus not to be counted */
+
+ ResetTnsData( &hTcxEnc->tnsData[k] );
+ IF( st->hTcxCfg->pCurrentTnsConfig->maxOrder <= 0 )
+ {
+ BREAK;
+ }
+
+ CalculateTnsFilt_fx( st->hTcxCfg->pCurrentTnsConfig, spectrum_fx, hTcxEnc->spectrum_e[k], &hTcxEnc->tnsData[k] );
+ }
+ }
+ }
+
+ IF( !mct_on )
+ {
+ /* TNS decision */
+ /* if framing differs between channels, keep the filter decision per channel */
+ test();
+ test();
+ IF( ( NE_16( sts[0]->hTcxEnc->transform_type[0], sts[1]->hTcxEnc->transform_type[0] ) &&
+ NE_16( sts[0]->hTcxEnc->transform_type[1], sts[1]->hTcxEnc->transform_type[1] ) ) ||
+ NE_16( sts[0]->hTcxCfg->fIsTNSAllowed, sts[1]->hTcxCfg->fIsTNSAllowed ) )
+ {
+ individual_decision[0] = individual_decision[1] = 1;
+ move16();
+ move16();
+ }
+ ELSE IF( bWhitenedDomain )
+ {
+ IF( EQ_16( sts[0]->hTcxEnc->tcxMode, TCX_20 ) )
+ {
+ nSubframes = 1;
+ }
+ ELSE
+ {
+ nSubframes = NB_DIV;
+ }
+ move16();
+ FOR( k = 0; k < nSubframes; k++ )
+ {
+ IF( NE_16( sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k], sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
+ {
+ individual_decision[k] = 1;
+ move16();
+ }
+ }
+ }
+
+ /* framing equal, check for similar filters, if very similar (also indicator for and M signal),
+ * use at least the same decision, maybe use the same filter
+ */
+ {
+ Word8 isTCX10;
+
+ IF( EQ_16( sts[0]->hTcxEnc->tcxMode, TCX_20 ) )
+ {
+ nSubframes = 1;
+ isTCX10 = 0;
+ }
+ ELSE
+ {
+ nSubframes = NB_DIV;
+ isTCX10 = 1;
+ }
+ move16();
+ move16();
+ FOR( k = 0; k < nSubframes; k++ )
+ {
+ test();
+ test();
+ test();
+ IF( sts[0]->hTcxCfg->fIsTNSAllowed && NE_16( individual_decision[k], 1 ) && ( !bWhitenedDomain || sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
+ {
+ Word32 maxPredGain_fx = -ONE_IN_Q31;
+ move32();
+ Word16 maxPredGain_e = 0;
+ move16();
+ sts[0]->hTcxCfg->pCurrentTnsConfig = &sts[0]->hTcxCfg->tnsConfig[sts[0]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[0]->last_core == ACELP_CORE )];
+ sts[1]->hTcxCfg->pCurrentTnsConfig = &sts[1]->hTcxCfg->tnsConfig[sts[1]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[1]->last_core == ACELP_CORE )];
+
+ FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
+ {
+ STnsFilter *pFilter[2];
+ struct TnsParameters const *pTnsParameters[2];
+ pFilter[0] = sts[0]->hTcxEnc->tnsData[k].filter + iFilter;
+ pTnsParameters[0] = sts[0]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter;
+ pFilter[1] = sts[1]->hTcxEnc->tnsData[k].filter + iFilter;
+ pTnsParameters[1] = sts[1]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter;
+
+ /* if prediction gain and avgSqrCoef are both close we are pretty sure the filters are quite similar, use the avg of
+ * both filters for the decision
+ */
+
+ meanPredictionGain_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( pFilter[0]->predictionGain32, 16384 /*0.5f Q15*/ ), pFilter[0]->predictionGain_e, Mpy_32_16_1( pFilter[1]->predictionGain32, 16384 /*0.5f Q15*/ ), pFilter[1]->predictionGain_e, &meanPredictionGain_e ); // meanPredictionGain_e
+
+ /* maxPredictionGain = max( maxPredictionGain, meanPredictionGain );*/
+ IF( GT_32( meanPredictionGain_fx, L_shl_sat( maxPredictionGain_fx, sub( maxPredictionGain_e, meanPredictionGain_e ) ) ) ) /* exp: meanPredictionGain_e */
+ {
+ maxPredictionGain_fx = meanPredictionGain_fx;
+ maxPredictionGain_e = meanPredictionGain_e;
+ move32();
+ move16();
+ }
+
+ test();
+ test();
+ test();
+ IF( GT_32( pFilter[0]->predictionGain32, L_shl_sat( L_deposit_h( pTnsParameters[0]->minPredictionGain ), sub( PRED_GAIN_E, pFilter[0]->predictionGain_e ) ) ) && LT_32( sts[0]->element_brate, IVAS_80k ) &&
+ GT_32( pFilter[1]->predictionGain32, L_shl_sat( L_deposit_h( pTnsParameters[1]->minPredictionGain ), sub( PRED_GAIN_E, pFilter[1]->predictionGain_e ) ) ) && EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) )
+ {
+ pFilter[0]->predictionGain32 = pFilter[1]->predictionGain32 = meanPredictionGain_fx; /* more TNS filter sync at 48kbps */
+ move32();
+ move32();
+ pFilter[0]->predictionGain_e = pFilter[1]->predictionGain_e = meanPredictionGain_e; /* more TNS filter sync at 48kbps */
+ move16();
+ move16();
+ pFilter[0]->predictionGain = pFilter[1]->predictionGain = shl_sat( extract_h( meanPredictionGain_fx ), sub( meanPredictionGain_e, PRED_GAIN_E ) ); /* Q7 */
+ move16();
+ }
+ sum_e = s_max( pFilter[0]->predictionGain_e, pFilter[1]->predictionGain_e );
+ sum = L_abs( L_sub_sat( L_shl( pFilter[0]->predictionGain32, sub( pFilter[0]->predictionGain_e, sum_e ) ), L_shl( pFilter[1]->predictionGain32, sub( pFilter[1]->predictionGain_e, sum_e ) ) ) ); // sum_e
+
+ IF( LT_32( L_shl_sat( sum, sub( sum_e, meanPredictionGain_e ) ), Mpy_32_16_1( meanPredictionGain_fx, SIMILAR_TNS_THRESHOLD_FX_IN_Q15 ) ) &&
+ ( EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) ) )
+ {
+
+ Word16 maxAvgSqrCoef_fx = s_max( pFilter[0]->avgSqrCoef, pFilter[1]->avgSqrCoef ); // Q15
+ Word16 meanLtpGain_fx = add( shr( sts[0]->hTcxEnc->tcxltp_gain, 1 ), shr( sts[1]->hTcxEnc->tcxltp_gain, 1 ) );
+
+ /* maxPredGain_fx = L_max( maxPredGain_fx, meanPredictionGain_fx ); */
+ IF( GT_32( meanPredictionGain_fx, L_shl_sat( maxPredGain_fx, sub( maxPredGain_e, maxPredictionGain_e ) ) ) ) /* exp: meanPredictionGain_e */
+ {
+ maxPredGain_fx = meanPredictionGain_fx;
+ maxPredGain_e = meanPredictionGain_e;
+ move32();
+ move16();
+ }
+
+ test();
+ test();
+ IF( GT_32( meanPredictionGain_fx, L_shl_sat( L_deposit_h( pTnsParameters[0]->minPredictionGain ), sub( PRED_GAIN_E, meanPredictionGain_e ) ) ) || GT_16( maxAvgSqrCoef_fx, pTnsParameters[0]->minAvgSqrCoef ) )
+ {
+ test();
+ test();
+ test();
+ IF( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( meanLtpGain_fx, 19660 /* 0.6 in Q15*/ ) )
+ {
+
+ sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here,
+ this may result in crash later. Changing the filter type here so the order is taken here in further section */
+ IF( pFilter[0]->order != 0 )
+ {
+ pFilter[0]->filterType = TNS_FILTER_ON;
+ move16();
+ }
+ ELSE
+ {
+ pFilter[0]->filterType = TNS_FILTER_ON_ZERO;
+ move16();
+ }
+ sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ IF( pFilter[1]->order != 0 )
+ {
+ pFilter[1]->filterType = TNS_FILTER_ON;
+ move16();
+ }
+ ELSE
+ {
+ pFilter[1]->filterType = TNS_FILTER_ON_ZERO;
+ move16();
+ }
+ }
+ ELSE
+ {
+ Word16 maxEnergyChange_fx;
+ maxEnergyChange_fx = mac_r( L_mult( GetTCXMaxenergyChange_ivas_fx( sts[0]->hTranDet, isTCX10, NSUBBLOCKS, 3 ), 16384 ), GetTCXMaxenergyChange_ivas_fx( sts[1]->hTranDet, isTCX10, NSUBBLOCKS, 3 ), 16384 );
+
+ IF( GE_16( maxEnergyChange_fx, shl( pTnsParameters[0]->minEnergyChange, Q3 - Q7 ) ) )
+ {
+ sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here,
+ this may result in crash later. Changing the filter type here so the order is taken here in further section */
+ IF( pFilter[0]->order != 0 )
+ {
+ pFilter[0]->filterType = TNS_FILTER_ON;
+ move16();
+ }
+ ELSE
+ {
+ pFilter[0]->filterType = TNS_FILTER_ON_ZERO;
+ move16();
+ }
+ sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ IF( pFilter[1]->order != 0 )
+ {
+ pFilter[1]->filterType = TNS_FILTER_ON;
+ move16();
+ }
+ ELSE
+ {
+ pFilter[1]->filterType = TNS_FILTER_ON_ZERO;
+ move16();
+ }
+ }
+ ELSE
+ {
+ pFilter[0]->filterType = TNS_FILTER_OFF;
+ move16();
+ pFilter[1]->filterType = TNS_FILTER_OFF;
+ move16();
+ }
+ }
+ }
+ ELSE IF( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 && sts[1]->hTcxEnc->tnsData[k].nFilters > 0 ) /* If a previous filter is turned on */
+ {
+ pFilter[0]->filterType = TNS_FILTER_ON_ZERO;
+ pFilter[1]->filterType = TNS_FILTER_ON_ZERO;
+ move16();
+ move16();
+ sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ }
+ ELSE IF( NE_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) ) /* sanity check */
+ {
+ assert( 0 );
+ }
+ ELSE
+ {
+ pFilter[0]->filterType = TNS_FILTER_OFF;
+ move16();
+ pFilter[1]->filterType = TNS_FILTER_OFF;
+ move16();
+ }
+
+ test();
+ test();
+ IF( EQ_16( pFilter[0]->filterType, TNS_FILTER_ON ) && EQ_16( pFilter[1]->filterType, TNS_FILTER_ON ) && LT_32( sts[0]->element_brate, IVAS_80k ) )
+ {
+ Word16 tmpIntValue = 0;
+ move16();
+ Word16 tmpCoeff[TNS_MAX_FILTER_ORDER];
+ Word16 i, maxOrder = s_max( pFilter[0]->order, pFilter[1]->order );
+
+ set16_fx( tmpCoeff, 0, TNS_MAX_FILTER_ORDER );
+ FOR( i = 0; i < maxOrder; i++ )
+ {
+ tmpIntValue = s_max( tmpIntValue, abs_s( sub( pFilter[0]->coefIndex[i], pFilter[1]->coefIndex[i] ) ) );
+ }
+
+ IF( EQ_16( tmpIntValue, 1 ) ) /* the TNS coefficients are sufficiently similar to equalize the two filters */
+ {
+ FOR( i = maxOrder - 1; i >= 0; i-- )
+ {
+ IF( LT_16( abs_s( pFilter[0]->coefIndex[i] ), abs_s( pFilter[1]->coefIndex[i] ) ) )
+ {
+ tmpCoeff[i] = pFilter[0]->coefIndex[i];
+ }
+ ELSE
+ {
+ tmpCoeff[i] = pFilter[1]->coefIndex[i];
+ }
+ move16();
+ IF( ( tmpIntValue > 0 ) && ( tmpCoeff[i] == 0 ) )
+ {
+ maxOrder = sub( maxOrder, 1 );
+ }
+ ELSE
+ {
+ tmpIntValue = 0;
+ move16();
+ }
+ }
+ /* make sure that maxOrder is non zero and not all coefficients are zero (could happen in rare cases) */
+ IF( maxOrder > 0 )
+ {
+ FOR( i = TNS_MAX_FILTER_ORDER - 1; i >= 0; i-- )
+ {
+ pFilter[0]->coefIndex[i] = pFilter[1]->coefIndex[i] = tmpCoeff[i];
+ move16();
+ move16();
+ }
+
+ pFilter[0]->order = pFilter[1]->order = maxOrder;
+ move16();
+ move16();
+ }
+ }
+ }
+ }
+ ELSE
+ {
+ individual_decision[k] = 1;
+ move16();
+ }
+ }
+
+ IF( individual_decision[k] == 0 )
+ {
+ IF( ( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 ) )
+ {
+ sts[0]->hTcxEnc->fUseTns[k] = 1;
+ }
+ ELSE
+ {
+ sts[0]->hTcxEnc->fUseTns[k] = 0;
+ }
+ move16();
+
+ IF( ( sts[1]->hTcxEnc->tnsData[k].nFilters > 0 ) )
+ {
+ sts[1]->hTcxEnc->fUseTns[k] = 1;
+ }
+ ELSE
+ {
+ sts[1]->hTcxEnc->fUseTns[k] = 0;
+ }
+ move16();
+ }
+ ELSE
+ {
+ sts[0]->hTcxEnc->tnsData[k].nFilters = 0;
+ move16();
+ sts[1]->hTcxEnc->tnsData[k].nFilters = 0;
+ move16();
+ sts[0]->hTcxEnc->fUseTns[k] = 0;
+ move16();
+ sts[1]->hTcxEnc->fUseTns[k] = 0;
+ move16();
+ FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
+ {
+ sts[0]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF;
+ move16();
+ sts[1]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF;
+ move16();
+ }
+ }
+
+ test();
+ test();
+ test();
+ IF( !bWhitenedDomain && individual_decision[k] == 0 &&
+ LT_32( L_shl_sat( maxPredGain_fx, sub( maxPredGain_e, PRED_GAIN_E ) ), TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q23 ) &&
+ NE_16( sts[0]->hTcxEnc->transform_type[k], TCX_5 ) )
+ {
+ sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1;
+ move16();
+ sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1;
+ move16();
+ sts[0]->hTcxEnc->tnsData[k].nFilters = 0;
+ move16();
+ sts[1]->hTcxEnc->tnsData[k].nFilters = 0;
+ move16();
+ sts[0]->hTcxEnc->fUseTns[k] = 0;
+ move16();
+ sts[1]->hTcxEnc->fUseTns[k] = 0;
+ move16();
+ FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
+ {
+ ClearTnsFilterCoefficients( sts[0]->hTcxEnc->tnsData[k].filter + iFilter );
+ ClearTnsFilterCoefficients( sts[1]->hTcxEnc->tnsData[k].filter + iFilter );
+ }
+ }
+
+ /* maxPredictionGain_fx = L_max( maxPredictionGain_fx, maxPredGain_fx ); */
+ IF( GT_32( maxPredGain_fx, L_shl_sat( maxPredictionGain_fx, sub( maxPredictionGain_e, maxPredGain_e ) ) ) ) /* exp: maxPredGain_e */
+ {
+ maxPredictionGain_fx = maxPredGain_fx;
+ maxPredictionGain_e = maxPredGain_e;
+ move32();
+ move16();
+ }
+ }
+ }
+ }
+ }
+
+ /* individual decision for each channel */
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
+ {
+ IF( EQ_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
+ {
+ CONTINUE;
+ }
+
+ Word8 isTCX10;
+
+ IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) )
+ {
+ nSubframes = 1;
+ isTCX10 = 0;
+ }
+ ELSE
+ {
+ nSubframes = NB_DIV;
+ isTCX10 = 1;
+ }
+ move16();
+ move16();
+
+ FOR( k = 0; k < nSubframes; k++ )
+ {
+ test();
+ test();
+ test();
+ test();
+ IF( sts[ch]->hTcxCfg->fIsTNSAllowed && ( individual_decision[k] || mct_on ) &&
+ ( !bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
+ {
+ Word32 maxPredGain_fx = -ONE_IN_Q31; // Q31
+ move32();
+ Word16 maxPredGain_e = 0;
+ move16();
+ sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[ch]->last_core == ACELP_CORE )];
+
+ FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
+ {
+ STnsFilter *pFilter;
+ struct TnsParameters const *pTnsParameters;
+ pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter;
+ pTnsParameters = sts[ch]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter;
+
+ // maxPredGain_fx = L_max( maxPredGain_fx, pFilter->predictionGain32 );
+ IF( GT_32( pFilter->predictionGain32, L_shl_sat( maxPredGain_fx, sub( maxPredGain_e, pFilter->predictionGain_e ) ) ) ) /* pFilter->predictionGain_e */
+ {
+ maxPredGain_fx = pFilter->predictionGain32;
+ maxPredGain_e = pFilter->predictionGain_e;
+ move32();
+ move16();
+ }
+
+ test();
+ IF( GT_32( pFilter->predictionGain32, L_shl_sat( L_deposit_h( pTnsParameters->minPredictionGain ), sub( PRED_GAIN_E, pFilter->predictionGain_e ) ) ) || GT_16( pFilter->avgSqrCoef, pTnsParameters->minAvgSqrCoef ) )
+ {
+ test();
+ test();
+ IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( sts[ch]->hTcxEnc->tcxltp_gain, 19660 /*.6f in Q15*/ ) )
+ {
+ sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here,
+ this may result in crash later. Changing the filter type here so the order is taken here in further section */
+ IF( pFilter->order != 0 )
+ {
+ pFilter->filterType = TNS_FILTER_ON;
+ move16();
+ }
+ ELSE
+ {
+ pFilter->filterType = TNS_FILTER_ON_ZERO;
+ move16();
+ }
+ }
+ ELSE
+ {
+ Word16 maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( sts[ch]->hTranDet, isTCX10, NSUBBLOCKS, 3 );
+
+ IF( GE_16( maxEnergyChange_fx, shl( pTnsParameters->minEnergyChange, Q3 - Q7 ) ) )
+ {
+ sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here,
+ this may result in crash later. Changing the filter type here so the order is taken here in further section */
+ IF( pFilter->order != 0 )
+ {
+ pFilter->filterType = TNS_FILTER_ON;
+ move16();
+ }
+ ELSE
+ {
+ pFilter->filterType = TNS_FILTER_ON_ZERO;
+ move16();
+ }
+ }
+ ELSE
+ {
+ pFilter->filterType = TNS_FILTER_OFF;
+ move16();
+ }
+ }
+ }
+ ELSE IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 ) /* If a previous filter is turned on */
+ {
+ pFilter->filterType = TNS_FILTER_ON_ZERO;
+ move16();
+ sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 );
+ move16();
+ }
+ ELSE
+ {
+ pFilter->filterType = TNS_FILTER_OFF;
+ move16();
+ }
+ }
+
+ sts[ch]->hTcxEnc->fUseTns[k] = 0;
+ move16();
+ if ( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 )
+ {
+ sts[ch]->hTcxEnc->fUseTns[k] = 1;
+ move16();
+ }
+
+ test();
+ test();
+ IF( !bWhitenedDomain && LT_32( L_shl_sat( maxPredGain_fx, sub( maxPredGain_e, PRED_GAIN_E ) ), TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q23 ) && NE_16( sts[ch]->hTcxEnc->transform_type[k], TCX_5 ) )
+ {
+ sts[ch]->hTcxEnc->fUseTns[k] = 0;
+ move16();
+ sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1;
+ move16();
+ sts[ch]->hTcxEnc->tnsData[k].nFilters = 0;
+ move16();
+ FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
+ {
+ ClearTnsFilterCoefficients( sts[ch]->hTcxEnc->tnsData[k].filter + iFilter );
+ sts[ch]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF;
+ move16();
+ }
+ }
+
+ // maxPredictionGain_fx = L_max( maxPredictionGain_fx, maxPredGain_fx );
+ IF( GT_32( maxPredGain_fx, L_shl_sat( maxPredictionGain_fx, sub( maxPredictionGain_e, maxPredGain_e ) ) ) ) /* maxPredGain_e */
+ {
+ maxPredictionGain_fx = maxPredGain_fx;
+ maxPredictionGain_e = maxPredGain_e;
+ move32();
+ move16();
+ }
+ }
+ }
+ }
+
+
+ /* we have the decision, set filter data accordingly */
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
+ {
+ IF( EQ_16( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
+ {
+ CONTINUE;
+ }
+
+ IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) )
+ {
+ nSubframes = 1;
+ }
+ ELSE
+ {
+ nSubframes = NB_DIV;
+ }
+ move16();
+ FOR( k = 0; k < nSubframes; k++ )
+ {
+ test();
+ test();
+ IF( sts[ch]->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
+ {
+ sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[ch]->last_core == ACELP_CORE )];
+
+ FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
+ {
+ STnsFilter *pFilter;
+ pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter;
+ SWITCH( pFilter->filterType )
+ {
+ case TNS_FILTER_OFF:
+ ClearTnsFilterCoefficients( sts[ch]->hTcxEnc->tnsData[k].filter + iFilter );
+ BREAK;
+ case TNS_FILTER_ON_ZERO:
+ /* Since TNS filter of order 0 is not allowed we have to signal in the stream filter of order 1 with the 0th coefficient equal to 0 */
+ ClearTnsFilterCoefficients( pFilter );
+ pFilter->order = 1;
+ move16();
+ BREAK;
+ }
+ }
+ }
+ }
+ }
+
+ /* Apply filters, loop over channels */
+ FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
+ {
+ st = sts[ch];
+ IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
+ {
+ CONTINUE;
+ }
+
+ IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) )
+ {
+ nSubframes = 1;
+ }
+ ELSE
+ {
+ nSubframes = NB_DIV;
+ }
+ move16();
+
+ FOR( k = 0; k < nSubframes; k++ )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( bWhitenedDomain && ( ch > 0 ) && /* test for identical TNS filter data in both channels */
+ sts[0]->hTcxCfg->fIsTNSAllowed && sts[0]->hTcxEnc->fUseTns[k] &&
+ sts[1]->hTcxCfg->fIsTNSAllowed && sts[1]->hTcxEnc->fUseTns[k] )
+ {
+ Word16 equalFilterData = 0;
+ move16();
+ test();
+ test();
+ if ( EQ_16( sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters, sts[1]->hTcxCfg->pCurrentTnsConfig->nMaxFilters ) &&
+ EQ_16( sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k], sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] ) &&
+ EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) )
+ {
+ equalFilterData = 1;
+ move16();
+ }
+
+ IF( equalFilterData )
+ {
+ FOR( iFilter = st->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- )
+ {
+ const Word16 *pDataCh0 = (const Word16 *) &sts[0]->hTcxEnc->tnsData[k].filter[iFilter];
+ const Word16 *pDataCh1 = (const Word16 *) &sts[1]->hTcxEnc->tnsData[k].filter[iFilter];
+ Word16 i = 2 + TNS_MAX_FILTER_ORDER; /* excl. informative float data. Portable? */
+
+ move16();
+ test();
+ WHILE( ( i >= 0 ) && EQ_16( pDataCh0[i], pDataCh1[i] ) )
+ {
+ test();
+ i = sub( i, 1 );
+ }
+ IF( i >= 0 )
+ {
+ equalFilterData = 0;
+ move16();
+ BREAK;
+ }
+ }
+ IF( equalFilterData )
+ {
+ st->hTcxEnc->tnsData[k].nFilters = i_mult( st->hTcxEnc->tnsData[k].nFilters, -1 ); /* signals common TNS */
+ move16();
+ }
+ }
+ }
+ test();
+ test();
+ IF( st->hTcxCfg->fIsTNSAllowed && ( !bWhitenedDomain || st->hTcxEnc->bTnsOnWhithenedSpectra[k] ) )
+ {
+ L_spec = st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0];
+ move16();
+ spectrum_fx = st->hTcxEnc->spectrum_fx[k];
+ /* If TNS should be used then get the residual after applying it inplace in the spectrum */
+ IF( st->hTcxEnc->fUseTns[k] )
+ {
+ st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[st->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( st->last_core == ACELP_CORE )];
+
+ ApplyTnsFilter( st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], spectrum_fx, 1 );
+ }
+
+ IF( EQ_16( st->hTcxEnc->transform_type[k], TCX_5 ) )
+ {
+ tcx5TnsUngrouping_fx( shr( L_frame, 2 ), shr( L_spec, 1 ), st->hTcxEnc->spectrum_fx[k], ENC );
+ }
+
+ st->hTcxEnc->tnsData[k].tnsOnWhitenedSpectra = st->hTcxEnc->bTnsOnWhithenedSpectra[k];
+ move16();
+ EncodeTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], param_core[ch] + k * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, tnsSize[ch] + k, tnsBits[ch] + k );
+ }
+
+ IF( EQ_16( st->hTcxEnc->transform_type[k], TCX_5 ) )
+ {
+ tcx5SpectrumInterleaving_fx( st->hTcxCfg->tcx5SizeFB, st->hTcxEnc->spectrum_fx[k] );
+ tcx5SpectrumInterleaving_fx( st->hTcxCfg->tcx5SizeFB, mdst_spectrum_fx[ch][k] );
+ }
+ }
+ }
+ return;
+}
diff --git a/lib_enc/cod_uv.c b/lib_enc/cod_uv.c
deleted file mode 100644
index 9e7ce955844554794434881de1f04317bb321cd3..0000000000000000000000000000000000000000
--- a/lib_enc/cod_uv.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "prot.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/comvad_decision.c b/lib_enc/comvad_decision.c
deleted file mode 100644
index efb9c1d789381c50f813704f56c5b207b055d790..0000000000000000000000000000000000000000
--- a/lib_enc/comvad_decision.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "prot.h"
-#include "rom_enc.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/cor_shif.c b/lib_enc/cor_shif.c
deleted file mode 100644
index 0e2004abf2b74fc291df1fafb1f856b731c8e611..0000000000000000000000000000000000000000
--- a/lib_enc/cor_shif.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include
-#include "prot.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/core_enc_2div.c b/lib_enc/core_enc_2div.c
deleted file mode 100644
index c899b52ff72d3d5658f135f34e7730d22f0987de..0000000000000000000000000000000000000000
--- a/lib_enc/core_enc_2div.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "cnst.h"
-#include "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c
deleted file mode 100644
index b0a1c880eec8cc1dd81c9ce0619c9712f124db62..0000000000000000000000000000000000000000
--- a/lib_enc/core_enc_init.c
+++ /dev/null
@@ -1,1055 +0,0 @@
-/******************************************************************************************************
-
- (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository. All Rights Reserved.
-
- This software is protected by copyright law and by international treaties.
- The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
- Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
- Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
- Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
- contributors to this repository retain full ownership rights in their respective contributions in
- the software. This notice grants no license of any kind, including but not limited to patent
- license, nor is any license granted by implication, estoppel or otherwise.
-
- Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
- contributions.
-
- This software is provided "AS IS", without any express or implied warranties. The software is in the
- development stage. It is intended exclusively for experts who have experience with such software and
- solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
- and fitness for a particular purpose are hereby disclaimed and excluded.
-
- Any dispute, controversy or claim arising under or in relation to providing this software shall be
- submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
- accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
- the United Nations Convention on Contracts on the International Sales of Goods.
-
-*******************************************************************************************************/
-
-/*====================================================================================
- EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
- ====================================================================================*/
-
-#include
-#include "options.h"
-#include "options_warnings.h"
-#include "cnst.h"
-#include "prot.h"
-#include "ivas_prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-#include "prot_fx_enc.h"
-
-#include "prot_fx.h"
-
-/*-----------------------------------------------------------------------*
- * Local function prototypes
- *-----------------------------------------------------------------------*/
-static void init_tcx_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, const Word16 MCT_flag );
-static void init_core_sig_ana_ivas_fx( Encoder_State *st );
-static void init_modes_ivas_fx( Encoder_State *st, const Word32 last_total_brate );
-static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const int32_t last_total_brate );
-static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const int32_t last_total_brate );
-/*-----------------------------------------------------------------------*
- * init_coder_ace_plus()
- *
- * Initialization of state variables
- *-----------------------------------------------------------------------*/
-void init_coder_ace_plus_ivas_fx(
- Encoder_State *st, /* i : Encoder state */
- const Word32 last_total_brate, /* i : last total bitrate */
-#ifdef FIX_920_IGF_INIT_ERROR
- const Word32 igf_brate, /* i : IGF configuration bitrate */
-#endif
- const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */
-)
-{
- TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
- Word16 L_frame_old; /*keep old frame size for switching */
- Word16 L_subfr;
-
- /* Bitrate */
- st->tcxonly = getTcxonly_ivas_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format );
- move16();
-
- /* Core Sampling Rate */
- st->sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format );
- st->fscale = sr2fscale_fx( st->sr_core );
- move32();
- move16();
-
- /* Narrowband? */
- IF( EQ_16( st->bwidth, NB ) )
- {
- st->narrowBand = 1;
- move16();
- }
- ELSE
- {
- st->narrowBand = 0;
- move16();
- }
-
- /* Core Framing */
- L_frame_old = st->last_L_frame;
- move16();
- st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/
- move16();
- st->L_frame_past = -1;
- move16();
-
- IF( hTcxEnc != NULL )
- {
- hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/
- move16();
-
- IF( st->ini_frame == 0 )
- {
- set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 );
- hTcxEnc->acelp_zir = hTcxEnc->Txnq + L_FRAME / 2;
- hTcxEnc->q_Txnq = Q15;
- move16();
- hTcxEnc->tcx_target_bits_fac = ONE_IN_Q14;
- move16();
- }
- }
-
- test();
- test();
- test();
- test();
- test();
- IF( ( st->element_mode == EVS_MONO && EQ_32( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->element_mode > EVS_MONO && EQ_32( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) )
- {
- st->nb_subfr = NB_SUBFR16k;
- move16();
- }
- ELSE
- {
- st->nb_subfr = NB_SUBFR;
- move16();
- }
- L_subfr = idiv1616( st->L_frame, st->nb_subfr );
-
- /* Core Lookahead */
- st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS );
- st->encoderLookahead_FB = NS2SA_FX2( st->input_Fs, ACELP_LOOK_NS );
- move16();
- move16();
-
- IF( st->ini_frame == 0 )
- {
- st->acelpFramesCount = 0;
- move16();
- st->prevTempFlatness_fx = 128 /*1.0f Q7*/;
- move16();
- }
-
- /* Initialize TBE */
- IF( st->hBWE_TD != NULL )
- {
- st->hBWE_TD->prev_coder_type = GENERIC;
- move16();
- set16_fx( st->hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 );
- st->hBWE_TD->prev_tilt_para_fx = 0;
- move16();
- set16_fx( st->hBWE_TD->cur_sub_Aq_fx, 0, M + 1 );
- }
-
- st->currEnergyHF_fx = 0;
- move32();
- st->currEnergyHF_e_fx = 0;
- move16();
- test();
- /* Initialize LPC analysis/quantization */
- IF( LE_32( st->sr_core, INT_FS_16k ) && st->tcxonly == 0 )
- {
- st->lpcQuantization = 1;
- move16();
- }
- ELSE
- {
- st->lpcQuantization = 0;
- move16();
- }
-
- st->next_force_safety_net = 0;
- move16();
- test();
- test();
- IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) )
- {
- set16_fx( st->mem_MA_fx, 0, M );
- Copy( GEWB_Ave_fx, st->mem_AR_fx, M );
- }
-
- /* Initialize IGF */
- if ( st->hIGFEnc != NULL )
- {
- st->hIGFEnc->infoStopFrequency = -1;
- move16();
- }
-
- test();
- IF( st->igf && st->hIGFEnc != NULL )
- {
-#ifdef FIX_920_IGF_INIT_ERROR
- IGFEncSetMode_ivas_fx( st->hIGFEnc, igf_brate, st->bwidth, st->element_mode, st->rf_mode );
-#else
- IGFEncSetMode_ivas_fx( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode );
-#endif
- }
- ELSE IF( st->hIGFEnc != NULL )
- {
- st->hIGFEnc->infoTotalBitsWritten = 0;
- move16();
- st->hIGFEnc->infoTotalBitsPerFrameWritten = 0;
- move16();
- }
-
- /* Initialize Core Signal Analysis Module */
- init_core_sig_ana_ivas_fx( st );
-
-
- /* Initialize TCX */
- IF( hTcxEnc != NULL )
- {
- init_tcx_ivas_fx( st, L_frame_old, st->total_brate, last_total_brate, MCT_flag );
- }
-
- /* Initialize Signal Buffers */
- init_sig_buffers_ivas_fx( st, L_frame_old, L_subfr, last_total_brate );
-
- /* Initialize ACELP */
-
- init_acelp_ivas_fx( st, L_frame_old, 0, last_total_brate );
-
- if ( st->ini_frame == 0 )
- {
- st->tec_tfa = 0;
- move16();
- }
-
- IF( st->hTECEnc != NULL )
- {
- resetTecEnc_Fx( st->hTECEnc, st->tec_tfa );
- }
-
- test();
- test();
- test();
- IF( EQ_16( st->bwidth, SWB ) && ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
- {
- st->tec_tfa = 1;
- move16();
- }
- ELSE
- {
- st->tec_tfa = 0;
- move16();
- }
-
- st->tec_flag = 0;
- move16();
- st->tfa_flag = 0;
- move16();
-
- test();
- test();
- test();
- IF( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
- {
- st->glr = 1;
- move16();
- }
- ELSE
- {
- st->glr = 0;
- move16();
- }
-
- st->glr_reset = 0;
- move16();
-
- /* Initialize ACELP/TCX Modes */
- init_modes_ivas_fx( st, last_total_brate );
-
- /* Adaptive BPF */
- set32_fx( st->mem_bpf_fx1, 0, 2 * L_FILT16k );
- set32_fx( st->mem_error_bpf_fx, 0, 2 * L_FILT16k );
-
- IF( st->ini_frame == 0 )
- {
- st->Q_max_enc[0] = 15;
- move16();
- st->Q_max_enc[1] = 15;
- move16();
- }
-
- IF( GE_32( st->total_brate, HQ_48k ) )
- {
- st->enablePlcWaveadjust = 1;
- move16();
- }
- ELSE
- {
- st->enablePlcWaveadjust = 0;
- move16();
- }
-
- IF( st->hPlcExt )
- {
- init_PLC_enc_fx( st->hPlcExt, st->sr_core );
- }
-
- st->glr_idx[0] = 0;
- move16();
- st->glr_idx[1] = 0;
- move16();
- st->mean_gc[0] = 0;
- move16();
- st->mean_gc[1] = 0;
- move16();
- st->prev_lsf4_mean = 0;
- move16();
- st->last_stab_fac = 0;
- move16();
-
- return;
-}
-
-/*-----------------------------------------------------------------------*
- * init_tcx()
- *
- * Initialization of TCX
- *-----------------------------------------------------------------------*/
-
-
-static void init_tcx_ivas_fx(
- Encoder_State *st,
- const Word16 L_frame_old,
- const Word32 total_brate,
- const Word32 last_total_brate,
- const Word16 MCT_flag )
-{
- TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
-
- /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */
- hTcxEnc->spectrum_fx[0] = hTcxEnc->spectrum_long_fx;
- hTcxEnc->spectrum_fx[1] = hTcxEnc->spectrum_long_fx + N_TCX10_MAX;
- st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_e[1] = 0;
- move16();
- move16();
-
- init_tcx_cfg_ivas_fx( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX,
- st->fscale, st->preemph_fac, st->tcxonly, st->rf_mode, st->igf,
- st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, MCT_flag );
-
- /* Init TCX target bits correction factor */
- hTcxEnc->tcx_target_bits_fac = 0x4000; /*1.0f in 1Q14*/
- move16();
- hTcxEnc->measuredBwRatio = 0x4000; /*1.0f in 1Q14*/
- move16();
- hTcxEnc->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/
- move16();
- hTcxEnc->noiseLevelMemory_cnt = 0;
- move16();
-
- set16_fx( hTcxEnc->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS );
- set8_fx( hTcxEnc->memQuantZeros, 0, L_FRAME_PLUS );
-
- /* TCX-LTP */
- hTcxEnc->tcxltp = getTcxLtp( st->sr_core );
- move16();
-
- test();
- test();
- test();
- test();
- IF( st->ini_frame == 0 )
- {
- hTcxEnc->tcxltp_pitch_int_past = st->L_frame;
- hTcxEnc->tcxltp_pitch_fr_past = 0;
- hTcxEnc->tcxltp_gain_past = 0;
- hTcxEnc->tcxltp_norm_corr_past = 0;
- hTcxEnc->tcxltp_norm_corr_mem = 0;
- hTcxEnc->kernel_switch_corr_past = 0;
- hTcxEnc->kernel_symmetry_past = 0; /* MDCT_IV & 1 */
- hTcxEnc->enc_ste_pre_corr_past = 0;
- hTcxEnc->tfm_mem_fx = 1610612736; /* 0.75 in Q31 */
- hTcxEnc->tcxltp_on_mem = 0;
- move16();
- move16();
- move16();
- move16();
- move16();
- move16();
- move16();
- move16();
- move16();
- move16();
- }
- ELSE IF( NE_16( st->L_frame, L_frame_old ) && !( ( GE_32( total_brate, ACELP_16k40 ) && LE_32( total_brate, ACELP_24k40 ) ) &&
- ( EQ_32( total_brate, last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) )
- {
- Word16 pitres, pitres_old;
- Word16 pit, pit_old;
-
- pitres_old = 4;
- move16();
- if ( EQ_16( 160, shr( L_frame_old, sub( 7, norm_s( L_frame_old ) ) ) ) ) /*if ( L_frame_old%160==0 )*/
- {
- pitres_old = 6;
- move16();
- }
-
- /*pit_old = (float)st->tcxltp_pitch_int_past + (float)st->tcxltp_pitch_fr_past/(float)pitres_old;*/
- pit_old = add( hTcxEnc->tcxltp_pitch_int_past, mult_r( hTcxEnc->tcxltp_pitch_fr_past, div_s( 1, pitres_old ) ) );
-
- pitres = 4;
- move16();
- if ( EQ_16( 160, shr( st->L_frame, sub( 7, norm_s( st->L_frame ) ) ) ) ) /*if ( st->L_frame%160==0 )*/
- {
- pitres = 6;
- move16();
- }
-
- /*pit = pit_old * (float)st->L_frame/(float)L_frame_old;*/
- pit = shl_sat( mult_r( pit_old, div_s( st->L_frame, shl( L_frame_old, 2 ) ) ), 2 );
- /* Note : the saturation here that can happens when FS == 32kHz*/
- /* assert(pit <= st->L_frame);*/
-
- hTcxEnc->tcxltp_pitch_int_past = pit;
- move16();
- hTcxEnc->tcxltp_pitch_fr_past = i_mult2( sub( pit, hTcxEnc->tcxltp_pitch_int_past ), pitres );
- move16();
- }
-
- hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->rf_mode, st->element_mode );
- move16();
-
- return;
-}
-
-/*-----------------------------------------------------------------------*
- * init_sig_buffers()
- *
- * Initialization of signal buffers
- *-----------------------------------------------------------------------*/
-/*copy of evs function since it was static */
-static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const int32_t last_total_brate )
-{
-
- LPD_state_HANDLE hLPDmem = st->hLPDmem;
- TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
-
- /* Encoder Past Samples at encoder-sampling-rate */
- st->encoderPastSamples_enc = shr( imult1616( st->L_frame, 9 ), 4 );
- move16();
-
- /* Initialize Signal Buffers and Pointers at encoder-sampling-rate */
- IF( st->ini_frame == 0 )
- {
- set16_fx( st->buf_speech_enc, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k );
- st->exp_buf_speech_enc = 0;
- move16();
- set16_fx( st->buf_speech_enc_pe, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k );
- st->exp_buf_speech_enc_pe = 0;
- move16();
- if ( hTcxEnc != NULL )
- {
- set16_fx( hTcxEnc->buf_speech_ltp, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k );
- hTcxEnc->exp_buf_speech_ltp = 0;
- move16();
- }
- set16_fx( st->buf_wspeech_enc, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); /* increased by 320 to avoid memory overlap in ivas_find_wsp_fx() and also to accomodate for the wspeech_enc */
- st->exp_buf_wspeech_enc = 0;
- move16();
- }
- ELSE
- {
- test();
- test();
- test();
- test();
- test();
- IF( NE_16( st->L_frame, L_frame_old ) && !( ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) )
- {
- lerp( st->buf_speech_enc, st->buf_speech_enc, st->L_frame, L_frame_old );
- test();
- IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) /* condition should be checked again */
- {
- Copy( st->buf_speech_enc, hTcxEnc->buf_speech_ltp, st->L_frame );
- Scale_sig( hTcxEnc->buf_speech_ltp, st->L_frame, sub( st->exp_buf_speech_enc, s_max( st->exp_buf_speech_enc, hTcxEnc->exp_buf_speech_ltp ) ) ); // Q(15-max(st->exp_buf_speech_enc, hTcxEnc->exp_buf_speech_ltp))
- Scale_sig( hTcxEnc->buf_speech_ltp + st->L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->L_frame ), sub( hTcxEnc->exp_buf_speech_ltp, s_max( st->exp_buf_speech_enc, hTcxEnc->exp_buf_speech_ltp ) ) ); // Q(15-max(st->exp_buf_speech_enc, hTcxEnc->exp_buf_speech_ltp))
- hTcxEnc->exp_buf_speech_ltp = s_max( hTcxEnc->exp_buf_speech_ltp, st->exp_buf_speech_enc );
- move16();
- }
-
- // Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM, sub( st->prev_Q_new, st->prev_Q_old ) );
- Copy( st->old_wsp_fx, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM );
- st->exp_buf_wspeech_enc = st->exp_old_wsp;
- move16();
-
- /*Resamp buffers needed only for ACELP*/
- test();
- test();
- IF( EQ_16( st->L_frame, L_FRAME ) && !st->tcxonly )
- {
- // Copy_Scale_sig( st->old_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM, sub( st->prev_Q_new, st->prev_Q_old ) );
- Copy( st->old_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM );
- /* SCaling to common exponent*/
- Scale_sig( st->buf_speech_enc_pe + sub( st->L_frame, L_INP_MEM ), L_INP_MEM, sub( st->exp_old_inp_12k8, s_max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ) ) ); // Q(15-max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ))
- Scale_sig( st->buf_speech_enc_pe, sub( st->L_frame, L_INP_MEM ), sub( st->exp_buf_speech_enc_pe, s_max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ) ) ); // Q(15-max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ))
- Scale_sig( st->buf_speech_enc_pe + st->L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->L_frame ), sub( st->exp_buf_speech_enc_pe, s_max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ) ) ); // Q(15-max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ))
- st->exp_buf_speech_enc_pe = s_max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe );
- move16();
- }
- ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) && !st->tcxonly )
- {
- lerp( st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM );
- Copy( st->old_inp_16k_fx, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM );
- /* SCaling to common exponent*/
- Scale_sig( st->buf_speech_enc_pe + sub( st->L_frame, L_INP_MEM ), L_INP_MEM, sub( st->exp_old_inp_16k, s_max( st->exp_old_inp_16k, st->exp_buf_speech_enc_pe ) ) );
- Scale_sig( st->buf_speech_enc_pe, sub( st->L_frame, L_INP_MEM ), sub( st->exp_buf_speech_enc_pe, s_max( st->exp_old_inp_16k, st->exp_buf_speech_enc_pe ) ) );
- Scale_sig( st->buf_speech_enc_pe + st->L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->L_frame ), sub( st->exp_buf_speech_enc_pe, s_max( st->exp_old_inp_16k, st->exp_buf_speech_enc_pe ) ) );
- st->exp_buf_speech_enc_pe = s_max( st->exp_old_inp_16k, st->exp_buf_speech_enc_pe );
- move16();
- }
-
- st->mem_preemph_enc = st->buf_speech_enc[st->encoderPastSamples_enc + st->encoderLookahead_enc - 1];
- move16();
- st->exp_mem_preemph_enc = st->exp_buf_speech_enc;
- move16();
- st->mem_wsp_enc = shr( st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1], sub( Q16, st->exp_buf_wspeech_enc ) ); // Q-1
- move16();
- }
- /*coming from TCXonly modes*/
- ELSE IF( !st->tcxonly && GE_32( last_total_brate, ACELP_32k ) )
- {
-
- Copy( st->old_wsp_fx, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM );
- // Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM, sub( st->prev_Q_new, st->prev_Q_old ) );
- st->exp_buf_wspeech_enc = st->exp_old_wsp;
- move16(); /*Resamp buffers needed only for ACELP*/
- IF( EQ_16( st->L_frame, L_FRAME16k ) )
- {
- lerp( st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM );
- }
- hLPDmem->mem_w0 = 0;
- move16();
- st->mem_wsp_enc = shr( st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1], sub( Q16, st->exp_buf_wspeech_enc ) ); // Q-1
- move16();
- }
- }
-
- st->new_speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc + st->encoderLookahead_enc;
- st->new_speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc + st->encoderLookahead_enc;
- if ( hTcxEnc != NULL )
- {
- hTcxEnc->new_speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc + st->encoderLookahead_enc;
- }
-
- IF( st->hTcxEnc != NULL )
- {
- st->hTcxEnc->new_speech_TCX = st->input_buff_fx + Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 );
- st->hTcxEnc->speech_TCX = st->hTcxEnc->new_speech_TCX - st->encoderLookahead_FB;
- }
- st->speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc;
- st->speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc;
-
- if ( hTcxEnc != NULL )
- {
- hTcxEnc->speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc;
- }
-
- IF( st->element_mode > EVS_MONO )
- {
- st->wspeech_enc = st->buf_wspeech_enc + st->L_frame + L_SUBFR;
- }
- ELSE
- {
- st->wspeech_enc = st->buf_wspeech_enc + st->L_frame + L_subfr;
- }
-
- test();
- test();
- IF( st->ini_frame == 0 || NE_16( st->L_frame, L_frame_old ) || EQ_16( st->last_codec_mode, MODE1 ) )
- {
- set16_fx( st->buf_synth, 0, OLD_SYNTH_SIZE_ENC + L_FRAME32k );
- }
-
- st->synth = st->buf_synth + st->L_frame + L_subfr;
-
-
- return;
-}
-
-/*-----------------------------------------------------------------------*
- * init_core_sig_ana()
- *
- *
- *-----------------------------------------------------------------------*/
-static void init_core_sig_ana_ivas_fx( Encoder_State *st )
-{
-
- /* Pre-emphasis factor and memory */
-
- st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/
- move16();
- IF( LT_16( st->fscale, ( 16000 * FSCALE_DENOM ) / 12800 ) )
- {
- st->preemph_fac = PREEMPH_FAC; /*WB*/
- move16();
- }
- ELSE IF( LT_16( st->fscale, ( 24000 * FSCALE_DENOM ) / 12800 ) )
- {
- st->preemph_fac = PREEMPH_FAC_16k; /*WB*/
- move16();
- }
-
- st->gamma = GAMMA1;
- move16();
- st->inv_gamma = GAMMA1_INV;
- move16();
- IF( EQ_32( st->sr_core, 16000 ) )
- {
- st->gamma = GAMMA16k;
- move16();
- st->inv_gamma = GAMMA16k_INV;
- move16();
- }
-
-
- st->min_band = 1;
- move16();
- st->max_band = 16;
- move16();
-
- IF( st->narrowBand == 0 )
- {
- st->min_band = 0;
- move16();
- st->max_band = 19;
- move16();
- }
-
-
- return;
-}
-/*-----------------------------------------------------------------------*
- * init_acelp()
- *
- *
- *-----------------------------------------------------------------------*/
-static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const int32_t last_total_brate )
-{
- Word16 mem_syn_r_size_old;
- Word16 mem_syn_r_size_new;
- LPD_state_HANDLE hLPDmem = st->hLPDmem;
- TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
-
- /* Init pitch lag */
- IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
- {
- /* TCX LTP ana always runs @12.8kHz */
- st->pit_res_max = initPitchLagParameters( 12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
- move16();
- }
- ELSE
- {
- st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
- move16();
- }
-
- /* Init LPDmem */
- IF( st->ini_frame == 0 )
- {
- IF( hLPDmem != NULL )
- {
- set16_fx( hLPDmem->syn, 0, 1 + M );
- set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM );
- }
-
- IF( st->hTcxEnc != NULL )
- {
- set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 );
- st->hTcxEnc->q_Txnq = Q15;
- move16();
- st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + shr( st->L_frame, 1 );
- }
- }
- ELSE /*Rate switching*/
- {
- IF( st->last_core == ACELP_CORE )
- {
- lerp( hTcxEnc->Txnq, hTcxEnc->Txnq, shr( st->L_frame, 1 ), shr( L_frame_old, 1 ) );
- }
- ELSE
- {
- lerp( hTcxEnc->Txnq, hTcxEnc->Txnq, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old );
- }
- hTcxEnc->acelp_zir = hTcxEnc->Txnq + shr( st->L_frame, 1 );
-
- /* Rate switching */
- IF( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO )
- {
- IF( hLPDmem != NULL )
- {
- Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M );
- set16_fx( hLPDmem->syn, 0, M );
- hLPDmem->q_lpd_syn = Q15;
- move16();
- }
- IF( st->hTcxEnc != NULL )
- {
- set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 );
- st->hTcxEnc->q_Txnq = Q15;
- move16();
- }
- }
-
- /*AMR-WBIO->MODE2*/
- IF( EQ_16( st->last_core, AMR_WB_CORE ) )
- {
- st->next_force_safety_net = 1;
- move16();
- st->last_core = ACELP_CORE;
- move16();
- }
- /*HQ-CORE->MODE2*/
- test();
- IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) )
- {
- /*Reset of ACELP memories*/
- st->next_force_safety_net = 1;
- move16();
- st->rate_switching_reset = 1;
- move16();
- IF( hLPDmem != NULL )
- {
- hLPDmem->tilt_code = TILT_CODE;
- move16();
- set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM );
- set16_fx( hLPDmem->syn, 0, 1 + M );
- hLPDmem->q_lpd_syn = Q15;
- move16();
- hLPDmem->q_lpd_old_exc = Q15;
- move16();
- hLPDmem->mem_w0 = 0;
- move16();
- set16_fx( hLPDmem->mem_syn, 0, M );
- set16_fx( hLPDmem->mem_syn2, 0, M );
- hLPDmem->q_mem_syn = Q15;
- move16();
- }
-
- /* unquantized LPC*/
- test();
- test();
- test();
- IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) )
- {
- Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/
- IF( EQ_16( st->L_frame, L_FRAME16k ) )
- {
- lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 );
- }
- }
- Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/
- IF( st->tcxonly == 0 )
- {
- lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
- }
- ELSE
- {
- E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
- }
- st->last_core = TCX_20_CORE;
- move16();
-
- st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/
- st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
- move16();
- move16();
- /*ALDO overlap windowed past: also used in MODE1 but for other MDCT-FB*/
- set16_fx( hTcxEnc->old_out_fx, 0, st->L_frame );
- }
- ELSE
- {
- test();
- test();
- test();
- test();
- IF( ( NE_16( st->L_frame, L_frame_old ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( L_frame_old, L_FRAME16k ) ) )
- {
- /* convert quantized LSP vector */
- st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
- move16();
- IF( st->tcxonly == 0 )
- {
- lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
- }
- ELSE
- {
- E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
- }
- IF( EQ_16( st->L_frame, L_FRAME16k ) )
- {
- Copy( st->lsp_old_fx, st->lspold_enc_fx, M );
- }
- ELSE
- {
- Copy( st->lsp_old1_fx, st->lspold_enc_fx, M );
- }
-
-
- /*Mem of deemphasis stay unchanged : hLPDmem->syn*/
- IF( hLPDmem != NULL )
- {
- synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC );
- Word16 tmp, A[M + 1], Ap[M + 1], tmp_buf[M + 1];
- /* Update wsyn */
- /* lsp2a_stab( st->lsp_old, A, M ); */
- E_LPC_f_lsp_a_conversion( st->lsp_old_fx, A, M );
- weight_a_fx( A, Ap, GAMMA1, M );
- tmp = 0;
- move16();
- tmp_buf[0] = 0;
- move16();
- Copy( hLPDmem->mem_syn2, tmp_buf + 1, M );
- deemph_fx( tmp_buf + 1, st->preemph_fac, M, &tmp );
- Residu3_fx( Ap, tmp_buf + M, &tmp, 1, 1 );
- hLPDmem->mem_w0 = sub_sat( shr_sat( st->wspeech_enc[-1], shift ), tmp );
- move16();
- }
- }
- ELSE IF( ( NE_16( st->L_frame, L_frame_old ) ) )
- {
- /*Partial reset of ACELP memories*/
- st->next_force_safety_net = 1;
- move16();
- st->rate_switching_reset = 1;
- move16();
-
- /*reset partly some memories*/
- IF( hLPDmem != NULL )
- {
- hLPDmem->tilt_code = TILT_CODE;
- move16();
- set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM );
- move16();
- hLPDmem->q_lpd_old_exc = Q15;
- move16();
- /*Resamp others memories*/
- /*Size of LPC syn memory*/
- /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */
- mem_syn_r_size_old = shr( L_frame_old, 4 );
- mem_syn_r_size_new = shr( st->L_frame, 4 );
-
- lerp( hLPDmem->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, hLPDmem->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
- Copy( hLPDmem->mem_syn_r + L_SYN_MEM - M, hLPDmem->mem_syn, M );
- Copy( hLPDmem->mem_syn, hLPDmem->mem_syn2, M );
-
- /*Untouched memories : hLPDmem->syn & hLPDmem->mem_w0*/
- hLPDmem->mem_w0 = 0;
- move16();
- }
- /* unquantized LPC*/
- Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/
- IF( EQ_16( st->L_frame, L_FRAME16k ) )
- {
- lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 );
- }
- Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/
- IF( st->tcxonly == 0 )
- {
- lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
- }
- ELSE
- {
- E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
- }
- }
- ELSE IF( !st->tcxonly && EQ_16( st->L_frame, L_FRAME16k ) && GT_32( st->last_total_brate, ACELP_32k ) )
- {
- lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
- }
- }
- }
-
- test();
- test();
- if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 )
- {
- st->rate_switching_reset = 1;
- move16();
- }
-
- /* Post-processing */
- /*EVS specific*/
- /* hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 );
- set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 );
- hLPDmem->dm_fx.prev_state = 0;*/
- /*------------*/
-
- if ( hLPDmem != NULL )
- {
- hLPDmem->dm_fx.prev_state = 0;
- move16(); /* This corresponds to st_fx->dispMem in FLP */
- hLPDmem->dm_fx.prev_gain_code = 0;
- move32();
-
- FOR( Word16 i = 2; i < 8; i++ )
- {
- hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0;
- move16();
- }
- hLPDmem->gc_threshold = 0;
- move16();
- }
-
- /* Pulse Search configuration */
- st->acelp_autocorr = 1;
- move16();
-
- /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/
- test();
- test();
- if ( ( LE_32( st->total_brate, ACELP_9k60 ) || EQ_16( st->rf_mode, 1 ) ) && ( EQ_32( st->sr_core, 12800 ) ) )
- {
- st->acelp_autocorr = 0;
- move16();
- }
-
-
- /*BPF parameters for adjusting gain in function of background noise*/
- IF( EQ_16( st->codec_mode, MODE2 ) )
- {
- st->mem_bpf_fx.lp_error_ener = L_deposit_l( 0 );
- move32();
- st->pst_lp_ener_fx = 0;
- move16();
- IF( EQ_16( st->last_codec_mode, MODE1 ) )
- {
- st->mem_bpf_fx.lp_error = 0;
- move32();
- st->pst_mem_deemp_err_fx = 0;
- move16();
- }
- }
-
- return;
-}
-/*-----------------------------------------------------------------------*
- * init_modes()
- *
- *
- *-----------------------------------------------------------------------*/
-
-static void init_modes_ivas_fx(
- Encoder_State *st,
- const Word32 last_total_brate )
-{
- Word8 n;
- Word32 tmp32;
- TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
-
- /* Restrict ACE/TCX20/TCX10 mode */
- move16();
- st->restrictedMode = getRestrictedMode( st->element_mode, st->total_brate, st->Opt_AMR_WB );
- move16();
- st->acelpEnabled = 0;
- move16();
- st->tcx20Enabled = 0;
- move16();
- st->tcx10Enabled = 0;
-
- if ( EQ_16( s_and( st->restrictedMode, 1 ), 1 ) )
- {
- st->acelpEnabled = 1;
- move16();
- }
- if ( EQ_16( s_and( st->restrictedMode, 2 ), 2 ) )
- {
- st->tcx20Enabled = 1;
- move16();
- }
- if ( EQ_16( s_and( st->restrictedMode, 4 ), 4 ) )
- {
- st->tcx10Enabled = 1;
- move16();
- }
-
- /* TCX mode (TCX20 TCX10_10 or NO_TCX) */
- if ( st->hTcxEnc != NULL )
- {
- hTcxEnc->tcxMode = NO_TCX;
- move16();
- }
-
- /* Bits Budget */
- /*st->bits_frame_nominal = (int)( (float)st->L_frame * (float)FSCALE_DENOM * (float)st->bitrate / ( (float)st->fscale * 12800.0f ) );*/
- /*st->bits_frame_nominal = (int)( (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate/100.0f + 0.49f );*/
- /*328 = 0.010009765625 in 0Q15*/
- /* st->bits_frame_nominal = extract_h(L_add(L_mult(div_l(L_mult(shl(st->L_frame,2),st->bitrate),st->fscale),328),16056)); */
-
- /* st->bits_frame_nominal = (int)( (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate/100.0f + 0.49f ); */
- tmp32 = L_shl( st->total_brate, 1 ); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */
- st->bits_frame_nominal = extract_l( L_shr( Mpy_32_16_1( tmp32, 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */
- move16();
-
- IF( st->Opt_AMR_WB )
- {
- st->bits_frame = st->bits_frame_nominal;
- move16();
- st->bits_frame_core = st->bits_frame_nominal;
- move16();
- st->frame_size_index = 0;
- move16();
- }
- ELSE
- {
- FOR( n = 0; n < FRAME_SIZE_NB; n++ )
- {
- IF( LT_32( n, FRAME_SIZE_NB - 1 ) )
- {
- test();
- IF( LE_32( FrameSizeConfig[n].frame_bits, st->bits_frame_nominal ) && GT_32( FrameSizeConfig[n + 1].frame_bits, st->bits_frame_nominal ) )
- {
- st->frame_size_index = n;
- move16();
- st->bits_frame = st->bits_frame_nominal;
- move16();
- st->bits_frame_core = sub( sub( sub( st->bits_frame_nominal, FrameSizeConfig[n].transmission_bits ), FrameSizeConfig[n].bandwidth_bits ), FrameSizeConfig[n].reserved_bits );
- move16();
- BREAK;
- }
- }
- ELSE
- {
- IF( LE_32( FrameSizeConfig[n].frame_bits, st->bits_frame_nominal ) )
- {
- st->frame_size_index = n;
- move16();
- st->bits_frame = st->bits_frame_nominal;
- move16();
- st->bits_frame_core = sub( sub( sub( st->bits_frame_nominal, FrameSizeConfig[n].transmission_bits ), FrameSizeConfig[n].bandwidth_bits ), FrameSizeConfig[n].reserved_bits );
- move16();
- BREAK;
- }
- }
- }
- }
-
- /* Reconfigure core */
- core_coder_reconfig_ivas_fx( st, last_total_brate );
-
-
- return;
-}
diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c
index f6b5b5984d61e51db4559eaf62c1f4ec2a63b8ae..a2995245d14972fb2795cff193f21d190312b48f 100644
--- a/lib_enc/core_enc_init_fx.c
+++ b/lib_enc/core_enc_init_fx.c
@@ -3,8 +3,8 @@
====================================================================================*/
#include
-//#include "prot_fx.h"
-//#include "basop_mpy.h"
+// #include "prot_fx.h"
+// #include "basop_mpy.h"
#include "options.h"
#include "cnst.h"
#include "stl.h"
@@ -13,7 +13,6 @@
#include "ivas_cnst.h"
#include